[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/animation.h" |
| 9 | #include "cc/animation/animation_id_provider.h" |
| 10 | #include "cc/animation/keyframed_animation_curve.h" |
| 11 | #include "cc/animation/scrollbar_animation_controller.h" |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 12 | #include "cc/debug/traced_value.h" |
[email protected] | cdb284d7 | 2013-03-18 09:34:48 | [diff] [blame] | 13 | #include "cc/input/pinch_zoom_scrollbar.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 14 | #include "cc/layers/heads_up_display_layer_impl.h" |
| 15 | #include "cc/layers/layer.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 16 | #include "cc/layers/render_surface_impl.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 17 | #include "cc/layers/scrollbar_layer_impl.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] | 8bef4057 | 2012-12-11 21:38:08 | [diff] [blame] | 25 | LayerTreeImpl::LayerTreeImpl(LayerTreeHostImpl* layer_tree_host_impl) |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 26 | : layer_tree_host_impl_(layer_tree_host_impl), |
| 27 | source_frame_number_(-1), |
| 28 | hud_layer_(0), |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 29 | root_scroll_layer_(NULL), |
| 30 | currently_scrolling_layer_(NULL), |
| 31 | root_layer_scroll_offset_delegate_(NULL), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 32 | background_color_(0), |
| 33 | has_transparent_background_(false), |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 34 | pinch_zoom_scrollbar_horizontal_layer_id_(Layer::INVALID_ID), |
| 35 | pinch_zoom_scrollbar_vertical_layer_id_(Layer::INVALID_ID), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 36 | page_scale_factor_(1), |
| 37 | page_scale_delta_(1), |
| 38 | sent_page_scale_delta_(1), |
| 39 | min_page_scale_factor_(0), |
| 40 | max_page_scale_factor_(0), |
| 41 | scrolling_layer_id_from_previous_tree_(0), |
| 42 | contents_textures_purged_(false), |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 43 | viewport_size_invalid_(false), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 44 | needs_update_draw_properties_(true), |
| 45 | needs_full_tree_sync_(true) { |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | LayerTreeImpl::~LayerTreeImpl() { |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 49 | // Need to explicitly clear the tree prior to destroying this so that |
| 50 | // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. |
| 51 | root_layer_.reset(); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 52 | } |
| 53 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 54 | static LayerImpl* FindRootScrollLayerRecursive(LayerImpl* layer) { |
| 55 | if (!layer) |
| 56 | return NULL; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 57 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 58 | if (layer->scrollable()) |
| 59 | return layer; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 60 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 61 | for (size_t i = 0; i < layer->children().size(); ++i) { |
| 62 | LayerImpl* found = FindRootScrollLayerRecursive(layer->children()[i]); |
| 63 | if (found) |
| 64 | return found; |
| 65 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 66 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 67 | return NULL; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 71 | if (root_scroll_layer_) |
| 72 | root_scroll_layer_->SetScrollOffsetDelegate(NULL); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 73 | root_layer_ = layer.Pass(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 74 | currently_scrolling_layer_ = NULL; |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 75 | root_scroll_layer_ = NULL; |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 76 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 77 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void LayerTreeImpl::FindRootScrollLayer() { |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 81 | root_scroll_layer_ = FindRootScrollLayerRecursive(root_layer_.get()); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 82 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 83 | if (root_scroll_layer_) { |
| 84 | root_scroll_layer_->SetScrollOffsetDelegate( |
| 85 | root_layer_scroll_offset_delegate_); |
| 86 | } |
| 87 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 88 | if (root_layer_ && scrolling_layer_id_from_previous_tree_) { |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 89 | currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 90 | root_layer_.get(), |
| 91 | scrolling_layer_id_from_previous_tree_); |
| 92 | } |
| 93 | |
| 94 | scrolling_layer_id_from_previous_tree_ = 0; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { |
| 98 | // Clear all data structures that have direct references to the layer tree. |
| 99 | scrolling_layer_id_from_previous_tree_ = |
| 100 | currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 101 | if (root_scroll_layer_) |
| 102 | root_scroll_layer_->SetScrollOffsetDelegate(NULL); |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 103 | root_scroll_layer_ = NULL; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 104 | currently_scrolling_layer_ = NULL; |
| 105 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 106 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 107 | set_needs_update_draw_properties(); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 108 | return root_layer_.Pass(); |
| 109 | } |
| 110 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 111 | void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { |
[email protected] | e4c3c87a | 2013-04-22 02:28:40 | [diff] [blame] | 112 | target_tree->SetLatencyInfo(latency_info_); |
| 113 | latency_info_.Clear(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 114 | target_tree->SetPageScaleFactorAndLimits( |
| 115 | page_scale_factor(), min_page_scale_factor(), max_page_scale_factor()); |
| 116 | target_tree->SetPageScaleDelta( |
| 117 | target_tree->page_scale_delta() / target_tree->sent_page_scale_delta()); |
| 118 | target_tree->set_sent_page_scale_delta(1); |
| 119 | |
| 120 | // This should match the property synchronization in |
| 121 | // LayerTreeHost::finishCommitOnImplThread(). |
| 122 | target_tree->set_source_frame_number(source_frame_number()); |
| 123 | target_tree->set_background_color(background_color()); |
| 124 | target_tree->set_has_transparent_background(has_transparent_background()); |
| 125 | |
| 126 | if (ContentsTexturesPurged()) |
| 127 | target_tree->SetContentsTexturesPurged(); |
| 128 | else |
| 129 | target_tree->ResetContentsTexturesPurged(); |
| 130 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 131 | if (ViewportSizeInvalid()) |
| 132 | target_tree->SetViewportSizeInvalid(); |
| 133 | else |
| 134 | target_tree->ResetViewportSizeInvalid(); |
| 135 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 136 | if (hud_layer()) |
| 137 | target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 138 | LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 139 | target_tree->root_layer(), hud_layer()->id()))); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 140 | else |
| 141 | target_tree->set_hud_layer(NULL); |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 142 | |
| 143 | target_tree->SetPinchZoomHorizontalLayerId( |
| 144 | pinch_zoom_scrollbar_horizontal_layer_id_); |
| 145 | target_tree->SetPinchZoomVerticalLayerId( |
| 146 | pinch_zoom_scrollbar_vertical_layer_id_); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 147 | } |
| 148 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 149 | LayerImpl* LayerTreeImpl::RootScrollLayer() const { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 150 | DCHECK(IsActiveTree()); |
| 151 | return root_scroll_layer_; |
| 152 | } |
| 153 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 154 | LayerImpl* LayerTreeImpl::RootClipLayer() const { |
| 155 | return root_scroll_layer_ ? root_scroll_layer_->parent() : NULL; |
| 156 | } |
| 157 | |
| 158 | LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 159 | DCHECK(IsActiveTree()); |
| 160 | return currently_scrolling_layer_; |
| 161 | } |
| 162 | |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 163 | void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) { |
| 164 | if (currently_scrolling_layer_ == layer) |
| 165 | return; |
| 166 | |
| 167 | if (currently_scrolling_layer_ && |
| 168 | currently_scrolling_layer_->scrollbar_animation_controller()) |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 169 | currently_scrolling_layer_->scrollbar_animation_controller()-> |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 170 | DidScrollGestureEnd(CurrentFrameTimeTicks()); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 171 | currently_scrolling_layer_ = layer; |
| 172 | if (layer && layer->scrollbar_animation_controller()) |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 173 | layer->scrollbar_animation_controller()->DidScrollGestureBegin(); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 174 | } |
| 175 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 176 | void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 177 | SetCurrentlyScrollingLayer(NULL); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 178 | scrolling_layer_id_from_previous_tree_ = 0; |
| 179 | } |
| 180 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 181 | void LayerTreeImpl::SetPageScaleFactorAndLimits(float page_scale_factor, |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 182 | float min_page_scale_factor, float max_page_scale_factor) { |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 183 | if (!page_scale_factor) |
| 184 | return; |
| 185 | |
| 186 | min_page_scale_factor_ = min_page_scale_factor; |
| 187 | max_page_scale_factor_ = max_page_scale_factor; |
| 188 | page_scale_factor_ = page_scale_factor; |
| 189 | } |
| 190 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 191 | void LayerTreeImpl::SetPageScaleDelta(float delta) { |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 192 | // Clamp to the current min/max limits. |
| 193 | float total = page_scale_factor_ * delta; |
| 194 | if (min_page_scale_factor_ && total < min_page_scale_factor_) |
| 195 | delta = min_page_scale_factor_ / page_scale_factor_; |
| 196 | else if (max_page_scale_factor_ && total > max_page_scale_factor_) |
| 197 | delta = max_page_scale_factor_ / page_scale_factor_; |
| 198 | |
| 199 | if (delta == page_scale_delta_) |
| 200 | return; |
| 201 | |
| 202 | page_scale_delta_ = delta; |
| 203 | |
| 204 | if (IsActiveTree()) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 205 | LayerTreeImpl* pending_tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 206 | if (pending_tree) { |
| 207 | DCHECK_EQ(1, pending_tree->sent_page_scale_delta()); |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 208 | pending_tree->SetPageScaleDelta( |
| 209 | page_scale_delta_ / sent_page_scale_delta_); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
| 213 | UpdateMaxScrollOffset(); |
| 214 | set_needs_update_draw_properties(); |
| 215 | } |
| 216 | |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 217 | gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 218 | return gfx::ScaleSize(layer_tree_host_impl_->VisibleViewportSize(), |
| 219 | 1.0f / total_page_scale_factor()); |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 220 | } |
| 221 | |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 222 | void LayerTreeImpl::UpdateMaxScrollOffset() { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 223 | if (!root_scroll_layer_ || !root_scroll_layer_->children().size()) |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 224 | return; |
| 225 | |
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 226 | gfx::Vector2dF max_scroll = gfx::Rect(ScrollableSize()).bottom_right() - |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 227 | gfx::RectF(ScrollableViewportSize()).bottom_right(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 228 | |
| 229 | // The viewport may be larger than the contents in some cases, such as |
| 230 | // having a vertical scrollbar but no horizontal overflow. |
| 231 | max_scroll.ClampToMin(gfx::Vector2dF()); |
| 232 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 233 | root_scroll_layer_->SetMaxScrollOffset(gfx::ToFlooredVector2d(max_scroll)); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 234 | } |
| 235 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 236 | void LayerTreeImpl::UpdateSolidColorScrollbars() { |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 237 | DCHECK(settings().solid_color_scrollbars); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 238 | |
| 239 | LayerImpl* root_scroll = RootScrollLayer(); |
[email protected] | ab5f4a9 | 2013-03-19 20:08:24 | [diff] [blame] | 240 | DCHECK(root_scroll); |
| 241 | DCHECK(IsActiveTree()); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 242 | |
| 243 | gfx::RectF scrollable_viewport( |
| 244 | gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()), |
| 245 | ScrollableViewportSize()); |
| 246 | float vertical_adjust = 0.0f; |
| 247 | if (RootClipLayer()) |
| 248 | vertical_adjust = layer_tree_host_impl_->VisibleViewportSize().height() - |
| 249 | RootClipLayer()->bounds().height(); |
| 250 | if (ScrollbarLayerImpl* horiz = root_scroll->horizontal_scrollbar_layer()) { |
| 251 | horiz->set_vertical_adjust(vertical_adjust); |
| 252 | horiz->SetViewportWithinScrollableArea(scrollable_viewport, |
| 253 | ScrollableSize()); |
| 254 | } |
| 255 | if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) { |
| 256 | vertical->set_vertical_adjust(vertical_adjust); |
| 257 | vertical->SetViewportWithinScrollableArea(scrollable_viewport, |
| 258 | ScrollableSize()); |
| 259 | } |
| 260 | } |
| 261 | |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 262 | void LayerTreeImpl::UpdateDrawProperties() { |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 263 | if (IsActiveTree() && RootScrollLayer() && RootClipLayer()) |
| 264 | UpdateRootScrollLayerSizeDelta(); |
| 265 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 266 | if (settings().solid_color_scrollbars && |
| 267 | IsActiveTree() && |
| 268 | RootScrollLayer()) { |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 269 | UpdateSolidColorScrollbars(); |
| 270 | |
| 271 | // The top controls manager is incompatible with the WebKit-created cliprect |
| 272 | // because it can bring into view a larger amount of content when it |
| 273 | // hides. It's safe to deactivate the clip rect if no non-overlay scrollbars |
| 274 | // are present. |
[email protected] | ab5f4a9 | 2013-03-19 20:08:24 | [diff] [blame] | 275 | if (RootClipLayer() && layer_tree_host_impl_->top_controls_manager()) |
| 276 | RootClipLayer()->SetMasksToBounds(false); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 277 | } |
| 278 | |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 279 | needs_update_draw_properties_ = false; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 280 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 281 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 282 | // For max_texture_size. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 283 | if (!layer_tree_host_impl_->renderer()) |
| 284 | return; |
| 285 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 286 | if (!root_layer()) |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 287 | return; |
| 288 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 289 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 290 | TRACE_EVENT1("cc", |
| 291 | "LayerTreeImpl::UpdateDrawProperties", |
| 292 | "IsActive", |
| 293 | IsActiveTree()); |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 294 | LayerTreeHostCommon::CalculateDrawProperties( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 295 | root_layer(), |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 296 | device_viewport_size(), |
| 297 | device_scale_factor(), |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 298 | total_page_scale_factor(), |
[email protected] | f213626 | 2013-04-26 21:10:19 | [diff] [blame] | 299 | root_scroll_layer_, |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 300 | MaxTextureSize(), |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 301 | settings().can_use_lcd_text, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 302 | settings().layer_transforms_should_scale_layer_contents, |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 303 | &render_surface_layer_list_); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 304 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 305 | |
| 306 | DCHECK(!needs_update_draw_properties_) << |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 307 | "CalcDrawProperties should not set_needs_update_draw_properties()"; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 308 | } |
| 309 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 310 | static void ClearRenderSurfacesOnLayerImplRecursive(LayerImpl* current) { |
| 311 | DCHECK(current); |
| 312 | for (size_t i = 0; i < current->children().size(); ++i) |
| 313 | ClearRenderSurfacesOnLayerImplRecursive(current->children()[i]); |
| 314 | current->ClearRenderSurface(); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | void LayerTreeImpl::ClearRenderSurfaces() { |
[email protected] | 2a61ad5 | 2013-05-13 14:01:29 | [diff] [blame^] | 318 | if (root_layer() == NULL) { |
| 319 | DCHECK(render_surface_layer_list_.empty()); |
| 320 | return; |
| 321 | } |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 322 | ClearRenderSurfacesOnLayerImplRecursive(root_layer()); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 323 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 324 | set_needs_update_draw_properties(); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 325 | } |
| 326 | |
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 327 | bool LayerTreeImpl::AreVisibleResourcesReady() const { |
| 328 | TRACE_EVENT0("cc", "LayerTreeImpl::AreVisibleResourcesReady"); |
| 329 | |
| 330 | typedef LayerIterator<LayerImpl, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 331 | LayerImplList, |
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 332 | RenderSurfaceImpl, |
| 333 | LayerIteratorActions::BackToFront> LayerIteratorType; |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 334 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 335 | for (LayerIteratorType it = LayerIteratorType::Begin( |
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 336 | &render_surface_layer_list_); it != end; ++it) { |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 337 | if (it.represents_itself() && !(*it)->AreVisibleResourcesReady()) |
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 338 | return false; |
| 339 | } |
| 340 | |
| 341 | return true; |
| 342 | } |
| 343 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 344 | const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const { |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 345 | // If this assert triggers, then the list is dirty. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 346 | DCHECK(!needs_update_draw_properties_); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 347 | return render_surface_layer_list_; |
| 348 | } |
| 349 | |
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 350 | gfx::Size LayerTreeImpl::ScrollableSize() const { |
[email protected] | c4d467a | 2013-01-21 03:21:01 | [diff] [blame] | 351 | if (!root_scroll_layer_ || root_scroll_layer_->children().empty()) |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 352 | return gfx::Size(); |
[email protected] | c4d467a | 2013-01-21 03:21:01 | [diff] [blame] | 353 | return root_scroll_layer_->children()[0]->bounds(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 354 | } |
| 355 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 356 | LayerImpl* LayerTreeImpl::LayerById(int id) { |
| 357 | LayerIdMap::iterator iter = layer_id_map_.find(id); |
| 358 | return iter != layer_id_map_.end() ? iter->second : NULL; |
| 359 | } |
| 360 | |
| 361 | void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { |
| 362 | DCHECK(!LayerById(layer->id())); |
| 363 | layer_id_map_[layer->id()] = layer; |
| 364 | } |
| 365 | |
| 366 | void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { |
| 367 | DCHECK(LayerById(layer->id())); |
| 368 | layer_id_map_.erase(layer->id()); |
| 369 | } |
| 370 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 371 | void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 372 | int id = currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; |
[email protected] | 2a61ad5 | 2013-05-13 14:01:29 | [diff] [blame^] | 373 | LayerImpl* pending_scrolling_layer_twin = NULL; |
| 374 | if (pending_tree->root_layer()) { |
| 375 | pending_scrolling_layer_twin = |
| 376 | LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), id); |
| 377 | } |
| 378 | pending_tree->SetCurrentlyScrollingLayer(pending_scrolling_layer_twin); |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 379 | } |
| 380 | |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 381 | static void DidBecomeActiveRecursive(LayerImpl* layer) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 382 | layer->DidBecomeActive(); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 383 | for (size_t i = 0; i < layer->children().size(); ++i) |
| 384 | DidBecomeActiveRecursive(layer->children()[i]); |
| 385 | } |
| 386 | |
| 387 | void LayerTreeImpl::DidBecomeActive() { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 388 | if (root_layer()) |
| 389 | DidBecomeActiveRecursive(root_layer()); |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 390 | FindRootScrollLayer(); |
| 391 | UpdateMaxScrollOffset(); |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 392 | // Main thread scrolls do not get handled in LayerTreeHostImpl, so after |
| 393 | // each commit (and after the root scroll layer has its max scroll offset |
| 394 | // set), we need to update pinch zoom scrollbars. |
| 395 | UpdatePinchZoomScrollbars(); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 396 | } |
| 397 | |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 398 | bool LayerTreeImpl::ContentsTexturesPurged() const { |
| 399 | return contents_textures_purged_; |
| 400 | } |
| 401 | |
| 402 | void LayerTreeImpl::SetContentsTexturesPurged() { |
| 403 | contents_textures_purged_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 404 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | void LayerTreeImpl::ResetContentsTexturesPurged() { |
| 408 | contents_textures_purged_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 409 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 410 | } |
| 411 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 412 | bool LayerTreeImpl::ViewportSizeInvalid() const { |
| 413 | return viewport_size_invalid_; |
| 414 | } |
| 415 | |
| 416 | void LayerTreeImpl::SetViewportSizeInvalid() { |
| 417 | viewport_size_invalid_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 418 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | void LayerTreeImpl::ResetViewportSizeInvalid() { |
| 422 | viewport_size_invalid_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 423 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 424 | } |
| 425 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 426 | Proxy* LayerTreeImpl::proxy() const { |
| 427 | return layer_tree_host_impl_->proxy(); |
| 428 | } |
| 429 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 430 | const LayerTreeSettings& LayerTreeImpl::settings() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 431 | return layer_tree_host_impl_->settings(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 432 | } |
| 433 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 434 | const RendererCapabilities& LayerTreeImpl::GetRendererCapabilities() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 435 | return layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | bf5b3a0 | 2013-02-13 02:02:52 | [diff] [blame] | 436 | } |
| 437 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 438 | OutputSurface* LayerTreeImpl::output_surface() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 439 | return layer_tree_host_impl_->output_surface(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | ResourceProvider* LayerTreeImpl::resource_provider() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 443 | return layer_tree_host_impl_->resource_provider(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | TileManager* LayerTreeImpl::tile_manager() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 447 | return layer_tree_host_impl_->tile_manager(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 451 | return layer_tree_host_impl_->fps_counter(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 452 | } |
| 453 | |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 454 | PaintTimeCounter* LayerTreeImpl::paint_time_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 455 | return layer_tree_host_impl_->paint_time_counter(); |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 456 | } |
| 457 | |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 458 | MemoryHistory* LayerTreeImpl::memory_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 459 | return layer_tree_host_impl_->memory_history(); |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 460 | } |
| 461 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 462 | bool LayerTreeImpl::IsActiveTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 463 | return layer_tree_host_impl_->active_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | bool LayerTreeImpl::IsPendingTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 467 | return layer_tree_host_impl_->pending_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 468 | } |
| 469 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 470 | bool LayerTreeImpl::IsRecycleTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 471 | return layer_tree_host_impl_->recycle_tree() == this; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 472 | } |
| 473 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 474 | LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 475 | LayerTreeImpl* tree = layer_tree_host_impl_->active_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 476 | if (!tree) |
| 477 | return NULL; |
| 478 | return tree->LayerById(id); |
| 479 | } |
| 480 | |
| 481 | LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 482 | LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 483 | if (!tree) |
| 484 | return NULL; |
| 485 | return tree->LayerById(id); |
| 486 | } |
| 487 | |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 488 | int LayerTreeImpl::MaxTextureSize() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 489 | return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size; |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 490 | } |
| 491 | |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 492 | bool LayerTreeImpl::PinchGestureActive() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 493 | return layer_tree_host_impl_->pinch_gesture_active(); |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 494 | } |
| 495 | |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 496 | base::TimeTicks LayerTreeImpl::CurrentFrameTimeTicks() const { |
| 497 | return layer_tree_host_impl_->CurrentFrameTimeTicks(); |
| 498 | } |
| 499 | |
| 500 | base::Time LayerTreeImpl::CurrentFrameTime() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 501 | return layer_tree_host_impl_->CurrentFrameTime(); |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 502 | } |
| 503 | |
[email protected] | d7eb8c7 | 2013-03-23 22:57:13 | [diff] [blame] | 504 | void LayerTreeImpl::SetNeedsCommit() { |
| 505 | layer_tree_host_impl_->SetNeedsCommit(); |
| 506 | } |
| 507 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 508 | void LayerTreeImpl::SetNeedsRedraw() { |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 509 | layer_tree_host_impl_->SetNeedsRedraw(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 510 | } |
| 511 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 512 | const LayerTreeDebugState& LayerTreeImpl::debug_state() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 513 | return layer_tree_host_impl_->debug_state(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 514 | } |
| 515 | |
| 516 | float LayerTreeImpl::device_scale_factor() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 517 | return layer_tree_host_impl_->device_scale_factor(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 518 | } |
| 519 | |
[email protected] | 90ec987 | 2013-03-08 02:28:18 | [diff] [blame] | 520 | gfx::Size LayerTreeImpl::device_viewport_size() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 521 | return layer_tree_host_impl_->device_viewport_size(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 522 | } |
| 523 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 524 | std::string LayerTreeImpl::layer_tree_as_text() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 525 | return layer_tree_host_impl_->LayerTreeAsText(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | DebugRectHistory* LayerTreeImpl::debug_rect_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 529 | return layer_tree_host_impl_->debug_rect_history(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 530 | } |
| 531 | |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 532 | AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 533 | return layer_tree_host_impl_->animation_registrar(); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 534 | } |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 535 | |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 536 | scoped_ptr<base::Value> LayerTreeImpl::AsValue() const { |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 537 | scoped_ptr<base::DictionaryValue> state(new base::DictionaryValue()); |
| 538 | TracedValue::MakeDictIntoImplicitSnapshot( |
| 539 | state.get(), "cc::LayerTreeImpl", this); |
| 540 | |
| 541 | state->Set("root_layer", root_layer_->AsValue().release()); |
| 542 | |
| 543 | scoped_ptr<base::ListValue> render_surface_layer_list(new base::ListValue()); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 544 | typedef LayerIterator<LayerImpl, |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 545 | LayerImplList, |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 546 | RenderSurfaceImpl, |
| 547 | LayerIteratorActions::BackToFront> LayerIteratorType; |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 548 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 549 | for (LayerIteratorType it = LayerIteratorType::Begin( |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 550 | &render_surface_layer_list_); it != end; ++it) { |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 551 | if (!it.represents_itself()) |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 552 | continue; |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 553 | render_surface_layer_list->Append(TracedValue::CreateIDRef(*it).release()); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 554 | } |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 555 | |
| 556 | state->Set("render_surface_layer_list", |
| 557 | render_surface_layer_list.release()); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 558 | return state.PassAs<base::Value>(); |
| 559 | } |
| 560 | |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 561 | void LayerTreeImpl::DidBeginScroll() { |
| 562 | if (HasPinchZoomScrollbars()) |
| 563 | FadeInPinchZoomScrollbars(); |
| 564 | } |
| 565 | |
| 566 | void LayerTreeImpl::DidUpdateScroll() { |
| 567 | if (HasPinchZoomScrollbars()) |
| 568 | UpdatePinchZoomScrollbars(); |
| 569 | } |
| 570 | |
| 571 | void LayerTreeImpl::DidEndScroll() { |
| 572 | if (HasPinchZoomScrollbars()) |
| 573 | FadeOutPinchZoomScrollbars(); |
| 574 | } |
| 575 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 576 | void LayerTreeImpl::SetRootLayerScrollOffsetDelegate( |
| 577 | LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) { |
| 578 | root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate; |
| 579 | if (root_scroll_layer_) { |
| 580 | root_scroll_layer_->SetScrollOffsetDelegate( |
| 581 | root_layer_scroll_offset_delegate_); |
| 582 | } |
| 583 | } |
| 584 | |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 585 | void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) { |
| 586 | pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id; |
| 587 | } |
| 588 | |
| 589 | ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() { |
| 590 | return static_cast<ScrollbarLayerImpl*>(LayerById( |
| 591 | pinch_zoom_scrollbar_horizontal_layer_id_)); |
| 592 | } |
| 593 | |
| 594 | void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) { |
| 595 | pinch_zoom_scrollbar_vertical_layer_id_ = layer_id; |
| 596 | } |
| 597 | |
| 598 | ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() { |
| 599 | return static_cast<ScrollbarLayerImpl*>(LayerById( |
| 600 | pinch_zoom_scrollbar_vertical_layer_id_)); |
| 601 | } |
| 602 | |
| 603 | void LayerTreeImpl::UpdatePinchZoomScrollbars() { |
| 604 | LayerImpl* root_scroll_layer = RootScrollLayer(); |
| 605 | if (!root_scroll_layer) |
| 606 | return; |
| 607 | |
| 608 | if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) { |
| 609 | scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x()); |
| 610 | scrollbar->SetTotalSize(root_scroll_layer->bounds().width()); |
| 611 | scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x()); |
| 612 | } |
| 613 | if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) { |
| 614 | scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y()); |
| 615 | scrollbar->SetTotalSize(root_scroll_layer->bounds().height()); |
| 616 | scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().y()); |
| 617 | } |
| 618 | } |
| 619 | |
| 620 | static scoped_ptr<Animation> MakePinchZoomFadeAnimation( |
| 621 | float start_opacity, float end_opacity) { |
| 622 | scoped_ptr<KeyframedFloatAnimationCurve> curve = |
| 623 | KeyframedFloatAnimationCurve::Create(); |
| 624 | curve->AddKeyframe(FloatKeyframe::Create( |
[email protected] | befd0f5 | 2013-03-24 10:00:36 | [diff] [blame] | 625 | 0, start_opacity, EaseInTimingFunction::Create())); |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 626 | curve->AddKeyframe(FloatKeyframe::Create( |
| 627 | PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity, |
[email protected] | befd0f5 | 2013-03-24 10:00:36 | [diff] [blame] | 628 | EaseInTimingFunction::Create())); |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 629 | |
| 630 | scoped_ptr<Animation> animation = Animation::Create( |
| 631 | curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(), |
| 632 | 0, Animation::Opacity); |
| 633 | animation->set_is_impl_only(true); |
| 634 | |
| 635 | return animation.Pass(); |
| 636 | } |
| 637 | |
| 638 | static void StartFadeInAnimation(ScrollbarLayerImpl* layer) { |
| 639 | DCHECK(layer); |
| 640 | float start_opacity = layer->opacity(); |
| 641 | LayerAnimationController* controller = layer->layer_animation_controller(); |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 642 | // TODO(wjmaclean) It shouldn't be necessary to manually remove the old |
| 643 | // animation. |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 644 | if (Animation* animation = controller->GetAnimation(Animation::Opacity)) |
| 645 | controller->RemoveAnimation(animation->id()); |
| 646 | controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity, |
| 647 | PinchZoomScrollbar::kDefaultOpacity)); |
| 648 | } |
| 649 | |
| 650 | void LayerTreeImpl::FadeInPinchZoomScrollbars() { |
| 651 | if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1) |
| 652 | return; |
| 653 | |
| 654 | StartFadeInAnimation(PinchZoomScrollbarHorizontal()); |
| 655 | StartFadeInAnimation(PinchZoomScrollbarVertical()); |
[email protected] | 2da0d47 | 2013-04-19 03:28:37 | [diff] [blame] | 656 | SetNeedsRedraw(); |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 657 | } |
| 658 | |
| 659 | static void StartFadeOutAnimation(LayerImpl* layer) { |
| 660 | float opacity = layer->opacity(); |
| 661 | if (!opacity) |
| 662 | return; |
| 663 | |
| 664 | LayerAnimationController* controller = layer->layer_animation_controller(); |
| 665 | // TODO(wjmaclean) It shouldn't be necessary to manually remove the old |
| 666 | // animation. |
| 667 | if (Animation* animation = controller->GetAnimation(Animation::Opacity)) |
| 668 | controller->RemoveAnimation(animation->id()); |
| 669 | controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0)); |
| 670 | } |
| 671 | |
| 672 | void LayerTreeImpl::FadeOutPinchZoomScrollbars() { |
| 673 | if (!HasPinchZoomScrollbars()) |
| 674 | return; |
| 675 | |
| 676 | StartFadeOutAnimation(PinchZoomScrollbarHorizontal()); |
| 677 | StartFadeOutAnimation(PinchZoomScrollbarVertical()); |
[email protected] | 2da0d47 | 2013-04-19 03:28:37 | [diff] [blame] | 678 | SetNeedsRedraw(); |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 679 | } |
| 680 | |
| 681 | bool LayerTreeImpl::HasPinchZoomScrollbars() const { |
| 682 | return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID && |
| 683 | pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID; |
| 684 | } |
| 685 | |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 686 | void LayerTreeImpl::UpdateRootScrollLayerSizeDelta() { |
| 687 | LayerImpl* root_scroll = RootScrollLayer(); |
| 688 | LayerImpl* root_clip = RootClipLayer(); |
| 689 | DCHECK(root_scroll); |
| 690 | DCHECK(root_clip); |
| 691 | DCHECK(IsActiveTree()); |
| 692 | |
| 693 | gfx::Vector2dF scrollable_viewport_size = |
| 694 | gfx::RectF(ScrollableViewportSize()).bottom_right() - gfx::PointF(); |
| 695 | |
| 696 | gfx::Vector2dF original_viewport_size = |
| 697 | gfx::RectF(root_clip->bounds()).bottom_right() - |
| 698 | gfx::PointF(); |
| 699 | original_viewport_size.Scale(1 / page_scale_factor()); |
| 700 | |
| 701 | root_scroll->SetFixedContainerSizeDelta( |
| 702 | scrollable_viewport_size - original_viewport_size); |
| 703 | } |
| 704 | |
[email protected] | e4c3c87a | 2013-04-22 02:28:40 | [diff] [blame] | 705 | void LayerTreeImpl::SetLatencyInfo(const LatencyInfo& latency_info) { |
| 706 | latency_info_.MergeWith(latency_info); |
| 707 | } |
| 708 | |
| 709 | const LatencyInfo& LayerTreeImpl::GetLatencyInfo() { |
| 710 | return latency_info_; |
| 711 | } |
| 712 | |
| 713 | void LayerTreeImpl::ClearLatencyInfo() { |
| 714 | latency_info_.Clear(); |
| 715 | } |
| 716 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 717 | } // namespace cc |