Title: [151226] trunk/Source/WebCore
Revision
151226
Author
[email protected]
Date
2013-06-05 08:54:22 -0700 (Wed, 05 Jun 2013)

Log Message

[GTK] Support using GLContext from multiple threads
https://bugs.webkit.org/show_bug.cgi?id=117238

Patch by Jae Hyun Park <[email protected]> on 2013-06-05
Reviewed by Martin Robinson.

Current implementation assumes that GLContext is only used in the main thread.
However, to support using GLContext from multiple threads, we need to change it
to thread local. Therefore, ASSERT(isMainThread()) is removed and GLContext is
changed to thread local.

* platform/graphics/cairo/GLContext.cpp:
(WebCore::ThreadGlobalGLContext::setContext):
(WebCore::ThreadGlobalGLContext::context):
(WebCore::currentContext):
(WebCore::GLContext::sharingContext):
(WebCore::GLContext::~GLContext):
(WebCore::GLContext::makeContextCurrent):
(WebCore::GLContext::getCurrent):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (151225 => 151226)


--- trunk/Source/WebCore/ChangeLog	2013-06-05 15:21:44 UTC (rev 151225)
+++ trunk/Source/WebCore/ChangeLog	2013-06-05 15:54:22 UTC (rev 151226)
@@ -1,3 +1,24 @@
+2013-06-05  Jae Hyun Park  <[email protected]>
+
+        [GTK] Support using GLContext from multiple threads
+        https://bugs.webkit.org/show_bug.cgi?id=117238
+
+        Reviewed by Martin Robinson.
+
+        Current implementation assumes that GLContext is only used in the main thread.
+        However, to support using GLContext from multiple threads, we need to change it
+        to thread local. Therefore, ASSERT(isMainThread()) is removed and GLContext is
+        changed to thread local.
+
+        * platform/graphics/cairo/GLContext.cpp:
+        (WebCore::ThreadGlobalGLContext::setContext):
+        (WebCore::ThreadGlobalGLContext::context):
+        (WebCore::currentContext):
+        (WebCore::GLContext::sharingContext):
+        (WebCore::GLContext::~GLContext):
+        (WebCore::GLContext::makeContextCurrent):
+        (WebCore::GLContext::getCurrent):
+
 2013-06-05  Christophe Dumez  <[email protected]>
 
         Unreviewed build fix when CHANNEL_MESSAGING is disabled.

Modified: trunk/Source/WebCore/platform/graphics/cairo/GLContext.cpp (151225 => 151226)


--- trunk/Source/WebCore/platform/graphics/cairo/GLContext.cpp	2013-06-05 15:21:44 UTC (rev 151225)
+++ trunk/Source/WebCore/platform/graphics/cairo/GLContext.cpp	2013-06-05 15:54:22 UTC (rev 151226)
@@ -23,7 +23,7 @@
 
 #include "GLContextEGL.h"
 #include "GLContextGLX.h"
-#include <wtf/MainThread.h>
+#include <wtf/ThreadSpecific.h>
 
 #if PLATFORM(X11)
 #include <X11/Xlib.h>
@@ -38,11 +38,32 @@
 #endif
 #endif
 
+using WTF::ThreadSpecific;
+
 namespace WebCore {
 
+class ThreadGlobalGLContext {
+public:
+    static ThreadSpecific<ThreadGlobalGLContext>* staticGLContext;
+
+    void setContext(GLContext* context) { m_context = context; }
+    GLContext* context() { return m_context; }
+
+private:
+    GLContext* m_context;
+};
+
+ThreadSpecific<ThreadGlobalGLContext>* ThreadGlobalGLContext::staticGLContext;
+
+inline ThreadGlobalGLContext* currentContext()
+{
+    if (!ThreadGlobalGLContext::staticGLContext)
+        ThreadGlobalGLContext::staticGLContext = new ThreadSpecific<ThreadGlobalGLContext>;
+    return *ThreadGlobalGLContext::staticGLContext;
+}
+
 GLContext* GLContext::sharingContext()
 {
-    ASSERT(isMainThread());
     DEFINE_STATIC_LOCAL(OwnPtr<GLContext>, sharing, (createOffscreenContext()));
     return sharing.get();
 }
@@ -153,28 +174,22 @@
     return createContextForWindow(0, sharingContext);
 }
 
-// FIXME: This should be a thread local eventually if we
-// want to support using GLContexts from multiple threads.
-static GLContext* gCurrentContext = 0;
-
 GLContext::~GLContext()
 {
-    if (this == gCurrentContext)
-        gCurrentContext = 0;
+    if (this == currentContext()->context())
+        currentContext()->setContext(0);
     removeActiveContext(this);
 }
 
 bool GLContext::makeContextCurrent()
 {
-    ASSERT(isMainThread());
-    gCurrentContext = this;
+    currentContext()->setContext(this);
     return true;
 }
 
 GLContext* GLContext::getCurrent()
 {
-    ASSERT(isMainThread());
-    return gCurrentContext;
+    return currentContext()->context();
 }
 
 } // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to