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