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/resources/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_transform_tree_index(int index
) {
155 transform_tree_index_
= index
;
156 SetNeedsPushProperties();
158 void set_clip_tree_index(int index
) {
159 clip_tree_index_
= index
;
160 SetNeedsPushProperties();
162 void set_opacity_tree_index(int index
) {
163 opacity_tree_index_
= index
;
164 SetNeedsPushProperties();
166 int clip_tree_index() const { return clip_tree_index_
; }
167 int transform_tree_index() const { return transform_tree_index_
; }
168 int opacity_tree_index() const { return opacity_tree_index_
; }
170 void set_offset_to_transform_parent(const gfx::Vector2dF
& offset
) {
171 offset_to_transform_parent_
= offset
;
172 SetNeedsPushProperties();
174 gfx::Vector2dF
offset_to_transform_parent() const {
175 return offset_to_transform_parent_
;
178 const gfx::Rect
& visible_rect_from_property_trees() const {
179 return visible_rect_from_property_trees_
;
181 void set_visible_rect_from_property_trees(const gfx::Rect
& rect
) {
182 visible_rect_from_property_trees_
= rect
;
185 void set_should_flatten_transform_from_property_tree(bool should_flatten
) {
186 should_flatten_transform_from_property_tree_
= should_flatten
;
187 SetNeedsPushProperties();
189 bool should_flatten_transform_from_property_tree() const {
190 return should_flatten_transform_from_property_tree_
;
193 // For compatibility with Layer.
194 bool has_render_surface() const { return !!render_surface(); }
196 void SetNumDescendantsThatDrawContent(int num_descendants
);
197 void SetClipParent(LayerImpl
* ancestor
);
199 LayerImpl
* clip_parent() {
202 const LayerImpl
* clip_parent() const {
206 void SetClipChildren(std::set
<LayerImpl
*>* children
);
208 std::set
<LayerImpl
*>* clip_children() { return clip_children_
.get(); }
209 const std::set
<LayerImpl
*>* clip_children() const {
210 return clip_children_
.get();
213 void PassCopyRequests(ScopedPtrVector
<CopyOutputRequest
>* requests
);
214 // Can only be called when the layer has a copy request.
215 void TakeCopyRequestsAndTransformToTarget(
216 ScopedPtrVector
<CopyOutputRequest
>* request
);
217 bool HasCopyRequest() const { return !copy_requests_
.empty(); }
219 void SetMaskLayer(scoped_ptr
<LayerImpl
> mask_layer
);
220 LayerImpl
* mask_layer() { return mask_layer_
.get(); }
221 const LayerImpl
* mask_layer() const { return mask_layer_
.get(); }
222 scoped_ptr
<LayerImpl
> TakeMaskLayer();
224 void SetReplicaLayer(scoped_ptr
<LayerImpl
> replica_layer
);
225 LayerImpl
* replica_layer() { return replica_layer_
.get(); }
226 const LayerImpl
* replica_layer() const { return replica_layer_
.get(); }
227 scoped_ptr
<LayerImpl
> TakeReplicaLayer();
229 bool has_mask() const { return mask_layer_
; }
230 bool has_replica() const { return replica_layer_
; }
231 bool replica_has_mask() const {
232 return replica_layer_
&& (mask_layer_
|| replica_layer_
->mask_layer_
);
235 LayerTreeImpl
* layer_tree_impl() const { return layer_tree_impl_
; }
237 void PopulateSharedQuadState(SharedQuadState
* state
) const;
238 void PopulateScaledSharedQuadState(SharedQuadState
* state
, float scale
) const;
239 // WillDraw must be called before AppendQuads. If WillDraw returns false,
240 // AppendQuads and DidDraw will not be called. If WillDraw returns true,
241 // DidDraw is guaranteed to be called before another WillDraw or before
242 // the layer is destroyed. To enforce this, any class that overrides
243 // WillDraw/DidDraw must call the base class version only if WillDraw
245 virtual bool WillDraw(DrawMode draw_mode
,
246 ResourceProvider
* resource_provider
);
247 virtual void AppendQuads(RenderPass
* render_pass
,
248 AppendQuadsData
* append_quads_data
) {}
249 virtual void DidDraw(ResourceProvider
* resource_provider
);
251 // Verify that the resource ids in the quad are valid.
252 void ValidateQuadResources(DrawQuad
* quad
) const {
254 ValidateQuadResourcesInternal(quad
);
258 virtual void GetContentsResourceId(ResourceProvider::ResourceId
* resource_id
,
259 gfx::Size
* resource_size
) const;
261 virtual bool HasDelegatedContent() const;
262 virtual bool HasContributingDelegatedRenderPasses() const;
263 virtual RenderPassId
FirstContributingRenderPassId() const;
264 virtual RenderPassId
NextContributingRenderPassId(RenderPassId id
) const;
266 virtual void NotifyTileStateChanged(const Tile
* tile
) {}
268 virtual ScrollbarLayerImplBase
* ToScrollbarLayer();
270 // Returns true if this layer has content to draw.
271 void SetDrawsContent(bool draws_content
);
272 bool DrawsContent() const { return draws_content_
; }
274 int NumDescendantsThatDrawContent() const;
275 void SetHideLayerAndSubtree(bool hide
);
276 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_
; }
278 void SetTransformOrigin(const gfx::Point3F
& transform_origin
);
279 gfx::Point3F
transform_origin() const { return transform_origin_
; }
281 void SetBackgroundColor(SkColor background_color
);
282 SkColor
background_color() const { return background_color_
; }
283 // If contents_opaque(), return an opaque color else return a
284 // non-opaque color. Tries to return background_color(), if possible.
285 SkColor
SafeOpaqueBackgroundColor() const;
287 void SetFilters(const FilterOperations
& filters
);
288 const FilterOperations
& filters() const { return filters_
; }
289 bool FilterIsAnimating() const;
290 bool FilterIsAnimatingOnImplOnly() const;
292 void SetBackgroundFilters(const FilterOperations
& filters
);
293 const FilterOperations
& background_filters() const {
294 return background_filters_
;
297 void SetMasksToBounds(bool masks_to_bounds
);
298 bool masks_to_bounds() const { return masks_to_bounds_
; }
300 void SetContentsOpaque(bool opaque
);
301 bool contents_opaque() const { return contents_opaque_
; }
303 void SetOpacity(float opacity
);
304 float opacity() const { return opacity_
; }
305 bool OpacityIsAnimating() const;
306 bool OpacityIsAnimatingOnImplOnly() const;
308 void SetBlendMode(SkXfermode::Mode
);
309 SkXfermode::Mode
blend_mode() const { return blend_mode_
; }
310 bool uses_default_blend_mode() const {
311 return blend_mode_
== SkXfermode::kSrcOver_Mode
;
314 void SetIsRootForIsolatedGroup(bool root
);
315 bool is_root_for_isolated_group() const {
316 return is_root_for_isolated_group_
;
319 void SetPosition(const gfx::PointF
& position
);
320 gfx::PointF
position() const { return position_
; }
322 void SetIsContainerForFixedPositionLayers(bool container
) {
323 is_container_for_fixed_position_layers_
= container
;
325 // This is a non-trivial function in Layer.
326 bool IsContainerForFixedPositionLayers() const {
327 return is_container_for_fixed_position_layers_
;
330 gfx::Vector2dF
FixedContainerSizeDelta() const;
332 void SetPositionConstraint(const LayerPositionConstraint
& constraint
) {
333 position_constraint_
= constraint
;
335 const LayerPositionConstraint
& position_constraint() const {
336 return position_constraint_
;
339 void SetShouldFlattenTransform(bool flatten
);
340 bool should_flatten_transform() const { return should_flatten_transform_
; }
342 bool Is3dSorted() const { return sorting_context_id_
!= 0; }
344 void SetUseParentBackfaceVisibility(bool use
) {
345 use_parent_backface_visibility_
= use
;
347 bool use_parent_backface_visibility() const {
348 return use_parent_backface_visibility_
;
351 bool ShowDebugBorders() const;
353 // These invalidate the host's render surface layer list. The caller
354 // is responsible for calling set_needs_update_draw_properties on the tree
355 // so that its list can be recreated.
356 void ClearRenderSurfaceLayerList();
357 void SetHasRenderSurface(bool has_render_surface
);
359 RenderSurfaceImpl
* render_surface() const { return render_surface_
.get(); }
361 DrawProperties
<LayerImpl
>& draw_properties() {
362 return draw_properties_
;
364 const DrawProperties
<LayerImpl
>& draw_properties() const {
365 return draw_properties_
;
368 // The following are shortcut accessors to get various information from
370 const gfx::Transform
& draw_transform() const {
371 return draw_properties_
.target_space_transform
;
373 const gfx::Transform
& screen_space_transform() const {
374 return draw_properties_
.screen_space_transform
;
376 float draw_opacity() const { return draw_properties_
.opacity
; }
377 SkXfermode::Mode
draw_blend_mode() const {
378 return draw_properties_
.blend_mode
;
380 bool draw_opacity_is_animating() const {
381 return draw_properties_
.opacity_is_animating
;
383 bool draw_transform_is_animating() const {
384 return draw_properties_
.target_space_transform_is_animating
;
386 bool screen_space_transform_is_animating() const {
387 return draw_properties_
.screen_space_transform_is_animating
;
389 bool screen_space_opacity_is_animating() const {
390 return draw_properties_
.screen_space_opacity_is_animating
;
392 bool can_use_lcd_text() const { return draw_properties_
.can_use_lcd_text
; }
393 bool is_clipped() const { return draw_properties_
.is_clipped
; }
394 gfx::Rect
clip_rect() const { return draw_properties_
.clip_rect
; }
395 gfx::Rect
drawable_content_rect() const {
396 return draw_properties_
.drawable_content_rect
;
398 gfx::Rect
visible_content_rect() const {
399 return draw_properties_
.visible_content_rect
;
401 LayerImpl
* render_target() {
402 DCHECK(!draw_properties_
.render_target
||
403 draw_properties_
.render_target
->render_surface());
404 return draw_properties_
.render_target
;
406 const LayerImpl
* render_target() const {
407 DCHECK(!draw_properties_
.render_target
||
408 draw_properties_
.render_target
->render_surface());
409 return draw_properties_
.render_target
;
412 int num_unclipped_descendants() const {
413 return draw_properties_
.num_unclipped_descendants
;
416 // The client should be responsible for setting bounds, content bounds and
417 // contents scale to appropriate values. LayerImpl doesn't calculate any of
418 // them from the other values.
420 void SetBounds(const gfx::Size
& bounds
);
421 gfx::Size
bounds() const;
422 // Like bounds() but doesn't snap to int. Lossy on giant pages (e.g. millions
423 // of pixels) due to use of single precision float.
424 gfx::SizeF
BoundsForScrolling() const;
425 void SetBoundsDelta(const gfx::Vector2dF
& bounds_delta
);
426 gfx::Vector2dF
bounds_delta() const { return bounds_delta_
; }
428 void SetContentBounds(const gfx::Size
& content_bounds
);
429 gfx::Size
content_bounds() const { return draw_properties_
.content_bounds
; }
431 float contents_scale_x() const { return draw_properties_
.contents_scale_x
; }
432 float contents_scale_y() const { return draw_properties_
.contents_scale_y
; }
433 void SetContentsScale(float contents_scale_x
, float contents_scale_y
);
435 bool IsExternalFlingActive() const;
437 void SetCurrentScrollOffset(const gfx::ScrollOffset
& scroll_offset
);
438 void SetCurrentScrollOffsetFromDelegate(
439 const gfx::ScrollOffset
& scroll_offset
);
440 void PushScrollOffsetFromMainThread(const gfx::ScrollOffset
& scroll_offset
);
441 // This method is similar to PushScrollOffsetFromMainThread but will cause the
442 // scroll offset given to clobber any scroll changes on the active tree in the
443 // time until this value is pushed to the active tree.
444 void PushScrollOffsetFromMainThreadAndClobberActiveValue(
445 const gfx::ScrollOffset
& scroll_offset
);
446 gfx::ScrollOffset
PullDeltaForMainThread();
447 gfx::ScrollOffset
CurrentScrollOffset() const;
448 gfx::ScrollOffset
BaseScrollOffset() const;
449 gfx::Vector2dF
ScrollDelta() const;
450 void SetScrollDelta(const gfx::Vector2dF
& delta
);
452 gfx::ScrollOffset
MaxScrollOffset() const;
453 gfx::ScrollOffset
ClampScrollOffsetToLimits(gfx::ScrollOffset offset
) const;
454 gfx::Vector2dF
ClampScrollToMaxScrollOffset();
455 void SetScrollbarPosition(ScrollbarLayerImplBase
* scrollbar_layer
,
456 LayerImpl
* scrollbar_clip_layer
,
457 bool on_resize
) const;
458 void SetScrollCompensationAdjustment(const gfx::Vector2dF
& scroll_offset
) {
459 scroll_compensation_adjustment_
= scroll_offset
;
461 gfx::Vector2dF
ScrollCompensationAdjustment() const {
462 return scroll_compensation_adjustment_
;
465 // Returns the delta of the scroll that was outside of the bounds of the
467 gfx::Vector2dF
ScrollBy(const gfx::Vector2dF
& scroll
);
469 void SetScrollClipLayer(int scroll_clip_layer_id
);
470 LayerImpl
* scroll_clip_layer() const { return scroll_clip_layer_
; }
471 bool scrollable() const { return !!scroll_clip_layer_
; }
473 void set_user_scrollable_horizontal(bool scrollable
) {
474 user_scrollable_horizontal_
= scrollable
;
476 bool user_scrollable_horizontal() const {
477 return user_scrollable_horizontal_
;
479 void set_user_scrollable_vertical(bool scrollable
) {
480 user_scrollable_vertical_
= scrollable
;
482 bool user_scrollable_vertical() const { return user_scrollable_vertical_
; }
484 bool user_scrollable(ScrollbarOrientation orientation
) const;
486 void ApplySentScrollDeltasFromAbortedCommit();
488 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread
) {
489 should_scroll_on_main_thread_
= should_scroll_on_main_thread
;
491 bool should_scroll_on_main_thread() const {
492 return should_scroll_on_main_thread_
;
495 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers
) {
496 have_wheel_event_handlers_
= have_wheel_event_handlers
;
498 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_
; }
500 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers
) {
501 have_scroll_event_handlers_
= have_scroll_event_handlers
;
503 bool have_scroll_event_handlers() const {
504 return have_scroll_event_handlers_
;
507 void SetNonFastScrollableRegion(const Region
& region
) {
508 non_fast_scrollable_region_
= region
;
510 const Region
& non_fast_scrollable_region() const {
511 return non_fast_scrollable_region_
;
514 void SetTouchEventHandlerRegion(const Region
& region
) {
515 touch_event_handler_region_
= region
;
517 const Region
& touch_event_handler_region() const {
518 return touch_event_handler_region_
;
521 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on
) {
522 scroll_blocks_on_
= scroll_blocks_on
;
524 ScrollBlocksOn
scroll_blocks_on() const { return scroll_blocks_on_
; }
525 void SetDrawCheckerboardForMissingTiles(bool checkerboard
) {
526 draw_checkerboard_for_missing_tiles_
= checkerboard
;
528 bool draw_checkerboard_for_missing_tiles() const {
529 return draw_checkerboard_for_missing_tiles_
;
532 InputHandler::ScrollStatus
TryScroll(
533 const gfx::PointF
& screen_space_point
,
534 InputHandler::ScrollInputType type
,
535 ScrollBlocksOn effective_block_mode
) const;
537 void SetDoubleSided(bool double_sided
);
538 bool double_sided() const { return double_sided_
; }
540 void SetTransform(const gfx::Transform
& transform
);
541 const gfx::Transform
& transform() const { return transform_
; }
542 bool TransformIsAnimating() const;
543 bool TransformIsAnimatingOnImplOnly() const;
544 void SetTransformAndInvertibility(const gfx::Transform
& transform
,
545 bool transform_is_invertible
);
546 bool transform_is_invertible() const { return transform_is_invertible_
; }
548 // Note this rect is in layer space (not content space).
549 void SetUpdateRect(const gfx::Rect
& update_rect
);
550 gfx::Rect
update_rect() const { return update_rect_
; }
552 void AddDamageRect(const gfx::RectF
& damage_rect
);
554 const gfx::RectF
& damage_rect() const { return damage_rect_
; }
556 virtual base::DictionaryValue
* LayerTreeAsJson() const;
558 void SetStackingOrderChanged(bool stacking_order_changed
);
560 bool LayerPropertyChanged() const { return layer_property_changed_
; }
562 void ResetAllChangeTrackingForSubtree();
564 LayerAnimationController
* layer_animation_controller() {
565 return layer_animation_controller_
.get();
568 const LayerAnimationController
* layer_animation_controller() const {
569 return layer_animation_controller_
.get();
572 virtual SimpleEnclosedRegion
VisibleContentOpaqueRegion() const;
574 virtual void DidBecomeActive();
576 virtual void DidBeginTracing();
578 // Release resources held by this layer. Called when the output surface
579 // that rendered this layer was lost or a rendering mode switch has occured.
580 virtual void ReleaseResources();
582 // Recreate resources that are required after they were released by a
583 // ReleaseResources call.
584 virtual void RecreateResources();
586 ScrollbarAnimationController
* scrollbar_animation_controller() const {
587 return scrollbar_animation_controller_
.get();
590 typedef std::set
<ScrollbarLayerImplBase
*> ScrollbarSet
;
591 ScrollbarSet
* scrollbars() { return scrollbars_
.get(); }
592 void ClearScrollbars();
593 void AddScrollbar(ScrollbarLayerImplBase
* layer
);
594 void RemoveScrollbar(ScrollbarLayerImplBase
* layer
);
595 bool HasScrollbar(ScrollbarOrientation orientation
) const;
596 void ScrollbarParametersDidChange(bool on_resize
);
598 return scroll_clip_layer_
? scroll_clip_layer_
->bounds().height() : 0;
601 gfx::Rect
LayerRectToContentRect(const gfx::RectF
& layer_rect
) const;
603 virtual skia::RefPtr
<SkPicture
> GetPicture();
605 virtual scoped_ptr
<LayerImpl
> CreateLayerImpl(LayerTreeImpl
* tree_impl
);
606 virtual void PushPropertiesTo(LayerImpl
* layer
);
608 virtual void GetAllPrioritizedTilesForTracing(
609 std::vector
<PrioritizedTile
>* prioritized_tiles
) const;
610 virtual void AsValueInto(base::trace_event::TracedValue
* dict
) const;
612 virtual size_t GPUMemoryUsageInBytes() const;
614 void SetNeedsPushProperties();
615 void AddDependentNeedsPushProperties();
616 void RemoveDependentNeedsPushProperties();
617 bool parent_should_know_need_push_properties() const {
618 return needs_push_properties() || descendant_needs_push_properties();
621 bool needs_push_properties() const { return needs_push_properties_
; }
622 bool descendant_needs_push_properties() const {
623 return num_dependents_need_push_properties_
> 0;
626 virtual void RunMicroBenchmark(MicroBenchmarkImpl
* benchmark
);
628 virtual void SetDebugInfo(
629 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> other
);
631 bool IsDrawnRenderSurfaceLayerListMember() const;
633 void Set3dSortingContextId(int id
);
634 int sorting_context_id() { return sorting_context_id_
; }
636 void PassFrameTimingRequests(
637 std::vector
<FrameTimingRequest
>* frame_timing_requests
);
638 const std::vector
<FrameTimingRequest
>& frame_timing_requests() const {
639 return frame_timing_requests_
;
641 void GatherFrameTimingRequestIds(std::vector
<int64_t>* request_ids
);
643 SyncedScrollOffset
* synced_scroll_offset() { return scroll_offset_
.get(); }
645 // Get the correct invalidation region instead of conservative Rect
646 // for layers that provide it.
647 virtual Region
GetInvalidationRegion();
649 virtual gfx::Rect
GetEnclosingRectInTargetSpace() const;
652 LayerImpl(LayerTreeImpl
* layer_impl
,
654 scoped_refptr
<SyncedScrollOffset
> scroll_offset
);
655 LayerImpl(LayerTreeImpl
* layer_impl
, int id
);
657 // Get the color and size of the layer's debug border.
658 virtual void GetDebugBorderProperties(SkColor
* color
, float* width
) const;
660 void AppendDebugBorderQuad(RenderPass
* render_pass
,
661 const gfx::Size
& content_bounds
,
662 const SharedQuadState
* shared_quad_state
,
663 AppendQuadsData
* append_quads_data
) const;
664 void AppendDebugBorderQuad(RenderPass
* render_pass
,
665 const gfx::Size
& content_bounds
,
666 const SharedQuadState
* shared_quad_state
,
667 AppendQuadsData
* append_quads_data
,
671 void NoteLayerPropertyChanged();
672 void NoteLayerPropertyChangedForSubtree();
674 // Note carefully this does not affect the current layer.
675 void NoteLayerPropertyChangedForDescendants();
677 gfx::Rect
GetScaledEnclosingRectInTargetSpace(float scale
) const;
680 void ValidateQuadResourcesInternal(DrawQuad
* quad
) const;
682 void PushScrollOffset(const gfx::ScrollOffset
* scroll_offset
);
683 // If the new scroll offset is assigned from the root scroll offset delegate,
684 // LayerImpl won't inform the root scroll offset delegate about the scroll
685 // change to avoid feedback.
686 void DidUpdateScrollOffset(bool is_from_root_delegate
);
687 void NoteLayerPropertyChangedForDescendantsInternal();
689 virtual const char* LayerTypeAsString() const;
691 // Properties internal to LayerImpl
693 OwnedLayerImplList children_
;
695 LayerImpl
* scroll_parent_
;
697 // Storing a pointer to a set rather than a set since this will be rarely
698 // used. If this pointer turns out to be too heavy, we could have this (and
699 // the scroll parent above) be stored in a LayerImpl -> scroll_info
701 scoped_ptr
<std::set
<LayerImpl
*>> scroll_children_
;
703 LayerImpl
* clip_parent_
;
704 scoped_ptr
<std::set
<LayerImpl
*>> clip_children_
;
706 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
707 // confirm newly assigned layer is still the previous one
709 scoped_ptr
<LayerImpl
> mask_layer_
;
710 int replica_layer_id_
; // ditto
711 scoped_ptr
<LayerImpl
> replica_layer_
;
713 LayerTreeImpl
* layer_tree_impl_
;
715 // Properties dynamically changeable on active tree.
716 scoped_refptr
<SyncedScrollOffset
> scroll_offset_
;
717 gfx::Vector2dF bounds_delta_
;
719 // Properties synchronized from the associated Layer.
720 gfx::Point3F transform_origin_
;
722 LayerImpl
* scroll_clip_layer_
;
724 gfx::Vector2dF offset_to_transform_parent_
;
726 bool scrollable_
: 1;
727 bool should_scroll_on_main_thread_
: 1;
728 bool have_wheel_event_handlers_
: 1;
729 bool have_scroll_event_handlers_
: 1;
731 static_assert(SCROLL_BLOCKS_ON_MAX
< (1 << 3), "ScrollBlocksOn too big");
732 ScrollBlocksOn scroll_blocks_on_
: 3;
734 bool user_scrollable_horizontal_
: 1;
735 bool user_scrollable_vertical_
: 1;
736 bool stacking_order_changed_
: 1;
737 // Whether the "back" of this layer should draw.
738 bool double_sided_
: 1;
739 bool should_flatten_transform_
: 1;
740 bool should_flatten_transform_from_property_tree_
: 1;
742 // Tracks if drawing-related properties have changed since last redraw.
743 bool layer_property_changed_
: 1;
745 bool masks_to_bounds_
: 1;
746 bool contents_opaque_
: 1;
747 bool is_root_for_isolated_group_
: 1;
748 bool use_parent_backface_visibility_
: 1;
749 bool draw_checkerboard_for_missing_tiles_
: 1;
750 bool draws_content_
: 1;
751 bool hide_layer_and_subtree_
: 1;
753 // Cache transform_'s invertibility.
754 bool transform_is_invertible_
: 1;
756 // Set for the layer that other layers are fixed to.
757 bool is_container_for_fixed_position_layers_
: 1;
759 Region non_fast_scrollable_region_
;
760 Region touch_event_handler_region_
;
761 SkColor background_color_
;
764 SkXfermode::Mode blend_mode_
;
765 gfx::PointF position_
;
766 gfx::Transform transform_
;
768 LayerPositionConstraint position_constraint_
;
770 gfx::Vector2dF scroll_compensation_adjustment_
;
772 int num_descendants_that_draw_content_
;
774 gfx::Rect visible_rect_from_property_trees_
;
775 int transform_tree_index_
;
776 int opacity_tree_index_
;
777 int clip_tree_index_
;
779 // The global depth value of the center of the layer. This value is used
780 // to sort layers from back to front.
783 FilterOperations filters_
;
784 FilterOperations background_filters_
;
787 friend class TreeSynchronizer
;
789 // This flag is set when the layer needs to push properties to the active
791 bool needs_push_properties_
;
793 // The number of direct children or dependent layers that need to be recursed
794 // to in order for them or a descendent of them to push properties to the
796 int num_dependents_need_push_properties_
;
798 // Layers that share a sorting context id will be sorted together in 3d
799 // space. 0 is a special value that means this layer will not be sorted and
800 // will be drawn in paint order.
801 int sorting_context_id_
;
803 DrawMode current_draw_mode_
;
806 // Rect indicating what was repainted/updated during update.
807 // Note that plugin layers bypass this and leave it empty.
808 // Uses layer (not content) space.
809 gfx::Rect update_rect_
;
811 // This rect is in layer space.
812 gfx::RectF damage_rect_
;
814 // Manages animations for this layer.
815 scoped_refptr
<LayerAnimationController
> layer_animation_controller_
;
817 // Manages scrollbars for this layer
818 scoped_ptr
<ScrollbarAnimationController
> scrollbar_animation_controller_
;
820 scoped_ptr
<ScrollbarSet
> scrollbars_
;
822 ScopedPtrVector
<CopyOutputRequest
> copy_requests_
;
824 // Group of properties that need to be computed based on the layer tree
825 // hierarchy before layers can be drawn.
826 DrawProperties
<LayerImpl
> draw_properties_
;
828 scoped_refptr
<base::trace_event::ConvertableToTraceFormat
> debug_info_
;
829 scoped_ptr
<RenderSurfaceImpl
> render_surface_
;
831 std::vector
<FrameTimingRequest
> frame_timing_requests_
;
832 bool frame_timing_requests_dirty_
;
834 DISALLOW_COPY_AND_ASSIGN(LayerImpl
);
839 #endif // CC_LAYERS_LAYER_IMPL_H_