| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_GFX_COMPOSITOR_LAYER_H_ | 5 #ifndef UI_GFX_COMPOSITOR_LAYER_H_ |
| 6 #define UI_GFX_COMPOSITOR_LAYER_H_ | 6 #define UI_GFX_COMPOSITOR_LAYER_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 12 #include "base/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 14 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 15 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 16 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
| 17 #include "ui/gfx/compositor/compositor.h" | 17 #include "ui/gfx/compositor/compositor.h" |
| 18 #include "ui/gfx/compositor/layer_animation_manager.h" | 18 #include "ui/gfx/compositor/layer_animation_delegate.h" |
| 19 #include "ui/gfx/compositor/layer_animator_delegate.h" | |
| 20 #include "ui/gfx/compositor/layer_delegate.h" | 19 #include "ui/gfx/compositor/layer_delegate.h" |
| 21 | 20 |
| 22 class SkCanvas; | 21 class SkCanvas; |
| 23 | 22 |
| 24 namespace ui { | 23 namespace ui { |
| 25 | 24 |
| 26 class Animation; | |
| 27 class Compositor; | 25 class Compositor; |
| 26 class LayerAnimator; |
| 28 class Texture; | 27 class Texture; |
| 29 | 28 |
| 30 // Layer manages a texture, transform and a set of child Layers. Any View that | 29 // Layer manages a texture, transform and a set of child Layers. Any View that |
| 31 // has enabled layers ends up creating a Layer to manage the texture. | 30 // has enabled layers ends up creating a Layer to manage the texture. |
| 32 // A Layer can also be created without a texture, in which case it renders | 31 // A Layer can also be created without a texture, in which case it renders |
| 33 // nothing and is simply used as a node in a hierarchy of layers. | 32 // nothing and is simply used as a node in a hierarchy of layers. |
| 34 // | 33 // |
| 35 // NOTE: unlike Views, each Layer does *not* own its children views. If you | 34 // NOTE: unlike Views, each Layer does *not* own its children views. If you |
| 36 // delete a Layer and it has children, the parent of each child layer is set to | 35 // delete a Layer and it has children, the parent of each child layer is set to |
| 37 // NULL, but the children are not deleted. | 36 // NULL, but the children are not deleted. |
| 38 class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate { | 37 class COMPOSITOR_EXPORT Layer : public LayerAnimationDelegate { |
| 39 public: | 38 public: |
| 40 enum LayerType { | 39 enum LayerType { |
| 41 LAYER_HAS_NO_TEXTURE = 0, | 40 LAYER_HAS_NO_TEXTURE = 0, |
| 42 LAYER_HAS_TEXTURE = 1 | 41 LAYER_HAS_TEXTURE = 1 |
| 43 }; | 42 }; |
| 44 | 43 |
| 45 // |compositor| can be NULL, and will be set later when the Layer is added to | 44 // |compositor| can be NULL, and will be set later when the Layer is added to |
| 46 // a Compositor. | 45 // a Compositor. |
| 47 explicit Layer(Compositor* compositor); | 46 explicit Layer(Compositor* compositor); |
| 48 Layer(Compositor* compositor, LayerType type); | 47 Layer(Compositor* compositor, LayerType type); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 71 // Returns the child Layers. | 70 // Returns the child Layers. |
| 72 const std::vector<Layer*>& children() const { return children_; } | 71 const std::vector<Layer*>& children() const { return children_; } |
| 73 | 72 |
| 74 // The parent. | 73 // The parent. |
| 75 const Layer* parent() const { return parent_; } | 74 const Layer* parent() const { return parent_; } |
| 76 Layer* parent() { return parent_; } | 75 Layer* parent() { return parent_; } |
| 77 | 76 |
| 78 // Returns true if this Layer contains |other| somewhere in its children. | 77 // Returns true if this Layer contains |other| somewhere in its children. |
| 79 bool Contains(const Layer* other) const; | 78 bool Contains(const Layer* other) const; |
| 80 | 79 |
| 81 // Sets the animation to use for changes to opacity, position or transform. | 80 // The layer's animator is responsible for causing automatic animations when |
| 82 // That is, if you invoke this with non-NULL |animation| is started and any | 81 // properties are set. It also manages a queue of pending animations and |
| 83 // changes to opacity, position or transform are animated between the current | 82 // handles blending of animations. |
| 84 // value and target value. If the current animation is NULL or completed, | 83 void SetAnimator(LayerAnimator* animator); |
| 85 // changes are immediate. If the opacity, transform or bounds are changed | 84 |
| 86 // and the animation is part way through, the animation is canceled and | 85 // Returns the layer's animator. Creates a default animator of one has not |
| 87 // the bounds, opacity and transfrom and set to the target value. | 86 // been set. Will not return NULL. |
| 88 // Layer takes ownership of |animation| and installs it's own delegate on the | 87 LayerAnimator* GetAnimator(); |
| 89 // animation. | |
| 90 void SetAnimation(Animation* animation); | |
| 91 | 88 |
| 92 // The transform, relative to the parent. | 89 // The transform, relative to the parent. |
| 93 void SetTransform(const ui::Transform& transform); | 90 void SetTransform(const ui::Transform& transform); |
| 94 const ui::Transform& transform() const { return transform_; } | 91 const Transform& transform() const { return transform_; } |
| 92 |
| 93 // Return the target transform if animator is running, or the current |
| 94 // transform otherwise. |
| 95 Transform GetTargetTransform() const; |
| 95 | 96 |
| 96 // The bounds, relative to the parent. | 97 // The bounds, relative to the parent. |
| 97 void SetBounds(const gfx::Rect& bounds); | 98 void SetBounds(const gfx::Rect& bounds); |
| 98 const gfx::Rect& bounds() const { return bounds_; } | 99 const gfx::Rect& bounds() const { return bounds_; } |
| 99 | 100 |
| 100 // Return the target bounds if animator is running, or the current bounds | 101 // Return the target bounds if animator is running, or the current bounds |
| 101 // otherwise. | 102 // otherwise. |
| 102 gfx::Rect GetTargetBounds() const; | 103 gfx::Rect GetTargetBounds() const; |
| 103 | 104 |
| 104 // The opacity of the layer. The opacity is applied to each pixel of the | 105 // The opacity of the layer. The opacity is applied to each pixel of the |
| 105 // texture (resulting alpha = opacity * alpha). | 106 // texture (resulting alpha = opacity * alpha). |
| 106 float opacity() const { return opacity_; } | 107 float opacity() const { return opacity_; } |
| 107 void SetOpacity(float opacity); | 108 void SetOpacity(float opacity); |
| 108 | 109 |
| 110 // Return the target opacity if animator is running, or the current bounds |
| 111 // otherwise. |
| 112 float GetTargetOpacity() const; |
| 113 |
| 109 // Sets the visibility of the Layer. A Layer may be visible but not | 114 // Sets the visibility of the Layer. A Layer may be visible but not |
| 110 // drawn. This happens if any ancestor of a Layer is not visible. | 115 // drawn. This happens if any ancestor of a Layer is not visible. |
| 111 void SetVisible(bool visible); | 116 void SetVisible(bool visible); |
| 112 bool visible() const { return visible_; } | 117 bool visible() const { return visible_; } |
| 113 | 118 |
| 114 // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors | 119 // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors |
| 115 // are visible. | 120 // are visible. |
| 116 bool IsDrawn() const; | 121 bool IsDrawn() const; |
| 117 | 122 |
| 118 // Returns true if this layer can have a texture (has_texture_ is true) | 123 // Returns true if this layer can have a texture (has_texture_ is true) |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; | 221 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 217 | 222 |
| 218 bool GetTransformRelativeTo(const Layer* ancestor, | 223 bool GetTransformRelativeTo(const Layer* ancestor, |
| 219 Transform* transform) const; | 224 Transform* transform) const; |
| 220 | 225 |
| 221 // The only externally updated layers are ones that get their pixels from | 226 // The only externally updated layers are ones that get their pixels from |
| 222 // WebKit and WebKit does not produce valid alpha values. All other layers | 227 // WebKit and WebKit does not produce valid alpha values. All other layers |
| 223 // should have valid alpha. | 228 // should have valid alpha. |
| 224 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } | 229 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } |
| 225 | 230 |
| 226 // If the animation is running and has progressed, it is stopped and all | |
| 227 // properties that are animated (except |property|) are immediately set to | |
| 228 // their target value. | |
| 229 void StopAnimatingIfNecessary( | |
| 230 LayerAnimationManager::AnimationProperty property); | |
| 231 | |
| 232 // Following are invoked from the animation or if no animation exists to | 231 // Following are invoked from the animation or if no animation exists to |
| 233 // update the values immediately. | 232 // update the values immediately. |
| 234 void SetBoundsImmediately(const gfx::Rect& bounds); | 233 void SetBoundsImmediately(const gfx::Rect& bounds); |
| 235 void SetTransformImmediately(const ui::Transform& transform); | 234 void SetTransformImmediately(const ui::Transform& transform); |
| 236 void SetOpacityImmediately(float opacity); | 235 void SetOpacityImmediately(float opacity); |
| 237 | 236 |
| 238 // LayerAnimatorDelegate overrides: | 237 // Implementation of LayerAnimationDelegate |
| 239 virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE; | 238 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE; |
| 240 virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE; | 239 virtual void SetTransformFromAnimation(const Transform& transform) OVERRIDE; |
| 241 virtual void SetOpacityFromAnimator(float opacity) OVERRIDE; | 240 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE; |
| 241 virtual void ScheduleDrawForAnimation() OVERRIDE; |
| 242 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE; |
| 243 virtual const Transform& GetTransformForAnimation() const OVERRIDE; |
| 244 virtual float GetOpacityForAnimation() const OVERRIDE; |
| 242 | 245 |
| 243 const LayerType type_; | 246 const LayerType type_; |
| 244 | 247 |
| 245 Compositor* compositor_; | 248 Compositor* compositor_; |
| 246 | 249 |
| 247 scoped_refptr<ui::Texture> texture_; | 250 scoped_refptr<ui::Texture> texture_; |
| 248 | 251 |
| 249 Layer* parent_; | 252 Layer* parent_; |
| 250 | 253 |
| 251 std::vector<Layer*> children_; | 254 std::vector<Layer*> children_; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 263 | 266 |
| 264 gfx::Rect invalid_rect_; | 267 gfx::Rect invalid_rect_; |
| 265 | 268 |
| 266 // If true the layer is always up to date. | 269 // If true the layer is always up to date. |
| 267 bool layer_updated_externally_; | 270 bool layer_updated_externally_; |
| 268 | 271 |
| 269 float opacity_; | 272 float opacity_; |
| 270 | 273 |
| 271 LayerDelegate* delegate_; | 274 LayerDelegate* delegate_; |
| 272 | 275 |
| 273 scoped_ptr<LayerAnimationManager> animator_; | 276 scoped_ptr<LayerAnimator> animator_; |
| 274 | 277 |
| 275 DISALLOW_COPY_AND_ASSIGN(Layer); | 278 DISALLOW_COPY_AND_ASSIGN(Layer); |
| 276 }; | 279 }; |
| 277 | 280 |
| 278 } // namespace ui | 281 } // namespace ui |
| 279 | 282 |
| 280 #endif // UI_GFX_COMPOSITOR_LAYER_H_ | 283 #endif // UI_GFX_COMPOSITOR_LAYER_H_ |
| OLD | NEW |