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

Side by Side Diff: components/view_manager/server_view.cc

Issue 1281663002: Mandoline: Allow submitting CompositorFrames directly to mojo::Views (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased Created 5 years, 3 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
« no previous file with comments | « components/view_manager/server_view.h ('k') | components/view_manager/server_view_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "components/view_manager/server_view.h" 5 #include "components/view_manager/server_view.h"
6 6
7 #include <inttypes.h> 7 #include <inttypes.h>
8 8
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "components/view_manager/server_view_delegate.h" 10 #include "components/view_manager/server_view_delegate.h"
11 #include "components/view_manager/server_view_observer.h" 11 #include "components/view_manager/server_view_observer.h"
12 #include "components/view_manager/surfaces/surfaces_state.h"
13 #include "mojo/converters/geometry/geometry_type_converters.h"
14 #include "mojo/converters/surfaces/surfaces_type_converters.h"
12 15
13 namespace view_manager { 16 namespace view_manager {
14 17
15 ServerView::ServerView(ServerViewDelegate* delegate, const ViewId& id) 18 namespace {
19
20 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) {
21 callback.Run();
22 }
23
24 } // namespace
25
26 ServerView::ServerView(ServerViewDelegate* delegate,
27 const ViewId& id)
16 : delegate_(delegate), 28 : delegate_(delegate),
17 id_(id), 29 id_(id),
18 parent_(nullptr), 30 parent_(nullptr),
19 visible_(false), 31 visible_(false),
20 opacity_(1), 32 opacity_(1),
21 allows_reembed_(false), 33 allows_reembed_(false),
22 // Don't notify newly added observers during notification. This causes 34 // Don't notify newly added observers during notification. This causes
23 // problems for code that adds an observer as part of an observer 35 // problems for code that adds an observer as part of an observer
24 // notification (such as ServerViewDrawTracker). 36 // notification (such as ServerViewDrawTracker).
25 observers_(base::ObserverList<ServerViewObserver>::NOTIFY_EXISTING_ONLY) { 37 observers_(base::ObserverList<ServerViewObserver>::NOTIFY_EXISTING_ONLY),
38 binding_(this) {
26 DCHECK(delegate); // Must provide a delegate. 39 DCHECK(delegate); // Must provide a delegate.
27 } 40 }
28 41
29 ServerView::~ServerView() { 42 ServerView::~ServerView() {
30 delegate_->PrepareToDestroyView(this); 43 delegate_->PrepareToDestroyView(this);
31 FOR_EACH_OBSERVER(ServerViewObserver, observers_, OnWillDestroyView(this)); 44 FOR_EACH_OBSERVER(ServerViewObserver, observers_, OnWillDestroyView(this));
32 45
33 while (!children_.empty()) 46 while (!children_.empty())
34 children_.front()->parent()->Remove(children_.front()); 47 children_.front()->parent()->Remove(children_.front());
35 48
36 if (parent_) 49 if (parent_)
37 parent_->Remove(this); 50 parent_->Remove(this);
38 51
39 FOR_EACH_OBSERVER(ServerViewObserver, observers_, OnViewDestroyed(this)); 52 FOR_EACH_OBSERVER(ServerViewObserver, observers_, OnViewDestroyed(this));
53
54 // SurfaceFactory's destructor will attempt to return resources which will
55 // call back into here and access |client_| so we should destroy
56 // |surface_factory_| early on.
57 surface_factory_.reset();
40 } 58 }
41 59
42 void ServerView::AddObserver(ServerViewObserver* observer) { 60 void ServerView::AddObserver(ServerViewObserver* observer) {
43 observers_.AddObserver(observer); 61 observers_.AddObserver(observer);
44 } 62 }
45 63
46 void ServerView::RemoveObserver(ServerViewObserver* observer) { 64 void ServerView::RemoveObserver(ServerViewObserver* observer) {
47 observers_.RemoveObserver(observer); 65 observers_.RemoveObserver(observer);
48 } 66 }
49 67
68 void ServerView::Bind(mojo::InterfaceRequest<Surface> request,
69 mojo::SurfaceClientPtr client) {
70 if (binding_.is_bound()) {
71 binding_.Close();
72 client_ = nullptr;
73 }
74 binding_.Bind(request.Pass());
75 client_ = client.Pass();
76 }
77
50 void ServerView::Add(ServerView* child) { 78 void ServerView::Add(ServerView* child) {
51 // We assume validation checks happened already. 79 // We assume validation checks happened already.
52 DCHECK(child); 80 DCHECK(child);
53 DCHECK(child != this); 81 DCHECK(child != this);
54 DCHECK(!child->Contains(this)); 82 DCHECK(!child->Contains(this));
55 if (child->parent() == this) { 83 if (child->parent() == this) {
56 if (children_.size() == 1) 84 if (children_.size() == 1)
57 return; // Already in the right position. 85 return; // Already in the right position.
58 Reorder(child, children_.back(), mojo::ORDER_DIRECTION_ABOVE); 86 Reorder(child, children_.back(), mojo::ORDER_DIRECTION_ABOVE);
59 return; 87 return;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 while (view && view != root && view->visible()) 238 while (view && view != root && view->visible())
211 view = view->parent(); 239 view = view->parent();
212 return root == view; 240 return root == view;
213 } 241 }
214 242
215 void ServerView::SetSurfaceId(cc::SurfaceId surface_id) { 243 void ServerView::SetSurfaceId(cc::SurfaceId surface_id) {
216 surface_id_ = surface_id; 244 surface_id_ = surface_id;
217 delegate_->OnScheduleViewPaint(this); 245 delegate_->OnScheduleViewPaint(this);
218 } 246 }
219 247
248 void ServerView::SubmitCompositorFrame(
249 mojo::CompositorFramePtr frame,
250 const SubmitCompositorFrameCallback& callback) {
251 gfx::Size frame_size = frame->passes[0]->output_rect.To<gfx::Rect>().size();
252 // Create Surfaces state on demand.
253 if (!surface_factory_) {
254 surface_factory_.reset(
255 new cc::SurfaceFactory(delegate_->GetSurfacesState()->manager(), this));
256 }
257 if (!surface_id_allocator_) {
258 surface_id_allocator_.reset(
259 new cc::SurfaceIdAllocator(
260 delegate_->GetSurfacesState()->next_id_namespace()));
261 }
262 if (surface_id().is_null()) {
263 // Create a Surface ID for the first time for this view.
264 cc::SurfaceId surface_id(surface_id_allocator_->GenerateId());
265 surface_factory_->Create(surface_id);
266 SetSurfaceId(surface_id);
267 } else {
268 // If the size of the CompostiorFrame has changed then destroy the existing
269 // Surface and create a new one of the appropriate size.
270 if (frame_size != last_submitted_frame_size()) {
271 surface_factory_->Destroy(surface_id());
272 cc::SurfaceId surface_id(surface_id_allocator_->GenerateId());
273 surface_factory_->Create(surface_id);
274 SetSurfaceId(surface_id);
275 }
276 }
277 surface_factory_->SubmitCompositorFrame(
278 surface_id(),
279 frame.To<scoped_ptr<cc::CompositorFrame>>(),
280 base::Bind(&CallCallback, callback));
281 delegate_->GetSurfacesState()->scheduler()->SetNeedsDraw();
282 last_submitted_frame_size_ = frame_size;
283 }
284
220 #if !defined(NDEBUG) 285 #if !defined(NDEBUG)
221 std::string ServerView::GetDebugWindowHierarchy() const { 286 std::string ServerView::GetDebugWindowHierarchy() const {
222 std::string result; 287 std::string result;
223 BuildDebugInfo(std::string(), &result); 288 BuildDebugInfo(std::string(), &result);
224 return result; 289 return result;
225 } 290 }
226 291
227 void ServerView::BuildDebugInfo(const std::string& depth, 292 void ServerView::BuildDebugInfo(const std::string& depth,
228 std::string* result) const { 293 std::string* result) const {
229 *result += base::StringPrintf( 294 *result += base::StringPrintf(
230 "%sid=%d,%d visible=%s bounds=%d,%d %dx%d surface_id=%" PRIu64 "\n", 295 "%sid=%d,%d visible=%s bounds=%d,%d %dx%d surface_id=%" PRIu64 "\n",
231 depth.c_str(), static_cast<int>(id_.connection_id), 296 depth.c_str(), static_cast<int>(id_.connection_id),
232 static_cast<int>(id_.view_id), visible_ ? "true" : "false", bounds_.x(), 297 static_cast<int>(id_.view_id), visible_ ? "true" : "false", bounds_.x(),
233 bounds_.y(), bounds_.width(), bounds_.height(), surface_id_.id); 298 bounds_.y(), bounds_.width(), bounds_.height(), surface_id_.id);
234 for (const ServerView* child : children_) 299 for (const ServerView* child : children_)
235 child->BuildDebugInfo(depth + " ", result); 300 child->BuildDebugInfo(depth + " ", result);
236 } 301 }
237 #endif 302 #endif
238 303
304 void ServerView::ReturnResources(
305 const cc::ReturnedResourceArray& resources) {
306 if (!client_)
307 return;
308 client_->ReturnResources(
309 mojo::Array<mojo::ReturnedResourcePtr>::From(resources));
310 }
311
239 void ServerView::RemoveImpl(ServerView* view) { 312 void ServerView::RemoveImpl(ServerView* view) {
240 view->parent_ = NULL; 313 view->parent_ = NULL;
241 children_.erase(std::find(children_.begin(), children_.end(), view)); 314 children_.erase(std::find(children_.begin(), children_.end(), view));
242 } 315 }
243 316
244 } // namespace view_manager 317 } // namespace view_manager
OLDNEW
« no previous file with comments | « components/view_manager/server_view.h ('k') | components/view_manager/server_view_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698