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