Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: sky/engine/platform/graphics/GraphicsLayer.h

Issue 762993003: Remove GraphicsLayer family of classes. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Intel Corporation. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 */
26
27 #ifndef SKY_ENGINE_PLATFORM_GRAPHICS_GRAPHICSLAYER_H_
28 #define SKY_ENGINE_PLATFORM_GRAPHICS_GRAPHICSLAYER_H_
29
30 #include "sky/engine/platform/PlatformExport.h"
31 #include "sky/engine/platform/geometry/FloatPoint.h"
32 #include "sky/engine/platform/geometry/FloatPoint3D.h"
33 #include "sky/engine/platform/geometry/FloatSize.h"
34 #include "sky/engine/platform/geometry/IntRect.h"
35 #include "sky/engine/platform/graphics/Color.h"
36 #include "sky/engine/platform/graphics/GraphicsLayerClient.h"
37 #include "sky/engine/platform/graphics/GraphicsLayerDebugInfo.h"
38 #include "sky/engine/platform/graphics/OpaqueRectTrackingContentLayerDelegate.h"
39 #include "sky/engine/platform/graphics/filters/FilterOperations.h"
40 #include "sky/engine/platform/transforms/TransformationMatrix.h"
41 #include "sky/engine/public/platform/WebCompositorAnimationDelegate.h"
42 #include "sky/engine/public/platform/WebContentLayer.h"
43 #include "sky/engine/public/platform/WebImageLayer.h"
44 #include "sky/engine/public/platform/WebLayerClient.h"
45 #include "sky/engine/public/platform/WebLayerScrollClient.h"
46 #include "sky/engine/wtf/OwnPtr.h"
47 #include "sky/engine/wtf/PassOwnPtr.h"
48 #include "sky/engine/wtf/Vector.h"
49
50 namespace blink {
51
52 class FloatRect;
53 class GraphicsContext;
54 class GraphicsLayer;
55 class GraphicsLayerFactory;
56 class GraphicsLayerFactoryChromium;
57 class Image;
58 class JSONObject;
59 class ScrollableArea;
60 class WebCompositorAnimation;
61 class WebLayer;
62
63 // FIXME: find a better home for this declaration.
64 class PLATFORM_EXPORT LinkHighlightClient {
65 public:
66 virtual void invalidate() = 0;
67 virtual void clearCurrentGraphicsLayer() = 0;
68 virtual WebLayer* layer() = 0;
69
70 protected:
71 virtual ~LinkHighlightClient() { }
72 };
73
74 typedef Vector<GraphicsLayer*, 64> GraphicsLayerVector;
75
76 // GraphicsLayer is an abstraction for a rendering surface with backing store,
77 // which may have associated transformation and animations.
78
79 class PLATFORM_EXPORT GraphicsLayer : public GraphicsContextPainter, public WebC ompositorAnimationDelegate, public WebLayerScrollClient, public WebLayerClient {
80 WTF_MAKE_NONCOPYABLE(GraphicsLayer); WTF_MAKE_FAST_ALLOCATED;
81 public:
82 static PassOwnPtr<GraphicsLayer> create(GraphicsLayerFactory*, GraphicsLayer Client*);
83
84 virtual ~GraphicsLayer();
85
86 GraphicsLayerClient* client() const { return m_client; }
87
88 // WebLayerClient implementation.
89 virtual WebGraphicsLayerDebugInfo* takeDebugInfoFor(WebLayer*) override;
90
91 GraphicsLayerDebugInfo& debugInfo();
92
93 void setCompositingReasons(CompositingReasons);
94 CompositingReasons compositingReasons() const { return m_debugInfo.compositi ngReasons(); }
95 void setOwnerNodeId(int);
96
97 GraphicsLayer* parent() const { return m_parent; };
98 void setParent(GraphicsLayer*); // Internal use only.
99
100 const Vector<GraphicsLayer*>& children() const { return m_children; }
101 // Returns true if the child list changed.
102 bool setChildren(const GraphicsLayerVector&);
103
104 // Add child layers. If the child is already parented, it will be removed fr om its old parent.
105 void addChild(GraphicsLayer*);
106 void addChildBelow(GraphicsLayer*, GraphicsLayer* sibling);
107
108 void removeAllChildren();
109 void removeFromParent();
110
111 GraphicsLayer* maskLayer() const { return m_maskLayer; }
112 void setMaskLayer(GraphicsLayer*);
113
114 GraphicsLayer* contentsClippingMaskLayer() const { return m_contentsClipping MaskLayer; }
115 void setContentsClippingMaskLayer(GraphicsLayer*);
116
117 enum ShouldSetNeedsDisplay {
118 DontSetNeedsDisplay,
119 SetNeedsDisplay
120 };
121
122 // Offset is origin of the renderer minus origin of the graphics layer (so e ither zero or negative).
123 IntSize offsetFromRenderer() const { return m_offsetFromRenderer; }
124 void setOffsetFromRenderer(const IntSize&, ShouldSetNeedsDisplay = SetNeedsD isplay);
125
126 // The position of the layer (the location of its top-left corner in its par ent)
127 const FloatPoint& position() const { return m_position; }
128 void setPosition(const FloatPoint&);
129
130 const FloatPoint3D& transformOrigin() const { return m_transformOrigin; }
131 void setTransformOrigin(const FloatPoint3D&);
132
133 // The size of the layer.
134 const FloatSize& size() const { return m_size; }
135 void setSize(const FloatSize&);
136
137 const TransformationMatrix& transform() const { return m_transform; }
138 void setTransform(const TransformationMatrix&);
139 void setShouldFlattenTransform(bool);
140 void setRenderingContext(int id);
141 void setMasksToBounds(bool);
142
143 bool drawsContent() const { return m_drawsContent; }
144 void setDrawsContent(bool);
145
146 bool contentsAreVisible() const { return m_contentsVisible; }
147 void setContentsVisible(bool);
148
149 void setScrollParent(WebLayer*);
150 void setClipParent(WebLayer*);
151
152 // For special cases, e.g. drawing missing tiles on Android.
153 // The compositor should never paint this color in normal cases because the RenderLayer
154 // will paint background by itself.
155 void setBackgroundColor(const Color&);
156
157 // opaque means that we know the layer contents have no alpha
158 bool contentsOpaque() const { return m_contentsOpaque; }
159 void setContentsOpaque(bool);
160
161 bool backfaceVisibility() const { return m_backfaceVisibility; }
162 void setBackfaceVisibility(bool visible);
163
164 float opacity() const { return m_opacity; }
165 void setOpacity(float);
166
167 void setBlendMode(WebBlendMode);
168
169 void setFilters(const FilterOperations&);
170
171 // Some GraphicsLayers paint only the foreground or the background content
172 void setPaintingPhase(GraphicsLayerPaintingPhase);
173
174 void setNeedsDisplay();
175 // mark the given rect (in layer coords) as needing dispay. Never goes deep.
176 void setNeedsDisplayInRect(const FloatRect&);
177
178 void setContentsNeedsDisplay();
179
180 // Set that the position/size of the contents (image or video).
181 void setContentsRect(const IntRect&);
182
183 // Return true if the animation is handled by the compositing system. If thi s returns
184 // false, the animation will be run by AnimationController.
185 // These methods handle both transitions and keyframe animations.
186 bool addAnimation(PassOwnPtr<WebCompositorAnimation>);
187 void pauseAnimation(int animationId, double /*timeOffset*/);
188 void removeAnimation(int animationId);
189
190 // Layer contents
191 void setContentsToImage(Image*);
192 void setContentsToPlatformLayer(WebLayer* layer) { setContentsTo(layer); }
193 bool hasContentsLayer() const { return m_contentsLayer; }
194
195 // For hosting this GraphicsLayer in a native layer hierarchy.
196 WebLayer* platformLayer() const;
197
198 int paintCount() const { return m_paintCount; }
199
200 void resetTrackedPaintInvalidations();
201 void addRepaintRect(const FloatRect&);
202
203 void addLinkHighlight(LinkHighlightClient*);
204 void removeLinkHighlight(LinkHighlightClient*);
205 // Exposed for tests
206 unsigned numLinkHighlights() { return m_linkHighlights.size(); }
207 LinkHighlightClient* linkHighlight(int i) { return m_linkHighlights[i]; }
208
209 void setScrollableArea(ScrollableArea*);
210 ScrollableArea* scrollableArea() const { return m_scrollableArea; }
211
212 WebContentLayer* contentLayer() const { return m_layer.get(); }
213
214 static void registerContentsLayer(WebLayer*);
215 static void unregisterContentsLayer(WebLayer*);
216
217 // GraphicsContextPainter implementation.
218 virtual void paint(GraphicsContext&, const IntRect& clip) override;
219
220 // WebCompositorAnimationDelegate implementation.
221 virtual void notifyAnimationStarted(double monotonicTime, WebCompositorAnima tion::TargetProperty) override;
222 virtual void notifyAnimationFinished(double monotonicTime, WebCompositorAnim ation::TargetProperty) override;
223
224 // WebLayerScrollClient implementation.
225 virtual void didScroll() override;
226
227 protected:
228 String debugName(WebLayer*) const;
229
230 explicit GraphicsLayer(GraphicsLayerClient*);
231 // GraphicsLayerFactoryChromium that wants to create a GraphicsLayer need to be friends.
232 friend class GraphicsLayerFactoryChromium;
233
234 // Exposed for tests.
235 virtual WebLayer* contentsLayer() const { return m_contentsLayer; }
236
237 private:
238 // Callback from the underlying graphics system to draw layer contents.
239 void paintGraphicsLayerContents(GraphicsContext&, const IntRect& clip);
240
241 // Adds a child without calling updateChildList(), so that adding children
242 // can be batched before updating.
243 void addChildInternal(GraphicsLayer*);
244
245 #if ENABLE(ASSERT)
246 bool hasAncestor(GraphicsLayer*) const;
247 #endif
248
249 void incrementPaintCount() { ++m_paintCount; }
250
251 // Helper functions used by settors to keep layer's the state consistent.
252 void updateChildList();
253 void updateLayerIsDrawable();
254 void updateContentsRect();
255
256 void setContentsTo(WebLayer*);
257 void setupContentsLayer(WebLayer*);
258 void clearContentsLayerIfUnregistered();
259 WebLayer* contentsLayerIfRegistered();
260
261 GraphicsLayerClient* m_client;
262
263 // Offset from the owning renderer
264 IntSize m_offsetFromRenderer;
265
266 // Position is relative to the parent GraphicsLayer
267 FloatPoint m_position;
268 FloatSize m_size;
269
270 TransformationMatrix m_transform;
271 FloatPoint3D m_transformOrigin;
272
273 Color m_backgroundColor;
274 float m_opacity;
275
276 WebBlendMode m_blendMode;
277
278 bool m_hasTransformOrigin : 1;
279 bool m_contentsOpaque : 1;
280 bool m_shouldFlattenTransform: 1;
281 bool m_backfaceVisibility : 1;
282 bool m_masksToBounds : 1;
283 bool m_drawsContent : 1;
284 bool m_contentsVisible : 1;
285
286 bool m_hasScrollParent : 1;
287 bool m_hasClipParent : 1;
288
289 GraphicsLayerPaintingPhase m_paintingPhase;
290
291 Vector<GraphicsLayer*> m_children;
292 GraphicsLayer* m_parent;
293
294 GraphicsLayer* m_maskLayer; // Reference to mask layer. We don't own this.
295 GraphicsLayer* m_contentsClippingMaskLayer; // Reference to clipping mask la yer. We don't own this.
296
297 IntRect m_contentsRect;
298
299 int m_paintCount;
300
301 OwnPtr<WebContentLayer> m_layer;
302 OwnPtr<WebImageLayer> m_imageLayer;
303 WebLayer* m_contentsLayer;
304 // We don't have ownership of m_contentsLayer, but we do want to know if a g iven layer is the
305 // same as our current layer in setContentsTo(). Since m_contentsLayer may b e deleted at this point,
306 // we stash an ID away when we know m_contentsLayer is alive and use that fo r comparisons from that point
307 // on.
308 int m_contentsLayerId;
309
310 Vector<LinkHighlightClient*> m_linkHighlights;
311
312 OwnPtr<OpaqueRectTrackingContentLayerDelegate> m_opaqueRectTrackingContentLa yerDelegate;
313
314 ScrollableArea* m_scrollableArea;
315 GraphicsLayerDebugInfo m_debugInfo;
316 int m_3dRenderingContext;
317 };
318
319 } // namespace blink
320
321 #endif // SKY_ENGINE_PLATFORM_GRAPHICS_GRAPHICSLAYER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698