Remove extra line from unit_tests.isolate
[chromium-blink-merge.git] / cc / CCLayerImpl.h
blob665b000d4bb8783e7a2a50eedb82d8fb3ff27c4d
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 "CCRenderPass.h"
11 #include "CCRenderSurface.h"
12 #include "CCResourceProvider.h"
13 #include "CCSharedQuadState.h"
14 #include "FloatRect.h"
15 #include "IntRect.h"
16 #include "Region.h"
17 #include "SkColor.h"
18 #include "cc/own_ptr_vector.h"
19 #include <public/WebFilterOperations.h>
20 #include <public/WebTransformationMatrix.h>
21 #include <string>
22 #include <wtf/OwnPtr.h>
23 #include <wtf/PassRefPtr.h>
24 #include <wtf/RefCounted.h>
26 namespace cc {
28 class CCLayerSorter;
29 class CCLayerTreeHostImpl;
30 class CCQuadSink;
31 class CCRenderer;
32 class CCScrollbarAnimationController;
33 class CCScrollbarLayerImpl;
34 class LayerChromium;
36 struct CCAppendQuadsData;
38 class CCLayerImpl : public CCLayerAnimationControllerClient {
39 public:
40 static PassOwnPtr<CCLayerImpl> create(int id)
42 return adoptPtr(new CCLayerImpl(id));
45 virtual ~CCLayerImpl();
47 // CCLayerAnimationControllerClient implementation.
48 virtual int id() const OVERRIDE;
49 virtual void setOpacityFromAnimation(float) OVERRIDE;
50 virtual float opacity() const OVERRIDE;
51 virtual void setTransformFromAnimation(const WebKit::WebTransformationMatrix&) OVERRIDE;
52 virtual const WebKit::WebTransformationMatrix& transform() const OVERRIDE;
54 // Tree structure.
55 CCLayerImpl* parent() const { return m_parent; }
56 const OwnPtrVector<CCLayerImpl>& children() const { return m_children; }
57 void addChild(PassOwnPtr<CCLayerImpl>);
58 void removeFromParent();
59 void removeAllChildren();
61 void setMaskLayer(PassOwnPtr<CCLayerImpl>);
62 CCLayerImpl* maskLayer() const { return m_maskLayer.get(); }
64 void setReplicaLayer(PassOwnPtr<CCLayerImpl>);
65 CCLayerImpl* replicaLayer() const { return m_replicaLayer.get(); }
67 bool hasMask() const { return m_maskLayer; }
68 bool hasReplica() const { return m_replicaLayer; }
69 bool replicaHasMask() const { return m_replicaLayer && (m_maskLayer || m_replicaLayer->m_maskLayer); }
71 CCLayerTreeHostImpl* layerTreeHostImpl() const { return m_layerTreeHostImpl; }
72 void setLayerTreeHostImpl(CCLayerTreeHostImpl* hostImpl) { m_layerTreeHostImpl = hostImpl; }
74 scoped_ptr<CCSharedQuadState> createSharedQuadState() const;
75 // willDraw must be called before appendQuads. If willDraw is called,
76 // didDraw is guaranteed to be called before another willDraw or before
77 // the layer is destroyed. To enforce this, any class that overrides
78 // willDraw/didDraw must call the base class version.
79 virtual void willDraw(CCResourceProvider*);
80 virtual void appendQuads(CCQuadSink&, CCAppendQuadsData&) { }
81 virtual void didDraw(CCResourceProvider*);
83 virtual CCResourceProvider::ResourceId contentsResourceId() const;
85 virtual bool hasContributingDelegatedRenderPasses() const;
86 virtual CCRenderPass::Id firstContributingRenderPassId() const;
87 virtual CCRenderPass::Id nextContributingRenderPassId(CCRenderPass::Id) const;
89 // Returns true if this layer has content to draw.
90 void setDrawsContent(bool);
91 bool drawsContent() const { return m_drawsContent; }
93 bool forceRenderSurface() const { return m_forceRenderSurface; }
94 void setForceRenderSurface(bool force) { m_forceRenderSurface = force; }
96 // Returns true if any of the layer's descendants has content to draw.
97 virtual bool descendantDrawsContent();
99 void setAnchorPoint(const FloatPoint&);
100 const FloatPoint& anchorPoint() const { return m_anchorPoint; }
102 void setAnchorPointZ(float);
103 float anchorPointZ() const { return m_anchorPointZ; }
105 void setBackgroundColor(SkColor);
106 SkColor backgroundColor() const { return m_backgroundColor; }
108 void setFilters(const WebKit::WebFilterOperations&);
109 const WebKit::WebFilterOperations& filters() const { return m_filters; }
111 void setBackgroundFilters(const WebKit::WebFilterOperations&);
112 const WebKit::WebFilterOperations& backgroundFilters() const { return m_backgroundFilters; }
114 void setMasksToBounds(bool);
115 bool masksToBounds() const { return m_masksToBounds; }
117 void setContentsOpaque(bool);
118 bool contentsOpaque() const { return m_contentsOpaque; }
120 void setOpacity(float);
121 bool opacityIsAnimating() const;
123 void setPosition(const FloatPoint&);
124 const FloatPoint& position() const { return m_position; }
126 void setIsContainerForFixedPositionLayers(bool isContainerForFixedPositionLayers) { m_isContainerForFixedPositionLayers = isContainerForFixedPositionLayers; }
127 bool isContainerForFixedPositionLayers() const { return m_isContainerForFixedPositionLayers; }
129 void setFixedToContainerLayer(bool fixedToContainerLayer = true) { m_fixedToContainerLayer = fixedToContainerLayer;}
130 bool fixedToContainerLayer() const { return m_fixedToContainerLayer; }
132 void setPreserves3D(bool);
133 bool preserves3D() const { return m_preserves3D; }
135 void setUseParentBackfaceVisibility(bool useParentBackfaceVisibility) { m_useParentBackfaceVisibility = useParentBackfaceVisibility; }
136 bool useParentBackfaceVisibility() const { return m_useParentBackfaceVisibility; }
138 void setUseLCDText(bool useLCDText) { m_useLCDText = useLCDText; }
139 bool useLCDText() const { return m_useLCDText; }
141 void setSublayerTransform(const WebKit::WebTransformationMatrix&);
142 const WebKit::WebTransformationMatrix& sublayerTransform() const { return m_sublayerTransform; }
144 // Debug layer border - visual effect only, do not change geometry/clipping/etc.
145 void setDebugBorderColor(SkColor);
146 SkColor debugBorderColor() const { return m_debugBorderColor; }
147 void setDebugBorderWidth(float);
148 float debugBorderWidth() const { return m_debugBorderWidth; }
149 bool hasDebugBorders() const;
151 // Debug layer name.
152 void setDebugName(const std::string& debugName) { m_debugName = debugName; }
153 std::string debugName() const { return m_debugName; }
155 CCRenderSurface* renderSurface() const { return m_renderSurface.get(); }
156 void createRenderSurface();
157 void clearRenderSurface() { m_renderSurface.clear(); }
159 float drawOpacity() const { return m_drawOpacity; }
160 void setDrawOpacity(float opacity) { m_drawOpacity = opacity; }
162 bool drawOpacityIsAnimating() const { return m_drawOpacityIsAnimating; }
163 void setDrawOpacityIsAnimating(bool drawOpacityIsAnimating) { m_drawOpacityIsAnimating = drawOpacityIsAnimating; }
165 CCLayerImpl* renderTarget() const { ASSERT(!m_renderTarget || m_renderTarget->renderSurface()); return m_renderTarget; }
166 void setRenderTarget(CCLayerImpl* target) { m_renderTarget = target; }
168 void setBounds(const IntSize&);
169 const IntSize& bounds() const { return m_bounds; }
171 const IntSize& contentBounds() const { return m_contentBounds; }
172 void setContentBounds(const IntSize&);
174 const IntPoint& scrollPosition() const { return m_scrollPosition; }
175 void setScrollPosition(const IntPoint&);
177 const IntSize& maxScrollPosition() const {return m_maxScrollPosition; }
178 void setMaxScrollPosition(const IntSize&);
180 const FloatSize& scrollDelta() const { return m_scrollDelta; }
181 void setScrollDelta(const FloatSize&);
183 const WebKit::WebTransformationMatrix& implTransform() const { return m_implTransform; }
184 void setImplTransform(const WebKit::WebTransformationMatrix& transform);
186 const IntSize& sentScrollDelta() const { return m_sentScrollDelta; }
187 void setSentScrollDelta(const IntSize& sentScrollDelta) { m_sentScrollDelta = sentScrollDelta; }
189 // Returns the delta of the scroll that was outside of the bounds of the initial scroll
190 FloatSize scrollBy(const FloatSize& scroll);
192 bool scrollable() const { return m_scrollable; }
193 void setScrollable(bool scrollable) { m_scrollable = scrollable; }
195 bool shouldScrollOnMainThread() const { return m_shouldScrollOnMainThread; }
196 void setShouldScrollOnMainThread(bool shouldScrollOnMainThread) { m_shouldScrollOnMainThread = shouldScrollOnMainThread; }
198 bool haveWheelEventHandlers() const { return m_haveWheelEventHandlers; }
199 void setHaveWheelEventHandlers(bool haveWheelEventHandlers) { m_haveWheelEventHandlers = haveWheelEventHandlers; }
201 const Region& nonFastScrollableRegion() const { return m_nonFastScrollableRegion; }
202 void setNonFastScrollableRegion(const Region& region) { m_nonFastScrollableRegion = region; }
204 void setDrawCheckerboardForMissingTiles(bool checkerboard) { m_drawCheckerboardForMissingTiles = checkerboard; }
205 bool drawCheckerboardForMissingTiles() const;
207 CCInputHandlerClient::ScrollStatus tryScroll(const IntPoint& viewportPoint, CCInputHandlerClient::ScrollInputType) const;
209 const IntRect& visibleContentRect() const { return m_visibleContentRect; }
210 void setVisibleContentRect(const IntRect& visibleContentRect) { m_visibleContentRect = visibleContentRect; }
212 bool doubleSided() const { return m_doubleSided; }
213 void setDoubleSided(bool);
215 void setTransform(const WebKit::WebTransformationMatrix&);
216 bool transformIsAnimating() const;
218 const WebKit::WebTransformationMatrix& drawTransform() const { return m_drawTransform; }
219 void setDrawTransform(const WebKit::WebTransformationMatrix& matrix) { m_drawTransform = matrix; }
220 const WebKit::WebTransformationMatrix& screenSpaceTransform() const { return m_screenSpaceTransform; }
221 void setScreenSpaceTransform(const WebKit::WebTransformationMatrix& matrix) { m_screenSpaceTransform = matrix; }
223 bool drawTransformIsAnimating() const { return m_drawTransformIsAnimating; }
224 void setDrawTransformIsAnimating(bool animating) { m_drawTransformIsAnimating = animating; }
225 bool screenSpaceTransformIsAnimating() const { return m_screenSpaceTransformIsAnimating; }
226 void setScreenSpaceTransformIsAnimating(bool animating) { m_screenSpaceTransformIsAnimating = animating; }
228 const IntRect& drawableContentRect() const { return m_drawableContentRect; }
229 void setDrawableContentRect(const IntRect& rect) { m_drawableContentRect = rect; }
230 const FloatRect& updateRect() const { return m_updateRect; }
231 void setUpdateRect(const FloatRect& updateRect) { m_updateRect = updateRect; }
233 std::string layerTreeAsText() const;
235 void setStackingOrderChanged(bool);
237 bool layerPropertyChanged() const { return m_layerPropertyChanged || layerIsAlwaysDamaged(); }
238 bool layerSurfacePropertyChanged() const;
240 void resetAllChangeTrackingForSubtree();
242 virtual bool layerIsAlwaysDamaged() const;
244 CCLayerAnimationController* layerAnimationController() { return m_layerAnimationController.get(); }
246 virtual Region visibleContentOpaqueRegion() const;
248 // Indicates that the context previously used to render this layer
249 // was lost and that a new one has been created. Won't be called
250 // until the new context has been created successfully.
251 virtual void didLoseContext();
253 CCScrollbarAnimationController* scrollbarAnimationController() const { return m_scrollbarAnimationController.get(); }
255 CCScrollbarLayerImpl* horizontalScrollbarLayer() const;
256 void setHorizontalScrollbarLayer(CCScrollbarLayerImpl*);
258 CCScrollbarLayerImpl* verticalScrollbarLayer() const;
259 void setVerticalScrollbarLayer(CCScrollbarLayerImpl*);
261 protected:
262 explicit CCLayerImpl(int);
264 void appendDebugBorderQuad(CCQuadSink&, const CCSharedQuadState*, CCAppendQuadsData&) const;
266 IntRect layerRectToContentRect(const WebKit::WebRect& layerRect);
268 virtual void dumpLayerProperties(std::string*, int indent) const;
269 static std::string indentString(int indent);
271 private:
272 void setParent(CCLayerImpl* parent) { m_parent = parent; }
273 friend class TreeSynchronizer;
274 void clearChildList(); // Warning: This does not preserve tree structure invariants and so is only exposed to the tree synchronizer.
276 void noteLayerPropertyChangedForSubtree();
278 // Note carefully this does not affect the current layer.
279 void noteLayerPropertyChangedForDescendants();
281 virtual const char* layerTypeAsString() const;
283 void dumpLayer(std::string*, int indent) const;
285 // Properties internal to CCLayerImpl
286 CCLayerImpl* m_parent;
287 OwnPtrVector<CCLayerImpl> m_children;
288 // m_maskLayer can be temporarily stolen during tree sync, we need this ID to confirm newly assigned layer is still the previous one
289 int m_maskLayerId;
290 OwnPtr<CCLayerImpl> m_maskLayer;
291 int m_replicaLayerId; // ditto
292 OwnPtr<CCLayerImpl> m_replicaLayer;
293 int m_layerId;
294 CCLayerTreeHostImpl* m_layerTreeHostImpl;
296 // Properties synchronized from the associated LayerChromium.
297 FloatPoint m_anchorPoint;
298 float m_anchorPointZ;
299 IntSize m_bounds;
300 IntSize m_contentBounds;
301 IntPoint m_scrollPosition;
302 bool m_scrollable;
303 bool m_shouldScrollOnMainThread;
304 bool m_haveWheelEventHandlers;
305 Region m_nonFastScrollableRegion;
306 SkColor m_backgroundColor;
308 // Whether the "back" of this layer should draw.
309 bool m_doubleSided;
311 // Tracks if drawing-related properties have changed since last redraw.
312 bool m_layerPropertyChanged;
314 // Indicates that a property has changed on this layer that would not
315 // affect the pixels on its target surface, but would require redrawing
316 // but would require redrawing the targetSurface onto its ancestor targetSurface.
317 // For layers that do not own a surface this flag acts as m_layerPropertyChanged.
318 bool m_layerSurfacePropertyChanged;
320 // Uses layer's content space.
321 IntRect m_visibleContentRect;
322 bool m_masksToBounds;
323 bool m_contentsOpaque;
324 float m_opacity;
325 FloatPoint m_position;
326 bool m_preserves3D;
327 bool m_useParentBackfaceVisibility;
328 bool m_drawCheckerboardForMissingTiles;
329 WebKit::WebTransformationMatrix m_sublayerTransform;
330 WebKit::WebTransformationMatrix m_transform;
331 bool m_useLCDText;
333 bool m_drawsContent;
334 bool m_forceRenderSurface;
336 // Set for the layer that other layers are fixed to.
337 bool m_isContainerForFixedPositionLayers;
338 // This is true if the layer should be fixed to the closest ancestor container.
339 bool m_fixedToContainerLayer;
341 FloatSize m_scrollDelta;
342 IntSize m_sentScrollDelta;
343 IntSize m_maxScrollPosition;
344 WebKit::WebTransformationMatrix m_implTransform;
346 // The layer whose coordinate space this layer draws into. This can be
347 // either the same layer (m_renderTarget == this) or an ancestor of this
348 // layer.
349 CCLayerImpl* m_renderTarget;
351 // The global depth value of the center of the layer. This value is used
352 // to sort layers from back to front.
353 float m_drawDepth;
354 float m_drawOpacity;
355 bool m_drawOpacityIsAnimating;
357 // Debug borders.
358 SkColor m_debugBorderColor;
359 float m_debugBorderWidth;
361 // Debug layer name.
362 std::string m_debugName;
364 WebKit::WebFilterOperations m_filters;
365 WebKit::WebFilterOperations m_backgroundFilters;
367 WebKit::WebTransformationMatrix m_drawTransform;
368 WebKit::WebTransformationMatrix m_screenSpaceTransform;
369 bool m_drawTransformIsAnimating;
370 bool m_screenSpaceTransformIsAnimating;
372 #ifndef NDEBUG
373 bool m_betweenWillDrawAndDidDraw;
374 #endif
376 // Render surface associated with this layer. The layer and its descendants
377 // will render to this surface.
378 OwnPtr<CCRenderSurface> m_renderSurface;
380 // Hierarchical bounding rect containing the layer and its descendants.
381 // Uses target surface's space.
382 IntRect m_drawableContentRect;
384 // Rect indicating what was repainted/updated during update.
385 // Note that plugin layers bypass this and leave it empty.
386 // Uses layer's content space.
387 FloatRect m_updateRect;
389 // Manages animations for this layer.
390 OwnPtr<CCLayerAnimationController> m_layerAnimationController;
392 // Manages scrollbars for this layer
393 OwnPtr<CCScrollbarAnimationController> m_scrollbarAnimationController;
396 void sortLayers(std::vector<CCLayerImpl*>::iterator first, std::vector<CCLayerImpl*>::iterator end, CCLayerSorter*);
400 #endif // CCLayerImpl_h