[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] | cdb284d7 | 2013-03-18 09:34:48 | [diff] [blame] | 12 | #include "cc/input/pinch_zoom_scrollbar.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 13 | #include "cc/layers/heads_up_display_layer_impl.h" |
| 14 | #include "cc/layers/layer.h" |
| 15 | #include "cc/layers/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_) { |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 79 | currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 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*>( |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 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()) |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 155 | currently_scrolling_layer_->scrollbar_animation_controller()-> |
| 156 | DidScrollGestureEnd(base::TimeTicks::Now()); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 157 | currently_scrolling_layer_ = layer; |
| 158 | if (layer && layer->scrollbar_animation_controller()) |
[email protected] | 6bc09e8 | 2013-03-19 03:48:35 | [diff] [blame] | 159 | layer->scrollbar_animation_controller()->DidScrollGestureBegin(); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 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() { |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 228 | DCHECK(settings().solid_color_scrollbars); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 229 | |
| 230 | LayerImpl* root_scroll = RootScrollLayer(); |
[email protected] | ab5f4a9 | 2013-03-19 20:08:24 | [diff] [blame] | 231 | DCHECK(root_scroll); |
| 232 | DCHECK(IsActiveTree()); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 233 | |
| 234 | gfx::RectF scrollable_viewport( |
| 235 | gfx::PointAtOffsetFromOrigin(root_scroll->TotalScrollOffset()), |
| 236 | ScrollableViewportSize()); |
| 237 | float vertical_adjust = 0.0f; |
| 238 | if (RootClipLayer()) |
| 239 | vertical_adjust = layer_tree_host_impl_->VisibleViewportSize().height() - |
| 240 | RootClipLayer()->bounds().height(); |
| 241 | if (ScrollbarLayerImpl* horiz = root_scroll->horizontal_scrollbar_layer()) { |
| 242 | horiz->set_vertical_adjust(vertical_adjust); |
| 243 | horiz->SetViewportWithinScrollableArea(scrollable_viewport, |
| 244 | ScrollableSize()); |
| 245 | } |
| 246 | if (ScrollbarLayerImpl* vertical = root_scroll->vertical_scrollbar_layer()) { |
| 247 | vertical->set_vertical_adjust(vertical_adjust); |
| 248 | vertical->SetViewportWithinScrollableArea(scrollable_viewport, |
| 249 | ScrollableSize()); |
| 250 | } |
| 251 | } |
| 252 | |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 253 | struct UpdateTilePrioritiesForLayer { |
| 254 | void operator()(LayerImpl *layer) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 255 | layer->UpdateTilePriorities(); |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 256 | } |
| 257 | }; |
| 258 | |
| 259 | void LayerTreeImpl::UpdateDrawProperties(UpdateDrawPropertiesReason reason) { |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 260 | if (settings().solid_color_scrollbars && IsActiveTree() && RootScrollLayer()) { |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 261 | UpdateSolidColorScrollbars(); |
| 262 | |
| 263 | // The top controls manager is incompatible with the WebKit-created cliprect |
| 264 | // because it can bring into view a larger amount of content when it |
| 265 | // hides. It's safe to deactivate the clip rect if no non-overlay scrollbars |
| 266 | // are present. |
[email protected] | ab5f4a9 | 2013-03-19 20:08:24 | [diff] [blame] | 267 | if (RootClipLayer() && layer_tree_host_impl_->top_controls_manager()) |
| 268 | RootClipLayer()->SetMasksToBounds(false); |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 269 | } |
| 270 | |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 271 | if (!needs_update_draw_properties_) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 272 | if (reason == UPDATE_ACTIVE_TREE_FOR_DRAW && root_layer()) |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 273 | LayerTreeHostCommon::CallFunctionForSubtree<UpdateTilePrioritiesForLayer>( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 274 | root_layer()); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 275 | return; |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 276 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 277 | |
| 278 | needs_update_draw_properties_ = false; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 279 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 280 | |
| 281 | // For maxTextureSize. |
| 282 | if (!layer_tree_host_impl_->renderer()) |
| 283 | return; |
| 284 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 285 | if (!root_layer()) |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 286 | return; |
| 287 | |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 288 | if (root_scroll_layer_) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 289 | root_scroll_layer_->SetImplTransform(ImplTransform()); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 290 | // Setting the impl transform re-sets this. |
| 291 | needs_update_draw_properties_ = false; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 292 | } |
| 293 | |
| 294 | { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 295 | TRACE_EVENT1("cc", |
| 296 | "LayerTreeImpl::UpdateDrawProperties", |
| 297 | "IsActive", |
| 298 | IsActiveTree()); |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 299 | bool update_tile_priorities = |
| 300 | reason == UPDATE_PENDING_TREE || |
| 301 | reason == UPDATE_ACTIVE_TREE_FOR_DRAW; |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 302 | LayerTreeHostCommon::CalculateDrawProperties( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 303 | root_layer(), |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 304 | device_viewport_size(), |
| 305 | device_scale_factor(), |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 306 | total_page_scale_factor(), |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 307 | MaxTextureSize(), |
[email protected] | 8e0176d | 2013-03-21 03:14:52 | [diff] [blame] | 308 | settings().can_use_lcd_text, |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 309 | &render_surface_layer_list_, |
[email protected] | 4c9bb95 | 2013-01-27 05:41:18 | [diff] [blame] | 310 | update_tile_priorities); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 311 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 312 | |
| 313 | DCHECK(!needs_update_draw_properties_) << |
| 314 | "calcDrawProperties should not set_needs_update_draw_properties()"; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 315 | } |
| 316 | |
[email protected] | 3c0a325 | 2013-03-18 04:24:36 | [diff] [blame] | 317 | static void ClearRenderSurfacesOnLayerImplRecursive(LayerImpl* current) { |
| 318 | DCHECK(current); |
| 319 | for (size_t i = 0; i < current->children().size(); ++i) |
| 320 | ClearRenderSurfacesOnLayerImplRecursive(current->children()[i]); |
| 321 | current->ClearRenderSurface(); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | void LayerTreeImpl::ClearRenderSurfaces() { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 325 | ClearRenderSurfacesOnLayerImplRecursive(root_layer()); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 326 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 327 | set_needs_update_draw_properties(); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 328 | } |
| 329 | |
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 330 | bool LayerTreeImpl::AreVisibleResourcesReady() const { |
| 331 | TRACE_EVENT0("cc", "LayerTreeImpl::AreVisibleResourcesReady"); |
| 332 | |
| 333 | typedef LayerIterator<LayerImpl, |
| 334 | std::vector<LayerImpl*>, |
| 335 | RenderSurfaceImpl, |
| 336 | LayerIteratorActions::BackToFront> LayerIteratorType; |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 337 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 338 | for (LayerIteratorType it = LayerIteratorType::Begin( |
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 339 | &render_surface_layer_list_); it != end; ++it) { |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 340 | if (it.represents_itself() && !(*it)->AreVisibleResourcesReady()) |
[email protected] | b0a917c8d | 2013-01-12 17:42:25 | [diff] [blame] | 341 | return false; |
| 342 | } |
| 343 | |
| 344 | return true; |
| 345 | } |
| 346 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 347 | const LayerTreeImpl::LayerList& LayerTreeImpl::RenderSurfaceLayerList() const { |
| 348 | // If this assert triggers, then the list is dirty. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 349 | DCHECK(!needs_update_draw_properties_); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 350 | return render_surface_layer_list_; |
| 351 | } |
| 352 | |
[email protected] | 42ccdbef | 2013-01-21 07:54:54 | [diff] [blame] | 353 | gfx::Size LayerTreeImpl::ScrollableSize() const { |
[email protected] | c4d467a | 2013-01-21 03:21:01 | [diff] [blame] | 354 | if (!root_scroll_layer_ || root_scroll_layer_->children().empty()) |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 355 | return gfx::Size(); |
[email protected] | c4d467a | 2013-01-21 03:21:01 | [diff] [blame] | 356 | return root_scroll_layer_->children()[0]->bounds(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 357 | } |
| 358 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 359 | LayerImpl* LayerTreeImpl::LayerById(int id) { |
| 360 | LayerIdMap::iterator iter = layer_id_map_.find(id); |
| 361 | return iter != layer_id_map_.end() ? iter->second : NULL; |
| 362 | } |
| 363 | |
| 364 | void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { |
| 365 | DCHECK(!LayerById(layer->id())); |
| 366 | layer_id_map_[layer->id()] = layer; |
| 367 | } |
| 368 | |
| 369 | void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { |
| 370 | DCHECK(LayerById(layer->id())); |
| 371 | layer_id_map_.erase(layer->id()); |
| 372 | } |
| 373 | |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 374 | void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pendingTree) { |
| 375 | int id = currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 376 | pendingTree->SetCurrentlyScrollingLayer( |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 377 | LayerTreeHostCommon::FindLayerInSubtree(pendingTree->root_layer(), id)); |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 378 | } |
| 379 | |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 380 | static void DidBecomeActiveRecursive(LayerImpl* layer) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 381 | layer->DidBecomeActive(); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 382 | for (size_t i = 0; i < layer->children().size(); ++i) |
| 383 | DidBecomeActiveRecursive(layer->children()[i]); |
| 384 | } |
| 385 | |
| 386 | void LayerTreeImpl::DidBecomeActive() { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 387 | if (root_layer()) |
| 388 | DidBecomeActiveRecursive(root_layer()); |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 389 | FindRootScrollLayer(); |
| 390 | UpdateMaxScrollOffset(); |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 391 | // Main thread scrolls do not get handled in LayerTreeHostImpl, so after |
| 392 | // each commit (and after the root scroll layer has its max scroll offset |
| 393 | // set), we need to update pinch zoom scrollbars. |
| 394 | UpdatePinchZoomScrollbars(); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 395 | } |
| 396 | |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 397 | bool LayerTreeImpl::ContentsTexturesPurged() const { |
| 398 | return contents_textures_purged_; |
| 399 | } |
| 400 | |
| 401 | void LayerTreeImpl::SetContentsTexturesPurged() { |
| 402 | contents_textures_purged_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 403 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 404 | } |
| 405 | |
| 406 | void LayerTreeImpl::ResetContentsTexturesPurged() { |
| 407 | contents_textures_purged_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 408 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 409 | } |
| 410 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 411 | bool LayerTreeImpl::ViewportSizeInvalid() const { |
| 412 | return viewport_size_invalid_; |
| 413 | } |
| 414 | |
| 415 | void LayerTreeImpl::SetViewportSizeInvalid() { |
| 416 | viewport_size_invalid_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 417 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | void LayerTreeImpl::ResetViewportSizeInvalid() { |
| 421 | viewport_size_invalid_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 422 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 423 | } |
| 424 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 425 | Proxy* LayerTreeImpl::proxy() const { |
| 426 | return layer_tree_host_impl_->proxy(); |
| 427 | } |
| 428 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 429 | const LayerTreeSettings& LayerTreeImpl::settings() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 430 | return layer_tree_host_impl_->settings(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 431 | } |
| 432 | |
[email protected] | bf5b3a0 | 2013-02-13 02:02:52 | [diff] [blame] | 433 | const RendererCapabilities& LayerTreeImpl::rendererCapabilities() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 434 | return layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | bf5b3a0 | 2013-02-13 02:02:52 | [diff] [blame] | 435 | } |
| 436 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 437 | OutputSurface* LayerTreeImpl::output_surface() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 438 | return layer_tree_host_impl_->output_surface(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | ResourceProvider* LayerTreeImpl::resource_provider() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 442 | return layer_tree_host_impl_->resource_provider(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | TileManager* LayerTreeImpl::tile_manager() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 446 | return layer_tree_host_impl_->tile_manager(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 447 | } |
| 448 | |
| 449 | FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 450 | return layer_tree_host_impl_->fps_counter(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 451 | } |
| 452 | |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 453 | PaintTimeCounter* LayerTreeImpl::paint_time_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 454 | return layer_tree_host_impl_->paint_time_counter(); |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 455 | } |
| 456 | |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 457 | MemoryHistory* LayerTreeImpl::memory_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 458 | return layer_tree_host_impl_->memory_history(); |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 459 | } |
| 460 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 461 | bool LayerTreeImpl::IsActiveTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 462 | return layer_tree_host_impl_->active_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | bool LayerTreeImpl::IsPendingTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 466 | return layer_tree_host_impl_->pending_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 467 | } |
| 468 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 469 | bool LayerTreeImpl::IsRecycleTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 470 | return layer_tree_host_impl_->recycle_tree() == this; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 471 | } |
| 472 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 473 | LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 474 | LayerTreeImpl* tree = layer_tree_host_impl_->active_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 475 | if (!tree) |
| 476 | return NULL; |
| 477 | return tree->LayerById(id); |
| 478 | } |
| 479 | |
| 480 | LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 481 | LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 482 | if (!tree) |
| 483 | return NULL; |
| 484 | return tree->LayerById(id); |
| 485 | } |
| 486 | |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 487 | int LayerTreeImpl::MaxTextureSize() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 488 | return layer_tree_host_impl_->GetRendererCapabilities().max_texture_size; |
[email protected] | f677653 | 2012-12-21 20:24:33 | [diff] [blame] | 489 | } |
| 490 | |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 491 | bool LayerTreeImpl::PinchGestureActive() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 492 | return layer_tree_host_impl_->pinch_gesture_active(); |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 493 | } |
| 494 | |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 495 | base::TimeTicks LayerTreeImpl::CurrentFrameTime() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 496 | return layer_tree_host_impl_->CurrentFrameTime(); |
[email protected] | 829ad97 | 2013-01-28 23:36:10 | [diff] [blame] | 497 | } |
| 498 | |
[email protected] | d7eb8c7 | 2013-03-23 22:57:13 | [diff] [blame^] | 499 | void LayerTreeImpl::SetNeedsCommit() { |
| 500 | layer_tree_host_impl_->SetNeedsCommit(); |
| 501 | } |
| 502 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 503 | void LayerTreeImpl::SetNeedsRedraw() { |
| 504 | layer_tree_host_impl_->setNeedsRedraw(); |
| 505 | } |
| 506 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 507 | const LayerTreeDebugState& LayerTreeImpl::debug_state() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 508 | return layer_tree_host_impl_->debug_state(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | float LayerTreeImpl::device_scale_factor() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 512 | return layer_tree_host_impl_->device_scale_factor(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 513 | } |
| 514 | |
[email protected] | 90ec9878 | 2013-03-08 02:28:18 | [diff] [blame] | 515 | gfx::Size LayerTreeImpl::device_viewport_size() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 516 | return layer_tree_host_impl_->device_viewport_size(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 517 | } |
| 518 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 519 | gfx::Size LayerTreeImpl::layout_viewport_size() const { |
| 520 | return layer_tree_host_impl_->layout_viewport_size(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 521 | } |
| 522 | |
| 523 | std::string LayerTreeImpl::layer_tree_as_text() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 524 | return layer_tree_host_impl_->LayerTreeAsText(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | DebugRectHistory* LayerTreeImpl::debug_rect_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 528 | return layer_tree_host_impl_->debug_rect_history(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 529 | } |
| 530 | |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 531 | AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 532 | return layer_tree_host_impl_->animation_registrar(); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 533 | } |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 534 | |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 535 | scoped_ptr<base::Value> LayerTreeImpl::AsValue() const { |
| 536 | scoped_ptr<base::ListValue> state(new base::ListValue()); |
| 537 | typedef LayerIterator<LayerImpl, |
| 538 | std::vector<LayerImpl*>, |
| 539 | RenderSurfaceImpl, |
| 540 | LayerIteratorActions::BackToFront> LayerIteratorType; |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 541 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 542 | for (LayerIteratorType it = LayerIteratorType::Begin( |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 543 | &render_surface_layer_list_); it != end; ++it) { |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 544 | if (!it.represents_itself()) |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 545 | continue; |
| 546 | state->Append((*it)->AsValue().release()); |
| 547 | } |
| 548 | return state.PassAs<base::Value>(); |
| 549 | } |
| 550 | |
[email protected] | b7c4783f | 2013-03-15 23:11:42 | [diff] [blame] | 551 | void LayerTreeImpl::DidBeginScroll() { |
| 552 | if (HasPinchZoomScrollbars()) |
| 553 | FadeInPinchZoomScrollbars(); |
| 554 | } |
| 555 | |
| 556 | void LayerTreeImpl::DidUpdateScroll() { |
| 557 | if (HasPinchZoomScrollbars()) |
| 558 | UpdatePinchZoomScrollbars(); |
| 559 | } |
| 560 | |
| 561 | void LayerTreeImpl::DidEndScroll() { |
| 562 | if (HasPinchZoomScrollbars()) |
| 563 | FadeOutPinchZoomScrollbars(); |
| 564 | } |
| 565 | |
| 566 | void LayerTreeImpl::SetPinchZoomHorizontalLayerId(int layer_id) { |
| 567 | pinch_zoom_scrollbar_horizontal_layer_id_ = layer_id; |
| 568 | } |
| 569 | |
| 570 | ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarHorizontal() { |
| 571 | return static_cast<ScrollbarLayerImpl*>(LayerById( |
| 572 | pinch_zoom_scrollbar_horizontal_layer_id_)); |
| 573 | } |
| 574 | |
| 575 | void LayerTreeImpl::SetPinchZoomVerticalLayerId(int layer_id) { |
| 576 | pinch_zoom_scrollbar_vertical_layer_id_ = layer_id; |
| 577 | } |
| 578 | |
| 579 | ScrollbarLayerImpl* LayerTreeImpl::PinchZoomScrollbarVertical() { |
| 580 | return static_cast<ScrollbarLayerImpl*>(LayerById( |
| 581 | pinch_zoom_scrollbar_vertical_layer_id_)); |
| 582 | } |
| 583 | |
| 584 | void LayerTreeImpl::UpdatePinchZoomScrollbars() { |
| 585 | LayerImpl* root_scroll_layer = RootScrollLayer(); |
| 586 | if (!root_scroll_layer) |
| 587 | return; |
| 588 | |
| 589 | if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarHorizontal()) { |
| 590 | scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().x()); |
| 591 | scrollbar->SetTotalSize(root_scroll_layer->bounds().width()); |
| 592 | scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().x()); |
| 593 | } |
| 594 | if (ScrollbarLayerImpl* scrollbar = PinchZoomScrollbarVertical()) { |
| 595 | scrollbar->SetCurrentPos(root_scroll_layer->scroll_offset().y()); |
| 596 | scrollbar->SetTotalSize(root_scroll_layer->bounds().height()); |
| 597 | scrollbar->SetMaximum(root_scroll_layer->max_scroll_offset().y()); |
| 598 | } |
| 599 | } |
| 600 | |
| 601 | static scoped_ptr<Animation> MakePinchZoomFadeAnimation( |
| 602 | float start_opacity, float end_opacity) { |
| 603 | scoped_ptr<KeyframedFloatAnimationCurve> curve = |
| 604 | KeyframedFloatAnimationCurve::Create(); |
| 605 | curve->AddKeyframe(FloatKeyframe::Create( |
| 606 | 0, start_opacity, EaseInTimingFunction::create())); |
| 607 | curve->AddKeyframe(FloatKeyframe::Create( |
| 608 | PinchZoomScrollbar::kFadeDurationInSeconds, end_opacity, |
| 609 | EaseInTimingFunction::create())); |
| 610 | |
| 611 | scoped_ptr<Animation> animation = Animation::Create( |
| 612 | curve.PassAs<AnimationCurve>(), AnimationIdProvider::NextAnimationId(), |
| 613 | 0, Animation::Opacity); |
| 614 | animation->set_is_impl_only(true); |
| 615 | |
| 616 | return animation.Pass(); |
| 617 | } |
| 618 | |
| 619 | static void StartFadeInAnimation(ScrollbarLayerImpl* layer) { |
| 620 | DCHECK(layer); |
| 621 | float start_opacity = layer->opacity(); |
| 622 | LayerAnimationController* controller = layer->layer_animation_controller(); |
| 623 | // TODO() It shouldn't be necessary to manually remove the old animation. |
| 624 | if (Animation* animation = controller->GetAnimation(Animation::Opacity)) |
| 625 | controller->RemoveAnimation(animation->id()); |
| 626 | controller->AddAnimation(MakePinchZoomFadeAnimation(start_opacity, |
| 627 | PinchZoomScrollbar::kDefaultOpacity)); |
| 628 | } |
| 629 | |
| 630 | void LayerTreeImpl::FadeInPinchZoomScrollbars() { |
| 631 | if (!HasPinchZoomScrollbars() || page_scale_factor_ == 1) |
| 632 | return; |
| 633 | |
| 634 | StartFadeInAnimation(PinchZoomScrollbarHorizontal()); |
| 635 | StartFadeInAnimation(PinchZoomScrollbarVertical()); |
| 636 | } |
| 637 | |
| 638 | static void StartFadeOutAnimation(LayerImpl* layer) { |
| 639 | float opacity = layer->opacity(); |
| 640 | if (!opacity) |
| 641 | return; |
| 642 | |
| 643 | LayerAnimationController* controller = layer->layer_animation_controller(); |
| 644 | // TODO(wjmaclean) It shouldn't be necessary to manually remove the old |
| 645 | // animation. |
| 646 | if (Animation* animation = controller->GetAnimation(Animation::Opacity)) |
| 647 | controller->RemoveAnimation(animation->id()); |
| 648 | controller->AddAnimation(MakePinchZoomFadeAnimation(opacity, 0)); |
| 649 | } |
| 650 | |
| 651 | void LayerTreeImpl::FadeOutPinchZoomScrollbars() { |
| 652 | if (!HasPinchZoomScrollbars()) |
| 653 | return; |
| 654 | |
| 655 | StartFadeOutAnimation(PinchZoomScrollbarHorizontal()); |
| 656 | StartFadeOutAnimation(PinchZoomScrollbarVertical()); |
| 657 | } |
| 658 | |
| 659 | bool LayerTreeImpl::HasPinchZoomScrollbars() const { |
| 660 | return pinch_zoom_scrollbar_horizontal_layer_id_ != Layer::INVALID_ID && |
| 661 | pinch_zoom_scrollbar_vertical_layer_id_ != Layer::INVALID_ID; |
| 662 | } |
| 663 | |
| 664 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 665 | } // namespace cc |