blob: 379db37e2bf0b4c0f600305a87f23cc0e405cbdc [file] [log] [blame]
[email protected]5e5648a2013-11-18 00:39:331// Copyright 2012 The Chromium Authors. All rights reserved.
[email protected]94f206c12012-08-25 00:09:142// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]cc3cfaa2013-03-18 09:05:525#include "cc/layers/layer_impl.h"
[email protected]94f206c12012-08-25 00:09:146
[email protected]9f3be432013-12-03 03:53:227#include "base/json/json_reader.h"
vmpstr91e23092015-06-08 22:24:168#include "base/numerics/safe_conversions.h"
[email protected]8e61d4b2013-06-10 22:11:489#include "base/strings/stringprintf.h"
primianoc06e2382015-01-28 04:21:4910#include "base/trace_event/trace_event.h"
11#include "base/trace_event/trace_event_argument.h"
[email protected]95e4e1a02013-03-18 07:09:0912#include "cc/animation/animation_registrar.h"
13#include "cc/animation/scrollbar_animation_controller.h"
[email protected]681ccff2013-03-18 06:13:5214#include "cc/base/math_util.h"
[email protected]d5467eb72014-08-22 01:16:4315#include "cc/base/simple_enclosed_region.h"
[email protected]6e84de22013-03-18 06:54:2716#include "cc/debug/debug_colors.h"
17#include "cc/debug/layer_tree_debug_state.h"
[email protected]5e5648a2013-11-18 00:39:3318#include "cc/debug/micro_benchmark_impl.h"
[email protected]f6742f52013-05-08 23:52:2219#include "cc/debug/traced_value.h"
tdresserd9e201472015-07-31 13:15:0720#include "cc/input/scroll_state.h"
[email protected]3d86dd7a2014-01-24 01:33:1121#include "cc/layers/layer_utils.h"
[email protected]3a83478b2013-08-22 20:55:1722#include "cc/layers/painted_scrollbar_layer_impl.h"
[email protected]0e5f7142013-05-24 06:45:3623#include "cc/output/copy_output_request.h"
[email protected]89e8267a2013-03-18 07:50:5624#include "cc/quads/debug_border_draw_quad.h"
[email protected]0cd7d6f72014-08-22 14:50:5125#include "cc/quads/render_pass.h"
[email protected]3d86dd7a2014-01-24 01:33:1126#include "cc/trees/layer_tree_host_common.h"
[email protected]556fd292013-03-18 08:03:0427#include "cc/trees/layer_tree_impl.h"
28#include "cc/trees/layer_tree_settings.h"
29#include "cc/trees/proxy.h"
heejin.r.chungd28506ba2014-10-23 16:36:2030#include "ui/gfx/geometry/box_f.h"
31#include "ui/gfx/geometry/point_conversions.h"
32#include "ui/gfx/geometry/quad_f.h"
33#include "ui/gfx/geometry/rect_conversions.h"
34#include "ui/gfx/geometry/size_conversions.h"
[email protected]adeda572014-01-31 00:49:4735#include "ui/gfx/geometry/vector2d_conversions.h"
[email protected]94f206c12012-08-25 00:09:1436
[email protected]9c88e562012-09-14 22:21:3037namespace cc {
aeliasd0070ba2015-01-31 13:44:4938LayerImpl::LayerImpl(LayerTreeImpl* layer_impl, int id)
39 : LayerImpl(layer_impl, id, new LayerImpl::SyncedScrollOffset) {
40}
41
42LayerImpl::LayerImpl(LayerTreeImpl* tree_impl,
43 int id,
44 scoped_refptr<SyncedScrollOffset> scroll_offset)
kulkarni.a4015690f12014-10-10 13:50:0645 : parent_(nullptr),
46 scroll_parent_(nullptr),
47 clip_parent_(nullptr),
[email protected]7aba6662013-03-12 10:17:3448 mask_layer_id_(-1),
49 replica_layer_id_(-1),
50 layer_id_(id),
51 layer_tree_impl_(tree_impl),
aeliasd0070ba2015-01-31 13:44:4952 scroll_offset_(scroll_offset),
kulkarni.a4015690f12014-10-10 13:50:0653 scroll_clip_layer_(nullptr),
[email protected]7aba6662013-03-12 10:17:3454 should_scroll_on_main_thread_(false),
55 have_wheel_event_handlers_(false),
[email protected]f998c532014-03-31 20:02:5156 have_scroll_event_handlers_(false),
ericrk7c030992015-02-20 01:39:3857 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE),
[email protected]59a7d552013-10-22 03:36:4358 user_scrollable_horizontal_(true),
59 user_scrollable_vertical_(true),
[email protected]7aba6662013-03-12 10:17:3460 stacking_order_changed_(false),
61 double_sided_(true),
[email protected]56fffdd2014-02-11 19:50:5762 should_flatten_transform_(true),
ennee95b1542015-04-20 20:35:5063 should_flatten_transform_from_property_tree_(false),
jaydasikad36e7fa2015-07-14 15:15:0464 is_clipped_(false),
[email protected]7aba6662013-03-12 10:17:3465 layer_property_changed_(false),
[email protected]7aba6662013-03-12 10:17:3466 masks_to_bounds_(false),
67 contents_opaque_(false),
[email protected]7bbeaf4e2013-11-26 10:27:2268 is_root_for_isolated_group_(false),
[email protected]7aba6662013-03-12 10:17:3469 use_parent_backface_visibility_(false),
[email protected]7aba6662013-03-12 10:17:3470 draws_content_(false),
[email protected]c0ae06c12013-06-24 18:32:1971 hide_layer_and_subtree_(false),
[email protected]08bdf1b2014-04-16 23:23:2972 transform_is_invertible_(true),
[email protected]7aba6662013-03-12 10:17:3473 is_container_for_fixed_position_layers_(false),
enne9c48d4f12015-06-30 00:31:1574 is_affected_by_page_scale_(true),
[email protected]c55f3fc2013-12-10 05:48:4875 background_color_(0),
76 opacity_(1.0),
77 blend_mode_(SkXfermode::kSrcOver_Mode),
jaydasika92239dc2015-08-15 02:59:2678 draw_blend_mode_(SkXfermode::kSrcOver_Mode),
[email protected]ad63b2f2014-08-11 17:39:5479 num_descendants_that_draw_content_(0),
ennee95b1542015-04-20 20:35:5080 transform_tree_index_(-1),
81 opacity_tree_index_(-1),
82 clip_tree_index_(-1),
[email protected]7aba6662013-03-12 10:17:3483 draw_depth_(0.f),
[email protected]ad0250b2014-01-18 03:24:3484 needs_push_properties_(false),
85 num_dependents_need_push_properties_(0),
[email protected]a9d4d4f2014-06-19 06:49:2886 sorting_context_id_(0),
vmpstr3d1d72c2015-01-26 18:27:4087 current_draw_mode_(DRAW_MODE_NONE),
jaydasika976cd10b2015-05-26 15:45:2488 frame_timing_requests_dirty_(false),
89 visited_(false),
90 layer_or_descendant_is_drawn_(false),
91 sorted_for_recursion_(false) {
[email protected]bf691c22013-03-26 21:15:0692 DCHECK_GT(layer_id_, 0);
[email protected]7aba6662013-03-12 10:17:3493 DCHECK(layer_tree_impl_);
94 layer_tree_impl_->RegisterLayer(this);
loysod71ece82015-07-03 13:48:5095
96 if (!layer_tree_impl_->settings().use_compositor_animation_timelines) {
97 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar();
98 layer_animation_controller_ =
99 registrar->GetAnimationControllerForId(layer_id_);
100 layer_animation_controller_->AddValueObserver(this);
101 if (IsActive()) {
102 layer_animation_controller_->set_value_provider(this);
103 layer_animation_controller_->set_layer_animation_delegate(this);
104 }
[email protected]749cbc62014-07-10 01:06:35105 }
[email protected]ad0250b2014-01-18 03:24:34106 SetNeedsPushProperties();
[email protected]94f206c12012-08-25 00:09:14107}
108
[email protected]7aba6662013-03-12 10:17:34109LayerImpl::~LayerImpl() {
[email protected]ffbb2212013-06-02 23:47:59110 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
[email protected]18a70192013-04-26 16:18:25111
loysod71ece82015-07-03 13:48:50112 if (layer_animation_controller_) {
113 layer_animation_controller_->RemoveValueObserver(this);
114 layer_animation_controller_->remove_value_provider(this);
115 layer_animation_controller_->remove_layer_animation_delegate(this);
116 }
[email protected]b8384e22013-12-03 02:20:48117
[email protected]19334ac2013-12-12 23:59:11118 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree())
119 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
[email protected]b8384e22013-12-03 02:20:48120 layer_tree_impl_->UnregisterLayer(this);
[email protected]0e98cdd2013-08-23 00:44:30121
[email protected]f5ad4282014-02-15 14:23:16122 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
[email protected]b4dc36472014-02-26 02:48:25123 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this);
[email protected]94f206c12012-08-25 00:09:14124}
125
[email protected]7aba6662013-03-12 10:17:34126void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) {
[email protected]ad0250b2014-01-18 03:24:34127 child->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34128 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl());
129 children_.push_back(child.Pass());
130 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]94f206c12012-08-25 00:09:14131}
132
[email protected]7aba6662013-03-12 10:17:34133scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) {
[email protected]50761e92013-03-29 20:51:28134 for (OwnedLayerImplList::iterator it = children_.begin();
[email protected]7aba6662013-03-12 10:17:34135 it != children_.end();
136 ++it) {
137 if (*it == child) {
138 scoped_ptr<LayerImpl> ret = children_.take(it);
139 children_.erase(it);
140 layer_tree_impl()->set_needs_update_draw_properties();
141 return ret.Pass();
[email protected]94f206c12012-08-25 00:09:14142 }
[email protected]7aba6662013-03-12 10:17:34143 }
danakjf446a072014-09-27 21:55:48144 return nullptr;
[email protected]94f206c12012-08-25 00:09:14145}
146
[email protected]ad0250b2014-01-18 03:24:34147void LayerImpl::SetParent(LayerImpl* parent) {
148 if (parent_should_know_need_push_properties()) {
149 if (parent_)
150 parent_->RemoveDependentNeedsPushProperties();
151 if (parent)
152 parent->AddDependentNeedsPushProperties();
153 }
154 parent_ = parent;
155}
156
[email protected]7aba6662013-03-12 10:17:34157void LayerImpl::ClearChildList() {
158 if (children_.empty())
159 return;
[email protected]0ede3bb2012-12-09 09:14:39160
[email protected]7aba6662013-03-12 10:17:34161 children_.clear();
162 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]94f206c12012-08-25 00:09:14163}
164
[email protected]0e98cdd2013-08-23 00:44:30165bool LayerImpl::HasAncestor(const LayerImpl* ancestor) const {
166 if (!ancestor)
167 return false;
168
169 for (const LayerImpl* layer = this; layer; layer = layer->parent()) {
170 if (layer == ancestor)
171 return true;
172 }
173
174 return false;
175}
176
177void LayerImpl::SetScrollParent(LayerImpl* parent) {
178 if (scroll_parent_ == parent)
179 return;
180
[email protected]d097e242014-02-28 21:51:11181 if (parent)
182 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent);
[email protected]0e98cdd2013-08-23 00:44:30183
184 scroll_parent_ = parent;
[email protected]ad0250b2014-01-18 03:24:34185 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30186}
187
[email protected]9f3be432013-12-03 03:53:22188void LayerImpl::SetDebugInfo(
ssid911e40e2015-02-09 17:55:20189 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other) {
[email protected]9f3be432013-12-03 03:53:22190 debug_info_ = other;
[email protected]ad0250b2014-01-18 03:24:34191 SetNeedsPushProperties();
[email protected]9f3be432013-12-03 03:53:22192}
193
[email protected]0e98cdd2013-08-23 00:44:30194void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) {
195 if (scroll_children_.get() == children)
196 return;
197 scroll_children_.reset(children);
[email protected]ad0250b2014-01-18 03:24:34198 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30199}
200
tdresserd9e201472015-07-31 13:15:07201void LayerImpl::DistributeScroll(ScrollState* scroll_state) {
202 DCHECK(scroll_state);
203 if (scroll_state->FullyConsumed())
204 return;
205
206 scroll_state->DistributeToScrollChainDescendant();
207
208 // If the scroll doesn't propagate, and we're currently scrolling
209 // a layer other than this one, prevent the scroll from
210 // propagating to this layer.
211 if (!scroll_state->should_propagate() &&
212 scroll_state->delta_consumed_for_scroll_sequence() &&
213 scroll_state->current_native_scrolling_layer() != this) {
214 return;
215 }
216
217 ApplyScroll(scroll_state);
218}
219
220void LayerImpl::ApplyScroll(ScrollState* scroll_state) {
221 DCHECK(scroll_state);
222 layer_tree_impl()->ApplyScroll(this, scroll_state);
223}
224
[email protected]ad63b2f2014-08-11 17:39:54225void LayerImpl::SetNumDescendantsThatDrawContent(int num_descendants) {
226 if (num_descendants_that_draw_content_ == num_descendants)
227 return;
228 num_descendants_that_draw_content_ = num_descendants;
229 SetNeedsPushProperties();
230}
231
[email protected]0e98cdd2013-08-23 00:44:30232void LayerImpl::SetClipParent(LayerImpl* ancestor) {
233 if (clip_parent_ == ancestor)
234 return;
235
[email protected]0e98cdd2013-08-23 00:44:30236 clip_parent_ = ancestor;
[email protected]ad0250b2014-01-18 03:24:34237 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30238}
239
240void LayerImpl::SetClipChildren(std::set<LayerImpl*>* children) {
241 if (clip_children_.get() == children)
242 return;
243 clip_children_.reset(children);
[email protected]ad0250b2014-01-18 03:24:34244 SetNeedsPushProperties();
[email protected]0e98cdd2013-08-23 00:44:30245}
246
vollick692444f2015-05-20 15:39:14247void LayerImpl::SetTransformTreeIndex(int index) {
248 transform_tree_index_ = index;
249 SetNeedsPushProperties();
250}
251
252void LayerImpl::SetClipTreeIndex(int index) {
253 clip_tree_index_ = index;
254 SetNeedsPushProperties();
255}
256
257void LayerImpl::SetOpacityTreeIndex(int index) {
258 opacity_tree_index_ = index;
259 SetNeedsPushProperties();
260}
261
[email protected]0e5f7142013-05-24 06:45:36262void LayerImpl::PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests) {
ennef44fcf92015-06-12 23:56:32263 // In the case that a layer still has a copy request, this means that there's
264 // a commit to the active tree without a draw. This only happens in some
265 // edge cases during lost context or visibility changes, so don't try to
266 // handle preserving these output requests (and their surface).
267 if (!copy_requests_.empty()) {
268 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
269 // Destroying these will abort them.
270 copy_requests_.clear();
271 }
272
[email protected]0e5f7142013-05-24 06:45:36273 if (requests->empty())
[email protected]18a70192013-04-26 16:18:25274 return;
ennef44fcf92015-06-12 23:56:32275
awoloszyne83f28c2014-12-22 15:40:00276 DCHECK(render_surface());
[email protected]f5de9e5b2013-07-30 22:26:57277 bool was_empty = copy_requests_.empty();
weiliangcc1878c62014-09-02 22:43:17278 copy_requests_.insert_and_take(copy_requests_.end(), requests);
[email protected]0e5f7142013-05-24 06:45:36279 requests->clear();
[email protected]18a70192013-04-26 16:18:25280
[email protected]f5de9e5b2013-07-30 22:26:57281 if (was_empty && layer_tree_impl()->IsActiveTree())
[email protected]30fe19ff2013-07-04 00:54:45282 layer_tree_impl()->AddLayerWithCopyOutputRequest(this);
[email protected]18a70192013-04-26 16:18:25283 NoteLayerPropertyChangedForSubtree();
284}
285
[email protected]d4d017e2013-06-20 21:46:11286void LayerImpl::TakeCopyRequestsAndTransformToTarget(
287 ScopedPtrVector<CopyOutputRequest>* requests) {
[email protected]df17af52014-02-06 02:20:40288 DCHECK(!copy_requests_.empty());
289 DCHECK(layer_tree_impl()->IsActiveTree());
awoloszyne83f28c2014-12-22 15:40:00290 DCHECK_EQ(render_target(), this);
[email protected]18a70192013-04-26 16:18:25291
[email protected]30fe19ff2013-07-04 00:54:45292 size_t first_inserted_request = requests->size();
weiliangcc1878c62014-09-02 22:43:17293 requests->insert_and_take(requests->end(), &copy_requests_);
[email protected]0e5f7142013-05-24 06:45:36294 copy_requests_.clear();
[email protected]d4d017e2013-06-20 21:46:11295
[email protected]30fe19ff2013-07-04 00:54:45296 for (size_t i = first_inserted_request; i < requests->size(); ++i) {
[email protected]d4d017e2013-06-20 21:46:11297 CopyOutputRequest* request = requests->at(i);
298 if (!request->has_area())
299 continue;
300
301 gfx::Rect request_in_layer_space = request->area();
danakje0f14a882015-06-18 05:05:07302 request_in_layer_space.Intersect(gfx::Rect(bounds()));
[email protected]8a822692014-02-12 17:30:55303 request->set_area(MathUtil::MapEnclosingClippedRect(
danakje0f14a882015-06-18 05:05:07304 draw_properties_.target_space_transform, request_in_layer_space));
[email protected]d4d017e2013-06-20 21:46:11305 }
[email protected]30fe19ff2013-07-04 00:54:45306
[email protected]df17af52014-02-06 02:20:40307 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
danakj0cf95392015-01-29 17:56:54308 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]18a70192013-04-26 16:18:25309}
310
[email protected]7644fa22014-04-28 12:20:33311void LayerImpl::ClearRenderSurfaceLayerList() {
awoloszyne83f28c2014-12-22 15:40:00312 if (render_surface_)
313 render_surface_->ClearLayerLists();
[email protected]7644fa22014-04-28 12:20:33314}
315
[email protected]9be1adc82014-05-07 15:39:41316void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const {
Dana Jansensc46d3742015-06-18 01:33:14317 state->SetAll(draw_properties_.target_space_transform, bounds(),
danakj64767d902015-06-19 00:10:43318 draw_properties_.visible_layer_rect, draw_properties_.clip_rect,
jaydasika92239dc2015-08-15 02:59:26319 is_clipped_, draw_properties_.opacity, draw_blend_mode_,
320 sorting_context_id_);
[email protected]94f206c12012-08-25 00:09:14321}
322
enne467829b2015-02-13 02:39:34323void LayerImpl::PopulateScaledSharedQuadState(SharedQuadState* state,
324 float scale) const {
325 gfx::Transform scaled_draw_transform =
326 draw_properties_.target_space_transform;
327 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
Dana Jansensc46d3742015-06-18 01:33:14328 gfx::Size scaled_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale));
danakj64767d902015-06-19 00:10:43329 gfx::Rect scaled_visible_layer_rect =
330 gfx::ScaleToEnclosingRect(visible_layer_rect(), scale);
331 scaled_visible_layer_rect.Intersect(gfx::Rect(scaled_bounds));
enne467829b2015-02-13 02:39:34332
danakj64767d902015-06-19 00:10:43333 state->SetAll(scaled_draw_transform, scaled_bounds, scaled_visible_layer_rect,
jaydasikad36e7fa2015-07-14 15:15:04334 draw_properties().clip_rect, is_clipped_,
jaydasika92239dc2015-08-15 02:59:26335 draw_properties().opacity, draw_blend_mode_,
danakj64767d902015-06-19 00:10:43336 sorting_context_id_);
enne467829b2015-02-13 02:39:34337}
338
[email protected]ffbb2212013-06-02 23:47:59339bool LayerImpl::WillDraw(DrawMode draw_mode,
340 ResourceProvider* resource_provider) {
[email protected]ed511b8d2013-03-25 03:29:29341 // WillDraw/DidDraw must be matched.
[email protected]ffbb2212013-06-02 23:47:59342 DCHECK_NE(DRAW_MODE_NONE, draw_mode);
343 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
344 current_draw_mode_ = draw_mode;
345 return true;
[email protected]94f206c12012-08-25 00:09:14346}
347
[email protected]7aba6662013-03-12 10:17:34348void LayerImpl::DidDraw(ResourceProvider* resource_provider) {
[email protected]ffbb2212013-06-02 23:47:59349 DCHECK_NE(DRAW_MODE_NONE, current_draw_mode_);
350 current_draw_mode_ = DRAW_MODE_NONE;
[email protected]94f206c12012-08-25 00:09:14351}
352
[email protected]7aba6662013-03-12 10:17:34353bool LayerImpl::ShowDebugBorders() const {
[email protected]846f455b2013-03-18 19:07:41354 return layer_tree_impl()->debug_state().show_debug_borders;
[email protected]3dce37232012-11-15 01:47:44355}
356
[email protected]7aba6662013-03-12 10:17:34357void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const {
358 if (draws_content_) {
359 *color = DebugColors::ContentLayerBorderColor();
360 *width = DebugColors::ContentLayerBorderWidth(layer_tree_impl());
361 return;
362 }
363
364 if (masks_to_bounds_) {
365 *color = DebugColors::MaskingLayerBorderColor();
366 *width = DebugColors::MaskingLayerBorderWidth(layer_tree_impl());
367 return;
368 }
369
370 *color = DebugColors::ContainerLayerBorderColor();
371 *width = DebugColors::ContainerLayerBorderWidth(layer_tree_impl());
372}
373
374void LayerImpl::AppendDebugBorderQuad(
[email protected]c6707fd2014-06-23 05:50:36375 RenderPass* render_pass,
Dana Jansensc46d3742015-06-18 01:33:14376 const gfx::Size& bounds,
[email protected]7aba6662013-03-12 10:17:34377 const SharedQuadState* shared_quad_state,
378 AppendQuadsData* append_quads_data) const {
[email protected]7aba6662013-03-12 10:17:34379 SkColor color;
380 float width;
381 GetDebugBorderProperties(&color, &width);
Dana Jansensc46d3742015-06-18 01:33:14382 AppendDebugBorderQuad(render_pass, bounds, shared_quad_state,
383 append_quads_data, color, width);
[email protected]bec084292013-05-21 21:31:44384}
385
[email protected]c6707fd2014-06-23 05:50:36386void LayerImpl::AppendDebugBorderQuad(RenderPass* render_pass,
Dana Jansensc46d3742015-06-18 01:33:14387 const gfx::Size& bounds,
[email protected]bec084292013-05-21 21:31:44388 const SharedQuadState* shared_quad_state,
389 AppendQuadsData* append_quads_data,
390 SkColor color,
391 float width) const {
392 if (!ShowDebugBorders())
393 return;
[email protected]7aba6662013-03-12 10:17:34394
Dana Jansensc46d3742015-06-18 01:33:14395 gfx::Rect quad_rect(bounds);
[email protected]9bf06c72014-03-07 18:16:24396 gfx::Rect visible_quad_rect(quad_rect);
[email protected]f7030c32014-07-03 18:54:34397 DebugBorderDrawQuad* debug_border_quad =
398 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
[email protected]9bf06c72014-03-07 18:16:24399 debug_border_quad->SetNew(
400 shared_quad_state, quad_rect, visible_quad_rect, color, width);
danakj069ac122015-02-12 00:59:22401 if (contents_opaque()) {
402 // When opaque, draw a second inner border that is thicker than the outer
403 // border, but more transparent.
404 static const float kFillOpacity = 0.3f;
405 SkColor fill_color = SkColorSetA(
406 color, static_cast<uint8_t>(SkColorGetA(color) * kFillOpacity));
407 float fill_width = width * 3;
408 gfx::Rect fill_rect = quad_rect;
409 fill_rect.Inset(fill_width / 2.f, fill_width / 2.f);
enneb79d5f142015-04-23 19:59:55410 if (fill_rect.IsEmpty())
411 return;
danakj069ac122015-02-12 00:59:22412 gfx::Rect visible_fill_rect =
413 gfx::IntersectRects(visible_quad_rect, fill_rect);
414 DebugBorderDrawQuad* fill_quad =
415 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
416 fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect,
417 fill_color, fill_width);
418 }
[email protected]7aba6662013-03-12 10:17:34419}
420
421bool LayerImpl::HasDelegatedContent() const {
422 return false;
423}
424
425bool LayerImpl::HasContributingDelegatedRenderPasses() const {
426 return false;
427}
428
[email protected]0cd7d6f72014-08-22 14:50:51429RenderPassId LayerImpl::FirstContributingRenderPassId() const {
430 return RenderPassId(0, 0);
[email protected]7aba6662013-03-12 10:17:34431}
432
[email protected]0cd7d6f72014-08-22 14:50:51433RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const {
434 return RenderPassId(0, 0);
[email protected]7aba6662013-03-12 10:17:34435}
436
jbaumanbbd425e2015-05-19 00:33:35437void LayerImpl::GetContentsResourceId(ResourceId* resource_id,
ennef6f3fbba42014-10-16 18:16:49438 gfx::Size* resource_size) const {
[email protected]7aba6662013-03-12 10:17:34439 NOTREACHED();
ennef6f3fbba42014-10-16 18:16:49440 *resource_id = 0;
[email protected]7aba6662013-03-12 10:17:34441}
442
[email protected]3244c9132014-01-23 10:39:12443gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) {
aeliasd0070ba2015-01-31 13:44:49444 gfx::ScrollOffset adjusted_scroll(scroll);
bokan57ebc052015-05-29 13:14:21445 if (!user_scrollable_horizontal_)
446 adjusted_scroll.set_x(0);
447 if (!user_scrollable_vertical_)
448 adjusted_scroll.set_y(0);
[email protected]d30700f12013-07-31 08:21:01449 DCHECK(scrollable());
aeliasd0070ba2015-01-31 13:44:49450 gfx::ScrollOffset old_offset = CurrentScrollOffset();
451 gfx::ScrollOffset new_offset =
452 ClampScrollOffsetToLimits(old_offset + adjusted_scroll);
453 SetCurrentScrollOffset(new_offset);
[email protected]adeda572014-01-31 00:49:47454
aeliasd0070ba2015-01-31 13:44:49455 gfx::ScrollOffset unscrolled =
456 old_offset + gfx::ScrollOffset(scroll) - new_offset;
457 return gfx::Vector2dF(unscrolled.x(), unscrolled.y());
[email protected]7aba6662013-03-12 10:17:34458}
459
[email protected]adeda572014-01-31 00:49:47460void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) {
461 scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id);
462}
463
timav3ca696932014-10-15 02:19:04464bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const {
465 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_
466 : user_scrollable_vertical_;
467}
468
[email protected]58241dc2013-08-20 01:39:25469void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() {
[email protected]3519b872013-07-30 07:17:50470 DCHECK(layer_tree_impl()->IsActiveTree());
aeliasd0070ba2015-01-31 13:44:49471 scroll_offset_->AbortCommit();
[email protected]58241dc2013-08-20 01:39:25472}
473
[email protected]5ff3c9782013-04-29 17:35:12474InputHandler::ScrollStatus LayerImpl::TryScroll(
[email protected]14bc5d682014-01-17 07:26:47475 const gfx::PointF& screen_space_point,
rbyers18779d822015-02-05 06:22:06476 InputHandler::ScrollInputType type,
477 ScrollBlocksOn effective_block_mode) const {
[email protected]7aba6662013-03-12 10:17:34478 if (should_scroll_on_main_thread()) {
[email protected]ed511b8d2013-03-25 03:29:29479 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread");
ericrk7c030992015-02-20 01:39:38480 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]7aba6662013-03-12 10:17:34481 }
482
483 if (!screen_space_transform().IsInvertible()) {
[email protected]ed511b8d2013-03-25 03:29:29484 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform");
ericrk7c030992015-02-20 01:39:38485 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34486 }
487
488 if (!non_fast_scrollable_region().IsEmpty()) {
489 bool clipped = false;
490 gfx::Transform inverse_screen_space_transform(
491 gfx::Transform::kSkipInitialization);
492 if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) {
493 // TODO(shawnsingh): We shouldn't be applying a projection if screen space
494 // transform is uninvertible here. Perhaps we should be returning
ericrk7c030992015-02-20 01:39:38495 // SCROLL_ON_MAIN_THREAD in this case?
[email protected]3dce37232012-11-15 01:47:44496 }
497
danakj2c8d12c2015-06-18 06:15:33498 gfx::PointF hit_test_point_in_layer_space = MathUtil::ProjectPoint(
499 inverse_screen_space_transform, screen_space_point, &clipped);
[email protected]7aba6662013-03-12 10:17:34500 if (!clipped &&
501 non_fast_scrollable_region().Contains(
502 gfx::ToRoundedPoint(hit_test_point_in_layer_space))) {
503 TRACE_EVENT0("cc",
[email protected]ed511b8d2013-03-25 03:29:29504 "LayerImpl::tryScroll: Failed NonFastScrollableRegion");
ericrk7c030992015-02-20 01:39:38505 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]3dce37232012-11-15 01:47:44506 }
[email protected]7aba6662013-03-12 10:17:34507 }
[email protected]3dce37232012-11-15 01:47:44508
rbyers18779d822015-02-05 06:22:06509 if (have_scroll_event_handlers() &&
ericrk7c030992015-02-20 01:39:38510 effective_block_mode & SCROLL_BLOCKS_ON_SCROLL_EVENT) {
rbyers18779d822015-02-05 06:22:06511 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed ScrollEventHandlers");
ericrk7c030992015-02-20 01:39:38512 return InputHandler::SCROLL_ON_MAIN_THREAD;
rbyers18779d822015-02-05 06:22:06513 }
514
ericrk7c030992015-02-20 01:39:38515 if (type == InputHandler::WHEEL && have_wheel_event_handlers() &&
516 effective_block_mode & SCROLL_BLOCKS_ON_WHEEL_EVENT) {
[email protected]ed511b8d2013-03-25 03:29:29517 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
ericrk7c030992015-02-20 01:39:38518 return InputHandler::SCROLL_ON_MAIN_THREAD;
[email protected]7aba6662013-03-12 10:17:34519 }
520
521 if (!scrollable()) {
522 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
ericrk7c030992015-02-20 01:39:38523 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34524 }
525
miletusf57925d2014-10-01 19:38:13526 gfx::ScrollOffset max_scroll_offset = MaxScrollOffset();
[email protected]adeda572014-01-31 00:49:47527 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
[email protected]7aba6662013-03-12 10:17:34528 TRACE_EVENT0("cc",
529 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
530 " but has no affordance in either direction.");
ericrk7c030992015-02-20 01:39:38531 return InputHandler::SCROLL_IGNORED;
[email protected]7aba6662013-03-12 10:17:34532 }
533
ericrk7c030992015-02-20 01:39:38534 return InputHandler::SCROLL_STARTED;
[email protected]3dce37232012-11-15 01:47:44535}
536
[email protected]7aba6662013-03-12 10:17:34537skia::RefPtr<SkPicture> LayerImpl::GetPicture() {
538 return skia::RefPtr<SkPicture>();
[email protected]76481592012-09-21 16:47:06539}
540
[email protected]7aba6662013-03-12 10:17:34541scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) {
aeliasd0070ba2015-01-31 13:44:49542 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_);
[email protected]94f206c12012-08-25 00:09:14543}
544
[email protected]7aba6662013-03-12 10:17:34545void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
[email protected]a2566412014-06-05 03:14:20546 layer->SetTransformOrigin(transform_origin_);
[email protected]7aba6662013-03-12 10:17:34547 layer->SetBackgroundColor(background_color_);
548 layer->SetBounds(bounds_);
[email protected]7aba6662013-03-12 10:17:34549 layer->SetDoubleSided(double_sided_);
[email protected]7aba6662013-03-12 10:17:34550 layer->SetDrawsContent(DrawsContent());
[email protected]c0ae06c12013-06-24 18:32:19551 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_);
ennef44fcf92015-06-12 23:56:32552 layer->SetHasRenderSurface(!!render_surface());
[email protected]7aba6662013-03-12 10:17:34553 layer->SetFilters(filters());
[email protected]7aba6662013-03-12 10:17:34554 layer->SetBackgroundFilters(background_filters());
555 layer->SetMasksToBounds(masks_to_bounds_);
556 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_);
557 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
[email protected]f998c532014-03-31 20:02:51558 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_);
rbyers18779d822015-02-05 06:22:06559 layer->SetScrollBlocksOn(scroll_blocks_on_);
[email protected]7aba6662013-03-12 10:17:34560 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
561 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
562 layer->SetContentsOpaque(contents_opaque_);
[email protected]43615872013-03-13 16:35:17563 layer->SetOpacity(opacity_);
[email protected]7bbeaf4e2013-11-26 10:27:22564 layer->SetBlendMode(blend_mode_);
565 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_);
[email protected]7aba6662013-03-12 10:17:34566 layer->SetPosition(position_);
567 layer->SetIsContainerForFixedPositionLayers(
568 is_container_for_fixed_position_layers_);
[email protected]fe956c9c42013-04-09 04:26:33569 layer->SetPositionConstraint(position_constraint_);
[email protected]56fffdd2014-02-11 19:50:57570 layer->SetShouldFlattenTransform(should_flatten_transform_);
ennee95b1542015-04-20 20:35:50571 layer->set_should_flatten_transform_from_property_tree(
572 should_flatten_transform_from_property_tree_);
jaydasikad36e7fa2015-07-14 15:15:04573 layer->set_is_clipped(is_clipped_);
jaydasika92239dc2015-08-15 02:59:26574 layer->set_draw_blend_mode(draw_blend_mode_);
[email protected]7aba6662013-03-12 10:17:34575 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
[email protected]08bdf1b2014-04-16 23:23:29576 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
[email protected]9bd1cb52013-01-03 22:26:33577
[email protected]adeda572014-01-31 00:49:47578 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id()
579 : Layer::INVALID_ID);
[email protected]59a7d552013-10-22 03:36:43580 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
581 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
bokanc687507f2014-11-04 23:41:42582
miletusff93ab72015-01-30 04:30:44583 layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_);
bokanc687507f2014-11-04 23:41:42584
aeliasd0070ba2015-01-31 13:44:49585 layer->PushScrollOffset(nullptr);
586
[email protected]a9d4d4f2014-06-19 06:49:28587 layer->Set3dSortingContextId(sorting_context_id_);
[email protected]ad63b2f2014-08-11 17:39:54588 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
[email protected]b34c97982013-08-24 15:21:38589
vollick692444f2015-05-20 15:39:14590 layer->SetTransformTreeIndex(transform_tree_index_);
591 layer->SetClipTreeIndex(clip_tree_index_);
592 layer->SetOpacityTreeIndex(opacity_tree_index_);
ennee95b1542015-04-20 20:35:50593 layer->set_offset_to_transform_parent(offset_to_transform_parent_);
594
kulkarni.a4015690f12014-10-10 13:50:06595 LayerImpl* scroll_parent = nullptr;
[email protected]d097e242014-02-28 21:51:11596 if (scroll_parent_) {
[email protected]0e98cdd2013-08-23 00:44:30597 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
[email protected]d097e242014-02-28 21:51:11598 DCHECK(scroll_parent);
599 }
[email protected]0e98cdd2013-08-23 00:44:30600
601 layer->SetScrollParent(scroll_parent);
602 if (scroll_children_) {
603 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
604 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin();
[email protected]d097e242014-02-28 21:51:11605 it != scroll_children_->end();
606 ++it) {
607 DCHECK_EQ((*it)->scroll_parent(), this);
608 LayerImpl* scroll_child =
609 layer->layer_tree_impl()->LayerById((*it)->id());
610 DCHECK(scroll_child);
611 scroll_children->insert(scroll_child);
612 }
[email protected]0e98cdd2013-08-23 00:44:30613 layer->SetScrollChildren(scroll_children);
[email protected]d097e242014-02-28 21:51:11614 } else {
kulkarni.a4015690f12014-10-10 13:50:06615 layer->SetScrollChildren(nullptr);
[email protected]0e98cdd2013-08-23 00:44:30616 }
617
kulkarni.a4015690f12014-10-10 13:50:06618 LayerImpl* clip_parent = nullptr;
[email protected]0e98cdd2013-08-23 00:44:30619 if (clip_parent_) {
620 clip_parent = layer->layer_tree_impl()->LayerById(
621 clip_parent_->id());
[email protected]d097e242014-02-28 21:51:11622 DCHECK(clip_parent);
[email protected]0e98cdd2013-08-23 00:44:30623 }
624
625 layer->SetClipParent(clip_parent);
626 if (clip_children_) {
627 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>;
628 for (std::set<LayerImpl*>::iterator it = clip_children_->begin();
629 it != clip_children_->end(); ++it)
630 clip_children->insert(layer->layer_tree_impl()->LayerById((*it)->id()));
631 layer->SetClipChildren(clip_children);
[email protected]d097e242014-02-28 21:51:11632 } else {
kulkarni.a4015690f12014-10-10 13:50:06633 layer->SetClipChildren(nullptr);
[email protected]0e98cdd2013-08-23 00:44:30634 }
635
[email protected]0e5f7142013-05-24 06:45:36636 layer->PassCopyRequests(&copy_requests_);
[email protected]18a70192013-04-26 16:18:25637
[email protected]7aba6662013-03-12 10:17:34638 // If the main thread commits multiple times before the impl thread actually
639 // draws, then damage tracking will become incorrect if we simply clobber the
[email protected]ed511b8d2013-03-25 03:29:29640 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
[email protected]7aba6662013-03-12 10:17:34641 // union) any update changes that have occurred on the main thread.
642 update_rect_.Union(layer->update_rect());
[email protected]ad0250b2014-01-18 03:24:34643 layer->SetUpdateRect(update_rect_);
[email protected]7aba6662013-03-12 10:17:34644
[email protected]7aba6662013-03-12 10:17:34645 layer->SetStackingOrderChanged(stacking_order_changed_);
[email protected]ad0250b2014-01-18 03:24:34646 layer->SetDebugInfo(debug_info_);
[email protected]7aba6662013-03-12 10:17:34647
vmpstr3d1d72c2015-01-26 18:27:40648 if (frame_timing_requests_dirty_) {
vmpstr3a24da5042015-05-27 03:33:31649 layer->SetFrameTimingRequests(frame_timing_requests_);
vmpstr3d1d72c2015-01-26 18:27:40650 frame_timing_requests_dirty_ = false;
651 }
652
[email protected]7aba6662013-03-12 10:17:34653 // Reset any state that should be cleared for the next update.
654 stacking_order_changed_ = false;
danakj19f0c9e2014-10-11 03:24:42655 update_rect_ = gfx::Rect();
[email protected]ad0250b2014-01-18 03:24:34656 needs_push_properties_ = false;
657 num_dependents_need_push_properties_ = 0;
[email protected]caa567d2012-12-20 07:56:16658}
659
[email protected]fef74fd2014-02-27 06:28:17660gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const {
661 if (!scroll_clip_layer_)
662 return gfx::Vector2dF();
663
[email protected]587941d2014-08-22 01:40:01664 gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta();
bokan8273d962014-10-22 02:40:27665
666 // In virtual-viewport mode, we don't need to compensate for pinch zoom or
667 // scale since the fixed container is the outer viewport, which sits below
668 // the page scale.
bokan57ebc052015-05-29 13:14:21669 return delta_from_scroll;
[email protected]fef74fd2014-02-27 06:28:17670}
671
[email protected]7aba6662013-03-12 10:17:34672base::DictionaryValue* LayerImpl::LayerTreeAsJson() const {
[email protected]7aba6662013-03-12 10:17:34673 base::DictionaryValue* result = new base::DictionaryValue;
r.kasibhatlafd17d0e2015-05-17 11:12:07674 result->SetInteger("LayerId", id());
[email protected]7aba6662013-03-12 10:17:34675 result->SetString("LayerType", LayerTypeAsString());
676
[email protected]46c76952013-07-10 00:21:45677 base::ListValue* list = new base::ListValue;
bokancccfde72014-10-08 15:15:22678 list->AppendInteger(bounds().width());
679 list->AppendInteger(bounds().height());
[email protected]7aba6662013-03-12 10:17:34680 result->Set("Bounds", list);
681
682 list = new base::ListValue;
683 list->AppendDouble(position_.x());
684 list->AppendDouble(position_.y());
685 result->Set("Position", list);
686
687 const gfx::Transform& gfx_transform = draw_properties_.target_space_transform;
688 double transform[16];
689 gfx_transform.matrix().asColMajord(transform);
690 list = new base::ListValue;
691 for (int i = 0; i < 16; ++i)
692 list->AppendDouble(transform[i]);
693 result->Set("DrawTransform", list);
694
695 result->SetBoolean("DrawsContent", draws_content_);
[email protected]a9d4d4f2014-06-19 06:49:28696 result->SetBoolean("Is3dSorted", Is3dSorted());
ericrk7c030992015-02-20 01:39:38697 result->SetDouble("OPACITY", opacity());
[email protected]46c76952013-07-10 00:21:45698 result->SetBoolean("ContentsOpaque", contents_opaque_);
[email protected]7aba6662013-03-12 10:17:34699
[email protected]adeda572014-01-31 00:49:47700 if (scrollable())
701 result->SetBoolean("Scrollable", true);
[email protected]d993e032013-06-07 00:16:16702
[email protected]9d161d22013-10-29 20:54:10703 if (have_wheel_event_handlers_)
704 result->SetBoolean("WheelHandler", have_wheel_event_handlers_);
[email protected]f998c532014-03-31 20:02:51705 if (have_scroll_event_handlers_)
706 result->SetBoolean("ScrollHandler", have_scroll_event_handlers_);
[email protected]9d161d22013-10-29 20:54:10707 if (!touch_event_handler_region_.IsEmpty()) {
708 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue();
709 result->Set("TouchRegion", region.release());
710 }
711
rbyers18779d822015-02-05 06:22:06712 if (scroll_blocks_on_) {
713 list = new base::ListValue;
ericrk7c030992015-02-20 01:39:38714 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_START_TOUCH)
rbyers18779d822015-02-05 06:22:06715 list->AppendString("StartTouch");
ericrk7c030992015-02-20 01:39:38716 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_WHEEL_EVENT)
rbyers18779d822015-02-05 06:22:06717 list->AppendString("WheelEvent");
ericrk7c030992015-02-20 01:39:38718 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_SCROLL_EVENT)
rbyers18779d822015-02-05 06:22:06719 list->AppendString("ScrollEvent");
720 result->Set("ScrollBlocksOn", list);
721 }
722
[email protected]7aba6662013-03-12 10:17:34723 list = new base::ListValue;
724 for (size_t i = 0; i < children_.size(); ++i)
725 list->Append(children_[i]->LayerTreeAsJson());
726 result->Set("Children", list);
727
728 return result;
[email protected]b9dcf43a2013-01-09 00:15:29729}
730
[email protected]7aba6662013-03-12 10:17:34731void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) {
732 if (stacking_order_changed) {
733 stacking_order_changed_ = true;
734 NoteLayerPropertyChangedForSubtree();
735 }
[email protected]aedf4e52013-01-09 23:24:44736}
737
[email protected]7aba6662013-03-12 10:17:34738void LayerImpl::NoteLayerPropertyChanged() {
739 layer_property_changed_ = true;
740 layer_tree_impl()->set_needs_update_draw_properties();
[email protected]ad0250b2014-01-18 03:24:34741 SetNeedsPushProperties();
[email protected]48871fc2013-01-23 07:36:51742}
743
[email protected]7aba6662013-03-12 10:17:34744void LayerImpl::NoteLayerPropertyChangedForSubtree() {
[email protected]ad0250b2014-01-18 03:24:34745 layer_property_changed_ = true;
746 layer_tree_impl()->set_needs_update_draw_properties();
747 for (size_t i = 0; i < children_.size(); ++i)
748 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
749 SetNeedsPushProperties();
750}
751
752void LayerImpl::NoteLayerPropertyChangedForDescendantsInternal() {
753 layer_property_changed_ = true;
754 for (size_t i = 0; i < children_.size(); ++i)
755 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
[email protected]94f206c12012-08-25 00:09:14756}
757
[email protected]7aba6662013-03-12 10:17:34758void LayerImpl::NoteLayerPropertyChangedForDescendants() {
759 layer_tree_impl()->set_needs_update_draw_properties();
760 for (size_t i = 0; i < children_.size(); ++i)
[email protected]ad0250b2014-01-18 03:24:34761 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
762 SetNeedsPushProperties();
[email protected]7aba6662013-03-12 10:17:34763}
[email protected]94f206c12012-08-25 00:09:14764
danakjf9427572015-04-24 22:19:02765void LayerImpl::ValidateQuadResourcesInternal(DrawQuad* quad) const {
766#if DCHECK_IS_ON()
vmpstr0eca2e82015-06-02 22:14:46767 const ResourceProvider* resource_provider =
768 layer_tree_impl_->resource_provider();
769 for (ResourceId resource_id : quad->resources)
770 resource_provider->ValidateResource(resource_id);
danakjf9427572015-04-24 22:19:02771#endif
772}
773
[email protected]7aba6662013-03-12 10:17:34774const char* LayerImpl::LayerTypeAsString() const {
[email protected]f256b7fd2013-05-15 01:49:30775 return "cc::LayerImpl";
[email protected]7aba6662013-03-12 10:17:34776}
[email protected]94f206c12012-08-25 00:09:14777
[email protected]7aba6662013-03-12 10:17:34778void LayerImpl::ResetAllChangeTrackingForSubtree() {
779 layer_property_changed_ = false;
[email protected]7aba6662013-03-12 10:17:34780
danakj19f0c9e2014-10-11 03:24:42781 update_rect_ = gfx::Rect();
[email protected]cfa7fd922014-04-29 11:50:03782 damage_rect_ = gfx::RectF();
[email protected]7aba6662013-03-12 10:17:34783
awoloszyne83f28c2014-12-22 15:40:00784 if (render_surface_)
785 render_surface_->ResetPropertyChangedFlag();
[email protected]7aba6662013-03-12 10:17:34786
787 if (mask_layer_)
788 mask_layer_->ResetAllChangeTrackingForSubtree();
789
790 if (replica_layer_) {
791 // This also resets the replica mask, if it exists.
792 replica_layer_->ResetAllChangeTrackingForSubtree();
793 }
794
795 for (size_t i = 0; i < children_.size(); ++i)
796 children_[i]->ResetAllChangeTrackingForSubtree();
[email protected]ad0250b2014-01-18 03:24:34797
798 needs_push_properties_ = false;
799 num_dependents_need_push_properties_ = 0;
[email protected]7aba6662013-03-12 10:17:34800}
801
ajuma59c23b42015-05-25 20:18:37802void LayerImpl::UpdatePropertyTreeTransform() {
803 if (transform_tree_index_ != -1) {
804 TransformTree& transform_tree =
805 layer_tree_impl()->property_trees()->transform_tree;
806 TransformNode* node = transform_tree.Node(transform_tree_index_);
ajumae7425272015-07-13 18:37:34807 // A LayerImpl's own current state is insufficient for determining whether
808 // it owns a TransformNode, since this depends on the state of the
809 // corresponding Layer at the time of the last commit. For example, a
810 // transform animation might have been in progress at the time the last
811 // commit started, but might have finished since then on the compositor
812 // thread.
813 if (node->owner_id != id())
814 return;
ajuma59c23b42015-05-25 20:18:37815 if (node->data.local != transform_) {
816 node->data.local = transform_;
817 node->data.needs_local_transform_update = true;
818 transform_tree.set_needs_update(true);
819 // TODO(ajuma): The current criteria for creating clip nodes means that
820 // property trees may need to be rebuilt when the new transform isn't
821 // axis-aligned wrt the old transform (see Layer::SetTransform). Since
822 // rebuilding property trees every frame of a transform animation is
823 // something we should try to avoid, change property tree-building so that
824 // it doesn't depend on axis aliginment.
825 }
826 }
827}
828
ajumacaaa9b32015-08-04 15:55:29829void LayerImpl::UpdatePropertyTreeTransformIsAnimated(bool is_animated) {
830 if (transform_tree_index_ != -1) {
831 TransformTree& transform_tree =
832 layer_tree_impl()->property_trees()->transform_tree;
833 TransformNode* node = transform_tree.Node(transform_tree_index_);
834 // A LayerImpl's own current state is insufficient for determining whether
835 // it owns a TransformNode, since this depends on the state of the
836 // corresponding Layer at the time of the last commit. For example, if
837 // |is_animated| is false, this might mean a transform animation just ticked
838 // past its finish point (so the LayerImpl still owns a TransformNode) or it
839 // might mean that a transform animation was removed during commit or
840 // activation (and, in that case, the LayerImpl will no longer own a
841 // TransformNode, unless it has non-animation-related reasons for owning a
842 // node).
843 if (node->owner_id != id())
844 return;
845 if (node->data.is_animated != is_animated) {
846 node->data.is_animated = is_animated;
847 transform_tree.set_needs_update(true);
848 }
849 }
850}
851
ajuma59c23b42015-05-25 20:18:37852void LayerImpl::UpdatePropertyTreeOpacity() {
853 if (opacity_tree_index_ != -1) {
854 OpacityTree& opacity_tree =
855 layer_tree_impl()->property_trees()->opacity_tree;
856 OpacityNode* node = opacity_tree.Node(opacity_tree_index_);
ajumae7425272015-07-13 18:37:34857 // A LayerImpl's own current state is insufficient for determining whether
858 // it owns an OpacityNode, since this depends on the state of the
859 // corresponding Layer at the time of the last commit. For example, an
860 // opacity animation might have been in progress at the time the last commit
861 // started, but might have finished since then on the compositor thread.
862 if (node->owner_id != id())
863 return;
jaydasika9fc1aef2015-06-26 23:35:57864 node->data.opacity = opacity_;
865 opacity_tree.set_needs_update(true);
ajuma59c23b42015-05-25 20:18:37866 }
867}
868
ajuma9db24fb2015-06-29 20:15:07869void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() {
870 if (scrollable())
871 UpdatePropertyTreeScrollOffset();
872
ajumae7425272015-07-13 18:37:34873 if (HasAnyAnimationTargetingProperty(Animation::OPACITY))
ajuma9db24fb2015-06-29 20:15:07874 UpdatePropertyTreeOpacity();
875
ajumacaaa9b32015-08-04 15:55:29876 if (HasAnyAnimationTargetingProperty(Animation::TRANSFORM)) {
ajuma9db24fb2015-06-29 20:15:07877 UpdatePropertyTreeTransform();
ajumacaaa9b32015-08-04 15:55:29878 UpdatePropertyTreeTransformIsAnimated(
879 HasPotentiallyRunningTransformAnimation());
880 }
ajuma9db24fb2015-06-29 20:15:07881}
882
miletusf57925d2014-10-01 19:38:13883gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const {
aeliasd0070ba2015-01-31 13:44:49884 return CurrentScrollOffset();
[email protected]b8384e22013-12-03 02:20:48885}
886
[email protected]b4c6d812013-10-03 15:48:56887void LayerImpl::OnFilterAnimated(const FilterOperations& filters) {
888 SetFilters(filters);
889}
890
[email protected]7aba6662013-03-12 10:17:34891void LayerImpl::OnOpacityAnimated(float opacity) {
892 SetOpacity(opacity);
ajuma59c23b42015-05-25 20:18:37893 UpdatePropertyTreeOpacity();
[email protected]7aba6662013-03-12 10:17:34894}
895
896void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) {
897 SetTransform(transform);
ajuma59c23b42015-05-25 20:18:37898 UpdatePropertyTreeTransform();
[email protected]7aba6662013-03-12 10:17:34899}
900
miletusf57925d2014-10-01 19:38:13901void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
[email protected]b8384e22013-12-03 02:20:48902 // Only layers in the active tree should need to do anything here, since
903 // layers in the pending tree will find out about these changes as a
aeliasd0070ba2015-01-31 13:44:49904 // result of the shared SyncedProperty.
[email protected]b8384e22013-12-03 02:20:48905 if (!IsActive())
906 return;
907
aeliasd0070ba2015-01-31 13:44:49908 SetCurrentScrollOffset(scroll_offset);
[email protected]b8384e22013-12-03 02:20:48909
910 layer_tree_impl_->DidAnimateScrollOffset();
911}
912
[email protected]1c24cf2962013-11-18 23:34:51913void LayerImpl::OnAnimationWaitingForDeletion() {}
914
ajumacaaa9b32015-08-04 15:55:29915void LayerImpl::OnTransformIsPotentiallyAnimatingChanged(bool is_animating) {
916 UpdatePropertyTreeTransformIsAnimated(is_animating);
917}
918
[email protected]7aba6662013-03-12 10:17:34919bool LayerImpl::IsActive() const {
920 return layer_tree_impl_->IsActiveTree();
921}
922
bokancccfde72014-10-08 15:15:22923gfx::Size LayerImpl::bounds() const {
bokanef971462014-10-13 22:58:32924 gfx::Vector2d delta = gfx::ToCeiledVector2d(bounds_delta_);
925 return gfx::Size(bounds_.width() + delta.x(),
926 bounds_.height() + delta.y());
927}
928
929gfx::SizeF LayerImpl::BoundsForScrolling() const {
930 return gfx::SizeF(bounds_.width() + bounds_delta_.x(),
931 bounds_.height() + bounds_delta_.y());
[email protected]fef74fd2014-02-27 06:28:17932}
933
[email protected]64348ea2014-01-29 22:58:26934void LayerImpl::SetBounds(const gfx::Size& bounds) {
[email protected]7aba6662013-03-12 10:17:34935 if (bounds_ == bounds)
936 return;
937
938 bounds_ = bounds;
[email protected]fef74fd2014-02-27 06:28:17939
sataya.m07f11a82014-10-07 14:29:18940 ScrollbarParametersDidChange(true);
[email protected]fef74fd2014-02-27 06:28:17941 if (masks_to_bounds())
942 NoteLayerPropertyChangedForSubtree();
943 else
944 NoteLayerPropertyChanged();
945}
946
[email protected]587941d2014-08-22 01:40:01947void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) {
ajuma6b46da22015-06-25 21:53:02948 DCHECK(IsActive());
[email protected]587941d2014-08-22 01:40:01949 if (bounds_delta_ == bounds_delta)
[email protected]fef74fd2014-02-27 06:28:17950 return;
951
[email protected]587941d2014-08-22 01:40:01952 bounds_delta_ = bounds_delta;
[email protected]7aba6662013-03-12 10:17:34953
ajuma6b46da22015-06-25 21:53:02954 TransformTree& transform_tree =
955 layer_tree_impl()->property_trees()->transform_tree;
ajumadd2802e72015-06-30 20:28:29956 if (this == layer_tree_impl()->InnerViewportContainerLayer())
957 transform_tree.SetInnerViewportBoundsDelta(bounds_delta);
958 else if (this == layer_tree_impl()->OuterViewportContainerLayer())
959 transform_tree.SetOuterViewportBoundsDelta(bounds_delta);
ajuma6b46da22015-06-25 21:53:02960
aelias1505e722014-10-07 22:19:46961 ScrollbarParametersDidChange(true);
miletus8bd08a622015-06-16 18:44:52962
963 if (masks_to_bounds()) {
964 // If layer is clipping, then update the clip node using the new bounds.
965 ClipNode* clip_node =
966 layer_tree_impl()->property_trees()->clip_tree.Node(clip_tree_index());
967 if (clip_node) {
968 DCHECK(id() == clip_node->owner_id);
969 clip_node->data.clip =
970 gfx::RectF(gfx::PointF() + offset_to_transform_parent(), bounds());
971 layer_tree_impl()->property_trees()->clip_tree.set_needs_update(true);
972 }
973
[email protected]7aba6662013-03-12 10:17:34974 NoteLayerPropertyChangedForSubtree();
miletus8bd08a622015-06-16 18:44:52975 } else {
[email protected]7aba6662013-03-12 10:17:34976 NoteLayerPropertyChanged();
miletus8bd08a622015-06-16 18:44:52977 }
[email protected]7aba6662013-03-12 10:17:34978}
979
980void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) {
981 int new_layer_id = mask_layer ? mask_layer->id() : -1;
982
983 if (mask_layer) {
984 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl());
985 DCHECK_NE(new_layer_id, mask_layer_id_);
986 } else if (new_layer_id == mask_layer_id_) {
987 return;
988 }
989
990 mask_layer_ = mask_layer.Pass();
991 mask_layer_id_ = new_layer_id;
992 if (mask_layer_)
[email protected]ad0250b2014-01-18 03:24:34993 mask_layer_->SetParent(this);
[email protected]7aba6662013-03-12 10:17:34994 NoteLayerPropertyChangedForSubtree();
995}
996
997scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() {
998 mask_layer_id_ = -1;
999 return mask_layer_.Pass();
1000}
1001
1002void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) {
1003 int new_layer_id = replica_layer ? replica_layer->id() : -1;
1004
1005 if (replica_layer) {
1006 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl());
1007 DCHECK_NE(new_layer_id, replica_layer_id_);
1008 } else if (new_layer_id == replica_layer_id_) {
1009 return;
1010 }
1011
1012 replica_layer_ = replica_layer.Pass();
1013 replica_layer_id_ = new_layer_id;
1014 if (replica_layer_)
[email protected]ad0250b2014-01-18 03:24:341015 replica_layer_->SetParent(this);
[email protected]7aba6662013-03-12 10:17:341016 NoteLayerPropertyChangedForSubtree();
1017}
1018
1019scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() {
1020 replica_layer_id_ = -1;
1021 return replica_layer_.Pass();
1022}
1023
[email protected]80413d72013-08-30 20:25:331024ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() {
kulkarni.a4015690f12014-10-10 13:50:061025 return nullptr;
[email protected]7aba6662013-03-12 10:17:341026}
1027
1028void LayerImpl::SetDrawsContent(bool draws_content) {
1029 if (draws_content_ == draws_content)
1030 return;
1031
1032 draws_content_ = draws_content;
1033 NoteLayerPropertyChanged();
1034}
1035
[email protected]c0ae06c12013-06-24 18:32:191036void LayerImpl::SetHideLayerAndSubtree(bool hide) {
1037 if (hide_layer_and_subtree_ == hide)
1038 return;
1039
1040 hide_layer_and_subtree_ = hide;
1041 NoteLayerPropertyChangedForSubtree();
1042}
1043
[email protected]a2566412014-06-05 03:14:201044void LayerImpl::SetTransformOrigin(const gfx::Point3F& transform_origin) {
1045 if (transform_origin_ == transform_origin)
[email protected]7aba6662013-03-12 10:17:341046 return;
[email protected]a2566412014-06-05 03:14:201047 transform_origin_ = transform_origin;
[email protected]7aba6662013-03-12 10:17:341048 NoteLayerPropertyChangedForSubtree();
1049}
1050
1051void LayerImpl::SetBackgroundColor(SkColor background_color) {
1052 if (background_color_ == background_color)
1053 return;
1054
1055 background_color_ = background_color;
1056 NoteLayerPropertyChanged();
1057}
1058
[email protected]2c4cbec2013-06-04 21:14:501059SkColor LayerImpl::SafeOpaqueBackgroundColor() const {
1060 SkColor color = background_color();
1061 if (SkColorGetA(color) == 255 && !contents_opaque()) {
1062 color = SK_ColorTRANSPARENT;
1063 } else if (SkColorGetA(color) != 255 && contents_opaque()) {
1064 for (const LayerImpl* layer = parent(); layer;
1065 layer = layer->parent()) {
1066 color = layer->background_color();
1067 if (SkColorGetA(color) == 255)
1068 break;
1069 }
1070 if (SkColorGetA(color) != 255)
1071 color = layer_tree_impl()->background_color();
1072 if (SkColorGetA(color) != 255)
1073 color = SkColorSetA(color, 255);
1074 }
1075 return color;
1076}
1077
[email protected]ae6b1a72013-06-25 18:49:291078void LayerImpl::SetFilters(const FilterOperations& filters) {
[email protected]7aba6662013-03-12 10:17:341079 if (filters_ == filters)
1080 return;
1081
[email protected]7aba6662013-03-12 10:17:341082 filters_ = filters;
1083 NoteLayerPropertyChangedForSubtree();
1084}
1085
[email protected]b4c6d812013-10-03 15:48:561086bool LayerImpl::FilterIsAnimating() const {
ajuma315a4782015-07-24 21:16:341087 LayerAnimationController::ObserverType observer_type =
1088 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1089 : LayerAnimationController::ObserverType::PENDING;
loysod71ece82015-07-03 13:48:501090 return layer_animation_controller_
ajuma315a4782015-07-24 21:16:341091 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
1092 Animation::FILTER, observer_type)
loysod71ece82015-07-03 13:48:501093 : layer_tree_impl_->IsAnimatingFilterProperty(this);
[email protected]b4c6d812013-10-03 15:48:561094}
1095
ajuma315a4782015-07-24 21:16:341096bool LayerImpl::HasPotentiallyRunningFilterAnimation() const {
1097 LayerAnimationController::ObserverType observer_type =
1098 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1099 : LayerAnimationController::ObserverType::PENDING;
1100 return layer_animation_controller_
1101 ? layer_animation_controller_->IsPotentiallyAnimatingProperty(
1102 Animation::FILTER, observer_type)
1103 : layer_tree_impl_->HasPotentiallyRunningFilterAnimation(this);
1104}
1105
[email protected]b4c6d812013-10-03 15:48:561106bool LayerImpl::FilterIsAnimatingOnImplOnly() const {
loysod71ece82015-07-03 13:48:501107 if (!layer_animation_controller_)
1108 return layer_tree_impl_->FilterIsAnimatingOnImplOnly(this);
1109
[email protected]b4c6d812013-10-03 15:48:561110 Animation* filter_animation =
ericrk7c030992015-02-20 01:39:381111 layer_animation_controller_->GetAnimation(Animation::FILTER);
[email protected]b4c6d812013-10-03 15:48:561112 return filter_animation && filter_animation->is_impl_only();
1113}
1114
[email protected]7aba6662013-03-12 10:17:341115void LayerImpl::SetBackgroundFilters(
[email protected]ae6b1a72013-06-25 18:49:291116 const FilterOperations& filters) {
[email protected]7aba6662013-03-12 10:17:341117 if (background_filters_ == filters)
1118 return;
1119
1120 background_filters_ = filters;
1121 NoteLayerPropertyChanged();
1122}
1123
[email protected]7aba6662013-03-12 10:17:341124void LayerImpl::SetMasksToBounds(bool masks_to_bounds) {
1125 if (masks_to_bounds_ == masks_to_bounds)
1126 return;
1127
1128 masks_to_bounds_ = masks_to_bounds;
1129 NoteLayerPropertyChangedForSubtree();
1130}
1131
1132void LayerImpl::SetContentsOpaque(bool opaque) {
1133 if (contents_opaque_ == opaque)
1134 return;
1135
1136 contents_opaque_ = opaque;
1137 NoteLayerPropertyChangedForSubtree();
1138}
1139
1140void LayerImpl::SetOpacity(float opacity) {
1141 if (opacity_ == opacity)
1142 return;
1143
1144 opacity_ = opacity;
[email protected]af37ce802013-10-07 23:53:281145 NoteLayerPropertyChangedForSubtree();
[email protected]7aba6662013-03-12 10:17:341146}
1147
1148bool LayerImpl::OpacityIsAnimating() const {
ajuma315a4782015-07-24 21:16:341149 LayerAnimationController::ObserverType observer_type =
1150 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1151 : LayerAnimationController::ObserverType::PENDING;
loysod71ece82015-07-03 13:48:501152 return layer_animation_controller_
ajuma315a4782015-07-24 21:16:341153 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
1154 Animation::OPACITY, observer_type)
loysod71ece82015-07-03 13:48:501155 : layer_tree_impl_->IsAnimatingOpacityProperty(this);
1156}
1157
1158bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const {
ajuma315a4782015-07-24 21:16:341159 LayerAnimationController::ObserverType observer_type =
1160 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1161 : LayerAnimationController::ObserverType::PENDING;
1162 return layer_animation_controller_
1163 ? layer_animation_controller_->IsPotentiallyAnimatingProperty(
1164 Animation::OPACITY, observer_type)
1165 : layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this);
[email protected]7aba6662013-03-12 10:17:341166}
1167
[email protected]43615872013-03-13 16:35:171168bool LayerImpl::OpacityIsAnimatingOnImplOnly() const {
loysod71ece82015-07-03 13:48:501169 if (!layer_animation_controller_)
1170 return layer_tree_impl_->OpacityIsAnimatingOnImplOnly(this);
1171
[email protected]43615872013-03-13 16:35:171172 Animation* opacity_animation =
ericrk7c030992015-02-20 01:39:381173 layer_animation_controller_->GetAnimation(Animation::OPACITY);
[email protected]43615872013-03-13 16:35:171174 return opacity_animation && opacity_animation->is_impl_only();
1175}
1176
[email protected]7bbeaf4e2013-11-26 10:27:221177void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) {
1178 if (blend_mode_ == blend_mode)
1179 return;
1180
1181 blend_mode_ = blend_mode;
1182 NoteLayerPropertyChangedForSubtree();
1183}
1184
1185void LayerImpl::SetIsRootForIsolatedGroup(bool root) {
1186 if (is_root_for_isolated_group_ == root)
1187 return;
1188
1189 is_root_for_isolated_group_ = root;
[email protected]ad0250b2014-01-18 03:24:341190 SetNeedsPushProperties();
[email protected]7bbeaf4e2013-11-26 10:27:221191}
1192
[email protected]14bc5d682014-01-17 07:26:471193void LayerImpl::SetPosition(const gfx::PointF& position) {
[email protected]7aba6662013-03-12 10:17:341194 if (position_ == position)
1195 return;
1196
1197 position_ = position;
1198 NoteLayerPropertyChangedForSubtree();
1199}
1200
[email protected]56fffdd2014-02-11 19:50:571201void LayerImpl::SetShouldFlattenTransform(bool flatten) {
1202 if (should_flatten_transform_ == flatten)
[email protected]7aba6662013-03-12 10:17:341203 return;
1204
[email protected]56fffdd2014-02-11 19:50:571205 should_flatten_transform_ = flatten;
1206 NoteLayerPropertyChangedForSubtree();
1207}
1208
[email protected]a9d4d4f2014-06-19 06:49:281209void LayerImpl::Set3dSortingContextId(int id) {
1210 if (id == sorting_context_id_)
[email protected]56fffdd2014-02-11 19:50:571211 return;
[email protected]a9d4d4f2014-06-19 06:49:281212 sorting_context_id_ = id;
[email protected]7aba6662013-03-12 10:17:341213 NoteLayerPropertyChangedForSubtree();
1214}
1215
vmpstr3a24da5042015-05-27 03:33:311216void LayerImpl::SetFrameTimingRequests(
1217 const std::vector<FrameTimingRequest>& requests) {
1218 frame_timing_requests_ = requests;
vmpstr3d1d72c2015-01-26 18:27:401219 frame_timing_requests_dirty_ = true;
1220 SetNeedsPushProperties();
1221}
1222
vmpstrd704c872015-04-03 20:29:511223void LayerImpl::GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids) {
1224 for (const auto& request : frame_timing_requests_)
1225 request_ids->push_back(request.id());
1226}
1227
[email protected]7aba6662013-03-12 10:17:341228void LayerImpl::SetTransform(const gfx::Transform& transform) {
1229 if (transform_ == transform)
1230 return;
1231
1232 transform_ = transform;
[email protected]08bdf1b2014-04-16 23:23:291233 transform_is_invertible_ = transform_.IsInvertible();
1234 NoteLayerPropertyChangedForSubtree();
1235}
1236
1237void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform,
1238 bool transform_is_invertible) {
1239 if (transform_ == transform) {
1240 DCHECK(transform_is_invertible_ == transform_is_invertible)
1241 << "Can't change invertibility if transform is unchanged";
1242 return;
1243 }
1244 transform_ = transform;
1245 transform_is_invertible_ = transform_is_invertible;
[email protected]af37ce802013-10-07 23:53:281246 NoteLayerPropertyChangedForSubtree();
[email protected]7aba6662013-03-12 10:17:341247}
1248
1249bool LayerImpl::TransformIsAnimating() const {
ajuma315a4782015-07-24 21:16:341250 LayerAnimationController::ObserverType observer_type =
1251 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1252 : LayerAnimationController::ObserverType::PENDING;
loysod71ece82015-07-03 13:48:501253 return layer_animation_controller_
ajuma315a4782015-07-24 21:16:341254 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
1255 Animation::TRANSFORM, observer_type)
loysod71ece82015-07-03 13:48:501256 : layer_tree_impl_->IsAnimatingTransformProperty(this);
1257}
1258
1259bool LayerImpl::HasPotentiallyRunningTransformAnimation() const {
ajuma315a4782015-07-24 21:16:341260 LayerAnimationController::ObserverType observer_type =
1261 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1262 : LayerAnimationController::ObserverType::PENDING;
1263 return layer_animation_controller_
1264 ? layer_animation_controller_->IsPotentiallyAnimatingProperty(
1265 Animation::TRANSFORM, observer_type)
1266 : layer_tree_impl_->HasPotentiallyRunningTransformAnimation(this);
[email protected]7aba6662013-03-12 10:17:341267}
1268
[email protected]43615872013-03-13 16:35:171269bool LayerImpl::TransformIsAnimatingOnImplOnly() const {
loysod71ece82015-07-03 13:48:501270 if (!layer_animation_controller_)
1271 return layer_tree_impl_->TransformIsAnimatingOnImplOnly(this);
1272
[email protected]43615872013-03-13 16:35:171273 Animation* transform_animation =
ericrk7c030992015-02-20 01:39:381274 layer_animation_controller_->GetAnimation(Animation::TRANSFORM);
[email protected]43615872013-03-13 16:35:171275 return transform_animation && transform_animation->is_impl_only();
1276}
1277
loysod71ece82015-07-03 13:48:501278bool LayerImpl::HasOnlyTranslationTransforms() const {
1279 if (!layer_animation_controller_)
1280 return layer_tree_impl_->HasOnlyTranslationTransforms(this);
1281
1282 return layer_animation_controller_->HasOnlyTranslationTransforms();
1283}
1284
1285bool LayerImpl::MaximumTargetScale(float* max_scale) const {
1286 if (!layer_animation_controller_)
1287 return layer_tree_impl_->MaximumTargetScale(this, max_scale);
1288
1289 return layer_animation_controller_->MaximumTargetScale(max_scale);
1290}
1291
1292bool LayerImpl::AnimationStartScale(float* start_scale) const {
1293 if (!layer_animation_controller_)
1294 return layer_tree_impl_->AnimationStartScale(this, start_scale);
1295
1296 return layer_animation_controller_->AnimationStartScale(start_scale);
1297}
1298
ajumae7425272015-07-13 18:37:341299bool LayerImpl::HasAnyAnimationTargetingProperty(
1300 Animation::TargetProperty property) const {
1301 if (!layer_animation_controller_)
1302 return layer_tree_impl_->HasAnyAnimationTargetingProperty(this, property);
1303
1304 return !!layer_animation_controller_->GetAnimation(property);
1305}
1306
loysod71ece82015-07-03 13:48:501307bool LayerImpl::HasFilterAnimationThatInflatesBounds() const {
1308 if (!layer_animation_controller_)
1309 return layer_tree_impl_->HasFilterAnimationThatInflatesBounds(this);
1310
1311 return layer_animation_controller_->HasFilterAnimationThatInflatesBounds();
1312}
1313
1314bool LayerImpl::HasTransformAnimationThatInflatesBounds() const {
1315 if (!layer_animation_controller_)
1316 return layer_tree_impl_->HasTransformAnimationThatInflatesBounds(this);
1317
1318 return layer_animation_controller_->HasTransformAnimationThatInflatesBounds();
1319}
1320
1321bool LayerImpl::HasAnimationThatInflatesBounds() const {
1322 if (!layer_animation_controller_)
1323 return layer_tree_impl_->HasAnimationThatInflatesBounds(this);
1324
1325 return layer_animation_controller_->HasAnimationThatInflatesBounds();
1326}
1327
1328bool LayerImpl::FilterAnimationBoundsForBox(const gfx::BoxF& box,
1329 gfx::BoxF* bounds) const {
1330 if (!layer_animation_controller_)
1331 return layer_tree_impl_->FilterAnimationBoundsForBox(this, box, bounds);
1332
1333 return layer_animation_controller_->FilterAnimationBoundsForBox(box, bounds);
1334}
1335
1336bool LayerImpl::TransformAnimationBoundsForBox(const gfx::BoxF& box,
1337 gfx::BoxF* bounds) const {
1338 if (!layer_animation_controller_)
1339 return layer_tree_impl_->TransformAnimationBoundsForBox(this, box, bounds);
1340
1341 return layer_animation_controller_->TransformAnimationBoundsForBox(box,
1342 bounds);
1343}
1344
danakj19f0c9e2014-10-11 03:24:421345void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) {
[email protected]ad0250b2014-01-18 03:24:341346 update_rect_ = update_rect;
1347 SetNeedsPushProperties();
1348}
1349
[email protected]cfa7fd922014-04-29 11:50:031350void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) {
1351 damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect);
1352}
1353
hushb0ee8dc2015-06-10 00:48:571354bool LayerImpl::IsExternalScrollActive() const {
1355 return layer_tree_impl_->IsExternalScrollActive();
[email protected]251699b2013-10-09 00:21:261356}
1357
aeliasd0070ba2015-01-31 13:44:491358void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) {
1359 DCHECK(IsActive());
1360 if (scroll_offset_->SetCurrent(scroll_offset))
hush33370e12015-04-07 03:49:501361 DidUpdateScrollOffset(false);
1362}
1363
1364void LayerImpl::SetCurrentScrollOffsetFromDelegate(
1365 const gfx::ScrollOffset& scroll_offset) {
1366 DCHECK(IsActive());
1367 if (scroll_offset_->SetCurrent(scroll_offset))
1368 DidUpdateScrollOffset(true);
boliu7d5dbab2014-10-10 20:05:471369}
1370
aeliasd0070ba2015-01-31 13:44:491371void LayerImpl::PushScrollOffsetFromMainThread(
1372 const gfx::ScrollOffset& scroll_offset) {
1373 PushScrollOffset(&scroll_offset);
[email protected]b34c97982013-08-24 15:21:381374}
[email protected]7aba6662013-03-12 10:17:341375
danakjb5197d32015-02-03 23:39:491376void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1377 const gfx::ScrollOffset& scroll_offset) {
1378 scroll_offset_->set_clobber_active_value();
1379 PushScrollOffset(&scroll_offset);
1380}
1381
aeliasd0070ba2015-01-31 13:44:491382gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() {
miletusd799dd22015-03-19 04:23:171383 // TODO(miletus): Remove all this temporary flooring machinery when
1384 // Blink fully supports fractional scrolls.
1385 gfx::ScrollOffset current_offset = CurrentScrollOffset();
bokan5a025bd62015-07-20 11:08:201386 gfx::ScrollOffset current_delta = IsActive()
1387 ? scroll_offset_->Delta()
1388 : scroll_offset_->PendingDelta().get();
1389 gfx::ScrollOffset floored_delta(floor(current_delta.x()),
1390 floor(current_delta.y()));
1391 gfx::ScrollOffset diff_delta = floored_delta - current_delta;
1392 gfx::ScrollOffset tmp_offset = current_offset + diff_delta;
miletusd799dd22015-03-19 04:23:171393 scroll_offset_->SetCurrent(tmp_offset);
1394 gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread();
1395 scroll_offset_->SetCurrent(current_offset);
1396 return delta;
aeliasd0070ba2015-01-31 13:44:491397}
[email protected]adeda572014-01-31 00:49:471398
aeliasd0070ba2015-01-31 13:44:491399gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const {
1400 return scroll_offset_->Current(IsActive());
[email protected]7aba6662013-03-12 10:17:341401}
1402
[email protected]1960a712013-04-30 17:06:471403gfx::Vector2dF LayerImpl::ScrollDelta() const {
aeliasd0070ba2015-01-31 13:44:491404 if (IsActive())
1405 return gfx::Vector2dF(scroll_offset_->Delta().x(),
1406 scroll_offset_->Delta().y());
1407 else
1408 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(),
1409 scroll_offset_->PendingDelta().get().y());
1410}
1411
1412void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) {
1413 DCHECK(IsActive());
ajuma5e47dec2015-05-29 22:10:231414 DCHECK(scrollable() || delta.IsZero());
aeliasd0070ba2015-01-31 13:44:491415 SetCurrentScrollOffset(scroll_offset_->ActiveBase() +
1416 gfx::ScrollOffset(delta));
1417}
1418
1419gfx::ScrollOffset LayerImpl::BaseScrollOffset() const {
1420 if (IsActive())
1421 return scroll_offset_->ActiveBase();
1422 else
1423 return scroll_offset_->PendingBase();
1424}
1425
1426void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) {
1427 DCHECK(scroll_offset || IsActive());
1428 bool changed = false;
1429 if (scroll_offset) {
1430 DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id()));
1431 changed |= scroll_offset_->PushFromMainThread(*scroll_offset);
miletusf57925d2014-10-01 19:38:131432 }
aeliasd0070ba2015-01-31 13:44:491433 if (IsActive()) {
1434 changed |= scroll_offset_->PushPendingToActive();
aeliasd0070ba2015-01-31 13:44:491435 }
1436
1437 if (changed)
hush33370e12015-04-07 03:49:501438 DidUpdateScrollOffset(false);
[email protected]1960a712013-04-30 17:06:471439}
1440
ajuma9db24fb2015-06-29 20:15:071441void LayerImpl::UpdatePropertyTreeScrollOffset() {
enne1eb3a922015-06-17 17:37:501442 // TODO(enne): in the future, scrolling should update the scroll tree
1443 // directly instead of going through layers.
1444 if (transform_tree_index_ != -1) {
1445 TransformTree& transform_tree =
1446 layer_tree_impl()->property_trees()->transform_tree;
1447 TransformNode* node = transform_tree.Node(transform_tree_index_);
1448 gfx::ScrollOffset current_offset = scroll_offset_->Current(IsActive());
1449 if (node->data.scroll_offset != current_offset) {
1450 node->data.scroll_offset = current_offset;
1451 node->data.needs_local_transform_update = true;
1452 transform_tree.set_needs_update(true);
1453 }
1454 }
1455}
1456
hush33370e12015-04-07 03:49:501457void LayerImpl::DidUpdateScrollOffset(bool is_from_root_delegate) {
enne04192cf92015-05-20 00:32:221458 DCHECK(scroll_offset_);
1459
hush33370e12015-04-07 03:49:501460 if (!is_from_root_delegate)
1461 layer_tree_impl()->DidUpdateScrollOffset(id());
aeliasd0070ba2015-01-31 13:44:491462 NoteLayerPropertyChangedForSubtree();
1463 ScrollbarParametersDidChange(false);
enne04192cf92015-05-20 00:32:221464
ajuma9db24fb2015-06-29 20:15:071465 UpdatePropertyTreeScrollOffset();
enne04192cf92015-05-20 00:32:221466
vmpstre86240822015-05-11 21:10:111467 // Inform the pending twin that a property changed.
1468 if (layer_tree_impl()->IsActiveTree()) {
1469 LayerImpl* pending_twin = layer_tree_impl()->FindPendingTreeLayerById(id());
1470 if (pending_twin)
enne04192cf92015-05-20 00:32:221471 pending_twin->DidUpdateScrollOffset(is_from_root_delegate);
vmpstre86240822015-05-11 21:10:111472 }
[email protected]ffb2720f2013-03-15 19:18:371473}
1474
[email protected]7aba6662013-03-12 10:17:341475void LayerImpl::SetDoubleSided(bool double_sided) {
1476 if (double_sided_ == double_sided)
1477 return;
1478
1479 double_sided_ = double_sided;
1480 NoteLayerPropertyChangedForSubtree();
1481}
1482
danakj64767d902015-06-19 00:10:431483SimpleEnclosedRegion LayerImpl::VisibleOpaqueRegion() const {
[email protected]7aba6662013-03-12 10:17:341484 if (contents_opaque())
danakj64767d902015-06-19 00:10:431485 return SimpleEnclosedRegion(visible_layer_rect());
[email protected]d5467eb72014-08-22 01:16:431486 return SimpleEnclosedRegion();
[email protected]7aba6662013-03-12 10:17:341487}
1488
[email protected]37349bc2013-06-04 01:31:521489void LayerImpl::DidBeginTracing() {}
1490
[email protected]9db24462014-01-14 02:25:501491void LayerImpl::ReleaseResources() {}
[email protected]7aba6662013-03-12 10:17:341492
vmpstr9ce5c662015-02-05 23:29:261493void LayerImpl::RecreateResources() {
1494}
1495
miletusf57925d2014-10-01 19:38:131496gfx::ScrollOffset LayerImpl::MaxScrollOffset() const {
[email protected]adeda572014-01-31 00:49:471497 if (!scroll_clip_layer_ || bounds().IsEmpty())
miletusf57925d2014-10-01 19:38:131498 return gfx::ScrollOffset();
[email protected]610834cb2014-01-29 13:54:331499
aeliasc26b50b72015-07-14 20:18:251500 LayerImpl const* page_scale_layer = layer_tree_impl()->PageScaleLayer();
[email protected]adeda572014-01-31 00:49:471501 DCHECK(this != page_scale_layer);
[email protected]adeda572014-01-31 00:49:471502 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1503 IsContainerForFixedPositionLayers());
1504
[email protected]adeda572014-01-31 00:49:471505 float scale_factor = 1.f;
1506 for (LayerImpl const* current_layer = this;
aeliasd0070ba2015-01-31 13:44:491507 current_layer != scroll_clip_layer_->parent();
[email protected]adeda572014-01-31 00:49:471508 current_layer = current_layer->parent()) {
aeliasd0070ba2015-01-31 13:44:491509 if (current_layer == page_scale_layer)
1510 scale_factor = layer_tree_impl()->current_page_scale_factor();
[email protected]adeda572014-01-31 00:49:471511 }
[email protected]adeda572014-01-31 00:49:471512
aeliasd0070ba2015-01-31 13:44:491513 gfx::SizeF scaled_scroll_bounds =
1514 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor));
[email protected]0072c112014-04-22 05:53:401515 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds);
[email protected]adeda572014-01-31 00:49:471516
miletusf57925d2014-10-01 19:38:131517 gfx::ScrollOffset max_offset(
[email protected]adeda572014-01-31 00:49:471518 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(),
1519 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height());
1520 // We need the final scroll offset to be in CSS coords.
1521 max_offset.Scale(1 / scale_factor);
miletusf57925d2014-10-01 19:38:131522 max_offset.SetToMax(gfx::ScrollOffset());
1523 return max_offset;
[email protected]adeda572014-01-31 00:49:471524}
1525
aeliasd0070ba2015-01-31 13:44:491526gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits(
1527 gfx::ScrollOffset offset) const {
1528 offset.SetToMin(MaxScrollOffset());
1529 offset.SetToMax(gfx::ScrollOffset());
1530 return offset;
1531}
[email protected]adeda572014-01-31 00:49:471532
aeliasd0070ba2015-01-31 13:44:491533gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() {
1534 gfx::ScrollOffset old_offset = CurrentScrollOffset();
1535 gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset);
miletusf57925d2014-10-01 19:38:131536 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset);
[email protected]adeda572014-01-31 00:49:471537 if (!delta.IsZero())
1538 ScrollBy(delta);
[email protected]adeda572014-01-31 00:49:471539 return delta;
1540}
1541
1542void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
sataya.m07f11a82014-10-07 14:29:181543 LayerImpl* scrollbar_clip_layer,
1544 bool on_resize) const {
[email protected]adeda572014-01-31 00:49:471545 DCHECK(scrollbar_layer);
aeliasc26b50b72015-07-14 20:18:251546 LayerImpl* page_scale_layer = layer_tree_impl()->PageScaleLayer();
[email protected]adeda572014-01-31 00:49:471547
1548 DCHECK(this != page_scale_layer);
1549 DCHECK(scrollbar_clip_layer);
bokanef971462014-10-13 22:58:321550 gfx::RectF clip_rect(gfx::PointF(),
1551 scrollbar_clip_layer->BoundsForScrolling());
[email protected]adeda572014-01-31 00:49:471552
1553 // See comment in MaxScrollOffset() regarding the use of the content layer
1554 // bounds here.
bokanef971462014-10-13 22:58:321555 gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling());
[email protected]adeda572014-01-31 00:49:471556
1557 if (scroll_rect.size().IsEmpty())
1558 return;
1559
miletusf57925d2014-10-01 19:38:131560 gfx::ScrollOffset current_offset;
[email protected]adeda572014-01-31 00:49:471561 for (LayerImpl const* current_layer = this;
aeliasd0070ba2015-01-31 13:44:491562 current_layer != scrollbar_clip_layer->parent();
[email protected]adeda572014-01-31 00:49:471563 current_layer = current_layer->parent()) {
aeliasd0070ba2015-01-31 13:44:491564 current_offset += current_layer->CurrentScrollOffset();
[email protected]adeda572014-01-31 00:49:471565 if (current_layer == page_scale_layer) {
aelias58eec0812014-12-04 01:04:401566 float scale_factor = layer_tree_impl()->current_page_scale_factor();
[email protected]adeda572014-01-31 00:49:471567 current_offset.Scale(scale_factor);
1568 scroll_rect.Scale(scale_factor);
[email protected]adeda572014-01-31 00:49:471569 }
1570 }
[email protected]adeda572014-01-31 00:49:471571
sataya.m68d7d9b42014-09-22 16:01:591572 bool scrollbar_needs_animation = false;
1573 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust(
1574 scrollbar_clip_layer->bounds_delta().y());
[email protected]adeda572014-01-31 00:49:471575 if (scrollbar_layer->orientation() == HORIZONTAL) {
1576 float visible_ratio = clip_rect.width() / scroll_rect.width();
sataya.m68d7d9b42014-09-22 16:01:591577 scrollbar_needs_animation |=
1578 scrollbar_layer->SetCurrentPos(current_offset.x());
1579 scrollbar_needs_animation |=
1580 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width());
1581 scrollbar_needs_animation |=
1582 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
[email protected]adeda572014-01-31 00:49:471583 } else {
1584 float visible_ratio = clip_rect.height() / scroll_rect.height();
wjmaclean56f35ff2015-03-25 23:59:351585 bool y_offset_did_change =
sataya.m68d7d9b42014-09-22 16:01:591586 scrollbar_layer->SetCurrentPos(current_offset.y());
wjmaclean56f35ff2015-03-25 23:59:351587 scrollbar_needs_animation |= y_offset_did_change;
sataya.m68d7d9b42014-09-22 16:01:591588 scrollbar_needs_animation |=
1589 scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height());
1590 scrollbar_needs_animation |=
1591 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
wjmaclean56f35ff2015-03-25 23:59:351592 if (y_offset_did_change && layer_tree_impl()->IsActiveTree() &&
wjmaclean32332692015-07-22 20:48:431593 this == layer_tree_impl()->OuterViewportScrollLayer()) {
wjmaclean56f35ff2015-03-25 23:59:351594 TRACE_COUNTER_ID1("cc", "scroll_offset_y", this->id(),
1595 current_offset.y());
1596 }
[email protected]adeda572014-01-31 00:49:471597 }
sataya.m7acc4b32014-09-23 15:37:211598 if (scrollbar_needs_animation) {
1599 layer_tree_impl()->set_needs_update_draw_properties();
1600 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars
1601 // should activate for every scroll on the main frame, not just the
1602 // scrolls that move the pinch virtual viewport (i.e. trigger from
1603 // either inner or outer viewport).
1604 if (scrollbar_animation_controller_) {
bokanc784a6f2015-01-28 04:11:501605 // Non-overlay scrollbars shouldn't trigger animations.
1606 if (scrollbar_layer->is_overlay_scrollbar())
sataya.m07f11a82014-10-07 14:29:181607 scrollbar_animation_controller_->DidScrollUpdate(on_resize);
sataya.m7acc4b32014-09-23 15:37:211608 }
[email protected]adeda572014-01-31 00:49:471609 }
[email protected]7aba6662013-03-12 10:17:341610}
1611
[email protected]7aba6662013-03-12 10:17:341612void LayerImpl::DidBecomeActive() {
[email protected]fea161872013-08-27 22:34:591613 if (layer_tree_impl_->settings().scrollbar_animator ==
ericrk7c030992015-02-20 01:39:381614 LayerTreeSettings::NO_ANIMATOR) {
[email protected]7aba6662013-03-12 10:17:341615 return;
[email protected]fea161872013-08-27 22:34:591616 }
[email protected]7aba6662013-03-12 10:17:341617
[email protected]adeda572014-01-31 00:49:471618 bool need_scrollbar_animation_controller = scrollable() && scrollbars_;
[email protected]fea161872013-08-27 22:34:591619 if (!need_scrollbar_animation_controller) {
danakjf446a072014-09-27 21:55:481620 scrollbar_animation_controller_ = nullptr;
[email protected]fea161872013-08-27 22:34:591621 return;
1622 }
1623
1624 if (scrollbar_animation_controller_)
1625 return;
1626
[email protected]930ff43b2014-05-02 05:24:001627 scrollbar_animation_controller_ =
1628 layer_tree_impl_->CreateScrollbarAnimationController(this);
[email protected]e45638c2013-01-17 22:01:401629}
[email protected]ad0250b2014-01-18 03:24:341630
[email protected]adeda572014-01-31 00:49:471631void LayerImpl::ClearScrollbars() {
1632 if (!scrollbars_)
1633 return;
1634
kulkarni.a4015690f12014-10-10 13:50:061635 scrollbars_.reset(nullptr);
[email protected]94f206c12012-08-25 00:09:141636}
1637
[email protected]adeda572014-01-31 00:49:471638void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) {
1639 DCHECK(layer);
1640 DCHECK(!scrollbars_ || scrollbars_->find(layer) == scrollbars_->end());
1641 if (!scrollbars_)
1642 scrollbars_.reset(new ScrollbarSet());
1643
1644 scrollbars_->insert(layer);
1645}
1646
1647void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) {
1648 DCHECK(scrollbars_);
1649 DCHECK(layer);
1650 DCHECK(scrollbars_->find(layer) != scrollbars_->end());
1651
1652 scrollbars_->erase(layer);
1653 if (scrollbars_->empty())
danakjf446a072014-09-27 21:55:481654 scrollbars_ = nullptr;
[email protected]adeda572014-01-31 00:49:471655}
1656
1657bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const {
1658 if (!scrollbars_)
1659 return false;
1660
1661 for (ScrollbarSet::iterator it = scrollbars_->begin();
1662 it != scrollbars_->end();
1663 ++it)
1664 if ((*it)->orientation() == orientation)
1665 return true;
1666
1667 return false;
1668}
1669
sataya.m07f11a82014-10-07 14:29:181670void LayerImpl::ScrollbarParametersDidChange(bool on_resize) {
[email protected]adeda572014-01-31 00:49:471671 if (!scrollbars_)
1672 return;
1673
1674 for (ScrollbarSet::iterator it = scrollbars_->begin();
1675 it != scrollbars_->end();
aelias1505e722014-10-07 22:19:461676 ++it) {
1677 bool is_scroll_layer = (*it)->ScrollLayerId() == layer_id_;
1678 bool scroll_layer_resized = is_scroll_layer && on_resize;
1679 (*it)->ScrollbarParametersDidChange(scroll_layer_resized);
1680 }
[email protected]94f206c12012-08-25 00:09:141681}
1682
[email protected]ad0250b2014-01-18 03:24:341683void LayerImpl::SetNeedsPushProperties() {
1684 if (needs_push_properties_)
1685 return;
1686 if (!parent_should_know_need_push_properties() && parent_)
1687 parent_->AddDependentNeedsPushProperties();
1688 needs_push_properties_ = true;
1689}
1690
1691void LayerImpl::AddDependentNeedsPushProperties() {
1692 DCHECK_GE(num_dependents_need_push_properties_, 0);
1693
1694 if (!parent_should_know_need_push_properties() && parent_)
1695 parent_->AddDependentNeedsPushProperties();
1696
1697 num_dependents_need_push_properties_++;
1698}
1699
1700void LayerImpl::RemoveDependentNeedsPushProperties() {
1701 num_dependents_need_push_properties_--;
1702 DCHECK_GE(num_dependents_need_push_properties_, 0);
1703
1704 if (!parent_should_know_need_push_properties() && parent_)
1705 parent_->RemoveDependentNeedsPushProperties();
1706}
1707
hendrikwc5e915852015-05-13 01:29:031708void LayerImpl::GetAllPrioritizedTilesForTracing(
1709 std::vector<PrioritizedTile>* prioritized_tiles) const {
vmpstrd7de03c2014-08-27 18:11:011710}
1711
ssid911e40e2015-02-09 17:55:201712void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
[email protected]f5ad4282014-02-15 14:23:161713 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
1714 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
[email protected]b4dc36472014-02-26 02:48:251715 state,
1716 "cc::LayerImpl",
1717 LayerTypeAsString(),
1718 this);
[email protected]f6742f52013-05-08 23:52:221719 state->SetInteger("layer_id", id());
jungjik.lee50f9c8e2015-01-21 14:06:161720 MathUtil::AddToTracedValue("bounds", bounds_, state);
[email protected]d12aa932014-08-01 13:10:381721
danakj38955562014-09-13 02:56:431722 state->SetDouble("opacity", opacity());
1723
jungjik.lee50f9c8e2015-01-21 14:06:161724 MathUtil::AddToTracedValue("position", position_, state);
[email protected]d12aa932014-08-01 13:10:381725
[email protected]f6742f52013-05-08 23:52:221726 state->SetInteger("draws_content", DrawsContent());
vmpstr91e23092015-06-08 22:24:161727 state->SetInteger("gpu_memory_usage",
1728 base::saturated_cast<int>(GPUMemoryUsageInBytes()));
[email protected]d12aa932014-08-01 13:10:381729
aeliasd0070ba2015-01-31 13:44:491730 MathUtil::AddToTracedValue(
1731 "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive())
1732 : gfx::ScrollOffset(),
1733 state);
1734
jungjik.lee50f9c8e2015-01-21 14:06:161735 MathUtil::AddToTracedValue("transform_origin", transform_origin_, state);
[email protected]8c5690222013-02-15 17:36:431736
[email protected]7aba6662013-03-12 10:17:341737 bool clipped;
[email protected]fa816c62013-03-18 04:24:211738 gfx::QuadF layer_quad = MathUtil::MapQuad(
Dana Jansensc46d3742015-06-18 01:33:141739 screen_space_transform(), gfx::QuadF(gfx::Rect(bounds())), &clipped);
jungjik.lee50f9c8e2015-01-21 14:06:161740 MathUtil::AddToTracedValue("layer_quad", layer_quad, state);
[email protected]78d78612013-09-12 18:04:041741 if (!touch_event_handler_region_.IsEmpty()) {
[email protected]d12aa932014-08-01 13:10:381742 state->BeginArray("touch_event_handler_region");
1743 touch_event_handler_region_.AsValueInto(state);
1744 state->EndArray();
[email protected]78d78612013-09-12 18:04:041745 }
1746 if (have_wheel_event_handlers_) {
Dana Jansensc46d3742015-06-18 01:33:141747 gfx::Rect wheel_rect(bounds());
[email protected]78d78612013-09-12 18:04:041748 Region wheel_region(wheel_rect);
[email protected]d12aa932014-08-01 13:10:381749 state->BeginArray("wheel_event_handler_region");
1750 wheel_region.AsValueInto(state);
1751 state->EndArray();
[email protected]78d78612013-09-12 18:04:041752 }
[email protected]f998c532014-03-31 20:02:511753 if (have_scroll_event_handlers_) {
Dana Jansensc46d3742015-06-18 01:33:141754 gfx::Rect scroll_rect(bounds());
[email protected]f998c532014-03-31 20:02:511755 Region scroll_region(scroll_rect);
[email protected]d12aa932014-08-01 13:10:381756 state->BeginArray("scroll_event_handler_region");
1757 scroll_region.AsValueInto(state);
1758 state->EndArray();
[email protected]f998c532014-03-31 20:02:511759 }
[email protected]78d78612013-09-12 18:04:041760 if (!non_fast_scrollable_region_.IsEmpty()) {
[email protected]d12aa932014-08-01 13:10:381761 state->BeginArray("non_fast_scrollable_region");
1762 non_fast_scrollable_region_.AsValueInto(state);
1763 state->EndArray();
[email protected]78d78612013-09-12 18:04:041764 }
rbyers18779d822015-02-05 06:22:061765 if (scroll_blocks_on_) {
1766 state->SetInteger("scroll_blocks_on", scroll_blocks_on_);
1767 }
[email protected]f6742f52013-05-08 23:52:221768
[email protected]d12aa932014-08-01 13:10:381769 state->BeginArray("children");
1770 for (size_t i = 0; i < children_.size(); ++i) {
1771 state->BeginDictionary();
1772 children_[i]->AsValueInto(state);
1773 state->EndDictionary();
1774 }
1775 state->EndArray();
1776 if (mask_layer_) {
1777 state->BeginDictionary("mask_layer");
1778 mask_layer_->AsValueInto(state);
1779 state->EndDictionary();
1780 }
1781 if (replica_layer_) {
1782 state->BeginDictionary("replica_layer");
1783 replica_layer_->AsValueInto(state);
1784 state->EndDictionary();
1785 }
[email protected]0e98cdd2013-08-23 00:44:301786
1787 if (scroll_parent_)
1788 state->SetInteger("scroll_parent", scroll_parent_->id());
1789
1790 if (clip_parent_)
1791 state->SetInteger("clip_parent", clip_parent_->id());
[email protected]c2a56ff2013-10-14 19:32:511792
1793 state->SetBoolean("can_use_lcd_text", can_use_lcd_text());
1794 state->SetBoolean("contents_opaque", contents_opaque());
[email protected]a1286742013-11-13 17:11:401795
[email protected]3d86dd7a2014-01-24 01:33:111796 state->SetBoolean(
1797 "has_animation_bounds",
loysod71ece82015-07-03 13:48:501798 layer_animation_controller_
1799 ? layer_animation_controller_->HasAnimationThatInflatesBounds()
1800 : layer_tree_impl_->HasAnimationThatInflatesBounds(this));
[email protected]3d86dd7a2014-01-24 01:33:111801
1802 gfx::BoxF box;
jungjik.lee50f9c8e2015-01-21 14:06:161803 if (LayerUtils::GetAnimationBounds(*this, &box))
1804 MathUtil::AddToTracedValue("animation_bounds", box, state);
[email protected]9f3be432013-12-03 03:53:221805
1806 if (debug_info_.get()) {
1807 std::string str;
1808 debug_info_->AppendAsTraceFormat(&str);
1809 base::JSONReader json_reader;
[email protected]685de6b12014-01-09 12:25:051810 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str));
1811
[email protected]478224312014-01-10 17:33:471812 if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) {
kulkarni.a4015690f12014-10-10 13:50:061813 base::DictionaryValue* dictionary_value = nullptr;
[email protected]685de6b12014-01-09 12:25:051814 bool converted_to_dictionary =
1815 debug_info_value->GetAsDictionary(&dictionary_value);
1816 DCHECK(converted_to_dictionary);
[email protected]d12aa932014-08-01 13:10:381817 for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd();
1818 it.Advance()) {
estade7bc801fb2015-05-07 01:53:081819 state->SetValue(it.key().data(), it.value().CreateDeepCopy());
[email protected]d12aa932014-08-01 13:10:381820 }
[email protected]685de6b12014-01-09 12:25:051821 } else {
1822 NOTREACHED();
1823 }
[email protected]9f3be432013-12-03 03:53:221824 }
vmpstr3d1d72c2015-01-26 18:27:401825
1826 if (!frame_timing_requests_.empty()) {
1827 state->BeginArray("frame_timing_requests");
1828 for (const auto& request : frame_timing_requests_) {
1829 state->BeginDictionary();
1830 state->SetInteger("request_id", request.id());
1831 MathUtil::AddToTracedValue("request_rect", request.rect(), state);
1832 state->EndDictionary();
1833 }
1834 state->EndArray();
1835 }
[email protected]8c5690222013-02-15 17:36:431836}
1837
[email protected]390bb1ff2014-05-09 17:14:401838bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const {
1839 return draw_properties_.last_drawn_render_surface_layer_list_id ==
1840 layer_tree_impl_->current_render_surface_list_id();
1841}
1842
[email protected]cdf5b952013-05-15 15:39:291843size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1844
[email protected]5e5648a2013-11-18 00:39:331845void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1846 benchmark->RunOnLayer(this);
1847}
[email protected]749cbc62014-07-10 01:06:351848
[email protected]ad63b2f2014-08-11 17:39:541849int LayerImpl::NumDescendantsThatDrawContent() const {
1850 return num_descendants_that_draw_content_;
1851}
1852
[email protected]749cbc62014-07-10 01:06:351853void LayerImpl::NotifyAnimationFinished(
1854 base::TimeTicks monotonic_time,
dstockwellaf2a117b2014-10-16 21:42:291855 Animation::TargetProperty target_property,
1856 int group) {
ericrk7c030992015-02-20 01:39:381857 if (target_property == Animation::SCROLL_OFFSET)
[email protected]749cbc62014-07-10 01:06:351858 layer_tree_impl_->InputScrollAnimationFinished();
1859}
1860
awoloszyne83f28c2014-12-22 15:40:001861void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) {
1862 if (!!render_surface() == should_have_render_surface)
1863 return;
1864
1865 SetNeedsPushProperties();
1866 layer_tree_impl()->set_needs_update_draw_properties();
1867 if (should_have_render_surface) {
1868 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this));
1869 return;
1870 }
1871 render_surface_.reset();
1872}
1873
daplatz350219e2015-03-04 19:04:411874Region LayerImpl::GetInvalidationRegion() {
1875 return Region(update_rect_);
1876}
1877
vmpstrd46a7ac2015-03-18 01:11:121878gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const {
1879 return MathUtil::MapEnclosingClippedRect(
Dana Jansensc46d3742015-06-18 01:33:141880 draw_properties_.target_space_transform, gfx::Rect(bounds()));
vmpstrd46a7ac2015-03-18 01:11:121881}
1882
1883gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const {
1884 gfx::Transform scaled_draw_transform =
1885 draw_properties_.target_space_transform;
1886 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
Dana Jansensc46d3742015-06-18 01:33:141887 gfx::Size scaled_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale));
vmpstrd46a7ac2015-03-18 01:11:121888 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform,
Dana Jansensc46d3742015-06-18 01:33:141889 gfx::Rect(scaled_bounds));
vmpstrd46a7ac2015-03-18 01:11:121890}
1891
enne637715732015-07-07 02:05:261892float LayerImpl::GetIdealContentsScale() const {
1893 float page_scale = IsAffectedByPageScale()
1894 ? layer_tree_impl()->current_page_scale_factor()
1895 : 1.f;
1896 float device_scale = layer_tree_impl()->device_scale_factor();
1897
1898 float default_scale = page_scale * device_scale;
1899 if (!layer_tree_impl()
1900 ->settings()
1901 .layer_transforms_should_scale_layer_contents) {
1902 return default_scale;
1903 }
1904
1905 // TODO(enne): the transform needs to come from property trees instead of
1906 // draw properties.
1907 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents(
1908 draw_properties().target_space_transform, default_scale);
1909 return std::max(transform_scales.x(), transform_scales.y());
1910}
1911
[email protected]bc5e77c2012-11-05 20:00:491912} // namespace cc