Don't show supervised user as "already on this device" while they're being imported.
[chromium-blink-merge.git] / cc / layers / layer.h
blob84e9c0f8ba69c65fa70ce676ed5cc1f6e61e0ae7
1 // Copyright 2010 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_H_
6 #define CC_LAYERS_LAYER_H_
8 #include <set>
9 #include <string>
10 #include <vector>
12 #include "base/callback.h"
13 #include "base/memory/ref_counted.h"
14 #include "base/observer_list.h"
15 #include "cc/animation/layer_animation_controller.h"
16 #include "cc/animation/layer_animation_value_observer.h"
17 #include "cc/animation/layer_animation_value_provider.h"
18 #include "cc/base/cc_export.h"
19 #include "cc/base/region.h"
20 #include "cc/base/scoped_ptr_vector.h"
21 #include "cc/debug/frame_timing_request.h"
22 #include "cc/debug/micro_benchmark.h"
23 #include "cc/layers/draw_properties.h"
24 #include "cc/layers/layer_lists.h"
25 #include "cc/layers/layer_position_constraint.h"
26 #include "cc/layers/paint_properties.h"
27 #include "cc/layers/render_surface.h"
28 #include "cc/layers/scroll_blocks_on.h"
29 #include "cc/output/filter_operations.h"
30 #include "cc/trees/property_tree.h"
31 #include "skia/ext/refptr.h"
32 #include "third_party/skia/include/core/SkColor.h"
33 #include "third_party/skia/include/core/SkImageFilter.h"
34 #include "third_party/skia/include/core/SkPicture.h"
35 #include "third_party/skia/include/core/SkXfermode.h"
36 #include "ui/gfx/geometry/point3_f.h"
37 #include "ui/gfx/geometry/rect.h"
38 #include "ui/gfx/geometry/rect_f.h"
39 #include "ui/gfx/geometry/scroll_offset.h"
40 #include "ui/gfx/transform.h"
42 namespace gfx {
43 class BoxF;
46 namespace base {
47 namespace trace_event {
48 class ConvertableToTraceFormat;
52 namespace cc {
54 class Animation;
55 class AnimationDelegate;
56 struct AnimationEvent;
57 class CopyOutputRequest;
58 class LayerAnimationEventObserver;
59 class LayerClient;
60 class LayerImpl;
61 class LayerSettings;
62 class LayerTreeHost;
63 class LayerTreeHostCommon;
64 class LayerTreeImpl;
65 class LayerTreeSettings;
66 class PriorityCalculator;
67 class RenderingStatsInstrumentation;
68 class ResourceUpdateQueue;
69 class ScrollbarLayerInterface;
70 class SimpleEnclosedRegion;
71 struct AnimationEvent;
72 template <typename LayerType>
73 class OcclusionTracker;
75 // Base class for composited layers. Special layer types are derived from
76 // this class.
77 class CC_EXPORT Layer : public base::RefCounted<Layer>,
78 public LayerAnimationValueObserver,
79 public LayerAnimationValueProvider {
80 public:
81 typedef RenderSurfaceLayerList RenderSurfaceListType;
82 typedef LayerList LayerListType;
83 typedef RenderSurface RenderSurfaceType;
85 enum LayerIdLabels {
86 INVALID_ID = -1,
89 static scoped_refptr<Layer> Create(const LayerSettings& settings);
91 int id() const { return layer_id_; }
93 Layer* RootLayer();
94 Layer* parent() { return parent_; }
95 const Layer* parent() const { return parent_; }
96 void AddChild(scoped_refptr<Layer> child);
97 void InsertChild(scoped_refptr<Layer> child, size_t index);
98 void ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer);
99 void RemoveFromParent();
100 void RemoveAllChildren();
101 void SetChildren(const LayerList& children);
102 bool HasAncestor(const Layer* ancestor) const;
104 const LayerList& children() const { return children_; }
105 Layer* child_at(size_t index) { return children_[index].get(); }
107 // This requests the layer and its subtree be rendered and given to the
108 // callback. If the copy is unable to be produced (the layer is destroyed
109 // first), then the callback is called with a nullptr/empty result. If the
110 // request's source property is set, any prior uncommitted requests having the
111 // same source will be aborted.
112 void RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> request);
113 bool HasCopyRequest() const {
114 return !copy_requests_.empty();
117 virtual void SetBackgroundColor(SkColor background_color);
118 SkColor background_color() const { return background_color_; }
119 // If contents_opaque(), return an opaque color else return a
120 // non-opaque color. Tries to return background_color(), if possible.
121 SkColor SafeOpaqueBackgroundColor() const;
123 // A layer's bounds are in logical, non-page-scaled pixels (however, the
124 // root layer's bounds are in physical pixels).
125 void SetBounds(const gfx::Size& bounds);
126 gfx::Size bounds() const { return bounds_; }
128 void SetMasksToBounds(bool masks_to_bounds);
129 bool masks_to_bounds() const { return masks_to_bounds_; }
131 void SetMaskLayer(Layer* mask_layer);
132 Layer* mask_layer() { return mask_layer_.get(); }
133 const Layer* mask_layer() const { return mask_layer_.get(); }
135 virtual void SetNeedsDisplayRect(const gfx::Rect& dirty_rect);
136 void SetNeedsDisplay() { SetNeedsDisplayRect(gfx::Rect(bounds())); }
138 void SetOpacity(float opacity);
139 float opacity() const { return opacity_; }
140 bool OpacityIsAnimating() const;
141 virtual bool OpacityCanAnimateOnImplThread() const;
143 void SetBlendMode(SkXfermode::Mode blend_mode);
144 SkXfermode::Mode blend_mode() const { return blend_mode_; }
146 bool uses_default_blend_mode() const {
147 return blend_mode_ == SkXfermode::kSrcOver_Mode;
150 // A layer is root for an isolated group when it and all its descendants are
151 // drawn over a black and fully transparent background, creating an isolated
152 // group. It should be used along with SetBlendMode(), in order to restrict
153 // layers within the group to blend with layers outside this group.
154 void SetIsRootForIsolatedGroup(bool root);
155 bool is_root_for_isolated_group() const {
156 return is_root_for_isolated_group_;
159 void SetFilters(const FilterOperations& filters);
160 const FilterOperations& filters() const { return filters_; }
161 bool FilterIsAnimating() const;
163 // Background filters are filters applied to what is behind this layer, when
164 // they are viewed through non-opaque regions in this layer. They are used
165 // through the WebLayer interface, and are not exposed to HTML.
166 void SetBackgroundFilters(const FilterOperations& filters);
167 const FilterOperations& background_filters() const {
168 return background_filters_;
171 virtual void SetContentsOpaque(bool opaque);
172 bool contents_opaque() const { return contents_opaque_; }
174 void SetPosition(const gfx::PointF& position);
175 gfx::PointF position() const { return position_; }
177 // A layer that is a container for fixed position layers cannot be both
178 // scrollable and have a non-identity transform.
179 void SetIsContainerForFixedPositionLayers(bool container);
180 bool IsContainerForFixedPositionLayers() const;
182 gfx::Vector2dF FixedContainerSizeDelta() const {
183 return gfx::Vector2dF();
186 void SetPositionConstraint(const LayerPositionConstraint& constraint);
187 const LayerPositionConstraint& position_constraint() const {
188 return position_constraint_;
191 void SetTransform(const gfx::Transform& transform);
192 const gfx::Transform& transform() const { return transform_; }
193 bool TransformIsAnimating() const;
194 bool AnimationsPreserveAxisAlignment() const;
195 bool transform_is_invertible() const { return transform_is_invertible_; }
197 void SetTransformOrigin(const gfx::Point3F&);
198 gfx::Point3F transform_origin() const { return transform_origin_; }
200 void SetScrollParent(Layer* parent);
202 Layer* scroll_parent() { return scroll_parent_; }
203 const Layer* scroll_parent() const { return scroll_parent_; }
205 void AddScrollChild(Layer* child);
206 void RemoveScrollChild(Layer* child);
208 std::set<Layer*>* scroll_children() { return scroll_children_.get(); }
209 const std::set<Layer*>* scroll_children() const {
210 return scroll_children_.get();
213 void SetClipParent(Layer* ancestor);
215 Layer* clip_parent() { return clip_parent_; }
216 const Layer* clip_parent() const {
217 return clip_parent_;
220 void AddClipChild(Layer* child);
221 void RemoveClipChild(Layer* child);
223 std::set<Layer*>* clip_children() { return clip_children_.get(); }
224 const std::set<Layer*>* clip_children() const {
225 return clip_children_.get();
228 DrawProperties<Layer>& draw_properties() { return draw_properties_; }
229 const DrawProperties<Layer>& draw_properties() const {
230 return draw_properties_;
233 // The following are shortcut accessors to get various information from
234 // draw_properties_
235 const gfx::Transform& draw_transform() const {
236 return draw_properties_.target_space_transform;
238 const gfx::Transform& screen_space_transform() const {
239 return draw_properties_.screen_space_transform;
241 float draw_opacity() const { return draw_properties_.opacity; }
242 bool draw_opacity_is_animating() const {
243 return draw_properties_.opacity_is_animating;
245 bool draw_transform_is_animating() const {
246 return draw_properties_.target_space_transform_is_animating;
248 bool screen_space_transform_is_animating() const {
249 return draw_properties_.screen_space_transform_is_animating;
251 bool screen_space_opacity_is_animating() const {
252 return draw_properties_.screen_space_opacity_is_animating;
254 bool is_clipped() const { return draw_properties_.is_clipped; }
255 gfx::Rect clip_rect() const { return draw_properties_.clip_rect; }
256 gfx::Rect drawable_content_rect() const {
257 return draw_properties_.drawable_content_rect;
259 gfx::Rect visible_content_rect() const {
260 return draw_properties_.visible_content_rect;
262 Layer* render_target() {
263 DCHECK(!draw_properties_.render_target ||
264 draw_properties_.render_target->render_surface());
265 return draw_properties_.render_target;
267 const Layer* render_target() const {
268 DCHECK(!draw_properties_.render_target ||
269 draw_properties_.render_target->render_surface());
270 return draw_properties_.render_target;
272 int num_unclipped_descendants() const {
273 return draw_properties_.num_unclipped_descendants;
276 RenderSurface* render_surface() const { return render_surface_.get(); }
277 void SetScrollOffset(const gfx::ScrollOffset& scroll_offset);
278 void SetScrollCompensationAdjustment(
279 const gfx::Vector2dF& scroll_compensation_adjustment);
280 gfx::Vector2dF ScrollCompensationAdjustment() const;
282 gfx::ScrollOffset scroll_offset() const { return scroll_offset_; }
283 void SetScrollOffsetFromImplSide(const gfx::ScrollOffset& scroll_offset);
285 void SetScrollClipLayerId(int clip_layer_id);
286 bool scrollable() const { return scroll_clip_layer_id_ != INVALID_ID; }
288 void SetUserScrollable(bool horizontal, bool vertical);
289 bool user_scrollable_horizontal() const {
290 return user_scrollable_horizontal_;
292 bool user_scrollable_vertical() const { return user_scrollable_vertical_; }
294 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread);
295 bool should_scroll_on_main_thread() const {
296 return should_scroll_on_main_thread_;
299 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers);
300 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_; }
302 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers);
303 bool have_scroll_event_handlers() const {
304 return have_scroll_event_handlers_;
307 void SetNonFastScrollableRegion(const Region& non_fast_scrollable_region);
308 const Region& non_fast_scrollable_region() const {
309 return non_fast_scrollable_region_;
312 void SetTouchEventHandlerRegion(const Region& touch_event_handler_region);
313 const Region& touch_event_handler_region() const {
314 return touch_event_handler_region_;
317 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on);
318 ScrollBlocksOn scroll_blocks_on() const { return scroll_blocks_on_; }
320 void set_did_scroll_callback(const base::Closure& callback) {
321 did_scroll_callback_ = callback;
324 void SetDrawCheckerboardForMissingTiles(bool checkerboard);
325 bool draw_checkerboard_for_missing_tiles() const {
326 return draw_checkerboard_for_missing_tiles_;
329 void SetForceRenderSurface(bool force_render_surface);
330 bool force_render_surface() const { return force_render_surface_; }
332 gfx::Vector2dF ScrollDelta() const { return gfx::Vector2dF(); }
333 gfx::ScrollOffset CurrentScrollOffset() const { return scroll_offset_; }
335 void SetDoubleSided(bool double_sided);
336 bool double_sided() const { return double_sided_; }
338 void SetShouldFlattenTransform(bool flatten);
339 bool should_flatten_transform() const { return should_flatten_transform_; }
341 bool Is3dSorted() const { return sorting_context_id_ != 0; }
343 void set_use_parent_backface_visibility(bool use) {
344 use_parent_backface_visibility_ = use;
346 bool use_parent_backface_visibility() const {
347 return use_parent_backface_visibility_;
350 virtual void SetLayerTreeHost(LayerTreeHost* host);
352 virtual bool HasDelegatedContent() const;
353 bool HasContributingDelegatedRenderPasses() const { return false; }
355 void SetIsDrawable(bool is_drawable);
357 void SetHideLayerAndSubtree(bool hide);
358 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_; }
360 void SetReplicaLayer(Layer* layer);
361 Layer* replica_layer() { return replica_layer_.get(); }
362 const Layer* replica_layer() const { return replica_layer_.get(); }
364 bool has_mask() const { return !!mask_layer_.get(); }
365 bool has_replica() const { return !!replica_layer_.get(); }
366 bool replica_has_mask() const {
367 return replica_layer_.get() &&
368 (mask_layer_.get() || replica_layer_->mask_layer_.get());
371 int NumDescendantsThatDrawContent() const;
373 // This is only virtual for tests.
374 // TODO(awoloszyn): Remove this once we no longer need it for tests
375 virtual bool DrawsContent() const;
377 // This methods typically need to be overwritten by derived classes.
378 virtual void SavePaintProperties();
379 // Returns true iff any resources were updated that need to be committed.
380 virtual bool Update(ResourceUpdateQueue* queue,
381 const OcclusionTracker<Layer>* occlusion);
382 virtual bool NeedMoreUpdates();
383 virtual void SetIsMask(bool is_mask) {}
384 virtual void ReduceMemoryUsage() {}
385 virtual void OnOutputSurfaceCreated() {}
386 virtual bool IsSuitableForGpuRasterization() const;
388 virtual scoped_refptr<base::trace_event::ConvertableToTraceFormat>
389 TakeDebugInfo();
391 void SetLayerClient(LayerClient* client) { client_ = client; }
393 virtual void PushPropertiesTo(LayerImpl* layer);
395 void CreateRenderSurface();
396 void ClearRenderSurface();
398 void ClearRenderSurfaceLayerList();
400 // The contents scale converts from logical, non-page-scaled pixels to target
401 // pixels. The contents scale is 1 for the root layer as it is already in
402 // physical pixels. By default contents scale is forced to be 1 except for
403 // subclasses of ContentsScalingLayer.
404 float contents_scale_x() const { return draw_properties_.contents_scale_x; }
405 float contents_scale_y() const { return draw_properties_.contents_scale_y; }
406 gfx::Size content_bounds() const { return draw_properties_.content_bounds; }
408 virtual void CalculateContentsScale(float ideal_contents_scale,
409 float* contents_scale_x,
410 float* contents_scale_y,
411 gfx::Size* content_bounds);
413 LayerTreeHost* layer_tree_host() { return layer_tree_host_; }
414 const LayerTreeHost* layer_tree_host() const { return layer_tree_host_; }
416 // Set the priority of all desired textures in this layer.
417 virtual void SetTexturePriorities(const PriorityCalculator& priority_calc) {}
419 bool AddAnimation(scoped_ptr<Animation> animation);
420 void PauseAnimation(int animation_id, double time_offset);
421 void RemoveAnimation(int animation_id);
422 void RemoveAnimation(int animation_id, Animation::TargetProperty property);
424 LayerAnimationController* layer_animation_controller() {
425 return layer_animation_controller_.get();
427 void SetLayerAnimationControllerForTest(
428 scoped_refptr<LayerAnimationController> controller);
430 void set_layer_animation_delegate(AnimationDelegate* delegate) {
431 DCHECK(layer_animation_controller_);
432 layer_animation_controller_->set_layer_animation_delegate(delegate);
435 bool HasActiveAnimation() const;
436 void RegisterForAnimations(AnimationRegistrar* registrar);
438 void AddLayerAnimationEventObserver(
439 LayerAnimationEventObserver* animation_observer);
440 void RemoveLayerAnimationEventObserver(
441 LayerAnimationEventObserver* animation_observer);
443 virtual SimpleEnclosedRegion VisibleContentOpaqueRegion() const;
445 virtual ScrollbarLayerInterface* ToScrollbarLayer();
447 gfx::Rect LayerRectToContentRect(const gfx::Rect& layer_rect) const;
449 virtual skia::RefPtr<SkPicture> GetPicture() const;
451 // Constructs a LayerImpl of the correct runtime type for this Layer type.
452 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl);
454 bool NeedsDisplayForTesting() const { return !update_rect_.IsEmpty(); }
455 void ResetNeedsDisplayForTesting() { update_rect_ = gfx::Rect(); }
457 RenderingStatsInstrumentation* rendering_stats_instrumentation() const;
459 const PaintProperties& paint_properties() const {
460 return paint_properties_;
463 // The scale at which contents should be rastered, to match the scale at
464 // which they will drawn to the screen. This scale is a component of the
465 // contents scale but does not include page/device scale factors.
466 // TODO(danakj): This goes away when TiledLayer goes away.
467 void set_raster_scale(float scale) { raster_scale_ = scale; }
468 float raster_scale() const { return raster_scale_; }
469 bool raster_scale_is_unknown() const { return raster_scale_ == 0.f; }
471 void SetNeedsPushProperties();
472 bool needs_push_properties() const { return needs_push_properties_; }
473 bool descendant_needs_push_properties() const {
474 return num_dependents_need_push_properties_ > 0;
476 void reset_needs_push_properties_for_testing() {
477 needs_push_properties_ = false;
480 virtual void RunMicroBenchmark(MicroBenchmark* benchmark);
482 void Set3dSortingContextId(int id);
483 int sorting_context_id() const { return sorting_context_id_; }
485 void set_property_tree_sequence_number(int sequence_number) {
486 property_tree_sequence_number_ = sequence_number;
489 void SetTransformTreeIndex(int index);
490 int transform_tree_index() const;
492 void SetClipTreeIndex(int index);
493 int clip_tree_index() const;
495 void SetOpacityTreeIndex(int index);
496 int opacity_tree_index() const;
498 void set_offset_to_transform_parent(gfx::Vector2dF offset) {
499 if (offset_to_transform_parent_ == offset)
500 return;
501 offset_to_transform_parent_ = offset;
502 SetNeedsPushProperties();
504 gfx::Vector2dF offset_to_transform_parent() const {
505 return offset_to_transform_parent_;
508 // TODO(vollick): Once we transition to transform and clip trees, rename these
509 // functions and related values. The "from property trees" functions below
510 // use the transform and clip trees. Eventually, we will use these functions
511 // to compute the official values, but these functions are retained for
512 // testing purposes until we've migrated.
514 const gfx::Rect& visible_rect_from_property_trees() const {
515 return visible_rect_from_property_trees_;
517 void set_visible_rect_from_property_trees(const gfx::Rect& rect) {
518 // No push properties here, as this acts like a draw property.
519 visible_rect_from_property_trees_ = rect;
522 void set_should_flatten_transform_from_property_tree(bool should_flatten) {
523 if (should_flatten_transform_from_property_tree_ == should_flatten)
524 return;
525 should_flatten_transform_from_property_tree_ = should_flatten;
526 SetNeedsPushProperties();
528 bool should_flatten_transform_from_property_tree() const {
529 return should_flatten_transform_from_property_tree_;
532 // TODO(vollick): These values are temporary and will be removed as soon as
533 // render surface determinations are moved out of CDP. They only exist because
534 // certain logic depends on whether or not a layer would render to a separate
535 // surface, but CDP destroys surfaces and targets it doesn't need, so without
536 // this boolean, this is impossible to determine after the fact without
537 // wastefully recomputing it. This is public for the time being so that it can
538 // be accessed from CDP.
539 bool has_render_surface() const {
540 return has_render_surface_;
543 // Sets new frame timing requests for this layer.
544 void SetFrameTimingRequests(const std::vector<FrameTimingRequest>& requests);
546 // Accessor for unit tests
547 const std::vector<FrameTimingRequest>& FrameTimingRequests() const {
548 return frame_timing_requests_;
551 void DidBeginTracing();
552 void set_num_layer_or_descandant_with_copy_request(
553 int num_layer_or_descendants_with_copy_request) {
554 num_layer_or_descendants_with_copy_request_ =
555 num_layer_or_descendants_with_copy_request;
558 void set_num_layer_or_descandant_with_input_handler(
559 int num_layer_or_descendants_with_input_handler) {
560 num_layer_or_descendants_with_input_handler_ =
561 num_layer_or_descendants_with_input_handler;
564 int num_layer_or_descendants_with_input_handler() {
565 return num_layer_or_descendants_with_input_handler_;
568 void set_num_children_with_scroll_parent(
569 int num_children_with_scroll_parent) {
570 num_children_with_scroll_parent_ = num_children_with_scroll_parent;
573 int num_children_with_scroll_parent() {
574 return num_children_with_scroll_parent_;
577 void set_visited(bool visited);
578 bool visited();
579 void set_layer_or_descendant_is_drawn(bool layer_or_descendant_is_drawn);
580 bool layer_or_descendant_is_drawn();
581 void set_sorted_for_recursion(bool sorted_for_recursion);
582 bool sorted_for_recursion();
584 protected:
585 friend class LayerImpl;
586 friend class TreeSynchronizer;
587 ~Layer() override;
589 explicit Layer(const LayerSettings& settings);
591 // These SetNeeds functions are in order of severity of update:
593 // Called when this layer has been modified in some way, but isn't sure
594 // that it needs a commit yet. It needs CalcDrawProperties and UpdateLayers
595 // before it knows whether or not a commit is required.
596 void SetNeedsUpdate();
597 // Called when a property has been modified in a way that the layer
598 // knows immediately that a commit is required. This implies SetNeedsUpdate
599 // as well as SetNeedsPushProperties to push that property.
600 void SetNeedsCommit();
601 // This is identical to SetNeedsCommit, but the former requests a rebuild of
602 // the property trees.
603 void SetNeedsCommitNoRebuild();
604 // Called when there's been a change in layer structure. Implies both
605 // SetNeedsUpdate and SetNeedsCommit, but not SetNeedsPushProperties.
606 void SetNeedsFullTreeSync();
608 // Called when the next commit should wait until the pending tree is activated
609 // before finishing the commit and unblocking the main thread. Used to ensure
610 // unused resources on the impl thread are returned before commit completes.
611 void SetNextCommitWaitsForActivation();
613 // Will recalculate whether the layer draws content and set draws_content_
614 // appropriately.
615 void UpdateDrawsContent(bool has_drawable_content);
616 virtual bool HasDrawableContent() const;
618 // Called when the layer's number of drawable descendants changes.
619 void AddDrawableDescendants(int num);
621 void AddDependentNeedsPushProperties();
622 void RemoveDependentNeedsPushProperties();
623 bool parent_should_know_need_push_properties() const {
624 return needs_push_properties() || descendant_needs_push_properties();
627 bool IsPropertyChangeAllowed() const;
629 void reset_raster_scale_to_unknown() { raster_scale_ = 0.f; }
631 // This flag is set when the layer needs to push properties to the impl
632 // side.
633 bool needs_push_properties_;
635 // The number of direct children or dependent layers that need to be recursed
636 // to in order for them or a descendent of them to push properties to the impl
637 // side.
638 int num_dependents_need_push_properties_;
640 // Tracks whether this layer may have changed stacking order with its
641 // siblings.
642 bool stacking_order_changed_;
644 // The update rect is the region of the compositor resource that was
645 // actually updated by the compositor. For layers that may do updating
646 // outside the compositor's control (i.e. plugin layers), this information
647 // is not available and the update rect will remain empty.
648 // Note this rect is in layer space (not content space).
649 gfx::Rect update_rect_;
651 scoped_refptr<Layer> mask_layer_;
653 int layer_id_;
655 // When true, the layer is about to perform an update. Any commit requests
656 // will be handled implicitly after the update completes.
657 bool ignore_set_needs_commit_;
659 // Layers that share a sorting context id will be sorted together in 3d
660 // space. 0 is a special value that means this layer will not be sorted and
661 // will be drawn in paint order.
662 int sorting_context_id_;
664 private:
665 friend class base::RefCounted<Layer>;
666 friend class LayerTreeHostCommon;
667 void SetParent(Layer* layer);
668 bool DescendantIsFixedToContainerLayer() const;
670 // This should only be called during BeginMainFrame since it does not
671 // trigger a Commit.
672 void SetHasRenderSurface(bool has_render_surface);
674 // Returns the index of the child or -1 if not found.
675 int IndexOfChild(const Layer* reference);
677 // This should only be called from RemoveFromParent().
678 void RemoveChildOrDependent(Layer* child);
680 // LayerAnimationValueProvider implementation.
681 gfx::ScrollOffset ScrollOffsetForAnimation() const override;
683 // LayerAnimationValueObserver implementation.
684 void OnFilterAnimated(const FilterOperations& filters) override;
685 void OnOpacityAnimated(float opacity) override;
686 void OnTransformAnimated(const gfx::Transform& transform) override;
687 void OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) override;
688 void OnAnimationWaitingForDeletion() override;
689 bool IsActive() const override;
691 // If this layer has a scroll parent, it removes |this| from its list of
692 // scroll children.
693 void RemoveFromScrollTree();
695 // If this layer has a clip parent, it removes |this| from its list of clip
696 // children.
697 void RemoveFromClipTree();
699 void UpdateNumCopyRequestsForSubtree(bool add);
700 void UpdateNumInputHandlersForSubtree(bool add);
702 LayerList children_;
703 Layer* parent_;
705 // Layer instances have a weak pointer to their LayerTreeHost.
706 // This pointer value is nil when a Layer is not in a tree and is
707 // updated via SetLayerTreeHost() if a layer moves between trees.
708 LayerTreeHost* layer_tree_host_;
710 scoped_refptr<LayerAnimationController> layer_animation_controller_;
712 // Layer properties.
713 gfx::Size bounds_;
715 gfx::ScrollOffset scroll_offset_;
716 gfx::Vector2dF scroll_compensation_adjustment_;
717 // This variable indicates which ancestor layer (if any) whose size,
718 // transformed relative to this layer, defines the maximum scroll offset for
719 // this layer.
720 int scroll_clip_layer_id_;
721 int num_descendants_that_draw_content_;
722 int transform_tree_index_;
723 int opacity_tree_index_;
724 int clip_tree_index_;
725 int property_tree_sequence_number_;
726 int num_layer_or_descendants_with_copy_request_;
727 int num_layer_or_descendants_with_input_handler_;
728 int num_children_with_scroll_parent_;
729 gfx::Vector2dF offset_to_transform_parent_;
730 bool should_flatten_transform_from_property_tree_ : 1;
731 bool should_scroll_on_main_thread_ : 1;
732 bool have_wheel_event_handlers_ : 1;
733 bool have_scroll_event_handlers_ : 1;
734 bool user_scrollable_horizontal_ : 1;
735 bool user_scrollable_vertical_ : 1;
736 bool is_root_for_isolated_group_ : 1;
737 bool is_container_for_fixed_position_layers_ : 1;
738 bool is_drawable_ : 1;
739 bool draws_content_ : 1;
740 bool hide_layer_and_subtree_ : 1;
741 bool masks_to_bounds_ : 1;
742 bool contents_opaque_ : 1;
743 bool double_sided_ : 1;
744 bool should_flatten_transform_ : 1;
745 bool use_parent_backface_visibility_ : 1;
746 bool draw_checkerboard_for_missing_tiles_ : 1;
747 bool force_render_surface_ : 1;
748 bool transform_is_invertible_ : 1;
749 bool has_render_surface_ : 1;
750 ScrollBlocksOn scroll_blocks_on_ : 3;
751 Region non_fast_scrollable_region_;
752 Region touch_event_handler_region_;
753 gfx::PointF position_;
754 SkColor background_color_;
755 float opacity_;
756 SkXfermode::Mode blend_mode_;
757 FilterOperations filters_;
758 FilterOperations background_filters_;
759 LayerPositionConstraint position_constraint_;
760 Layer* scroll_parent_;
761 scoped_ptr<std::set<Layer*>> scroll_children_;
763 // The following three variables are tracker variables. They are bools
764 // wrapped inside an integer variable. If true, their value equals the
765 // LayerTreeHost's meta_information_sequence_number. This wrapping of bools
766 // inside ints is done to avoid a layer tree treewalk to reset their values.
767 int layer_or_descendant_is_drawn_tracker_;
768 int sorted_for_recursion_tracker_;
769 int visited_tracker_;
771 Layer* clip_parent_;
772 scoped_ptr<std::set<Layer*>> clip_children_;
774 gfx::Transform transform_;
775 gfx::Point3F transform_origin_;
777 // Replica layer used for reflections.
778 scoped_refptr<Layer> replica_layer_;
780 // Transient properties.
781 float raster_scale_;
783 LayerClient* client_;
785 ScopedPtrVector<CopyOutputRequest> copy_requests_;
787 base::Closure did_scroll_callback_;
789 DrawProperties<Layer> draw_properties_;
791 PaintProperties paint_properties_;
792 // TODO(awoloszyn): This is redundant with has_render_surface_,
793 // and should get removed once it is no longer needed on main thread.
794 scoped_ptr<RenderSurface> render_surface_;
796 gfx::Rect visible_rect_from_property_trees_;
798 std::vector<FrameTimingRequest> frame_timing_requests_;
799 bool frame_timing_requests_dirty_;
801 DISALLOW_COPY_AND_ASSIGN(Layer);
804 } // namespace cc
806 #endif // CC_LAYERS_LAYER_H_