blob: 948c2bae3204342669eec1748c24ff0e0bdabd5f [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"
[email protected]28336d52014-05-12 19:07:2830#include "ui/gfx/point_conversions.h"
[email protected]ffb2720f2013-03-15 19:18:3731#include "ui/gfx/size_conversions.h"
[email protected]caa567d2012-12-20 07:56:1632#include "ui/gfx/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.
miletusf57925d2014-10-01 19:38:1352 virtual void SetTotalScrollOffset(
53 const gfx::ScrollOffset& new_offset) OVERRIDE {
[email protected]adeda572014-01-31 00:49:4754 last_set_scroll_offset_ = new_offset;
55 layer_tree_impl_->UpdateScrollOffsetDelegate();
56 }
57
miletusf57925d2014-10-01 19:38:1358 virtual gfx::ScrollOffset GetTotalScrollOffset() OVERRIDE {
[email protected]adeda572014-01-31 00:49:4759 return layer_tree_impl_->GetDelegatedScrollOffset(layer_);
60 }
61
62 virtual bool IsExternalFlingActive() const OVERRIDE {
63 return delegate_->IsExternalFlingActive();
64 }
65
[email protected]adeda572014-01-31 00:49:4766 private:
67 LayerImpl* layer_;
68 LayerScrollOffsetDelegate* delegate_;
69 LayerTreeImpl* layer_tree_impl_;
miletusf57925d2014-10-01 19:38:1370 gfx::ScrollOffset last_set_scroll_offset_;
[email protected]adeda572014-01-31 00:49:4771};
72
[email protected]8bef40572012-12-11 21:38:0873LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
[email protected]db8259f2013-02-01 05:25:0474 : layer_tree_host_impl_(layer_tree_host_impl),
75 source_frame_number_(-1),
76 hud_layer_(0),
[email protected]1960a712013-04-30 17:06:4777 currently_scrolling_layer_(NULL),
78 root_layer_scroll_offset_delegate_(NULL),
[email protected]db8259f2013-02-01 05:25:0479 background_color_(0),
80 has_transparent_background_(false),
[email protected]57ac9482013-09-17 21:13:3981 page_scale_layer_(NULL),
82 inner_viewport_scroll_layer_(NULL),
83 outer_viewport_scroll_layer_(NULL),
[email protected]db8259f2013-02-01 05:25:0484 page_scale_factor_(1),
85 page_scale_delta_(1),
86 sent_page_scale_delta_(1),
87 min_page_scale_factor_(0),
88 max_page_scale_factor_(0),
89 scrolling_layer_id_from_previous_tree_(0),
90 contents_textures_purged_(false),
[email protected]3d609bb2014-02-01 01:10:2391 requires_high_res_to_draw_(false),
[email protected]318822852013-02-14 00:54:2792 viewport_size_invalid_(false),
[email protected]db8259f2013-02-01 05:25:0493 needs_update_draw_properties_(true),
[email protected]7d08a9352013-10-15 08:24:5694 needs_full_tree_sync_(true),
[email protected]390bb1ff2014-05-09 17:14:4095 next_activation_forces_redraw_(false),
[email protected]759dc9f2014-07-23 19:18:5196 has_ever_been_drawn_(false),
bokan88eae012014-09-09 20:40:4297 render_surface_layer_list_id_(0),
98 top_controls_layout_height_(0),
bokan55b2f152014-09-15 14:47:5999 top_controls_content_offset_(0),
bokan88eae012014-09-09 20:40:42100 top_controls_delta_(0),
101 sent_top_controls_delta_(0) {
[email protected]390bb1ff2014-05-09 17:14:40102}
[email protected]3b31c6ac2012-12-06 21:27:29103
104LayerTreeImpl::~LayerTreeImpl() {
[email protected]586871b2014-07-22 17:05:11105 BreakSwapPromises(SwapPromise::SWAP_FAILS);
106
[email protected]361bc00d2012-12-14 07:03:24107 // Need to explicitly clear the tree prior to destroying this so that
108 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
[email protected]df17af52014-02-06 02:20:40109 DCHECK(!root_layer_);
110 DCHECK(layers_with_copy_output_request_.empty());
[email protected]3b31c6ac2012-12-06 21:27:29111}
112
danakjf446a072014-09-27 21:55:48113void LayerTreeImpl::Shutdown() {
114 root_layer_ = nullptr;
115}
[email protected]df17af52014-02-06 02:20:40116
[email protected]aeef2f02014-05-10 12:15:48117void LayerTreeImpl::ReleaseResources() {
118 if (root_layer_)
119 ReleaseResourcesRecursive(root_layer_.get());
120}
121
[email protected]d35cd7b22014-01-29 14:32:46122void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
[email protected]adeda572014-01-31 00:49:47123 if (inner_viewport_scroll_layer_)
124 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
125 if (outer_viewport_scroll_layer_)
126 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48127 inner_viewport_scroll_delegate_proxy_ = nullptr;
128 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]adeda572014-01-31 00:49:47129
[email protected]3b31c6ac2012-12-06 21:27:29130 root_layer_ = layer.Pass();
[email protected]5c4824e12013-01-12 16:34:53131 currently_scrolling_layer_ = NULL;
[email protected]adeda572014-01-31 00:49:47132 inner_viewport_scroll_layer_ = NULL;
133 outer_viewport_scroll_layer_ = NULL;
134 page_scale_layer_ = NULL;
[email protected]5c4824e12013-01-12 16:34:53135
[email protected]c1bb5af2013-03-13 19:06:27136 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]5c4824e12013-01-12 16:34:53137}
138
[email protected]adeda572014-01-31 00:49:47139LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const {
140 return inner_viewport_scroll_layer_;
141}
[email protected]3b31c6ac2012-12-06 21:27:29142
[email protected]adeda572014-01-31 00:49:47143LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const {
144 return outer_viewport_scroll_layer_;
145}
[email protected]1960a712013-04-30 17:06:47146
miletusf57925d2014-10-01 19:38:13147gfx::ScrollOffset LayerTreeImpl::TotalScrollOffset() const {
148 gfx::ScrollOffset offset;
[email protected]3b31c6ac2012-12-06 21:27:29149
[email protected]adeda572014-01-31 00:49:47150 if (inner_viewport_scroll_layer_)
151 offset += inner_viewport_scroll_layer_->TotalScrollOffset();
152
153 if (outer_viewport_scroll_layer_)
154 offset += outer_viewport_scroll_layer_->TotalScrollOffset();
155
156 return offset;
157}
158
miletusf57925d2014-10-01 19:38:13159gfx::ScrollOffset LayerTreeImpl::TotalMaxScrollOffset() const {
160 gfx::ScrollOffset offset;
[email protected]adeda572014-01-31 00:49:47161
162 if (inner_viewport_scroll_layer_)
163 offset += inner_viewport_scroll_layer_->MaxScrollOffset();
164
165 if (outer_viewport_scroll_layer_)
166 offset += outer_viewport_scroll_layer_->MaxScrollOffset();
167
168 return offset;
169}
170gfx::Vector2dF LayerTreeImpl::TotalScrollDelta() const {
171 DCHECK(inner_viewport_scroll_layer_);
172 gfx::Vector2dF delta = inner_viewport_scroll_layer_->ScrollDelta();
173
174 if (outer_viewport_scroll_layer_)
175 delta += outer_viewport_scroll_layer_->ScrollDelta();
176
177 return delta;
[email protected]3b31c6ac2012-12-06 21:27:29178}
179
180scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
181 // Clear all data structures that have direct references to the layer tree.
182 scrolling_layer_id_from_previous_tree_ =
183 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]adeda572014-01-31 00:49:47184 if (inner_viewport_scroll_layer_)
185 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
186 if (outer_viewport_scroll_layer_)
187 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48188 inner_viewport_scroll_delegate_proxy_ = nullptr;
189 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]adeda572014-01-31 00:49:47190 inner_viewport_scroll_layer_ = NULL;
191 outer_viewport_scroll_layer_ = NULL;
192 page_scale_layer_ = NULL;
[email protected]3b31c6ac2012-12-06 21:27:29193 currently_scrolling_layer_ = NULL;
194
[email protected]76ffd9e2012-12-20 19:12:47195 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16196 set_needs_update_draw_properties();
[email protected]3b31c6ac2012-12-06 21:27:29197 return root_layer_.Pass();
198}
199
[email protected]7aba6662013-03-12 10:17:34200void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
[email protected]c9280762013-08-01 06:28:57201 // The request queue should have been processed and does not require a push.
202 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
203
[email protected]7d08a9352013-10-15 08:24:56204 if (next_activation_forces_redraw_) {
[email protected]12a63da2014-06-13 06:06:22205 target_tree->ForceRedrawNextActivation();
[email protected]7d08a9352013-10-15 08:24:56206 next_activation_forces_redraw_ = false;
207 }
208
[email protected]b69c1db2013-11-27 00:05:19209 target_tree->PassSwapPromises(&swap_promise_list_);
210
bokan88eae012014-09-09 20:40:42211 target_tree->top_controls_layout_height_ = top_controls_layout_height_;
bokan55b2f152014-09-15 14:47:59212 target_tree->top_controls_content_offset_ = top_controls_content_offset_;
bokan88eae012014-09-09 20:40:42213 target_tree->top_controls_delta_ =
214 target_tree->top_controls_delta_ -
215 target_tree->sent_top_controls_delta_;
216 target_tree->sent_top_controls_delta_ = 0.f;
217
[email protected]d6021f6a2014-06-12 21:15:24218 target_tree->SetPageScaleValues(
219 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor(),
[email protected]c60279472013-01-30 12:10:51220 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta());
221 target_tree->set_sent_page_scale_delta(1);
222
bokan915bf352014-10-02 21:57:14223 target_tree->page_scale_animation_ = page_scale_animation_.Pass();
224
[email protected]adeda572014-01-31 00:49:47225 if (page_scale_layer_ && inner_viewport_scroll_layer_) {
[email protected]57ac9482013-09-17 21:13:39226 target_tree->SetViewportLayersFromIds(
227 page_scale_layer_->id(),
228 inner_viewport_scroll_layer_->id(),
229 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
230 : Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47231 } else {
232 target_tree->ClearViewportLayers();
[email protected]57ac9482013-09-17 21:13:39233 }
[email protected]19aec372014-07-01 19:08:49234
[email protected]ebb179b2014-07-16 17:54:41235 target_tree->RegisterSelection(selection_start_, selection_end_);
[email protected]19aec372014-07-01 19:08:49236
[email protected]c60279472013-01-30 12:10:51237 // This should match the property synchronization in
238 // LayerTreeHost::finishCommitOnImplThread().
239 target_tree->set_source_frame_number(source_frame_number());
240 target_tree->set_background_color(background_color());
241 target_tree->set_has_transparent_background(has_transparent_background());
242
243 if (ContentsTexturesPurged())
244 target_tree->SetContentsTexturesPurged();
245 else
246 target_tree->ResetContentsTexturesPurged();
247
[email protected]318822852013-02-14 00:54:27248 if (ViewportSizeInvalid())
249 target_tree->SetViewportSizeInvalid();
250 else
251 target_tree->ResetViewportSizeInvalid();
252
[email protected]c60279472013-01-30 12:10:51253 if (hud_layer())
254 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
[email protected]6ba914122013-03-22 16:26:39255 LayerTreeHostCommon::FindLayerInSubtree(
[email protected]c1bb5af2013-03-13 19:06:27256 target_tree->root_layer(), hud_layer()->id())));
[email protected]c60279472013-01-30 12:10:51257 else
258 target_tree->set_hud_layer(NULL);
[email protected]759dc9f2014-07-23 19:18:51259
260 target_tree->has_ever_been_drawn_ = false;
[email protected]c60279472013-01-30 12:10:51261}
262
[email protected]fef74fd2014-02-27 06:28:17263LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const {
264 return inner_viewport_scroll_layer_
265 ? inner_viewport_scroll_layer_->scroll_clip_layer()
266 : NULL;
[email protected]ffb2720f2013-03-15 19:18:37267}
268
269LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
[email protected]69b50ec2013-01-19 04:58:01270 DCHECK(IsActiveTree());
271 return currently_scrolling_layer_;
272}
273
[email protected]0fc818e2013-03-18 06:45:20274void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
275 if (currently_scrolling_layer_ == layer)
276 return;
277
278 if (currently_scrolling_layer_ &&
279 currently_scrolling_layer_->scrollbar_animation_controller())
[email protected]1dc06162014-03-26 22:54:45280 currently_scrolling_layer_->scrollbar_animation_controller()
[email protected]930ff43b2014-05-02 05:24:00281 ->DidScrollEnd();
[email protected]0fc818e2013-03-18 06:45:20282 currently_scrolling_layer_ = layer;
283 if (layer && layer->scrollbar_animation_controller())
[email protected]930ff43b2014-05-02 05:24:00284 layer->scrollbar_animation_controller()->DidScrollBegin();
[email protected]0fc818e2013-03-18 06:45:20285}
286
[email protected]3b31c6ac2012-12-06 21:27:29287void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
[email protected]0fc818e2013-03-18 06:45:20288 SetCurrentlyScrollingLayer(NULL);
[email protected]3b31c6ac2012-12-06 21:27:29289 scrolling_layer_id_from_previous_tree_ = 0;
290}
291
[email protected]adeda572014-01-31 00:49:47292namespace {
293
294void ForceScrollbarParameterUpdateAfterScaleChange(LayerImpl* current_layer) {
295 if (!current_layer)
296 return;
297
298 while (current_layer) {
299 current_layer->ScrollbarParametersDidChange();
300 current_layer = current_layer->parent();
301 }
302}
303
304} // namespace
305
[email protected]c60279472013-01-30 12:10:51306void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
[email protected]3c0a3252013-03-18 04:24:36307 float min_page_scale_factor, float max_page_scale_factor) {
[email protected]d6021f6a2014-06-12 21:15:24308 SetPageScaleValues(page_scale_factor, min_page_scale_factor,
309 max_page_scale_factor, page_scale_delta_);
310}
[email protected]c60279472013-01-30 12:10:51311
[email protected]d6021f6a2014-06-12 21:15:24312void LayerTreeImpl::SetPageScaleDelta(float delta) {
313 SetPageScaleValues(page_scale_factor_, min_page_scale_factor_,
314 max_page_scale_factor_, delta);
315}
316
317void LayerTreeImpl::SetPageScaleValues(float page_scale_factor,
318 float min_page_scale_factor, float max_page_scale_factor,
319 float page_scale_delta) {
320 bool page_scale_changed =
321 min_page_scale_factor != min_page_scale_factor_ ||
322 max_page_scale_factor != max_page_scale_factor_ ||
323 page_scale_factor != page_scale_factor_;
[email protected]7265e74e2014-02-07 23:43:06324
[email protected]c60279472013-01-30 12:10:51325 min_page_scale_factor_ = min_page_scale_factor;
326 max_page_scale_factor_ = max_page_scale_factor;
327 page_scale_factor_ = page_scale_factor;
[email protected]20d2b742013-09-26 05:41:34328
[email protected]d6021f6a2014-06-12 21:15:24329 float total = page_scale_factor_ * page_scale_delta;
330 if (min_page_scale_factor_ && total < min_page_scale_factor_)
331 page_scale_delta = min_page_scale_factor_ / page_scale_factor_;
332 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
333 page_scale_delta = max_page_scale_factor_ / page_scale_factor_;
334
335 if (page_scale_delta_ == page_scale_delta && !page_scale_changed)
336 return;
337
338 if (page_scale_delta_ != page_scale_delta) {
339 page_scale_delta_ = page_scale_delta;
340
341 if (IsActiveTree()) {
342 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
343 if (pending_tree) {
344 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
345 pending_tree->SetPageScaleDelta(
346 page_scale_delta_ / sent_page_scale_delta_);
347 }
348 }
349
350 set_needs_update_draw_properties();
351 }
352
[email protected]22f200a2013-10-09 18:08:29353 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00354 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
355 TotalScrollOffset(),
356 TotalMaxScrollOffset(),
357 ScrollableSize(),
[email protected]68fe60f2014-02-12 13:49:11358 total_page_scale_factor(),
[email protected]d6021f6a2014-06-12 21:15:24359 min_page_scale_factor_,
360 max_page_scale_factor_);
[email protected]22f200a2013-10-09 18:08:29361 }
[email protected]adeda572014-01-31 00:49:47362
363 ForceScrollbarParameterUpdateAfterScaleChange(page_scale_layer());
[email protected]c60279472013-01-30 12:10:51364}
365
[email protected]257abfa82013-01-29 23:47:24366gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]587941d2014-08-22 01:40:01367 if (!InnerViewportContainerLayer())
368 return gfx::SizeF();
369
370 return gfx::ScaleSize(InnerViewportContainerLayer()->bounds(),
371 1.0f / total_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24372}
373
[email protected]3744e27b2013-11-06 21:44:08374gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const {
[email protected]adeda572014-01-31 00:49:47375 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
376 ? OuterViewportScrollLayer()
377 : InnerViewportScrollLayer();
378 if (!root_scroll_layer || root_scroll_layer->children().empty())
[email protected]3744e27b2013-11-06 21:44:08379 return gfx::Rect();
[email protected]adeda572014-01-31 00:49:47380 LayerImpl* layer = root_scroll_layer->children()[0];
[email protected]8a822692014-02-12 17:30:55381 return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(),
382 gfx::Rect(layer->content_bounds()));
[email protected]3744e27b2013-11-06 21:44:08383}
384
[email protected]58241dc2013-08-20 01:39:25385static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) {
386 layer->ApplySentScrollDeltasFromAbortedCommit();
[email protected]3519b872013-07-30 07:17:50387}
388
[email protected]58241dc2013-08-20 01:39:25389void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50390 DCHECK(IsActiveTree());
391
392 page_scale_factor_ *= sent_page_scale_delta_;
393 page_scale_delta_ /= sent_page_scale_delta_;
394 sent_page_scale_delta_ = 1.f;
395
bokan55b2f152014-09-15 14:47:59396 top_controls_content_offset_ += sent_top_controls_delta_;
bokan88eae012014-09-09 20:40:42397 top_controls_delta_ -= sent_top_controls_delta_;
398 sent_top_controls_delta_ = 0.f;
399
[email protected]3519b872013-07-30 07:17:50400 if (!root_layer())
401 return;
402
403 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]58241dc2013-08-20 01:39:25404 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo));
405}
406
[email protected]daea3d42013-10-23 17:04:50407static void ApplyScrollDeltasSinceBeginMainFrameTo(LayerImpl* layer) {
408 layer->ApplyScrollDeltasSinceBeginMainFrame();
[email protected]58241dc2013-08-20 01:39:25409}
410
[email protected]daea3d42013-10-23 17:04:50411void LayerTreeImpl::ApplyScrollDeltasSinceBeginMainFrame() {
[email protected]58241dc2013-08-20 01:39:25412 DCHECK(IsPendingTree());
413 if (!root_layer())
414 return;
415
416 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]daea3d42013-10-23 17:04:50417 root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginMainFrameTo));
[email protected]3519b872013-07-30 07:17:50418}
419
[email protected]57ac9482013-09-17 21:13:39420void LayerTreeImpl::SetViewportLayersFromIds(
421 int page_scale_layer_id,
422 int inner_viewport_scroll_layer_id,
423 int outer_viewport_scroll_layer_id) {
424 page_scale_layer_ = LayerById(page_scale_layer_id);
425 DCHECK(page_scale_layer_);
426
427 inner_viewport_scroll_layer_ =
428 LayerById(inner_viewport_scroll_layer_id);
429 DCHECK(inner_viewport_scroll_layer_);
430
431 outer_viewport_scroll_layer_ =
432 LayerById(outer_viewport_scroll_layer_id);
433 DCHECK(outer_viewport_scroll_layer_ ||
434 outer_viewport_scroll_layer_id == Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47435
436 if (!root_layer_scroll_offset_delegate_)
437 return;
438
439 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
440 new LayerScrollOffsetDelegateProxy(inner_viewport_scroll_layer_,
441 root_layer_scroll_offset_delegate_,
442 this));
443
444 if (outer_viewport_scroll_layer_)
445 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
446 new LayerScrollOffsetDelegateProxy(outer_viewport_scroll_layer_,
447 root_layer_scroll_offset_delegate_,
448 this));
[email protected]57ac9482013-09-17 21:13:39449}
450
451void LayerTreeImpl::ClearViewportLayers() {
452 page_scale_layer_ = NULL;
453 inner_viewport_scroll_layer_ = NULL;
454 outer_viewport_scroll_layer_ = NULL;
455}
456
[email protected]8f7f298822014-06-13 00:23:32457bool LayerTreeImpl::UpdateDrawProperties() {
458 if (!needs_update_draw_properties_)
459 return true;
[email protected]615c78a2013-01-24 23:44:16460
[email protected]ed511b8d2013-03-25 03:29:29461 // For max_texture_size.
[email protected]615c78a2013-01-24 23:44:16462 if (!layer_tree_host_impl_->renderer())
[email protected]8f7f298822014-06-13 00:23:32463 return false;
[email protected]615c78a2013-01-24 23:44:16464
[email protected]c1bb5af2013-03-13 19:06:27465 if (!root_layer())
[email protected]8f7f298822014-06-13 00:23:32466 return false;
467
468 needs_update_draw_properties_ = false;
469 render_surface_layer_list_.clear();
[email protected]76ffd9e2012-12-20 19:12:47470
[email protected]76ffd9e2012-12-20 19:12:47471 {
[email protected]7a52f43e2013-07-10 01:58:47472 TRACE_EVENT2("cc",
[email protected]c1bb5af2013-03-13 19:06:27473 "LayerTreeImpl::UpdateDrawProperties",
474 "IsActive",
[email protected]7a52f43e2013-07-10 01:58:47475 IsActiveTree(),
476 "SourceFrameNumber",
477 source_frame_number_);
[email protected]57ac9482013-09-17 21:13:39478 LayerImpl* page_scale_layer =
[email protected]fef74fd2014-02-27 06:28:17479 page_scale_layer_ ? page_scale_layer_ : InnerViewportContainerLayer();
hush367d7dd2014-08-29 23:56:01480 bool can_render_to_separate_surface =
481 (layer_tree_host_impl_->GetDrawMode() !=
482 DRAW_MODE_RESOURCELESS_SOFTWARE);
[email protected]390bb1ff2014-05-09 17:14:40483
484 ++render_surface_layer_list_id_;
[email protected]7aad55f2013-07-26 11:25:53485 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
[email protected]c1bb5af2013-03-13 19:06:27486 root_layer(),
[email protected]54af03522013-09-05 00:43:28487 DrawViewportSize(),
488 layer_tree_host_impl_->DrawTransform(),
[email protected]76ffd9e2012-12-20 19:12:47489 device_scale_factor(),
[email protected]c60279472013-01-30 12:10:51490 total_page_scale_factor(),
[email protected]57ac9482013-09-17 21:13:39491 page_scale_layer,
danakj132fdfe2014-09-07 06:08:16492 resource_provider()->max_texture_size(),
[email protected]8e0176d2013-03-21 03:14:52493 settings().can_use_lcd_text,
[email protected]45948712013-09-27 02:46:48494 can_render_to_separate_surface,
[email protected]35a99a12013-05-09 23:52:29495 settings().layer_transforms_should_scale_layer_contents,
[email protected]390bb1ff2014-05-09 17:14:40496 &render_surface_layer_list_,
497 render_surface_layer_list_id_);
[email protected]7aad55f2013-07-26 11:25:53498 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]76ffd9e2012-12-20 19:12:47499 }
[email protected]615c78a2013-01-24 23:44:16500
[email protected]e4be0262013-10-19 16:54:28501 {
502 TRACE_EVENT2("cc",
503 "LayerTreeImpl::UpdateTilePriorities",
504 "IsActive",
505 IsActiveTree(),
506 "SourceFrameNumber",
507 source_frame_number_);
[email protected]562b7ad2014-06-23 22:17:11508 scoped_ptr<OcclusionTracker<LayerImpl> > occlusion_tracker;
509 if (settings().use_occlusion_for_tile_prioritization) {
510 occlusion_tracker.reset(new OcclusionTracker<LayerImpl>(
511 root_layer()->render_surface()->content_rect()));
512 occlusion_tracker->set_minimum_tracking_size(
513 settings().minimum_occlusion_tracking_size);
514 }
515
boliu7473f7f52014-10-01 16:54:56516 bool resourceless_software_draw = (layer_tree_host_impl_->GetDrawMode() ==
517 DRAW_MODE_RESOURCELESS_SOFTWARE);
518
[email protected]e4be0262013-10-19 16:54:28519 // LayerIterator is used here instead of CallFunctionForSubtree to only
520 // UpdateTilePriorities on layers that will be visible (and thus have valid
521 // draw properties) and not because any ordering is required.
[email protected]ba1b33e2014-02-28 16:44:51522 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]e4be0262013-10-19 16:54:28523 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
524 for (LayerIteratorType it =
525 LayerIteratorType::Begin(&render_surface_layer_list_);
526 it != end;
527 ++it) {
[email protected]562b7ad2014-06-23 22:17:11528 if (occlusion_tracker)
529 occlusion_tracker->EnterLayer(it);
530
[email protected]e4be0262013-10-19 16:54:28531 LayerImpl* layer = *it;
vmpstrcdcb5f72014-09-11 00:58:37532 const Occlusion& occlusion_in_content_space =
533 occlusion_tracker ? occlusion_tracker->GetCurrentOcclusionForLayer(
534 layer->draw_transform())
535 : Occlusion();
536
boliu7473f7f52014-10-01 16:54:56537 if (it.represents_itself()) {
538 layer->UpdateTiles(occlusion_in_content_space,
539 resourceless_software_draw);
540 }
[email protected]e4be0262013-10-19 16:54:28541
[email protected]562b7ad2014-06-23 22:17:11542 if (!it.represents_contributing_render_surface()) {
543 if (occlusion_tracker)
544 occlusion_tracker->LeaveLayer(it);
[email protected]6355d2d2014-05-07 15:07:27545 continue;
[email protected]562b7ad2014-06-23 22:17:11546 }
[email protected]6355d2d2014-05-07 15:07:27547
boliu7473f7f52014-10-01 16:54:56548 if (layer->mask_layer()) {
549 layer->mask_layer()->UpdateTiles(occlusion_in_content_space,
550 resourceless_software_draw);
551 }
552 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) {
[email protected]562b7ad2014-06-23 22:17:11553 layer->replica_layer()->mask_layer()->UpdateTiles(
boliu7473f7f52014-10-01 16:54:56554 occlusion_in_content_space, resourceless_software_draw);
555 }
[email protected]562b7ad2014-06-23 22:17:11556
557 if (occlusion_tracker)
558 occlusion_tracker->LeaveLayer(it);
[email protected]e4be0262013-10-19 16:54:28559 }
560 }
561
[email protected]615c78a2013-01-24 23:44:16562 DCHECK(!needs_update_draw_properties_) <<
[email protected]7d19dc342013-05-02 22:02:04563 "CalcDrawProperties should not set_needs_update_draw_properties()";
[email protected]8f7f298822014-06-13 00:23:32564 return true;
[email protected]76ffd9e2012-12-20 19:12:47565}
566
[email protected]50761e92013-03-29 20:51:28567const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const {
[email protected]76ffd9e2012-12-20 19:12:47568 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16569 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47570 return render_surface_layer_list_;
571}
572
[email protected]42ccdbef2013-01-21 07:54:54573gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]adeda572014-01-31 00:49:47574 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
575 ? OuterViewportScrollLayer()
576 : InnerViewportScrollLayer();
577 if (!root_scroll_layer || root_scroll_layer->children().empty())
[email protected]caa567d2012-12-20 07:56:16578 return gfx::Size();
[email protected]adeda572014-01-31 00:49:47579 return root_scroll_layer->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16580}
581
[email protected]361bc00d2012-12-14 07:03:24582LayerImpl* LayerTreeImpl::LayerById(int id) {
583 LayerIdMap::iterator iter = layer_id_map_.find(id);
584 return iter != layer_id_map_.end() ? iter->second : NULL;
585}
586
587void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
588 DCHECK(!LayerById(layer->id()));
589 layer_id_map_[layer->id()] = layer;
590}
591
592void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
593 DCHECK(LayerById(layer->id()));
594 layer_id_map_.erase(layer->id());
595}
596
[email protected]aebf4622014-07-14 16:57:59597size_t LayerTreeImpl::NumLayers() {
598 return layer_id_map_.size();
599}
600
[email protected]ed511b8d2013-03-25 03:29:29601void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) {
[email protected]a90fac72013-06-06 18:56:13602 pending_tree->SetCurrentlyScrollingLayer(
603 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(),
604 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0));
[email protected]1e0f8d62013-01-09 07:41:35605}
606
[email protected]ff1211d2013-06-07 01:58:35607static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34608 layer->DidBecomeActive();
[email protected]db2e29c2014-08-06 05:58:25609 if (layer->mask_layer())
610 layer->mask_layer()->DidBecomeActive();
611 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
612 layer->replica_layer()->mask_layer()->DidBecomeActive();
613
[email protected]ff1211d2013-06-07 01:58:35614 for (size_t i = 0; i < layer->children().size(); ++i)
615 DidBecomeActiveRecursive(layer->children()[i]);
[email protected]37386f052013-01-13 00:42:22616}
617
618void LayerTreeImpl::DidBecomeActive() {
[email protected]12a63da2014-06-13 06:06:22619 if (next_activation_forces_redraw_) {
620 layer_tree_host_impl_->SetFullRootLayerDamage();
621 next_activation_forces_redraw_ = false;
622 }
623
[email protected]adeda572014-01-31 00:49:47624 if (scrolling_layer_id_from_previous_tree_) {
625 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
[email protected]7dcf5632014-06-25 01:11:55626 root_layer(), scrolling_layer_id_from_previous_tree_);
[email protected]adeda572014-01-31 00:49:47627 }
628
[email protected]7dcf5632014-06-25 01:11:55629 // Always reset this flag on activation, as we would only have activated
630 // if we were in a good state.
631 ResetRequiresHighResToDraw();
632
633 if (root_layer())
634 DidBecomeActiveRecursive(root_layer());
635
[email protected]12a63da2014-06-13 06:06:22636 devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(),
637 source_frame_number_);
[email protected]37386f052013-01-13 00:42:22638}
639
[email protected]6f90b9e2013-01-17 23:42:00640bool LayerTreeImpl::ContentsTexturesPurged() const {
641 return contents_textures_purged_;
642}
643
644void LayerTreeImpl::SetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04645 if (contents_textures_purged_)
646 return;
[email protected]6f90b9e2013-01-17 23:42:00647 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27648 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00649}
650
651void LayerTreeImpl::ResetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04652 if (!contents_textures_purged_)
653 return;
[email protected]6f90b9e2013-01-17 23:42:00654 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27655 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00656}
657
[email protected]3d609bb2014-02-01 01:10:23658void LayerTreeImpl::SetRequiresHighResToDraw() {
659 requires_high_res_to_draw_ = true;
660}
661
662void LayerTreeImpl::ResetRequiresHighResToDraw() {
663 requires_high_res_to_draw_ = false;
664}
665
666bool LayerTreeImpl::RequiresHighResToDraw() const {
667 return requires_high_res_to_draw_;
668}
669
[email protected]318822852013-02-14 00:54:27670bool LayerTreeImpl::ViewportSizeInvalid() const {
671 return viewport_size_invalid_;
672}
673
674void LayerTreeImpl::SetViewportSizeInvalid() {
675 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27676 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27677}
678
679void LayerTreeImpl::ResetViewportSizeInvalid() {
680 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27681 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27682}
683
[email protected]48871fc2013-01-23 07:36:51684Proxy* LayerTreeImpl::proxy() const {
685 return layer_tree_host_impl_->proxy();
686}
687
[email protected]ff762fb2012-12-12 19:18:37688const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27689 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37690}
691
[email protected]7a8bcd262014-01-15 12:54:58692const RendererCapabilitiesImpl& LayerTreeImpl::GetRendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27693 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52694}
695
[email protected]0634cdd42013-08-16 00:46:09696ContextProvider* LayerTreeImpl::context_provider() const {
dcheng6afa17002014-08-26 19:11:31697 return output_surface()->context_provider();
[email protected]0634cdd42013-08-16 00:46:09698}
699
[email protected]ff762fb2012-12-12 19:18:37700OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27701 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37702}
703
704ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27705 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37706}
707
708TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27709 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37710}
711
712FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27713 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37714}
715
[email protected]71691c22013-01-18 03:14:22716PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27717 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22718}
719
[email protected]1191d9d2013-02-02 06:00:33720MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27721 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33722}
723
[email protected]4a6c091d2014-04-24 21:06:46724gfx::Size LayerTreeImpl::device_viewport_size() const {
725 return layer_tree_host_impl_->device_viewport_size();
726}
727
[email protected]f117a4c2012-12-16 04:53:10728bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27729 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10730}
731
732bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27733 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10734}
735
[email protected]48871fc2013-01-23 07:36:51736bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27737 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51738}
739
[email protected]f117a4c2012-12-16 04:53:10740LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27741 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10742 if (!tree)
743 return NULL;
744 return tree->LayerById(id);
745}
746
747LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27748 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10749 if (!tree)
750 return NULL;
751 return tree->LayerById(id);
752}
753
[email protected]71618ed2014-07-24 02:23:45754LayerImpl* LayerTreeImpl::FindRecycleTreeLayerById(int id) {
755 LayerTreeImpl* tree = layer_tree_host_impl_->recycle_tree();
756 if (!tree)
757 return NULL;
758 return tree->LayerById(id);
759}
760
[email protected]166db5c82013-01-09 23:54:31761bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27762 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31763}
764
[email protected]04c5900d2014-08-18 13:38:36765BeginFrameArgs LayerTreeImpl::CurrentBeginFrameArgs() const {
766 return layer_tree_host_impl_->CurrentBeginFrameArgs();
[email protected]fb7425a2013-04-22 16:28:55767}
768
[email protected]c92195e2014-05-07 18:18:49769base::TimeDelta LayerTreeImpl::begin_impl_frame_interval() const {
770 return layer_tree_host_impl_->begin_impl_frame_interval();
771}
772
[email protected]d7eb8c72013-03-23 22:57:13773void LayerTreeImpl::SetNeedsCommit() {
774 layer_tree_host_impl_->SetNeedsCommit();
775}
776
[email protected]bd5324592014-07-31 09:09:33777gfx::Rect LayerTreeImpl::DeviceViewport() const {
778 return layer_tree_host_impl_->DeviceViewport();
779}
780
[email protected]54af03522013-09-05 00:43:28781gfx::Size LayerTreeImpl::DrawViewportSize() const {
782 return layer_tree_host_impl_->DrawViewportSize();
783}
784
[email protected]bd5324592014-07-31 09:09:33785const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const {
786 return layer_tree_host_impl_->ViewportRectForTilePriority();
787}
788
[email protected]930ff43b2014-05-02 05:24:00789scoped_ptr<ScrollbarAnimationController>
790LayerTreeImpl::CreateScrollbarAnimationController(LayerImpl* scrolling_layer) {
791 DCHECK(settings().scrollbar_fade_delay_ms);
792 DCHECK(settings().scrollbar_fade_duration_ms);
793 base::TimeDelta delay =
794 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms);
795 base::TimeDelta duration =
796 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms);
797 switch (settings().scrollbar_animator) {
798 case LayerTreeSettings::LinearFade: {
799 return ScrollbarAnimationControllerLinearFade::Create(
danakjf446a072014-09-27 21:55:48800 scrolling_layer, layer_tree_host_impl_, delay, duration);
[email protected]930ff43b2014-05-02 05:24:00801 }
802 case LayerTreeSettings::Thinning: {
803 return ScrollbarAnimationControllerThinning::Create(
danakjf446a072014-09-27 21:55:48804 scrolling_layer, layer_tree_host_impl_, delay, duration);
[email protected]930ff43b2014-05-02 05:24:00805 }
806 case LayerTreeSettings::NoAnimator:
807 NOTREACHED();
808 break;
809 }
danakjf446a072014-09-27 21:55:48810 return nullptr;
[email protected]2ea5aba2013-09-11 14:26:56811}
812
[email protected]b8384e22013-12-03 02:20:48813void LayerTreeImpl::DidAnimateScrollOffset() {
814 layer_tree_host_impl_->DidAnimateScrollOffset();
815}
816
[email protected]13525d62014-05-20 21:22:04817bool LayerTreeImpl::use_gpu_rasterization() const {
818 return layer_tree_host_impl_->use_gpu_rasterization();
819}
820
[email protected]473f1f22014-05-22 08:19:17821bool LayerTreeImpl::create_low_res_tiling() const {
822 return layer_tree_host_impl_->create_low_res_tiling();
823}
824
[email protected]ff762fb2012-12-12 19:18:37825void LayerTreeImpl::SetNeedsRedraw() {
[email protected]59adb112013-04-09 04:48:44826 layer_tree_host_impl_->SetNeedsRedraw();
[email protected]ff762fb2012-12-12 19:18:37827}
828
[email protected]ff762fb2012-12-12 19:18:37829const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27830 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37831}
832
833float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27834 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37835}
836
[email protected]ff762fb2012-12-12 19:18:37837DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27838 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37839}
840
[email protected]de4afb5e2012-12-20 00:11:34841AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27842 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34843}
[email protected]ff762fb2012-12-12 19:18:37844
vmpstrd7de03c2014-08-27 18:11:01845void LayerTreeImpl::GetAllTilesForTracing(std::set<const Tile*>* tiles) const {
846 typedef LayerIterator<LayerImpl> LayerIteratorType;
847 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
848 for (LayerIteratorType it =
849 LayerIteratorType::Begin(&render_surface_layer_list_);
850 it != end;
851 ++it) {
852 if (!it.represents_itself())
853 continue;
854 LayerImpl* layer_impl = *it;
855 layer_impl->GetAllTilesForTracing(tiles);
856 }
857}
858
[email protected]d12aa932014-08-01 13:10:38859void LayerTreeImpl::AsValueInto(base::debug::TracedValue* state) const {
860 TracedValue::MakeDictIntoImplicitSnapshot(state, "cc::LayerTreeImpl", this);
nduca929378a02014-08-23 19:48:52861 state->SetInteger("source_frame_number", source_frame_number_);
[email protected]f6742f52013-05-08 23:52:22862
[email protected]d12aa932014-08-01 13:10:38863 state->BeginDictionary("root_layer");
864 root_layer_->AsValueInto(state);
865 state->EndDictionary();
[email protected]f6742f52013-05-08 23:52:22866
[email protected]d12aa932014-08-01 13:10:38867 state->BeginArray("render_surface_layer_list");
[email protected]ba1b33e2014-02-28 16:44:51868 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09869 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
870 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]8c5690222013-02-15 17:36:43871 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09872 if (!it.represents_itself())
[email protected]8c5690222013-02-15 17:36:43873 continue;
[email protected]d12aa932014-08-01 13:10:38874 TracedValue::AppendIDRef(*it, state);
[email protected]8c5690222013-02-15 17:36:43875 }
[email protected]d12aa932014-08-01 13:10:38876 state->EndArray();
skyostil43c330f72014-09-22 16:49:11877
878 state->BeginArray("swap_promise_trace_ids");
879 for (size_t i = 0; i < swap_promise_list_.size(); i++)
880 state->AppendDouble(swap_promise_list_[i]->TraceId());
881 state->EndArray();
[email protected]8c5690222013-02-15 17:36:43882}
883
[email protected]1960a712013-04-30 17:06:47884void LayerTreeImpl::SetRootLayerScrollOffsetDelegate(
[email protected]c9280762013-08-01 06:28:57885 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
[email protected]20d2b742013-09-26 05:41:34886 if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate)
887 return;
888
[email protected]adeda572014-01-31 00:49:47889 if (!root_layer_scroll_offset_delegate) {
890 // Make sure we remove the proxies from their layers before
891 // releasing them.
892 if (InnerViewportScrollLayer())
893 InnerViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
894 if (OuterViewportScrollLayer())
895 OuterViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48896 inner_viewport_scroll_delegate_proxy_ = nullptr;
897 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]d35cd7b22014-01-29 14:32:46898 }
899
[email protected]adeda572014-01-31 00:49:47900 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
901
[email protected]20d2b742013-09-26 05:41:34902 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00903 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
904 TotalScrollOffset(),
905 TotalMaxScrollOffset(),
906 ScrollableSize(),
[email protected]68fe60f2014-02-12 13:49:11907 total_page_scale_factor(),
908 min_page_scale_factor(),
909 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47910
911 if (inner_viewport_scroll_layer_) {
912 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
913 new LayerScrollOffsetDelegateProxy(InnerViewportScrollLayer(),
914 root_layer_scroll_offset_delegate_,
915 this));
916 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(
917 inner_viewport_scroll_delegate_proxy_.get());
918 }
919
920 if (outer_viewport_scroll_layer_) {
921 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
922 new LayerScrollOffsetDelegateProxy(OuterViewportScrollLayer(),
923 root_layer_scroll_offset_delegate_,
924 this));
925 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(
926 outer_viewport_scroll_delegate_proxy_.get());
927 }
[email protected]20d2b742013-09-26 05:41:34928 }
[email protected]1960a712013-04-30 17:06:47929}
930
[email protected]adeda572014-01-31 00:49:47931void LayerTreeImpl::UpdateScrollOffsetDelegate() {
932 DCHECK(InnerViewportScrollLayer());
933 DCHECK(root_layer_scroll_offset_delegate_);
934
miletusf57925d2014-10-01 19:38:13935 gfx::ScrollOffset offset =
[email protected]adeda572014-01-31 00:49:47936 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
937
938 if (OuterViewportScrollLayer())
939 offset += outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
940
[email protected]ec2322e2014-05-15 16:32:00941 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
942 offset,
943 TotalMaxScrollOffset(),
944 ScrollableSize(),
945 total_page_scale_factor(),
946 min_page_scale_factor(),
947 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47948}
949
miletusf57925d2014-10-01 19:38:13950gfx::ScrollOffset LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) {
[email protected]adeda572014-01-31 00:49:47951 DCHECK(root_layer_scroll_offset_delegate_);
952 DCHECK(InnerViewportScrollLayer());
953 if (layer == InnerViewportScrollLayer() && !OuterViewportScrollLayer())
954 return root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
955
956 // If we get here, we have both inner/outer viewports, and need to distribute
957 // the scroll offset between them.
958 DCHECK(inner_viewport_scroll_delegate_proxy_);
959 DCHECK(outer_viewport_scroll_delegate_proxy_);
miletusf57925d2014-10-01 19:38:13960 gfx::ScrollOffset inner_viewport_offset =
[email protected]adeda572014-01-31 00:49:47961 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
miletusf57925d2014-10-01 19:38:13962 gfx::ScrollOffset outer_viewport_offset =
[email protected]adeda572014-01-31 00:49:47963 outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
964
965 // It may be nothing has changed.
miletusf57925d2014-10-01 19:38:13966 gfx::ScrollOffset delegate_offset =
[email protected]adeda572014-01-31 00:49:47967 root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
968 if (inner_viewport_offset + outer_viewport_offset == delegate_offset) {
969 if (layer == InnerViewportScrollLayer())
970 return inner_viewport_offset;
971 else
972 return outer_viewport_offset;
973 }
974
miletusf57925d2014-10-01 19:38:13975 gfx::ScrollOffset max_outer_viewport_scroll_offset =
[email protected]adeda572014-01-31 00:49:47976 OuterViewportScrollLayer()->MaxScrollOffset();
977
978 outer_viewport_offset = delegate_offset - inner_viewport_offset;
979 outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset);
miletusf57925d2014-10-01 19:38:13980 outer_viewport_offset.SetToMax(gfx::ScrollOffset());
[email protected]adeda572014-01-31 00:49:47981
982 if (layer == OuterViewportScrollLayer())
983 return outer_viewport_offset;
984
985 inner_viewport_offset = delegate_offset - outer_viewport_offset;
986
987 return inner_viewport_offset;
988}
989
[email protected]b69c1db2013-11-27 00:05:19990void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) {
991 DCHECK(swap_promise);
[email protected]b69c1db2013-11-27 00:05:19992 swap_promise_list_.push_back(swap_promise.Pass());
993}
994
995void LayerTreeImpl::PassSwapPromises(
996 ScopedPtrVector<SwapPromise>* new_swap_promise) {
997 swap_promise_list_.insert_and_take(swap_promise_list_.end(),
weiliangcc1878c62014-09-02 22:43:17998 new_swap_promise);
[email protected]b69c1db2013-11-27 00:05:19999 new_swap_promise->clear();
1000}
1001
[email protected]d359203a2013-11-29 06:16:551002void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) {
[email protected]b69c1db2013-11-27 00:05:191003 for (size_t i = 0; i < swap_promise_list_.size(); i++)
[email protected]d359203a2013-11-29 06:16:551004 swap_promise_list_[i]->DidSwap(metadata);
[email protected]b69c1db2013-11-27 00:05:191005 swap_promise_list_.clear();
1006}
1007
1008void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) {
1009 for (size_t i = 0; i < swap_promise_list_.size(); i++)
1010 swap_promise_list_[i]->DidNotSwap(reason);
1011 swap_promise_list_.clear();
1012}
1013
[email protected]c48536a52013-09-14 00:02:081014void LayerTreeImpl::DidModifyTilePriorities() {
1015 layer_tree_host_impl_->DidModifyTilePriorities();
[email protected]fcb846d2013-05-22 01:42:361016}
1017
[email protected]c9280762013-08-01 06:28:571018void LayerTreeImpl::set_ui_resource_request_queue(
1019 const UIResourceRequestQueue& queue) {
1020 ui_resource_request_queue_ = queue;
1021}
1022
1023ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource(
1024 UIResourceId uid) const {
1025 return layer_tree_host_impl_->ResourceIdForUIResource(uid);
1026}
1027
[email protected]709c9542013-10-26 01:43:511028bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const {
1029 return layer_tree_host_impl_->IsUIResourceOpaque(uid);
1030}
1031
[email protected]c9280762013-08-01 06:28:571032void LayerTreeImpl::ProcessUIResourceRequestQueue() {
1033 while (ui_resource_request_queue_.size() > 0) {
1034 UIResourceRequest req = ui_resource_request_queue_.front();
1035 ui_resource_request_queue_.pop_front();
1036
[email protected]741fba422013-09-20 03:34:141037 switch (req.GetType()) {
[email protected]c9280762013-08-01 06:28:571038 case UIResourceRequest::UIResourceCreate:
[email protected]741fba422013-09-20 03:34:141039 layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap());
[email protected]c9280762013-08-01 06:28:571040 break;
1041 case UIResourceRequest::UIResourceDelete:
[email protected]741fba422013-09-20 03:34:141042 layer_tree_host_impl_->DeleteUIResource(req.GetId());
[email protected]c9280762013-08-01 06:28:571043 break;
[email protected]f28d64d2013-08-27 04:17:451044 case UIResourceRequest::UIResourceInvalidRequest:
[email protected]c9280762013-08-01 06:28:571045 NOTREACHED();
1046 break;
1047 }
1048 }
[email protected]127bdc1a2013-09-11 01:44:481049
1050 // If all UI resource evictions were not recreated by processing this queue,
1051 // then another commit is required.
1052 if (layer_tree_host_impl_->EvictedUIResourcesExist())
1053 layer_tree_host_impl_->SetNeedsCommit();
[email protected]c9280762013-08-01 06:28:571054}
1055
[email protected]30fe19ff2013-07-04 00:54:451056void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) {
1057 // Only the active tree needs to know about layers with copy requests, as
1058 // they are aborted if not serviced during draw.
1059 DCHECK(IsActiveTree());
1060
[email protected]a4ee12812014-02-06 17:33:381061 // DCHECK(std::find(layers_with_copy_output_request_.begin(),
1062 // layers_with_copy_output_request_.end(),
1063 // layer) == layers_with_copy_output_request_.end());
1064 // TODO(danakj): Remove this once crash is found crbug.com/309777
1065 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1066 CHECK(layers_with_copy_output_request_[i] != layer)
1067 << i << " of " << layers_with_copy_output_request_.size();
1068 }
[email protected]30fe19ff2013-07-04 00:54:451069 layers_with_copy_output_request_.push_back(layer);
1070}
1071
1072void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) {
1073 // Only the active tree needs to know about layers with copy requests, as
1074 // they are aborted if not serviced during draw.
1075 DCHECK(IsActiveTree());
1076
1077 std::vector<LayerImpl*>::iterator it = std::find(
1078 layers_with_copy_output_request_.begin(),
1079 layers_with_copy_output_request_.end(),
1080 layer);
1081 DCHECK(it != layers_with_copy_output_request_.end());
[email protected]f5de9e5b2013-07-30 22:26:571082 layers_with_copy_output_request_.erase(it);
[email protected]a4ee12812014-02-06 17:33:381083
1084 // TODO(danakj): Remove this once crash is found crbug.com/309777
1085 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1086 CHECK(layers_with_copy_output_request_[i] != layer)
1087 << i << " of " << layers_with_copy_output_request_.size();
1088 }
[email protected]30fe19ff2013-07-04 00:54:451089}
1090
[email protected]53526372013-12-07 04:31:501091const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest()
[email protected]30fe19ff2013-07-04 00:54:451092 const {
1093 // Only the active tree needs to know about layers with copy requests, as
1094 // they are aborted if not serviced during draw.
1095 DCHECK(IsActiveTree());
1096
1097 return layers_with_copy_output_request_;
1098}
1099
[email protected]aeef2f02014-05-10 12:15:481100void LayerTreeImpl::ReleaseResourcesRecursive(LayerImpl* current) {
1101 DCHECK(current);
1102 current->ReleaseResources();
1103 if (current->mask_layer())
1104 ReleaseResourcesRecursive(current->mask_layer());
1105 if (current->replica_layer())
1106 ReleaseResourcesRecursive(current->replica_layer());
1107 for (size_t i = 0; i < current->children().size(); ++i)
1108 ReleaseResourcesRecursive(current->children()[i]);
1109}
1110
[email protected]28336d52014-05-12 19:07:281111template <typename LayerType>
1112static inline bool LayerClipsSubtree(LayerType* layer) {
1113 return layer->masks_to_bounds() || layer->mask_layer();
1114}
1115
1116static bool PointHitsRect(
1117 const gfx::PointF& screen_space_point,
1118 const gfx::Transform& local_space_to_screen_space_transform,
1119 const gfx::RectF& local_space_rect,
1120 float* distance_to_camera) {
1121 // If the transform is not invertible, then assume that this point doesn't hit
1122 // this rect.
1123 gfx::Transform inverse_local_space_to_screen_space(
1124 gfx::Transform::kSkipInitialization);
1125 if (!local_space_to_screen_space_transform.GetInverse(
1126 &inverse_local_space_to_screen_space))
1127 return false;
1128
1129 // Transform the hit test point from screen space to the local space of the
1130 // given rect.
1131 bool clipped = false;
1132 gfx::Point3F planar_point = MathUtil::ProjectPoint3D(
1133 inverse_local_space_to_screen_space, screen_space_point, &clipped);
1134 gfx::PointF hit_test_point_in_local_space =
1135 gfx::PointF(planar_point.x(), planar_point.y());
1136
1137 // If ProjectPoint could not project to a valid value, then we assume that
1138 // this point doesn't hit this rect.
1139 if (clipped)
1140 return false;
1141
1142 if (!local_space_rect.Contains(hit_test_point_in_local_space))
1143 return false;
1144
1145 if (distance_to_camera) {
1146 // To compute the distance to the camera, we have to take the planar point
1147 // and pull it back to world space and compute the displacement along the
1148 // z-axis.
1149 gfx::Point3F planar_point_in_screen_space(planar_point);
1150 local_space_to_screen_space_transform.TransformPoint(
1151 &planar_point_in_screen_space);
1152 *distance_to_camera = planar_point_in_screen_space.z();
1153 }
1154
1155 return true;
1156}
1157
1158static bool PointHitsRegion(const gfx::PointF& screen_space_point,
1159 const gfx::Transform& screen_space_transform,
1160 const Region& layer_space_region,
1161 float layer_content_scale_x,
1162 float layer_content_scale_y) {
1163 // If the transform is not invertible, then assume that this point doesn't hit
1164 // this region.
1165 gfx::Transform inverse_screen_space_transform(
1166 gfx::Transform::kSkipInitialization);
1167 if (!screen_space_transform.GetInverse(&inverse_screen_space_transform))
1168 return false;
1169
1170 // Transform the hit test point from screen space to the local space of the
1171 // given region.
1172 bool clipped = false;
1173 gfx::PointF hit_test_point_in_content_space = MathUtil::ProjectPoint(
1174 inverse_screen_space_transform, screen_space_point, &clipped);
1175 gfx::PointF hit_test_point_in_layer_space =
1176 gfx::ScalePoint(hit_test_point_in_content_space,
1177 1.f / layer_content_scale_x,
1178 1.f / layer_content_scale_y);
1179
1180 // If ProjectPoint could not project to a valid value, then we assume that
1181 // this point doesn't hit this region.
1182 if (clipped)
1183 return false;
1184
1185 return layer_space_region.Contains(
1186 gfx::ToRoundedPoint(hit_test_point_in_layer_space));
1187}
1188
[email protected]19aec372014-07-01 19:08:491189static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) {
[email protected]0ec86f52014-06-12 20:54:031190 if (layer->scroll_parent())
1191 return layer->scroll_parent();
1192 if (layer->clip_parent())
1193 return layer->clip_parent();
1194 return layer->parent();
1195}
1196
[email protected]28336d52014-05-12 19:07:281197static bool PointIsClippedBySurfaceOrClipRect(
1198 const gfx::PointF& screen_space_point,
[email protected]19aec372014-07-01 19:08:491199 const LayerImpl* layer) {
[email protected]28336d52014-05-12 19:07:281200 // Walk up the layer tree and hit-test any render_surfaces and any layer
1201 // clip rects that are active.
[email protected]0ec86f52014-06-12 20:54:031202 for (; layer; layer = GetNextClippingLayer(layer)) {
1203 if (layer->render_surface() &&
1204 !PointHitsRect(screen_space_point,
1205 layer->render_surface()->screen_space_transform(),
1206 layer->render_surface()->content_rect(),
1207 NULL))
[email protected]28336d52014-05-12 19:07:281208 return true;
1209
[email protected]0ec86f52014-06-12 20:54:031210 if (LayerClipsSubtree(layer) &&
1211 !PointHitsRect(screen_space_point,
1212 layer->screen_space_transform(),
1213 gfx::Rect(layer->content_bounds()),
1214 NULL))
[email protected]28336d52014-05-12 19:07:281215 return true;
[email protected]28336d52014-05-12 19:07:281216 }
1217
1218 // If we have finished walking all ancestors without having already exited,
1219 // then the point is not clipped by any ancestors.
1220 return false;
1221}
1222
[email protected]19aec372014-07-01 19:08:491223static bool PointHitsLayer(const LayerImpl* layer,
[email protected]28336d52014-05-12 19:07:281224 const gfx::PointF& screen_space_point,
1225 float* distance_to_intersection) {
1226 gfx::RectF content_rect(layer->content_bounds());
1227 if (!PointHitsRect(screen_space_point,
1228 layer->screen_space_transform(),
1229 content_rect,
1230 distance_to_intersection))
1231 return false;
1232
1233 // At this point, we think the point does hit the layer, but we need to walk
1234 // up the parents to ensure that the layer was not clipped in such a way
1235 // that the hit point actually should not hit the layer.
1236 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer))
1237 return false;
1238
1239 // Skip the HUD layer.
1240 if (layer == layer->layer_tree_impl()->hud_layer())
1241 return false;
1242
1243 return true;
1244}
1245
1246struct FindClosestMatchingLayerDataForRecursion {
1247 FindClosestMatchingLayerDataForRecursion()
1248 : closest_match(NULL),
1249 closest_distance(-std::numeric_limits<float>::infinity()) {}
1250 LayerImpl* closest_match;
1251 // Note that the positive z-axis points towards the camera, so bigger means
1252 // closer in this case, counterintuitively.
1253 float closest_distance;
1254};
1255
1256template <typename Functor>
1257static void FindClosestMatchingLayer(
1258 const gfx::PointF& screen_space_point,
1259 LayerImpl* layer,
1260 const Functor& func,
1261 FindClosestMatchingLayerDataForRecursion* data_for_recursion) {
1262 for (int i = layer->children().size() - 1; i >= 0; --i) {
1263 FindClosestMatchingLayer(
1264 screen_space_point, layer->children()[i], func, data_for_recursion);
1265 }
1266
1267 float distance_to_intersection = 0.f;
1268 if (func(layer) &&
1269 PointHitsLayer(layer, screen_space_point, &distance_to_intersection) &&
1270 ((!data_for_recursion->closest_match ||
1271 distance_to_intersection > data_for_recursion->closest_distance))) {
1272 data_for_recursion->closest_distance = distance_to_intersection;
1273 data_for_recursion->closest_match = layer;
1274 }
1275}
1276
1277static bool ScrollsAnyDrawnRenderSurfaceLayerListMember(LayerImpl* layer) {
1278 if (!layer->scrollable())
1279 return false;
1280 if (layer->IsDrawnRenderSurfaceLayerListMember())
1281 return true;
1282 if (!layer->scroll_children())
1283 return false;
1284 for (std::set<LayerImpl*>::const_iterator it =
1285 layer->scroll_children()->begin();
1286 it != layer->scroll_children()->end();
1287 ++it) {
1288 if ((*it)->IsDrawnRenderSurfaceLayerListMember())
1289 return true;
1290 }
1291 return false;
1292}
1293
1294struct FindScrollingLayerFunctor {
1295 bool operator()(LayerImpl* layer) const {
1296 return ScrollsAnyDrawnRenderSurfaceLayerListMember(layer);
1297 }
1298};
1299
1300LayerImpl* LayerTreeImpl::FindFirstScrollingLayerThatIsHitByPoint(
1301 const gfx::PointF& screen_space_point) {
1302 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1303 FindClosestMatchingLayer(screen_space_point,
1304 root_layer(),
1305 FindScrollingLayerFunctor(),
1306 &data_for_recursion);
1307 return data_for_recursion.closest_match;
1308}
1309
1310struct HitTestVisibleScrollableOrTouchableFunctor {
1311 bool operator()(LayerImpl* layer) const {
1312 return layer->IsDrawnRenderSurfaceLayerListMember() ||
1313 ScrollsAnyDrawnRenderSurfaceLayerListMember(layer) ||
1314 !layer->touch_event_handler_region().IsEmpty() ||
1315 layer->have_wheel_event_handlers();
1316 }
1317};
1318
1319LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPoint(
1320 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321321 if (!root_layer())
1322 return NULL;
1323 if (!UpdateDrawProperties())
1324 return NULL;
[email protected]28336d52014-05-12 19:07:281325 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1326 FindClosestMatchingLayer(screen_space_point,
1327 root_layer(),
1328 HitTestVisibleScrollableOrTouchableFunctor(),
1329 &data_for_recursion);
1330 return data_for_recursion.closest_match;
1331}
1332
1333static bool LayerHasTouchEventHandlersAt(const gfx::PointF& screen_space_point,
1334 LayerImpl* layer_impl) {
1335 if (layer_impl->touch_event_handler_region().IsEmpty())
1336 return false;
1337
1338 if (!PointHitsRegion(screen_space_point,
1339 layer_impl->screen_space_transform(),
1340 layer_impl->touch_event_handler_region(),
1341 layer_impl->contents_scale_x(),
1342 layer_impl->contents_scale_y()))
1343 return false;
1344
1345 // At this point, we think the point does hit the touch event handler region
1346 // on the layer, but we need to walk up the parents to ensure that the layer
1347 // was not clipped in such a way that the hit point actually should not hit
1348 // the layer.
1349 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
1350 return false;
1351
1352 return true;
1353}
1354
1355struct FindTouchEventLayerFunctor {
1356 bool operator()(LayerImpl* layer) const {
1357 return LayerHasTouchEventHandlersAt(screen_space_point, layer);
1358 }
1359 const gfx::PointF screen_space_point;
1360};
1361
1362LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion(
1363 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321364 if (!root_layer())
1365 return NULL;
1366 if (!UpdateDrawProperties())
1367 return NULL;
[email protected]28336d52014-05-12 19:07:281368 FindTouchEventLayerFunctor func = {screen_space_point};
1369 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1370 FindClosestMatchingLayer(
1371 screen_space_point, root_layer(), func, &data_for_recursion);
1372 return data_for_recursion.closest_match;
1373}
1374
[email protected]ebb179b2014-07-16 17:54:411375void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& start,
1376 const LayerSelectionBound& end) {
1377 selection_start_ = start;
1378 selection_end_ = end;
[email protected]19aec372014-07-01 19:08:491379}
1380
1381static ViewportSelectionBound ComputeViewportSelection(
[email protected]6ef948732014-08-22 18:57:441382 const LayerSelectionBound& layer_bound,
[email protected]19aec372014-07-01 19:08:491383 LayerImpl* layer,
1384 float device_scale_factor) {
[email protected]6ef948732014-08-22 18:57:441385 ViewportSelectionBound viewport_bound;
1386 viewport_bound.type = layer_bound.type;
[email protected]19aec372014-07-01 19:08:491387
[email protected]6ef948732014-08-22 18:57:441388 if (!layer || layer_bound.type == SELECTION_BOUND_EMPTY)
1389 return viewport_bound;
[email protected]19aec372014-07-01 19:08:491390
[email protected]6ef948732014-08-22 18:57:441391 gfx::PointF layer_scaled_top = gfx::ScalePoint(layer_bound.edge_top,
1392 layer->contents_scale_x(),
1393 layer->contents_scale_y());
1394 gfx::PointF layer_scaled_bottom = gfx::ScalePoint(layer_bound.edge_bottom,
1395 layer->contents_scale_x(),
1396 layer->contents_scale_y());
[email protected]19aec372014-07-01 19:08:491397
[email protected]6ef948732014-08-22 18:57:441398 bool clipped = false;
1399 gfx::PointF screen_top = MathUtil::MapPoint(
1400 layer->screen_space_transform(), layer_scaled_top, &clipped);
1401 gfx::PointF screen_bottom = MathUtil::MapPoint(
1402 layer->screen_space_transform(), layer_scaled_bottom, &clipped);
1403
1404 const float inv_scale = 1.f / device_scale_factor;
1405 viewport_bound.edge_top = gfx::ScalePoint(screen_top, inv_scale);
1406 viewport_bound.edge_bottom = gfx::ScalePoint(screen_bottom, inv_scale);
1407
1408 // The bottom edge point is used for visibility testing as it is the logical
[email protected]19aec372014-07-01 19:08:491409 // focal point for bound selection handles (this may change in the future).
[email protected]6ef948732014-08-22 18:57:441410 // Shifting the visibility point fractionally inward ensures that neighboring
1411 // or logically coincident layers aligned to integral DPI coordinates will not
1412 // spuriously occlude the bound.
1413 gfx::Vector2dF visibility_offset = layer_scaled_top - layer_scaled_bottom;
1414 visibility_offset.Scale(device_scale_factor / visibility_offset.Length());
1415 gfx::PointF visibility_point = layer_scaled_bottom + visibility_offset;
1416 if (visibility_point.x() <= 0)
1417 visibility_point.set_x(visibility_point.x() + device_scale_factor);
1418 visibility_point = MathUtil::MapPoint(
1419 layer->screen_space_transform(), visibility_point, &clipped);
1420
[email protected]19aec372014-07-01 19:08:491421 float intersect_distance = 0.f;
[email protected]6ef948732014-08-22 18:57:441422 viewport_bound.visible =
1423 PointHitsLayer(layer, visibility_point, &intersect_distance);
[email protected]19aec372014-07-01 19:08:491424
[email protected]6ef948732014-08-22 18:57:441425 return viewport_bound;
[email protected]19aec372014-07-01 19:08:491426}
1427
[email protected]ebb179b2014-07-16 17:54:411428void LayerTreeImpl::GetViewportSelection(ViewportSelectionBound* start,
1429 ViewportSelectionBound* end) {
1430 DCHECK(start);
1431 DCHECK(end);
[email protected]19aec372014-07-01 19:08:491432
[email protected]ebb179b2014-07-16 17:54:411433 *start = ComputeViewportSelection(
1434 selection_start_,
1435 selection_start_.layer_id ? LayerById(selection_start_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491436 device_scale_factor());
[email protected]ebb179b2014-07-16 17:54:411437 if (start->type == SELECTION_BOUND_CENTER ||
1438 start->type == SELECTION_BOUND_EMPTY) {
1439 *end = *start;
[email protected]19aec372014-07-01 19:08:491440 } else {
[email protected]ebb179b2014-07-16 17:54:411441 *end = ComputeViewportSelection(
1442 selection_end_,
1443 selection_end_.layer_id ? LayerById(selection_end_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491444 device_scale_factor());
1445 }
1446}
1447
[email protected]8aa39ecb2014-06-12 14:19:141448void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) {
1449 layer_tree_host_impl_->RegisterPictureLayerImpl(layer);
1450}
1451
1452void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
1453 layer_tree_host_impl_->UnregisterPictureLayerImpl(layer);
1454}
1455
[email protected]749cbc62014-07-10 01:06:351456void LayerTreeImpl::InputScrollAnimationFinished() {
1457 layer_tree_host_impl_->ScrollEnd();
1458}
1459
skyostil3976a3f2014-09-04 22:07:231460BlockingTaskRunner* LayerTreeImpl::BlockingMainThreadTaskRunner() const {
1461 return proxy()->blocking_main_thread_task_runner();
1462}
1463
bokan915bf352014-10-02 21:57:141464void LayerTreeImpl::SetPageScaleAnimation(
1465 const gfx::Vector2d& target_offset,
1466 bool anchor_point,
1467 float page_scale,
1468 base::TimeDelta duration) {
1469 if (!InnerViewportScrollLayer())
1470 return;
1471
1472 gfx::ScrollOffset scroll_total = TotalScrollOffset();
1473 gfx::SizeF scaled_scrollable_size = ScrollableSize();
1474 gfx::SizeF viewport_size = InnerViewportContainerLayer()->bounds();
1475
1476 // Easing constants experimentally determined.
1477 scoped_ptr<TimingFunction> timing_function =
1478 CubicBezierTimingFunction::Create(.8, 0, .3, .9);
1479
1480 // TODO(miletus) : Pass in ScrollOffset.
1481 page_scale_animation_ =
1482 PageScaleAnimation::Create(ScrollOffsetToVector2dF(scroll_total),
1483 total_page_scale_factor(),
1484 viewport_size,
1485 scaled_scrollable_size,
1486 timing_function.Pass());
1487
1488 if (anchor_point) {
1489 gfx::Vector2dF anchor(target_offset);
1490 page_scale_animation_->ZoomWithAnchor(anchor,
1491 page_scale,
1492 duration.InSecondsF());
1493 } else {
1494 gfx::Vector2dF scaled_target_offset = target_offset;
1495 page_scale_animation_->ZoomTo(scaled_target_offset,
1496 page_scale,
1497 duration.InSecondsF());
1498 }
1499}
1500
1501scoped_ptr<PageScaleAnimation> LayerTreeImpl::TakePageScaleAnimation() {
1502 return page_scale_animation_.Pass();
1503}
1504
[email protected]ca2902e92013-03-28 01:45:351505} // namespace cc