blob: 52a54365b3b8c5d9aacf572a6ab4ea96027e5a5f [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"
aelias58eec0812014-12-04 01:04:4017#include "cc/base/synced_property.h"
[email protected]3744e27b2013-11-06 21:44:0818#include "cc/base/util.h"
[email protected]12a63da2014-06-13 06:06:2219#include "cc/debug/devtools_instrumentation.h"
[email protected]f6742f52013-05-08 23:52:2220#include "cc/debug/traced_value.h"
bokan915bf352014-10-02 21:57:1421#include "cc/input/page_scale_animation.h"
[email protected]cc3cfaa2013-03-18 09:05:5222#include "cc/layers/heads_up_display_layer_impl.h"
[email protected]57ac9482013-09-17 21:13:3923#include "cc/layers/layer.h"
[email protected]34ba1ffb2014-03-05 06:55:0324#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2825#include "cc/layers/render_surface_impl.h"
[email protected]80413d72013-08-30 20:25:3326#include "cc/layers/scrollbar_layer_impl_base.h"
[email protected]e1042192013-11-08 05:44:2427#include "cc/resources/ui_resource_request.h"
[email protected]556fd292013-03-18 08:03:0428#include "cc/trees/layer_tree_host_common.h"
29#include "cc/trees/layer_tree_host_impl.h"
[email protected]562b7ad2014-06-23 22:17:1130#include "cc/trees/occlusion_tracker.h"
heejin.r.chungd28506ba2014-10-23 16:36:2031#include "ui/gfx/geometry/point_conversions.h"
32#include "ui/gfx/geometry/size_conversions.h"
33#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]3b31c6ac2012-12-06 21:27:2934
35namespace cc {
36
[email protected]adeda572014-01-31 00:49:4737// This class exists to split the LayerScrollOffsetDelegate between the
38// InnerViewportScrollLayer and the OuterViewportScrollLayer in a manner
39// that never requires the embedder or LayerImpl to know about.
[email protected]ec2322e2014-05-15 16:32:0040class LayerScrollOffsetDelegateProxy : public LayerImpl::ScrollOffsetDelegate {
[email protected]adeda572014-01-31 00:49:4741 public:
42 LayerScrollOffsetDelegateProxy(LayerImpl* layer,
43 LayerScrollOffsetDelegate* delegate,
44 LayerTreeImpl* layer_tree)
45 : layer_(layer), delegate_(delegate), layer_tree_impl_(layer_tree) {}
[email protected]ec2322e2014-05-15 16:32:0046 virtual ~LayerScrollOffsetDelegateProxy() {}
[email protected]adeda572014-01-31 00:49:4747
miletusf57925d2014-10-01 19:38:1348 gfx::ScrollOffset last_set_scroll_offset() const {
[email protected]adeda572014-01-31 00:49:4749 return last_set_scroll_offset_;
50 }
51
52 // LayerScrollOffsetDelegate implementation.
dcheng716bedf2014-10-21 09:51:0853 void SetTotalScrollOffset(const gfx::ScrollOffset& new_offset) override {
[email protected]adeda572014-01-31 00:49:4754 last_set_scroll_offset_ = new_offset;
[email protected]adeda572014-01-31 00:49:4755 }
56
dcheng716bedf2014-10-21 09:51:0857 gfx::ScrollOffset GetTotalScrollOffset() override {
[email protected]adeda572014-01-31 00:49:4758 return layer_tree_impl_->GetDelegatedScrollOffset(layer_);
59 }
60
dcheng716bedf2014-10-21 09:51:0861 bool IsExternalFlingActive() const override {
[email protected]adeda572014-01-31 00:49:4762 return delegate_->IsExternalFlingActive();
63 }
64
bokan6747f5522014-10-24 19:28:5465 void Update() const override {
66 layer_tree_impl_->UpdateScrollOffsetDelegate();
67 }
68
[email protected]adeda572014-01-31 00:49:4769 private:
70 LayerImpl* layer_;
71 LayerScrollOffsetDelegate* delegate_;
72 LayerTreeImpl* layer_tree_impl_;
miletusf57925d2014-10-01 19:38:1373 gfx::ScrollOffset last_set_scroll_offset_;
[email protected]adeda572014-01-31 00:49:4774};
75
aelias58eec0812014-12-04 01:04:4076LayerTreeImpl::LayerTreeImpl(
77 LayerTreeHostImpl* layer_tree_host_impl,
78 scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor)
[email protected]db8259f2013-02-01 05:25:0479 : layer_tree_host_impl_(layer_tree_host_impl),
80 source_frame_number_(-1),
81 hud_layer_(0),
[email protected]1960a712013-04-30 17:06:4782 currently_scrolling_layer_(NULL),
83 root_layer_scroll_offset_delegate_(NULL),
[email protected]db8259f2013-02-01 05:25:0484 background_color_(0),
85 has_transparent_background_(false),
[email protected]57ac9482013-09-17 21:13:3986 page_scale_layer_(NULL),
87 inner_viewport_scroll_layer_(NULL),
88 outer_viewport_scroll_layer_(NULL),
aelias58eec0812014-12-04 01:04:4089 page_scale_factor_(page_scale_factor),
[email protected]db8259f2013-02-01 05:25:0490 min_page_scale_factor_(0),
91 max_page_scale_factor_(0),
92 scrolling_layer_id_from_previous_tree_(0),
93 contents_textures_purged_(false),
[email protected]318822852013-02-14 00:54:2794 viewport_size_invalid_(false),
[email protected]db8259f2013-02-01 05:25:0495 needs_update_draw_properties_(true),
[email protected]7d08a9352013-10-15 08:24:5696 needs_full_tree_sync_(true),
[email protected]390bb1ff2014-05-09 17:14:4097 next_activation_forces_redraw_(false),
[email protected]759dc9f2014-07-23 19:18:5198 has_ever_been_drawn_(false),
bokan88eae012014-09-09 20:40:4299 render_surface_layer_list_id_(0),
100 top_controls_layout_height_(0),
bokan55b2f152014-09-15 14:47:59101 top_controls_content_offset_(0),
bokan88eae012014-09-09 20:40:42102 top_controls_delta_(0),
103 sent_top_controls_delta_(0) {
[email protected]390bb1ff2014-05-09 17:14:40104}
[email protected]3b31c6ac2012-12-06 21:27:29105
106LayerTreeImpl::~LayerTreeImpl() {
[email protected]586871b2014-07-22 17:05:11107 BreakSwapPromises(SwapPromise::SWAP_FAILS);
108
[email protected]361bc00d2012-12-14 07:03:24109 // Need to explicitly clear the tree prior to destroying this so that
110 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
[email protected]df17af52014-02-06 02:20:40111 DCHECK(!root_layer_);
112 DCHECK(layers_with_copy_output_request_.empty());
[email protected]3b31c6ac2012-12-06 21:27:29113}
114
danakjf446a072014-09-27 21:55:48115void LayerTreeImpl::Shutdown() {
116 root_layer_ = nullptr;
117}
[email protected]df17af52014-02-06 02:20:40118
[email protected]aeef2f02014-05-10 12:15:48119void LayerTreeImpl::ReleaseResources() {
120 if (root_layer_)
121 ReleaseResourcesRecursive(root_layer_.get());
122}
123
[email protected]d35cd7b22014-01-29 14:32:46124void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
[email protected]adeda572014-01-31 00:49:47125 if (inner_viewport_scroll_layer_)
126 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
127 if (outer_viewport_scroll_layer_)
128 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48129 inner_viewport_scroll_delegate_proxy_ = nullptr;
130 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]adeda572014-01-31 00:49:47131
[email protected]3b31c6ac2012-12-06 21:27:29132 root_layer_ = layer.Pass();
[email protected]5c4824e12013-01-12 16:34:53133 currently_scrolling_layer_ = NULL;
[email protected]adeda572014-01-31 00:49:47134 inner_viewport_scroll_layer_ = NULL;
135 outer_viewport_scroll_layer_ = NULL;
136 page_scale_layer_ = NULL;
[email protected]5c4824e12013-01-12 16:34:53137
[email protected]c1bb5af2013-03-13 19:06:27138 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]5c4824e12013-01-12 16:34:53139}
140
[email protected]adeda572014-01-31 00:49:47141LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const {
142 return inner_viewport_scroll_layer_;
143}
[email protected]3b31c6ac2012-12-06 21:27:29144
[email protected]adeda572014-01-31 00:49:47145LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const {
146 return outer_viewport_scroll_layer_;
147}
[email protected]1960a712013-04-30 17:06:47148
miletusf57925d2014-10-01 19:38:13149gfx::ScrollOffset LayerTreeImpl::TotalScrollOffset() const {
150 gfx::ScrollOffset offset;
[email protected]3b31c6ac2012-12-06 21:27:29151
[email protected]adeda572014-01-31 00:49:47152 if (inner_viewport_scroll_layer_)
153 offset += inner_viewport_scroll_layer_->TotalScrollOffset();
154
155 if (outer_viewport_scroll_layer_)
156 offset += outer_viewport_scroll_layer_->TotalScrollOffset();
157
158 return offset;
159}
160
miletusf57925d2014-10-01 19:38:13161gfx::ScrollOffset LayerTreeImpl::TotalMaxScrollOffset() const {
162 gfx::ScrollOffset offset;
[email protected]adeda572014-01-31 00:49:47163
164 if (inner_viewport_scroll_layer_)
165 offset += inner_viewport_scroll_layer_->MaxScrollOffset();
166
167 if (outer_viewport_scroll_layer_)
168 offset += outer_viewport_scroll_layer_->MaxScrollOffset();
169
170 return offset;
171}
172gfx::Vector2dF LayerTreeImpl::TotalScrollDelta() const {
173 DCHECK(inner_viewport_scroll_layer_);
174 gfx::Vector2dF delta = inner_viewport_scroll_layer_->ScrollDelta();
175
176 if (outer_viewport_scroll_layer_)
177 delta += outer_viewport_scroll_layer_->ScrollDelta();
178
179 return delta;
[email protected]3b31c6ac2012-12-06 21:27:29180}
181
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
bokan88eae012014-09-09 20:40:42213 target_tree->top_controls_layout_height_ = top_controls_layout_height_;
bokan55b2f152014-09-15 14:47:59214 target_tree->top_controls_content_offset_ = top_controls_content_offset_;
bokan88eae012014-09-09 20:40:42215 target_tree->top_controls_delta_ =
216 target_tree->top_controls_delta_ -
217 target_tree->sent_top_controls_delta_;
218 target_tree->sent_top_controls_delta_ = 0.f;
219
aelias58eec0812014-12-04 01:04:40220 // Active tree already shares the page_scale_factor object with pending
221 // tree so only the limits need to be provided.
222 target_tree->PushPageScaleFactorAndLimits(nullptr, min_page_scale_factor(),
223 max_page_scale_factor());
[email protected]c60279472013-01-30 12:10:51224
bokanfcdbc182014-11-21 21:53:33225 target_tree->pending_page_scale_animation_ =
226 pending_page_scale_animation_.Pass();
bokan915bf352014-10-02 21:57:14227
[email protected]adeda572014-01-31 00:49:47228 if (page_scale_layer_ && inner_viewport_scroll_layer_) {
[email protected]57ac9482013-09-17 21:13:39229 target_tree->SetViewportLayersFromIds(
ccameron8230b68b2014-11-21 19:25:18230 overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id()
231 : Layer::INVALID_ID,
232 page_scale_layer_->id(), inner_viewport_scroll_layer_->id(),
[email protected]57ac9482013-09-17 21:13:39233 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
234 : Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47235 } else {
236 target_tree->ClearViewportLayers();
[email protected]57ac9482013-09-17 21:13:39237 }
[email protected]19aec372014-07-01 19:08:49238
[email protected]ebb179b2014-07-16 17:54:41239 target_tree->RegisterSelection(selection_start_, selection_end_);
[email protected]19aec372014-07-01 19:08:49240
[email protected]c60279472013-01-30 12:10:51241 // This should match the property synchronization in
242 // LayerTreeHost::finishCommitOnImplThread().
243 target_tree->set_source_frame_number(source_frame_number());
244 target_tree->set_background_color(background_color());
245 target_tree->set_has_transparent_background(has_transparent_background());
246
247 if (ContentsTexturesPurged())
248 target_tree->SetContentsTexturesPurged();
249 else
250 target_tree->ResetContentsTexturesPurged();
251
[email protected]318822852013-02-14 00:54:27252 if (ViewportSizeInvalid())
253 target_tree->SetViewportSizeInvalid();
254 else
255 target_tree->ResetViewportSizeInvalid();
256
[email protected]c60279472013-01-30 12:10:51257 if (hud_layer())
258 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
[email protected]6ba914122013-03-22 16:26:39259 LayerTreeHostCommon::FindLayerInSubtree(
[email protected]c1bb5af2013-03-13 19:06:27260 target_tree->root_layer(), hud_layer()->id())));
[email protected]c60279472013-01-30 12:10:51261 else
262 target_tree->set_hud_layer(NULL);
[email protected]759dc9f2014-07-23 19:18:51263
264 target_tree->has_ever_been_drawn_ = false;
[email protected]c60279472013-01-30 12:10:51265}
266
[email protected]fef74fd2014-02-27 06:28:17267LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const {
268 return inner_viewport_scroll_layer_
269 ? inner_viewport_scroll_layer_->scroll_clip_layer()
270 : NULL;
[email protected]ffb2720f2013-03-15 19:18:37271}
272
bokanef971462014-10-13 22:58:32273LayerImpl* LayerTreeImpl::OuterViewportContainerLayer() const {
274 return outer_viewport_scroll_layer_
275 ? outer_viewport_scroll_layer_->scroll_clip_layer()
276 : NULL;
277}
278
[email protected]ffb2720f2013-03-15 19:18:37279LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
[email protected]69b50ec2013-01-19 04:58:01280 DCHECK(IsActiveTree());
281 return currently_scrolling_layer_;
282}
283
[email protected]0fc818e2013-03-18 06:45:20284void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
285 if (currently_scrolling_layer_ == layer)
286 return;
287
288 if (currently_scrolling_layer_ &&
289 currently_scrolling_layer_->scrollbar_animation_controller())
[email protected]1dc06162014-03-26 22:54:45290 currently_scrolling_layer_->scrollbar_animation_controller()
[email protected]930ff43b2014-05-02 05:24:00291 ->DidScrollEnd();
[email protected]0fc818e2013-03-18 06:45:20292 currently_scrolling_layer_ = layer;
293 if (layer && layer->scrollbar_animation_controller())
[email protected]930ff43b2014-05-02 05:24:00294 layer->scrollbar_animation_controller()->DidScrollBegin();
[email protected]0fc818e2013-03-18 06:45:20295}
296
[email protected]3b31c6ac2012-12-06 21:27:29297void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
[email protected]0fc818e2013-03-18 06:45:20298 SetCurrentlyScrollingLayer(NULL);
[email protected]3b31c6ac2012-12-06 21:27:29299 scrolling_layer_id_from_previous_tree_ = 0;
300}
301
[email protected]adeda572014-01-31 00:49:47302namespace {
303
304void ForceScrollbarParameterUpdateAfterScaleChange(LayerImpl* current_layer) {
305 if (!current_layer)
306 return;
307
308 while (current_layer) {
sataya.m07f11a82014-10-07 14:29:18309 current_layer->ScrollbarParametersDidChange(false);
[email protected]adeda572014-01-31 00:49:47310 current_layer = current_layer->parent();
311 }
312}
313
314} // namespace
315
aelias58eec0812014-12-04 01:04:40316float LayerTreeImpl::ClampPageScaleFactorToLimits(
317 float page_scale_factor) const {
318 if (min_page_scale_factor_ && page_scale_factor < min_page_scale_factor_)
319 page_scale_factor = min_page_scale_factor_;
320 else if (max_page_scale_factor_ && page_scale_factor > max_page_scale_factor_)
321 page_scale_factor = max_page_scale_factor_;
322 return page_scale_factor;
[email protected]d6021f6a2014-06-12 21:15:24323}
[email protected]c60279472013-01-30 12:10:51324
aelias58eec0812014-12-04 01:04:40325void LayerTreeImpl::SetPageScaleOnActiveTree(float active_page_scale) {
326 DCHECK(IsActiveTree());
327 if (page_scale_factor()->SetCurrent(
328 ClampPageScaleFactorToLimits(active_page_scale)))
329 DidUpdatePageScale();
[email protected]d6021f6a2014-06-12 21:15:24330}
331
aelias58eec0812014-12-04 01:04:40332void LayerTreeImpl::PushPageScaleFromMainThread(float page_scale_factor,
333 float min_page_scale_factor,
334 float max_page_scale_factor) {
335 PushPageScaleFactorAndLimits(&page_scale_factor, min_page_scale_factor,
336 max_page_scale_factor);
337}
338
339void LayerTreeImpl::PushPageScaleFactorAndLimits(const float* page_scale_factor,
340 float min_page_scale_factor,
341 float max_page_scale_factor) {
342 DCHECK(page_scale_factor || IsActiveTree());
343 bool changed_page_scale = false;
344 if (page_scale_factor) {
345 DCHECK(!IsActiveTree() || !layer_tree_host_impl_->pending_tree());
346 changed_page_scale |=
347 page_scale_factor_->PushFromMainThread(*page_scale_factor);
348 }
349 if (IsActiveTree())
350 changed_page_scale |= page_scale_factor_->PushPendingToActive();
351 changed_page_scale |=
352 SetPageScaleFactorLimits(min_page_scale_factor, max_page_scale_factor);
353
354 if (changed_page_scale)
355 DidUpdatePageScale();
356}
357
358bool LayerTreeImpl::SetPageScaleFactorLimits(float min_page_scale_factor,
359 float max_page_scale_factor) {
360 if (min_page_scale_factor == min_page_scale_factor_ &&
361 max_page_scale_factor == max_page_scale_factor_)
362 return false;
[email protected]7265e74e2014-02-07 23:43:06363
[email protected]c60279472013-01-30 12:10:51364 min_page_scale_factor_ = min_page_scale_factor;
365 max_page_scale_factor_ = max_page_scale_factor;
[email protected]20d2b742013-09-26 05:41:34366
aelias58eec0812014-12-04 01:04:40367 return true;
368}
[email protected]d6021f6a2014-06-12 21:15:24369
aelias58eec0812014-12-04 01:04:40370void LayerTreeImpl::DidUpdatePageScale() {
371 if (IsActiveTree())
372 page_scale_factor()->SetCurrent(
373 ClampPageScaleFactorToLimits(current_page_scale_factor()));
[email protected]d6021f6a2014-06-12 21:15:24374
aelias58eec0812014-12-04 01:04:40375 set_needs_update_draw_properties();
[email protected]d6021f6a2014-06-12 21:15:24376
[email protected]22f200a2013-10-09 18:08:29377 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00378 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
aelias58eec0812014-12-04 01:04:40379 TotalScrollOffset(), TotalMaxScrollOffset(), ScrollableSize(),
380 current_page_scale_factor(), min_page_scale_factor_,
[email protected]d6021f6a2014-06-12 21:15:24381 max_page_scale_factor_);
[email protected]22f200a2013-10-09 18:08:29382 }
[email protected]adeda572014-01-31 00:49:47383
384 ForceScrollbarParameterUpdateAfterScaleChange(page_scale_layer());
[email protected]c60279472013-01-30 12:10:51385}
386
aelias58eec0812014-12-04 01:04:40387SyncedProperty<ScaleGroup>* LayerTreeImpl::page_scale_factor() {
388 return page_scale_factor_.get();
389}
390
391const SyncedProperty<ScaleGroup>* LayerTreeImpl::page_scale_factor() const {
392 return page_scale_factor_.get();
393}
394
[email protected]257abfa82013-01-29 23:47:24395gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]587941d2014-08-22 01:40:01396 if (!InnerViewportContainerLayer())
397 return gfx::SizeF();
398
bokanef971462014-10-13 22:58:32399 return gfx::ScaleSize(InnerViewportContainerLayer()->BoundsForScrolling(),
aelias58eec0812014-12-04 01:04:40400 1.0f / current_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24401}
402
[email protected]3744e27b2013-11-06 21:44:08403gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const {
[email protected]adeda572014-01-31 00:49:47404 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
405 ? OuterViewportScrollLayer()
406 : InnerViewportScrollLayer();
407 if (!root_scroll_layer || root_scroll_layer->children().empty())
[email protected]3744e27b2013-11-06 21:44:08408 return gfx::Rect();
[email protected]adeda572014-01-31 00:49:47409 LayerImpl* layer = root_scroll_layer->children()[0];
[email protected]8a822692014-02-12 17:30:55410 return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(),
411 gfx::Rect(layer->content_bounds()));
[email protected]3744e27b2013-11-06 21:44:08412}
413
[email protected]58241dc2013-08-20 01:39:25414static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) {
415 layer->ApplySentScrollDeltasFromAbortedCommit();
[email protected]3519b872013-07-30 07:17:50416}
417
[email protected]58241dc2013-08-20 01:39:25418void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50419 DCHECK(IsActiveTree());
420
aelias58eec0812014-12-04 01:04:40421 page_scale_factor()->AbortCommit();
[email protected]3519b872013-07-30 07:17:50422
bokan55b2f152014-09-15 14:47:59423 top_controls_content_offset_ += sent_top_controls_delta_;
bokan88eae012014-09-09 20:40:42424 top_controls_delta_ -= sent_top_controls_delta_;
425 sent_top_controls_delta_ = 0.f;
426
[email protected]3519b872013-07-30 07:17:50427 if (!root_layer())
428 return;
429
430 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]58241dc2013-08-20 01:39:25431 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo));
432}
433
[email protected]daea3d42013-10-23 17:04:50434static void ApplyScrollDeltasSinceBeginMainFrameTo(LayerImpl* layer) {
435 layer->ApplyScrollDeltasSinceBeginMainFrame();
[email protected]58241dc2013-08-20 01:39:25436}
437
[email protected]daea3d42013-10-23 17:04:50438void LayerTreeImpl::ApplyScrollDeltasSinceBeginMainFrame() {
[email protected]58241dc2013-08-20 01:39:25439 DCHECK(IsPendingTree());
440 if (!root_layer())
441 return;
442
443 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]daea3d42013-10-23 17:04:50444 root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginMainFrameTo));
[email protected]3519b872013-07-30 07:17:50445}
446
[email protected]57ac9482013-09-17 21:13:39447void LayerTreeImpl::SetViewportLayersFromIds(
ccameron8230b68b2014-11-21 19:25:18448 int overscroll_elasticity_layer_id,
[email protected]57ac9482013-09-17 21:13:39449 int page_scale_layer_id,
450 int inner_viewport_scroll_layer_id,
451 int outer_viewport_scroll_layer_id) {
ccameron8230b68b2014-11-21 19:25:18452 overscroll_elasticity_layer_ = LayerById(overscroll_elasticity_layer_id);
[email protected]57ac9482013-09-17 21:13:39453 page_scale_layer_ = LayerById(page_scale_layer_id);
454 DCHECK(page_scale_layer_);
455
456 inner_viewport_scroll_layer_ =
457 LayerById(inner_viewport_scroll_layer_id);
458 DCHECK(inner_viewport_scroll_layer_);
459
460 outer_viewport_scroll_layer_ =
461 LayerById(outer_viewport_scroll_layer_id);
462 DCHECK(outer_viewport_scroll_layer_ ||
463 outer_viewport_scroll_layer_id == Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47464
465 if (!root_layer_scroll_offset_delegate_)
466 return;
467
468 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
469 new LayerScrollOffsetDelegateProxy(inner_viewport_scroll_layer_,
470 root_layer_scroll_offset_delegate_,
471 this));
472
473 if (outer_viewport_scroll_layer_)
474 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
475 new LayerScrollOffsetDelegateProxy(outer_viewport_scroll_layer_,
476 root_layer_scroll_offset_delegate_,
477 this));
[email protected]57ac9482013-09-17 21:13:39478}
479
480void LayerTreeImpl::ClearViewportLayers() {
481 page_scale_layer_ = NULL;
482 inner_viewport_scroll_layer_ = NULL;
483 outer_viewport_scroll_layer_ = NULL;
484}
485
[email protected]8f7f298822014-06-13 00:23:32486bool LayerTreeImpl::UpdateDrawProperties() {
487 if (!needs_update_draw_properties_)
488 return true;
[email protected]615c78a2013-01-24 23:44:16489
[email protected]ed511b8d2013-03-25 03:29:29490 // For max_texture_size.
[email protected]615c78a2013-01-24 23:44:16491 if (!layer_tree_host_impl_->renderer())
[email protected]8f7f298822014-06-13 00:23:32492 return false;
[email protected]615c78a2013-01-24 23:44:16493
[email protected]c1bb5af2013-03-13 19:06:27494 if (!root_layer())
[email protected]8f7f298822014-06-13 00:23:32495 return false;
496
497 needs_update_draw_properties_ = false;
498 render_surface_layer_list_.clear();
[email protected]76ffd9e2012-12-20 19:12:47499
[email protected]76ffd9e2012-12-20 19:12:47500 {
[email protected]7a52f43e2013-07-10 01:58:47501 TRACE_EVENT2("cc",
[email protected]c1bb5af2013-03-13 19:06:27502 "LayerTreeImpl::UpdateDrawProperties",
503 "IsActive",
[email protected]7a52f43e2013-07-10 01:58:47504 IsActiveTree(),
505 "SourceFrameNumber",
506 source_frame_number_);
[email protected]57ac9482013-09-17 21:13:39507 LayerImpl* page_scale_layer =
[email protected]fef74fd2014-02-27 06:28:17508 page_scale_layer_ ? page_scale_layer_ : InnerViewportContainerLayer();
hush367d7dd2014-08-29 23:56:01509 bool can_render_to_separate_surface =
510 (layer_tree_host_impl_->GetDrawMode() !=
511 DRAW_MODE_RESOURCELESS_SOFTWARE);
[email protected]390bb1ff2014-05-09 17:14:40512
513 ++render_surface_layer_list_id_;
[email protected]7aad55f2013-07-26 11:25:53514 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
danakj3f76ace2014-11-18 16:56:00515 root_layer(), DrawViewportSize(),
516 layer_tree_host_impl_->DrawTransform(), device_scale_factor(),
aelias58eec0812014-12-04 01:04:40517 current_page_scale_factor(), page_scale_layer,
danakj3f76ace2014-11-18 16:56:00518 resource_provider()->max_texture_size(), settings().can_use_lcd_text,
519 settings().layers_always_allowed_lcd_text,
[email protected]45948712013-09-27 02:46:48520 can_render_to_separate_surface,
[email protected]35a99a12013-05-09 23:52:29521 settings().layer_transforms_should_scale_layer_contents,
danakj3f76ace2014-11-18 16:56:00522 &render_surface_layer_list_, render_surface_layer_list_id_);
[email protected]7aad55f2013-07-26 11:25:53523 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]76ffd9e2012-12-20 19:12:47524 }
[email protected]615c78a2013-01-24 23:44:16525
[email protected]e4be0262013-10-19 16:54:28526 {
vmpstrd6166202014-11-05 18:45:40527 TRACE_EVENT_BEGIN2("cc", "LayerTreeImpl::UpdateTilePriorities", "IsActive",
528 IsActiveTree(), "SourceFrameNumber",
529 source_frame_number_);
danakj6496cba2014-10-16 01:31:08530 scoped_ptr<OcclusionTracker<LayerImpl>> occlusion_tracker;
[email protected]562b7ad2014-06-23 22:17:11531 if (settings().use_occlusion_for_tile_prioritization) {
532 occlusion_tracker.reset(new OcclusionTracker<LayerImpl>(
533 root_layer()->render_surface()->content_rect()));
534 occlusion_tracker->set_minimum_tracking_size(
535 settings().minimum_occlusion_tracking_size);
536 }
537
boliu7473f7f52014-10-01 16:54:56538 bool resourceless_software_draw = (layer_tree_host_impl_->GetDrawMode() ==
539 DRAW_MODE_RESOURCELESS_SOFTWARE);
540
[email protected]e4be0262013-10-19 16:54:28541 // LayerIterator is used here instead of CallFunctionForSubtree to only
542 // UpdateTilePriorities on layers that will be visible (and thus have valid
543 // draw properties) and not because any ordering is required.
[email protected]ba1b33e2014-02-28 16:44:51544 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]e4be0262013-10-19 16:54:28545 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
vmpstrd6166202014-11-05 18:45:40546 size_t layers_updated_count = 0;
[email protected]e4be0262013-10-19 16:54:28547 for (LayerIteratorType it =
548 LayerIteratorType::Begin(&render_surface_layer_list_);
549 it != end;
550 ++it) {
[email protected]562b7ad2014-06-23 22:17:11551 if (occlusion_tracker)
552 occlusion_tracker->EnterLayer(it);
553
[email protected]e4be0262013-10-19 16:54:28554 LayerImpl* layer = *it;
vmpstrcdcb5f72014-09-11 00:58:37555 const Occlusion& occlusion_in_content_space =
556 occlusion_tracker ? occlusion_tracker->GetCurrentOcclusionForLayer(
557 layer->draw_transform())
558 : Occlusion();
559
boliu7473f7f52014-10-01 16:54:56560 if (it.represents_itself()) {
561 layer->UpdateTiles(occlusion_in_content_space,
562 resourceless_software_draw);
vmpstrd6166202014-11-05 18:45:40563 ++layers_updated_count;
boliu7473f7f52014-10-01 16:54:56564 }
[email protected]e4be0262013-10-19 16:54:28565
[email protected]562b7ad2014-06-23 22:17:11566 if (!it.represents_contributing_render_surface()) {
567 if (occlusion_tracker)
568 occlusion_tracker->LeaveLayer(it);
[email protected]6355d2d2014-05-07 15:07:27569 continue;
[email protected]562b7ad2014-06-23 22:17:11570 }
[email protected]6355d2d2014-05-07 15:07:27571
boliu7473f7f52014-10-01 16:54:56572 if (layer->mask_layer()) {
573 layer->mask_layer()->UpdateTiles(occlusion_in_content_space,
574 resourceless_software_draw);
vmpstrd6166202014-11-05 18:45:40575 ++layers_updated_count;
boliu7473f7f52014-10-01 16:54:56576 }
577 if (layer->replica_layer() && layer->replica_layer()->mask_layer()) {
[email protected]562b7ad2014-06-23 22:17:11578 layer->replica_layer()->mask_layer()->UpdateTiles(
boliu7473f7f52014-10-01 16:54:56579 occlusion_in_content_space, resourceless_software_draw);
vmpstrd6166202014-11-05 18:45:40580 ++layers_updated_count;
boliu7473f7f52014-10-01 16:54:56581 }
[email protected]562b7ad2014-06-23 22:17:11582
583 if (occlusion_tracker)
584 occlusion_tracker->LeaveLayer(it);
[email protected]e4be0262013-10-19 16:54:28585 }
vmpstrd6166202014-11-05 18:45:40586
587 TRACE_EVENT_END1("cc", "LayerTreeImpl::UpdateTilePriorities",
588 "layers_updated_count", layers_updated_count);
[email protected]e4be0262013-10-19 16:54:28589 }
590
[email protected]615c78a2013-01-24 23:44:16591 DCHECK(!needs_update_draw_properties_) <<
[email protected]7d19dc342013-05-02 22:02:04592 "CalcDrawProperties should not set_needs_update_draw_properties()";
[email protected]8f7f298822014-06-13 00:23:32593 return true;
[email protected]76ffd9e2012-12-20 19:12:47594}
595
[email protected]50761e92013-03-29 20:51:28596const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const {
[email protected]76ffd9e2012-12-20 19:12:47597 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16598 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47599 return render_surface_layer_list_;
600}
601
bokancccfde72014-10-08 15:15:22602gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]adeda572014-01-31 00:49:47603 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
604 ? OuterViewportScrollLayer()
605 : InnerViewportScrollLayer();
606 if (!root_scroll_layer || root_scroll_layer->children().empty())
bokancccfde72014-10-08 15:15:22607 return gfx::Size();
[email protected]adeda572014-01-31 00:49:47608 return root_scroll_layer->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16609}
610
[email protected]361bc00d2012-12-14 07:03:24611LayerImpl* LayerTreeImpl::LayerById(int id) {
612 LayerIdMap::iterator iter = layer_id_map_.find(id);
613 return iter != layer_id_map_.end() ? iter->second : NULL;
614}
615
616void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
617 DCHECK(!LayerById(layer->id()));
618 layer_id_map_[layer->id()] = layer;
619}
620
621void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
622 DCHECK(LayerById(layer->id()));
623 layer_id_map_.erase(layer->id());
624}
625
[email protected]aebf4622014-07-14 16:57:59626size_t LayerTreeImpl::NumLayers() {
627 return layer_id_map_.size();
628}
629
[email protected]ed511b8d2013-03-25 03:29:29630void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) {
[email protected]a90fac72013-06-06 18:56:13631 pending_tree->SetCurrentlyScrollingLayer(
632 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(),
633 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0));
[email protected]1e0f8d62013-01-09 07:41:35634}
635
[email protected]ff1211d2013-06-07 01:58:35636static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34637 layer->DidBecomeActive();
[email protected]db2e29c2014-08-06 05:58:25638 if (layer->mask_layer())
639 layer->mask_layer()->DidBecomeActive();
640 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
641 layer->replica_layer()->mask_layer()->DidBecomeActive();
642
[email protected]ff1211d2013-06-07 01:58:35643 for (size_t i = 0; i < layer->children().size(); ++i)
644 DidBecomeActiveRecursive(layer->children()[i]);
[email protected]37386f052013-01-13 00:42:22645}
646
647void LayerTreeImpl::DidBecomeActive() {
[email protected]12a63da2014-06-13 06:06:22648 if (next_activation_forces_redraw_) {
649 layer_tree_host_impl_->SetFullRootLayerDamage();
650 next_activation_forces_redraw_ = false;
651 }
652
[email protected]adeda572014-01-31 00:49:47653 if (scrolling_layer_id_from_previous_tree_) {
654 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
[email protected]7dcf5632014-06-25 01:11:55655 root_layer(), scrolling_layer_id_from_previous_tree_);
[email protected]adeda572014-01-31 00:49:47656 }
657
[email protected]7dcf5632014-06-25 01:11:55658 // Always reset this flag on activation, as we would only have activated
659 // if we were in a good state.
vmpstr61ed94a12014-10-09 04:49:30660 layer_tree_host_impl_->ResetRequiresHighResToDraw();
[email protected]7dcf5632014-06-25 01:11:55661
662 if (root_layer())
663 DidBecomeActiveRecursive(root_layer());
664
[email protected]12a63da2014-06-13 06:06:22665 devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(),
666 source_frame_number_);
[email protected]37386f052013-01-13 00:42:22667}
668
[email protected]6f90b9e2013-01-17 23:42:00669bool LayerTreeImpl::ContentsTexturesPurged() const {
670 return contents_textures_purged_;
671}
672
673void LayerTreeImpl::SetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04674 if (contents_textures_purged_)
675 return;
[email protected]6f90b9e2013-01-17 23:42:00676 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27677 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00678}
679
680void LayerTreeImpl::ResetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04681 if (!contents_textures_purged_)
682 return;
[email protected]6f90b9e2013-01-17 23:42:00683 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27684 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00685}
686
[email protected]3d609bb2014-02-01 01:10:23687bool LayerTreeImpl::RequiresHighResToDraw() const {
vmpstr61ed94a12014-10-09 04:49:30688 return layer_tree_host_impl_->RequiresHighResToDraw();
[email protected]3d609bb2014-02-01 01:10:23689}
690
[email protected]318822852013-02-14 00:54:27691bool LayerTreeImpl::ViewportSizeInvalid() const {
692 return viewport_size_invalid_;
693}
694
695void LayerTreeImpl::SetViewportSizeInvalid() {
696 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27697 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27698}
699
700void LayerTreeImpl::ResetViewportSizeInvalid() {
701 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27702 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27703}
704
[email protected]48871fc2013-01-23 07:36:51705Proxy* LayerTreeImpl::proxy() const {
706 return layer_tree_host_impl_->proxy();
707}
708
[email protected]ff762fb2012-12-12 19:18:37709const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27710 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37711}
712
[email protected]7a8bcd262014-01-15 12:54:58713const RendererCapabilitiesImpl& LayerTreeImpl::GetRendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27714 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52715}
716
[email protected]0634cdd42013-08-16 00:46:09717ContextProvider* LayerTreeImpl::context_provider() const {
dcheng6afa17002014-08-26 19:11:31718 return output_surface()->context_provider();
[email protected]0634cdd42013-08-16 00:46:09719}
720
[email protected]ff762fb2012-12-12 19:18:37721OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27722 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37723}
724
725ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27726 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37727}
728
729TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27730 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37731}
732
733FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27734 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37735}
736
[email protected]71691c22013-01-18 03:14:22737PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27738 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22739}
740
[email protected]1191d9d2013-02-02 06:00:33741MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27742 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33743}
744
[email protected]4a6c091d2014-04-24 21:06:46745gfx::Size LayerTreeImpl::device_viewport_size() const {
746 return layer_tree_host_impl_->device_viewport_size();
747}
748
[email protected]f117a4c2012-12-16 04:53:10749bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27750 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10751}
752
753bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27754 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10755}
756
[email protected]48871fc2013-01-23 07:36:51757bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27758 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51759}
760
[email protected]f117a4c2012-12-16 04:53:10761LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27762 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10763 if (!tree)
764 return NULL;
765 return tree->LayerById(id);
766}
767
768LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27769 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10770 if (!tree)
771 return NULL;
772 return tree->LayerById(id);
773}
774
[email protected]166db5c82013-01-09 23:54:31775bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27776 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31777}
778
[email protected]04c5900d2014-08-18 13:38:36779BeginFrameArgs LayerTreeImpl::CurrentBeginFrameArgs() const {
780 return layer_tree_host_impl_->CurrentBeginFrameArgs();
[email protected]fb7425a2013-04-22 16:28:55781}
782
[email protected]c92195e2014-05-07 18:18:49783base::TimeDelta LayerTreeImpl::begin_impl_frame_interval() const {
784 return layer_tree_host_impl_->begin_impl_frame_interval();
785}
786
[email protected]d7eb8c72013-03-23 22:57:13787void LayerTreeImpl::SetNeedsCommit() {
788 layer_tree_host_impl_->SetNeedsCommit();
789}
790
[email protected]bd5324592014-07-31 09:09:33791gfx::Rect LayerTreeImpl::DeviceViewport() const {
792 return layer_tree_host_impl_->DeviceViewport();
793}
794
[email protected]54af03522013-09-05 00:43:28795gfx::Size LayerTreeImpl::DrawViewportSize() const {
796 return layer_tree_host_impl_->DrawViewportSize();
797}
798
[email protected]bd5324592014-07-31 09:09:33799const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const {
800 return layer_tree_host_impl_->ViewportRectForTilePriority();
801}
802
[email protected]930ff43b2014-05-02 05:24:00803scoped_ptr<ScrollbarAnimationController>
804LayerTreeImpl::CreateScrollbarAnimationController(LayerImpl* scrolling_layer) {
805 DCHECK(settings().scrollbar_fade_delay_ms);
806 DCHECK(settings().scrollbar_fade_duration_ms);
807 base::TimeDelta delay =
808 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms);
sataya.m07f11a82014-10-07 14:29:18809 base::TimeDelta resize_delay = base::TimeDelta::FromMilliseconds(
810 settings().scrollbar_fade_resize_delay_ms);
[email protected]930ff43b2014-05-02 05:24:00811 base::TimeDelta duration =
812 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms);
813 switch (settings().scrollbar_animator) {
814 case LayerTreeSettings::LinearFade: {
815 return ScrollbarAnimationControllerLinearFade::Create(
sataya.m07f11a82014-10-07 14:29:18816 scrolling_layer,
817 layer_tree_host_impl_,
818 delay,
819 resize_delay,
820 duration);
[email protected]930ff43b2014-05-02 05:24:00821 }
822 case LayerTreeSettings::Thinning: {
sataya.m07f11a82014-10-07 14:29:18823 return ScrollbarAnimationControllerThinning::Create(scrolling_layer,
824 layer_tree_host_impl_,
825 delay,
826 resize_delay,
827 duration);
[email protected]930ff43b2014-05-02 05:24:00828 }
829 case LayerTreeSettings::NoAnimator:
830 NOTREACHED();
831 break;
832 }
danakjf446a072014-09-27 21:55:48833 return nullptr;
[email protected]2ea5aba2013-09-11 14:26:56834}
835
[email protected]b8384e22013-12-03 02:20:48836void LayerTreeImpl::DidAnimateScrollOffset() {
837 layer_tree_host_impl_->DidAnimateScrollOffset();
838}
839
[email protected]13525d62014-05-20 21:22:04840bool LayerTreeImpl::use_gpu_rasterization() const {
841 return layer_tree_host_impl_->use_gpu_rasterization();
842}
843
hendrikwc2bbd612014-12-03 23:49:34844GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const {
845 return layer_tree_host_impl_->gpu_rasterization_status();
846}
847
[email protected]473f1f22014-05-22 08:19:17848bool LayerTreeImpl::create_low_res_tiling() const {
849 return layer_tree_host_impl_->create_low_res_tiling();
850}
851
[email protected]ff762fb2012-12-12 19:18:37852void LayerTreeImpl::SetNeedsRedraw() {
[email protected]59adb112013-04-09 04:48:44853 layer_tree_host_impl_->SetNeedsRedraw();
[email protected]ff762fb2012-12-12 19:18:37854}
855
[email protected]ff762fb2012-12-12 19:18:37856const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27857 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37858}
859
860float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27861 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37862}
863
[email protected]ff762fb2012-12-12 19:18:37864DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27865 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37866}
867
[email protected]de4afb5e2012-12-20 00:11:34868AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27869 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34870}
[email protected]ff762fb2012-12-12 19:18:37871
vmpstrd7de03c2014-08-27 18:11:01872void LayerTreeImpl::GetAllTilesForTracing(std::set<const Tile*>* tiles) const {
873 typedef LayerIterator<LayerImpl> LayerIteratorType;
874 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
875 for (LayerIteratorType it =
876 LayerIteratorType::Begin(&render_surface_layer_list_);
877 it != end;
878 ++it) {
879 if (!it.represents_itself())
880 continue;
881 LayerImpl* layer_impl = *it;
882 layer_impl->GetAllTilesForTracing(tiles);
883 }
884}
885
[email protected]d12aa932014-08-01 13:10:38886void LayerTreeImpl::AsValueInto(base::debug::TracedValue* state) const {
887 TracedValue::MakeDictIntoImplicitSnapshot(state, "cc::LayerTreeImpl", this);
nduca929378a02014-08-23 19:48:52888 state->SetInteger("source_frame_number", source_frame_number_);
[email protected]f6742f52013-05-08 23:52:22889
[email protected]d12aa932014-08-01 13:10:38890 state->BeginDictionary("root_layer");
891 root_layer_->AsValueInto(state);
892 state->EndDictionary();
[email protected]f6742f52013-05-08 23:52:22893
[email protected]d12aa932014-08-01 13:10:38894 state->BeginArray("render_surface_layer_list");
[email protected]ba1b33e2014-02-28 16:44:51895 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09896 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
897 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]8c5690222013-02-15 17:36:43898 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09899 if (!it.represents_itself())
[email protected]8c5690222013-02-15 17:36:43900 continue;
[email protected]d12aa932014-08-01 13:10:38901 TracedValue::AppendIDRef(*it, state);
[email protected]8c5690222013-02-15 17:36:43902 }
[email protected]d12aa932014-08-01 13:10:38903 state->EndArray();
skyostil43c330f72014-09-22 16:49:11904
905 state->BeginArray("swap_promise_trace_ids");
906 for (size_t i = 0; i < swap_promise_list_.size(); i++)
907 state->AppendDouble(swap_promise_list_[i]->TraceId());
908 state->EndArray();
[email protected]8c5690222013-02-15 17:36:43909}
910
[email protected]1960a712013-04-30 17:06:47911void LayerTreeImpl::SetRootLayerScrollOffsetDelegate(
[email protected]c9280762013-08-01 06:28:57912 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
[email protected]20d2b742013-09-26 05:41:34913 if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate)
914 return;
915
[email protected]adeda572014-01-31 00:49:47916 if (!root_layer_scroll_offset_delegate) {
917 // Make sure we remove the proxies from their layers before
918 // releasing them.
919 if (InnerViewportScrollLayer())
920 InnerViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
921 if (OuterViewportScrollLayer())
922 OuterViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
danakjf446a072014-09-27 21:55:48923 inner_viewport_scroll_delegate_proxy_ = nullptr;
924 outer_viewport_scroll_delegate_proxy_ = nullptr;
[email protected]d35cd7b22014-01-29 14:32:46925 }
926
[email protected]adeda572014-01-31 00:49:47927 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
928
[email protected]20d2b742013-09-26 05:41:34929 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00930 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
aelias58eec0812014-12-04 01:04:40931 TotalScrollOffset(), TotalMaxScrollOffset(), ScrollableSize(),
932 current_page_scale_factor(), min_page_scale_factor(),
[email protected]68fe60f2014-02-12 13:49:11933 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47934
935 if (inner_viewport_scroll_layer_) {
936 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
937 new LayerScrollOffsetDelegateProxy(InnerViewportScrollLayer(),
938 root_layer_scroll_offset_delegate_,
939 this));
940 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(
941 inner_viewport_scroll_delegate_proxy_.get());
942 }
943
944 if (outer_viewport_scroll_layer_) {
945 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
946 new LayerScrollOffsetDelegateProxy(OuterViewportScrollLayer(),
947 root_layer_scroll_offset_delegate_,
948 this));
949 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(
950 outer_viewport_scroll_delegate_proxy_.get());
951 }
bokan6747f5522014-10-24 19:28:54952
953 if (inner_viewport_scroll_layer_)
954 UpdateScrollOffsetDelegate();
[email protected]20d2b742013-09-26 05:41:34955 }
[email protected]1960a712013-04-30 17:06:47956}
957
boliu7d5dbab2014-10-10 20:05:47958void LayerTreeImpl::OnRootLayerDelegatedScrollOffsetChanged() {
959 DCHECK(root_layer_scroll_offset_delegate_);
960 if (inner_viewport_scroll_layer_) {
961 inner_viewport_scroll_layer_->DidScroll();
962 }
963 if (outer_viewport_scroll_layer_) {
964 outer_viewport_scroll_layer_->DidScroll();
965 }
966}
967
[email protected]adeda572014-01-31 00:49:47968void LayerTreeImpl::UpdateScrollOffsetDelegate() {
969 DCHECK(InnerViewportScrollLayer());
bokan6747f5522014-10-24 19:28:54970 DCHECK(!OuterViewportScrollLayer() || outer_viewport_scroll_delegate_proxy_);
[email protected]adeda572014-01-31 00:49:47971 DCHECK(root_layer_scroll_offset_delegate_);
972
miletusf57925d2014-10-01 19:38:13973 gfx::ScrollOffset offset =
[email protected]adeda572014-01-31 00:49:47974 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
975
976 if (OuterViewportScrollLayer())
977 offset += outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
978
[email protected]ec2322e2014-05-15 16:32:00979 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
aelias58eec0812014-12-04 01:04:40980 offset, TotalMaxScrollOffset(), ScrollableSize(),
981 current_page_scale_factor(), min_page_scale_factor(),
[email protected]ec2322e2014-05-15 16:32:00982 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47983}
984
miletusf57925d2014-10-01 19:38:13985gfx::ScrollOffset LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) {
[email protected]adeda572014-01-31 00:49:47986 DCHECK(root_layer_scroll_offset_delegate_);
987 DCHECK(InnerViewportScrollLayer());
988 if (layer == InnerViewportScrollLayer() && !OuterViewportScrollLayer())
989 return root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
990
991 // If we get here, we have both inner/outer viewports, and need to distribute
992 // the scroll offset between them.
993 DCHECK(inner_viewport_scroll_delegate_proxy_);
994 DCHECK(outer_viewport_scroll_delegate_proxy_);
miletusf57925d2014-10-01 19:38:13995 gfx::ScrollOffset inner_viewport_offset =
[email protected]adeda572014-01-31 00:49:47996 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
miletusf57925d2014-10-01 19:38:13997 gfx::ScrollOffset outer_viewport_offset =
[email protected]adeda572014-01-31 00:49:47998 outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
999
1000 // It may be nothing has changed.
miletusf57925d2014-10-01 19:38:131001 gfx::ScrollOffset delegate_offset =
[email protected]adeda572014-01-31 00:49:471002 root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
1003 if (inner_viewport_offset + outer_viewport_offset == delegate_offset) {
1004 if (layer == InnerViewportScrollLayer())
1005 return inner_viewport_offset;
1006 else
1007 return outer_viewport_offset;
1008 }
1009
miletusf57925d2014-10-01 19:38:131010 gfx::ScrollOffset max_outer_viewport_scroll_offset =
[email protected]adeda572014-01-31 00:49:471011 OuterViewportScrollLayer()->MaxScrollOffset();
1012
1013 outer_viewport_offset = delegate_offset - inner_viewport_offset;
1014 outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset);
miletusf57925d2014-10-01 19:38:131015 outer_viewport_offset.SetToMax(gfx::ScrollOffset());
[email protected]adeda572014-01-31 00:49:471016
1017 if (layer == OuterViewportScrollLayer())
1018 return outer_viewport_offset;
1019
1020 inner_viewport_offset = delegate_offset - outer_viewport_offset;
1021
1022 return inner_viewport_offset;
1023}
1024
[email protected]b69c1db2013-11-27 00:05:191025void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) {
1026 DCHECK(swap_promise);
[email protected]b69c1db2013-11-27 00:05:191027 swap_promise_list_.push_back(swap_promise.Pass());
1028}
1029
1030void LayerTreeImpl::PassSwapPromises(
1031 ScopedPtrVector<SwapPromise>* new_swap_promise) {
1032 swap_promise_list_.insert_and_take(swap_promise_list_.end(),
weiliangcc1878c62014-09-02 22:43:171033 new_swap_promise);
[email protected]b69c1db2013-11-27 00:05:191034 new_swap_promise->clear();
1035}
1036
[email protected]d359203a2013-11-29 06:16:551037void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) {
[email protected]b69c1db2013-11-27 00:05:191038 for (size_t i = 0; i < swap_promise_list_.size(); i++)
[email protected]d359203a2013-11-29 06:16:551039 swap_promise_list_[i]->DidSwap(metadata);
[email protected]b69c1db2013-11-27 00:05:191040 swap_promise_list_.clear();
1041}
1042
1043void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) {
1044 for (size_t i = 0; i < swap_promise_list_.size(); i++)
1045 swap_promise_list_[i]->DidNotSwap(reason);
1046 swap_promise_list_.clear();
1047}
1048
[email protected]c48536a52013-09-14 00:02:081049void LayerTreeImpl::DidModifyTilePriorities() {
1050 layer_tree_host_impl_->DidModifyTilePriorities();
[email protected]fcb846d2013-05-22 01:42:361051}
1052
[email protected]c9280762013-08-01 06:28:571053void LayerTreeImpl::set_ui_resource_request_queue(
1054 const UIResourceRequestQueue& queue) {
1055 ui_resource_request_queue_ = queue;
1056}
1057
1058ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource(
1059 UIResourceId uid) const {
1060 return layer_tree_host_impl_->ResourceIdForUIResource(uid);
1061}
1062
[email protected]709c9542013-10-26 01:43:511063bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const {
1064 return layer_tree_host_impl_->IsUIResourceOpaque(uid);
1065}
1066
[email protected]c9280762013-08-01 06:28:571067void LayerTreeImpl::ProcessUIResourceRequestQueue() {
1068 while (ui_resource_request_queue_.size() > 0) {
1069 UIResourceRequest req = ui_resource_request_queue_.front();
1070 ui_resource_request_queue_.pop_front();
1071
[email protected]741fba422013-09-20 03:34:141072 switch (req.GetType()) {
[email protected]c9280762013-08-01 06:28:571073 case UIResourceRequest::UIResourceCreate:
[email protected]741fba422013-09-20 03:34:141074 layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap());
[email protected]c9280762013-08-01 06:28:571075 break;
1076 case UIResourceRequest::UIResourceDelete:
[email protected]741fba422013-09-20 03:34:141077 layer_tree_host_impl_->DeleteUIResource(req.GetId());
[email protected]c9280762013-08-01 06:28:571078 break;
[email protected]f28d64d2013-08-27 04:17:451079 case UIResourceRequest::UIResourceInvalidRequest:
[email protected]c9280762013-08-01 06:28:571080 NOTREACHED();
1081 break;
1082 }
1083 }
[email protected]127bdc1a2013-09-11 01:44:481084
1085 // If all UI resource evictions were not recreated by processing this queue,
1086 // then another commit is required.
1087 if (layer_tree_host_impl_->EvictedUIResourcesExist())
1088 layer_tree_host_impl_->SetNeedsCommit();
[email protected]c9280762013-08-01 06:28:571089}
1090
[email protected]30fe19ff2013-07-04 00:54:451091void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) {
1092 // Only the active tree needs to know about layers with copy requests, as
1093 // they are aborted if not serviced during draw.
1094 DCHECK(IsActiveTree());
1095
[email protected]a4ee12812014-02-06 17:33:381096 // DCHECK(std::find(layers_with_copy_output_request_.begin(),
1097 // layers_with_copy_output_request_.end(),
1098 // layer) == layers_with_copy_output_request_.end());
1099 // TODO(danakj): Remove this once crash is found crbug.com/309777
1100 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1101 CHECK(layers_with_copy_output_request_[i] != layer)
1102 << i << " of " << layers_with_copy_output_request_.size();
1103 }
[email protected]30fe19ff2013-07-04 00:54:451104 layers_with_copy_output_request_.push_back(layer);
1105}
1106
1107void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) {
1108 // Only the active tree needs to know about layers with copy requests, as
1109 // they are aborted if not serviced during draw.
1110 DCHECK(IsActiveTree());
1111
1112 std::vector<LayerImpl*>::iterator it = std::find(
1113 layers_with_copy_output_request_.begin(),
1114 layers_with_copy_output_request_.end(),
1115 layer);
1116 DCHECK(it != layers_with_copy_output_request_.end());
[email protected]f5de9e5b2013-07-30 22:26:571117 layers_with_copy_output_request_.erase(it);
[email protected]a4ee12812014-02-06 17:33:381118
1119 // TODO(danakj): Remove this once crash is found crbug.com/309777
1120 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1121 CHECK(layers_with_copy_output_request_[i] != layer)
1122 << i << " of " << layers_with_copy_output_request_.size();
1123 }
[email protected]30fe19ff2013-07-04 00:54:451124}
1125
[email protected]53526372013-12-07 04:31:501126const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest()
[email protected]30fe19ff2013-07-04 00:54:451127 const {
1128 // Only the active tree needs to know about layers with copy requests, as
1129 // they are aborted if not serviced during draw.
1130 DCHECK(IsActiveTree());
1131
1132 return layers_with_copy_output_request_;
1133}
1134
[email protected]aeef2f02014-05-10 12:15:481135void LayerTreeImpl::ReleaseResourcesRecursive(LayerImpl* current) {
1136 DCHECK(current);
1137 current->ReleaseResources();
1138 if (current->mask_layer())
1139 ReleaseResourcesRecursive(current->mask_layer());
1140 if (current->replica_layer())
1141 ReleaseResourcesRecursive(current->replica_layer());
1142 for (size_t i = 0; i < current->children().size(); ++i)
1143 ReleaseResourcesRecursive(current->children()[i]);
1144}
1145
[email protected]28336d52014-05-12 19:07:281146template <typename LayerType>
1147static inline bool LayerClipsSubtree(LayerType* layer) {
1148 return layer->masks_to_bounds() || layer->mask_layer();
1149}
1150
1151static bool PointHitsRect(
1152 const gfx::PointF& screen_space_point,
1153 const gfx::Transform& local_space_to_screen_space_transform,
1154 const gfx::RectF& local_space_rect,
1155 float* distance_to_camera) {
1156 // If the transform is not invertible, then assume that this point doesn't hit
1157 // this rect.
1158 gfx::Transform inverse_local_space_to_screen_space(
1159 gfx::Transform::kSkipInitialization);
1160 if (!local_space_to_screen_space_transform.GetInverse(
1161 &inverse_local_space_to_screen_space))
1162 return false;
1163
1164 // Transform the hit test point from screen space to the local space of the
1165 // given rect.
1166 bool clipped = false;
1167 gfx::Point3F planar_point = MathUtil::ProjectPoint3D(
1168 inverse_local_space_to_screen_space, screen_space_point, &clipped);
1169 gfx::PointF hit_test_point_in_local_space =
1170 gfx::PointF(planar_point.x(), planar_point.y());
1171
1172 // If ProjectPoint could not project to a valid value, then we assume that
1173 // this point doesn't hit this rect.
1174 if (clipped)
1175 return false;
1176
1177 if (!local_space_rect.Contains(hit_test_point_in_local_space))
1178 return false;
1179
1180 if (distance_to_camera) {
1181 // To compute the distance to the camera, we have to take the planar point
1182 // and pull it back to world space and compute the displacement along the
1183 // z-axis.
1184 gfx::Point3F planar_point_in_screen_space(planar_point);
1185 local_space_to_screen_space_transform.TransformPoint(
1186 &planar_point_in_screen_space);
1187 *distance_to_camera = planar_point_in_screen_space.z();
1188 }
1189
1190 return true;
1191}
1192
1193static bool PointHitsRegion(const gfx::PointF& screen_space_point,
1194 const gfx::Transform& screen_space_transform,
1195 const Region& layer_space_region,
1196 float layer_content_scale_x,
1197 float layer_content_scale_y) {
1198 // If the transform is not invertible, then assume that this point doesn't hit
1199 // this region.
1200 gfx::Transform inverse_screen_space_transform(
1201 gfx::Transform::kSkipInitialization);
1202 if (!screen_space_transform.GetInverse(&inverse_screen_space_transform))
1203 return false;
1204
1205 // Transform the hit test point from screen space to the local space of the
1206 // given region.
1207 bool clipped = false;
1208 gfx::PointF hit_test_point_in_content_space = MathUtil::ProjectPoint(
1209 inverse_screen_space_transform, screen_space_point, &clipped);
1210 gfx::PointF hit_test_point_in_layer_space =
1211 gfx::ScalePoint(hit_test_point_in_content_space,
1212 1.f / layer_content_scale_x,
1213 1.f / layer_content_scale_y);
1214
1215 // If ProjectPoint could not project to a valid value, then we assume that
1216 // this point doesn't hit this region.
1217 if (clipped)
1218 return false;
1219
1220 return layer_space_region.Contains(
1221 gfx::ToRoundedPoint(hit_test_point_in_layer_space));
1222}
1223
[email protected]19aec372014-07-01 19:08:491224static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) {
[email protected]0ec86f52014-06-12 20:54:031225 if (layer->scroll_parent())
1226 return layer->scroll_parent();
1227 if (layer->clip_parent())
1228 return layer->clip_parent();
1229 return layer->parent();
1230}
1231
[email protected]28336d52014-05-12 19:07:281232static bool PointIsClippedBySurfaceOrClipRect(
1233 const gfx::PointF& screen_space_point,
[email protected]19aec372014-07-01 19:08:491234 const LayerImpl* layer) {
[email protected]28336d52014-05-12 19:07:281235 // Walk up the layer tree and hit-test any render_surfaces and any layer
1236 // clip rects that are active.
[email protected]0ec86f52014-06-12 20:54:031237 for (; layer; layer = GetNextClippingLayer(layer)) {
1238 if (layer->render_surface() &&
1239 !PointHitsRect(screen_space_point,
1240 layer->render_surface()->screen_space_transform(),
1241 layer->render_surface()->content_rect(),
1242 NULL))
[email protected]28336d52014-05-12 19:07:281243 return true;
1244
[email protected]0ec86f52014-06-12 20:54:031245 if (LayerClipsSubtree(layer) &&
1246 !PointHitsRect(screen_space_point,
1247 layer->screen_space_transform(),
1248 gfx::Rect(layer->content_bounds()),
1249 NULL))
[email protected]28336d52014-05-12 19:07:281250 return true;
[email protected]28336d52014-05-12 19:07:281251 }
1252
1253 // If we have finished walking all ancestors without having already exited,
1254 // then the point is not clipped by any ancestors.
1255 return false;
1256}
1257
[email protected]19aec372014-07-01 19:08:491258static bool PointHitsLayer(const LayerImpl* layer,
[email protected]28336d52014-05-12 19:07:281259 const gfx::PointF& screen_space_point,
1260 float* distance_to_intersection) {
1261 gfx::RectF content_rect(layer->content_bounds());
1262 if (!PointHitsRect(screen_space_point,
1263 layer->screen_space_transform(),
1264 content_rect,
1265 distance_to_intersection))
1266 return false;
1267
1268 // At this point, we think the point does hit the layer, but we need to walk
1269 // up the parents to ensure that the layer was not clipped in such a way
1270 // that the hit point actually should not hit the layer.
1271 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer))
1272 return false;
1273
1274 // Skip the HUD layer.
1275 if (layer == layer->layer_tree_impl()->hud_layer())
1276 return false;
1277
1278 return true;
1279}
1280
1281struct FindClosestMatchingLayerDataForRecursion {
1282 FindClosestMatchingLayerDataForRecursion()
1283 : closest_match(NULL),
1284 closest_distance(-std::numeric_limits<float>::infinity()) {}
1285 LayerImpl* closest_match;
1286 // Note that the positive z-axis points towards the camera, so bigger means
1287 // closer in this case, counterintuitively.
1288 float closest_distance;
1289};
1290
1291template <typename Functor>
1292static void FindClosestMatchingLayer(
1293 const gfx::PointF& screen_space_point,
1294 LayerImpl* layer,
1295 const Functor& func,
1296 FindClosestMatchingLayerDataForRecursion* data_for_recursion) {
1297 for (int i = layer->children().size() - 1; i >= 0; --i) {
1298 FindClosestMatchingLayer(
1299 screen_space_point, layer->children()[i], func, data_for_recursion);
1300 }
1301
1302 float distance_to_intersection = 0.f;
1303 if (func(layer) &&
1304 PointHitsLayer(layer, screen_space_point, &distance_to_intersection) &&
1305 ((!data_for_recursion->closest_match ||
1306 distance_to_intersection > data_for_recursion->closest_distance))) {
1307 data_for_recursion->closest_distance = distance_to_intersection;
1308 data_for_recursion->closest_match = layer;
1309 }
1310}
1311
1312static bool ScrollsAnyDrawnRenderSurfaceLayerListMember(LayerImpl* layer) {
1313 if (!layer->scrollable())
1314 return false;
1315 if (layer->IsDrawnRenderSurfaceLayerListMember())
1316 return true;
1317 if (!layer->scroll_children())
1318 return false;
1319 for (std::set<LayerImpl*>::const_iterator it =
1320 layer->scroll_children()->begin();
1321 it != layer->scroll_children()->end();
1322 ++it) {
1323 if ((*it)->IsDrawnRenderSurfaceLayerListMember())
1324 return true;
1325 }
1326 return false;
1327}
1328
1329struct FindScrollingLayerFunctor {
1330 bool operator()(LayerImpl* layer) const {
1331 return ScrollsAnyDrawnRenderSurfaceLayerListMember(layer);
1332 }
1333};
1334
1335LayerImpl* LayerTreeImpl::FindFirstScrollingLayerThatIsHitByPoint(
1336 const gfx::PointF& screen_space_point) {
1337 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1338 FindClosestMatchingLayer(screen_space_point,
1339 root_layer(),
1340 FindScrollingLayerFunctor(),
1341 &data_for_recursion);
1342 return data_for_recursion.closest_match;
1343}
1344
1345struct HitTestVisibleScrollableOrTouchableFunctor {
1346 bool operator()(LayerImpl* layer) const {
1347 return layer->IsDrawnRenderSurfaceLayerListMember() ||
1348 ScrollsAnyDrawnRenderSurfaceLayerListMember(layer) ||
1349 !layer->touch_event_handler_region().IsEmpty() ||
1350 layer->have_wheel_event_handlers();
1351 }
1352};
1353
1354LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPoint(
1355 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321356 if (!root_layer())
1357 return NULL;
1358 if (!UpdateDrawProperties())
1359 return NULL;
[email protected]28336d52014-05-12 19:07:281360 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1361 FindClosestMatchingLayer(screen_space_point,
1362 root_layer(),
1363 HitTestVisibleScrollableOrTouchableFunctor(),
1364 &data_for_recursion);
1365 return data_for_recursion.closest_match;
1366}
1367
1368static bool LayerHasTouchEventHandlersAt(const gfx::PointF& screen_space_point,
1369 LayerImpl* layer_impl) {
1370 if (layer_impl->touch_event_handler_region().IsEmpty())
1371 return false;
1372
1373 if (!PointHitsRegion(screen_space_point,
1374 layer_impl->screen_space_transform(),
1375 layer_impl->touch_event_handler_region(),
1376 layer_impl->contents_scale_x(),
1377 layer_impl->contents_scale_y()))
1378 return false;
1379
1380 // At this point, we think the point does hit the touch event handler region
1381 // on the layer, but we need to walk up the parents to ensure that the layer
1382 // was not clipped in such a way that the hit point actually should not hit
1383 // the layer.
1384 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
1385 return false;
1386
1387 return true;
1388}
1389
1390struct FindTouchEventLayerFunctor {
1391 bool operator()(LayerImpl* layer) const {
1392 return LayerHasTouchEventHandlersAt(screen_space_point, layer);
1393 }
1394 const gfx::PointF screen_space_point;
1395};
1396
1397LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion(
1398 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321399 if (!root_layer())
1400 return NULL;
1401 if (!UpdateDrawProperties())
1402 return NULL;
[email protected]28336d52014-05-12 19:07:281403 FindTouchEventLayerFunctor func = {screen_space_point};
1404 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1405 FindClosestMatchingLayer(
1406 screen_space_point, root_layer(), func, &data_for_recursion);
1407 return data_for_recursion.closest_match;
1408}
1409
[email protected]ebb179b2014-07-16 17:54:411410void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& start,
1411 const LayerSelectionBound& end) {
1412 selection_start_ = start;
1413 selection_end_ = end;
[email protected]19aec372014-07-01 19:08:491414}
1415
1416static ViewportSelectionBound ComputeViewportSelection(
[email protected]6ef948732014-08-22 18:57:441417 const LayerSelectionBound& layer_bound,
[email protected]19aec372014-07-01 19:08:491418 LayerImpl* layer,
1419 float device_scale_factor) {
[email protected]6ef948732014-08-22 18:57:441420 ViewportSelectionBound viewport_bound;
1421 viewport_bound.type = layer_bound.type;
[email protected]19aec372014-07-01 19:08:491422
[email protected]6ef948732014-08-22 18:57:441423 if (!layer || layer_bound.type == SELECTION_BOUND_EMPTY)
1424 return viewport_bound;
[email protected]19aec372014-07-01 19:08:491425
[email protected]6ef948732014-08-22 18:57:441426 gfx::PointF layer_scaled_top = gfx::ScalePoint(layer_bound.edge_top,
1427 layer->contents_scale_x(),
1428 layer->contents_scale_y());
1429 gfx::PointF layer_scaled_bottom = gfx::ScalePoint(layer_bound.edge_bottom,
1430 layer->contents_scale_x(),
1431 layer->contents_scale_y());
[email protected]19aec372014-07-01 19:08:491432
[email protected]6ef948732014-08-22 18:57:441433 bool clipped = false;
1434 gfx::PointF screen_top = MathUtil::MapPoint(
1435 layer->screen_space_transform(), layer_scaled_top, &clipped);
1436 gfx::PointF screen_bottom = MathUtil::MapPoint(
1437 layer->screen_space_transform(), layer_scaled_bottom, &clipped);
1438
1439 const float inv_scale = 1.f / device_scale_factor;
1440 viewport_bound.edge_top = gfx::ScalePoint(screen_top, inv_scale);
1441 viewport_bound.edge_bottom = gfx::ScalePoint(screen_bottom, inv_scale);
1442
1443 // The bottom edge point is used for visibility testing as it is the logical
[email protected]19aec372014-07-01 19:08:491444 // focal point for bound selection handles (this may change in the future).
[email protected]6ef948732014-08-22 18:57:441445 // Shifting the visibility point fractionally inward ensures that neighboring
1446 // or logically coincident layers aligned to integral DPI coordinates will not
1447 // spuriously occlude the bound.
1448 gfx::Vector2dF visibility_offset = layer_scaled_top - layer_scaled_bottom;
1449 visibility_offset.Scale(device_scale_factor / visibility_offset.Length());
1450 gfx::PointF visibility_point = layer_scaled_bottom + visibility_offset;
1451 if (visibility_point.x() <= 0)
1452 visibility_point.set_x(visibility_point.x() + device_scale_factor);
1453 visibility_point = MathUtil::MapPoint(
1454 layer->screen_space_transform(), visibility_point, &clipped);
1455
[email protected]19aec372014-07-01 19:08:491456 float intersect_distance = 0.f;
[email protected]6ef948732014-08-22 18:57:441457 viewport_bound.visible =
1458 PointHitsLayer(layer, visibility_point, &intersect_distance);
[email protected]19aec372014-07-01 19:08:491459
[email protected]6ef948732014-08-22 18:57:441460 return viewport_bound;
[email protected]19aec372014-07-01 19:08:491461}
1462
[email protected]ebb179b2014-07-16 17:54:411463void LayerTreeImpl::GetViewportSelection(ViewportSelectionBound* start,
1464 ViewportSelectionBound* end) {
1465 DCHECK(start);
1466 DCHECK(end);
[email protected]19aec372014-07-01 19:08:491467
[email protected]ebb179b2014-07-16 17:54:411468 *start = ComputeViewportSelection(
1469 selection_start_,
1470 selection_start_.layer_id ? LayerById(selection_start_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491471 device_scale_factor());
[email protected]ebb179b2014-07-16 17:54:411472 if (start->type == SELECTION_BOUND_CENTER ||
1473 start->type == SELECTION_BOUND_EMPTY) {
1474 *end = *start;
[email protected]19aec372014-07-01 19:08:491475 } else {
[email protected]ebb179b2014-07-16 17:54:411476 *end = ComputeViewportSelection(
1477 selection_end_,
1478 selection_end_.layer_id ? LayerById(selection_end_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491479 device_scale_factor());
1480 }
1481}
1482
[email protected]8aa39ecb2014-06-12 14:19:141483void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) {
1484 layer_tree_host_impl_->RegisterPictureLayerImpl(layer);
1485}
1486
1487void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
1488 layer_tree_host_impl_->UnregisterPictureLayerImpl(layer);
1489}
1490
[email protected]749cbc62014-07-10 01:06:351491void LayerTreeImpl::InputScrollAnimationFinished() {
1492 layer_tree_host_impl_->ScrollEnd();
1493}
1494
vmpstr56ace232014-10-09 20:16:281495bool LayerTreeImpl::SmoothnessTakesPriority() const {
1496 return layer_tree_host_impl_->GetTreePriority() == SMOOTHNESS_TAKES_PRIORITY;
1497}
1498
skyostil3976a3f2014-09-04 22:07:231499BlockingTaskRunner* LayerTreeImpl::BlockingMainThreadTaskRunner() const {
1500 return proxy()->blocking_main_thread_task_runner();
1501}
1502
bokanfcdbc182014-11-21 21:53:331503void LayerTreeImpl::SetPendingPageScaleAnimation(
1504 scoped_ptr<PendingPageScaleAnimation> pending_animation) {
1505 pending_page_scale_animation_ = pending_animation.Pass();
bokan915bf352014-10-02 21:57:141506}
1507
bokanfcdbc182014-11-21 21:53:331508scoped_ptr<PendingPageScaleAnimation>
1509 LayerTreeImpl::TakePendingPageScaleAnimation() {
1510 return pending_page_scale_animation_.Pass();
bokan915bf352014-10-02 21:57:141511}
1512
[email protected]ca2902e92013-03-28 01:45:351513} // namespace cc