summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichal Klocek <michal.klocek@qt.io>2018-04-10 10:53:15 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2018-04-12 21:45:38 +0000
commit0841e85172a76766301454fc407fdf0bebf047f4 (patch)
tree0e6b1afa131fe28935fdc4c33aca8cc4c58ec9ac /src
parent01ee897dc5395f7e0c121f6c8532ebb3d7f1344e (diff)
Add initialization of static bindings for egl and glx
Use lazy binding for static bindings initialization, the same way we do in ozone. Task-number: QTBUG-65682 Change-Id: I51ecdfa3b7daca8b1345cf2c0c89a4ac6e25a7c9 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/core/gl_surface_qt.cpp79
1 files changed, 78 insertions, 1 deletions
diff --git a/src/core/gl_surface_qt.cpp b/src/core/gl_surface_qt.cpp
index abe0ed5d3..4e620af87 100644
--- a/src/core/gl_surface_qt.cpp
+++ b/src/core/gl_surface_qt.cpp
@@ -52,13 +52,14 @@
#include "ozone/gl_surface_egl_qt.h"
#include "base/logging.h"
+#include "base/threading/thread_restrictions.h"
#include "gpu/ipc/service/image_transport_surface.h"
#include "ui/gl/gl_bindings.h"
#include "ui/gl/gl_context.h"
#include "ui/gl/gl_implementation.h"
#include "ui/gl/init/gl_initializer.h"
#include "ui/gl/init/gl_factory.h"
-
+#include "ui/gl/gl_gl_api_implementation.h"
#if defined(OS_WIN)
#include "ozone/gl_surface_wgl_qt.h"
@@ -69,9 +70,12 @@
#if defined(USE_X11)
#include "ozone/gl_surface_glx_qt.h"
+#include "ui/gl/gl_glx_api_implementation.h"
+#include <dlfcn.h>
#endif
#include "ozone/gl_surface_egl_qt.h"
+#include "ui/gl/gl_egl_api_implementation.h"
namespace gl {
@@ -168,6 +172,79 @@ bool InitializeGLOneOffPlatform()
return false;
}
+#if defined(USE_X11)
+// FIXME: This should be removed when we switch to OZONE only
+bool InitializeStaticGLBindings(GLImplementation implementation) {
+ // Prevent reinitialization with a different implementation. Once the gpu
+ // unit tests have initialized with kGLImplementationMock, we don't want to
+ // later switch to another GL implementation.
+ DCHECK_EQ(kGLImplementationNone, GetGLImplementation());
+ base::ThreadRestrictions::ScopedAllowIO allow_io;
+
+ switch (implementation) {
+ case kGLImplementationOSMesaGL:
+ return false;
+ case kGLImplementationDesktopGL: {
+ base::NativeLibrary library = dlopen(NULL, RTLD_LAZY);
+ if (!library) {
+ LOG(ERROR) << "Failed to obtain glx handle" << dlerror();
+ return false;
+ }
+
+ GLGetProcAddressProc get_proc_address =
+ reinterpret_cast<GLGetProcAddressProc>(
+ base::GetFunctionPointerFromNativeLibrary(library,
+ "glXGetProcAddress"));
+ if (!get_proc_address) {
+ LOG(ERROR) << "glxGetProcAddress not found.";
+ base::UnloadNativeLibrary(library);
+ return false;
+ }
+
+ SetGLGetProcAddressProc(get_proc_address);
+ AddGLNativeLibrary(library);
+ SetGLImplementation(kGLImplementationDesktopGL);
+
+ InitializeStaticGLBindingsGL();
+ InitializeStaticGLBindingsGLX();
+ return true;
+ }
+ case kGLImplementationSwiftShaderGL:
+ case kGLImplementationEGLGLES2: {
+ base::NativeLibrary library = dlopen(NULL, RTLD_LAZY);
+ if (!library) {
+ LOG(ERROR) << "Failed to obtain egl handle" << dlerror();
+ return false;
+ }
+
+ GLGetProcAddressProc get_proc_address =
+ reinterpret_cast<GLGetProcAddressProc>(
+ base::GetFunctionPointerFromNativeLibrary(library,
+ "eglGetProcAddress"));
+ if (!get_proc_address) {
+ LOG(ERROR) << "eglGetProcAddress not found.";
+ base::UnloadNativeLibrary(library);
+ return false;
+ }
+
+ SetGLGetProcAddressProc(get_proc_address);
+ AddGLNativeLibrary(library);
+ SetGLImplementation(kGLImplementationEGLGLES2);
+
+ InitializeStaticGLBindingsGL();
+ InitializeStaticGLBindingsEGL();
+ return true;
+ }
+ case kGLImplementationMockGL:
+ case kGLImplementationStubGL:
+ return false;
+ default:
+ NOTREACHED();
+ }
+ return false;
+}
+#endif
+
bool usingSoftwareDynamicGL()
{
return QtWebEngineCore::usingSoftwareDynamicGL();