[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] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 7 | #include "base/debug/trace_event.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 8 | #include "cc/animation/keyframed_animation_curve.h" |
| 9 | #include "cc/animation/scrollbar_animation_controller.h" |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 10 | #include "cc/base/math_util.h" |
| 11 | #include "cc/base/util.h" |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 12 | #include "cc/debug/traced_value.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 13 | #include "cc/layers/heads_up_display_layer_impl.h" |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 14 | #include "cc/layers/layer.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 15 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 16 | #include "cc/layers/scrollbar_layer_impl_base.h" |
[email protected] | e104219 | 2013-11-08 05:44:24 | [diff] [blame] | 17 | #include "cc/resources/ui_resource_request.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 18 | #include "cc/trees/layer_tree_host_common.h" |
| 19 | #include "cc/trees/layer_tree_host_impl.h" |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 20 | #include "ui/gfx/size_conversions.h" |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 21 | #include "ui/gfx/vector2d_conversions.h" |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 22 | |
| 23 | namespace cc { |
| 24 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 25 | // This class exists to split the LayerScrollOffsetDelegate between the |
| 26 | // InnerViewportScrollLayer and the OuterViewportScrollLayer in a manner |
| 27 | // that never requires the embedder or LayerImpl to know about. |
| 28 | class LayerScrollOffsetDelegateProxy : public LayerScrollOffsetDelegate { |
| 29 | public: |
| 30 | LayerScrollOffsetDelegateProxy(LayerImpl* layer, |
| 31 | LayerScrollOffsetDelegate* delegate, |
| 32 | LayerTreeImpl* layer_tree) |
| 33 | : layer_(layer), delegate_(delegate), layer_tree_impl_(layer_tree) {} |
| 34 | |
| 35 | gfx::Vector2dF last_set_scroll_offset() const { |
| 36 | return last_set_scroll_offset_; |
| 37 | } |
| 38 | |
| 39 | // LayerScrollOffsetDelegate implementation. |
| 40 | |
| 41 | virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_offset) OVERRIDE { |
| 42 | last_set_scroll_offset_ = new_offset; |
| 43 | layer_tree_impl_->UpdateScrollOffsetDelegate(); |
| 44 | } |
| 45 | |
| 46 | virtual gfx::Vector2dF GetTotalScrollOffset() OVERRIDE { |
| 47 | return layer_tree_impl_->GetDelegatedScrollOffset(layer_); |
| 48 | } |
| 49 | |
| 50 | virtual bool IsExternalFlingActive() const OVERRIDE { |
| 51 | return delegate_->IsExternalFlingActive(); |
| 52 | } |
| 53 | |
| 54 | // Functions below this point are never called by LayerImpl on its |
| 55 | // LayerScrollOffsetDelegate, and so are not implemented. |
| 56 | virtual void SetMaxScrollOffset(const gfx::Vector2dF&) OVERRIDE { |
| 57 | NOTIMPLEMENTED(); |
| 58 | } |
| 59 | |
| 60 | virtual void SetTotalPageScaleFactor(float scale) OVERRIDE { |
| 61 | NOTIMPLEMENTED(); |
| 62 | } |
| 63 | |
| 64 | virtual void SetScrollableSize(const gfx::SizeF& scrollable_size) OVERRIDE { |
| 65 | NOTIMPLEMENTED(); |
| 66 | } |
| 67 | |
| 68 | private: |
| 69 | LayerImpl* layer_; |
| 70 | LayerScrollOffsetDelegate* delegate_; |
| 71 | LayerTreeImpl* layer_tree_impl_; |
| 72 | gfx::Vector2dF last_set_scroll_offset_; |
| 73 | }; |
| 74 | |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 75 | LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 76 | : layer_tree_host_impl_(layer_tree_host_impl), |
| 77 | source_frame_number_(-1), |
| 78 | hud_layer_(0), |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 79 | currently_scrolling_layer_(NULL), |
| 80 | root_layer_scroll_offset_delegate_(NULL), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 81 | background_color_(0), |
| 82 | has_transparent_background_(false), |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 83 | page_scale_layer_(NULL), |
| 84 | inner_viewport_scroll_layer_(NULL), |
| 85 | outer_viewport_scroll_layer_(NULL), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 86 | page_scale_factor_(1), |
| 87 | page_scale_delta_(1), |
| 88 | sent_page_scale_delta_(1), |
| 89 | min_page_scale_factor_(0), |
| 90 | max_page_scale_factor_(0), |
| 91 | scrolling_layer_id_from_previous_tree_(0), |
| 92 | contents_textures_purged_(false), |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 93 | requires_high_res_to_draw_(false), |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 94 | viewport_size_invalid_(false), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 95 | needs_update_draw_properties_(true), |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 96 | needs_full_tree_sync_(true), |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 97 | next_activation_forces_redraw_(false) {} |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 98 | |
| 99 | LayerTreeImpl::~LayerTreeImpl() { |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 100 | // Need to explicitly clear the tree prior to destroying this so that |
| 101 | // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. |
[email protected] | df17af5 | 2014-02-06 02:20:40 | [diff] [blame] | 102 | DCHECK(!root_layer_); |
| 103 | DCHECK(layers_with_copy_output_request_.empty()); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 104 | } |
| 105 | |
[email protected] | df17af5 | 2014-02-06 02:20:40 | [diff] [blame] | 106 | void LayerTreeImpl::Shutdown() { root_layer_.reset(); } |
| 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 | |
| 218 | if (ContentsTexturesPurged()) |
| 219 | target_tree->SetContentsTexturesPurged(); |
| 220 | else |
| 221 | target_tree->ResetContentsTexturesPurged(); |
| 222 | |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 223 | // Always reset this flag on activation, as we would only have activated |
| 224 | // if we were in a good state. |
| 225 | target_tree->ResetRequiresHighResToDraw(); |
| 226 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 227 | if (ViewportSizeInvalid()) |
| 228 | target_tree->SetViewportSizeInvalid(); |
| 229 | else |
| 230 | target_tree->ResetViewportSizeInvalid(); |
| 231 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 232 | if (hud_layer()) |
| 233 | target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 234 | LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 235 | target_tree->root_layer(), hud_layer()->id()))); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 236 | else |
| 237 | target_tree->set_hud_layer(NULL); |
| 238 | } |
| 239 | |
[email protected] | 0263522 | 2013-07-15 18:28:07 | [diff] [blame] | 240 | LayerImpl* LayerTreeImpl::RootContainerLayer() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 241 | return inner_viewport_scroll_layer_ ? inner_viewport_scroll_layer_->parent() |
| 242 | : NULL; |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 243 | } |
| 244 | |
| 245 | LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 246 | DCHECK(IsActiveTree()); |
| 247 | return currently_scrolling_layer_; |
| 248 | } |
| 249 | |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 250 | void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) { |
| 251 | if (currently_scrolling_layer_ == layer) |
| 252 | return; |
| 253 | |
| 254 | if (currently_scrolling_layer_ && |
| 255 | currently_scrolling_layer_->scrollbar_animation_controller()) |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 256 | currently_scrolling_layer_->scrollbar_animation_controller()-> |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 257 | DidScrollGestureEnd(CurrentPhysicalTimeTicks()); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 258 | currently_scrolling_layer_ = layer; |
| 259 | if (layer && layer->scrollbar_animation_controller()) |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 260 | layer->scrollbar_animation_controller()->DidScrollGestureBegin(); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 261 | } |
| 262 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 263 | void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 264 | SetCurrentlyScrollingLayer(NULL); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 265 | scrolling_layer_id_from_previous_tree_ = 0; |
| 266 | } |
| 267 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 268 | float LayerTreeImpl::VerticalAdjust(const LayerImpl* layer) const { |
| 269 | DCHECK(layer); |
| 270 | if (layer->parent() != RootContainerLayer()) |
| 271 | return 0.f; |
| 272 | |
| 273 | return layer_tree_host_impl_->UnscaledScrollableViewportSize().height() - |
| 274 | RootContainerLayer()->bounds().height(); |
| 275 | } |
| 276 | |
| 277 | namespace { |
| 278 | |
| 279 | void ForceScrollbarParameterUpdateAfterScaleChange(LayerImpl* current_layer) { |
| 280 | if (!current_layer) |
| 281 | return; |
| 282 | |
| 283 | while (current_layer) { |
| 284 | current_layer->ScrollbarParametersDidChange(); |
| 285 | current_layer = current_layer->parent(); |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | } // namespace |
| 290 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 291 | void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor, |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 292 | float min_page_scale_factor, float max_page_scale_factor) { |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 293 | if (!page_scale_factor) |
| 294 | return; |
| 295 | |
| 296 | min_page_scale_factor_ = min_page_scale_factor; |
| 297 | max_page_scale_factor_ = max_page_scale_factor; |
| 298 | page_scale_factor_ = page_scale_factor; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 299 | |
[email protected] | 22f200a | 2013-10-09 18:08:29 | [diff] [blame] | 300 | if (root_layer_scroll_offset_delegate_) { |
| 301 | root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor( |
| 302 | total_page_scale_factor()); |
| 303 | } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 304 | |
| 305 | ForceScrollbarParameterUpdateAfterScaleChange(page_scale_layer()); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 306 | } |
| 307 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 308 | void LayerTreeImpl::SetPageScaleDelta(float delta) { |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 309 | // Clamp to the current min/max limits. |
| 310 | float total = page_scale_factor_ * delta; |
| 311 | if (min_page_scale_factor_ && total < min_page_scale_factor_) |
| 312 | delta = min_page_scale_factor_ / page_scale_factor_; |
| 313 | else if (max_page_scale_factor_ && total > max_page_scale_factor_) |
| 314 | delta = max_page_scale_factor_ / page_scale_factor_; |
| 315 | |
| 316 | if (delta == page_scale_delta_) |
| 317 | return; |
| 318 | |
| 319 | page_scale_delta_ = delta; |
| 320 | |
| 321 | if (IsActiveTree()) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 322 | LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 323 | if (pending_tree) { |
| 324 | DCHECK_EQ(1, pending_tree->sent_page_scale_delta()); |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 325 | pending_tree->SetPageScaleDelta( |
| 326 | page_scale_delta_ / sent_page_scale_delta_); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 330 | set_needs_update_draw_properties(); |
[email protected] | 22f200a | 2013-10-09 18:08:29 | [diff] [blame] | 331 | |
| 332 | if (root_layer_scroll_offset_delegate_) { |
| 333 | root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor( |
| 334 | total_page_scale_factor()); |
| 335 | } |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 336 | } |
| 337 | |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 338 | gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 339 | if (outer_viewport_scroll_layer_) |
| 340 | return layer_tree_host_impl_->UnscaledScrollableViewportSize(); |
| 341 | else |
| 342 | return gfx::ScaleSize( |
| 343 | layer_tree_host_impl_->UnscaledScrollableViewportSize(), |
| 344 | 1.0f / total_page_scale_factor()); |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 345 | } |
| 346 | |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 347 | gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 348 | LayerImpl* root_scroll_layer = OuterViewportScrollLayer() |
| 349 | ? OuterViewportScrollLayer() |
| 350 | : InnerViewportScrollLayer(); |
| 351 | if (!root_scroll_layer || root_scroll_layer->children().empty()) |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 352 | return gfx::Rect(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 353 | LayerImpl* layer = root_scroll_layer->children()[0]; |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 354 | return MathUtil::MapClippedRect( |
| 355 | layer->screen_space_transform(), |
| 356 | gfx::Rect(layer->content_bounds())); |
| 357 | } |
| 358 | |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 359 | static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) { |
| 360 | layer->ApplySentScrollDeltasFromAbortedCommit(); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 361 | } |
| 362 | |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 363 | void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() { |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 364 | DCHECK(IsActiveTree()); |
| 365 | |
| 366 | page_scale_factor_ *= sent_page_scale_delta_; |
| 367 | page_scale_delta_ /= sent_page_scale_delta_; |
| 368 | sent_page_scale_delta_ = 1.f; |
| 369 | |
| 370 | if (!root_layer()) |
| 371 | return; |
| 372 | |
| 373 | LayerTreeHostCommon::CallFunctionForSubtree( |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 374 | root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo)); |
| 375 | } |
| 376 | |
[email protected] | daea3d4 | 2013-10-23 17:04:50 | [diff] [blame] | 377 | static void ApplyScrollDeltasSinceBeginMainFrameTo(LayerImpl* layer) { |
| 378 | layer->ApplyScrollDeltasSinceBeginMainFrame(); |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 379 | } |
| 380 | |
[email protected] | daea3d4 | 2013-10-23 17:04:50 | [diff] [blame] | 381 | void LayerTreeImpl::ApplyScrollDeltasSinceBeginMainFrame() { |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 382 | DCHECK(IsPendingTree()); |
| 383 | if (!root_layer()) |
| 384 | return; |
| 385 | |
| 386 | LayerTreeHostCommon::CallFunctionForSubtree( |
[email protected] | daea3d4 | 2013-10-23 17:04:50 | [diff] [blame] | 387 | root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginMainFrameTo)); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 388 | } |
| 389 | |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 390 | void LayerTreeImpl::SetViewportLayersFromIds( |
| 391 | int page_scale_layer_id, |
| 392 | int inner_viewport_scroll_layer_id, |
| 393 | int outer_viewport_scroll_layer_id) { |
| 394 | page_scale_layer_ = LayerById(page_scale_layer_id); |
| 395 | DCHECK(page_scale_layer_); |
| 396 | |
| 397 | inner_viewport_scroll_layer_ = |
| 398 | LayerById(inner_viewport_scroll_layer_id); |
| 399 | DCHECK(inner_viewport_scroll_layer_); |
| 400 | |
| 401 | outer_viewport_scroll_layer_ = |
| 402 | LayerById(outer_viewport_scroll_layer_id); |
| 403 | DCHECK(outer_viewport_scroll_layer_ || |
| 404 | outer_viewport_scroll_layer_id == Layer::INVALID_ID); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 405 | |
| 406 | if (!root_layer_scroll_offset_delegate_) |
| 407 | return; |
| 408 | |
| 409 | inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 410 | new LayerScrollOffsetDelegateProxy(inner_viewport_scroll_layer_, |
| 411 | root_layer_scroll_offset_delegate_, |
| 412 | this)); |
| 413 | |
| 414 | if (outer_viewport_scroll_layer_) |
| 415 | outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 416 | new LayerScrollOffsetDelegateProxy(outer_viewport_scroll_layer_, |
| 417 | root_layer_scroll_offset_delegate_, |
| 418 | this)); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void LayerTreeImpl::ClearViewportLayers() { |
| 422 | page_scale_layer_ = NULL; |
| 423 | inner_viewport_scroll_layer_ = NULL; |
| 424 | outer_viewport_scroll_layer_ = NULL; |
| 425 | } |
| 426 | |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 427 | void LayerTreeImpl::UpdateDrawProperties() { |
[email protected] | d35cd7b2 | 2014-01-29 14:32:46 | [diff] [blame] | 428 | if (IsActiveTree() && RootContainerLayer()) |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 429 | UpdateRootScrollLayerSizeDelta(); |
[email protected] | d35cd7b2 | 2014-01-29 14:32:46 | [diff] [blame] | 430 | |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 431 | needs_update_draw_properties_ = false; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 432 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 433 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 434 | // For max_texture_size. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 435 | if (!layer_tree_host_impl_->renderer()) |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 436 | return; |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 437 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 438 | if (!root_layer()) |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 439 | return; |
| 440 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 441 | { |
[email protected] | 7a52f43e | 2013-07-10 01:58:47 | [diff] [blame] | 442 | TRACE_EVENT2("cc", |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 443 | "LayerTreeImpl::UpdateDrawProperties", |
| 444 | "IsActive", |
[email protected] | 7a52f43e | 2013-07-10 01:58:47 | [diff] [blame] | 445 | IsActiveTree(), |
| 446 | "SourceFrameNumber", |
| 447 | source_frame_number_); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 448 | LayerImpl* page_scale_layer = |
| 449 | page_scale_layer_ ? page_scale_layer_ : RootContainerLayer(); |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 450 | bool can_render_to_separate_surface = |
| 451 | !output_surface()->ForcedDrawToSoftwareDevice(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 452 | LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 453 | root_layer(), |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 454 | DrawViewportSize(), |
| 455 | layer_tree_host_impl_->DrawTransform(), |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 456 | device_scale_factor(), |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 457 | total_page_scale_factor(), |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 458 | page_scale_layer, |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 459 | MaxTextureSize(), |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 460 | settings().can_use_lcd_text, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 461 | can_render_to_separate_surface, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 462 | settings().layer_transforms_should_scale_layer_contents, |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 463 | &render_surface_layer_list_); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 464 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 465 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 466 | |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 467 | { |
| 468 | TRACE_EVENT2("cc", |
| 469 | "LayerTreeImpl::UpdateTilePriorities", |
| 470 | "IsActive", |
| 471 | IsActiveTree(), |
| 472 | "SourceFrameNumber", |
| 473 | source_frame_number_); |
| 474 | // LayerIterator is used here instead of CallFunctionForSubtree to only |
| 475 | // UpdateTilePriorities on layers that will be visible (and thus have valid |
| 476 | // draw properties) and not because any ordering is required. |
| 477 | typedef LayerIterator<LayerImpl, |
| 478 | LayerImplList, |
| 479 | RenderSurfaceImpl, |
| 480 | LayerIteratorActions::FrontToBack> LayerIteratorType; |
| 481 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 482 | for (LayerIteratorType it = |
| 483 | LayerIteratorType::Begin(&render_surface_layer_list_); |
| 484 | it != end; |
| 485 | ++it) { |
| 486 | if (!it.represents_itself()) |
| 487 | continue; |
| 488 | LayerImpl* layer = *it; |
| 489 | |
| 490 | layer->UpdateTilePriorities(); |
| 491 | if (layer->mask_layer()) |
| 492 | layer->mask_layer()->UpdateTilePriorities(); |
| 493 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 494 | layer->replica_layer()->mask_layer()->UpdateTilePriorities(); |
| 495 | } |
| 496 | } |
| 497 | |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 498 | DCHECK(!needs_update_draw_properties_) << |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 499 | "CalcDrawProperties should not set_needs_update_draw_properties()"; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 500 | } |
| 501 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 502 | const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const { |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 503 | // If this assert triggers, then the list is dirty. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 504 | DCHECK(!needs_update_draw_properties_); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 505 | return render_surface_layer_list_; |
| 506 | } |
| 507 | |
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 508 | gfx::Size LayerTreeImpl::ScrollableSize() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 509 | LayerImpl* root_scroll_layer = OuterViewportScrollLayer() |
| 510 | ? OuterViewportScrollLayer() |
| 511 | : InnerViewportScrollLayer(); |
| 512 | if (!root_scroll_layer || root_scroll_layer->children().empty()) |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 513 | return gfx::Size(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 514 | return root_scroll_layer->children()[0]->bounds(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 515 | } |
| 516 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 517 | LayerImpl* LayerTreeImpl::LayerById(int id) { |
| 518 | LayerIdMap::iterator iter = layer_id_map_.find(id); |
| 519 | return iter != layer_id_map_.end() ? iter->second : NULL; |
| 520 | } |
| 521 | |
| 522 | void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { |
| 523 | DCHECK(!LayerById(layer->id())); |
| 524 | layer_id_map_[layer->id()] = layer; |
| 525 | } |
| 526 | |
| 527 | void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { |
| 528 | DCHECK(LayerById(layer->id())); |
| 529 | layer_id_map_.erase(layer->id()); |
| 530 | } |
| 531 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 532 | void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { |
[email protected] | a90fac7 | 2013-06-06 18:56:13 | [diff] [blame] | 533 | pending_tree->SetCurrentlyScrollingLayer( |
| 534 | LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), |
| 535 | currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 536 | } |
| 537 | |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 538 | static void DidBecomeActiveRecursive(LayerImpl* layer) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 539 | layer->DidBecomeActive(); |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 540 | for (size_t i = 0; i < layer->children().size(); ++i) |
| 541 | DidBecomeActiveRecursive(layer->children()[i]); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | void LayerTreeImpl::DidBecomeActive() { |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 545 | if (!root_layer()) |
| 546 | return; |
| 547 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 548 | if (scrolling_layer_id_from_previous_tree_) { |
| 549 | currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( |
| 550 | root_layer_.get(), scrolling_layer_id_from_previous_tree_); |
| 551 | } |
| 552 | |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 553 | DidBecomeActiveRecursive(root_layer()); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 554 | } |
| 555 | |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 556 | bool LayerTreeImpl::ContentsTexturesPurged() const { |
| 557 | return contents_textures_purged_; |
| 558 | } |
| 559 | |
| 560 | void LayerTreeImpl::SetContentsTexturesPurged() { |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 561 | if (contents_textures_purged_) |
| 562 | return; |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 563 | contents_textures_purged_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 564 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 565 | } |
| 566 | |
| 567 | void LayerTreeImpl::ResetContentsTexturesPurged() { |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 568 | if (!contents_textures_purged_) |
| 569 | return; |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 570 | contents_textures_purged_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 571 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 572 | } |
| 573 | |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 574 | void LayerTreeImpl::SetRequiresHighResToDraw() { |
| 575 | requires_high_res_to_draw_ = true; |
| 576 | } |
| 577 | |
| 578 | void LayerTreeImpl::ResetRequiresHighResToDraw() { |
| 579 | requires_high_res_to_draw_ = false; |
| 580 | } |
| 581 | |
| 582 | bool LayerTreeImpl::RequiresHighResToDraw() const { |
| 583 | return requires_high_res_to_draw_; |
| 584 | } |
| 585 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 586 | bool LayerTreeImpl::ViewportSizeInvalid() const { |
| 587 | return viewport_size_invalid_; |
| 588 | } |
| 589 | |
| 590 | void LayerTreeImpl::SetViewportSizeInvalid() { |
| 591 | viewport_size_invalid_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 592 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | void LayerTreeImpl::ResetViewportSizeInvalid() { |
| 596 | viewport_size_invalid_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 597 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 598 | } |
| 599 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 600 | Proxy* LayerTreeImpl::proxy() const { |
| 601 | return layer_tree_host_impl_->proxy(); |
| 602 | } |
| 603 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 604 | const LayerTreeSettings& LayerTreeImpl::settings() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 605 | return layer_tree_host_impl_->settings(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 606 | } |
| 607 | |
[email protected] | 7a8bcd26 | 2014-01-15 12:54:58 | [diff] [blame] | 608 | const RendererCapabilitiesImpl& LayerTreeImpl::GetRendererCapabilities() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 609 | return layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | bf5b3a0 | 2013-02-13 02:02:52 | [diff] [blame] | 610 | } |
| 611 | |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 612 | ContextProvider* LayerTreeImpl::context_provider() const { |
| 613 | return output_surface()->context_provider(); |
| 614 | } |
| 615 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 616 | OutputSurface* LayerTreeImpl::output_surface() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 617 | return layer_tree_host_impl_->output_surface(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | ResourceProvider* LayerTreeImpl::resource_provider() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 621 | return layer_tree_host_impl_->resource_provider(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | TileManager* LayerTreeImpl::tile_manager() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 625 | return layer_tree_host_impl_->tile_manager(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 629 | return layer_tree_host_impl_->fps_counter(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 630 | } |
| 631 | |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 632 | PaintTimeCounter* LayerTreeImpl::paint_time_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 633 | return layer_tree_host_impl_->paint_time_counter(); |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 634 | } |
| 635 | |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 636 | MemoryHistory* LayerTreeImpl::memory_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 637 | return layer_tree_host_impl_->memory_history(); |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 638 | } |
| 639 | |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 640 | bool LayerTreeImpl::device_viewport_valid_for_tile_management() const { |
| 641 | return layer_tree_host_impl_->device_viewport_valid_for_tile_management(); |
| 642 | } |
| 643 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 644 | bool LayerTreeImpl::IsActiveTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 645 | return layer_tree_host_impl_->active_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | bool LayerTreeImpl::IsPendingTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 649 | return layer_tree_host_impl_->pending_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 650 | } |
| 651 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 652 | bool LayerTreeImpl::IsRecycleTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 653 | return layer_tree_host_impl_->recycle_tree() == this; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 654 | } |
| 655 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 656 | LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 657 | LayerTreeImpl* tree = layer_tree_host_impl_->active_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 658 | if (!tree) |
| 659 | return NULL; |
| 660 | return tree->LayerById(id); |
| 661 | } |
| 662 | |
| 663 | LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 664 | LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 665 | if (!tree) |
| 666 | return NULL; |
| 667 | return tree->LayerById(id); |
| 668 | } |
| 669 | |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 670 | int LayerTreeImpl::MaxTextureSize() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 671 | return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size; |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 672 | } |
| 673 | |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 674 | bool LayerTreeImpl::PinchGestureActive() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 675 | return layer_tree_host_impl_->pinch_gesture_active(); |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 676 | } |
| 677 | |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 678 | base::TimeTicks LayerTreeImpl::CurrentFrameTimeTicks() const { |
| 679 | return layer_tree_host_impl_->CurrentFrameTimeTicks(); |
| 680 | } |
| 681 | |
| 682 | base::Time LayerTreeImpl::CurrentFrameTime() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 683 | return layer_tree_host_impl_->CurrentFrameTime(); |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 684 | } |
| 685 | |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 686 | base::TimeTicks LayerTreeImpl::CurrentPhysicalTimeTicks() const { |
| 687 | return layer_tree_host_impl_->CurrentPhysicalTimeTicks(); |
| 688 | } |
| 689 | |
[email protected] | d7eb8c7 | 2013-03-23 22:57:13 | [diff] [blame] | 690 | void LayerTreeImpl::SetNeedsCommit() { |
| 691 | layer_tree_host_impl_->SetNeedsCommit(); |
| 692 | } |
| 693 | |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 694 | gfx::Size LayerTreeImpl::DrawViewportSize() const { |
| 695 | return layer_tree_host_impl_->DrawViewportSize(); |
| 696 | } |
| 697 | |
[email protected] | 2ea5aba | 2013-09-11 14:26:56 | [diff] [blame] | 698 | void LayerTreeImpl::StartScrollbarAnimation() { |
| 699 | layer_tree_host_impl_->StartScrollbarAnimation(); |
| 700 | } |
| 701 | |
[email protected] | b8384e2 | 2013-12-03 02:20:48 | [diff] [blame] | 702 | void LayerTreeImpl::DidAnimateScrollOffset() { |
| 703 | layer_tree_host_impl_->DidAnimateScrollOffset(); |
| 704 | } |
| 705 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 706 | void LayerTreeImpl::SetNeedsRedraw() { |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 707 | layer_tree_host_impl_->SetNeedsRedraw(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 708 | } |
| 709 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 710 | const LayerTreeDebugState& LayerTreeImpl::debug_state() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 711 | return layer_tree_host_impl_->debug_state(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | float LayerTreeImpl::device_scale_factor() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 715 | return layer_tree_host_impl_->device_scale_factor(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 716 | } |
| 717 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 718 | DebugRectHistory* LayerTreeImpl::debug_rect_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 719 | return layer_tree_host_impl_->debug_rect_history(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 720 | } |
| 721 | |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 722 | AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 723 | return layer_tree_host_impl_->animation_registrar(); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 724 | } |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 725 | |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 726 | scoped_ptr<base::Value> LayerTreeImpl::AsValue() const { |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 727 | scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 728 | TracedValue::MakeDictIntoImplicitSnapshot( |
| 729 | state.get(), "cc::LayerTreeImpl", this); |
| 730 | |
| 731 | state->Set("root_layer", root_layer_->AsValue().release()); |
| 732 | |
| 733 | scoped_ptr<base::ListValue> render_surface_layer_list(new base::ListValue()); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 734 | typedef LayerIterator<LayerImpl, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 735 | LayerImplList, |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 736 | RenderSurfaceImpl, |
[email protected] | d08c3a4 | 2013-10-14 21:28:34 | [diff] [blame] | 737 | LayerIteratorActions::FrontToBack> LayerIteratorType; |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 738 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 739 | for (LayerIteratorType it = LayerIteratorType::Begin( |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 740 | &render_surface_layer_list_); it != end; ++it) { |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 741 | if (!it.represents_itself()) |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 742 | continue; |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 743 | render_surface_layer_list->Append(TracedValue::CreateIDRef(*it).release()); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 744 | } |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 745 | |
| 746 | state->Set("render_surface_layer_list", |
| 747 | render_surface_layer_list.release()); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 748 | return state.PassAs<base::Value>(); |
| 749 | } |
| 750 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 751 | void LayerTreeImpl::SetRootLayerScrollOffsetDelegate( |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 752 | LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) { |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 753 | if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate) |
| 754 | return; |
| 755 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 756 | if (!root_layer_scroll_offset_delegate) { |
| 757 | // Make sure we remove the proxies from their layers before |
| 758 | // releasing them. |
| 759 | if (InnerViewportScrollLayer()) |
| 760 | InnerViewportScrollLayer()->SetScrollOffsetDelegate(NULL); |
| 761 | if (OuterViewportScrollLayer()) |
| 762 | OuterViewportScrollLayer()->SetScrollOffsetDelegate(NULL); |
| 763 | inner_viewport_scroll_delegate_proxy_.reset(); |
| 764 | outer_viewport_scroll_delegate_proxy_.reset(); |
[email protected] | d35cd7b2 | 2014-01-29 14:32:46 | [diff] [blame] | 765 | } |
| 766 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 767 | root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate; |
| 768 | |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 769 | if (root_layer_scroll_offset_delegate_) { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 770 | root_layer_scroll_offset_delegate_->SetTotalScrollOffset( |
| 771 | TotalScrollOffset()); |
| 772 | root_layer_scroll_offset_delegate_->SetMaxScrollOffset( |
| 773 | TotalMaxScrollOffset()); |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 774 | root_layer_scroll_offset_delegate_->SetScrollableSize(ScrollableSize()); |
[email protected] | 22f200a | 2013-10-09 18:08:29 | [diff] [blame] | 775 | root_layer_scroll_offset_delegate_->SetTotalPageScaleFactor( |
| 776 | total_page_scale_factor()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 777 | |
| 778 | if (inner_viewport_scroll_layer_) { |
| 779 | inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 780 | new LayerScrollOffsetDelegateProxy(InnerViewportScrollLayer(), |
| 781 | root_layer_scroll_offset_delegate_, |
| 782 | this)); |
| 783 | inner_viewport_scroll_layer_->SetScrollOffsetDelegate( |
| 784 | inner_viewport_scroll_delegate_proxy_.get()); |
| 785 | } |
| 786 | |
| 787 | if (outer_viewport_scroll_layer_) { |
| 788 | outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 789 | new LayerScrollOffsetDelegateProxy(OuterViewportScrollLayer(), |
| 790 | root_layer_scroll_offset_delegate_, |
| 791 | this)); |
| 792 | outer_viewport_scroll_layer_->SetScrollOffsetDelegate( |
| 793 | outer_viewport_scroll_delegate_proxy_.get()); |
| 794 | } |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 795 | } |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 796 | } |
| 797 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 798 | void LayerTreeImpl::UpdateScrollOffsetDelegate() { |
| 799 | DCHECK(InnerViewportScrollLayer()); |
| 800 | DCHECK(root_layer_scroll_offset_delegate_); |
| 801 | |
| 802 | gfx::Vector2dF offset = |
| 803 | inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 804 | |
| 805 | if (OuterViewportScrollLayer()) |
| 806 | offset += outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 807 | |
| 808 | root_layer_scroll_offset_delegate_->SetTotalScrollOffset(offset); |
| 809 | root_layer_scroll_offset_delegate_->SetMaxScrollOffset( |
| 810 | TotalMaxScrollOffset()); |
| 811 | } |
| 812 | |
| 813 | gfx::Vector2dF LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) { |
| 814 | DCHECK(root_layer_scroll_offset_delegate_); |
| 815 | DCHECK(InnerViewportScrollLayer()); |
| 816 | if (layer == InnerViewportScrollLayer() && !OuterViewportScrollLayer()) |
| 817 | return root_layer_scroll_offset_delegate_->GetTotalScrollOffset(); |
| 818 | |
| 819 | // If we get here, we have both inner/outer viewports, and need to distribute |
| 820 | // the scroll offset between them. |
| 821 | DCHECK(inner_viewport_scroll_delegate_proxy_); |
| 822 | DCHECK(outer_viewport_scroll_delegate_proxy_); |
| 823 | gfx::Vector2dF inner_viewport_offset = |
| 824 | inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 825 | gfx::Vector2dF outer_viewport_offset = |
| 826 | outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 827 | |
| 828 | // It may be nothing has changed. |
| 829 | gfx::Vector2dF delegate_offset = |
| 830 | root_layer_scroll_offset_delegate_->GetTotalScrollOffset(); |
| 831 | if (inner_viewport_offset + outer_viewport_offset == delegate_offset) { |
| 832 | if (layer == InnerViewportScrollLayer()) |
| 833 | return inner_viewport_offset; |
| 834 | else |
| 835 | return outer_viewport_offset; |
| 836 | } |
| 837 | |
| 838 | gfx::Vector2d max_outer_viewport_scroll_offset = |
| 839 | OuterViewportScrollLayer()->MaxScrollOffset(); |
| 840 | |
| 841 | outer_viewport_offset = delegate_offset - inner_viewport_offset; |
| 842 | outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset); |
| 843 | outer_viewport_offset.SetToMax(gfx::Vector2d()); |
| 844 | |
| 845 | if (layer == OuterViewportScrollLayer()) |
| 846 | return outer_viewport_offset; |
| 847 | |
| 848 | inner_viewport_offset = delegate_offset - outer_viewport_offset; |
| 849 | |
| 850 | return inner_viewport_offset; |
| 851 | } |
| 852 | |
| 853 | // TODO(wjmaclean) Rename this function, as we no longer have a |
| 854 | // "RootScrollLayer". |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 855 | void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 856 | // TODO(wjmaclean) verify this is really the right thing to do in cases where |
| 857 | // the pinch virtual viewport is active. |
| 858 | LayerImpl* root_scroll = InnerViewportScrollLayer(); |
[email protected] | 0263522 | 2013-07-15 18:28:07 | [diff] [blame] | 859 | LayerImpl* root_container = RootContainerLayer(); |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 860 | DCHECK(root_scroll); |
[email protected] | 0263522 | 2013-07-15 18:28:07 | [diff] [blame] | 861 | DCHECK(root_container); |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 862 | DCHECK(IsActiveTree()); |
| 863 | |
| 864 | gfx::Vector2dF scrollable_viewport_size = |
| 865 | gfx::RectF(ScrollableViewportSize()).bottom_right() - gfx::PointF(); |
| 866 | |
| 867 | gfx::Vector2dF original_viewport_size = |
[email protected] | 0263522 | 2013-07-15 18:28:07 | [diff] [blame] | 868 | gfx::RectF(root_container->bounds()).bottom_right() - |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 869 | gfx::PointF(); |
| 870 | original_viewport_size.Scale(1 / page_scale_factor()); |
| 871 | |
| 872 | root_scroll->SetFixedContainerSizeDelta( |
| 873 | scrollable_viewport_size - original_viewport_size); |
| 874 | } |
| 875 | |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 876 | void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) { |
| 877 | DCHECK(swap_promise); |
| 878 | if (swap_promise_list_.size() > kMaxQueuedSwapPromiseNumber) |
| 879 | BreakSwapPromises(SwapPromise::SWAP_PROMISE_LIST_OVERFLOW); |
| 880 | swap_promise_list_.push_back(swap_promise.Pass()); |
| 881 | } |
| 882 | |
| 883 | void LayerTreeImpl::PassSwapPromises( |
| 884 | ScopedPtrVector<SwapPromise>* new_swap_promise) { |
| 885 | swap_promise_list_.insert_and_take(swap_promise_list_.end(), |
| 886 | *new_swap_promise); |
| 887 | new_swap_promise->clear(); |
| 888 | } |
| 889 | |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 890 | void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) { |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 891 | for (size_t i = 0; i < swap_promise_list_.size(); i++) |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 892 | swap_promise_list_[i]->DidSwap(metadata); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 893 | swap_promise_list_.clear(); |
| 894 | } |
| 895 | |
| 896 | void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) { |
| 897 | for (size_t i = 0; i < swap_promise_list_.size(); i++) |
| 898 | swap_promise_list_[i]->DidNotSwap(reason); |
| 899 | swap_promise_list_.clear(); |
| 900 | } |
| 901 | |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 902 | void LayerTreeImpl::DidModifyTilePriorities() { |
| 903 | layer_tree_host_impl_->DidModifyTilePriorities(); |
[email protected] | fcb846d | 2013-05-22 01:42:36 | [diff] [blame] | 904 | } |
| 905 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 906 | void LayerTreeImpl::set_ui_resource_request_queue( |
| 907 | const UIResourceRequestQueue& queue) { |
| 908 | ui_resource_request_queue_ = queue; |
| 909 | } |
| 910 | |
| 911 | ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource( |
| 912 | UIResourceId uid) const { |
| 913 | return layer_tree_host_impl_->ResourceIdForUIResource(uid); |
| 914 | } |
| 915 | |
[email protected] | 709c954 | 2013-10-26 01:43:51 | [diff] [blame] | 916 | bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const { |
| 917 | return layer_tree_host_impl_->IsUIResourceOpaque(uid); |
| 918 | } |
| 919 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 920 | void LayerTreeImpl::ProcessUIResourceRequestQueue() { |
| 921 | while (ui_resource_request_queue_.size() > 0) { |
| 922 | UIResourceRequest req = ui_resource_request_queue_.front(); |
| 923 | ui_resource_request_queue_.pop_front(); |
| 924 | |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 925 | switch (req.GetType()) { |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 926 | case UIResourceRequest::UIResourceCreate: |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 927 | layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap()); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 928 | break; |
| 929 | case UIResourceRequest::UIResourceDelete: |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 930 | layer_tree_host_impl_->DeleteUIResource(req.GetId()); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 931 | break; |
[email protected] | f28d64d | 2013-08-27 04:17:45 | [diff] [blame] | 932 | case UIResourceRequest::UIResourceInvalidRequest: |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 933 | NOTREACHED(); |
| 934 | break; |
| 935 | } |
| 936 | } |
[email protected] | 127bdc1a | 2013-09-11 01:44:48 | [diff] [blame] | 937 | |
| 938 | // If all UI resource evictions were not recreated by processing this queue, |
| 939 | // then another commit is required. |
| 940 | if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
| 941 | layer_tree_host_impl_->SetNeedsCommit(); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 942 | } |
| 943 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 944 | void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) { |
| 945 | // Only the active tree needs to know about layers with copy requests, as |
| 946 | // they are aborted if not serviced during draw. |
| 947 | DCHECK(IsActiveTree()); |
| 948 | |
[email protected] | a4ee1281 | 2014-02-06 17:33:38 | [diff] [blame^] | 949 | // DCHECK(std::find(layers_with_copy_output_request_.begin(), |
| 950 | // layers_with_copy_output_request_.end(), |
| 951 | // layer) == layers_with_copy_output_request_.end()); |
| 952 | // TODO(danakj): Remove this once crash is found crbug.com/309777 |
| 953 | for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) { |
| 954 | CHECK(layers_with_copy_output_request_[i] != layer) |
| 955 | << i << " of " << layers_with_copy_output_request_.size(); |
| 956 | } |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 957 | layers_with_copy_output_request_.push_back(layer); |
| 958 | } |
| 959 | |
| 960 | void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) { |
| 961 | // Only the active tree needs to know about layers with copy requests, as |
| 962 | // they are aborted if not serviced during draw. |
| 963 | DCHECK(IsActiveTree()); |
| 964 | |
| 965 | std::vector<LayerImpl*>::iterator it = std::find( |
| 966 | layers_with_copy_output_request_.begin(), |
| 967 | layers_with_copy_output_request_.end(), |
| 968 | layer); |
| 969 | DCHECK(it != layers_with_copy_output_request_.end()); |
[email protected] | f5de9e5b | 2013-07-30 22:26:57 | [diff] [blame] | 970 | layers_with_copy_output_request_.erase(it); |
[email protected] | a4ee1281 | 2014-02-06 17:33:38 | [diff] [blame^] | 971 | |
| 972 | // TODO(danakj): Remove this once crash is found crbug.com/309777 |
| 973 | for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) { |
| 974 | CHECK(layers_with_copy_output_request_[i] != layer) |
| 975 | << i << " of " << layers_with_copy_output_request_.size(); |
| 976 | } |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 977 | } |
| 978 | |
[email protected] | 5352637 | 2013-12-07 04:31:50 | [diff] [blame] | 979 | const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest() |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 980 | const { |
| 981 | // Only the active tree needs to know about layers with copy requests, as |
| 982 | // they are aborted if not serviced during draw. |
| 983 | DCHECK(IsActiveTree()); |
| 984 | |
| 985 | return layers_with_copy_output_request_; |
| 986 | } |
| 987 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 988 | } // namespace cc |