1 /* 2 * Copyright (C) 2012 Apple Inc. All rights reserved. 3 * Copyright (C) 2013 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 * 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 15 * its contributors may be used to endorse or promote products derived 16 * from this software without specific prior written permission. 17 * 18 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30 #ifndef InspectorLayerTreeAgent_h 31 #define InspectorLayerTreeAgent_h 32 33 34 #include "core/InspectorFrontend.h" 35 #include "core/InspectorTypeBuilder.h" 36 #include "core/inspector/InspectorBaseAgent.h" 37 #include "core/rendering/RenderLayer.h" 38 #include "platform/Timer.h" 39 #include "wtf/PassOwnPtr.h" 40 #include "wtf/PassRefPtr.h" 41 #include "wtf/text/WTFString.h" 42 43 namespace WebCore { 44 45 class GraphicsContextSnapshot; 46 class InstrumentingAgents; 47 class Page; 48 class RenderLayerCompositor; 49 50 typedef String ErrorString; 51 52 class InspectorLayerTreeAgent FINAL : public InspectorBaseAgent<InspectorLayerTreeAgent>, public InspectorBackendDispatcher::LayerTreeCommandHandler { 53 public: 54 static PassOwnPtr<InspectorLayerTreeAgent> create(Page* page) 55 { 56 return adoptPtr(new InspectorLayerTreeAgent(page)); 57 } 58 virtual ~InspectorLayerTreeAgent(); 59 60 virtual void setFrontend(InspectorFrontend*) OVERRIDE; 61 virtual void clearFrontend() OVERRIDE; 62 virtual void restore() OVERRIDE; 63 64 // Called from InspectorController 65 void willAddPageOverlay(const GraphicsLayer*); 66 void didRemovePageOverlay(const GraphicsLayer*); 67 68 // Called from InspectorInstrumentation 69 void layerTreeDidChange(); 70 void didPaint(RenderObject*, const GraphicsLayer*, GraphicsContext*, const LayoutRect&); 71 72 // Called from the front-end. 73 virtual void enable(ErrorString*) OVERRIDE; 74 virtual void disable(ErrorString*) OVERRIDE; 75 virtual void compositingReasons(ErrorString*, const String& layerId, RefPtr<TypeBuilder::Array<String> >&) OVERRIDE; 76 virtual void makeSnapshot(ErrorString*, const String& layerId, String* snapshotId) OVERRIDE; 77 virtual void loadSnapshot(ErrorString*, const String& data, String* snapshotId) OVERRIDE; 78 virtual void releaseSnapshot(ErrorString*, const String& snapshotId) OVERRIDE; 79 virtual void replaySnapshot(ErrorString*, const String& snapshotId, const int* fromStep, const int* toStep, String* dataURL) OVERRIDE; 80 virtual void profileSnapshot(ErrorString*, const String& snapshotId, const int* minRepeatCount, const double* minDuration, RefPtr<TypeBuilder::Array<TypeBuilder::Array<double> > >&) OVERRIDE; 81 virtual void snapshotCommandLog(ErrorString*, const String& snapshotId, RefPtr<TypeBuilder::Array<JSONObject> >&) OVERRIDE; 82 83 // Called by other agents. 84 PassRefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > buildLayerTree(); 85 86 private: 87 static unsigned s_lastSnapshotId; 88 89 explicit InspectorLayerTreeAgent(Page*); 90 91 RenderLayerCompositor* renderLayerCompositor(); 92 GraphicsLayer* layerById(ErrorString*, const String& layerId); 93 const GraphicsContextSnapshot* snapshotById(ErrorString*, const String& snapshotId); 94 95 typedef HashMap<int, int> LayerIdToNodeIdMap; 96 void buildLayerIdToNodeIdMap(RenderLayer*, LayerIdToNodeIdMap&); 97 void gatherGraphicsLayers(GraphicsLayer*, HashMap<int, int>& layerIdToNodeIdMap, RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> >&); 98 int idForNode(Node*); 99 100 InspectorFrontend::LayerTree* m_frontend; 101 Page* m_page; 102 Vector<int, 2> m_pageOverlayLayerIds; 103 104 typedef HashMap<String, RefPtr<GraphicsContextSnapshot> > SnapshotById; 105 SnapshotById m_snapshotById; 106 }; 107 108 } // namespace WebCore 109 110 111 #endif // !defined(InspectorLayerTreeAgent_h) 112