1 // Copyright 2013 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/aura/software_output_device_ozone.h"
6 #include "third_party/skia/include/core/SkBitmapDevice.h"
7 #include "third_party/skia/include/core/SkDevice.h"
8 #include "ui/compositor/compositor.h"
9 #include "ui/gfx/ozone/surface_factory_ozone.h"
10 #include "ui/gfx/skia_util.h"
14 SoftwareOutputDeviceOzone::SoftwareOutputDeviceOzone(
15 ui::Compositor* compositor) : compositor_(compositor) {
16 if (gfx::SurfaceFactoryOzone::GetInstance()->InitializeHardware() !=
17 gfx::SurfaceFactoryOzone::INITIALIZED)
18 LOG(FATAL) << "Failed to initialize hardware in OZONE";
21 SoftwareOutputDeviceOzone::~SoftwareOutputDeviceOzone() {
24 void SoftwareOutputDeviceOzone::Resize(gfx::Size viewport_size) {
25 if (viewport_size_ == viewport_size)
28 viewport_size_ = viewport_size;
29 gfx::Rect bounds(viewport_size_);
31 gfx::SurfaceFactoryOzone* factory = gfx::SurfaceFactoryOzone::GetInstance();
32 factory->AttemptToResizeAcceleratedWidget(compositor_->widget(),
34 gfx::AcceleratedWidget realized_widget = factory->RealizeAcceleratedWidget(
35 compositor_->widget());
37 if (realized_widget == gfx::kNullAcceleratedWidget)
38 LOG(FATAL) << "Failed to get a realized AcceleratedWidget";
40 canvas_ = skia::SharePtr(factory->GetCanvasForWidget(realized_widget));
41 device_ = skia::SharePtr(canvas_->getDevice());
44 SkCanvas* SoftwareOutputDeviceOzone::BeginPaint(gfx::Rect damage_rect) {
45 DCHECK(gfx::Rect(viewport_size_).Contains(damage_rect));
47 canvas_->clipRect(gfx::RectToSkRect(damage_rect), SkRegion::kReplace_Op);
48 // Save the current state so we can restore once we're done drawing. This is
49 // saved after the clip since we want to keep the clip information after we're
50 // done drawing such that OZONE knows what was updated.
53 return SoftwareOutputDevice::BeginPaint(damage_rect);
56 void SoftwareOutputDeviceOzone::EndPaint(cc::SoftwareFrameData* frame_data) {
57 SoftwareOutputDevice::EndPaint(frame_data);
61 if (damage_rect_.IsEmpty())
64 bool scheduled = gfx::SurfaceFactoryOzone::GetInstance()->SchedulePageFlip(
65 compositor_->widget());
66 DCHECK(scheduled) << "Failed to schedule pageflip";
69 } // namespace content