Revert "Reland c91b178b07b0d - Delete dead signin code (SigninGlobalError)"
[chromium-blink-merge.git] / cc / layers / layer.cc
blob279d0d5ca3a93df48a896dd8e5754fe3e6e0ab42
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"
7 #include <algorithm>
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"
33 namespace cc {
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),
49 parent_(nullptr),
50 layer_tree_host_(nullptr),
51 scroll_clip_layer_id_(INVALID_ID),
52 num_descendants_that_draw_content_(0),
53 transform_tree_index_(-1),
54 effect_tree_index_(-1),
55 clip_tree_index_(-1),
56 property_tree_sequence_number_(-1),
57 num_layer_or_descendants_with_copy_request_(0),
58 num_children_with_scroll_parent_(0),
59 should_flatten_transform_from_property_tree_(false),
60 is_clipped_(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),
68 is_drawable_(false),
69 draws_content_(false),
70 hide_layer_and_subtree_(false),
71 masks_to_bounds_(false),
72 contents_opaque_(false),
73 double_sided_(true),
74 should_flatten_transform_(true),
75 use_parent_backface_visibility_(false),
76 force_render_surface_(false),
77 transform_is_invertible_(true),
78 has_render_surface_(false),
79 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE),
80 background_color_(0),
81 opacity_(1.f),
82 blend_mode_(SkXfermode::kSrcOver_Mode),
83 draw_blend_mode_(SkXfermode::kSrcOver_Mode),
84 scroll_parent_(nullptr),
85 layer_or_descendant_is_drawn_tracker_(0),
86 sorted_for_recursion_tracker_(0),
87 visited_tracker_(0),
88 clip_parent_(nullptr),
89 replica_layer_(nullptr),
90 client_(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);
99 Layer::~Layer() {
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.
102 DCHECK(!parent());
103 // Similarly we shouldn't have a layer tree host since it also keeps a
104 // reference to us.
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.
116 RemoveAllChildren();
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)
129 return;
131 if (layer_tree_host_) {
132 layer_tree_host_->property_trees()->needs_rebuild = true;
133 layer_tree_host_->UnregisterLayer(this);
135 if (host) {
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);
156 if (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_)
176 return;
178 SetNeedsPushProperties();
179 layer_tree_host_->property_trees()->needs_rebuild = true;
181 if (ignore_set_needs_commit_)
182 return;
184 layer_tree_host_->SetNeedsCommit();
187 void Layer::SetNeedsCommitNoRebuild() {
188 if (!layer_tree_host_)
189 return;
191 SetNeedsPushProperties();
193 if (ignore_set_needs_commit_)
194 return;
196 layer_tree_host_->SetNeedsCommit();
199 void Layer::SetNeedsFullTreeSync() {
200 if (!layer_tree_host_)
201 return;
203 layer_tree_host_->SetNeedsFullTreeSync();
206 void Layer::SetNextCommitWaitsForActivation() {
207 if (!layer_tree_host_)
208 return;
210 layer_tree_host_->SetNextCommitWaitsForActivation();
213 void Layer::SetNeedsPushProperties() {
214 if (needs_push_properties_)
215 return;
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_)
240 return true;
242 if (!layer_tree_host_->settings().strict_layer_property_change_checking)
243 return true;
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()) {
256 if (parent_)
257 parent_->RemoveDependentNeedsPushProperties();
258 if (layer)
259 layer->AddDependentNeedsPushProperties();
262 parent_ = layer;
263 SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : nullptr);
265 if (!layer_tree_host_)
266 return;
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());
290 if (parent_)
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();
299 return;
301 if (replica_layer_.get() == child) {
302 replica_layer_->SetParent(nullptr);
303 replica_layer_ = nullptr;
304 SetNeedsFullTreeSync();
305 return;
308 for (LayerList::iterator iter = children_.begin();
309 iter != children_.end();
310 ++iter) {
311 if (iter->get() != child)
312 continue;
314 child->SetParent(nullptr);
315 AddDrawableDescendants(-child->NumDescendantsThatDrawContent() -
316 (child->DrawsContent() ? 1 : 0));
317 children_.erase(iter);
318 SetNeedsFullTreeSync();
319 return;
323 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) {
324 DCHECK(reference);
325 DCHECK_EQ(reference->parent(), this);
326 DCHECK(IsPropertyChangeAllowed());
328 if (reference == new_layer.get())
329 return;
331 // Find the index of |reference| in |children_|.
332 auto reference_it =
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)
350 return;
351 bounds_ = size;
353 if (!layer_tree_host_)
354 return;
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() {
368 Layer* layer = this;
369 while (layer->parent())
370 layer = layer->parent();
371 return layer;
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_)
386 return;
388 RemoveAllChildren();
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)
396 return true;
398 return false;
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())
413 return;
414 copy_requests_.push_back(request.Pass());
415 if (had_no_copy_requests) {
416 bool copy_request_added = true;
417 UpdateNumCopyRequestsForSubtree(copy_request_added);
419 SetNeedsCommit();
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)
435 return;
436 background_color_ = background_color;
437 SetNeedsCommit();
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)
449 break;
451 if (SkColorGetA(color) != 255)
452 color = layer_tree_host_->background_color();
453 if (SkColorGetA(color) != 255)
454 color = SkColorSetA(color, 255);
456 return color;
459 void Layer::SetMasksToBounds(bool masks_to_bounds) {
460 DCHECK(IsPropertyChangeAllowed());
461 if (masks_to_bounds_ == masks_to_bounds)
462 return;
463 masks_to_bounds_ = masks_to_bounds;
464 SetNeedsCommit();
467 void Layer::SetMaskLayer(Layer* mask_layer) {
468 DCHECK(IsPropertyChangeAllowed());
469 if (mask_layer_.get() == mask_layer)
470 return;
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)
488 return;
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)
505 return;
506 filters_ = filters;
507 SetNeedsCommit();
510 bool Layer::FilterIsAnimating() const {
511 DCHECK(layer_tree_host_);
512 return layer_animation_controller_
513 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
514 Animation::FILTER,
515 LayerAnimationController::ObserverType::ACTIVE)
516 : layer_tree_host_->IsAnimatingFilterProperty(this);
519 bool Layer::HasPotentiallyRunningFilterAnimation() const {
520 if (layer_animation_controller_) {
521 return layer_animation_controller_->IsPotentiallyAnimatingProperty(
522 Animation::FILTER, LayerAnimationController::ObserverType::ACTIVE);
524 return layer_tree_host_->HasPotentiallyRunningFilterAnimation(this);
527 void Layer::SetBackgroundFilters(const FilterOperations& filters) {
528 DCHECK(IsPropertyChangeAllowed());
529 if (background_filters_ == filters)
530 return;
531 background_filters_ = filters;
532 SetNeedsCommit();
535 void Layer::SetOpacity(float opacity) {
536 DCHECK(IsPropertyChangeAllowed());
537 if (opacity_ == opacity)
538 return;
539 opacity_ = opacity;
540 SetNeedsCommit();
543 bool Layer::OpacityIsAnimating() const {
544 DCHECK(layer_tree_host_);
545 return layer_animation_controller_
546 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
547 Animation::OPACITY,
548 LayerAnimationController::ObserverType::ACTIVE)
549 : layer_tree_host_->IsAnimatingOpacityProperty(this);
552 bool Layer::HasPotentiallyRunningOpacityAnimation() const {
553 if (layer_animation_controller_) {
554 return layer_animation_controller_->IsPotentiallyAnimatingProperty(
555 Animation::OPACITY, LayerAnimationController::ObserverType::ACTIVE);
557 return layer_tree_host_->HasPotentiallyRunningOpacityAnimation(this);
560 bool Layer::OpacityCanAnimateOnImplThread() const {
561 return false;
564 void Layer::SetBlendMode(SkXfermode::Mode blend_mode) {
565 DCHECK(IsPropertyChangeAllowed());
566 if (blend_mode_ == blend_mode)
567 return;
569 // Allowing only blend modes that are defined in the CSS Compositing standard:
570 // http://dev.w3.org/fxtf/compositing-1/#blending
571 switch (blend_mode) {
572 case SkXfermode::kSrcOver_Mode:
573 case SkXfermode::kScreen_Mode:
574 case SkXfermode::kOverlay_Mode:
575 case SkXfermode::kDarken_Mode:
576 case SkXfermode::kLighten_Mode:
577 case SkXfermode::kColorDodge_Mode:
578 case SkXfermode::kColorBurn_Mode:
579 case SkXfermode::kHardLight_Mode:
580 case SkXfermode::kSoftLight_Mode:
581 case SkXfermode::kDifference_Mode:
582 case SkXfermode::kExclusion_Mode:
583 case SkXfermode::kMultiply_Mode:
584 case SkXfermode::kHue_Mode:
585 case SkXfermode::kSaturation_Mode:
586 case SkXfermode::kColor_Mode:
587 case SkXfermode::kLuminosity_Mode:
588 // supported blend modes
589 break;
590 case SkXfermode::kClear_Mode:
591 case SkXfermode::kSrc_Mode:
592 case SkXfermode::kDst_Mode:
593 case SkXfermode::kDstOver_Mode:
594 case SkXfermode::kSrcIn_Mode:
595 case SkXfermode::kDstIn_Mode:
596 case SkXfermode::kSrcOut_Mode:
597 case SkXfermode::kDstOut_Mode:
598 case SkXfermode::kSrcATop_Mode:
599 case SkXfermode::kDstATop_Mode:
600 case SkXfermode::kXor_Mode:
601 case SkXfermode::kPlus_Mode:
602 case SkXfermode::kModulate_Mode:
603 // Porter Duff Compositing Operators are not yet supported
604 // http://dev.w3.org/fxtf/compositing-1/#porterduffcompositingoperators
605 NOTREACHED();
606 return;
609 blend_mode_ = blend_mode;
610 SetNeedsCommit();
613 void Layer::SetIsRootForIsolatedGroup(bool root) {
614 DCHECK(IsPropertyChangeAllowed());
615 if (is_root_for_isolated_group_ == root)
616 return;
617 is_root_for_isolated_group_ = root;
618 SetNeedsCommit();
621 void Layer::SetContentsOpaque(bool opaque) {
622 DCHECK(IsPropertyChangeAllowed());
623 if (contents_opaque_ == opaque)
624 return;
625 contents_opaque_ = opaque;
626 SetNeedsCommit();
629 void Layer::SetPosition(const gfx::PointF& position) {
630 DCHECK(IsPropertyChangeAllowed());
631 if (position_ == position)
632 return;
633 position_ = position;
635 if (!layer_tree_host_)
636 return;
638 if (TransformNode* transform_node =
639 layer_tree_host_->property_trees()->transform_tree.Node(
640 transform_tree_index())) {
641 if (transform_node->owner_id == id()) {
642 transform_node->data.update_post_local_transform(position,
643 transform_origin());
644 transform_node->data.needs_local_transform_update = true;
645 layer_tree_host_->property_trees()->transform_tree.set_needs_update(true);
646 SetNeedsCommitNoRebuild();
647 return;
651 SetNeedsCommit();
654 bool Layer::IsContainerForFixedPositionLayers() const {
655 if (!transform_.IsIdentityOrTranslation())
656 return true;
657 if (parent_ && !parent_->transform_.IsIdentityOrTranslation())
658 return true;
659 return is_container_for_fixed_position_layers_;
662 bool Are2dAxisAligned(const gfx::Transform& a,
663 const gfx::Transform& b,
664 bool* is_invertible) {
665 if (a.IsScaleOrTranslation() && b.IsScaleOrTranslation()) {
666 *is_invertible = b.IsInvertible();
667 return true;
670 gfx::Transform inverse(gfx::Transform::kSkipInitialization);
671 *is_invertible = b.GetInverse(&inverse);
673 inverse *= a;
674 return inverse.Preserves2dAxisAlignment();
677 void Layer::SetTransform(const gfx::Transform& transform) {
678 DCHECK(IsPropertyChangeAllowed());
679 if (transform_ == transform)
680 return;
682 if (layer_tree_host_) {
683 if (TransformNode* transform_node =
684 layer_tree_host_->property_trees()->transform_tree.Node(
685 transform_tree_index())) {
686 if (transform_node->owner_id == id()) {
687 // We need to trigger a rebuild if we could have affected 2d axis
688 // alignment. We'll check to see if transform and transform_ are axis
689 // align with respect to one another.
690 bool invertible = false;
691 bool preserves_2d_axis_alignment =
692 Are2dAxisAligned(transform_, transform, &invertible);
693 transform_node->data.local = transform;
694 transform_node->data.needs_local_transform_update = true;
695 layer_tree_host_->property_trees()->transform_tree.set_needs_update(
696 true);
697 if (preserves_2d_axis_alignment)
698 SetNeedsCommitNoRebuild();
699 else
700 SetNeedsCommit();
701 transform_ = transform;
702 transform_is_invertible_ = invertible;
703 return;
708 transform_ = transform;
709 transform_is_invertible_ = transform.IsInvertible();
711 SetNeedsCommit();
714 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) {
715 DCHECK(IsPropertyChangeAllowed());
716 if (transform_origin_ == transform_origin)
717 return;
718 transform_origin_ = transform_origin;
720 if (!layer_tree_host_)
721 return;
723 if (TransformNode* transform_node =
724 layer_tree_host_->property_trees()->transform_tree.Node(
725 transform_tree_index())) {
726 if (transform_node->owner_id == id()) {
727 transform_node->data.update_pre_local_transform(transform_origin);
728 transform_node->data.update_post_local_transform(position(),
729 transform_origin);
730 transform_node->data.needs_local_transform_update = true;
731 layer_tree_host_->property_trees()->transform_tree.set_needs_update(true);
732 SetNeedsCommitNoRebuild();
733 return;
737 SetNeedsCommit();
740 bool Layer::AnimationsPreserveAxisAlignment() const {
741 DCHECK(layer_tree_host_);
742 return layer_animation_controller_
743 ? layer_animation_controller_->AnimationsPreserveAxisAlignment()
744 : layer_tree_host_->AnimationsPreserveAxisAlignment(this);
747 bool Layer::TransformIsAnimating() const {
748 DCHECK(layer_tree_host_);
749 return layer_animation_controller_
750 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
751 Animation::TRANSFORM,
752 LayerAnimationController::ObserverType::ACTIVE)
753 : layer_tree_host_->IsAnimatingTransformProperty(this);
756 bool Layer::HasPotentiallyRunningTransformAnimation() const {
757 if (layer_animation_controller_) {
758 return layer_animation_controller_->IsPotentiallyAnimatingProperty(
759 Animation::TRANSFORM, LayerAnimationController::ObserverType::ACTIVE);
761 return layer_tree_host_->HasPotentiallyRunningTransformAnimation(this);
764 bool Layer::HasAnyAnimationTargetingProperty(
765 Animation::TargetProperty property) const {
766 if (layer_animation_controller_)
767 return !!layer_animation_controller_->GetAnimation(property);
769 return layer_tree_host_->HasAnyAnimationTargetingProperty(this, property);
772 bool Layer::ScrollOffsetAnimationWasInterrupted() const {
773 DCHECK(layer_tree_host_);
774 return layer_animation_controller_
775 ? layer_animation_controller_
776 ->scroll_offset_animation_was_interrupted()
777 : layer_tree_host_->ScrollOffsetAnimationWasInterrupted(this);
780 void Layer::SetScrollParent(Layer* parent) {
781 DCHECK(IsPropertyChangeAllowed());
782 if (scroll_parent_ == parent)
783 return;
785 if (scroll_parent_)
786 scroll_parent_->RemoveScrollChild(this);
788 scroll_parent_ = parent;
790 if (scroll_parent_)
791 scroll_parent_->AddScrollChild(this);
793 SetNeedsCommit();
796 void Layer::AddScrollChild(Layer* child) {
797 if (!scroll_children_)
798 scroll_children_.reset(new std::set<Layer*>);
799 scroll_children_->insert(child);
800 if (layer_tree_host_ && !layer_tree_host_->needs_meta_info_recomputation()) {
801 num_children_with_scroll_parent_++;
802 draw_properties().has_child_with_a_scroll_parent = true;
804 SetNeedsCommit();
807 void Layer::RemoveScrollChild(Layer* child) {
808 scroll_children_->erase(child);
809 if (scroll_children_->empty())
810 scroll_children_ = nullptr;
811 if (layer_tree_host_ && !layer_tree_host_->needs_meta_info_recomputation()) {
812 num_children_with_scroll_parent_--;
813 DCHECK_GE(num_children_with_scroll_parent_, 0);
814 draw_properties().has_child_with_a_scroll_parent =
815 (num_children_with_scroll_parent_ != 0);
817 SetNeedsCommit();
820 void Layer::SetClipParent(Layer* ancestor) {
821 DCHECK(IsPropertyChangeAllowed());
822 if (clip_parent_ == ancestor)
823 return;
825 if (clip_parent_)
826 clip_parent_->RemoveClipChild(this);
828 clip_parent_ = ancestor;
830 if (clip_parent_)
831 clip_parent_->AddClipChild(this);
833 SetNeedsCommit();
834 if (layer_tree_host_)
835 layer_tree_host_->SetNeedsMetaInfoRecomputation(true);
838 void Layer::AddClipChild(Layer* child) {
839 if (!clip_children_)
840 clip_children_.reset(new std::set<Layer*>);
841 clip_children_->insert(child);
842 SetNeedsCommit();
845 void Layer::RemoveClipChild(Layer* child) {
846 clip_children_->erase(child);
847 if (clip_children_->empty())
848 clip_children_ = nullptr;
849 SetNeedsCommit();
852 void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) {
853 DCHECK(IsPropertyChangeAllowed());
855 if (scroll_offset_ == scroll_offset)
856 return;
857 scroll_offset_ = scroll_offset;
859 if (!layer_tree_host_)
860 return;
862 if (TransformNode* transform_node =
863 layer_tree_host_->property_trees()->transform_tree.Node(
864 transform_tree_index())) {
865 if (transform_node->owner_id == id()) {
866 transform_node->data.scroll_offset = CurrentScrollOffset();
867 transform_node->data.needs_local_transform_update = true;
868 layer_tree_host_->property_trees()->transform_tree.set_needs_update(true);
869 SetNeedsCommitNoRebuild();
870 return;
874 SetNeedsCommit();
877 void Layer::SetScrollCompensationAdjustment(
878 const gfx::Vector2dF& scroll_compensation_adjustment) {
879 if (scroll_compensation_adjustment_ == scroll_compensation_adjustment)
880 return;
881 scroll_compensation_adjustment_ = scroll_compensation_adjustment;
882 SetNeedsCommit();
885 gfx::Vector2dF Layer::ScrollCompensationAdjustment() const {
886 return scroll_compensation_adjustment_;
889 void Layer::SetScrollOffsetFromImplSide(
890 const gfx::ScrollOffset& scroll_offset) {
891 DCHECK(IsPropertyChangeAllowed());
892 // This function only gets called during a BeginMainFrame, so there
893 // is no need to call SetNeedsUpdate here.
894 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested());
895 if (scroll_offset_ == scroll_offset)
896 return;
897 scroll_offset_ = scroll_offset;
898 SetNeedsPushProperties();
900 bool needs_rebuild = true;
901 if (TransformNode* transform_node =
902 layer_tree_host_->property_trees()->transform_tree.Node(
903 transform_tree_index())) {
904 if (transform_node->owner_id == id()) {
905 transform_node->data.scroll_offset = CurrentScrollOffset();
906 transform_node->data.needs_local_transform_update = true;
907 layer_tree_host_->property_trees()->transform_tree.set_needs_update(true);
908 needs_rebuild = false;
912 if (needs_rebuild)
913 layer_tree_host_->property_trees()->needs_rebuild = true;
915 if (!did_scroll_callback_.is_null())
916 did_scroll_callback_.Run();
917 // The callback could potentially change the layer structure:
918 // "this" may have been destroyed during the process.
921 void Layer::SetScrollClipLayerId(int clip_layer_id) {
922 DCHECK(IsPropertyChangeAllowed());
923 if (scroll_clip_layer_id_ == clip_layer_id)
924 return;
925 scroll_clip_layer_id_ = clip_layer_id;
926 SetNeedsCommit();
929 void Layer::SetUserScrollable(bool horizontal, bool vertical) {
930 DCHECK(IsPropertyChangeAllowed());
931 if (user_scrollable_horizontal_ == horizontal &&
932 user_scrollable_vertical_ == vertical)
933 return;
934 user_scrollable_horizontal_ = horizontal;
935 user_scrollable_vertical_ = vertical;
936 SetNeedsCommit();
939 void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) {
940 DCHECK(IsPropertyChangeAllowed());
941 if (should_scroll_on_main_thread_ == should_scroll_on_main_thread)
942 return;
943 should_scroll_on_main_thread_ = should_scroll_on_main_thread;
944 SetNeedsCommit();
947 void Layer::SetHaveWheelEventHandlers(bool have_wheel_event_handlers) {
948 DCHECK(IsPropertyChangeAllowed());
949 if (have_wheel_event_handlers_ == have_wheel_event_handlers)
950 return;
952 have_wheel_event_handlers_ = have_wheel_event_handlers;
953 SetNeedsCommit();
956 void Layer::SetHaveScrollEventHandlers(bool have_scroll_event_handlers) {
957 DCHECK(IsPropertyChangeAllowed());
958 if (have_scroll_event_handlers_ == have_scroll_event_handlers)
959 return;
960 have_scroll_event_handlers_ = have_scroll_event_handlers;
961 SetNeedsCommit();
964 void Layer::SetNonFastScrollableRegion(const Region& region) {
965 DCHECK(IsPropertyChangeAllowed());
966 if (non_fast_scrollable_region_ == region)
967 return;
968 non_fast_scrollable_region_ = region;
969 SetNeedsCommit();
972 void Layer::SetTouchEventHandlerRegion(const Region& region) {
973 DCHECK(IsPropertyChangeAllowed());
974 if (touch_event_handler_region_ == region)
975 return;
977 touch_event_handler_region_ = region;
978 SetNeedsCommit();
981 void Layer::SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on) {
982 DCHECK(IsPropertyChangeAllowed());
983 if (scroll_blocks_on_ == scroll_blocks_on)
984 return;
985 scroll_blocks_on_ = scroll_blocks_on;
986 SetNeedsCommit();
989 void Layer::SetForceRenderSurface(bool force) {
990 DCHECK(IsPropertyChangeAllowed());
991 if (force_render_surface_ == force)
992 return;
993 force_render_surface_ = force;
994 SetNeedsCommit();
997 void Layer::SetDoubleSided(bool double_sided) {
998 DCHECK(IsPropertyChangeAllowed());
999 if (double_sided_ == double_sided)
1000 return;
1001 double_sided_ = double_sided;
1002 SetNeedsCommit();
1005 void Layer::Set3dSortingContextId(int id) {
1006 DCHECK(IsPropertyChangeAllowed());
1007 if (id == sorting_context_id_)
1008 return;
1009 sorting_context_id_ = id;
1010 SetNeedsCommit();
1013 void Layer::SetTransformTreeIndex(int index) {
1014 DCHECK(IsPropertyChangeAllowed());
1015 if (transform_tree_index_ == index)
1016 return;
1017 transform_tree_index_ = index;
1018 SetNeedsPushProperties();
1021 int Layer::transform_tree_index() const {
1022 if (!layer_tree_host_ ||
1023 layer_tree_host_->property_trees()->sequence_number !=
1024 property_tree_sequence_number_) {
1025 return -1;
1027 return transform_tree_index_;
1030 void Layer::SetClipTreeIndex(int index) {
1031 DCHECK(IsPropertyChangeAllowed());
1032 if (clip_tree_index_ == index)
1033 return;
1034 clip_tree_index_ = index;
1035 SetNeedsPushProperties();
1038 int Layer::clip_tree_index() const {
1039 if (!layer_tree_host_ ||
1040 layer_tree_host_->property_trees()->sequence_number !=
1041 property_tree_sequence_number_) {
1042 return -1;
1044 return clip_tree_index_;
1047 void Layer::SetEffectTreeIndex(int index) {
1048 DCHECK(IsPropertyChangeAllowed());
1049 if (effect_tree_index_ == index)
1050 return;
1051 effect_tree_index_ = index;
1052 SetNeedsPushProperties();
1055 int Layer::effect_tree_index() const {
1056 if (!layer_tree_host_ ||
1057 layer_tree_host_->property_trees()->sequence_number !=
1058 property_tree_sequence_number_) {
1059 return -1;
1061 return effect_tree_index_;
1064 void Layer::InvalidatePropertyTreesIndices() {
1065 int invalid_property_tree_index = -1;
1066 SetTransformTreeIndex(invalid_property_tree_index);
1067 SetClipTreeIndex(invalid_property_tree_index);
1068 SetEffectTreeIndex(invalid_property_tree_index);
1071 void Layer::SetShouldFlattenTransform(bool should_flatten) {
1072 DCHECK(IsPropertyChangeAllowed());
1073 if (should_flatten_transform_ == should_flatten)
1074 return;
1075 should_flatten_transform_ = should_flatten;
1076 SetNeedsCommit();
1079 void Layer::SetIsDrawable(bool is_drawable) {
1080 DCHECK(IsPropertyChangeAllowed());
1081 if (is_drawable_ == is_drawable)
1082 return;
1084 is_drawable_ = is_drawable;
1085 UpdateDrawsContent(HasDrawableContent());
1088 void Layer::SetHideLayerAndSubtree(bool hide) {
1089 DCHECK(IsPropertyChangeAllowed());
1090 if (hide_layer_and_subtree_ == hide)
1091 return;
1093 hide_layer_and_subtree_ = hide;
1094 SetNeedsCommit();
1097 void Layer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) {
1098 if (dirty_rect.IsEmpty())
1099 return;
1101 SetNeedsPushProperties();
1102 update_rect_.Union(dirty_rect);
1104 if (DrawsContent())
1105 SetNeedsUpdate();
1108 bool Layer::DescendantIsFixedToContainerLayer() const {
1109 for (size_t i = 0; i < children_.size(); ++i) {
1110 if (children_[i]->position_constraint_.is_fixed_position() ||
1111 children_[i]->DescendantIsFixedToContainerLayer())
1112 return true;
1114 return false;
1117 void Layer::SetIsContainerForFixedPositionLayers(bool container) {
1118 if (is_container_for_fixed_position_layers_ == container)
1119 return;
1120 is_container_for_fixed_position_layers_ = container;
1122 if (layer_tree_host_ && layer_tree_host_->CommitRequested())
1123 return;
1125 // Only request a commit if we have a fixed positioned descendant.
1126 if (DescendantIsFixedToContainerLayer())
1127 SetNeedsCommit();
1130 void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) {
1131 DCHECK(IsPropertyChangeAllowed());
1132 if (position_constraint_ == constraint)
1133 return;
1134 position_constraint_ = constraint;
1135 SetNeedsCommit();
1138 static void RunCopyCallbackOnMainThread(scoped_ptr<CopyOutputRequest> request,
1139 scoped_ptr<CopyOutputResult> result) {
1140 request->SendResult(result.Pass());
1143 static void PostCopyCallbackToMainThread(
1144 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
1145 scoped_ptr<CopyOutputRequest> request,
1146 scoped_ptr<CopyOutputResult> result) {
1147 main_thread_task_runner->PostTask(FROM_HERE,
1148 base::Bind(&RunCopyCallbackOnMainThread,
1149 base::Passed(&request),
1150 base::Passed(&result)));
1153 void Layer::PushPropertiesTo(LayerImpl* layer) {
1154 DCHECK(layer_tree_host_);
1156 // If we did not SavePaintProperties() for the layer this frame, then push the
1157 // real property values, not the paint property values.
1158 bool use_paint_properties = paint_properties_.source_frame_number ==
1159 layer_tree_host_->source_frame_number();
1161 layer->SetTransformOrigin(transform_origin_);
1162 layer->SetBackgroundColor(background_color_);
1163 layer->SetBounds(use_paint_properties ? paint_properties_.bounds
1164 : bounds_);
1166 if (frame_viewer_instrumentation::IsTracingLayerTreeSnapshots())
1167 layer->SetDebugInfo(TakeDebugInfo());
1169 layer->SetTransformTreeIndex(transform_tree_index());
1170 layer->SetEffectTreeIndex(effect_tree_index());
1171 layer->SetClipTreeIndex(clip_tree_index());
1172 layer->set_offset_to_transform_parent(offset_to_transform_parent_);
1173 layer->SetDoubleSided(double_sided_);
1174 layer->SetDrawsContent(DrawsContent());
1175 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_);
1176 layer->SetHasRenderSurface(has_render_surface_);
1177 if (!layer->FilterIsAnimatingOnImplOnly() && !FilterIsAnimating())
1178 layer->SetFilters(filters_);
1179 DCHECK(!(FilterIsAnimating() && layer->FilterIsAnimatingOnImplOnly()));
1180 layer->SetBackgroundFilters(background_filters());
1181 layer->SetMasksToBounds(masks_to_bounds_);
1182 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_);
1183 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
1184 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_);
1185 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
1186 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
1187 layer->SetScrollBlocksOn(scroll_blocks_on_);
1188 layer->SetContentsOpaque(contents_opaque_);
1189 if (!layer->OpacityIsAnimatingOnImplOnly() && !OpacityIsAnimating())
1190 layer->SetOpacity(opacity_);
1191 DCHECK(!(OpacityIsAnimating() && layer->OpacityIsAnimatingOnImplOnly()));
1192 layer->SetBlendMode(blend_mode_);
1193 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_);
1194 layer->SetPosition(position_);
1195 layer->SetIsContainerForFixedPositionLayers(
1196 IsContainerForFixedPositionLayers());
1197 layer->SetPositionConstraint(position_constraint_);
1198 layer->SetShouldFlattenTransform(should_flatten_transform_);
1199 layer->set_should_flatten_transform_from_property_tree(
1200 should_flatten_transform_from_property_tree_);
1201 layer->set_is_clipped(is_clipped_);
1202 layer->set_draw_blend_mode(draw_blend_mode_);
1203 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
1204 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating())
1205 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
1206 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly()));
1207 layer->Set3dSortingContextId(sorting_context_id_);
1208 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
1210 layer->SetScrollClipLayer(scroll_clip_layer_id_);
1211 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
1212 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
1214 LayerImpl* scroll_parent = nullptr;
1215 if (scroll_parent_) {
1216 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
1217 DCHECK(scroll_parent);
1220 layer->SetScrollParent(scroll_parent);
1221 if (scroll_children_) {
1222 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
1223 for (std::set<Layer*>::iterator it = scroll_children_->begin();
1224 it != scroll_children_->end();
1225 ++it) {
1226 DCHECK_EQ((*it)->scroll_parent(), this);
1227 LayerImpl* scroll_child =
1228 layer->layer_tree_impl()->LayerById((*it)->id());
1229 DCHECK(scroll_child);
1230 scroll_children->insert(scroll_child);
1232 layer->SetScrollChildren(scroll_children);
1233 } else {
1234 layer->SetScrollChildren(nullptr);
1237 LayerImpl* clip_parent = nullptr;
1238 if (clip_parent_) {
1239 clip_parent =
1240 layer->layer_tree_impl()->LayerById(clip_parent_->id());
1241 DCHECK(clip_parent);
1244 layer->SetClipParent(clip_parent);
1245 if (clip_children_) {
1246 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>;
1247 for (std::set<Layer*>::iterator it = clip_children_->begin();
1248 it != clip_children_->end(); ++it) {
1249 DCHECK_EQ((*it)->clip_parent(), this);
1250 LayerImpl* clip_child = layer->layer_tree_impl()->LayerById((*it)->id());
1251 DCHECK(clip_child);
1252 clip_children->insert(clip_child);
1254 layer->SetClipChildren(clip_children);
1255 } else {
1256 layer->SetClipChildren(nullptr);
1259 // When a scroll offset animation is interrupted the new scroll position on
1260 // the pending tree will clobber any impl-side scrolling occuring on the
1261 // active tree. To do so, avoid scrolling the pending tree along with it
1262 // instead of trying to undo that scrolling later.
1263 if (ScrollOffsetAnimationWasInterrupted())
1264 layer->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_);
1265 else
1266 layer->PushScrollOffsetFromMainThread(scroll_offset_);
1267 layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment());
1269 // Wrap the copy_requests_ in a PostTask to the main thread.
1270 bool had_copy_requests = !copy_requests_.empty();
1271 ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests;
1272 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin();
1273 it != copy_requests_.end();
1274 ++it) {
1275 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner =
1276 layer_tree_host()->proxy()->MainThreadTaskRunner();
1277 scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it);
1278 const CopyOutputRequest& original_request_ref = *original_request;
1279 scoped_ptr<CopyOutputRequest> main_thread_request =
1280 CopyOutputRequest::CreateRelayRequest(
1281 original_request_ref,
1282 base::Bind(&PostCopyCallbackToMainThread,
1283 main_thread_task_runner,
1284 base::Passed(&original_request)));
1285 main_thread_copy_requests.push_back(main_thread_request.Pass());
1287 if (!copy_requests_.empty() && layer_tree_host_)
1288 layer_tree_host_->property_trees()->needs_rebuild = true;
1289 if (had_copy_requests)
1290 UpdateNumCopyRequestsForSubtree(false);
1291 copy_requests_.clear();
1292 layer->PassCopyRequests(&main_thread_copy_requests);
1294 // If the main thread commits multiple times before the impl thread actually
1295 // draws, then damage tracking will become incorrect if we simply clobber the
1296 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
1297 // union) any update changes that have occurred on the main thread.
1298 update_rect_.Union(layer->update_rect());
1299 layer->SetUpdateRect(update_rect_);
1301 layer->SetStackingOrderChanged(stacking_order_changed_);
1303 if (layer->layer_animation_controller() && layer_animation_controller_)
1304 layer_animation_controller_->PushAnimationUpdatesTo(
1305 layer->layer_animation_controller());
1307 if (frame_timing_requests_dirty_) {
1308 layer->SetFrameTimingRequests(frame_timing_requests_);
1309 frame_timing_requests_dirty_ = false;
1312 bool is_page_scale_layer = this == layer_tree_host()->page_scale_layer();
1313 bool parent_affected =
1314 layer->parent() && layer->parent()->IsAffectedByPageScale();
1315 layer->SetIsAffectedByPageScale(is_page_scale_layer || parent_affected);
1317 // Reset any state that should be cleared for the next update.
1318 stacking_order_changed_ = false;
1319 update_rect_ = gfx::Rect();
1321 needs_push_properties_ = false;
1322 num_dependents_need_push_properties_ = 0;
1325 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
1326 return LayerImpl::Create(tree_impl, layer_id_,
1327 new LayerImpl::SyncedScrollOffset);
1330 bool Layer::DrawsContent() const {
1331 return draws_content_;
1334 bool Layer::HasDrawableContent() const {
1335 return is_drawable_;
1338 void Layer::UpdateDrawsContent(bool has_drawable_content) {
1339 bool draws_content = has_drawable_content;
1340 DCHECK(is_drawable_ || !has_drawable_content);
1341 if (draws_content == draws_content_)
1342 return;
1344 if (HasDelegatedContent()) {
1345 // Layers with delegated content need to be treated as if they have as
1346 // many children as the number of layers they own delegated quads for.
1347 // Since we don't know this number right now, we choose one that acts like
1348 // infinity for our purposes.
1349 AddDrawableDescendants(draws_content ? 1000 : -1000);
1352 if (parent())
1353 parent()->AddDrawableDescendants(draws_content ? 1 : -1);
1355 draws_content_ = draws_content;
1356 SetNeedsCommit();
1359 int Layer::NumDescendantsThatDrawContent() const {
1360 return num_descendants_that_draw_content_;
1363 void Layer::SavePaintProperties() {
1364 DCHECK(layer_tree_host_);
1366 // TODO(reveman): Save all layer properties that we depend on not
1367 // changing until PushProperties() has been called. crbug.com/231016
1368 paint_properties_.bounds = bounds_;
1369 paint_properties_.source_frame_number =
1370 layer_tree_host_->source_frame_number();
1373 bool Layer::Update() {
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.";
1378 return false;
1381 bool Layer::NeedMoreUpdates() {
1382 return false;
1385 bool Layer::IsSuitableForGpuRasterization() const {
1386 return true;
1389 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
1390 Layer::TakeDebugInfo() {
1391 if (client_)
1392 return client_->TakeDebugInfo();
1393 else
1394 return nullptr;
1397 void Layer::SetHasRenderSurface(bool has_render_surface) {
1398 if (has_render_surface_ == has_render_surface)
1399 return;
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();
1404 layer_tree_host_->property_trees()->needs_rebuild = true;
1407 void Layer::CreateRenderSurface() {
1408 DCHECK(!render_surface_);
1409 render_surface_ = make_scoped_ptr(new RenderSurface(this));
1412 void Layer::ClearRenderSurface() {
1413 render_surface_ = nullptr;
1416 void Layer::ClearRenderSurfaceLayerList() {
1417 if (render_surface_)
1418 render_surface_->ClearLayerLists();
1421 gfx::ScrollOffset Layer::ScrollOffsetForAnimation() const {
1422 return CurrentScrollOffset();
1425 // On<Property>Animated is called due to an ongoing accelerated animation.
1426 // Since this animation is also being run on the compositor thread, there
1427 // is no need to request a commit to push this value over, so the value is
1428 // set directly rather than by calling Set<Property>.
1429 void Layer::OnFilterAnimated(const FilterOperations& filters) {
1430 filters_ = filters;
1433 void Layer::OnOpacityAnimated(float opacity) {
1434 opacity_ = opacity;
1435 if (layer_tree_host_) {
1436 if (EffectNode* node = layer_tree_host_->property_trees()->effect_tree.Node(
1437 effect_tree_index())) {
1438 if (node->owner_id == id()) {
1439 node->data.opacity = opacity;
1440 layer_tree_host_->property_trees()->effect_tree.set_needs_update(true);
1446 void Layer::OnTransformAnimated(const gfx::Transform& transform) {
1447 if (transform_ == transform)
1448 return;
1449 transform_ = transform;
1450 transform_is_invertible_ = transform.IsInvertible();
1451 if (layer_tree_host_) {
1452 if (TransformNode* node =
1453 layer_tree_host_->property_trees()->transform_tree.Node(
1454 transform_tree_index())) {
1455 if (node->owner_id == id()) {
1456 node->data.local = transform;
1457 node->data.needs_local_transform_update = true;
1458 node->data.is_animated = true;
1459 layer_tree_host_->property_trees()->transform_tree.set_needs_update(
1460 true);
1466 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
1467 // Do nothing. Scroll deltas will be sent from the compositor thread back
1468 // to the main thread in the same manner as during non-animated
1469 // compositor-driven scrolling.
1472 void Layer::OnAnimationWaitingForDeletion() {
1473 // Animations are only deleted during PushProperties.
1474 SetNeedsPushProperties();
1477 void Layer::OnTransformIsPotentiallyAnimatingChanged(bool is_animating) {
1478 if (!layer_tree_host_)
1479 return;
1480 TransformTree& transform_tree =
1481 layer_tree_host_->property_trees()->transform_tree;
1482 TransformNode* node = transform_tree.Node(transform_tree_index());
1483 if (!node)
1484 return;
1486 if (node->owner_id == id()) {
1487 node->data.is_animated = is_animating;
1488 transform_tree.set_needs_update(true);
1492 bool Layer::IsActive() const {
1493 return true;
1496 bool Layer::AddAnimation(scoped_ptr <Animation> animation) {
1497 DCHECK(layer_animation_controller_);
1498 if (!layer_animation_controller_->animation_registrar())
1499 return false;
1501 if (animation->target_property() == Animation::SCROLL_OFFSET &&
1502 !layer_animation_controller_->animation_registrar()
1503 ->supports_scroll_animations())
1504 return false;
1506 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer",
1507 !layer_tree_host_);
1508 layer_animation_controller_->AddAnimation(animation.Pass());
1509 SetNeedsCommit();
1510 return true;
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));
1517 SetNeedsCommit();
1520 void Layer::RemoveAnimation(int animation_id) {
1521 DCHECK(layer_animation_controller_);
1522 layer_animation_controller_->RemoveAnimation(animation_id);
1523 SetNeedsCommit();
1526 void Layer::RemoveAnimation(int animation_id,
1527 Animation::TargetProperty property) {
1528 DCHECK(layer_animation_controller_);
1529 layer_animation_controller_->RemoveAnimation(animation_id, property);
1530 SetNeedsCommit();
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);
1539 SetNeedsCommit();
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() {
1567 return nullptr;
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);
1599 if (num == 0)
1600 return;
1601 num_descendants_that_draw_content_ += num;
1602 SetNeedsCommit();
1603 if (parent())
1604 parent()->AddDrawableDescendants(num);
1607 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) {
1608 benchmark->RunOnLayer(this);
1611 bool Layer::HasDelegatedContent() const {
1612 return false;
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_)
1619 return;
1620 frame_timing_requests_ = requests;
1621 frame_timing_requests_dirty_ = true;
1622 SetNeedsCommit();
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) {
1634 visited_tracker_ =
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()
1648 : 0;
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()
1660 : 0;
1663 bool Layer::sorted_for_recursion() {
1664 return sorted_for_recursion_tracker_ ==
1665 layer_tree_host()->meta_information_sequence_number();
1668 } // namespace cc