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/gbm_surface_factory.h" | 5 #include "ui/ozone/platform/dri/gbm_surface_factory.h" |
6 | 6 |
7 #include <EGL/egl.h> | 7 #include <EGL/egl.h> |
8 #include <gbm.h> | 8 #include <gbm.h> |
9 | 9 |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
11 #include "ui/ozone/platform/dri/dri_vsync_provider.h" | |
12 #include "ui/ozone/platform/dri/gbm_buffer.h" | 11 #include "ui/ozone/platform/dri/gbm_buffer.h" |
13 #include "ui/ozone/platform/dri/gbm_surface.h" | 12 #include "ui/ozone/platform/dri/gbm_surface.h" |
14 #include "ui/ozone/platform/dri/hardware_display_controller.h" | 13 #include "ui/ozone/platform/dri/gbm_surfaceless.h" |
15 #include "ui/ozone/platform/dri/scanout_surface.h" | |
16 #include "ui/ozone/platform/dri/screen_manager.h" | 14 #include "ui/ozone/platform/dri/screen_manager.h" |
17 #include "ui/ozone/public/native_pixmap.h" | 15 #include "ui/ozone/public/native_pixmap.h" |
18 #include "ui/ozone/public/surface_ozone_egl.h" | 16 #include "ui/ozone/public/surface_ozone_egl.h" |
19 | 17 |
20 namespace ui { | 18 namespace ui { |
21 | 19 |
22 namespace { | |
23 | |
24 class GbmSurfaceAdapter : public ui::SurfaceOzoneEGL { | |
25 public: | |
26 GbmSurfaceAdapter( | |
27 gbm_device* device, | |
28 DriWrapper* dri, | |
29 const base::WeakPtr<HardwareDisplayController>& controller); | |
30 virtual ~GbmSurfaceAdapter(); | |
31 | |
32 bool Initialize(); | |
33 | |
34 // SurfaceOzoneEGL: | |
35 virtual intptr_t GetNativeWindow() OVERRIDE; | |
36 virtual bool ResizeNativeWindow(const gfx::Size& viewport_size) OVERRIDE; | |
37 virtual bool OnSwapBuffers() OVERRIDE; | |
38 virtual scoped_ptr<gfx::VSyncProvider> CreateVSyncProvider() OVERRIDE; | |
39 virtual bool ScheduleOverlayPlane(int plane_z_order, | |
40 gfx::OverlayTransform plane_transform, | |
41 scoped_refptr<ui::NativePixmap> buffer, | |
42 const gfx::Rect& display_bounds, | |
43 const gfx::RectF& crop_rect) OVERRIDE; | |
44 | |
45 private: | |
46 gbm_device* device_; | |
47 DriWrapper* dri_; | |
48 scoped_ptr<GbmSurface> surface_; | |
49 base::WeakPtr<HardwareDisplayController> controller_; | |
50 OverlayPlaneList overlays_; | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(GbmSurfaceAdapter); | |
53 }; | |
54 | |
55 GbmSurfaceAdapter::GbmSurfaceAdapter( | |
56 gbm_device* device, | |
57 DriWrapper* dri, | |
58 const base::WeakPtr<HardwareDisplayController>& controller) | |
59 : device_(device), dri_(dri), controller_(controller) {} | |
60 | |
61 GbmSurfaceAdapter::~GbmSurfaceAdapter() {} | |
62 | |
63 bool GbmSurfaceAdapter::Initialize() { | |
64 if (controller_) { | |
65 surface_.reset( | |
66 new GbmSurface(device_, | |
67 dri_, | |
68 gfx::Size(controller_->get_mode().hdisplay, | |
69 controller_->get_mode().vdisplay))); | |
70 return surface_->Initialize(); | |
71 } | |
72 | |
73 return false; | |
74 } | |
75 | |
76 intptr_t GbmSurfaceAdapter::GetNativeWindow() { | |
77 if (!controller_) | |
78 return 0; | |
79 | |
80 return reinterpret_cast<intptr_t>(surface_->native_surface()); | |
81 } | |
82 | |
83 bool GbmSurfaceAdapter::ResizeNativeWindow(const gfx::Size& viewport_size) { | |
84 | |
85 return true; | |
86 } | |
87 | |
88 bool GbmSurfaceAdapter::OnSwapBuffers() { | |
89 if (!controller_) | |
90 return false; | |
91 if (surface_) { | |
92 surface_->PreSwapBuffers(); | |
93 overlays_.push_back(OverlayPlane(surface_->backbuffer())); | |
94 } | |
95 | |
96 bool flip_succeeded = controller_->SchedulePageFlip(overlays_); | |
97 overlays_.clear(); | |
98 if (flip_succeeded) | |
99 controller_->WaitForPageFlipEvent(); | |
100 | |
101 if (surface_) | |
102 surface_->SwapBuffers(); | |
103 | |
104 return flip_succeeded; | |
105 } | |
106 | |
107 bool GbmSurfaceAdapter::ScheduleOverlayPlane( | |
108 int plane_z_order, | |
109 gfx::OverlayTransform plane_transform, | |
110 scoped_refptr<NativePixmap> buffer, | |
111 const gfx::Rect& display_bounds, | |
112 const gfx::RectF& crop_rect) { | |
113 GbmPixmap* pixmap = static_cast<GbmPixmap*>(buffer.get()); | |
114 if (!pixmap) { | |
115 LOG(ERROR) << "ScheduleOverlayPlane passed NULL buffer"; | |
116 return false; | |
117 } | |
118 overlays_.push_back(OverlayPlane(pixmap->buffer(), | |
119 plane_z_order, | |
120 plane_transform, | |
121 display_bounds, | |
122 crop_rect)); | |
123 return true; | |
124 } | |
125 | |
126 scoped_ptr<gfx::VSyncProvider> GbmSurfaceAdapter::CreateVSyncProvider() { | |
127 return scoped_ptr<gfx::VSyncProvider>(new DriVSyncProvider(controller_)); | |
128 } | |
129 | |
130 } // namespace | |
131 | |
132 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) | 20 GbmSurfaceFactory::GbmSurfaceFactory(bool allow_surfaceless) |
133 : DriSurfaceFactory(NULL, NULL), | 21 : DriSurfaceFactory(NULL, NULL), |
134 device_(NULL), | 22 device_(NULL), |
135 allow_surfaceless_(allow_surfaceless) { | 23 allow_surfaceless_(allow_surfaceless) { |
136 } | 24 } |
137 | 25 |
138 GbmSurfaceFactory::~GbmSurfaceFactory() {} | 26 GbmSurfaceFactory::~GbmSurfaceFactory() {} |
139 | 27 |
140 void GbmSurfaceFactory::InitializeGpu( | 28 void GbmSurfaceFactory::InitializeGpu( |
141 DriWrapper* dri, gbm_device* device, ScreenManager* screen_manager) { | 29 DriWrapper* dri, gbm_device* device, ScreenManager* screen_manager) { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 return false; | 85 return false; |
198 } | 86 } |
199 | 87 |
200 set_gl_get_proc_address.Run(get_proc_address); | 88 set_gl_get_proc_address.Run(get_proc_address); |
201 add_gl_library.Run(egl_library); | 89 add_gl_library.Run(egl_library); |
202 add_gl_library.Run(gles_library); | 90 add_gl_library.Run(gles_library); |
203 | 91 |
204 return true; | 92 return true; |
205 } | 93 } |
206 | 94 |
207 scoped_ptr<ui::SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( | 95 scoped_ptr<SurfaceOzoneEGL> GbmSurfaceFactory::CreateEGLSurfaceForWidget( |
208 gfx::AcceleratedWidget w) { | 96 gfx::AcceleratedWidget widget) { |
209 CHECK(state_ == INITIALIZED); | 97 CHECK(state_ == INITIALIZED); |
210 ResetCursor(w); | 98 ResetCursor(widget); |
211 | 99 |
212 scoped_ptr<GbmSurfaceAdapter> surface( | 100 if (allow_surfaceless_) { |
213 new GbmSurfaceAdapter(device_, | 101 return scoped_ptr<SurfaceOzoneEGL>( |
214 drm_, | 102 new GbmSurfaceless(screen_manager_->GetDisplayController(widget))); |
215 screen_manager_->GetDisplayController(w))); | 103 } else { |
216 if (!allow_surfaceless_ && !surface->Initialize()) | 104 scoped_ptr<GbmSurface> surface( |
217 return scoped_ptr<SurfaceOzoneEGL>(); | 105 new GbmSurface(screen_manager_->GetDisplayController(widget), |
| 106 device_, |
| 107 drm_)); |
| 108 if (!surface->Initialize()) |
| 109 return scoped_ptr<SurfaceOzoneEGL>(); |
218 | 110 |
219 return surface.PassAs<SurfaceOzoneEGL>(); | 111 return surface.PassAs<SurfaceOzoneEGL>(); |
| 112 } |
220 } | 113 } |
221 | 114 |
222 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( | 115 scoped_refptr<ui::NativePixmap> GbmSurfaceFactory::CreateNativePixmap( |
223 gfx::Size size, | 116 gfx::Size size, |
224 BufferFormat format) { | 117 BufferFormat format) { |
225 scoped_refptr<GbmBuffer> buffer = GbmBuffer::CreateBuffer( | 118 scoped_refptr<GbmBuffer> buffer = GbmBuffer::CreateBuffer( |
226 drm_, device_, format, size, true); | 119 drm_, device_, format, size, true); |
227 if (!buffer) | 120 if (!buffer) |
228 return NULL; | 121 return NULL; |
229 | 122 |
230 return scoped_refptr<GbmPixmap>(new GbmPixmap(buffer)); | 123 return scoped_refptr<GbmPixmap>(new GbmPixmap(buffer)); |
231 } | 124 } |
232 | 125 |
233 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { | 126 bool GbmSurfaceFactory::CanShowPrimaryPlaneAsOverlay() { |
234 return allow_surfaceless_; | 127 return allow_surfaceless_; |
235 } | 128 } |
236 | 129 |
237 } // namespace ui | 130 } // namespace ui |
OLD | NEW |