OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2009 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Intel Corporation. All rights reserved. | 3 * Copyright (C) 2013 Intel Corporation. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 #include "public/platform/WebContentLayer.h" | 42 #include "public/platform/WebContentLayer.h" |
43 #include "public/platform/WebImageLayer.h" | 43 #include "public/platform/WebImageLayer.h" |
44 #include "public/platform/WebLayerClient.h" | 44 #include "public/platform/WebLayerClient.h" |
45 #include "public/platform/WebLayerScrollClient.h" | 45 #include "public/platform/WebLayerScrollClient.h" |
46 #include "public/platform/WebNinePatchLayer.h" | 46 #include "public/platform/WebNinePatchLayer.h" |
47 #include "wtf/OwnPtr.h" | 47 #include "wtf/OwnPtr.h" |
48 #include "wtf/PassOwnPtr.h" | 48 #include "wtf/PassOwnPtr.h" |
49 #include "wtf/Vector.h" | 49 #include "wtf/Vector.h" |
50 | 50 |
51 namespace blink { | 51 namespace blink { |
52 class GraphicsLayerFactoryChromium; | |
53 class WebAnimation; | |
54 class WebLayer; | |
55 } | |
56 | |
57 namespace blink { | |
58 | 52 |
59 class FloatRect; | 53 class FloatRect; |
60 class GraphicsContext; | 54 class GraphicsContext; |
61 class GraphicsLayer; | 55 class GraphicsLayer; |
62 class GraphicsLayerFactory; | 56 class GraphicsLayerFactory; |
| 57 class GraphicsLayerFactoryChromium; |
63 class Image; | 58 class Image; |
64 class JSONObject; | 59 class JSONObject; |
65 class ScrollableArea; | 60 class ScrollableArea; |
66 class TextStream; | 61 class TextStream; |
| 62 class WebAnimation; |
| 63 class WebLayer; |
67 | 64 |
68 // FIXME: find a better home for this declaration. | 65 // FIXME: find a better home for this declaration. |
69 class PLATFORM_EXPORT LinkHighlightClient { | 66 class PLATFORM_EXPORT LinkHighlightClient { |
70 public: | 67 public: |
71 virtual void invalidate() = 0; | 68 virtual void invalidate() = 0; |
72 virtual void clearCurrentGraphicsLayer() = 0; | 69 virtual void clearCurrentGraphicsLayer() = 0; |
73 virtual blink::WebLayer* layer() = 0; | 70 virtual WebLayer* layer() = 0; |
74 | 71 |
75 protected: | 72 protected: |
76 virtual ~LinkHighlightClient() { } | 73 virtual ~LinkHighlightClient() { } |
77 }; | 74 }; |
78 | 75 |
79 typedef Vector<GraphicsLayer*, 64> GraphicsLayerVector; | 76 typedef Vector<GraphicsLayer*, 64> GraphicsLayerVector; |
80 | 77 |
81 // GraphicsLayer is an abstraction for a rendering surface with backing store, | 78 // GraphicsLayer is an abstraction for a rendering surface with backing store, |
82 // which may have associated transformation and animations. | 79 // which may have associated transformation and animations. |
83 | 80 |
84 class PLATFORM_EXPORT GraphicsLayer : public GraphicsContextPainter, public blin
k::WebAnimationDelegate, public blink::WebLayerScrollClient, public blink::WebLa
yerClient { | 81 class PLATFORM_EXPORT GraphicsLayer : public GraphicsContextPainter, public WebA
nimationDelegate, public WebLayerScrollClient, public WebLayerClient { |
85 WTF_MAKE_NONCOPYABLE(GraphicsLayer); WTF_MAKE_FAST_ALLOCATED; | 82 WTF_MAKE_NONCOPYABLE(GraphicsLayer); WTF_MAKE_FAST_ALLOCATED; |
86 public: | 83 public: |
87 static PassOwnPtr<GraphicsLayer> create(GraphicsLayerFactory*, GraphicsLayer
Client*); | 84 static PassOwnPtr<GraphicsLayer> create(GraphicsLayerFactory*, GraphicsLayer
Client*); |
88 | 85 |
89 virtual ~GraphicsLayer(); | 86 virtual ~GraphicsLayer(); |
90 | 87 |
91 GraphicsLayerClient* client() const { return m_client; } | 88 GraphicsLayerClient* client() const { return m_client; } |
92 | 89 |
93 // blink::WebLayerClient implementation. | 90 // WebLayerClient implementation. |
94 virtual blink::WebGraphicsLayerDebugInfo* takeDebugInfoFor(blink::WebLayer*)
OVERRIDE; | 91 virtual WebGraphicsLayerDebugInfo* takeDebugInfoFor(WebLayer*) OVERRIDE; |
95 | 92 |
96 GraphicsLayerDebugInfo& debugInfo(); | 93 GraphicsLayerDebugInfo& debugInfo(); |
97 | 94 |
98 void setCompositingReasons(CompositingReasons); | 95 void setCompositingReasons(CompositingReasons); |
99 CompositingReasons compositingReasons() const { return m_debugInfo.compositi
ngReasons(); } | 96 CompositingReasons compositingReasons() const { return m_debugInfo.compositi
ngReasons(); } |
100 void setOwnerNodeId(int); | 97 void setOwnerNodeId(int); |
101 | 98 |
102 GraphicsLayer* parent() const { return m_parent; }; | 99 GraphicsLayer* parent() const { return m_parent; }; |
103 void setParent(GraphicsLayer*); // Internal use only. | 100 void setParent(GraphicsLayer*); // Internal use only. |
104 | 101 |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 void setShouldFlattenTransform(bool); | 148 void setShouldFlattenTransform(bool); |
152 void setRenderingContext(int id); | 149 void setRenderingContext(int id); |
153 void setMasksToBounds(bool); | 150 void setMasksToBounds(bool); |
154 | 151 |
155 bool drawsContent() const { return m_drawsContent; } | 152 bool drawsContent() const { return m_drawsContent; } |
156 void setDrawsContent(bool); | 153 void setDrawsContent(bool); |
157 | 154 |
158 bool contentsAreVisible() const { return m_contentsVisible; } | 155 bool contentsAreVisible() const { return m_contentsVisible; } |
159 void setContentsVisible(bool); | 156 void setContentsVisible(bool); |
160 | 157 |
161 void setScrollParent(blink::WebLayer*); | 158 void setScrollParent(WebLayer*); |
162 void setClipParent(blink::WebLayer*); | 159 void setClipParent(WebLayer*); |
163 | 160 |
164 // For special cases, e.g. drawing missing tiles on Android. | 161 // For special cases, e.g. drawing missing tiles on Android. |
165 // The compositor should never paint this color in normal cases because the
RenderLayer | 162 // The compositor should never paint this color in normal cases because the
RenderLayer |
166 // will paint background by itself. | 163 // will paint background by itself. |
167 void setBackgroundColor(const Color&); | 164 void setBackgroundColor(const Color&); |
168 | 165 |
169 // opaque means that we know the layer contents have no alpha | 166 // opaque means that we know the layer contents have no alpha |
170 bool contentsOpaque() const { return m_contentsOpaque; } | 167 bool contentsOpaque() const { return m_contentsOpaque; } |
171 void setContentsOpaque(bool); | 168 void setContentsOpaque(bool); |
172 | 169 |
173 bool backfaceVisibility() const { return m_backfaceVisibility; } | 170 bool backfaceVisibility() const { return m_backfaceVisibility; } |
174 void setBackfaceVisibility(bool visible); | 171 void setBackfaceVisibility(bool visible); |
175 | 172 |
176 float opacity() const { return m_opacity; } | 173 float opacity() const { return m_opacity; } |
177 void setOpacity(float); | 174 void setOpacity(float); |
178 | 175 |
179 void setBlendMode(blink::WebBlendMode); | 176 void setBlendMode(WebBlendMode); |
180 void setIsRootForIsolatedGroup(bool); | 177 void setIsRootForIsolatedGroup(bool); |
181 | 178 |
182 void setFilters(const FilterOperations&); | 179 void setFilters(const FilterOperations&); |
183 | 180 |
184 // Some GraphicsLayers paint only the foreground or the background content | 181 // Some GraphicsLayers paint only the foreground or the background content |
185 void setPaintingPhase(GraphicsLayerPaintingPhase); | 182 void setPaintingPhase(GraphicsLayerPaintingPhase); |
186 | 183 |
187 void setNeedsDisplay(); | 184 void setNeedsDisplay(); |
188 // mark the given rect (in layer coords) as needing dispay. Never goes deep. | 185 // mark the given rect (in layer coords) as needing dispay. Never goes deep. |
189 void setNeedsDisplayInRect(const FloatRect&); | 186 void setNeedsDisplayInRect(const FloatRect&); |
190 | 187 |
191 void setContentsNeedsDisplay(); | 188 void setContentsNeedsDisplay(); |
192 | 189 |
193 // Set that the position/size of the contents (image or video). | 190 // Set that the position/size of the contents (image or video). |
194 void setContentsRect(const IntRect&); | 191 void setContentsRect(const IntRect&); |
195 | 192 |
196 // Return true if the animation is handled by the compositing system. If thi
s returns | 193 // Return true if the animation is handled by the compositing system. If thi
s returns |
197 // false, the animation will be run by AnimationController. | 194 // false, the animation will be run by AnimationController. |
198 // These methods handle both transitions and keyframe animations. | 195 // These methods handle both transitions and keyframe animations. |
199 bool addAnimation(PassOwnPtr<blink::WebAnimation>); | 196 bool addAnimation(PassOwnPtr<WebAnimation>); |
200 void pauseAnimation(int animationId, double /*timeOffset*/); | 197 void pauseAnimation(int animationId, double /*timeOffset*/); |
201 void removeAnimation(int animationId); | 198 void removeAnimation(int animationId); |
202 | 199 |
203 // Layer contents | 200 // Layer contents |
204 void setContentsToImage(Image*); | 201 void setContentsToImage(Image*); |
205 void setContentsToNinePatch(Image*, const IntRect& aperture); | 202 void setContentsToNinePatch(Image*, const IntRect& aperture); |
206 void setContentsToPlatformLayer(blink::WebLayer* layer) { setContentsTo(laye
r); } | 203 void setContentsToPlatformLayer(WebLayer* layer) { setContentsTo(layer); } |
207 bool hasContentsLayer() const { return m_contentsLayer; } | 204 bool hasContentsLayer() const { return m_contentsLayer; } |
208 | 205 |
209 // For hosting this GraphicsLayer in a native layer hierarchy. | 206 // For hosting this GraphicsLayer in a native layer hierarchy. |
210 blink::WebLayer* platformLayer() const; | 207 WebLayer* platformLayer() const; |
211 | 208 |
212 typedef HashMap<int, int> RenderingContextMap; | 209 typedef HashMap<int, int> RenderingContextMap; |
213 PassRefPtr<JSONObject> layerTreeAsJSON(LayerTreeFlags, RenderingContextMap&)
const; | 210 PassRefPtr<JSONObject> layerTreeAsJSON(LayerTreeFlags, RenderingContextMap&)
const; |
214 | 211 |
215 int paintCount() const { return m_paintCount; } | 212 int paintCount() const { return m_paintCount; } |
216 | 213 |
217 // Return a string with a human readable form of the layer tree, If debug is
true | 214 // Return a string with a human readable form of the layer tree, If debug is
true |
218 // pointers for the layers and timing data will be included in the returned
string. | 215 // pointers for the layers and timing data will be included in the returned
string. |
219 String layerTreeAsText(LayerTreeFlags = LayerTreeNormal) const; | 216 String layerTreeAsText(LayerTreeFlags = LayerTreeNormal) const; |
220 | 217 |
221 void resetTrackedRepaints(); | 218 void resetTrackedRepaints(); |
222 void addRepaintRect(const FloatRect&); | 219 void addRepaintRect(const FloatRect&); |
223 | 220 |
224 void addLinkHighlight(LinkHighlightClient*); | 221 void addLinkHighlight(LinkHighlightClient*); |
225 void removeLinkHighlight(LinkHighlightClient*); | 222 void removeLinkHighlight(LinkHighlightClient*); |
226 // Exposed for tests | 223 // Exposed for tests |
227 unsigned numLinkHighlights() { return m_linkHighlights.size(); } | 224 unsigned numLinkHighlights() { return m_linkHighlights.size(); } |
228 LinkHighlightClient* linkHighlight(int i) { return m_linkHighlights[i]; } | 225 LinkHighlightClient* linkHighlight(int i) { return m_linkHighlights[i]; } |
229 | 226 |
230 void setScrollableArea(ScrollableArea*, bool isMainFrame); | 227 void setScrollableArea(ScrollableArea*, bool isMainFrame); |
231 ScrollableArea* scrollableArea() const { return m_scrollableArea; } | 228 ScrollableArea* scrollableArea() const { return m_scrollableArea; } |
232 | 229 |
233 blink::WebContentLayer* contentLayer() const { return m_layer.get(); } | 230 WebContentLayer* contentLayer() const { return m_layer.get(); } |
234 | 231 |
235 static void registerContentsLayer(blink::WebLayer*); | 232 static void registerContentsLayer(WebLayer*); |
236 static void unregisterContentsLayer(blink::WebLayer*); | 233 static void unregisterContentsLayer(WebLayer*); |
237 | 234 |
238 // GraphicsContextPainter implementation. | 235 // GraphicsContextPainter implementation. |
239 virtual void paint(GraphicsContext&, const IntRect& clip) OVERRIDE; | 236 virtual void paint(GraphicsContext&, const IntRect& clip) OVERRIDE; |
240 | 237 |
241 // WebAnimationDelegate implementation. | 238 // WebAnimationDelegate implementation. |
242 virtual void notifyAnimationStarted(double monotonicTime, blink::WebAnimatio
n::TargetProperty) OVERRIDE; | 239 virtual void notifyAnimationStarted(double monotonicTime, WebAnimation::Targ
etProperty) OVERRIDE; |
243 virtual void notifyAnimationFinished(double monotonicTime, blink::WebAnimati
on::TargetProperty) OVERRIDE; | 240 virtual void notifyAnimationFinished(double monotonicTime, WebAnimation::Tar
getProperty) OVERRIDE; |
244 | 241 |
245 // WebLayerScrollClient implementation. | 242 // WebLayerScrollClient implementation. |
246 virtual void didScroll() OVERRIDE; | 243 virtual void didScroll() OVERRIDE; |
247 | 244 |
248 protected: | 245 protected: |
249 String debugName(blink::WebLayer*) const; | 246 String debugName(WebLayer*) const; |
250 | 247 |
251 explicit GraphicsLayer(GraphicsLayerClient*); | 248 explicit GraphicsLayer(GraphicsLayerClient*); |
252 // GraphicsLayerFactoryChromium that wants to create a GraphicsLayer need to
be friends. | 249 // GraphicsLayerFactoryChromium that wants to create a GraphicsLayer need to
be friends. |
253 friend class blink::GraphicsLayerFactoryChromium; | 250 friend class GraphicsLayerFactoryChromium; |
254 | 251 |
255 // Exposed for tests. | 252 // Exposed for tests. |
256 virtual blink::WebLayer* contentsLayer() const { return m_contentsLayer; } | 253 virtual WebLayer* contentsLayer() const { return m_contentsLayer; } |
257 | 254 |
258 private: | 255 private: |
259 // Callback from the underlying graphics system to draw layer contents. | 256 // Callback from the underlying graphics system to draw layer contents. |
260 void paintGraphicsLayerContents(GraphicsContext&, const IntRect& clip); | 257 void paintGraphicsLayerContents(GraphicsContext&, const IntRect& clip); |
261 | 258 |
262 // Adds a child without calling updateChildList(), so that adding children | 259 // Adds a child without calling updateChildList(), so that adding children |
263 // can be batched before updating. | 260 // can be batched before updating. |
264 void addChildInternal(GraphicsLayer*); | 261 void addChildInternal(GraphicsLayer*); |
265 | 262 |
266 #if ENABLE(ASSERT) | 263 #if ENABLE(ASSERT) |
267 bool hasAncestor(GraphicsLayer*) const; | 264 bool hasAncestor(GraphicsLayer*) const; |
268 #endif | 265 #endif |
269 | 266 |
270 void setReplicatedLayer(GraphicsLayer* layer) { m_replicatedLayer = layer; } | 267 void setReplicatedLayer(GraphicsLayer* layer) { m_replicatedLayer = layer; } |
271 | 268 |
272 void incrementPaintCount() { ++m_paintCount; } | 269 void incrementPaintCount() { ++m_paintCount; } |
273 | 270 |
274 // Helper functions used by settors to keep layer's the state consistent. | 271 // Helper functions used by settors to keep layer's the state consistent. |
275 void updateChildList(); | 272 void updateChildList(); |
276 void updateLayerIsDrawable(); | 273 void updateLayerIsDrawable(); |
277 void updateContentsRect(); | 274 void updateContentsRect(); |
278 | 275 |
279 void setContentsTo(blink::WebLayer*); | 276 void setContentsTo(WebLayer*); |
280 void setupContentsLayer(blink::WebLayer*); | 277 void setupContentsLayer(WebLayer*); |
281 void clearContentsLayerIfUnregistered(); | 278 void clearContentsLayerIfUnregistered(); |
282 blink::WebLayer* contentsLayerIfRegistered(); | 279 WebLayer* contentsLayerIfRegistered(); |
283 | 280 |
284 GraphicsLayerClient* m_client; | 281 GraphicsLayerClient* m_client; |
285 | 282 |
286 // Offset from the owning renderer | 283 // Offset from the owning renderer |
287 IntSize m_offsetFromRenderer; | 284 IntSize m_offsetFromRenderer; |
288 | 285 |
289 // Position is relative to the parent GraphicsLayer | 286 // Position is relative to the parent GraphicsLayer |
290 FloatPoint m_position; | 287 FloatPoint m_position; |
291 FloatSize m_size; | 288 FloatSize m_size; |
292 | 289 |
293 TransformationMatrix m_transform; | 290 TransformationMatrix m_transform; |
294 FloatPoint3D m_transformOrigin; | 291 FloatPoint3D m_transformOrigin; |
295 | 292 |
296 Color m_backgroundColor; | 293 Color m_backgroundColor; |
297 float m_opacity; | 294 float m_opacity; |
298 | 295 |
299 blink::WebBlendMode m_blendMode; | 296 WebBlendMode m_blendMode; |
300 | 297 |
301 bool m_hasTransformOrigin : 1; | 298 bool m_hasTransformOrigin : 1; |
302 bool m_contentsOpaque : 1; | 299 bool m_contentsOpaque : 1; |
303 bool m_shouldFlattenTransform: 1; | 300 bool m_shouldFlattenTransform: 1; |
304 bool m_backfaceVisibility : 1; | 301 bool m_backfaceVisibility : 1; |
305 bool m_masksToBounds : 1; | 302 bool m_masksToBounds : 1; |
306 bool m_drawsContent : 1; | 303 bool m_drawsContent : 1; |
307 bool m_contentsVisible : 1; | 304 bool m_contentsVisible : 1; |
308 bool m_isRootForIsolatedGroup : 1; | 305 bool m_isRootForIsolatedGroup : 1; |
309 | 306 |
(...skipping 10 matching lines...) Expand all Loading... |
320 | 317 |
321 GraphicsLayer* m_replicaLayer; // A layer that replicates this layer. We onl
y allow one, for now. | 318 GraphicsLayer* m_replicaLayer; // A layer that replicates this layer. We onl
y allow one, for now. |
322 // The replica is not parented; this is the p
rimary reference to it. | 319 // The replica is not parented; this is the p
rimary reference to it. |
323 GraphicsLayer* m_replicatedLayer; // For a replica layer, a reference to the
original layer. | 320 GraphicsLayer* m_replicatedLayer; // For a replica layer, a reference to the
original layer. |
324 FloatPoint m_replicatedLayerPosition; // For a replica layer, the position o
f the replica. | 321 FloatPoint m_replicatedLayerPosition; // For a replica layer, the position o
f the replica. |
325 | 322 |
326 IntRect m_contentsRect; | 323 IntRect m_contentsRect; |
327 | 324 |
328 int m_paintCount; | 325 int m_paintCount; |
329 | 326 |
330 OwnPtr<blink::WebContentLayer> m_layer; | 327 OwnPtr<WebContentLayer> m_layer; |
331 OwnPtr<blink::WebImageLayer> m_imageLayer; | 328 OwnPtr<WebImageLayer> m_imageLayer; |
332 OwnPtr<blink::WebNinePatchLayer> m_ninePatchLayer; | 329 OwnPtr<WebNinePatchLayer> m_ninePatchLayer; |
333 blink::WebLayer* m_contentsLayer; | 330 WebLayer* m_contentsLayer; |
334 // We don't have ownership of m_contentsLayer, but we do want to know if a g
iven layer is the | 331 // We don't have ownership of m_contentsLayer, but we do want to know if a g
iven layer is the |
335 // same as our current layer in setContentsTo(). Since m_contentsLayer may b
e deleted at this point, | 332 // same as our current layer in setContentsTo(). Since m_contentsLayer may b
e deleted at this point, |
336 // we stash an ID away when we know m_contentsLayer is alive and use that fo
r comparisons from that point | 333 // we stash an ID away when we know m_contentsLayer is alive and use that fo
r comparisons from that point |
337 // on. | 334 // on. |
338 int m_contentsLayerId; | 335 int m_contentsLayerId; |
339 | 336 |
340 Vector<LinkHighlightClient*> m_linkHighlights; | 337 Vector<LinkHighlightClient*> m_linkHighlights; |
341 | 338 |
342 OwnPtr<OpaqueRectTrackingContentLayerDelegate> m_opaqueRectTrackingContentLa
yerDelegate; | 339 OwnPtr<OpaqueRectTrackingContentLayerDelegate> m_opaqueRectTrackingContentLa
yerDelegate; |
343 | 340 |
344 ScrollableArea* m_scrollableArea; | 341 ScrollableArea* m_scrollableArea; |
345 GraphicsLayerDebugInfo m_debugInfo; | 342 GraphicsLayerDebugInfo m_debugInfo; |
346 int m_3dRenderingContext; | 343 int m_3dRenderingContext; |
347 }; | 344 }; |
348 | 345 |
349 } // namespace blink | 346 } // namespace blink |
350 | 347 |
351 #ifndef NDEBUG | 348 #ifndef NDEBUG |
352 // Outside the WebCore namespace for ease of invocation from gdb. | 349 // Outside the WebCore namespace for ease of invocation from gdb. |
353 void PLATFORM_EXPORT showGraphicsLayerTree(const blink::GraphicsLayer*); | 350 void PLATFORM_EXPORT showGraphicsLayerTree(const blink::GraphicsLayer*); |
354 #endif | 351 #endif |
355 | 352 |
356 #endif // GraphicsLayer_h | 353 #endif // GraphicsLayer_h |
OLD | NEW |