Commit 412ffac7 authored by jamesr@chromium.org's avatar jamesr@chromium.org

Mojo surfaces service and example app

This provides an implementation of the mojo surfaces service and a
sample with two mojo applications composing each other via surfaces. The
viewport / display hookup is a bit of a hack in this patch as is the
complete lack of scheduling logic, but it's enough to get started.

Review URL: https://codereview.chromium.org/361123002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282856 0039d316-1c4b-4281-b951-d872f2087c98
parent 9b6ec202
...@@ -93,6 +93,10 @@ bool Display::Draw() { ...@@ -93,6 +93,10 @@ bool Display::Draw() {
TRACE_EVENT0("cc", "Display::Draw"); TRACE_EVENT0("cc", "Display::Draw");
DelegatedFrameData* frame_data = frame->delegated_frame_data.get(); DelegatedFrameData* frame_data = frame->delegated_frame_data.get();
// Only reshape when we know we are going to draw. Otherwise, the reshape
// can leave the window at the wrong size if we never draw and the proper
// viewport size is never set.
output_surface_->Reshape(current_surface_size_, 1.f);
float device_scale_factor = 1.0f; float device_scale_factor = 1.0f;
gfx::Rect device_viewport_rect = gfx::Rect(current_surface_size_); gfx::Rect device_viewport_rect = gfx::Rect(current_surface_size_);
gfx::Rect device_clip_rect = device_viewport_rect; gfx::Rect device_clip_rect = device_viewport_rect;
......
include_rules = [
"+cc",
"+ui/gfx",
"+gpu/command_buffer/client",
"+third_party/skia/include",
]
// 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.
import "mojo/services/public/interfaces/geometry/geometry.mojom"
import "mojo/services/public/interfaces/surfaces/quads.mojom"
import "mojo/services/public/interfaces/surfaces/surface_id.mojom"
interface Child {
ProduceFrame(mojo.surfaces.Color color, mojo.Size size) =>
(mojo.surfaces.SurfaceId id);
};
// 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.
#include "mojo/examples/surfaces_app/child_impl.h"
#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/bindings/string.h"
namespace mojo {
namespace examples {
class ChildApp : public ApplicationDelegate, public ChildImpl::Context {
public:
ChildApp() {}
virtual ~ChildApp() {}
virtual void Initialize(ApplicationImpl* app) OVERRIDE { app_ = app; }
// ApplicationDelegate implementation.
virtual bool ConfigureIncomingConnection(
ApplicationConnection* connection) OVERRIDE {
connection->AddService<ChildImpl, ChildImpl::Context>(this);
return true;
}
// ChildImpl::Context implementation.
virtual ApplicationConnection* ShellConnection(
const mojo::String& application_url) OVERRIDE {
return app_->ConnectToApplication(application_url);
}
private:
ApplicationImpl* app_;
DISALLOW_COPY_AND_ASSIGN(ChildApp);
};
} // namespace examples
// static
ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::ChildApp();
}
} // namespace mojo
// 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.
#include "mojo/examples/surfaces_app/child_impl.h"
#include "base/bind.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/delegated_frame_data.h"
#include "cc/quads/render_pass.h"
#include "cc/quads/solid_color_draw_quad.h"
#include "mojo/examples/surfaces_app/surfaces_util.h"
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h"
#include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h"
#include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/transform.h"
namespace mojo {
namespace examples {
using cc::RenderPass;
using cc::DrawQuad;
using cc::SolidColorDrawQuad;
using cc::DelegatedFrameData;
using cc::CompositorFrame;
class SurfaceClientImpl : public surfaces::SurfaceClient {
public:
explicit SurfaceClientImpl(ChildImpl* impl) : impl_(impl) {}
virtual ~SurfaceClientImpl() {}
// surfaces::SurfaceClient implementation
virtual void SetIdNamespace(uint32_t id_namespace) OVERRIDE {
impl_->SetIdNamespace(id_namespace);
}
virtual void ReturnResources(
Array<surfaces::ReturnedResourcePtr> resources) OVERRIDE {
DCHECK(!resources.size());
}
private:
ChildImpl* impl_;
};
ChildImpl::ChildImpl(ApplicationConnection* connection, Context* context)
: surface_client_(new SurfaceClientImpl(this)) {
context->ShellConnection("mojo:mojo_surfaces_service")
->ConnectToService(&surface_);
surface_.set_client(surface_client_.get());
}
ChildImpl::~ChildImpl() {
surface_->DestroySurface(mojo::surfaces::SurfaceId::From(id_));
}
void ChildImpl::ProduceFrame(
surfaces::ColorPtr color,
SizePtr size,
const mojo::Callback<void(surfaces::SurfaceIdPtr id)>& callback) {
color_ = color.To<SkColor>();
size_ = size.To<gfx::Size>();
produce_callback_ = callback;
if (allocator_)
Draw();
}
void ChildImpl::SetIdNamespace(uint32_t id_namespace) {
allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
if (!produce_callback_.is_null())
Draw();
}
void ChildImpl::Draw() {
id_ = allocator_->GenerateId();
surface_->CreateSurface(mojo::surfaces::SurfaceId::From(id_),
mojo::Size::From(size_));
gfx::Rect rect(size_);
RenderPass::Id id(1, 1);
scoped_ptr<RenderPass> pass = RenderPass::Create();
pass->SetNew(id, rect, rect, gfx::Transform());
CreateAndAppendSimpleSharedQuadState(pass.get(), gfx::Transform(), size_);
scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
bool force_anti_aliasing_off = false;
color_quad->SetNew(pass->shared_quad_state_list.back(),
rect,
rect,
color_,
force_anti_aliasing_off);
pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
delegated_frame_data->render_pass_list.push_back(pass.Pass());
scoped_ptr<CompositorFrame> frame(new CompositorFrame);
frame->delegated_frame_data = delegated_frame_data.Pass();
surface_->SubmitFrame(mojo::surfaces::SurfaceId::From(id_),
mojo::surfaces::Frame::From(*frame));
produce_callback_.Run(surfaces::SurfaceId::From(id_));
}
} // namespace examples
} // namespace mojo
// 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_EXAMPLES_SURFACES_APP_CHILD_IMPL_H_
#define MOJO_EXAMPLES_SURFACES_APP_CHILD_IMPL_H_
#include "base/memory/scoped_ptr.h"
#include "cc/surfaces/surface_id.h"
#include "cc/surfaces/surface_id_allocator.h"
#include "mojo/examples/surfaces_app/child.mojom.h"
#include "mojo/public/cpp/bindings/string.h"
#include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h"
#include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/size.h"
namespace cc {
class CompositorFrame;
}
namespace mojo {
class ApplicationConnection;
namespace surfaces {
class Surface;
}
namespace examples {
class SurfaceClientImpl;
// Simple example of a child app using surfaces.
class ChildImpl : public InterfaceImpl<Child> {
public:
class Context {
public:
virtual ApplicationConnection* ShellConnection(
const mojo::String& application_url) = 0;
};
ChildImpl(ApplicationConnection* connection, Context* context);
virtual ~ChildImpl();
void SetIdNamespace(uint32_t id_namespace);
private:
// Child implementation.
virtual void ProduceFrame(
surfaces::ColorPtr color,
SizePtr size,
const mojo::Callback<void(surfaces::SurfaceIdPtr id)>& callback) OVERRIDE;
void Draw();
SkColor color_;
gfx::Size size_;
scoped_ptr<cc::SurfaceIdAllocator> allocator_;
surfaces::SurfacePtr surface_;
cc::SurfaceId id_;
scoped_ptr<SurfaceClientImpl> surface_client_;
mojo::Callback<void(surfaces::SurfaceIdPtr id)> produce_callback_;
DISALLOW_COPY_AND_ASSIGN(ChildImpl);
};
} // namespace examples
} // namespace mojo
#endif // MOJO_EXAMPLES_SURFACES_APP_CHILD_IMPL_H_
// 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.
#include "mojo/examples/surfaces_app/embedder.h"
#include "cc/output/compositor_frame.h"
#include "cc/output/delegated_frame_data.h"
#include "cc/quads/render_pass.h"
#include "cc/quads/solid_color_draw_quad.h"
#include "cc/quads/surface_draw_quad.h"
#include "mojo/examples/surfaces_app/surfaces_util.h"
#include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h"
#include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "ui/gfx/transform.h"
namespace mojo {
namespace examples {
using cc::RenderPass;
using cc::SurfaceDrawQuad;
using cc::DrawQuad;
using cc::SolidColorDrawQuad;
using cc::DelegatedFrameData;
using cc::CompositorFrame;
Embedder::Embedder(surfaces::Surface* surface) : surface_(surface) {
}
Embedder::~Embedder() {
}
void Embedder::ProduceFrame(cc::SurfaceId child_one,
cc::SurfaceId child_two,
const gfx::Size& child_size,
const gfx::Size& size,
double rotation_degrees) {
gfx::Rect rect(size);
RenderPass::Id pass_id(1, 1);
scoped_ptr<RenderPass> pass = RenderPass::Create();
pass->SetNew(pass_id, rect, rect, gfx::Transform());
gfx::Transform one_transform;
one_transform.Translate(10 + child_size.width() / 2,
50 + child_size.height() / 2);
one_transform.Rotate(rotation_degrees);
one_transform.Translate(-child_size.width() / 2, -child_size.height() / 2);
CreateAndAppendSimpleSharedQuadState(pass.get(), one_transform, size);
scoped_ptr<SurfaceDrawQuad> surface_one_quad = SurfaceDrawQuad::Create();
gfx::Rect one_rect(child_size);
surface_one_quad->SetNew(
pass->shared_quad_state_list.back(), one_rect, one_rect, child_one);
pass->quad_list.push_back(surface_one_quad.PassAs<DrawQuad>());
gfx::Transform two_transform;
two_transform.Translate(10 + size.width() / 2 + child_size.width() / 2,
50 + child_size.height() / 2);
two_transform.Rotate(-rotation_degrees * 0.76);
two_transform.Translate(-child_size.width() / 2, -child_size.height() / 2);
CreateAndAppendSimpleSharedQuadState(pass.get(), two_transform, size);
scoped_ptr<SurfaceDrawQuad> surface_two_quad = SurfaceDrawQuad::Create();
gfx::Rect two_rect(child_size);
surface_two_quad->SetNew(
pass->shared_quad_state_list.back(), two_rect, two_rect, child_two);
pass->quad_list.push_back(surface_two_quad.PassAs<DrawQuad>());
CreateAndAppendSimpleSharedQuadState(pass.get(), gfx::Transform(), size);
scoped_ptr<SolidColorDrawQuad> color_quad = SolidColorDrawQuad::Create();
bool force_anti_aliasing_off = false;
color_quad->SetNew(pass->shared_quad_state_list.back(),
rect,
rect,
SK_ColorYELLOW,
force_anti_aliasing_off);
pass->quad_list.push_back(color_quad.PassAs<DrawQuad>());
scoped_ptr<DelegatedFrameData> delegated_frame_data(new DelegatedFrameData);
delegated_frame_data->render_pass_list.push_back(pass.Pass());
scoped_ptr<CompositorFrame> frame(new CompositorFrame);
frame->delegated_frame_data = delegated_frame_data.Pass();
surface_->SubmitFrame(mojo::surfaces::SurfaceId::From(id_),
mojo::surfaces::Frame::From(*frame));
}
} // namespace examples
} // namespace mojo
// 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_EXAMPLES_SURFACES_APP_EMBEDDER_H_
#define MOJO_EXAMPLES_SURFACES_APP_EMBEDDER_H_
#include "base/memory/scoped_ptr.h"
#include "cc/surfaces/surface_id.h"
#include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
#include "ui/gfx/size.h"
namespace cc {
class CompositorFrame;
}
namespace mojo {
class ApplicationConnection;
namespace examples {
// Simple example of a surface embedder that embeds two other surfaces.
class Embedder {
public:
explicit Embedder(surfaces::Surface* surface);
~Embedder();
void SetSurfaceId(cc::SurfaceId id) { id_ = id; }
void ProduceFrame(cc::SurfaceId child_one,
cc::SurfaceId child_two,
const gfx::Size& child_size,
const gfx::Size& size,
double rotation_degrees);
private:
cc::SurfaceId id_;
surfaces::Surface* surface_;
DISALLOW_COPY_AND_ASSIGN(Embedder);
};
} // namespace examples
} // namespace mojo
#endif // MOJO_EXAMPLES_SURFACES_APP_EMBEDDER_H_
// 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.
#include "base/bind.h"
#include "base/macros.h"
#include "base/message_loop/message_loop.h"
#include "cc/surfaces/surface_id_allocator.h"
#include "mojo/examples/surfaces_app/child.mojom.h"
#include "mojo/examples/surfaces_app/embedder.h"
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/public/cpp/system/core.h"
#include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
#include "mojo/services/gles2/command_buffer.mojom.h"
#include "mojo/services/public/cpp/geometry/geometry_type_converters.h"
#include "mojo/services/public/cpp/surfaces/surfaces_type_converters.h"
#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
#include "ui/gfx/rect.h"
namespace mojo {
namespace examples {
class SurfacesApp : public ApplicationDelegate,
public surfaces::SurfaceClient,
public NativeViewportClient {
public:
SurfacesApp() {}
virtual ~SurfacesApp() {}
// ApplicationDelegate implementation
virtual bool ConfigureIncomingConnection(
ApplicationConnection* connection) OVERRIDE {
connection->ConnectToService("mojo:mojo_native_viewport_service",
&viewport_);
viewport_.set_client(this);
connection->ConnectToService("mojo:mojo_surfaces_service", &surfaces_);
surfaces_.set_client(this);
size_ = gfx::Size(800, 600);
viewport_->Create(Rect::From(gfx::Rect(gfx::Point(10, 10), size_)));
viewport_->Show();
child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2);
connection->ConnectToService("mojo:mojo_surfaces_child_app", &child_one_);
connection->ConnectToService("mojo:mojo_surfaces_child_app", &child_two_);
child_one_->ProduceFrame(surfaces::Color::From(SK_ColorBLUE),
Size::From(child_size_),
base::Bind(&SurfacesApp::ChildOneProducedFrame,
base::Unretained(this)));
child_two_->ProduceFrame(surfaces::Color::From(SK_ColorGREEN),
Size::From(child_size_),
base::Bind(&SurfacesApp::ChildTwoProducedFrame,
base::Unretained(this)));
embedder_.reset(new Embedder(surfaces_.get()));
return true;
}
void ChildOneProducedFrame(surfaces::SurfaceIdPtr id) {
child_one_id_ = id.To<cc::SurfaceId>();
Draw(45.0);
}
void ChildTwoProducedFrame(surfaces::SurfaceIdPtr id) {
child_two_id_ = id.To<cc::SurfaceId>();
Draw(45.0);
}
void Draw(double rotation_degrees) {
if (onscreen_id_.is_null()) {
onscreen_id_ = allocator_->GenerateId();
CommandBufferPtr cb;
viewport_->CreateGLES2Context(Get(&cb));
surfaces_->CreateGLES2BoundSurface(
cb.Pass(),
surfaces::SurfaceId::From(onscreen_id_),
Size::From(size_));
embedder_->SetSurfaceId(onscreen_id_);
}
if (child_one_id_.is_null() || child_two_id_.is_null())
return;
embedder_->ProduceFrame(
child_one_id_, child_two_id_, child_size_, size_, rotation_degrees);
base::MessageLoop::current()->PostDelayedTask(
FROM_HERE,
base::Bind(
&SurfacesApp::Draw, base::Unretained(this), rotation_degrees + 2.0),
base::TimeDelta::FromMilliseconds(17));
}
// surfaces::SurfaceClient implementation.
virtual void SetIdNamespace(uint32_t id_namespace) OVERRIDE {
allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
Draw(45.0);
}
virtual void ReturnResources(
Array<surfaces::ReturnedResourcePtr> resources) OVERRIDE {
DCHECK(!resources.size());
}
// NativeViewportClient implementation
virtual void OnCreated() OVERRIDE {}
virtual void OnBoundsChanged(mojo::RectPtr bounds) OVERRIDE {}
virtual void OnDestroyed(const mojo::Callback<void()>& callback) OVERRIDE {
callback.Run();
}
virtual void OnEvent(mojo::EventPtr event,
const mojo::Callback<void()>& callback) OVERRIDE {
callback.Run();
}
private:
surfaces::SurfacePtr surfaces_;
cc::SurfaceId onscreen_id_;
scoped_ptr<cc::SurfaceIdAllocator> allocator_;
scoped_ptr<Embedder> embedder_;
ChildPtr child_one_;
cc::SurfaceId child_one_id_;
ChildPtr child_two_;
cc::SurfaceId child_two_id_;
gfx::Size size_;
gfx::Size child_size_;
NativeViewportPtr viewport_;
DISALLOW_COPY_AND_ASSIGN(SurfacesApp);
};
} // namespace examples
// static
ApplicationDelegate* ApplicationDelegate::Create() {
return new examples::SurfacesApp();
}
} // namespace mojo
// 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.
#include "mojo/examples/surfaces_app/surfaces_util.h"
#include "cc/quads/render_pass.h"
#include "cc/quads/shared_quad_state.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/size.h"
#include "ui/gfx/transform.h"
namespace mojo {
namespace examples {
using cc::SharedQuadState;
void CreateAndAppendSimpleSharedQuadState(cc::RenderPass* render_pass,
const gfx::Transform& transform,
const gfx::Size& size) {
const gfx::Size content_bounds = size;
const gfx::Rect visible_content_rect = gfx::Rect(size);
const gfx::Rect clip_rect = gfx::Rect(size);
bool is_clipped = false;
float opacity = 1.f;
const SkXfermode::Mode blend_mode = SkXfermode::kSrcOver_Mode;
SharedQuadState* shared_state = render_pass->CreateAndAppendSharedQuadState();
shared_state->SetAll(transform,
content_bounds,
visible_content_rect,
clip_rect,
is_clipped,
opacity,
blend_mode,
0);
}
} // namespace mojo
} // namespace examples
// 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_EXAMPLES_SURFACES_APP_SURFACES_UTIL_H_
#define MOJO_EXAMPLES_SURFACES_APP_SURFACES_UTIL_H_
namespace cc {
class RenderPass;
}
namespace gfx {
class Transform;
class Size;
}
namespace mojo {
namespace examples {
void CreateAndAppendSimpleSharedQuadState(cc::RenderPass* render_pass,
const gfx::Transform& transform,
const gfx::Size& size);
} // namespace mojo
} // namespace examples
#endif // MOJO_EXAMPLES_SURFACES_APP_SURFACES_UTIL_H_
...@@ -89,8 +89,12 @@ ...@@ -89,8 +89,12 @@
'mojo_shell', 'mojo_shell',
'mojo_shell_lib', 'mojo_shell_lib',
'mojo_shell_tests', 'mojo_shell_tests',
'mojo_surfaces_app',
'mojo_surfaces_child_app',
'mojo_surfaces_lib', 'mojo_surfaces_lib',
'mojo_surfaces_lib_unittests', 'mojo_surfaces_lib_unittests',
'mojo_surfaces_app',
'mojo_surfaces_service',
'mojo_system', 'mojo_system',
'mojo_system_impl', 'mojo_system_impl',
'mojo_system_unittests', 'mojo_system_unittests',
......
...@@ -267,6 +267,87 @@ ...@@ -267,6 +267,87 @@
'public/cpp/application/lib/mojo_main_chromium.cc', 'public/cpp/application/lib/mojo_main_chromium.cc',
], ],
}, },
{
'target_name': 'mojo_surfaces_app',
'type': 'shared_library',
'dependencies': [
'../base/base.gyp:base',
'../cc/cc.gyp:cc',
'../cc/cc.gyp:cc_surfaces',
'../skia/skia.gyp:skia',
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
'mojo_application',
'mojo_common_lib',
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_geometry_lib',
'mojo_gles2',
'mojo_native_viewport_bindings',
'mojo_surfaces_bindings',
'mojo_surfaces_app_bindings',
'mojo_surfaces_lib',
'mojo_system_impl',
],
'sources': [
'examples/surfaces_app/embedder.cc',
'examples/surfaces_app/embedder.h',
'examples/surfaces_app/surfaces_app.cc',
'examples/surfaces_app/surfaces_util.cc',
'examples/surfaces_app/surfaces_util.h',
'public/cpp/application/lib/mojo_main_chromium.cc',
],
},
{
'target_name': 'mojo_surfaces_app_bindings',
'type': 'static_library',
'sources': [
'examples/surfaces_app/child.mojom',
],
'includes': [ 'public/tools/bindings/mojom_bindings_generator.gypi' ],
'export_dependent_settings': [
'mojo_cpp_bindings',
],
'dependencies': [
'mojo_cpp_bindings',
],
},
{
'target_name': 'package_mojo_surfaces_app',
'variables': {
'app_name': 'mojo_surfaces_app',
},
'includes': [ 'build/package_app.gypi' ],
},
{
'target_name': 'mojo_surfaces_child_app',
'type': 'shared_library',
'dependencies': [
'../base/base.gyp:base',
'../cc/cc.gyp:cc',
'../cc/cc.gyp:cc_surfaces',
'../skia/skia.gyp:skia',
'../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry',
'mojo_application',
'mojo_common_lib',
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_geometry_lib',
'mojo_surfaces_app_bindings',
'mojo_surfaces_bindings',
'mojo_surfaces_lib',
'mojo_system_impl',
],
'sources': [
'examples/surfaces_app/child_app.cc',
'examples/surfaces_app/child_impl.cc',
'examples/surfaces_app/child_impl.h',
'examples/surfaces_app/surfaces_util.cc',
'examples/surfaces_app/surfaces_util.h',
'public/cpp/application/lib/mojo_main_chromium.cc',
],
},
], ],
'conditions': [ 'conditions': [
['use_aura==1', { ['use_aura==1', {
......
...@@ -133,6 +133,7 @@ ...@@ -133,6 +133,7 @@
'../ui/gfx/gfx.gyp:gfx', '../ui/gfx/gfx.gyp:gfx',
'../ui/gfx/gfx.gyp:gfx_geometry', '../ui/gfx/gfx.gyp:gfx_geometry',
'../ui/gfx/gfx.gyp:gfx_test_support', '../ui/gfx/gfx.gyp:gfx_test_support',
'mojo_environment_chromium',
'mojo_geometry_lib', 'mojo_geometry_lib',
'mojo_run_all_unittests', 'mojo_run_all_unittests',
'mojo_surfaces_bindings', 'mojo_surfaces_bindings',
...@@ -337,6 +338,32 @@ ...@@ -337,6 +338,32 @@
'services/network/url_loader_impl.h', 'services/network/url_loader_impl.h',
], ],
}, },
{
'target_name': 'mojo_surfaces_service',
'type': 'shared_library',
'dependencies': [
'../base/base.gyp:base',
'../cc/cc.gyp:cc',
'../cc/cc.gyp:cc_surfaces',
'../ui/gfx/gfx.gyp:gfx_geometry',
'mojo_application',
'mojo_cc_support',
'mojo_environment_chromium',
'mojo_geometry_bindings',
'mojo_geometry_lib',
'mojo_gles2',
'mojo_surfaces_bindings',
'mojo_surfaces_lib',
'mojo_system_impl',
],
'sources': [
'services/surfaces/surfaces_impl.cc',
'services/surfaces/surfaces_impl.h',
'services/surfaces/surfaces_service_application.cc',
'services/surfaces/surfaces_service_application.h',
'public/cpp/application/lib/mojo_main_chromium.cc',
],
},
{ {
'target_name': 'mojo_view_manager_common', 'target_name': 'mojo_view_manager_common',
'type': 'static_library', 'type': 'static_library',
...@@ -480,6 +507,7 @@ ...@@ -480,6 +507,7 @@
'dependencies': [ 'dependencies': [
'mojo_cpp_bindings', 'mojo_cpp_bindings',
'mojo_geometry_bindings', 'mojo_geometry_bindings',
'mojo_native_viewport_bindings',
], ],
}, },
{ {
......
...@@ -3,6 +3,7 @@ ...@@ -3,6 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import "mojo/services/public/interfaces/geometry/geometry.mojom" import "mojo/services/public/interfaces/geometry/geometry.mojom"
import "mojo/services/gles2/command_buffer.mojom"
import "mojo/services/public/interfaces/surfaces/quads.mojom" import "mojo/services/public/interfaces/surfaces/quads.mojom"
import "mojo/services/public/interfaces/surfaces/surface_id.mojom" import "mojo/services/public/interfaces/surfaces/surface_id.mojom"
...@@ -50,14 +51,19 @@ struct Frame { ...@@ -50,14 +51,19 @@ struct Frame {
}; };
interface SurfaceClient { interface SurfaceClient {
SetIdNamespace(uint32 id);
ReturnResources(ReturnedResource[] resources); ReturnResources(ReturnedResource[] resources);
}; };
[Client=SurfaceClient] [Client=SurfaceClient]
interface Surface { interface Surface {
CreateSurface(mojo.Size size) => (SurfaceId id); CreateSurface(SurfaceId id, mojo.Size size);
SubmitFrame(SurfaceId id, Frame frame); SubmitFrame(SurfaceId id, Frame frame);
DestroySurface(SurfaceId id); DestroySurface(SurfaceId id);
CreateGLES2BoundSurface(mojo.CommandBuffer gles2_client,
SurfaceId id,
mojo.Size size);
}; };
} }
include_rules = [
"+cc",
"+mojo/cc",
"+mojo/services/gles2",
"+mojo/services/public",
]
// 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.
#include "mojo/services/surfaces/surfaces_impl.h"
#include "cc/output/compositor_frame.h"
#include "cc/resources/returned_resource.h"
#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"
namespace mojo {
namespace surfaces {
SurfacesImpl::SurfacesImpl(ApplicationConnection* app, Context* context)
: context_(context),
factory_(context_->Manager(), this),
id_namespace_(context->IdNamespace()) {
}
SurfacesImpl::~SurfacesImpl() {
}
void SurfacesImpl::OnConnectionEstablished() {
client()->SetIdNamespace(id_namespace_);
}
void SurfacesImpl::CreateSurface(SurfaceIdPtr id, mojo::SizePtr size) {
cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
// Bad message, do something bad to the caller?
NOTREACHED();
return;
}
factory_.Create(id.To<cc::SurfaceId>(), size.To<gfx::Size>());
}
void SurfacesImpl::SubmitFrame(SurfaceIdPtr id, FramePtr frame_ptr) {
cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
// Bad message, do something bad to the caller?
NOTREACHED();
return;
}
factory_.SubmitFrame(id.To<cc::SurfaceId>(), mojo::ConvertTo(frame_ptr));
context_->FrameSubmitted();
}
void SurfacesImpl::DestroySurface(SurfaceIdPtr id) {
cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
// Bad message, do something bad to the caller?
NOTREACHED();
return;
}
factory_.Destroy(id.To<cc::SurfaceId>());
}
void SurfacesImpl::CreateGLES2BoundSurface(CommandBufferPtr gles2_client,
SurfaceIdPtr id,
mojo::SizePtr size) {
command_buffer_handle_ = gles2_client.PassMessagePipe();
cc::SurfaceId cc_id = id.To<cc::SurfaceId>();
if (cc::SurfaceIdAllocator::NamespaceForId(cc_id) != id_namespace_) {
// Bad message, do something bad to the caller?
NOTREACHED();
return;
}
if (!display_) {
display_.reset(new cc::Display(this, context_->Manager(), NULL));
context_->SetDisplay(display_.get());
}
factory_.Create(cc_id, size.To<gfx::Size>());
display_->Resize(cc_id, size.To<gfx::Size>());
}
void SurfacesImpl::ReturnResources(const cc::ReturnedResourceArray& resources) {
Array<ReturnedResourcePtr> ret(resources.size());
for (size_t i = 0; i < resources.size(); ++i) {
ret[i] = ReturnedResource::From(resources[i]);
}
client()->ReturnResources(ret.Pass());
}
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())));
}
} // namespace surfaces
} // namespace mojo
// 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_SERVICES_SURFACES_SURFACES_IMPL_H_
#define MOJO_SERVICES_SURFACES_SURFACES_IMPL_H_
#include "base/compiler_specific.h"
#include "cc/surfaces/display_client.h"
#include "cc/surfaces/surface_factory.h"
#include "cc/surfaces/surface_factory_client.h"
#include "mojo/public/cpp/application/application_connection.h"
#include "mojo/services/gles2/command_buffer.mojom.h"
#include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
namespace cc {
class Display;
}
namespace mojo {
class ServiceManager;
namespace surfaces {
class SurfaceNativeViewportClient;
class SurfacesImpl : public InterfaceImpl<Surface>,
public cc::SurfaceFactoryClient,
public cc::DisplayClient {
public:
class Context {
public:
virtual cc::SurfaceManager* Manager() = 0;
virtual uint32_t IdNamespace() = 0;
virtual void FrameSubmitted() = 0;
virtual void SetDisplay(cc::Display*) = 0;
};
SurfacesImpl(ApplicationConnection* app, Context* context);
virtual ~SurfacesImpl();
// InterfaceImpl<Surface> implementation.
virtual void OnConnectionEstablished() OVERRIDE;
// Surface implementation.
virtual void CreateSurface(SurfaceIdPtr id, mojo::SizePtr size) OVERRIDE;
virtual void SubmitFrame(SurfaceIdPtr id, FramePtr frame) OVERRIDE;
virtual void DestroySurface(SurfaceIdPtr id) OVERRIDE;
virtual void CreateGLES2BoundSurface(CommandBufferPtr gles2_client,
SurfaceIdPtr id,
mojo::SizePtr size) OVERRIDE;
// SurfaceFactoryClient implementation.
virtual void ReturnResources(
const cc::ReturnedResourceArray& resources) OVERRIDE;
// DisplayClient implementation.
virtual scoped_ptr<cc::OutputSurface> CreateOutputSurface() OVERRIDE;
cc::SurfaceFactory* factory() { return &factory_; }
private:
Context* context_;
cc::SurfaceFactory factory_;
uint32_t id_namespace_;
scoped_ptr<cc::Display> display_;
ScopedMessagePipeHandle command_buffer_handle_;
DISALLOW_COPY_AND_ASSIGN(SurfacesImpl);
};
} // namespace surfaces
} // namespace mojo
#endif // MOJO_SERVICES_SURFACES_SURFACES_IMPL_H_
// 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.
#include "mojo/services/surfaces/surfaces_service_application.h"
#include "cc/surfaces/display.h"
namespace mojo {
namespace surfaces {
SurfacesServiceApplication::SurfacesServiceApplication()
: next_id_namespace_(1u), display_(NULL) {
}
SurfacesServiceApplication::~SurfacesServiceApplication() {
}
bool SurfacesServiceApplication::ConfigureIncomingConnection(
ApplicationConnection* connection) {
connection->AddService<SurfacesImpl, SurfacesImpl::Context>(this);
return true;
}
cc::SurfaceManager* SurfacesServiceApplication::Manager() {
return &manager_;
}
uint32_t SurfacesServiceApplication::IdNamespace() {
return next_id_namespace_++;
}
void SurfacesServiceApplication::FrameSubmitted() {
if (display_)
display_->Draw();
}
void SurfacesServiceApplication::SetDisplay(cc::Display* display) {
display_ = display;
}
} // namespace surfaces
// static
ApplicationDelegate* ApplicationDelegate::Create() {
return new surfaces::SurfacesServiceApplication;
}
} // namespace mojo
// 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_SERVICES_SURFACES_SURFACES_SERVICE_APPLICATION_H_
#define MOJO_SERVICES_SURFACES_SURFACES_SERVICE_APPLICATION_H_
#include "base/macros.h"
#include "cc/surfaces/surface_manager.h"
#include "mojo/public/cpp/application/application_delegate.h"
#include "mojo/services/surfaces/surfaces_impl.h"
namespace mojo {
class ApplicationConnection;
namespace surfaces {
class SurfacesServiceApplication : public ApplicationDelegate,
public SurfacesImpl::Context {
public:
SurfacesServiceApplication();
virtual ~SurfacesServiceApplication();
// ApplicationDelegate implementation.
virtual bool ConfigureIncomingConnection(
ApplicationConnection* connection) OVERRIDE;
// SurfacesImpl::Context implementation.
virtual cc::SurfaceManager* Manager() OVERRIDE;
virtual uint32_t IdNamespace() OVERRIDE;
virtual void FrameSubmitted() OVERRIDE;
virtual void SetDisplay(cc::Display*) OVERRIDE;
private:
cc::SurfaceManager manager_;
uint32_t next_id_namespace_;
cc::Display* display_;
DISALLOW_COPY_AND_ASSIGN(SurfacesServiceApplication);
};
} // namespace surfaces
} // namespace mojo
#endif // MOJO_SERVICES_SURFACES_SURFACES_SERVICE_APPLICATION_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