DeviceOrientation.absolute should return false when it was not initialized.
[framework/web/webkit-efl.git] / Source / WebCore / rendering / RenderLayerBacking.h
1 /*
2  * Copyright (C) 2009, 2010, 2011 Apple Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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. 
24  */
25
26 #ifndef RenderLayerBacking_h
27 #define RenderLayerBacking_h
28
29 #if USE(ACCELERATED_COMPOSITING)
30
31 #include "FloatPoint.h"
32 #include "FloatPoint3D.h"
33 #include "GraphicsLayer.h"
34 #include "GraphicsLayerClient.h"
35 #include "RenderLayer.h"
36 #include "TransformationMatrix.h"
37
38 namespace WebCore {
39
40 class KeyframeList;
41 class RenderLayerCompositor;
42
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
48 };
49
50 // RenderLayerBacking controls the compositing behavior for a single RenderLayer.
51 // It holds the various GraphicsLayers, and makes decisions about intra-layer rendering
52 // optimizations.
53 // 
54 // There is one RenderLayerBacking for each RenderLayer that is composited.
55
56 class RenderLayerBacking : public GraphicsLayerClient {
57     WTF_MAKE_NONCOPYABLE(RenderLayerBacking); WTF_MAKE_FAST_ALLOCATED;
58 public:
59     RenderLayerBacking(RenderLayer*);
60     ~RenderLayerBacking();
61
62     RenderLayer* owningLayer() const { return m_owningLayer; }
63
64     enum UpdateDepth { CompositingChildren, AllDescendants };
65     void updateAfterLayout(UpdateDepth, bool isUpdateRoot);
66     
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();
73     
74     GraphicsLayer* graphicsLayer() const { return m_graphicsLayer.get(); }
75
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; }
79
80     // Layer to get clipped by ancestor
81     bool hasAncestorClippingLayer() const { return m_ancestorClippingLayer != 0; }
82     GraphicsLayer* ancestorClippingLayer() const { return m_ancestorClippingLayer.get(); }
83
84     bool hasContentsLayer() const { return m_foregroundLayer != 0; }
85     GraphicsLayer* foregroundLayer() const { return m_foregroundLayer.get(); }
86     
87     bool hasMaskLayer() const { return m_maskLayer != 0; }
88
89 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
90     GraphicsLayer* parentForSublayers() const;
91 #else
92     GraphicsLayer* parentForSublayers() const { return m_containmentLayer ? m_containmentLayer.get() : m_graphicsLayer.get(); }
93 #endif
94     GraphicsLayer* childForSuperlayers() const { return m_ancestorClippingLayer ? m_ancestorClippingLayer.get() : m_graphicsLayer.get(); }
95
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
101     // for some reason.
102     bool paintsIntoWindow() const;
103     
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; }
107
108     void setRequiresOwnBackingStore(bool);
109
110     void setContentsNeedDisplay();
111     // r is in the coordinate space of the layer's render object
112     void setContentsNeedDisplayInRect(const IntRect&);
113
114     // Notification from the renderer that its content changed.
115     void contentChanged(ContentChangeType);
116
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);
121
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);
125
126     void suspendAnimations(double time = 0);
127     void resumeAnimations();
128
129     IntRect compositedBounds() const;
130     void setCompositedBounds(const IntRect&);
131     void updateCompositedBounds();
132     
133     void updateAfterWidgetResize();
134
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*);
140
141     virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& clip);
142
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;
147
148     virtual bool showDebugBorders(const GraphicsLayer*) const;
149     virtual bool showRepaintCounter(const GraphicsLayer*) const;
150
151 #if ENABLE(TIZEN_CSS_OVERFLOW_SCROLL_ACCELERATION)
152     virtual void platformLayerChanged(GraphicsLayer*, PlatformLayer* oldPlatformLayer, PlatformLayer* newPlatformLayer);
153
154     bool hasScrollingLayer() const { return m_scrollingLayer; }
155     GraphicsLayer* scrollingLayer() const { return m_scrollingLayer.get(); }
156     GraphicsLayer* scrollingContentsLayer() const { return m_scrollingContentsLayer.get(); }
157 #endif
158 #ifndef NDEBUG
159     virtual void verifyNotPainting();
160 #endif
161
162     IntRect contentsBox() const;
163     IntRect backgroundBox() const;
164     
165     // For informative purposes only.
166     CompositingLayerType compositingLayerType() const;
167     
168     GraphicsLayer* layerForHorizontalScrollbar() const { return m_layerForHorizontalScrollbar.get(); }
169     GraphicsLayer* layerForVerticalScrollbar() const { return m_layerForVerticalScrollbar.get(); }
170     GraphicsLayer* layerForScrollCorner() const { return m_layerForScrollCorner.get(); }
171
172 #if ENABLE(CSS_FILTERS)
173     bool canCompositeFilters() const { return m_canCompositeFilters; }
174 #endif
175
176     // Return an estimate of the backing store area (in pixels) allocated by this object's GraphicsLayers.
177     double backingStoreMemoryEstimate() const;
178
179     String nameForLayer() const;
180     
181 private:
182     void createPrimaryGraphicsLayer();
183     void destroyGraphicsLayers();
184     
185     PassOwnPtr<GraphicsLayer> createGraphicsLayer(const String&);
186
187     RenderBoxModelObject* renderer() const { return m_owningLayer->renderer(); }
188     RenderLayerCompositor* compositor() const { return m_owningLayer->compositor(); }
189
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);
200 #endif
201     void updateDrawsContent(bool isSimpleContainer);
202
203     GraphicsLayerPaintingPhase paintingPhaseForPrimaryLayer() const;
204     
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;
210
211     void updateLayerOpacity(const RenderStyle*);
212     void updateLayerTransform(const RenderStyle*);
213 #if ENABLE(CSS_FILTERS)
214     void updateLayerFilters(const RenderStyle*);
215 #endif
216
217     // Return the opacity value that this layer should use for compositing.
218     float compositingOpacity(float rendererOpacity) const;
219     
220     bool isMainFrameRenderViewLayer() const;
221     
222     bool paintsBoxDecorations() const;
223     bool paintsChildren() const;
224
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();
232
233     Color rendererBackgroundColor() const;
234     void updateBackgroundColor(bool isSimpleContainer);
235     void updateContentsRect(bool isSimpleContainer);
236
237     bool containsNonEmptyRenderers() const;
238     bool hasVisibleNonCompositingDescendantLayers() const;
239
240     bool shouldClipCompositedBounds() const;
241
242     bool hasTileCacheFlatteningLayer() const { return (m_containmentLayer && m_usingTiledCacheLayer); }
243     GraphicsLayer* tileCacheFlatteningLayer() const { return m_usingTiledCacheLayer ? m_containmentLayer.get() : 0; }
244
245     void paintIntoLayer(RenderLayer* rootLayer, GraphicsContext*, const IntRect& paintDirtyRect, PaintBehavior, GraphicsLayerPaintingPhase, RenderObject* paintingRoot);
246
247     static CSSPropertyID graphicsLayerToCSSProperty(AnimatedPropertyID);
248     static AnimatedPropertyID cssToGraphicsLayerProperty(CSSPropertyID);
249
250     RenderLayer* m_owningLayer;
251
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
257
258     OwnPtr<GraphicsLayer> m_layerForHorizontalScrollbar;
259     OwnPtr<GraphicsLayer> m_layerForVerticalScrollbar;
260     OwnPtr<GraphicsLayer> m_layerForScrollCorner;
261
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.
265 #endif
266
267     IntRect m_compositedBounds;
268
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;
275 #endif
276
277     static bool m_creatingPrimaryGraphicsLayer;
278 };
279
280 } // namespace WebCore
281
282 #endif // USE(ACCELERATED_COMPOSITING)
283
284 #endif // RenderLayerBacking_h