Commit 882aa3c9 authored by jamesr@chromium.org's avatar jamesr@chromium.org

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
parent 15b9275f
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "gin/object_template_builder.h" #include "gin/object_template_builder.h"
#include "gin/per_context_data.h" #include "gin/per_context_data.h"
#include "mojo/public/c/gles2/gles2.h" #include "mojo/public/c/gles2/gles2.h"
#include "mojo/public/cpp/environment/environment.h"
namespace gin { namespace gin {
template<> template<>
...@@ -154,10 +155,10 @@ Context::Context(v8::Isolate* isolate, ...@@ -154,10 +155,10 @@ Context::Context(v8::Isolate* isolate,
v8::Handle<v8::Context> context = isolate->GetCurrentContext(); v8::Handle<v8::Context> context = isolate->GetCurrentContext();
runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr();
context_lost_callback_.Reset(isolate, context_lost_callback); context_lost_callback_.Reset(isolate, context_lost_callback);
context_ = MojoGLES2CreateContext( context_ = MojoGLES2CreateContext(handle.value(),
handle.value(), &ContextLostThunk,
&ContextLostThunk, this,
this); Environment::GetDefaultAsyncWaiter());
MojoGLES2MakeCurrent(context_); MojoGLES2MakeCurrent(context_);
} }
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include "base/message_loop/message_loop.h" #include "base/message_loop/message_loop.h"
#include "gin/public/isolate_holder.h" #include "gin/public/isolate_holder.h"
#include "mojo/apps/js/mojo_runner_delegate.h" #include "mojo/apps/js/mojo_runner_delegate.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.h" #include "mojo/public/cpp/system/macros.h"
...@@ -37,7 +36,6 @@ void Start(MojoHandle pipe, const std::string& module) { ...@@ -37,7 +36,6 @@ void Start(MojoHandle pipe, const std::string& module) {
} // namespace mojo } // namespace mojo
extern "C" MOJO_APPS_JS_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) { extern "C" MOJO_APPS_JS_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) {
mojo::GLES2Initializer gles2;
mojo::apps::Start(pipe, "mojo/apps/js/main"); mojo::apps::Start(pipe, "mojo/apps/js/main");
return MOJO_RESULT_OK; return MOJO_RESULT_OK;
} }
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "mojo/cc/context_provider_mojo.h" #include "mojo/cc/context_provider_mojo.h"
#include "base/logging.h" #include "base/logging.h"
#include "mojo/public/cpp/environment/environment.h"
namespace mojo { namespace mojo {
...@@ -16,10 +17,10 @@ ContextProviderMojo::ContextProviderMojo( ...@@ -16,10 +17,10 @@ ContextProviderMojo::ContextProviderMojo(
bool ContextProviderMojo::BindToCurrentThread() { bool ContextProviderMojo::BindToCurrentThread() {
DCHECK(command_buffer_handle_.is_valid()); DCHECK(command_buffer_handle_.is_valid());
context_ = MojoGLES2CreateContext( context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(),
command_buffer_handle_.release().value(), &ContextLostThunk,
&ContextLostThunk, this,
this); Environment::GetDefaultAsyncWaiter());
return !!context_; return !!context_;
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "mojo/examples/compositor_app/compositor_host.h" #include "mojo/examples/compositor_app/compositor_host.h"
#include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h" #include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/core.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h" #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
...@@ -53,7 +52,6 @@ class SampleApp : public ApplicationDelegate, public NativeViewportClient { ...@@ -53,7 +52,6 @@ class SampleApp : public ApplicationDelegate, public NativeViewportClient {
} }
private: private:
mojo::GLES2Initializer gles2;
NativeViewportPtr viewport_; NativeViewportPtr viewport_;
scoped_ptr<CompositorHost> host_; scoped_ptr<CompositorHost> host_;
DISALLOW_COPY_AND_ASSIGN(SampleApp); DISALLOW_COPY_AND_ASSIGN(SampleApp);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h" #include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h"
#include "mojo/examples/pepper_container_app/plugin_instance.h" #include "mojo/examples/pepper_container_app/plugin_instance.h"
#include "mojo/public/c/gles2/gles2.h" #include "mojo/public/c/gles2/gles2.h"
#include "mojo/public/cpp/environment/environment.h"
#include "ppapi/c/pp_errors.h" #include "ppapi/c/pp_errors.h"
namespace mojo { namespace mojo {
...@@ -28,7 +29,8 @@ Graphics3DResource::Graphics3DResource(PP_Instance instance) ...@@ -28,7 +29,8 @@ Graphics3DResource::Graphics3DResource(PP_Instance instance)
ScopedMessagePipeHandle pipe = MojoPpapiGlobals::Get()->CreateGLES2Context(); ScopedMessagePipeHandle pipe = MojoPpapiGlobals::Get()->CreateGLES2Context();
context_ = MojoGLES2CreateContext(pipe.release().value(), context_ = MojoGLES2CreateContext(pipe.release().value(),
&ContextLostThunk, &ContextLostThunk,
this); this,
Environment::GetDefaultAsyncWaiter());
} }
bool Graphics3DResource::IsBoundGraphics() const { bool Graphics3DResource::IsBoundGraphics() const {
......
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
#include "mojo/examples/pepper_container_app/type_converters.h" #include "mojo/examples/pepper_container_app/type_converters.h"
#include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h" #include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/core.h"
#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h" #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
#include "ppapi/c/pp_rect.h" #include "ppapi/c/pp_rect.h"
......
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
#include <stdlib.h> #include <stdlib.h>
#include "mojo/public/c/gles2/gles2.h" #include "mojo/public/c/gles2/gles2.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/utility/run_loop.h" #include "mojo/public/cpp/utility/run_loop.h"
namespace examples { namespace examples {
...@@ -28,10 +29,11 @@ float GetRandomColor() { ...@@ -28,10 +29,11 @@ float GetRandomColor() {
GLES2ClientImpl::GLES2ClientImpl(mojo::CommandBufferPtr command_buffer) GLES2ClientImpl::GLES2ClientImpl(mojo::CommandBufferPtr command_buffer)
: last_time_(mojo::GetTimeTicksNow()), waiting_to_draw_(false) { : last_time_(mojo::GetTimeTicksNow()), waiting_to_draw_(false) {
context_ = MojoGLES2CreateContext( context_ =
command_buffer.PassMessagePipe().release().value(), MojoGLES2CreateContext(command_buffer.PassMessagePipe().release().value(),
&ContextLostThunk, &ContextLostThunk,
this); this,
mojo::Environment::GetDefaultAsyncWaiter());
MojoGLES2MakeCurrent(context_); MojoGLES2MakeCurrent(context_);
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "mojo/public/cpp/application/application_connection.h" #include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_delegate.h" #include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/application/application_impl.h" #include "mojo/public/cpp/application/application_impl.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/public/cpp/system/core.h" #include "mojo/public/cpp/system/core.h"
#include "mojo/public/cpp/system/macros.h" #include "mojo/public/cpp/system/macros.h"
#include "mojo/public/cpp/utility/run_loop.h" #include "mojo/public/cpp/utility/run_loop.h"
...@@ -70,7 +69,6 @@ class SampleApp : public mojo::ApplicationDelegate, ...@@ -70,7 +69,6 @@ class SampleApp : public mojo::ApplicationDelegate,
} }
private: private:
mojo::GLES2Initializer gles2;
scoped_ptr<GLES2ClientImpl> gles2_client_; scoped_ptr<GLES2ClientImpl> gles2_client_;
mojo::NativeViewportPtr viewport_; mojo::NativeViewportPtr viewport_;
......
...@@ -4,6 +4,8 @@ ...@@ -4,6 +4,8 @@
#include "mojo/public/c/gles2/gles2.h" #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 "gpu/command_buffer/client/gles2_interface.h"
#include "mojo/gles2/gles2_context.h" #include "mojo/gles2/gles2_context.h"
...@@ -11,34 +13,20 @@ using mojo::gles2::GLES2Context; ...@@ -11,34 +13,20 @@ using mojo::gles2::GLES2Context;
namespace { namespace {
const MojoAsyncWaiter* g_async_waiter = NULL; base::LazyInstance<base::ThreadLocalPointer<gpu::gles2::GLES2Interface> >::Leaky
gpu::gles2::GLES2Interface* g_gpu_interface = NULL; g_gpu_interface;
} // namespace } // namespace
extern "C" { extern "C" {
MojoGLES2Context MojoGLES2CreateContext(MojoHandle handle,
void MojoGLES2Initialize(const MojoAsyncWaiter* async_waiter) { MojoGLES2ContextLost lost_callback,
DCHECK(!g_async_waiter); void* closure,
DCHECK(async_waiter); const MojoAsyncWaiter* 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) {
mojo::MessagePipeHandle mph(handle); mojo::MessagePipeHandle mph(handle);
mojo::ScopedMessagePipeHandle scoped_handle(mph); mojo::ScopedMessagePipeHandle scoped_handle(mph);
scoped_ptr<GLES2Context> client(new GLES2Context(g_async_waiter, scoped_ptr<GLES2Context> client(new GLES2Context(
scoped_handle.Pass(), async_waiter, scoped_handle.Pass(), lost_callback, closure));
lost_callback,
closure));
if (!client->Initialize()) if (!client->Initialize())
client.reset(); client.reset();
return client.release(); return client.release();
...@@ -55,12 +43,12 @@ void MojoGLES2MakeCurrent(MojoGLES2Context context) { ...@@ -55,12 +43,12 @@ void MojoGLES2MakeCurrent(MojoGLES2Context context) {
interface = client->interface(); interface = client->interface();
DCHECK(interface); DCHECK(interface);
} }
g_gpu_interface = interface; g_gpu_interface.Get().Set(interface);
} }
void MojoGLES2SwapBuffers() { void MojoGLES2SwapBuffers() {
assert(g_gpu_interface); DCHECK(g_gpu_interface.Get().Get());
g_gpu_interface->SwapBuffers(); g_gpu_interface.Get().Get()->SwapBuffers();
} }
void* MojoGLES2GetGLES2Interface(MojoGLES2Context context) { void* MojoGLES2GetGLES2Interface(MojoGLES2Context context) {
...@@ -71,10 +59,10 @@ void* MojoGLES2GetContextSupport(MojoGLES2Context context) { ...@@ -71,10 +59,10 @@ void* MojoGLES2GetContextSupport(MojoGLES2Context context) {
return static_cast<GLES2Context*>(context)->context_support(); return static_cast<GLES2Context*>(context)->context_support();
} }
#define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \ #define VISIT_GL_CALL(Function, ReturnType, PARAMETERS, ARGUMENTS) \
ReturnType gl##Function PARAMETERS { \ ReturnType gl##Function PARAMETERS { \
assert(g_gpu_interface); \ DCHECK(g_gpu_interface.Get().Get()); \
return g_gpu_interface->Function ARGUMENTS; \ return g_gpu_interface.Get().Get()->Function ARGUMENTS; \
} }
#include "mojo/public/c/gles2/gles2_call_visitor_autogen.h" #include "mojo/public/c/gles2/gles2_call_visitor_autogen.h"
#undef VISIT_GL_CALL #undef VISIT_GL_CALL
......
...@@ -379,7 +379,6 @@ ...@@ -379,7 +379,6 @@
'mojo_surfaces_bindings', 'mojo_surfaces_bindings',
'mojo_surfaces_app_bindings', 'mojo_surfaces_app_bindings',
'mojo_surfaces_lib', 'mojo_surfaces_lib',
'<(mojo_gles2_for_loadable_module)',
'<(mojo_system_for_loadable_module)', '<(mojo_system_for_loadable_module)',
], ],
'sources': [ 'sources': [
......
...@@ -19,12 +19,11 @@ ...@@ -19,12 +19,11 @@
extern "C" { extern "C" {
#endif #endif
MOJO_GLES2_EXPORT void MojoGLES2Initialize(const MojoAsyncWaiter* async_waiter); MOJO_GLES2_EXPORT MojoGLES2Context
MOJO_GLES2_EXPORT void MojoGLES2Terminate(void); MojoGLES2CreateContext(MojoHandle handle,
MOJO_GLES2_EXPORT MojoGLES2Context MojoGLES2CreateContext( MojoGLES2ContextLost lost_callback,
MojoHandle handle, void* closure,
MojoGLES2ContextLost lost_callback, const MojoAsyncWaiter* async_waiter);
void* closure);
MOJO_GLES2_EXPORT void MojoGLES2DestroyContext(MojoGLES2Context context); MOJO_GLES2_EXPORT void MojoGLES2DestroyContext(MojoGLES2Context context);
MOJO_GLES2_EXPORT void MojoGLES2MakeCurrent(MojoGLES2Context context); MOJO_GLES2_EXPORT void MojoGLES2MakeCurrent(MojoGLES2Context context);
MOJO_GLES2_EXPORT void MojoGLES2SwapBuffers(void); MOJO_GLES2_EXPORT void MojoGLES2SwapBuffers(void);
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef MOJO_PUBLIC_CPP_GLES2_GLES2_H_
#define MOJO_PUBLIC_CPP_GLES2_GLES2_H_
#include "mojo/public/c/gles2/gles2.h"
#include "mojo/public/cpp/environment/environment.h"
namespace mojo {
class GLES2Initializer {
public:
explicit GLES2Initializer(const MojoAsyncWaiter* async_waiter =
Environment::GetDefaultAsyncWaiter()) {
MojoGLES2Initialize(async_waiter);
}
~GLES2Initializer() { MojoGLES2Terminate(); }
};
} // namespace mojo
#endif // MOJO_PUBLIC_CPP_GLES2_GLES2_H_
...@@ -13,22 +13,13 @@ extern "C" { ...@@ -13,22 +13,13 @@ extern "C" {
static MojoGLES2ControlThunks g_control_thunks = {0}; static MojoGLES2ControlThunks g_control_thunks = {0};
static MojoGLES2ImplThunks g_impl_thunks = {0}; static MojoGLES2ImplThunks g_impl_thunks = {0};
void MojoGLES2Initialize(const MojoAsyncWaiter* async_waiter) { MojoGLES2Context MojoGLES2CreateContext(MojoHandle handle,
assert(g_control_thunks.GLES2Initialize); MojoGLES2ContextLost lost_callback,
g_control_thunks.GLES2Initialize(async_waiter); void* closure,
} const MojoAsyncWaiter* async_waiter) {
void MojoGLES2Terminate() {
assert(g_control_thunks.GLES2Terminate);
g_control_thunks.GLES2Terminate();
}
MojoGLES2Context MojoGLES2CreateContext(
MojoHandle handle,
MojoGLES2ContextLost lost_callback,
void* closure) {
assert(g_control_thunks.GLES2CreateContext); assert(g_control_thunks.GLES2CreateContext);
return g_control_thunks.GLES2CreateContext(handle, lost_callback, closure); return g_control_thunks.GLES2CreateContext(
handle, lost_callback, closure, async_waiter);
} }
void MojoGLES2DestroyContext(MojoGLES2Context context) { void MojoGLES2DestroyContext(MojoGLES2Context context) {
......
...@@ -18,12 +18,10 @@ ...@@ -18,12 +18,10 @@
struct MojoGLES2ControlThunks { struct MojoGLES2ControlThunks {
size_t size; // Should be set to sizeof(MojoGLES2ControlThunks). size_t size; // Should be set to sizeof(MojoGLES2ControlThunks).
void (*GLES2Initialize)(const MojoAsyncWaiter* async_waiter); MojoGLES2Context (*GLES2CreateContext)(MojoHandle handle,
void (*GLES2Terminate)(); MojoGLES2ContextLost lost_callback,
MojoGLES2Context (*GLES2CreateContext)( void* closure,
MojoHandle handle, const MojoAsyncWaiter* async_waiter);
MojoGLES2ContextLost lost_callback,
void* closure);
void (*GLES2DestroyContext)(MojoGLES2Context context); void (*GLES2DestroyContext)(MojoGLES2Context context);
void (*GLES2MakeCurrent)(MojoGLES2Context context); void (*GLES2MakeCurrent)(MojoGLES2Context context);
void (*GLES2SwapBuffers)(); void (*GLES2SwapBuffers)();
...@@ -40,8 +38,6 @@ struct MojoGLES2ControlThunks { ...@@ -40,8 +38,6 @@ struct MojoGLES2ControlThunks {
inline MojoGLES2ControlThunks MojoMakeGLES2ControlThunks() { inline MojoGLES2ControlThunks MojoMakeGLES2ControlThunks() {
MojoGLES2ControlThunks gles2_control_thunks = { MojoGLES2ControlThunks gles2_control_thunks = {
sizeof(MojoGLES2ControlThunks), sizeof(MojoGLES2ControlThunks),
MojoGLES2Initialize,
MojoGLES2Terminate,
MojoGLES2CreateContext, MojoGLES2CreateContext,
MojoGLES2DestroyContext, MojoGLES2DestroyContext,
MojoGLES2MakeCurrent, MojoGLES2MakeCurrent,
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include "cc/surfaces/display.h" #include "cc/surfaces/display.h"
#include "cc/surfaces/surface_id_allocator.h" #include "cc/surfaces/surface_id_allocator.h"
#include "mojo/cc/context_provider_mojo.h" #include "mojo/cc/context_provider_mojo.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h" #include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h" #include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h"
...@@ -90,8 +89,6 @@ void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) { ...@@ -90,8 +89,6 @@ void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) {
} }
scoped_ptr<cc::OutputSurface> SurfacesImpl::CreateOutputSurface() { scoped_ptr<cc::OutputSurface> SurfacesImpl::CreateOutputSurface() {
static GLES2Initializer* gles2 = new GLES2Initializer;
DCHECK(gles2);
return make_scoped_ptr(new cc::OutputSurface( return make_scoped_ptr(new cc::OutputSurface(
new ContextProviderMojo(command_buffer_handle_.Pass()))); new ContextProviderMojo(command_buffer_handle_.Pass())));
} }
......
...@@ -10,7 +10,6 @@ ...@@ -10,7 +10,6 @@
#include "base/basictypes.h" #include "base/basictypes.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
#include "mojo/public/cpp/bindings/callback.h" #include "mojo/public/cpp/bindings/callback.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/services/view_manager/view_manager_export.h" #include "mojo/services/view_manager/view_manager_export.h"
namespace aura { namespace aura {
...@@ -53,8 +52,6 @@ class MOJO_VIEW_MANAGER_EXPORT RootViewManager { ...@@ -53,8 +52,6 @@ class MOJO_VIEW_MANAGER_EXPORT RootViewManager {
RootNodeManager* root_node_manager_; RootNodeManager* root_node_manager_;
GLES2Initializer gles_initializer_;
// Returns true if adding the root node's window to |window_tree_host_|. // Returns true if adding the root node's window to |window_tree_host_|.
bool in_setup_; bool in_setup_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment