| OLD | NEW |
| (Empty) |
| 1 // Copyright 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_LAYERS_LAYER_H_ | |
| 6 #define CC_LAYERS_LAYER_H_ | |
| 7 | |
| 8 #include <set> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/callback.h" | |
| 13 #include "base/memory/ref_counted.h" | |
| 14 #include "base/observer_list.h" | |
| 15 #include "cc/animation/layer_animation_controller.h" | |
| 16 #include "cc/animation/layer_animation_value_observer.h" | |
| 17 #include "cc/animation/layer_animation_value_provider.h" | |
| 18 #include "cc/base/cc_export.h" | |
| 19 #include "cc/base/region.h" | |
| 20 #include "cc/base/scoped_ptr_vector.h" | |
| 21 #include "cc/debug/frame_timing_request.h" | |
| 22 #include "cc/debug/micro_benchmark.h" | |
| 23 #include "cc/layers/draw_properties.h" | |
| 24 #include "cc/layers/layer_lists.h" | |
| 25 #include "cc/layers/layer_position_constraint.h" | |
| 26 #include "cc/layers/paint_properties.h" | |
| 27 #include "cc/layers/render_surface.h" | |
| 28 #include "cc/layers/scroll_blocks_on.h" | |
| 29 #include "cc/output/filter_operations.h" | |
| 30 #include "cc/trees/property_tree.h" | |
| 31 #include "skia/ext/refptr.h" | |
| 32 #include "third_party/skia/include/core/SkColor.h" | |
| 33 #include "third_party/skia/include/core/SkImageFilter.h" | |
| 34 #include "third_party/skia/include/core/SkPicture.h" | |
| 35 #include "third_party/skia/include/core/SkXfermode.h" | |
| 36 #include "ui/gfx/geometry/point3_f.h" | |
| 37 #include "ui/gfx/geometry/rect.h" | |
| 38 #include "ui/gfx/geometry/rect_f.h" | |
| 39 #include "ui/gfx/geometry/scroll_offset.h" | |
| 40 #include "ui/gfx/transform.h" | |
| 41 | |
| 42 namespace gfx { | |
| 43 class BoxF; | |
| 44 } | |
| 45 | |
| 46 namespace base { | |
| 47 namespace trace_event { | |
| 48 class ConvertableToTraceFormat; | |
| 49 } | |
| 50 } | |
| 51 | |
| 52 namespace cc { | |
| 53 | |
| 54 class Animation; | |
| 55 class AnimationDelegate; | |
| 56 struct AnimationEvent; | |
| 57 class CopyOutputRequest; | |
| 58 class LayerAnimationDelegate; | |
| 59 class LayerAnimationEventObserver; | |
| 60 class LayerClient; | |
| 61 class LayerImpl; | |
| 62 class LayerTreeHost; | |
| 63 class LayerTreeHostCommon; | |
| 64 class LayerTreeImpl; | |
| 65 class PriorityCalculator; | |
| 66 class RenderingStatsInstrumentation; | |
| 67 class ResourceUpdateQueue; | |
| 68 class ScrollbarLayerInterface; | |
| 69 class SimpleEnclosedRegion; | |
| 70 struct AnimationEvent; | |
| 71 template <typename LayerType> | |
| 72 class OcclusionTracker; | |
| 73 | |
| 74 // Base class for composited layers. Special layer types are derived from | |
| 75 // this class. | |
| 76 class CC_EXPORT Layer : public base::RefCounted<Layer>, | |
| 77 public LayerAnimationValueObserver, | |
| 78 public LayerAnimationValueProvider { | |
| 79 public: | |
| 80 typedef RenderSurfaceLayerList RenderSurfaceListType; | |
| 81 typedef LayerList LayerListType; | |
| 82 typedef RenderSurface RenderSurfaceType; | |
| 83 | |
| 84 enum LayerIdLabels { | |
| 85 INVALID_ID = -1, | |
| 86 }; | |
| 87 | |
| 88 static scoped_refptr<Layer> Create(); | |
| 89 | |
| 90 int id() const { return layer_id_; } | |
| 91 | |
| 92 Layer* RootLayer(); | |
| 93 Layer* parent() { return parent_; } | |
| 94 const Layer* parent() const { return parent_; } | |
| 95 void AddChild(scoped_refptr<Layer> child); | |
| 96 void InsertChild(scoped_refptr<Layer> child, size_t index); | |
| 97 void ReplaceChild(Layer* reference, scoped_refptr<Layer> new_layer); | |
| 98 void RemoveFromParent(); | |
| 99 void RemoveAllChildren(); | |
| 100 void SetChildren(const LayerList& children); | |
| 101 bool HasAncestor(const Layer* ancestor) const; | |
| 102 | |
| 103 const LayerList& children() const { return children_; } | |
| 104 Layer* child_at(size_t index) { return children_[index].get(); } | |
| 105 | |
| 106 // This requests the layer and its subtree be rendered and given to the | |
| 107 // callback. If the copy is unable to be produced (the layer is destroyed | |
| 108 // first), then the callback is called with a nullptr/empty result. | |
| 109 void RequestCopyOfOutput(scoped_ptr<CopyOutputRequest> request); | |
| 110 bool HasCopyRequest() const { | |
| 111 return !copy_requests_.empty(); | |
| 112 } | |
| 113 | |
| 114 virtual void SetBackgroundColor(SkColor background_color); | |
| 115 SkColor background_color() const { return background_color_; } | |
| 116 // If contents_opaque(), return an opaque color else return a | |
| 117 // non-opaque color. Tries to return background_color(), if possible. | |
| 118 SkColor SafeOpaqueBackgroundColor() const; | |
| 119 | |
| 120 // A layer's bounds are in logical, non-page-scaled pixels (however, the | |
| 121 // root layer's bounds are in physical pixels). | |
| 122 void SetBounds(const gfx::Size& bounds); | |
| 123 gfx::Size bounds() const { return bounds_; } | |
| 124 | |
| 125 void SetMasksToBounds(bool masks_to_bounds); | |
| 126 bool masks_to_bounds() const { return masks_to_bounds_; } | |
| 127 | |
| 128 void SetMaskLayer(Layer* mask_layer); | |
| 129 Layer* mask_layer() { return mask_layer_.get(); } | |
| 130 const Layer* mask_layer() const { return mask_layer_.get(); } | |
| 131 | |
| 132 virtual void SetNeedsDisplayRect(const gfx::Rect& dirty_rect); | |
| 133 void SetNeedsDisplay() { SetNeedsDisplayRect(gfx::Rect(bounds())); } | |
| 134 | |
| 135 void SetOpacity(float opacity); | |
| 136 float opacity() const { return opacity_; } | |
| 137 bool OpacityIsAnimating() const; | |
| 138 virtual bool OpacityCanAnimateOnImplThread() const; | |
| 139 | |
| 140 void SetBlendMode(SkXfermode::Mode blend_mode); | |
| 141 SkXfermode::Mode blend_mode() const { return blend_mode_; } | |
| 142 | |
| 143 bool uses_default_blend_mode() const { | |
| 144 return blend_mode_ == SkXfermode::kSrcOver_Mode; | |
| 145 } | |
| 146 | |
| 147 // A layer is root for an isolated group when it and all its descendants are | |
| 148 // drawn over a black and fully transparent background, creating an isolated | |
| 149 // group. It should be used along with SetBlendMode(), in order to restrict | |
| 150 // layers within the group to blend with layers outside this group. | |
| 151 void SetIsRootForIsolatedGroup(bool root); | |
| 152 bool is_root_for_isolated_group() const { | |
| 153 return is_root_for_isolated_group_; | |
| 154 } | |
| 155 | |
| 156 void SetFilters(const FilterOperations& filters); | |
| 157 const FilterOperations& filters() const { return filters_; } | |
| 158 bool FilterIsAnimating() const; | |
| 159 | |
| 160 // Background filters are filters applied to what is behind this layer, when | |
| 161 // they are viewed through non-opaque regions in this layer. They are used | |
| 162 // through the WebLayer interface, and are not exposed to HTML. | |
| 163 void SetBackgroundFilters(const FilterOperations& filters); | |
| 164 const FilterOperations& background_filters() const { | |
| 165 return background_filters_; | |
| 166 } | |
| 167 | |
| 168 virtual void SetContentsOpaque(bool opaque); | |
| 169 bool contents_opaque() const { return contents_opaque_; } | |
| 170 | |
| 171 void SetPosition(const gfx::PointF& position); | |
| 172 gfx::PointF position() const { return position_; } | |
| 173 | |
| 174 void SetIsContainerForFixedPositionLayers(bool container); | |
| 175 bool IsContainerForFixedPositionLayers() const; | |
| 176 | |
| 177 gfx::Vector2dF FixedContainerSizeDelta() const { | |
| 178 return gfx::Vector2dF(); | |
| 179 } | |
| 180 | |
| 181 void SetPositionConstraint(const LayerPositionConstraint& constraint); | |
| 182 const LayerPositionConstraint& position_constraint() const { | |
| 183 return position_constraint_; | |
| 184 } | |
| 185 | |
| 186 void SetTransform(const gfx::Transform& transform); | |
| 187 const gfx::Transform& transform() const { return transform_; } | |
| 188 bool TransformIsAnimating() const; | |
| 189 bool AnimationsPreserveAxisAlignment() const; | |
| 190 bool transform_is_invertible() const { return transform_is_invertible_; } | |
| 191 | |
| 192 void SetTransformOrigin(const gfx::Point3F&); | |
| 193 gfx::Point3F transform_origin() const { return transform_origin_; } | |
| 194 | |
| 195 void SetScrollParent(Layer* parent); | |
| 196 | |
| 197 Layer* scroll_parent() { return scroll_parent_; } | |
| 198 const Layer* scroll_parent() const { return scroll_parent_; } | |
| 199 | |
| 200 void AddScrollChild(Layer* child); | |
| 201 void RemoveScrollChild(Layer* child); | |
| 202 | |
| 203 std::set<Layer*>* scroll_children() { return scroll_children_.get(); } | |
| 204 const std::set<Layer*>* scroll_children() const { | |
| 205 return scroll_children_.get(); | |
| 206 } | |
| 207 | |
| 208 void SetClipParent(Layer* ancestor); | |
| 209 | |
| 210 Layer* clip_parent() { return clip_parent_; } | |
| 211 const Layer* clip_parent() const { | |
| 212 return clip_parent_; | |
| 213 } | |
| 214 | |
| 215 void AddClipChild(Layer* child); | |
| 216 void RemoveClipChild(Layer* child); | |
| 217 | |
| 218 std::set<Layer*>* clip_children() { return clip_children_.get(); } | |
| 219 const std::set<Layer*>* clip_children() const { | |
| 220 return clip_children_.get(); | |
| 221 } | |
| 222 | |
| 223 DrawProperties<Layer>& draw_properties() { return draw_properties_; } | |
| 224 const DrawProperties<Layer>& draw_properties() const { | |
| 225 return draw_properties_; | |
| 226 } | |
| 227 | |
| 228 // The following are shortcut accessors to get various information from | |
| 229 // draw_properties_ | |
| 230 const gfx::Transform& draw_transform() const { | |
| 231 return draw_properties_.target_space_transform; | |
| 232 } | |
| 233 const gfx::Transform& screen_space_transform() const { | |
| 234 return draw_properties_.screen_space_transform; | |
| 235 } | |
| 236 float draw_opacity() const { return draw_properties_.opacity; } | |
| 237 bool draw_opacity_is_animating() const { | |
| 238 return draw_properties_.opacity_is_animating; | |
| 239 } | |
| 240 bool draw_transform_is_animating() const { | |
| 241 return draw_properties_.target_space_transform_is_animating; | |
| 242 } | |
| 243 bool screen_space_transform_is_animating() const { | |
| 244 return draw_properties_.screen_space_transform_is_animating; | |
| 245 } | |
| 246 bool screen_space_opacity_is_animating() const { | |
| 247 return draw_properties_.screen_space_opacity_is_animating; | |
| 248 } | |
| 249 bool is_clipped() const { return draw_properties_.is_clipped; } | |
| 250 gfx::Rect clip_rect() const { return draw_properties_.clip_rect; } | |
| 251 gfx::Rect drawable_content_rect() const { | |
| 252 return draw_properties_.drawable_content_rect; | |
| 253 } | |
| 254 gfx::Rect visible_content_rect() const { | |
| 255 return draw_properties_.visible_content_rect; | |
| 256 } | |
| 257 Layer* render_target() { | |
| 258 DCHECK(!draw_properties_.render_target || | |
| 259 draw_properties_.render_target->render_surface()); | |
| 260 return draw_properties_.render_target; | |
| 261 } | |
| 262 const Layer* render_target() const { | |
| 263 DCHECK(!draw_properties_.render_target || | |
| 264 draw_properties_.render_target->render_surface()); | |
| 265 return draw_properties_.render_target; | |
| 266 } | |
| 267 int num_unclipped_descendants() const { | |
| 268 return draw_properties_.num_unclipped_descendants; | |
| 269 } | |
| 270 | |
| 271 RenderSurface* render_surface() const { return render_surface_.get(); } | |
| 272 void SetScrollOffset(const gfx::ScrollOffset& scroll_offset); | |
| 273 void SetScrollCompensationAdjustment( | |
| 274 const gfx::Vector2dF& scroll_compensation_adjustment); | |
| 275 gfx::Vector2dF ScrollCompensationAdjustment() const; | |
| 276 | |
| 277 gfx::ScrollOffset scroll_offset() const { return scroll_offset_; } | |
| 278 void SetScrollOffsetFromImplSide(const gfx::ScrollOffset& scroll_offset); | |
| 279 | |
| 280 void SetScrollClipLayerId(int clip_layer_id); | |
| 281 bool scrollable() const { return scroll_clip_layer_id_ != INVALID_ID; } | |
| 282 | |
| 283 void SetUserScrollable(bool horizontal, bool vertical); | |
| 284 bool user_scrollable_horizontal() const { | |
| 285 return user_scrollable_horizontal_; | |
| 286 } | |
| 287 bool user_scrollable_vertical() const { return user_scrollable_vertical_; } | |
| 288 | |
| 289 void SetShouldScrollOnMainThread(bool should_scroll_on_main_thread); | |
| 290 bool should_scroll_on_main_thread() const { | |
| 291 return should_scroll_on_main_thread_; | |
| 292 } | |
| 293 | |
| 294 void SetHaveWheelEventHandlers(bool have_wheel_event_handlers); | |
| 295 bool have_wheel_event_handlers() const { return have_wheel_event_handlers_; } | |
| 296 | |
| 297 void SetHaveScrollEventHandlers(bool have_scroll_event_handlers); | |
| 298 bool have_scroll_event_handlers() const { | |
| 299 return have_scroll_event_handlers_; | |
| 300 } | |
| 301 | |
| 302 void SetNonFastScrollableRegion(const Region& non_fast_scrollable_region); | |
| 303 const Region& non_fast_scrollable_region() const { | |
| 304 return non_fast_scrollable_region_; | |
| 305 } | |
| 306 | |
| 307 void SetTouchEventHandlerRegion(const Region& touch_event_handler_region); | |
| 308 const Region& touch_event_handler_region() const { | |
| 309 return touch_event_handler_region_; | |
| 310 } | |
| 311 | |
| 312 void SetScrollBlocksOn(ScrollBlocksOn scroll_blocks_on); | |
| 313 ScrollBlocksOn scroll_blocks_on() const { return scroll_blocks_on_; } | |
| 314 | |
| 315 void set_did_scroll_callback(const base::Closure& callback) { | |
| 316 did_scroll_callback_ = callback; | |
| 317 } | |
| 318 | |
| 319 void SetDrawCheckerboardForMissingTiles(bool checkerboard); | |
| 320 bool draw_checkerboard_for_missing_tiles() const { | |
| 321 return draw_checkerboard_for_missing_tiles_; | |
| 322 } | |
| 323 | |
| 324 void SetForceRenderSurface(bool force_render_surface); | |
| 325 bool force_render_surface() const { return force_render_surface_; } | |
| 326 | |
| 327 gfx::Vector2dF ScrollDelta() const { return gfx::Vector2dF(); } | |
| 328 gfx::ScrollOffset CurrentScrollOffset() const { return scroll_offset_; } | |
| 329 | |
| 330 void SetDoubleSided(bool double_sided); | |
| 331 bool double_sided() const { return double_sided_; } | |
| 332 | |
| 333 void SetShouldFlattenTransform(bool flatten); | |
| 334 bool should_flatten_transform() const { return should_flatten_transform_; } | |
| 335 | |
| 336 bool Is3dSorted() const { return sorting_context_id_ != 0; } | |
| 337 | |
| 338 void set_use_parent_backface_visibility(bool use) { | |
| 339 use_parent_backface_visibility_ = use; | |
| 340 } | |
| 341 bool use_parent_backface_visibility() const { | |
| 342 return use_parent_backface_visibility_; | |
| 343 } | |
| 344 | |
| 345 virtual void SetLayerTreeHost(LayerTreeHost* host); | |
| 346 | |
| 347 virtual bool HasDelegatedContent() const; | |
| 348 bool HasContributingDelegatedRenderPasses() const { return false; } | |
| 349 | |
| 350 void SetIsDrawable(bool is_drawable); | |
| 351 | |
| 352 void SetHideLayerAndSubtree(bool hide); | |
| 353 bool hide_layer_and_subtree() const { return hide_layer_and_subtree_; } | |
| 354 | |
| 355 void SetReplicaLayer(Layer* layer); | |
| 356 Layer* replica_layer() { return replica_layer_.get(); } | |
| 357 const Layer* replica_layer() const { return replica_layer_.get(); } | |
| 358 | |
| 359 bool has_mask() const { return !!mask_layer_.get(); } | |
| 360 bool has_replica() const { return !!replica_layer_.get(); } | |
| 361 bool replica_has_mask() const { | |
| 362 return replica_layer_.get() && | |
| 363 (mask_layer_.get() || replica_layer_->mask_layer_.get()); | |
| 364 } | |
| 365 | |
| 366 int NumDescendantsThatDrawContent() const; | |
| 367 | |
| 368 // This is only virtual for tests. | |
| 369 // TODO(awoloszyn): Remove this once we no longer need it for tests | |
| 370 virtual bool DrawsContent() const; | |
| 371 | |
| 372 // This methods typically need to be overwritten by derived classes. | |
| 373 virtual void SavePaintProperties(); | |
| 374 // Returns true iff any resources were updated that need to be committed. | |
| 375 virtual bool Update(ResourceUpdateQueue* queue, | |
| 376 const OcclusionTracker<Layer>* occlusion); | |
| 377 virtual bool NeedMoreUpdates(); | |
| 378 virtual void SetIsMask(bool is_mask) {} | |
| 379 virtual void ReduceMemoryUsage() {} | |
| 380 virtual void OnOutputSurfaceCreated() {} | |
| 381 virtual bool IsSuitableForGpuRasterization() const; | |
| 382 | |
| 383 virtual scoped_refptr<base::trace_event::ConvertableToTraceFormat> | |
| 384 TakeDebugInfo(); | |
| 385 | |
| 386 void SetLayerClient(LayerClient* client) { client_ = client; } | |
| 387 | |
| 388 virtual void PushPropertiesTo(LayerImpl* layer); | |
| 389 | |
| 390 void CreateRenderSurface(); | |
| 391 void ClearRenderSurface(); | |
| 392 | |
| 393 void ClearRenderSurfaceLayerList(); | |
| 394 | |
| 395 // The contents scale converts from logical, non-page-scaled pixels to target | |
| 396 // pixels. The contents scale is 1 for the root layer as it is already in | |
| 397 // physical pixels. By default contents scale is forced to be 1 except for | |
| 398 // subclasses of ContentsScalingLayer. | |
| 399 float contents_scale_x() const { return draw_properties_.contents_scale_x; } | |
| 400 float contents_scale_y() const { return draw_properties_.contents_scale_y; } | |
| 401 gfx::Size content_bounds() const { return draw_properties_.content_bounds; } | |
| 402 | |
| 403 virtual void CalculateContentsScale(float ideal_contents_scale, | |
| 404 float* contents_scale_x, | |
| 405 float* contents_scale_y, | |
| 406 gfx::Size* content_bounds); | |
| 407 | |
| 408 LayerTreeHost* layer_tree_host() { return layer_tree_host_; } | |
| 409 const LayerTreeHost* layer_tree_host() const { return layer_tree_host_; } | |
| 410 | |
| 411 // Set the priority of all desired textures in this layer. | |
| 412 virtual void SetTexturePriorities(const PriorityCalculator& priority_calc) {} | |
| 413 | |
| 414 bool AddAnimation(scoped_ptr<Animation> animation); | |
| 415 void PauseAnimation(int animation_id, double time_offset); | |
| 416 void RemoveAnimation(int animation_id); | |
| 417 void RemoveAnimation(int animation_id, Animation::TargetProperty property); | |
| 418 | |
| 419 LayerAnimationController* layer_animation_controller() { | |
| 420 return layer_animation_controller_.get(); | |
| 421 } | |
| 422 void SetLayerAnimationControllerForTest( | |
| 423 scoped_refptr<LayerAnimationController> controller); | |
| 424 | |
| 425 void set_layer_animation_delegate(AnimationDelegate* delegate) { | |
| 426 layer_animation_controller_->set_layer_animation_delegate(delegate); | |
| 427 } | |
| 428 | |
| 429 bool HasActiveAnimation() const; | |
| 430 | |
| 431 void AddLayerAnimationEventObserver( | |
| 432 LayerAnimationEventObserver* animation_observer); | |
| 433 void RemoveLayerAnimationEventObserver( | |
| 434 LayerAnimationEventObserver* animation_observer); | |
| 435 | |
| 436 virtual SimpleEnclosedRegion VisibleContentOpaqueRegion() const; | |
| 437 | |
| 438 virtual ScrollbarLayerInterface* ToScrollbarLayer(); | |
| 439 | |
| 440 gfx::Rect LayerRectToContentRect(const gfx::Rect& layer_rect) const; | |
| 441 | |
| 442 virtual skia::RefPtr<SkPicture> GetPicture() const; | |
| 443 | |
| 444 // Constructs a LayerImpl of the correct runtime type for this Layer type. | |
| 445 virtual scoped_ptr<LayerImpl> CreateLayerImpl(LayerTreeImpl* tree_impl); | |
| 446 | |
| 447 bool NeedsDisplayForTesting() const { return !update_rect_.IsEmpty(); } | |
| 448 void ResetNeedsDisplayForTesting() { update_rect_ = gfx::Rect(); } | |
| 449 | |
| 450 RenderingStatsInstrumentation* rendering_stats_instrumentation() const; | |
| 451 | |
| 452 const PaintProperties& paint_properties() const { | |
| 453 return paint_properties_; | |
| 454 } | |
| 455 | |
| 456 // The scale at which contents should be rastered, to match the scale at | |
| 457 // which they will drawn to the screen. This scale is a component of the | |
| 458 // contents scale but does not include page/device scale factors. | |
| 459 // TODO(danakj): This goes away when TiledLayer goes away. | |
| 460 void set_raster_scale(float scale) { raster_scale_ = scale; } | |
| 461 float raster_scale() const { return raster_scale_; } | |
| 462 bool raster_scale_is_unknown() const { return raster_scale_ == 0.f; } | |
| 463 | |
| 464 void SetNeedsPushProperties(); | |
| 465 bool needs_push_properties() const { return needs_push_properties_; } | |
| 466 bool descendant_needs_push_properties() const { | |
| 467 return num_dependents_need_push_properties_ > 0; | |
| 468 } | |
| 469 void reset_needs_push_properties_for_testing() { | |
| 470 needs_push_properties_ = false; | |
| 471 } | |
| 472 | |
| 473 virtual void RunMicroBenchmark(MicroBenchmark* benchmark); | |
| 474 | |
| 475 void Set3dSortingContextId(int id); | |
| 476 int sorting_context_id() const { return sorting_context_id_; } | |
| 477 | |
| 478 void set_transform_tree_index(int index) { transform_tree_index_ = index; } | |
| 479 void set_clip_tree_index(int index) { clip_tree_index_ = index; } | |
| 480 void set_opacity_tree_index(int index) { opacity_tree_index_ = index; } | |
| 481 int clip_tree_index() const { return clip_tree_index_; } | |
| 482 int transform_tree_index() const { return transform_tree_index_; } | |
| 483 int opacity_tree_index() const { return opacity_tree_index_; } | |
| 484 | |
| 485 void set_offset_to_transform_parent(gfx::Vector2dF offset) { | |
| 486 offset_to_transform_parent_ = offset; | |
| 487 } | |
| 488 gfx::Vector2dF offset_to_transform_parent() const { | |
| 489 return offset_to_transform_parent_; | |
| 490 } | |
| 491 | |
| 492 // TODO(vollick): Once we transition to transform and clip trees, rename these | |
| 493 // functions and related values. The "from property trees" functions below | |
| 494 // use the transform and clip trees. Eventually, we will use these functions | |
| 495 // to compute the official values, but these functions are retained for | |
| 496 // testing purposes until we've migrated. | |
| 497 | |
| 498 const gfx::Rect& visible_rect_from_property_trees() const { | |
| 499 return visible_rect_from_property_trees_; | |
| 500 } | |
| 501 void set_visible_rect_from_property_trees(const gfx::Rect& rect) { | |
| 502 visible_rect_from_property_trees_ = rect; | |
| 503 } | |
| 504 | |
| 505 gfx::Transform screen_space_transform_from_property_trees( | |
| 506 const TransformTree& tree) const; | |
| 507 gfx::Transform draw_transform_from_property_trees( | |
| 508 const TransformTree& tree) const; | |
| 509 float DrawOpacityFromPropertyTrees(const OpacityTree& tree) const; | |
| 510 | |
| 511 void set_should_flatten_transform_from_property_tree(bool should_flatten) { | |
| 512 should_flatten_transform_from_property_tree_ = should_flatten; | |
| 513 } | |
| 514 | |
| 515 // TODO(vollick): These values are temporary and will be removed as soon as | |
| 516 // render surface determinations are moved out of CDP. They only exist because | |
| 517 // certain logic depends on whether or not a layer would render to a separate | |
| 518 // surface, but CDP destroys surfaces and targets it doesn't need, so without | |
| 519 // this boolean, this is impossible to determine after the fact without | |
| 520 // wastefully recomputing it. This is public for the time being so that it can | |
| 521 // be accessed from CDP. | |
| 522 bool has_render_surface() const { | |
| 523 return has_render_surface_; | |
| 524 } | |
| 525 | |
| 526 // Sets new frame timing requests for this layer. | |
| 527 void SetFrameTimingRequests(const std::vector<FrameTimingRequest>& requests); | |
| 528 | |
| 529 void DidBeginTracing(); | |
| 530 | |
| 531 protected: | |
| 532 friend class LayerImpl; | |
| 533 friend class TreeSynchronizer; | |
| 534 ~Layer() override; | |
| 535 | |
| 536 Layer(); | |
| 537 | |
| 538 // These SetNeeds functions are in order of severity of update: | |
| 539 // | |
| 540 // Called when this layer has been modified in some way, but isn't sure | |
| 541 // that it needs a commit yet. It needs CalcDrawProperties and UpdateLayers | |
| 542 // before it knows whether or not a commit is required. | |
| 543 void SetNeedsUpdate(); | |
| 544 // Called when a property has been modified in a way that the layer | |
| 545 // knows immediately that a commit is required. This implies SetNeedsUpdate | |
| 546 // as well as SetNeedsPushProperties to push that property. | |
| 547 void SetNeedsCommit(); | |
| 548 // Called when there's been a change in layer structure. Implies both | |
| 549 // SetNeedsUpdate and SetNeedsCommit, but not SetNeedsPushProperties. | |
| 550 void SetNeedsFullTreeSync(); | |
| 551 | |
| 552 // Called when the next commit should wait until the pending tree is activated | |
| 553 // before finishing the commit and unblocking the main thread. Used to ensure | |
| 554 // unused resources on the impl thread are returned before commit completes. | |
| 555 void SetNextCommitWaitsForActivation(); | |
| 556 | |
| 557 // Will recalculate whether the layer draws content and set draws_content_ | |
| 558 // appropriately. | |
| 559 void UpdateDrawsContent(bool has_drawable_content); | |
| 560 virtual bool HasDrawableContent() const; | |
| 561 | |
| 562 // Called when the layer's number of drawable descendants changes. | |
| 563 void AddDrawableDescendants(int num); | |
| 564 | |
| 565 void AddDependentNeedsPushProperties(); | |
| 566 void RemoveDependentNeedsPushProperties(); | |
| 567 bool parent_should_know_need_push_properties() const { | |
| 568 return needs_push_properties() || descendant_needs_push_properties(); | |
| 569 } | |
| 570 | |
| 571 bool IsPropertyChangeAllowed() const; | |
| 572 | |
| 573 void reset_raster_scale_to_unknown() { raster_scale_ = 0.f; } | |
| 574 | |
| 575 // This flag is set when the layer needs to push properties to the impl | |
| 576 // side. | |
| 577 bool needs_push_properties_; | |
| 578 | |
| 579 // The number of direct children or dependent layers that need to be recursed | |
| 580 // to in order for them or a descendent of them to push properties to the impl | |
| 581 // side. | |
| 582 int num_dependents_need_push_properties_; | |
| 583 | |
| 584 // Tracks whether this layer may have changed stacking order with its | |
| 585 // siblings. | |
| 586 bool stacking_order_changed_; | |
| 587 | |
| 588 // The update rect is the region of the compositor resource that was | |
| 589 // actually updated by the compositor. For layers that may do updating | |
| 590 // outside the compositor's control (i.e. plugin layers), this information | |
| 591 // is not available and the update rect will remain empty. | |
| 592 // Note this rect is in layer space (not content space). | |
| 593 gfx::Rect update_rect_; | |
| 594 | |
| 595 scoped_refptr<Layer> mask_layer_; | |
| 596 | |
| 597 int layer_id_; | |
| 598 | |
| 599 // When true, the layer is about to perform an update. Any commit requests | |
| 600 // will be handled implicitly after the update completes. | |
| 601 bool ignore_set_needs_commit_; | |
| 602 | |
| 603 // Layers that share a sorting context id will be sorted together in 3d | |
| 604 // space. 0 is a special value that means this layer will not be sorted and | |
| 605 // will be drawn in paint order. | |
| 606 int sorting_context_id_; | |
| 607 | |
| 608 private: | |
| 609 friend class base::RefCounted<Layer>; | |
| 610 friend class LayerTreeHostCommon; | |
| 611 void SetParent(Layer* layer); | |
| 612 bool DescendantIsFixedToContainerLayer() const; | |
| 613 | |
| 614 // This should only be called during BeginMainFrame since it does not | |
| 615 // trigger a Commit. | |
| 616 void SetHasRenderSurface(bool has_render_surface); | |
| 617 | |
| 618 // Returns the index of the child or -1 if not found. | |
| 619 int IndexOfChild(const Layer* reference); | |
| 620 | |
| 621 // This should only be called from RemoveFromParent(). | |
| 622 void RemoveChildOrDependent(Layer* child); | |
| 623 | |
| 624 // LayerAnimationValueProvider implementation. | |
| 625 gfx::ScrollOffset ScrollOffsetForAnimation() const override; | |
| 626 | |
| 627 // LayerAnimationValueObserver implementation. | |
| 628 void OnFilterAnimated(const FilterOperations& filters) override; | |
| 629 void OnOpacityAnimated(float opacity) override; | |
| 630 void OnTransformAnimated(const gfx::Transform& transform) override; | |
| 631 void OnScrollOffsetAnimated(const gfx::ScrollOffset& scroll_offset) override; | |
| 632 void OnAnimationWaitingForDeletion() override; | |
| 633 bool IsActive() const override; | |
| 634 | |
| 635 // If this layer has a scroll parent, it removes |this| from its list of | |
| 636 // scroll children. | |
| 637 void RemoveFromScrollTree(); | |
| 638 | |
| 639 // If this layer has a clip parent, it removes |this| from its list of clip | |
| 640 // children. | |
| 641 void RemoveFromClipTree(); | |
| 642 | |
| 643 LayerList children_; | |
| 644 Layer* parent_; | |
| 645 | |
| 646 // Layer instances have a weak pointer to their LayerTreeHost. | |
| 647 // This pointer value is nil when a Layer is not in a tree and is | |
| 648 // updated via SetLayerTreeHost() if a layer moves between trees. | |
| 649 LayerTreeHost* layer_tree_host_; | |
| 650 | |
| 651 scoped_refptr<LayerAnimationController> layer_animation_controller_; | |
| 652 | |
| 653 // Layer properties. | |
| 654 gfx::Size bounds_; | |
| 655 | |
| 656 gfx::ScrollOffset scroll_offset_; | |
| 657 gfx::Vector2dF scroll_compensation_adjustment_; | |
| 658 // This variable indicates which ancestor layer (if any) whose size, | |
| 659 // transformed relative to this layer, defines the maximum scroll offset for | |
| 660 // this layer. | |
| 661 int scroll_clip_layer_id_; | |
| 662 int num_descendants_that_draw_content_; | |
| 663 int transform_tree_index_; | |
| 664 int opacity_tree_index_; | |
| 665 int clip_tree_index_; | |
| 666 gfx::Vector2dF offset_to_transform_parent_; | |
| 667 bool should_flatten_transform_from_property_tree_ : 1; | |
| 668 bool should_scroll_on_main_thread_ : 1; | |
| 669 bool have_wheel_event_handlers_ : 1; | |
| 670 bool have_scroll_event_handlers_ : 1; | |
| 671 bool user_scrollable_horizontal_ : 1; | |
| 672 bool user_scrollable_vertical_ : 1; | |
| 673 bool is_root_for_isolated_group_ : 1; | |
| 674 bool is_container_for_fixed_position_layers_ : 1; | |
| 675 bool is_drawable_ : 1; | |
| 676 bool draws_content_ : 1; | |
| 677 bool hide_layer_and_subtree_ : 1; | |
| 678 bool masks_to_bounds_ : 1; | |
| 679 bool contents_opaque_ : 1; | |
| 680 bool double_sided_ : 1; | |
| 681 bool should_flatten_transform_ : 1; | |
| 682 bool use_parent_backface_visibility_ : 1; | |
| 683 bool draw_checkerboard_for_missing_tiles_ : 1; | |
| 684 bool force_render_surface_ : 1; | |
| 685 bool transform_is_invertible_ : 1; | |
| 686 bool has_render_surface_ : 1; | |
| 687 ScrollBlocksOn scroll_blocks_on_ : 3; | |
| 688 Region non_fast_scrollable_region_; | |
| 689 Region touch_event_handler_region_; | |
| 690 gfx::PointF position_; | |
| 691 SkColor background_color_; | |
| 692 float opacity_; | |
| 693 SkXfermode::Mode blend_mode_; | |
| 694 FilterOperations filters_; | |
| 695 FilterOperations background_filters_; | |
| 696 LayerPositionConstraint position_constraint_; | |
| 697 Layer* scroll_parent_; | |
| 698 scoped_ptr<std::set<Layer*>> scroll_children_; | |
| 699 | |
| 700 Layer* clip_parent_; | |
| 701 scoped_ptr<std::set<Layer*>> clip_children_; | |
| 702 | |
| 703 gfx::Transform transform_; | |
| 704 gfx::Point3F transform_origin_; | |
| 705 | |
| 706 // Replica layer used for reflections. | |
| 707 scoped_refptr<Layer> replica_layer_; | |
| 708 | |
| 709 // Transient properties. | |
| 710 float raster_scale_; | |
| 711 | |
| 712 LayerClient* client_; | |
| 713 | |
| 714 ScopedPtrVector<CopyOutputRequest> copy_requests_; | |
| 715 | |
| 716 base::Closure did_scroll_callback_; | |
| 717 | |
| 718 DrawProperties<Layer> draw_properties_; | |
| 719 | |
| 720 PaintProperties paint_properties_; | |
| 721 // TODO(awoloszyn): This is redundant with has_render_surface_, | |
| 722 // and should get removed once it is no longer needed on main thread. | |
| 723 scoped_ptr<RenderSurface> render_surface_; | |
| 724 | |
| 725 gfx::Rect visible_rect_from_property_trees_; | |
| 726 | |
| 727 std::vector<FrameTimingRequest> frame_timing_requests_; | |
| 728 bool frame_timing_requests_dirty_; | |
| 729 | |
| 730 DISALLOW_COPY_AND_ASSIGN(Layer); | |
| 731 }; | |
| 732 | |
| 733 } // namespace cc | |
| 734 | |
| 735 #endif // CC_LAYERS_LAYER_H_ | |
| OLD | NEW |