]> git.saurik.com Git - iphone-api.git/blob - WebCore/RenderLayerCompositor.h
Adding the WebCore headers (for Cydget).
[iphone-api.git] / WebCore / RenderLayerCompositor.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 RenderLayerCompositor_h
27 #define RenderLayerCompositor_h
28
29 #include "RenderLayer.h"
30
31 namespace WebCore {
32
33 #define PROFILE_LAYER_REBUILD 0
34
35 class GraphicsLayer;
36
37 // RenderLayerCompositor manages the hierarchy of
38 // composited RenderLayers. It determines which RenderLayers
39 // become compositing, and creates and maintains a hierarchy of
40 // GraphicsLayers based on the RenderLayer painting order.
41 //
42 // There is one RenderLayerCompositor per RenderView.
43
44 class RenderLayerCompositor {
45 public:
46
47 RenderLayerCompositor(RenderView*);
48 ~RenderLayerCompositor();
49
50 // Return true if this RenderView is in "compositing mode" (i.e. has one or more
51 // composited RenderLayers)
52 bool inCompositingMode() const { return m_compositing; }
53 // This will make a compositing layer at the root automatically, and hook up to
54 // the native view/window system.
55 void enableCompositingMode(bool enable = true);
56
57 void setCompositingLayersNeedUpdate(bool needUpdate = true);
58 bool compositingLayersNeedUpdate() const { return m_compositingLayersNeedUpdate; }
59
60 void scheduleViewUpdate();
61
62 // Rebuild the tree of compositing layers
63 void updateCompositingLayers(RenderLayer* updateRoot = 0);
64
65 // Update the compositing state of the given layer. Returns true if that state changed.
66 enum CompositingChangeRepaint { CompositingChangeRepaintNow, CompositingChangeWillRepaintLater };
67 bool updateLayerCompositingState(RenderLayer*, CompositingChangeRepaint = CompositingChangeRepaintNow);
68
69 // Whether layer's backing needs a graphics layer to do clipping by an ancestor (non-stacking-context parent with overflow).
70 bool clippedByAncestor(RenderLayer*) const;
71 // Whether layer's backing needs a graphics layer to clip z-order children of the given layer.
72 bool clipsCompositingDescendants(const RenderLayer*) const;
73
74 // Whether the given layer needs an extra 'contents' layer.
75 bool needsContentsCompositingLayer(const RenderLayer*) const;
76 // Return the bounding box required for compositing layer and its childern, relative to ancestorLayer.
77 // If layerBoundingBox is not 0, on return it contains the bounding box of this layer only.
78 IntRect calculateCompositedBounds(const RenderLayer* layer, const RenderLayer* ancestorLayer, IntRect* layerBoundingBox = 0);
79
80 // Repaint the appropriate layers when the given RenderLayer starts or stops being composited.
81 void repaintOnCompositingChange(RenderLayer*);
82
83 // Notify us that a layer has been added or removed
84 void layerWasAdded(RenderLayer* parent, RenderLayer* child);
85 void layerWillBeRemoved(RenderLayer* parent, RenderLayer* child);
86
87 // Get the nearest ancestor layer that has overflow or clip, but is not a stacking context
88 RenderLayer* enclosingNonStackingClippingLayer(const RenderLayer* layer) const;
89
90 // Repaint parts of all composited layers that intersect the given absolute rectangle.
91 void repaintCompositedLayersAbsoluteRect(const IntRect&);
92
93 RenderLayer* rootRenderLayer() const;
94 GraphicsLayer* rootPlatformLayer() const;
95
96 void didMoveOnscreen();
97 void willMoveOffscreen();
98
99 void updateRootLayerPosition();
100
101 // Walk the tree looking for layers with 3d transforms. Useful in case you need
102 // to know if there is non-affine content, e.g. for drawing into an image.
103 bool has3DContent() const;
104
105 void setDocumentScale(float, RenderLayer* = 0);
106
107 private:
108 // Whether the given RL needs a compositing layer.
109 bool needsToBeComposited(const RenderLayer*) const;
110 // Whether the layer has an intrinsic need for compositing layer.
111 bool requiresCompositingLayer(const RenderLayer*) const;
112
113 // Repaint the given rect (which is layer's coords), and regions of child layers that intersect that rect.
114 void recursiveRepaintLayerRect(RenderLayer* layer, const IntRect& rect);
115
116 void computeCompositingRequirements(RenderLayer*, struct CompositingState&);
117 void rebuildCompositingLayerTree(RenderLayer* layer, struct CompositingState&);
118
119 // Hook compositing layers together
120 void setCompositingParent(RenderLayer* childLayer, RenderLayer* parentLayer);
121 void removeCompositedChildren(RenderLayer*);
122
123 void parentInRootLayer(RenderLayer*);
124
125 bool layerHas3DContent(const RenderLayer*) const;
126
127 void ensureRootPlatformLayer();
128
129 // Whether a running transition or animation enforces the need for a compositing layer.
130 static bool requiresCompositingForAnimation(RenderObject*);
131 static bool requiresCompositingForTransform(RenderObject*);
132
133 private:
134 RenderView* m_renderView;
135 GraphicsLayer* m_rootPlatformLayer;
136 bool m_compositing;
137 bool m_rootLayerAttached;
138 bool m_compositingLayersNeedUpdate;
139 #if PROFILE_LAYER_REBUILD
140 int m_rootLayerUpdateCount;
141 #endif
142 };
143
144
145 } // namespace WebCore
146
147 #endif // RenderLayerCompositor_h