layer_impl.h 24 KB
Newer Older
1 2 3 4 5 6 7
// Copyright 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CC_LAYERS_LAYER_IMPL_H_
#define CC_LAYERS_LAYER_IMPL_H_

8
#include <set>
9 10 11 12 13 14 15
#include <string>

#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "base/values.h"
#include "cc/animation/layer_animation_controller.h"
#include "cc/animation/layer_animation_value_observer.h"
16
#include "cc/animation/layer_animation_value_provider.h"
17 18 19 20 21
#include "cc/base/cc_export.h"
#include "cc/base/region.h"
#include "cc/base/scoped_ptr_vector.h"
#include "cc/input/input_handler.h"
#include "cc/layers/draw_properties.h"
22 23
#include "cc/layers/layer_lists.h"
#include "cc/layers/layer_position_constraint.h"
24
#include "cc/layers/render_surface_impl.h"
25
#include "cc/output/filter_operations.h"
26 27 28 29 30 31 32
#include "cc/quads/render_pass.h"
#include "cc/quads/shared_quad_state.h"
#include "cc/resources/resource_provider.h"
#include "skia/ext/refptr.h"
#include "third_party/skia/include/core/SkColor.h"
#include "third_party/skia/include/core/SkImageFilter.h"
#include "third_party/skia/include/core/SkPicture.h"
33
#include "ui/gfx/point3_f.h"
34 35 36 37 38
#include "ui/gfx/rect.h"
#include "ui/gfx/rect_f.h"
#include "ui/gfx/transform.h"

namespace base {
39 40 41 42
namespace debug {
class ConvertableToTraceFormat;
}

43 44 45 46 47 48 49
class DictionaryValue;
}

