OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "base/bind.h" | 5 #include "base/bind.h" |
6 #include "base/macros.h" | 6 #include "base/macros.h" |
7 #include "base/memory/weak_ptr.h" | 7 #include "base/memory/weak_ptr.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "cc/surfaces/surface_id_allocator.h" | 9 #include "cc/surfaces/surface_id_allocator.h" |
10 #include "examples/surfaces_app/child.mojom.h" | 10 #include "examples/surfaces_app/child.mojom.h" |
11 #include "examples/surfaces_app/embedder.h" | 11 #include "examples/surfaces_app/embedder.h" |
12 #include "mojo/application/application_runner_chromium.h" | 12 #include "mojo/application/application_runner_chromium.h" |
13 #include "mojo/converters/geometry/geometry_type_converters.h" | 13 #include "mojo/converters/geometry/geometry_type_converters.h" |
14 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 14 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
15 #include "mojo/public/c/system/main.h" | 15 #include "mojo/public/c/system/main.h" |
16 #include "mojo/public/cpp/application/application_connection.h" | 16 #include "mojo/public/cpp/application/application_connection.h" |
17 #include "mojo/public/cpp/application/application_delegate.h" | 17 #include "mojo/public/cpp/application/application_delegate.h" |
18 #include "mojo/public/cpp/system/core.h" | 18 #include "mojo/public/cpp/system/core.h" |
19 #include "mojo/services/gpu/public/interfaces/command_buffer.mojom.h" | 19 #include "mojo/services/gpu/public/interfaces/command_buffer.mojom.h" |
20 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" | 20 #include "mojo/services/gpu/public/interfaces/gpu.mojom.h" |
21 #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom.
h" | 21 #include "mojo/services/native_viewport/public/interfaces/native_viewport.mojom.
h" |
22 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" | 22 #include "mojo/services/surfaces/public/interfaces/surfaces.mojom.h" |
23 #include "ui/gfx/rect.h" | 23 #include "ui/gfx/rect.h" |
24 | 24 |
25 namespace mojo { | 25 namespace mojo { |
26 namespace examples { | 26 namespace examples { |
27 | 27 |
28 static const uint32_t kLocalId = 1u; | 28 static const uint32_t kLocalId = 1u; |
29 | 29 |
30 class SurfacesApp : public ApplicationDelegate, | 30 class SurfacesApp : public ApplicationDelegate, public SurfaceClient { |
31 public SurfaceClient, | |
32 public NativeViewportClient { | |
33 public: | 31 public: |
34 SurfacesApp() : id_namespace_(0u), weak_factory_(this) {} | 32 SurfacesApp() : id_namespace_(0u), weak_factory_(this) {} |
35 ~SurfacesApp() override {} | 33 ~SurfacesApp() override {} |
36 | 34 |
37 // ApplicationDelegate implementation | 35 // ApplicationDelegate implementation |
38 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { | 36 bool ConfigureIncomingConnection(ApplicationConnection* connection) override { |
39 connection->ConnectToService("mojo:native_viewport_service", &viewport_); | 37 connection->ConnectToService("mojo:native_viewport_service", &viewport_); |
40 viewport_.set_client(this); | |
41 | 38 |
42 connection->ConnectToService("mojo:surfaces_service", &surface_); | 39 connection->ConnectToService("mojo:surfaces_service", &surface_); |
43 surface_.set_client(this); | 40 surface_.set_client(this); |
44 embedder_.reset(new Embedder(kLocalId, surface_.get())); | 41 embedder_.reset(new Embedder(kLocalId, surface_.get())); |
45 | 42 |
46 size_ = gfx::Size(800, 600); | 43 size_ = gfx::Size(800, 600); |
47 | 44 |
48 viewport_->Create(Size::From(size_), | 45 viewport_->Create(Size::From(size_), |
49 base::Bind(&SurfacesApp::OnCreatedNativeViewport, | 46 base::Bind(&SurfacesApp::OnCreatedNativeViewport, |
50 weak_factory_.GetWeakPtr())); | 47 weak_factory_.GetWeakPtr())); |
(...skipping 29 matching lines...) Expand all Loading... |
80 bounced_offset = 400 - offset; | 77 bounced_offset = 400 - offset; |
81 embedder_->ProduceFrame(child_one_id_, child_two_id_, child_size_, size_, | 78 embedder_->ProduceFrame(child_one_id_, child_two_id_, child_size_, size_, |
82 bounced_offset); | 79 bounced_offset); |
83 base::MessageLoop::current()->PostDelayedTask( | 80 base::MessageLoop::current()->PostDelayedTask( |
84 FROM_HERE, | 81 FROM_HERE, |
85 base::Bind( | 82 base::Bind( |
86 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400), | 83 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400), |
87 base::TimeDelta::FromMilliseconds(50)); | 84 base::TimeDelta::FromMilliseconds(50)); |
88 } | 85 } |
89 | 86 |
| 87 private: |
90 // SurfaceClient implementation. | 88 // SurfaceClient implementation. |
91 void SetIdNamespace(uint32_t id_namespace) override { | 89 void SetIdNamespace(uint32_t id_namespace) override { |
92 auto qualified_id = mojo::SurfaceId::New(); | 90 auto qualified_id = mojo::SurfaceId::New(); |
93 qualified_id->id_namespace = id_namespace; | 91 qualified_id->id_namespace = id_namespace; |
94 qualified_id->local = kLocalId; | 92 qualified_id->local = kLocalId; |
95 viewport_->SubmittedFrame(qualified_id.Pass()); | 93 viewport_->SubmittedFrame(qualified_id.Pass()); |
96 } | 94 } |
97 void ReturnResources(Array<ReturnedResourcePtr> resources) override { | 95 void ReturnResources(Array<ReturnedResourcePtr> resources) override { |
98 DCHECK(!resources.size()); | 96 DCHECK(!resources.size()); |
99 } | 97 } |
100 // NativeViewportClient implementation. | 98 void OnCreatedNativeViewport(uint64_t native_viewport_id, |
101 void OnMetricsChanged(mojo::ViewportMetricsPtr metrics) override {} | 99 mojo::ViewportMetricsPtr metrics) {} |
102 void OnDestroyed() override {} | |
103 | |
104 private: | |
105 void OnCreatedNativeViewport(uint64_t native_viewport_id) {} | |
106 | 100 |
107 SurfacePtr surface_; | 101 SurfacePtr surface_; |
108 uint32_t id_namespace_; | 102 uint32_t id_namespace_; |
109 SurfaceIdPtr onscreen_id_; | 103 SurfaceIdPtr onscreen_id_; |
110 scoped_ptr<Embedder> embedder_; | 104 scoped_ptr<Embedder> embedder_; |
111 ChildPtr child_one_; | 105 ChildPtr child_one_; |
112 cc::SurfaceId child_one_id_; | 106 cc::SurfaceId child_one_id_; |
113 ChildPtr child_two_; | 107 ChildPtr child_two_; |
114 cc::SurfaceId child_two_id_; | 108 cc::SurfaceId child_two_id_; |
115 gfx::Size size_; | 109 gfx::Size size_; |
116 gfx::Size child_size_; | 110 gfx::Size child_size_; |
117 | 111 |
118 NativeViewportPtr viewport_; | 112 NativeViewportPtr viewport_; |
119 | 113 |
120 base::WeakPtrFactory<SurfacesApp> weak_factory_; | 114 base::WeakPtrFactory<SurfacesApp> weak_factory_; |
121 | 115 |
122 DISALLOW_COPY_AND_ASSIGN(SurfacesApp); | 116 DISALLOW_COPY_AND_ASSIGN(SurfacesApp); |
123 }; | 117 }; |
124 | 118 |
125 } // namespace examples | 119 } // namespace examples |
126 } // namespace mojo | 120 } // namespace mojo |
127 | 121 |
128 MojoResult MojoMain(MojoHandle shell_handle) { | 122 MojoResult MojoMain(MojoHandle shell_handle) { |
129 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp); | 123 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp); |
130 return runner.Run(shell_handle); | 124 return runner.Run(shell_handle); |
131 } | 125 } |
OLD | NEW |