| OLD | NEW |
| (Empty) |
| 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/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" | |
| 11 #include "ui/gfx/vsync_provider.h" | |
| 12 | |
| 13 namespace content { | |
| 14 | |
| 15 SoftwareOutputDeviceOzone::SoftwareOutputDeviceOzone(ui::Compositor* compositor) | |
| 16 : compositor_(compositor), realized_widget_(gfx::kNullAcceleratedWidget) { | |
| 17 gfx::SurfaceFactoryOzone* factory = gfx::SurfaceFactoryOzone::GetInstance(); | |
| 18 | |
| 19 if (factory->InitializeHardware() != gfx::SurfaceFactoryOzone::INITIALIZED) | |
| 20 LOG(FATAL) << "Failed to initialize hardware in OZONE"; | |
| 21 | |
| 22 realized_widget_ = factory->RealizeAcceleratedWidget(compositor_->widget()); | |
| 23 | |
| 24 if (realized_widget_ == gfx::kNullAcceleratedWidget) | |
| 25 LOG(FATAL) << "Failed to get a realized AcceleratedWidget"; | |
| 26 | |
| 27 vsync_provider_ = factory->CreateVSyncProvider(realized_widget_); | |
| 28 } | |
| 29 | |
| 30 SoftwareOutputDeviceOzone::~SoftwareOutputDeviceOzone() { | |
| 31 } | |
| 32 | |
| 33 void SoftwareOutputDeviceOzone::Resize(gfx::Size viewport_size) { | |
| 34 if (viewport_size_ == viewport_size) | |
| 35 return; | |
| 36 | |
| 37 viewport_size_ = viewport_size; | |
| 38 gfx::Rect bounds(viewport_size_); | |
| 39 | |
| 40 gfx::SurfaceFactoryOzone* factory = gfx::SurfaceFactoryOzone::GetInstance(); | |
| 41 factory->AttemptToResizeAcceleratedWidget(compositor_->widget(), | |
| 42 bounds); | |
| 43 | |
| 44 canvas_ = skia::SharePtr(factory->GetCanvasForWidget(realized_widget_)); | |
| 45 device_ = skia::SharePtr(canvas_->getDevice()); | |
| 46 } | |
| 47 | |
| 48 SkCanvas* SoftwareOutputDeviceOzone::BeginPaint(const gfx::Rect& damage_rect) { | |
| 49 DCHECK(gfx::Rect(viewport_size_).Contains(damage_rect)); | |
| 50 | |
| 51 canvas_->clipRect(gfx::RectToSkRect(damage_rect), SkRegion::kReplace_Op); | |
| 52 // Save the current state so we can restore once we're done drawing. This is | |
| 53 // saved after the clip since we want to keep the clip information after we're | |
| 54 // done drawing such that OZONE knows what was updated. | |
| 55 canvas_->save(); | |
| 56 | |
| 57 return SoftwareOutputDevice::BeginPaint(damage_rect); | |
| 58 } | |
| 59 | |
| 60 void SoftwareOutputDeviceOzone::EndPaint(cc::SoftwareFrameData* frame_data) { | |
| 61 SoftwareOutputDevice::EndPaint(frame_data); | |
| 62 | |
| 63 canvas_->restore(); | |
| 64 | |
| 65 if (damage_rect_.IsEmpty()) | |
| 66 return; | |
| 67 | |
| 68 bool scheduled = gfx::SurfaceFactoryOzone::GetInstance()->SchedulePageFlip( | |
| 69 compositor_->widget()); | |
| 70 DCHECK(scheduled) << "Failed to schedule pageflip"; | |
| 71 } | |
| 72 | |
| 73 } // namespace content | |
| OLD | NEW |