Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(353)

Side by Side Diff: ui/gfx/compositor/layer.h

Issue 7972023: Implicit animations through Layer. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More tweaks Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/compositor/compositor.gyp ('k') | ui/gfx/compositor/layer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.h"
19 #include "ui/gfx/compositor/layer_animator_delegate.h"
16 #include "ui/gfx/compositor/layer_delegate.h" 20 #include "ui/gfx/compositor/layer_delegate.h"
17 21
18 class SkCanvas; 22 class SkCanvas;
19 23
20 namespace ui { 24 namespace ui {
21 25
26 class Animation;
22 class Compositor; 27 class Compositor;
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 LayerType { 40 enum LayerType {
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 // |compositor| can be NULL, and will be set later when the Layer is added to 45 // |compositor| can be NULL, and will be set later when the Layer is added to
41 // a Compositor. 46 // a Compositor.
42 explicit Layer(Compositor* compositor); 47 explicit Layer(Compositor* compositor);
43 Layer(Compositor* compositor, LayerType type); 48 Layer(Compositor* compositor, LayerType type);
(...skipping 19 matching lines...) Expand all
63 // Returns the child Layers. 68 // Returns the child Layers.
64 const std::vector<Layer*>& children() { return children_; } 69 const std::vector<Layer*>& children() { return children_; }
65 70
66 // The parent. 71 // The parent.
67 const Layer* parent() const { return parent_; } 72 const Layer* parent() const { return parent_; }
68 Layer* parent() { return parent_; } 73 Layer* parent() { return parent_; }
69 74
70 // Returns true if this Layer contains |other| somewhere in its children. 75 // Returns true if this Layer contains |other| somewhere in its children.
71 bool Contains(const Layer* other) const; 76 bool Contains(const Layer* other) const;
72 77
78 // Sets the animation to use for changes to opacity, position or transform.
79 // That is, if you invoke this with non-NULL |animation| is started and any
80 // changes to opacity, position or transform are animated between the current
81 // value and target value. If the current animation is NULL or completed,
82 // changes are immediate. If the opacity, transform or bounds are changed
83 // and the animation is part way through, the animation is canceled and
84 // the bounds, opacity and transfrom and set to the target value.
85 // Layer takes ownership of |animation| and installs it's own delegate on the
86 // animation.
87 void SetAnimation(Animation* animation);
88
73 // The transform, relative to the parent. 89 // The transform, relative to the parent.
74 void SetTransform(const ui::Transform& transform); 90 void SetTransform(const ui::Transform& transform);
75 const ui::Transform& transform() const { return transform_; } 91 const ui::Transform& transform() const { return transform_; }
76 92
77 // The bounds, relative to the parent. 93 // The bounds, relative to the parent.
78 void SetBounds(const gfx::Rect& bounds); 94 void SetBounds(const gfx::Rect& bounds);
79 const gfx::Rect& bounds() const { return bounds_; } 95 const gfx::Rect& bounds() const { return bounds_; }
80 96
97 // The opacity of the layer. The opacity is applied to each pixel of the
98 // texture (resulting alpha = opacity * alpha).
99 float opacity() const { return opacity_; }
100 void SetOpacity(float opacity);
101
81 // Sets |visible_|. The Layer is drawn by Draw() only when visible_ is true. 102 // Sets |visible_|. The Layer is drawn by Draw() only when visible_ is true.
82 bool visible() const { return visible_; } 103 bool visible() const { return visible_; }
83 void SetVisible(bool visible); 104 void SetVisible(bool visible);
84 105
85 // Returns true if this layer can have a texture (has_texture_ is true) 106 // Returns true if this layer can have a texture (has_texture_ is true)
86 // and is not completely obscured by a child. 107 // and is not completely obscured by a child.
87 bool ShouldDraw(); 108 bool ShouldDraw();
88 109
89 // Converts a point from the coordinates of |source| to the coordinates of 110 // Converts a point from the coordinates of |source| to the coordinates of
90 // |target|. Necessarily, |source| and |target| must inhabit the same Layer 111 // |target|. Necessarily, |source| and |target| must inhabit the same Layer
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 void Draw(); 160 void Draw();
140 161
141 // Draws a tree of Layers, by calling Draw() on each in the hierarchy starting 162 // Draws a tree of Layers, by calling Draw() on each in the hierarchy starting
142 // with the receiver. 163 // with the receiver.
143 void DrawTree(); 164 void DrawTree();
144 165
145 // Sometimes the Layer is being updated by something other than SetCanvas 166 // Sometimes the Layer is being updated by something other than SetCanvas
146 // (e.g. the GPU process on TOUCH_UI). 167 // (e.g. the GPU process on TOUCH_UI).
147 bool layer_updated_externally() const { return layer_updated_externally_; } 168 bool layer_updated_externally() const { return layer_updated_externally_; }
148 169
149 float opacity() const { return opacity_; }
150 void SetOpacity(float alpha);
151
152 private: 170 private:
153 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than 171 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than
154 // 1.0, we'll render to a separate texture, and then apply the alpha. 172 // 1.0, we'll render to a separate texture, and then apply the alpha.
155 // Currently, we multiply our opacity by all our ancestor's opacities and 173 // Currently, we multiply our opacity by all our ancestor's opacities and
156 // use the combined result, but this is only temporary. 174 // use the combined result, but this is only temporary.
157 float GetCombinedOpacity() const; 175 float GetCombinedOpacity() const;
158 176
159 // calls Texture::Draw only if the region to be drawn is non empty 177 // calls Texture::Draw only if the region to be drawn is non empty
160 void DrawRegion(const ui::TextureDrawParams& params, 178 void DrawRegion(const ui::TextureDrawParams& params,
161 const gfx::Rect& region_to_draw); 179 const gfx::Rect& region_to_draw);
(...skipping 20 matching lines...) Expand all
182 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; 200 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const;
183 201
184 bool GetTransformRelativeTo(const Layer* ancestor, 202 bool GetTransformRelativeTo(const Layer* ancestor,
185 Transform* transform) const; 203 Transform* transform) const;
186 204
187 // The only externally updated layers are ones that get their pixels from 205 // The only externally updated layers are ones that get their pixels from
188 // WebKit and WebKit does not produce valid alpha values. All other layers 206 // WebKit and WebKit does not produce valid alpha values. All other layers
189 // should have valid alpha. 207 // should have valid alpha.
190 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } 208 bool has_valid_alpha_channel() const { return !layer_updated_externally_; }
191 209
210 // If the animation is running and has progressed, it is stopped and all
211 // properties that are animated (except |property|) are immediately set to
212 // their target value.
213 void StopAnimatingIfNecessary(LayerAnimator::AnimationProperty property);
214
215 // Following are invoked from the animation or if no animation exists to
216 // update the values immediately.
217 void SetBoundsImmediately(const gfx::Rect& bounds);
218 void SetTransformImmediately(const ui::Transform& transform);
219 void SetOpacityImmediately(float opacity);
220
221 // LayerAnimatorDelegate overrides:
222 virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE;
223 virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE;
224 virtual void SetOpacityFromAnimator(float opacity) OVERRIDE;
225
192 const LayerType type_; 226 const LayerType type_;
193 227
194 Compositor* compositor_; 228 Compositor* compositor_;
195 229
196 scoped_refptr<ui::Texture> texture_; 230 scoped_refptr<ui::Texture> texture_;
197 231
198 Layer* parent_; 232 Layer* parent_;
199 233
200 std::vector<Layer*> children_; 234 std::vector<Layer*> children_;
201 235
202 ui::Transform transform_; 236 ui::Transform transform_;
203 237
204 gfx::Rect bounds_; 238 gfx::Rect bounds_;
205 239
206 bool visible_; 240 bool visible_;
207 241
208 bool fills_bounds_opaquely_; 242 bool fills_bounds_opaquely_;
209 243
210 gfx::Rect hole_rect_; 244 gfx::Rect hole_rect_;
211 245
212 gfx::Rect invalid_rect_; 246 gfx::Rect invalid_rect_;
213 247
214 // If true the layer is always up to date. 248 // If true the layer is always up to date.
215 bool layer_updated_externally_; 249 bool layer_updated_externally_;
216 250
217 float opacity_; 251 float opacity_;
218 252
219 LayerDelegate* delegate_; 253 LayerDelegate* delegate_;
220 254
255 scoped_ptr<LayerAnimator> animator_;
256
221 DISALLOW_COPY_AND_ASSIGN(Layer); 257 DISALLOW_COPY_AND_ASSIGN(Layer);
222 }; 258 };
223 259
224 } // namespace ui 260 } // namespace ui
225 261
226 #endif // UI_GFX_COMPOSITOR_LAYER_H_ 262 #endif // UI_GFX_COMPOSITOR_LAYER_H_
OLDNEW
« no previous file with comments | « ui/gfx/compositor/compositor.gyp ('k') | ui/gfx/compositor/layer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698