[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] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 10 | #include "cc/debug/traced_value.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 11 | #include "cc/layers/heads_up_display_layer_impl.h" |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 12 | #include "cc/layers/layer.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 13 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 14 | #include "cc/layers/scrollbar_layer_impl_base.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 15 | #include "cc/trees/layer_tree_host_common.h" |
| 16 | #include "cc/trees/layer_tree_host_impl.h" |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 17 | #include "ui/gfx/size_conversions.h" |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 18 | #include "ui/gfx/vector2d_conversions.h" |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 19 | |
| 20 | namespace cc { |
| 21 | |
[email protected] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 22 | LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 23 | : layer_tree_host_impl_(layer_tree_host_impl), |
| 24 | source_frame_number_(-1), |
| 25 | hud_layer_(0), |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 26 | root_scroll_layer_(NULL), |
| 27 | currently_scrolling_layer_(NULL), |
| 28 | root_layer_scroll_offset_delegate_(NULL), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 29 | background_color_(0), |
| 30 | has_transparent_background_(false), |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 31 | page_scale_layer_(NULL), |
| 32 | inner_viewport_scroll_layer_(NULL), |
| 33 | outer_viewport_scroll_layer_(NULL), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 34 | page_scale_factor_(1), |
| 35 | page_scale_delta_(1), |
| 36 | sent_page_scale_delta_(1), |
| 37 | min_page_scale_factor_(0), |
| 38 | max_page_scale_factor_(0), |
| 39 | scrolling_layer_id_from_previous_tree_(0), |
| 40 | contents_textures_purged_(false), |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 41 | viewport_size_invalid_(false), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 42 | needs_update_draw_properties_(true), |
| 43 | needs_full_tree_sync_(true) { |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | LayerTreeImpl::~LayerTreeImpl() { |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 47 | // Need to explicitly clear the tree prior to destroying this so that |
| 48 | // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. |
| 49 | root_layer_.reset(); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 50 | } |
| 51 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 52 | static LayerImpl* FindRootScrollLayerRecursive(LayerImpl* layer) { |
| 53 | if (!layer) |
| 54 | return NULL; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 55 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 56 | if (layer->scrollable()) |
| 57 | return layer; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 58 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 59 | for (size_t i = 0; i < layer->children().size(); ++i) { |
| 60 | LayerImpl* found = FindRootScrollLayerRecursive(layer->children()[i]); |
| 61 | if (found) |
| 62 | return found; |
| 63 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 64 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 65 | return NULL; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 69 | if (root_scroll_layer_) |
| 70 | root_scroll_layer_->SetScrollOffsetDelegate(NULL); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 71 | root_layer_ = layer.Pass(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 72 | currently_scrolling_layer_ = NULL; |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 73 | root_scroll_layer_ = NULL; |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 74 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 75 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | void LayerTreeImpl::FindRootScrollLayer() { |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 79 | root_scroll_layer_ = FindRootScrollLayerRecursive(root_layer_.get()); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 80 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 81 | if (root_scroll_layer_) { |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 82 | UpdateMaxScrollOffset(); |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 83 | root_scroll_layer_->SetScrollOffsetDelegate( |
| 84 | root_layer_scroll_offset_delegate_); |
| 85 | } |
| 86 | |
[email protected] | a90fac7 | 2013-06-06 18:56:13 | [diff] [blame] | 87 | if (scrolling_layer_id_from_previous_tree_) { |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 88 | currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 89 | root_layer_.get(), |
| 90 | scrolling_layer_id_from_previous_tree_); |
| 91 | } |
| 92 | |
| 93 | scrolling_layer_id_from_previous_tree_ = 0; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { |
| 97 | // Clear all data structures that have direct references to the layer tree. |
| 98 | scrolling_layer_id_from_previous_tree_ = |
| 99 | currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 100 | if (root_scroll_layer_) |
| 101 | root_scroll_layer_->SetScrollOffsetDelegate(NULL); |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 102 | root_scroll_layer_ = NULL; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 103 | currently_scrolling_layer_ = NULL; |
| 104 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 105 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 106 | set_needs_update_draw_properties(); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 107 | return root_layer_.Pass(); |
| 108 | } |
| 109 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 110 | void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 111 | // The request queue should have been processed and does not require a push. |
| 112 | DCHECK_EQ(ui_resource_request_queue_.size(), 0u); |
| 113 | |
[email protected] | e4c3c87a | 2013-04-22 02:28:40 | [diff] [blame] | 114 | target_tree->SetLatencyInfo(latency_info_); |
| 115 | latency_info_.Clear(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 116 | target_tree->SetPageScaleFactorAndLimits( |
| 117 | page_scale_factor(), min_page_scale_factor(), max_page_scale_factor()); |
| 118 | target_tree->SetPageScaleDelta( |
| 119 | target_tree->page_scale_delta() / target_tree->sent_page_scale_delta()); |
| 120 | target_tree->set_sent_page_scale_delta(1); |
| 121 | |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 122 | if (settings().use_pinch_virtual_viewport) { |
| 123 | target_tree->SetViewportLayersFromIds( |
| 124 | page_scale_layer_->id(), |
| 125 | inner_viewport_scroll_layer_->id(), |
| 126 | outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() |
| 127 | : Layer::INVALID_ID); |
| 128 | } |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 129 | // This should match the property synchronization in |
| 130 | // LayerTreeHost::finishCommitOnImplThread(). |
| 131 | target_tree->set_source_frame_number(source_frame_number()); |
| 132 | target_tree->set_background_color(background_color()); |
| 133 | target_tree->set_has_transparent_background(has_transparent_background()); |
| 134 | |
| 135 | if (ContentsTexturesPurged()) |
| 136 | target_tree->SetContentsTexturesPurged(); |
| 137 | else |
| 138 | target_tree->ResetContentsTexturesPurged(); |
| 139 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 140 | if (ViewportSizeInvalid()) |
| 141 | target_tree->SetViewportSizeInvalid(); |
| 142 | else |
| 143 | target_tree->ResetViewportSizeInvalid(); |
| 144 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 145 | if (hud_layer()) |
| 146 | target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 147 | LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 148 | target_tree->root_layer(), hud_layer()->id()))); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 149 | else |
| 150 | target_tree->set_hud_layer(NULL); |
| 151 | } |
| 152 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 153 | LayerImpl* LayerTreeImpl::RootScrollLayer() const { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 154 | return root_scroll_layer_; |
| 155 | } |
| 156 | |
[email protected] | 0263522 | 2013-07-15 18:28:07 | [diff] [blame] | 157 | LayerImpl* LayerTreeImpl::RootContainerLayer() const { |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 158 | return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL; |
| 159 | } |
| 160 | |
| 161 | LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 162 | DCHECK(IsActiveTree()); |
| 163 | return currently_scrolling_layer_; |
| 164 | } |
| 165 | |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 166 | void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) { |
| 167 | if (currently_scrolling_layer_ == layer) |
| 168 | return; |
| 169 | |
| 170 | if (currently_scrolling_layer_ && |
| 171 | currently_scrolling_layer_->scrollbar_animation_controller()) |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 172 | currently_scrolling_layer_->scrollbar_animation_controller()-> |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 173 | DidScrollGestureEnd(CurrentPhysicalTimeTicks()); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 174 | currently_scrolling_layer_ = layer; |
| 175 | if (layer && layer->scrollbar_animation_controller()) |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 176 | layer->scrollbar_animation_controller()->DidScrollGestureBegin(); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 177 | } |
| 178 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 179 | void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 180 | SetCurrentlyScrollingLayer(NULL); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 181 | scrolling_layer_id_from_previous_tree_ = 0; |
| 182 | } |
| 183 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 184 | void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor, |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 185 | float min_page_scale_factor, float max_page_scale_factor) { |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 186 | if (!page_scale_factor) |
| 187 | return; |
| 188 | |
| 189 | min_page_scale_factor_ = min_page_scale_factor; |
| 190 | max_page_scale_factor_ = max_page_scale_factor; |
| 191 | page_scale_factor_ = page_scale_factor; |
| 192 | } |
| 193 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 194 | void LayerTreeImpl::SetPageScaleDelta(float delta) { |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 195 | // Clamp to the current min/max limits. |
| 196 | float total = page_scale_factor_ * delta; |
| 197 | if (min_page_scale_factor_ && total < min_page_scale_factor_) |
| 198 | delta = min_page_scale_factor_ / page_scale_factor_; |
| 199 | else if (max_page_scale_factor_ && total > max_page_scale_factor_) |
| 200 | delta = max_page_scale_factor_ / page_scale_factor_; |
| 201 | |
| 202 | if (delta == page_scale_delta_) |
| 203 | return; |
| 204 | |
| 205 | page_scale_delta_ = delta; |
| 206 | |
| 207 | if (IsActiveTree()) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 208 | LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 209 | if (pending_tree) { |
| 210 | DCHECK_EQ(1, pending_tree->sent_page_scale_delta()); |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 211 | pending_tree->SetPageScaleDelta( |
| 212 | page_scale_delta_ / sent_page_scale_delta_); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 213 | } |
| 214 | } |
| 215 | |
| 216 | UpdateMaxScrollOffset(); |
| 217 | set_needs_update_draw_properties(); |
| 218 | } |
| 219 | |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 220 | gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 221 | return gfx::ScaleSize(layer_tree_host_impl_->UnscaledScrollableViewportSize(), |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 222 | 1.0f / total_page_scale_factor()); |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 223 | } |
| 224 | |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 225 | void LayerTreeImpl::UpdateMaxScrollOffset() { |
[email protected] | 4babb95 | 2013-07-13 00:04:32 | [diff] [blame] | 226 | LayerImpl* root_scroll = RootScrollLayer(); |
| 227 | if (!root_scroll || !root_scroll->children().size()) |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 228 | return; |
| 229 | |
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 230 | gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() - |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 231 | gfx::RectF(ScrollableViewportSize()).bottom_right(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 232 | |
| 233 | // The viewport may be larger than the contents in some cases, such as |
| 234 | // having a vertical scrollbar but no horizontal overflow. |
[email protected] | a4a08d0 | 2013-05-30 00:18:00 | [diff] [blame] | 235 | max_scroll.SetToMax(gfx::Vector2dF()); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 236 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 237 | root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 238 | } |
| 239 | |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 240 | static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) { |
| 241 | layer->ApplySentScrollDeltasFromAbortedCommit(); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 242 | } |
| 243 | |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 244 | void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() { |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 245 | DCHECK(IsActiveTree()); |
| 246 | |
| 247 | page_scale_factor_ *= sent_page_scale_delta_; |
| 248 | page_scale_delta_ /= sent_page_scale_delta_; |
| 249 | sent_page_scale_delta_ = 1.f; |
| 250 | |
| 251 | if (!root_layer()) |
| 252 | return; |
| 253 | |
| 254 | LayerTreeHostCommon::CallFunctionForSubtree( |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 255 | root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo)); |
| 256 | } |
| 257 | |
| 258 | static void ApplyScrollDeltasSinceBeginFrameTo(LayerImpl* layer) { |
| 259 | layer->ApplyScrollDeltasSinceBeginFrame(); |
| 260 | } |
| 261 | |
| 262 | void LayerTreeImpl::ApplyScrollDeltasSinceBeginFrame() { |
| 263 | DCHECK(IsPendingTree()); |
| 264 | if (!root_layer()) |
| 265 | return; |
| 266 | |
| 267 | LayerTreeHostCommon::CallFunctionForSubtree( |
| 268 | root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginFrameTo)); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 271 | void LayerTreeImpl::SetViewportLayersFromIds( |
| 272 | int page_scale_layer_id, |
| 273 | int inner_viewport_scroll_layer_id, |
| 274 | int outer_viewport_scroll_layer_id) { |
| 275 | page_scale_layer_ = LayerById(page_scale_layer_id); |
| 276 | DCHECK(page_scale_layer_); |
| 277 | |
| 278 | inner_viewport_scroll_layer_ = |
| 279 | LayerById(inner_viewport_scroll_layer_id); |
| 280 | DCHECK(inner_viewport_scroll_layer_); |
| 281 | |
| 282 | outer_viewport_scroll_layer_ = |
| 283 | LayerById(outer_viewport_scroll_layer_id); |
| 284 | DCHECK(outer_viewport_scroll_layer_ || |
| 285 | outer_viewport_scroll_layer_id == Layer::INVALID_ID); |
| 286 | } |
| 287 | |
| 288 | void LayerTreeImpl::ClearViewportLayers() { |
| 289 | page_scale_layer_ = NULL; |
| 290 | inner_viewport_scroll_layer_ = NULL; |
| 291 | outer_viewport_scroll_layer_ = NULL; |
| 292 | } |
| 293 | |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 294 | // TODO(wjmaclean) This needs to go away, and be replaced with a single core |
| 295 | // of login that works for both scrollbar layer types. This is already planned |
| 296 | // as part of the larger pinch-zoom re-factoring viewport. |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 297 | void LayerTreeImpl::UpdateSolidColorScrollbars() { |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 298 | DCHECK(settings().solid_color_scrollbars); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 299 | |
| 300 | LayerImpl* root_scroll = RootScrollLayer(); |
[email protected] | ab5f4a9 | 2013-03-19 20:08:24 | [diff] [blame] | 301 | DCHECK(root_scroll); |
| 302 | DCHECK(IsActiveTree()); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 303 | |
| 304 | gfx::RectF scrollable_viewport( |
| 305 | gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()), |
| 306 | ScrollableViewportSize()); |
| 307 | float vertical_adjust = 0.0f; |
[email protected] | 0263522 | 2013-07-15 18:28:07 | [diff] [blame] | 308 | if (RootContainerLayer()) |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 309 | vertical_adjust = |
| 310 | layer_tree_host_impl_->UnscaledScrollableViewportSize().height() - |
| 311 | RootContainerLayer()->bounds().height(); |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 312 | if (ScrollbarLayerImplBase* horiz = |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 313 | root_scroll->horizontal_scrollbar_layer()) { |
[email protected] | 5493fc4 | 2013-08-15 01:46:22 | [diff] [blame] | 314 | horiz->SetVerticalAdjust(vertical_adjust); |
| 315 | horiz->SetVisibleToTotalLengthRatio( |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 316 | scrollable_viewport.width() / ScrollableSize().width()); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 317 | } |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 318 | if (ScrollbarLayerImplBase* vertical = |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 319 | root_scroll->vertical_scrollbar_layer()) { |
[email protected] | 5493fc4 | 2013-08-15 01:46:22 | [diff] [blame] | 320 | vertical->SetVerticalAdjust(vertical_adjust); |
| 321 | vertical->SetVisibleToTotalLengthRatio( |
[email protected] | c28df4c1 | 2013-05-22 17:36:49 | [diff] [blame] | 322 | scrollable_viewport.height() / ScrollableSize().height()); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 323 | } |
| 324 | } |
| 325 | |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 326 | void LayerTreeImpl::UpdateDrawProperties() { |
[email protected] | 0263522 | 2013-07-15 18:28:07 | [diff] [blame] | 327 | if (IsActiveTree() && RootScrollLayer() && RootContainerLayer()) |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 328 | UpdateRootScrollLayerSizeDelta(); |
| 329 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 330 | if (settings().solid_color_scrollbars && |
| 331 | IsActiveTree() && |
| 332 | RootScrollLayer()) { |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 333 | UpdateSolidColorScrollbars(); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 336 | needs_update_draw_properties_ = false; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 337 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 338 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 339 | // For max_texture_size. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 340 | if (!layer_tree_host_impl_->renderer()) |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 341 | return; |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 342 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 343 | if (!root_layer()) |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 344 | return; |
| 345 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 346 | { |
[email protected] | 7a52f43e | 2013-07-10 01:58:47 | [diff] [blame] | 347 | TRACE_EVENT2("cc", |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 348 | "LayerTreeImpl::UpdateDrawProperties", |
| 349 | "IsActive", |
[email protected] | 7a52f43e | 2013-07-10 01:58:47 | [diff] [blame] | 350 | IsActiveTree(), |
| 351 | "SourceFrameNumber", |
| 352 | source_frame_number_); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 353 | LayerImpl* page_scale_layer = |
| 354 | page_scale_layer_ ? page_scale_layer_ : RootContainerLayer(); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 355 | LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 356 | root_layer(), |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 357 | DrawViewportSize(), |
| 358 | layer_tree_host_impl_->DrawTransform(), |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 359 | device_scale_factor(), |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 360 | total_page_scale_factor(), |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 361 | page_scale_layer, |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 362 | MaxTextureSize(), |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 363 | settings().can_use_lcd_text, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 364 | settings().layer_transforms_should_scale_layer_contents, |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 365 | &render_surface_layer_list_); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 366 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 367 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 368 | |
| 369 | DCHECK(!needs_update_draw_properties_) << |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 370 | "CalcDrawProperties should not set_needs_update_draw_properties()"; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 371 | } |
| 372 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 373 | const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const { |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 374 | // If this assert triggers, then the list is dirty. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 375 | DCHECK(!needs_update_draw_properties_); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 376 | return render_surface_layer_list_; |
| 377 | } |
| 378 | |
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 379 | gfx::Size LayerTreeImpl::ScrollableSize() const { |
[email protected] | c4d467a | 2013-01-21 03:21:01 | [diff] [blame] | 380 | if (!root_scroll_layer_ || root_scroll_layer_->children().empty()) |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 381 | return gfx::Size(); |
[email protected] | c4d467a | 2013-01-21 03:21:01 | [diff] [blame] | 382 | return root_scroll_layer_->children()[0]->bounds(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 383 | } |
| 384 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 385 | LayerImpl* LayerTreeImpl::LayerById(int id) { |
| 386 | LayerIdMap::iterator iter = layer_id_map_.find(id); |
| 387 | return iter != layer_id_map_.end() ? iter->second : NULL; |
| 388 | } |
| 389 | |
| 390 | void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { |
| 391 | DCHECK(!LayerById(layer->id())); |
| 392 | layer_id_map_[layer->id()] = layer; |
| 393 | } |
| 394 | |
| 395 | void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { |
| 396 | DCHECK(LayerById(layer->id())); |
| 397 | layer_id_map_.erase(layer->id()); |
| 398 | } |
| 399 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 400 | void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { |
[email protected] | a90fac7 | 2013-06-06 18:56:13 | [diff] [blame] | 401 | pending_tree->SetCurrentlyScrollingLayer( |
| 402 | LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), |
| 403 | currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); |
[email protected] | b76329d | 2013-06-11 04:15:08 | [diff] [blame] | 404 | pending_tree->SetLatencyInfo(latency_info_); |
| 405 | latency_info_.Clear(); |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 406 | } |
| 407 | |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 408 | static void DidBecomeActiveRecursive(LayerImpl* layer) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 409 | layer->DidBecomeActive(); |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 410 | for (size_t i = 0; i < layer->children().size(); ++i) |
| 411 | DidBecomeActiveRecursive(layer->children()[i]); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | void LayerTreeImpl::DidBecomeActive() { |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 415 | if (!root_layer()) |
| 416 | return; |
| 417 | |
| 418 | DidBecomeActiveRecursive(root_layer()); |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 419 | FindRootScrollLayer(); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 420 | } |
| 421 | |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 422 | bool LayerTreeImpl::ContentsTexturesPurged() const { |
| 423 | return contents_textures_purged_; |
| 424 | } |
| 425 | |
| 426 | void LayerTreeImpl::SetContentsTexturesPurged() { |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 427 | if (contents_textures_purged_) |
| 428 | return; |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 429 | contents_textures_purged_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 430 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 431 | } |
| 432 | |
| 433 | void LayerTreeImpl::ResetContentsTexturesPurged() { |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 434 | if (!contents_textures_purged_) |
| 435 | return; |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 436 | contents_textures_purged_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 437 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 438 | } |
| 439 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 440 | bool LayerTreeImpl::ViewportSizeInvalid() const { |
| 441 | return viewport_size_invalid_; |
| 442 | } |
| 443 | |
| 444 | void LayerTreeImpl::SetViewportSizeInvalid() { |
| 445 | viewport_size_invalid_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 446 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | void LayerTreeImpl::ResetViewportSizeInvalid() { |
| 450 | viewport_size_invalid_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 451 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 454 | Proxy* LayerTreeImpl::proxy() const { |
| 455 | return layer_tree_host_impl_->proxy(); |
| 456 | } |
| 457 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 458 | const LayerTreeSettings& LayerTreeImpl::settings() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 459 | return layer_tree_host_impl_->settings(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 460 | } |
| 461 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 462 | const RendererCapabilities& LayerTreeImpl::GetRendererCapabilities() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 463 | return layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | bf5b3a0 | 2013-02-13 02:02:52 | [diff] [blame] | 464 | } |
| 465 | |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 466 | ContextProvider* LayerTreeImpl::context_provider() const { |
| 467 | return output_surface()->context_provider(); |
| 468 | } |
| 469 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 470 | OutputSurface* LayerTreeImpl::output_surface() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 471 | return layer_tree_host_impl_->output_surface(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | ResourceProvider* LayerTreeImpl::resource_provider() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 475 | return layer_tree_host_impl_->resource_provider(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 476 | } |
| 477 | |
| 478 | TileManager* LayerTreeImpl::tile_manager() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 479 | return layer_tree_host_impl_->tile_manager(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 480 | } |
| 481 | |
| 482 | FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 483 | return layer_tree_host_impl_->fps_counter(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 484 | } |
| 485 | |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 486 | PaintTimeCounter* LayerTreeImpl::paint_time_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 487 | return layer_tree_host_impl_->paint_time_counter(); |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 488 | } |
| 489 | |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 490 | MemoryHistory* LayerTreeImpl::memory_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 491 | return layer_tree_host_impl_->memory_history(); |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 492 | } |
| 493 | |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 494 | bool LayerTreeImpl::device_viewport_valid_for_tile_management() const { |
| 495 | return layer_tree_host_impl_->device_viewport_valid_for_tile_management(); |
| 496 | } |
| 497 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 498 | bool LayerTreeImpl::IsActiveTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 499 | return layer_tree_host_impl_->active_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | bool LayerTreeImpl::IsPendingTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 503 | return layer_tree_host_impl_->pending_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 504 | } |
| 505 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 506 | bool LayerTreeImpl::IsRecycleTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 507 | return layer_tree_host_impl_->recycle_tree() == this; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 508 | } |
| 509 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 510 | LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 511 | LayerTreeImpl* tree = layer_tree_host_impl_->active_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 512 | if (!tree) |
| 513 | return NULL; |
| 514 | return tree->LayerById(id); |
| 515 | } |
| 516 | |
| 517 | LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 518 | LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 519 | if (!tree) |
| 520 | return NULL; |
| 521 | return tree->LayerById(id); |
| 522 | } |
| 523 | |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 524 | int LayerTreeImpl::MaxTextureSize() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 525 | return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size; |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 526 | } |
| 527 | |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 528 | bool LayerTreeImpl::PinchGestureActive() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 529 | return layer_tree_host_impl_->pinch_gesture_active(); |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 530 | } |
| 531 | |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 532 | base::TimeTicks LayerTreeImpl::CurrentFrameTimeTicks() const { |
| 533 | return layer_tree_host_impl_->CurrentFrameTimeTicks(); |
| 534 | } |
| 535 | |
| 536 | base::Time LayerTreeImpl::CurrentFrameTime() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 537 | return layer_tree_host_impl_->CurrentFrameTime(); |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 538 | } |
| 539 | |
[email protected] | 21c9dee7 | 2013-06-15 01:20:05 | [diff] [blame] | 540 | base::TimeTicks LayerTreeImpl::CurrentPhysicalTimeTicks() const { |
| 541 | return layer_tree_host_impl_->CurrentPhysicalTimeTicks(); |
| 542 | } |
| 543 | |
[email protected] | d7eb8c7 | 2013-03-23 22:57:13 | [diff] [blame] | 544 | void LayerTreeImpl::SetNeedsCommit() { |
| 545 | layer_tree_host_impl_->SetNeedsCommit(); |
| 546 | } |
| 547 | |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 548 | gfx::Size LayerTreeImpl::DrawViewportSize() const { |
| 549 | return layer_tree_host_impl_->DrawViewportSize(); |
| 550 | } |
| 551 | |
[email protected] | 2ea5aba | 2013-09-11 14:26:56 | [diff] [blame] | 552 | void LayerTreeImpl::StartScrollbarAnimation() { |
| 553 | layer_tree_host_impl_->StartScrollbarAnimation(); |
| 554 | } |
| 555 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 556 | void LayerTreeImpl::SetNeedsRedraw() { |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 557 | layer_tree_host_impl_->SetNeedsRedraw(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 558 | } |
| 559 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 560 | const LayerTreeDebugState& LayerTreeImpl::debug_state() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 561 | return layer_tree_host_impl_->debug_state(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 562 | } |
| 563 | |
| 564 | float LayerTreeImpl::device_scale_factor() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 565 | return layer_tree_host_impl_->device_scale_factor(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 566 | } |
| 567 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 568 | DebugRectHistory* LayerTreeImpl::debug_rect_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 569 | return layer_tree_host_impl_->debug_rect_history(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 570 | } |
| 571 | |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 572 | AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 573 | return layer_tree_host_impl_->animation_registrar(); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 574 | } |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 575 | |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 576 | scoped_ptr<base::Value> LayerTreeImpl::AsValue() const { |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 577 | scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 578 | TracedValue::MakeDictIntoImplicitSnapshot( |
| 579 | state.get(), "cc::LayerTreeImpl", this); |
| 580 | |
| 581 | state->Set("root_layer", root_layer_->AsValue().release()); |
| 582 | |
| 583 | scoped_ptr<base::ListValue> render_surface_layer_list(new base::ListValue()); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 584 | typedef LayerIterator<LayerImpl, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 585 | LayerImplList, |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 586 | RenderSurfaceImpl, |
| 587 | LayerIteratorActions::BackToFront> LayerIteratorType; |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 588 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 589 | for (LayerIteratorType it = LayerIteratorType::Begin( |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 590 | &render_surface_layer_list_); it != end; ++it) { |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 591 | if (!it.represents_itself()) |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 592 | continue; |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 593 | render_surface_layer_list->Append(TracedValue::CreateIDRef(*it).release()); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 594 | } |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 595 | |
| 596 | state->Set("render_surface_layer_list", |
| 597 | render_surface_layer_list.release()); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 598 | return state.PassAs<base::Value>(); |
| 599 | } |
| 600 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 601 | void LayerTreeImpl::SetRootLayerScrollOffsetDelegate( |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 602 | LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) { |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 603 | root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate; |
| 604 | if (root_scroll_layer_) { |
| 605 | root_scroll_layer_->SetScrollOffsetDelegate( |
| 606 | root_layer_scroll_offset_delegate_); |
| 607 | } |
| 608 | } |
| 609 | |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 610 | void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() { |
| 611 | LayerImpl* root_scroll = RootScrollLayer(); |
[email protected] | 0263522 | 2013-07-15 18:28:07 | [diff] [blame] | 612 | LayerImpl* root_container = RootContainerLayer(); |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 613 | DCHECK(root_scroll); |
[email protected] | 0263522 | 2013-07-15 18:28:07 | [diff] [blame] | 614 | DCHECK(root_container); |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 615 | DCHECK(IsActiveTree()); |
| 616 | |
| 617 | gfx::Vector2dF scrollable_viewport_size = |
| 618 | gfx::RectF(ScrollableViewportSize()).bottom_right() - gfx::PointF(); |
| 619 | |
| 620 | gfx::Vector2dF original_viewport_size = |
[email protected] | 0263522 | 2013-07-15 18:28:07 | [diff] [blame] | 621 | gfx::RectF(root_container->bounds()).bottom_right() - |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 622 | gfx::PointF(); |
| 623 | original_viewport_size.Scale(1 / page_scale_factor()); |
| 624 | |
| 625 | root_scroll->SetFixedContainerSizeDelta( |
| 626 | scrollable_viewport_size - original_viewport_size); |
| 627 | } |
| 628 | |
[email protected] | 4b15766 | 2013-05-29 04:05:05 | [diff] [blame] | 629 | void LayerTreeImpl::SetLatencyInfo(const ui::LatencyInfo& latency_info) { |
[email protected] | e4c3c87a | 2013-04-22 02:28:40 | [diff] [blame] | 630 | latency_info_.MergeWith(latency_info); |
| 631 | } |
| 632 | |
[email protected] | 4b15766 | 2013-05-29 04:05:05 | [diff] [blame] | 633 | const ui::LatencyInfo& LayerTreeImpl::GetLatencyInfo() { |
[email protected] | e4c3c87a | 2013-04-22 02:28:40 | [diff] [blame] | 634 | return latency_info_; |
| 635 | } |
| 636 | |
| 637 | void LayerTreeImpl::ClearLatencyInfo() { |
| 638 | latency_info_.Clear(); |
| 639 | } |
| 640 | |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 641 | void LayerTreeImpl::DidModifyTilePriorities() { |
| 642 | layer_tree_host_impl_->DidModifyTilePriorities(); |
[email protected] | fcb846d | 2013-05-22 01:42:36 | [diff] [blame] | 643 | } |
| 644 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 645 | void LayerTreeImpl::set_ui_resource_request_queue( |
| 646 | const UIResourceRequestQueue& queue) { |
| 647 | ui_resource_request_queue_ = queue; |
| 648 | } |
| 649 | |
| 650 | ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource( |
| 651 | UIResourceId uid) const { |
| 652 | return layer_tree_host_impl_->ResourceIdForUIResource(uid); |
| 653 | } |
| 654 | |
| 655 | void LayerTreeImpl::ProcessUIResourceRequestQueue() { |
| 656 | while (ui_resource_request_queue_.size() > 0) { |
| 657 | UIResourceRequest req = ui_resource_request_queue_.front(); |
| 658 | ui_resource_request_queue_.pop_front(); |
| 659 | |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame^] | 660 | switch (req.GetType()) { |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 661 | case UIResourceRequest::UIResourceCreate: |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame^] | 662 | layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap()); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 663 | break; |
| 664 | case UIResourceRequest::UIResourceDelete: |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame^] | 665 | layer_tree_host_impl_->DeleteUIResource(req.GetId()); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 666 | break; |
[email protected] | f28d64d | 2013-08-27 04:17:45 | [diff] [blame] | 667 | case UIResourceRequest::UIResourceInvalidRequest: |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 668 | NOTREACHED(); |
| 669 | break; |
| 670 | } |
| 671 | } |
[email protected] | 127bdc1a | 2013-09-11 01:44:48 | [diff] [blame] | 672 | |
| 673 | // If all UI resource evictions were not recreated by processing this queue, |
| 674 | // then another commit is required. |
| 675 | if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
| 676 | layer_tree_host_impl_->SetNeedsCommit(); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 677 | } |
| 678 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 679 | void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) { |
| 680 | // Only the active tree needs to know about layers with copy requests, as |
| 681 | // they are aborted if not serviced during draw. |
| 682 | DCHECK(IsActiveTree()); |
| 683 | |
[email protected] | f5de9e5b | 2013-07-30 22:26:57 | [diff] [blame] | 684 | DCHECK(std::find(layers_with_copy_output_request_.begin(), |
| 685 | layers_with_copy_output_request_.end(), |
| 686 | layer) == layers_with_copy_output_request_.end()); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 687 | layers_with_copy_output_request_.push_back(layer); |
| 688 | } |
| 689 | |
| 690 | void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) { |
| 691 | // Only the active tree needs to know about layers with copy requests, as |
| 692 | // they are aborted if not serviced during draw. |
| 693 | DCHECK(IsActiveTree()); |
| 694 | |
| 695 | std::vector<LayerImpl*>::iterator it = std::find( |
| 696 | layers_with_copy_output_request_.begin(), |
| 697 | layers_with_copy_output_request_.end(), |
| 698 | layer); |
| 699 | DCHECK(it != layers_with_copy_output_request_.end()); |
[email protected] | f5de9e5b | 2013-07-30 22:26:57 | [diff] [blame] | 700 | layers_with_copy_output_request_.erase(it); |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 701 | } |
| 702 | |
| 703 | const std::vector<LayerImpl*> LayerTreeImpl::LayersWithCopyOutputRequest() |
| 704 | const { |
| 705 | // Only the active tree needs to know about layers with copy requests, as |
| 706 | // they are aborted if not serviced during draw. |
| 707 | DCHECK(IsActiveTree()); |
| 708 | |
| 709 | return layers_with_copy_output_request_; |
| 710 | } |
| 711 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 712 | } // namespace cc |