Commit 99e508a4 authored by abarth@chromium.org's avatar abarth@chromium.org

[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
parent 6edd0608
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.
......@@ -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_
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",
]
......@@ -2,42 +2,47 @@
// 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 "mojo/examples/sample_app/gles2_client_impl.h"
#include <stdio.h>
#include <GLES2/gl2.h>
#include <GLES2/gl2ext.h>
#include "mojo/public/gles2/gles2.h"
namespace mojo {
namespace examples {
SampleGLES2Delegate::SampleGLES2Delegate()
: gl_(NULL) {
GLES2ClientImpl::GLES2ClientImpl(ScopedMessagePipeHandle pipe)
: service_(pipe.Pass()) {
service_.SetPeer(this);
}
SampleGLES2Delegate::~SampleGLES2Delegate() {
GLES2ClientImpl::~GLES2ClientImpl() {
service_->Destroy();
}
void SampleGLES2Delegate::DidCreateContext(
GLES2ClientImpl* gl, uint32_t width, uint32_t height) {
gl_ = gl;
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, &SampleGLES2Delegate::Draw);
this, &GLES2ClientImpl::Draw);
}
void SampleGLES2Delegate::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();
gl_->SwapBuffers();
MojoGLES2SwapBuffers();
}
void SampleGLES2Delegate::ContextLost(GLES2ClientImpl* gl) {
gl_ = NULL;
void GLES2ClientImpl::ContextLost() {
timer_.Stop();
}
......
......@@ -2,35 +2,40 @@
// 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_
#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/gles2_client/gles2_client_impl.h"
#include "mojo/public/bindings/lib/remote_ptr.h"
#include "mojom/gles2.h"
namespace mojo {
namespace examples {
class SampleGLES2Delegate : public GLES2Delegate {
class GLES2ClientImpl : public GLES2ClientStub {
public:
SampleGLES2Delegate();
virtual ~SampleGLES2Delegate();
explicit GLES2ClientImpl(ScopedMessagePipeHandle pipe);
virtual ~GLES2ClientImpl();
private:
virtual void DidCreateContext(
GLES2ClientImpl* gl, uint32_t width, uint32_t height) MOJO_OVERRIDE;
virtual void ContextLost(GLES2ClientImpl* gl) MOJO_OVERRIDE;
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<SampleGLES2Delegate> timer_;
base::RepeatingTimer<GLES2ClientImpl> timer_;
SpinningCube cube_;
GLES2ClientImpl* gl_;
RemotePtr<GLES2> service_;
MOJO_DISALLOW_COPY_AND_ASSIGN(GLES2ClientImpl);
};
} // namespace examples
} // namespace mojo
#endif // MOJO_EXAMPLES_SAMPLE_APP_SAMPLE_GLES2_DELEGATE_H_
#endif // MOJO_EXAMPLES_SAMPLE_APP_GLES2_CLIENT_IMPL_H_
......@@ -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());
}
......
......@@ -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
......
......@@ -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;
}
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.
......@@ -2,59 +2,21 @@
// 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 "mojo/public/gles2/gles2.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);
}
extern "C" {
GLES2ClientImpl::~GLES2ClientImpl() {
gl_->Destroy();
}
void GLES2ClientImpl::Initialize() {
assert(!g_gles2_initialized);
void MojoGLES2Initialize() {
gles2::Initialize();
g_gles2_initialized = true;
}
void GLES2ClientImpl::Terminate() {
assert(g_gles2_initialized);
void MojoGLES2Terminate() {
gles2::Terminate();
g_gles2_initialized = false;
}
void GLES2ClientImpl::SwapBuffers() {
gles2::GetGLContext()->SwapBuffers();
}
void GLES2ClientImpl::DidCreateContext(
uint64_t encoded, uint32_t width, uint32_t height) {
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
......@@ -64,12 +26,10 @@ void GLES2ClientImpl::DidCreateContext(
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);
void MojoGLES2SwapBuffers() {
gles2::GetGLContext()->SwapBuffers();
}
} // mojo
} // extern "C"
......@@ -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',
......@@ -139,6 +139,19 @@
'system/waiter_unittest.cc',
],
},
{
'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)',
......@@ -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': {
......
......@@ -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',
],
},
],
......
......@@ -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',
],
},
],
}
{
'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',
......
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.
// 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_
// 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_
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