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/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
8 #include "cc/surfaces/surface_id_allocator.h" | 8 #include "cc/surfaces/surface_id_allocator.h" |
9 #include "mojo/examples/surfaces_app/child.mojom.h" | 9 #include "mojo/examples/surfaces_app/child.mojom.h" |
10 #include "mojo/examples/surfaces_app/embedder.h" | 10 #include "mojo/examples/surfaces_app/embedder.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h" | 22 #include "mojo/services/public/interfaces/surfaces/surfaces_service.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 class SurfacesApp : public ApplicationDelegate, | 28 class SurfacesApp : public ApplicationDelegate, |
29 public SurfaceClient, | 29 public SurfaceClient, |
30 public NativeViewportClient { | 30 public NativeViewportClient { |
31 public: | 31 public: |
32 SurfacesApp() : native_viewport_id_(0) {} | 32 SurfacesApp() {} |
33 virtual ~SurfacesApp() {} | 33 virtual ~SurfacesApp() {} |
34 | 34 |
35 // ApplicationDelegate implementation | 35 // ApplicationDelegate implementation |
36 virtual bool ConfigureIncomingConnection( | 36 virtual bool ConfigureIncomingConnection( |
37 ApplicationConnection* connection) OVERRIDE { | 37 ApplicationConnection* connection) OVERRIDE { |
38 connection->ConnectToService("mojo:mojo_native_viewport_service", | 38 connection->ConnectToService("mojo:mojo_native_viewport_service", |
39 &viewport_); | 39 &viewport_); |
40 viewport_.set_client(this); | 40 viewport_.set_client(this); |
41 | 41 |
42 // TODO(jamesr): Should be mojo:mojo_gpu_service | |
43 connection->ConnectToService("mojo:mojo_native_viewport_service", | |
44 &gpu_service_); | |
45 | |
46 connection->ConnectToService("mojo:mojo_surfaces_service", | 42 connection->ConnectToService("mojo:mojo_surfaces_service", |
47 &surfaces_service_); | 43 &surfaces_service_); |
48 surfaces_service_->CreateSurfaceConnection(base::Bind( | 44 surfaces_service_->CreateSurfaceConnection(base::Bind( |
49 &SurfacesApp::SurfaceConnectionCreated, base::Unretained(this))); | 45 &SurfacesApp::SurfaceConnectionCreated, base::Unretained(this))); |
50 | 46 |
51 size_ = gfx::Size(800, 600); | 47 size_ = gfx::Size(800, 600); |
52 | 48 |
53 viewport_->Create(Rect::From(gfx::Rect(gfx::Point(10, 10), size_))); | 49 viewport_->Create(Rect::From(gfx::Rect(gfx::Point(10, 10), size_))); |
54 viewport_->Show(); | 50 viewport_->Show(); |
55 | 51 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 surface_.set_client(this); | 95 surface_.set_client(this); |
100 embedder_.reset(new Embedder(surface_.get())); | 96 embedder_.reset(new Embedder(surface_.get())); |
101 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); | 97 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); |
102 CreateSurfaceIfReady(); | 98 CreateSurfaceIfReady(); |
103 } | 99 } |
104 virtual void ReturnResources( | 100 virtual void ReturnResources( |
105 Array<ReturnedResourcePtr> resources) OVERRIDE { | 101 Array<ReturnedResourcePtr> resources) OVERRIDE { |
106 DCHECK(!resources.size()); | 102 DCHECK(!resources.size()); |
107 } | 103 } |
108 | 104 |
109 // NativeViewportClient implementation | |
110 virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE { | |
111 native_viewport_id_ = native_viewport_id; | |
112 CreateSurfaceIfReady(); | |
113 } | |
114 | |
115 // We can't create our GLES2-bound surface until we have our id namespace from | 105 // We can't create our GLES2-bound surface until we have our id namespace from |
116 // the surfaces service and our native viewport id from the native viewport | 106 // the surfaces service and our native viewport id from the native viewport |
117 // service. There's no way of knowing which we'll get first, so we just start | 107 // service. There's no way of knowing which we'll get first, so we just start |
118 // whenever both arrive. | 108 // whenever both arrive. |
119 void CreateSurfaceIfReady() { | 109 void CreateSurfaceIfReady() { |
120 if (!onscreen_id_.is_null()) | 110 if (!onscreen_id_.is_null() || !allocator_) |
121 return; | |
122 if (native_viewport_id_ == 0) | |
123 return; | |
124 if (!allocator_) | |
125 return; | 111 return; |
126 | 112 |
127 onscreen_id_ = allocator_->GenerateId(); | 113 onscreen_id_ = allocator_->GenerateId(); |
128 embedder_->SetSurfaceId(onscreen_id_); | 114 embedder_->SetSurfaceId(onscreen_id_); |
129 CommandBufferPtr cb; | 115 surface_->CreateSurface(SurfaceId::From(onscreen_id_), Size::From(size_)); |
130 gpu_service_->CreateOnscreenGLES2Context( | 116 viewport_->SubmittedFrame(SurfaceId::From(onscreen_id_)); |
131 native_viewport_id_, Size::From(size_), Get(&cb)); | |
132 surface_->CreateGLES2BoundSurface( | |
133 cb.Pass(), SurfaceId::From(onscreen_id_), Size::From(size_)); | |
134 Draw(10); | 117 Draw(10); |
135 } | 118 } |
| 119 |
| 120 // NativeViewportClient implementation. |
| 121 virtual void OnCreated(uint64_t native_viewport_id) OVERRIDE {} |
136 virtual void OnBoundsChanged(mojo::RectPtr bounds) OVERRIDE {} | 122 virtual void OnBoundsChanged(mojo::RectPtr bounds) OVERRIDE {} |
137 virtual void OnDestroyed() OVERRIDE {} | 123 virtual void OnDestroyed() OVERRIDE {} |
138 virtual void OnEvent(mojo::EventPtr event, | 124 virtual void OnEvent(mojo::EventPtr event, |
139 const mojo::Callback<void()>& callback) OVERRIDE { | 125 const mojo::Callback<void()>& callback) OVERRIDE { |
140 callback.Run(); | 126 callback.Run(); |
141 } | 127 } |
142 | 128 |
143 private: | 129 private: |
144 SurfacesServicePtr surfaces_service_; | 130 SurfacesServicePtr surfaces_service_; |
145 SurfacePtr surface_; | 131 SurfacePtr surface_; |
146 cc::SurfaceId onscreen_id_; | 132 cc::SurfaceId onscreen_id_; |
147 uint64_t native_viewport_id_; | |
148 scoped_ptr<cc::SurfaceIdAllocator> allocator_; | 133 scoped_ptr<cc::SurfaceIdAllocator> allocator_; |
149 scoped_ptr<Embedder> embedder_; | 134 scoped_ptr<Embedder> embedder_; |
150 ChildPtr child_one_; | 135 ChildPtr child_one_; |
151 cc::SurfaceId child_one_id_; | 136 cc::SurfaceId child_one_id_; |
152 ChildPtr child_two_; | 137 ChildPtr child_two_; |
153 cc::SurfaceId child_two_id_; | 138 cc::SurfaceId child_two_id_; |
154 gfx::Size size_; | 139 gfx::Size size_; |
155 gfx::Size child_size_; | 140 gfx::Size child_size_; |
156 | 141 |
157 NativeViewportPtr viewport_; | 142 NativeViewportPtr viewport_; |
158 GpuPtr gpu_service_; | |
159 | 143 |
160 DISALLOW_COPY_AND_ASSIGN(SurfacesApp); | 144 DISALLOW_COPY_AND_ASSIGN(SurfacesApp); |
161 }; | 145 }; |
162 | 146 |
163 } // namespace examples | 147 } // namespace examples |
164 } // namespace mojo | 148 } // namespace mojo |
165 | 149 |
166 MojoResult MojoMain(MojoHandle shell_handle) { | 150 MojoResult MojoMain(MojoHandle shell_handle) { |
167 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp); | 151 mojo::ApplicationRunnerChromium runner(new mojo::examples::SurfacesApp); |
168 return runner.Run(shell_handle); | 152 return runner.Run(shell_handle); |
169 } | 153 } |
OLD | NEW |