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