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/WebContentLayer.h" | |
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayerClient
.h" | |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerClient.h" | |
18 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
19 #include "ui/gfx/transform.h" | 16 #include "ui/gfx/transform.h" |
20 #include "ui/gfx/compositor/compositor.h" | 17 #include "ui/gfx/compositor/compositor.h" |
21 #include "ui/gfx/compositor/layer_animator.h" | 18 #include "ui/gfx/compositor/layer_animator.h" |
22 #include "ui/gfx/compositor/layer_animator_delegate.h" | 19 #include "ui/gfx/compositor/layer_animator_delegate.h" |
23 #include "ui/gfx/compositor/layer_delegate.h" | 20 #include "ui/gfx/compositor/layer_delegate.h" |
24 | 21 |
25 class SkCanvas; | 22 class SkCanvas; |
26 | 23 |
27 namespace ui { | 24 namespace ui { |
28 | 25 |
29 class Animation; | 26 class Animation; |
30 class Compositor; | 27 class Compositor; |
31 class Texture; | 28 class Texture; |
32 | 29 |
33 // 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 |
34 // 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. |
35 // 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 |
36 // 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. |
37 // | 34 // |
38 // 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 |
39 // 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 |
40 // NULL, but the children are not deleted. | 37 // NULL, but the children are not deleted. |
41 class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate, | 38 class COMPOSITOR_EXPORT Layer : public LayerAnimatorDelegate { |
42 public WebKit::WebLayerClient, | |
43 public WebKit::WebContentLayerClient { | |
44 public: | 39 public: |
45 enum LayerType { | 40 enum LayerType { |
46 LAYER_HAS_NO_TEXTURE = 0, | 41 LAYER_HAS_NO_TEXTURE = 0, |
47 LAYER_HAS_TEXTURE = 1 | 42 LAYER_HAS_TEXTURE = 1 |
48 }; | 43 }; |
49 | 44 |
50 // |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 |
51 // a Compositor. | 46 // a Compositor. |
52 explicit Layer(Compositor* compositor); | 47 explicit Layer(Compositor* compositor); |
53 Layer(Compositor* compositor, LayerType type); | 48 Layer(Compositor* compositor, LayerType type); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 // drawn. This happens if any ancestor of a Layer is not visible. | 110 // drawn. This happens if any ancestor of a Layer is not visible. |
116 void SetVisible(bool visible); | 111 void SetVisible(bool visible); |
117 bool visible() const { return visible_; } | 112 bool visible() const { return visible_; } |
118 | 113 |
119 // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors | 114 // Returns true if this Layer is drawn. A Layer is drawn only if all ancestors |
120 // are visible. | 115 // are visible. |
121 bool IsDrawn() const; | 116 bool IsDrawn() const; |
122 | 117 |
123 // Returns true if this layer can have a texture (has_texture_ is true) | 118 // Returns true if this layer can have a texture (has_texture_ is true) |
124 // and is not completely obscured by a child. | 119 // and is not completely obscured by a child. |
125 bool ShouldDraw() const; | 120 bool ShouldDraw(); |
126 | 121 |
127 // Converts a point from the coordinates of |source| to the coordinates of | 122 // Converts a point from the coordinates of |source| to the coordinates of |
128 // |target|. Necessarily, |source| and |target| must inhabit the same Layer | 123 // |target|. Necessarily, |source| and |target| must inhabit the same Layer |
129 // tree. | 124 // tree. |
130 static void ConvertPointToLayer(const Layer* source, | 125 static void ConvertPointToLayer(const Layer* source, |
131 const Layer* target, | 126 const Layer* target, |
132 gfx::Point* point); | 127 gfx::Point* point); |
133 | 128 |
134 // See description in View for details | 129 // See description in View for details |
135 void SetFillsBoundsOpaquely(bool fills_bounds_opaquely); | 130 void SetFillsBoundsOpaquely(bool fills_bounds_opaquely); |
(...skipping 27 matching lines...) Expand all Loading... |
163 void Draw(); | 158 void Draw(); |
164 | 159 |
165 // Draws a tree of Layers, by calling Draw() on each in the hierarchy starting | 160 // Draws a tree of Layers, by calling Draw() on each in the hierarchy starting |
166 // with the receiver. | 161 // with the receiver. |
167 void DrawTree(); | 162 void DrawTree(); |
168 | 163 |
169 // Sometimes the Layer is being updated by something other than SetCanvas | 164 // Sometimes the Layer is being updated by something other than SetCanvas |
170 // (e.g. the GPU process on TOUCH_UI). | 165 // (e.g. the GPU process on TOUCH_UI). |
171 bool layer_updated_externally() const { return layer_updated_externally_; } | 166 bool layer_updated_externally() const { return layer_updated_externally_; } |
172 | 167 |
173 // WebLayerClient | |
174 virtual void notifyNeedsComposite(); | |
175 | |
176 // WebContentLayerClient | |
177 virtual void paintContents(WebKit::WebCanvas*, const WebKit::WebRect& clip); | |
178 | |
179 #if defined(USE_WEBKIT_COMPOSITOR) | |
180 WebKit::WebContentLayer web_layer() { return web_layer_; } | |
181 #endif | |
182 | |
183 private: | 168 private: |
184 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than | 169 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than |
185 // 1.0, we'll render to a separate texture, and then apply the alpha. | 170 // 1.0, we'll render to a separate texture, and then apply the alpha. |
186 // Currently, we multiply our opacity by all our ancestor's opacities and | 171 // Currently, we multiply our opacity by all our ancestor's opacities and |
187 // use the combined result, but this is only temporary. | 172 // use the combined result, but this is only temporary. |
188 float GetCombinedOpacity() const; | 173 float GetCombinedOpacity() const; |
189 | 174 |
190 // Called during the Draw() pass to freshen the Layer's contents from the | 175 // Called during the Draw() pass to freshen the Layer's contents from the |
191 // delegate. | 176 // delegate. |
192 void UpdateLayerCanvas(); | 177 void UpdateLayerCanvas(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
247 // update the values immediately. | 232 // update the values immediately. |
248 void SetBoundsImmediately(const gfx::Rect& bounds); | 233 void SetBoundsImmediately(const gfx::Rect& bounds); |
249 void SetTransformImmediately(const ui::Transform& transform); | 234 void SetTransformImmediately(const ui::Transform& transform); |
250 void SetOpacityImmediately(float opacity); | 235 void SetOpacityImmediately(float opacity); |
251 | 236 |
252 // LayerAnimatorDelegate overrides: | 237 // LayerAnimatorDelegate overrides: |
253 virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE; | 238 virtual void SetBoundsFromAnimator(const gfx::Rect& bounds) OVERRIDE; |
254 virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE; | 239 virtual void SetTransformFromAnimator(const Transform& transform) OVERRIDE; |
255 virtual void SetOpacityFromAnimator(float opacity) OVERRIDE; | 240 virtual void SetOpacityFromAnimator(float opacity) OVERRIDE; |
256 | 241 |
257 #if defined(USE_WEBKIT_COMPOSITOR) | |
258 void CreateWebLayer(); | |
259 void RecomputeTransform(); | |
260 void RecomputeDrawsContent(); | |
261 #endif | |
262 | |
263 const LayerType type_; | 242 const LayerType type_; |
264 | 243 |
265 Compositor* compositor_; | 244 Compositor* compositor_; |
266 | 245 |
267 scoped_refptr<ui::Texture> texture_; | 246 scoped_refptr<ui::Texture> texture_; |
268 | 247 |
269 Layer* parent_; | 248 Layer* parent_; |
270 | 249 |
271 std::vector<Layer*> children_; | 250 std::vector<Layer*> children_; |
272 | 251 |
(...skipping 12 matching lines...) Expand all Loading... |
285 | 264 |
286 // If true the layer is always up to date. | 265 // If true the layer is always up to date. |
287 bool layer_updated_externally_; | 266 bool layer_updated_externally_; |
288 | 267 |
289 float opacity_; | 268 float opacity_; |
290 | 269 |
291 LayerDelegate* delegate_; | 270 LayerDelegate* delegate_; |
292 | 271 |
293 scoped_ptr<LayerAnimator> animator_; | 272 scoped_ptr<LayerAnimator> animator_; |
294 | 273 |
295 #if defined(USE_WEBKIT_COMPOSITOR) | |
296 WebKit::WebContentLayer web_layer_; | |
297 #endif | |
298 | |
299 DISALLOW_COPY_AND_ASSIGN(Layer); | 274 DISALLOW_COPY_AND_ASSIGN(Layer); |
300 }; | 275 }; |
301 | 276 |
302 } // namespace ui | 277 } // namespace ui |
303 | 278 |
304 #endif // UI_GFX_COMPOSITOR_LAYER_H_ | 279 #endif // UI_GFX_COMPOSITOR_LAYER_H_ |
OLD | NEW |