[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 1 | // 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] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 5 | #include "cc/trees/layer_tree_impl.h" |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 6 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 7 | #include <algorithm> |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 8 | #include <limits> |
| 9 | #include <set> |
| 10 | |
primiano | c06e238 | 2015-01-28 04:21:49 | [diff] [blame] | 11 | #include "base/trace_event/trace_event.h" |
| 12 | #include "base/trace_event/trace_event_argument.h" |
loyso | bb93bef | 2015-07-03 00:19:50 | [diff] [blame] | 13 | #include "cc/animation/animation_host.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 14 | #include "cc/animation/keyframed_animation_curve.h" |
| 15 | #include "cc/animation/scrollbar_animation_controller.h" |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 16 | #include "cc/animation/scrollbar_animation_controller_linear_fade.h" |
| 17 | #include "cc/animation/scrollbar_animation_controller_thinning.h" |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 18 | #include "cc/base/math_util.h" |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 19 | #include "cc/base/synced_property.h" |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 20 | #include "cc/debug/devtools_instrumentation.h" |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 21 | #include "cc/debug/traced_value.h" |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 22 | #include "cc/input/page_scale_animation.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 23 | #include "cc/layers/heads_up_display_layer_impl.h" |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 24 | #include "cc/layers/layer.h" |
[email protected] | 34ba1ffb | 2014-03-05 06:55:03 | [diff] [blame] | 25 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 26 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 27 | #include "cc/layers/scrollbar_layer_impl_base.h" |
[email protected] | e104219 | 2013-11-08 05:44:24 | [diff] [blame] | 28 | #include "cc/resources/ui_resource_request.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 29 | #include "cc/trees/layer_tree_host_common.h" |
| 30 | #include "cc/trees/layer_tree_host_impl.h" |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 31 | #include "cc/trees/occlusion_tracker.h" |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 32 | #include "cc/trees/property_tree.h" |
enne | 7c733af | 2015-05-27 23:32:48 | [diff] [blame] | 33 | #include "cc/trees/property_tree_builder.h" |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 34 | #include "ui/gfx/geometry/box_f.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 35 | #include "ui/gfx/geometry/point_conversions.h" |
| 36 | #include "ui/gfx/geometry/size_conversions.h" |
| 37 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 38 | |
| 39 | namespace cc { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 40 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 41 | LayerTreeImpl::LayerTreeImpl( |
| 42 | LayerTreeHostImpl* layer_tree_host_impl, |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 43 | scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor, |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 44 | scoped_refptr<SyncedTopControls> top_controls_shown_ratio, |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 45 | scoped_refptr<SyncedElasticOverscroll> elastic_overscroll) |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 46 | : layer_tree_host_impl_(layer_tree_host_impl), |
| 47 | source_frame_number_(-1), |
| 48 | hud_layer_(0), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 49 | background_color_(0), |
| 50 | has_transparent_background_(false), |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 51 | currently_scrolling_layer_id_(Layer::INVALID_ID), |
| 52 | overscroll_elasticity_layer_id_(Layer::INVALID_ID), |
| 53 | page_scale_layer_id_(Layer::INVALID_ID), |
| 54 | inner_viewport_scroll_layer_id_(Layer::INVALID_ID), |
| 55 | outer_viewport_scroll_layer_id_(Layer::INVALID_ID), |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 56 | page_scale_factor_(page_scale_factor), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 57 | min_page_scale_factor_(0), |
| 58 | max_page_scale_factor_(0), |
skobes | 93102bc | 2015-08-04 20:38:05 | [diff] [blame] | 59 | hide_pinch_scrollbars_near_min_scale_(false), |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 60 | elastic_overscroll_(elastic_overscroll), |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 61 | viewport_size_invalid_(false), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 62 | needs_update_draw_properties_(true), |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 63 | needs_full_tree_sync_(true), |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 64 | next_activation_forces_redraw_(false), |
[email protected] | 759dc9f | 2014-07-23 19:18:51 | [diff] [blame] | 65 | has_ever_been_drawn_(false), |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 66 | render_surface_layer_list_id_(0), |
dtrainor | cb7779b8 | 2014-12-04 01:08:02 | [diff] [blame] | 67 | top_controls_shrink_blink_size_(false), |
| 68 | top_controls_height_(0), |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 69 | top_controls_shown_ratio_(top_controls_shown_ratio) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 70 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 71 | |
| 72 | LayerTreeImpl::~LayerTreeImpl() { |
tobiasjs | 93d46484 | 2015-05-15 17:52:44 | [diff] [blame] | 73 | BreakSwapPromises(IsActiveTree() ? SwapPromise::SWAP_FAILS |
| 74 | : SwapPromise::ACTIVATION_FAILS); |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 75 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 76 | // Need to explicitly clear the tree prior to destroying this so that |
| 77 | // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. |
[email protected] | df17af5 | 2014-02-06 02:20:40 | [diff] [blame] | 78 | DCHECK(!root_layer_); |
| 79 | DCHECK(layers_with_copy_output_request_.empty()); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 80 | } |
| 81 | |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 82 | void LayerTreeImpl::Shutdown() { |
| 83 | root_layer_ = nullptr; |
| 84 | } |
[email protected] | df17af5 | 2014-02-06 02:20:40 | [diff] [blame] | 85 | |
[email protected] | aeef2f0 | 2014-05-10 12:15:48 | [diff] [blame] | 86 | void LayerTreeImpl::ReleaseResources() { |
vmpstr | a73f18d | 2015-03-02 21:04:39 | [diff] [blame] | 87 | if (root_layer_) { |
| 88 | LayerTreeHostCommon::CallFunctionForSubtree( |
| 89 | root_layer_.get(), [](LayerImpl* layer) { layer->ReleaseResources(); }); |
| 90 | } |
vmpstr | 9ce5c66 | 2015-02-05 23:29:26 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | void LayerTreeImpl::RecreateResources() { |
vmpstr | a73f18d | 2015-03-02 21:04:39 | [diff] [blame] | 94 | if (root_layer_) { |
| 95 | LayerTreeHostCommon::CallFunctionForSubtree( |
| 96 | root_layer_.get(), |
| 97 | [](LayerImpl* layer) { layer->RecreateResources(); }); |
| 98 | } |
[email protected] | aeef2f0 | 2014-05-10 12:15:48 | [diff] [blame] | 99 | } |
| 100 | |
vmpstr | d704c87 | 2015-04-03 20:29:51 | [diff] [blame] | 101 | void LayerTreeImpl::GatherFrameTimingRequestIds( |
| 102 | std::vector<int64_t>* request_ids) { |
| 103 | if (!root_layer_) |
| 104 | return; |
| 105 | |
| 106 | // TODO(vmpstr): Early out if there are no requests on any of the layers. For |
| 107 | // that, we need to inform LayerTreeImpl whenever there are requests when we |
| 108 | // get them. |
| 109 | LayerTreeHostCommon::CallFunctionForSubtree( |
| 110 | root_layer_.get(), [request_ids](LayerImpl* layer) { |
| 111 | layer->GatherFrameTimingRequestIds(request_ids); |
| 112 | }); |
| 113 | } |
| 114 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 115 | void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 116 | root_layer_ = layer.Pass(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 117 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 118 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 119 | } |
| 120 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 121 | LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const { |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 122 | return LayerById(inner_viewport_scroll_layer_id_); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 123 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 124 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 125 | LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const { |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 126 | return LayerById(outer_viewport_scroll_layer_id_); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 127 | } |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 128 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 129 | gfx::ScrollOffset LayerTreeImpl::TotalScrollOffset() const { |
| 130 | gfx::ScrollOffset offset; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 131 | |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 132 | if (InnerViewportScrollLayer()) |
| 133 | offset += InnerViewportScrollLayer()->CurrentScrollOffset(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 134 | |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 135 | if (OuterViewportScrollLayer()) |
| 136 | offset += OuterViewportScrollLayer()->CurrentScrollOffset(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 137 | |
| 138 | return offset; |
| 139 | } |
| 140 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 141 | gfx::ScrollOffset LayerTreeImpl::TotalMaxScrollOffset() const { |
| 142 | gfx::ScrollOffset offset; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 143 | |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 144 | if (InnerViewportScrollLayer()) |
| 145 | offset += InnerViewportScrollLayer()->MaxScrollOffset(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 146 | |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 147 | if (OuterViewportScrollLayer()) |
| 148 | offset += OuterViewportScrollLayer()->MaxScrollOffset(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 149 | |
| 150 | return offset; |
| 151 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 152 | |
| 153 | scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 154 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 155 | set_needs_update_draw_properties(); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 156 | return root_layer_.Pass(); |
| 157 | } |
| 158 | |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 159 | static void UpdateClipTreeForBoundsDeltaOnLayer(LayerImpl* layer, |
| 160 | ClipTree* clip_tree) { |
| 161 | if (layer && layer->masks_to_bounds()) { |
| 162 | ClipNode* clip_node = clip_tree->Node(layer->clip_tree_index()); |
| 163 | if (clip_node) { |
| 164 | DCHECK_EQ(layer->id(), clip_node->owner_id); |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 165 | gfx::SizeF bounds = gfx::SizeF(layer->bounds()); |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 166 | if (clip_node->data.clip.size() != bounds) { |
| 167 | clip_node->data.clip.set_size(bounds); |
| 168 | clip_tree->set_needs_update(true); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | void LayerTreeImpl::UpdatePropertyTreesForBoundsDelta() { |
| 175 | DCHECK(IsActiveTree()); |
| 176 | LayerImpl* inner_container = InnerViewportContainerLayer(); |
| 177 | LayerImpl* outer_container = OuterViewportContainerLayer(); |
| 178 | |
| 179 | UpdateClipTreeForBoundsDeltaOnLayer(inner_container, |
| 180 | &property_trees_.clip_tree); |
| 181 | UpdateClipTreeForBoundsDeltaOnLayer(InnerViewportScrollLayer(), |
| 182 | &property_trees_.clip_tree); |
| 183 | UpdateClipTreeForBoundsDeltaOnLayer(outer_container, |
| 184 | &property_trees_.clip_tree); |
| 185 | |
| 186 | TransformTree& transform_tree = property_trees_.transform_tree; |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 187 | if (inner_container) |
| 188 | transform_tree.SetInnerViewportBoundsDelta(inner_container->bounds_delta()); |
| 189 | if (outer_container) |
| 190 | transform_tree.SetOuterViewportBoundsDelta(outer_container->bounds_delta()); |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 191 | } |
| 192 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 193 | void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 194 | // The request queue should have been processed and does not require a push. |
| 195 | DCHECK_EQ(ui_resource_request_queue_.size(), 0u); |
| 196 | |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 197 | target_tree->SetPropertyTrees(property_trees_); |
| 198 | |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 199 | if (next_activation_forces_redraw_) { |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 200 | target_tree->ForceRedrawNextActivation(); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 201 | next_activation_forces_redraw_ = false; |
| 202 | } |
| 203 | |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 204 | target_tree->PassSwapPromises(&swap_promise_list_); |
| 205 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 206 | target_tree->set_top_controls_shrink_blink_size( |
| 207 | top_controls_shrink_blink_size_); |
| 208 | target_tree->set_top_controls_height(top_controls_height_); |
| 209 | target_tree->PushTopControls(nullptr); |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 210 | |
skobes | 93102bc | 2015-08-04 20:38:05 | [diff] [blame] | 211 | target_tree->set_hide_pinch_scrollbars_near_min_scale( |
| 212 | hide_pinch_scrollbars_near_min_scale_); |
| 213 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 214 | // Active tree already shares the page_scale_factor object with pending |
| 215 | // tree so only the limits need to be provided. |
| 216 | target_tree->PushPageScaleFactorAndLimits(nullptr, min_page_scale_factor(), |
| 217 | max_page_scale_factor()); |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 218 | target_tree->elastic_overscroll()->PushPendingToActive(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 219 | |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 220 | target_tree->pending_page_scale_animation_ = |
| 221 | pending_page_scale_animation_.Pass(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 222 | |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 223 | target_tree->SetViewportLayersFromIds( |
| 224 | overscroll_elasticity_layer_id_, page_scale_layer_id_, |
| 225 | inner_viewport_scroll_layer_id_, outer_viewport_scroll_layer_id_); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 226 | |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 227 | target_tree->RegisterSelection(selection_); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 228 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 229 | // This should match the property synchronization in |
| 230 | // LayerTreeHost::finishCommitOnImplThread(). |
| 231 | target_tree->set_source_frame_number(source_frame_number()); |
| 232 | target_tree->set_background_color(background_color()); |
| 233 | target_tree->set_has_transparent_background(has_transparent_background()); |
| 234 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 235 | if (ViewportSizeInvalid()) |
| 236 | target_tree->SetViewportSizeInvalid(); |
| 237 | else |
| 238 | target_tree->ResetViewportSizeInvalid(); |
| 239 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 240 | if (hud_layer()) |
| 241 | target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 242 | LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 243 | target_tree->root_layer(), hud_layer()->id()))); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 244 | else |
| 245 | target_tree->set_hud_layer(NULL); |
[email protected] | 759dc9f | 2014-07-23 19:18:51 | [diff] [blame] | 246 | |
| 247 | target_tree->has_ever_been_drawn_ = false; |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 248 | } |
| 249 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 250 | LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const { |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 251 | return InnerViewportScrollLayer() |
| 252 | ? InnerViewportScrollLayer()->scroll_clip_layer() |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 253 | : NULL; |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 254 | } |
| 255 | |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 256 | LayerImpl* LayerTreeImpl::OuterViewportContainerLayer() const { |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 257 | return OuterViewportScrollLayer() |
| 258 | ? OuterViewportScrollLayer()->scroll_clip_layer() |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 259 | : NULL; |
| 260 | } |
| 261 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 262 | LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 263 | DCHECK(IsActiveTree()); |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 264 | return LayerById(currently_scrolling_layer_id_); |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 267 | void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) { |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 268 | int new_id = layer ? layer->id() : Layer::INVALID_ID; |
| 269 | if (currently_scrolling_layer_id_ == new_id) |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 270 | return; |
| 271 | |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 272 | if (CurrentlyScrollingLayer() && |
| 273 | CurrentlyScrollingLayer()->scrollbar_animation_controller()) |
| 274 | CurrentlyScrollingLayer()->scrollbar_animation_controller()->DidScrollEnd(); |
| 275 | currently_scrolling_layer_id_ = new_id; |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 276 | if (layer && layer->scrollbar_animation_controller()) |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 277 | layer->scrollbar_animation_controller()->DidScrollBegin(); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 278 | } |
| 279 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 280 | void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 281 | SetCurrentlyScrollingLayer(NULL); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 282 | } |
| 283 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 284 | namespace { |
| 285 | |
| 286 | void ForceScrollbarParameterUpdateAfterScaleChange(LayerImpl* current_layer) { |
| 287 | if (!current_layer) |
| 288 | return; |
| 289 | |
| 290 | while (current_layer) { |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 291 | current_layer->ScrollbarParametersDidChange(false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 292 | current_layer = current_layer->parent(); |
| 293 | } |
| 294 | } |
| 295 | |
| 296 | } // namespace |
| 297 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 298 | float LayerTreeImpl::ClampPageScaleFactorToLimits( |
| 299 | float page_scale_factor) const { |
| 300 | if (min_page_scale_factor_ && page_scale_factor < min_page_scale_factor_) |
| 301 | page_scale_factor = min_page_scale_factor_; |
| 302 | else if (max_page_scale_factor_ && page_scale_factor > max_page_scale_factor_) |
| 303 | page_scale_factor = max_page_scale_factor_; |
| 304 | return page_scale_factor; |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 305 | } |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 306 | |
ajuma | 9db24fb | 2015-06-29 20:15:07 | [diff] [blame] | 307 | void LayerTreeImpl::UpdatePropertyTreeScrollingAndAnimationFromMainThread() { |
| 308 | // TODO(enne): This should get replaced by pulling out scrolling and |
| 309 | // animations into their own trees. Then scrolls and animations would have |
| 310 | // their own ways of synchronizing across commits. This occurs to push |
| 311 | // updates from scrolling deltas on the compositor thread that have occurred |
| 312 | // after begin frame and updates from animations that have ticked since begin |
| 313 | // frame to a newly-committed property tree. |
enne | 1eb3a92 | 2015-06-17 17:37:50 | [diff] [blame] | 314 | if (!root_layer()) |
| 315 | return; |
| 316 | LayerTreeHostCommon::CallFunctionForSubtree( |
| 317 | root_layer(), [](LayerImpl* layer) { |
ajuma | 9db24fb | 2015-06-29 20:15:07 | [diff] [blame] | 318 | layer->UpdatePropertyTreeForScrollingAndAnimationIfNeeded(); |
enne | 1eb3a92 | 2015-06-17 17:37:50 | [diff] [blame] | 319 | }); |
| 320 | } |
| 321 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 322 | void LayerTreeImpl::SetPageScaleOnActiveTree(float active_page_scale) { |
| 323 | DCHECK(IsActiveTree()); |
| 324 | if (page_scale_factor()->SetCurrent( |
| 325 | ClampPageScaleFactorToLimits(active_page_scale))) |
| 326 | DidUpdatePageScale(); |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 327 | } |
| 328 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 329 | void LayerTreeImpl::PushPageScaleFromMainThread(float page_scale_factor, |
| 330 | float min_page_scale_factor, |
| 331 | float max_page_scale_factor) { |
| 332 | PushPageScaleFactorAndLimits(&page_scale_factor, min_page_scale_factor, |
| 333 | max_page_scale_factor); |
| 334 | } |
| 335 | |
| 336 | void LayerTreeImpl::PushPageScaleFactorAndLimits(const float* page_scale_factor, |
| 337 | float min_page_scale_factor, |
| 338 | float max_page_scale_factor) { |
| 339 | DCHECK(page_scale_factor || IsActiveTree()); |
| 340 | bool changed_page_scale = false; |
| 341 | if (page_scale_factor) { |
| 342 | DCHECK(!IsActiveTree() || !layer_tree_host_impl_->pending_tree()); |
enne | 1eb3a92 | 2015-06-17 17:37:50 | [diff] [blame] | 343 | changed_page_scale |= page_scale_factor_->Delta() != 1.f; |
| 344 | // TODO(enne): Once CDP goes away, ignore this call below. The only time |
| 345 | // the property trees will differ is if there's been a page scale on the |
| 346 | // compositor thread after the begin frame, which is the delta check above. |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 347 | changed_page_scale |= |
| 348 | page_scale_factor_->PushFromMainThread(*page_scale_factor); |
| 349 | } |
enne | 1eb3a92 | 2015-06-17 17:37:50 | [diff] [blame] | 350 | if (IsActiveTree()) { |
| 351 | // TODO(enne): Pushing from pending to active should never require |
| 352 | // DidUpdatePageScale. The values should already be set by the fully |
| 353 | // computed property trees being synced from one tree to another. Remove |
| 354 | // this once CDP goes away. |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 355 | changed_page_scale |= page_scale_factor_->PushPendingToActive(); |
enne | 1eb3a92 | 2015-06-17 17:37:50 | [diff] [blame] | 356 | } |
| 357 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 358 | changed_page_scale |= |
| 359 | SetPageScaleFactorLimits(min_page_scale_factor, max_page_scale_factor); |
| 360 | |
| 361 | if (changed_page_scale) |
| 362 | DidUpdatePageScale(); |
| 363 | } |
| 364 | |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 365 | void LayerTreeImpl::set_top_controls_shrink_blink_size(bool shrink) { |
| 366 | if (top_controls_shrink_blink_size_ == shrink) |
| 367 | return; |
| 368 | |
| 369 | top_controls_shrink_blink_size_ = shrink; |
| 370 | if (IsActiveTree()) |
| 371 | layer_tree_host_impl_->UpdateViewportContainerSizes(); |
| 372 | } |
| 373 | |
| 374 | void LayerTreeImpl::set_top_controls_height(float top_controls_height) { |
| 375 | if (top_controls_height_ == top_controls_height) |
| 376 | return; |
| 377 | |
| 378 | top_controls_height_ = top_controls_height; |
| 379 | if (IsActiveTree()) |
| 380 | layer_tree_host_impl_->UpdateViewportContainerSizes(); |
| 381 | } |
| 382 | |
| 383 | bool LayerTreeImpl::SetCurrentTopControlsShownRatio(float ratio) { |
| 384 | ratio = std::max(ratio, 0.f); |
| 385 | ratio = std::min(ratio, 1.f); |
| 386 | return top_controls_shown_ratio_->SetCurrent(ratio); |
| 387 | } |
| 388 | |
| 389 | void LayerTreeImpl::PushTopControlsFromMainThread( |
| 390 | float top_controls_shown_ratio) { |
| 391 | PushTopControls(&top_controls_shown_ratio); |
| 392 | } |
| 393 | |
| 394 | void LayerTreeImpl::PushTopControls(const float* top_controls_shown_ratio) { |
| 395 | DCHECK(top_controls_shown_ratio || IsActiveTree()); |
| 396 | |
| 397 | if (top_controls_shown_ratio) { |
| 398 | DCHECK(!IsActiveTree() || !layer_tree_host_impl_->pending_tree()); |
| 399 | top_controls_shown_ratio_->PushFromMainThread(*top_controls_shown_ratio); |
| 400 | } |
| 401 | if (IsActiveTree()) { |
| 402 | if (top_controls_shown_ratio_->PushPendingToActive()) |
| 403 | layer_tree_host_impl_->DidChangeTopControlsPosition(); |
| 404 | } |
| 405 | } |
| 406 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 407 | bool LayerTreeImpl::SetPageScaleFactorLimits(float min_page_scale_factor, |
| 408 | float max_page_scale_factor) { |
| 409 | if (min_page_scale_factor == min_page_scale_factor_ && |
| 410 | max_page_scale_factor == max_page_scale_factor_) |
| 411 | return false; |
[email protected] | 7265e74e | 2014-02-07 23:43:06 | [diff] [blame] | 412 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 413 | min_page_scale_factor_ = min_page_scale_factor; |
| 414 | max_page_scale_factor_ = max_page_scale_factor; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 415 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 416 | return true; |
| 417 | } |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 418 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 419 | void LayerTreeImpl::DidUpdatePageScale() { |
| 420 | if (IsActiveTree()) |
| 421 | page_scale_factor()->SetCurrent( |
| 422 | ClampPageScaleFactorToLimits(current_page_scale_factor())); |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 423 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 424 | set_needs_update_draw_properties(); |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 425 | |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 426 | if (PageScaleLayer() && PageScaleLayer()->transform_tree_index() != -1) { |
enne | b21df31 | 2015-05-27 00:27:18 | [diff] [blame] | 427 | TransformNode* node = property_trees_.transform_tree.Node( |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 428 | PageScaleLayer()->transform_tree_index()); |
enne | b21df31 | 2015-05-27 00:27:18 | [diff] [blame] | 429 | node->data.post_local_scale_factor = current_page_scale_factor(); |
ajuma | babeff1 | 2015-05-28 21:56:27 | [diff] [blame] | 430 | node->data.needs_local_transform_update = true; |
enne | b21df31 | 2015-05-27 00:27:18 | [diff] [blame] | 431 | // TODO(enne): property trees can't ask the layer these things, but |
| 432 | // the page scale layer should *just* be the page scale. |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 433 | DCHECK_EQ(PageScaleLayer()->position().ToString(), |
enne | b21df31 | 2015-05-27 00:27:18 | [diff] [blame] | 434 | gfx::PointF().ToString()); |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 435 | DCHECK_EQ(PageScaleLayer()->transform_origin().ToString(), |
enne | b21df31 | 2015-05-27 00:27:18 | [diff] [blame] | 436 | gfx::Point3F().ToString()); |
| 437 | node->data.update_post_local_transform(gfx::PointF(), gfx::Point3F()); |
| 438 | property_trees_.transform_tree.set_needs_update(true); |
| 439 | } |
| 440 | |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 441 | ForceScrollbarParameterUpdateAfterScaleChange(PageScaleLayer()); |
skobes | 93102bc | 2015-08-04 20:38:05 | [diff] [blame] | 442 | HideInnerViewportScrollbarsIfNeeded(); |
bokan | c784a6f | 2015-01-28 04:11:50 | [diff] [blame] | 443 | } |
| 444 | |
skobes | 93102bc | 2015-08-04 20:38:05 | [diff] [blame] | 445 | void LayerTreeImpl::HideInnerViewportScrollbarsIfNeeded() { |
bokan | c784a6f | 2015-01-28 04:11:50 | [diff] [blame] | 446 | if (!InnerViewportContainerLayer()) |
| 447 | return; |
| 448 | |
| 449 | LayerImpl::ScrollbarSet* scrollbars = |
| 450 | InnerViewportContainerLayer()->scrollbars(); |
| 451 | |
| 452 | if (!scrollbars) |
| 453 | return; |
| 454 | |
skobes | 93102bc | 2015-08-04 20:38:05 | [diff] [blame] | 455 | float minimum_scale_to_show_at = min_page_scale_factor() * 1.05f; |
| 456 | bool hide_scrollbars = |
| 457 | hide_pinch_scrollbars_near_min_scale_ && |
| 458 | (current_page_scale_factor() < minimum_scale_to_show_at); |
| 459 | |
bokan | c784a6f | 2015-01-28 04:11:50 | [diff] [blame] | 460 | for (LayerImpl::ScrollbarSet::iterator it = scrollbars->begin(); |
skobes | 93102bc | 2015-08-04 20:38:05 | [diff] [blame] | 461 | it != scrollbars->end(); ++it) |
| 462 | (*it)->SetHideLayerAndSubtree(hide_scrollbars); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 463 | } |
| 464 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 465 | SyncedProperty<ScaleGroup>* LayerTreeImpl::page_scale_factor() { |
| 466 | return page_scale_factor_.get(); |
| 467 | } |
| 468 | |
| 469 | const SyncedProperty<ScaleGroup>* LayerTreeImpl::page_scale_factor() const { |
| 470 | return page_scale_factor_.get(); |
| 471 | } |
| 472 | |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 473 | gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 474 | if (!InnerViewportContainerLayer()) |
| 475 | return gfx::SizeF(); |
| 476 | |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 477 | return gfx::ScaleSize(InnerViewportContainerLayer()->BoundsForScrolling(), |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 478 | 1.0f / current_page_scale_factor()); |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 479 | } |
| 480 | |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 481 | gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 482 | LayerImpl* root_scroll_layer = OuterViewportScrollLayer() |
| 483 | ? OuterViewportScrollLayer() |
| 484 | : InnerViewportScrollLayer(); |
| 485 | if (!root_scroll_layer || root_scroll_layer->children().empty()) |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 486 | return gfx::Rect(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 487 | LayerImpl* layer = root_scroll_layer->children()[0]; |
[email protected] | 8a82269 | 2014-02-12 17:30:55 | [diff] [blame] | 488 | return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(), |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 489 | gfx::Rect(layer->bounds())); |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 490 | } |
| 491 | |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 492 | void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() { |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 493 | DCHECK(IsActiveTree()); |
| 494 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 495 | page_scale_factor()->AbortCommit(); |
aelias | 6004fe0 | 2015-02-07 21:43:01 | [diff] [blame] | 496 | top_controls_shown_ratio()->AbortCommit(); |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 497 | elastic_overscroll()->AbortCommit(); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 498 | |
| 499 | if (!root_layer()) |
| 500 | return; |
| 501 | |
| 502 | LayerTreeHostCommon::CallFunctionForSubtree( |
vmpstr | a73f18d | 2015-03-02 21:04:39 | [diff] [blame] | 503 | root_layer(), [](LayerImpl* layer) { |
| 504 | layer->ApplySentScrollDeltasFromAbortedCommit(); |
| 505 | }); |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 506 | } |
| 507 | |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 508 | void LayerTreeImpl::SetViewportLayersFromIds( |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 509 | int overscroll_elasticity_layer_id, |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 510 | int page_scale_layer_id, |
| 511 | int inner_viewport_scroll_layer_id, |
| 512 | int outer_viewport_scroll_layer_id) { |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 513 | overscroll_elasticity_layer_id_ = overscroll_elasticity_layer_id; |
| 514 | page_scale_layer_id_ = page_scale_layer_id; |
| 515 | inner_viewport_scroll_layer_id_ = inner_viewport_scroll_layer_id; |
| 516 | outer_viewport_scroll_layer_id_ = outer_viewport_scroll_layer_id; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 517 | |
skobes | 93102bc | 2015-08-04 20:38:05 | [diff] [blame] | 518 | HideInnerViewportScrollbarsIfNeeded(); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 519 | } |
| 520 | |
| 521 | void LayerTreeImpl::ClearViewportLayers() { |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 522 | overscroll_elasticity_layer_id_ = Layer::INVALID_ID; |
| 523 | page_scale_layer_id_ = Layer::INVALID_ID; |
| 524 | inner_viewport_scroll_layer_id_ = Layer::INVALID_ID; |
| 525 | outer_viewport_scroll_layer_id_ = Layer::INVALID_ID; |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 526 | } |
| 527 | |
enne | 2504193 | 2015-09-25 19:42:01 | [diff] [blame^] | 528 | #if DCHECK_IS_ON() |
| 529 | int SanityCheckCopyRequestCounts(LayerImpl* layer) { |
| 530 | int count = layer->HasCopyRequest() ? 1 : 0; |
| 531 | for (size_t i = 0; i < layer->children().size(); ++i) { |
| 532 | count += SanityCheckCopyRequestCounts(layer->child_at(i)); |
| 533 | } |
| 534 | DCHECK_EQ(count, layer->num_layer_or_descendants_with_copy_request()) |
| 535 | << ", id: " << layer->id(); |
| 536 | return count; |
| 537 | } |
| 538 | #endif |
| 539 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 540 | bool LayerTreeImpl::UpdateDrawProperties(bool update_lcd_text) { |
enne | 2504193 | 2015-09-25 19:42:01 | [diff] [blame^] | 541 | #if DCHECK_IS_ON() |
| 542 | if (root_layer()) |
| 543 | SanityCheckCopyRequestCounts(root_layer()); |
| 544 | #endif |
| 545 | |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 546 | if (!needs_update_draw_properties_) |
| 547 | return true; |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 548 | |
enne | 0acea6ae | 2015-02-19 20:01:51 | [diff] [blame] | 549 | // Calling UpdateDrawProperties must clear this flag, so there can be no |
| 550 | // early outs before this. |
| 551 | needs_update_draw_properties_ = false; |
| 552 | |
| 553 | // For max_texture_size. When the renderer is re-created in |
| 554 | // CreateAndSetRenderer, the needs update draw properties flag is set |
| 555 | // again. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 556 | if (!layer_tree_host_impl_->renderer()) |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 557 | return false; |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 558 | |
enne | 0acea6ae | 2015-02-19 20:01:51 | [diff] [blame] | 559 | // Clear this after the renderer early out, as it should still be |
| 560 | // possible to hit test even without a renderer. |
| 561 | render_surface_layer_list_.clear(); |
| 562 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 563 | if (!root_layer()) |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 564 | return false; |
| 565 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 566 | { |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 567 | TRACE_EVENT2( |
| 568 | "cc", "LayerTreeImpl::UpdateDrawProperties::CalculateDrawProperties", |
| 569 | "IsActive", IsActiveTree(), "SourceFrameNumber", source_frame_number_); |
hush | 367d7dd | 2014-08-29 23:56:01 | [diff] [blame] | 570 | bool can_render_to_separate_surface = |
| 571 | (layer_tree_host_impl_->GetDrawMode() != |
| 572 | DRAW_MODE_RESOURCELESS_SOFTWARE); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 573 | |
| 574 | ++render_surface_layer_list_id_; |
enne | c301147 | 2015-04-09 01:27:25 | [diff] [blame] | 575 | |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 576 | LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 577 | root_layer(), DrawViewportSize(), |
| 578 | layer_tree_host_impl_->DrawTransform(), device_scale_factor(), |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 579 | current_page_scale_factor(), PageScaleLayer(), |
| 580 | InnerViewportScrollLayer(), OuterViewportScrollLayer(), |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 581 | elastic_overscroll()->Current(IsActiveTree()), |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 582 | OverscrollElasticityLayer(), resource_provider()->max_texture_size(), |
ccameron | b9aec450 | 2014-12-05 19:31:00 | [diff] [blame] | 583 | settings().can_use_lcd_text, settings().layers_always_allowed_lcd_text, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 584 | can_render_to_separate_surface, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 585 | settings().layer_transforms_should_scale_layer_contents, |
enne | c301147 | 2015-04-09 01:27:25 | [diff] [blame] | 586 | settings().verify_property_trees, &render_surface_layer_list_, |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 587 | render_surface_layer_list_id_, &property_trees_); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 588 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 589 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 590 | |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 591 | { |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 592 | TRACE_EVENT2("cc", "LayerTreeImpl::UpdateDrawProperties::Occlusion", |
| 593 | "IsActive", IsActiveTree(), "SourceFrameNumber", |
| 594 | source_frame_number_); |
danakj | 00f7925e | 2015-06-15 21:19:22 | [diff] [blame] | 595 | OcclusionTracker occlusion_tracker( |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 596 | root_layer()->render_surface()->content_rect()); |
| 597 | occlusion_tracker.set_minimum_tracking_size( |
| 598 | settings().minimum_occlusion_tracking_size); |
boliu | 7473f7f5 | 2014-10-01 16:54:56 | [diff] [blame] | 599 | |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 600 | // LayerIterator is used here instead of CallFunctionForSubtree to only |
| 601 | // UpdateTilePriorities on layers that will be visible (and thus have valid |
| 602 | // draw properties) and not because any ordering is required. |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 603 | LayerIterator end = LayerIterator::End(&render_surface_layer_list_); |
| 604 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list_); |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 605 | it != end; ++it) { |
| 606 | occlusion_tracker.EnterLayer(it); |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 607 | |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 608 | // There are very few render targets so this should be cheap to do for |
| 609 | // each layer instead of something more complicated. |
| 610 | bool inside_replica = false; |
| 611 | LayerImpl* layer = it->render_target(); |
| 612 | while (layer && !inside_replica) { |
| 613 | if (layer->render_target()->has_replica()) |
| 614 | inside_replica = true; |
| 615 | layer = layer->render_target()->parent(); |
| 616 | } |
| 617 | |
| 618 | // Don't use occlusion if a layer will appear in a replica, since the |
| 619 | // tile raster code does not know how to look for the replica and would |
| 620 | // consider it occluded even though the replica is visible. |
| 621 | // Since occlusion is only used for browser compositor (i.e. |
| 622 | // use_occlusion_for_tile_prioritization) and it won't use replicas, |
| 623 | // this should matter not. |
vmpstr | cdcb5f7 | 2014-09-11 00:58:37 | [diff] [blame] | 624 | |
boliu | 7473f7f5 | 2014-10-01 16:54:56 | [diff] [blame] | 625 | if (it.represents_itself()) { |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 626 | Occlusion occlusion = |
| 627 | inside_replica ? Occlusion() |
| 628 | : occlusion_tracker.GetCurrentOcclusionForLayer( |
| 629 | it->draw_transform()); |
| 630 | it->draw_properties().occlusion_in_content_space = occlusion; |
boliu | 7473f7f5 | 2014-10-01 16:54:56 | [diff] [blame] | 631 | } |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 632 | |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 633 | if (it.represents_contributing_render_surface()) { |
| 634 | // Surfaces aren't used by the tile raster code, so they can have |
| 635 | // occlusion regardless of replicas. |
| 636 | Occlusion occlusion = |
| 637 | occlusion_tracker.GetCurrentOcclusionForContributingSurface( |
| 638 | it->render_surface()->draw_transform()); |
| 639 | it->render_surface()->set_occlusion_in_content_space(occlusion); |
| 640 | // Masks are used to draw the contributing surface, so should have |
| 641 | // the same occlusion as the surface (nothing inside the surface |
| 642 | // occludes them). |
| 643 | if (LayerImpl* mask = it->mask_layer()) { |
| 644 | Occlusion mask_occlusion = |
| 645 | inside_replica |
| 646 | ? Occlusion() |
| 647 | : occlusion_tracker.GetCurrentOcclusionForContributingSurface( |
| 648 | it->render_surface()->draw_transform() * |
| 649 | it->draw_transform()); |
| 650 | mask->draw_properties().occlusion_in_content_space = mask_occlusion; |
| 651 | } |
| 652 | if (LayerImpl* replica = it->replica_layer()) { |
| 653 | if (LayerImpl* mask = replica->mask_layer()) |
| 654 | mask->draw_properties().occlusion_in_content_space = Occlusion(); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | occlusion_tracker.LeaveLayer(it); |
| 659 | } |
| 660 | |
| 661 | unoccluded_screen_space_region_ = |
| 662 | occlusion_tracker.ComputeVisibleRegionInScreen(); |
| 663 | } |
| 664 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 665 | // It'd be ideal if this could be done earlier, but when the raster source |
| 666 | // is updated from the main thread during push properties, update draw |
| 667 | // properties has not occurred yet and so it's not clear whether or not the |
| 668 | // layer can or cannot use lcd text. So, this is the cleanup pass to |
| 669 | // determine if the raster source needs to be replaced with a non-lcd |
| 670 | // raster source due to draw properties. |
| 671 | if (update_lcd_text) { |
| 672 | // TODO(enne): Make LTHI::sync_tree return this value. |
| 673 | LayerTreeImpl* sync_tree = |
| 674 | layer_tree_host_impl_->proxy()->CommitToActiveTree() |
| 675 | ? layer_tree_host_impl_->active_tree() |
| 676 | : layer_tree_host_impl_->pending_tree(); |
| 677 | // If this is not the sync tree, then it is not safe to update lcd text |
| 678 | // as it causes invalidations and the tiles may be in use. |
| 679 | DCHECK_EQ(this, sync_tree); |
| 680 | for (const auto& layer : picture_layers_) |
| 681 | layer->UpdateCanUseLCDTextAfterCommit(); |
| 682 | } |
| 683 | |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 684 | { |
| 685 | TRACE_EVENT_BEGIN2("cc", "LayerTreeImpl::UpdateDrawProperties::UpdateTiles", |
| 686 | "IsActive", IsActiveTree(), "SourceFrameNumber", |
| 687 | source_frame_number_); |
| 688 | const bool resourceless_software_draw = |
| 689 | (layer_tree_host_impl_->GetDrawMode() == |
| 690 | DRAW_MODE_RESOURCELESS_SOFTWARE); |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 691 | size_t layers_updated_count = 0; |
| 692 | bool tile_priorities_updated = false; |
| 693 | for (PictureLayerImpl* layer : picture_layers_) { |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 694 | if (!layer->IsDrawnRenderSurfaceLayerListMember()) |
[email protected] | 6355d2d | 2014-05-07 15:07:27 | [diff] [blame] | 695 | continue; |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 696 | ++layers_updated_count; |
danakj | 83c3d4a8 | 2015-02-14 01:42:57 | [diff] [blame] | 697 | tile_priorities_updated |= layer->UpdateTiles(resourceless_software_draw); |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 698 | } |
vmpstr | d616620 | 2014-11-05 18:45:40 | [diff] [blame] | 699 | |
vmpstr | 5377520a | 2014-12-29 23:26:13 | [diff] [blame] | 700 | if (tile_priorities_updated) |
| 701 | DidModifyTilePriorities(); |
| 702 | |
vmpstr | d616620 | 2014-11-05 18:45:40 | [diff] [blame] | 703 | TRACE_EVENT_END1("cc", "LayerTreeImpl::UpdateTilePriorities", |
| 704 | "layers_updated_count", layers_updated_count); |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 705 | } |
| 706 | |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 707 | DCHECK(!needs_update_draw_properties_) << |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 708 | "CalcDrawProperties should not set_needs_update_draw_properties()"; |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 709 | return true; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 710 | } |
| 711 | |
enne | 7c733af | 2015-05-27 23:32:48 | [diff] [blame] | 712 | void LayerTreeImpl::BuildPropertyTreesForTesting() { |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 713 | LayerTreeHostCommon::PreCalculateMetaInformationForTesting(root_layer_.get()); |
enne | 7c733af | 2015-05-27 23:32:48 | [diff] [blame] | 714 | PropertyTreeBuilder::BuildPropertyTrees( |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 715 | root_layer_.get(), PageScaleLayer(), InnerViewportScrollLayer(), |
| 716 | OuterViewportScrollLayer(), current_page_scale_factor(), |
enne | 7c733af | 2015-05-27 23:32:48 | [diff] [blame] | 717 | device_scale_factor(), gfx::Rect(DrawViewportSize()), |
| 718 | layer_tree_host_impl_->DrawTransform(), &property_trees_); |
| 719 | } |
| 720 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 721 | const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const { |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 722 | // If this assert triggers, then the list is dirty. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 723 | DCHECK(!needs_update_draw_properties_); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 724 | return render_surface_layer_list_; |
| 725 | } |
| 726 | |
danakj | 4902c30 | 2015-02-13 22:12:16 | [diff] [blame] | 727 | const Region& LayerTreeImpl::UnoccludedScreenSpaceRegion() const { |
| 728 | // If this assert triggers, then the render_surface_layer_list_ is dirty, so |
| 729 | // the unoccluded_screen_space_region_ is not valid anymore. |
| 730 | DCHECK(!needs_update_draw_properties_); |
| 731 | return unoccluded_screen_space_region_; |
| 732 | } |
| 733 | |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 734 | gfx::SizeF LayerTreeImpl::ScrollableSize() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 735 | LayerImpl* root_scroll_layer = OuterViewportScrollLayer() |
| 736 | ? OuterViewportScrollLayer() |
| 737 | : InnerViewportScrollLayer(); |
| 738 | if (!root_scroll_layer || root_scroll_layer->children().empty()) |
danakj | ddaec91 | 2015-09-25 19:38:40 | [diff] [blame] | 739 | return gfx::SizeF(); |
bokan | 574c4363 | 2015-08-14 02:22:07 | [diff] [blame] | 740 | |
| 741 | gfx::SizeF content_size = |
| 742 | root_scroll_layer->children()[0]->BoundsForScrolling(); |
| 743 | gfx::SizeF viewport_size = |
| 744 | root_scroll_layer->scroll_clip_layer()->BoundsForScrolling(); |
| 745 | |
| 746 | content_size.SetToMax(viewport_size); |
| 747 | return content_size; |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 748 | } |
| 749 | |
loyso | bb93bef | 2015-07-03 00:19:50 | [diff] [blame] | 750 | LayerImpl* LayerTreeImpl::LayerById(int id) const { |
| 751 | LayerIdMap::const_iterator iter = layer_id_map_.find(id); |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 752 | return iter != layer_id_map_.end() ? iter->second : NULL; |
| 753 | } |
| 754 | |
| 755 | void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { |
| 756 | DCHECK(!LayerById(layer->id())); |
| 757 | layer_id_map_[layer->id()] = layer; |
loyso | bb93bef | 2015-07-03 00:19:50 | [diff] [blame] | 758 | if (layer_tree_host_impl_->animation_host()) |
| 759 | layer_tree_host_impl_->animation_host()->RegisterLayer( |
| 760 | layer->id(), |
| 761 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING); |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { |
| 765 | DCHECK(LayerById(layer->id())); |
loyso | bb93bef | 2015-07-03 00:19:50 | [diff] [blame] | 766 | if (layer_tree_host_impl_->animation_host()) |
| 767 | layer_tree_host_impl_->animation_host()->UnregisterLayer( |
| 768 | layer->id(), |
| 769 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING); |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 770 | layer_id_map_.erase(layer->id()); |
| 771 | } |
| 772 | |
[email protected] | aebf462 | 2014-07-14 16:57:59 | [diff] [blame] | 773 | size_t LayerTreeImpl::NumLayers() { |
| 774 | return layer_id_map_.size(); |
| 775 | } |
| 776 | |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 777 | void LayerTreeImpl::DidBecomeActive() { |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 778 | if (next_activation_forces_redraw_) { |
| 779 | layer_tree_host_impl_->SetFullRootLayerDamage(); |
| 780 | next_activation_forces_redraw_ = false; |
| 781 | } |
| 782 | |
[email protected] | 7dcf563 | 2014-06-25 01:11:55 | [diff] [blame] | 783 | // Always reset this flag on activation, as we would only have activated |
| 784 | // if we were in a good state. |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 785 | layer_tree_host_impl_->ResetRequiresHighResToDraw(); |
[email protected] | 7dcf563 | 2014-06-25 01:11:55 | [diff] [blame] | 786 | |
vmpstr | a73f18d | 2015-03-02 21:04:39 | [diff] [blame] | 787 | if (root_layer()) { |
| 788 | LayerTreeHostCommon::CallFunctionForSubtree( |
| 789 | root_layer(), [](LayerImpl* layer) { layer->DidBecomeActive(); }); |
| 790 | } |
[email protected] | 7dcf563 | 2014-06-25 01:11:55 | [diff] [blame] | 791 | |
tobiasjs | 93d46484 | 2015-05-15 17:52:44 | [diff] [blame] | 792 | for (auto* swap_promise : swap_promise_list_) |
| 793 | swap_promise->DidActivate(); |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 794 | devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(), |
| 795 | source_frame_number_); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 796 | } |
| 797 | |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 798 | bool LayerTreeImpl::RequiresHighResToDraw() const { |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 799 | return layer_tree_host_impl_->RequiresHighResToDraw(); |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 800 | } |
| 801 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 802 | bool LayerTreeImpl::ViewportSizeInvalid() const { |
| 803 | return viewport_size_invalid_; |
| 804 | } |
| 805 | |
| 806 | void LayerTreeImpl::SetViewportSizeInvalid() { |
| 807 | viewport_size_invalid_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 808 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 809 | } |
| 810 | |
| 811 | void LayerTreeImpl::ResetViewportSizeInvalid() { |
| 812 | viewport_size_invalid_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 813 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 814 | } |
| 815 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 816 | Proxy* LayerTreeImpl::proxy() const { |
| 817 | return layer_tree_host_impl_->proxy(); |
| 818 | } |
| 819 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 820 | const LayerTreeSettings& LayerTreeImpl::settings() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 821 | return layer_tree_host_impl_->settings(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 822 | } |
| 823 | |
danakj | 875efa4 | 2015-02-10 22:18:23 | [diff] [blame] | 824 | const LayerTreeDebugState& LayerTreeImpl::debug_state() const { |
| 825 | return layer_tree_host_impl_->debug_state(); |
| 826 | } |
| 827 | |
[email protected] | 7a8bcd26 | 2014-01-15 12:54:58 | [diff] [blame] | 828 | const RendererCapabilitiesImpl& LayerTreeImpl::GetRendererCapabilities() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 829 | return layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | bf5b3a0 | 2013-02-13 02:02:52 | [diff] [blame] | 830 | } |
| 831 | |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 832 | ContextProvider* LayerTreeImpl::context_provider() const { |
dcheng | 6afa1700 | 2014-08-26 19:11:31 | [diff] [blame] | 833 | return output_surface()->context_provider(); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 834 | } |
| 835 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 836 | OutputSurface* LayerTreeImpl::output_surface() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 837 | return layer_tree_host_impl_->output_surface(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 838 | } |
| 839 | |
| 840 | ResourceProvider* LayerTreeImpl::resource_provider() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 841 | return layer_tree_host_impl_->resource_provider(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | TileManager* LayerTreeImpl::tile_manager() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 845 | return layer_tree_host_impl_->tile_manager(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 846 | } |
| 847 | |
| 848 | FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 849 | return layer_tree_host_impl_->fps_counter(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 850 | } |
| 851 | |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 852 | MemoryHistory* LayerTreeImpl::memory_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 853 | return layer_tree_host_impl_->memory_history(); |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 854 | } |
| 855 | |
[email protected] | 4a6c091d | 2014-04-24 21:06:46 | [diff] [blame] | 856 | gfx::Size LayerTreeImpl::device_viewport_size() const { |
| 857 | return layer_tree_host_impl_->device_viewport_size(); |
| 858 | } |
| 859 | |
danakj | 875efa4 | 2015-02-10 22:18:23 | [diff] [blame] | 860 | float LayerTreeImpl::device_scale_factor() const { |
| 861 | return layer_tree_host_impl_->device_scale_factor(); |
| 862 | } |
| 863 | |
| 864 | DebugRectHistory* LayerTreeImpl::debug_rect_history() const { |
| 865 | return layer_tree_host_impl_->debug_rect_history(); |
| 866 | } |
| 867 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 868 | bool LayerTreeImpl::IsActiveTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 869 | return layer_tree_host_impl_->active_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 870 | } |
| 871 | |
| 872 | bool LayerTreeImpl::IsPendingTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 873 | return layer_tree_host_impl_->pending_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 874 | } |
| 875 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 876 | bool LayerTreeImpl::IsRecycleTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 877 | return layer_tree_host_impl_->recycle_tree() == this; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 878 | } |
| 879 | |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 880 | bool LayerTreeImpl::IsSyncTree() const { |
| 881 | return layer_tree_host_impl_->sync_tree() == this; |
| 882 | } |
| 883 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 884 | LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 885 | LayerTreeImpl* tree = layer_tree_host_impl_->active_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 886 | if (!tree) |
| 887 | return NULL; |
| 888 | return tree->LayerById(id); |
| 889 | } |
| 890 | |
| 891 | LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 892 | LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 893 | if (!tree) |
| 894 | return NULL; |
| 895 | return tree->LayerById(id); |
| 896 | } |
| 897 | |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 898 | bool LayerTreeImpl::PinchGestureActive() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 899 | return layer_tree_host_impl_->pinch_gesture_active(); |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 900 | } |
| 901 | |
[email protected] | 04c5900d | 2014-08-18 13:38:36 | [diff] [blame] | 902 | BeginFrameArgs LayerTreeImpl::CurrentBeginFrameArgs() const { |
| 903 | return layer_tree_host_impl_->CurrentBeginFrameArgs(); |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 904 | } |
| 905 | |
mithro | 0bdb49d | 2015-05-27 13:08:01 | [diff] [blame] | 906 | base::TimeDelta LayerTreeImpl::CurrentBeginFrameInterval() const { |
| 907 | return layer_tree_host_impl_->CurrentBeginFrameInterval(); |
[email protected] | c92195e | 2014-05-07 18:18:49 | [diff] [blame] | 908 | } |
| 909 | |
[email protected] | d7eb8c7 | 2013-03-23 22:57:13 | [diff] [blame] | 910 | void LayerTreeImpl::SetNeedsCommit() { |
| 911 | layer_tree_host_impl_->SetNeedsCommit(); |
| 912 | } |
| 913 | |
[email protected] | bd532459 | 2014-07-31 09:09:33 | [diff] [blame] | 914 | gfx::Rect LayerTreeImpl::DeviceViewport() const { |
| 915 | return layer_tree_host_impl_->DeviceViewport(); |
| 916 | } |
| 917 | |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 918 | gfx::Size LayerTreeImpl::DrawViewportSize() const { |
| 919 | return layer_tree_host_impl_->DrawViewportSize(); |
| 920 | } |
| 921 | |
[email protected] | bd532459 | 2014-07-31 09:09:33 | [diff] [blame] | 922 | const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const { |
| 923 | return layer_tree_host_impl_->ViewportRectForTilePriority(); |
| 924 | } |
| 925 | |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 926 | scoped_ptr<ScrollbarAnimationController> |
| 927 | LayerTreeImpl::CreateScrollbarAnimationController(LayerImpl* scrolling_layer) { |
| 928 | DCHECK(settings().scrollbar_fade_delay_ms); |
| 929 | DCHECK(settings().scrollbar_fade_duration_ms); |
| 930 | base::TimeDelta delay = |
| 931 | base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms); |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 932 | base::TimeDelta resize_delay = base::TimeDelta::FromMilliseconds( |
| 933 | settings().scrollbar_fade_resize_delay_ms); |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 934 | base::TimeDelta duration = |
| 935 | base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms); |
| 936 | switch (settings().scrollbar_animator) { |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 937 | case LayerTreeSettings::LINEAR_FADE: { |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 938 | return ScrollbarAnimationControllerLinearFade::Create( |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 939 | scrolling_layer, |
| 940 | layer_tree_host_impl_, |
| 941 | delay, |
| 942 | resize_delay, |
| 943 | duration); |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 944 | } |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 945 | case LayerTreeSettings::THINNING: { |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 946 | return ScrollbarAnimationControllerThinning::Create(scrolling_layer, |
| 947 | layer_tree_host_impl_, |
| 948 | delay, |
| 949 | resize_delay, |
| 950 | duration); |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 951 | } |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 952 | case LayerTreeSettings::NO_ANIMATOR: |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 953 | NOTREACHED(); |
| 954 | break; |
| 955 | } |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 956 | return nullptr; |
[email protected] | 2ea5aba | 2013-09-11 14:26:56 | [diff] [blame] | 957 | } |
| 958 | |
[email protected] | b8384e2 | 2013-12-03 02:20:48 | [diff] [blame] | 959 | void LayerTreeImpl::DidAnimateScrollOffset() { |
| 960 | layer_tree_host_impl_->DidAnimateScrollOffset(); |
| 961 | } |
| 962 | |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 963 | bool LayerTreeImpl::use_gpu_rasterization() const { |
| 964 | return layer_tree_host_impl_->use_gpu_rasterization(); |
| 965 | } |
| 966 | |
hendrikw | c2bbd61 | 2014-12-03 23:49:34 | [diff] [blame] | 967 | GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const { |
| 968 | return layer_tree_host_impl_->gpu_rasterization_status(); |
| 969 | } |
| 970 | |
[email protected] | 473f1f2 | 2014-05-22 08:19:17 | [diff] [blame] | 971 | bool LayerTreeImpl::create_low_res_tiling() const { |
| 972 | return layer_tree_host_impl_->create_low_res_tiling(); |
| 973 | } |
| 974 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 975 | void LayerTreeImpl::SetNeedsRedraw() { |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 976 | layer_tree_host_impl_->SetNeedsRedraw(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 977 | } |
| 978 | |
sunnyps | ea328be1 | 2015-02-26 06:03:27 | [diff] [blame] | 979 | AnimationRegistrar* LayerTreeImpl::GetAnimationRegistrar() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 980 | return layer_tree_host_impl_->animation_registrar(); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 981 | } |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 982 | |
hendrikw | c5e91585 | 2015-05-13 01:29:03 | [diff] [blame] | 983 | void LayerTreeImpl::GetAllPrioritizedTilesForTracing( |
| 984 | std::vector<PrioritizedTile>* prioritized_tiles) const { |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 985 | LayerIterator end = LayerIterator::End(&render_surface_layer_list_); |
| 986 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list_); |
| 987 | it != end; ++it) { |
vmpstr | d7de03c | 2014-08-27 18:11:01 | [diff] [blame] | 988 | if (!it.represents_itself()) |
| 989 | continue; |
| 990 | LayerImpl* layer_impl = *it; |
hendrikw | c5e91585 | 2015-05-13 01:29:03 | [diff] [blame] | 991 | layer_impl->GetAllPrioritizedTilesForTracing(prioritized_tiles); |
vmpstr | d7de03c | 2014-08-27 18:11:01 | [diff] [blame] | 992 | } |
| 993 | } |
| 994 | |
ssid | 911e40e | 2015-02-09 17:55:20 | [diff] [blame] | 995 | void LayerTreeImpl::AsValueInto(base::trace_event::TracedValue* state) const { |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 996 | TracedValue::MakeDictIntoImplicitSnapshot(state, "cc::LayerTreeImpl", this); |
nduca | 929378a0 | 2014-08-23 19:48:52 | [diff] [blame] | 997 | state->SetInteger("source_frame_number", source_frame_number_); |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 998 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 999 | state->BeginDictionary("root_layer"); |
| 1000 | root_layer_->AsValueInto(state); |
| 1001 | state->EndDictionary(); |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 1002 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1003 | state->BeginArray("render_surface_layer_list"); |
enne | 389d1a1 | 2015-06-18 20:40:51 | [diff] [blame] | 1004 | LayerIterator end = LayerIterator::End(&render_surface_layer_list_); |
| 1005 | for (LayerIterator it = LayerIterator::Begin(&render_surface_layer_list_); |
| 1006 | it != end; ++it) { |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 1007 | if (!it.represents_itself()) |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 1008 | continue; |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1009 | TracedValue::AppendIDRef(*it, state); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 1010 | } |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1011 | state->EndArray(); |
skyostil | 43c330f7 | 2014-09-22 16:49:11 | [diff] [blame] | 1012 | |
| 1013 | state->BeginArray("swap_promise_trace_ids"); |
tobiasjs | 93d46484 | 2015-05-15 17:52:44 | [diff] [blame] | 1014 | for (auto* swap_promise : swap_promise_list_) |
| 1015 | state->AppendDouble(swap_promise->TraceId()); |
skyostil | 43c330f7 | 2014-09-22 16:49:11 | [diff] [blame] | 1016 | state->EndArray(); |
tobiasjs | 2e02f73e | 2015-09-02 12:08:03 | [diff] [blame] | 1017 | |
| 1018 | state->BeginArray("pinned_swap_promise_trace_ids"); |
| 1019 | for (auto* swap_promise : pinned_swap_promise_list_) |
| 1020 | state->AppendDouble(swap_promise->TraceId()); |
| 1021 | state->EndArray(); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 1022 | } |
| 1023 | |
danakj | 0481b57 | 2015-09-10 01:18:01 | [diff] [blame] | 1024 | void LayerTreeImpl::DistributeRootScrollOffset( |
| 1025 | const gfx::ScrollOffset& root_offset) { |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 1026 | if (!InnerViewportScrollLayer()) |
| 1027 | return; |
| 1028 | |
| 1029 | DCHECK(OuterViewportScrollLayer()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1030 | |
| 1031 | // If we get here, we have both inner/outer viewports, and need to distribute |
| 1032 | // the scroll offset between them. |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1033 | gfx::ScrollOffset inner_viewport_offset = |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 1034 | InnerViewportScrollLayer()->CurrentScrollOffset(); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1035 | gfx::ScrollOffset outer_viewport_offset = |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 1036 | OuterViewportScrollLayer()->CurrentScrollOffset(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1037 | |
| 1038 | // It may be nothing has changed. |
danakj | 2c51326 | 2015-09-16 00:43:01 | [diff] [blame] | 1039 | DCHECK(inner_viewport_offset + outer_viewport_offset == TotalScrollOffset()); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 1040 | if (inner_viewport_offset + outer_viewport_offset == root_offset) |
| 1041 | return; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1042 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1043 | gfx::ScrollOffset max_outer_viewport_scroll_offset = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1044 | OuterViewportScrollLayer()->MaxScrollOffset(); |
| 1045 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 1046 | outer_viewport_offset = root_offset - inner_viewport_offset; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1047 | outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1048 | outer_viewport_offset.SetToMax(gfx::ScrollOffset()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1049 | |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 1050 | OuterViewportScrollLayer()->SetCurrentScrollOffset(outer_viewport_offset); |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 1051 | inner_viewport_offset = root_offset - outer_viewport_offset; |
danakj | a342d6f3b | 2015-09-17 22:25:48 | [diff] [blame] | 1052 | InnerViewportScrollLayer()->SetCurrentScrollOffset(inner_viewport_offset); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1053 | } |
| 1054 | |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1055 | void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) { |
| 1056 | DCHECK(swap_promise); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1057 | swap_promise_list_.push_back(swap_promise.Pass()); |
| 1058 | } |
| 1059 | |
tobiasjs | 2e02f73e | 2015-09-02 12:08:03 | [diff] [blame] | 1060 | void LayerTreeImpl::QueuePinnedSwapPromise( |
| 1061 | scoped_ptr<SwapPromise> swap_promise) { |
| 1062 | DCHECK(IsActiveTree()); |
| 1063 | DCHECK(swap_promise); |
| 1064 | pinned_swap_promise_list_.push_back(swap_promise.Pass()); |
| 1065 | } |
| 1066 | |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1067 | void LayerTreeImpl::PassSwapPromises( |
| 1068 | ScopedPtrVector<SwapPromise>* new_swap_promise) { |
tobiasjs | 2e02f73e | 2015-09-02 12:08:03 | [diff] [blame] | 1069 | for (auto* swap_promise : swap_promise_list_) |
| 1070 | swap_promise->DidNotSwap(SwapPromise::SWAP_FAILS); |
| 1071 | swap_promise_list_.clear(); |
| 1072 | swap_promise_list_.swap(*new_swap_promise); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1073 | } |
| 1074 | |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 1075 | void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) { |
tobiasjs | 93d46484 | 2015-05-15 17:52:44 | [diff] [blame] | 1076 | for (auto* swap_promise : swap_promise_list_) |
| 1077 | swap_promise->DidSwap(metadata); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1078 | swap_promise_list_.clear(); |
tobiasjs | 2e02f73e | 2015-09-02 12:08:03 | [diff] [blame] | 1079 | for (auto* swap_promise : pinned_swap_promise_list_) |
| 1080 | swap_promise->DidSwap(metadata); |
| 1081 | pinned_swap_promise_list_.clear(); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1082 | } |
| 1083 | |
| 1084 | void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) { |
tobiasjs | 93d46484 | 2015-05-15 17:52:44 | [diff] [blame] | 1085 | for (auto* swap_promise : swap_promise_list_) |
| 1086 | swap_promise->DidNotSwap(reason); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1087 | swap_promise_list_.clear(); |
tobiasjs | 2e02f73e | 2015-09-02 12:08:03 | [diff] [blame] | 1088 | for (auto* swap_promise : pinned_swap_promise_list_) |
| 1089 | swap_promise->DidNotSwap(reason); |
| 1090 | pinned_swap_promise_list_.clear(); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1091 | } |
| 1092 | |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 1093 | void LayerTreeImpl::DidModifyTilePriorities() { |
| 1094 | layer_tree_host_impl_->DidModifyTilePriorities(); |
[email protected] | fcb846d | 2013-05-22 01:42:36 | [diff] [blame] | 1095 | } |
| 1096 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1097 | void LayerTreeImpl::set_ui_resource_request_queue( |
| 1098 | const UIResourceRequestQueue& queue) { |
| 1099 | ui_resource_request_queue_ = queue; |
| 1100 | } |
| 1101 | |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 1102 | ResourceId LayerTreeImpl::ResourceIdForUIResource(UIResourceId uid) const { |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1103 | return layer_tree_host_impl_->ResourceIdForUIResource(uid); |
| 1104 | } |
| 1105 | |
[email protected] | 709c954 | 2013-10-26 01:43:51 | [diff] [blame] | 1106 | bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const { |
| 1107 | return layer_tree_host_impl_->IsUIResourceOpaque(uid); |
| 1108 | } |
| 1109 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1110 | void LayerTreeImpl::ProcessUIResourceRequestQueue() { |
jdduke | 5ad3681 | 2015-01-02 17:59:32 | [diff] [blame] | 1111 | for (const auto& req : ui_resource_request_queue_) { |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 1112 | switch (req.GetType()) { |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1113 | case UIResourceRequest::UI_RESOURCE_CREATE: |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 1114 | layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap()); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1115 | break; |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1116 | case UIResourceRequest::UI_RESOURCE_DELETE: |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 1117 | layer_tree_host_impl_->DeleteUIResource(req.GetId()); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1118 | break; |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1119 | case UIResourceRequest::UI_RESOURCE_INVALID_REQUEST: |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1120 | NOTREACHED(); |
| 1121 | break; |
| 1122 | } |
| 1123 | } |
jdduke | 5ad3681 | 2015-01-02 17:59:32 | [diff] [blame] | 1124 | ui_resource_request_queue_.clear(); |
[email protected] | 127bdc1a | 2013-09-11 01:44:48 | [diff] [blame] | 1125 | |
| 1126 | // If all UI resource evictions were not recreated by processing this queue, |
| 1127 | // then another commit is required. |
| 1128 | if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
| 1129 | layer_tree_host_impl_->SetNeedsCommit(); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1130 | } |
| 1131 | |
danakj | 7383c55 | 2015-02-11 18:01:48 | [diff] [blame] | 1132 | void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 1133 | DCHECK(std::find(picture_layers_.begin(), picture_layers_.end(), layer) == |
| 1134 | picture_layers_.end()); |
| 1135 | picture_layers_.push_back(layer); |
| 1136 | } |
| 1137 | |
| 1138 | void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 1139 | std::vector<PictureLayerImpl*>::iterator it = |
| 1140 | std::find(picture_layers_.begin(), picture_layers_.end(), layer); |
| 1141 | DCHECK(it != picture_layers_.end()); |
| 1142 | picture_layers_.erase(it); |
| 1143 | } |
| 1144 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1145 | void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) { |
| 1146 | // Only the active tree needs to know about layers with copy requests, as |
| 1147 | // they are aborted if not serviced during draw. |
| 1148 | DCHECK(IsActiveTree()); |
| 1149 | |
[email protected] | a4ee1281 | 2014-02-06 17:33:38 | [diff] [blame] | 1150 | // DCHECK(std::find(layers_with_copy_output_request_.begin(), |
| 1151 | // layers_with_copy_output_request_.end(), |
| 1152 | // layer) == layers_with_copy_output_request_.end()); |
| 1153 | // TODO(danakj): Remove this once crash is found crbug.com/309777 |
| 1154 | for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) { |
| 1155 | CHECK(layers_with_copy_output_request_[i] != layer) |
| 1156 | << i << " of " << layers_with_copy_output_request_.size(); |
| 1157 | } |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1158 | layers_with_copy_output_request_.push_back(layer); |
| 1159 | } |
| 1160 | |
| 1161 | void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) { |
| 1162 | // Only the active tree needs to know about layers with copy requests, as |
| 1163 | // they are aborted if not serviced during draw. |
| 1164 | DCHECK(IsActiveTree()); |
| 1165 | |
| 1166 | std::vector<LayerImpl*>::iterator it = std::find( |
| 1167 | layers_with_copy_output_request_.begin(), |
| 1168 | layers_with_copy_output_request_.end(), |
| 1169 | layer); |
| 1170 | DCHECK(it != layers_with_copy_output_request_.end()); |
[email protected] | f5de9e5b | 2013-07-30 22:26:57 | [diff] [blame] | 1171 | layers_with_copy_output_request_.erase(it); |
[email protected] | a4ee1281 | 2014-02-06 17:33:38 | [diff] [blame] | 1172 | |
| 1173 | // TODO(danakj): Remove this once crash is found crbug.com/309777 |
| 1174 | for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) { |
| 1175 | CHECK(layers_with_copy_output_request_[i] != layer) |
| 1176 | << i << " of " << layers_with_copy_output_request_.size(); |
| 1177 | } |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1178 | } |
| 1179 | |
[email protected] | 5352637 | 2013-12-07 04:31:50 | [diff] [blame] | 1180 | const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest() |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1181 | const { |
| 1182 | // Only the active tree needs to know about layers with copy requests, as |
| 1183 | // they are aborted if not serviced during draw. |
| 1184 | DCHECK(IsActiveTree()); |
| 1185 | |
| 1186 | return layers_with_copy_output_request_; |
| 1187 | } |
| 1188 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1189 | template <typename LayerType> |
| 1190 | static inline bool LayerClipsSubtree(LayerType* layer) { |
| 1191 | return layer->masks_to_bounds() || layer->mask_layer(); |
| 1192 | } |
| 1193 | |
| 1194 | static bool PointHitsRect( |
| 1195 | const gfx::PointF& screen_space_point, |
| 1196 | const gfx::Transform& local_space_to_screen_space_transform, |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 1197 | const gfx::Rect& local_space_rect, |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1198 | float* distance_to_camera) { |
| 1199 | // If the transform is not invertible, then assume that this point doesn't hit |
| 1200 | // this rect. |
| 1201 | gfx::Transform inverse_local_space_to_screen_space( |
| 1202 | gfx::Transform::kSkipInitialization); |
| 1203 | if (!local_space_to_screen_space_transform.GetInverse( |
| 1204 | &inverse_local_space_to_screen_space)) |
| 1205 | return false; |
| 1206 | |
| 1207 | // Transform the hit test point from screen space to the local space of the |
| 1208 | // given rect. |
| 1209 | bool clipped = false; |
| 1210 | gfx::Point3F planar_point = MathUtil::ProjectPoint3D( |
| 1211 | inverse_local_space_to_screen_space, screen_space_point, &clipped); |
| 1212 | gfx::PointF hit_test_point_in_local_space = |
| 1213 | gfx::PointF(planar_point.x(), planar_point.y()); |
| 1214 | |
| 1215 | // If ProjectPoint could not project to a valid value, then we assume that |
| 1216 | // this point doesn't hit this rect. |
| 1217 | if (clipped) |
| 1218 | return false; |
| 1219 | |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 1220 | if (!gfx::RectF(local_space_rect).Contains(hit_test_point_in_local_space)) |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1221 | return false; |
| 1222 | |
| 1223 | if (distance_to_camera) { |
| 1224 | // To compute the distance to the camera, we have to take the planar point |
| 1225 | // and pull it back to world space and compute the displacement along the |
| 1226 | // z-axis. |
| 1227 | gfx::Point3F planar_point_in_screen_space(planar_point); |
| 1228 | local_space_to_screen_space_transform.TransformPoint( |
| 1229 | &planar_point_in_screen_space); |
| 1230 | *distance_to_camera = planar_point_in_screen_space.z(); |
| 1231 | } |
| 1232 | |
| 1233 | return true; |
| 1234 | } |
| 1235 | |
| 1236 | static bool PointHitsRegion(const gfx::PointF& screen_space_point, |
| 1237 | const gfx::Transform& screen_space_transform, |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 1238 | const Region& layer_space_region) { |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1239 | // If the transform is not invertible, then assume that this point doesn't hit |
| 1240 | // this region. |
| 1241 | gfx::Transform inverse_screen_space_transform( |
| 1242 | gfx::Transform::kSkipInitialization); |
| 1243 | if (!screen_space_transform.GetInverse(&inverse_screen_space_transform)) |
| 1244 | return false; |
| 1245 | |
| 1246 | // Transform the hit test point from screen space to the local space of the |
| 1247 | // given region. |
| 1248 | bool clipped = false; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 1249 | gfx::PointF hit_test_point_in_layer_space = MathUtil::ProjectPoint( |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1250 | inverse_screen_space_transform, screen_space_point, &clipped); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1251 | |
| 1252 | // If ProjectPoint could not project to a valid value, then we assume that |
| 1253 | // this point doesn't hit this region. |
| 1254 | if (clipped) |
| 1255 | return false; |
| 1256 | |
| 1257 | return layer_space_region.Contains( |
| 1258 | gfx::ToRoundedPoint(hit_test_point_in_layer_space)); |
| 1259 | } |
| 1260 | |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1261 | static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) { |
[email protected] | 0ec86f5 | 2014-06-12 20:54:03 | [diff] [blame] | 1262 | if (layer->scroll_parent()) |
| 1263 | return layer->scroll_parent(); |
| 1264 | if (layer->clip_parent()) |
| 1265 | return layer->clip_parent(); |
| 1266 | return layer->parent(); |
| 1267 | } |
| 1268 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1269 | static bool PointIsClippedBySurfaceOrClipRect( |
| 1270 | const gfx::PointF& screen_space_point, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1271 | const LayerImpl* layer) { |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1272 | // Walk up the layer tree and hit-test any render_surfaces and any layer |
| 1273 | // clip rects that are active. |
[email protected] | 0ec86f5 | 2014-06-12 20:54:03 | [diff] [blame] | 1274 | for (; layer; layer = GetNextClippingLayer(layer)) { |
| 1275 | if (layer->render_surface() && |
| 1276 | !PointHitsRect(screen_space_point, |
| 1277 | layer->render_surface()->screen_space_transform(), |
| 1278 | layer->render_surface()->content_rect(), |
| 1279 | NULL)) |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1280 | return true; |
| 1281 | |
[email protected] | 0ec86f5 | 2014-06-12 20:54:03 | [diff] [blame] | 1282 | if (LayerClipsSubtree(layer) && |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 1283 | !PointHitsRect(screen_space_point, layer->screen_space_transform(), |
| 1284 | gfx::Rect(layer->bounds()), NULL)) |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1285 | return true; |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | // If we have finished walking all ancestors without having already exited, |
| 1289 | // then the point is not clipped by any ancestors. |
| 1290 | return false; |
| 1291 | } |
| 1292 | |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1293 | static bool PointHitsLayer(const LayerImpl* layer, |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1294 | const gfx::PointF& screen_space_point, |
| 1295 | float* distance_to_intersection) { |
danakj | 5e6ff6d | 2015-09-05 04:43:44 | [diff] [blame] | 1296 | gfx::Rect content_rect(layer->bounds()); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1297 | if (!PointHitsRect(screen_space_point, |
| 1298 | layer->screen_space_transform(), |
| 1299 | content_rect, |
| 1300 | distance_to_intersection)) |
| 1301 | return false; |
| 1302 | |
| 1303 | // At this point, we think the point does hit the layer, but we need to walk |
| 1304 | // up the parents to ensure that the layer was not clipped in such a way |
| 1305 | // that the hit point actually should not hit the layer. |
| 1306 | if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer)) |
| 1307 | return false; |
| 1308 | |
| 1309 | // Skip the HUD layer. |
| 1310 | if (layer == layer->layer_tree_impl()->hud_layer()) |
| 1311 | return false; |
| 1312 | |
| 1313 | return true; |
| 1314 | } |
| 1315 | |
| 1316 | struct FindClosestMatchingLayerDataForRecursion { |
| 1317 | FindClosestMatchingLayerDataForRecursion() |
| 1318 | : closest_match(NULL), |
| 1319 | closest_distance(-std::numeric_limits<float>::infinity()) {} |
| 1320 | LayerImpl* closest_match; |
| 1321 | // Note that the positive z-axis points towards the camera, so bigger means |
| 1322 | // closer in this case, counterintuitively. |
| 1323 | float closest_distance; |
| 1324 | }; |
| 1325 | |
| 1326 | template <typename Functor> |
| 1327 | static void FindClosestMatchingLayer( |
| 1328 | const gfx::PointF& screen_space_point, |
| 1329 | LayerImpl* layer, |
| 1330 | const Functor& func, |
| 1331 | FindClosestMatchingLayerDataForRecursion* data_for_recursion) { |
vmpstr | 24b32b3e | 2015-06-09 22:39:33 | [diff] [blame] | 1332 | size_t children_size = layer->children().size(); |
| 1333 | for (size_t i = 0; i < children_size; ++i) { |
| 1334 | size_t index = children_size - 1 - i; |
| 1335 | FindClosestMatchingLayer(screen_space_point, layer->children()[index], func, |
| 1336 | data_for_recursion); |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | float distance_to_intersection = 0.f; |
| 1340 | if (func(layer) && |
| 1341 | PointHitsLayer(layer, screen_space_point, &distance_to_intersection) && |
| 1342 | ((!data_for_recursion->closest_match || |
| 1343 | distance_to_intersection > data_for_recursion->closest_distance))) { |
| 1344 | data_for_recursion->closest_distance = distance_to_intersection; |
| 1345 | data_for_recursion->closest_match = layer; |
| 1346 | } |
| 1347 | } |
| 1348 | |
| 1349 | static bool ScrollsAnyDrawnRenderSurfaceLayerListMember(LayerImpl* layer) { |
| 1350 | if (!layer->scrollable()) |
| 1351 | return false; |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 1352 | if (layer->layer_or_descendant_is_drawn()) |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1353 | return true; |
majidvp | 6cfcc36 | 2015-03-06 20:46:39 | [diff] [blame] | 1354 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1355 | if (!layer->scroll_children()) |
| 1356 | return false; |
| 1357 | for (std::set<LayerImpl*>::const_iterator it = |
| 1358 | layer->scroll_children()->begin(); |
| 1359 | it != layer->scroll_children()->end(); |
| 1360 | ++it) { |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 1361 | if ((*it)->layer_or_descendant_is_drawn()) |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1362 | return true; |
| 1363 | } |
| 1364 | return false; |
| 1365 | } |
| 1366 | |
| 1367 | struct FindScrollingLayerFunctor { |
| 1368 | bool operator()(LayerImpl* layer) const { |
| 1369 | return ScrollsAnyDrawnRenderSurfaceLayerListMember(layer); |
| 1370 | } |
| 1371 | }; |
| 1372 | |
| 1373 | LayerImpl* LayerTreeImpl::FindFirstScrollingLayerThatIsHitByPoint( |
| 1374 | const gfx::PointF& screen_space_point) { |
| 1375 | FindClosestMatchingLayerDataForRecursion data_for_recursion; |
| 1376 | FindClosestMatchingLayer(screen_space_point, |
| 1377 | root_layer(), |
| 1378 | FindScrollingLayerFunctor(), |
| 1379 | &data_for_recursion); |
| 1380 | return data_for_recursion.closest_match; |
| 1381 | } |
| 1382 | |
| 1383 | struct HitTestVisibleScrollableOrTouchableFunctor { |
| 1384 | bool operator()(LayerImpl* layer) const { |
| 1385 | return layer->IsDrawnRenderSurfaceLayerListMember() || |
| 1386 | ScrollsAnyDrawnRenderSurfaceLayerListMember(layer) || |
| 1387 | !layer->touch_event_handler_region().IsEmpty() || |
| 1388 | layer->have_wheel_event_handlers(); |
| 1389 | } |
| 1390 | }; |
| 1391 | |
| 1392 | LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPoint( |
| 1393 | const gfx::PointF& screen_space_point) { |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 1394 | if (!root_layer()) |
| 1395 | return NULL; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 1396 | bool update_lcd_text = false; |
| 1397 | if (!UpdateDrawProperties(update_lcd_text)) |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 1398 | return NULL; |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1399 | FindClosestMatchingLayerDataForRecursion data_for_recursion; |
| 1400 | FindClosestMatchingLayer(screen_space_point, |
| 1401 | root_layer(), |
| 1402 | HitTestVisibleScrollableOrTouchableFunctor(), |
| 1403 | &data_for_recursion); |
| 1404 | return data_for_recursion.closest_match; |
| 1405 | } |
| 1406 | |
| 1407 | static bool LayerHasTouchEventHandlersAt(const gfx::PointF& screen_space_point, |
| 1408 | LayerImpl* layer_impl) { |
| 1409 | if (layer_impl->touch_event_handler_region().IsEmpty()) |
| 1410 | return false; |
| 1411 | |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 1412 | if (!PointHitsRegion(screen_space_point, layer_impl->screen_space_transform(), |
| 1413 | layer_impl->touch_event_handler_region())) |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1414 | return false; |
| 1415 | |
| 1416 | // At this point, we think the point does hit the touch event handler region |
| 1417 | // on the layer, but we need to walk up the parents to ensure that the layer |
| 1418 | // was not clipped in such a way that the hit point actually should not hit |
| 1419 | // the layer. |
| 1420 | if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
| 1421 | return false; |
| 1422 | |
| 1423 | return true; |
| 1424 | } |
| 1425 | |
ccameron | 3b60736 | 2015-02-02 22:46:29 | [diff] [blame] | 1426 | struct FindWheelEventLayerFunctor { |
| 1427 | bool operator()(LayerImpl* layer) const { |
| 1428 | return layer->have_wheel_event_handlers(); |
| 1429 | } |
| 1430 | }; |
| 1431 | |
| 1432 | LayerImpl* LayerTreeImpl::FindLayerWithWheelHandlerThatIsHitByPoint( |
| 1433 | const gfx::PointF& screen_space_point) { |
| 1434 | if (!root_layer()) |
| 1435 | return NULL; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 1436 | bool update_lcd_text = false; |
| 1437 | if (!UpdateDrawProperties(update_lcd_text)) |
ccameron | 3b60736 | 2015-02-02 22:46:29 | [diff] [blame] | 1438 | return NULL; |
| 1439 | FindWheelEventLayerFunctor func; |
| 1440 | FindClosestMatchingLayerDataForRecursion data_for_recursion; |
| 1441 | FindClosestMatchingLayer(screen_space_point, root_layer(), func, |
| 1442 | &data_for_recursion); |
| 1443 | return data_for_recursion.closest_match; |
| 1444 | } |
| 1445 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1446 | struct FindTouchEventLayerFunctor { |
| 1447 | bool operator()(LayerImpl* layer) const { |
| 1448 | return LayerHasTouchEventHandlersAt(screen_space_point, layer); |
| 1449 | } |
| 1450 | const gfx::PointF screen_space_point; |
| 1451 | }; |
| 1452 | |
| 1453 | LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 1454 | const gfx::PointF& screen_space_point) { |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 1455 | if (!root_layer()) |
| 1456 | return NULL; |
enne | af5bda3 | 2015-02-19 01:27:36 | [diff] [blame] | 1457 | bool update_lcd_text = false; |
| 1458 | if (!UpdateDrawProperties(update_lcd_text)) |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 1459 | return NULL; |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1460 | FindTouchEventLayerFunctor func = {screen_space_point}; |
| 1461 | FindClosestMatchingLayerDataForRecursion data_for_recursion; |
| 1462 | FindClosestMatchingLayer( |
| 1463 | screen_space_point, root_layer(), func, &data_for_recursion); |
| 1464 | return data_for_recursion.closest_match; |
| 1465 | } |
| 1466 | |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 1467 | void LayerTreeImpl::RegisterSelection(const LayerSelection& selection) { |
| 1468 | selection_ = selection; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1469 | } |
| 1470 | |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 1471 | static ViewportSelectionBound ComputeViewportSelectionBound( |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1472 | const LayerSelectionBound& layer_bound, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1473 | LayerImpl* layer, |
| 1474 | float device_scale_factor) { |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1475 | ViewportSelectionBound viewport_bound; |
| 1476 | viewport_bound.type = layer_bound.type; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1477 | |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1478 | if (!layer || layer_bound.type == SELECTION_BOUND_EMPTY) |
| 1479 | return viewport_bound; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1480 | |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 1481 | gfx::PointF layer_top = layer_bound.edge_top; |
| 1482 | gfx::PointF layer_bottom = layer_bound.edge_bottom; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1483 | |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1484 | bool clipped = false; |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 1485 | gfx::PointF screen_top = |
| 1486 | MathUtil::MapPoint(layer->screen_space_transform(), layer_top, &clipped); |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1487 | gfx::PointF screen_bottom = MathUtil::MapPoint( |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 1488 | layer->screen_space_transform(), layer_bottom, &clipped); |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1489 | |
ajuma | 9384b9c2 | 2015-09-17 20:35:03 | [diff] [blame] | 1490 | // MapPoint can produce points with NaN components (even when no inputs are |
| 1491 | // NaN). Since consumers of ViewportSelectionBounds may round |edge_top| or |
| 1492 | // |edge_bottom| (and since rounding will crash on NaN), we return an empty |
| 1493 | // bound instead. |
| 1494 | if (std::isnan(screen_top.x()) || std::isnan(screen_top.y()) || |
| 1495 | std::isnan(screen_bottom.x()) || std::isnan(screen_bottom.y())) |
| 1496 | return ViewportSelectionBound(); |
| 1497 | |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1498 | const float inv_scale = 1.f / device_scale_factor; |
| 1499 | viewport_bound.edge_top = gfx::ScalePoint(screen_top, inv_scale); |
| 1500 | viewport_bound.edge_bottom = gfx::ScalePoint(screen_bottom, inv_scale); |
| 1501 | |
| 1502 | // The bottom edge point is used for visibility testing as it is the logical |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1503 | // focal point for bound selection handles (this may change in the future). |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1504 | // Shifting the visibility point fractionally inward ensures that neighboring |
| 1505 | // or logically coincident layers aligned to integral DPI coordinates will not |
| 1506 | // spuriously occlude the bound. |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 1507 | gfx::Vector2dF visibility_offset = layer_top - layer_bottom; |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1508 | visibility_offset.Scale(device_scale_factor / visibility_offset.Length()); |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 1509 | gfx::PointF visibility_point = layer_bottom + visibility_offset; |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1510 | if (visibility_point.x() <= 0) |
| 1511 | visibility_point.set_x(visibility_point.x() + device_scale_factor); |
| 1512 | visibility_point = MathUtil::MapPoint( |
| 1513 | layer->screen_space_transform(), visibility_point, &clipped); |
| 1514 | |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1515 | float intersect_distance = 0.f; |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1516 | viewport_bound.visible = |
| 1517 | PointHitsLayer(layer, visibility_point, &intersect_distance); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1518 | |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1519 | return viewport_bound; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1520 | } |
| 1521 | |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 1522 | void LayerTreeImpl::GetViewportSelection(ViewportSelection* selection) { |
| 1523 | DCHECK(selection); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1524 | |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 1525 | selection->start = ComputeViewportSelectionBound( |
| 1526 | selection_.start, |
| 1527 | selection_.start.layer_id ? LayerById(selection_.start.layer_id) : NULL, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1528 | device_scale_factor()); |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 1529 | selection->is_editable = selection_.is_editable; |
| 1530 | selection->is_empty_text_form_control = selection_.is_empty_text_form_control; |
| 1531 | if (selection->start.type == SELECTION_BOUND_CENTER || |
| 1532 | selection->start.type == SELECTION_BOUND_EMPTY) { |
| 1533 | selection->end = selection->start; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1534 | } else { |
jdduke | 449b529 | 2015-04-23 19:36:44 | [diff] [blame] | 1535 | selection->end = ComputeViewportSelectionBound( |
| 1536 | selection_.end, |
| 1537 | selection_.end.layer_id ? LayerById(selection_.end.layer_id) : NULL, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1538 | device_scale_factor()); |
| 1539 | } |
| 1540 | } |
| 1541 | |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 1542 | void LayerTreeImpl::InputScrollAnimationFinished() { |
| 1543 | layer_tree_host_impl_->ScrollEnd(); |
| 1544 | } |
| 1545 | |
vmpstr | 56ace23 | 2014-10-09 20:16:28 | [diff] [blame] | 1546 | bool LayerTreeImpl::SmoothnessTakesPriority() const { |
| 1547 | return layer_tree_host_impl_->GetTreePriority() == SMOOTHNESS_TAKES_PRIORITY; |
| 1548 | } |
| 1549 | |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1550 | BlockingTaskRunner* LayerTreeImpl::BlockingMainThreadTaskRunner() const { |
| 1551 | return proxy()->blocking_main_thread_task_runner(); |
| 1552 | } |
| 1553 | |
sunnyps | 7d073dc | 2015-04-16 23:29:12 | [diff] [blame] | 1554 | VideoFrameControllerClient* LayerTreeImpl::GetVideoFrameControllerClient() |
| 1555 | const { |
| 1556 | return layer_tree_host_impl_; |
| 1557 | } |
| 1558 | |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 1559 | void LayerTreeImpl::SetPendingPageScaleAnimation( |
| 1560 | scoped_ptr<PendingPageScaleAnimation> pending_animation) { |
| 1561 | pending_page_scale_animation_ = pending_animation.Pass(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 1562 | } |
| 1563 | |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 1564 | scoped_ptr<PendingPageScaleAnimation> |
| 1565 | LayerTreeImpl::TakePendingPageScaleAnimation() { |
| 1566 | return pending_page_scale_animation_.Pass(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 1567 | } |
| 1568 | |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1569 | bool LayerTreeImpl::IsAnimatingFilterProperty(const LayerImpl* layer) const { |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 1570 | LayerTreeType tree_type = |
| 1571 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING; |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1572 | return layer_tree_host_impl_->animation_host() |
| 1573 | ? layer_tree_host_impl_->animation_host() |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 1574 | ->IsAnimatingFilterProperty(layer->id(), tree_type) |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1575 | : false; |
| 1576 | } |
| 1577 | |
| 1578 | bool LayerTreeImpl::IsAnimatingOpacityProperty(const LayerImpl* layer) const { |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 1579 | LayerTreeType tree_type = |
| 1580 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING; |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1581 | return layer_tree_host_impl_->animation_host() |
| 1582 | ? layer_tree_host_impl_->animation_host() |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 1583 | ->IsAnimatingOpacityProperty(layer->id(), tree_type) |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1584 | : false; |
| 1585 | } |
| 1586 | |
| 1587 | bool LayerTreeImpl::IsAnimatingTransformProperty(const LayerImpl* layer) const { |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 1588 | LayerTreeType tree_type = |
| 1589 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING; |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1590 | return layer_tree_host_impl_->animation_host() |
| 1591 | ? layer_tree_host_impl_->animation_host() |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 1592 | ->IsAnimatingTransformProperty(layer->id(), tree_type) |
| 1593 | : false; |
| 1594 | } |
| 1595 | |
| 1596 | bool LayerTreeImpl::HasPotentiallyRunningFilterAnimation( |
| 1597 | const LayerImpl* layer) const { |
| 1598 | LayerTreeType tree_type = |
| 1599 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING; |
| 1600 | return layer_tree_host_impl_->animation_host() |
| 1601 | ? layer_tree_host_impl_->animation_host() |
| 1602 | ->HasPotentiallyRunningFilterAnimation(layer->id(), |
| 1603 | tree_type) |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1604 | : false; |
| 1605 | } |
| 1606 | |
| 1607 | bool LayerTreeImpl::HasPotentiallyRunningOpacityAnimation( |
| 1608 | const LayerImpl* layer) const { |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 1609 | LayerTreeType tree_type = |
| 1610 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING; |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1611 | return layer_tree_host_impl_->animation_host() |
| 1612 | ? layer_tree_host_impl_->animation_host() |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 1613 | ->HasPotentiallyRunningOpacityAnimation(layer->id(), |
| 1614 | tree_type) |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1615 | : false; |
| 1616 | } |
| 1617 | |
| 1618 | bool LayerTreeImpl::HasPotentiallyRunningTransformAnimation( |
| 1619 | const LayerImpl* layer) const { |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 1620 | LayerTreeType tree_type = |
| 1621 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING; |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1622 | return layer_tree_host_impl_->animation_host() |
| 1623 | ? layer_tree_host_impl_->animation_host() |
ajuma | 315a478 | 2015-07-24 21:16:34 | [diff] [blame] | 1624 | ->HasPotentiallyRunningTransformAnimation(layer->id(), |
| 1625 | tree_type) |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1626 | : false; |
| 1627 | } |
| 1628 | |
ajuma | e742527 | 2015-07-13 18:37:34 | [diff] [blame] | 1629 | bool LayerTreeImpl::HasAnyAnimationTargetingProperty( |
| 1630 | const LayerImpl* layer, |
| 1631 | Animation::TargetProperty property) const { |
| 1632 | return layer_tree_host_impl_->animation_host() |
| 1633 | ? layer_tree_host_impl_->animation_host() |
| 1634 | ->HasAnyAnimationTargetingProperty(layer->id(), property) |
| 1635 | : false; |
| 1636 | } |
| 1637 | |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1638 | bool LayerTreeImpl::FilterIsAnimatingOnImplOnly(const LayerImpl* layer) const { |
| 1639 | return layer_tree_host_impl_->animation_host() |
| 1640 | ? layer_tree_host_impl_->animation_host() |
| 1641 | ->FilterIsAnimatingOnImplOnly(layer->id()) |
| 1642 | : false; |
| 1643 | } |
| 1644 | |
| 1645 | bool LayerTreeImpl::OpacityIsAnimatingOnImplOnly(const LayerImpl* layer) const { |
| 1646 | return layer_tree_host_impl_->animation_host() |
| 1647 | ? layer_tree_host_impl_->animation_host() |
| 1648 | ->OpacityIsAnimatingOnImplOnly(layer->id()) |
| 1649 | : false; |
| 1650 | } |
| 1651 | |
| 1652 | bool LayerTreeImpl::TransformIsAnimatingOnImplOnly( |
| 1653 | const LayerImpl* layer) const { |
| 1654 | return layer_tree_host_impl_->animation_host() |
| 1655 | ? layer_tree_host_impl_->animation_host() |
| 1656 | ->TransformIsAnimatingOnImplOnly(layer->id()) |
| 1657 | : false; |
| 1658 | } |
| 1659 | |
| 1660 | bool LayerTreeImpl::HasOnlyTranslationTransforms(const LayerImpl* layer) const { |
ajuma | dd3592c | 2015-08-20 15:07:29 | [diff] [blame] | 1661 | LayerTreeType tree_type = |
| 1662 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING; |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1663 | return layer_tree_host_impl_->animation_host() |
| 1664 | ? layer_tree_host_impl_->animation_host() |
ajuma | dd3592c | 2015-08-20 15:07:29 | [diff] [blame] | 1665 | ->HasOnlyTranslationTransforms(layer->id(), tree_type) |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1666 | : true; |
| 1667 | } |
| 1668 | |
| 1669 | bool LayerTreeImpl::MaximumTargetScale(const LayerImpl* layer, |
| 1670 | float* max_scale) const { |
| 1671 | *max_scale = 0.f; |
ajuma | dd3592c | 2015-08-20 15:07:29 | [diff] [blame] | 1672 | LayerTreeType tree_type = |
| 1673 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING; |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1674 | return layer_tree_host_impl_->animation_host() |
| 1675 | ? layer_tree_host_impl_->animation_host()->MaximumTargetScale( |
ajuma | dd3592c | 2015-08-20 15:07:29 | [diff] [blame] | 1676 | layer->id(), tree_type, max_scale) |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1677 | : true; |
| 1678 | } |
| 1679 | |
| 1680 | bool LayerTreeImpl::AnimationStartScale(const LayerImpl* layer, |
| 1681 | float* start_scale) const { |
| 1682 | *start_scale = 0.f; |
ajuma | dd3592c | 2015-08-20 15:07:29 | [diff] [blame] | 1683 | LayerTreeType tree_type = |
| 1684 | IsActiveTree() ? LayerTreeType::ACTIVE : LayerTreeType::PENDING; |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1685 | return layer_tree_host_impl_->animation_host() |
| 1686 | ? layer_tree_host_impl_->animation_host()->AnimationStartScale( |
ajuma | dd3592c | 2015-08-20 15:07:29 | [diff] [blame] | 1687 | layer->id(), tree_type, start_scale) |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1688 | : true; |
| 1689 | } |
| 1690 | |
| 1691 | bool LayerTreeImpl::HasFilterAnimationThatInflatesBounds( |
| 1692 | const LayerImpl* layer) const { |
| 1693 | return layer_tree_host_impl_->animation_host() |
| 1694 | ? layer_tree_host_impl_->animation_host() |
| 1695 | ->HasFilterAnimationThatInflatesBounds(layer->id()) |
| 1696 | : false; |
| 1697 | } |
| 1698 | |
| 1699 | bool LayerTreeImpl::HasTransformAnimationThatInflatesBounds( |
| 1700 | const LayerImpl* layer) const { |
| 1701 | return layer_tree_host_impl_->animation_host() |
| 1702 | ? layer_tree_host_impl_->animation_host() |
| 1703 | ->HasTransformAnimationThatInflatesBounds(layer->id()) |
| 1704 | : false; |
| 1705 | } |
| 1706 | |
| 1707 | bool LayerTreeImpl::HasAnimationThatInflatesBounds( |
| 1708 | const LayerImpl* layer) const { |
| 1709 | return layer_tree_host_impl_->animation_host() |
| 1710 | ? layer_tree_host_impl_->animation_host() |
| 1711 | ->HasAnimationThatInflatesBounds(layer->id()) |
| 1712 | : false; |
| 1713 | } |
| 1714 | |
| 1715 | bool LayerTreeImpl::FilterAnimationBoundsForBox(const LayerImpl* layer, |
| 1716 | const gfx::BoxF& box, |
| 1717 | gfx::BoxF* bounds) const { |
| 1718 | return layer_tree_host_impl_->animation_host() |
| 1719 | ? layer_tree_host_impl_->animation_host() |
| 1720 | ->FilterAnimationBoundsForBox(layer->id(), box, bounds) |
| 1721 | : false; |
| 1722 | } |
| 1723 | |
| 1724 | bool LayerTreeImpl::TransformAnimationBoundsForBox(const LayerImpl* layer, |
| 1725 | const gfx::BoxF& box, |
| 1726 | gfx::BoxF* bounds) const { |
| 1727 | *bounds = gfx::BoxF(); |
| 1728 | return layer_tree_host_impl_->animation_host() |
| 1729 | ? layer_tree_host_impl_->animation_host() |
| 1730 | ->TransformAnimationBoundsForBox(layer->id(), box, bounds) |
| 1731 | : true; |
| 1732 | } |
| 1733 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1734 | } // namespace cc |