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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 66 } |
67 int layerId; | 67 int layerId; |
68 RefPtr<GraphicsContextSnapshot> graphicsSnapshot; | 68 RefPtr<GraphicsContextSnapshot> graphicsSnapshot; |
69 }; | 69 }; |
70 | 70 |
71 inline String idForLayer(const GraphicsLayer* graphicsLayer) | 71 inline String idForLayer(const GraphicsLayer* graphicsLayer) |
72 { | 72 { |
73 return String::number(graphicsLayer->platformLayer()->id()); | 73 return String::number(graphicsLayer->platformLayer()->id()); |
74 } | 74 } |
75 | 75 |
| 76 static void buildRegionObjects(const blink::WebVector<blink::WebRect>& regions, |
| 77 TypeBuilder::Array<TypeBuilder::LayerTree::ScrollRect>& scrollRects, |
| 78 const TypeBuilder::LayerTree::ScrollRect::Type::Enum& type, |
| 79 const TypeBuilder::LayerTree::LayerId& layerId) |
| 80 { |
| 81 for (size_t i = 0; i < regions.size(); ++i) { |
| 82 RefPtr<TypeBuilder::DOM::Rect> rectObject = TypeBuilder::DOM::Rect::crea
te() |
| 83 .setX(regions[i].x) |
| 84 .setY(regions[i].y) |
| 85 .setHeight(regions[i].height) |
| 86 .setWidth(regions[i].width); |
| 87 RefPtr<TypeBuilder::LayerTree::ScrollRect> regionObject = TypeBuilder::L
ayerTree::ScrollRect::create() |
| 88 .setRect(rectObject) |
| 89 .setType(type); |
| 90 scrollRects.addItem(regionObject); |
| 91 } |
| 92 } |
| 93 |
| 94 static PassRefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::ScrollRect> > build
ScrollRectsForLayer(GraphicsLayer* graphicsLayer) |
| 95 { |
| 96 RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::ScrollRect> > scrollRects
= TypeBuilder::Array<TypeBuilder::LayerTree::ScrollRect>::create(); |
| 97 blink::WebLayer* webLayer = graphicsLayer->platformLayer(); |
| 98 buildRegionObjects(webLayer->nonFastScrollableRegion(), *scrollRects, TypeBu
ilder::LayerTree::ScrollRect::Type::RepaintsOnScroll, idForLayer(graphicsLayer))
; |
| 99 buildRegionObjects(webLayer->touchEventHandlerRegion(), *scrollRects, TypeBu
ilder::LayerTree::ScrollRect::Type::TouchEventHandler, idForLayer(graphicsLayer)
); |
| 100 if (webLayer->haveWheelEventHandlers()) { |
| 101 RefPtr<TypeBuilder::DOM::Rect> rectObject = TypeBuilder::DOM::Rect::crea
te() |
| 102 .setX(webLayer->position().x) |
| 103 .setY(webLayer->position().y) |
| 104 .setHeight(webLayer->bounds().height) |
| 105 .setWidth(webLayer->bounds().width); |
| 106 RefPtr<TypeBuilder::LayerTree::ScrollRect> regionObject = TypeBuilder::L
ayerTree::ScrollRect::create() |
| 107 .setRect(rectObject) |
| 108 .setType(TypeBuilder::LayerTree::ScrollRect::Type::WheelEventHandler
); |
| 109 scrollRects->addItem(regionObject); |
| 110 } |
| 111 return scrollRects->length() ? scrollRects : nullptr; |
| 112 } |
| 113 |
76 static PassRefPtr<TypeBuilder::LayerTree::Layer> buildObjectForLayer(GraphicsLay
er* graphicsLayer, int nodeId) | 114 static PassRefPtr<TypeBuilder::LayerTree::Layer> buildObjectForLayer(GraphicsLay
er* graphicsLayer, int nodeId) |
77 { | 115 { |
78 blink::WebLayer* webLayer = graphicsLayer->platformLayer(); | 116 blink::WebLayer* webLayer = graphicsLayer->platformLayer(); |
79 RefPtr<TypeBuilder::LayerTree::Layer> layerObject = TypeBuilder::LayerTree::
Layer::create() | 117 RefPtr<TypeBuilder::LayerTree::Layer> layerObject = TypeBuilder::LayerTree::
Layer::create() |
80 .setLayerId(idForLayer(graphicsLayer)) | 118 .setLayerId(idForLayer(graphicsLayer)) |
81 .setOffsetX(webLayer->position().x) | 119 .setOffsetX(webLayer->position().x) |
82 .setOffsetY(webLayer->position().y) | 120 .setOffsetY(webLayer->position().y) |
83 .setWidth(webLayer->bounds().width) | 121 .setWidth(webLayer->bounds().width) |
84 .setHeight(webLayer->bounds().height) | 122 .setHeight(webLayer->bounds().height) |
85 .setPaintCount(graphicsLayer->paintCount()); | 123 .setPaintCount(graphicsLayer->paintCount()); |
(...skipping 14 matching lines...) Expand all Loading... |
100 transform.toColumnMajorFloatArray(flattenedMatrix); | 138 transform.toColumnMajorFloatArray(flattenedMatrix); |
101 RefPtr<TypeBuilder::Array<double> > transformArray = TypeBuilder::Array<
double>::create(); | 139 RefPtr<TypeBuilder::Array<double> > transformArray = TypeBuilder::Array<
double>::create(); |
102 for (size_t i = 0; i < WTF_ARRAY_LENGTH(flattenedMatrix); ++i) | 140 for (size_t i = 0; i < WTF_ARRAY_LENGTH(flattenedMatrix); ++i) |
103 transformArray->addItem(flattenedMatrix[i]); | 141 transformArray->addItem(flattenedMatrix[i]); |
104 layerObject->setTransform(transformArray); | 142 layerObject->setTransform(transformArray); |
105 const FloatPoint3D& anchor = graphicsLayer->anchorPoint(); | 143 const FloatPoint3D& anchor = graphicsLayer->anchorPoint(); |
106 layerObject->setAnchorX(anchor.x()); | 144 layerObject->setAnchorX(anchor.x()); |
107 layerObject->setAnchorY(anchor.y()); | 145 layerObject->setAnchorY(anchor.y()); |
108 layerObject->setAnchorZ(anchor.z()); | 146 layerObject->setAnchorZ(anchor.z()); |
109 } | 147 } |
| 148 RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::ScrollRect> > scrollRects
= |
| 149 buildScrollRectsForLayer(graphicsLayer); |
| 150 if (scrollRects) |
| 151 layerObject->setScrollRects(buildScrollRectsForLayer(graphicsLayer)); |
110 return layerObject; | 152 return layerObject; |
111 } | 153 } |
112 | 154 |
113 InspectorLayerTreeAgent::InspectorLayerTreeAgent(InspectorDOMAgent* domAgent, Pa
ge* page) | 155 InspectorLayerTreeAgent::InspectorLayerTreeAgent(InspectorDOMAgent* domAgent, Pa
ge* page) |
114 : InspectorBaseAgent<InspectorLayerTreeAgent>("LayerTree") | 156 : InspectorBaseAgent<InspectorLayerTreeAgent>("LayerTree") |
115 , m_frontend(0) | 157 , m_frontend(0) |
116 , m_page(page) | 158 , m_page(page) |
117 , m_domAgent(domAgent) | 159 , m_domAgent(domAgent) |
118 { | 160 { |
119 } | 161 } |
(...skipping 27 matching lines...) Expand all Loading... |
147 } | 189 } |
148 | 190 |
149 void InspectorLayerTreeAgent::disable(ErrorString*) | 191 void InspectorLayerTreeAgent::disable(ErrorString*) |
150 { | 192 { |
151 m_instrumentingAgents->setInspectorLayerTreeAgent(0); | 193 m_instrumentingAgents->setInspectorLayerTreeAgent(0); |
152 m_snapshotById.clear(); | 194 m_snapshotById.clear(); |
153 } | 195 } |
154 | 196 |
155 void InspectorLayerTreeAgent::layerTreeDidChange() | 197 void InspectorLayerTreeAgent::layerTreeDidChange() |
156 { | 198 { |
157 m_frontend->layerTreeDidChange(buildLayerTree()); | 199 RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > layers = TypeBuil
der::Array<TypeBuilder::LayerTree::Layer>::create(); |
| 200 if (buildLayerTree(*layers)) |
| 201 m_frontend->layerTreeDidChange(layers); |
| 202 else |
| 203 m_frontend->layerTreeDidChange(nullptr); |
158 } | 204 } |
159 | 205 |
160 void InspectorLayerTreeAgent::didPaint(RenderObject*, const GraphicsLayer* graph
icsLayer, GraphicsContext*, const LayoutRect& rect) | 206 void InspectorLayerTreeAgent::didPaint(RenderObject*, const GraphicsLayer* graph
icsLayer, GraphicsContext*, const LayoutRect& rect) |
161 { | 207 { |
162 // Should only happen for FrameView paints when compositing is off. Consider
different instrumentation method for that. | 208 // Should only happen for FrameView paints when compositing is off. Consider
different instrumentation method for that. |
163 if (!graphicsLayer) | 209 if (!graphicsLayer) |
164 return; | 210 return; |
165 | 211 |
166 RefPtr<TypeBuilder::DOM::Rect> domRect = TypeBuilder::DOM::Rect::create() | 212 RefPtr<TypeBuilder::DOM::Rect> domRect = TypeBuilder::DOM::Rect::create() |
167 .setX(rect.x()) | 213 .setX(rect.x()) |
168 .setY(rect.y()) | 214 .setY(rect.y()) |
169 .setWidth(rect.width()) | 215 .setWidth(rect.width()) |
170 .setHeight(rect.height()); | 216 .setHeight(rect.height()); |
171 m_frontend->layerPainted(idForLayer(graphicsLayer), domRect.release()); | 217 m_frontend->layerPainted(idForLayer(graphicsLayer), domRect.release()); |
172 } | 218 } |
173 | 219 |
174 PassRefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > InspectorLayerTre
eAgent::buildLayerTree() | 220 bool InspectorLayerTreeAgent::buildLayerTree(TypeBuilder::Array<TypeBuilder::Lay
erTree::Layer>& layers) |
175 { | 221 { |
176 RenderLayerCompositor* compositor = renderLayerCompositor(); | 222 RenderLayerCompositor* compositor = renderLayerCompositor(); |
177 if (!compositor || !compositor->inCompositingMode()) | 223 if (!compositor || !compositor->inCompositingMode()) |
178 return nullptr; | 224 return false; |
179 LayerIdToNodeIdMap layerIdToNodeIdMap; | 225 LayerIdToNodeIdMap layerIdToNodeIdMap; |
180 RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > layers = TypeBuil
der::Array<TypeBuilder::LayerTree::Layer>::create(); | |
181 buildLayerIdToNodeIdMap(compositor->rootRenderLayer(), layerIdToNodeIdMap); | 226 buildLayerIdToNodeIdMap(compositor->rootRenderLayer(), layerIdToNodeIdMap); |
182 gatherGraphicsLayers(compositor->rootGraphicsLayer(), layerIdToNodeIdMap, la
yers); | 227 gatherGraphicsLayers(compositor->rootGraphicsLayer(), layerIdToNodeIdMap, la
yers); |
183 return layers.release(); | 228 return true; |
184 } | 229 } |
185 | 230 |
186 void InspectorLayerTreeAgent::buildLayerIdToNodeIdMap(RenderLayer* root, LayerId
ToNodeIdMap& layerIdToNodeIdMap) | 231 void InspectorLayerTreeAgent::buildLayerIdToNodeIdMap(RenderLayer* root, LayerId
ToNodeIdMap& layerIdToNodeIdMap) |
187 { | 232 { |
188 if (root->hasCompositedLayerMapping()) { | 233 if (root->hasCompositedLayerMapping()) { |
189 if (Node* node = root->renderer()->generatingNode()) { | 234 if (Node* node = root->renderer()->generatingNode()) { |
190 GraphicsLayer* graphicsLayer = root->compositedLayerMapping()->child
ForSuperlayers(); | 235 GraphicsLayer* graphicsLayer = root->compositedLayerMapping()->child
ForSuperlayers(); |
191 layerIdToNodeIdMap.set(graphicsLayer->platformLayer()->id(), idForNo
de(node)); | 236 layerIdToNodeIdMap.set(graphicsLayer->platformLayer()->id(), idForNo
de(node)); |
192 } | 237 } |
193 } | 238 } |
194 for (RenderLayer* child = root->firstChild(); child; child = child->nextSibl
ing()) | 239 for (RenderLayer* child = root->firstChild(); child; child = child->nextSibl
ing()) |
195 buildLayerIdToNodeIdMap(child, layerIdToNodeIdMap); | 240 buildLayerIdToNodeIdMap(child, layerIdToNodeIdMap); |
196 if (!root->renderer()->isRenderIFrame()) | 241 if (!root->renderer()->isRenderIFrame()) |
197 return; | 242 return; |
198 FrameView* childFrameView = toFrameView(toRenderWidget(root->renderer())->wi
dget()); | 243 FrameView* childFrameView = toFrameView(toRenderWidget(root->renderer())->wi
dget()); |
199 if (RenderView* childRenderView = childFrameView->renderView()) { | 244 if (RenderView* childRenderView = childFrameView->renderView()) { |
200 if (RenderLayerCompositor* childCompositor = childRenderView->compositor
()) | 245 if (RenderLayerCompositor* childCompositor = childRenderView->compositor
()) |
201 buildLayerIdToNodeIdMap(childCompositor->rootRenderLayer(), layerIdT
oNodeIdMap); | 246 buildLayerIdToNodeIdMap(childCompositor->rootRenderLayer(), layerIdT
oNodeIdMap); |
202 } | 247 } |
203 } | 248 } |
204 | 249 |
205 void InspectorLayerTreeAgent::gatherGraphicsLayers(GraphicsLayer* root, HashMap<
int, int>& layerIdToNodeIdMap, RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree:
:Layer> >& layers) | 250 void InspectorLayerTreeAgent::gatherGraphicsLayers(GraphicsLayer* root, HashMap<
int, int>& layerIdToNodeIdMap, |
| 251 TypeBuilder::Array<TypeBuilder::LayerTree::Layer>& layers) |
206 { | 252 { |
207 int layerId = root->platformLayer()->id(); | 253 int layerId = root->platformLayer()->id(); |
208 if (m_pageOverlayLayerIds.find(layerId) != WTF::kNotFound) | 254 if (m_pageOverlayLayerIds.find(layerId) != WTF::kNotFound) |
209 return; | 255 return; |
210 layers->addItem(buildObjectForLayer(root, layerIdToNodeIdMap.get(layerId))); | 256 layers.addItem(buildObjectForLayer(root, layerIdToNodeIdMap.get(layerId))); |
211 if (GraphicsLayer* replica = root->replicaLayer()) | 257 if (GraphicsLayer* replica = root->replicaLayer()) |
212 gatherGraphicsLayers(replica, layerIdToNodeIdMap, layers); | 258 gatherGraphicsLayers(replica, layerIdToNodeIdMap, layers); |
213 for (size_t i = 0, size = root->children().size(); i < size; ++i) | 259 for (size_t i = 0, size = root->children().size(); i < size; ++i) |
214 gatherGraphicsLayers(root->children()[i], layerIdToNodeIdMap, layers); | 260 gatherGraphicsLayers(root->children()[i], layerIdToNodeIdMap, layers); |
215 } | 261 } |
216 | 262 |
217 int InspectorLayerTreeAgent::idForNode(Node* node) | 263 int InspectorLayerTreeAgent::idForNode(Node* node) |
218 { | 264 { |
219 int nodeId = m_domAgent->boundNodeId(node); | 265 int nodeId = m_domAgent->boundNodeId(node); |
220 if (!nodeId) { | 266 if (!nodeId) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 void InspectorLayerTreeAgent::didRemovePageOverlay(const GraphicsLayer* layer) | 399 void InspectorLayerTreeAgent::didRemovePageOverlay(const GraphicsLayer* layer) |
354 { | 400 { |
355 size_t index = m_pageOverlayLayerIds.find(layer->platformLayer()->id()); | 401 size_t index = m_pageOverlayLayerIds.find(layer->platformLayer()->id()); |
356 if (index == WTF::kNotFound) | 402 if (index == WTF::kNotFound) |
357 return; | 403 return; |
358 m_pageOverlayLayerIds.remove(index); | 404 m_pageOverlayLayerIds.remove(index); |
359 } | 405 } |
360 | 406 |
361 | 407 |
362 } // namespace WebCore | 408 } // namespace WebCore |
OLD | NEW |