Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(993)

Side by Side Diff: ui/ozone/platform/dri/dri_surface_factory.cc

Issue 407603002: [Ozone-DRI] Migrate cursor to using ScanoutBuffer (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/ozone/platform/dri/dri_surface_factory.h ('k') | ui/ozone/platform/dri/dri_wrapper.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/ozone/platform/dri/dri_surface_factory.h" 5 #include "ui/ozone/platform/dri/dri_surface_factory.h"
6 6
7 #include <errno.h> 7 #include <errno.h>
8 8
9 #include "base/debug/trace_event.h" 9 #include "base/debug/trace_event.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "third_party/skia/include/core/SkBitmap.h" 11 #include "third_party/skia/include/core/SkBitmap.h"
12 #include "third_party/skia/include/core/SkDevice.h" 12 #include "third_party/skia/include/core/SkDevice.h"
13 #include "third_party/skia/include/core/SkSurface.h" 13 #include "third_party/skia/include/core/SkSurface.h"
14 #include "ui/gfx/native_widget_types.h" 14 #include "ui/gfx/native_widget_types.h"
15 #include "ui/ozone/platform/dri/dri_buffer.h"
15 #include "ui/ozone/platform/dri/dri_surface.h" 16 #include "ui/ozone/platform/dri/dri_surface.h"
16 #include "ui/ozone/platform/dri/dri_util.h" 17 #include "ui/ozone/platform/dri/dri_util.h"
17 #include "ui/ozone/platform/dri/dri_vsync_provider.h" 18 #include "ui/ozone/platform/dri/dri_vsync_provider.h"
18 #include "ui/ozone/platform/dri/dri_wrapper.h" 19 #include "ui/ozone/platform/dri/dri_wrapper.h"
19 #include "ui/ozone/platform/dri/hardware_display_controller.h" 20 #include "ui/ozone/platform/dri/hardware_display_controller.h"
20 #include "ui/ozone/platform/dri/screen_manager.h" 21 #include "ui/ozone/platform/dri/screen_manager.h"
21 #include "ui/ozone/public/surface_ozone_canvas.h" 22 #include "ui/ozone/public/surface_ozone_canvas.h"
22 23
23 namespace ui { 24 namespace ui {
24 25
25 namespace { 26 namespace {
26 27
27 // TODO(dnicoara) Read the cursor plane size from the hardware. 28 // TODO(dnicoara) Read the cursor plane size from the hardware.
28 const gfx::Size kCursorSize(64, 64); 29 const gfx::Size kCursorSize(64, 64);
29 30
30 void UpdateCursorImage(DriSurface* cursor, const SkBitmap& image) { 31 void UpdateCursorImage(DriBuffer* cursor, const SkBitmap& image) {
31 SkRect damage; 32 SkRect damage;
32 image.getBounds(&damage); 33 image.getBounds(&damage);
33 34
34 // Clear to transparent in case |image| is smaller than the canvas. 35 // Clear to transparent in case |image| is smaller than the canvas.
35 SkCanvas* canvas = cursor->GetDrawableForWidget(); 36 SkCanvas* canvas = cursor->GetCanvas();
36 canvas->clear(SK_ColorTRANSPARENT); 37 canvas->clear(SK_ColorTRANSPARENT);
37 38
38 SkRect clip; 39 SkRect clip;
39 clip.set( 40 clip.set(
40 0, 0, canvas->getDeviceSize().width(), canvas->getDeviceSize().height()); 41 0, 0, canvas->getDeviceSize().width(), canvas->getDeviceSize().height());
41 canvas->clipRect(clip, SkRegion::kReplace_Op); 42 canvas->clipRect(clip, SkRegion::kReplace_Op);
42 canvas->drawBitmapRectToRect(image, &damage, damage); 43 canvas->drawBitmapRectToRect(image, &damage, damage);
43 } 44 }
44 45
45 class DriSurfaceAdapter : public ui::SurfaceOzoneCanvas { 46 class DriSurfaceAdapter : public ui::SurfaceOzoneCanvas {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 } // namespace 114 } // namespace
114 115
115 // static 116 // static
116 const gfx::AcceleratedWidget DriSurfaceFactory::kDefaultWidgetHandle = 1; 117 const gfx::AcceleratedWidget DriSurfaceFactory::kDefaultWidgetHandle = 1;
117 118
118 DriSurfaceFactory::DriSurfaceFactory(DriWrapper* drm, 119 DriSurfaceFactory::DriSurfaceFactory(DriWrapper* drm,
119 ScreenManager* screen_manager) 120 ScreenManager* screen_manager)
120 : drm_(drm), 121 : drm_(drm),
121 screen_manager_(screen_manager), 122 screen_manager_(screen_manager),
122 state_(UNINITIALIZED), 123 state_(UNINITIALIZED),
123 allocated_widgets_(0) { 124 allocated_widgets_(0),
125 cursor_frontbuffer_(0) {
124 } 126 }
125 127
126 DriSurfaceFactory::~DriSurfaceFactory() { 128 DriSurfaceFactory::~DriSurfaceFactory() {
127 if (state_ == INITIALIZED) 129 if (state_ == INITIALIZED)
128 ShutdownHardware(); 130 ShutdownHardware();
129 } 131 }
130 132
131 ui::SurfaceFactoryOzone::HardwareState DriSurfaceFactory::InitializeHardware() { 133 ui::SurfaceFactoryOzone::HardwareState DriSurfaceFactory::InitializeHardware() {
132 if (state_ != UNINITIALIZED) 134 if (state_ != UNINITIALIZED)
133 return state_; 135 return state_;
134 136
135 if (drm_->get_fd() < 0) { 137 if (drm_->get_fd() < 0) {
136 LOG(ERROR) << "Failed to create DRI connection"; 138 LOG(ERROR) << "Failed to create DRI connection";
137 state_ = FAILED; 139 state_ = FAILED;
138 return state_; 140 return state_;
139 } 141 }
140 142
141 cursor_surface_.reset(CreateSurface(kCursorSize)); 143 SkImageInfo info = SkImageInfo::MakeN32Premul(kCursorSize.width(),
142 if (!cursor_surface_->Initialize()) { 144 kCursorSize.height());
143 LOG(ERROR) << "Failed to initialize cursor surface"; 145 for (size_t i = 0; i < arraysize(cursor_buffers_); ++i) {
144 state_ = FAILED; 146 cursor_buffers_[i] = new DriBuffer(drm_);
alexst (slow to review) 2014/07/18 18:34:59 nit: probably not a big deal, given things have to
dnicoara 2014/07/18 18:38:56 SFO keeps track of them and since they're scoped_r
145 return state_; 147 if (!cursor_buffers_[i]->Initialize(info)) {
148 LOG(ERROR) << "Failed to initialize cursor buffer";
149 state_ = FAILED;
150 return state_;
151 }
146 } 152 }
147 153
148 state_ = INITIALIZED; 154 state_ = INITIALIZED;
149 return state_; 155 return state_;
150 } 156 }
151 157
152 void DriSurfaceFactory::ShutdownHardware() { 158 void DriSurfaceFactory::ShutdownHardware() {
153 CHECK(state_ == INITIALIZED); 159 CHECK(state_ == INITIALIZED);
154 state_ = UNINITIALIZED; 160 state_ = UNINITIALIZED;
155 } 161 }
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
209 215
210 base::WeakPtr<HardwareDisplayController> controller = 216 base::WeakPtr<HardwareDisplayController> controller =
211 screen_manager_->GetDisplayController(window); 217 screen_manager_->GetDisplayController(window);
212 if (controller) 218 if (controller)
213 controller->MoveCursor(location); 219 controller->MoveCursor(location);
214 } 220 }
215 221
216 //////////////////////////////////////////////////////////////////////////////// 222 ////////////////////////////////////////////////////////////////////////////////
217 // DriSurfaceFactory private 223 // DriSurfaceFactory private
218 224
219 DriSurface* DriSurfaceFactory::CreateSurface(const gfx::Size& size) {
220 return new DriSurface(drm_, size);
221 }
222
223 void DriSurfaceFactory::ResetCursor(gfx::AcceleratedWidget w) { 225 void DriSurfaceFactory::ResetCursor(gfx::AcceleratedWidget w) {
224 base::WeakPtr<HardwareDisplayController> controller = 226 base::WeakPtr<HardwareDisplayController> controller =
225 screen_manager_->GetDisplayController(w); 227 screen_manager_->GetDisplayController(w);
226 228
227 if (!cursor_bitmap_.empty()) { 229 if (!cursor_bitmap_.empty()) {
228 // Draw new cursor into backbuffer. 230 // Draw new cursor into backbuffer.
229 UpdateCursorImage(cursor_surface_.get(), cursor_bitmap_); 231 UpdateCursorImage(cursor_buffers_[cursor_frontbuffer_ ^ 1].get(),
232 cursor_bitmap_);
230 233
231 // Reset location & buffer. 234 // Reset location & buffer.
232 if (controller) { 235 if (controller) {
233 controller->MoveCursor(cursor_location_); 236 controller->MoveCursor(cursor_location_);
234 controller->SetCursor(cursor_surface_.get()); 237 controller->SetCursor(cursor_buffers_[cursor_frontbuffer_ ^ 1]);
238 cursor_frontbuffer_ ^= 1;
235 } 239 }
236 } else { 240 } else {
237 // No cursor set. 241 // No cursor set.
238 if (controller) 242 if (controller)
239 controller->UnsetCursor(); 243 controller->UnsetCursor();
240 } 244 }
241 } 245 }
242 246
243 } // namespace ui 247 } // namespace ui
OLDNEW
« no previous file with comments | « ui/ozone/platform/dri/dri_surface_factory.h ('k') | ui/ozone/platform/dri/dri_wrapper.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698