OLD | NEW |
1 // Copyright 2011 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 CCLayerImpl_h | 5 // Temporary forwarding header |
6 #define CCLayerImpl_h | 6 #include "cc/layer_impl.h" |
7 | |
8 #include "base/memory/scoped_ptr.h" | |
9 #include "cc/scoped_ptr_vector.h" | |
10 #include "CCInputHandler.h" | |
11 #include "CCLayerAnimationController.h" | |
12 #include "CCRenderPass.h" | |
13 #include "CCRenderSurface.h" | |
14 #include "CCResourceProvider.h" | |
15 #include "CCSharedQuadState.h" | |
16 #include "FloatRect.h" | |
17 #include "IntRect.h" | |
18 #include "Region.h" | |
19 #include "SkColor.h" | |
20 #include <public/WebFilterOperations.h> | |
21 #include <public/WebTransformationMatrix.h> | |
22 #include <string> | |
23 #include <wtf/OwnPtr.h> | |
24 | |
25 namespace cc { | |
26 | |
27 class CCLayerSorter; | |
28 class CCLayerTreeHostImpl; | |
29 class CCQuadSink; | |
30 class CCRenderer; | |
31 class CCScrollbarAnimationController; | |
32 class CCScrollbarLayerImpl; | |
33 class LayerChromium; | |
34 | |
35 struct CCAppendQuadsData; | |
36 | |
37 class CCLayerImpl : public CCLayerAnimationControllerClient { | |
38 public: | |
39 static scoped_ptr<CCLayerImpl> create(int id) | |
40 { | |
41 return make_scoped_ptr(new CCLayerImpl(id)); | |
42 } | |
43 | |
44 virtual ~CCLayerImpl(); | |
45 | |
46 // CCLayerAnimationControllerClient implementation. | |
47 virtual int id() const OVERRIDE; | |
48 virtual void setOpacityFromAnimation(float) OVERRIDE; | |
49 virtual float opacity() const OVERRIDE; | |
50 virtual void setTransformFromAnimation(const WebKit::WebTransformationMatrix
&) OVERRIDE; | |
51 virtual const WebKit::WebTransformationMatrix& transform() const OVERRIDE; | |
52 | |
53 // Tree structure. | |
54 CCLayerImpl* parent() const { return m_parent; } | |
55 const ScopedPtrVector<CCLayerImpl>& children() const { return m_children; } | |
56 void addChild(scoped_ptr<CCLayerImpl>); | |
57 void removeFromParent(); | |
58 void removeAllChildren(); | |
59 | |
60 void setMaskLayer(scoped_ptr<CCLayerImpl>); | |
61 CCLayerImpl* maskLayer() const { return m_maskLayer.get(); } | |
62 | |
63 void setReplicaLayer(scoped_ptr<CCLayerImpl>); | |
64 CCLayerImpl* replicaLayer() const { return m_replicaLayer.get(); } | |
65 | |
66 bool hasMask() const { return m_maskLayer; } | |
67 bool hasReplica() const { return m_replicaLayer; } | |
68 bool replicaHasMask() const { return m_replicaLayer && (m_maskLayer || m_rep
licaLayer->m_maskLayer); } | |
69 | |
70 CCLayerTreeHostImpl* layerTreeHostImpl() const { return m_layerTreeHostImpl;
} | |
71 void setLayerTreeHostImpl(CCLayerTreeHostImpl* hostImpl) { m_layerTreeHostIm
pl = hostImpl; } | |
72 | |
73 scoped_ptr<CCSharedQuadState> createSharedQuadState() const; | |
74 // willDraw must be called before appendQuads. If willDraw is called, | |
75 // didDraw is guaranteed to be called before another willDraw or before | |
76 // the layer is destroyed. To enforce this, any class that overrides | |
77 // willDraw/didDraw must call the base class version. | |
78 virtual void willDraw(CCResourceProvider*); | |
79 virtual void appendQuads(CCQuadSink&, CCAppendQuadsData&) { } | |
80 virtual void didDraw(CCResourceProvider*); | |
81 | |
82 virtual CCResourceProvider::ResourceId contentsResourceId() const; | |
83 | |
84 virtual bool hasContributingDelegatedRenderPasses() const; | |
85 virtual CCRenderPass::Id firstContributingRenderPassId() const; | |
86 virtual CCRenderPass::Id nextContributingRenderPassId(CCRenderPass::Id) cons
t; | |
87 | |
88 // Returns true if this layer has content to draw. | |
89 void setDrawsContent(bool); | |
90 bool drawsContent() const { return m_drawsContent; } | |
91 | |
92 bool forceRenderSurface() const { return m_forceRenderSurface; } | |
93 void setForceRenderSurface(bool force) { m_forceRenderSurface = force; } | |
94 | |
95 // Returns true if any of the layer's descendants has content to draw. | |
96 virtual bool descendantDrawsContent(); | |
97 | |
98 void setAnchorPoint(const FloatPoint&); | |
99 const FloatPoint& anchorPoint() const { return m_anchorPoint; } | |
100 | |
101 void setAnchorPointZ(float); | |
102 float anchorPointZ() const { return m_anchorPointZ; } | |
103 | |
104 void setBackgroundColor(SkColor); | |
105 SkColor backgroundColor() const { return m_backgroundColor; } | |
106 | |
107 void setFilters(const WebKit::WebFilterOperations&); | |
108 const WebKit::WebFilterOperations& filters() const { return m_filters; } | |
109 | |
110 void setBackgroundFilters(const WebKit::WebFilterOperations&); | |
111 const WebKit::WebFilterOperations& backgroundFilters() const { return m_back
groundFilters; } | |
112 | |
113 void setMasksToBounds(bool); | |
114 bool masksToBounds() const { return m_masksToBounds; } | |
115 | |
116 void setContentsOpaque(bool); | |
117 bool contentsOpaque() const { return m_contentsOpaque; } | |
118 | |
119 void setOpacity(float); | |
120 bool opacityIsAnimating() const; | |
121 | |
122 void setPosition(const FloatPoint&); | |
123 const FloatPoint& position() const { return m_position; } | |
124 | |
125 void setIsContainerForFixedPositionLayers(bool isContainerForFixedPositionLa
yers) { m_isContainerForFixedPositionLayers = isContainerForFixedPositionLayers;
} | |
126 bool isContainerForFixedPositionLayers() const { return m_isContainerForFixe
dPositionLayers; } | |
127 | |
128 void setFixedToContainerLayer(bool fixedToContainerLayer = true) { m_fixedTo
ContainerLayer = fixedToContainerLayer;} | |
129 bool fixedToContainerLayer() const { return m_fixedToContainerLayer; } | |
130 | |
131 void setPreserves3D(bool); | |
132 bool preserves3D() const { return m_preserves3D; } | |
133 | |
134 void setUseParentBackfaceVisibility(bool useParentBackfaceVisibility) { m_us
eParentBackfaceVisibility = useParentBackfaceVisibility; } | |
135 bool useParentBackfaceVisibility() const { return m_useParentBackfaceVisibil
ity; } | |
136 | |
137 void setUseLCDText(bool useLCDText) { m_useLCDText = useLCDText; } | |
138 bool useLCDText() const { return m_useLCDText; } | |
139 | |
140 void setSublayerTransform(const WebKit::WebTransformationMatrix&); | |
141 const WebKit::WebTransformationMatrix& sublayerTransform() const { return m_
sublayerTransform; } | |
142 | |
143 // Debug layer border - visual effect only, do not change geometry/clipping/
etc. | |
144 void setDebugBorderColor(SkColor); | |
145 SkColor debugBorderColor() const { return m_debugBorderColor; } | |
146 void setDebugBorderWidth(float); | |
147 float debugBorderWidth() const { return m_debugBorderWidth; } | |
148 bool hasDebugBorders() const; | |
149 | |
150 // Debug layer name. | |
151 void setDebugName(const std::string& debugName) { m_debugName = debugName; } | |
152 std::string debugName() const { return m_debugName; } | |
153 | |
154 CCRenderSurface* renderSurface() const { return m_renderSurface.get(); } | |
155 void createRenderSurface(); | |
156 void clearRenderSurface() { m_renderSurface.clear(); } | |
157 | |
158 float drawOpacity() const { return m_drawOpacity; } | |
159 void setDrawOpacity(float opacity) { m_drawOpacity = opacity; } | |
160 | |
161 bool drawOpacityIsAnimating() const { return m_drawOpacityIsAnimating; } | |
162 void setDrawOpacityIsAnimating(bool drawOpacityIsAnimating) { m_drawOpacityI
sAnimating = drawOpacityIsAnimating; } | |
163 | |
164 CCLayerImpl* renderTarget() const { ASSERT(!m_renderTarget || m_renderTarget
->renderSurface()); return m_renderTarget; } | |
165 void setRenderTarget(CCLayerImpl* target) { m_renderTarget = target; } | |
166 | |
167 void setBounds(const IntSize&); | |
168 const IntSize& bounds() const { return m_bounds; } | |
169 | |
170 const IntSize& contentBounds() const { return m_contentBounds; } | |
171 void setContentBounds(const IntSize&); | |
172 | |
173 const IntPoint& scrollPosition() const { return m_scrollPosition; } | |
174 void setScrollPosition(const IntPoint&); | |
175 | |
176 const IntSize& maxScrollPosition() const {return m_maxScrollPosition; } | |
177 void setMaxScrollPosition(const IntSize&); | |
178 | |
179 const FloatSize& scrollDelta() const { return m_scrollDelta; } | |
180 void setScrollDelta(const FloatSize&); | |
181 | |
182 const WebKit::WebTransformationMatrix& implTransform() const { return m_impl
Transform; } | |
183 void setImplTransform(const WebKit::WebTransformationMatrix& transform); | |
184 | |
185 const IntSize& sentScrollDelta() const { return m_sentScrollDelta; } | |
186 void setSentScrollDelta(const IntSize& sentScrollDelta) { m_sentScrollDelta
= sentScrollDelta; } | |
187 | |
188 // Returns the delta of the scroll that was outside of the bounds of the ini
tial scroll | |
189 FloatSize scrollBy(const FloatSize& scroll); | |
190 | |
191 bool scrollable() const { return m_scrollable; } | |
192 void setScrollable(bool scrollable) { m_scrollable = scrollable; } | |
193 | |
194 bool shouldScrollOnMainThread() const { return m_shouldScrollOnMainThread; } | |
195 void setShouldScrollOnMainThread(bool shouldScrollOnMainThread) { m_shouldSc
rollOnMainThread = shouldScrollOnMainThread; } | |
196 | |
197 bool haveWheelEventHandlers() const { return m_haveWheelEventHandlers; } | |
198 void setHaveWheelEventHandlers(bool haveWheelEventHandlers) { m_haveWheelEve
ntHandlers = haveWheelEventHandlers; } | |
199 | |
200 const Region& nonFastScrollableRegion() const { return m_nonFastScrollableRe
gion; } | |
201 void setNonFastScrollableRegion(const Region& region) { m_nonFastScrollableR
egion = region; } | |
202 | |
203 void setDrawCheckerboardForMissingTiles(bool checkerboard) { m_drawCheckerbo
ardForMissingTiles = checkerboard; } | |
204 bool drawCheckerboardForMissingTiles() const; | |
205 | |
206 CCInputHandlerClient::ScrollStatus tryScroll(const IntPoint& viewportPoint,
CCInputHandlerClient::ScrollInputType) const; | |
207 | |
208 const IntRect& visibleContentRect() const { return m_visibleContentRect; } | |
209 void setVisibleContentRect(const IntRect& visibleContentRect) { m_visibleCon
tentRect = visibleContentRect; } | |
210 | |
211 bool doubleSided() const { return m_doubleSided; } | |
212 void setDoubleSided(bool); | |
213 | |
214 void setTransform(const WebKit::WebTransformationMatrix&); | |
215 bool transformIsAnimating() const; | |
216 | |
217 const WebKit::WebTransformationMatrix& drawTransform() const { return m_draw
Transform; } | |
218 void setDrawTransform(const WebKit::WebTransformationMatrix& matrix) { m_dra
wTransform = matrix; } | |
219 const WebKit::WebTransformationMatrix& screenSpaceTransform() const { return
m_screenSpaceTransform; } | |
220 void setScreenSpaceTransform(const WebKit::WebTransformationMatrix& matrix)
{ m_screenSpaceTransform = matrix; } | |
221 | |
222 bool drawTransformIsAnimating() const { return m_drawTransformIsAnimating; } | |
223 void setDrawTransformIsAnimating(bool animating) { m_drawTransformIsAnimatin
g = animating; } | |
224 bool screenSpaceTransformIsAnimating() const { return m_screenSpaceTransform
IsAnimating; } | |
225 void setScreenSpaceTransformIsAnimating(bool animating) { m_screenSpaceTrans
formIsAnimating = animating; } | |
226 | |
227 const IntRect& drawableContentRect() const { return m_drawableContentRect; } | |
228 void setDrawableContentRect(const IntRect& rect) { m_drawableContentRect = r
ect; } | |
229 const FloatRect& updateRect() const { return m_updateRect; } | |
230 void setUpdateRect(const FloatRect& updateRect) { m_updateRect = updateRect;
} | |
231 | |
232 std::string layerTreeAsText() const; | |
233 | |
234 void setStackingOrderChanged(bool); | |
235 | |
236 bool layerPropertyChanged() const { return m_layerPropertyChanged || layerIs
AlwaysDamaged(); } | |
237 bool layerSurfacePropertyChanged() const; | |
238 | |
239 void resetAllChangeTrackingForSubtree(); | |
240 | |
241 virtual bool layerIsAlwaysDamaged() const; | |
242 | |
243 CCLayerAnimationController* layerAnimationController() { return m_layerAnima
tionController.get(); } | |
244 | |
245 virtual Region visibleContentOpaqueRegion() const; | |
246 | |
247 // Indicates that the context previously used to render this layer | |
248 // was lost and that a new one has been created. Won't be called | |
249 // until the new context has been created successfully. | |
250 virtual void didLoseContext(); | |
251 | |
252 CCScrollbarAnimationController* scrollbarAnimationController() const { retur
n m_scrollbarAnimationController.get(); } | |
253 | |
254 CCScrollbarLayerImpl* horizontalScrollbarLayer() const; | |
255 void setHorizontalScrollbarLayer(CCScrollbarLayerImpl*); | |
256 | |
257 CCScrollbarLayerImpl* verticalScrollbarLayer() const; | |
258 void setVerticalScrollbarLayer(CCScrollbarLayerImpl*); | |
259 | |
260 protected: | |
261 explicit CCLayerImpl(int); | |
262 | |
263 void appendDebugBorderQuad(CCQuadSink&, const CCSharedQuadState*, CCAppendQu
adsData&) const; | |
264 | |
265 IntRect layerRectToContentRect(const WebKit::WebRect& layerRect); | |
266 | |
267 virtual void dumpLayerProperties(std::string*, int indent) const; | |
268 static std::string indentString(int indent); | |
269 | |
270 private: | |
271 void setParent(CCLayerImpl* parent) { m_parent = parent; } | |
272 friend class TreeSynchronizer; | |
273 void clearChildList(); // Warning: This does not preserve tree structure inv
ariants and so is only exposed to the tree synchronizer. | |
274 | |
275 void noteLayerPropertyChangedForSubtree(); | |
276 | |
277 // Note carefully this does not affect the current layer. | |
278 void noteLayerPropertyChangedForDescendants(); | |
279 | |
280 virtual const char* layerTypeAsString() const; | |
281 | |
282 void dumpLayer(std::string*, int indent) const; | |
283 | |
284 // Properties internal to CCLayerImpl | |
285 CCLayerImpl* m_parent; | |
286 ScopedPtrVector<CCLayerImpl> m_children; | |
287 // m_maskLayer can be temporarily stolen during tree sync, we need this ID t
o confirm newly assigned layer is still the previous one | |
288 int m_maskLayerId; | |
289 scoped_ptr<CCLayerImpl> m_maskLayer; | |
290 int m_replicaLayerId; // ditto | |
291 scoped_ptr<CCLayerImpl> m_replicaLayer; | |
292 int m_layerId; | |
293 CCLayerTreeHostImpl* m_layerTreeHostImpl; | |
294 | |
295 // Properties synchronized from the associated LayerChromium. | |
296 FloatPoint m_anchorPoint; | |
297 float m_anchorPointZ; | |
298 IntSize m_bounds; | |
299 IntSize m_contentBounds; | |
300 IntPoint m_scrollPosition; | |
301 bool m_scrollable; | |
302 bool m_shouldScrollOnMainThread; | |
303 bool m_haveWheelEventHandlers; | |
304 Region m_nonFastScrollableRegion; | |
305 SkColor m_backgroundColor; | |
306 | |
307 // Whether the "back" of this layer should draw. | |
308 bool m_doubleSided; | |
309 | |
310 // Tracks if drawing-related properties have changed since last redraw. | |
311 bool m_layerPropertyChanged; | |
312 | |
313 // Indicates that a property has changed on this layer that would not | |
314 // affect the pixels on its target surface, but would require redrawing | |
315 // but would require redrawing the targetSurface onto its ancestor targetSur
face. | |
316 // For layers that do not own a surface this flag acts as m_layerPropertyCha
nged. | |
317 bool m_layerSurfacePropertyChanged; | |
318 | |
319 // Uses layer's content space. | |
320 IntRect m_visibleContentRect; | |
321 bool m_masksToBounds; | |
322 bool m_contentsOpaque; | |
323 float m_opacity; | |
324 FloatPoint m_position; | |
325 bool m_preserves3D; | |
326 bool m_useParentBackfaceVisibility; | |
327 bool m_drawCheckerboardForMissingTiles; | |
328 WebKit::WebTransformationMatrix m_sublayerTransform; | |
329 WebKit::WebTransformationMatrix m_transform; | |
330 bool m_useLCDText; | |
331 | |
332 bool m_drawsContent; | |
333 bool m_forceRenderSurface; | |
334 | |
335 // Set for the layer that other layers are fixed to. | |
336 bool m_isContainerForFixedPositionLayers; | |
337 // This is true if the layer should be fixed to the closest ancestor contain
er. | |
338 bool m_fixedToContainerLayer; | |
339 | |
340 FloatSize m_scrollDelta; | |
341 IntSize m_sentScrollDelta; | |
342 IntSize m_maxScrollPosition; | |
343 WebKit::WebTransformationMatrix m_implTransform; | |
344 | |
345 // The layer whose coordinate space this layer draws into. This can be | |
346 // either the same layer (m_renderTarget == this) or an ancestor of this | |
347 // layer. | |
348 CCLayerImpl* m_renderTarget; | |
349 | |
350 // The global depth value of the center of the layer. This value is used | |
351 // to sort layers from back to front. | |
352 float m_drawDepth; | |
353 float m_drawOpacity; | |
354 bool m_drawOpacityIsAnimating; | |
355 | |
356 // Debug borders. | |
357 SkColor m_debugBorderColor; | |
358 float m_debugBorderWidth; | |
359 | |
360 // Debug layer name. | |
361 std::string m_debugName; | |
362 | |
363 WebKit::WebFilterOperations m_filters; | |
364 WebKit::WebFilterOperations m_backgroundFilters; | |
365 | |
366 WebKit::WebTransformationMatrix m_drawTransform; | |
367 WebKit::WebTransformationMatrix m_screenSpaceTransform; | |
368 bool m_drawTransformIsAnimating; | |
369 bool m_screenSpaceTransformIsAnimating; | |
370 | |
371 #ifndef NDEBUG | |
372 bool m_betweenWillDrawAndDidDraw; | |
373 #endif | |
374 | |
375 // Render surface associated with this layer. The layer and its descendants | |
376 // will render to this surface. | |
377 OwnPtr<CCRenderSurface> m_renderSurface; | |
378 | |
379 // Hierarchical bounding rect containing the layer and its descendants. | |
380 // Uses target surface's space. | |
381 IntRect m_drawableContentRect; | |
382 | |
383 // Rect indicating what was repainted/updated during update. | |
384 // Note that plugin layers bypass this and leave it empty. | |
385 // Uses layer's content space. | |
386 FloatRect m_updateRect; | |
387 | |
388 // Manages animations for this layer. | |
389 scoped_ptr<CCLayerAnimationController> m_layerAnimationController; | |
390 | |
391 // Manages scrollbars for this layer | |
392 OwnPtr<CCScrollbarAnimationController> m_scrollbarAnimationController; | |
393 }; | |
394 | |
395 void sortLayers(std::vector<CCLayerImpl*>::iterator first, std::vector<CCLayerIm
pl*>::iterator end, CCLayerSorter*); | |
396 | |
397 } | |
398 | |
399 #endif // CCLayerImpl_h | |
OLD | NEW |