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

Unified Diff: ui/gl/gl_surface_ozone.cc

Issue 1723303002: Implement GLX for Ozone X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase. 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 side-by-side diff with in-line comments
Download patch
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));

Powered by Google App Engine
This is Rietveld 408576698