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