blob: d1b8ded311dfb387af7f0cc9953f2bd100c28057 [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]cdb284d72013-03-18 09:34:4812#include "cc/input/pinch_zoom_scrollbar.h"
[email protected]cc3cfaa2013-03-18 09:05:5213#include "cc/layers/heads_up_display_layer_impl.h"
14#include "cc/layers/layer.h"
15#include "cc/layers/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_) {
[email protected]6ba914122013-03-22 16:26:3979 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
[email protected]3b31c6ac2012-12-06 21:27:2980 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*>(
[email protected]6ba914122013-03-22 16:26:39124 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())
[email protected]6bc09e82013-03-19 03:48:35155 currently_scrolling_layer_->scrollbar_animation_controller()->
156 DidScrollGestureEnd(base::TimeTicks::Now());
[email protected]0fc818e2013-03-18 06:45:20157 currently_scrolling_layer_ = layer;
158 if (layer && layer->scrollbar_animation_controller())
[email protected]6bc09e82013-03-19 03:48:35159 layer->scrollbar_animation_controller()->DidScrollGestureBegin();
[email protected]0fc818e2013-03-18 06:45:20160}
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() {
[email protected]8e0176d2013-03-21 03:14:52228 DCHECK(settings().solid_color_scrollbars);
[email protected]ffb2720f2013-03-15 19:18:37229
230 LayerImpl* root_scroll = RootScrollLayer();
[email protected]ab5f4a92013-03-19 20:08:24231 DCHECK(root_scroll);
232 DCHECK(IsActiveTree());
[email protected]ffb2720f2013-03-15 19:18:37233
234 gfx::RectF scrollable_viewport(
235 gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()),
236 ScrollableViewportSize());
237 float vertical_adjust = 0.0f;
238 if (RootClipLayer())
239 vertical_adjust = layer_tree_host_impl_->VisibleViewportSize().height() -
240 RootClipLayer()->bounds().height();
241 if (ScrollbarLayerImpl* horiz = root_scroll->horizontal_scrollbar_layer()) {
242 horiz->set_vertical_adjust(vertical_adjust);
243 horiz->SetViewportWithinScrollableArea(scrollable_viewport,
244 ScrollableSize());
245 }
246 if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) {
247 vertical->set_vertical_adjust(vertical_adjust);
248 vertical->SetViewportWithinScrollableArea(scrollable_viewport,
249 ScrollableSize());
250 }
251}
252
[email protected]4c9bb952013-01-27 05:41:18253struct UpdateTilePrioritiesForLayer {
254 void operator()(LayerImpl *layer) {
[email protected]7aba6662013-03-12 10:17:34255 layer->UpdateTilePriorities();
[email protected]4c9bb952013-01-27 05:41:18256 }
257};
258
259void LayerTreeImpl::UpdateDrawProperties(UpdateDrawPropertiesReason reason) {
[email protected]8e0176d2013-03-21 03:14:52260 if (settings().solid_color_scrollbars && IsActiveTree() && RootScrollLayer()) {
[email protected]ffb2720f2013-03-15 19:18:37261 UpdateSolidColorScrollbars();
262
263 // The top controls manager is incompatible with the WebKit-created cliprect
264 // because it can bring into view a larger amount of content when it
265 // hides. It's safe to deactivate the clip rect if no non-overlay scrollbars
266 // are present.
[email protected]ab5f4a92013-03-19 20:08:24267 if (RootClipLayer() && layer_tree_host_impl_->top_controls_manager())
268 RootClipLayer()->SetMasksToBounds(false);
[email protected]ffb2720f2013-03-15 19:18:37269 }
270
[email protected]4c9bb952013-01-27 05:41:18271 if (!needs_update_draw_properties_) {
[email protected]c1bb5af2013-03-13 19:06:27272 if (reason == UPDATE_ACTIVE_TREE_FOR_DRAW && root_layer())
[email protected]6ba914122013-03-22 16:26:39273 LayerTreeHostCommon::CallFunctionForSubtree<UpdateTilePrioritiesForLayer>(
[email protected]c1bb5af2013-03-13 19:06:27274 root_layer());
[email protected]615c78a2013-01-24 23:44:16275 return;
[email protected]4c9bb952013-01-27 05:41:18276 }
[email protected]615c78a2013-01-24 23:44:16277
278 needs_update_draw_properties_ = false;
[email protected]76ffd9e2012-12-20 19:12:47279 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16280
281 // For maxTextureSize.
282 if (!layer_tree_host_impl_->renderer())
283 return;
284
[email protected]c1bb5af2013-03-13 19:06:27285 if (!root_layer())
[email protected]76ffd9e2012-12-20 19:12:47286 return;
287
[email protected]69b50ec2013-01-19 04:58:01288 if (root_scroll_layer_) {
[email protected]7aba6662013-03-12 10:17:34289 root_scroll_layer_->SetImplTransform(ImplTransform());
[email protected]615c78a2013-01-24 23:44:16290 // Setting the impl transform re-sets this.
291 needs_update_draw_properties_ = false;
[email protected]76ffd9e2012-12-20 19:12:47292 }
293
294 {
[email protected]c1bb5af2013-03-13 19:06:27295 TRACE_EVENT1("cc",
296 "LayerTreeImpl::UpdateDrawProperties",
297 "IsActive",
298 IsActiveTree());
[email protected]4c9bb952013-01-27 05:41:18299 bool update_tile_priorities =
300 reason == UPDATE_PENDING_TREE ||
301 reason == UPDATE_ACTIVE_TREE_FOR_DRAW;
[email protected]6ba914122013-03-22 16:26:39302 LayerTreeHostCommon::CalculateDrawProperties(
[email protected]c1bb5af2013-03-13 19:06:27303 root_layer(),
[email protected]76ffd9e2012-12-20 19:12:47304 device_viewport_size(),
305 device_scale_factor(),
[email protected]c60279472013-01-30 12:10:51306 total_page_scale_factor(),
[email protected]f6776532012-12-21 20:24:33307 MaxTextureSize(),
[email protected]8e0176d2013-03-21 03:14:52308 settings().can_use_lcd_text,
[email protected]6ba914122013-03-22 16:26:39309 &render_surface_layer_list_,
[email protected]4c9bb952013-01-27 05:41:18310 update_tile_priorities);
[email protected]76ffd9e2012-12-20 19:12:47311 }
[email protected]615c78a2013-01-24 23:44:16312
313 DCHECK(!needs_update_draw_properties_) <<
314 "calcDrawProperties should not set_needs_update_draw_properties()";
[email protected]76ffd9e2012-12-20 19:12:47315}
316
[email protected]3c0a3252013-03-18 04:24:36317static void ClearRenderSurfacesOnLayerImplRecursive(LayerImpl* current) {
318 DCHECK(current);
319 for (size_t i = 0; i < current->children().size(); ++i)
320 ClearRenderSurfacesOnLayerImplRecursive(current->children()[i]);
321 current->ClearRenderSurface();
[email protected]76ffd9e2012-12-20 19:12:47322}
323
324void LayerTreeImpl::ClearRenderSurfaces() {
[email protected]c1bb5af2013-03-13 19:06:27325 ClearRenderSurfacesOnLayerImplRecursive(root_layer());
[email protected]76ffd9e2012-12-20 19:12:47326 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16327 set_needs_update_draw_properties();
[email protected]76ffd9e2012-12-20 19:12:47328}
329
[email protected]b0a917c8d2013-01-12 17:42:25330bool LayerTreeImpl::AreVisibleResourcesReady() const {
331 TRACE_EVENT0("cc", "LayerTreeImpl::AreVisibleResourcesReady");
332
333 typedef LayerIterator<LayerImpl,
334 std::vector<LayerImpl*>,
335 RenderSurfaceImpl,
336 LayerIteratorActions::BackToFront> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09337 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
338 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]b0a917c8d2013-01-12 17:42:25339 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09340 if (it.represents_itself() && !(*it)->AreVisibleResourcesReady())
[email protected]b0a917c8d2013-01-12 17:42:25341 return false;
342 }
343
344 return true;
345}
346
[email protected]76ffd9e2012-12-20 19:12:47347const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const {
348 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16349 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47350 return render_surface_layer_list_;
351}
352
[email protected]42ccdbef2013-01-21 07:54:54353gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]c4d467a2013-01-21 03:21:01354 if (!root_scroll_layer_ || root_scroll_layer_->children().empty())
[email protected]caa567d2012-12-20 07:56:16355 return gfx::Size();
[email protected]c4d467a2013-01-21 03:21:01356 return root_scroll_layer_->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16357}
358
[email protected]361bc00d2012-12-14 07:03:24359LayerImpl* LayerTreeImpl::LayerById(int id) {
360 LayerIdMap::iterator iter = layer_id_map_.find(id);
361 return iter != layer_id_map_.end() ? iter->second : NULL;
362}
363
364void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
365 DCHECK(!LayerById(layer->id()));
366 layer_id_map_[layer->id()] = layer;
367}
368
369void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
370 DCHECK(LayerById(layer->id()));
371 layer_id_map_.erase(layer->id());
372}
373
[email protected]1e0f8d62013-01-09 07:41:35374void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pendingTree) {
375 int id = currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]0fc818e2013-03-18 06:45:20376 pendingTree->SetCurrentlyScrollingLayer(
[email protected]6ba914122013-03-22 16:26:39377 LayerTreeHostCommon::FindLayerInSubtree(pendingTree->root_layer(), id));
[email protected]1e0f8d62013-01-09 07:41:35378}
379
[email protected]37386f052013-01-13 00:42:22380static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34381 layer->DidBecomeActive();
[email protected]37386f052013-01-13 00:42:22382 for (size_t i = 0; i < layer->children().size(); ++i)
383 DidBecomeActiveRecursive(layer->children()[i]);
384}
385
386void LayerTreeImpl::DidBecomeActive() {
[email protected]c1bb5af2013-03-13 19:06:27387 if (root_layer())
388 DidBecomeActiveRecursive(root_layer());
[email protected]69b50ec2013-01-19 04:58:01389 FindRootScrollLayer();
390 UpdateMaxScrollOffset();
[email protected]b7c4783f2013-03-15 23:11:42391 // Main thread scrolls do not get handled in LayerTreeHostImpl, so after
392 // each commit (and after the root scroll layer has its max scroll offset
393 // set), we need to update pinch zoom scrollbars.
394 UpdatePinchZoomScrollbars();
[email protected]37386f052013-01-13 00:42:22395}
396
[email protected]6f90b9e2013-01-17 23:42:00397bool LayerTreeImpl::ContentsTexturesPurged() const {
398 return contents_textures_purged_;
399}
400
401void LayerTreeImpl::SetContentsTexturesPurged() {
402 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27403 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00404}
405
406void LayerTreeImpl::ResetContentsTexturesPurged() {
407 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27408 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00409}
410
[email protected]318822852013-02-14 00:54:27411bool LayerTreeImpl::ViewportSizeInvalid() const {
412 return viewport_size_invalid_;
413}
414
415void LayerTreeImpl::SetViewportSizeInvalid() {
416 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27417 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27418}
419
420void LayerTreeImpl::ResetViewportSizeInvalid() {
421 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27422 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27423}
424
[email protected]48871fc2013-01-23 07:36:51425Proxy* LayerTreeImpl::proxy() const {
426 return layer_tree_host_impl_->proxy();
427}
428
[email protected]ff762fb2012-12-12 19:18:37429const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27430 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37431}
432
[email protected]bf5b3a02013-02-13 02:02:52433const RendererCapabilities& LayerTreeImpl::rendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27434 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52435}
436
[email protected]ff762fb2012-12-12 19:18:37437OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27438 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37439}
440
441ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27442 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37443}
444
445TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27446 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37447}
448
449FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27450 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37451}
452
[email protected]71691c22013-01-18 03:14:22453PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27454 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22455}
456
[email protected]1191d9d2013-02-02 06:00:33457MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27458 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33459}
460
[email protected]f117a4c2012-12-16 04:53:10461bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27462 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10463}
464
465bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27466 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10467}
468
[email protected]48871fc2013-01-23 07:36:51469bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27470 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51471}
472
[email protected]f117a4c2012-12-16 04:53:10473LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27474 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10475 if (!tree)
476 return NULL;
477 return tree->LayerById(id);
478}
479
480LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27481 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10482 if (!tree)
483 return NULL;
484 return tree->LayerById(id);
485}
486
[email protected]f6776532012-12-21 20:24:33487int LayerTreeImpl::MaxTextureSize() const {
[email protected]c1bb5af2013-03-13 19:06:27488 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size;
[email protected]f6776532012-12-21 20:24:33489}
490
[email protected]166db5c82013-01-09 23:54:31491bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27492 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31493}
494
[email protected]829ad972013-01-28 23:36:10495base::TimeTicks LayerTreeImpl::CurrentFrameTime() const {
[email protected]c1bb5af2013-03-13 19:06:27496 return layer_tree_host_impl_->CurrentFrameTime();
[email protected]829ad972013-01-28 23:36:10497}
498
[email protected]d7eb8c72013-03-23 22:57:13499void LayerTreeImpl::SetNeedsCommit() {
500 layer_tree_host_impl_->SetNeedsCommit();
501}
502
[email protected]ff762fb2012-12-12 19:18:37503void LayerTreeImpl::SetNeedsRedraw() {
504 layer_tree_host_impl_->setNeedsRedraw();
505}
506
[email protected]ff762fb2012-12-12 19:18:37507const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27508 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37509}
510
511float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27512 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37513}
514
[email protected]90ec98782013-03-08 02:28:18515gfx::Size LayerTreeImpl::device_viewport_size() const {
[email protected]c1bb5af2013-03-13 19:06:27516 return layer_tree_host_impl_->device_viewport_size();
[email protected]ff762fb2012-12-12 19:18:37517}
518
[email protected]c1bb5af2013-03-13 19:06:27519gfx::Size LayerTreeImpl::layout_viewport_size() const {
520 return layer_tree_host_impl_->layout_viewport_size();
[email protected]ff762fb2012-12-12 19:18:37521}
522
523std::string LayerTreeImpl::layer_tree_as_text() const {
[email protected]c1bb5af2013-03-13 19:06:27524 return layer_tree_host_impl_->LayerTreeAsText();
[email protected]ff762fb2012-12-12 19:18:37525}
526
527DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27528 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37529}
530
[email protected]de4afb5e2012-12-20 00:11:34531AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27532 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34533}
[email protected]ff762fb2012-12-12 19:18:37534
[email protected]8c5690222013-02-15 17:36:43535scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
536 scoped_ptr<base::ListValue> state(new base::ListValue());
537 typedef LayerIterator<LayerImpl,
538 std::vector<LayerImpl*>,
539 RenderSurfaceImpl,
540 LayerIteratorActions::BackToFront> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09541 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
542 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]8c5690222013-02-15 17:36:43543 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09544 if (!it.represents_itself())
[email protected]8c5690222013-02-15 17:36:43545 continue;
546 state->Append((*it)->AsValue().release());
547 }
548 return state.PassAs<base::Value>();
549}
550
[email protected]b7c4783f2013-03-15 23:11:42551void LayerTreeImpl::DidBeginScroll() {
552 if (HasPinchZoomScrollbars())
553 FadeInPinchZoomScrollbars();
554}
555
556void LayerTreeImpl::DidUpdateScroll() {
557 if (HasPinchZoomScrollbars())
558 UpdatePinchZoomScrollbars();
559}
560
561void LayerTreeImpl::DidEndScroll() {
562 if (HasPinchZoomScrollbars())
563 FadeOutPinchZoomScrollbars();
564}
565
566void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) {
567 pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id;
568}
569
570ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() {
571 return static_cast<ScrollbarLayerImpl*>(LayerById(
572 pinch_zoom_scrollbar_horizontal_layer_id_));
573}
574
575void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) {
576 pinch_zoom_scrollbar_vertical_layer_id_ = layer_id;
577}
578
579ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() {
580 return static_cast<ScrollbarLayerImpl*>(LayerById(
581 pinch_zoom_scrollbar_vertical_layer_id_));
582}
583
584void LayerTreeImpl::UpdatePinchZoomScrollbars() {
585 LayerImpl* root_scroll_layer = RootScrollLayer();
586 if (!root_scroll_layer)
587 return;
588
589 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) {
590 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x());
591 scrollbar->SetTotalSize(root_scroll_layer->bounds().width());
592 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x());
593 }
594 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) {
595 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y());
596 scrollbar->SetTotalSize(root_scroll_layer->bounds().height());
597 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().y());
598 }
599}
600
601static scoped_ptr<Animation> MakePinchZoomFadeAnimation(
602 float start_opacity, float end_opacity) {
603 scoped_ptr<KeyframedFloatAnimationCurve> curve =
604 KeyframedFloatAnimationCurve::Create();
605 curve->AddKeyframe(FloatKeyframe::Create(
606 0, start_opacity, EaseInTimingFunction::create()));
607 curve->AddKeyframe(FloatKeyframe::Create(
608 PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity,
609 EaseInTimingFunction::create()));
610
611 scoped_ptr<Animation> animation = Animation::Create(
612 curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(),
613 0, Animation::Opacity);
614 animation->set_is_impl_only(true);
615
616 return animation.Pass();
617}
618
619static void StartFadeInAnimation(ScrollbarLayerImpl* layer) {
620 DCHECK(layer);
621 float start_opacity = layer->opacity();
622 LayerAnimationController* controller = layer->layer_animation_controller();
623 // TODO() It shouldn't be necessary to manually remove the old animation.
624 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
625 controller->RemoveAnimation(animation->id());
626 controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity,
627 PinchZoomScrollbar::kDefaultOpacity));
628}
629
630void LayerTreeImpl::FadeInPinchZoomScrollbars() {
631 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1)
632 return;
633
634 StartFadeInAnimation(PinchZoomScrollbarHorizontal());
635 StartFadeInAnimation(PinchZoomScrollbarVertical());
636}
637
638static void StartFadeOutAnimation(LayerImpl* layer) {
639 float opacity = layer->opacity();
640 if (!opacity)
641 return;
642
643 LayerAnimationController* controller = layer->layer_animation_controller();
644 // TODO(wjmaclean) It shouldn't be necessary to manually remove the old
645 // animation.
646 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
647 controller->RemoveAnimation(animation->id());
648 controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0));
649}
650
651void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
652 if (!HasPinchZoomScrollbars())
653 return;
654
655 StartFadeOutAnimation(PinchZoomScrollbarHorizontal());
656 StartFadeOutAnimation(PinchZoomScrollbarVertical());
657}
658
659bool LayerTreeImpl::HasPinchZoomScrollbars() const {
660 return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID &&
661 pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID;
662}
663
664
[email protected]3b31c6ac2012-12-06 21:27:29665} // namespace cc