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 "InspectorFrontend.h" 35#include "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 WebCore { 44 45class InspectorDOMAgent; 46class InstrumentingAgents; 47class Page; 48class RenderLayerCompositor; 49 50struct LayerSnapshot; 51 52typedef String ErrorString; 53 54class InspectorLayerTreeAgent : public InspectorBaseAgent<InspectorLayerTreeAgent>, public InspectorBackendDispatcher::LayerTreeCommandHandler { 55public: 56 static PassOwnPtr<InspectorLayerTreeAgent> create(InstrumentingAgents* instrumentingAgents, InspectorCompositeState* state, InspectorDOMAgent* domAgent, Page* page) 57 { 58 return adoptPtr(new InspectorLayerTreeAgent(instrumentingAgents, state, domAgent, page)); 59 } 60 ~InspectorLayerTreeAgent(); 61 62 virtual void setFrontend(InspectorFrontend*); 63 virtual void clearFrontend(); 64 virtual void restore(); 65 66 // Called from InspectorInstrumentation 67 void layerTreeDidChange(); 68 void didPaint(RenderObject*, const GraphicsLayer*, GraphicsContext*, const LayoutRect&); 69 70 // Called from the front-end. 71 virtual void enable(ErrorString*); 72 virtual void disable(ErrorString*); 73 virtual void compositingReasons(ErrorString*, const String& layerId, RefPtr<TypeBuilder::Array<String> >&); 74 virtual void makeSnapshot(ErrorString*, const String& layerId, String* snapshotId); 75 virtual void releaseSnapshot(ErrorString*, const String& snapshotId); 76 virtual void replaySnapshot(ErrorString*, const String& snapshotId, const int* fromStep, const int* toStep, String* dataURL); 77 virtual void profileSnapshot(ErrorString*, const String& snapshotId, const int* minRepeatCount, const double* minDuration, RefPtr<TypeBuilder::Array<TypeBuilder::Array<double> > >&); 78 79private: 80 static unsigned s_lastSnapshotId; 81 82 InspectorLayerTreeAgent(InstrumentingAgents*, InspectorCompositeState*, InspectorDOMAgent*, Page*); 83 84 RenderLayerCompositor* renderLayerCompositor(); 85 GraphicsLayer* layerById(ErrorString*, const String& layerId); 86 const LayerSnapshot* snapshotById(ErrorString*, const String& snapshotId); 87 PassRefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > buildLayerTree(); 88 89 typedef HashMap<int, int> LayerIdToNodeIdMap; 90 void buildLayerIdToNodeIdMap(RenderLayer*, LayerIdToNodeIdMap&); 91 int idForNode(Node*); 92 93 InspectorFrontend::LayerTree* m_frontend; 94 Page* m_page; 95 InspectorDOMAgent* m_domAgent; 96 97 typedef HashMap<String, LayerSnapshot> SnapshotById; 98 SnapshotById m_snapshotById; 99}; 100 101} // namespace WebCore 102 103 104#endif // !defined(InspectorLayerTreeAgent_h) 105