blob: 392e80b658b041d71e09d53b63a164c90917945e [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]95e4e1a02013-03-18 07:09:0911#include "cc/animation/keyframed_animation_curve.h"
12#include "cc/animation/scrollbar_animation_controller.h"
[email protected]930ff43b2014-05-02 05:24:0013#include "cc/animation/scrollbar_animation_controller_linear_fade.h"
14#include "cc/animation/scrollbar_animation_controller_thinning.h"
[email protected]3744e27b2013-11-06 21:44:0815#include "cc/base/math_util.h"
16#include "cc/base/util.h"
[email protected]12a63da2014-06-13 06:06:2217#include "cc/debug/devtools_instrumentation.h"
[email protected]f6742f52013-05-08 23:52:2218#include "cc/debug/traced_value.h"
[email protected]cc3cfaa2013-03-18 09:05:5219#include "cc/layers/heads_up_display_layer_impl.h"
[email protected]57ac9482013-09-17 21:13:3920#include "cc/layers/layer.h"
[email protected]34ba1ffb2014-03-05 06:55:0321#include "cc/layers/layer_iterator.h"
[email protected]50761e92013-03-29 20:51:2822#include "cc/layers/render_surface_impl.h"
[email protected]80413d72013-08-30 20:25:3323#include "cc/layers/scrollbar_layer_impl_base.h"
[email protected]e1042192013-11-08 05:44:2424#include "cc/resources/ui_resource_request.h"
[email protected]556fd292013-03-18 08:03:0425#include "cc/trees/layer_tree_host_common.h"
26#include "cc/trees/layer_tree_host_impl.h"
[email protected]562b7ad2014-06-23 22:17:1127#include "cc/trees/occlusion_tracker.h"
[email protected]28336d52014-05-12 19:07:2828#include "ui/gfx/point_conversions.h"
[email protected]ffb2720f2013-03-15 19:18:3729#include "ui/gfx/size_conversions.h"
[email protected]caa567d2012-12-20 07:56:1630#include "ui/gfx/vector2d_conversions.h"
[email protected]3b31c6ac2012-12-06 21:27:2931
32namespace cc {
33
[email protected]adeda572014-01-31 00:49:4734// This class exists to split the LayerScrollOffsetDelegate between the
35// InnerViewportScrollLayer and the OuterViewportScrollLayer in a manner
36// that never requires the embedder or LayerImpl to know about.
[email protected]ec2322e2014-05-15 16:32:0037class LayerScrollOffsetDelegateProxy : public LayerImpl::ScrollOffsetDelegate {
[email protected]adeda572014-01-31 00:49:4738 public:
39 LayerScrollOffsetDelegateProxy(LayerImpl* layer,
40 LayerScrollOffsetDelegate* delegate,
41 LayerTreeImpl* layer_tree)
42 : layer_(layer), delegate_(delegate), layer_tree_impl_(layer_tree) {}
[email protected]ec2322e2014-05-15 16:32:0043 virtual ~LayerScrollOffsetDelegateProxy() {}
[email protected]adeda572014-01-31 00:49:4744
45 gfx::Vector2dF last_set_scroll_offset() const {
46 return last_set_scroll_offset_;
47 }
48
49 // LayerScrollOffsetDelegate implementation.
[email protected]adeda572014-01-31 00:49:4750 virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_offset) OVERRIDE {
51 last_set_scroll_offset_ = new_offset;
52 layer_tree_impl_->UpdateScrollOffsetDelegate();
53 }
54
55 virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE {
56 return layer_tree_impl_->GetDelegatedScrollOffset(layer_);
57 }
58
59 virtual bool IsExternalFlingActive() const OVERRIDE {
60 return delegate_->IsExternalFlingActive();
61 }
62
[email protected]adeda572014-01-31 00:49:4763 private:
64 LayerImpl* layer_;
65 LayerScrollOffsetDelegate* delegate_;
66 LayerTreeImpl* layer_tree_impl_;
67 gfx::Vector2dF last_set_scroll_offset_;
68};
69
[email protected]8bef40572012-12-11 21:38:0870LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl)
[email protected]db8259f2013-02-01 05:25:0471 : layer_tree_host_impl_(layer_tree_host_impl),
72 source_frame_number_(-1),
73 hud_layer_(0),
[email protected]1960a712013-04-30 17:06:4774 currently_scrolling_layer_(NULL),
75 root_layer_scroll_offset_delegate_(NULL),
[email protected]db8259f2013-02-01 05:25:0476 background_color_(0),
77 has_transparent_background_(false),
[email protected]57ac9482013-09-17 21:13:3978 page_scale_layer_(NULL),
79 inner_viewport_scroll_layer_(NULL),
80 outer_viewport_scroll_layer_(NULL),
[email protected]db8259f2013-02-01 05:25:0481 page_scale_factor_(1),
82 page_scale_delta_(1),
83 sent_page_scale_delta_(1),
84 min_page_scale_factor_(0),
85 max_page_scale_factor_(0),
86 scrolling_layer_id_from_previous_tree_(0),
87 contents_textures_purged_(false),
[email protected]3d609bb2014-02-01 01:10:2388 requires_high_res_to_draw_(false),
[email protected]318822852013-02-14 00:54:2789 viewport_size_invalid_(false),
[email protected]db8259f2013-02-01 05:25:0490 needs_update_draw_properties_(true),
[email protected]7d08a9352013-10-15 08:24:5691 needs_full_tree_sync_(true),
[email protected]390bb1ff2014-05-09 17:14:4092 next_activation_forces_redraw_(false),
93 render_surface_layer_list_id_(0) {
94}
[email protected]3b31c6ac2012-12-06 21:27:2995
96LayerTreeImpl::~LayerTreeImpl() {
[email protected]361bc00d2012-12-14 07:03:2497 // Need to explicitly clear the tree prior to destroying this so that
98 // the LayerTreeImpl pointer is still valid in the LayerImpl dtor.
[email protected]df17af52014-02-06 02:20:4099 DCHECK(!root_layer_);
100 DCHECK(layers_with_copy_output_request_.empty());
[email protected]3b31c6ac2012-12-06 21:27:29101}
102
[email protected]df17af52014-02-06 02:20:40103void LayerTreeImpl::Shutdown() { root_layer_.reset(); }
104
[email protected]aeef2f02014-05-10 12:15:48105void LayerTreeImpl::ReleaseResources() {
106 if (root_layer_)
107 ReleaseResourcesRecursive(root_layer_.get());
108}
109
[email protected]d35cd7b22014-01-29 14:32:46110void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) {
[email protected]adeda572014-01-31 00:49:47111 if (inner_viewport_scroll_layer_)
112 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
113 if (outer_viewport_scroll_layer_)
114 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
115 inner_viewport_scroll_delegate_proxy_.reset();
116 outer_viewport_scroll_delegate_proxy_.reset();
117
[email protected]3b31c6ac2012-12-06 21:27:29118 root_layer_ = layer.Pass();
[email protected]5c4824e12013-01-12 16:34:53119 currently_scrolling_layer_ = NULL;
[email protected]adeda572014-01-31 00:49:47120 inner_viewport_scroll_layer_ = NULL;
121 outer_viewport_scroll_layer_ = NULL;
122 page_scale_layer_ = NULL;
[email protected]5c4824e12013-01-12 16:34:53123
[email protected]c1bb5af2013-03-13 19:06:27124 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]5c4824e12013-01-12 16:34:53125}
126
[email protected]adeda572014-01-31 00:49:47127LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const {
128 return inner_viewport_scroll_layer_;
129}
[email protected]3b31c6ac2012-12-06 21:27:29130
[email protected]adeda572014-01-31 00:49:47131LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const {
132 return outer_viewport_scroll_layer_;
133}
[email protected]1960a712013-04-30 17:06:47134
[email protected]adeda572014-01-31 00:49:47135gfx::Vector2dF LayerTreeImpl::TotalScrollOffset() const {
136 gfx::Vector2dF offset;
[email protected]3b31c6ac2012-12-06 21:27:29137
[email protected]adeda572014-01-31 00:49:47138 if (inner_viewport_scroll_layer_)
139 offset += inner_viewport_scroll_layer_->TotalScrollOffset();
140
141 if (outer_viewport_scroll_layer_)
142 offset += outer_viewport_scroll_layer_->TotalScrollOffset();
143
144 return offset;
145}
146
147gfx::Vector2dF LayerTreeImpl::TotalMaxScrollOffset() const {
148 gfx::Vector2dF offset;
149
150 if (inner_viewport_scroll_layer_)
151 offset += inner_viewport_scroll_layer_->MaxScrollOffset();
152
153 if (outer_viewport_scroll_layer_)
154 offset += outer_viewport_scroll_layer_->MaxScrollOffset();
155
156 return offset;
157}
158gfx::Vector2dF LayerTreeImpl::TotalScrollDelta() const {
159 DCHECK(inner_viewport_scroll_layer_);
160 gfx::Vector2dF delta = inner_viewport_scroll_layer_->ScrollDelta();
161
162 if (outer_viewport_scroll_layer_)
163 delta += outer_viewport_scroll_layer_->ScrollDelta();
164
165 return delta;
[email protected]3b31c6ac2012-12-06 21:27:29166}
167
168scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() {
169 // Clear all data structures that have direct references to the layer tree.
170 scrolling_layer_id_from_previous_tree_ =
171 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0;
[email protected]adeda572014-01-31 00:49:47172 if (inner_viewport_scroll_layer_)
173 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
174 if (outer_viewport_scroll_layer_)
175 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL);
176 inner_viewport_scroll_delegate_proxy_.reset();
177 outer_viewport_scroll_delegate_proxy_.reset();
178 inner_viewport_scroll_layer_ = NULL;
179 outer_viewport_scroll_layer_ = NULL;
180 page_scale_layer_ = NULL;
[email protected]3b31c6ac2012-12-06 21:27:29181 currently_scrolling_layer_ = NULL;
182
[email protected]76ffd9e2012-12-20 19:12:47183 render_surface_layer_list_.clear();
[email protected]615c78a2013-01-24 23:44:16184 set_needs_update_draw_properties();
[email protected]3b31c6ac2012-12-06 21:27:29185 return root_layer_.Pass();
186}
187
[email protected]7aba6662013-03-12 10:17:34188void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) {
[email protected]c9280762013-08-01 06:28:57189 // The request queue should have been processed and does not require a push.
190 DCHECK_EQ(ui_resource_request_queue_.size(), 0u);
191
[email protected]7d08a9352013-10-15 08:24:56192 if (next_activation_forces_redraw_) {
[email protected]12a63da2014-06-13 06:06:22193 target_tree->ForceRedrawNextActivation();
[email protected]7d08a9352013-10-15 08:24:56194 next_activation_forces_redraw_ = false;
195 }
196
[email protected]b69c1db2013-11-27 00:05:19197 target_tree->PassSwapPromises(&swap_promise_list_);
198
[email protected]d6021f6a2014-06-12 21:15:24199 target_tree->SetPageScaleValues(
200 page_scale_factor(), min_page_scale_factor(), max_page_scale_factor(),
[email protected]c60279472013-01-30 12:10:51201 target_tree->page_scale_delta() / target_tree->sent_page_scale_delta());
202 target_tree->set_sent_page_scale_delta(1);
203
[email protected]adeda572014-01-31 00:49:47204 if (page_scale_layer_ && inner_viewport_scroll_layer_) {
[email protected]57ac9482013-09-17 21:13:39205 target_tree->SetViewportLayersFromIds(
206 page_scale_layer_->id(),
207 inner_viewport_scroll_layer_->id(),
208 outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id()
209 : Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47210 } else {
211 target_tree->ClearViewportLayers();
[email protected]57ac9482013-09-17 21:13:39212 }
[email protected]19aec372014-07-01 19:08:49213
[email protected]ebb179b2014-07-16 17:54:41214 target_tree->RegisterSelection(selection_start_, selection_end_);
[email protected]19aec372014-07-01 19:08:49215
[email protected]c60279472013-01-30 12:10:51216 // This should match the property synchronization in
217 // LayerTreeHost::finishCommitOnImplThread().
218 target_tree->set_source_frame_number(source_frame_number());
219 target_tree->set_background_color(background_color());
220 target_tree->set_has_transparent_background(has_transparent_background());
221
222 if (ContentsTexturesPurged())
223 target_tree->SetContentsTexturesPurged();
224 else
225 target_tree->ResetContentsTexturesPurged();
226
[email protected]318822852013-02-14 00:54:27227 if (ViewportSizeInvalid())
228 target_tree->SetViewportSizeInvalid();
229 else
230 target_tree->ResetViewportSizeInvalid();
231
[email protected]c60279472013-01-30 12:10:51232 if (hud_layer())
233 target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>(
[email protected]6ba914122013-03-22 16:26:39234 LayerTreeHostCommon::FindLayerInSubtree(
[email protected]c1bb5af2013-03-13 19:06:27235 target_tree->root_layer(), hud_layer()->id())));
[email protected]c60279472013-01-30 12:10:51236 else
237 target_tree->set_hud_layer(NULL);
238}
239
[email protected]fef74fd2014-02-27 06:28:17240LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const {
241 return inner_viewport_scroll_layer_
242 ? inner_viewport_scroll_layer_->scroll_clip_layer()
243 : NULL;
[email protected]ffb2720f2013-03-15 19:18:37244}
245
246LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const {
[email protected]69b50ec2013-01-19 04:58:01247 DCHECK(IsActiveTree());
248 return currently_scrolling_layer_;
249}
250
[email protected]0fc818e2013-03-18 06:45:20251void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) {
252 if (currently_scrolling_layer_ == layer)
253 return;
254
255 if (currently_scrolling_layer_ &&
256 currently_scrolling_layer_->scrollbar_animation_controller())
[email protected]1dc06162014-03-26 22:54:45257 currently_scrolling_layer_->scrollbar_animation_controller()
[email protected]930ff43b2014-05-02 05:24:00258 ->DidScrollEnd();
[email protected]0fc818e2013-03-18 06:45:20259 currently_scrolling_layer_ = layer;
260 if (layer && layer->scrollbar_animation_controller())
[email protected]930ff43b2014-05-02 05:24:00261 layer->scrollbar_animation_controller()->DidScrollBegin();
[email protected]0fc818e2013-03-18 06:45:20262}
263
[email protected]3b31c6ac2012-12-06 21:27:29264void LayerTreeImpl::ClearCurrentlyScrollingLayer() {
[email protected]0fc818e2013-03-18 06:45:20265 SetCurrentlyScrollingLayer(NULL);
[email protected]3b31c6ac2012-12-06 21:27:29266 scrolling_layer_id_from_previous_tree_ = 0;
267}
268
[email protected]1f15bed2014-03-11 02:50:44269float LayerTreeImpl::VerticalAdjust(const int clip_layer_id) const {
270 LayerImpl* container_layer = InnerViewportContainerLayer();
271 if (!container_layer || clip_layer_id != container_layer->id())
[email protected]adeda572014-01-31 00:49:47272 return 0.f;
273
[email protected]fef74fd2014-02-27 06:28:17274 return layer_tree_host_impl_->VerticalAdjust();
[email protected]adeda572014-01-31 00:49:47275}
276
277namespace {
278
279void ForceScrollbarParameterUpdateAfterScaleChange(LayerImpl* current_layer) {
280 if (!current_layer)
281 return;
282
283 while (current_layer) {
284 current_layer->ScrollbarParametersDidChange();
285 current_layer = current_layer->parent();
286 }
287}
288
289} // namespace
290
[email protected]c60279472013-01-30 12:10:51291void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor,
[email protected]3c0a3252013-03-18 04:24:36292 float min_page_scale_factor, float max_page_scale_factor) {
[email protected]d6021f6a2014-06-12 21:15:24293 SetPageScaleValues(page_scale_factor, min_page_scale_factor,
294 max_page_scale_factor, page_scale_delta_);
295}
[email protected]c60279472013-01-30 12:10:51296
[email protected]d6021f6a2014-06-12 21:15:24297void LayerTreeImpl::SetPageScaleDelta(float delta) {
298 SetPageScaleValues(page_scale_factor_, min_page_scale_factor_,
299 max_page_scale_factor_, delta);
300}
301
302void LayerTreeImpl::SetPageScaleValues(float page_scale_factor,
303 float min_page_scale_factor, float max_page_scale_factor,
304 float page_scale_delta) {
305 bool page_scale_changed =
306 min_page_scale_factor != min_page_scale_factor_ ||
307 max_page_scale_factor != max_page_scale_factor_ ||
308 page_scale_factor != page_scale_factor_;
[email protected]7265e74e2014-02-07 23:43:06309
[email protected]c60279472013-01-30 12:10:51310 min_page_scale_factor_ = min_page_scale_factor;
311 max_page_scale_factor_ = max_page_scale_factor;
312 page_scale_factor_ = page_scale_factor;
[email protected]20d2b742013-09-26 05:41:34313
[email protected]d6021f6a2014-06-12 21:15:24314 float total = page_scale_factor_ * page_scale_delta;
315 if (min_page_scale_factor_ && total < min_page_scale_factor_)
316 page_scale_delta = min_page_scale_factor_ / page_scale_factor_;
317 else if (max_page_scale_factor_ && total > max_page_scale_factor_)
318 page_scale_delta = max_page_scale_factor_ / page_scale_factor_;
319
320 if (page_scale_delta_ == page_scale_delta && !page_scale_changed)
321 return;
322
323 if (page_scale_delta_ != page_scale_delta) {
324 page_scale_delta_ = page_scale_delta;
325
326 if (IsActiveTree()) {
327 LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree();
328 if (pending_tree) {
329 DCHECK_EQ(1, pending_tree->sent_page_scale_delta());
330 pending_tree->SetPageScaleDelta(
331 page_scale_delta_ / sent_page_scale_delta_);
332 }
333 }
334
335 set_needs_update_draw_properties();
336 }
337
[email protected]22f200a2013-10-09 18:08:29338 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00339 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
340 TotalScrollOffset(),
341 TotalMaxScrollOffset(),
342 ScrollableSize(),
[email protected]68fe60f2014-02-12 13:49:11343 total_page_scale_factor(),
[email protected]d6021f6a2014-06-12 21:15:24344 min_page_scale_factor_,
345 max_page_scale_factor_);
[email protected]22f200a2013-10-09 18:08:29346 }
[email protected]adeda572014-01-31 00:49:47347
348 ForceScrollbarParameterUpdateAfterScaleChange(page_scale_layer());
[email protected]c60279472013-01-30 12:10:51349}
350
[email protected]257abfa82013-01-29 23:47:24351gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const {
[email protected]adeda572014-01-31 00:49:47352 if (outer_viewport_scroll_layer_)
353 return layer_tree_host_impl_->UnscaledScrollableViewportSize();
354 else
355 return gfx::ScaleSize(
356 layer_tree_host_impl_->UnscaledScrollableViewportSize(),
357 1.0f / total_page_scale_factor());
[email protected]257abfa82013-01-29 23:47:24358}
359
[email protected]3744e27b2013-11-06 21:44:08360gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const {
[email protected]adeda572014-01-31 00:49:47361 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
362 ? OuterViewportScrollLayer()
363 : InnerViewportScrollLayer();
364 if (!root_scroll_layer || root_scroll_layer->children().empty())
[email protected]3744e27b2013-11-06 21:44:08365 return gfx::Rect();
[email protected]adeda572014-01-31 00:49:47366 LayerImpl* layer = root_scroll_layer->children()[0];
[email protected]8a822692014-02-12 17:30:55367 return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(),
368 gfx::Rect(layer->content_bounds()));
[email protected]3744e27b2013-11-06 21:44:08369}
370
[email protected]58241dc2013-08-20 01:39:25371static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) {
372 layer->ApplySentScrollDeltasFromAbortedCommit();
[email protected]3519b872013-07-30 07:17:50373}
374
[email protected]58241dc2013-08-20 01:39:25375void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50376 DCHECK(IsActiveTree());
377
378 page_scale_factor_ *= sent_page_scale_delta_;
379 page_scale_delta_ /= sent_page_scale_delta_;
380 sent_page_scale_delta_ = 1.f;
381
382 if (!root_layer())
383 return;
384
385 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]58241dc2013-08-20 01:39:25386 root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo));
387}
388
[email protected]daea3d42013-10-23 17:04:50389static void ApplyScrollDeltasSinceBeginMainFrameTo(LayerImpl* layer) {
390 layer->ApplyScrollDeltasSinceBeginMainFrame();
[email protected]58241dc2013-08-20 01:39:25391}
392
[email protected]daea3d42013-10-23 17:04:50393void LayerTreeImpl::ApplyScrollDeltasSinceBeginMainFrame() {
[email protected]58241dc2013-08-20 01:39:25394 DCHECK(IsPendingTree());
395 if (!root_layer())
396 return;
397
398 LayerTreeHostCommon::CallFunctionForSubtree(
[email protected]daea3d42013-10-23 17:04:50399 root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginMainFrameTo));
[email protected]3519b872013-07-30 07:17:50400}
401
[email protected]57ac9482013-09-17 21:13:39402void LayerTreeImpl::SetViewportLayersFromIds(
403 int page_scale_layer_id,
404 int inner_viewport_scroll_layer_id,
405 int outer_viewport_scroll_layer_id) {
406 page_scale_layer_ = LayerById(page_scale_layer_id);
407 DCHECK(page_scale_layer_);
408
409 inner_viewport_scroll_layer_ =
410 LayerById(inner_viewport_scroll_layer_id);
411 DCHECK(inner_viewport_scroll_layer_);
412
413 outer_viewport_scroll_layer_ =
414 LayerById(outer_viewport_scroll_layer_id);
415 DCHECK(outer_viewport_scroll_layer_ ||
416 outer_viewport_scroll_layer_id == Layer::INVALID_ID);
[email protected]adeda572014-01-31 00:49:47417
418 if (!root_layer_scroll_offset_delegate_)
419 return;
420
421 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
422 new LayerScrollOffsetDelegateProxy(inner_viewport_scroll_layer_,
423 root_layer_scroll_offset_delegate_,
424 this));
425
426 if (outer_viewport_scroll_layer_)
427 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
428 new LayerScrollOffsetDelegateProxy(outer_viewport_scroll_layer_,
429 root_layer_scroll_offset_delegate_,
430 this));
[email protected]57ac9482013-09-17 21:13:39431}
432
433void LayerTreeImpl::ClearViewportLayers() {
434 page_scale_layer_ = NULL;
435 inner_viewport_scroll_layer_ = NULL;
436 outer_viewport_scroll_layer_ = NULL;
437}
438
[email protected]8f7f298822014-06-13 00:23:32439bool LayerTreeImpl::UpdateDrawProperties() {
440 if (!needs_update_draw_properties_)
441 return true;
[email protected]615c78a2013-01-24 23:44:16442
[email protected]ed511b8d2013-03-25 03:29:29443 // For max_texture_size.
[email protected]615c78a2013-01-24 23:44:16444 if (!layer_tree_host_impl_->renderer())
[email protected]8f7f298822014-06-13 00:23:32445 return false;
[email protected]615c78a2013-01-24 23:44:16446
[email protected]c1bb5af2013-03-13 19:06:27447 if (!root_layer())
[email protected]8f7f298822014-06-13 00:23:32448 return false;
449
450 needs_update_draw_properties_ = false;
451 render_surface_layer_list_.clear();
[email protected]76ffd9e2012-12-20 19:12:47452
[email protected]76ffd9e2012-12-20 19:12:47453 {
[email protected]7a52f43e2013-07-10 01:58:47454 TRACE_EVENT2("cc",
[email protected]c1bb5af2013-03-13 19:06:27455 "LayerTreeImpl::UpdateDrawProperties",
456 "IsActive",
[email protected]7a52f43e2013-07-10 01:58:47457 IsActiveTree(),
458 "SourceFrameNumber",
459 source_frame_number_);
[email protected]57ac9482013-09-17 21:13:39460 LayerImpl* page_scale_layer =
[email protected]fef74fd2014-02-27 06:28:17461 page_scale_layer_ ? page_scale_layer_ : InnerViewportContainerLayer();
[email protected]c05dfbb2014-07-10 22:49:04462 bool can_render_to_separate_surface = !resourceless_software_draw();
[email protected]390bb1ff2014-05-09 17:14:40463
464 ++render_surface_layer_list_id_;
[email protected]7aad55f2013-07-26 11:25:53465 LayerTreeHostCommon::CalcDrawPropsImplInputs inputs(
[email protected]c1bb5af2013-03-13 19:06:27466 root_layer(),
[email protected]54af03522013-09-05 00:43:28467 DrawViewportSize(),
468 layer_tree_host_impl_->DrawTransform(),
[email protected]76ffd9e2012-12-20 19:12:47469 device_scale_factor(),
[email protected]c60279472013-01-30 12:10:51470 total_page_scale_factor(),
[email protected]57ac9482013-09-17 21:13:39471 page_scale_layer,
[email protected]f6776532012-12-21 20:24:33472 MaxTextureSize(),
[email protected]8e0176d2013-03-21 03:14:52473 settings().can_use_lcd_text,
[email protected]45948712013-09-27 02:46:48474 can_render_to_separate_surface,
[email protected]35a99a12013-05-09 23:52:29475 settings().layer_transforms_should_scale_layer_contents,
[email protected]390bb1ff2014-05-09 17:14:40476 &render_surface_layer_list_,
477 render_surface_layer_list_id_);
[email protected]7aad55f2013-07-26 11:25:53478 LayerTreeHostCommon::CalculateDrawProperties(&inputs);
[email protected]76ffd9e2012-12-20 19:12:47479 }
[email protected]615c78a2013-01-24 23:44:16480
[email protected]e4be0262013-10-19 16:54:28481 {
482 TRACE_EVENT2("cc",
483 "LayerTreeImpl::UpdateTilePriorities",
484 "IsActive",
485 IsActiveTree(),
486 "SourceFrameNumber",
487 source_frame_number_);
[email protected]562b7ad2014-06-23 22:17:11488 scoped_ptr<OcclusionTracker<LayerImpl> > occlusion_tracker;
489 if (settings().use_occlusion_for_tile_prioritization) {
490 occlusion_tracker.reset(new OcclusionTracker<LayerImpl>(
491 root_layer()->render_surface()->content_rect()));
492 occlusion_tracker->set_minimum_tracking_size(
493 settings().minimum_occlusion_tracking_size);
494 }
495
[email protected]e4be0262013-10-19 16:54:28496 // LayerIterator is used here instead of CallFunctionForSubtree to only
497 // UpdateTilePriorities on layers that will be visible (and thus have valid
498 // draw properties) and not because any ordering is required.
[email protected]ba1b33e2014-02-28 16:44:51499 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]e4be0262013-10-19 16:54:28500 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
501 for (LayerIteratorType it =
502 LayerIteratorType::Begin(&render_surface_layer_list_);
503 it != end;
504 ++it) {
[email protected]562b7ad2014-06-23 22:17:11505 if (occlusion_tracker)
506 occlusion_tracker->EnterLayer(it);
507
[email protected]e4be0262013-10-19 16:54:28508 LayerImpl* layer = *it;
[email protected]6355d2d2014-05-07 15:07:27509 if (it.represents_itself())
[email protected]562b7ad2014-06-23 22:17:11510 layer->UpdateTiles(occlusion_tracker.get());
[email protected]e4be0262013-10-19 16:54:28511
[email protected]562b7ad2014-06-23 22:17:11512 if (!it.represents_contributing_render_surface()) {
513 if (occlusion_tracker)
514 occlusion_tracker->LeaveLayer(it);
[email protected]6355d2d2014-05-07 15:07:27515 continue;
[email protected]562b7ad2014-06-23 22:17:11516 }
[email protected]6355d2d2014-05-07 15:07:27517
[email protected]e4be0262013-10-19 16:54:28518 if (layer->mask_layer())
[email protected]562b7ad2014-06-23 22:17:11519 layer->mask_layer()->UpdateTiles(occlusion_tracker.get());
[email protected]e4be0262013-10-19 16:54:28520 if (layer->replica_layer() && layer->replica_layer()->mask_layer())
[email protected]562b7ad2014-06-23 22:17:11521 layer->replica_layer()->mask_layer()->UpdateTiles(
522 occlusion_tracker.get());
523
524 if (occlusion_tracker)
525 occlusion_tracker->LeaveLayer(it);
[email protected]e4be0262013-10-19 16:54:28526 }
527 }
528
[email protected]615c78a2013-01-24 23:44:16529 DCHECK(!needs_update_draw_properties_) <<
[email protected]7d19dc342013-05-02 22:02:04530 "CalcDrawProperties should not set_needs_update_draw_properties()";
[email protected]8f7f298822014-06-13 00:23:32531 return true;
[email protected]76ffd9e2012-12-20 19:12:47532}
533
[email protected]50761e92013-03-29 20:51:28534const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const {
[email protected]76ffd9e2012-12-20 19:12:47535 // If this assert triggers, then the list is dirty.
[email protected]615c78a2013-01-24 23:44:16536 DCHECK(!needs_update_draw_properties_);
[email protected]76ffd9e2012-12-20 19:12:47537 return render_surface_layer_list_;
538}
539
[email protected]42ccdbef2013-01-21 07:54:54540gfx::Size LayerTreeImpl::ScrollableSize() const {
[email protected]adeda572014-01-31 00:49:47541 LayerImpl* root_scroll_layer = OuterViewportScrollLayer()
542 ? OuterViewportScrollLayer()
543 : InnerViewportScrollLayer();
544 if (!root_scroll_layer || root_scroll_layer->children().empty())
[email protected]caa567d2012-12-20 07:56:16545 return gfx::Size();
[email protected]adeda572014-01-31 00:49:47546 return root_scroll_layer->children()[0]->bounds();
[email protected]caa567d2012-12-20 07:56:16547}
548
[email protected]361bc00d2012-12-14 07:03:24549LayerImpl* LayerTreeImpl::LayerById(int id) {
550 LayerIdMap::iterator iter = layer_id_map_.find(id);
551 return iter != layer_id_map_.end() ? iter->second : NULL;
552}
553
554void LayerTreeImpl::RegisterLayer(LayerImpl* layer) {
555 DCHECK(!LayerById(layer->id()));
556 layer_id_map_[layer->id()] = layer;
557}
558
559void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) {
560 DCHECK(LayerById(layer->id()));
561 layer_id_map_.erase(layer->id());
562}
563
[email protected]aebf4622014-07-14 16:57:59564size_t LayerTreeImpl::NumLayers() {
565 return layer_id_map_.size();
566}
567
[email protected]ed511b8d2013-03-25 03:29:29568void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) {
[email protected]a90fac72013-06-06 18:56:13569 pending_tree->SetCurrentlyScrollingLayer(
570 LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(),
571 currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0));
[email protected]1e0f8d62013-01-09 07:41:35572}
573
[email protected]ff1211d2013-06-07 01:58:35574static void DidBecomeActiveRecursive(LayerImpl* layer) {
[email protected]7aba6662013-03-12 10:17:34575 layer->DidBecomeActive();
[email protected]ff1211d2013-06-07 01:58:35576 for (size_t i = 0; i < layer->children().size(); ++i)
577 DidBecomeActiveRecursive(layer->children()[i]);
[email protected]37386f052013-01-13 00:42:22578}
579
580void LayerTreeImpl::DidBecomeActive() {
[email protected]12a63da2014-06-13 06:06:22581 if (next_activation_forces_redraw_) {
582 layer_tree_host_impl_->SetFullRootLayerDamage();
583 next_activation_forces_redraw_ = false;
584 }
585
[email protected]adeda572014-01-31 00:49:47586 if (scrolling_layer_id_from_previous_tree_) {
587 currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree(
[email protected]7dcf5632014-06-25 01:11:55588 root_layer(), scrolling_layer_id_from_previous_tree_);
[email protected]adeda572014-01-31 00:49:47589 }
590
[email protected]7dcf5632014-06-25 01:11:55591 // Always reset this flag on activation, as we would only have activated
592 // if we were in a good state.
593 ResetRequiresHighResToDraw();
594
595 if (root_layer())
596 DidBecomeActiveRecursive(root_layer());
597
[email protected]12a63da2014-06-13 06:06:22598 devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(),
599 source_frame_number_);
[email protected]37386f052013-01-13 00:42:22600}
601
[email protected]6f90b9e2013-01-17 23:42:00602bool LayerTreeImpl::ContentsTexturesPurged() const {
603 return contents_textures_purged_;
604}
605
606void LayerTreeImpl::SetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04607 if (contents_textures_purged_)
608 return;
[email protected]6f90b9e2013-01-17 23:42:00609 contents_textures_purged_ = true;
[email protected]c1bb5af2013-03-13 19:06:27610 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00611}
612
613void LayerTreeImpl::ResetContentsTexturesPurged() {
[email protected]94bf75c2013-06-12 13:20:04614 if (!contents_textures_purged_)
615 return;
[email protected]6f90b9e2013-01-17 23:42:00616 contents_textures_purged_ = false;
[email protected]c1bb5af2013-03-13 19:06:27617 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]6f90b9e2013-01-17 23:42:00618}
619
[email protected]3d609bb2014-02-01 01:10:23620void LayerTreeImpl::SetRequiresHighResToDraw() {
621 requires_high_res_to_draw_ = true;
622}
623
624void LayerTreeImpl::ResetRequiresHighResToDraw() {
625 requires_high_res_to_draw_ = false;
626}
627
628bool LayerTreeImpl::RequiresHighResToDraw() const {
629 return requires_high_res_to_draw_;
630}
631
[email protected]318822852013-02-14 00:54:27632bool LayerTreeImpl::ViewportSizeInvalid() const {
633 return viewport_size_invalid_;
634}
635
636void LayerTreeImpl::SetViewportSizeInvalid() {
637 viewport_size_invalid_ = true;
[email protected]c1bb5af2013-03-13 19:06:27638 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27639}
640
641void LayerTreeImpl::ResetViewportSizeInvalid() {
642 viewport_size_invalid_ = false;
[email protected]c1bb5af2013-03-13 19:06:27643 layer_tree_host_impl_->OnCanDrawStateChangedForTree();
[email protected]318822852013-02-14 00:54:27644}
645
[email protected]48871fc2013-01-23 07:36:51646Proxy* LayerTreeImpl::proxy() const {
647 return layer_tree_host_impl_->proxy();
648}
649
[email protected]ff762fb2012-12-12 19:18:37650const LayerTreeSettings& LayerTreeImpl::settings() const {
[email protected]c1bb5af2013-03-13 19:06:27651 return layer_tree_host_impl_->settings();
[email protected]ff762fb2012-12-12 19:18:37652}
653
[email protected]7a8bcd262014-01-15 12:54:58654const RendererCapabilitiesImpl& LayerTreeImpl::GetRendererCapabilities() const {
[email protected]c1bb5af2013-03-13 19:06:27655 return layer_tree_host_impl_->GetRendererCapabilities();
[email protected]bf5b3a02013-02-13 02:02:52656}
657
[email protected]0634cdd42013-08-16 00:46:09658ContextProvider* LayerTreeImpl::context_provider() const {
659 return output_surface()->context_provider();
660}
661
[email protected]ff762fb2012-12-12 19:18:37662OutputSurface* LayerTreeImpl::output_surface() const {
[email protected]c1bb5af2013-03-13 19:06:27663 return layer_tree_host_impl_->output_surface();
[email protected]ff762fb2012-12-12 19:18:37664}
665
666ResourceProvider* LayerTreeImpl::resource_provider() const {
[email protected]c1bb5af2013-03-13 19:06:27667 return layer_tree_host_impl_->resource_provider();
[email protected]ff762fb2012-12-12 19:18:37668}
669
670TileManager* LayerTreeImpl::tile_manager() const {
[email protected]c1bb5af2013-03-13 19:06:27671 return layer_tree_host_impl_->tile_manager();
[email protected]ff762fb2012-12-12 19:18:37672}
673
674FrameRateCounter* LayerTreeImpl::frame_rate_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27675 return layer_tree_host_impl_->fps_counter();
[email protected]ff762fb2012-12-12 19:18:37676}
677
[email protected]71691c22013-01-18 03:14:22678PaintTimeCounter* LayerTreeImpl::paint_time_counter() const {
[email protected]c1bb5af2013-03-13 19:06:27679 return layer_tree_host_impl_->paint_time_counter();
[email protected]71691c22013-01-18 03:14:22680}
681
[email protected]1191d9d2013-02-02 06:00:33682MemoryHistory* LayerTreeImpl::memory_history() const {
[email protected]c1bb5af2013-03-13 19:06:27683 return layer_tree_host_impl_->memory_history();
[email protected]1191d9d2013-02-02 06:00:33684}
685
[email protected]c05dfbb2014-07-10 22:49:04686bool LayerTreeImpl::resourceless_software_draw() const {
687 return layer_tree_host_impl_->GetDrawMode() ==
688 DRAW_MODE_RESOURCELESS_SOFTWARE;
[email protected]54af03522013-09-05 00:43:28689}
690
[email protected]4a6c091d2014-04-24 21:06:46691gfx::Size LayerTreeImpl::device_viewport_size() const {
692 return layer_tree_host_impl_->device_viewport_size();
693}
694
[email protected]f117a4c2012-12-16 04:53:10695bool LayerTreeImpl::IsActiveTree() const {
[email protected]c1bb5af2013-03-13 19:06:27696 return layer_tree_host_impl_->active_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10697}
698
699bool LayerTreeImpl::IsPendingTree() const {
[email protected]c1bb5af2013-03-13 19:06:27700 return layer_tree_host_impl_->pending_tree() == this;
[email protected]f117a4c2012-12-16 04:53:10701}
702
[email protected]48871fc2013-01-23 07:36:51703bool LayerTreeImpl::IsRecycleTree() const {
[email protected]c1bb5af2013-03-13 19:06:27704 return layer_tree_host_impl_->recycle_tree() == this;
[email protected]48871fc2013-01-23 07:36:51705}
706
[email protected]f117a4c2012-12-16 04:53:10707LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27708 LayerTreeImpl* tree = layer_tree_host_impl_->active_tree();
[email protected]f117a4c2012-12-16 04:53:10709 if (!tree)
710 return NULL;
711 return tree->LayerById(id);
712}
713
714LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) {
[email protected]c1bb5af2013-03-13 19:06:27715 LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree();
[email protected]f117a4c2012-12-16 04:53:10716 if (!tree)
717 return NULL;
718 return tree->LayerById(id);
719}
720
[email protected]f6776532012-12-21 20:24:33721int LayerTreeImpl::MaxTextureSize() const {
[email protected]c1bb5af2013-03-13 19:06:27722 return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size;
[email protected]f6776532012-12-21 20:24:33723}
724
[email protected]166db5c82013-01-09 23:54:31725bool LayerTreeImpl::PinchGestureActive() const {
[email protected]c1bb5af2013-03-13 19:06:27726 return layer_tree_host_impl_->pinch_gesture_active();
[email protected]166db5c82013-01-09 23:54:31727}
728
[email protected]fb7425a2013-04-22 16:28:55729base::TimeTicks LayerTreeImpl::CurrentFrameTimeTicks() const {
730 return layer_tree_host_impl_->CurrentFrameTimeTicks();
731}
732
[email protected]c92195e2014-05-07 18:18:49733base::TimeDelta LayerTreeImpl::begin_impl_frame_interval() const {
734 return layer_tree_host_impl_->begin_impl_frame_interval();
735}
736
[email protected]d7eb8c72013-03-23 22:57:13737void LayerTreeImpl::SetNeedsCommit() {
738 layer_tree_host_impl_->SetNeedsCommit();
739}
740
[email protected]54af03522013-09-05 00:43:28741gfx::Size LayerTreeImpl::DrawViewportSize() const {
742 return layer_tree_host_impl_->DrawViewportSize();
743}
744
[email protected]930ff43b2014-05-02 05:24:00745scoped_ptr<ScrollbarAnimationController>
746LayerTreeImpl::CreateScrollbarAnimationController(LayerImpl* scrolling_layer) {
747 DCHECK(settings().scrollbar_fade_delay_ms);
748 DCHECK(settings().scrollbar_fade_duration_ms);
749 base::TimeDelta delay =
750 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms);
751 base::TimeDelta duration =
752 base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms);
753 switch (settings().scrollbar_animator) {
754 case LayerTreeSettings::LinearFade: {
755 return ScrollbarAnimationControllerLinearFade::Create(
756 scrolling_layer, layer_tree_host_impl_, delay, duration)
757 .PassAs<ScrollbarAnimationController>();
758 }
759 case LayerTreeSettings::Thinning: {
760 return ScrollbarAnimationControllerThinning::Create(
761 scrolling_layer, layer_tree_host_impl_, delay, duration)
762 .PassAs<ScrollbarAnimationController>();
763 }
764 case LayerTreeSettings::NoAnimator:
765 NOTREACHED();
766 break;
767 }
768 return scoped_ptr<ScrollbarAnimationController>();
[email protected]2ea5aba2013-09-11 14:26:56769}
770
[email protected]b8384e22013-12-03 02:20:48771void LayerTreeImpl::DidAnimateScrollOffset() {
772 layer_tree_host_impl_->DidAnimateScrollOffset();
773}
774
[email protected]13525d62014-05-20 21:22:04775bool LayerTreeImpl::use_gpu_rasterization() const {
776 return layer_tree_host_impl_->use_gpu_rasterization();
777}
778
[email protected]473f1f22014-05-22 08:19:17779bool LayerTreeImpl::create_low_res_tiling() const {
780 return layer_tree_host_impl_->create_low_res_tiling();
781}
782
[email protected]ff762fb2012-12-12 19:18:37783void LayerTreeImpl::SetNeedsRedraw() {
[email protected]59adb112013-04-09 04:48:44784 layer_tree_host_impl_->SetNeedsRedraw();
[email protected]ff762fb2012-12-12 19:18:37785}
786
[email protected]ff762fb2012-12-12 19:18:37787const LayerTreeDebugState& LayerTreeImpl::debug_state() const {
[email protected]c1bb5af2013-03-13 19:06:27788 return layer_tree_host_impl_->debug_state();
[email protected]ff762fb2012-12-12 19:18:37789}
790
791float LayerTreeImpl::device_scale_factor() const {
[email protected]c1bb5af2013-03-13 19:06:27792 return layer_tree_host_impl_->device_scale_factor();
[email protected]ff762fb2012-12-12 19:18:37793}
794
[email protected]ff762fb2012-12-12 19:18:37795DebugRectHistory* LayerTreeImpl::debug_rect_history() const {
[email protected]c1bb5af2013-03-13 19:06:27796 return layer_tree_host_impl_->debug_rect_history();
[email protected]ff762fb2012-12-12 19:18:37797}
798
[email protected]de4afb5e2012-12-20 00:11:34799AnimationRegistrar* LayerTreeImpl::animationRegistrar() const {
[email protected]c1bb5af2013-03-13 19:06:27800 return layer_tree_host_impl_->animation_registrar();
[email protected]de4afb5e2012-12-20 00:11:34801}
[email protected]ff762fb2012-12-12 19:18:37802
[email protected]8c5690222013-02-15 17:36:43803scoped_ptr<base::Value> LayerTreeImpl::AsValue() const {
[email protected]f6742f52013-05-08 23:52:22804 scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue());
805 TracedValue::MakeDictIntoImplicitSnapshot(
806 state.get(), "cc::LayerTreeImpl", this);
807
808 state->Set("root_layer", root_layer_->AsValue().release());
809
810 scoped_ptr<base::ListValue> render_surface_layer_list(new base::ListValue());
[email protected]ba1b33e2014-02-28 16:44:51811 typedef LayerIterator<LayerImpl> LayerIteratorType;
[email protected]71dfcc72013-03-20 21:30:09812 LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_);
813 for (LayerIteratorType it = LayerIteratorType::Begin(
[email protected]8c5690222013-02-15 17:36:43814 &render_surface_layer_list_); it != end; ++it) {
[email protected]71dfcc72013-03-20 21:30:09815 if (!it.represents_itself())
[email protected]8c5690222013-02-15 17:36:43816 continue;
[email protected]f6742f52013-05-08 23:52:22817 render_surface_layer_list->Append(TracedValue::CreateIDRef(*it).release());
[email protected]8c5690222013-02-15 17:36:43818 }
[email protected]f6742f52013-05-08 23:52:22819
820 state->Set("render_surface_layer_list",
821 render_surface_layer_list.release());
[email protected]8c5690222013-02-15 17:36:43822 return state.PassAs<base::Value>();
823}
824
[email protected]1960a712013-04-30 17:06:47825void LayerTreeImpl::SetRootLayerScrollOffsetDelegate(
[email protected]c9280762013-08-01 06:28:57826 LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) {
[email protected]20d2b742013-09-26 05:41:34827 if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate)
828 return;
829
[email protected]adeda572014-01-31 00:49:47830 if (!root_layer_scroll_offset_delegate) {
831 // Make sure we remove the proxies from their layers before
832 // releasing them.
833 if (InnerViewportScrollLayer())
834 InnerViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
835 if (OuterViewportScrollLayer())
836 OuterViewportScrollLayer()->SetScrollOffsetDelegate(NULL);
837 inner_viewport_scroll_delegate_proxy_.reset();
838 outer_viewport_scroll_delegate_proxy_.reset();
[email protected]d35cd7b22014-01-29 14:32:46839 }
840
[email protected]adeda572014-01-31 00:49:47841 root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate;
842
[email protected]20d2b742013-09-26 05:41:34843 if (root_layer_scroll_offset_delegate_) {
[email protected]ec2322e2014-05-15 16:32:00844 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
845 TotalScrollOffset(),
846 TotalMaxScrollOffset(),
847 ScrollableSize(),
[email protected]68fe60f2014-02-12 13:49:11848 total_page_scale_factor(),
849 min_page_scale_factor(),
850 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47851
852 if (inner_viewport_scroll_layer_) {
853 inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
854 new LayerScrollOffsetDelegateProxy(InnerViewportScrollLayer(),
855 root_layer_scroll_offset_delegate_,
856 this));
857 inner_viewport_scroll_layer_->SetScrollOffsetDelegate(
858 inner_viewport_scroll_delegate_proxy_.get());
859 }
860
861 if (outer_viewport_scroll_layer_) {
862 outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr(
863 new LayerScrollOffsetDelegateProxy(OuterViewportScrollLayer(),
864 root_layer_scroll_offset_delegate_,
865 this));
866 outer_viewport_scroll_layer_->SetScrollOffsetDelegate(
867 outer_viewport_scroll_delegate_proxy_.get());
868 }
[email protected]20d2b742013-09-26 05:41:34869 }
[email protected]1960a712013-04-30 17:06:47870}
871
[email protected]adeda572014-01-31 00:49:47872void LayerTreeImpl::UpdateScrollOffsetDelegate() {
873 DCHECK(InnerViewportScrollLayer());
874 DCHECK(root_layer_scroll_offset_delegate_);
875
876 gfx::Vector2dF offset =
877 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
878
879 if (OuterViewportScrollLayer())
880 offset += outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
881
[email protected]ec2322e2014-05-15 16:32:00882 root_layer_scroll_offset_delegate_->UpdateRootLayerState(
883 offset,
884 TotalMaxScrollOffset(),
885 ScrollableSize(),
886 total_page_scale_factor(),
887 min_page_scale_factor(),
888 max_page_scale_factor());
[email protected]adeda572014-01-31 00:49:47889}
890
891gfx::Vector2dF LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) {
892 DCHECK(root_layer_scroll_offset_delegate_);
893 DCHECK(InnerViewportScrollLayer());
894 if (layer == InnerViewportScrollLayer() && !OuterViewportScrollLayer())
895 return root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
896
897 // If we get here, we have both inner/outer viewports, and need to distribute
898 // the scroll offset between them.
899 DCHECK(inner_viewport_scroll_delegate_proxy_);
900 DCHECK(outer_viewport_scroll_delegate_proxy_);
901 gfx::Vector2dF inner_viewport_offset =
902 inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
903 gfx::Vector2dF outer_viewport_offset =
904 outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset();
905
906 // It may be nothing has changed.
907 gfx::Vector2dF delegate_offset =
908 root_layer_scroll_offset_delegate_->GetTotalScrollOffset();
909 if (inner_viewport_offset + outer_viewport_offset == delegate_offset) {
910 if (layer == InnerViewportScrollLayer())
911 return inner_viewport_offset;
912 else
913 return outer_viewport_offset;
914 }
915
916 gfx::Vector2d max_outer_viewport_scroll_offset =
917 OuterViewportScrollLayer()->MaxScrollOffset();
918
919 outer_viewport_offset = delegate_offset - inner_viewport_offset;
920 outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset);
921 outer_viewport_offset.SetToMax(gfx::Vector2d());
922
923 if (layer == OuterViewportScrollLayer())
924 return outer_viewport_offset;
925
926 inner_viewport_offset = delegate_offset - outer_viewport_offset;
927
928 return inner_viewport_offset;
929}
930
[email protected]b69c1db2013-11-27 00:05:19931void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) {
932 DCHECK(swap_promise);
933 if (swap_promise_list_.size() > kMaxQueuedSwapPromiseNumber)
934 BreakSwapPromises(SwapPromise::SWAP_PROMISE_LIST_OVERFLOW);
935 swap_promise_list_.push_back(swap_promise.Pass());
936}
937
938void LayerTreeImpl::PassSwapPromises(
939 ScopedPtrVector<SwapPromise>* new_swap_promise) {
940 swap_promise_list_.insert_and_take(swap_promise_list_.end(),
941 *new_swap_promise);
942 new_swap_promise->clear();
943}
944
[email protected]d359203a2013-11-29 06:16:55945void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) {
[email protected]b69c1db2013-11-27 00:05:19946 for (size_t i = 0; i < swap_promise_list_.size(); i++)
[email protected]d359203a2013-11-29 06:16:55947 swap_promise_list_[i]->DidSwap(metadata);
[email protected]b69c1db2013-11-27 00:05:19948 swap_promise_list_.clear();
949}
950
951void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) {
952 for (size_t i = 0; i < swap_promise_list_.size(); i++)
953 swap_promise_list_[i]->DidNotSwap(reason);
954 swap_promise_list_.clear();
955}
956
[email protected]c48536a52013-09-14 00:02:08957void LayerTreeImpl::DidModifyTilePriorities() {
958 layer_tree_host_impl_->DidModifyTilePriorities();
[email protected]fcb846d2013-05-22 01:42:36959}
960
[email protected]c9280762013-08-01 06:28:57961void LayerTreeImpl::set_ui_resource_request_queue(
962 const UIResourceRequestQueue& queue) {
963 ui_resource_request_queue_ = queue;
964}
965
966ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource(
967 UIResourceId uid) const {
968 return layer_tree_host_impl_->ResourceIdForUIResource(uid);
969}
970
[email protected]709c9542013-10-26 01:43:51971bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const {
972 return layer_tree_host_impl_->IsUIResourceOpaque(uid);
973}
974
[email protected]c9280762013-08-01 06:28:57975void LayerTreeImpl::ProcessUIResourceRequestQueue() {
976 while (ui_resource_request_queue_.size() > 0) {
977 UIResourceRequest req = ui_resource_request_queue_.front();
978 ui_resource_request_queue_.pop_front();
979
[email protected]741fba422013-09-20 03:34:14980 switch (req.GetType()) {
[email protected]c9280762013-08-01 06:28:57981 case UIResourceRequest::UIResourceCreate:
[email protected]741fba422013-09-20 03:34:14982 layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap());
[email protected]c9280762013-08-01 06:28:57983 break;
984 case UIResourceRequest::UIResourceDelete:
[email protected]741fba422013-09-20 03:34:14985 layer_tree_host_impl_->DeleteUIResource(req.GetId());
[email protected]c9280762013-08-01 06:28:57986 break;
[email protected]f28d64d2013-08-27 04:17:45987 case UIResourceRequest::UIResourceInvalidRequest:
[email protected]c9280762013-08-01 06:28:57988 NOTREACHED();
989 break;
990 }
991 }
[email protected]127bdc1a2013-09-11 01:44:48992
993 // If all UI resource evictions were not recreated by processing this queue,
994 // then another commit is required.
995 if (layer_tree_host_impl_->EvictedUIResourcesExist())
996 layer_tree_host_impl_->SetNeedsCommit();
[email protected]c9280762013-08-01 06:28:57997}
998
[email protected]30fe19ff2013-07-04 00:54:45999void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) {
1000 // Only the active tree needs to know about layers with copy requests, as
1001 // they are aborted if not serviced during draw.
1002 DCHECK(IsActiveTree());
1003
[email protected]a4ee12812014-02-06 17:33:381004 // DCHECK(std::find(layers_with_copy_output_request_.begin(),
1005 // layers_with_copy_output_request_.end(),
1006 // layer) == layers_with_copy_output_request_.end());
1007 // TODO(danakj): Remove this once crash is found crbug.com/309777
1008 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1009 CHECK(layers_with_copy_output_request_[i] != layer)
1010 << i << " of " << layers_with_copy_output_request_.size();
1011 }
[email protected]30fe19ff2013-07-04 00:54:451012 layers_with_copy_output_request_.push_back(layer);
1013}
1014
1015void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) {
1016 // Only the active tree needs to know about layers with copy requests, as
1017 // they are aborted if not serviced during draw.
1018 DCHECK(IsActiveTree());
1019
1020 std::vector<LayerImpl*>::iterator it = std::find(
1021 layers_with_copy_output_request_.begin(),
1022 layers_with_copy_output_request_.end(),
1023 layer);
1024 DCHECK(it != layers_with_copy_output_request_.end());
[email protected]f5de9e5b2013-07-30 22:26:571025 layers_with_copy_output_request_.erase(it);
[email protected]a4ee12812014-02-06 17:33:381026
1027 // TODO(danakj): Remove this once crash is found crbug.com/309777
1028 for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) {
1029 CHECK(layers_with_copy_output_request_[i] != layer)
1030 << i << " of " << layers_with_copy_output_request_.size();
1031 }
[email protected]30fe19ff2013-07-04 00:54:451032}
1033
[email protected]53526372013-12-07 04:31:501034const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest()
[email protected]30fe19ff2013-07-04 00:54:451035 const {
1036 // Only the active tree needs to know about layers with copy requests, as
1037 // they are aborted if not serviced during draw.
1038 DCHECK(IsActiveTree());
1039
1040 return layers_with_copy_output_request_;
1041}
1042
[email protected]aeef2f02014-05-10 12:15:481043void LayerTreeImpl::ReleaseResourcesRecursive(LayerImpl* current) {
1044 DCHECK(current);
1045 current->ReleaseResources();
1046 if (current->mask_layer())
1047 ReleaseResourcesRecursive(current->mask_layer());
1048 if (current->replica_layer())
1049 ReleaseResourcesRecursive(current->replica_layer());
1050 for (size_t i = 0; i < current->children().size(); ++i)
1051 ReleaseResourcesRecursive(current->children()[i]);
1052}
1053
[email protected]28336d52014-05-12 19:07:281054template <typename LayerType>
1055static inline bool LayerClipsSubtree(LayerType* layer) {
1056 return layer->masks_to_bounds() || layer->mask_layer();
1057}
1058
1059static bool PointHitsRect(
1060 const gfx::PointF& screen_space_point,
1061 const gfx::Transform& local_space_to_screen_space_transform,
1062 const gfx::RectF& local_space_rect,
1063 float* distance_to_camera) {
1064 // If the transform is not invertible, then assume that this point doesn't hit
1065 // this rect.
1066 gfx::Transform inverse_local_space_to_screen_space(
1067 gfx::Transform::kSkipInitialization);
1068 if (!local_space_to_screen_space_transform.GetInverse(
1069 &inverse_local_space_to_screen_space))
1070 return false;
1071
1072 // Transform the hit test point from screen space to the local space of the
1073 // given rect.
1074 bool clipped = false;
1075 gfx::Point3F planar_point = MathUtil::ProjectPoint3D(
1076 inverse_local_space_to_screen_space, screen_space_point, &clipped);
1077 gfx::PointF hit_test_point_in_local_space =
1078 gfx::PointF(planar_point.x(), planar_point.y());
1079
1080 // If ProjectPoint could not project to a valid value, then we assume that
1081 // this point doesn't hit this rect.
1082 if (clipped)
1083 return false;
1084
1085 if (!local_space_rect.Contains(hit_test_point_in_local_space))
1086 return false;
1087
1088 if (distance_to_camera) {
1089 // To compute the distance to the camera, we have to take the planar point
1090 // and pull it back to world space and compute the displacement along the
1091 // z-axis.
1092 gfx::Point3F planar_point_in_screen_space(planar_point);
1093 local_space_to_screen_space_transform.TransformPoint(
1094 &planar_point_in_screen_space);
1095 *distance_to_camera = planar_point_in_screen_space.z();
1096 }
1097
1098 return true;
1099}
1100
1101static bool PointHitsRegion(const gfx::PointF& screen_space_point,
1102 const gfx::Transform& screen_space_transform,
1103 const Region& layer_space_region,
1104 float layer_content_scale_x,
1105 float layer_content_scale_y) {
1106 // If the transform is not invertible, then assume that this point doesn't hit
1107 // this region.
1108 gfx::Transform inverse_screen_space_transform(
1109 gfx::Transform::kSkipInitialization);
1110 if (!screen_space_transform.GetInverse(&inverse_screen_space_transform))
1111 return false;
1112
1113 // Transform the hit test point from screen space to the local space of the
1114 // given region.
1115 bool clipped = false;
1116 gfx::PointF hit_test_point_in_content_space = MathUtil::ProjectPoint(
1117 inverse_screen_space_transform, screen_space_point, &clipped);
1118 gfx::PointF hit_test_point_in_layer_space =
1119 gfx::ScalePoint(hit_test_point_in_content_space,
1120 1.f / layer_content_scale_x,
1121 1.f / layer_content_scale_y);
1122
1123 // If ProjectPoint could not project to a valid value, then we assume that
1124 // this point doesn't hit this region.
1125 if (clipped)
1126 return false;
1127
1128 return layer_space_region.Contains(
1129 gfx::ToRoundedPoint(hit_test_point_in_layer_space));
1130}
1131
[email protected]19aec372014-07-01 19:08:491132static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) {
[email protected]0ec86f52014-06-12 20:54:031133 if (layer->scroll_parent())
1134 return layer->scroll_parent();
1135 if (layer->clip_parent())
1136 return layer->clip_parent();
1137 return layer->parent();
1138}
1139
[email protected]28336d52014-05-12 19:07:281140static bool PointIsClippedBySurfaceOrClipRect(
1141 const gfx::PointF& screen_space_point,
[email protected]19aec372014-07-01 19:08:491142 const LayerImpl* layer) {
[email protected]28336d52014-05-12 19:07:281143 // Walk up the layer tree and hit-test any render_surfaces and any layer
1144 // clip rects that are active.
[email protected]0ec86f52014-06-12 20:54:031145 for (; layer; layer = GetNextClippingLayer(layer)) {
1146 if (layer->render_surface() &&
1147 !PointHitsRect(screen_space_point,
1148 layer->render_surface()->screen_space_transform(),
1149 layer->render_surface()->content_rect(),
1150 NULL))
[email protected]28336d52014-05-12 19:07:281151 return true;
1152
[email protected]0ec86f52014-06-12 20:54:031153 if (LayerClipsSubtree(layer) &&
1154 !PointHitsRect(screen_space_point,
1155 layer->screen_space_transform(),
1156 gfx::Rect(layer->content_bounds()),
1157 NULL))
[email protected]28336d52014-05-12 19:07:281158 return true;
[email protected]28336d52014-05-12 19:07:281159 }
1160
1161 // If we have finished walking all ancestors without having already exited,
1162 // then the point is not clipped by any ancestors.
1163 return false;
1164}
1165
[email protected]19aec372014-07-01 19:08:491166static bool PointHitsLayer(const LayerImpl* layer,
[email protected]28336d52014-05-12 19:07:281167 const gfx::PointF& screen_space_point,
1168 float* distance_to_intersection) {
1169 gfx::RectF content_rect(layer->content_bounds());
1170 if (!PointHitsRect(screen_space_point,
1171 layer->screen_space_transform(),
1172 content_rect,
1173 distance_to_intersection))
1174 return false;
1175
1176 // At this point, we think the point does hit the layer, but we need to walk
1177 // up the parents to ensure that the layer was not clipped in such a way
1178 // that the hit point actually should not hit the layer.
1179 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer))
1180 return false;
1181
1182 // Skip the HUD layer.
1183 if (layer == layer->layer_tree_impl()->hud_layer())
1184 return false;
1185
1186 return true;
1187}
1188
1189struct FindClosestMatchingLayerDataForRecursion {
1190 FindClosestMatchingLayerDataForRecursion()
1191 : closest_match(NULL),
1192 closest_distance(-std::numeric_limits<float>::infinity()) {}
1193 LayerImpl* closest_match;
1194 // Note that the positive z-axis points towards the camera, so bigger means
1195 // closer in this case, counterintuitively.
1196 float closest_distance;
1197};
1198
1199template <typename Functor>
1200static void FindClosestMatchingLayer(
1201 const gfx::PointF& screen_space_point,
1202 LayerImpl* layer,
1203 const Functor& func,
1204 FindClosestMatchingLayerDataForRecursion* data_for_recursion) {
1205 for (int i = layer->children().size() - 1; i >= 0; --i) {
1206 FindClosestMatchingLayer(
1207 screen_space_point, layer->children()[i], func, data_for_recursion);
1208 }
1209
1210 float distance_to_intersection = 0.f;
1211 if (func(layer) &&
1212 PointHitsLayer(layer, screen_space_point, &distance_to_intersection) &&
1213 ((!data_for_recursion->closest_match ||
1214 distance_to_intersection > data_for_recursion->closest_distance))) {
1215 data_for_recursion->closest_distance = distance_to_intersection;
1216 data_for_recursion->closest_match = layer;
1217 }
1218}
1219
1220static bool ScrollsAnyDrawnRenderSurfaceLayerListMember(LayerImpl* layer) {
1221 if (!layer->scrollable())
1222 return false;
1223 if (layer->IsDrawnRenderSurfaceLayerListMember())
1224 return true;
1225 if (!layer->scroll_children())
1226 return false;
1227 for (std::set<LayerImpl*>::const_iterator it =
1228 layer->scroll_children()->begin();
1229 it != layer->scroll_children()->end();
1230 ++it) {
1231 if ((*it)->IsDrawnRenderSurfaceLayerListMember())
1232 return true;
1233 }
1234 return false;
1235}
1236
1237struct FindScrollingLayerFunctor {
1238 bool operator()(LayerImpl* layer) const {
1239 return ScrollsAnyDrawnRenderSurfaceLayerListMember(layer);
1240 }
1241};
1242
1243LayerImpl* LayerTreeImpl::FindFirstScrollingLayerThatIsHitByPoint(
1244 const gfx::PointF& screen_space_point) {
1245 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1246 FindClosestMatchingLayer(screen_space_point,
1247 root_layer(),
1248 FindScrollingLayerFunctor(),
1249 &data_for_recursion);
1250 return data_for_recursion.closest_match;
1251}
1252
1253struct HitTestVisibleScrollableOrTouchableFunctor {
1254 bool operator()(LayerImpl* layer) const {
1255 return layer->IsDrawnRenderSurfaceLayerListMember() ||
1256 ScrollsAnyDrawnRenderSurfaceLayerListMember(layer) ||
1257 !layer->touch_event_handler_region().IsEmpty() ||
1258 layer->have_wheel_event_handlers();
1259 }
1260};
1261
1262LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPoint(
1263 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321264 if (!root_layer())
1265 return NULL;
1266 if (!UpdateDrawProperties())
1267 return NULL;
[email protected]28336d52014-05-12 19:07:281268 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1269 FindClosestMatchingLayer(screen_space_point,
1270 root_layer(),
1271 HitTestVisibleScrollableOrTouchableFunctor(),
1272 &data_for_recursion);
1273 return data_for_recursion.closest_match;
1274}
1275
1276static bool LayerHasTouchEventHandlersAt(const gfx::PointF& screen_space_point,
1277 LayerImpl* layer_impl) {
1278 if (layer_impl->touch_event_handler_region().IsEmpty())
1279 return false;
1280
1281 if (!PointHitsRegion(screen_space_point,
1282 layer_impl->screen_space_transform(),
1283 layer_impl->touch_event_handler_region(),
1284 layer_impl->contents_scale_x(),
1285 layer_impl->contents_scale_y()))
1286 return false;
1287
1288 // At this point, we think the point does hit the touch event handler region
1289 // on the layer, but we need to walk up the parents to ensure that the layer
1290 // was not clipped in such a way that the hit point actually should not hit
1291 // the layer.
1292 if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl))
1293 return false;
1294
1295 return true;
1296}
1297
1298struct FindTouchEventLayerFunctor {
1299 bool operator()(LayerImpl* layer) const {
1300 return LayerHasTouchEventHandlersAt(screen_space_point, layer);
1301 }
1302 const gfx::PointF screen_space_point;
1303};
1304
1305LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion(
1306 const gfx::PointF& screen_space_point) {
[email protected]8f7f298822014-06-13 00:23:321307 if (!root_layer())
1308 return NULL;
1309 if (!UpdateDrawProperties())
1310 return NULL;
[email protected]28336d52014-05-12 19:07:281311 FindTouchEventLayerFunctor func = {screen_space_point};
1312 FindClosestMatchingLayerDataForRecursion data_for_recursion;
1313 FindClosestMatchingLayer(
1314 screen_space_point, root_layer(), func, &data_for_recursion);
1315 return data_for_recursion.closest_match;
1316}
1317
[email protected]ebb179b2014-07-16 17:54:411318void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& start,
1319 const LayerSelectionBound& end) {
1320 selection_start_ = start;
1321 selection_end_ = end;
[email protected]19aec372014-07-01 19:08:491322}
1323
1324static ViewportSelectionBound ComputeViewportSelection(
1325 const LayerSelectionBound& bound,
1326 LayerImpl* layer,
1327 float device_scale_factor) {
1328 ViewportSelectionBound result;
1329 result.type = bound.type;
1330
1331 if (!layer || bound.type == SELECTION_BOUND_EMPTY)
1332 return result;
1333
1334 gfx::RectF layer_scaled_rect = gfx::ScaleRect(
1335 bound.layer_rect, layer->contents_scale_x(), layer->contents_scale_y());
1336 gfx::RectF screen_rect = MathUtil::ProjectClippedRect(
1337 layer->screen_space_transform(), layer_scaled_rect);
1338
1339 // The bottom left of the bound is used for visibility because 1) the bound
1340 // edge rect is one-dimensional (no width), and 2) the bottom is the logical
1341 // focal point for bound selection handles (this may change in the future).
1342 const gfx::PointF& visibility_point = screen_rect.bottom_left();
1343 float intersect_distance = 0.f;
1344 result.visible = PointHitsLayer(layer, visibility_point, &intersect_distance);
1345
1346 screen_rect.Scale(1.f / device_scale_factor);
1347 result.viewport_rect = screen_rect;
1348
1349 return result;
1350}
1351
[email protected]ebb179b2014-07-16 17:54:411352void LayerTreeImpl::GetViewportSelection(ViewportSelectionBound* start,
1353 ViewportSelectionBound* end) {
1354 DCHECK(start);
1355 DCHECK(end);
[email protected]19aec372014-07-01 19:08:491356
[email protected]ebb179b2014-07-16 17:54:411357 *start = ComputeViewportSelection(
1358 selection_start_,
1359 selection_start_.layer_id ? LayerById(selection_start_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491360 device_scale_factor());
[email protected]ebb179b2014-07-16 17:54:411361 if (start->type == SELECTION_BOUND_CENTER ||
1362 start->type == SELECTION_BOUND_EMPTY) {
1363 *end = *start;
[email protected]19aec372014-07-01 19:08:491364 } else {
[email protected]ebb179b2014-07-16 17:54:411365 *end = ComputeViewportSelection(
1366 selection_end_,
1367 selection_end_.layer_id ? LayerById(selection_end_.layer_id) : NULL,
[email protected]19aec372014-07-01 19:08:491368 device_scale_factor());
1369 }
1370}
1371
[email protected]8aa39ecb2014-06-12 14:19:141372void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) {
1373 layer_tree_host_impl_->RegisterPictureLayerImpl(layer);
1374}
1375
1376void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) {
1377 layer_tree_host_impl_->UnregisterPictureLayerImpl(layer);
1378}
1379
[email protected]749cbc62014-07-10 01:06:351380void LayerTreeImpl::InputScrollAnimationFinished() {
1381 layer_tree_host_impl_->ScrollEnd();
1382}
1383
[email protected]ca2902e92013-03-28 01:45:351384} // namespace cc