OLD | NEW |
| (Empty) |
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 "core/layout/compositing/CompositingReasonFinder.h" | |
30 #include "core/rendering/RenderLayer.h" | |
31 #include "platform/graphics/GraphicsLayerClient.h" | |
32 #include "wtf/HashMap.h" | |
33 | |
34 namespace blink { | |
35 | |
36 class DocumentLifecycle; | |
37 class GraphicsLayer; | |
38 class GraphicsLayerFactory; | |
39 class Page; | |
40 class RenderPart; | |
41 class ScrollingCoordinator; | |
42 | |
43 enum CompositingUpdateType { | |
44 CompositingUpdateNone, | |
45 CompositingUpdateAfterGeometryChange, | |
46 CompositingUpdateAfterCompositingInputChange, | |
47 CompositingUpdateRebuildTree, | |
48 }; | |
49 | |
50 enum CompositingStateTransitionType { | |
51 NoCompositingStateChange, | |
52 AllocateOwnCompositedLayerMapping, | |
53 RemoveOwnCompositedLayerMapping, | |
54 PutInSquashingLayer, | |
55 RemoveFromSquashingLayer | |
56 }; | |
57 | |
58 // RenderLayerCompositor manages the hierarchy of | |
59 // composited RenderLayers. It determines which RenderLayers | |
60 // become compositing, and creates and maintains a hierarchy of | |
61 // GraphicsLayers based on the RenderLayer painting order. | |
62 // | |
63 // There is one RenderLayerCompositor per RenderView. | |
64 | |
65 class RenderLayerCompositor final : public GraphicsLayerClient { | |
66 WTF_MAKE_FAST_ALLOCATED; | |
67 public: | |
68 explicit RenderLayerCompositor(RenderView&); | |
69 virtual ~RenderLayerCompositor(); | |
70 | |
71 void updateIfNeededRecursive(); | |
72 | |
73 // Return true if this RenderView is in "compositing mode" (i.e. has one or
more | |
74 // composited RenderLayers) | |
75 bool inCompositingMode() const; | |
76 // FIXME: Replace all callers with inCompositingMode and remove this functio
n. | |
77 bool staleInCompositingMode() const; | |
78 // This will make a compositing layer at the root automatically, and hook up
to | |
79 // the native view/window system. | |
80 void setCompositingModeEnabled(bool); | |
81 | |
82 // Returns true if the accelerated compositing is enabled | |
83 bool hasAcceleratedCompositing() const { return m_hasAcceleratedCompositing;
} | |
84 | |
85 bool preferCompositingToLCDTextEnabled() const; | |
86 | |
87 bool rootShouldAlwaysComposite() const; | |
88 | |
89 // Copy the accelerated compositing related flags from Settings | |
90 void updateAcceleratedCompositingSettings(); | |
91 | |
92 // Used to indicate that a compositing update will be needed for the next fr
ame that gets drawn. | |
93 void setNeedsCompositingUpdate(CompositingUpdateType); | |
94 | |
95 void didLayout(); | |
96 | |
97 // Whether layer's compositedLayerMapping needs a GraphicsLayer to clip z-or
der children of the given RenderLayer. | |
98 bool clipsCompositingDescendants(const RenderLayer*) const; | |
99 | |
100 // Whether the given layer needs an extra 'contents' layer. | |
101 bool needsContentsCompositingLayer(const RenderLayer*) const; | |
102 | |
103 bool supportsFixedRootBackgroundCompositing() const; | |
104 bool needsFixedRootBackgroundLayer(const RenderLayer*) const; | |
105 GraphicsLayer* fixedRootBackgroundLayer() const; | |
106 void setNeedsUpdateFixedBackground() { m_needsUpdateFixedBackground = true;
} | |
107 | |
108 // Issue paint invalidations of the appropriate layers when the given Render
Layer starts or stops being composited. | |
109 void paintInvalidationOnCompositingChange(RenderLayer*); | |
110 | |
111 void fullyInvalidatePaint(); | |
112 | |
113 RenderLayer* rootRenderLayer() const; | |
114 GraphicsLayer* rootGraphicsLayer() const; | |
115 GraphicsLayer* frameScrollLayer() const; | |
116 GraphicsLayer* scrollLayer() const; | |
117 GraphicsLayer* containerLayer() const; | |
118 | |
119 // We don't always have a root transform layer. This function lazily allocat
es one | |
120 // and returns it as required. | |
121 GraphicsLayer* ensureRootTransformLayer(); | |
122 | |
123 enum RootLayerAttachment { | |
124 RootLayerUnattached, | |
125 RootLayerAttachedViaChromeClient, | |
126 RootLayerAttachedViaEnclosingFrame | |
127 }; | |
128 | |
129 RootLayerAttachment rootLayerAttachment() const { return m_rootLayerAttachme
nt; } | |
130 void updateRootLayerAttachment(); | |
131 void updateRootLayerPosition(); | |
132 | |
133 void setIsInWindow(bool); | |
134 | |
135 static RenderLayerCompositor* frameContentsCompositor(RenderPart*); | |
136 // Return true if the layers changed. | |
137 static bool parentFrameContentLayers(RenderPart*); | |
138 | |
139 // Update the geometry of the layers used for clipping and scrolling in fram
es. | |
140 void frameViewDidChangeLocation(const IntPoint& contentsOffset); | |
141 void frameViewDidChangeSize(); | |
142 void frameViewDidScroll(); | |
143 void frameViewScrollbarsExistenceDidChange(); | |
144 void rootFixedBackgroundsChanged(); | |
145 | |
146 bool scrollingLayerDidChange(RenderLayer*); | |
147 | |
148 String layerTreeAsText(LayerTreeFlags); | |
149 | |
150 GraphicsLayer* layerForHorizontalScrollbar() const { return m_layerForHorizo
ntalScrollbar.get(); } | |
151 GraphicsLayer* layerForVerticalScrollbar() const { return m_layerForVertical
Scrollbar.get(); } | |
152 GraphicsLayer* layerForScrollCorner() const { return m_layerForScrollCorner.
get(); } | |
153 | |
154 void resetTrackedPaintInvalidationRects(); | |
155 void setTracksPaintInvalidations(bool); | |
156 | |
157 virtual String debugName(const GraphicsLayer*) override; | |
158 DocumentLifecycle& lifecycle() const; | |
159 | |
160 void updatePotentialCompositingReasonsFromStyle(RenderLayer*); | |
161 | |
162 // Whether the layer could ever be composited. | |
163 bool canBeComposited(const RenderLayer*) const; | |
164 | |
165 // FIXME: Move allocateOrClearCompositedLayerMapping to CompositingLayerAssi
gner once we've fixed | |
166 // the compositing chicken/egg issues. | |
167 bool allocateOrClearCompositedLayerMapping(RenderLayer*, CompositingStateTra
nsitionType compositedLayerUpdate); | |
168 | |
169 void updateDirectCompositingReasons(RenderLayer*); | |
170 | |
171 void setOverlayLayer(GraphicsLayer*); | |
172 | |
173 bool inOverlayFullscreenVideo() const { return m_inOverlayFullscreenVideo; } | |
174 | |
175 private: | |
176 #if ENABLE(ASSERT) | |
177 void assertNoUnresolvedDirtyBits(); | |
178 #endif | |
179 | |
180 // GraphicsLayerClient implementation | |
181 virtual void paintContents(const GraphicsLayer*, GraphicsContext&, GraphicsL
ayerPaintingPhase, const IntRect&) override; | |
182 | |
183 virtual bool isTrackingPaintInvalidations() const override; | |
184 | |
185 void updateWithoutAcceleratedCompositing(CompositingUpdateType); | |
186 void updateIfNeeded(); | |
187 | |
188 void ensureRootLayer(); | |
189 void destroyRootLayer(); | |
190 | |
191 void attachRootLayer(RootLayerAttachment); | |
192 void detachRootLayer(); | |
193 | |
194 void updateOverflowControlsLayers(); | |
195 | |
196 Page* page() const; | |
197 | |
198 GraphicsLayerFactory* graphicsLayerFactory() const; | |
199 ScrollingCoordinator* scrollingCoordinator() const; | |
200 | |
201 void enableCompositingModeIfNeeded(); | |
202 | |
203 bool requiresHorizontalScrollbarLayer() const; | |
204 bool requiresVerticalScrollbarLayer() const; | |
205 bool requiresScrollCornerLayer() const; | |
206 | |
207 void applyOverlayFullscreenVideoAdjustment(); | |
208 | |
209 RenderView& m_renderView; | |
210 OwnPtr<GraphicsLayer> m_rootContentLayer; | |
211 OwnPtr<GraphicsLayer> m_rootTransformLayer; | |
212 | |
213 CompositingReasonFinder m_compositingReasonFinder; | |
214 | |
215 CompositingUpdateType m_pendingUpdateType; | |
216 | |
217 bool m_hasAcceleratedCompositing; | |
218 bool m_compositing; | |
219 | |
220 // The root layer doesn't composite if it's a non-scrollable frame. | |
221 // So, after a layout we set this dirty bit to know that we need | |
222 // to recompute whether the root layer should composite even if | |
223 // none of its descendants composite. | |
224 // FIXME: Get rid of all the callers of setCompositingModeEnabled | |
225 // except the one in updateIfNeeded, then rename this to | |
226 // m_compositingDirty. | |
227 bool m_rootShouldAlwaysCompositeDirty; | |
228 bool m_needsUpdateFixedBackground; | |
229 bool m_isTrackingPaintInvalidations; // Used for testing. | |
230 | |
231 RootLayerAttachment m_rootLayerAttachment; | |
232 | |
233 // Enclosing container layer, which clips for iframe content | |
234 OwnPtr<GraphicsLayer> m_containerLayer; | |
235 OwnPtr<GraphicsLayer> m_scrollLayer; | |
236 | |
237 // Enclosing layer for overflow controls and the clipping layer | |
238 OwnPtr<GraphicsLayer> m_overflowControlsHostLayer; | |
239 | |
240 // Layers for overflow controls | |
241 OwnPtr<GraphicsLayer> m_layerForHorizontalScrollbar; | |
242 OwnPtr<GraphicsLayer> m_layerForVerticalScrollbar; | |
243 OwnPtr<GraphicsLayer> m_layerForScrollCorner; | |
244 | |
245 bool m_inOverlayFullscreenVideo; | |
246 }; | |
247 | |
248 } // namespace blink | |
249 | |
250 #endif // RenderLayerCompositor_h | |
OLD | NEW |