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

Side by Side Diff: ui/gl/gl_surface_x11.cc

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

Powered by Google App Engine
This is Rietveld 408576698