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 bool IsActive() const override
;
118 // AnimationDelegate implementation.
119 void NotifyAnimationStarted(base::TimeTicks monotonic_time
,
120 Animation::TargetProperty target_property
,
121 int group
) override
{};
122 void NotifyAnimationFinished(base::TimeTicks monotonic_time
,
123 Animation::TargetProperty target_property
,
127 LayerImpl
* parent() { return parent_
; }
128 const LayerImpl
* parent() const { return parent_
; }
129 const OwnedLayerImplList
& children() const { return children_
; }
130 OwnedLayerImplList
& children() { return children_
; }
131 LayerImpl
* child_at(size_t index
) const { return children_
[index
]; }
132 void AddChild(scoped_ptr
<LayerImpl
> child
);
133 scoped_ptr
<LayerImpl
> RemoveChild(LayerImpl
* child
);
134 void SetParent(LayerImpl
* parent
);
136 // Warning: This does not preserve tree structure invariants.
137 void ClearChildList();
139 bool HasAncestor(const LayerImpl
* ancestor
) const;
141 void SetScrollParent(LayerImpl
* parent
);
143 LayerImpl
* scroll_parent() { return scroll_parent_
; }
144 const LayerImpl
* scroll_parent() const { return scroll_parent_
; }
146 void SetScrollChildren(std::set
<LayerImpl
*>* children
);
148 std::set
<LayerImpl
*>* scroll_children() { return scroll_children_
.get(); }
149 const std::set
<LayerImpl
*>* scroll_children() const {
150 return scroll_children_
.get();
153 void DistributeScroll(ScrollState
* scroll_state
);
154 void ApplyScroll(ScrollState
* scroll_state
);
156 void set_property_tree_sequence_number(int sequence_number
) {}
158 void SetTransformTreeIndex(int index
);
159 int transform_tree_index() const { return transform_tree_index_
; }
161 void SetClipTreeIndex(int index
);
162 int clip_tree_index() const { return clip_tree_index_
; }
164 void SetOpacityTreeIndex(int index
);
165 int opacity_tree_index() const { return opacity_tree_index_
; }
167 void set_offset_to_transform_parent(const gfx::Vector2dF
& offset
) {
168 offset_to_transform_parent_
= offset
;
169 SetNeedsPushProperties();
171 gfx::Vector2dF
offset_to_transform_parent() const {
172 return offset_to_transform_parent_
;
175 const gfx::Rect
& visible_rect_from_property_trees() const {
176 return visible_rect_from_property_trees_
;
178 void set_visible_rect_from_property_trees(const gfx::Rect
& rect
) {
179 visible_rect_from_property_trees_
= rect
;
182 void set_should_flatten_transform_from_property_tree(bool should_flatten
) {
183 should_flatten_transform_from_property_tree_
= should_flatten
;
184 SetNeedsPushProperties();
186 bool should_flatten_transform_from_property_tree() const {
187 return should_flatten_transform_from_property_tree_
;
190 void set_is_clipped(bool is_clipped
) {
191 is_clipped_
= is_clipped
;
192 SetNeedsPushProperties();
194 bool is_clipped() const { return is_clipped_
; }
196 void UpdatePropertyTreeTransform();
197 void UpdatePropertyTreeOpacity();
198 void UpdatePropertyTreeScrollOffset();
200 // For compatibility with Layer.
201 bool has_render_surface() const { return !!render_surface(); }
203 void SetNumDescendantsThatDrawContent(int num_descendants
);
204 void SetClipParent(LayerImpl
* ancestor
);
206 LayerImpl
* clip_parent() {
209 const LayerImpl
* clip_parent() const {
213 void SetClipChildren(std::set
<LayerImpl
*>* children
);
215 std::set
<LayerImpl
*>* clip_children() { return clip_children_
.get(); }
216 const std::set
<LayerImpl
*>* clip_children() const {
217 return clip_children_
.get();
220 void PassCopyRequests(ScopedPtrVector
<CopyOutputRequest
>* requests
);
221 // Can only be called when the layer has a copy request.
222 void TakeCopyRequestsAndTransformToTarget(
223 ScopedPtrVector
<CopyOutputRequest
>* request
);
224 bool HasCopyRequest() const { return !copy_requests_
.empty(); }
226 void SetMaskLayer(scoped_ptr
<LayerImpl
> mask_layer
);
227 LayerImpl
* mask_layer() { return mask_layer_
.get(); }
228 const LayerImpl
* mask_layer() const { return mask_layer_
.get(); }
229 scoped_ptr
<LayerImpl
> TakeMaskLayer();
231 void SetReplicaLayer(scoped_ptr
<LayerImpl
> replica_layer
);
232 LayerImpl
* replica_layer() { return replica_layer_
.get(); }
233 const LayerImpl
* replica_layer() const { return replica_layer_
.get(); }
234 scoped_ptr
<LayerImpl
> TakeReplicaLayer();
236 bool has_mask() const { return mask_layer_
; }
237 bool has_replica() const { return replica_layer_
; }
238 bool replica_has_mask() const {
239 return replica_layer_
&& (mask_layer_
|| replica_layer_
->mask_layer_
);
242 LayerTreeImpl
* layer_tree_impl() const { return layer_tree_impl_
; }
244 void PopulateSharedQuadState(SharedQuadState
* state
) const;
245 void PopulateScaledSharedQuadState(SharedQuadState
* state
, float scale
) const;
246 // WillDraw must be called before AppendQuads. If WillDraw returns false,
247 // AppendQuads and DidDraw will not be called. If WillDraw returns true,
248 // DidDraw is guaranteed to be called before another WillDraw or before
249 // the layer is destroyed. To enforce this, any class that overrides
250 // WillDraw/DidDraw must call the base class version only if WillDraw
252 virtual bool WillDraw(DrawMode draw_mode
,
253 ResourceProvider
* resource_provider
);
254 virtual void AppendQuads(RenderPass
* render_pass
,
255 AppendQuadsData
* append_quads_data
) {}
256 virtual void DidDraw(ResourceProvider
* resource_provider
);
258 // Verify that the resource ids in the quad are valid.
259 void ValidateQuadResources(DrawQuad
* quad
) const {
261 ValidateQuadResourcesInternal(quad
);
265 virtual void GetContentsResourceId(ResourceId
* resource_id
,
266 gfx::Size
* resource_size
) const;
268 virtual bool HasDelegatedContent() const;
269 virtual bool HasContributingDelegatedRenderPasses() const;
270 virtual RenderPassId
FirstContributingRenderPassId() const;
271 virtual RenderPassId
NextContributingRenderPassId(RenderPassId id
) const;
273 virtual void NotifyTileStateChanged(const Tile
* tile
) {}
275 virtual ScrollbarLayerImplBase
* ToScrollbarLayer();
277 // Returns true if this layer has content to draw.
278 void SetDrawsContent(bool draws_content
);
279 bool DrawsContent() const { return draws_content_
; }
281 int NumDescendantsThatDrawContent() const;
282 void SetHideLayerAndSubtree(bool hide
);
283 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_
; }
285 void SetTransformOrigin(const gfx::Point3F
& transform_origin
);
286 gfx::Point3F
transform_origin() const { return transform_origin_
; }
288 void SetBackgroundColor(SkColor background_color
);
289 SkColor
background_color() const { return background_color_
; }
290 // If contents_opaque(), return an opaque color else return a
291 // non-opaque color. Tries to return background_color(), if possible.
292 SkColor
SafeOpaqueBackgroundColor() const;
294 void SetFilters(const FilterOperations
& filters
);
295 const FilterOperations
& filters() const { return filters_
; }
296 bool FilterIsAnimating() const;
297 bool HasPotentiallyRunningFilterAnimation() const;
298 bool FilterIsAnimatingOnImplOnly() const;
300 void SetBackgroundFilters(const FilterOperations
& filters
);
301 const FilterOperations
& background_filters() const {
302 return background_filters_
;
305 void SetMasksToBounds(bool masks_to_bounds
);
306 bool masks_to_bounds() const { return masks_to_bounds_
; }
308 void SetContentsOpaque(bool opaque
);
309 bool contents_opaque() const { return contents_opaque_
; }
311 void SetOpacity(float opacity
);
312 float opacity() const { return opacity_
; }
313 bool OpacityIsAnimating() const;
314 bool HasPotentiallyRunningOpacityAnimation() const;
315 bool OpacityIsAnimatingOnImplOnly() const;
317 void SetBlendMode(SkXfermode::Mode
);
318 SkXfermode::Mode
blend_mode() const { return blend_mode_
; }
319 bool uses_default_blend_mode() const {
320 return blend_mode_
== SkXfermode::kSrcOver_Mode
;
323 void SetIsRootForIsolatedGroup(bool root
);
324 bool is_root_for_isolated_group() const {
325 return is_root_for_isolated_group_
;
328 void SetPosition(const gfx::PointF
& position
);
329 gfx::PointF
position() const { return position_
; }
331 void SetIsContainerForFixedPositionLayers(bool container
) {
332 is_container_for_fixed_position_layers_
= container
;
334 // This is a non-trivial function in Layer.
335 bool IsContainerForFixedPositionLayers() const {
336 return is_container_for_fixed_position_layers_
;
339 bool IsAffectedByPageScale() const { return is_affected_by_page_scale_
; }
340 void SetIsAffectedByPageScale(bool is_affected
) {
341 is_affected_by_page_scale_
= is_affected
;
344 gfx::Vector2dF
FixedContainerSizeDelta() const;
346 void SetPositionConstraint(const LayerPositionConstraint
& constraint
) {
347 position_constraint_
= constraint
;
349 const LayerPositionConstraint
& position_constraint() const {
350 return position_constraint_
;
353 void SetShouldFlattenTransform(bool flatten
);
354 bool should_flatten_transform() const { return should_flatten_transform_
; }
356 bool Is3dSorted() const { return sorting_context_id_
!= 0; }
358 void SetUseParentBackfaceVisibility(bool use
) {
359 use_parent_backface_visibility_
= use
;
361 bool use_parent_backface_visibility() const {
362 return use_parent_backface_visibility_
;
365 bool ShowDebugBorders() const;
367 // These invalidate the host's render surface layer list. The caller
368 // is responsible for calling set_needs_update_draw_properties on the tree
369 // so that its list can be recreated.
370 void ClearRenderSurfaceLayerList();
371 void SetHasRenderSurface(bool has_render_surface
);
373 RenderSurfaceImpl
* render_surface() const { return render_surface_
.get(); }
375 DrawProperties
<LayerImpl
>& draw_properties() {
376 return draw_properties_
;
378 const DrawProperties
<LayerImpl
>& draw_properties() const {
379 return draw_properties_
;
382 // The following are shortcut accessors to get various information from
384 const gfx::Transform
& draw_transform() const {
385 return draw_properties_
.target_space_transform
;
387 const gfx::Transform
& screen_space_transform() const {
388 return draw_properties_
.screen_space_transform
;
390 float draw_opacity() const { return draw_properties_
.opacity
; }
391 SkXfermode::Mode
draw_blend_mode() const {
392 return draw_properties_
.blend_mode
;
394 bool screen_space_transform_is_animating() const {
395 return draw_properties_
.screen_space_transform_is_animating
;
397 bool can_use_lcd_text() const { return draw_properties_
.can_use_lcd_text
; }
398 gfx::Rect
clip_rect() const { return draw_properties_
.clip_rect
; }
399 gfx::Rect
drawable_content_rect() const {
400 return draw_properties_
.drawable_content_rect
;
402 gfx::Rect
visible_layer_rect() const {
403 return draw_properties_
.visible_layer_rect
;
405 LayerImpl
* render_target() {
406 DCHECK(!draw_properties_
.render_target
||
407 draw_properties_
.render_target
->render_surface());
408 return draw_properties_
.render_target
;
410 const LayerImpl
* render_target() const {
411 DCHECK(!draw_properties_
.render_target
||
412 draw_properties_
.render_target
->render_surface());
413 return draw_properties_
.render_target
;
416 size_t num_unclipped_descendants() const {
417 return draw_properties_
.num_unclipped_descendants
;
420 // The client should be responsible for setting bounds, content bounds and
421 // contents scale to appropriate values. LayerImpl doesn't calculate any of
422 // them from the other values.
424 void SetBounds(const gfx::Size
& bounds
);
425 gfx::Size
bounds() const;
426 // Like bounds() but doesn't snap to int. Lossy on giant pages (e.g. millions
427 // of pixels) due to use of single precision float.
428 gfx::SizeF
BoundsForScrolling() const;
429 void SetBoundsDelta(const gfx::Vector2dF
& bounds_delta
);
430 gfx::Vector2dF
bounds_delta() const { return bounds_delta_
; }
432 bool IsExternalScrollActive() const;
434 void SetCurrentScrollOffset(const gfx::ScrollOffset
& scroll_offset
);
435 void SetCurrentScrollOffsetFromDelegate(
436 const gfx::ScrollOffset
& scroll_offset
);
437 void PushScrollOffsetFromMainThread(const gfx::ScrollOffset
& scroll_offset
);
438 // This method is similar to PushScrollOffsetFromMainThread but will cause the
439 // scroll offset given to clobber any scroll changes on the active tree in the
440 // time until this value is pushed to the active tree.
441 void PushScrollOffsetFromMainThreadAndClobberActiveValue(
442 const gfx::ScrollOffset
& scroll_offset
);
443 gfx::ScrollOffset
PullDeltaForMainThread();
444 gfx::ScrollOffset
CurrentScrollOffset() const;
445 gfx::ScrollOffset
BaseScrollOffset() const;
446 gfx::Vector2dF
ScrollDelta() const;
447 void SetScrollDelta(const gfx::Vector2dF
& delta
);
449 gfx::ScrollOffset
MaxScrollOffset() const;
450 gfx::ScrollOffset
ClampScrollOffsetToLimits(gfx::ScrollOffset offset
) const;
451 gfx::Vector2dF
ClampScrollToMaxScrollOffset();
452 void SetScrollbarPosition(ScrollbarLayerImplBase
* scrollbar_layer
,
453 LayerImpl
* scrollbar_clip_layer
,
454 bool on_resize
) const;
455 void SetScrollCompensationAdjustment(const gfx::Vector2dF
& scroll_offset
) {
456 scroll_compensation_adjustment_
= scroll_offset
;
458 gfx::Vector2dF
ScrollCompensationAdjustment() const {
459 return scroll_compensation_adjustment_
;
462 // Returns the delta of the scroll that was outside of the bounds of the
464 gfx::Vector2dF
ScrollBy(const gfx::Vector2dF
& scroll
);
466 void SetScrollClipLayer(int scroll_clip_layer_id
);
467 LayerImpl
* scroll_clip_layer() const { return scroll_clip_layer_
; }
468 bool scrollable() const { return !!scroll_clip_layer_
; }
470 void set_user_scrollable_horizontal(bool scrollable
) {
471 user_scrollable_horizontal_
= scrollable
;
473 bool user_scrollable_horizontal() const {
474 return user_scrollable_horizontal_
;
476 void set_user_scrollable_vertical(bool scrollable
) {
477 user_scrollable_vertical_
= scrollable
;
479 bool user_scrollable_vertical() const { return user_scrollable_vertical_
; }
481 bool user_scrollable(ScrollbarOrientation orientation
) const;
483 void ApplySentScrollDeltasFromAbortedCommit();
485 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
486 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
488 bool should_scroll_on_main_thread() const {
489 return should_scroll_on_main_thread_
;
492 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
493 have_wheel_event_handlers_
= have_wheel_event_handlers
;
495 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_
; }
497 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
498 have_scroll_event_handlers_
= have_scroll_event_handlers
;
500 bool have_scroll_event_handlers() const {
501 return have_scroll_event_handlers_
;
504 void SetNonFastScrollableRegion(const Region
& region
) {
505 non_fast_scrollable_region_
= region
;
507 const Region
& non_fast_scrollable_region() const {
508 return non_fast_scrollable_region_
;
511 void SetTouchEventHandlerRegion(const Region
& region
) {
512 touch_event_handler_region_
= region
;
514 const Region
& touch_event_handler_region() const {
515 return touch_event_handler_region_
;
518 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
519 scroll_blocks_on_
= scroll_blocks_on
;
521 ScrollBlocksOn
scroll_blocks_on() const { return scroll_blocks_on_
; }
522 void SetDrawCheckerboardForMissingTiles(bool checkerboard
) {
523 draw_checkerboard_for_missing_tiles_
= checkerboard
;
525 bool draw_checkerboard_for_missing_tiles() const {
526 return draw_checkerboard_for_missing_tiles_
;
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 gfx::Rect
update_rect() const { return update_rect_
; }
568 void AddDamageRect(const gfx::RectF
& damage_rect
);
570 const gfx::RectF
& damage_rect() const { return damage_rect_
; }
572 virtual base::DictionaryValue
* LayerTreeAsJson() const;
574 void SetStackingOrderChanged(bool stacking_order_changed
);
576 bool LayerPropertyChanged() const { return layer_property_changed_
; }
578 void ResetAllChangeTrackingForSubtree();
580 LayerAnimationController
* layer_animation_controller() {
581 return layer_animation_controller_
.get();
584 const LayerAnimationController
* layer_animation_controller() const {
585 return layer_animation_controller_
.get();
588 virtual SimpleEnclosedRegion
VisibleOpaqueRegion() const;
590 virtual void DidBecomeActive();
592 virtual void DidBeginTracing();
594 // Release resources held by this layer. Called when the output surface
595 // that rendered this layer was lost or a rendering mode switch has occured.
596 virtual void ReleaseResources();
598 // Recreate resources that are required after they were released by a
599 // ReleaseResources call.
600 virtual void RecreateResources();
602 ScrollbarAnimationController
* scrollbar_animation_controller() const {
603 return scrollbar_animation_controller_
.get();
606 typedef std::set
<ScrollbarLayerImplBase
*> ScrollbarSet
;
607 ScrollbarSet
* scrollbars() { return scrollbars_
.get(); }
608 void ClearScrollbars();
609 void AddScrollbar(ScrollbarLayerImplBase
* layer
);
610 void RemoveScrollbar(ScrollbarLayerImplBase
* layer
);
611 bool HasScrollbar(ScrollbarOrientation orientation
) const;
612 void ScrollbarParametersDidChange(bool on_resize
);
614 return scroll_clip_layer_
? scroll_clip_layer_
->bounds().height() : 0;
617 virtual skia::RefPtr
<SkPicture
> GetPicture();
619 virtual scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
);
620 virtual void PushPropertiesTo(LayerImpl
* layer
);
622 virtual void GetAllPrioritizedTilesForTracing(
623 std::vector
<PrioritizedTile
>* prioritized_tiles
) const;
624 virtual void AsValueInto(base::trace_event::TracedValue
* dict
) const;
626 virtual size_t GPUMemoryUsageInBytes() const;
628 void SetNeedsPushProperties();
629 void AddDependentNeedsPushProperties();
630 void RemoveDependentNeedsPushProperties();
631 bool parent_should_know_need_push_properties() const {
632 return needs_push_properties() || descendant_needs_push_properties();
635 bool needs_push_properties() const { return needs_push_properties_
; }
636 bool descendant_needs_push_properties() const {
637 return num_dependents_need_push_properties_
> 0;
640 virtual void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
);
642 virtual void SetDebugInfo(
643 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> other
);
645 bool IsDrawnRenderSurfaceLayerListMember() const;
647 void Set3dSortingContextId(int id
);
648 int sorting_context_id() { return sorting_context_id_
; }
650 void SetFrameTimingRequests(
651 const std::vector
<FrameTimingRequest
>& frame_timing_requests
);
652 const std::vector
<FrameTimingRequest
>& frame_timing_requests() const {
653 return frame_timing_requests_
;
655 void GatherFrameTimingRequestIds(std::vector
<int64_t>* request_ids
);
657 SyncedScrollOffset
* synced_scroll_offset() { return scroll_offset_
.get(); }
659 // Get the correct invalidation region instead of conservative Rect
660 // for layers that provide it.
661 virtual Region
GetInvalidationRegion();
663 virtual gfx::Rect
GetEnclosingRectInTargetSpace() const;
665 void set_visited(bool visited
) { visited_
= visited
; }
667 bool visited() { return visited_
; }
669 void set_layer_or_descendant_is_drawn(bool layer_or_descendant_is_drawn
) {
670 layer_or_descendant_is_drawn_
= layer_or_descendant_is_drawn
;
673 bool layer_or_descendant_is_drawn() { return layer_or_descendant_is_drawn_
; }
675 void set_sorted_for_recursion(bool sorted_for_recursion
) {
676 sorted_for_recursion_
= sorted_for_recursion
;
679 bool sorted_for_recursion() { return sorted_for_recursion_
; }
681 void UpdatePropertyTreeForScrollingAndAnimationIfNeeded();
683 float GetIdealContentsScale() const;
686 LayerImpl(LayerTreeImpl
* layer_impl
,
688 scoped_refptr
<SyncedScrollOffset
> scroll_offset
);
689 LayerImpl(LayerTreeImpl
* layer_impl
, int id
);
691 // Get the color and size of the layer's debug border.
692 virtual void GetDebugBorderProperties(SkColor
* color
, float* width
) const;
694 void AppendDebugBorderQuad(RenderPass
* render_pass
,
695 const gfx::Size
& bounds
,
696 const SharedQuadState
* shared_quad_state
,
697 AppendQuadsData
* append_quads_data
) const;
698 void AppendDebugBorderQuad(RenderPass
* render_pass
,
699 const gfx::Size
& bounds
,
700 const SharedQuadState
* shared_quad_state
,
701 AppendQuadsData
* append_quads_data
,
705 void NoteLayerPropertyChanged();
706 void NoteLayerPropertyChangedForSubtree();
708 // Note carefully this does not affect the current layer.
709 void NoteLayerPropertyChangedForDescendants();
711 gfx::Rect
GetScaledEnclosingRectInTargetSpace(float scale
) const;
714 void ValidateQuadResourcesInternal(DrawQuad
* quad
) const;
716 void PushScrollOffset(const gfx::ScrollOffset
* scroll_offset
);
717 // If the new scroll offset is assigned from the root scroll offset delegate,
718 // LayerImpl won't inform the root scroll offset delegate about the scroll
719 // change to avoid feedback.
720 void DidUpdateScrollOffset(bool is_from_root_delegate
);
721 void NoteLayerPropertyChangedForDescendantsInternal();
723 virtual const char* LayerTypeAsString() const;
725 // Properties internal to LayerImpl
727 OwnedLayerImplList children_
;
729 LayerImpl
* scroll_parent_
;
731 // Storing a pointer to a set rather than a set since this will be rarely
732 // used. If this pointer turns out to be too heavy, we could have this (and
733 // the scroll parent above) be stored in a LayerImpl -> scroll_info
735 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children_
;
737 LayerImpl
* clip_parent_
;
738 scoped_ptr
<std::set
<LayerImpl
*>> clip_children_
;
740 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
741 // confirm newly assigned layer is still the previous one
743 scoped_ptr
<LayerImpl
> mask_layer_
;
744 int replica_layer_id_
; // ditto
745 scoped_ptr
<LayerImpl
> replica_layer_
;
747 LayerTreeImpl
* layer_tree_impl_
;
749 // Properties dynamically changeable on active tree.
750 scoped_refptr
<SyncedScrollOffset
> scroll_offset_
;
751 gfx::Vector2dF bounds_delta_
;
753 // Properties synchronized from the associated Layer.
754 gfx::Point3F transform_origin_
;
756 LayerImpl
* scroll_clip_layer_
;
758 gfx::Vector2dF offset_to_transform_parent_
;
760 bool scrollable_
: 1;
761 bool should_scroll_on_main_thread_
: 1;
762 bool have_wheel_event_handlers_
: 1;
763 bool have_scroll_event_handlers_
: 1;
765 static_assert(SCROLL_BLOCKS_ON_MAX
< (1 << 3), "ScrollBlocksOn too big");
766 ScrollBlocksOn scroll_blocks_on_
: 3;
768 bool user_scrollable_horizontal_
: 1;
769 bool user_scrollable_vertical_
: 1;
770 bool stacking_order_changed_
: 1;
771 // Whether the "back" of this layer should draw.
772 bool double_sided_
: 1;
773 bool should_flatten_transform_
: 1;
774 bool should_flatten_transform_from_property_tree_
: 1;
775 bool is_clipped_
: 1;
777 // Tracks if drawing-related properties have changed since last redraw.
778 bool layer_property_changed_
: 1;
780 bool masks_to_bounds_
: 1;
781 bool contents_opaque_
: 1;
782 bool is_root_for_isolated_group_
: 1;
783 bool use_parent_backface_visibility_
: 1;
784 bool draw_checkerboard_for_missing_tiles_
: 1;
785 bool draws_content_
: 1;
786 bool hide_layer_and_subtree_
: 1;
788 // Cache transform_'s invertibility.
789 bool transform_is_invertible_
: 1;
791 // Set for the layer that other layers are fixed to.
792 bool is_container_for_fixed_position_layers_
: 1;
794 bool is_affected_by_page_scale_
: 1;
796 Region non_fast_scrollable_region_
;
797 Region touch_event_handler_region_
;
798 SkColor background_color_
;
801 SkXfermode::Mode blend_mode_
;
802 gfx::PointF position_
;
803 gfx::Transform transform_
;
805 LayerPositionConstraint position_constraint_
;
807 gfx::Vector2dF scroll_compensation_adjustment_
;
809 int num_descendants_that_draw_content_
;
811 gfx::Rect visible_rect_from_property_trees_
;
812 int transform_tree_index_
;
813 int opacity_tree_index_
;
814 int clip_tree_index_
;
816 // The global depth value of the center of the layer. This value is used
817 // to sort layers from back to front.
820 FilterOperations filters_
;
821 FilterOperations background_filters_
;
824 friend class TreeSynchronizer
;
826 // This flag is set when the layer needs to push properties to the active
828 bool needs_push_properties_
;
830 // The number of direct children or dependent layers that need to be recursed
831 // to in order for them or a descendent of them to push properties to the
833 int num_dependents_need_push_properties_
;
835 // Layers that share a sorting context id will be sorted together in 3d
836 // space. 0 is a special value that means this layer will not be sorted and
837 // will be drawn in paint order.
838 int sorting_context_id_
;
840 DrawMode current_draw_mode_
;
843 // Rect indicating what was repainted/updated during update.
844 // Note that plugin layers bypass this and leave it empty.
845 // Uses layer (not content) space.
846 gfx::Rect update_rect_
;
848 // This rect is in layer space.
849 gfx::RectF damage_rect_
;
851 // Manages animations for this layer.
852 scoped_refptr
<LayerAnimationController
> layer_animation_controller_
;
854 // Manages scrollbars for this layer
855 scoped_ptr
<ScrollbarAnimationController
> scrollbar_animation_controller_
;
857 scoped_ptr
<ScrollbarSet
> scrollbars_
;
859 ScopedPtrVector
<CopyOutputRequest
> copy_requests_
;
861 // Group of properties that need to be computed based on the layer tree
862 // hierarchy before layers can be drawn.
863 DrawProperties
<LayerImpl
> draw_properties_
;
865 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> debug_info_
;
866 scoped_ptr
<RenderSurfaceImpl
> render_surface_
;
868 std::vector
<FrameTimingRequest
> frame_timing_requests_
;
869 bool frame_timing_requests_dirty_
;
871 bool layer_or_descendant_is_drawn_
;
872 bool sorted_for_recursion_
;
874 DISALLOW_COPY_AND_ASSIGN(LayerImpl
);
879 #endif // CC_LAYERS_LAYER_IMPL_H_