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
;
71 struct AppendQuadsData
;
77 DRAW_MODE_RESOURCELESS_SOFTWARE
80 class CC_EXPORT LayerImpl
: public LayerAnimationValueObserver
,
81 public LayerAnimationValueProvider
,
82 public AnimationDelegate
{
84 typedef SyncedProperty
<AdditionGroup
<gfx::ScrollOffset
>> SyncedScrollOffset
;
85 typedef LayerImplList RenderSurfaceListType
;
86 typedef LayerImplList LayerListType
;
87 typedef RenderSurfaceImpl RenderSurfaceType
;
89 enum RenderingContextConstants
{ NO_RENDERING_CONTEXT
= 0 };
91 static scoped_ptr
<LayerImpl
> Create(
92 LayerTreeImpl
* tree_impl
,
94 scoped_refptr
<SyncedScrollOffset
> scroll_offset
) {
95 return make_scoped_ptr(new LayerImpl(tree_impl
, id
, scroll_offset
));
98 static scoped_ptr
<LayerImpl
> Create(LayerTreeImpl
* tree_impl
, int id
) {
99 return make_scoped_ptr(new LayerImpl(tree_impl
, id
));
102 ~LayerImpl() override
;
104 int id() const { return layer_id_
; }
106 // LayerAnimationValueProvider implementation.
107 gfx::ScrollOffset
ScrollOffsetForAnimation() const override
;
109 // LayerAnimationValueObserver implementation.
110 void OnFilterAnimated(const FilterOperations
& filters
) override
;
111 void OnOpacityAnimated(float opacity
) override
;
112 void OnTransformAnimated(const gfx::Transform
& transform
) override
;
113 void OnScrollOffsetAnimated(const gfx::ScrollOffset
& scroll_offset
) override
;
114 void OnAnimationWaitingForDeletion() override
;
115 bool IsActive() const override
;
117 // AnimationDelegate implementation.
118 void NotifyAnimationStarted(base::TimeTicks monotonic_time
,
119 Animation::TargetProperty target_property
,
120 int group
) override
{};
121 void NotifyAnimationFinished(base::TimeTicks monotonic_time
,
122 Animation::TargetProperty target_property
,
126 LayerImpl
* parent() { return parent_
; }
127 const LayerImpl
* parent() const { return parent_
; }
128 const OwnedLayerImplList
& children() const { return children_
; }
129 OwnedLayerImplList
& children() { return children_
; }
130 LayerImpl
* child_at(size_t index
) const { return children_
[index
]; }
131 void AddChild(scoped_ptr
<LayerImpl
> child
);
132 scoped_ptr
<LayerImpl
> RemoveChild(LayerImpl
* child
);
133 void SetParent(LayerImpl
* parent
);
135 // Warning: This does not preserve tree structure invariants.
136 void ClearChildList();
138 bool HasAncestor(const LayerImpl
* ancestor
) const;
140 void SetScrollParent(LayerImpl
* parent
);
142 LayerImpl
* scroll_parent() { return scroll_parent_
; }
143 const LayerImpl
* scroll_parent() const { return scroll_parent_
; }
145 void SetScrollChildren(std::set
<LayerImpl
*>* children
);
147 std::set
<LayerImpl
*>* scroll_children() { return scroll_children_
.get(); }
148 const std::set
<LayerImpl
*>* scroll_children() const {
149 return scroll_children_
.get();
152 void set_property_tree_sequence_number(int sequence_number
) {}
154 void SetTransformTreeIndex(int index
);
155 int transform_tree_index() const { return transform_tree_index_
; }
157 void SetClipTreeIndex(int index
);
158 int clip_tree_index() const { return clip_tree_index_
; }
160 void SetOpacityTreeIndex(int index
);
161 int opacity_tree_index() const { return opacity_tree_index_
; }
163 void set_offset_to_transform_parent(const gfx::Vector2dF
& offset
) {
164 offset_to_transform_parent_
= offset
;
165 SetNeedsPushProperties();
167 gfx::Vector2dF
offset_to_transform_parent() const {
168 return offset_to_transform_parent_
;
171 const gfx::Rect
& visible_rect_from_property_trees() const {
172 return visible_rect_from_property_trees_
;
174 void set_visible_rect_from_property_trees(const gfx::Rect
& rect
) {
175 visible_rect_from_property_trees_
= rect
;
178 void set_should_flatten_transform_from_property_tree(bool should_flatten
) {
179 should_flatten_transform_from_property_tree_
= should_flatten
;
180 SetNeedsPushProperties();
182 bool should_flatten_transform_from_property_tree() const {
183 return should_flatten_transform_from_property_tree_
;
186 void UpdatePropertyTreeTransform();
187 void UpdatePropertyTreeOpacity();
189 // For compatibility with Layer.
190 bool has_render_surface() const { return !!render_surface(); }
192 void SetNumDescendantsThatDrawContent(int num_descendants
);
193 void SetClipParent(LayerImpl
* ancestor
);
195 LayerImpl
* clip_parent() {
198 const LayerImpl
* clip_parent() const {
202 void SetClipChildren(std::set
<LayerImpl
*>* children
);
204 std::set
<LayerImpl
*>* clip_children() { return clip_children_
.get(); }
205 const std::set
<LayerImpl
*>* clip_children() const {
206 return clip_children_
.get();
209 void PassCopyRequests(ScopedPtrVector
<CopyOutputRequest
>* requests
);
210 // Can only be called when the layer has a copy request.
211 void TakeCopyRequestsAndTransformToTarget(
212 ScopedPtrVector
<CopyOutputRequest
>* request
);
213 bool HasCopyRequest() const { return !copy_requests_
.empty(); }
215 void SetMaskLayer(scoped_ptr
<LayerImpl
> mask_layer
);
216 LayerImpl
* mask_layer() { return mask_layer_
.get(); }
217 const LayerImpl
* mask_layer() const { return mask_layer_
.get(); }
218 scoped_ptr
<LayerImpl
> TakeMaskLayer();
220 void SetReplicaLayer(scoped_ptr
<LayerImpl
> replica_layer
);
221 LayerImpl
* replica_layer() { return replica_layer_
.get(); }
222 const LayerImpl
* replica_layer() const { return replica_layer_
.get(); }
223 scoped_ptr
<LayerImpl
> TakeReplicaLayer();
225 bool has_mask() const { return mask_layer_
; }
226 bool has_replica() const { return replica_layer_
; }
227 bool replica_has_mask() const {
228 return replica_layer_
&& (mask_layer_
|| replica_layer_
->mask_layer_
);
231 LayerTreeImpl
* layer_tree_impl() const { return layer_tree_impl_
; }
233 void PopulateSharedQuadState(SharedQuadState
* state
) const;
234 void PopulateScaledSharedQuadState(SharedQuadState
* state
, float scale
) const;
235 // WillDraw must be called before AppendQuads. If WillDraw returns false,
236 // AppendQuads and DidDraw will not be called. If WillDraw returns true,
237 // DidDraw is guaranteed to be called before another WillDraw or before
238 // the layer is destroyed. To enforce this, any class that overrides
239 // WillDraw/DidDraw must call the base class version only if WillDraw
241 virtual bool WillDraw(DrawMode draw_mode
,
242 ResourceProvider
* resource_provider
);
243 virtual void AppendQuads(RenderPass
* render_pass
,
244 AppendQuadsData
* append_quads_data
) {}
245 virtual void DidDraw(ResourceProvider
* resource_provider
);
247 // Verify that the resource ids in the quad are valid.
248 void ValidateQuadResources(DrawQuad
* quad
) const {
250 ValidateQuadResourcesInternal(quad
);
254 virtual void GetContentsResourceId(ResourceId
* resource_id
,
255 gfx::Size
* resource_size
) const;
257 virtual bool HasDelegatedContent() const;
258 virtual bool HasContributingDelegatedRenderPasses() const;
259 virtual RenderPassId
FirstContributingRenderPassId() const;
260 virtual RenderPassId
NextContributingRenderPassId(RenderPassId id
) const;
262 virtual void NotifyTileStateChanged(const Tile
* tile
) {}
264 virtual ScrollbarLayerImplBase
* ToScrollbarLayer();
266 // Returns true if this layer has content to draw.
267 void SetDrawsContent(bool draws_content
);
268 bool DrawsContent() const { return draws_content_
; }
270 int NumDescendantsThatDrawContent() const;
271 void SetHideLayerAndSubtree(bool hide
);
272 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_
; }
274 void SetTransformOrigin(const gfx::Point3F
& transform_origin
);
275 gfx::Point3F
transform_origin() const { return transform_origin_
; }
277 void SetBackgroundColor(SkColor background_color
);
278 SkColor
background_color() const { return background_color_
; }
279 // If contents_opaque(), return an opaque color else return a
280 // non-opaque color. Tries to return background_color(), if possible.
281 SkColor
SafeOpaqueBackgroundColor() const;
283 void SetFilters(const FilterOperations
& filters
);
284 const FilterOperations
& filters() const { return filters_
; }
285 bool FilterIsAnimating() const;
286 bool FilterIsAnimatingOnImplOnly() const;
288 void SetBackgroundFilters(const FilterOperations
& filters
);
289 const FilterOperations
& background_filters() const {
290 return background_filters_
;
293 void SetMasksToBounds(bool masks_to_bounds
);
294 bool masks_to_bounds() const { return masks_to_bounds_
; }
296 void SetContentsOpaque(bool opaque
);
297 bool contents_opaque() const { return contents_opaque_
; }
299 void SetOpacity(float opacity
);
300 float opacity() const { return opacity_
; }
301 bool OpacityIsAnimating() const;
302 bool OpacityIsAnimatingOnImplOnly() const;
304 void SetBlendMode(SkXfermode::Mode
);
305 SkXfermode::Mode
blend_mode() const { return blend_mode_
; }
306 bool uses_default_blend_mode() const {
307 return blend_mode_
== SkXfermode::kSrcOver_Mode
;
310 void SetIsRootForIsolatedGroup(bool root
);
311 bool is_root_for_isolated_group() const {
312 return is_root_for_isolated_group_
;
315 void SetPosition(const gfx::PointF
& position
);
316 gfx::PointF
position() const { return position_
; }
318 void SetIsContainerForFixedPositionLayers(bool container
) {
319 is_container_for_fixed_position_layers_
= container
;
321 // This is a non-trivial function in Layer.
322 bool IsContainerForFixedPositionLayers() const {
323 return is_container_for_fixed_position_layers_
;
326 gfx::Vector2dF
FixedContainerSizeDelta() const;
328 void SetPositionConstraint(const LayerPositionConstraint
& constraint
) {
329 position_constraint_
= constraint
;
331 const LayerPositionConstraint
& position_constraint() const {
332 return position_constraint_
;
335 void SetShouldFlattenTransform(bool flatten
);
336 bool should_flatten_transform() const { return should_flatten_transform_
; }
338 bool Is3dSorted() const { return sorting_context_id_
!= 0; }
340 void SetUseParentBackfaceVisibility(bool use
) {
341 use_parent_backface_visibility_
= use
;
343 bool use_parent_backface_visibility() const {
344 return use_parent_backface_visibility_
;
347 bool ShowDebugBorders() const;
349 // These invalidate the host's render surface layer list. The caller
350 // is responsible for calling set_needs_update_draw_properties on the tree
351 // so that its list can be recreated.
352 void ClearRenderSurfaceLayerList();
353 void SetHasRenderSurface(bool has_render_surface
);
355 RenderSurfaceImpl
* render_surface() const { return render_surface_
.get(); }
357 DrawProperties
<LayerImpl
>& draw_properties() {
358 return draw_properties_
;
360 const DrawProperties
<LayerImpl
>& draw_properties() const {
361 return draw_properties_
;
364 // The following are shortcut accessors to get various information from
366 const gfx::Transform
& draw_transform() const {
367 return draw_properties_
.target_space_transform
;
369 const gfx::Transform
& screen_space_transform() const {
370 return draw_properties_
.screen_space_transform
;
372 float draw_opacity() const { return draw_properties_
.opacity
; }
373 SkXfermode::Mode
draw_blend_mode() const {
374 return draw_properties_
.blend_mode
;
376 bool draw_opacity_is_animating() const {
377 return draw_properties_
.opacity_is_animating
;
379 bool draw_transform_is_animating() const {
380 return draw_properties_
.target_space_transform_is_animating
;
382 bool screen_space_transform_is_animating() const {
383 return draw_properties_
.screen_space_transform_is_animating
;
385 bool screen_space_opacity_is_animating() const {
386 return draw_properties_
.screen_space_opacity_is_animating
;
388 bool can_use_lcd_text() const { return draw_properties_
.can_use_lcd_text
; }
389 bool is_clipped() const { return draw_properties_
.is_clipped
; }
390 gfx::Rect
clip_rect() const { return draw_properties_
.clip_rect
; }
391 gfx::Rect
drawable_content_rect() const {
392 return draw_properties_
.drawable_content_rect
;
394 gfx::Rect
visible_layer_rect() const {
395 return draw_properties_
.visible_layer_rect
;
397 LayerImpl
* render_target() {
398 DCHECK(!draw_properties_
.render_target
||
399 draw_properties_
.render_target
->render_surface());
400 return draw_properties_
.render_target
;
402 const LayerImpl
* render_target() const {
403 DCHECK(!draw_properties_
.render_target
||
404 draw_properties_
.render_target
->render_surface());
405 return draw_properties_
.render_target
;
408 size_t num_unclipped_descendants() const {
409 return draw_properties_
.num_unclipped_descendants
;
412 // The client should be responsible for setting bounds, content bounds and
413 // contents scale to appropriate values. LayerImpl doesn't calculate any of
414 // them from the other values.
416 void SetBounds(const gfx::Size
& bounds
);
417 gfx::Size
bounds() const;
418 // Like bounds() but doesn't snap to int. Lossy on giant pages (e.g. millions
419 // of pixels) due to use of single precision float.
420 gfx::SizeF
BoundsForScrolling() const;
421 void SetBoundsDelta(const gfx::Vector2dF
& bounds_delta
);
422 gfx::Vector2dF
bounds_delta() const { return bounds_delta_
; }
424 bool IsExternalScrollActive() const;
426 void SetCurrentScrollOffset(const gfx::ScrollOffset
& scroll_offset
);
427 void SetCurrentScrollOffsetFromDelegate(
428 const gfx::ScrollOffset
& scroll_offset
);
429 void PushScrollOffsetFromMainThread(const gfx::ScrollOffset
& scroll_offset
);
430 // This method is similar to PushScrollOffsetFromMainThread but will cause the
431 // scroll offset given to clobber any scroll changes on the active tree in the
432 // time until this value is pushed to the active tree.
433 void PushScrollOffsetFromMainThreadAndClobberActiveValue(
434 const gfx::ScrollOffset
& scroll_offset
);
435 gfx::ScrollOffset
PullDeltaForMainThread();
436 gfx::ScrollOffset
CurrentScrollOffset() const;
437 gfx::ScrollOffset
BaseScrollOffset() const;
438 gfx::Vector2dF
ScrollDelta() const;
439 void SetScrollDelta(const gfx::Vector2dF
& delta
);
441 gfx::ScrollOffset
MaxScrollOffset() const;
442 gfx::ScrollOffset
ClampScrollOffsetToLimits(gfx::ScrollOffset offset
) const;
443 gfx::Vector2dF
ClampScrollToMaxScrollOffset();
444 void SetScrollbarPosition(ScrollbarLayerImplBase
* scrollbar_layer
,
445 LayerImpl
* scrollbar_clip_layer
,
446 bool on_resize
) const;
447 void SetScrollCompensationAdjustment(const gfx::Vector2dF
& scroll_offset
) {
448 scroll_compensation_adjustment_
= scroll_offset
;
450 gfx::Vector2dF
ScrollCompensationAdjustment() const {
451 return scroll_compensation_adjustment_
;
454 // Returns the delta of the scroll that was outside of the bounds of the
456 gfx::Vector2dF
ScrollBy(const gfx::Vector2dF
& scroll
);
458 void SetScrollClipLayer(int scroll_clip_layer_id
);
459 LayerImpl
* scroll_clip_layer() const { return scroll_clip_layer_
; }
460 bool scrollable() const { return !!scroll_clip_layer_
; }
462 void set_user_scrollable_horizontal(bool scrollable
) {
463 user_scrollable_horizontal_
= scrollable
;
465 bool user_scrollable_horizontal() const {
466 return user_scrollable_horizontal_
;
468 void set_user_scrollable_vertical(bool scrollable
) {
469 user_scrollable_vertical_
= scrollable
;
471 bool user_scrollable_vertical() const { return user_scrollable_vertical_
; }
473 bool user_scrollable(ScrollbarOrientation orientation
) const;
475 void ApplySentScrollDeltasFromAbortedCommit();
477 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
478 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
480 bool should_scroll_on_main_thread() const {
481 return should_scroll_on_main_thread_
;
484 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
485 have_wheel_event_handlers_
= have_wheel_event_handlers
;
487 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_
; }
489 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
490 have_scroll_event_handlers_
= have_scroll_event_handlers
;
492 bool have_scroll_event_handlers() const {
493 return have_scroll_event_handlers_
;
496 void SetNonFastScrollableRegion(const Region
& region
) {
497 non_fast_scrollable_region_
= region
;
499 const Region
& non_fast_scrollable_region() const {
500 return non_fast_scrollable_region_
;
503 void SetTouchEventHandlerRegion(const Region
& region
) {
504 touch_event_handler_region_
= region
;
506 const Region
& touch_event_handler_region() const {
507 return touch_event_handler_region_
;
510 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
511 scroll_blocks_on_
= scroll_blocks_on
;
513 ScrollBlocksOn
scroll_blocks_on() const { return scroll_blocks_on_
; }
514 void SetDrawCheckerboardForMissingTiles(bool checkerboard
) {
515 draw_checkerboard_for_missing_tiles_
= checkerboard
;
517 bool draw_checkerboard_for_missing_tiles() const {
518 return draw_checkerboard_for_missing_tiles_
;
521 InputHandler::ScrollStatus
TryScroll(
522 const gfx::PointF
& screen_space_point
,
523 InputHandler::ScrollInputType type
,
524 ScrollBlocksOn effective_block_mode
) const;
526 void SetDoubleSided(bool double_sided
);
527 bool double_sided() const { return double_sided_
; }
529 void SetTransform(const gfx::Transform
& transform
);
530 const gfx::Transform
& transform() const { return transform_
; }
531 bool TransformIsAnimating() const;
532 bool TransformIsAnimatingOnImplOnly() const;
533 void SetTransformAndInvertibility(const gfx::Transform
& transform
,
534 bool transform_is_invertible
);
535 bool transform_is_invertible() const { return transform_is_invertible_
; }
537 // Note this rect is in layer space (not content space).
538 void SetUpdateRect(const gfx::Rect
& update_rect
);
539 gfx::Rect
update_rect() const { return update_rect_
; }
541 void AddDamageRect(const gfx::RectF
& damage_rect
);
543 const gfx::RectF
& damage_rect() const { return damage_rect_
; }
545 virtual base::DictionaryValue
* LayerTreeAsJson() const;
547 void SetStackingOrderChanged(bool stacking_order_changed
);
549 bool LayerPropertyChanged() const { return layer_property_changed_
; }
551 void ResetAllChangeTrackingForSubtree();
553 LayerAnimationController
* layer_animation_controller() {
554 return layer_animation_controller_
.get();
557 const LayerAnimationController
* layer_animation_controller() const {
558 return layer_animation_controller_
.get();
561 virtual SimpleEnclosedRegion
VisibleOpaqueRegion() const;
563 virtual void DidBecomeActive();
565 virtual void DidBeginTracing();
567 // Release resources held by this layer. Called when the output surface
568 // that rendered this layer was lost or a rendering mode switch has occured.
569 virtual void ReleaseResources();
571 // Recreate resources that are required after they were released by a
572 // ReleaseResources call.
573 virtual void RecreateResources();
575 ScrollbarAnimationController
* scrollbar_animation_controller() const {
576 return scrollbar_animation_controller_
.get();
579 typedef std::set
<ScrollbarLayerImplBase
*> ScrollbarSet
;
580 ScrollbarSet
* scrollbars() { return scrollbars_
.get(); }
581 void ClearScrollbars();
582 void AddScrollbar(ScrollbarLayerImplBase
* layer
);
583 void RemoveScrollbar(ScrollbarLayerImplBase
* layer
);
584 bool HasScrollbar(ScrollbarOrientation orientation
) const;
585 void ScrollbarParametersDidChange(bool on_resize
);
587 return scroll_clip_layer_
? scroll_clip_layer_
->bounds().height() : 0;
590 virtual skia::RefPtr
<SkPicture
> GetPicture();
592 virtual scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
);
593 virtual void PushPropertiesTo(LayerImpl
* layer
);
595 virtual void GetAllPrioritizedTilesForTracing(
596 std::vector
<PrioritizedTile
>* prioritized_tiles
) const;
597 virtual void AsValueInto(base::trace_event::TracedValue
* dict
) const;
599 virtual size_t GPUMemoryUsageInBytes() const;
601 void SetNeedsPushProperties();
602 void AddDependentNeedsPushProperties();
603 void RemoveDependentNeedsPushProperties();
604 bool parent_should_know_need_push_properties() const {
605 return needs_push_properties() || descendant_needs_push_properties();
608 bool needs_push_properties() const { return needs_push_properties_
; }
609 bool descendant_needs_push_properties() const {
610 return num_dependents_need_push_properties_
> 0;
613 virtual void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
);
615 virtual void SetDebugInfo(
616 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> other
);
618 bool IsDrawnRenderSurfaceLayerListMember() const;
620 void Set3dSortingContextId(int id
);
621 int sorting_context_id() { return sorting_context_id_
; }
623 void SetFrameTimingRequests(
624 const std::vector
<FrameTimingRequest
>& frame_timing_requests
);
625 const std::vector
<FrameTimingRequest
>& frame_timing_requests() const {
626 return frame_timing_requests_
;
628 void GatherFrameTimingRequestIds(std::vector
<int64_t>* request_ids
);
630 SyncedScrollOffset
* synced_scroll_offset() { return scroll_offset_
.get(); }
632 // Get the correct invalidation region instead of conservative Rect
633 // for layers that provide it.
634 virtual Region
GetInvalidationRegion();
636 virtual gfx::Rect
GetEnclosingRectInTargetSpace() const;
638 void set_visited(bool visited
) { visited_
= visited
; }
640 bool visited() { return visited_
; }
642 void set_layer_or_descendant_is_drawn(bool layer_or_descendant_is_drawn
) {
643 layer_or_descendant_is_drawn_
= layer_or_descendant_is_drawn
;
646 bool layer_or_descendant_is_drawn() { return layer_or_descendant_is_drawn_
; }
648 void set_sorted_for_recursion(bool sorted_for_recursion
) {
649 sorted_for_recursion_
= sorted_for_recursion
;
652 bool sorted_for_recursion() { return sorted_for_recursion_
; }
654 void UpdatePropertyTreeForScrollingIfNeeded();
657 LayerImpl(LayerTreeImpl
* layer_impl
,
659 scoped_refptr
<SyncedScrollOffset
> scroll_offset
);
660 LayerImpl(LayerTreeImpl
* layer_impl
, int id
);
662 // Get the color and size of the layer's debug border.
663 virtual void GetDebugBorderProperties(SkColor
* color
, float* width
) const;
665 void AppendDebugBorderQuad(RenderPass
* render_pass
,
666 const gfx::Size
& bounds
,
667 const SharedQuadState
* shared_quad_state
,
668 AppendQuadsData
* append_quads_data
) const;
669 void AppendDebugBorderQuad(RenderPass
* render_pass
,
670 const gfx::Size
& bounds
,
671 const SharedQuadState
* shared_quad_state
,
672 AppendQuadsData
* append_quads_data
,
676 void NoteLayerPropertyChanged();
677 void NoteLayerPropertyChangedForSubtree();
679 // Note carefully this does not affect the current layer.
680 void NoteLayerPropertyChangedForDescendants();
682 gfx::Rect
GetScaledEnclosingRectInTargetSpace(float scale
) const;
685 void ValidateQuadResourcesInternal(DrawQuad
* quad
) const;
687 void PushScrollOffset(const gfx::ScrollOffset
* scroll_offset
);
688 // If the new scroll offset is assigned from the root scroll offset delegate,
689 // LayerImpl won't inform the root scroll offset delegate about the scroll
690 // change to avoid feedback.
691 void DidUpdateScrollOffset(bool is_from_root_delegate
);
692 void NoteLayerPropertyChangedForDescendantsInternal();
694 virtual const char* LayerTypeAsString() const;
696 // Properties internal to LayerImpl
698 OwnedLayerImplList children_
;
700 LayerImpl
* scroll_parent_
;
702 // Storing a pointer to a set rather than a set since this will be rarely
703 // used. If this pointer turns out to be too heavy, we could have this (and
704 // the scroll parent above) be stored in a LayerImpl -> scroll_info
706 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children_
;
708 LayerImpl
* clip_parent_
;
709 scoped_ptr
<std::set
<LayerImpl
*>> clip_children_
;
711 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
712 // confirm newly assigned layer is still the previous one
714 scoped_ptr
<LayerImpl
> mask_layer_
;
715 int replica_layer_id_
; // ditto
716 scoped_ptr
<LayerImpl
> replica_layer_
;
718 LayerTreeImpl
* layer_tree_impl_
;
720 // Properties dynamically changeable on active tree.
721 scoped_refptr
<SyncedScrollOffset
> scroll_offset_
;
722 gfx::Vector2dF bounds_delta_
;
724 // Properties synchronized from the associated Layer.
725 gfx::Point3F transform_origin_
;
727 LayerImpl
* scroll_clip_layer_
;
729 gfx::Vector2dF offset_to_transform_parent_
;
731 bool scrollable_
: 1;
732 bool should_scroll_on_main_thread_
: 1;
733 bool have_wheel_event_handlers_
: 1;
734 bool have_scroll_event_handlers_
: 1;
736 static_assert(SCROLL_BLOCKS_ON_MAX
< (1 << 3), "ScrollBlocksOn too big");
737 ScrollBlocksOn scroll_blocks_on_
: 3;
739 bool user_scrollable_horizontal_
: 1;
740 bool user_scrollable_vertical_
: 1;
741 bool stacking_order_changed_
: 1;
742 // Whether the "back" of this layer should draw.
743 bool double_sided_
: 1;
744 bool should_flatten_transform_
: 1;
745 bool should_flatten_transform_from_property_tree_
: 1;
747 // Tracks if drawing-related properties have changed since last redraw.
748 bool layer_property_changed_
: 1;
750 bool masks_to_bounds_
: 1;
751 bool contents_opaque_
: 1;
752 bool is_root_for_isolated_group_
: 1;
753 bool use_parent_backface_visibility_
: 1;
754 bool draw_checkerboard_for_missing_tiles_
: 1;
755 bool draws_content_
: 1;
756 bool hide_layer_and_subtree_
: 1;
758 // Cache transform_'s invertibility.
759 bool transform_is_invertible_
: 1;
761 // Set for the layer that other layers are fixed to.
762 bool is_container_for_fixed_position_layers_
: 1;
764 Region non_fast_scrollable_region_
;
765 Region touch_event_handler_region_
;
766 SkColor background_color_
;
769 SkXfermode::Mode blend_mode_
;
770 gfx::PointF position_
;
771 gfx::Transform transform_
;
773 LayerPositionConstraint position_constraint_
;
775 gfx::Vector2dF scroll_compensation_adjustment_
;
777 int num_descendants_that_draw_content_
;
779 gfx::Rect visible_rect_from_property_trees_
;
780 int transform_tree_index_
;
781 int opacity_tree_index_
;
782 int clip_tree_index_
;
784 // The global depth value of the center of the layer. This value is used
785 // to sort layers from back to front.
788 FilterOperations filters_
;
789 FilterOperations background_filters_
;
792 friend class TreeSynchronizer
;
794 // This flag is set when the layer needs to push properties to the active
796 bool needs_push_properties_
;
798 // The number of direct children or dependent layers that need to be recursed
799 // to in order for them or a descendent of them to push properties to the
801 int num_dependents_need_push_properties_
;
803 // Layers that share a sorting context id will be sorted together in 3d
804 // space. 0 is a special value that means this layer will not be sorted and
805 // will be drawn in paint order.
806 int sorting_context_id_
;
808 DrawMode current_draw_mode_
;
811 // Rect indicating what was repainted/updated during update.
812 // Note that plugin layers bypass this and leave it empty.
813 // Uses layer (not content) space.
814 gfx::Rect update_rect_
;
816 // This rect is in layer space.
817 gfx::RectF damage_rect_
;
819 // Manages animations for this layer.
820 scoped_refptr
<LayerAnimationController
> layer_animation_controller_
;
822 // Manages scrollbars for this layer
823 scoped_ptr
<ScrollbarAnimationController
> scrollbar_animation_controller_
;
825 scoped_ptr
<ScrollbarSet
> scrollbars_
;
827 ScopedPtrVector
<CopyOutputRequest
> copy_requests_
;
829 // Group of properties that need to be computed based on the layer tree
830 // hierarchy before layers can be drawn.
831 DrawProperties
<LayerImpl
> draw_properties_
;
833 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> debug_info_
;
834 scoped_ptr
<RenderSurfaceImpl
> render_surface_
;
836 std::vector
<FrameTimingRequest
> frame_timing_requests_
;
837 bool frame_timing_requests_dirty_
;
839 bool layer_or_descendant_is_drawn_
;
840 bool sorted_for_recursion_
;
842 DISALLOW_COPY_AND_ASSIGN(LayerImpl
);
847 #endif // CC_LAYERS_LAYER_IMPL_H_