OLD | NEW |
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/gfx/ozone/surface_ozone_canvas.h" | |
16 #include "ui/ozone/platform/dri/dri_surface.h" | 15 #include "ui/ozone/platform/dri/dri_surface.h" |
17 #include "ui/ozone/platform/dri/dri_util.h" | 16 #include "ui/ozone/platform/dri/dri_util.h" |
18 #include "ui/ozone/platform/dri/dri_vsync_provider.h" | 17 #include "ui/ozone/platform/dri/dri_vsync_provider.h" |
19 #include "ui/ozone/platform/dri/dri_wrapper.h" | 18 #include "ui/ozone/platform/dri/dri_wrapper.h" |
20 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 19 #include "ui/ozone/platform/dri/hardware_display_controller.h" |
21 #include "ui/ozone/platform/dri/screen_manager.h" | 20 #include "ui/ozone/platform/dri/screen_manager.h" |
| 21 #include "ui/ozone/public/surface_ozone_canvas.h" |
22 | 22 |
23 namespace ui { | 23 namespace ui { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // TODO(dnicoara) Read the cursor plane size from the hardware. | 27 // TODO(dnicoara) Read the cursor plane size from the hardware. |
28 const gfx::Size kCursorSize(64, 64); | 28 const gfx::Size kCursorSize(64, 64); |
29 | 29 |
30 void UpdateCursorImage(DriSurface* cursor, const SkBitmap& image) { | 30 void UpdateCursorImage(DriSurface* cursor, const SkBitmap& image) { |
31 SkRect damage; | 31 SkRect damage; |
32 image.getBounds(&damage); | 32 image.getBounds(&damage); |
33 | 33 |
34 // Clear to transparent in case |image| is smaller than the canvas. | 34 // Clear to transparent in case |image| is smaller than the canvas. |
35 SkCanvas* canvas = cursor->GetDrawableForWidget(); | 35 SkCanvas* canvas = cursor->GetDrawableForWidget(); |
36 canvas->clear(SK_ColorTRANSPARENT); | 36 canvas->clear(SK_ColorTRANSPARENT); |
37 | 37 |
38 SkRect clip; | 38 SkRect clip; |
39 clip.set( | 39 clip.set( |
40 0, 0, canvas->getDeviceSize().width(), canvas->getDeviceSize().height()); | 40 0, 0, canvas->getDeviceSize().width(), canvas->getDeviceSize().height()); |
41 canvas->clipRect(clip, SkRegion::kReplace_Op); | 41 canvas->clipRect(clip, SkRegion::kReplace_Op); |
42 canvas->drawBitmapRectToRect(image, &damage, damage); | 42 canvas->drawBitmapRectToRect(image, &damage, damage); |
43 } | 43 } |
44 | 44 |
45 class DriSurfaceAdapter : public gfx::SurfaceOzoneCanvas { | 45 class DriSurfaceAdapter : public ui::SurfaceOzoneCanvas { |
46 public: | 46 public: |
47 DriSurfaceAdapter(const base::WeakPtr<HardwareDisplayController>& controller); | 47 DriSurfaceAdapter(const base::WeakPtr<HardwareDisplayController>& controller); |
48 virtual ~DriSurfaceAdapter(); | 48 virtual ~DriSurfaceAdapter(); |
49 | 49 |
50 // SurfaceOzoneCanvas: | 50 // SurfaceOzoneCanvas: |
51 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE; | 51 virtual skia::RefPtr<SkCanvas> GetCanvas() OVERRIDE; |
52 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE; | 52 virtual void ResizeCanvas(const gfx::Size& viewport_size) OVERRIDE; |
53 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE; | 53 virtual void PresentCanvas(const gfx::Rect& damage) OVERRIDE; |
54 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; | 54 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; |
55 | 55 |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 screen_manager_(screen_manager), | 121 screen_manager_(screen_manager), |
122 state_(UNINITIALIZED), | 122 state_(UNINITIALIZED), |
123 allocated_widgets_(0) { | 123 allocated_widgets_(0) { |
124 } | 124 } |
125 | 125 |
126 DriSurfaceFactory::~DriSurfaceFactory() { | 126 DriSurfaceFactory::~DriSurfaceFactory() { |
127 if (state_ == INITIALIZED) | 127 if (state_ == INITIALIZED) |
128 ShutdownHardware(); | 128 ShutdownHardware(); |
129 } | 129 } |
130 | 130 |
131 gfx::SurfaceFactoryOzone::HardwareState | 131 ui::SurfaceFactoryOzone::HardwareState DriSurfaceFactory::InitializeHardware() { |
132 DriSurfaceFactory::InitializeHardware() { | |
133 if (state_ != UNINITIALIZED) | 132 if (state_ != UNINITIALIZED) |
134 return state_; | 133 return state_; |
135 | 134 |
136 if (drm_->get_fd() < 0) { | 135 if (drm_->get_fd() < 0) { |
137 LOG(ERROR) << "Failed to create DRI connection"; | 136 LOG(ERROR) << "Failed to create DRI connection"; |
138 state_ = FAILED; | 137 state_ = FAILED; |
139 return state_; | 138 return state_; |
140 } | 139 } |
141 | 140 |
142 cursor_surface_.reset(CreateSurface(kCursorSize)); | 141 cursor_surface_.reset(CreateSurface(kCursorSize)); |
(...skipping 13 matching lines...) Expand all Loading... |
156 } | 155 } |
157 | 156 |
158 gfx::AcceleratedWidget DriSurfaceFactory::GetAcceleratedWidget() { | 157 gfx::AcceleratedWidget DriSurfaceFactory::GetAcceleratedWidget() { |
159 CHECK(state_ != FAILED); | 158 CHECK(state_ != FAILED); |
160 | 159 |
161 // We're not using 0 since other code assumes that a 0 AcceleratedWidget is an | 160 // We're not using 0 since other code assumes that a 0 AcceleratedWidget is an |
162 // invalid widget. | 161 // invalid widget. |
163 return ++allocated_widgets_; | 162 return ++allocated_widgets_; |
164 } | 163 } |
165 | 164 |
166 scoped_ptr<gfx::SurfaceOzoneCanvas> DriSurfaceFactory::CreateCanvasForWidget( | 165 scoped_ptr<ui::SurfaceOzoneCanvas> DriSurfaceFactory::CreateCanvasForWidget( |
167 gfx::AcceleratedWidget w) { | 166 gfx::AcceleratedWidget w) { |
168 CHECK(state_ == INITIALIZED); | 167 CHECK(state_ == INITIALIZED); |
169 // Initial cursor set. | 168 // Initial cursor set. |
170 ResetCursor(w); | 169 ResetCursor(w); |
171 | 170 |
172 return scoped_ptr<gfx::SurfaceOzoneCanvas>( | 171 return scoped_ptr<ui::SurfaceOzoneCanvas>( |
173 new DriSurfaceAdapter(screen_manager_->GetDisplayController(w))); | 172 new DriSurfaceAdapter(screen_manager_->GetDisplayController(w))); |
174 } | 173 } |
175 | 174 |
176 bool DriSurfaceFactory::LoadEGLGLES2Bindings( | 175 bool DriSurfaceFactory::LoadEGLGLES2Bindings( |
177 AddGLLibraryCallback add_gl_library, | 176 AddGLLibraryCallback add_gl_library, |
178 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 177 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
179 return false; | 178 return false; |
180 } | 179 } |
181 | 180 |
182 gfx::Size DriSurfaceFactory::GetWidgetSize(gfx::AcceleratedWidget w) { | 181 gfx::Size DriSurfaceFactory::GetWidgetSize(gfx::AcceleratedWidget w) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 controller->SetCursor(cursor_surface_.get()); | 243 controller->SetCursor(cursor_surface_.get()); |
245 } | 244 } |
246 } else { | 245 } else { |
247 // No cursor set. | 246 // No cursor set. |
248 if (controller) | 247 if (controller) |
249 controller->UnsetCursor(); | 248 controller->UnsetCursor(); |
250 } | 249 } |
251 } | 250 } |
252 | 251 |
253 } // namespace ui | 252 } // namespace ui |
OLD | NEW |