Delete unused downloads page asset.
[chromium-blink-merge.git] / cc / layers / layer_impl.cc
blob970789ff795942011db820793a1f56f15b73dc2e
1 // Copyright 2012 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_impl.h"
7 #include "base/json/json_reader.h"
8 #include "base/numerics/safe_conversions.h"
9 #include "base/strings/stringprintf.h"
10 #include "base/trace_event/trace_event.h"
11 #include "base/trace_event/trace_event_argument.h"
12 #include "cc/animation/animation_registrar.h"
13 #include "cc/animation/scrollbar_animation_controller.h"
14 #include "cc/base/math_util.h"
15 #include "cc/base/simple_enclosed_region.h"
16 #include "cc/debug/debug_colors.h"
17 #include "cc/debug/layer_tree_debug_state.h"
18 #include "cc/debug/micro_benchmark_impl.h"
19 #include "cc/debug/traced_value.h"
20 #include "cc/input/scroll_state.h"
21 #include "cc/layers/layer_utils.h"
22 #include "cc/layers/painted_scrollbar_layer_impl.h"
23 #include "cc/output/copy_output_request.h"
24 #include "cc/quads/debug_border_draw_quad.h"
25 #include "cc/quads/render_pass.h"
26 #include "cc/trees/layer_tree_host_common.h"
27 #include "cc/trees/layer_tree_impl.h"
28 #include "cc/trees/layer_tree_settings.h"
29 #include "cc/trees/proxy.h"
30 #include "ui/gfx/geometry/box_f.h"
31 #include "ui/gfx/geometry/point_conversions.h"
32 #include "ui/gfx/geometry/quad_f.h"
33 #include "ui/gfx/geometry/rect_conversions.h"
34 #include "ui/gfx/geometry/size_conversions.h"
35 #include "ui/gfx/geometry/vector2d_conversions.h"
37 namespace cc {
38 LayerImpl::LayerImpl(LayerTreeImpl* layer_impl, int id)
39 : LayerImpl(layer_impl, id, new LayerImpl::SyncedScrollOffset) {
42 LayerImpl::LayerImpl(LayerTreeImpl* tree_impl,
43 int id,
44 scoped_refptr<SyncedScrollOffset> scroll_offset)
45 : parent_(nullptr),
46 scroll_parent_(nullptr),
47 clip_parent_(nullptr),
48 mask_layer_id_(-1),
49 replica_layer_id_(-1),
50 layer_id_(id),
51 layer_tree_impl_(tree_impl),
52 scroll_offset_(scroll_offset),
53 scroll_clip_layer_(nullptr),
54 should_scroll_on_main_thread_(false),
55 have_wheel_event_handlers_(false),
56 have_scroll_event_handlers_(false),
57 scroll_blocks_on_(SCROLL_BLOCKS_ON_NONE),
58 user_scrollable_horizontal_(true),
59 user_scrollable_vertical_(true),
60 stacking_order_changed_(false),
61 double_sided_(true),
62 should_flatten_transform_(true),
63 should_flatten_transform_from_property_tree_(false),
64 is_clipped_(false),
65 layer_property_changed_(false),
66 masks_to_bounds_(false),
67 contents_opaque_(false),
68 is_root_for_isolated_group_(false),
69 use_parent_backface_visibility_(false),
70 draws_content_(false),
71 hide_layer_and_subtree_(false),
72 transform_is_invertible_(true),
73 is_container_for_fixed_position_layers_(false),
74 is_affected_by_page_scale_(true),
75 background_color_(0),
76 opacity_(1.0),
77 blend_mode_(SkXfermode::kSrcOver_Mode),
78 draw_blend_mode_(SkXfermode::kSrcOver_Mode),
79 num_descendants_that_draw_content_(0),
80 transform_tree_index_(-1),
81 effect_tree_index_(-1),
82 clip_tree_index_(-1),
83 draw_depth_(0.f),
84 needs_push_properties_(false),
85 num_dependents_need_push_properties_(0),
86 sorting_context_id_(0),
87 current_draw_mode_(DRAW_MODE_NONE),
88 frame_timing_requests_dirty_(false),
89 visited_(false),
90 layer_or_descendant_is_drawn_(false),
91 sorted_for_recursion_(false) {
92 DCHECK_GT(layer_id_, 0);
93 DCHECK(layer_tree_impl_);
94 layer_tree_impl_->RegisterLayer(this);
96 if (!layer_tree_impl_->settings().use_compositor_animation_timelines) {
97 AnimationRegistrar* registrar = layer_tree_impl_->GetAnimationRegistrar();
98 layer_animation_controller_ =
99 registrar->GetAnimationControllerForId(layer_id_);
100 layer_animation_controller_->AddValueObserver(this);
101 if (IsActive()) {
102 layer_animation_controller_->set_value_provider(this);
103 layer_animation_controller_->set_layer_animation_delegate(this);
106 SetNeedsPushProperties();
109 LayerImpl::~LayerImpl() {
110 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
112 if (layer_animation_controller_) {
113 layer_animation_controller_->RemoveValueObserver(this);
114 layer_animation_controller_->remove_value_provider(this);
115 layer_animation_controller_->remove_layer_animation_delegate(this);
118 if (!copy_requests_.empty() && layer_tree_impl_->IsActiveTree())
119 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
120 layer_tree_impl_->UnregisterLayer(this);
122 TRACE_EVENT_OBJECT_DELETED_WITH_ID(
123 TRACE_DISABLED_BY_DEFAULT("cc.debug"), "cc::LayerImpl", this);
126 void LayerImpl::AddChild(scoped_ptr<LayerImpl> child) {
127 child->SetParent(this);
128 DCHECK_EQ(layer_tree_impl(), child->layer_tree_impl());
129 children_.push_back(child.Pass());
130 layer_tree_impl()->set_needs_update_draw_properties();
133 scoped_ptr<LayerImpl> LayerImpl::RemoveChild(LayerImpl* child) {
134 for (OwnedLayerImplList::iterator it = children_.begin();
135 it != children_.end();
136 ++it) {
137 if (*it == child) {
138 scoped_ptr<LayerImpl> ret = children_.take(it);
139 children_.erase(it);
140 layer_tree_impl()->set_needs_update_draw_properties();
141 return ret.Pass();
144 return nullptr;
147 void LayerImpl::SetParent(LayerImpl* parent) {
148 if (parent_should_know_need_push_properties()) {
149 if (parent_)
150 parent_->RemoveDependentNeedsPushProperties();
151 if (parent)
152 parent->AddDependentNeedsPushProperties();
154 parent_ = parent;
157 void LayerImpl::ClearChildList() {
158 if (children_.empty())
159 return;
161 children_.clear();
162 layer_tree_impl()->set_needs_update_draw_properties();
165 bool LayerImpl::HasAncestor(const LayerImpl* ancestor) const {
166 if (!ancestor)
167 return false;
169 for (const LayerImpl* layer = this; layer; layer = layer->parent()) {
170 if (layer == ancestor)
171 return true;
174 return false;
177 void LayerImpl::SetScrollParent(LayerImpl* parent) {
178 if (scroll_parent_ == parent)
179 return;
181 if (parent)
182 DCHECK_EQ(layer_tree_impl()->LayerById(parent->id()), parent);
184 scroll_parent_ = parent;
185 SetNeedsPushProperties();
188 void LayerImpl::SetDebugInfo(
189 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other) {
190 debug_info_ = other;
191 SetNeedsPushProperties();
194 void LayerImpl::SetScrollChildren(std::set<LayerImpl*>* children) {
195 if (scroll_children_.get() == children)
196 return;
197 scroll_children_.reset(children);
198 SetNeedsPushProperties();
201 void LayerImpl::DistributeScroll(ScrollState* scroll_state) {
202 DCHECK(scroll_state);
203 if (scroll_state->FullyConsumed())
204 return;
206 scroll_state->DistributeToScrollChainDescendant();
208 // If the scroll doesn't propagate, and we're currently scrolling
209 // a layer other than this one, prevent the scroll from
210 // propagating to this layer.
211 if (!scroll_state->should_propagate() &&
212 scroll_state->delta_consumed_for_scroll_sequence() &&
213 scroll_state->current_native_scrolling_layer() != this) {
214 return;
217 ApplyScroll(scroll_state);
220 void LayerImpl::ApplyScroll(ScrollState* scroll_state) {
221 DCHECK(scroll_state);
222 layer_tree_impl()->ApplyScroll(this, scroll_state);
225 void LayerImpl::SetNumDescendantsThatDrawContent(int num_descendants) {
226 if (num_descendants_that_draw_content_ == num_descendants)
227 return;
228 num_descendants_that_draw_content_ = num_descendants;
229 SetNeedsPushProperties();
232 void LayerImpl::SetClipParent(LayerImpl* ancestor) {
233 if (clip_parent_ == ancestor)
234 return;
236 clip_parent_ = ancestor;
237 SetNeedsPushProperties();
240 void LayerImpl::SetClipChildren(std::set<LayerImpl*>* children) {
241 if (clip_children_.get() == children)
242 return;
243 clip_children_.reset(children);
244 SetNeedsPushProperties();
247 void LayerImpl::SetTransformTreeIndex(int index) {
248 transform_tree_index_ = index;
249 SetNeedsPushProperties();
252 void LayerImpl::SetClipTreeIndex(int index) {
253 clip_tree_index_ = index;
254 SetNeedsPushProperties();
257 void LayerImpl::SetEffectTreeIndex(int index) {
258 effect_tree_index_ = index;
259 SetNeedsPushProperties();
262 void LayerImpl::PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests) {
263 // In the case that a layer still has a copy request, this means that there's
264 // a commit to the active tree without a draw. This only happens in some
265 // edge cases during lost context or visibility changes, so don't try to
266 // handle preserving these output requests (and their surface).
267 if (!copy_requests_.empty()) {
268 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
269 // Destroying these will abort them.
270 copy_requests_.clear();
273 if (requests->empty())
274 return;
276 DCHECK(render_surface());
277 bool was_empty = copy_requests_.empty();
278 copy_requests_.insert_and_take(copy_requests_.end(), requests);
279 requests->clear();
281 if (was_empty && layer_tree_impl()->IsActiveTree())
282 layer_tree_impl()->AddLayerWithCopyOutputRequest(this);
283 NoteLayerPropertyChangedForSubtree();
286 void LayerImpl::TakeCopyRequestsAndTransformToTarget(
287 ScopedPtrVector<CopyOutputRequest>* requests) {
288 DCHECK(!copy_requests_.empty());
289 DCHECK(layer_tree_impl()->IsActiveTree());
290 DCHECK_EQ(render_target(), this);
292 size_t first_inserted_request = requests->size();
293 requests->insert_and_take(requests->end(), &copy_requests_);
294 copy_requests_.clear();
296 for (size_t i = first_inserted_request; i < requests->size(); ++i) {
297 CopyOutputRequest* request = requests->at(i);
298 if (!request->has_area())
299 continue;
301 gfx::Rect request_in_layer_space = request->area();
302 request_in_layer_space.Intersect(gfx::Rect(bounds()));
303 request->set_area(MathUtil::MapEnclosingClippedRect(
304 draw_properties_.target_space_transform, request_in_layer_space));
307 layer_tree_impl()->RemoveLayerWithCopyOutputRequest(this);
308 layer_tree_impl()->set_needs_update_draw_properties();
311 void LayerImpl::ClearRenderSurfaceLayerList() {
312 if (render_surface_)
313 render_surface_->ClearLayerLists();
316 void LayerImpl::PopulateSharedQuadState(SharedQuadState* state) const {
317 state->SetAll(draw_properties_.target_space_transform, bounds(),
318 draw_properties_.visible_layer_rect, draw_properties_.clip_rect,
319 is_clipped_, draw_properties_.opacity, draw_blend_mode_,
320 sorting_context_id_);
323 void LayerImpl::PopulateScaledSharedQuadState(SharedQuadState* state,
324 float scale) const {
325 gfx::Transform scaled_draw_transform =
326 draw_properties_.target_space_transform;
327 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
328 gfx::Size scaled_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale));
329 gfx::Rect scaled_visible_layer_rect =
330 gfx::ScaleToEnclosingRect(visible_layer_rect(), scale);
331 scaled_visible_layer_rect.Intersect(gfx::Rect(scaled_bounds));
333 state->SetAll(scaled_draw_transform, scaled_bounds, scaled_visible_layer_rect,
334 draw_properties().clip_rect, is_clipped_,
335 draw_properties().opacity, draw_blend_mode_,
336 sorting_context_id_);
339 bool LayerImpl::WillDraw(DrawMode draw_mode,
340 ResourceProvider* resource_provider) {
341 // WillDraw/DidDraw must be matched.
342 DCHECK_NE(DRAW_MODE_NONE, draw_mode);
343 DCHECK_EQ(DRAW_MODE_NONE, current_draw_mode_);
344 current_draw_mode_ = draw_mode;
345 return true;
348 void LayerImpl::DidDraw(ResourceProvider* resource_provider) {
349 DCHECK_NE(DRAW_MODE_NONE, current_draw_mode_);
350 current_draw_mode_ = DRAW_MODE_NONE;
353 bool LayerImpl::ShowDebugBorders() const {
354 return layer_tree_impl()->debug_state().show_debug_borders;
357 void LayerImpl::GetDebugBorderProperties(SkColor* color, float* width) const {
358 if (draws_content_) {
359 *color = DebugColors::ContentLayerBorderColor();
360 *width = DebugColors::ContentLayerBorderWidth(layer_tree_impl());
361 return;
364 if (masks_to_bounds_) {
365 *color = DebugColors::MaskingLayerBorderColor();
366 *width = DebugColors::MaskingLayerBorderWidth(layer_tree_impl());
367 return;
370 *color = DebugColors::ContainerLayerBorderColor();
371 *width = DebugColors::ContainerLayerBorderWidth(layer_tree_impl());
374 void LayerImpl::AppendDebugBorderQuad(
375 RenderPass* render_pass,
376 const gfx::Size& bounds,
377 const SharedQuadState* shared_quad_state,
378 AppendQuadsData* append_quads_data) const {
379 SkColor color;
380 float width;
381 GetDebugBorderProperties(&color, &width);
382 AppendDebugBorderQuad(render_pass, bounds, shared_quad_state,
383 append_quads_data, color, width);
386 void LayerImpl::AppendDebugBorderQuad(RenderPass* render_pass,
387 const gfx::Size& bounds,
388 const SharedQuadState* shared_quad_state,
389 AppendQuadsData* append_quads_data,
390 SkColor color,
391 float width) const {
392 if (!ShowDebugBorders())
393 return;
395 gfx::Rect quad_rect(bounds);
396 gfx::Rect visible_quad_rect(quad_rect);
397 DebugBorderDrawQuad* debug_border_quad =
398 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
399 debug_border_quad->SetNew(
400 shared_quad_state, quad_rect, visible_quad_rect, color, width);
401 if (contents_opaque()) {
402 // When opaque, draw a second inner border that is thicker than the outer
403 // border, but more transparent.
404 static const float kFillOpacity = 0.3f;
405 SkColor fill_color = SkColorSetA(
406 color, static_cast<uint8_t>(SkColorGetA(color) * kFillOpacity));
407 float fill_width = width * 3;
408 gfx::Rect fill_rect = quad_rect;
409 fill_rect.Inset(fill_width / 2.f, fill_width / 2.f);
410 if (fill_rect.IsEmpty())
411 return;
412 gfx::Rect visible_fill_rect =
413 gfx::IntersectRects(visible_quad_rect, fill_rect);
414 DebugBorderDrawQuad* fill_quad =
415 render_pass->CreateAndAppendDrawQuad<DebugBorderDrawQuad>();
416 fill_quad->SetNew(shared_quad_state, fill_rect, visible_fill_rect,
417 fill_color, fill_width);
421 bool LayerImpl::HasDelegatedContent() const {
422 return false;
425 bool LayerImpl::HasContributingDelegatedRenderPasses() const {
426 return false;
429 RenderPassId LayerImpl::FirstContributingRenderPassId() const {
430 return RenderPassId(0, 0);
433 RenderPassId LayerImpl::NextContributingRenderPassId(RenderPassId id) const {
434 return RenderPassId(0, 0);
437 void LayerImpl::GetContentsResourceId(ResourceId* resource_id,
438 gfx::Size* resource_size) const {
439 NOTREACHED();
440 *resource_id = 0;
443 gfx::Vector2dF LayerImpl::ScrollBy(const gfx::Vector2dF& scroll) {
444 gfx::ScrollOffset adjusted_scroll(scroll);
445 if (!user_scrollable_horizontal_)
446 adjusted_scroll.set_x(0);
447 if (!user_scrollable_vertical_)
448 adjusted_scroll.set_y(0);
449 DCHECK(scrollable());
450 gfx::ScrollOffset old_offset = CurrentScrollOffset();
451 gfx::ScrollOffset new_offset =
452 ClampScrollOffsetToLimits(old_offset + adjusted_scroll);
453 SetCurrentScrollOffset(new_offset);
455 gfx::ScrollOffset unscrolled =
456 old_offset + gfx::ScrollOffset(scroll) - new_offset;
457 return gfx::Vector2dF(unscrolled.x(), unscrolled.y());
460 void LayerImpl::SetScrollClipLayer(int scroll_clip_layer_id) {
461 scroll_clip_layer_ = layer_tree_impl()->LayerById(scroll_clip_layer_id);
464 bool LayerImpl::user_scrollable(ScrollbarOrientation orientation) const {
465 return (orientation == HORIZONTAL) ? user_scrollable_horizontal_
466 : user_scrollable_vertical_;
469 void LayerImpl::ApplySentScrollDeltasFromAbortedCommit() {
470 DCHECK(layer_tree_impl()->IsActiveTree());
471 scroll_offset_->AbortCommit();
474 InputHandler::ScrollStatus LayerImpl::TryScroll(
475 const gfx::PointF& screen_space_point,
476 InputHandler::ScrollInputType type,
477 ScrollBlocksOn effective_block_mode) const {
478 if (should_scroll_on_main_thread()) {
479 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Failed ShouldScrollOnMainThread");
480 return InputHandler::SCROLL_ON_MAIN_THREAD;
483 if (!screen_space_transform().IsInvertible()) {
484 TRACE_EVENT0("cc", "LayerImpl::TryScroll: Ignored NonInvertibleTransform");
485 return InputHandler::SCROLL_IGNORED;
488 if (!non_fast_scrollable_region().IsEmpty()) {
489 bool clipped = false;
490 gfx::Transform inverse_screen_space_transform(
491 gfx::Transform::kSkipInitialization);
492 if (!screen_space_transform().GetInverse(&inverse_screen_space_transform)) {
493 // TODO(shawnsingh): We shouldn't be applying a projection if screen space
494 // transform is uninvertible here. Perhaps we should be returning
495 // SCROLL_ON_MAIN_THREAD in this case?
498 gfx::PointF hit_test_point_in_layer_space = MathUtil::ProjectPoint(
499 inverse_screen_space_transform, screen_space_point, &clipped);
500 if (!clipped &&
501 non_fast_scrollable_region().Contains(
502 gfx::ToRoundedPoint(hit_test_point_in_layer_space))) {
503 TRACE_EVENT0("cc",
504 "LayerImpl::tryScroll: Failed NonFastScrollableRegion");
505 return InputHandler::SCROLL_ON_MAIN_THREAD;
509 if (have_scroll_event_handlers() &&
510 effective_block_mode & SCROLL_BLOCKS_ON_SCROLL_EVENT) {
511 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed ScrollEventHandlers");
512 return InputHandler::SCROLL_ON_MAIN_THREAD;
515 if (type == InputHandler::WHEEL && have_wheel_event_handlers() &&
516 effective_block_mode & SCROLL_BLOCKS_ON_WHEEL_EVENT) {
517 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Failed WheelEventHandlers");
518 return InputHandler::SCROLL_ON_MAIN_THREAD;
521 if (!scrollable()) {
522 TRACE_EVENT0("cc", "LayerImpl::tryScroll: Ignored not scrollable");
523 return InputHandler::SCROLL_IGNORED;
526 gfx::ScrollOffset max_scroll_offset = MaxScrollOffset();
527 if (max_scroll_offset.x() <= 0 && max_scroll_offset.y() <= 0) {
528 TRACE_EVENT0("cc",
529 "LayerImpl::tryScroll: Ignored. Technically scrollable,"
530 " but has no affordance in either direction.");
531 return InputHandler::SCROLL_IGNORED;
534 return InputHandler::SCROLL_STARTED;
537 skia::RefPtr<SkPicture> LayerImpl::GetPicture() {
538 return skia::RefPtr<SkPicture>();
541 scoped_ptr<LayerImpl> LayerImpl::CreateLayerImpl(LayerTreeImpl* tree_impl) {
542 return LayerImpl::Create(tree_impl, layer_id_, scroll_offset_);
545 void LayerImpl::PushPropertiesTo(LayerImpl* layer) {
546 layer->SetTransformOrigin(transform_origin_);
547 layer->SetBackgroundColor(background_color_);
548 layer->SetBounds(bounds_);
549 layer->SetDoubleSided(double_sided_);
550 layer->SetDrawsContent(DrawsContent());
551 layer->SetHideLayerAndSubtree(hide_layer_and_subtree_);
552 layer->SetHasRenderSurface(!!render_surface());
553 layer->SetFilters(filters());
554 layer->SetBackgroundFilters(background_filters());
555 layer->SetMasksToBounds(masks_to_bounds_);
556 layer->SetShouldScrollOnMainThread(should_scroll_on_main_thread_);
557 layer->SetHaveWheelEventHandlers(have_wheel_event_handlers_);
558 layer->SetHaveScrollEventHandlers(have_scroll_event_handlers_);
559 layer->SetScrollBlocksOn(scroll_blocks_on_);
560 layer->SetNonFastScrollableRegion(non_fast_scrollable_region_);
561 layer->SetTouchEventHandlerRegion(touch_event_handler_region_);
562 layer->SetContentsOpaque(contents_opaque_);
563 layer->SetOpacity(opacity_);
564 layer->SetBlendMode(blend_mode_);
565 layer->SetIsRootForIsolatedGroup(is_root_for_isolated_group_);
566 layer->SetPosition(position_);
567 layer->SetIsContainerForFixedPositionLayers(
568 is_container_for_fixed_position_layers_);
569 layer->SetPositionConstraint(position_constraint_);
570 layer->SetShouldFlattenTransform(should_flatten_transform_);
571 layer->set_should_flatten_transform_from_property_tree(
572 should_flatten_transform_from_property_tree_);
573 layer->set_is_clipped(is_clipped_);
574 layer->set_draw_blend_mode(draw_blend_mode_);
575 layer->SetUseParentBackfaceVisibility(use_parent_backface_visibility_);
576 layer->SetTransformAndInvertibility(transform_, transform_is_invertible_);
578 layer->SetScrollClipLayer(scroll_clip_layer_ ? scroll_clip_layer_->id()
579 : Layer::INVALID_ID);
580 layer->set_user_scrollable_horizontal(user_scrollable_horizontal_);
581 layer->set_user_scrollable_vertical(user_scrollable_vertical_);
583 layer->SetScrollCompensationAdjustment(scroll_compensation_adjustment_);
585 layer->PushScrollOffset(nullptr);
587 layer->Set3dSortingContextId(sorting_context_id_);
588 layer->SetNumDescendantsThatDrawContent(num_descendants_that_draw_content_);
590 layer->SetTransformTreeIndex(transform_tree_index_);
591 layer->SetClipTreeIndex(clip_tree_index_);
592 layer->SetEffectTreeIndex(effect_tree_index_);
593 layer->set_offset_to_transform_parent(offset_to_transform_parent_);
595 LayerImpl* scroll_parent = nullptr;
596 if (scroll_parent_) {
597 scroll_parent = layer->layer_tree_impl()->LayerById(scroll_parent_->id());
598 DCHECK(scroll_parent);
601 layer->SetScrollParent(scroll_parent);
602 if (scroll_children_) {
603 std::set<LayerImpl*>* scroll_children = new std::set<LayerImpl*>;
604 for (std::set<LayerImpl*>::iterator it = scroll_children_->begin();
605 it != scroll_children_->end();
606 ++it) {
607 DCHECK_EQ((*it)->scroll_parent(), this);
608 LayerImpl* scroll_child =
609 layer->layer_tree_impl()->LayerById((*it)->id());
610 DCHECK(scroll_child);
611 scroll_children->insert(scroll_child);
613 layer->SetScrollChildren(scroll_children);
614 } else {
615 layer->SetScrollChildren(nullptr);
618 LayerImpl* clip_parent = nullptr;
619 if (clip_parent_) {
620 clip_parent = layer->layer_tree_impl()->LayerById(
621 clip_parent_->id());
622 DCHECK(clip_parent);
625 layer->SetClipParent(clip_parent);
626 if (clip_children_) {
627 std::set<LayerImpl*>* clip_children = new std::set<LayerImpl*>;
628 for (std::set<LayerImpl*>::iterator it = clip_children_->begin();
629 it != clip_children_->end(); ++it)
630 clip_children->insert(layer->layer_tree_impl()->LayerById((*it)->id()));
631 layer->SetClipChildren(clip_children);
632 } else {
633 layer->SetClipChildren(nullptr);
636 layer->PassCopyRequests(&copy_requests_);
638 // If the main thread commits multiple times before the impl thread actually
639 // draws, then damage tracking will become incorrect if we simply clobber the
640 // update_rect here. The LayerImpl's update_rect needs to accumulate (i.e.
641 // union) any update changes that have occurred on the main thread.
642 update_rect_.Union(layer->update_rect());
643 layer->SetUpdateRect(update_rect_);
645 layer->SetStackingOrderChanged(stacking_order_changed_);
646 layer->SetDebugInfo(debug_info_);
648 if (frame_timing_requests_dirty_) {
649 layer->SetFrameTimingRequests(frame_timing_requests_);
650 frame_timing_requests_dirty_ = false;
653 // Reset any state that should be cleared for the next update.
654 stacking_order_changed_ = false;
655 update_rect_ = gfx::Rect();
656 needs_push_properties_ = false;
657 num_dependents_need_push_properties_ = 0;
660 gfx::Vector2dF LayerImpl::FixedContainerSizeDelta() const {
661 if (!scroll_clip_layer_)
662 return gfx::Vector2dF();
664 gfx::Vector2dF delta_from_scroll = scroll_clip_layer_->bounds_delta();
666 // In virtual-viewport mode, we don't need to compensate for pinch zoom or
667 // scale since the fixed container is the outer viewport, which sits below
668 // the page scale.
669 return delta_from_scroll;
672 base::DictionaryValue* LayerImpl::LayerTreeAsJson() const {
673 base::DictionaryValue* result = new base::DictionaryValue;
674 result->SetInteger("LayerId", id());
675 result->SetString("LayerType", LayerTypeAsString());
677 base::ListValue* list = new base::ListValue;
678 list->AppendInteger(bounds().width());
679 list->AppendInteger(bounds().height());
680 result->Set("Bounds", list);
682 list = new base::ListValue;
683 list->AppendDouble(position_.x());
684 list->AppendDouble(position_.y());
685 result->Set("Position", list);
687 const gfx::Transform& gfx_transform = draw_properties_.target_space_transform;
688 double transform[16];
689 gfx_transform.matrix().asColMajord(transform);
690 list = new base::ListValue;
691 for (int i = 0; i < 16; ++i)
692 list->AppendDouble(transform[i]);
693 result->Set("DrawTransform", list);
695 result->SetBoolean("DrawsContent", draws_content_);
696 result->SetBoolean("Is3dSorted", Is3dSorted());
697 result->SetDouble("OPACITY", opacity());
698 result->SetBoolean("ContentsOpaque", contents_opaque_);
700 if (scrollable())
701 result->SetBoolean("Scrollable", true);
703 if (have_wheel_event_handlers_)
704 result->SetBoolean("WheelHandler", have_wheel_event_handlers_);
705 if (have_scroll_event_handlers_)
706 result->SetBoolean("ScrollHandler", have_scroll_event_handlers_);
707 if (!touch_event_handler_region_.IsEmpty()) {
708 scoped_ptr<base::Value> region = touch_event_handler_region_.AsValue();
709 result->Set("TouchRegion", region.release());
712 if (scroll_blocks_on_) {
713 list = new base::ListValue;
714 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_START_TOUCH)
715 list->AppendString("StartTouch");
716 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_WHEEL_EVENT)
717 list->AppendString("WheelEvent");
718 if (scroll_blocks_on_ & SCROLL_BLOCKS_ON_SCROLL_EVENT)
719 list->AppendString("ScrollEvent");
720 result->Set("ScrollBlocksOn", list);
723 list = new base::ListValue;
724 for (size_t i = 0; i < children_.size(); ++i)
725 list->Append(children_[i]->LayerTreeAsJson());
726 result->Set("Children", list);
728 return result;
731 void LayerImpl::SetStackingOrderChanged(bool stacking_order_changed) {
732 if (stacking_order_changed) {
733 stacking_order_changed_ = true;
734 NoteLayerPropertyChangedForSubtree();
738 void LayerImpl::NoteLayerPropertyChanged() {
739 layer_property_changed_ = true;
740 layer_tree_impl()->set_needs_update_draw_properties();
741 SetNeedsPushProperties();
744 void LayerImpl::NoteLayerPropertyChangedForSubtree() {
745 layer_property_changed_ = true;
746 layer_tree_impl()->set_needs_update_draw_properties();
747 for (size_t i = 0; i < children_.size(); ++i)
748 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
749 SetNeedsPushProperties();
752 void LayerImpl::NoteLayerPropertyChangedForDescendantsInternal() {
753 layer_property_changed_ = true;
754 for (size_t i = 0; i < children_.size(); ++i)
755 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
758 void LayerImpl::NoteLayerPropertyChangedForDescendants() {
759 layer_tree_impl()->set_needs_update_draw_properties();
760 for (size_t i = 0; i < children_.size(); ++i)
761 children_[i]->NoteLayerPropertyChangedForDescendantsInternal();
762 SetNeedsPushProperties();
765 void LayerImpl::ValidateQuadResourcesInternal(DrawQuad* quad) const {
766 #if DCHECK_IS_ON()
767 const ResourceProvider* resource_provider =
768 layer_tree_impl_->resource_provider();
769 for (ResourceId resource_id : quad->resources)
770 resource_provider->ValidateResource(resource_id);
771 #endif
774 const char* LayerImpl::LayerTypeAsString() const {
775 return "cc::LayerImpl";
778 void LayerImpl::ResetAllChangeTrackingForSubtree() {
779 layer_property_changed_ = false;
781 update_rect_ = gfx::Rect();
782 damage_rect_ = gfx::RectF();
784 if (render_surface_)
785 render_surface_->ResetPropertyChangedFlag();
787 if (mask_layer_)
788 mask_layer_->ResetAllChangeTrackingForSubtree();
790 if (replica_layer_) {
791 // This also resets the replica mask, if it exists.
792 replica_layer_->ResetAllChangeTrackingForSubtree();
795 for (size_t i = 0; i < children_.size(); ++i)
796 children_[i]->ResetAllChangeTrackingForSubtree();
798 needs_push_properties_ = false;
799 num_dependents_need_push_properties_ = 0;
802 void LayerImpl::UpdatePropertyTreeTransform() {
803 if (transform_tree_index_ != -1) {
804 TransformTree& transform_tree =
805 layer_tree_impl()->property_trees()->transform_tree;
806 TransformNode* node = transform_tree.Node(transform_tree_index_);
807 // A LayerImpl's own current state is insufficient for determining whether
808 // it owns a TransformNode, since this depends on the state of the
809 // corresponding Layer at the time of the last commit. For example, a
810 // transform animation might have been in progress at the time the last
811 // commit started, but might have finished since then on the compositor
812 // thread.
813 if (node->owner_id != id())
814 return;
815 if (node->data.local != transform_) {
816 node->data.local = transform_;
817 node->data.needs_local_transform_update = true;
818 transform_tree.set_needs_update(true);
819 // TODO(ajuma): The current criteria for creating clip nodes means that
820 // property trees may need to be rebuilt when the new transform isn't
821 // axis-aligned wrt the old transform (see Layer::SetTransform). Since
822 // rebuilding property trees every frame of a transform animation is
823 // something we should try to avoid, change property tree-building so that
824 // it doesn't depend on axis aliginment.
829 void LayerImpl::UpdatePropertyTreeTransformIsAnimated(bool is_animated) {
830 if (transform_tree_index_ != -1) {
831 TransformTree& transform_tree =
832 layer_tree_impl()->property_trees()->transform_tree;
833 TransformNode* node = transform_tree.Node(transform_tree_index_);
834 // A LayerImpl's own current state is insufficient for determining whether
835 // it owns a TransformNode, since this depends on the state of the
836 // corresponding Layer at the time of the last commit. For example, if
837 // |is_animated| is false, this might mean a transform animation just ticked
838 // past its finish point (so the LayerImpl still owns a TransformNode) or it
839 // might mean that a transform animation was removed during commit or
840 // activation (and, in that case, the LayerImpl will no longer own a
841 // TransformNode, unless it has non-animation-related reasons for owning a
842 // node).
843 if (node->owner_id != id())
844 return;
845 if (node->data.is_animated != is_animated) {
846 node->data.is_animated = is_animated;
847 if (is_animated) {
848 float maximum_target_scale = 0.f;
849 node->data.local_maximum_animation_target_scale =
850 MaximumTargetScale(&maximum_target_scale) ? maximum_target_scale
851 : 0.f;
853 float animation_start_scale = 0.f;
854 node->data.local_starting_animation_scale =
855 AnimationStartScale(&animation_start_scale) ? animation_start_scale
856 : 0.f;
858 node->data.has_only_translation_animations =
859 HasOnlyTranslationTransforms();
860 } else {
861 node->data.local_maximum_animation_target_scale = 0.f;
862 node->data.local_starting_animation_scale = 0.f;
863 node->data.has_only_translation_animations = true;
866 transform_tree.set_needs_update(true);
871 void LayerImpl::UpdatePropertyTreeOpacity() {
872 if (effect_tree_index_ != -1) {
873 EffectTree& effect_tree = layer_tree_impl()->property_trees()->effect_tree;
874 EffectNode* node = effect_tree.Node(effect_tree_index_);
875 // A LayerImpl's own current state is insufficient for determining whether
876 // it owns an OpacityNode, since this depends on the state of the
877 // corresponding Layer at the time of the last commit. For example, an
878 // opacity animation might have been in progress at the time the last commit
879 // started, but might have finished since then on the compositor thread.
880 if (node->owner_id != id())
881 return;
882 node->data.opacity = opacity_;
883 effect_tree.set_needs_update(true);
887 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() {
888 if (scrollable())
889 UpdatePropertyTreeScrollOffset();
891 if (HasAnyAnimationTargetingProperty(Animation::OPACITY))
892 UpdatePropertyTreeOpacity();
894 if (HasAnyAnimationTargetingProperty(Animation::TRANSFORM)) {
895 UpdatePropertyTreeTransform();
896 UpdatePropertyTreeTransformIsAnimated(
897 HasPotentiallyRunningTransformAnimation());
901 gfx::ScrollOffset LayerImpl::ScrollOffsetForAnimation() const {
902 return CurrentScrollOffset();
905 void LayerImpl::OnFilterAnimated(const FilterOperations& filters) {
906 SetFilters(filters);
909 void LayerImpl::OnOpacityAnimated(float opacity) {
910 SetOpacity(opacity);
911 UpdatePropertyTreeOpacity();
914 void LayerImpl::OnTransformAnimated(const gfx::Transform& transform) {
915 SetTransform(transform);
916 UpdatePropertyTreeTransform();
919 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) {
920 // Only layers in the active tree should need to do anything here, since
921 // layers in the pending tree will find out about these changes as a
922 // result of the shared SyncedProperty.
923 if (!IsActive())
924 return;
926 SetCurrentScrollOffset(scroll_offset);
928 layer_tree_impl_->DidAnimateScrollOffset();
931 void LayerImpl::OnAnimationWaitingForDeletion() {}
933 void LayerImpl::OnTransformIsPotentiallyAnimatingChanged(bool is_animating) {
934 UpdatePropertyTreeTransformIsAnimated(is_animating);
937 bool LayerImpl::IsActive() const {
938 return layer_tree_impl_->IsActiveTree();
941 gfx::Size LayerImpl::bounds() const {
942 gfx::Vector2d delta = gfx::ToCeiledVector2d(bounds_delta_);
943 return gfx::Size(bounds_.width() + delta.x(),
944 bounds_.height() + delta.y());
947 gfx::SizeF LayerImpl::BoundsForScrolling() const {
948 return gfx::SizeF(bounds_.width() + bounds_delta_.x(),
949 bounds_.height() + bounds_delta_.y());
952 void LayerImpl::SetBounds(const gfx::Size& bounds) {
953 if (bounds_ == bounds)
954 return;
956 bounds_ = bounds;
958 ScrollbarParametersDidChange(true);
959 if (masks_to_bounds())
960 NoteLayerPropertyChangedForSubtree();
961 else
962 NoteLayerPropertyChanged();
965 void LayerImpl::SetBoundsDelta(const gfx::Vector2dF& bounds_delta) {
966 DCHECK(IsActive());
967 if (bounds_delta_ == bounds_delta)
968 return;
970 bounds_delta_ = bounds_delta;
972 TransformTree& transform_tree =
973 layer_tree_impl()->property_trees()->transform_tree;
974 if (this == layer_tree_impl()->InnerViewportContainerLayer())
975 transform_tree.SetInnerViewportBoundsDelta(bounds_delta);
976 else if (this == layer_tree_impl()->OuterViewportContainerLayer())
977 transform_tree.SetOuterViewportBoundsDelta(bounds_delta);
979 ScrollbarParametersDidChange(true);
981 if (masks_to_bounds()) {
982 // If layer is clipping, then update the clip node using the new bounds.
983 ClipNode* clip_node =
984 layer_tree_impl()->property_trees()->clip_tree.Node(clip_tree_index());
985 if (clip_node) {
986 DCHECK(id() == clip_node->owner_id);
987 clip_node->data.clip =
988 gfx::RectF(gfx::PointF() + offset_to_transform_parent(), bounds());
989 layer_tree_impl()->property_trees()->clip_tree.set_needs_update(true);
992 NoteLayerPropertyChangedForSubtree();
993 } else {
994 NoteLayerPropertyChanged();
998 void LayerImpl::SetMaskLayer(scoped_ptr<LayerImpl> mask_layer) {
999 int new_layer_id = mask_layer ? mask_layer->id() : -1;
1001 if (mask_layer) {
1002 DCHECK_EQ(layer_tree_impl(), mask_layer->layer_tree_impl());
1003 DCHECK_NE(new_layer_id, mask_layer_id_);
1004 } else if (new_layer_id == mask_layer_id_) {
1005 return;
1008 mask_layer_ = mask_layer.Pass();
1009 mask_layer_id_ = new_layer_id;
1010 if (mask_layer_)
1011 mask_layer_->SetParent(this);
1012 NoteLayerPropertyChangedForSubtree();
1015 scoped_ptr<LayerImpl> LayerImpl::TakeMaskLayer() {
1016 mask_layer_id_ = -1;
1017 return mask_layer_.Pass();
1020 void LayerImpl::SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer) {
1021 int new_layer_id = replica_layer ? replica_layer->id() : -1;
1023 if (replica_layer) {
1024 DCHECK_EQ(layer_tree_impl(), replica_layer->layer_tree_impl());
1025 DCHECK_NE(new_layer_id, replica_layer_id_);
1026 } else if (new_layer_id == replica_layer_id_) {
1027 return;
1030 replica_layer_ = replica_layer.Pass();
1031 replica_layer_id_ = new_layer_id;
1032 if (replica_layer_)
1033 replica_layer_->SetParent(this);
1034 NoteLayerPropertyChangedForSubtree();
1037 scoped_ptr<LayerImpl> LayerImpl::TakeReplicaLayer() {
1038 replica_layer_id_ = -1;
1039 return replica_layer_.Pass();
1042 ScrollbarLayerImplBase* LayerImpl::ToScrollbarLayer() {
1043 return nullptr;
1046 void LayerImpl::SetDrawsContent(bool draws_content) {
1047 if (draws_content_ == draws_content)
1048 return;
1050 draws_content_ = draws_content;
1051 NoteLayerPropertyChanged();
1054 void LayerImpl::SetHideLayerAndSubtree(bool hide) {
1055 if (hide_layer_and_subtree_ == hide)
1056 return;
1058 hide_layer_and_subtree_ = hide;
1059 NoteLayerPropertyChangedForSubtree();
1062 void LayerImpl::SetTransformOrigin(const gfx::Point3F& transform_origin) {
1063 if (transform_origin_ == transform_origin)
1064 return;
1065 transform_origin_ = transform_origin;
1066 NoteLayerPropertyChangedForSubtree();
1069 void LayerImpl::SetBackgroundColor(SkColor background_color) {
1070 if (background_color_ == background_color)
1071 return;
1073 background_color_ = background_color;
1074 NoteLayerPropertyChanged();
1077 SkColor LayerImpl::SafeOpaqueBackgroundColor() const {
1078 SkColor color = background_color();
1079 if (SkColorGetA(color) == 255 && !contents_opaque()) {
1080 color = SK_ColorTRANSPARENT;
1081 } else if (SkColorGetA(color) != 255 && contents_opaque()) {
1082 for (const LayerImpl* layer = parent(); layer;
1083 layer = layer->parent()) {
1084 color = layer->background_color();
1085 if (SkColorGetA(color) == 255)
1086 break;
1088 if (SkColorGetA(color) != 255)
1089 color = layer_tree_impl()->background_color();
1090 if (SkColorGetA(color) != 255)
1091 color = SkColorSetA(color, 255);
1093 return color;
1096 void LayerImpl::SetFilters(const FilterOperations& filters) {
1097 if (filters_ == filters)
1098 return;
1100 filters_ = filters;
1101 NoteLayerPropertyChangedForSubtree();
1104 bool LayerImpl::FilterIsAnimating() const {
1105 LayerAnimationController::ObserverType observer_type =
1106 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1107 : LayerAnimationController::ObserverType::PENDING;
1108 return layer_animation_controller_
1109 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
1110 Animation::FILTER, observer_type)
1111 : layer_tree_impl_->IsAnimatingFilterProperty(this);
1114 bool LayerImpl::HasPotentiallyRunningFilterAnimation() const {
1115 LayerAnimationController::ObserverType observer_type =
1116 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1117 : LayerAnimationController::ObserverType::PENDING;
1118 return layer_animation_controller_
1119 ? layer_animation_controller_->IsPotentiallyAnimatingProperty(
1120 Animation::FILTER, observer_type)
1121 : layer_tree_impl_->HasPotentiallyRunningFilterAnimation(this);
1124 bool LayerImpl::FilterIsAnimatingOnImplOnly() const {
1125 if (!layer_animation_controller_)
1126 return layer_tree_impl_->FilterIsAnimatingOnImplOnly(this);
1128 Animation* filter_animation =
1129 layer_animation_controller_->GetAnimation(Animation::FILTER);
1130 return filter_animation && filter_animation->is_impl_only();
1133 void LayerImpl::SetBackgroundFilters(
1134 const FilterOperations& filters) {
1135 if (background_filters_ == filters)
1136 return;
1138 background_filters_ = filters;
1139 NoteLayerPropertyChanged();
1142 void LayerImpl::SetMasksToBounds(bool masks_to_bounds) {
1143 if (masks_to_bounds_ == masks_to_bounds)
1144 return;
1146 masks_to_bounds_ = masks_to_bounds;
1147 NoteLayerPropertyChangedForSubtree();
1150 void LayerImpl::SetContentsOpaque(bool opaque) {
1151 if (contents_opaque_ == opaque)
1152 return;
1154 contents_opaque_ = opaque;
1155 NoteLayerPropertyChangedForSubtree();
1158 void LayerImpl::SetOpacity(float opacity) {
1159 if (opacity_ == opacity)
1160 return;
1162 opacity_ = opacity;
1163 NoteLayerPropertyChangedForSubtree();
1166 bool LayerImpl::OpacityIsAnimating() const {
1167 LayerAnimationController::ObserverType observer_type =
1168 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1169 : LayerAnimationController::ObserverType::PENDING;
1170 return layer_animation_controller_
1171 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
1172 Animation::OPACITY, observer_type)
1173 : layer_tree_impl_->IsAnimatingOpacityProperty(this);
1176 bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const {
1177 LayerAnimationController::ObserverType observer_type =
1178 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1179 : LayerAnimationController::ObserverType::PENDING;
1180 return layer_animation_controller_
1181 ? layer_animation_controller_->IsPotentiallyAnimatingProperty(
1182 Animation::OPACITY, observer_type)
1183 : layer_tree_impl_->HasPotentiallyRunningOpacityAnimation(this);
1186 bool LayerImpl::OpacityIsAnimatingOnImplOnly() const {
1187 if (!layer_animation_controller_)
1188 return layer_tree_impl_->OpacityIsAnimatingOnImplOnly(this);
1190 Animation* opacity_animation =
1191 layer_animation_controller_->GetAnimation(Animation::OPACITY);
1192 return opacity_animation && opacity_animation->is_impl_only();
1195 void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode) {
1196 if (blend_mode_ == blend_mode)
1197 return;
1199 blend_mode_ = blend_mode;
1200 NoteLayerPropertyChangedForSubtree();
1203 void LayerImpl::SetIsRootForIsolatedGroup(bool root) {
1204 if (is_root_for_isolated_group_ == root)
1205 return;
1207 is_root_for_isolated_group_ = root;
1208 SetNeedsPushProperties();
1211 void LayerImpl::SetPosition(const gfx::PointF& position) {
1212 if (position_ == position)
1213 return;
1215 position_ = position;
1216 NoteLayerPropertyChangedForSubtree();
1219 void LayerImpl::SetShouldFlattenTransform(bool flatten) {
1220 if (should_flatten_transform_ == flatten)
1221 return;
1223 should_flatten_transform_ = flatten;
1224 NoteLayerPropertyChangedForSubtree();
1227 void LayerImpl::Set3dSortingContextId(int id) {
1228 if (id == sorting_context_id_)
1229 return;
1230 sorting_context_id_ = id;
1231 NoteLayerPropertyChangedForSubtree();
1234 void LayerImpl::SetFrameTimingRequests(
1235 const std::vector<FrameTimingRequest>& requests) {
1236 frame_timing_requests_ = requests;
1237 frame_timing_requests_dirty_ = true;
1238 SetNeedsPushProperties();
1241 void LayerImpl::GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids) {
1242 for (const auto& request : frame_timing_requests_)
1243 request_ids->push_back(request.id());
1246 void LayerImpl::SetTransform(const gfx::Transform& transform) {
1247 if (transform_ == transform)
1248 return;
1250 transform_ = transform;
1251 transform_is_invertible_ = transform_.IsInvertible();
1252 NoteLayerPropertyChangedForSubtree();
1255 void LayerImpl::SetTransformAndInvertibility(const gfx::Transform& transform,
1256 bool transform_is_invertible) {
1257 if (transform_ == transform) {
1258 DCHECK(transform_is_invertible_ == transform_is_invertible)
1259 << "Can't change invertibility if transform is unchanged";
1260 return;
1262 transform_ = transform;
1263 transform_is_invertible_ = transform_is_invertible;
1264 NoteLayerPropertyChangedForSubtree();
1267 bool LayerImpl::TransformIsAnimating() const {
1268 LayerAnimationController::ObserverType observer_type =
1269 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1270 : LayerAnimationController::ObserverType::PENDING;
1271 return layer_animation_controller_
1272 ? layer_animation_controller_->IsCurrentlyAnimatingProperty(
1273 Animation::TRANSFORM, observer_type)
1274 : layer_tree_impl_->IsAnimatingTransformProperty(this);
1277 bool LayerImpl::HasPotentiallyRunningTransformAnimation() const {
1278 LayerAnimationController::ObserverType observer_type =
1279 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1280 : LayerAnimationController::ObserverType::PENDING;
1281 return layer_animation_controller_
1282 ? layer_animation_controller_->IsPotentiallyAnimatingProperty(
1283 Animation::TRANSFORM, observer_type)
1284 : layer_tree_impl_->HasPotentiallyRunningTransformAnimation(this);
1287 bool LayerImpl::TransformIsAnimatingOnImplOnly() const {
1288 if (!layer_animation_controller_)
1289 return layer_tree_impl_->TransformIsAnimatingOnImplOnly(this);
1291 Animation* transform_animation =
1292 layer_animation_controller_->GetAnimation(Animation::TRANSFORM);
1293 return transform_animation && transform_animation->is_impl_only();
1296 bool LayerImpl::HasOnlyTranslationTransforms() const {
1297 if (!layer_animation_controller_)
1298 return layer_tree_impl_->HasOnlyTranslationTransforms(this);
1300 LayerAnimationController::ObserverType observer_type =
1301 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1302 : LayerAnimationController::ObserverType::PENDING;
1303 return layer_animation_controller_->HasOnlyTranslationTransforms(
1304 observer_type);
1307 bool LayerImpl::MaximumTargetScale(float* max_scale) const {
1308 if (!layer_animation_controller_)
1309 return layer_tree_impl_->MaximumTargetScale(this, max_scale);
1311 LayerAnimationController::ObserverType observer_type =
1312 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1313 : LayerAnimationController::ObserverType::PENDING;
1314 return layer_animation_controller_->MaximumTargetScale(observer_type,
1315 max_scale);
1318 bool LayerImpl::AnimationStartScale(float* start_scale) const {
1319 if (!layer_animation_controller_)
1320 return layer_tree_impl_->AnimationStartScale(this, start_scale);
1322 LayerAnimationController::ObserverType observer_type =
1323 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1324 : LayerAnimationController::ObserverType::PENDING;
1325 return layer_animation_controller_->AnimationStartScale(observer_type,
1326 start_scale);
1329 bool LayerImpl::HasAnyAnimationTargetingProperty(
1330 Animation::TargetProperty property) const {
1331 if (!layer_animation_controller_)
1332 return layer_tree_impl_->HasAnyAnimationTargetingProperty(this, property);
1334 return !!layer_animation_controller_->GetAnimation(property);
1337 bool LayerImpl::HasFilterAnimationThatInflatesBounds() const {
1338 if (!layer_animation_controller_)
1339 return layer_tree_impl_->HasFilterAnimationThatInflatesBounds(this);
1341 return layer_animation_controller_->HasFilterAnimationThatInflatesBounds();
1344 bool LayerImpl::HasTransformAnimationThatInflatesBounds() const {
1345 if (!layer_animation_controller_)
1346 return layer_tree_impl_->HasTransformAnimationThatInflatesBounds(this);
1348 return layer_animation_controller_->HasTransformAnimationThatInflatesBounds();
1351 bool LayerImpl::HasAnimationThatInflatesBounds() const {
1352 if (!layer_animation_controller_)
1353 return layer_tree_impl_->HasAnimationThatInflatesBounds(this);
1355 return layer_animation_controller_->HasAnimationThatInflatesBounds();
1358 bool LayerImpl::FilterAnimationBoundsForBox(const gfx::BoxF& box,
1359 gfx::BoxF* bounds) const {
1360 if (!layer_animation_controller_)
1361 return layer_tree_impl_->FilterAnimationBoundsForBox(this, box, bounds);
1363 return layer_animation_controller_->FilterAnimationBoundsForBox(box, bounds);
1366 bool LayerImpl::TransformAnimationBoundsForBox(const gfx::BoxF& box,
1367 gfx::BoxF* bounds) const {
1368 if (!layer_animation_controller_)
1369 return layer_tree_impl_->TransformAnimationBoundsForBox(this, box, bounds);
1371 return layer_animation_controller_->TransformAnimationBoundsForBox(box,
1372 bounds);
1375 void LayerImpl::SetUpdateRect(const gfx::Rect& update_rect) {
1376 update_rect_ = update_rect;
1377 SetNeedsPushProperties();
1380 void LayerImpl::AddDamageRect(const gfx::RectF& damage_rect) {
1381 damage_rect_ = gfx::UnionRects(damage_rect_, damage_rect);
1384 bool LayerImpl::IsExternalScrollActive() const {
1385 return layer_tree_impl_->IsExternalScrollActive();
1388 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset) {
1389 DCHECK(IsActive());
1390 if (scroll_offset_->SetCurrent(scroll_offset))
1391 DidUpdateScrollOffset(false);
1394 void LayerImpl::SetCurrentScrollOffsetFromDelegate(
1395 const gfx::ScrollOffset& scroll_offset) {
1396 DCHECK(IsActive());
1397 if (scroll_offset_->SetCurrent(scroll_offset))
1398 DidUpdateScrollOffset(true);
1401 void LayerImpl::PushScrollOffsetFromMainThread(
1402 const gfx::ScrollOffset& scroll_offset) {
1403 PushScrollOffset(&scroll_offset);
1406 void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1407 const gfx::ScrollOffset& scroll_offset) {
1408 scroll_offset_->set_clobber_active_value();
1409 PushScrollOffset(&scroll_offset);
1412 gfx::ScrollOffset LayerImpl::PullDeltaForMainThread() {
1413 // TODO(miletus): Remove all this temporary flooring machinery when
1414 // Blink fully supports fractional scrolls.
1415 gfx::ScrollOffset current_offset = CurrentScrollOffset();
1416 gfx::ScrollOffset current_delta = IsActive()
1417 ? scroll_offset_->Delta()
1418 : scroll_offset_->PendingDelta().get();
1419 gfx::ScrollOffset floored_delta(floor(current_delta.x()),
1420 floor(current_delta.y()));
1421 gfx::ScrollOffset diff_delta = floored_delta - current_delta;
1422 gfx::ScrollOffset tmp_offset = current_offset + diff_delta;
1423 scroll_offset_->SetCurrent(tmp_offset);
1424 gfx::ScrollOffset delta = scroll_offset_->PullDeltaForMainThread();
1425 scroll_offset_->SetCurrent(current_offset);
1426 return delta;
1429 gfx::ScrollOffset LayerImpl::CurrentScrollOffset() const {
1430 return scroll_offset_->Current(IsActive());
1433 gfx::Vector2dF LayerImpl::ScrollDelta() const {
1434 if (IsActive())
1435 return gfx::Vector2dF(scroll_offset_->Delta().x(),
1436 scroll_offset_->Delta().y());
1437 else
1438 return gfx::Vector2dF(scroll_offset_->PendingDelta().get().x(),
1439 scroll_offset_->PendingDelta().get().y());
1442 void LayerImpl::SetScrollDelta(const gfx::Vector2dF& delta) {
1443 DCHECK(IsActive());
1444 DCHECK(scrollable() || delta.IsZero());
1445 SetCurrentScrollOffset(scroll_offset_->ActiveBase() +
1446 gfx::ScrollOffset(delta));
1449 gfx::ScrollOffset LayerImpl::BaseScrollOffset() const {
1450 if (IsActive())
1451 return scroll_offset_->ActiveBase();
1452 else
1453 return scroll_offset_->PendingBase();
1456 void LayerImpl::PushScrollOffset(const gfx::ScrollOffset* scroll_offset) {
1457 DCHECK(scroll_offset || IsActive());
1458 bool changed = false;
1459 if (scroll_offset) {
1460 DCHECK(!IsActive() || !layer_tree_impl_->FindPendingTreeLayerById(id()));
1461 changed |= scroll_offset_->PushFromMainThread(*scroll_offset);
1463 if (IsActive()) {
1464 changed |= scroll_offset_->PushPendingToActive();
1467 if (changed)
1468 DidUpdateScrollOffset(false);
1471 void LayerImpl::UpdatePropertyTreeScrollOffset() {
1472 // TODO(enne): in the future, scrolling should update the scroll tree
1473 // directly instead of going through layers.
1474 if (transform_tree_index_ != -1) {
1475 TransformTree& transform_tree =
1476 layer_tree_impl()->property_trees()->transform_tree;
1477 TransformNode* node = transform_tree.Node(transform_tree_index_);
1478 gfx::ScrollOffset current_offset = scroll_offset_->Current(IsActive());
1479 if (node->data.scroll_offset != current_offset) {
1480 node->data.scroll_offset = current_offset;
1481 node->data.needs_local_transform_update = true;
1482 transform_tree.set_needs_update(true);
1487 void LayerImpl::DidUpdateScrollOffset(bool is_from_root_delegate) {
1488 DCHECK(scroll_offset_);
1490 if (!is_from_root_delegate)
1491 layer_tree_impl()->DidUpdateScrollOffset(id());
1492 NoteLayerPropertyChangedForSubtree();
1493 ScrollbarParametersDidChange(false);
1495 UpdatePropertyTreeScrollOffset();
1497 // Inform the pending twin that a property changed.
1498 if (layer_tree_impl()->IsActiveTree()) {
1499 LayerImpl* pending_twin = layer_tree_impl()->FindPendingTreeLayerById(id());
1500 if (pending_twin)
1501 pending_twin->DidUpdateScrollOffset(is_from_root_delegate);
1505 void LayerImpl::SetDoubleSided(bool double_sided) {
1506 if (double_sided_ == double_sided)
1507 return;
1509 double_sided_ = double_sided;
1510 NoteLayerPropertyChangedForSubtree();
1513 SimpleEnclosedRegion LayerImpl::VisibleOpaqueRegion() const {
1514 if (contents_opaque())
1515 return SimpleEnclosedRegion(visible_layer_rect());
1516 return SimpleEnclosedRegion();
1519 void LayerImpl::DidBeginTracing() {}
1521 void LayerImpl::ReleaseResources() {}
1523 void LayerImpl::RecreateResources() {
1526 gfx::ScrollOffset LayerImpl::MaxScrollOffset() const {
1527 if (!scroll_clip_layer_ || bounds().IsEmpty())
1528 return gfx::ScrollOffset();
1530 LayerImpl const* page_scale_layer = layer_tree_impl()->PageScaleLayer();
1531 DCHECK(this != page_scale_layer);
1532 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1533 IsContainerForFixedPositionLayers());
1535 float scale_factor = 1.f;
1536 for (LayerImpl const* current_layer = this;
1537 current_layer != scroll_clip_layer_->parent();
1538 current_layer = current_layer->parent()) {
1539 if (current_layer == page_scale_layer)
1540 scale_factor = layer_tree_impl()->current_page_scale_factor();
1543 gfx::SizeF scaled_scroll_bounds =
1544 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor));
1545 scaled_scroll_bounds = gfx::ToFlooredSize(scaled_scroll_bounds);
1547 gfx::ScrollOffset max_offset(
1548 scaled_scroll_bounds.width() - scroll_clip_layer_->bounds().width(),
1549 scaled_scroll_bounds.height() - scroll_clip_layer_->bounds().height());
1550 // We need the final scroll offset to be in CSS coords.
1551 max_offset.Scale(1 / scale_factor);
1552 max_offset.SetToMax(gfx::ScrollOffset());
1553 return max_offset;
1556 gfx::ScrollOffset LayerImpl::ClampScrollOffsetToLimits(
1557 gfx::ScrollOffset offset) const {
1558 offset.SetToMin(MaxScrollOffset());
1559 offset.SetToMax(gfx::ScrollOffset());
1560 return offset;
1563 gfx::Vector2dF LayerImpl::ClampScrollToMaxScrollOffset() {
1564 gfx::ScrollOffset old_offset = CurrentScrollOffset();
1565 gfx::ScrollOffset clamped_offset = ClampScrollOffsetToLimits(old_offset);
1566 gfx::Vector2dF delta = clamped_offset.DeltaFrom(old_offset);
1567 if (!delta.IsZero())
1568 ScrollBy(delta);
1569 return delta;
1572 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
1573 LayerImpl* scrollbar_clip_layer,
1574 bool on_resize) const {
1575 DCHECK(scrollbar_layer);
1576 LayerImpl* page_scale_layer = layer_tree_impl()->PageScaleLayer();
1578 DCHECK(this != page_scale_layer);
1579 DCHECK(scrollbar_clip_layer);
1580 gfx::RectF clip_rect(gfx::PointF(),
1581 scrollbar_clip_layer->BoundsForScrolling());
1583 // See comment in MaxScrollOffset() regarding the use of the content layer
1584 // bounds here.
1585 gfx::RectF scroll_rect(gfx::PointF(), BoundsForScrolling());
1587 if (scroll_rect.size().IsEmpty())
1588 return;
1590 gfx::ScrollOffset current_offset;
1591 for (LayerImpl const* current_layer = this;
1592 current_layer != scrollbar_clip_layer->parent();
1593 current_layer = current_layer->parent()) {
1594 current_offset += current_layer->CurrentScrollOffset();
1595 if (current_layer == page_scale_layer) {
1596 float scale_factor = layer_tree_impl()->current_page_scale_factor();
1597 current_offset.Scale(scale_factor);
1598 scroll_rect.Scale(scale_factor);
1602 bool scrollbar_needs_animation = false;
1603 scrollbar_needs_animation |= scrollbar_layer->SetVerticalAdjust(
1604 scrollbar_clip_layer->bounds_delta().y());
1605 if (scrollbar_layer->orientation() == HORIZONTAL) {
1606 float visible_ratio = clip_rect.width() / scroll_rect.width();
1607 scrollbar_needs_animation |=
1608 scrollbar_layer->SetCurrentPos(current_offset.x());
1609 scrollbar_needs_animation |=
1610 scrollbar_layer->SetMaximum(scroll_rect.width() - clip_rect.width());
1611 scrollbar_needs_animation |=
1612 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
1613 } else {
1614 float visible_ratio = clip_rect.height() / scroll_rect.height();
1615 bool y_offset_did_change =
1616 scrollbar_layer->SetCurrentPos(current_offset.y());
1617 scrollbar_needs_animation |= y_offset_did_change;
1618 scrollbar_needs_animation |=
1619 scrollbar_layer->SetMaximum(scroll_rect.height() - clip_rect.height());
1620 scrollbar_needs_animation |=
1621 scrollbar_layer->SetVisibleToTotalLengthRatio(visible_ratio);
1622 if (y_offset_did_change && layer_tree_impl()->IsActiveTree() &&
1623 this == layer_tree_impl()->OuterViewportScrollLayer()) {
1624 TRACE_COUNTER_ID1("cc", "scroll_offset_y", this->id(),
1625 current_offset.y());
1628 if (scrollbar_needs_animation) {
1629 layer_tree_impl()->set_needs_update_draw_properties();
1630 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars
1631 // should activate for every scroll on the main frame, not just the
1632 // scrolls that move the pinch virtual viewport (i.e. trigger from
1633 // either inner or outer viewport).
1634 if (scrollbar_animation_controller_) {
1635 // Non-overlay scrollbars shouldn't trigger animations.
1636 if (scrollbar_layer->is_overlay_scrollbar())
1637 scrollbar_animation_controller_->DidScrollUpdate(on_resize);
1642 void LayerImpl::DidBecomeActive() {
1643 if (layer_tree_impl_->settings().scrollbar_animator ==
1644 LayerTreeSettings::NO_ANIMATOR) {
1645 return;
1648 bool need_scrollbar_animation_controller = scrollable() && scrollbars_;
1649 if (!need_scrollbar_animation_controller) {
1650 scrollbar_animation_controller_ = nullptr;
1651 return;
1654 if (scrollbar_animation_controller_)
1655 return;
1657 scrollbar_animation_controller_ =
1658 layer_tree_impl_->CreateScrollbarAnimationController(this);
1661 void LayerImpl::ClearScrollbars() {
1662 if (!scrollbars_)
1663 return;
1665 scrollbars_.reset(nullptr);
1668 void LayerImpl::AddScrollbar(ScrollbarLayerImplBase* layer) {
1669 DCHECK(layer);
1670 DCHECK(!scrollbars_ || scrollbars_->find(layer) == scrollbars_->end());
1671 if (!scrollbars_)
1672 scrollbars_.reset(new ScrollbarSet());
1674 scrollbars_->insert(layer);
1677 void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase* layer) {
1678 DCHECK(scrollbars_);
1679 DCHECK(layer);
1680 DCHECK(scrollbars_->find(layer) != scrollbars_->end());
1682 scrollbars_->erase(layer);
1683 if (scrollbars_->empty())
1684 scrollbars_ = nullptr;
1687 bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation) const {
1688 if (!scrollbars_)
1689 return false;
1691 for (ScrollbarSet::iterator it = scrollbars_->begin();
1692 it != scrollbars_->end();
1693 ++it)
1694 if ((*it)->orientation() == orientation)
1695 return true;
1697 return false;
1700 void LayerImpl::ScrollbarParametersDidChange(bool on_resize) {
1701 if (!scrollbars_)
1702 return;
1704 for (ScrollbarSet::iterator it = scrollbars_->begin();
1705 it != scrollbars_->end();
1706 ++it) {
1707 bool is_scroll_layer = (*it)->ScrollLayerId() == layer_id_;
1708 bool scroll_layer_resized = is_scroll_layer && on_resize;
1709 (*it)->ScrollbarParametersDidChange(scroll_layer_resized);
1713 void LayerImpl::SetNeedsPushProperties() {
1714 if (needs_push_properties_)
1715 return;
1716 if (!parent_should_know_need_push_properties() && parent_)
1717 parent_->AddDependentNeedsPushProperties();
1718 needs_push_properties_ = true;
1721 void LayerImpl::AddDependentNeedsPushProperties() {
1722 DCHECK_GE(num_dependents_need_push_properties_, 0);
1724 if (!parent_should_know_need_push_properties() && parent_)
1725 parent_->AddDependentNeedsPushProperties();
1727 num_dependents_need_push_properties_++;
1730 void LayerImpl::RemoveDependentNeedsPushProperties() {
1731 num_dependents_need_push_properties_--;
1732 DCHECK_GE(num_dependents_need_push_properties_, 0);
1734 if (!parent_should_know_need_push_properties() && parent_)
1735 parent_->RemoveDependentNeedsPushProperties();
1738 void LayerImpl::GetAllPrioritizedTilesForTracing(
1739 std::vector<PrioritizedTile>* prioritized_tiles) const {
1742 void LayerImpl::AsValueInto(base::trace_event::TracedValue* state) const {
1743 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
1744 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1745 state,
1746 "cc::LayerImpl",
1747 LayerTypeAsString(),
1748 this);
1749 state->SetInteger("layer_id", id());
1750 MathUtil::AddToTracedValue("bounds", bounds_, state);
1752 state->SetDouble("opacity", opacity());
1754 MathUtil::AddToTracedValue("position", position_, state);
1756 state->SetInteger("draws_content", DrawsContent());
1757 state->SetInteger("gpu_memory_usage",
1758 base::saturated_cast<int>(GPUMemoryUsageInBytes()));
1760 MathUtil::AddToTracedValue(
1761 "scroll_offset", scroll_offset_ ? scroll_offset_->Current(IsActive())
1762 : gfx::ScrollOffset(),
1763 state);
1765 MathUtil::AddToTracedValue("transform_origin", transform_origin_, state);
1767 bool clipped;
1768 gfx::QuadF layer_quad = MathUtil::MapQuad(
1769 screen_space_transform(), gfx::QuadF(gfx::Rect(bounds())), &clipped);
1770 MathUtil::AddToTracedValue("layer_quad", layer_quad, state);
1771 if (!touch_event_handler_region_.IsEmpty()) {
1772 state->BeginArray("touch_event_handler_region");
1773 touch_event_handler_region_.AsValueInto(state);
1774 state->EndArray();
1776 if (have_wheel_event_handlers_) {
1777 gfx::Rect wheel_rect(bounds());
1778 Region wheel_region(wheel_rect);
1779 state->BeginArray("wheel_event_handler_region");
1780 wheel_region.AsValueInto(state);
1781 state->EndArray();
1783 if (have_scroll_event_handlers_) {
1784 gfx::Rect scroll_rect(bounds());
1785 Region scroll_region(scroll_rect);
1786 state->BeginArray("scroll_event_handler_region");
1787 scroll_region.AsValueInto(state);
1788 state->EndArray();
1790 if (!non_fast_scrollable_region_.IsEmpty()) {
1791 state->BeginArray("non_fast_scrollable_region");
1792 non_fast_scrollable_region_.AsValueInto(state);
1793 state->EndArray();
1795 if (scroll_blocks_on_) {
1796 state->SetInteger("scroll_blocks_on", scroll_blocks_on_);
1799 state->BeginArray("children");
1800 for (size_t i = 0; i < children_.size(); ++i) {
1801 state->BeginDictionary();
1802 children_[i]->AsValueInto(state);
1803 state->EndDictionary();
1805 state->EndArray();
1806 if (mask_layer_) {
1807 state->BeginDictionary("mask_layer");
1808 mask_layer_->AsValueInto(state);
1809 state->EndDictionary();
1811 if (replica_layer_) {
1812 state->BeginDictionary("replica_layer");
1813 replica_layer_->AsValueInto(state);
1814 state->EndDictionary();
1817 if (scroll_parent_)
1818 state->SetInteger("scroll_parent", scroll_parent_->id());
1820 if (clip_parent_)
1821 state->SetInteger("clip_parent", clip_parent_->id());
1823 state->SetBoolean("can_use_lcd_text", can_use_lcd_text());
1824 state->SetBoolean("contents_opaque", contents_opaque());
1826 state->SetBoolean(
1827 "has_animation_bounds",
1828 layer_animation_controller_
1829 ? layer_animation_controller_->HasAnimationThatInflatesBounds()
1830 : layer_tree_impl_->HasAnimationThatInflatesBounds(this));
1832 gfx::BoxF box;
1833 if (LayerUtils::GetAnimationBounds(*this, &box))
1834 MathUtil::AddToTracedValue("animation_bounds", box, state);
1836 if (debug_info_.get()) {
1837 std::string str;
1838 debug_info_->AppendAsTraceFormat(&str);
1839 base::JSONReader json_reader;
1840 scoped_ptr<base::Value> debug_info_value(json_reader.ReadToValue(str));
1842 if (debug_info_value->IsType(base::Value::TYPE_DICTIONARY)) {
1843 base::DictionaryValue* dictionary_value = nullptr;
1844 bool converted_to_dictionary =
1845 debug_info_value->GetAsDictionary(&dictionary_value);
1846 DCHECK(converted_to_dictionary);
1847 for (base::DictionaryValue::Iterator it(*dictionary_value); !it.IsAtEnd();
1848 it.Advance()) {
1849 state->SetValue(it.key().data(), it.value().CreateDeepCopy());
1851 } else {
1852 NOTREACHED();
1856 if (!frame_timing_requests_.empty()) {
1857 state->BeginArray("frame_timing_requests");
1858 for (const auto& request : frame_timing_requests_) {
1859 state->BeginDictionary();
1860 state->SetInteger("request_id", request.id());
1861 MathUtil::AddToTracedValue("request_rect", request.rect(), state);
1862 state->EndDictionary();
1864 state->EndArray();
1868 bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const {
1869 return draw_properties_.last_drawn_render_surface_layer_list_id ==
1870 layer_tree_impl_->current_render_surface_list_id();
1873 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1875 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl* benchmark) {
1876 benchmark->RunOnLayer(this);
1879 int LayerImpl::NumDescendantsThatDrawContent() const {
1880 return num_descendants_that_draw_content_;
1883 void LayerImpl::NotifyAnimationFinished(
1884 base::TimeTicks monotonic_time,
1885 Animation::TargetProperty target_property,
1886 int group) {
1887 if (target_property == Animation::SCROLL_OFFSET)
1888 layer_tree_impl_->InputScrollAnimationFinished();
1891 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface) {
1892 if (!!render_surface() == should_have_render_surface)
1893 return;
1895 SetNeedsPushProperties();
1896 layer_tree_impl()->set_needs_update_draw_properties();
1897 if (should_have_render_surface) {
1898 render_surface_ = make_scoped_ptr(new RenderSurfaceImpl(this));
1899 return;
1901 render_surface_.reset();
1904 Region LayerImpl::GetInvalidationRegion() {
1905 return Region(update_rect_);
1908 gfx::Rect LayerImpl::GetEnclosingRectInTargetSpace() const {
1909 return MathUtil::MapEnclosingClippedRect(
1910 draw_properties_.target_space_transform, gfx::Rect(bounds()));
1913 gfx::Rect LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale) const {
1914 gfx::Transform scaled_draw_transform =
1915 draw_properties_.target_space_transform;
1916 scaled_draw_transform.Scale(SK_MScalar1 / scale, SK_MScalar1 / scale);
1917 gfx::Size scaled_bounds = gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale));
1918 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform,
1919 gfx::Rect(scaled_bounds));
1922 float LayerImpl::GetIdealContentsScale() const {
1923 float page_scale = IsAffectedByPageScale()
1924 ? layer_tree_impl()->current_page_scale_factor()
1925 : 1.f;
1926 float device_scale = layer_tree_impl()->device_scale_factor();
1928 float default_scale = page_scale * device_scale;
1929 if (!layer_tree_impl()
1930 ->settings()
1931 .layer_transforms_should_scale_layer_contents) {
1932 return default_scale;
1935 // TODO(enne): the transform needs to come from property trees instead of
1936 // draw properties.
1937 gfx::Vector2dF transform_scales = MathUtil::ComputeTransform2dScaleComponents(
1938 draw_properties().target_space_transform, default_scale);
1939 return std::max(transform_scales.x(), transform_scales.y());
1942 } // namespace cc