namespace cc {

class LayerTreeHostImpl;
class LayerTreeImpl;
50
class MicroBenchmarkImpl;
51 52 53
class QuadSink;
class Renderer;
class ScrollbarAnimationController;
54
class ScrollbarLayerImplBase;
55
class Tile;
56 57 58

struct AppendQuadsData;

59 60 61 62 63 64 65
enum DrawMode {
  DRAW_MODE_NONE,
  DRAW_MODE_HARDWARE,
  DRAW_MODE_SOFTWARE,
  DRAW_MODE_RESOURCELESS_SOFTWARE
};

66 67
class CC_EXPORT LayerImpl : public LayerAnimationValueObserver,
                            public LayerAnimationValueProvider {
68
 public:
69 70 71 72 73 74 75 76 77
  // Allows for the ownership of the total scroll offset to be delegated outside
  // of the layer.
  class ScrollOffsetDelegate {
   public:
    virtual void SetTotalScrollOffset(const gfx::Vector2dF& new_value) = 0;
    virtual gfx::Vector2dF GetTotalScrollOffset() = 0;
    virtual bool IsExternalFlingActive() const = 0;
  };

78 79 80 81
  typedef LayerImplList RenderSurfaceListType;
  typedef LayerImplList LayerListType;
  typedef RenderSurfaceImpl RenderSurfaceType;

82 83
  enum RenderingContextConstants { NO_RENDERING_CONTEXT = 0 };

84 85 86 87 88 89 90 91
  static scoped_ptr<LayerImpl> Create(LayerTreeImpl* tree_impl, int id) {
    return make_scoped_ptr(new LayerImpl(tree_impl, id));
  }

  virtual ~LayerImpl();

  int id() const { return layer_id_; }

92 93 94
  // LayerAnimationValueProvider implementation.
  virtual gfx::Vector2dF ScrollOffsetForAnimation() const OVERRIDE;

95
  // LayerAnimationValueObserver implementation.
96
  virtual void OnFilterAnimated(const FilterOperations& filters) OVERRIDE;
97 98
  virtual void OnOpacityAnimated(float opacity) OVERRIDE;
  virtual void OnTransformAnimated(const gfx::Transform& transform) OVERRIDE;
99 100
  virtual void OnScrollOffsetAnimated(
      const gfx::Vector2dF& scroll_offset) OVERRIDE;
101
  virtual void OnAnimationWaitingForDeletion() OVERRIDE;
102 103 104 105 106
  virtual bool IsActive() const OVERRIDE;

  // Tree structure.
  LayerImpl* parent() { return parent_; }
  const LayerImpl* parent() const { return parent_; }
107 108
  const OwnedLayerImplList& children() const { return children_; }
  OwnedLayerImplList& children() { return children_; }
109 110 111
  LayerImpl* child_at(size_t index) const { return children_[index]; }
  void AddChild(scoped_ptr<LayerImpl> child);
  scoped_ptr<LayerImpl> RemoveChild(LayerImpl* child);
112 113
  void SetParent(LayerImpl* parent);

114 115 116
  // Warning: This does not preserve tree structure invariants.
  void ClearChildList();

117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
  bool HasAncestor(const LayerImpl* ancestor) const;

  void SetScrollParent(LayerImpl* parent);

  LayerImpl* scroll_parent() { return scroll_parent_; }
  const LayerImpl* scroll_parent() const { return scroll_parent_; }

  void SetScrollChildren(std::set<LayerImpl*>* children);

  std::set<LayerImpl*>* scroll_children() { return scroll_children_.get(); }
  const std::set<LayerImpl*>* scroll_children() const {
    return scroll_children_.get();
  }

  void SetClipParent(LayerImpl* ancestor);

  LayerImpl* clip_parent() {
    return clip_parent_;
  }
  const LayerImpl* clip_parent() const {
    return clip_parent_;
  }

  void SetClipChildren(std::set<LayerImpl*>* children);

  std::set<LayerImpl*>* clip_children() { return clip_children_.get(); }
  const std::set<LayerImpl*>* clip_children() const {
    return clip_children_.get();
  }

147
  void PassCopyRequests(ScopedPtrVector<CopyOutputRequest>* requests);
148
  // Can only be called when the layer has a copy request.
149 150
  void TakeCopyRequestsAndTransformToTarget(
      ScopedPtrVector<CopyOutputRequest>* request);
151
  bool HasCopyRequest() const { return !copy_requests_.empty(); }
152

153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
  void SetMaskLayer(scoped_ptr<LayerImpl> mask_layer);
  LayerImpl* mask_layer() { return mask_layer_.get(); }
  const LayerImpl* mask_layer() const { return mask_layer_.get(); }
  scoped_ptr<LayerImpl> TakeMaskLayer();

  void SetReplicaLayer(scoped_ptr<LayerImpl> replica_layer);
  LayerImpl* replica_layer() { return replica_layer_.get(); }
  const LayerImpl* replica_layer() const { return replica_layer_.get(); }
  scoped_ptr<LayerImpl> TakeReplicaLayer();

  bool has_mask() const { return mask_layer_; }
  bool has_replica() const { return replica_layer_; }
  bool replica_has_mask() const {
    return replica_layer_ && (mask_layer_ || replica_layer_->mask_layer_);
  }

  LayerTreeImpl* layer_tree_impl() const { return layer_tree_impl_; }

171
  void PopulateSharedQuadState(SharedQuadState* state) const;
172 173
  // WillDraw must be called before AppendQuads. If WillDraw returns false,
  // AppendQuads and DidDraw will not be called. If WillDraw returns true,
174 175
  // DidDraw is guaranteed to be called before another WillDraw or before
  // the layer is destroyed. To enforce this, any class that overrides
176 177 178 179
  // WillDraw/DidDraw must call the base class version only if WillDraw
  // returns true.
  virtual bool WillDraw(DrawMode draw_mode,
                        ResourceProvider* resource_provider);
180 181 182 183 184 185 186 187 188 189 190
  virtual void AppendQuads(QuadSink* quad_sink,
                           AppendQuadsData* append_quads_data) {}
  virtual void DidDraw(ResourceProvider* resource_provider);

  virtual ResourceProvider::ResourceId ContentsResourceId() const;

  virtual bool HasDelegatedContent() const;
  virtual bool HasContributingDelegatedRenderPasses() const;
  virtual RenderPass::Id FirstContributingRenderPassId() const;
  virtual RenderPass::Id NextContributingRenderPassId(RenderPass::Id id) const;

191
  virtual void UpdateTiles() {}
192
  virtual void NotifyTileStateChanged(const Tile* tile) {}
193

194
  virtual ScrollbarLayerImplBase* ToScrollbarLayer();
195 196 197 198 199

  // Returns true if this layer has content to draw.
  void SetDrawsContent(bool draws_content);
  bool DrawsContent() const { return draws_content_; }

200 201 202
  void SetHideLayerAndSubtree(bool hide);
  bool hide_layer_and_subtree() const { return hide_layer_and_subtree_; }

203 204 205
  bool force_render_surface() const { return force_render_surface_; }
  void SetForceRenderSurface(bool force) { force_render_surface_ = force; }

206 207
  void SetTransformOrigin(const gfx::Point3F& transform_origin);
  gfx::Point3F transform_origin() const { return transform_origin_; }
208 209 210

  void SetBackgroundColor(SkColor background_color);
  SkColor background_color() const { return background_color_; }
211 212 213
  // If contents_opaque(), return an opaque color else return a
  // non-opaque color.  Tries to return background_color(), if possible.
  SkColor SafeOpaqueBackgroundColor() const;
214

215 216
  void SetFilters(const FilterOperations& filters);
  const FilterOperations& filters() const { return filters_; }
217 218
  bool FilterIsAnimating() const;
  bool FilterIsAnimatingOnImplOnly() const;
219

220 221
  void SetBackgroundFilters(const FilterOperations& filters);
  const FilterOperations& background_filters() const {
222 223 224 225 226 227 228 229 230 231 232 233 234 235
    return background_filters_;
  }

  void SetMasksToBounds(bool masks_to_bounds);
  bool masks_to_bounds() const { return masks_to_bounds_; }

  void SetContentsOpaque(bool opaque);
  bool contents_opaque() const { return contents_opaque_; }

  void SetOpacity(float opacity);
  float opacity() const { return opacity_; }
  bool OpacityIsAnimating() const;
  bool OpacityIsAnimatingOnImplOnly() const;

236 237 238 239 240 241 242 243 244 245 246
  void SetBlendMode(SkXfermode::Mode);
  SkXfermode::Mode blend_mode() const { return blend_mode_; }
  bool uses_default_blend_mode() const {
    return blend_mode_ == SkXfermode::kSrcOver_Mode;
  }

  void SetIsRootForIsolatedGroup(bool root);
  bool is_root_for_isolated_group() const {
    return is_root_for_isolated_group_;
  }

247
  void SetPosition(const gfx::PointF& position);
248 249 250 251 252
  gfx::PointF position() const { return position_; }

  void SetIsContainerForFixedPositionLayers(bool container) {
    is_container_for_fixed_position_layers_ = container;
  }
253 254
  // This is a non-trivial function in Layer.
  bool IsContainerForFixedPositionLayers() const {
255 256 257
    return is_container_for_fixed_position_layers_;
  }

258
  gfx::Vector2dF FixedContainerSizeDelta() const;
259 260 261 262 263 264

  void SetPositionConstraint(const LayerPositionConstraint& constraint) {
    position_constraint_ = constraint;
  }
  const LayerPositionConstraint& position_constraint() const {
    return position_constraint_;
265 266
  }

267 268 269
  void SetShouldFlattenTransform(bool flatten);
  bool should_flatten_transform() const { return should_flatten_transform_; }

270
  bool Is3dSorted() const { return sorting_context_id_ != 0; }
271 272 273 274 275 276 277 278 279 280 281 282 283 284

  void SetUseParentBackfaceVisibility(bool use) {
    use_parent_backface_visibility_ = use;
  }
  bool use_parent_backface_visibility() const {
    return use_parent_backface_visibility_;
  }

  bool ShowDebugBorders() const;

  // These invalidate the host's render surface layer list.  The caller
  // is responsible for calling set_needs_update_draw_properties on the tree
  // so that its list can be recreated.
  void CreateRenderSurface();
285
  void ClearRenderSurface();
286
  void ClearRenderSurfaceLayerList();
287

288
  DrawProperties<LayerImpl>& draw_properties() {
289 290
    return draw_properties_;
  }
291
  const DrawProperties<LayerImpl>& draw_properties() const {
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
    return draw_properties_;
  }

  // The following are shortcut accessors to get various information from
  // draw_properties_
  const gfx::Transform& draw_transform() const {
    return draw_properties_.target_space_transform;
  }
  const gfx::Transform& screen_space_transform() const {
    return draw_properties_.screen_space_transform;
  }
  float draw_opacity() const { return draw_properties_.opacity; }
  bool draw_opacity_is_animating() const {
    return draw_properties_.opacity_is_animating;
  }
  bool draw_transform_is_animating() const {
    return draw_properties_.target_space_transform_is_animating;
  }
  bool screen_space_transform_is_animating() const {
    return draw_properties_.screen_space_transform_is_animating;
  }
  bool screen_space_opacity_is_animating() const {
    return draw_properties_.screen_space_opacity_is_animating;
  }
  bool can_use_lcd_text() const { return draw_properties_.can_use_lcd_text; }
  bool is_clipped() const { return draw_properties_.is_clipped; }
  gfx::Rect clip_rect() const { return draw_properties_.clip_rect; }
  gfx::Rect drawable_content_rect() const {
    return draw_properties_.drawable_content_rect;
  }
  gfx::Rect visible_content_rect() const {
    return draw_properties_.visible_content_rect;
  }
  LayerImpl* render_target() {
    DCHECK(!draw_properties_.render_target ||
           draw_properties_.render_target->render_surface());
    return draw_properties_.render_target;
  }
  const LayerImpl* render_target() const {
    DCHECK(!draw_properties_.render_target ||
           draw_properties_.render_target->render_surface());
    return draw_properties_.render_target;
  }
  RenderSurfaceImpl* render_surface() const {
336
    return draw_properties_.render_surface.get();
337
  }
338 339 340
  int num_unclipped_descendants() const {
    return draw_properties_.num_unclipped_descendants;
  }
341 342 343 344 345

  // The client should be responsible for setting bounds, content bounds and
  // contents scale to appropriate values. LayerImpl doesn't calculate any of
  // them from the other values.

346
  void SetBounds(const gfx::Size& bounds);
347 348 349 350 351 352
  void SetTemporaryImplBounds(const gfx::SizeF& bounds);
  gfx::Size bounds() const;
  gfx::Vector2dF BoundsDelta() const {
    return gfx::Vector2dF(temporary_impl_bounds_.width() - bounds_.width(),
                          temporary_impl_bounds_.height() - bounds_.height());
  }
353

354
  void SetContentBounds(const gfx::Size& content_bounds);
355 356 357 358 359 360
  gfx::Size content_bounds() const { return draw_properties_.content_bounds; }

  float contents_scale_x() const { return draw_properties_.contents_scale_x; }
  float contents_scale_y() const { return draw_properties_.contents_scale_y; }
  void SetContentsScale(float contents_scale_x, float contents_scale_y);

361
  void SetScrollOffsetDelegate(ScrollOffsetDelegate* scroll_offset_delegate);
362 363
  bool IsExternalFlingActive() const;

364 365 366
  void SetScrollOffset(const gfx::Vector2d& scroll_offset);
  void SetScrollOffsetAndDelta(const gfx::Vector2d& scroll_offset,
                               const gfx::Vector2dF& scroll_delta);
367 368
  gfx::Vector2d scroll_offset() const { return scroll_offset_; }

369 370 371 372 373
  gfx::Vector2d MaxScrollOffset() const;
  gfx::Vector2dF ClampScrollToMaxScrollOffset();
  void SetScrollbarPosition(ScrollbarLayerImplBase* scrollbar_layer,
                            LayerImpl* scrollbar_clip_layer) const;
  void SetScrollDelta(const gfx::Vector2dF& scroll_delta);
374
  gfx::Vector2dF ScrollDelta() const;
375 376 377

  gfx::Vector2dF TotalScrollOffset() const;

378
  void SetSentScrollDelta(const gfx::Vector2d& sent_scroll_delta);
379 380 381 382
  gfx::Vector2d sent_scroll_delta() const { return sent_scroll_delta_; }

  // Returns the delta of the scroll that was outside of the bounds of the
  // initial scroll
383
  gfx::Vector2dF ScrollBy(const gfx::Vector2dF& scroll);
384

385
  void SetScrollClipLayer(int scroll_clip_layer_id);
386
  LayerImpl* scroll_clip_layer() const { return scroll_clip_layer_; }
387
  bool scrollable() const { return !!scroll_clip_layer_; }
388

389 390 391 392 393 394 395
  void set_user_scrollable_horizontal(bool scrollable) {
    user_scrollable_horizontal_ = scrollable;
  }
  void set_user_scrollable_vertical(bool scrollable) {
    user_scrollable_vertical_ = scrollable;
  }

396
  void ApplySentScrollDeltasFromAbortedCommit();
397
  void ApplyScrollDeltasSinceBeginMainFrame();
398

399 400 401 402 403 404 405 406 407 408 409 410
  void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread) {
    should_scroll_on_main_thread_ = should_scroll_on_main_thread;
  }
  bool should_scroll_on_main_thread() const {
    return should_scroll_on_main_thread_;
  }

