diff options
author | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-12 21:52:41 +0000 |
---|---|---|
committer | jamesr@chromium.org <jamesr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-12 21:54:19 +0000 |
commit | 882aa3c950a867ce5485cd2a505d3fd194532714 (patch) | |
tree | a432a6d954c450dfeac13f845aa66c37a3196fe6 /mojo/gles2 | |
parent | 15b9275f70a35750c5bb3bf38dc69b72f83b55aa (diff) | |
download | chromium_src-882aa3c950a867ce5485cd2a505d3fd194532714.zip chromium_src-882aa3c950a867ce5485cd2a505d3fd194532714.tar.gz chromium_src-882aa3c950a867ce5485cd2a505d3fd194532714.tar.bz2 |
Make async waiter explicit MojoGLES2CreateContext param
Hiding the async_waiter in a static makes it difficult to deal with
different threads running potentially different loop types running in
the same process. Making this explicit in the create call is much easier.
This assumes that callers will want to permantently bind a context with
a particular async waiter. In the case that we end up with a caller that
wishes to create a context on a thread using one async waiter type and
then bind that context to a thread using a different async waiter type
we can add another version of MakeCurrent, but that seems like a fairly
remote possibility at this point.
R=piman@chromium.org
Review URL: https://codereview.chromium.org/428413002
Cr-Commit-Position: refs/heads/master@{#289074}
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@289074 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/gles2')
-rw-r--r-- | mojo/gles2/gles2_impl.cc | 46 |
1 files changed, 17 insertions, 29 deletions
diff --git a/mojo/gles2/gles2_impl.cc b/mojo/gles2/gles2_impl.cc index 59b4278..a77405f 100644 --- a/mojo/gles2/gles2_impl.cc +++ b/mojo/gles2/gles2_impl.cc @@ -4,6 +4,8 @@ #include "mojo/public/c/gles2/gles2.h" +#include "base/lazy_instance.h" +#include "base/threading/thread_local.h" #include "gpu/command_buffer/client/gles2_interface.h" #include "mojo/gles2/gles2_context.h" @@ -11,34 +13,20 @@ using mojo::gles2::GLES2Context; namespace { -const MojoAsyncWaiter* g_async_waiter = NULL; -gpu::gles2::GLES2Interface* g_gpu_interface = NULL; +base::LazyInstance<base::ThreadLocalPointer<gpu::gles2::GLES2Interface> >::Leaky + g_gpu_interface; } // namespace extern "C" { - -void MojoGLES2Initialize(const MojoAsyncWaiter* async_waiter) { - DCHECK(!g_async_waiter); - DCHECK(async_waiter); - g_async_waiter = async_waiter; -} - -void MojoGLES2Terminate() { - DCHECK(g_async_waiter); - g_async_waiter = NULL; -} - -MojoGLES2Context MojoGLES2CreateContext( - MojoHandle handle, - MojoGLES2ContextLost lost_callback, - void* closure) { +MojoGLES2Context MojoGLES2CreateContext(MojoHandle handle, + MojoGLES2ContextLost lost_callback, + void* closure, + const MojoAsyncWaiter* async_waiter) { mojo::MessagePipeHandle mph(handle); mojo::ScopedMessagePipeHandle scoped_handle(mph); - scoped_ptr<GLES2Context> client(new GLES2Context(g_async_waiter, - scoped_handle.Pass(), - lost_callback, - closure)); + scoped_ptr<GLES2Context> client(new GLES2Context( + async_waiter, scoped_handle.Pass(), lost_callback, closure)); if (!client->Initialize()) client.reset(); return client.release(); @@ -55,12 +43,12 @@ void MojoGLES2MakeCurrent(MojoGLES2Context context) { interface = client->interface(); DCHECK(interface); } - g_gpu_interface = interface; + g_gpu_interface.Get().Set(interface); } void MojoGLES2SwapBuffers() { - assert(g_gpu_interface); - g_gpu_interface->SwapBuffers(); + DCHECK(g_gpu_interface.Get().Get()); + g_gpu_interface.Get().Get()->SwapBuffers(); } void* MojoGLES2GetGLES2Interface(MojoGLES2Context context) { @@ -71,10 +59,10 @@ void* MojoGLES2GetContextSupport(MojoGLES2Context context) { return static_cast<GLES2Context*>(context)->context_support(); } -#define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \ - ReturnType gl##Function PARAMETERS { \ - assert(g_gpu_interface); \ - return g_gpu_interface->Function ARGUMENTS; \ +#define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \ + ReturnType gl##Function PARAMETERS { \ + DCHECK(g_gpu_interface.Get().Get()); \ + return g_gpu_interface.Get().Get()->Function ARGUMENTS; \ } #include "mojo/public/c/gles2/gles2_call_visitor_autogen.h" #undef VISIT_GL_CALL |