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 "components/viz/service/display_embedder/software_output_device_ozone.h" 6 7 #include <memory> 8 9 #include "ui/gfx/skia_util.h" 10 #include "ui/gfx/vsync_provider.h" 11 #include "ui/ozone/public/platform_window_surface.h" 12 #include "ui/ozone/public/surface_ozone_canvas.h" 13 14 namespace viz { 15 SoftwareOutputDeviceOzone(std::unique_ptr<ui::PlatformWindowSurface> platform_window_surface,std::unique_ptr<ui::SurfaceOzoneCanvas> surface_ozone)16SoftwareOutputDeviceOzone::SoftwareOutputDeviceOzone( 17 std::unique_ptr<ui::PlatformWindowSurface> platform_window_surface, 18 std::unique_ptr<ui::SurfaceOzoneCanvas> surface_ozone) 19 : platform_window_surface_(std::move(platform_window_surface)), 20 surface_ozone_(std::move(surface_ozone)) { 21 vsync_provider_ = surface_ozone_->CreateVSyncProvider(); 22 } 23 ~SoftwareOutputDeviceOzone()24SoftwareOutputDeviceOzone::~SoftwareOutputDeviceOzone() {} 25 Resize(const gfx::Size & viewport_pixel_size,float scale_factor)26void SoftwareOutputDeviceOzone::Resize(const gfx::Size& viewport_pixel_size, 27 float scale_factor) { 28 if (viewport_pixel_size_ == viewport_pixel_size) 29 return; 30 31 viewport_pixel_size_ = viewport_pixel_size; 32 33 surface_ozone_->ResizeCanvas(viewport_pixel_size_); 34 } 35 BeginPaint(const gfx::Rect & damage_rect)36SkCanvas* SoftwareOutputDeviceOzone::BeginPaint(const gfx::Rect& damage_rect) { 37 DCHECK(gfx::Rect(viewport_pixel_size_).Contains(damage_rect)); 38 39 damage_rect_ = damage_rect; 40 41 // Get canvas for next frame. 42 return surface_ozone_->GetCanvas(); 43 } 44 EndPaint()45void SoftwareOutputDeviceOzone::EndPaint() { 46 SoftwareOutputDevice::EndPaint(); 47 48 surface_ozone_->PresentCanvas(damage_rect_); 49 } 50 OnSwapBuffers(SwapBuffersCallback swap_ack_callback)51void SoftwareOutputDeviceOzone::OnSwapBuffers( 52 SwapBuffersCallback swap_ack_callback) { 53 if (surface_ozone_->SupportsAsyncBufferSwap()) 54 surface_ozone_->OnSwapBuffers(std::move(swap_ack_callback)); 55 else 56 SoftwareOutputDevice::OnSwapBuffers(std::move(swap_ack_callback)); 57 } 58 MaxFramesPending() const59int SoftwareOutputDeviceOzone::MaxFramesPending() const { 60 return surface_ozone_->MaxFramesPending(); 61 } 62 63 } // namespace viz 64