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 "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 void CallCallback(const mojo::Closure& callback, cc::SurfaceDrawStatus status) { | |
20 callback.Run(); | |
21 } | |
22 } | |
sky
2015/08/26 22:58:03
nit: // namespace
Fady Samuel
2015/08/26 23:51:01
Done.
| |
23 | |
24 ServerView::ServerView(ServerViewDelegate* delegate, | |
25 const ViewId& id) | |
16 : delegate_(delegate), | 26 : delegate_(delegate), |
17 id_(id), | 27 id_(id), |
18 parent_(nullptr), | 28 parent_(nullptr), |
19 visible_(false), | 29 visible_(false), |
20 opacity_(1), | 30 opacity_(1), |
21 allows_reembed_(false), | 31 allows_reembed_(false), |
22 // Don't notify newly added observers during notification. This causes | 32 // Don't notify newly added observers during notification. This causes |
23 // problems for code that adds an observer as part of an observer | 33 // problems for code that adds an observer as part of an observer |
24 // notification (such as ServerViewDrawTracker). | 34 // notification (such as ServerViewDrawTracker). |
25 observers_(base::ObserverList<ServerViewObserver>::NOTIFY_EXISTING_ONLY) { | 35 observers_(base::ObserverList<ServerViewObserver>::NOTIFY_EXISTING_ONLY), |
36 binding_(this) { | |
26 DCHECK(delegate); // Must provide a delegate. | 37 DCHECK(delegate); // Must provide a delegate. |
27 } | 38 } |
28 | 39 |
29 ServerView::~ServerView() { | 40 ServerView::~ServerView() { |
30 delegate_->PrepareToDestroyView(this); | 41 delegate_->PrepareToDestroyView(this); |
31 FOR_EACH_OBSERVER(ServerViewObserver, observers_, OnWillDestroyView(this)); | 42 FOR_EACH_OBSERVER(ServerViewObserver, observers_, OnWillDestroyView(this)); |
32 | 43 |
33 while (!children_.empty()) | 44 while (!children_.empty()) |
34 children_.front()->parent()->Remove(children_.front()); | 45 children_.front()->parent()->Remove(children_.front()); |
35 | 46 |
36 if (parent_) | 47 if (parent_) |
37 parent_->Remove(this); | 48 parent_->Remove(this); |
38 | 49 |
39 FOR_EACH_OBSERVER(ServerViewObserver, observers_, OnViewDestroyed(this)); | 50 FOR_EACH_OBSERVER(ServerViewObserver, observers_, OnViewDestroyed(this)); |
40 } | 51 } |
41 | 52 |
42 void ServerView::AddObserver(ServerViewObserver* observer) { | 53 void ServerView::AddObserver(ServerViewObserver* observer) { |
43 observers_.AddObserver(observer); | 54 observers_.AddObserver(observer); |
44 } | 55 } |
45 | 56 |
46 void ServerView::RemoveObserver(ServerViewObserver* observer) { | 57 void ServerView::RemoveObserver(ServerViewObserver* observer) { |
47 observers_.RemoveObserver(observer); | 58 observers_.RemoveObserver(observer); |
48 } | 59 } |
49 | 60 |
61 void ServerView::Bind(mojo::InterfaceRequest<Surface> request, | |
62 mojo::SurfaceClientPtr client) { | |
63 binding_.Bind(request.Pass()); | |
64 client_ = client.Pass(); | |
65 } | |
66 | |
50 void ServerView::Add(ServerView* child) { | 67 void ServerView::Add(ServerView* child) { |
51 // We assume validation checks happened already. | 68 // We assume validation checks happened already. |
52 DCHECK(child); | 69 DCHECK(child); |
53 DCHECK(child != this); | 70 DCHECK(child != this); |
54 DCHECK(!child->Contains(this)); | 71 DCHECK(!child->Contains(this)); |
55 if (child->parent() == this) { | 72 if (child->parent() == this) { |
56 if (children_.size() == 1) | 73 if (children_.size() == 1) |
57 return; // Already in the right position. | 74 return; // Already in the right position. |
58 Reorder(child, children_.back(), mojo::ORDER_DIRECTION_ABOVE); | 75 Reorder(child, children_.back(), mojo::ORDER_DIRECTION_ABOVE); |
59 return; | 76 return; |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
210 while (view && view != root && view->visible()) | 227 while (view && view != root && view->visible()) |
211 view = view->parent(); | 228 view = view->parent(); |
212 return root == view; | 229 return root == view; |
213 } | 230 } |
214 | 231 |
215 void ServerView::SetSurfaceId(cc::SurfaceId surface_id) { | 232 void ServerView::SetSurfaceId(cc::SurfaceId surface_id) { |
216 surface_id_ = surface_id; | 233 surface_id_ = surface_id; |
217 delegate_->OnScheduleViewPaint(this); | 234 delegate_->OnScheduleViewPaint(this); |
218 } | 235 } |
219 | 236 |
237 void ServerView::SubmitCompositorFrame( | |
238 mojo::CompositorFramePtr frame, | |
239 const SubmitCompositorFrameCallback& callback) { | |
240 gfx::Size frame_size = frame->passes[0]->output_rect.To<gfx::Rect>().size(); | |
241 //delegate_->SubmitCompositorFrame(this, frame.Pass(), callback); | |
sky
2015/08/26 22:58:03
?
Fady Samuel
2015/08/26 23:51:00
Moving some code around and missed this. Deleted.
| |
242 // Create Surfaces state on demand. | |
243 if (!surface_factory_) { | |
244 surface_factory_.reset( | |
245 new cc::SurfaceFactory(delegate_->GetSurfacesState()->manager(), this)); | |
246 } | |
247 if (!surface_id_allocator_) { | |
248 surface_id_allocator_.reset( | |
249 new cc::SurfaceIdAllocator( | |
250 delegate_->GetSurfacesState()->next_id_namespace())); | |
251 } | |
252 if (surface_id().is_null()) { | |
253 // Create a Surface ID for the first time for this view. | |
254 cc::SurfaceId surface_id(surface_id_allocator_->GenerateId()); | |
255 surface_factory_->Create(surface_id); | |
256 SetSurfaceId(surface_id); | |
257 } else { | |
258 // If the size of the CompostiorFrame has changed then destroy the existing | |
259 // Surface and create a new one of the appropriate size. | |
260 gfx::Size frame_size = | |
sky
2015/08/26 22:58:03
Don't you hvae this defined on 240 already?
Fady Samuel
2015/08/26 23:51:00
Removed
| |
261 frame->passes[0]->output_rect.To<gfx::Rect>().size(); | |
262 if (frame_size != last_submitted_frame_size()) { | |
263 surface_factory_->Destroy(surface_id()); | |
264 cc::SurfaceId surface_id(surface_id_allocator_->GenerateId()); | |
265 surface_factory_->Create(surface_id); | |
266 SetSurfaceId(surface_id); | |
267 } | |
268 } | |
269 surface_factory_->SubmitCompositorFrame( | |
270 surface_id(), | |
271 frame.To<scoped_ptr<cc::CompositorFrame>>(), | |
272 base::Bind(&CallCallback, callback)); | |
273 delegate_->GetSurfacesState()->scheduler()->SetNeedsDraw(); | |
274 last_submitted_frame_size_ = frame_size; | |
sky
2015/08/26 22:58:03
This is only needed @ 266 and 256ish, right?
Fady Samuel
2015/08/26 23:51:00
Yes. We keep track of the last frame's size, so we
| |
275 } | |
276 | |
220 #if !defined(NDEBUG) | 277 #if !defined(NDEBUG) |
221 std::string ServerView::GetDebugWindowHierarchy() const { | 278 std::string ServerView::GetDebugWindowHierarchy() const { |
222 std::string result; | 279 std::string result; |
223 BuildDebugInfo(std::string(), &result); | 280 BuildDebugInfo(std::string(), &result); |
224 return result; | 281 return result; |
225 } | 282 } |
226 | 283 |
227 void ServerView::BuildDebugInfo(const std::string& depth, | 284 void ServerView::BuildDebugInfo(const std::string& depth, |
228 std::string* result) const { | 285 std::string* result) const { |
229 *result += base::StringPrintf( | 286 *result += base::StringPrintf( |
230 "%sid=%d,%d visible=%s bounds=%d,%d %dx%d surface_id=%" PRIu64 "\n", | 287 "%sid=%d,%d visible=%s bounds=%d,%d %dx%d surface_id=%" PRIu64 "\n", |
231 depth.c_str(), static_cast<int>(id_.connection_id), | 288 depth.c_str(), static_cast<int>(id_.connection_id), |
232 static_cast<int>(id_.view_id), visible_ ? "true" : "false", bounds_.x(), | 289 static_cast<int>(id_.view_id), visible_ ? "true" : "false", bounds_.x(), |
233 bounds_.y(), bounds_.width(), bounds_.height(), surface_id_.id); | 290 bounds_.y(), bounds_.width(), bounds_.height(), surface_id_.id); |
234 for (const ServerView* child : children_) | 291 for (const ServerView* child : children_) |
235 child->BuildDebugInfo(depth + " ", result); | 292 child->BuildDebugInfo(depth + " ", result); |
236 } | 293 } |
237 #endif | 294 #endif |
238 | 295 |
296 void ServerView::ReturnResources( | |
297 const cc::ReturnedResourceArray& resources) { | |
298 client_->ReturnResources( | |
299 mojo::Array<mojo::ReturnedResourcePtr>::From(resources)); | |
300 } | |
301 | |
239 void ServerView::RemoveImpl(ServerView* view) { | 302 void ServerView::RemoveImpl(ServerView* view) { |
240 view->parent_ = NULL; | 303 view->parent_ = NULL; |
241 children_.erase(std::find(children_.begin(), children_.end(), view)); | 304 children_.erase(std::find(children_.begin(), children_.end(), view)); |
242 } | 305 } |
243 | 306 |
244 } // namespace view_manager | 307 } // namespace view_manager |
OLD | NEW |