OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/gl/gl_surface.h" | 5 #include "ui/gl/gl_surface.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 #include <X11/Xlib.h> | |
8 | 9 |
9 #include "base/logging.h" | 10 #include "base/logging.h" |
10 #include "base/macros.h" | 11 #include "base/macros.h" |
11 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
12 #include "base/message_loop/message_loop.h" | 13 #include "base/message_loop/message_loop.h" |
13 #include "base/trace_event/trace_event.h" | 14 #include "base/trace_event/trace_event.h" |
15 #include "ui/events/platform/platform_event_dispatcher.h" | |
16 #include "ui/events/platform/platform_event_source.h" | |
14 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
15 #include "ui/gfx/x/x11_types.h" | 18 #include "ui/gfx/x/x11_types.h" |
16 #include "ui/gl/gl_bindings.h" | 19 #include "ui/gl/gl_bindings.h" |
17 #include "ui/gl/gl_implementation.h" | 20 #include "ui/gl/gl_implementation.h" |
18 #include "ui/gl/gl_surface_egl.h" | 21 #include "ui/gl/gl_surface_egl.h" |
19 #include "ui/gl/gl_surface_egl_x11.h" | 22 #include "ui/gl/gl_surface_egl_x11.h" |
20 #include "ui/gl/gl_surface_glx.h" | 23 #include "ui/gl/gl_surface_glx.h" |
21 #include "ui/gl/gl_surface_osmesa.h" | 24 #include "ui/gl/gl_surface_osmesa.h" |
22 #include "ui/gl/gl_surface_stub.h" | 25 #include "ui/gl/gl_surface_stub.h" |
23 | 26 |
24 namespace gfx { | 27 namespace gfx { |
25 | 28 |
29 namespace { | |
30 | |
26 // This OSMesa GL surface can use XLib to swap the contents of the buffer to a | 31 // This OSMesa GL surface can use XLib to swap the contents of the buffer to a |
27 // view. | 32 // view. |
28 class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa { | 33 class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa { |
29 public: | 34 public: |
30 explicit NativeViewGLSurfaceOSMesa(gfx::AcceleratedWidget window); | 35 explicit NativeViewGLSurfaceOSMesa(gfx::AcceleratedWidget window); |
31 | 36 |
32 static bool InitializeOneOff(); | 37 static bool InitializeOneOff(); |
33 | 38 |
34 // Implement a subset of GLSurface. | 39 // Implement a subset of GLSurface. |
35 bool Initialize(GLSurface::Format format) override; | 40 bool Initialize(GLSurface::Format format) override; |
(...skipping 12 matching lines...) Expand all Loading... | |
48 private: | 53 private: |
49 Display* xdisplay_; | 54 Display* xdisplay_; |
50 GC window_graphics_context_; | 55 GC window_graphics_context_; |
51 gfx::AcceleratedWidget window_; | 56 gfx::AcceleratedWidget window_; |
52 GC pixmap_graphics_context_; | 57 GC pixmap_graphics_context_; |
53 Pixmap pixmap_; | 58 Pixmap pixmap_; |
54 | 59 |
55 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); | 60 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa); |
56 }; | 61 }; |
57 | 62 |
58 bool GLSurface::InitializeOneOffInternal() { | |
59 switch (GetGLImplementation()) { | |
60 case kGLImplementationDesktopGL: | |
61 if (!GLSurfaceGLX::InitializeOneOff()) { | |
62 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; | |
63 return false; | |
64 } | |
65 break; | |
66 case kGLImplementationOSMesaGL: | |
67 if (!NativeViewGLSurfaceOSMesa::InitializeOneOff()) { | |
68 LOG(ERROR) << "NativeViewGLSurfaceOSMesa::InitializeOneOff failed."; | |
69 return false; | |
70 } | |
71 break; | |
72 case kGLImplementationEGLGLES2: | |
73 if (!GLSurfaceEGL::InitializeOneOff()) { | |
74 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | |
75 return false; | |
76 } | |
77 break; | |
78 default: | |
79 break; | |
80 } | |
81 | |
82 return true; | |
83 } | |
84 | |
85 NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa( | 63 NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa( |
86 gfx::AcceleratedWidget window) | 64 gfx::AcceleratedWidget window) |
87 : GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, gfx::Size(1, 1)), | 65 : GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, gfx::Size(1, 1)), |
88 xdisplay_(gfx::GetXDisplay()), | 66 xdisplay_(gfx::GetXDisplay()), |
89 window_graphics_context_(0), | 67 window_graphics_context_(0), |
90 window_(window), | 68 window_(window), |
91 pixmap_graphics_context_(0), | 69 pixmap_graphics_context_(0), |
92 pixmap_(0) { | 70 pixmap_(0) { |
93 DCHECK(xdisplay_); | 71 DCHECK(xdisplay_); |
94 DCHECK(window_); | 72 DCHECK(window_); |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
260 x, | 238 x, |
261 y); | 239 y); |
262 | 240 |
263 return gfx::SwapResult::SWAP_ACK; | 241 return gfx::SwapResult::SWAP_ACK; |
264 } | 242 } |
265 | 243 |
266 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { | 244 NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() { |
267 Destroy(); | 245 Destroy(); |
268 } | 246 } |
269 | 247 |
248 // Native X11 specific implementation of GLX surface. Registers as a | |
249 // PlatformEventDispatcher to handle XEvents. | |
250 class GL_EXPORT NativeViewGLSurfaceGLXX11 : public NativeViewGLSurfaceGLX, | |
kylechar
2016/03/23 15:40:09
NativeViewGLSurfaceGLXX11 is a bit.. terrible?
| |
251 public ui::PlatformEventDispatcher { | |
252 public: | |
253 explicit NativeViewGLSurfaceGLXX11(gfx::AcceleratedWidget window); | |
254 | |
255 // PlatformEventDispatcher implementation: | |
256 bool CanDispatchEvent(const ui::PlatformEvent& event) override; | |
257 uint32_t DispatchEvent(const ui::PlatformEvent& event) override; | |
258 | |
259 protected: | |
260 ~NativeViewGLSurfaceGLXX11() override; | |
261 | |
262 // NativeViewGLSurfaceGLX implementation: | |
263 void RegisterEvents() override; | |
264 void UnregisterEvents() override; | |
265 | |
266 private: | |
267 DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceGLXX11); | |
268 }; | |
269 | |
270 NativeViewGLSurfaceGLXX11::NativeViewGLSurfaceGLXX11( | |
271 gfx::AcceleratedWidget window) | |
272 : NativeViewGLSurfaceGLX(window) {} | |
273 | |
274 bool NativeViewGLSurfaceGLXX11::CanDispatchEvent( | |
275 const ui::PlatformEvent& event) { | |
276 return CanHandleEvent(event); | |
277 } | |
278 | |
279 uint32_t NativeViewGLSurfaceGLXX11::DispatchEvent( | |
280 const ui::PlatformEvent& event) { | |
281 ForwardExposeEvent(event); | |
282 return ui::POST_DISPATCH_STOP_PROPAGATION; | |
283 } | |
284 | |
285 NativeViewGLSurfaceGLXX11::~NativeViewGLSurfaceGLXX11() { | |
286 Destroy(); | |
287 } | |
288 | |
289 void NativeViewGLSurfaceGLXX11::RegisterEvents() { | |
290 ui::PlatformEventSource* event_source = | |
291 ui::PlatformEventSource::GetInstance(); | |
292 // Can be nullptr in tests, when we don't care about Exposes. | |
293 if (event_source) { | |
294 XSelectInput(gfx::GetXDisplay(), window(), ExposureMask); | |
295 event_source->AddPlatformEventDispatcher(this); | |
296 } | |
297 } | |
298 | |
299 void NativeViewGLSurfaceGLXX11::UnregisterEvents() { | |
300 ui::PlatformEventSource* event_source = | |
301 ui::PlatformEventSource::GetInstance(); | |
302 if (event_source) | |
303 event_source->RemovePlatformEventDispatcher(this); | |
304 } | |
305 | |
306 } // namespace | |
307 | |
308 bool GLSurface::InitializeOneOffInternal() { | |
309 switch (GetGLImplementation()) { | |
310 case kGLImplementationDesktopGL: | |
311 if (!GLSurfaceGLX::InitializeOneOff()) { | |
312 LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; | |
313 return false; | |
314 } | |
315 break; | |
316 case kGLImplementationOSMesaGL: | |
317 if (!NativeViewGLSurfaceOSMesa::InitializeOneOff()) { | |
318 LOG(ERROR) << "NativeViewGLSurfaceOSMesa::InitializeOneOff failed."; | |
319 return false; | |
320 } | |
321 break; | |
322 case kGLImplementationEGLGLES2: | |
323 if (!GLSurfaceEGL::InitializeOneOff()) { | |
324 LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; | |
325 return false; | |
326 } | |
327 break; | |
328 default: | |
329 break; | |
330 } | |
331 | |
332 return true; | |
333 } | |
334 | |
270 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( | 335 scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
271 gfx::AcceleratedWidget window) { | 336 gfx::AcceleratedWidget window) { |
272 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); | 337 TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface"); |
273 switch (GetGLImplementation()) { | 338 switch (GetGLImplementation()) { |
274 case kGLImplementationOSMesaGL: { | 339 case kGLImplementationOSMesaGL: { |
275 scoped_refptr<GLSurface> surface( | 340 scoped_refptr<GLSurface> surface( |
276 new NativeViewGLSurfaceOSMesa(window)); | 341 new NativeViewGLSurfaceOSMesa(window)); |
277 if (!surface->Initialize()) | 342 if (!surface->Initialize()) |
278 return NULL; | 343 return NULL; |
279 | 344 |
280 return surface; | 345 return surface; |
281 } | 346 } |
282 case kGLImplementationDesktopGL: { | 347 case kGLImplementationDesktopGL: { |
283 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLX(window)); | 348 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLXX11(window)); |
284 if (!surface->Initialize()) | 349 if (!surface->Initialize()) |
285 return NULL; | 350 return NULL; |
286 | 351 |
287 return surface; | 352 return surface; |
288 } | 353 } |
289 case kGLImplementationEGLGLES2: { | 354 case kGLImplementationEGLGLES2: { |
290 DCHECK(window != gfx::kNullAcceleratedWidget); | 355 DCHECK(window != gfx::kNullAcceleratedWidget); |
291 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGLX11(window)); | 356 scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceEGLX11(window)); |
292 if (!surface->Initialize()) | 357 if (!surface->Initialize()) |
293 return NULL; | 358 return NULL; |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
335 NOTREACHED(); | 400 NOTREACHED(); |
336 return NULL; | 401 return NULL; |
337 } | 402 } |
338 } | 403 } |
339 | 404 |
340 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { | 405 EGLNativeDisplayType GetPlatformDefaultEGLNativeDisplay() { |
341 return gfx::GetXDisplay(); | 406 return gfx::GetXDisplay(); |
342 } | 407 } |
343 | 408 |
344 } // namespace gfx | 409 } // namespace gfx |
OLD | NEW |