OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_COMPOSITOR_LAYER_H_ | 5 #ifndef UI_COMPOSITOR_LAYER_H_ |
6 #define UI_COMPOSITOR_LAYER_H_ | 6 #define UI_COMPOSITOR_LAYER_H_ |
7 | 7 |
8 #include <stddef.h> | 8 #include <stddef.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
(...skipping 10 matching lines...) Expand all Loading... | |
21 #include "cc/layers/layer_client.h" | 21 #include "cc/layers/layer_client.h" |
22 #include "cc/layers/surface_layer.h" | 22 #include "cc/layers/surface_layer.h" |
23 #include "cc/layers/texture_layer_client.h" | 23 #include "cc/layers/texture_layer_client.h" |
24 #include "cc/resources/texture_mailbox.h" | 24 #include "cc/resources/texture_mailbox.h" |
25 #include "cc/surfaces/surface_id.h" | 25 #include "cc/surfaces/surface_id.h" |
26 #include "third_party/skia/include/core/SkColor.h" | 26 #include "third_party/skia/include/core/SkColor.h" |
27 #include "third_party/skia/include/core/SkRegion.h" | 27 #include "third_party/skia/include/core/SkRegion.h" |
28 #include "ui/compositor/compositor.h" | 28 #include "ui/compositor/compositor.h" |
29 #include "ui/compositor/layer_animation_delegate.h" | 29 #include "ui/compositor/layer_animation_delegate.h" |
30 #include "ui/compositor/layer_delegate.h" | 30 #include "ui/compositor/layer_delegate.h" |
31 #include "ui/compositor/layer_observer.h" | |
31 #include "ui/compositor/layer_type.h" | 32 #include "ui/compositor/layer_type.h" |
32 #include "ui/gfx/geometry/rect.h" | 33 #include "ui/gfx/geometry/rect.h" |
33 #include "ui/gfx/image/image_skia.h" | 34 #include "ui/gfx/image/image_skia.h" |
34 #include "ui/gfx/transform.h" | 35 #include "ui/gfx/transform.h" |
35 | 36 |
36 class SkCanvas; | 37 class SkCanvas; |
37 | 38 |
38 namespace cc { | 39 namespace cc { |
39 class ContentLayer; | 40 class ContentLayer; |
40 class CopyOutputRequest; | 41 class CopyOutputRequest; |
41 class Layer; | 42 class Layer; |
42 class NinePatchLayer; | 43 class NinePatchLayer; |
43 class ResourceUpdateQueue; | 44 class ResourceUpdateQueue; |
44 class SolidColorLayer; | 45 class SolidColorLayer; |
45 class SurfaceLayer; | 46 class SurfaceLayer; |
46 class TextureLayer; | 47 class TextureLayer; |
47 struct ReturnedResource; | 48 struct ReturnedResource; |
48 typedef std::vector<ReturnedResource> ReturnedResourceArray; | 49 typedef std::vector<ReturnedResource> ReturnedResourceArray; |
49 } | 50 } |
50 | 51 |
51 namespace ui { | 52 namespace ui { |
52 | 53 |
53 class Compositor; | 54 class Compositor; |
54 class LayerAnimator; | 55 class LayerAnimator; |
55 class LayerObserver; | |
56 class LayerOwner; | 56 class LayerOwner; |
57 class LayerThreadedAnimationDelegate; | 57 class LayerThreadedAnimationDelegate; |
58 | 58 |
59 // Layer manages a texture, transform and a set of child Layers. Any View that | 59 // Layer manages a texture, transform and a set of child Layers. Any View that |
60 // has enabled layers ends up creating a Layer to manage the texture. | 60 // has enabled layers ends up creating a Layer to manage the texture. |
61 // A Layer can also be created without a texture, in which case it renders | 61 // A Layer can also be created without a texture, in which case it renders |
62 // nothing and is simply used as a node in a hierarchy of layers. | 62 // nothing and is simply used as a node in a hierarchy of layers. |
63 // Coordinate system used in layers is DIP (Density Independent Pixel) | 63 // Coordinate system used in layers is DIP (Density Independent Pixel) |
64 // coordinates unless explicitly mentioned as pixel coordinates. | 64 // coordinates unless explicitly mentioned as pixel coordinates. |
65 // | 65 // |
66 // NOTE: Unlike Views, each Layer does *not* own its child Layers. If you | 66 // NOTE: Unlike Views, each Layer does *not* own its child Layers. If you |
67 // delete a Layer and it has children, the parent of each child Layer is set to | 67 // delete a Layer and it has children, the parent of each child Layer is set to |
68 // NULL, but the children are not deleted. | 68 // NULL, but the children are not deleted. |
69 class COMPOSITOR_EXPORT Layer | 69 class COMPOSITOR_EXPORT Layer |
70 : public LayerAnimationDelegate, | 70 : public LayerAnimationDelegate, |
71 public LayerObserver, | |
71 NON_EXPORTED_BASE(public cc::ContentLayerClient), | 72 NON_EXPORTED_BASE(public cc::ContentLayerClient), |
72 NON_EXPORTED_BASE(public cc::TextureLayerClient), | 73 NON_EXPORTED_BASE(public cc::TextureLayerClient), |
73 NON_EXPORTED_BASE(public cc::LayerClient) { | 74 NON_EXPORTED_BASE(public cc::LayerClient) { |
74 public: | 75 public: |
75 Layer(); | 76 Layer(); |
76 explicit Layer(LayerType type); | 77 explicit Layer(LayerType type); |
77 ~Layer() override; | 78 ~Layer() override; |
78 | 79 |
80 std::unique_ptr<Layer> Clone() const; | |
81 | |
79 // Retrieves the Layer's compositor. The Layer will walk up its parent chain | 82 // Retrieves the Layer's compositor. The Layer will walk up its parent chain |
80 // to locate it. Returns NULL if the Layer is not attached to a compositor. | 83 // to locate it. Returns NULL if the Layer is not attached to a compositor. |
81 Compositor* GetCompositor() { | 84 Compositor* GetCompositor() { |
82 return const_cast<Compositor*>( | 85 return const_cast<Compositor*>( |
83 const_cast<const Layer*>(this)->GetCompositor()); | 86 const_cast<const Layer*>(this)->GetCompositor()); |
84 } | 87 } |
85 const Compositor* GetCompositor() const; | 88 const Compositor* GetCompositor() const; |
86 | 89 |
87 // Called by the compositor when the Layer is set as its root Layer. This can | 90 // Called by the compositor when the Layer is set as its root Layer. This can |
88 // only ever be called on the root layer. | 91 // only ever be called on the root layer. |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 bool TextureFlipped() const; | 290 bool TextureFlipped() const; |
288 | 291 |
289 // Begins showing content from a surface with a particular id. | 292 // Begins showing content from a surface with a particular id. |
290 void SetShowSurface(const cc::SurfaceId& surface_id, | 293 void SetShowSurface(const cc::SurfaceId& surface_id, |
291 const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, | 294 const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, |
292 const cc::SurfaceLayer::RequireCallback& require_callback, | 295 const cc::SurfaceLayer::RequireCallback& require_callback, |
293 gfx::Size surface_size, | 296 gfx::Size surface_size, |
294 float scale, | 297 float scale, |
295 gfx::Size frame_size_in_dip); | 298 gfx::Size frame_size_in_dip); |
296 | 299 |
300 // Returns a new layer that mirrors this layer and is optionally synchronized | |
301 // with the bounds thereof. Note that children are not mirrored, and that the | |
302 // content is only mirrored if backed by a surface. | |
303 std::unique_ptr<Layer> Mirror(); | |
304 | |
305 void set_sync_bounds(bool sync_bounds) { sync_bounds_ = sync_bounds; } | |
306 | |
297 bool has_external_content() { | 307 bool has_external_content() { |
298 return texture_layer_.get() || surface_layer_.get(); | 308 return texture_layer_.get() || surface_layer_.get(); |
299 } | 309 } |
300 | 310 |
301 // Show a solid color instead of delegated or surface contents. | 311 // Show a solid color instead of delegated or surface contents. |
302 void SetShowSolidColorContent(); | 312 void SetShowSolidColorContent(); |
303 | 313 |
304 // Sets the layer's fill color. May only be called for LAYER_SOLID_COLOR. | 314 // Sets the layer's fill color. May only be called for LAYER_SOLID_COLOR. |
305 void SetColor(SkColor color); | 315 void SetColor(SkColor color); |
306 SkColor GetTargetColor(); | 316 SkColor GetTargetColor() const; |
307 SkColor background_color() const; | 317 SkColor background_color() const; |
308 | 318 |
309 // Updates the nine patch layer's image, aperture and border. May only be | 319 // Updates the nine patch layer's image, aperture and border. May only be |
310 // called for LAYER_NINE_PATCH. | 320 // called for LAYER_NINE_PATCH. |
311 void UpdateNinePatchLayerImage(const gfx::ImageSkia& image); | 321 void UpdateNinePatchLayerImage(const gfx::ImageSkia& image); |
312 void UpdateNinePatchLayerAperture(const gfx::Rect& aperture_in_dip); | 322 void UpdateNinePatchLayerAperture(const gfx::Rect& aperture_in_dip); |
313 void UpdateNinePatchLayerBorder(const gfx::Rect& border); | 323 void UpdateNinePatchLayerBorder(const gfx::Rect& border); |
314 // Updates the area completely occluded by another layer, this can be an | 324 // Updates the area completely occluded by another layer, this can be an |
315 // empty rectangle if nothing is occluded. | 325 // empty rectangle if nothing is occluded. |
316 void UpdateNinePatchOcclusion(const gfx::Rect& occlusion); | 326 void UpdateNinePatchOcclusion(const gfx::Rect& occlusion); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 float GetOpacityForAnimation() const override; | 417 float GetOpacityForAnimation() const override; |
408 bool GetVisibilityForAnimation() const override; | 418 bool GetVisibilityForAnimation() const override; |
409 float GetBrightnessForAnimation() const override; | 419 float GetBrightnessForAnimation() const override; |
410 float GetGrayscaleForAnimation() const override; | 420 float GetGrayscaleForAnimation() const override; |
411 SkColor GetColorForAnimation() const override; | 421 SkColor GetColorForAnimation() const override; |
412 float GetDeviceScaleFactor() const override; | 422 float GetDeviceScaleFactor() const override; |
413 cc::Layer* GetCcLayer() const override; | 423 cc::Layer* GetCcLayer() const override; |
414 LayerThreadedAnimationDelegate* GetThreadedAnimationDelegate() override; | 424 LayerThreadedAnimationDelegate* GetThreadedAnimationDelegate() override; |
415 LayerAnimatorCollection* GetLayerAnimatorCollection() override; | 425 LayerAnimatorCollection* GetLayerAnimatorCollection() override; |
416 | 426 |
427 // LayerObserver: | |
428 void LayerDestroyed(Layer* layer) override; | |
429 | |
417 // Creates a corresponding composited layer for |type_|. | 430 // Creates a corresponding composited layer for |type_|. |
418 void CreateCcLayer(); | 431 void CreateCcLayer(); |
419 | 432 |
420 // Recomputes and sets to |cc_layer_|. | 433 // Recomputes and sets to |cc_layer_|. |
421 void RecomputeDrawsContentAndUVRect(); | 434 void RecomputeDrawsContentAndUVRect(); |
422 void RecomputePosition(); | 435 void RecomputePosition(); |
423 | 436 |
424 // Set all filters which got applied to the layer. | 437 // Set all filters which got applied to the layer. |
425 void SetLayerFilters(); | 438 void SetLayerFilters(); |
426 | 439 |
427 // Set all filters which got applied to the layer background. | 440 // Set all filters which got applied to the layer background. |
428 void SetLayerBackgroundFilters(); | 441 void SetLayerBackgroundFilters(); |
429 | 442 |
430 // Cleanup |cc_layer_| and replaces it with |new_layer|. | 443 // Cleanup |cc_layer_| and replaces it with |new_layer|. |
431 void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); | 444 void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); |
432 | 445 |
433 void SetCompositorForAnimatorsInTree(Compositor* compositor); | 446 void SetCompositorForAnimatorsInTree(Compositor* compositor); |
434 void ResetCompositorForAnimatorsInTree(Compositor* compositor); | 447 void ResetCompositorForAnimatorsInTree(Compositor* compositor); |
435 | 448 |
436 const LayerType type_; | 449 const LayerType type_; |
437 | 450 |
438 Compositor* compositor_; | 451 Compositor* compositor_; |
439 | 452 |
440 Layer* parent_; | 453 Layer* parent_; |
441 | 454 |
442 // This layer's children, in bottom-to-top stacking order. | 455 // This layer's children, in bottom-to-top stacking order. |
443 std::vector<Layer*> children_; | 456 std::vector<Layer*> children_; |
444 | 457 |
458 std::vector<Layer*> mirrors_; // Not owned. | |
459 bool sync_bounds_ = false; // Synchronize bounds to mirrors. | |
sky
2016/10/14 22:36:37
Please add a more descriptive comment. Maybe somet
Dominik Laskowski
2016/10/17 19:53:21
Done.
| |
460 | |
445 gfx::Rect bounds_; | 461 gfx::Rect bounds_; |
446 gfx::Vector2dF subpixel_position_offset_; | 462 gfx::Vector2dF subpixel_position_offset_; |
447 | 463 |
448 // Visibility of this layer. See SetVisible/IsDrawn for more details. | 464 // Visibility of this layer. See SetVisible/IsDrawn for more details. |
449 bool visible_; | 465 bool visible_; |
450 | 466 |
451 bool fills_bounds_opaquely_; | 467 bool fills_bounds_opaquely_; |
452 bool fills_bounds_completely_; | 468 bool fills_bounds_completely_; |
453 | 469 |
454 // Union of damaged rects, in layer space, that SetNeedsDisplayRect should | 470 // Union of damaged rects, in layer space, that SetNeedsDisplayRect should |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
522 // The size of the frame or texture in DIP, set when SetShowDelegatedContent | 538 // The size of the frame or texture in DIP, set when SetShowDelegatedContent |
523 // or SetTextureMailbox was called. | 539 // or SetTextureMailbox was called. |
524 gfx::Size frame_size_in_dip_; | 540 gfx::Size frame_size_in_dip_; |
525 | 541 |
526 DISALLOW_COPY_AND_ASSIGN(Layer); | 542 DISALLOW_COPY_AND_ASSIGN(Layer); |
527 }; | 543 }; |
528 | 544 |
529 } // namespace ui | 545 } // namespace ui |
530 | 546 |
531 #endif // UI_COMPOSITOR_LAYER_H_ | 547 #endif // UI_COMPOSITOR_LAYER_H_ |
OLD | NEW |