Supervised user whitelists: Cleanup
[chromium-blink-merge.git] / cc / layers / layer.cc
blob56b8c739e4f24004b59bf8a138f3cd3606cb7bf9
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() {
38 return make_scoped_refptr(new Layer());
41 Layer::Layer()
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),
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 opacity_tree_index_(-1),
55 clip_tree_index_(-1),
56 should_flatten_transform_from_property_tree_(false),
57 should_scroll_on_main_thread_(false),
58 have_wheel_event_handlers_(false),
59 have_scroll_event_handlers_(false),
60 user_scrollable_horizontal_(true),
61 user_scrollable_vertical_(true),
62 is_root_for_isolated_group_(false),
63 is_container_for_fixed_position_layers_(false),
64 is_drawable_(false),
65 draws_content_(false),
66 hide_layer_and_subtree_(false),
67 masks_to_bounds_(false),
68 contents_opaque_(false),
69 double_sided_(true),
70 should_flatten_transform_(true),
71 use_parent_backface_visibility_(false),
72 draw_checkerboard_for_missing_tiles_(false),
73 force_render_surface_(false),
74 transform_is_invertible_(true),
75 has_render_surface_(false),
76 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE),
77 background_color_(0),
78 opacity_(1.f),
79 blend_mode_(SkXfermode::kSrcOver_Mode),
80 scroll_parent_(nullptr),
81 clip_parent_(nullptr),
82 replica_layer_(nullptr),
83 raster_scale_(0.f),
84 client_(nullptr),
85 frame_timing_requests_dirty_(false) {
86 layer_animation_controller_ = LayerAnimationController::Create(layer_id_);
87 layer_animation_controller_->AddValueObserver(this);
88 layer_animation_controller_->set_value_provider(this);
91 Layer::~Layer() {
92 // Our parent should be holding a reference to us so there should be no
93 // way for us to be destroyed while we still have a parent.
94 DCHECK(!parent());
95 // Similarly we shouldn't have a layer tree host since it also keeps a
96 // reference to us.
97 DCHECK(!layer_tree_host());
99 layer_animation_controller_->RemoveValueObserver(this);
100 layer_animation_controller_->remove_value_provider(this);
102 RemoveFromScrollTree();
103 RemoveFromClipTree();
105 // Remove the parent reference from all children and dependents.
106 RemoveAllChildren();
107 if (mask_layer_.get()) {
108 DCHECK_EQ(this, mask_layer_->parent());
109 mask_layer_->RemoveFromParent();
111 if (replica_layer_.get()) {
112 DCHECK_EQ(this, replica_layer_->parent());
113 replica_layer_->RemoveFromParent();
117 void Layer::SetLayerTreeHost(LayerTreeHost* host) {
118 if (layer_tree_host_ == host)
119 return;
121 if (layer_tree_host_)
122 layer_tree_host_->property_trees()->needs_rebuild = true;
124 layer_tree_host_ = host;
126 // When changing hosts, the layer needs to commit its properties to the impl
127 // side for the new host.
128 SetNeedsPushProperties();
130 for (size_t i = 0; i < children_.size(); ++i)
131 children_[i]->SetLayerTreeHost(host);
133 if (mask_layer_.get())
134 mask_layer_->SetLayerTreeHost(host);
135 if (replica_layer_.get())
136 replica_layer_->SetLayerTreeHost(host);
138 if (host) {
139 layer_animation_controller_->SetAnimationRegistrar(
140 host->animation_registrar());
142 if (host->settings().layer_transforms_should_scale_layer_contents)
143 reset_raster_scale_to_unknown();
146 if (host && layer_animation_controller_->has_any_animation())
147 host->SetNeedsCommit();
150 void Layer::SetNeedsUpdate() {
151 if (layer_tree_host_ && !ignore_set_needs_commit_)
152 layer_tree_host_->SetNeedsUpdateLayers();
155 void Layer::SetNeedsCommit() {
156 if (!layer_tree_host_)
157 return;
159 SetNeedsPushProperties();
160 layer_tree_host_->property_trees()->needs_rebuild = true;
162 if (ignore_set_needs_commit_)
163 return;
165 layer_tree_host_->SetNeedsCommit();
168 void Layer::SetNeedsCommitNoRebuild() {
169 if (!layer_tree_host_)
170 return;
172 SetNeedsPushProperties();
174 if (ignore_set_needs_commit_)
175 return;
177 layer_tree_host_->SetNeedsCommit();
180 void Layer::SetNeedsFullTreeSync() {
181 if (!layer_tree_host_)
182 return;
184 layer_tree_host_->SetNeedsFullTreeSync();
187 void Layer::SetNextCommitWaitsForActivation() {
188 if (!layer_tree_host_)
189 return;
191 layer_tree_host_->SetNextCommitWaitsForActivation();
194 void Layer::SetNeedsPushProperties() {
195 if (needs_push_properties_)
196 return;
197 if (!parent_should_know_need_push_properties() && parent_)
198 parent_->AddDependentNeedsPushProperties();
199 needs_push_properties_ = true;
202 void Layer::AddDependentNeedsPushProperties() {
203 DCHECK_GE(num_dependents_need_push_properties_, 0);
205 if (!parent_should_know_need_push_properties() && parent_)
206 parent_->AddDependentNeedsPushProperties();
208 num_dependents_need_push_properties_++;
211 void Layer::RemoveDependentNeedsPushProperties() {
212 num_dependents_need_push_properties_--;
213 DCHECK_GE(num_dependents_need_push_properties_, 0);
215 if (!parent_should_know_need_push_properties() && parent_)
216 parent_->RemoveDependentNeedsPushProperties();
219 bool Layer::IsPropertyChangeAllowed() const {
220 if (!layer_tree_host_)
221 return true;
223 if (!layer_tree_host_->settings().strict_layer_property_change_checking)
224 return true;
226 return !layer_tree_host_->in_paint_layer_contents();
229 gfx::Rect Layer::LayerRectToContentRect(const gfx::Rect& layer_rect) const {
230 gfx::Rect content_rect = gfx::ScaleToEnclosingRect(
231 layer_rect, contents_scale_x(), contents_scale_y());
232 // Intersect with content rect to avoid the extra pixel because for some
233 // values x and y, ceil((x / y) * y) may be x + 1.
234 content_rect.Intersect(gfx::Rect(content_bounds()));
235 return content_rect;
238 skia::RefPtr<SkPicture> Layer::GetPicture() const {
239 return skia::RefPtr<SkPicture>();
242 void Layer::SetParent(Layer* layer) {
243 DCHECK(!layer || !layer->HasAncestor(this));
245 if (parent_should_know_need_push_properties()) {
246 if (parent_)
247 parent_->RemoveDependentNeedsPushProperties();
248 if (layer)
249 layer->AddDependentNeedsPushProperties();
252 parent_ = layer;
253 SetLayerTreeHost(parent_ ? parent_->layer_tree_host() : nullptr);
255 if (!layer_tree_host_)
256 return;
257 const LayerTreeSettings& settings = layer_tree_host_->settings();
258 if (!settings.layer_transforms_should_scale_layer_contents)
259 return;
261 reset_raster_scale_to_unknown();
262 if (mask_layer_.get())
263 mask_layer_->reset_raster_scale_to_unknown();
264 if (replica_layer_.get() && replica_layer_->mask_layer_.get())
265 replica_layer_->mask_layer_->reset_raster_scale_to_unknown();
268 void Layer::AddChild(scoped_refptr<Layer> child) {
269 InsertChild(child, children_.size());
272 void Layer::InsertChild(scoped_refptr<Layer> child, size_t index) {
273 DCHECK(IsPropertyChangeAllowed());
274 child->RemoveFromParent();
275 AddDrawableDescendants(child->NumDescendantsThatDrawContent() +
276 (child->DrawsContent() ? 1 : 0));
277 child->SetParent(this);
278 child->stacking_order_changed_ = true;
280 index = std::min(index, children_.size());
281 children_.insert(children_.begin() + index, child);
282 SetNeedsFullTreeSync();
285 void Layer::RemoveFromParent() {
286 DCHECK(IsPropertyChangeAllowed());
287 if (parent_)
288 parent_->RemoveChildOrDependent(this);
291 void Layer::RemoveChildOrDependent(Layer* child) {
292 if (mask_layer_.get() == child) {
293 mask_layer_->SetParent(nullptr);
294 mask_layer_ = nullptr;
295 SetNeedsFullTreeSync();
296 return;
298 if (replica_layer_.get() == child) {
299 replica_layer_->SetParent(nullptr);
300 replica_layer_ = nullptr;
301 SetNeedsFullTreeSync();
302 return;
305 for (LayerList::iterator iter = children_.begin();
306 iter != children_.end();
307 ++iter) {
308 if (iter->get() != child)
309 continue;
311 child->SetParent(nullptr);
312 AddDrawableDescendants(-child->NumDescendantsThatDrawContent() -
313 (child->DrawsContent() ? 1 : 0));
314 children_.erase(iter);
315 SetNeedsFullTreeSync();
316 return;
320 void Layer::ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer) {
321 DCHECK(reference);
322 DCHECK_EQ(reference->parent(), this);
323 DCHECK(IsPropertyChangeAllowed());
325 if (reference == new_layer.get())
326 return;
328 int reference_index = IndexOfChild(reference);
329 if (reference_index == -1) {
330 NOTREACHED();
331 return;
334 reference->RemoveFromParent();
336 if (new_layer.get()) {
337 new_layer->RemoveFromParent();
338 InsertChild(new_layer, reference_index);
342 int Layer::IndexOfChild(const Layer* reference) {
343 for (size_t i = 0; i < children_.size(); ++i) {
344 if (children_[i].get() == reference)
345 return i;
347 return -1;
350 void Layer::SetBounds(const gfx::Size& size) {
351 DCHECK(IsPropertyChangeAllowed());
352 if (bounds() == size)
353 return;
354 bounds_ = size;
356 if (!layer_tree_host_)
357 return;
359 if (ClipNode* clip_node = layer_tree_host_->property_trees()->clip_tree.Node(
360 clip_tree_index())) {
361 if (clip_node->owner_id == id()) {
362 clip_node->data.clip.set_size(size);
363 layer_tree_host_->property_trees()->clip_tree.set_needs_update(true);
367 SetNeedsCommitNoRebuild();
370 Layer* Layer::RootLayer() {
371 Layer* layer = this;
372 while (layer->parent())
373 layer = layer->parent();
374 return layer;
377 void Layer::RemoveAllChildren() {
378 DCHECK(IsPropertyChangeAllowed());
379 while (children_.size()) {
380 Layer* layer = children_[0].get();
381 DCHECK_EQ(this, layer->parent());
382 layer->RemoveFromParent();
386 void Layer::SetChildren(const LayerList& children) {
387 DCHECK(IsPropertyChangeAllowed());
388 if (children == children_)
389 return;
391 RemoveAllChildren();
392 for (size_t i = 0; i < children.size(); ++i)
393 AddChild(children[i]);
396 bool Layer::HasAncestor(const Layer* ancestor) const {
397 for (const Layer* layer = parent(); layer; layer = layer->parent()) {
398 if (layer == ancestor)
399 return true;
401 return false;
404 void Layer::RequestCopyOfOutput(
405 scoped_ptr<CopyOutputRequest> request) {
406 DCHECK(IsPropertyChangeAllowed());
407 if (void* source = request->source()) {
408 auto it = std::find_if(
409 copy_requests_.begin(), copy_requests_.end(),
410 [source](const CopyOutputRequest* x) { return x->source() == source; });
411 if (it != copy_requests_.end())
412 copy_requests_.erase(it);
414 if (request->IsEmpty())
415 return;
416 copy_requests_.push_back(request.Pass());
417 SetNeedsCommit();
420 void Layer::SetBackgroundColor(SkColor background_color) {
421 DCHECK(IsPropertyChangeAllowed());
422 if (background_color_ == background_color)
423 return;
424 background_color_ = background_color;
425 SetNeedsCommit();
428 SkColor Layer::SafeOpaqueBackgroundColor() const {
429 SkColor color = background_color();
430 if (SkColorGetA(color) == 255 && !contents_opaque()) {
431 color = SK_ColorTRANSPARENT;
432 } else if (SkColorGetA(color) != 255 && contents_opaque()) {
433 for (const Layer* layer = parent(); layer;
434 layer = layer->parent()) {
435 color = layer->background_color();
436 if (SkColorGetA(color) == 255)
437 break;
439 if (SkColorGetA(color) != 255)
440 color = layer_tree_host_->background_color();
441 if (SkColorGetA(color) != 255)
442 color = SkColorSetA(color, 255);
444 return color;
447 void Layer::CalculateContentsScale(float ideal_contents_scale,
448 float* contents_scale_x,
449 float* contents_scale_y,
450 gfx::Size* content_bounds) {
451 DCHECK(layer_tree_host_);
453 *contents_scale_x = 1;
454 *contents_scale_y = 1;
455 *content_bounds = bounds();
458 void Layer::SetMasksToBounds(bool masks_to_bounds) {
459 DCHECK(IsPropertyChangeAllowed());
460 if (masks_to_bounds_ == masks_to_bounds)
461 return;
462 masks_to_bounds_ = masks_to_bounds;
463 SetNeedsCommit();
466 void Layer::SetMaskLayer(Layer* mask_layer) {
467 DCHECK(IsPropertyChangeAllowed());
468 if (mask_layer_.get() == mask_layer)
469 return;
470 if (mask_layer_.get()) {
471 DCHECK_EQ(this, mask_layer_->parent());
472 mask_layer_->RemoveFromParent();
474 mask_layer_ = mask_layer;
475 if (mask_layer_.get()) {
476 DCHECK(!mask_layer_->parent());
477 mask_layer_->RemoveFromParent();
478 mask_layer_->SetParent(this);
479 mask_layer_->SetIsMask(true);
481 SetNeedsFullTreeSync();
484 void Layer::SetReplicaLayer(Layer* layer) {
485 DCHECK(IsPropertyChangeAllowed());
486 if (replica_layer_.get() == layer)
487 return;
488 if (replica_layer_.get()) {
489 DCHECK_EQ(this, replica_layer_->parent());
490 replica_layer_->RemoveFromParent();
492 replica_layer_ = layer;
493 if (replica_layer_.get()) {
494 DCHECK(!replica_layer_->parent());
495 replica_layer_->RemoveFromParent();
496 replica_layer_->SetParent(this);
498 SetNeedsFullTreeSync();
501 void Layer::SetFilters(const FilterOperations& filters) {
502 DCHECK(IsPropertyChangeAllowed());
503 if (filters_ == filters)
504 return;
505 filters_ = filters;
506 SetNeedsCommit();
509 bool Layer::FilterIsAnimating() const {
510 return layer_animation_controller_->IsAnimatingProperty(Animation::FILTER);
513 void Layer::SetBackgroundFilters(const FilterOperations& filters) {
514 DCHECK(IsPropertyChangeAllowed());
515 if (background_filters_ == filters)
516 return;
517 background_filters_ = filters;
518 SetNeedsCommit();
521 void Layer::SetOpacity(float opacity) {
522 DCHECK(IsPropertyChangeAllowed());
523 if (opacity_ == opacity)
524 return;
525 opacity_ = opacity;
526 SetNeedsCommit();
529 bool Layer::OpacityIsAnimating() const {
530 return layer_animation_controller_->IsAnimatingProperty(Animation::OPACITY);
533 bool Layer::OpacityCanAnimateOnImplThread() const {
534 return false;
537 void Layer::SetBlendMode(SkXfermode::Mode blend_mode) {
538 DCHECK(IsPropertyChangeAllowed());
539 if (blend_mode_ == blend_mode)
540 return;
542 // Allowing only blend modes that are defined in the CSS Compositing standard:
543 // http://dev.w3.org/fxtf/compositing-1/#blending
544 switch (blend_mode) {
545 case SkXfermode::kSrcOver_Mode:
546 case SkXfermode::kScreen_Mode:
547 case SkXfermode::kOverlay_Mode:
548 case SkXfermode::kDarken_Mode:
549 case SkXfermode::kLighten_Mode:
550 case SkXfermode::kColorDodge_Mode:
551 case SkXfermode::kColorBurn_Mode:
552 case SkXfermode::kHardLight_Mode:
553 case SkXfermode::kSoftLight_Mode:
554 case SkXfermode::kDifference_Mode:
555 case SkXfermode::kExclusion_Mode:
556 case SkXfermode::kMultiply_Mode:
557 case SkXfermode::kHue_Mode:
558 case SkXfermode::kSaturation_Mode:
559 case SkXfermode::kColor_Mode:
560 case SkXfermode::kLuminosity_Mode:
561 // supported blend modes
562 break;
563 case SkXfermode::kClear_Mode:
564 case SkXfermode::kSrc_Mode:
565 case SkXfermode::kDst_Mode:
566 case SkXfermode::kDstOver_Mode:
567 case SkXfermode::kSrcIn_Mode:
568 case SkXfermode::kDstIn_Mode:
569 case SkXfermode::kSrcOut_Mode:
570 case SkXfermode::kDstOut_Mode:
571 case SkXfermode::kSrcATop_Mode:
572 case SkXfermode::kDstATop_Mode:
573 case SkXfermode::kXor_Mode:
574 case SkXfermode::kPlus_Mode:
575 case SkXfermode::kModulate_Mode:
576 // Porter Duff Compositing Operators are not yet supported
577 // http://dev.w3.org/fxtf/compositing-1/#porterduffcompositingoperators
578 NOTREACHED();
579 return;
582 blend_mode_ = blend_mode;
583 SetNeedsCommit();
586 void Layer::SetIsRootForIsolatedGroup(bool root) {
587 DCHECK(IsPropertyChangeAllowed());
588 if (is_root_for_isolated_group_ == root)
589 return;
590 is_root_for_isolated_group_ = root;
591 SetNeedsCommit();
594 void Layer::SetContentsOpaque(bool opaque) {
595 DCHECK(IsPropertyChangeAllowed());
596 if (contents_opaque_ == opaque)
597 return;
598 contents_opaque_ = opaque;
599 SetNeedsCommit();
602 void Layer::SetPosition(const gfx::PointF& position) {
603 DCHECK(IsPropertyChangeAllowed());
604 if (position_ == position)
605 return;
606 position_ = position;
608 if (!layer_tree_host_)
609 return;
611 if (TransformNode* transform_node =
612 layer_tree_host_->property_trees()->transform_tree.Node(
613 transform_tree_index())) {
614 if (transform_node->owner_id == id()) {
615 transform_node->data.update_post_local_transform(position,
616 transform_origin());
617 transform_node->data.needs_local_transform_update = true;
618 layer_tree_host_->property_trees()->transform_tree.set_needs_update(true);
619 SetNeedsCommitNoRebuild();
620 return;
624 SetNeedsCommit();
627 bool Layer::IsContainerForFixedPositionLayers() const {
628 if (!transform_.IsIdentityOrTranslation())
629 return true;
630 if (parent_ && !parent_->transform_.IsIdentityOrTranslation())
631 return true;
632 return is_container_for_fixed_position_layers_;
635 bool Are2dAxisAligned(const gfx::Transform& a,
636 const gfx::Transform& b,
637 bool* is_invertible) {
638 if (a.IsScaleOrTranslation() && b.IsScaleOrTranslation()) {
639 *is_invertible = b.IsInvertible();
640 return true;
643 gfx::Transform inverse(gfx::Transform::kSkipInitialization);
644 *is_invertible = b.GetInverse(&inverse);
646 inverse *= a;
647 return inverse.Preserves2dAxisAlignment();
650 void Layer::SetTransform(const gfx::Transform& transform) {
651 DCHECK(IsPropertyChangeAllowed());
652 if (transform_ == transform)
653 return;
655 if (layer_tree_host_) {
656 if (TransformNode* transform_node =
657 layer_tree_host_->property_trees()->transform_tree.Node(
658 transform_tree_index())) {
659 if (transform_node->owner_id == id()) {
660 // We need to trigger a rebuild if we could have affected 2d axis
661 // alignment. We'll check to see if transform and transform_ are axis
662 // align with respect to one another.
663 bool invertible = false;
664 bool preserves_2d_axis_alignment =
665 Are2dAxisAligned(transform_, transform, &invertible);
666 transform_node->data.local = transform;
667 transform_node->data.needs_local_transform_update = true;
668 layer_tree_host_->property_trees()->transform_tree.set_needs_update(
669 true);
670 if (preserves_2d_axis_alignment)
671 SetNeedsCommitNoRebuild();
672 else
673 SetNeedsCommit();
674 transform_ = transform;
675 transform_is_invertible_ = invertible;
676 return;
681 transform_ = transform;
682 transform_is_invertible_ = transform.IsInvertible();
684 SetNeedsCommit();
687 void Layer::SetTransformOrigin(const gfx::Point3F& transform_origin) {
688 DCHECK(IsPropertyChangeAllowed());
689 if (transform_origin_ == transform_origin)
690 return;
691 transform_origin_ = transform_origin;
693 if (!layer_tree_host_)
694 return;
696 if (TransformNode* transform_node =
697 layer_tree_host_->property_trees()->transform_tree.Node(
698 transform_tree_index())) {
699 if (transform_node->owner_id == id()) {
700 transform_node->data.update_pre_local_transform(transform_origin);
701 transform_node->data.update_post_local_transform(position(),
702 transform_origin);
703 transform_node->data.needs_local_transform_update = true;
704 layer_tree_host_->property_trees()->transform_tree.set_needs_update(true);
705 SetNeedsCommitNoRebuild();
706 return;
710 SetNeedsCommit();
713 bool Layer::AnimationsPreserveAxisAlignment() const {
714 return layer_animation_controller_->AnimationsPreserveAxisAlignment();
717 bool Layer::TransformIsAnimating() const {
718 return layer_animation_controller_->IsAnimatingProperty(Animation::TRANSFORM);
721 void Layer::SetScrollParent(Layer* parent) {
722 DCHECK(IsPropertyChangeAllowed());
723 if (scroll_parent_ == parent)
724 return;
726 if (scroll_parent_)
727 scroll_parent_->RemoveScrollChild(this);
729 scroll_parent_ = parent;
731 if (scroll_parent_)
732 scroll_parent_->AddScrollChild(this);
734 SetNeedsCommit();
737 void Layer::AddScrollChild(Layer* child) {
738 if (!scroll_children_)
739 scroll_children_.reset(new std::set<Layer*>);
740 scroll_children_->insert(child);
741 SetNeedsCommit();
744 void Layer::RemoveScrollChild(Layer* child) {
745 scroll_children_->erase(child);
746 if (scroll_children_->empty())
747 scroll_children_ = nullptr;
748 SetNeedsCommit();
751 void Layer::SetClipParent(Layer* ancestor) {
752 DCHECK(IsPropertyChangeAllowed());
753 if (clip_parent_ == ancestor)
754 return;
756 if (clip_parent_)
757 clip_parent_->RemoveClipChild(this);
759 clip_parent_ = ancestor;
761 if (clip_parent_)
762 clip_parent_->AddClipChild(this);
764 SetNeedsCommit();
767 void Layer::AddClipChild(Layer* child) {
768 if (!clip_children_)
769 clip_children_.reset(new std::set<Layer*>);
770 clip_children_->insert(child);
771 SetNeedsCommit();
774 void Layer::RemoveClipChild(Layer* child) {
775 clip_children_->erase(child);
776 if (clip_children_->empty())
777 clip_children_ = nullptr;
778 SetNeedsCommit();
781 void Layer::SetScrollOffset(const gfx::ScrollOffset& scroll_offset) {
782 DCHECK(IsPropertyChangeAllowed());
784 if (scroll_offset_ == scroll_offset)
785 return;
786 scroll_offset_ = scroll_offset;
788 if (!layer_tree_host_)
789 return;
791 if (TransformNode* transform_node =
792 layer_tree_host_->property_trees()->transform_tree.Node(
793 transform_tree_index())) {
794 if (transform_node->owner_id == id()) {
795 transform_node->data.scroll_offset =
796 gfx::ScrollOffsetToVector2dF(CurrentScrollOffset());
797 transform_node->data.needs_local_transform_update = true;
798 layer_tree_host_->property_trees()->transform_tree.set_needs_update(true);
799 SetNeedsCommitNoRebuild();
800 return;
804 SetNeedsCommit();
807 void Layer::SetScrollCompensationAdjustment(
808 const gfx::Vector2dF& scroll_compensation_adjustment) {
809 if (scroll_compensation_adjustment_ == scroll_compensation_adjustment)
810 return;
811 scroll_compensation_adjustment_ = scroll_compensation_adjustment;
812 SetNeedsCommit();
815 gfx::Vector2dF Layer::ScrollCompensationAdjustment() const {
816 return scroll_compensation_adjustment_;
819 void Layer::SetScrollOffsetFromImplSide(
820 const gfx::ScrollOffset& scroll_offset) {
821 DCHECK(IsPropertyChangeAllowed());
822 // This function only gets called during a BeginMainFrame, so there
823 // is no need to call SetNeedsUpdate here.
824 DCHECK(layer_tree_host_ && layer_tree_host_->CommitRequested());
825 if (scroll_offset_ == scroll_offset)
826 return;
827 scroll_offset_ = scroll_offset;
828 SetNeedsPushProperties();
830 bool needs_rebuild = true;
831 if (TransformNode* transform_node =
832 layer_tree_host_->property_trees()->transform_tree.Node(
833 transform_tree_index())) {
834 if (transform_node->owner_id == id()) {
835 transform_node->data.scroll_offset =
836 gfx::ScrollOffsetToVector2dF(CurrentScrollOffset());
837 transform_node->data.needs_local_transform_update = true;
838 layer_tree_host_->property_trees()->transform_tree.set_needs_update(true);
839 needs_rebuild = false;
843 if (needs_rebuild)
844 layer_tree_host_->property_trees()->needs_rebuild = true;
846 if (!did_scroll_callback_.is_null())
847 did_scroll_callback_.Run();
848 // The callback could potentially change the layer structure:
849 // "this" may have been destroyed during the process.
852 void Layer::SetScrollClipLayerId(int clip_layer_id) {
853 DCHECK(IsPropertyChangeAllowed());
854 if (scroll_clip_layer_id_ == clip_layer_id)
855 return;
856 scroll_clip_layer_id_ = clip_layer_id;
857 SetNeedsCommit();
860 void Layer::SetUserScrollable(bool horizontal, bool vertical) {
861 DCHECK(IsPropertyChangeAllowed());
862 if (user_scrollable_horizontal_ == horizontal &&
863 user_scrollable_vertical_ == vertical)
864 return;
865 user_scrollable_horizontal_ = horizontal;
866 user_scrollable_vertical_ = vertical;
867 SetNeedsCommit();
870 void Layer::SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) {
871 DCHECK(IsPropertyChangeAllowed());
872 if (should_scroll_on_main_thread_ == should_scroll_on_main_thread)
873 return;
874 should_scroll_on_main_thread_ = should_scroll_on_main_thread;
875 SetNeedsCommit();
878 void Layer::SetHaveWheelEventHandlers(bool have_wheel_event_handlers) {
879 DCHECK(IsPropertyChangeAllowed());
880 if (have_wheel_event_handlers_ == have_wheel_event_handlers)
881 return;
882 have_wheel_event_handlers_ = have_wheel_event_handlers;
883 SetNeedsCommit();
886 void Layer::SetHaveScrollEventHandlers(bool have_scroll_event_handlers) {
887 DCHECK(IsPropertyChangeAllowed());
888 if (have_scroll_event_handlers_ == have_scroll_event_handlers)
889 return;
890 have_scroll_event_handlers_ = have_scroll_event_handlers;
891 SetNeedsCommit();
894 void Layer::SetNonFastScrollableRegion(const Region& region) {
895 DCHECK(IsPropertyChangeAllowed());
896 if (non_fast_scrollable_region_ == region)
897 return;
898 non_fast_scrollable_region_ = region;
899 SetNeedsCommit();
902 void Layer::SetTouchEventHandlerRegion(const Region& region) {
903 DCHECK(IsPropertyChangeAllowed());
904 if (touch_event_handler_region_ == region)
905 return;
906 touch_event_handler_region_ = region;
907 SetNeedsCommit();
910 void Layer::SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on) {
911 DCHECK(IsPropertyChangeAllowed());
912 if (scroll_blocks_on_ == scroll_blocks_on)
913 return;
914 scroll_blocks_on_ = scroll_blocks_on;
915 SetNeedsCommit();
918 void Layer::SetDrawCheckerboardForMissingTiles(bool checkerboard) {
919 DCHECK(IsPropertyChangeAllowed());
920 if (draw_checkerboard_for_missing_tiles_ == checkerboard)
921 return;
922 draw_checkerboard_for_missing_tiles_ = checkerboard;
923 SetNeedsCommit();
926 void Layer::SetForceRenderSurface(bool force) {
927 DCHECK(IsPropertyChangeAllowed());
928 if (force_render_surface_ == force)
929 return;
930 force_render_surface_ = force;
931 SetNeedsCommit();
934 void Layer::SetDoubleSided(bool double_sided) {
935 DCHECK(IsPropertyChangeAllowed());
936 if (double_sided_ == double_sided)
937 return;
938 double_sided_ = double_sided;
939 SetNeedsCommit();
942 void Layer::Set3dSortingContextId(int id) {
943 DCHECK(IsPropertyChangeAllowed());
944 if (id == sorting_context_id_)
945 return;
946 sorting_context_id_ = id;
947 SetNeedsCommit();
950 void Layer::SetShouldFlattenTransform(bool should_flatten) {
951 DCHECK(IsPropertyChangeAllowed());
952 if (should_flatten_transform_ == should_flatten)
953 return;
954 should_flatten_transform_ = should_flatten;
955 SetNeedsCommit();
958 void Layer::SetIsDrawable(bool is_drawable) {
959 DCHECK(IsPropertyChangeAllowed());
960 if (is_drawable_ == is_drawable)
961 return;
963 is_drawable_ = is_drawable;
964 UpdateDrawsContent(HasDrawableContent());
967 void Layer::SetHideLayerAndSubtree(bool hide) {
968 DCHECK(IsPropertyChangeAllowed());
969 if (hide_layer_and_subtree_ == hide)
970 return;
972 hide_layer_and_subtree_ = hide;
973 SetNeedsCommit();
976 void Layer::SetNeedsDisplayRect(const gfx::Rect& dirty_rect) {
977 if (dirty_rect.IsEmpty())
978 return;
980 SetNeedsPushProperties();
981 update_rect_.Union(dirty_rect);
983 if (DrawsContent())
984 SetNeedsUpdate();
987 bool Layer::DescendantIsFixedToContainerLayer() const {
988 for (size_t i = 0; i < children_.size(); ++i) {
989 if (children_[i]->position_constraint_.is_fixed_position() ||
990 children_[i]->DescendantIsFixedToContainerLayer())
991 return true;
993 return false;
996 void Layer::SetIsContainerForFixedPositionLayers(bool container) {
997 if (is_container_for_fixed_position_layers_ == container)
998 return;
999 is_container_for_fixed_position_layers_ = container;
1001 if (layer_tree_host_ && layer_tree_host_->CommitRequested())
1002 return;
1004 // Only request a commit if we have a fixed positioned descendant.
1005 if (DescendantIsFixedToContainerLayer())
1006 SetNeedsCommit();
1009 void Layer::SetPositionConstraint(const LayerPositionConstraint& constraint) {
1010 DCHECK(IsPropertyChangeAllowed());
1011 if (position_constraint_ == constraint)
1012 return;
1013 position_constraint_ = constraint;
1014 SetNeedsCommit();
1017 static void RunCopyCallbackOnMainThread(scoped_ptr<CopyOutputRequest> request,
1018 scoped_ptr<CopyOutputResult> result) {
1019 request->SendResult(result.Pass());
1022 static void PostCopyCallbackToMainThread(
1023 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner,
1024 scoped_ptr<CopyOutputRequest> request,
1025 scoped_ptr<CopyOutputResult> result) {
1026 main_thread_task_runner->PostTask(FROM_HERE,
1027 base::Bind(&RunCopyCallbackOnMainThread,
1028 base::Passed(&request),
1029 base::Passed(&result)));
1032 void Layer::PushPropertiesTo(LayerImpl* layer) {
1033 DCHECK(layer_tree_host_);
1035 // If we did not SavePaintProperties() for the layer this frame, then push the
1036 // real property values, not the paint property values.
1037 bool use_paint_properties = paint_properties_.source_frame_number ==
1038 layer_tree_host_->source_frame_number();
1040 layer->SetTransformOrigin(transform_origin_);
1041 layer->SetBackgroundColor(background_color_);
1042 layer->SetBounds(use_paint_properties ? paint_properties_.bounds
1043 : bounds_);
1044 layer->SetContentBounds(content_bounds());
1045 layer->SetContentsScale(contents_scale_x(), contents_scale_y());
1047 if (frame_viewer_instrumentation::IsTracingLayerTreeSnapshots())
1048 layer->SetDebugInfo(TakeDebugInfo());
1050 layer->SetDoubleSided(double_sided_);
1051 layer->SetDrawCheckerboardForMissingTiles(
1052 draw_checkerboard_for_missing_tiles_);
1053 layer->SetDrawsContent(DrawsContent());
1054 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_);
1055 layer->SetHasRenderSurface(has_render_surface_ || layer->HasCopyRequest());
1056 if (!layer->FilterIsAnimatingOnImplOnly() && !FilterIsAnimating())
1057 layer->SetFilters(filters_);
1058 DCHECK(!(FilterIsAnimating() && layer->FilterIsAnimatingOnImplOnly()));
1059 layer->SetBackgroundFilters(background_filters());
1060 layer->SetMasksToBounds(masks_to_bounds_);
1061 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_);
1062 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
1063 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_);
1064 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
1065 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
1066 layer->SetScrollBlocksOn(scroll_blocks_on_);
1067 layer->SetContentsOpaque(contents_opaque_);
1068 if (!layer->OpacityIsAnimatingOnImplOnly() && !OpacityIsAnimating())
1069 layer->SetOpacity(opacity_);
1070 DCHECK(!(OpacityIsAnimating() && layer->OpacityIsAnimatingOnImplOnly()));
1071 layer->SetBlendMode(blend_mode_);
1072 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_);
1073 layer->SetPosition(position_);
1074 layer->SetIsContainerForFixedPositionLayers(
1075 IsContainerForFixedPositionLayers());
1076 layer->SetPositionConstraint(position_constraint_);
1077 layer->SetShouldFlattenTransform(should_flatten_transform_);
1078 layer->set_should_flatten_transform_from_property_tree(
1079 should_flatten_transform_from_property_tree_);
1080 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
1081 if (!layer->TransformIsAnimatingOnImplOnly() && !TransformIsAnimating())
1082 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
1083 DCHECK(!(TransformIsAnimating() && layer->TransformIsAnimatingOnImplOnly()));
1084 layer->Set3dSortingContextId(sorting_context_id_);
1085 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
1086 layer->set_transform_tree_index(transform_tree_index_);
1087 layer->set_opacity_tree_index(opacity_tree_index_);
1088 layer->set_clip_tree_index(clip_tree_index_);
1089 layer->set_offset_to_transform_parent(offset_to_transform_parent_);
1091 layer->SetScrollClipLayer(scroll_clip_layer_id_);
1092 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
1093 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
1095 LayerImpl* scroll_parent = nullptr;
1096 if (scroll_parent_) {
1097 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
1098 DCHECK(scroll_parent);
1101 layer->SetScrollParent(scroll_parent);
1102 if (scroll_children_) {
1103 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
1104 for (std::set<Layer*>::iterator it = scroll_children_->begin();
1105 it != scroll_children_->end();
1106 ++it) {
1107 DCHECK_EQ((*it)->scroll_parent(), this);
1108 LayerImpl* scroll_child =
1109 layer->layer_tree_impl()->LayerById((*it)->id());
1110 DCHECK(scroll_child);
1111 scroll_children->insert(scroll_child);
1113 layer->SetScrollChildren(scroll_children);
1114 } else {
1115 layer->SetScrollChildren(nullptr);
1118 LayerImpl* clip_parent = nullptr;
1119 if (clip_parent_) {
1120 clip_parent =
1121 layer->layer_tree_impl()->LayerById(clip_parent_->id());
1122 DCHECK(clip_parent);
1125 layer->SetClipParent(clip_parent);
1126 if (clip_children_) {
1127 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>;
1128 for (std::set<Layer*>::iterator it = clip_children_->begin();
1129 it != clip_children_->end(); ++it) {
1130 DCHECK_EQ((*it)->clip_parent(), this);
1131 LayerImpl* clip_child = layer->layer_tree_impl()->LayerById((*it)->id());
1132 DCHECK(clip_child);
1133 clip_children->insert(clip_child);
1135 layer->SetClipChildren(clip_children);
1136 } else {
1137 layer->SetClipChildren(nullptr);
1140 // When a scroll offset animation is interrupted the new scroll position on
1141 // the pending tree will clobber any impl-side scrolling occuring on the
1142 // active tree. To do so, avoid scrolling the pending tree along with it
1143 // instead of trying to undo that scrolling later.
1144 if (layer_animation_controller_->scroll_offset_animation_was_interrupted())
1145 layer->PushScrollOffsetFromMainThreadAndClobberActiveValue(scroll_offset_);
1146 else
1147 layer->PushScrollOffsetFromMainThread(scroll_offset_);
1148 layer->SetScrollCompensationAdjustment(ScrollCompensationAdjustment());
1150 // Wrap the copy_requests_ in a PostTask to the main thread.
1151 ScopedPtrVector<CopyOutputRequest> main_thread_copy_requests;
1152 for (ScopedPtrVector<CopyOutputRequest>::iterator it = copy_requests_.begin();
1153 it != copy_requests_.end();
1154 ++it) {
1155 scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner =
1156 layer_tree_host()->proxy()->MainThreadTaskRunner();
1157 scoped_ptr<CopyOutputRequest> original_request = copy_requests_.take(it);
1158 const CopyOutputRequest& original_request_ref = *original_request;
1159 scoped_ptr<CopyOutputRequest> main_thread_request =
1160 CopyOutputRequest::CreateRelayRequest(
1161 original_request_ref,
1162 base::Bind(&PostCopyCallbackToMainThread,
1163 main_thread_task_runner,
1164 base::Passed(&original_request)));
1165 main_thread_copy_requests.push_back(main_thread_request.Pass());
1167 if (!copy_requests_.empty() && layer_tree_host_)
1168 layer_tree_host_->property_trees()->needs_rebuild = true;
1169 copy_requests_.clear();
1170 layer->PassCopyRequests(&main_thread_copy_requests);
1172 // If the main thread commits multiple times before the impl thread actually
1173 // draws, then damage tracking will become incorrect if we simply clobber the
1174 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
1175 // union) any update changes that have occurred on the main thread.
1176 update_rect_.Union(layer->update_rect());
1177 layer->SetUpdateRect(update_rect_);
1179 layer->SetStackingOrderChanged(stacking_order_changed_);
1181 layer_animation_controller_->PushAnimationUpdatesTo(
1182 layer->layer_animation_controller());
1184 if (frame_timing_requests_dirty_) {
1185 layer->PassFrameTimingRequests(&frame_timing_requests_);
1186 frame_timing_requests_dirty_ = false;
1189 // Reset any state that should be cleared for the next update.
1190 stacking_order_changed_ = false;
1191 update_rect_ = gfx::Rect();
1193 needs_push_properties_ = false;
1194 num_dependents_need_push_properties_ = 0;
1197 scoped_ptr<LayerImpl> Layer::CreateLayerImpl(LayerTreeImpl* tree_impl) {
1198 return LayerImpl::Create(tree_impl, layer_id_,
1199 new LayerImpl::SyncedScrollOffset);
1202 bool Layer::DrawsContent() const {
1203 return draws_content_;
1206 bool Layer::HasDrawableContent() const {
1207 return is_drawable_;
1210 void Layer::UpdateDrawsContent(bool has_drawable_content) {
1211 bool draws_content = has_drawable_content;
1212 DCHECK(is_drawable_ || !has_drawable_content);
1213 if (draws_content == draws_content_)
1214 return;
1216 if (HasDelegatedContent()) {
1217 // Layers with delegated content need to be treated as if they have as
1218 // many children as the number of layers they own delegated quads for.
1219 // Since we don't know this number right now, we choose one that acts like
1220 // infinity for our purposes.
1221 AddDrawableDescendants(draws_content ? 1000 : -1000);
1224 if (parent())
1225 parent()->AddDrawableDescendants(draws_content ? 1 : -1);
1227 draws_content_ = draws_content;
1228 SetNeedsCommit();
1231 int Layer::NumDescendantsThatDrawContent() const {
1232 return num_descendants_that_draw_content_;
1235 void Layer::SavePaintProperties() {
1236 DCHECK(layer_tree_host_);
1238 // TODO(reveman): Save all layer properties that we depend on not
1239 // changing until PushProperties() has been called. crbug.com/231016
1240 paint_properties_.bounds = bounds_;
1241 paint_properties_.source_frame_number =
1242 layer_tree_host_->source_frame_number();
1245 bool Layer::Update(ResourceUpdateQueue* queue,
1246 const OcclusionTracker<Layer>* occlusion) {
1247 DCHECK(layer_tree_host_);
1248 DCHECK_EQ(layer_tree_host_->source_frame_number(),
1249 paint_properties_.source_frame_number) <<
1250 "SavePaintProperties must be called for any layer that is painted.";
1251 return false;
1254 bool Layer::NeedMoreUpdates() {
1255 return false;
1258 bool Layer::IsSuitableForGpuRasterization() const {
1259 return true;
1262 scoped_refptr<base::trace_event::ConvertableToTraceFormat>
1263 Layer::TakeDebugInfo() {
1264 if (client_)
1265 return client_->TakeDebugInfo();
1266 else
1267 return nullptr;
1270 void Layer::SetHasRenderSurface(bool has_render_surface) {
1271 if (has_render_surface_ == has_render_surface)
1272 return;
1273 has_render_surface_ = has_render_surface;
1274 // We do not need SetNeedsCommit here, since this is only ever called
1275 // during a commit, from CalculateDrawProperties.
1276 SetNeedsPushProperties();
1279 void Layer::CreateRenderSurface() {
1280 DCHECK(!render_surface_);
1281 render_surface_ = make_scoped_ptr(new RenderSurface(this));
1284 void Layer::ClearRenderSurface() {
1285 render_surface_ = nullptr;
1288 void Layer::ClearRenderSurfaceLayerList() {
1289 if (render_surface_)
1290 render_surface_->ClearLayerLists();
1293 gfx::ScrollOffset Layer::ScrollOffsetForAnimation() const {
1294 return CurrentScrollOffset();
1297 // On<Property>Animated is called due to an ongoing accelerated animation.
1298 // Since this animation is also being run on the compositor thread, there
1299 // is no need to request a commit to push this value over, so the value is
1300 // set directly rather than by calling Set<Property>.
1301 void Layer::OnFilterAnimated(const FilterOperations& filters) {
1302 filters_ = filters;
1305 void Layer::OnOpacityAnimated(float opacity) {
1306 opacity_ = opacity;
1307 if (layer_tree_host_) {
1308 if (OpacityNode* node =
1309 layer_tree_host_->property_trees()->opacity_tree.Node(
1310 opacity_tree_index_)) {
1311 if (node->owner_id == id())
1312 node->data = opacity;
1317 void Layer::OnTransformAnimated(const gfx::Transform& transform) {
1318 if (transform_ == transform)
1319 return;
1320 transform_ = transform;
1321 transform_is_invertible_ = transform.IsInvertible();
1322 if (layer_tree_host_) {
1323 if (TransformNode* node =
1324 layer_tree_host_->property_trees()->transform_tree.Node(
1325 transform_tree_index_)) {
1326 if (node->owner_id == id()) {
1327 node->data.local = transform;
1328 node->data.needs_local_transform_update = true;
1329 node->data.is_animated = true;
1330 layer_tree_host_->property_trees()->transform_tree.set_needs_update(
1331 true);
1337 void Layer::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
1338 // Do nothing. Scroll deltas will be sent from the compositor thread back
1339 // to the main thread in the same manner as during non-animated
1340 // compositor-driven scrolling.
1343 void Layer::OnAnimationWaitingForDeletion() {
1344 // Animations are only deleted during PushProperties.
1345 SetNeedsPushProperties();
1348 bool Layer::IsActive() const {
1349 return true;
1352 bool Layer::AddAnimation(scoped_ptr <Animation> animation) {
1353 if (!layer_animation_controller_->animation_registrar())
1354 return false;
1356 if (animation->target_property() == Animation::SCROLL_OFFSET &&
1357 !layer_animation_controller_->animation_registrar()
1358 ->supports_scroll_animations())
1359 return false;
1361 UMA_HISTOGRAM_BOOLEAN("Renderer.AnimationAddedToOrphanLayer",
1362 !layer_tree_host_);
1363 layer_animation_controller_->AddAnimation(animation.Pass());
1364 SetNeedsCommit();
1365 return true;
1368 void Layer::PauseAnimation(int animation_id, double time_offset) {
1369 layer_animation_controller_->PauseAnimation(
1370 animation_id, base::TimeDelta::FromSecondsD(time_offset));
1371 SetNeedsCommit();
1374 void Layer::RemoveAnimation(int animation_id) {
1375 layer_animation_controller_->RemoveAnimation(animation_id);
1376 SetNeedsCommit();
1379 void Layer::RemoveAnimation(int animation_id,
1380 Animation::TargetProperty property) {
1381 layer_animation_controller_->RemoveAnimation(animation_id, property);
1382 SetNeedsCommit();
1385 void Layer::SetLayerAnimationControllerForTest(
1386 scoped_refptr<LayerAnimationController> controller) {
1387 layer_animation_controller_->RemoveValueObserver(this);
1388 layer_animation_controller_ = controller;
1389 layer_animation_controller_->AddValueObserver(this);
1390 SetNeedsCommit();
1393 bool Layer::HasActiveAnimation() const {
1394 return layer_animation_controller_->HasActiveAnimation();
1397 void Layer::AddLayerAnimationEventObserver(
1398 LayerAnimationEventObserver* animation_observer) {
1399 layer_animation_controller_->AddEventObserver(animation_observer);
1402 void Layer::RemoveLayerAnimationEventObserver(
1403 LayerAnimationEventObserver* animation_observer) {
1404 layer_animation_controller_->RemoveEventObserver(animation_observer);
1407 SimpleEnclosedRegion Layer::VisibleContentOpaqueRegion() const {
1408 if (contents_opaque())
1409 return SimpleEnclosedRegion(visible_content_rect());
1410 return SimpleEnclosedRegion();
1413 ScrollbarLayerInterface* Layer::ToScrollbarLayer() {
1414 return nullptr;
1417 RenderingStatsInstrumentation* Layer::rendering_stats_instrumentation() const {
1418 return layer_tree_host_->rendering_stats_instrumentation();
1421 void Layer::RemoveFromScrollTree() {
1422 if (scroll_children_.get()) {
1423 std::set<Layer*> copy = *scroll_children_;
1424 for (std::set<Layer*>::iterator it = copy.begin(); it != copy.end(); ++it)
1425 (*it)->SetScrollParent(nullptr);
1428 DCHECK(!scroll_children_);
1429 SetScrollParent(nullptr);
1432 void Layer::RemoveFromClipTree() {
1433 if (clip_children_.get()) {
1434 std::set<Layer*> copy = *clip_children_;
1435 for (std::set<Layer*>::iterator it = copy.begin(); it != copy.end(); ++it)
1436 (*it)->SetClipParent(nullptr);
1439 DCHECK(!clip_children_);
1440 SetClipParent(nullptr);
1443 void Layer::AddDrawableDescendants(int num) {
1444 DCHECK_GE(num_descendants_that_draw_content_, 0);
1445 DCHECK_GE(num_descendants_that_draw_content_ + num, 0);
1446 if (num == 0)
1447 return;
1448 num_descendants_that_draw_content_ += num;
1449 SetNeedsCommit();
1450 if (parent())
1451 parent()->AddDrawableDescendants(num);
1454 void Layer::RunMicroBenchmark(MicroBenchmark* benchmark) {
1455 benchmark->RunOnLayer(this);
1458 bool Layer::HasDelegatedContent() const {
1459 return false;
1462 void Layer::SetFrameTimingRequests(
1463 const std::vector<FrameTimingRequest>& requests) {
1464 frame_timing_requests_ = requests;
1465 frame_timing_requests_dirty_ = true;
1466 SetNeedsCommit();
1469 void Layer::DidBeginTracing() {
1470 // We'll be dumping layer trees as part of trace, so make sure
1471 // PushPropertiesTo() propagates layer debug info to the impl
1472 // side -- otherwise this won't happen for the the layers that
1473 // remain unchanged since tracing started.
1474 SetNeedsPushProperties();
1477 } // namespace cc