blob: 7cedbc20f703d9aa998e22effe5ca91c0a4cc063 [file] [log] [blame]
[email protected]3b31c6ac2012-12-06 21:27:291// Copyright 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/layer_tree_impl.h"
[email protected]3b31c6ac2012-12-06 21:27:296
[email protected]76ffd9e2012-12-20 19:12:477#include "base/debug/trace_event.h"
[email protected]95e4e1a02013-03-18 07:09:098#include "cc/animation/animation.h"
9#include "cc/animation/animation_id_provider.h"
10#include "cc/animation/keyframed_animation_curve.h"
11#include "cc/animation/scrollbar_animation_controller.h"
[email protected]c60279472013-01-30 12:10:5112#include "cc/heads_up_display_layer_impl.h"
[email protected]b7c4783f2013-03-15 23:11:4213#include "cc/layer.h"
[email protected]b7c4783f2013-03-15 23:11:4214#include "cc/pinch_zoom_scrollbar.h"
[email protected]ffb2720f2013-03-15 19:18:3715#include "cc/scrollbar_layer_impl.h"
[email protected]556fd292013-03-18 08:03:0416#include "cc/trees/layer_tree_host_common.h"
17#include "cc/trees/layer_tree_host_impl.h"
[email protected]ffb2720f2013-03-15 19:18:3718#include "ui/gfx/size_conversions.h"
[email protected]caa567d2012-12-20 07:56:1619#include "ui/gfx/vector2d_conversions.h"
[email protected]3b31c6ac2012-12-06 21:27:2920
21namespace cc {
22
[email protected]8bef40572012-12-11 21:38:0823LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
[email protected]db8259f2013-02-01 05:25:0424 : layer_tree_host_impl_(layer_tree_host_impl),
25 source_frame_number_(-1),
26 hud_layer_(0),
27 root_scroll_layer_(0),
28 currently_scrolling_layer_(0),
29 background_color_(0),
30 has_transparent_background_(false),
[email protected]b7c4783f2013-03-15 23:11:4231 pinch_zoom_scrollbar_horizontal_layer_id_(Layer::INVALID_ID),
32 pinch_zoom_scrollbar_vertical_layer_id_(Layer::INVALID_ID),
[email protected]db8259f2013-02-01 05:25:0433 page_scale_factor_(1),
34 page_scale_delta_(1),
35 sent_page_scale_delta_(1),
36 min_page_scale_factor_(0),
37 max_page_scale_factor_(0),
38 scrolling_layer_id_from_previous_tree_(0),
39 contents_textures_purged_(false),
[email protected]318822852013-02-14 00:54:2740 viewport_size_invalid_(false),
[email protected]db8259f2013-02-01 05:25:0441 needs_update_draw_properties_(true),
42 needs_full_tree_sync_(true) {
[email protected]3b31c6ac2012-12-06 21:27:2943}
44
45LayerTreeImpl::~LayerTreeImpl() {
[email protected]361bc00d2012-12-14 07:03:2446 // Need to explicitly clear the tree prior to destroying this so that
47 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
48 root_layer_.reset();
[email protected]3b31c6ac2012-12-06 21:27:2949}
50
[email protected]3c0a3252013-03-18 04:24:3651static LayerImpl* FindRootScrollLayerRecursive(LayerImpl* layer) {
52 if (!layer)
53 return NULL;
[email protected]3b31c6ac2012-12-06 21:27:2954
[email protected]3c0a3252013-03-18 04:24:3655 if (layer->scrollable())
56 return layer;
[email protected]3b31c6ac2012-12-06 21:27:2957
[email protected]3c0a3252013-03-18 04:24:3658 for (size_t i = 0; i < layer->children().size(); ++i) {
59 LayerImpl* found = FindRootScrollLayerRecursive(layer->children()[i]);
60 if (found)
61 return found;
62 }
[email protected]3b31c6ac2012-12-06 21:27:2963
[email protected]3c0a3252013-03-18 04:24:3664 return NULL;
[email protected]3b31c6ac2012-12-06 21:27:2965}
66
67void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
68 root_layer_ = layer.Pass();
[email protected]5c4824e12013-01-12 16:34:5369 root_scroll_layer_ = NULL;
70 currently_scrolling_layer_ = NULL;
71
[email protected]c1bb5af2013-03-13 19:06:2772 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]5c4824e12013-01-12 16:34:5373}
74
75void LayerTreeImpl::FindRootScrollLayer() {
[email protected]3c0a3252013-03-18 04:24:3676 root_scroll_layer_ = FindRootScrollLayerRecursive(root_layer_.get());
[email protected]3b31c6ac2012-12-06 21:27:2977
78 if (root_layer_ && scrolling_layer_id_from_previous_tree_) {
79 currently_scrolling_layer_ = LayerTreeHostCommon::findLayerInSubtree(
80 root_layer_.get(),
81 scrolling_layer_id_from_previous_tree_);
82 }
83
84 scrolling_layer_id_from_previous_tree_ = 0;
[email protected]3b31c6ac2012-12-06 21:27:2985}
86
87scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
88 // Clear all data structures that have direct references to the layer tree.
89 scrolling_layer_id_from_previous_tree_ =
90 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]69b50ec2013-01-19 04:58:0191 root_scroll_layer_ = NULL;
[email protected]3b31c6ac2012-12-06 21:27:2992 currently_scrolling_layer_ = NULL;
93
[email protected]76ffd9e2012-12-20 19:12:4794 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:1695 set_needs_update_draw_properties();
[email protected]3b31c6ac2012-12-06 21:27:2996 return root_layer_.Pass();
97}
98
[email protected]7aba6662013-03-12 10:17:3499void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
[email protected]c60279472013-01-30 12:10:51100 target_tree->SetPageScaleFactorAndLimits(
101 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor());
102 target_tree->SetPageScaleDelta(
103 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta());
104 target_tree->set_sent_page_scale_delta(1);
105
106 // This should match the property synchronization in
107 // LayerTreeHost::finishCommitOnImplThread().
108 target_tree->set_source_frame_number(source_frame_number());
109 target_tree->set_background_color(background_color());
110 target_tree->set_has_transparent_background(has_transparent_background());
111
112 if (ContentsTexturesPurged())
113 target_tree->SetContentsTexturesPurged();
114 else
115 target_tree->ResetContentsTexturesPurged();
116
[email protected]318822852013-02-14 00:54:27117 if (ViewportSizeInvalid())
118 target_tree->SetViewportSizeInvalid();
119 else
120 target_tree->ResetViewportSizeInvalid();
121
[email protected]c60279472013-01-30 12:10:51122 if (hud_layer())
123 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
124 LayerTreeHostCommon::findLayerInSubtree(
[email protected]c1bb5af2013-03-13 19:06:27125 target_tree->root_layer(), hud_layer()->id())));
[email protected]c60279472013-01-30 12:10:51126 else
127 target_tree->set_hud_layer(NULL);
[email protected]b7c4783f2013-03-15 23:11:42128
129 target_tree->SetPinchZoomHorizontalLayerId(
130 pinch_zoom_scrollbar_horizontal_layer_id_);
131 target_tree->SetPinchZoomVerticalLayerId(
132 pinch_zoom_scrollbar_vertical_layer_id_);
[email protected]c60279472013-01-30 12:10:51133}
134
[email protected]ffb2720f2013-03-15 19:18:37135LayerImpl* LayerTreeImpl::RootScrollLayer() const {
[email protected]69b50ec2013-01-19 04:58:01136 DCHECK(IsActiveTree());
137 return root_scroll_layer_;
138}
139
[email protected]ffb2720f2013-03-15 19:18:37140LayerImpl* LayerTreeImpl::RootClipLayer() const {
141 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL;
142}
143
144LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
[email protected]69b50ec2013-01-19 04:58:01145 DCHECK(IsActiveTree());
146 return currently_scrolling_layer_;
147}
148
[email protected]0fc818e2013-03-18 06:45:20149void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
150 if (currently_scrolling_layer_ == layer)
151 return;
152
153 if (currently_scrolling_layer_ &&
154 currently_scrolling_layer_->scrollbar_animation_controller())
155 currently_scrolling_layer_->scrollbar_animation_controller()
156 ->didScrollGestureEnd(base::TimeTicks::Now());
157 currently_scrolling_layer_ = layer;
158 if (layer && layer->scrollbar_animation_controller())
159 layer->scrollbar_animation_controller()->didScrollGestureBegin();
160}
161
[email protected]3b31c6ac2012-12-06 21:27:29162void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
[email protected]0fc818e2013-03-18 06:45:20163 SetCurrentlyScrollingLayer(NULL);
[email protected]3b31c6ac2012-12-06 21:27:29164 scrolling_layer_id_from_previous_tree_ = 0;
165}
166
[email protected]c60279472013-01-30 12:10:51167void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
[email protected]3c0a3252013-03-18 04:24:36168 float min_page_scale_factor, float max_page_scale_factor) {
[email protected]c60279472013-01-30 12:10:51169 if (!page_scale_factor)
170 return;
171
172 min_page_scale_factor_ = min_page_scale_factor;
173 max_page_scale_factor_ = max_page_scale_factor;
174 page_scale_factor_ = page_scale_factor;
175}
176
[email protected]3c0a3252013-03-18 04:24:36177void LayerTreeImpl::SetPageScaleDelta(float delta) {
[email protected]c60279472013-01-30 12:10:51178 // Clamp to the current min/max limits.
179 float total = page_scale_factor_ * delta;
180 if (min_page_scale_factor_ && total < min_page_scale_factor_)
181 delta = min_page_scale_factor_ / page_scale_factor_;
182 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
183 delta = max_page_scale_factor_ / page_scale_factor_;
184
185 if (delta == page_scale_delta_)
186 return;
187
188 page_scale_delta_ = delta;
189
190 if (IsActiveTree()) {
[email protected]c1bb5af2013-03-13 19:06:27191 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
[email protected]c60279472013-01-30 12:10:51192 if (pending_tree) {
193 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
194 pending_tree->SetPageScaleDelta(page_scale_delta_ / sent_page_scale_delta_);
195 }
196 }
197
198 UpdateMaxScrollOffset();
199 set_needs_update_draw_properties();
200}
201
[email protected]257abfa82013-01-29 23:47:24202gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]ffb2720f2013-03-15 19:18:37203 return gfx::ScaleSize(layer_tree_host_impl_->VisibleViewportSize(),
204 1.0f / total_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24205}
206
[email protected]caa567d2012-12-20 07:56:16207void LayerTreeImpl::UpdateMaxScrollOffset() {
[email protected]69b50ec2013-01-19 04:58:01208 if (!root_scroll_layer_ || !root_scroll_layer_->children().size())
[email protected]caa567d2012-12-20 07:56:16209 return;
210
[email protected]42ccdbef2013-01-21 07:54:54211 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() -
[email protected]257abfa82013-01-29 23:47:24212 gfx::RectF(ScrollableViewportSize()).bottom_right();
[email protected]caa567d2012-12-20 07:56:16213
214 // The viewport may be larger than the contents in some cases, such as
215 // having a vertical scrollbar but no horizontal overflow.
216 max_scroll.ClampToMin(gfx::Vector2dF());
217
[email protected]7aba6662013-03-12 10:17:34218 root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
[email protected]caa567d2012-12-20 07:56:16219}
220
[email protected]c60279472013-01-30 12:10:51221gfx::Transform LayerTreeImpl::ImplTransform() const {
222 gfx::Transform transform;
[email protected]c2d0c5a2013-02-26 04:43:36223 transform.Scale(total_page_scale_factor(), total_page_scale_factor());
[email protected]c60279472013-01-30 12:10:51224 return transform;
225}
226
[email protected]ffb2720f2013-03-15 19:18:37227void LayerTreeImpl::UpdateSolidColorScrollbars() {
228 DCHECK(settings().solidColorScrollbars);
229
230 LayerImpl* root_scroll = RootScrollLayer();
231 if (!root_scroll)
232 return;
233
234 if (!IsActiveTree())
235 return;
236
237 gfx::RectF scrollable_viewport(
238 gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()),
239 ScrollableViewportSize());
240 float vertical_adjust = 0.0f;
241 if (RootClipLayer())
242 vertical_adjust = layer_tree_host_impl_->VisibleViewportSize().height() -
243 RootClipLayer()->bounds().height();
244 if (ScrollbarLayerImpl* horiz = root_scroll->horizontal_scrollbar_layer()) {
245 horiz->set_vertical_adjust(vertical_adjust);
246 horiz->SetViewportWithinScrollableArea(scrollable_viewport,
247 ScrollableSize());
248 }
249 if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) {
250 vertical->set_vertical_adjust(vertical_adjust);
251 vertical->SetViewportWithinScrollableArea(scrollable_viewport,
252 ScrollableSize());
253 }
254}
255
[email protected]4c9bb952013-01-27 05:41:18256struct UpdateTilePrioritiesForLayer {
257 void operator()(LayerImpl *layer) {
[email protected]7aba6662013-03-12 10:17:34258 layer->UpdateTilePriorities();
[email protected]4c9bb952013-01-27 05:41:18259 }
260};
261
262void LayerTreeImpl::UpdateDrawProperties(UpdateDrawPropertiesReason reason) {
[email protected]ffb2720f2013-03-15 19:18:37263 if (settings().solidColorScrollbars && IsActiveTree()) {
264 UpdateSolidColorScrollbars();
265
266 // The top controls manager is incompatible with the WebKit-created cliprect
267 // because it can bring into view a larger amount of content when it
268 // hides. It's safe to deactivate the clip rect if no non-overlay scrollbars
269 // are present.
270 if (layer_tree_host_impl_->top_controls_manager())
271 RootScrollLayer()->parent()->SetMasksToBounds(false);
272 }
273
[email protected]4c9bb952013-01-27 05:41:18274 if (!needs_update_draw_properties_) {
[email protected]c1bb5af2013-03-13 19:06:27275 if (reason == UPDATE_ACTIVE_TREE_FOR_DRAW && root_layer())
[email protected]4c9bb952013-01-27 05:41:18276 LayerTreeHostCommon::callFunctionForSubtree<UpdateTilePrioritiesForLayer>(
[email protected]c1bb5af2013-03-13 19:06:27277 root_layer());
[email protected]615c78a2013-01-24 23:44:16278 return;
[email protected]4c9bb952013-01-27 05:41:18279 }
[email protected]615c78a2013-01-24 23:44:16280
281 needs_update_draw_properties_ = false;
[email protected]76ffd9e2012-12-20 19:12:47282 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16283
284 // For maxTextureSize.
285 if (!layer_tree_host_impl_->renderer())
286 return;
287
[email protected]c1bb5af2013-03-13 19:06:27288 if (!root_layer())
[email protected]76ffd9e2012-12-20 19:12:47289 return;
290
[email protected]69b50ec2013-01-19 04:58:01291 if (root_scroll_layer_) {
[email protected]7aba6662013-03-12 10:17:34292 root_scroll_layer_->SetImplTransform(ImplTransform());
[email protected]615c78a2013-01-24 23:44:16293 // Setting the impl transform re-sets this.
294 needs_update_draw_properties_ = false;
[email protected]76ffd9e2012-12-20 19:12:47295 }
296
297 {
[email protected]c1bb5af2013-03-13 19:06:27298 TRACE_EVENT1("cc",
299 "LayerTreeImpl::UpdateDrawProperties",
300 "IsActive",
301 IsActiveTree());
[email protected]4c9bb952013-01-27 05:41:18302 bool update_tile_priorities =
303 reason == UPDATE_PENDING_TREE ||
304 reason == UPDATE_ACTIVE_TREE_FOR_DRAW;
[email protected]76ffd9e2012-12-20 19:12:47305 LayerTreeHostCommon::calculateDrawProperties(
[email protected]c1bb5af2013-03-13 19:06:27306 root_layer(),
[email protected]76ffd9e2012-12-20 19:12:47307 device_viewport_size(),
308 device_scale_factor(),
[email protected]c60279472013-01-30 12:10:51309 total_page_scale_factor(),
[email protected]f6776532012-12-21 20:24:33310 MaxTextureSize(),
[email protected]76ffd9e2012-12-20 19:12:47311 settings().canUseLCDText,
[email protected]4c9bb952013-01-27 05:41:18312 render_surface_layer_list_,
313 update_tile_priorities);
[email protected]76ffd9e2012-12-20 19:12:47314 }
[email protected]615c78a2013-01-24 23:44:16315
316 DCHECK(!needs_update_draw_properties_) <<
317 "calcDrawProperties should not set_needs_update_draw_properties()";
[email protected]76ffd9e2012-12-20 19:12:47318}
319
[email protected]3c0a3252013-03-18 04:24:36320static void ClearRenderSurfacesOnLayerImplRecursive(LayerImpl* current) {
321 DCHECK(current);
322 for (size_t i = 0; i < current->children().size(); ++i)
323 ClearRenderSurfacesOnLayerImplRecursive(current->children()[i]);
324 current->ClearRenderSurface();
[email protected]76ffd9e2012-12-20 19:12:47325}
326
327void LayerTreeImpl::ClearRenderSurfaces() {
[email protected]c1bb5af2013-03-13 19:06:27328 ClearRenderSurfacesOnLayerImplRecursive(root_layer());
[email protected]76ffd9e2012-12-20 19:12:47329 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16330 set_needs_update_draw_properties();
[email protected]76ffd9e2012-12-20 19:12:47331}
332
[email protected]b0a917c8d2013-01-12 17:42:25333bool LayerTreeImpl::AreVisibleResourcesReady() const {
334 TRACE_EVENT0("cc", "LayerTreeImpl::AreVisibleResourcesReady");
335
336 typedef LayerIterator<LayerImpl,
337 std::vector<LayerImpl*>,
338 RenderSurfaceImpl,
339 LayerIteratorActions::BackToFront> LayerIteratorType;
340 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_);
341 for (LayerIteratorType it = LayerIteratorType::begin(
342 &render_surface_layer_list_); it != end; ++it) {
[email protected]7aba6662013-03-12 10:17:34343 if (it.representsItself() && !(*it)->AreVisibleResourcesReady())
[email protected]b0a917c8d2013-01-12 17:42:25344 return false;
345 }
346
347 return true;
348}
349
[email protected]76ffd9e2012-12-20 19:12:47350const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const {
351 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16352 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47353 return render_surface_layer_list_;
354}
355
[email protected]42ccdbef2013-01-21 07:54:54356gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]c4d467a2013-01-21 03:21:01357 if (!root_scroll_layer_ || root_scroll_layer_->children().empty())
[email protected]caa567d2012-12-20 07:56:16358 return gfx::Size();
[email protected]c4d467a2013-01-21 03:21:01359 return root_scroll_layer_->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16360}
361
[email protected]361bc00d2012-12-14 07:03:24362LayerImpl* LayerTreeImpl::LayerById(int id) {
363 LayerIdMap::iterator iter = layer_id_map_.find(id);
364 return iter != layer_id_map_.end() ? iter->second : NULL;
365}
366
367void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
368 DCHECK(!LayerById(layer->id()));
369 layer_id_map_[layer->id()] = layer;
370}
371
372void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
373 DCHECK(LayerById(layer->id()));
374 layer_id_map_.erase(layer->id());
375}
376
[email protected]1e0f8d62013-01-09 07:41:35377void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pendingTree) {
378 int id = currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]0fc818e2013-03-18 06:45:20379 pendingTree->SetCurrentlyScrollingLayer(
[email protected]c1bb5af2013-03-13 19:06:27380 LayerTreeHostCommon::findLayerInSubtree(pendingTree->root_layer(), id));
[email protected]1e0f8d62013-01-09 07:41:35381}
382
[email protected]37386f052013-01-13 00:42:22383static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34384 layer->DidBecomeActive();
[email protected]37386f052013-01-13 00:42:22385 for (size_t i = 0; i < layer->children().size(); ++i)
386 DidBecomeActiveRecursive(layer->children()[i]);
387}
388
389void LayerTreeImpl::DidBecomeActive() {
[email protected]c1bb5af2013-03-13 19:06:27390 if (root_layer())
391 DidBecomeActiveRecursive(root_layer());
[email protected]69b50ec2013-01-19 04:58:01392 FindRootScrollLayer();
393 UpdateMaxScrollOffset();
[email protected]b7c4783f2013-03-15 23:11:42394 // Main thread scrolls do not get handled in LayerTreeHostImpl, so after
395 // each commit (and after the root scroll layer has its max scroll offset
396 // set), we need to update pinch zoom scrollbars.
397 UpdatePinchZoomScrollbars();
[email protected]37386f052013-01-13 00:42:22398}
399
[email protected]6f90b9e2013-01-17 23:42:00400bool LayerTreeImpl::ContentsTexturesPurged() const {
401 return contents_textures_purged_;
402}
403
404void LayerTreeImpl::SetContentsTexturesPurged() {
405 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27406 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00407}
408
409void LayerTreeImpl::ResetContentsTexturesPurged() {
410 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27411 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00412}
413
[email protected]318822852013-02-14 00:54:27414bool LayerTreeImpl::ViewportSizeInvalid() const {
415 return viewport_size_invalid_;
416}
417
418void LayerTreeImpl::SetViewportSizeInvalid() {
419 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27420 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27421}
422
423void LayerTreeImpl::ResetViewportSizeInvalid() {
424 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27425 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27426}
427
[email protected]48871fc2013-01-23 07:36:51428Proxy* LayerTreeImpl::proxy() const {
429 return layer_tree_host_impl_->proxy();
430}
431
[email protected]ff762fb2012-12-12 19:18:37432const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27433 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37434}
435
[email protected]bf5b3a02013-02-13 02:02:52436const RendererCapabilities& LayerTreeImpl::rendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27437 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52438}
439
[email protected]ff762fb2012-12-12 19:18:37440OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27441 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37442}
443
444ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27445 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37446}
447
448TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27449 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37450}
451
452FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27453 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37454}
455
[email protected]71691c22013-01-18 03:14:22456PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27457 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22458}
459
[email protected]1191d9d2013-02-02 06:00:33460MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27461 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33462}
463
[email protected]f117a4c2012-12-16 04:53:10464bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27465 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10466}
467
468bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27469 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10470}
471
[email protected]48871fc2013-01-23 07:36:51472bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27473 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51474}
475
[email protected]f117a4c2012-12-16 04:53:10476LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27477 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10478 if (!tree)
479 return NULL;
480 return tree->LayerById(id);
481}
482
483LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27484 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10485 if (!tree)
486 return NULL;
487 return tree->LayerById(id);
488}
489
[email protected]f6776532012-12-21 20:24:33490int LayerTreeImpl::MaxTextureSize() const {
[email protected]c1bb5af2013-03-13 19:06:27491 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size;
[email protected]f6776532012-12-21 20:24:33492}
493
[email protected]166db5c82013-01-09 23:54:31494bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27495 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31496}
497
[email protected]829ad972013-01-28 23:36:10498base::TimeTicks LayerTreeImpl::CurrentFrameTime() const {
[email protected]c1bb5af2013-03-13 19:06:27499 return layer_tree_host_impl_->CurrentFrameTime();
[email protected]829ad972013-01-28 23:36:10500}
501
[email protected]ff762fb2012-12-12 19:18:37502void LayerTreeImpl::SetNeedsRedraw() {
503 layer_tree_host_impl_->setNeedsRedraw();
504}
505
[email protected]ff762fb2012-12-12 19:18:37506const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27507 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37508}
509
510float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27511 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37512}
513
[email protected]90ec9872013-03-08 02:28:18514gfx::Size LayerTreeImpl::device_viewport_size() const {
[email protected]c1bb5af2013-03-13 19:06:27515 return layer_tree_host_impl_->device_viewport_size();
[email protected]ff762fb2012-12-12 19:18:37516}
517
[email protected]c1bb5af2013-03-13 19:06:27518gfx::Size LayerTreeImpl::layout_viewport_size() const {
519 return layer_tree_host_impl_->layout_viewport_size();
[email protected]ff762fb2012-12-12 19:18:37520}
521
522std::string LayerTreeImpl::layer_tree_as_text() const {
[email protected]c1bb5af2013-03-13 19:06:27523 return layer_tree_host_impl_->LayerTreeAsText();
[email protected]ff762fb2012-12-12 19:18:37524}
525
526DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27527 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37528}
529
[email protected]de4afb5e2012-12-20 00:11:34530AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27531 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34532}
[email protected]ff762fb2012-12-12 19:18:37533
[email protected]8c5690222013-02-15 17:36:43534scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
535 scoped_ptr<base::ListValue> state(new base::ListValue());
536 typedef LayerIterator<LayerImpl,
537 std::vector<LayerImpl*>,
538 RenderSurfaceImpl,
539 LayerIteratorActions::BackToFront> LayerIteratorType;
540 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_);
541 for (LayerIteratorType it = LayerIteratorType::begin(
542 &render_surface_layer_list_); it != end; ++it) {
543 if (!it.representsItself())
544 continue;
545 state->Append((*it)->AsValue().release());
546 }
547 return state.PassAs<base::Value>();
548}
549
[email protected]b7c4783f2013-03-15 23:11:42550void LayerTreeImpl::DidBeginScroll() {
551 if (HasPinchZoomScrollbars())
552 FadeInPinchZoomScrollbars();
553}
554
555void LayerTreeImpl::DidUpdateScroll() {
556 if (HasPinchZoomScrollbars())
557 UpdatePinchZoomScrollbars();
558}
559
560void LayerTreeImpl::DidEndScroll() {
561 if (HasPinchZoomScrollbars())
562 FadeOutPinchZoomScrollbars();
563}
564
565void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) {
566 pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id;
567}
568
569ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() {
570 return static_cast<ScrollbarLayerImpl*>(LayerById(
571 pinch_zoom_scrollbar_horizontal_layer_id_));
572}
573
574void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) {
575 pinch_zoom_scrollbar_vertical_layer_id_ = layer_id;
576}
577
578ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() {
579 return static_cast<ScrollbarLayerImpl*>(LayerById(
580 pinch_zoom_scrollbar_vertical_layer_id_));
581}
582
583void LayerTreeImpl::UpdatePinchZoomScrollbars() {
584 LayerImpl* root_scroll_layer = RootScrollLayer();
585 if (!root_scroll_layer)
586 return;
587
588 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) {
589 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x());
590 scrollbar->SetTotalSize(root_scroll_layer->bounds().width());
591 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x());
592 }
593 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) {
594 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y());
595 scrollbar->SetTotalSize(root_scroll_layer->bounds().height());
596 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().y());
597 }
598}
599
600static scoped_ptr<Animation> MakePinchZoomFadeAnimation(
601 float start_opacity, float end_opacity) {
602 scoped_ptr<KeyframedFloatAnimationCurve> curve =
603 KeyframedFloatAnimationCurve::Create();
604 curve->AddKeyframe(FloatKeyframe::Create(
605 0, start_opacity, EaseInTimingFunction::create()));
606 curve->AddKeyframe(FloatKeyframe::Create(
607 PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity,
608 EaseInTimingFunction::create()));
609
610 scoped_ptr<Animation> animation = Animation::Create(
611 curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(),
612 0, Animation::Opacity);
613 animation->set_is_impl_only(true);
614
615 return animation.Pass();
616}
617
618static void StartFadeInAnimation(ScrollbarLayerImpl* layer) {
619 DCHECK(layer);
620 float start_opacity = layer->opacity();
621 LayerAnimationController* controller = layer->layer_animation_controller();
622 // TODO() It shouldn't be necessary to manually remove the old animation.
623 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
624 controller->RemoveAnimation(animation->id());
625 controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity,
626 PinchZoomScrollbar::kDefaultOpacity));
627}
628
629void LayerTreeImpl::FadeInPinchZoomScrollbars() {
630 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1)
631 return;
632
633 StartFadeInAnimation(PinchZoomScrollbarHorizontal());
634 StartFadeInAnimation(PinchZoomScrollbarVertical());
635}
636
637static void StartFadeOutAnimation(LayerImpl* layer) {
638 float opacity = layer->opacity();
639 if (!opacity)
640 return;
641
642 LayerAnimationController* controller = layer->layer_animation_controller();
643 // TODO(wjmaclean) It shouldn't be necessary to manually remove the old
644 // animation.
645 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
646 controller->RemoveAnimation(animation->id());
647 controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0));
648}
649
650void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
651 if (!HasPinchZoomScrollbars())
652 return;
653
654 StartFadeOutAnimation(PinchZoomScrollbarHorizontal());
655 StartFadeOutAnimation(PinchZoomScrollbarVertical());
656}
657
658bool LayerTreeImpl::HasPinchZoomScrollbars() const {
659 return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID &&
660 pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID;
661}
662
663
[email protected]3b31c6ac2012-12-06 21:27:29664} // namespace cc