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