blob: dde8fe466e7442b8aeb5938726409dd6d7c24768 [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
[email protected]3c0a3252013-03-18 04:24:3650static LayerImpl* FindRootScrollLayerRecursive(LayerImpl* layer) {
51 if (!layer)
52 return NULL;
[email protected]3b31c6ac2012-12-06 21:27:2953
[email protected]3c0a3252013-03-18 04:24:3654 if (layer->scrollable())
55 return layer;
[email protected]3b31c6ac2012-12-06 21:27:2956
[email protected]3c0a3252013-03-18 04:24:3657 for (size_t i = 0; i < layer->children().size(); ++i) {
58 LayerImpl* found = FindRootScrollLayerRecursive(layer->children()[i]);
59 if (found)
60 return found;
61 }
[email protected]3b31c6ac2012-12-06 21:27:2962
[email protected]3c0a3252013-03-18 04:24:3663 return NULL;
[email protected]3b31c6ac2012-12-06 21:27:2964}
65
66void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
67 root_layer_ = layer.Pass();
[email protected]5c4824e12013-01-12 16:34:5368 root_scroll_layer_ = NULL;
69 currently_scrolling_layer_ = NULL;
70
[email protected]c1bb5af2013-03-13 19:06:2771 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]5c4824e12013-01-12 16:34:5372}
73
74void LayerTreeImpl::FindRootScrollLayer() {
[email protected]3c0a3252013-03-18 04:24:3675 root_scroll_layer_ = FindRootScrollLayerRecursive(root_layer_.get());
[email protected]3b31c6ac2012-12-06 21:27:2976
77 if (root_layer_ && scrolling_layer_id_from_previous_tree_) {
78 currently_scrolling_layer_ = LayerTreeHostCommon::findLayerInSubtree(
79 root_layer_.get(),
80 scrolling_layer_id_from_previous_tree_);
81 }
82
83 scrolling_layer_id_from_previous_tree_ = 0;
[email protected]3b31c6ac2012-12-06 21:27:2984}
85
86scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
87 // Clear all data structures that have direct references to the layer tree.
88 scrolling_layer_id_from_previous_tree_ =
89 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]69b50ec2013-01-19 04:58:0190 root_scroll_layer_ = NULL;
[email protected]3b31c6ac2012-12-06 21:27:2991 currently_scrolling_layer_ = NULL;
92
[email protected]76ffd9e2012-12-20 19:12:4793 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:1694 set_needs_update_draw_properties();
[email protected]3b31c6ac2012-12-06 21:27:2995 return root_layer_.Pass();
96}
97
[email protected]7aba6662013-03-12 10:17:3498void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
[email protected]c60279472013-01-30 12:10:5199 target_tree->SetPageScaleFactorAndLimits(
100 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor());
101 target_tree->SetPageScaleDelta(
102 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta());
103 target_tree->set_sent_page_scale_delta(1);
104
105 // This should match the property synchronization in
106 // LayerTreeHost::finishCommitOnImplThread().
107 target_tree->set_source_frame_number(source_frame_number());
108 target_tree->set_background_color(background_color());
109 target_tree->set_has_transparent_background(has_transparent_background());
110
111 if (ContentsTexturesPurged())
112 target_tree->SetContentsTexturesPurged();
113 else
114 target_tree->ResetContentsTexturesPurged();
115
[email protected]318822852013-02-14 00:54:27116 if (ViewportSizeInvalid())
117 target_tree->SetViewportSizeInvalid();
118 else
119 target_tree->ResetViewportSizeInvalid();
120
[email protected]c60279472013-01-30 12:10:51121 if (hud_layer())
122 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
123 LayerTreeHostCommon::findLayerInSubtree(
[email protected]c1bb5af2013-03-13 19:06:27124 target_tree->root_layer(), hud_layer()->id())));
[email protected]c60279472013-01-30 12:10:51125 else
126 target_tree->set_hud_layer(NULL);
[email protected]b7c4783f2013-03-15 23:11:42127
128 target_tree->SetPinchZoomHorizontalLayerId(
129 pinch_zoom_scrollbar_horizontal_layer_id_);
130 target_tree->SetPinchZoomVerticalLayerId(
131 pinch_zoom_scrollbar_vertical_layer_id_);
[email protected]c60279472013-01-30 12:10:51132}
133
[email protected]ffb2720f2013-03-15 19:18:37134LayerImpl* LayerTreeImpl::RootScrollLayer() const {
[email protected]69b50ec2013-01-19 04:58:01135 DCHECK(IsActiveTree());
136 return root_scroll_layer_;
137}
138
[email protected]ffb2720f2013-03-15 19:18:37139LayerImpl* LayerTreeImpl::RootClipLayer() const {
140 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL;
141}
142
143LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
[email protected]69b50ec2013-01-19 04:58:01144 DCHECK(IsActiveTree());
145 return currently_scrolling_layer_;
146}
147
[email protected]3b31c6ac2012-12-06 21:27:29148void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
149 currently_scrolling_layer_ = NULL;
150 scrolling_layer_id_from_previous_tree_ = 0;
151}
152
[email protected]c60279472013-01-30 12:10:51153void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
[email protected]3c0a3252013-03-18 04:24:36154 float min_page_scale_factor, float max_page_scale_factor) {
[email protected]c60279472013-01-30 12:10:51155 if (!page_scale_factor)
156 return;
157
158 min_page_scale_factor_ = min_page_scale_factor;
159 max_page_scale_factor_ = max_page_scale_factor;
160 page_scale_factor_ = page_scale_factor;
161}
162
[email protected]3c0a3252013-03-18 04:24:36163void LayerTreeImpl::SetPageScaleDelta(float delta) {
[email protected]c60279472013-01-30 12:10:51164 // Clamp to the current min/max limits.
165 float total = page_scale_factor_ * delta;
166 if (min_page_scale_factor_ && total < min_page_scale_factor_)
167 delta = min_page_scale_factor_ / page_scale_factor_;
168 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
169 delta = max_page_scale_factor_ / page_scale_factor_;
170
171 if (delta == page_scale_delta_)
172 return;
173
174 page_scale_delta_ = delta;
175
176 if (IsActiveTree()) {
[email protected]c1bb5af2013-03-13 19:06:27177 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
[email protected]c60279472013-01-30 12:10:51178 if (pending_tree) {
179 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
180 pending_tree->SetPageScaleDelta(page_scale_delta_ / sent_page_scale_delta_);
181 }
182 }
183
184 UpdateMaxScrollOffset();
185 set_needs_update_draw_properties();
186}
187
[email protected]257abfa82013-01-29 23:47:24188gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]ffb2720f2013-03-15 19:18:37189 return gfx::ScaleSize(layer_tree_host_impl_->VisibleViewportSize(),
190 1.0f / total_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24191}
192
[email protected]caa567d2012-12-20 07:56:16193void LayerTreeImpl::UpdateMaxScrollOffset() {
[email protected]69b50ec2013-01-19 04:58:01194 if (!root_scroll_layer_ || !root_scroll_layer_->children().size())
[email protected]caa567d2012-12-20 07:56:16195 return;
196
[email protected]42ccdbef2013-01-21 07:54:54197 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() -
[email protected]257abfa82013-01-29 23:47:24198 gfx::RectF(ScrollableViewportSize()).bottom_right();
[email protected]caa567d2012-12-20 07:56:16199
200 // The viewport may be larger than the contents in some cases, such as
201 // having a vertical scrollbar but no horizontal overflow.
202 max_scroll.ClampToMin(gfx::Vector2dF());
203
[email protected]7aba6662013-03-12 10:17:34204 root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
[email protected]caa567d2012-12-20 07:56:16205}
206
[email protected]c60279472013-01-30 12:10:51207gfx::Transform LayerTreeImpl::ImplTransform() const {
208 gfx::Transform transform;
[email protected]c2d0c5a2013-02-26 04:43:36209 transform.Scale(total_page_scale_factor(), total_page_scale_factor());
[email protected]c60279472013-01-30 12:10:51210 return transform;
211}
212
[email protected]ffb2720f2013-03-15 19:18:37213void LayerTreeImpl::UpdateSolidColorScrollbars() {
214 DCHECK(settings().solidColorScrollbars);
215
216 LayerImpl* root_scroll = RootScrollLayer();
217 if (!root_scroll)
218 return;
219
220 if (!IsActiveTree())
221 return;
222
223 gfx::RectF scrollable_viewport(
224 gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()),
225 ScrollableViewportSize());
226 float vertical_adjust = 0.0f;
227 if (RootClipLayer())
228 vertical_adjust = layer_tree_host_impl_->VisibleViewportSize().height() -
229 RootClipLayer()->bounds().height();
230 if (ScrollbarLayerImpl* horiz = root_scroll->horizontal_scrollbar_layer()) {
231 horiz->set_vertical_adjust(vertical_adjust);
232 horiz->SetViewportWithinScrollableArea(scrollable_viewport,
233 ScrollableSize());
234 }
235 if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) {
236 vertical->set_vertical_adjust(vertical_adjust);
237 vertical->SetViewportWithinScrollableArea(scrollable_viewport,
238 ScrollableSize());
239 }
240}
241
[email protected]4c9bb952013-01-27 05:41:18242struct UpdateTilePrioritiesForLayer {
243 void operator()(LayerImpl *layer) {
[email protected]7aba6662013-03-12 10:17:34244 layer->UpdateTilePriorities();
[email protected]4c9bb952013-01-27 05:41:18245 }
246};
247
248void LayerTreeImpl::UpdateDrawProperties(UpdateDrawPropertiesReason reason) {
[email protected]ffb2720f2013-03-15 19:18:37249 if (settings().solidColorScrollbars && IsActiveTree()) {
250 UpdateSolidColorScrollbars();
251
252 // The top controls manager is incompatible with the WebKit-created cliprect
253 // because it can bring into view a larger amount of content when it
254 // hides. It's safe to deactivate the clip rect if no non-overlay scrollbars
255 // are present.
256 if (layer_tree_host_impl_->top_controls_manager())
257 RootScrollLayer()->parent()->SetMasksToBounds(false);
258 }
259
[email protected]4c9bb952013-01-27 05:41:18260 if (!needs_update_draw_properties_) {
[email protected]c1bb5af2013-03-13 19:06:27261 if (reason == UPDATE_ACTIVE_TREE_FOR_DRAW && root_layer())
[email protected]4c9bb952013-01-27 05:41:18262 LayerTreeHostCommon::callFunctionForSubtree<UpdateTilePrioritiesForLayer>(
[email protected]c1bb5af2013-03-13 19:06:27263 root_layer());
[email protected]615c78a2013-01-24 23:44:16264 return;
[email protected]4c9bb952013-01-27 05:41:18265 }
[email protected]615c78a2013-01-24 23:44:16266
267 needs_update_draw_properties_ = false;
[email protected]76ffd9e2012-12-20 19:12:47268 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16269
270 // For maxTextureSize.
271 if (!layer_tree_host_impl_->renderer())
272 return;
273
[email protected]c1bb5af2013-03-13 19:06:27274 if (!root_layer())
[email protected]76ffd9e2012-12-20 19:12:47275 return;
276
[email protected]69b50ec2013-01-19 04:58:01277 if (root_scroll_layer_) {
[email protected]7aba6662013-03-12 10:17:34278 root_scroll_layer_->SetImplTransform(ImplTransform());
[email protected]615c78a2013-01-24 23:44:16279 // Setting the impl transform re-sets this.
280 needs_update_draw_properties_ = false;
[email protected]76ffd9e2012-12-20 19:12:47281 }
282
283 {
[email protected]c1bb5af2013-03-13 19:06:27284 TRACE_EVENT1("cc",
285 "LayerTreeImpl::UpdateDrawProperties",
286 "IsActive",
287 IsActiveTree());
[email protected]4c9bb952013-01-27 05:41:18288 bool update_tile_priorities =
289 reason == UPDATE_PENDING_TREE ||
290 reason == UPDATE_ACTIVE_TREE_FOR_DRAW;
[email protected]76ffd9e2012-12-20 19:12:47291 LayerTreeHostCommon::calculateDrawProperties(
[email protected]c1bb5af2013-03-13 19:06:27292 root_layer(),
[email protected]76ffd9e2012-12-20 19:12:47293 device_viewport_size(),
294 device_scale_factor(),
[email protected]c60279472013-01-30 12:10:51295 total_page_scale_factor(),
[email protected]f6776532012-12-21 20:24:33296 MaxTextureSize(),
[email protected]76ffd9e2012-12-20 19:12:47297 settings().canUseLCDText,
[email protected]4c9bb952013-01-27 05:41:18298 render_surface_layer_list_,
299 update_tile_priorities);
[email protected]76ffd9e2012-12-20 19:12:47300 }
[email protected]615c78a2013-01-24 23:44:16301
302 DCHECK(!needs_update_draw_properties_) <<
303 "calcDrawProperties should not set_needs_update_draw_properties()";
[email protected]76ffd9e2012-12-20 19:12:47304}
305
[email protected]3c0a3252013-03-18 04:24:36306static void ClearRenderSurfacesOnLayerImplRecursive(LayerImpl* current) {
307 DCHECK(current);
308 for (size_t i = 0; i < current->children().size(); ++i)
309 ClearRenderSurfacesOnLayerImplRecursive(current->children()[i]);
310 current->ClearRenderSurface();
[email protected]76ffd9e2012-12-20 19:12:47311}
312
313void LayerTreeImpl::ClearRenderSurfaces() {
[email protected]c1bb5af2013-03-13 19:06:27314 ClearRenderSurfacesOnLayerImplRecursive(root_layer());
[email protected]76ffd9e2012-12-20 19:12:47315 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16316 set_needs_update_draw_properties();
[email protected]76ffd9e2012-12-20 19:12:47317}
318
[email protected]b0a917c8d2013-01-12 17:42:25319bool LayerTreeImpl::AreVisibleResourcesReady() const {
320 TRACE_EVENT0("cc", "LayerTreeImpl::AreVisibleResourcesReady");
321
322 typedef LayerIterator<LayerImpl,
323 std::vector<LayerImpl*>,
324 RenderSurfaceImpl,
325 LayerIteratorActions::BackToFront> LayerIteratorType;
326 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_);
327 for (LayerIteratorType it = LayerIteratorType::begin(
328 &render_surface_layer_list_); it != end; ++it) {
[email protected]7aba6662013-03-12 10:17:34329 if (it.representsItself() && !(*it)->AreVisibleResourcesReady())
[email protected]b0a917c8d2013-01-12 17:42:25330 return false;
331 }
332
333 return true;
334}
335
[email protected]76ffd9e2012-12-20 19:12:47336const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const {
337 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16338 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47339 return render_surface_layer_list_;
340}
341
[email protected]42ccdbef2013-01-21 07:54:54342gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]c4d467a2013-01-21 03:21:01343 if (!root_scroll_layer_ || root_scroll_layer_->children().empty())
[email protected]caa567d2012-12-20 07:56:16344 return gfx::Size();
[email protected]c4d467a2013-01-21 03:21:01345 return root_scroll_layer_->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16346}
347
[email protected]361bc00d2012-12-14 07:03:24348LayerImpl* LayerTreeImpl::LayerById(int id) {
349 LayerIdMap::iterator iter = layer_id_map_.find(id);
350 return iter != layer_id_map_.end() ? iter->second : NULL;
351}
352
353void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
354 DCHECK(!LayerById(layer->id()));
355 layer_id_map_[layer->id()] = layer;
356}
357
358void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
359 DCHECK(LayerById(layer->id()));
360 layer_id_map_.erase(layer->id());
361}
362
[email protected]1e0f8d62013-01-09 07:41:35363void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pendingTree) {
364 int id = currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
365 pendingTree->set_currently_scrolling_layer(
[email protected]c1bb5af2013-03-13 19:06:27366 LayerTreeHostCommon::findLayerInSubtree(pendingTree->root_layer(), id));
[email protected]1e0f8d62013-01-09 07:41:35367}
368
[email protected]37386f052013-01-13 00:42:22369static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34370 layer->DidBecomeActive();
[email protected]37386f052013-01-13 00:42:22371 for (size_t i = 0; i < layer->children().size(); ++i)
372 DidBecomeActiveRecursive(layer->children()[i]);
373}
374
375void LayerTreeImpl::DidBecomeActive() {
[email protected]c1bb5af2013-03-13 19:06:27376 if (root_layer())
377 DidBecomeActiveRecursive(root_layer());
[email protected]69b50ec2013-01-19 04:58:01378 FindRootScrollLayer();
379 UpdateMaxScrollOffset();
[email protected]b7c4783f2013-03-15 23:11:42380 // Main thread scrolls do not get handled in LayerTreeHostImpl, so after
381 // each commit (and after the root scroll layer has its max scroll offset
382 // set), we need to update pinch zoom scrollbars.
383 UpdatePinchZoomScrollbars();
[email protected]37386f052013-01-13 00:42:22384}
385
[email protected]6f90b9e2013-01-17 23:42:00386bool LayerTreeImpl::ContentsTexturesPurged() const {
387 return contents_textures_purged_;
388}
389
390void LayerTreeImpl::SetContentsTexturesPurged() {
391 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27392 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00393}
394
395void LayerTreeImpl::ResetContentsTexturesPurged() {
396 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27397 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00398}
399
[email protected]318822852013-02-14 00:54:27400bool LayerTreeImpl::ViewportSizeInvalid() const {
401 return viewport_size_invalid_;
402}
403
404void LayerTreeImpl::SetViewportSizeInvalid() {
405 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27406 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27407}
408
409void LayerTreeImpl::ResetViewportSizeInvalid() {
410 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27411 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27412}
413
[email protected]48871fc2013-01-23 07:36:51414Proxy* LayerTreeImpl::proxy() const {
415 return layer_tree_host_impl_->proxy();
416}
417
[email protected]ff762fb2012-12-12 19:18:37418const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27419 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37420}
421
[email protected]bf5b3a02013-02-13 02:02:52422const RendererCapabilities& LayerTreeImpl::rendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27423 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52424}
425
[email protected]ff762fb2012-12-12 19:18:37426OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27427 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37428}
429
430ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27431 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37432}
433
434TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27435 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37436}
437
438FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27439 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37440}
441
[email protected]71691c22013-01-18 03:14:22442PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27443 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22444}
445
[email protected]1191d9d2013-02-02 06:00:33446MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27447 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33448}
449
[email protected]f117a4c2012-12-16 04:53:10450bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27451 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10452}
453
454bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27455 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10456}
457
[email protected]48871fc2013-01-23 07:36:51458bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27459 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51460}
461
[email protected]f117a4c2012-12-16 04:53:10462LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27463 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10464 if (!tree)
465 return NULL;
466 return tree->LayerById(id);
467}
468
469LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27470 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10471 if (!tree)
472 return NULL;
473 return tree->LayerById(id);
474}
475
[email protected]f6776532012-12-21 20:24:33476int LayerTreeImpl::MaxTextureSize() const {
[email protected]c1bb5af2013-03-13 19:06:27477 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size;
[email protected]f6776532012-12-21 20:24:33478}
479
[email protected]166db5c82013-01-09 23:54:31480bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27481 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31482}
483
[email protected]829ad972013-01-28 23:36:10484base::TimeTicks LayerTreeImpl::CurrentFrameTime() const {
[email protected]c1bb5af2013-03-13 19:06:27485 return layer_tree_host_impl_->CurrentFrameTime();
[email protected]829ad972013-01-28 23:36:10486}
487
[email protected]ff762fb2012-12-12 19:18:37488void LayerTreeImpl::SetNeedsRedraw() {
489 layer_tree_host_impl_->setNeedsRedraw();
490}
491
[email protected]ff762fb2012-12-12 19:18:37492const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27493 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37494}
495
496float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27497 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37498}
499
[email protected]90ec9872013-03-08 02:28:18500gfx::Size LayerTreeImpl::device_viewport_size() const {
[email protected]c1bb5af2013-03-13 19:06:27501 return layer_tree_host_impl_->device_viewport_size();
[email protected]ff762fb2012-12-12 19:18:37502}
503
[email protected]c1bb5af2013-03-13 19:06:27504gfx::Size LayerTreeImpl::layout_viewport_size() const {
505 return layer_tree_host_impl_->layout_viewport_size();
[email protected]ff762fb2012-12-12 19:18:37506}
507
508std::string LayerTreeImpl::layer_tree_as_text() const {
[email protected]c1bb5af2013-03-13 19:06:27509 return layer_tree_host_impl_->LayerTreeAsText();
[email protected]ff762fb2012-12-12 19:18:37510}
511
512DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27513 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37514}
515
[email protected]de4afb5e2012-12-20 00:11:34516AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27517 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34518}
[email protected]ff762fb2012-12-12 19:18:37519
[email protected]8c5690222013-02-15 17:36:43520scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
521 scoped_ptr<base::ListValue> state(new base::ListValue());
522 typedef LayerIterator<LayerImpl,
523 std::vector<LayerImpl*>,
524 RenderSurfaceImpl,
525 LayerIteratorActions::BackToFront> LayerIteratorType;
526 LayerIteratorType end = LayerIteratorType::end(&render_surface_layer_list_);
527 for (LayerIteratorType it = LayerIteratorType::begin(
528 &render_surface_layer_list_); it != end; ++it) {
529 if (!it.representsItself())
530 continue;
531 state->Append((*it)->AsValue().release());
532 }
533 return state.PassAs<base::Value>();
534}
535
[email protected]b7c4783f2013-03-15 23:11:42536void LayerTreeImpl::DidBeginScroll() {
537 if (HasPinchZoomScrollbars())
538 FadeInPinchZoomScrollbars();
539}
540
541void LayerTreeImpl::DidUpdateScroll() {
542 if (HasPinchZoomScrollbars())
543 UpdatePinchZoomScrollbars();
544}
545
546void LayerTreeImpl::DidEndScroll() {
547 if (HasPinchZoomScrollbars())
548 FadeOutPinchZoomScrollbars();
549}
550
551void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) {
552 pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id;
553}
554
555ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() {
556 return static_cast<ScrollbarLayerImpl*>(LayerById(
557 pinch_zoom_scrollbar_horizontal_layer_id_));
558}
559
560void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) {
561 pinch_zoom_scrollbar_vertical_layer_id_ = layer_id;
562}
563
564ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() {
565 return static_cast<ScrollbarLayerImpl*>(LayerById(
566 pinch_zoom_scrollbar_vertical_layer_id_));
567}
568
569void LayerTreeImpl::UpdatePinchZoomScrollbars() {
570 LayerImpl* root_scroll_layer = RootScrollLayer();
571 if (!root_scroll_layer)
572 return;
573
574 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) {
575 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x());
576 scrollbar->SetTotalSize(root_scroll_layer->bounds().width());
577 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x());
578 }
579 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) {
580 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y());
581 scrollbar->SetTotalSize(root_scroll_layer->bounds().height());
582 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().y());
583 }
584}
585
586static scoped_ptr<Animation> MakePinchZoomFadeAnimation(
587 float start_opacity, float end_opacity) {
588 scoped_ptr<KeyframedFloatAnimationCurve> curve =
589 KeyframedFloatAnimationCurve::Create();
590 curve->AddKeyframe(FloatKeyframe::Create(
591 0, start_opacity, EaseInTimingFunction::create()));
592 curve->AddKeyframe(FloatKeyframe::Create(
593 PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity,
594 EaseInTimingFunction::create()));
595
596 scoped_ptr<Animation> animation = Animation::Create(
597 curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(),
598 0, Animation::Opacity);
599 animation->set_is_impl_only(true);
600
601 return animation.Pass();
602}
603
604static void StartFadeInAnimation(ScrollbarLayerImpl* layer) {
605 DCHECK(layer);
606 float start_opacity = layer->opacity();
607 LayerAnimationController* controller = layer->layer_animation_controller();
608 // TODO() It shouldn't be necessary to manually remove the old animation.
609 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
610 controller->RemoveAnimation(animation->id());
611 controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity,
612 PinchZoomScrollbar::kDefaultOpacity));
613}
614
615void LayerTreeImpl::FadeInPinchZoomScrollbars() {
616 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1)
617 return;
618
619 StartFadeInAnimation(PinchZoomScrollbarHorizontal());
620 StartFadeInAnimation(PinchZoomScrollbarVertical());
621}
622
623static void StartFadeOutAnimation(LayerImpl* layer) {
624 float opacity = layer->opacity();
625 if (!opacity)
626 return;
627
628 LayerAnimationController* controller = layer->layer_animation_controller();
629 // TODO(wjmaclean) It shouldn't be necessary to manually remove the old
630 // animation.
631 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
632 controller->RemoveAnimation(animation->id());
633 controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0));
634}
635
636void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
637 if (!HasPinchZoomScrollbars())
638 return;
639
640 StartFadeOutAnimation(PinchZoomScrollbarHorizontal());
641 StartFadeOutAnimation(PinchZoomScrollbarVertical());
642}
643
644bool LayerTreeImpl::HasPinchZoomScrollbars() const {
645 return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID &&
646 pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID;
647}
648
649
[email protected]3b31c6ac2012-12-06 21:27:29650} // namespace cc