Update V8 to version 4.7.44.
[chromium-blink-merge.git] / cc / layers / layer_impl.h
blobb5f60e946101c4531ef1b8ecb94c2f34f544fbd3
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_
8 #include <map>
9 #include <set>
10 #include <string>
11 #include <vector>
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"
46 namespace base {
47 namespace trace_event {
48 class ConvertableToTraceFormat;
49 class TracedValue;
51 class DictionaryValue;
54 namespace cc {
56 class LayerTreeHostImpl;
57 class LayerTreeImpl;
58 class MicroBenchmarkImpl;
59 class Occlusion;
60 class EffectTree;
61 class PrioritizedTile;
62 class RenderPass;
63 class RenderPassId;
64 class Renderer;
65 class ScrollbarAnimationController;
66 class ScrollbarLayerImplBase;
67 class SimpleEnclosedRegion;
68 class Tile;
69 class TransformTree;
70 class ScrollState;
72 struct AppendQuadsData;
74 enum DrawMode {
75 DRAW_MODE_NONE,
76 DRAW_MODE_HARDWARE,
77 DRAW_MODE_SOFTWARE,
78 DRAW_MODE_RESOURCELESS_SOFTWARE
81 class CC_EXPORT LayerImpl : public LayerAnimationValueObserver,
82 public LayerAnimationValueProvider,
83 public AnimationDelegate {
84 public:
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,
94 int id,
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,
125 int group) override;
127 // Tree structure.
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() {
217 return clip_parent_;
219 const LayerImpl* clip_parent() const {
220 return clip_parent_;
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
261 // returns true.
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 {
270 #if DCHECK_IS_ON()
271 ValidateQuadResourcesInternal(quad);
272 #endif
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)
331 return;
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& draw_properties() { return draw_properties_; }
393 const DrawProperties& draw_properties() const { return draw_properties_; }
395 // The following are shortcut accessors to get various information from
396 // draw_properties_
397 const gfx::Transform& draw_transform() const {
398 return draw_properties_.target_space_transform;
400 const gfx::Transform& screen_space_transform() const {
401 return draw_properties_.screen_space_transform;
403 float draw_opacity() const { return draw_properties_.opacity; }
404 bool screen_space_transform_is_animating() const {
405 return draw_properties_.screen_space_transform_is_animating;
407 bool can_use_lcd_text() const { return draw_properties_.can_use_lcd_text; }
408 gfx::Rect clip_rect() const { return draw_properties_.clip_rect; }
409 gfx::Rect drawable_content_rect() const {
410 return draw_properties_.drawable_content_rect;
412 gfx::Rect visible_layer_rect() const {
413 return draw_properties_.visible_layer_rect;
415 LayerImpl* render_target() {
416 DCHECK(!draw_properties_.render_target ||
417 draw_properties_.render_target->render_surface());
418 return draw_properties_.render_target;
420 const LayerImpl* render_target() const {
421 DCHECK(!draw_properties_.render_target ||
422 draw_properties_.render_target->render_surface());
423 return draw_properties_.render_target;
426 size_t num_unclipped_descendants() const {
427 return draw_properties_.num_unclipped_descendants;
430 // The client should be responsible for setting bounds, content bounds and
431 // contents scale to appropriate values. LayerImpl doesn't calculate any of
432 // them from the other values.
434 void SetBounds(const gfx::Size& bounds);
435 gfx::Size bounds() const;
436 // Like bounds() but doesn't snap to int. Lossy on giant pages (e.g. millions
437 // of pixels) due to use of single precision float.
438 gfx::SizeF BoundsForScrolling() const;
439 void SetBoundsDelta(const gfx::Vector2dF& bounds_delta);
440 gfx::Vector2dF bounds_delta() const { return bounds_delta_; }
442 void SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset);
443 void SetCurrentScrollOffsetFromDelegate(
444 const gfx::ScrollOffset& scroll_offset);
445 void PushScrollOffsetFromMainThread(const gfx::ScrollOffset& scroll_offset);
446 // This method is similar to PushScrollOffsetFromMainThread but will cause the
447 // scroll offset given to clobber any scroll changes on the active tree in the
448 // time until this value is pushed to the active tree.
449 void PushScrollOffsetFromMainThreadAndClobberActiveValue(
450 const gfx::ScrollOffset& scroll_offset);
451 gfx::ScrollOffset PullDeltaForMainThread();
452 gfx::ScrollOffset CurrentScrollOffset() const;
453 gfx::ScrollOffset BaseScrollOffset() const;
454 gfx::Vector2dF ScrollDelta() const;
455 void SetScrollDelta(const gfx::Vector2dF& delta);
457 gfx::ScrollOffset MaxScrollOffset() const;
458 gfx::ScrollOffset ClampScrollOffsetToLimits(gfx::ScrollOffset offset) const;
459 gfx::Vector2dF ClampScrollToMaxScrollOffset();
460 void SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
461 LayerImpl* scrollbar_clip_layer,
462 bool on_resize) const;
463 void SetScrollCompensationAdjustment(const gfx::Vector2dF& scroll_offset) {
464 scroll_compensation_adjustment_ = scroll_offset;
466 gfx::Vector2dF ScrollCompensationAdjustment() const {
467 return scroll_compensation_adjustment_;
470 // Returns the delta of the scroll that was outside of the bounds of the
471 // initial scroll
472 gfx::Vector2dF ScrollBy(const gfx::Vector2dF& scroll);
474 void SetScrollClipLayer(int scroll_clip_layer_id);
475 LayerImpl* scroll_clip_layer() const { return scroll_clip_layer_; }
476 bool scrollable() const { return !!scroll_clip_layer_; }
478 void set_user_scrollable_horizontal(bool scrollable) {
479 user_scrollable_horizontal_ = scrollable;
481 bool user_scrollable_horizontal() const {
482 return user_scrollable_horizontal_;
484 void set_user_scrollable_vertical(bool scrollable) {
485 user_scrollable_vertical_ = scrollable;
487 bool user_scrollable_vertical() const { return user_scrollable_vertical_; }
489 bool user_scrollable(ScrollbarOrientation orientation) const;
491 void ApplySentScrollDeltasFromAbortedCommit();
493 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) {
494 should_scroll_on_main_thread_ = should_scroll_on_main_thread;
496 bool should_scroll_on_main_thread() const {
497 return should_scroll_on_main_thread_;
500 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers) {
501 have_wheel_event_handlers_ = have_wheel_event_handlers;
503 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_; }
505 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers) {
506 have_scroll_event_handlers_ = have_scroll_event_handlers;
508 bool have_scroll_event_handlers() const {
509 return have_scroll_event_handlers_;
512 void SetNonFastScrollableRegion(const Region& region) {
513 non_fast_scrollable_region_ = region;
515 const Region& non_fast_scrollable_region() const {
516 return non_fast_scrollable_region_;
519 void SetTouchEventHandlerRegion(const Region& region) {
520 touch_event_handler_region_ = region;
522 const Region& touch_event_handler_region() const {
523 return touch_event_handler_region_;
526 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on) {
527 scroll_blocks_on_ = scroll_blocks_on;
529 ScrollBlocksOn scroll_blocks_on() const { return scroll_blocks_on_; }
531 InputHandler::ScrollStatus TryScroll(
532 const gfx::PointF& screen_space_point,
533 InputHandler::ScrollInputType type,
534 ScrollBlocksOn effective_block_mode) const;
536 void SetDoubleSided(bool double_sided);
537 bool double_sided() const { return double_sided_; }
539 void SetTransform(const gfx::Transform& transform);
540 const gfx::Transform& transform() const { return transform_; }
541 bool TransformIsAnimating() const;
542 bool HasPotentiallyRunningTransformAnimation() const;
543 bool TransformIsAnimatingOnImplOnly() const;
544 bool HasOnlyTranslationTransforms() const;
545 void SetTransformAndInvertibility(const gfx::Transform& transform,
546 bool transform_is_invertible);
547 bool transform_is_invertible() const { return transform_is_invertible_; }
549 bool MaximumTargetScale(float* max_scale) const;
550 bool AnimationStartScale(float* start_scale) const;
552 // This includes all animations, even those that are finished but haven't yet
553 // been deleted.
554 bool HasAnyAnimationTargetingProperty(
555 Animation::TargetProperty property) const;
557 bool HasFilterAnimationThatInflatesBounds() const;
558 bool HasTransformAnimationThatInflatesBounds() const;
559 bool HasAnimationThatInflatesBounds() const;
561 bool FilterAnimationBoundsForBox(const gfx::BoxF& box,
562 gfx::BoxF* bounds) const;
563 bool TransformAnimationBoundsForBox(const gfx::BoxF& box,
564 gfx::BoxF* bounds) const;
566 // Note this rect is in layer space (not content space).
567 void SetUpdateRect(const gfx::Rect& update_rect);
568 const gfx::Rect& update_rect() const { return update_rect_; }
570 void AddDamageRect(const gfx::Rect& damage_rect);
571 const gfx::Rect& damage_rect() const { return damage_rect_; }
573 virtual base::DictionaryValue* LayerTreeAsJson() const;
575 void SetStackingOrderChanged(bool stacking_order_changed);
577 bool LayerPropertyChanged() const { return layer_property_changed_; }
579 void ResetAllChangeTrackingForSubtree();
581 LayerAnimationController* layer_animation_controller() {
582 return layer_animation_controller_.get();
585 const LayerAnimationController* layer_animation_controller() const {
586 return layer_animation_controller_.get();
589 virtual SimpleEnclosedRegion VisibleOpaqueRegion() const;
591 virtual void DidBecomeActive();
593 virtual void DidBeginTracing();
595 // Release resources held by this layer. Called when the output surface
596 // that rendered this layer was lost or a rendering mode switch has occured.
597 virtual void ReleaseResources();
599 // Recreate resources that are required after they were released by a
600 // ReleaseResources call.
601 virtual void RecreateResources();
603 ScrollbarAnimationController* scrollbar_animation_controller() const {
604 return scrollbar_animation_controller_.get();
607 typedef std::set<ScrollbarLayerImplBase*> ScrollbarSet;
608 ScrollbarSet* scrollbars() { return scrollbars_.get(); }
609 void ClearScrollbars();
610 void AddScrollbar(ScrollbarLayerImplBase* layer);
611 void RemoveScrollbar(ScrollbarLayerImplBase* layer);
612 bool HasScrollbar(ScrollbarOrientation orientation) const;
613 void ScrollbarParametersDidChange(bool on_resize);
614 int clip_height() {
615 return scroll_clip_layer_ ? scroll_clip_layer_->bounds().height() : 0;
618 virtual skia::RefPtr<SkPicture> GetPicture();
620 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl);
621 virtual void PushPropertiesTo(LayerImpl* layer);
623 virtual void GetAllPrioritizedTilesForTracing(
624 std::vector<PrioritizedTile>* prioritized_tiles) const;
625 virtual void AsValueInto(base::trace_event::TracedValue* dict) const;
627 virtual size_t GPUMemoryUsageInBytes() const;
629 void SetNeedsPushProperties();
630 void AddDependentNeedsPushProperties();
631 void RemoveDependentNeedsPushProperties();
632 bool parent_should_know_need_push_properties() const {
633 return needs_push_properties() || descendant_needs_push_properties();
636 bool needs_push_properties() const { return needs_push_properties_; }
637 bool descendant_needs_push_properties() const {
638 return num_dependents_need_push_properties_ > 0;
641 virtual void RunMicroBenchmark(MicroBenchmarkImpl* benchmark);
643 virtual void SetDebugInfo(
644 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other);
646 bool IsDrawnRenderSurfaceLayerListMember() const;
648 void Set3dSortingContextId(int id);
649 int sorting_context_id() { return sorting_context_id_; }
651 void SetFrameTimingRequests(
652 const std::vector<FrameTimingRequest>& frame_timing_requests);
653 const std::vector<FrameTimingRequest>& frame_timing_requests() const {
654 return frame_timing_requests_;
656 void GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids);
658 SyncedScrollOffset* synced_scroll_offset() { return scroll_offset_.get(); }
660 // Get the correct invalidation region instead of conservative Rect
661 // for layers that provide it.
662 virtual Region GetInvalidationRegion();
664 virtual gfx::Rect GetEnclosingRectInTargetSpace() const;
666 void set_visited(bool visited) { visited_ = visited; }
668 bool visited() { return visited_; }
670 void set_layer_or_descendant_is_drawn(bool layer_or_descendant_is_drawn) {
671 layer_or_descendant_is_drawn_ = layer_or_descendant_is_drawn;
674 bool layer_or_descendant_is_drawn() { return layer_or_descendant_is_drawn_; }
676 void set_sorted_for_recursion(bool sorted_for_recursion) {
677 sorted_for_recursion_ = sorted_for_recursion;
680 bool sorted_for_recursion() { return sorted_for_recursion_; }
682 void UpdatePropertyTreeForScrollingAndAnimationIfNeeded();
684 float GetIdealContentsScale() const;
686 protected:
687 LayerImpl(LayerTreeImpl* layer_impl,
688 int id,
689 scoped_refptr<SyncedScrollOffset> scroll_offset);
690 LayerImpl(LayerTreeImpl* layer_impl, int id);
692 // Get the color and size of the layer's debug border.
693 virtual void GetDebugBorderProperties(SkColor* color, float* width) const;
695 void AppendDebugBorderQuad(RenderPass* render_pass,
696 const gfx::Size& bounds,
697 const SharedQuadState* shared_quad_state,
698 AppendQuadsData* append_quads_data) const;
699 void AppendDebugBorderQuad(RenderPass* render_pass,
700 const gfx::Size& bounds,
701 const SharedQuadState* shared_quad_state,
702 AppendQuadsData* append_quads_data,
703 SkColor color,
704 float width) const;
706 void NoteLayerPropertyChanged();
707 void NoteLayerPropertyChangedForSubtree();
709 // Note carefully this does not affect the current layer.
710 void NoteLayerPropertyChangedForDescendants();
712 gfx::Rect GetScaledEnclosingRectInTargetSpace(float scale) const;
714 private:
715 void ValidateQuadResourcesInternal(DrawQuad* quad) const;
717 void PushScrollOffset(const gfx::ScrollOffset* scroll_offset);
718 // If the new scroll offset is assigned from the root scroll offset delegate,
719 // LayerImpl won't inform the root scroll offset delegate about the scroll
720 // change to avoid feedback.
721 void DidUpdateScrollOffset(bool is_from_root_delegate);
722 void NoteLayerPropertyChangedForDescendantsInternal();
724 virtual const char* LayerTypeAsString() const;
726 // Properties internal to LayerImpl
727 LayerImpl* parent_;
728 OwnedLayerImplList children_;
730 LayerImpl* scroll_parent_;
732 // Storing a pointer to a set rather than a set since this will be rarely
733 // used. If this pointer turns out to be too heavy, we could have this (and
734 // the scroll parent above) be stored in a LayerImpl -> scroll_info
735 // map somewhere.
736 scoped_ptr<std::set<LayerImpl*>> scroll_children_;
738 LayerImpl* clip_parent_;
739 scoped_ptr<std::set<LayerImpl*>> clip_children_;
741 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
742 // confirm newly assigned layer is still the previous one
743 int mask_layer_id_;
744 scoped_ptr<LayerImpl> mask_layer_;
745 int replica_layer_id_; // ditto
746 scoped_ptr<LayerImpl> replica_layer_;
747 int layer_id_;
748 LayerTreeImpl* layer_tree_impl_;
750 // Properties dynamically changeable on active tree.
751 scoped_refptr<SyncedScrollOffset> scroll_offset_;
752 gfx::Vector2dF bounds_delta_;
754 // Properties synchronized from the associated Layer.
755 gfx::Point3F transform_origin_;
756 gfx::Size bounds_;
757 LayerImpl* scroll_clip_layer_;
759 gfx::Vector2dF offset_to_transform_parent_;
761 bool should_scroll_on_main_thread_ : 1;
762 bool have_wheel_event_handlers_ : 1;
763 bool have_scroll_event_handlers_ : 1;
765 static_assert(SCROLL_BLOCKS_ON_MAX < (1 << 3), "ScrollBlocksOn too big");
766 ScrollBlocksOn scroll_blocks_on_ : 3;
768 bool user_scrollable_horizontal_ : 1;
769 bool user_scrollable_vertical_ : 1;
770 bool stacking_order_changed_ : 1;
771 // Whether the "back" of this layer should draw.
772 bool double_sided_ : 1;
773 bool should_flatten_transform_ : 1;
774 bool should_flatten_transform_from_property_tree_ : 1;
775 bool is_clipped_ : 1;
777 // Tracks if drawing-related properties have changed since last redraw.
778 bool layer_property_changed_ : 1;
780 bool masks_to_bounds_ : 1;
781 bool contents_opaque_ : 1;
782 bool is_root_for_isolated_group_ : 1;
783 bool use_parent_backface_visibility_ : 1;
784 bool draws_content_ : 1;
785 bool hide_layer_and_subtree_ : 1;
787 // Cache transform_'s invertibility.
788 bool transform_is_invertible_ : 1;
790 // Set for the layer that other layers are fixed to.
791 bool is_container_for_fixed_position_layers_ : 1;
793 bool is_affected_by_page_scale_ : 1;
795 Region non_fast_scrollable_region_;
796 Region touch_event_handler_region_;
797 SkColor background_color_;
799 float opacity_;
800 SkXfermode::Mode blend_mode_;
801 // draw_blend_mode may be different than blend_mode_,
802 // when a RenderSurface re-parents the layer's blend_mode.
803 SkXfermode::Mode draw_blend_mode_;
804 gfx::PointF position_;
805 gfx::Transform transform_;
807 LayerPositionConstraint position_constraint_;
809 gfx::Vector2dF scroll_compensation_adjustment_;
811 int num_descendants_that_draw_content_;
813 gfx::Rect visible_rect_from_property_trees_;
814 gfx::Rect clip_rect_in_target_space_from_property_trees_;
815 int transform_tree_index_;
816 int effect_tree_index_;
817 int clip_tree_index_;
819 // The global depth value of the center of the layer. This value is used
820 // to sort layers from back to front.
821 float draw_depth_;
823 FilterOperations filters_;
824 FilterOperations background_filters_;
826 protected:
827 friend class TreeSynchronizer;
829 // This flag is set when the layer needs to push properties to the active
830 // side.
831 bool needs_push_properties_;
833 // The number of direct children or dependent layers that need to be recursed
834 // to in order for them or a descendent of them to push properties to the
835 // active side.
836 int num_dependents_need_push_properties_;
838 // Layers that share a sorting context id will be sorted together in 3d
839 // space. 0 is a special value that means this layer will not be sorted and
840 // will be drawn in paint order.
841 int sorting_context_id_;
843 DrawMode current_draw_mode_;
845 private:
846 // Rect indicating what was repainted/updated during update.
847 // Note that plugin layers bypass this and leave it empty.
848 // This is in the layer's space.
849 gfx::Rect update_rect_;
851 // Denotes an area that is damaged and needs redraw. This is in the layer's
852 // space.
853 gfx::Rect damage_rect_;
855 // Manages animations for this layer.
856 scoped_refptr<LayerAnimationController> layer_animation_controller_;
858 // Manages scrollbars for this layer
859 scoped_ptr<ScrollbarAnimationController> scrollbar_animation_controller_;
861 scoped_ptr<ScrollbarSet> scrollbars_;
863 ScopedPtrVector<CopyOutputRequest> copy_requests_;
865 // Group of properties that need to be computed based on the layer tree
866 // hierarchy before layers can be drawn.
867 DrawProperties draw_properties_;
869 scoped_refptr<base::trace_event::ConvertableToTraceFormat> debug_info_;
870 scoped_ptr<RenderSurfaceImpl> render_surface_;
872 std::vector<FrameTimingRequest> frame_timing_requests_;
873 bool frame_timing_requests_dirty_;
874 bool visited_;
875 bool layer_or_descendant_is_drawn_;
876 bool sorted_for_recursion_;
878 DISALLOW_COPY_AND_ASSIGN(LayerImpl);
881 } // namespace cc
883 #endif // CC_LAYERS_LAYER_IMPL_H_