Chromium Code Reviews| 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 <string> | 9 #include <string> |
| 10 #include <vector> | 10 #include <vector> |
| 11 | 11 |
| 12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
| 13 #include "base/memory/ref_counted.h" | 13 #include "base/memory/ref_counted.h" |
| 14 #include "base/memory/scoped_ptr.h" | 14 #include "base/memory/scoped_ptr.h" |
| 15 #include "base/message_loop.h" | 15 #include "base/message_loop.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayer.h" | 17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayer.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayerClient .h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContentLayerClient .h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerClient.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebLayerClient.h" |
| 20 #include "ui/gfx/rect.h" | 20 #include "ui/gfx/rect.h" |
| 21 #include "ui/gfx/transform.h" | 21 #include "ui/gfx/transform.h" |
| 22 #include "ui/gfx/compositor/compositor.h" | 22 #include "ui/gfx/compositor/compositor.h" |
| 23 #include "ui/gfx/compositor/layer_animation_manager.h" | 23 #include "ui/gfx/compositor/layer_animation_manager.h" |
| 24 #include "ui/gfx/compositor/layer_animator_delegate.h" | 24 #include "ui/gfx/compositor/layer_animator_delegate.h" |
| 25 #include "ui/gfx/compositor/layer_delegate.h" | 25 #include "ui/gfx/compositor/layer_delegate.h" |
| 26 | 26 |
| 27 class SkCanvas; | 27 class SkCanvas; |
| 28 | 28 |
| 29 namespace { | |
|
sky
2011/10/25 21:44:09
Move this to the private section of Layer.
| |
| 30 | |
| 31 // contains info for a layer with respect to the root layer. | |
|
sky
2011/10/25 21:44:09
Contains
| |
| 32 struct LayerProperties { | |
| 33 public: | |
|
sky
2011/10/25 21:44:09
don't use a public section with structs.
| |
| 34 ui::Layer* layer; | |
| 35 ui::Transform transform_relative_to_root; | |
| 36 float combined_opacity; | |
| 37 | |
| 38 // Copy and assignment are allowed. | |
|
sky
2011/10/25 21:44:09
Remove this comment. Generally when we use structs
| |
| 39 }; | |
| 40 | |
| 41 } // namespace | |
| 42 | |
| 29 namespace ui { | 43 namespace ui { |
| 30 | 44 |
| 31 class Animation; | 45 class Animation; |
| 32 class Compositor; | 46 class Compositor; |
| 33 class Texture; | 47 class Texture; |
| 34 | 48 |
| 35 // Layer manages a texture, transform and a set of child Layers. Any View that | 49 // Layer manages a texture, transform and a set of child Layers. Any View that |
| 36 // has enabled layers ends up creating a Layer to manage the texture. | 50 // has enabled layers ends up creating a Layer to manage the texture. |
| 37 // A Layer can also be created without a texture, in which case it renders | 51 // A Layer can also be created without a texture, in which case it renders |
| 38 // nothing and is simply used as a node in a hierarchy of layers. | 52 // nothing and is simply used as a node in a hierarchy of layers. |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 194 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than | 208 // TODO(vollick): Eventually, if a non-leaf node has an opacity of less than |
| 195 // 1.0, we'll render to a separate texture, and then apply the alpha. | 209 // 1.0, we'll render to a separate texture, and then apply the alpha. |
| 196 // Currently, we multiply our opacity by all our ancestor's opacities and | 210 // Currently, we multiply our opacity by all our ancestor's opacities and |
| 197 // use the combined result, but this is only temporary. | 211 // use the combined result, but this is only temporary. |
| 198 float GetCombinedOpacity() const; | 212 float GetCombinedOpacity() const; |
| 199 | 213 |
| 200 // Called during the Draw() pass to freshen the Layer's contents from the | 214 // Called during the Draw() pass to freshen the Layer's contents from the |
| 201 // delegate. | 215 // delegate. |
| 202 void UpdateLayerCanvas(); | 216 void UpdateLayerCanvas(); |
| 203 | 217 |
| 218 // Called to indicate that a layer's properties have changed and that the | |
| 219 // holes for the layers must be recomputed. | |
| 220 void SetNeedsToRecomputeHole(); | |
| 221 | |
| 222 // Resets |hole_rect_| to the empty rect for all layers below and | |
| 223 // including this one. | |
| 224 void ClearHoleRects(); | |
| 225 | |
| 226 // Does a preorder traversal of layers starting with this layer. Omits layers | |
| 227 // which cannot punch a hole in another layer such as non visible layers | |
| 228 // and layers which don't fill their bounds opaquely. | |
| 229 void GeneratePreorderTraversal(std::vector<LayerProperties>* layer_traversal, | |
| 230 const ui::Transform& current_transform, float current_opacity); | |
|
sky
2011/10/25 21:44:09
When you wrap, you want each argument on its own l
| |
| 231 | |
| 204 // A hole in a layer is an area in the layer that does not get drawn | 232 // A hole in a layer is an area in the layer that does not get drawn |
| 205 // because this area is covered up with another layer which is known to be | 233 // because this area is covered up with another layer which is known to be |
| 206 // opaque. | 234 // opaque. |
| 207 // This method computes the dimension of the hole (if there is one) | 235 // This method computes the dimension of the hole (if there is one) |
| 208 // based on whether one of its child nodes is always opaque. | 236 // based on whether one of its child nodes is always opaque. |
| 209 // Note: For simplicity's sake, currently a hole is only created if the child | 237 // Note: This method should only be called from the root. |
| 210 // view has no transform with respect to its parent. | |
| 211 void RecomputeHole(); | 238 void RecomputeHole(); |
| 212 | 239 |
| 213 // Returns true if the layer paints every pixel (fills_bounds_opaquely) | 240 void set_hole_rect(const gfx::Rect& hole_rect) { |
| 214 // and the alpha of the layer is 1.0f. | 241 hole_rect_ = hole_rect; |
| 215 bool IsCompletelyOpaque() const; | 242 } |
| 216 | 243 |
| 217 // Determines the regions that don't intersect |rect| and places the | 244 // Determines the regions that don't intersect |rect| and places the |
| 218 // result in |sides|. | 245 // result in |sides|. |
| 219 // | 246 // |
| 220 // rect_____________________________ | 247 // rect_____________________________ |
| 221 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| | 248 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| |
| 222 // |xxxxxxxxxxxxx top xxxxxxxxxxxxxx| | 249 // |xxxxxxxxxxxxx top xxxxxxxxxxxxxx| |
| 223 // |________________________________| | 250 // |________________________________| |
| 224 // |xxxxx| |xxxxx| | 251 // |xxxxx| |xxxxx| |
| 225 // |xxxxx|region_to_punch_out |xxxxx| | 252 // |xxxxx|region_to_punch_out |xxxxx| |
| 226 // |left | |right| | 253 // |left | |right| |
| 227 // |_____|____________________|_____| | 254 // |_____|____________________|_____| |
| 228 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| | 255 // |xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx| |
| 229 // |xxxxxxxxxx bottom xxxxxxxxxxxxxx| | 256 // |xxxxxxxxxx bottom xxxxxxxxxxxxxx| |
| 230 // |________________________________| | 257 // |________________________________| |
| 231 static void PunchHole(const gfx::Rect& rect, | 258 static void PunchHole(const gfx::Rect& rect, |
| 232 const gfx::Rect& region_to_punch_out, | 259 const gfx::Rect& region_to_punch_out, |
| 233 std::vector<gfx::Rect>* sides); | 260 std::vector<gfx::Rect>* sides); |
| 234 | 261 |
| 262 // Drops texture just for this layer. | |
| 263 void DropTexture(); | |
| 264 | |
| 235 // Drop all textures for layers below and including this one. Called when | 265 // Drop all textures for layers below and including this one. Called when |
| 236 // the layer is removed from a hierarchy. Textures will be re-generated if | 266 // the layer is removed from a hierarchy. Textures will be re-generated if |
| 237 // the layer is subsequently re-attached and needs to be drawn. | 267 // the layer is subsequently re-attached and needs to be drawn. |
| 238 void DropTextures(); | 268 void DropTextures(); |
| 239 | 269 |
| 240 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; | 270 bool ConvertPointForAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 241 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; | 271 bool ConvertPointFromAncestor(const Layer* ancestor, gfx::Point* point) const; |
| 242 | 272 |
| 243 bool GetTransformRelativeTo(const Layer* ancestor, | 273 bool GetTransformRelativeTo(const Layer* ancestor, |
| 244 Transform* transform) const; | 274 Transform* transform) const; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 285 | 315 |
| 286 gfx::Rect bounds_; | 316 gfx::Rect bounds_; |
| 287 | 317 |
| 288 // Visibility of this layer. See SetVisible/IsDrawn for more details. | 318 // Visibility of this layer. See SetVisible/IsDrawn for more details. |
| 289 bool visible_; | 319 bool visible_; |
| 290 | 320 |
| 291 bool fills_bounds_opaquely_; | 321 bool fills_bounds_opaquely_; |
| 292 | 322 |
| 293 gfx::Rect hole_rect_; | 323 gfx::Rect hole_rect_; |
| 294 | 324 |
| 325 bool recompute_hole_; | |
| 326 | |
| 295 gfx::Rect invalid_rect_; | 327 gfx::Rect invalid_rect_; |
| 296 | 328 |
| 297 // If true the layer is always up to date. | 329 // If true the layer is always up to date. |
| 298 bool layer_updated_externally_; | 330 bool layer_updated_externally_; |
| 299 | 331 |
| 300 float opacity_; | 332 float opacity_; |
| 301 | 333 |
| 302 LayerDelegate* delegate_; | 334 LayerDelegate* delegate_; |
| 303 | 335 |
| 304 scoped_ptr<LayerAnimationManager> animator_; | 336 scoped_ptr<LayerAnimationManager> animator_; |
| 305 | 337 |
| 306 #if defined(USE_WEBKIT_COMPOSITOR) | 338 #if defined(USE_WEBKIT_COMPOSITOR) |
| 307 WebKit::WebContentLayer web_layer_; | 339 WebKit::WebContentLayer web_layer_; |
| 308 #endif | 340 #endif |
| 309 | 341 |
| 310 DISALLOW_COPY_AND_ASSIGN(Layer); | 342 DISALLOW_COPY_AND_ASSIGN(Layer); |
| 311 }; | 343 }; |
| 312 | 344 |
| 313 } // namespace ui | 345 } // namespace ui |
| 314 | 346 |
| 315 #endif // UI_GFX_COMPOSITOR_LAYER_H_ | 347 #endif // UI_GFX_COMPOSITOR_LAYER_H_ |
| OLD | NEW |