diff options
author | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-23 04:02:49 +0000 |
---|---|---|
committer | piman@chromium.org <piman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-01-23 04:02:49 +0000 |
commit | c329ad7d7bdd43c89468f744a8fbd6b8f3a3c3ca (patch) | |
tree | dd0659a208a0beef98218dccee894c3770111682 /mojo/apps | |
parent | 20af413cd157596fc2794e01dc8db14534e794ff (diff) | |
download | chromium_src-c329ad7d7bdd43c89468f744a8fbd6b8f3a3c3ca.zip chromium_src-c329ad7d7bdd43c89468f744a8fbd6b8f3a3c3ca.tar.gz chromium_src-c329ad7d7bdd43c89468f744a8fbd6b8f3a3c3ca.tar.bz2 |
Internalize the GLES2Client logic into libmojo_gles2
Expose an API that looks a bit like EGL to create/destroy contexts/make them
current etc. This allows libmojo_gles2 to properly hide the GLES2
implementation. A follow up wil replace it by a proper CommandBuffer interface, etc.
Some caveats:
- we need a BindingsSupport in libmojo_gles2 because it's a component. We need
to integrate with the embedder's run loop because we need to asynchronously wait
on handles, so we pass in the embedder's BindingsSupport. We should probably
pass an abstraction over the embedder's run loop, and have an implementation of
BindingsSupport on top of that (note, currently on Android libmojo_gles2 is
statically linked into the client, so we can't have 2 different
BindingsSupport).
- creating a context is currently asynchronous, and that's awkward.
- we have to expose the chrome types (GLES2Implementation/ContextSupport) for
the compositor app. That's awkward too.
- some things like RequestAnimationFrames don't belong there at all.
- libmojo_gles2 is a C API so we can't really have type safety, and some things
like callbacks are a PITA.
BUG=333157
Review URL: https://codereview.chromium.org/132913004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@246516 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/apps')
-rw-r--r-- | mojo/apps/js/bindings/gl/context.cc | 60 | ||||
-rw-r--r-- | mojo/apps/js/bindings/gl/context.h | 28 | ||||
-rw-r--r-- | mojo/apps/js/bindings/gl/module.cc | 12 | ||||
-rw-r--r-- | mojo/apps/js/main.cc | 7 | ||||
-rw-r--r-- | mojo/apps/js/main.js | 15 |
5 files changed, 90 insertions, 32 deletions
diff --git a/mojo/apps/js/bindings/gl/context.cc b/mojo/apps/js/bindings/gl/context.cc index ade9883..878a873 100644 --- a/mojo/apps/js/bindings/gl/context.cc +++ b/mojo/apps/js/bindings/gl/context.cc @@ -9,6 +9,7 @@ #include "gin/arguments.h" #include "gin/array_buffer.h" #include "gin/object_template_builder.h" +#include "gin/per_context_data.h" #include "mojo/public/gles2/gles2.h" namespace gin { @@ -31,9 +32,12 @@ namespace gl { gin::WrapperInfo Context::kWrapperInfo = { gin::kEmbedderNativeGin }; -gin::Handle<Context> Context::Create(v8::Isolate* isolate, uint64_t encoded, - int width, int height) { - return gin::CreateHandle(isolate, new Context(encoded, width, height)); +gin::Handle<Context> Context::Create( + v8::Isolate* isolate, + mojo::Handle handle, + v8::Handle<v8::Function> did_create_callback) { + return gin::CreateHandle(isolate, + new Context(isolate, handle, did_create_callback)); } void Context::BufferData(GLenum target, const gin::ArrayBufferView& buffer, @@ -144,11 +148,55 @@ gin::ObjectTemplateBuilder Context::GetObjectTemplateBuilder( .SetMethod("viewport", glViewport); } -Context::Context(uint64_t encoded, int width, int height) - : encoded_(encoded) { +Context::Context(v8::Isolate* isolate, + mojo::Handle handle, + v8::Handle<v8::Function> did_create_callback) { + v8::Handle<v8::Context> context = isolate->GetCurrentContext(); + runner_ = gin::PerContextData::From(context)->runner()->GetWeakPtr(); + did_create_callback_.Reset(isolate, did_create_callback); + context_ = MojoGLES2CreateContext( + handle.value(), + &DidCreateContextThunk, + &ContextLostThunk, + NULL, + this); +} + +Context::~Context() { + MojoGLES2DestroyContext(context_); +} + +void Context::DidCreateContext(uint32_t width, uint32_t height) { // TODO(aa): When we want to support multiple contexts, we should add // Context::MakeCurrent() for developers to switch between them. - MojoGLES2MakeCurrent(encoded_); + MojoGLES2MakeCurrent(context_); + if (!runner_) + return; + gin::Runner::Scope scope(runner_.get()); + v8::Isolate* isolate = runner_->isolate(); + + v8::Handle<v8::Function> callback = v8::Local<v8::Function>::New( + isolate, did_create_callback_); + + v8::Handle<v8::Value> args[] = { + gin::ConvertToV8(isolate, width), + gin::ConvertToV8(isolate, height), + }; + runner_->Call(callback, runner_->global(), 2, args); +} + +void Context::DidCreateContextThunk( + void* closure, + uint32_t width, + uint32_t height) { + static_cast<Context*>(closure)->DidCreateContext(width, height); +} + +void Context::ContextLost() { +} + +void Context::ContextLostThunk(void* closure) { + static_cast<Context*>(closure)->ContextLost(); } } // namespace gl diff --git a/mojo/apps/js/bindings/gl/context.h b/mojo/apps/js/bindings/gl/context.h index 081dbb2..de47f15 100644 --- a/mojo/apps/js/bindings/gl/context.h +++ b/mojo/apps/js/bindings/gl/context.h @@ -7,9 +7,13 @@ #include <GLES2/gl2.h> +#include "base/memory/weak_ptr.h" #include "gin/handle.h" #include "gin/public/wrapper_info.h" +#include "gin/runner.h" #include "gin/wrappable.h" +#include "mojo/apps/js/bindings/handle.h" +#include "mojo/public/gles2/gles2.h" #include "v8/include/v8.h" namespace gin { @@ -26,8 +30,11 @@ class Context : public gin::Wrappable<Context> { public: static gin::WrapperInfo kWrapperInfo; - static gin::Handle<Context> Create(v8::Isolate* isolate, uint64_t encoded, - int width, int height); + // TODO(piman): lost context callback, draw animation frame callback. + static gin::Handle<Context> Create( + v8::Isolate* isolate, + mojo::Handle handle, + v8::Handle<v8::Function> did_create_callback); static void BufferData(GLenum target, const gin::ArrayBufferView& buffer, GLenum usage); @@ -50,9 +57,22 @@ class Context : public gin::Wrappable<Context> { virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder( v8::Isolate* isolate) OVERRIDE; - Context(uint64_t encoded, int width, int height); + explicit Context(v8::Isolate* isolate, + mojo::Handle handle, + v8::Handle<v8::Function> did_create_callback); + virtual ~Context(); - uint64_t encoded_; + void DidCreateContext(uint32_t width, uint32_t height); + static void DidCreateContextThunk( + void* closure, + uint32_t width, + uint32_t height); + void ContextLost(); + static void ContextLostThunk(void* closure); + + base::WeakPtr<gin::Runner> runner_; + v8::Persistent<v8::Function> did_create_callback_; + MojoGLES2Context context_; }; } // namespace gl diff --git a/mojo/apps/js/bindings/gl/module.cc b/mojo/apps/js/bindings/gl/module.cc index 2c67ac1..973e9be 100644 --- a/mojo/apps/js/bindings/gl/module.cc +++ b/mojo/apps/js/bindings/gl/module.cc @@ -4,15 +4,13 @@ #include "mojo/apps/js/bindings/gl/module.h" -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> - #include "base/logging.h" #include "gin/arguments.h" #include "gin/object_template_builder.h" #include "gin/per_isolate_data.h" #include "gin/wrappable.h" #include "mojo/apps/js/bindings/gl/context.h" +#include "mojo/apps/js/bindings/handle.h" namespace mojo { namespace js { @@ -24,9 +22,11 @@ namespace { gin::WrapperInfo kWrapperInfo = { gin::kEmbedderNativeGin }; -gin::Handle<Context> CreateContext(const gin::Arguments& args, uint64_t encoded, - int width, int height) { - return Context::Create(args.isolate(), encoded, width, height); +gin::Handle<Context> CreateContext( + const gin::Arguments& args, + mojo::Handle handle, + v8::Handle<v8::Function> did_create_callback) { + return Context::Create(args.isolate(), handle, did_create_callback); } } // namespace diff --git a/mojo/apps/js/main.cc b/mojo/apps/js/main.cc index bfc6e2c..50f46d4 100644 --- a/mojo/apps/js/main.cc +++ b/mojo/apps/js/main.cc @@ -5,7 +5,7 @@ #include "base/message_loop/message_loop.h" #include "gin/public/isolate_holder.h" #include "mojo/apps/js/mojo_runner_delegate.h" -#include "mojo/public/gles2/gles2.h" +#include "mojo/public/gles2/gles2_cpp.h" #include "mojo/public/system/core_cpp.h" #include "mojo/public/system/macros.h" @@ -37,10 +37,7 @@ void Start(MojoHandle pipe, const std::string& module) { } // namespace mojo extern "C" MOJO_APPS_JS_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) { - MojoGLES2Initialize(); - + mojo::GLES2Initializer gles2; mojo::apps::Start(pipe, "mojo/apps/js/main"); - - MojoGLES2Terminate(); return MOJO_RESULT_OK; } diff --git a/mojo/apps/js/main.js b/mojo/apps/js/main.js index 4f821a7..9ca9e9d 100644 --- a/mojo/apps/js/main.js +++ b/mojo/apps/js/main.js @@ -11,7 +11,6 @@ define([ 'mojo/apps/js/bindings/gl', 'mojo/apps/js/bindings/threading', 'mojom/native_viewport', - 'mojom/gles2', 'mojom/shell', ], function(console, monotonicClock, @@ -21,7 +20,6 @@ define([ gljs, threading, nativeViewport, - gles2, shell) { const VERTEX_SHADER_SOURCE = [ @@ -297,7 +295,7 @@ define([ this.remote_ = remote; var pipe = core.createMessagePipe(); - new connector.Connection(pipe.handle0, GLES2ClientImpl, gles2.GLES2Proxy); + new GLES2ClientImpl(pipe.handle0); this.remote_.open(); this.remote_.createGLES2Context(pipe.handle1); @@ -313,20 +311,15 @@ define([ }; - function GLES2ClientImpl(remote) { - this.remote_ = remote; + function GLES2ClientImpl(remotePipe) { + this.gl_ = new gljs.Context(remotePipe, this.didCreateContext.bind(this)); this.lastTime_ = monotonicClock.seconds(); this.angle_ = 45; } - GLES2ClientImpl.prototype = - Object.create(gles2.GLES2ClientStub.prototype); - GLES2ClientImpl.prototype.didCreateContext = function(encoded, - width, - height) { + GLES2ClientImpl.prototype.didCreateContext = function(width, height) { this.width_ = width; this.height_ = height; - this.gl_ = new gljs.Context(encoded, width, height); this.program_ = loadProgram(this.gl_); this.positionLocation_ = this.gl_.getAttribLocation(this.program_, 'a_position'); |