summaryrefslogtreecommitdiffstats
path: root/ui/gl
diff options
context:
space:
mode:
authorepenner@chromium.org <epenner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 11:51:52 +0000
committerepenner@chromium.org <epenner@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-26 11:51:52 +0000
commit06a1a6929980f090136c63c0f232a1e9125d7360 (patch)
tree34b36f14c6fecdaf738e99493ee2acaf23ecf528 /ui/gl
parent99001311b0a75e16e35b0b65245b78ffd4ed86ac (diff)
downloadchromium_src-06a1a6929980f090136c63c0f232a1e9125d7360.zip
chromium_src-06a1a6929980f090136c63c0f232a1e9125d7360.tar.gz
chromium_src-06a1a6929980f090136c63c0f232a1e9125d7360.tar.bz2
GPU: Use TLS pointer for GLApi.
This is straight from: https://codereview.chromium.org/16894002/ To support GL access on multiple threads, GL-API needs to be in TLS. It hasn't mattered previously in practice because our limited threaded GL calls were always forwarded to the right native calls. But as we improve virtual contexts and unset the API on ReleaseCurrent, this will no longer be the case. BUG=261264,263398 Review URL: https://chromiumcodereview.appspot.com/20014006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@213852 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gl')
-rw-r--r--ui/gl/gl_bindings.h6
-rw-r--r--ui/gl/gl_context_stub.cc1
-rw-r--r--ui/gl/gl_gl_api_implementation.cc12
-rw-r--r--ui/gl/gl_implementation.cc2
4 files changed, 14 insertions, 7 deletions
diff --git a/ui/gl/gl_bindings.h b/ui/gl/gl_bindings.h
index c6a1eac..1c12a68 100644
--- a/ui/gl/gl_bindings.h
+++ b/ui/gl/gl_bindings.h
@@ -16,6 +16,7 @@
#include <EGL/eglext.h>
#include "base/logging.h"
+#include "base/threading/thread_local.h"
#include "build/build_config.h"
#include "ui/gl/gl_export.h"
@@ -299,7 +300,10 @@ struct GL_EXPORT DriverGLX {
};
#endif
-GL_EXPORT extern GLApi* g_current_gl_context;
+// This #define is here to support autogenerated code.
+#define g_current_gl_context g_current_gl_context_tls->Get()
+GL_EXPORT extern base::ThreadLocalPointer<GLApi>* g_current_gl_context_tls;
+
GL_EXPORT extern OSMESAApi* g_current_osmesa_context;
GL_EXPORT extern DriverGL g_driver_gl;
GL_EXPORT extern DriverOSMESA g_driver_osmesa;
diff --git a/ui/gl/gl_context_stub.cc b/ui/gl/gl_context_stub.cc
index 7c63ff2..56fb3c7 100644
--- a/ui/gl/gl_context_stub.cc
+++ b/ui/gl/gl_context_stub.cc
@@ -17,7 +17,6 @@ void GLContextStub::Destroy() {}
bool GLContextStub::MakeCurrent(GLSurface* surface) {
SetCurrent(surface);
- SetRealGLApi();
return true;
}
diff --git a/ui/gl/gl_gl_api_implementation.cc b/ui/gl/gl_gl_api_implementation.cc
index 802d250..03d1302 100644
--- a/ui/gl/gl_gl_api_implementation.cc
+++ b/ui/gl/gl_gl_api_implementation.cc
@@ -143,6 +143,7 @@ void DriverGL::InitializeExtensions(GLContext* context) {
}
void InitializeGLBindingsGL() {
+ g_current_gl_context_tls = new base::ThreadLocalPointer<GLApi>;
g_driver_gl.Initialize();
if (!g_real_gl) {
g_real_gl = new RealGLApi();
@@ -158,11 +159,11 @@ void InitializeGLBindingsGL() {
}
GLApi* GetCurrentGLApi() {
- return g_current_gl_context;
+ return g_current_gl_context_tls->Get();
}
void SetGLApi(GLApi* api) {
- g_current_gl_context = api;
+ g_current_gl_context_tls->Set(api);
}
void SetGLToRealGLApi() {
@@ -187,8 +188,11 @@ void ClearGLBindingsGL() {
g_trace_gl = NULL;
}
g_gl = NULL;
- g_current_gl_context = NULL;
g_driver_gl.ClearBindings();
+ if (g_current_gl_context_tls) {
+ delete g_current_gl_context_tls;
+ g_current_gl_context_tls = NULL;
+ }
}
GLApi::GLApi() {
@@ -253,7 +257,7 @@ void VirtualGLApi::Initialize(DriverGL* driver, GLContext* real_context) {
}
bool VirtualGLApi::MakeCurrent(GLContext* virtual_context, GLSurface* surface) {
- bool switched_contexts = g_current_gl_context != this;
+ bool switched_contexts = g_current_gl_context_tls->Get() != this;
GLSurface* current_surface = GLSurface::GetCurrent();
if (switched_contexts || surface != current_surface) {
// MakeCurrent 'lite' path that avoids potentially expensive MakeCurrent()
diff --git a/ui/gl/gl_implementation.cc b/ui/gl/gl_implementation.cc
index 7fe6486..a1896fd 100644
--- a/ui/gl/gl_implementation.cc
+++ b/ui/gl/gl_implementation.cc
@@ -63,7 +63,7 @@ bool ExportsCoreFunctionsFromGetProcAddress(GLImplementation implementation) {
}
-GLApi* g_current_gl_context;
+base::ThreadLocalPointer<GLApi>* g_current_gl_context_tls = NULL;
OSMESAApi* g_current_osmesa_context;
#if defined(OS_WIN)