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