[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 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 7 | #include <limits> |
| 8 | #include <set> |
| 9 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 10 | #include "base/debug/trace_event.h" |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 11 | #include "base/debug/trace_event_argument.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 12 | #include "cc/animation/keyframed_animation_curve.h" |
| 13 | #include "cc/animation/scrollbar_animation_controller.h" |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 14 | #include "cc/animation/scrollbar_animation_controller_linear_fade.h" |
| 15 | #include "cc/animation/scrollbar_animation_controller_thinning.h" |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 16 | #include "cc/base/math_util.h" |
| 17 | #include "cc/base/util.h" |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 18 | #include "cc/debug/devtools_instrumentation.h" |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 19 | #include "cc/debug/traced_value.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 20 | #include "cc/layers/heads_up_display_layer_impl.h" |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 21 | #include "cc/layers/layer.h" |
[email protected] | 34ba1ffb | 2014-03-05 06:55:03 | [diff] [blame] | 22 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 23 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 24 | #include "cc/layers/scrollbar_layer_impl_base.h" |
[email protected] | e104219 | 2013-11-08 05:44:24 | [diff] [blame] | 25 | #include "cc/resources/ui_resource_request.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 26 | #include "cc/trees/layer_tree_host_common.h" |
| 27 | #include "cc/trees/layer_tree_host_impl.h" |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 28 | #include "cc/trees/occlusion_tracker.h" |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 29 | #include "ui/gfx/point_conversions.h" |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 30 | #include "ui/gfx/size_conversions.h" |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 31 | #include "ui/gfx/vector2d_conversions.h" |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 32 | |
| 33 | namespace cc { |
| 34 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 35 | // This class exists to split the LayerScrollOffsetDelegate between the |
| 36 | // InnerViewportScrollLayer and the OuterViewportScrollLayer in a manner |
| 37 | // that never requires the embedder or LayerImpl to know about. |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 38 | class LayerScrollOffsetDelegateProxy : public LayerImpl::ScrollOffsetDelegate { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 39 | public: |
| 40 | LayerScrollOffsetDelegateProxy(LayerImpl* layer, |
| 41 | LayerScrollOffsetDelegate* delegate, |
| 42 | LayerTreeImpl* layer_tree) |
| 43 | : layer_(layer), delegate_(delegate), layer_tree_impl_(layer_tree) {} |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 44 | virtual ~LayerScrollOffsetDelegateProxy() {} |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 45 | |
| 46 | gfx::Vector2dF last_set_scroll_offset() const { |
| 47 | return last_set_scroll_offset_; |
| 48 | } |
| 49 | |
| 50 | // LayerScrollOffsetDelegate implementation. |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 51 | virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_offset) OVERRIDE { |
| 52 | last_set_scroll_offset_ = new_offset; |
| 53 | layer_tree_impl_->UpdateScrollOffsetDelegate(); |
| 54 | } |
| 55 | |
| 56 | virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { |
| 57 | return layer_tree_impl_->GetDelegatedScrollOffset(layer_); |
| 58 | } |
| 59 | |
| 60 | virtual bool IsExternalFlingActive() const OVERRIDE { |
| 61 | return delegate_->IsExternalFlingActive(); |
| 62 | } |
| 63 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 64 | private: |
| 65 | LayerImpl* layer_; |
| 66 | LayerScrollOffsetDelegate* delegate_; |
| 67 | LayerTreeImpl* layer_tree_impl_; |
| 68 | gfx::Vector2dF last_set_scroll_offset_; |
| 69 | }; |
| 70 | |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 71 | LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 72 | : layer_tree_host_impl_(layer_tree_host_impl), |
| 73 | source_frame_number_(-1), |
| 74 | hud_layer_(0), |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 75 | currently_scrolling_layer_(NULL), |
| 76 | root_layer_scroll_offset_delegate_(NULL), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 77 | background_color_(0), |
| 78 | has_transparent_background_(false), |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 79 | page_scale_layer_(NULL), |
| 80 | inner_viewport_scroll_layer_(NULL), |
| 81 | outer_viewport_scroll_layer_(NULL), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 82 | page_scale_factor_(1), |
| 83 | page_scale_delta_(1), |
| 84 | sent_page_scale_delta_(1), |
| 85 | min_page_scale_factor_(0), |
| 86 | max_page_scale_factor_(0), |
| 87 | scrolling_layer_id_from_previous_tree_(0), |
| 88 | contents_textures_purged_(false), |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 89 | requires_high_res_to_draw_(false), |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 90 | viewport_size_invalid_(false), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 91 | needs_update_draw_properties_(true), |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 92 | needs_full_tree_sync_(true), |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 93 | next_activation_forces_redraw_(false), |
[email protected] | 759dc9f | 2014-07-23 19:18:51 | [diff] [blame] | 94 | has_ever_been_drawn_(false), |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 95 | render_surface_layer_list_id_(0) { |
| 96 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 97 | |
| 98 | LayerTreeImpl::~LayerTreeImpl() { |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 99 | BreakSwapPromises(SwapPromise::SWAP_FAILS); |
| 100 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 101 | // Need to explicitly clear the tree prior to destroying this so that |
| 102 | // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. |
[email protected] | df17af5 | 2014-02-06 02:20:40 | [diff] [blame] | 103 | DCHECK(!root_layer_); |
| 104 | DCHECK(layers_with_copy_output_request_.empty()); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 105 | } |
| 106 | |
[email protected] | df17af5 | 2014-02-06 02:20:40 | [diff] [blame] | 107 | void LayerTreeImpl::Shutdown() { root_layer_.reset(); } |
| 108 | |
[email protected] | aeef2f0 | 2014-05-10 12:15:48 | [diff] [blame] | 109 | void LayerTreeImpl::ReleaseResources() { |
| 110 | if (root_layer_) |
| 111 | ReleaseResourcesRecursive(root_layer_.get()); |
| 112 | } |
| 113 | |
[email protected] | d35cd7b2 | 2014-01-29 14:32:46 | [diff] [blame] | 114 | void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 115 | if (inner_viewport_scroll_layer_) |
| 116 | inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
| 117 | if (outer_viewport_scroll_layer_) |
| 118 | outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
| 119 | inner_viewport_scroll_delegate_proxy_.reset(); |
| 120 | outer_viewport_scroll_delegate_proxy_.reset(); |
| 121 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 122 | root_layer_ = layer.Pass(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 123 | currently_scrolling_layer_ = NULL; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 124 | inner_viewport_scroll_layer_ = NULL; |
| 125 | outer_viewport_scroll_layer_ = NULL; |
| 126 | page_scale_layer_ = NULL; |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 127 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 128 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 129 | } |
| 130 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 131 | LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const { |
| 132 | return inner_viewport_scroll_layer_; |
| 133 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 134 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 135 | LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const { |
| 136 | return outer_viewport_scroll_layer_; |
| 137 | } |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 138 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 139 | gfx::Vector2dF LayerTreeImpl::TotalScrollOffset() const { |
| 140 | gfx::Vector2dF offset; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 141 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 142 | if (inner_viewport_scroll_layer_) |
| 143 | offset += inner_viewport_scroll_layer_->TotalScrollOffset(); |
| 144 | |
| 145 | if (outer_viewport_scroll_layer_) |
| 146 | offset += outer_viewport_scroll_layer_->TotalScrollOffset(); |
| 147 | |
| 148 | return offset; |
| 149 | } |
| 150 | |
| 151 | gfx::Vector2dF LayerTreeImpl::TotalMaxScrollOffset() const { |
| 152 | gfx::Vector2dF offset; |
| 153 | |
| 154 | if (inner_viewport_scroll_layer_) |
| 155 | offset += inner_viewport_scroll_layer_->MaxScrollOffset(); |
| 156 | |
| 157 | if (outer_viewport_scroll_layer_) |
| 158 | offset += outer_viewport_scroll_layer_->MaxScrollOffset(); |
| 159 | |
| 160 | return offset; |
| 161 | } |
| 162 | gfx::Vector2dF LayerTreeImpl::TotalScrollDelta() const { |
| 163 | DCHECK(inner_viewport_scroll_layer_); |
| 164 | gfx::Vector2dF delta = inner_viewport_scroll_layer_->ScrollDelta(); |
| 165 | |
| 166 | if (outer_viewport_scroll_layer_) |
| 167 | delta += outer_viewport_scroll_layer_->ScrollDelta(); |
| 168 | |
| 169 | return delta; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { |
| 173 | // Clear all data structures that have direct references to the layer tree. |
| 174 | scrolling_layer_id_from_previous_tree_ = |
| 175 | currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 176 | if (inner_viewport_scroll_layer_) |
| 177 | inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
| 178 | if (outer_viewport_scroll_layer_) |
| 179 | outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
| 180 | inner_viewport_scroll_delegate_proxy_.reset(); |
| 181 | outer_viewport_scroll_delegate_proxy_.reset(); |
| 182 | inner_viewport_scroll_layer_ = NULL; |
| 183 | outer_viewport_scroll_layer_ = NULL; |
| 184 | page_scale_layer_ = NULL; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 185 | currently_scrolling_layer_ = NULL; |
| 186 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 187 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 188 | set_needs_update_draw_properties(); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 189 | return root_layer_.Pass(); |
| 190 | } |
| 191 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 192 | void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 193 | // The request queue should have been processed and does not require a push. |
| 194 | DCHECK_EQ(ui_resource_request_queue_.size(), 0u); |
| 195 | |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 196 | if (next_activation_forces_redraw_) { |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 197 | target_tree->ForceRedrawNextActivation(); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 198 | next_activation_forces_redraw_ = false; |
| 199 | } |
| 200 | |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 201 | target_tree->PassSwapPromises(&swap_promise_list_); |
| 202 | |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 203 | target_tree->SetPageScaleValues( |
| 204 | page_scale_factor(), min_page_scale_factor(), max_page_scale_factor(), |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 205 | target_tree->page_scale_delta() / target_tree->sent_page_scale_delta()); |
| 206 | target_tree->set_sent_page_scale_delta(1); |
| 207 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 208 | if (page_scale_layer_ && inner_viewport_scroll_layer_) { |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 209 | target_tree->SetViewportLayersFromIds( |
| 210 | page_scale_layer_->id(), |
| 211 | inner_viewport_scroll_layer_->id(), |
| 212 | outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() |
| 213 | : Layer::INVALID_ID); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 214 | } else { |
| 215 | target_tree->ClearViewportLayers(); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 216 | } |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 217 | |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 218 | target_tree->RegisterSelection(selection_start_, selection_end_); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 219 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 220 | // This should match the property synchronization in |
| 221 | // LayerTreeHost::finishCommitOnImplThread(). |
| 222 | target_tree->set_source_frame_number(source_frame_number()); |
| 223 | target_tree->set_background_color(background_color()); |
| 224 | target_tree->set_has_transparent_background(has_transparent_background()); |
| 225 | |
| 226 | if (ContentsTexturesPurged()) |
| 227 | target_tree->SetContentsTexturesPurged(); |
| 228 | else |
| 229 | target_tree->ResetContentsTexturesPurged(); |
| 230 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 231 | if (ViewportSizeInvalid()) |
| 232 | target_tree->SetViewportSizeInvalid(); |
| 233 | else |
| 234 | target_tree->ResetViewportSizeInvalid(); |
| 235 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 236 | if (hud_layer()) |
| 237 | target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 238 | LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 239 | target_tree->root_layer(), hud_layer()->id()))); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 240 | else |
| 241 | target_tree->set_hud_layer(NULL); |
[email protected] | 759dc9f | 2014-07-23 19:18:51 | [diff] [blame] | 242 | |
| 243 | target_tree->has_ever_been_drawn_ = false; |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 244 | } |
| 245 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 246 | LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const { |
| 247 | return inner_viewport_scroll_layer_ |
| 248 | ? inner_viewport_scroll_layer_->scroll_clip_layer() |
| 249 | : NULL; |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 253 | DCHECK(IsActiveTree()); |
| 254 | return currently_scrolling_layer_; |
| 255 | } |
| 256 | |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 257 | void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) { |
| 258 | if (currently_scrolling_layer_ == layer) |
| 259 | return; |
| 260 | |
| 261 | if (currently_scrolling_layer_ && |
| 262 | currently_scrolling_layer_->scrollbar_animation_controller()) |
[email protected] | 1dc0616 | 2014-03-26 22:54:45 | [diff] [blame] | 263 | currently_scrolling_layer_->scrollbar_animation_controller() |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 264 | ->DidScrollEnd(); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 265 | currently_scrolling_layer_ = layer; |
| 266 | if (layer && layer->scrollbar_animation_controller()) |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 267 | layer->scrollbar_animation_controller()->DidScrollBegin(); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 268 | } |
| 269 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 270 | void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 271 | SetCurrentlyScrollingLayer(NULL); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 272 | scrolling_layer_id_from_previous_tree_ = 0; |
| 273 | } |
| 274 | |
[email protected] | 1f15bed | 2014-03-11 02:50:44 | [diff] [blame] | 275 | float LayerTreeImpl::VerticalAdjust(const int clip_layer_id) const { |
| 276 | LayerImpl* container_layer = InnerViewportContainerLayer(); |
| 277 | if (!container_layer || clip_layer_id != container_layer->id()) |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 278 | return 0.f; |
| 279 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 280 | return layer_tree_host_impl_->VerticalAdjust(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | namespace { |
| 284 | |
| 285 | void ForceScrollbarParameterUpdateAfterScaleChange(LayerImpl* current_layer) { |
| 286 | if (!current_layer) |
| 287 | return; |
| 288 | |
| 289 | while (current_layer) { |
| 290 | current_layer->ScrollbarParametersDidChange(); |
| 291 | current_layer = current_layer->parent(); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | } // namespace |
| 296 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 297 | void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor, |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 298 | float min_page_scale_factor, float max_page_scale_factor) { |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 299 | SetPageScaleValues(page_scale_factor, min_page_scale_factor, |
| 300 | max_page_scale_factor, page_scale_delta_); |
| 301 | } |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 302 | |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 303 | void LayerTreeImpl::SetPageScaleDelta(float delta) { |
| 304 | SetPageScaleValues(page_scale_factor_, min_page_scale_factor_, |
| 305 | max_page_scale_factor_, delta); |
| 306 | } |
| 307 | |
| 308 | void LayerTreeImpl::SetPageScaleValues(float page_scale_factor, |
| 309 | float min_page_scale_factor, float max_page_scale_factor, |
| 310 | float page_scale_delta) { |
| 311 | bool page_scale_changed = |
| 312 | min_page_scale_factor != min_page_scale_factor_ || |
| 313 | max_page_scale_factor != max_page_scale_factor_ || |
| 314 | page_scale_factor != page_scale_factor_; |
[email protected] | 7265e74e | 2014-02-07 23:43:06 | [diff] [blame] | 315 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 316 | min_page_scale_factor_ = min_page_scale_factor; |
| 317 | max_page_scale_factor_ = max_page_scale_factor; |
| 318 | page_scale_factor_ = page_scale_factor; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 319 | |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 320 | float total = page_scale_factor_ * page_scale_delta; |
| 321 | if (min_page_scale_factor_ && total < min_page_scale_factor_) |
| 322 | page_scale_delta = min_page_scale_factor_ / page_scale_factor_; |
| 323 | else if (max_page_scale_factor_ && total > max_page_scale_factor_) |
| 324 | page_scale_delta = max_page_scale_factor_ / page_scale_factor_; |
| 325 | |
| 326 | if (page_scale_delta_ == page_scale_delta && !page_scale_changed) |
| 327 | return; |
| 328 | |
| 329 | if (page_scale_delta_ != page_scale_delta) { |
| 330 | page_scale_delta_ = page_scale_delta; |
| 331 | |
| 332 | if (IsActiveTree()) { |
| 333 | LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree(); |
| 334 | if (pending_tree) { |
| 335 | DCHECK_EQ(1, pending_tree->sent_page_scale_delta()); |
| 336 | pending_tree->SetPageScaleDelta( |
| 337 | page_scale_delta_ / sent_page_scale_delta_); |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | set_needs_update_draw_properties(); |
| 342 | } |
| 343 | |
[email protected] | 22f200a | 2013-10-09 18:08:29 | [diff] [blame] | 344 | if (root_layer_scroll_offset_delegate_) { |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 345 | root_layer_scroll_offset_delegate_->UpdateRootLayerState( |
| 346 | TotalScrollOffset(), |
| 347 | TotalMaxScrollOffset(), |
| 348 | ScrollableSize(), |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 349 | total_page_scale_factor(), |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 350 | min_page_scale_factor_, |
| 351 | max_page_scale_factor_); |
[email protected] | 22f200a | 2013-10-09 18:08:29 | [diff] [blame] | 352 | } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 353 | |
| 354 | ForceScrollbarParameterUpdateAfterScaleChange(page_scale_layer()); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 355 | } |
| 356 | |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 357 | gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 358 | if (outer_viewport_scroll_layer_) |
| 359 | return layer_tree_host_impl_->UnscaledScrollableViewportSize(); |
| 360 | else |
| 361 | return gfx::ScaleSize( |
| 362 | layer_tree_host_impl_->UnscaledScrollableViewportSize(), |
| 363 | 1.0f / total_page_scale_factor()); |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 364 | } |
| 365 | |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 366 | gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 367 | LayerImpl* root_scroll_layer = OuterViewportScrollLayer() |
| 368 | ? OuterViewportScrollLayer() |
| 369 | : InnerViewportScrollLayer(); |
| 370 | if (!root_scroll_layer || root_scroll_layer->children().empty()) |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 371 | return gfx::Rect(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 372 | LayerImpl* layer = root_scroll_layer->children()[0]; |
[email protected] | 8a82269 | 2014-02-12 17:30:55 | [diff] [blame] | 373 | return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(), |
| 374 | gfx::Rect(layer->content_bounds())); |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 375 | } |
| 376 | |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 377 | static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) { |
| 378 | layer->ApplySentScrollDeltasFromAbortedCommit(); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 379 | } |
| 380 | |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 381 | void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() { |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 382 | DCHECK(IsActiveTree()); |
| 383 | |
| 384 | page_scale_factor_ *= sent_page_scale_delta_; |
| 385 | page_scale_delta_ /= sent_page_scale_delta_; |
| 386 | sent_page_scale_delta_ = 1.f; |
| 387 | |
| 388 | if (!root_layer()) |
| 389 | return; |
| 390 | |
| 391 | LayerTreeHostCommon::CallFunctionForSubtree( |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 392 | root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo)); |
| 393 | } |
| 394 | |
[email protected] | daea3d4 | 2013-10-23 17:04:50 | [diff] [blame] | 395 | static void ApplyScrollDeltasSinceBeginMainFrameTo(LayerImpl* layer) { |
| 396 | layer->ApplyScrollDeltasSinceBeginMainFrame(); |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 397 | } |
| 398 | |
[email protected] | daea3d4 | 2013-10-23 17:04:50 | [diff] [blame] | 399 | void LayerTreeImpl::ApplyScrollDeltasSinceBeginMainFrame() { |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 400 | DCHECK(IsPendingTree()); |
| 401 | if (!root_layer()) |
| 402 | return; |
| 403 | |
| 404 | LayerTreeHostCommon::CallFunctionForSubtree( |
[email protected] | daea3d4 | 2013-10-23 17:04:50 | [diff] [blame] | 405 | root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginMainFrameTo)); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 406 | } |
| 407 | |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 408 | void LayerTreeImpl::SetViewportLayersFromIds( |
| 409 | int page_scale_layer_id, |
| 410 | int inner_viewport_scroll_layer_id, |
| 411 | int outer_viewport_scroll_layer_id) { |
| 412 | page_scale_layer_ = LayerById(page_scale_layer_id); |
| 413 | DCHECK(page_scale_layer_); |
| 414 | |
| 415 | inner_viewport_scroll_layer_ = |
| 416 | LayerById(inner_viewport_scroll_layer_id); |
| 417 | DCHECK(inner_viewport_scroll_layer_); |
| 418 | |
| 419 | outer_viewport_scroll_layer_ = |
| 420 | LayerById(outer_viewport_scroll_layer_id); |
| 421 | DCHECK(outer_viewport_scroll_layer_ || |
| 422 | outer_viewport_scroll_layer_id == Layer::INVALID_ID); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 423 | |
| 424 | if (!root_layer_scroll_offset_delegate_) |
| 425 | return; |
| 426 | |
| 427 | inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 428 | new LayerScrollOffsetDelegateProxy(inner_viewport_scroll_layer_, |
| 429 | root_layer_scroll_offset_delegate_, |
| 430 | this)); |
| 431 | |
| 432 | if (outer_viewport_scroll_layer_) |
| 433 | outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 434 | new LayerScrollOffsetDelegateProxy(outer_viewport_scroll_layer_, |
| 435 | root_layer_scroll_offset_delegate_, |
| 436 | this)); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | void LayerTreeImpl::ClearViewportLayers() { |
| 440 | page_scale_layer_ = NULL; |
| 441 | inner_viewport_scroll_layer_ = NULL; |
| 442 | outer_viewport_scroll_layer_ = NULL; |
| 443 | } |
| 444 | |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 445 | bool LayerTreeImpl::UpdateDrawProperties() { |
| 446 | if (!needs_update_draw_properties_) |
| 447 | return true; |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 448 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 449 | // For max_texture_size. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 450 | if (!layer_tree_host_impl_->renderer()) |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 451 | return false; |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 452 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 453 | if (!root_layer()) |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 454 | return false; |
| 455 | |
| 456 | needs_update_draw_properties_ = false; |
| 457 | render_surface_layer_list_.clear(); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 458 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 459 | { |
[email protected] | 7a52f43e | 2013-07-10 01:58:47 | [diff] [blame] | 460 | TRACE_EVENT2("cc", |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 461 | "LayerTreeImpl::UpdateDrawProperties", |
| 462 | "IsActive", |
[email protected] | 7a52f43e | 2013-07-10 01:58:47 | [diff] [blame] | 463 | IsActiveTree(), |
| 464 | "SourceFrameNumber", |
| 465 | source_frame_number_); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 466 | LayerImpl* page_scale_layer = |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 467 | page_scale_layer_ ? page_scale_layer_ : InnerViewportContainerLayer(); |
[email protected] | c05dfbb | 2014-07-10 22:49:04 | [diff] [blame] | 468 | bool can_render_to_separate_surface = !resourceless_software_draw(); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 469 | |
| 470 | ++render_surface_layer_list_id_; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 471 | LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 472 | root_layer(), |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 473 | DrawViewportSize(), |
| 474 | layer_tree_host_impl_->DrawTransform(), |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 475 | device_scale_factor(), |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 476 | total_page_scale_factor(), |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 477 | page_scale_layer, |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 478 | MaxTextureSize(), |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 479 | settings().can_use_lcd_text, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 480 | can_render_to_separate_surface, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 481 | settings().layer_transforms_should_scale_layer_contents, |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 482 | &render_surface_layer_list_, |
| 483 | render_surface_layer_list_id_); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 484 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 485 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 486 | |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 487 | { |
| 488 | TRACE_EVENT2("cc", |
| 489 | "LayerTreeImpl::UpdateTilePriorities", |
| 490 | "IsActive", |
| 491 | IsActiveTree(), |
| 492 | "SourceFrameNumber", |
| 493 | source_frame_number_); |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 494 | scoped_ptr<OcclusionTracker<LayerImpl> > occlusion_tracker; |
| 495 | if (settings().use_occlusion_for_tile_prioritization) { |
| 496 | occlusion_tracker.reset(new OcclusionTracker<LayerImpl>( |
| 497 | root_layer()->render_surface()->content_rect())); |
| 498 | occlusion_tracker->set_minimum_tracking_size( |
| 499 | settings().minimum_occlusion_tracking_size); |
| 500 | } |
| 501 | |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 502 | // LayerIterator is used here instead of CallFunctionForSubtree to only |
| 503 | // UpdateTilePriorities on layers that will be visible (and thus have valid |
| 504 | // draw properties) and not because any ordering is required. |
[email protected] | ba1b33e | 2014-02-28 16:44:51 | [diff] [blame] | 505 | typedef LayerIterator<LayerImpl> LayerIteratorType; |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 506 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 507 | for (LayerIteratorType it = |
| 508 | LayerIteratorType::Begin(&render_surface_layer_list_); |
| 509 | it != end; |
| 510 | ++it) { |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 511 | if (occlusion_tracker) |
| 512 | occlusion_tracker->EnterLayer(it); |
| 513 | |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 514 | LayerImpl* layer = *it; |
[email protected] | 6355d2d | 2014-05-07 15:07:27 | [diff] [blame] | 515 | if (it.represents_itself()) |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 516 | layer->UpdateTiles(occlusion_tracker.get()); |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 517 | |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 518 | if (!it.represents_contributing_render_surface()) { |
| 519 | if (occlusion_tracker) |
| 520 | occlusion_tracker->LeaveLayer(it); |
[email protected] | 6355d2d | 2014-05-07 15:07:27 | [diff] [blame] | 521 | continue; |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 522 | } |
[email protected] | 6355d2d | 2014-05-07 15:07:27 | [diff] [blame] | 523 | |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 524 | if (layer->mask_layer()) |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 525 | layer->mask_layer()->UpdateTiles(occlusion_tracker.get()); |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 526 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 527 | layer->replica_layer()->mask_layer()->UpdateTiles( |
| 528 | occlusion_tracker.get()); |
| 529 | |
| 530 | if (occlusion_tracker) |
| 531 | occlusion_tracker->LeaveLayer(it); |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 532 | } |
| 533 | } |
| 534 | |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 535 | DCHECK(!needs_update_draw_properties_) << |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 536 | "CalcDrawProperties should not set_needs_update_draw_properties()"; |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 537 | return true; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 538 | } |
| 539 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 540 | const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const { |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 541 | // If this assert triggers, then the list is dirty. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 542 | DCHECK(!needs_update_draw_properties_); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 543 | return render_surface_layer_list_; |
| 544 | } |
| 545 | |
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 546 | gfx::Size LayerTreeImpl::ScrollableSize() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 547 | LayerImpl* root_scroll_layer = OuterViewportScrollLayer() |
| 548 | ? OuterViewportScrollLayer() |
| 549 | : InnerViewportScrollLayer(); |
| 550 | if (!root_scroll_layer || root_scroll_layer->children().empty()) |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 551 | return gfx::Size(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 552 | return root_scroll_layer->children()[0]->bounds(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 553 | } |
| 554 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 555 | LayerImpl* LayerTreeImpl::LayerById(int id) { |
| 556 | LayerIdMap::iterator iter = layer_id_map_.find(id); |
| 557 | return iter != layer_id_map_.end() ? iter->second : NULL; |
| 558 | } |
| 559 | |
| 560 | void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { |
| 561 | DCHECK(!LayerById(layer->id())); |
| 562 | layer_id_map_[layer->id()] = layer; |
| 563 | } |
| 564 | |
| 565 | void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { |
| 566 | DCHECK(LayerById(layer->id())); |
| 567 | layer_id_map_.erase(layer->id()); |
| 568 | } |
| 569 | |
[email protected] | aebf462 | 2014-07-14 16:57:59 | [diff] [blame] | 570 | size_t LayerTreeImpl::NumLayers() { |
| 571 | return layer_id_map_.size(); |
| 572 | } |
| 573 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 574 | void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { |
[email protected] | a90fac7 | 2013-06-06 18:56:13 | [diff] [blame] | 575 | pending_tree->SetCurrentlyScrollingLayer( |
| 576 | LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), |
| 577 | currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 578 | } |
| 579 | |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 580 | static void DidBecomeActiveRecursive(LayerImpl* layer) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 581 | layer->DidBecomeActive(); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 582 | if (layer->mask_layer()) |
| 583 | layer->mask_layer()->DidBecomeActive(); |
| 584 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 585 | layer->replica_layer()->mask_layer()->DidBecomeActive(); |
| 586 | |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 587 | for (size_t i = 0; i < layer->children().size(); ++i) |
| 588 | DidBecomeActiveRecursive(layer->children()[i]); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | void LayerTreeImpl::DidBecomeActive() { |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 592 | if (next_activation_forces_redraw_) { |
| 593 | layer_tree_host_impl_->SetFullRootLayerDamage(); |
| 594 | next_activation_forces_redraw_ = false; |
| 595 | } |
| 596 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 597 | if (scrolling_layer_id_from_previous_tree_) { |
| 598 | currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | 7dcf563 | 2014-06-25 01:11:55 | [diff] [blame] | 599 | root_layer(), scrolling_layer_id_from_previous_tree_); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 600 | } |
| 601 | |
[email protected] | 7dcf563 | 2014-06-25 01:11:55 | [diff] [blame] | 602 | // Always reset this flag on activation, as we would only have activated |
| 603 | // if we were in a good state. |
| 604 | ResetRequiresHighResToDraw(); |
| 605 | |
| 606 | if (root_layer()) |
| 607 | DidBecomeActiveRecursive(root_layer()); |
| 608 | |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 609 | devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(), |
| 610 | source_frame_number_); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 611 | } |
| 612 | |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 613 | bool LayerTreeImpl::ContentsTexturesPurged() const { |
| 614 | return contents_textures_purged_; |
| 615 | } |
| 616 | |
| 617 | void LayerTreeImpl::SetContentsTexturesPurged() { |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 618 | if (contents_textures_purged_) |
| 619 | return; |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 620 | contents_textures_purged_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 621 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | void LayerTreeImpl::ResetContentsTexturesPurged() { |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 625 | if (!contents_textures_purged_) |
| 626 | return; |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 627 | contents_textures_purged_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 628 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 629 | } |
| 630 | |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 631 | void LayerTreeImpl::SetRequiresHighResToDraw() { |
| 632 | requires_high_res_to_draw_ = true; |
| 633 | } |
| 634 | |
| 635 | void LayerTreeImpl::ResetRequiresHighResToDraw() { |
| 636 | requires_high_res_to_draw_ = false; |
| 637 | } |
| 638 | |
| 639 | bool LayerTreeImpl::RequiresHighResToDraw() const { |
| 640 | return requires_high_res_to_draw_; |
| 641 | } |
| 642 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 643 | bool LayerTreeImpl::ViewportSizeInvalid() const { |
| 644 | return viewport_size_invalid_; |
| 645 | } |
| 646 | |
| 647 | void LayerTreeImpl::SetViewportSizeInvalid() { |
| 648 | viewport_size_invalid_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 649 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 650 | } |
| 651 | |
| 652 | void LayerTreeImpl::ResetViewportSizeInvalid() { |
| 653 | viewport_size_invalid_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 654 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 655 | } |
| 656 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 657 | Proxy* LayerTreeImpl::proxy() const { |
| 658 | return layer_tree_host_impl_->proxy(); |
| 659 | } |
| 660 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 661 | const LayerTreeSettings& LayerTreeImpl::settings() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 662 | return layer_tree_host_impl_->settings(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 663 | } |
| 664 | |
[email protected] | 7a8bcd26 | 2014-01-15 12:54:58 | [diff] [blame] | 665 | const RendererCapabilitiesImpl& LayerTreeImpl::GetRendererCapabilities() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 666 | return layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | bf5b3a0 | 2013-02-13 02:02:52 | [diff] [blame] | 667 | } |
| 668 | |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 669 | ContextProvider* LayerTreeImpl::context_provider() const { |
| 670 | return output_surface()->context_provider(); |
| 671 | } |
| 672 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 673 | OutputSurface* LayerTreeImpl::output_surface() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 674 | return layer_tree_host_impl_->output_surface(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | ResourceProvider* LayerTreeImpl::resource_provider() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 678 | return layer_tree_host_impl_->resource_provider(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | TileManager* LayerTreeImpl::tile_manager() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 682 | return layer_tree_host_impl_->tile_manager(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 683 | } |
| 684 | |
| 685 | FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 686 | return layer_tree_host_impl_->fps_counter(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 687 | } |
| 688 | |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 689 | PaintTimeCounter* LayerTreeImpl::paint_time_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 690 | return layer_tree_host_impl_->paint_time_counter(); |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 691 | } |
| 692 | |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 693 | MemoryHistory* LayerTreeImpl::memory_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 694 | return layer_tree_host_impl_->memory_history(); |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 695 | } |
| 696 | |
[email protected] | c05dfbb | 2014-07-10 22:49:04 | [diff] [blame] | 697 | bool LayerTreeImpl::resourceless_software_draw() const { |
| 698 | return layer_tree_host_impl_->GetDrawMode() == |
| 699 | DRAW_MODE_RESOURCELESS_SOFTWARE; |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 700 | } |
| 701 | |
[email protected] | 4a6c091d | 2014-04-24 21:06:46 | [diff] [blame] | 702 | gfx::Size LayerTreeImpl::device_viewport_size() const { |
| 703 | return layer_tree_host_impl_->device_viewport_size(); |
| 704 | } |
| 705 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 706 | bool LayerTreeImpl::IsActiveTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 707 | return layer_tree_host_impl_->active_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | bool LayerTreeImpl::IsPendingTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 711 | return layer_tree_host_impl_->pending_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 712 | } |
| 713 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 714 | bool LayerTreeImpl::IsRecycleTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 715 | return layer_tree_host_impl_->recycle_tree() == this; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 716 | } |
| 717 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 718 | LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 719 | LayerTreeImpl* tree = layer_tree_host_impl_->active_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 720 | if (!tree) |
| 721 | return NULL; |
| 722 | return tree->LayerById(id); |
| 723 | } |
| 724 | |
| 725 | LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 726 | LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 727 | if (!tree) |
| 728 | return NULL; |
| 729 | return tree->LayerById(id); |
| 730 | } |
| 731 | |
[email protected] | 71618ed | 2014-07-24 02:23:45 | [diff] [blame] | 732 | LayerImpl* LayerTreeImpl::FindRecycleTreeLayerById(int id) { |
| 733 | LayerTreeImpl* tree = layer_tree_host_impl_->recycle_tree(); |
| 734 | if (!tree) |
| 735 | return NULL; |
| 736 | return tree->LayerById(id); |
| 737 | } |
| 738 | |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 739 | int LayerTreeImpl::MaxTextureSize() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 740 | return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size; |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 741 | } |
| 742 | |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 743 | bool LayerTreeImpl::PinchGestureActive() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 744 | return layer_tree_host_impl_->pinch_gesture_active(); |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 745 | } |
| 746 | |
[email protected] | 04c5900d | 2014-08-18 13:38:36 | [diff] [blame^] | 747 | BeginFrameArgs LayerTreeImpl::CurrentBeginFrameArgs() const { |
| 748 | return layer_tree_host_impl_->CurrentBeginFrameArgs(); |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 749 | } |
| 750 | |
[email protected] | c92195e | 2014-05-07 18:18:49 | [diff] [blame] | 751 | base::TimeDelta LayerTreeImpl::begin_impl_frame_interval() const { |
| 752 | return layer_tree_host_impl_->begin_impl_frame_interval(); |
| 753 | } |
| 754 | |
[email protected] | d7eb8c7 | 2013-03-23 22:57:13 | [diff] [blame] | 755 | void LayerTreeImpl::SetNeedsCommit() { |
| 756 | layer_tree_host_impl_->SetNeedsCommit(); |
| 757 | } |
| 758 | |
[email protected] | bd532459 | 2014-07-31 09:09:33 | [diff] [blame] | 759 | gfx::Rect LayerTreeImpl::DeviceViewport() const { |
| 760 | return layer_tree_host_impl_->DeviceViewport(); |
| 761 | } |
| 762 | |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 763 | gfx::Size LayerTreeImpl::DrawViewportSize() const { |
| 764 | return layer_tree_host_impl_->DrawViewportSize(); |
| 765 | } |
| 766 | |
[email protected] | bd532459 | 2014-07-31 09:09:33 | [diff] [blame] | 767 | const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const { |
| 768 | return layer_tree_host_impl_->ViewportRectForTilePriority(); |
| 769 | } |
| 770 | |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 771 | scoped_ptr<ScrollbarAnimationController> |
| 772 | LayerTreeImpl::CreateScrollbarAnimationController(LayerImpl* scrolling_layer) { |
| 773 | DCHECK(settings().scrollbar_fade_delay_ms); |
| 774 | DCHECK(settings().scrollbar_fade_duration_ms); |
| 775 | base::TimeDelta delay = |
| 776 | base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms); |
| 777 | base::TimeDelta duration = |
| 778 | base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms); |
| 779 | switch (settings().scrollbar_animator) { |
| 780 | case LayerTreeSettings::LinearFade: { |
| 781 | return ScrollbarAnimationControllerLinearFade::Create( |
| 782 | scrolling_layer, layer_tree_host_impl_, delay, duration) |
| 783 | .PassAs<ScrollbarAnimationController>(); |
| 784 | } |
| 785 | case LayerTreeSettings::Thinning: { |
| 786 | return ScrollbarAnimationControllerThinning::Create( |
| 787 | scrolling_layer, layer_tree_host_impl_, delay, duration) |
| 788 | .PassAs<ScrollbarAnimationController>(); |
| 789 | } |
| 790 | case LayerTreeSettings::NoAnimator: |
| 791 | NOTREACHED(); |
| 792 | break; |
| 793 | } |
| 794 | return scoped_ptr<ScrollbarAnimationController>(); |
[email protected] | 2ea5aba | 2013-09-11 14:26:56 | [diff] [blame] | 795 | } |
| 796 | |
[email protected] | b8384e2 | 2013-12-03 02:20:48 | [diff] [blame] | 797 | void LayerTreeImpl::DidAnimateScrollOffset() { |
| 798 | layer_tree_host_impl_->DidAnimateScrollOffset(); |
| 799 | } |
| 800 | |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 801 | bool LayerTreeImpl::use_gpu_rasterization() const { |
| 802 | return layer_tree_host_impl_->use_gpu_rasterization(); |
| 803 | } |
| 804 | |
[email protected] | 473f1f2 | 2014-05-22 08:19:17 | [diff] [blame] | 805 | bool LayerTreeImpl::create_low_res_tiling() const { |
| 806 | return layer_tree_host_impl_->create_low_res_tiling(); |
| 807 | } |
| 808 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 809 | void LayerTreeImpl::SetNeedsRedraw() { |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 810 | layer_tree_host_impl_->SetNeedsRedraw(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 811 | } |
| 812 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 813 | const LayerTreeDebugState& LayerTreeImpl::debug_state() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 814 | return layer_tree_host_impl_->debug_state(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | float LayerTreeImpl::device_scale_factor() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 818 | return layer_tree_host_impl_->device_scale_factor(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 819 | } |
| 820 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 821 | DebugRectHistory* LayerTreeImpl::debug_rect_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 822 | return layer_tree_host_impl_->debug_rect_history(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 823 | } |
| 824 | |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 825 | AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 826 | return layer_tree_host_impl_->animation_registrar(); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 827 | } |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 828 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 829 | void LayerTreeImpl::AsValueInto(base::debug::TracedValue* state) const { |
| 830 | TracedValue::MakeDictIntoImplicitSnapshot(state, "cc::LayerTreeImpl", this); |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 831 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 832 | state->BeginDictionary("root_layer"); |
| 833 | root_layer_->AsValueInto(state); |
| 834 | state->EndDictionary(); |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 835 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 836 | state->BeginArray("render_surface_layer_list"); |
[email protected] | ba1b33e | 2014-02-28 16:44:51 | [diff] [blame] | 837 | typedef LayerIterator<LayerImpl> LayerIteratorType; |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 838 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 839 | for (LayerIteratorType it = LayerIteratorType::Begin( |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 840 | &render_surface_layer_list_); it != end; ++it) { |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 841 | if (!it.represents_itself()) |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 842 | continue; |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 843 | TracedValue::AppendIDRef(*it, state); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 844 | } |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 845 | state->EndArray(); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 846 | } |
| 847 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 848 | void LayerTreeImpl::SetRootLayerScrollOffsetDelegate( |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 849 | LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) { |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 850 | if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate) |
| 851 | return; |
| 852 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 853 | if (!root_layer_scroll_offset_delegate) { |
| 854 | // Make sure we remove the proxies from their layers before |
| 855 | // releasing them. |
| 856 | if (InnerViewportScrollLayer()) |
| 857 | InnerViewportScrollLayer()->SetScrollOffsetDelegate(NULL); |
| 858 | if (OuterViewportScrollLayer()) |
| 859 | OuterViewportScrollLayer()->SetScrollOffsetDelegate(NULL); |
| 860 | inner_viewport_scroll_delegate_proxy_.reset(); |
| 861 | outer_viewport_scroll_delegate_proxy_.reset(); |
[email protected] | d35cd7b2 | 2014-01-29 14:32:46 | [diff] [blame] | 862 | } |
| 863 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 864 | root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate; |
| 865 | |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 866 | if (root_layer_scroll_offset_delegate_) { |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 867 | root_layer_scroll_offset_delegate_->UpdateRootLayerState( |
| 868 | TotalScrollOffset(), |
| 869 | TotalMaxScrollOffset(), |
| 870 | ScrollableSize(), |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 871 | total_page_scale_factor(), |
| 872 | min_page_scale_factor(), |
| 873 | max_page_scale_factor()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 874 | |
| 875 | if (inner_viewport_scroll_layer_) { |
| 876 | inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 877 | new LayerScrollOffsetDelegateProxy(InnerViewportScrollLayer(), |
| 878 | root_layer_scroll_offset_delegate_, |
| 879 | this)); |
| 880 | inner_viewport_scroll_layer_->SetScrollOffsetDelegate( |
| 881 | inner_viewport_scroll_delegate_proxy_.get()); |
| 882 | } |
| 883 | |
| 884 | if (outer_viewport_scroll_layer_) { |
| 885 | outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 886 | new LayerScrollOffsetDelegateProxy(OuterViewportScrollLayer(), |
| 887 | root_layer_scroll_offset_delegate_, |
| 888 | this)); |
| 889 | outer_viewport_scroll_layer_->SetScrollOffsetDelegate( |
| 890 | outer_viewport_scroll_delegate_proxy_.get()); |
| 891 | } |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 892 | } |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 893 | } |
| 894 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 895 | void LayerTreeImpl::UpdateScrollOffsetDelegate() { |
| 896 | DCHECK(InnerViewportScrollLayer()); |
| 897 | DCHECK(root_layer_scroll_offset_delegate_); |
| 898 | |
| 899 | gfx::Vector2dF offset = |
| 900 | inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 901 | |
| 902 | if (OuterViewportScrollLayer()) |
| 903 | offset += outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 904 | |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 905 | root_layer_scroll_offset_delegate_->UpdateRootLayerState( |
| 906 | offset, |
| 907 | TotalMaxScrollOffset(), |
| 908 | ScrollableSize(), |
| 909 | total_page_scale_factor(), |
| 910 | min_page_scale_factor(), |
| 911 | max_page_scale_factor()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 912 | } |
| 913 | |
| 914 | gfx::Vector2dF LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) { |
| 915 | DCHECK(root_layer_scroll_offset_delegate_); |
| 916 | DCHECK(InnerViewportScrollLayer()); |
| 917 | if (layer == InnerViewportScrollLayer() && !OuterViewportScrollLayer()) |
| 918 | return root_layer_scroll_offset_delegate_->GetTotalScrollOffset(); |
| 919 | |
| 920 | // If we get here, we have both inner/outer viewports, and need to distribute |
| 921 | // the scroll offset between them. |
| 922 | DCHECK(inner_viewport_scroll_delegate_proxy_); |
| 923 | DCHECK(outer_viewport_scroll_delegate_proxy_); |
| 924 | gfx::Vector2dF inner_viewport_offset = |
| 925 | inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 926 | gfx::Vector2dF outer_viewport_offset = |
| 927 | outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 928 | |
| 929 | // It may be nothing has changed. |
| 930 | gfx::Vector2dF delegate_offset = |
| 931 | root_layer_scroll_offset_delegate_->GetTotalScrollOffset(); |
| 932 | if (inner_viewport_offset + outer_viewport_offset == delegate_offset) { |
| 933 | if (layer == InnerViewportScrollLayer()) |
| 934 | return inner_viewport_offset; |
| 935 | else |
| 936 | return outer_viewport_offset; |
| 937 | } |
| 938 | |
| 939 | gfx::Vector2d max_outer_viewport_scroll_offset = |
| 940 | OuterViewportScrollLayer()->MaxScrollOffset(); |
| 941 | |
| 942 | outer_viewport_offset = delegate_offset - inner_viewport_offset; |
| 943 | outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset); |
| 944 | outer_viewport_offset.SetToMax(gfx::Vector2d()); |
| 945 | |
| 946 | if (layer == OuterViewportScrollLayer()) |
| 947 | return outer_viewport_offset; |
| 948 | |
| 949 | inner_viewport_offset = delegate_offset - outer_viewport_offset; |
| 950 | |
| 951 | return inner_viewport_offset; |
| 952 | } |
| 953 | |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 954 | void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) { |
| 955 | DCHECK(swap_promise); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 956 | swap_promise_list_.push_back(swap_promise.Pass()); |
| 957 | } |
| 958 | |
| 959 | void LayerTreeImpl::PassSwapPromises( |
| 960 | ScopedPtrVector<SwapPromise>* new_swap_promise) { |
| 961 | swap_promise_list_.insert_and_take(swap_promise_list_.end(), |
| 962 | *new_swap_promise); |
| 963 | new_swap_promise->clear(); |
| 964 | } |
| 965 | |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 966 | void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) { |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 967 | for (size_t i = 0; i < swap_promise_list_.size(); i++) |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 968 | swap_promise_list_[i]->DidSwap(metadata); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 969 | swap_promise_list_.clear(); |
| 970 | } |
| 971 | |
| 972 | void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) { |
| 973 | for (size_t i = 0; i < swap_promise_list_.size(); i++) |
| 974 | swap_promise_list_[i]->DidNotSwap(reason); |
| 975 | swap_promise_list_.clear(); |
| 976 | } |
| 977 | |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 978 | void LayerTreeImpl::DidModifyTilePriorities() { |
| 979 | layer_tree_host_impl_->DidModifyTilePriorities(); |
[email protected] | fcb846d | 2013-05-22 01:42:36 | [diff] [blame] | 980 | } |
| 981 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 982 | void LayerTreeImpl::set_ui_resource_request_queue( |
| 983 | const UIResourceRequestQueue& queue) { |
| 984 | ui_resource_request_queue_ = queue; |
| 985 | } |
| 986 | |
| 987 | ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource( |
| 988 | UIResourceId uid) const { |
| 989 | return layer_tree_host_impl_->ResourceIdForUIResource(uid); |
| 990 | } |
| 991 | |
[email protected] | 709c954 | 2013-10-26 01:43:51 | [diff] [blame] | 992 | bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const { |
| 993 | return layer_tree_host_impl_->IsUIResourceOpaque(uid); |
| 994 | } |
| 995 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 996 | void LayerTreeImpl::ProcessUIResourceRequestQueue() { |
| 997 | while (ui_resource_request_queue_.size() > 0) { |
| 998 | UIResourceRequest req = ui_resource_request_queue_.front(); |
| 999 | ui_resource_request_queue_.pop_front(); |
| 1000 | |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 1001 | switch (req.GetType()) { |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1002 | case UIResourceRequest::UIResourceCreate: |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 1003 | layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap()); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1004 | break; |
| 1005 | case UIResourceRequest::UIResourceDelete: |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 1006 | layer_tree_host_impl_->DeleteUIResource(req.GetId()); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1007 | break; |
[email protected] | f28d64d | 2013-08-27 04:17:45 | [diff] [blame] | 1008 | case UIResourceRequest::UIResourceInvalidRequest: |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1009 | NOTREACHED(); |
| 1010 | break; |
| 1011 | } |
| 1012 | } |
[email protected] | 127bdc1a | 2013-09-11 01:44:48 | [diff] [blame] | 1013 | |
| 1014 | // If all UI resource evictions were not recreated by processing this queue, |
| 1015 | // then another commit is required. |
| 1016 | if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
| 1017 | layer_tree_host_impl_->SetNeedsCommit(); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1018 | } |
| 1019 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1020 | void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) { |
| 1021 | // Only the active tree needs to know about layers with copy requests, as |
| 1022 | // they are aborted if not serviced during draw. |
| 1023 | DCHECK(IsActiveTree()); |
| 1024 | |
[email protected] | a4ee1281 | 2014-02-06 17:33:38 | [diff] [blame] | 1025 | // DCHECK(std::find(layers_with_copy_output_request_.begin(), |
| 1026 | // layers_with_copy_output_request_.end(), |
| 1027 | // layer) == layers_with_copy_output_request_.end()); |
| 1028 | // TODO(danakj): Remove this once crash is found crbug.com/309777 |
| 1029 | for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) { |
| 1030 | CHECK(layers_with_copy_output_request_[i] != layer) |
| 1031 | << i << " of " << layers_with_copy_output_request_.size(); |
| 1032 | } |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1033 | layers_with_copy_output_request_.push_back(layer); |
| 1034 | } |
| 1035 | |
| 1036 | void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) { |
| 1037 | // Only the active tree needs to know about layers with copy requests, as |
| 1038 | // they are aborted if not serviced during draw. |
| 1039 | DCHECK(IsActiveTree()); |
| 1040 | |
| 1041 | std::vector<LayerImpl*>::iterator it = std::find( |
| 1042 | layers_with_copy_output_request_.begin(), |
| 1043 | layers_with_copy_output_request_.end(), |
| 1044 | layer); |
| 1045 | DCHECK(it != layers_with_copy_output_request_.end()); |
[email protected] | f5de9e5b | 2013-07-30 22:26:57 | [diff] [blame] | 1046 | layers_with_copy_output_request_.erase(it); |
[email protected] | a4ee1281 | 2014-02-06 17:33:38 | [diff] [blame] | 1047 | |
| 1048 | // TODO(danakj): Remove this once crash is found crbug.com/309777 |
| 1049 | for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) { |
| 1050 | CHECK(layers_with_copy_output_request_[i] != layer) |
| 1051 | << i << " of " << layers_with_copy_output_request_.size(); |
| 1052 | } |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1053 | } |
| 1054 | |
[email protected] | 5352637 | 2013-12-07 04:31:50 | [diff] [blame] | 1055 | const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest() |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1056 | const { |
| 1057 | // Only the active tree needs to know about layers with copy requests, as |
| 1058 | // they are aborted if not serviced during draw. |
| 1059 | DCHECK(IsActiveTree()); |
| 1060 | |
| 1061 | return layers_with_copy_output_request_; |
| 1062 | } |
| 1063 | |
[email protected] | aeef2f0 | 2014-05-10 12:15:48 | [diff] [blame] | 1064 | void LayerTreeImpl::ReleaseResourcesRecursive(LayerImpl* current) { |
| 1065 | DCHECK(current); |
| 1066 | current->ReleaseResources(); |
| 1067 | if (current->mask_layer()) |
| 1068 | ReleaseResourcesRecursive(current->mask_layer()); |
| 1069 | if (current->replica_layer()) |
| 1070 | ReleaseResourcesRecursive(current->replica_layer()); |
| 1071 | for (size_t i = 0; i < current->children().size(); ++i) |
| 1072 | ReleaseResourcesRecursive(current->children()[i]); |
| 1073 | } |
| 1074 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1075 | template <typename LayerType> |
| 1076 | static inline bool LayerClipsSubtree(LayerType* layer) { |
| 1077 | return layer->masks_to_bounds() || layer->mask_layer(); |
| 1078 | } |
| 1079 | |
| 1080 | static bool PointHitsRect( |
| 1081 | const gfx::PointF& screen_space_point, |
| 1082 | const gfx::Transform& local_space_to_screen_space_transform, |
| 1083 | const gfx::RectF& local_space_rect, |
| 1084 | float* distance_to_camera) { |
| 1085 | // If the transform is not invertible, then assume that this point doesn't hit |
| 1086 | // this rect. |
| 1087 | gfx::Transform inverse_local_space_to_screen_space( |
| 1088 | gfx::Transform::kSkipInitialization); |
| 1089 | if (!local_space_to_screen_space_transform.GetInverse( |
| 1090 | &inverse_local_space_to_screen_space)) |
| 1091 | return false; |
| 1092 | |
| 1093 | // Transform the hit test point from screen space to the local space of the |
| 1094 | // given rect. |
| 1095 | bool clipped = false; |
| 1096 | gfx::Point3F planar_point = MathUtil::ProjectPoint3D( |
| 1097 | inverse_local_space_to_screen_space, screen_space_point, &clipped); |
| 1098 | gfx::PointF hit_test_point_in_local_space = |
| 1099 | gfx::PointF(planar_point.x(), planar_point.y()); |
| 1100 | |
| 1101 | // If ProjectPoint could not project to a valid value, then we assume that |
| 1102 | // this point doesn't hit this rect. |
| 1103 | if (clipped) |
| 1104 | return false; |
| 1105 | |
| 1106 | if (!local_space_rect.Contains(hit_test_point_in_local_space)) |
| 1107 | return false; |
| 1108 | |
| 1109 | if (distance_to_camera) { |
| 1110 | // To compute the distance to the camera, we have to take the planar point |
| 1111 | // and pull it back to world space and compute the displacement along the |
| 1112 | // z-axis. |
| 1113 | gfx::Point3F planar_point_in_screen_space(planar_point); |
| 1114 | local_space_to_screen_space_transform.TransformPoint( |
| 1115 | &planar_point_in_screen_space); |
| 1116 | *distance_to_camera = planar_point_in_screen_space.z(); |
| 1117 | } |
| 1118 | |
| 1119 | return true; |
| 1120 | } |
| 1121 | |
| 1122 | static bool PointHitsRegion(const gfx::PointF& screen_space_point, |
| 1123 | const gfx::Transform& screen_space_transform, |
| 1124 | const Region& layer_space_region, |
| 1125 | float layer_content_scale_x, |
| 1126 | float layer_content_scale_y) { |
| 1127 | // If the transform is not invertible, then assume that this point doesn't hit |
| 1128 | // this region. |
| 1129 | gfx::Transform inverse_screen_space_transform( |
| 1130 | gfx::Transform::kSkipInitialization); |
| 1131 | if (!screen_space_transform.GetInverse(&inverse_screen_space_transform)) |
| 1132 | return false; |
| 1133 | |
| 1134 | // Transform the hit test point from screen space to the local space of the |
| 1135 | // given region. |
| 1136 | bool clipped = false; |
| 1137 | gfx::PointF hit_test_point_in_content_space = MathUtil::ProjectPoint( |
| 1138 | inverse_screen_space_transform, screen_space_point, &clipped); |
| 1139 | gfx::PointF hit_test_point_in_layer_space = |
| 1140 | gfx::ScalePoint(hit_test_point_in_content_space, |
| 1141 | 1.f / layer_content_scale_x, |
| 1142 | 1.f / layer_content_scale_y); |
| 1143 | |
| 1144 | // If ProjectPoint could not project to a valid value, then we assume that |
| 1145 | // this point doesn't hit this region. |
| 1146 | if (clipped) |
| 1147 | return false; |
| 1148 | |
| 1149 | return layer_space_region.Contains( |
| 1150 | gfx::ToRoundedPoint(hit_test_point_in_layer_space)); |
| 1151 | } |
| 1152 | |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1153 | static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) { |
[email protected] | 0ec86f5 | 2014-06-12 20:54:03 | [diff] [blame] | 1154 | if (layer->scroll_parent()) |
| 1155 | return layer->scroll_parent(); |
| 1156 | if (layer->clip_parent()) |
| 1157 | return layer->clip_parent(); |
| 1158 | return layer->parent(); |
| 1159 | } |
| 1160 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1161 | static bool PointIsClippedBySurfaceOrClipRect( |
| 1162 | const gfx::PointF& screen_space_point, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1163 | const LayerImpl* layer) { |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1164 | // Walk up the layer tree and hit-test any render_surfaces and any layer |
| 1165 | // clip rects that are active. |
[email protected] | 0ec86f5 | 2014-06-12 20:54:03 | [diff] [blame] | 1166 | for (; layer; layer = GetNextClippingLayer(layer)) { |
| 1167 | if (layer->render_surface() && |
| 1168 | !PointHitsRect(screen_space_point, |
| 1169 | layer->render_surface()->screen_space_transform(), |
| 1170 | layer->render_surface()->content_rect(), |
| 1171 | NULL)) |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1172 | return true; |
| 1173 | |
[email protected] | 0ec86f5 | 2014-06-12 20:54:03 | [diff] [blame] | 1174 | if (LayerClipsSubtree(layer) && |
| 1175 | !PointHitsRect(screen_space_point, |
| 1176 | layer->screen_space_transform(), |
| 1177 | gfx::Rect(layer->content_bounds()), |
| 1178 | NULL)) |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1179 | return true; |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | // If we have finished walking all ancestors without having already exited, |
| 1183 | // then the point is not clipped by any ancestors. |
| 1184 | return false; |
| 1185 | } |
| 1186 | |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1187 | static bool PointHitsLayer(const LayerImpl* layer, |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1188 | const gfx::PointF& screen_space_point, |
| 1189 | float* distance_to_intersection) { |
| 1190 | gfx::RectF content_rect(layer->content_bounds()); |
| 1191 | if (!PointHitsRect(screen_space_point, |
| 1192 | layer->screen_space_transform(), |
| 1193 | content_rect, |
| 1194 | distance_to_intersection)) |
| 1195 | return false; |
| 1196 | |
| 1197 | // At this point, we think the point does hit the layer, but we need to walk |
| 1198 | // up the parents to ensure that the layer was not clipped in such a way |
| 1199 | // that the hit point actually should not hit the layer. |
| 1200 | if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer)) |
| 1201 | return false; |
| 1202 | |
| 1203 | // Skip the HUD layer. |
| 1204 | if (layer == layer->layer_tree_impl()->hud_layer()) |
| 1205 | return false; |
| 1206 | |
| 1207 | return true; |
| 1208 | } |
| 1209 | |
| 1210 | struct FindClosestMatchingLayerDataForRecursion { |
| 1211 | FindClosestMatchingLayerDataForRecursion() |
| 1212 | : closest_match(NULL), |
| 1213 | closest_distance(-std::numeric_limits<float>::infinity()) {} |
| 1214 | LayerImpl* closest_match; |
| 1215 | // Note that the positive z-axis points towards the camera, so bigger means |
| 1216 | // closer in this case, counterintuitively. |
| 1217 | float closest_distance; |
| 1218 | }; |
| 1219 | |
| 1220 | template <typename Functor> |
| 1221 | static void FindClosestMatchingLayer( |
| 1222 | const gfx::PointF& screen_space_point, |
| 1223 | LayerImpl* layer, |
| 1224 | const Functor& func, |
| 1225 | FindClosestMatchingLayerDataForRecursion* data_for_recursion) { |
| 1226 | for (int i = layer->children().size() - 1; i >= 0; --i) { |
| 1227 | FindClosestMatchingLayer( |
| 1228 | screen_space_point, layer->children()[i], func, data_for_recursion); |
| 1229 | } |
| 1230 | |
| 1231 | float distance_to_intersection = 0.f; |
| 1232 | if (func(layer) && |
| 1233 | PointHitsLayer(layer, screen_space_point, &distance_to_intersection) && |
| 1234 | ((!data_for_recursion->closest_match || |
| 1235 | distance_to_intersection > data_for_recursion->closest_distance))) { |
| 1236 | data_for_recursion->closest_distance = distance_to_intersection; |
| 1237 | data_for_recursion->closest_match = layer; |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | static bool ScrollsAnyDrawnRenderSurfaceLayerListMember(LayerImpl* layer) { |
| 1242 | if (!layer->scrollable()) |
| 1243 | return false; |
| 1244 | if (layer->IsDrawnRenderSurfaceLayerListMember()) |
| 1245 | return true; |
| 1246 | if (!layer->scroll_children()) |
| 1247 | return false; |
| 1248 | for (std::set<LayerImpl*>::const_iterator it = |
| 1249 | layer->scroll_children()->begin(); |
| 1250 | it != layer->scroll_children()->end(); |
| 1251 | ++it) { |
| 1252 | if ((*it)->IsDrawnRenderSurfaceLayerListMember()) |
| 1253 | return true; |
| 1254 | } |
| 1255 | return false; |
| 1256 | } |
| 1257 | |
| 1258 | struct FindScrollingLayerFunctor { |
| 1259 | bool operator()(LayerImpl* layer) const { |
| 1260 | return ScrollsAnyDrawnRenderSurfaceLayerListMember(layer); |
| 1261 | } |
| 1262 | }; |
| 1263 | |
| 1264 | LayerImpl* LayerTreeImpl::FindFirstScrollingLayerThatIsHitByPoint( |
| 1265 | const gfx::PointF& screen_space_point) { |
| 1266 | FindClosestMatchingLayerDataForRecursion data_for_recursion; |
| 1267 | FindClosestMatchingLayer(screen_space_point, |
| 1268 | root_layer(), |
| 1269 | FindScrollingLayerFunctor(), |
| 1270 | &data_for_recursion); |
| 1271 | return data_for_recursion.closest_match; |
| 1272 | } |
| 1273 | |
| 1274 | struct HitTestVisibleScrollableOrTouchableFunctor { |
| 1275 | bool operator()(LayerImpl* layer) const { |
| 1276 | return layer->IsDrawnRenderSurfaceLayerListMember() || |
| 1277 | ScrollsAnyDrawnRenderSurfaceLayerListMember(layer) || |
| 1278 | !layer->touch_event_handler_region().IsEmpty() || |
| 1279 | layer->have_wheel_event_handlers(); |
| 1280 | } |
| 1281 | }; |
| 1282 | |
| 1283 | LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPoint( |
| 1284 | const gfx::PointF& screen_space_point) { |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 1285 | if (!root_layer()) |
| 1286 | return NULL; |
| 1287 | if (!UpdateDrawProperties()) |
| 1288 | return NULL; |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1289 | FindClosestMatchingLayerDataForRecursion data_for_recursion; |
| 1290 | FindClosestMatchingLayer(screen_space_point, |
| 1291 | root_layer(), |
| 1292 | HitTestVisibleScrollableOrTouchableFunctor(), |
| 1293 | &data_for_recursion); |
| 1294 | return data_for_recursion.closest_match; |
| 1295 | } |
| 1296 | |
| 1297 | static bool LayerHasTouchEventHandlersAt(const gfx::PointF& screen_space_point, |
| 1298 | LayerImpl* layer_impl) { |
| 1299 | if (layer_impl->touch_event_handler_region().IsEmpty()) |
| 1300 | return false; |
| 1301 | |
| 1302 | if (!PointHitsRegion(screen_space_point, |
| 1303 | layer_impl->screen_space_transform(), |
| 1304 | layer_impl->touch_event_handler_region(), |
| 1305 | layer_impl->contents_scale_x(), |
| 1306 | layer_impl->contents_scale_y())) |
| 1307 | return false; |
| 1308 | |
| 1309 | // At this point, we think the point does hit the touch event handler region |
| 1310 | // on the layer, but we need to walk up the parents to ensure that the layer |
| 1311 | // was not clipped in such a way that the hit point actually should not hit |
| 1312 | // the layer. |
| 1313 | if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
| 1314 | return false; |
| 1315 | |
| 1316 | return true; |
| 1317 | } |
| 1318 | |
| 1319 | struct FindTouchEventLayerFunctor { |
| 1320 | bool operator()(LayerImpl* layer) const { |
| 1321 | return LayerHasTouchEventHandlersAt(screen_space_point, layer); |
| 1322 | } |
| 1323 | const gfx::PointF screen_space_point; |
| 1324 | }; |
| 1325 | |
| 1326 | LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 1327 | const gfx::PointF& screen_space_point) { |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 1328 | if (!root_layer()) |
| 1329 | return NULL; |
| 1330 | if (!UpdateDrawProperties()) |
| 1331 | return NULL; |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1332 | FindTouchEventLayerFunctor func = {screen_space_point}; |
| 1333 | FindClosestMatchingLayerDataForRecursion data_for_recursion; |
| 1334 | FindClosestMatchingLayer( |
| 1335 | screen_space_point, root_layer(), func, &data_for_recursion); |
| 1336 | return data_for_recursion.closest_match; |
| 1337 | } |
| 1338 | |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 1339 | void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& start, |
| 1340 | const LayerSelectionBound& end) { |
| 1341 | selection_start_ = start; |
| 1342 | selection_end_ = end; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1343 | } |
| 1344 | |
| 1345 | static ViewportSelectionBound ComputeViewportSelection( |
| 1346 | const LayerSelectionBound& bound, |
| 1347 | LayerImpl* layer, |
| 1348 | float device_scale_factor) { |
| 1349 | ViewportSelectionBound result; |
| 1350 | result.type = bound.type; |
| 1351 | |
| 1352 | if (!layer || bound.type == SELECTION_BOUND_EMPTY) |
| 1353 | return result; |
| 1354 | |
| 1355 | gfx::RectF layer_scaled_rect = gfx::ScaleRect( |
| 1356 | bound.layer_rect, layer->contents_scale_x(), layer->contents_scale_y()); |
| 1357 | gfx::RectF screen_rect = MathUtil::ProjectClippedRect( |
| 1358 | layer->screen_space_transform(), layer_scaled_rect); |
| 1359 | |
| 1360 | // The bottom left of the bound is used for visibility because 1) the bound |
| 1361 | // edge rect is one-dimensional (no width), and 2) the bottom is the logical |
| 1362 | // focal point for bound selection handles (this may change in the future). |
| 1363 | const gfx::PointF& visibility_point = screen_rect.bottom_left(); |
| 1364 | float intersect_distance = 0.f; |
| 1365 | result.visible = PointHitsLayer(layer, visibility_point, &intersect_distance); |
| 1366 | |
| 1367 | screen_rect.Scale(1.f / device_scale_factor); |
| 1368 | result.viewport_rect = screen_rect; |
| 1369 | |
| 1370 | return result; |
| 1371 | } |
| 1372 | |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 1373 | void LayerTreeImpl::GetViewportSelection(ViewportSelectionBound* start, |
| 1374 | ViewportSelectionBound* end) { |
| 1375 | DCHECK(start); |
| 1376 | DCHECK(end); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1377 | |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 1378 | *start = ComputeViewportSelection( |
| 1379 | selection_start_, |
| 1380 | selection_start_.layer_id ? LayerById(selection_start_.layer_id) : NULL, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1381 | device_scale_factor()); |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 1382 | if (start->type == SELECTION_BOUND_CENTER || |
| 1383 | start->type == SELECTION_BOUND_EMPTY) { |
| 1384 | *end = *start; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1385 | } else { |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 1386 | *end = ComputeViewportSelection( |
| 1387 | selection_end_, |
| 1388 | selection_end_.layer_id ? LayerById(selection_end_.layer_id) : NULL, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1389 | device_scale_factor()); |
| 1390 | } |
| 1391 | } |
| 1392 | |
[email protected] | 8aa39ecb | 2014-06-12 14:19:14 | [diff] [blame] | 1393 | void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 1394 | layer_tree_host_impl_->RegisterPictureLayerImpl(layer); |
| 1395 | } |
| 1396 | |
| 1397 | void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 1398 | layer_tree_host_impl_->UnregisterPictureLayerImpl(layer); |
| 1399 | } |
| 1400 | |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 1401 | void LayerTreeImpl::InputScrollAnimationFinished() { |
| 1402 | layer_tree_host_impl_->ScrollEnd(); |
| 1403 | } |
| 1404 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1405 | } // namespace cc |