| 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/memory/ref_counted.h" | 12 #include "base/memory/ref_counted.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 12 #include "base/message_loop.h" | 14 #include "base/message_loop.h" |
| 13 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
| 14 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
| 15 #include "ui/gfx/compositor/compositor.h" | 17 #include "ui/gfx/compositor/compositor.h" |
| 18 #include "ui/gfx/compositor/layer_animator_delegate.h" |
| 16 #include "ui/gfx/compositor/layer_delegate.h" | 19 #include "ui/gfx/compositor/layer_delegate.h" |
| 17 | 20 |
| 18 class SkCanvas; | 21 class SkCanvas; |
| 19 | 22 |
| 20 namespace ui { | 23 namespace ui { |
| 21 | 24 |
| 25 class Animation; |
| 22 class Compositor; | 26 class Compositor; |
| 27 class LayerAnimator; |
| 23 class Texture; | 28 class Texture; |
| 24 | 29 |
| 25 // Layer manages a texture, transform and a set of child Layers. Any View that | 30 // Layer manages a texture, transform and a set of child Layers. Any View that |
| 26 // has enabled layers ends up creating a Layer to manage the texture. | 31 // has enabled layers ends up creating a Layer to manage the texture. |
| 27 // A Layer can also be created without a texture, in which case it renders | 32 // A Layer can also be created without a texture, in which case it renders |
| 28 // nothing and is simply used as a node in a hierarchy of layers. | 33 // nothing and is simply used as a node in a hierarchy of layers. |
| 29 // | 34 // |
| 30 // NOTE: unlike Views, each Layer does *not* own its children views. If you | 35 // NOTE: unlike Views, each Layer does *not* own its children views. If you |
| 31 // delete a Layer and it has children, the parent of each child layer is set to | 36 // delete a Layer and it has children, the parent of each child layer is set to |
| 32 // NULL, but the children are not deleted. | 37 // NULL, but the children are not deleted. |
| 33 class COMPOSITOR_EXPORT Layer { | 38 class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate { |
| 34 public: | 39 public: |
| 35 enum TextureParam { | 40 enum TextureParam { |
| 36 LAYER_HAS_NO_TEXTURE = 0, | 41 LAYER_HAS_NO_TEXTURE = 0, |
| 37 LAYER_HAS_TEXTURE = 1 | 42 LAYER_HAS_TEXTURE = 1 |
| 38 }; | 43 }; |
| 39 | 44 |
| 40 explicit Layer(Compositor* compositor); | 45 explicit Layer(Compositor* compositor); |
| 41 Layer(Compositor* compositor, TextureParam texture_param); | 46 Layer(Compositor* compositor, TextureParam texture_param); |
| 42 ~Layer(); | 47 ~Layer(); |
| 43 | 48 |
| 44 LayerDelegate* delegate() { return delegate_; } | 49 LayerDelegate* delegate() { return delegate_; } |
| 45 void set_delegate(LayerDelegate* delegate) { delegate_ = delegate; } | 50 void set_delegate(LayerDelegate* delegate) { delegate_ = delegate; } |
| 46 | 51 |
| 47 // Adds a new Layer to this Layer. | 52 // Adds a new Layer to this Layer. |
| 48 void Add(Layer* child); | 53 void Add(Layer* child); |
| 49 | 54 |
| 50 // Removes a Layer from this Layer. | 55 // Removes a Layer from this Layer. |
| 51 void Remove(Layer* child); | 56 void Remove(Layer* child); |
| 52 | 57 |
| 53 // Returns the child Layers. | 58 // Returns the child Layers. |
| 54 const std::vector<Layer*>& children() { return children_; } | 59 const std::vector<Layer*>& children() { return children_; } |
| 55 | 60 |
| 56 // The parent. | 61 // The parent. |
| 57 const Layer* parent() const { return parent_; } | 62 const Layer* parent() const { return parent_; } |
| 58 Layer* parent() { return parent_; } | 63 Layer* parent() { return parent_; } |
| 59 | 64 |
| 60 // Returns true if this Layer contains |other| somewhere in its children. | 65 // Returns true if this Layer contains |other| somewhere in its children. |
| 61 bool Contains(const Layer* other) const; | 66 bool Contains(const Layer* other) const; |
| 62 | 67 |
| 68 // Sets the animation to use for changes to opacity, position or transform. |
| 69 // That is, if you invoke this with non-NULL |animation| is started and any |
| 70 // changes to opacity, position or transform are animated between the current |
| 71 // value and target value. If the current animation is NULL or completed, |
| 72 // changes are immediate. |
| 73 // Layer takes ownership of |animation| and installs it's own delegate on the |
| 74 // animation. |
| 75 void SetAnimation(Animation* animation); |
| 76 |
| 63 // The transform, relative to the parent. | 77 // The transform, relative to the parent. |
| 64 void SetTransform(const ui::Transform& transform); | 78 void SetTransform(const ui::Transform& transform); |
| 65 const ui::Transform& transform() const { return transform_; } | 79 const ui::Transform& transform() const { return transform_; } |
| 66 | 80 |
| 67 // The bounds, relative to the parent. | 81 // The bounds, relative to the parent. |
| 68 void SetBounds(const gfx::Rect& bounds); | 82 void SetBounds(const gfx::Rect& bounds); |
| 69 const gfx::Rect& bounds() const { return bounds_; } | 83 const gfx::Rect& bounds() const { return bounds_; } |
| 70 | 84 |
| 85 float opacity() const { return opacity_; } |
| 86 void SetOpacity(float opacity); |
| 87 |
| 71 // Sets |visible_|. The Layer is drawn by Draw() only when visible_ is true. | 88 // Sets |visible_|. The Layer is drawn by Draw() only when visible_ is true. |
| 72 bool visible() const { return visible_; } | 89 bool visible() const { return visible_; } |
| 73 void set_visible(bool visible) { visible_ = visible; } | 90 void set_visible(bool visible) { visible_ = visible; } |
| 74 | 91 |
| 75 // Returns true if this layer can have a texture (has_texture_ is true) | 92 // Returns true if this layer can have a texture (has_texture_ is true) |
| 76 // and is not completely obscured by a child. | 93 // and is not completely obscured by a child. |
| 77 bool ShouldDraw(); | 94 bool ShouldDraw(); |
| 78 | 95 |
| 79 // Converts a point from the coordinates of |source| to the coordinates of | 96 // Converts a point from the coordinates of |source| to the coordinates of |
| 80 // |target|. Necessarily, |source| and |target| must inhabit the same Layer | 97 // |target|. Necessarily, |source| and |target| must inhabit the same Layer |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 void Draw(); | 146 void Draw(); |
| 130 | 147 |
| 131 // Draws a tree of Layers, by calling Draw() on each in the hierarchy starting | 148 // Draws a tree of Layers, by calling Draw() on each in the hierarchy starting |
| 132 // with the receiver. | 149 // with the receiver. |
| 133 void DrawTree(); | 150 void DrawTree(); |
| 134 | 151 |
| 135 // Sometimes the Layer is being updated by something other than SetCanvas | 152 // Sometimes the Layer is being updated by something other than SetCanvas |
| 136 // (e.g. the GPU process on TOUCH_UI). | 153 // (e.g. the GPU process on TOUCH_UI). |
| 137 bool layer_updated_externally() const { return layer_updated_externally_; } | 154 bool layer_updated_externally() const { return layer_updated_externally_; } |
| 138 | 155 |
| 139 float opacity() const { return opacity_; } | |
| 140 void SetOpacity(float alpha); | |
| 141 | |
| 142 private: | 156 private: |
| 143 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than | 157 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than |
| 144 // 1.0, we'll render to a separate texture, and then apply the alpha. | 158 // 1.0, we'll render to a separate texture, and then apply the alpha. |
| 145 // Currently, we multiply our opacity by all our ancestor's opacities and | 159 // Currently, we multiply our opacity by all our ancestor's opacities and |
| 146 // use the combined result, but this is only temporary. | 160 // use the combined result, but this is only temporary. |
| 147 float GetCombinedOpacity() const; | 161 float GetCombinedOpacity() const; |
| 148 | 162 |
| 149 // calls Texture::Draw only if the region to be drawn is non empty | 163 // calls Texture::Draw only if the region to be drawn is non empty |
| 150 void DrawRegion(const ui::TextureDrawParams& params, | 164 void DrawRegion(const ui::TextureDrawParams& params, |
| 151 const gfx::Rect& region_to_draw); | 165 const gfx::Rect& region_to_draw); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 167 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; | 181 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 168 | 182 |
| 169 bool GetTransformRelativeTo(const Layer* ancestor, | 183 bool GetTransformRelativeTo(const Layer* ancestor, |
| 170 Transform* transform) const; | 184 Transform* transform) const; |
| 171 | 185 |
| 172 // The only externally updated layers are ones that get their pixels from | 186 // The only externally updated layers are ones that get their pixels from |
| 173 // WebKit and WebKit does not produce valid alpha values. All other layers | 187 // WebKit and WebKit does not produce valid alpha values. All other layers |
| 174 // should have valid alpha. | 188 // should have valid alpha. |
| 175 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } | 189 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } |
| 176 | 190 |
| 191 // Following are invoked from the animation or if no animation exists to |
| 192 // update the values immediately. |
| 193 void SetBoundsImmediately(const gfx::Rect& bounds); |
| 194 void SetTransformImmediately(const ui::Transform& transform); |
| 195 void SetOpacityImmediately(float opacity); |
| 196 |
| 197 // LayerAnimatorDelegate overrides: |
| 198 virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE; |
| 199 virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE; |
| 200 virtual void SetOpacityFromAnimator(float opacity) OVERRIDE; |
| 201 |
| 177 Compositor* compositor_; | 202 Compositor* compositor_; |
| 178 | 203 |
| 179 scoped_refptr<ui::Texture> texture_; | 204 scoped_refptr<ui::Texture> texture_; |
| 180 | 205 |
| 181 Layer* parent_; | 206 Layer* parent_; |
| 182 | 207 |
| 183 std::vector<Layer*> children_; | 208 std::vector<Layer*> children_; |
| 184 | 209 |
| 185 ui::Transform transform_; | 210 ui::Transform transform_; |
| 186 | 211 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 197 | 222 |
| 198 gfx::Rect invalid_rect_; | 223 gfx::Rect invalid_rect_; |
| 199 | 224 |
| 200 // If true the layer is always up to date. | 225 // If true the layer is always up to date. |
| 201 bool layer_updated_externally_; | 226 bool layer_updated_externally_; |
| 202 | 227 |
| 203 float opacity_; | 228 float opacity_; |
| 204 | 229 |
| 205 LayerDelegate* delegate_; | 230 LayerDelegate* delegate_; |
| 206 | 231 |
| 232 scoped_ptr<LayerAnimator> animator_; |
| 233 |
| 207 DISALLOW_COPY_AND_ASSIGN(Layer); | 234 DISALLOW_COPY_AND_ASSIGN(Layer); |
| 208 }; | 235 }; |
| 209 | 236 |
| 210 } // namespace ui | 237 } // namespace ui |
| 211 | 238 |
| 212 #endif // UI_GFX_COMPOSITOR_LAYER_H_ | 239 #endif // UI_GFX_COMPOSITOR_LAYER_H_ |
| OLD | NEW |