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
;
60 template <typename LayerType
>
61 class OcclusionTracker
;
63 class PrioritizedTile
;
67 class ScrollbarAnimationController
;
68 class ScrollbarLayerImplBase
;
69 class SimpleEnclosedRegion
;
73 struct AppendQuadsData
;
79 DRAW_MODE_RESOURCELESS_SOFTWARE
82 class CC_EXPORT LayerImpl
: public LayerAnimationValueObserver
,
83 public LayerAnimationValueProvider
,
84 public AnimationDelegate
{
86 typedef SyncedProperty
<AdditionGroup
<gfx::ScrollOffset
>> SyncedScrollOffset
;
87 typedef LayerImplList RenderSurfaceListType
;
88 typedef LayerImplList LayerListType
;
89 typedef RenderSurfaceImpl RenderSurfaceType
;
91 enum RenderingContextConstants
{ NO_RENDERING_CONTEXT
= 0 };
93 static scoped_ptr
<LayerImpl
> Create(
94 LayerTreeImpl
* tree_impl
,
96 scoped_refptr
<SyncedScrollOffset
> scroll_offset
) {
97 return make_scoped_ptr(new LayerImpl(tree_impl
, id
, scroll_offset
));
100 static scoped_ptr
<LayerImpl
> Create(LayerTreeImpl
* tree_impl
, int id
) {
101 return make_scoped_ptr(new LayerImpl(tree_impl
, id
));
104 ~LayerImpl() override
;
106 int id() const { return layer_id_
; }
108 // LayerAnimationValueProvider implementation.
109 gfx::ScrollOffset
ScrollOffsetForAnimation() const override
;
111 // LayerAnimationValueObserver implementation.
112 void OnFilterAnimated(const FilterOperations
& filters
) override
;
113 void OnOpacityAnimated(float opacity
) override
;
114 void OnTransformAnimated(const gfx::Transform
& transform
) override
;
115 void OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) override
;
116 void OnAnimationWaitingForDeletion() 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 set_property_tree_sequence_number(int sequence_number
) {}
156 void SetTransformTreeIndex(int index
);
157 int transform_tree_index() const { return transform_tree_index_
; }
159 void SetClipTreeIndex(int index
);
160 int clip_tree_index() const { return clip_tree_index_
; }
162 void SetOpacityTreeIndex(int index
);
163 int opacity_tree_index() const { return opacity_tree_index_
; }
165 void set_offset_to_transform_parent(const gfx::Vector2dF
& offset
) {
166 offset_to_transform_parent_
= offset
;
167 SetNeedsPushProperties();
169 gfx::Vector2dF
offset_to_transform_parent() const {
170 return offset_to_transform_parent_
;
173 const gfx::Rect
& visible_rect_from_property_trees() const {
174 return visible_rect_from_property_trees_
;
176 void set_visible_rect_from_property_trees(const gfx::Rect
& rect
) {
177 visible_rect_from_property_trees_
= rect
;
180 void set_should_flatten_transform_from_property_tree(bool should_flatten
) {
181 should_flatten_transform_from_property_tree_
= should_flatten
;
182 SetNeedsPushProperties();
184 bool should_flatten_transform_from_property_tree() const {
185 return should_flatten_transform_from_property_tree_
;
188 void UpdatePropertyTreeTransform();
189 void UpdatePropertyTreeOpacity();
191 // For compatibility with Layer.
192 bool has_render_surface() const { return !!render_surface(); }
194 void SetNumDescendantsThatDrawContent(int num_descendants
);
195 void SetClipParent(LayerImpl
* ancestor
);
197 LayerImpl
* clip_parent() {
200 const LayerImpl
* clip_parent() const {
204 void SetClipChildren(std::set
<LayerImpl
*>* children
);
206 std::set
<LayerImpl
*>* clip_children() { return clip_children_
.get(); }
207 const std::set
<LayerImpl
*>* clip_children() const {
208 return clip_children_
.get();
211 void PassCopyRequests(ScopedPtrVector
<CopyOutputRequest
>* requests
);
212 // Can only be called when the layer has a copy request.
213 void TakeCopyRequestsAndTransformToTarget(
214 ScopedPtrVector
<CopyOutputRequest
>* request
);
215 bool HasCopyRequest() const { return !copy_requests_
.empty(); }
217 void SetMaskLayer(scoped_ptr
<LayerImpl
> mask_layer
);
218 LayerImpl
* mask_layer() { return mask_layer_
.get(); }
219 const LayerImpl
* mask_layer() const { return mask_layer_
.get(); }
220 scoped_ptr
<LayerImpl
> TakeMaskLayer();
222 void SetReplicaLayer(scoped_ptr
<LayerImpl
> replica_layer
);
223 LayerImpl
* replica_layer() { return replica_layer_
.get(); }
224 const LayerImpl
* replica_layer() const { return replica_layer_
.get(); }
225 scoped_ptr
<LayerImpl
> TakeReplicaLayer();
227 bool has_mask() const { return mask_layer_
; }
228 bool has_replica() const { return replica_layer_
; }
229 bool replica_has_mask() const {
230 return replica_layer_
&& (mask_layer_
|| replica_layer_
->mask_layer_
);
233 LayerTreeImpl
* layer_tree_impl() const { return layer_tree_impl_
; }
235 void PopulateSharedQuadState(SharedQuadState
* state
) const;
236 void PopulateScaledSharedQuadState(SharedQuadState
* state
, float scale
) const;
237 // WillDraw must be called before AppendQuads. If WillDraw returns false,
238 // AppendQuads and DidDraw will not be called. If WillDraw returns true,
239 // DidDraw is guaranteed to be called before another WillDraw or before
240 // the layer is destroyed. To enforce this, any class that overrides
241 // WillDraw/DidDraw must call the base class version only if WillDraw
243 virtual bool WillDraw(DrawMode draw_mode
,
244 ResourceProvider
* resource_provider
);
245 virtual void AppendQuads(RenderPass
* render_pass
,
246 AppendQuadsData
* append_quads_data
) {}
247 virtual void DidDraw(ResourceProvider
* resource_provider
);
249 // Verify that the resource ids in the quad are valid.
250 void ValidateQuadResources(DrawQuad
* quad
) const {
252 ValidateQuadResourcesInternal(quad
);
256 virtual void GetContentsResourceId(ResourceId
* resource_id
,
257 gfx::Size
* resource_size
) const;
259 virtual bool HasDelegatedContent() const;
260 virtual bool HasContributingDelegatedRenderPasses() const;
261 virtual RenderPassId
FirstContributingRenderPassId() const;
262 virtual RenderPassId
NextContributingRenderPassId(RenderPassId id
) const;
264 virtual void NotifyTileStateChanged(const Tile
* tile
) {}
266 virtual ScrollbarLayerImplBase
* ToScrollbarLayer();
268 // Returns true if this layer has content to draw.
269 void SetDrawsContent(bool draws_content
);
270 bool DrawsContent() const { return draws_content_
; }
272 int NumDescendantsThatDrawContent() const;
273 void SetHideLayerAndSubtree(bool hide
);
274 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_
; }
276 void SetTransformOrigin(const gfx::Point3F
& transform_origin
);
277 gfx::Point3F
transform_origin() const { return transform_origin_
; }
279 void SetBackgroundColor(SkColor background_color
);
280 SkColor
background_color() const { return background_color_
; }
281 // If contents_opaque(), return an opaque color else return a
282 // non-opaque color. Tries to return background_color(), if possible.
283 SkColor
SafeOpaqueBackgroundColor() const;
285 void SetFilters(const FilterOperations
& filters
);
286 const FilterOperations
& filters() const { return filters_
; }
287 bool FilterIsAnimating() const;
288 bool FilterIsAnimatingOnImplOnly() const;
290 void SetBackgroundFilters(const FilterOperations
& filters
);
291 const FilterOperations
& background_filters() const {
292 return background_filters_
;
295 void SetMasksToBounds(bool masks_to_bounds
);
296 bool masks_to_bounds() const { return masks_to_bounds_
; }
298 void SetContentsOpaque(bool opaque
);
299 bool contents_opaque() const { return contents_opaque_
; }
301 void SetOpacity(float opacity
);
302 float opacity() const { return opacity_
; }
303 bool OpacityIsAnimating() const;
304 bool OpacityIsAnimatingOnImplOnly() const;
306 void SetBlendMode(SkXfermode::Mode
);
307 SkXfermode::Mode
blend_mode() const { return blend_mode_
; }
308 bool uses_default_blend_mode() const {
309 return blend_mode_
== SkXfermode::kSrcOver_Mode
;
312 void SetIsRootForIsolatedGroup(bool root
);
313 bool is_root_for_isolated_group() const {
314 return is_root_for_isolated_group_
;
317 void SetPosition(const gfx::PointF
& position
);
318 gfx::PointF
position() const { return position_
; }
320 void SetIsContainerForFixedPositionLayers(bool container
) {
321 is_container_for_fixed_position_layers_
= container
;
323 // This is a non-trivial function in Layer.
324 bool IsContainerForFixedPositionLayers() const {
325 return is_container_for_fixed_position_layers_
;
328 gfx::Vector2dF
FixedContainerSizeDelta() const;
330 void SetPositionConstraint(const LayerPositionConstraint
& constraint
) {
331 position_constraint_
= constraint
;
333 const LayerPositionConstraint
& position_constraint() const {
334 return position_constraint_
;
337 void SetShouldFlattenTransform(bool flatten
);
338 bool should_flatten_transform() const { return should_flatten_transform_
; }
340 bool Is3dSorted() const { return sorting_context_id_
!= 0; }
342 void SetUseParentBackfaceVisibility(bool use
) {
343 use_parent_backface_visibility_
= use
;
345 bool use_parent_backface_visibility() const {
346 return use_parent_backface_visibility_
;
349 bool ShowDebugBorders() const;
351 // These invalidate the host's render surface layer list. The caller
352 // is responsible for calling set_needs_update_draw_properties on the tree
353 // so that its list can be recreated.
354 void ClearRenderSurfaceLayerList();
355 void SetHasRenderSurface(bool has_render_surface
);
357 RenderSurfaceImpl
* render_surface() const { return render_surface_
.get(); }
359 DrawProperties
<LayerImpl
>& draw_properties() {
360 return draw_properties_
;
362 const DrawProperties
<LayerImpl
>& draw_properties() const {
363 return draw_properties_
;
366 // The following are shortcut accessors to get various information from
368 const gfx::Transform
& draw_transform() const {
369 return draw_properties_
.target_space_transform
;
371 const gfx::Transform
& screen_space_transform() const {
372 return draw_properties_
.screen_space_transform
;
374 float draw_opacity() const { return draw_properties_
.opacity
; }
375 SkXfermode::Mode
draw_blend_mode() const {
376 return draw_properties_
.blend_mode
;
378 bool draw_opacity_is_animating() const {
379 return draw_properties_
.opacity_is_animating
;
381 bool draw_transform_is_animating() const {
382 return draw_properties_
.target_space_transform_is_animating
;
384 bool screen_space_transform_is_animating() const {
385 return draw_properties_
.screen_space_transform_is_animating
;
387 bool screen_space_opacity_is_animating() const {
388 return draw_properties_
.screen_space_opacity_is_animating
;
390 bool can_use_lcd_text() const { return draw_properties_
.can_use_lcd_text
; }
391 bool is_clipped() const { return draw_properties_
.is_clipped
; }
392 gfx::Rect
clip_rect() const { return draw_properties_
.clip_rect
; }
393 gfx::Rect
drawable_content_rect() const {
394 return draw_properties_
.drawable_content_rect
;
396 gfx::Rect
visible_content_rect() const {
397 return draw_properties_
.visible_content_rect
;
399 LayerImpl
* render_target() {
400 DCHECK(!draw_properties_
.render_target
||
401 draw_properties_
.render_target
->render_surface());
402 return draw_properties_
.render_target
;
404 const LayerImpl
* render_target() const {
405 DCHECK(!draw_properties_
.render_target
||
406 draw_properties_
.render_target
->render_surface());
407 return draw_properties_
.render_target
;
410 int num_unclipped_descendants() const {
411 return draw_properties_
.num_unclipped_descendants
;
414 // The client should be responsible for setting bounds, content bounds and
415 // contents scale to appropriate values. LayerImpl doesn't calculate any of
416 // them from the other values.
418 void SetBounds(const gfx::Size
& bounds
);
419 gfx::Size
bounds() const;
420 // Like bounds() but doesn't snap to int. Lossy on giant pages (e.g. millions
421 // of pixels) due to use of single precision float.
422 gfx::SizeF
BoundsForScrolling() const;
423 void SetBoundsDelta(const gfx::Vector2dF
& bounds_delta
);
424 gfx::Vector2dF
bounds_delta() const { return bounds_delta_
; }
426 void SetContentBounds(const gfx::Size
& content_bounds
);
427 gfx::Size
content_bounds() const { return draw_properties_
.content_bounds
; }
429 float contents_scale_x() const { return draw_properties_
.contents_scale_x
; }
430 float contents_scale_y() const { return draw_properties_
.contents_scale_y
; }
431 void SetContentsScale(float contents_scale_x
, float contents_scale_y
);
433 bool IsExternalFlingActive() const;
435 void SetCurrentScrollOffset(const gfx::ScrollOffset
& scroll_offset
);
436 void SetCurrentScrollOffsetFromDelegate(
437 const gfx::ScrollOffset
& scroll_offset
);
438 void PushScrollOffsetFromMainThread(const gfx::ScrollOffset
& scroll_offset
);
439 // This method is similar to PushScrollOffsetFromMainThread but will cause the
440 // scroll offset given to clobber any scroll changes on the active tree in the
441 // time until this value is pushed to the active tree.
442 void PushScrollOffsetFromMainThreadAndClobberActiveValue(
443 const gfx::ScrollOffset
& scroll_offset
);
444 gfx::ScrollOffset
PullDeltaForMainThread();
445 gfx::ScrollOffset
CurrentScrollOffset() const;
446 gfx::ScrollOffset
BaseScrollOffset() const;
447 gfx::Vector2dF
ScrollDelta() const;
448 void SetScrollDelta(const gfx::Vector2dF
& delta
);
450 gfx::ScrollOffset
MaxScrollOffset() const;
451 gfx::ScrollOffset
ClampScrollOffsetToLimits(gfx::ScrollOffset offset
) const;
452 gfx::Vector2dF
ClampScrollToMaxScrollOffset();
453 void SetScrollbarPosition(ScrollbarLayerImplBase
* scrollbar_layer
,
454 LayerImpl
* scrollbar_clip_layer
,
455 bool on_resize
) const;
456 void SetScrollCompensationAdjustment(const gfx::Vector2dF
& scroll_offset
) {
457 scroll_compensation_adjustment_
= scroll_offset
;
459 gfx::Vector2dF
ScrollCompensationAdjustment() const {
460 return scroll_compensation_adjustment_
;
463 // Returns the delta of the scroll that was outside of the bounds of the
465 gfx::Vector2dF
ScrollBy(const gfx::Vector2dF
& scroll
);
467 void SetScrollClipLayer(int scroll_clip_layer_id
);
468 LayerImpl
* scroll_clip_layer() const { return scroll_clip_layer_
; }
469 bool scrollable() const { return !!scroll_clip_layer_
; }
471 void set_user_scrollable_horizontal(bool scrollable
) {
472 user_scrollable_horizontal_
= scrollable
;
474 bool user_scrollable_horizontal() const {
475 return user_scrollable_horizontal_
;
477 void set_user_scrollable_vertical(bool scrollable
) {
478 user_scrollable_vertical_
= scrollable
;
480 bool user_scrollable_vertical() const { return user_scrollable_vertical_
; }
482 bool user_scrollable(ScrollbarOrientation orientation
) const;
484 void ApplySentScrollDeltasFromAbortedCommit();
486 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
487 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
489 bool should_scroll_on_main_thread() const {
490 return should_scroll_on_main_thread_
;
493 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
494 have_wheel_event_handlers_
= have_wheel_event_handlers
;
496 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_
; }
498 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
499 have_scroll_event_handlers_
= have_scroll_event_handlers
;
501 bool have_scroll_event_handlers() const {
502 return have_scroll_event_handlers_
;
505 void SetNonFastScrollableRegion(const Region
& region
) {
506 non_fast_scrollable_region_
= region
;
508 const Region
& non_fast_scrollable_region() const {
509 return non_fast_scrollable_region_
;
512 void SetTouchEventHandlerRegion(const Region
& region
) {
513 touch_event_handler_region_
= region
;
515 const Region
& touch_event_handler_region() const {
516 return touch_event_handler_region_
;
519 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
520 scroll_blocks_on_
= scroll_blocks_on
;
522 ScrollBlocksOn
scroll_blocks_on() const { return scroll_blocks_on_
; }
523 void SetDrawCheckerboardForMissingTiles(bool checkerboard
) {
524 draw_checkerboard_for_missing_tiles_
= checkerboard
;
526 bool draw_checkerboard_for_missing_tiles() const {
527 return draw_checkerboard_for_missing_tiles_
;
530 InputHandler::ScrollStatus
TryScroll(
531 const gfx::PointF
& screen_space_point
,
532 InputHandler::ScrollInputType type
,
533 ScrollBlocksOn effective_block_mode
) const;
535 void SetDoubleSided(bool double_sided
);
536 bool double_sided() const { return double_sided_
; }
538 void SetTransform(const gfx::Transform
& transform
);
539 const gfx::Transform
& transform() const { return transform_
; }
540 bool TransformIsAnimating() const;
541 bool TransformIsAnimatingOnImplOnly() const;
542 void SetTransformAndInvertibility(const gfx::Transform
& transform
,
543 bool transform_is_invertible
);
544 bool transform_is_invertible() const { return transform_is_invertible_
; }
546 // Note this rect is in layer space (not content space).
547 void SetUpdateRect(const gfx::Rect
& update_rect
);
548 gfx::Rect
update_rect() const { return update_rect_
; }
550 void AddDamageRect(const gfx::RectF
& damage_rect
);
552 const gfx::RectF
& damage_rect() const { return damage_rect_
; }
554 virtual base::DictionaryValue
* LayerTreeAsJson() const;
556 void SetStackingOrderChanged(bool stacking_order_changed
);
558 bool LayerPropertyChanged() const { return layer_property_changed_
; }
560 void ResetAllChangeTrackingForSubtree();
562 LayerAnimationController
* layer_animation_controller() {
563 return layer_animation_controller_
.get();
566 const LayerAnimationController
* layer_animation_controller() const {
567 return layer_animation_controller_
.get();
570 virtual SimpleEnclosedRegion
VisibleContentOpaqueRegion() const;
572 virtual void DidBecomeActive();
574 virtual void DidBeginTracing();
576 // Release resources held by this layer. Called when the output surface
577 // that rendered this layer was lost or a rendering mode switch has occured.
578 virtual void ReleaseResources();
580 // Recreate resources that are required after they were released by a
581 // ReleaseResources call.
582 virtual void RecreateResources();
584 ScrollbarAnimationController
* scrollbar_animation_controller() const {
585 return scrollbar_animation_controller_
.get();
588 typedef std::set
<ScrollbarLayerImplBase
*> ScrollbarSet
;
589 ScrollbarSet
* scrollbars() { return scrollbars_
.get(); }
590 void ClearScrollbars();
591 void AddScrollbar(ScrollbarLayerImplBase
* layer
);
592 void RemoveScrollbar(ScrollbarLayerImplBase
* layer
);
593 bool HasScrollbar(ScrollbarOrientation orientation
) const;
594 void ScrollbarParametersDidChange(bool on_resize
);
596 return scroll_clip_layer_
? scroll_clip_layer_
->bounds().height() : 0;
599 gfx::Rect
LayerRectToContentRect(const gfx::RectF
& layer_rect
) const;
601 virtual skia::RefPtr
<SkPicture
> GetPicture();
603 virtual scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
);
604 virtual void PushPropertiesTo(LayerImpl
* layer
);
606 virtual void GetAllPrioritizedTilesForTracing(
607 std::vector
<PrioritizedTile
>* prioritized_tiles
) const;
608 virtual void AsValueInto(base::trace_event::TracedValue
* dict
) const;
610 virtual size_t GPUMemoryUsageInBytes() const;
612 void SetNeedsPushProperties();
613 void AddDependentNeedsPushProperties();
614 void RemoveDependentNeedsPushProperties();
615 bool parent_should_know_need_push_properties() const {
616 return needs_push_properties() || descendant_needs_push_properties();
619 bool needs_push_properties() const { return needs_push_properties_
; }
620 bool descendant_needs_push_properties() const {
621 return num_dependents_need_push_properties_
> 0;
624 virtual void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
);
626 virtual void SetDebugInfo(
627 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> other
);
629 bool IsDrawnRenderSurfaceLayerListMember() const;
631 void Set3dSortingContextId(int id
);
632 int sorting_context_id() { return sorting_context_id_
; }
634 void PassFrameTimingRequests(
635 std::vector
<FrameTimingRequest
>* frame_timing_requests
);
636 const std::vector
<FrameTimingRequest
>& frame_timing_requests() const {
637 return frame_timing_requests_
;
639 void GatherFrameTimingRequestIds(std::vector
<int64_t>* request_ids
);
641 SyncedScrollOffset
* synced_scroll_offset() { return scroll_offset_
.get(); }
643 // Get the correct invalidation region instead of conservative Rect
644 // for layers that provide it.
645 virtual Region
GetInvalidationRegion();
647 virtual gfx::Rect
GetEnclosingRectInTargetSpace() const;
649 void set_visited(bool visited
) { visited_
= visited
; }
651 bool visited() { return visited_
; }
653 void set_layer_or_descendant_is_drawn(bool layer_or_descendant_is_drawn
) {
654 layer_or_descendant_is_drawn_
= layer_or_descendant_is_drawn
;
657 bool layer_or_descendant_is_drawn() { return layer_or_descendant_is_drawn_
; }
659 void set_sorted_for_recursion(bool sorted_for_recursion
) {
660 sorted_for_recursion_
= sorted_for_recursion
;
663 bool sorted_for_recursion() { return sorted_for_recursion_
; }
666 LayerImpl(LayerTreeImpl
* layer_impl
,
668 scoped_refptr
<SyncedScrollOffset
> scroll_offset
);
669 LayerImpl(LayerTreeImpl
* layer_impl
, int id
);
671 // Get the color and size of the layer's debug border.
672 virtual void GetDebugBorderProperties(SkColor
* color
, float* width
) const;
674 void AppendDebugBorderQuad(RenderPass
* render_pass
,
675 const gfx::Size
& content_bounds
,
676 const SharedQuadState
* shared_quad_state
,
677 AppendQuadsData
* append_quads_data
) const;
678 void AppendDebugBorderQuad(RenderPass
* render_pass
,
679 const gfx::Size
& content_bounds
,
680 const SharedQuadState
* shared_quad_state
,
681 AppendQuadsData
* append_quads_data
,
685 void NoteLayerPropertyChanged();
686 void NoteLayerPropertyChangedForSubtree();
688 // Note carefully this does not affect the current layer.
689 void NoteLayerPropertyChangedForDescendants();
691 gfx::Rect
GetScaledEnclosingRectInTargetSpace(float scale
) const;
694 void ValidateQuadResourcesInternal(DrawQuad
* quad
) const;
696 void PushScrollOffset(const gfx::ScrollOffset
* scroll_offset
);
697 // If the new scroll offset is assigned from the root scroll offset delegate,
698 // LayerImpl won't inform the root scroll offset delegate about the scroll
699 // change to avoid feedback.
700 void DidUpdateScrollOffset(bool is_from_root_delegate
);
701 void NoteLayerPropertyChangedForDescendantsInternal();
703 virtual const char* LayerTypeAsString() const;
705 // Properties internal to LayerImpl
707 OwnedLayerImplList children_
;
709 LayerImpl
* scroll_parent_
;
711 // Storing a pointer to a set rather than a set since this will be rarely
712 // used. If this pointer turns out to be too heavy, we could have this (and
713 // the scroll parent above) be stored in a LayerImpl -> scroll_info
715 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children_
;
717 LayerImpl
* clip_parent_
;
718 scoped_ptr
<std::set
<LayerImpl
*>> clip_children_
;
720 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
721 // confirm newly assigned layer is still the previous one
723 scoped_ptr
<LayerImpl
> mask_layer_
;
724 int replica_layer_id_
; // ditto
725 scoped_ptr
<LayerImpl
> replica_layer_
;
727 LayerTreeImpl
* layer_tree_impl_
;
729 // Properties dynamically changeable on active tree.
730 scoped_refptr
<SyncedScrollOffset
> scroll_offset_
;
731 gfx::Vector2dF bounds_delta_
;
733 // Properties synchronized from the associated Layer.
734 gfx::Point3F transform_origin_
;
736 LayerImpl
* scroll_clip_layer_
;
738 gfx::Vector2dF offset_to_transform_parent_
;
740 bool scrollable_
: 1;
741 bool should_scroll_on_main_thread_
: 1;
742 bool have_wheel_event_handlers_
: 1;
743 bool have_scroll_event_handlers_
: 1;
745 static_assert(SCROLL_BLOCKS_ON_MAX
< (1 << 3), "ScrollBlocksOn too big");
746 ScrollBlocksOn scroll_blocks_on_
: 3;
748 bool user_scrollable_horizontal_
: 1;
749 bool user_scrollable_vertical_
: 1;
750 bool stacking_order_changed_
: 1;
751 // Whether the "back" of this layer should draw.
752 bool double_sided_
: 1;
753 bool should_flatten_transform_
: 1;
754 bool should_flatten_transform_from_property_tree_
: 1;
756 // Tracks if drawing-related properties have changed since last redraw.
757 bool layer_property_changed_
: 1;
759 bool masks_to_bounds_
: 1;
760 bool contents_opaque_
: 1;
761 bool is_root_for_isolated_group_
: 1;
762 bool use_parent_backface_visibility_
: 1;
763 bool draw_checkerboard_for_missing_tiles_
: 1;
764 bool draws_content_
: 1;
765 bool hide_layer_and_subtree_
: 1;
767 // Cache transform_'s invertibility.
768 bool transform_is_invertible_
: 1;
770 // Set for the layer that other layers are fixed to.
771 bool is_container_for_fixed_position_layers_
: 1;
773 Region non_fast_scrollable_region_
;
774 Region touch_event_handler_region_
;
775 SkColor background_color_
;
778 SkXfermode::Mode blend_mode_
;
779 gfx::PointF position_
;
780 gfx::Transform transform_
;
782 LayerPositionConstraint position_constraint_
;
784 gfx::Vector2dF scroll_compensation_adjustment_
;
786 int num_descendants_that_draw_content_
;
788 gfx::Rect visible_rect_from_property_trees_
;
789 int transform_tree_index_
;
790 int opacity_tree_index_
;
791 int clip_tree_index_
;
793 // The global depth value of the center of the layer. This value is used
794 // to sort layers from back to front.
797 FilterOperations filters_
;
798 FilterOperations background_filters_
;
801 friend class TreeSynchronizer
;
803 // This flag is set when the layer needs to push properties to the active
805 bool needs_push_properties_
;
807 // The number of direct children or dependent layers that need to be recursed
808 // to in order for them or a descendent of them to push properties to the
810 int num_dependents_need_push_properties_
;
812 // Layers that share a sorting context id will be sorted together in 3d
813 // space. 0 is a special value that means this layer will not be sorted and
814 // will be drawn in paint order.
815 int sorting_context_id_
;
817 DrawMode current_draw_mode_
;
820 // Rect indicating what was repainted/updated during update.
821 // Note that plugin layers bypass this and leave it empty.
822 // Uses layer (not content) space.
823 gfx::Rect update_rect_
;
825 // This rect is in layer space.
826 gfx::RectF damage_rect_
;
828 // Manages animations for this layer.
829 scoped_refptr
<LayerAnimationController
> layer_animation_controller_
;
831 // Manages scrollbars for this layer
832 scoped_ptr
<ScrollbarAnimationController
> scrollbar_animation_controller_
;
834 scoped_ptr
<ScrollbarSet
> scrollbars_
;
836 ScopedPtrVector
<CopyOutputRequest
> copy_requests_
;
838 // Group of properties that need to be computed based on the layer tree
839 // hierarchy before layers can be drawn.
840 DrawProperties
<LayerImpl
> draw_properties_
;
842 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> debug_info_
;
843 scoped_ptr
<RenderSurfaceImpl
> render_surface_
;
845 std::vector
<FrameTimingRequest
> frame_timing_requests_
;
846 bool frame_timing_requests_dirty_
;
848 bool layer_or_descendant_is_drawn_
;
849 bool sorted_for_recursion_
;
851 DISALLOW_COPY_AND_ASSIGN(LayerImpl
);
856 #endif // CC_LAYERS_LAYER_IMPL_H_