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_
= gfx::Rect();
782 damage_rect_
= gfx::RectF();
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
;
847 transform_tree
.set_needs_update(true);
852 void LayerImpl::UpdatePropertyTreeOpacity() {
853 if (effect_tree_index_
!= -1) {
854 EffectTree
& effect_tree
= layer_tree_impl()->property_trees()->effect_tree
;
855 EffectNode
* node
= effect_tree
.Node(effect_tree_index_
);
856 // A LayerImpl's own current state is insufficient for determining whether
857 // it owns an OpacityNode, since this depends on the state of the
858 // corresponding Layer at the time of the last commit. For example, an
859 // opacity animation might have been in progress at the time the last commit
860 // started, but might have finished since then on the compositor thread.
861 if (node
->owner_id
!= id())
863 node
->data
.opacity
= opacity_
;
864 effect_tree
.set_needs_update(true);
868 void LayerImpl::UpdatePropertyTreeForScrollingAndAnimationIfNeeded() {
870 UpdatePropertyTreeScrollOffset();
872 if (HasAnyAnimationTargetingProperty(Animation::OPACITY
))
873 UpdatePropertyTreeOpacity();
875 if (HasAnyAnimationTargetingProperty(Animation::TRANSFORM
)) {
876 UpdatePropertyTreeTransform();
877 UpdatePropertyTreeTransformIsAnimated(
878 HasPotentiallyRunningTransformAnimation());
882 gfx::ScrollOffset
LayerImpl::ScrollOffsetForAnimation() const {
883 return CurrentScrollOffset();
886 void LayerImpl::OnFilterAnimated(const FilterOperations
& filters
) {
890 void LayerImpl::OnOpacityAnimated(float opacity
) {
892 UpdatePropertyTreeOpacity();
895 void LayerImpl::OnTransformAnimated(const gfx::Transform
& transform
) {
896 SetTransform(transform
);
897 UpdatePropertyTreeTransform();
900 void LayerImpl::OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) {
901 // Only layers in the active tree should need to do anything here, since
902 // layers in the pending tree will find out about these changes as a
903 // result of the shared SyncedProperty.
907 SetCurrentScrollOffset(scroll_offset
);
909 layer_tree_impl_
->DidAnimateScrollOffset();
912 void LayerImpl::OnAnimationWaitingForDeletion() {}
914 void LayerImpl::OnTransformIsPotentiallyAnimatingChanged(bool is_animating
) {
915 UpdatePropertyTreeTransformIsAnimated(is_animating
);
918 bool LayerImpl::IsActive() const {
919 return layer_tree_impl_
->IsActiveTree();
922 gfx::Size
LayerImpl::bounds() const {
923 gfx::Vector2d delta
= gfx::ToCeiledVector2d(bounds_delta_
);
924 return gfx::Size(bounds_
.width() + delta
.x(),
925 bounds_
.height() + delta
.y());
928 gfx::SizeF
LayerImpl::BoundsForScrolling() const {
929 return gfx::SizeF(bounds_
.width() + bounds_delta_
.x(),
930 bounds_
.height() + bounds_delta_
.y());
933 void LayerImpl::SetBounds(const gfx::Size
& bounds
) {
934 if (bounds_
== bounds
)
939 ScrollbarParametersDidChange(true);
940 if (masks_to_bounds())
941 NoteLayerPropertyChangedForSubtree();
943 NoteLayerPropertyChanged();
946 void LayerImpl::SetBoundsDelta(const gfx::Vector2dF
& bounds_delta
) {
948 if (bounds_delta_
== bounds_delta
)
951 bounds_delta_
= bounds_delta
;
953 TransformTree
& transform_tree
=
954 layer_tree_impl()->property_trees()->transform_tree
;
955 if (this == layer_tree_impl()->InnerViewportContainerLayer())
956 transform_tree
.SetInnerViewportBoundsDelta(bounds_delta
);
957 else if (this == layer_tree_impl()->OuterViewportContainerLayer())
958 transform_tree
.SetOuterViewportBoundsDelta(bounds_delta
);
960 ScrollbarParametersDidChange(true);
962 if (masks_to_bounds()) {
963 // If layer is clipping, then update the clip node using the new bounds.
964 ClipNode
* clip_node
=
965 layer_tree_impl()->property_trees()->clip_tree
.Node(clip_tree_index());
967 DCHECK(id() == clip_node
->owner_id
);
968 clip_node
->data
.clip
=
969 gfx::RectF(gfx::PointF() + offset_to_transform_parent(), bounds());
970 layer_tree_impl()->property_trees()->clip_tree
.set_needs_update(true);
973 NoteLayerPropertyChangedForSubtree();
975 NoteLayerPropertyChanged();
979 void LayerImpl::SetMaskLayer(scoped_ptr
<LayerImpl
> mask_layer
) {
980 int new_layer_id
= mask_layer
? mask_layer
->id() : -1;
983 DCHECK_EQ(layer_tree_impl(), mask_layer
->layer_tree_impl());
984 DCHECK_NE(new_layer_id
, mask_layer_id_
);
985 } else if (new_layer_id
== mask_layer_id_
) {
989 mask_layer_
= mask_layer
.Pass();
990 mask_layer_id_
= new_layer_id
;
992 mask_layer_
->SetParent(this);
993 NoteLayerPropertyChangedForSubtree();
996 scoped_ptr
<LayerImpl
> LayerImpl::TakeMaskLayer() {
998 return mask_layer_
.Pass();
1001 void LayerImpl::SetReplicaLayer(scoped_ptr
<LayerImpl
> replica_layer
) {
1002 int new_layer_id
= replica_layer
? replica_layer
->id() : -1;
1004 if (replica_layer
) {
1005 DCHECK_EQ(layer_tree_impl(), replica_layer
->layer_tree_impl());
1006 DCHECK_NE(new_layer_id
, replica_layer_id_
);
1007 } else if (new_layer_id
== replica_layer_id_
) {
1011 replica_layer_
= replica_layer
.Pass();
1012 replica_layer_id_
= new_layer_id
;
1014 replica_layer_
->SetParent(this);
1015 NoteLayerPropertyChangedForSubtree();
1018 scoped_ptr
<LayerImpl
> LayerImpl::TakeReplicaLayer() {
1019 replica_layer_id_
= -1;
1020 return replica_layer_
.Pass();
1023 ScrollbarLayerImplBase
* LayerImpl::ToScrollbarLayer() {
1027 void LayerImpl::SetDrawsContent(bool draws_content
) {
1028 if (draws_content_
== draws_content
)
1031 draws_content_
= draws_content
;
1032 NoteLayerPropertyChanged();
1035 void LayerImpl::SetHideLayerAndSubtree(bool hide
) {
1036 if (hide_layer_and_subtree_
== hide
)
1039 hide_layer_and_subtree_
= hide
;
1040 NoteLayerPropertyChangedForSubtree();
1043 void LayerImpl::SetTransformOrigin(const gfx::Point3F
& transform_origin
) {
1044 if (transform_origin_
== transform_origin
)
1046 transform_origin_
= transform_origin
;
1047 NoteLayerPropertyChangedForSubtree();
1050 void LayerImpl::SetBackgroundColor(SkColor background_color
) {
1051 if (background_color_
== background_color
)
1054 background_color_
= background_color
;
1055 NoteLayerPropertyChanged();
1058 SkColor
LayerImpl::SafeOpaqueBackgroundColor() const {
1059 SkColor color
= background_color();
1060 if (SkColorGetA(color
) == 255 && !contents_opaque()) {
1061 color
= SK_ColorTRANSPARENT
;
1062 } else if (SkColorGetA(color
) != 255 && contents_opaque()) {
1063 for (const LayerImpl
* layer
= parent(); layer
;
1064 layer
= layer
->parent()) {
1065 color
= layer
->background_color();
1066 if (SkColorGetA(color
) == 255)
1069 if (SkColorGetA(color
) != 255)
1070 color
= layer_tree_impl()->background_color();
1071 if (SkColorGetA(color
) != 255)
1072 color
= SkColorSetA(color
, 255);
1077 void LayerImpl::SetFilters(const FilterOperations
& filters
) {
1078 if (filters_
== filters
)
1082 NoteLayerPropertyChangedForSubtree();
1085 bool LayerImpl::FilterIsAnimating() const {
1086 LayerAnimationController::ObserverType observer_type
=
1087 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1088 : LayerAnimationController::ObserverType::PENDING
;
1089 return layer_animation_controller_
1090 ? layer_animation_controller_
->IsCurrentlyAnimatingProperty(
1091 Animation::FILTER
, observer_type
)
1092 : layer_tree_impl_
->IsAnimatingFilterProperty(this);
1095 bool LayerImpl::HasPotentiallyRunningFilterAnimation() const {
1096 LayerAnimationController::ObserverType observer_type
=
1097 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1098 : LayerAnimationController::ObserverType::PENDING
;
1099 return layer_animation_controller_
1100 ? layer_animation_controller_
->IsPotentiallyAnimatingProperty(
1101 Animation::FILTER
, observer_type
)
1102 : layer_tree_impl_
->HasPotentiallyRunningFilterAnimation(this);
1105 bool LayerImpl::FilterIsAnimatingOnImplOnly() const {
1106 if (!layer_animation_controller_
)
1107 return layer_tree_impl_
->FilterIsAnimatingOnImplOnly(this);
1109 Animation
* filter_animation
=
1110 layer_animation_controller_
->GetAnimation(Animation::FILTER
);
1111 return filter_animation
&& filter_animation
->is_impl_only();
1114 void LayerImpl::SetBackgroundFilters(
1115 const FilterOperations
& filters
) {
1116 if (background_filters_
== filters
)
1119 background_filters_
= filters
;
1120 NoteLayerPropertyChanged();
1123 void LayerImpl::SetMasksToBounds(bool masks_to_bounds
) {
1124 if (masks_to_bounds_
== masks_to_bounds
)
1127 masks_to_bounds_
= masks_to_bounds
;
1128 NoteLayerPropertyChangedForSubtree();
1131 void LayerImpl::SetContentsOpaque(bool opaque
) {
1132 if (contents_opaque_
== opaque
)
1135 contents_opaque_
= opaque
;
1136 NoteLayerPropertyChangedForSubtree();
1139 void LayerImpl::SetOpacity(float opacity
) {
1140 if (opacity_
== opacity
)
1144 NoteLayerPropertyChangedForSubtree();
1147 bool LayerImpl::OpacityIsAnimating() const {
1148 LayerAnimationController::ObserverType observer_type
=
1149 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1150 : LayerAnimationController::ObserverType::PENDING
;
1151 return layer_animation_controller_
1152 ? layer_animation_controller_
->IsCurrentlyAnimatingProperty(
1153 Animation::OPACITY
, observer_type
)
1154 : layer_tree_impl_
->IsAnimatingOpacityProperty(this);
1157 bool LayerImpl::HasPotentiallyRunningOpacityAnimation() const {
1158 LayerAnimationController::ObserverType observer_type
=
1159 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1160 : LayerAnimationController::ObserverType::PENDING
;
1161 return layer_animation_controller_
1162 ? layer_animation_controller_
->IsPotentiallyAnimatingProperty(
1163 Animation::OPACITY
, observer_type
)
1164 : layer_tree_impl_
->HasPotentiallyRunningOpacityAnimation(this);
1167 bool LayerImpl::OpacityIsAnimatingOnImplOnly() const {
1168 if (!layer_animation_controller_
)
1169 return layer_tree_impl_
->OpacityIsAnimatingOnImplOnly(this);
1171 Animation
* opacity_animation
=
1172 layer_animation_controller_
->GetAnimation(Animation::OPACITY
);
1173 return opacity_animation
&& opacity_animation
->is_impl_only();
1176 void LayerImpl::SetBlendMode(SkXfermode::Mode blend_mode
) {
1177 if (blend_mode_
== blend_mode
)
1180 blend_mode_
= blend_mode
;
1181 NoteLayerPropertyChangedForSubtree();
1184 void LayerImpl::SetIsRootForIsolatedGroup(bool root
) {
1185 if (is_root_for_isolated_group_
== root
)
1188 is_root_for_isolated_group_
= root
;
1189 SetNeedsPushProperties();
1192 void LayerImpl::SetPosition(const gfx::PointF
& position
) {
1193 if (position_
== position
)
1196 position_
= position
;
1197 NoteLayerPropertyChangedForSubtree();
1200 void LayerImpl::SetShouldFlattenTransform(bool flatten
) {
1201 if (should_flatten_transform_
== flatten
)
1204 should_flatten_transform_
= flatten
;
1205 NoteLayerPropertyChangedForSubtree();
1208 void LayerImpl::Set3dSortingContextId(int id
) {
1209 if (id
== sorting_context_id_
)
1211 sorting_context_id_
= id
;
1212 NoteLayerPropertyChangedForSubtree();
1215 void LayerImpl::SetFrameTimingRequests(
1216 const std::vector
<FrameTimingRequest
>& requests
) {
1217 frame_timing_requests_
= requests
;
1218 frame_timing_requests_dirty_
= true;
1219 SetNeedsPushProperties();
1222 void LayerImpl::GatherFrameTimingRequestIds(std::vector
<int64_t>* request_ids
) {
1223 for (const auto& request
: frame_timing_requests_
)
1224 request_ids
->push_back(request
.id());
1227 void LayerImpl::SetTransform(const gfx::Transform
& transform
) {
1228 if (transform_
== transform
)
1231 transform_
= transform
;
1232 transform_is_invertible_
= transform_
.IsInvertible();
1233 NoteLayerPropertyChangedForSubtree();
1236 void LayerImpl::SetTransformAndInvertibility(const gfx::Transform
& transform
,
1237 bool transform_is_invertible
) {
1238 if (transform_
== transform
) {
1239 DCHECK(transform_is_invertible_
== transform_is_invertible
)
1240 << "Can't change invertibility if transform is unchanged";
1243 transform_
= transform
;
1244 transform_is_invertible_
= transform_is_invertible
;
1245 NoteLayerPropertyChangedForSubtree();
1248 bool LayerImpl::TransformIsAnimating() const {
1249 LayerAnimationController::ObserverType observer_type
=
1250 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1251 : LayerAnimationController::ObserverType::PENDING
;
1252 return layer_animation_controller_
1253 ? layer_animation_controller_
->IsCurrentlyAnimatingProperty(
1254 Animation::TRANSFORM
, observer_type
)
1255 : layer_tree_impl_
->IsAnimatingTransformProperty(this);
1258 bool LayerImpl::HasPotentiallyRunningTransformAnimation() const {
1259 LayerAnimationController::ObserverType observer_type
=
1260 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1261 : LayerAnimationController::ObserverType::PENDING
;
1262 return layer_animation_controller_
1263 ? layer_animation_controller_
->IsPotentiallyAnimatingProperty(
1264 Animation::TRANSFORM
, observer_type
)
1265 : layer_tree_impl_
->HasPotentiallyRunningTransformAnimation(this);
1268 bool LayerImpl::TransformIsAnimatingOnImplOnly() const {
1269 if (!layer_animation_controller_
)
1270 return layer_tree_impl_
->TransformIsAnimatingOnImplOnly(this);
1272 Animation
* transform_animation
=
1273 layer_animation_controller_
->GetAnimation(Animation::TRANSFORM
);
1274 return transform_animation
&& transform_animation
->is_impl_only();
1277 bool LayerImpl::HasOnlyTranslationTransforms() const {
1278 if (!layer_animation_controller_
)
1279 return layer_tree_impl_
->HasOnlyTranslationTransforms(this);
1281 return layer_animation_controller_
->HasOnlyTranslationTransforms();
1284 bool LayerImpl::MaximumTargetScale(float* max_scale
) const {
1285 if (!layer_animation_controller_
)
1286 return layer_tree_impl_
->MaximumTargetScale(this, max_scale
);
1288 return layer_animation_controller_
->MaximumTargetScale(max_scale
);
1291 bool LayerImpl::AnimationStartScale(float* start_scale
) const {
1292 if (!layer_animation_controller_
)
1293 return layer_tree_impl_
->AnimationStartScale(this, start_scale
);
1295 return layer_animation_controller_
->AnimationStartScale(start_scale
);
1298 bool LayerImpl::HasAnyAnimationTargetingProperty(
1299 Animation::TargetProperty property
) const {
1300 if (!layer_animation_controller_
)
1301 return layer_tree_impl_
->HasAnyAnimationTargetingProperty(this, property
);
1303 return !!layer_animation_controller_
->GetAnimation(property
);
1306 bool LayerImpl::HasFilterAnimationThatInflatesBounds() const {
1307 if (!layer_animation_controller_
)
1308 return layer_tree_impl_
->HasFilterAnimationThatInflatesBounds(this);
1310 return layer_animation_controller_
->HasFilterAnimationThatInflatesBounds();
1313 bool LayerImpl::HasTransformAnimationThatInflatesBounds() const {
1314 if (!layer_animation_controller_
)
1315 return layer_tree_impl_
->HasTransformAnimationThatInflatesBounds(this);
1317 return layer_animation_controller_
->HasTransformAnimationThatInflatesBounds();
1320 bool LayerImpl::HasAnimationThatInflatesBounds() const {
1321 if (!layer_animation_controller_
)
1322 return layer_tree_impl_
->HasAnimationThatInflatesBounds(this);
1324 return layer_animation_controller_
->HasAnimationThatInflatesBounds();
1327 bool LayerImpl::FilterAnimationBoundsForBox(const gfx::BoxF
& box
,
1328 gfx::BoxF
* bounds
) const {
1329 if (!layer_animation_controller_
)
1330 return layer_tree_impl_
->FilterAnimationBoundsForBox(this, box
, bounds
);
1332 return layer_animation_controller_
->FilterAnimationBoundsForBox(box
, bounds
);
1335 bool LayerImpl::TransformAnimationBoundsForBox(const gfx::BoxF
& box
,
1336 gfx::BoxF
* bounds
) const {
1337 if (!layer_animation_controller_
)
1338 return layer_tree_impl_
->TransformAnimationBoundsForBox(this, box
, bounds
);
1340 return layer_animation_controller_
->TransformAnimationBoundsForBox(box
,
1344 void LayerImpl::SetUpdateRect(const gfx::Rect
& update_rect
) {
1345 update_rect_
= update_rect
;
1346 SetNeedsPushProperties();
1349 void LayerImpl::AddDamageRect(const gfx::RectF
& damage_rect
) {
1350 damage_rect_
= gfx::UnionRects(damage_rect_
, damage_rect
);
1353 bool LayerImpl::IsExternalScrollActive() const {
1354 return layer_tree_impl_
->IsExternalScrollActive();
1357 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset
& scroll_offset
) {
1359 if (scroll_offset_
->SetCurrent(scroll_offset
))
1360 DidUpdateScrollOffset(false);
1363 void LayerImpl::SetCurrentScrollOffsetFromDelegate(
1364 const gfx::ScrollOffset
& scroll_offset
) {
1366 if (scroll_offset_
->SetCurrent(scroll_offset
))
1367 DidUpdateScrollOffset(true);
1370 void LayerImpl::PushScrollOffsetFromMainThread(
1371 const gfx::ScrollOffset
& scroll_offset
) {
1372 PushScrollOffset(&scroll_offset
);
1375 void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1376 const gfx::ScrollOffset
& scroll_offset
) {
1377 scroll_offset_
->set_clobber_active_value();
1378 PushScrollOffset(&scroll_offset
);
1381 gfx::ScrollOffset
LayerImpl::PullDeltaForMainThread() {
1382 // TODO(miletus): Remove all this temporary flooring machinery when
1383 // Blink fully supports fractional scrolls.
1384 gfx::ScrollOffset current_offset
= CurrentScrollOffset();
1385 gfx::ScrollOffset current_delta
= IsActive()
1386 ? scroll_offset_
->Delta()
1387 : scroll_offset_
->PendingDelta().get();
1388 gfx::ScrollOffset
floored_delta(floor(current_delta
.x()),
1389 floor(current_delta
.y()));
1390 gfx::ScrollOffset diff_delta
= floored_delta
- current_delta
;
1391 gfx::ScrollOffset tmp_offset
= current_offset
+ diff_delta
;
1392 scroll_offset_
->SetCurrent(tmp_offset
);
1393 gfx::ScrollOffset delta
= scroll_offset_
->PullDeltaForMainThread();
1394 scroll_offset_
->SetCurrent(current_offset
);
1398 gfx::ScrollOffset
LayerImpl::CurrentScrollOffset() const {
1399 return scroll_offset_
->Current(IsActive());
1402 gfx::Vector2dF
LayerImpl::ScrollDelta() const {
1404 return gfx::Vector2dF(scroll_offset_
->Delta().x(),
1405 scroll_offset_
->Delta().y());
1407 return gfx::Vector2dF(scroll_offset_
->PendingDelta().get().x(),
1408 scroll_offset_
->PendingDelta().get().y());
1411 void LayerImpl::SetScrollDelta(const gfx::Vector2dF
& delta
) {
1413 DCHECK(scrollable() || delta
.IsZero());
1414 SetCurrentScrollOffset(scroll_offset_
->ActiveBase() +
1415 gfx::ScrollOffset(delta
));
1418 gfx::ScrollOffset
LayerImpl::BaseScrollOffset() const {
1420 return scroll_offset_
->ActiveBase();
1422 return scroll_offset_
->PendingBase();
1425 void LayerImpl::PushScrollOffset(const gfx::ScrollOffset
* scroll_offset
) {
1426 DCHECK(scroll_offset
|| IsActive());
1427 bool changed
= false;
1428 if (scroll_offset
) {
1429 DCHECK(!IsActive() || !layer_tree_impl_
->FindPendingTreeLayerById(id()));
1430 changed
|= scroll_offset_
->PushFromMainThread(*scroll_offset
);
1433 changed
|= scroll_offset_
->PushPendingToActive();
1437 DidUpdateScrollOffset(false);
1440 void LayerImpl::UpdatePropertyTreeScrollOffset() {
1441 // TODO(enne): in the future, scrolling should update the scroll tree
1442 // directly instead of going through layers.
1443 if (transform_tree_index_
!= -1) {
1444 TransformTree
& transform_tree
=
1445 layer_tree_impl()->property_trees()->transform_tree
;
1446 TransformNode
* node
= transform_tree
.Node(transform_tree_index_
);
1447 gfx::ScrollOffset current_offset
= scroll_offset_
->Current(IsActive());
1448 if (node
->data
.scroll_offset
!= current_offset
) {
1449 node
->data
.scroll_offset
= current_offset
;
1450 node
->data
.needs_local_transform_update
= true;
1451 transform_tree
.set_needs_update(true);
1456 void LayerImpl::DidUpdateScrollOffset(bool is_from_root_delegate
) {
1457 DCHECK(scroll_offset_
);
1459 if (!is_from_root_delegate
)
1460 layer_tree_impl()->DidUpdateScrollOffset(id());
1461 NoteLayerPropertyChangedForSubtree();
1462 ScrollbarParametersDidChange(false);
1464 UpdatePropertyTreeScrollOffset();
1466 // Inform the pending twin that a property changed.
1467 if (layer_tree_impl()->IsActiveTree()) {
1468 LayerImpl
* pending_twin
= layer_tree_impl()->FindPendingTreeLayerById(id());
1470 pending_twin
->DidUpdateScrollOffset(is_from_root_delegate
);
1474 void LayerImpl::SetDoubleSided(bool double_sided
) {
1475 if (double_sided_
== double_sided
)
1478 double_sided_
= double_sided
;
1479 NoteLayerPropertyChangedForSubtree();
1482 SimpleEnclosedRegion
LayerImpl::VisibleOpaqueRegion() const {
1483 if (contents_opaque())
1484 return SimpleEnclosedRegion(visible_layer_rect());
1485 return SimpleEnclosedRegion();
1488 void LayerImpl::DidBeginTracing() {}
1490 void LayerImpl::ReleaseResources() {}
1492 void LayerImpl::RecreateResources() {
1495 gfx::ScrollOffset
LayerImpl::MaxScrollOffset() const {
1496 if (!scroll_clip_layer_
|| bounds().IsEmpty())
1497 return gfx::ScrollOffset();
1499 LayerImpl
const* page_scale_layer
= layer_tree_impl()->PageScaleLayer();
1500 DCHECK(this != page_scale_layer
);
1501 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1502 IsContainerForFixedPositionLayers());
1504 float scale_factor
= 1.f
;
1505 for (LayerImpl
const* current_layer
= this;
1506 current_layer
!= scroll_clip_layer_
->parent();
1507 current_layer
= current_layer
->parent()) {
1508 if (current_layer
== page_scale_layer
)
1509 scale_factor
= layer_tree_impl()->current_page_scale_factor();
1512 gfx::SizeF scaled_scroll_bounds
=
1513 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor
));
1514 scaled_scroll_bounds
= gfx::ToFlooredSize(scaled_scroll_bounds
);
1516 gfx::ScrollOffset
max_offset(
1517 scaled_scroll_bounds
.width() - scroll_clip_layer_
->bounds().width(),
1518 scaled_scroll_bounds
.height() - scroll_clip_layer_
->bounds().height());
1519 // We need the final scroll offset to be in CSS coords.
1520 max_offset
.Scale(1 / scale_factor
);
1521 max_offset
.SetToMax(gfx::ScrollOffset());
1525 gfx::ScrollOffset
LayerImpl::ClampScrollOffsetToLimits(
1526 gfx::ScrollOffset offset
) const {
1527 offset
.SetToMin(MaxScrollOffset());
1528 offset
.SetToMax(gfx::ScrollOffset());
1532 gfx::Vector2dF
LayerImpl::ClampScrollToMaxScrollOffset() {
1533 gfx::ScrollOffset old_offset
= CurrentScrollOffset();
1534 gfx::ScrollOffset clamped_offset
= ClampScrollOffsetToLimits(old_offset
);
1535 gfx::Vector2dF delta
= clamped_offset
.DeltaFrom(old_offset
);
1536 if (!delta
.IsZero())
1541 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase
* scrollbar_layer
,
1542 LayerImpl
* scrollbar_clip_layer
,
1543 bool on_resize
) const {
1544 DCHECK(scrollbar_layer
);
1545 LayerImpl
* page_scale_layer
= layer_tree_impl()->PageScaleLayer();
1547 DCHECK(this != page_scale_layer
);
1548 DCHECK(scrollbar_clip_layer
);
1549 gfx::RectF
clip_rect(gfx::PointF(),
1550 scrollbar_clip_layer
->BoundsForScrolling());
1552 // See comment in MaxScrollOffset() regarding the use of the content layer
1554 gfx::RectF
scroll_rect(gfx::PointF(), BoundsForScrolling());
1556 if (scroll_rect
.size().IsEmpty())
1559 gfx::ScrollOffset current_offset
;
1560 for (LayerImpl
const* current_layer
= this;
1561 current_layer
!= scrollbar_clip_layer
->parent();
1562 current_layer
= current_layer
->parent()) {
1563 current_offset
+= current_layer
->CurrentScrollOffset();
1564 if (current_layer
== page_scale_layer
) {
1565 float scale_factor
= layer_tree_impl()->current_page_scale_factor();
1566 current_offset
.Scale(scale_factor
);
1567 scroll_rect
.Scale(scale_factor
);
1571 bool scrollbar_needs_animation
= false;
1572 scrollbar_needs_animation
|= scrollbar_layer
->SetVerticalAdjust(
1573 scrollbar_clip_layer
->bounds_delta().y());
1574 if (scrollbar_layer
->orientation() == HORIZONTAL
) {
1575 float visible_ratio
= clip_rect
.width() / scroll_rect
.width();
1576 scrollbar_needs_animation
|=
1577 scrollbar_layer
->SetCurrentPos(current_offset
.x());
1578 scrollbar_needs_animation
|=
1579 scrollbar_layer
->SetMaximum(scroll_rect
.width() - clip_rect
.width());
1580 scrollbar_needs_animation
|=
1581 scrollbar_layer
->SetVisibleToTotalLengthRatio(visible_ratio
);
1583 float visible_ratio
= clip_rect
.height() / scroll_rect
.height();
1584 bool y_offset_did_change
=
1585 scrollbar_layer
->SetCurrentPos(current_offset
.y());
1586 scrollbar_needs_animation
|= y_offset_did_change
;
1587 scrollbar_needs_animation
|=
1588 scrollbar_layer
->SetMaximum(scroll_rect
.height() - clip_rect
.height());
1589 scrollbar_needs_animation
|=
1590 scrollbar_layer
->SetVisibleToTotalLengthRatio(visible_ratio
);
1591 if (y_offset_did_change
&& layer_tree_impl()->IsActiveTree() &&
1592 this == layer_tree_impl()->OuterViewportScrollLayer()) {
1593 TRACE_COUNTER_ID1("cc", "scroll_offset_y", this->id(),
1594 current_offset
.y());
1597 if (scrollbar_needs_animation
) {
1598 layer_tree_impl()->set_needs_update_draw_properties();
1599 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars
1600 // should activate for every scroll on the main frame, not just the
1601 // scrolls that move the pinch virtual viewport (i.e. trigger from
1602 // either inner or outer viewport).
1603 if (scrollbar_animation_controller_
) {
1604 // Non-overlay scrollbars shouldn't trigger animations.
1605 if (scrollbar_layer
->is_overlay_scrollbar())
1606 scrollbar_animation_controller_
->DidScrollUpdate(on_resize
);
1611 void LayerImpl::DidBecomeActive() {
1612 if (layer_tree_impl_
->settings().scrollbar_animator
==
1613 LayerTreeSettings::NO_ANIMATOR
) {
1617 bool need_scrollbar_animation_controller
= scrollable() && scrollbars_
;
1618 if (!need_scrollbar_animation_controller
) {
1619 scrollbar_animation_controller_
= nullptr;
1623 if (scrollbar_animation_controller_
)
1626 scrollbar_animation_controller_
=
1627 layer_tree_impl_
->CreateScrollbarAnimationController(this);
1630 void LayerImpl::ClearScrollbars() {
1634 scrollbars_
.reset(nullptr);
1637 void LayerImpl::AddScrollbar(ScrollbarLayerImplBase
* layer
) {
1639 DCHECK(!scrollbars_
|| scrollbars_
->find(layer
) == scrollbars_
->end());
1641 scrollbars_
.reset(new ScrollbarSet());
1643 scrollbars_
->insert(layer
);
1646 void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase
* layer
) {
1647 DCHECK(scrollbars_
);
1649 DCHECK(scrollbars_
->find(layer
) != scrollbars_
->end());
1651 scrollbars_
->erase(layer
);
1652 if (scrollbars_
->empty())
1653 scrollbars_
= nullptr;
1656 bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation
) const {
1660 for (ScrollbarSet::iterator it
= scrollbars_
->begin();
1661 it
!= scrollbars_
->end();
1663 if ((*it
)->orientation() == orientation
)
1669 void LayerImpl::ScrollbarParametersDidChange(bool on_resize
) {
1673 for (ScrollbarSet::iterator it
= scrollbars_
->begin();
1674 it
!= scrollbars_
->end();
1676 bool is_scroll_layer
= (*it
)->ScrollLayerId() == layer_id_
;
1677 bool scroll_layer_resized
= is_scroll_layer
&& on_resize
;
1678 (*it
)->ScrollbarParametersDidChange(scroll_layer_resized
);
1682 void LayerImpl::SetNeedsPushProperties() {
1683 if (needs_push_properties_
)
1685 if (!parent_should_know_need_push_properties() && parent_
)
1686 parent_
->AddDependentNeedsPushProperties();
1687 needs_push_properties_
= true;
1690 void LayerImpl::AddDependentNeedsPushProperties() {
1691 DCHECK_GE(num_dependents_need_push_properties_
, 0);
1693 if (!parent_should_know_need_push_properties() && parent_
)
1694 parent_
->AddDependentNeedsPushProperties();
1696 num_dependents_need_push_properties_
++;
1699 void LayerImpl::RemoveDependentNeedsPushProperties() {
1700 num_dependents_need_push_properties_
--;
1701 DCHECK_GE(num_dependents_need_push_properties_
, 0);
1703 if (!parent_should_know_need_push_properties() && parent_
)
1704 parent_
->RemoveDependentNeedsPushProperties();
1707 void LayerImpl::GetAllPrioritizedTilesForTracing(
1708 std::vector
<PrioritizedTile
>* prioritized_tiles
) const {
1711 void LayerImpl::AsValueInto(base::trace_event::TracedValue
* state
) const {
1712 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
1713 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1716 LayerTypeAsString(),
1718 state
->SetInteger("layer_id", id());
1719 MathUtil::AddToTracedValue("bounds", bounds_
, state
);
1721 state
->SetDouble("opacity", opacity());
1723 MathUtil::AddToTracedValue("position", position_
, state
);
1725 state
->SetInteger("draws_content", DrawsContent());
1726 state
->SetInteger("gpu_memory_usage",
1727 base::saturated_cast
<int>(GPUMemoryUsageInBytes()));
1729 MathUtil::AddToTracedValue(
1730 "scroll_offset", scroll_offset_
? scroll_offset_
->Current(IsActive())
1731 : gfx::ScrollOffset(),
1734 MathUtil::AddToTracedValue("transform_origin", transform_origin_
, state
);
1737 gfx::QuadF layer_quad
= MathUtil::MapQuad(
1738 screen_space_transform(), gfx::QuadF(gfx::Rect(bounds())), &clipped
);
1739 MathUtil::AddToTracedValue("layer_quad", layer_quad
, state
);
1740 if (!touch_event_handler_region_
.IsEmpty()) {
1741 state
->BeginArray("touch_event_handler_region");
1742 touch_event_handler_region_
.AsValueInto(state
);
1745 if (have_wheel_event_handlers_
) {
1746 gfx::Rect
wheel_rect(bounds());
1747 Region
wheel_region(wheel_rect
);
1748 state
->BeginArray("wheel_event_handler_region");
1749 wheel_region
.AsValueInto(state
);
1752 if (have_scroll_event_handlers_
) {
1753 gfx::Rect
scroll_rect(bounds());
1754 Region
scroll_region(scroll_rect
);
1755 state
->BeginArray("scroll_event_handler_region");
1756 scroll_region
.AsValueInto(state
);
1759 if (!non_fast_scrollable_region_
.IsEmpty()) {
1760 state
->BeginArray("non_fast_scrollable_region");
1761 non_fast_scrollable_region_
.AsValueInto(state
);
1764 if (scroll_blocks_on_
) {
1765 state
->SetInteger("scroll_blocks_on", scroll_blocks_on_
);
1768 state
->BeginArray("children");
1769 for (size_t i
= 0; i
< children_
.size(); ++i
) {
1770 state
->BeginDictionary();
1771 children_
[i
]->AsValueInto(state
);
1772 state
->EndDictionary();
1776 state
->BeginDictionary("mask_layer");
1777 mask_layer_
->AsValueInto(state
);
1778 state
->EndDictionary();
1780 if (replica_layer_
) {
1781 state
->BeginDictionary("replica_layer");
1782 replica_layer_
->AsValueInto(state
);
1783 state
->EndDictionary();
1787 state
->SetInteger("scroll_parent", scroll_parent_
->id());
1790 state
->SetInteger("clip_parent", clip_parent_
->id());
1792 state
->SetBoolean("can_use_lcd_text", can_use_lcd_text());
1793 state
->SetBoolean("contents_opaque", contents_opaque());
1796 "has_animation_bounds",
1797 layer_animation_controller_
1798 ? layer_animation_controller_
->HasAnimationThatInflatesBounds()
1799 : layer_tree_impl_
->HasAnimationThatInflatesBounds(this));
1802 if (LayerUtils::GetAnimationBounds(*this, &box
))
1803 MathUtil::AddToTracedValue("animation_bounds", box
, state
);
1805 if (debug_info_
.get()) {
1807 debug_info_
->AppendAsTraceFormat(&str
);
1808 base::JSONReader json_reader
;
1809 scoped_ptr
<base::Value
> debug_info_value(json_reader
.ReadToValue(str
));
1811 if (debug_info_value
->IsType(base::Value::TYPE_DICTIONARY
)) {
1812 base::DictionaryValue
* dictionary_value
= nullptr;
1813 bool converted_to_dictionary
=
1814 debug_info_value
->GetAsDictionary(&dictionary_value
);
1815 DCHECK(converted_to_dictionary
);
1816 for (base::DictionaryValue::Iterator
it(*dictionary_value
); !it
.IsAtEnd();
1818 state
->SetValue(it
.key().data(), it
.value().CreateDeepCopy());
1825 if (!frame_timing_requests_
.empty()) {
1826 state
->BeginArray("frame_timing_requests");
1827 for (const auto& request
: frame_timing_requests_
) {
1828 state
->BeginDictionary();
1829 state
->SetInteger("request_id", request
.id());
1830 MathUtil::AddToTracedValue("request_rect", request
.rect(), state
);
1831 state
->EndDictionary();
1837 bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const {
1838 return draw_properties_
.last_drawn_render_surface_layer_list_id
==
1839 layer_tree_impl_
->current_render_surface_list_id();
1842 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1844 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) {
1845 benchmark
->RunOnLayer(this);
1848 int LayerImpl::NumDescendantsThatDrawContent() const {
1849 return num_descendants_that_draw_content_
;
1852 void LayerImpl::NotifyAnimationFinished(
1853 base::TimeTicks monotonic_time
,
1854 Animation::TargetProperty target_property
,
1856 if (target_property
== Animation::SCROLL_OFFSET
)
1857 layer_tree_impl_
->InputScrollAnimationFinished();
1860 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface
) {
1861 if (!!render_surface() == should_have_render_surface
)
1864 SetNeedsPushProperties();
1865 layer_tree_impl()->set_needs_update_draw_properties();
1866 if (should_have_render_surface
) {
1867 render_surface_
= make_scoped_ptr(new RenderSurfaceImpl(this));
1870 render_surface_
.reset();
1873 Region
LayerImpl::GetInvalidationRegion() {
1874 return Region(update_rect_
);
1877 gfx::Rect
LayerImpl::GetEnclosingRectInTargetSpace() const {
1878 return MathUtil::MapEnclosingClippedRect(
1879 draw_properties_
.target_space_transform
, gfx::Rect(bounds()));
1882 gfx::Rect
LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale
) const {
1883 gfx::Transform scaled_draw_transform
=
1884 draw_properties_
.target_space_transform
;
1885 scaled_draw_transform
.Scale(SK_MScalar1
/ scale
, SK_MScalar1
/ scale
);
1886 gfx::Size scaled_bounds
= gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale
));
1887 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform
,
1888 gfx::Rect(scaled_bounds
));
1891 float LayerImpl::GetIdealContentsScale() const {
1892 float page_scale
= IsAffectedByPageScale()
1893 ? layer_tree_impl()->current_page_scale_factor()
1895 float device_scale
= layer_tree_impl()->device_scale_factor();
1897 float default_scale
= page_scale
* device_scale
;
1898 if (!layer_tree_impl()
1900 .layer_transforms_should_scale_layer_contents
) {
1901 return default_scale
;
1904 // TODO(enne): the transform needs to come from property trees instead of
1906 gfx::Vector2dF transform_scales
= MathUtil::ComputeTransform2dScaleComponents(
1907 draw_properties().target_space_transform
, default_scale
);
1908 return std::max(transform_scales
.x(), transform_scales
.y());