  void SetHaveWheelEventHandlers(bool have_wheel_event_handlers) {
    have_wheel_event_handlers_ = have_wheel_event_handlers;
  }
  bool have_wheel_event_handlers() const { return have_wheel_event_handlers_; }

411 412 413 414 415 416 417
  void SetHaveScrollEventHandlers(bool have_scroll_event_handlers) {
    have_scroll_event_handlers_ = have_scroll_event_handlers;
  }
  bool have_scroll_event_handlers() const {
    return have_scroll_event_handlers_;
  }

418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434
  void SetNonFastScrollableRegion(const Region& region) {
    non_fast_scrollable_region_ = region;
  }
  const Region& non_fast_scrollable_region() const {
    return non_fast_scrollable_region_;
  }

  void SetTouchEventHandlerRegion(const Region& region) {
    touch_event_handler_region_ = region;
  }
  const Region& touch_event_handler_region() const {
    return touch_event_handler_region_;
  }

  void SetDrawCheckerboardForMissingTiles(bool checkerboard) {
    draw_checkerboard_for_missing_tiles_ = checkerboard;
  }
435 436 437
  bool draw_checkerboard_for_missing_tiles() const {
    return draw_checkerboard_for_missing_tiles_;
  }
438

439
  InputHandler::ScrollStatus TryScroll(
440
      const gfx::PointF& screen_space_point,
441
      InputHandler::ScrollInputType type) const;
442 443 444 445 446 447 448 449

