Changeset 151226 in webkit


Ignore:
Timestamp:
Jun 5, 2013 8:54:22 AM (11 years ago)
Author:
commit-queue@webkit.org
Message:

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

Patch by Jae Hyun Park <jae.park@company100.net> 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):

Location:
trunk/Source/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r151224 r151226  
     12013-06-05  Jae Hyun Park  <jae.park@company100.net>
     2
     3        [GTK] Support using GLContext from multiple threads
     4        https://bugs.webkit.org/show_bug.cgi?id=117238
     5
     6        Reviewed by Martin Robinson.
     7
     8        Current implementation assumes that GLContext is only used in the main thread.
     9        However, to support using GLContext from multiple threads, we need to change it
     10        to thread local. Therefore, ASSERT(isMainThread()) is removed and GLContext is
     11        changed to thread local.
     12
     13        * platform/graphics/cairo/GLContext.cpp:
     14        (WebCore::ThreadGlobalGLContext::setContext):
     15        (WebCore::ThreadGlobalGLContext::context):
     16        (WebCore::currentContext):
     17        (WebCore::GLContext::sharingContext):
     18        (WebCore::GLContext::~GLContext):
     19        (WebCore::GLContext::makeContextCurrent):
     20        (WebCore::GLContext::getCurrent):
     21
    1222013-06-05  Christophe Dumez  <ch.dumez@sisa.samsung.com>
    223
  • trunk/Source/WebCore/platform/graphics/cairo/GLContext.cpp

    r150440 r151226  
    2424#include "GLContextEGL.h"
    2525#include "GLContextGLX.h"
    26 #include <wtf/MainThread.h>
     26#include <wtf/ThreadSpecific.h>
    2727
    2828#if PLATFORM(X11)
     
    3939#endif
    4040
     41using WTF::ThreadSpecific;
     42
    4143namespace WebCore {
     44
     45class ThreadGlobalGLContext {
     46public:
     47    static ThreadSpecific<ThreadGlobalGLContext>* staticGLContext;
     48
     49    void setContext(GLContext* context) { m_context = context; }
     50    GLContext* context() { return m_context; }
     51
     52private:
     53    GLContext* m_context;
     54};
     55
     56ThreadSpecific<ThreadGlobalGLContext>* ThreadGlobalGLContext::staticGLContext;
     57
     58inline ThreadGlobalGLContext* currentContext()
     59{
     60    if (!ThreadGlobalGLContext::staticGLContext)
     61        ThreadGlobalGLContext::staticGLContext = new ThreadSpecific<ThreadGlobalGLContext>;
     62    return *ThreadGlobalGLContext::staticGLContext;
     63}
    4264
    4365GLContext* GLContext::sharingContext()
    4466{
    45     ASSERT(isMainThread());
    4667    DEFINE_STATIC_LOCAL(OwnPtr<GLContext>, sharing, (createOffscreenContext()));
    4768    return sharing.get();
     
    154175}
    155176
    156 // FIXME: This should be a thread local eventually if we
    157 // want to support using GLContexts from multiple threads.
    158 static GLContext* gCurrentContext = 0;
    159 
    160177GLContext::~GLContext()
    161178{
    162     if (this == gCurrentContext)
    163         gCurrentContext = 0;
     179    if (this == currentContext()->context())
     180        currentContext()->setContext(0);
    164181    removeActiveContext(this);
    165182}
     
    167184bool GLContext::makeContextCurrent()
    168185{
    169     ASSERT(isMainThread());
    170     gCurrentContext = this;
     186    currentContext()->setContext(this);
    171187    return true;
    172188}
     
    174190GLContext* GLContext::getCurrent()
    175191{
    176     ASSERT(isMainThread());
    177     return gCurrentContext;
     192    return currentContext()->context();
    178193}
    179194
Note: See TracChangeset for help on using the changeset viewer.