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 43namespace blink { 44 45class GraphicsContextSnapshot; 46class InstrumentingAgents; 47class Page; 48class RenderLayerCompositor; 49 50typedef String ErrorString; 51 52class InspectorLayerTreeAgent FINAL : public InspectorBaseAgent<InspectorLayerTreeAgent>, public InspectorBackendDispatcher::LayerTreeCommandHandler { 53public: 54 static PassOwnPtrWillBeRawPtr<InspectorLayerTreeAgent> create(Page* page) 55 { 56 return adoptPtrWillBeNoop(new InspectorLayerTreeAgent(page)); 57 } 58 virtual ~InspectorLayerTreeAgent(); 59 virtual void trace(Visitor*) OVERRIDE; 60 61 virtual void setFrontend(InspectorFrontend*) OVERRIDE; 62 virtual void clearFrontend() OVERRIDE; 63 virtual void restore() OVERRIDE; 64 65 // Called from InspectorController 66 void willAddPageOverlay(const GraphicsLayer*); 67 void didRemovePageOverlay(const GraphicsLayer*); 68 69 // Called from InspectorInstrumentation 70 void layerTreeDidChange(); 71 void didPaint(RenderObject*, const GraphicsLayer*, GraphicsContext*, const LayoutRect&); 72 73 // Called from the front-end. 74 virtual void enable(ErrorString*) OVERRIDE; 75 virtual void disable(ErrorString*) OVERRIDE; 76 virtual void compositingReasons(ErrorString*, const String& layerId, RefPtr<TypeBuilder::Array<String> >&) OVERRIDE; 77 virtual void makeSnapshot(ErrorString*, const String& layerId, String* snapshotId) OVERRIDE; 78 virtual void loadSnapshot(ErrorString*, const String& data, String* snapshotId) OVERRIDE; 79 virtual void releaseSnapshot(ErrorString*, const String& snapshotId) OVERRIDE; 80 virtual void replaySnapshot(ErrorString*, const String& snapshotId, const int* fromStep, const int* toStep, const double* scale, String* dataURL) OVERRIDE; 81 virtual void profileSnapshot(ErrorString*, const String& snapshotId, const int* minRepeatCount, const double* minDuration, RefPtr<TypeBuilder::Array<TypeBuilder::Array<double> > >&) OVERRIDE; 82 virtual void snapshotCommandLog(ErrorString*, const String& snapshotId, RefPtr<TypeBuilder::Array<JSONObject> >&) OVERRIDE; 83 84 // Called by other agents. 85 PassRefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > buildLayerTree(); 86 87private: 88 static unsigned s_lastSnapshotId; 89 90 explicit InspectorLayerTreeAgent(Page*); 91 92 RenderLayerCompositor* renderLayerCompositor(); 93 GraphicsLayer* layerById(ErrorString*, const String& layerId); 94 const GraphicsContextSnapshot* snapshotById(ErrorString*, const String& snapshotId); 95 96 typedef HashMap<int, int> LayerIdToNodeIdMap; 97 void buildLayerIdToNodeIdMap(RenderLayer*, LayerIdToNodeIdMap&); 98 void gatherGraphicsLayers(GraphicsLayer*, HashMap<int, int>& layerIdToNodeIdMap, RefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> >&); 99 int idForNode(Node*); 100 101 InspectorFrontend::LayerTree* m_frontend; 102 RawPtrWillBeMember<Page> m_page; 103 Vector<int, 2> m_pageOverlayLayerIds; 104 105 typedef HashMap<String, RefPtr<GraphicsContextSnapshot> > SnapshotById; 106 SnapshotById m_snapshotById; 107}; 108 109} // namespace blink 110 111 112#endif // !defined(InspectorLayerTreeAgent_h) 113