OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
11 * copyright notice, this list of conditions and the following disclaimer | 11 * copyright notice, this list of conditions and the following disclaimer |
12 * in the documentation and/or other materials provided with the | 12 * in the documentation and/or other materials provided with the |
13 * distribution. | 13 * distribution. |
14 * * Neither the name of Google Inc. nor the names of its | 14 * * Neither the name of Google Inc. nor the names of its |
15 * contributors may be used to endorse or promote products derived from | 15 * contributors may be used to endorse or promote products derived from |
16 * this software without specific prior written permission. | 16 * this software without specific prior written permission. |
17 * | 17 * |
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | |
31 SDK.PaintProfilerModel = class extends SDK.SDKModel { | |
32 /** | |
33 * @param {!SDK.Target} target | |
34 */ | |
35 constructor(target) { | |
36 super(target); | |
37 this._layerTreeAgent = target.layerTreeAgent(); | |
38 } | |
39 | |
40 /** | |
41 * @param {!Array.<!SDK.PictureFragment>} fragments | |
42 * @return {!Promise<?SDK.PaintProfilerSnapshot>} | |
43 */ | |
44 loadSnapshotFromFragments(fragments) { | |
45 return this._layerTreeAgent.loadSnapshot( | |
46 fragments, (error, snapshotId) => error ? null : new SDK.PaintProfilerSn apshot(this, snapshotId)); | |
47 } | |
48 | |
49 /** | |
50 * @param {string} encodedPicture | |
51 * @return {!Promise<?SDK.PaintProfilerSnapshot>} | |
52 */ | |
53 loadSnapshot(encodedPicture) { | |
54 var fragment = {x: 0, y: 0, picture: encodedPicture}; | |
55 return this.loadSnapshotFromFragments([fragment]); | |
56 } | |
57 | |
58 /** | |
59 * @param {string} layerId | |
60 * @return {!Promise<?SDK.PaintProfilerSnapshot>} | |
61 */ | |
62 layerSnapshot(layerId) { | |
caseq1
2017/04/27 21:19:22
Let's keep the underlying name, i.e. makeSnapshot(
dgozman
2017/04/28 00:07:33
Done.
| |
63 return this._layerTreeAgent.makeSnapshot( | |
64 layerId, (error, snapshotId) => error ? null : new SDK.PaintProfilerSnap shot(this, snapshotId)); | |
65 } | |
66 }; | |
67 | |
68 SDK.SDKModel.register(SDK.PaintProfilerModel, SDK.Target.Capability.DOM, false); | |
69 | |
30 /** | 70 /** |
31 * @typedef {!{x: number, y: number, picture: string}} | 71 * @typedef {!{x: number, y: number, picture: string}} |
32 */ | 72 */ |
33 SDK.PictureFragment; | 73 SDK.PictureFragment; |
34 | 74 |
35 /** | |
36 * @unrestricted | |
37 */ | |
38 SDK.PaintProfilerSnapshot = class { | 75 SDK.PaintProfilerSnapshot = class { |
39 /** | 76 /** |
40 * @param {!SDK.Target} target | 77 * @param {!SDK.PaintProfilerModel} paintProfilerModel |
41 * @param {string} snapshotId | 78 * @param {string} snapshotId |
42 */ | 79 */ |
43 constructor(target, snapshotId) { | 80 constructor(paintProfilerModel, snapshotId) { |
44 this._target = target; | 81 this._paintProfilerModel = paintProfilerModel; |
45 this._id = snapshotId; | 82 this._id = snapshotId; |
46 this._refCount = 1; | 83 this._refCount = 1; |
47 } | 84 } |
48 | 85 |
49 /** | |
50 * @param {!SDK.Target} target | |
51 * @param {!Array.<!SDK.PictureFragment>} fragments | |
52 * @return {!Promise<?SDK.PaintProfilerSnapshot>} | |
53 */ | |
54 static loadFromFragments(target, fragments) { | |
55 return target.layerTreeAgent().loadSnapshot( | |
56 fragments, (error, snapshotId) => error ? null : new SDK.PaintProfilerSn apshot(target, snapshotId)); | |
57 } | |
58 | |
59 /** | |
60 * @param {!SDK.Target} target | |
61 * @param {string} encodedPicture | |
62 * @return {!Promise<?SDK.PaintProfilerSnapshot>} | |
63 */ | |
64 static load(target, encodedPicture) { | |
65 var fragment = {x: 0, y: 0, picture: encodedPicture}; | |
66 return SDK.PaintProfilerSnapshot.loadFromFragments(target, [fragment]); | |
67 } | |
68 | |
69 release() { | 86 release() { |
70 console.assert(this._refCount > 0, 'release is already called on the object' ); | 87 console.assert(this._refCount > 0, 'release is already called on the object' ); |
71 if (!--this._refCount) | 88 if (!--this._refCount) |
72 this._target.layerTreeAgent().releaseSnapshot(this._id); | 89 this._paintProfilerModel._layerTreeAgent.releaseSnapshot(this._id); |
73 } | 90 } |
74 | 91 |
75 addReference() { | 92 addReference() { |
76 ++this._refCount; | 93 ++this._refCount; |
77 console.assert(this._refCount > 0, 'Referencing a dead object'); | 94 console.assert(this._refCount > 0, 'Referencing a dead object'); |
78 } | 95 } |
79 | 96 |
80 /** | 97 /** |
81 * @return {!SDK.Target} | |
82 */ | |
83 target() { | |
84 return this._target; | |
85 } | |
86 | |
87 /** | |
88 * @param {?number} firstStep | 98 * @param {?number} firstStep |
89 * @param {?number} lastStep | 99 * @param {?number} lastStep |
90 * @param {?number} scale | 100 * @param {?number} scale |
91 * @return {!Promise<?string>} | 101 * @return {!Promise<?string>} |
92 */ | 102 */ |
93 replay(firstStep, lastStep, scale) { | 103 replay(firstStep, lastStep, scale) { |
94 return this._target.layerTreeAgent().replaySnapshot( | 104 return this._paintProfilerModel._layerTreeAgent.replaySnapshot( |
95 this._id, firstStep || undefined, lastStep || undefined, scale || 1.0, ( error, str) => error ? null : str); | 105 this._id, firstStep || undefined, lastStep || undefined, scale || 1.0, ( error, str) => error ? null : str); |
96 } | 106 } |
97 | 107 |
98 /** | 108 /** |
99 * @param {?Protocol.DOM.Rect} clipRect | 109 * @param {?Protocol.DOM.Rect} clipRect |
100 * @param {function(!Array.<!Protocol.LayerTree.PaintProfile>=)} callback | 110 * @param {function(!Array.<!Protocol.LayerTree.PaintProfile>=)} callback |
101 */ | 111 */ |
102 profile(clipRect, callback) { | 112 profile(clipRect, callback) { |
103 var wrappedCallback = | 113 var wrappedCallback = |
104 Protocol.inspectorBackend.wrapClientCallback(callback, 'Protocol.LayerTr ee.profileSnapshot(): '); | 114 Protocol.inspectorBackend.wrapClientCallback(callback, 'Protocol.LayerTr ee.profileSnapshot(): '); |
105 this._target.layerTreeAgent().profileSnapshot(this._id, 5, 1, clipRect || un defined, wrappedCallback); | 115 this._paintProfilerModel._layerTreeAgent.profileSnapshot(this._id, 5, 1, cli pRect || undefined, wrappedCallback); |
106 } | 116 } |
107 | 117 |
108 /** | 118 /** |
109 * @return {!Promise<?Array<!SDK.PaintProfilerLogItem>>} | 119 * @return {!Promise<?Array<!SDK.PaintProfilerLogItem>>} |
110 */ | 120 */ |
111 commandLog() { | 121 commandLog() { |
112 return this._target.layerTreeAgent().snapshotCommandLog(this._id, processLog ); | 122 return this._paintProfilerModel._layerTreeAgent.snapshotCommandLog(this._id, processLog); |
113 | 123 |
114 /** | 124 /** |
115 * @param {?string} error | 125 * @param {?string} error |
116 * @param {?Array<!Object>} log | 126 * @param {?Array<!Object>} log |
117 */ | 127 */ |
118 function processLog(error, log) { | 128 function processLog(error, log) { |
119 if (error) | 129 if (error) |
120 return null; | 130 return null; |
121 return log.map( | 131 return log.map( |
122 (entry, index) => new SDK.PaintProfilerLogItem( | 132 (entry, index) => new SDK.PaintProfilerLogItem( |
123 /** @type {!SDK.RawPaintProfilerLogItem} */ (entry), index)); | 133 /** @type {!SDK.RawPaintProfilerLogItem} */ (entry), index)); |
124 } | 134 } |
125 } | 135 } |
126 }; | 136 }; |
127 | 137 |
128 | |
129 /** | 138 /** |
130 * @typedef {!{method: string, params: ?Object<string, *>}} | 139 * @typedef {!{method: string, params: ?Object<string, *>}} |
131 */ | 140 */ |
132 SDK.RawPaintProfilerLogItem; | 141 SDK.RawPaintProfilerLogItem; |
133 | 142 |
134 /** | 143 /** |
135 * @unrestricted | 144 * @unrestricted |
136 */ | 145 */ |
137 SDK.PaintProfilerLogItem = class { | 146 SDK.PaintProfilerLogItem = class { |
138 /** | 147 /** |
139 * @param {!SDK.RawPaintProfilerLogItem} rawEntry | 148 * @param {!SDK.RawPaintProfilerLogItem} rawEntry |
140 * @param {number} commandIndex | 149 * @param {number} commandIndex |
141 */ | 150 */ |
142 constructor(rawEntry, commandIndex) { | 151 constructor(rawEntry, commandIndex) { |
143 this.method = rawEntry.method; | 152 this.method = rawEntry.method; |
144 this.params = rawEntry.params; | 153 this.params = rawEntry.params; |
145 this.commandIndex = commandIndex; | 154 this.commandIndex = commandIndex; |
146 } | 155 } |
147 }; | 156 }; |
OLD | NEW |