ANGLE: Fix static build.

Introduce  QT_OPENGL_ES_2_ANGLE_STATIC define for static builds
and modify export accordingly. Provided static instances
of gl::Current and egl::Current for Qt's single threaded
use.

Task-number: QTBUG-28196

Change-Id: Ia75699d6da103fb8dd9d5fe97c1ee51e48a74406
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@digia.com>
Reviewed-by: Kai Koehne <kai.koehne@digia.com>
This commit is contained in:
Friedemann Kleint 2013-02-14 09:43:16 +01:00 committed by The Qt Project
parent 7686b2386d
commit a8fce5d6e2
6 changed files with 274 additions and 40 deletions

View File

@ -21,6 +21,7 @@ wince* {
QMAKE_LIBDIR += $$QMAKE_LIBDIR_OPENGL_ES2_RELEASE
}
DEFINES += QT_OPENGL_ES_2 QT_OPENGL_ES_2_ANGLE
contains(QT_CONFIG, static): DEFINES += QT_OPENGL_ES_2_ANGLE_STATIC
QT_CONFIG -= opengl
} else {
QMAKE_LIBS += $$QMAKE_LIBS_OPENGL

View File

@ -97,7 +97,8 @@
*-------------------------------------------------------------------------
* This precedes the return type of the function in the function prototype.
*/
#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
#if defined(_WIN32) && !defined(__SCITECH_SNAP__) && !defined(QT_OPENGL_ES_2_ANGLE_STATIC)
# define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__)
# define KHRONOS_APICALL IMPORT_C

View File

@ -10,6 +10,8 @@
#include "common/debug.h"
#ifndef QT_OPENGL_ES_2_ANGLE_STATIC
static DWORD currentTLS = TLS_OUT_OF_INDEXES;
extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
@ -86,76 +88,72 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
return TRUE;
}
static inline egl::Current *current()
{
return (egl::Current*)TlsGetValue(currentTLS);
}
#else // !QT_OPENGL_ES_2_ANGLE_STATIC
static egl::Current *current()
{
// No precautions for thread safety taken as ANGLE is used single-threaded in Qt.
static egl::Current curr = { EGL_SUCCESS, EGL_OPENGL_ES_API, EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE };
return &curr;
}
#endif // QT_OPENGL_ES_2_ANGLE_STATIC
namespace egl
{
void setCurrentError(EGLint error)
{
Current *current = (Current*)TlsGetValue(currentTLS);
current->error = error;
current()->error = error;
}
EGLint getCurrentError()
{
Current *current = (Current*)TlsGetValue(currentTLS);
return current->error;
return current()->error;
}
void setCurrentAPI(EGLenum API)
{
Current *current = (Current*)TlsGetValue(currentTLS);
current->API = API;
current()->API = API;
}
EGLenum getCurrentAPI()
{
Current *current = (Current*)TlsGetValue(currentTLS);
return current->API;
return current()->API;
}
void setCurrentDisplay(EGLDisplay dpy)
{
Current *current = (Current*)TlsGetValue(currentTLS);
current->display = dpy;
current()->display = dpy;
}
EGLDisplay getCurrentDisplay()
{
Current *current = (Current*)TlsGetValue(currentTLS);
return current->display;
return current()->display;
}
void setCurrentDrawSurface(EGLSurface surface)
{
Current *current = (Current*)TlsGetValue(currentTLS);
current->drawSurface = surface;
current()->drawSurface = surface;
}
EGLSurface getCurrentDrawSurface()
{
Current *current = (Current*)TlsGetValue(currentTLS);
return current->drawSurface;
return current()->drawSurface;
}
void setCurrentReadSurface(EGLSurface surface)
{
Current *current = (Current*)TlsGetValue(currentTLS);
current->readSurface = surface;
current()->readSurface = surface;
}
EGLSurface getCurrentReadSurface()
{
Current *current = (Current*)TlsGetValue(currentTLS);
return current->readSurface;
return current()->readSurface;
}
}

