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_(false),
44 stacking_order_changed_(false),
45 // Layer IDs start from 1.
46 layer_id_(g_next_layer_id
.GetNext() + 1),
47 ignore_set_needs_commit_(false),
48 sorting_context_id_(0),
50 layer_tree_host_(nullptr),
51 scroll_clip_layer_id_(INVALID_ID
),
52 num_descendants_that_draw_content_(0),
53 transform_tree_index_(-1),
54 opacity_tree_index_(-1),
56 property_tree_sequence_number_(-1),
57 num_layer_or_descendants_with_copy_request_(0),
58 num_layer_or_descendants_with_input_handler_(0),
59 num_children_with_scroll_parent_(0),
60 should_flatten_transform_from_property_tree_(false),
61 should_scroll_on_main_thread_(false),
62 have_wheel_event_handlers_(false),
63 have_scroll_event_handlers_(false),
64 user_scrollable_horizontal_(true),
65 user_scrollable_vertical_(true),
66 is_root_for_isolated_group_(false),
67 is_container_for_fixed_position_layers_(false),
69 draws_content_(false),
70 hide_layer_and_subtree_(false),
71 masks_to_bounds_(false),
72 contents_opaque_(false),
74 should_flatten_transform_(true),
75 use_parent_backface_visibility_(false),
76 draw_checkerboard_for_missing_tiles_(false),
77 force_render_surface_(false),
78 transform_is_invertible_(true),
79 has_render_surface_(false),
80 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE
),
83 blend_mode_(SkXfermode::kSrcOver_Mode
),
84 scroll_parent_(nullptr),
85 layer_or_descendant_is_drawn_tracker_(0),
86 sorted_for_recursion_tracker_(0),
88 clip_parent_(nullptr),
89 replica_layer_(nullptr),
92 frame_timing_requests_dirty_(false) {
93 layer_animation_controller_
= LayerAnimationController::Create(layer_id_
);
94 layer_animation_controller_
->AddValueObserver(this);
95 layer_animation_controller_
->set_value_provider(this);
99 // Our parent should be holding a reference to us so there should be no
100 // way for us to be destroyed while we still have a parent.
102 // Similarly we shouldn't have a layer tree host since it also keeps a
104 DCHECK(!layer_tree_host());
106 layer_animation_controller_
->RemoveValueObserver(this);
107 layer_animation_controller_
->remove_value_provider(this);
109 RemoveFromScrollTree();
110 RemoveFromClipTree();
112 // Remove the parent reference from all children and dependents.
114 if (mask_layer_
.get()) {
115 DCHECK_EQ(this, mask_layer_
->parent());
116 mask_layer_
->RemoveFromParent();
118 if (replica_layer_
.get()) {
119 DCHECK_EQ(this, replica_layer_
->parent());
120 replica_layer_
->RemoveFromParent();
124 void Layer::SetLayerTreeHost(LayerTreeHost
* host
) {
125 if (layer_tree_host_
== host
)
128 if (layer_tree_host_
)
129 layer_tree_host_
->property_trees()->needs_rebuild
= true;
131 layer_tree_host_
= host
;
133 // When changing hosts, the layer needs to commit its properties to the impl
134 // side for the new host.
135 SetNeedsPushProperties();
137 for (size_t i
= 0; i
< children_
.size(); ++i
)
138 children_
[i
]->SetLayerTreeHost(host
);
140 if (mask_layer_
.get())
141 mask_layer_
->SetLayerTreeHost(host
);
142 if (replica_layer_
.get())
143 replica_layer_
->SetLayerTreeHost(host
);
146 layer_animation_controller_
->SetAnimationRegistrar(
147 host
->animation_registrar());
149 if (host
->settings().layer_transforms_should_scale_layer_contents
)
150 reset_raster_scale_to_unknown();
153 if (host
&& layer_animation_controller_
->has_any_animation())
154 host
->SetNeedsCommit();
157 void Layer::SetNeedsUpdate() {
158 if (layer_tree_host_
&& !ignore_set_needs_commit_
)
159 layer_tree_host_
->SetNeedsUpdateLayers();
162 void Layer::SetNeedsCommit() {
163 if (!layer_tree_host_
)
166 SetNeedsPushProperties();
167 layer_tree_host_
->property_trees()->needs_rebuild
= true;
169 if (ignore_set_needs_commit_
)
172 layer_tree_host_
->SetNeedsCommit();
175 void Layer::SetNeedsCommitNoRebuild() {
176 if (!layer_tree_host_
)
179 SetNeedsPushProperties();
181 if (ignore_set_needs_commit_
)
184 layer_tree_host_
->SetNeedsCommit();
187 void Layer::SetNeedsFullTreeSync() {
188 if (!layer_tree_host_
)
191 layer_tree_host_
->SetNeedsFullTreeSync();
194 void Layer::SetNextCommitWaitsForActivation() {
195 if (!layer_tree_host_
)
198 layer_tree_host_
->SetNextCommitWaitsForActivation();
201 void Layer::SetNeedsPushProperties() {
202 if (needs_push_properties_
)
204 if (!parent_should_know_need_push_properties() && parent_
)
205 parent_
->AddDependentNeedsPushProperties();
206 needs_push_properties_
= true;
209 void Layer::AddDependentNeedsPushProperties() {
210 DCHECK_GE(num_dependents_need_push_properties_
, 0);
212 if (!parent_should_know_need_push_properties() && parent_
)
213 parent_
->AddDependentNeedsPushProperties();
215 num_dependents_need_push_properties_
++;
218 void Layer::RemoveDependentNeedsPushProperties() {
219 num_dependents_need_push_properties_
--;
220 DCHECK_GE(num_dependents_need_push_properties_
, 0);
222 if (!parent_should_know_need_push_properties() && parent_
)
223 parent_
->RemoveDependentNeedsPushProperties();
226 bool Layer::IsPropertyChangeAllowed() const {
227 if (!layer_tree_host_
)
230 if (!layer_tree_host_
->settings().strict_layer_property_change_checking
)
233 return !layer_tree_host_
->in_paint_layer_contents();
236 gfx::Rect
Layer::LayerRectToContentRect(const gfx::Rect
& layer_rect
) const {
237 gfx::Rect content_rect
= gfx::ScaleToEnclosingRect(
238 layer_rect
, contents_scale_x(), contents_scale_y());
239 // Intersect with content rect to avoid the extra pixel because for some
240 // values x and y, ceil((x / y) * y) may be x + 1.
241 content_rect
.Intersect(gfx::Rect(content_bounds()));
245 skia::RefPtr
<SkPicture
> Layer::GetPicture() const {
246 return skia::RefPtr
<SkPicture
>();
249 void Layer::SetParent(Layer
* layer
) {
250 DCHECK(!layer
|| !layer
->HasAncestor(this));
252 if (parent_should_know_need_push_properties()) {
254 parent_
->RemoveDependentNeedsPushProperties();
256 layer
->AddDependentNeedsPushProperties();
260 SetLayerTreeHost(parent_
? parent_
->layer_tree_host() : nullptr);
262 if (!layer_tree_host_
)
265 layer_tree_host_
->property_trees()->needs_rebuild
= true;
267 const LayerTreeSettings
& settings
= layer_tree_host_
->settings();
268 if (!settings
.layer_transforms_should_scale_layer_contents
)
271 reset_raster_scale_to_unknown();
272 if (mask_layer_
.get())
273 mask_layer_
->reset_raster_scale_to_unknown();
274 if (replica_layer_
.get() && replica_layer_
->mask_layer_
.get())
275 replica_layer_
->mask_layer_
->reset_raster_scale_to_unknown();
278 void Layer::AddChild(scoped_refptr
<Layer
> child
) {
279 InsertChild(child
, children_
.size());
282 void Layer::InsertChild(scoped_refptr
<Layer
> child
, size_t index
) {
283 DCHECK(IsPropertyChangeAllowed());
284 child
->RemoveFromParent();
285 AddDrawableDescendants(child
->NumDescendantsThatDrawContent() +
286 (child
->DrawsContent() ? 1 : 0));
287 child
->SetParent(this);
288 child
->stacking_order_changed_
= true;
290 index
= std::min(index
, children_
.size());
291 children_
.insert(children_
.begin() + index
, child
);
292 SetNeedsFullTreeSync();
295 void Layer::RemoveFromParent() {
296 DCHECK(IsPropertyChangeAllowed());
298 parent_
->RemoveChildOrDependent(this);
301 void Layer::RemoveChildOrDependent(Layer
* child
) {
302 if (mask_layer_
.get() == child
) {
303 mask_layer_
->SetParent(nullptr);
304 mask_layer_
= nullptr;
305 SetNeedsFullTreeSync();
308 if (replica_layer_
.get() == child
) {
309 replica_layer_
->SetParent(nullptr);
310 replica_layer_
= nullptr;
311 SetNeedsFullTreeSync();
315 for (LayerList::iterator iter
= children_
.begin();
316 iter
!= children_
.end();
318 if (iter
->get() != child
)
321 child
->SetParent(nullptr);
322 AddDrawableDescendants(-child
->NumDescendantsThatDrawContent() -
323 (child
->DrawsContent() ? 1 : 0));
324 children_
.erase(iter
);
325 SetNeedsFullTreeSync();
330 void Layer::ReplaceChild(Layer
* reference
, scoped_refptr
<Layer
> new_layer
) {
332 DCHECK_EQ(reference
->parent(), this);
333 DCHECK(IsPropertyChangeAllowed());
335 if (reference
== new_layer
.get())
338 int reference_index
= IndexOfChild(reference
);
339 if (reference_index
== -1) {
344 reference
->RemoveFromParent();
346 if (new_layer
.get()) {
347 new_layer
->RemoveFromParent();
348 InsertChild(new_layer
, reference_index
);
352 int Layer::IndexOfChild(const Layer
* reference
) {
353 for (size_t i
= 0; i
< children_
.size(); ++i
) {
354 if (children_
[i
].get() == reference
)
360 void Layer::SetBounds(const gfx::Size
& size
) {
361 DCHECK(IsPropertyChangeAllowed());
362 if (bounds() == size
)
366 if (!layer_tree_host_
)
369 if (ClipNode
* clip_node
= layer_tree_host_
->property_trees()->clip_tree
.Node(
370 clip_tree_index())) {
371 if (clip_node
->owner_id
== id()) {
372 clip_node
->data
.clip
.set_size(size
);
373 layer_tree_host_
->property_trees()->clip_tree
.set_needs_update(true);
377 SetNeedsCommitNoRebuild();
380 Layer
* Layer::RootLayer() {
382 while (layer
->parent())
383 layer
= layer
->parent();
387 void Layer::RemoveAllChildren() {
388 DCHECK(IsPropertyChangeAllowed());
389 while (children_
.size()) {
390 Layer
* layer
= children_
[0].get();
391 DCHECK_EQ(this, layer
->parent());
392 layer
->RemoveFromParent();
396 void Layer::SetChildren(const LayerList
& children
) {
397 DCHECK(IsPropertyChangeAllowed());
398 if (children
== children_
)
402 for (size_t i
= 0; i
< children
.size(); ++i
)
403 AddChild(children
[i
]);
406 bool Layer::HasAncestor(const Layer
* ancestor
) const {
407 for (const Layer
* layer
= parent(); layer
; layer
= layer
->parent()) {
408 if (layer
== ancestor
)
414 void Layer::RequestCopyOfOutput(
415 scoped_ptr
<CopyOutputRequest
> request
) {
416 DCHECK(IsPropertyChangeAllowed());
417 int size
= copy_requests_
.size();
418 if (void* source
= request
->source()) {
419 auto it
= std::find_if(
420 copy_requests_
.begin(), copy_requests_
.end(),
421 [source
](const CopyOutputRequest
* x
) { return x
->source() == source
; });
422 if (it
!= copy_requests_
.end())
423 copy_requests_
.erase(it
);
425 if (request
->IsEmpty())
427 copy_requests_
.push_back(request
.Pass());
429 bool copy_request_added
= true;
430 UpdateNumCopyRequestsForSubtree(copy_request_added
);
435 void Layer::UpdateNumCopyRequestsForSubtree(bool add
) {
436 int change
= add
? 1 : -1;
437 for (Layer
* layer
= this; layer
; layer
= layer
->parent()) {
438 layer
->num_layer_or_descendants_with_copy_request_
+= change
;
439 layer
->draw_properties().layer_or_descendant_has_copy_request
=
440 (layer
->num_layer_or_descendants_with_copy_request_
!= 0);
441 DCHECK_GE(layer
->num_layer_or_descendants_with_copy_request_
, 0);
445 void Layer::SetBackgroundColor(SkColor background_color
) {
446 DCHECK(IsPropertyChangeAllowed());
447 if (background_color_
== background_color
)
449 background_color_
= background_color
;
453 SkColor
Layer::SafeOpaqueBackgroundColor() const {
454 SkColor color
= background_color();
455 if (SkColorGetA(color
) == 255 && !contents_opaque()) {
456 color
= SK_ColorTRANSPARENT
;
457 } else if (SkColorGetA(color
) != 255 && contents_opaque()) {
458 for (const Layer
* layer
= parent(); layer
;
459 layer
= layer
->parent()) {
460 color
= layer
->background_color();
461 if (SkColorGetA(color
) == 255)
464 if (SkColorGetA(color
) != 255)
465 color
= layer_tree_host_
->background_color();
466 if (SkColorGetA(color
) != 255)
467 color
= SkColorSetA(color
, 255);
472 void Layer::CalculateContentsScale(float ideal_contents_scale
,
473 float* contents_scale_x
,
474 float* contents_scale_y
,
475 gfx::Size
* content_bounds
) {
476 DCHECK(layer_tree_host_
);
478 *contents_scale_x
= 1;
479 *contents_scale_y
= 1;
480 *content_bounds
= bounds();
483 void Layer::SetMasksToBounds(bool masks_to_bounds
) {
484 DCHECK(IsPropertyChangeAllowed());
485 if (masks_to_bounds_
== masks_to_bounds
)
487 masks_to_bounds_
= masks_to_bounds
;
491 void Layer::SetMaskLayer(Layer
* mask_layer
) {
492 DCHECK(IsPropertyChangeAllowed());
493 if (mask_layer_
.get() == mask_layer
)
495 if (mask_layer_
.get()) {
496 DCHECK_EQ(this, mask_layer_
->parent());
497 mask_layer_
->RemoveFromParent();
499 mask_layer_
= mask_layer
;
500 if (mask_layer_
.get()) {
501 DCHECK(!mask_layer_
->parent());
502 mask_layer_
->RemoveFromParent();
503 mask_layer_
->SetParent(this);
504 mask_layer_
->SetIsMask(true);
506 SetNeedsFullTreeSync();
509 void Layer::SetReplicaLayer(Layer
* layer
) {
510 DCHECK(IsPropertyChangeAllowed());
511 if (replica_layer_
.get() == layer
)
513 if (replica_layer_
.get()) {
514 DCHECK_EQ(this, replica_layer_
->parent());
515 replica_layer_
->RemoveFromParent();
517 replica_layer_
= layer
;
518 if (replica_layer_
.get()) {
519 DCHECK(!replica_layer_
->parent());
520 replica_layer_
->RemoveFromParent();
521 replica_layer_
->SetParent(this);
523 SetNeedsFullTreeSync();
526 void Layer::SetFilters(const FilterOperations
& filters
) {
527 DCHECK(IsPropertyChangeAllowed());
528 if (filters_
== filters
)
534 bool Layer::FilterIsAnimating() const {
535 return layer_animation_controller_
->IsAnimatingProperty(Animation::FILTER
);
538 void Layer::SetBackgroundFilters(const FilterOperations
& filters
) {
539 DCHECK(IsPropertyChangeAllowed());
540 if (background_filters_
== filters
)
542 background_filters_
= filters
;
546 void Layer::SetOpacity(float opacity
) {
547 DCHECK(IsPropertyChangeAllowed());
548 if (opacity_
== opacity
)
554 bool Layer::OpacityIsAnimating() const {
555 return layer_animation_controller_
->IsAnimatingProperty(Animation::OPACITY
);
558 bool Layer::OpacityCanAnimateOnImplThread() const {
562 void Layer::SetBlendMode(SkXfermode::Mode blend_mode
) {
563 DCHECK(IsPropertyChangeAllowed());
564 if (blend_mode_
== blend_mode
)
567 // Allowing only blend modes that are defined in the CSS Compositing standard:
568 // http://dev.w3.org/fxtf/compositing-1/#blending
569 switch (blend_mode
) {
570 case SkXfermode::kSrcOver_Mode
:
571 case SkXfermode::kScreen_Mode
:
572 case SkXfermode::kOverlay_Mode
:
573 case SkXfermode::kDarken_Mode
:
574 case SkXfermode::kLighten_Mode
:
575 case SkXfermode::kColorDodge_Mode
:
576 case SkXfermode::kColorBurn_Mode
:
577 case SkXfermode::kHardLight_Mode
:
578 case SkXfermode::kSoftLight_Mode
:
579 case SkXfermode::kDifference_Mode
:
580 case SkXfermode::kExclusion_Mode
:
581 case SkXfermode::kMultiply_Mode
:
582 case SkXfermode::kHue_Mode
:
583 case SkXfermode::kSaturation_Mode
:
584 case SkXfermode::kColor_Mode
:
585 case SkXfermode::kLuminosity_Mode
:
586 // supported blend modes
588 case SkXfermode::kClear_Mode
:
589 case SkXfermode::kSrc_Mode
:
590 case SkXfermode::kDst_Mode
:
591 case SkXfermode::kDstOver_Mode
:
592 case SkXfermode::kSrcIn_Mode
:
593 case SkXfermode::kDstIn_Mode
:
594 case SkXfermode::kSrcOut_Mode
:
595 case SkXfermode::kDstOut_Mode
:
596 case SkXfermode::kSrcATop_Mode
:
597 case SkXfermode::kDstATop_Mode
:
598 case SkXfermode::kXor_Mode
:
599 case SkXfermode::kPlus_Mode
:
600 case SkXfermode::kModulate_Mode
:
601 // Porter Duff Compositing Operators are not yet supported
602 // http://dev.w3.org/fxtf/compositing-1/#porterduffcompositingoperators
607 blend_mode_
= blend_mode
;
611 void Layer::SetIsRootForIsolatedGroup(bool root
) {
612 DCHECK(IsPropertyChangeAllowed());
613 if (is_root_for_isolated_group_
== root
)
615 is_root_for_isolated_group_
= root
;
619 void Layer::SetContentsOpaque(bool opaque
) {
620 DCHECK(IsPropertyChangeAllowed());
621 if (contents_opaque_
== opaque
)
623 contents_opaque_
= opaque
;
627 void Layer::SetPosition(const gfx::PointF
& position
) {
628 DCHECK(IsPropertyChangeAllowed());
629 if (position_
== position
)
631 position_
= position
;
633 if (!layer_tree_host_
)
636 if (TransformNode
* transform_node
=
637 layer_tree_host_
->property_trees()->transform_tree
.Node(
638 transform_tree_index())) {
639 if (transform_node
->owner_id
== id()) {
640 transform_node
->data
.update_post_local_transform(position
,
642 transform_node
->data
.needs_local_transform_update
= true;
643 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
644 SetNeedsCommitNoRebuild();
652 bool Layer::IsContainerForFixedPositionLayers() const {
653 if (!transform_
.IsIdentityOrTranslation())
655 if (parent_
&& !parent_
->transform_
.IsIdentityOrTranslation())
657 return is_container_for_fixed_position_layers_
;
660 bool Are2dAxisAligned(const gfx::Transform
& a
,
661 const gfx::Transform
& b
,
662 bool* is_invertible
) {
663 if (a
.IsScaleOrTranslation() && b
.IsScaleOrTranslation()) {
664 *is_invertible
= b
.IsInvertible();
668 gfx::Transform
inverse(gfx::Transform::kSkipInitialization
);
669 *is_invertible
= b
.GetInverse(&inverse
);
672 return inverse
.Preserves2dAxisAlignment();
675 void Layer::SetTransform(const gfx::Transform
& transform
) {
676 DCHECK(IsPropertyChangeAllowed());
677 if (transform_
== transform
)
680 if (layer_tree_host_
) {
681 if (TransformNode
* transform_node
=
682 layer_tree_host_
->property_trees()->transform_tree
.Node(
683 transform_tree_index())) {
684 if (transform_node
->owner_id
== id()) {
685 // We need to trigger a rebuild if we could have affected 2d axis
686 // alignment. We'll check to see if transform and transform_ are axis
687 // align with respect to one another.
688 bool invertible
= false;
689 bool preserves_2d_axis_alignment
=
690 Are2dAxisAligned(transform_
, transform
, &invertible
);
691 transform_node
->data
.local
= transform
;
692 transform_node
->data
.needs_local_transform_update
= true;
693 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(
695 if (preserves_2d_axis_alignment
)
696 SetNeedsCommitNoRebuild();
699 transform_
= transform
;
700 transform_is_invertible_
= invertible
;
706 transform_
= transform
;
707 transform_is_invertible_
= transform
.IsInvertible();
712 void Layer::SetTransformOrigin(const gfx::Point3F
& transform_origin
) {
713 DCHECK(IsPropertyChangeAllowed());
714 if (transform_origin_
== transform_origin
)
716 transform_origin_
= transform_origin
;
718 if (!layer_tree_host_
)
721 if (TransformNode
* transform_node
=
722 layer_tree_host_
->property_trees()->transform_tree
.Node(
723 transform_tree_index())) {
724 if (transform_node
->owner_id
== id()) {
725 transform_node
->data
.update_pre_local_transform(transform_origin
);
726 transform_node
->data
.update_post_local_transform(position(),
728 transform_node
->data
.needs_local_transform_update
= true;
729 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
730 SetNeedsCommitNoRebuild();
738 bool Layer::AnimationsPreserveAxisAlignment() const {
739 return layer_animation_controller_
->AnimationsPreserveAxisAlignment();
742 bool Layer::TransformIsAnimating() const {
743 return layer_animation_controller_
->IsAnimatingProperty(Animation::TRANSFORM
);
746 void Layer::SetScrollParent(Layer
* parent
) {
747 DCHECK(IsPropertyChangeAllowed());
748 if (scroll_parent_
== parent
)
752 scroll_parent_
->RemoveScrollChild(this);
754 scroll_parent_
= parent
;
757 scroll_parent_
->AddScrollChild(this);
762 void Layer::AddScrollChild(Layer
* child
) {
763 if (!scroll_children_
)
764 scroll_children_
.reset(new std::set
<Layer
*>);
765 scroll_children_
->insert(child
);
766 if (layer_tree_host_
&& !layer_tree_host_
->needs_meta_info_recomputation()) {
767 num_children_with_scroll_parent_
++;
768 draw_properties().has_child_with_a_scroll_parent
= true;
773 void Layer::RemoveScrollChild(Layer
* child
) {
774 scroll_children_
->erase(child
);
775 if (scroll_children_
->empty())
776 scroll_children_
= nullptr;
777 if (layer_tree_host_
&& !layer_tree_host_
->needs_meta_info_recomputation()) {
778 num_children_with_scroll_parent_
--;
779 DCHECK_GE(num_children_with_scroll_parent_
, 0);
780 draw_properties().has_child_with_a_scroll_parent
=
781 (num_children_with_scroll_parent_
!= 0);
786 void Layer::SetClipParent(Layer
* ancestor
) {
787 DCHECK(IsPropertyChangeAllowed());
788 if (clip_parent_
== ancestor
)
792 clip_parent_
->RemoveClipChild(this);
794 clip_parent_
= ancestor
;
797 clip_parent_
->AddClipChild(this);
800 if (layer_tree_host_
)
801 layer_tree_host_
->SetNeedsMetaInfoRecomputation(true);
804 void Layer::AddClipChild(Layer
* child
) {
806 clip_children_
.reset(new std::set
<Layer
*>);
807 clip_children_
->insert(child
);
811 void Layer::RemoveClipChild(Layer
* child
) {
812 clip_children_
->erase(child
);
813 if (clip_children_
->empty())
814 clip_children_
= nullptr;
818 void Layer::SetScrollOffset(const gfx::ScrollOffset
& scroll_offset
) {
819 DCHECK(IsPropertyChangeAllowed());
821 if (scroll_offset_
== scroll_offset
)
823 scroll_offset_
= scroll_offset
;
825 if (!layer_tree_host_
)
828 if (TransformNode
* transform_node
=
829 layer_tree_host_
->property_trees()->transform_tree
.Node(
830 transform_tree_index())) {
831 if (transform_node
->owner_id
== id()) {
832 transform_node
->data
.scroll_offset
= CurrentScrollOffset();
833 transform_node
->data
.needs_local_transform_update
= true;
834 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
835 SetNeedsCommitNoRebuild();
843 void Layer::SetScrollCompensationAdjustment(
844 const gfx::Vector2dF
& scroll_compensation_adjustment
) {
845 if (scroll_compensation_adjustment_
== scroll_compensation_adjustment
)
847 scroll_compensation_adjustment_
= scroll_compensation_adjustment
;
851 gfx::Vector2dF
Layer::ScrollCompensationAdjustment() const {
852 return scroll_compensation_adjustment_
;
855 void Layer::SetScrollOffsetFromImplSide(
856 const gfx::ScrollOffset
& scroll_offset
) {
857 DCHECK(IsPropertyChangeAllowed());
858 // This function only gets called during a BeginMainFrame, so there
859 // is no need to call SetNeedsUpdate here.
860 DCHECK(layer_tree_host_
&& layer_tree_host_
->CommitRequested());
861 if (scroll_offset_
== scroll_offset
)
863 scroll_offset_
= scroll_offset
;
864 SetNeedsPushProperties();
866 bool needs_rebuild
= true;
867 if (TransformNode
* transform_node
=
868 layer_tree_host_
->property_trees()->transform_tree
.Node(
869 transform_tree_index())) {
870 if (transform_node
->owner_id
== id()) {
871 transform_node
->data
.scroll_offset
= CurrentScrollOffset();
872 transform_node
->data
.needs_local_transform_update
= true;
873 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(true);
874 needs_rebuild
= false;
879 layer_tree_host_
->property_trees()->needs_rebuild
= true;
881 if (!did_scroll_callback_
.is_null())
882 did_scroll_callback_
.Run();
883 // The callback could potentially change the layer structure:
884 // "this" may have been destroyed during the process.
887 void Layer::SetScrollClipLayerId(int clip_layer_id
) {
888 DCHECK(IsPropertyChangeAllowed());
889 if (scroll_clip_layer_id_
== clip_layer_id
)
891 scroll_clip_layer_id_
= clip_layer_id
;
895 void Layer::SetUserScrollable(bool horizontal
, bool vertical
) {
896 DCHECK(IsPropertyChangeAllowed());
897 if (user_scrollable_horizontal_
== horizontal
&&
898 user_scrollable_vertical_
== vertical
)
900 user_scrollable_horizontal_
= horizontal
;
901 user_scrollable_vertical_
= vertical
;
905 void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
906 DCHECK(IsPropertyChangeAllowed());
907 if (should_scroll_on_main_thread_
== should_scroll_on_main_thread
)
909 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
913 void Layer::SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
914 DCHECK(IsPropertyChangeAllowed());
915 if (have_wheel_event_handlers_
== have_wheel_event_handlers
)
917 if (touch_event_handler_region_
.IsEmpty() && layer_tree_host_
&&
918 !layer_tree_host_
->needs_meta_info_recomputation())
919 UpdateNumInputHandlersForSubtree(have_wheel_event_handlers
);
921 have_wheel_event_handlers_
= have_wheel_event_handlers
;
925 void Layer::UpdateNumInputHandlersForSubtree(bool add
) {
926 int change
= add
? 1 : -1;
927 for (Layer
* layer
= this; layer
; layer
= layer
->parent()) {
928 layer
->num_layer_or_descendants_with_input_handler_
+= change
;
929 layer
->draw_properties().layer_or_descendant_has_input_handler
=
930 (layer
->num_layer_or_descendants_with_input_handler_
!= 0);
931 DCHECK_GE(layer
->num_layer_or_descendants_with_input_handler_
, 0);
935 void Layer::SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
936 DCHECK(IsPropertyChangeAllowed());
937 if (have_scroll_event_handlers_
== have_scroll_event_handlers
)
939 have_scroll_event_handlers_
= have_scroll_event_handlers
;
943 void Layer::SetNonFastScrollableRegion(const Region
& region
) {
944 DCHECK(IsPropertyChangeAllowed());
945 if (non_fast_scrollable_region_
== region
)
947 non_fast_scrollable_region_
= region
;
951 void Layer::SetTouchEventHandlerRegion(const Region
& region
) {
952 DCHECK(IsPropertyChangeAllowed());
953 if (touch_event_handler_region_
== region
)
955 if (!have_wheel_event_handlers_
&& layer_tree_host_
&&
956 !layer_tree_host_
->needs_meta_info_recomputation())
957 UpdateNumInputHandlersForSubtree(!region
.IsEmpty());
959 touch_event_handler_region_
= region
;
963 void Layer::SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
964 DCHECK(IsPropertyChangeAllowed());
965 if (scroll_blocks_on_
== scroll_blocks_on
)
967 scroll_blocks_on_
= scroll_blocks_on
;
971 void Layer::SetDrawCheckerboardForMissingTiles(bool checkerboard
) {
972 DCHECK(IsPropertyChangeAllowed());
973 if (draw_checkerboard_for_missing_tiles_
== checkerboard
)
975 draw_checkerboard_for_missing_tiles_
= checkerboard
;
979 void Layer::SetForceRenderSurface(bool force
) {
980 DCHECK(IsPropertyChangeAllowed());
981 if (force_render_surface_
== force
)
983 force_render_surface_
= force
;
987 void Layer::SetDoubleSided(bool double_sided
) {
988 DCHECK(IsPropertyChangeAllowed());
989 if (double_sided_
== double_sided
)
991 double_sided_
= double_sided
;
995 void Layer::Set3dSortingContextId(int id
) {
996 DCHECK(IsPropertyChangeAllowed());
997 if (id
== sorting_context_id_
)
999 sorting_context_id_
= id
;
1003 void Layer::SetTransformTreeIndex(int index
) {
1004 DCHECK(IsPropertyChangeAllowed());
1005 if (transform_tree_index_
== index
)
1007 transform_tree_index_
= index
;
1008 SetNeedsPushProperties();
1011 int Layer::transform_tree_index() const {
1012 if (!layer_tree_host_
||
1013 layer_tree_host_
->property_trees()->sequence_number
!=
1014 property_tree_sequence_number_
) {
1017 return transform_tree_index_
;
1020 void Layer::SetClipTreeIndex(int index
) {
1021 DCHECK(IsPropertyChangeAllowed());
1022 if (clip_tree_index_
== index
)
1024 clip_tree_index_
= index
;
1025 SetNeedsPushProperties();
1028 int Layer::clip_tree_index() const {
1029 if (!layer_tree_host_
||
1030 layer_tree_host_
->property_trees()->sequence_number
!=
1031 property_tree_sequence_number_
) {
1034 return clip_tree_index_
;
1037 void Layer::SetOpacityTreeIndex(int index
) {
1038 DCHECK(IsPropertyChangeAllowed());
1039 if (opacity_tree_index_
== index
)
1041 opacity_tree_index_
= index
;
1042 SetNeedsPushProperties();
1045 int Layer::opacity_tree_index() const {
1046 if (!layer_tree_host_
||
1047 layer_tree_host_
->property_trees()->sequence_number
!=
1048 property_tree_sequence_number_
) {
1051 return opacity_tree_index_
;
1054 void Layer::SetShouldFlattenTransform(bool should_flatten
) {
1055 DCHECK(IsPropertyChangeAllowed());
1056 if (should_flatten_transform_
== should_flatten
)
1058 should_flatten_transform_
= should_flatten
;
1062 void Layer::SetIsDrawable(bool is_drawable
) {
1063 DCHECK(IsPropertyChangeAllowed());
1064 if (is_drawable_
== is_drawable
)
1067 is_drawable_
= is_drawable
;
1068 UpdateDrawsContent(HasDrawableContent());
1071 void Layer::SetHideLayerAndSubtree(bool hide
) {
1072 DCHECK(IsPropertyChangeAllowed());
1073 if (hide_layer_and_subtree_
== hide
)
1076 hide_layer_and_subtree_
= hide
;
1080 void Layer::SetNeedsDisplayRect(const gfx::Rect
& dirty_rect
) {
1081 if (dirty_rect
.IsEmpty())
1084 SetNeedsPushProperties();
1085 update_rect_
.Union(dirty_rect
);
1091 bool Layer::DescendantIsFixedToContainerLayer() const {
1092 for (size_t i
= 0; i
< children_
.size(); ++i
) {
1093 if (children_
[i
]->position_constraint_
.is_fixed_position() ||
1094 children_
[i
]->DescendantIsFixedToContainerLayer())
1100 void Layer::SetIsContainerForFixedPositionLayers(bool container
) {
1101 if (is_container_for_fixed_position_layers_
== container
)
1103 is_container_for_fixed_position_layers_
= container
;
1105 if (layer_tree_host_
&& layer_tree_host_
->CommitRequested())
1108 // Only request a commit if we have a fixed positioned descendant.
1109 if (DescendantIsFixedToContainerLayer())
1113 void Layer::SetPositionConstraint(const LayerPositionConstraint
& constraint
) {
1114 DCHECK(IsPropertyChangeAllowed());
1115 if (position_constraint_
== constraint
)
1117 position_constraint_
= constraint
;
1121 static void RunCopyCallbackOnMainThread(scoped_ptr
<CopyOutputRequest
> request
,
1122 scoped_ptr
<CopyOutputResult
> result
) {
1123 request
->SendResult(result
.Pass());
1126 static void PostCopyCallbackToMainThread(
1127 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
,
1128 scoped_ptr
<CopyOutputRequest
> request
,
1129 scoped_ptr
<CopyOutputResult
> result
) {
1130 main_thread_task_runner
->PostTask(FROM_HERE
,
1131 base::Bind(&RunCopyCallbackOnMainThread
,
1132 base::Passed(&request
),
1133 base::Passed(&result
)));
1136 void Layer::PushPropertiesTo(LayerImpl
* layer
) {
1137 DCHECK(layer_tree_host_
);
1139 // If we did not SavePaintProperties() for the layer this frame, then push the
1140 // real property values, not the paint property values.
1141 bool use_paint_properties
= paint_properties_
.source_frame_number
==
1142 layer_tree_host_
->source_frame_number();
1144 layer
->SetTransformOrigin(transform_origin_
);
1145 layer
->SetBackgroundColor(background_color_
);
1146 layer
->SetBounds(use_paint_properties
? paint_properties_
.bounds
1149 // TODO(enne): This is needed because CDP does this. Once main thread CDP
1150 // goes away, content scale / bounds can be removed.
1151 if (layer_tree_host()->settings().impl_side_painting
) {
1152 layer
->SetContentsScale(1.f
, 1.f
);
1153 layer
->SetContentBounds(bounds());
1155 layer
->SetContentBounds(content_bounds());
1156 layer
->SetContentsScale(contents_scale_x(), contents_scale_y());
1159 if (frame_viewer_instrumentation::IsTracingLayerTreeSnapshots())
1160 layer
->SetDebugInfo(TakeDebugInfo());
1162 layer
->SetTransformTreeIndex(transform_tree_index());
1163 layer
->SetOpacityTreeIndex(opacity_tree_index());
1164 layer
->SetClipTreeIndex(clip_tree_index());
1165 layer
->set_offset_to_transform_parent(offset_to_transform_parent_
);
1166 layer
->SetDoubleSided(double_sided_
);
1167 layer
->SetDrawCheckerboardForMissingTiles(
1168 draw_checkerboard_for_missing_tiles_
);
1169 layer
->SetDrawsContent(DrawsContent());
1170 layer
->SetHideLayerAndSubtree(hide_layer_and_subtree_
);
1171 layer
->SetHasRenderSurface(has_render_surface_
|| layer
->HasCopyRequest());
1172 if (!layer
->FilterIsAnimatingOnImplOnly() && !FilterIsAnimating())
1173 layer
->SetFilters(filters_
);
1174 DCHECK(!(FilterIsAnimating() && layer
->FilterIsAnimatingOnImplOnly()));
1175 layer
->SetBackgroundFilters(background_filters());
1176 layer
->SetMasksToBounds(masks_to_bounds_
);
1177 layer
->SetShouldScrollOnMainThread(should_scroll_on_main_thread_
);
1178 layer
->SetHaveWheelEventHandlers(have_wheel_event_handlers_
);
1179 layer
->SetHaveScrollEventHandlers(have_scroll_event_handlers_
);
1180 layer
->SetNonFastScrollableRegion(non_fast_scrollable_region_
);
1181 layer
->SetTouchEventHandlerRegion(touch_event_handler_region_
);
1182 layer
->SetScrollBlocksOn(scroll_blocks_on_
);
1183 layer
->SetContentsOpaque(contents_opaque_
);
1184 if (!layer
->OpacityIsAnimatingOnImplOnly() && !OpacityIsAnimating()) {
1185 layer
->SetOpacity(opacity_
);
1187 // The just-pushed opacity tree will contain |opacity_|. Since we didn't
1188 // push this value to |layer|, it might have a different opacity value. To
1189 // ensure consistency, we need to update the opacity tree.
1190 layer
->UpdatePropertyTreeOpacity();
1192 DCHECK(!(OpacityIsAnimating() && layer
->OpacityIsAnimatingOnImplOnly()));
1193 layer
->SetBlendMode(blend_mode_
);
1194 layer
->SetIsRootForIsolatedGroup(is_root_for_isolated_group_
);
1195 layer
->SetPosition(position_
);
1196 layer
->SetIsContainerForFixedPositionLayers(
1197 IsContainerForFixedPositionLayers());
1198 layer
->SetPositionConstraint(position_constraint_
);
1199 layer
->SetShouldFlattenTransform(should_flatten_transform_
);
1200 layer
->set_should_flatten_transform_from_property_tree(
1201 should_flatten_transform_from_property_tree_
);
1202 layer
->SetUseParentBackfaceVisibility(use_parent_backface_visibility_
);
1203 if (!layer
->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating()) {
1204 layer
->SetTransformAndInvertibility(transform_
, transform_is_invertible_
);
1206 // The just-pushed transform tree will contain |transform_|. Since we
1207 // didn't push this value to |layer|, it might have a different transform
1208 // value. To ensure consistency, we need to update the transform tree.
1209 layer
->UpdatePropertyTreeTransform();
1211 DCHECK(!(TransformIsAnimating() && layer
->TransformIsAnimatingOnImplOnly()));
1212 layer
->Set3dSortingContextId(sorting_context_id_
);
1213 layer
->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_
);
1215 layer
->SetScrollClipLayer(scroll_clip_layer_id_
);
1216 layer
->set_user_scrollable_horizontal(user_scrollable_horizontal_
);
1217 layer
->set_user_scrollable_vertical(user_scrollable_vertical_
);
1219 LayerImpl
* scroll_parent
= nullptr;
1220 if (scroll_parent_
) {
1221 scroll_parent
= layer
->layer_tree_impl()->LayerById(scroll_parent_
->id());
1222 DCHECK(scroll_parent
);
1225 layer
->SetScrollParent(scroll_parent
);
1226 if (scroll_children_
) {
1227 std::set
<LayerImpl
*>* scroll_children
= new std::set
<LayerImpl
*>;
1228 for (std::set
<Layer
*>::iterator it
= scroll_children_
->begin();
1229 it
!= scroll_children_
->end();
1231 DCHECK_EQ((*it
)->scroll_parent(), this);
1232 LayerImpl
* scroll_child
=
1233 layer
->layer_tree_impl()->LayerById((*it
)->id());
1234 DCHECK(scroll_child
);
1235 scroll_children
->insert(scroll_child
);
1237 layer
->SetScrollChildren(scroll_children
);
1239 layer
->SetScrollChildren(nullptr);
1242 LayerImpl
* clip_parent
= nullptr;
1245 layer
->layer_tree_impl()->LayerById(clip_parent_
->id());
1246 DCHECK(clip_parent
);
1249 layer
->SetClipParent(clip_parent
);
1250 if (clip_children_
) {
1251 std::set
<LayerImpl
*>* clip_children
= new std::set
<LayerImpl
*>;
1252 for (std::set
<Layer
*>::iterator it
= clip_children_
->begin();
1253 it
!= clip_children_
->end(); ++it
) {
1254 DCHECK_EQ((*it
)->clip_parent(), this);
1255 LayerImpl
* clip_child
= layer
->layer_tree_impl()->LayerById((*it
)->id());
1257 clip_children
->insert(clip_child
);
1259 layer
->SetClipChildren(clip_children
);
1261 layer
->SetClipChildren(nullptr);
1264 // When a scroll offset animation is interrupted the new scroll position on
1265 // the pending tree will clobber any impl-side scrolling occuring on the
1266 // active tree. To do so, avoid scrolling the pending tree along with it
1267 // instead of trying to undo that scrolling later.
1268 if (layer_animation_controller_
->scroll_offset_animation_was_interrupted())
1269 layer
->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_
);
1271 layer
->PushScrollOffsetFromMainThread(scroll_offset_
);
1272 layer
->SetScrollCompensationAdjustment(ScrollCompensationAdjustment());
1274 // Wrap the copy_requests_ in a PostTask to the main thread.
1275 int size
= copy_requests_
.size();
1276 ScopedPtrVector
<CopyOutputRequest
> main_thread_copy_requests
;
1277 for (ScopedPtrVector
<CopyOutputRequest
>::iterator it
= copy_requests_
.begin();
1278 it
!= copy_requests_
.end();
1280 scoped_refptr
<base::SingleThreadTaskRunner
> main_thread_task_runner
=
1281 layer_tree_host()->proxy()->MainThreadTaskRunner();
1282 scoped_ptr
<CopyOutputRequest
> original_request
= copy_requests_
.take(it
);
1283 const CopyOutputRequest
& original_request_ref
= *original_request
;
1284 scoped_ptr
<CopyOutputRequest
> main_thread_request
=
1285 CopyOutputRequest::CreateRelayRequest(
1286 original_request_ref
,
1287 base::Bind(&PostCopyCallbackToMainThread
,
1288 main_thread_task_runner
,
1289 base::Passed(&original_request
)));
1290 main_thread_copy_requests
.push_back(main_thread_request
.Pass());
1292 if (!copy_requests_
.empty() && layer_tree_host_
)
1293 layer_tree_host_
->property_trees()->needs_rebuild
= true;
1295 UpdateNumCopyRequestsForSubtree(false);
1296 copy_requests_
.clear();
1297 layer
->PassCopyRequests(&main_thread_copy_requests
);
1299 // If the main thread commits multiple times before the impl thread actually
1300 // draws, then damage tracking will become incorrect if we simply clobber the
1301 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
1302 // union) any update changes that have occurred on the main thread.
1303 update_rect_
.Union(layer
->update_rect());
1304 layer
->SetUpdateRect(update_rect_
);
1306 layer
->SetStackingOrderChanged(stacking_order_changed_
);
1308 layer_animation_controller_
->PushAnimationUpdatesTo(
1309 layer
->layer_animation_controller());
1311 if (frame_timing_requests_dirty_
) {
1312 layer
->PassFrameTimingRequests(&frame_timing_requests_
);
1313 frame_timing_requests_dirty_
= false;
1316 // Reset any state that should be cleared for the next update.
1317 stacking_order_changed_
= false;
1318 update_rect_
= gfx::Rect();
1320 needs_push_properties_
= false;
1321 num_dependents_need_push_properties_
= 0;
1324 scoped_ptr
<LayerImpl
> Layer::CreateLayerImpl(LayerTreeImpl
* tree_impl
) {
1325 return LayerImpl::Create(tree_impl
, layer_id_
,
1326 new LayerImpl::SyncedScrollOffset
);
1329 bool Layer::DrawsContent() const {
1330 return draws_content_
;
1333 bool Layer::HasDrawableContent() const {
1334 return is_drawable_
;
1337 void Layer::UpdateDrawsContent(bool has_drawable_content
) {
1338 bool draws_content
= has_drawable_content
;
1339 DCHECK(is_drawable_
|| !has_drawable_content
);
1340 if (draws_content
== draws_content_
)
1343 if (HasDelegatedContent()) {
1344 // Layers with delegated content need to be treated as if they have as
1345 // many children as the number of layers they own delegated quads for.
1346 // Since we don't know this number right now, we choose one that acts like
1347 // infinity for our purposes.
1348 AddDrawableDescendants(draws_content
? 1000 : -1000);
1352 parent()->AddDrawableDescendants(draws_content
? 1 : -1);
1354 draws_content_
= draws_content
;
1358 int Layer::NumDescendantsThatDrawContent() const {
1359 return num_descendants_that_draw_content_
;
1362 void Layer::SavePaintProperties() {
1363 DCHECK(layer_tree_host_
);
1365 // TODO(reveman): Save all layer properties that we depend on not
1366 // changing until PushProperties() has been called. crbug.com/231016
1367 paint_properties_
.bounds
= bounds_
;
1368 paint_properties_
.source_frame_number
=
1369 layer_tree_host_
->source_frame_number();
1372 bool Layer::Update(ResourceUpdateQueue
* queue
,
1373 const OcclusionTracker
<Layer
>* occlusion
) {
1374 DCHECK(layer_tree_host_
);
1375 DCHECK_EQ(layer_tree_host_
->source_frame_number(),
1376 paint_properties_
.source_frame_number
) <<
1377 "SavePaintProperties must be called for any layer that is painted.";
1381 bool Layer::NeedMoreUpdates() {
1385 bool Layer::IsSuitableForGpuRasterization() const {
1389 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
>
1390 Layer::TakeDebugInfo() {
1392 return client_
->TakeDebugInfo();
1397 void Layer::SetHasRenderSurface(bool has_render_surface
) {
1398 if (has_render_surface_
== has_render_surface
)
1400 has_render_surface_
= has_render_surface
;
1401 // We do not need SetNeedsCommit here, since this is only ever called
1402 // during a commit, from CalculateDrawProperties.
1403 SetNeedsPushProperties();
1406 void Layer::CreateRenderSurface() {
1407 DCHECK(!render_surface_
);
1408 render_surface_
= make_scoped_ptr(new RenderSurface(this));
1411 void Layer::ClearRenderSurface() {
1412 render_surface_
= nullptr;
1415 void Layer::ClearRenderSurfaceLayerList() {
1416 if (render_surface_
)
1417 render_surface_
->ClearLayerLists();
1420 gfx::ScrollOffset
Layer::ScrollOffsetForAnimation() const {
1421 return CurrentScrollOffset();
1424 // On<Property>Animated is called due to an ongoing accelerated animation.
1425 // Since this animation is also being run on the compositor thread, there
1426 // is no need to request a commit to push this value over, so the value is
1427 // set directly rather than by calling Set<Property>.
1428 void Layer::OnFilterAnimated(const FilterOperations
& filters
) {
1432 void Layer::OnOpacityAnimated(float opacity
) {
1434 if (layer_tree_host_
) {
1435 if (OpacityNode
* node
=
1436 layer_tree_host_
->property_trees()->opacity_tree
.Node(
1437 opacity_tree_index())) {
1438 if (node
->owner_id
== id())
1439 node
->data
= opacity
;
1444 void Layer::OnTransformAnimated(const gfx::Transform
& transform
) {
1445 if (transform_
== transform
)
1447 transform_
= transform
;
1448 transform_is_invertible_
= transform
.IsInvertible();
1449 if (layer_tree_host_
) {
1450 if (TransformNode
* node
=
1451 layer_tree_host_
->property_trees()->transform_tree
.Node(
1452 transform_tree_index())) {
1453 if (node
->owner_id
== id()) {
1454 node
->data
.local
= transform
;
1455 node
->data
.needs_local_transform_update
= true;
1456 node
->data
.is_animated
= true;
1457 layer_tree_host_
->property_trees()->transform_tree
.set_needs_update(
1464 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) {
1465 // Do nothing. Scroll deltas will be sent from the compositor thread back
1466 // to the main thread in the same manner as during non-animated
1467 // compositor-driven scrolling.
1470 void Layer::OnAnimationWaitingForDeletion() {
1471 // Animations are only deleted during PushProperties.
1472 SetNeedsPushProperties();
1475 bool Layer::IsActive() const {
1479 bool Layer::AddAnimation(scoped_ptr
<Animation
> animation
) {
1480 if (!layer_animation_controller_
->animation_registrar())
1483 if (animation
->target_property() == Animation::SCROLL_OFFSET
&&
1484 !layer_animation_controller_
->animation_registrar()
1485 ->supports_scroll_animations())
1488 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer",
1490 layer_animation_controller_
->AddAnimation(animation
.Pass());
1495 void Layer::PauseAnimation(int animation_id
, double time_offset
) {
1496 layer_animation_controller_
->PauseAnimation(
1497 animation_id
, base::TimeDelta::FromSecondsD(time_offset
));
1501 void Layer::RemoveAnimation(int animation_id
) {
1502 layer_animation_controller_
->RemoveAnimation(animation_id
);
1506 void Layer::RemoveAnimation(int animation_id
,
1507 Animation::TargetProperty property
) {
1508 layer_animation_controller_
->RemoveAnimation(animation_id
, property
);
1512 void Layer::SetLayerAnimationControllerForTest(
1513 scoped_refptr
<LayerAnimationController
> controller
) {
1514 layer_animation_controller_
->RemoveValueObserver(this);
1515 layer_animation_controller_
= controller
;
1516 layer_animation_controller_
->AddValueObserver(this);
1520 bool Layer::HasActiveAnimation() const {
1521 return layer_animation_controller_
->HasActiveAnimation();
1524 void Layer::AddLayerAnimationEventObserver(
1525 LayerAnimationEventObserver
* animation_observer
) {
1526 layer_animation_controller_
->AddEventObserver(animation_observer
);
1529 void Layer::RemoveLayerAnimationEventObserver(
1530 LayerAnimationEventObserver
* animation_observer
) {
1531 layer_animation_controller_
->RemoveEventObserver(animation_observer
);
1534 SimpleEnclosedRegion
Layer::VisibleContentOpaqueRegion() const {
1535 if (contents_opaque())
1536 return SimpleEnclosedRegion(visible_content_rect());
1537 return SimpleEnclosedRegion();
1540 ScrollbarLayerInterface
* Layer::ToScrollbarLayer() {
1544 RenderingStatsInstrumentation
* Layer::rendering_stats_instrumentation() const {
1545 return layer_tree_host_
->rendering_stats_instrumentation();
1548 void Layer::RemoveFromScrollTree() {
1549 if (scroll_children_
.get()) {
1550 std::set
<Layer
*> copy
= *scroll_children_
;
1551 for (std::set
<Layer
*>::iterator it
= copy
.begin(); it
!= copy
.end(); ++it
)
1552 (*it
)->SetScrollParent(nullptr);
1555 DCHECK(!scroll_children_
);
1556 SetScrollParent(nullptr);
1559 void Layer::RemoveFromClipTree() {
1560 if (clip_children_
.get()) {
1561 std::set
<Layer
*> copy
= *clip_children_
;
1562 for (std::set
<Layer
*>::iterator it
= copy
.begin(); it
!= copy
.end(); ++it
)
1563 (*it
)->SetClipParent(nullptr);
1566 DCHECK(!clip_children_
);
1567 SetClipParent(nullptr);
1570 void Layer::AddDrawableDescendants(int num
) {
1571 DCHECK_GE(num_descendants_that_draw_content_
, 0);
1572 DCHECK_GE(num_descendants_that_draw_content_
+ num
, 0);
1575 num_descendants_that_draw_content_
+= num
;
1578 parent()->AddDrawableDescendants(num
);
1581 void Layer::RunMicroBenchmark(MicroBenchmark
* benchmark
) {
1582 benchmark
->RunOnLayer(this);
1585 bool Layer::HasDelegatedContent() const {
1589 void Layer::SetFrameTimingRequests(
1590 const std::vector
<FrameTimingRequest
>& requests
) {
1591 frame_timing_requests_
= requests
;
1592 frame_timing_requests_dirty_
= true;
1596 void Layer::DidBeginTracing() {
1597 // We'll be dumping layer trees as part of trace, so make sure
1598 // PushPropertiesTo() propagates layer debug info to the impl
1599 // side -- otherwise this won't happen for the the layers that
1600 // remain unchanged since tracing started.
1601 SetNeedsPushProperties();
1604 void Layer::set_visited(bool visited
) {
1606 visited
? layer_tree_host()->meta_information_sequence_number() : 0;
1609 bool Layer::visited() {
1610 return visited_tracker_
==
1611 layer_tree_host()->meta_information_sequence_number();
1614 void Layer::set_layer_or_descendant_is_drawn(
1615 bool layer_or_descendant_is_drawn
) {
1616 layer_or_descendant_is_drawn_tracker_
=
1617 layer_or_descendant_is_drawn
1618 ? layer_tree_host()->meta_information_sequence_number()
1622 bool Layer::layer_or_descendant_is_drawn() {
1623 return layer_or_descendant_is_drawn_tracker_
==
1624 layer_tree_host()->meta_information_sequence_number();
1627 void Layer::set_sorted_for_recursion(bool sorted_for_recursion
) {
1628 sorted_for_recursion_tracker_
=
1629 sorted_for_recursion
1630 ? layer_tree_host()->meta_information_sequence_number()
1634 bool Layer::sorted_for_recursion() {
1635 return sorted_for_recursion_tracker_
==
1636 layer_tree_host()->meta_information_sequence_number();