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