| 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 29 matching lines...) Expand all Loading... |
| 40 #include "core/loader/DocumentLoader.h" | 40 #include "core/loader/DocumentLoader.h" |
| 41 #include "core/frame/Frame.h" | 41 #include "core/frame/Frame.h" |
| 42 #include "core/page/Page.h" | 42 #include "core/page/Page.h" |
| 43 #include "core/rendering/CompositedLayerMapping.h" | 43 #include "core/rendering/CompositedLayerMapping.h" |
| 44 #include "core/rendering/RenderLayerCompositor.h" | 44 #include "core/rendering/RenderLayerCompositor.h" |
| 45 #include "core/rendering/RenderView.h" | 45 #include "core/rendering/RenderView.h" |
| 46 #include "platform/geometry/IntRect.h" | 46 #include "platform/geometry/IntRect.h" |
| 47 #include "platform/graphics/CompositingReasons.h" | 47 #include "platform/graphics/CompositingReasons.h" |
| 48 #include "platform/graphics/GraphicsContextRecorder.h" | 48 #include "platform/graphics/GraphicsContextRecorder.h" |
| 49 #include "platform/transforms/TransformationMatrix.h" | 49 #include "platform/transforms/TransformationMatrix.h" |
| 50 #include "public/platform/WebFloatPoint.h" |
| 50 #include "public/platform/WebLayer.h" | 51 #include "public/platform/WebLayer.h" |
| 51 | 52 |
| 52 namespace WebCore { | 53 namespace WebCore { |
| 53 | 54 |
| 54 unsigned InspectorLayerTreeAgent::s_lastSnapshotId; | 55 unsigned InspectorLayerTreeAgent::s_lastSnapshotId; |
| 55 | 56 |
| 56 struct LayerSnapshot { | 57 struct LayerSnapshot { |
| 57 LayerSnapshot() | 58 LayerSnapshot() |
| 58 : layerId(0) | 59 : layerId(0) |
| 59 { | 60 { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 transformArray->addItem(flattenedMatrix[i]); | 102 transformArray->addItem(flattenedMatrix[i]); |
| 102 layerObject->setTransform(transformArray); | 103 layerObject->setTransform(transformArray); |
| 103 const FloatPoint3D& anchor = graphicsLayer->anchorPoint(); | 104 const FloatPoint3D& anchor = graphicsLayer->anchorPoint(); |
| 104 layerObject->setAnchorX(anchor.x()); | 105 layerObject->setAnchorX(anchor.x()); |
| 105 layerObject->setAnchorY(anchor.y()); | 106 layerObject->setAnchorY(anchor.y()); |
| 106 layerObject->setAnchorZ(anchor.z()); | 107 layerObject->setAnchorZ(anchor.z()); |
| 107 } | 108 } |
| 108 return layerObject; | 109 return layerObject; |
| 109 } | 110 } |
| 110 | 111 |
| 111 void gatherGraphicsLayers(GraphicsLayer* root, HashMap<int, int>& layerIdToNodeI
dMap, RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> >& layers) | 112 static void addRegionObjects(const blink::WebVector<blink::WebRect>& regions, |
| 113 TypeBuilder::Array<TypeBuilder::LayerTree::ScrollRect>& scrollRects, |
| 114 const TypeBuilder::LayerTree::ScrollRect::Type::Enum& type, |
| 115 const TypeBuilder::LayerTree::LayerId& layerId) |
| 116 { |
| 117 for (size_t i = 0; i < regions.size(); ++i) { |
| 118 RefPtr<TypeBuilder::LayerTree::ScrollRect> regionObject = TypeBuilder::L
ayerTree::ScrollRect::create() |
| 119 .setLayerId(layerId) |
| 120 .setX(regions[i].x) |
| 121 .setY(regions[i].y) |
| 122 .setHeight(regions[i].height) |
| 123 .setWidth(regions[i].width) |
| 124 .setType(type); |
| 125 scrollRects.addItem(regionObject); |
| 126 } |
| 127 } |
| 128 |
| 129 |
| 130 static void addScrollRectsForLayer(GraphicsLayer* graphicsLayer, |
| 131 TypeBuilder::Array<TypeBuilder::LayerTree::ScrollRect>& scrollRects) |
| 132 { |
| 133 blink::WebLayer* webLayer = graphicsLayer->platformLayer(); |
| 134 addRegionObjects(webLayer->nonFastScrollableRegion(), |
| 135 scrollRects, |
| 136 TypeBuilder::LayerTree::ScrollRect::Type::NonFastScrollable, |
| 137 idForLayer(graphicsLayer)); |
| 138 addRegionObjects(webLayer->touchEventHandlerRegion(), |
| 139 scrollRects, |
| 140 TypeBuilder::LayerTree::ScrollRect::Type::TouchEventHandler, |
| 141 idForLayer(graphicsLayer)); |
| 142 if (webLayer->haveWheelEventHandlers()) { |
| 143 RefPtr<TypeBuilder::LayerTree::ScrollRect> regionObject = TypeBuilder::L
ayerTree::ScrollRect::create() |
| 144 .setLayerId(idForLayer(graphicsLayer)) |
| 145 .setX(webLayer->position().x) |
| 146 .setY(webLayer->position().y) |
| 147 .setHeight(webLayer->bounds().height) |
| 148 .setWidth(webLayer->bounds().width) |
| 149 .setType(TypeBuilder::LayerTree::ScrollRect::Type::WheelEventHandler
); |
| 150 scrollRects.addItem(regionObject); |
| 151 } |
| 152 } |
| 153 |
| 154 void gatherGraphicsLayers(GraphicsLayer* root, HashMap<int, int>& layerIdToNodeI
dMap, |
| 155 TypeBuilder::Array<TypeBuilder::LayerTree::Layer>& layers, TypeBuilder::Arra
y<TypeBuilder::LayerTree::ScrollRect>& scrollRects) |
| 112 { | 156 { |
| 113 int layerId = root->platformLayer()->id(); | 157 int layerId = root->platformLayer()->id(); |
| 114 layers->addItem(buildObjectForLayer(root, layerIdToNodeIdMap.get(layerId))); | 158 layers.addItem(buildObjectForLayer(root, layerIdToNodeIdMap.get(layerId))); |
| 159 addScrollRectsForLayer(root, scrollRects); |
| 115 if (GraphicsLayer* replica = root->replicaLayer()) | 160 if (GraphicsLayer* replica = root->replicaLayer()) |
| 116 gatherGraphicsLayers(replica, layerIdToNodeIdMap, layers); | 161 gatherGraphicsLayers(replica, layerIdToNodeIdMap, layers, scrollRects); |
| 117 for (size_t i = 0, size = root->children().size(); i < size; ++i) | 162 for (size_t i = 0, size = root->children().size(); i < size; ++i) |
| 118 gatherGraphicsLayers(root->children()[i], layerIdToNodeIdMap, layers); | 163 gatherGraphicsLayers(root->children()[i], layerIdToNodeIdMap, layers, sc
rollRects); |
| 119 } | 164 } |
| 120 | 165 |
| 121 InspectorLayerTreeAgent::InspectorLayerTreeAgent(InspectorDOMAgent* domAgent, Pa
ge* page) | 166 InspectorLayerTreeAgent::InspectorLayerTreeAgent(InspectorDOMAgent* domAgent, Pa
ge* page) |
| 122 : InspectorBaseAgent<InspectorLayerTreeAgent>("LayerTree") | 167 : InspectorBaseAgent<InspectorLayerTreeAgent>("LayerTree") |
| 123 , m_frontend(0) | 168 , m_frontend(0) |
| 124 , m_page(page) | 169 , m_page(page) |
| 125 , m_domAgent(domAgent) | 170 , m_domAgent(domAgent) |
| 126 { | 171 { |
| 127 } | 172 } |
| 128 | 173 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 155 } | 200 } |
| 156 | 201 |
| 157 void InspectorLayerTreeAgent::disable(ErrorString*) | 202 void InspectorLayerTreeAgent::disable(ErrorString*) |
| 158 { | 203 { |
| 159 m_instrumentingAgents->setInspectorLayerTreeAgent(0); | 204 m_instrumentingAgents->setInspectorLayerTreeAgent(0); |
| 160 m_snapshotById.clear(); | 205 m_snapshotById.clear(); |
| 161 } | 206 } |
| 162 | 207 |
| 163 void InspectorLayerTreeAgent::layerTreeDidChange() | 208 void InspectorLayerTreeAgent::layerTreeDidChange() |
| 164 { | 209 { |
| 165 m_frontend->layerTreeDidChange(buildLayerTree()); | 210 RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > layers = TypeBuil
der::Array<TypeBuilder::LayerTree::Layer>::create(); |
| 211 RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::ScrollRect> > scrollRects
= TypeBuilder::Array<TypeBuilder::LayerTree::ScrollRect>::create(); |
| 212 if (buildLayerTree(*layers, *scrollRects)) |
| 213 m_frontend->layerTreeDidChange(layers, scrollRects); |
| 214 else |
| 215 m_frontend->layerTreeDidChange(0, 0); |
| 166 } | 216 } |
| 167 | 217 |
| 168 void InspectorLayerTreeAgent::didPaint(RenderObject*, const GraphicsLayer* graph
icsLayer, GraphicsContext*, const LayoutRect& rect) | 218 void InspectorLayerTreeAgent::didPaint(RenderObject*, const GraphicsLayer* graph
icsLayer, GraphicsContext*, const LayoutRect& rect) |
| 169 { | 219 { |
| 170 // Should only happen for FrameView paints when compositing is off. Consider
different instrumentation method for that. | 220 // Should only happen for FrameView paints when compositing is off. Consider
different instrumentation method for that. |
| 171 if (!graphicsLayer) | 221 if (!graphicsLayer) |
| 172 return; | 222 return; |
| 173 | 223 |
| 174 RefPtr<TypeBuilder::DOM::Rect> domRect = TypeBuilder::DOM::Rect::create() | 224 RefPtr<TypeBuilder::DOM::Rect> domRect = TypeBuilder::DOM::Rect::create() |
| 175 .setX(rect.x()) | 225 .setX(rect.x()) |
| 176 .setY(rect.y()) | 226 .setY(rect.y()) |
| 177 .setWidth(rect.width()) | 227 .setWidth(rect.width()) |
| 178 .setHeight(rect.height()); | 228 .setHeight(rect.height()); |
| 179 m_frontend->layerPainted(idForLayer(graphicsLayer), domRect.release()); | 229 m_frontend->layerPainted(idForLayer(graphicsLayer), domRect.release()); |
| 180 } | 230 } |
| 181 | 231 |
| 182 PassRefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > InspectorLayerTre
eAgent::buildLayerTree() | 232 bool InspectorLayerTreeAgent::buildLayerTree(TypeBuilder::Array<TypeBuilder::Lay
erTree::Layer>& layers, |
| 233 TypeBuilder::Array<TypeBuilder::LayerTree::ScrollRect>& scrollRects) |
| 183 { | 234 { |
| 184 RenderLayerCompositor* compositor = renderLayerCompositor(); | 235 RenderLayerCompositor* compositor = renderLayerCompositor(); |
| 185 if (!compositor || !compositor->inCompositingMode()) | 236 if (!compositor || !compositor->inCompositingMode()) |
| 186 return 0; | 237 return false; |
| 187 LayerIdToNodeIdMap layerIdToNodeIdMap; | 238 LayerIdToNodeIdMap layerIdToNodeIdMap; |
| 188 RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > layers = TypeBuil
der::Array<TypeBuilder::LayerTree::Layer>::create(); | |
| 189 buildLayerIdToNodeIdMap(compositor->rootRenderLayer(), layerIdToNodeIdMap); | 239 buildLayerIdToNodeIdMap(compositor->rootRenderLayer(), layerIdToNodeIdMap); |
| 190 gatherGraphicsLayers(compositor->rootGraphicsLayer(), layerIdToNodeIdMap, la
yers); | 240 gatherGraphicsLayers(compositor->rootGraphicsLayer(), layerIdToNodeIdMap, la
yers, scrollRects); |
| 191 return layers.release(); | 241 return true; |
| 192 } | 242 } |
| 193 | 243 |
| 194 void InspectorLayerTreeAgent::buildLayerIdToNodeIdMap(RenderLayer* root, LayerId
ToNodeIdMap& layerIdToNodeIdMap) | 244 void InspectorLayerTreeAgent::buildLayerIdToNodeIdMap(RenderLayer* root, LayerId
ToNodeIdMap& layerIdToNodeIdMap) |
| 195 { | 245 { |
| 196 if (root->hasCompositedLayerMapping()) { | 246 if (root->hasCompositedLayerMapping()) { |
| 197 if (Node* node = root->renderer()->generatingNode()) { | 247 if (Node* node = root->renderer()->generatingNode()) { |
| 198 GraphicsLayer* graphicsLayer = root->compositedLayerMapping()->child
ForSuperlayers(); | 248 GraphicsLayer* graphicsLayer = root->compositedLayerMapping()->child
ForSuperlayers(); |
| 199 layerIdToNodeIdMap.set(graphicsLayer->platformLayer()->id(), idForNo
de(node)); | 249 layerIdToNodeIdMap.set(graphicsLayer->platformLayer()->id(), idForNo
de(node)); |
| 200 } | 250 } |
| 201 } | 251 } |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 for (size_t i = 0; i < timings->size(); ++i) { | 426 for (size_t i = 0; i < timings->size(); ++i) { |
| 377 const Vector<double>& row = (*timings)[i]; | 427 const Vector<double>& row = (*timings)[i]; |
| 378 RefPtr<TypeBuilder::Array<double> > outRow = TypeBuilder::Array<double>:
:create(); | 428 RefPtr<TypeBuilder::Array<double> > outRow = TypeBuilder::Array<double>:
:create(); |
| 379 for (size_t j = 1; j < row.size(); ++j) | 429 for (size_t j = 1; j < row.size(); ++j) |
| 380 outRow->addItem(row[j] - row[j - 1]); | 430 outRow->addItem(row[j] - row[j - 1]); |
| 381 outTimings->addItem(outRow.release()); | 431 outTimings->addItem(outRow.release()); |
| 382 } | 432 } |
| 383 } | 433 } |
| 384 | 434 |
| 385 } // namespace WebCore | 435 } // namespace WebCore |
| OLD | NEW |