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 render 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 frame scrolling). |
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; | 160 if (!compositor) |
156 if (!compositor) { | |
157 *errorString = "Not in compositing mode"; | |
158 return; | 161 return; |
159 } | |
160 if (!nodeId) { | 162 if (!nodeId) { |
161 gatherLayersUsingRenderLayerHierarchy(errorString, compositor->rootRende
rLayer(), layers); | 163 gatherLayersUsingRenderLayerHierarchy(errorString, compositor->rootRende
rLayer(), layers); |
162 return; | 164 return; |
163 } | 165 } |
164 Node* node = m_instrumentingAgents->inspectorDOMAgent()->nodeForId(*nodeId); | 166 Node* node = m_instrumentingAgents->inspectorDOMAgent()->nodeForId(*nodeId); |
165 if (!node) { | 167 if (!node) { |
166 *errorString = "Provided node id doesn't match any known node"; | 168 *errorString = "Provided node id doesn't match any known node"; |
167 return; | 169 return; |
168 } | 170 } |
169 RenderObject* renderer = node->renderer(); | 171 RenderObject* renderer = node->renderer(); |
170 if (!renderer) { | 172 if (!renderer) { |
171 *errorString = "Node for provided node id doesn't have a renderer"; | 173 *errorString = "Node for provided node id doesn't have a renderer"; |
172 return; | 174 return; |
173 } | 175 } |
174 gatherLayersUsingRenderObjectHierarchy(errorString, renderer, layers); | 176 gatherLayersUsingRenderObjectHierarchy(errorString, renderer, layers); |
175 } | 177 } |
176 | 178 |
177 void InspectorLayerTreeAgent::addRenderLayerBacking(ErrorString* errorString, Re
nderLayerBacking* layerBacking, Node* node, RefPtr<TypeBuilder::Array<TypeBuilde
r::LayerTree::Layer> >& layers) | 179 void InspectorLayerTreeAgent::addRenderLayerBacking(ErrorString* errorString, Re
nderLayerBacking* layerBacking, Node* node, RefPtr<TypeBuilder::Array<TypeBuilde
r::LayerTree::Layer> >& layers) |
178 { | 180 { |
179 int nodeId = idForNode(errorString, node); | 181 int nodeId = idForNode(errorString, node); |
180 RenderLayerCompositor* compositor = layerBacking->owningLayer()->compositor(
); | |
181 bool forceRoot = layerBacking->owningLayer()->isRootLayer(); | 182 bool forceRoot = layerBacking->owningLayer()->isRootLayer(); |
182 if (layerBacking->ancestorClippingLayer()) { | 183 if (layerBacking->ancestorClippingLayer()) { |
183 maybeAddGraphicsLayer(layerBacking->ancestorClippingLayer(), nodeId, lay
ers, forceRoot); | 184 maybeAddGraphicsLayer(layerBacking->ancestorClippingLayer(), nodeId, lay
ers, forceRoot); |
184 forceRoot = false; | 185 forceRoot = false; |
185 } | 186 } |
186 maybeAddGraphicsLayer(layerBacking->graphicsLayer(), nodeId, layers, forceRo
ot); | 187 maybeAddGraphicsLayer(layerBacking->graphicsLayer(), nodeId, layers, forceRo
ot); |
187 maybeAddGraphicsLayer(layerBacking->clippingLayer(), nodeId, layers); | 188 maybeAddGraphicsLayer(layerBacking->clippingLayer(), nodeId, layers); |
188 maybeAddGraphicsLayer(layerBacking->foregroundLayer(), nodeId, layers); | 189 maybeAddGraphicsLayer(layerBacking->foregroundLayer(), nodeId, layers); |
189 maybeAddGraphicsLayer(layerBacking->backgroundLayer(), nodeId, layers); | 190 maybeAddGraphicsLayer(layerBacking->backgroundLayer(), nodeId, layers); |
190 maybeAddGraphicsLayer(layerBacking->scrollingLayer(), nodeId, layers); | 191 maybeAddGraphicsLayer(layerBacking->scrollingLayer(), nodeId, layers); |
(...skipping 27 matching lines...) Expand all Loading... |
218 { | 219 { |
219 InspectorDOMAgent* domAgent = m_instrumentingAgents->inspectorDOMAgent(); | 220 InspectorDOMAgent* domAgent = m_instrumentingAgents->inspectorDOMAgent(); |
220 | 221 |
221 int nodeId = domAgent->boundNodeId(node); | 222 int nodeId = domAgent->boundNodeId(node); |
222 if (!nodeId) | 223 if (!nodeId) |
223 nodeId = domAgent->pushNodeToFrontend(errorString, domAgent->boundNodeId
(node->document()), node); | 224 nodeId = domAgent->pushNodeToFrontend(errorString, domAgent->boundNodeId
(node->document()), node); |
224 | 225 |
225 return nodeId; | 226 return nodeId; |
226 } | 227 } |
227 | 228 |
| 229 RenderLayerCompositor* InspectorLayerTreeAgent::renderLayerCompositor(ErrorStrin
g* errorString) |
| 230 { |
| 231 RenderView* renderView = m_page->mainFrame()->contentRenderer(); |
| 232 RenderLayerCompositor* compositor = renderView ? renderView->compositor() :
0; |
| 233 if (!compositor) |
| 234 *errorString = "Not in the compositing mode"; |
| 235 return compositor; |
| 236 } |
| 237 |
| 238 static GraphicsLayer* findLayerById(GraphicsLayer* root, int layerId) |
| 239 { |
| 240 if (root->platformLayer()->id() == layerId) |
| 241 return root; |
| 242 for (size_t i = 0, size = root->children().size(); i < size; ++i) { |
| 243 if (GraphicsLayer* layer = findLayerById(root->children()[i], layerId)) |
| 244 return layer; |
| 245 } |
| 246 return 0; |
| 247 } |
| 248 |
| 249 GraphicsLayer* InspectorLayerTreeAgent::layerById(ErrorString* errorString, cons
t String& layerId) |
| 250 { |
| 251 bool ok; |
| 252 int id = layerId.toInt(&ok); |
| 253 if (!ok) { |
| 254 *errorString = "Invalid layer id"; |
| 255 return 0; |
| 256 } |
| 257 RenderLayerCompositor* compositor = renderLayerCompositor(errorString); |
| 258 if (!compositor) |
| 259 return 0; |
| 260 |
| 261 GraphicsLayer* result = findLayerById(compositor->rootGraphicsLayer(), id); |
| 262 if (!result) |
| 263 *errorString = "No layer matching given id found"; |
| 264 return result; |
| 265 } |
| 266 |
| 267 struct CompositingReasonToProtocolName { |
| 268 uint64_t mask; |
| 269 const char *protocolName; |
| 270 }; |
| 271 |
| 272 |
| 273 void InspectorLayerTreeAgent::compositingReasons(ErrorString* errorString, const
String& layerId, RefPtr<TypeBuilder::Array<String> >& reasonStrings) |
| 274 { |
| 275 static CompositingReasonToProtocolName compositingReasonNames[] = { |
| 276 { CompositingReason3DTransform, "transform3D" }, |
| 277 { CompositingReasonVideo, "video" }, |
| 278 { CompositingReasonCanvas, "canvas" }, |
| 279 { CompositingReasonPlugin, "plugin" }, |
| 280 { CompositingReasonIFrame, "iFrame" }, |
| 281 { CompositingReasonBackfaceVisibilityHidden, "backfaceVisibilityHidden"
}, |
| 282 { CompositingReasonAnimation, "animation" }, |
| 283 { CompositingReasonFilters, "filters" }, |
| 284 { CompositingReasonPositionFixed, "positionFixed" }, |
| 285 { CompositingReasonPositionSticky, "positionSticky" }, |
| 286 { CompositingReasonOverflowScrollingTouch, "overflowScrollingTouch" }, |
| 287 { CompositingReasonAssumedOverlap, "assumedOverlap" }, |
| 288 { CompositingReasonOverlap, "overlap" }, |
| 289 { CompositingReasonNegativeZIndexChildren, "negativeZIndexChildren" }, |
| 290 { CompositingReasonTransformWithCompositedDescendants, "transformWithCom
positedDescendants" }, |
| 291 { CompositingReasonOpacityWithCompositedDescendants, "opacityWithComposi
tedDescendants" }, |
| 292 { CompositingReasonMaskWithCompositedDescendants, "maskWithCompositedDes
cendants" }, |
| 293 { CompositingReasonReflectionWithCompositedDescendants, "reflectionWithC
ompositedDescendants" }, |
| 294 { CompositingReasonFilterWithCompositedDescendants, "filterWithComposite
dDescendants" }, |
| 295 { CompositingReasonBlendingWithCompositedDescendants, "blendingWithCompo
sitedDescendants" }, |
| 296 { CompositingReasonClipsCompositingDescendants, "clipsCompositingDescend
ants" }, |
| 297 { CompositingReasonPerspective, "perspective" }, |
| 298 { CompositingReasonPreserve3D, "preserve3D" }, |
| 299 { CompositingReasonRoot, "root" }, |
| 300 { CompositingReasonLayerForClip, "layerForClip" }, |
| 301 { CompositingReasonLayerForScrollbar, "layerForScrollbar" }, |
| 302 { CompositingReasonLayerForScrollingContainer, "layerForScrollingContain
er" }, |
| 303 { CompositingReasonLayerForForeground, "layerForForeground" }, |
| 304 { CompositingReasonLayerForBackground, "layerForBackground" }, |
| 305 { CompositingReasonLayerForMask, "layerForMask" }, |
| 306 { CompositingReasonLayerForVideoOverlay, "layerForVideoOverlay" } |
| 307 }; |
| 308 |
| 309 const GraphicsLayer* graphicsLayer = layerById(errorString, layerId); |
| 310 if (!graphicsLayer) |
| 311 return; |
| 312 WebKit::WebCompositingReasons reasonsBitmask = graphicsLayer->compositingRea
sons(); |
| 313 reasonStrings = TypeBuilder::Array<String>::create(); |
| 314 for (size_t i = 0; i < WTF_ARRAY_LENGTH(compositingReasonNames); ++i) { |
| 315 if (!(reasonsBitmask & compositingReasonNames[i].mask)) |
| 316 continue; |
| 317 reasonStrings->addItem(compositingReasonNames[i].protocolName); |
| 318 #ifndef _NDEBUG |
| 319 reasonsBitmask &= ~compositingReasonNames[i].mask; |
| 320 #endif |
| 321 } |
| 322 ASSERT(!reasonsBitmask); |
| 323 } |
| 324 |
228 } // namespace WebCore | 325 } // namespace WebCore |
OLD | NEW |