OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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 CC_LAYER_H_ | 5 #ifndef CC_LAYER_H_ |
6 #define CC_LAYER_H_ | 6 #define CC_LAYER_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
11 #include "base/memory/ref_counted.h" | 11 #include "base/memory/ref_counted.h" |
12 #include "base/observer_list.h" | 12 #include "base/observer_list.h" |
13 #include "cc/cc_export.h" | 13 #include "cc/cc_export.h" |
14 #include "cc/draw_properties.h" | 14 #include "cc/draw_properties.h" |
15 #include "cc/layer_animation_controller.h" | 15 #include "cc/layer_animation_controller.h" |
16 #include "cc/layer_animation_observer.h" | 16 #include "cc/layer_animation_event_observer.h" |
| 17 #include "cc/layer_animation_value_observer.h" |
17 #include "cc/occlusion_tracker.h" | 18 #include "cc/occlusion_tracker.h" |
18 #include "cc/region.h" | 19 #include "cc/region.h" |
19 #include "cc/render_surface.h" | 20 #include "cc/render_surface.h" |
20 #include "skia/ext/refptr.h" | 21 #include "skia/ext/refptr.h" |
21 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" | 22 #include "third_party/WebKit/Source/Platform/chromium/public/WebFilterOperations
.h" |
22 #include "third_party/skia/include/core/SkColor.h" | 23 #include "third_party/skia/include/core/SkColor.h" |
23 #include "third_party/skia/include/core/SkImageFilter.h" | 24 #include "third_party/skia/include/core/SkImageFilter.h" |
24 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
25 #include "ui/gfx/rect_f.h" | 26 #include "ui/gfx/rect_f.h" |
26 #include "ui/gfx/transform.h" | 27 #include "ui/gfx/transform.h" |
(...skipping 12 matching lines...) Expand all Loading... |
39 class LayerTreeHost; | 40 class LayerTreeHost; |
40 class LayerTreeImpl; | 41 class LayerTreeImpl; |
41 class PriorityCalculator; | 42 class PriorityCalculator; |
42 class ResourceUpdateQueue; | 43 class ResourceUpdateQueue; |
43 class ScrollbarLayer; | 44 class ScrollbarLayer; |
44 struct AnimationEvent; | 45 struct AnimationEvent; |
45 struct RenderingStats; | 46 struct RenderingStats; |
46 | 47 |
47 // Base class for composited layers. Special layer types are derived from | 48 // Base class for composited layers. Special layer types are derived from |
48 // this class. | 49 // this class. |
49 class CC_EXPORT Layer : public base::RefCounted<Layer>, public LayerAnimationCon
trollerClient { | 50 class CC_EXPORT Layer : public base::RefCounted<Layer>, |
| 51 public LayerAnimationValueObserver { |
50 public: | 52 public: |
51 typedef std::vector<scoped_refptr<Layer> > LayerList; | 53 typedef std::vector<scoped_refptr<Layer> > LayerList; |
52 | 54 |
53 static scoped_refptr<Layer> create(); | 55 static scoped_refptr<Layer> create(); |
54 | 56 |
55 // LayerAnimationControllerClient implementation | 57 int id() const; |
56 virtual int id() const OVERRIDE; | |
57 virtual void setOpacityFromAnimation(float) OVERRIDE; | |
58 virtual float opacity() const OVERRIDE; | |
59 virtual void setTransformFromAnimation(const gfx::Transform&) OVERRIDE; | |
60 // A layer's transform operates layer space. That is, entirely in logical, | |
61 // non-page-scaled pixels (that is, they have page zoom baked in, but not pa
ge scale). | |
62 // The root layer is a special case -- it operates in physical pixels. | |
63 virtual const gfx::Transform& transform() const OVERRIDE; | |
64 | 58 |
65 Layer* rootLayer(); | 59 Layer* rootLayer(); |
66 Layer* parent() { return m_parent; } | 60 Layer* parent() { return m_parent; } |
67 const Layer* parent() const { return m_parent; } | 61 const Layer* parent() const { return m_parent; } |
68 void addChild(scoped_refptr<Layer>); | 62 void addChild(scoped_refptr<Layer>); |
69 void insertChild(scoped_refptr<Layer>, size_t index); | 63 void insertChild(scoped_refptr<Layer>, size_t index); |
70 void replaceChild(Layer* reference, scoped_refptr<Layer> newLayer); | 64 void replaceChild(Layer* reference, scoped_refptr<Layer> newLayer); |
71 void removeFromParent(); | 65 void removeFromParent(); |
72 void removeAllChildren(); | 66 void removeAllChildren(); |
73 void setChildren(const LayerList&); | 67 void setChildren(const LayerList&); |
(...skipping 21 matching lines...) Expand all Loading... |
95 | 89 |
96 void setMaskLayer(Layer*); | 90 void setMaskLayer(Layer*); |
97 Layer* maskLayer() { return m_maskLayer.get(); } | 91 Layer* maskLayer() { return m_maskLayer.get(); } |
98 const Layer* maskLayer() const { return m_maskLayer.get(); } | 92 const Layer* maskLayer() const { return m_maskLayer.get(); } |
99 | 93 |
100 virtual void setNeedsDisplayRect(const gfx::RectF& dirtyRect); | 94 virtual void setNeedsDisplayRect(const gfx::RectF& dirtyRect); |
101 void setNeedsDisplay() { setNeedsDisplayRect(gfx::RectF(gfx::PointF(), bound
s())); } | 95 void setNeedsDisplay() { setNeedsDisplayRect(gfx::RectF(gfx::PointF(), bound
s())); } |
102 virtual bool needsDisplay() const; | 96 virtual bool needsDisplay() const; |
103 | 97 |
104 void setOpacity(float); | 98 void setOpacity(float); |
| 99 float opacity() const; |
105 bool opacityIsAnimating() const; | 100 bool opacityIsAnimating() const; |
106 | 101 |
107 void setFilters(const WebKit::WebFilterOperations&); | 102 void setFilters(const WebKit::WebFilterOperations&); |
108 const WebKit::WebFilterOperations& filters() const { return m_filters; } | 103 const WebKit::WebFilterOperations& filters() const { return m_filters; } |
109 | 104 |
110 void setFilter(const skia::RefPtr<SkImageFilter>& filter); | 105 void setFilter(const skia::RefPtr<SkImageFilter>& filter); |
111 skia::RefPtr<SkImageFilter> filter() const { return m_filter; } | 106 skia::RefPtr<SkImageFilter> filter() const { return m_filter; } |
112 | 107 |
113 // Background filters are filters applied to what is behind this layer, when
they are viewed through non-opaque | 108 // Background filters are filters applied to what is behind this layer, when
they are viewed through non-opaque |
114 // regions in this layer. They are used through the WebLayer interface, and
are not exposed to HTML. | 109 // regions in this layer. They are used through the WebLayer interface, and
are not exposed to HTML. |
115 void setBackgroundFilters(const WebKit::WebFilterOperations&); | 110 void setBackgroundFilters(const WebKit::WebFilterOperations&); |
116 const WebKit::WebFilterOperations& backgroundFilters() const { return m_back
groundFilters; } | 111 const WebKit::WebFilterOperations& backgroundFilters() const { return m_back
groundFilters; } |
117 | 112 |
118 virtual void setContentsOpaque(bool); | 113 virtual void setContentsOpaque(bool); |
119 bool contentsOpaque() const { return m_contentsOpaque; } | 114 bool contentsOpaque() const { return m_contentsOpaque; } |
120 | 115 |
121 void setPosition(const gfx::PointF&); | 116 void setPosition(const gfx::PointF&); |
122 gfx::PointF position() const { return m_position; } | 117 gfx::PointF position() const { return m_position; } |
123 | 118 |
124 void setIsContainerForFixedPositionLayers(bool); | 119 void setIsContainerForFixedPositionLayers(bool); |
125 bool isContainerForFixedPositionLayers() const { return m_isContainerForFixe
dPositionLayers; } | 120 bool isContainerForFixedPositionLayers() const { return m_isContainerForFixe
dPositionLayers; } |
126 | 121 |
127 void setFixedToContainerLayer(bool); | 122 void setFixedToContainerLayer(bool); |
128 bool fixedToContainerLayer() const { return m_fixedToContainerLayer; } | 123 bool fixedToContainerLayer() const { return m_fixedToContainerLayer; } |
129 | 124 |
130 void setSublayerTransform(const gfx::Transform&); | 125 void setSublayerTransform(const gfx::Transform&); |
131 const gfx::Transform& sublayerTransform() const { return m_sublayerTransform
; } | 126 const gfx::Transform& sublayerTransform() const { return m_sublayerTransform
; } |
132 | 127 |
133 void setTransform(const gfx::Transform&); | 128 void setTransform(const gfx::Transform&); |
| 129 const gfx::Transform& transform() const; |
134 bool transformIsAnimating() const; | 130 bool transformIsAnimating() const; |
135 | 131 |
136 DrawProperties<Layer, RenderSurface>& drawProperties() { return m_drawProper
ties; } | 132 DrawProperties<Layer, RenderSurface>& drawProperties() { return m_drawProper
ties; } |
137 const DrawProperties<Layer, RenderSurface>& drawProperties() const { return
m_drawProperties; } | 133 const DrawProperties<Layer, RenderSurface>& drawProperties() const { return
m_drawProperties; } |
138 | 134 |
139 // The following are shortcut accessors to get various information from m_dr
awProperties | 135 // The following are shortcut accessors to get various information from m_dr
awProperties |
140 const gfx::Transform& drawTransform() const { return m_drawProperties.target
_space_transform; } | 136 const gfx::Transform& drawTransform() const { return m_drawProperties.target
_space_transform; } |
141 const gfx::Transform& screenSpaceTransform() const { return m_drawProperties
.screen_space_transform; } | 137 const gfx::Transform& screenSpaceTransform() const { return m_drawProperties
.screen_space_transform; } |
142 float drawOpacity() const { return m_drawProperties.opacity; } | 138 float drawOpacity() const { return m_drawProperties.opacity; } |
143 bool drawOpacityIsAnimating() const { return m_drawProperties.opacity_is_ani
mating; } | 139 bool drawOpacityIsAnimating() const { return m_drawProperties.opacity_is_ani
mating; } |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
262 virtual void setTexturePriorities(const PriorityCalculator&) { } | 258 virtual void setTexturePriorities(const PriorityCalculator&) { } |
263 | 259 |
264 bool addAnimation(scoped_ptr<ActiveAnimation>); | 260 bool addAnimation(scoped_ptr<ActiveAnimation>); |
265 void pauseAnimation(int animationId, double timeOffset); | 261 void pauseAnimation(int animationId, double timeOffset); |
266 void removeAnimation(int animationId); | 262 void removeAnimation(int animationId); |
267 | 263 |
268 void suspendAnimations(double monotonicTime); | 264 void suspendAnimations(double monotonicTime); |
269 void resumeAnimations(double monotonicTime); | 265 void resumeAnimations(double monotonicTime); |
270 | 266 |
271 LayerAnimationController* layerAnimationController() { return m_layerAnimati
onController.get(); } | 267 LayerAnimationController* layerAnimationController() { return m_layerAnimati
onController.get(); } |
272 void setLayerAnimationController(scoped_ptr<LayerAnimationController>); | 268 void setLayerAnimationController(scoped_refptr<LayerAnimationController>); |
273 scoped_ptr<LayerAnimationController> releaseLayerAnimationController(); | 269 scoped_refptr<LayerAnimationController> releaseLayerAnimationController(); |
274 | 270 |
275 void setLayerAnimationDelegate(WebKit::WebAnimationDelegate* layerAnimationD
elegate) { m_layerAnimationDelegate = layerAnimationDelegate; } | 271 void setLayerAnimationDelegate(WebKit::WebAnimationDelegate* layerAnimationD
elegate) { m_layerAnimationDelegate = layerAnimationDelegate; } |
276 | 272 |
277 bool hasActiveAnimation() const; | 273 bool hasActiveAnimation() const; |
278 | 274 |
279 virtual void notifyAnimationStarted(const AnimationEvent&, double wallClockT
ime); | 275 virtual void notifyAnimationStarted(const AnimationEvent&, double wallClockT
ime); |
280 virtual void notifyAnimationFinished(double wallClockTime); | 276 virtual void notifyAnimationFinished(double wallClockTime); |
281 | 277 |
282 void addLayerAnimationObserver(LayerAnimationObserver* animationObserver); | 278 void addLayerAnimationEventObserver(LayerAnimationEventObserver* animationOb
server); |
283 void removeLayerAnimationObserver(LayerAnimationObserver* animationObserver)
; | 279 void removeLayerAnimationEventObserver(LayerAnimationEventObserver* animatio
nObserver); |
284 | 280 |
285 virtual Region visibleContentOpaqueRegion() const; | 281 virtual Region visibleContentOpaqueRegion() const; |
286 | 282 |
287 virtual ScrollbarLayer* toScrollbarLayer(); | 283 virtual ScrollbarLayer* toScrollbarLayer(); |
288 | 284 |
289 gfx::Rect layerRectToContentRect(const gfx::RectF& layerRect) const; | 285 gfx::Rect layerRectToContentRect(const gfx::RectF& layerRect) const; |
290 | 286 |
291 // In impl-side painting, this returns true if this layer type is not | 287 // In impl-side painting, this returns true if this layer type is not |
292 // compatible with the main thread running freely, such as a double-buffered | 288 // compatible with the main thread running freely, such as a double-buffered |
293 // canvas that doesn't want to be triple-buffered across all three trees. | 289 // canvas that doesn't want to be triple-buffered across all three trees. |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 bool descendantIsFixedToContainerLayer() const; | 325 bool descendantIsFixedToContainerLayer() const; |
330 | 326 |
331 size_t numChildren() const { return m_children.size(); } | 327 size_t numChildren() const { return m_children.size(); } |
332 | 328 |
333 // Returns the index of the child or -1 if not found. | 329 // Returns the index of the child or -1 if not found. |
334 int indexOfChild(const Layer*); | 330 int indexOfChild(const Layer*); |
335 | 331 |
336 // This should only be called from removeFromParent. | 332 // This should only be called from removeFromParent. |
337 void removeChild(Layer*); | 333 void removeChild(Layer*); |
338 | 334 |
| 335 // LayerAnimationValueObserver implementation. |
| 336 virtual void OnOpacityAnimated(float) OVERRIDE; |
| 337 virtual void OnTransformAnimated(const gfx::Transform&) OVERRIDE; |
| 338 |
339 LayerList m_children; | 339 LayerList m_children; |
340 Layer* m_parent; | 340 Layer* m_parent; |
341 | 341 |
342 // Layer instances have a weak pointer to their LayerTreeHost. | 342 // Layer instances have a weak pointer to their LayerTreeHost. |
343 // This pointer value is nil when a Layer is not in a tree and is | 343 // This pointer value is nil when a Layer is not in a tree and is |
344 // updated via setLayerTreeHost() if a layer moves between trees. | 344 // updated via setLayerTreeHost() if a layer moves between trees. |
345 LayerTreeHost* m_layerTreeHost; | 345 LayerTreeHost* m_layerTreeHost; |
346 | 346 |
347 scoped_ptr<LayerAnimationController> m_layerAnimationController; | 347 ObserverList<LayerAnimationEventObserver> m_layerAnimationObservers; |
348 ObserverList<LayerAnimationObserver> m_layerAnimationObservers; | 348 |
| 349 scoped_refptr<LayerAnimationController> m_layerAnimationController; |
349 | 350 |
350 // Layer properties. | 351 // Layer properties. |
351 gfx::Size m_bounds; | 352 gfx::Size m_bounds; |
352 | 353 |
353 gfx::Vector2d m_scrollOffset; | 354 gfx::Vector2d m_scrollOffset; |
354 gfx::Vector2d m_maxScrollOffset; | 355 gfx::Vector2d m_maxScrollOffset; |
355 bool m_scrollable; | 356 bool m_scrollable; |
356 bool m_shouldScrollOnMainThread; | 357 bool m_shouldScrollOnMainThread; |
357 bool m_haveWheelEventHandlers; | 358 bool m_haveWheelEventHandlers; |
358 Region m_nonFastScrollableRegion; | 359 Region m_nonFastScrollableRegion; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 WebKit::WebLayerScrollClient* m_layerScrollClient; | 397 WebKit::WebLayerScrollClient* m_layerScrollClient; |
397 | 398 |
398 DrawProperties<Layer, RenderSurface> m_drawProperties; | 399 DrawProperties<Layer, RenderSurface> m_drawProperties; |
399 }; | 400 }; |
400 | 401 |
401 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped
_refptr<Layer> >::iterator, void*); | 402 void sortLayers(std::vector<scoped_refptr<Layer> >::iterator, std::vector<scoped
_refptr<Layer> >::iterator, void*); |
402 | 403 |
403 } // namespace cc | 404 } // namespace cc |
404 | 405 |
405 #endif // CC_LAYER_H_ | 406 #endif // CC_LAYER_H_ |
OLD | NEW |