1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/layer.h"
9 #include "base/atomic_sequence_num.h"
10 #include "base/location.h"
11 #include "base/metrics/histogram.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/time/time.h"
14 #include "base/trace_event/trace_event.h"
15 #include "cc/animation/animation.h"
16 #include "cc/animation/animation_events.h"
17 #include "cc/animation/animation_registrar.h"
18 #include "cc/animation/keyframed_animation_curve.h"
19 #include "cc/animation/layer_animation_controller.h"
20 #include "cc/base/simple_enclosed_region.h"
21 #include "cc/debug/frame_viewer_instrumentation.h"
22 #include "cc/layers/layer_client.h"
23 #include "cc/layers/layer_impl.h"
24 #include "cc/layers/scrollbar_layer_interface.h"
25 #include "cc/output/copy_output_request.h"
26 #include "cc/output/copy_output_result.h"
27 #include "cc/trees/layer_tree_host.h"
28 #include "cc/trees/layer_tree_impl.h"
29 #include "third_party/skia/include/core/SkImageFilter.h"
30 #include "ui/gfx/geometry/rect_conversions.h"
31 #include "ui/gfx/geometry/vector2d_conversions.h"
35 base::StaticAtomicSequenceNumber g_next_layer_id
;
37 scoped_refptr
<Layer
> Layer::Create(const LayerSettings
& settings
) {
38 return make_scoped_refptr(new Layer(settings
));
41 Layer::Layer(const LayerSettings
& settings
)
42 : needs_push_properties_(false),
43 num_dependents_need_push_properties_(0),
44 stacking_order_changed_(false),
45 // Layer IDs start from 1.
46 layer_id_(g_next_layer_id
.GetNext() + 1),
47 ignore_set_needs_commit_(false),
48 sorting_context_id_(0),
50 layer_tree_host_(nullptr),
51 scroll_clip_layer_id_(INVALID_ID
),
52 num_descendants_that_draw_content_(0),
53 transform_tree_index_(-1),
54 opacity_tree_index_(-1),
56 property_tree_sequence_number_(-1),
57 num_layer_or_descendants_with_copy_request_(0),
58 num_layer_or_descendants_with_input_handler_(0),
59 num_children_with_scroll_parent_(0),
60 should_flatten_transform_from_property_tree_(false),
61 should_scroll_on_main_thread_(false),
62 have_wheel_event_handlers_(false),
63 have_scroll_event_handlers_(false),
64 user_scrollable_horizontal_(true),
65 user_scrollable_vertical_(true),
66 is_root_for_isolated_group_(false),
67 is_container_for_fixed_position_layers_(false),
69 draws_content_(false),
70 hide_layer_and_subtree_(false),
71 masks_to_bounds_(false),
72 contents_opaque_(false),
74 should_flatten_transform_(true),
75 use_parent_backface_visibility_(false),
76 draw_checkerboard_for_missing_tiles_(false),
77 force_render_surface_(false),
78 transform_is_invertible_(true),
79 has_render_surface_(false),
80 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE
),
83 blend_mode_(SkXfermode::kSrcOver_Mode
),
84 scroll_parent_(nullptr),
85 layer_or_descendant_is_drawn_tracker_(0),
86 sorted_for_recursion_tracker_(0),
88 clip_parent_(nullptr),
89 replica_layer_(nullptr),
92 frame_timing_requests_dirty_(false) {
93 if (!settings
.use_compositor_animation_timelines
) {
94 layer_animation_controller_
= LayerAnimationController::Create(layer_id_
);
95 layer_animation_controller_
->AddValueObserver(this);
96 layer_animation_controller_
->set_value_provider(this);
101 // Our parent should be holding a reference to us so there should be no
102 // way for us to be destroyed while we still have a parent.
104 // Similarly we shouldn't have a layer tree host since it also keeps a
106 DCHECK(!layer_tree_host());
108 if (layer_animation_controller_
) {
109 layer_animation_controller_
->RemoveValueObserver(this);
110 layer_animation_controller_
->remove_value_provider(this);
113 RemoveFromScrollTree();
114 RemoveFromClipTree();
116 // Remove the parent reference from all children and dependents.
118 if (mask_layer_
.get()) {
119 DCHECK_EQ(this, mask_layer_
->parent());
120 mask_layer_
->RemoveFromParent();
122 if (replica_layer_
.get()) {
123 DCHECK_EQ(this, replica_layer_
->parent());
124 replica_layer_
->RemoveFromParent();
128 void Layer::SetLayerTreeHost(LayerTreeHost
* host
) {
129 if (layer_tree_host_
== host
)
132 if (layer_tree_host_
)
133 layer_tree_host_
->property_trees()->needs_rebuild
= true;
136 host
->property_trees()->needs_rebuild
= true;
138 InvalidatePropertyTreesIndices();
140 layer_tree_host_
= host
;
142 // When changing hosts, the layer needs to commit its properties to the impl
143 // side for the new host.
144 SetNeedsPushProperties();
146 for (size_t i
= 0; i
< children_
.size(); ++i
)
147 children_
[i
]->SetLayerTreeHost(host
);
149 if (mask_layer_
.get())
150 mask_layer_
->SetLayerTreeHost(host
);
151 if (replica_layer_
.get())
152 replica_layer_
->SetLayerTreeHost(host
);
155 RegisterForAnimations(host
->animation_registrar());
156 if (host
->settings().layer_transforms_should_scale_layer_contents
)
157 reset_raster_scale_to_unknown();
160 if (host
&& layer_animation_controller_
->has_any_animation())
161 host
->SetNeedsCommit();
164 void Layer::SetNeedsUpdate() {
165 if (layer_tree_host_
&& !ignore_set_needs_commit_
)
166 layer_tree_host_
->SetNeedsUpdateLayers();
169 void Layer::SetNeedsCommit() {
170 if (!layer_tree_host_
)
173 SetNeedsPushProperties();
174 layer_tree_host_
->property_trees()->needs_rebuild
= true;
176 if (ignore_set_needs_commit_
)
179 layer_tree_host_
->SetNeedsCommit();
182 void Layer::SetNeedsCommitNoRebuild() {
183 if (!layer_tree_host_
)
186 SetNeedsPushProperties();
188 if (ignore_set_needs_commit_
)
191 layer_tree_host_
->SetNeedsCommit();
194 void Layer::SetNeedsFullTreeSync() {
195 if (!layer_tree_host_
)
198 layer_tree_host_
->SetNeedsFullTreeSync();
201 void Layer::SetNextCommitWaitsForActivation() {
202 if (!layer_tree_host_
)
205 layer_tree_host_
->SetNextCommitWaitsForActivation();
208 void Layer::SetNeedsPushProperties() {
209 if (needs_push_properties_
)
211 if (!parent_should_know_need_push_properties() && parent_
)
212 parent_
->AddDependentNeedsPushProperties();
213 needs_push_properties_
= true;
216 void Layer::AddDependentNeedsPushProperties() {
217 DCHECK_GE(num_dependents_need_push_properties_
, 0);
219 if (!parent_should_know_need_push_properties() && parent_
)
220 parent_
->AddDependentNeedsPushProperties();
222 num_dependents_need_push_properties_
++;
225 void Layer::RemoveDependentNeedsPushProperties() {
226 num_dependents_need_push_properties_
--;
227 DCHECK_GE(num_dependents_need_push_properties_
, 0);
229 if (!parent_should_know_need_push_properties() && parent_
)
230 parent_
->RemoveDependentNeedsPushProperties();
233 bool Layer::IsPropertyChangeAllowed() const {
234 if (!layer_tree_host_
)
237 if (!layer_tree_host_
->settings().strict_layer_property_change_checking
)
240 return !layer_tree_host_
->in_paint_layer_contents();
243 skia::RefPtr
<SkPicture
> Layer::GetPicture() const {
244 return skia::RefPtr
<SkPicture
>();
247 void Layer::SetParent(Layer
* layer
) {
248 DCHECK(!layer
|| !layer
->HasAncestor(this));
250 if (parent_should_know_need_push_properties()) {
252 parent_
->RemoveDependentNeedsPushProperties();
254 layer
->AddDependentNeedsPushProperties();
258 SetLayerTreeHost(parent_
? parent_
->layer_tree_host() : nullptr);
260 if (!layer_tree_host_
)
263 layer_tree_host_
->property_trees()->needs_rebuild
= true;
265 const LayerTreeSettings
& settings
= layer_tree_host_
->settings();
266 if (!settings
.layer_transforms_should_scale_layer_contents
)
269 reset_raster_scale_to_unknown();
270 if (mask_layer_
.get())
271 mask_layer_
->reset_raster_scale_to_unknown();
272 if (replica_layer_
.get() && replica_layer_
->mask_layer_
.get())
273 replica_layer_
->mask_layer_
->reset_raster_scale_to_unknown();
276 void Layer::AddChild(scoped_refptr
<Layer
> child
) {
277 InsertChild(child
, children_
.size());
280 void Layer::InsertChild(scoped_refptr
<Layer
> child
, size_t index
) {
281 DCHECK(IsPropertyChangeAllowed());
282 child
->RemoveFromParent();
283 AddDrawableDescendants(child
->NumDescendantsThatDrawContent() +
284 (child
->DrawsContent() ? 1 : 0));
285 child
->SetParent(this);
286 child
->stacking_order_changed_
= true;
288 index
= std::min(index
, children_
.size());
289 children_
.insert(children_
.begin() + index
, child
);
290 SetNeedsFullTreeSync();
293 void Layer::RemoveFromParent() {
294 DCHECK(IsPropertyChangeAllowed());
296 parent_
->RemoveChildOrDependent(this);
299 void Layer::RemoveChildOrDependent(Layer
* child
) {
300 if (mask_layer_
.get() == child
) {
301 mask_layer_
->SetParent(nullptr);
302 mask_layer_
= nullptr;
303 SetNeedsFullTreeSync();
306 if (replica_layer_
.get() == child
) {
307 replica_layer_
->SetParent(nullptr);
308 replica_layer_
= nullptr;
309 SetNeedsFullTreeSync();
313 for (LayerList::iterator iter
= children_
.begin();
314 iter
!= children_
.end();
316 if (iter
->get() != child
)
319 child
->SetParent(nullptr);
320 AddDrawableDescendants(-child
->NumDescendantsThatDrawContent() -
321 (child
->DrawsContent() ? 1 : 0));
322 children_
.erase(iter
);
323 SetNeedsFullTreeSync();
328 void Layer::ReplaceChild(Layer
* reference
, scoped_refptr
<Layer
> new_layer
) {
330 DCHECK_EQ(reference
->parent(), this);
331 DCHECK(IsPropertyChangeAllowed());
333 if (reference
== new_layer
.get())
336 // Find the index of |reference| in |children_|.
338 std::find_if(children_
.begin(), children_
.end(),
339 [reference
](const scoped_refptr
<Layer
>& layer
) {
340 return layer
.get() == reference
;
342 DCHECK(reference_it
!= children_
.end());
343 size_t reference_index
= reference_it
- children_
.begin();
344 reference
->RemoveFromParent();
346 if (new_layer
.get()) {
347 new_layer
->RemoveFromParent();
348 InsertChild(new_layer
, reference_index
);
352 void Layer::SetBounds(const gfx::Size
& size
) {
353 DCHECK(IsPropertyChangeAllowed());
354 if (bounds() == size
)
358 if (!layer_tree_host_
)
361 if (ClipNode
* clip_node
= layer_tree_host_
->property_trees()->clip_tree
.Node(
362 clip_tree_index())) {
363 if (clip_node
->owner_id
== id()) {
364 clip_node
->data
.clip
.set_size(size
);
365 layer_tree_host_
->property_trees()->clip_tree
.set_needs_update(true);
369 SetNeedsCommitNoRebuild();
372 Layer
* Layer::RootLayer() {
374 while (layer
->parent())
375 layer
= layer
->parent();
379 void Layer::RemoveAllChildren() {
380 DCHECK(IsPropertyChangeAllowed());
381 while (children_
.size()) {
382 Layer
* layer
= children_
[0].get();
383 DCHECK_EQ(this, layer
->parent());
384 layer
->RemoveFromParent();
388 void Layer::SetChildren(const LayerList
& children
) {
389 DCHECK(IsPropertyChangeAllowed());
390 if (children
== children_
)
394 for (size_t i
= 0; i
< children
.size(); ++i
)
395 AddChild(children
[i
]);
398 bool Layer::HasAncestor(const Layer
* ancestor
) const {
399 for (const Layer
* layer
= parent(); layer
; layer
= layer
->parent()) {
400 if (layer
== ancestor
)
406 void Layer::RequestCopyOfOutput(
407 scoped_ptr
<CopyOutputRequest
> request
) {
408 DCHECK(IsPropertyChangeAllowed());
409 bool had_no_copy_requests
= copy_requests_
.empty();
410 if (void* source
= request
->source()) {
411 auto it
= std::find_if(
412 copy_requests_
.begin(), copy_requests_
.end(),
413 [source
](const CopyOutputRequest
* x
) { return x
->source() == source
; });
414 if (it
!= copy_requests_
.end())
415 copy_requests_
.erase(it
);
417 if (request
->IsEmpty())
419 copy_requests_
.push_back(request
.Pass());
420 if (had_no_copy_requests
) {
421 bool copy_request_added
= true;
422 UpdateNumCopyRequestsForSubtree(copy_request_added
);
427 void Layer::UpdateNumCopyRequestsForSubtree(bool add
) {
428 int change
= add
? 1 : -1;
429 for (Layer
* layer
= this; layer
; layer
= layer
->parent()) {
430 layer
->num_layer_or_descendants_with_copy_request_
+= change
;
431 layer
->draw_properties().layer_or_descendant_has_copy_request
=
432 (layer
->num_layer_or_descendants_with_copy_request_
!= 0);
433 DCHECK_GE(layer
->num_layer_or_descendants_with_copy_request_
, 0);
437 void Layer::SetBackgroundColor(SkColor background_color
) {
438 DCHECK(IsPropertyChangeAllowed());
439 if (background_color_
== background_color
)
441 background_color_
= background_color
;
445 SkColor
Layer::SafeOpaqueBackgroundColor() const {
446 SkColor color
= background_color();
447 if (SkColorGetA(color
) == 255 && !contents_opaque()) {
448 color
= SK_ColorTRANSPARENT
;
449 } else if (SkColorGetA(color
) != 255 && contents_opaque()) {
450 for (const Layer
* layer
= parent(); layer
;
451 layer
= layer
->parent()) {
452 color
= layer
->background_color();
453 if (SkColorGetA(color
) == 255)
456 if (SkColorGetA(color
) != 255)
457 color
= layer_tree_host_
->background_color();
458 if (SkColorGetA(color
) != 255)
459 color
= SkColorSetA(color
, 255);
464 void Layer::SetMasksToBounds(bool masks_to_bounds
) {
465 DCHECK(IsPropertyChangeAllowed());
466 if (masks_to_bounds_
== masks_to_bounds
)
468 masks_to_bounds_
= masks_to_bounds
;
472 void Layer::SetMaskLayer(Layer
* mask_layer
) {
473 DCHECK(IsPropertyChangeAllowed());
474 if (mask_layer_
.get() == mask_layer
)
476 if (mask_layer_
.get()) {
477 DCHECK_EQ(this, mask_layer_
->parent());
478 mask_layer_
->RemoveFromParent();
480 mask_layer_
= mask_layer
;
481 if (mask_layer_
.get()) {
482 DCHECK(!mask_layer_
->parent());
483 mask_layer_
->RemoveFromParent();
484 mask_layer_
->SetParent(this);
485 mask_layer_
->SetIsMask(true);
487 SetNeedsFullTreeSync();
490 void Layer::SetReplicaLayer(Layer
* layer
) {
491 DCHECK(IsPropertyChangeAllowed());
492 if (replica_layer_
.get() == layer
)
494 if (replica_layer_
.get()) {
495 DCHECK_EQ(this, replica_layer_
->parent());
496 replica_layer_
->RemoveFromParent();
498 replica_layer_
= layer
;
499 if (replica_layer_
.get()) {
500 DCHECK(!replica_layer_
->parent());
501 replica_layer_
->RemoveFromParent();
502 replica_layer_
->SetParent(this);
504 SetNeedsFullTreeSync();
507 void Layer::SetFilters(const FilterOperations
& filters
) {
508 DCHECK(IsPropertyChangeAllowed());
509 if (filters_
== filters
)
515 bool Layer::FilterIsAnimating() const {
516 return layer_animation_controller_
->IsAnimatingProperty(Animation::FILTER
);
519 void Layer::SetBackgroundFilters(const FilterOperations
& filters
) {
520 DCHECK(IsPropertyChangeAllowed());
521 if (background_filters_
== filters
)
523 background_filters_
= filters
;
527 void Layer::SetOpacity(float opacity
) {
528 DCHECK(IsPropertyChangeAllowed());
529 if (opacity_
== opacity
)
535 bool Layer::OpacityIsAnimating() const {
536 return layer_animation_controller_
->IsAnimatingProperty(Animation::OPACITY
);
539 bool Layer::OpacityCanAnimateOnImplThread() const {
543 void Layer::SetBlendMode(SkXfermode::Mode blend_mode
) {
544 DCHECK(IsPropertyChangeAllowed());
545 if (blend_mode_
== blend_mode
)
548 // Allowing only blend modes that are defined in the CSS Compositing standard:
549 // http://dev.w3.org/fxtf/compositing-1/#blending
550 switch (blend_mode
) {
551 case SkXfermode::kSrcOver_Mode
:
552 case SkXfermode::kScreen_Mode
:
553 case SkXfermode::kOverlay_Mode
:
554 case SkXfermode::kDarken_Mode
:
555 case SkXfermode::kLighten_Mode
:
556 case SkXfermode::kColorDodge_Mode
:
557 case SkXfermode::kColorBurn_Mode
:
558 case SkXfermode::kHardLight_Mode
:
559 case SkXfermode::kSoftLight_Mode
:
560 case SkXfermode::kDifference_Mode
:
561 case SkXfermode::kExclusion_Mode
:
562 case SkXfermode::kMultiply_Mode
:
563 case SkXfermode::kHue_Mode
:
564 case SkXfermode::kSaturation_Mode
:
565 case SkXfermode::kColor_Mode
:
566 case SkXfermode::kLuminosity_Mode
:
567 // supported blend modes
569 case SkXfermode::kClear_Mode
:
570 case SkXfermode::kSrc_Mode
:
571 case SkXfermode::kDst_Mode
:
572 case SkXfermode::kDstOver_Mode
:
573 case SkXfermode::kSrcIn_Mode
:
574 case SkXfermode::kDstIn_Mode
:
575 case SkXfermode::kSrcOut_Mode
:
576 case SkXfermode::kDstOut_Mode
:
577 case SkXfermode::kSrcATop_Mode
:
578 case SkXfermode::kDstATop_Mode
:
579 case SkXfermode::kXor_Mode
:
580 case SkXfermode::kPlus_Mode
:
581 case SkXfermode::kModulate_Mode
:
582 // Porter Duff Compositing Operators are not yet supported
583 // http://dev.w3.org/fxtf/compositing-1/#porterduffcompositingoperators
588 blend_mode_
= blend_mode
;
592 void Layer::SetIsRootForIsolatedGroup(bool root
) {
593 DCHECK(IsPropertyChangeAllowed());
594 if (is_root_for_isolated_group_
== root
)
596 is_root_for_isolated_group_
= root
;
600 void Layer::SetContentsOpaque(bool opaque
) {
601 DCHECK(IsPropertyChangeAllowed());
602 if (contents_opaque_
== opaque
)
604 contents_opaque_
= opaque
;
608 void Layer::SetPosition(const gfx::PointF
& position
) {
609 DCHECK(IsPropertyChangeAllowed());
610 if (position_
== position
)
612 position_
= position
;
614 if (!layer_tree_host_
)
617 if (TransformNode
* transform_node
=
618 layer_tree_host_
->property_trees()->transform_tree
.Node(
619 transform_tree_index())) {
620 if (transform_node
->owner_id
== id()) {
621 transform_node
->data
.update_post_local_transform(position
,
623 transform_node
->data
.needs_local_transform_update
= true;
624 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
625 SetNeedsCommitNoRebuild();
633 bool Layer::IsContainerForFixedPositionLayers() const {
634 if (!transform_
.IsIdentityOrTranslation())
636 if (parent_
&& !parent_
->transform_
.IsIdentityOrTranslation())
638 return is_container_for_fixed_position_layers_
;
641 bool Are2dAxisAligned(const gfx::Transform
& a
,
642 const gfx::Transform
& b
,
643 bool* is_invertible
) {
644 if (a
.IsScaleOrTranslation() && b
.IsScaleOrTranslation()) {
645 *is_invertible
= b
.IsInvertible();
649 gfx::Transform
inverse(gfx::Transform::kSkipInitialization
);
650 *is_invertible
= b
.GetInverse(&inverse
);
653 return inverse
.Preserves2dAxisAlignment();
656 void Layer::SetTransform(const gfx::Transform
& transform
) {
657 DCHECK(IsPropertyChangeAllowed());
658 if (transform_
== transform
)
661 if (layer_tree_host_
) {
662 if (TransformNode
* transform_node
=
663 layer_tree_host_
->property_trees()->transform_tree
.Node(
664 transform_tree_index())) {
665 if (transform_node
->owner_id
== id()) {
666 // We need to trigger a rebuild if we could have affected 2d axis
667 // alignment. We'll check to see if transform and transform_ are axis
668 // align with respect to one another.
669 bool invertible
= false;
670 bool preserves_2d_axis_alignment
=
671 Are2dAxisAligned(transform_
, transform
, &invertible
);
672 transform_node
->data
.local
= transform
;
673 transform_node
->data
.needs_local_transform_update
= true;
674 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(
676 if (preserves_2d_axis_alignment
)
677 SetNeedsCommitNoRebuild();
680 transform_
= transform
;
681 transform_is_invertible_
= invertible
;
687 transform_
= transform
;
688 transform_is_invertible_
= transform
.IsInvertible();
693 void Layer::SetTransformOrigin(const gfx::Point3F
& transform_origin
) {
694 DCHECK(IsPropertyChangeAllowed());
695 if (transform_origin_
== transform_origin
)
697 transform_origin_
= transform_origin
;
699 if (!layer_tree_host_
)
702 if (TransformNode
* transform_node
=
703 layer_tree_host_
->property_trees()->transform_tree
.Node(
704 transform_tree_index())) {
705 if (transform_node
->owner_id
== id()) {
706 transform_node
->data
.update_pre_local_transform(transform_origin
);
707 transform_node
->data
.update_post_local_transform(position(),
709 transform_node
->data
.needs_local_transform_update
= true;
710 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
711 SetNeedsCommitNoRebuild();
719 bool Layer::AnimationsPreserveAxisAlignment() const {
720 return layer_animation_controller_
->AnimationsPreserveAxisAlignment();
723 bool Layer::TransformIsAnimating() const {
724 return layer_animation_controller_
->IsAnimatingProperty(Animation::TRANSFORM
);
727 void Layer::SetScrollParent(Layer
* parent
) {
728 DCHECK(IsPropertyChangeAllowed());
729 if (scroll_parent_
== parent
)
733 scroll_parent_
->RemoveScrollChild(this);
735 scroll_parent_
= parent
;
738 scroll_parent_
->AddScrollChild(this);
743 void Layer::AddScrollChild(Layer
* child
) {
744 if (!scroll_children_
)
745 scroll_children_
.reset(new std::set
<Layer
*>);
746 scroll_children_
->insert(child
);
747 if (layer_tree_host_
&& !layer_tree_host_
->needs_meta_info_recomputation()) {
748 num_children_with_scroll_parent_
++;
749 draw_properties().has_child_with_a_scroll_parent
= true;
754 void Layer::RemoveScrollChild(Layer
* child
) {
755 scroll_children_
->erase(child
);
756 if (scroll_children_
->empty())
757 scroll_children_
= nullptr;
758 if (layer_tree_host_
&& !layer_tree_host_
->needs_meta_info_recomputation()) {
759 num_children_with_scroll_parent_
--;
760 DCHECK_GE(num_children_with_scroll_parent_
, 0);
761 draw_properties().has_child_with_a_scroll_parent
=
762 (num_children_with_scroll_parent_
!= 0);
767 void Layer::SetClipParent(Layer
* ancestor
) {
768 DCHECK(IsPropertyChangeAllowed());
769 if (clip_parent_
== ancestor
)
773 clip_parent_
->RemoveClipChild(this);
775 clip_parent_
= ancestor
;
778 clip_parent_
->AddClipChild(this);
781 if (layer_tree_host_
)
782 layer_tree_host_
->SetNeedsMetaInfoRecomputation(true);
785 void Layer::AddClipChild(Layer
* child
) {
787 clip_children_
.reset(new std::set
<Layer
*>);
788 clip_children_
->insert(child
);
792 void Layer::RemoveClipChild(Layer
* child
) {
793 clip_children_
->erase(child
);
794 if (clip_children_
->empty())
795 clip_children_
= nullptr;
799 void Layer::SetScrollOffset(const gfx::ScrollOffset
& scroll_offset
) {
800 DCHECK(IsPropertyChangeAllowed());
802 if (scroll_offset_
== scroll_offset
)
804 scroll_offset_
= scroll_offset
;
806 if (!layer_tree_host_
)
809 if (TransformNode
* transform_node
=
810 layer_tree_host_
->property_trees()->transform_tree
.Node(
811 transform_tree_index())) {
812 if (transform_node
->owner_id
== id()) {
813 transform_node
->data
.scroll_offset
= CurrentScrollOffset();
814 transform_node
->data
.needs_local_transform_update
= true;
815 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
816 SetNeedsCommitNoRebuild();
824 void Layer::SetScrollCompensationAdjustment(
825 const gfx::Vector2dF
& scroll_compensation_adjustment
) {
826 if (scroll_compensation_adjustment_
== scroll_compensation_adjustment
)
828 scroll_compensation_adjustment_
= scroll_compensation_adjustment
;
832 gfx::Vector2dF
Layer::ScrollCompensationAdjustment() const {
833 return scroll_compensation_adjustment_
;
836 void Layer::SetScrollOffsetFromImplSide(
837 const gfx::ScrollOffset
& scroll_offset
) {
838 DCHECK(IsPropertyChangeAllowed());
839 // This function only gets called during a BeginMainFrame, so there
840 // is no need to call SetNeedsUpdate here.
841 DCHECK(layer_tree_host_
&& layer_tree_host_
->CommitRequested());
842 if (scroll_offset_
== scroll_offset
)
844 scroll_offset_
= scroll_offset
;
845 SetNeedsPushProperties();
847 bool needs_rebuild
= true;
848 if (TransformNode
* transform_node
=
849 layer_tree_host_
->property_trees()->transform_tree
.Node(
850 transform_tree_index())) {
851 if (transform_node
->owner_id
== id()) {
852 transform_node
->data
.scroll_offset
= CurrentScrollOffset();
853 transform_node
->data
.needs_local_transform_update
= true;
854 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
855 needs_rebuild
= false;
860 layer_tree_host_
->property_trees()->needs_rebuild
= true;
862 if (!did_scroll_callback_
.is_null())
863 did_scroll_callback_
.Run();
864 // The callback could potentially change the layer structure:
865 // "this" may have been destroyed during the process.
868 void Layer::SetScrollClipLayerId(int clip_layer_id
) {
869 DCHECK(IsPropertyChangeAllowed());
870 if (scroll_clip_layer_id_
== clip_layer_id
)
872 scroll_clip_layer_id_
= clip_layer_id
;
876 void Layer::SetUserScrollable(bool horizontal
, bool vertical
) {
877 DCHECK(IsPropertyChangeAllowed());
878 if (user_scrollable_horizontal_
== horizontal
&&
879 user_scrollable_vertical_
== vertical
)
881 user_scrollable_horizontal_
= horizontal
;
882 user_scrollable_vertical_
= vertical
;
886 void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
887 DCHECK(IsPropertyChangeAllowed());
888 if (should_scroll_on_main_thread_
== should_scroll_on_main_thread
)
890 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
894 void Layer::SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
895 DCHECK(IsPropertyChangeAllowed());
896 if (have_wheel_event_handlers_
== have_wheel_event_handlers
)
898 if (touch_event_handler_region_
.IsEmpty() && layer_tree_host_
&&
899 !layer_tree_host_
->needs_meta_info_recomputation())
900 UpdateNumInputHandlersForSubtree(have_wheel_event_handlers
);
902 have_wheel_event_handlers_
= have_wheel_event_handlers
;
906 void Layer::UpdateNumInputHandlersForSubtree(bool add
) {
907 int change
= add
? 1 : -1;
908 for (Layer
* layer
= this; layer
; layer
= layer
->parent()) {
909 layer
->num_layer_or_descendants_with_input_handler_
+= change
;
910 layer
->draw_properties().layer_or_descendant_has_input_handler
=
911 (layer
->num_layer_or_descendants_with_input_handler_
!= 0);
912 DCHECK_GE(layer
->num_layer_or_descendants_with_input_handler_
, 0);
916 void Layer::SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
917 DCHECK(IsPropertyChangeAllowed());
918 if (have_scroll_event_handlers_
== have_scroll_event_handlers
)
920 have_scroll_event_handlers_
= have_scroll_event_handlers
;
924 void Layer::SetNonFastScrollableRegion(const Region
& region
) {
925 DCHECK(IsPropertyChangeAllowed());
926 if (non_fast_scrollable_region_
== region
)
928 non_fast_scrollable_region_
= region
;
932 void Layer::SetTouchEventHandlerRegion(const Region
& region
) {
933 DCHECK(IsPropertyChangeAllowed());
934 if (touch_event_handler_region_
== region
)
936 if (!have_wheel_event_handlers_
&& layer_tree_host_
&&
937 !layer_tree_host_
->needs_meta_info_recomputation())
938 UpdateNumInputHandlersForSubtree(!region
.IsEmpty());
940 touch_event_handler_region_
= region
;
944 void Layer::SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
945 DCHECK(IsPropertyChangeAllowed());
946 if (scroll_blocks_on_
== scroll_blocks_on
)
948 scroll_blocks_on_
= scroll_blocks_on
;
952 void Layer::SetDrawCheckerboardForMissingTiles(bool checkerboard
) {
953 DCHECK(IsPropertyChangeAllowed());
954 if (draw_checkerboard_for_missing_tiles_
== checkerboard
)
956 draw_checkerboard_for_missing_tiles_
= checkerboard
;
960 void Layer::SetForceRenderSurface(bool force
) {
961 DCHECK(IsPropertyChangeAllowed());
962 if (force_render_surface_
== force
)
964 force_render_surface_
= force
;
968 void Layer::SetDoubleSided(bool double_sided
) {
969 DCHECK(IsPropertyChangeAllowed());
970 if (double_sided_
== double_sided
)
972 double_sided_
= double_sided
;
976 void Layer::Set3dSortingContextId(int id
) {
977 DCHECK(IsPropertyChangeAllowed());
978 if (id
== sorting_context_id_
)
980 sorting_context_id_
= id
;
984 void Layer::SetTransformTreeIndex(int index
) {
985 DCHECK(IsPropertyChangeAllowed());
986 if (transform_tree_index_
== index
)
988 transform_tree_index_
= index
;
989 SetNeedsPushProperties();
992 int Layer::transform_tree_index() const {
993 if (!layer_tree_host_
||
994 layer_tree_host_
->property_trees()->sequence_number
!=
995 property_tree_sequence_number_
) {
998 return transform_tree_index_
;
1001 void Layer::SetClipTreeIndex(int index
) {
1002 DCHECK(IsPropertyChangeAllowed());
1003 if (clip_tree_index_
== index
)
1005 clip_tree_index_
= index
;
1006 SetNeedsPushProperties();
1009 int Layer::clip_tree_index() const {
1010 if (!layer_tree_host_
||
1011 layer_tree_host_
->property_trees()->sequence_number
!=
1012 property_tree_sequence_number_
) {
1015 return clip_tree_index_
;
1018 void Layer::SetOpacityTreeIndex(int index
) {
1019 DCHECK(IsPropertyChangeAllowed());
1020 if (opacity_tree_index_
== index
)
1022 opacity_tree_index_
= index
;
1023 SetNeedsPushProperties();
1026 int Layer::opacity_tree_index() const {
1027 if (!layer_tree_host_
||
1028 layer_tree_host_
->property_trees()->sequence_number
!=
1029 property_tree_sequence_number_
) {
1032 return opacity_tree_index_
;
1035 void Layer::InvalidatePropertyTreesIndices() {
1036 int invalid_property_tree_index
= -1;
1037 SetTransformTreeIndex(invalid_property_tree_index
);
1038 SetClipTreeIndex(invalid_property_tree_index
);
1039 SetOpacityTreeIndex(invalid_property_tree_index
);
1042 void Layer::SetShouldFlattenTransform(bool should_flatten
) {
1043 DCHECK(IsPropertyChangeAllowed());
1044 if (should_flatten_transform_
== should_flatten
)
1046 should_flatten_transform_
= should_flatten
;
1050 void Layer::SetIsDrawable(bool is_drawable
) {
1051 DCHECK(IsPropertyChangeAllowed());
1052 if (is_drawable_
== is_drawable
)
1055 is_drawable_
= is_drawable
;
1056 UpdateDrawsContent(HasDrawableContent());
1059 void Layer::SetHideLayerAndSubtree(bool hide
) {
1060 DCHECK(IsPropertyChangeAllowed());
1061 if (hide_layer_and_subtree_
== hide
)
1064 hide_layer_and_subtree_
= hide
;
1068 void Layer::SetNeedsDisplayRect(const gfx::Rect
& dirty_rect
) {
1069 if (dirty_rect
.IsEmpty())
1072 SetNeedsPushProperties();
1073 update_rect_
.Union(dirty_rect
);
1079 bool Layer::DescendantIsFixedToContainerLayer() const {
1080 for (size_t i
= 0; i
< children_
.size(); ++i
) {
1081 if (children_
[i
]->position_constraint_
.is_fixed_position() ||
1082 children_
[i
]->DescendantIsFixedToContainerLayer())
1088 void Layer::SetIsContainerForFixedPositionLayers(bool container
) {
1089 if (is_container_for_fixed_position_layers_
== container
)
1091 is_container_for_fixed_position_layers_
= container
;
1093 if (layer_tree_host_
&& layer_tree_host_
->CommitRequested())
1096 // Only request a commit if we have a fixed positioned descendant.
1097 if (DescendantIsFixedToContainerLayer())
1101 void Layer::SetPositionConstraint(const LayerPositionConstraint
& constraint
) {
1102 DCHECK(IsPropertyChangeAllowed());
1103 if (position_constraint_
== constraint
)
1105 position_constraint_
= constraint
;
1109 static void RunCopyCallbackOnMainThread(scoped_ptr
<CopyOutputRequest
> request
,
1110 scoped_ptr
<CopyOutputResult
> result
) {
1111 request
->SendResult(result
.Pass());
1114 static void PostCopyCallbackToMainThread(
1115 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
,
1116 scoped_ptr
<CopyOutputRequest
> request
,
1117 scoped_ptr
<CopyOutputResult
> result
) {
1118 main_thread_task_runner
->PostTask(FROM_HERE
,
1119 base::Bind(&RunCopyCallbackOnMainThread
,
1120 base::Passed(&request
),
1121 base::Passed(&result
)));
1124 void Layer::PushPropertiesTo(LayerImpl
* layer
) {
1125 DCHECK(layer_tree_host_
);
1127 // If we did not SavePaintProperties() for the layer this frame, then push the
1128 // real property values, not the paint property values.
1129 bool use_paint_properties
= paint_properties_
.source_frame_number
==
1130 layer_tree_host_
->source_frame_number();
1132 layer
->SetTransformOrigin(transform_origin_
);
1133 layer
->SetBackgroundColor(background_color_
);
1134 layer
->SetBounds(use_paint_properties
? paint_properties_
.bounds
1137 if (frame_viewer_instrumentation::IsTracingLayerTreeSnapshots())
1138 layer
->SetDebugInfo(TakeDebugInfo());
1140 layer
->SetTransformTreeIndex(transform_tree_index());
1141 layer
->SetOpacityTreeIndex(opacity_tree_index());
1142 layer
->SetClipTreeIndex(clip_tree_index());
1143 layer
->set_offset_to_transform_parent(offset_to_transform_parent_
);
1144 layer
->SetDoubleSided(double_sided_
);
1145 layer
->SetDrawCheckerboardForMissingTiles(
1146 draw_checkerboard_for_missing_tiles_
);
1147 layer
->SetDrawsContent(DrawsContent());
1148 layer
->SetHideLayerAndSubtree(hide_layer_and_subtree_
);
1149 layer
->SetHasRenderSurface(has_render_surface_
);
1150 if (!layer
->FilterIsAnimatingOnImplOnly() && !FilterIsAnimating())
1151 layer
->SetFilters(filters_
);
1152 DCHECK(!(FilterIsAnimating() && layer
->FilterIsAnimatingOnImplOnly()));
1153 layer
->SetBackgroundFilters(background_filters());
1154 layer
->SetMasksToBounds(masks_to_bounds_
);
1155 layer
->SetShouldScrollOnMainThread(should_scroll_on_main_thread_
);
1156 layer
->SetHaveWheelEventHandlers(have_wheel_event_handlers_
);
1157 layer
->SetHaveScrollEventHandlers(have_scroll_event_handlers_
);
1158 layer
->SetNonFastScrollableRegion(non_fast_scrollable_region_
);
1159 layer
->SetTouchEventHandlerRegion(touch_event_handler_region_
);
1160 layer
->SetScrollBlocksOn(scroll_blocks_on_
);
1161 layer
->SetContentsOpaque(contents_opaque_
);
1162 if (!layer
->OpacityIsAnimatingOnImplOnly() && !OpacityIsAnimating())
1163 layer
->SetOpacity(opacity_
);
1164 DCHECK(!(OpacityIsAnimating() && layer
->OpacityIsAnimatingOnImplOnly()));
1165 layer
->SetBlendMode(blend_mode_
);
1166 layer
->SetIsRootForIsolatedGroup(is_root_for_isolated_group_
);
1167 layer
->SetPosition(position_
);
1168 layer
->SetIsContainerForFixedPositionLayers(
1169 IsContainerForFixedPositionLayers());
1170 layer
->SetPositionConstraint(position_constraint_
);
1171 layer
->SetShouldFlattenTransform(should_flatten_transform_
);
1172 layer
->set_should_flatten_transform_from_property_tree(
1173 should_flatten_transform_from_property_tree_
);
1174 layer
->SetUseParentBackfaceVisibility(use_parent_backface_visibility_
);
1175 if (!layer
->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating())
1176 layer
->SetTransformAndInvertibility(transform_
, transform_is_invertible_
);
1177 DCHECK(!(TransformIsAnimating() && layer
->TransformIsAnimatingOnImplOnly()));
1178 layer
->Set3dSortingContextId(sorting_context_id_
);
1179 layer
->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_
);
1181 layer
->SetScrollClipLayer(scroll_clip_layer_id_
);
1182 layer
->set_user_scrollable_horizontal(user_scrollable_horizontal_
);
1183 layer
->set_user_scrollable_vertical(user_scrollable_vertical_
);
1185 LayerImpl
* scroll_parent
= nullptr;
1186 if (scroll_parent_
) {
1187 scroll_parent
= layer
->layer_tree_impl()->LayerById(scroll_parent_
->id());
1188 DCHECK(scroll_parent
);
1191 layer
->SetScrollParent(scroll_parent
);
1192 if (scroll_children_
) {
1193 std::set
<LayerImpl
*>* scroll_children
= new std::set
<LayerImpl
*>;
1194 for (std::set
<Layer
*>::iterator it
= scroll_children_
->begin();
1195 it
!= scroll_children_
->end();
1197 DCHECK_EQ((*it
)->scroll_parent(), this);
1198 LayerImpl
* scroll_child
=
1199 layer
->layer_tree_impl()->LayerById((*it
)->id());
1200 DCHECK(scroll_child
);
1201 scroll_children
->insert(scroll_child
);
1203 layer
->SetScrollChildren(scroll_children
);
1205 layer
->SetScrollChildren(nullptr);
1208 LayerImpl
* clip_parent
= nullptr;
1211 layer
->layer_tree_impl()->LayerById(clip_parent_
->id());
1212 DCHECK(clip_parent
);
1215 layer
->SetClipParent(clip_parent
);
1216 if (clip_children_
) {
1217 std::set
<LayerImpl
*>* clip_children
= new std::set
<LayerImpl
*>;
1218 for (std::set
<Layer
*>::iterator it
= clip_children_
->begin();
1219 it
!= clip_children_
->end(); ++it
) {
1220 DCHECK_EQ((*it
)->clip_parent(), this);
1221 LayerImpl
* clip_child
= layer
->layer_tree_impl()->LayerById((*it
)->id());
1223 clip_children
->insert(clip_child
);
1225 layer
->SetClipChildren(clip_children
);
1227 layer
->SetClipChildren(nullptr);
1230 // When a scroll offset animation is interrupted the new scroll position on
1231 // the pending tree will clobber any impl-side scrolling occuring on the
1232 // active tree. To do so, avoid scrolling the pending tree along with it
1233 // instead of trying to undo that scrolling later.
1234 if (layer_animation_controller_
->scroll_offset_animation_was_interrupted())
1235 layer
->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_
);
1237 layer
->PushScrollOffsetFromMainThread(scroll_offset_
);
1238 layer
->SetScrollCompensationAdjustment(ScrollCompensationAdjustment());
1240 // Wrap the copy_requests_ in a PostTask to the main thread.
1241 bool had_copy_requests
= !copy_requests_
.empty();
1242 ScopedPtrVector
<CopyOutputRequest
> main_thread_copy_requests
;
1243 for (ScopedPtrVector
<CopyOutputRequest
>::iterator it
= copy_requests_
.begin();
1244 it
!= copy_requests_
.end();
1246 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
=
1247 layer_tree_host()->proxy()->MainThreadTaskRunner();
1248 scoped_ptr
<CopyOutputRequest
> original_request
= copy_requests_
.take(it
);
1249 const CopyOutputRequest
& original_request_ref
= *original_request
;
1250 scoped_ptr
<CopyOutputRequest
> main_thread_request
=
1251 CopyOutputRequest::CreateRelayRequest(
1252 original_request_ref
,
1253 base::Bind(&PostCopyCallbackToMainThread
,
1254 main_thread_task_runner
,
1255 base::Passed(&original_request
)));
1256 main_thread_copy_requests
.push_back(main_thread_request
.Pass());
1258 if (!copy_requests_
.empty() && layer_tree_host_
)
1259 layer_tree_host_
->property_trees()->needs_rebuild
= true;
1260 if (had_copy_requests
)
1261 UpdateNumCopyRequestsForSubtree(false);
1262 copy_requests_
.clear();
1263 layer
->PassCopyRequests(&main_thread_copy_requests
);
1265 // If the main thread commits multiple times before the impl thread actually
1266 // draws, then damage tracking will become incorrect if we simply clobber the
1267 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
1268 // union) any update changes that have occurred on the main thread.
1269 update_rect_
.Union(layer
->update_rect());
1270 layer
->SetUpdateRect(update_rect_
);
1272 layer
->SetStackingOrderChanged(stacking_order_changed_
);
1274 layer_animation_controller_
->PushAnimationUpdatesTo(
1275 layer
->layer_animation_controller());
1277 if (frame_timing_requests_dirty_
) {
1278 layer
->SetFrameTimingRequests(frame_timing_requests_
);
1279 frame_timing_requests_dirty_
= false;
1282 bool is_page_scale_layer
= this == layer_tree_host()->page_scale_layer();
1283 bool parent_affected
=
1284 layer
->parent() && layer
->parent()->IsAffectedByPageScale();
1285 layer
->SetIsAffectedByPageScale(is_page_scale_layer
|| parent_affected
);
1287 // Reset any state that should be cleared for the next update.
1288 stacking_order_changed_
= false;
1289 update_rect_
= gfx::Rect();
1291 needs_push_properties_
= false;
1292 num_dependents_need_push_properties_
= 0;
1295 scoped_ptr
<LayerImpl
> Layer::CreateLayerImpl(LayerTreeImpl
* tree_impl
) {
1296 return LayerImpl::Create(tree_impl
, layer_id_
,
1297 new LayerImpl::SyncedScrollOffset
);
1300 bool Layer::DrawsContent() const {
1301 return draws_content_
;
1304 bool Layer::HasDrawableContent() const {
1305 return is_drawable_
;
1308 void Layer::UpdateDrawsContent(bool has_drawable_content
) {
1309 bool draws_content
= has_drawable_content
;
1310 DCHECK(is_drawable_
|| !has_drawable_content
);
1311 if (draws_content
== draws_content_
)
1314 if (HasDelegatedContent()) {
1315 // Layers with delegated content need to be treated as if they have as
1316 // many children as the number of layers they own delegated quads for.
1317 // Since we don't know this number right now, we choose one that acts like
1318 // infinity for our purposes.
1319 AddDrawableDescendants(draws_content
? 1000 : -1000);
1323 parent()->AddDrawableDescendants(draws_content
? 1 : -1);
1325 draws_content_
= draws_content
;
1329 int Layer::NumDescendantsThatDrawContent() const {
1330 return num_descendants_that_draw_content_
;
1333 void Layer::SavePaintProperties() {
1334 DCHECK(layer_tree_host_
);
1336 // TODO(reveman): Save all layer properties that we depend on not
1337 // changing until PushProperties() has been called. crbug.com/231016
1338 paint_properties_
.bounds
= bounds_
;
1339 paint_properties_
.source_frame_number
=
1340 layer_tree_host_
->source_frame_number();
1343 bool Layer::Update() {
1344 DCHECK(layer_tree_host_
);
1345 DCHECK_EQ(layer_tree_host_
->source_frame_number(),
1346 paint_properties_
.source_frame_number
) <<
1347 "SavePaintProperties must be called for any layer that is painted.";
1351 bool Layer::NeedMoreUpdates() {
1355 bool Layer::IsSuitableForGpuRasterization() const {
1359 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
1360 Layer::TakeDebugInfo() {
1362 return client_
->TakeDebugInfo();
1367 void Layer::SetHasRenderSurface(bool has_render_surface
) {
1368 if (has_render_surface_
== has_render_surface
)
1370 has_render_surface_
= has_render_surface
;
1371 // We do not need SetNeedsCommit here, since this is only ever called
1372 // during a commit, from CalculateDrawProperties.
1373 SetNeedsPushProperties();
1376 void Layer::CreateRenderSurface() {
1377 DCHECK(!render_surface_
);
1378 render_surface_
= make_scoped_ptr(new RenderSurface(this));
1381 void Layer::ClearRenderSurface() {
1382 render_surface_
= nullptr;
1385 void Layer::ClearRenderSurfaceLayerList() {
1386 if (render_surface_
)
1387 render_surface_
->ClearLayerLists();
1390 gfx::ScrollOffset
Layer::ScrollOffsetForAnimation() const {
1391 return CurrentScrollOffset();
1394 // On<Property>Animated is called due to an ongoing accelerated animation.
1395 // Since this animation is also being run on the compositor thread, there
1396 // is no need to request a commit to push this value over, so the value is
1397 // set directly rather than by calling Set<Property>.
1398 void Layer::OnFilterAnimated(const FilterOperations
& filters
) {
1402 void Layer::OnOpacityAnimated(float opacity
) {
1404 if (layer_tree_host_
) {
1405 if (OpacityNode
* node
=
1406 layer_tree_host_
->property_trees()->opacity_tree
.Node(
1407 opacity_tree_index())) {
1408 if (node
->owner_id
== id()) {
1409 node
->data
.opacity
= opacity
;
1410 layer_tree_host_
->property_trees()->opacity_tree
.set_needs_update(true);
1416 void Layer::OnTransformAnimated(const gfx::Transform
& transform
) {
1417 if (transform_
== transform
)
1419 transform_
= transform
;
1420 transform_is_invertible_
= transform
.IsInvertible();
1421 if (layer_tree_host_
) {
1422 if (TransformNode
* node
=
1423 layer_tree_host_
->property_trees()->transform_tree
.Node(
1424 transform_tree_index())) {
1425 if (node
->owner_id
== id()) {
1426 node
->data
.local
= transform
;
1427 node
->data
.needs_local_transform_update
= true;
1428 node
->data
.is_animated
= true;
1429 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(
1436 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) {
1437 // Do nothing. Scroll deltas will be sent from the compositor thread back
1438 // to the main thread in the same manner as during non-animated
1439 // compositor-driven scrolling.
1442 void Layer::OnAnimationWaitingForDeletion() {
1443 // Animations are only deleted during PushProperties.
1444 SetNeedsPushProperties();
1447 bool Layer::IsActive() const {
1451 bool Layer::AddAnimation(scoped_ptr
<Animation
> animation
) {
1452 DCHECK(layer_animation_controller_
);
1453 if (!layer_animation_controller_
->animation_registrar())
1456 if (animation
->target_property() == Animation::SCROLL_OFFSET
&&
1457 !layer_animation_controller_
->animation_registrar()
1458 ->supports_scroll_animations())
1461 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer",
1463 layer_animation_controller_
->AddAnimation(animation
.Pass());
1468 void Layer::PauseAnimation(int animation_id
, double time_offset
) {
1469 DCHECK(layer_animation_controller_
);
1470 layer_animation_controller_
->PauseAnimation(
1471 animation_id
, base::TimeDelta::FromSecondsD(time_offset
));
1475 void Layer::RemoveAnimation(int animation_id
) {
1476 DCHECK(layer_animation_controller_
);
1477 layer_animation_controller_
->RemoveAnimation(animation_id
);
1481 void Layer::RemoveAnimation(int animation_id
,
1482 Animation::TargetProperty property
) {
1483 DCHECK(layer_animation_controller_
);
1484 layer_animation_controller_
->RemoveAnimation(animation_id
, property
);
1488 void Layer::SetLayerAnimationControllerForTest(
1489 scoped_refptr
<LayerAnimationController
> controller
) {
1490 layer_animation_controller_
->RemoveValueObserver(this);
1491 layer_animation_controller_
= controller
;
1492 layer_animation_controller_
->AddValueObserver(this);
1496 bool Layer::HasActiveAnimation() const {
1497 DCHECK(layer_animation_controller_
);
1498 return layer_animation_controller_
->HasActiveAnimation();
1501 void Layer::RegisterForAnimations(AnimationRegistrar
* registrar
) {
1502 if (layer_animation_controller_
)
1503 layer_animation_controller_
->SetAnimationRegistrar(registrar
);
1506 void Layer::AddLayerAnimationEventObserver(
1507 LayerAnimationEventObserver
* animation_observer
) {
1508 DCHECK(layer_animation_controller_
);
1509 layer_animation_controller_
->AddEventObserver(animation_observer
);
1512 void Layer::RemoveLayerAnimationEventObserver(
1513 LayerAnimationEventObserver
* animation_observer
) {
1514 DCHECK(layer_animation_controller_
);
1515 layer_animation_controller_
->RemoveEventObserver(animation_observer
);
1518 ScrollbarLayerInterface
* Layer::ToScrollbarLayer() {
1522 RenderingStatsInstrumentation
* Layer::rendering_stats_instrumentation() const {
1523 return layer_tree_host_
->rendering_stats_instrumentation();
1526 void Layer::RemoveFromScrollTree() {
1527 if (scroll_children_
.get()) {
1528 std::set
<Layer
*> copy
= *scroll_children_
;
1529 for (std::set
<Layer
*>::iterator it
= copy
.begin(); it
!= copy
.end(); ++it
)
1530 (*it
)->SetScrollParent(nullptr);
1533 DCHECK(!scroll_children_
);
1534 SetScrollParent(nullptr);
1537 void Layer::RemoveFromClipTree() {
1538 if (clip_children_
.get()) {
1539 std::set
<Layer
*> copy
= *clip_children_
;
1540 for (std::set
<Layer
*>::iterator it
= copy
.begin(); it
!= copy
.end(); ++it
)
1541 (*it
)->SetClipParent(nullptr);
1544 DCHECK(!clip_children_
);
1545 SetClipParent(nullptr);
1548 void Layer::AddDrawableDescendants(int num
) {
1549 DCHECK_GE(num_descendants_that_draw_content_
, 0);
1550 DCHECK_GE(num_descendants_that_draw_content_
+ num
, 0);
1553 num_descendants_that_draw_content_
+= num
;
1556 parent()->AddDrawableDescendants(num
);
1559 void Layer::RunMicroBenchmark(MicroBenchmark
* benchmark
) {
1560 benchmark
->RunOnLayer(this);
1563 bool Layer::HasDelegatedContent() const {
1567 void Layer::SetFrameTimingRequests(
1568 const std::vector
<FrameTimingRequest
>& requests
) {
1569 // TODO(vmpstr): Early out if there are no changes earlier in the call stack.
1570 if (requests
== frame_timing_requests_
)
1572 frame_timing_requests_
= requests
;
1573 frame_timing_requests_dirty_
= true;
1577 void Layer::DidBeginTracing() {
1578 // We'll be dumping layer trees as part of trace, so make sure
1579 // PushPropertiesTo() propagates layer debug info to the impl
1580 // side -- otherwise this won't happen for the the layers that
1581 // remain unchanged since tracing started.
1582 SetNeedsPushProperties();
1585 void Layer::set_visited(bool visited
) {
1587 visited
? layer_tree_host()->meta_information_sequence_number() : 0;
1590 bool Layer::visited() {
1591 return visited_tracker_
==
1592 layer_tree_host()->meta_information_sequence_number();
1595 void Layer::set_layer_or_descendant_is_drawn(
1596 bool layer_or_descendant_is_drawn
) {
1597 layer_or_descendant_is_drawn_tracker_
=
1598 layer_or_descendant_is_drawn
1599 ? layer_tree_host()->meta_information_sequence_number()
1603 bool Layer::layer_or_descendant_is_drawn() {
1604 return layer_or_descendant_is_drawn_tracker_
==
1605 layer_tree_host()->meta_information_sequence_number();
1608 void Layer::set_sorted_for_recursion(bool sorted_for_recursion
) {
1609 sorted_for_recursion_tracker_
=
1610 sorted_for_recursion
1611 ? layer_tree_host()->meta_information_sequence_number()
1615 bool Layer::sorted_for_recursion() {
1616 return sorted_for_recursion_tracker_
==
1617 layer_tree_host()->meta_information_sequence_number();