  void SetDoubleSided(bool double_sided);
  bool double_sided() const { return double_sided_; }

  void SetTransform(const gfx::Transform& transform);
  const gfx::Transform& transform() const { return transform_; }
  bool TransformIsAnimating() const;
  bool TransformIsAnimatingOnImplOnly() const;
450 451 452
  void SetTransformAndInvertibility(const gfx::Transform& transform,
                                    bool transform_is_invertible);
  bool transform_is_invertible() const { return transform_is_invertible_; }
453

454
  // Note this rect is in layer space (not content space).
455 456
  void SetUpdateRect(const gfx::RectF& update_rect);

457 458
  const gfx::RectF& update_rect() const { return update_rect_; }

459 460 461 462
  void AddDamageRect(const gfx::RectF& damage_rect);

  const gfx::RectF& damage_rect() const { return damage_rect_; }

463 464 465 466
  virtual base::DictionaryValue* LayerTreeAsJson() const;

  void SetStackingOrderChanged(bool stacking_order_changed);

467
  bool LayerPropertyChanged() const { return layer_property_changed_; }
468 469 470 471 472 473 474

  void ResetAllChangeTrackingForSubtree();

  LayerAnimationController* layer_animation_controller() {
    return layer_animation_controller_.get();
  }

475 476 477 478
  const LayerAnimationController* layer_animation_controller() const {
    return layer_animation_controller_.get();
  }

479 480 481 482
  virtual Region VisibleContentOpaqueRegion() const;

