OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/gfx/ozone/dri/dri_surface_factory.h" | 5 #include "ui/gfx/ozone/dri/dri_surface_factory.h" |
6 | 6 |
7 #include <drm.h> | 7 #include <drm.h> |
8 #include <errno.h> | 8 #include <errno.h> |
9 #include <xf86drm.h> | 9 #include <xf86drm.h> |
10 | 10 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 HardwareDisplayController::UNASSOCIATED); | 162 HardwareDisplayController::UNASSOCIATED); |
163 | 163 |
164 // Until now the controller is just a stub. Initializing it will link it to a | 164 // Until now the controller is just a stub. Initializing it will link it to a |
165 // hardware display. | 165 // hardware display. |
166 if (!InitializeControllerForPrimaryDisplay(drm_.get(), controller_.get())) { | 166 if (!InitializeControllerForPrimaryDisplay(drm_.get(), controller_.get())) { |
167 LOG(ERROR) << "Failed to initialize controller"; | 167 LOG(ERROR) << "Failed to initialize controller"; |
168 return gfx::kNullAcceleratedWidget; | 168 return gfx::kNullAcceleratedWidget; |
169 } | 169 } |
170 | 170 |
171 // Create a surface suitable for the current controller. | 171 // Create a surface suitable for the current controller. |
172 scoped_ptr<DriSurface> surface(CreateSurface(controller_.get())); | 172 scoped_ptr<ScanoutSurface> surface(CreateSurface(controller_.get())); |
173 | 173 |
174 if (!surface->Initialize()) { | 174 if (!surface->Initialize()) { |
175 LOG(ERROR) << "Failed to initialize surface"; | 175 LOG(ERROR) << "Failed to initialize surface"; |
176 return gfx::kNullAcceleratedWidget; | 176 return gfx::kNullAcceleratedWidget; |
177 } | 177 } |
178 | 178 |
179 // Bind the surface to the controller. This will register the backing buffers | 179 // Bind the surface to the controller. The controller takes ownership of the |
180 // with the hardware CRTC such that we can show the buffers. The controller | 180 // surface. |
181 // takes ownership of the surface. | |
182 if (!controller_->BindSurfaceToController(surface.Pass())) { | 181 if (!controller_->BindSurfaceToController(surface.Pass())) { |
183 LOG(ERROR) << "Failed to bind surface to controller"; | 182 LOG(ERROR) << "Failed to bind surface to controller"; |
184 return gfx::kNullAcceleratedWidget; | 183 return gfx::kNullAcceleratedWidget; |
185 } | 184 } |
186 | 185 |
187 return reinterpret_cast<gfx::AcceleratedWidget>(controller_->get_surface()); | 186 return GetNativeWidget(controller_->get_surface()); |
188 } | 187 } |
189 | 188 |
190 bool DriSurfaceFactory::LoadEGLGLES2Bindings( | 189 bool DriSurfaceFactory::LoadEGLGLES2Bindings( |
191 AddGLLibraryCallback add_gl_library, | 190 AddGLLibraryCallback add_gl_library, |
192 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { | 191 SetGLGetProcAddressProcCallback set_gl_get_proc_address) { |
193 return false; | 192 return false; |
194 } | 193 } |
195 | 194 |
196 bool DriSurfaceFactory::AttemptToResizeAcceleratedWidget( | 195 bool DriSurfaceFactory::AttemptToResizeAcceleratedWidget( |
197 gfx::AcceleratedWidget w, | 196 gfx::AcceleratedWidget w, |
198 const gfx::Rect& bounds) { | 197 const gfx::Rect& bounds) { |
199 return false; | 198 return false; |
200 } | 199 } |
201 | 200 |
202 bool DriSurfaceFactory::SchedulePageFlip(gfx::AcceleratedWidget w) { | 201 bool DriSurfaceFactory::SchedulePageFlip(gfx::AcceleratedWidget w) { |
203 CHECK(state_ == INITIALIZED); | 202 CHECK(state_ == INITIALIZED); |
204 // TODO(dnicoara) Change this CHECK once we're running with the threaded | 203 // TODO(dnicoara) Change this CHECK once we're running with the threaded |
205 // compositor. | 204 // compositor. |
206 CHECK(base::MessageLoop::current()->type() == base::MessageLoop::TYPE_UI); | 205 //CHECK(base::MessageLoop::current()->type() == base::MessageLoop::TYPE_UI); |
207 | 206 |
208 // TODO(dnicoara) Once we can handle multiple displays this needs to be | 207 // TODO(dnicoara) Once we can handle multiple displays this needs to be |
209 // changed. | 208 // changed. |
210 CHECK(w == kDefaultWidgetHandle); | 209 CHECK(w == kDefaultWidgetHandle); |
211 | 210 |
212 if (!controller_->SchedulePageFlip()) | 211 if (!controller_->SchedulePageFlip()) |
213 return false; | 212 return false; |
214 | 213 |
215 // Only wait for the page flip event to finish if it was properly scheduled. | 214 // Only wait for the page flip event to finish if it was properly scheduled. |
216 // | 215 // |
(...skipping 22 matching lines...) Expand all Loading... |
239 | 238 |
240 gfx::VSyncProvider* DriSurfaceFactory::GetVSyncProvider( | 239 gfx::VSyncProvider* DriSurfaceFactory::GetVSyncProvider( |
241 gfx::AcceleratedWidget w) { | 240 gfx::AcceleratedWidget w) { |
242 CHECK(state_ == INITIALIZED); | 241 CHECK(state_ == INITIALIZED); |
243 return new DriVSyncProvider(controller_.get()); | 242 return new DriVSyncProvider(controller_.get()); |
244 } | 243 } |
245 | 244 |
246 //////////////////////////////////////////////////////////////////////////////// | 245 //////////////////////////////////////////////////////////////////////////////// |
247 // DriSurfaceFactory private | 246 // DriSurfaceFactory private |
248 | 247 |
249 DriSurface* DriSurfaceFactory::CreateSurface( | 248 ScanoutSurface* DriSurfaceFactory::CreateSurface( |
250 HardwareDisplayController* controller) { | 249 HardwareDisplayController* controller) { |
251 return new DriSurface(controller); | 250 return new DriSurface(controller); |
252 } | 251 } |
253 | 252 |
254 DriWrapper* DriSurfaceFactory::CreateWrapper() { | 253 DriWrapper* DriSurfaceFactory::CreateWrapper() { |
255 return new DriWrapper(kDefaultGraphicsCardPath); | 254 return new DriWrapper(kDefaultGraphicsCardPath); |
256 } | 255 } |
257 | 256 |
| 257 gfx::AcceleratedWidget DriSurfaceFactory::GetNativeWidget( |
| 258 ScanoutSurface* surface) { |
| 259 return reinterpret_cast<gfx::AcceleratedWidget>(surface); |
| 260 } |
| 261 |
258 bool DriSurfaceFactory::InitializeControllerForPrimaryDisplay( | 262 bool DriSurfaceFactory::InitializeControllerForPrimaryDisplay( |
259 DriWrapper* drm, | 263 DriWrapper* drm, |
260 HardwareDisplayController* controller) { | 264 HardwareDisplayController* controller) { |
261 CHECK(state_ == SurfaceFactoryOzone::INITIALIZED); | 265 CHECK(state_ == SurfaceFactoryOzone::INITIALIZED); |
262 | 266 |
263 drmModeRes* resources = drmModeGetResources(drm->get_fd()); | 267 drmModeRes* resources = drmModeGetResources(drm->get_fd()); |
264 | 268 |
265 // Search for an active connector. | 269 // Search for an active connector. |
266 for (int i = 0; i < resources->count_connectors; ++i) { | 270 for (int i = 0; i < resources->count_connectors; ++i) { |
267 drmModeConnector* connector = drmModeGetConnector( | 271 drmModeConnector* connector = drmModeGetConnector( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 drmEventContext drm_event; | 312 drmEventContext drm_event; |
309 drm_event.version = DRM_EVENT_CONTEXT_VERSION; | 313 drm_event.version = DRM_EVENT_CONTEXT_VERSION; |
310 drm_event.page_flip_handler = HandlePageFlipEvent; | 314 drm_event.page_flip_handler = HandlePageFlipEvent; |
311 drm_event.vblank_handler = NULL; | 315 drm_event.vblank_handler = NULL; |
312 | 316 |
313 // Wait for the page-flip to complete. | 317 // Wait for the page-flip to complete. |
314 drmHandleEvent(fd, &drm_event); | 318 drmHandleEvent(fd, &drm_event); |
315 } | 319 } |
316 | 320 |
317 } // namespace gfx | 321 } // namespace gfx |
OLD | NEW |