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