Index: ui/gl/gl_surface_ozone.cc |
diff --git a/ui/gl/gl_surface_ozone.cc b/ui/gl/gl_surface_ozone.cc |
index da80397654374248b9305f0701a7c0ba0de7eaa5..035e1e3f9e8828b96f176ebd74f64b746671b23a 100644 |
--- a/ui/gl/gl_surface_ozone.cc |
+++ b/ui/gl/gl_surface_ozone.cc |
@@ -32,6 +32,13 @@ |
#include "ui/ozone/public/surface_factory_ozone.h" |
#include "ui/ozone/public/surface_ozone_egl.h" |
+#if defined(USE_GLX) |
+#include <X11/Xlib.h> |
+ |
+#include "ui/events/platform/x11/x11_event_source_libevent.h" |
+#include "ui/gl/gl_surface_glx.h" |
+#endif |
+ |
using gl::GLImage; |
namespace gfx { |
@@ -651,6 +658,64 @@ bool GLSurfaceOzoneSurfacelessSurfaceImpl::CreatePixmaps() { |
return true; |
} |
+#if defined(USE_GLX) |
+ |
+// Ozone specific implementation of GLX surface. Registers as XEventDispatcher |
+// to handle XEvents. |
+class GL_EXPORT NativeViewGLSurfaceGLXOzone : public NativeViewGLSurfaceGLX, |
+ public ui::XEventDispatcher { |
sadrul
2016/04/19 14:49:49
Can this not use the PlatformEventDispatcher inter
kylechar
2016/04/19 16:00:20
No, Expose events are platform specific and we don
|
+ public: |
+ explicit NativeViewGLSurfaceGLXOzone(gfx::AcceleratedWidget window); |
+ |
+ // XEventDispatcher implementation: |
+ bool DispatchXEvent(XEvent* xevent) override; |
+ |
+ protected: |
+ ~NativeViewGLSurfaceGLXOzone() override; |
+ |
+ // NativeViewGLSurfaceGLX implementation: |
+ void RegisterEvents() override; |
+ void UnregisterEvents() override; |
+ |
+ private: |
+ DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceGLXOzone); |
+}; |
+ |
+NativeViewGLSurfaceGLXOzone::NativeViewGLSurfaceGLXOzone( |
+ gfx::AcceleratedWidget window) |
+ : NativeViewGLSurfaceGLX(window) {} |
+ |
+bool NativeViewGLSurfaceGLXOzone::DispatchXEvent(XEvent* event) { |
+ if (!CanHandleEvent(event)) |
+ return false; |
+ |
+ ForwardExposeEvent(event); |
+ return true; |
+} |
+ |
+NativeViewGLSurfaceGLXOzone::~NativeViewGLSurfaceGLXOzone() { |
+ Destroy(); |
+} |
+ |
+void NativeViewGLSurfaceGLXOzone::RegisterEvents() { |
+ ui::X11EventSourceLibevent* event_source = |
+ ui::X11EventSourceLibevent::GetInstance(); |
+ // Can be nullptr in tests, when we don't care about Exposes. |
+ if (event_source) { |
+ XSelectInput(gfx::GetXDisplay(), window(), ExposureMask); |
+ event_source->AddXEventDispatcher(this); |
+ } |
+} |
+ |
+void NativeViewGLSurfaceGLXOzone::UnregisterEvents() { |
+ ui::X11EventSourceLibevent* event_source = |
+ ui::X11EventSourceLibevent::GetInstance(); |
+ if (event_source) |
+ event_source->RemoveXEventDispatcher(this); |
+} |
+ |
+#endif // defined(USE_GLX) |
+ |
scoped_refptr<GLSurface> CreateViewGLSurfaceOzone( |
gfx::AcceleratedWidget window) { |
scoped_ptr<ui::SurfaceOzoneEGL> surface_ozone = |
@@ -686,6 +751,15 @@ scoped_refptr<GLSurface> CreateViewGLSurfaceOzoneSurfacelessSurfaceImpl( |
// static |
bool GLSurface::InitializeOneOffInternal() { |
switch (GetGLImplementation()) { |
+#if defined(USE_GLX) |
+ case kGLImplementationDesktopGL: |
+ if (!GLSurfaceGLX::InitializeOneOff()) { |
+ LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed."; |
+ return false; |
+ } |
+ |
+ return true; |
+#endif |
case kGLImplementationEGLGLES2: |
if (!GLSurfaceEGL::InitializeOneOff()) { |
LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed."; |
@@ -725,6 +799,14 @@ scoped_refptr<GLSurface> GLSurface::CreateSurfacelessViewGLSurface( |
// static |
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
gfx::AcceleratedWidget window) { |
+#if defined(USE_GLX) |
+ if (GetGLImplementation() == kGLImplementationDesktopGL) { |
+ scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLXOzone(window)); |
+ if (!surface->Initialize()) |
+ return nullptr; |
+ return surface; |
+ } |
+#endif |
if (GetGLImplementation() == kGLImplementationOSMesaGL) { |
scoped_refptr<GLSurface> surface(new GLSurfaceOSMesaHeadless()); |
if (!surface->Initialize()) |
@@ -751,6 +833,16 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface( |
scoped_refptr<GLSurface> GLSurface::CreateOffscreenGLSurface( |
const gfx::Size& size) { |
switch (GetGLImplementation()) { |
+#if defined(USE_GLX) |
+ case kGLImplementationDesktopGL: { |
+ scoped_refptr<GLSurface> surface( |
+ new UnmappedNativeViewGLSurfaceGLX(size)); |
+ if (!surface->Initialize()) |
+ return nullptr; |
+ |
+ return surface; |
+ } |
+#endif |
case kGLImplementationOSMesaGL: { |
scoped_refptr<GLSurface> surface( |
new GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, size)); |