OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright (C) 2009, 2010 Apple Inc. All rights reserved. | |
esprehn
2014/03/01 09:37:07
ditto, shorter copyright
| |
3 * Copyright (C) 2014 Google Inc. All rights reserved. | |
4 * | |
5 * Redistribution and use in source and binary forms, with or without | |
6 * modification, are permitted provided that the following conditions | |
7 * are met: | |
8 * 1. Redistributions of source code must retain the above copyright | |
9 * notice, this list of conditions and the following disclaimer. | |
10 * 2. Redistributions in binary form must reproduce the above copyright | |
11 * notice, this list of conditions and the following disclaimer in the | |
12 * documentation and/or other materials provided with the distribution. | |
13 * | |
14 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY | |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | |
18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | |
19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | |
20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | |
21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | |
22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
25 */ | |
26 | |
27 #include "config.h" | |
28 #include "core/rendering/compositing/GraphicsLayerUpdater.h" | |
29 | |
30 #include "core/rendering/RenderLayer.h" | |
31 #include "core/rendering/RenderLayerReflectionInfo.h" | |
32 #include "core/rendering/RenderPart.h" | |
33 #include "core/rendering/RenderView.h" | |
34 #include "core/rendering/compositing/CompositedLayerMapping.h" | |
35 #include "core/rendering/compositing/RenderLayerCompositor.h" | |
36 #include "public/platform/Platform.h" | |
37 | |
38 namespace WebCore { | |
39 | |
40 GraphicsLayerUpdater::GraphicsLayerUpdater(RenderView& renderView) | |
41 : m_renderView(renderView) | |
42 , m_pixelsWithoutPromotingAllTransitions(0.0) | |
43 , m_pixelsAddedByPromotingAllTransitions(0.0) | |
44 { | |
45 } | |
46 | |
47 GraphicsLayerUpdater::~GraphicsLayerUpdater() | |
48 { | |
49 } | |
50 | |
51 void GraphicsLayerUpdater::rebuildTree(RenderLayer* layer, Vector<GraphicsLayer* >& childLayersOfEnclosingLayer, int depth) | |
esprehn
2014/03/01 09:37:07
Can we pass a RenderLayer& ?
abarth-chromium
2014/03/01 09:40:39
Sure.
| |
52 { | |
53 // Make the layer compositing if necessary, and set up clipping and content layers. | |
54 // Note that we can only do work here that is independent of whether the des cendant layers | |
55 // have been processed. computeCompositingRequirements() will already have d one the repaint if necessary. | |
56 | |
57 layer->stackingNode()->updateLayerListsIfNeeded(); | |
58 layer->update3dRenderingContext(); | |
59 | |
60 const bool hasCompositedLayerMapping = layer->hasCompositedLayerMapping(); | |
61 CompositedLayerMappingPtr currentCompositedLayerMapping = layer->compositedL ayerMapping(); | |
62 | |
63 update(layer); | |
64 | |
65 // Grab some stats for histograms. | |
66 if (hasCompositedLayerMapping) { | |
67 m_pixelsWithoutPromotingAllTransitions += layer->size().height() * layer ->size().width(); | |
68 } else { | |
69 if ((layer->renderer()->style()->transitionForProperty(CSSPropertyOpacit y) || | |
70 layer->renderer()->style()->transitionForProperty(CSSPropertyWebkit Transform)) && | |
71 m_renderView.viewRect().intersects(layer->absoluteBoundingBox())) | |
72 m_pixelsAddedByPromotingAllTransitions += layer->size().height() * l ayer->size().width(); | |
73 } | |
74 | |
75 // If this layer has a compositedLayerMapping, then that is where we place s ubsequent children GraphicsLayers. | |
76 // Otherwise children continue to append to the child list of the enclosing layer. | |
77 Vector<GraphicsLayer*> layerChildren; | |
78 Vector<GraphicsLayer*>& childList = hasCompositedLayerMapping ? layerChildre n : childLayersOfEnclosingLayer; | |
79 | |
80 #if !ASSERT_DISABLED | |
81 LayerListMutationDetector mutationChecker(layer->stackingNode()); | |
82 #endif | |
83 | |
84 if (layer->stackingNode()->isStackingContainer()) { | |
85 RenderLayerStackingNodeIterator iterator(*layer->stackingNode(), Negativ eZOrderChildren); | |
86 while (RenderLayerStackingNode* curNode = iterator.next()) | |
87 rebuildTree(curNode->layer(), childList, depth + 1); | |
88 | |
89 // If a negative z-order child is compositing, we get a foreground layer which needs to get parented. | |
90 if (hasCompositedLayerMapping && currentCompositedLayerMapping->foregrou ndLayer()) | |
91 childList.append(currentCompositedLayerMapping->foregroundLayer()); | |
92 } | |
93 | |
94 RenderLayerStackingNodeIterator iterator(*layer->stackingNode(), NormalFlowC hildren | PositiveZOrderChildren); | |
95 while (RenderLayerStackingNode* curNode = iterator.next()) | |
96 rebuildTree(curNode->layer(), childList, depth + 1); | |
97 | |
98 if (hasCompositedLayerMapping) { | |
99 bool parented = false; | |
100 if (layer->renderer()->isRenderPart()) | |
101 parented = parentFrameContentLayers(toRenderPart(layer->renderer())) ; | |
102 | |
103 if (!parented) | |
104 currentCompositedLayerMapping->parentForSublayers()->setChildren(lay erChildren); | |
105 | |
106 // If the layer has a clipping layer the overflow controls layers will b e siblings of the clipping layer. | |
107 // Otherwise, the overflow control layers are normal children. | |
108 if (!currentCompositedLayerMapping->hasClippingLayer() && !currentCompos itedLayerMapping->hasScrollingLayer()) { | |
109 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapp ing->layerForHorizontalScrollbar()) { | |
110 overflowControlLayer->removeFromParent(); | |
111 currentCompositedLayerMapping->parentForSublayers()->addChild(ov erflowControlLayer); | |
112 } | |
113 | |
114 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapp ing->layerForVerticalScrollbar()) { | |
115 overflowControlLayer->removeFromParent(); | |
116 currentCompositedLayerMapping->parentForSublayers()->addChild(ov erflowControlLayer); | |
117 } | |
118 | |
119 if (GraphicsLayer* overflowControlLayer = currentCompositedLayerMapp ing->layerForScrollCorner()) { | |
120 overflowControlLayer->removeFromParent(); | |
121 currentCompositedLayerMapping->parentForSublayers()->addChild(ov erflowControlLayer); | |
122 } | |
123 } | |
124 | |
125 childLayersOfEnclosingLayer.append(currentCompositedLayerMapping->childF orSuperlayers()); | |
126 } | |
127 | |
128 if (!depth) { | |
129 int percentageIncreaseInPixels = static_cast<int>(m_pixelsAddedByPromoti ngAllTransitions / m_pixelsWithoutPromotingAllTransitions * 100); | |
130 blink::Platform::current()->histogramCustomCounts("Renderer.PixelIncreas eFromTransitions", percentageIncreaseInPixels, 0, 1000, 50); | |
131 } | |
132 } | |
133 | |
134 // This just updates layer geometry without changing the hierarchy. | |
135 void GraphicsLayerUpdater::updateRecursive(RenderLayer* layer) | |
esprehn
2014/03/01 09:37:07
same
| |
136 { | |
137 update(layer); | |
138 | |
139 #if !ASSERT_DISABLED | |
140 LayerListMutationDetector mutationChecker(layer->stackingNode()); | |
141 #endif | |
142 | |
143 RenderLayerStackingNodeIterator iterator(*layer->stackingNode(), AllChildren ); | |
144 while (RenderLayerStackingNode* curNode = iterator.next()) | |
145 updateRecursive(curNode->layer()); | |
146 } | |
147 | |
148 void GraphicsLayerUpdater::update(RenderLayer* layer) | |
149 { | |
150 if (!layer->hasCompositedLayerMapping()) | |
151 return; | |
152 | |
153 CompositedLayerMappingPtr mapping = layer->compositedLayerMapping(); | |
154 | |
155 // Note carefully: here we assume that the compositing state of all descenda nts have been updated already, | |
156 // so it is legitimate to compute and cache the composited bounds for this l ayer. | |
157 mapping->updateCompositedBounds(); | |
158 | |
159 if (RenderLayerReflectionInfo* reflection = layer->reflectionInfo()) { | |
160 if (reflection->reflectionLayer()->hasCompositedLayerMapping()) | |
161 reflection->reflectionLayer()->compositedLayerMapping()->updateCompo sitedBounds(); | |
162 } | |
163 | |
164 mapping->updateGraphicsLayerConfiguration(); | |
165 mapping->updateGraphicsLayerGeometry(); | |
166 | |
167 if (!layer->parent()) | |
168 layer->compositor()->updateRootLayerPosition(); | |
169 | |
170 if (mapping->hasUnpositionedOverflowControlsLayers()) | |
171 layer->scrollableArea()->positionOverflowControls(); | |
172 } | |
173 | |
174 bool GraphicsLayerUpdater::parentFrameContentLayers(RenderPart* renderer) | |
esprehn
2014/03/01 09:37:07
This should have a verb name. parentFrameContentLa
abarth-chromium
2014/03/01 09:40:39
I haven't figured that out yet.
| |
175 { | |
176 RenderLayerCompositor* innerCompositor = RenderLayerCompositor::frameContent sCompositor(renderer); | |
177 if (!innerCompositor || !innerCompositor->inCompositingMode() || innerCompos itor->rootLayerAttachment() != RenderLayerCompositor::RootLayerAttachedViaEnclos ingFrame) | |
178 return false; | |
179 | |
180 RenderLayer* layer = renderer->layer(); | |
181 if (!layer->hasCompositedLayerMapping()) | |
182 return false; | |
183 | |
184 CompositedLayerMappingPtr compositedLayerMapping = layer->compositedLayerMap ping(); | |
185 GraphicsLayer* hostingLayer = compositedLayerMapping->parentForSublayers(); | |
186 GraphicsLayer* rootLayer = innerCompositor->rootGraphicsLayer(); | |
187 if (hostingLayer->children().size() != 1 || hostingLayer->children()[0] != r ootLayer) { | |
188 hostingLayer->removeAllChildren(); | |
189 hostingLayer->addChild(rootLayer); | |
190 } | |
191 return true; | |
192 } | |
193 | |
194 | |
195 } // namespace WebCore | |
OLD | NEW |