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); |
78 explicit Layer(const Layer&); | |
sky
2016/10/13 19:21:33
The style guide generally frowns on this, especial
Dominik Laskowski
2016/10/13 22:19:39
It's also called from LayerOwner::RecreateLayer. W
sky
2016/10/14 15:18:41
Yes please.
Dominik Laskowski
2016/10/14 19:15:02
Done.
| |
77 ~Layer() override; | 79 ~Layer() override; |
78 | 80 |
79 // Retrieves the Layer's compositor. The Layer will walk up its parent chain | 81 // 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. | 82 // to locate it. Returns NULL if the Layer is not attached to a compositor. |
81 Compositor* GetCompositor() { | 83 Compositor* GetCompositor() { |
82 return const_cast<Compositor*>( | 84 return const_cast<Compositor*>( |
83 const_cast<const Layer*>(this)->GetCompositor()); | 85 const_cast<const Layer*>(this)->GetCompositor()); |
84 } | 86 } |
85 const Compositor* GetCompositor() const; | 87 const Compositor* GetCompositor() const; |
86 | 88 |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
287 bool TextureFlipped() const; | 289 bool TextureFlipped() const; |
288 | 290 |
289 // Begins showing content from a surface with a particular id. | 291 // Begins showing content from a surface with a particular id. |
290 void SetShowSurface(const cc::SurfaceId& surface_id, | 292 void SetShowSurface(const cc::SurfaceId& surface_id, |
291 const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, | 293 const cc::SurfaceLayer::SatisfyCallback& satisfy_callback, |
292 const cc::SurfaceLayer::RequireCallback& require_callback, | 294 const cc::SurfaceLayer::RequireCallback& require_callback, |
293 gfx::Size surface_size, | 295 gfx::Size surface_size, |
294 float scale, | 296 float scale, |
295 gfx::Size frame_size_in_dip); | 297 gfx::Size frame_size_in_dip); |
296 | 298 |
299 // Returns a new layer that mirrors this layer and is optionally synchronized | |
300 // with the bounds thereof. Note that children are not mirrored, and that the | |
301 // content is only mirrored if backed by a surface. | |
302 std::unique_ptr<Layer> Mirror(); | |
303 | |
304 void set_sync_bounds(bool sync_bounds) { sync_bounds_ = sync_bounds; } | |
305 | |
297 bool has_external_content() { | 306 bool has_external_content() { |
298 return texture_layer_.get() || surface_layer_.get(); | 307 return texture_layer_.get() || surface_layer_.get(); |
299 } | 308 } |
300 | 309 |
301 // Show a solid color instead of delegated or surface contents. | 310 // Show a solid color instead of delegated or surface contents. |
302 void SetShowSolidColorContent(); | 311 void SetShowSolidColorContent(); |
303 | 312 |
304 // Sets the layer's fill color. May only be called for LAYER_SOLID_COLOR. | 313 // Sets the layer's fill color. May only be called for LAYER_SOLID_COLOR. |
305 void SetColor(SkColor color); | 314 void SetColor(SkColor color); |
306 SkColor GetTargetColor(); | 315 SkColor GetTargetColor() const; |
307 SkColor background_color() const; | 316 SkColor background_color() const; |
308 | 317 |
309 // Updates the nine patch layer's image, aperture and border. May only be | 318 // Updates the nine patch layer's image, aperture and border. May only be |
310 // called for LAYER_NINE_PATCH. | 319 // called for LAYER_NINE_PATCH. |
311 void UpdateNinePatchLayerImage(const gfx::ImageSkia& image); | 320 void UpdateNinePatchLayerImage(const gfx::ImageSkia& image); |
312 void UpdateNinePatchLayerAperture(const gfx::Rect& aperture_in_dip); | 321 void UpdateNinePatchLayerAperture(const gfx::Rect& aperture_in_dip); |
313 void UpdateNinePatchLayerBorder(const gfx::Rect& border); | 322 void UpdateNinePatchLayerBorder(const gfx::Rect& border); |
314 // Updates the area completely occluded by another layer, this can be an | 323 // Updates the area completely occluded by another layer, this can be an |
315 // empty rectangle if nothing is occluded. | 324 // empty rectangle if nothing is occluded. |
316 void UpdateNinePatchOcclusion(const gfx::Rect& occlusion); | 325 void UpdateNinePatchOcclusion(const gfx::Rect& occlusion); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
407 float GetOpacityForAnimation() const override; | 416 float GetOpacityForAnimation() const override; |
408 bool GetVisibilityForAnimation() const override; | 417 bool GetVisibilityForAnimation() const override; |
409 float GetBrightnessForAnimation() const override; | 418 float GetBrightnessForAnimation() const override; |
410 float GetGrayscaleForAnimation() const override; | 419 float GetGrayscaleForAnimation() const override; |
411 SkColor GetColorForAnimation() const override; | 420 SkColor GetColorForAnimation() const override; |
412 float GetDeviceScaleFactor() const override; | 421 float GetDeviceScaleFactor() const override; |
413 cc::Layer* GetCcLayer() const override; | 422 cc::Layer* GetCcLayer() const override; |
414 LayerThreadedAnimationDelegate* GetThreadedAnimationDelegate() override; | 423 LayerThreadedAnimationDelegate* GetThreadedAnimationDelegate() override; |
415 LayerAnimatorCollection* GetLayerAnimatorCollection() override; | 424 LayerAnimatorCollection* GetLayerAnimatorCollection() override; |
416 | 425 |
426 // LayerObserver: | |
427 void LayerDestroyed(Layer* layer) override; | |
428 | |
417 // Creates a corresponding composited layer for |type_|. | 429 // Creates a corresponding composited layer for |type_|. |
418 void CreateCcLayer(); | 430 void CreateCcLayer(); |
419 | 431 |
420 // Recomputes and sets to |cc_layer_|. | 432 // Recomputes and sets to |cc_layer_|. |
421 void RecomputeDrawsContentAndUVRect(); | 433 void RecomputeDrawsContentAndUVRect(); |
422 void RecomputePosition(); | 434 void RecomputePosition(); |
423 | 435 |
424 // Set all filters which got applied to the layer. | 436 // Set all filters which got applied to the layer. |
425 void SetLayerFilters(); | 437 void SetLayerFilters(); |
426 | 438 |
427 // Set all filters which got applied to the layer background. | 439 // Set all filters which got applied to the layer background. |
428 void SetLayerBackgroundFilters(); | 440 void SetLayerBackgroundFilters(); |
429 | 441 |
430 // Cleanup |cc_layer_| and replaces it with |new_layer|. | 442 // Cleanup |cc_layer_| and replaces it with |new_layer|. |
431 void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); | 443 void SwitchToLayer(scoped_refptr<cc::Layer> new_layer); |
432 | 444 |
433 void SetCompositorForAnimatorsInTree(Compositor* compositor); | 445 void SetCompositorForAnimatorsInTree(Compositor* compositor); |
434 void ResetCompositorForAnimatorsInTree(Compositor* compositor); | 446 void ResetCompositorForAnimatorsInTree(Compositor* compositor); |
435 | 447 |
436 const LayerType type_; | 448 const LayerType type_; |
437 | 449 |
438 Compositor* compositor_; | 450 Compositor* compositor_; |
439 | 451 |
440 Layer* parent_; | 452 Layer* parent_; |
441 | 453 |
442 // This layer's children, in bottom-to-top stacking order. | 454 // This layer's children, in bottom-to-top stacking order. |
443 std::vector<Layer*> children_; | 455 std::vector<Layer*> children_; |
444 | 456 |
457 std::vector<Layer*> mirrors_; // Not owned. | |
sky
2016/10/13 19:21:33
std::vector->std::set as you don't need the order.
Dominik Laskowski
2016/10/13 22:19:39
I started with std::unordered_set, but figured std
sky
2016/10/14 15:18:41
I like set to convey it's unordered, but ok.
| |
458 bool sync_bounds_ = false; // Synchronize bounds to mirrors. | |
459 | |
445 gfx::Rect bounds_; | 460 gfx::Rect bounds_; |
446 gfx::Vector2dF subpixel_position_offset_; | 461 gfx::Vector2dF subpixel_position_offset_; |
447 | 462 |
448 // Visibility of this layer. See SetVisible/IsDrawn for more details. | 463 // Visibility of this layer. See SetVisible/IsDrawn for more details. |
449 bool visible_; | 464 bool visible_; |
450 | 465 |
451 bool fills_bounds_opaquely_; | 466 bool fills_bounds_opaquely_; |
452 bool fills_bounds_completely_; | 467 bool fills_bounds_completely_; |
453 | 468 |
454 // Union of damaged rects, in layer space, that SetNeedsDisplayRect should | 469 // Union of damaged rects, in layer space, that SetNeedsDisplayRect should |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
516 cc::TextureMailbox mailbox_; | 531 cc::TextureMailbox mailbox_; |
517 | 532 |
518 // The callback to release the mailbox. This is only set after | 533 // The callback to release the mailbox. This is only set after |
519 // SetTextureMailbox is called, before we give it to the TextureLayer. | 534 // SetTextureMailbox is called, before we give it to the TextureLayer. |
520 std::unique_ptr<cc::SingleReleaseCallback> mailbox_release_callback_; | 535 std::unique_ptr<cc::SingleReleaseCallback> mailbox_release_callback_; |
521 | 536 |
522 // The size of the frame or texture in DIP, set when SetShowDelegatedContent | 537 // The size of the frame or texture in DIP, set when SetShowDelegatedContent |
523 // or SetTextureMailbox was called. | 538 // or SetTextureMailbox was called. |
524 gfx::Size frame_size_in_dip_; | 539 gfx::Size frame_size_in_dip_; |
525 | 540 |
526 DISALLOW_COPY_AND_ASSIGN(Layer); | 541 DISALLOW_ASSIGN(Layer); |
527 }; | 542 }; |
528 | 543 |
529 } // namespace ui | 544 } // namespace ui |
530 | 545 |
531 #endif // UI_COMPOSITOR_LAYER_H_ | 546 #endif // UI_COMPOSITOR_LAYER_H_ |
OLD | NEW |