software_output_device_ozone.cc revision e5d81f57cb97b3b6b7fccc9c5610d21eb81db09d
1// Copyright 2014 The Chromium Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5#include "content/browser/compositor/software_output_device_ozone.h" 6#include "third_party/skia/include/core/SkDevice.h" 7#include "ui/compositor/compositor.h" 8#include "ui/gfx/ozone/surface_factory_ozone.h" 9#include "ui/gfx/ozone/surface_ozone.h" 10#include "ui/gfx/skia_util.h" 11#include "ui/gfx/vsync_provider.h" 12 13namespace content { 14 15SoftwareOutputDeviceOzone::SoftwareOutputDeviceOzone(ui::Compositor* compositor) 16 : compositor_(compositor) { 17 gfx::SurfaceFactoryOzone* factory = gfx::SurfaceFactoryOzone::GetInstance(); 18 19 if (factory->InitializeHardware() != gfx::SurfaceFactoryOzone::INITIALIZED) 20 LOG(FATAL) << "Failed to initialize hardware in OZONE"; 21 22 surface_ozone_ = factory->CreateSurfaceForWidget(compositor_->widget()); 23 24 if (!surface_ozone_->InitializeCanvas()) 25 LOG(FATAL) << "Failed to initialize canvas"; 26 27 vsync_provider_ = surface_ozone_->CreateVSyncProvider(); 28} 29 30SoftwareOutputDeviceOzone::~SoftwareOutputDeviceOzone() { 31} 32 33void SoftwareOutputDeviceOzone::Resize(const gfx::Size& viewport_size) { 34 if (viewport_size_ == viewport_size) 35 return; 36 37 viewport_size_ = viewport_size; 38 39 surface_ozone_->ResizeCanvas(viewport_size_); 40} 41 42SkCanvas* SoftwareOutputDeviceOzone::BeginPaint(const gfx::Rect& damage_rect) { 43 DCHECK(gfx::Rect(viewport_size_).Contains(damage_rect)); 44 45 // Get canvas for next frame. 46 canvas_ = surface_ozone_->GetCanvas(); 47 48 canvas_->clipRect(gfx::RectToSkRect(damage_rect), SkRegion::kReplace_Op); 49 // Save the current state so we can restore once we're done drawing. This is 50 // saved after the clip since we want to keep the clip information after we're 51 // done drawing such that OZONE knows what was updated. 52 canvas_->save(); 53 54 return SoftwareOutputDevice::BeginPaint(damage_rect); 55} 56 57void SoftwareOutputDeviceOzone::EndPaint(cc::SoftwareFrameData* frame_data) { 58 SoftwareOutputDevice::EndPaint(frame_data); 59 60 canvas_->restore(); 61 62 if (damage_rect_.IsEmpty()) 63 return; 64 65 bool scheduled = surface_ozone_->PresentCanvas(); 66 DCHECK(scheduled) << "Failed to present canvas"; 67} 68 69} // namespace content 70