blob: f442ca2d7363376c92e45ed02bfb791be51fe698 [file] [log] [blame]
[email protected]3b31c6ac2012-12-06 21:27:291// Copyright 2011 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]556fd292013-03-18 08:03:045#include "cc/trees/layer_tree_impl.h"
[email protected]3b31c6ac2012-12-06 21:27:296
[email protected]28336d52014-05-12 19:07:287#include <limits>
8#include <set>
9
[email protected]76ffd9e2012-12-20 19:12:4710#include "base/debug/trace_event.h"
[email protected]d12aa932014-08-01 13:10:3811#include "base/debug/trace_event_argument.h"
[email protected]95e4e1a02013-03-18 07:09:0912#include "cc/animation/keyframed_animation_curve.h"
13#include "cc/animation/scrollbar_animation_controller.h"
[email protected]930ff43b2014-05-02 05:24:0014#include "cc/animation/scrollbar_animation_controller_linear_fade.h"
15#include "cc/animation/scrollbar_animation_controller_thinning.h"
[email protected]3744e27b2013-11-06 21:44:0816#include "cc/base/math_util.h"
17#include "cc/base/util.h"
[email protected]12a63da2014-06-13 06:06:2218#include "cc/debug/devtools_instrumentation.h"
[email protected]f6742f52013-05-08 23:52:2219#include "cc/debug/traced_value.h"
[email protected]cc3cfaa2013-03-18 09:05:5220#include "cc/layers/heads_up_display_layer_impl.h"
[email protected]57ac9482013-09-17 21:13:3921#include "cc/layers/layer.h"
[email protected]34ba1ffb2014-03-05 06:55:0322#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2823#include "cc/layers/render_surface_impl.h"
[email protected]80413d72013-08-30 20:25:3324#include "cc/layers/scrollbar_layer_impl_base.h"
[email protected]e1042192013-11-08 05:44:2425#include "cc/resources/ui_resource_request.h"
[email protected]556fd292013-03-18 08:03:0426#include "cc/trees/layer_tree_host_common.h"
27#include "cc/trees/layer_tree_host_impl.h"
[email protected]562b7ad2014-06-23 22:17:1128#include "cc/trees/occlusion_tracker.h"
[email protected]28336d52014-05-12 19:07:2829#include "ui/gfx/point_conversions.h"
[email protected]ffb2720f2013-03-15 19:18:3730#include "ui/gfx/size_conversions.h"
[email protected]caa567d2012-12-20 07:56:1631#include "ui/gfx/vector2d_conversions.h"
[email protected]3b31c6ac2012-12-06 21:27:2932
33namespace cc {
34
[email protected]adeda572014-01-31 00:49:4735// This class exists to split the LayerScrollOffsetDelegate between the
36// InnerViewportScrollLayer and the OuterViewportScrollLayer in a manner
37// that never requires the embedder or LayerImpl to know about.
[email protected]ec2322e2014-05-15 16:32:0038class LayerScrollOffsetDelegateProxy : public LayerImpl::ScrollOffsetDelegate {
[email protected]adeda572014-01-31 00:49:4739 public:
40 LayerScrollOffsetDelegateProxy(LayerImpl* layer,
41 LayerScrollOffsetDelegate* delegate,
42 LayerTreeImpl* layer_tree)
43 : layer_(layer), delegate_(delegate), layer_tree_impl_(layer_tree) {}
[email protected]ec2322e2014-05-15 16:32:0044 virtual ~LayerScrollOffsetDelegateProxy() {}
[email protected]adeda572014-01-31 00:49:4745
46 gfx::Vector2dF last_set_scroll_offset() const {
47 return last_set_scroll_offset_;
48 }
49
50 // LayerScrollOffsetDelegate implementation.
[email protected]adeda572014-01-31 00:49:4751 virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_offset) OVERRIDE {
52 last_set_scroll_offset_ = new_offset;
53 layer_tree_impl_->UpdateScrollOffsetDelegate();
54 }
55
56 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE {
57 return layer_tree_impl_->GetDelegatedScrollOffset(layer_);
58 }
59
60 virtual bool IsExternalFlingActive() const OVERRIDE {
61 return delegate_->IsExternalFlingActive();
62 }
63
[email protected]adeda572014-01-31 00:49:4764 private:
65 LayerImpl* layer_;
66 LayerScrollOffsetDelegate* delegate_;
67 LayerTreeImpl* layer_tree_impl_;
68 gfx::Vector2dF last_set_scroll_offset_;
69};
70
[email protected]8bef40572012-12-11 21:38:0871LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
[email protected]db8259f2013-02-01 05:25:0472 : layer_tree_host_impl_(layer_tree_host_impl),
73 source_frame_number_(-1),
74 hud_layer_(0),
[email protected]1960a712013-04-30 17:06:4775 currently_scrolling_layer_(NULL),
76 root_layer_scroll_offset_delegate_(NULL),
[email protected]db8259f2013-02-01 05:25:0477 background_color_(0),
78 has_transparent_background_(false),
[email protected]57ac9482013-09-17 21:13:3979 page_scale_layer_(NULL),
80 inner_viewport_scroll_layer_(NULL),
81 outer_viewport_scroll_layer_(NULL),
[email protected]db8259f2013-02-01 05:25:0482 page_scale_factor_(1),
83 page_scale_delta_(1),
84 sent_page_scale_delta_(1),
85 min_page_scale_factor_(0),
86 max_page_scale_factor_(0),
87 scrolling_layer_id_from_previous_tree_(0),
88 contents_textures_purged_(false),
[email protected]3d609bb2014-02-01 01:10:2389 requires_high_res_to_draw_(false),
[email protected]318822852013-02-14 00:54:2790 viewport_size_invalid_(false),
[email protected]db8259f2013-02-01 05:25:0491 needs_update_draw_properties_(true),
[email protected]7d08a9352013-10-15 08:24:5692 needs_full_tree_sync_(true),
[email protected]390bb1ff2014-05-09 17:14:4093 next_activation_forces_redraw_(false),
[email protected]759dc9f2014-07-23 19:18:5194 has_ever_been_drawn_(false),
[email protected]390bb1ff2014-05-09 17:14:4095 render_surface_layer_list_id_(0) {
96}
[email protected]3b31c6ac2012-12-06 21:27:2997
98LayerTreeImpl::~LayerTreeImpl() {
[email protected]586871b2014-07-22 17:05:1199 BreakSwapPromises(SwapPromise::SWAP_FAILS);
100
[email protected]361bc00d2012-12-14 07:03:24101 // Need to explicitly clear the tree prior to destroying this so that
102 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
[email protected]df17af52014-02-06 02:20:40103 DCHECK(!root_layer_);
104 DCHECK(layers_with_copy_output_request_.empty());
[email protected]3b31c6ac2012-12-06 21:27:29105}
106
[email protected]df17af52014-02-06 02:20:40107void LayerTreeImpl::Shutdown() { root_layer_.reset(); }
108
[email protected]aeef2f02014-05-10 12:15:48109void LayerTreeImpl::ReleaseResources() {
110 if (root_layer_)
111 ReleaseResourcesRecursive(root_layer_.get());
112}
113
[email protected]d35cd7b22014-01-29 14:32:46114void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
[email protected]adeda572014-01-31 00:49:47115 if (inner_viewport_scroll_layer_)
116 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
117 if (outer_viewport_scroll_layer_)
118 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
119 inner_viewport_scroll_delegate_proxy_.reset();
120 outer_viewport_scroll_delegate_proxy_.reset();
121
[email protected]3b31c6ac2012-12-06 21:27:29122 root_layer_ = layer.Pass();
[email protected]5c4824e12013-01-12 16:34:53123 currently_scrolling_layer_ = NULL;
[email protected]adeda572014-01-31 00:49:47124 inner_viewport_scroll_layer_ = NULL;
125 outer_viewport_scroll_layer_ = NULL;
126 page_scale_layer_ = NULL;
[email protected]5c4824e12013-01-12 16:34:53127
[email protected]c1bb5af2013-03-13 19:06:27128 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]5c4824e12013-01-12 16:34:53129}
130
[email protected]adeda572014-01-31 00:49:47131LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const {
132 return inner_viewport_scroll_layer_;
133}
[email protected]3b31c6ac2012-12-06 21:27:29134
[email protected]adeda572014-01-31 00:49:47135LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const {
136 return outer_viewport_scroll_layer_;
137}
[email protected]1960a712013-04-30 17:06:47138
[email protected]adeda572014-01-31 00:49:47139gfx::Vector2dF LayerTreeImpl::TotalScrollOffset() const {
140 gfx::Vector2dF offset;
[email protected]3b31c6ac2012-12-06 21:27:29141
[email protected]adeda572014-01-31 00:49:47142 if (inner_viewport_scroll_layer_)
143 offset += inner_viewport_scroll_layer_->TotalScrollOffset();
144
145 if (outer_viewport_scroll_layer_)
146 offset += outer_viewport_scroll_layer_->TotalScrollOffset();
147
148 return offset;
149}
150
151gfx::Vector2dF LayerTreeImpl::TotalMaxScrollOffset() const {
152 gfx::Vector2dF offset;
153
154 if (inner_viewport_scroll_layer_)
155 offset += inner_viewport_scroll_layer_->MaxScrollOffset();
156
157 if (outer_viewport_scroll_layer_)
158 offset += outer_viewport_scroll_layer_->MaxScrollOffset();
159
160 return offset;
161}
162gfx::Vector2dF LayerTreeImpl::TotalScrollDelta() const {
163 DCHECK(inner_viewport_scroll_layer_);
164 gfx::Vector2dF delta = inner_viewport_scroll_layer_->ScrollDelta();
165
166 if (outer_viewport_scroll_layer_)
167 delta += outer_viewport_scroll_layer_->ScrollDelta();
168
169 return delta;
[email protected]3b31c6ac2012-12-06 21:27:29170}
171
172scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
173 // Clear all data structures that have direct references to the layer tree.
174 scrolling_layer_id_from_previous_tree_ =
175 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]adeda572014-01-31 00:49:47176 if (inner_viewport_scroll_layer_)
177 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
178 if (outer_viewport_scroll_layer_)
179 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
180 inner_viewport_scroll_delegate_proxy_.reset();
181 outer_viewport_scroll_delegate_proxy_.reset();
182 inner_viewport_scroll_layer_ = NULL;
183 outer_viewport_scroll_layer_ = NULL;
184 page_scale_layer_ = NULL;
[email protected]3b31c6ac2012-12-06 21:27:29185 currently_scrolling_layer_ = NULL;
186
[email protected]76ffd9e2012-12-20 19:12:47187 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16188 set_needs_update_draw_properties();
[email protected]3b31c6ac2012-12-06 21:27:29189 return root_layer_.Pass();
190}
191
[email protected]7aba6662013-03-12 10:17:34192void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
[email protected]c9280762013-08-01 06:28:57193 // The request queue should have been processed and does not require a push.
194 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
195
[email protected]7d08a9352013-10-15 08:24:56196 if (next_activation_forces_redraw_) {
[email protected]12a63da2014-06-13 06:06:22197 target_tree->ForceRedrawNextActivation();
[email protected]7d08a9352013-10-15 08:24:56198 next_activation_forces_redraw_ = false;
199 }
200
[email protected]b69c1db2013-11-27 00:05:19201 target_tree->PassSwapPromises(&swap_promise_list_);
202
[email protected]d6021f6a2014-06-12 21:15:24203 target_tree->SetPageScaleValues(
204 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor(),
[email protected]c60279472013-01-30 12:10:51205 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta());
206 target_tree->set_sent_page_scale_delta(1);
207
[email protected]adeda572014-01-31 00:49:47208 if (page_scale_layer_ && inner_viewport_scroll_layer_) {
[email protected]57ac9482013-09-17 21:13:39209 target_tree->SetViewportLayersFromIds(
210 page_scale_layer_->id(),
211 inner_viewport_scroll_layer_->id(),
212 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
213 : Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47214 } else {
215 target_tree->ClearViewportLayers();
[email protected]57ac9482013-09-17 21:13:39216 }
[email protected]19aec372014-07-01 19:08:49217
[email protected]ebb179b2014-07-16 17:54:41218 target_tree->RegisterSelection(selection_start_, selection_end_);
[email protected]19aec372014-07-01 19:08:49219
[email protected]c60279472013-01-30 12:10:51220 // This should match the property synchronization in
221 // LayerTreeHost::finishCommitOnImplThread().
222 target_tree->set_source_frame_number(source_frame_number());
223 target_tree->set_background_color(background_color());
224 target_tree->set_has_transparent_background(has_transparent_background());
225
226 if (ContentsTexturesPurged())
227 target_tree->SetContentsTexturesPurged();
228 else
229 target_tree->ResetContentsTexturesPurged();
230
[email protected]318822852013-02-14 00:54:27231 if (ViewportSizeInvalid())
232 target_tree->SetViewportSizeInvalid();
233 else
234 target_tree->ResetViewportSizeInvalid();
235
[email protected]c60279472013-01-30 12:10:51236 if (hud_layer())
237 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
[email protected]6ba914122013-03-22 16:26:39238 LayerTreeHostCommon::FindLayerInSubtree(
[email protected]c1bb5af2013-03-13 19:06:27239 target_tree->root_layer(), hud_layer()->id())));
[email protected]c60279472013-01-30 12:10:51240 else
241 target_tree->set_hud_layer(NULL);
[email protected]759dc9f2014-07-23 19:18:51242
243 target_tree->has_ever_been_drawn_ = false;
[email protected]c60279472013-01-30 12:10:51244}
245
[email protected]fef74fd2014-02-27 06:28:17246LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const {
247 return inner_viewport_scroll_layer_
248 ? inner_viewport_scroll_layer_->scroll_clip_layer()
249 : NULL;
[email protected]ffb2720f2013-03-15 19:18:37250}
251
252LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
[email protected]69b50ec2013-01-19 04:58:01253 DCHECK(IsActiveTree());
254 return currently_scrolling_layer_;
255}
256
[email protected]0fc818e2013-03-18 06:45:20257void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
258 if (currently_scrolling_layer_ == layer)
259 return;
260
261 if (currently_scrolling_layer_ &&
262 currently_scrolling_layer_->scrollbar_animation_controller())
[email protected]1dc06162014-03-26 22:54:45263 currently_scrolling_layer_->scrollbar_animation_controller()
[email protected]930ff43b2014-05-02 05:24:00264 ->DidScrollEnd();
[email protected]0fc818e2013-03-18 06:45:20265 currently_scrolling_layer_ = layer;
266 if (layer && layer->scrollbar_animation_controller())
[email protected]930ff43b2014-05-02 05:24:00267 layer->scrollbar_animation_controller()->DidScrollBegin();
[email protected]0fc818e2013-03-18 06:45:20268}
269
[email protected]3b31c6ac2012-12-06 21:27:29270void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
[email protected]0fc818e2013-03-18 06:45:20271 SetCurrentlyScrollingLayer(NULL);
[email protected]3b31c6ac2012-12-06 21:27:29272 scrolling_layer_id_from_previous_tree_ = 0;
273}
274
[email protected]1f15bed2014-03-11 02:50:44275float LayerTreeImpl::VerticalAdjust(const int clip_layer_id) const {
276 LayerImpl* container_layer = InnerViewportContainerLayer();
277 if (!container_layer || clip_layer_id != container_layer->id())
[email protected]adeda572014-01-31 00:49:47278 return 0.f;
279
[email protected]fef74fd2014-02-27 06:28:17280 return layer_tree_host_impl_->VerticalAdjust();
[email protected]adeda572014-01-31 00:49:47281}
282
283namespace {
284
285void ForceScrollbarParameterUpdateAfterScaleChange(LayerImpl* current_layer) {
286 if (!current_layer)
287 return;
288
289 while (current_layer) {
290 current_layer->ScrollbarParametersDidChange();
291 current_layer = current_layer->parent();
292 }
293}
294
295} // namespace
296
[email protected]c60279472013-01-30 12:10:51297void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
[email protected]3c0a3252013-03-18 04:24:36298 float min_page_scale_factor, float max_page_scale_factor) {
[email protected]d6021f6a2014-06-12 21:15:24299 SetPageScaleValues(page_scale_factor, min_page_scale_factor,
300 max_page_scale_factor, page_scale_delta_);
301}
[email protected]c60279472013-01-30 12:10:51302
[email protected]d6021f6a2014-06-12 21:15:24303void LayerTreeImpl::SetPageScaleDelta(float delta) {
304 SetPageScaleValues(page_scale_factor_, min_page_scale_factor_,
305 max_page_scale_factor_, delta);
306}
307
308void LayerTreeImpl::SetPageScaleValues(float page_scale_factor,
309 float min_page_scale_factor, float max_page_scale_factor,
310 float page_scale_delta) {
311 bool page_scale_changed =
312 min_page_scale_factor != min_page_scale_factor_ ||
313 max_page_scale_factor != max_page_scale_factor_ ||
314 page_scale_factor != page_scale_factor_;
[email protected]7265e74e2014-02-07 23:43:06315
[email protected]c60279472013-01-30 12:10:51316 min_page_scale_factor_ = min_page_scale_factor;
317 max_page_scale_factor_ = max_page_scale_factor;
318 page_scale_factor_ = page_scale_factor;
[email protected]20d2b742013-09-26 05:41:34319
[email protected]d6021f6a2014-06-12 21:15:24320 float total = page_scale_factor_ * page_scale_delta;
321 if (min_page_scale_factor_ && total < min_page_scale_factor_)
322 page_scale_delta = min_page_scale_factor_ / page_scale_factor_;
323 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
324 page_scale_delta = max_page_scale_factor_ / page_scale_factor_;
325
326 if (page_scale_delta_ == page_scale_delta && !page_scale_changed)
327 return;
328
329 if (page_scale_delta_ != page_scale_delta) {
330 page_scale_delta_ = page_scale_delta;
331
332 if (IsActiveTree()) {
333 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
334 if (pending_tree) {
335 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
336 pending_tree->SetPageScaleDelta(
337 page_scale_delta_ / sent_page_scale_delta_);
338 }
339 }
340
341 set_needs_update_draw_properties();
342 }
343
[email protected]22f200a2013-10-09 18:08:29344 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00345 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
346 TotalScrollOffset(),
347 TotalMaxScrollOffset(),
348 ScrollableSize(),
[email protected]68fe60f2014-02-12 13:49:11349 total_page_scale_factor(),
[email protected]d6021f6a2014-06-12 21:15:24350 min_page_scale_factor_,
351 max_page_scale_factor_);
[email protected]22f200a2013-10-09 18:08:29352 }
[email protected]adeda572014-01-31 00:49:47353
354 ForceScrollbarParameterUpdateAfterScaleChange(page_scale_layer());
[email protected]c60279472013-01-30 12:10:51355}
356
[email protected]257abfa82013-01-29 23:47:24357gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]adeda572014-01-31 00:49:47358 if (outer_viewport_scroll_layer_)
359 return layer_tree_host_impl_->UnscaledScrollableViewportSize();
360 else
361 return gfx::ScaleSize(
362 layer_tree_host_impl_->UnscaledScrollableViewportSize(),
363 1.0f / total_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24364}
365
[email protected]3744e27b2013-11-06 21:44:08366gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const {
[email protected]adeda572014-01-31 00:49:47367 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
368 ? OuterViewportScrollLayer()
369 : InnerViewportScrollLayer();
370 if (!root_scroll_layer || root_scroll_layer->children().empty())
[email protected]3744e27b2013-11-06 21:44:08371 return gfx::Rect();
[email protected]adeda572014-01-31 00:49:47372 LayerImpl* layer = root_scroll_layer->children()[0];
[email protected]8a822692014-02-12 17:30:55373 return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(),
374 gfx::Rect(layer->content_bounds()));
[email protected]3744e27b2013-11-06 21:44:08375}
376
[email protected]58241dc2013-08-20 01:39:25377static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) {
378 layer->ApplySentScrollDeltasFromAbortedCommit();
[email protected]3519b872013-07-30 07:17:50379}
380
[email protected]58241dc2013-08-20 01:39:25381void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50382 DCHECK(IsActiveTree());
383
384 page_scale_factor_ *= sent_page_scale_delta_;
385 page_scale_delta_ /= sent_page_scale_delta_;
386 sent_page_scale_delta_ = 1.f;
387
388 if (!root_layer())
389 return;
390
391 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]58241dc2013-08-20 01:39:25392 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo));
393}
394
[email protected]daea3d42013-10-23 17:04:50395static void ApplyScrollDeltasSinceBeginMainFrameTo(LayerImpl* layer) {
396 layer->ApplyScrollDeltasSinceBeginMainFrame();
[email protected]58241dc2013-08-20 01:39:25397}
398
[email protected]daea3d42013-10-23 17:04:50399void LayerTreeImpl::ApplyScrollDeltasSinceBeginMainFrame() {
[email protected]58241dc2013-08-20 01:39:25400 DCHECK(IsPendingTree());
401 if (!root_layer())
402 return;
403
404 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]daea3d42013-10-23 17:04:50405 root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginMainFrameTo));
[email protected]3519b872013-07-30 07:17:50406}
407
[email protected]57ac9482013-09-17 21:13:39408void LayerTreeImpl::SetViewportLayersFromIds(
409 int page_scale_layer_id,
410 int inner_viewport_scroll_layer_id,
411 int outer_viewport_scroll_layer_id) {
412 page_scale_layer_ = LayerById(page_scale_layer_id);
413 DCHECK(page_scale_layer_);
414
415 inner_viewport_scroll_layer_ =
416 LayerById(inner_viewport_scroll_layer_id);
417 DCHECK(inner_viewport_scroll_layer_);
418
419 outer_viewport_scroll_layer_ =
420 LayerById(outer_viewport_scroll_layer_id);
421 DCHECK(outer_viewport_scroll_layer_ ||
422 outer_viewport_scroll_layer_id == Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47423
424 if (!root_layer_scroll_offset_delegate_)
425 return;
426
427 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
428 new LayerScrollOffsetDelegateProxy(inner_viewport_scroll_layer_,
429 root_layer_scroll_offset_delegate_,
430 this));
431
432 if (outer_viewport_scroll_layer_)
433 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
434 new LayerScrollOffsetDelegateProxy(outer_viewport_scroll_layer_,
435 root_layer_scroll_offset_delegate_,
436 this));
[email protected]57ac9482013-09-17 21:13:39437}
438
439void LayerTreeImpl::ClearViewportLayers() {
440 page_scale_layer_ = NULL;
441 inner_viewport_scroll_layer_ = NULL;
442 outer_viewport_scroll_layer_ = NULL;
443}
444
[email protected]8f7f298822014-06-13 00:23:32445bool LayerTreeImpl::UpdateDrawProperties() {
446 if (!needs_update_draw_properties_)
447 return true;
[email protected]615c78a2013-01-24 23:44:16448
[email protected]ed511b8d2013-03-25 03:29:29449 // For max_texture_size.
[email protected]615c78a2013-01-24 23:44:16450 if (!layer_tree_host_impl_->renderer())
[email protected]8f7f298822014-06-13 00:23:32451 return false;
[email protected]615c78a2013-01-24 23:44:16452
[email protected]c1bb5af2013-03-13 19:06:27453 if (!root_layer())
[email protected]8f7f298822014-06-13 00:23:32454 return false;
455
456 needs_update_draw_properties_ = false;
457 render_surface_layer_list_.clear();
[email protected]76ffd9e2012-12-20 19:12:47458
[email protected]76ffd9e2012-12-20 19:12:47459 {
[email protected]7a52f43e2013-07-10 01:58:47460 TRACE_EVENT2("cc",
[email protected]c1bb5af2013-03-13 19:06:27461 "LayerTreeImpl::UpdateDrawProperties",
462 "IsActive",
[email protected]7a52f43e2013-07-10 01:58:47463 IsActiveTree(),
464 "SourceFrameNumber",
465 source_frame_number_);
[email protected]57ac9482013-09-17 21:13:39466 LayerImpl* page_scale_layer =
[email protected]fef74fd2014-02-27 06:28:17467 page_scale_layer_ ? page_scale_layer_ : InnerViewportContainerLayer();
[email protected]c05dfbb2014-07-10 22:49:04468 bool can_render_to_separate_surface = !resourceless_software_draw();
[email protected]390bb1ff2014-05-09 17:14:40469
470 ++render_surface_layer_list_id_;
[email protected]7aad55f2013-07-26 11:25:53471 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
[email protected]c1bb5af2013-03-13 19:06:27472 root_layer(),
[email protected]54af03522013-09-05 00:43:28473 DrawViewportSize(),
474 layer_tree_host_impl_->DrawTransform(),
[email protected]76ffd9e2012-12-20 19:12:47475 device_scale_factor(),
[email protected]c60279472013-01-30 12:10:51476 total_page_scale_factor(),
[email protected]57ac9482013-09-17 21:13:39477 page_scale_layer,
[email protected]f6776532012-12-21 20:24:33478 MaxTextureSize(),
[email protected]8e0176d2013-03-21 03:14:52479 settings().can_use_lcd_text,
[email protected]45948712013-09-27 02:46:48480 can_render_to_separate_surface,
[email protected]35a99a12013-05-09 23:52:29481 settings().layer_transforms_should_scale_layer_contents,
[email protected]390bb1ff2014-05-09 17:14:40482 &render_surface_layer_list_,
483 render_surface_layer_list_id_);
[email protected]7aad55f2013-07-26 11:25:53484 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]76ffd9e2012-12-20 19:12:47485 }
[email protected]615c78a2013-01-24 23:44:16486
[email protected]e4be0262013-10-19 16:54:28487 {
488 TRACE_EVENT2("cc",
489 "LayerTreeImpl::UpdateTilePriorities",
490 "IsActive",
491 IsActiveTree(),
492 "SourceFrameNumber",
493 source_frame_number_);
[email protected]562b7ad2014-06-23 22:17:11494 scoped_ptr<OcclusionTracker<LayerImpl> > occlusion_tracker;
495 if (settings().use_occlusion_for_tile_prioritization) {
496 occlusion_tracker.reset(new OcclusionTracker<LayerImpl>(
497 root_layer()->render_surface()->content_rect()));
498 occlusion_tracker->set_minimum_tracking_size(
499 settings().minimum_occlusion_tracking_size);
500 }
501
[email protected]e4be0262013-10-19 16:54:28502 // LayerIterator is used here instead of CallFunctionForSubtree to only
503 // UpdateTilePriorities on layers that will be visible (and thus have valid
504 // draw properties) and not because any ordering is required.
[email protected]ba1b33e2014-02-28 16:44:51505 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]e4be0262013-10-19 16:54:28506 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
507 for (LayerIteratorType it =
508 LayerIteratorType::Begin(&render_surface_layer_list_);
509 it != end;
510 ++it) {
[email protected]562b7ad2014-06-23 22:17:11511 if (occlusion_tracker)
512 occlusion_tracker->EnterLayer(it);
513
[email protected]e4be0262013-10-19 16:54:28514 LayerImpl* layer = *it;
[email protected]6355d2d2014-05-07 15:07:27515 if (it.represents_itself())
[email protected]562b7ad2014-06-23 22:17:11516 layer->UpdateTiles(occlusion_tracker.get());
[email protected]e4be0262013-10-19 16:54:28517
[email protected]562b7ad2014-06-23 22:17:11518 if (!it.represents_contributing_render_surface()) {
519 if (occlusion_tracker)
520 occlusion_tracker->LeaveLayer(it);
[email protected]6355d2d2014-05-07 15:07:27521 continue;
[email protected]562b7ad2014-06-23 22:17:11522 }
[email protected]6355d2d2014-05-07 15:07:27523
[email protected]e4be0262013-10-19 16:54:28524 if (layer->mask_layer())
[email protected]562b7ad2014-06-23 22:17:11525 layer->mask_layer()->UpdateTiles(occlusion_tracker.get());
[email protected]e4be0262013-10-19 16:54:28526 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
[email protected]562b7ad2014-06-23 22:17:11527 layer->replica_layer()->mask_layer()->UpdateTiles(
528 occlusion_tracker.get());
529
530 if (occlusion_tracker)
531 occlusion_tracker->LeaveLayer(it);
[email protected]e4be0262013-10-19 16:54:28532 }
533 }
534
[email protected]615c78a2013-01-24 23:44:16535 DCHECK(!needs_update_draw_properties_) <<
[email protected]7d19dc342013-05-02 22:02:04536 "CalcDrawProperties should not set_needs_update_draw_properties()";
[email protected]8f7f298822014-06-13 00:23:32537 return true;
[email protected]76ffd9e2012-12-20 19:12:47538}
539
[email protected]50761e92013-03-29 20:51:28540const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const {
[email protected]76ffd9e2012-12-20 19:12:47541 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16542 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47543 return render_surface_layer_list_;
544}
545
[email protected]42ccdbef2013-01-21 07:54:54546gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]adeda572014-01-31 00:49:47547 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
548 ? OuterViewportScrollLayer()
549 : InnerViewportScrollLayer();
550 if (!root_scroll_layer || root_scroll_layer->children().empty())
[email protected]caa567d2012-12-20 07:56:16551 return gfx::Size();
[email protected]adeda572014-01-31 00:49:47552 return root_scroll_layer->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16553}
554
[email protected]361bc00d2012-12-14 07:03:24555LayerImpl* LayerTreeImpl::LayerById(int id) {
556 LayerIdMap::iterator iter = layer_id_map_.find(id);
557 return iter != layer_id_map_.end() ? iter->second : NULL;
558}
559
560void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
561 DCHECK(!LayerById(layer->id()));
562 layer_id_map_[layer->id()] = layer;
563}
564
565void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
566 DCHECK(LayerById(layer->id()));
567 layer_id_map_.erase(layer->id());
568}
569
[email protected]aebf4622014-07-14 16:57:59570size_t LayerTreeImpl::NumLayers() {
571 return layer_id_map_.size();
572}
573
[email protected]ed511b8d2013-03-25 03:29:29574void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) {
[email protected]a90fac72013-06-06 18:56:13575 pending_tree->SetCurrentlyScrollingLayer(
576 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(),
577 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0));
[email protected]1e0f8d62013-01-09 07:41:35578}
579
[email protected]ff1211d2013-06-07 01:58:35580static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34581 layer->DidBecomeActive();
[email protected]db2e29c2014-08-06 05:58:25582 if (layer->mask_layer())
583 layer->mask_layer()->DidBecomeActive();
584 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
585 layer->replica_layer()->mask_layer()->DidBecomeActive();
586
[email protected]ff1211d2013-06-07 01:58:35587 for (size_t i = 0; i < layer->children().size(); ++i)
588 DidBecomeActiveRecursive(layer->children()[i]);
[email protected]37386f052013-01-13 00:42:22589}
590
591void LayerTreeImpl::DidBecomeActive() {
[email protected]12a63da2014-06-13 06:06:22592 if (next_activation_forces_redraw_) {
593 layer_tree_host_impl_->SetFullRootLayerDamage();
594 next_activation_forces_redraw_ = false;
595 }
596
[email protected]adeda572014-01-31 00:49:47597 if (scrolling_layer_id_from_previous_tree_) {
598 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
[email protected]7dcf5632014-06-25 01:11:55599 root_layer(), scrolling_layer_id_from_previous_tree_);
[email protected]adeda572014-01-31 00:49:47600 }
601
[email protected]7dcf5632014-06-25 01:11:55602 // Always reset this flag on activation, as we would only have activated
603 // if we were in a good state.
604 ResetRequiresHighResToDraw();
605
606 if (root_layer())
607 DidBecomeActiveRecursive(root_layer());
608
[email protected]12a63da2014-06-13 06:06:22609 devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(),
610 source_frame_number_);
[email protected]37386f052013-01-13 00:42:22611}
612
[email protected]6f90b9e2013-01-17 23:42:00613bool LayerTreeImpl::ContentsTexturesPurged() const {
614 return contents_textures_purged_;
615}
616
617void LayerTreeImpl::SetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04618 if (contents_textures_purged_)
619 return;
[email protected]6f90b9e2013-01-17 23:42:00620 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27621 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00622}
623
624void LayerTreeImpl::ResetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04625 if (!contents_textures_purged_)
626 return;
[email protected]6f90b9e2013-01-17 23:42:00627 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27628 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00629}
630
[email protected]3d609bb2014-02-01 01:10:23631void LayerTreeImpl::SetRequiresHighResToDraw() {
632 requires_high_res_to_draw_ = true;
633}
634
635void LayerTreeImpl::ResetRequiresHighResToDraw() {
636 requires_high_res_to_draw_ = false;
637}
638
639bool LayerTreeImpl::RequiresHighResToDraw() const {
640 return requires_high_res_to_draw_;
641}
642
[email protected]318822852013-02-14 00:54:27643bool LayerTreeImpl::ViewportSizeInvalid() const {
644 return viewport_size_invalid_;
645}
646
647void LayerTreeImpl::SetViewportSizeInvalid() {
648 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27649 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27650}
651
652void LayerTreeImpl::ResetViewportSizeInvalid() {
653 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27654 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27655}
656
[email protected]48871fc2013-01-23 07:36:51657Proxy* LayerTreeImpl::proxy() const {
658 return layer_tree_host_impl_->proxy();
659}
660
[email protected]ff762fb2012-12-12 19:18:37661const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27662 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37663}
664
[email protected]7a8bcd262014-01-15 12:54:58665const RendererCapabilitiesImpl& LayerTreeImpl::GetRendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27666 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52667}
668
[email protected]0634cdd42013-08-16 00:46:09669ContextProvider* LayerTreeImpl::context_provider() const {
670 return output_surface()->context_provider();
671}
672
[email protected]ff762fb2012-12-12 19:18:37673OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27674 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37675}
676
677ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27678 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37679}
680
681TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27682 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37683}
684
685FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27686 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37687}
688
[email protected]71691c22013-01-18 03:14:22689PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27690 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22691}
692
[email protected]1191d9d2013-02-02 06:00:33693MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27694 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33695}
696
[email protected]c05dfbb2014-07-10 22:49:04697bool LayerTreeImpl::resourceless_software_draw() const {
698 return layer_tree_host_impl_->GetDrawMode() ==
699 DRAW_MODE_RESOURCELESS_SOFTWARE;
[email protected]54af03522013-09-05 00:43:28700}
701
[email protected]4a6c091d2014-04-24 21:06:46702gfx::Size LayerTreeImpl::device_viewport_size() const {
703 return layer_tree_host_impl_->device_viewport_size();
704}
705
[email protected]f117a4c2012-12-16 04:53:10706bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27707 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10708}
709
710bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27711 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10712}
713
[email protected]48871fc2013-01-23 07:36:51714bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27715 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51716}
717
[email protected]f117a4c2012-12-16 04:53:10718LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27719 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10720 if (!tree)
721 return NULL;
722 return tree->LayerById(id);
723}
724
725LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27726 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10727 if (!tree)
728 return NULL;
729 return tree->LayerById(id);
730}
731
[email protected]71618ed2014-07-24 02:23:45732LayerImpl* LayerTreeImpl::FindRecycleTreeLayerById(int id) {
733 LayerTreeImpl* tree = layer_tree_host_impl_->recycle_tree();
734 if (!tree)
735 return NULL;
736 return tree->LayerById(id);
737}
738
[email protected]f6776532012-12-21 20:24:33739int LayerTreeImpl::MaxTextureSize() const {
[email protected]c1bb5af2013-03-13 19:06:27740 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size;
[email protected]f6776532012-12-21 20:24:33741}
742
[email protected]166db5c82013-01-09 23:54:31743bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27744 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31745}
746
[email protected]04c5900d2014-08-18 13:38:36747BeginFrameArgs LayerTreeImpl::CurrentBeginFrameArgs() const {
748 return layer_tree_host_impl_->CurrentBeginFrameArgs();
[email protected]fb7425a2013-04-22 16:28:55749}
750
[email protected]c92195e2014-05-07 18:18:49751base::TimeDelta LayerTreeImpl::begin_impl_frame_interval() const {
752 return layer_tree_host_impl_->begin_impl_frame_interval();
753}
754
[email protected]d7eb8c72013-03-23 22:57:13755void LayerTreeImpl::SetNeedsCommit() {
756 layer_tree_host_impl_->SetNeedsCommit();
757}
758
[email protected]bd5324592014-07-31 09:09:33759gfx::Rect LayerTreeImpl::DeviceViewport() const {
760 return layer_tree_host_impl_->DeviceViewport();
761}
762
[email protected]54af03522013-09-05 00:43:28763gfx::Size LayerTreeImpl::DrawViewportSize() const {
764 return layer_tree_host_impl_->DrawViewportSize();
765}
766
[email protected]bd5324592014-07-31 09:09:33767const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const {
768 return layer_tree_host_impl_->ViewportRectForTilePriority();
769}
770
[email protected]930ff43b2014-05-02 05:24:00771scoped_ptr<ScrollbarAnimationController>
772LayerTreeImpl::CreateScrollbarAnimationController(LayerImpl* scrolling_layer) {
773 DCHECK(settings().scrollbar_fade_delay_ms);
774 DCHECK(settings().scrollbar_fade_duration_ms);
775 base::TimeDelta delay =
776 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms);
777 base::TimeDelta duration =
778 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms);
779 switch (settings().scrollbar_animator) {
780 case LayerTreeSettings::LinearFade: {
781 return ScrollbarAnimationControllerLinearFade::Create(
782 scrolling_layer, layer_tree_host_impl_, delay, duration)
783 .PassAs<ScrollbarAnimationController>();
784 }
785 case LayerTreeSettings::Thinning: {
786 return ScrollbarAnimationControllerThinning::Create(
787 scrolling_layer, layer_tree_host_impl_, delay, duration)
788 .PassAs<ScrollbarAnimationController>();
789 }
790 case LayerTreeSettings::NoAnimator:
791 NOTREACHED();
792 break;
793 }
794 return scoped_ptr<ScrollbarAnimationController>();
[email protected]2ea5aba2013-09-11 14:26:56795}
796
[email protected]b8384e22013-12-03 02:20:48797void LayerTreeImpl::DidAnimateScrollOffset() {
798 layer_tree_host_impl_->DidAnimateScrollOffset();
799}
800
[email protected]13525d62014-05-20 21:22:04801bool LayerTreeImpl::use_gpu_rasterization() const {
802 return layer_tree_host_impl_->use_gpu_rasterization();
803}
804
[email protected]473f1f22014-05-22 08:19:17805bool LayerTreeImpl::create_low_res_tiling() const {
806 return layer_tree_host_impl_->create_low_res_tiling();
807}
808
[email protected]ff762fb2012-12-12 19:18:37809void LayerTreeImpl::SetNeedsRedraw() {
[email protected]59adb112013-04-09 04:48:44810 layer_tree_host_impl_->SetNeedsRedraw();
[email protected]ff762fb2012-12-12 19:18:37811}
812
[email protected]ff762fb2012-12-12 19:18:37813const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27814 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37815}
816
817float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27818 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37819}
820
[email protected]ff762fb2012-12-12 19:18:37821DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27822 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37823}
824
[email protected]de4afb5e2012-12-20 00:11:34825AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27826 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34827}
[email protected]ff762fb2012-12-12 19:18:37828
[email protected]d12aa932014-08-01 13:10:38829void LayerTreeImpl::AsValueInto(base::debug::TracedValue* state) const {
830 TracedValue::MakeDictIntoImplicitSnapshot(state, "cc::LayerTreeImpl", this);
[email protected]f6742f52013-05-08 23:52:22831
[email protected]d12aa932014-08-01 13:10:38832 state->BeginDictionary("root_layer");
833 root_layer_->AsValueInto(state);
834 state->EndDictionary();
[email protected]f6742f52013-05-08 23:52:22835
[email protected]d12aa932014-08-01 13:10:38836 state->BeginArray("render_surface_layer_list");
[email protected]ba1b33e2014-02-28 16:44:51837 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09838 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
839 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]8c5690222013-02-15 17:36:43840 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09841 if (!it.represents_itself())
[email protected]8c5690222013-02-15 17:36:43842 continue;
[email protected]d12aa932014-08-01 13:10:38843 TracedValue::AppendIDRef(*it, state);
[email protected]8c5690222013-02-15 17:36:43844 }
[email protected]d12aa932014-08-01 13:10:38845 state->EndArray();
[email protected]8c5690222013-02-15 17:36:43846}
847
[email protected]1960a712013-04-30 17:06:47848void LayerTreeImpl::SetRootLayerScrollOffsetDelegate(
[email protected]c9280762013-08-01 06:28:57849 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
[email protected]20d2b742013-09-26 05:41:34850 if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate)
851 return;
852
[email protected]adeda572014-01-31 00:49:47853 if (!root_layer_scroll_offset_delegate) {
854 // Make sure we remove the proxies from their layers before
855 // releasing them.
856 if (InnerViewportScrollLayer())
857 InnerViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
858 if (OuterViewportScrollLayer())
859 OuterViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
860 inner_viewport_scroll_delegate_proxy_.reset();
861 outer_viewport_scroll_delegate_proxy_.reset();
[email protected]d35cd7b22014-01-29 14:32:46862 }
863
[email protected]adeda572014-01-31 00:49:47864 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
865
[email protected]20d2b742013-09-26 05:41:34866 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00867 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
868 TotalScrollOffset(),
869 TotalMaxScrollOffset(),
870 ScrollableSize(),
[email protected]68fe60f2014-02-12 13:49:11871 total_page_scale_factor(),
872 min_page_scale_factor(),
873 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47874
875 if (inner_viewport_scroll_layer_) {
876 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
877 new LayerScrollOffsetDelegateProxy(InnerViewportScrollLayer(),
878 root_layer_scroll_offset_delegate_,
879 this));
880 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(
881 inner_viewport_scroll_delegate_proxy_.get());
882 }
883
884 if (outer_viewport_scroll_layer_) {
885 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
886 new LayerScrollOffsetDelegateProxy(OuterViewportScrollLayer(),
887 root_layer_scroll_offset_delegate_,
888 this));
889 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(
890 outer_viewport_scroll_delegate_proxy_.get());
891 }
[email protected]20d2b742013-09-26 05:41:34892 }
[email protected]1960a712013-04-30 17:06:47893}
894
[email protected]adeda572014-01-31 00:49:47895void LayerTreeImpl::UpdateScrollOffsetDelegate() {
896 DCHECK(InnerViewportScrollLayer());
897 DCHECK(root_layer_scroll_offset_delegate_);
898
899 gfx::Vector2dF offset =
900 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
901
902 if (OuterViewportScrollLayer())
903 offset += outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
904
[email protected]ec2322e2014-05-15 16:32:00905 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
906 offset,
907 TotalMaxScrollOffset(),
908 ScrollableSize(),
909 total_page_scale_factor(),
910 min_page_scale_factor(),
911 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47912}
913
914gfx::Vector2dF LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) {
915 DCHECK(root_layer_scroll_offset_delegate_);
916 DCHECK(InnerViewportScrollLayer());
917 if (layer == InnerViewportScrollLayer() && !OuterViewportScrollLayer())
918 return root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
919
920 // If we get here, we have both inner/outer viewports, and need to distribute
921 // the scroll offset between them.
922 DCHECK(inner_viewport_scroll_delegate_proxy_);
923 DCHECK(outer_viewport_scroll_delegate_proxy_);
924 gfx::Vector2dF inner_viewport_offset =
925 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
926 gfx::Vector2dF outer_viewport_offset =
927 outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
928
929 // It may be nothing has changed.
930 gfx::Vector2dF delegate_offset =
931 root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
932 if (inner_viewport_offset + outer_viewport_offset == delegate_offset) {
933 if (layer == InnerViewportScrollLayer())
934 return inner_viewport_offset;
935 else
936 return outer_viewport_offset;
937 }
938
939 gfx::Vector2d max_outer_viewport_scroll_offset =
940 OuterViewportScrollLayer()->MaxScrollOffset();
941
942 outer_viewport_offset = delegate_offset - inner_viewport_offset;
943 outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset);
944 outer_viewport_offset.SetToMax(gfx::Vector2d());
945
946 if (layer == OuterViewportScrollLayer())
947 return outer_viewport_offset;
948
949 inner_viewport_offset = delegate_offset - outer_viewport_offset;
950
951 return inner_viewport_offset;
952}
953
[email protected]b69c1db2013-11-27 00:05:19954void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) {
955 DCHECK(swap_promise);
[email protected]b69c1db2013-11-27 00:05:19956 swap_promise_list_.push_back(swap_promise.Pass());
957}
958
959void LayerTreeImpl::PassSwapPromises(
960 ScopedPtrVector<SwapPromise>* new_swap_promise) {
961 swap_promise_list_.insert_and_take(swap_promise_list_.end(),
962 *new_swap_promise);
963 new_swap_promise->clear();
964}
965
[email protected]d359203a2013-11-29 06:16:55966void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) {
[email protected]b69c1db2013-11-27 00:05:19967 for (size_t i = 0; i < swap_promise_list_.size(); i++)
[email protected]d359203a2013-11-29 06:16:55968 swap_promise_list_[i]->DidSwap(metadata);
[email protected]b69c1db2013-11-27 00:05:19969 swap_promise_list_.clear();
970}
971
972void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) {
973 for (size_t i = 0; i < swap_promise_list_.size(); i++)
974 swap_promise_list_[i]->DidNotSwap(reason);
975 swap_promise_list_.clear();
976}
977
[email protected]c48536a52013-09-14 00:02:08978void LayerTreeImpl::DidModifyTilePriorities() {
979 layer_tree_host_impl_->DidModifyTilePriorities();
[email protected]fcb846d2013-05-22 01:42:36980}
981
[email protected]c9280762013-08-01 06:28:57982void LayerTreeImpl::set_ui_resource_request_queue(
983 const UIResourceRequestQueue& queue) {
984 ui_resource_request_queue_ = queue;
985}
986
987ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource(
988 UIResourceId uid) const {
989 return layer_tree_host_impl_->ResourceIdForUIResource(uid);
990}
991
[email protected]709c9542013-10-26 01:43:51992bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const {
993 return layer_tree_host_impl_->IsUIResourceOpaque(uid);
994}
995
[email protected]c9280762013-08-01 06:28:57996void LayerTreeImpl::ProcessUIResourceRequestQueue() {
997 while (ui_resource_request_queue_.size() > 0) {
998 UIResourceRequest req = ui_resource_request_queue_.front();
999 ui_resource_request_queue_.pop_front();
1000
[email protected]741fba422013-09-20 03:34:141001 switch (req.GetType()) {
[email protected]c9280762013-08-01 06:28:571002 case UIResourceRequest::UIResourceCreate:
[email protected]741fba422013-09-20 03:34:141003 layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap());
[email protected]c9280762013-08-01 06:28:571004 break;
1005 case UIResourceRequest::UIResourceDelete:
[email protected]741fba422013-09-20 03:34:141006 layer_tree_host_impl_->DeleteUIResource(req.GetId());
[email protected]c9280762013-08-01 06:28:571007 break;
[email protected]f28d64d2013-08-27 04:17:451008 case UIResourceRequest::UIResourceInvalidRequest:
[email protected]c9280762013-08-01 06:28:571009 NOTREACHED();
1010 break;
1011 }
1012 }
[email protected]127bdc1a2013-09-11 01:44:481013
1014 // If all UI resource evictions were not recreated by processing this queue,
1015 // then another commit is required.
1016 if (layer_tree_host_impl_->EvictedUIResourcesExist())
1017 layer_tree_host_impl_->SetNeedsCommit();
[email protected]c9280762013-08-01 06:28:571018}
1019
[email protected]30fe19ff2013-07-04 00:54:451020void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) {
1021 // Only the active tree needs to know about layers with copy requests, as
1022 // they are aborted if not serviced during draw.
1023 DCHECK(IsActiveTree());
1024
[email protected]a4ee12812014-02-06 17:33:381025 // DCHECK(std::find(layers_with_copy_output_request_.begin(),
1026 // layers_with_copy_output_request_.end(),
1027 // layer) == layers_with_copy_output_request_.end());
1028 // TODO(danakj): Remove this once crash is found crbug.com/309777
1029 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1030 CHECK(layers_with_copy_output_request_[i] != layer)
1031 << i << " of " << layers_with_copy_output_request_.size();
1032 }
[email protected]30fe19ff2013-07-04 00:54:451033 layers_with_copy_output_request_.push_back(layer);
1034}
1035
1036void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) {
1037 // Only the active tree needs to know about layers with copy requests, as
1038 // they are aborted if not serviced during draw.
1039 DCHECK(IsActiveTree());
1040
1041 std::vector<LayerImpl*>::iterator it = std::find(
1042 layers_with_copy_output_request_.begin(),
1043 layers_with_copy_output_request_.end(),
1044 layer);
1045 DCHECK(it != layers_with_copy_output_request_.end());
[email protected]f5de9e5b2013-07-30 22:26:571046 layers_with_copy_output_request_.erase(it);
[email protected]a4ee12812014-02-06 17:33:381047
1048 // TODO(danakj): Remove this once crash is found crbug.com/309777
1049 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1050 CHECK(layers_with_copy_output_request_[i] != layer)
1051 << i << " of " << layers_with_copy_output_request_.size();
1052 }
[email protected]30fe19ff2013-07-04 00:54:451053}
1054
[email protected]53526372013-12-07 04:31:501055const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest()
[email protected]30fe19ff2013-07-04 00:54:451056 const {
1057 // Only the active tree needs to know about layers with copy requests, as
1058 // they are aborted if not serviced during draw.
1059 DCHECK(IsActiveTree());
1060
1061 return layers_with_copy_output_request_;
1062}
1063
[email protected]aeef2f02014-05-10 12:15:481064void LayerTreeImpl::ReleaseResourcesRecursive(LayerImpl* current) {
1065 DCHECK(current);
1066 current->ReleaseResources();
1067 if (current->mask_layer())
1068 ReleaseResourcesRecursive(current->mask_layer());
1069 if (current->replica_layer())
1070 ReleaseResourcesRecursive(current->replica_layer());
1071 for (size_t i = 0; i < current->children().size(); ++i)
1072 ReleaseResourcesRecursive(current->children()[i]);
1073}
1074
[email protected]28336d52014-05-12 19:07:281075template <typename LayerType>
1076static inline bool LayerClipsSubtree(LayerType* layer) {
1077 return layer->masks_to_bounds() || layer->mask_layer();
1078}
1079
1080static bool PointHitsRect(
1081 const gfx::PointF& screen_space_point,
1082 const gfx::Transform& local_space_to_screen_space_transform,
1083 const gfx::RectF& local_space_rect,
1084 float* distance_to_camera) {
1085 // If the transform is not invertible, then assume that this point doesn't hit
1086 // this rect.
1087 gfx::Transform inverse_local_space_to_screen_space(
1088 gfx::Transform::kSkipInitialization);
1089 if (!local_space_to_screen_space_transform.GetInverse(
1090 &inverse_local_space_to_screen_space))
1091 return false;
1092
1093 // Transform the hit test point from screen space to the local space of the
1094 // given rect.
1095 bool clipped = false;
1096 gfx::Point3F planar_point = MathUtil::ProjectPoint3D(
1097 inverse_local_space_to_screen_space, screen_space_point, &clipped);
1098 gfx::PointF hit_test_point_in_local_space =
1099 gfx::PointF(planar_point.x(), planar_point.y());
1100
1101 // If ProjectPoint could not project to a valid value, then we assume that
1102 // this point doesn't hit this rect.
1103 if (clipped)
1104 return false;
1105
1106 if (!local_space_rect.Contains(hit_test_point_in_local_space))
1107 return false;
1108
1109 if (distance_to_camera) {
1110 // To compute the distance to the camera, we have to take the planar point
1111 // and pull it back to world space and compute the displacement along the
1112 // z-axis.
1113 gfx::Point3F planar_point_in_screen_space(planar_point);
1114 local_space_to_screen_space_transform.TransformPoint(
1115 &planar_point_in_screen_space);
1116 *distance_to_camera = planar_point_in_screen_space.z();
1117 }
1118
1119 return true;
1120}
1121
1122static bool PointHitsRegion(const gfx::PointF& screen_space_point,
1123 const gfx::Transform& screen_space_transform,
1124 const Region& layer_space_region,
1125 float layer_content_scale_x,
1126 float layer_content_scale_y) {
1127 // If the transform is not invertible, then assume that this point doesn't hit
1128 // this region.
1129 gfx::Transform inverse_screen_space_transform(
1130 gfx::Transform::kSkipInitialization);
1131 if (!screen_space_transform.GetInverse(&inverse_screen_space_transform))
1132 return false;
1133
1134 // Transform the hit test point from screen space to the local space of the
1135 // given region.
1136 bool clipped = false;
1137 gfx::PointF hit_test_point_in_content_space = MathUtil::ProjectPoint(
1138 inverse_screen_space_transform, screen_space_point, &clipped);
1139 gfx::PointF hit_test_point_in_layer_space =
1140 gfx::ScalePoint(hit_test_point_in_content_space,
1141 1.f / layer_content_scale_x,
1142 1.f / layer_content_scale_y);
1143
1144 // If ProjectPoint could not project to a valid value, then we assume that
1145 // this point doesn't hit this region.
1146 if (clipped)
1147 return false;
1148
1149 return layer_space_region.Contains(
1150 gfx::ToRoundedPoint(hit_test_point_in_layer_space));
1151}
1152
[email protected]19aec372014-07-01 19:08:491153static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) {
[email protected]0ec86f52014-06-12 20:54:031154 if (layer->scroll_parent())
1155 return layer->scroll_parent();
1156 if (layer->clip_parent())
1157 return layer->clip_parent();
1158 return layer->parent();
1159}
1160
[email protected]28336d52014-05-12 19:07:281161static bool PointIsClippedBySurfaceOrClipRect(
1162 const gfx::PointF& screen_space_point,
[email protected]19aec372014-07-01 19:08:491163 const LayerImpl* layer) {
[email protected]28336d52014-05-12 19:07:281164 // Walk up the layer tree and hit-test any render_surfaces and any layer
1165 // clip rects that are active.
[email protected]0ec86f52014-06-12 20:54:031166 for (; layer; layer = GetNextClippingLayer(layer)) {
1167 if (layer->render_surface() &&
1168 !PointHitsRect(screen_space_point,
1169 layer->render_surface()->screen_space_transform(),
1170 layer->render_surface()->content_rect(),
1171 NULL))
[email protected]28336d52014-05-12 19:07:281172 return true;
1173
[email protected]0ec86f52014-06-12 20:54:031174 if (LayerClipsSubtree(layer) &&
1175 !PointHitsRect(screen_space_point,
1176 layer->screen_space_transform(),
1177 gfx::Rect(layer->content_bounds()),
1178 NULL))
[email protected]28336d52014-05-12 19:07:281179 return true;
[email protected]28336d52014-05-12 19:07:281180 }
1181
1182 // If we have finished walking all ancestors without having already exited,
1183 // then the point is not clipped by any ancestors.
1184 return false;
1185}
1186
[email protected]19aec372014-07-01 19:08:491187static bool PointHitsLayer(const LayerImpl* layer,
[email protected]28336d52014-05-12 19:07:281188 const gfx::PointF& screen_space_point,
1189 float* distance_to_intersection) {
1190 gfx::RectF content_rect(layer->content_bounds());
1191 if (!PointHitsRect(screen_space_point,
1192 layer->screen_space_transform(),
1193 content_rect,
1194 distance_to_intersection))
1195 return false;
1196
1197 // At this point, we think the point does hit the layer, but we need to walk
1198 // up the parents to ensure that the layer was not clipped in such a way
1199 // that the hit point actually should not hit the layer.
1200 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer))
1201 return false;
1202
1203 // Skip the HUD layer.
1204 if (layer == layer->layer_tree_impl()->hud_layer())
1205 return false;
1206
1207 return true;
1208}
1209
1210struct FindClosestMatchingLayerDataForRecursion {
1211 FindClosestMatchingLayerDataForRecursion()
1212 : closest_match(NULL),
1213 closest_distance(-std::numeric_limits<float>::infinity()) {}
1214 LayerImpl* closest_match;
1215 // Note that the positive z-axis points towards the camera, so bigger means
1216 // closer in this case, counterintuitively.
1217 float closest_distance;
1218};
1219
1220template <typename Functor>
1221static void FindClosestMatchingLayer(
1222 const gfx::PointF& screen_space_point,
1223 LayerImpl* layer,
1224 const Functor& func,
1225 FindClosestMatchingLayerDataForRecursion* data_for_recursion) {
1226 for (int i = layer->children().size() - 1; i >= 0; --i) {
1227 FindClosestMatchingLayer(
1228 screen_space_point, layer->children()[i], func, data_for_recursion);
1229 }
1230
1231 float distance_to_intersection = 0.f;
1232 if (func(layer) &&
1233 PointHitsLayer(layer, screen_space_point, &distance_to_intersection) &&
1234 ((!data_for_recursion->closest_match ||
1235 distance_to_intersection > data_for_recursion->closest_distance))) {
1236 data_for_recursion->closest_distance = distance_to_intersection;
1237 data_for_recursion->closest_match = layer;
1238 }
1239}
1240
1241static bool ScrollsAnyDrawnRenderSurfaceLayerListMember(LayerImpl* layer) {
1242 if (!layer->scrollable())
1243 return false;
1244 if (layer->IsDrawnRenderSurfaceLayerListMember())
1245 return true;
1246 if (!layer->scroll_children())
1247 return false;
1248 for (std::set<LayerImpl*>::const_iterator it =
1249 layer->scroll_children()->begin();
1250 it != layer->scroll_children()->end();
1251 ++it) {
1252 if ((*it)->IsDrawnRenderSurfaceLayerListMember())
1253 return true;
1254 }
1255 return false;
1256}
1257
1258struct FindScrollingLayerFunctor {
1259 bool operator()(LayerImpl* layer) const {
1260 return ScrollsAnyDrawnRenderSurfaceLayerListMember(layer);
1261 }
1262};
1263
1264LayerImpl* LayerTreeImpl::FindFirstScrollingLayerThatIsHitByPoint(
1265 const gfx::PointF& screen_space_point) {
1266 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1267 FindClosestMatchingLayer(screen_space_point,
1268 root_layer(),
1269 FindScrollingLayerFunctor(),
1270 &data_for_recursion);
1271 return data_for_recursion.closest_match;
1272}
1273
1274struct HitTestVisibleScrollableOrTouchableFunctor {
1275 bool operator()(LayerImpl* layer) const {
1276 return layer->IsDrawnRenderSurfaceLayerListMember() ||
1277 ScrollsAnyDrawnRenderSurfaceLayerListMember(layer) ||
1278 !layer->touch_event_handler_region().IsEmpty() ||
1279 layer->have_wheel_event_handlers();
1280 }
1281};
1282
1283LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPoint(
1284 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321285 if (!root_layer())
1286 return NULL;
1287 if (!UpdateDrawProperties())
1288 return NULL;
[email protected]28336d52014-05-12 19:07:281289 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1290 FindClosestMatchingLayer(screen_space_point,
1291 root_layer(),
1292 HitTestVisibleScrollableOrTouchableFunctor(),
1293 &data_for_recursion);
1294 return data_for_recursion.closest_match;
1295}
1296
1297static bool LayerHasTouchEventHandlersAt(const gfx::PointF& screen_space_point,
1298 LayerImpl* layer_impl) {
1299 if (layer_impl->touch_event_handler_region().IsEmpty())
1300 return false;
1301
1302 if (!PointHitsRegion(screen_space_point,
1303 layer_impl->screen_space_transform(),
1304 layer_impl->touch_event_handler_region(),
1305 layer_impl->contents_scale_x(),
1306 layer_impl->contents_scale_y()))
1307 return false;
1308
1309 // At this point, we think the point does hit the touch event handler region
1310 // on the layer, but we need to walk up the parents to ensure that the layer
1311 // was not clipped in such a way that the hit point actually should not hit
1312 // the layer.
1313 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
1314 return false;
1315
1316 return true;
1317}
1318
1319struct FindTouchEventLayerFunctor {
1320 bool operator()(LayerImpl* layer) const {
1321 return LayerHasTouchEventHandlersAt(screen_space_point, layer);
1322 }
1323 const gfx::PointF screen_space_point;
1324};
1325
1326LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion(
1327 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321328 if (!root_layer())
1329 return NULL;
1330 if (!UpdateDrawProperties())
1331 return NULL;
[email protected]28336d52014-05-12 19:07:281332 FindTouchEventLayerFunctor func = {screen_space_point};
1333 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1334 FindClosestMatchingLayer(
1335 screen_space_point, root_layer(), func, &data_for_recursion);
1336 return data_for_recursion.closest_match;
1337}
1338
[email protected]ebb179b2014-07-16 17:54:411339void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& start,
1340 const LayerSelectionBound& end) {
1341 selection_start_ = start;
1342 selection_end_ = end;
[email protected]19aec372014-07-01 19:08:491343}
1344
1345static ViewportSelectionBound ComputeViewportSelection(
1346 const LayerSelectionBound& bound,
1347 LayerImpl* layer,
1348 float device_scale_factor) {
1349 ViewportSelectionBound result;
1350 result.type = bound.type;
1351
1352 if (!layer || bound.type == SELECTION_BOUND_EMPTY)
1353 return result;
1354
1355 gfx::RectF layer_scaled_rect = gfx::ScaleRect(
1356 bound.layer_rect, layer->contents_scale_x(), layer->contents_scale_y());
1357 gfx::RectF screen_rect = MathUtil::ProjectClippedRect(
1358 layer->screen_space_transform(), layer_scaled_rect);
1359
1360 // The bottom left of the bound is used for visibility because 1) the bound
1361 // edge rect is one-dimensional (no width), and 2) the bottom is the logical
1362 // focal point for bound selection handles (this may change in the future).
1363 const gfx::PointF& visibility_point = screen_rect.bottom_left();
1364 float intersect_distance = 0.f;
1365 result.visible = PointHitsLayer(layer, visibility_point, &intersect_distance);
1366
1367 screen_rect.Scale(1.f / device_scale_factor);
1368 result.viewport_rect = screen_rect;
1369
1370 return result;
1371}
1372
[email protected]ebb179b2014-07-16 17:54:411373void LayerTreeImpl::GetViewportSelection(ViewportSelectionBound* start,
1374 ViewportSelectionBound* end) {
1375 DCHECK(start);
1376 DCHECK(end);
[email protected]19aec372014-07-01 19:08:491377
[email protected]ebb179b2014-07-16 17:54:411378 *start = ComputeViewportSelection(
1379 selection_start_,
1380 selection_start_.layer_id ? LayerById(selection_start_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491381 device_scale_factor());
[email protected]ebb179b2014-07-16 17:54:411382 if (start->type == SELECTION_BOUND_CENTER ||
1383 start->type == SELECTION_BOUND_EMPTY) {
1384 *end = *start;
[email protected]19aec372014-07-01 19:08:491385 } else {
[email protected]ebb179b2014-07-16 17:54:411386 *end = ComputeViewportSelection(
1387 selection_end_,
1388 selection_end_.layer_id ? LayerById(selection_end_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491389 device_scale_factor());
1390 }
1391}
1392
[email protected]8aa39ecb2014-06-12 14:19:141393void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) {
1394 layer_tree_host_impl_->RegisterPictureLayerImpl(layer);
1395}
1396
1397void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
1398 layer_tree_host_impl_->UnregisterPictureLayerImpl(layer);
1399}
1400
[email protected]749cbc62014-07-10 01:06:351401void LayerTreeImpl::InputScrollAnimationFinished() {
1402 layer_tree_host_impl_->ScrollEnd();
1403}
1404
[email protected]ca2902e92013-03-28 01:45:351405} // namespace cc