[email protected] | 5e5648a | 2013-11-18 00:39:33 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors. All rights reserved. |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 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] | cc3cfaa | 2013-03-18 09:05:52 | [diff] [blame] | 5 | #include "cc/layers/layer_impl.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 6 | |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 7 | #include "base/json/json_reader.h" |
vmpstr | 91e2309 | 2015-06-08 22:24:16 | [diff] [blame] | 8 | #include "base/numerics/safe_conversions.h" |
[email protected] | 8e61d4b | 2013-06-10 22:11:48 | [diff] [blame] | 9 | #include "base/strings/stringprintf.h" |
primiano | c06e238 | 2015-01-28 04:21:49 | [diff] [blame] | 10 | #include "base/trace_event/trace_event.h" |
| 11 | #include "base/trace_event/trace_event_argument.h" |
[email protected] | 95e4e1a0 | 2013-03-18 07:09:09 | [diff] [blame] | 12 | #include "cc/animation/animation_registrar.h" |
| 13 | #include "cc/animation/scrollbar_animation_controller.h" |
[email protected] | 681ccff | 2013-03-18 06:13:52 | [diff] [blame] | 14 | #include "cc/base/math_util.h" |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 15 | #include "cc/base/simple_enclosed_region.h" |
[email protected] | 6e84de2 | 2013-03-18 06:54:27 | [diff] [blame] | 16 | #include "cc/debug/debug_colors.h" |
| 17 | #include "cc/debug/layer_tree_debug_state.h" |
[email protected] | 5e5648a | 2013-11-18 00:39:33 | [diff] [blame] | 18 | #include "cc/debug/micro_benchmark_impl.h" |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 19 | #include "cc/debug/traced_value.h" |
[email protected] | 3d86dd7a | 2014-01-24 01:33:11 | [diff] [blame] | 20 | #include "cc/layers/layer_utils.h" |
[email protected] | 3a83478b | 2013-08-22 20:55:17 | [diff] [blame] | 21 | #include "cc/layers/painted_scrollbar_layer_impl.h" |
[email protected] | 0e5f714 | 2013-05-24 06:45:36 | [diff] [blame] | 22 | #include "cc/output/copy_output_request.h" |
[email protected] | 89e8267a | 2013-03-18 07:50:56 | [diff] [blame] | 23 | #include "cc/quads/debug_border_draw_quad.h" |
[email protected] | 0cd7d6f7 | 2014-08-22 14:50:51 | [diff] [blame] | 24 | #include "cc/quads/render_pass.h" |
[email protected] | 3d86dd7a | 2014-01-24 01:33:11 | [diff] [blame] | 25 | #include "cc/trees/layer_tree_host_common.h" |
[email protected] | 556fd29 | 2013-03-18 08:03:04 | [diff] [blame] | 26 | #include "cc/trees/layer_tree_impl.h" |
| 27 | #include "cc/trees/layer_tree_settings.h" |
| 28 | #include "cc/trees/proxy.h" |
heejin.r.chung | d28506ba | 2014-10-23 16:36:20 | [diff] [blame] | 29 | #include "ui/gfx/geometry/box_f.h" |
| 30 | #include "ui/gfx/geometry/point_conversions.h" |
| 31 | #include "ui/gfx/geometry/quad_f.h" |
| 32 | #include "ui/gfx/geometry/rect_conversions.h" |
| 33 | #include "ui/gfx/geometry/size_conversions.h" |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 34 | #include "ui/gfx/geometry/vector2d_conversions.h" |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 35 | |
[email protected] | 9c88e56 | 2012-09-14 22:21:30 | [diff] [blame] | 36 | namespace cc { |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 37 | LayerImpl::LayerImpl(LayerTreeImpl* layer_impl, int id) |
| 38 | : LayerImpl(layer_impl, id, new LayerImpl::SyncedScrollOffset) { |
| 39 | } |
| 40 | |
| 41 | LayerImpl::LayerImpl(LayerTreeImpl* tree_impl, |
| 42 | int id, |
| 43 | scoped_refptr<SyncedScrollOffset> scroll_offset) |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 44 | : parent_(nullptr), |
| 45 | scroll_parent_(nullptr), |
| 46 | clip_parent_(nullptr), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 47 | mask_layer_id_(-1), |
| 48 | replica_layer_id_(-1), |
| 49 | layer_id_(id), |
| 50 | layer_tree_impl_(tree_impl), |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 51 | scroll_offset_(scroll_offset), |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 52 | scroll_clip_layer_(nullptr), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 53 | should_scroll_on_main_thread_(false), |
| 54 | have_wheel_event_handlers_(false), |
[email protected] | f998c53 | 2014-03-31 20:02:51 | [diff] [blame] | 55 | have_scroll_event_handlers_(false), |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 56 | scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE), |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 57 | user_scrollable_horizontal_(true), |
| 58 | user_scrollable_vertical_(true), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 59 | stacking_order_changed_(false), |
| 60 | double_sided_(true), |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 61 | should_flatten_transform_(true), |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 62 | should_flatten_transform_from_property_tree_(false), |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 63 | is_clipped_(false), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 64 | layer_property_changed_(false), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 65 | masks_to_bounds_(false), |
| 66 | contents_opaque_(false), |
[email protected] | 7bbeaf4e | 2013-11-26 10:27:22 | [diff] [blame] | 67 | is_root_for_isolated_group_(false), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 68 | use_parent_backface_visibility_(false), |
| 69 | draw_checkerboard_for_missing_tiles_(false), |
| 70 | draws_content_(false), |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 71 | hide_layer_and_subtree_(false), |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 72 | transform_is_invertible_(true), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 73 | is_container_for_fixed_position_layers_(false), |
enne | 9c48d4f1 | 2015-06-30 00:31:15 | [diff] [blame] | 74 | is_affected_by_page_scale_(true), |
[email protected] | c55f3fc | 2013-12-10 05:48:48 | [diff] [blame] | 75 | background_color_(0), |
| 76 | opacity_(1.0), |
| 77 | blend_mode_(SkXfermode::kSrcOver_Mode), |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 78 | num_descendants_that_draw_content_(0), |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 79 | transform_tree_index_(-1), |
| 80 | opacity_tree_index_(-1), |
| 81 | clip_tree_index_(-1), |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 82 | draw_depth_(0.f), |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 83 | needs_push_properties_(false), |
| 84 | num_dependents_need_push_properties_(0), |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 85 | sorting_context_id_(0), |
vmpstr | 3d1d72c | 2015-01-26 18:27:40 | [diff] [blame] | 86 | current_draw_mode_(DRAW_MODE_NONE), |
jaydasika | 976cd10b | 2015-05-26 15:45:24 | [diff] [blame] | 87 | frame_timing_requests_dirty_(false), |
| 88 | visited_(false), |
| 89 | layer_or_descendant_is_drawn_(false), |
| 90 | sorted_for_recursion_(false) { |
[email protected] | bf691c2 | 2013-03-26 21:15:06 | [diff] [blame] | 91 | DCHECK_GT(layer_id_, 0); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 92 | DCHECK(layer_tree_impl_); |
| 93 | layer_tree_impl_->RegisterLayer(this); |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 94 | |
| 95 | if (!layer_tree_impl_->settings().use_compositor_animation_timelines) { |
| 96 | AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar(); |
| 97 | layer_animation_controller_ = |
| 98 | registrar->GetAnimationControllerForId(layer_id_); |
| 99 | layer_animation_controller_->AddValueObserver(this); |
| 100 | if (IsActive()) { |
| 101 | layer_animation_controller_->set_value_provider(this); |
| 102 | layer_animation_controller_->set_layer_animation_delegate(this); |
| 103 | } |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 104 | } |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 105 | SetNeedsPushProperties(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 106 | } |
| 107 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 108 | LayerImpl::~LayerImpl() { |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 109 | DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_); |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 110 | |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 111 | if (layer_animation_controller_) { |
| 112 | layer_animation_controller_->RemoveValueObserver(this); |
| 113 | layer_animation_controller_->remove_value_provider(this); |
| 114 | layer_animation_controller_->remove_layer_animation_delegate(this); |
| 115 | } |
[email protected] | b8384e2 | 2013-12-03 02:20:48 | [diff] [blame] | 116 | |
[email protected] | 19334ac | 2013-12-12 23:59:11 | [diff] [blame] | 117 | if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree()) |
| 118 | layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); |
[email protected] | b8384e2 | 2013-12-03 02:20:48 | [diff] [blame] | 119 | layer_tree_impl_->UnregisterLayer(this); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 120 | |
[email protected] | f5ad428 | 2014-02-15 14:23:16 | [diff] [blame] | 121 | TRACE_EVENT_OBJECT_DELETED_WITH_ID( |
[email protected] | b4dc3647 | 2014-02-26 02:48:25 | [diff] [blame] | 122 | TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 123 | } |
| 124 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 125 | void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) { |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 126 | child->SetParent(this); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 127 | DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl()); |
| 128 | children_.push_back(child.Pass()); |
| 129 | layer_tree_impl()->set_needs_update_draw_properties(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 130 | } |
| 131 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 132 | scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) { |
[email protected] | 50761e9 | 2013-03-29 20:51:28 | [diff] [blame] | 133 | for (OwnedLayerImplList::iterator it = children_.begin(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 134 | it != children_.end(); |
| 135 | ++it) { |
| 136 | if (*it == child) { |
| 137 | scoped_ptr<LayerImpl> ret = children_.take(it); |
| 138 | children_.erase(it); |
| 139 | layer_tree_impl()->set_needs_update_draw_properties(); |
| 140 | return ret.Pass(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 141 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 142 | } |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 143 | return nullptr; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 144 | } |
| 145 | |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 146 | void LayerImpl::SetParent(LayerImpl* parent) { |
| 147 | if (parent_should_know_need_push_properties()) { |
| 148 | if (parent_) |
| 149 | parent_->RemoveDependentNeedsPushProperties(); |
| 150 | if (parent) |
| 151 | parent->AddDependentNeedsPushProperties(); |
| 152 | } |
| 153 | parent_ = parent; |
| 154 | } |
| 155 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 156 | void LayerImpl::ClearChildList() { |
| 157 | if (children_.empty()) |
| 158 | return; |
[email protected] | 0ede3bb | 2012-12-09 09:14:39 | [diff] [blame] | 159 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 160 | children_.clear(); |
| 161 | layer_tree_impl()->set_needs_update_draw_properties(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 162 | } |
| 163 | |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 164 | bool LayerImpl::HasAncestor(const LayerImpl* ancestor) const { |
| 165 | if (!ancestor) |
| 166 | return false; |
| 167 | |
| 168 | for (const LayerImpl* layer = this; layer; layer = layer->parent()) { |
| 169 | if (layer == ancestor) |
| 170 | return true; |
| 171 | } |
| 172 | |
| 173 | return false; |
| 174 | } |
| 175 | |
| 176 | void LayerImpl::SetScrollParent(LayerImpl* parent) { |
| 177 | if (scroll_parent_ == parent) |
| 178 | return; |
| 179 | |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 180 | if (parent) |
| 181 | DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 182 | |
| 183 | scroll_parent_ = parent; |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 184 | SetNeedsPushProperties(); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 185 | } |
| 186 | |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 187 | void LayerImpl::SetDebugInfo( |
ssid | 911e40e | 2015-02-09 17:55:20 | [diff] [blame] | 188 | scoped_refptr<base::trace_event::ConvertableToTraceFormat> other) { |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 189 | debug_info_ = other; |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 190 | SetNeedsPushProperties(); |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 191 | } |
| 192 | |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 193 | void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) { |
| 194 | if (scroll_children_.get() == children) |
| 195 | return; |
| 196 | scroll_children_.reset(children); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 197 | SetNeedsPushProperties(); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 198 | } |
| 199 | |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 200 | void LayerImpl::SetNumDescendantsThatDrawContent(int num_descendants) { |
| 201 | if (num_descendants_that_draw_content_ == num_descendants) |
| 202 | return; |
| 203 | num_descendants_that_draw_content_ = num_descendants; |
| 204 | SetNeedsPushProperties(); |
| 205 | } |
| 206 | |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 207 | void LayerImpl::SetClipParent(LayerImpl* ancestor) { |
| 208 | if (clip_parent_ == ancestor) |
| 209 | return; |
| 210 | |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 211 | clip_parent_ = ancestor; |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 212 | SetNeedsPushProperties(); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | void LayerImpl::SetClipChildren(std::set<LayerImpl*>* children) { |
| 216 | if (clip_children_.get() == children) |
| 217 | return; |
| 218 | clip_children_.reset(children); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 219 | SetNeedsPushProperties(); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 220 | } |
| 221 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 222 | void LayerImpl::SetTransformTreeIndex(int index) { |
| 223 | transform_tree_index_ = index; |
| 224 | SetNeedsPushProperties(); |
| 225 | } |
| 226 | |
| 227 | void LayerImpl::SetClipTreeIndex(int index) { |
| 228 | clip_tree_index_ = index; |
| 229 | SetNeedsPushProperties(); |
| 230 | } |
| 231 | |
| 232 | void LayerImpl::SetOpacityTreeIndex(int index) { |
| 233 | opacity_tree_index_ = index; |
| 234 | SetNeedsPushProperties(); |
| 235 | } |
| 236 | |
[email protected] | 0e5f714 | 2013-05-24 06:45:36 | [diff] [blame] | 237 | void LayerImpl::PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests) { |
enne | f44fcf9 | 2015-06-12 23:56:32 | [diff] [blame] | 238 | // In the case that a layer still has a copy request, this means that there's |
| 239 | // a commit to the active tree without a draw. This only happens in some |
| 240 | // edge cases during lost context or visibility changes, so don't try to |
| 241 | // handle preserving these output requests (and their surface). |
| 242 | if (!copy_requests_.empty()) { |
| 243 | layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); |
| 244 | // Destroying these will abort them. |
| 245 | copy_requests_.clear(); |
| 246 | } |
| 247 | |
[email protected] | 0e5f714 | 2013-05-24 06:45:36 | [diff] [blame] | 248 | if (requests->empty()) |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 249 | return; |
enne | f44fcf9 | 2015-06-12 23:56:32 | [diff] [blame] | 250 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 251 | DCHECK(render_surface()); |
[email protected] | f5de9e5b | 2013-07-30 22:26:57 | [diff] [blame] | 252 | bool was_empty = copy_requests_.empty(); |
weiliangc | c1878c6 | 2014-09-02 22:43:17 | [diff] [blame] | 253 | copy_requests_.insert_and_take(copy_requests_.end(), requests); |
[email protected] | 0e5f714 | 2013-05-24 06:45:36 | [diff] [blame] | 254 | requests->clear(); |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 255 | |
[email protected] | f5de9e5b | 2013-07-30 22:26:57 | [diff] [blame] | 256 | if (was_empty && layer_tree_impl()->IsActiveTree()) |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 257 | layer_tree_impl()->AddLayerWithCopyOutputRequest(this); |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 258 | NoteLayerPropertyChangedForSubtree(); |
| 259 | } |
| 260 | |
[email protected] | d4d017e | 2013-06-20 21:46:11 | [diff] [blame] | 261 | void LayerImpl::TakeCopyRequestsAndTransformToTarget( |
| 262 | ScopedPtrVector<CopyOutputRequest>* requests) { |
[email protected] | df17af5 | 2014-02-06 02:20:40 | [diff] [blame] | 263 | DCHECK(!copy_requests_.empty()); |
| 264 | DCHECK(layer_tree_impl()->IsActiveTree()); |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 265 | DCHECK_EQ(render_target(), this); |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 266 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 267 | size_t first_inserted_request = requests->size(); |
weiliangc | c1878c6 | 2014-09-02 22:43:17 | [diff] [blame] | 268 | requests->insert_and_take(requests->end(), ©_requests_); |
[email protected] | 0e5f714 | 2013-05-24 06:45:36 | [diff] [blame] | 269 | copy_requests_.clear(); |
[email protected] | d4d017e | 2013-06-20 21:46:11 | [diff] [blame] | 270 | |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 271 | for (size_t i = first_inserted_request; i < requests->size(); ++i) { |
[email protected] | d4d017e | 2013-06-20 21:46:11 | [diff] [blame] | 272 | CopyOutputRequest* request = requests->at(i); |
| 273 | if (!request->has_area()) |
| 274 | continue; |
| 275 | |
| 276 | gfx::Rect request_in_layer_space = request->area(); |
danakj | e0f14a88 | 2015-06-18 05:05:07 | [diff] [blame] | 277 | request_in_layer_space.Intersect(gfx::Rect(bounds())); |
[email protected] | 8a82269 | 2014-02-12 17:30:55 | [diff] [blame] | 278 | request->set_area(MathUtil::MapEnclosingClippedRect( |
danakj | e0f14a88 | 2015-06-18 05:05:07 | [diff] [blame] | 279 | draw_properties_.target_space_transform, request_in_layer_space)); |
[email protected] | d4d017e | 2013-06-20 21:46:11 | [diff] [blame] | 280 | } |
[email protected] | 30fe19ff | 2013-07-04 00:54:45 | [diff] [blame] | 281 | |
[email protected] | df17af5 | 2014-02-06 02:20:40 | [diff] [blame] | 282 | layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this); |
danakj | 0cf9539 | 2015-01-29 17:56:54 | [diff] [blame] | 283 | layer_tree_impl()->set_needs_update_draw_properties(); |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 284 | } |
| 285 | |
[email protected] | 7644fa2 | 2014-04-28 12:20:33 | [diff] [blame] | 286 | void LayerImpl::ClearRenderSurfaceLayerList() { |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 287 | if (render_surface_) |
| 288 | render_surface_->ClearLayerLists(); |
[email protected] | 7644fa2 | 2014-04-28 12:20:33 | [diff] [blame] | 289 | } |
| 290 | |
[email protected] | 9be1adc8 | 2014-05-07 15:39:41 | [diff] [blame] | 291 | void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const { |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 292 | state->SetAll(draw_properties_.target_space_transform, bounds(), |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 293 | draw_properties_.visible_layer_rect, draw_properties_.clip_rect, |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 294 | is_clipped_, draw_properties_.opacity, |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 295 | draw_properties_.blend_mode, sorting_context_id_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 296 | } |
| 297 | |
enne | 467829b | 2015-02-13 02:39:34 | [diff] [blame] | 298 | void LayerImpl::PopulateScaledSharedQuadState(SharedQuadState* state, |
| 299 | float scale) const { |
| 300 | gfx::Transform scaled_draw_transform = |
| 301 | draw_properties_.target_space_transform; |
| 302 | scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 303 | gfx::Size scaled_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale)); |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 304 | gfx::Rect scaled_visible_layer_rect = |
| 305 | gfx::ScaleToEnclosingRect(visible_layer_rect(), scale); |
| 306 | scaled_visible_layer_rect.Intersect(gfx::Rect(scaled_bounds)); |
enne | 467829b | 2015-02-13 02:39:34 | [diff] [blame] | 307 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 308 | state->SetAll(scaled_draw_transform, scaled_bounds, scaled_visible_layer_rect, |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 309 | draw_properties().clip_rect, is_clipped_, |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 310 | draw_properties().opacity, draw_properties().blend_mode, |
| 311 | sorting_context_id_); |
enne | 467829b | 2015-02-13 02:39:34 | [diff] [blame] | 312 | } |
| 313 | |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 314 | bool LayerImpl::WillDraw(DrawMode draw_mode, |
| 315 | ResourceProvider* resource_provider) { |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 316 | // WillDraw/DidDraw must be matched. |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 317 | DCHECK_NE(DRAW_MODE_NONE, draw_mode); |
| 318 | DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_); |
| 319 | current_draw_mode_ = draw_mode; |
| 320 | return true; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 321 | } |
| 322 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 323 | void LayerImpl::DidDraw(ResourceProvider* resource_provider) { |
[email protected] | ffbb221 | 2013-06-02 23:47:59 | [diff] [blame] | 324 | DCHECK_NE(DRAW_MODE_NONE, current_draw_mode_); |
| 325 | current_draw_mode_ = DRAW_MODE_NONE; |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 326 | } |
| 327 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 328 | bool LayerImpl::ShowDebugBorders() const { |
[email protected] | 846f455b | 2013-03-18 19:07:41 | [diff] [blame] | 329 | return layer_tree_impl()->debug_state().show_debug_borders; |
[email protected] | 3dce3723 | 2012-11-15 01:47:44 | [diff] [blame] | 330 | } |
| 331 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 332 | void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const { |
| 333 | if (draws_content_) { |
| 334 | *color = DebugColors::ContentLayerBorderColor(); |
| 335 | *width = DebugColors::ContentLayerBorderWidth(layer_tree_impl()); |
| 336 | return; |
| 337 | } |
| 338 | |
| 339 | if (masks_to_bounds_) { |
| 340 | *color = DebugColors::MaskingLayerBorderColor(); |
| 341 | *width = DebugColors::MaskingLayerBorderWidth(layer_tree_impl()); |
| 342 | return; |
| 343 | } |
| 344 | |
| 345 | *color = DebugColors::ContainerLayerBorderColor(); |
| 346 | *width = DebugColors::ContainerLayerBorderWidth(layer_tree_impl()); |
| 347 | } |
| 348 | |
| 349 | void LayerImpl::AppendDebugBorderQuad( |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 350 | RenderPass* render_pass, |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 351 | const gfx::Size& bounds, |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 352 | const SharedQuadState* shared_quad_state, |
| 353 | AppendQuadsData* append_quads_data) const { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 354 | SkColor color; |
| 355 | float width; |
| 356 | GetDebugBorderProperties(&color, &width); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 357 | AppendDebugBorderQuad(render_pass, bounds, shared_quad_state, |
| 358 | append_quads_data, color, width); |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 359 | } |
| 360 | |
[email protected] | c6707fd | 2014-06-23 05:50:36 | [diff] [blame] | 361 | void LayerImpl::AppendDebugBorderQuad(RenderPass* render_pass, |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 362 | const gfx::Size& bounds, |
[email protected] | bec08429 | 2013-05-21 21:31:44 | [diff] [blame] | 363 | const SharedQuadState* shared_quad_state, |
| 364 | AppendQuadsData* append_quads_data, |
| 365 | SkColor color, |
| 366 | float width) const { |
| 367 | if (!ShowDebugBorders()) |
| 368 | return; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 369 | |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 370 | gfx::Rect quad_rect(bounds); |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 371 | gfx::Rect visible_quad_rect(quad_rect); |
[email protected] | f7030c3 | 2014-07-03 18:54:34 | [diff] [blame] | 372 | DebugBorderDrawQuad* debug_border_quad = |
| 373 | render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>(); |
[email protected] | 9bf06c7 | 2014-03-07 18:16:24 | [diff] [blame] | 374 | debug_border_quad->SetNew( |
| 375 | shared_quad_state, quad_rect, visible_quad_rect, color, width); |
danakj | 069ac12 | 2015-02-12 00:59:22 | [diff] [blame] | 376 | if (contents_opaque()) { |
| 377 | // When opaque, draw a second inner border that is thicker than the outer |
| 378 | // border, but more transparent. |
| 379 | static const float kFillOpacity = 0.3f; |
| 380 | SkColor fill_color = SkColorSetA( |
| 381 | color, static_cast<uint8_t>(SkColorGetA(color) * kFillOpacity)); |
| 382 | float fill_width = width * 3; |
| 383 | gfx::Rect fill_rect = quad_rect; |
| 384 | fill_rect.Inset(fill_width / 2.f, fill_width / 2.f); |
enne | b79d5f14 | 2015-04-23 19:59:55 | [diff] [blame] | 385 | if (fill_rect.IsEmpty()) |
| 386 | return; |
danakj | 069ac12 | 2015-02-12 00:59:22 | [diff] [blame] | 387 | gfx::Rect visible_fill_rect = |
| 388 | gfx::IntersectRects(visible_quad_rect, fill_rect); |
| 389 | DebugBorderDrawQuad* fill_quad = |
| 390 | render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>(); |
| 391 | fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect, |
| 392 | fill_color, fill_width); |
| 393 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | bool LayerImpl::HasDelegatedContent() const { |
| 397 | return false; |
| 398 | } |
| 399 | |
| 400 | bool LayerImpl::HasContributingDelegatedRenderPasses() const { |
| 401 | return false; |
| 402 | } |
| 403 | |
[email protected] | 0cd7d6f7 | 2014-08-22 14:50:51 | [diff] [blame] | 404 | RenderPassId LayerImpl::FirstContributingRenderPassId() const { |
| 405 | return RenderPassId(0, 0); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 406 | } |
| 407 | |
[email protected] | 0cd7d6f7 | 2014-08-22 14:50:51 | [diff] [blame] | 408 | RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const { |
| 409 | return RenderPassId(0, 0); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 410 | } |
| 411 | |
jbauman | bbd425e | 2015-05-19 00:33:35 | [diff] [blame] | 412 | void LayerImpl::GetContentsResourceId(ResourceId* resource_id, |
enne | f6f3fbba4 | 2014-10-16 18:16:49 | [diff] [blame] | 413 | gfx::Size* resource_size) const { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 414 | NOTREACHED(); |
enne | f6f3fbba4 | 2014-10-16 18:16:49 | [diff] [blame] | 415 | *resource_id = 0; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 416 | } |
| 417 | |
[email protected] | 3244c913 | 2014-01-23 10:39:12 | [diff] [blame] | 418 | gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) { |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 419 | gfx::ScrollOffset adjusted_scroll(scroll); |
bokan | 57ebc05 | 2015-05-29 13:14:21 | [diff] [blame] | 420 | if (!user_scrollable_horizontal_) |
| 421 | adjusted_scroll.set_x(0); |
| 422 | if (!user_scrollable_vertical_) |
| 423 | adjusted_scroll.set_y(0); |
[email protected] | d30700f1 | 2013-07-31 08:21:01 | [diff] [blame] | 424 | DCHECK(scrollable()); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 425 | gfx::ScrollOffset old_offset = CurrentScrollOffset(); |
| 426 | gfx::ScrollOffset new_offset = |
| 427 | ClampScrollOffsetToLimits(old_offset + adjusted_scroll); |
| 428 | SetCurrentScrollOffset(new_offset); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 429 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 430 | gfx::ScrollOffset unscrolled = |
| 431 | old_offset + gfx::ScrollOffset(scroll) - new_offset; |
| 432 | return gfx::Vector2dF(unscrolled.x(), unscrolled.y()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 433 | } |
| 434 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 435 | void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) { |
| 436 | scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id); |
| 437 | } |
| 438 | |
timav | 3ca69693 | 2014-10-15 02:19:04 | [diff] [blame] | 439 | bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const { |
| 440 | return (orientation == HORIZONTAL) ? user_scrollable_horizontal_ |
| 441 | : user_scrollable_vertical_; |
| 442 | } |
| 443 | |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 444 | void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() { |
[email protected] | 3519b87 | 2013-07-30 07:17:50 | [diff] [blame] | 445 | DCHECK(layer_tree_impl()->IsActiveTree()); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 446 | scroll_offset_->AbortCommit(); |
[email protected] | 58241dc | 2013-08-20 01:39:25 | [diff] [blame] | 447 | } |
| 448 | |
[email protected] | 5ff3c978 | 2013-04-29 17:35:12 | [diff] [blame] | 449 | InputHandler::ScrollStatus LayerImpl::TryScroll( |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 450 | const gfx::PointF& screen_space_point, |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 451 | InputHandler::ScrollInputType type, |
| 452 | ScrollBlocksOn effective_block_mode) const { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 453 | if (should_scroll_on_main_thread()) { |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 454 | TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread"); |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 455 | return InputHandler::SCROLL_ON_MAIN_THREAD; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 456 | } |
| 457 | |
| 458 | if (!screen_space_transform().IsInvertible()) { |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 459 | TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform"); |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 460 | return InputHandler::SCROLL_IGNORED; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | if (!non_fast_scrollable_region().IsEmpty()) { |
| 464 | bool clipped = false; |
| 465 | gfx::Transform inverse_screen_space_transform( |
| 466 | gfx::Transform::kSkipInitialization); |
| 467 | if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) { |
| 468 | // TODO(shawnsingh): We shouldn't be applying a projection if screen space |
| 469 | // transform is uninvertible here. Perhaps we should be returning |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 470 | // SCROLL_ON_MAIN_THREAD in this case? |
[email protected] | 3dce3723 | 2012-11-15 01:47:44 | [diff] [blame] | 471 | } |
| 472 | |
danakj | 2c8d12c | 2015-06-18 06:15:33 | [diff] [blame] | 473 | gfx::PointF hit_test_point_in_layer_space = MathUtil::ProjectPoint( |
| 474 | inverse_screen_space_transform, screen_space_point, &clipped); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 475 | if (!clipped && |
| 476 | non_fast_scrollable_region().Contains( |
| 477 | gfx::ToRoundedPoint(hit_test_point_in_layer_space))) { |
| 478 | TRACE_EVENT0("cc", |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 479 | "LayerImpl::tryScroll: Failed NonFastScrollableRegion"); |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 480 | return InputHandler::SCROLL_ON_MAIN_THREAD; |
[email protected] | 3dce3723 | 2012-11-15 01:47:44 | [diff] [blame] | 481 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 482 | } |
[email protected] | 3dce3723 | 2012-11-15 01:47:44 | [diff] [blame] | 483 | |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 484 | if (have_scroll_event_handlers() && |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 485 | effective_block_mode & SCROLL_BLOCKS_ON_SCROLL_EVENT) { |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 486 | TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed ScrollEventHandlers"); |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 487 | return InputHandler::SCROLL_ON_MAIN_THREAD; |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 488 | } |
| 489 | |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 490 | if (type == InputHandler::WHEEL && have_wheel_event_handlers() && |
| 491 | effective_block_mode & SCROLL_BLOCKS_ON_WHEEL_EVENT) { |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 492 | TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers"); |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 493 | return InputHandler::SCROLL_ON_MAIN_THREAD; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 494 | } |
| 495 | |
| 496 | if (!scrollable()) { |
| 497 | TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable"); |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 498 | return InputHandler::SCROLL_IGNORED; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 499 | } |
| 500 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 501 | gfx::ScrollOffset max_scroll_offset = MaxScrollOffset(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 502 | if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 503 | TRACE_EVENT0("cc", |
| 504 | "LayerImpl::tryScroll: Ignored. Technically scrollable," |
| 505 | " but has no affordance in either direction."); |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 506 | return InputHandler::SCROLL_IGNORED; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 507 | } |
| 508 | |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 509 | return InputHandler::SCROLL_STARTED; |
[email protected] | 3dce3723 | 2012-11-15 01:47:44 | [diff] [blame] | 510 | } |
| 511 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 512 | skia::RefPtr<SkPicture> LayerImpl::GetPicture() { |
| 513 | return skia::RefPtr<SkPicture>(); |
[email protected] | 7648159 | 2012-09-21 16:47:06 | [diff] [blame] | 514 | } |
| 515 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 516 | scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) { |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 517 | return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 518 | } |
| 519 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 520 | void LayerImpl::PushPropertiesTo(LayerImpl* layer) { |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 521 | layer->SetTransformOrigin(transform_origin_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 522 | layer->SetBackgroundColor(background_color_); |
| 523 | layer->SetBounds(bounds_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 524 | layer->SetDoubleSided(double_sided_); |
| 525 | layer->SetDrawCheckerboardForMissingTiles( |
| 526 | draw_checkerboard_for_missing_tiles_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 527 | layer->SetDrawsContent(DrawsContent()); |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 528 | layer->SetHideLayerAndSubtree(hide_layer_and_subtree_); |
enne | f44fcf9 | 2015-06-12 23:56:32 | [diff] [blame] | 529 | layer->SetHasRenderSurface(!!render_surface()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 530 | layer->SetFilters(filters()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 531 | layer->SetBackgroundFilters(background_filters()); |
| 532 | layer->SetMasksToBounds(masks_to_bounds_); |
| 533 | layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_); |
| 534 | layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_); |
[email protected] | f998c53 | 2014-03-31 20:02:51 | [diff] [blame] | 535 | layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_); |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 536 | layer->SetScrollBlocksOn(scroll_blocks_on_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 537 | layer->SetNonFastScrollableRegion(non_fast_scrollable_region_); |
| 538 | layer->SetTouchEventHandlerRegion(touch_event_handler_region_); |
| 539 | layer->SetContentsOpaque(contents_opaque_); |
[email protected] | 4361587 | 2013-03-13 16:35:17 | [diff] [blame] | 540 | layer->SetOpacity(opacity_); |
[email protected] | 7bbeaf4e | 2013-11-26 10:27:22 | [diff] [blame] | 541 | layer->SetBlendMode(blend_mode_); |
| 542 | layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 543 | layer->SetPosition(position_); |
| 544 | layer->SetIsContainerForFixedPositionLayers( |
| 545 | is_container_for_fixed_position_layers_); |
[email protected] | fe956c9c4 | 2013-04-09 04:26:33 | [diff] [blame] | 546 | layer->SetPositionConstraint(position_constraint_); |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 547 | layer->SetShouldFlattenTransform(should_flatten_transform_); |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 548 | layer->set_should_flatten_transform_from_property_tree( |
| 549 | should_flatten_transform_from_property_tree_); |
jaydasika | d36e7fa | 2015-07-14 15:15:04 | [diff] [blame] | 550 | layer->set_is_clipped(is_clipped_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 551 | layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_); |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 552 | layer->SetTransformAndInvertibility(transform_, transform_is_invertible_); |
[email protected] | 9bd1cb5 | 2013-01-03 22:26:33 | [diff] [blame] | 553 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 554 | layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id() |
| 555 | : Layer::INVALID_ID); |
[email protected] | 59a7d55 | 2013-10-22 03:36:43 | [diff] [blame] | 556 | layer->set_user_scrollable_horizontal(user_scrollable_horizontal_); |
| 557 | layer->set_user_scrollable_vertical(user_scrollable_vertical_); |
bokan | c687507f | 2014-11-04 23:41:42 | [diff] [blame] | 558 | |
miletus | ff93ab7 | 2015-01-30 04:30:44 | [diff] [blame] | 559 | layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_); |
bokan | c687507f | 2014-11-04 23:41:42 | [diff] [blame] | 560 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 561 | layer->PushScrollOffset(nullptr); |
| 562 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 563 | layer->Set3dSortingContextId(sorting_context_id_); |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 564 | layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_); |
[email protected] | b34c9798 | 2013-08-24 15:21:38 | [diff] [blame] | 565 | |
vollick | 692444f | 2015-05-20 15:39:14 | [diff] [blame] | 566 | layer->SetTransformTreeIndex(transform_tree_index_); |
| 567 | layer->SetClipTreeIndex(clip_tree_index_); |
| 568 | layer->SetOpacityTreeIndex(opacity_tree_index_); |
enne | e95b154 | 2015-04-20 20:35:50 | [diff] [blame] | 569 | layer->set_offset_to_transform_parent(offset_to_transform_parent_); |
| 570 | |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 571 | LayerImpl* scroll_parent = nullptr; |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 572 | if (scroll_parent_) { |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 573 | scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id()); |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 574 | DCHECK(scroll_parent); |
| 575 | } |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 576 | |
| 577 | layer->SetScrollParent(scroll_parent); |
| 578 | if (scroll_children_) { |
| 579 | std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>; |
| 580 | for (std::set<LayerImpl*>::iterator it = scroll_children_->begin(); |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 581 | it != scroll_children_->end(); |
| 582 | ++it) { |
| 583 | DCHECK_EQ((*it)->scroll_parent(), this); |
| 584 | LayerImpl* scroll_child = |
| 585 | layer->layer_tree_impl()->LayerById((*it)->id()); |
| 586 | DCHECK(scroll_child); |
| 587 | scroll_children->insert(scroll_child); |
| 588 | } |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 589 | layer->SetScrollChildren(scroll_children); |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 590 | } else { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 591 | layer->SetScrollChildren(nullptr); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 592 | } |
| 593 | |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 594 | LayerImpl* clip_parent = nullptr; |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 595 | if (clip_parent_) { |
| 596 | clip_parent = layer->layer_tree_impl()->LayerById( |
| 597 | clip_parent_->id()); |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 598 | DCHECK(clip_parent); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | layer->SetClipParent(clip_parent); |
| 602 | if (clip_children_) { |
| 603 | std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>; |
| 604 | for (std::set<LayerImpl*>::iterator it = clip_children_->begin(); |
| 605 | it != clip_children_->end(); ++it) |
| 606 | clip_children->insert(layer->layer_tree_impl()->LayerById((*it)->id())); |
| 607 | layer->SetClipChildren(clip_children); |
[email protected] | d097e24 | 2014-02-28 21:51:11 | [diff] [blame] | 608 | } else { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 609 | layer->SetClipChildren(nullptr); |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 610 | } |
| 611 | |
[email protected] | 0e5f714 | 2013-05-24 06:45:36 | [diff] [blame] | 612 | layer->PassCopyRequests(©_requests_); |
[email protected] | 18a7019 | 2013-04-26 16:18:25 | [diff] [blame] | 613 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 614 | // If the main thread commits multiple times before the impl thread actually |
| 615 | // draws, then damage tracking will become incorrect if we simply clobber the |
[email protected] | ed511b8d | 2013-03-25 03:29:29 | [diff] [blame] | 616 | // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e. |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 617 | // union) any update changes that have occurred on the main thread. |
| 618 | update_rect_.Union(layer->update_rect()); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 619 | layer->SetUpdateRect(update_rect_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 620 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 621 | layer->SetStackingOrderChanged(stacking_order_changed_); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 622 | layer->SetDebugInfo(debug_info_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 623 | |
vmpstr | 3d1d72c | 2015-01-26 18:27:40 | [diff] [blame] | 624 | if (frame_timing_requests_dirty_) { |
vmpstr | 3a24da504 | 2015-05-27 03:33:31 | [diff] [blame] | 625 | layer->SetFrameTimingRequests(frame_timing_requests_); |
vmpstr | 3d1d72c | 2015-01-26 18:27:40 | [diff] [blame] | 626 | frame_timing_requests_dirty_ = false; |
| 627 | } |
| 628 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 629 | // Reset any state that should be cleared for the next update. |
| 630 | stacking_order_changed_ = false; |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 631 | update_rect_ = gfx::Rect(); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 632 | needs_push_properties_ = false; |
| 633 | num_dependents_need_push_properties_ = 0; |
[email protected] | caa567d | 2012-12-20 07:56:16 | [diff] [blame] | 634 | } |
| 635 | |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 636 | gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const { |
| 637 | if (!scroll_clip_layer_) |
| 638 | return gfx::Vector2dF(); |
| 639 | |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 640 | gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta(); |
bokan | 8273d96 | 2014-10-22 02:40:27 | [diff] [blame] | 641 | |
| 642 | // In virtual-viewport mode, we don't need to compensate for pinch zoom or |
| 643 | // scale since the fixed container is the outer viewport, which sits below |
| 644 | // the page scale. |
bokan | 57ebc05 | 2015-05-29 13:14:21 | [diff] [blame] | 645 | return delta_from_scroll; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 646 | } |
| 647 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 648 | base::DictionaryValue* LayerImpl::LayerTreeAsJson() const { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 649 | base::DictionaryValue* result = new base::DictionaryValue; |
r.kasibhatla | fd17d0e | 2015-05-17 11:12:07 | [diff] [blame] | 650 | result->SetInteger("LayerId", id()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 651 | result->SetString("LayerType", LayerTypeAsString()); |
| 652 | |
[email protected] | 46c7695 | 2013-07-10 00:21:45 | [diff] [blame] | 653 | base::ListValue* list = new base::ListValue; |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 654 | list->AppendInteger(bounds().width()); |
| 655 | list->AppendInteger(bounds().height()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 656 | result->Set("Bounds", list); |
| 657 | |
| 658 | list = new base::ListValue; |
| 659 | list->AppendDouble(position_.x()); |
| 660 | list->AppendDouble(position_.y()); |
| 661 | result->Set("Position", list); |
| 662 | |
| 663 | const gfx::Transform& gfx_transform = draw_properties_.target_space_transform; |
| 664 | double transform[16]; |
| 665 | gfx_transform.matrix().asColMajord(transform); |
| 666 | list = new base::ListValue; |
| 667 | for (int i = 0; i < 16; ++i) |
| 668 | list->AppendDouble(transform[i]); |
| 669 | result->Set("DrawTransform", list); |
| 670 | |
| 671 | result->SetBoolean("DrawsContent", draws_content_); |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 672 | result->SetBoolean("Is3dSorted", Is3dSorted()); |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 673 | result->SetDouble("OPACITY", opacity()); |
[email protected] | 46c7695 | 2013-07-10 00:21:45 | [diff] [blame] | 674 | result->SetBoolean("ContentsOpaque", contents_opaque_); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 675 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 676 | if (scrollable()) |
| 677 | result->SetBoolean("Scrollable", true); |
[email protected] | d993e03 | 2013-06-07 00:16:16 | [diff] [blame] | 678 | |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 679 | if (have_wheel_event_handlers_) |
| 680 | result->SetBoolean("WheelHandler", have_wheel_event_handlers_); |
[email protected] | f998c53 | 2014-03-31 20:02:51 | [diff] [blame] | 681 | if (have_scroll_event_handlers_) |
| 682 | result->SetBoolean("ScrollHandler", have_scroll_event_handlers_); |
[email protected] | 9d161d2 | 2013-10-29 20:54:10 | [diff] [blame] | 683 | if (!touch_event_handler_region_.IsEmpty()) { |
| 684 | scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue(); |
| 685 | result->Set("TouchRegion", region.release()); |
| 686 | } |
| 687 | |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 688 | if (scroll_blocks_on_) { |
| 689 | list = new base::ListValue; |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 690 | if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_START_TOUCH) |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 691 | list->AppendString("StartTouch"); |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 692 | if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_WHEEL_EVENT) |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 693 | list->AppendString("WheelEvent"); |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 694 | if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_SCROLL_EVENT) |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 695 | list->AppendString("ScrollEvent"); |
| 696 | result->Set("ScrollBlocksOn", list); |
| 697 | } |
| 698 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 699 | list = new base::ListValue; |
| 700 | for (size_t i = 0; i < children_.size(); ++i) |
| 701 | list->Append(children_[i]->LayerTreeAsJson()); |
| 702 | result->Set("Children", list); |
| 703 | |
| 704 | return result; |
[email protected] | b9dcf43a | 2013-01-09 00:15:29 | [diff] [blame] | 705 | } |
| 706 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 707 | void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) { |
| 708 | if (stacking_order_changed) { |
| 709 | stacking_order_changed_ = true; |
| 710 | NoteLayerPropertyChangedForSubtree(); |
| 711 | } |
[email protected] | aedf4e5 | 2013-01-09 23:24:44 | [diff] [blame] | 712 | } |
| 713 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 714 | void LayerImpl::NoteLayerPropertyChanged() { |
| 715 | layer_property_changed_ = true; |
| 716 | layer_tree_impl()->set_needs_update_draw_properties(); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 717 | SetNeedsPushProperties(); |
[email protected] | 48871fc | 2013-01-23 07:36:51 | [diff] [blame] | 718 | } |
| 719 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 720 | void LayerImpl::NoteLayerPropertyChangedForSubtree() { |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 721 | layer_property_changed_ = true; |
| 722 | layer_tree_impl()->set_needs_update_draw_properties(); |
| 723 | for (size_t i = 0; i < children_.size(); ++i) |
| 724 | children_[i]->NoteLayerPropertyChangedForDescendantsInternal(); |
| 725 | SetNeedsPushProperties(); |
| 726 | } |
| 727 | |
| 728 | void LayerImpl::NoteLayerPropertyChangedForDescendantsInternal() { |
| 729 | layer_property_changed_ = true; |
| 730 | for (size_t i = 0; i < children_.size(); ++i) |
| 731 | children_[i]->NoteLayerPropertyChangedForDescendantsInternal(); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 732 | } |
| 733 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 734 | void LayerImpl::NoteLayerPropertyChangedForDescendants() { |
| 735 | layer_tree_impl()->set_needs_update_draw_properties(); |
| 736 | for (size_t i = 0; i < children_.size(); ++i) |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 737 | children_[i]->NoteLayerPropertyChangedForDescendantsInternal(); |
| 738 | SetNeedsPushProperties(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 739 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 740 | |
danakj | f942757 | 2015-04-24 22:19:02 | [diff] [blame] | 741 | void LayerImpl::ValidateQuadResourcesInternal(DrawQuad* quad) const { |
| 742 | #if DCHECK_IS_ON() |
vmpstr | 0eca2e8 | 2015-06-02 22:14:46 | [diff] [blame] | 743 | const ResourceProvider* resource_provider = |
| 744 | layer_tree_impl_->resource_provider(); |
| 745 | for (ResourceId resource_id : quad->resources) |
| 746 | resource_provider->ValidateResource(resource_id); |
danakj | f942757 | 2015-04-24 22:19:02 | [diff] [blame] | 747 | #endif |
| 748 | } |
| 749 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 750 | const char* LayerImpl::LayerTypeAsString() const { |
[email protected] | f256b7fd | 2013-05-15 01:49:30 | [diff] [blame] | 751 | return "cc::LayerImpl"; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 752 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 753 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 754 | void LayerImpl::ResetAllChangeTrackingForSubtree() { |
| 755 | layer_property_changed_ = false; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 756 | |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 757 | update_rect_ = gfx::Rect(); |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 758 | damage_rect_ = gfx::RectF(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 759 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 760 | if (render_surface_) |
| 761 | render_surface_->ResetPropertyChangedFlag(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 762 | |
| 763 | if (mask_layer_) |
| 764 | mask_layer_->ResetAllChangeTrackingForSubtree(); |
| 765 | |
| 766 | if (replica_layer_) { |
| 767 | // This also resets the replica mask, if it exists. |
| 768 | replica_layer_->ResetAllChangeTrackingForSubtree(); |
| 769 | } |
| 770 | |
| 771 | for (size_t i = 0; i < children_.size(); ++i) |
| 772 | children_[i]->ResetAllChangeTrackingForSubtree(); |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 773 | |
| 774 | needs_push_properties_ = false; |
| 775 | num_dependents_need_push_properties_ = 0; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 776 | } |
| 777 | |
ajuma | 59c23b4 | 2015-05-25 20:18:37 | [diff] [blame] | 778 | void LayerImpl::UpdatePropertyTreeTransform() { |
| 779 | if (transform_tree_index_ != -1) { |
| 780 | TransformTree& transform_tree = |
| 781 | layer_tree_impl()->property_trees()->transform_tree; |
| 782 | TransformNode* node = transform_tree.Node(transform_tree_index_); |
ajuma | e742527 | 2015-07-13 18:37:34 | [diff] [blame] | 783 | // A LayerImpl's own current state is insufficient for determining whether |
| 784 | // it owns a TransformNode, since this depends on the state of the |
| 785 | // corresponding Layer at the time of the last commit. For example, a |
| 786 | // transform animation might have been in progress at the time the last |
| 787 | // commit started, but might have finished since then on the compositor |
| 788 | // thread. |
| 789 | if (node->owner_id != id()) |
| 790 | return; |
ajuma | 59c23b4 | 2015-05-25 20:18:37 | [diff] [blame] | 791 | if (node->data.local != transform_) { |
| 792 | node->data.local = transform_; |
| 793 | node->data.needs_local_transform_update = true; |
| 794 | transform_tree.set_needs_update(true); |
| 795 | // TODO(ajuma): The current criteria for creating clip nodes means that |
| 796 | // property trees may need to be rebuilt when the new transform isn't |
| 797 | // axis-aligned wrt the old transform (see Layer::SetTransform). Since |
| 798 | // rebuilding property trees every frame of a transform animation is |
| 799 | // something we should try to avoid, change property tree-building so that |
| 800 | // it doesn't depend on axis aliginment. |
| 801 | } |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | void LayerImpl::UpdatePropertyTreeOpacity() { |
| 806 | if (opacity_tree_index_ != -1) { |
| 807 | OpacityTree& opacity_tree = |
| 808 | layer_tree_impl()->property_trees()->opacity_tree; |
| 809 | OpacityNode* node = opacity_tree.Node(opacity_tree_index_); |
ajuma | e742527 | 2015-07-13 18:37:34 | [diff] [blame] | 810 | // A LayerImpl's own current state is insufficient for determining whether |
| 811 | // it owns an OpacityNode, since this depends on the state of the |
| 812 | // corresponding Layer at the time of the last commit. For example, an |
| 813 | // opacity animation might have been in progress at the time the last commit |
| 814 | // started, but might have finished since then on the compositor thread. |
| 815 | if (node->owner_id != id()) |
| 816 | return; |
jaydasika | 9fc1aef | 2015-06-26 23:35:57 | [diff] [blame] | 817 | node->data.opacity = opacity_; |
| 818 | opacity_tree.set_needs_update(true); |
ajuma | 59c23b4 | 2015-05-25 20:18:37 | [diff] [blame] | 819 | } |
| 820 | } |
| 821 | |
ajuma | 9db24fb | 2015-06-29 20:15:07 | [diff] [blame] | 822 | void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() { |
| 823 | if (scrollable()) |
| 824 | UpdatePropertyTreeScrollOffset(); |
| 825 | |
ajuma | e742527 | 2015-07-13 18:37:34 | [diff] [blame] | 826 | if (HasAnyAnimationTargetingProperty(Animation::OPACITY)) |
ajuma | 9db24fb | 2015-06-29 20:15:07 | [diff] [blame] | 827 | UpdatePropertyTreeOpacity(); |
| 828 | |
ajuma | e742527 | 2015-07-13 18:37:34 | [diff] [blame] | 829 | if (HasAnyAnimationTargetingProperty(Animation::TRANSFORM)) |
ajuma | 9db24fb | 2015-06-29 20:15:07 | [diff] [blame] | 830 | UpdatePropertyTreeTransform(); |
| 831 | } |
| 832 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 833 | gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const { |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 834 | return CurrentScrollOffset(); |
[email protected] | b8384e2 | 2013-12-03 02:20:48 | [diff] [blame] | 835 | } |
| 836 | |
[email protected] | b4c6d81 | 2013-10-03 15:48:56 | [diff] [blame] | 837 | void LayerImpl::OnFilterAnimated(const FilterOperations& filters) { |
| 838 | SetFilters(filters); |
| 839 | } |
| 840 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 841 | void LayerImpl::OnOpacityAnimated(float opacity) { |
| 842 | SetOpacity(opacity); |
ajuma | 59c23b4 | 2015-05-25 20:18:37 | [diff] [blame] | 843 | UpdatePropertyTreeOpacity(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) { |
| 847 | SetTransform(transform); |
ajuma | 59c23b4 | 2015-05-25 20:18:37 | [diff] [blame] | 848 | UpdatePropertyTreeTransform(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 849 | } |
| 850 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 851 | void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) { |
[email protected] | b8384e2 | 2013-12-03 02:20:48 | [diff] [blame] | 852 | // Only layers in the active tree should need to do anything here, since |
| 853 | // layers in the pending tree will find out about these changes as a |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 854 | // result of the shared SyncedProperty. |
[email protected] | b8384e2 | 2013-12-03 02:20:48 | [diff] [blame] | 855 | if (!IsActive()) |
| 856 | return; |
| 857 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 858 | SetCurrentScrollOffset(scroll_offset); |
[email protected] | b8384e2 | 2013-12-03 02:20:48 | [diff] [blame] | 859 | |
| 860 | layer_tree_impl_->DidAnimateScrollOffset(); |
| 861 | } |
| 862 | |
[email protected] | 1c24cf296 | 2013-11-18 23:34:51 | [diff] [blame] | 863 | void LayerImpl::OnAnimationWaitingForDeletion() {} |
| 864 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 865 | bool LayerImpl::IsActive() const { |
| 866 | return layer_tree_impl_->IsActiveTree(); |
| 867 | } |
| 868 | |
bokan | cccfde7 | 2014-10-08 15:15:22 | [diff] [blame] | 869 | gfx::Size LayerImpl::bounds() const { |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 870 | gfx::Vector2d delta = gfx::ToCeiledVector2d(bounds_delta_); |
| 871 | return gfx::Size(bounds_.width() + delta.x(), |
| 872 | bounds_.height() + delta.y()); |
| 873 | } |
| 874 | |
| 875 | gfx::SizeF LayerImpl::BoundsForScrolling() const { |
| 876 | return gfx::SizeF(bounds_.width() + bounds_delta_.x(), |
| 877 | bounds_.height() + bounds_delta_.y()); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 878 | } |
| 879 | |
[email protected] | 64348ea | 2014-01-29 22:58:26 | [diff] [blame] | 880 | void LayerImpl::SetBounds(const gfx::Size& bounds) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 881 | if (bounds_ == bounds) |
| 882 | return; |
| 883 | |
| 884 | bounds_ = bounds; |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 885 | |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 886 | ScrollbarParametersDidChange(true); |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 887 | if (masks_to_bounds()) |
| 888 | NoteLayerPropertyChangedForSubtree(); |
| 889 | else |
| 890 | NoteLayerPropertyChanged(); |
| 891 | } |
| 892 | |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 893 | void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) { |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 894 | DCHECK(IsActive()); |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 895 | if (bounds_delta_ == bounds_delta) |
[email protected] | fef74fd | 2014-02-27 06:28:17 | [diff] [blame] | 896 | return; |
| 897 | |
[email protected] | 587941d | 2014-08-22 01:40:01 | [diff] [blame] | 898 | bounds_delta_ = bounds_delta; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 899 | |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 900 | TransformTree& transform_tree = |
| 901 | layer_tree_impl()->property_trees()->transform_tree; |
ajuma | dd2802e7 | 2015-06-30 20:28:29 | [diff] [blame] | 902 | if (this == layer_tree_impl()->InnerViewportContainerLayer()) |
| 903 | transform_tree.SetInnerViewportBoundsDelta(bounds_delta); |
| 904 | else if (this == layer_tree_impl()->OuterViewportContainerLayer()) |
| 905 | transform_tree.SetOuterViewportBoundsDelta(bounds_delta); |
ajuma | 6b46da2 | 2015-06-25 21:53:02 | [diff] [blame] | 906 | |
aelias | 1505e72 | 2014-10-07 22:19:46 | [diff] [blame] | 907 | ScrollbarParametersDidChange(true); |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 908 | |
| 909 | if (masks_to_bounds()) { |
| 910 | // If layer is clipping, then update the clip node using the new bounds. |
| 911 | ClipNode* clip_node = |
| 912 | layer_tree_impl()->property_trees()->clip_tree.Node(clip_tree_index()); |
| 913 | if (clip_node) { |
| 914 | DCHECK(id() == clip_node->owner_id); |
| 915 | clip_node->data.clip = |
| 916 | gfx::RectF(gfx::PointF() + offset_to_transform_parent(), bounds()); |
| 917 | layer_tree_impl()->property_trees()->clip_tree.set_needs_update(true); |
| 918 | } |
| 919 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 920 | NoteLayerPropertyChangedForSubtree(); |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 921 | } else { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 922 | NoteLayerPropertyChanged(); |
miletus | 8bd08a62 | 2015-06-16 18:44:52 | [diff] [blame] | 923 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 924 | } |
| 925 | |
| 926 | void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) { |
| 927 | int new_layer_id = mask_layer ? mask_layer->id() : -1; |
| 928 | |
| 929 | if (mask_layer) { |
| 930 | DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl()); |
| 931 | DCHECK_NE(new_layer_id, mask_layer_id_); |
| 932 | } else if (new_layer_id == mask_layer_id_) { |
| 933 | return; |
| 934 | } |
| 935 | |
| 936 | mask_layer_ = mask_layer.Pass(); |
| 937 | mask_layer_id_ = new_layer_id; |
| 938 | if (mask_layer_) |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 939 | mask_layer_->SetParent(this); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 940 | NoteLayerPropertyChangedForSubtree(); |
| 941 | } |
| 942 | |
| 943 | scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() { |
| 944 | mask_layer_id_ = -1; |
| 945 | return mask_layer_.Pass(); |
| 946 | } |
| 947 | |
| 948 | void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) { |
| 949 | int new_layer_id = replica_layer ? replica_layer->id() : -1; |
| 950 | |
| 951 | if (replica_layer) { |
| 952 | DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl()); |
| 953 | DCHECK_NE(new_layer_id, replica_layer_id_); |
| 954 | } else if (new_layer_id == replica_layer_id_) { |
| 955 | return; |
| 956 | } |
| 957 | |
| 958 | replica_layer_ = replica_layer.Pass(); |
| 959 | replica_layer_id_ = new_layer_id; |
| 960 | if (replica_layer_) |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 961 | replica_layer_->SetParent(this); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 962 | NoteLayerPropertyChangedForSubtree(); |
| 963 | } |
| 964 | |
| 965 | scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() { |
| 966 | replica_layer_id_ = -1; |
| 967 | return replica_layer_.Pass(); |
| 968 | } |
| 969 | |
[email protected] | 80413d7 | 2013-08-30 20:25:33 | [diff] [blame] | 970 | ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 971 | return nullptr; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 972 | } |
| 973 | |
| 974 | void LayerImpl::SetDrawsContent(bool draws_content) { |
| 975 | if (draws_content_ == draws_content) |
| 976 | return; |
| 977 | |
| 978 | draws_content_ = draws_content; |
| 979 | NoteLayerPropertyChanged(); |
| 980 | } |
| 981 | |
[email protected] | c0ae06c1 | 2013-06-24 18:32:19 | [diff] [blame] | 982 | void LayerImpl::SetHideLayerAndSubtree(bool hide) { |
| 983 | if (hide_layer_and_subtree_ == hide) |
| 984 | return; |
| 985 | |
| 986 | hide_layer_and_subtree_ = hide; |
| 987 | NoteLayerPropertyChangedForSubtree(); |
| 988 | } |
| 989 | |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 990 | void LayerImpl::SetTransformOrigin(const gfx::Point3F& transform_origin) { |
| 991 | if (transform_origin_ == transform_origin) |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 992 | return; |
[email protected] | a256641 | 2014-06-05 03:14:20 | [diff] [blame] | 993 | transform_origin_ = transform_origin; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 994 | NoteLayerPropertyChangedForSubtree(); |
| 995 | } |
| 996 | |
| 997 | void LayerImpl::SetBackgroundColor(SkColor background_color) { |
| 998 | if (background_color_ == background_color) |
| 999 | return; |
| 1000 | |
| 1001 | background_color_ = background_color; |
| 1002 | NoteLayerPropertyChanged(); |
| 1003 | } |
| 1004 | |
[email protected] | 2c4cbec | 2013-06-04 21:14:50 | [diff] [blame] | 1005 | SkColor LayerImpl::SafeOpaqueBackgroundColor() const { |
| 1006 | SkColor color = background_color(); |
| 1007 | if (SkColorGetA(color) == 255 && !contents_opaque()) { |
| 1008 | color = SK_ColorTRANSPARENT; |
| 1009 | } else if (SkColorGetA(color) != 255 && contents_opaque()) { |
| 1010 | for (const LayerImpl* layer = parent(); layer; |
| 1011 | layer = layer->parent()) { |
| 1012 | color = layer->background_color(); |
| 1013 | if (SkColorGetA(color) == 255) |
| 1014 | break; |
| 1015 | } |
| 1016 | if (SkColorGetA(color) != 255) |
| 1017 | color = layer_tree_impl()->background_color(); |
| 1018 | if (SkColorGetA(color) != 255) |
| 1019 | color = SkColorSetA(color, 255); |
| 1020 | } |
| 1021 | return color; |
| 1022 | } |
| 1023 | |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1024 | void LayerImpl::SetFilters(const FilterOperations& filters) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1025 | if (filters_ == filters) |
| 1026 | return; |
| 1027 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1028 | filters_ = filters; |
| 1029 | NoteLayerPropertyChangedForSubtree(); |
| 1030 | } |
| 1031 | |
[email protected] | b4c6d81 | 2013-10-03 15:48:56 | [diff] [blame] | 1032 | bool LayerImpl::FilterIsAnimating() const { |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1033 | return layer_animation_controller_ |
| 1034 | ? layer_animation_controller_->IsAnimatingProperty( |
| 1035 | Animation::FILTER) |
| 1036 | : layer_tree_impl_->IsAnimatingFilterProperty(this); |
[email protected] | b4c6d81 | 2013-10-03 15:48:56 | [diff] [blame] | 1037 | } |
| 1038 | |
| 1039 | bool LayerImpl::FilterIsAnimatingOnImplOnly() const { |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1040 | if (!layer_animation_controller_) |
| 1041 | return layer_tree_impl_->FilterIsAnimatingOnImplOnly(this); |
| 1042 | |
[email protected] | b4c6d81 | 2013-10-03 15:48:56 | [diff] [blame] | 1043 | Animation* filter_animation = |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1044 | layer_animation_controller_->GetAnimation(Animation::FILTER); |
[email protected] | b4c6d81 | 2013-10-03 15:48:56 | [diff] [blame] | 1045 | return filter_animation && filter_animation->is_impl_only(); |
| 1046 | } |
| 1047 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1048 | void LayerImpl::SetBackgroundFilters( |
[email protected] | ae6b1a7 | 2013-06-25 18:49:29 | [diff] [blame] | 1049 | const FilterOperations& filters) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1050 | if (background_filters_ == filters) |
| 1051 | return; |
| 1052 | |
| 1053 | background_filters_ = filters; |
| 1054 | NoteLayerPropertyChanged(); |
| 1055 | } |
| 1056 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1057 | void LayerImpl::SetMasksToBounds(bool masks_to_bounds) { |
| 1058 | if (masks_to_bounds_ == masks_to_bounds) |
| 1059 | return; |
| 1060 | |
| 1061 | masks_to_bounds_ = masks_to_bounds; |
| 1062 | NoteLayerPropertyChangedForSubtree(); |
| 1063 | } |
| 1064 | |
| 1065 | void LayerImpl::SetContentsOpaque(bool opaque) { |
| 1066 | if (contents_opaque_ == opaque) |
| 1067 | return; |
| 1068 | |
| 1069 | contents_opaque_ = opaque; |
| 1070 | NoteLayerPropertyChangedForSubtree(); |
| 1071 | } |
| 1072 | |
| 1073 | void LayerImpl::SetOpacity(float opacity) { |
| 1074 | if (opacity_ == opacity) |
| 1075 | return; |
| 1076 | |
| 1077 | opacity_ = opacity; |
[email protected] | af37ce80 | 2013-10-07 23:53:28 | [diff] [blame] | 1078 | NoteLayerPropertyChangedForSubtree(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | bool LayerImpl::OpacityIsAnimating() const { |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1082 | return layer_animation_controller_ |
| 1083 | ? layer_animation_controller_->IsAnimatingProperty( |
| 1084 | Animation::OPACITY) |
| 1085 | : layer_tree_impl_->IsAnimatingOpacityProperty(this); |
| 1086 | } |
| 1087 | |
| 1088 | bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const { |
| 1089 | if (layer_animation_controller_) { |
| 1090 | if (Animation* animation = |
| 1091 | layer_animation_controller()->GetAnimation(Animation::OPACITY)) { |
| 1092 | return !animation->is_finished(); |
| 1093 | } |
| 1094 | return false; |
| 1095 | } else { |
| 1096 | return layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this); |
| 1097 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1098 | } |
| 1099 | |
[email protected] | 4361587 | 2013-03-13 16:35:17 | [diff] [blame] | 1100 | bool LayerImpl::OpacityIsAnimatingOnImplOnly() const { |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1101 | if (!layer_animation_controller_) |
| 1102 | return layer_tree_impl_->OpacityIsAnimatingOnImplOnly(this); |
| 1103 | |
[email protected] | 4361587 | 2013-03-13 16:35:17 | [diff] [blame] | 1104 | Animation* opacity_animation = |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1105 | layer_animation_controller_->GetAnimation(Animation::OPACITY); |
[email protected] | 4361587 | 2013-03-13 16:35:17 | [diff] [blame] | 1106 | return opacity_animation && opacity_animation->is_impl_only(); |
| 1107 | } |
| 1108 | |
[email protected] | 7bbeaf4e | 2013-11-26 10:27:22 | [diff] [blame] | 1109 | void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) { |
| 1110 | if (blend_mode_ == blend_mode) |
| 1111 | return; |
| 1112 | |
| 1113 | blend_mode_ = blend_mode; |
| 1114 | NoteLayerPropertyChangedForSubtree(); |
| 1115 | } |
| 1116 | |
| 1117 | void LayerImpl::SetIsRootForIsolatedGroup(bool root) { |
| 1118 | if (is_root_for_isolated_group_ == root) |
| 1119 | return; |
| 1120 | |
| 1121 | is_root_for_isolated_group_ = root; |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 1122 | SetNeedsPushProperties(); |
[email protected] | 7bbeaf4e | 2013-11-26 10:27:22 | [diff] [blame] | 1123 | } |
| 1124 | |
[email protected] | 14bc5d68 | 2014-01-17 07:26:47 | [diff] [blame] | 1125 | void LayerImpl::SetPosition(const gfx::PointF& position) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1126 | if (position_ == position) |
| 1127 | return; |
| 1128 | |
| 1129 | position_ = position; |
| 1130 | NoteLayerPropertyChangedForSubtree(); |
| 1131 | } |
| 1132 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1133 | void LayerImpl::SetShouldFlattenTransform(bool flatten) { |
| 1134 | if (should_flatten_transform_ == flatten) |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1135 | return; |
| 1136 | |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1137 | should_flatten_transform_ = flatten; |
| 1138 | NoteLayerPropertyChangedForSubtree(); |
| 1139 | } |
| 1140 | |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 1141 | void LayerImpl::Set3dSortingContextId(int id) { |
| 1142 | if (id == sorting_context_id_) |
[email protected] | 56fffdd | 2014-02-11 19:50:57 | [diff] [blame] | 1143 | return; |
[email protected] | a9d4d4f | 2014-06-19 06:49:28 | [diff] [blame] | 1144 | sorting_context_id_ = id; |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1145 | NoteLayerPropertyChangedForSubtree(); |
| 1146 | } |
| 1147 | |
vmpstr | 3a24da504 | 2015-05-27 03:33:31 | [diff] [blame] | 1148 | void LayerImpl::SetFrameTimingRequests( |
| 1149 | const std::vector<FrameTimingRequest>& requests) { |
| 1150 | frame_timing_requests_ = requests; |
vmpstr | 3d1d72c | 2015-01-26 18:27:40 | [diff] [blame] | 1151 | frame_timing_requests_dirty_ = true; |
| 1152 | SetNeedsPushProperties(); |
| 1153 | } |
| 1154 | |
vmpstr | d704c87 | 2015-04-03 20:29:51 | [diff] [blame] | 1155 | void LayerImpl::GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids) { |
| 1156 | for (const auto& request : frame_timing_requests_) |
| 1157 | request_ids->push_back(request.id()); |
| 1158 | } |
| 1159 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1160 | void LayerImpl::SetTransform(const gfx::Transform& transform) { |
| 1161 | if (transform_ == transform) |
| 1162 | return; |
| 1163 | |
| 1164 | transform_ = transform; |
[email protected] | 08bdf1b | 2014-04-16 23:23:29 | [diff] [blame] | 1165 | transform_is_invertible_ = transform_.IsInvertible(); |
| 1166 | NoteLayerPropertyChangedForSubtree(); |
| 1167 | } |
| 1168 | |
| 1169 | void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform, |
| 1170 | bool transform_is_invertible) { |
| 1171 | if (transform_ == transform) { |
| 1172 | DCHECK(transform_is_invertible_ == transform_is_invertible) |
| 1173 | << "Can't change invertibility if transform is unchanged"; |
| 1174 | return; |
| 1175 | } |
| 1176 | transform_ = transform; |
| 1177 | transform_is_invertible_ = transform_is_invertible; |
[email protected] | af37ce80 | 2013-10-07 23:53:28 | [diff] [blame] | 1178 | NoteLayerPropertyChangedForSubtree(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | bool LayerImpl::TransformIsAnimating() const { |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1182 | return layer_animation_controller_ |
| 1183 | ? layer_animation_controller_->IsAnimatingProperty( |
| 1184 | Animation::TRANSFORM) |
| 1185 | : layer_tree_impl_->IsAnimatingTransformProperty(this); |
| 1186 | } |
| 1187 | |
| 1188 | bool LayerImpl::HasPotentiallyRunningTransformAnimation() const { |
| 1189 | if (layer_animation_controller_) { |
| 1190 | if (Animation* animation = |
| 1191 | layer_animation_controller()->GetAnimation(Animation::TRANSFORM)) { |
| 1192 | return !animation->is_finished(); |
| 1193 | } |
| 1194 | return false; |
| 1195 | } else { |
| 1196 | return layer_tree_impl_->HasPotentiallyRunningTransformAnimation(this); |
| 1197 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1198 | } |
| 1199 | |
[email protected] | 4361587 | 2013-03-13 16:35:17 | [diff] [blame] | 1200 | bool LayerImpl::TransformIsAnimatingOnImplOnly() const { |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1201 | if (!layer_animation_controller_) |
| 1202 | return layer_tree_impl_->TransformIsAnimatingOnImplOnly(this); |
| 1203 | |
[email protected] | 4361587 | 2013-03-13 16:35:17 | [diff] [blame] | 1204 | Animation* transform_animation = |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1205 | layer_animation_controller_->GetAnimation(Animation::TRANSFORM); |
[email protected] | 4361587 | 2013-03-13 16:35:17 | [diff] [blame] | 1206 | return transform_animation && transform_animation->is_impl_only(); |
| 1207 | } |
| 1208 | |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1209 | bool LayerImpl::HasOnlyTranslationTransforms() const { |
| 1210 | if (!layer_animation_controller_) |
| 1211 | return layer_tree_impl_->HasOnlyTranslationTransforms(this); |
| 1212 | |
| 1213 | return layer_animation_controller_->HasOnlyTranslationTransforms(); |
| 1214 | } |
| 1215 | |
| 1216 | bool LayerImpl::MaximumTargetScale(float* max_scale) const { |
| 1217 | if (!layer_animation_controller_) |
| 1218 | return layer_tree_impl_->MaximumTargetScale(this, max_scale); |
| 1219 | |
| 1220 | return layer_animation_controller_->MaximumTargetScale(max_scale); |
| 1221 | } |
| 1222 | |
| 1223 | bool LayerImpl::AnimationStartScale(float* start_scale) const { |
| 1224 | if (!layer_animation_controller_) |
| 1225 | return layer_tree_impl_->AnimationStartScale(this, start_scale); |
| 1226 | |
| 1227 | return layer_animation_controller_->AnimationStartScale(start_scale); |
| 1228 | } |
| 1229 | |
ajuma | e742527 | 2015-07-13 18:37:34 | [diff] [blame] | 1230 | bool LayerImpl::HasAnyAnimationTargetingProperty( |
| 1231 | Animation::TargetProperty property) const { |
| 1232 | if (!layer_animation_controller_) |
| 1233 | return layer_tree_impl_->HasAnyAnimationTargetingProperty(this, property); |
| 1234 | |
| 1235 | return !!layer_animation_controller_->GetAnimation(property); |
| 1236 | } |
| 1237 | |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1238 | bool LayerImpl::HasFilterAnimationThatInflatesBounds() const { |
| 1239 | if (!layer_animation_controller_) |
| 1240 | return layer_tree_impl_->HasFilterAnimationThatInflatesBounds(this); |
| 1241 | |
| 1242 | return layer_animation_controller_->HasFilterAnimationThatInflatesBounds(); |
| 1243 | } |
| 1244 | |
| 1245 | bool LayerImpl::HasTransformAnimationThatInflatesBounds() const { |
| 1246 | if (!layer_animation_controller_) |
| 1247 | return layer_tree_impl_->HasTransformAnimationThatInflatesBounds(this); |
| 1248 | |
| 1249 | return layer_animation_controller_->HasTransformAnimationThatInflatesBounds(); |
| 1250 | } |
| 1251 | |
| 1252 | bool LayerImpl::HasAnimationThatInflatesBounds() const { |
| 1253 | if (!layer_animation_controller_) |
| 1254 | return layer_tree_impl_->HasAnimationThatInflatesBounds(this); |
| 1255 | |
| 1256 | return layer_animation_controller_->HasAnimationThatInflatesBounds(); |
| 1257 | } |
| 1258 | |
| 1259 | bool LayerImpl::FilterAnimationBoundsForBox(const gfx::BoxF& box, |
| 1260 | gfx::BoxF* bounds) const { |
| 1261 | if (!layer_animation_controller_) |
| 1262 | return layer_tree_impl_->FilterAnimationBoundsForBox(this, box, bounds); |
| 1263 | |
| 1264 | return layer_animation_controller_->FilterAnimationBoundsForBox(box, bounds); |
| 1265 | } |
| 1266 | |
| 1267 | bool LayerImpl::TransformAnimationBoundsForBox(const gfx::BoxF& box, |
| 1268 | gfx::BoxF* bounds) const { |
| 1269 | if (!layer_animation_controller_) |
| 1270 | return layer_tree_impl_->TransformAnimationBoundsForBox(this, box, bounds); |
| 1271 | |
| 1272 | return layer_animation_controller_->TransformAnimationBoundsForBox(box, |
| 1273 | bounds); |
| 1274 | } |
| 1275 | |
danakj | 19f0c9e | 2014-10-11 03:24:42 | [diff] [blame] | 1276 | void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) { |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 1277 | update_rect_ = update_rect; |
| 1278 | SetNeedsPushProperties(); |
| 1279 | } |
| 1280 | |
[email protected] | cfa7fd92 | 2014-04-29 11:50:03 | [diff] [blame] | 1281 | void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) { |
| 1282 | damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect); |
| 1283 | } |
| 1284 | |
hush | b0ee8dc | 2015-06-10 00:48:57 | [diff] [blame] | 1285 | bool LayerImpl::IsExternalScrollActive() const { |
| 1286 | return layer_tree_impl_->IsExternalScrollActive(); |
[email protected] | 251699b | 2013-10-09 00:21:26 | [diff] [blame] | 1287 | } |
| 1288 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1289 | void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) { |
| 1290 | DCHECK(IsActive()); |
| 1291 | if (scroll_offset_->SetCurrent(scroll_offset)) |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 1292 | DidUpdateScrollOffset(false); |
| 1293 | } |
| 1294 | |
| 1295 | void LayerImpl::SetCurrentScrollOffsetFromDelegate( |
| 1296 | const gfx::ScrollOffset& scroll_offset) { |
| 1297 | DCHECK(IsActive()); |
| 1298 | if (scroll_offset_->SetCurrent(scroll_offset)) |
| 1299 | DidUpdateScrollOffset(true); |
boliu | 7d5dbab | 2014-10-10 20:05:47 | [diff] [blame] | 1300 | } |
| 1301 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1302 | void LayerImpl::PushScrollOffsetFromMainThread( |
| 1303 | const gfx::ScrollOffset& scroll_offset) { |
| 1304 | PushScrollOffset(&scroll_offset); |
[email protected] | b34c9798 | 2013-08-24 15:21:38 | [diff] [blame] | 1305 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1306 | |
danakj | b5197d3 | 2015-02-03 23:39:49 | [diff] [blame] | 1307 | void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue( |
| 1308 | const gfx::ScrollOffset& scroll_offset) { |
| 1309 | scroll_offset_->set_clobber_active_value(); |
| 1310 | PushScrollOffset(&scroll_offset); |
| 1311 | } |
| 1312 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1313 | gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() { |
miletus | d799dd2 | 2015-03-19 04:23:17 | [diff] [blame] | 1314 | // TODO(miletus): Remove all this temporary flooring machinery when |
| 1315 | // Blink fully supports fractional scrolls. |
| 1316 | gfx::ScrollOffset current_offset = CurrentScrollOffset(); |
bokan | 5a025bd6 | 2015-07-20 11:08:20 | [diff] [blame^] | 1317 | gfx::ScrollOffset current_delta = IsActive() |
| 1318 | ? scroll_offset_->Delta() |
| 1319 | : scroll_offset_->PendingDelta().get(); |
| 1320 | gfx::ScrollOffset floored_delta(floor(current_delta.x()), |
| 1321 | floor(current_delta.y())); |
| 1322 | gfx::ScrollOffset diff_delta = floored_delta - current_delta; |
| 1323 | gfx::ScrollOffset tmp_offset = current_offset + diff_delta; |
miletus | d799dd2 | 2015-03-19 04:23:17 | [diff] [blame] | 1324 | scroll_offset_->SetCurrent(tmp_offset); |
| 1325 | gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread(); |
| 1326 | scroll_offset_->SetCurrent(current_offset); |
| 1327 | return delta; |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1328 | } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1329 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1330 | gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const { |
| 1331 | return scroll_offset_->Current(IsActive()); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1332 | } |
| 1333 | |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 1334 | gfx::Vector2dF LayerImpl::ScrollDelta() const { |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1335 | if (IsActive()) |
| 1336 | return gfx::Vector2dF(scroll_offset_->Delta().x(), |
| 1337 | scroll_offset_->Delta().y()); |
| 1338 | else |
| 1339 | return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(), |
| 1340 | scroll_offset_->PendingDelta().get().y()); |
| 1341 | } |
| 1342 | |
| 1343 | void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) { |
| 1344 | DCHECK(IsActive()); |
ajuma | 5e47dec | 2015-05-29 22:10:23 | [diff] [blame] | 1345 | DCHECK(scrollable() || delta.IsZero()); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1346 | SetCurrentScrollOffset(scroll_offset_->ActiveBase() + |
| 1347 | gfx::ScrollOffset(delta)); |
| 1348 | } |
| 1349 | |
| 1350 | gfx::ScrollOffset LayerImpl::BaseScrollOffset() const { |
| 1351 | if (IsActive()) |
| 1352 | return scroll_offset_->ActiveBase(); |
| 1353 | else |
| 1354 | return scroll_offset_->PendingBase(); |
| 1355 | } |
| 1356 | |
| 1357 | void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) { |
| 1358 | DCHECK(scroll_offset || IsActive()); |
| 1359 | bool changed = false; |
| 1360 | if (scroll_offset) { |
| 1361 | DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id())); |
| 1362 | changed |= scroll_offset_->PushFromMainThread(*scroll_offset); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1363 | } |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1364 | if (IsActive()) { |
| 1365 | changed |= scroll_offset_->PushPendingToActive(); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1366 | } |
| 1367 | |
| 1368 | if (changed) |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 1369 | DidUpdateScrollOffset(false); |
[email protected] | 1960a71 | 2013-04-30 17:06:47 | [diff] [blame] | 1370 | } |
| 1371 | |
ajuma | 9db24fb | 2015-06-29 20:15:07 | [diff] [blame] | 1372 | void LayerImpl::UpdatePropertyTreeScrollOffset() { |
enne | 1eb3a92 | 2015-06-17 17:37:50 | [diff] [blame] | 1373 | // TODO(enne): in the future, scrolling should update the scroll tree |
| 1374 | // directly instead of going through layers. |
| 1375 | if (transform_tree_index_ != -1) { |
| 1376 | TransformTree& transform_tree = |
| 1377 | layer_tree_impl()->property_trees()->transform_tree; |
| 1378 | TransformNode* node = transform_tree.Node(transform_tree_index_); |
| 1379 | gfx::ScrollOffset current_offset = scroll_offset_->Current(IsActive()); |
| 1380 | if (node->data.scroll_offset != current_offset) { |
| 1381 | node->data.scroll_offset = current_offset; |
| 1382 | node->data.needs_local_transform_update = true; |
| 1383 | transform_tree.set_needs_update(true); |
| 1384 | } |
| 1385 | } |
| 1386 | } |
| 1387 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 1388 | void LayerImpl::DidUpdateScrollOffset(bool is_from_root_delegate) { |
enne | 04192cf9 | 2015-05-20 00:32:22 | [diff] [blame] | 1389 | DCHECK(scroll_offset_); |
| 1390 | |
hush | 33370e1 | 2015-04-07 03:49:50 | [diff] [blame] | 1391 | if (!is_from_root_delegate) |
| 1392 | layer_tree_impl()->DidUpdateScrollOffset(id()); |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1393 | NoteLayerPropertyChangedForSubtree(); |
| 1394 | ScrollbarParametersDidChange(false); |
enne | 04192cf9 | 2015-05-20 00:32:22 | [diff] [blame] | 1395 | |
ajuma | 9db24fb | 2015-06-29 20:15:07 | [diff] [blame] | 1396 | UpdatePropertyTreeScrollOffset(); |
enne | 04192cf9 | 2015-05-20 00:32:22 | [diff] [blame] | 1397 | |
vmpstr | e8624082 | 2015-05-11 21:10:11 | [diff] [blame] | 1398 | // Inform the pending twin that a property changed. |
| 1399 | if (layer_tree_impl()->IsActiveTree()) { |
| 1400 | LayerImpl* pending_twin = layer_tree_impl()->FindPendingTreeLayerById(id()); |
| 1401 | if (pending_twin) |
enne | 04192cf9 | 2015-05-20 00:32:22 | [diff] [blame] | 1402 | pending_twin->DidUpdateScrollOffset(is_from_root_delegate); |
vmpstr | e8624082 | 2015-05-11 21:10:11 | [diff] [blame] | 1403 | } |
[email protected] | ffb2720f | 2013-03-15 19:18:37 | [diff] [blame] | 1404 | } |
| 1405 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1406 | void LayerImpl::SetDoubleSided(bool double_sided) { |
| 1407 | if (double_sided_ == double_sided) |
| 1408 | return; |
| 1409 | |
| 1410 | double_sided_ = double_sided; |
| 1411 | NoteLayerPropertyChangedForSubtree(); |
| 1412 | } |
| 1413 | |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 1414 | SimpleEnclosedRegion LayerImpl::VisibleOpaqueRegion() const { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1415 | if (contents_opaque()) |
danakj | 64767d90 | 2015-06-19 00:10:43 | [diff] [blame] | 1416 | return SimpleEnclosedRegion(visible_layer_rect()); |
[email protected] | d5467eb7 | 2014-08-22 01:16:43 | [diff] [blame] | 1417 | return SimpleEnclosedRegion(); |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1418 | } |
| 1419 | |
[email protected] | 37349bc | 2013-06-04 01:31:52 | [diff] [blame] | 1420 | void LayerImpl::DidBeginTracing() {} |
| 1421 | |
[email protected] | 9db2446 | 2014-01-14 02:25:50 | [diff] [blame] | 1422 | void LayerImpl::ReleaseResources() {} |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1423 | |
vmpstr | 9ce5c66 | 2015-02-05 23:29:26 | [diff] [blame] | 1424 | void LayerImpl::RecreateResources() { |
| 1425 | } |
| 1426 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1427 | gfx::ScrollOffset LayerImpl::MaxScrollOffset() const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1428 | if (!scroll_clip_layer_ || bounds().IsEmpty()) |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1429 | return gfx::ScrollOffset(); |
[email protected] | 610834cb | 2014-01-29 13:54:33 | [diff] [blame] | 1430 | |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 1431 | LayerImpl const* page_scale_layer = layer_tree_impl()->PageScaleLayer(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1432 | DCHECK(this != page_scale_layer); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1433 | DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() || |
| 1434 | IsContainerForFixedPositionLayers()); |
| 1435 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1436 | float scale_factor = 1.f; |
| 1437 | for (LayerImpl const* current_layer = this; |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1438 | current_layer != scroll_clip_layer_->parent(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1439 | current_layer = current_layer->parent()) { |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1440 | if (current_layer == page_scale_layer) |
| 1441 | scale_factor = layer_tree_impl()->current_page_scale_factor(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1442 | } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1443 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1444 | gfx::SizeF scaled_scroll_bounds = |
| 1445 | gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor)); |
[email protected] | 0072c11 | 2014-04-22 05:53:40 | [diff] [blame] | 1446 | scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1447 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1448 | gfx::ScrollOffset max_offset( |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1449 | scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(), |
| 1450 | scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height()); |
| 1451 | // We need the final scroll offset to be in CSS coords. |
| 1452 | max_offset.Scale(1 / scale_factor); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1453 | max_offset.SetToMax(gfx::ScrollOffset()); |
| 1454 | return max_offset; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1455 | } |
| 1456 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1457 | gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits( |
| 1458 | gfx::ScrollOffset offset) const { |
| 1459 | offset.SetToMin(MaxScrollOffset()); |
| 1460 | offset.SetToMax(gfx::ScrollOffset()); |
| 1461 | return offset; |
| 1462 | } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1463 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1464 | gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() { |
| 1465 | gfx::ScrollOffset old_offset = CurrentScrollOffset(); |
| 1466 | gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset); |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1467 | gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1468 | if (!delta.IsZero()) |
| 1469 | ScrollBy(delta); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1470 | return delta; |
| 1471 | } |
| 1472 | |
| 1473 | void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer, |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 1474 | LayerImpl* scrollbar_clip_layer, |
| 1475 | bool on_resize) const { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1476 | DCHECK(scrollbar_layer); |
aelias | c26b50b7 | 2015-07-14 20:18:25 | [diff] [blame] | 1477 | LayerImpl* page_scale_layer = layer_tree_impl()->PageScaleLayer(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1478 | |
| 1479 | DCHECK(this != page_scale_layer); |
| 1480 | DCHECK(scrollbar_clip_layer); |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 1481 | gfx::RectF clip_rect(gfx::PointF(), |
| 1482 | scrollbar_clip_layer->BoundsForScrolling()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1483 | |
| 1484 | // See comment in MaxScrollOffset() regarding the use of the content layer |
| 1485 | // bounds here. |
bokan | ef97146 | 2014-10-13 22:58:32 | [diff] [blame] | 1486 | gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1487 | |
| 1488 | if (scroll_rect.size().IsEmpty()) |
| 1489 | return; |
| 1490 | |
miletus | f57925d | 2014-10-01 19:38:13 | [diff] [blame] | 1491 | gfx::ScrollOffset current_offset; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1492 | for (LayerImpl const* current_layer = this; |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1493 | current_layer != scrollbar_clip_layer->parent(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1494 | current_layer = current_layer->parent()) { |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1495 | current_offset += current_layer->CurrentScrollOffset(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1496 | if (current_layer == page_scale_layer) { |
aelias | 58eec081 | 2014-12-04 01:04:40 | [diff] [blame] | 1497 | float scale_factor = layer_tree_impl()->current_page_scale_factor(); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1498 | current_offset.Scale(scale_factor); |
| 1499 | scroll_rect.Scale(scale_factor); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1500 | } |
| 1501 | } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1502 | |
sataya.m | 68d7d9b4 | 2014-09-22 16:01:59 | [diff] [blame] | 1503 | bool scrollbar_needs_animation = false; |
| 1504 | scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust( |
| 1505 | scrollbar_clip_layer->bounds_delta().y()); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1506 | if (scrollbar_layer->orientation() == HORIZONTAL) { |
| 1507 | float visible_ratio = clip_rect.width() / scroll_rect.width(); |
sataya.m | 68d7d9b4 | 2014-09-22 16:01:59 | [diff] [blame] | 1508 | scrollbar_needs_animation |= |
| 1509 | scrollbar_layer->SetCurrentPos(current_offset.x()); |
| 1510 | scrollbar_needs_animation |= |
| 1511 | scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width()); |
| 1512 | scrollbar_needs_animation |= |
| 1513 | scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio); |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1514 | } else { |
| 1515 | float visible_ratio = clip_rect.height() / scroll_rect.height(); |
wjmaclean | 56f35ff | 2015-03-25 23:59:35 | [diff] [blame] | 1516 | bool y_offset_did_change = |
sataya.m | 68d7d9b4 | 2014-09-22 16:01:59 | [diff] [blame] | 1517 | scrollbar_layer->SetCurrentPos(current_offset.y()); |
wjmaclean | 56f35ff | 2015-03-25 23:59:35 | [diff] [blame] | 1518 | scrollbar_needs_animation |= y_offset_did_change; |
sataya.m | 68d7d9b4 | 2014-09-22 16:01:59 | [diff] [blame] | 1519 | scrollbar_needs_animation |= |
| 1520 | scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height()); |
| 1521 | scrollbar_needs_animation |= |
| 1522 | scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio); |
wjmaclean | 56f35ff | 2015-03-25 23:59:35 | [diff] [blame] | 1523 | if (y_offset_did_change && layer_tree_impl()->IsActiveTree() && |
| 1524 | this == layer_tree_impl()->InnerViewportScrollLayer()) { |
| 1525 | TRACE_COUNTER_ID1("cc", "scroll_offset_y", this->id(), |
| 1526 | current_offset.y()); |
| 1527 | } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1528 | } |
sataya.m | 7acc4b3 | 2014-09-23 15:37:21 | [diff] [blame] | 1529 | if (scrollbar_needs_animation) { |
| 1530 | layer_tree_impl()->set_needs_update_draw_properties(); |
| 1531 | // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars |
| 1532 | // should activate for every scroll on the main frame, not just the |
| 1533 | // scrolls that move the pinch virtual viewport (i.e. trigger from |
| 1534 | // either inner or outer viewport). |
| 1535 | if (scrollbar_animation_controller_) { |
bokan | c784a6f | 2015-01-28 04:11:50 | [diff] [blame] | 1536 | // Non-overlay scrollbars shouldn't trigger animations. |
| 1537 | if (scrollbar_layer->is_overlay_scrollbar()) |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 1538 | scrollbar_animation_controller_->DidScrollUpdate(on_resize); |
sataya.m | 7acc4b3 | 2014-09-23 15:37:21 | [diff] [blame] | 1539 | } |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1540 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1541 | } |
| 1542 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1543 | void LayerImpl::DidBecomeActive() { |
[email protected] | fea16187 | 2013-08-27 22:34:59 | [diff] [blame] | 1544 | if (layer_tree_impl_->settings().scrollbar_animator == |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1545 | LayerTreeSettings::NO_ANIMATOR) { |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1546 | return; |
[email protected] | fea16187 | 2013-08-27 22:34:59 | [diff] [blame] | 1547 | } |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1548 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1549 | bool need_scrollbar_animation_controller = scrollable() && scrollbars_; |
[email protected] | fea16187 | 2013-08-27 22:34:59 | [diff] [blame] | 1550 | if (!need_scrollbar_animation_controller) { |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 1551 | scrollbar_animation_controller_ = nullptr; |
[email protected] | fea16187 | 2013-08-27 22:34:59 | [diff] [blame] | 1552 | return; |
| 1553 | } |
| 1554 | |
| 1555 | if (scrollbar_animation_controller_) |
| 1556 | return; |
| 1557 | |
[email protected] | 930ff43b | 2014-05-02 05:24:00 | [diff] [blame] | 1558 | scrollbar_animation_controller_ = |
| 1559 | layer_tree_impl_->CreateScrollbarAnimationController(this); |
[email protected] | e45638c | 2013-01-17 22:01:40 | [diff] [blame] | 1560 | } |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 1561 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1562 | void LayerImpl::ClearScrollbars() { |
| 1563 | if (!scrollbars_) |
| 1564 | return; |
| 1565 | |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 1566 | scrollbars_.reset(nullptr); |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1567 | } |
| 1568 | |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1569 | void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) { |
| 1570 | DCHECK(layer); |
| 1571 | DCHECK(!scrollbars_ || scrollbars_->find(layer) == scrollbars_->end()); |
| 1572 | if (!scrollbars_) |
| 1573 | scrollbars_.reset(new ScrollbarSet()); |
| 1574 | |
| 1575 | scrollbars_->insert(layer); |
| 1576 | } |
| 1577 | |
| 1578 | void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) { |
| 1579 | DCHECK(scrollbars_); |
| 1580 | DCHECK(layer); |
| 1581 | DCHECK(scrollbars_->find(layer) != scrollbars_->end()); |
| 1582 | |
| 1583 | scrollbars_->erase(layer); |
| 1584 | if (scrollbars_->empty()) |
danakj | f446a07 | 2014-09-27 21:55:48 | [diff] [blame] | 1585 | scrollbars_ = nullptr; |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1586 | } |
| 1587 | |
| 1588 | bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const { |
| 1589 | if (!scrollbars_) |
| 1590 | return false; |
| 1591 | |
| 1592 | for (ScrollbarSet::iterator it = scrollbars_->begin(); |
| 1593 | it != scrollbars_->end(); |
| 1594 | ++it) |
| 1595 | if ((*it)->orientation() == orientation) |
| 1596 | return true; |
| 1597 | |
| 1598 | return false; |
| 1599 | } |
| 1600 | |
sataya.m | 07f11a8 | 2014-10-07 14:29:18 | [diff] [blame] | 1601 | void LayerImpl::ScrollbarParametersDidChange(bool on_resize) { |
[email protected] | adeda57 | 2014-01-31 00:49:47 | [diff] [blame] | 1602 | if (!scrollbars_) |
| 1603 | return; |
| 1604 | |
| 1605 | for (ScrollbarSet::iterator it = scrollbars_->begin(); |
| 1606 | it != scrollbars_->end(); |
aelias | 1505e72 | 2014-10-07 22:19:46 | [diff] [blame] | 1607 | ++it) { |
| 1608 | bool is_scroll_layer = (*it)->ScrollLayerId() == layer_id_; |
| 1609 | bool scroll_layer_resized = is_scroll_layer && on_resize; |
| 1610 | (*it)->ScrollbarParametersDidChange(scroll_layer_resized); |
| 1611 | } |
[email protected] | 94f206c1 | 2012-08-25 00:09:14 | [diff] [blame] | 1612 | } |
| 1613 | |
[email protected] | ad0250b | 2014-01-18 03:24:34 | [diff] [blame] | 1614 | void LayerImpl::SetNeedsPushProperties() { |
| 1615 | if (needs_push_properties_) |
| 1616 | return; |
| 1617 | if (!parent_should_know_need_push_properties() && parent_) |
| 1618 | parent_->AddDependentNeedsPushProperties(); |
| 1619 | needs_push_properties_ = true; |
| 1620 | } |
| 1621 | |
| 1622 | void LayerImpl::AddDependentNeedsPushProperties() { |
| 1623 | DCHECK_GE(num_dependents_need_push_properties_, 0); |
| 1624 | |
| 1625 | if (!parent_should_know_need_push_properties() && parent_) |
| 1626 | parent_->AddDependentNeedsPushProperties(); |
| 1627 | |
| 1628 | num_dependents_need_push_properties_++; |
| 1629 | } |
| 1630 | |
| 1631 | void LayerImpl::RemoveDependentNeedsPushProperties() { |
| 1632 | num_dependents_need_push_properties_--; |
| 1633 | DCHECK_GE(num_dependents_need_push_properties_, 0); |
| 1634 | |
| 1635 | if (!parent_should_know_need_push_properties() && parent_) |
| 1636 | parent_->RemoveDependentNeedsPushProperties(); |
| 1637 | } |
| 1638 | |
hendrikw | c5e91585 | 2015-05-13 01:29:03 | [diff] [blame] | 1639 | void LayerImpl::GetAllPrioritizedTilesForTracing( |
| 1640 | std::vector<PrioritizedTile>* prioritized_tiles) const { |
vmpstr | d7de03c | 2014-08-27 18:11:01 | [diff] [blame] | 1641 | } |
| 1642 | |
ssid | 911e40e | 2015-02-09 17:55:20 | [diff] [blame] | 1643 | void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const { |
[email protected] | f5ad428 | 2014-02-15 14:23:16 | [diff] [blame] | 1644 | TracedValue::MakeDictIntoImplicitSnapshotWithCategory( |
| 1645 | TRACE_DISABLED_BY_DEFAULT("cc.debug"), |
[email protected] | b4dc3647 | 2014-02-26 02:48:25 | [diff] [blame] | 1646 | state, |
| 1647 | "cc::LayerImpl", |
| 1648 | LayerTypeAsString(), |
| 1649 | this); |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 1650 | state->SetInteger("layer_id", id()); |
jungjik.lee | 50f9c8e | 2015-01-21 14:06:16 | [diff] [blame] | 1651 | MathUtil::AddToTracedValue("bounds", bounds_, state); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1652 | |
danakj | 3895556 | 2014-09-13 02:56:43 | [diff] [blame] | 1653 | state->SetDouble("opacity", opacity()); |
| 1654 | |
jungjik.lee | 50f9c8e | 2015-01-21 14:06:16 | [diff] [blame] | 1655 | MathUtil::AddToTracedValue("position", position_, state); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1656 | |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 1657 | state->SetInteger("draws_content", DrawsContent()); |
vmpstr | 91e2309 | 2015-06-08 22:24:16 | [diff] [blame] | 1658 | state->SetInteger("gpu_memory_usage", |
| 1659 | base::saturated_cast<int>(GPUMemoryUsageInBytes())); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1660 | |
aelias | d0070ba | 2015-01-31 13:44:49 | [diff] [blame] | 1661 | MathUtil::AddToTracedValue( |
| 1662 | "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive()) |
| 1663 | : gfx::ScrollOffset(), |
| 1664 | state); |
| 1665 | |
jungjik.lee | 50f9c8e | 2015-01-21 14:06:16 | [diff] [blame] | 1666 | MathUtil::AddToTracedValue("transform_origin", transform_origin_, state); |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 1667 | |
[email protected] | 7aba666 | 2013-03-12 10:17:34 | [diff] [blame] | 1668 | bool clipped; |
[email protected] | fa816c6 | 2013-03-18 04:24:21 | [diff] [blame] | 1669 | gfx::QuadF layer_quad = MathUtil::MapQuad( |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 1670 | screen_space_transform(), gfx::QuadF(gfx::Rect(bounds())), &clipped); |
jungjik.lee | 50f9c8e | 2015-01-21 14:06:16 | [diff] [blame] | 1671 | MathUtil::AddToTracedValue("layer_quad", layer_quad, state); |
[email protected] | 78d7861 | 2013-09-12 18:04:04 | [diff] [blame] | 1672 | if (!touch_event_handler_region_.IsEmpty()) { |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1673 | state->BeginArray("touch_event_handler_region"); |
| 1674 | touch_event_handler_region_.AsValueInto(state); |
| 1675 | state->EndArray(); |
[email protected] | 78d7861 | 2013-09-12 18:04:04 | [diff] [blame] | 1676 | } |
| 1677 | if (have_wheel_event_handlers_) { |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 1678 | gfx::Rect wheel_rect(bounds()); |
[email protected] | 78d7861 | 2013-09-12 18:04:04 | [diff] [blame] | 1679 | Region wheel_region(wheel_rect); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1680 | state->BeginArray("wheel_event_handler_region"); |
| 1681 | wheel_region.AsValueInto(state); |
| 1682 | state->EndArray(); |
[email protected] | 78d7861 | 2013-09-12 18:04:04 | [diff] [blame] | 1683 | } |
[email protected] | f998c53 | 2014-03-31 20:02:51 | [diff] [blame] | 1684 | if (have_scroll_event_handlers_) { |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 1685 | gfx::Rect scroll_rect(bounds()); |
[email protected] | f998c53 | 2014-03-31 20:02:51 | [diff] [blame] | 1686 | Region scroll_region(scroll_rect); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1687 | state->BeginArray("scroll_event_handler_region"); |
| 1688 | scroll_region.AsValueInto(state); |
| 1689 | state->EndArray(); |
[email protected] | f998c53 | 2014-03-31 20:02:51 | [diff] [blame] | 1690 | } |
[email protected] | 78d7861 | 2013-09-12 18:04:04 | [diff] [blame] | 1691 | if (!non_fast_scrollable_region_.IsEmpty()) { |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1692 | state->BeginArray("non_fast_scrollable_region"); |
| 1693 | non_fast_scrollable_region_.AsValueInto(state); |
| 1694 | state->EndArray(); |
[email protected] | 78d7861 | 2013-09-12 18:04:04 | [diff] [blame] | 1695 | } |
rbyers | 18779d82 | 2015-02-05 06:22:06 | [diff] [blame] | 1696 | if (scroll_blocks_on_) { |
| 1697 | state->SetInteger("scroll_blocks_on", scroll_blocks_on_); |
| 1698 | } |
[email protected] | f6742f5 | 2013-05-08 23:52:22 | [diff] [blame] | 1699 | |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1700 | state->BeginArray("children"); |
| 1701 | for (size_t i = 0; i < children_.size(); ++i) { |
| 1702 | state->BeginDictionary(); |
| 1703 | children_[i]->AsValueInto(state); |
| 1704 | state->EndDictionary(); |
| 1705 | } |
| 1706 | state->EndArray(); |
| 1707 | if (mask_layer_) { |
| 1708 | state->BeginDictionary("mask_layer"); |
| 1709 | mask_layer_->AsValueInto(state); |
| 1710 | state->EndDictionary(); |
| 1711 | } |
| 1712 | if (replica_layer_) { |
| 1713 | state->BeginDictionary("replica_layer"); |
| 1714 | replica_layer_->AsValueInto(state); |
| 1715 | state->EndDictionary(); |
| 1716 | } |
[email protected] | 0e98cdd | 2013-08-23 00:44:30 | [diff] [blame] | 1717 | |
| 1718 | if (scroll_parent_) |
| 1719 | state->SetInteger("scroll_parent", scroll_parent_->id()); |
| 1720 | |
| 1721 | if (clip_parent_) |
| 1722 | state->SetInteger("clip_parent", clip_parent_->id()); |
[email protected] | c2a56ff | 2013-10-14 19:32:51 | [diff] [blame] | 1723 | |
| 1724 | state->SetBoolean("can_use_lcd_text", can_use_lcd_text()); |
| 1725 | state->SetBoolean("contents_opaque", contents_opaque()); |
[email protected] | a128674 | 2013-11-13 17:11:40 | [diff] [blame] | 1726 | |
[email protected] | 3d86dd7a | 2014-01-24 01:33:11 | [diff] [blame] | 1727 | state->SetBoolean( |
| 1728 | "has_animation_bounds", |
loyso | d71ece8 | 2015-07-03 13:48:50 | [diff] [blame] | 1729 | layer_animation_controller_ |
| 1730 | ? layer_animation_controller_->HasAnimationThatInflatesBounds() |
| 1731 | : layer_tree_impl_->HasAnimationThatInflatesBounds(this)); |
[email protected] | 3d86dd7a | 2014-01-24 01:33:11 | [diff] [blame] | 1732 | |
| 1733 | gfx::BoxF box; |
jungjik.lee | 50f9c8e | 2015-01-21 14:06:16 | [diff] [blame] | 1734 | if (LayerUtils::GetAnimationBounds(*this, &box)) |
| 1735 | MathUtil::AddToTracedValue("animation_bounds", box, state); |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 1736 | |
| 1737 | if (debug_info_.get()) { |
| 1738 | std::string str; |
| 1739 | debug_info_->AppendAsTraceFormat(&str); |
| 1740 | base::JSONReader json_reader; |
[email protected] | 685de6b1 | 2014-01-09 12:25:05 | [diff] [blame] | 1741 | scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str)); |
| 1742 | |
[email protected] | 47822431 | 2014-01-10 17:33:47 | [diff] [blame] | 1743 | if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) { |
kulkarni.a | 4015690f1 | 2014-10-10 13:50:06 | [diff] [blame] | 1744 | base::DictionaryValue* dictionary_value = nullptr; |
[email protected] | 685de6b1 | 2014-01-09 12:25:05 | [diff] [blame] | 1745 | bool converted_to_dictionary = |
| 1746 | debug_info_value->GetAsDictionary(&dictionary_value); |
| 1747 | DCHECK(converted_to_dictionary); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1748 | for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd(); |
| 1749 | it.Advance()) { |
estade | 7bc801fb | 2015-05-07 01:53:08 | [diff] [blame] | 1750 | state->SetValue(it.key().data(), it.value().CreateDeepCopy()); |
[email protected] | d12aa93 | 2014-08-01 13:10:38 | [diff] [blame] | 1751 | } |
[email protected] | 685de6b1 | 2014-01-09 12:25:05 | [diff] [blame] | 1752 | } else { |
| 1753 | NOTREACHED(); |
| 1754 | } |
[email protected] | 9f3be43 | 2013-12-03 03:53:22 | [diff] [blame] | 1755 | } |
vmpstr | 3d1d72c | 2015-01-26 18:27:40 | [diff] [blame] | 1756 | |
| 1757 | if (!frame_timing_requests_.empty()) { |
| 1758 | state->BeginArray("frame_timing_requests"); |
| 1759 | for (const auto& request : frame_timing_requests_) { |
| 1760 | state->BeginDictionary(); |
| 1761 | state->SetInteger("request_id", request.id()); |
| 1762 | MathUtil::AddToTracedValue("request_rect", request.rect(), state); |
| 1763 | state->EndDictionary(); |
| 1764 | } |
| 1765 | state->EndArray(); |
| 1766 | } |
[email protected] | 8c569022 | 2013-02-15 17:36:43 | [diff] [blame] | 1767 | } |
| 1768 | |
[email protected] | 390bb1ff | 2014-05-09 17:14:40 | [diff] [blame] | 1769 | bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const { |
| 1770 | return draw_properties_.last_drawn_render_surface_layer_list_id == |
| 1771 | layer_tree_impl_->current_render_surface_list_id(); |
| 1772 | } |
| 1773 | |
[email protected] | cdf5b95 | 2013-05-15 15:39:29 | [diff] [blame] | 1774 | size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; } |
| 1775 | |
[email protected] | 5e5648a | 2013-11-18 00:39:33 | [diff] [blame] | 1776 | void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) { |
| 1777 | benchmark->RunOnLayer(this); |
| 1778 | } |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 1779 | |
[email protected] | ad63b2f | 2014-08-11 17:39:54 | [diff] [blame] | 1780 | int LayerImpl::NumDescendantsThatDrawContent() const { |
| 1781 | return num_descendants_that_draw_content_; |
| 1782 | } |
| 1783 | |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 1784 | void LayerImpl::NotifyAnimationFinished( |
| 1785 | base::TimeTicks monotonic_time, |
dstockwell | af2a117b | 2014-10-16 21:42:29 | [diff] [blame] | 1786 | Animation::TargetProperty target_property, |
| 1787 | int group) { |
ericrk | 7c03099 | 2015-02-20 01:39:38 | [diff] [blame] | 1788 | if (target_property == Animation::SCROLL_OFFSET) |
[email protected] | 749cbc6 | 2014-07-10 01:06:35 | [diff] [blame] | 1789 | layer_tree_impl_->InputScrollAnimationFinished(); |
| 1790 | } |
| 1791 | |
awoloszyn | e83f28c | 2014-12-22 15:40:00 | [diff] [blame] | 1792 | void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) { |
| 1793 | if (!!render_surface() == should_have_render_surface) |
| 1794 | return; |
| 1795 | |
| 1796 | SetNeedsPushProperties(); |
| 1797 | layer_tree_impl()->set_needs_update_draw_properties(); |
| 1798 | if (should_have_render_surface) { |
| 1799 | render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this)); |
| 1800 | return; |
| 1801 | } |
| 1802 | render_surface_.reset(); |
| 1803 | } |
| 1804 | |
daplatz | 350219e | 2015-03-04 19:04:41 | [diff] [blame] | 1805 | Region LayerImpl::GetInvalidationRegion() { |
| 1806 | return Region(update_rect_); |
| 1807 | } |
| 1808 | |
vmpstr | d46a7ac | 2015-03-18 01:11:12 | [diff] [blame] | 1809 | gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const { |
| 1810 | return MathUtil::MapEnclosingClippedRect( |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 1811 | draw_properties_.target_space_transform, gfx::Rect(bounds())); |
vmpstr | d46a7ac | 2015-03-18 01:11:12 | [diff] [blame] | 1812 | } |
| 1813 | |
| 1814 | gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const { |
| 1815 | gfx::Transform scaled_draw_transform = |
| 1816 | draw_properties_.target_space_transform; |
| 1817 | scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale); |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 1818 | gfx::Size scaled_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale)); |
vmpstr | d46a7ac | 2015-03-18 01:11:12 | [diff] [blame] | 1819 | return MathUtil::MapEnclosingClippedRect(scaled_draw_transform, |
Dana Jansens | c46d374 | 2015-06-18 01:33:14 | [diff] [blame] | 1820 | gfx::Rect(scaled_bounds)); |
vmpstr | d46a7ac | 2015-03-18 01:11:12 | [diff] [blame] | 1821 | } |
| 1822 | |
enne | 63771573 | 2015-07-07 02:05:26 | [diff] [blame] | 1823 | float LayerImpl::GetIdealContentsScale() const { |
| 1824 | float page_scale = IsAffectedByPageScale() |
| 1825 | ? layer_tree_impl()->current_page_scale_factor() |
| 1826 | : 1.f; |
| 1827 | float device_scale = layer_tree_impl()->device_scale_factor(); |
| 1828 | |
| 1829 | float default_scale = page_scale * device_scale; |
| 1830 | if (!layer_tree_impl() |
| 1831 | ->settings() |
| 1832 | .layer_transforms_should_scale_layer_contents) { |
| 1833 | return default_scale; |
| 1834 | } |
| 1835 | |
| 1836 | // TODO(enne): the transform needs to come from property trees instead of |
| 1837 | // draw properties. |
| 1838 | gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents( |
| 1839 | draw_properties().target_space_transform, default_scale); |
| 1840 | return std::max(transform_scales.x(), transform_scales.y()); |
| 1841 | } |
| 1842 | |
[email protected] | bc5e77c | 2012-11-05 20:00:49 | [diff] [blame] | 1843 | } // namespace cc |