| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdio.h> | 5 #include <stdio.h> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "mojo/examples/compositor_app/compositor_host.h" | 9 #include "mojo/examples/compositor_app/compositor_host.h" |
| 10 #include "mojo/public/cpp/application/application.h" | 10 #include "mojo/public/cpp/application/application.h" |
| 11 #include "mojo/public/cpp/bindings/allocation_scope.h" | |
| 12 #include "mojo/public/cpp/gles2/gles2.h" | 11 #include "mojo/public/cpp/gles2/gles2.h" |
| 13 #include "mojo/public/cpp/system/core.h" | 12 #include "mojo/public/cpp/system/core.h" |
| 14 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" | 13 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" |
| 15 #include "mojo/services/native_viewport/native_viewport.mojom.h" | 14 #include "mojo/services/native_viewport/native_viewport.mojom.h" |
| 16 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 15 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
| 17 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 18 | 17 |
| 19 namespace mojo { | 18 namespace mojo { |
| 20 namespace examples { | 19 namespace examples { |
| 21 | 20 |
| 22 class SampleApp : public Application, public NativeViewportClient { | 21 class SampleApp : public Application, public NativeViewportClient { |
| 23 public: | 22 public: |
| 24 SampleApp() {} | 23 SampleApp() {} |
| 25 virtual ~SampleApp() {} | 24 virtual ~SampleApp() {} |
| 26 | 25 |
| 27 virtual void Initialize() OVERRIDE { | 26 virtual void Initialize() OVERRIDE { |
| 28 AllocationScope scope; | |
| 29 | |
| 30 ConnectTo("mojo:mojo_native_viewport_service", &viewport_); | 27 ConnectTo("mojo:mojo_native_viewport_service", &viewport_); |
| 31 viewport_.set_client(this); | 28 viewport_.set_client(this); |
| 32 | 29 |
| 33 viewport_->Create(gfx::Rect(10, 10, 800, 600)); | 30 viewport_->Create(Rect::From(gfx::Rect(10, 10, 800, 600))); |
| 34 viewport_->Show(); | 31 viewport_->Show(); |
| 35 | 32 |
| 36 MessagePipe gles2_pipe; | 33 MessagePipe gles2_pipe; |
| 37 viewport_->CreateGLES2Context(gles2_pipe.handle0.Pass()); | 34 viewport_->CreateGLES2Context(gles2_pipe.handle0.Pass()); |
| 38 host_.reset(new CompositorHost(gles2_pipe.handle1.Pass())); | 35 host_.reset(new CompositorHost(gles2_pipe.handle1.Pass())); |
| 39 } | 36 } |
| 40 | 37 |
| 41 virtual void OnCreated() OVERRIDE { | 38 virtual void OnCreated() OVERRIDE { |
| 42 } | 39 } |
| 43 | 40 |
| 44 virtual void OnDestroyed() OVERRIDE { | 41 virtual void OnDestroyed() OVERRIDE { |
| 45 base::MessageLoop::current()->Quit(); | 42 base::MessageLoop::current()->Quit(); |
| 46 } | 43 } |
| 47 | 44 |
| 48 virtual void OnBoundsChanged(const Rect& bounds) OVERRIDE { | 45 virtual void OnBoundsChanged(RectPtr bounds) OVERRIDE { |
| 49 AllocationScope scope; | 46 host_->SetSize(gfx::Size(bounds->width, bounds->height)); |
| 50 Size::Builder size; | |
| 51 size.set_width(bounds.width()); | |
| 52 size.set_height(bounds.height()); | |
| 53 host_->SetSize(size.Finish()); | |
| 54 } | 47 } |
| 55 | 48 |
| 56 virtual void OnEvent(const Event& event, | 49 virtual void OnEvent(EventPtr event, |
| 57 const mojo::Callback<void()>& callback) OVERRIDE { | 50 const mojo::Callback<void()>& callback) OVERRIDE { |
| 58 callback.Run(); | 51 callback.Run(); |
| 59 } | 52 } |
| 60 | 53 |
| 61 private: | 54 private: |
| 62 mojo::GLES2Initializer gles2; | 55 mojo::GLES2Initializer gles2; |
| 63 NativeViewportPtr viewport_; | 56 NativeViewportPtr viewport_; |
| 64 scoped_ptr<CompositorHost> host_; | 57 scoped_ptr<CompositorHost> host_; |
| 65 DISALLOW_COPY_AND_ASSIGN(SampleApp); | 58 DISALLOW_COPY_AND_ASSIGN(SampleApp); |
| 66 }; | 59 }; |
| 67 | 60 |
| 68 } // namespace examples | 61 } // namespace examples |
| 69 | 62 |
| 70 // static | 63 // static |
| 71 Application* Application::Create() { | 64 Application* Application::Create() { |
| 72 return new examples::SampleApp(); | 65 return new examples::SampleApp(); |
| 73 } | 66 } |
| 74 | 67 |
| 75 } // namespace mojo | 68 } // namespace mojo |
| OLD | NEW |