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