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 LayerAnimationController::ObserverType observer_type
=
1282 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1283 : LayerAnimationController::ObserverType::PENDING
;
1284 return layer_animation_controller_
->HasOnlyTranslationTransforms(
1288 bool LayerImpl::MaximumTargetScale(float* max_scale
) const {
1289 if (!layer_animation_controller_
)
1290 return layer_tree_impl_
->MaximumTargetScale(this, max_scale
);
1292 LayerAnimationController::ObserverType observer_type
=
1293 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1294 : LayerAnimationController::ObserverType::PENDING
;
1295 return layer_animation_controller_
->MaximumTargetScale(observer_type
,
1299 bool LayerImpl::AnimationStartScale(float* start_scale
) const {
1300 if (!layer_animation_controller_
)
1301 return layer_tree_impl_
->AnimationStartScale(this, start_scale
);
1303 LayerAnimationController::ObserverType observer_type
=
1304 IsActive() ? LayerAnimationController::ObserverType::ACTIVE
1305 : LayerAnimationController::ObserverType::PENDING
;
1306 return layer_animation_controller_
->AnimationStartScale(observer_type
,
1310 bool LayerImpl::HasAnyAnimationTargetingProperty(
1311 Animation::TargetProperty property
) const {
1312 if (!layer_animation_controller_
)
1313 return layer_tree_impl_
->HasAnyAnimationTargetingProperty(this, property
);
1315 return !!layer_animation_controller_
->GetAnimation(property
);
1318 bool LayerImpl::HasFilterAnimationThatInflatesBounds() const {
1319 if (!layer_animation_controller_
)
1320 return layer_tree_impl_
->HasFilterAnimationThatInflatesBounds(this);
1322 return layer_animation_controller_
->HasFilterAnimationThatInflatesBounds();
1325 bool LayerImpl::HasTransformAnimationThatInflatesBounds() const {
1326 if (!layer_animation_controller_
)
1327 return layer_tree_impl_
->HasTransformAnimationThatInflatesBounds(this);
1329 return layer_animation_controller_
->HasTransformAnimationThatInflatesBounds();
1332 bool LayerImpl::HasAnimationThatInflatesBounds() const {
1333 if (!layer_animation_controller_
)
1334 return layer_tree_impl_
->HasAnimationThatInflatesBounds(this);
1336 return layer_animation_controller_
->HasAnimationThatInflatesBounds();
1339 bool LayerImpl::FilterAnimationBoundsForBox(const gfx::BoxF
& box
,
1340 gfx::BoxF
* bounds
) const {
1341 if (!layer_animation_controller_
)
1342 return layer_tree_impl_
->FilterAnimationBoundsForBox(this, box
, bounds
);
1344 return layer_animation_controller_
->FilterAnimationBoundsForBox(box
, bounds
);
1347 bool LayerImpl::TransformAnimationBoundsForBox(const gfx::BoxF
& box
,
1348 gfx::BoxF
* bounds
) const {
1349 if (!layer_animation_controller_
)
1350 return layer_tree_impl_
->TransformAnimationBoundsForBox(this, box
, bounds
);
1352 return layer_animation_controller_
->TransformAnimationBoundsForBox(box
,
1356 void LayerImpl::SetUpdateRect(const gfx::Rect
& update_rect
) {
1357 update_rect_
= update_rect
;
1358 SetNeedsPushProperties();
1361 void LayerImpl::AddDamageRect(const gfx::RectF
& damage_rect
) {
1362 damage_rect_
= gfx::UnionRects(damage_rect_
, damage_rect
);
1365 bool LayerImpl::IsExternalScrollActive() const {
1366 return layer_tree_impl_
->IsExternalScrollActive();
1369 void LayerImpl::SetCurrentScrollOffset(const gfx::ScrollOffset
& scroll_offset
) {
1371 if (scroll_offset_
->SetCurrent(scroll_offset
))
1372 DidUpdateScrollOffset(false);
1375 void LayerImpl::SetCurrentScrollOffsetFromDelegate(
1376 const gfx::ScrollOffset
& scroll_offset
) {
1378 if (scroll_offset_
->SetCurrent(scroll_offset
))
1379 DidUpdateScrollOffset(true);
1382 void LayerImpl::PushScrollOffsetFromMainThread(
1383 const gfx::ScrollOffset
& scroll_offset
) {
1384 PushScrollOffset(&scroll_offset
);
1387 void LayerImpl::PushScrollOffsetFromMainThreadAndClobberActiveValue(
1388 const gfx::ScrollOffset
& scroll_offset
) {
1389 scroll_offset_
->set_clobber_active_value();
1390 PushScrollOffset(&scroll_offset
);
1393 gfx::ScrollOffset
LayerImpl::PullDeltaForMainThread() {
1394 // TODO(miletus): Remove all this temporary flooring machinery when
1395 // Blink fully supports fractional scrolls.
1396 gfx::ScrollOffset current_offset
= CurrentScrollOffset();
1397 gfx::ScrollOffset current_delta
= IsActive()
1398 ? scroll_offset_
->Delta()
1399 : scroll_offset_
->PendingDelta().get();
1400 gfx::ScrollOffset
floored_delta(floor(current_delta
.x()),
1401 floor(current_delta
.y()));
1402 gfx::ScrollOffset diff_delta
= floored_delta
- current_delta
;
1403 gfx::ScrollOffset tmp_offset
= current_offset
+ diff_delta
;
1404 scroll_offset_
->SetCurrent(tmp_offset
);
1405 gfx::ScrollOffset delta
= scroll_offset_
->PullDeltaForMainThread();
1406 scroll_offset_
->SetCurrent(current_offset
);
1410 gfx::ScrollOffset
LayerImpl::CurrentScrollOffset() const {
1411 return scroll_offset_
->Current(IsActive());
1414 gfx::Vector2dF
LayerImpl::ScrollDelta() const {
1416 return gfx::Vector2dF(scroll_offset_
->Delta().x(),
1417 scroll_offset_
->Delta().y());
1419 return gfx::Vector2dF(scroll_offset_
->PendingDelta().get().x(),
1420 scroll_offset_
->PendingDelta().get().y());
1423 void LayerImpl::SetScrollDelta(const gfx::Vector2dF
& delta
) {
1425 DCHECK(scrollable() || delta
.IsZero());
1426 SetCurrentScrollOffset(scroll_offset_
->ActiveBase() +
1427 gfx::ScrollOffset(delta
));
1430 gfx::ScrollOffset
LayerImpl::BaseScrollOffset() const {
1432 return scroll_offset_
->ActiveBase();
1434 return scroll_offset_
->PendingBase();
1437 void LayerImpl::PushScrollOffset(const gfx::ScrollOffset
* scroll_offset
) {
1438 DCHECK(scroll_offset
|| IsActive());
1439 bool changed
= false;
1440 if (scroll_offset
) {
1441 DCHECK(!IsActive() || !layer_tree_impl_
->FindPendingTreeLayerById(id()));
1442 changed
|= scroll_offset_
->PushFromMainThread(*scroll_offset
);
1445 changed
|= scroll_offset_
->PushPendingToActive();
1449 DidUpdateScrollOffset(false);
1452 void LayerImpl::UpdatePropertyTreeScrollOffset() {
1453 // TODO(enne): in the future, scrolling should update the scroll tree
1454 // directly instead of going through layers.
1455 if (transform_tree_index_
!= -1) {
1456 TransformTree
& transform_tree
=
1457 layer_tree_impl()->property_trees()->transform_tree
;
1458 TransformNode
* node
= transform_tree
.Node(transform_tree_index_
);
1459 gfx::ScrollOffset current_offset
= scroll_offset_
->Current(IsActive());
1460 if (node
->data
.scroll_offset
!= current_offset
) {
1461 node
->data
.scroll_offset
= current_offset
;
1462 node
->data
.needs_local_transform_update
= true;
1463 transform_tree
.set_needs_update(true);
1468 void LayerImpl::DidUpdateScrollOffset(bool is_from_root_delegate
) {
1469 DCHECK(scroll_offset_
);
1471 if (!is_from_root_delegate
)
1472 layer_tree_impl()->DidUpdateScrollOffset(id());
1473 NoteLayerPropertyChangedForSubtree();
1474 ScrollbarParametersDidChange(false);
1476 UpdatePropertyTreeScrollOffset();
1478 // Inform the pending twin that a property changed.
1479 if (layer_tree_impl()->IsActiveTree()) {
1480 LayerImpl
* pending_twin
= layer_tree_impl()->FindPendingTreeLayerById(id());
1482 pending_twin
->DidUpdateScrollOffset(is_from_root_delegate
);
1486 void LayerImpl::SetDoubleSided(bool double_sided
) {
1487 if (double_sided_
== double_sided
)
1490 double_sided_
= double_sided
;
1491 NoteLayerPropertyChangedForSubtree();
1494 SimpleEnclosedRegion
LayerImpl::VisibleOpaqueRegion() const {
1495 if (contents_opaque())
1496 return SimpleEnclosedRegion(visible_layer_rect());
1497 return SimpleEnclosedRegion();
1500 void LayerImpl::DidBeginTracing() {}
1502 void LayerImpl::ReleaseResources() {}
1504 void LayerImpl::RecreateResources() {
1507 gfx::ScrollOffset
LayerImpl::MaxScrollOffset() const {
1508 if (!scroll_clip_layer_
|| bounds().IsEmpty())
1509 return gfx::ScrollOffset();
1511 LayerImpl
const* page_scale_layer
= layer_tree_impl()->PageScaleLayer();
1512 DCHECK(this != page_scale_layer
);
1513 DCHECK(this != layer_tree_impl()->InnerViewportScrollLayer() ||
1514 IsContainerForFixedPositionLayers());
1516 float scale_factor
= 1.f
;
1517 for (LayerImpl
const* current_layer
= this;
1518 current_layer
!= scroll_clip_layer_
->parent();
1519 current_layer
= current_layer
->parent()) {
1520 if (current_layer
== page_scale_layer
)
1521 scale_factor
= layer_tree_impl()->current_page_scale_factor();
1524 gfx::SizeF scaled_scroll_bounds
=
1525 gfx::ToFlooredSize(gfx::ScaleSize(BoundsForScrolling(), scale_factor
));
1526 scaled_scroll_bounds
= gfx::ToFlooredSize(scaled_scroll_bounds
);
1528 gfx::ScrollOffset
max_offset(
1529 scaled_scroll_bounds
.width() - scroll_clip_layer_
->bounds().width(),
1530 scaled_scroll_bounds
.height() - scroll_clip_layer_
->bounds().height());
1531 // We need the final scroll offset to be in CSS coords.
1532 max_offset
.Scale(1 / scale_factor
);
1533 max_offset
.SetToMax(gfx::ScrollOffset());
1537 gfx::ScrollOffset
LayerImpl::ClampScrollOffsetToLimits(
1538 gfx::ScrollOffset offset
) const {
1539 offset
.SetToMin(MaxScrollOffset());
1540 offset
.SetToMax(gfx::ScrollOffset());
1544 gfx::Vector2dF
LayerImpl::ClampScrollToMaxScrollOffset() {
1545 gfx::ScrollOffset old_offset
= CurrentScrollOffset();
1546 gfx::ScrollOffset clamped_offset
= ClampScrollOffsetToLimits(old_offset
);
1547 gfx::Vector2dF delta
= clamped_offset
.DeltaFrom(old_offset
);
1548 if (!delta
.IsZero())
1553 void LayerImpl::SetScrollbarPosition(ScrollbarLayerImplBase
* scrollbar_layer
,
1554 LayerImpl
* scrollbar_clip_layer
,
1555 bool on_resize
) const {
1556 DCHECK(scrollbar_layer
);
1557 LayerImpl
* page_scale_layer
= layer_tree_impl()->PageScaleLayer();
1559 DCHECK(this != page_scale_layer
);
1560 DCHECK(scrollbar_clip_layer
);
1561 gfx::RectF
clip_rect(gfx::PointF(),
1562 scrollbar_clip_layer
->BoundsForScrolling());
1564 // See comment in MaxScrollOffset() regarding the use of the content layer
1566 gfx::RectF
scroll_rect(gfx::PointF(), BoundsForScrolling());
1568 if (scroll_rect
.size().IsEmpty())
1571 gfx::ScrollOffset current_offset
;
1572 for (LayerImpl
const* current_layer
= this;
1573 current_layer
!= scrollbar_clip_layer
->parent();
1574 current_layer
= current_layer
->parent()) {
1575 current_offset
+= current_layer
->CurrentScrollOffset();
1576 if (current_layer
== page_scale_layer
) {
1577 float scale_factor
= layer_tree_impl()->current_page_scale_factor();
1578 current_offset
.Scale(scale_factor
);
1579 scroll_rect
.Scale(scale_factor
);
1583 bool scrollbar_needs_animation
= false;
1584 scrollbar_needs_animation
|= scrollbar_layer
->SetVerticalAdjust(
1585 scrollbar_clip_layer
->bounds_delta().y());
1586 if (scrollbar_layer
->orientation() == HORIZONTAL
) {
1587 float visible_ratio
= clip_rect
.width() / scroll_rect
.width();
1588 scrollbar_needs_animation
|=
1589 scrollbar_layer
->SetCurrentPos(current_offset
.x());
1590 scrollbar_needs_animation
|=
1591 scrollbar_layer
->SetMaximum(scroll_rect
.width() - clip_rect
.width());
1592 scrollbar_needs_animation
|=
1593 scrollbar_layer
->SetVisibleToTotalLengthRatio(visible_ratio
);
1595 float visible_ratio
= clip_rect
.height() / scroll_rect
.height();
1596 bool y_offset_did_change
=
1597 scrollbar_layer
->SetCurrentPos(current_offset
.y());
1598 scrollbar_needs_animation
|= y_offset_did_change
;
1599 scrollbar_needs_animation
|=
1600 scrollbar_layer
->SetMaximum(scroll_rect
.height() - clip_rect
.height());
1601 scrollbar_needs_animation
|=
1602 scrollbar_layer
->SetVisibleToTotalLengthRatio(visible_ratio
);
1603 if (y_offset_did_change
&& layer_tree_impl()->IsActiveTree() &&
1604 this == layer_tree_impl()->OuterViewportScrollLayer()) {
1605 TRACE_COUNTER_ID1("cc", "scroll_offset_y", this->id(),
1606 current_offset
.y());
1609 if (scrollbar_needs_animation
) {
1610 layer_tree_impl()->set_needs_update_draw_properties();
1611 // TODO(wjmaclean) The scrollbar animator for the pinch-zoom scrollbars
1612 // should activate for every scroll on the main frame, not just the
1613 // scrolls that move the pinch virtual viewport (i.e. trigger from
1614 // either inner or outer viewport).
1615 if (scrollbar_animation_controller_
) {
1616 // Non-overlay scrollbars shouldn't trigger animations.
1617 if (scrollbar_layer
->is_overlay_scrollbar())
1618 scrollbar_animation_controller_
->DidScrollUpdate(on_resize
);
1623 void LayerImpl::DidBecomeActive() {
1624 if (layer_tree_impl_
->settings().scrollbar_animator
==
1625 LayerTreeSettings::NO_ANIMATOR
) {
1629 bool need_scrollbar_animation_controller
= scrollable() && scrollbars_
;
1630 if (!need_scrollbar_animation_controller
) {
1631 scrollbar_animation_controller_
= nullptr;
1635 if (scrollbar_animation_controller_
)
1638 scrollbar_animation_controller_
=
1639 layer_tree_impl_
->CreateScrollbarAnimationController(this);
1642 void LayerImpl::ClearScrollbars() {
1646 scrollbars_
.reset(nullptr);
1649 void LayerImpl::AddScrollbar(ScrollbarLayerImplBase
* layer
) {
1651 DCHECK(!scrollbars_
|| scrollbars_
->find(layer
) == scrollbars_
->end());
1653 scrollbars_
.reset(new ScrollbarSet());
1655 scrollbars_
->insert(layer
);
1658 void LayerImpl::RemoveScrollbar(ScrollbarLayerImplBase
* layer
) {
1659 DCHECK(scrollbars_
);
1661 DCHECK(scrollbars_
->find(layer
) != scrollbars_
->end());
1663 scrollbars_
->erase(layer
);
1664 if (scrollbars_
->empty())
1665 scrollbars_
= nullptr;
1668 bool LayerImpl::HasScrollbar(ScrollbarOrientation orientation
) const {
1672 for (ScrollbarSet::iterator it
= scrollbars_
->begin();
1673 it
!= scrollbars_
->end();
1675 if ((*it
)->orientation() == orientation
)
1681 void LayerImpl::ScrollbarParametersDidChange(bool on_resize
) {
1685 for (ScrollbarSet::iterator it
= scrollbars_
->begin();
1686 it
!= scrollbars_
->end();
1688 bool is_scroll_layer
= (*it
)->ScrollLayerId() == layer_id_
;
1689 bool scroll_layer_resized
= is_scroll_layer
&& on_resize
;
1690 (*it
)->ScrollbarParametersDidChange(scroll_layer_resized
);
1694 void LayerImpl::SetNeedsPushProperties() {
1695 if (needs_push_properties_
)
1697 if (!parent_should_know_need_push_properties() && parent_
)
1698 parent_
->AddDependentNeedsPushProperties();
1699 needs_push_properties_
= true;
1702 void LayerImpl::AddDependentNeedsPushProperties() {
1703 DCHECK_GE(num_dependents_need_push_properties_
, 0);
1705 if (!parent_should_know_need_push_properties() && parent_
)
1706 parent_
->AddDependentNeedsPushProperties();
1708 num_dependents_need_push_properties_
++;
1711 void LayerImpl::RemoveDependentNeedsPushProperties() {
1712 num_dependents_need_push_properties_
--;
1713 DCHECK_GE(num_dependents_need_push_properties_
, 0);
1715 if (!parent_should_know_need_push_properties() && parent_
)
1716 parent_
->RemoveDependentNeedsPushProperties();
1719 void LayerImpl::GetAllPrioritizedTilesForTracing(
1720 std::vector
<PrioritizedTile
>* prioritized_tiles
) const {
1723 void LayerImpl::AsValueInto(base::trace_event::TracedValue
* state
) const {
1724 TracedValue::MakeDictIntoImplicitSnapshotWithCategory(
1725 TRACE_DISABLED_BY_DEFAULT("cc.debug"),
1728 LayerTypeAsString(),
1730 state
->SetInteger("layer_id", id());
1731 MathUtil::AddToTracedValue("bounds", bounds_
, state
);
1733 state
->SetDouble("opacity", opacity());
1735 MathUtil::AddToTracedValue("position", position_
, state
);
1737 state
->SetInteger("draws_content", DrawsContent());
1738 state
->SetInteger("gpu_memory_usage",
1739 base::saturated_cast
<int>(GPUMemoryUsageInBytes()));
1741 MathUtil::AddToTracedValue(
1742 "scroll_offset", scroll_offset_
? scroll_offset_
->Current(IsActive())
1743 : gfx::ScrollOffset(),
1746 MathUtil::AddToTracedValue("transform_origin", transform_origin_
, state
);
1749 gfx::QuadF layer_quad
= MathUtil::MapQuad(
1750 screen_space_transform(), gfx::QuadF(gfx::Rect(bounds())), &clipped
);
1751 MathUtil::AddToTracedValue("layer_quad", layer_quad
, state
);
1752 if (!touch_event_handler_region_
.IsEmpty()) {
1753 state
->BeginArray("touch_event_handler_region");
1754 touch_event_handler_region_
.AsValueInto(state
);
1757 if (have_wheel_event_handlers_
) {
1758 gfx::Rect
wheel_rect(bounds());
1759 Region
wheel_region(wheel_rect
);
1760 state
->BeginArray("wheel_event_handler_region");
1761 wheel_region
.AsValueInto(state
);
1764 if (have_scroll_event_handlers_
) {
1765 gfx::Rect
scroll_rect(bounds());
1766 Region
scroll_region(scroll_rect
);
1767 state
->BeginArray("scroll_event_handler_region");
1768 scroll_region
.AsValueInto(state
);
1771 if (!non_fast_scrollable_region_
.IsEmpty()) {
1772 state
->BeginArray("non_fast_scrollable_region");
1773 non_fast_scrollable_region_
.AsValueInto(state
);
1776 if (scroll_blocks_on_
) {
1777 state
->SetInteger("scroll_blocks_on", scroll_blocks_on_
);
1780 state
->BeginArray("children");
1781 for (size_t i
= 0; i
< children_
.size(); ++i
) {
1782 state
->BeginDictionary();
1783 children_
[i
]->AsValueInto(state
);
1784 state
->EndDictionary();
1788 state
->BeginDictionary("mask_layer");
1789 mask_layer_
->AsValueInto(state
);
1790 state
->EndDictionary();
1792 if (replica_layer_
) {
1793 state
->BeginDictionary("replica_layer");
1794 replica_layer_
->AsValueInto(state
);
1795 state
->EndDictionary();
1799 state
->SetInteger("scroll_parent", scroll_parent_
->id());
1802 state
->SetInteger("clip_parent", clip_parent_
->id());
1804 state
->SetBoolean("can_use_lcd_text", can_use_lcd_text());
1805 state
->SetBoolean("contents_opaque", contents_opaque());
1808 "has_animation_bounds",
1809 layer_animation_controller_
1810 ? layer_animation_controller_
->HasAnimationThatInflatesBounds()
1811 : layer_tree_impl_
->HasAnimationThatInflatesBounds(this));
1814 if (LayerUtils::GetAnimationBounds(*this, &box
))
1815 MathUtil::AddToTracedValue("animation_bounds", box
, state
);
1817 if (debug_info_
.get()) {
1819 debug_info_
->AppendAsTraceFormat(&str
);
1820 base::JSONReader json_reader
;
1821 scoped_ptr
<base::Value
> debug_info_value(json_reader
.ReadToValue(str
));
1823 if (debug_info_value
->IsType(base::Value::TYPE_DICTIONARY
)) {
1824 base::DictionaryValue
* dictionary_value
= nullptr;
1825 bool converted_to_dictionary
=
1826 debug_info_value
->GetAsDictionary(&dictionary_value
);
1827 DCHECK(converted_to_dictionary
);
1828 for (base::DictionaryValue::Iterator
it(*dictionary_value
); !it
.IsAtEnd();
1830 state
->SetValue(it
.key().data(), it
.value().CreateDeepCopy());
1837 if (!frame_timing_requests_
.empty()) {
1838 state
->BeginArray("frame_timing_requests");
1839 for (const auto& request
: frame_timing_requests_
) {
1840 state
->BeginDictionary();
1841 state
->SetInteger("request_id", request
.id());
1842 MathUtil::AddToTracedValue("request_rect", request
.rect(), state
);
1843 state
->EndDictionary();
1849 bool LayerImpl::IsDrawnRenderSurfaceLayerListMember() const {
1850 return draw_properties_
.last_drawn_render_surface_layer_list_id
==
1851 layer_tree_impl_
->current_render_surface_list_id();
1854 size_t LayerImpl::GPUMemoryUsageInBytes() const { return 0; }
1856 void LayerImpl::RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
) {
1857 benchmark
->RunOnLayer(this);
1860 int LayerImpl::NumDescendantsThatDrawContent() const {
1861 return num_descendants_that_draw_content_
;
1864 void LayerImpl::NotifyAnimationFinished(
1865 base::TimeTicks monotonic_time
,
1866 Animation::TargetProperty target_property
,
1868 if (target_property
== Animation::SCROLL_OFFSET
)
1869 layer_tree_impl_
->InputScrollAnimationFinished();
1872 void LayerImpl::SetHasRenderSurface(bool should_have_render_surface
) {
1873 if (!!render_surface() == should_have_render_surface
)
1876 SetNeedsPushProperties();
1877 layer_tree_impl()->set_needs_update_draw_properties();
1878 if (should_have_render_surface
) {
1879 render_surface_
= make_scoped_ptr(new RenderSurfaceImpl(this));
1882 render_surface_
.reset();
1885 Region
LayerImpl::GetInvalidationRegion() {
1886 return Region(update_rect_
);
1889 gfx::Rect
LayerImpl::GetEnclosingRectInTargetSpace() const {
1890 return MathUtil::MapEnclosingClippedRect(
1891 draw_properties_
.target_space_transform
, gfx::Rect(bounds()));
1894 gfx::Rect
LayerImpl::GetScaledEnclosingRectInTargetSpace(float scale
) const {
1895 gfx::Transform scaled_draw_transform
=
1896 draw_properties_
.target_space_transform
;
1897 scaled_draw_transform
.Scale(SK_MScalar1
/ scale
, SK_MScalar1
/ scale
);
1898 gfx::Size scaled_bounds
= gfx::ToCeiledSize(gfx::ScaleSize(bounds(), scale
));
1899 return MathUtil::MapEnclosingClippedRect(scaled_draw_transform
,
1900 gfx::Rect(scaled_bounds
));
1903 float LayerImpl::GetIdealContentsScale() const {
1904 float page_scale
= IsAffectedByPageScale()
1905 ? layer_tree_impl()->current_page_scale_factor()
1907 float device_scale
= layer_tree_impl()->device_scale_factor();
1909 float default_scale
= page_scale
* device_scale
;
1910 if (!layer_tree_impl()
1912 .layer_transforms_should_scale_layer_contents
) {
1913 return default_scale
;
1916 // TODO(enne): the transform needs to come from property trees instead of
1918 gfx::Vector2dF transform_scales
= MathUtil::ComputeTransform2dScaleComponents(
1919 draw_properties().target_space_transform
, default_scale
);
1920 return std::max(transform_scales
.x(), transform_scales
.y());