Skip to content

Commit

Permalink
DevTools: Promisify LayersTree protocol domain
Browse files Browse the repository at this point in the history
Bug: 718063
Change-Id: Ib8a33d8eb2f931a50303b2efd0692755cf8e5ebf
Reviewed-on: https://chromium-review.googlesource.com/520725
Reviewed-by: Pavel Feldman <pfeldman@chromium.org>
Reviewed-by: Andrey Kosyakov <caseq@chromium.org>
Commit-Queue: Alexei Filippov <alph@chromium.org>
Cr-Commit-Position: refs/heads/master@{#476322}
  • Loading branch information
a1ph authored and Commit Bot committed Jun 1, 2017
1 parent 81bd492 commit 8e95368
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 64 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,24 @@
{
InspectorTest.requestLayers(onGotLayers);

function onGotLayers()
async function onGotLayers()
{
var layer = InspectorTest.findLayerByNodeIdAttribute("a");
layer.snapshots()[0].then(snapshotWithRect =>
testImageForSnapshot(snapshotWithRect.snapshot, undefined)
.then(() => testImageForSnapshot(snapshotWithRect.snapshot, 0.5))
.then(() => InspectorTest.completeTest()));
var snapshotWithRect = await layer.snapshots()[0];
await testImageForSnapshot(snapshotWithRect.snapshot, undefined);
await testImageForSnapshot(snapshotWithRect.snapshot, 0.5);
InspectorTest.completeTest();
}

function testImageForSnapshot(snapshot, scale)
async function testImageForSnapshot(snapshot, scale)
{
return snapshot.replay(null, null, scale).then(imageURL => new Promise(fulfill => {
var image = new Image();
image.addEventListener("load", () => fulfill(image), false);
image.src = imageURL;
})).then(image => {
InspectorTest.addResult(`Image dimensions at scale ${scale}: ${image.naturalWidth} x ${image.naturalHeight}`);
var imageURL = await snapshot.replay(scale);
var image = await new Promise(fulfill => {
var image = new Image();
image.addEventListener("load", () => fulfill(image), false);
image.src = imageURL;
});
InspectorTest.addResult(`Image dimensions at scale ${scale}: ${image.naturalWidth} x ${image.naturalHeight}`);
}
}
</script>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1174,11 +1174,11 @@ LayerViewer.LayerTextureManager.Tile = class {
* @param {number} scale
* @return {!Promise}
*/
update(glContext, scale) {
async update(glContext, scale) {
this._gl = glContext;
this.scale = scale;
return this.snapshot.replay(null, null, scale).then(imageURL => imageURL && UI.loadImage(imageURL)).then(image => {
this.texture = image && LayerViewer.LayerTextureManager._createTextureForImage(glContext, image);
});
var imageURL = await this.snapshot.replay(scale);
var image = imageURL && await UI.loadImage(imageURL);
this.texture = image && LayerViewer.LayerTextureManager._createTextureForImage(glContext, image);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ LayerViewer.PaintProfilerView = class extends UI.HBox {
* @param {!Array.<!SDK.PaintProfilerLogItem>} log
* @param {?Protocol.DOM.Rect} clipRect
*/
setSnapshotAndLog(snapshot, log, clipRect) {
async setSnapshotAndLog(snapshot, log, clipRect) {
this._reset();
this._snapshot = snapshot;
if (this._snapshot)
Expand All @@ -174,17 +174,13 @@ LayerViewer.PaintProfilerView = class extends UI.HBox {
this._selectionWindow.setEnabled(true);
this._progressBanner.classList.remove('hidden');
this._updateImage();
snapshot.profile(clipRect, onProfileDone.bind(this));
/**
* @param {!Array.<!Protocol.LayerTree.PaintProfile>=} profiles
* @this {LayerViewer.PaintProfilerView}
*/
function onProfileDone(profiles) {
this._progressBanner.classList.add('hidden');
this._profiles = profiles;
this._update();
this._updatePieChart();
}

var profiles = await snapshot.profile(clipRect);

this._progressBanner.classList.add('hidden');
this._profiles = profiles;
this._update();
this._updatePieChart();
}

/**
Expand Down Expand Up @@ -323,15 +319,15 @@ LayerViewer.PaintProfilerView = class extends UI.HBox {

_updateImage() {
delete this._updateImageTimer;
var left = null;
var right = null;
var left;
var right;
var window = this.selectionWindow();
if (this._profiles && this._profiles.length && window) {
left = this._log[window.left].commandIndex;
right = this._log[window.right - 1].commandIndex;
}
var scale = this._pendingScale;
this._snapshot.replay(left, right, scale).then(image => {
this._snapshot.replay(scale, left, right).then(image => {
if (!image)
return;
this._scale = scale;
Expand Down
48 changes: 17 additions & 31 deletions third_party/WebKit/Source/devtools/front_end/sdk/PaintProfiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ SDK.PaintProfilerModel = class extends SDK.SDKModel {
* @param {!Array.<!SDK.PictureFragment>} fragments
* @return {!Promise<?SDK.PaintProfilerSnapshot>}
*/
loadSnapshotFromFragments(fragments) {
return this._layerTreeAgent.loadSnapshot(
fragments, (error, snapshotId) => error ? null : new SDK.PaintProfilerSnapshot(this, snapshotId));
async loadSnapshotFromFragments(fragments) {
var snapshotId = await this._layerTreeAgent.loadSnapshot(fragments);
return snapshotId && new SDK.PaintProfilerSnapshot(this, snapshotId);
}

/**
Expand All @@ -59,9 +59,9 @@ SDK.PaintProfilerModel = class extends SDK.SDKModel {
* @param {string} layerId
* @return {!Promise<?SDK.PaintProfilerSnapshot>}
*/
makeSnapshot(layerId) {
return this._layerTreeAgent.makeSnapshot(
layerId, (error, snapshotId) => error ? null : new SDK.PaintProfilerSnapshot(this, snapshotId));
async makeSnapshot(layerId) {
var snapshotId = await this._layerTreeAgent.makeSnapshot(layerId);
return snapshotId && new SDK.PaintProfilerSnapshot(this, snapshotId);
}
};

Expand Down Expand Up @@ -95,43 +95,29 @@ SDK.PaintProfilerSnapshot = class {
}

/**
* @param {?number} firstStep
* @param {?number} lastStep
* @param {?number} scale
* @param {number=} scale
* @param {number=} firstStep
* @param {number=} lastStep
* @return {!Promise<?string>}
*/
replay(firstStep, lastStep, scale) {
return this._paintProfilerModel._layerTreeAgent.replaySnapshot(
this._id, firstStep || undefined, lastStep || undefined, scale || 1.0, (error, str) => error ? null : str);
replay(scale, firstStep, lastStep) {
return this._paintProfilerModel._layerTreeAgent.replaySnapshot(this._id, firstStep, lastStep, scale || 1.0);
}

/**
* @param {?Protocol.DOM.Rect} clipRect
* @param {function(!Array.<!Protocol.LayerTree.PaintProfile>=)} callback
* @return {!Promise<?Array<!Protocol.LayerTree.PaintProfile>>}
*/
profile(clipRect, callback) {
var wrappedCallback =
Protocol.inspectorBackend.wrapClientCallback(callback, 'Protocol.LayerTree.profileSnapshot(): ');
this._paintProfilerModel._layerTreeAgent.profileSnapshot(this._id, 5, 1, clipRect || undefined, wrappedCallback);
profile(clipRect) {
return this._paintProfilerModel._layerTreeAgent.profileSnapshot(this._id, 5, 1, clipRect || undefined);
}

/**
* @return {!Promise<?Array<!SDK.PaintProfilerLogItem>>}
*/
commandLog() {
return this._paintProfilerModel._layerTreeAgent.snapshotCommandLog(this._id, processLog);

/**
* @param {?string} error
* @param {?Array<!Object>} log
*/
function processLog(error, log) {
if (error)
return null;
return log.map(
(entry, index) => new SDK.PaintProfilerLogItem(
/** @type {!SDK.RawPaintProfilerLogItem} */ (entry), index));
}
async commandLog() {
var log = await this._paintProfilerModel._layerTreeAgent.snapshotCommandLog(this._id);
return log && log.map((entry, index) => new SDK.PaintProfilerLogItem(entry, index));
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ Timeline.TimelineUIUtils = class {
var snapshotWithRect = await new TimelineModel.LayerPaintEvent(event, target).snapshotPromise();
if (!snapshotWithRect)
return null;
var imageURLPromise = snapshotWithRect.snapshot.replay(null, null, 1);
var imageURLPromise = snapshotWithRect.snapshot.replay();
snapshotWithRect.snapshot.release();
var imageURL = await imageURLPromise;
if (!imageURL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"CSS",
"DOMDebugger",
"IndexedDB",
"LayerTree",
])


Expand Down

0 comments on commit 8e95368

Please sign in to comment.