View File

@ -14,6 +14,8 @@
#include "libGLESv2/Framebuffer.h"
#ifndef QT_OPENGL_ES_2_ANGLE_STATIC
static DWORD currentTLS = TLS_OUT_OF_INDEXES;
extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
@ -72,14 +74,30 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
return TRUE;
}
static gl::Current *current()
{
return (gl::Current*)TlsGetValue(currentTLS);
}
#else // !QT_OPENGL_ES_2_ANGLE_STATIC
static inline gl::Current *current()
{
// No precautions for thread safety taken as ANGLE is used single-threaded in Qt.
static gl::Current curr = { 0, 0 };
return &curr;
}
#endif // QT_OPENGL_ES_2_ANGLE_STATIC
namespace gl
{
void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface)
{
Current *current = (Current*)TlsGetValue(currentTLS);
Current *curr = current();
current->context = context;
current->display = display;
curr->context = context;
curr->display = display;
if (context && display && surface)
{
@ -89,9 +107,7 @@ void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface)
Context *getContext()
{
Current *current = (Current*)TlsGetValue(currentTLS);
return current->context;
return current()->context;
}
Context *getNonLostContext()
@ -115,9 +131,7 @@ Context *getNonLostContext()
egl::Display *getDisplay()
{
Current *current = (Current*)TlsGetValue(currentTLS);
return current->display;
return current()->display;
}
IDirect3DDevice9 *getDevice()

View File

@ -0,0 +1,218 @@
From cbe9afef7cd467c41353e8a41544d86807be7dd2 Mon Sep 17 00:00:00 2001
From: Friedemann Kleint <Friedemann.Kleint@digia.com>
Date: Thu, 14 Feb 2013 09:40:30 +0100
Subject: [PATCH] Make it possible to link ANGLE statically for single-thread
use.
Fix exports and provide static instances of thread-local
data depending on QT_OPENGL_ES_2_ANGLE_STATIC.
Change-Id: Ifab25a820adf5953bb3b09036de53dbf7f1a7fd5
---
src/3rdparty/angle/include/KHR/khrplatform.h | 3 +-
src/3rdparty/angle/src/libEGL/main.cpp | 58 ++++++++++++++--------------
src/3rdparty/angle/src/libGLESv2/main.cpp | 32 ++++++++++-----
3 files changed, 53 insertions(+), 40 deletions(-)
diff --git a/src/3rdparty/angle/include/KHR/khrplatform.h b/src/3rdparty/angle/include/KHR/khrplatform.h
index 56c676c..18a104e 100644
--- a/src/3rdparty/angle/include/KHR/khrplatform.h
+++ b/src/3rdparty/angle/include/KHR/khrplatform.h
@@ -97,7 +97,8 @@
*-------------------------------------------------------------------------
* This precedes the return type of the function in the function prototype.
*/
-#if defined(_WIN32) && !defined(__SCITECH_SNAP__)
+
+#if defined(_WIN32) && !defined(__SCITECH_SNAP__) && !defined(QT_OPENGL_ES_2_ANGLE_STATIC)
# define KHRONOS_APICALL __declspec(dllimport)
#elif defined (__SYMBIAN32__)
# define KHRONOS_APICALL IMPORT_C
diff --git a/src/3rdparty/angle/src/libEGL/main.cpp b/src/3rdparty/angle/src/libEGL/main.cpp
index dc24c4f..614bcf6 100644
--- a/src/3rdparty/angle/src/libEGL/main.cpp
+++ b/src/3rdparty/angle/src/libEGL/main.cpp
@@ -10,6 +10,8 @@
#include "common/debug.h"
+#ifndef QT_OPENGL_ES_2_ANGLE_STATIC
+
static DWORD currentTLS = TLS_OUT_OF_INDEXES;
extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
@@ -86,76 +88,72 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
return TRUE;
}
+static inline egl::Current *current()
+{
+ return (egl::Current*)TlsGetValue(currentTLS);
+}
+
+#else // !QT_OPENGL_ES_2_ANGLE_STATIC
+
+static egl::Current *current()
+{
+ // No precautions for thread safety taken as ANGLE is used single-threaded in Qt.
+ static egl::Current curr = { EGL_SUCCESS, EGL_OPENGL_ES_API, EGL_NO_DISPLAY, EGL_NO_SURFACE, EGL_NO_SURFACE };
+ return &curr;
+}
+
+#endif // QT_OPENGL_ES_2_ANGLE_STATIC
+
namespace egl
{
void setCurrentError(EGLint error)
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- current->error = error;
+ current()->error = error;
}
EGLint getCurrentError()
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- return current->error;
+ return current()->error;
}
void setCurrentAPI(EGLenum API)
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- current->API = API;
+ current()->API = API;
}
EGLenum getCurrentAPI()
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- return current->API;
+ return current()->API;
}
void setCurrentDisplay(EGLDisplay dpy)
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- current->display = dpy;
+ current()->display = dpy;
}
EGLDisplay getCurrentDisplay()
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- return current->display;
+ return current()->display;
}
void setCurrentDrawSurface(EGLSurface surface)
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- current->drawSurface = surface;
+ current()->drawSurface = surface;
}
EGLSurface getCurrentDrawSurface()
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- return current->drawSurface;
+ return current()->drawSurface;
}
void setCurrentReadSurface(EGLSurface surface)
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- current->readSurface = surface;
+ current()->readSurface = surface;
}
EGLSurface getCurrentReadSurface()
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- return current->readSurface;
+ return current()->readSurface;
}
}
diff --git a/src/3rdparty/angle/src/libGLESv2/main.cpp b/src/3rdparty/angle/src/libGLESv2/main.cpp
index 6e678c2..3853e41 100644
--- a/src/3rdparty/angle/src/libGLESv2/main.cpp
+++ b/src/3rdparty/angle/src/libGLESv2/main.cpp
@@ -14,6 +14,8 @@
#include "libGLESv2/Framebuffer.h"
+#ifndef QT_OPENGL_ES_2_ANGLE_STATIC
+
static DWORD currentTLS = TLS_OUT_OF_INDEXES;
extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
@@ -72,14 +74,30 @@ extern "C" BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved
return TRUE;
}
+static gl::Current *current()
+{
+ return (gl::Current*)TlsGetValue(currentTLS);
+}
+
+#else // !QT_OPENGL_ES_2_ANGLE_STATIC
+
+static inline gl::Current *current()
+{
+ // No precautions for thread safety taken as ANGLE is used single-threaded in Qt.
+ static gl::Current curr = { 0, 0 };
+ return &curr;
+}
+
+#endif // QT_OPENGL_ES_2_ANGLE_STATIC
+
namespace gl
{
void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface)
{
- Current *current = (Current*)TlsGetValue(currentTLS);
+ Current *curr = current();
- current->context = context;
- current->display = display;
+ curr->context = context;
+ curr->display = display;
if (context && display && surface)
{
@@ -89,9 +107,7 @@ void makeCurrent(Context *context, egl::Display *display, egl::Surface *surface)
Context *getContext()
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- return current->context;
+ return current()->context;
}
Context *getNonLostContext()
@@ -115,9 +131,7 @@ Context *getNonLostContext()
egl::Display *getDisplay()
{
- Current *current = (Current*)TlsGetValue(currentTLS);
-
- return current->display;
+ return current()->display;
}
IDirect3DDevice9 *getDevice()
--
1.8.0.msysgit.0

View File

@ -40,6 +40,8 @@ win32-msvc2012 {
}
}
static: DEFINES *= QT_OPENGL_ES_2_ANGLE_STATIC
HEADERS += \
$$ANGLE_DIR/src/common/angleutils.h \
$$ANGLE_DIR/src/common/debug.h \