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
<LayerImpl
>& draw_properties() {
393 return draw_properties_
;
395 const DrawProperties
<LayerImpl
>& draw_properties() const {
396 return draw_properties_
;
399 // The following are shortcut accessors to get various information from
401 const gfx::Transform
& draw_transform() const {
402 return draw_properties_
.target_space_transform
;
404 const gfx::Transform
& screen_space_transform() const {
405 return draw_properties_
.screen_space_transform
;
407 float draw_opacity() const { return draw_properties_
.opacity
; }
408 bool screen_space_transform_is_animating() const {
409 return draw_properties_
.screen_space_transform_is_animating
;
411 bool can_use_lcd_text() const { return draw_properties_
.can_use_lcd_text
; }
412 gfx::Rect
clip_rect() const { return draw_properties_
.clip_rect
; }
413 gfx::Rect
drawable_content_rect() const {
414 return draw_properties_
.drawable_content_rect
;
416 gfx::Rect
visible_layer_rect() const {
417 return draw_properties_
.visible_layer_rect
;
419 LayerImpl
* render_target() {
420 DCHECK(!draw_properties_
.render_target
||
421 draw_properties_
.render_target
->render_surface());
422 return draw_properties_
.render_target
;
424 const LayerImpl
* render_target() const {
425 DCHECK(!draw_properties_
.render_target
||
426 draw_properties_
.render_target
->render_surface());
427 return draw_properties_
.render_target
;
430 size_t num_unclipped_descendants() const {
431 return draw_properties_
.num_unclipped_descendants
;
434 // The client should be responsible for setting bounds, content bounds and
435 // contents scale to appropriate values. LayerImpl doesn't calculate any of
436 // them from the other values.
438 void SetBounds(const gfx::Size
& bounds
);
439 gfx::Size
bounds() const;
440 // Like bounds() but doesn't snap to int. Lossy on giant pages (e.g. millions
441 // of pixels) due to use of single precision float.
442 gfx::SizeF
BoundsForScrolling() const;
443 void SetBoundsDelta(const gfx::Vector2dF
& bounds_delta
);
444 gfx::Vector2dF
bounds_delta() const { return bounds_delta_
; }
446 bool IsExternalScrollActive() const;
448 void SetCurrentScrollOffset(const gfx::ScrollOffset
& scroll_offset
);
449 void SetCurrentScrollOffsetFromDelegate(
450 const gfx::ScrollOffset
& scroll_offset
);
451 void PushScrollOffsetFromMainThread(const gfx::ScrollOffset
& scroll_offset
);
452 // This method is similar to PushScrollOffsetFromMainThread but will cause the
453 // scroll offset given to clobber any scroll changes on the active tree in the
454 // time until this value is pushed to the active tree.
455 void PushScrollOffsetFromMainThreadAndClobberActiveValue(
456 const gfx::ScrollOffset
& scroll_offset
);
457 gfx::ScrollOffset
PullDeltaForMainThread();
458 gfx::ScrollOffset
CurrentScrollOffset() const;
459 gfx::ScrollOffset
BaseScrollOffset() const;
460 gfx::Vector2dF
ScrollDelta() const;
461 void SetScrollDelta(const gfx::Vector2dF
& delta
);
463 gfx::ScrollOffset
MaxScrollOffset() const;
464 gfx::ScrollOffset
ClampScrollOffsetToLimits(gfx::ScrollOffset offset
) const;
465 gfx::Vector2dF
ClampScrollToMaxScrollOffset();
466 void SetScrollbarPosition(ScrollbarLayerImplBase
* scrollbar_layer
,
467 LayerImpl
* scrollbar_clip_layer
,
468 bool on_resize
) const;
469 void SetScrollCompensationAdjustment(const gfx::Vector2dF
& scroll_offset
) {
470 scroll_compensation_adjustment_
= scroll_offset
;
472 gfx::Vector2dF
ScrollCompensationAdjustment() const {
473 return scroll_compensation_adjustment_
;
476 // Returns the delta of the scroll that was outside of the bounds of the
478 gfx::Vector2dF
ScrollBy(const gfx::Vector2dF
& scroll
);
480 void SetScrollClipLayer(int scroll_clip_layer_id
);
481 LayerImpl
* scroll_clip_layer() const { return scroll_clip_layer_
; }
482 bool scrollable() const { return !!scroll_clip_layer_
; }
484 void set_user_scrollable_horizontal(bool scrollable
) {
485 user_scrollable_horizontal_
= scrollable
;
487 bool user_scrollable_horizontal() const {
488 return user_scrollable_horizontal_
;
490 void set_user_scrollable_vertical(bool scrollable
) {
491 user_scrollable_vertical_
= scrollable
;
493 bool user_scrollable_vertical() const { return user_scrollable_vertical_
; }
495 bool user_scrollable(ScrollbarOrientation orientation
) const;
497 void ApplySentScrollDeltasFromAbortedCommit();
499 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
500 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
502 bool should_scroll_on_main_thread() const {
503 return should_scroll_on_main_thread_
;
506 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
507 have_wheel_event_handlers_
= have_wheel_event_handlers
;
509 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_
; }
511 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
512 have_scroll_event_handlers_
= have_scroll_event_handlers
;
514 bool have_scroll_event_handlers() const {
515 return have_scroll_event_handlers_
;
518 void SetNonFastScrollableRegion(const Region
& region
) {
519 non_fast_scrollable_region_
= region
;
521 const Region
& non_fast_scrollable_region() const {
522 return non_fast_scrollable_region_
;
525 void SetTouchEventHandlerRegion(const Region
& region
) {
526 touch_event_handler_region_
= region
;
528 const Region
& touch_event_handler_region() const {
529 return touch_event_handler_region_
;
532 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
533 scroll_blocks_on_
= scroll_blocks_on
;
535 ScrollBlocksOn
scroll_blocks_on() const { return scroll_blocks_on_
; }
537 InputHandler::ScrollStatus
TryScroll(
538 const gfx::PointF
& screen_space_point
,
539 InputHandler::ScrollInputType type
,
540 ScrollBlocksOn effective_block_mode
) const;
542 void SetDoubleSided(bool double_sided
);
543 bool double_sided() const { return double_sided_
; }
545 void SetTransform(const gfx::Transform
& transform
);
546 const gfx::Transform
& transform() const { return transform_
; }
547 bool TransformIsAnimating() const;
548 bool HasPotentiallyRunningTransformAnimation() const;
549 bool TransformIsAnimatingOnImplOnly() const;
550 bool HasOnlyTranslationTransforms() const;
551 void SetTransformAndInvertibility(const gfx::Transform
& transform
,
552 bool transform_is_invertible
);
553 bool transform_is_invertible() const { return transform_is_invertible_
; }
555 bool MaximumTargetScale(float* max_scale
) const;
556 bool AnimationStartScale(float* start_scale
) const;
558 // This includes all animations, even those that are finished but haven't yet
560 bool HasAnyAnimationTargetingProperty(
561 Animation::TargetProperty property
) const;
563 bool HasFilterAnimationThatInflatesBounds() const;
564 bool HasTransformAnimationThatInflatesBounds() const;
565 bool HasAnimationThatInflatesBounds() const;
567 bool FilterAnimationBoundsForBox(const gfx::BoxF
& box
,
568 gfx::BoxF
* bounds
) const;
569 bool TransformAnimationBoundsForBox(const gfx::BoxF
& box
,
570 gfx::BoxF
* bounds
) const;
572 // Note this rect is in layer space (not content space).
573 void SetUpdateRect(const gfx::Rect
& update_rect
);
574 gfx::Rect
update_rect() const { return update_rect_
; }
576 void AddDamageRect(const gfx::RectF
& damage_rect
);
578 const gfx::RectF
& damage_rect() const { return damage_rect_
; }
580 virtual base::DictionaryValue
* LayerTreeAsJson() const;
582 void SetStackingOrderChanged(bool stacking_order_changed
);
584 bool LayerPropertyChanged() const { return layer_property_changed_
; }
586 void ResetAllChangeTrackingForSubtree();
588 LayerAnimationController
* layer_animation_controller() {
589 return layer_animation_controller_
.get();
592 const LayerAnimationController
* layer_animation_controller() const {
593 return layer_animation_controller_
.get();
596 virtual SimpleEnclosedRegion
VisibleOpaqueRegion() const;
598 virtual void DidBecomeActive();
600 virtual void DidBeginTracing();
602 // Release resources held by this layer. Called when the output surface
603 // that rendered this layer was lost or a rendering mode switch has occured.
604 virtual void ReleaseResources();
606 // Recreate resources that are required after they were released by a
607 // ReleaseResources call.
608 virtual void RecreateResources();
610 ScrollbarAnimationController
* scrollbar_animation_controller() const {
611 return scrollbar_animation_controller_
.get();
614 typedef std::set
<ScrollbarLayerImplBase
*> ScrollbarSet
;
615 ScrollbarSet
* scrollbars() { return scrollbars_
.get(); }
616 void ClearScrollbars();
617 void AddScrollbar(ScrollbarLayerImplBase
* layer
);
618 void RemoveScrollbar(ScrollbarLayerImplBase
* layer
);
619 bool HasScrollbar(ScrollbarOrientation orientation
) const;
620 void ScrollbarParametersDidChange(bool on_resize
);
622 return scroll_clip_layer_
? scroll_clip_layer_
->bounds().height() : 0;
625 virtual skia::RefPtr
<SkPicture
> GetPicture();
627 virtual scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
);
628 virtual void PushPropertiesTo(LayerImpl
* layer
);
630 virtual void GetAllPrioritizedTilesForTracing(
631 std::vector
<PrioritizedTile
>* prioritized_tiles
) const;
632 virtual void AsValueInto(base::trace_event::TracedValue
* dict
) const;
634 virtual size_t GPUMemoryUsageInBytes() const;
636 void SetNeedsPushProperties();
637 void AddDependentNeedsPushProperties();
638 void RemoveDependentNeedsPushProperties();
639 bool parent_should_know_need_push_properties() const {
640 return needs_push_properties() || descendant_needs_push_properties();
643 bool needs_push_properties() const { return needs_push_properties_
; }
644 bool descendant_needs_push_properties() const {
645 return num_dependents_need_push_properties_
> 0;
648 virtual void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
);
650 virtual void SetDebugInfo(
651 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> other
);
653 bool IsDrawnRenderSurfaceLayerListMember() const;
655 void Set3dSortingContextId(int id
);
656 int sorting_context_id() { return sorting_context_id_
; }
658 void SetFrameTimingRequests(
659 const std::vector
<FrameTimingRequest
>& frame_timing_requests
);
660 const std::vector
<FrameTimingRequest
>& frame_timing_requests() const {
661 return frame_timing_requests_
;
663 void GatherFrameTimingRequestIds(std::vector
<int64_t>* request_ids
);
665 SyncedScrollOffset
* synced_scroll_offset() { return scroll_offset_
.get(); }
667 // Get the correct invalidation region instead of conservative Rect
668 // for layers that provide it.
669 virtual Region
GetInvalidationRegion();
671 virtual gfx::Rect
GetEnclosingRectInTargetSpace() const;
673 void set_visited(bool visited
) { visited_
= visited
; }
675 bool visited() { return visited_
; }
677 void set_layer_or_descendant_is_drawn(bool layer_or_descendant_is_drawn
) {
678 layer_or_descendant_is_drawn_
= layer_or_descendant_is_drawn
;
681 bool layer_or_descendant_is_drawn() { return layer_or_descendant_is_drawn_
; }
683 void set_sorted_for_recursion(bool sorted_for_recursion
) {
684 sorted_for_recursion_
= sorted_for_recursion
;
687 bool sorted_for_recursion() { return sorted_for_recursion_
; }
689 void UpdatePropertyTreeForScrollingAndAnimationIfNeeded();
691 float GetIdealContentsScale() const;
694 LayerImpl(LayerTreeImpl
* layer_impl
,
696 scoped_refptr
<SyncedScrollOffset
> scroll_offset
);
697 LayerImpl(LayerTreeImpl
* layer_impl
, int id
);
699 // Get the color and size of the layer's debug border.
700 virtual void GetDebugBorderProperties(SkColor
* color
, float* width
) const;
702 void AppendDebugBorderQuad(RenderPass
* render_pass
,
703 const gfx::Size
& bounds
,
704 const SharedQuadState
* shared_quad_state
,
705 AppendQuadsData
* append_quads_data
) const;
706 void AppendDebugBorderQuad(RenderPass
* render_pass
,
707 const gfx::Size
& bounds
,
708 const SharedQuadState
* shared_quad_state
,
709 AppendQuadsData
* append_quads_data
,
713 void NoteLayerPropertyChanged();
714 void NoteLayerPropertyChangedForSubtree();
716 // Note carefully this does not affect the current layer.
717 void NoteLayerPropertyChangedForDescendants();
719 gfx::Rect
GetScaledEnclosingRectInTargetSpace(float scale
) const;
722 void ValidateQuadResourcesInternal(DrawQuad
* quad
) const;
724 void PushScrollOffset(const gfx::ScrollOffset
* scroll_offset
);
725 // If the new scroll offset is assigned from the root scroll offset delegate,
726 // LayerImpl won't inform the root scroll offset delegate about the scroll
727 // change to avoid feedback.
728 void DidUpdateScrollOffset(bool is_from_root_delegate
);
729 void NoteLayerPropertyChangedForDescendantsInternal();
731 virtual const char* LayerTypeAsString() const;
733 // Properties internal to LayerImpl
735 OwnedLayerImplList children_
;
737 LayerImpl
* scroll_parent_
;
739 // Storing a pointer to a set rather than a set since this will be rarely
740 // used. If this pointer turns out to be too heavy, we could have this (and
741 // the scroll parent above) be stored in a LayerImpl -> scroll_info
743 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children_
;
745 LayerImpl
* clip_parent_
;
746 scoped_ptr
<std::set
<LayerImpl
*>> clip_children_
;
748 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
749 // confirm newly assigned layer is still the previous one
751 scoped_ptr
<LayerImpl
> mask_layer_
;
752 int replica_layer_id_
; // ditto
753 scoped_ptr
<LayerImpl
> replica_layer_
;
755 LayerTreeImpl
* layer_tree_impl_
;
757 // Properties dynamically changeable on active tree.
758 scoped_refptr
<SyncedScrollOffset
> scroll_offset_
;
759 gfx::Vector2dF bounds_delta_
;
761 // Properties synchronized from the associated Layer.
762 gfx::Point3F transform_origin_
;
764 LayerImpl
* scroll_clip_layer_
;
766 gfx::Vector2dF offset_to_transform_parent_
;
768 bool should_scroll_on_main_thread_
: 1;
769 bool have_wheel_event_handlers_
: 1;
770 bool have_scroll_event_handlers_
: 1;
772 static_assert(SCROLL_BLOCKS_ON_MAX
< (1 << 3), "ScrollBlocksOn too big");
773 ScrollBlocksOn scroll_blocks_on_
: 3;
775 bool user_scrollable_horizontal_
: 1;
776 bool user_scrollable_vertical_
: 1;
777 bool stacking_order_changed_
: 1;
778 // Whether the "back" of this layer should draw.
779 bool double_sided_
: 1;
780 bool should_flatten_transform_
: 1;
781 bool should_flatten_transform_from_property_tree_
: 1;
782 bool is_clipped_
: 1;
784 // Tracks if drawing-related properties have changed since last redraw.
785 bool layer_property_changed_
: 1;
787 bool masks_to_bounds_
: 1;
788 bool contents_opaque_
: 1;
789 bool is_root_for_isolated_group_
: 1;
790 bool use_parent_backface_visibility_
: 1;
791 bool draws_content_
: 1;
792 bool hide_layer_and_subtree_
: 1;
794 // Cache transform_'s invertibility.
795 bool transform_is_invertible_
: 1;
797 // Set for the layer that other layers are fixed to.
798 bool is_container_for_fixed_position_layers_
: 1;
800 bool is_affected_by_page_scale_
: 1;
802 Region non_fast_scrollable_region_
;
803 Region touch_event_handler_region_
;
804 SkColor background_color_
;
807 SkXfermode::Mode blend_mode_
;
808 // draw_blend_mode may be different than blend_mode_,
809 // when a RenderSurface re-parents the layer's blend_mode.
810 SkXfermode::Mode draw_blend_mode_
;
811 gfx::PointF position_
;
812 gfx::Transform transform_
;
814 LayerPositionConstraint position_constraint_
;
816 gfx::Vector2dF scroll_compensation_adjustment_
;
818 int num_descendants_that_draw_content_
;
820 gfx::Rect visible_rect_from_property_trees_
;
821 gfx::Rect clip_rect_in_target_space_from_property_trees_
;
822 int transform_tree_index_
;
823 int effect_tree_index_
;
824 int clip_tree_index_
;
826 // The global depth value of the center of the layer. This value is used
827 // to sort layers from back to front.
830 FilterOperations filters_
;
831 FilterOperations background_filters_
;
834 friend class TreeSynchronizer
;
836 // This flag is set when the layer needs to push properties to the active
838 bool needs_push_properties_
;
840 // The number of direct children or dependent layers that need to be recursed
841 // to in order for them or a descendent of them to push properties to the
843 int num_dependents_need_push_properties_
;
845 // Layers that share a sorting context id will be sorted together in 3d
846 // space. 0 is a special value that means this layer will not be sorted and
847 // will be drawn in paint order.
848 int sorting_context_id_
;
850 DrawMode current_draw_mode_
;
853 // Rect indicating what was repainted/updated during update.
854 // Note that plugin layers bypass this and leave it empty.
855 // Uses layer (not content) space.
856 gfx::Rect update_rect_
;
858 // This rect is in layer space.
859 gfx::RectF damage_rect_
;
861 // Manages animations for this layer.
862 scoped_refptr
<LayerAnimationController
> layer_animation_controller_
;
864 // Manages scrollbars for this layer
865 scoped_ptr
<ScrollbarAnimationController
> scrollbar_animation_controller_
;
867 scoped_ptr
<ScrollbarSet
> scrollbars_
;
869 ScopedPtrVector
<CopyOutputRequest
> copy_requests_
;
871 // Group of properties that need to be computed based on the layer tree
872 // hierarchy before layers can be drawn.
873 DrawProperties
<LayerImpl
> draw_properties_
;
875 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> debug_info_
;
876 scoped_ptr
<RenderSurfaceImpl
> render_surface_
;
878 std::vector
<FrameTimingRequest
> frame_timing_requests_
;
879 bool frame_timing_requests_dirty_
;
881 bool layer_or_descendant_is_drawn_
;
882 bool sorted_for_recursion_
;
884 DISALLOW_COPY_AND_ASSIGN(LayerImpl
);
889 #endif // CC_LAYERS_LAYER_IMPL_H_