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