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 "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayerClient
.h" | 15 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayerClient
.h" |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebLayer.h" | 16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebLayer.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 Loading... |
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. The layer takes ownership of the animator. |
90 // value and target value. If the current animation is NULL or completed, | 90 void SetAnimator(LayerAnimator* animator); |
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 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; | 260 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; |
256 | 261 |
257 bool GetTransformRelativeTo(const Layer* ancestor, | 262 bool GetTransformRelativeTo(const Layer* ancestor, |
258 Transform* transform) const; | 263 Transform* transform) const; |
259 | 264 |
260 // The only externally updated layers are ones that get their pixels from | 265 // The only externally updated layers are ones that get their pixels from |
261 // WebKit and WebKit does not produce valid alpha values. All other layers | 266 // WebKit and WebKit does not produce valid alpha values. All other layers |
262 // should have valid alpha. | 267 // should have valid alpha. |
263 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } | 268 bool has_valid_alpha_channel() const { return !layer_updated_externally_; } |
264 | 269 |
265 // If the animation is running and has progressed, it is stopped and all | |
266 // properties that are animated (except |property|) are immediately set to | |
267 // their target value. | |
268 void StopAnimatingIfNecessary( | |
269 LayerAnimationManager::AnimationProperty property); | |
270 | |
271 // Following are invoked from the animation or if no animation exists to | 270 // Following are invoked from the animation or if no animation exists to |
272 // update the values immediately. | 271 // update the values immediately. |
273 void SetBoundsImmediately(const gfx::Rect& bounds); | 272 void SetBoundsImmediately(const gfx::Rect& bounds); |
274 void SetTransformImmediately(const ui::Transform& transform); | 273 void SetTransformImmediately(const ui::Transform& transform); |
275 void SetOpacityImmediately(float opacity); | 274 void SetOpacityImmediately(float opacity); |
276 | 275 |
277 // LayerAnimatorDelegate overrides: | 276 // Implementation of LayerAnimatorDelegate |
278 virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE; | 277 virtual void SetBoundsFromAnimation(const gfx::Rect& bounds) OVERRIDE; |
279 virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE; | 278 virtual void SetTransformFromAnimation(const Transform& transform) OVERRIDE; |
280 virtual void SetOpacityFromAnimator(float opacity) OVERRIDE; | 279 virtual void SetOpacityFromAnimation(float opacity) OVERRIDE; |
| 280 virtual void ScheduleDrawForAnimation() OVERRIDE; |
| 281 virtual const gfx::Rect& GetBoundsForAnimation() const OVERRIDE; |
| 282 virtual const Transform& GetTransformForAnimation() const OVERRIDE; |
| 283 virtual float GetOpacityForAnimation() const OVERRIDE; |
| 284 virtual void OnLayerAnimationEnded(LayerAnimationSequence* sequence) OVERRIDE; |
281 | 285 |
282 #if defined(USE_WEBKIT_COMPOSITOR) | 286 #if defined(USE_WEBKIT_COMPOSITOR) |
283 void CreateWebLayer(); | 287 void CreateWebLayer(); |
284 void RecomputeTransform(); | 288 void RecomputeTransform(); |
285 void RecomputeDrawsContent(); | 289 void RecomputeDrawsContent(); |
286 #endif | 290 #endif |
287 | 291 |
288 const LayerType type_; | 292 const LayerType type_; |
289 | 293 |
290 Compositor* compositor_; | 294 Compositor* compositor_; |
(...skipping 19 matching lines...) Expand all Loading... |
310 | 314 |
311 gfx::Rect invalid_rect_; | 315 gfx::Rect invalid_rect_; |
312 | 316 |
313 // If true the layer is always up to date. | 317 // If true the layer is always up to date. |
314 bool layer_updated_externally_; | 318 bool layer_updated_externally_; |
315 | 319 |
316 float opacity_; | 320 float opacity_; |
317 | 321 |
318 LayerDelegate* delegate_; | 322 LayerDelegate* delegate_; |
319 | 323 |
320 scoped_ptr<LayerAnimationManager> animator_; | 324 scoped_ptr<LayerAnimator> animator_; |
321 | 325 |
322 #if defined(USE_WEBKIT_COMPOSITOR) | 326 #if defined(USE_WEBKIT_COMPOSITOR) |
323 WebKit::WebLayer web_layer_; | 327 WebKit::WebLayer web_layer_; |
324 bool web_layer_is_accelerated_; | 328 bool web_layer_is_accelerated_; |
325 #endif | 329 #endif |
326 | 330 |
327 DISALLOW_COPY_AND_ASSIGN(Layer); | 331 DISALLOW_COPY_AND_ASSIGN(Layer); |
328 }; | 332 }; |
329 | 333 |
330 } // namespace ui | 334 } // namespace ui |
331 | 335 |
332 #endif // UI_GFX_COMPOSITOR_LAYER_H_ | 336 #endif // UI_GFX_COMPOSITOR_LAYER_H_ |
OLD | NEW |