  virtual void DidBecomeActive();

483 484
  virtual void DidBeginTracing();

485 486 487
  // Release resources held by this layer. Called when the output surface
  // that rendered this layer was lost or a rendering mode switch has occured.
  virtual void ReleaseResources();
488 489 490 491 492

  ScrollbarAnimationController* scrollbar_animation_controller() const {
    return scrollbar_animation_controller_.get();
  }

493 494 495 496 497 498 499 500 501
  typedef std::set<ScrollbarLayerImplBase*> ScrollbarSet;
  ScrollbarSet* scrollbars() { return scrollbars_.get(); }
  void ClearScrollbars();
  void AddScrollbar(ScrollbarLayerImplBase* layer);
  void RemoveScrollbar(ScrollbarLayerImplBase* layer);
  bool HasScrollbar(ScrollbarOrientation orientation) const;
  void ScrollbarParametersDidChange();
  int clip_height() {
    return scroll_clip_layer_ ? scroll_clip_layer_->bounds().height() : 0;
502 503 504 505 506 507 508 509 510
  }

  gfx::Rect LayerRectToContentRect(const gfx::RectF& layer_rect) const;

  virtual skia::RefPtr<SkPicture> GetPicture();

  virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl);
  virtual void PushPropertiesTo(LayerImpl* layer);

