Experimental push messaging api reference docs.
[chromium-blink-merge.git] / cc / CCLayerImpl.h
blob3509ffd694b1ff4792292b102dac47b8dcf8f317
1 // Copyright 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CCLayerImpl_h
6 #define CCLayerImpl_h
8 #include "CCInputHandler.h"
9 #include "CCLayerAnimationController.h"
10 #include "CCRenderSurface.h"
11 #include "CCResourceProvider.h"
12 #include "CCSharedQuadState.h"
13 #include "FloatRect.h"
14 #include "IntRect.h"
15 #include "Region.h"
16 #include "SkColor.h"
17 #include <public/WebFilterOperations.h>
18 #include <public/WebTransformationMatrix.h>
19 #include <string>
20 #include <wtf/OwnPtr.h>
21 #include <wtf/PassRefPtr.h>
22 #include <wtf/RefCounted.h>
24 namespace cc {
26 class CCLayerSorter;
27 class CCLayerTreeHostImpl;
28 class CCQuadSink;
29 class CCRenderer;
30 class CCScrollbarAnimationController;
31 class CCScrollbarLayerImpl;
32 class LayerChromium;
34 struct CCAppendQuadsData;
36 class CCLayerImpl : public CCLayerAnimationControllerClient {
37 public:
38 static PassOwnPtr<CCLayerImpl> create(int id)
40 return adoptPtr(new CCLayerImpl(id));
43 virtual ~CCLayerImpl();
45 // CCLayerAnimationControllerClient implementation.
46 virtual int id() const OVERRIDE { return m_layerId; }
47 virtual void setOpacityFromAnimation(float) OVERRIDE;
48 virtual float opacity() const OVERRIDE { return m_opacity; }
49 virtual void setTransformFromAnimation(const WebKit::WebTransformationMatrix&) OVERRIDE;
50 virtual const WebKit::WebTransformationMatrix& transform() const OVERRIDE { return m_transform; }
52 // Tree structure.
53 CCLayerImpl* parent() const { return m_parent; }
54 const Vector<OwnPtr<CCLayerImpl> >& children() const { return m_children; }
55 void addChild(PassOwnPtr<CCLayerImpl>);
56 void removeFromParent();
57 void removeAllChildren();
59 void setMaskLayer(PassOwnPtr<CCLayerImpl>);
60 CCLayerImpl* maskLayer() const { return m_maskLayer.get(); }
62 void setReplicaLayer(PassOwnPtr<CCLayerImpl>);
63 CCLayerImpl* replicaLayer() const { return m_replicaLayer.get(); }
65 bool hasMask() const { return m_maskLayer; }
66 bool hasReplica() const { return m_replicaLayer; }
67 bool replicaHasMask() const { return m_replicaLayer && (m_maskLayer || m_replicaLayer->m_maskLayer); }
69 CCLayerTreeHostImpl* layerTreeHostImpl() const { return m_layerTreeHostImpl; }
70 void setLayerTreeHostImpl(CCLayerTreeHostImpl* hostImpl) { m_layerTreeHostImpl = hostImpl; }
72 PassOwnPtr<CCSharedQuadState> createSharedQuadState() const;
73 // willDraw must be called before appendQuads. If willDraw is called,
74 // didDraw is guaranteed to be called before another willDraw or before
75 // the layer is destroyed. To enforce this, any class that overrides
76 // willDraw/didDraw must call the base class version.
77 virtual void willDraw(CCResourceProvider*);
78 virtual void appendQuads(CCQuadSink&, CCAppendQuadsData&) { }
79 virtual void didDraw(CCResourceProvider*);
81 virtual CCResourceProvider::ResourceId contentsResourceId() const;
83 // Returns true if this layer has content to draw.
84 void setDrawsContent(bool);
85 bool drawsContent() const { return m_drawsContent; }
87 bool forceRenderSurface() const { return m_forceRenderSurface; }
88 void setForceRenderSurface(bool force) { m_forceRenderSurface = force; }
90 // Returns true if any of the layer's descendants has content to draw.
91 bool descendantDrawsContent();
93 void setAnchorPoint(const FloatPoint&);
94 const FloatPoint& anchorPoint() const { return m_anchorPoint; }
96 void setAnchorPointZ(float);
97 float anchorPointZ() const { return m_anchorPointZ; }
99 void setBackgroundColor(SkColor);
100 SkColor backgroundColor() const { return m_backgroundColor; }
102 void setFilters(const WebKit::WebFilterOperations&);
103 const WebKit::WebFilterOperations& filters() const { return m_filters; }
105 void setBackgroundFilters(const WebKit::WebFilterOperations&);
106 const WebKit::WebFilterOperations& backgroundFilters() const { return m_backgroundFilters; }
108 void setMasksToBounds(bool);
109 bool masksToBounds() const { return m_masksToBounds; }
111 void setOpaque(bool);
112 bool opaque() const { return m_opaque; }
114 void setOpacity(float);
115 bool opacityIsAnimating() const;
117 void setPosition(const FloatPoint&);
118 const FloatPoint& position() const { return m_position; }
120 void setIsContainerForFixedPositionLayers(bool isContainerForFixedPositionLayers) { m_isContainerForFixedPositionLayers = isContainerForFixedPositionLayers; }
121 bool isContainerForFixedPositionLayers() const { return m_isContainerForFixedPositionLayers; }
123 void setFixedToContainerLayer(bool fixedToContainerLayer = true) { m_fixedToContainerLayer = fixedToContainerLayer;}
124 bool fixedToContainerLayer() const { return m_fixedToContainerLayer; }
126 void setPreserves3D(bool);
127 bool preserves3D() const { return m_preserves3D; }
129 void setUseParentBackfaceVisibility(bool useParentBackfaceVisibility) { m_useParentBackfaceVisibility = useParentBackfaceVisibility; }
130 bool useParentBackfaceVisibility() const { return m_useParentBackfaceVisibility; }
132 void setUseLCDText(bool useLCDText) { m_useLCDText = useLCDText; }
133 bool useLCDText() const { return m_useLCDText; }
135 void setSublayerTransform(const WebKit::WebTransformationMatrix&);
136 const WebKit::WebTransformationMatrix& sublayerTransform() const { return m_sublayerTransform; }
138 // Debug layer border - visual effect only, do not change geometry/clipping/etc.
139 void setDebugBorderColor(SkColor);
140 SkColor debugBorderColor() const { return m_debugBorderColor; }
141 void setDebugBorderWidth(float);
142 float debugBorderWidth() const { return m_debugBorderWidth; }
143 bool hasDebugBorders() const;
145 // Debug layer name.
146 void setDebugName(const std::string& debugName) { m_debugName = debugName; }
147 std::string debugName() const { return m_debugName; }
149 CCRenderSurface* renderSurface() const { return m_renderSurface.get(); }
150 void createRenderSurface();
151 void clearRenderSurface() { m_renderSurface.clear(); }
153 float drawOpacity() const { return m_drawOpacity; }
154 void setDrawOpacity(float opacity) { m_drawOpacity = opacity; }
156 bool drawOpacityIsAnimating() const { return m_drawOpacityIsAnimating; }
157 void setDrawOpacityIsAnimating(bool drawOpacityIsAnimating) { m_drawOpacityIsAnimating = drawOpacityIsAnimating; }
159 CCLayerImpl* renderTarget() const { ASSERT(!m_renderTarget || m_renderTarget->renderSurface()); return m_renderTarget; }
160 void setRenderTarget(CCLayerImpl* target) { m_renderTarget = target; }
162 void setBounds(const IntSize&);
163 const IntSize& bounds() const { return m_bounds; }
165 const IntSize& contentBounds() const { return m_contentBounds; }
166 void setContentBounds(const IntSize&);
168 const IntPoint& scrollPosition() const { return m_scrollPosition; }
169 void setScrollPosition(const IntPoint&);
171 const IntSize& maxScrollPosition() const {return m_maxScrollPosition; }
172 void setMaxScrollPosition(const IntSize&);
174 const FloatSize& scrollDelta() const { return m_scrollDelta; }
175 void setScrollDelta(const FloatSize&);
177 float pageScaleDelta() const { return m_pageScaleDelta; }
178 void setPageScaleDelta(float);
180 const IntSize& sentScrollDelta() const { return m_sentScrollDelta; }
181 void setSentScrollDelta(const IntSize& sentScrollDelta) { m_sentScrollDelta = sentScrollDelta; }
183 void scrollBy(const FloatSize& scroll);
185 bool scrollable() const { return m_scrollable; }
186 void setScrollable(bool scrollable) { m_scrollable = scrollable; }
188 bool shouldScrollOnMainThread() const { return m_shouldScrollOnMainThread; }
189 void setShouldScrollOnMainThread(bool shouldScrollOnMainThread) { m_shouldScrollOnMainThread = shouldScrollOnMainThread; }
191 bool haveWheelEventHandlers() const { return m_haveWheelEventHandlers; }
192 void setHaveWheelEventHandlers(bool haveWheelEventHandlers) { m_haveWheelEventHandlers = haveWheelEventHandlers; }
194 const Region& nonFastScrollableRegion() const { return m_nonFastScrollableRegion; }
195 void setNonFastScrollableRegion(const Region& region) { m_nonFastScrollableRegion = region; }
197 void setDrawCheckerboardForMissingTiles(bool checkerboard) { m_drawCheckerboardForMissingTiles = checkerboard; }
198 bool drawCheckerboardForMissingTiles() const { return m_drawCheckerboardForMissingTiles; }
200 CCInputHandlerClient::ScrollStatus tryScroll(const IntPoint& viewportPoint, CCInputHandlerClient::ScrollInputType) const;
202 const IntRect& visibleContentRect() const { return m_visibleContentRect; }
203 void setVisibleContentRect(const IntRect& visibleContentRect) { m_visibleContentRect = visibleContentRect; }
205 bool doubleSided() const { return m_doubleSided; }
206 void setDoubleSided(bool);
208 void setTransform(const WebKit::WebTransformationMatrix&);
209 bool transformIsAnimating() const;
211 const WebKit::WebTransformationMatrix& drawTransform() const { return m_drawTransform; }
212 void setDrawTransform(const WebKit::WebTransformationMatrix& matrix) { m_drawTransform = matrix; }
213 const WebKit::WebTransformationMatrix& screenSpaceTransform() const { return m_screenSpaceTransform; }
214 void setScreenSpaceTransform(const WebKit::WebTransformationMatrix& matrix) { m_screenSpaceTransform = matrix; }
216 bool drawTransformIsAnimating() const { return m_drawTransformIsAnimating; }
217 void setDrawTransformIsAnimating(bool animating) { m_drawTransformIsAnimating = animating; }
218 bool screenSpaceTransformIsAnimating() const { return m_screenSpaceTransformIsAnimating; }
219 void setScreenSpaceTransformIsAnimating(bool animating) { m_screenSpaceTransformIsAnimating = animating; }
221 const IntRect& drawableContentRect() const { return m_drawableContentRect; }
222 void setDrawableContentRect(const IntRect& rect) { m_drawableContentRect = rect; }
223 const FloatRect& updateRect() const { return m_updateRect; }
224 void setUpdateRect(const FloatRect& updateRect) { m_updateRect = updateRect; }
226 std::string layerTreeAsText() const;
228 void setStackingOrderChanged(bool);
230 bool layerPropertyChanged() const { return m_layerPropertyChanged || layerIsAlwaysDamaged(); }
231 bool layerSurfacePropertyChanged() const;
233 void resetAllChangeTrackingForSubtree();
235 virtual bool layerIsAlwaysDamaged() const { return false; }
237 CCLayerAnimationController* layerAnimationController() { return m_layerAnimationController.get(); }
239 virtual Region visibleContentOpaqueRegion() const;
241 // Indicates that the context previously used to render this layer
242 // was lost and that a new one has been created. Won't be called
243 // until the new context has been created successfully.
244 virtual void didLoseContext();
246 CCScrollbarAnimationController* scrollbarAnimationController() const { return m_scrollbarAnimationController.get(); }
248 CCScrollbarLayerImpl* horizontalScrollbarLayer() const;
249 void setHorizontalScrollbarLayer(CCScrollbarLayerImpl*);
251 CCScrollbarLayerImpl* verticalScrollbarLayer() const;
252 void setVerticalScrollbarLayer(CCScrollbarLayerImpl*);
254 protected:
255 explicit CCLayerImpl(int);
257 void appendDebugBorderQuad(CCQuadSink&, const CCSharedQuadState*, CCAppendQuadsData&) const;
259 virtual void dumpLayerProperties(std::string*, int indent) const;
260 static std::string indentString(int indent);
262 private:
263 void setParent(CCLayerImpl* parent) { m_parent = parent; }
264 friend class TreeSynchronizer;
265 void clearChildList(); // Warning: This does not preserve tree structure invariants and so is only exposed to the tree synchronizer.
267 void noteLayerPropertyChangedForSubtree();
269 // Note carefully this does not affect the current layer.
270 void noteLayerPropertyChangedForDescendants();
272 virtual const char* layerTypeAsString() const { return "LayerChromium"; }
274 void dumpLayer(std::string*, int indent) const;
276 // Properties internal to CCLayerImpl
277 CCLayerImpl* m_parent;
278 Vector<OwnPtr<CCLayerImpl> > m_children;
279 // m_maskLayer can be temporarily stolen during tree sync, we need this ID to confirm newly assigned layer is still the previous one
280 int m_maskLayerId;
281 OwnPtr<CCLayerImpl> m_maskLayer;
282 int m_replicaLayerId; // ditto
283 OwnPtr<CCLayerImpl> m_replicaLayer;
284 int m_layerId;
285 CCLayerTreeHostImpl* m_layerTreeHostImpl;
287 // Properties synchronized from the associated LayerChromium.
288 FloatPoint m_anchorPoint;
289 float m_anchorPointZ;
290 IntSize m_bounds;
291 IntSize m_contentBounds;
292 IntPoint m_scrollPosition;
293 bool m_scrollable;
294 bool m_shouldScrollOnMainThread;
295 bool m_haveWheelEventHandlers;
296 Region m_nonFastScrollableRegion;
297 SkColor m_backgroundColor;
299 // Whether the "back" of this layer should draw.
300 bool m_doubleSided;
302 // Tracks if drawing-related properties have changed since last redraw.
303 bool m_layerPropertyChanged;
305 // Indicates that a property has changed on this layer that would not
306 // affect the pixels on its target surface, but would require redrawing
307 // but would require redrawing the targetSurface onto its ancestor targetSurface.
308 // For layers that do not own a surface this flag acts as m_layerPropertyChanged.
309 bool m_layerSurfacePropertyChanged;
311 // Uses layer's content space.
312 IntRect m_visibleContentRect;
313 bool m_masksToBounds;
314 bool m_opaque;
315 float m_opacity;
316 FloatPoint m_position;
317 bool m_preserves3D;
318 bool m_useParentBackfaceVisibility;
319 bool m_drawCheckerboardForMissingTiles;
320 WebKit::WebTransformationMatrix m_sublayerTransform;
321 WebKit::WebTransformationMatrix m_transform;
322 bool m_useLCDText;
324 bool m_drawsContent;
325 bool m_forceRenderSurface;
327 // Set for the layer that other layers are fixed to.
328 bool m_isContainerForFixedPositionLayers;
329 // This is true if the layer should be fixed to the closest ancestor container.
330 bool m_fixedToContainerLayer;
332 FloatSize m_scrollDelta;
333 IntSize m_sentScrollDelta;
334 IntSize m_maxScrollPosition;
335 float m_pageScaleDelta;
337 // The layer whose coordinate space this layer draws into. This can be
338 // either the same layer (m_renderTarget == this) or an ancestor of this
339 // layer.
340 CCLayerImpl* m_renderTarget;
342 // The global depth value of the center of the layer. This value is used
343 // to sort layers from back to front.
344 float m_drawDepth;
345 float m_drawOpacity;
346 bool m_drawOpacityIsAnimating;
348 // Debug borders.
349 SkColor m_debugBorderColor;
350 float m_debugBorderWidth;
352 // Debug layer name.
353 std::string m_debugName;
355 WebKit::WebFilterOperations m_filters;
356 WebKit::WebFilterOperations m_backgroundFilters;
358 WebKit::WebTransformationMatrix m_drawTransform;
359 WebKit::WebTransformationMatrix m_screenSpaceTransform;
360 bool m_drawTransformIsAnimating;
361 bool m_screenSpaceTransformIsAnimating;
363 #ifndef NDEBUG
364 bool m_betweenWillDrawAndDidDraw;
365 #endif
367 // Render surface associated with this layer. The layer and its descendants
368 // will render to this surface.
369 OwnPtr<CCRenderSurface> m_renderSurface;
371 // Hierarchical bounding rect containing the layer and its descendants.
372 // Uses target surface's space.
373 IntRect m_drawableContentRect;
375 // Rect indicating what was repainted/updated during update.
376 // Note that plugin layers bypass this and leave it empty.
377 // Uses layer's content space.
378 FloatRect m_updateRect;
380 // Manages animations for this layer.
381 OwnPtr<CCLayerAnimationController> m_layerAnimationController;
383 // Manages scrollbars for this layer
384 OwnPtr<CCScrollbarAnimationController> m_scrollbarAnimationController;
387 void sortLayers(Vector<CCLayerImpl*>::iterator first, Vector<CCLayerImpl*>::iterator end, CCLayerSorter*);
391 #endif // CCLayerImpl_h