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/examples/compositor_app | |
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/examples/compositor_app')
-rw-r--r-- | mojo/examples/compositor_app/compositor_app.cc | 5 | ||||
-rw-r--r-- | mojo/examples/compositor_app/gles2_client_impl.cc | 57 | ||||
-rw-r--r-- | mojo/examples/compositor_app/gles2_client_impl.h | 20 |
3 files changed, 53 insertions, 29 deletions
diff --git a/mojo/examples/compositor_app/compositor_app.cc b/mojo/examples/compositor_app/compositor_app.cc index d2547fd..a4e1182 100644 --- a/mojo/examples/compositor_app/compositor_app.cc +++ b/mojo/examples/compositor_app/compositor_app.cc @@ -9,7 +9,7 @@ #include "mojo/examples/compositor_app/compositor_host.h" #include "mojo/examples/compositor_app/gles2_client_impl.h" #include "mojo/public/bindings/lib/remote_ptr.h" -#include "mojo/public/gles2/gles2.h" +#include "mojo/public/gles2/gles2_cpp.h" #include "mojo/public/system/core.h" #include "mojo/public/system/macros.h" #include "mojom/native_viewport.h" @@ -96,12 +96,11 @@ class SampleApp : public ShellClient { extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( MojoHandle shell_handle) { base::MessageLoop loop; - MojoGLES2Initialize(); + mojo::GLES2Initializer gles2; mojo::examples::SampleApp app( mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle)).Pass()); loop.Run(); - MojoGLES2Terminate(); return MOJO_RESULT_OK; } diff --git a/mojo/examples/compositor_app/gles2_client_impl.cc b/mojo/examples/compositor_app/gles2_client_impl.cc index 7bd0b06..3b59f96 100644 --- a/mojo/examples/compositor_app/gles2_client_impl.cc +++ b/mojo/examples/compositor_app/gles2_client_impl.cc @@ -5,8 +5,8 @@ #include "mojo/examples/compositor_app/gles2_client_impl.h" #include "base/debug/trace_event.h" -#include "gpu/command_buffer/client/gles2_implementation.h" -#include "mojo/public/gles2/gles2.h" +#include "gpu/command_buffer/client/context_support.h" +#include "gpu/command_buffer/client/gles2_interface.h" namespace mojo { namespace examples { @@ -14,33 +14,58 @@ namespace examples { GLES2ClientImpl::GLES2ClientImpl( ScopedMessagePipeHandle pipe, const base::Callback<void(gfx::Size)>& context_created_callback) - : context_created_callback_(context_created_callback), - impl_(NULL), - service_(pipe.Pass(), this) { + : context_created_callback_(context_created_callback) { + context_ = MojoGLES2CreateContext( + pipe.release().value(), + &DidCreateContextThunk, + &ContextLostThunk, + NULL, + this); } -GLES2ClientImpl::~GLES2ClientImpl() { service_->Destroy(); } +GLES2ClientImpl::~GLES2ClientImpl() { + if (context_) + MojoGLES2DestroyContext(context_); +} + +gpu::gles2::GLES2Interface* GLES2ClientImpl::Interface() const { + if (!context_) + return NULL; + return static_cast<gpu::gles2::GLES2Interface*>( + MojoGLES2GetGLES2Interface(context_)); +} -void GLES2ClientImpl::DidCreateContext(uint64_t encoded, - uint32_t width, +gpu::ContextSupport* GLES2ClientImpl::Support() const { + if (!context_) + return NULL; + return static_cast<gpu::ContextSupport*>( + MojoGLES2GetContextSupport(context_)); +} + +void GLES2ClientImpl::DidCreateContext(uint32_t width, uint32_t height) { TRACE_EVENT0("compositor_app", "DidCreateContext"); - impl_ = reinterpret_cast<gpu::gles2::GLES2Implementation*>(encoded); if (!context_created_callback_.is_null()) context_created_callback_.Run(gfx::Size(width, height)); } -gpu::gles2::GLES2Interface* GLES2ClientImpl::Interface() const { - return impl_; +void GLES2ClientImpl::DidCreateContextThunk( + void* closure, + uint32_t width, + uint32_t height) { + static_cast<GLES2ClientImpl*>(closure)->DidCreateContext(width, height); } -gpu::ContextSupport* GLES2ClientImpl::Support() const { - return impl_; +void GLES2ClientImpl::ContextLost() { + if (context_) { + MojoGLES2DestroyContext(context_); + context_ = NULL; + } } -void GLES2ClientImpl::ContextLost() { impl_ = NULL; } - -void GLES2ClientImpl::DrawAnimationFrame() {} +void GLES2ClientImpl::ContextLostThunk(void* closure) { + static_cast<GLES2ClientImpl*>(closure)->ContextLost(); +} } // namespace examples } // namespace mojo diff --git a/mojo/examples/compositor_app/gles2_client_impl.h b/mojo/examples/compositor_app/gles2_client_impl.h index fbb49b0..3c91cef 100644 --- a/mojo/examples/compositor_app/gles2_client_impl.h +++ b/mojo/examples/compositor_app/gles2_client_impl.h @@ -8,7 +8,7 @@ #include "base/time/time.h" #include "base/timer/timer.h" #include "mojo/public/bindings/lib/remote_ptr.h" -#include "mojom/gles2.h" +#include "mojo/public/gles2/gles2.h" #include "mojom/native_viewport.h" #include "ui/gfx/size.h" @@ -16,14 +16,13 @@ namespace gpu { class ContextSupport; namespace gles2 { class GLES2Interface; -class GLES2Implementation; } } namespace mojo { namespace examples { -class GLES2ClientImpl : public GLES2Client { +class GLES2ClientImpl { public: GLES2ClientImpl( ScopedMessagePipeHandle pipe, @@ -34,16 +33,17 @@ class GLES2ClientImpl : public GLES2Client { gpu::ContextSupport* Support() const; private: - virtual void DidCreateContext(uint64_t encoded, - uint32_t width, - uint32_t height) MOJO_OVERRIDE; - virtual void ContextLost() MOJO_OVERRIDE; - virtual void DrawAnimationFrame() MOJO_OVERRIDE; + 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::Callback<void(gfx::Size viewport_size)> context_created_callback_; - gpu::gles2::GLES2Implementation* impl_; - RemotePtr<GLES2> service_; + MojoGLES2Context context_; MOJO_DISALLOW_COPY_AND_ASSIGN(GLES2ClientImpl); }; |