| Index: mojo/examples/compositor_app/compositor_app.cc
|
| diff --git a/mojo/examples/compositor_app/compositor_app.cc b/mojo/examples/compositor_app/compositor_app.cc
|
| index 0a7607bd2d62d521d91e4335d83067afd487dd57..2bbd97cd09813f56bbb5d235949dcc11778cc0cc 100644
|
| --- a/mojo/examples/compositor_app/compositor_app.cc
|
| +++ b/mojo/examples/compositor_app/compositor_app.cc
|
| @@ -5,7 +5,9 @@
|
| #include <stdio.h>
|
| #include <string>
|
|
|
| +#include "base/bind.h"
|
| #include "base/macros.h"
|
| +#include "base/memory/weak_ptr.h"
|
| #include "mojo/application/application_runner_chromium.h"
|
| #include "mojo/examples/compositor_app/compositor_host.h"
|
| #include "mojo/public/c/system/main.h"
|
| @@ -22,32 +24,26 @@ namespace examples {
|
|
|
| class SampleApp : public ApplicationDelegate, public NativeViewportClient {
|
| public:
|
| - SampleApp() {}
|
| + SampleApp() : weak_factory_(this) {}
|
| virtual ~SampleApp() {}
|
|
|
| virtual void Initialize(ApplicationImpl* app) OVERRIDE {
|
| app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_);
|
| viewport_.set_client(this);
|
| - viewport_->Create(Size::From(gfx::Size(800, 600)));
|
| + viewport_->Create(Size::From(gfx::Size(800, 600)),
|
| + base::Bind(&SampleApp::OnCreatedNativeViewport,
|
| + weak_factory_.GetWeakPtr()));
|
| viewport_->Show();
|
|
|
| // TODO(jamesr): Should be mojo:mojo_gpu_service
|
| app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_);
|
| }
|
|
|
| - virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE {
|
| - CommandBufferPtr cb;
|
| - // TODO(jamesr): Output to a surface instead.
|
| - gpu_service_->CreateOnscreenGLES2Context(
|
| - native_viewport_id, Size::From(gfx::Size(800, 600)), Get(&cb));
|
| - host_.reset(new CompositorHost(cb.PassMessagePipe()));
|
| - }
|
| -
|
| virtual void OnDestroyed() OVERRIDE { base::MessageLoop::current()->Quit(); }
|
|
|
| - virtual void OnBoundsChanged(SizePtr bounds) OVERRIDE {
|
| + virtual void OnSizeChanged(SizePtr size) OVERRIDE {
|
| if (host_)
|
| - host_->SetSize(bounds.To<gfx::Size>());
|
| + host_->SetSize(size.To<gfx::Size>());
|
| }
|
|
|
| virtual void OnEvent(EventPtr event,
|
| @@ -56,9 +52,20 @@ class SampleApp : public ApplicationDelegate, public NativeViewportClient {
|
| }
|
|
|
| private:
|
| + void OnCreatedNativeViewport(uint64_t native_viewport_id) {
|
| + CommandBufferPtr cb;
|
| + // TODO(jamesr): Output to a surface instead.
|
| + gpu_service_->CreateOnscreenGLES2Context(
|
| + native_viewport_id, Size::From(gfx::Size(800, 600)), Get(&cb));
|
| + host_.reset(new CompositorHost(cb.PassMessagePipe()));
|
| + }
|
| +
|
| +
|
| NativeViewportPtr viewport_;
|
| GpuPtr gpu_service_;
|
| scoped_ptr<CompositorHost> host_;
|
| + base::WeakPtrFactory<SampleApp> weak_factory_;
|
| +
|
| DISALLOW_COPY_AND_ASSIGN(SampleApp);
|
| };
|
|
|
|
|