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_delegate.h" | 10 #include "mojo/public/cpp/application/application_delegate.h" |
11 #include "mojo/public/cpp/application/application_impl.h" | 11 #include "mojo/public/cpp/application/application_impl.h" |
12 #include "mojo/public/cpp/system/core.h" | 12 #include "mojo/public/cpp/system/core.h" |
13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" | 13 #include "mojo/services/public/cpp/geometry/geometry_type_converters.h" |
14 #include "mojo/services/public/interfaces/gpu/gpu.mojom.h" | |
15 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" | 14 #include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.
h" |
16 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
17 | 16 |
18 namespace mojo { | 17 namespace mojo { |
19 namespace examples { | 18 namespace examples { |
20 | 19 |
21 class SampleApp : public ApplicationDelegate, public NativeViewportClient { | 20 class SampleApp : public ApplicationDelegate, public NativeViewportClient { |
22 public: | 21 public: |
23 SampleApp() {} | 22 SampleApp() {} |
24 virtual ~SampleApp() {} | 23 virtual ~SampleApp() {} |
25 | 24 |
26 virtual void Initialize(ApplicationImpl* app) OVERRIDE { | 25 virtual void Initialize(ApplicationImpl* app) OVERRIDE { |
27 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); | 26 app->ConnectToService("mojo:mojo_native_viewport_service", &viewport_); |
28 viewport_.set_client(this); | 27 viewport_.set_client(this); |
29 viewport_->Create(Rect::From(gfx::Rect(10, 10, 800, 600))); | 28 viewport_->Create(Rect::From(gfx::Rect(10, 10, 800, 600))); |
30 viewport_->Show(); | 29 viewport_->Show(); |
31 | 30 |
32 // TODO(jamesr): Should be mojo:mojo_gpu_service | 31 MessagePipe pipe; |
33 app->ConnectToService("mojo:mojo_native_viewport_service", &gpu_service_); | 32 viewport_->CreateGLES2Context( |
| 33 MakeRequest<CommandBuffer>(pipe.handle0.Pass())); |
| 34 host_.reset(new CompositorHost(pipe.handle1.Pass())); |
34 } | 35 } |
35 | 36 |
36 virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE { | 37 virtual void OnCreated() OVERRIDE { |
37 CommandBufferPtr cb; | |
38 gpu_service_->CreateOnscreenGLES2Context( | |
39 native_viewport_id, Size::From(gfx::Size(800, 600)), Get(&cb)); | |
40 host_.reset(new CompositorHost(cb.PassMessagePipe())); | |
41 } | 38 } |
42 | 39 |
43 virtual void OnDestroyed() OVERRIDE { base::MessageLoop::current()->Quit(); } | 40 virtual void OnDestroyed(const mojo::Callback<void()>& callback) OVERRIDE { |
| 41 base::MessageLoop::current()->Quit(); |
| 42 callback.Run(); |
| 43 } |
44 | 44 |
45 virtual void OnBoundsChanged(RectPtr bounds) OVERRIDE { | 45 virtual void OnBoundsChanged(RectPtr bounds) OVERRIDE { |
46 if (host_) | 46 host_->SetSize(gfx::Size(bounds->width, bounds->height)); |
47 host_->SetSize(gfx::Size(bounds->width, bounds->height)); | |
48 } | 47 } |
49 | 48 |
50 virtual void OnEvent(EventPtr event, | 49 virtual void OnEvent(EventPtr event, |
51 const mojo::Callback<void()>& callback) OVERRIDE { | 50 const mojo::Callback<void()>& callback) OVERRIDE { |
52 callback.Run(); | 51 callback.Run(); |
53 } | 52 } |
54 | 53 |
55 private: | 54 private: |
56 NativeViewportPtr viewport_; | 55 NativeViewportPtr viewport_; |
57 GpuPtr gpu_service_; | |
58 scoped_ptr<CompositorHost> host_; | 56 scoped_ptr<CompositorHost> host_; |
59 DISALLOW_COPY_AND_ASSIGN(SampleApp); | 57 DISALLOW_COPY_AND_ASSIGN(SampleApp); |
60 }; | 58 }; |
61 | 59 |
62 } // namespace examples | 60 } // namespace examples |
63 | 61 |
64 // static | 62 // static |
65 ApplicationDelegate* ApplicationDelegate::Create() { | 63 ApplicationDelegate* ApplicationDelegate::Create() { |
66 return new examples::SampleApp(); | 64 return new examples::SampleApp(); |
67 } | 65 } |
68 | 66 |
69 } // namespace mojo | 67 } // namespace mojo |
OLD | NEW |