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

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

Issue 8362006: Reland r107720 - Enable the new layer animation framework. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Enable framework for aura 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
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/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 "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayer.h" 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayer.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayerClient .h" 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayerClient .h"
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerClient.h" 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerClient.h"
18 #include "ui/gfx/rect.h" 18 #include "ui/gfx/rect.h"
19 #include "ui/gfx/transform.h" 19 #include "ui/gfx/transform.h"
20 #include "ui/gfx/compositor/compositor.h" 20 #include "ui/gfx/compositor/compositor.h"
21 #include "ui/gfx/compositor/layer_animation_manager.h"
22 #include "ui/gfx/compositor/layer_animator_delegate.h" 21 #include "ui/gfx/compositor/layer_animator_delegate.h"
23 #include "ui/gfx/compositor/layer_delegate.h" 22 #include "ui/gfx/compositor/layer_delegate.h"
24 23
25 class SkCanvas; 24 class SkCanvas;
26 25
27 namespace ui { 26 namespace ui {
28 27
29 class Animation;
30 class Compositor; 28 class Compositor;
29 class LayerAnimator;
30 class LayerAnimationSequence;
31 class Texture; 31 class Texture;
32 32
33 // Layer manages a texture, transform and a set of child Layers. Any View that 33 // Layer manages a texture, transform and a set of child Layers. Any View that
34 // has enabled layers ends up creating a Layer to manage the texture. 34 // has enabled layers ends up creating a Layer to manage the texture.
35 // A Layer can also be created without a texture, in which case it renders 35 // A Layer can also be created without a texture, in which case it renders
36 // nothing and is simply used as a node in a hierarchy of layers. 36 // nothing and is simply used as a node in a hierarchy of layers.
37 // 37 //
38 // NOTE: unlike Views, each Layer does *not* own its children views. If you 38 // NOTE: unlike Views, each Layer does *not* own its children views. If you
39 // delete a Layer and it has children, the parent of each child layer is set to 39 // delete a Layer and it has children, the parent of each child layer is set to
40 // NULL, but the children are not deleted. 40 // NULL, but the children are not deleted.
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 // Returns the child Layers. 77 // Returns the child Layers.
78 const std::vector<Layer*>& children() const { return children_; } 78 const std::vector<Layer*>& children() const { return children_; }
79 79
80 // The parent. 80 // The parent.
81 const Layer* parent() const { return parent_; } 81 const Layer* parent() const { return parent_; }
82 Layer* parent() { return parent_; } 82 Layer* parent() { return parent_; }
83 83
84 // Returns true if this Layer contains |other| somewhere in its children. 84 // Returns true if this Layer contains |other| somewhere in its children.
85 bool Contains(const Layer* other) const; 85 bool Contains(const Layer* other) const;
86 86
87 // Sets the animation to use for changes to opacity, position or transform. 87 // The layer's animator is responsible for causing automatic animations when
88 // That is, if you invoke this with non-NULL |animation| is started and any 88 // properties are set. It also manages a queue of pending animations and
89 // changes to opacity, position or transform are animated between the current 89 // handles blending of animations.
90 // value and target value. If the current animation is NULL or completed, 90 void SetAnimator(LayerAnimator* animator);
sky 2011/10/25 04:00:55 document ownership.
91 // changes are immediate. If the opacity, transform or bounds are changed 91
92 // and the animation is part way through, the animation is canceled and 92 // Returns the layer's animator. Creates a default animator of one has not
93 // the bounds, opacity and transfrom and set to the target value. 93 // been set. Will not return NULL.
94 // Layer takes ownership of |animation| and installs it's own delegate on the 94 LayerAnimator* GetAnimator();
95 // animation.
96 void SetAnimation(Animation* animation);
97 bool has_animation() const { return animator_.get() != NULL; }
98 95
99 // The transform, relative to the parent. 96 // The transform, relative to the parent.
100 void SetTransform(const ui::Transform& transform); 97 void SetTransform(const Transform& transform);
101 const ui::Transform& transform() const { return transform_; } 98 const Transform& transform() const { return transform_; }
99
100 // Return the target transform if animator is running, or the current
101 // transform otherwise.
102 Transform GetTargetTransform() const;
102 103
103 // The bounds, relative to the parent. 104 // The bounds, relative to the parent.
104 void SetBounds(const gfx::Rect& bounds); 105 void SetBounds(const gfx::Rect& bounds);
105 const gfx::Rect& bounds() const { return bounds_; } 106 const gfx::Rect& bounds() const { return bounds_; }
106 107
107 // Return the target bounds if animator is running, or the current bounds 108 // Return the target bounds if animator is running, or the current bounds
108 // otherwise. 109 // otherwise.
109 gfx::Rect GetTargetBounds() const; 110 gfx::Rect GetTargetBounds() const;
110 111
111 // The opacity of the layer. The opacity is applied to each pixel of the 112 // The opacity of the layer. The opacity is applied to each pixel of the
112 // texture (resulting alpha = opacity * alpha). 113 // texture (resulting alpha = opacity * alpha).
113 float opacity() const { return opacity_; } 114 float opacity() const { return opacity_; }
114 void SetOpacity(float opacity); 115 void SetOpacity(float opacity);
115 116
117 // Return the target opacity if animator is running, or the current bounds
118 // otherwise.
119 float GetTargetOpacity() const;
120
116 // Sets the visibility of the Layer. A Layer may be visible but not 121 // Sets the visibility of the Layer. A Layer may be visible but not
117 // drawn. This happens if any ancestor of a Layer is not visible. 122 // drawn. This happens if any ancestor of a Layer is not visible.
118 void SetVisible(bool visible); 123 void SetVisible(bool visible);
119 bool visible() const { return visible_; } 124 bool visible() const { return visible_; }
120 125
121 // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors 126 // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors
122 // are visible. 127 // are visible.
123 bool IsDrawn() const; 128 bool IsDrawn() const;
124 129
125 // Returns true if this layer can have a texture (has_texture_ is true) 130 // Returns true if this layer can have a texture (has_texture_ is true)
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; 238 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const;
234 239
235 bool GetTransformRelativeTo(const Layer* ancestor, 240 bool GetTransformRelativeTo(const Layer* ancestor,
236 Transform* transform) const; 241 Transform* transform) const;
237 242
238 // The only externally updated layers are ones that get their pixels from 243 // The only externally updated layers are ones that get their pixels from
239 // WebKit and WebKit does not produce valid alpha values. All other layers 244 // WebKit and WebKit does not produce valid alpha values. All other layers
240 // should have valid alpha. 245 // should have valid alpha.
241 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } 246 bool has_valid_alpha_channel() const { return !layer_updated_externally_; }
242 247
243 // If the animation is running and has progressed, it is stopped and all
244 // properties that are animated (except |property|) are immediately set to
245 // their target value.
246 void StopAnimatingIfNecessary(
247 LayerAnimationManager::AnimationProperty property);
248
249 // Following are invoked from the animation or if no animation exists to 248 // Following are invoked from the animation or if no animation exists to
250 // update the values immediately. 249 // update the values immediately.
251 void SetBoundsImmediately(const gfx::Rect& bounds); 250 void SetBoundsImmediately(const gfx::Rect& bounds);
252 void SetTransformImmediately(const ui::Transform& transform); 251 void SetTransformImmediately(const ui::Transform& transform);
253 void SetOpacityImmediately(float opacity); 252 void SetOpacityImmediately(float opacity);
254 253
255 // LayerAnimatorDelegate overrides: 254 // Implementation of LayerAnimatorDelegate
256 virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE; 255 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE;
257 virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE; 256 virtual void SetTransformFromAnimation(const Transform& transform) OVERRIDE;
258 virtual void SetOpacityFromAnimator(float opacity) OVERRIDE; 257 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE;
258 virtual void ScheduleDrawForAnimation() OVERRIDE;
259 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE;
260 virtual const Transform& GetTransformForAnimation() const OVERRIDE;
261 virtual float GetOpacityForAnimation() const OVERRIDE;
262 virtual void OnLayerAnimationEnded(LayerAnimationSequence* sequence) OVERRIDE;
259 263
260 #if defined(USE_WEBKIT_COMPOSITOR) 264 #if defined(USE_WEBKIT_COMPOSITOR)
261 void CreateWebLayer(); 265 void CreateWebLayer();
262 void RecomputeTransform(); 266 void RecomputeTransform();
263 void RecomputeDrawsContent(); 267 void RecomputeDrawsContent();
264 #endif 268 #endif
265 269
266 const LayerType type_; 270 const LayerType type_;
267 271
268 Compositor* compositor_; 272 Compositor* compositor_;
(...skipping 17 matching lines...) Expand all
286 290
287 gfx::Rect invalid_rect_; 291 gfx::Rect invalid_rect_;
288 292
289 // If true the layer is always up to date. 293 // If true the layer is always up to date.
290 bool layer_updated_externally_; 294 bool layer_updated_externally_;
291 295
292 float opacity_; 296 float opacity_;
293 297
294 LayerDelegate* delegate_; 298 LayerDelegate* delegate_;
295 299
296 scoped_ptr<LayerAnimationManager> animator_; 300 scoped_ptr<LayerAnimator> animator_;
297 301
298 #if defined(USE_WEBKIT_COMPOSITOR) 302 #if defined(USE_WEBKIT_COMPOSITOR)
299 WebKit::WebContentLayer web_layer_; 303 WebKit::WebContentLayer web_layer_;
300 #endif 304 #endif
301 305
302 DISALLOW_COPY_AND_ASSIGN(Layer); 306 DISALLOW_COPY_AND_ASSIGN(Layer);
303 }; 307 };
304 308
305 } // namespace ui 309 } // namespace ui
306 310
307 #endif // UI_GFX_COMPOSITOR_LAYER_H_ 311 #endif // UI_GFX_COMPOSITOR_LAYER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698