Chromium Code Reviews| 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_animator.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. |
|
sky
2011/10/19 00:06:33
Mention this takes ownership of LayerAnimator and
| |
| 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. |
|
sky
2011/10/19 00:06:33
Mention this creates a LayerAnimator if null.
| |
| 87 // the bounds, opacity and transfrom and set to the target value. | 86 LayerAnimator* GetAnimator(); |
| 88 // Layer takes ownership of |animation| and installs it's own delegate on the | |
| 89 // animation. | |
| 90 void SetAnimation(Animation* animation); | |
| 91 | 87 |
| 92 // The transform, relative to the parent. | 88 // The transform, relative to the parent. |
| 93 void SetTransform(const ui::Transform& transform); | 89 void SetTransform(const ui::Transform& transform); |
| 94 const ui::Transform& transform() const { return transform_; } | 90 const ui::Transform& transform() const { return transform_; } |
| 95 | 91 |
| 96 // The bounds, relative to the parent. | 92 // The bounds, relative to the parent. |
| 97 void SetBounds(const gfx::Rect& bounds); | 93 void SetBounds(const gfx::Rect& bounds); |
| 98 const gfx::Rect& bounds() const { return bounds_; } | 94 const gfx::Rect& bounds() const { return bounds_; } |
| 99 | 95 |
| 100 // The opacity of the layer. The opacity is applied to each pixel of the | 96 // The opacity of the layer. The opacity is applied to each pixel of the |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 212 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; | 208 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 213 | 209 |
| 214 bool GetTransformRelativeTo(const Layer* ancestor, | 210 bool GetTransformRelativeTo(const Layer* ancestor, |
| 215 Transform* transform) const; | 211 Transform* transform) const; |
| 216 | 212 |
| 217 // The only externally updated layers are ones that get their pixels from | 213 // The only externally updated layers are ones that get their pixels from |
| 218 // WebKit and WebKit does not produce valid alpha values. All other layers | 214 // WebKit and WebKit does not produce valid alpha values. All other layers |
| 219 // should have valid alpha. | 215 // should have valid alpha. |
| 220 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } | 216 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } |
| 221 | 217 |
| 222 // If the animation is running and has progressed, it is stopped and all | |
| 223 // properties that are animated (except |property|) are immediately set to | |
| 224 // their target value. | |
| 225 void StopAnimatingIfNecessary(LayerAnimator::AnimationProperty property); | |
| 226 | |
| 227 // Following are invoked from the animation or if no animation exists to | 218 // Following are invoked from the animation or if no animation exists to |
| 228 // update the values immediately. | 219 // update the values immediately. |
| 229 void SetBoundsImmediately(const gfx::Rect& bounds); | 220 void SetBoundsImmediately(const gfx::Rect& bounds); |
| 230 void SetTransformImmediately(const ui::Transform& transform); | 221 void SetTransformImmediately(const ui::Transform& transform); |
| 231 void SetOpacityImmediately(float opacity); | 222 void SetOpacityImmediately(float opacity); |
| 232 | 223 |
| 233 // LayerAnimatorDelegate overrides: | 224 // Implementation of LayerAnimationDelegate |
| 234 virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE; | 225 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE; |
| 235 virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE; | 226 virtual void SetTransformFromAnimation(const Transform& transform) OVERRIDE; |
| 236 virtual void SetOpacityFromAnimator(float opacity) OVERRIDE; | 227 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE; |
| 228 virtual void ScheduleDrawForAnimation() OVERRIDE; | |
| 229 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE; | |
| 230 virtual const Transform& GetTransformForAnimation() const OVERRIDE; | |
| 231 virtual const float GetOpacityForAnimation() const OVERRIDE; | |
| 237 | 232 |
| 238 const LayerType type_; | 233 const LayerType type_; |
| 239 | 234 |
| 240 Compositor* compositor_; | 235 Compositor* compositor_; |
| 241 | 236 |
| 242 scoped_refptr<ui::Texture> texture_; | 237 scoped_refptr<ui::Texture> texture_; |
| 243 | 238 |
| 244 Layer* parent_; | 239 Layer* parent_; |
| 245 | 240 |
| 246 std::vector<Layer*> children_; | 241 std::vector<Layer*> children_; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 266 LayerDelegate* delegate_; | 261 LayerDelegate* delegate_; |
| 267 | 262 |
| 268 scoped_ptr<LayerAnimator> animator_; | 263 scoped_ptr<LayerAnimator> animator_; |
| 269 | 264 |
| 270 DISALLOW_COPY_AND_ASSIGN(Layer); | 265 DISALLOW_COPY_AND_ASSIGN(Layer); |
| 271 }; | 266 }; |
| 272 | 267 |
| 273 } // namespace ui | 268 } // namespace ui |
| 274 | 269 |
| 275 #endif // UI_GFX_COMPOSITOR_LAYER_H_ | 270 #endif // UI_GFX_COMPOSITOR_LAYER_H_ |
| OLD | NEW |