]> git.saurik.com Git - iphone-api.git/blob - WebCore/RenderLayerBacking.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / RenderLayerBacking.h
1 /*
2 * Copyright (C) 2009 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 // RenderLayerBacking controls the compositing behavior for a single RenderLayer.
44 // It holds the various GraphicsLayers, and makes decisions about intra-layer rendering
45 // optimizations.
46 //
47 // There is one RenderLayerBacking for each RenderLayer that is composited.
48
49 class RenderLayerBacking : public GraphicsLayerClient {
50 public:
51 RenderLayerBacking(RenderLayer*);
52 ~RenderLayerBacking();
53
54 RenderLayer* owningLayer() const { return m_owningLayer; }
55
56 void updateAfterLayout();
57
58 // Returns true if layer configuration changed.
59 bool updateGraphicsLayerConfiguration();
60 void updateGraphicsLayerGeometry();
61 void updateInternalHierarchy();
62
63 GraphicsLayer* graphicsLayer() const { return m_graphicsLayer; }
64
65 // Layer to clip children
66 bool hasClippingLayer() const { return m_clippingLayer != 0; }
67 GraphicsLayer* clippingLayer() const { return m_clippingLayer; }
68
69 // Layer to get clipped by ancestor
70 bool hasAncestorClippingLayer() const { return m_ancestorClippingLayer != 0; }
71 GraphicsLayer* ancestorClippingLayer() const { return m_ancestorClippingLayer; }
72
73 bool hasContentsLayer() const { return m_contentsLayer != 0; }
74 GraphicsLayer* contentsLayer() const { return m_contentsLayer; }
75
76 GraphicsLayer* parentForSublayers() const { return m_clippingLayer ? m_clippingLayer : m_graphicsLayer; }
77 GraphicsLayer* childForSuperlayers() const { return m_ancestorClippingLayer ? m_ancestorClippingLayer : m_graphicsLayer; }
78
79 // RenderLayers with backing normally short-circuit paintLayer() because
80 // their content is rendered via callbacks from GraphicsLayer. However, the document
81 // layer is special, because it has a GraphicsLayer to act as a container for the GraphicsLayers
82 // for descendants, but its contents usually render into the window (in which case this returns true).
83 // This returns false for other layers, and when the document layer actually needs to paint into its backing store
84 // for some reason.
85 bool paintingGoesToWindow() const;
86
87 void setContentsNeedDisplay();
88 // r is in the coordinate space of the layer's render object
89 void setContentsNeedDisplayInRect(const IntRect& r);
90
91 // Notification from the renderer that its content changed; used by RenderImage.
92 void rendererContentChanged();
93
94 // Interface to start, finish, suspend and resume animations and transitions
95 bool startAnimation(double beginTime, const Animation* anim, const KeyframeList& keyframes);
96 bool startTransition(double beginTime, int property, const RenderStyle* fromStyle, const RenderStyle* toStyle);
97 void animationFinished(const String& name, int index, bool reset);
98 void transitionFinished(int property);
99
100 void suspendAnimations();
101 void resumeAnimations();
102
103 FloatPoint graphicsLayerToContentsCoordinates(const GraphicsLayer*, const FloatPoint&);
104 FloatPoint contentsToGraphicsLayerCoordinates(const GraphicsLayer*, const FloatPoint&);
105
106 // GraphicsLayerClient interface
107 virtual void notifyAnimationStarted(const GraphicsLayer*, double startTime);
108
109 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsLayerPaintingPhase, const IntRect& clip);
110
111 virtual IntRect contentsBox(const GraphicsLayer*);
112
113 void setDocumentScale(float scale);
114
115 private:
116 void createGraphicsLayer();
117 void destroyGraphicsLayer();
118
119 RenderBox* renderer() const { return m_owningLayer->renderer(); }
120 RenderLayerCompositor* compositor() const { return m_owningLayer->compositor(); }
121
122 bool updateClippingLayers(bool needsAncestorClip, bool needsDescendantClip);
123 bool updateContentsLayer(bool needsContentsLayer);
124
125 IntSize contentOffsetInCompostingLayer();
126 // Result is transform origin in pixels.
127 FloatPoint3D computeTransformOrigin(const IntRect& borderBox) const;
128 // Result is perspective origin in pixels.
129 FloatPoint computePerspectiveOrigin(const IntRect& borderBox) const;
130
131 void updateLayerOpacity();
132 void updateLayerTransform();
133
134 // Return the opacity value that this layer should use for compositing.
135 float compositingOpacity(float rendererOpacity) const;
136
137 // Returns true if this RenderLayer only has content that can be rendered directly
138 // by the compositing layer, without drawing (e.g. solid background color).
139 bool isSimpleContainerCompositingLayer() const;
140 // Returns true if we can optimize the RenderLayer to draw the replaced content
141 // directly into a compositing buffer
142 bool canUseDirectCompositing() const;
143 void updateImageContents();
144
145 bool rendererHasBackground() const;
146 const Color& rendererBackgroundColor() const;
147
148 bool hasNonCompositingContent() const;
149
150 void paintIntoLayer(RenderLayer* rootLayer, GraphicsContext*, const IntRect& paintDirtyRect,
151 bool haveTransparency, PaintRestriction paintRestriction, GraphicsLayerPaintingPhase, RenderObject* paintingRoot);
152
153 static int graphicsLayerToCSSProperty(AnimatedPropertyID);
154 static AnimatedPropertyID cssToGraphicsLayerProperty(int);
155
156 private:
157 RenderLayer* m_owningLayer;
158
159 GraphicsLayer* m_ancestorClippingLayer; // only used if we are clipped by an ancestor which is not a stacking context
160 GraphicsLayer* m_graphicsLayer;
161 GraphicsLayer* m_contentsLayer; // only used in cases where we need to draw the foreground separately
162 GraphicsLayer* m_clippingLayer; // only used if we have clipping on a stacking context, with compositing children
163
164 IntSize m_compositingContentOffset;
165
166 bool m_hasDirectlyCompositedContent: 1;
167 bool m_compositingContentOffsetDirty: 1;
168 };
169
170 } // namespace WebCore
171
172 #endif // USE(ACCELERATED_COMPOSITING)
173
174 #endif // RenderLayerBacking_h