[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] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 7 | #include <limits> |
| 8 | #include <set> |
| 9 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 10 | #include "base/debug/trace_event.h" |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 11 | #include "base/debug/trace_event_argument.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 12 | #include "cc/animation/keyframed_animation_curve.h" |
| 13 | #include "cc/animation/scrollbar_animation_controller.h" |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 14 | #include "cc/animation/scrollbar_animation_controller_linear_fade.h" |
| 15 | #include "cc/animation/scrollbar_animation_controller_thinning.h" |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 16 | #include "cc/base/math_util.h" |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 17 | #include "cc/base/synced_property.h" |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 18 | #include "cc/base/util.h" |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 19 | #include "cc/debug/devtools_instrumentation.h" |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 20 | #include "cc/debug/traced_value.h" |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 21 | #include "cc/input/page_scale_animation.h" |
[email protected] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 22 | #include "cc/layers/heads_up_display_layer_impl.h" |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 23 | #include "cc/layers/layer.h" |
[email protected] | 34ba1ffb | 2014-03-05 06:55:03 | [diff] [blame] | 24 | #include "cc/layers/layer_iterator.h" |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 25 | #include "cc/layers/render_surface_impl.h" |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 26 | #include "cc/layers/scrollbar_layer_impl_base.h" |
[email protected] | e104219 | 2013-11-08 05:44:24 | [diff] [blame] | 27 | #include "cc/resources/ui_resource_request.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 28 | #include "cc/trees/layer_tree_host_common.h" |
| 29 | #include "cc/trees/layer_tree_host_impl.h" |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 30 | #include "cc/trees/occlusion_tracker.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 31 | #include "ui/gfx/geometry/point_conversions.h" |
| 32 | #include "ui/gfx/geometry/size_conversions.h" |
| 33 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 34 | |
| 35 | namespace cc { |
| 36 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 37 | // This class exists to split the LayerScrollOffsetDelegate between the |
| 38 | // InnerViewportScrollLayer and the OuterViewportScrollLayer in a manner |
| 39 | // that never requires the embedder or LayerImpl to know about. |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 40 | class LayerScrollOffsetDelegateProxy : public LayerImpl::ScrollOffsetDelegate { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 41 | public: |
| 42 | LayerScrollOffsetDelegateProxy(LayerImpl* layer, |
| 43 | LayerScrollOffsetDelegate* delegate, |
| 44 | LayerTreeImpl* layer_tree) |
| 45 | : layer_(layer), delegate_(delegate), layer_tree_impl_(layer_tree) {} |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 46 | virtual ~LayerScrollOffsetDelegateProxy() {} |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 47 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 48 | gfx::ScrollOffset last_set_scroll_offset() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 49 | return last_set_scroll_offset_; |
| 50 | } |
| 51 | |
| 52 | // LayerScrollOffsetDelegate implementation. |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 53 | void SetTotalScrollOffset(const gfx::ScrollOffset& new_offset) override { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 54 | last_set_scroll_offset_ = new_offset; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 55 | } |
| 56 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 57 | gfx::ScrollOffset GetTotalScrollOffset() override { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 58 | return layer_tree_impl_->GetDelegatedScrollOffset(layer_); |
| 59 | } |
| 60 | |
dcheng | 716bedf | 2014-10-21 09:51:08 | [diff] [blame] | 61 | bool IsExternalFlingActive() const override { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 62 | return delegate_->IsExternalFlingActive(); |
| 63 | } |
| 64 | |
bokan | 6747f552 | 2014-10-24 19:28:54 | [diff] [blame] | 65 | void Update() const override { |
| 66 | layer_tree_impl_->UpdateScrollOffsetDelegate(); |
| 67 | } |
| 68 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 69 | private: |
| 70 | LayerImpl* layer_; |
| 71 | LayerScrollOffsetDelegate* delegate_; |
| 72 | LayerTreeImpl* layer_tree_impl_; |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 73 | gfx::ScrollOffset last_set_scroll_offset_; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 74 | }; |
| 75 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 76 | LayerTreeImpl::LayerTreeImpl( |
| 77 | LayerTreeHostImpl* layer_tree_host_impl, |
| 78 | scoped_refptr<SyncedProperty<ScaleGroup>> page_scale_factor) |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 79 | : layer_tree_host_impl_(layer_tree_host_impl), |
| 80 | source_frame_number_(-1), |
| 81 | hud_layer_(0), |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 82 | currently_scrolling_layer_(NULL), |
| 83 | root_layer_scroll_offset_delegate_(NULL), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 84 | background_color_(0), |
| 85 | has_transparent_background_(false), |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 86 | page_scale_layer_(NULL), |
| 87 | inner_viewport_scroll_layer_(NULL), |
| 88 | outer_viewport_scroll_layer_(NULL), |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 89 | page_scale_factor_(page_scale_factor), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 90 | min_page_scale_factor_(0), |
| 91 | max_page_scale_factor_(0), |
| 92 | scrolling_layer_id_from_previous_tree_(0), |
| 93 | contents_textures_purged_(false), |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 94 | viewport_size_invalid_(false), |
[email protected] | db8259f | 2013-02-01 05:25:04 | [diff] [blame] | 95 | needs_update_draw_properties_(true), |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 96 | needs_full_tree_sync_(true), |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 97 | next_activation_forces_redraw_(false), |
[email protected] | 759dc9f | 2014-07-23 19:18:51 | [diff] [blame] | 98 | has_ever_been_drawn_(false), |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 99 | render_surface_layer_list_id_(0), |
| 100 | top_controls_layout_height_(0), |
bokan | 55b2f15 | 2014-09-15 14:47:59 | [diff] [blame] | 101 | top_controls_content_offset_(0), |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 102 | top_controls_delta_(0), |
| 103 | sent_top_controls_delta_(0) { |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 104 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 105 | |
| 106 | LayerTreeImpl::~LayerTreeImpl() { |
[email protected] | 586871b | 2014-07-22 17:05:11 | [diff] [blame] | 107 | BreakSwapPromises(SwapPromise::SWAP_FAILS); |
| 108 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 109 | // Need to explicitly clear the tree prior to destroying this so that |
| 110 | // the LayerTreeImpl pointer is still valid in the LayerImpl dtor. |
[email protected] | df17af5 | 2014-02-06 02:20:40 | [diff] [blame] | 111 | DCHECK(!root_layer_); |
| 112 | DCHECK(layers_with_copy_output_request_.empty()); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 113 | } |
| 114 | |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 115 | void LayerTreeImpl::Shutdown() { |
| 116 | root_layer_ = nullptr; |
| 117 | } |
[email protected] | df17af5 | 2014-02-06 02:20:40 | [diff] [blame] | 118 | |
[email protected] | aeef2f0 | 2014-05-10 12:15:48 | [diff] [blame] | 119 | void LayerTreeImpl::ReleaseResources() { |
| 120 | if (root_layer_) |
| 121 | ReleaseResourcesRecursive(root_layer_.get()); |
| 122 | } |
| 123 | |
[email protected] | d35cd7b2 | 2014-01-29 14:32:46 | [diff] [blame] | 124 | void LayerTreeImpl::SetRootLayer(scoped_ptr<LayerImpl> layer) { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 125 | if (inner_viewport_scroll_layer_) |
| 126 | inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
| 127 | if (outer_viewport_scroll_layer_) |
| 128 | outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 129 | inner_viewport_scroll_delegate_proxy_ = nullptr; |
| 130 | outer_viewport_scroll_delegate_proxy_ = nullptr; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 131 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 132 | root_layer_ = layer.Pass(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 133 | currently_scrolling_layer_ = NULL; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 134 | inner_viewport_scroll_layer_ = NULL; |
| 135 | outer_viewport_scroll_layer_ = NULL; |
| 136 | page_scale_layer_ = NULL; |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 137 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 138 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 5c4824e1 | 2013-01-12 16:34:53 | [diff] [blame] | 139 | } |
| 140 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 141 | LayerImpl* LayerTreeImpl::InnerViewportScrollLayer() const { |
| 142 | return inner_viewport_scroll_layer_; |
| 143 | } |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 144 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 145 | LayerImpl* LayerTreeImpl::OuterViewportScrollLayer() const { |
| 146 | return outer_viewport_scroll_layer_; |
| 147 | } |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 148 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 149 | gfx::ScrollOffset LayerTreeImpl::TotalScrollOffset() const { |
| 150 | gfx::ScrollOffset offset; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 151 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 152 | if (inner_viewport_scroll_layer_) |
| 153 | offset += inner_viewport_scroll_layer_->TotalScrollOffset(); |
| 154 | |
| 155 | if (outer_viewport_scroll_layer_) |
| 156 | offset += outer_viewport_scroll_layer_->TotalScrollOffset(); |
| 157 | |
| 158 | return offset; |
| 159 | } |
| 160 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 161 | gfx::ScrollOffset LayerTreeImpl::TotalMaxScrollOffset() const { |
| 162 | gfx::ScrollOffset offset; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 163 | |
| 164 | if (inner_viewport_scroll_layer_) |
| 165 | offset += inner_viewport_scroll_layer_->MaxScrollOffset(); |
| 166 | |
| 167 | if (outer_viewport_scroll_layer_) |
| 168 | offset += outer_viewport_scroll_layer_->MaxScrollOffset(); |
| 169 | |
| 170 | return offset; |
| 171 | } |
| 172 | gfx::Vector2dF LayerTreeImpl::TotalScrollDelta() const { |
| 173 | DCHECK(inner_viewport_scroll_layer_); |
| 174 | gfx::Vector2dF delta = inner_viewport_scroll_layer_->ScrollDelta(); |
| 175 | |
| 176 | if (outer_viewport_scroll_layer_) |
| 177 | delta += outer_viewport_scroll_layer_->ScrollDelta(); |
| 178 | |
| 179 | return delta; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 180 | } |
| 181 | |
| 182 | scoped_ptr<LayerImpl> LayerTreeImpl::DetachLayerTree() { |
| 183 | // Clear all data structures that have direct references to the layer tree. |
| 184 | scrolling_layer_id_from_previous_tree_ = |
| 185 | currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 186 | if (inner_viewport_scroll_layer_) |
| 187 | inner_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
| 188 | if (outer_viewport_scroll_layer_) |
| 189 | outer_viewport_scroll_layer_->SetScrollOffsetDelegate(NULL); |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 190 | inner_viewport_scroll_delegate_proxy_ = nullptr; |
| 191 | outer_viewport_scroll_delegate_proxy_ = nullptr; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 192 | inner_viewport_scroll_layer_ = NULL; |
| 193 | outer_viewport_scroll_layer_ = NULL; |
| 194 | page_scale_layer_ = NULL; |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 195 | currently_scrolling_layer_ = NULL; |
| 196 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 197 | render_surface_layer_list_.clear(); |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 198 | set_needs_update_draw_properties(); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 199 | return root_layer_.Pass(); |
| 200 | } |
| 201 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 202 | void LayerTreeImpl::PushPropertiesTo(LayerTreeImpl* target_tree) { |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 203 | // The request queue should have been processed and does not require a push. |
| 204 | DCHECK_EQ(ui_resource_request_queue_.size(), 0u); |
| 205 | |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 206 | if (next_activation_forces_redraw_) { |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 207 | target_tree->ForceRedrawNextActivation(); |
[email protected] | 7d08a935 | 2013-10-15 08:24:56 | [diff] [blame] | 208 | next_activation_forces_redraw_ = false; |
| 209 | } |
| 210 | |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 211 | target_tree->PassSwapPromises(&swap_promise_list_); |
| 212 | |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 213 | target_tree->top_controls_layout_height_ = top_controls_layout_height_; |
bokan | 55b2f15 | 2014-09-15 14:47:59 | [diff] [blame] | 214 | target_tree->top_controls_content_offset_ = top_controls_content_offset_; |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 215 | target_tree->top_controls_delta_ = |
| 216 | target_tree->top_controls_delta_ - |
| 217 | target_tree->sent_top_controls_delta_; |
| 218 | target_tree->sent_top_controls_delta_ = 0.f; |
| 219 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 220 | // Active tree already shares the page_scale_factor object with pending |
| 221 | // tree so only the limits need to be provided. |
| 222 | target_tree->PushPageScaleFactorAndLimits(nullptr, min_page_scale_factor(), |
| 223 | max_page_scale_factor()); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 224 | |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 225 | target_tree->pending_page_scale_animation_ = |
| 226 | pending_page_scale_animation_.Pass(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 227 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 228 | if (page_scale_layer_ && inner_viewport_scroll_layer_) { |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 229 | target_tree->SetViewportLayersFromIds( |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 230 | overscroll_elasticity_layer_ ? overscroll_elasticity_layer_->id() |
| 231 | : Layer::INVALID_ID, |
| 232 | page_scale_layer_->id(), inner_viewport_scroll_layer_->id(), |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 233 | outer_viewport_scroll_layer_ ? outer_viewport_scroll_layer_->id() |
| 234 | : Layer::INVALID_ID); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 235 | } else { |
| 236 | target_tree->ClearViewportLayers(); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 237 | } |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 238 | |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 239 | target_tree->RegisterSelection(selection_start_, selection_end_); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 240 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 241 | // This should match the property synchronization in |
| 242 | // LayerTreeHost::finishCommitOnImplThread(). |
| 243 | target_tree->set_source_frame_number(source_frame_number()); |
| 244 | target_tree->set_background_color(background_color()); |
| 245 | target_tree->set_has_transparent_background(has_transparent_background()); |
| 246 | |
| 247 | if (ContentsTexturesPurged()) |
| 248 | target_tree->SetContentsTexturesPurged(); |
| 249 | else |
| 250 | target_tree->ResetContentsTexturesPurged(); |
| 251 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 252 | if (ViewportSizeInvalid()) |
| 253 | target_tree->SetViewportSizeInvalid(); |
| 254 | else |
| 255 | target_tree->ResetViewportSizeInvalid(); |
| 256 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 257 | if (hud_layer()) |
| 258 | target_tree->set_hud_layer(static_cast<HeadsUpDisplayLayerImpl*>( |
[email protected] | 6ba91412 | 2013-03-22 16:26:39 | [diff] [blame] | 259 | LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 260 | target_tree->root_layer(), hud_layer()->id()))); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 261 | else |
| 262 | target_tree->set_hud_layer(NULL); |
[email protected] | 759dc9f | 2014-07-23 19:18:51 | [diff] [blame] | 263 | |
| 264 | target_tree->has_ever_been_drawn_ = false; |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 265 | } |
| 266 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 267 | LayerImpl* LayerTreeImpl::InnerViewportContainerLayer() const { |
| 268 | return inner_viewport_scroll_layer_ |
| 269 | ? inner_viewport_scroll_layer_->scroll_clip_layer() |
| 270 | : NULL; |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 271 | } |
| 272 | |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 273 | LayerImpl* LayerTreeImpl::OuterViewportContainerLayer() const { |
| 274 | return outer_viewport_scroll_layer_ |
| 275 | ? outer_viewport_scroll_layer_->scroll_clip_layer() |
| 276 | : NULL; |
| 277 | } |
| 278 | |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 279 | LayerImpl* LayerTreeImpl::CurrentlyScrollingLayer() const { |
[email protected] | 69b50ec | 2013-01-19 04:58:01 | [diff] [blame] | 280 | DCHECK(IsActiveTree()); |
| 281 | return currently_scrolling_layer_; |
| 282 | } |
| 283 | |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 284 | void LayerTreeImpl::SetCurrentlyScrollingLayer(LayerImpl* layer) { |
| 285 | if (currently_scrolling_layer_ == layer) |
| 286 | return; |
| 287 | |
| 288 | if (currently_scrolling_layer_ && |
| 289 | currently_scrolling_layer_->scrollbar_animation_controller()) |
[email protected] | 1dc0616 | 2014-03-26 22:54:45 | [diff] [blame] | 290 | currently_scrolling_layer_->scrollbar_animation_controller() |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 291 | ->DidScrollEnd(); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 292 | currently_scrolling_layer_ = layer; |
| 293 | if (layer && layer->scrollbar_animation_controller()) |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 294 | layer->scrollbar_animation_controller()->DidScrollBegin(); |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 295 | } |
| 296 | |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 297 | void LayerTreeImpl::ClearCurrentlyScrollingLayer() { |
[email protected] | 0fc818e | 2013-03-18 06:45:20 | [diff] [blame] | 298 | SetCurrentlyScrollingLayer(NULL); |
[email protected] | 3b31c6ac | 2012-12-06 21:27:29 | [diff] [blame] | 299 | scrolling_layer_id_from_previous_tree_ = 0; |
| 300 | } |
| 301 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 302 | namespace { |
| 303 | |
| 304 | void ForceScrollbarParameterUpdateAfterScaleChange(LayerImpl* current_layer) { |
| 305 | if (!current_layer) |
| 306 | return; |
| 307 | |
| 308 | while (current_layer) { |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 309 | current_layer->ScrollbarParametersDidChange(false); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 310 | current_layer = current_layer->parent(); |
| 311 | } |
| 312 | } |
| 313 | |
| 314 | } // namespace |
| 315 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 316 | float LayerTreeImpl::ClampPageScaleFactorToLimits( |
| 317 | float page_scale_factor) const { |
| 318 | if (min_page_scale_factor_ && page_scale_factor < min_page_scale_factor_) |
| 319 | page_scale_factor = min_page_scale_factor_; |
| 320 | else if (max_page_scale_factor_ && page_scale_factor > max_page_scale_factor_) |
| 321 | page_scale_factor = max_page_scale_factor_; |
| 322 | return page_scale_factor; |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 323 | } |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 324 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 325 | void LayerTreeImpl::SetPageScaleOnActiveTree(float active_page_scale) { |
| 326 | DCHECK(IsActiveTree()); |
| 327 | if (page_scale_factor()->SetCurrent( |
| 328 | ClampPageScaleFactorToLimits(active_page_scale))) |
| 329 | DidUpdatePageScale(); |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 330 | } |
| 331 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 332 | void LayerTreeImpl::PushPageScaleFromMainThread(float page_scale_factor, |
| 333 | float min_page_scale_factor, |
| 334 | float max_page_scale_factor) { |
| 335 | PushPageScaleFactorAndLimits(&page_scale_factor, min_page_scale_factor, |
| 336 | max_page_scale_factor); |
| 337 | } |
| 338 | |
| 339 | void LayerTreeImpl::PushPageScaleFactorAndLimits(const float* page_scale_factor, |
| 340 | float min_page_scale_factor, |
| 341 | float max_page_scale_factor) { |
| 342 | DCHECK(page_scale_factor || IsActiveTree()); |
| 343 | bool changed_page_scale = false; |
| 344 | if (page_scale_factor) { |
| 345 | DCHECK(!IsActiveTree() || !layer_tree_host_impl_->pending_tree()); |
| 346 | changed_page_scale |= |
| 347 | page_scale_factor_->PushFromMainThread(*page_scale_factor); |
| 348 | } |
| 349 | if (IsActiveTree()) |
| 350 | changed_page_scale |= page_scale_factor_->PushPendingToActive(); |
| 351 | changed_page_scale |= |
| 352 | SetPageScaleFactorLimits(min_page_scale_factor, max_page_scale_factor); |
| 353 | |
| 354 | if (changed_page_scale) |
| 355 | DidUpdatePageScale(); |
| 356 | } |
| 357 | |
| 358 | bool LayerTreeImpl::SetPageScaleFactorLimits(float min_page_scale_factor, |
| 359 | float max_page_scale_factor) { |
| 360 | if (min_page_scale_factor == min_page_scale_factor_ && |
| 361 | max_page_scale_factor == max_page_scale_factor_) |
| 362 | return false; |
[email protected] | 7265e74e | 2014-02-07 23:43:06 | [diff] [blame] | 363 | |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 364 | min_page_scale_factor_ = min_page_scale_factor; |
| 365 | max_page_scale_factor_ = max_page_scale_factor; |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 366 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 367 | return true; |
| 368 | } |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 369 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 370 | void LayerTreeImpl::DidUpdatePageScale() { |
| 371 | if (IsActiveTree()) |
| 372 | page_scale_factor()->SetCurrent( |
| 373 | ClampPageScaleFactorToLimits(current_page_scale_factor())); |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 374 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 375 | set_needs_update_draw_properties(); |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 376 | |
[email protected] | 22f200a | 2013-10-09 18:08:29 | [diff] [blame] | 377 | if (root_layer_scroll_offset_delegate_) { |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 378 | root_layer_scroll_offset_delegate_->UpdateRootLayerState( |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 379 | TotalScrollOffset(), TotalMaxScrollOffset(), ScrollableSize(), |
| 380 | current_page_scale_factor(), min_page_scale_factor_, |
[email protected] | d6021f6a | 2014-06-12 21:15:24 | [diff] [blame] | 381 | max_page_scale_factor_); |
[email protected] | 22f200a | 2013-10-09 18:08:29 | [diff] [blame] | 382 | } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 383 | |
| 384 | ForceScrollbarParameterUpdateAfterScaleChange(page_scale_layer()); |
[email protected] | c6027947 | 2013-01-30 12:10:51 | [diff] [blame] | 385 | } |
| 386 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 387 | SyncedProperty<ScaleGroup>* LayerTreeImpl::page_scale_factor() { |
| 388 | return page_scale_factor_.get(); |
| 389 | } |
| 390 | |
| 391 | const SyncedProperty<ScaleGroup>* LayerTreeImpl::page_scale_factor() const { |
| 392 | return page_scale_factor_.get(); |
| 393 | } |
| 394 | |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 395 | gfx::SizeF LayerTreeImpl::ScrollableViewportSize() const { |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 396 | if (!InnerViewportContainerLayer()) |
| 397 | return gfx::SizeF(); |
| 398 | |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 399 | return gfx::ScaleSize(InnerViewportContainerLayer()->BoundsForScrolling(), |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 400 | 1.0f / current_page_scale_factor()); |
[email protected] | 257abfa8 | 2013-01-29 23:47:24 | [diff] [blame] | 401 | } |
| 402 | |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 403 | gfx::Rect LayerTreeImpl::RootScrollLayerDeviceViewportBounds() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 404 | LayerImpl* root_scroll_layer = OuterViewportScrollLayer() |
| 405 | ? OuterViewportScrollLayer() |
| 406 | : InnerViewportScrollLayer(); |
| 407 | if (!root_scroll_layer || root_scroll_layer->children().empty()) |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 408 | return gfx::Rect(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 409 | LayerImpl* layer = root_scroll_layer->children()[0]; |
[email protected] | 8a82269 | 2014-02-12 17:30:55 | [diff] [blame] | 410 | return MathUtil::MapEnclosingClippedRect(layer->screen_space_transform(), |
| 411 | gfx::Rect(layer->content_bounds())); |
[email protected] | 3744e27b | 2013-11-06 21:44:08 | [diff] [blame] | 412 | } |
| 413 | |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 414 | static void ApplySentScrollDeltasFromAbortedCommitTo(LayerImpl* layer) { |
| 415 | layer->ApplySentScrollDeltasFromAbortedCommit(); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 416 | } |
| 417 | |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 418 | void LayerTreeImpl::ApplySentScrollAndScaleDeltasFromAbortedCommit() { |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 419 | DCHECK(IsActiveTree()); |
| 420 | |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 421 | page_scale_factor()->AbortCommit(); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 422 | |
bokan | 55b2f15 | 2014-09-15 14:47:59 | [diff] [blame] | 423 | top_controls_content_offset_ += sent_top_controls_delta_; |
bokan | 88eae01 | 2014-09-09 20:40:42 | [diff] [blame] | 424 | top_controls_delta_ -= sent_top_controls_delta_; |
| 425 | sent_top_controls_delta_ = 0.f; |
| 426 | |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 427 | if (!root_layer()) |
| 428 | return; |
| 429 | |
| 430 | LayerTreeHostCommon::CallFunctionForSubtree( |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 431 | root_layer(), base::Bind(&ApplySentScrollDeltasFromAbortedCommitTo)); |
| 432 | } |
| 433 | |
[email protected] | daea3d4 | 2013-10-23 17:04:50 | [diff] [blame] | 434 | static void ApplyScrollDeltasSinceBeginMainFrameTo(LayerImpl* layer) { |
| 435 | layer->ApplyScrollDeltasSinceBeginMainFrame(); |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 436 | } |
| 437 | |
[email protected] | daea3d4 | 2013-10-23 17:04:50 | [diff] [blame] | 438 | void LayerTreeImpl::ApplyScrollDeltasSinceBeginMainFrame() { |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 439 | DCHECK(IsPendingTree()); |
| 440 | if (!root_layer()) |
| 441 | return; |
| 442 | |
| 443 | LayerTreeHostCommon::CallFunctionForSubtree( |
[email protected] | daea3d4 | 2013-10-23 17:04:50 | [diff] [blame] | 444 | root_layer(), base::Bind(&ApplyScrollDeltasSinceBeginMainFrameTo)); |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 445 | } |
| 446 | |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 447 | void LayerTreeImpl::SetViewportLayersFromIds( |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 448 | int overscroll_elasticity_layer_id, |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 449 | int page_scale_layer_id, |
| 450 | int inner_viewport_scroll_layer_id, |
| 451 | int outer_viewport_scroll_layer_id) { |
ccameron | 8230b68b | 2014-11-21 19:25:18 | [diff] [blame] | 452 | overscroll_elasticity_layer_ = LayerById(overscroll_elasticity_layer_id); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 453 | page_scale_layer_ = LayerById(page_scale_layer_id); |
| 454 | DCHECK(page_scale_layer_); |
| 455 | |
| 456 | inner_viewport_scroll_layer_ = |
| 457 | LayerById(inner_viewport_scroll_layer_id); |
| 458 | DCHECK(inner_viewport_scroll_layer_); |
| 459 | |
| 460 | outer_viewport_scroll_layer_ = |
| 461 | LayerById(outer_viewport_scroll_layer_id); |
| 462 | DCHECK(outer_viewport_scroll_layer_ || |
| 463 | outer_viewport_scroll_layer_id == Layer::INVALID_ID); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 464 | |
| 465 | if (!root_layer_scroll_offset_delegate_) |
| 466 | return; |
| 467 | |
| 468 | inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 469 | new LayerScrollOffsetDelegateProxy(inner_viewport_scroll_layer_, |
| 470 | root_layer_scroll_offset_delegate_, |
| 471 | this)); |
| 472 | |
| 473 | if (outer_viewport_scroll_layer_) |
| 474 | outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 475 | new LayerScrollOffsetDelegateProxy(outer_viewport_scroll_layer_, |
| 476 | root_layer_scroll_offset_delegate_, |
| 477 | this)); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | void LayerTreeImpl::ClearViewportLayers() { |
| 481 | page_scale_layer_ = NULL; |
| 482 | inner_viewport_scroll_layer_ = NULL; |
| 483 | outer_viewport_scroll_layer_ = NULL; |
| 484 | } |
| 485 | |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 486 | bool LayerTreeImpl::UpdateDrawProperties() { |
| 487 | if (!needs_update_draw_properties_) |
| 488 | return true; |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 489 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 490 | // For max_texture_size. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 491 | if (!layer_tree_host_impl_->renderer()) |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 492 | return false; |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 493 | |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 494 | if (!root_layer()) |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 495 | return false; |
| 496 | |
| 497 | needs_update_draw_properties_ = false; |
| 498 | render_surface_layer_list_.clear(); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 499 | |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 500 | { |
[email protected] | 7a52f43e | 2013-07-10 01:58:47 | [diff] [blame] | 501 | TRACE_EVENT2("cc", |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 502 | "LayerTreeImpl::UpdateDrawProperties", |
| 503 | "IsActive", |
[email protected] | 7a52f43e | 2013-07-10 01:58:47 | [diff] [blame] | 504 | IsActiveTree(), |
| 505 | "SourceFrameNumber", |
| 506 | source_frame_number_); |
[email protected] | 57ac948 | 2013-09-17 21:13:39 | [diff] [blame] | 507 | LayerImpl* page_scale_layer = |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 508 | page_scale_layer_ ? page_scale_layer_ : InnerViewportContainerLayer(); |
hush | 367d7dd | 2014-08-29 23:56:01 | [diff] [blame] | 509 | bool can_render_to_separate_surface = |
| 510 | (layer_tree_host_impl_->GetDrawMode() != |
| 511 | DRAW_MODE_RESOURCELESS_SOFTWARE); |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 512 | |
| 513 | ++render_surface_layer_list_id_; |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 514 | LayerTreeHostCommon::CalcDrawPropsImplInputs inputs( |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 515 | root_layer(), DrawViewportSize(), |
| 516 | layer_tree_host_impl_->DrawTransform(), device_scale_factor(), |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 517 | current_page_scale_factor(), page_scale_layer, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 518 | resource_provider()->max_texture_size(), settings().can_use_lcd_text, |
| 519 | settings().layers_always_allowed_lcd_text, |
[email protected] | 4594871 | 2013-09-27 02:46:48 | [diff] [blame] | 520 | can_render_to_separate_surface, |
[email protected] | 35a99a1 | 2013-05-09 23:52:29 | [diff] [blame] | 521 | settings().layer_transforms_should_scale_layer_contents, |
danakj | 3f76ace | 2014-11-18 16:56:00 | [diff] [blame] | 522 | &render_surface_layer_list_, render_surface_layer_list_id_); |
[email protected] | 7aad55f | 2013-07-26 11:25:53 | [diff] [blame] | 523 | LayerTreeHostCommon::CalculateDrawProperties(&inputs); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 524 | } |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 525 | |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 526 | { |
vmpstr | d616620 | 2014-11-05 18:45:40 | [diff] [blame] | 527 | TRACE_EVENT_BEGIN2("cc", "LayerTreeImpl::UpdateTilePriorities", "IsActive", |
| 528 | IsActiveTree(), "SourceFrameNumber", |
| 529 | source_frame_number_); |
danakj | 6496cba | 2014-10-16 01:31:08 | [diff] [blame] | 530 | scoped_ptr<OcclusionTracker<LayerImpl>> occlusion_tracker; |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 531 | if (settings().use_occlusion_for_tile_prioritization) { |
| 532 | occlusion_tracker.reset(new OcclusionTracker<LayerImpl>( |
| 533 | root_layer()->render_surface()->content_rect())); |
| 534 | occlusion_tracker->set_minimum_tracking_size( |
| 535 | settings().minimum_occlusion_tracking_size); |
| 536 | } |
| 537 | |
boliu | 7473f7f5 | 2014-10-01 16:54:56 | [diff] [blame] | 538 | bool resourceless_software_draw = (layer_tree_host_impl_->GetDrawMode() == |
| 539 | DRAW_MODE_RESOURCELESS_SOFTWARE); |
| 540 | |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 541 | // LayerIterator is used here instead of CallFunctionForSubtree to only |
| 542 | // UpdateTilePriorities on layers that will be visible (and thus have valid |
| 543 | // draw properties) and not because any ordering is required. |
[email protected] | ba1b33e | 2014-02-28 16:44:51 | [diff] [blame] | 544 | typedef LayerIterator<LayerImpl> LayerIteratorType; |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 545 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
vmpstr | d616620 | 2014-11-05 18:45:40 | [diff] [blame] | 546 | size_t layers_updated_count = 0; |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 547 | for (LayerIteratorType it = |
| 548 | LayerIteratorType::Begin(&render_surface_layer_list_); |
| 549 | it != end; |
| 550 | ++it) { |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 551 | if (occlusion_tracker) |
| 552 | occlusion_tracker->EnterLayer(it); |
| 553 | |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 554 | LayerImpl* layer = *it; |
vmpstr | cdcb5f7 | 2014-09-11 00:58:37 | [diff] [blame] | 555 | const Occlusion& occlusion_in_content_space = |
| 556 | occlusion_tracker ? occlusion_tracker->GetCurrentOcclusionForLayer( |
| 557 | layer->draw_transform()) |
| 558 | : Occlusion(); |
| 559 | |
boliu | 7473f7f5 | 2014-10-01 16:54:56 | [diff] [blame] | 560 | if (it.represents_itself()) { |
| 561 | layer->UpdateTiles(occlusion_in_content_space, |
| 562 | resourceless_software_draw); |
vmpstr | d616620 | 2014-11-05 18:45:40 | [diff] [blame] | 563 | ++layers_updated_count; |
boliu | 7473f7f5 | 2014-10-01 16:54:56 | [diff] [blame] | 564 | } |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 565 | |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 566 | if (!it.represents_contributing_render_surface()) { |
| 567 | if (occlusion_tracker) |
| 568 | occlusion_tracker->LeaveLayer(it); |
[email protected] | 6355d2d | 2014-05-07 15:07:27 | [diff] [blame] | 569 | continue; |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 570 | } |
[email protected] | 6355d2d | 2014-05-07 15:07:27 | [diff] [blame] | 571 | |
boliu | 7473f7f5 | 2014-10-01 16:54:56 | [diff] [blame] | 572 | if (layer->mask_layer()) { |
| 573 | layer->mask_layer()->UpdateTiles(occlusion_in_content_space, |
| 574 | resourceless_software_draw); |
vmpstr | d616620 | 2014-11-05 18:45:40 | [diff] [blame] | 575 | ++layers_updated_count; |
boliu | 7473f7f5 | 2014-10-01 16:54:56 | [diff] [blame] | 576 | } |
| 577 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) { |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 578 | layer->replica_layer()->mask_layer()->UpdateTiles( |
boliu | 7473f7f5 | 2014-10-01 16:54:56 | [diff] [blame] | 579 | occlusion_in_content_space, resourceless_software_draw); |
vmpstr | d616620 | 2014-11-05 18:45:40 | [diff] [blame] | 580 | ++layers_updated_count; |
boliu | 7473f7f5 | 2014-10-01 16:54:56 | [diff] [blame] | 581 | } |
[email protected] | 562b7ad | 2014-06-23 22:17:11 | [diff] [blame] | 582 | |
| 583 | if (occlusion_tracker) |
| 584 | occlusion_tracker->LeaveLayer(it); |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 585 | } |
vmpstr | d616620 | 2014-11-05 18:45:40 | [diff] [blame] | 586 | |
| 587 | TRACE_EVENT_END1("cc", "LayerTreeImpl::UpdateTilePriorities", |
| 588 | "layers_updated_count", layers_updated_count); |
[email protected] | e4be026 | 2013-10-19 16:54:28 | [diff] [blame] | 589 | } |
| 590 | |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 591 | DCHECK(!needs_update_draw_properties_) << |
[email protected] | 7d19dc34 | 2013-05-02 22:02:04 | [diff] [blame] | 592 | "CalcDrawProperties should not set_needs_update_draw_properties()"; |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 593 | return true; |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 594 | } |
| 595 | |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 596 | const LayerImplList& LayerTreeImpl::RenderSurfaceLayerList() const { |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 597 | // If this assert triggers, then the list is dirty. |
[email protected] | 615c78a | 2013-01-24 23:44:16 | [diff] [blame] | 598 | DCHECK(!needs_update_draw_properties_); |
[email protected] | 76ffd9e | 2012-12-20 19:12:47 | [diff] [blame] | 599 | return render_surface_layer_list_; |
| 600 | } |
| 601 | |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 602 | gfx::Size LayerTreeImpl::ScrollableSize() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 603 | LayerImpl* root_scroll_layer = OuterViewportScrollLayer() |
| 604 | ? OuterViewportScrollLayer() |
| 605 | : InnerViewportScrollLayer(); |
| 606 | if (!root_scroll_layer || root_scroll_layer->children().empty()) |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 607 | return gfx::Size(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 608 | return root_scroll_layer->children()[0]->bounds(); |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 609 | } |
| 610 | |
[email protected] | 361bc00d | 2012-12-14 07:03:24 | [diff] [blame] | 611 | LayerImpl* LayerTreeImpl::LayerById(int id) { |
| 612 | LayerIdMap::iterator iter = layer_id_map_.find(id); |
| 613 | return iter != layer_id_map_.end() ? iter->second : NULL; |
| 614 | } |
| 615 | |
| 616 | void LayerTreeImpl::RegisterLayer(LayerImpl* layer) { |
| 617 | DCHECK(!LayerById(layer->id())); |
| 618 | layer_id_map_[layer->id()] = layer; |
| 619 | } |
| 620 | |
| 621 | void LayerTreeImpl::UnregisterLayer(LayerImpl* layer) { |
| 622 | DCHECK(LayerById(layer->id())); |
| 623 | layer_id_map_.erase(layer->id()); |
| 624 | } |
| 625 | |
[email protected] | aebf462 | 2014-07-14 16:57:59 | [diff] [blame] | 626 | size_t LayerTreeImpl::NumLayers() { |
| 627 | return layer_id_map_.size(); |
| 628 | } |
| 629 | |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 630 | void LayerTreeImpl::PushPersistedState(LayerTreeImpl* pending_tree) { |
[email protected] | a90fac7 | 2013-06-06 18:56:13 | [diff] [blame] | 631 | pending_tree->SetCurrentlyScrollingLayer( |
| 632 | LayerTreeHostCommon::FindLayerInSubtree(pending_tree->root_layer(), |
| 633 | currently_scrolling_layer_ ? currently_scrolling_layer_->id() : 0)); |
[email protected] | 1e0f8d6 | 2013-01-09 07:41:35 | [diff] [blame] | 634 | } |
| 635 | |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 636 | static void DidBecomeActiveRecursive(LayerImpl* layer) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 637 | layer->DidBecomeActive(); |
[email protected] | db2e29c | 2014-08-06 05:58:25 | [diff] [blame] | 638 | if (layer->mask_layer()) |
| 639 | layer->mask_layer()->DidBecomeActive(); |
| 640 | if (layer->replica_layer() && layer->replica_layer()->mask_layer()) |
| 641 | layer->replica_layer()->mask_layer()->DidBecomeActive(); |
| 642 | |
[email protected] | ff1211d | 2013-06-07 01:58:35 | [diff] [blame] | 643 | for (size_t i = 0; i < layer->children().size(); ++i) |
| 644 | DidBecomeActiveRecursive(layer->children()[i]); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 645 | } |
| 646 | |
| 647 | void LayerTreeImpl::DidBecomeActive() { |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 648 | if (next_activation_forces_redraw_) { |
| 649 | layer_tree_host_impl_->SetFullRootLayerDamage(); |
| 650 | next_activation_forces_redraw_ = false; |
| 651 | } |
| 652 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 653 | if (scrolling_layer_id_from_previous_tree_) { |
| 654 | currently_scrolling_layer_ = LayerTreeHostCommon::FindLayerInSubtree( |
[email protected] | 7dcf563 | 2014-06-25 01:11:55 | [diff] [blame] | 655 | root_layer(), scrolling_layer_id_from_previous_tree_); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 656 | } |
| 657 | |
[email protected] | 7dcf563 | 2014-06-25 01:11:55 | [diff] [blame] | 658 | // Always reset this flag on activation, as we would only have activated |
| 659 | // if we were in a good state. |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 660 | layer_tree_host_impl_->ResetRequiresHighResToDraw(); |
[email protected] | 7dcf563 | 2014-06-25 01:11:55 | [diff] [blame] | 661 | |
| 662 | if (root_layer()) |
| 663 | DidBecomeActiveRecursive(root_layer()); |
| 664 | |
[email protected] | 12a63da | 2014-06-13 06:06:22 | [diff] [blame] | 665 | devtools_instrumentation::DidActivateLayerTree(layer_tree_host_impl_->id(), |
| 666 | source_frame_number_); |
[email protected] | 37386f05 | 2013-01-13 00:42:22 | [diff] [blame] | 667 | } |
| 668 | |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 669 | bool LayerTreeImpl::ContentsTexturesPurged() const { |
| 670 | return contents_textures_purged_; |
| 671 | } |
| 672 | |
| 673 | void LayerTreeImpl::SetContentsTexturesPurged() { |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 674 | if (contents_textures_purged_) |
| 675 | return; |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 676 | contents_textures_purged_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 677 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 678 | } |
| 679 | |
| 680 | void LayerTreeImpl::ResetContentsTexturesPurged() { |
[email protected] | 94bf75c | 2013-06-12 13:20:04 | [diff] [blame] | 681 | if (!contents_textures_purged_) |
| 682 | return; |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 683 | contents_textures_purged_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 684 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 6f90b9e | 2013-01-17 23:42:00 | [diff] [blame] | 685 | } |
| 686 | |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 687 | bool LayerTreeImpl::RequiresHighResToDraw() const { |
vmpstr | 61ed94a1 | 2014-10-09 04:49:30 | [diff] [blame] | 688 | return layer_tree_host_impl_->RequiresHighResToDraw(); |
[email protected] | 3d609bb | 2014-02-01 01:10:23 | [diff] [blame] | 689 | } |
| 690 | |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 691 | bool LayerTreeImpl::ViewportSizeInvalid() const { |
| 692 | return viewport_size_invalid_; |
| 693 | } |
| 694 | |
| 695 | void LayerTreeImpl::SetViewportSizeInvalid() { |
| 696 | viewport_size_invalid_ = true; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 697 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 698 | } |
| 699 | |
| 700 | void LayerTreeImpl::ResetViewportSizeInvalid() { |
| 701 | viewport_size_invalid_ = false; |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 702 | layer_tree_host_impl_->OnCanDrawStateChangedForTree(); |
[email protected] | 31882285 | 2013-02-14 00:54:27 | [diff] [blame] | 703 | } |
| 704 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 705 | Proxy* LayerTreeImpl::proxy() const { |
| 706 | return layer_tree_host_impl_->proxy(); |
| 707 | } |
| 708 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 709 | const LayerTreeSettings& LayerTreeImpl::settings() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 710 | return layer_tree_host_impl_->settings(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 711 | } |
| 712 | |
[email protected] | 7a8bcd26 | 2014-01-15 12:54:58 | [diff] [blame] | 713 | const RendererCapabilitiesImpl& LayerTreeImpl::GetRendererCapabilities() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 714 | return layer_tree_host_impl_->GetRendererCapabilities(); |
[email protected] | bf5b3a0 | 2013-02-13 02:02:52 | [diff] [blame] | 715 | } |
| 716 | |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 717 | ContextProvider* LayerTreeImpl::context_provider() const { |
dcheng | 6afa1700 | 2014-08-26 19:11:31 | [diff] [blame] | 718 | return output_surface()->context_provider(); |
[email protected] | 0634cdd4 | 2013-08-16 00:46:09 | [diff] [blame] | 719 | } |
| 720 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 721 | OutputSurface* LayerTreeImpl::output_surface() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 722 | return layer_tree_host_impl_->output_surface(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | ResourceProvider* LayerTreeImpl::resource_provider() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 726 | return layer_tree_host_impl_->resource_provider(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | TileManager* LayerTreeImpl::tile_manager() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 730 | return layer_tree_host_impl_->tile_manager(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 731 | } |
| 732 | |
| 733 | FrameRateCounter* LayerTreeImpl::frame_rate_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 734 | return layer_tree_host_impl_->fps_counter(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 735 | } |
| 736 | |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 737 | PaintTimeCounter* LayerTreeImpl::paint_time_counter() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 738 | return layer_tree_host_impl_->paint_time_counter(); |
[email protected] | 71691c2 | 2013-01-18 03:14:22 | [diff] [blame] | 739 | } |
| 740 | |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 741 | MemoryHistory* LayerTreeImpl::memory_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 742 | return layer_tree_host_impl_->memory_history(); |
[email protected] | 1191d9d | 2013-02-02 06:00:33 | [diff] [blame] | 743 | } |
| 744 | |
[email protected] | 4a6c091d | 2014-04-24 21:06:46 | [diff] [blame] | 745 | gfx::Size LayerTreeImpl::device_viewport_size() const { |
| 746 | return layer_tree_host_impl_->device_viewport_size(); |
| 747 | } |
| 748 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 749 | bool LayerTreeImpl::IsActiveTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 750 | return layer_tree_host_impl_->active_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 751 | } |
| 752 | |
| 753 | bool LayerTreeImpl::IsPendingTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 754 | return layer_tree_host_impl_->pending_tree() == this; |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 755 | } |
| 756 | |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 757 | bool LayerTreeImpl::IsRecycleTree() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 758 | return layer_tree_host_impl_->recycle_tree() == this; |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 759 | } |
| 760 | |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 761 | LayerImpl* LayerTreeImpl::FindActiveTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 762 | LayerTreeImpl* tree = layer_tree_host_impl_->active_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 763 | if (!tree) |
| 764 | return NULL; |
| 765 | return tree->LayerById(id); |
| 766 | } |
| 767 | |
| 768 | LayerImpl* LayerTreeImpl::FindPendingTreeLayerById(int id) { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 769 | LayerTreeImpl* tree = layer_tree_host_impl_->pending_tree(); |
[email protected] | f117a4c | 2012-12-16 04:53:10 | [diff] [blame] | 770 | if (!tree) |
| 771 | return NULL; |
| 772 | return tree->LayerById(id); |
| 773 | } |
| 774 | |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 775 | bool LayerTreeImpl::PinchGestureActive() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 776 | return layer_tree_host_impl_->pinch_gesture_active(); |
[email protected] | 166db5c8 | 2013-01-09 23:54:31 | [diff] [blame] | 777 | } |
| 778 | |
[email protected] | 04c5900d | 2014-08-18 13:38:36 | [diff] [blame] | 779 | BeginFrameArgs LayerTreeImpl::CurrentBeginFrameArgs() const { |
| 780 | return layer_tree_host_impl_->CurrentBeginFrameArgs(); |
[email protected] | fb7425a | 2013-04-22 16:28:55 | [diff] [blame] | 781 | } |
| 782 | |
[email protected] | c92195e | 2014-05-07 18:18:49 | [diff] [blame] | 783 | base::TimeDelta LayerTreeImpl::begin_impl_frame_interval() const { |
| 784 | return layer_tree_host_impl_->begin_impl_frame_interval(); |
| 785 | } |
| 786 | |
[email protected] | d7eb8c7 | 2013-03-23 22:57:13 | [diff] [blame] | 787 | void LayerTreeImpl::SetNeedsCommit() { |
| 788 | layer_tree_host_impl_->SetNeedsCommit(); |
| 789 | } |
| 790 | |
[email protected] | bd532459 | 2014-07-31 09:09:33 | [diff] [blame] | 791 | gfx::Rect LayerTreeImpl::DeviceViewport() const { |
| 792 | return layer_tree_host_impl_->DeviceViewport(); |
| 793 | } |
| 794 | |
[email protected] | 54af0352 | 2013-09-05 00:43:28 | [diff] [blame] | 795 | gfx::Size LayerTreeImpl::DrawViewportSize() const { |
| 796 | return layer_tree_host_impl_->DrawViewportSize(); |
| 797 | } |
| 798 | |
[email protected] | bd532459 | 2014-07-31 09:09:33 | [diff] [blame] | 799 | const gfx::Rect LayerTreeImpl::ViewportRectForTilePriority() const { |
| 800 | return layer_tree_host_impl_->ViewportRectForTilePriority(); |
| 801 | } |
| 802 | |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 803 | scoped_ptr<ScrollbarAnimationController> |
| 804 | LayerTreeImpl::CreateScrollbarAnimationController(LayerImpl* scrolling_layer) { |
| 805 | DCHECK(settings().scrollbar_fade_delay_ms); |
| 806 | DCHECK(settings().scrollbar_fade_duration_ms); |
| 807 | base::TimeDelta delay = |
| 808 | base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_delay_ms); |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 809 | base::TimeDelta resize_delay = base::TimeDelta::FromMilliseconds( |
| 810 | settings().scrollbar_fade_resize_delay_ms); |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 811 | base::TimeDelta duration = |
| 812 | base::TimeDelta::FromMilliseconds(settings().scrollbar_fade_duration_ms); |
| 813 | switch (settings().scrollbar_animator) { |
| 814 | case LayerTreeSettings::LinearFade: { |
| 815 | return ScrollbarAnimationControllerLinearFade::Create( |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 816 | scrolling_layer, |
| 817 | layer_tree_host_impl_, |
| 818 | delay, |
| 819 | resize_delay, |
| 820 | duration); |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 821 | } |
| 822 | case LayerTreeSettings::Thinning: { |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 823 | return ScrollbarAnimationControllerThinning::Create(scrolling_layer, |
| 824 | layer_tree_host_impl_, |
| 825 | delay, |
| 826 | resize_delay, |
| 827 | duration); |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 828 | } |
| 829 | case LayerTreeSettings::NoAnimator: |
| 830 | NOTREACHED(); |
| 831 | break; |
| 832 | } |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 833 | return nullptr; |
[email protected] | 2ea5aba | 2013-09-11 14:26:56 | [diff] [blame] | 834 | } |
| 835 | |
[email protected] | b8384e2 | 2013-12-03 02:20:48 | [diff] [blame] | 836 | void LayerTreeImpl::DidAnimateScrollOffset() { |
| 837 | layer_tree_host_impl_->DidAnimateScrollOffset(); |
| 838 | } |
| 839 | |
[email protected] | 13525d6 | 2014-05-20 21:22:04 | [diff] [blame] | 840 | bool LayerTreeImpl::use_gpu_rasterization() const { |
| 841 | return layer_tree_host_impl_->use_gpu_rasterization(); |
| 842 | } |
| 843 | |
hendrikw | c2bbd61 | 2014-12-03 23:49:34 | [diff] [blame] | 844 | GpuRasterizationStatus LayerTreeImpl::GetGpuRasterizationStatus() const { |
| 845 | return layer_tree_host_impl_->gpu_rasterization_status(); |
| 846 | } |
| 847 | |
[email protected] | 473f1f2 | 2014-05-22 08:19:17 | [diff] [blame] | 848 | bool LayerTreeImpl::create_low_res_tiling() const { |
| 849 | return layer_tree_host_impl_->create_low_res_tiling(); |
| 850 | } |
| 851 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 852 | void LayerTreeImpl::SetNeedsRedraw() { |
[email protected] | 59adb11 | 2013-04-09 04:48:44 | [diff] [blame] | 853 | layer_tree_host_impl_->SetNeedsRedraw(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 854 | } |
| 855 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 856 | const LayerTreeDebugState& LayerTreeImpl::debug_state() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 857 | return layer_tree_host_impl_->debug_state(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | float LayerTreeImpl::device_scale_factor() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 861 | return layer_tree_host_impl_->device_scale_factor(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 862 | } |
| 863 | |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 864 | DebugRectHistory* LayerTreeImpl::debug_rect_history() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 865 | return layer_tree_host_impl_->debug_rect_history(); |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 866 | } |
| 867 | |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 868 | AnimationRegistrar* LayerTreeImpl::animationRegistrar() const { |
[email protected] | c1bb5af | 2013-03-13 19:06:27 | [diff] [blame] | 869 | return layer_tree_host_impl_->animation_registrar(); |
[email protected] | de4afb5e | 2012-12-20 00:11:34 | [diff] [blame] | 870 | } |
[email protected] | ff762fb | 2012-12-12 19:18:37 | [diff] [blame] | 871 | |
vmpstr | d7de03c | 2014-08-27 18:11:01 | [diff] [blame] | 872 | void LayerTreeImpl::GetAllTilesForTracing(std::set<const Tile*>* tiles) const { |
| 873 | typedef LayerIterator<LayerImpl> LayerIteratorType; |
| 874 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 875 | for (LayerIteratorType it = |
| 876 | LayerIteratorType::Begin(&render_surface_layer_list_); |
| 877 | it != end; |
| 878 | ++it) { |
| 879 | if (!it.represents_itself()) |
| 880 | continue; |
| 881 | LayerImpl* layer_impl = *it; |
| 882 | layer_impl->GetAllTilesForTracing(tiles); |
| 883 | } |
| 884 | } |
| 885 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 886 | void LayerTreeImpl::AsValueInto(base::debug::TracedValue* state) const { |
| 887 | TracedValue::MakeDictIntoImplicitSnapshot(state, "cc::LayerTreeImpl", this); |
nduca | 929378a0 | 2014-08-23 19:48:52 | [diff] [blame] | 888 | state->SetInteger("source_frame_number", source_frame_number_); |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 889 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 890 | state->BeginDictionary("root_layer"); |
| 891 | root_layer_->AsValueInto(state); |
| 892 | state->EndDictionary(); |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 893 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 894 | state->BeginArray("render_surface_layer_list"); |
[email protected] | ba1b33e | 2014-02-28 16:44:51 | [diff] [blame] | 895 | typedef LayerIterator<LayerImpl> LayerIteratorType; |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 896 | LayerIteratorType end = LayerIteratorType::End(&render_surface_layer_list_); |
| 897 | for (LayerIteratorType it = LayerIteratorType::Begin( |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 898 | &render_surface_layer_list_); it != end; ++it) { |
[email protected] | 71dfcc7 | 2013-03-20 21:30:09 | [diff] [blame] | 899 | if (!it.represents_itself()) |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 900 | continue; |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 901 | TracedValue::AppendIDRef(*it, state); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 902 | } |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 903 | state->EndArray(); |
skyostil | 43c330f7 | 2014-09-22 16:49:11 | [diff] [blame] | 904 | |
| 905 | state->BeginArray("swap_promise_trace_ids"); |
| 906 | for (size_t i = 0; i < swap_promise_list_.size(); i++) |
| 907 | state->AppendDouble(swap_promise_list_[i]->TraceId()); |
| 908 | state->EndArray(); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 909 | } |
| 910 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 911 | void LayerTreeImpl::SetRootLayerScrollOffsetDelegate( |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 912 | LayerScrollOffsetDelegate* root_layer_scroll_offset_delegate) { |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 913 | if (root_layer_scroll_offset_delegate_ == root_layer_scroll_offset_delegate) |
| 914 | return; |
| 915 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 916 | if (!root_layer_scroll_offset_delegate) { |
| 917 | // Make sure we remove the proxies from their layers before |
| 918 | // releasing them. |
| 919 | if (InnerViewportScrollLayer()) |
| 920 | InnerViewportScrollLayer()->SetScrollOffsetDelegate(NULL); |
| 921 | if (OuterViewportScrollLayer()) |
| 922 | OuterViewportScrollLayer()->SetScrollOffsetDelegate(NULL); |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 923 | inner_viewport_scroll_delegate_proxy_ = nullptr; |
| 924 | outer_viewport_scroll_delegate_proxy_ = nullptr; |
[email protected] | d35cd7b2 | 2014-01-29 14:32:46 | [diff] [blame] | 925 | } |
| 926 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 927 | root_layer_scroll_offset_delegate_ = root_layer_scroll_offset_delegate; |
| 928 | |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 929 | if (root_layer_scroll_offset_delegate_) { |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 930 | root_layer_scroll_offset_delegate_->UpdateRootLayerState( |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 931 | TotalScrollOffset(), TotalMaxScrollOffset(), ScrollableSize(), |
| 932 | current_page_scale_factor(), min_page_scale_factor(), |
[email protected] | 68fe60f | 2014-02-12 13:49:11 | [diff] [blame] | 933 | max_page_scale_factor()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 934 | |
| 935 | if (inner_viewport_scroll_layer_) { |
| 936 | inner_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 937 | new LayerScrollOffsetDelegateProxy(InnerViewportScrollLayer(), |
| 938 | root_layer_scroll_offset_delegate_, |
| 939 | this)); |
| 940 | inner_viewport_scroll_layer_->SetScrollOffsetDelegate( |
| 941 | inner_viewport_scroll_delegate_proxy_.get()); |
| 942 | } |
| 943 | |
| 944 | if (outer_viewport_scroll_layer_) { |
| 945 | outer_viewport_scroll_delegate_proxy_ = make_scoped_ptr( |
| 946 | new LayerScrollOffsetDelegateProxy(OuterViewportScrollLayer(), |
| 947 | root_layer_scroll_offset_delegate_, |
| 948 | this)); |
| 949 | outer_viewport_scroll_layer_->SetScrollOffsetDelegate( |
| 950 | outer_viewport_scroll_delegate_proxy_.get()); |
| 951 | } |
bokan | 6747f552 | 2014-10-24 19:28:54 | [diff] [blame] | 952 | |
| 953 | if (inner_viewport_scroll_layer_) |
| 954 | UpdateScrollOffsetDelegate(); |
[email protected] | 20d2b74 | 2013-09-26 05:41:34 | [diff] [blame] | 955 | } |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 956 | } |
| 957 | |
boliu | 7d5dbab | 2014-10-10 20:05:47 | [diff] [blame] | 958 | void LayerTreeImpl::OnRootLayerDelegatedScrollOffsetChanged() { |
| 959 | DCHECK(root_layer_scroll_offset_delegate_); |
| 960 | if (inner_viewport_scroll_layer_) { |
| 961 | inner_viewport_scroll_layer_->DidScroll(); |
| 962 | } |
| 963 | if (outer_viewport_scroll_layer_) { |
| 964 | outer_viewport_scroll_layer_->DidScroll(); |
| 965 | } |
| 966 | } |
| 967 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 968 | void LayerTreeImpl::UpdateScrollOffsetDelegate() { |
| 969 | DCHECK(InnerViewportScrollLayer()); |
bokan | 6747f552 | 2014-10-24 19:28:54 | [diff] [blame] | 970 | DCHECK(!OuterViewportScrollLayer() || outer_viewport_scroll_delegate_proxy_); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 971 | DCHECK(root_layer_scroll_offset_delegate_); |
| 972 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 973 | gfx::ScrollOffset offset = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 974 | inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 975 | |
| 976 | if (OuterViewportScrollLayer()) |
| 977 | offset += outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 978 | |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 979 | root_layer_scroll_offset_delegate_->UpdateRootLayerState( |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame^] | 980 | offset, TotalMaxScrollOffset(), ScrollableSize(), |
| 981 | current_page_scale_factor(), min_page_scale_factor(), |
[email protected] | ec2322e | 2014-05-15 16:32:00 | [diff] [blame] | 982 | max_page_scale_factor()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 983 | } |
| 984 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 985 | gfx::ScrollOffset LayerTreeImpl::GetDelegatedScrollOffset(LayerImpl* layer) { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 986 | DCHECK(root_layer_scroll_offset_delegate_); |
| 987 | DCHECK(InnerViewportScrollLayer()); |
| 988 | if (layer == InnerViewportScrollLayer() && !OuterViewportScrollLayer()) |
| 989 | return root_layer_scroll_offset_delegate_->GetTotalScrollOffset(); |
| 990 | |
| 991 | // If we get here, we have both inner/outer viewports, and need to distribute |
| 992 | // the scroll offset between them. |
| 993 | DCHECK(inner_viewport_scroll_delegate_proxy_); |
| 994 | DCHECK(outer_viewport_scroll_delegate_proxy_); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 995 | gfx::ScrollOffset inner_viewport_offset = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 996 | inner_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 997 | gfx::ScrollOffset outer_viewport_offset = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 998 | outer_viewport_scroll_delegate_proxy_->last_set_scroll_offset(); |
| 999 | |
| 1000 | // It may be nothing has changed. |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1001 | gfx::ScrollOffset delegate_offset = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1002 | root_layer_scroll_offset_delegate_->GetTotalScrollOffset(); |
| 1003 | if (inner_viewport_offset + outer_viewport_offset == delegate_offset) { |
| 1004 | if (layer == InnerViewportScrollLayer()) |
| 1005 | return inner_viewport_offset; |
| 1006 | else |
| 1007 | return outer_viewport_offset; |
| 1008 | } |
| 1009 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1010 | gfx::ScrollOffset max_outer_viewport_scroll_offset = |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1011 | OuterViewportScrollLayer()->MaxScrollOffset(); |
| 1012 | |
| 1013 | outer_viewport_offset = delegate_offset - inner_viewport_offset; |
| 1014 | outer_viewport_offset.SetToMin(max_outer_viewport_scroll_offset); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1015 | outer_viewport_offset.SetToMax(gfx::ScrollOffset()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1016 | |
| 1017 | if (layer == OuterViewportScrollLayer()) |
| 1018 | return outer_viewport_offset; |
| 1019 | |
| 1020 | inner_viewport_offset = delegate_offset - outer_viewport_offset; |
| 1021 | |
| 1022 | return inner_viewport_offset; |
| 1023 | } |
| 1024 | |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1025 | void LayerTreeImpl::QueueSwapPromise(scoped_ptr<SwapPromise> swap_promise) { |
| 1026 | DCHECK(swap_promise); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1027 | swap_promise_list_.push_back(swap_promise.Pass()); |
| 1028 | } |
| 1029 | |
| 1030 | void LayerTreeImpl::PassSwapPromises( |
| 1031 | ScopedPtrVector<SwapPromise>* new_swap_promise) { |
| 1032 | swap_promise_list_.insert_and_take(swap_promise_list_.end(), |
weiliangc | c1878c6 | 2014-09-02 22:43:17 | [diff] [blame] | 1033 | new_swap_promise); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1034 | new_swap_promise->clear(); |
| 1035 | } |
| 1036 | |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 1037 | void LayerTreeImpl::FinishSwapPromises(CompositorFrameMetadata* metadata) { |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1038 | for (size_t i = 0; i < swap_promise_list_.size(); i++) |
[email protected] | d359203a | 2013-11-29 06:16:55 | [diff] [blame] | 1039 | swap_promise_list_[i]->DidSwap(metadata); |
[email protected] | b69c1db | 2013-11-27 00:05:19 | [diff] [blame] | 1040 | swap_promise_list_.clear(); |
| 1041 | } |
| 1042 | |
| 1043 | void LayerTreeImpl::BreakSwapPromises(SwapPromise::DidNotSwapReason reason) { |
| 1044 | for (size_t i = 0; i < swap_promise_list_.size(); i++) |
| 1045 | swap_promise_list_[i]->DidNotSwap(reason); |
| 1046 | swap_promise_list_.clear(); |
| 1047 | } |
| 1048 | |
[email protected] | c48536a5 | 2013-09-14 00:02:08 | [diff] [blame] | 1049 | void LayerTreeImpl::DidModifyTilePriorities() { |
| 1050 | layer_tree_host_impl_->DidModifyTilePriorities(); |
[email protected] | fcb846d | 2013-05-22 01:42:36 | [diff] [blame] | 1051 | } |
| 1052 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1053 | void LayerTreeImpl::set_ui_resource_request_queue( |
| 1054 | const UIResourceRequestQueue& queue) { |
| 1055 | ui_resource_request_queue_ = queue; |
| 1056 | } |
| 1057 | |
| 1058 | ResourceProvider::ResourceId LayerTreeImpl::ResourceIdForUIResource( |
| 1059 | UIResourceId uid) const { |
| 1060 | return layer_tree_host_impl_->ResourceIdForUIResource(uid); |
| 1061 | } |
| 1062 | |
[email protected] | 709c954 | 2013-10-26 01:43:51 | [diff] [blame] | 1063 | bool LayerTreeImpl::IsUIResourceOpaque(UIResourceId uid) const { |
| 1064 | return layer_tree_host_impl_->IsUIResourceOpaque(uid); |
| 1065 | } |
| 1066 | |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1067 | void LayerTreeImpl::ProcessUIResourceRequestQueue() { |
| 1068 | while (ui_resource_request_queue_.size() > 0) { |
| 1069 | UIResourceRequest req = ui_resource_request_queue_.front(); |
| 1070 | ui_resource_request_queue_.pop_front(); |
| 1071 | |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 1072 | switch (req.GetType()) { |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1073 | case UIResourceRequest::UIResourceCreate: |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 1074 | layer_tree_host_impl_->CreateUIResource(req.GetId(), req.GetBitmap()); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1075 | break; |
| 1076 | case UIResourceRequest::UIResourceDelete: |
[email protected] | 741fba42 | 2013-09-20 03:34:14 | [diff] [blame] | 1077 | layer_tree_host_impl_->DeleteUIResource(req.GetId()); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1078 | break; |
[email protected] | f28d64d | 2013-08-27 04:17:45 | [diff] [blame] | 1079 | case UIResourceRequest::UIResourceInvalidRequest: |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1080 | NOTREACHED(); |
| 1081 | break; |
| 1082 | } |
| 1083 | } |
[email protected] | 127bdc1a | 2013-09-11 01:44:48 | [diff] [blame] | 1084 | |
| 1085 | // If all UI resource evictions were not recreated by processing this queue, |
| 1086 | // then another commit is required. |
| 1087 | if (layer_tree_host_impl_->EvictedUIResourcesExist()) |
| 1088 | layer_tree_host_impl_->SetNeedsCommit(); |
[email protected] | c928076 | 2013-08-01 06:28:57 | [diff] [blame] | 1089 | } |
| 1090 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1091 | void LayerTreeImpl::AddLayerWithCopyOutputRequest(LayerImpl* layer) { |
| 1092 | // Only the active tree needs to know about layers with copy requests, as |
| 1093 | // they are aborted if not serviced during draw. |
| 1094 | DCHECK(IsActiveTree()); |
| 1095 | |
[email protected] | a4ee1281 | 2014-02-06 17:33:38 | [diff] [blame] | 1096 | // DCHECK(std::find(layers_with_copy_output_request_.begin(), |
| 1097 | // layers_with_copy_output_request_.end(), |
| 1098 | // layer) == layers_with_copy_output_request_.end()); |
| 1099 | // TODO(danakj): Remove this once crash is found crbug.com/309777 |
| 1100 | for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) { |
| 1101 | CHECK(layers_with_copy_output_request_[i] != layer) |
| 1102 | << i << " of " << layers_with_copy_output_request_.size(); |
| 1103 | } |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1104 | layers_with_copy_output_request_.push_back(layer); |
| 1105 | } |
| 1106 | |
| 1107 | void LayerTreeImpl::RemoveLayerWithCopyOutputRequest(LayerImpl* layer) { |
| 1108 | // Only the active tree needs to know about layers with copy requests, as |
| 1109 | // they are aborted if not serviced during draw. |
| 1110 | DCHECK(IsActiveTree()); |
| 1111 | |
| 1112 | std::vector<LayerImpl*>::iterator it = std::find( |
| 1113 | layers_with_copy_output_request_.begin(), |
| 1114 | layers_with_copy_output_request_.end(), |
| 1115 | layer); |
| 1116 | DCHECK(it != layers_with_copy_output_request_.end()); |
[email protected] | f5de9e5b | 2013-07-30 22:26:57 | [diff] [blame] | 1117 | layers_with_copy_output_request_.erase(it); |
[email protected] | a4ee1281 | 2014-02-06 17:33:38 | [diff] [blame] | 1118 | |
| 1119 | // TODO(danakj): Remove this once crash is found crbug.com/309777 |
| 1120 | for (size_t i = 0; i < layers_with_copy_output_request_.size(); ++i) { |
| 1121 | CHECK(layers_with_copy_output_request_[i] != layer) |
| 1122 | << i << " of " << layers_with_copy_output_request_.size(); |
| 1123 | } |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1124 | } |
| 1125 | |
[email protected] | 5352637 | 2013-12-07 04:31:50 | [diff] [blame] | 1126 | const std::vector<LayerImpl*>& LayerTreeImpl::LayersWithCopyOutputRequest() |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 1127 | const { |
| 1128 | // Only the active tree needs to know about layers with copy requests, as |
| 1129 | // they are aborted if not serviced during draw. |
| 1130 | DCHECK(IsActiveTree()); |
| 1131 | |
| 1132 | return layers_with_copy_output_request_; |
| 1133 | } |
| 1134 | |
[email protected] | aeef2f0 | 2014-05-10 12:15:48 | [diff] [blame] | 1135 | void LayerTreeImpl::ReleaseResourcesRecursive(LayerImpl* current) { |
| 1136 | DCHECK(current); |
| 1137 | current->ReleaseResources(); |
| 1138 | if (current->mask_layer()) |
| 1139 | ReleaseResourcesRecursive(current->mask_layer()); |
| 1140 | if (current->replica_layer()) |
| 1141 | ReleaseResourcesRecursive(current->replica_layer()); |
| 1142 | for (size_t i = 0; i < current->children().size(); ++i) |
| 1143 | ReleaseResourcesRecursive(current->children()[i]); |
| 1144 | } |
| 1145 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1146 | template <typename LayerType> |
| 1147 | static inline bool LayerClipsSubtree(LayerType* layer) { |
| 1148 | return layer->masks_to_bounds() || layer->mask_layer(); |
| 1149 | } |
| 1150 | |
| 1151 | static bool PointHitsRect( |
| 1152 | const gfx::PointF& screen_space_point, |
| 1153 | const gfx::Transform& local_space_to_screen_space_transform, |
| 1154 | const gfx::RectF& local_space_rect, |
| 1155 | float* distance_to_camera) { |
| 1156 | // If the transform is not invertible, then assume that this point doesn't hit |
| 1157 | // this rect. |
| 1158 | gfx::Transform inverse_local_space_to_screen_space( |
| 1159 | gfx::Transform::kSkipInitialization); |
| 1160 | if (!local_space_to_screen_space_transform.GetInverse( |
| 1161 | &inverse_local_space_to_screen_space)) |
| 1162 | return false; |
| 1163 | |
| 1164 | // Transform the hit test point from screen space to the local space of the |
| 1165 | // given rect. |
| 1166 | bool clipped = false; |
| 1167 | gfx::Point3F planar_point = MathUtil::ProjectPoint3D( |
| 1168 | inverse_local_space_to_screen_space, screen_space_point, &clipped); |
| 1169 | gfx::PointF hit_test_point_in_local_space = |
| 1170 | gfx::PointF(planar_point.x(), planar_point.y()); |
| 1171 | |
| 1172 | // If ProjectPoint could not project to a valid value, then we assume that |
| 1173 | // this point doesn't hit this rect. |
| 1174 | if (clipped) |
| 1175 | return false; |
| 1176 | |
| 1177 | if (!local_space_rect.Contains(hit_test_point_in_local_space)) |
| 1178 | return false; |
| 1179 | |
| 1180 | if (distance_to_camera) { |
| 1181 | // To compute the distance to the camera, we have to take the planar point |
| 1182 | // and pull it back to world space and compute the displacement along the |
| 1183 | // z-axis. |
| 1184 | gfx::Point3F planar_point_in_screen_space(planar_point); |
| 1185 | local_space_to_screen_space_transform.TransformPoint( |
| 1186 | &planar_point_in_screen_space); |
| 1187 | *distance_to_camera = planar_point_in_screen_space.z(); |
| 1188 | } |
| 1189 | |
| 1190 | return true; |
| 1191 | } |
| 1192 | |
| 1193 | static bool PointHitsRegion(const gfx::PointF& screen_space_point, |
| 1194 | const gfx::Transform& screen_space_transform, |
| 1195 | const Region& layer_space_region, |
| 1196 | float layer_content_scale_x, |
| 1197 | float layer_content_scale_y) { |
| 1198 | // If the transform is not invertible, then assume that this point doesn't hit |
| 1199 | // this region. |
| 1200 | gfx::Transform inverse_screen_space_transform( |
| 1201 | gfx::Transform::kSkipInitialization); |
| 1202 | if (!screen_space_transform.GetInverse(&inverse_screen_space_transform)) |
| 1203 | return false; |
| 1204 | |
| 1205 | // Transform the hit test point from screen space to the local space of the |
| 1206 | // given region. |
| 1207 | bool clipped = false; |
| 1208 | gfx::PointF hit_test_point_in_content_space = MathUtil::ProjectPoint( |
| 1209 | inverse_screen_space_transform, screen_space_point, &clipped); |
| 1210 | gfx::PointF hit_test_point_in_layer_space = |
| 1211 | gfx::ScalePoint(hit_test_point_in_content_space, |
| 1212 | 1.f / layer_content_scale_x, |
| 1213 | 1.f / layer_content_scale_y); |
| 1214 | |
| 1215 | // If ProjectPoint could not project to a valid value, then we assume that |
| 1216 | // this point doesn't hit this region. |
| 1217 | if (clipped) |
| 1218 | return false; |
| 1219 | |
| 1220 | return layer_space_region.Contains( |
| 1221 | gfx::ToRoundedPoint(hit_test_point_in_layer_space)); |
| 1222 | } |
| 1223 | |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1224 | static const LayerImpl* GetNextClippingLayer(const LayerImpl* layer) { |
[email protected] | 0ec86f5 | 2014-06-12 20:54:03 | [diff] [blame] | 1225 | if (layer->scroll_parent()) |
| 1226 | return layer->scroll_parent(); |
| 1227 | if (layer->clip_parent()) |
| 1228 | return layer->clip_parent(); |
| 1229 | return layer->parent(); |
| 1230 | } |
| 1231 | |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1232 | static bool PointIsClippedBySurfaceOrClipRect( |
| 1233 | const gfx::PointF& screen_space_point, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1234 | const LayerImpl* layer) { |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1235 | // Walk up the layer tree and hit-test any render_surfaces and any layer |
| 1236 | // clip rects that are active. |
[email protected] | 0ec86f5 | 2014-06-12 20:54:03 | [diff] [blame] | 1237 | for (; layer; layer = GetNextClippingLayer(layer)) { |
| 1238 | if (layer->render_surface() && |
| 1239 | !PointHitsRect(screen_space_point, |
| 1240 | layer->render_surface()->screen_space_transform(), |
| 1241 | layer->render_surface()->content_rect(), |
| 1242 | NULL)) |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1243 | return true; |
| 1244 | |
[email protected] | 0ec86f5 | 2014-06-12 20:54:03 | [diff] [blame] | 1245 | if (LayerClipsSubtree(layer) && |
| 1246 | !PointHitsRect(screen_space_point, |
| 1247 | layer->screen_space_transform(), |
| 1248 | gfx::Rect(layer->content_bounds()), |
| 1249 | NULL)) |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1250 | return true; |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1251 | } |
| 1252 | |
| 1253 | // If we have finished walking all ancestors without having already exited, |
| 1254 | // then the point is not clipped by any ancestors. |
| 1255 | return false; |
| 1256 | } |
| 1257 | |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1258 | static bool PointHitsLayer(const LayerImpl* layer, |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1259 | const gfx::PointF& screen_space_point, |
| 1260 | float* distance_to_intersection) { |
| 1261 | gfx::RectF content_rect(layer->content_bounds()); |
| 1262 | if (!PointHitsRect(screen_space_point, |
| 1263 | layer->screen_space_transform(), |
| 1264 | content_rect, |
| 1265 | distance_to_intersection)) |
| 1266 | return false; |
| 1267 | |
| 1268 | // At this point, we think the point does hit the layer, but we need to walk |
| 1269 | // up the parents to ensure that the layer was not clipped in such a way |
| 1270 | // that the hit point actually should not hit the layer. |
| 1271 | if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer)) |
| 1272 | return false; |
| 1273 | |
| 1274 | // Skip the HUD layer. |
| 1275 | if (layer == layer->layer_tree_impl()->hud_layer()) |
| 1276 | return false; |
| 1277 | |
| 1278 | return true; |
| 1279 | } |
| 1280 | |
| 1281 | struct FindClosestMatchingLayerDataForRecursion { |
| 1282 | FindClosestMatchingLayerDataForRecursion() |
| 1283 | : closest_match(NULL), |
| 1284 | closest_distance(-std::numeric_limits<float>::infinity()) {} |
| 1285 | LayerImpl* closest_match; |
| 1286 | // Note that the positive z-axis points towards the camera, so bigger means |
| 1287 | // closer in this case, counterintuitively. |
| 1288 | float closest_distance; |
| 1289 | }; |
| 1290 | |
| 1291 | template <typename Functor> |
| 1292 | static void FindClosestMatchingLayer( |
| 1293 | const gfx::PointF& screen_space_point, |
| 1294 | LayerImpl* layer, |
| 1295 | const Functor& func, |
| 1296 | FindClosestMatchingLayerDataForRecursion* data_for_recursion) { |
| 1297 | for (int i = layer->children().size() - 1; i >= 0; --i) { |
| 1298 | FindClosestMatchingLayer( |
| 1299 | screen_space_point, layer->children()[i], func, data_for_recursion); |
| 1300 | } |
| 1301 | |
| 1302 | float distance_to_intersection = 0.f; |
| 1303 | if (func(layer) && |
| 1304 | PointHitsLayer(layer, screen_space_point, &distance_to_intersection) && |
| 1305 | ((!data_for_recursion->closest_match || |
| 1306 | distance_to_intersection > data_for_recursion->closest_distance))) { |
| 1307 | data_for_recursion->closest_distance = distance_to_intersection; |
| 1308 | data_for_recursion->closest_match = layer; |
| 1309 | } |
| 1310 | } |
| 1311 | |
| 1312 | static bool ScrollsAnyDrawnRenderSurfaceLayerListMember(LayerImpl* layer) { |
| 1313 | if (!layer->scrollable()) |
| 1314 | return false; |
| 1315 | if (layer->IsDrawnRenderSurfaceLayerListMember()) |
| 1316 | return true; |
| 1317 | if (!layer->scroll_children()) |
| 1318 | return false; |
| 1319 | for (std::set<LayerImpl*>::const_iterator it = |
| 1320 | layer->scroll_children()->begin(); |
| 1321 | it != layer->scroll_children()->end(); |
| 1322 | ++it) { |
| 1323 | if ((*it)->IsDrawnRenderSurfaceLayerListMember()) |
| 1324 | return true; |
| 1325 | } |
| 1326 | return false; |
| 1327 | } |
| 1328 | |
| 1329 | struct FindScrollingLayerFunctor { |
| 1330 | bool operator()(LayerImpl* layer) const { |
| 1331 | return ScrollsAnyDrawnRenderSurfaceLayerListMember(layer); |
| 1332 | } |
| 1333 | }; |
| 1334 | |
| 1335 | LayerImpl* LayerTreeImpl::FindFirstScrollingLayerThatIsHitByPoint( |
| 1336 | const gfx::PointF& screen_space_point) { |
| 1337 | FindClosestMatchingLayerDataForRecursion data_for_recursion; |
| 1338 | FindClosestMatchingLayer(screen_space_point, |
| 1339 | root_layer(), |
| 1340 | FindScrollingLayerFunctor(), |
| 1341 | &data_for_recursion); |
| 1342 | return data_for_recursion.closest_match; |
| 1343 | } |
| 1344 | |
| 1345 | struct HitTestVisibleScrollableOrTouchableFunctor { |
| 1346 | bool operator()(LayerImpl* layer) const { |
| 1347 | return layer->IsDrawnRenderSurfaceLayerListMember() || |
| 1348 | ScrollsAnyDrawnRenderSurfaceLayerListMember(layer) || |
| 1349 | !layer->touch_event_handler_region().IsEmpty() || |
| 1350 | layer->have_wheel_event_handlers(); |
| 1351 | } |
| 1352 | }; |
| 1353 | |
| 1354 | LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPoint( |
| 1355 | const gfx::PointF& screen_space_point) { |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 1356 | if (!root_layer()) |
| 1357 | return NULL; |
| 1358 | if (!UpdateDrawProperties()) |
| 1359 | return NULL; |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1360 | FindClosestMatchingLayerDataForRecursion data_for_recursion; |
| 1361 | FindClosestMatchingLayer(screen_space_point, |
| 1362 | root_layer(), |
| 1363 | HitTestVisibleScrollableOrTouchableFunctor(), |
| 1364 | &data_for_recursion); |
| 1365 | return data_for_recursion.closest_match; |
| 1366 | } |
| 1367 | |
| 1368 | static bool LayerHasTouchEventHandlersAt(const gfx::PointF& screen_space_point, |
| 1369 | LayerImpl* layer_impl) { |
| 1370 | if (layer_impl->touch_event_handler_region().IsEmpty()) |
| 1371 | return false; |
| 1372 | |
| 1373 | if (!PointHitsRegion(screen_space_point, |
| 1374 | layer_impl->screen_space_transform(), |
| 1375 | layer_impl->touch_event_handler_region(), |
| 1376 | layer_impl->contents_scale_x(), |
| 1377 | layer_impl->contents_scale_y())) |
| 1378 | return false; |
| 1379 | |
| 1380 | // At this point, we think the point does hit the touch event handler region |
| 1381 | // on the layer, but we need to walk up the parents to ensure that the layer |
| 1382 | // was not clipped in such a way that the hit point actually should not hit |
| 1383 | // the layer. |
| 1384 | if (PointIsClippedBySurfaceOrClipRect(screen_space_point, layer_impl)) |
| 1385 | return false; |
| 1386 | |
| 1387 | return true; |
| 1388 | } |
| 1389 | |
| 1390 | struct FindTouchEventLayerFunctor { |
| 1391 | bool operator()(LayerImpl* layer) const { |
| 1392 | return LayerHasTouchEventHandlersAt(screen_space_point, layer); |
| 1393 | } |
| 1394 | const gfx::PointF screen_space_point; |
| 1395 | }; |
| 1396 | |
| 1397 | LayerImpl* LayerTreeImpl::FindLayerThatIsHitByPointInTouchHandlerRegion( |
| 1398 | const gfx::PointF& screen_space_point) { |
[email protected] | 8f7f29882 | 2014-06-13 00:23:32 | [diff] [blame] | 1399 | if (!root_layer()) |
| 1400 | return NULL; |
| 1401 | if (!UpdateDrawProperties()) |
| 1402 | return NULL; |
[email protected] | 28336d5 | 2014-05-12 19:07:28 | [diff] [blame] | 1403 | FindTouchEventLayerFunctor func = {screen_space_point}; |
| 1404 | FindClosestMatchingLayerDataForRecursion data_for_recursion; |
| 1405 | FindClosestMatchingLayer( |
| 1406 | screen_space_point, root_layer(), func, &data_for_recursion); |
| 1407 | return data_for_recursion.closest_match; |
| 1408 | } |
| 1409 | |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 1410 | void LayerTreeImpl::RegisterSelection(const LayerSelectionBound& start, |
| 1411 | const LayerSelectionBound& end) { |
| 1412 | selection_start_ = start; |
| 1413 | selection_end_ = end; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1414 | } |
| 1415 | |
| 1416 | static ViewportSelectionBound ComputeViewportSelection( |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1417 | const LayerSelectionBound& layer_bound, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1418 | LayerImpl* layer, |
| 1419 | float device_scale_factor) { |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1420 | ViewportSelectionBound viewport_bound; |
| 1421 | viewport_bound.type = layer_bound.type; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1422 | |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1423 | if (!layer || layer_bound.type == SELECTION_BOUND_EMPTY) |
| 1424 | return viewport_bound; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1425 | |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1426 | gfx::PointF layer_scaled_top = gfx::ScalePoint(layer_bound.edge_top, |
| 1427 | layer->contents_scale_x(), |
| 1428 | layer->contents_scale_y()); |
| 1429 | gfx::PointF layer_scaled_bottom = gfx::ScalePoint(layer_bound.edge_bottom, |
| 1430 | layer->contents_scale_x(), |
| 1431 | layer->contents_scale_y()); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1432 | |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1433 | bool clipped = false; |
| 1434 | gfx::PointF screen_top = MathUtil::MapPoint( |
| 1435 | layer->screen_space_transform(), layer_scaled_top, &clipped); |
| 1436 | gfx::PointF screen_bottom = MathUtil::MapPoint( |
| 1437 | layer->screen_space_transform(), layer_scaled_bottom, &clipped); |
| 1438 | |
| 1439 | const float inv_scale = 1.f / device_scale_factor; |
| 1440 | viewport_bound.edge_top = gfx::ScalePoint(screen_top, inv_scale); |
| 1441 | viewport_bound.edge_bottom = gfx::ScalePoint(screen_bottom, inv_scale); |
| 1442 | |
| 1443 | // The bottom edge point is used for visibility testing as it is the logical |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1444 | // focal point for bound selection handles (this may change in the future). |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1445 | // Shifting the visibility point fractionally inward ensures that neighboring |
| 1446 | // or logically coincident layers aligned to integral DPI coordinates will not |
| 1447 | // spuriously occlude the bound. |
| 1448 | gfx::Vector2dF visibility_offset = layer_scaled_top - layer_scaled_bottom; |
| 1449 | visibility_offset.Scale(device_scale_factor / visibility_offset.Length()); |
| 1450 | gfx::PointF visibility_point = layer_scaled_bottom + visibility_offset; |
| 1451 | if (visibility_point.x() <= 0) |
| 1452 | visibility_point.set_x(visibility_point.x() + device_scale_factor); |
| 1453 | visibility_point = MathUtil::MapPoint( |
| 1454 | layer->screen_space_transform(), visibility_point, &clipped); |
| 1455 | |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1456 | float intersect_distance = 0.f; |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1457 | viewport_bound.visible = |
| 1458 | PointHitsLayer(layer, visibility_point, &intersect_distance); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1459 | |
[email protected] | 6ef94873 | 2014-08-22 18:57:44 | [diff] [blame] | 1460 | return viewport_bound; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1461 | } |
| 1462 | |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 1463 | void LayerTreeImpl::GetViewportSelection(ViewportSelectionBound* start, |
| 1464 | ViewportSelectionBound* end) { |
| 1465 | DCHECK(start); |
| 1466 | DCHECK(end); |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1467 | |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 1468 | *start = ComputeViewportSelection( |
| 1469 | selection_start_, |
| 1470 | selection_start_.layer_id ? LayerById(selection_start_.layer_id) : NULL, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1471 | device_scale_factor()); |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 1472 | if (start->type == SELECTION_BOUND_CENTER || |
| 1473 | start->type == SELECTION_BOUND_EMPTY) { |
| 1474 | *end = *start; |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1475 | } else { |
[email protected] | ebb179b | 2014-07-16 17:54:41 | [diff] [blame] | 1476 | *end = ComputeViewportSelection( |
| 1477 | selection_end_, |
| 1478 | selection_end_.layer_id ? LayerById(selection_end_.layer_id) : NULL, |
[email protected] | 19aec37 | 2014-07-01 19:08:49 | [diff] [blame] | 1479 | device_scale_factor()); |
| 1480 | } |
| 1481 | } |
| 1482 | |
[email protected] | 8aa39ecb | 2014-06-12 14:19:14 | [diff] [blame] | 1483 | void LayerTreeImpl::RegisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 1484 | layer_tree_host_impl_->RegisterPictureLayerImpl(layer); |
| 1485 | } |
| 1486 | |
| 1487 | void LayerTreeImpl::UnregisterPictureLayerImpl(PictureLayerImpl* layer) { |
| 1488 | layer_tree_host_impl_->UnregisterPictureLayerImpl(layer); |
| 1489 | } |
| 1490 | |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 1491 | void LayerTreeImpl::InputScrollAnimationFinished() { |
| 1492 | layer_tree_host_impl_->ScrollEnd(); |
| 1493 | } |
| 1494 | |
vmpstr | 56ace23 | 2014-10-09 20:16:28 | [diff] [blame] | 1495 | bool LayerTreeImpl::SmoothnessTakesPriority() const { |
| 1496 | return layer_tree_host_impl_->GetTreePriority() == SMOOTHNESS_TAKES_PRIORITY; |
| 1497 | } |
| 1498 | |
skyostil | 3976a3f | 2014-09-04 22:07:23 | [diff] [blame] | 1499 | BlockingTaskRunner* LayerTreeImpl::BlockingMainThreadTaskRunner() const { |
| 1500 | return proxy()->blocking_main_thread_task_runner(); |
| 1501 | } |
| 1502 | |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 1503 | void LayerTreeImpl::SetPendingPageScaleAnimation( |
| 1504 | scoped_ptr<PendingPageScaleAnimation> pending_animation) { |
| 1505 | pending_page_scale_animation_ = pending_animation.Pass(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 1506 | } |
| 1507 | |
bokan | fcdbc18 | 2014-11-21 21:53:33 | [diff] [blame] | 1508 | scoped_ptr<PendingPageScaleAnimation> |
| 1509 | LayerTreeImpl::TakePendingPageScaleAnimation() { |
| 1510 | return pending_page_scale_animation_.Pass(); |
bokan | 915bf35 | 2014-10-02 21:57:14 | [diff] [blame] | 1511 | } |
| 1512 | |
[email protected] | ca2902e9 | 2013-03-28 01:45:35 | [diff] [blame] | 1513 | } // namespace cc |