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

Unified 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/refactor. Created 4 years, 9 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_x11.cc
diff --git a/ui/gl/gl_surface_x11.cc b/ui/gl/gl_surface_x11.cc
index 4e36e2ee86e3a2a22cdf703b907390e54d66c46b..96383806772ee9d8b27f220a0db486554b3b452c 100644
--- a/ui/gl/gl_surface_x11.cc
+++ b/ui/gl/gl_surface_x11.cc
@@ -5,12 +5,15 @@
#include "ui/gl/gl_surface.h"
#include <stdint.h>
+#include <X11/Xlib.h>
#include "base/logging.h"
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop/message_loop.h"
#include "base/trace_event/trace_event.h"
+#include "ui/events/platform/platform_event_dispatcher.h"
+#include "ui/events/platform/platform_event_source.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/gfx/x/x11_types.h"
#include "ui/gl/gl_bindings.h"
@@ -23,6 +26,8 @@
namespace gfx {
+namespace {
+
// This OSMesa GL surface can use XLib to swap the contents of the buffer to a
// view.
class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa {
@@ -55,33 +60,6 @@ class NativeViewGLSurfaceOSMesa : public GLSurfaceOSMesa {
DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceOSMesa);
};
-bool GLSurface::InitializeOneOffInternal() {
- switch (GetGLImplementation()) {
- case kGLImplementationDesktopGL:
- if (!GLSurfaceGLX::InitializeOneOff()) {
- LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed.";
- return false;
- }
- break;
- case kGLImplementationOSMesaGL:
- if (!NativeViewGLSurfaceOSMesa::InitializeOneOff()) {
- LOG(ERROR) << "NativeViewGLSurfaceOSMesa::InitializeOneOff failed.";
- return false;
- }
- break;
- case kGLImplementationEGLGLES2:
- if (!GLSurfaceEGL::InitializeOneOff()) {
- LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
- return false;
- }
- break;
- default:
- break;
- }
-
- return true;
-}
-
NativeViewGLSurfaceOSMesa::NativeViewGLSurfaceOSMesa(
gfx::AcceleratedWidget window)
: GLSurfaceOSMesa(SURFACE_OSMESA_BGRA, gfx::Size(1, 1)),
@@ -267,6 +245,93 @@ NativeViewGLSurfaceOSMesa::~NativeViewGLSurfaceOSMesa() {
Destroy();
}
+// Native X11 specific implementation of GLX surface. Registers as a
+// PlatformEventDispatcher to handle XEvents.
+class GL_EXPORT NativeViewGLSurfaceGLXX11 : public NativeViewGLSurfaceGLX,
kylechar 2016/03/23 15:40:09 NativeViewGLSurfaceGLXX11 is a bit.. terrible?
+ public ui::PlatformEventDispatcher {
+ public:
+ explicit NativeViewGLSurfaceGLXX11(gfx::AcceleratedWidget window);
+
+ // PlatformEventDispatcher implementation:
+ bool CanDispatchEvent(const ui::PlatformEvent& event) override;
+ uint32_t DispatchEvent(const ui::PlatformEvent& event) override;
+
+ protected:
+ ~NativeViewGLSurfaceGLXX11() override;
+
+ // NativeViewGLSurfaceGLX implementation:
+ void RegisterEvents() override;
+ void UnregisterEvents() override;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NativeViewGLSurfaceGLXX11);
+};
+
+NativeViewGLSurfaceGLXX11::NativeViewGLSurfaceGLXX11(
+ gfx::AcceleratedWidget window)
+ : NativeViewGLSurfaceGLX(window) {}
+
+bool NativeViewGLSurfaceGLXX11::CanDispatchEvent(
+ const ui::PlatformEvent& event) {
+ return CanHandleEvent(event);
+}
+
+uint32_t NativeViewGLSurfaceGLXX11::DispatchEvent(
+ const ui::PlatformEvent& event) {
+ ForwardExposeEvent(event);
+ return ui::POST_DISPATCH_STOP_PROPAGATION;
+}
+
+NativeViewGLSurfaceGLXX11::~NativeViewGLSurfaceGLXX11() {
+ Destroy();
+}
+
+void NativeViewGLSurfaceGLXX11::RegisterEvents() {
+ ui::PlatformEventSource* event_source =
+ ui::PlatformEventSource::GetInstance();
+ // Can be nullptr in tests, when we don't care about Exposes.
+ if (event_source) {
+ XSelectInput(gfx::GetXDisplay(), window(), ExposureMask);
+ event_source->AddPlatformEventDispatcher(this);
+ }
+}
+
+void NativeViewGLSurfaceGLXX11::UnregisterEvents() {
+ ui::PlatformEventSource* event_source =
+ ui::PlatformEventSource::GetInstance();
+ if (event_source)
+ event_source->RemovePlatformEventDispatcher(this);
+}
+
+} // namespace
+
+bool GLSurface::InitializeOneOffInternal() {
+ switch (GetGLImplementation()) {
+ case kGLImplementationDesktopGL:
+ if (!GLSurfaceGLX::InitializeOneOff()) {
+ LOG(ERROR) << "GLSurfaceGLX::InitializeOneOff failed.";
+ return false;
+ }
+ break;
+ case kGLImplementationOSMesaGL:
+ if (!NativeViewGLSurfaceOSMesa::InitializeOneOff()) {
+ LOG(ERROR) << "NativeViewGLSurfaceOSMesa::InitializeOneOff failed.";
+ return false;
+ }
+ break;
+ case kGLImplementationEGLGLES2:
+ if (!GLSurfaceEGL::InitializeOneOff()) {
+ LOG(ERROR) << "GLSurfaceEGL::InitializeOneOff failed.";
+ return false;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return true;
+}
+
scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
gfx::AcceleratedWidget window) {
TRACE_EVENT0("gpu", "GLSurface::CreateViewGLSurface");
@@ -280,7 +345,7 @@ scoped_refptr<GLSurface> GLSurface::CreateViewGLSurface(
return surface;
}
case kGLImplementationDesktopGL: {
- scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLX(window));
+ scoped_refptr<GLSurface> surface(new NativeViewGLSurfaceGLXX11(window));
if (!surface->Initialize())
return NULL;

Powered by Google App Engine
This is Rietveld 408576698