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_clippingLayer != 0; }
78 GraphicsLayer* clippingLayer() const { return m_clippingLayer.get(); }
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 GraphicsLayer* parentForSublayers() const { return m_clippingLayer ? m_clippingLayer.get() : m_graphicsLayer.get(); }
90 GraphicsLayer* childForSuperlayers() const { return m_ancestorClippingLayer ? m_ancestorClippingLayer.get() : m_graphicsLayer.get(); }
92 // RenderLayers with backing normally short-circuit paintLayer() because
93 // their content is rendered via callbacks from GraphicsLayer. However, the document
94 // layer is special, because it has a GraphicsLayer to act as a container for the GraphicsLayers
95 // for descendants, but its contents usually render into the window (in which case this returns true).
96 // This returns false for other layers, and when the document layer actually needs to paint into its backing store
98 bool paintingGoesToWindow() const;
100 void setContentsNeedDisplay();
101 // r is in the coordinate space of the layer's render object
102 void setContentsNeedDisplayInRect(const LayoutRect&);
104 // Notification from the renderer that its content changed.
105 void contentChanged(RenderLayer::ContentChangeType);
107 // Interface to start, finish, suspend and resume animations and transitions
108 bool startTransition(double timeOffset, int property, const RenderStyle* fromStyle, const RenderStyle* toStyle);
109 void transitionPaused(double timeOffset, int property);
110 void transitionFinished(int property);
112 bool startAnimation(double timeOffset, const Animation* anim, const KeyframeList& keyframes);
113 void animationPaused(double timeOffset, const String& name);
114 void animationFinished(const String& name);
116 void suspendAnimations(double time = 0);
117 void resumeAnimations();
119 LayoutRect compositedBounds() const;
120 void setCompositedBounds(const LayoutRect&);
121 void updateCompositedBounds();
123 void updateAfterWidgetResize();
125 // GraphicsLayerClient interface
126 virtual void notifyAnimationStarted(const GraphicsLayer*, double startTime);
127 virtual void notifySyncRequired(const GraphicsLayer*);
129 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const LayoutRect& clip);
131 virtual float deviceScaleFactor() const;
132 virtual float pageScaleFactor() const;
133 virtual void didCommitChangesForLayer(const GraphicsLayer*) const;
135 virtual bool showDebugBorders() const;
136 virtual bool showRepaintCounter() const;
138 LayoutRect contentsBox() const;
140 // For informative purposes only.
141 CompositingLayerType compositingLayerType() const;
143 GraphicsLayer* layerForHorizontalScrollbar() const { return m_layerForHorizontalScrollbar.get(); }
144 GraphicsLayer* layerForVerticalScrollbar() const { return m_layerForVerticalScrollbar.get(); }
145 GraphicsLayer* layerForScrollCorner() const { return m_layerForScrollCorner.get(); }
148 void createPrimaryGraphicsLayer();
149 void destroyGraphicsLayers();
151 PassOwnPtr<GraphicsLayer> createGraphicsLayer(const String&);
153 RenderBoxModelObject* renderer() const { return m_owningLayer->renderer(); }
154 RenderLayerCompositor* compositor() const { return m_owningLayer->compositor(); }
156 void updateInternalHierarchy();
157 bool updateClippingLayers(bool needsAncestorClip, bool needsDescendantClip);
158 bool updateOverflowControlsLayers(bool needsHorizontalScrollbarLayer, bool needsVerticalScrollbarLayer, bool needsScrollCornerLayer);
159 bool updateForegroundLayer(bool needsForegroundLayer);
160 bool updateMaskLayer(bool needsMaskLayer);
161 bool requiresHorizontalScrollbarLayer() const;
162 bool requiresVerticalScrollbarLayer() const;
163 bool requiresScrollCornerLayer() const;
165 GraphicsLayerPaintingPhase paintingPhaseForPrimaryLayer() const;
167 LayoutSize contentOffsetInCompostingLayer() const;
168 // Result is transform origin in pixels.
169 FloatPoint3D computeTransformOrigin(const LayoutRect& borderBox) const;
170 // Result is perspective origin in pixels.
171 FloatPoint computePerspectiveOrigin(const LayoutRect& borderBox) const;
173 void updateLayerOpacity(const RenderStyle*);
174 void updateLayerTransform(const RenderStyle*);
176 // Return the opacity value that this layer should use for compositing.
177 float compositingOpacity(float rendererOpacity) const;
179 // Returns true if this compositing layer has no visible content.
180 bool isSimpleContainerCompositingLayer() const;
181 // Returns true if this layer has content that needs to be rendered by painting into the backing store.
182 bool containsPaintedContent() const;
183 // Returns true if the RenderLayer just contains an image that we can composite directly.
184 bool isDirectlyCompositedImage() const;
185 void updateImageContents();
187 bool rendererHasBackground() const;
188 const Color rendererBackgroundColor() const;
189 void updateBackgroundColor();
191 bool hasNonCompositingDescendants() const;
193 void paintIntoLayer(RenderLayer* rootLayer, GraphicsContext*, const LayoutRect& paintDirtyRect, PaintBehavior, GraphicsLayerPaintingPhase, RenderObject* paintingRoot);
195 static int graphicsLayerToCSSProperty(AnimatedPropertyID);
196 static AnimatedPropertyID cssToGraphicsLayerProperty(int);
199 String nameForLayer() const;
202 RenderLayer* m_owningLayer;
204 OwnPtr<GraphicsLayer> m_ancestorClippingLayer; // only used if we are clipped by an ancestor which is not a stacking context
205 OwnPtr<GraphicsLayer> m_graphicsLayer;
206 OwnPtr<GraphicsLayer> m_foregroundLayer; // only used in cases where we need to draw the foreground separately
207 OwnPtr<GraphicsLayer> m_clippingLayer; // only used if we have clipping on a stacking context, with compositing children
208 OwnPtr<GraphicsLayer> m_maskLayer; // only used if we have a mask
210 OwnPtr<GraphicsLayer> m_layerForHorizontalScrollbar;
211 OwnPtr<GraphicsLayer> m_layerForVerticalScrollbar;
212 OwnPtr<GraphicsLayer> m_layerForScrollCorner;
214 LayoutRect m_compositedBounds;
216 bool m_artificiallyInflatedBounds; // bounds had to be made non-zero to make transform-origin work
219 } // namespace WebCore
221 #endif // USE(ACCELERATED_COMPOSITING)
223 #endif // RenderLayerBacking_h