1 // Copyright 2011 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 #ifndef CC_LAYERS_LAYER_IMPL_H_
6 #define CC_LAYERS_LAYER_IMPL_H_
13 #include "base/logging.h"
14 #include "base/memory/scoped_ptr.h"
15 #include "base/values.h"
16 #include "cc/animation/animation_delegate.h"
17 #include "cc/animation/layer_animation_controller.h"
18 #include "cc/animation/layer_animation_value_observer.h"
19 #include "cc/animation/layer_animation_value_provider.h"
20 #include "cc/base/cc_export.h"
21 #include "cc/base/region.h"
22 #include "cc/base/scoped_ptr_vector.h"
23 #include "cc/base/synced_property.h"
24 #include "cc/debug/frame_timing_request.h"
25 #include "cc/input/input_handler.h"
26 #include "cc/input/scrollbar.h"
27 #include "cc/layers/draw_properties.h"
28 #include "cc/layers/layer_lists.h"
29 #include "cc/layers/layer_position_constraint.h"
30 #include "cc/layers/render_surface_impl.h"
31 #include "cc/layers/scroll_blocks_on.h"
32 #include "cc/output/filter_operations.h"
33 #include "cc/quads/shared_quad_state.h"
34 #include "cc/resources/resource_provider.h"
35 #include "cc/tiles/tile_priority.h"
36 #include "skia/ext/refptr.h"
37 #include "third_party/skia/include/core/SkColor.h"
38 #include "third_party/skia/include/core/SkImageFilter.h"
39 #include "third_party/skia/include/core/SkPicture.h"
40 #include "ui/gfx/geometry/point3_f.h"
41 #include "ui/gfx/geometry/rect.h"
42 #include "ui/gfx/geometry/rect_f.h"
43 #include "ui/gfx/geometry/scroll_offset.h"
44 #include "ui/gfx/transform.h"
47 namespace trace_event
{
48 class ConvertableToTraceFormat
;
51 class DictionaryValue
;
56 class LayerTreeHostImpl
;
58 class MicroBenchmarkImpl
;
61 class PrioritizedTile
;
65 class ScrollbarAnimationController
;
66 class ScrollbarLayerImplBase
;
67 class SimpleEnclosedRegion
;
72 struct AppendQuadsData
;
78 DRAW_MODE_RESOURCELESS_SOFTWARE
81 class CC_EXPORT LayerImpl
: public LayerAnimationValueObserver
,
82 public LayerAnimationValueProvider
,
83 public AnimationDelegate
{
85 typedef SyncedProperty
<AdditionGroup
<gfx::ScrollOffset
>> SyncedScrollOffset
;
86 typedef LayerImplList RenderSurfaceListType
;
87 typedef LayerImplList LayerListType
;
88 typedef RenderSurfaceImpl RenderSurfaceType
;
90 enum RenderingContextConstants
{ NO_RENDERING_CONTEXT
= 0 };
92 static scoped_ptr
<LayerImpl
> Create(
93 LayerTreeImpl
* tree_impl
,
95 scoped_refptr
<SyncedScrollOffset
> scroll_offset
) {
96 return make_scoped_ptr(new LayerImpl(tree_impl
, id
, scroll_offset
));
99 static scoped_ptr
<LayerImpl
> Create(LayerTreeImpl
* tree_impl
, int id
) {
100 return make_scoped_ptr(new LayerImpl(tree_impl
, id
));
103 ~LayerImpl() override
;
105 int id() const { return layer_id_
; }
107 // LayerAnimationValueProvider implementation.
108 gfx::ScrollOffset
ScrollOffsetForAnimation() const override
;
110 // LayerAnimationValueObserver implementation.
111 void OnFilterAnimated(const FilterOperations
& filters
) override
;
112 void OnOpacityAnimated(float opacity
) override
;
113 void OnTransformAnimated(const gfx::Transform
& transform
) override
;
114 void OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) override
;
115 void OnAnimationWaitingForDeletion() override
;
116 void OnTransformIsPotentiallyAnimatingChanged(bool is_animating
) override
;
117 bool IsActive() const override
;
119 // AnimationDelegate implementation.
120 void NotifyAnimationStarted(base::TimeTicks monotonic_time
,
121 Animation::TargetProperty target_property
,
122 int group
) override
{};
123 void NotifyAnimationFinished(base::TimeTicks monotonic_time
,
124 Animation::TargetProperty target_property
,
128 LayerImpl
* parent() { return parent_
; }
129 const LayerImpl
* parent() const { return parent_
; }
130 const OwnedLayerImplList
& children() const { return children_
; }
131 OwnedLayerImplList
& children() { return children_
; }
132 LayerImpl
* child_at(size_t index
) const { return children_
[index
]; }
133 void AddChild(scoped_ptr
<LayerImpl
> child
);
134 scoped_ptr
<LayerImpl
> RemoveChild(LayerImpl
* child
);
135 void SetParent(LayerImpl
* parent
);
137 // Warning: This does not preserve tree structure invariants.
138 void ClearChildList();
140 bool HasAncestor(const LayerImpl
* ancestor
) const;
142 void SetScrollParent(LayerImpl
* parent
);
144 LayerImpl
* scroll_parent() { return scroll_parent_
; }
145 const LayerImpl
* scroll_parent() const { return scroll_parent_
; }
147 void SetScrollChildren(std::set
<LayerImpl
*>* children
);
149 std::set
<LayerImpl
*>* scroll_children() { return scroll_children_
.get(); }
150 const std::set
<LayerImpl
*>* scroll_children() const {
151 return scroll_children_
.get();
154 void DistributeScroll(ScrollState
* scroll_state
);
155 void ApplyScroll(ScrollState
* scroll_state
);
157 void set_property_tree_sequence_number(int sequence_number
) {}
159 void SetTransformTreeIndex(int index
);
160 int transform_tree_index() const { return transform_tree_index_
; }
162 void SetClipTreeIndex(int index
);
163 int clip_tree_index() const { return clip_tree_index_
; }
165 void SetEffectTreeIndex(int index
);
166 int effect_tree_index() const { return effect_tree_index_
; }
168 void set_offset_to_transform_parent(const gfx::Vector2dF
& offset
) {
169 offset_to_transform_parent_
= offset
;
170 SetNeedsPushProperties();
172 gfx::Vector2dF
offset_to_transform_parent() const {
173 return offset_to_transform_parent_
;
176 const gfx::Rect
& visible_rect_from_property_trees() const {
177 return visible_rect_from_property_trees_
;
179 void set_visible_rect_from_property_trees(const gfx::Rect
& rect
) {
180 visible_rect_from_property_trees_
= rect
;
183 const gfx::Rect
& clip_rect_in_target_space_from_property_trees() const {
184 return clip_rect_in_target_space_from_property_trees_
;
186 void set_clip_rect_in_target_space_from_property_trees(
187 const gfx::Rect
& rect
) {
188 clip_rect_in_target_space_from_property_trees_
= rect
;
191 void set_should_flatten_transform_from_property_tree(bool should_flatten
) {
192 should_flatten_transform_from_property_tree_
= should_flatten
;
193 SetNeedsPushProperties();
195 bool should_flatten_transform_from_property_tree() const {
196 return should_flatten_transform_from_property_tree_
;
199 void set_is_clipped(bool is_clipped
) {
200 is_clipped_
= is_clipped
;
201 SetNeedsPushProperties();
203 bool is_clipped() const { return is_clipped_
; }
205 void UpdatePropertyTreeTransform();
206 void UpdatePropertyTreeTransformIsAnimated(bool is_animated
);
207 void UpdatePropertyTreeOpacity();
208 void UpdatePropertyTreeScrollOffset();
210 // For compatibility with Layer.
211 bool has_render_surface() const { return !!render_surface(); }
213 void SetNumDescendantsThatDrawContent(int num_descendants
);
214 void SetClipParent(LayerImpl
* ancestor
);
216 LayerImpl
* clip_parent() {
219 const LayerImpl
* clip_parent() const {
223 void SetClipChildren(std::set
<LayerImpl
*>* children
);
225 std::set
<LayerImpl
*>* clip_children() { return clip_children_
.get(); }
226 const std::set
<LayerImpl
*>* clip_children() const {
227 return clip_children_
.get();
230 void PassCopyRequests(ScopedPtrVector
<CopyOutputRequest
>* requests
);
231 // Can only be called when the layer has a copy request.
232 void TakeCopyRequestsAndTransformToTarget(
233 ScopedPtrVector
<CopyOutputRequest
>* request
);
234 bool HasCopyRequest() const { return !copy_requests_
.empty(); }
236 void SetMaskLayer(scoped_ptr
<LayerImpl
> mask_layer
);
237 LayerImpl
* mask_layer() { return mask_layer_
.get(); }
238 const LayerImpl
* mask_layer() const { return mask_layer_
.get(); }
239 scoped_ptr
<LayerImpl
> TakeMaskLayer();
241 void SetReplicaLayer(scoped_ptr
<LayerImpl
> replica_layer
);
242 LayerImpl
* replica_layer() { return replica_layer_
.get(); }
243 const LayerImpl
* replica_layer() const { return replica_layer_
.get(); }
244 scoped_ptr
<LayerImpl
> TakeReplicaLayer();
246 bool has_mask() const { return mask_layer_
; }
247 bool has_replica() const { return replica_layer_
; }
248 bool replica_has_mask() const {
249 return replica_layer_
&& (mask_layer_
|| replica_layer_
->mask_layer_
);
252 LayerTreeImpl
* layer_tree_impl() const { return layer_tree_impl_
; }
254 void PopulateSharedQuadState(SharedQuadState
* state
) const;
255 void PopulateScaledSharedQuadState(SharedQuadState
* state
, float scale
) const;
256 // WillDraw must be called before AppendQuads. If WillDraw returns false,
257 // AppendQuads and DidDraw will not be called. If WillDraw returns true,
258 // DidDraw is guaranteed to be called before another WillDraw or before
259 // the layer is destroyed. To enforce this, any class that overrides
260 // WillDraw/DidDraw must call the base class version only if WillDraw
262 virtual bool WillDraw(DrawMode draw_mode
,
263 ResourceProvider
* resource_provider
);
264 virtual void AppendQuads(RenderPass
* render_pass
,
265 AppendQuadsData
* append_quads_data
) {}
266 virtual void DidDraw(ResourceProvider
* resource_provider
);
268 // Verify that the resource ids in the quad are valid.
269 void ValidateQuadResources(DrawQuad
* quad
) const {
271 ValidateQuadResourcesInternal(quad
);
275 virtual void GetContentsResourceId(ResourceId
* resource_id
,
276 gfx::Size
* resource_size
) const;
278 virtual bool HasDelegatedContent() const;
279 virtual bool HasContributingDelegatedRenderPasses() const;
280 virtual RenderPassId
FirstContributingRenderPassId() const;
281 virtual RenderPassId
NextContributingRenderPassId(RenderPassId id
) const;
283 virtual void NotifyTileStateChanged(const Tile
* tile
) {}
285 virtual ScrollbarLayerImplBase
* ToScrollbarLayer();
287 // Returns true if this layer has content to draw.
288 void SetDrawsContent(bool draws_content
);
289 bool DrawsContent() const { return draws_content_
; }
291 int NumDescendantsThatDrawContent() const;
292 void SetHideLayerAndSubtree(bool hide
);
293 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_
; }
295 void SetTransformOrigin(const gfx::Point3F
& transform_origin
);
296 gfx::Point3F
transform_origin() const { return transform_origin_
; }
298 void SetBackgroundColor(SkColor background_color
);
299 SkColor
background_color() const { return background_color_
; }
300 // If contents_opaque(), return an opaque color else return a
301 // non-opaque color. Tries to return background_color(), if possible.
302 SkColor
SafeOpaqueBackgroundColor() const;
304 void SetFilters(const FilterOperations
& filters
);
305 const FilterOperations
& filters() const { return filters_
; }
306 bool FilterIsAnimating() const;
307 bool HasPotentiallyRunningFilterAnimation() const;
308 bool FilterIsAnimatingOnImplOnly() const;
310 void SetBackgroundFilters(const FilterOperations
& filters
);
311 const FilterOperations
& background_filters() const {
312 return background_filters_
;
315 void SetMasksToBounds(bool masks_to_bounds
);
316 bool masks_to_bounds() const { return masks_to_bounds_
; }
318 void SetContentsOpaque(bool opaque
);
319 bool contents_opaque() const { return contents_opaque_
; }
321 void SetOpacity(float opacity
);
322 float opacity() const { return opacity_
; }
323 bool OpacityIsAnimating() const;
324 bool HasPotentiallyRunningOpacityAnimation() const;
325 bool OpacityIsAnimatingOnImplOnly() const;
327 void SetBlendMode(SkXfermode::Mode
);
328 SkXfermode::Mode
blend_mode() const { return blend_mode_
; }
329 void set_draw_blend_mode(SkXfermode::Mode blend_mode
) {
330 if (draw_blend_mode_
== blend_mode
)
332 draw_blend_mode_
= blend_mode
;
333 SetNeedsPushProperties();
335 SkXfermode::Mode
draw_blend_mode() const { return draw_blend_mode_
; }
336 bool uses_default_blend_mode() const {
337 return blend_mode_
== SkXfermode::kSrcOver_Mode
;
340 void SetIsRootForIsolatedGroup(bool root
);
341 bool is_root_for_isolated_group() const {
342 return is_root_for_isolated_group_
;
345 void SetPosition(const gfx::PointF
& position
);
346 gfx::PointF
position() const { return position_
; }
348 void SetIsContainerForFixedPositionLayers(bool container
) {
349 is_container_for_fixed_position_layers_
= container
;
351 // This is a non-trivial function in Layer.
352 bool IsContainerForFixedPositionLayers() const {
353 return is_container_for_fixed_position_layers_
;
356 bool IsAffectedByPageScale() const { return is_affected_by_page_scale_
; }
357 void SetIsAffectedByPageScale(bool is_affected
) {
358 is_affected_by_page_scale_
= is_affected
;
361 gfx::Vector2dF
FixedContainerSizeDelta() const;
363 void SetPositionConstraint(const LayerPositionConstraint
& constraint
) {
364 position_constraint_
= constraint
;
366 const LayerPositionConstraint
& position_constraint() const {
367 return position_constraint_
;
370 void SetShouldFlattenTransform(bool flatten
);
371 bool should_flatten_transform() const { return should_flatten_transform_
; }
373 bool Is3dSorted() const { return sorting_context_id_
!= 0; }
375 void SetUseParentBackfaceVisibility(bool use
) {
376 use_parent_backface_visibility_
= use
;
378 bool use_parent_backface_visibility() const {
379 return use_parent_backface_visibility_
;
382 bool ShowDebugBorders() const;
384 // These invalidate the host's render surface layer list. The caller
385 // is responsible for calling set_needs_update_draw_properties on the tree
386 // so that its list can be recreated.
387 void ClearRenderSurfaceLayerList();
388 void SetHasRenderSurface(bool has_render_surface
);
390 RenderSurfaceImpl
* render_surface() const { return render_surface_
.get(); }
392 DrawProperties
& draw_properties() { return draw_properties_
; }
393 const DrawProperties
& draw_properties() const { return draw_properties_
; }
395 // The following are shortcut accessors to get various information from
397 const gfx::Transform
& draw_transform() const {
398 return draw_properties_
.target_space_transform
;
400 const gfx::Transform
& screen_space_transform() const {
401 return draw_properties_
.screen_space_transform
;
403 float draw_opacity() const { return draw_properties_
.opacity
; }
404 bool screen_space_transform_is_animating() const {
405 return draw_properties_
.screen_space_transform_is_animating
;
407 bool can_use_lcd_text() const { return draw_properties_
.can_use_lcd_text
; }
408 gfx::Rect
clip_rect() const { return draw_properties_
.clip_rect
; }
409 gfx::Rect
drawable_content_rect() const {
410 return draw_properties_
.drawable_content_rect
;
412 gfx::Rect
visible_layer_rect() const {
413 return draw_properties_
.visible_layer_rect
;
415 LayerImpl
* render_target() {
416 DCHECK(!draw_properties_
.render_target
||
417 draw_properties_
.render_target
->render_surface());
418 return draw_properties_
.render_target
;
420 const LayerImpl
* render_target() const {
421 DCHECK(!draw_properties_
.render_target
||
422 draw_properties_
.render_target
->render_surface());
423 return draw_properties_
.render_target
;
426 size_t num_unclipped_descendants() const {
427 return draw_properties_
.num_unclipped_descendants
;
430 // The client should be responsible for setting bounds, content bounds and
431 // contents scale to appropriate values. LayerImpl doesn't calculate any of
432 // them from the other values.
434 void SetBounds(const gfx::Size
& bounds
);
435 gfx::Size
bounds() const;
436 // Like bounds() but doesn't snap to int. Lossy on giant pages (e.g. millions
437 // of pixels) due to use of single precision float.
438 gfx::SizeF
BoundsForScrolling() const;
439 void SetBoundsDelta(const gfx::Vector2dF
& bounds_delta
);
440 gfx::Vector2dF
bounds_delta() const { return bounds_delta_
; }
442 void SetCurrentScrollOffset(const gfx::ScrollOffset
& scroll_offset
);
443 void PushScrollOffsetFromMainThread(const gfx::ScrollOffset
& scroll_offset
);
444 // This method is similar to PushScrollOffsetFromMainThread but will cause the
445 // scroll offset given to clobber any scroll changes on the active tree in the
446 // time until this value is pushed to the active tree.
447 void PushScrollOffsetFromMainThreadAndClobberActiveValue(
448 const gfx::ScrollOffset
& scroll_offset
);
449 gfx::ScrollOffset
PullDeltaForMainThread();
450 gfx::ScrollOffset
CurrentScrollOffset() const;
451 gfx::ScrollOffset
BaseScrollOffset() const;
452 gfx::Vector2dF
ScrollDelta() const;
453 void SetScrollDelta(const gfx::Vector2dF
& delta
);
455 gfx::ScrollOffset
MaxScrollOffset() const;
456 gfx::ScrollOffset
ClampScrollOffsetToLimits(gfx::ScrollOffset offset
) const;
457 gfx::Vector2dF
ClampScrollToMaxScrollOffset();
458 void SetScrollbarPosition(ScrollbarLayerImplBase
* scrollbar_layer
,
459 LayerImpl
* scrollbar_clip_layer
,
460 bool on_resize
) const;
461 void SetScrollCompensationAdjustment(const gfx::Vector2dF
& scroll_offset
) {
462 scroll_compensation_adjustment_
= scroll_offset
;
464 gfx::Vector2dF
ScrollCompensationAdjustment() const {
465 return scroll_compensation_adjustment_
;
468 // Returns the delta of the scroll that was outside of the bounds of the
470 gfx::Vector2dF
ScrollBy(const gfx::Vector2dF
& scroll
);
472 void SetScrollClipLayer(int scroll_clip_layer_id
);
473 LayerImpl
* scroll_clip_layer() const { return scroll_clip_layer_
; }
474 bool scrollable() const { return !!scroll_clip_layer_
; }
476 void set_user_scrollable_horizontal(bool scrollable
) {
477 user_scrollable_horizontal_
= scrollable
;
479 bool user_scrollable_horizontal() const {
480 return user_scrollable_horizontal_
;
482 void set_user_scrollable_vertical(bool scrollable
) {
483 user_scrollable_vertical_
= scrollable
;
485 bool user_scrollable_vertical() const { return user_scrollable_vertical_
; }
487 bool user_scrollable(ScrollbarOrientation orientation
) const;
489 void ApplySentScrollDeltasFromAbortedCommit();
491 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
492 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
494 bool should_scroll_on_main_thread() const {
495 return should_scroll_on_main_thread_
;
498 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
499 have_wheel_event_handlers_
= have_wheel_event_handlers
;
501 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_
; }
503 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
504 have_scroll_event_handlers_
= have_scroll_event_handlers
;
506 bool have_scroll_event_handlers() const {
507 return have_scroll_event_handlers_
;
510 void SetNonFastScrollableRegion(const Region
& region
) {
511 non_fast_scrollable_region_
= region
;
513 const Region
& non_fast_scrollable_region() const {
514 return non_fast_scrollable_region_
;
517 void SetTouchEventHandlerRegion(const Region
& region
) {
518 touch_event_handler_region_
= region
;
520 const Region
& touch_event_handler_region() const {
521 return touch_event_handler_region_
;
524 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
525 scroll_blocks_on_
= scroll_blocks_on
;
527 ScrollBlocksOn
scroll_blocks_on() const { return scroll_blocks_on_
; }
529 InputHandler::ScrollStatus
TryScroll(
530 const gfx::PointF
& screen_space_point
,
531 InputHandler::ScrollInputType type
,
532 ScrollBlocksOn effective_block_mode
) const;
534 void SetDoubleSided(bool double_sided
);
535 bool double_sided() const { return double_sided_
; }
537 void SetTransform(const gfx::Transform
& transform
);
538 const gfx::Transform
& transform() const { return transform_
; }
539 bool TransformIsAnimating() const;
540 bool HasPotentiallyRunningTransformAnimation() const;
541 bool TransformIsAnimatingOnImplOnly() const;
542 bool HasOnlyTranslationTransforms() const;
543 void SetTransformAndInvertibility(const gfx::Transform
& transform
,
544 bool transform_is_invertible
);
545 bool transform_is_invertible() const { return transform_is_invertible_
; }
547 bool MaximumTargetScale(float* max_scale
) const;
548 bool AnimationStartScale(float* start_scale
) const;
550 // This includes all animations, even those that are finished but haven't yet
552 bool HasAnyAnimationTargetingProperty(
553 Animation::TargetProperty property
) const;
555 bool HasFilterAnimationThatInflatesBounds() const;
556 bool HasTransformAnimationThatInflatesBounds() const;
557 bool HasAnimationThatInflatesBounds() const;
559 bool FilterAnimationBoundsForBox(const gfx::BoxF
& box
,
560 gfx::BoxF
* bounds
) const;
561 bool TransformAnimationBoundsForBox(const gfx::BoxF
& box
,
562 gfx::BoxF
* bounds
) const;
564 // Note this rect is in layer space (not content space).
565 void SetUpdateRect(const gfx::Rect
& update_rect
);
566 const gfx::Rect
& update_rect() const { return update_rect_
; }
568 void AddDamageRect(const gfx::Rect
& damage_rect
);
569 const gfx::Rect
& damage_rect() const { return damage_rect_
; }
571 virtual base::DictionaryValue
* LayerTreeAsJson() const;
573 void SetStackingOrderChanged(bool stacking_order_changed
);
575 bool LayerPropertyChanged() const { return layer_property_changed_
; }
577 void ResetAllChangeTrackingForSubtree();
579 LayerAnimationController
* layer_animation_controller() {
580 return layer_animation_controller_
.get();
583 const LayerAnimationController
* layer_animation_controller() const {
584 return layer_animation_controller_
.get();
587 virtual SimpleEnclosedRegion
VisibleOpaqueRegion() const;
589 virtual void DidBecomeActive();
591 virtual void DidBeginTracing();
593 // Release resources held by this layer. Called when the output surface
594 // that rendered this layer was lost or a rendering mode switch has occured.
595 virtual void ReleaseResources();
597 // Recreate resources that are required after they were released by a
598 // ReleaseResources call.
599 virtual void RecreateResources();
601 ScrollbarAnimationController
* scrollbar_animation_controller() const {
602 return scrollbar_animation_controller_
.get();
605 typedef std::set
<ScrollbarLayerImplBase
*> ScrollbarSet
;
606 ScrollbarSet
* scrollbars() { return scrollbars_
.get(); }
607 void ClearScrollbars();
608 void AddScrollbar(ScrollbarLayerImplBase
* layer
);
609 void RemoveScrollbar(ScrollbarLayerImplBase
* layer
);
610 bool HasScrollbar(ScrollbarOrientation orientation
) const;
611 void ScrollbarParametersDidChange(bool on_resize
);
613 return scroll_clip_layer_
? scroll_clip_layer_
->bounds().height() : 0;
616 virtual skia::RefPtr
<SkPicture
> GetPicture();
618 virtual scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
);
619 virtual void PushPropertiesTo(LayerImpl
* layer
);
621 virtual void GetAllPrioritizedTilesForTracing(
622 std::vector
<PrioritizedTile
>* prioritized_tiles
) const;
623 virtual void AsValueInto(base::trace_event::TracedValue
* dict
) const;
625 virtual size_t GPUMemoryUsageInBytes() const;
627 void SetNeedsPushProperties();
628 void AddDependentNeedsPushProperties();
629 void RemoveDependentNeedsPushProperties();
630 bool parent_should_know_need_push_properties() const {
631 return needs_push_properties() || descendant_needs_push_properties();
634 bool needs_push_properties() const { return needs_push_properties_
; }
635 bool descendant_needs_push_properties() const {
636 return num_dependents_need_push_properties_
> 0;
639 virtual void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
);
641 virtual void SetDebugInfo(
642 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> other
);
644 bool IsDrawnRenderSurfaceLayerListMember() const;
646 void Set3dSortingContextId(int id
);
647 int sorting_context_id() { return sorting_context_id_
; }
649 void SetFrameTimingRequests(
650 const std::vector
<FrameTimingRequest
>& frame_timing_requests
);
651 const std::vector
<FrameTimingRequest
>& frame_timing_requests() const {
652 return frame_timing_requests_
;
654 void GatherFrameTimingRequestIds(std::vector
<int64_t>* request_ids
);
656 SyncedScrollOffset
* synced_scroll_offset() { return scroll_offset_
.get(); }
658 // Get the correct invalidation region instead of conservative Rect
659 // for layers that provide it.
660 virtual Region
GetInvalidationRegion();
662 virtual gfx::Rect
GetEnclosingRectInTargetSpace() const;
664 void set_visited(bool visited
) { visited_
= visited
; }
666 bool visited() { return visited_
; }
668 void set_layer_or_descendant_is_drawn(bool layer_or_descendant_is_drawn
) {
669 layer_or_descendant_is_drawn_
= layer_or_descendant_is_drawn
;
672 bool layer_or_descendant_is_drawn() { return layer_or_descendant_is_drawn_
; }
674 void set_sorted_for_recursion(bool sorted_for_recursion
) {
675 sorted_for_recursion_
= sorted_for_recursion
;
678 bool sorted_for_recursion() { return sorted_for_recursion_
; }
680 void UpdatePropertyTreeForScrollingAndAnimationIfNeeded();
682 float GetIdealContentsScale() const;
685 LayerImpl(LayerTreeImpl
* layer_impl
,
687 scoped_refptr
<SyncedScrollOffset
> scroll_offset
);
688 LayerImpl(LayerTreeImpl
* layer_impl
, int id
);
690 // Get the color and size of the layer's debug border.
691 virtual void GetDebugBorderProperties(SkColor
* color
, float* width
) const;
693 void AppendDebugBorderQuad(RenderPass
* render_pass
,
694 const gfx::Size
& bounds
,
695 const SharedQuadState
* shared_quad_state
,
696 AppendQuadsData
* append_quads_data
) const;
697 void AppendDebugBorderQuad(RenderPass
* render_pass
,
698 const gfx::Size
& bounds
,
699 const SharedQuadState
* shared_quad_state
,
700 AppendQuadsData
* append_quads_data
,
704 void NoteLayerPropertyChanged();
705 void NoteLayerPropertyChangedForSubtree();
707 // Note carefully this does not affect the current layer.
708 void NoteLayerPropertyChangedForDescendants();
710 gfx::Rect
GetScaledEnclosingRectInTargetSpace(float scale
) const;
713 void ValidateQuadResourcesInternal(DrawQuad
* quad
) const;
715 void PushScrollOffset(const gfx::ScrollOffset
* scroll_offset
);
716 void DidUpdateScrollOffset();
717 void NoteLayerPropertyChangedForDescendantsInternal();
719 virtual const char* LayerTypeAsString() const;
721 // Properties internal to LayerImpl
723 OwnedLayerImplList children_
;
725 LayerImpl
* scroll_parent_
;
727 // Storing a pointer to a set rather than a set since this will be rarely
728 // used. If this pointer turns out to be too heavy, we could have this (and
729 // the scroll parent above) be stored in a LayerImpl -> scroll_info
731 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children_
;
733 LayerImpl
* clip_parent_
;
734 scoped_ptr
<std::set
<LayerImpl
*>> clip_children_
;
736 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
737 // confirm newly assigned layer is still the previous one
739 scoped_ptr
<LayerImpl
> mask_layer_
;
740 int replica_layer_id_
; // ditto
741 scoped_ptr
<LayerImpl
> replica_layer_
;
743 LayerTreeImpl
* layer_tree_impl_
;
745 // Properties dynamically changeable on active tree.
746 scoped_refptr
<SyncedScrollOffset
> scroll_offset_
;
747 gfx::Vector2dF bounds_delta_
;
749 // Properties synchronized from the associated Layer.
750 gfx::Point3F transform_origin_
;
752 LayerImpl
* scroll_clip_layer_
;
754 gfx::Vector2dF offset_to_transform_parent_
;
756 bool should_scroll_on_main_thread_
: 1;
757 bool have_wheel_event_handlers_
: 1;
758 bool have_scroll_event_handlers_
: 1;
760 static_assert(SCROLL_BLOCKS_ON_MAX
< (1 << 3), "ScrollBlocksOn too big");
761 ScrollBlocksOn scroll_blocks_on_
: 3;
763 bool user_scrollable_horizontal_
: 1;
764 bool user_scrollable_vertical_
: 1;
765 bool stacking_order_changed_
: 1;
766 // Whether the "back" of this layer should draw.
767 bool double_sided_
: 1;
768 bool should_flatten_transform_
: 1;
769 bool should_flatten_transform_from_property_tree_
: 1;
770 bool is_clipped_
: 1;
772 // Tracks if drawing-related properties have changed since last redraw.
773 bool layer_property_changed_
: 1;
775 bool masks_to_bounds_
: 1;
776 bool contents_opaque_
: 1;
777 bool is_root_for_isolated_group_
: 1;
778 bool use_parent_backface_visibility_
: 1;
779 bool draws_content_
: 1;
780 bool hide_layer_and_subtree_
: 1;
782 // Cache transform_'s invertibility.
783 bool transform_is_invertible_
: 1;
785 // Set for the layer that other layers are fixed to.
786 bool is_container_for_fixed_position_layers_
: 1;
788 bool is_affected_by_page_scale_
: 1;
790 Region non_fast_scrollable_region_
;
791 Region touch_event_handler_region_
;
792 SkColor background_color_
;
795 SkXfermode::Mode blend_mode_
;
796 // draw_blend_mode may be different than blend_mode_,
797 // when a RenderSurface re-parents the layer's blend_mode.
798 SkXfermode::Mode draw_blend_mode_
;
799 gfx::PointF position_
;
800 gfx::Transform transform_
;
802 LayerPositionConstraint position_constraint_
;
804 gfx::Vector2dF scroll_compensation_adjustment_
;
806 int num_descendants_that_draw_content_
;
808 gfx::Rect visible_rect_from_property_trees_
;
809 gfx::Rect clip_rect_in_target_space_from_property_trees_
;
810 int transform_tree_index_
;
811 int effect_tree_index_
;
812 int clip_tree_index_
;
814 // The global depth value of the center of the layer. This value is used
815 // to sort layers from back to front.
818 FilterOperations filters_
;
819 FilterOperations background_filters_
;
822 friend class TreeSynchronizer
;
824 // This flag is set when the layer needs to push properties to the active
826 bool needs_push_properties_
;
828 // The number of direct children or dependent layers that need to be recursed
829 // to in order for them or a descendent of them to push properties to the
831 int num_dependents_need_push_properties_
;
833 // Layers that share a sorting context id will be sorted together in 3d
834 // space. 0 is a special value that means this layer will not be sorted and
835 // will be drawn in paint order.
836 int sorting_context_id_
;
838 DrawMode current_draw_mode_
;
841 // Rect indicating what was repainted/updated during update.
842 // Note that plugin layers bypass this and leave it empty.
843 // This is in the layer's space.
844 gfx::Rect update_rect_
;
846 // Denotes an area that is damaged and needs redraw. This is in the layer's
848 gfx::Rect damage_rect_
;
850 // Manages animations for this layer.
851 scoped_refptr
<LayerAnimationController
> layer_animation_controller_
;
853 // Manages scrollbars for this layer
854 scoped_ptr
<ScrollbarAnimationController
> scrollbar_animation_controller_
;
856 scoped_ptr
<ScrollbarSet
> scrollbars_
;
858 ScopedPtrVector
<CopyOutputRequest
> copy_requests_
;
860 // Group of properties that need to be computed based on the layer tree
861 // hierarchy before layers can be drawn.
862 DrawProperties draw_properties_
;
864 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> debug_info_
;
865 scoped_ptr
<RenderSurfaceImpl
> render_surface_
;
867 std::vector
<FrameTimingRequest
> frame_timing_requests_
;
868 bool frame_timing_requests_dirty_
;
870 bool layer_or_descendant_is_drawn_
;
871 bool sorted_for_recursion_
;
873 DISALLOW_COPY_AND_ASSIGN(LayerImpl
);
878 #endif // CC_LAYERS_LAYER_IMPL_H_