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 @@
#include "gin/object_template_builder.h"
#include "gin/per_context_data.h"
#include "mojo/public/c/gles2/gles2.h"
#include "mojo/public/cpp/environment/environment.h"
namespace gin {
template<>
......@@ -154,10 +155,10 @@ Context::Context(v8::Isolate* isolate,
v8::Handle<v8::Context> context = isolate->GetCurrentContext();
runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr();
context_lost_callback_.Reset(isolate, context_lost_callback);
context_ = MojoGLES2CreateContext(
handle.value(),
&ContextLostThunk,
this);
context_ = MojoGLES2CreateContext(handle.value(),
&ContextLostThunk,
this,
Environment::GetDefaultAsyncWaiter());
MojoGLES2MakeCurrent(context_);
}
......
......@@ -5,7 +5,6 @@
#include "base/message_loop/message_loop.h"
#include "gin/public/isolate_holder.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/macros.h"
......@@ -37,7 +36,6 @@ void Start(MojoHandle pipe, const std::string& module) {
} // namespace mojo
extern "C" MOJO_APPS_JS_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) {
mojo::GLES2Initializer gles2;
mojo::apps::Start(pipe, "mojo/apps/js/main");
return MOJO_RESULT_OK;
}
......@@ -5,6 +5,7 @@
#include "mojo/cc/context_provider_mojo.h"
#include "base/logging.h"
#include "mojo/public/cpp/environment/environment.h"
namespace mojo {
......@@ -16,10 +17,10 @@ ContextProviderMojo::ContextProviderMojo(
bool ContextProviderMojo::BindToCurrentThread() {
DCHECK(command_buffer_handle_.is_valid());
context_ = MojoGLES2CreateContext(
command_buffer_handle_.release().value(),
&ContextLostThunk,
this);
context_ = MojoGLES2CreateContext(command_buffer_handle_.release().value(),
&ContextLostThunk,
this,
Environment::GetDefaultAsyncWaiter());
return !!context_;
}
......
......@@ -9,7 +9,6 @@
#include "mojo/examples/compositor_app/compositor_host.h"
#include "mojo/public/cpp/application/application_delegate.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/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
......@@ -53,7 +52,6 @@ class SampleApp : public ApplicationDelegate, public NativeViewportClient {
}
private:
mojo::GLES2Initializer gles2;
NativeViewportPtr viewport_;
scoped_ptr<CompositorHost> host_;
DISALLOW_COPY_AND_ASSIGN(SampleApp);
......
......@@ -8,6 +8,7 @@
#include "mojo/examples/pepper_container_app/mojo_ppapi_globals.h"
#include "mojo/examples/pepper_container_app/plugin_instance.h"
#include "mojo/public/c/gles2/gles2.h"
#include "mojo/public/cpp/environment/environment.h"
#include "ppapi/c/pp_errors.h"
namespace mojo {
......@@ -28,7 +29,8 @@ Graphics3DResource::Graphics3DResource(PP_Instance instance)
ScopedMessagePipeHandle pipe = MojoPpapiGlobals::Get()->CreateGLES2Context();
context_ = MojoGLES2CreateContext(pipe.release().value(),
&ContextLostThunk,
this);
this,
Environment::GetDefaultAsyncWaiter());
}
bool Graphics3DResource::IsBoundGraphics() const {
......
......@@ -13,7 +13,6 @@
#include "mojo/examples/pepper_container_app/type_converters.h"
#include "mojo/public/cpp/application/application_delegate.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/services/public/interfaces/native_viewport/native_viewport.mojom.h"
#include "ppapi/c/pp_rect.h"
......
......@@ -10,6 +10,7 @@
#include <stdlib.h>
#include "mojo/public/c/gles2/gles2.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/utility/run_loop.h"
namespace examples {
......@@ -28,10 +29,11 @@ float GetRandomColor() {
GLES2ClientImpl::GLES2ClientImpl(mojo::CommandBufferPtr command_buffer)
: last_time_(mojo::GetTimeTicksNow()), waiting_to_draw_(false) {
context_ = MojoGLES2CreateContext(
command_buffer.PassMessagePipe().release().value(),
&ContextLostThunk,
this);
context_ =
MojoGLES2CreateContext(command_buffer.PassMessagePipe().release().value(),
&ContextLostThunk,
this,
mojo::Environment::GetDefaultAsyncWaiter());
MojoGLES2MakeCurrent(context_);
}
......
......@@ -9,7 +9,6 @@
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_delegate.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/macros.h"
#include "mojo/public/cpp/utility/run_loop.h"
......@@ -70,7 +69,6 @@ class SampleApp : public mojo::ApplicationDelegate,
}
private:
mojo::GLES2Initializer gles2;
scoped_ptr<GLES2ClientImpl> gles2_client_;
mojo::NativeViewportPtr viewport_;
......
......@@ -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
......
......@@ -379,7 +379,6 @@
'mojo_surfaces_bindings',
'mojo_surfaces_app_bindings',
'mojo_surfaces_lib',
'<(mojo_gles2_for_loadable_module)',
'<(mojo_system_for_loadable_module)',
],
'sources': [
......
......@@ -19,12 +19,11 @@
extern "C" {
#endif
MOJO_GLES2_EXPORT void MojoGLES2Initialize(const MojoAsyncWaiter* async_waiter);
MOJO_GLES2_EXPORT void MojoGLES2Terminate(void);
MOJO_GLES2_EXPORT MojoGLES2Context MojoGLES2CreateContext(
MojoHandle handle,
MojoGLES2ContextLost lost_callback,
void* closure);
MOJO_GLES2_EXPORT MojoGLES2Context
MojoGLES2CreateContext(MojoHandle handle,
MojoGLES2ContextLost lost_callback,
void* closure,
const MojoAsyncWaiter* async_waiter);
MOJO_GLES2_EXPORT void MojoGLES2DestroyContext(MojoGLES2Context context);
MOJO_GLES2_EXPORT void MojoGLES2MakeCurrent(MojoGLES2Context context);
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" {
static MojoGLES2ControlThunks g_control_thunks = {0};
static MojoGLES2ImplThunks g_impl_thunks = {0};
void MojoGLES2Initialize(const MojoAsyncWaiter* async_waiter) {
assert(g_control_thunks.GLES2Initialize);
g_control_thunks.GLES2Initialize(async_waiter);
}
void MojoGLES2Terminate() {
assert(g_control_thunks.GLES2Terminate);
g_control_thunks.GLES2Terminate();
}
MojoGLES2Context MojoGLES2CreateContext(
MojoHandle handle,
MojoGLES2ContextLost lost_callback,
void* closure) {
MojoGLES2Context MojoGLES2CreateContext(MojoHandle handle,
MojoGLES2ContextLost lost_callback,
void* closure,
const MojoAsyncWaiter* async_waiter) {
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) {
......
......@@ -18,12 +18,10 @@
struct MojoGLES2ControlThunks {
size_t size; // Should be set to sizeof(MojoGLES2ControlThunks).
void (*GLES2Initialize)(const MojoAsyncWaiter* async_waiter);
void (*GLES2Terminate)();
MojoGLES2Context (*GLES2CreateContext)(
MojoHandle handle,
MojoGLES2ContextLost lost_callback,
void* closure);
MojoGLES2Context (*GLES2CreateContext)(MojoHandle handle,
MojoGLES2ContextLost lost_callback,
void* closure,
const MojoAsyncWaiter* async_waiter);
void (*GLES2DestroyContext)(MojoGLES2Context context);
void (*GLES2MakeCurrent)(MojoGLES2Context context);
void (*GLES2SwapBuffers)();
......@@ -40,8 +38,6 @@ struct MojoGLES2ControlThunks {
inline MojoGLES2ControlThunks MojoMakeGLES2ControlThunks() {
MojoGLES2ControlThunks gles2_control_thunks = {
sizeof(MojoGLES2ControlThunks),
MojoGLES2Initialize,
MojoGLES2Terminate,
MojoGLES2CreateContext,
MojoGLES2DestroyContext,
MojoGLES2MakeCurrent,
......
......@@ -9,7 +9,6 @@
#include "cc/surfaces/display.h"
#include "cc/surfaces/surface_id_allocator.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/surfaces/surfaces_type_converters.h"
......@@ -90,8 +89,6 @@ void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) {
}
scoped_ptr<cc::OutputSurface> SurfacesImpl::CreateOutputSurface() {
static GLES2Initializer* gles2 = new GLES2Initializer;
DCHECK(gles2);
return make_scoped_ptr(new cc::OutputSurface(
new ContextProviderMojo(command_buffer_handle_.Pass())));
}
......
......@@ -10,7 +10,6 @@
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "mojo/public/cpp/bindings/callback.h"
#include "mojo/public/cpp/gles2/gles2.h"
#include "mojo/services/view_manager/view_manager_export.h"
namespace aura {
......@@ -53,8 +52,6 @@ class MOJO_VIEW_MANAGER_EXPORT RootViewManager {
RootNodeManager* root_node_manager_;
GLES2Initializer gles_initializer_;
// Returns true if adding the root node's window to |window_tree_host_|.
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