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.
4
5#ifndef CC_LAYERS_LAYER_IMPL_H_
6#define CC_LAYERS_LAYER_IMPL_H_
7
8#include <set>
9#include <string>
10
11#include "base/logging.h"
12#include "base/memory/scoped_ptr.h"
13#include "base/values.h"
14#include "cc/animation/animation_delegate.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/input/input_handler.h"
22#include "cc/layers/draw_properties.h"
23#include "cc/layers/layer_lists.h"
24#include "cc/layers/layer_position_constraint.h"
25#include "cc/layers/render_surface_impl.h"
26#include "cc/output/filter_operations.h"
27#include "cc/quads/shared_quad_state.h"
28#include "cc/resources/resource_provider.h"
29#include "skia/ext/refptr.h"
30#include "third_party/skia/include/core/SkColor.h"
31#include "third_party/skia/include/core/SkImageFilter.h"
32#include "third_party/skia/include/core/SkPicture.h"
33#include "ui/gfx/point3_f.h"
34#include "ui/gfx/rect.h"
35#include "ui/gfx/rect_f.h"
36#include "ui/gfx/transform.h"
37
38namespace base {
39namespace debug {
40class ConvertableToTraceFormat;
41class TracedValue;
42}
43
44class DictionaryValue;
45}
46
47namespace cc {
48
49class LayerTreeHostImpl;
50class LayerTreeImpl;
51class MicroBenchmarkImpl;
52class Occlusion;
53template <typename LayerType>
54class OcclusionTracker;
55class RenderPass;
56class RenderPassId;
57class Renderer;
58class ScrollbarAnimationController;
59class ScrollbarLayerImplBase;
60class SimpleEnclosedRegion;
61class Tile;
62
63struct AppendQuadsData;
64
65enum DrawMode {
66  DRAW_MODE_NONE,
67  DRAW_MODE_HARDWARE,
68  DRAW_MODE_SOFTWARE,
69  DRAW_MODE_RESOURCELESS_SOFTWARE
70};
71
72class CC_EXPORT LayerImpl : public LayerAnimationValueObserver,
73                            public LayerAnimationValueProvider,
74                            public AnimationDelegate {
75 public:
76  // Allows for the ownership of the total scroll offset to be delegated outside
77  // of the layer.
78  class ScrollOffsetDelegate {
79   public:
80    virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_value) = 0;
81    virtual gfx::Vector2dF GetTotalScrollOffset() = 0;
82    virtual bool IsExternalFlingActive() const = 0;
83  };
84
85  typedef LayerImplList RenderSurfaceListType;
86  typedef LayerImplList LayerListType;
87  typedef RenderSurfaceImpl RenderSurfaceType;
88
89  enum RenderingContextConstants { NO_RENDERING_CONTEXT = 0 };
90
91  static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) {
92    return make_scoped_ptr(new LayerImpl(tree_impl, id));
93  }
94
95  virtual ~LayerImpl();
96
97  int id() const { return layer_id_; }
98
99  // LayerAnimationValueProvider implementation.
100  virtual gfx::Vector2dF ScrollOffsetForAnimation() const OVERRIDE;
101
102  // LayerAnimationValueObserver implementation.
103  virtual void OnFilterAnimated(const FilterOperations& filters) OVERRIDE;
104  virtual void OnOpacityAnimated(float opacity) OVERRIDE;
105  virtual void OnTransformAnimated(const gfx::Transform& transform) OVERRIDE;
106  virtual void OnScrollOffsetAnimated(
107      const gfx::Vector2dF& scroll_offset) OVERRIDE;
108  virtual void OnAnimationWaitingForDeletion() OVERRIDE;
109  virtual bool IsActive() const OVERRIDE;
110
111  // AnimationDelegate implementation.
112  virtual void NotifyAnimationStarted(
113      base::TimeTicks monotonic_time,
114      Animation::TargetProperty target_property) OVERRIDE{};
115  virtual void NotifyAnimationFinished(
116      base::TimeTicks monotonic_time,
117      Animation::TargetProperty target_property) OVERRIDE;
118
119  // Tree structure.
120  LayerImpl* parent() { return parent_; }
121  const LayerImpl* parent() const { return parent_; }
122  const OwnedLayerImplList& children() const { return children_; }
123  OwnedLayerImplList& children() { return children_; }
124  LayerImpl* child_at(size_t index) const { return children_[index]; }
125  void AddChild(scoped_ptr<LayerImpl> child);
126  scoped_ptr<LayerImpl> RemoveChild(LayerImpl* child);
127  void SetParent(LayerImpl* parent);
128
129  // Warning: This does not preserve tree structure invariants.
130  void ClearChildList();
131
132  bool HasAncestor(const LayerImpl* ancestor) const;
133
134  void SetScrollParent(LayerImpl* parent);
135
136  LayerImpl* scroll_parent() { return scroll_parent_; }
137  const LayerImpl* scroll_parent() const { return scroll_parent_; }
138
139  void SetScrollChildren(std::set<LayerImpl*>* children);
140
141  std::set<LayerImpl*>* scroll_children() { return scroll_children_.get(); }
142  const std::set<LayerImpl*>* scroll_children() const {
143    return scroll_children_.get();
144  }
145
146  void SetNumDescendantsThatDrawContent(int num_descendants);
147  void SetClipParent(LayerImpl* ancestor);
148
149  LayerImpl* clip_parent() {
150    return clip_parent_;
151  }
152  const LayerImpl* clip_parent() const {
153    return clip_parent_;
154  }
155
156  void SetClipChildren(std::set<LayerImpl*>* children);
157
158  std::set<LayerImpl*>* clip_children() { return clip_children_.get(); }
159  const std::set<LayerImpl*>* clip_children() const {
160    return clip_children_.get();
161  }
162
163  void PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests);
164  // Can only be called when the layer has a copy request.
165  void TakeCopyRequestsAndTransformToTarget(
166      ScopedPtrVector<CopyOutputRequest>* request);
167  bool HasCopyRequest() const { return !copy_requests_.empty(); }
168
169  void SetMaskLayer(scoped_ptr<LayerImpl> mask_layer);
170  LayerImpl* mask_layer() { return mask_layer_.get(); }
171  const LayerImpl* mask_layer() const { return mask_layer_.get(); }
172  scoped_ptr<LayerImpl> TakeMaskLayer();
173
174  void SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer);
175  LayerImpl* replica_layer() { return replica_layer_.get(); }
176  const LayerImpl* replica_layer() const { return replica_layer_.get(); }
177  scoped_ptr<LayerImpl> TakeReplicaLayer();
178
179  bool has_mask() const { return mask_layer_; }
180  bool has_replica() const { return replica_layer_; }
181  bool replica_has_mask() const {
182    return replica_layer_ && (mask_layer_ || replica_layer_->mask_layer_);
183  }
184
185  LayerTreeImpl* layer_tree_impl() const { return layer_tree_impl_; }
186
187  void PopulateSharedQuadState(SharedQuadState* state) const;
188  // WillDraw must be called before AppendQuads. If WillDraw returns false,
189  // AppendQuads and DidDraw will not be called. If WillDraw returns true,
190  // DidDraw is guaranteed to be called before another WillDraw or before
191  // the layer is destroyed. To enforce this, any class that overrides
192  // WillDraw/DidDraw must call the base class version only if WillDraw
193  // returns true.
194  virtual bool WillDraw(DrawMode draw_mode,
195                        ResourceProvider* resource_provider);
196  virtual void AppendQuads(RenderPass* render_pass,
197                           const OcclusionTracker<LayerImpl>& occlusion_tracker,
198                           AppendQuadsData* append_quads_data) {}
199  virtual void DidDraw(ResourceProvider* resource_provider);
200
201  virtual ResourceProvider::ResourceId ContentsResourceId() const;
202
203  virtual bool HasDelegatedContent() const;
204  virtual bool HasContributingDelegatedRenderPasses() const;
205  virtual RenderPassId FirstContributingRenderPassId() const;
206  virtual RenderPassId NextContributingRenderPassId(RenderPassId id) const;
207
208  virtual void UpdateTiles(const Occlusion& occlusion_in_layer_space,
209                           bool resourceless_software_draw) {}
210  virtual void NotifyTileStateChanged(const Tile* tile) {}
211
212  virtual ScrollbarLayerImplBase* ToScrollbarLayer();
213
214  // Returns true if this layer has content to draw.
215  void SetDrawsContent(bool draws_content);
216  bool DrawsContent() const { return draws_content_; }
217
218  int NumDescendantsThatDrawContent() const;
219  void SetHideLayerAndSubtree(bool hide);
220  bool hide_layer_and_subtree() const { return hide_layer_and_subtree_; }
221
222  bool force_render_surface() const { return force_render_surface_; }
223  void SetForceRenderSurface(bool force) { force_render_surface_ = force; }
224
225  void SetTransformOrigin(const gfx::Point3F& transform_origin);
226  gfx::Point3F transform_origin() const { return transform_origin_; }
227
228  void SetBackgroundColor(SkColor background_color);
229  SkColor background_color() const { return background_color_; }
230  // If contents_opaque(), return an opaque color else return a
231  // non-opaque color.  Tries to return background_color(), if possible.
232  SkColor SafeOpaqueBackgroundColor() const;
233
234  void SetFilters(const FilterOperations& filters);
235  const FilterOperations& filters() const { return filters_; }
236  bool FilterIsAnimating() const;
237  bool FilterIsAnimatingOnImplOnly() const;
238
239  void SetBackgroundFilters(const FilterOperations& filters);
240  const FilterOperations& background_filters() const {
241    return background_filters_;
242  }
243
244  void SetMasksToBounds(bool masks_to_bounds);
245  bool masks_to_bounds() const { return masks_to_bounds_; }
246
247  void SetContentsOpaque(bool opaque);
248  bool contents_opaque() const { return contents_opaque_; }
249
250  void SetOpacity(float opacity);
251  float opacity() const { return opacity_; }
252  bool OpacityIsAnimating() const;
253  bool OpacityIsAnimatingOnImplOnly() const;
254
255  void SetBlendMode(SkXfermode::Mode);
256  SkXfermode::Mode blend_mode() const { return blend_mode_; }
257  bool uses_default_blend_mode() const {
258    return blend_mode_ == SkXfermode::kSrcOver_Mode;
259  }
260
261  void SetIsRootForIsolatedGroup(bool root);
262  bool is_root_for_isolated_group() const {
263    return is_root_for_isolated_group_;
264  }
265
266  void SetPosition(const gfx::PointF& position);
267  gfx::PointF position() const { return position_; }
268
269  void SetIsContainerForFixedPositionLayers(bool container) {
270    is_container_for_fixed_position_layers_ = container;
271  }
272  // This is a non-trivial function in Layer.
273  bool IsContainerForFixedPositionLayers() const {
274    return is_container_for_fixed_position_layers_;
275  }
276
277  gfx::Vector2dF FixedContainerSizeDelta() const;
278
279  void SetPositionConstraint(const LayerPositionConstraint& constraint) {
280    position_constraint_ = constraint;
281  }
282  const LayerPositionConstraint& position_constraint() const {
283    return position_constraint_;
284  }
285
286  void SetShouldFlattenTransform(bool flatten);
287  bool should_flatten_transform() const { return should_flatten_transform_; }
288
289  bool Is3dSorted() const { return sorting_context_id_ != 0; }
290
291  void SetUseParentBackfaceVisibility(bool use) {
292    use_parent_backface_visibility_ = use;
293  }
294  bool use_parent_backface_visibility() const {
295    return use_parent_backface_visibility_;
296  }
297
298  bool ShowDebugBorders() const;
299
300  // These invalidate the host's render surface layer list.  The caller
301  // is responsible for calling set_needs_update_draw_properties on the tree
302  // so that its list can be recreated.
303  void CreateRenderSurface();
304  void ClearRenderSurface();
305  void ClearRenderSurfaceLayerList();
306
307  DrawProperties<LayerImpl>& draw_properties() {
308    return draw_properties_;
309  }
310  const DrawProperties<LayerImpl>& draw_properties() const {
311    return draw_properties_;
312  }
313
314  // The following are shortcut accessors to get various information from
315  // draw_properties_
316  const gfx::Transform& draw_transform() const {
317    return draw_properties_.target_space_transform;
318  }
319  const gfx::Transform& screen_space_transform() const {
320    return draw_properties_.screen_space_transform;
321  }
322  float draw_opacity() const { return draw_properties_.opacity; }
323  bool draw_opacity_is_animating() const {
324    return draw_properties_.opacity_is_animating;
325  }
326  bool draw_transform_is_animating() const {
327    return draw_properties_.target_space_transform_is_animating;
328  }
329  bool screen_space_transform_is_animating() const {
330    return draw_properties_.screen_space_transform_is_animating;
331  }
332  bool screen_space_opacity_is_animating() const {
333    return draw_properties_.screen_space_opacity_is_animating;
334  }
335  bool can_use_lcd_text() const { return draw_properties_.can_use_lcd_text; }
336  bool is_clipped() const { return draw_properties_.is_clipped; }
337  gfx::Rect clip_rect() const { return draw_properties_.clip_rect; }
338  gfx::Rect drawable_content_rect() const {
339    return draw_properties_.drawable_content_rect;
340  }
341  gfx::Rect visible_content_rect() const {
342    return draw_properties_.visible_content_rect;
343  }
344  LayerImpl* render_target() {
345    DCHECK(!draw_properties_.render_target ||
346           draw_properties_.render_target->render_surface());
347    return draw_properties_.render_target;
348  }
349  const LayerImpl* render_target() const {
350    DCHECK(!draw_properties_.render_target ||
351           draw_properties_.render_target->render_surface());
352    return draw_properties_.render_target;
353  }
354  RenderSurfaceImpl* render_surface() const {
355    return draw_properties_.render_surface.get();
356  }
357  int num_unclipped_descendants() const {
358    return draw_properties_.num_unclipped_descendants;
359  }
360
361  // The client should be responsible for setting bounds, content bounds and
362  // contents scale to appropriate values. LayerImpl doesn't calculate any of
363  // them from the other values.
364
365  void SetBounds(const gfx::Size& bounds);
366  gfx::Size bounds() const;
367  void SetBoundsDelta(const gfx::Vector2dF& bounds_delta);
368  gfx::Vector2dF bounds_delta() const { return bounds_delta_; }
369
370  void SetContentBounds(const gfx::Size& content_bounds);
371  gfx::Size content_bounds() const { return draw_properties_.content_bounds; }
372
373  float contents_scale_x() const { return draw_properties_.contents_scale_x; }
374  float contents_scale_y() const { return draw_properties_.contents_scale_y; }
375  void SetContentsScale(float contents_scale_x, float contents_scale_y);
376
377  void SetScrollOffsetDelegate(ScrollOffsetDelegate* scroll_offset_delegate);
378  bool IsExternalFlingActive() const;
379
380  void SetScrollOffset(const gfx::Vector2d& scroll_offset);
381  void SetScrollOffsetAndDelta(const gfx::Vector2d& scroll_offset,
382                               const gfx::Vector2dF& scroll_delta);
383  gfx::Vector2d scroll_offset() const { return scroll_offset_; }
384
385  gfx::Vector2d MaxScrollOffset() const;
386  gfx::Vector2dF ClampScrollToMaxScrollOffset();
387  void SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
388                            LayerImpl* scrollbar_clip_layer) const;
389  void SetScrollDelta(const gfx::Vector2dF& scroll_delta);
390  gfx::Vector2dF ScrollDelta() const;
391
392  gfx::Vector2dF TotalScrollOffset() const;
393
394  void SetSentScrollDelta(const gfx::Vector2d& sent_scroll_delta);
395  gfx::Vector2d sent_scroll_delta() const { return sent_scroll_delta_; }
396
397  // Returns the delta of the scroll that was outside of the bounds of the
398  // initial scroll
399  gfx::Vector2dF ScrollBy(const gfx::Vector2dF& scroll);
400
401  void SetScrollClipLayer(int scroll_clip_layer_id);
402  LayerImpl* scroll_clip_layer() const { return scroll_clip_layer_; }
403  bool scrollable() const { return !!scroll_clip_layer_; }
404
405  void set_user_scrollable_horizontal(bool scrollable) {
406    user_scrollable_horizontal_ = scrollable;
407  }
408  void set_user_scrollable_vertical(bool scrollable) {
409    user_scrollable_vertical_ = scrollable;
410  }
411
412  void ApplySentScrollDeltasFromAbortedCommit();
413  void ApplyScrollDeltasSinceBeginMainFrame();
414
415  void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) {
416    should_scroll_on_main_thread_ = should_scroll_on_main_thread;
417  }
418  bool should_scroll_on_main_thread() const {
419    return should_scroll_on_main_thread_;
420  }
421
422  void SetHaveWheelEventHandlers(bool have_wheel_event_handlers) {
423    have_wheel_event_handlers_ = have_wheel_event_handlers;
424  }
425  bool have_wheel_event_handlers() const { return have_wheel_event_handlers_; }
426
427  void SetHaveScrollEventHandlers(bool have_scroll_event_handlers) {
428    have_scroll_event_handlers_ = have_scroll_event_handlers;
429  }
430  bool have_scroll_event_handlers() const {
431    return have_scroll_event_handlers_;
432  }
433
434  void SetNonFastScrollableRegion(const Region& region) {
435    non_fast_scrollable_region_ = region;
436  }
437  const Region& non_fast_scrollable_region() const {
438    return non_fast_scrollable_region_;
439  }
440
441  void SetTouchEventHandlerRegion(const Region& region) {
442    touch_event_handler_region_ = region;
443  }
444  const Region& touch_event_handler_region() const {
445    return touch_event_handler_region_;
446  }
447
448  void SetDrawCheckerboardForMissingTiles(bool checkerboard) {
449    draw_checkerboard_for_missing_tiles_ = checkerboard;
450  }
451  bool draw_checkerboard_for_missing_tiles() const {
452    return draw_checkerboard_for_missing_tiles_;
453  }
454
455  InputHandler::ScrollStatus TryScroll(
456      const gfx::PointF& screen_space_point,
457      InputHandler::ScrollInputType type) const;
458
459  void SetDoubleSided(bool double_sided);
460  bool double_sided() const { return double_sided_; }
461
462  void SetTransform(const gfx::Transform& transform);
463  const gfx::Transform& transform() const { return transform_; }
464  bool TransformIsAnimating() const;
465  bool TransformIsAnimatingOnImplOnly() const;
466  void SetTransformAndInvertibility(const gfx::Transform& transform,
467                                    bool transform_is_invertible);
468  bool transform_is_invertible() const { return transform_is_invertible_; }
469
470  // Note this rect is in layer space (not content space).
471  void SetUpdateRect(const gfx::RectF& update_rect);
472
473  const gfx::RectF& update_rect() const { return update_rect_; }
474
475  void AddDamageRect(const gfx::RectF& damage_rect);
476
477  const gfx::RectF& damage_rect() const { return damage_rect_; }
478
479  virtual base::DictionaryValue* LayerTreeAsJson() const;
480
481  void SetStackingOrderChanged(bool stacking_order_changed);
482
483  bool LayerPropertyChanged() const { return layer_property_changed_; }
484
485  void ResetAllChangeTrackingForSubtree();
486
487  LayerAnimationController* layer_animation_controller() {
488    return layer_animation_controller_.get();
489  }
490
491  const LayerAnimationController* layer_animation_controller() const {
492    return layer_animation_controller_.get();
493  }
494
495  virtual SimpleEnclosedRegion VisibleContentOpaqueRegion() const;
496
497  virtual void DidBecomeActive();
498
499  virtual void DidBeginTracing();
500
501  // Release resources held by this layer. Called when the output surface
502  // that rendered this layer was lost or a rendering mode switch has occured.
503  virtual void ReleaseResources();
504
505  ScrollbarAnimationController* scrollbar_animation_controller() const {
506    return scrollbar_animation_controller_.get();
507  }
508
509  typedef std::set<ScrollbarLayerImplBase*> ScrollbarSet;
510  ScrollbarSet* scrollbars() { return scrollbars_.get(); }
511  void ClearScrollbars();
512  void AddScrollbar(ScrollbarLayerImplBase* layer);
513  void RemoveScrollbar(ScrollbarLayerImplBase* layer);
514  bool HasScrollbar(ScrollbarOrientation orientation) const;
515  void ScrollbarParametersDidChange();
516  int clip_height() {
517    return scroll_clip_layer_ ? scroll_clip_layer_->bounds().height() : 0;
518  }
519
520  gfx::Rect LayerRectToContentRect(const gfx::RectF& layer_rect) const;
521
522  virtual skia::RefPtr<SkPicture> GetPicture();
523
524  virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl);
525  virtual void PushPropertiesTo(LayerImpl* layer);
526
527  virtual void GetAllTilesForTracing(std::set<const Tile*>* tiles) const;
528  virtual void AsValueInto(base::debug::TracedValue* dict) const;
529
530  virtual size_t GPUMemoryUsageInBytes() const;
531
532  void SetNeedsPushProperties();
533  void AddDependentNeedsPushProperties();
534  void RemoveDependentNeedsPushProperties();
535  bool parent_should_know_need_push_properties() const {
536    return needs_push_properties() || descendant_needs_push_properties();
537  }
538
539  bool needs_push_properties() const { return needs_push_properties_; }
540  bool descendant_needs_push_properties() const {
541    return num_dependents_need_push_properties_ > 0;
542  }
543
544  virtual void RunMicroBenchmark(MicroBenchmarkImpl* benchmark);
545
546  virtual void SetDebugInfo(
547      scoped_refptr<base::debug::ConvertableToTraceFormat> other);
548
549  bool IsDrawnRenderSurfaceLayerListMember() const;
550
551  void Set3dSortingContextId(int id);
552  int sorting_context_id() { return sorting_context_id_; }
553
554 protected:
555  LayerImpl(LayerTreeImpl* layer_impl, int id);
556
557  // Get the color and size of the layer's debug border.
558  virtual void GetDebugBorderProperties(SkColor* color, float* width) const;
559
560  void AppendDebugBorderQuad(RenderPass* render_pass,
561                             const gfx::Size& content_bounds,
562                             const SharedQuadState* shared_quad_state,
563                             AppendQuadsData* append_quads_data) const;
564  void AppendDebugBorderQuad(RenderPass* render_pass,
565                             const gfx::Size& content_bounds,
566                             const SharedQuadState* shared_quad_state,
567                             AppendQuadsData* append_quads_data,
568                             SkColor color,
569                             float width) const;
570
571  void NoteLayerPropertyChanged();
572  void NoteLayerPropertyChangedForSubtree();
573
574  // Note carefully this does not affect the current layer.
575  void NoteLayerPropertyChangedForDescendants();
576
577 private:
578  void NoteLayerPropertyChangedForDescendantsInternal();
579
580  virtual const char* LayerTypeAsString() const;
581
582  // Properties internal to LayerImpl
583  LayerImpl* parent_;
584  OwnedLayerImplList children_;
585
586  LayerImpl* scroll_parent_;
587
588  // Storing a pointer to a set rather than a set since this will be rarely
589  // used. If this pointer turns out to be too heavy, we could have this (and
590  // the scroll parent above) be stored in a LayerImpl -> scroll_info
591  // map somewhere.
592  scoped_ptr<std::set<LayerImpl*> > scroll_children_;
593
594  LayerImpl* clip_parent_;
595  scoped_ptr<std::set<LayerImpl*> > clip_children_;
596
597  // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
598  // confirm newly assigned layer is still the previous one
599  int mask_layer_id_;
600  scoped_ptr<LayerImpl> mask_layer_;
601  int replica_layer_id_;  // ditto
602  scoped_ptr<LayerImpl> replica_layer_;
603  int layer_id_;
604  LayerTreeImpl* layer_tree_impl_;
605
606  // Properties synchronized from the associated Layer.
607  gfx::Point3F transform_origin_;
608  gfx::Size bounds_;
609  gfx::Vector2dF bounds_delta_;
610  gfx::Vector2d scroll_offset_;
611  ScrollOffsetDelegate* scroll_offset_delegate_;
612  LayerImpl* scroll_clip_layer_;
613  bool scrollable_ : 1;
614  bool should_scroll_on_main_thread_ : 1;
615  bool have_wheel_event_handlers_ : 1;
616  bool have_scroll_event_handlers_ : 1;
617  bool user_scrollable_horizontal_ : 1;
618  bool user_scrollable_vertical_ : 1;
619  bool stacking_order_changed_ : 1;
620  // Whether the "back" of this layer should draw.
621  bool double_sided_ : 1;
622  bool should_flatten_transform_ : 1;
623
624  // Tracks if drawing-related properties have changed since last redraw.
625  bool layer_property_changed_ : 1;
626
627  bool masks_to_bounds_ : 1;
628  bool contents_opaque_ : 1;
629  bool is_root_for_isolated_group_ : 1;
630  bool use_parent_backface_visibility_ : 1;
631  bool draw_checkerboard_for_missing_tiles_ : 1;
632  bool draws_content_ : 1;
633  bool hide_layer_and_subtree_ : 1;
634  bool force_render_surface_ : 1;
635
636  // Cache transform_'s invertibility.
637  bool transform_is_invertible_ : 1;
638
639  // Set for the layer that other layers are fixed to.
640  bool is_container_for_fixed_position_layers_ : 1;
641  Region non_fast_scrollable_region_;
642  Region touch_event_handler_region_;
643  SkColor background_color_;
644
645  float opacity_;
646  SkXfermode::Mode blend_mode_;
647  gfx::PointF position_;
648  gfx::Transform transform_;
649
650  LayerPositionConstraint position_constraint_;
651
652  gfx::Vector2dF scroll_delta_;
653  gfx::Vector2d sent_scroll_delta_;
654  gfx::Vector2dF last_scroll_offset_;
655
656  int num_descendants_that_draw_content_;
657
658  // The global depth value of the center of the layer. This value is used
659  // to sort layers from back to front.
660  float draw_depth_;
661
662  FilterOperations filters_;
663  FilterOperations background_filters_;
664
665 protected:
666  friend class TreeSynchronizer;
667
668  // This flag is set when the layer needs to push properties to the active
669  // side.
670  bool needs_push_properties_;
671
672  // The number of direct children or dependent layers that need to be recursed
673  // to in order for them or a descendent of them to push properties to the
674  // active side.
675  int num_dependents_need_push_properties_;
676
677  // Layers that share a sorting context id will be sorted together in 3d
678  // space.  0 is a special value that means this layer will not be sorted and
679  // will be drawn in paint order.
680  int sorting_context_id_;
681
682  DrawMode current_draw_mode_;
683
684 private:
685  // Rect indicating what was repainted/updated during update.
686  // Note that plugin layers bypass this and leave it empty.
687  // Uses layer (not content) space.
688  gfx::RectF update_rect_;
689
690  // This rect is in layer space.
691  gfx::RectF damage_rect_;
692
693  // Manages animations for this layer.
694  scoped_refptr<LayerAnimationController> layer_animation_controller_;
695
696  // Manages scrollbars for this layer
697  scoped_ptr<ScrollbarAnimationController> scrollbar_animation_controller_;
698
699  scoped_ptr<ScrollbarSet> scrollbars_;
700
701  ScopedPtrVector<CopyOutputRequest> copy_requests_;
702
703  // Group of properties that need to be computed based on the layer tree
704  // hierarchy before layers can be drawn.
705  DrawProperties<LayerImpl> draw_properties_;
706
707  scoped_refptr<base::debug::ConvertableToTraceFormat> debug_info_;
708
709  DISALLOW_COPY_AND_ASSIGN(LayerImpl);
710};
711
712}  // namespace cc
713
714#endif  // CC_LAYERS_LAYER_IMPL_H_
715