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"
38 LayerImpl::LayerImpl(LayerTreeImpl
* layer_impl
, int id
)
39 : LayerImpl(layer_impl
, id
, new LayerImpl::SyncedScrollOffset
) {
42 LayerImpl::LayerImpl(LayerTreeImpl
* tree_impl
,
44 scoped_refptr
<SyncedScrollOffset
> scroll_offset
)
46 scroll_parent_(nullptr),
47 clip_parent_(nullptr),
49 replica_layer_id_(-1),
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),
62 should_flatten_transform_(true),
63 should_flatten_transform_from_property_tree_(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),
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),
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),
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);
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();
138 scoped_ptr
<LayerImpl
> ret
= children_
.take(it
);
140 layer_tree_impl()->set_needs_update_draw_properties();
147 void LayerImpl::SetParent(LayerImpl
* parent
) {
148 if (parent_should_know_need_push_properties()) {
150 parent_
->RemoveDependentNeedsPushProperties();
152 parent
->AddDependentNeedsPushProperties();
157 void LayerImpl::ClearChildList() {
158 if (children_
.empty())
162 layer_tree_impl()->set_needs_update_draw_properties();
165 bool LayerImpl::HasAncestor(const LayerImpl
* ancestor
) const {
169 for (const LayerImpl
* layer
= this; layer
; layer
= layer
->parent()) {
170 if (layer
== ancestor
)
177 void LayerImpl::SetScrollParent(LayerImpl
* parent
) {
178 if (scroll_parent_
== 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
) {
191 SetNeedsPushProperties();
194 void LayerImpl::SetScrollChildren(std::set
<LayerImpl
*>* children
) {
195 if (scroll_children_
.get() == children
)
197 scroll_children_
.reset(children
);
198 SetNeedsPushProperties();
201 void LayerImpl::DistributeScroll(ScrollState
* scroll_state
) {
202 DCHECK(scroll_state
);
203 if (scroll_state
->FullyConsumed())
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) {
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
)
228 num_descendants_that_draw_content_
= num_descendants
;
229 SetNeedsPushProperties();
232 void LayerImpl::SetClipParent(LayerImpl
* ancestor
) {
233 if (clip_parent_
== ancestor
)
236 clip_parent_
= ancestor
;
237 SetNeedsPushProperties();
240 void LayerImpl::SetClipChildren(std::set
<LayerImpl
*>* children
) {
241 if (clip_children_
.get() == children
)
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())
276 DCHECK(render_surface());
277 bool was_empty
= copy_requests_
.empty();
278 copy_requests_
.insert_and_take(copy_requests_
.end(), requests
);
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(), ©_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())
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() {
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
,
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
;
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());
364 if (masks_to_bounds_
) {
365 *color
= DebugColors::MaskingLayerBorderColor();
366 *width
= DebugColors::MaskingLayerBorderWidth(layer_tree_impl());
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 {
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
,
392 if (!ShowDebugBorders())
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())
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 {
425 bool LayerImpl::HasContributingDelegatedRenderPasses() const {
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 {
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
);
501 non_fast_scrollable_region().Contains(
502 gfx::ToRoundedPoint(hit_test_point_in_layer_space
))) {
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
;
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) {
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();
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
);
615 layer
->SetScrollChildren(nullptr);
618 LayerImpl
* clip_parent
= nullptr;
620 clip_parent
= layer
->layer_tree_impl()->LayerById(
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
);
633 layer
->SetClipChildren(nullptr);
636 layer
->PassCopyRequests(©_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
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_
);
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
);
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 {
767 const ResourceProvider
* resource_provider
=
768 layer_tree_impl_
->resource_provider();
769 for (ResourceId resource_id
: quad
->resources
)
770 resource_provider
->ValidateResource(resource_id
);
774 const char* LayerImpl::LayerTypeAsString() const {
775 return "cc::LayerImpl";
778 void LayerImpl::ResetAllChangeTrackingForSubtree() {
779 layer_property_changed_
= false;
781 update_rect_
.SetRect(0, 0, 0, 0);
782 damage_rect_
.SetRect(0, 0, 0, 0);
785 render_surface_
->ResetPropertyChangedFlag();
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
813 if (node
->owner_id
!= id())
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
843 if (node
->owner_id
!= id())
845 if (node
->data
.is_animated
!= is_animated
) {
846 node
->data
.is_animated
= 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
853 float animation_start_scale
= 0.f
;
854 node
->data
.local_starting_animation_scale
=
855 AnimationStartScale(&animation_start_scale
) ? animation_start_scale
858 node
->data
.has_only_translation_animations
=
859 HasOnlyTranslationTransforms();
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())
882 node
->data
.opacity
= opacity_
;
883 effect_tree
.set_needs_update(true);
887 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() {
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
) {
909 void LayerImpl::OnOpacityAnimated(float 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.
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
)
958 ScrollbarParametersDidChange(true);
959 if (masks_to_bounds())
960 NoteLayerPropertyChangedForSubtree();
962 NoteLayerPropertyChanged();
965 void LayerImpl::SetBoundsDelta(const gfx::Vector2dF
& bounds_delta
) {
967 if (bounds_delta_
== bounds_delta
)
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());
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();
994 NoteLayerPropertyChanged();
998 void LayerImpl::SetMaskLayer(scoped_ptr
<LayerImpl
> mask_layer
) {
999 int new_layer_id
= mask_layer
? mask_layer
->id() : -1;
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_
) {
1008 mask_layer_
= mask_layer
.Pass();
1009 mask_layer_id_
= new_layer_id
;
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_
) {
1030 replica_layer_
= replica_layer
.Pass();
1031 replica_layer_id_
= new_layer_id
;
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() {
1046 void LayerImpl::SetDrawsContent(bool draws_content
) {
1047 if (draws_content_
== draws_content
)
1050 draws_content_
= draws_content
;
1051 NoteLayerPropertyChanged();
1054 void LayerImpl::SetHideLayerAndSubtree(bool hide
) {
1055 if (hide_layer_and_subtree_
== hide
)
1058 hide_layer_and_subtree_
= hide
;
1059 NoteLayerPropertyChangedForSubtree();
1062 void LayerImpl::SetTransformOrigin(const gfx::Point3F
& transform_origin
) {
1063 if (transform_origin_
== transform_origin
)
1065 transform_origin_
= transform_origin
;
1066 NoteLayerPropertyChangedForSubtree();
1069 void LayerImpl::SetBackgroundColor(SkColor background_color
) {
1070 if (background_color_
== background_color
)
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)
1088 if (SkColorGetA(color
) != 255)
1089 color
= layer_tree_impl()->background_color();
1090 if (SkColorGetA(color
) != 255)
1091 color
= SkColorSetA(color
, 255);
1096 void LayerImpl::SetFilters(const FilterOperations
& filters
) {
1097 if (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
)
1138 background_filters_
= filters
;
1139 NoteLayerPropertyChanged();
1142 void LayerImpl::SetMasksToBounds(bool masks_to_bounds
) {
1143 if (masks_to_bounds_
== masks_to_bounds
)
1146 masks_to_bounds_
= masks_to_bounds
;
1147 NoteLayerPropertyChangedForSubtree();
1150 void LayerImpl::SetContentsOpaque(bool opaque
) {
1151 if (contents_opaque_
== opaque
)
1154 contents_opaque_
= opaque
;
1155 NoteLayerPropertyChangedForSubtree();
1158 void LayerImpl::SetOpacity(float opacity
) {
1159 if (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
)
1199 blend_mode_
= blend_mode
;
1200 NoteLayerPropertyChangedForSubtree();
1203 void LayerImpl::SetIsRootForIsolatedGroup(bool root
) {
1204 if (is_root_for_isolated_group_
== root
)
1207 is_root_for_isolated_group_
= root
;
1208 SetNeedsPushProperties();
1211 void LayerImpl::SetPosition(const gfx::PointF
& position
) {
1212 if (position_
== position
)
1215 position_
= position
;
1216 NoteLayerPropertyChangedForSubtree();
1219 void LayerImpl::SetShouldFlattenTransform(bool flatten
) {
1220 if (should_flatten_transform_
== flatten
)
1223 should_flatten_transform_
= flatten
;
1224 NoteLayerPropertyChangedForSubtree();
1227 void LayerImpl::Set3dSortingContextId(int id
) {
1228 if (id
== sorting_context_id_
)
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
)
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";
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(
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
,
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
,
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
,
1375 void LayerImpl::SetUpdateRect(const gfx::Rect
& update_rect
) {
1376 update_rect_
= update_rect
;
1377 SetNeedsPushProperties();
1380 void LayerImpl::AddDamageRect(const gfx::Rect
& damage_rect
) {
1381 damage_rect_
.Union(damage_rect
);
1384 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset
& scroll_offset
) {
1386 if (scroll_offset_
->SetCurrent(scroll_offset
))
1387 DidUpdateScrollOffset(false);
1390 void LayerImpl::SetCurrentScrollOffsetFromDelegate(
1391 const gfx::ScrollOffset
& scroll_offset
) {
1393 if (scroll_offset_
->SetCurrent(scroll_offset
))
1394 DidUpdateScrollOffset(true);
1397 void LayerImpl::PushScrollOffsetFromMainThread(
1398 const gfx::ScrollOffset
& scroll_offset
) {
1399 PushScrollOffset(&scroll_offset
);
1402 void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1403 const gfx::ScrollOffset
& scroll_offset
) {
1404 scroll_offset_
->set_clobber_active_value();
1405 PushScrollOffset(&scroll_offset
);
1408 gfx::ScrollOffset
LayerImpl::PullDeltaForMainThread() {
1409 // TODO(miletus): Remove all this temporary flooring machinery when
1410 // Blink fully supports fractional scrolls.
1411 gfx::ScrollOffset current_offset
= CurrentScrollOffset();
1412 gfx::ScrollOffset current_delta
= IsActive()
1413 ? scroll_offset_
->Delta()
1414 : scroll_offset_
->PendingDelta().get();
1415 gfx::ScrollOffset
floored_delta(floor(current_delta
.x()),
1416 floor(current_delta
.y()));
1417 gfx::ScrollOffset diff_delta
= floored_delta
- current_delta
;
1418 gfx::ScrollOffset tmp_offset
= current_offset
+ diff_delta
;
1419 scroll_offset_
->SetCurrent(tmp_offset
);
1420 gfx::ScrollOffset delta
= scroll_offset_
->PullDeltaForMainThread();
1421 scroll_offset_
->SetCurrent(current_offset
);
1425 gfx::ScrollOffset
LayerImpl::CurrentScrollOffset() const {
1426 return scroll_offset_
->Current(IsActive());
1429 gfx::Vector2dF
LayerImpl::ScrollDelta() const {
1431 return gfx::Vector2dF(scroll_offset_
->Delta().x(),
1432 scroll_offset_
->Delta().y());
1434 return gfx::Vector2dF(scroll_offset_
->PendingDelta().get().x(),
1435 scroll_offset_
->PendingDelta().get().y());
1438 void LayerImpl::SetScrollDelta(const gfx::Vector2dF
& delta
) {
1440 DCHECK(scrollable() || delta
.IsZero());
1441 SetCurrentScrollOffset(scroll_offset_
->ActiveBase() +
1442 gfx::ScrollOffset(delta
));
1445 gfx::ScrollOffset
LayerImpl::BaseScrollOffset() const {
1447 return scroll_offset_
->ActiveBase();
1449 return scroll_offset_
->PendingBase();
1452 void LayerImpl::PushScrollOffset(const gfx::ScrollOffset
* scroll_offset
) {
1453 DCHECK(scroll_offset
|| IsActive());
1454 bool changed
= false;
1455 if (scroll_offset
) {
1456 DCHECK(!IsActive() || !layer_tree_impl_
->FindPendingTreeLayerById(id()));
1457 changed
|= scroll_offset_
->PushFromMainThread(*scroll_offset
);
1460 changed
|= scroll_offset_
->PushPendingToActive();
1464 DidUpdateScrollOffset(false);
1467 void LayerImpl::UpdatePropertyTreeScrollOffset() {
1468 // TODO(enne): in the future, scrolling should update the scroll tree
1469 // directly instead of going through layers.
1470 if (transform_tree_index_
!= -1) {
1471 TransformTree
& transform_tree
=
1472 layer_tree_impl()->property_trees()->transform_tree
;
1473 TransformNode
* node
= transform_tree
.Node(transform_tree_index_
);
1474 gfx::ScrollOffset current_offset
= scroll_offset_
->Current(IsActive());
1475 if (node
->data
.scroll_offset
!= current_offset
) {
1476 node
->data
.scroll_offset
= current_offset
;
1477 node
->data
.needs_local_transform_update
= true;
1478 transform_tree
.set_needs_update(true);
1483 void LayerImpl::DidUpdateScrollOffset(bool is_from_root_delegate
) {
1484 DCHECK(scroll_offset_
);
1486 if (!is_from_root_delegate
)
1487 layer_tree_impl()->DidUpdateScrollOffset(id());
1488 NoteLayerPropertyChangedForSubtree();
1489 ScrollbarParametersDidChange(false);
1491 UpdatePropertyTreeScrollOffset();
1493 // Inform the pending twin that a property changed.
1494 if (layer_tree_impl()->IsActiveTree()) {
1495 LayerImpl
* pending_twin
= layer_tree_impl()->FindPendingTreeLayerById(id());
1497 pending_twin
->DidUpdateScrollOffset(is_from_root_delegate
);
1501 void LayerImpl::SetDoubleSided(bool double_sided
) {
1502 if (double_sided_
== double_sided
)
1505 double_sided_
= double_sided
;
1506 NoteLayerPropertyChangedForSubtree();
1509 SimpleEnclosedRegion
LayerImpl::VisibleOpaqueRegion() const {
1510 if (contents_opaque())
1511 return SimpleEnclosedRegion(visible_layer_rect());
1512 return SimpleEnclosedRegion();
1515 void LayerImpl::DidBeginTracing() {}
1517 void LayerImpl::ReleaseResources() {}
1519 void LayerImpl::RecreateResources() {
1522 gfx::ScrollOffset
LayerImpl::MaxScrollOffset() const {
1523 if (!scroll_clip_layer_
|| bounds().IsEmpty())
1524 return gfx::ScrollOffset();
1526 LayerImpl
const* page_scale_layer
= layer_tree_impl()->PageScaleLayer();
1527 DCHECK(this != page_scale_layer
);
1528 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1529 IsContainerForFixedPositionLayers());
1531 float scale_factor
= 1.f
;
1532 for (LayerImpl
const* current_layer
= this;
1533 current_layer
!= scroll_clip_layer_
->parent();
1534 current_layer
= current_layer
->parent()) {
1535 if (current_layer
== page_scale_layer
)
1536 scale_factor
= layer_tree_impl()->current_page_scale_factor();
1539 gfx::SizeF scaled_scroll_bounds
=
1540 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor
));
1541 scaled_scroll_bounds
= gfx::ToFlooredSize(scaled_scroll_bounds
);
1543 gfx::ScrollOffset
max_offset(
1544 scaled_scroll_bounds
.width() - scroll_clip_layer_
->bounds().width(),
1545 scaled_scroll_bounds
.height() - scroll_clip_layer_
->bounds().height());
1546 // We need the final scroll offset to be in CSS coords.
1547 max_offset
.Scale(1 / scale_factor
);
1548 max_offset
.SetToMax(gfx::ScrollOffset());
1552 gfx::ScrollOffset
LayerImpl::ClampScrollOffsetToLimits(
1553 gfx::ScrollOffset offset
) const {
1554 offset
.SetToMin(MaxScrollOffset());
1555 offset
.SetToMax(gfx::ScrollOffset());
1559 gfx::Vector2dF
LayerImpl::ClampScrollToMaxScrollOffset() {
1560 gfx::ScrollOffset old_offset
= CurrentScrollOffset();
1561 gfx::ScrollOffset clamped_offset
= ClampScrollOffsetToLimits(old_offset
);
1562 gfx::Vector2dF delta
= clamped_offset
.DeltaFrom(old_offset
);
1563 if (!delta
.IsZero())
1568 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase
* scrollbar_layer
,
1569 LayerImpl
* scrollbar_clip_layer
,
1570 bool on_resize
) const {
1571 DCHECK(scrollbar_layer
);
1572 LayerImpl
* page_scale_layer
= layer_tree_impl()->PageScaleLayer();
1574 DCHECK(this != page_scale_layer
);
1575 DCHECK(scrollbar_clip_layer
);
1576 gfx::RectF
clip_rect(gfx::PointF(),
1577 scrollbar_clip_layer
->BoundsForScrolling());
1579 // See comment in MaxScrollOffset() regarding the use of the content layer
1581 gfx::RectF
scroll_rect(gfx::PointF(), BoundsForScrolling());
1583 if (scroll_rect
.size().IsEmpty())
1586 gfx::ScrollOffset current_offset
;
1587 for (LayerImpl
const* current_layer
= this;
1588 current_layer
!= scrollbar_clip_layer
->parent();
1589 current_layer
= current_layer
->parent()) {
1590 current_offset
+= current_layer
->CurrentScrollOffset();
1591 if (current_layer
== page_scale_layer
) {
1592 float scale_factor
= layer_tree_impl()->current_page_scale_factor();
1593 current_offset
.Scale(scale_factor
);
1594 scroll_rect
.Scale(scale_factor
);
1598 bool scrollbar_needs_animation
= false;
1599 scrollbar_needs_animation
|= scrollbar_layer
->SetVerticalAdjust(
1600 scrollbar_clip_layer
->bounds_delta().y());
1601 if (scrollbar_layer
->orientation() == HORIZONTAL
) {
1602 float visible_ratio
= clip_rect
.width() / scroll_rect
.width();
1603 scrollbar_needs_animation
|=
1604 scrollbar_layer
->SetCurrentPos(current_offset
.x());
1605 scrollbar_needs_animation
|=
1606 scrollbar_layer
->SetMaximum(scroll_rect
.width() - clip_rect
.width());
1607 scrollbar_needs_animation
|=
1608 scrollbar_layer
->SetVisibleToTotalLengthRatio(visible_ratio
);
1610 float visible_ratio
= clip_rect
.height() / scroll_rect
.height();
1611 bool y_offset_did_change
=
1612 scrollbar_layer
->SetCurrentPos(current_offset
.y());
1613 scrollbar_needs_animation
|= y_offset_did_change
;
1614 scrollbar_needs_animation
|=
1615 scrollbar_layer
->SetMaximum(scroll_rect
.height() - clip_rect
.height());
1616 scrollbar_needs_animation
|=
1617 scrollbar_layer
->SetVisibleToTotalLengthRatio(visible_ratio
);
1618 if (y_offset_did_change
&& layer_tree_impl()->IsActiveTree() &&
1619 this == layer_tree_impl()->OuterViewportScrollLayer()) {
1620 TRACE_COUNTER_ID1("cc", "scroll_offset_y", this->id(),
1621 current_offset
.y());
1624 if (scrollbar_needs_animation
) {
1625 layer_tree_impl()->set_needs_update_draw_properties();
1626 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars
1627 // should activate for every scroll on the main frame, not just the
1628 // scrolls that move the pinch virtual viewport (i.e. trigger from
1629 // either inner or outer viewport).
1630 if (scrollbar_animation_controller_
) {
1631 // Non-overlay scrollbars shouldn't trigger animations.
1632 if (scrollbar_layer
->is_overlay_scrollbar())
1633 scrollbar_animation_controller_
->DidScrollUpdate(on_resize
);
1638 void LayerImpl::DidBecomeActive() {
1639 if (layer_tree_impl_
->settings().scrollbar_animator
==
1640 LayerTreeSettings::NO_ANIMATOR
) {
1644 bool need_scrollbar_animation_controller
= scrollable() && scrollbars_
;
1645 if (!need_scrollbar_animation_controller
) {
1646 scrollbar_animation_controller_
= nullptr;
1650 if (scrollbar_animation_controller_
)
1653 scrollbar_animation_controller_
=
1654 layer_tree_impl_
->CreateScrollbarAnimationController(this);
1657 void LayerImpl::ClearScrollbars() {
1661 scrollbars_
.reset(nullptr);
1664 void LayerImpl::AddScrollbar(ScrollbarLayerImplBase
* layer
) {
1666 DCHECK(!scrollbars_
|| scrollbars_
->find(layer
) == scrollbars_
->end());
1668 scrollbars_
.reset(new ScrollbarSet());
1670 scrollbars_
->insert(layer
);
1673 void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase
* layer
) {
1674 DCHECK(scrollbars_
);
1676 DCHECK(scrollbars_
->find(layer
) != scrollbars_
->end());
1678 scrollbars_
->erase(layer
);
1679 if (scrollbars_
->empty())
1680 scrollbars_
= nullptr;
1683 bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation
) const {
1687 for (ScrollbarSet::iterator it
= scrollbars_
->begin();
1688 it
!= scrollbars_
->end();
1690 if ((*it
)->orientation() == orientation
)
1696 void LayerImpl::ScrollbarParametersDidChange(bool on_resize
) {
1700 for (ScrollbarSet::iterator it
= scrollbars_
->begin();
1701 it
!= scrollbars_
->end();
1703 bool is_scroll_layer
= (*it
)->ScrollLayerId() == layer_id_
;
1704 bool scroll_layer_resized
= is_scroll_layer
&& on_resize
;
1705 (*it
)->ScrollbarParametersDidChange(scroll_layer_resized
);
1709 void LayerImpl::SetNeedsPushProperties() {
1710 if (needs_push_properties_
)
1712 if (!parent_should_know_need_push_properties() && parent_
)
1713 parent_
->AddDependentNeedsPushProperties();
1714 needs_push_properties_
= true;
1717 void LayerImpl::AddDependentNeedsPushProperties() {
1718 DCHECK_GE(num_dependents_need_push_properties_
, 0);
1720 if (!parent_should_know_need_push_properties() && parent_
)
1721 parent_
->AddDependentNeedsPushProperties();
1723 num_dependents_need_push_properties_
++;
1726 void LayerImpl::RemoveDependentNeedsPushProperties() {
1727 num_dependents_need_push_properties_
--;
1728 DCHECK_GE(num_dependents_need_push_properties_
, 0);
1730 if (!parent_should_know_need_push_properties() && parent_
)
1731 parent_
->RemoveDependentNeedsPushProperties();
1734 void LayerImpl::GetAllPrioritizedTilesForTracing(
1735 std::vector
<PrioritizedTile
>* prioritized_tiles
) const {
1738 void LayerImpl::AsValueInto(base::trace_event::TracedValue
* state
) const {
1739 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
1740 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1743 LayerTypeAsString(),
1745 state
->SetInteger("layer_id", id());
1746 MathUtil::AddToTracedValue("bounds", bounds_
, state
);
1748 state
->SetDouble("opacity", opacity());
1750 MathUtil::AddToTracedValue("position", position_
, state
);
1752 state
->SetInteger("draws_content", DrawsContent());
1753 state
->SetInteger("gpu_memory_usage",
1754 base::saturated_cast
<int>(GPUMemoryUsageInBytes()));
1756 MathUtil::AddToTracedValue(
1757 "scroll_offset", scroll_offset_
? scroll_offset_
->Current(IsActive())
1758 : gfx::ScrollOffset(),
1761 MathUtil::AddToTracedValue("transform_origin", transform_origin_
, state
);
1764 gfx::QuadF layer_quad
=
1765 MathUtil::MapQuad(screen_space_transform(),
1766 gfx::QuadF(gfx::RectF(gfx::Rect(bounds()))), &clipped
);
1767 MathUtil::AddToTracedValue("layer_quad", layer_quad
, state
);
1768 if (!touch_event_handler_region_
.IsEmpty()) {
1769 state
->BeginArray("touch_event_handler_region");
1770 touch_event_handler_region_
.AsValueInto(state
);
1773 if (have_wheel_event_handlers_
) {
1774 gfx::Rect
wheel_rect(bounds());
1775 Region
wheel_region(wheel_rect
);
1776 state
->BeginArray("wheel_event_handler_region");
1777 wheel_region
.AsValueInto(state
);
1780 if (have_scroll_event_handlers_
) {
1781 gfx::Rect
scroll_rect(bounds());
1782 Region
scroll_region(scroll_rect
);
1783 state
->BeginArray("scroll_event_handler_region");
1784 scroll_region
.AsValueInto(state
);
1787 if (!non_fast_scrollable_region_
.IsEmpty()) {
1788 state
->BeginArray("non_fast_scrollable_region");
1789 non_fast_scrollable_region_
.AsValueInto(state
);
1792 if (scroll_blocks_on_
) {
1793 state
->SetInteger("scroll_blocks_on", scroll_blocks_on_
);
1796 state
->BeginArray("children");
1797 for (size_t i
= 0; i
< children_
.size(); ++i
) {
1798 state
->BeginDictionary();
1799 children_
[i
]->AsValueInto(state
);
1800 state
->EndDictionary();
1804 state
->BeginDictionary("mask_layer");
1805 mask_layer_
->AsValueInto(state
);
1806 state
->EndDictionary();
1808 if (replica_layer_
) {
1809 state
->BeginDictionary("replica_layer");
1810 replica_layer_
->AsValueInto(state
);
1811 state
->EndDictionary();
1815 state
->SetInteger("scroll_parent", scroll_parent_
->id());
1818 state
->SetInteger("clip_parent", clip_parent_
->id());
1820 state
->SetBoolean("can_use_lcd_text", can_use_lcd_text());
1821 state
->SetBoolean("contents_opaque", contents_opaque());
1824 "has_animation_bounds",
1825 layer_animation_controller_
1826 ? layer_animation_controller_
->HasAnimationThatInflatesBounds()
1827 : layer_tree_impl_
->HasAnimationThatInflatesBounds(this));
1830 if (LayerUtils::GetAnimationBounds(*this, &box
))
1831 MathUtil::AddToTracedValue("animation_bounds", box
, state
);
1833 if (debug_info_
.get()) {
1835 debug_info_
->AppendAsTraceFormat(&str
);
1836 base::JSONReader json_reader
;
1837 scoped_ptr
<base::Value
> debug_info_value(json_reader
.ReadToValue(str
));
1839 if (debug_info_value
->IsType(base::Value::TYPE_DICTIONARY
)) {
1840 base::DictionaryValue
* dictionary_value
= nullptr;
1841 bool converted_to_dictionary
=
1842 debug_info_value
->GetAsDictionary(&dictionary_value
);
1843 DCHECK(converted_to_dictionary
);
1844 for (base::DictionaryValue::Iterator
it(*dictionary_value
); !it
.IsAtEnd();
1846 state
->SetValue(it
.key().data(), it
.value().CreateDeepCopy());
1853 if (!frame_timing_requests_
.empty()) {
1854 state
->BeginArray("frame_timing_requests");
1855 for (const auto& request
: frame_timing_requests_
) {
1856 state
->BeginDictionary();
1857 state
->SetInteger("request_id", request
.id());
1858 MathUtil::AddToTracedValue("request_rect", request
.rect(), state
);
1859 state
->EndDictionary();
1865 bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const {
1866 return draw_properties_
.last_drawn_render_surface_layer_list_id
==
1867 layer_tree_impl_
->current_render_surface_list_id();
1870 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1872 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) {
1873 benchmark
->RunOnLayer(this);
1876 int LayerImpl::NumDescendantsThatDrawContent() const {
1877 return num_descendants_that_draw_content_
;
1880 void LayerImpl::NotifyAnimationFinished(
1881 base::TimeTicks monotonic_time
,
1882 Animation::TargetProperty target_property
,
1884 if (target_property
== Animation::SCROLL_OFFSET
)
1885 layer_tree_impl_
->InputScrollAnimationFinished();
1888 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface
) {
1889 if (!!render_surface() == should_have_render_surface
)
1892 SetNeedsPushProperties();
1893 layer_tree_impl()->set_needs_update_draw_properties();
1894 if (should_have_render_surface
) {
1895 render_surface_
= make_scoped_ptr(new RenderSurfaceImpl(this));
1898 render_surface_
.reset();
1901 Region
LayerImpl::GetInvalidationRegion() {
1902 return Region(update_rect_
);
1905 gfx::Rect
LayerImpl::GetEnclosingRectInTargetSpace() const {
1906 return MathUtil::MapEnclosingClippedRect(
1907 draw_properties_
.target_space_transform
, gfx::Rect(bounds()));
1910 gfx::Rect
LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale
) const {
1911 gfx::Transform scaled_draw_transform
=
1912 draw_properties_
.target_space_transform
;
1913 scaled_draw_transform
.Scale(SK_MScalar1
/ scale
, SK_MScalar1
/ scale
);
1914 gfx::Size scaled_bounds
= gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale
));
1915 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform
,
1916 gfx::Rect(scaled_bounds
));
1919 float LayerImpl::GetIdealContentsScale() const {
1920 float page_scale
= IsAffectedByPageScale()
1921 ? layer_tree_impl()->current_page_scale_factor()
1923 float device_scale
= layer_tree_impl()->device_scale_factor();
1925 float default_scale
= page_scale
* device_scale
;
1926 if (!layer_tree_impl()
1928 .layer_transforms_should_scale_layer_contents
) {
1929 return default_scale
;
1932 // TODO(enne): the transform needs to come from property trees instead of
1934 gfx::Vector2dF transform_scales
= MathUtil::ComputeTransform2dScaleComponents(
1935 draw_properties().target_space_transform
, default_scale
);
1936 return std::max(transform_scales
.x(), transform_scales
.y());