2 * Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef RenderLayerBacking_h
27 #define RenderLayerBacking_h
29 #if USE(ACCELERATED_COMPOSITING)
31 #include "FloatPoint.h"
32 #include "FloatPoint3D.h"
33 #include "GraphicsLayer.h"
34 #include "GraphicsLayerClient.h"
35 #include "RenderLayer.h"
36 #include "TransformationMatrix.h"
41 class RenderLayerCompositor;
43 enum CompositingLayerType {
44 NormalCompositingLayer, // non-tiled layer with backing store
45 TiledCompositingLayer, // tiled layer (always has backing store)
46 MediaCompositingLayer, // layer that contains an image, video, webGL or plugin
47 ContainerCompositingLayer // layer with no backing store
50 // RenderLayerBacking controls the compositing behavior for a single RenderLayer.
51 // It holds the various GraphicsLayers, and makes decisions about intra-layer rendering
54 // There is one RenderLayerBacking for each RenderLayer that is composited.
56 class RenderLayerBacking : public GraphicsLayerClient {
57 WTF_MAKE_NONCOPYABLE(RenderLayerBacking); WTF_MAKE_FAST_ALLOCATED;
59 RenderLayerBacking(RenderLayer*);
60 ~RenderLayerBacking();
62 RenderLayer* owningLayer() const { return m_owningLayer; }
64 enum UpdateDepth { CompositingChildren, AllDescendants };
65 void updateAfterLayout(UpdateDepth, bool isUpdateRoot);
67 // Returns true if layer configuration changed.
68 bool updateGraphicsLayerConfiguration();
69 // Update graphics layer position and bounds.
70 void updateGraphicsLayerGeometry(); // make private
71 // Update contents and clipping structure.
72 void updateDrawsContent();
74 GraphicsLayer* graphicsLayer() const { return m_graphicsLayer.get(); }
76 // Layer to clip children
77 bool hasClippingLayer() const { return (m_containmentLayer && !m_usingTiledCacheLayer); }
78 GraphicsLayer* clippingLayer() const { return !m_usingTiledCacheLayer ? m_containmentLayer.get() : 0; }
80 // Layer to get clipped by ancestor
81 bool hasAncestorClippingLayer() const { return m_ancestorClippingLayer != 0; }
82 GraphicsLayer* ancestorClippingLayer() const { return m_ancestorClippingLayer.get(); }
84 bool hasContentsLayer() const { return m_foregroundLayer != 0; }
85 GraphicsLayer* foregroundLayer() const { return m_foregroundLayer.get(); }
87 bool hasMaskLayer() const { return m_maskLayer != 0; }
89 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
90 GraphicsLayer* parentForSublayers() const;
92 GraphicsLayer* parentForSublayers() const { return m_containmentLayer ? m_containmentLayer.get() : m_graphicsLayer.get(); }
94 GraphicsLayer* childForSuperlayers() const { return m_ancestorClippingLayer ? m_ancestorClippingLayer.get() : m_graphicsLayer.get(); }
96 // RenderLayers with backing normally short-circuit paintLayer() because
97 // their content is rendered via callbacks from GraphicsLayer. However, the document
98 // layer is special, because it has a GraphicsLayer to act as a container for the GraphicsLayers
99 // for descendants, but its contents usually render into the window (in which case this returns true).
100 // This returns false for other layers, and when the document layer actually needs to paint into its backing store
102 bool paintsIntoWindow() const;
104 // Returns true for a composited layer that has no backing store of its own, so
105 // paints into some ancestor layer.
106 bool paintsIntoCompositedAncestor() const { return !m_requiresOwnBackingStore; }
108 void setRequiresOwnBackingStore(bool);
110 void setContentsNeedDisplay();
111 // r is in the coordinate space of the layer's render object
112 void setContentsNeedDisplayInRect(const IntRect&);
114 // Notification from the renderer that its content changed.
115 void contentChanged(ContentChangeType);
117 // Interface to start, finish, suspend and resume animations and transitions
118 bool startTransition(double, CSSPropertyID, const RenderStyle* fromStyle, const RenderStyle* toStyle);
119 void transitionPaused(double timeOffset, CSSPropertyID);
120 void transitionFinished(CSSPropertyID);
122 bool startAnimation(double timeOffset, const Animation* anim, const KeyframeList& keyframes);
123 void animationPaused(double timeOffset, const String& name);
124 void animationFinished(const String& name);
126 void suspendAnimations(double time = 0);
127 void resumeAnimations();
129 IntRect compositedBounds() const;
130 void setCompositedBounds(const IntRect&);
131 void updateCompositedBounds();
133 void updateAfterWidgetResize();
135 // GraphicsLayerClient interface
136 virtual bool shouldUseTileCache(const GraphicsLayer*) const;
137 virtual bool usingTileCache(const GraphicsLayer*) const { return m_usingTiledCacheLayer; }
138 virtual void notifyAnimationStarted(const GraphicsLayer*, double startTime);
139 virtual void notifySyncRequired(const GraphicsLayer*);
141 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& clip);
143 virtual float deviceScaleFactor() const;
144 virtual float pageScaleFactor() const;
145 virtual void didCommitChangesForLayer(const GraphicsLayer*) const;
146 virtual bool getCurrentTransform(const GraphicsLayer*, TransformationMatrix&) const;
148 virtual bool showDebugBorders(const GraphicsLayer*) const;
149 virtual bool showRepaintCounter(const GraphicsLayer*) const;
151 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
152 virtual void platformLayerChanged(GraphicsLayer*, PlatformLayer* oldPlatformLayer, PlatformLayer* newPlatformLayer);
154 bool hasScrollingLayer() const { return m_scrollingLayer; }
155 GraphicsLayer* scrollingLayer() const { return m_scrollingLayer.get(); }
156 GraphicsLayer* scrollingContentsLayer() const { return m_scrollingContentsLayer.get(); }
159 virtual void verifyNotPainting();
162 IntRect contentsBox() const;
163 IntRect backgroundBox() const;
165 // For informative purposes only.
166 CompositingLayerType compositingLayerType() const;
168 GraphicsLayer* layerForHorizontalScrollbar() const { return m_layerForHorizontalScrollbar.get(); }
169 GraphicsLayer* layerForVerticalScrollbar() const { return m_layerForVerticalScrollbar.get(); }
170 GraphicsLayer* layerForScrollCorner() const { return m_layerForScrollCorner.get(); }
172 #if ENABLE(CSS_FILTERS)
173 bool canCompositeFilters() const { return m_canCompositeFilters; }
176 // Return an estimate of the backing store area (in pixels) allocated by this object's GraphicsLayers.
177 double backingStoreMemoryEstimate() const;
179 String nameForLayer() const;
182 void createPrimaryGraphicsLayer();
183 void destroyGraphicsLayers();
185 PassOwnPtr<GraphicsLayer> createGraphicsLayer(const String&);
187 RenderBoxModelObject* renderer() const { return m_owningLayer->renderer(); }
188 RenderLayerCompositor* compositor() const { return m_owningLayer->compositor(); }
190 void updateInternalHierarchy();
191 bool updateClippingLayers(bool needsAncestorClip, bool needsDescendantClip);
192 bool updateOverflowControlsLayers(bool needsHorizontalScrollbarLayer, bool needsVerticalScrollbarLayer, bool needsScrollCornerLayer);
193 bool updateForegroundLayer(bool needsForegroundLayer);
194 bool updateMaskLayer(bool needsMaskLayer);
195 bool requiresHorizontalScrollbarLayer() const;
196 bool requiresVerticalScrollbarLayer() const;
197 bool requiresScrollCornerLayer() const;
198 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
199 bool updateScrollingLayers(bool scrollingLayers);
201 void updateDrawsContent(bool isSimpleContainer);
203 GraphicsLayerPaintingPhase paintingPhaseForPrimaryLayer() const;
205 IntSize contentOffsetInCompostingLayer() const;
206 // Result is transform origin in pixels.
207 FloatPoint3D computeTransformOrigin(const IntRect& borderBox) const;
208 // Result is perspective origin in pixels.
209 FloatPoint computePerspectiveOrigin(const IntRect& borderBox) const;
211 void updateLayerOpacity(const RenderStyle*);
212 void updateLayerTransform(const RenderStyle*);
213 #if ENABLE(CSS_FILTERS)
214 void updateLayerFilters(const RenderStyle*);
217 // Return the opacity value that this layer should use for compositing.
218 float compositingOpacity(float rendererOpacity) const;
220 bool isMainFrameRenderViewLayer() const;
222 bool paintsBoxDecorations() const;
223 bool paintsChildren() const;
225 // Returns true if this compositing layer has no visible content.
226 bool isSimpleContainerCompositingLayer() const;
227 // Returns true if this layer has content that needs to be rendered by painting into the backing store.
228 bool containsPaintedContent() const;
229 // Returns true if the RenderLayer just contains an image that we can composite directly.
230 bool isDirectlyCompositedImage() const;
231 void updateImageContents();
233 Color rendererBackgroundColor() const;
234 void updateBackgroundColor(bool isSimpleContainer);
235 void updateContentsRect(bool isSimpleContainer);
237 bool containsNonEmptyRenderers() const;
238 bool hasVisibleNonCompositingDescendantLayers() const;
240 bool shouldClipCompositedBounds() const;
242 bool hasTileCacheFlatteningLayer() const { return (m_containmentLayer && m_usingTiledCacheLayer); }
243 GraphicsLayer* tileCacheFlatteningLayer() const { return m_usingTiledCacheLayer ? m_containmentLayer.get() : 0; }
245 void paintIntoLayer(RenderLayer* rootLayer, GraphicsContext*, const IntRect& paintDirtyRect, PaintBehavior, GraphicsLayerPaintingPhase, RenderObject* paintingRoot);
247 static CSSPropertyID graphicsLayerToCSSProperty(AnimatedPropertyID);
248 static AnimatedPropertyID cssToGraphicsLayerProperty(CSSPropertyID);
250 RenderLayer* m_owningLayer;
252 OwnPtr<GraphicsLayer> m_ancestorClippingLayer; // only used if we are clipped by an ancestor which is not a stacking context
253 OwnPtr<GraphicsLayer> m_graphicsLayer;
254 OwnPtr<GraphicsLayer> m_foregroundLayer; // only used in cases where we need to draw the foreground separately
255 OwnPtr<GraphicsLayer> m_containmentLayer; // Only used if we have clipping on a stacking context with compositing children, or if the layer has a tile cache.
256 OwnPtr<GraphicsLayer> m_maskLayer; // only used if we have a mask
258 OwnPtr<GraphicsLayer> m_layerForHorizontalScrollbar;
259 OwnPtr<GraphicsLayer> m_layerForVerticalScrollbar;
260 OwnPtr<GraphicsLayer> m_layerForScrollCorner;
262 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
263 OwnPtr<GraphicsLayer> m_scrollingLayer; // only used if the layer is touch-scrollable.
264 OwnPtr<GraphicsLayer> m_scrollingContentsLayer; // only used if the layer is touch-scrollable.
267 IntRect m_compositedBounds;
269 bool m_artificiallyInflatedBounds; // bounds had to be made non-zero to make transform-origin work
270 bool m_isMainFrameRenderViewLayer;
271 bool m_usingTiledCacheLayer;
272 bool m_requiresOwnBackingStore;
273 #if ENABLE(CSS_FILTERS)
274 bool m_canCompositeFilters;
277 static bool m_creatingPrimaryGraphicsLayer;
280 } // namespace WebCore
282 #endif // USE(ACCELERATED_COMPOSITING)
284 #endif // RenderLayerBacking_h