Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / content / browser / compositor / software_output_device_ozone.cc
blob0476ccb0fccfd3476d49d7b185153c896db17699
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/skia_util.h"
9 #include "ui/gfx/vsync_provider.h"
10 #include "ui/ozone/public/ozone_platform.h"
11 #include "ui/ozone/public/surface_factory_ozone.h"
12 #include "ui/ozone/public/surface_ozone_canvas.h"
14 namespace content {
16 SoftwareOutputDeviceOzone::SoftwareOutputDeviceOzone(ui::Compositor* compositor)
17 : compositor_(compositor) {
18 ui::SurfaceFactoryOzone* factory =
19 ui::OzonePlatform::GetInstance()->GetSurfaceFactoryOzone();
21 surface_ozone_ = factory->CreateCanvasForWidget(compositor_->widget());
23 if (!surface_ozone_)
24 LOG(FATAL) << "Failed to initialize canvas";
26 vsync_provider_ = surface_ozone_->CreateVSyncProvider();
29 SoftwareOutputDeviceOzone::~SoftwareOutputDeviceOzone() {
32 void SoftwareOutputDeviceOzone::Resize(const gfx::Size& viewport_pixel_size,
33 float scale_factor) {
34 scale_factor_ = scale_factor;
36 if (viewport_pixel_size_ == viewport_pixel_size)
37 return;
39 viewport_pixel_size_ = viewport_pixel_size;
41 surface_ozone_->ResizeCanvas(viewport_pixel_size_);
44 SkCanvas* SoftwareOutputDeviceOzone::BeginPaint(const gfx::Rect& damage_rect) {
45 DCHECK(gfx::Rect(viewport_pixel_size_).Contains(damage_rect));
47 // Get canvas for next frame.
48 surface_ = surface_ozone_->GetSurface();
50 return SoftwareOutputDevice::BeginPaint(damage_rect);
53 void SoftwareOutputDeviceOzone::EndPaint() {
54 SoftwareOutputDevice::EndPaint();
56 surface_ozone_->PresentCanvas(damage_rect_);
59 } // namespace content