blob: 36d76019764d3d22f496c0021b2b4cc3d081cc52 [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
aelias6004fe02015-02-07 21:43:017#include <algorithm>
[email protected]28336d52014-05-12 19:07:288#include <limits>
9#include <set>
10
primianoc06e2382015-01-28 04:21:4911#include "base/trace_event/trace_event.h"
12#include "base/trace_event/trace_event_argument.h"
[email protected]95e4e1a02013-03-18 07:09:0913#include "cc/animation/keyframed_animation_curve.h"
14#include "cc/animation/scrollbar_animation_controller.h"
[email protected]930ff43b2014-05-02 05:24:0015#include "cc/animation/scrollbar_animation_controller_linear_fade.h"
16#include "cc/animation/scrollbar_animation_controller_thinning.h"
[email protected]3744e27b2013-11-06 21:44:0817#include "cc/base/math_util.h"
aelias58eec0812014-12-04 01:04:4018#include "cc/base/synced_property.h"
[email protected]3744e27b2013-11-06 21:44:0819#include "cc/base/util.h"
[email protected]12a63da2014-06-13 06:06:2220#include "cc/debug/devtools_instrumentation.h"
[email protected]f6742f52013-05-08 23:52:2221#include "cc/debug/traced_value.h"
bokan915bf352014-10-02 21:57:1422#include "cc/input/page_scale_animation.h"
[email protected]cc3cfaa2013-03-18 09:05:5223#include "cc/layers/heads_up_display_layer_impl.h"
[email protected]57ac9482013-09-17 21:13:3924#include "cc/layers/layer.h"
[email protected]34ba1ffb2014-03-05 06:55:0325#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2826#include "cc/layers/render_surface_impl.h"
[email protected]80413d72013-08-30 20:25:3327#include "cc/layers/scrollbar_layer_impl_base.h"
[email protected]e1042192013-11-08 05:44:2428#include "cc/resources/ui_resource_request.h"
[email protected]556fd292013-03-18 08:03:0429#include "cc/trees/layer_tree_host_common.h"
30#include "cc/trees/layer_tree_host_impl.h"
[email protected]562b7ad2014-06-23 22:17:1131#include "cc/trees/occlusion_tracker.h"
heejin.r.chungd28506ba2014-10-23 16:36:2032#include "ui/gfx/geometry/point_conversions.h"
33#include "ui/gfx/geometry/size_conversions.h"
34#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]3b31c6ac2012-12-06 21:27:2935
36namespace cc {
37
[email protected]adeda572014-01-31 00:49:4738// This class exists to split the LayerScrollOffsetDelegate between the
39// InnerViewportScrollLayer and the OuterViewportScrollLayer in a manner
40// that never requires the embedder or LayerImpl to know about.
[email protected]ec2322e2014-05-15 16:32:0041class LayerScrollOffsetDelegateProxy : public LayerImpl::ScrollOffsetDelegate {
[email protected]adeda572014-01-31 00:49:4742 public:
43 LayerScrollOffsetDelegateProxy(LayerImpl* layer,
44 LayerScrollOffsetDelegate* delegate,
45 LayerTreeImpl* layer_tree)
46 : layer_(layer), delegate_(delegate), layer_tree_impl_(layer_tree) {}
[email protected]ec2322e2014-05-15 16:32:0047 virtual ~LayerScrollOffsetDelegateProxy() {}
[email protected]adeda572014-01-31 00:49:4748
miletusf57925d2014-10-01 19:38:1349 gfx::ScrollOffset last_set_scroll_offset() const {
[email protected]adeda572014-01-31 00:49:4750 return last_set_scroll_offset_;
51 }
52
53 // LayerScrollOffsetDelegate implementation.
aeliasd0070ba2015-01-31 13:44:4954 void SetCurrentScrollOffset(const gfx::ScrollOffset& new_offset) override {
[email protected]adeda572014-01-31 00:49:4755 last_set_scroll_offset_ = new_offset;
[email protected]adeda572014-01-31 00:49:4756 }
57
aeliasd0070ba2015-01-31 13:44:4958 gfx::ScrollOffset GetCurrentScrollOffset() override {
[email protected]adeda572014-01-31 00:49:4759 return layer_tree_impl_->GetDelegatedScrollOffset(layer_);
60 }
61
dcheng716bedf2014-10-21 09:51:0862 bool IsExternalFlingActive() const override {
[email protected]adeda572014-01-31 00:49:4763 return delegate_->IsExternalFlingActive();
64 }
65
bokan6747f5522014-10-24 19:28:5466 void Update() const override {
67 layer_tree_impl_->UpdateScrollOffsetDelegate();
68 }
69
[email protected]adeda572014-01-31 00:49:4770 private:
71 LayerImpl* layer_;
72 LayerScrollOffsetDelegate* delegate_;
73 LayerTreeImpl* layer_tree_impl_;
miletusf57925d2014-10-01 19:38:1374 gfx::ScrollOffset last_set_scroll_offset_;
[email protected]adeda572014-01-31 00:49:4775};
76
aelias58eec0812014-12-04 01:04:4077LayerTreeImpl::LayerTreeImpl(
78 LayerTreeHostImpl* layer_tree_host_impl,
ccameronb9aec4502014-12-05 19:31:0079 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor,
aelias6004fe02015-02-07 21:43:0180 scoped_refptr<SyncedTopControls> top_controls_shown_ratio,
ccameronb9aec4502014-12-05 19:31:0081 scoped_refptr<SyncedElasticOverscroll> elastic_overscroll)
[email protected]db8259f2013-02-01 05:25:0482 : layer_tree_host_impl_(layer_tree_host_impl),
83 source_frame_number_(-1),
84 hud_layer_(0),
[email protected]1960a712013-04-30 17:06:4785 currently_scrolling_layer_(NULL),
86 root_layer_scroll_offset_delegate_(NULL),
[email protected]db8259f2013-02-01 05:25:0487 background_color_(0),
88 has_transparent_background_(false),
ccameronb9aec4502014-12-05 19:31:0089 overscroll_elasticity_layer_(NULL),
[email protected]57ac9482013-09-17 21:13:3990 page_scale_layer_(NULL),
91 inner_viewport_scroll_layer_(NULL),
92 outer_viewport_scroll_layer_(NULL),
aelias58eec0812014-12-04 01:04:4093 page_scale_factor_(page_scale_factor),
[email protected]db8259f2013-02-01 05:25:0494 min_page_scale_factor_(0),
95 max_page_scale_factor_(0),
ccameronb9aec4502014-12-05 19:31:0096 elastic_overscroll_(elastic_overscroll),
[email protected]db8259f2013-02-01 05:25:0497 scrolling_layer_id_from_previous_tree_(0),
98 contents_textures_purged_(false),
[email protected]318822852013-02-14 00:54:2799 viewport_size_invalid_(false),
[email protected]db8259f2013-02-01 05:25:04100 needs_update_draw_properties_(true),
[email protected]7d08a9352013-10-15 08:24:56101 needs_full_tree_sync_(true),
[email protected]390bb1ff2014-05-09 17:14:40102 next_activation_forces_redraw_(false),
[email protected]759dc9f2014-07-23 19:18:51103 has_ever_been_drawn_(false),
bokan88eae012014-09-09 20:40:42104 render_surface_layer_list_id_(0),
dtrainorcb7779b82014-12-04 01:08:02105 top_controls_shrink_blink_size_(false),
106 top_controls_height_(0),
aelias6004fe02015-02-07 21:43:01107 top_controls_shown_ratio_(top_controls_shown_ratio) {
[email protected]390bb1ff2014-05-09 17:14:40108}
[email protected]3b31c6ac2012-12-06 21:27:29109
110LayerTreeImpl::~LayerTreeImpl() {
[email protected]586871b2014-07-22 17:05:11111 BreakSwapPromises(SwapPromise::SWAP_FAILS);
112
[email protected]361bc00d2012-12-14 07:03:24113 // Need to explicitly clear the tree prior to destroying this so that
114 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
[email protected]df17af52014-02-06 02:20:40115 DCHECK(!root_layer_);
116 DCHECK(layers_with_copy_output_request_.empty());
[email protected]3b31c6ac2012-12-06 21:27:29117}
118
danakjf446a072014-09-27 21:55:48119void LayerTreeImpl::Shutdown() {
120 root_layer_ = nullptr;
121}
[email protected]df17af52014-02-06 02:20:40122
[email protected]aeef2f02014-05-10 12:15:48123void LayerTreeImpl::ReleaseResources() {
124 if (root_layer_)
vmpstr9ce5c662015-02-05 23:29:26125 ProcessLayersRecursive(root_layer_.get(), &LayerImpl::ReleaseResources);
126}
127
128void LayerTreeImpl::RecreateResources() {
129 if (root_layer_)
130 ProcessLayersRecursive(root_layer_.get(), &LayerImpl::RecreateResources);
[email protected]aeef2f02014-05-10 12:15:48131}
132
[email protected]d35cd7b22014-01-29 14:32:46133void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
[email protected]adeda572014-01-31 00:49:47134 if (inner_viewport_scroll_layer_)
135 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
136 if (outer_viewport_scroll_layer_)
137 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48138 inner_viewport_scroll_delegate_proxy_ = nullptr;
139 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]adeda572014-01-31 00:49:47140
[email protected]3b31c6ac2012-12-06 21:27:29141 root_layer_ = layer.Pass();
[email protected]5c4824e12013-01-12 16:34:53142 currently_scrolling_layer_ = NULL;
[email protected]adeda572014-01-31 00:49:47143 inner_viewport_scroll_layer_ = NULL;
144 outer_viewport_scroll_layer_ = NULL;
145 page_scale_layer_ = NULL;
[email protected]5c4824e12013-01-12 16:34:53146
[email protected]c1bb5af2013-03-13 19:06:27147 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]5c4824e12013-01-12 16:34:53148}
149
[email protected]adeda572014-01-31 00:49:47150LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const {
151 return inner_viewport_scroll_layer_;
152}
[email protected]3b31c6ac2012-12-06 21:27:29153
[email protected]adeda572014-01-31 00:49:47154LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const {
155 return outer_viewport_scroll_layer_;
156}
[email protected]1960a712013-04-30 17:06:47157
miletusf57925d2014-10-01 19:38:13158gfx::ScrollOffset LayerTreeImpl::TotalScrollOffset() const {
159 gfx::ScrollOffset offset;
[email protected]3b31c6ac2012-12-06 21:27:29160
[email protected]adeda572014-01-31 00:49:47161 if (inner_viewport_scroll_layer_)
aeliasd0070ba2015-01-31 13:44:49162 offset += inner_viewport_scroll_layer_->CurrentScrollOffset();
[email protected]adeda572014-01-31 00:49:47163
164 if (outer_viewport_scroll_layer_)
aeliasd0070ba2015-01-31 13:44:49165 offset += outer_viewport_scroll_layer_->CurrentScrollOffset();
[email protected]adeda572014-01-31 00:49:47166
167 return offset;
168}
169
miletusf57925d2014-10-01 19:38:13170gfx::ScrollOffset LayerTreeImpl::TotalMaxScrollOffset() const {
171 gfx::ScrollOffset offset;
[email protected]adeda572014-01-31 00:49:47172
173 if (inner_viewport_scroll_layer_)
174 offset += inner_viewport_scroll_layer_->MaxScrollOffset();
175
176 if (outer_viewport_scroll_layer_)
177 offset += outer_viewport_scroll_layer_->MaxScrollOffset();
178
179 return offset;
180}
[email protected]3b31c6ac2012-12-06 21:27:29181
182scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
183 // Clear all data structures that have direct references to the layer tree.
184 scrolling_layer_id_from_previous_tree_ =
185 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]adeda572014-01-31 00:49:47186 if (inner_viewport_scroll_layer_)
187 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
188 if (outer_viewport_scroll_layer_)
189 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48190 inner_viewport_scroll_delegate_proxy_ = nullptr;
191 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]adeda572014-01-31 00:49:47192 inner_viewport_scroll_layer_ = NULL;
193 outer_viewport_scroll_layer_ = NULL;
194 page_scale_layer_ = NULL;
[email protected]3b31c6ac2012-12-06 21:27:29195 currently_scrolling_layer_ = NULL;
196
[email protected]76ffd9e2012-12-20 19:12:47197 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16198 set_needs_update_draw_properties();
[email protected]3b31c6ac2012-12-06 21:27:29199 return root_layer_.Pass();
200}
201
[email protected]7aba6662013-03-12 10:17:34202void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
[email protected]c9280762013-08-01 06:28:57203 // The request queue should have been processed and does not require a push.
204 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
205
[email protected]7d08a9352013-10-15 08:24:56206 if (next_activation_forces_redraw_) {
[email protected]12a63da2014-06-13 06:06:22207 target_tree->ForceRedrawNextActivation();
[email protected]7d08a9352013-10-15 08:24:56208 next_activation_forces_redraw_ = false;
209 }
210
[email protected]b69c1db2013-11-27 00:05:19211 target_tree->PassSwapPromises(&swap_promise_list_);
212
aelias6004fe02015-02-07 21:43:01213 target_tree->set_top_controls_shrink_blink_size(
214 top_controls_shrink_blink_size_);
215 target_tree->set_top_controls_height(top_controls_height_);
216 target_tree->PushTopControls(nullptr);
bokan88eae012014-09-09 20:40:42217
aelias58eec0812014-12-04 01:04:40218 // Active tree already shares the page_scale_factor object with pending
219 // tree so only the limits need to be provided.
220 target_tree->PushPageScaleFactorAndLimits(nullptr, min_page_scale_factor(),
221 max_page_scale_factor());
ccameronb9aec4502014-12-05 19:31:00222 target_tree->elastic_overscroll()->PushPendingToActive();
[email protected]c60279472013-01-30 12:10:51223
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
aelias58eec0812014-12-04 01:04:40315float LayerTreeImpl::ClampPageScaleFactorToLimits(
316 float page_scale_factor) const {
317 if (min_page_scale_factor_ && page_scale_factor < min_page_scale_factor_)
318 page_scale_factor = min_page_scale_factor_;
319 else if (max_page_scale_factor_ && page_scale_factor > max_page_scale_factor_)
320 page_scale_factor = max_page_scale_factor_;
321 return page_scale_factor;
[email protected]d6021f6a2014-06-12 21:15:24322}
[email protected]c60279472013-01-30 12:10:51323
aelias58eec0812014-12-04 01:04:40324void LayerTreeImpl::SetPageScaleOnActiveTree(float active_page_scale) {
325 DCHECK(IsActiveTree());
326 if (page_scale_factor()->SetCurrent(
327 ClampPageScaleFactorToLimits(active_page_scale)))
328 DidUpdatePageScale();
[email protected]d6021f6a2014-06-12 21:15:24329}
330
aelias58eec0812014-12-04 01:04:40331void LayerTreeImpl::PushPageScaleFromMainThread(float page_scale_factor,
332 float min_page_scale_factor,
333 float max_page_scale_factor) {
334 PushPageScaleFactorAndLimits(&page_scale_factor, min_page_scale_factor,
335 max_page_scale_factor);
336}
337
338void LayerTreeImpl::PushPageScaleFactorAndLimits(const float* page_scale_factor,
339 float min_page_scale_factor,
340 float max_page_scale_factor) {
341 DCHECK(page_scale_factor || IsActiveTree());
342 bool changed_page_scale = false;
343 if (page_scale_factor) {
344 DCHECK(!IsActiveTree() || !layer_tree_host_impl_->pending_tree());
345 changed_page_scale |=
346 page_scale_factor_->PushFromMainThread(*page_scale_factor);
347 }
348 if (IsActiveTree())
349 changed_page_scale |= page_scale_factor_->PushPendingToActive();
350 changed_page_scale |=
351 SetPageScaleFactorLimits(min_page_scale_factor, max_page_scale_factor);
352
353 if (changed_page_scale)
354 DidUpdatePageScale();
355}
356
aelias6004fe02015-02-07 21:43:01357void LayerTreeImpl::set_top_controls_shrink_blink_size(bool shrink) {
358 if (top_controls_shrink_blink_size_ == shrink)
359 return;
360
361 top_controls_shrink_blink_size_ = shrink;
362 if (IsActiveTree())
363 layer_tree_host_impl_->UpdateViewportContainerSizes();
364}
365
366void LayerTreeImpl::set_top_controls_height(float top_controls_height) {
367 if (top_controls_height_ == top_controls_height)
368 return;
369
370 top_controls_height_ = top_controls_height;
371 if (IsActiveTree())
372 layer_tree_host_impl_->UpdateViewportContainerSizes();
373}
374
375bool LayerTreeImpl::SetCurrentTopControlsShownRatio(float ratio) {
376 ratio = std::max(ratio, 0.f);
377 ratio = std::min(ratio, 1.f);
378 return top_controls_shown_ratio_->SetCurrent(ratio);
379}
380
381void LayerTreeImpl::PushTopControlsFromMainThread(
382 float top_controls_shown_ratio) {
383 PushTopControls(&top_controls_shown_ratio);
384}
385
386void LayerTreeImpl::PushTopControls(const float* top_controls_shown_ratio) {
387 DCHECK(top_controls_shown_ratio || IsActiveTree());
388
389 if (top_controls_shown_ratio) {
390 DCHECK(!IsActiveTree() || !layer_tree_host_impl_->pending_tree());
391 top_controls_shown_ratio_->PushFromMainThread(*top_controls_shown_ratio);
392 }
393 if (IsActiveTree()) {
394 if (top_controls_shown_ratio_->PushPendingToActive())
395 layer_tree_host_impl_->DidChangeTopControlsPosition();
396 }
397}
398
aelias58eec0812014-12-04 01:04:40399bool LayerTreeImpl::SetPageScaleFactorLimits(float min_page_scale_factor,
400 float max_page_scale_factor) {
401 if (min_page_scale_factor == min_page_scale_factor_ &&
402 max_page_scale_factor == max_page_scale_factor_)
403 return false;
[email protected]7265e74e2014-02-07 23:43:06404
[email protected]c60279472013-01-30 12:10:51405 min_page_scale_factor_ = min_page_scale_factor;
406 max_page_scale_factor_ = max_page_scale_factor;
[email protected]20d2b742013-09-26 05:41:34407
aelias58eec0812014-12-04 01:04:40408 return true;
409}
[email protected]d6021f6a2014-06-12 21:15:24410
aelias58eec0812014-12-04 01:04:40411void LayerTreeImpl::DidUpdatePageScale() {
412 if (IsActiveTree())
413 page_scale_factor()->SetCurrent(
414 ClampPageScaleFactorToLimits(current_page_scale_factor()));
[email protected]d6021f6a2014-06-12 21:15:24415
aelias58eec0812014-12-04 01:04:40416 set_needs_update_draw_properties();
[email protected]d6021f6a2014-06-12 21:15:24417
[email protected]22f200a2013-10-09 18:08:29418 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00419 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
aelias58eec0812014-12-04 01:04:40420 TotalScrollOffset(), TotalMaxScrollOffset(), ScrollableSize(),
421 current_page_scale_factor(), min_page_scale_factor_,
[email protected]d6021f6a2014-06-12 21:15:24422 max_page_scale_factor_);
[email protected]22f200a2013-10-09 18:08:29423 }
[email protected]adeda572014-01-31 00:49:47424
425 ForceScrollbarParameterUpdateAfterScaleChange(page_scale_layer());
bokanc784a6f2015-01-28 04:11:50426
427 HideInnerViewportScrollbarsIfNearMinimumScale();
428}
429
430void LayerTreeImpl::HideInnerViewportScrollbarsIfNearMinimumScale() {
431 if (!InnerViewportContainerLayer())
432 return;
433
434 LayerImpl::ScrollbarSet* scrollbars =
435 InnerViewportContainerLayer()->scrollbars();
436
437 if (!scrollbars)
438 return;
439
440 for (LayerImpl::ScrollbarSet::iterator it = scrollbars->begin();
441 it != scrollbars->end();
442 ++it) {
443 ScrollbarLayerImplBase* scrollbar = *it;
444 float minimum_scale_to_show_at =
445 min_page_scale_factor() * settings().scrollbar_show_scale_threshold;
446 scrollbar->SetHideLayerAndSubtree(
447 current_page_scale_factor() < minimum_scale_to_show_at);
448 }
[email protected]c60279472013-01-30 12:10:51449}
450
aelias58eec0812014-12-04 01:04:40451SyncedProperty<ScaleGroup>* LayerTreeImpl::page_scale_factor() {
452 return page_scale_factor_.get();
453}
454
455const SyncedProperty<ScaleGroup>* LayerTreeImpl::page_scale_factor() const {
456 return page_scale_factor_.get();
457}
458
[email protected]257abfa82013-01-29 23:47:24459gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]587941d2014-08-22 01:40:01460 if (!InnerViewportContainerLayer())
461 return gfx::SizeF();
462
bokanef971462014-10-13 22:58:32463 return gfx::ScaleSize(InnerViewportContainerLayer()->BoundsForScrolling(),
aelias58eec0812014-12-04 01:04:40464 1.0f / current_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24465}
466
[email protected]3744e27b2013-11-06 21:44:08467gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const {
[email protected]adeda572014-01-31 00:49:47468 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
469 ? OuterViewportScrollLayer()
470 : InnerViewportScrollLayer();
471 if (!root_scroll_layer || root_scroll_layer->children().empty())
[email protected]3744e27b2013-11-06 21:44:08472 return gfx::Rect();
[email protected]adeda572014-01-31 00:49:47473 LayerImpl* layer = root_scroll_layer->children()[0];
[email protected]8a822692014-02-12 17:30:55474 return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(),
475 gfx::Rect(layer->content_bounds()));
[email protected]3744e27b2013-11-06 21:44:08476}
477
[email protected]58241dc2013-08-20 01:39:25478static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) {
479 layer->ApplySentScrollDeltasFromAbortedCommit();
[email protected]3519b872013-07-30 07:17:50480}
481
[email protected]58241dc2013-08-20 01:39:25482void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50483 DCHECK(IsActiveTree());
484
aelias58eec0812014-12-04 01:04:40485 page_scale_factor()->AbortCommit();
aelias6004fe02015-02-07 21:43:01486 top_controls_shown_ratio()->AbortCommit();
ccameronb9aec4502014-12-05 19:31:00487 elastic_overscroll()->AbortCommit();
[email protected]3519b872013-07-30 07:17:50488
489 if (!root_layer())
490 return;
491
492 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]58241dc2013-08-20 01:39:25493 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo));
494}
495
[email protected]57ac9482013-09-17 21:13:39496void LayerTreeImpl::SetViewportLayersFromIds(
ccameron8230b68b2014-11-21 19:25:18497 int overscroll_elasticity_layer_id,
[email protected]57ac9482013-09-17 21:13:39498 int page_scale_layer_id,
499 int inner_viewport_scroll_layer_id,
500 int outer_viewport_scroll_layer_id) {
ccameron8230b68b2014-11-21 19:25:18501 overscroll_elasticity_layer_ = LayerById(overscroll_elasticity_layer_id);
[email protected]57ac9482013-09-17 21:13:39502 page_scale_layer_ = LayerById(page_scale_layer_id);
503 DCHECK(page_scale_layer_);
504
505 inner_viewport_scroll_layer_ =
506 LayerById(inner_viewport_scroll_layer_id);
507 DCHECK(inner_viewport_scroll_layer_);
508
509 outer_viewport_scroll_layer_ =
510 LayerById(outer_viewport_scroll_layer_id);
511 DCHECK(outer_viewport_scroll_layer_ ||
512 outer_viewport_scroll_layer_id == Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47513
bokanc784a6f2015-01-28 04:11:50514 HideInnerViewportScrollbarsIfNearMinimumScale();
515
[email protected]adeda572014-01-31 00:49:47516 if (!root_layer_scroll_offset_delegate_)
517 return;
518
519 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
520 new LayerScrollOffsetDelegateProxy(inner_viewport_scroll_layer_,
521 root_layer_scroll_offset_delegate_,
522 this));
523
524 if (outer_viewport_scroll_layer_)
525 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
526 new LayerScrollOffsetDelegateProxy(outer_viewport_scroll_layer_,
527 root_layer_scroll_offset_delegate_,
528 this));
[email protected]57ac9482013-09-17 21:13:39529}
530
531void LayerTreeImpl::ClearViewportLayers() {
532 page_scale_layer_ = NULL;
533 inner_viewport_scroll_layer_ = NULL;
534 outer_viewport_scroll_layer_ = NULL;
535}
536
[email protected]8f7f298822014-06-13 00:23:32537bool LayerTreeImpl::UpdateDrawProperties() {
538 if (!needs_update_draw_properties_)
539 return true;
[email protected]615c78a2013-01-24 23:44:16540
[email protected]ed511b8d2013-03-25 03:29:29541 // For max_texture_size.
[email protected]615c78a2013-01-24 23:44:16542 if (!layer_tree_host_impl_->renderer())
[email protected]8f7f298822014-06-13 00:23:32543 return false;
[email protected]615c78a2013-01-24 23:44:16544
[email protected]c1bb5af2013-03-13 19:06:27545 if (!root_layer())
[email protected]8f7f298822014-06-13 00:23:32546 return false;
547
548 needs_update_draw_properties_ = false;
549 render_surface_layer_list_.clear();
[email protected]76ffd9e2012-12-20 19:12:47550
[email protected]76ffd9e2012-12-20 19:12:47551 {
[email protected]7a52f43e2013-07-10 01:58:47552 TRACE_EVENT2("cc",
[email protected]c1bb5af2013-03-13 19:06:27553 "LayerTreeImpl::UpdateDrawProperties",
554 "IsActive",
[email protected]7a52f43e2013-07-10 01:58:47555 IsActiveTree(),
556 "SourceFrameNumber",
557 source_frame_number_);
[email protected]57ac9482013-09-17 21:13:39558 LayerImpl* page_scale_layer =
[email protected]fef74fd2014-02-27 06:28:17559 page_scale_layer_ ? page_scale_layer_ : InnerViewportContainerLayer();
hush367d7dd2014-08-29 23:56:01560 bool can_render_to_separate_surface =
561 (layer_tree_host_impl_->GetDrawMode() !=
562 DRAW_MODE_RESOURCELESS_SOFTWARE);
[email protected]390bb1ff2014-05-09 17:14:40563
564 ++render_surface_layer_list_id_;
[email protected]7aad55f2013-07-26 11:25:53565 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
danakj3f76ace2014-11-18 16:56:00566 root_layer(), DrawViewportSize(),
567 layer_tree_host_impl_->DrawTransform(), device_scale_factor(),
aelias58eec0812014-12-04 01:04:40568 current_page_scale_factor(), page_scale_layer,
ccameronb9aec4502014-12-05 19:31:00569 elastic_overscroll()->Current(IsActiveTree()),
570 overscroll_elasticity_layer_, resource_provider()->max_texture_size(),
571 settings().can_use_lcd_text, settings().layers_always_allowed_lcd_text,
[email protected]45948712013-09-27 02:46:48572 can_render_to_separate_surface,
[email protected]35a99a12013-05-09 23:52:29573 settings().layer_transforms_should_scale_layer_contents,
vollick51ed1a22014-12-17 02:03:00574 settings().verify_property_trees,
danakj3f76ace2014-11-18 16:56:00575 &render_surface_layer_list_, render_surface_layer_list_id_);
[email protected]7aad55f2013-07-26 11:25:53576 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]76ffd9e2012-12-20 19:12:47577 }
[email protected]615c78a2013-01-24 23:44:16578
[email protected]e4be0262013-10-19 16:54:28579 {
vmpstrd6166202014-11-05 18:45:40580 TRACE_EVENT_BEGIN2("cc", "LayerTreeImpl::UpdateTilePriorities", "IsActive",
581 IsActiveTree(), "SourceFrameNumber",
582 source_frame_number_);
danakj6496cba2014-10-16 01:31:08583 scoped_ptr<OcclusionTracker<LayerImpl>> occlusion_tracker;
[email protected]562b7ad2014-06-23 22:17:11584 if (settings().use_occlusion_for_tile_prioritization) {
585 occlusion_tracker.reset(new OcclusionTracker<LayerImpl>(
586 root_layer()->render_surface()->content_rect()));
587 occlusion_tracker->set_minimum_tracking_size(
588 settings().minimum_occlusion_tracking_size);
589 }
590
boliu7473f7f52014-10-01 16:54:56591 bool resourceless_software_draw = (layer_tree_host_impl_->GetDrawMode() ==
592 DRAW_MODE_RESOURCELESS_SOFTWARE);
593
[email protected]e4be0262013-10-19 16:54:28594 // LayerIterator is used here instead of CallFunctionForSubtree to only
595 // UpdateTilePriorities on layers that will be visible (and thus have valid
596 // draw properties) and not because any ordering is required.
[email protected]ba1b33e2014-02-28 16:44:51597 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]e4be0262013-10-19 16:54:28598 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
vmpstrd6166202014-11-05 18:45:40599 size_t layers_updated_count = 0;
vmpstr5377520a2014-12-29 23:26:13600 bool tile_priorities_updated = false;
[email protected]e4be0262013-10-19 16:54:28601 for (LayerIteratorType it =
602 LayerIteratorType::Begin(&render_surface_layer_list_);
603 it != end;
604 ++it) {
[email protected]562b7ad2014-06-23 22:17:11605 if (occlusion_tracker)
606 occlusion_tracker->EnterLayer(it);
607
[email protected]e4be0262013-10-19 16:54:28608 LayerImpl* layer = *it;
vmpstrcdcb5f72014-09-11 00:58:37609 const Occlusion& occlusion_in_content_space =
610 occlusion_tracker ? occlusion_tracker->GetCurrentOcclusionForLayer(
611 layer->draw_transform())
612 : Occlusion();
613
boliu7473f7f52014-10-01 16:54:56614 if (it.represents_itself()) {
vmpstr5377520a2014-12-29 23:26:13615 tile_priorities_updated |= layer->UpdateTiles(
616 occlusion_in_content_space, resourceless_software_draw);
vmpstrd6166202014-11-05 18:45:40617 ++layers_updated_count;
boliu7473f7f52014-10-01 16:54:56618 }
[email protected]e4be0262013-10-19 16:54:28619
[email protected]562b7ad2014-06-23 22:17:11620 if (!it.represents_contributing_render_surface()) {
621 if (occlusion_tracker)
622 occlusion_tracker->LeaveLayer(it);
[email protected]6355d2d2014-05-07 15:07:27623 continue;
[email protected]562b7ad2014-06-23 22:17:11624 }
[email protected]6355d2d2014-05-07 15:07:27625
boliu7473f7f52014-10-01 16:54:56626 if (layer->mask_layer()) {
vmpstr5377520a2014-12-29 23:26:13627 tile_priorities_updated |= layer->mask_layer()->UpdateTiles(
628 occlusion_in_content_space, resourceless_software_draw);
vmpstrd6166202014-11-05 18:45:40629 ++layers_updated_count;
boliu7473f7f52014-10-01 16:54:56630 }
631 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) {
vmpstr5377520a2014-12-29 23:26:13632 tile_priorities_updated |=
633 layer->replica_layer()->mask_layer()->UpdateTiles(
634 occlusion_in_content_space, resourceless_software_draw);
vmpstrd6166202014-11-05 18:45:40635 ++layers_updated_count;
boliu7473f7f52014-10-01 16:54:56636 }
[email protected]562b7ad2014-06-23 22:17:11637
638 if (occlusion_tracker)
639 occlusion_tracker->LeaveLayer(it);
[email protected]e4be0262013-10-19 16:54:28640 }
vmpstrd6166202014-11-05 18:45:40641
vmpstr5377520a2014-12-29 23:26:13642 if (tile_priorities_updated)
643 DidModifyTilePriorities();
644
vmpstrd6166202014-11-05 18:45:40645 TRACE_EVENT_END1("cc", "LayerTreeImpl::UpdateTilePriorities",
646 "layers_updated_count", layers_updated_count);
[email protected]e4be0262013-10-19 16:54:28647 }
648
[email protected]615c78a2013-01-24 23:44:16649 DCHECK(!needs_update_draw_properties_) <<
[email protected]7d19dc342013-05-02 22:02:04650 "CalcDrawProperties should not set_needs_update_draw_properties()";
[email protected]8f7f298822014-06-13 00:23:32651 return true;
[email protected]76ffd9e2012-12-20 19:12:47652}
653
[email protected]50761e92013-03-29 20:51:28654const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const {
[email protected]76ffd9e2012-12-20 19:12:47655 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16656 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47657 return render_surface_layer_list_;
658}
659
bokancccfde72014-10-08 15:15:22660gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]adeda572014-01-31 00:49:47661 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
662 ? OuterViewportScrollLayer()
663 : InnerViewportScrollLayer();
664 if (!root_scroll_layer || root_scroll_layer->children().empty())
bokancccfde72014-10-08 15:15:22665 return gfx::Size();
[email protected]adeda572014-01-31 00:49:47666 return root_scroll_layer->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16667}
668
[email protected]361bc00d2012-12-14 07:03:24669LayerImpl* LayerTreeImpl::LayerById(int id) {
670 LayerIdMap::iterator iter = layer_id_map_.find(id);
671 return iter != layer_id_map_.end() ? iter->second : NULL;
672}
673
674void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
675 DCHECK(!LayerById(layer->id()));
676 layer_id_map_[layer->id()] = layer;
677}
678
679void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
680 DCHECK(LayerById(layer->id()));
681 layer_id_map_.erase(layer->id());
682}
683
[email protected]aebf4622014-07-14 16:57:59684size_t LayerTreeImpl::NumLayers() {
685 return layer_id_map_.size();
686}
687
[email protected]ed511b8d2013-03-25 03:29:29688void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) {
[email protected]a90fac72013-06-06 18:56:13689 pending_tree->SetCurrentlyScrollingLayer(
690 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(),
691 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0));
[email protected]1e0f8d62013-01-09 07:41:35692}
693
[email protected]ff1211d2013-06-07 01:58:35694static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34695 layer->DidBecomeActive();
[email protected]db2e29c2014-08-06 05:58:25696 if (layer->mask_layer())
697 layer->mask_layer()->DidBecomeActive();
698 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
699 layer->replica_layer()->mask_layer()->DidBecomeActive();
700
[email protected]ff1211d2013-06-07 01:58:35701 for (size_t i = 0; i < layer->children().size(); ++i)
702 DidBecomeActiveRecursive(layer->children()[i]);
[email protected]37386f052013-01-13 00:42:22703}
704
705void LayerTreeImpl::DidBecomeActive() {
[email protected]12a63da2014-06-13 06:06:22706 if (next_activation_forces_redraw_) {
707 layer_tree_host_impl_->SetFullRootLayerDamage();
708 next_activation_forces_redraw_ = false;
709 }
710
[email protected]adeda572014-01-31 00:49:47711 if (scrolling_layer_id_from_previous_tree_) {
712 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
[email protected]7dcf5632014-06-25 01:11:55713 root_layer(), scrolling_layer_id_from_previous_tree_);
[email protected]adeda572014-01-31 00:49:47714 }
715
[email protected]7dcf5632014-06-25 01:11:55716 // Always reset this flag on activation, as we would only have activated
717 // if we were in a good state.
vmpstr61ed94a12014-10-09 04:49:30718 layer_tree_host_impl_->ResetRequiresHighResToDraw();
[email protected]7dcf5632014-06-25 01:11:55719
720 if (root_layer())
721 DidBecomeActiveRecursive(root_layer());
722
[email protected]12a63da2014-06-13 06:06:22723 devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(),
724 source_frame_number_);
[email protected]37386f052013-01-13 00:42:22725}
726
[email protected]6f90b9e2013-01-17 23:42:00727bool LayerTreeImpl::ContentsTexturesPurged() const {
728 return contents_textures_purged_;
729}
730
731void LayerTreeImpl::SetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04732 if (contents_textures_purged_)
733 return;
[email protected]6f90b9e2013-01-17 23:42:00734 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27735 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00736}
737
738void LayerTreeImpl::ResetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04739 if (!contents_textures_purged_)
740 return;
[email protected]6f90b9e2013-01-17 23:42:00741 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27742 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00743}
744
[email protected]3d609bb2014-02-01 01:10:23745bool LayerTreeImpl::RequiresHighResToDraw() const {
vmpstr61ed94a12014-10-09 04:49:30746 return layer_tree_host_impl_->RequiresHighResToDraw();
[email protected]3d609bb2014-02-01 01:10:23747}
748
[email protected]318822852013-02-14 00:54:27749bool LayerTreeImpl::ViewportSizeInvalid() const {
750 return viewport_size_invalid_;
751}
752
753void LayerTreeImpl::SetViewportSizeInvalid() {
754 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27755 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27756}
757
758void LayerTreeImpl::ResetViewportSizeInvalid() {
759 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27760 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27761}
762
[email protected]48871fc2013-01-23 07:36:51763Proxy* LayerTreeImpl::proxy() const {
764 return layer_tree_host_impl_->proxy();
765}
766
[email protected]ff762fb2012-12-12 19:18:37767const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27768 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37769}
770
[email protected]7a8bcd262014-01-15 12:54:58771const RendererCapabilitiesImpl& LayerTreeImpl::GetRendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27772 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52773}
774
[email protected]0634cdd42013-08-16 00:46:09775ContextProvider* LayerTreeImpl::context_provider() const {
dcheng6afa17002014-08-26 19:11:31776 return output_surface()->context_provider();
[email protected]0634cdd42013-08-16 00:46:09777}
778
[email protected]ff762fb2012-12-12 19:18:37779OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27780 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37781}
782
783ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27784 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37785}
786
787TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27788 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37789}
790
791FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27792 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37793}
794
[email protected]71691c22013-01-18 03:14:22795PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27796 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22797}
798
[email protected]1191d9d2013-02-02 06:00:33799MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27800 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33801}
802
[email protected]4a6c091d2014-04-24 21:06:46803gfx::Size LayerTreeImpl::device_viewport_size() const {
804 return layer_tree_host_impl_->device_viewport_size();
805}
806
[email protected]f117a4c2012-12-16 04:53:10807bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27808 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10809}
810
811bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27812 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10813}
814
[email protected]48871fc2013-01-23 07:36:51815bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27816 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51817}
818
[email protected]f117a4c2012-12-16 04:53:10819LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27820 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10821 if (!tree)
822 return NULL;
823 return tree->LayerById(id);
824}
825
826LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27827 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10828 if (!tree)
829 return NULL;
830 return tree->LayerById(id);
831}
832
[email protected]166db5c82013-01-09 23:54:31833bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27834 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31835}
836
[email protected]04c5900d2014-08-18 13:38:36837BeginFrameArgs LayerTreeImpl::CurrentBeginFrameArgs() const {
838 return layer_tree_host_impl_->CurrentBeginFrameArgs();
[email protected]fb7425a2013-04-22 16:28:55839}
840
[email protected]c92195e2014-05-07 18:18:49841base::TimeDelta LayerTreeImpl::begin_impl_frame_interval() const {
842 return layer_tree_host_impl_->begin_impl_frame_interval();
843}
844
[email protected]d7eb8c72013-03-23 22:57:13845void LayerTreeImpl::SetNeedsCommit() {
846 layer_tree_host_impl_->SetNeedsCommit();
847}
848
[email protected]bd5324592014-07-31 09:09:33849gfx::Rect LayerTreeImpl::DeviceViewport() const {
850 return layer_tree_host_impl_->DeviceViewport();
851}
852
[email protected]54af03522013-09-05 00:43:28853gfx::Size LayerTreeImpl::DrawViewportSize() const {
854 return layer_tree_host_impl_->DrawViewportSize();
855}
856
[email protected]bd5324592014-07-31 09:09:33857const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const {
858 return layer_tree_host_impl_->ViewportRectForTilePriority();
859}
860
[email protected]930ff43b2014-05-02 05:24:00861scoped_ptr<ScrollbarAnimationController>
862LayerTreeImpl::CreateScrollbarAnimationController(LayerImpl* scrolling_layer) {
863 DCHECK(settings().scrollbar_fade_delay_ms);
864 DCHECK(settings().scrollbar_fade_duration_ms);
865 base::TimeDelta delay =
866 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms);
sataya.m07f11a82014-10-07 14:29:18867 base::TimeDelta resize_delay = base::TimeDelta::FromMilliseconds(
868 settings().scrollbar_fade_resize_delay_ms);
[email protected]930ff43b2014-05-02 05:24:00869 base::TimeDelta duration =
870 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms);
871 switch (settings().scrollbar_animator) {
872 case LayerTreeSettings::LinearFade: {
873 return ScrollbarAnimationControllerLinearFade::Create(
sataya.m07f11a82014-10-07 14:29:18874 scrolling_layer,
875 layer_tree_host_impl_,
876 delay,
877 resize_delay,
878 duration);
[email protected]930ff43b2014-05-02 05:24:00879 }
880 case LayerTreeSettings::Thinning: {
sataya.m07f11a82014-10-07 14:29:18881 return ScrollbarAnimationControllerThinning::Create(scrolling_layer,
882 layer_tree_host_impl_,
883 delay,
884 resize_delay,
885 duration);
[email protected]930ff43b2014-05-02 05:24:00886 }
887 case LayerTreeSettings::NoAnimator:
888 NOTREACHED();
889 break;
890 }
danakjf446a072014-09-27 21:55:48891 return nullptr;
[email protected]2ea5aba2013-09-11 14:26:56892}
893
[email protected]b8384e22013-12-03 02:20:48894void LayerTreeImpl::DidAnimateScrollOffset() {
895 layer_tree_host_impl_->DidAnimateScrollOffset();
896}
897
[email protected]13525d62014-05-20 21:22:04898bool LayerTreeImpl::use_gpu_rasterization() const {
899 return layer_tree_host_impl_->use_gpu_rasterization();
900}
901
hendrikwc2bbd612014-12-03 23:49:34902GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const {
903 return layer_tree_host_impl_->gpu_rasterization_status();
904}
905
[email protected]473f1f22014-05-22 08:19:17906bool LayerTreeImpl::create_low_res_tiling() const {
907 return layer_tree_host_impl_->create_low_res_tiling();
908}
909
[email protected]ff762fb2012-12-12 19:18:37910void LayerTreeImpl::SetNeedsRedraw() {
[email protected]59adb112013-04-09 04:48:44911 layer_tree_host_impl_->SetNeedsRedraw();
[email protected]ff762fb2012-12-12 19:18:37912}
913
[email protected]ff762fb2012-12-12 19:18:37914const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27915 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37916}
917
918float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27919 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37920}
921
[email protected]ff762fb2012-12-12 19:18:37922DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27923 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37924}
925
[email protected]de4afb5e2012-12-20 00:11:34926AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27927 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34928}
[email protected]ff762fb2012-12-12 19:18:37929
vmpstrd7de03c2014-08-27 18:11:01930void LayerTreeImpl::GetAllTilesForTracing(std::set<const Tile*>* tiles) const {
931 typedef LayerIterator<LayerImpl> LayerIteratorType;
932 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
933 for (LayerIteratorType it =
934 LayerIteratorType::Begin(&render_surface_layer_list_);
935 it != end;
936 ++it) {
937 if (!it.represents_itself())
938 continue;
939 LayerImpl* layer_impl = *it;
940 layer_impl->GetAllTilesForTracing(tiles);
941 }
942}
943
ssid911e40e2015-02-09 17:55:20944void LayerTreeImpl::AsValueInto(base::trace_event::TracedValue* state) const {
[email protected]d12aa932014-08-01 13:10:38945 TracedValue::MakeDictIntoImplicitSnapshot(state, "cc::LayerTreeImpl", this);
nduca929378a02014-08-23 19:48:52946 state->SetInteger("source_frame_number", source_frame_number_);
[email protected]f6742f52013-05-08 23:52:22947
[email protected]d12aa932014-08-01 13:10:38948 state->BeginDictionary("root_layer");
949 root_layer_->AsValueInto(state);
950 state->EndDictionary();
[email protected]f6742f52013-05-08 23:52:22951
[email protected]d12aa932014-08-01 13:10:38952 state->BeginArray("render_surface_layer_list");
[email protected]ba1b33e2014-02-28 16:44:51953 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09954 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
955 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]8c5690222013-02-15 17:36:43956 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09957 if (!it.represents_itself())
[email protected]8c5690222013-02-15 17:36:43958 continue;
[email protected]d12aa932014-08-01 13:10:38959 TracedValue::AppendIDRef(*it, state);
[email protected]8c5690222013-02-15 17:36:43960 }
[email protected]d12aa932014-08-01 13:10:38961 state->EndArray();
skyostil43c330f72014-09-22 16:49:11962
963 state->BeginArray("swap_promise_trace_ids");
964 for (size_t i = 0; i < swap_promise_list_.size(); i++)
965 state->AppendDouble(swap_promise_list_[i]->TraceId());
966 state->EndArray();
[email protected]8c5690222013-02-15 17:36:43967}
968
[email protected]1960a712013-04-30 17:06:47969void LayerTreeImpl::SetRootLayerScrollOffsetDelegate(
[email protected]c9280762013-08-01 06:28:57970 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
[email protected]20d2b742013-09-26 05:41:34971 if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate)
972 return;
973
[email protected]adeda572014-01-31 00:49:47974 if (!root_layer_scroll_offset_delegate) {
975 // Make sure we remove the proxies from their layers before
976 // releasing them.
977 if (InnerViewportScrollLayer())
978 InnerViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
979 if (OuterViewportScrollLayer())
980 OuterViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48981 inner_viewport_scroll_delegate_proxy_ = nullptr;
982 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]d35cd7b22014-01-29 14:32:46983 }
984
[email protected]adeda572014-01-31 00:49:47985 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
986
[email protected]20d2b742013-09-26 05:41:34987 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00988 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
aelias58eec0812014-12-04 01:04:40989 TotalScrollOffset(), TotalMaxScrollOffset(), ScrollableSize(),
990 current_page_scale_factor(), min_page_scale_factor(),
[email protected]68fe60f2014-02-12 13:49:11991 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47992
993 if (inner_viewport_scroll_layer_) {
994 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
995 new LayerScrollOffsetDelegateProxy(InnerViewportScrollLayer(),
996 root_layer_scroll_offset_delegate_,
997 this));
998 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(
999 inner_viewport_scroll_delegate_proxy_.get());
1000 }
1001
1002 if (outer_viewport_scroll_layer_) {
1003 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
1004 new LayerScrollOffsetDelegateProxy(OuterViewportScrollLayer(),
1005 root_layer_scroll_offset_delegate_,
1006 this));
1007 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(
1008 outer_viewport_scroll_delegate_proxy_.get());
1009 }
bokan6747f5522014-10-24 19:28:541010
1011 if (inner_viewport_scroll_layer_)
aeliasd0070ba2015-01-31 13:44:491012 inner_viewport_scroll_layer_->RefreshFromScrollDelegate();
1013 if (outer_viewport_scroll_layer_)
1014 outer_viewport_scroll_layer_->RefreshFromScrollDelegate();
1015
1016 if (inner_viewport_scroll_layer_)
bokan6747f5522014-10-24 19:28:541017 UpdateScrollOffsetDelegate();
[email protected]20d2b742013-09-26 05:41:341018 }
[email protected]1960a712013-04-30 17:06:471019}
1020
boliu7d5dbab2014-10-10 20:05:471021void LayerTreeImpl::OnRootLayerDelegatedScrollOffsetChanged() {
1022 DCHECK(root_layer_scroll_offset_delegate_);
1023 if (inner_viewport_scroll_layer_) {
aeliasd0070ba2015-01-31 13:44:491024 inner_viewport_scroll_layer_->RefreshFromScrollDelegate();
boliu7d5dbab2014-10-10 20:05:471025 }
1026 if (outer_viewport_scroll_layer_) {
aeliasd0070ba2015-01-31 13:44:491027 outer_viewport_scroll_layer_->RefreshFromScrollDelegate();
boliu7d5dbab2014-10-10 20:05:471028 }
1029}
1030
[email protected]adeda572014-01-31 00:49:471031void LayerTreeImpl::UpdateScrollOffsetDelegate() {
1032 DCHECK(InnerViewportScrollLayer());
bokan6747f5522014-10-24 19:28:541033 DCHECK(!OuterViewportScrollLayer() || outer_viewport_scroll_delegate_proxy_);
[email protected]adeda572014-01-31 00:49:471034 DCHECK(root_layer_scroll_offset_delegate_);
1035
miletusf57925d2014-10-01 19:38:131036 gfx::ScrollOffset offset =
[email protected]adeda572014-01-31 00:49:471037 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
1038
1039 if (OuterViewportScrollLayer())
1040 offset += outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
1041
[email protected]ec2322e2014-05-15 16:32:001042 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
aelias58eec0812014-12-04 01:04:401043 offset, TotalMaxScrollOffset(), ScrollableSize(),
1044 current_page_scale_factor(), min_page_scale_factor(),
[email protected]ec2322e2014-05-15 16:32:001045 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:471046}
1047
miletusf57925d2014-10-01 19:38:131048gfx::ScrollOffset LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) {
[email protected]adeda572014-01-31 00:49:471049 DCHECK(root_layer_scroll_offset_delegate_);
1050 DCHECK(InnerViewportScrollLayer());
1051 if (layer == InnerViewportScrollLayer() && !OuterViewportScrollLayer())
1052 return root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
1053
1054 // If we get here, we have both inner/outer viewports, and need to distribute
1055 // the scroll offset between them.
1056 DCHECK(inner_viewport_scroll_delegate_proxy_);
1057 DCHECK(outer_viewport_scroll_delegate_proxy_);
miletusf57925d2014-10-01 19:38:131058 gfx::ScrollOffset inner_viewport_offset =
[email protected]adeda572014-01-31 00:49:471059 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
miletusf57925d2014-10-01 19:38:131060 gfx::ScrollOffset outer_viewport_offset =
[email protected]adeda572014-01-31 00:49:471061 outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
1062
1063 // It may be nothing has changed.
miletusf57925d2014-10-01 19:38:131064 gfx::ScrollOffset delegate_offset =
[email protected]adeda572014-01-31 00:49:471065 root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
1066 if (inner_viewport_offset + outer_viewport_offset == delegate_offset) {
1067 if (layer == InnerViewportScrollLayer())
1068 return inner_viewport_offset;
1069 else
1070 return outer_viewport_offset;
1071 }
1072
miletusf57925d2014-10-01 19:38:131073 gfx::ScrollOffset max_outer_viewport_scroll_offset =
[email protected]adeda572014-01-31 00:49:471074 OuterViewportScrollLayer()->MaxScrollOffset();
1075
1076 outer_viewport_offset = delegate_offset - inner_viewport_offset;
1077 outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset);
miletusf57925d2014-10-01 19:38:131078 outer_viewport_offset.SetToMax(gfx::ScrollOffset());
[email protected]adeda572014-01-31 00:49:471079
1080 if (layer == OuterViewportScrollLayer())
1081 return outer_viewport_offset;
1082
1083 inner_viewport_offset = delegate_offset - outer_viewport_offset;
1084
1085 return inner_viewport_offset;
1086}
1087
[email protected]b69c1db2013-11-27 00:05:191088void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) {
1089 DCHECK(swap_promise);
[email protected]b69c1db2013-11-27 00:05:191090 swap_promise_list_.push_back(swap_promise.Pass());
1091}
1092
1093void LayerTreeImpl::PassSwapPromises(
1094 ScopedPtrVector<SwapPromise>* new_swap_promise) {
1095 swap_promise_list_.insert_and_take(swap_promise_list_.end(),
weiliangcc1878c62014-09-02 22:43:171096 new_swap_promise);
[email protected]b69c1db2013-11-27 00:05:191097 new_swap_promise->clear();
1098}
1099
[email protected]d359203a2013-11-29 06:16:551100void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) {
[email protected]b69c1db2013-11-27 00:05:191101 for (size_t i = 0; i < swap_promise_list_.size(); i++)
[email protected]d359203a2013-11-29 06:16:551102 swap_promise_list_[i]->DidSwap(metadata);
[email protected]b69c1db2013-11-27 00:05:191103 swap_promise_list_.clear();
1104}
1105
1106void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) {
1107 for (size_t i = 0; i < swap_promise_list_.size(); i++)
1108 swap_promise_list_[i]->DidNotSwap(reason);
1109 swap_promise_list_.clear();
1110}
1111
[email protected]c48536a52013-09-14 00:02:081112void LayerTreeImpl::DidModifyTilePriorities() {
1113 layer_tree_host_impl_->DidModifyTilePriorities();
[email protected]fcb846d2013-05-22 01:42:361114}
1115
[email protected]c9280762013-08-01 06:28:571116void LayerTreeImpl::set_ui_resource_request_queue(
1117 const UIResourceRequestQueue& queue) {
1118 ui_resource_request_queue_ = queue;
1119}
1120
1121ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource(
1122 UIResourceId uid) const {
1123 return layer_tree_host_impl_->ResourceIdForUIResource(uid);
1124}
1125
[email protected]709c9542013-10-26 01:43:511126bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const {
1127 return layer_tree_host_impl_->IsUIResourceOpaque(uid);
1128}
1129
[email protected]c9280762013-08-01 06:28:571130void LayerTreeImpl::ProcessUIResourceRequestQueue() {
jdduke5ad36812015-01-02 17:59:321131 for (const auto& req : ui_resource_request_queue_) {
[email protected]741fba422013-09-20 03:34:141132 switch (req.GetType()) {
[email protected]c9280762013-08-01 06:28:571133 case UIResourceRequest::UIResourceCreate:
[email protected]741fba422013-09-20 03:34:141134 layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap());
[email protected]c9280762013-08-01 06:28:571135 break;
1136 case UIResourceRequest::UIResourceDelete:
[email protected]741fba422013-09-20 03:34:141137 layer_tree_host_impl_->DeleteUIResource(req.GetId());
[email protected]c9280762013-08-01 06:28:571138 break;
[email protected]f28d64d2013-08-27 04:17:451139 case UIResourceRequest::UIResourceInvalidRequest:
[email protected]c9280762013-08-01 06:28:571140 NOTREACHED();
1141 break;
1142 }
1143 }
jdduke5ad36812015-01-02 17:59:321144 ui_resource_request_queue_.clear();
[email protected]127bdc1a2013-09-11 01:44:481145
1146 // If all UI resource evictions were not recreated by processing this queue,
1147 // then another commit is required.
1148 if (layer_tree_host_impl_->EvictedUIResourcesExist())
1149 layer_tree_host_impl_->SetNeedsCommit();
[email protected]c9280762013-08-01 06:28:571150}
1151
[email protected]30fe19ff2013-07-04 00:54:451152void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) {
1153 // Only the active tree needs to know about layers with copy requests, as
1154 // they are aborted if not serviced during draw.
1155 DCHECK(IsActiveTree());
1156
[email protected]a4ee12812014-02-06 17:33:381157 // DCHECK(std::find(layers_with_copy_output_request_.begin(),
1158 // layers_with_copy_output_request_.end(),
1159 // layer) == layers_with_copy_output_request_.end());
1160 // TODO(danakj): Remove this once crash is found crbug.com/309777
1161 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1162 CHECK(layers_with_copy_output_request_[i] != layer)
1163 << i << " of " << layers_with_copy_output_request_.size();
1164 }
[email protected]30fe19ff2013-07-04 00:54:451165 layers_with_copy_output_request_.push_back(layer);
1166}
1167
1168void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) {
1169 // Only the active tree needs to know about layers with copy requests, as
1170 // they are aborted if not serviced during draw.
1171 DCHECK(IsActiveTree());
1172
1173 std::vector<LayerImpl*>::iterator it = std::find(
1174 layers_with_copy_output_request_.begin(),
1175 layers_with_copy_output_request_.end(),
1176 layer);
1177 DCHECK(it != layers_with_copy_output_request_.end());
[email protected]f5de9e5b2013-07-30 22:26:571178 layers_with_copy_output_request_.erase(it);
[email protected]a4ee12812014-02-06 17:33:381179
1180 // TODO(danakj): Remove this once crash is found crbug.com/309777
1181 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1182 CHECK(layers_with_copy_output_request_[i] != layer)
1183 << i << " of " << layers_with_copy_output_request_.size();
1184 }
[email protected]30fe19ff2013-07-04 00:54:451185}
1186
[email protected]53526372013-12-07 04:31:501187const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest()
[email protected]30fe19ff2013-07-04 00:54:451188 const {
1189 // Only the active tree needs to know about layers with copy requests, as
1190 // they are aborted if not serviced during draw.
1191 DCHECK(IsActiveTree());
1192
1193 return layers_with_copy_output_request_;
1194}
1195
vmpstr9ce5c662015-02-05 23:29:261196void LayerTreeImpl::ProcessLayersRecursive(LayerImpl* current,
1197 void (LayerImpl::*function)()) {
[email protected]aeef2f02014-05-10 12:15:481198 DCHECK(current);
vmpstr9ce5c662015-02-05 23:29:261199 (current->*function)();
[email protected]aeef2f02014-05-10 12:15:481200 if (current->mask_layer())
vmpstr9ce5c662015-02-05 23:29:261201 ProcessLayersRecursive(current->mask_layer(), function);
[email protected]aeef2f02014-05-10 12:15:481202 if (current->replica_layer())
vmpstr9ce5c662015-02-05 23:29:261203 ProcessLayersRecursive(current->replica_layer(), function);
[email protected]aeef2f02014-05-10 12:15:481204 for (size_t i = 0; i < current->children().size(); ++i)
vmpstr9ce5c662015-02-05 23:29:261205 ProcessLayersRecursive(current->children()[i], function);
[email protected]aeef2f02014-05-10 12:15:481206}
1207
[email protected]28336d52014-05-12 19:07:281208template <typename LayerType>
1209static inline bool LayerClipsSubtree(LayerType* layer) {
1210 return layer->masks_to_bounds() || layer->mask_layer();
1211}
1212
1213static bool PointHitsRect(
1214 const gfx::PointF& screen_space_point,
1215 const gfx::Transform& local_space_to_screen_space_transform,
1216 const gfx::RectF& local_space_rect,
1217 float* distance_to_camera) {
1218 // If the transform is not invertible, then assume that this point doesn't hit
1219 // this rect.
1220 gfx::Transform inverse_local_space_to_screen_space(
1221 gfx::Transform::kSkipInitialization);
1222 if (!local_space_to_screen_space_transform.GetInverse(
1223 &inverse_local_space_to_screen_space))
1224 return false;
1225
1226 // Transform the hit test point from screen space to the local space of the
1227 // given rect.
1228 bool clipped = false;
1229 gfx::Point3F planar_point = MathUtil::ProjectPoint3D(
1230 inverse_local_space_to_screen_space, screen_space_point, &clipped);
1231 gfx::PointF hit_test_point_in_local_space =
1232 gfx::PointF(planar_point.x(), planar_point.y());
1233
1234 // If ProjectPoint could not project to a valid value, then we assume that
1235 // this point doesn't hit this rect.
1236 if (clipped)
1237 return false;
1238
1239 if (!local_space_rect.Contains(hit_test_point_in_local_space))
1240 return false;
1241
1242 if (distance_to_camera) {
1243 // To compute the distance to the camera, we have to take the planar point
1244 // and pull it back to world space and compute the displacement along the
1245 // z-axis.
1246 gfx::Point3F planar_point_in_screen_space(planar_point);
1247 local_space_to_screen_space_transform.TransformPoint(
1248 &planar_point_in_screen_space);
1249 *distance_to_camera = planar_point_in_screen_space.z();
1250 }
1251
1252 return true;
1253}
1254
1255static bool PointHitsRegion(const gfx::PointF& screen_space_point,
1256 const gfx::Transform& screen_space_transform,
1257 const Region& layer_space_region,
1258 float layer_content_scale_x,
1259 float layer_content_scale_y) {
1260 // If the transform is not invertible, then assume that this point doesn't hit
1261 // this region.
1262 gfx::Transform inverse_screen_space_transform(
1263 gfx::Transform::kSkipInitialization);
1264 if (!screen_space_transform.GetInverse(&inverse_screen_space_transform))
1265 return false;
1266
1267 // Transform the hit test point from screen space to the local space of the
1268 // given region.
1269 bool clipped = false;
1270 gfx::PointF hit_test_point_in_content_space = MathUtil::ProjectPoint(
1271 inverse_screen_space_transform, screen_space_point, &clipped);
1272 gfx::PointF hit_test_point_in_layer_space =
1273 gfx::ScalePoint(hit_test_point_in_content_space,
1274 1.f / layer_content_scale_x,
1275 1.f / layer_content_scale_y);
1276
1277 // If ProjectPoint could not project to a valid value, then we assume that
1278 // this point doesn't hit this region.
1279 if (clipped)
1280 return false;
1281
1282 return layer_space_region.Contains(
1283 gfx::ToRoundedPoint(hit_test_point_in_layer_space));
1284}
1285
[email protected]19aec372014-07-01 19:08:491286static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) {
[email protected]0ec86f52014-06-12 20:54:031287 if (layer->scroll_parent())
1288 return layer->scroll_parent();
1289 if (layer->clip_parent())
1290 return layer->clip_parent();
1291 return layer->parent();
1292}
1293
[email protected]28336d52014-05-12 19:07:281294static bool PointIsClippedBySurfaceOrClipRect(
1295 const gfx::PointF& screen_space_point,
[email protected]19aec372014-07-01 19:08:491296 const LayerImpl* layer) {
[email protected]28336d52014-05-12 19:07:281297 // Walk up the layer tree and hit-test any render_surfaces and any layer
1298 // clip rects that are active.
[email protected]0ec86f52014-06-12 20:54:031299 for (; layer; layer = GetNextClippingLayer(layer)) {
1300 if (layer->render_surface() &&
1301 !PointHitsRect(screen_space_point,
1302 layer->render_surface()->screen_space_transform(),
1303 layer->render_surface()->content_rect(),
1304 NULL))
[email protected]28336d52014-05-12 19:07:281305 return true;
1306
[email protected]0ec86f52014-06-12 20:54:031307 if (LayerClipsSubtree(layer) &&
1308 !PointHitsRect(screen_space_point,
1309 layer->screen_space_transform(),
1310 gfx::Rect(layer->content_bounds()),
1311 NULL))
[email protected]28336d52014-05-12 19:07:281312 return true;
[email protected]28336d52014-05-12 19:07:281313 }
1314
1315 // If we have finished walking all ancestors without having already exited,
1316 // then the point is not clipped by any ancestors.
1317 return false;
1318}
1319
[email protected]19aec372014-07-01 19:08:491320static bool PointHitsLayer(const LayerImpl* layer,
[email protected]28336d52014-05-12 19:07:281321 const gfx::PointF& screen_space_point,
1322 float* distance_to_intersection) {
1323 gfx::RectF content_rect(layer->content_bounds());
1324 if (!PointHitsRect(screen_space_point,
1325 layer->screen_space_transform(),
1326 content_rect,
1327 distance_to_intersection))
1328 return false;
1329
1330 // At this point, we think the point does hit the layer, but we need to walk
1331 // up the parents to ensure that the layer was not clipped in such a way
1332 // that the hit point actually should not hit the layer.
1333 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer))
1334 return false;
1335
1336 // Skip the HUD layer.
1337 if (layer == layer->layer_tree_impl()->hud_layer())
1338 return false;
1339
1340 return true;
1341}
1342
1343struct FindClosestMatchingLayerDataForRecursion {
1344 FindClosestMatchingLayerDataForRecursion()
1345 : closest_match(NULL),
1346 closest_distance(-std::numeric_limits<float>::infinity()) {}
1347 LayerImpl* closest_match;
1348 // Note that the positive z-axis points towards the camera, so bigger means
1349 // closer in this case, counterintuitively.
1350 float closest_distance;
1351};
1352
1353template <typename Functor>
1354static void FindClosestMatchingLayer(
1355 const gfx::PointF& screen_space_point,
1356 LayerImpl* layer,
1357 const Functor& func,
1358 FindClosestMatchingLayerDataForRecursion* data_for_recursion) {
1359 for (int i = layer->children().size() - 1; i >= 0; --i) {
1360 FindClosestMatchingLayer(
1361 screen_space_point, layer->children()[i], func, data_for_recursion);
1362 }
1363
1364 float distance_to_intersection = 0.f;
1365 if (func(layer) &&
1366 PointHitsLayer(layer, screen_space_point, &distance_to_intersection) &&
1367 ((!data_for_recursion->closest_match ||
1368 distance_to_intersection > data_for_recursion->closest_distance))) {
1369 data_for_recursion->closest_distance = distance_to_intersection;
1370 data_for_recursion->closest_match = layer;
1371 }
1372}
1373
1374static bool ScrollsAnyDrawnRenderSurfaceLayerListMember(LayerImpl* layer) {
1375 if (!layer->scrollable())
1376 return false;
1377 if (layer->IsDrawnRenderSurfaceLayerListMember())
1378 return true;
1379 if (!layer->scroll_children())
1380 return false;
1381 for (std::set<LayerImpl*>::const_iterator it =
1382 layer->scroll_children()->begin();
1383 it != layer->scroll_children()->end();
1384 ++it) {
1385 if ((*it)->IsDrawnRenderSurfaceLayerListMember())
1386 return true;
1387 }
1388 return false;
1389}
1390
1391struct FindScrollingLayerFunctor {
1392 bool operator()(LayerImpl* layer) const {
1393 return ScrollsAnyDrawnRenderSurfaceLayerListMember(layer);
1394 }
1395};
1396
1397LayerImpl* LayerTreeImpl::FindFirstScrollingLayerThatIsHitByPoint(
1398 const gfx::PointF& screen_space_point) {
1399 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1400 FindClosestMatchingLayer(screen_space_point,
1401 root_layer(),
1402 FindScrollingLayerFunctor(),
1403 &data_for_recursion);
1404 return data_for_recursion.closest_match;
1405}
1406
1407struct HitTestVisibleScrollableOrTouchableFunctor {
1408 bool operator()(LayerImpl* layer) const {
1409 return layer->IsDrawnRenderSurfaceLayerListMember() ||
1410 ScrollsAnyDrawnRenderSurfaceLayerListMember(layer) ||
1411 !layer->touch_event_handler_region().IsEmpty() ||
1412 layer->have_wheel_event_handlers();
1413 }
1414};
1415
1416LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPoint(
1417 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321418 if (!root_layer())
1419 return NULL;
1420 if (!UpdateDrawProperties())
1421 return NULL;
[email protected]28336d52014-05-12 19:07:281422 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1423 FindClosestMatchingLayer(screen_space_point,
1424 root_layer(),
1425 HitTestVisibleScrollableOrTouchableFunctor(),
1426 &data_for_recursion);
1427 return data_for_recursion.closest_match;
1428}
1429
1430static bool LayerHasTouchEventHandlersAt(const gfx::PointF& screen_space_point,
1431 LayerImpl* layer_impl) {
1432 if (layer_impl->touch_event_handler_region().IsEmpty())
1433 return false;
1434
1435 if (!PointHitsRegion(screen_space_point,
1436 layer_impl->screen_space_transform(),
1437 layer_impl->touch_event_handler_region(),
1438 layer_impl->contents_scale_x(),
1439 layer_impl->contents_scale_y()))
1440 return false;
1441
1442 // At this point, we think the point does hit the touch event handler region
1443 // on the layer, but we need to walk up the parents to ensure that the layer
1444 // was not clipped in such a way that the hit point actually should not hit
1445 // the layer.
1446 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
1447 return false;
1448
1449 return true;
1450}
1451
ccameron3b607362015-02-02 22:46:291452struct FindWheelEventLayerFunctor {
1453 bool operator()(LayerImpl* layer) const {
1454 return layer->have_wheel_event_handlers();
1455 }
1456};
1457
1458LayerImpl* LayerTreeImpl::FindLayerWithWheelHandlerThatIsHitByPoint(
1459 const gfx::PointF& screen_space_point) {
1460 if (!root_layer())
1461 return NULL;
1462 if (!UpdateDrawProperties())
1463 return NULL;
1464 FindWheelEventLayerFunctor func;
1465 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1466 FindClosestMatchingLayer(screen_space_point, root_layer(), func,
1467 &data_for_recursion);
1468 return data_for_recursion.closest_match;
1469}
1470
[email protected]28336d52014-05-12 19:07:281471struct FindTouchEventLayerFunctor {
1472 bool operator()(LayerImpl* layer) const {
1473 return LayerHasTouchEventHandlersAt(screen_space_point, layer);
1474 }
1475 const gfx::PointF screen_space_point;
1476};
1477
1478LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion(
1479 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321480 if (!root_layer())
1481 return NULL;
1482 if (!UpdateDrawProperties())
1483 return NULL;
[email protected]28336d52014-05-12 19:07:281484 FindTouchEventLayerFunctor func = {screen_space_point};
1485 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1486 FindClosestMatchingLayer(
1487 screen_space_point, root_layer(), func, &data_for_recursion);
1488 return data_for_recursion.closest_match;
1489}
1490
[email protected]ebb179b2014-07-16 17:54:411491void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& start,
1492 const LayerSelectionBound& end) {
1493 selection_start_ = start;
1494 selection_end_ = end;
[email protected]19aec372014-07-01 19:08:491495}
1496
1497static ViewportSelectionBound ComputeViewportSelection(
[email protected]6ef948732014-08-22 18:57:441498 const LayerSelectionBound& layer_bound,
[email protected]19aec372014-07-01 19:08:491499 LayerImpl* layer,
1500 float device_scale_factor) {
[email protected]6ef948732014-08-22 18:57:441501 ViewportSelectionBound viewport_bound;
1502 viewport_bound.type = layer_bound.type;
[email protected]19aec372014-07-01 19:08:491503
[email protected]6ef948732014-08-22 18:57:441504 if (!layer || layer_bound.type == SELECTION_BOUND_EMPTY)
1505 return viewport_bound;
[email protected]19aec372014-07-01 19:08:491506
[email protected]6ef948732014-08-22 18:57:441507 gfx::PointF layer_scaled_top = gfx::ScalePoint(layer_bound.edge_top,
1508 layer->contents_scale_x(),
1509 layer->contents_scale_y());
1510 gfx::PointF layer_scaled_bottom = gfx::ScalePoint(layer_bound.edge_bottom,
1511 layer->contents_scale_x(),
1512 layer->contents_scale_y());
[email protected]19aec372014-07-01 19:08:491513
[email protected]6ef948732014-08-22 18:57:441514 bool clipped = false;
1515 gfx::PointF screen_top = MathUtil::MapPoint(
1516 layer->screen_space_transform(), layer_scaled_top, &clipped);
1517 gfx::PointF screen_bottom = MathUtil::MapPoint(
1518 layer->screen_space_transform(), layer_scaled_bottom, &clipped);
1519
1520 const float inv_scale = 1.f / device_scale_factor;
1521 viewport_bound.edge_top = gfx::ScalePoint(screen_top, inv_scale);
1522 viewport_bound.edge_bottom = gfx::ScalePoint(screen_bottom, inv_scale);
1523
1524 // The bottom edge point is used for visibility testing as it is the logical
[email protected]19aec372014-07-01 19:08:491525 // focal point for bound selection handles (this may change in the future).
[email protected]6ef948732014-08-22 18:57:441526 // Shifting the visibility point fractionally inward ensures that neighboring
1527 // or logically coincident layers aligned to integral DPI coordinates will not
1528 // spuriously occlude the bound.
1529 gfx::Vector2dF visibility_offset = layer_scaled_top - layer_scaled_bottom;
1530 visibility_offset.Scale(device_scale_factor / visibility_offset.Length());
1531 gfx::PointF visibility_point = layer_scaled_bottom + visibility_offset;
1532 if (visibility_point.x() <= 0)
1533 visibility_point.set_x(visibility_point.x() + device_scale_factor);
1534 visibility_point = MathUtil::MapPoint(
1535 layer->screen_space_transform(), visibility_point, &clipped);
1536
[email protected]19aec372014-07-01 19:08:491537 float intersect_distance = 0.f;
[email protected]6ef948732014-08-22 18:57:441538 viewport_bound.visible =
1539 PointHitsLayer(layer, visibility_point, &intersect_distance);
[email protected]19aec372014-07-01 19:08:491540
[email protected]6ef948732014-08-22 18:57:441541 return viewport_bound;
[email protected]19aec372014-07-01 19:08:491542}
1543
[email protected]ebb179b2014-07-16 17:54:411544void LayerTreeImpl::GetViewportSelection(ViewportSelectionBound* start,
1545 ViewportSelectionBound* end) {
1546 DCHECK(start);
1547 DCHECK(end);
[email protected]19aec372014-07-01 19:08:491548
[email protected]ebb179b2014-07-16 17:54:411549 *start = ComputeViewportSelection(
1550 selection_start_,
1551 selection_start_.layer_id ? LayerById(selection_start_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491552 device_scale_factor());
[email protected]ebb179b2014-07-16 17:54:411553 if (start->type == SELECTION_BOUND_CENTER ||
1554 start->type == SELECTION_BOUND_EMPTY) {
1555 *end = *start;
[email protected]19aec372014-07-01 19:08:491556 } else {
[email protected]ebb179b2014-07-16 17:54:411557 *end = ComputeViewportSelection(
1558 selection_end_,
1559 selection_end_.layer_id ? LayerById(selection_end_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491560 device_scale_factor());
1561 }
1562}
1563
[email protected]8aa39ecb2014-06-12 14:19:141564void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) {
1565 layer_tree_host_impl_->RegisterPictureLayerImpl(layer);
1566}
1567
1568void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
1569 layer_tree_host_impl_->UnregisterPictureLayerImpl(layer);
1570}
1571
[email protected]749cbc62014-07-10 01:06:351572void LayerTreeImpl::InputScrollAnimationFinished() {
1573 layer_tree_host_impl_->ScrollEnd();
1574}
1575
vmpstr56ace232014-10-09 20:16:281576bool LayerTreeImpl::SmoothnessTakesPriority() const {
1577 return layer_tree_host_impl_->GetTreePriority() == SMOOTHNESS_TAKES_PRIORITY;
1578}
1579
skyostil3976a3f2014-09-04 22:07:231580BlockingTaskRunner* LayerTreeImpl::BlockingMainThreadTaskRunner() const {
1581 return proxy()->blocking_main_thread_task_runner();
1582}
1583
bokanfcdbc182014-11-21 21:53:331584void LayerTreeImpl::SetPendingPageScaleAnimation(
1585 scoped_ptr<PendingPageScaleAnimation> pending_animation) {
1586 pending_page_scale_animation_ = pending_animation.Pass();
bokan915bf352014-10-02 21:57:141587}
1588
bokanfcdbc182014-11-21 21:53:331589scoped_ptr<PendingPageScaleAnimation>
1590 LayerTreeImpl::TakePendingPageScaleAnimation() {
1591 return pending_page_scale_animation_.Pass();
bokan915bf352014-10-02 21:57:141592}
1593
[email protected]ca2902e92013-03-28 01:45:351594} // namespace cc