Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: mojo/examples/aura_demo/aura_demo.cc

Issue 314113011: Moves common view_manager related aura files to mojo/aura (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: tweaks Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/bind.h" 8 #include "base/bind.h"
9 #include "mojo/aura/context_factory_mojo.h"
9 #include "mojo/aura/screen_mojo.h" 10 #include "mojo/aura/screen_mojo.h"
10 #include "mojo/examples/aura_demo/context_factory_view_manager.h" 11 #include "mojo/aura/window_tree_host_mojo.h"
11 #include "mojo/examples/aura_demo/window_tree_host_view_manager.h" 12 #include "mojo/aura/window_tree_host_mojo_delegate.h"
12 #include "mojo/public/cpp/application/application.h" 13 #include "mojo/public/cpp/application/application.h"
13 #include "mojo/public/cpp/system/core.h" 14 #include "mojo/public/cpp/system/core.h"
14 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h" 15 #include "mojo/public/interfaces/service_provider/service_provider.mojom.h"
15 #include "mojo/services/native_viewport/native_viewport.mojom.h" 16 #include "mojo/services/native_viewport/native_viewport.mojom.h"
16 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h" 17 #include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
17 #include "ui/aura/client/default_capture_client.h" 18 #include "ui/aura/client/default_capture_client.h"
18 #include "ui/aura/client/window_tree_client.h" 19 #include "ui/aura/client/window_tree_client.h"
19 #include "ui/aura/env.h" 20 #include "ui/aura/env.h"
20 #include "ui/aura/window.h" 21 #include "ui/aura/window.h"
21 #include "ui/aura/window_delegate.h" 22 #include "ui/aura/window_delegate.h"
22 #include "ui/base/hit_test.h" 23 #include "ui/base/hit_test.h"
23 #include "ui/gfx/canvas.h" 24 #include "ui/gfx/canvas.h"
25 #include "ui/gfx/codec/png_codec.h"
24 26
25 namespace mojo { 27 namespace mojo {
26 namespace examples { 28 namespace examples {
27 29
30 void OnSetViewContentsDone(bool value) {
31 VLOG(1) << "OnSetViewContentsDone " << value;
32 DCHECK(value);
33 }
34
35 bool CreateMapAndDupSharedBuffer(size_t size,
36 void** memory,
37 ScopedSharedBufferHandle* handle,
38 ScopedSharedBufferHandle* duped) {
39 MojoResult result = CreateSharedBuffer(NULL, size, handle);
40 if (result != MOJO_RESULT_OK)
41 return false;
42 DCHECK(handle->is_valid());
43
44 result = DuplicateBuffer(handle->get(), NULL, duped);
45 if (result != MOJO_RESULT_OK)
46 return false;
47 DCHECK(duped->is_valid());
48
49 result = MapBuffer(
50 handle->get(), 0, size, memory, MOJO_MAP_BUFFER_FLAG_NONE);
51 if (result != MOJO_RESULT_OK)
52 return false;
53 DCHECK(*memory);
54
55 return true;
56 }
57
28 // Trivial WindowDelegate implementation that draws a colored background. 58 // Trivial WindowDelegate implementation that draws a colored background.
29 class DemoWindowDelegate : public aura::WindowDelegate { 59 class DemoWindowDelegate : public aura::WindowDelegate {
30 public: 60 public:
31 explicit DemoWindowDelegate(SkColor color) : color_(color) {} 61 explicit DemoWindowDelegate(SkColor color) : color_(color) {}
32 62
33 // Overridden from WindowDelegate: 63 // Overridden from WindowDelegate:
34 virtual gfx::Size GetMinimumSize() const OVERRIDE { 64 virtual gfx::Size GetMinimumSize() const OVERRIDE {
35 return gfx::Size(); 65 return gfx::Size();
36 } 66 }
37 67
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
149 virtual void OnViewInputEvent(uint32_t view_id, 179 virtual void OnViewInputEvent(uint32_t view_id,
150 EventPtr event, 180 EventPtr event,
151 const Callback<void()>& callback) OVERRIDE { 181 const Callback<void()>& callback) OVERRIDE {
152 } 182 }
153 183
154 AuraDemo* aura_demo_; 184 AuraDemo* aura_demo_;
155 185
156 DISALLOW_COPY_AND_ASSIGN(IViewManagerClientImpl); 186 DISALLOW_COPY_AND_ASSIGN(IViewManagerClientImpl);
157 }; 187 };
158 188
159 class AuraDemo : public Application { 189 class AuraDemo : public Application, public WindowTreeHostMojoDelegate {
160 public: 190 public:
161 AuraDemo() { 191 AuraDemo()
192 : view_manager_(NULL),
193 window1_(NULL),
194 window2_(NULL),
195 window21_(NULL),
196 view_id_(0) {
162 AddService<IViewManagerClientImpl>(this); 197 AddService<IViewManagerClientImpl>(this);
163 } 198 }
164 virtual ~AuraDemo() {} 199 virtual ~AuraDemo() {}
165 200
166 void SetRoot(view_manager::IViewManager* view_manager, uint32_t node_id) { 201 void SetRoot(view_manager::IViewManager* view_manager, uint32_t view_id) {
167 context_factory_.reset(
168 new ContextFactoryViewManager(view_manager, node_id));
169 aura::Env::CreateInstance(true); 202 aura::Env::CreateInstance(true);
203 view_manager_ = view_manager;
204 view_id_ = view_id;
205 context_factory_.reset(new ContextFactoryMojo);
170 aura::Env::GetInstance()->set_context_factory(context_factory_.get()); 206 aura::Env::GetInstance()->set_context_factory(context_factory_.get());
171 screen_.reset(ScreenMojo::Create()); 207 screen_.reset(ScreenMojo::Create());
172 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get()); 208 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, screen_.get());
173 209
174 window_tree_host_.reset(new WindowTreeHostViewManager(gfx::Rect(800, 600))); 210 window_tree_host_.reset(new WindowTreeHostMojo(gfx::Rect(800, 600), this));
175 window_tree_host_->InitHost(); 211 window_tree_host_->InitHost();
176 212
177 window_tree_client_.reset( 213 window_tree_client_.reset(
178 new DemoWindowTreeClient(window_tree_host_->window())); 214 new DemoWindowTreeClient(window_tree_host_->window()));
179 215
180 delegate1_.reset(new DemoWindowDelegate(SK_ColorBLUE)); 216 delegate1_.reset(new DemoWindowDelegate(SK_ColorBLUE));
181 window1_ = new aura::Window(delegate1_.get()); 217 window1_ = new aura::Window(delegate1_.get());
182 window1_->Init(aura::WINDOW_LAYER_TEXTURED); 218 window1_->Init(aura::WINDOW_LAYER_TEXTURED);
183 window1_->SetBounds(gfx::Rect(100, 100, 400, 400)); 219 window1_->SetBounds(gfx::Rect(100, 100, 400, 400));
184 window1_->Show(); 220 window1_->Show();
185 window_tree_host_->window()->AddChild(window1_); 221 window_tree_host_->window()->AddChild(window1_);
186 222
187 delegate2_.reset(new DemoWindowDelegate(SK_ColorRED)); 223 delegate2_.reset(new DemoWindowDelegate(SK_ColorRED));
188 window2_ = new aura::Window(delegate2_.get()); 224 window2_ = new aura::Window(delegate2_.get());
189 window2_->Init(aura::WINDOW_LAYER_TEXTURED); 225 window2_->Init(aura::WINDOW_LAYER_TEXTURED);
190 window2_->SetBounds(gfx::Rect(200, 200, 350, 350)); 226 window2_->SetBounds(gfx::Rect(200, 200, 350, 350));
191 window2_->Show(); 227 window2_->Show();
192 window_tree_host_->window()->AddChild(window2_); 228 window_tree_host_->window()->AddChild(window2_);
193 229
194 delegate21_.reset(new DemoWindowDelegate(SK_ColorGREEN)); 230 delegate21_.reset(new DemoWindowDelegate(SK_ColorGREEN));
195 window21_ = new aura::Window(delegate21_.get()); 231 window21_ = new aura::Window(delegate21_.get());
196 window21_->Init(aura::WINDOW_LAYER_TEXTURED); 232 window21_->Init(aura::WINDOW_LAYER_TEXTURED);
197 window21_->SetBounds(gfx::Rect(10, 10, 50, 50)); 233 window21_->SetBounds(gfx::Rect(10, 10, 50, 50));
198 window21_->Show(); 234 window21_->Show();
199 window2_->AddChild(window21_); 235 window2_->AddChild(window21_);
200 236
201 window_tree_host_->Show(); 237 window_tree_host_->Show();
202 } 238 }
203 239
240 // WindowTreeHostMojoDelegate:
241 virtual void CompositorContentsChanged(const SkBitmap& bitmap) OVERRIDE {
242 std::vector<unsigned char> data;
243 gfx::PNGCodec::EncodeBGRASkBitmap(bitmap, false, &data);
244
245 void* memory = NULL;
246 ScopedSharedBufferHandle duped;
247 bool result = CreateMapAndDupSharedBuffer(data.size(),
248 &memory,
249 &shared_state_handle_,
250 &duped);
251 if (!result)
252 return;
253
254 memcpy(memory, &data[0], data.size());
255
256 view_manager_->SetViewContents(
257 view_id_, duped.Pass(), static_cast<uint32_t>(data.size()),
258 base::Bind(&OnSetViewContentsDone));
259 }
260
204 virtual void Initialize() OVERRIDE { 261 virtual void Initialize() OVERRIDE {
205 } 262 }
206 263
207 scoped_ptr<ContextFactoryViewManager> context_factory_; 264 scoped_ptr<DemoWindowTreeClient> window_tree_client_;
265
266 scoped_ptr<ui::ContextFactory> context_factory_;
208 267
209 scoped_ptr<ScreenMojo> screen_; 268 scoped_ptr<ScreenMojo> screen_;
210 269
211 scoped_ptr<DemoWindowTreeClient> window_tree_client_;
212
213 scoped_ptr<DemoWindowDelegate> delegate1_; 270 scoped_ptr<DemoWindowDelegate> delegate1_;
214 scoped_ptr<DemoWindowDelegate> delegate2_; 271 scoped_ptr<DemoWindowDelegate> delegate2_;
215 scoped_ptr<DemoWindowDelegate> delegate21_; 272 scoped_ptr<DemoWindowDelegate> delegate21_;
216 273
274 view_manager::IViewManager* view_manager_;
275
217 aura::Window* window1_; 276 aura::Window* window1_;
218 aura::Window* window2_; 277 aura::Window* window2_;
219 aura::Window* window21_; 278 aura::Window* window21_;
220 279
280 uint32_t view_id_;
281
221 scoped_ptr<aura::WindowTreeHost> window_tree_host_; 282 scoped_ptr<aura::WindowTreeHost> window_tree_host_;
222 283
284 ScopedSharedBufferHandle shared_state_handle_;
285
223 DISALLOW_COPY_AND_ASSIGN(AuraDemo); 286 DISALLOW_COPY_AND_ASSIGN(AuraDemo);
224 }; 287 };
225 288
226 void IViewManagerClientImpl::OnViewManagerConnectionEstablished( 289 void IViewManagerClientImpl::OnViewManagerConnectionEstablished(
227 uint16_t connection_id, 290 uint16_t connection_id,
228 uint32_t next_server_change_id, 291 uint32_t next_server_change_id,
229 mojo::Array<view_manager::INodePtr> nodes) { 292 mojo::Array<view_manager::INodePtr> nodes) {
230 const uint32_t view_id = connection_id << 16 | 1; 293 const uint32_t view_id = connection_id << 16 | 1;
231 client()->CreateView(view_id, base::Bind(&IViewManagerClientImpl::OnResult, 294 client()->CreateView(view_id, base::Bind(&IViewManagerClientImpl::OnResult,
232 base::Unretained(this))); 295 base::Unretained(this)));
233 client()->SetView(nodes[0]->node_id, view_id, 296 client()->SetView(nodes[0]->node_id, view_id,
234 base::Bind(&IViewManagerClientImpl::OnResult, 297 base::Bind(&IViewManagerClientImpl::OnResult,
235 base::Unretained(this))); 298 base::Unretained(this)));
236 299
237 aura_demo_->SetRoot(client(), view_id); 300 aura_demo_->SetRoot(client(), view_id);
238 } 301 }
239 302
240 } // namespace examples 303 } // namespace examples
241 304
242 // static 305 // static
243 Application* Application::Create() { 306 Application* Application::Create() {
244 return new examples::AuraDemo(); 307 return new examples::AuraDemo();
245 } 308 }
246 309
247 } // namespace mojo 310 } // namespace mojo
248 311
OLDNEW
« no previous file with comments | « mojo/aura/window_tree_host_mojo_delegate.h ('k') | mojo/examples/aura_demo/context_factory_view_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698