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