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 "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"
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 PassOwnPtrWillBeRawPtr<InspectorLayerTreeAgent> create(Page* page)
56 return adoptPtrWillBeNoop(new InspectorLayerTreeAgent(page));
58 virtual ~InspectorLayerTreeAgent();
59 virtual void trace(Visitor*) OVERRIDE;
61 virtual void setFrontend(InspectorFrontend*) OVERRIDE;
62 virtual void clearFrontend() OVERRIDE;
63 virtual void restore() OVERRIDE;
65 // Called from InspectorController
66 void willAddPageOverlay(const GraphicsLayer*);
67 void didRemovePageOverlay(const GraphicsLayer*);
69 // Called from InspectorInstrumentation
70 void layerTreeDidChange();
71 void didPaint(RenderObject*, const GraphicsLayer*, GraphicsContext*, const LayoutRect&);
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;
84 // Called by other agents.
85 PassRefPtr<TypeBuilder::Array<TypeBuilder::LayerTree::Layer> > buildLayerTree();
88 static unsigned s_lastSnapshotId;
90 explicit InspectorLayerTreeAgent(Page*);
92 RenderLayerCompositor* renderLayerCompositor();
93 GraphicsLayer* layerById(ErrorString*, const String& layerId);
94 const GraphicsContextSnapshot* snapshotById(ErrorString*, const String& snapshotId);
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> >&);
101 InspectorFrontend::LayerTree* m_frontend;
102 RawPtrWillBeMember<Page> m_page;
103 Vector<int, 2> m_pageOverlayLayerIds;
105 typedef HashMap<String, RefPtr<GraphicsContextSnapshot> > SnapshotById;
106 SnapshotById m_snapshotById;
112 #endif // !defined(InspectorLayerTreeAgent_h)