OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2012 Apple Inc. All rights reserved. | 2 * Copyright (C) 2012 Apple Inc. All rights reserved. |
3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions are | 6 * modification, are permitted provided that the following conditions are |
7 * met: | 7 * met: |
8 * | 8 * |
9 * * Redistributions of source code must retain the above copyright | 9 * * Redistributions of source code must retain the above copyright |
10 * notice, this list of conditions and the following disclaimer. | 10 * notice, this list of conditions and the following disclaimer. |
(...skipping 28 matching lines...) Expand all Loading... | |
39 #include "core/inspector/InspectorState.h" | 39 #include "core/inspector/InspectorState.h" |
40 #include "core/inspector/InstrumentingAgents.h" | 40 #include "core/inspector/InstrumentingAgents.h" |
41 #include "core/loader/DocumentLoader.h" | 41 #include "core/loader/DocumentLoader.h" |
42 #include "core/page/Page.h" | 42 #include "core/page/Page.h" |
43 #include "core/platform/graphics/IntRect.h" | 43 #include "core/platform/graphics/IntRect.h" |
44 #include "core/platform/graphics/transforms/TransformationMatrix.h" | 44 #include "core/platform/graphics/transforms/TransformationMatrix.h" |
45 #include "core/rendering/RenderLayer.h" | 45 #include "core/rendering/RenderLayer.h" |
46 #include "core/rendering/RenderLayerBacking.h" | 46 #include "core/rendering/RenderLayerBacking.h" |
47 #include "core/rendering/RenderLayerCompositor.h" | 47 #include "core/rendering/RenderLayerCompositor.h" |
48 #include "core/rendering/RenderView.h" | 48 #include "core/rendering/RenderView.h" |
49 #include "public/platform/WebCompositingReasons.h" | |
49 #include "public/platform/WebLayer.h" | 50 #include "public/platform/WebLayer.h" |
50 | 51 |
51 namespace WebCore { | 52 namespace WebCore { |
52 | 53 |
53 namespace LayerTreeAgentState { | 54 namespace LayerTreeAgentState { |
54 static const char layerTreeAgentEnabled[] = "layerTreeAgentEnabled"; | 55 static const char layerTreeAgentEnabled[] = "layerTreeAgentEnabled"; |
55 }; | 56 }; |
56 | 57 |
57 static PassRefPtr<TypeBuilder::LayerTree::Layer> buildObjectForLayer(GraphicsLay er* graphicsLayer, int nodeId, bool forceRoot) | 58 static PassRefPtr<TypeBuilder::LayerTree::Layer> buildObjectForLayer(GraphicsLay er* graphicsLayer, int nodeId, bool forceRoot) |
58 { | 59 { |
59 RefPtr<TypeBuilder::LayerTree::Layer> layerObject = TypeBuilder::LayerTree:: Layer::create() | 60 RefPtr<TypeBuilder::LayerTree::Layer> layerObject = TypeBuilder::LayerTree:: Layer::create() |
60 .setLayerId(String::number(graphicsLayer->platformLayer()->id())) | 61 .setLayerId(String::number(graphicsLayer->platformLayer()->id())) |
61 .setNodeId(nodeId) | 62 .setNodeId(nodeId) |
62 .setOffsetX(graphicsLayer->position().x()) | 63 .setOffsetX(graphicsLayer->position().x()) |
63 .setOffsetY(graphicsLayer->position().y()) | 64 .setOffsetY(graphicsLayer->position().y()) |
64 .setWidth(graphicsLayer->size().width()) | 65 .setWidth(graphicsLayer->size().width()) |
65 .setHeight(graphicsLayer->size().height()) | 66 .setHeight(graphicsLayer->size().height()) |
66 .setPaintCount(graphicsLayer->repaintCount()); | 67 .setPaintCount(graphicsLayer->paintCount()); |
67 | 68 |
68 // Artificially clip tree at root renger layer's graphic layer -- it might b e not the real | 69 // Artificially clip tree at root renger layer's graphic layer -- it might b e not the real |
69 // root of graphics layer hierarchy, as platform adds containing layers (e.g . for overflosw scroll). | 70 // root of graphics layer hierarchy, as platform adds containing layers (e.g . for overflosw scroll). |
trchen
2013/08/22 23:02:35
I knew you didn't add this, but this comment is fu
| |
70 if (graphicsLayer->parent() && !forceRoot) | 71 if (!forceRoot) { |
71 layerObject->setParentLayerId(String::number(graphicsLayer->parent()->pl atformLayer()->id())); | 72 GraphicsLayer* parent = graphicsLayer->parent(); |
72 | 73 if (!parent) |
74 parent = graphicsLayer->replicatedLayer(); | |
75 if (parent) | |
76 layerObject->setParentLayerId(String::number(parent->platformLayer() ->id())); | |
77 } | |
73 const TransformationMatrix& transform = graphicsLayer->transform(); | 78 const TransformationMatrix& transform = graphicsLayer->transform(); |
74 if (!transform.isIdentity()) { | 79 if (!transform.isIdentity()) { |
75 TransformationMatrix::FloatMatrix4 flattenedMatrix; | 80 TransformationMatrix::FloatMatrix4 flattenedMatrix; |
76 transform.toColumnMajorFloatArray(flattenedMatrix); | 81 transform.toColumnMajorFloatArray(flattenedMatrix); |
77 RefPtr<TypeBuilder::Array<double> > transformArray = TypeBuilder::Array< double>::create(); | 82 RefPtr<TypeBuilder::Array<double> > transformArray = TypeBuilder::Array< double>::create(); |
78 for (size_t i = 0; i < WTF_ARRAY_LENGTH(flattenedMatrix); ++i) | 83 for (size_t i = 0; i < WTF_ARRAY_LENGTH(flattenedMatrix); ++i) |
79 transformArray->addItem(flattenedMatrix[i]); | 84 transformArray->addItem(flattenedMatrix[i]); |
80 layerObject->setTransform(transformArray); | 85 layerObject->setTransform(transformArray); |
81 const FloatPoint3D& anchor = graphicsLayer->anchorPoint(); | 86 const FloatPoint3D& anchor = graphicsLayer->anchorPoint(); |
82 layerObject->setAnchorX(anchor.x()); | 87 layerObject->setAnchorX(anchor.x()); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 149 |
145 void InspectorLayerTreeAgent::layerTreeDidChange() | 150 void InspectorLayerTreeAgent::layerTreeDidChange() |
146 { | 151 { |
147 m_frontend->layerTreeDidChange(); | 152 m_frontend->layerTreeDidChange(); |
148 } | 153 } |
149 | 154 |
150 void InspectorLayerTreeAgent::getLayers(ErrorString* errorString, const int* nod eId, RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> >& layers) | 155 void InspectorLayerTreeAgent::getLayers(ErrorString* errorString, const int* nod eId, RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> >& layers) |
151 { | 156 { |
152 layers = TypeBuilder::Array<TypeBuilder::LayerTree::Layer>::create(); | 157 layers = TypeBuilder::Array<TypeBuilder::LayerTree::Layer>::create(); |
153 | 158 |
154 RenderView* renderView = m_page->mainFrame()->contentRenderer(); | 159 RenderLayerCompositor* compositor = renderLayerCompositor(errorString); |
155 RenderLayerCompositor* compositor = renderView ? renderView->compositor() : 0; | |
156 if (!compositor) { | 160 if (!compositor) { |
157 *errorString = "Not in compositing mode"; | 161 *errorString = "Not in compositing mode"; |
trchen
2013/08/22 23:02:35
errorString is already set.
| |
158 return; | 162 return; |
159 } | 163 } |
160 if (!nodeId) { | 164 if (!nodeId) { |
161 gatherLayersUsingRenderLayerHierarchy(errorString, compositor->rootRende rLayer(), layers); | 165 gatherLayersUsingRenderLayerHierarchy(errorString, compositor->rootRende rLayer(), layers); |
162 return; | 166 return; |
163 } | 167 } |
164 Node* node = m_instrumentingAgents->inspectorDOMAgent()->nodeForId(*nodeId); | 168 Node* node = m_instrumentingAgents->inspectorDOMAgent()->nodeForId(*nodeId); |
165 if (!node) { | 169 if (!node) { |
166 *errorString = "Provided node id doesn't match any known node"; | 170 *errorString = "Provided node id doesn't match any known node"; |
167 return; | 171 return; |
168 } | 172 } |
169 RenderObject* renderer = node->renderer(); | 173 RenderObject* renderer = node->renderer(); |
170 if (!renderer) { | 174 if (!renderer) { |
171 *errorString = "Node for provided node id doesn't have a renderer"; | 175 *errorString = "Node for provided node id doesn't have a renderer"; |
172 return; | 176 return; |
173 } | 177 } |
174 gatherLayersUsingRenderObjectHierarchy(errorString, renderer, layers); | 178 gatherLayersUsingRenderObjectHierarchy(errorString, renderer, layers); |
175 } | 179 } |
176 | 180 |
177 void InspectorLayerTreeAgent::addRenderLayerBacking(ErrorString* errorString, Re nderLayerBacking* layerBacking, Node* node, RefPtr<TypeBuilder::Array<TypeBuilde r::LayerTree::Layer> >& layers) | 181 void InspectorLayerTreeAgent::addRenderLayerBacking(ErrorString* errorString, Re nderLayerBacking* layerBacking, Node* node, RefPtr<TypeBuilder::Array<TypeBuilde r::LayerTree::Layer> >& layers) |
178 { | 182 { |
179 int nodeId = idForNode(errorString, node); | 183 int nodeId = idForNode(errorString, node); |
180 RenderLayerCompositor* compositor = layerBacking->owningLayer()->compositor( ); | 184 RenderLayerCompositor* compositor = renderLayerCompositor(errorString); |
trchen
2013/08/22 23:02:35
Unused. Can we remove this variable?
| |
181 bool forceRoot = layerBacking->owningLayer()->isRootLayer(); | 185 bool forceRoot = layerBacking->owningLayer()->isRootLayer(); |
182 if (layerBacking->ancestorClippingLayer()) { | 186 if (layerBacking->ancestorClippingLayer()) { |
183 maybeAddGraphicsLayer(layerBacking->ancestorClippingLayer(), nodeId, lay ers, forceRoot); | 187 maybeAddGraphicsLayer(layerBacking->ancestorClippingLayer(), nodeId, lay ers, forceRoot); |
184 forceRoot = false; | 188 forceRoot = false; |
185 } | 189 } |
186 maybeAddGraphicsLayer(layerBacking->graphicsLayer(), nodeId, layers, forceRo ot); | 190 maybeAddGraphicsLayer(layerBacking->graphicsLayer(), nodeId, layers, forceRo ot); |
187 maybeAddGraphicsLayer(layerBacking->clippingLayer(), nodeId, layers); | 191 maybeAddGraphicsLayer(layerBacking->clippingLayer(), nodeId, layers); |
188 maybeAddGraphicsLayer(layerBacking->foregroundLayer(), nodeId, layers); | 192 maybeAddGraphicsLayer(layerBacking->foregroundLayer(), nodeId, layers); |
189 maybeAddGraphicsLayer(layerBacking->backgroundLayer(), nodeId, layers); | 193 maybeAddGraphicsLayer(layerBacking->backgroundLayer(), nodeId, layers); |
190 maybeAddGraphicsLayer(layerBacking->scrollingLayer(), nodeId, layers); | 194 maybeAddGraphicsLayer(layerBacking->scrollingLayer(), nodeId, layers); |
(...skipping 27 matching lines...) Expand all Loading... | |
218 { | 222 { |
219 InspectorDOMAgent* domAgent = m_instrumentingAgents->inspectorDOMAgent(); | 223 InspectorDOMAgent* domAgent = m_instrumentingAgents->inspectorDOMAgent(); |
220 | 224 |
221 int nodeId = domAgent->boundNodeId(node); | 225 int nodeId = domAgent->boundNodeId(node); |
222 if (!nodeId) | 226 if (!nodeId) |
223 nodeId = domAgent->pushNodeToFrontend(errorString, domAgent->boundNodeId (node->document()), node); | 227 nodeId = domAgent->pushNodeToFrontend(errorString, domAgent->boundNodeId (node->document()), node); |
224 | 228 |
225 return nodeId; | 229 return nodeId; |
226 } | 230 } |
227 | 231 |
232 RenderLayerCompositor* InspectorLayerTreeAgent::renderLayerCompositor(ErrorStrin g* errorString) | |
233 { | |
234 RenderView* renderView = m_page->mainFrame()->contentRenderer(); | |
235 RenderLayerCompositor* compositor = renderView ? renderView->compositor() : 0; | |
236 if (!compositor) | |
237 *errorString = "Not in the compositing mode"; | |
238 return compositor; | |
239 } | |
240 | |
241 GraphicsLayer* InspectorLayerTreeAgent::layerById(ErrorString* errorString, cons t String& layerId) | |
242 { | |
243 bool ok; | |
244 int id = layerId.toInt(&ok); | |
245 if (!ok) { | |
246 *errorString = "Invalid layer id"; | |
247 return 0; | |
248 } | |
249 RenderLayerCompositor* compositor = renderLayerCompositor(errorString); | |
250 if (!compositor) | |
251 return 0; | |
252 Vector<std::pair<GraphicsLayer*, size_t> > stack; | |
trchen
2013/08/22 23:02:35
Any reason why not use recursion here?
| |
253 stack.append(std::make_pair(compositor->rootGraphicsLayer(), 0)); | |
254 while (!stack.isEmpty()) { | |
255 GraphicsLayer* layer = stack.last().first; | |
256 size_t& childIndex = stack.last().second; | |
257 if (childIndex < layer->children().size()) { | |
258 stack.append(std::make_pair(layer->children()[childIndex], 0)); | |
259 childIndex++; | |
260 continue; | |
261 } | |
262 if (layer->platformLayer()->id() == id) | |
263 return layer; | |
264 stack.removeLast(); | |
265 } | |
266 *errorString = "No layer matching given id found"; | |
267 return 0; | |
268 } | |
269 | |
270 void InspectorLayerTreeAgent::reasonsForCompositingLayer(ErrorString* errorStrin g, const String& layerId, RefPtr<TypeBuilder::LayerTree::CompositingReasons>& co mpositingReasons) | |
271 { | |
272 const GraphicsLayer* graphicsLayer = layerById(errorString, layerId); | |
273 if (!graphicsLayer) | |
274 return; | |
275 | |
276 WebKit::WebCompositingReasons reasonsBitmask = graphicsLayer->compositingRea sons(); | |
277 compositingReasons = TypeBuilder::LayerTree::CompositingReasons::create(); | |
278 | |
279 if (reasonsBitmask & CompositingReason3DTransform) | |
280 compositingReasons->setTransform3D(true); | |
281 | |
282 if (reasonsBitmask & CompositingReasonVideo) | |
283 compositingReasons->setVideo(true); | |
284 else if (reasonsBitmask & CompositingReasonCanvas) | |
285 compositingReasons->setCanvas(true); | |
286 else if (reasonsBitmask & CompositingReasonPlugin) | |
287 compositingReasons->setPlugin(true); | |
288 else if (reasonsBitmask & CompositingReasonIFrame) | |
289 compositingReasons->setIFrame(true); | |
290 | |
291 if (reasonsBitmask & CompositingReasonBackfaceVisibilityHidden) | |
292 compositingReasons->setBackfaceVisibilityHidden(true); | |
293 | |
294 if (reasonsBitmask & CompositingReasonAnimation) | |
295 compositingReasons->setAnimation(true); | |
296 | |
297 if (reasonsBitmask & CompositingReasonFilters) | |
298 compositingReasons->setFilters(true); | |
299 | |
300 if (reasonsBitmask & CompositingReasonPositionFixed) | |
301 compositingReasons->setPositionFixed(true); | |
302 | |
303 if (reasonsBitmask & CompositingReasonPositionSticky) | |
304 compositingReasons->setPositionSticky(true); | |
305 | |
306 if (reasonsBitmask & CompositingReasonOverflowScrollingTouch) | |
307 compositingReasons->setOverflowScrollingTouch(true); | |
308 | |
309 if (reasonsBitmask & CompositingReasonAssumedOverlap) | |
310 compositingReasons->setAssumedOverlap(true); | |
311 | |
312 if (reasonsBitmask & CompositingReasonOverlap) | |
313 compositingReasons->setOverlap(true); | |
314 | |
315 if (reasonsBitmask & CompositingReasonNegativeZIndexChildren) | |
316 compositingReasons->setNegativeZIndexChildren(true); | |
317 | |
318 if (reasonsBitmask & CompositingReasonTransformWithCompositedDescendants) | |
319 compositingReasons->setTransformWithCompositedDescendants(true); | |
320 | |
321 if (reasonsBitmask & CompositingReasonOpacityWithCompositedDescendants) | |
322 compositingReasons->setOpacityWithCompositedDescendants(true); | |
323 | |
324 if (reasonsBitmask & CompositingReasonMaskWithCompositedDescendants) | |
325 compositingReasons->setMaskWithCompositedDescendants(true); | |
326 | |
327 if (reasonsBitmask & CompositingReasonReflectionWithCompositedDescendants) | |
328 compositingReasons->setReflectionWithCompositedDescendants(true); | |
329 | |
330 if (reasonsBitmask & CompositingReasonFilterWithCompositedDescendants) | |
331 compositingReasons->setFilterWithCompositedDescendants(true); | |
332 | |
333 if (reasonsBitmask & CompositingReasonBlendingWithCompositedDescendants) | |
334 compositingReasons->setBlendingWithCompositedDescendants(true); | |
335 | |
336 if (reasonsBitmask & CompositingReasonClipsCompositingDescendants) | |
337 compositingReasons->setClipsCompositingDescendants(true); | |
338 | |
339 if (reasonsBitmask & CompositingReasonPerspective) | |
340 compositingReasons->setPerspective(true); | |
341 | |
342 if (reasonsBitmask & CompositingReasonPreserve3D) | |
343 compositingReasons->setPreserve3D(true); | |
344 | |
345 if (reasonsBitmask & CompositingReasonRoot) | |
346 compositingReasons->setRoot(true); | |
347 | |
348 if (reasonsBitmask & CompositingReasonLayerForClip) | |
349 compositingReasons->setLayerForClip(true); | |
350 | |
351 if (reasonsBitmask & CompositingReasonLayerForScrollbar) | |
352 compositingReasons->setLayerForScrollbar(true); | |
353 | |
354 if (reasonsBitmask & CompositingReasonLayerForScrollingContainer) | |
355 compositingReasons->setLayerForScrollingContainer(true); | |
356 | |
357 if (reasonsBitmask & CompositingReasonLayerForForeground) | |
358 compositingReasons->setLayerForForeground(true); | |
359 | |
360 if (reasonsBitmask & CompositingReasonLayerForBackground) | |
361 compositingReasons->setLayerForBackground(true); | |
362 | |
363 if (reasonsBitmask & CompositingReasonLayerForMask) | |
364 compositingReasons->setLayerForMask(true); | |
365 | |
366 if (reasonsBitmask & CompositingReasonLayerForVideoOverlay) | |
367 compositingReasons->setLayerForVideoOverlay(true); | |
368 } | |
369 | |
228 } // namespace WebCore | 370 } // namespace WebCore |
OLD | NEW |