1 // Copyright 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/layers/layer.h"
9 #include "base/atomic_sequence_num.h"
10 #include "base/location.h"
11 #include "base/metrics/histogram.h"
12 #include "base/single_thread_task_runner.h"
13 #include "base/time/time.h"
14 #include "base/trace_event/trace_event.h"
15 #include "cc/animation/animation.h"
16 #include "cc/animation/animation_events.h"
17 #include "cc/animation/animation_registrar.h"
18 #include "cc/animation/keyframed_animation_curve.h"
19 #include "cc/animation/layer_animation_controller.h"
20 #include "cc/base/simple_enclosed_region.h"
21 #include "cc/debug/frame_viewer_instrumentation.h"
22 #include "cc/layers/layer_client.h"
23 #include "cc/layers/layer_impl.h"
24 #include "cc/layers/scrollbar_layer_interface.h"
25 #include "cc/output/copy_output_request.h"
26 #include "cc/output/copy_output_result.h"
27 #include "cc/trees/layer_tree_host.h"
28 #include "cc/trees/layer_tree_impl.h"
29 #include "third_party/skia/include/core/SkImageFilter.h"
30 #include "ui/gfx/geometry/rect_conversions.h"
31 #include "ui/gfx/geometry/vector2d_conversions.h"
35 base::StaticAtomicSequenceNumber g_next_layer_id
;
37 scoped_refptr
<Layer
> Layer::Create(const LayerSettings
& settings
) {
38 return make_scoped_refptr(new Layer(settings
));
41 Layer::Layer(const LayerSettings
& settings
)
42 : needs_push_properties_(false),
43 num_dependents_need_push_properties_(0),
44 stacking_order_changed_(false),
45 // Layer IDs start from 1.
46 layer_id_(g_next_layer_id
.GetNext() + 1),
47 ignore_set_needs_commit_(false),
48 sorting_context_id_(0),
50 layer_tree_host_(nullptr),
51 scroll_clip_layer_id_(INVALID_ID
),
52 num_descendants_that_draw_content_(0),
53 transform_tree_index_(-1),
54 opacity_tree_index_(-1),
56 property_tree_sequence_number_(-1),
57 num_layer_or_descendants_with_copy_request_(0),
58 num_layer_or_descendants_with_input_handler_(0),
59 num_children_with_scroll_parent_(0),
60 should_flatten_transform_from_property_tree_(false),
61 should_scroll_on_main_thread_(false),
62 have_wheel_event_handlers_(false),
63 have_scroll_event_handlers_(false),
64 user_scrollable_horizontal_(true),
65 user_scrollable_vertical_(true),
66 is_root_for_isolated_group_(false),
67 is_container_for_fixed_position_layers_(false),
69 draws_content_(false),
70 hide_layer_and_subtree_(false),
71 masks_to_bounds_(false),
72 contents_opaque_(false),
74 should_flatten_transform_(true),
75 use_parent_backface_visibility_(false),
76 draw_checkerboard_for_missing_tiles_(false),
77 force_render_surface_(false),
78 transform_is_invertible_(true),
79 has_render_surface_(false),
80 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE
),
83 blend_mode_(SkXfermode::kSrcOver_Mode
),
84 scroll_parent_(nullptr),
85 layer_or_descendant_is_drawn_tracker_(0),
86 sorted_for_recursion_tracker_(0),
88 clip_parent_(nullptr),
89 replica_layer_(nullptr),
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_
->IsAnimatingProperty(
515 : layer_tree_host_
->IsAnimatingFilterProperty(this);
518 void Layer::SetBackgroundFilters(const FilterOperations
& filters
) {
519 DCHECK(IsPropertyChangeAllowed());
520 if (background_filters_
== filters
)
522 background_filters_
= filters
;
526 void Layer::SetOpacity(float opacity
) {
527 DCHECK(IsPropertyChangeAllowed());
528 if (opacity_
== opacity
)
534 bool Layer::OpacityIsAnimating() const {
535 DCHECK(layer_tree_host_
);
536 return layer_animation_controller_
537 ? layer_animation_controller_
->IsAnimatingProperty(
539 : layer_tree_host_
->IsAnimatingOpacityProperty(this);
542 bool Layer::HasPotentiallyRunningOpacityAnimation() const {
543 if (layer_animation_controller_
) {
544 if (Animation
* animation
=
545 layer_animation_controller()->GetAnimation(Animation::OPACITY
)) {
546 return !animation
->is_finished();
550 DCHECK(layer_tree_host_
);
551 return layer_tree_host_
->HasPotentiallyRunningOpacityAnimation(this);
555 bool Layer::OpacityCanAnimateOnImplThread() const {
559 void Layer::SetBlendMode(SkXfermode::Mode blend_mode
) {
560 DCHECK(IsPropertyChangeAllowed());
561 if (blend_mode_
== blend_mode
)
564 // Allowing only blend modes that are defined in the CSS Compositing standard:
565 // http://dev.w3.org/fxtf/compositing-1/#blending
566 switch (blend_mode
) {
567 case SkXfermode::kSrcOver_Mode
:
568 case SkXfermode::kScreen_Mode
:
569 case SkXfermode::kOverlay_Mode
:
570 case SkXfermode::kDarken_Mode
:
571 case SkXfermode::kLighten_Mode
:
572 case SkXfermode::kColorDodge_Mode
:
573 case SkXfermode::kColorBurn_Mode
:
574 case SkXfermode::kHardLight_Mode
:
575 case SkXfermode::kSoftLight_Mode
:
576 case SkXfermode::kDifference_Mode
:
577 case SkXfermode::kExclusion_Mode
:
578 case SkXfermode::kMultiply_Mode
:
579 case SkXfermode::kHue_Mode
:
580 case SkXfermode::kSaturation_Mode
:
581 case SkXfermode::kColor_Mode
:
582 case SkXfermode::kLuminosity_Mode
:
583 // supported blend modes
585 case SkXfermode::kClear_Mode
:
586 case SkXfermode::kSrc_Mode
:
587 case SkXfermode::kDst_Mode
:
588 case SkXfermode::kDstOver_Mode
:
589 case SkXfermode::kSrcIn_Mode
:
590 case SkXfermode::kDstIn_Mode
:
591 case SkXfermode::kSrcOut_Mode
:
592 case SkXfermode::kDstOut_Mode
:
593 case SkXfermode::kSrcATop_Mode
:
594 case SkXfermode::kDstATop_Mode
:
595 case SkXfermode::kXor_Mode
:
596 case SkXfermode::kPlus_Mode
:
597 case SkXfermode::kModulate_Mode
:
598 // Porter Duff Compositing Operators are not yet supported
599 // http://dev.w3.org/fxtf/compositing-1/#porterduffcompositingoperators
604 blend_mode_
= blend_mode
;
608 void Layer::SetIsRootForIsolatedGroup(bool root
) {
609 DCHECK(IsPropertyChangeAllowed());
610 if (is_root_for_isolated_group_
== root
)
612 is_root_for_isolated_group_
= root
;
616 void Layer::SetContentsOpaque(bool opaque
) {
617 DCHECK(IsPropertyChangeAllowed());
618 if (contents_opaque_
== opaque
)
620 contents_opaque_
= opaque
;
624 void Layer::SetPosition(const gfx::PointF
& position
) {
625 DCHECK(IsPropertyChangeAllowed());
626 if (position_
== position
)
628 position_
= position
;
630 if (!layer_tree_host_
)
633 if (TransformNode
* transform_node
=
634 layer_tree_host_
->property_trees()->transform_tree
.Node(
635 transform_tree_index())) {
636 if (transform_node
->owner_id
== id()) {
637 transform_node
->data
.update_post_local_transform(position
,
639 transform_node
->data
.needs_local_transform_update
= true;
640 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
641 SetNeedsCommitNoRebuild();
649 bool Layer::IsContainerForFixedPositionLayers() const {
650 if (!transform_
.IsIdentityOrTranslation())
652 if (parent_
&& !parent_
->transform_
.IsIdentityOrTranslation())
654 return is_container_for_fixed_position_layers_
;
657 bool Are2dAxisAligned(const gfx::Transform
& a
,
658 const gfx::Transform
& b
,
659 bool* is_invertible
) {
660 if (a
.IsScaleOrTranslation() && b
.IsScaleOrTranslation()) {
661 *is_invertible
= b
.IsInvertible();
665 gfx::Transform
inverse(gfx::Transform::kSkipInitialization
);
666 *is_invertible
= b
.GetInverse(&inverse
);
669 return inverse
.Preserves2dAxisAlignment();
672 void Layer::SetTransform(const gfx::Transform
& transform
) {
673 DCHECK(IsPropertyChangeAllowed());
674 if (transform_
== transform
)
677 if (layer_tree_host_
) {
678 if (TransformNode
* transform_node
=
679 layer_tree_host_
->property_trees()->transform_tree
.Node(
680 transform_tree_index())) {
681 if (transform_node
->owner_id
== id()) {
682 // We need to trigger a rebuild if we could have affected 2d axis
683 // alignment. We'll check to see if transform and transform_ are axis
684 // align with respect to one another.
685 bool invertible
= false;
686 bool preserves_2d_axis_alignment
=
687 Are2dAxisAligned(transform_
, transform
, &invertible
);
688 transform_node
->data
.local
= transform
;
689 transform_node
->data
.needs_local_transform_update
= true;
690 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(
692 if (preserves_2d_axis_alignment
)
693 SetNeedsCommitNoRebuild();
696 transform_
= transform
;
697 transform_is_invertible_
= invertible
;
703 transform_
= transform
;
704 transform_is_invertible_
= transform
.IsInvertible();
709 void Layer::SetTransformOrigin(const gfx::Point3F
& transform_origin
) {
710 DCHECK(IsPropertyChangeAllowed());
711 if (transform_origin_
== transform_origin
)
713 transform_origin_
= transform_origin
;
715 if (!layer_tree_host_
)
718 if (TransformNode
* transform_node
=
719 layer_tree_host_
->property_trees()->transform_tree
.Node(
720 transform_tree_index())) {
721 if (transform_node
->owner_id
== id()) {
722 transform_node
->data
.update_pre_local_transform(transform_origin
);
723 transform_node
->data
.update_post_local_transform(position(),
725 transform_node
->data
.needs_local_transform_update
= true;
726 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
727 SetNeedsCommitNoRebuild();
735 bool Layer::AnimationsPreserveAxisAlignment() const {
736 DCHECK(layer_tree_host_
);
737 return layer_animation_controller_
738 ? layer_animation_controller_
->AnimationsPreserveAxisAlignment()
739 : layer_tree_host_
->AnimationsPreserveAxisAlignment(this);
742 bool Layer::TransformIsAnimating() const {
743 DCHECK(layer_tree_host_
);
744 return layer_animation_controller_
745 ? layer_animation_controller_
->IsAnimatingProperty(
746 Animation::TRANSFORM
)
747 : layer_tree_host_
->IsAnimatingTransformProperty(this);
750 bool Layer::HasPotentiallyRunningTransformAnimation() const {
751 if (layer_animation_controller_
) {
752 if (Animation
* animation
=
753 layer_animation_controller()->GetAnimation(Animation::TRANSFORM
)) {
754 return !animation
->is_finished();
758 DCHECK(layer_tree_host_
);
759 return layer_tree_host_
->HasPotentiallyRunningTransformAnimation(this);
763 bool Layer::ScrollOffsetAnimationWasInterrupted() const {
764 DCHECK(layer_tree_host_
);
765 return layer_animation_controller_
766 ? layer_animation_controller_
767 ->scroll_offset_animation_was_interrupted()
768 : layer_tree_host_
->ScrollOffsetAnimationWasInterrupted(this);
771 void Layer::SetScrollParent(Layer
* parent
) {
772 DCHECK(IsPropertyChangeAllowed());
773 if (scroll_parent_
== parent
)
777 scroll_parent_
->RemoveScrollChild(this);
779 scroll_parent_
= parent
;
782 scroll_parent_
->AddScrollChild(this);
787 void Layer::AddScrollChild(Layer
* child
) {
788 if (!scroll_children_
)
789 scroll_children_
.reset(new std::set
<Layer
*>);
790 scroll_children_
->insert(child
);
791 if (layer_tree_host_
&& !layer_tree_host_
->needs_meta_info_recomputation()) {
792 num_children_with_scroll_parent_
++;
793 draw_properties().has_child_with_a_scroll_parent
= true;
798 void Layer::RemoveScrollChild(Layer
* child
) {
799 scroll_children_
->erase(child
);
800 if (scroll_children_
->empty())
801 scroll_children_
= nullptr;
802 if (layer_tree_host_
&& !layer_tree_host_
->needs_meta_info_recomputation()) {
803 num_children_with_scroll_parent_
--;
804 DCHECK_GE(num_children_with_scroll_parent_
, 0);
805 draw_properties().has_child_with_a_scroll_parent
=
806 (num_children_with_scroll_parent_
!= 0);
811 void Layer::SetClipParent(Layer
* ancestor
) {
812 DCHECK(IsPropertyChangeAllowed());
813 if (clip_parent_
== ancestor
)
817 clip_parent_
->RemoveClipChild(this);
819 clip_parent_
= ancestor
;
822 clip_parent_
->AddClipChild(this);
825 if (layer_tree_host_
)
826 layer_tree_host_
->SetNeedsMetaInfoRecomputation(true);
829 void Layer::AddClipChild(Layer
* child
) {
831 clip_children_
.reset(new std::set
<Layer
*>);
832 clip_children_
->insert(child
);
836 void Layer::RemoveClipChild(Layer
* child
) {
837 clip_children_
->erase(child
);
838 if (clip_children_
->empty())
839 clip_children_
= nullptr;
843 void Layer::SetScrollOffset(const gfx::ScrollOffset
& scroll_offset
) {
844 DCHECK(IsPropertyChangeAllowed());
846 if (scroll_offset_
== scroll_offset
)
848 scroll_offset_
= scroll_offset
;
850 if (!layer_tree_host_
)
853 if (TransformNode
* transform_node
=
854 layer_tree_host_
->property_trees()->transform_tree
.Node(
855 transform_tree_index())) {
856 if (transform_node
->owner_id
== id()) {
857 transform_node
->data
.scroll_offset
= CurrentScrollOffset();
858 transform_node
->data
.needs_local_transform_update
= true;
859 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
860 SetNeedsCommitNoRebuild();
868 void Layer::SetScrollCompensationAdjustment(
869 const gfx::Vector2dF
& scroll_compensation_adjustment
) {
870 if (scroll_compensation_adjustment_
== scroll_compensation_adjustment
)
872 scroll_compensation_adjustment_
= scroll_compensation_adjustment
;
876 gfx::Vector2dF
Layer::ScrollCompensationAdjustment() const {
877 return scroll_compensation_adjustment_
;
880 void Layer::SetScrollOffsetFromImplSide(
881 const gfx::ScrollOffset
& scroll_offset
) {
882 DCHECK(IsPropertyChangeAllowed());
883 // This function only gets called during a BeginMainFrame, so there
884 // is no need to call SetNeedsUpdate here.
885 DCHECK(layer_tree_host_
&& layer_tree_host_
->CommitRequested());
886 if (scroll_offset_
== scroll_offset
)
888 scroll_offset_
= scroll_offset
;
889 SetNeedsPushProperties();
891 bool needs_rebuild
= true;
892 if (TransformNode
* transform_node
=
893 layer_tree_host_
->property_trees()->transform_tree
.Node(
894 transform_tree_index())) {
895 if (transform_node
->owner_id
== id()) {
896 transform_node
->data
.scroll_offset
= CurrentScrollOffset();
897 transform_node
->data
.needs_local_transform_update
= true;
898 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
899 needs_rebuild
= false;
904 layer_tree_host_
->property_trees()->needs_rebuild
= true;
906 if (!did_scroll_callback_
.is_null())
907 did_scroll_callback_
.Run();
908 // The callback could potentially change the layer structure:
909 // "this" may have been destroyed during the process.
912 void Layer::SetScrollClipLayerId(int clip_layer_id
) {
913 DCHECK(IsPropertyChangeAllowed());
914 if (scroll_clip_layer_id_
== clip_layer_id
)
916 scroll_clip_layer_id_
= clip_layer_id
;
920 void Layer::SetUserScrollable(bool horizontal
, bool vertical
) {
921 DCHECK(IsPropertyChangeAllowed());
922 if (user_scrollable_horizontal_
== horizontal
&&
923 user_scrollable_vertical_
== vertical
)
925 user_scrollable_horizontal_
= horizontal
;
926 user_scrollable_vertical_
= vertical
;
930 void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
931 DCHECK(IsPropertyChangeAllowed());
932 if (should_scroll_on_main_thread_
== should_scroll_on_main_thread
)
934 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
938 void Layer::SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
939 DCHECK(IsPropertyChangeAllowed());
940 if (have_wheel_event_handlers_
== have_wheel_event_handlers
)
942 if (touch_event_handler_region_
.IsEmpty() && layer_tree_host_
&&
943 !layer_tree_host_
->needs_meta_info_recomputation())
944 UpdateNumInputHandlersForSubtree(have_wheel_event_handlers
);
946 have_wheel_event_handlers_
= have_wheel_event_handlers
;
950 void Layer::UpdateNumInputHandlersForSubtree(bool add
) {
951 int change
= add
? 1 : -1;
952 for (Layer
* layer
= this; layer
; layer
= layer
->parent()) {
953 layer
->num_layer_or_descendants_with_input_handler_
+= change
;
954 layer
->draw_properties().layer_or_descendant_has_input_handler
=
955 (layer
->num_layer_or_descendants_with_input_handler_
!= 0);
956 DCHECK_GE(layer
->num_layer_or_descendants_with_input_handler_
, 0);
960 void Layer::SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
961 DCHECK(IsPropertyChangeAllowed());
962 if (have_scroll_event_handlers_
== have_scroll_event_handlers
)
964 have_scroll_event_handlers_
= have_scroll_event_handlers
;
968 void Layer::SetNonFastScrollableRegion(const Region
& region
) {
969 DCHECK(IsPropertyChangeAllowed());
970 if (non_fast_scrollable_region_
== region
)
972 non_fast_scrollable_region_
= region
;
976 void Layer::SetTouchEventHandlerRegion(const Region
& region
) {
977 DCHECK(IsPropertyChangeAllowed());
978 if (touch_event_handler_region_
== region
)
980 if (!have_wheel_event_handlers_
&& layer_tree_host_
&&
981 !layer_tree_host_
->needs_meta_info_recomputation())
982 UpdateNumInputHandlersForSubtree(!region
.IsEmpty());
984 touch_event_handler_region_
= region
;
988 void Layer::SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
989 DCHECK(IsPropertyChangeAllowed());
990 if (scroll_blocks_on_
== scroll_blocks_on
)
992 scroll_blocks_on_
= scroll_blocks_on
;
996 void Layer::SetDrawCheckerboardForMissingTiles(bool checkerboard
) {
997 DCHECK(IsPropertyChangeAllowed());
998 if (draw_checkerboard_for_missing_tiles_
== checkerboard
)
1000 draw_checkerboard_for_missing_tiles_
= checkerboard
;
1004 void Layer::SetForceRenderSurface(bool force
) {
1005 DCHECK(IsPropertyChangeAllowed());
1006 if (force_render_surface_
== force
)
1008 force_render_surface_
= force
;
1012 void Layer::SetDoubleSided(bool double_sided
) {
1013 DCHECK(IsPropertyChangeAllowed());
1014 if (double_sided_
== double_sided
)
1016 double_sided_
= double_sided
;
1020 void Layer::Set3dSortingContextId(int id
) {
1021 DCHECK(IsPropertyChangeAllowed());
1022 if (id
== sorting_context_id_
)
1024 sorting_context_id_
= id
;
1028 void Layer::SetTransformTreeIndex(int index
) {
1029 DCHECK(IsPropertyChangeAllowed());
1030 if (transform_tree_index_
== index
)
1032 transform_tree_index_
= index
;
1033 SetNeedsPushProperties();
1036 int Layer::transform_tree_index() const {
1037 if (!layer_tree_host_
||
1038 layer_tree_host_
->property_trees()->sequence_number
!=
1039 property_tree_sequence_number_
) {
1042 return transform_tree_index_
;
1045 void Layer::SetClipTreeIndex(int index
) {
1046 DCHECK(IsPropertyChangeAllowed());
1047 if (clip_tree_index_
== index
)
1049 clip_tree_index_
= index
;
1050 SetNeedsPushProperties();
1053 int Layer::clip_tree_index() const {
1054 if (!layer_tree_host_
||
1055 layer_tree_host_
->property_trees()->sequence_number
!=
1056 property_tree_sequence_number_
) {
1059 return clip_tree_index_
;
1062 void Layer::SetOpacityTreeIndex(int index
) {
1063 DCHECK(IsPropertyChangeAllowed());
1064 if (opacity_tree_index_
== index
)
1066 opacity_tree_index_
= index
;
1067 SetNeedsPushProperties();
1070 int Layer::opacity_tree_index() const {
1071 if (!layer_tree_host_
||
1072 layer_tree_host_
->property_trees()->sequence_number
!=
1073 property_tree_sequence_number_
) {
1076 return opacity_tree_index_
;
1079 void Layer::InvalidatePropertyTreesIndices() {
1080 int invalid_property_tree_index
= -1;
1081 SetTransformTreeIndex(invalid_property_tree_index
);
1082 SetClipTreeIndex(invalid_property_tree_index
);
1083 SetOpacityTreeIndex(invalid_property_tree_index
);
1086 void Layer::SetShouldFlattenTransform(bool should_flatten
) {
1087 DCHECK(IsPropertyChangeAllowed());
1088 if (should_flatten_transform_
== should_flatten
)
1090 should_flatten_transform_
= should_flatten
;
1094 void Layer::SetIsDrawable(bool is_drawable
) {
1095 DCHECK(IsPropertyChangeAllowed());
1096 if (is_drawable_
== is_drawable
)
1099 is_drawable_
= is_drawable
;
1100 UpdateDrawsContent(HasDrawableContent());
1103 void Layer::SetHideLayerAndSubtree(bool hide
) {
1104 DCHECK(IsPropertyChangeAllowed());
1105 if (hide_layer_and_subtree_
== hide
)
1108 hide_layer_and_subtree_
= hide
;
1112 void Layer::SetNeedsDisplayRect(const gfx::Rect
& dirty_rect
) {
1113 if (dirty_rect
.IsEmpty())
1116 SetNeedsPushProperties();
1117 update_rect_
.Union(dirty_rect
);
1123 bool Layer::DescendantIsFixedToContainerLayer() const {
1124 for (size_t i
= 0; i
< children_
.size(); ++i
) {
1125 if (children_
[i
]->position_constraint_
.is_fixed_position() ||
1126 children_
[i
]->DescendantIsFixedToContainerLayer())
1132 void Layer::SetIsContainerForFixedPositionLayers(bool container
) {
1133 if (is_container_for_fixed_position_layers_
== container
)
1135 is_container_for_fixed_position_layers_
= container
;
1137 if (layer_tree_host_
&& layer_tree_host_
->CommitRequested())
1140 // Only request a commit if we have a fixed positioned descendant.
1141 if (DescendantIsFixedToContainerLayer())
1145 void Layer::SetPositionConstraint(const LayerPositionConstraint
& constraint
) {
1146 DCHECK(IsPropertyChangeAllowed());
1147 if (position_constraint_
== constraint
)
1149 position_constraint_
= constraint
;
1153 static void RunCopyCallbackOnMainThread(scoped_ptr
<CopyOutputRequest
> request
,
1154 scoped_ptr
<CopyOutputResult
> result
) {
1155 request
->SendResult(result
.Pass());
1158 static void PostCopyCallbackToMainThread(
1159 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
,
1160 scoped_ptr
<CopyOutputRequest
> request
,
1161 scoped_ptr
<CopyOutputResult
> result
) {
1162 main_thread_task_runner
->PostTask(FROM_HERE
,
1163 base::Bind(&RunCopyCallbackOnMainThread
,
1164 base::Passed(&request
),
1165 base::Passed(&result
)));
1168 void Layer::PushPropertiesTo(LayerImpl
* layer
) {
1169 DCHECK(layer_tree_host_
);
1171 // If we did not SavePaintProperties() for the layer this frame, then push the
1172 // real property values, not the paint property values.
1173 bool use_paint_properties
= paint_properties_
.source_frame_number
==
1174 layer_tree_host_
->source_frame_number();
1176 layer
->SetTransformOrigin(transform_origin_
);
1177 layer
->SetBackgroundColor(background_color_
);
1178 layer
->SetBounds(use_paint_properties
? paint_properties_
.bounds
1181 if (frame_viewer_instrumentation::IsTracingLayerTreeSnapshots())
1182 layer
->SetDebugInfo(TakeDebugInfo());
1184 layer
->SetTransformTreeIndex(transform_tree_index());
1185 layer
->SetOpacityTreeIndex(opacity_tree_index());
1186 layer
->SetClipTreeIndex(clip_tree_index());
1187 layer
->set_offset_to_transform_parent(offset_to_transform_parent_
);
1188 layer
->SetDoubleSided(double_sided_
);
1189 layer
->SetDrawCheckerboardForMissingTiles(
1190 draw_checkerboard_for_missing_tiles_
);
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
->SetUseParentBackfaceVisibility(use_parent_backface_visibility_
);
1219 if (!layer
->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating())
1220 layer
->SetTransformAndInvertibility(transform_
, transform_is_invertible_
);
1221 DCHECK(!(TransformIsAnimating() && layer
->TransformIsAnimatingOnImplOnly()));
1222 layer
->Set3dSortingContextId(sorting_context_id_
);
1223 layer
->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_
);
1225 layer
->SetScrollClipLayer(scroll_clip_layer_id_
);
1226 layer
->set_user_scrollable_horizontal(user_scrollable_horizontal_
);
1227 layer
->set_user_scrollable_vertical(user_scrollable_vertical_
);
1229 LayerImpl
* scroll_parent
= nullptr;
1230 if (scroll_parent_
) {
1231 scroll_parent
= layer
->layer_tree_impl()->LayerById(scroll_parent_
->id());
1232 DCHECK(scroll_parent
);
1235 layer
->SetScrollParent(scroll_parent
);
1236 if (scroll_children_
) {
1237 std::set
<LayerImpl
*>* scroll_children
= new std::set
<LayerImpl
*>;
1238 for (std::set
<Layer
*>::iterator it
= scroll_children_
->begin();
1239 it
!= scroll_children_
->end();
1241 DCHECK_EQ((*it
)->scroll_parent(), this);
1242 LayerImpl
* scroll_child
=
1243 layer
->layer_tree_impl()->LayerById((*it
)->id());
1244 DCHECK(scroll_child
);
1245 scroll_children
->insert(scroll_child
);
1247 layer
->SetScrollChildren(scroll_children
);
1249 layer
->SetScrollChildren(nullptr);
1252 LayerImpl
* clip_parent
= nullptr;
1255 layer
->layer_tree_impl()->LayerById(clip_parent_
->id());
1256 DCHECK(clip_parent
);
1259 layer
->SetClipParent(clip_parent
);
1260 if (clip_children_
) {
1261 std::set
<LayerImpl
*>* clip_children
= new std::set
<LayerImpl
*>;
1262 for (std::set
<Layer
*>::iterator it
= clip_children_
->begin();
1263 it
!= clip_children_
->end(); ++it
) {
1264 DCHECK_EQ((*it
)->clip_parent(), this);
1265 LayerImpl
* clip_child
= layer
->layer_tree_impl()->LayerById((*it
)->id());
1267 clip_children
->insert(clip_child
);
1269 layer
->SetClipChildren(clip_children
);
1271 layer
->SetClipChildren(nullptr);
1274 // When a scroll offset animation is interrupted the new scroll position on
1275 // the pending tree will clobber any impl-side scrolling occuring on the
1276 // active tree. To do so, avoid scrolling the pending tree along with it
1277 // instead of trying to undo that scrolling later.
1278 if (ScrollOffsetAnimationWasInterrupted())
1279 layer
->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_
);
1281 layer
->PushScrollOffsetFromMainThread(scroll_offset_
);
1282 layer
->SetScrollCompensationAdjustment(ScrollCompensationAdjustment());
1284 // Wrap the copy_requests_ in a PostTask to the main thread.
1285 bool had_copy_requests
= !copy_requests_
.empty();
1286 ScopedPtrVector
<CopyOutputRequest
> main_thread_copy_requests
;
1287 for (ScopedPtrVector
<CopyOutputRequest
>::iterator it
= copy_requests_
.begin();
1288 it
!= copy_requests_
.end();
1290 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
=
1291 layer_tree_host()->proxy()->MainThreadTaskRunner();
1292 scoped_ptr
<CopyOutputRequest
> original_request
= copy_requests_
.take(it
);
1293 const CopyOutputRequest
& original_request_ref
= *original_request
;
1294 scoped_ptr
<CopyOutputRequest
> main_thread_request
=
1295 CopyOutputRequest::CreateRelayRequest(
1296 original_request_ref
,
1297 base::Bind(&PostCopyCallbackToMainThread
,
1298 main_thread_task_runner
,
1299 base::Passed(&original_request
)));
1300 main_thread_copy_requests
.push_back(main_thread_request
.Pass());
1302 if (!copy_requests_
.empty() && layer_tree_host_
)
1303 layer_tree_host_
->property_trees()->needs_rebuild
= true;
1304 if (had_copy_requests
)
1305 UpdateNumCopyRequestsForSubtree(false);
1306 copy_requests_
.clear();
1307 layer
->PassCopyRequests(&main_thread_copy_requests
);
1309 // If the main thread commits multiple times before the impl thread actually
1310 // draws, then damage tracking will become incorrect if we simply clobber the
1311 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
1312 // union) any update changes that have occurred on the main thread.
1313 update_rect_
.Union(layer
->update_rect());
1314 layer
->SetUpdateRect(update_rect_
);
1316 layer
->SetStackingOrderChanged(stacking_order_changed_
);
1318 if (layer
->layer_animation_controller() && layer_animation_controller_
)
1319 layer_animation_controller_
->PushAnimationUpdatesTo(
1320 layer
->layer_animation_controller());
1322 if (frame_timing_requests_dirty_
) {
1323 layer
->SetFrameTimingRequests(frame_timing_requests_
);
1324 frame_timing_requests_dirty_
= false;
1327 bool is_page_scale_layer
= this == layer_tree_host()->page_scale_layer();
1328 bool parent_affected
=
1329 layer
->parent() && layer
->parent()->IsAffectedByPageScale();
1330 layer
->SetIsAffectedByPageScale(is_page_scale_layer
|| parent_affected
);
1332 // Reset any state that should be cleared for the next update.
1333 stacking_order_changed_
= false;
1334 update_rect_
= gfx::Rect();
1336 needs_push_properties_
= false;
1337 num_dependents_need_push_properties_
= 0;
1340 scoped_ptr
<LayerImpl
> Layer::CreateLayerImpl(LayerTreeImpl
* tree_impl
) {
1341 return LayerImpl::Create(tree_impl
, layer_id_
,
1342 new LayerImpl::SyncedScrollOffset
);
1345 bool Layer::DrawsContent() const {
1346 return draws_content_
;
1349 bool Layer::HasDrawableContent() const {
1350 return is_drawable_
;
1353 void Layer::UpdateDrawsContent(bool has_drawable_content
) {
1354 bool draws_content
= has_drawable_content
;
1355 DCHECK(is_drawable_
|| !has_drawable_content
);
1356 if (draws_content
== draws_content_
)
1359 if (HasDelegatedContent()) {
1360 // Layers with delegated content need to be treated as if they have as
1361 // many children as the number of layers they own delegated quads for.
1362 // Since we don't know this number right now, we choose one that acts like
1363 // infinity for our purposes.
1364 AddDrawableDescendants(draws_content
? 1000 : -1000);
1368 parent()->AddDrawableDescendants(draws_content
? 1 : -1);
1370 draws_content_
= draws_content
;
1374 int Layer::NumDescendantsThatDrawContent() const {
1375 return num_descendants_that_draw_content_
;
1378 void Layer::SavePaintProperties() {
1379 DCHECK(layer_tree_host_
);
1381 // TODO(reveman): Save all layer properties that we depend on not
1382 // changing until PushProperties() has been called. crbug.com/231016
1383 paint_properties_
.bounds
= bounds_
;
1384 paint_properties_
.source_frame_number
=
1385 layer_tree_host_
->source_frame_number();
1388 bool Layer::Update() {
1389 DCHECK(layer_tree_host_
);
1390 DCHECK_EQ(layer_tree_host_
->source_frame_number(),
1391 paint_properties_
.source_frame_number
) <<
1392 "SavePaintProperties must be called for any layer that is painted.";
1396 bool Layer::NeedMoreUpdates() {
1400 bool Layer::IsSuitableForGpuRasterization() const {
1404 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
1405 Layer::TakeDebugInfo() {
1407 return client_
->TakeDebugInfo();
1412 void Layer::SetHasRenderSurface(bool has_render_surface
) {
1413 if (has_render_surface_
== has_render_surface
)
1415 has_render_surface_
= has_render_surface
;
1416 // We do not need SetNeedsCommit here, since this is only ever called
1417 // during a commit, from CalculateDrawProperties.
1418 SetNeedsPushProperties();
1421 void Layer::CreateRenderSurface() {
1422 DCHECK(!render_surface_
);
1423 render_surface_
= make_scoped_ptr(new RenderSurface(this));
1426 void Layer::ClearRenderSurface() {
1427 render_surface_
= nullptr;
1430 void Layer::ClearRenderSurfaceLayerList() {
1431 if (render_surface_
)
1432 render_surface_
->ClearLayerLists();
1435 gfx::ScrollOffset
Layer::ScrollOffsetForAnimation() const {
1436 return CurrentScrollOffset();
1439 // On<Property>Animated is called due to an ongoing accelerated animation.
1440 // Since this animation is also being run on the compositor thread, there
1441 // is no need to request a commit to push this value over, so the value is
1442 // set directly rather than by calling Set<Property>.
1443 void Layer::OnFilterAnimated(const FilterOperations
& filters
) {
1447 void Layer::OnOpacityAnimated(float opacity
) {
1449 if (layer_tree_host_
) {
1450 if (OpacityNode
* node
=
1451 layer_tree_host_
->property_trees()->opacity_tree
.Node(
1452 opacity_tree_index())) {
1453 if (node
->owner_id
== id()) {
1454 node
->data
.opacity
= opacity
;
1455 layer_tree_host_
->property_trees()->opacity_tree
.set_needs_update(true);
1461 void Layer::OnTransformAnimated(const gfx::Transform
& transform
) {
1462 if (transform_
== transform
)
1464 transform_
= transform
;
1465 transform_is_invertible_
= transform
.IsInvertible();
1466 if (layer_tree_host_
) {
1467 if (TransformNode
* node
=
1468 layer_tree_host_
->property_trees()->transform_tree
.Node(
1469 transform_tree_index())) {
1470 if (node
->owner_id
== id()) {
1471 node
->data
.local
= transform
;
1472 node
->data
.needs_local_transform_update
= true;
1473 node
->data
.is_animated
= true;
1474 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(
1481 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) {
1482 // Do nothing. Scroll deltas will be sent from the compositor thread back
1483 // to the main thread in the same manner as during non-animated
1484 // compositor-driven scrolling.
1487 void Layer::OnAnimationWaitingForDeletion() {
1488 // Animations are only deleted during PushProperties.
1489 SetNeedsPushProperties();
1492 bool Layer::IsActive() const {
1496 bool Layer::AddAnimation(scoped_ptr
<Animation
> animation
) {
1497 DCHECK(layer_animation_controller_
);
1498 if (!layer_animation_controller_
->animation_registrar())
1501 if (animation
->target_property() == Animation::SCROLL_OFFSET
&&
1502 !layer_animation_controller_
->animation_registrar()
1503 ->supports_scroll_animations())
1506 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer",
1508 layer_animation_controller_
->AddAnimation(animation
.Pass());
1513 void Layer::PauseAnimation(int animation_id
, double time_offset
) {
1514 DCHECK(layer_animation_controller_
);
1515 layer_animation_controller_
->PauseAnimation(
1516 animation_id
, base::TimeDelta::FromSecondsD(time_offset
));
1520 void Layer::RemoveAnimation(int animation_id
) {
1521 DCHECK(layer_animation_controller_
);
1522 layer_animation_controller_
->RemoveAnimation(animation_id
);
1526 void Layer::RemoveAnimation(int animation_id
,
1527 Animation::TargetProperty property
) {
1528 DCHECK(layer_animation_controller_
);
1529 layer_animation_controller_
->RemoveAnimation(animation_id
, property
);
1533 void Layer::SetLayerAnimationControllerForTest(
1534 scoped_refptr
<LayerAnimationController
> controller
) {
1535 DCHECK(layer_animation_controller_
);
1536 layer_animation_controller_
->RemoveValueObserver(this);
1537 layer_animation_controller_
= controller
;
1538 layer_animation_controller_
->AddValueObserver(this);
1542 bool Layer::HasActiveAnimation() const {
1543 DCHECK(layer_tree_host_
);
1544 return layer_animation_controller_
1545 ? layer_animation_controller_
->HasActiveAnimation()
1546 : layer_tree_host_
->HasActiveAnimation(this);
1549 void Layer::RegisterForAnimations(AnimationRegistrar
* registrar
) {
1550 if (layer_animation_controller_
)
1551 layer_animation_controller_
->SetAnimationRegistrar(registrar
);
1554 void Layer::AddLayerAnimationEventObserver(
1555 LayerAnimationEventObserver
* animation_observer
) {
1556 DCHECK(layer_animation_controller_
);
1557 layer_animation_controller_
->AddEventObserver(animation_observer
);
1560 void Layer::RemoveLayerAnimationEventObserver(
1561 LayerAnimationEventObserver
* animation_observer
) {
1562 DCHECK(layer_animation_controller_
);
1563 layer_animation_controller_
->RemoveEventObserver(animation_observer
);
1566 ScrollbarLayerInterface
* Layer::ToScrollbarLayer() {
1570 RenderingStatsInstrumentation
* Layer::rendering_stats_instrumentation() const {
1571 return layer_tree_host_
->rendering_stats_instrumentation();
1574 void Layer::RemoveFromScrollTree() {
1575 if (scroll_children_
.get()) {
1576 std::set
<Layer
*> copy
= *scroll_children_
;
1577 for (std::set
<Layer
*>::iterator it
= copy
.begin(); it
!= copy
.end(); ++it
)
1578 (*it
)->SetScrollParent(nullptr);
1581 DCHECK(!scroll_children_
);
1582 SetScrollParent(nullptr);
1585 void Layer::RemoveFromClipTree() {
1586 if (clip_children_
.get()) {
1587 std::set
<Layer
*> copy
= *clip_children_
;
1588 for (std::set
<Layer
*>::iterator it
= copy
.begin(); it
!= copy
.end(); ++it
)
1589 (*it
)->SetClipParent(nullptr);
1592 DCHECK(!clip_children_
);
1593 SetClipParent(nullptr);
1596 void Layer::AddDrawableDescendants(int num
) {
1597 DCHECK_GE(num_descendants_that_draw_content_
, 0);
1598 DCHECK_GE(num_descendants_that_draw_content_
+ num
, 0);
1601 num_descendants_that_draw_content_
+= num
;
1604 parent()->AddDrawableDescendants(num
);
1607 void Layer::RunMicroBenchmark(MicroBenchmark
* benchmark
) {
1608 benchmark
->RunOnLayer(this);
1611 bool Layer::HasDelegatedContent() const {
1615 void Layer::SetFrameTimingRequests(
1616 const std::vector
<FrameTimingRequest
>& requests
) {
1617 // TODO(vmpstr): Early out if there are no changes earlier in the call stack.
1618 if (requests
== frame_timing_requests_
)
1620 frame_timing_requests_
= requests
;
1621 frame_timing_requests_dirty_
= true;
1625 void Layer::DidBeginTracing() {
1626 // We'll be dumping layer trees as part of trace, so make sure
1627 // PushPropertiesTo() propagates layer debug info to the impl
1628 // side -- otherwise this won't happen for the the layers that
1629 // remain unchanged since tracing started.
1630 SetNeedsPushProperties();
1633 void Layer::set_visited(bool visited
) {
1635 visited
? layer_tree_host()->meta_information_sequence_number() : 0;
1638 bool Layer::visited() {
1639 return visited_tracker_
==
1640 layer_tree_host()->meta_information_sequence_number();
1643 void Layer::set_layer_or_descendant_is_drawn(
1644 bool layer_or_descendant_is_drawn
) {
1645 layer_or_descendant_is_drawn_tracker_
=
1646 layer_or_descendant_is_drawn
1647 ? layer_tree_host()->meta_information_sequence_number()
1651 bool Layer::layer_or_descendant_is_drawn() {
1652 return layer_or_descendant_is_drawn_tracker_
==
1653 layer_tree_host()->meta_information_sequence_number();
1656 void Layer::set_sorted_for_recursion(bool sorted_for_recursion
) {
1657 sorted_for_recursion_tracker_
=
1658 sorted_for_recursion
1659 ? layer_tree_host()->meta_information_sequence_number()
1663 bool Layer::sorted_for_recursion() {
1664 return sorted_for_recursion_tracker_
==
1665 layer_tree_host()->meta_information_sequence_number();