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

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

Issue 451753003: Mojo multiple command buffer support and sample (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 4 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 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 26 matching lines...) Expand all
37 connection->ConnectToService("mojo:mojo_surfaces_service", &surfaces_); 37 connection->ConnectToService("mojo:mojo_surfaces_service", &surfaces_);
38 surfaces_.set_client(this); 38 surfaces_.set_client(this);
39 39
40 size_ = gfx::Size(800, 600); 40 size_ = gfx::Size(800, 600);
41 41
42 viewport_->Create(Rect::From(gfx::Rect(gfx::Point(10, 10), size_))); 42 viewport_->Create(Rect::From(gfx::Rect(gfx::Point(10, 10), size_)));
43 viewport_->Show(); 43 viewport_->Show();
44 44
45 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2); 45 child_size_ = gfx::Size(size_.width() / 3, size_.height() / 2);
46 connection->ConnectToService("mojo:mojo_surfaces_child_app", &child_one_); 46 connection->ConnectToService("mojo:mojo_surfaces_child_app", &child_one_);
47 connection->ConnectToService("mojo:mojo_surfaces_child_app", &child_two_); 47 connection->ConnectToService("mojo:mojo_surfaces_child_gl_app",
48 &child_two_);
48 child_one_->ProduceFrame(Color::From(SK_ColorBLUE), 49 child_one_->ProduceFrame(Color::From(SK_ColorBLUE),
49 Size::From(child_size_), 50 Size::From(child_size_),
50 base::Bind(&SurfacesApp::ChildOneProducedFrame, 51 base::Bind(&SurfacesApp::ChildOneProducedFrame,
51 base::Unretained(this))); 52 base::Unretained(this)));
52 child_two_->ProduceFrame(Color::From(SK_ColorGREEN), 53 child_two_->ProduceFrame(Color::From(SK_ColorGREEN),
53 Size::From(child_size_), 54 Size::From(child_size_),
54 base::Bind(&SurfacesApp::ChildTwoProducedFrame, 55 base::Bind(&SurfacesApp::ChildTwoProducedFrame,
55 base::Unretained(this))); 56 base::Unretained(this)));
56 embedder_.reset(new Embedder(surfaces_.get())); 57 embedder_.reset(new Embedder(surfaces_.get()));
57 return true; 58 return true;
58 } 59 }
59 60
60 void ChildOneProducedFrame(SurfaceIdPtr id) { 61 void ChildOneProducedFrame(SurfaceIdPtr id) {
61 child_one_id_ = id.To<cc::SurfaceId>(); 62 child_one_id_ = id.To<cc::SurfaceId>();
62 Draw(45.0); 63 Draw(10);
63 } 64 }
64 65
65 void ChildTwoProducedFrame(SurfaceIdPtr id) { 66 void ChildTwoProducedFrame(SurfaceIdPtr id) {
66 child_two_id_ = id.To<cc::SurfaceId>(); 67 child_two_id_ = id.To<cc::SurfaceId>();
67 Draw(45.0); 68 Draw(10);
68 } 69 }
69 70
70 void Draw(double rotation_degrees) { 71 void Draw(int offset) {
71 if (onscreen_id_.is_null()) { 72 if (onscreen_id_.is_null()) {
72 onscreen_id_ = allocator_->GenerateId(); 73 onscreen_id_ = allocator_->GenerateId();
73 CommandBufferPtr cb; 74 CommandBufferPtr cb;
74 viewport_->CreateGLES2Context(Get(&cb)); 75 viewport_->CreateGLES2Context(Get(&cb));
75 surfaces_->CreateGLES2BoundSurface( 76 surfaces_->CreateGLES2BoundSurface(
76 cb.Pass(), 77 cb.Pass(),
77 SurfaceId::From(onscreen_id_), 78 SurfaceId::From(onscreen_id_),
78 Size::From(size_)); 79 Size::From(size_));
79 embedder_->SetSurfaceId(onscreen_id_); 80 embedder_->SetSurfaceId(onscreen_id_);
80 } 81 }
81 if (child_one_id_.is_null() || child_two_id_.is_null()) 82 if (child_one_id_.is_null() || child_two_id_.is_null())
82 return; 83 return;
84 int bounced_offset = offset;
85 if (offset > 200)
86 bounced_offset = 400 - offset;
83 embedder_->ProduceFrame( 87 embedder_->ProduceFrame(
84 child_one_id_, child_two_id_, child_size_, size_, rotation_degrees); 88 child_one_id_, child_two_id_, child_size_, size_, bounced_offset);
85 base::MessageLoop::current()->PostDelayedTask( 89 base::MessageLoop::current()->PostDelayedTask(
86 FROM_HERE, 90 FROM_HERE,
87 base::Bind( 91 base::Bind(
88 &SurfacesApp::Draw, base::Unretained(this), rotation_degrees + 2.0), 92 &SurfacesApp::Draw, base::Unretained(this), (offset + 2) % 400),
89 base::TimeDelta::FromMilliseconds(17)); 93 base::TimeDelta::FromMilliseconds(50));
90 } 94 }
91 95
92 // SurfaceClient implementation. 96 // SurfaceClient implementation.
93 virtual void SetIdNamespace(uint32_t id_namespace) OVERRIDE { 97 virtual void SetIdNamespace(uint32_t id_namespace) OVERRIDE {
94 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace)); 98 allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
95 Draw(45.0); 99 Draw(10);
96 } 100 }
97 virtual void ReturnResources( 101 virtual void ReturnResources(
98 Array<ReturnedResourcePtr> resources) OVERRIDE { 102 Array<ReturnedResourcePtr> resources) OVERRIDE {
99 DCHECK(!resources.size()); 103 DCHECK(!resources.size());
100 } 104 }
101 105
102 // NativeViewportClient implementation 106 // NativeViewportClient implementation
103 virtual void OnCreated() OVERRIDE {} 107 virtual void OnCreated() OVERRIDE {}
104 virtual void OnBoundsChanged(mojo::RectPtr bounds) OVERRIDE {} 108 virtual void OnBoundsChanged(mojo::RectPtr bounds) OVERRIDE {}
105 virtual void OnDestroyed(const mojo::Callback<void()>& callback) OVERRIDE { 109 virtual void OnDestroyed(const mojo::Callback<void()>& callback) OVERRIDE {
(...skipping 22 matching lines...) Expand all
128 }; 132 };
129 133
130 } // namespace examples 134 } // namespace examples
131 135
132 // static 136 // static
133 ApplicationDelegate* ApplicationDelegate::Create() { 137 ApplicationDelegate* ApplicationDelegate::Create() {
134 return new examples::SurfacesApp(); 138 return new examples::SurfacesApp();
135 } 139 }
136 140
137 } // namespace mojo 141 } // namespace mojo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698