blob: 32cf6495523fb0bf9e8011088ff96604359a8ded [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]f6742f52013-05-08 23:52:2212#include "cc/debug/traced_value.h"
[email protected]cdb284d72013-03-18 09:34:4813#include "cc/input/pinch_zoom_scrollbar.h"
[email protected]cc3cfaa2013-03-18 09:05:5214#include "cc/layers/heads_up_display_layer_impl.h"
15#include "cc/layers/layer.h"
[email protected]50761e92013-03-29 20:51:2816#include "cc/layers/render_surface_impl.h"
[email protected]cc3cfaa2013-03-18 09:05:5217#include "cc/layers/scrollbar_layer_impl.h"
[email protected]556fd292013-03-18 08:03:0418#include "cc/trees/layer_tree_host_common.h"
19#include "cc/trees/layer_tree_host_impl.h"
[email protected]ffb2720f2013-03-15 19:18:3720#include "ui/gfx/size_conversions.h"
[email protected]caa567d2012-12-20 07:56:1621#include "ui/gfx/vector2d_conversions.h"
[email protected]3b31c6ac2012-12-06 21:27:2922
23namespace cc {
24
[email protected]8bef40572012-12-11 21:38:0825LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
[email protected]db8259f2013-02-01 05:25:0426 : layer_tree_host_impl_(layer_tree_host_impl),
27 source_frame_number_(-1),
28 hud_layer_(0),
[email protected]1960a712013-04-30 17:06:4729 root_scroll_layer_(NULL),
30 currently_scrolling_layer_(NULL),
31 root_layer_scroll_offset_delegate_(NULL),
[email protected]db8259f2013-02-01 05:25:0432 background_color_(0),
33 has_transparent_background_(false),
[email protected]b7c4783f2013-03-15 23:11:4234 pinch_zoom_scrollbar_horizontal_layer_id_(Layer::INVALID_ID),
35 pinch_zoom_scrollbar_vertical_layer_id_(Layer::INVALID_ID),
[email protected]db8259f2013-02-01 05:25:0436 page_scale_factor_(1),
37 page_scale_delta_(1),
38 sent_page_scale_delta_(1),
39 min_page_scale_factor_(0),
40 max_page_scale_factor_(0),
41 scrolling_layer_id_from_previous_tree_(0),
42 contents_textures_purged_(false),
[email protected]318822852013-02-14 00:54:2743 viewport_size_invalid_(false),
[email protected]db8259f2013-02-01 05:25:0444 needs_update_draw_properties_(true),
45 needs_full_tree_sync_(true) {
[email protected]3b31c6ac2012-12-06 21:27:2946}
47
48LayerTreeImpl::~LayerTreeImpl() {
[email protected]361bc00d2012-12-14 07:03:2449 // Need to explicitly clear the tree prior to destroying this so that
50 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
51 root_layer_.reset();
[email protected]3b31c6ac2012-12-06 21:27:2952}
53
[email protected]3c0a3252013-03-18 04:24:3654static LayerImpl* FindRootScrollLayerRecursive(LayerImpl* layer) {
55 if (!layer)
56 return NULL;
[email protected]3b31c6ac2012-12-06 21:27:2957
[email protected]3c0a3252013-03-18 04:24:3658 if (layer->scrollable())
59 return layer;
[email protected]3b31c6ac2012-12-06 21:27:2960
[email protected]3c0a3252013-03-18 04:24:3661 for (size_t i = 0; i < layer->children().size(); ++i) {
62 LayerImpl* found = FindRootScrollLayerRecursive(layer->children()[i]);
63 if (found)
64 return found;
65 }
[email protected]3b31c6ac2012-12-06 21:27:2966
[email protected]3c0a3252013-03-18 04:24:3667 return NULL;
[email protected]3b31c6ac2012-12-06 21:27:2968}
69
70void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
[email protected]1960a712013-04-30 17:06:4771 if (root_scroll_layer_)
72 root_scroll_layer_->SetScrollOffsetDelegate(NULL);
[email protected]3b31c6ac2012-12-06 21:27:2973 root_layer_ = layer.Pass();
[email protected]5c4824e12013-01-12 16:34:5374 currently_scrolling_layer_ = NULL;
[email protected]1960a712013-04-30 17:06:4775 root_scroll_layer_ = NULL;
[email protected]5c4824e12013-01-12 16:34:5376
[email protected]c1bb5af2013-03-13 19:06:2777 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]5c4824e12013-01-12 16:34:5378}
79
80void LayerTreeImpl::FindRootScrollLayer() {
[email protected]3c0a3252013-03-18 04:24:3681 root_scroll_layer_ = FindRootScrollLayerRecursive(root_layer_.get());
[email protected]3b31c6ac2012-12-06 21:27:2982
[email protected]1960a712013-04-30 17:06:4783 if (root_scroll_layer_) {
84 root_scroll_layer_->SetScrollOffsetDelegate(
85 root_layer_scroll_offset_delegate_);
86 }
87
[email protected]3b31c6ac2012-12-06 21:27:2988 if (root_layer_ && scrolling_layer_id_from_previous_tree_) {
[email protected]6ba914122013-03-22 16:26:3989 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
[email protected]3b31c6ac2012-12-06 21:27:2990 root_layer_.get(),
91 scrolling_layer_id_from_previous_tree_);
92 }
93
94 scrolling_layer_id_from_previous_tree_ = 0;
[email protected]3b31c6ac2012-12-06 21:27:2995}
96
97scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
98 // Clear all data structures that have direct references to the layer tree.
99 scrolling_layer_id_from_previous_tree_ =
100 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]1960a712013-04-30 17:06:47101 if (root_scroll_layer_)
102 root_scroll_layer_->SetScrollOffsetDelegate(NULL);
[email protected]69b50ec2013-01-19 04:58:01103 root_scroll_layer_ = NULL;
[email protected]3b31c6ac2012-12-06 21:27:29104 currently_scrolling_layer_ = NULL;
105
[email protected]76ffd9e2012-12-20 19:12:47106 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16107 set_needs_update_draw_properties();
[email protected]3b31c6ac2012-12-06 21:27:29108 return root_layer_.Pass();
109}
110
[email protected]7aba6662013-03-12 10:17:34111void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
[email protected]e4c3c87a2013-04-22 02:28:40112 target_tree->SetLatencyInfo(latency_info_);
113 latency_info_.Clear();
[email protected]c60279472013-01-30 12:10:51114 target_tree->SetPageScaleFactorAndLimits(
115 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor());
116 target_tree->SetPageScaleDelta(
117 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta());
118 target_tree->set_sent_page_scale_delta(1);
119
120 // This should match the property synchronization in
121 // LayerTreeHost::finishCommitOnImplThread().
122 target_tree->set_source_frame_number(source_frame_number());
123 target_tree->set_background_color(background_color());
124 target_tree->set_has_transparent_background(has_transparent_background());
125
126 if (ContentsTexturesPurged())
127 target_tree->SetContentsTexturesPurged();
128 else
129 target_tree->ResetContentsTexturesPurged();
130
[email protected]318822852013-02-14 00:54:27131 if (ViewportSizeInvalid())
132 target_tree->SetViewportSizeInvalid();
133 else
134 target_tree->ResetViewportSizeInvalid();
135
[email protected]c60279472013-01-30 12:10:51136 if (hud_layer())
137 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
[email protected]6ba914122013-03-22 16:26:39138 LayerTreeHostCommon::FindLayerInSubtree(
[email protected]c1bb5af2013-03-13 19:06:27139 target_tree->root_layer(), hud_layer()->id())));
[email protected]c60279472013-01-30 12:10:51140 else
141 target_tree->set_hud_layer(NULL);
[email protected]b7c4783f2013-03-15 23:11:42142
143 target_tree->SetPinchZoomHorizontalLayerId(
144 pinch_zoom_scrollbar_horizontal_layer_id_);
145 target_tree->SetPinchZoomVerticalLayerId(
146 pinch_zoom_scrollbar_vertical_layer_id_);
[email protected]c60279472013-01-30 12:10:51147}
148
[email protected]ffb2720f2013-03-15 19:18:37149LayerImpl* LayerTreeImpl::RootScrollLayer() const {
[email protected]69b50ec2013-01-19 04:58:01150 DCHECK(IsActiveTree());
151 return root_scroll_layer_;
152}
153
[email protected]ffb2720f2013-03-15 19:18:37154LayerImpl* LayerTreeImpl::RootClipLayer() const {
155 return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL;
156}
157
158LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
[email protected]69b50ec2013-01-19 04:58:01159 DCHECK(IsActiveTree());
160 return currently_scrolling_layer_;
161}
162
[email protected]0fc818e2013-03-18 06:45:20163void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
164 if (currently_scrolling_layer_ == layer)
165 return;
166
167 if (currently_scrolling_layer_ &&
168 currently_scrolling_layer_->scrollbar_animation_controller())
[email protected]6bc09e82013-03-19 03:48:35169 currently_scrolling_layer_->scrollbar_animation_controller()->
[email protected]fb7425a2013-04-22 16:28:55170 DidScrollGestureEnd(CurrentFrameTimeTicks());
[email protected]0fc818e2013-03-18 06:45:20171 currently_scrolling_layer_ = layer;
172 if (layer && layer->scrollbar_animation_controller())
[email protected]6bc09e82013-03-19 03:48:35173 layer->scrollbar_animation_controller()->DidScrollGestureBegin();
[email protected]0fc818e2013-03-18 06:45:20174}
175
[email protected]3b31c6ac2012-12-06 21:27:29176void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
[email protected]0fc818e2013-03-18 06:45:20177 SetCurrentlyScrollingLayer(NULL);
[email protected]3b31c6ac2012-12-06 21:27:29178 scrolling_layer_id_from_previous_tree_ = 0;
179}
180
[email protected]c60279472013-01-30 12:10:51181void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
[email protected]3c0a3252013-03-18 04:24:36182 float min_page_scale_factor, float max_page_scale_factor) {
[email protected]c60279472013-01-30 12:10:51183 if (!page_scale_factor)
184 return;
185
186 min_page_scale_factor_ = min_page_scale_factor;
187 max_page_scale_factor_ = max_page_scale_factor;
188 page_scale_factor_ = page_scale_factor;
189}
190
[email protected]3c0a3252013-03-18 04:24:36191void LayerTreeImpl::SetPageScaleDelta(float delta) {
[email protected]c60279472013-01-30 12:10:51192 // Clamp to the current min/max limits.
193 float total = page_scale_factor_ * delta;
194 if (min_page_scale_factor_ && total < min_page_scale_factor_)
195 delta = min_page_scale_factor_ / page_scale_factor_;
196 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
197 delta = max_page_scale_factor_ / page_scale_factor_;
198
199 if (delta == page_scale_delta_)
200 return;
201
202 page_scale_delta_ = delta;
203
204 if (IsActiveTree()) {
[email protected]c1bb5af2013-03-13 19:06:27205 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
[email protected]c60279472013-01-30 12:10:51206 if (pending_tree) {
207 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
[email protected]ca2902e92013-03-28 01:45:35208 pending_tree->SetPageScaleDelta(
209 page_scale_delta_ / sent_page_scale_delta_);
[email protected]c60279472013-01-30 12:10:51210 }
211 }
212
213 UpdateMaxScrollOffset();
214 set_needs_update_draw_properties();
215}
216
[email protected]257abfa82013-01-29 23:47:24217gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]ffb2720f2013-03-15 19:18:37218 return gfx::ScaleSize(layer_tree_host_impl_->VisibleViewportSize(),
219 1.0f / total_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24220}
221
[email protected]caa567d2012-12-20 07:56:16222void LayerTreeImpl::UpdateMaxScrollOffset() {
[email protected]69b50ec2013-01-19 04:58:01223 if (!root_scroll_layer_ || !root_scroll_layer_->children().size())
[email protected]caa567d2012-12-20 07:56:16224 return;
225
[email protected]42ccdbef2013-01-21 07:54:54226 gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() -
[email protected]257abfa82013-01-29 23:47:24227 gfx::RectF(ScrollableViewportSize()).bottom_right();
[email protected]caa567d2012-12-20 07:56:16228
229 // The viewport may be larger than the contents in some cases, such as
230 // having a vertical scrollbar but no horizontal overflow.
231 max_scroll.ClampToMin(gfx::Vector2dF());
232
[email protected]7aba6662013-03-12 10:17:34233 root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll));
[email protected]caa567d2012-12-20 07:56:16234}
235
[email protected]ffb2720f2013-03-15 19:18:37236void LayerTreeImpl::UpdateSolidColorScrollbars() {
[email protected]8e0176d2013-03-21 03:14:52237 DCHECK(settings().solid_color_scrollbars);
[email protected]ffb2720f2013-03-15 19:18:37238
239 LayerImpl* root_scroll = RootScrollLayer();
[email protected]ab5f4a92013-03-19 20:08:24240 DCHECK(root_scroll);
241 DCHECK(IsActiveTree());
[email protected]ffb2720f2013-03-15 19:18:37242
243 gfx::RectF scrollable_viewport(
244 gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()),
245 ScrollableViewportSize());
246 float vertical_adjust = 0.0f;
247 if (RootClipLayer())
248 vertical_adjust = layer_tree_host_impl_->VisibleViewportSize().height() -
249 RootClipLayer()->bounds().height();
250 if (ScrollbarLayerImpl* horiz = root_scroll->horizontal_scrollbar_layer()) {
251 horiz->set_vertical_adjust(vertical_adjust);
252 horiz->SetViewportWithinScrollableArea(scrollable_viewport,
253 ScrollableSize());
254 }
255 if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) {
256 vertical->set_vertical_adjust(vertical_adjust);
257 vertical->SetViewportWithinScrollableArea(scrollable_viewport,
258 ScrollableSize());
259 }
260}
261
[email protected]7d19dc342013-05-02 22:02:04262void LayerTreeImpl::UpdateDrawProperties() {
[email protected]fe956c9c42013-04-09 04:26:33263 if (IsActiveTree() && RootScrollLayer() && RootClipLayer())
264 UpdateRootScrollLayerSizeDelta();
265
[email protected]ca2902e92013-03-28 01:45:35266 if (settings().solid_color_scrollbars &&
267 IsActiveTree() &&
268 RootScrollLayer()) {
[email protected]ffb2720f2013-03-15 19:18:37269 UpdateSolidColorScrollbars();
270
271 // The top controls manager is incompatible with the WebKit-created cliprect
272 // because it can bring into view a larger amount of content when it
273 // hides. It's safe to deactivate the clip rect if no non-overlay scrollbars
274 // are present.
[email protected]ab5f4a92013-03-19 20:08:24275 if (RootClipLayer() && layer_tree_host_impl_->top_controls_manager())
276 RootClipLayer()->SetMasksToBounds(false);
[email protected]ffb2720f2013-03-15 19:18:37277 }
278
[email protected]615c78a2013-01-24 23:44:16279 needs_update_draw_properties_ = false;
[email protected]76ffd9e2012-12-20 19:12:47280 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16281
[email protected]ed511b8d2013-03-25 03:29:29282 // For max_texture_size.
[email protected]615c78a2013-01-24 23:44:16283 if (!layer_tree_host_impl_->renderer())
284 return;
285
[email protected]c1bb5af2013-03-13 19:06:27286 if (!root_layer())
[email protected]76ffd9e2012-12-20 19:12:47287 return;
288
[email protected]76ffd9e2012-12-20 19:12:47289 {
[email protected]c1bb5af2013-03-13 19:06:27290 TRACE_EVENT1("cc",
291 "LayerTreeImpl::UpdateDrawProperties",
292 "IsActive",
293 IsActiveTree());
[email protected]6ba914122013-03-22 16:26:39294 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]f2136262013-04-26 21:10:19299 root_scroll_layer_,
[email protected]f6776532012-12-21 20:24:33300 MaxTextureSize(),
[email protected]8e0176d2013-03-21 03:14:52301 settings().can_use_lcd_text,
[email protected]35a99a12013-05-09 23:52:29302 settings().layer_transforms_should_scale_layer_contents,
[email protected]7d19dc342013-05-02 22:02:04303 &render_surface_layer_list_);
[email protected]76ffd9e2012-12-20 19:12:47304 }
[email protected]615c78a2013-01-24 23:44:16305
306 DCHECK(!needs_update_draw_properties_) <<
[email protected]7d19dc342013-05-02 22:02:04307 "CalcDrawProperties should not set_needs_update_draw_properties()";
[email protected]76ffd9e2012-12-20 19:12:47308}
309
[email protected]3c0a3252013-03-18 04:24:36310static void ClearRenderSurfacesOnLayerImplRecursive(LayerImpl* current) {
311 DCHECK(current);
312 for (size_t i = 0; i < current->children().size(); ++i)
313 ClearRenderSurfacesOnLayerImplRecursive(current->children()[i]);
314 current->ClearRenderSurface();
[email protected]76ffd9e2012-12-20 19:12:47315}
316
317void LayerTreeImpl::ClearRenderSurfaces() {
[email protected]2a61ad52013-05-13 14:01:29318 if (root_layer() == NULL) {
319 DCHECK(render_surface_layer_list_.empty());
320 return;
321 }
[email protected]c1bb5af2013-03-13 19:06:27322 ClearRenderSurfacesOnLayerImplRecursive(root_layer());
[email protected]76ffd9e2012-12-20 19:12:47323 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16324 set_needs_update_draw_properties();
[email protected]76ffd9e2012-12-20 19:12:47325}
326
[email protected]b0a917c8d2013-01-12 17:42:25327bool LayerTreeImpl::AreVisibleResourcesReady() const {
328 TRACE_EVENT0("cc", "LayerTreeImpl::AreVisibleResourcesReady");
329
330 typedef LayerIterator<LayerImpl,
[email protected]50761e92013-03-29 20:51:28331 LayerImplList,
[email protected]b0a917c8d2013-01-12 17:42:25332 RenderSurfaceImpl,
333 LayerIteratorActions::BackToFront> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09334 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
335 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]b0a917c8d2013-01-12 17:42:25336 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09337 if (it.represents_itself() && !(*it)->AreVisibleResourcesReady())
[email protected]b0a917c8d2013-01-12 17:42:25338 return false;
339 }
340
341 return true;
342}
343
[email protected]50761e92013-03-29 20:51:28344const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const {
[email protected]76ffd9e2012-12-20 19:12:47345 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16346 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47347 return render_surface_layer_list_;
348}
349
[email protected]42ccdbef2013-01-21 07:54:54350gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]c4d467a2013-01-21 03:21:01351 if (!root_scroll_layer_ || root_scroll_layer_->children().empty())
[email protected]caa567d2012-12-20 07:56:16352 return gfx::Size();
[email protected]c4d467a2013-01-21 03:21:01353 return root_scroll_layer_->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16354}
355
[email protected]361bc00d2012-12-14 07:03:24356LayerImpl* LayerTreeImpl::LayerById(int id) {
357 LayerIdMap::iterator iter = layer_id_map_.find(id);
358 return iter != layer_id_map_.end() ? iter->second : NULL;
359}
360
361void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
362 DCHECK(!LayerById(layer->id()));
363 layer_id_map_[layer->id()] = layer;
364}
365
366void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
367 DCHECK(LayerById(layer->id()));
368 layer_id_map_.erase(layer->id());
369}
370
[email protected]ed511b8d2013-03-25 03:29:29371void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) {
[email protected]1e0f8d62013-01-09 07:41:35372 int id = currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]2a61ad52013-05-13 14:01:29373 LayerImpl* pending_scrolling_layer_twin = NULL;
374 if (pending_tree->root_layer()) {
375 pending_scrolling_layer_twin =
376 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), id);
377 }
378 pending_tree->SetCurrentlyScrollingLayer(pending_scrolling_layer_twin);
[email protected]1e0f8d62013-01-09 07:41:35379}
380
[email protected]37386f052013-01-13 00:42:22381static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34382 layer->DidBecomeActive();
[email protected]37386f052013-01-13 00:42:22383 for (size_t i = 0; i < layer->children().size(); ++i)
384 DidBecomeActiveRecursive(layer->children()[i]);
385}
386
387void LayerTreeImpl::DidBecomeActive() {
[email protected]c1bb5af2013-03-13 19:06:27388 if (root_layer())
389 DidBecomeActiveRecursive(root_layer());
[email protected]69b50ec2013-01-19 04:58:01390 FindRootScrollLayer();
391 UpdateMaxScrollOffset();
[email protected]b7c4783f2013-03-15 23:11:42392 // Main thread scrolls do not get handled in LayerTreeHostImpl, so after
393 // each commit (and after the root scroll layer has its max scroll offset
394 // set), we need to update pinch zoom scrollbars.
395 UpdatePinchZoomScrollbars();
[email protected]37386f052013-01-13 00:42:22396}
397
[email protected]6f90b9e2013-01-17 23:42:00398bool LayerTreeImpl::ContentsTexturesPurged() const {
399 return contents_textures_purged_;
400}
401
402void LayerTreeImpl::SetContentsTexturesPurged() {
403 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27404 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00405}
406
407void LayerTreeImpl::ResetContentsTexturesPurged() {
408 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27409 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00410}
411
[email protected]318822852013-02-14 00:54:27412bool LayerTreeImpl::ViewportSizeInvalid() const {
413 return viewport_size_invalid_;
414}
415
416void LayerTreeImpl::SetViewportSizeInvalid() {
417 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27418 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27419}
420
421void LayerTreeImpl::ResetViewportSizeInvalid() {
422 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27423 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27424}
425
[email protected]48871fc2013-01-23 07:36:51426Proxy* LayerTreeImpl::proxy() const {
427 return layer_tree_host_impl_->proxy();
428}
429
[email protected]ff762fb2012-12-12 19:18:37430const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27431 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37432}
433
[email protected]ed511b8d2013-03-25 03:29:29434const RendererCapabilities& LayerTreeImpl::GetRendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27435 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52436}
437
[email protected]ff762fb2012-12-12 19:18:37438OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27439 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37440}
441
442ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27443 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37444}
445
446TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27447 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37448}
449
450FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27451 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37452}
453
[email protected]71691c22013-01-18 03:14:22454PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27455 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22456}
457
[email protected]1191d9d2013-02-02 06:00:33458MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27459 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33460}
461
[email protected]f117a4c2012-12-16 04:53:10462bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27463 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10464}
465
466bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27467 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10468}
469
[email protected]48871fc2013-01-23 07:36:51470bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27471 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51472}
473
[email protected]f117a4c2012-12-16 04:53:10474LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27475 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10476 if (!tree)
477 return NULL;
478 return tree->LayerById(id);
479}
480
481LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27482 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10483 if (!tree)
484 return NULL;
485 return tree->LayerById(id);
486}
487
[email protected]f6776532012-12-21 20:24:33488int LayerTreeImpl::MaxTextureSize() const {
[email protected]c1bb5af2013-03-13 19:06:27489 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size;
[email protected]f6776532012-12-21 20:24:33490}
491
[email protected]166db5c82013-01-09 23:54:31492bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27493 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31494}
495
[email protected]fb7425a2013-04-22 16:28:55496base::TimeTicks LayerTreeImpl::CurrentFrameTimeTicks() const {
497 return layer_tree_host_impl_->CurrentFrameTimeTicks();
498}
499
500base::Time LayerTreeImpl::CurrentFrameTime() const {
[email protected]c1bb5af2013-03-13 19:06:27501 return layer_tree_host_impl_->CurrentFrameTime();
[email protected]829ad972013-01-28 23:36:10502}
503
[email protected]d7eb8c72013-03-23 22:57:13504void LayerTreeImpl::SetNeedsCommit() {
505 layer_tree_host_impl_->SetNeedsCommit();
506}
507
[email protected]ff762fb2012-12-12 19:18:37508void LayerTreeImpl::SetNeedsRedraw() {
[email protected]59adb112013-04-09 04:48:44509 layer_tree_host_impl_->SetNeedsRedraw();
[email protected]ff762fb2012-12-12 19:18:37510}
511
[email protected]ff762fb2012-12-12 19:18:37512const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27513 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37514}
515
516float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27517 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37518}
519
[email protected]90ec9872013-03-08 02:28:18520gfx::Size LayerTreeImpl::device_viewport_size() const {
[email protected]c1bb5af2013-03-13 19:06:27521 return layer_tree_host_impl_->device_viewport_size();
[email protected]ff762fb2012-12-12 19:18:37522}
523
[email protected]ff762fb2012-12-12 19:18:37524std::string LayerTreeImpl::layer_tree_as_text() const {
[email protected]c1bb5af2013-03-13 19:06:27525 return layer_tree_host_impl_->LayerTreeAsText();
[email protected]ff762fb2012-12-12 19:18:37526}
527
528DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27529 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37530}
531
[email protected]de4afb5e2012-12-20 00:11:34532AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27533 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34534}
[email protected]ff762fb2012-12-12 19:18:37535
[email protected]8c5690222013-02-15 17:36:43536scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
[email protected]f6742f52013-05-08 23:52:22537 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
538 TracedValue::MakeDictIntoImplicitSnapshot(
539 state.get(), "cc::LayerTreeImpl", this);
540
541 state->Set("root_layer", root_layer_->AsValue().release());
542
543 scoped_ptr<base::ListValue> render_surface_layer_list(new base::ListValue());
[email protected]8c5690222013-02-15 17:36:43544 typedef LayerIterator<LayerImpl,
[email protected]50761e92013-03-29 20:51:28545 LayerImplList,
[email protected]8c5690222013-02-15 17:36:43546 RenderSurfaceImpl,
547 LayerIteratorActions::BackToFront> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09548 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
549 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]8c5690222013-02-15 17:36:43550 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09551 if (!it.represents_itself())
[email protected]8c5690222013-02-15 17:36:43552 continue;
[email protected]f6742f52013-05-08 23:52:22553 render_surface_layer_list->Append(TracedValue::CreateIDRef(*it).release());
[email protected]8c5690222013-02-15 17:36:43554 }
[email protected]f6742f52013-05-08 23:52:22555
556 state->Set("render_surface_layer_list",
557 render_surface_layer_list.release());
[email protected]8c5690222013-02-15 17:36:43558 return state.PassAs<base::Value>();
559}
560
[email protected]b7c4783f2013-03-15 23:11:42561void LayerTreeImpl::DidBeginScroll() {
562 if (HasPinchZoomScrollbars())
563 FadeInPinchZoomScrollbars();
564}
565
566void LayerTreeImpl::DidUpdateScroll() {
567 if (HasPinchZoomScrollbars())
568 UpdatePinchZoomScrollbars();
569}
570
571void LayerTreeImpl::DidEndScroll() {
572 if (HasPinchZoomScrollbars())
573 FadeOutPinchZoomScrollbars();
574}
575
[email protected]1960a712013-04-30 17:06:47576void LayerTreeImpl::SetRootLayerScrollOffsetDelegate(
577 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
578 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
579 if (root_scroll_layer_) {
580 root_scroll_layer_->SetScrollOffsetDelegate(
581 root_layer_scroll_offset_delegate_);
582 }
583}
584
[email protected]b7c4783f2013-03-15 23:11:42585void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) {
586 pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id;
587}
588
589ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() {
590 return static_cast<ScrollbarLayerImpl*>(LayerById(
591 pinch_zoom_scrollbar_horizontal_layer_id_));
592}
593
594void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) {
595 pinch_zoom_scrollbar_vertical_layer_id_ = layer_id;
596}
597
598ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() {
599 return static_cast<ScrollbarLayerImpl*>(LayerById(
600 pinch_zoom_scrollbar_vertical_layer_id_));
601}
602
603void LayerTreeImpl::UpdatePinchZoomScrollbars() {
604 LayerImpl* root_scroll_layer = RootScrollLayer();
605 if (!root_scroll_layer)
606 return;
607
608 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) {
609 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x());
610 scrollbar->SetTotalSize(root_scroll_layer->bounds().width());
611 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x());
612 }
613 if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) {
614 scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y());
615 scrollbar->SetTotalSize(root_scroll_layer->bounds().height());
616 scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().y());
617 }
618}
619
620static scoped_ptr<Animation> MakePinchZoomFadeAnimation(
621 float start_opacity, float end_opacity) {
622 scoped_ptr<KeyframedFloatAnimationCurve> curve =
623 KeyframedFloatAnimationCurve::Create();
624 curve->AddKeyframe(FloatKeyframe::Create(
[email protected]befd0f52013-03-24 10:00:36625 0, start_opacity, EaseInTimingFunction::Create()));
[email protected]b7c4783f2013-03-15 23:11:42626 curve->AddKeyframe(FloatKeyframe::Create(
627 PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity,
[email protected]befd0f52013-03-24 10:00:36628 EaseInTimingFunction::Create()));
[email protected]b7c4783f2013-03-15 23:11:42629
630 scoped_ptr<Animation> animation = Animation::Create(
631 curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(),
632 0, Animation::Opacity);
633 animation->set_is_impl_only(true);
634
635 return animation.Pass();
636}
637
638static void StartFadeInAnimation(ScrollbarLayerImpl* layer) {
639 DCHECK(layer);
640 float start_opacity = layer->opacity();
641 LayerAnimationController* controller = layer->layer_animation_controller();
[email protected]ca2902e92013-03-28 01:45:35642 // TODO(wjmaclean) It shouldn't be necessary to manually remove the old
643 // animation.
[email protected]b7c4783f2013-03-15 23:11:42644 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
645 controller->RemoveAnimation(animation->id());
646 controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity,
647 PinchZoomScrollbar::kDefaultOpacity));
648}
649
650void LayerTreeImpl::FadeInPinchZoomScrollbars() {
651 if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1)
652 return;
653
654 StartFadeInAnimation(PinchZoomScrollbarHorizontal());
655 StartFadeInAnimation(PinchZoomScrollbarVertical());
[email protected]2da0d472013-04-19 03:28:37656 SetNeedsRedraw();
[email protected]b7c4783f2013-03-15 23:11:42657}
658
659static void StartFadeOutAnimation(LayerImpl* layer) {
660 float opacity = layer->opacity();
661 if (!opacity)
662 return;
663
664 LayerAnimationController* controller = layer->layer_animation_controller();
665 // TODO(wjmaclean) It shouldn't be necessary to manually remove the old
666 // animation.
667 if (Animation* animation = controller->GetAnimation(Animation::Opacity))
668 controller->RemoveAnimation(animation->id());
669 controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0));
670}
671
672void LayerTreeImpl::FadeOutPinchZoomScrollbars() {
673 if (!HasPinchZoomScrollbars())
674 return;
675
676 StartFadeOutAnimation(PinchZoomScrollbarHorizontal());
677 StartFadeOutAnimation(PinchZoomScrollbarVertical());
[email protected]2da0d472013-04-19 03:28:37678 SetNeedsRedraw();
[email protected]b7c4783f2013-03-15 23:11:42679}
680
681bool LayerTreeImpl::HasPinchZoomScrollbars() const {
682 return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID &&
683 pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID;
684}
685
[email protected]fe956c9c42013-04-09 04:26:33686void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() {
687 LayerImpl* root_scroll = RootScrollLayer();
688 LayerImpl* root_clip = RootClipLayer();
689 DCHECK(root_scroll);
690 DCHECK(root_clip);
691 DCHECK(IsActiveTree());
692
693 gfx::Vector2dF scrollable_viewport_size =
694 gfx::RectF(ScrollableViewportSize()).bottom_right() - gfx::PointF();
695
696 gfx::Vector2dF original_viewport_size =
697 gfx::RectF(root_clip->bounds()).bottom_right() -
698 gfx::PointF();
699 original_viewport_size.Scale(1 / page_scale_factor());
700
701 root_scroll->SetFixedContainerSizeDelta(
702 scrollable_viewport_size - original_viewport_size);
703}
704
[email protected]e4c3c87a2013-04-22 02:28:40705void LayerTreeImpl::SetLatencyInfo(const LatencyInfo& latency_info) {
706 latency_info_.MergeWith(latency_info);
707}
708
709const LatencyInfo& LayerTreeImpl::GetLatencyInfo() {
710 return latency_info_;
711}
712
713void LayerTreeImpl::ClearLatencyInfo() {
714 latency_info_.Clear();
715}
716
[email protected]ca2902e92013-03-28 01:45:35717} // namespace cc