diff options
author | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-04 01:15:09 +0000 |
---|---|---|
committer | abarth@chromium.org <abarth@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-04 01:15:09 +0000 |
commit | 99e508a465b28665fe32b8f01b1dacf24c925c66 (patch) | |
tree | f3883732637ec7a6b416efa3cc7008f3d2625f4d /mojo | |
parent | 6edd060869e0cc78544a947c768e48422d499375 (diff) | |
download | chromium_src-99e508a465b28665fe32b8f01b1dacf24c925c66.zip chromium_src-99e508a465b28665fe32b8f01b1dacf24c925c66.tar.gz chromium_src-99e508a465b28665fe32b8f01b1dacf24c925c66.tar.bz2 |
[Mojo] Remove dependency between mojo/public and gpu
This CL restructures how sample_app integrates with the GPU command buffer.
Instead of mojo/public containing code that depends directly on
gpu/command_buffer, this CL isolates that dependency into a dynamically linked
library modelled after mojo_system.
1) mojo/public/gles2 contains a simple C API to libmojo_gles2.so.
2) mojo/gles2 contains a "thin" implementation of this API in terms of
gpu/command_buffer.
3) Instead of subclassing GLES2ClientStub in mojo/public/bindings, we now
subclass the stub directly in sample_app and control the GLES2 C API via
mojo/public/gles2.
I've also added a couple of README.md files that describe the purposes of the
various directories and the reasons why the code is structured in this way.
R=darin@chromium.org
Review URL: https://codereview.chromium.org/101413002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238517 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
21 files changed, 273 insertions, 259 deletions
diff --git a/mojo/README b/mojo/README.md index 96631fb..5af1dcb 100644 --- a/mojo/README +++ b/mojo/README.md @@ -1,3 +1,6 @@ -This is an effort to extract a common platform out of Chrome's renderer and +Mojo +==== + +Mojo is an effort to extract a common platform out of Chrome's renderer and plugin processes that can support multiple types of sandboxed content, such as HTML, Pepper, or NaCl. diff --git a/mojo/apps/js/bindings/threading.h b/mojo/apps/js/bindings/threading.h index 356d1e7..56905ce 100644 --- a/mojo/apps/js/bindings/threading.h +++ b/mojo/apps/js/bindings/threading.h @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef MOJO_APPS_JS_THREADING_H_ -#define MOJO_APPS_JS_THREADING_H_ +#ifndef MOJO_APPS_JS_BINDINGS_THREADING_H_ +#define MOJO_APPS_JS_BINDINGS_THREADING_H_ #include "mojo/public/system/core.h" #include "v8/include/v8.h" @@ -20,4 +20,4 @@ class Threading { } // namespace apps } // namespace mojo -#endif // MOJO_APPS_JS_THREADING_H_ +#endif // MOJO_APPS_JS_BINDINGS_THREADING_H_ diff --git a/mojo/examples/sample_app/DEPS b/mojo/examples/sample_app/DEPS deleted file mode 100644 index 2f6ef95..0000000 --- a/mojo/examples/sample_app/DEPS +++ /dev/null @@ -1,5 +0,0 @@ -include_rules = [ - # TODO(abarth): Rather than including this interface directly, - # we need to figure out the right way for apps to call GL. - "!gpu/command_buffer/client/gles2_interface.h", -] diff --git a/mojo/examples/sample_app/gles2_client_impl.cc b/mojo/examples/sample_app/gles2_client_impl.cc new file mode 100644 index 0000000..2a87ca0 --- /dev/null +++ b/mojo/examples/sample_app/gles2_client_impl.cc @@ -0,0 +1,50 @@ +// Copyright 2013 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. + +#include "mojo/examples/sample_app/gles2_client_impl.h" + +#include <GLES2/gl2.h> +#include <GLES2/gl2ext.h> + +#include "mojo/public/gles2/gles2.h" + +namespace mojo { +namespace examples { + +GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe) + : service_(pipe.Pass()) { + service_.SetPeer(this); +} + +GLES2ClientImpl::~GLES2ClientImpl() { + service_->Destroy(); +} + +void GLES2ClientImpl::DidCreateContext(uint64_t encoded, + uint32_t width, + uint32_t height) { + MojoGLES2MakeCurrent(encoded); + + cube_.Init(width, height); + last_time_ = base::Time::Now(); + timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(16), + this, &GLES2ClientImpl::Draw); +} + +void GLES2ClientImpl::Draw() { + base::Time now = base::Time::Now(); + base::TimeDelta offset = now - last_time_; + last_time_ = now; + cube_.Update(offset.InSecondsF()); + cube_.Draw(); + + MojoGLES2SwapBuffers(); +} + +void GLES2ClientImpl::ContextLost() { + timer_.Stop(); +} + +} // namespace examples +} // namespace mojo diff --git a/mojo/examples/sample_app/gles2_client_impl.h b/mojo/examples/sample_app/gles2_client_impl.h new file mode 100644 index 0000000..1d38a3c --- /dev/null +++ b/mojo/examples/sample_app/gles2_client_impl.h @@ -0,0 +1,41 @@ +// Copyright 2013 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_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_ +#define MOJO_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_ + +#include "base/timer/timer.h" +#include "mojo/examples/sample_app/spinning_cube.h" +#include "mojo/public/bindings/lib/remote_ptr.h" +#include "mojom/gles2.h" + +namespace mojo { +namespace examples { + +class GLES2ClientImpl : public GLES2ClientStub { + public: + explicit GLES2ClientImpl(ScopedMessagePipeHandle pipe); + virtual ~GLES2ClientImpl(); + + private: + virtual void DidCreateContext(uint64_t encoded, + uint32_t width, + uint32_t height) MOJO_OVERRIDE; + virtual void ContextLost() MOJO_OVERRIDE; + + void Draw(); + + base::Time last_time_; + base::RepeatingTimer<GLES2ClientImpl> timer_; + SpinningCube cube_; + + RemotePtr<GLES2> service_; + + MOJO_DISALLOW_COPY_AND_ASSIGN(GLES2ClientImpl); +}; + +} // namespace examples +} // namespace mojo + +#endif // MOJO_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_ diff --git a/mojo/examples/sample_app/native_viewport_client_impl.cc b/mojo/examples/sample_app/native_viewport_client_impl.cc index 6f10990..5d70df1 100644 --- a/mojo/examples/sample_app/native_viewport_client_impl.cc +++ b/mojo/examples/sample_app/native_viewport_client_impl.cc @@ -6,8 +6,6 @@ #include <stdio.h> -#include "mojo/public/bindings/gles2_client/gles2_client_impl.h" - namespace mojo { namespace examples { @@ -27,7 +25,7 @@ void NativeViewportClientImpl::Open() { ScopedMessagePipeHandle gles2_client; CreateMessagePipe(&gles2, &gles2_client); - gles2_client_.reset(new GLES2ClientImpl(&gles2_delegate_, gles2.Pass())); + gles2_client_.reset(new GLES2ClientImpl(gles2.Pass())); service_->CreateGLES2Context(gles2_client.release()); } diff --git a/mojo/examples/sample_app/native_viewport_client_impl.h b/mojo/examples/sample_app/native_viewport_client_impl.h index d959c45..32beb6b 100644 --- a/mojo/examples/sample_app/native_viewport_client_impl.h +++ b/mojo/examples/sample_app/native_viewport_client_impl.h @@ -6,7 +6,7 @@ #define MOJO_EXAMPLES_SAMPLE_APP_NATIVE_VIEWPORT_CLIENT_IMPL_H_ #include "base/memory/scoped_ptr.h" -#include "mojo/examples/sample_app/sample_gles2_delegate.h" +#include "mojo/examples/sample_app/gles2_client_impl.h" #include "mojo/public/bindings/lib/remote_ptr.h" #include "mojom/native_viewport.h" @@ -23,10 +23,11 @@ class NativeViewportClientImpl : public NativeViewportClientStub { private: virtual void DidOpen() MOJO_OVERRIDE; - SampleGLES2Delegate gles2_delegate_; scoped_ptr<GLES2ClientImpl> gles2_client_; RemotePtr<NativeViewport> service_; + + MOJO_DISALLOW_COPY_AND_ASSIGN(NativeViewportClientImpl); }; } // namespace examples diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc index 1cf86c4..02d4ce2 100644 --- a/mojo/examples/sample_app/sample_app.cc +++ b/mojo/examples/sample_app/sample_app.cc @@ -8,8 +8,8 @@ #include "base/message_loop/message_loop.h" #include "mojo/common/bindings_support_impl.h" #include "mojo/examples/sample_app/native_viewport_client_impl.h" -#include "mojo/public/bindings/gles2_client/gles2_client_impl.h" #include "mojo/public/bindings/lib/bindings_support.h" +#include "mojo/public/gles2/gles2.h" #include "mojo/public/system/core.h" #include "mojo/public/system/macros.h" @@ -40,13 +40,13 @@ extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(MojoHandle pipe) { base::MessageLoop loop; mojo::common::BindingsSupportImpl bindings_support; mojo::BindingsSupport::Set(&bindings_support); - mojo::GLES2ClientImpl::Initialize(); + MojoGLES2Initialize(); mojo::ScopedMessagePipeHandle scoped_handle; scoped_handle.reset(mojo::MessagePipeHandle(pipe)); mojo::examples::Start(scoped_handle.Pass()); - mojo::GLES2ClientImpl::Terminate(); + MojoGLES2Terminate(); mojo::BindingsSupport::Set(NULL); return MOJO_RESULT_OK; } diff --git a/mojo/examples/sample_app/sample_gles2_delegate.cc b/mojo/examples/sample_app/sample_gles2_delegate.cc deleted file mode 100644 index 4bac022..0000000 --- a/mojo/examples/sample_app/sample_gles2_delegate.cc +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2013 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. - -#include "mojo/examples/sample_app/sample_gles2_delegate.h" - -#include <stdio.h> -#include <GLES2/gl2.h> -#include <GLES2/gl2ext.h> - -namespace mojo { -namespace examples { - -SampleGLES2Delegate::SampleGLES2Delegate() - : gl_(NULL) { -} - -SampleGLES2Delegate::~SampleGLES2Delegate() { -} - -void SampleGLES2Delegate::DidCreateContext( - GLES2ClientImpl* gl, uint32_t width, uint32_t height) { - gl_ = gl; - cube_.Init(width, height); - last_time_ = base::Time::Now(); - timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(16), - this, &SampleGLES2Delegate::Draw); -} - -void SampleGLES2Delegate::Draw() { - base::Time now = base::Time::Now(); - base::TimeDelta offset = now - last_time_; - last_time_ = now; - cube_.Update(offset.InSecondsF()); - cube_.Draw(); - gl_->SwapBuffers(); -} - -void SampleGLES2Delegate::ContextLost(GLES2ClientImpl* gl) { - gl_ = NULL; - timer_.Stop(); -} - -} // namespace examples -} // namespace mojo diff --git a/mojo/examples/sample_app/sample_gles2_delegate.h b/mojo/examples/sample_app/sample_gles2_delegate.h deleted file mode 100644 index efd4872..0000000 --- a/mojo/examples/sample_app/sample_gles2_delegate.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright 2013 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_EXAMPLES_SAMPLE_APP_SAMPLE_GLES2_DELEGATE_H_ -#define MOJO_EXAMPLES_SAMPLE_APP_SAMPLE_GLES2_DELEGATE_H_ - -#include "base/timer/timer.h" -#include "mojo/examples/sample_app/spinning_cube.h" -#include "mojo/public/bindings/gles2_client/gles2_client_impl.h" - -namespace mojo { -namespace examples { - -class SampleGLES2Delegate : public GLES2Delegate { - public: - SampleGLES2Delegate(); - virtual ~SampleGLES2Delegate(); - - private: - virtual void DidCreateContext( - GLES2ClientImpl* gl, uint32_t width, uint32_t height) MOJO_OVERRIDE; - virtual void ContextLost(GLES2ClientImpl* gl) MOJO_OVERRIDE; - - void Draw(); - - base::Time last_time_; - base::RepeatingTimer<SampleGLES2Delegate> timer_; - SpinningCube cube_; - GLES2ClientImpl* gl_; -}; - -} // namespace examples -} // namespace mojo - -#endif // MOJO_EXAMPLES_SAMPLE_APP_SAMPLE_GLES2_DELEGATE_H_ diff --git a/mojo/public/bindings/gles2_client/DEPS b/mojo/gles2/DEPS index 08992c3..08992c3 100644 --- a/mojo/public/bindings/gles2_client/DEPS +++ b/mojo/gles2/DEPS diff --git a/mojo/gles2/README.md b/mojo/gles2/README.md new file mode 100644 index 0000000..94b3997a5 --- /dev/null +++ b/mojo/gles2/README.md @@ -0,0 +1,5 @@ +Mojo GLES2 +========== + +We export this dynamically linked library via mojo/public/gles2 in order to +hide the gpu/command_buffer/client dependency from clients of the Mojo API. diff --git a/mojo/gles2/gles2.cc b/mojo/gles2/gles2.cc new file mode 100644 index 0000000..c90a331 --- /dev/null +++ b/mojo/gles2/gles2.cc @@ -0,0 +1,35 @@ +// Copyright 2013 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. + +#include "mojo/public/gles2/gles2.h" + +#include "gpu/command_buffer/client/gles2_lib.h" + +extern "C" { + +void MojoGLES2Initialize() { + gles2::Initialize(); +} + +void MojoGLES2Terminate() { + gles2::Terminate(); +} + +void MojoGLES2MakeCurrent(uint64_t encoded) { + // Ack, Hans! It's the giant hack. + // TODO(abarth): Replace this hack with something more disciplined. Most + // likley, we should receive a MojoHandle that we use to wire up the + // client side of an out-of-process command buffer. Given that we're + // still in-process, we just reinterpret_cast the value into a GL interface. + gpu::gles2::GLES2Interface* gl_interface = + reinterpret_cast<gpu::gles2::GLES2Interface*>( + static_cast<uintptr_t>(encoded)); + gles2::SetGLContext(gl_interface); +} + +void MojoGLES2SwapBuffers() { + gles2::GetGLContext()->SwapBuffers(); +} + +} // extern "C" diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp index df95f5e..128fcc4 100644 --- a/mojo/mojo.gyp +++ b/mojo/mojo.gyp @@ -17,7 +17,7 @@ 'target_name': 'mojo', 'type': 'none', 'dependencies': [ - 'hello_world_service_impl', + 'hello_world_service', 'mojo_bindings', 'mojo_bindings_unittests', 'mojo_common_lib', @@ -140,6 +140,19 @@ ], }, { + 'target_name': 'mojo_gles2', + 'type': '<(component)', + 'dependencies': [ + '../gpu/gpu.gyp:gles2_c_lib', + ], + 'defines': [ + 'MOJO_GLES2_IMPLEMENTATION', + ], + 'sources': [ + 'gles2/gles2.cc', + ], + }, + { 'target_name': 'mojo_common_lib', 'type': '<(component)', 'defines': [ @@ -207,7 +220,7 @@ '../url/url.gyp:url_lib', 'mojo_bindings', 'mojo_system', - 'native_viewport_impl', + 'mojo_native_viewport_service', ], 'sources': [ 'shell/app_container.cc', @@ -268,7 +281,7 @@ ['OS=="android"', { 'targets': [ { - 'target_name': 'native_viewport_java', + 'target_name': 'mojo_native_viewport_java', 'type': 'none', 'dependencies': [ '../base/base.gyp:base_java', @@ -331,7 +344,7 @@ 'dependencies': [ '../base/base.gyp:base_java', '../net/net.gyp:net_java', - 'native_viewport_java', + 'mojo_native_viewport_java', 'libmojo_shell', ], 'variables': { diff --git a/mojo/mojo_examples.gypi b/mojo/mojo_examples.gypi index 8c80e1c..08b8896 100644 --- a/mojo/mojo_examples.gypi +++ b/mojo/mojo_examples.gypi @@ -7,24 +7,24 @@ '../base/base.gyp:base', '../gpu/gpu.gyp:gles2_c_lib', '../ui/gl/gl.gyp:gl', - 'gles2', - 'gles2_client_impl', 'mojo_common_lib', + 'mojo_gles2', + 'mojo_gles2_bindings', + 'mojo_native_viewport_bindings', 'mojo_system', - 'native_viewport', ], 'sources': [ + 'examples/sample_app/gles2_client_impl.cc', + 'examples/sample_app/gles2_client_impl.cc', 'examples/sample_app/native_viewport_client_impl.cc', 'examples/sample_app/native_viewport_client_impl.h', 'examples/sample_app/sample_app.cc', - 'examples/sample_app/sample_gles2_delegate.cc', - 'examples/sample_app/sample_gles2_delegate.h', 'examples/sample_app/spinning_cube.cc', 'examples/sample_app/spinning_cube.h', ], }, { - 'target_name': 'hello_world_service', + 'target_name': 'hello_world_bindings', 'type': 'static_library', 'sources': [ 'examples/hello_world_service/hello_world_service.mojom', @@ -36,18 +36,18 @@ ], }, { - 'target_name': 'hello_world_service_impl', + 'target_name': 'hello_world_service', 'type': 'static_library', - 'sources': [ - 'examples/hello_world_service/hello_world_service_impl.cc', - 'examples/hello_world_service/hello_world_service_impl.h', + 'dependencies': [ + '../base/base.gyp:base', + 'hello_world_bindings', ], 'export_dependent_settings': [ - 'hello_world_service', + 'hello_world_bindings', ], - 'dependencies': [ - '../base/base.gyp:base', - 'hello_world_service', + 'sources': [ + 'examples/hello_world_service/hello_world_service_impl.cc', + 'examples/hello_world_service/hello_world_service_impl.h', ], }, ], diff --git a/mojo/mojo_public.gypi b/mojo/mojo_public.gypi index d916d10..01dd9a2 100644 --- a/mojo/mojo_public.gypi +++ b/mojo/mojo_public.gypi @@ -102,20 +102,5 @@ 'sample_service', ], }, - { - 'target_name': 'gles2_client_impl', - 'type': 'static_library', - 'dependencies': [ - '../gpu/gpu.gyp:gles2_c_lib', - 'gles2', - ], - 'export_dependent_settings': [ - 'gles2', - ], - 'sources': [ - 'public/bindings/gles2_client/gles2_client_impl.cc', - 'public/bindings/gles2_client/gles2_client_impl.h', - ], - }, ], } diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi index 0eea6d4..2942f6d 100644 --- a/mojo/mojo_services.gypi +++ b/mojo/mojo_services.gypi @@ -1,7 +1,7 @@ { 'targets': [ { - 'target_name': 'gles2', + 'target_name': 'mojo_gles2_bindings', 'type': 'static_library', 'sources': [ 'services/gles2/gles2.mojom', @@ -13,7 +13,7 @@ ], }, { - 'target_name': 'gles2_impl', + 'target_name': 'mojo_gles2_service', 'type': 'static_library', 'dependencies': [ '../base/base.gyp:base', @@ -21,10 +21,10 @@ '../gpu/gpu.gyp:gles2_implementation', '../ui/gfx/gfx.gyp:gfx', '../ui/gl/gl.gyp:gl', - 'gles2', + 'mojo_gles2_bindings', ], 'export_dependent_settings': [ - 'gles2', + 'mojo_gles2_bindings', ], 'sources': [ 'services/gles2/gles2_impl.cc', @@ -32,7 +32,7 @@ ], }, { - 'target_name': 'native_viewport', + 'target_name': 'mojo_native_viewport_bindings', 'type': 'static_library', 'sources': [ 'services/native_viewport/native_viewport.mojom', @@ -44,17 +44,17 @@ ], }, { - 'target_name': 'native_viewport_impl', + 'target_name': 'mojo_native_viewport_service', 'type': 'static_library', 'dependencies': [ '../base/base.gyp:base', '../ui/events/events.gyp:events', '../ui/gfx/gfx.gyp:gfx', - 'gles2_impl', - 'native_viewport', + 'mojo_gles2_service', + 'mojo_native_viewport_bindings', ], 'export_dependent_settings': [ - 'native_viewport', + 'mojo_native_viewport_bindings', ], 'sources': [ 'services/native_viewport/android/mojo_viewport.cc', diff --git a/mojo/public/README.md b/mojo/public/README.md new file mode 100644 index 0000000..08f9881 --- /dev/null +++ b/mojo/public/README.md @@ -0,0 +1,41 @@ +Mojo Public API +=============== + +The Mojo Public API is a binary stable API to the Mojo system. There are +several components to the API: + +Bindings +-------- + +This directory contains a static library that clients can link into their +binary. The contents of this directory are not binary stable because each +client is free to use whichever version they prefer. + +This directory also contains a compiler that translates mojom interface +definition files into idiomatic bindings for various languages, including +C++ and JavaScript. Clients are expected to statically link with the generated +code, which reads and writes the binary stable IPC message format. + +GLES2 +----- + +The IPC protocol used to communicate between Mojo client and the GLES2 +service is not binary stable. To insulate themselves from changes in this +protocol, clients are expected to link dynamically against the standard GLES2 +headers from Khronos and the headers in this directory, which provide an +adaptor between the GLES2 C API and the underlying IPC protocol. + +System +------ + +This directory defines the interface between Mojo clients and the Mojo IPC +system. Although the Mojo IPC message format is binary stable, the mechanism +by which these messages are transported is not stable. To insulate themselves +from changes in the underlying transport, clients are expected to link against +these headers dynamically. + +Tests +----- + +This directory contains tests for code contained in the public API. Mojo +clients are expected to ignore this directory. diff --git a/mojo/public/bindings/gles2_client/gles2_client_impl.cc b/mojo/public/bindings/gles2_client/gles2_client_impl.cc deleted file mode 100644 index 2fea93c..0000000 --- a/mojo/public/bindings/gles2_client/gles2_client_impl.cc +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2013 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. - -#include "mojo/public/bindings/gles2_client/gles2_client_impl.h" - -#include <assert.h> - -#include "gpu/command_buffer/client/gles2_lib.h" - -namespace mojo { -namespace { - -bool g_gles2_initialized = false; - -} // namespace - -GLES2Delegate::~GLES2Delegate() { -} - -void GLES2Delegate::DidCreateContext( - GLES2ClientImpl* gl, uint32_t width, uint32_t height) { -} - -void GLES2Delegate::ContextLost(GLES2ClientImpl* gl) { -} - -GLES2ClientImpl::GLES2ClientImpl(GLES2Delegate* delegate, - ScopedMessagePipeHandle gl) - : delegate_(delegate), - gl_(gl.Pass()) { - assert(g_gles2_initialized); - gl_.SetPeer(this); -} - -GLES2ClientImpl::~GLES2ClientImpl() { - gl_->Destroy(); -} - -void GLES2ClientImpl::Initialize() { - assert(!g_gles2_initialized); - gles2::Initialize(); - g_gles2_initialized = true; -} - -void GLES2ClientImpl::Terminate() { - assert(g_gles2_initialized); - gles2::Terminate(); - g_gles2_initialized = false; -} - -void GLES2ClientImpl::SwapBuffers() { - gles2::GetGLContext()->SwapBuffers(); -} - -void GLES2ClientImpl::DidCreateContext( - uint64_t encoded, uint32_t width, uint32_t height) { - // Ack, Hans! It's the giant hack. - // TODO(abarth): Replace this hack with something more disciplined. Most - // likley, we should receive a MojoHandle that we use to wire up the - // client side of an out-of-process command buffer. Given that we're - // still in-process, we just reinterpret_cast the value into a GL interface. - gpu::gles2::GLES2Interface* gl_interface = - reinterpret_cast<gpu::gles2::GLES2Interface*>( - static_cast<uintptr_t>(encoded)); - gles2::SetGLContext(gl_interface); - - delegate_->DidCreateContext(this, width, height); -} - -void GLES2ClientImpl::ContextLost() { - delegate_->ContextLost(this); -} - -} // mojo diff --git a/mojo/public/bindings/gles2_client/gles2_client_impl.h b/mojo/public/bindings/gles2_client/gles2_client_impl.h deleted file mode 100644 index 9213905..0000000 --- a/mojo/public/bindings/gles2_client/gles2_client_impl.h +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2013 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_BINDINGS_GLES2_CLIENT_GLES2_CLIENT_IMPL_H_ -#define MOJO_PUBLIC_BINDINGS_GLES2_CLIENT_GLES2_CLIENT_IMPL_H_ - -#include "mojo/public/bindings/lib/remote_ptr.h" -#include "mojom/gles2.h" - -namespace mojo { -class GLES2ClientImpl; - -class GLES2Delegate { - public: - virtual ~GLES2Delegate(); - virtual void DidCreateContext( - GLES2ClientImpl* gl, uint32_t width, uint32_t height); - virtual void ContextLost(GLES2ClientImpl* gl); -}; - -class GLES2ClientImpl : public GLES2ClientStub { - public: - explicit GLES2ClientImpl(GLES2Delegate* delegate, - ScopedMessagePipeHandle gl); - virtual ~GLES2ClientImpl(); - - static void Initialize(); - static void Terminate(); - - void SwapBuffers(); - - private: - virtual void DidCreateContext( - uint64_t encoded, uint32_t width, uint32_t height) MOJO_OVERRIDE; - virtual void ContextLost() MOJO_OVERRIDE; - - GLES2Delegate* delegate_; - RemotePtr<GLES2> gl_; -}; - -} // mojo - -#endif // MOJO_PUBLIC_BINDINGS_GLES2_CLIENT_GLES2_CLIENT_IMPL_H_ diff --git a/mojo/public/gles2/gles2.h b/mojo/public/gles2/gles2.h new file mode 100644 index 0000000..0a32cdd --- /dev/null +++ b/mojo/public/gles2/gles2.h @@ -0,0 +1,47 @@ +// Copyright 2013 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_GLES2_ADAPTOR_H_ +#define MOJO_PUBLIC_GLES2_ADAPTOR_H_ + +// Note: This header should be compilable as C. + +#include <stdint.h> + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(MOJO_GLES2_IMPLEMENTATION) +#define MOJO_GLES2_EXPORT __declspec(dllexport) +#else +#define MOJO_GLES2_EXPORT __declspec(dllimport) +#endif // defined(GFX_IMPLEMENTATION) + +#else // defined(WIN32) +#if defined(MOJO_GLES2_IMPLEMENTATION) +#define MOJO_GLES2_EXPORT __attribute__((visibility("default"))) +#else +#define MOJO_GLES2_EXPORT +#endif +#endif + +#else // defined(COMPONENT_BUILD) +#define MOJO_GLES2_EXPORT +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +MOJO_GLES2_EXPORT void MojoGLES2Initialize(); +MOJO_GLES2_EXPORT void MojoGLES2Terminate(); +// TODO(abarth): MojoGLES2MakeCurrent should take a MojoHandle. +MOJO_GLES2_EXPORT void MojoGLES2MakeCurrent(uint64_t encoded); +MOJO_GLES2_EXPORT void MojoGLES2SwapBuffers(); + +#ifdef __cplusplus +} // extern "C" +#endif + +#endif // MOJO_PUBLIC_GLES2_ADAPTOR_H_ |