blob: a278fbfc988e51fc8cf63086720e4b010d545642 [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]28336d52014-05-12 19:07:287#include <limits>
8#include <set>
9
[email protected]76ffd9e2012-12-20 19:12:4710#include "base/debug/trace_event.h"
[email protected]d12aa932014-08-01 13:10:3811#include "base/debug/trace_event_argument.h"
[email protected]95e4e1a02013-03-18 07:09:0912#include "cc/animation/keyframed_animation_curve.h"
13#include "cc/animation/scrollbar_animation_controller.h"
[email protected]930ff43b2014-05-02 05:24:0014#include "cc/animation/scrollbar_animation_controller_linear_fade.h"
15#include "cc/animation/scrollbar_animation_controller_thinning.h"
[email protected]3744e27b2013-11-06 21:44:0816#include "cc/base/math_util.h"
17#include "cc/base/util.h"
[email protected]12a63da2014-06-13 06:06:2218#include "cc/debug/devtools_instrumentation.h"
[email protected]f6742f52013-05-08 23:52:2219#include "cc/debug/traced_value.h"
bokan915bf352014-10-02 21:57:1420#include "cc/input/page_scale_animation.h"
[email protected]cc3cfaa2013-03-18 09:05:5221#include "cc/layers/heads_up_display_layer_impl.h"
[email protected]57ac9482013-09-17 21:13:3922#include "cc/layers/layer.h"
[email protected]34ba1ffb2014-03-05 06:55:0323#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2824#include "cc/layers/render_surface_impl.h"
[email protected]80413d72013-08-30 20:25:3325#include "cc/layers/scrollbar_layer_impl_base.h"
[email protected]e1042192013-11-08 05:44:2426#include "cc/resources/ui_resource_request.h"
[email protected]556fd292013-03-18 08:03:0427#include "cc/trees/layer_tree_host_common.h"
28#include "cc/trees/layer_tree_host_impl.h"
[email protected]562b7ad2014-06-23 22:17:1129#include "cc/trees/occlusion_tracker.h"
heejin.r.chungd28506ba2014-10-23 16:36:2030#include "ui/gfx/geometry/point_conversions.h"
31#include "ui/gfx/geometry/size_conversions.h"
32#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]3b31c6ac2012-12-06 21:27:2933
34namespace cc {
35
[email protected]adeda572014-01-31 00:49:4736// This class exists to split the LayerScrollOffsetDelegate between the
37// InnerViewportScrollLayer and the OuterViewportScrollLayer in a manner
38// that never requires the embedder or LayerImpl to know about.
[email protected]ec2322e2014-05-15 16:32:0039class LayerScrollOffsetDelegateProxy : public LayerImpl::ScrollOffsetDelegate {
[email protected]adeda572014-01-31 00:49:4740 public:
41 LayerScrollOffsetDelegateProxy(LayerImpl* layer,
42 LayerScrollOffsetDelegate* delegate,
43 LayerTreeImpl* layer_tree)
44 : layer_(layer), delegate_(delegate), layer_tree_impl_(layer_tree) {}
[email protected]ec2322e2014-05-15 16:32:0045 virtual ~LayerScrollOffsetDelegateProxy() {}
[email protected]adeda572014-01-31 00:49:4746
miletusf57925d2014-10-01 19:38:1347 gfx::ScrollOffset last_set_scroll_offset() const {
[email protected]adeda572014-01-31 00:49:4748 return last_set_scroll_offset_;
49 }
50
51 // LayerScrollOffsetDelegate implementation.
dcheng716bedf2014-10-21 09:51:0852 void SetTotalScrollOffset(const gfx::ScrollOffset& new_offset) override {
[email protected]adeda572014-01-31 00:49:4753 last_set_scroll_offset_ = new_offset;
[email protected]adeda572014-01-31 00:49:4754 }
55
dcheng716bedf2014-10-21 09:51:0856 gfx::ScrollOffset GetTotalScrollOffset() override {
[email protected]adeda572014-01-31 00:49:4757 return layer_tree_impl_->GetDelegatedScrollOffset(layer_);
58 }
59
dcheng716bedf2014-10-21 09:51:0860 bool IsExternalFlingActive() const override {
[email protected]adeda572014-01-31 00:49:4761 return delegate_->IsExternalFlingActive();
62 }
63
bokan6747f5522014-10-24 19:28:5464 void Update() const override {
65 layer_tree_impl_->UpdateScrollOffsetDelegate();
66 }
67
[email protected]adeda572014-01-31 00:49:4768 private:
69 LayerImpl* layer_;
70 LayerScrollOffsetDelegate* delegate_;
71 LayerTreeImpl* layer_tree_impl_;
miletusf57925d2014-10-01 19:38:1372 gfx::ScrollOffset last_set_scroll_offset_;
[email protected]adeda572014-01-31 00:49:4773};
74
[email protected]8bef40572012-12-11 21:38:0875LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
[email protected]db8259f2013-02-01 05:25:0476 : layer_tree_host_impl_(layer_tree_host_impl),
77 source_frame_number_(-1),
78 hud_layer_(0),
[email protected]1960a712013-04-30 17:06:4779 currently_scrolling_layer_(NULL),
80 root_layer_scroll_offset_delegate_(NULL),
[email protected]db8259f2013-02-01 05:25:0481 background_color_(0),
82 has_transparent_background_(false),
[email protected]57ac9482013-09-17 21:13:3983 page_scale_layer_(NULL),
84 inner_viewport_scroll_layer_(NULL),
85 outer_viewport_scroll_layer_(NULL),
[email protected]db8259f2013-02-01 05:25:0486 page_scale_factor_(1),
87 page_scale_delta_(1),
88 sent_page_scale_delta_(1),
89 min_page_scale_factor_(0),
90 max_page_scale_factor_(0),
91 scrolling_layer_id_from_previous_tree_(0),
92 contents_textures_purged_(false),
[email protected]318822852013-02-14 00:54:2793 viewport_size_invalid_(false),
[email protected]db8259f2013-02-01 05:25:0494 needs_update_draw_properties_(true),
[email protected]7d08a9352013-10-15 08:24:5695 needs_full_tree_sync_(true),
[email protected]390bb1ff2014-05-09 17:14:4096 next_activation_forces_redraw_(false),
[email protected]759dc9f2014-07-23 19:18:5197 has_ever_been_drawn_(false),
bokan88eae012014-09-09 20:40:4298 render_surface_layer_list_id_(0),
99 top_controls_layout_height_(0),
bokan55b2f152014-09-15 14:47:59100 top_controls_content_offset_(0),
bokan88eae012014-09-09 20:40:42101 top_controls_delta_(0),
102 sent_top_controls_delta_(0) {
[email protected]390bb1ff2014-05-09 17:14:40103}
[email protected]3b31c6ac2012-12-06 21:27:29104
105LayerTreeImpl::~LayerTreeImpl() {
[email protected]586871b2014-07-22 17:05:11106 BreakSwapPromises(SwapPromise::SWAP_FAILS);
107
[email protected]361bc00d2012-12-14 07:03:24108 // Need to explicitly clear the tree prior to destroying this so that
109 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
[email protected]df17af52014-02-06 02:20:40110 DCHECK(!root_layer_);
111 DCHECK(layers_with_copy_output_request_.empty());
[email protected]3b31c6ac2012-12-06 21:27:29112}
113
danakjf446a072014-09-27 21:55:48114void LayerTreeImpl::Shutdown() {
115 root_layer_ = nullptr;
116}
[email protected]df17af52014-02-06 02:20:40117
[email protected]aeef2f02014-05-10 12:15:48118void LayerTreeImpl::ReleaseResources() {
119 if (root_layer_)
120 ReleaseResourcesRecursive(root_layer_.get());
121}
122
[email protected]d35cd7b22014-01-29 14:32:46123void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
[email protected]adeda572014-01-31 00:49:47124 if (inner_viewport_scroll_layer_)
125 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
126 if (outer_viewport_scroll_layer_)
127 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48128 inner_viewport_scroll_delegate_proxy_ = nullptr;
129 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]adeda572014-01-31 00:49:47130
[email protected]3b31c6ac2012-12-06 21:27:29131 root_layer_ = layer.Pass();
[email protected]5c4824e12013-01-12 16:34:53132 currently_scrolling_layer_ = NULL;
[email protected]adeda572014-01-31 00:49:47133 inner_viewport_scroll_layer_ = NULL;
134 outer_viewport_scroll_layer_ = NULL;
135 page_scale_layer_ = NULL;
[email protected]5c4824e12013-01-12 16:34:53136
[email protected]c1bb5af2013-03-13 19:06:27137 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]5c4824e12013-01-12 16:34:53138}
139
[email protected]adeda572014-01-31 00:49:47140LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const {
141 return inner_viewport_scroll_layer_;
142}
[email protected]3b31c6ac2012-12-06 21:27:29143
[email protected]adeda572014-01-31 00:49:47144LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const {
145 return outer_viewport_scroll_layer_;
146}
[email protected]1960a712013-04-30 17:06:47147
miletusf57925d2014-10-01 19:38:13148gfx::ScrollOffset LayerTreeImpl::TotalScrollOffset() const {
149 gfx::ScrollOffset offset;
[email protected]3b31c6ac2012-12-06 21:27:29150
[email protected]adeda572014-01-31 00:49:47151 if (inner_viewport_scroll_layer_)
152 offset += inner_viewport_scroll_layer_->TotalScrollOffset();
153
154 if (outer_viewport_scroll_layer_)
155 offset += outer_viewport_scroll_layer_->TotalScrollOffset();
156
157 return offset;
158}
159
miletusf57925d2014-10-01 19:38:13160gfx::ScrollOffset LayerTreeImpl::TotalMaxScrollOffset() const {
161 gfx::ScrollOffset offset;
[email protected]adeda572014-01-31 00:49:47162
163 if (inner_viewport_scroll_layer_)
164 offset += inner_viewport_scroll_layer_->MaxScrollOffset();
165
166 if (outer_viewport_scroll_layer_)
167 offset += outer_viewport_scroll_layer_->MaxScrollOffset();
168
169 return offset;
170}
171gfx::Vector2dF LayerTreeImpl::TotalScrollDelta() const {
172 DCHECK(inner_viewport_scroll_layer_);
173 gfx::Vector2dF delta = inner_viewport_scroll_layer_->ScrollDelta();
174
175 if (outer_viewport_scroll_layer_)
176 delta += outer_viewport_scroll_layer_->ScrollDelta();
177
178 return delta;
[email protected]3b31c6ac2012-12-06 21:27:29179}
180
181scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
182 // Clear all data structures that have direct references to the layer tree.
183 scrolling_layer_id_from_previous_tree_ =
184 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]adeda572014-01-31 00:49:47185 if (inner_viewport_scroll_layer_)
186 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
187 if (outer_viewport_scroll_layer_)
188 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48189 inner_viewport_scroll_delegate_proxy_ = nullptr;
190 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]adeda572014-01-31 00:49:47191 inner_viewport_scroll_layer_ = NULL;
192 outer_viewport_scroll_layer_ = NULL;
193 page_scale_layer_ = NULL;
[email protected]3b31c6ac2012-12-06 21:27:29194 currently_scrolling_layer_ = NULL;
195
[email protected]76ffd9e2012-12-20 19:12:47196 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16197 set_needs_update_draw_properties();
[email protected]3b31c6ac2012-12-06 21:27:29198 return root_layer_.Pass();
199}
200
[email protected]7aba6662013-03-12 10:17:34201void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
[email protected]c9280762013-08-01 06:28:57202 // The request queue should have been processed and does not require a push.
203 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
204
[email protected]7d08a9352013-10-15 08:24:56205 if (next_activation_forces_redraw_) {
[email protected]12a63da2014-06-13 06:06:22206 target_tree->ForceRedrawNextActivation();
[email protected]7d08a9352013-10-15 08:24:56207 next_activation_forces_redraw_ = false;
208 }
209
[email protected]b69c1db2013-11-27 00:05:19210 target_tree->PassSwapPromises(&swap_promise_list_);
211
bokan88eae012014-09-09 20:40:42212 target_tree->top_controls_layout_height_ = top_controls_layout_height_;
bokan55b2f152014-09-15 14:47:59213 target_tree->top_controls_content_offset_ = top_controls_content_offset_;
bokan88eae012014-09-09 20:40:42214 target_tree->top_controls_delta_ =
215 target_tree->top_controls_delta_ -
216 target_tree->sent_top_controls_delta_;
217 target_tree->sent_top_controls_delta_ = 0.f;
218
[email protected]d6021f6a2014-06-12 21:15:24219 target_tree->SetPageScaleValues(
220 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor(),
[email protected]c60279472013-01-30 12:10:51221 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta());
222 target_tree->set_sent_page_scale_delta(1);
223
bokanfcdbc182014-11-21 21:53:33224 target_tree->pending_page_scale_animation_ =
225 pending_page_scale_animation_.Pass();
bokan915bf352014-10-02 21:57:14226
[email protected]adeda572014-01-31 00:49:47227 if (page_scale_layer_ && inner_viewport_scroll_layer_) {
[email protected]57ac9482013-09-17 21:13:39228 target_tree->SetViewportLayersFromIds(
ccameron8230b68b2014-11-21 19:25:18229 overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id()
230 : Layer::INVALID_ID,
231 page_scale_layer_->id(), inner_viewport_scroll_layer_->id(),
[email protected]57ac9482013-09-17 21:13:39232 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
233 : Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47234 } else {
235 target_tree->ClearViewportLayers();
[email protected]57ac9482013-09-17 21:13:39236 }
[email protected]19aec372014-07-01 19:08:49237
[email protected]ebb179b2014-07-16 17:54:41238 target_tree->RegisterSelection(selection_start_, selection_end_);
[email protected]19aec372014-07-01 19:08:49239
[email protected]c60279472013-01-30 12:10:51240 // This should match the property synchronization in
241 // LayerTreeHost::finishCommitOnImplThread().
242 target_tree->set_source_frame_number(source_frame_number());
243 target_tree->set_background_color(background_color());
244 target_tree->set_has_transparent_background(has_transparent_background());
245
246 if (ContentsTexturesPurged())
247 target_tree->SetContentsTexturesPurged();
248 else
249 target_tree->ResetContentsTexturesPurged();
250
[email protected]318822852013-02-14 00:54:27251 if (ViewportSizeInvalid())
252 target_tree->SetViewportSizeInvalid();
253 else
254 target_tree->ResetViewportSizeInvalid();
255
[email protected]c60279472013-01-30 12:10:51256 if (hud_layer())
257 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
[email protected]6ba914122013-03-22 16:26:39258 LayerTreeHostCommon::FindLayerInSubtree(
[email protected]c1bb5af2013-03-13 19:06:27259 target_tree->root_layer(), hud_layer()->id())));
[email protected]c60279472013-01-30 12:10:51260 else
261 target_tree->set_hud_layer(NULL);
[email protected]759dc9f2014-07-23 19:18:51262
263 target_tree->has_ever_been_drawn_ = false;
[email protected]c60279472013-01-30 12:10:51264}
265
[email protected]fef74fd2014-02-27 06:28:17266LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const {
267 return inner_viewport_scroll_layer_
268 ? inner_viewport_scroll_layer_->scroll_clip_layer()
269 : NULL;
[email protected]ffb2720f2013-03-15 19:18:37270}
271
bokanef971462014-10-13 22:58:32272LayerImpl* LayerTreeImpl::OuterViewportContainerLayer() const {
273 return outer_viewport_scroll_layer_
274 ? outer_viewport_scroll_layer_->scroll_clip_layer()
275 : NULL;
276}
277
[email protected]ffb2720f2013-03-15 19:18:37278LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
[email protected]69b50ec2013-01-19 04:58:01279 DCHECK(IsActiveTree());
280 return currently_scrolling_layer_;
281}
282
[email protected]0fc818e2013-03-18 06:45:20283void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
284 if (currently_scrolling_layer_ == layer)
285 return;
286
287 if (currently_scrolling_layer_ &&
288 currently_scrolling_layer_->scrollbar_animation_controller())
[email protected]1dc06162014-03-26 22:54:45289 currently_scrolling_layer_->scrollbar_animation_controller()
[email protected]930ff43b2014-05-02 05:24:00290 ->DidScrollEnd();
[email protected]0fc818e2013-03-18 06:45:20291 currently_scrolling_layer_ = layer;
292 if (layer && layer->scrollbar_animation_controller())
[email protected]930ff43b2014-05-02 05:24:00293 layer->scrollbar_animation_controller()->DidScrollBegin();
[email protected]0fc818e2013-03-18 06:45:20294}
295
[email protected]3b31c6ac2012-12-06 21:27:29296void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
[email protected]0fc818e2013-03-18 06:45:20297 SetCurrentlyScrollingLayer(NULL);
[email protected]3b31c6ac2012-12-06 21:27:29298 scrolling_layer_id_from_previous_tree_ = 0;
299}
300
[email protected]adeda572014-01-31 00:49:47301namespace {
302
303void ForceScrollbarParameterUpdateAfterScaleChange(LayerImpl* current_layer) {
304 if (!current_layer)
305 return;
306
307 while (current_layer) {
sataya.m07f11a82014-10-07 14:29:18308 current_layer->ScrollbarParametersDidChange(false);
[email protected]adeda572014-01-31 00:49:47309 current_layer = current_layer->parent();
310 }
311}
312
313} // namespace
314
[email protected]c60279472013-01-30 12:10:51315void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
[email protected]3c0a3252013-03-18 04:24:36316 float min_page_scale_factor, float max_page_scale_factor) {
[email protected]d6021f6a2014-06-12 21:15:24317 SetPageScaleValues(page_scale_factor, min_page_scale_factor,
318 max_page_scale_factor, page_scale_delta_);
319}
[email protected]c60279472013-01-30 12:10:51320
[email protected]d6021f6a2014-06-12 21:15:24321void LayerTreeImpl::SetPageScaleDelta(float delta) {
322 SetPageScaleValues(page_scale_factor_, min_page_scale_factor_,
323 max_page_scale_factor_, delta);
324}
325
326void LayerTreeImpl::SetPageScaleValues(float page_scale_factor,
327 float min_page_scale_factor, float max_page_scale_factor,
328 float page_scale_delta) {
329 bool page_scale_changed =
330 min_page_scale_factor != min_page_scale_factor_ ||
331 max_page_scale_factor != max_page_scale_factor_ ||
332 page_scale_factor != page_scale_factor_;
[email protected]7265e74e2014-02-07 23:43:06333
[email protected]c60279472013-01-30 12:10:51334 min_page_scale_factor_ = min_page_scale_factor;
335 max_page_scale_factor_ = max_page_scale_factor;
336 page_scale_factor_ = page_scale_factor;
[email protected]20d2b742013-09-26 05:41:34337
[email protected]d6021f6a2014-06-12 21:15:24338 float total = page_scale_factor_ * page_scale_delta;
339 if (min_page_scale_factor_ && total < min_page_scale_factor_)
340 page_scale_delta = min_page_scale_factor_ / page_scale_factor_;
341 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
342 page_scale_delta = max_page_scale_factor_ / page_scale_factor_;
343
344 if (page_scale_delta_ == page_scale_delta && !page_scale_changed)
345 return;
346
347 if (page_scale_delta_ != page_scale_delta) {
348 page_scale_delta_ = page_scale_delta;
349
350 if (IsActiveTree()) {
351 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
352 if (pending_tree) {
353 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
354 pending_tree->SetPageScaleDelta(
355 page_scale_delta_ / sent_page_scale_delta_);
356 }
357 }
358
359 set_needs_update_draw_properties();
360 }
361
[email protected]22f200a2013-10-09 18:08:29362 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00363 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
364 TotalScrollOffset(),
365 TotalMaxScrollOffset(),
366 ScrollableSize(),
[email protected]68fe60f2014-02-12 13:49:11367 total_page_scale_factor(),
[email protected]d6021f6a2014-06-12 21:15:24368 min_page_scale_factor_,
369 max_page_scale_factor_);
[email protected]22f200a2013-10-09 18:08:29370 }
[email protected]adeda572014-01-31 00:49:47371
372 ForceScrollbarParameterUpdateAfterScaleChange(page_scale_layer());
[email protected]c60279472013-01-30 12:10:51373}
374
[email protected]257abfa82013-01-29 23:47:24375gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]587941d2014-08-22 01:40:01376 if (!InnerViewportContainerLayer())
377 return gfx::SizeF();
378
bokanef971462014-10-13 22:58:32379 return gfx::ScaleSize(InnerViewportContainerLayer()->BoundsForScrolling(),
[email protected]587941d2014-08-22 01:40:01380 1.0f / total_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24381}
382
[email protected]3744e27b2013-11-06 21:44:08383gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const {
[email protected]adeda572014-01-31 00:49:47384 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
385 ? OuterViewportScrollLayer()
386 : InnerViewportScrollLayer();
387 if (!root_scroll_layer || root_scroll_layer->children().empty())
[email protected]3744e27b2013-11-06 21:44:08388 return gfx::Rect();
[email protected]adeda572014-01-31 00:49:47389 LayerImpl* layer = root_scroll_layer->children()[0];
[email protected]8a822692014-02-12 17:30:55390 return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(),
391 gfx::Rect(layer->content_bounds()));
[email protected]3744e27b2013-11-06 21:44:08392}
393
[email protected]58241dc2013-08-20 01:39:25394static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) {
395 layer->ApplySentScrollDeltasFromAbortedCommit();
[email protected]3519b872013-07-30 07:17:50396}
397
[email protected]58241dc2013-08-20 01:39:25398void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50399 DCHECK(IsActiveTree());
400
401 page_scale_factor_ *= sent_page_scale_delta_;
402 page_scale_delta_ /= sent_page_scale_delta_;
403 sent_page_scale_delta_ = 1.f;
404
bokan55b2f152014-09-15 14:47:59405 top_controls_content_offset_ += sent_top_controls_delta_;
bokan88eae012014-09-09 20:40:42406 top_controls_delta_ -= sent_top_controls_delta_;
407 sent_top_controls_delta_ = 0.f;
408
[email protected]3519b872013-07-30 07:17:50409 if (!root_layer())
410 return;
411
412 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]58241dc2013-08-20 01:39:25413 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo));
414}
415
[email protected]daea3d42013-10-23 17:04:50416static void ApplyScrollDeltasSinceBeginMainFrameTo(LayerImpl* layer) {
417 layer->ApplyScrollDeltasSinceBeginMainFrame();
[email protected]58241dc2013-08-20 01:39:25418}
419
[email protected]daea3d42013-10-23 17:04:50420void LayerTreeImpl::ApplyScrollDeltasSinceBeginMainFrame() {
[email protected]58241dc2013-08-20 01:39:25421 DCHECK(IsPendingTree());
422 if (!root_layer())
423 return;
424
425 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]daea3d42013-10-23 17:04:50426 root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginMainFrameTo));
[email protected]3519b872013-07-30 07:17:50427}
428
[email protected]57ac9482013-09-17 21:13:39429void LayerTreeImpl::SetViewportLayersFromIds(
ccameron8230b68b2014-11-21 19:25:18430 int overscroll_elasticity_layer_id,
[email protected]57ac9482013-09-17 21:13:39431 int page_scale_layer_id,
432 int inner_viewport_scroll_layer_id,
433 int outer_viewport_scroll_layer_id) {
ccameron8230b68b2014-11-21 19:25:18434 overscroll_elasticity_layer_ = LayerById(overscroll_elasticity_layer_id);
[email protected]57ac9482013-09-17 21:13:39435 page_scale_layer_ = LayerById(page_scale_layer_id);
436 DCHECK(page_scale_layer_);
437
438 inner_viewport_scroll_layer_ =
439 LayerById(inner_viewport_scroll_layer_id);
440 DCHECK(inner_viewport_scroll_layer_);
441
442 outer_viewport_scroll_layer_ =
443 LayerById(outer_viewport_scroll_layer_id);
444 DCHECK(outer_viewport_scroll_layer_ ||
445 outer_viewport_scroll_layer_id == Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47446
447 if (!root_layer_scroll_offset_delegate_)
448 return;
449
450 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
451 new LayerScrollOffsetDelegateProxy(inner_viewport_scroll_layer_,
452 root_layer_scroll_offset_delegate_,
453 this));
454
455 if (outer_viewport_scroll_layer_)
456 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
457 new LayerScrollOffsetDelegateProxy(outer_viewport_scroll_layer_,
458 root_layer_scroll_offset_delegate_,
459 this));
[email protected]57ac9482013-09-17 21:13:39460}
461
462void LayerTreeImpl::ClearViewportLayers() {
463 page_scale_layer_ = NULL;
464 inner_viewport_scroll_layer_ = NULL;
465 outer_viewport_scroll_layer_ = NULL;
466}
467
[email protected]8f7f298822014-06-13 00:23:32468bool LayerTreeImpl::UpdateDrawProperties() {
469 if (!needs_update_draw_properties_)
470 return true;
[email protected]615c78a2013-01-24 23:44:16471
[email protected]ed511b8d2013-03-25 03:29:29472 // For max_texture_size.
[email protected]615c78a2013-01-24 23:44:16473 if (!layer_tree_host_impl_->renderer())
[email protected]8f7f298822014-06-13 00:23:32474 return false;
[email protected]615c78a2013-01-24 23:44:16475
[email protected]c1bb5af2013-03-13 19:06:27476 if (!root_layer())
[email protected]8f7f298822014-06-13 00:23:32477 return false;
478
479 needs_update_draw_properties_ = false;
480 render_surface_layer_list_.clear();
[email protected]76ffd9e2012-12-20 19:12:47481
[email protected]76ffd9e2012-12-20 19:12:47482 {
[email protected]7a52f43e2013-07-10 01:58:47483 TRACE_EVENT2("cc",
[email protected]c1bb5af2013-03-13 19:06:27484 "LayerTreeImpl::UpdateDrawProperties",
485 "IsActive",
[email protected]7a52f43e2013-07-10 01:58:47486 IsActiveTree(),
487 "SourceFrameNumber",
488 source_frame_number_);
[email protected]57ac9482013-09-17 21:13:39489 LayerImpl* page_scale_layer =
[email protected]fef74fd2014-02-27 06:28:17490 page_scale_layer_ ? page_scale_layer_ : InnerViewportContainerLayer();
hush367d7dd2014-08-29 23:56:01491 bool can_render_to_separate_surface =
492 (layer_tree_host_impl_->GetDrawMode() !=
493 DRAW_MODE_RESOURCELESS_SOFTWARE);
[email protected]390bb1ff2014-05-09 17:14:40494
495 ++render_surface_layer_list_id_;
[email protected]7aad55f2013-07-26 11:25:53496 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
danakj3f76ace2014-11-18 16:56:00497 root_layer(), DrawViewportSize(),
498 layer_tree_host_impl_->DrawTransform(), device_scale_factor(),
499 total_page_scale_factor(), page_scale_layer,
500 resource_provider()->max_texture_size(), settings().can_use_lcd_text,
501 settings().layers_always_allowed_lcd_text,
[email protected]45948712013-09-27 02:46:48502 can_render_to_separate_surface,
[email protected]35a99a12013-05-09 23:52:29503 settings().layer_transforms_should_scale_layer_contents,
danakj3f76ace2014-11-18 16:56:00504 &render_surface_layer_list_, render_surface_layer_list_id_);
[email protected]7aad55f2013-07-26 11:25:53505 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]76ffd9e2012-12-20 19:12:47506 }
[email protected]615c78a2013-01-24 23:44:16507
[email protected]e4be0262013-10-19 16:54:28508 {
vmpstrd6166202014-11-05 18:45:40509 TRACE_EVENT_BEGIN2("cc", "LayerTreeImpl::UpdateTilePriorities", "IsActive",
510 IsActiveTree(), "SourceFrameNumber",
511 source_frame_number_);
danakj6496cba2014-10-16 01:31:08512 scoped_ptr<OcclusionTracker<LayerImpl>> occlusion_tracker;
[email protected]562b7ad2014-06-23 22:17:11513 if (settings().use_occlusion_for_tile_prioritization) {
514 occlusion_tracker.reset(new OcclusionTracker<LayerImpl>(
515 root_layer()->render_surface()->content_rect()));
516 occlusion_tracker->set_minimum_tracking_size(
517 settings().minimum_occlusion_tracking_size);
518 }
519
boliu7473f7f52014-10-01 16:54:56520 bool resourceless_software_draw = (layer_tree_host_impl_->GetDrawMode() ==
521 DRAW_MODE_RESOURCELESS_SOFTWARE);
522
[email protected]e4be0262013-10-19 16:54:28523 // LayerIterator is used here instead of CallFunctionForSubtree to only
524 // UpdateTilePriorities on layers that will be visible (and thus have valid
525 // draw properties) and not because any ordering is required.
[email protected]ba1b33e2014-02-28 16:44:51526 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]e4be0262013-10-19 16:54:28527 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
vmpstrd6166202014-11-05 18:45:40528 size_t layers_updated_count = 0;
[email protected]e4be0262013-10-19 16:54:28529 for (LayerIteratorType it =
530 LayerIteratorType::Begin(&render_surface_layer_list_);
531 it != end;
532 ++it) {
[email protected]562b7ad2014-06-23 22:17:11533 if (occlusion_tracker)
534 occlusion_tracker->EnterLayer(it);
535
[email protected]e4be0262013-10-19 16:54:28536 LayerImpl* layer = *it;
vmpstrcdcb5f72014-09-11 00:58:37537 const Occlusion& occlusion_in_content_space =
538 occlusion_tracker ? occlusion_tracker->GetCurrentOcclusionForLayer(
539 layer->draw_transform())
540 : Occlusion();
541
boliu7473f7f52014-10-01 16:54:56542 if (it.represents_itself()) {
543 layer->UpdateTiles(occlusion_in_content_space,
544 resourceless_software_draw);
vmpstrd6166202014-11-05 18:45:40545 ++layers_updated_count;
boliu7473f7f52014-10-01 16:54:56546 }
[email protected]e4be0262013-10-19 16:54:28547
[email protected]562b7ad2014-06-23 22:17:11548 if (!it.represents_contributing_render_surface()) {
549 if (occlusion_tracker)
550 occlusion_tracker->LeaveLayer(it);
[email protected]6355d2d2014-05-07 15:07:27551 continue;
[email protected]562b7ad2014-06-23 22:17:11552 }
[email protected]6355d2d2014-05-07 15:07:27553
boliu7473f7f52014-10-01 16:54:56554 if (layer->mask_layer()) {
555 layer->mask_layer()->UpdateTiles(occlusion_in_content_space,
556 resourceless_software_draw);
vmpstrd6166202014-11-05 18:45:40557 ++layers_updated_count;
boliu7473f7f52014-10-01 16:54:56558 }
559 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) {
[email protected]562b7ad2014-06-23 22:17:11560 layer->replica_layer()->mask_layer()->UpdateTiles(
boliu7473f7f52014-10-01 16:54:56561 occlusion_in_content_space, resourceless_software_draw);
vmpstrd6166202014-11-05 18:45:40562 ++layers_updated_count;
boliu7473f7f52014-10-01 16:54:56563 }
[email protected]562b7ad2014-06-23 22:17:11564
565 if (occlusion_tracker)
566 occlusion_tracker->LeaveLayer(it);
[email protected]e4be0262013-10-19 16:54:28567 }
vmpstrd6166202014-11-05 18:45:40568
569 TRACE_EVENT_END1("cc", "LayerTreeImpl::UpdateTilePriorities",
570 "layers_updated_count", layers_updated_count);
[email protected]e4be0262013-10-19 16:54:28571 }
572
[email protected]615c78a2013-01-24 23:44:16573 DCHECK(!needs_update_draw_properties_) <<
[email protected]7d19dc342013-05-02 22:02:04574 "CalcDrawProperties should not set_needs_update_draw_properties()";
[email protected]8f7f298822014-06-13 00:23:32575 return true;
[email protected]76ffd9e2012-12-20 19:12:47576}
577
[email protected]50761e92013-03-29 20:51:28578const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const {
[email protected]76ffd9e2012-12-20 19:12:47579 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16580 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47581 return render_surface_layer_list_;
582}
583
bokancccfde72014-10-08 15:15:22584gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]adeda572014-01-31 00:49:47585 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
586 ? OuterViewportScrollLayer()
587 : InnerViewportScrollLayer();
588 if (!root_scroll_layer || root_scroll_layer->children().empty())
bokancccfde72014-10-08 15:15:22589 return gfx::Size();
[email protected]adeda572014-01-31 00:49:47590 return root_scroll_layer->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16591}
592
[email protected]361bc00d2012-12-14 07:03:24593LayerImpl* LayerTreeImpl::LayerById(int id) {
594 LayerIdMap::iterator iter = layer_id_map_.find(id);
595 return iter != layer_id_map_.end() ? iter->second : NULL;
596}
597
598void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
599 DCHECK(!LayerById(layer->id()));
600 layer_id_map_[layer->id()] = layer;
601}
602
603void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
604 DCHECK(LayerById(layer->id()));
605 layer_id_map_.erase(layer->id());
606}
607
[email protected]aebf4622014-07-14 16:57:59608size_t LayerTreeImpl::NumLayers() {
609 return layer_id_map_.size();
610}
611
[email protected]ed511b8d2013-03-25 03:29:29612void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) {
[email protected]a90fac72013-06-06 18:56:13613 pending_tree->SetCurrentlyScrollingLayer(
614 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(),
615 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0));
[email protected]1e0f8d62013-01-09 07:41:35616}
617
[email protected]ff1211d2013-06-07 01:58:35618static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34619 layer->DidBecomeActive();
[email protected]db2e29c2014-08-06 05:58:25620 if (layer->mask_layer())
621 layer->mask_layer()->DidBecomeActive();
622 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
623 layer->replica_layer()->mask_layer()->DidBecomeActive();
624
[email protected]ff1211d2013-06-07 01:58:35625 for (size_t i = 0; i < layer->children().size(); ++i)
626 DidBecomeActiveRecursive(layer->children()[i]);
[email protected]37386f052013-01-13 00:42:22627}
628
629void LayerTreeImpl::DidBecomeActive() {
[email protected]12a63da2014-06-13 06:06:22630 if (next_activation_forces_redraw_) {
631 layer_tree_host_impl_->SetFullRootLayerDamage();
632 next_activation_forces_redraw_ = false;
633 }
634
[email protected]adeda572014-01-31 00:49:47635 if (scrolling_layer_id_from_previous_tree_) {
636 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
[email protected]7dcf5632014-06-25 01:11:55637 root_layer(), scrolling_layer_id_from_previous_tree_);
[email protected]adeda572014-01-31 00:49:47638 }
639
[email protected]7dcf5632014-06-25 01:11:55640 // Always reset this flag on activation, as we would only have activated
641 // if we were in a good state.
vmpstr61ed94a12014-10-09 04:49:30642 layer_tree_host_impl_->ResetRequiresHighResToDraw();
[email protected]7dcf5632014-06-25 01:11:55643
644 if (root_layer())
645 DidBecomeActiveRecursive(root_layer());
646
[email protected]12a63da2014-06-13 06:06:22647 devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(),
648 source_frame_number_);
[email protected]37386f052013-01-13 00:42:22649}
650
[email protected]6f90b9e2013-01-17 23:42:00651bool LayerTreeImpl::ContentsTexturesPurged() const {
652 return contents_textures_purged_;
653}
654
655void LayerTreeImpl::SetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04656 if (contents_textures_purged_)
657 return;
[email protected]6f90b9e2013-01-17 23:42:00658 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27659 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00660}
661
662void LayerTreeImpl::ResetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04663 if (!contents_textures_purged_)
664 return;
[email protected]6f90b9e2013-01-17 23:42:00665 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27666 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00667}
668
[email protected]3d609bb2014-02-01 01:10:23669bool LayerTreeImpl::RequiresHighResToDraw() const {
vmpstr61ed94a12014-10-09 04:49:30670 return layer_tree_host_impl_->RequiresHighResToDraw();
[email protected]3d609bb2014-02-01 01:10:23671}
672
[email protected]318822852013-02-14 00:54:27673bool LayerTreeImpl::ViewportSizeInvalid() const {
674 return viewport_size_invalid_;
675}
676
677void LayerTreeImpl::SetViewportSizeInvalid() {
678 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27679 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27680}
681
682void LayerTreeImpl::ResetViewportSizeInvalid() {
683 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27684 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27685}
686
[email protected]48871fc2013-01-23 07:36:51687Proxy* LayerTreeImpl::proxy() const {
688 return layer_tree_host_impl_->proxy();
689}
690
[email protected]ff762fb2012-12-12 19:18:37691const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27692 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37693}
694
[email protected]7a8bcd262014-01-15 12:54:58695const RendererCapabilitiesImpl& LayerTreeImpl::GetRendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27696 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52697}
698
[email protected]0634cdd42013-08-16 00:46:09699ContextProvider* LayerTreeImpl::context_provider() const {
dcheng6afa17002014-08-26 19:11:31700 return output_surface()->context_provider();
[email protected]0634cdd42013-08-16 00:46:09701}
702
[email protected]ff762fb2012-12-12 19:18:37703OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27704 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37705}
706
707ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27708 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37709}
710
711TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27712 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37713}
714
715FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27716 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37717}
718
[email protected]71691c22013-01-18 03:14:22719PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27720 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22721}
722
[email protected]1191d9d2013-02-02 06:00:33723MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27724 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33725}
726
[email protected]4a6c091d2014-04-24 21:06:46727gfx::Size LayerTreeImpl::device_viewport_size() const {
728 return layer_tree_host_impl_->device_viewport_size();
729}
730
[email protected]f117a4c2012-12-16 04:53:10731bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27732 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10733}
734
735bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27736 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10737}
738
[email protected]48871fc2013-01-23 07:36:51739bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27740 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51741}
742
[email protected]f117a4c2012-12-16 04:53:10743LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27744 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10745 if (!tree)
746 return NULL;
747 return tree->LayerById(id);
748}
749
750LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27751 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10752 if (!tree)
753 return NULL;
754 return tree->LayerById(id);
755}
756
[email protected]166db5c82013-01-09 23:54:31757bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27758 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31759}
760
[email protected]04c5900d2014-08-18 13:38:36761BeginFrameArgs LayerTreeImpl::CurrentBeginFrameArgs() const {
762 return layer_tree_host_impl_->CurrentBeginFrameArgs();
[email protected]fb7425a2013-04-22 16:28:55763}
764
[email protected]c92195e2014-05-07 18:18:49765base::TimeDelta LayerTreeImpl::begin_impl_frame_interval() const {
766 return layer_tree_host_impl_->begin_impl_frame_interval();
767}
768
[email protected]d7eb8c72013-03-23 22:57:13769void LayerTreeImpl::SetNeedsCommit() {
770 layer_tree_host_impl_->SetNeedsCommit();
771}
772
[email protected]bd5324592014-07-31 09:09:33773gfx::Rect LayerTreeImpl::DeviceViewport() const {
774 return layer_tree_host_impl_->DeviceViewport();
775}
776
[email protected]54af03522013-09-05 00:43:28777gfx::Size LayerTreeImpl::DrawViewportSize() const {
778 return layer_tree_host_impl_->DrawViewportSize();
779}
780
[email protected]bd5324592014-07-31 09:09:33781const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const {
782 return layer_tree_host_impl_->ViewportRectForTilePriority();
783}
784
[email protected]930ff43b2014-05-02 05:24:00785scoped_ptr<ScrollbarAnimationController>
786LayerTreeImpl::CreateScrollbarAnimationController(LayerImpl* scrolling_layer) {
787 DCHECK(settings().scrollbar_fade_delay_ms);
788 DCHECK(settings().scrollbar_fade_duration_ms);
789 base::TimeDelta delay =
790 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms);
sataya.m07f11a82014-10-07 14:29:18791 base::TimeDelta resize_delay = base::TimeDelta::FromMilliseconds(
792 settings().scrollbar_fade_resize_delay_ms);
[email protected]930ff43b2014-05-02 05:24:00793 base::TimeDelta duration =
794 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms);
795 switch (settings().scrollbar_animator) {
796 case LayerTreeSettings::LinearFade: {
797 return ScrollbarAnimationControllerLinearFade::Create(
sataya.m07f11a82014-10-07 14:29:18798 scrolling_layer,
799 layer_tree_host_impl_,
800 delay,
801 resize_delay,
802 duration);
[email protected]930ff43b2014-05-02 05:24:00803 }
804 case LayerTreeSettings::Thinning: {
sataya.m07f11a82014-10-07 14:29:18805 return ScrollbarAnimationControllerThinning::Create(scrolling_layer,
806 layer_tree_host_impl_,
807 delay,
808 resize_delay,
809 duration);
[email protected]930ff43b2014-05-02 05:24:00810 }
811 case LayerTreeSettings::NoAnimator:
812 NOTREACHED();
813 break;
814 }
danakjf446a072014-09-27 21:55:48815 return nullptr;
[email protected]2ea5aba2013-09-11 14:26:56816}
817
[email protected]b8384e22013-12-03 02:20:48818void LayerTreeImpl::DidAnimateScrollOffset() {
819 layer_tree_host_impl_->DidAnimateScrollOffset();
820}
821
[email protected]13525d62014-05-20 21:22:04822bool LayerTreeImpl::use_gpu_rasterization() const {
823 return layer_tree_host_impl_->use_gpu_rasterization();
824}
825
hendrikwc2bbd612014-12-03 23:49:34826GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const {
827 return layer_tree_host_impl_->gpu_rasterization_status();
828}
829
[email protected]473f1f22014-05-22 08:19:17830bool LayerTreeImpl::create_low_res_tiling() const {
831 return layer_tree_host_impl_->create_low_res_tiling();
832}
833
[email protected]ff762fb2012-12-12 19:18:37834void LayerTreeImpl::SetNeedsRedraw() {
[email protected]59adb112013-04-09 04:48:44835 layer_tree_host_impl_->SetNeedsRedraw();
[email protected]ff762fb2012-12-12 19:18:37836}
837
[email protected]ff762fb2012-12-12 19:18:37838const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27839 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37840}
841
842float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27843 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37844}
845
[email protected]ff762fb2012-12-12 19:18:37846DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27847 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37848}
849
[email protected]de4afb5e2012-12-20 00:11:34850AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27851 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34852}
[email protected]ff762fb2012-12-12 19:18:37853
vmpstrd7de03c2014-08-27 18:11:01854void LayerTreeImpl::GetAllTilesForTracing(std::set<const Tile*>* tiles) const {
855 typedef LayerIterator<LayerImpl> LayerIteratorType;
856 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
857 for (LayerIteratorType it =
858 LayerIteratorType::Begin(&render_surface_layer_list_);
859 it != end;
860 ++it) {
861 if (!it.represents_itself())
862 continue;
863 LayerImpl* layer_impl = *it;
864 layer_impl->GetAllTilesForTracing(tiles);
865 }
866}
867
[email protected]d12aa932014-08-01 13:10:38868void LayerTreeImpl::AsValueInto(base::debug::TracedValue* state) const {
869 TracedValue::MakeDictIntoImplicitSnapshot(state, "cc::LayerTreeImpl", this);
nduca929378a02014-08-23 19:48:52870 state->SetInteger("source_frame_number", source_frame_number_);
[email protected]f6742f52013-05-08 23:52:22871
[email protected]d12aa932014-08-01 13:10:38872 state->BeginDictionary("root_layer");
873 root_layer_->AsValueInto(state);
874 state->EndDictionary();
[email protected]f6742f52013-05-08 23:52:22875
[email protected]d12aa932014-08-01 13:10:38876 state->BeginArray("render_surface_layer_list");
[email protected]ba1b33e2014-02-28 16:44:51877 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09878 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
879 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]8c5690222013-02-15 17:36:43880 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09881 if (!it.represents_itself())
[email protected]8c5690222013-02-15 17:36:43882 continue;
[email protected]d12aa932014-08-01 13:10:38883 TracedValue::AppendIDRef(*it, state);
[email protected]8c5690222013-02-15 17:36:43884 }
[email protected]d12aa932014-08-01 13:10:38885 state->EndArray();
skyostil43c330f72014-09-22 16:49:11886
887 state->BeginArray("swap_promise_trace_ids");
888 for (size_t i = 0; i < swap_promise_list_.size(); i++)
889 state->AppendDouble(swap_promise_list_[i]->TraceId());
890 state->EndArray();
[email protected]8c5690222013-02-15 17:36:43891}
892
[email protected]1960a712013-04-30 17:06:47893void LayerTreeImpl::SetRootLayerScrollOffsetDelegate(
[email protected]c9280762013-08-01 06:28:57894 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
[email protected]20d2b742013-09-26 05:41:34895 if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate)
896 return;
897
[email protected]adeda572014-01-31 00:49:47898 if (!root_layer_scroll_offset_delegate) {
899 // Make sure we remove the proxies from their layers before
900 // releasing them.
901 if (InnerViewportScrollLayer())
902 InnerViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
903 if (OuterViewportScrollLayer())
904 OuterViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48905 inner_viewport_scroll_delegate_proxy_ = nullptr;
906 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]d35cd7b22014-01-29 14:32:46907 }
908
[email protected]adeda572014-01-31 00:49:47909 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
910
[email protected]20d2b742013-09-26 05:41:34911 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00912 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
913 TotalScrollOffset(),
914 TotalMaxScrollOffset(),
915 ScrollableSize(),
[email protected]68fe60f2014-02-12 13:49:11916 total_page_scale_factor(),
917 min_page_scale_factor(),
918 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47919
920 if (inner_viewport_scroll_layer_) {
921 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
922 new LayerScrollOffsetDelegateProxy(InnerViewportScrollLayer(),
923 root_layer_scroll_offset_delegate_,
924 this));
925 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(
926 inner_viewport_scroll_delegate_proxy_.get());
927 }
928
929 if (outer_viewport_scroll_layer_) {
930 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
931 new LayerScrollOffsetDelegateProxy(OuterViewportScrollLayer(),
932 root_layer_scroll_offset_delegate_,
933 this));
934 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(
935 outer_viewport_scroll_delegate_proxy_.get());
936 }
bokan6747f5522014-10-24 19:28:54937
938 if (inner_viewport_scroll_layer_)
939 UpdateScrollOffsetDelegate();
[email protected]20d2b742013-09-26 05:41:34940 }
[email protected]1960a712013-04-30 17:06:47941}
942
boliu7d5dbab2014-10-10 20:05:47943void LayerTreeImpl::OnRootLayerDelegatedScrollOffsetChanged() {
944 DCHECK(root_layer_scroll_offset_delegate_);
945 if (inner_viewport_scroll_layer_) {
946 inner_viewport_scroll_layer_->DidScroll();
947 }
948 if (outer_viewport_scroll_layer_) {
949 outer_viewport_scroll_layer_->DidScroll();
950 }
951}
952
[email protected]adeda572014-01-31 00:49:47953void LayerTreeImpl::UpdateScrollOffsetDelegate() {
954 DCHECK(InnerViewportScrollLayer());
bokan6747f5522014-10-24 19:28:54955 DCHECK(!OuterViewportScrollLayer() || outer_viewport_scroll_delegate_proxy_);
[email protected]adeda572014-01-31 00:49:47956 DCHECK(root_layer_scroll_offset_delegate_);
957
miletusf57925d2014-10-01 19:38:13958 gfx::ScrollOffset offset =
[email protected]adeda572014-01-31 00:49:47959 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
960
961 if (OuterViewportScrollLayer())
962 offset += outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
963
[email protected]ec2322e2014-05-15 16:32:00964 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
965 offset,
966 TotalMaxScrollOffset(),
967 ScrollableSize(),
968 total_page_scale_factor(),
969 min_page_scale_factor(),
970 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47971}
972
miletusf57925d2014-10-01 19:38:13973gfx::ScrollOffset LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) {
[email protected]adeda572014-01-31 00:49:47974 DCHECK(root_layer_scroll_offset_delegate_);
975 DCHECK(InnerViewportScrollLayer());
976 if (layer == InnerViewportScrollLayer() && !OuterViewportScrollLayer())
977 return root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
978
979 // If we get here, we have both inner/outer viewports, and need to distribute
980 // the scroll offset between them.
981 DCHECK(inner_viewport_scroll_delegate_proxy_);
982 DCHECK(outer_viewport_scroll_delegate_proxy_);
miletusf57925d2014-10-01 19:38:13983 gfx::ScrollOffset inner_viewport_offset =
[email protected]adeda572014-01-31 00:49:47984 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
miletusf57925d2014-10-01 19:38:13985 gfx::ScrollOffset outer_viewport_offset =
[email protected]adeda572014-01-31 00:49:47986 outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
987
988 // It may be nothing has changed.
miletusf57925d2014-10-01 19:38:13989 gfx::ScrollOffset delegate_offset =
[email protected]adeda572014-01-31 00:49:47990 root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
991 if (inner_viewport_offset + outer_viewport_offset == delegate_offset) {
992 if (layer == InnerViewportScrollLayer())
993 return inner_viewport_offset;
994 else
995 return outer_viewport_offset;
996 }
997
miletusf57925d2014-10-01 19:38:13998 gfx::ScrollOffset max_outer_viewport_scroll_offset =
[email protected]adeda572014-01-31 00:49:47999 OuterViewportScrollLayer()->MaxScrollOffset();
1000
1001 outer_viewport_offset = delegate_offset - inner_viewport_offset;
1002 outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset);
miletusf57925d2014-10-01 19:38:131003 outer_viewport_offset.SetToMax(gfx::ScrollOffset());
[email protected]adeda572014-01-31 00:49:471004
1005 if (layer == OuterViewportScrollLayer())
1006 return outer_viewport_offset;
1007
1008 inner_viewport_offset = delegate_offset - outer_viewport_offset;
1009
1010 return inner_viewport_offset;
1011}
1012
[email protected]b69c1db2013-11-27 00:05:191013void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) {
1014 DCHECK(swap_promise);
[email protected]b69c1db2013-11-27 00:05:191015 swap_promise_list_.push_back(swap_promise.Pass());
1016}
1017
1018void LayerTreeImpl::PassSwapPromises(
1019 ScopedPtrVector<SwapPromise>* new_swap_promise) {
1020 swap_promise_list_.insert_and_take(swap_promise_list_.end(),
weiliangcc1878c62014-09-02 22:43:171021 new_swap_promise);
[email protected]b69c1db2013-11-27 00:05:191022 new_swap_promise->clear();
1023}
1024
[email protected]d359203a2013-11-29 06:16:551025void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) {
[email protected]b69c1db2013-11-27 00:05:191026 for (size_t i = 0; i < swap_promise_list_.size(); i++)
[email protected]d359203a2013-11-29 06:16:551027 swap_promise_list_[i]->DidSwap(metadata);
[email protected]b69c1db2013-11-27 00:05:191028 swap_promise_list_.clear();
1029}
1030
1031void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) {
1032 for (size_t i = 0; i < swap_promise_list_.size(); i++)
1033 swap_promise_list_[i]->DidNotSwap(reason);
1034 swap_promise_list_.clear();
1035}
1036
[email protected]c48536a52013-09-14 00:02:081037void LayerTreeImpl::DidModifyTilePriorities() {
1038 layer_tree_host_impl_->DidModifyTilePriorities();
[email protected]fcb846d2013-05-22 01:42:361039}
1040
[email protected]c9280762013-08-01 06:28:571041void LayerTreeImpl::set_ui_resource_request_queue(
1042 const UIResourceRequestQueue& queue) {
1043 ui_resource_request_queue_ = queue;
1044}
1045
1046ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource(
1047 UIResourceId uid) const {
1048 return layer_tree_host_impl_->ResourceIdForUIResource(uid);
1049}
1050
[email protected]709c9542013-10-26 01:43:511051bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const {
1052 return layer_tree_host_impl_->IsUIResourceOpaque(uid);
1053}
1054
[email protected]c9280762013-08-01 06:28:571055void LayerTreeImpl::ProcessUIResourceRequestQueue() {
1056 while (ui_resource_request_queue_.size() > 0) {
1057 UIResourceRequest req = ui_resource_request_queue_.front();
1058 ui_resource_request_queue_.pop_front();
1059
[email protected]741fba422013-09-20 03:34:141060 switch (req.GetType()) {
[email protected]c9280762013-08-01 06:28:571061 case UIResourceRequest::UIResourceCreate:
[email protected]741fba422013-09-20 03:34:141062 layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap());
[email protected]c9280762013-08-01 06:28:571063 break;
1064 case UIResourceRequest::UIResourceDelete:
[email protected]741fba422013-09-20 03:34:141065 layer_tree_host_impl_->DeleteUIResource(req.GetId());
[email protected]c9280762013-08-01 06:28:571066 break;
[email protected]f28d64d2013-08-27 04:17:451067 case UIResourceRequest::UIResourceInvalidRequest:
[email protected]c9280762013-08-01 06:28:571068 NOTREACHED();
1069 break;
1070 }
1071 }
[email protected]127bdc1a2013-09-11 01:44:481072
1073 // If all UI resource evictions were not recreated by processing this queue,
1074 // then another commit is required.
1075 if (layer_tree_host_impl_->EvictedUIResourcesExist())
1076 layer_tree_host_impl_->SetNeedsCommit();
[email protected]c9280762013-08-01 06:28:571077}
1078
[email protected]30fe19ff2013-07-04 00:54:451079void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) {
1080 // Only the active tree needs to know about layers with copy requests, as
1081 // they are aborted if not serviced during draw.
1082 DCHECK(IsActiveTree());
1083
[email protected]a4ee12812014-02-06 17:33:381084 // DCHECK(std::find(layers_with_copy_output_request_.begin(),
1085 // layers_with_copy_output_request_.end(),
1086 // layer) == layers_with_copy_output_request_.end());
1087 // TODO(danakj): Remove this once crash is found crbug.com/309777
1088 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1089 CHECK(layers_with_copy_output_request_[i] != layer)
1090 << i << " of " << layers_with_copy_output_request_.size();
1091 }
[email protected]30fe19ff2013-07-04 00:54:451092 layers_with_copy_output_request_.push_back(layer);
1093}
1094
1095void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) {
1096 // Only the active tree needs to know about layers with copy requests, as
1097 // they are aborted if not serviced during draw.
1098 DCHECK(IsActiveTree());
1099
1100 std::vector<LayerImpl*>::iterator it = std::find(
1101 layers_with_copy_output_request_.begin(),
1102 layers_with_copy_output_request_.end(),
1103 layer);
1104 DCHECK(it != layers_with_copy_output_request_.end());
[email protected]f5de9e5b2013-07-30 22:26:571105 layers_with_copy_output_request_.erase(it);
[email protected]a4ee12812014-02-06 17:33:381106
1107 // TODO(danakj): Remove this once crash is found crbug.com/309777
1108 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1109 CHECK(layers_with_copy_output_request_[i] != layer)
1110 << i << " of " << layers_with_copy_output_request_.size();
1111 }
[email protected]30fe19ff2013-07-04 00:54:451112}
1113
[email protected]53526372013-12-07 04:31:501114const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest()
[email protected]30fe19ff2013-07-04 00:54:451115 const {
1116 // Only the active tree needs to know about layers with copy requests, as
1117 // they are aborted if not serviced during draw.
1118 DCHECK(IsActiveTree());
1119
1120 return layers_with_copy_output_request_;
1121}
1122
[email protected]aeef2f02014-05-10 12:15:481123void LayerTreeImpl::ReleaseResourcesRecursive(LayerImpl* current) {
1124 DCHECK(current);
1125 current->ReleaseResources();
1126 if (current->mask_layer())
1127 ReleaseResourcesRecursive(current->mask_layer());
1128 if (current->replica_layer())
1129 ReleaseResourcesRecursive(current->replica_layer());
1130 for (size_t i = 0; i < current->children().size(); ++i)
1131 ReleaseResourcesRecursive(current->children()[i]);
1132}
1133
[email protected]28336d52014-05-12 19:07:281134template <typename LayerType>
1135static inline bool LayerClipsSubtree(LayerType* layer) {
1136 return layer->masks_to_bounds() || layer->mask_layer();
1137}
1138
1139static bool PointHitsRect(
1140 const gfx::PointF& screen_space_point,
1141 const gfx::Transform& local_space_to_screen_space_transform,
1142 const gfx::RectF& local_space_rect,
1143 float* distance_to_camera) {
1144 // If the transform is not invertible, then assume that this point doesn't hit
1145 // this rect.
1146 gfx::Transform inverse_local_space_to_screen_space(
1147 gfx::Transform::kSkipInitialization);
1148 if (!local_space_to_screen_space_transform.GetInverse(
1149 &inverse_local_space_to_screen_space))
1150 return false;
1151
1152 // Transform the hit test point from screen space to the local space of the
1153 // given rect.
1154 bool clipped = false;
1155 gfx::Point3F planar_point = MathUtil::ProjectPoint3D(
1156 inverse_local_space_to_screen_space, screen_space_point, &clipped);
1157 gfx::PointF hit_test_point_in_local_space =
1158 gfx::PointF(planar_point.x(), planar_point.y());
1159
1160 // If ProjectPoint could not project to a valid value, then we assume that
1161 // this point doesn't hit this rect.
1162 if (clipped)
1163 return false;
1164
1165 if (!local_space_rect.Contains(hit_test_point_in_local_space))
1166 return false;
1167
1168 if (distance_to_camera) {
1169 // To compute the distance to the camera, we have to take the planar point
1170 // and pull it back to world space and compute the displacement along the
1171 // z-axis.
1172 gfx::Point3F planar_point_in_screen_space(planar_point);
1173 local_space_to_screen_space_transform.TransformPoint(
1174 &planar_point_in_screen_space);
1175 *distance_to_camera = planar_point_in_screen_space.z();
1176 }
1177
1178 return true;
1179}
1180
1181static bool PointHitsRegion(const gfx::PointF& screen_space_point,
1182 const gfx::Transform& screen_space_transform,
1183 const Region& layer_space_region,
1184 float layer_content_scale_x,
1185 float layer_content_scale_y) {
1186 // If the transform is not invertible, then assume that this point doesn't hit
1187 // this region.
1188 gfx::Transform inverse_screen_space_transform(
1189 gfx::Transform::kSkipInitialization);
1190 if (!screen_space_transform.GetInverse(&inverse_screen_space_transform))
1191 return false;
1192
1193 // Transform the hit test point from screen space to the local space of the
1194 // given region.
1195 bool clipped = false;
1196 gfx::PointF hit_test_point_in_content_space = MathUtil::ProjectPoint(
1197 inverse_screen_space_transform, screen_space_point, &clipped);
1198 gfx::PointF hit_test_point_in_layer_space =
1199 gfx::ScalePoint(hit_test_point_in_content_space,
1200 1.f / layer_content_scale_x,
1201 1.f / layer_content_scale_y);
1202
1203 // If ProjectPoint could not project to a valid value, then we assume that
1204 // this point doesn't hit this region.
1205 if (clipped)
1206 return false;
1207
1208 return layer_space_region.Contains(
1209 gfx::ToRoundedPoint(hit_test_point_in_layer_space));
1210}
1211
[email protected]19aec372014-07-01 19:08:491212static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) {
[email protected]0ec86f52014-06-12 20:54:031213 if (layer->scroll_parent())
1214 return layer->scroll_parent();
1215 if (layer->clip_parent())
1216 return layer->clip_parent();
1217 return layer->parent();
1218}
1219
[email protected]28336d52014-05-12 19:07:281220static bool PointIsClippedBySurfaceOrClipRect(
1221 const gfx::PointF& screen_space_point,
[email protected]19aec372014-07-01 19:08:491222 const LayerImpl* layer) {
[email protected]28336d52014-05-12 19:07:281223 // Walk up the layer tree and hit-test any render_surfaces and any layer
1224 // clip rects that are active.
[email protected]0ec86f52014-06-12 20:54:031225 for (; layer; layer = GetNextClippingLayer(layer)) {
1226 if (layer->render_surface() &&
1227 !PointHitsRect(screen_space_point,
1228 layer->render_surface()->screen_space_transform(),
1229 layer->render_surface()->content_rect(),
1230 NULL))
[email protected]28336d52014-05-12 19:07:281231 return true;
1232
[email protected]0ec86f52014-06-12 20:54:031233 if (LayerClipsSubtree(layer) &&
1234 !PointHitsRect(screen_space_point,
1235 layer->screen_space_transform(),
1236 gfx::Rect(layer->content_bounds()),
1237 NULL))
[email protected]28336d52014-05-12 19:07:281238 return true;
[email protected]28336d52014-05-12 19:07:281239 }
1240
1241 // If we have finished walking all ancestors without having already exited,
1242 // then the point is not clipped by any ancestors.
1243 return false;
1244}
1245
[email protected]19aec372014-07-01 19:08:491246static bool PointHitsLayer(const LayerImpl* layer,
[email protected]28336d52014-05-12 19:07:281247 const gfx::PointF& screen_space_point,
1248 float* distance_to_intersection) {
1249 gfx::RectF content_rect(layer->content_bounds());
1250 if (!PointHitsRect(screen_space_point,
1251 layer->screen_space_transform(),
1252 content_rect,
1253 distance_to_intersection))
1254 return false;
1255
1256 // At this point, we think the point does hit the layer, but we need to walk
1257 // up the parents to ensure that the layer was not clipped in such a way
1258 // that the hit point actually should not hit the layer.
1259 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer))
1260 return false;
1261
1262 // Skip the HUD layer.
1263 if (layer == layer->layer_tree_impl()->hud_layer())
1264 return false;
1265
1266 return true;
1267}
1268
1269struct FindClosestMatchingLayerDataForRecursion {
1270 FindClosestMatchingLayerDataForRecursion()
1271 : closest_match(NULL),
1272 closest_distance(-std::numeric_limits<float>::infinity()) {}
1273 LayerImpl* closest_match;
1274 // Note that the positive z-axis points towards the camera, so bigger means
1275 // closer in this case, counterintuitively.
1276 float closest_distance;
1277};
1278
1279template <typename Functor>
1280static void FindClosestMatchingLayer(
1281 const gfx::PointF& screen_space_point,
1282 LayerImpl* layer,
1283 const Functor& func,
1284 FindClosestMatchingLayerDataForRecursion* data_for_recursion) {
1285 for (int i = layer->children().size() - 1; i >= 0; --i) {
1286 FindClosestMatchingLayer(
1287 screen_space_point, layer->children()[i], func, data_for_recursion);
1288 }
1289
1290 float distance_to_intersection = 0.f;
1291 if (func(layer) &&
1292 PointHitsLayer(layer, screen_space_point, &distance_to_intersection) &&
1293 ((!data_for_recursion->closest_match ||
1294 distance_to_intersection > data_for_recursion->closest_distance))) {
1295 data_for_recursion->closest_distance = distance_to_intersection;
1296 data_for_recursion->closest_match = layer;
1297 }
1298}
1299
1300static bool ScrollsAnyDrawnRenderSurfaceLayerListMember(LayerImpl* layer) {
1301 if (!layer->scrollable())
1302 return false;
1303 if (layer->IsDrawnRenderSurfaceLayerListMember())
1304 return true;
1305 if (!layer->scroll_children())
1306 return false;
1307 for (std::set<LayerImpl*>::const_iterator it =
1308 layer->scroll_children()->begin();
1309 it != layer->scroll_children()->end();
1310 ++it) {
1311 if ((*it)->IsDrawnRenderSurfaceLayerListMember())
1312 return true;
1313 }
1314 return false;
1315}
1316
1317struct FindScrollingLayerFunctor {
1318 bool operator()(LayerImpl* layer) const {
1319 return ScrollsAnyDrawnRenderSurfaceLayerListMember(layer);
1320 }
1321};
1322
1323LayerImpl* LayerTreeImpl::FindFirstScrollingLayerThatIsHitByPoint(
1324 const gfx::PointF& screen_space_point) {
1325 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1326 FindClosestMatchingLayer(screen_space_point,
1327 root_layer(),
1328 FindScrollingLayerFunctor(),
1329 &data_for_recursion);
1330 return data_for_recursion.closest_match;
1331}
1332
1333struct HitTestVisibleScrollableOrTouchableFunctor {
1334 bool operator()(LayerImpl* layer) const {
1335 return layer->IsDrawnRenderSurfaceLayerListMember() ||
1336 ScrollsAnyDrawnRenderSurfaceLayerListMember(layer) ||
1337 !layer->touch_event_handler_region().IsEmpty() ||
1338 layer->have_wheel_event_handlers();
1339 }
1340};
1341
1342LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPoint(
1343 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321344 if (!root_layer())
1345 return NULL;
1346 if (!UpdateDrawProperties())
1347 return NULL;
[email protected]28336d52014-05-12 19:07:281348 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1349 FindClosestMatchingLayer(screen_space_point,
1350 root_layer(),
1351 HitTestVisibleScrollableOrTouchableFunctor(),
1352 &data_for_recursion);
1353 return data_for_recursion.closest_match;
1354}
1355
1356static bool LayerHasTouchEventHandlersAt(const gfx::PointF& screen_space_point,
1357 LayerImpl* layer_impl) {
1358 if (layer_impl->touch_event_handler_region().IsEmpty())
1359 return false;
1360
1361 if (!PointHitsRegion(screen_space_point,
1362 layer_impl->screen_space_transform(),
1363 layer_impl->touch_event_handler_region(),
1364 layer_impl->contents_scale_x(),
1365 layer_impl->contents_scale_y()))
1366 return false;
1367
1368 // At this point, we think the point does hit the touch event handler region
1369 // on the layer, but we need to walk up the parents to ensure that the layer
1370 // was not clipped in such a way that the hit point actually should not hit
1371 // the layer.
1372 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
1373 return false;
1374
1375 return true;
1376}
1377
1378struct FindTouchEventLayerFunctor {
1379 bool operator()(LayerImpl* layer) const {
1380 return LayerHasTouchEventHandlersAt(screen_space_point, layer);
1381 }
1382 const gfx::PointF screen_space_point;
1383};
1384
1385LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion(
1386 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321387 if (!root_layer())
1388 return NULL;
1389 if (!UpdateDrawProperties())
1390 return NULL;
[email protected]28336d52014-05-12 19:07:281391 FindTouchEventLayerFunctor func = {screen_space_point};
1392 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1393 FindClosestMatchingLayer(
1394 screen_space_point, root_layer(), func, &data_for_recursion);
1395 return data_for_recursion.closest_match;
1396}
1397
[email protected]ebb179b2014-07-16 17:54:411398void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& start,
1399 const LayerSelectionBound& end) {
1400 selection_start_ = start;
1401 selection_end_ = end;
[email protected]19aec372014-07-01 19:08:491402}
1403
1404static ViewportSelectionBound ComputeViewportSelection(
[email protected]6ef948732014-08-22 18:57:441405 const LayerSelectionBound& layer_bound,
[email protected]19aec372014-07-01 19:08:491406 LayerImpl* layer,
1407 float device_scale_factor) {
[email protected]6ef948732014-08-22 18:57:441408 ViewportSelectionBound viewport_bound;
1409 viewport_bound.type = layer_bound.type;
[email protected]19aec372014-07-01 19:08:491410
[email protected]6ef948732014-08-22 18:57:441411 if (!layer || layer_bound.type == SELECTION_BOUND_EMPTY)
1412 return viewport_bound;
[email protected]19aec372014-07-01 19:08:491413
[email protected]6ef948732014-08-22 18:57:441414 gfx::PointF layer_scaled_top = gfx::ScalePoint(layer_bound.edge_top,
1415 layer->contents_scale_x(),
1416 layer->contents_scale_y());
1417 gfx::PointF layer_scaled_bottom = gfx::ScalePoint(layer_bound.edge_bottom,
1418 layer->contents_scale_x(),
1419 layer->contents_scale_y());
[email protected]19aec372014-07-01 19:08:491420
[email protected]6ef948732014-08-22 18:57:441421 bool clipped = false;
1422 gfx::PointF screen_top = MathUtil::MapPoint(
1423 layer->screen_space_transform(), layer_scaled_top, &clipped);
1424 gfx::PointF screen_bottom = MathUtil::MapPoint(
1425 layer->screen_space_transform(), layer_scaled_bottom, &clipped);
1426
1427 const float inv_scale = 1.f / device_scale_factor;
1428 viewport_bound.edge_top = gfx::ScalePoint(screen_top, inv_scale);
1429 viewport_bound.edge_bottom = gfx::ScalePoint(screen_bottom, inv_scale);
1430
1431 // The bottom edge point is used for visibility testing as it is the logical
[email protected]19aec372014-07-01 19:08:491432 // focal point for bound selection handles (this may change in the future).
[email protected]6ef948732014-08-22 18:57:441433 // Shifting the visibility point fractionally inward ensures that neighboring
1434 // or logically coincident layers aligned to integral DPI coordinates will not
1435 // spuriously occlude the bound.
1436 gfx::Vector2dF visibility_offset = layer_scaled_top - layer_scaled_bottom;
1437 visibility_offset.Scale(device_scale_factor / visibility_offset.Length());
1438 gfx::PointF visibility_point = layer_scaled_bottom + visibility_offset;
1439 if (visibility_point.x() <= 0)
1440 visibility_point.set_x(visibility_point.x() + device_scale_factor);
1441 visibility_point = MathUtil::MapPoint(
1442 layer->screen_space_transform(), visibility_point, &clipped);
1443
[email protected]19aec372014-07-01 19:08:491444 float intersect_distance = 0.f;
[email protected]6ef948732014-08-22 18:57:441445 viewport_bound.visible =
1446 PointHitsLayer(layer, visibility_point, &intersect_distance);
[email protected]19aec372014-07-01 19:08:491447
[email protected]6ef948732014-08-22 18:57:441448 return viewport_bound;
[email protected]19aec372014-07-01 19:08:491449}
1450
[email protected]ebb179b2014-07-16 17:54:411451void LayerTreeImpl::GetViewportSelection(ViewportSelectionBound* start,
1452 ViewportSelectionBound* end) {
1453 DCHECK(start);
1454 DCHECK(end);
[email protected]19aec372014-07-01 19:08:491455
[email protected]ebb179b2014-07-16 17:54:411456 *start = ComputeViewportSelection(
1457 selection_start_,
1458 selection_start_.layer_id ? LayerById(selection_start_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491459 device_scale_factor());
[email protected]ebb179b2014-07-16 17:54:411460 if (start->type == SELECTION_BOUND_CENTER ||
1461 start->type == SELECTION_BOUND_EMPTY) {
1462 *end = *start;
[email protected]19aec372014-07-01 19:08:491463 } else {
[email protected]ebb179b2014-07-16 17:54:411464 *end = ComputeViewportSelection(
1465 selection_end_,
1466 selection_end_.layer_id ? LayerById(selection_end_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491467 device_scale_factor());
1468 }
1469}
1470
[email protected]8aa39ecb2014-06-12 14:19:141471void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) {
1472 layer_tree_host_impl_->RegisterPictureLayerImpl(layer);
1473}
1474
1475void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
1476 layer_tree_host_impl_->UnregisterPictureLayerImpl(layer);
1477}
1478
[email protected]749cbc62014-07-10 01:06:351479void LayerTreeImpl::InputScrollAnimationFinished() {
1480 layer_tree_host_impl_->ScrollEnd();
1481}
1482
vmpstr56ace232014-10-09 20:16:281483bool LayerTreeImpl::SmoothnessTakesPriority() const {
1484 return layer_tree_host_impl_->GetTreePriority() == SMOOTHNESS_TAKES_PRIORITY;
1485}
1486
skyostil3976a3f2014-09-04 22:07:231487BlockingTaskRunner* LayerTreeImpl::BlockingMainThreadTaskRunner() const {
1488 return proxy()->blocking_main_thread_task_runner();
1489}
1490
bokanfcdbc182014-11-21 21:53:331491void LayerTreeImpl::SetPendingPageScaleAnimation(
1492 scoped_ptr<PendingPageScaleAnimation> pending_animation) {
1493 pending_page_scale_animation_ = pending_animation.Pass();
bokan915bf352014-10-02 21:57:141494}
1495
bokanfcdbc182014-11-21 21:53:331496scoped_ptr<PendingPageScaleAnimation>
1497 LayerTreeImpl::TakePendingPageScaleAnimation() {
1498 return pending_page_scale_animation_.Pass();
bokan915bf352014-10-02 21:57:141499}
1500
[email protected]ca2902e92013-03-28 01:45:351501} // namespace cc