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 effect_tree_index_(-1),
56 property_tree_sequence_number_(-1),
57 num_layer_or_descendants_with_copy_request_(0),
58 num_children_with_scroll_parent_(0),
59 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 force_render_surface_(false),
77 transform_is_invertible_(true),
78 has_render_surface_(false),
79 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE
),
82 blend_mode_(SkXfermode::kSrcOver_Mode
),
83 draw_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),
91 frame_timing_requests_dirty_(false) {
92 if (!settings
.use_compositor_animation_timelines
) {
93 layer_animation_controller_
= LayerAnimationController::Create(layer_id_
);
94 layer_animation_controller_
->AddValueObserver(this);
95 layer_animation_controller_
->set_value_provider(this);
100 // Our parent should be holding a reference to us so there should be no
101 // way for us to be destroyed while we still have a parent.
103 // Similarly we shouldn't have a layer tree host since it also keeps a
105 DCHECK(!layer_tree_host());
107 if (layer_animation_controller_
) {
108 layer_animation_controller_
->RemoveValueObserver(this);
109 layer_animation_controller_
->remove_value_provider(this);
112 RemoveFromScrollTree();
113 RemoveFromClipTree();
115 // Remove the parent reference from all children and dependents.
117 if (mask_layer_
.get()) {
118 DCHECK_EQ(this, mask_layer_
->parent());
119 mask_layer_
->RemoveFromParent();
121 if (replica_layer_
.get()) {
122 DCHECK_EQ(this, replica_layer_
->parent());
123 replica_layer_
->RemoveFromParent();
127 void Layer::SetLayerTreeHost(LayerTreeHost
* host
) {
128 if (layer_tree_host_
== host
)
131 if (layer_tree_host_
) {
132 layer_tree_host_
->property_trees()->needs_rebuild
= true;
133 layer_tree_host_
->UnregisterLayer(this);
136 host
->property_trees()->needs_rebuild
= true;
137 host
->RegisterLayer(this);
140 InvalidatePropertyTreesIndices();
142 layer_tree_host_
= host
;
144 // When changing hosts, the layer needs to commit its properties to the impl
145 // side for the new host.
146 SetNeedsPushProperties();
148 for (size_t i
= 0; i
< children_
.size(); ++i
)
149 children_
[i
]->SetLayerTreeHost(host
);
151 if (mask_layer_
.get())
152 mask_layer_
->SetLayerTreeHost(host
);
153 if (replica_layer_
.get())
154 replica_layer_
->SetLayerTreeHost(host
);
157 RegisterForAnimations(host
->animation_registrar());
159 bool has_any_animation
= false;
160 if (layer_animation_controller_
)
161 has_any_animation
= layer_animation_controller_
->has_any_animation();
162 else if (layer_tree_host_
)
163 has_any_animation
= layer_tree_host_
->HasAnyAnimation(this);
165 if (host
&& has_any_animation
)
166 host
->SetNeedsCommit();
169 void Layer::SetNeedsUpdate() {
170 if (layer_tree_host_
&& !ignore_set_needs_commit_
)
171 layer_tree_host_
->SetNeedsUpdateLayers();
174 void Layer::SetNeedsCommit() {
175 if (!layer_tree_host_
)
178 SetNeedsPushProperties();
179 layer_tree_host_
->property_trees()->needs_rebuild
= true;
181 if (ignore_set_needs_commit_
)
184 layer_tree_host_
->SetNeedsCommit();
187 void Layer::SetNeedsCommitNoRebuild() {
188 if (!layer_tree_host_
)
191 SetNeedsPushProperties();
193 if (ignore_set_needs_commit_
)
196 layer_tree_host_
->SetNeedsCommit();
199 void Layer::SetNeedsFullTreeSync() {
200 if (!layer_tree_host_
)
203 layer_tree_host_
->SetNeedsFullTreeSync();
206 void Layer::SetNextCommitWaitsForActivation() {
207 if (!layer_tree_host_
)
210 layer_tree_host_
->SetNextCommitWaitsForActivation();
213 void Layer::SetNeedsPushProperties() {
214 if (needs_push_properties_
)
216 if (!parent_should_know_need_push_properties() && parent_
)
217 parent_
->AddDependentNeedsPushProperties();
218 needs_push_properties_
= true;
221 void Layer::AddDependentNeedsPushProperties() {
222 DCHECK_GE(num_dependents_need_push_properties_
, 0);
224 if (!parent_should_know_need_push_properties() && parent_
)
225 parent_
->AddDependentNeedsPushProperties();
227 num_dependents_need_push_properties_
++;
230 void Layer::RemoveDependentNeedsPushProperties() {
231 num_dependents_need_push_properties_
--;
232 DCHECK_GE(num_dependents_need_push_properties_
, 0);
234 if (!parent_should_know_need_push_properties() && parent_
)
235 parent_
->RemoveDependentNeedsPushProperties();
238 bool Layer::IsPropertyChangeAllowed() const {
239 if (!layer_tree_host_
)
242 if (!layer_tree_host_
->settings().strict_layer_property_change_checking
)
245 return !layer_tree_host_
->in_paint_layer_contents();
248 skia::RefPtr
<SkPicture
> Layer::GetPicture() const {
249 return skia::RefPtr
<SkPicture
>();
252 void Layer::SetParent(Layer
* layer
) {
253 DCHECK(!layer
|| !layer
->HasAncestor(this));
255 if (parent_should_know_need_push_properties()) {
257 parent_
->RemoveDependentNeedsPushProperties();
259 layer
->AddDependentNeedsPushProperties();
263 SetLayerTreeHost(parent_
? parent_
->layer_tree_host() : nullptr);
265 if (!layer_tree_host_
)
268 layer_tree_host_
->property_trees()->needs_rebuild
= true;
271 void Layer::AddChild(scoped_refptr
<Layer
> child
) {
272 InsertChild(child
, children_
.size());
275 void Layer::InsertChild(scoped_refptr
<Layer
> child
, size_t index
) {
276 DCHECK(IsPropertyChangeAllowed());
277 child
->RemoveFromParent();
278 AddDrawableDescendants(child
->NumDescendantsThatDrawContent() +
279 (child
->DrawsContent() ? 1 : 0));
280 child
->SetParent(this);
281 child
->stacking_order_changed_
= true;
283 index
= std::min(index
, children_
.size());
284 children_
.insert(children_
.begin() + index
, child
);
285 SetNeedsFullTreeSync();
288 void Layer::RemoveFromParent() {
289 DCHECK(IsPropertyChangeAllowed());
291 parent_
->RemoveChildOrDependent(this);
294 void Layer::RemoveChildOrDependent(Layer
* child
) {
295 if (mask_layer_
.get() == child
) {
296 mask_layer_
->SetParent(nullptr);
297 mask_layer_
= nullptr;
298 SetNeedsFullTreeSync();
301 if (replica_layer_
.get() == child
) {
302 replica_layer_
->SetParent(nullptr);
303 replica_layer_
= nullptr;
304 SetNeedsFullTreeSync();
308 for (LayerList::iterator iter
= children_
.begin();
309 iter
!= children_
.end();
311 if (iter
->get() != child
)
314 child
->SetParent(nullptr);
315 AddDrawableDescendants(-child
->NumDescendantsThatDrawContent() -
316 (child
->DrawsContent() ? 1 : 0));
317 children_
.erase(iter
);
318 SetNeedsFullTreeSync();
323 void Layer::ReplaceChild(Layer
* reference
, scoped_refptr
<Layer
> new_layer
) {
325 DCHECK_EQ(reference
->parent(), this);
326 DCHECK(IsPropertyChangeAllowed());
328 if (reference
== new_layer
.get())
331 // Find the index of |reference| in |children_|.
333 std::find_if(children_
.begin(), children_
.end(),
334 [reference
](const scoped_refptr
<Layer
>& layer
) {
335 return layer
.get() == reference
;
337 DCHECK(reference_it
!= children_
.end());
338 size_t reference_index
= reference_it
- children_
.begin();
339 reference
->RemoveFromParent();
341 if (new_layer
.get()) {
342 new_layer
->RemoveFromParent();
343 InsertChild(new_layer
, reference_index
);
347 void Layer::SetBounds(const gfx::Size
& size
) {
348 DCHECK(IsPropertyChangeAllowed());
349 if (bounds() == size
)
353 if (!layer_tree_host_
)
356 if (ClipNode
* clip_node
= layer_tree_host_
->property_trees()->clip_tree
.Node(
357 clip_tree_index())) {
358 if (clip_node
->owner_id
== id()) {
359 clip_node
->data
.clip
.set_size(size
);
360 layer_tree_host_
->property_trees()->clip_tree
.set_needs_update(true);
364 SetNeedsCommitNoRebuild();
367 Layer
* Layer::RootLayer() {
369 while (layer
->parent())
370 layer
= layer
->parent();
374 void Layer::RemoveAllChildren() {
375 DCHECK(IsPropertyChangeAllowed());
376 while (children_
.size()) {
377 Layer
* layer
= children_
[0].get();
378 DCHECK_EQ(this, layer
->parent());
379 layer
->RemoveFromParent();
383 void Layer::SetChildren(const LayerList
& children
) {
384 DCHECK(IsPropertyChangeAllowed());
385 if (children
== children_
)
389 for (size_t i
= 0; i
< children
.size(); ++i
)
390 AddChild(children
[i
]);
393 bool Layer::HasAncestor(const Layer
* ancestor
) const {
394 for (const Layer
* layer
= parent(); layer
; layer
= layer
->parent()) {
395 if (layer
== ancestor
)
401 void Layer::RequestCopyOfOutput(
402 scoped_ptr
<CopyOutputRequest
> request
) {
403 DCHECK(IsPropertyChangeAllowed());
404 bool had_no_copy_requests
= copy_requests_
.empty();
405 if (void* source
= request
->source()) {
406 auto it
= std::find_if(
407 copy_requests_
.begin(), copy_requests_
.end(),
408 [source
](const CopyOutputRequest
* x
) { return x
->source() == source
; });
409 if (it
!= copy_requests_
.end())
410 copy_requests_
.erase(it
);
412 if (request
->IsEmpty())
414 copy_requests_
.push_back(request
.Pass());
415 if (had_no_copy_requests
) {
416 bool copy_request_added
= true;
417 UpdateNumCopyRequestsForSubtree(copy_request_added
);
422 void Layer::UpdateNumCopyRequestsForSubtree(bool add
) {
423 int change
= add
? 1 : -1;
424 for (Layer
* layer
= this; layer
; layer
= layer
->parent()) {
425 layer
->num_layer_or_descendants_with_copy_request_
+= change
;
426 layer
->draw_properties().layer_or_descendant_has_copy_request
=
427 (layer
->num_layer_or_descendants_with_copy_request_
!= 0);
428 DCHECK_GE(layer
->num_layer_or_descendants_with_copy_request_
, 0);
432 void Layer::SetBackgroundColor(SkColor background_color
) {
433 DCHECK(IsPropertyChangeAllowed());
434 if (background_color_
== background_color
)
436 background_color_
= background_color
;
440 SkColor
Layer::SafeOpaqueBackgroundColor() const {
441 SkColor color
= background_color();
442 if (SkColorGetA(color
) == 255 && !contents_opaque()) {
443 color
= SK_ColorTRANSPARENT
;
444 } else if (SkColorGetA(color
) != 255 && contents_opaque()) {
445 for (const Layer
* layer
= parent(); layer
;
446 layer
= layer
->parent()) {
447 color
= layer
->background_color();
448 if (SkColorGetA(color
) == 255)
451 if (SkColorGetA(color
) != 255)
452 color
= layer_tree_host_
->background_color();
453 if (SkColorGetA(color
) != 255)
454 color
= SkColorSetA(color
, 255);
459 void Layer::SetMasksToBounds(bool masks_to_bounds
) {
460 DCHECK(IsPropertyChangeAllowed());
461 if (masks_to_bounds_
== masks_to_bounds
)
463 masks_to_bounds_
= masks_to_bounds
;
467 void Layer::SetMaskLayer(Layer
* mask_layer
) {
468 DCHECK(IsPropertyChangeAllowed());
469 if (mask_layer_
.get() == mask_layer
)
471 if (mask_layer_
.get()) {
472 DCHECK_EQ(this, mask_layer_
->parent());
473 mask_layer_
->RemoveFromParent();
475 mask_layer_
= mask_layer
;
476 if (mask_layer_
.get()) {
477 DCHECK(!mask_layer_
->parent());
478 mask_layer_
->RemoveFromParent();
479 mask_layer_
->SetParent(this);
480 mask_layer_
->SetIsMask(true);
482 SetNeedsFullTreeSync();
485 void Layer::SetReplicaLayer(Layer
* layer
) {
486 DCHECK(IsPropertyChangeAllowed());
487 if (replica_layer_
.get() == layer
)
489 if (replica_layer_
.get()) {
490 DCHECK_EQ(this, replica_layer_
->parent());
491 replica_layer_
->RemoveFromParent();
493 replica_layer_
= layer
;
494 if (replica_layer_
.get()) {
495 DCHECK(!replica_layer_
->parent());
496 replica_layer_
->RemoveFromParent();
497 replica_layer_
->SetParent(this);
499 SetNeedsFullTreeSync();
502 void Layer::SetFilters(const FilterOperations
& filters
) {
503 DCHECK(IsPropertyChangeAllowed());
504 if (filters_
== filters
)
510 bool Layer::FilterIsAnimating() const {
511 DCHECK(layer_tree_host_
);
512 return layer_animation_controller_
513 ? layer_animation_controller_
->IsCurrentlyAnimatingProperty(
515 LayerAnimationController::ObserverType::ACTIVE
)
516 : layer_tree_host_
->IsAnimatingFilterProperty(this);
519 bool Layer::HasPotentiallyRunningFilterAnimation() const {
520 if (layer_animation_controller_
) {
521 return layer_animation_controller_
->IsPotentiallyAnimatingProperty(
522 Animation::FILTER
, LayerAnimationController::ObserverType::ACTIVE
);
524 return layer_tree_host_
->HasPotentiallyRunningFilterAnimation(this);
527 void Layer::SetBackgroundFilters(const FilterOperations
& filters
) {
528 DCHECK(IsPropertyChangeAllowed());
529 if (background_filters_
== filters
)
531 background_filters_
= filters
;
535 void Layer::SetOpacity(float opacity
) {
536 DCHECK(IsPropertyChangeAllowed());
537 if (opacity_
== opacity
)
543 bool Layer::OpacityIsAnimating() const {
544 DCHECK(layer_tree_host_
);
545 return layer_animation_controller_
546 ? layer_animation_controller_
->IsCurrentlyAnimatingProperty(
548 LayerAnimationController::ObserverType::ACTIVE
)
549 : layer_tree_host_
->IsAnimatingOpacityProperty(this);
552 bool Layer::HasPotentiallyRunningOpacityAnimation() const {
553 if (layer_animation_controller_
) {
554 return layer_animation_controller_
->IsPotentiallyAnimatingProperty(
555 Animation::OPACITY
, LayerAnimationController::ObserverType::ACTIVE
);
557 return layer_tree_host_
->HasPotentiallyRunningOpacityAnimation(this);
560 bool Layer::OpacityCanAnimateOnImplThread() const {
564 void Layer::SetBlendMode(SkXfermode::Mode blend_mode
) {
565 DCHECK(IsPropertyChangeAllowed());
566 if (blend_mode_
== blend_mode
)
569 // Allowing only blend modes that are defined in the CSS Compositing standard:
570 // http://dev.w3.org/fxtf/compositing-1/#blending
571 switch (blend_mode
) {
572 case SkXfermode::kSrcOver_Mode
:
573 case SkXfermode::kScreen_Mode
:
574 case SkXfermode::kOverlay_Mode
:
575 case SkXfermode::kDarken_Mode
:
576 case SkXfermode::kLighten_Mode
:
577 case SkXfermode::kColorDodge_Mode
:
578 case SkXfermode::kColorBurn_Mode
:
579 case SkXfermode::kHardLight_Mode
:
580 case SkXfermode::kSoftLight_Mode
:
581 case SkXfermode::kDifference_Mode
:
582 case SkXfermode::kExclusion_Mode
:
583 case SkXfermode::kMultiply_Mode
:
584 case SkXfermode::kHue_Mode
:
585 case SkXfermode::kSaturation_Mode
:
586 case SkXfermode::kColor_Mode
:
587 case SkXfermode::kLuminosity_Mode
:
588 // supported blend modes
590 case SkXfermode::kClear_Mode
:
591 case SkXfermode::kSrc_Mode
:
592 case SkXfermode::kDst_Mode
:
593 case SkXfermode::kDstOver_Mode
:
594 case SkXfermode::kSrcIn_Mode
:
595 case SkXfermode::kDstIn_Mode
:
596 case SkXfermode::kSrcOut_Mode
:
597 case SkXfermode::kDstOut_Mode
:
598 case SkXfermode::kSrcATop_Mode
:
599 case SkXfermode::kDstATop_Mode
:
600 case SkXfermode::kXor_Mode
:
601 case SkXfermode::kPlus_Mode
:
602 case SkXfermode::kModulate_Mode
:
603 // Porter Duff Compositing Operators are not yet supported
604 // http://dev.w3.org/fxtf/compositing-1/#porterduffcompositingoperators
609 blend_mode_
= blend_mode
;
613 void Layer::SetIsRootForIsolatedGroup(bool root
) {
614 DCHECK(IsPropertyChangeAllowed());
615 if (is_root_for_isolated_group_
== root
)
617 is_root_for_isolated_group_
= root
;
621 void Layer::SetContentsOpaque(bool opaque
) {
622 DCHECK(IsPropertyChangeAllowed());
623 if (contents_opaque_
== opaque
)
625 contents_opaque_
= opaque
;
629 void Layer::SetPosition(const gfx::PointF
& position
) {
630 DCHECK(IsPropertyChangeAllowed());
631 if (position_
== position
)
633 position_
= position
;
635 if (!layer_tree_host_
)
638 if (TransformNode
* transform_node
=
639 layer_tree_host_
->property_trees()->transform_tree
.Node(
640 transform_tree_index())) {
641 if (transform_node
->owner_id
== id()) {
642 transform_node
->data
.update_post_local_transform(position
,
644 transform_node
->data
.needs_local_transform_update
= true;
645 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
646 SetNeedsCommitNoRebuild();
654 bool Layer::IsContainerForFixedPositionLayers() const {
655 if (!transform_
.IsIdentityOrTranslation())
657 if (parent_
&& !parent_
->transform_
.IsIdentityOrTranslation())
659 return is_container_for_fixed_position_layers_
;
662 bool Are2dAxisAligned(const gfx::Transform
& a
,
663 const gfx::Transform
& b
,
664 bool* is_invertible
) {
665 if (a
.IsScaleOrTranslation() && b
.IsScaleOrTranslation()) {
666 *is_invertible
= b
.IsInvertible();
670 gfx::Transform
inverse(gfx::Transform::kSkipInitialization
);
671 *is_invertible
= b
.GetInverse(&inverse
);
674 return inverse
.Preserves2dAxisAlignment();
677 void Layer::SetTransform(const gfx::Transform
& transform
) {
678 DCHECK(IsPropertyChangeAllowed());
679 if (transform_
== transform
)
682 if (layer_tree_host_
) {
683 if (TransformNode
* transform_node
=
684 layer_tree_host_
->property_trees()->transform_tree
.Node(
685 transform_tree_index())) {
686 if (transform_node
->owner_id
== id()) {
687 // We need to trigger a rebuild if we could have affected 2d axis
688 // alignment. We'll check to see if transform and transform_ are axis
689 // align with respect to one another.
690 bool invertible
= false;
691 bool preserves_2d_axis_alignment
=
692 Are2dAxisAligned(transform_
, transform
, &invertible
);
693 transform_node
->data
.local
= transform
;
694 transform_node
->data
.needs_local_transform_update
= true;
695 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(
697 if (preserves_2d_axis_alignment
)
698 SetNeedsCommitNoRebuild();
701 transform_
= transform
;
702 transform_is_invertible_
= invertible
;
708 transform_
= transform
;
709 transform_is_invertible_
= transform
.IsInvertible();
714 void Layer::SetTransformOrigin(const gfx::Point3F
& transform_origin
) {
715 DCHECK(IsPropertyChangeAllowed());
716 if (transform_origin_
== transform_origin
)
718 transform_origin_
= transform_origin
;
720 if (!layer_tree_host_
)
723 if (TransformNode
* transform_node
=
724 layer_tree_host_
->property_trees()->transform_tree
.Node(
725 transform_tree_index())) {
726 if (transform_node
->owner_id
== id()) {
727 transform_node
->data
.update_pre_local_transform(transform_origin
);
728 transform_node
->data
.update_post_local_transform(position(),
730 transform_node
->data
.needs_local_transform_update
= true;
731 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
732 SetNeedsCommitNoRebuild();
740 bool Layer::AnimationsPreserveAxisAlignment() const {
741 DCHECK(layer_tree_host_
);
742 return layer_animation_controller_
743 ? layer_animation_controller_
->AnimationsPreserveAxisAlignment()
744 : layer_tree_host_
->AnimationsPreserveAxisAlignment(this);
747 bool Layer::TransformIsAnimating() const {
748 DCHECK(layer_tree_host_
);
749 return layer_animation_controller_
750 ? layer_animation_controller_
->IsCurrentlyAnimatingProperty(
751 Animation::TRANSFORM
,
752 LayerAnimationController::ObserverType::ACTIVE
)
753 : layer_tree_host_
->IsAnimatingTransformProperty(this);
756 bool Layer::HasPotentiallyRunningTransformAnimation() const {
757 if (layer_animation_controller_
) {
758 return layer_animation_controller_
->IsPotentiallyAnimatingProperty(
759 Animation::TRANSFORM
, LayerAnimationController::ObserverType::ACTIVE
);
761 return layer_tree_host_
->HasPotentiallyRunningTransformAnimation(this);
764 bool Layer::HasOnlyTranslationTransforms() const {
765 if (layer_animation_controller_
) {
766 return layer_animation_controller_
->HasOnlyTranslationTransforms(
767 LayerAnimationController::ObserverType::ACTIVE
);
769 return layer_tree_host_
->HasOnlyTranslationTransforms(this);
772 bool Layer::MaximumTargetScale(float* max_scale
) const {
773 if (layer_animation_controller_
) {
774 return layer_animation_controller_
->MaximumTargetScale(
775 LayerAnimationController::ObserverType::ACTIVE
, max_scale
);
777 return layer_tree_host_
->MaximumTargetScale(this, max_scale
);
780 bool Layer::AnimationStartScale(float* start_scale
) const {
781 if (layer_animation_controller_
) {
782 return layer_animation_controller_
->AnimationStartScale(
783 LayerAnimationController::ObserverType::ACTIVE
, start_scale
);
785 return layer_tree_host_
->AnimationStartScale(this, start_scale
);
788 bool Layer::HasAnyAnimationTargetingProperty(
789 Animation::TargetProperty property
) const {
790 if (layer_animation_controller_
)
791 return !!layer_animation_controller_
->GetAnimation(property
);
793 return layer_tree_host_
->HasAnyAnimationTargetingProperty(this, property
);
796 bool Layer::ScrollOffsetAnimationWasInterrupted() const {
797 DCHECK(layer_tree_host_
);
798 return layer_animation_controller_
799 ? layer_animation_controller_
800 ->scroll_offset_animation_was_interrupted()
801 : layer_tree_host_
->ScrollOffsetAnimationWasInterrupted(this);
804 void Layer::SetScrollParent(Layer
* parent
) {
805 DCHECK(IsPropertyChangeAllowed());
806 if (scroll_parent_
== parent
)
810 scroll_parent_
->RemoveScrollChild(this);
812 scroll_parent_
= parent
;
815 scroll_parent_
->AddScrollChild(this);
820 void Layer::AddScrollChild(Layer
* child
) {
821 if (!scroll_children_
)
822 scroll_children_
.reset(new std::set
<Layer
*>);
823 scroll_children_
->insert(child
);
824 if (layer_tree_host_
&& !layer_tree_host_
->needs_meta_info_recomputation()) {
825 num_children_with_scroll_parent_
++;
826 draw_properties().has_child_with_a_scroll_parent
= true;
831 void Layer::RemoveScrollChild(Layer
* child
) {
832 scroll_children_
->erase(child
);
833 if (scroll_children_
->empty())
834 scroll_children_
= nullptr;
835 if (layer_tree_host_
&& !layer_tree_host_
->needs_meta_info_recomputation()) {
836 num_children_with_scroll_parent_
--;
837 DCHECK_GE(num_children_with_scroll_parent_
, 0);
838 draw_properties().has_child_with_a_scroll_parent
=
839 (num_children_with_scroll_parent_
!= 0);
844 void Layer::SetClipParent(Layer
* ancestor
) {
845 DCHECK(IsPropertyChangeAllowed());
846 if (clip_parent_
== ancestor
)
850 clip_parent_
->RemoveClipChild(this);
852 clip_parent_
= ancestor
;
855 clip_parent_
->AddClipChild(this);
858 if (layer_tree_host_
)
859 layer_tree_host_
->SetNeedsMetaInfoRecomputation(true);
862 void Layer::AddClipChild(Layer
* child
) {
864 clip_children_
.reset(new std::set
<Layer
*>);
865 clip_children_
->insert(child
);
869 void Layer::RemoveClipChild(Layer
* child
) {
870 clip_children_
->erase(child
);
871 if (clip_children_
->empty())
872 clip_children_
= nullptr;
876 void Layer::SetScrollOffset(const gfx::ScrollOffset
& scroll_offset
) {
877 DCHECK(IsPropertyChangeAllowed());
879 if (scroll_offset_
== scroll_offset
)
881 scroll_offset_
= scroll_offset
;
883 if (!layer_tree_host_
)
886 if (TransformNode
* transform_node
=
887 layer_tree_host_
->property_trees()->transform_tree
.Node(
888 transform_tree_index())) {
889 if (transform_node
->owner_id
== id()) {
890 transform_node
->data
.scroll_offset
= CurrentScrollOffset();
891 transform_node
->data
.needs_local_transform_update
= true;
892 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
893 SetNeedsCommitNoRebuild();
901 void Layer::SetScrollCompensationAdjustment(
902 const gfx::Vector2dF
& scroll_compensation_adjustment
) {
903 if (scroll_compensation_adjustment_
== scroll_compensation_adjustment
)
905 scroll_compensation_adjustment_
= scroll_compensation_adjustment
;
909 gfx::Vector2dF
Layer::ScrollCompensationAdjustment() const {
910 return scroll_compensation_adjustment_
;
913 void Layer::SetScrollOffsetFromImplSide(
914 const gfx::ScrollOffset
& scroll_offset
) {
915 DCHECK(IsPropertyChangeAllowed());
916 // This function only gets called during a BeginMainFrame, so there
917 // is no need to call SetNeedsUpdate here.
918 DCHECK(layer_tree_host_
&& layer_tree_host_
->CommitRequested());
919 if (scroll_offset_
== scroll_offset
)
921 scroll_offset_
= scroll_offset
;
922 SetNeedsPushProperties();
924 bool needs_rebuild
= true;
925 if (TransformNode
* transform_node
=
926 layer_tree_host_
->property_trees()->transform_tree
.Node(
927 transform_tree_index())) {
928 if (transform_node
->owner_id
== id()) {
929 transform_node
->data
.scroll_offset
= CurrentScrollOffset();
930 transform_node
->data
.needs_local_transform_update
= true;
931 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
932 needs_rebuild
= false;
937 layer_tree_host_
->property_trees()->needs_rebuild
= true;
939 if (!did_scroll_callback_
.is_null())
940 did_scroll_callback_
.Run();
941 // The callback could potentially change the layer structure:
942 // "this" may have been destroyed during the process.
945 void Layer::SetScrollClipLayerId(int clip_layer_id
) {
946 DCHECK(IsPropertyChangeAllowed());
947 if (scroll_clip_layer_id_
== clip_layer_id
)
949 scroll_clip_layer_id_
= clip_layer_id
;
953 void Layer::SetUserScrollable(bool horizontal
, bool vertical
) {
954 DCHECK(IsPropertyChangeAllowed());
955 if (user_scrollable_horizontal_
== horizontal
&&
956 user_scrollable_vertical_
== vertical
)
958 user_scrollable_horizontal_
= horizontal
;
959 user_scrollable_vertical_
= vertical
;
963 void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
964 DCHECK(IsPropertyChangeAllowed());
965 if (should_scroll_on_main_thread_
== should_scroll_on_main_thread
)
967 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
971 void Layer::SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
972 DCHECK(IsPropertyChangeAllowed());
973 if (have_wheel_event_handlers_
== have_wheel_event_handlers
)
976 have_wheel_event_handlers_
= have_wheel_event_handlers
;
980 void Layer::SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
981 DCHECK(IsPropertyChangeAllowed());
982 if (have_scroll_event_handlers_
== have_scroll_event_handlers
)
984 have_scroll_event_handlers_
= have_scroll_event_handlers
;
988 void Layer::SetNonFastScrollableRegion(const Region
& region
) {
989 DCHECK(IsPropertyChangeAllowed());
990 if (non_fast_scrollable_region_
== region
)
992 non_fast_scrollable_region_
= region
;
996 void Layer::SetTouchEventHandlerRegion(const Region
& region
) {
997 DCHECK(IsPropertyChangeAllowed());
998 if (touch_event_handler_region_
== region
)
1001 touch_event_handler_region_
= region
;
1005 void Layer::SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
1006 DCHECK(IsPropertyChangeAllowed());
1007 if (scroll_blocks_on_
== scroll_blocks_on
)
1009 scroll_blocks_on_
= scroll_blocks_on
;
1013 void Layer::SetForceRenderSurface(bool force
) {
1014 DCHECK(IsPropertyChangeAllowed());
1015 if (force_render_surface_
== force
)
1017 force_render_surface_
= force
;
1021 void Layer::SetDoubleSided(bool double_sided
) {
1022 DCHECK(IsPropertyChangeAllowed());
1023 if (double_sided_
== double_sided
)
1025 double_sided_
= double_sided
;
1029 void Layer::Set3dSortingContextId(int id
) {
1030 DCHECK(IsPropertyChangeAllowed());
1031 if (id
== sorting_context_id_
)
1033 sorting_context_id_
= id
;
1037 void Layer::SetTransformTreeIndex(int index
) {
1038 DCHECK(IsPropertyChangeAllowed());
1039 if (transform_tree_index_
== index
)
1041 transform_tree_index_
= index
;
1042 SetNeedsPushProperties();
1045 int Layer::transform_tree_index() const {
1046 if (!layer_tree_host_
||
1047 layer_tree_host_
->property_trees()->sequence_number
!=
1048 property_tree_sequence_number_
) {
1051 return transform_tree_index_
;
1054 void Layer::SetClipTreeIndex(int index
) {
1055 DCHECK(IsPropertyChangeAllowed());
1056 if (clip_tree_index_
== index
)
1058 clip_tree_index_
= index
;
1059 SetNeedsPushProperties();
1062 int Layer::clip_tree_index() const {
1063 if (!layer_tree_host_
||
1064 layer_tree_host_
->property_trees()->sequence_number
!=
1065 property_tree_sequence_number_
) {
1068 return clip_tree_index_
;
1071 void Layer::SetEffectTreeIndex(int index
) {
1072 DCHECK(IsPropertyChangeAllowed());
1073 if (effect_tree_index_
== index
)
1075 effect_tree_index_
= index
;
1076 SetNeedsPushProperties();
1079 int Layer::effect_tree_index() const {
1080 if (!layer_tree_host_
||
1081 layer_tree_host_
->property_trees()->sequence_number
!=
1082 property_tree_sequence_number_
) {
1085 return effect_tree_index_
;
1088 void Layer::InvalidatePropertyTreesIndices() {
1089 int invalid_property_tree_index
= -1;
1090 SetTransformTreeIndex(invalid_property_tree_index
);
1091 SetClipTreeIndex(invalid_property_tree_index
);
1092 SetEffectTreeIndex(invalid_property_tree_index
);
1095 void Layer::SetShouldFlattenTransform(bool should_flatten
) {
1096 DCHECK(IsPropertyChangeAllowed());
1097 if (should_flatten_transform_
== should_flatten
)
1099 should_flatten_transform_
= should_flatten
;
1103 void Layer::SetIsDrawable(bool is_drawable
) {
1104 DCHECK(IsPropertyChangeAllowed());
1105 if (is_drawable_
== is_drawable
)
1108 is_drawable_
= is_drawable
;
1109 UpdateDrawsContent(HasDrawableContent());
1112 void Layer::SetHideLayerAndSubtree(bool hide
) {
1113 DCHECK(IsPropertyChangeAllowed());
1114 if (hide_layer_and_subtree_
== hide
)
1117 hide_layer_and_subtree_
= hide
;
1121 void Layer::SetNeedsDisplayRect(const gfx::Rect
& dirty_rect
) {
1122 if (dirty_rect
.IsEmpty())
1125 SetNeedsPushProperties();
1126 update_rect_
.Union(dirty_rect
);
1132 bool Layer::DescendantIsFixedToContainerLayer() const {
1133 for (size_t i
= 0; i
< children_
.size(); ++i
) {
1134 if (children_
[i
]->position_constraint_
.is_fixed_position() ||
1135 children_
[i
]->DescendantIsFixedToContainerLayer())
1141 void Layer::SetIsContainerForFixedPositionLayers(bool container
) {
1142 if (is_container_for_fixed_position_layers_
== container
)
1144 is_container_for_fixed_position_layers_
= container
;
1146 if (layer_tree_host_
&& layer_tree_host_
->CommitRequested())
1149 // Only request a commit if we have a fixed positioned descendant.
1150 if (DescendantIsFixedToContainerLayer())
1154 void Layer::SetPositionConstraint(const LayerPositionConstraint
& constraint
) {
1155 DCHECK(IsPropertyChangeAllowed());
1156 if (position_constraint_
== constraint
)
1158 position_constraint_
= constraint
;
1162 static void RunCopyCallbackOnMainThread(scoped_ptr
<CopyOutputRequest
> request
,
1163 scoped_ptr
<CopyOutputResult
> result
) {
1164 request
->SendResult(result
.Pass());
1167 static void PostCopyCallbackToMainThread(
1168 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
,
1169 scoped_ptr
<CopyOutputRequest
> request
,
1170 scoped_ptr
<CopyOutputResult
> result
) {
1171 main_thread_task_runner
->PostTask(FROM_HERE
,
1172 base::Bind(&RunCopyCallbackOnMainThread
,
1173 base::Passed(&request
),
1174 base::Passed(&result
)));
1177 void Layer::PushPropertiesTo(LayerImpl
* layer
) {
1178 DCHECK(layer_tree_host_
);
1180 // If we did not SavePaintProperties() for the layer this frame, then push the
1181 // real property values, not the paint property values.
1182 bool use_paint_properties
= paint_properties_
.source_frame_number
==
1183 layer_tree_host_
->source_frame_number();
1185 layer
->SetTransformOrigin(transform_origin_
);
1186 layer
->SetBackgroundColor(background_color_
);
1187 layer
->SetBounds(use_paint_properties
? paint_properties_
.bounds
1190 if (frame_viewer_instrumentation::IsTracingLayerTreeSnapshots())
1191 layer
->SetDebugInfo(TakeDebugInfo());
1193 layer
->SetTransformTreeIndex(transform_tree_index());
1194 layer
->SetEffectTreeIndex(effect_tree_index());
1195 layer
->SetClipTreeIndex(clip_tree_index());
1196 layer
->set_offset_to_transform_parent(offset_to_transform_parent_
);
1197 layer
->SetDoubleSided(double_sided_
);
1198 layer
->SetDrawsContent(DrawsContent());
1199 layer
->SetHideLayerAndSubtree(hide_layer_and_subtree_
);
1200 layer
->SetHasRenderSurface(has_render_surface_
);
1201 if (!layer
->FilterIsAnimatingOnImplOnly() && !FilterIsAnimating())
1202 layer
->SetFilters(filters_
);
1203 DCHECK(!(FilterIsAnimating() && layer
->FilterIsAnimatingOnImplOnly()));
1204 layer
->SetBackgroundFilters(background_filters());
1205 layer
->SetMasksToBounds(masks_to_bounds_
);
1206 layer
->SetShouldScrollOnMainThread(should_scroll_on_main_thread_
);
1207 layer
->SetHaveWheelEventHandlers(have_wheel_event_handlers_
);
1208 layer
->SetHaveScrollEventHandlers(have_scroll_event_handlers_
);
1209 layer
->SetNonFastScrollableRegion(non_fast_scrollable_region_
);
1210 layer
->SetTouchEventHandlerRegion(touch_event_handler_region_
);
1211 layer
->SetScrollBlocksOn(scroll_blocks_on_
);
1212 layer
->SetContentsOpaque(contents_opaque_
);
1213 if (!layer
->OpacityIsAnimatingOnImplOnly() && !OpacityIsAnimating())
1214 layer
->SetOpacity(opacity_
);
1215 DCHECK(!(OpacityIsAnimating() && layer
->OpacityIsAnimatingOnImplOnly()));
1216 layer
->SetBlendMode(blend_mode_
);
1217 layer
->SetIsRootForIsolatedGroup(is_root_for_isolated_group_
);
1218 layer
->SetPosition(position_
);
1219 layer
->SetIsContainerForFixedPositionLayers(
1220 IsContainerForFixedPositionLayers());
1221 layer
->SetPositionConstraint(position_constraint_
);
1222 layer
->SetShouldFlattenTransform(should_flatten_transform_
);
1223 layer
->set_should_flatten_transform_from_property_tree(
1224 should_flatten_transform_from_property_tree_
);
1225 layer
->set_is_clipped(is_clipped_
);
1226 layer
->set_draw_blend_mode(draw_blend_mode_
);
1227 layer
->SetUseParentBackfaceVisibility(use_parent_backface_visibility_
);
1228 if (!layer
->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating())
1229 layer
->SetTransformAndInvertibility(transform_
, transform_is_invertible_
);
1230 DCHECK(!(TransformIsAnimating() && layer
->TransformIsAnimatingOnImplOnly()));
1231 layer
->Set3dSortingContextId(sorting_context_id_
);
1232 layer
->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_
);
1234 layer
->SetScrollClipLayer(scroll_clip_layer_id_
);
1235 layer
->set_user_scrollable_horizontal(user_scrollable_horizontal_
);
1236 layer
->set_user_scrollable_vertical(user_scrollable_vertical_
);
1238 LayerImpl
* scroll_parent
= nullptr;
1239 if (scroll_parent_
) {
1240 scroll_parent
= layer
->layer_tree_impl()->LayerById(scroll_parent_
->id());
1241 DCHECK(scroll_parent
);
1244 layer
->SetScrollParent(scroll_parent
);
1245 if (scroll_children_
) {
1246 std::set
<LayerImpl
*>* scroll_children
= new std::set
<LayerImpl
*>;
1247 for (std::set
<Layer
*>::iterator it
= scroll_children_
->begin();
1248 it
!= scroll_children_
->end();
1250 DCHECK_EQ((*it
)->scroll_parent(), this);
1251 LayerImpl
* scroll_child
=
1252 layer
->layer_tree_impl()->LayerById((*it
)->id());
1253 DCHECK(scroll_child
);
1254 scroll_children
->insert(scroll_child
);
1256 layer
->SetScrollChildren(scroll_children
);
1258 layer
->SetScrollChildren(nullptr);
1261 LayerImpl
* clip_parent
= nullptr;
1264 layer
->layer_tree_impl()->LayerById(clip_parent_
->id());
1265 DCHECK(clip_parent
);
1268 layer
->SetClipParent(clip_parent
);
1269 if (clip_children_
) {
1270 std::set
<LayerImpl
*>* clip_children
= new std::set
<LayerImpl
*>;
1271 for (std::set
<Layer
*>::iterator it
= clip_children_
->begin();
1272 it
!= clip_children_
->end(); ++it
) {
1273 DCHECK_EQ((*it
)->clip_parent(), this);
1274 LayerImpl
* clip_child
= layer
->layer_tree_impl()->LayerById((*it
)->id());
1276 clip_children
->insert(clip_child
);
1278 layer
->SetClipChildren(clip_children
);
1280 layer
->SetClipChildren(nullptr);
1283 // When a scroll offset animation is interrupted the new scroll position on
1284 // the pending tree will clobber any impl-side scrolling occuring on the
1285 // active tree. To do so, avoid scrolling the pending tree along with it
1286 // instead of trying to undo that scrolling later.
1287 if (ScrollOffsetAnimationWasInterrupted())
1288 layer
->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_
);
1290 layer
->PushScrollOffsetFromMainThread(scroll_offset_
);
1291 layer
->SetScrollCompensationAdjustment(ScrollCompensationAdjustment());
1293 // Wrap the copy_requests_ in a PostTask to the main thread.
1294 bool had_copy_requests
= !copy_requests_
.empty();
1295 ScopedPtrVector
<CopyOutputRequest
> main_thread_copy_requests
;
1296 for (ScopedPtrVector
<CopyOutputRequest
>::iterator it
= copy_requests_
.begin();
1297 it
!= copy_requests_
.end();
1299 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
=
1300 layer_tree_host()->proxy()->MainThreadTaskRunner();
1301 scoped_ptr
<CopyOutputRequest
> original_request
= copy_requests_
.take(it
);
1302 const CopyOutputRequest
& original_request_ref
= *original_request
;
1303 scoped_ptr
<CopyOutputRequest
> main_thread_request
=
1304 CopyOutputRequest::CreateRelayRequest(
1305 original_request_ref
,
1306 base::Bind(&PostCopyCallbackToMainThread
,
1307 main_thread_task_runner
,
1308 base::Passed(&original_request
)));
1309 main_thread_copy_requests
.push_back(main_thread_request
.Pass());
1311 if (!copy_requests_
.empty() && layer_tree_host_
)
1312 layer_tree_host_
->property_trees()->needs_rebuild
= true;
1313 if (had_copy_requests
)
1314 UpdateNumCopyRequestsForSubtree(false);
1315 copy_requests_
.clear();
1316 layer
->PassCopyRequests(&main_thread_copy_requests
);
1318 // If the main thread commits multiple times before the impl thread actually
1319 // draws, then damage tracking will become incorrect if we simply clobber the
1320 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
1321 // union) any update changes that have occurred on the main thread.
1322 update_rect_
.Union(layer
->update_rect());
1323 layer
->SetUpdateRect(update_rect_
);
1325 layer
->SetStackingOrderChanged(stacking_order_changed_
);
1327 if (layer
->layer_animation_controller() && layer_animation_controller_
)
1328 layer_animation_controller_
->PushAnimationUpdatesTo(
1329 layer
->layer_animation_controller());
1331 if (frame_timing_requests_dirty_
) {
1332 layer
->SetFrameTimingRequests(frame_timing_requests_
);
1333 frame_timing_requests_dirty_
= false;
1336 bool is_page_scale_layer
= this == layer_tree_host()->page_scale_layer();
1337 bool parent_affected
=
1338 layer
->parent() && layer
->parent()->IsAffectedByPageScale();
1339 layer
->SetIsAffectedByPageScale(is_page_scale_layer
|| parent_affected
);
1341 // Reset any state that should be cleared for the next update.
1342 stacking_order_changed_
= false;
1343 update_rect_
= gfx::Rect();
1345 needs_push_properties_
= false;
1346 num_dependents_need_push_properties_
= 0;
1349 scoped_ptr
<LayerImpl
> Layer::CreateLayerImpl(LayerTreeImpl
* tree_impl
) {
1350 return LayerImpl::Create(tree_impl
, layer_id_
,
1351 new LayerImpl::SyncedScrollOffset
);
1354 bool Layer::DrawsContent() const {
1355 return draws_content_
;
1358 bool Layer::HasDrawableContent() const {
1359 return is_drawable_
;
1362 void Layer::UpdateDrawsContent(bool has_drawable_content
) {
1363 bool draws_content
= has_drawable_content
;
1364 DCHECK(is_drawable_
|| !has_drawable_content
);
1365 if (draws_content
== draws_content_
)
1368 if (HasDelegatedContent()) {
1369 // Layers with delegated content need to be treated as if they have as
1370 // many children as the number of layers they own delegated quads for.
1371 // Since we don't know this number right now, we choose one that acts like
1372 // infinity for our purposes.
1373 AddDrawableDescendants(draws_content
? 1000 : -1000);
1377 parent()->AddDrawableDescendants(draws_content
? 1 : -1);
1379 draws_content_
= draws_content
;
1383 int Layer::NumDescendantsThatDrawContent() const {
1384 return num_descendants_that_draw_content_
;
1387 void Layer::SavePaintProperties() {
1388 DCHECK(layer_tree_host_
);
1390 // TODO(reveman): Save all layer properties that we depend on not
1391 // changing until PushProperties() has been called. crbug.com/231016
1392 paint_properties_
.bounds
= bounds_
;
1393 paint_properties_
.source_frame_number
=
1394 layer_tree_host_
->source_frame_number();
1397 bool Layer::Update() {
1398 DCHECK(layer_tree_host_
);
1399 DCHECK_EQ(layer_tree_host_
->source_frame_number(),
1400 paint_properties_
.source_frame_number
) <<
1401 "SavePaintProperties must be called for any layer that is painted.";
1405 bool Layer::IsSuitableForGpuRasterization() const {
1409 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
1410 Layer::TakeDebugInfo() {
1412 return client_
->TakeDebugInfo();
1417 void Layer::SetHasRenderSurface(bool has_render_surface
) {
1418 if (has_render_surface_
== has_render_surface
)
1420 has_render_surface_
= has_render_surface
;
1421 // We do not need SetNeedsCommit here, since this is only ever called
1422 // during a commit, from CalculateDrawProperties.
1423 SetNeedsPushProperties();
1424 layer_tree_host_
->property_trees()->needs_rebuild
= true;
1427 gfx::ScrollOffset
Layer::ScrollOffsetForAnimation() const {
1428 return CurrentScrollOffset();
1431 // On<Property>Animated is called due to an ongoing accelerated animation.
1432 // Since this animation is also being run on the compositor thread, there
1433 // is no need to request a commit to push this value over, so the value is
1434 // set directly rather than by calling Set<Property>.
1435 void Layer::OnFilterAnimated(const FilterOperations
& filters
) {
1439 void Layer::OnOpacityAnimated(float opacity
) {
1441 if (layer_tree_host_
) {
1442 if (EffectNode
* node
= layer_tree_host_
->property_trees()->effect_tree
.Node(
1443 effect_tree_index())) {
1444 if (node
->owner_id
== id()) {
1445 node
->data
.opacity
= opacity
;
1446 layer_tree_host_
->property_trees()->effect_tree
.set_needs_update(true);
1452 void Layer::OnTransformAnimated(const gfx::Transform
& transform
) {
1453 if (transform_
== transform
)
1455 transform_
= transform
;
1456 transform_is_invertible_
= transform
.IsInvertible();
1457 if (layer_tree_host_
) {
1458 if (TransformNode
* node
=
1459 layer_tree_host_
->property_trees()->transform_tree
.Node(
1460 transform_tree_index())) {
1461 if (node
->owner_id
== id()) {
1462 node
->data
.local
= transform
;
1463 node
->data
.needs_local_transform_update
= true;
1464 node
->data
.is_animated
= true;
1465 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(
1472 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) {
1473 // Do nothing. Scroll deltas will be sent from the compositor thread back
1474 // to the main thread in the same manner as during non-animated
1475 // compositor-driven scrolling.
1478 void Layer::OnAnimationWaitingForDeletion() {
1479 // Animations are only deleted during PushProperties.
1480 SetNeedsPushProperties();
1483 void Layer::OnTransformIsPotentiallyAnimatingChanged(bool is_animating
) {
1484 if (!layer_tree_host_
)
1486 TransformTree
& transform_tree
=
1487 layer_tree_host_
->property_trees()->transform_tree
;
1488 TransformNode
* node
= transform_tree
.Node(transform_tree_index());
1492 if (node
->owner_id
== id()) {
1493 node
->data
.is_animated
= is_animating
;
1495 float maximum_target_scale
= 0.f
;
1496 node
->data
.local_maximum_animation_target_scale
=
1497 MaximumTargetScale(&maximum_target_scale
) ? maximum_target_scale
1500 float animation_start_scale
= 0.f
;
1501 node
->data
.local_starting_animation_scale
=
1502 AnimationStartScale(&animation_start_scale
) ? animation_start_scale
1505 node
->data
.has_only_translation_animations
=
1506 HasOnlyTranslationTransforms();
1509 node
->data
.local_maximum_animation_target_scale
= 0.f
;
1510 node
->data
.local_starting_animation_scale
= 0.f
;
1511 node
->data
.has_only_translation_animations
= true;
1513 transform_tree
.set_needs_update(true);
1517 bool Layer::IsActive() const {
1521 bool Layer::AddAnimation(scoped_ptr
<Animation
> animation
) {
1522 DCHECK(layer_animation_controller_
);
1523 if (!layer_animation_controller_
->animation_registrar())
1526 if (animation
->target_property() == Animation::SCROLL_OFFSET
&&
1527 !layer_animation_controller_
->animation_registrar()
1528 ->supports_scroll_animations())
1531 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer",
1533 layer_animation_controller_
->AddAnimation(animation
.Pass());
1538 void Layer::PauseAnimation(int animation_id
, double time_offset
) {
1539 DCHECK(layer_animation_controller_
);
1540 layer_animation_controller_
->PauseAnimation(
1541 animation_id
, base::TimeDelta::FromSecondsD(time_offset
));
1545 void Layer::RemoveAnimation(int animation_id
) {
1546 DCHECK(layer_animation_controller_
);
1547 layer_animation_controller_
->RemoveAnimation(animation_id
);
1551 void Layer::RemoveAnimation(int animation_id
,
1552 Animation::TargetProperty property
) {
1553 DCHECK(layer_animation_controller_
);
1554 layer_animation_controller_
->RemoveAnimation(animation_id
, property
);
1558 void Layer::SetLayerAnimationControllerForTest(
1559 scoped_refptr
<LayerAnimationController
> controller
) {
1560 DCHECK(layer_animation_controller_
);
1561 layer_animation_controller_
->RemoveValueObserver(this);
1562 layer_animation_controller_
= controller
;
1563 layer_animation_controller_
->AddValueObserver(this);
1567 bool Layer::HasActiveAnimation() const {
1568 DCHECK(layer_tree_host_
);
1569 return layer_animation_controller_
1570 ? layer_animation_controller_
->HasActiveAnimation()
1571 : layer_tree_host_
->HasActiveAnimation(this);
1574 void Layer::RegisterForAnimations(AnimationRegistrar
* registrar
) {
1575 if (layer_animation_controller_
)
1576 layer_animation_controller_
->SetAnimationRegistrar(registrar
);
1579 void Layer::AddLayerAnimationEventObserver(
1580 LayerAnimationEventObserver
* animation_observer
) {
1581 DCHECK(layer_animation_controller_
);
1582 layer_animation_controller_
->AddEventObserver(animation_observer
);
1585 void Layer::RemoveLayerAnimationEventObserver(
1586 LayerAnimationEventObserver
* animation_observer
) {
1587 DCHECK(layer_animation_controller_
);
1588 layer_animation_controller_
->RemoveEventObserver(animation_observer
);
1591 ScrollbarLayerInterface
* Layer::ToScrollbarLayer() {
1595 RenderingStatsInstrumentation
* Layer::rendering_stats_instrumentation() const {
1596 return layer_tree_host_
->rendering_stats_instrumentation();
1599 void Layer::RemoveFromScrollTree() {
1600 if (scroll_children_
.get()) {
1601 std::set
<Layer
*> copy
= *scroll_children_
;
1602 for (std::set
<Layer
*>::iterator it
= copy
.begin(); it
!= copy
.end(); ++it
)
1603 (*it
)->SetScrollParent(nullptr);
1606 DCHECK(!scroll_children_
);
1607 SetScrollParent(nullptr);
1610 void Layer::RemoveFromClipTree() {
1611 if (clip_children_
.get()) {
1612 std::set
<Layer
*> copy
= *clip_children_
;
1613 for (std::set
<Layer
*>::iterator it
= copy
.begin(); it
!= copy
.end(); ++it
)
1614 (*it
)->SetClipParent(nullptr);
1617 DCHECK(!clip_children_
);
1618 SetClipParent(nullptr);
1621 void Layer::AddDrawableDescendants(int num
) {
1622 DCHECK_GE(num_descendants_that_draw_content_
, 0);
1623 DCHECK_GE(num_descendants_that_draw_content_
+ num
, 0);
1626 num_descendants_that_draw_content_
+= num
;
1629 parent()->AddDrawableDescendants(num
);
1632 void Layer::RunMicroBenchmark(MicroBenchmark
* benchmark
) {
1633 benchmark
->RunOnLayer(this);
1636 bool Layer::HasDelegatedContent() const {
1640 void Layer::SetFrameTimingRequests(
1641 const std::vector
<FrameTimingRequest
>& requests
) {
1642 // TODO(vmpstr): Early out if there are no changes earlier in the call stack.
1643 if (requests
== frame_timing_requests_
)
1645 frame_timing_requests_
= requests
;
1646 frame_timing_requests_dirty_
= true;
1650 void Layer::DidBeginTracing() {
1651 // We'll be dumping layer trees as part of trace, so make sure
1652 // PushPropertiesTo() propagates layer debug info to the impl
1653 // side -- otherwise this won't happen for the the layers that
1654 // remain unchanged since tracing started.
1655 SetNeedsPushProperties();
1658 void Layer::set_visited(bool visited
) {
1660 visited
? layer_tree_host()->meta_information_sequence_number() : 0;
1663 bool Layer::visited() {
1664 return visited_tracker_
==
1665 layer_tree_host()->meta_information_sequence_number();
1668 void Layer::set_layer_or_descendant_is_drawn(
1669 bool layer_or_descendant_is_drawn
) {
1670 layer_or_descendant_is_drawn_tracker_
=
1671 layer_or_descendant_is_drawn
1672 ? layer_tree_host()->meta_information_sequence_number()
1676 bool Layer::layer_or_descendant_is_drawn() {
1677 return layer_or_descendant_is_drawn_tracker_
==
1678 layer_tree_host()->meta_information_sequence_number();
1681 void Layer::set_sorted_for_recursion(bool sorted_for_recursion
) {
1682 sorted_for_recursion_tracker_
=
1683 sorted_for_recursion
1684 ? layer_tree_host()->meta_information_sequence_number()
1688 bool Layer::sorted_for_recursion() {
1689 return sorted_for_recursion_tracker_
==
1690 layer_tree_host()->meta_information_sequence_number();