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.
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_canvas.h"
10 #include "ui/gfx/skia_util.h"
11 #include "ui/gfx/vsync_provider.h"
15 SoftwareOutputDeviceOzone::SoftwareOutputDeviceOzone(ui::Compositor* compositor)
16 : compositor_(compositor) {
17 gfx::SurfaceFactoryOzone* factory = gfx::SurfaceFactoryOzone::GetInstance();
19 if (factory->InitializeHardware() != gfx::SurfaceFactoryOzone::INITIALIZED)
20 LOG(FATAL) << "Failed to initialize hardware in OZONE";
22 surface_ozone_ = factory->CreateCanvasForWidget(compositor_->widget());
25 LOG(FATAL) << "Failed to initialize canvas";
27 vsync_provider_ = surface_ozone_->CreateVSyncProvider();
30 SoftwareOutputDeviceOzone::~SoftwareOutputDeviceOzone() {
33 void SoftwareOutputDeviceOzone::Resize(const gfx::Size& viewport_size) {
34 if (viewport_size_ == viewport_size)
37 viewport_size_ = viewport_size;
39 surface_ozone_->ResizeCanvas(viewport_size_);
42 SkCanvas* SoftwareOutputDeviceOzone::BeginPaint(const gfx::Rect& damage_rect) {
43 DCHECK(gfx::Rect(viewport_size_).Contains(damage_rect));
45 // Get canvas for next frame.
46 canvas_ = surface_ozone_->GetCanvas();
48 return SoftwareOutputDevice::BeginPaint(damage_rect);
51 void SoftwareOutputDeviceOzone::EndPaint(cc::SoftwareFrameData* frame_data) {
52 SoftwareOutputDevice::EndPaint(frame_data);
54 surface_ozone_->PresentCanvas(damage_rect_);
57 } // namespace content