511
  virtual void GetAllTilesForTracing(std::set<const Tile*>* tiles) const;
512
  scoped_ptr<base::Value> AsValue() const;
513
  virtual size_t GPUMemoryUsageInBytes() const;
514

515 516 517 518 519 520 521 522 523 524 525
  void SetNeedsPushProperties();
  void AddDependentNeedsPushProperties();
  void RemoveDependentNeedsPushProperties();
  bool parent_should_know_need_push_properties() const {
    return needs_push_properties() || descendant_needs_push_properties();
  }

  bool needs_push_properties() const { return needs_push_properties_; }
  bool descendant_needs_push_properties() const {
    return num_dependents_need_push_properties_ > 0;
  }
526

527 528
  virtual void RunMicroBenchmark(MicroBenchmarkImpl* benchmark);

529 530 531
  virtual void SetDebugInfo(
      scoped_refptr<base::debug::ConvertableToTraceFormat> other);

532 533
  bool IsDrawnRenderSurfaceLayerListMember() const;

534 535 536
  void Set3dSortingContextId(int id);
  int sorting_context_id() { return sorting_context_id_; }

537 538 539 540 541 542 543
 protected:
  LayerImpl(LayerTreeImpl* layer_impl, int id);

  // Get the color and size of the layer's debug border.
  virtual void GetDebugBorderProperties(SkColor* color, float* width) const;

  void AppendDebugBorderQuad(QuadSink* quad_sink,
544
                             const gfx::Size& content_bounds,
545 546
                             const SharedQuadState* shared_quad_state,
                             AppendQuadsData* append_quads_data) const;
547
  void AppendDebugBorderQuad(QuadSink* quad_sink,
548
                             const gfx::Size& content_bounds,
549 550 551 552
                             const SharedQuadState* shared_quad_state,
                             AppendQuadsData* append_quads_data,
                             SkColor color,
                             float width) const;
553

554
  virtual void AsValueInto(base::DictionaryValue* dict) const;
555 556 557 558 559 560 561 562

  void NoteLayerPropertyChanged();
  void NoteLayerPropertyChangedForSubtree();

  // Note carefully this does not affect the current layer.
  void NoteLayerPropertyChangedForDescendants();

 private:
563
  void NoteLayerPropertyChangedForDescendantsInternal();
564 565 566 567 568

  virtual const char* LayerTypeAsString() const;

  // Properties internal to LayerImpl
  LayerImpl* parent_;
569
  OwnedLayerImplList children_;
570 571 572 573 574 575 576 577 578 579 580 581

  LayerImpl* scroll_parent_;

  // Storing a pointer to a set rather than a set since this will be rarely
  // used. If this pointer turns out to be too heavy, we could have this (and
  // the scroll parent above) be stored in a LayerImpl -> scroll_info
  // map somewhere.
  scoped_ptr<std::set<LayerImpl*> > scroll_children_;

  LayerImpl* clip_parent_;
  scoped_ptr<std::set<LayerImpl*> > clip_children_;

582 583 584 585 586 587 588 589 590 591
  // mask_layer_ can be temporarily stolen during tree sync, we need this ID to
  // confirm newly assigned layer is still the previous one
  int mask_layer_id_;
  scoped_ptr<LayerImpl> mask_layer_;
  int replica_layer_id_;  // ditto
  scoped_ptr<LayerImpl> replica_layer_;
  int layer_id_;
  LayerTreeImpl* layer_tree_impl_;

  // Properties synchronized from the associated Layer.
