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/skia_util.h" 9 #include "ui/gfx/vsync_provider.h" 10 #include "ui/ozone/public/surface_factory_ozone.h" 11 #include "ui/ozone/public/surface_ozone_canvas.h" 12 13 namespace content { 14 15 SoftwareOutputDeviceOzone::SoftwareOutputDeviceOzone(ui::Compositor* compositor) 16 : compositor_(compositor) { 17 ui::SurfaceFactoryOzone* factory = ui::SurfaceFactoryOzone::GetInstance(); 18 19 if (factory->InitializeHardware() != ui::SurfaceFactoryOzone::INITIALIZED) 20 LOG(FATAL) << "Failed to initialize hardware in OZONE"; 21 22 surface_ozone_ = factory->CreateCanvasForWidget(compositor_->widget()); 23 24 if (!surface_ozone_) 25 LOG(FATAL) << "Failed to initialize canvas"; 26 27 vsync_provider_ = surface_ozone_->CreateVSyncProvider(); 28 } 29 30 SoftwareOutputDeviceOzone::~SoftwareOutputDeviceOzone() { 31 } 32 33 void SoftwareOutputDeviceOzone::Resize(const gfx::Size& viewport_pixel_size, 34 float scale_factor) { 35 scale_factor_ = scale_factor; 36 37 if (viewport_pixel_size_ == viewport_pixel_size) 38 return; 39 40 viewport_pixel_size_ = viewport_pixel_size; 41 42 surface_ozone_->ResizeCanvas(viewport_pixel_size_); 43 } 44 45 SkCanvas* SoftwareOutputDeviceOzone::BeginPaint(const gfx::Rect& damage_rect) { 46 DCHECK(gfx::Rect(viewport_pixel_size_).Contains(damage_rect)); 47 48 // Get canvas for next frame. 49 canvas_ = surface_ozone_->GetCanvas(); 50 51 return SoftwareOutputDevice::BeginPaint(damage_rect); 52 } 53 54 void SoftwareOutputDeviceOzone::EndPaint(cc::SoftwareFrameData* frame_data) { 55 SoftwareOutputDevice::EndPaint(frame_data); 56 57 surface_ozone_->PresentCanvas(damage_rect_); 58 } 59 60 } // namespace content 61