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),
62 should_scroll_on_main_thread_(false),
63 have_wheel_event_handlers_(false),
64 have_scroll_event_handlers_(false),
65 user_scrollable_horizontal_(true),
66 user_scrollable_vertical_(true),
67 is_root_for_isolated_group_(false),
68 is_container_for_fixed_position_layers_(false),
70 draws_content_(false),
71 hide_layer_and_subtree_(false),
72 masks_to_bounds_(false),
73 contents_opaque_(false),
75 should_flatten_transform_(true),
76 use_parent_backface_visibility_(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 draw_blend_mode_(SkXfermode::kSrcOver_Mode
),
85 scroll_parent_(nullptr),
86 layer_or_descendant_is_drawn_tracker_(0),
87 sorted_for_recursion_tracker_(0),
89 clip_parent_(nullptr),
90 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;
134 layer_tree_host_
->UnregisterLayer(this);
137 host
->property_trees()->needs_rebuild
= true;
138 host
->RegisterLayer(this);
141 InvalidatePropertyTreesIndices();
143 layer_tree_host_
= host
;
145 // When changing hosts, the layer needs to commit its properties to the impl
146 // side for the new host.
147 SetNeedsPushProperties();
149 for (size_t i
= 0; i
< children_
.size(); ++i
)
150 children_
[i
]->SetLayerTreeHost(host
);
152 if (mask_layer_
.get())
153 mask_layer_
->SetLayerTreeHost(host
);
154 if (replica_layer_
.get())
155 replica_layer_
->SetLayerTreeHost(host
);
158 RegisterForAnimations(host
->animation_registrar());
160 bool has_any_animation
= false;
161 if (layer_animation_controller_
)
162 has_any_animation
= layer_animation_controller_
->has_any_animation();
163 else if (layer_tree_host_
)
164 has_any_animation
= layer_tree_host_
->HasAnyAnimation(this);
166 if (host
&& has_any_animation
)
167 host
->SetNeedsCommit();
170 void Layer::SetNeedsUpdate() {
171 if (layer_tree_host_
&& !ignore_set_needs_commit_
)
172 layer_tree_host_
->SetNeedsUpdateLayers();
175 void Layer::SetNeedsCommit() {
176 if (!layer_tree_host_
)
179 SetNeedsPushProperties();
180 layer_tree_host_
->property_trees()->needs_rebuild
= true;
182 if (ignore_set_needs_commit_
)
185 layer_tree_host_
->SetNeedsCommit();
188 void Layer::SetNeedsCommitNoRebuild() {
189 if (!layer_tree_host_
)
192 SetNeedsPushProperties();
194 if (ignore_set_needs_commit_
)
197 layer_tree_host_
->SetNeedsCommit();
200 void Layer::SetNeedsFullTreeSync() {
201 if (!layer_tree_host_
)
204 layer_tree_host_
->SetNeedsFullTreeSync();
207 void Layer::SetNextCommitWaitsForActivation() {
208 if (!layer_tree_host_
)
211 layer_tree_host_
->SetNextCommitWaitsForActivation();
214 void Layer::SetNeedsPushProperties() {
215 if (needs_push_properties_
)
217 if (!parent_should_know_need_push_properties() && parent_
)
218 parent_
->AddDependentNeedsPushProperties();
219 needs_push_properties_
= true;
222 void Layer::AddDependentNeedsPushProperties() {
223 DCHECK_GE(num_dependents_need_push_properties_
, 0);
225 if (!parent_should_know_need_push_properties() && parent_
)
226 parent_
->AddDependentNeedsPushProperties();
228 num_dependents_need_push_properties_
++;
231 void Layer::RemoveDependentNeedsPushProperties() {
232 num_dependents_need_push_properties_
--;
233 DCHECK_GE(num_dependents_need_push_properties_
, 0);
235 if (!parent_should_know_need_push_properties() && parent_
)
236 parent_
->RemoveDependentNeedsPushProperties();
239 bool Layer::IsPropertyChangeAllowed() const {
240 if (!layer_tree_host_
)
243 if (!layer_tree_host_
->settings().strict_layer_property_change_checking
)
246 return !layer_tree_host_
->in_paint_layer_contents();
249 skia::RefPtr
<SkPicture
> Layer::GetPicture() const {
250 return skia::RefPtr
<SkPicture
>();
253 void Layer::SetParent(Layer
* layer
) {
254 DCHECK(!layer
|| !layer
->HasAncestor(this));
256 if (parent_should_know_need_push_properties()) {
258 parent_
->RemoveDependentNeedsPushProperties();
260 layer
->AddDependentNeedsPushProperties();
264 SetLayerTreeHost(parent_
? parent_
->layer_tree_host() : nullptr);
266 if (!layer_tree_host_
)
269 layer_tree_host_
->property_trees()->needs_rebuild
= true;
272 void Layer::AddChild(scoped_refptr
<Layer
> child
) {
273 InsertChild(child
, children_
.size());
276 void Layer::InsertChild(scoped_refptr
<Layer
> child
, size_t index
) {
277 DCHECK(IsPropertyChangeAllowed());
278 child
->RemoveFromParent();
279 AddDrawableDescendants(child
->NumDescendantsThatDrawContent() +
280 (child
->DrawsContent() ? 1 : 0));
281 child
->SetParent(this);
282 child
->stacking_order_changed_
= true;
284 index
= std::min(index
, children_
.size());
285 children_
.insert(children_
.begin() + index
, child
);
286 SetNeedsFullTreeSync();
289 void Layer::RemoveFromParent() {
290 DCHECK(IsPropertyChangeAllowed());
292 parent_
->RemoveChildOrDependent(this);
295 void Layer::RemoveChildOrDependent(Layer
* child
) {
296 if (mask_layer_
.get() == child
) {
297 mask_layer_
->SetParent(nullptr);
298 mask_layer_
= nullptr;
299 SetNeedsFullTreeSync();
302 if (replica_layer_
.get() == child
) {
303 replica_layer_
->SetParent(nullptr);
304 replica_layer_
= nullptr;
305 SetNeedsFullTreeSync();
309 for (LayerList::iterator iter
= children_
.begin();
310 iter
!= children_
.end();
312 if (iter
->get() != child
)
315 child
->SetParent(nullptr);
316 AddDrawableDescendants(-child
->NumDescendantsThatDrawContent() -
317 (child
->DrawsContent() ? 1 : 0));
318 children_
.erase(iter
);
319 SetNeedsFullTreeSync();
324 void Layer::ReplaceChild(Layer
* reference
, scoped_refptr
<Layer
> new_layer
) {
326 DCHECK_EQ(reference
->parent(), this);
327 DCHECK(IsPropertyChangeAllowed());
329 if (reference
== new_layer
.get())
332 // Find the index of |reference| in |children_|.
334 std::find_if(children_
.begin(), children_
.end(),
335 [reference
](const scoped_refptr
<Layer
>& layer
) {
336 return layer
.get() == reference
;
338 DCHECK(reference_it
!= children_
.end());
339 size_t reference_index
= reference_it
- children_
.begin();
340 reference
->RemoveFromParent();
342 if (new_layer
.get()) {
343 new_layer
->RemoveFromParent();
344 InsertChild(new_layer
, reference_index
);
348 void Layer::SetBounds(const gfx::Size
& size
) {
349 DCHECK(IsPropertyChangeAllowed());
350 if (bounds() == size
)
354 if (!layer_tree_host_
)
357 if (ClipNode
* clip_node
= layer_tree_host_
->property_trees()->clip_tree
.Node(
358 clip_tree_index())) {
359 if (clip_node
->owner_id
== id()) {
360 clip_node
->data
.clip
.set_size(size
);
361 layer_tree_host_
->property_trees()->clip_tree
.set_needs_update(true);
365 SetNeedsCommitNoRebuild();
368 Layer
* Layer::RootLayer() {
370 while (layer
->parent())
371 layer
= layer
->parent();
375 void Layer::RemoveAllChildren() {
376 DCHECK(IsPropertyChangeAllowed());
377 while (children_
.size()) {
378 Layer
* layer
= children_
[0].get();
379 DCHECK_EQ(this, layer
->parent());
380 layer
->RemoveFromParent();
384 void Layer::SetChildren(const LayerList
& children
) {
385 DCHECK(IsPropertyChangeAllowed());
386 if (children
== children_
)
390 for (size_t i
= 0; i
< children
.size(); ++i
)
391 AddChild(children
[i
]);
394 bool Layer::HasAncestor(const Layer
* ancestor
) const {
395 for (const Layer
* layer
= parent(); layer
; layer
= layer
->parent()) {
396 if (layer
== ancestor
)
402 void Layer::RequestCopyOfOutput(
403 scoped_ptr
<CopyOutputRequest
> request
) {
404 DCHECK(IsPropertyChangeAllowed());
405 bool had_no_copy_requests
= copy_requests_
.empty();
406 if (void* source
= request
->source()) {
407 auto it
= std::find_if(
408 copy_requests_
.begin(), copy_requests_
.end(),
409 [source
](const CopyOutputRequest
* x
) { return x
->source() == source
; });
410 if (it
!= copy_requests_
.end())
411 copy_requests_
.erase(it
);
413 if (request
->IsEmpty())
415 copy_requests_
.push_back(request
.Pass());
416 if (had_no_copy_requests
) {
417 bool copy_request_added
= true;
418 UpdateNumCopyRequestsForSubtree(copy_request_added
);
423 void Layer::UpdateNumCopyRequestsForSubtree(bool add
) {
424 int change
= add
? 1 : -1;
425 for (Layer
* layer
= this; layer
; layer
= layer
->parent()) {
426 layer
->num_layer_or_descendants_with_copy_request_
+= change
;
427 layer
->draw_properties().layer_or_descendant_has_copy_request
=
428 (layer
->num_layer_or_descendants_with_copy_request_
!= 0);
429 DCHECK_GE(layer
->num_layer_or_descendants_with_copy_request_
, 0);
433 void Layer::SetBackgroundColor(SkColor background_color
) {
434 DCHECK(IsPropertyChangeAllowed());
435 if (background_color_
== background_color
)
437 background_color_
= background_color
;
441 SkColor
Layer::SafeOpaqueBackgroundColor() const {
442 SkColor color
= background_color();
443 if (SkColorGetA(color
) == 255 && !contents_opaque()) {
444 color
= SK_ColorTRANSPARENT
;
445 } else if (SkColorGetA(color
) != 255 && contents_opaque()) {
446 for (const Layer
* layer
= parent(); layer
;
447 layer
= layer
->parent()) {
448 color
= layer
->background_color();
449 if (SkColorGetA(color
) == 255)
452 if (SkColorGetA(color
) != 255)
453 color
= layer_tree_host_
->background_color();
454 if (SkColorGetA(color
) != 255)
455 color
= SkColorSetA(color
, 255);
460 void Layer::SetMasksToBounds(bool masks_to_bounds
) {
461 DCHECK(IsPropertyChangeAllowed());
462 if (masks_to_bounds_
== masks_to_bounds
)
464 masks_to_bounds_
= masks_to_bounds
;
468 void Layer::SetMaskLayer(Layer
* mask_layer
) {
469 DCHECK(IsPropertyChangeAllowed());
470 if (mask_layer_
.get() == mask_layer
)
472 if (mask_layer_
.get()) {
473 DCHECK_EQ(this, mask_layer_
->parent());
474 mask_layer_
->RemoveFromParent();
476 mask_layer_
= mask_layer
;
477 if (mask_layer_
.get()) {
478 DCHECK(!mask_layer_
->parent());
479 mask_layer_
->RemoveFromParent();
480 mask_layer_
->SetParent(this);
481 mask_layer_
->SetIsMask(true);
483 SetNeedsFullTreeSync();
486 void Layer::SetReplicaLayer(Layer
* layer
) {
487 DCHECK(IsPropertyChangeAllowed());
488 if (replica_layer_
.get() == layer
)
490 if (replica_layer_
.get()) {
491 DCHECK_EQ(this, replica_layer_
->parent());
492 replica_layer_
->RemoveFromParent();
494 replica_layer_
= layer
;
495 if (replica_layer_
.get()) {
496 DCHECK(!replica_layer_
->parent());
497 replica_layer_
->RemoveFromParent();
498 replica_layer_
->SetParent(this);
500 SetNeedsFullTreeSync();
503 void Layer::SetFilters(const FilterOperations
& filters
) {
504 DCHECK(IsPropertyChangeAllowed());
505 if (filters_
== filters
)
511 bool Layer::FilterIsAnimating() const {
512 DCHECK(layer_tree_host_
);
513 return layer_animation_controller_
514 ? layer_animation_controller_
->IsCurrentlyAnimatingProperty(
516 LayerAnimationController::ObserverType::ACTIVE
)
517 : layer_tree_host_
->IsAnimatingFilterProperty(this);
520 bool Layer::HasPotentiallyRunningFilterAnimation() const {
521 if (layer_animation_controller_
) {
522 return layer_animation_controller_
->IsPotentiallyAnimatingProperty(
523 Animation::FILTER
, LayerAnimationController::ObserverType::ACTIVE
);
525 return layer_tree_host_
->HasPotentiallyRunningFilterAnimation(this);
528 void Layer::SetBackgroundFilters(const FilterOperations
& filters
) {
529 DCHECK(IsPropertyChangeAllowed());
530 if (background_filters_
== filters
)
532 background_filters_
= filters
;
536 void Layer::SetOpacity(float opacity
) {
537 DCHECK(IsPropertyChangeAllowed());
538 if (opacity_
== opacity
)
544 bool Layer::OpacityIsAnimating() const {
545 DCHECK(layer_tree_host_
);
546 return layer_animation_controller_
547 ? layer_animation_controller_
->IsCurrentlyAnimatingProperty(
549 LayerAnimationController::ObserverType::ACTIVE
)
550 : layer_tree_host_
->IsAnimatingOpacityProperty(this);
553 bool Layer::HasPotentiallyRunningOpacityAnimation() const {
554 if (layer_animation_controller_
) {
555 return layer_animation_controller_
->IsPotentiallyAnimatingProperty(
556 Animation::OPACITY
, LayerAnimationController::ObserverType::ACTIVE
);
558 return layer_tree_host_
->HasPotentiallyRunningOpacityAnimation(this);
561 bool Layer::OpacityCanAnimateOnImplThread() const {
565 void Layer::SetBlendMode(SkXfermode::Mode blend_mode
) {
566 DCHECK(IsPropertyChangeAllowed());
567 if (blend_mode_
== blend_mode
)
570 // Allowing only blend modes that are defined in the CSS Compositing standard:
571 // http://dev.w3.org/fxtf/compositing-1/#blending
572 switch (blend_mode
) {
573 case SkXfermode::kSrcOver_Mode
:
574 case SkXfermode::kScreen_Mode
:
575 case SkXfermode::kOverlay_Mode
:
576 case SkXfermode::kDarken_Mode
:
577 case SkXfermode::kLighten_Mode
:
578 case SkXfermode::kColorDodge_Mode
:
579 case SkXfermode::kColorBurn_Mode
:
580 case SkXfermode::kHardLight_Mode
:
581 case SkXfermode::kSoftLight_Mode
:
582 case SkXfermode::kDifference_Mode
:
583 case SkXfermode::kExclusion_Mode
:
584 case SkXfermode::kMultiply_Mode
:
585 case SkXfermode::kHue_Mode
:
586 case SkXfermode::kSaturation_Mode
:
587 case SkXfermode::kColor_Mode
:
588 case SkXfermode::kLuminosity_Mode
:
589 // supported blend modes
591 case SkXfermode::kClear_Mode
:
592 case SkXfermode::kSrc_Mode
:
593 case SkXfermode::kDst_Mode
:
594 case SkXfermode::kDstOver_Mode
:
595 case SkXfermode::kSrcIn_Mode
:
596 case SkXfermode::kDstIn_Mode
:
597 case SkXfermode::kSrcOut_Mode
:
598 case SkXfermode::kDstOut_Mode
:
599 case SkXfermode::kSrcATop_Mode
:
600 case SkXfermode::kDstATop_Mode
:
601 case SkXfermode::kXor_Mode
:
602 case SkXfermode::kPlus_Mode
:
603 case SkXfermode::kModulate_Mode
:
604 // Porter Duff Compositing Operators are not yet supported
605 // http://dev.w3.org/fxtf/compositing-1/#porterduffcompositingoperators
610 blend_mode_
= blend_mode
;
614 void Layer::SetIsRootForIsolatedGroup(bool root
) {
615 DCHECK(IsPropertyChangeAllowed());
616 if (is_root_for_isolated_group_
== root
)
618 is_root_for_isolated_group_
= root
;
622 void Layer::SetContentsOpaque(bool opaque
) {
623 DCHECK(IsPropertyChangeAllowed());
624 if (contents_opaque_
== opaque
)
626 contents_opaque_
= opaque
;
630 void Layer::SetPosition(const gfx::PointF
& position
) {
631 DCHECK(IsPropertyChangeAllowed());
632 if (position_
== position
)
634 position_
= position
;
636 if (!layer_tree_host_
)
639 if (TransformNode
* transform_node
=
640 layer_tree_host_
->property_trees()->transform_tree
.Node(
641 transform_tree_index())) {
642 if (transform_node
->owner_id
== id()) {
643 transform_node
->data
.update_post_local_transform(position
,
645 transform_node
->data
.needs_local_transform_update
= true;
646 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
647 SetNeedsCommitNoRebuild();
655 bool Layer::IsContainerForFixedPositionLayers() const {
656 if (!transform_
.IsIdentityOrTranslation())
658 if (parent_
&& !parent_
->transform_
.IsIdentityOrTranslation())
660 return is_container_for_fixed_position_layers_
;
663 bool Are2dAxisAligned(const gfx::Transform
& a
,
664 const gfx::Transform
& b
,
665 bool* is_invertible
) {
666 if (a
.IsScaleOrTranslation() && b
.IsScaleOrTranslation()) {
667 *is_invertible
= b
.IsInvertible();
671 gfx::Transform
inverse(gfx::Transform::kSkipInitialization
);
672 *is_invertible
= b
.GetInverse(&inverse
);
675 return inverse
.Preserves2dAxisAlignment();
678 void Layer::SetTransform(const gfx::Transform
& transform
) {
679 DCHECK(IsPropertyChangeAllowed());
680 if (transform_
== transform
)
683 if (layer_tree_host_
) {
684 if (TransformNode
* transform_node
=
685 layer_tree_host_
->property_trees()->transform_tree
.Node(
686 transform_tree_index())) {
687 if (transform_node
->owner_id
== id()) {
688 // We need to trigger a rebuild if we could have affected 2d axis
689 // alignment. We'll check to see if transform and transform_ are axis
690 // align with respect to one another.
691 bool invertible
= false;
692 bool preserves_2d_axis_alignment
=
693 Are2dAxisAligned(transform_
, transform
, &invertible
);
694 transform_node
->data
.local
= transform
;
695 transform_node
->data
.needs_local_transform_update
= true;
696 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(
698 if (preserves_2d_axis_alignment
)
699 SetNeedsCommitNoRebuild();
702 transform_
= transform
;
703 transform_is_invertible_
= invertible
;
709 transform_
= transform
;
710 transform_is_invertible_
= transform
.IsInvertible();
715 void Layer::SetTransformOrigin(const gfx::Point3F
& transform_origin
) {
716 DCHECK(IsPropertyChangeAllowed());
717 if (transform_origin_
== transform_origin
)
719 transform_origin_
= transform_origin
;
721 if (!layer_tree_host_
)
724 if (TransformNode
* transform_node
=
725 layer_tree_host_
->property_trees()->transform_tree
.Node(
726 transform_tree_index())) {
727 if (transform_node
->owner_id
== id()) {
728 transform_node
->data
.update_pre_local_transform(transform_origin
);
729 transform_node
->data
.update_post_local_transform(position(),
731 transform_node
->data
.needs_local_transform_update
= true;
732 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
733 SetNeedsCommitNoRebuild();
741 bool Layer::AnimationsPreserveAxisAlignment() const {
742 DCHECK(layer_tree_host_
);
743 return layer_animation_controller_
744 ? layer_animation_controller_
->AnimationsPreserveAxisAlignment()
745 : layer_tree_host_
->AnimationsPreserveAxisAlignment(this);
748 bool Layer::TransformIsAnimating() const {
749 DCHECK(layer_tree_host_
);
750 return layer_animation_controller_
751 ? layer_animation_controller_
->IsCurrentlyAnimatingProperty(
752 Animation::TRANSFORM
,
753 LayerAnimationController::ObserverType::ACTIVE
)
754 : layer_tree_host_
->IsAnimatingTransformProperty(this);
757 bool Layer::HasPotentiallyRunningTransformAnimation() const {
758 if (layer_animation_controller_
) {
759 return layer_animation_controller_
->IsPotentiallyAnimatingProperty(
760 Animation::TRANSFORM
, LayerAnimationController::ObserverType::ACTIVE
);
762 return layer_tree_host_
->HasPotentiallyRunningTransformAnimation(this);
765 bool Layer::HasAnyAnimationTargetingProperty(
766 Animation::TargetProperty property
) const {
767 if (layer_animation_controller_
)
768 return !!layer_animation_controller_
->GetAnimation(property
);
770 return layer_tree_host_
->HasAnyAnimationTargetingProperty(this, property
);
773 bool Layer::ScrollOffsetAnimationWasInterrupted() const {
774 DCHECK(layer_tree_host_
);
775 return layer_animation_controller_
776 ? layer_animation_controller_
777 ->scroll_offset_animation_was_interrupted()
778 : layer_tree_host_
->ScrollOffsetAnimationWasInterrupted(this);
781 void Layer::SetScrollParent(Layer
* parent
) {
782 DCHECK(IsPropertyChangeAllowed());
783 if (scroll_parent_
== parent
)
787 scroll_parent_
->RemoveScrollChild(this);
789 scroll_parent_
= parent
;
792 scroll_parent_
->AddScrollChild(this);
797 void Layer::AddScrollChild(Layer
* child
) {
798 if (!scroll_children_
)
799 scroll_children_
.reset(new std::set
<Layer
*>);
800 scroll_children_
->insert(child
);
801 if (layer_tree_host_
&& !layer_tree_host_
->needs_meta_info_recomputation()) {
802 num_children_with_scroll_parent_
++;
803 draw_properties().has_child_with_a_scroll_parent
= true;
808 void Layer::RemoveScrollChild(Layer
* child
) {
809 scroll_children_
->erase(child
);
810 if (scroll_children_
->empty())
811 scroll_children_
= nullptr;
812 if (layer_tree_host_
&& !layer_tree_host_
->needs_meta_info_recomputation()) {
813 num_children_with_scroll_parent_
--;
814 DCHECK_GE(num_children_with_scroll_parent_
, 0);
815 draw_properties().has_child_with_a_scroll_parent
=
816 (num_children_with_scroll_parent_
!= 0);
821 void Layer::SetClipParent(Layer
* ancestor
) {
822 DCHECK(IsPropertyChangeAllowed());
823 if (clip_parent_
== ancestor
)
827 clip_parent_
->RemoveClipChild(this);
829 clip_parent_
= ancestor
;
832 clip_parent_
->AddClipChild(this);
835 if (layer_tree_host_
)
836 layer_tree_host_
->SetNeedsMetaInfoRecomputation(true);
839 void Layer::AddClipChild(Layer
* child
) {
841 clip_children_
.reset(new std::set
<Layer
*>);
842 clip_children_
->insert(child
);
846 void Layer::RemoveClipChild(Layer
* child
) {
847 clip_children_
->erase(child
);
848 if (clip_children_
->empty())
849 clip_children_
= nullptr;
853 void Layer::SetScrollOffset(const gfx::ScrollOffset
& scroll_offset
) {
854 DCHECK(IsPropertyChangeAllowed());
856 if (scroll_offset_
== scroll_offset
)
858 scroll_offset_
= scroll_offset
;
860 if (!layer_tree_host_
)
863 if (TransformNode
* transform_node
=
864 layer_tree_host_
->property_trees()->transform_tree
.Node(
865 transform_tree_index())) {
866 if (transform_node
->owner_id
== id()) {
867 transform_node
->data
.scroll_offset
= CurrentScrollOffset();
868 transform_node
->data
.needs_local_transform_update
= true;
869 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
870 SetNeedsCommitNoRebuild();
878 void Layer::SetScrollCompensationAdjustment(
879 const gfx::Vector2dF
& scroll_compensation_adjustment
) {
880 if (scroll_compensation_adjustment_
== scroll_compensation_adjustment
)
882 scroll_compensation_adjustment_
= scroll_compensation_adjustment
;
886 gfx::Vector2dF
Layer::ScrollCompensationAdjustment() const {
887 return scroll_compensation_adjustment_
;
890 void Layer::SetScrollOffsetFromImplSide(
891 const gfx::ScrollOffset
& scroll_offset
) {
892 DCHECK(IsPropertyChangeAllowed());
893 // This function only gets called during a BeginMainFrame, so there
894 // is no need to call SetNeedsUpdate here.
895 DCHECK(layer_tree_host_
&& layer_tree_host_
->CommitRequested());
896 if (scroll_offset_
== scroll_offset
)
898 scroll_offset_
= scroll_offset
;
899 SetNeedsPushProperties();
901 bool needs_rebuild
= true;
902 if (TransformNode
* transform_node
=
903 layer_tree_host_
->property_trees()->transform_tree
.Node(
904 transform_tree_index())) {
905 if (transform_node
->owner_id
== id()) {
906 transform_node
->data
.scroll_offset
= CurrentScrollOffset();
907 transform_node
->data
.needs_local_transform_update
= true;
908 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
909 needs_rebuild
= false;
914 layer_tree_host_
->property_trees()->needs_rebuild
= true;
916 if (!did_scroll_callback_
.is_null())
917 did_scroll_callback_
.Run();
918 // The callback could potentially change the layer structure:
919 // "this" may have been destroyed during the process.
922 void Layer::SetScrollClipLayerId(int clip_layer_id
) {
923 DCHECK(IsPropertyChangeAllowed());
924 if (scroll_clip_layer_id_
== clip_layer_id
)
926 scroll_clip_layer_id_
= clip_layer_id
;
930 void Layer::SetUserScrollable(bool horizontal
, bool vertical
) {
931 DCHECK(IsPropertyChangeAllowed());
932 if (user_scrollable_horizontal_
== horizontal
&&
933 user_scrollable_vertical_
== vertical
)
935 user_scrollable_horizontal_
= horizontal
;
936 user_scrollable_vertical_
= vertical
;
940 void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
941 DCHECK(IsPropertyChangeAllowed());
942 if (should_scroll_on_main_thread_
== should_scroll_on_main_thread
)
944 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
948 void Layer::SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
949 DCHECK(IsPropertyChangeAllowed());
950 if (have_wheel_event_handlers_
== have_wheel_event_handlers
)
952 if (touch_event_handler_region_
.IsEmpty() && layer_tree_host_
&&
953 !layer_tree_host_
->needs_meta_info_recomputation())
954 UpdateNumInputHandlersForSubtree(have_wheel_event_handlers
);
956 have_wheel_event_handlers_
= have_wheel_event_handlers
;
960 void Layer::UpdateNumInputHandlersForSubtree(bool add
) {
961 int change
= add
? 1 : -1;
962 for (Layer
* layer
= this; layer
; layer
= layer
->parent()) {
963 layer
->num_layer_or_descendants_with_input_handler_
+= change
;
964 layer
->draw_properties().layer_or_descendant_has_input_handler
=
965 (layer
->num_layer_or_descendants_with_input_handler_
!= 0);
966 DCHECK_GE(layer
->num_layer_or_descendants_with_input_handler_
, 0);
970 void Layer::SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
971 DCHECK(IsPropertyChangeAllowed());
972 if (have_scroll_event_handlers_
== have_scroll_event_handlers
)
974 have_scroll_event_handlers_
= have_scroll_event_handlers
;
978 void Layer::SetNonFastScrollableRegion(const Region
& region
) {
979 DCHECK(IsPropertyChangeAllowed());
980 if (non_fast_scrollable_region_
== region
)
982 non_fast_scrollable_region_
= region
;
986 void Layer::SetTouchEventHandlerRegion(const Region
& region
) {
987 DCHECK(IsPropertyChangeAllowed());
988 if (touch_event_handler_region_
== region
)
990 if (!have_wheel_event_handlers_
&& layer_tree_host_
&&
991 !layer_tree_host_
->needs_meta_info_recomputation())
992 UpdateNumInputHandlersForSubtree(!region
.IsEmpty());
994 touch_event_handler_region_
= region
;
998 void Layer::SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
999 DCHECK(IsPropertyChangeAllowed());
1000 if (scroll_blocks_on_
== scroll_blocks_on
)
1002 scroll_blocks_on_
= scroll_blocks_on
;
1006 void Layer::SetForceRenderSurface(bool force
) {
1007 DCHECK(IsPropertyChangeAllowed());
1008 if (force_render_surface_
== force
)
1010 force_render_surface_
= force
;
1014 void Layer::SetDoubleSided(bool double_sided
) {
1015 DCHECK(IsPropertyChangeAllowed());
1016 if (double_sided_
== double_sided
)
1018 double_sided_
= double_sided
;
1022 void Layer::Set3dSortingContextId(int id
) {
1023 DCHECK(IsPropertyChangeAllowed());
1024 if (id
== sorting_context_id_
)
1026 sorting_context_id_
= id
;
1030 void Layer::SetTransformTreeIndex(int index
) {
1031 DCHECK(IsPropertyChangeAllowed());
1032 if (transform_tree_index_
== index
)
1034 transform_tree_index_
= index
;
1035 SetNeedsPushProperties();
1038 int Layer::transform_tree_index() const {
1039 if (!layer_tree_host_
||
1040 layer_tree_host_
->property_trees()->sequence_number
!=
1041 property_tree_sequence_number_
) {
1044 return transform_tree_index_
;
1047 void Layer::SetClipTreeIndex(int index
) {
1048 DCHECK(IsPropertyChangeAllowed());
1049 if (clip_tree_index_
== index
)
1051 clip_tree_index_
= index
;
1052 SetNeedsPushProperties();
1055 int Layer::clip_tree_index() const {
1056 if (!layer_tree_host_
||
1057 layer_tree_host_
->property_trees()->sequence_number
!=
1058 property_tree_sequence_number_
) {
1061 return clip_tree_index_
;
1064 void Layer::SetOpacityTreeIndex(int index
) {
1065 DCHECK(IsPropertyChangeAllowed());
1066 if (opacity_tree_index_
== index
)
1068 opacity_tree_index_
= index
;
1069 SetNeedsPushProperties();
1072 int Layer::opacity_tree_index() const {
1073 if (!layer_tree_host_
||
1074 layer_tree_host_
->property_trees()->sequence_number
!=
1075 property_tree_sequence_number_
) {
1078 return opacity_tree_index_
;
1081 void Layer::InvalidatePropertyTreesIndices() {
1082 int invalid_property_tree_index
= -1;
1083 SetTransformTreeIndex(invalid_property_tree_index
);
1084 SetClipTreeIndex(invalid_property_tree_index
);
1085 SetOpacityTreeIndex(invalid_property_tree_index
);
1088 void Layer::SetShouldFlattenTransform(bool should_flatten
) {
1089 DCHECK(IsPropertyChangeAllowed());
1090 if (should_flatten_transform_
== should_flatten
)
1092 should_flatten_transform_
= should_flatten
;
1096 void Layer::SetIsDrawable(bool is_drawable
) {
1097 DCHECK(IsPropertyChangeAllowed());
1098 if (is_drawable_
== is_drawable
)
1101 is_drawable_
= is_drawable
;
1102 UpdateDrawsContent(HasDrawableContent());
1105 void Layer::SetHideLayerAndSubtree(bool hide
) {
1106 DCHECK(IsPropertyChangeAllowed());
1107 if (hide_layer_and_subtree_
== hide
)
1110 hide_layer_and_subtree_
= hide
;
1114 void Layer::SetNeedsDisplayRect(const gfx::Rect
& dirty_rect
) {
1115 if (dirty_rect
.IsEmpty())
1118 SetNeedsPushProperties();
1119 update_rect_
.Union(dirty_rect
);
1125 bool Layer::DescendantIsFixedToContainerLayer() const {
1126 for (size_t i
= 0; i
< children_
.size(); ++i
) {
1127 if (children_
[i
]->position_constraint_
.is_fixed_position() ||
1128 children_
[i
]->DescendantIsFixedToContainerLayer())
1134 void Layer::SetIsContainerForFixedPositionLayers(bool container
) {
1135 if (is_container_for_fixed_position_layers_
== container
)
1137 is_container_for_fixed_position_layers_
= container
;
1139 if (layer_tree_host_
&& layer_tree_host_
->CommitRequested())
1142 // Only request a commit if we have a fixed positioned descendant.
1143 if (DescendantIsFixedToContainerLayer())
1147 void Layer::SetPositionConstraint(const LayerPositionConstraint
& constraint
) {
1148 DCHECK(IsPropertyChangeAllowed());
1149 if (position_constraint_
== constraint
)
1151 position_constraint_
= constraint
;
1155 static void RunCopyCallbackOnMainThread(scoped_ptr
<CopyOutputRequest
> request
,
1156 scoped_ptr
<CopyOutputResult
> result
) {
1157 request
->SendResult(result
.Pass());
1160 static void PostCopyCallbackToMainThread(
1161 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
,
1162 scoped_ptr
<CopyOutputRequest
> request
,
1163 scoped_ptr
<CopyOutputResult
> result
) {
1164 main_thread_task_runner
->PostTask(FROM_HERE
,
1165 base::Bind(&RunCopyCallbackOnMainThread
,
1166 base::Passed(&request
),
1167 base::Passed(&result
)));
1170 void Layer::PushPropertiesTo(LayerImpl
* layer
) {
1171 DCHECK(layer_tree_host_
);
1173 // If we did not SavePaintProperties() for the layer this frame, then push the
1174 // real property values, not the paint property values.
1175 bool use_paint_properties
= paint_properties_
.source_frame_number
==
1176 layer_tree_host_
->source_frame_number();
1178 layer
->SetTransformOrigin(transform_origin_
);
1179 layer
->SetBackgroundColor(background_color_
);
1180 layer
->SetBounds(use_paint_properties
? paint_properties_
.bounds
1183 if (frame_viewer_instrumentation::IsTracingLayerTreeSnapshots())
1184 layer
->SetDebugInfo(TakeDebugInfo());
1186 layer
->SetTransformTreeIndex(transform_tree_index());
1187 layer
->SetOpacityTreeIndex(opacity_tree_index());
1188 layer
->SetClipTreeIndex(clip_tree_index());
1189 layer
->set_offset_to_transform_parent(offset_to_transform_parent_
);
1190 layer
->SetDoubleSided(double_sided_
);
1191 layer
->SetDrawsContent(DrawsContent());
1192 layer
->SetHideLayerAndSubtree(hide_layer_and_subtree_
);
1193 layer
->SetHasRenderSurface(has_render_surface_
);
1194 if (!layer
->FilterIsAnimatingOnImplOnly() && !FilterIsAnimating())
1195 layer
->SetFilters(filters_
);
1196 DCHECK(!(FilterIsAnimating() && layer
->FilterIsAnimatingOnImplOnly()));
1197 layer
->SetBackgroundFilters(background_filters());
1198 layer
->SetMasksToBounds(masks_to_bounds_
);
1199 layer
->SetShouldScrollOnMainThread(should_scroll_on_main_thread_
);
1200 layer
->SetHaveWheelEventHandlers(have_wheel_event_handlers_
);
1201 layer
->SetHaveScrollEventHandlers(have_scroll_event_handlers_
);
1202 layer
->SetNonFastScrollableRegion(non_fast_scrollable_region_
);
1203 layer
->SetTouchEventHandlerRegion(touch_event_handler_region_
);
1204 layer
->SetScrollBlocksOn(scroll_blocks_on_
);
1205 layer
->SetContentsOpaque(contents_opaque_
);
1206 if (!layer
->OpacityIsAnimatingOnImplOnly() && !OpacityIsAnimating())
1207 layer
->SetOpacity(opacity_
);
1208 DCHECK(!(OpacityIsAnimating() && layer
->OpacityIsAnimatingOnImplOnly()));
1209 layer
->SetBlendMode(blend_mode_
);
1210 layer
->SetIsRootForIsolatedGroup(is_root_for_isolated_group_
);
1211 layer
->SetPosition(position_
);
1212 layer
->SetIsContainerForFixedPositionLayers(
1213 IsContainerForFixedPositionLayers());
1214 layer
->SetPositionConstraint(position_constraint_
);
1215 layer
->SetShouldFlattenTransform(should_flatten_transform_
);
1216 layer
->set_should_flatten_transform_from_property_tree(
1217 should_flatten_transform_from_property_tree_
);
1218 layer
->set_is_clipped(is_clipped_
);
1219 layer
->set_draw_blend_mode(draw_blend_mode_
);
1220 layer
->SetUseParentBackfaceVisibility(use_parent_backface_visibility_
);
1221 if (!layer
->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating())
1222 layer
->SetTransformAndInvertibility(transform_
, transform_is_invertible_
);
1223 DCHECK(!(TransformIsAnimating() && layer
->TransformIsAnimatingOnImplOnly()));
1224 layer
->Set3dSortingContextId(sorting_context_id_
);
1225 layer
->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_
);
1227 layer
->SetScrollClipLayer(scroll_clip_layer_id_
);
1228 layer
->set_user_scrollable_horizontal(user_scrollable_horizontal_
);
1229 layer
->set_user_scrollable_vertical(user_scrollable_vertical_
);
1231 LayerImpl
* scroll_parent
= nullptr;
1232 if (scroll_parent_
) {
1233 scroll_parent
= layer
->layer_tree_impl()->LayerById(scroll_parent_
->id());
1234 DCHECK(scroll_parent
);
1237 layer
->SetScrollParent(scroll_parent
);
1238 if (scroll_children_
) {
1239 std::set
<LayerImpl
*>* scroll_children
= new std::set
<LayerImpl
*>;
1240 for (std::set
<Layer
*>::iterator it
= scroll_children_
->begin();
1241 it
!= scroll_children_
->end();
1243 DCHECK_EQ((*it
)->scroll_parent(), this);
1244 LayerImpl
* scroll_child
=
1245 layer
->layer_tree_impl()->LayerById((*it
)->id());
1246 DCHECK(scroll_child
);
1247 scroll_children
->insert(scroll_child
);
1249 layer
->SetScrollChildren(scroll_children
);
1251 layer
->SetScrollChildren(nullptr);
1254 LayerImpl
* clip_parent
= nullptr;
1257 layer
->layer_tree_impl()->LayerById(clip_parent_
->id());
1258 DCHECK(clip_parent
);
1261 layer
->SetClipParent(clip_parent
);
1262 if (clip_children_
) {
1263 std::set
<LayerImpl
*>* clip_children
= new std::set
<LayerImpl
*>;
1264 for (std::set
<Layer
*>::iterator it
= clip_children_
->begin();
1265 it
!= clip_children_
->end(); ++it
) {
1266 DCHECK_EQ((*it
)->clip_parent(), this);
1267 LayerImpl
* clip_child
= layer
->layer_tree_impl()->LayerById((*it
)->id());
1269 clip_children
->insert(clip_child
);
1271 layer
->SetClipChildren(clip_children
);
1273 layer
->SetClipChildren(nullptr);
1276 // When a scroll offset animation is interrupted the new scroll position on
1277 // the pending tree will clobber any impl-side scrolling occuring on the
1278 // active tree. To do so, avoid scrolling the pending tree along with it
1279 // instead of trying to undo that scrolling later.
1280 if (ScrollOffsetAnimationWasInterrupted())
1281 layer
->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_
);
1283 layer
->PushScrollOffsetFromMainThread(scroll_offset_
);
1284 layer
->SetScrollCompensationAdjustment(ScrollCompensationAdjustment());
1286 // Wrap the copy_requests_ in a PostTask to the main thread.
1287 bool had_copy_requests
= !copy_requests_
.empty();
1288 ScopedPtrVector
<CopyOutputRequest
> main_thread_copy_requests
;
1289 for (ScopedPtrVector
<CopyOutputRequest
>::iterator it
= copy_requests_
.begin();
1290 it
!= copy_requests_
.end();
1292 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
=
1293 layer_tree_host()->proxy()->MainThreadTaskRunner();
1294 scoped_ptr
<CopyOutputRequest
> original_request
= copy_requests_
.take(it
);
1295 const CopyOutputRequest
& original_request_ref
= *original_request
;
1296 scoped_ptr
<CopyOutputRequest
> main_thread_request
=
1297 CopyOutputRequest::CreateRelayRequest(
1298 original_request_ref
,
1299 base::Bind(&PostCopyCallbackToMainThread
,
1300 main_thread_task_runner
,
1301 base::Passed(&original_request
)));
1302 main_thread_copy_requests
.push_back(main_thread_request
.Pass());
1304 if (!copy_requests_
.empty() && layer_tree_host_
)
1305 layer_tree_host_
->property_trees()->needs_rebuild
= true;
1306 if (had_copy_requests
)
1307 UpdateNumCopyRequestsForSubtree(false);
1308 copy_requests_
.clear();
1309 layer
->PassCopyRequests(&main_thread_copy_requests
);
1311 // If the main thread commits multiple times before the impl thread actually
1312 // draws, then damage tracking will become incorrect if we simply clobber the
1313 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
1314 // union) any update changes that have occurred on the main thread.
1315 update_rect_
.Union(layer
->update_rect());
1316 layer
->SetUpdateRect(update_rect_
);
1318 layer
->SetStackingOrderChanged(stacking_order_changed_
);
1320 if (layer
->layer_animation_controller() && layer_animation_controller_
)
1321 layer_animation_controller_
->PushAnimationUpdatesTo(
1322 layer
->layer_animation_controller());
1324 if (frame_timing_requests_dirty_
) {
1325 layer
->SetFrameTimingRequests(frame_timing_requests_
);
1326 frame_timing_requests_dirty_
= false;
1329 bool is_page_scale_layer
= this == layer_tree_host()->page_scale_layer();
1330 bool parent_affected
=
1331 layer
->parent() && layer
->parent()->IsAffectedByPageScale();
1332 layer
->SetIsAffectedByPageScale(is_page_scale_layer
|| parent_affected
);
1334 // Reset any state that should be cleared for the next update.
1335 stacking_order_changed_
= false;
1336 update_rect_
= gfx::Rect();
1338 needs_push_properties_
= false;
1339 num_dependents_need_push_properties_
= 0;
1342 scoped_ptr
<LayerImpl
> Layer::CreateLayerImpl(LayerTreeImpl
* tree_impl
) {
1343 return LayerImpl::Create(tree_impl
, layer_id_
,
1344 new LayerImpl::SyncedScrollOffset
);
1347 bool Layer::DrawsContent() const {
1348 return draws_content_
;
1351 bool Layer::HasDrawableContent() const {
1352 return is_drawable_
;
1355 void Layer::UpdateDrawsContent(bool has_drawable_content
) {
1356 bool draws_content
= has_drawable_content
;
1357 DCHECK(is_drawable_
|| !has_drawable_content
);
1358 if (draws_content
== draws_content_
)
1361 if (HasDelegatedContent()) {
1362 // Layers with delegated content need to be treated as if they have as
1363 // many children as the number of layers they own delegated quads for.
1364 // Since we don't know this number right now, we choose one that acts like
1365 // infinity for our purposes.
1366 AddDrawableDescendants(draws_content
? 1000 : -1000);
1370 parent()->AddDrawableDescendants(draws_content
? 1 : -1);
1372 draws_content_
= draws_content
;
1376 int Layer::NumDescendantsThatDrawContent() const {
1377 return num_descendants_that_draw_content_
;
1380 void Layer::SavePaintProperties() {
1381 DCHECK(layer_tree_host_
);
1383 // TODO(reveman): Save all layer properties that we depend on not
1384 // changing until PushProperties() has been called. crbug.com/231016
1385 paint_properties_
.bounds
= bounds_
;
1386 paint_properties_
.source_frame_number
=
1387 layer_tree_host_
->source_frame_number();
1390 bool Layer::Update() {
1391 DCHECK(layer_tree_host_
);
1392 DCHECK_EQ(layer_tree_host_
->source_frame_number(),
1393 paint_properties_
.source_frame_number
) <<
1394 "SavePaintProperties must be called for any layer that is painted.";
1398 bool Layer::NeedMoreUpdates() {
1402 bool Layer::IsSuitableForGpuRasterization() const {
1406 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
1407 Layer::TakeDebugInfo() {
1409 return client_
->TakeDebugInfo();
1414 void Layer::SetHasRenderSurface(bool has_render_surface
) {
1415 if (has_render_surface_
== has_render_surface
)
1417 has_render_surface_
= has_render_surface
;
1418 // We do not need SetNeedsCommit here, since this is only ever called
1419 // during a commit, from CalculateDrawProperties.
1420 SetNeedsPushProperties();
1421 layer_tree_host_
->property_trees()->needs_rebuild
= true;
1424 void Layer::CreateRenderSurface() {
1425 DCHECK(!render_surface_
);
1426 render_surface_
= make_scoped_ptr(new RenderSurface(this));
1429 void Layer::ClearRenderSurface() {
1430 render_surface_
= nullptr;
1433 void Layer::ClearRenderSurfaceLayerList() {
1434 if (render_surface_
)
1435 render_surface_
->ClearLayerLists();
1438 gfx::ScrollOffset
Layer::ScrollOffsetForAnimation() const {
1439 return CurrentScrollOffset();
1442 // On<Property>Animated is called due to an ongoing accelerated animation.
1443 // Since this animation is also being run on the compositor thread, there
1444 // is no need to request a commit to push this value over, so the value is
1445 // set directly rather than by calling Set<Property>.
1446 void Layer::OnFilterAnimated(const FilterOperations
& filters
) {
1450 void Layer::OnOpacityAnimated(float opacity
) {
1452 if (layer_tree_host_
) {
1453 if (OpacityNode
* node
=
1454 layer_tree_host_
->property_trees()->opacity_tree
.Node(
1455 opacity_tree_index())) {
1456 if (node
->owner_id
== id()) {
1457 node
->data
.opacity
= opacity
;
1458 layer_tree_host_
->property_trees()->opacity_tree
.set_needs_update(true);
1464 void Layer::OnTransformAnimated(const gfx::Transform
& transform
) {
1465 if (transform_
== transform
)
1467 transform_
= transform
;
1468 transform_is_invertible_
= transform
.IsInvertible();
1469 if (layer_tree_host_
) {
1470 if (TransformNode
* node
=
1471 layer_tree_host_
->property_trees()->transform_tree
.Node(
1472 transform_tree_index())) {
1473 if (node
->owner_id
== id()) {
1474 node
->data
.local
= transform
;
1475 node
->data
.needs_local_transform_update
= true;
1476 node
->data
.is_animated
= true;
1477 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(
1484 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) {
1485 // Do nothing. Scroll deltas will be sent from the compositor thread back
1486 // to the main thread in the same manner as during non-animated
1487 // compositor-driven scrolling.
1490 void Layer::OnAnimationWaitingForDeletion() {
1491 // Animations are only deleted during PushProperties.
1492 SetNeedsPushProperties();
1495 void Layer::OnTransformIsPotentiallyAnimatingChanged(bool is_animating
) {
1496 if (!layer_tree_host_
)
1498 TransformTree
& transform_tree
=
1499 layer_tree_host_
->property_trees()->transform_tree
;
1500 TransformNode
* node
= transform_tree
.Node(transform_tree_index());
1504 if (node
->owner_id
== id()) {
1505 node
->data
.is_animated
= is_animating
;
1506 transform_tree
.set_needs_update(true);
1510 bool Layer::IsActive() const {
1514 bool Layer::AddAnimation(scoped_ptr
<Animation
> animation
) {
1515 DCHECK(layer_animation_controller_
);
1516 if (!layer_animation_controller_
->animation_registrar())
1519 if (animation
->target_property() == Animation::SCROLL_OFFSET
&&
1520 !layer_animation_controller_
->animation_registrar()
1521 ->supports_scroll_animations())
1524 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer",
1526 layer_animation_controller_
->AddAnimation(animation
.Pass());
1531 void Layer::PauseAnimation(int animation_id
, double time_offset
) {
1532 DCHECK(layer_animation_controller_
);
1533 layer_animation_controller_
->PauseAnimation(
1534 animation_id
, base::TimeDelta::FromSecondsD(time_offset
));
1538 void Layer::RemoveAnimation(int animation_id
) {
1539 DCHECK(layer_animation_controller_
);
1540 layer_animation_controller_
->RemoveAnimation(animation_id
);
1544 void Layer::RemoveAnimation(int animation_id
,
1545 Animation::TargetProperty property
) {
1546 DCHECK(layer_animation_controller_
);
1547 layer_animation_controller_
->RemoveAnimation(animation_id
, property
);
1551 void Layer::SetLayerAnimationControllerForTest(
1552 scoped_refptr
<LayerAnimationController
> controller
) {
1553 DCHECK(layer_animation_controller_
);
1554 layer_animation_controller_
->RemoveValueObserver(this);
1555 layer_animation_controller_
= controller
;
1556 layer_animation_controller_
->AddValueObserver(this);
1560 bool Layer::HasActiveAnimation() const {
1561 DCHECK(layer_tree_host_
);
1562 return layer_animation_controller_
1563 ? layer_animation_controller_
->HasActiveAnimation()
1564 : layer_tree_host_
->HasActiveAnimation(this);
1567 void Layer::RegisterForAnimations(AnimationRegistrar
* registrar
) {
1568 if (layer_animation_controller_
)
1569 layer_animation_controller_
->SetAnimationRegistrar(registrar
);
1572 void Layer::AddLayerAnimationEventObserver(
1573 LayerAnimationEventObserver
* animation_observer
) {
1574 DCHECK(layer_animation_controller_
);
1575 layer_animation_controller_
->AddEventObserver(animation_observer
);
1578 void Layer::RemoveLayerAnimationEventObserver(
1579 LayerAnimationEventObserver
* animation_observer
) {
1580 DCHECK(layer_animation_controller_
);
1581 layer_animation_controller_
->RemoveEventObserver(animation_observer
);
1584 ScrollbarLayerInterface
* Layer::ToScrollbarLayer() {
1588 RenderingStatsInstrumentation
* Layer::rendering_stats_instrumentation() const {
1589 return layer_tree_host_
->rendering_stats_instrumentation();
1592 void Layer::RemoveFromScrollTree() {
1593 if (scroll_children_
.get()) {
1594 std::set
<Layer
*> copy
= *scroll_children_
;
1595 for (std::set
<Layer
*>::iterator it
= copy
.begin(); it
!= copy
.end(); ++it
)
1596 (*it
)->SetScrollParent(nullptr);
1599 DCHECK(!scroll_children_
);
1600 SetScrollParent(nullptr);
1603 void Layer::RemoveFromClipTree() {
1604 if (clip_children_
.get()) {
1605 std::set
<Layer
*> copy
= *clip_children_
;
1606 for (std::set
<Layer
*>::iterator it
= copy
.begin(); it
!= copy
.end(); ++it
)
1607 (*it
)->SetClipParent(nullptr);
1610 DCHECK(!clip_children_
);
1611 SetClipParent(nullptr);
1614 void Layer::AddDrawableDescendants(int num
) {
1615 DCHECK_GE(num_descendants_that_draw_content_
, 0);
1616 DCHECK_GE(num_descendants_that_draw_content_
+ num
, 0);
1619 num_descendants_that_draw_content_
+= num
;
1622 parent()->AddDrawableDescendants(num
);
1625 void Layer::RunMicroBenchmark(MicroBenchmark
* benchmark
) {
1626 benchmark
->RunOnLayer(this);
1629 bool Layer::HasDelegatedContent() const {
1633 void Layer::SetFrameTimingRequests(
1634 const std::vector
<FrameTimingRequest
>& requests
) {
1635 // TODO(vmpstr): Early out if there are no changes earlier in the call stack.
1636 if (requests
== frame_timing_requests_
)
1638 frame_timing_requests_
= requests
;
1639 frame_timing_requests_dirty_
= true;
1643 void Layer::DidBeginTracing() {
1644 // We'll be dumping layer trees as part of trace, so make sure
1645 // PushPropertiesTo() propagates layer debug info to the impl
1646 // side -- otherwise this won't happen for the the layers that
1647 // remain unchanged since tracing started.
1648 SetNeedsPushProperties();
1651 void Layer::set_visited(bool visited
) {
1653 visited
? layer_tree_host()->meta_information_sequence_number() : 0;
1656 bool Layer::visited() {
1657 return visited_tracker_
==
1658 layer_tree_host()->meta_information_sequence_number();
1661 void Layer::set_layer_or_descendant_is_drawn(
1662 bool layer_or_descendant_is_drawn
) {
1663 layer_or_descendant_is_drawn_tracker_
=
1664 layer_or_descendant_is_drawn
1665 ? layer_tree_host()->meta_information_sequence_number()
1669 bool Layer::layer_or_descendant_is_drawn() {
1670 return layer_or_descendant_is_drawn_tracker_
==
1671 layer_tree_host()->meta_information_sequence_number();
1674 void Layer::set_sorted_for_recursion(bool sorted_for_recursion
) {
1675 sorted_for_recursion_tracker_
=
1676 sorted_for_recursion
1677 ? layer_tree_host()->meta_information_sequence_number()
1681 bool Layer::sorted_for_recursion() {
1682 return sorted_for_recursion_tracker_
==
1683 layer_tree_host()->meta_information_sequence_number();