592
  gfx::Point3F transform_origin_;
593
  gfx::Size bounds_;
594
  gfx::SizeF temporary_impl_bounds_;
595
  gfx::Vector2d scroll_offset_;
596
  ScrollOffsetDelegate* scroll_offset_delegate_;
597
  LayerImpl* scroll_clip_layer_;
598 599 600
  bool scrollable_ : 1;
  bool should_scroll_on_main_thread_ : 1;
  bool have_wheel_event_handlers_ : 1;
601
  bool have_scroll_event_handlers_ : 1;
602 603 604
  bool user_scrollable_horizontal_ : 1;
  bool user_scrollable_vertical_ : 1;
  bool stacking_order_changed_ : 1;
605
  // Whether the "back" of this layer should draw.
606
  bool double_sided_ : 1;
607
  bool should_flatten_transform_ : 1;
608 609

  // Tracks if drawing-related properties have changed since last redraw.
610 611 612 613 614 615 616 617 618 619 620
  bool layer_property_changed_ : 1;

  bool masks_to_bounds_ : 1;
  bool contents_opaque_ : 1;
  bool is_root_for_isolated_group_ : 1;
  bool use_parent_backface_visibility_ : 1;
  bool draw_checkerboard_for_missing_tiles_ : 1;
  bool draws_content_ : 1;
  bool hide_layer_and_subtree_ : 1;
  bool force_render_surface_ : 1;

621 622 623
  // Cache transform_'s invertibility.
  bool transform_is_invertible_ : 1;

624 625 626 627 628
  // Set for the layer that other layers are fixed to.
  bool is_container_for_fixed_position_layers_ : 1;
  Region non_fast_scrollable_region_;
  Region touch_event_handler_region_;
  SkColor background_color_;
629 630

  float opacity_;
631
  SkXfermode::Mode blend_mode_;
632 633 634
  gfx::PointF position_;
  gfx::Transform transform_;

635
  LayerPositionConstraint position_constraint_;
636 637 638 639 640 641 642 643 644

  gfx::Vector2dF scroll_delta_;
  gfx::Vector2d sent_scroll_delta_;
  gfx::Vector2dF last_scroll_offset_;

  // The global depth value of the center of the layer. This value is used
  // to sort layers from back to front.
  float draw_depth_;

645 646
  FilterOperations filters_;
  FilterOperations background_filters_;
647

648
 protected:
649 650 651 652 653 654 655 656 657 658 659
  friend class TreeSynchronizer;

  // This flag is set when the layer needs to push properties to the active
  // side.
  bool needs_push_properties_;

  // The number of direct children or dependent layers that need to be recursed
  // to in order for them or a descendent of them to push properties to the
  // active side.
  int num_dependents_need_push_properties_;

660 661 662 663 664
  // Layers that share a sorting context id will be sorted together in 3d
  // space.  0 is a special value that means this layer will not be sorted and
  // will be drawn in paint order.
  int sorting_context_id_;

665
  DrawMode current_draw_mode_;
666

667
 private:
668 669
  // Rect indicating what was repainted/updated during update.
  // Note that plugin layers bypass this and leave it empty.
670
  // Uses layer (not content) space.
671 672
  gfx::RectF update_rect_;

673 674 675
  // This rect is in layer space.
  gfx::RectF damage_rect_;

676 677 678 679 680 681
  // Manages animations for this layer.
  scoped_refptr<LayerAnimationController> layer_animation_controller_;

  // Manages scrollbars for this layer
  scoped_ptr<ScrollbarAnimationController> scrollbar_animation_controller_;

682
  scoped_ptr<ScrollbarSet> scrollbars_;
683

684
  ScopedPtrVector<CopyOutputRequest> copy_requests_;
685

686 687
  // Group of properties that need to be computed based on the layer tree
  // hierarchy before layers can be drawn.
688
  DrawProperties<LayerImpl> draw_properties_;
689

690 691
  scoped_refptr<base::debug::ConvertableToTraceFormat> debug_info_;

692 693 694
  DISALLOW_COPY_AND_ASSIGN(LayerImpl);
};

695
}  // namespace cc
696 697

#endif  // CC_LAYERS_LAYER_IMPL_H_