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