| Index: mojo/examples/surfaces_app/surfaces_app.cc
|
| diff --git a/mojo/examples/surfaces_app/surfaces_app.cc b/mojo/examples/surfaces_app/surfaces_app.cc
|
| index d5f46848e464c02733e5a1bf83549fc2659d11d7..6b7a9e94194a6675d672f2343c67698a8e6c3a92 100644
|
| --- a/mojo/examples/surfaces_app/surfaces_app.cc
|
| +++ b/mojo/examples/surfaces_app/surfaces_app.cc
|
| @@ -14,7 +14,6 @@
|
| #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/gpu/gpu.mojom.h"
|
| #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
|
| #include "ui/gfx/rect.h"
|
|
|
| @@ -25,7 +24,7 @@
|
| public SurfaceClient,
|
| public NativeViewportClient {
|
| public:
|
| - SurfacesApp() : native_viewport_id_(0) {}
|
| + SurfacesApp() {}
|
| virtual ~SurfacesApp() {}
|
|
|
| // ApplicationDelegate implementation
|
| @@ -34,10 +33,6 @@
|
| connection->ConnectToService("mojo:mojo_native_viewport_service",
|
| &viewport_);
|
| viewport_.set_client(this);
|
| -
|
| - // TODO(jamesr): Should be mojo:mojo_gpu_service
|
| - connection->ConnectToService("mojo:mojo_native_viewport_service",
|
| - &gpu_service_);
|
|
|
| connection->ConnectToService("mojo:mojo_surfaces_service", &surfaces_);
|
| surfaces_.set_client(this);
|
| @@ -49,8 +44,7 @@
|
|
|
| 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_gl_app",
|
| - &child_two_);
|
| + connection->ConnectToService("mojo:mojo_surfaces_child_app", &child_two_);
|
| child_one_->ProduceFrame(Color::From(SK_ColorBLUE),
|
| Size::From(child_size_),
|
| base::Bind(&SurfacesApp::ChildOneProducedFrame,
|
| @@ -65,34 +59,40 @@
|
|
|
| void ChildOneProducedFrame(SurfaceIdPtr id) {
|
| child_one_id_ = id.To<cc::SurfaceId>();
|
| - Draw(10);
|
| + Draw(45.0);
|
| }
|
|
|
| void ChildTwoProducedFrame(SurfaceIdPtr id) {
|
| child_two_id_ = id.To<cc::SurfaceId>();
|
| - Draw(10);
|
| + Draw(45.0);
|
| }
|
|
|
| - void Draw(int offset) {
|
| - if (onscreen_id_.is_null() || child_one_id_.is_null() ||
|
| - child_two_id_.is_null())
|
| + void Draw(double rotation_degrees) {
|
| + if (onscreen_id_.is_null()) {
|
| + onscreen_id_ = allocator_->GenerateId();
|
| + CommandBufferPtr cb;
|
| + viewport_->CreateGLES2Context(Get(&cb));
|
| + surfaces_->CreateGLES2BoundSurface(
|
| + cb.Pass(),
|
| + SurfaceId::From(onscreen_id_),
|
| + Size::From(size_));
|
| + embedder_->SetSurfaceId(onscreen_id_);
|
| + }
|
| + if (child_one_id_.is_null() || child_two_id_.is_null())
|
| return;
|
| - int bounced_offset = offset;
|
| - if (offset > 200)
|
| - bounced_offset = 400 - offset;
|
| embedder_->ProduceFrame(
|
| - child_one_id_, child_two_id_, child_size_, size_, bounced_offset);
|
| + child_one_id_, child_two_id_, child_size_, size_, rotation_degrees);
|
| base::MessageLoop::current()->PostDelayedTask(
|
| FROM_HERE,
|
| base::Bind(
|
| - &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400),
|
| - base::TimeDelta::FromMilliseconds(50));
|
| + &SurfacesApp::Draw, base::Unretained(this), rotation_degrees + 2.0),
|
| + base::TimeDelta::FromMilliseconds(17));
|
| }
|
|
|
| // SurfaceClient implementation.
|
| virtual void SetIdNamespace(uint32_t id_namespace) OVERRIDE {
|
| allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
|
| - CreateSurfaceIfReady();
|
| + Draw(45.0);
|
| }
|
| virtual void ReturnResources(
|
| Array<ReturnedResourcePtr> resources) OVERRIDE {
|
| @@ -100,34 +100,11 @@
|
| }
|
|
|
| // NativeViewportClient implementation
|
| - virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE {
|
| - native_viewport_id_ = native_viewport_id;
|
| - CreateSurfaceIfReady();
|
| + virtual void OnCreated() OVERRIDE {}
|
| + virtual void OnBoundsChanged(mojo::RectPtr bounds) OVERRIDE {}
|
| + virtual void OnDestroyed(const mojo::Callback<void()>& callback) OVERRIDE {
|
| + callback.Run();
|
| }
|
| -
|
| - // We can't create our GLES2-bound surface until we have our id namespace from
|
| - // the surfaces service and our native viewport id from the native viewport
|
| - // service. There's no way of knowing which we'll get first, so we just start
|
| - // whenever both arrive.
|
| - void CreateSurfaceIfReady() {
|
| - if (!onscreen_id_.is_null())
|
| - return;
|
| - if (native_viewport_id_ == 0)
|
| - return;
|
| - if (!allocator_)
|
| - return;
|
| -
|
| - onscreen_id_ = allocator_->GenerateId();
|
| - embedder_->SetSurfaceId(onscreen_id_);
|
| - CommandBufferPtr cb;
|
| - gpu_service_->CreateOnscreenGLES2Context(
|
| - native_viewport_id_, Size::From(size_), Get(&cb));
|
| - surfaces_->CreateGLES2BoundSurface(
|
| - cb.Pass(), SurfaceId::From(onscreen_id_), Size::From(size_));
|
| - Draw(10);
|
| - }
|
| - virtual void OnBoundsChanged(mojo::RectPtr bounds) OVERRIDE {}
|
| - virtual void OnDestroyed() OVERRIDE {}
|
| virtual void OnEvent(mojo::EventPtr event,
|
| const mojo::Callback<void()>& callback) OVERRIDE {
|
| callback.Run();
|
| @@ -136,7 +113,6 @@
|
| private:
|
| SurfacePtr surfaces_;
|
| cc::SurfaceId onscreen_id_;
|
| - uint64_t native_viewport_id_;
|
| scoped_ptr<cc::SurfaceIdAllocator> allocator_;
|
| scoped_ptr<Embedder> embedder_;
|
| ChildPtr child_one_;
|
| @@ -147,7 +123,6 @@
|
| gfx::Size child_size_;
|
|
|
| NativeViewportPtr viewport_;
|
| - GpuPtr gpu_service_;
|
|
|
| DISALLOW_COPY_AND_ASSIGN(SurfacesApp);
|
| };
|
|
|