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 /** | 30 /** |
32 * @typedef {!{x: number, y: number, picture: string}} | 31 * @typedef {!{x: number, y: number, picture: string}} |
33 */ | 32 */ |
34 WebInspector.PictureFragment; | 33 WebInspector.PictureFragment; |
35 | 34 |
36 /** | 35 /** |
37 * @constructor | 36 * @unrestricted |
38 * @param {!WebInspector.Target} target | |
39 * @param {string} snapshotId | |
40 */ | 37 */ |
41 WebInspector.PaintProfilerSnapshot = function(target, snapshotId) | 38 WebInspector.PaintProfilerSnapshot = class { |
42 { | 39 /** |
| 40 * @param {!WebInspector.Target} target |
| 41 * @param {string} snapshotId |
| 42 */ |
| 43 constructor(target, snapshotId) { |
43 this._target = target; | 44 this._target = target; |
44 this._id = snapshotId; | 45 this._id = snapshotId; |
45 this._refCount = 1; | 46 this._refCount = 1; |
| 47 } |
| 48 |
| 49 /** |
| 50 * @param {!WebInspector.Target} target |
| 51 * @param {!Array.<!WebInspector.PictureFragment>} fragments |
| 52 * @return {!Promise<?WebInspector.PaintProfilerSnapshot>} |
| 53 */ |
| 54 static loadFromFragments(target, fragments) { |
| 55 return target.layerTreeAgent().loadSnapshot( |
| 56 fragments, (error, snapshotId) => error ? null : new WebInspector.PaintP
rofilerSnapshot(target, snapshotId)); |
| 57 } |
| 58 |
| 59 /** |
| 60 * @param {!WebInspector.Target} target |
| 61 * @param {string} encodedPicture |
| 62 * @return {!Promise<?WebInspector.PaintProfilerSnapshot>} |
| 63 */ |
| 64 static load(target, encodedPicture) { |
| 65 var fragment = {x: 0, y: 0, picture: encodedPicture}; |
| 66 return WebInspector.PaintProfilerSnapshot.loadFromFragments(target, [fragmen
t]); |
| 67 } |
| 68 |
| 69 release() { |
| 70 console.assert(this._refCount > 0, 'release is already called on the object'
); |
| 71 if (!--this._refCount) |
| 72 this._target.layerTreeAgent().releaseSnapshot(this._id); |
| 73 } |
| 74 |
| 75 addReference() { |
| 76 ++this._refCount; |
| 77 console.assert(this._refCount > 0, 'Referencing a dead object'); |
| 78 } |
| 79 |
| 80 /** |
| 81 * @return {!WebInspector.Target} |
| 82 */ |
| 83 target() { |
| 84 return this._target; |
| 85 } |
| 86 |
| 87 /** |
| 88 * @param {?number} firstStep |
| 89 * @param {?number} lastStep |
| 90 * @param {?number} scale |
| 91 * @return {!Promise<?string>} |
| 92 */ |
| 93 replay(firstStep, lastStep, scale) { |
| 94 return this._target.layerTreeAgent().replaySnapshot( |
| 95 this._id, firstStep || undefined, lastStep || undefined, scale || 1.0, (
error, str) => error ? null : str); |
| 96 } |
| 97 |
| 98 /** |
| 99 * @param {?DOMAgent.Rect} clipRect |
| 100 * @param {function(!Array.<!LayerTreeAgent.PaintProfile>=)} callback |
| 101 */ |
| 102 profile(clipRect, callback) { |
| 103 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, 'LayerTr
eeAgent.profileSnapshot(): '); |
| 104 this._target.layerTreeAgent().profileSnapshot(this._id, 5, 1, clipRect || un
defined, wrappedCallback); |
| 105 } |
| 106 |
| 107 /** |
| 108 * @return {!Promise<?Array<!WebInspector.PaintProfilerLogItem>>} |
| 109 */ |
| 110 commandLog() { |
| 111 return this._target.layerTreeAgent().snapshotCommandLog(this._id, processLog
); |
| 112 |
| 113 /** |
| 114 * @param {?string} error |
| 115 * @param {?Array<!Object>} log |
| 116 */ |
| 117 function processLog(error, log) { |
| 118 if (error) |
| 119 return null; |
| 120 return log.map( |
| 121 (entry, index) => new WebInspector.PaintProfilerLogItem( |
| 122 /** @type {!WebInspector.RawPaintProfilerLogItem} */ (entry), inde
x)); |
| 123 } |
| 124 } |
46 }; | 125 }; |
47 | 126 |
48 /** | |
49 * @param {!WebInspector.Target} target | |
50 * @param {!Array.<!WebInspector.PictureFragment>} fragments | |
51 * @return {!Promise<?WebInspector.PaintProfilerSnapshot>} | |
52 */ | |
53 WebInspector.PaintProfilerSnapshot.loadFromFragments = function(target, fragment
s) | |
54 { | |
55 return target.layerTreeAgent().loadSnapshot(fragments, (error, snapshotId) =
> error ? null : new WebInspector.PaintProfilerSnapshot(target, snapshotId)); | |
56 }; | |
57 | |
58 /** | |
59 * @param {!WebInspector.Target} target | |
60 * @param {string} encodedPicture | |
61 * @return {!Promise<?WebInspector.PaintProfilerSnapshot>} | |
62 */ | |
63 WebInspector.PaintProfilerSnapshot.load = function(target, encodedPicture) | |
64 { | |
65 var fragment = { | |
66 x: 0, | |
67 y: 0, | |
68 picture: encodedPicture | |
69 }; | |
70 return WebInspector.PaintProfilerSnapshot.loadFromFragments(target, [fragmen
t]); | |
71 }; | |
72 | |
73 WebInspector.PaintProfilerSnapshot.prototype = { | |
74 release: function() | |
75 { | |
76 console.assert(this._refCount > 0, "release is already called on the obj
ect"); | |
77 if (!--this._refCount) | |
78 this._target.layerTreeAgent().releaseSnapshot(this._id); | |
79 }, | |
80 | |
81 addReference: function() | |
82 { | |
83 ++this._refCount; | |
84 console.assert(this._refCount > 0, "Referencing a dead object"); | |
85 }, | |
86 | |
87 /** | |
88 * @return {!WebInspector.Target} | |
89 */ | |
90 target: function() | |
91 { | |
92 return this._target; | |
93 }, | |
94 | |
95 /** | |
96 * @param {?number} firstStep | |
97 * @param {?number} lastStep | |
98 * @param {?number} scale | |
99 * @return {!Promise<?string>} | |
100 */ | |
101 replay: function(firstStep, lastStep, scale) | |
102 { | |
103 return this._target.layerTreeAgent().replaySnapshot(this._id, firstStep
|| undefined, lastStep || undefined, scale || 1.0, (error, str) => error ? null
: str); | |
104 }, | |
105 | |
106 /** | |
107 * @param {?DOMAgent.Rect} clipRect | |
108 * @param {function(!Array.<!LayerTreeAgent.PaintProfile>=)} callback | |
109 */ | |
110 profile: function(clipRect, callback) | |
111 { | |
112 var wrappedCallback = InspectorBackend.wrapClientCallback(callback, "Lay
erTreeAgent.profileSnapshot(): "); | |
113 this._target.layerTreeAgent().profileSnapshot(this._id, 5, 1, clipRect |
| undefined, wrappedCallback); | |
114 }, | |
115 | |
116 /** | |
117 * @return {!Promise<?Array<!WebInspector.PaintProfilerLogItem>>} | |
118 */ | |
119 commandLog: function() | |
120 { | |
121 return this._target.layerTreeAgent().snapshotCommandLog(this._id, proces
sLog); | |
122 | |
123 /** | |
124 * @param {?string} error | |
125 * @param {?Array<!Object>} log | |
126 */ | |
127 function processLog(error, log) | |
128 { | |
129 if (error) | |
130 return null; | |
131 return log.map((entry, index) => new WebInspector.PaintProfilerLogIt
em(/** @type {!WebInspector.RawPaintProfilerLogItem} */ (entry), index)); | |
132 } | |
133 } | |
134 }; | |
135 | 127 |
136 /** | 128 /** |
137 * @typedef {!{method: string, params: ?Object<string, *>}} | 129 * @typedef {!{method: string, params: ?Object<string, *>}} |
138 */ | 130 */ |
139 WebInspector.RawPaintProfilerLogItem; | 131 WebInspector.RawPaintProfilerLogItem; |
140 | 132 |
141 /** | 133 /** |
142 * @constructor | 134 * @unrestricted |
143 * @param {!WebInspector.RawPaintProfilerLogItem} rawEntry | |
144 * @param {number} commandIndex | |
145 */ | 135 */ |
146 WebInspector.PaintProfilerLogItem = function(rawEntry, commandIndex) | 136 WebInspector.PaintProfilerLogItem = class { |
147 { | 137 /** |
| 138 * @param {!WebInspector.RawPaintProfilerLogItem} rawEntry |
| 139 * @param {number} commandIndex |
| 140 */ |
| 141 constructor(rawEntry, commandIndex) { |
148 this.method = rawEntry.method; | 142 this.method = rawEntry.method; |
149 this.params = rawEntry.params; | 143 this.params = rawEntry.params; |
150 this.commandIndex = commandIndex; | 144 this.commandIndex = commandIndex; |
| 145 } |
151 }; | 146 }; |
OLD | NEW |