blob: 84436d450ab4dcb21219ea92a36f925191db676d [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
5#include "cc/layer_tree_impl.h"
6
[email protected]76ffd9e2012-12-20 19:12:477#include "base/debug/trace_event.h"
[email protected]b7c4783f2013-03-15 23:11:428#include "cc/animation.h"
9#include "cc/animation_id_provider.h"
[email protected]c60279472013-01-30 12:10:5110#include "cc/heads_up_display_layer_impl.h"
[email protected]b7c4783f2013-03-15 23:11:4211#include "cc/keyframed_animation_curve.h"
12#include "cc/layer.h"
[email protected]3b31c6ac2012-12-06 21:27:2913#include "cc/layer_tree_host_common.h"
14#include "cc/layer_tree_host_impl.h"
[email protected]b7c4783f2013-03-15 23:11:4215#include "cc/pinch_zoom_scrollbar.h"
[email protected]ffb2720f2013-03-15 19:18:3716#include "cc/scrollbar_layer_impl.h"
17#include "ui/gfx/size_conversions.h"
[email protected]caa567d2012-12-20 07:56:1618#include "ui/gfx/vector2d_conversions.h"
[email protected]3b31c6ac2012-12-06 21:27:2919
20namespace cc {
21
[email protected]8bef40572012-12-11 21:38:0822LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
[email protected]db8259f2013-02-01 05:25:0423 : layer_tree_host_impl_(layer_tree_host_impl),
24 source_frame_number_(-1),
25 hud_layer_(0),
26 root_scroll_layer_(0),
27 currently_scrolling_layer_(0),
28 background_color_(0),
29 has_transparent_background_(false),
[email protected]b7c4783f2013-03-15 23:11:4230 pinch_zoom_scrollbar_horizontal_layer_id_(Layer::INVALID_ID),
31 pinch_zoom_scrollbar_vertical_layer_id_(Layer::INVALID_ID),
[email protected]db8259f2013-02-01 05:25:0432 page_scale_factor_(1),
33 page_scale_delta_(1),
34 sent_page_scale_delta_(1),
35 min_page_scale_factor_(0),
36 max_page_scale_factor_(0),
37 scrolling_layer_id_from_previous_tree_(0),
38 contents_textures_purged_(false),
[email protected]318822852013-02-14 00:54:2739 viewport_size_invalid_(false),
[email protected]db8259f2013-02-01 05:25:0440 needs_update_draw_properties_(true),
41 needs_full_tree_sync_(true) {
[email protected]3b31c6ac2012-12-06 21:27:2942}
43
44LayerTreeImpl::~LayerTreeImpl() {
[email protected]361bc00d2012-12-14 07:03:2445 // Need to explicitly clear the tree prior to destroying this so that
46 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
47 root_layer_.reset();
[email protected]3b31c6ac2012-12-06 21:27:2948}
49
50static LayerImpl* findRootScrollLayer(LayerImpl* layer)
51{
52 if (!layer)
53 return 0;
54
55 if (layer->scrollable())
56 return layer;
57
58 for (size_t i = 0; i < layer->children().size(); ++i) {
59 LayerImpl* found = findRootScrollLayer(layer->children()[i]);
60 if (found)
61 return found;
62 }
63
64 return 0;
65}
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]3b31c6ac2012-12-06 21:27:2976 root_scroll_layer_ = findRootScrollLayer(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]3b31c6ac2012-12-06 21:27:29149void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
150 currently_scrolling_layer_ = NULL;
151 scrolling_layer_id_from_previous_tree_ = 0;
152}
153
[email protected]c60279472013-01-30 12:10:51154void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
155 float min_page_scale_factor, float max_page_scale_factor)
156{
157 if (!page_scale_factor)
158 return;
159
160 min_page_scale_factor_ = min_page_scale_factor;
161 max_page_scale_factor_ = max_page_scale_factor;
162 page_scale_factor_ = page_scale_factor;
163}
164
165void LayerTreeImpl::SetPageScaleDelta(float delta)
166{
167 // Clamp to the current min/max limits.
168 float total = page_scale_factor_ * delta;
169 if (min_page_scale_factor_ && total < min_page_scale_factor_)
170 delta = min_page_scale_factor_ / page_scale_factor_;
171 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
172 delta = max_page_scale_factor_ / page_scale_factor_;
173
174 if (delta == page_scale_delta_)
175 return;
176
177 page_scale_delta_ = delta;
178
179 if (IsActiveTree()) {
[email protected]c1bb5af2013-03-13 19:06:27180 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
[email protected]c60279472013-01-30 12:10:51181 if (pending_tree) {
182 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
183 pending_tree->SetPageScaleDelta(page_scale_delta_ / sent_page_scale_delta_);
184 }
185 }
186
187 UpdateMaxScrollOffset();
188 set_needs_update_draw_properties();
189}
190
[email protected]257abfa82013-01-29 23:47:24191gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]ffb2720f2013-03-15 19:18:37192 return gfx::ScaleSize(layer_tree_host_impl_->VisibleViewportSize(),
193 1.0f / total_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24194}
195
[email protected]caa567d2012-12-20 07:56:16196void LayerTreeImpl::UpdateMaxScrollOffset() {
[email protected]69b50ec2013-01-19 04:58:01197 if (!root_scroll_layer_ || !root_scroll_layer_->children().size())
[email protected]caa567d2012-12-20 07:56:16198 return;
199
[email protected]42ccdbef2013-01-21 07:54:54200 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() -
[email protected]257abfa82013-01-29 23:47:24201 gfx::RectF(ScrollableViewportSize()).bottom_right();
[email protected]caa567d2012-12-20 07:56:16202
203 // The viewport may be larger than the contents in some cases, such as
204 // having a vertical scrollbar but no horizontal overflow.
205 max_scroll.ClampToMin(gfx::Vector2dF());
206
[email protected]7aba6662013-03-12 10:17:34207 root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
[email protected]caa567d2012-12-20 07:56:16208}
209
[email protected]c60279472013-01-30 12:10:51210gfx::Transform LayerTreeImpl::ImplTransform() const {
211 gfx::Transform transform;
[email protected]c2d0c5a2013-02-26 04:43:36212 transform.Scale(total_page_scale_factor(), total_page_scale_factor());
[email protected]c60279472013-01-30 12:10:51213 return transform;
214}
215
[email protected]ffb2720f2013-03-15 19:18:37216void LayerTreeImpl::UpdateSolidColorScrollbars() {
217 DCHECK(settings().solidColorScrollbars);
218
219 LayerImpl* root_scroll = RootScrollLayer();
220 if (!root_scroll)
221 return;
222
223 if (!IsActiveTree())
224 return;
225
226 gfx::RectF scrollable_viewport(
227 gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()),
228 ScrollableViewportSize());
229 float vertical_adjust = 0.0f;
230 if (RootClipLayer())
231 vertical_adjust = layer_tree_host_impl_->VisibleViewportSize().height() -
232 RootClipLayer()->bounds().height();
233 if (ScrollbarLayerImpl* horiz = root_scroll->horizontal_scrollbar_layer()) {
234 horiz->set_vertical_adjust(vertical_adjust);
235 horiz->SetViewportWithinScrollableArea(scrollable_viewport,
236 ScrollableSize());
237 }
238 if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) {
239 vertical->set_vertical_adjust(vertical_adjust);
240 vertical->SetViewportWithinScrollableArea(scrollable_viewport,
241 ScrollableSize());
242 }
243}
244
[email protected]4c9bb952013-01-27 05:41:18245struct UpdateTilePrioritiesForLayer {
246 void operator()(LayerImpl *layer) {
[email protected]7aba6662013-03-12 10:17:34247 layer->UpdateTilePriorities();
[email protected]4c9bb952013-01-27 05:41:18248 }
249};
250
251void LayerTreeImpl::UpdateDrawProperties(UpdateDrawPropertiesReason reason) {
[email protected]ffb2720f2013-03-15 19:18:37252 if (settings().solidColorScrollbars && IsActiveTree()) {
253 UpdateSolidColorScrollbars();
254
255 // The top controls manager is incompatible with the WebKit-created cliprect
256 // because it can bring into view a larger amount of content when it
257 // hides. It's safe to deactivate the clip rect if no non-overlay scrollbars
258 // are present.
259 if (layer_tree_host_impl_->top_controls_manager())
260 RootScrollLayer()->parent()->SetMasksToBounds(false);
261 }
262
[email protected]4c9bb952013-01-27 05:41:18263 if (!needs_update_draw_properties_) {
[email protected]c1bb5af2013-03-13 19:06:27264 if (reason == UPDATE_ACTIVE_TREE_FOR_DRAW && root_layer())
[email protected]4c9bb952013-01-27 05:41:18265 LayerTreeHostCommon::callFunctionForSubtree<UpdateTilePrioritiesForLayer>(
[email protected]c1bb5af2013-03-13 19:06:27266 root_layer());
[email protected]615c78a2013-01-24 23:44:16267 return;
[email protected]4c9bb952013-01-27 05:41:18268 }
[email protected]615c78a2013-01-24 23:44:16269
270 needs_update_draw_properties_ = false;
[email protected]76ffd9e2012-12-20 19:12:47271 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16272
273 // For maxTextureSize.
274 if (!layer_tree_host_impl_->renderer())
275 return;
276
[email protected]c1bb5af2013-03-13 19:06:27277 if (!root_layer())
[email protected]76ffd9e2012-12-20 19:12:47278 return;
279
[email protected]69b50ec2013-01-19 04:58:01280 if (root_scroll_layer_) {
[email protected]7aba6662013-03-12 10:17:34281 root_scroll_layer_->SetImplTransform(ImplTransform());
[email protected]615c78a2013-01-24 23:44:16282 // Setting the impl transform re-sets this.
283 needs_update_draw_properties_ = false;
[email protected]76ffd9e2012-12-20 19:12:47284 }
285
286 {
[email protected]c1bb5af2013-03-13 19:06:27287 TRACE_EVENT1("cc",
288 "LayerTreeImpl::UpdateDrawProperties",
289 "IsActive",
290 IsActiveTree());
[email protected]4c9bb952013-01-27 05:41:18291 bool update_tile_priorities =
292 reason == UPDATE_PENDING_TREE ||
293 reason == UPDATE_ACTIVE_TREE_FOR_DRAW;
[email protected]76ffd9e2012-12-20 19:12:47294 LayerTreeHostCommon::calculateDrawProperties(
[email protected]c1bb5af2013-03-13 19:06:27295 root_layer(),
[email protected]76ffd9e2012-12-20 19:12:47296 device_viewport_size(),
297 device_scale_factor(),
[email protected]c60279472013-01-30 12:10:51298 total_page_scale_factor(),
[email protected]f6776532012-12-21 20:24:33299 MaxTextureSize(),
[email protected]76ffd9e2012-12-20 19:12:47300 settings().canUseLCDText,
[email protected]4c9bb952013-01-27 05:41:18301 render_surface_layer_list_,
302 update_tile_priorities);
[email protected]76ffd9e2012-12-20 19:12:47303 }
[email protected]615c78a2013-01-24 23:44:16304
305 DCHECK(!needs_update_draw_properties_) <<
306 "calcDrawProperties should not set_needs_update_draw_properties()";
[email protected]76ffd9e2012-12-20 19:12:47307}
308
309static void ClearRenderSurfacesOnLayerImplRecursive(LayerImpl* current)
310{
311 DCHECK(current);
312 for (size_t i = 0; i < current->children().size(); ++i)
313 ClearRenderSurfacesOnLayerImplRecursive(current->children()[i]);
[email protected]7aba6662013-03-12 10:17:34314 current->ClearRenderSurface();
[email protected]76ffd9e2012-12-20 19:12:47315}
316
317void LayerTreeImpl::ClearRenderSurfaces() {
[email protected]c1bb5af2013-03-13 19:06:27318 ClearRenderSurfacesOnLayerImplRecursive(root_layer());
[email protected]76ffd9e2012-12-20 19:12:47319 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16320 set_needs_update_draw_properties();
[email protected]76ffd9e2012-12-20 19:12:47321}
322
[email protected]b0a917c8d2013-01-12 17:42:25323bool LayerTreeImpl::AreVisibleResourcesReady() const {
324 TRACE_EVENT0("cc", "LayerTreeImpl::AreVisibleResourcesReady");
325
326 typedef LayerIterator<LayerImpl,
327 std::vector<LayerImpl*>,
328 RenderSurfaceImpl,
329 LayerIteratorActions::BackToFront> LayerIteratorType;
330 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_);
331 for (LayerIteratorType it = LayerIteratorType::begin(
332 &render_surface_layer_list_); it != end; ++it) {
[email protected]7aba6662013-03-12 10:17:34333 if (it.representsItself() && !(*it)->AreVisibleResourcesReady())
[email protected]b0a917c8d2013-01-12 17:42:25334 return false;
335 }
336
337 return true;
338}
339
[email protected]76ffd9e2012-12-20 19:12:47340const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const {
341 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16342 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47343 return render_surface_layer_list_;
344}
345
[email protected]42ccdbef2013-01-21 07:54:54346gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]c4d467a2013-01-21 03:21:01347 if (!root_scroll_layer_ || root_scroll_layer_->children().empty())
[email protected]caa567d2012-12-20 07:56:16348 return gfx::Size();
[email protected]c4d467a2013-01-21 03:21:01349 return root_scroll_layer_->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16350}
351
[email protected]361bc00d2012-12-14 07:03:24352LayerImpl* LayerTreeImpl::LayerById(int id) {
353 LayerIdMap::iterator iter = layer_id_map_.find(id);
354 return iter != layer_id_map_.end() ? iter->second : NULL;
355}
356
357void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
358 DCHECK(!LayerById(layer->id()));
359 layer_id_map_[layer->id()] = layer;
360}
361
362void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
363 DCHECK(LayerById(layer->id()));
364 layer_id_map_.erase(layer->id());
365}
366
[email protected]1e0f8d62013-01-09 07:41:35367void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pendingTree) {
368 int id = currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
369 pendingTree->set_currently_scrolling_layer(
[email protected]c1bb5af2013-03-13 19:06:27370 LayerTreeHostCommon::findLayerInSubtree(pendingTree->root_layer(), id));
[email protected]1e0f8d62013-01-09 07:41:35371}
372
[email protected]37386f052013-01-13 00:42:22373static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34374 layer->DidBecomeActive();
[email protected]37386f052013-01-13 00:42:22375 for (size_t i = 0; i < layer->children().size(); ++i)
376 DidBecomeActiveRecursive(layer->children()[i]);
377}
378
379void LayerTreeImpl::DidBecomeActive() {
[email protected]c1bb5af2013-03-13 19:06:27380 if (root_layer())
381 DidBecomeActiveRecursive(root_layer());
[email protected]69b50ec2013-01-19 04:58:01382 FindRootScrollLayer();
383 UpdateMaxScrollOffset();
[email protected]b7c4783f2013-03-15 23:11:42384 // Main thread scrolls do not get handled in LayerTreeHostImpl, so after
385 // each commit (and after the root scroll layer has its max scroll offset
386 // set), we need to update pinch zoom scrollbars.
387 UpdatePinchZoomScrollbars();
[email protected]37386f052013-01-13 00:42:22388}
389
[email protected]6f90b9e2013-01-17 23:42:00390bool LayerTreeImpl::ContentsTexturesPurged() const {
391 return contents_textures_purged_;
392}
393
394void LayerTreeImpl::SetContentsTexturesPurged() {
395 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27396 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00397}
398
399void LayerTreeImpl::ResetContentsTexturesPurged() {
400 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27401 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00402}
403
[email protected]318822852013-02-14 00:54:27404bool LayerTreeImpl::ViewportSizeInvalid() const {
405 return viewport_size_invalid_;
406}
407
408void LayerTreeImpl::SetViewportSizeInvalid() {
409 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27410 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27411}
412
413void LayerTreeImpl::ResetViewportSizeInvalid() {
414 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27415 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27416}
417
[email protected]48871fc2013-01-23 07:36:51418Proxy* LayerTreeImpl::proxy() const {
419 return layer_tree_host_impl_->proxy();
420}
421
[email protected]ff762fb2012-12-12 19:18:37422const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27423 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37424}
425
[email protected]bf5b3a02013-02-13 02:02:52426const RendererCapabilities& LayerTreeImpl::rendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27427 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52428}
429
[email protected]ff762fb2012-12-12 19:18:37430OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27431 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37432}
433
434ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27435 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37436}
437
438TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27439 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37440}
441
442FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27443 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37444}
445
[email protected]71691c22013-01-18 03:14:22446PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27447 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22448}
449
[email protected]1191d9d2013-02-02 06:00:33450MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27451 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33452}
453
[email protected]f117a4c2012-12-16 04:53:10454bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27455 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10456}
457
458bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27459 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10460}
461
[email protected]48871fc2013-01-23 07:36:51462bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27463 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51464}
465
[email protected]f117a4c2012-12-16 04:53:10466LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27467 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10468 if (!tree)
469 return NULL;
470 return tree->LayerById(id);
471}
472
473LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27474 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10475 if (!tree)
476 return NULL;
477 return tree->LayerById(id);
478}
479
[email protected]f6776532012-12-21 20:24:33480int LayerTreeImpl::MaxTextureSize() const {
[email protected]c1bb5af2013-03-13 19:06:27481 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size;
[email protected]f6776532012-12-21 20:24:33482}
483
[email protected]166db5c82013-01-09 23:54:31484bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27485 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31486}
487
[email protected]829ad972013-01-28 23:36:10488base::TimeTicks LayerTreeImpl::CurrentFrameTime() const {
[email protected]c1bb5af2013-03-13 19:06:27489 return layer_tree_host_impl_->CurrentFrameTime();
[email protected]829ad972013-01-28 23:36:10490}
491
[email protected]ff762fb2012-12-12 19:18:37492void LayerTreeImpl::SetNeedsRedraw() {
493 layer_tree_host_impl_->setNeedsRedraw();
494}
495
[email protected]ff762fb2012-12-12 19:18:37496const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27497 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37498}
499
500float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27501 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37502}
503
[email protected]90ec9872013-03-08 02:28:18504gfx::Size LayerTreeImpl::device_viewport_size() const {
[email protected]c1bb5af2013-03-13 19:06:27505 return layer_tree_host_impl_->device_viewport_size();
[email protected]ff762fb2012-12-12 19:18:37506}
507
[email protected]c1bb5af2013-03-13 19:06:27508gfx::Size LayerTreeImpl::layout_viewport_size() const {
509 return layer_tree_host_impl_->layout_viewport_size();
[email protected]ff762fb2012-12-12 19:18:37510}
511
512std::string LayerTreeImpl::layer_tree_as_text() const {
[email protected]c1bb5af2013-03-13 19:06:27513 return layer_tree_host_impl_->LayerTreeAsText();
[email protected]ff762fb2012-12-12 19:18:37514}
515
516DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27517 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37518}
519
[email protected]de4afb5e2012-12-20 00:11:34520AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27521 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34522}
[email protected]ff762fb2012-12-12 19:18:37523
[email protected]8c5690222013-02-15 17:36:43524scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
525 scoped_ptr<base::ListValue> state(new base::ListValue());
526 typedef LayerIterator<LayerImpl,
527 std::vector<LayerImpl*>,
528 RenderSurfaceImpl,
529 LayerIteratorActions::BackToFront> LayerIteratorType;
530 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_);
531 for (LayerIteratorType it = LayerIteratorType::begin(
532 &render_surface_layer_list_); it != end; ++it) {
533 if (!it.representsItself())
534 continue;
535 state->Append((*it)->AsValue().release());
536 }
537 return state.PassAs<base::Value>();
538}
539
[email protected]b7c4783f2013-03-15 23:11:42540void LayerTreeImpl::DidBeginScroll() {
541 if (HasPinchZoomScrollbars())
542 FadeInPinchZoomScrollbars();
543}
544
545void LayerTreeImpl::DidUpdateScroll() {
546 if (HasPinchZoomScrollbars())
547 UpdatePinchZoomScrollbars();
548}
549
550void LayerTreeImpl::DidEndScroll() {
551 if (HasPinchZoomScrollbars())
552 FadeOutPinchZoomScrollbars();
553}
554
555void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) {
556 pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id;
557}
558
559ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() {
560 return static_cast<ScrollbarLayerImpl*>(LayerById(
561 pinch_zoom_scrollbar_horizontal_layer_id_));
562}
563
564void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) {
565 pinch_zoom_scrollbar_vertical_layer_id_ = layer_id;
566}
567
568ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() {
569 return static_cast<ScrollbarLayerImpl*>(LayerById(
570 pinch_zoom_scrollbar_vertical_layer_id_));
571}
572
573void LayerTreeImpl::UpdatePinchZoomScrollbars() {
574 LayerImpl* root_scroll_layer = RootScrollLayer();
575 if (!root_scroll_layer)
576 return;
577
578 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) {
579 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x());
580 scrollbar->SetTotalSize(root_scroll_layer->bounds().width());
581 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x());
582 }
583 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) {
584 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y());
585 scrollbar->SetTotalSize(root_scroll_layer->bounds().height());
586 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().y());
587 }
588}
589
590static scoped_ptr<Animation> MakePinchZoomFadeAnimation(
591 float start_opacity, float end_opacity) {
592 scoped_ptr<KeyframedFloatAnimationCurve> curve =
593 KeyframedFloatAnimationCurve::Create();
594 curve->AddKeyframe(FloatKeyframe::Create(
595 0, start_opacity, EaseInTimingFunction::create()));
596 curve->AddKeyframe(FloatKeyframe::Create(
597 PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity,
598 EaseInTimingFunction::create()));
599
600 scoped_ptr<Animation> animation = Animation::Create(
601 curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(),
602 0, Animation::Opacity);
603 animation->set_is_impl_only(true);
604
605 return animation.Pass();
606}
607
608static void StartFadeInAnimation(ScrollbarLayerImpl* layer) {
609 DCHECK(layer);
610 float start_opacity = layer->opacity();
611 LayerAnimationController* controller = layer->layer_animation_controller();
612 // TODO() It shouldn't be necessary to manually remove the old animation.
613 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
614 controller->RemoveAnimation(animation->id());
615 controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity,
616 PinchZoomScrollbar::kDefaultOpacity));
617}
618
619void LayerTreeImpl::FadeInPinchZoomScrollbars() {
620 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1)
621 return;
622
623 StartFadeInAnimation(PinchZoomScrollbarHorizontal());
624 StartFadeInAnimation(PinchZoomScrollbarVertical());
625}
626
627static void StartFadeOutAnimation(LayerImpl* layer) {
628 float opacity = layer->opacity();
629 if (!opacity)
630 return;
631
632 LayerAnimationController* controller = layer->layer_animation_controller();
633 // TODO(wjmaclean) It shouldn't be necessary to manually remove the old
634 // animation.
635 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
636 controller->RemoveAnimation(animation->id());
637 controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0));
638}
639
640void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
641 if (!HasPinchZoomScrollbars())
642 return;
643
644 StartFadeOutAnimation(PinchZoomScrollbarHorizontal());
645 StartFadeOutAnimation(PinchZoomScrollbarVertical());
646}
647
648bool LayerTreeImpl::HasPinchZoomScrollbars() const {
649 return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID &&
650 pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID;
651}
652
653
[email protected]3b31c6ac2012-12-06 21:27:29654} // namespace cc