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