2 * Copyright (C) 2012 Apple Inc. All rights reserved.
3 * Copyright (C) 2013 Google Inc. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
30 #ifndef InspectorLayerTreeAgent_h
31 #define InspectorLayerTreeAgent_h
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"
45 class GraphicsContextSnapshot;
46 class InstrumentingAgents;
48 class RenderLayerCompositor;
50 typedef String ErrorString;
52 class InspectorLayerTreeAgent FINAL : public InspectorBaseAgent<InspectorLayerTreeAgent>, public InspectorBackendDispatcher::LayerTreeCommandHandler {
54 static PassOwnPtr<InspectorLayerTreeAgent> create(Page* page)
56 return adoptPtr(new InspectorLayerTreeAgent(page));
58 virtual ~InspectorLayerTreeAgent();
60 virtual void setFrontend(InspectorFrontend*) OVERRIDE;
61 virtual void clearFrontend() OVERRIDE;
62 virtual void restore() OVERRIDE;
64 // Called from InspectorController
65 void willAddPageOverlay(const GraphicsLayer*);
66 void didRemovePageOverlay(const GraphicsLayer*);
68 // Called from InspectorInstrumentation
69 void layerTreeDidChange();
70 void didPaint(RenderObject*, const GraphicsLayer*, GraphicsContext*, const LayoutRect&);
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;
83 // Called by other agents.
84 PassRefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > buildLayerTree();
87 static unsigned s_lastSnapshotId;
89 explicit InspectorLayerTreeAgent(Page*);
91 RenderLayerCompositor* renderLayerCompositor();
92 GraphicsLayer* layerById(ErrorString*, const String& layerId);
93 const GraphicsContextSnapshot* snapshotById(ErrorString*, const String& snapshotId);
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> >&);
100 InspectorFrontend::LayerTree* m_frontend;
102 Vector<int, 2> m_pageOverlayLayerIds;
104 typedef HashMap<String, RefPtr<GraphicsContextSnapshot> > SnapshotById;
105 SnapshotById m_snapshotById;
108 } // namespace WebCore
111 #endif // !defined(InspectorLayerTreeAgent_h)