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