[Chromoting] Remove check for out/Release dir in build-webapp.py
[chromium-blink-merge.git] / cc / layers / layer_impl.h
blob6fc5cb296f9e10ce6269dd96c63decdcfb285fa2
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/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"
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 template <typename LayerType>
61 class OcclusionTracker;
62 class OpacityTree;
63 class RenderPass;
64 class RenderPassId;
65 class Renderer;
66 class ScrollbarAnimationController;
67 class ScrollbarLayerImplBase;
68 class SimpleEnclosedRegion;
69 class Tile;
70 class TransformTree;
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 bool IsActive() const override;
118 // AnimationDelegate implementation.
119 void NotifyAnimationStarted(base::TimeTicks monotonic_time,
120 Animation::TargetProperty target_property,
121 int group) override{};
122 void NotifyAnimationFinished(base::TimeTicks monotonic_time,
123 Animation::TargetProperty target_property,
124 int group) override;
126 // Tree structure.
127 LayerImpl* parent() { return parent_; }
128 const LayerImpl* parent() const { return parent_; }
129 const OwnedLayerImplList& children() const { return children_; }
130 OwnedLayerImplList& children() { return children_; }
131 LayerImpl* child_at(size_t index) const { return children_[index]; }
132 void AddChild(scoped_ptr<LayerImpl> child);
133 scoped_ptr<LayerImpl> RemoveChild(LayerImpl* child);
134 void SetParent(LayerImpl* parent);
136 // Warning: This does not preserve tree structure invariants.
137 void ClearChildList();
139 bool HasAncestor(const LayerImpl* ancestor) const;
141 void SetScrollParent(LayerImpl* parent);
143 LayerImpl* scroll_parent() { return scroll_parent_; }
144 const LayerImpl* scroll_parent() const { return scroll_parent_; }
146 void SetScrollChildren(std::set<LayerImpl*>* children);
148 std::set<LayerImpl*>* scroll_children() { return scroll_children_.get(); }
149 const std::set<LayerImpl*>* scroll_children() const {
150 return scroll_children_.get();
153 void set_transform_tree_index(int index) {
154 transform_tree_index_ = index;
155 SetNeedsPushProperties();
157 void set_clip_tree_index(int index) {
158 clip_tree_index_ = index;
159 SetNeedsPushProperties();
161 void set_opacity_tree_index(int index) {
162 opacity_tree_index_ = index;
163 SetNeedsPushProperties();
165 int clip_tree_index() const { return clip_tree_index_; }
166 int transform_tree_index() const { return transform_tree_index_; }
167 int opacity_tree_index() const { return opacity_tree_index_; }
169 void set_offset_to_transform_parent(const gfx::Vector2dF& offset) {
170 offset_to_transform_parent_ = offset;
171 SetNeedsPushProperties();
173 gfx::Vector2dF offset_to_transform_parent() const {
174 return offset_to_transform_parent_;
177 const gfx::Rect& visible_rect_from_property_trees() const {
178 return visible_rect_from_property_trees_;
180 void set_visible_rect_from_property_trees(const gfx::Rect& rect) {
181 visible_rect_from_property_trees_ = rect;
184 void set_should_flatten_transform_from_property_tree(bool should_flatten) {
185 should_flatten_transform_from_property_tree_ = should_flatten;
186 SetNeedsPushProperties();
188 bool should_flatten_transform_from_property_tree() const {
189 return should_flatten_transform_from_property_tree_;
192 // For compatibility with Layer.
193 bool has_render_surface() const { return !!render_surface(); }
195 void SetNumDescendantsThatDrawContent(int num_descendants);
196 void SetClipParent(LayerImpl* ancestor);
198 LayerImpl* clip_parent() {
199 return clip_parent_;
201 const LayerImpl* clip_parent() const {
202 return clip_parent_;
205 void SetClipChildren(std::set<LayerImpl*>* children);
207 std::set<LayerImpl*>* clip_children() { return clip_children_.get(); }
208 const std::set<LayerImpl*>* clip_children() const {
209 return clip_children_.get();
212 void PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests);
213 // Can only be called when the layer has a copy request.
214 void TakeCopyRequestsAndTransformToTarget(
215 ScopedPtrVector<CopyOutputRequest>* request);
216 bool HasCopyRequest() const { return !copy_requests_.empty(); }
218 void SetMaskLayer(scoped_ptr<LayerImpl> mask_layer);
219 LayerImpl* mask_layer() { return mask_layer_.get(); }
220 const LayerImpl* mask_layer() const { return mask_layer_.get(); }
221 scoped_ptr<LayerImpl> TakeMaskLayer();
223 void SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer);
224 LayerImpl* replica_layer() { return replica_layer_.get(); }
225 const LayerImpl* replica_layer() const { return replica_layer_.get(); }
226 scoped_ptr<LayerImpl> TakeReplicaLayer();
228 bool has_mask() const { return mask_layer_; }
229 bool has_replica() const { return replica_layer_; }
230 bool replica_has_mask() const {
231 return replica_layer_ && (mask_layer_ || replica_layer_->mask_layer_);
234 LayerTreeImpl* layer_tree_impl() const { return layer_tree_impl_; }
236 void PopulateSharedQuadState(SharedQuadState* state) const;
237 void PopulateScaledSharedQuadState(SharedQuadState* state, float scale) const;
238 // WillDraw must be called before AppendQuads. If WillDraw returns false,
239 // AppendQuads and DidDraw will not be called. If WillDraw returns true,
240 // DidDraw is guaranteed to be called before another WillDraw or before
241 // the layer is destroyed. To enforce this, any class that overrides
242 // WillDraw/DidDraw must call the base class version only if WillDraw
243 // returns true.
244 virtual bool WillDraw(DrawMode draw_mode,
245 ResourceProvider* resource_provider);
246 virtual void AppendQuads(RenderPass* render_pass,
247 AppendQuadsData* append_quads_data) {}
248 virtual void DidDraw(ResourceProvider* resource_provider);
250 // Verify that the resource ids in the quad are valid.
251 void ValidateQuadResources(DrawQuad* quad) const {
252 #if DCHECK_IS_ON()
253 ValidateQuadResourcesInternal(quad);
254 #endif
257 virtual void GetContentsResourceId(ResourceProvider::ResourceId* resource_id,
258 gfx::Size* resource_size) const;
260 virtual bool HasDelegatedContent() const;
261 virtual bool HasContributingDelegatedRenderPasses() const;
262 virtual RenderPassId FirstContributingRenderPassId() const;
263 virtual RenderPassId NextContributingRenderPassId(RenderPassId id) const;
265 virtual void NotifyTileStateChanged(const Tile* tile) {}
267 virtual ScrollbarLayerImplBase* ToScrollbarLayer();
269 // Returns true if this layer has content to draw.
270 void SetDrawsContent(bool draws_content);
271 bool DrawsContent() const { return draws_content_; }
273 int NumDescendantsThatDrawContent() const;
274 void SetHideLayerAndSubtree(bool hide);
275 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_; }
277 void SetTransformOrigin(const gfx::Point3F& transform_origin);
278 gfx::Point3F transform_origin() const { return transform_origin_; }
280 void SetBackgroundColor(SkColor background_color);
281 SkColor background_color() const { return background_color_; }
282 // If contents_opaque(), return an opaque color else return a
283 // non-opaque color. Tries to return background_color(), if possible.
284 SkColor SafeOpaqueBackgroundColor() const;
286 void SetFilters(const FilterOperations& filters);
287 const FilterOperations& filters() const { return filters_; }
288 bool FilterIsAnimating() const;
289 bool FilterIsAnimatingOnImplOnly() const;
291 void SetBackgroundFilters(const FilterOperations& filters);
292 const FilterOperations& background_filters() const {
293 return background_filters_;
296 void SetMasksToBounds(bool masks_to_bounds);
297 bool masks_to_bounds() const { return masks_to_bounds_; }
299 void SetContentsOpaque(bool opaque);
300 bool contents_opaque() const { return contents_opaque_; }
302 void SetOpacity(float opacity);
303 float opacity() const { return opacity_; }
304 bool OpacityIsAnimating() const;
305 bool OpacityIsAnimatingOnImplOnly() const;
307 void SetBlendMode(SkXfermode::Mode);
308 SkXfermode::Mode blend_mode() const { return blend_mode_; }
309 bool uses_default_blend_mode() const {
310 return blend_mode_ == SkXfermode::kSrcOver_Mode;
313 void SetIsRootForIsolatedGroup(bool root);
314 bool is_root_for_isolated_group() const {
315 return is_root_for_isolated_group_;
318 void SetPosition(const gfx::PointF& position);
319 gfx::PointF position() const { return position_; }
321 void SetIsContainerForFixedPositionLayers(bool container) {
322 is_container_for_fixed_position_layers_ = container;
324 // This is a non-trivial function in Layer.
325 bool IsContainerForFixedPositionLayers() const {
326 return is_container_for_fixed_position_layers_;
329 gfx::Vector2dF FixedContainerSizeDelta() const;
331 void SetPositionConstraint(const LayerPositionConstraint& constraint) {
332 position_constraint_ = constraint;
334 const LayerPositionConstraint& position_constraint() const {
335 return position_constraint_;
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 SetUseParentBackfaceVisibility(bool use) {
344 use_parent_backface_visibility_ = use;
346 bool use_parent_backface_visibility() const {
347 return use_parent_backface_visibility_;
350 bool ShowDebugBorders() const;
352 // These invalidate the host's render surface layer list. The caller
353 // is responsible for calling set_needs_update_draw_properties on the tree
354 // so that its list can be recreated.
355 void ClearRenderSurfaceLayerList();
356 void SetHasRenderSurface(bool has_render_surface);
358 RenderSurfaceImpl* render_surface() const { return render_surface_.get(); }
360 DrawProperties<LayerImpl>& draw_properties() {
361 return draw_properties_;
363 const DrawProperties<LayerImpl>& draw_properties() const {
364 return draw_properties_;
367 // The following are shortcut accessors to get various information from
368 // draw_properties_
369 const gfx::Transform& draw_transform() const {
370 return draw_properties_.target_space_transform;
372 const gfx::Transform& screen_space_transform() const {
373 return draw_properties_.screen_space_transform;
375 float draw_opacity() const { return draw_properties_.opacity; }
376 SkXfermode::Mode draw_blend_mode() const {
377 return draw_properties_.blend_mode;
379 bool draw_opacity_is_animating() const {
380 return draw_properties_.opacity_is_animating;
382 bool draw_transform_is_animating() const {
383 return draw_properties_.target_space_transform_is_animating;
385 bool screen_space_transform_is_animating() const {
386 return draw_properties_.screen_space_transform_is_animating;
388 bool screen_space_opacity_is_animating() const {
389 return draw_properties_.screen_space_opacity_is_animating;
391 bool can_use_lcd_text() const { return draw_properties_.can_use_lcd_text; }
392 bool is_clipped() const { return draw_properties_.is_clipped; }
393 gfx::Rect clip_rect() const { return draw_properties_.clip_rect; }
394 gfx::Rect drawable_content_rect() const {
395 return draw_properties_.drawable_content_rect;
397 gfx::Rect visible_content_rect() const {
398 return draw_properties_.visible_content_rect;
400 LayerImpl* render_target() {
401 DCHECK(!draw_properties_.render_target ||
402 draw_properties_.render_target->render_surface());
403 return draw_properties_.render_target;
405 const LayerImpl* render_target() const {
406 DCHECK(!draw_properties_.render_target ||
407 draw_properties_.render_target->render_surface());
408 return draw_properties_.render_target;
411 int num_unclipped_descendants() const {
412 return draw_properties_.num_unclipped_descendants;
415 // The client should be responsible for setting bounds, content bounds and
416 // contents scale to appropriate values. LayerImpl doesn't calculate any of
417 // them from the other values.
419 void SetBounds(const gfx::Size& bounds);
420 gfx::Size bounds() const;
421 // Like bounds() but doesn't snap to int. Lossy on giant pages (e.g. millions
422 // of pixels) due to use of single precision float.
423 gfx::SizeF BoundsForScrolling() const;
424 void SetBoundsDelta(const gfx::Vector2dF& bounds_delta);
425 gfx::Vector2dF bounds_delta() const { return bounds_delta_; }
427 void SetContentBounds(const gfx::Size& content_bounds);
428 gfx::Size content_bounds() const { return draw_properties_.content_bounds; }
430 float contents_scale_x() const { return draw_properties_.contents_scale_x; }
431 float contents_scale_y() const { return draw_properties_.contents_scale_y; }
432 void SetContentsScale(float contents_scale_x, float contents_scale_y);
434 bool IsExternalFlingActive() const;
436 void SetCurrentScrollOffset(const gfx::ScrollOffset& scroll_offset);
437 void SetCurrentScrollOffsetFromDelegate(
438 const gfx::ScrollOffset& scroll_offset);
439 void PushScrollOffsetFromMainThread(const gfx::ScrollOffset& scroll_offset);
440 // This method is similar to PushScrollOffsetFromMainThread but will cause the
441 // scroll offset given to clobber any scroll changes on the active tree in the
442 // time until this value is pushed to the active tree.
443 void PushScrollOffsetFromMainThreadAndClobberActiveValue(
444 const gfx::ScrollOffset& scroll_offset);
445 gfx::ScrollOffset PullDeltaForMainThread();
446 gfx::ScrollOffset CurrentScrollOffset() const;
447 gfx::ScrollOffset BaseScrollOffset() const;
448 gfx::Vector2dF ScrollDelta() const;
449 void SetScrollDelta(const gfx::Vector2dF& delta);
451 gfx::ScrollOffset MaxScrollOffset() const;
452 gfx::ScrollOffset ClampScrollOffsetToLimits(gfx::ScrollOffset offset) const;
453 gfx::Vector2dF ClampScrollToMaxScrollOffset();
454 void SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
455 LayerImpl* scrollbar_clip_layer,
456 bool on_resize) const;
457 void SetScrollCompensationAdjustment(const gfx::Vector2dF& scroll_offset) {
458 scroll_compensation_adjustment_ = scroll_offset;
460 gfx::Vector2dF ScrollCompensationAdjustment() const {
461 return scroll_compensation_adjustment_;
464 // Returns the delta of the scroll that was outside of the bounds of the
465 // initial scroll
466 gfx::Vector2dF ScrollBy(const gfx::Vector2dF& scroll);
468 void SetScrollClipLayer(int scroll_clip_layer_id);
469 LayerImpl* scroll_clip_layer() const { return scroll_clip_layer_; }
470 bool scrollable() const { return !!scroll_clip_layer_; }
472 void set_user_scrollable_horizontal(bool scrollable) {
473 user_scrollable_horizontal_ = scrollable;
475 bool user_scrollable_horizontal() const {
476 return user_scrollable_horizontal_;
478 void set_user_scrollable_vertical(bool scrollable) {
479 user_scrollable_vertical_ = scrollable;
481 bool user_scrollable_vertical() const { return user_scrollable_vertical_; }
483 bool user_scrollable(ScrollbarOrientation orientation) const;
485 void ApplySentScrollDeltasFromAbortedCommit();
487 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) {
488 should_scroll_on_main_thread_ = should_scroll_on_main_thread;
490 bool should_scroll_on_main_thread() const {
491 return should_scroll_on_main_thread_;
494 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers) {
495 have_wheel_event_handlers_ = have_wheel_event_handlers;
497 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_; }
499 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers) {
500 have_scroll_event_handlers_ = have_scroll_event_handlers;
502 bool have_scroll_event_handlers() const {
503 return have_scroll_event_handlers_;
506 void SetNonFastScrollableRegion(const Region& region) {
507 non_fast_scrollable_region_ = region;
509 const Region& non_fast_scrollable_region() const {
510 return non_fast_scrollable_region_;
513 void SetTouchEventHandlerRegion(const Region& region) {
514 touch_event_handler_region_ = region;
516 const Region& touch_event_handler_region() const {
517 return touch_event_handler_region_;
520 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on) {
521 scroll_blocks_on_ = scroll_blocks_on;
523 ScrollBlocksOn scroll_blocks_on() const { return scroll_blocks_on_; }
524 void SetDrawCheckerboardForMissingTiles(bool checkerboard) {
525 draw_checkerboard_for_missing_tiles_ = checkerboard;
527 bool draw_checkerboard_for_missing_tiles() const {
528 return draw_checkerboard_for_missing_tiles_;
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 TransformIsAnimatingOnImplOnly() const;
543 void SetTransformAndInvertibility(const gfx::Transform& transform,
544 bool transform_is_invertible);
545 bool transform_is_invertible() const { return transform_is_invertible_; }
547 // Note this rect is in layer space (not content space).
548 void SetUpdateRect(const gfx::Rect& update_rect);
549 gfx::Rect update_rect() const { return update_rect_; }
551 void AddDamageRect(const gfx::RectF& damage_rect);
553 const gfx::RectF& damage_rect() const { return damage_rect_; }
555 virtual base::DictionaryValue* LayerTreeAsJson() const;
557 void SetStackingOrderChanged(bool stacking_order_changed);
559 bool LayerPropertyChanged() const { return layer_property_changed_; }
561 void ResetAllChangeTrackingForSubtree();
563 LayerAnimationController* layer_animation_controller() {
564 return layer_animation_controller_.get();
567 const LayerAnimationController* layer_animation_controller() const {
568 return layer_animation_controller_.get();
571 virtual SimpleEnclosedRegion VisibleContentOpaqueRegion() const;
573 virtual void DidBecomeActive();
575 virtual void DidBeginTracing();
577 // Release resources held by this layer. Called when the output surface
578 // that rendered this layer was lost or a rendering mode switch has occured.
579 virtual void ReleaseResources();
581 // Recreate resources that are required after they were released by a
582 // ReleaseResources call.
583 virtual void RecreateResources();
585 ScrollbarAnimationController* scrollbar_animation_controller() const {
586 return scrollbar_animation_controller_.get();
589 typedef std::set<ScrollbarLayerImplBase*> ScrollbarSet;
590 ScrollbarSet* scrollbars() { return scrollbars_.get(); }
591 void ClearScrollbars();
592 void AddScrollbar(ScrollbarLayerImplBase* layer);
593 void RemoveScrollbar(ScrollbarLayerImplBase* layer);
594 bool HasScrollbar(ScrollbarOrientation orientation) const;
595 void ScrollbarParametersDidChange(bool on_resize);
596 int clip_height() {
597 return scroll_clip_layer_ ? scroll_clip_layer_->bounds().height() : 0;
600 gfx::Rect LayerRectToContentRect(const gfx::RectF& layer_rect) const;
602 virtual skia::RefPtr<SkPicture> GetPicture();
604 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl);
605 virtual void PushPropertiesTo(LayerImpl* layer);
607 virtual void GetAllTilesAndPrioritiesForTracing(
608 std::map<const Tile*, TilePriority>* tile_map) const;
609 virtual void AsValueInto(base::trace_event::TracedValue* dict) const;
611 virtual size_t GPUMemoryUsageInBytes() const;
613 void SetNeedsPushProperties();
614 void AddDependentNeedsPushProperties();
615 void RemoveDependentNeedsPushProperties();
616 bool parent_should_know_need_push_properties() const {
617 return needs_push_properties() || descendant_needs_push_properties();
620 bool needs_push_properties() const { return needs_push_properties_; }
621 bool descendant_needs_push_properties() const {
622 return num_dependents_need_push_properties_ > 0;
625 virtual void RunMicroBenchmark(MicroBenchmarkImpl* benchmark);
627 virtual void SetDebugInfo(
628 scoped_refptr<base::trace_event::ConvertableToTraceFormat> other);
630 bool IsDrawnRenderSurfaceLayerListMember() const;
632 void Set3dSortingContextId(int id);
633 int sorting_context_id() { return sorting_context_id_; }
635 void PassFrameTimingRequests(
636 std::vector<FrameTimingRequest>* frame_timing_requests);
637 const std::vector<FrameTimingRequest>& frame_timing_requests() const {
638 return frame_timing_requests_;
640 void GatherFrameTimingRequestIds(std::vector<int64_t>* request_ids);
642 SyncedScrollOffset* synced_scroll_offset() { return scroll_offset_.get(); }
644 // Get the correct invalidation region instead of conservative Rect
645 // for layers that provide it.
646 virtual Region GetInvalidationRegion();
648 virtual gfx::Rect GetEnclosingRectInTargetSpace() const;
650 protected:
651 LayerImpl(LayerTreeImpl* layer_impl,
652 int id,
653 scoped_refptr<SyncedScrollOffset> scroll_offset);
654 LayerImpl(LayerTreeImpl* layer_impl, int id);
656 // Get the color and size of the layer's debug border.
657 virtual void GetDebugBorderProperties(SkColor* color, float* width) const;
659 void AppendDebugBorderQuad(RenderPass* render_pass,
660 const gfx::Size& content_bounds,
661 const SharedQuadState* shared_quad_state,
662 AppendQuadsData* append_quads_data) const;
663 void AppendDebugBorderQuad(RenderPass* render_pass,
664 const gfx::Size& content_bounds,
665 const SharedQuadState* shared_quad_state,
666 AppendQuadsData* append_quads_data,
667 SkColor color,
668 float width) const;
670 void NoteLayerPropertyChanged();
671 void NoteLayerPropertyChangedForSubtree();
673 // Note carefully this does not affect the current layer.
674 void NoteLayerPropertyChangedForDescendants();
676 gfx::Rect GetScaledEnclosingRectInTargetSpace(float scale) const;
678 private:
679 void ValidateQuadResourcesInternal(DrawQuad* quad) const;
681 void PushScrollOffset(const gfx::ScrollOffset* scroll_offset);
682 // If the new scroll offset is assigned from the root scroll offset delegate,
683 // LayerImpl won't inform the root scroll offset delegate about the scroll
684 // change to avoid feedback.
685 void DidUpdateScrollOffset(bool is_from_root_delegate);
686 void NoteLayerPropertyChangedForDescendantsInternal();
688 virtual const char* LayerTypeAsString() const;
690 // Properties internal to LayerImpl
691 LayerImpl* parent_;
692 OwnedLayerImplList children_;
694 LayerImpl* scroll_parent_;
696 // Storing a pointer to a set rather than a set since this will be rarely
697 // used. If this pointer turns out to be too heavy, we could have this (and
698 // the scroll parent above) be stored in a LayerImpl -> scroll_info
699 // map somewhere.
700 scoped_ptr<std::set<LayerImpl*>> scroll_children_;
702 LayerImpl* clip_parent_;
703 scoped_ptr<std::set<LayerImpl*>> clip_children_;
705 // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
706 // confirm newly assigned layer is still the previous one
707 int mask_layer_id_;
708 scoped_ptr<LayerImpl> mask_layer_;
709 int replica_layer_id_; // ditto
710 scoped_ptr<LayerImpl> replica_layer_;
711 int layer_id_;
712 LayerTreeImpl* layer_tree_impl_;
714 // Properties dynamically changeable on active tree.
715 scoped_refptr<SyncedScrollOffset> scroll_offset_;
716 gfx::Vector2dF bounds_delta_;
718 // Properties synchronized from the associated Layer.
719 gfx::Point3F transform_origin_;
720 gfx::Size bounds_;
721 LayerImpl* scroll_clip_layer_;
723 gfx::Vector2dF offset_to_transform_parent_;
725 bool scrollable_ : 1;
726 bool should_scroll_on_main_thread_ : 1;
727 bool have_wheel_event_handlers_ : 1;
728 bool have_scroll_event_handlers_ : 1;
730 static_assert(SCROLL_BLOCKS_ON_MAX < (1 << 3), "ScrollBlocksOn too big");
731 ScrollBlocksOn scroll_blocks_on_ : 3;
733 bool user_scrollable_horizontal_ : 1;
734 bool user_scrollable_vertical_ : 1;
735 bool stacking_order_changed_ : 1;
736 // Whether the "back" of this layer should draw.
737 bool double_sided_ : 1;
738 bool should_flatten_transform_ : 1;
739 bool should_flatten_transform_from_property_tree_ : 1;
741 // Tracks if drawing-related properties have changed since last redraw.
742 bool layer_property_changed_ : 1;
744 bool masks_to_bounds_ : 1;
745 bool contents_opaque_ : 1;
746 bool is_root_for_isolated_group_ : 1;
747 bool use_parent_backface_visibility_ : 1;
748 bool draw_checkerboard_for_missing_tiles_ : 1;
749 bool draws_content_ : 1;
750 bool hide_layer_and_subtree_ : 1;
752 // Cache transform_'s invertibility.
753 bool transform_is_invertible_ : 1;
755 // Set for the layer that other layers are fixed to.
756 bool is_container_for_fixed_position_layers_ : 1;
758 Region non_fast_scrollable_region_;
759 Region touch_event_handler_region_;
760 SkColor background_color_;
762 float opacity_;
763 SkXfermode::Mode blend_mode_;
764 gfx::PointF position_;
765 gfx::Transform transform_;
767 LayerPositionConstraint position_constraint_;
769 gfx::Vector2dF scroll_compensation_adjustment_;
771 int num_descendants_that_draw_content_;
773 gfx::Rect visible_rect_from_property_trees_;
774 int transform_tree_index_;
775 int opacity_tree_index_;
776 int clip_tree_index_;
778 // The global depth value of the center of the layer. This value is used
779 // to sort layers from back to front.
780 float draw_depth_;
782 FilterOperations filters_;
783 FilterOperations background_filters_;
785 protected:
786 friend class TreeSynchronizer;
788 // This flag is set when the layer needs to push properties to the active
789 // side.
790 bool needs_push_properties_;
792 // The number of direct children or dependent layers that need to be recursed
793 // to in order for them or a descendent of them to push properties to the
794 // active side.
795 int num_dependents_need_push_properties_;
797 // Layers that share a sorting context id will be sorted together in 3d
798 // space. 0 is a special value that means this layer will not be sorted and
799 // will be drawn in paint order.
800 int sorting_context_id_;
802 DrawMode current_draw_mode_;
804 private:
805 // Rect indicating what was repainted/updated during update.
806 // Note that plugin layers bypass this and leave it empty.
807 // Uses layer (not content) space.
808 gfx::Rect update_rect_;
810 // This rect is in layer space.
811 gfx::RectF damage_rect_;
813 // Manages animations for this layer.
814 scoped_refptr<LayerAnimationController> layer_animation_controller_;
816 // Manages scrollbars for this layer
817 scoped_ptr<ScrollbarAnimationController> scrollbar_animation_controller_;
819 scoped_ptr<ScrollbarSet> scrollbars_;
821 ScopedPtrVector<CopyOutputRequest> copy_requests_;
823 // Group of properties that need to be computed based on the layer tree
824 // hierarchy before layers can be drawn.
825 DrawProperties<LayerImpl> draw_properties_;
827 scoped_refptr<base::trace_event::ConvertableToTraceFormat> debug_info_;
828 scoped_ptr<RenderSurfaceImpl> render_surface_;
830 std::vector<FrameTimingRequest> frame_timing_requests_;
831 bool frame_timing_requests_dirty_;
833 DISALLOW_COPY_AND_ASSIGN(LayerImpl);
836 } // namespace cc
838 #endif // CC_LAYERS_LAYER_IMPL_H_