Commit 39206f00 authored by dgozman's avatar dgozman Committed by Commit bot

[DevTools] Host paint profiles in PaintProfilerModel

This ensures proper capability check.

BUG=none

Review-Url: https://codereview.chromium.org/2845813003
Cr-Commit-Position: refs/heads/master@{#468108}
parent fd1f401a
......@@ -370,11 +370,9 @@ LayerViewer.PaintProfilerCommandLogView = class extends UI.ThrottledWidget {
}
/**
* @param {?SDK.Target} target
* @param {!Array.<!SDK.PaintProfilerLogItem>} log
*/
setCommandLog(target, log) {
this._target = target;
setCommandLog(log) {
this._log = log;
/** @type {!Map<!SDK.PaintProfilerLogItem>} */
this._treeItemCache = new Map();
......
......@@ -34,7 +34,7 @@ Layers.LayerPaintProfilerView = class extends UI.SplitWidget {
* @this {Layers.LayerPaintProfilerView}
*/
function setSnapshotAndLog(snapshot, log) {
this._logTreeView.setCommandLog(snapshot && snapshot.target(), log || []);
this._logTreeView.setCommandLog(log || []);
this._paintProfilerView.setSnapshotAndLog(snapshot, log || [], null);
if (snapshot)
snapshot.release();
......
......@@ -34,7 +34,9 @@
Layers.LayerTreeModel = class extends SDK.SDKModel {
constructor(target) {
super(target);
this._layerTreeAgent = target.layerTreeAgent();
target.registerLayerTreeDispatcher(new Layers.LayerTreeDispatcher(this));
this._paintProfilerModel = /** @type {!SDK.PaintProfilerModel} */ (target.model(SDK.PaintProfilerModel));
var resourceTreeModel = target.model(SDK.ResourceTreeModel);
if (resourceTreeModel) {
resourceTreeModel.addEventListener(
......@@ -48,7 +50,7 @@ Layers.LayerTreeModel = class extends SDK.SDKModel {
if (!this._enabled)
return;
this._enabled = false;
this.target().layerTreeAgent().disable();
this._layerTreeAgent.disable();
}
enable() {
......@@ -61,8 +63,8 @@ Layers.LayerTreeModel = class extends SDK.SDKModel {
_forceEnable() {
this._lastPaintRectByLayerId = {};
if (!this._layerTree)
this._layerTree = new Layers.AgentLayerTree(this.target());
this.target().layerTreeAgent().enable();
this._layerTree = new Layers.AgentLayerTree(this);
this._layerTreeAgent.enable();
}
/**
......@@ -134,10 +136,11 @@ Layers.LayerTreeModel.Events = {
*/
Layers.AgentLayerTree = class extends SDK.LayerTreeBase {
/**
* @param {?SDK.Target} target
* @param {!Layers.LayerTreeModel} layerTreeModel
*/
constructor(target) {
super(target);
constructor(layerTreeModel) {
super(layerTreeModel.target());
this._layerTreeModel = layerTreeModel;
}
/**
......@@ -186,7 +189,7 @@ Layers.AgentLayerTree = class extends SDK.LayerTreeBase {
if (layer)
layer._reset(layers[i]);
else
layer = new Layers.AgentLayer(this.target(), layers[i]);
layer = new Layers.AgentLayer(this._layerTreeModel, layers[i]);
this._layersById[layerId] = layer;
var backendNodeId = layers[i].backendNodeId;
if (backendNodeId)
......@@ -218,11 +221,11 @@ Layers.AgentLayerTree = class extends SDK.LayerTreeBase {
*/
Layers.AgentLayer = class {
/**
* @param {?SDK.Target} target
* @param {!Layers.LayerTreeModel} layerTreeModel
* @param {!Protocol.LayerTree.Layer} layerPayload
*/
constructor(target, layerPayload) {
this._target = target;
constructor(layerTreeModel, layerPayload) {
this._layerTreeModel = layerTreeModel;
this._reset(layerPayload);
}
......@@ -401,14 +404,9 @@ Layers.AgentLayer = class {
* @param {function(!Array.<string>)} callback
*/
requestCompositingReasons(callback) {
if (!this._target) {
callback([]);
return;
}
var wrappedCallback = Protocol.inspectorBackend.wrapClientCallback(
callback, 'Protocol.LayerTree.reasonsForCompositingLayer(): ', undefined, []);
this._target.layerTreeAgent().compositingReasons(this.id(), wrappedCallback);
this._layerTreeModel._layerTreeAgent.compositingReasons(this.id(), wrappedCallback);
}
/**
......@@ -436,11 +434,11 @@ Layers.AgentLayer = class {
* @return {!Array<!Promise<?SDK.SnapshotWithRect>>}
*/
snapshots() {
var rect = {x: 0, y: 0, width: this.width(), height: this.height()};
var promise = this._target.layerTreeAgent().makeSnapshot(
this.id(), (error, snapshotId) => error || !this._target ?
null :
{rect: rect, snapshot: new SDK.PaintProfilerSnapshot(this._target, snapshotId)});
var promise = this._layerTreeModel._paintProfilerModel.makeSnapshot(this.id()).then(snapshot => {
if (!snapshot)
return null;
return {rect: {x: 0, y: 0, width: this.width(), height: this.height()}, snapshot: snapshot};
});
return [promise];
}
......
......@@ -27,49 +27,66 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/**
* @typedef {!{x: number, y: number, picture: string}}
*/
SDK.PictureFragment;
/**
* @unrestricted
*/
SDK.PaintProfilerSnapshot = class {
SDK.PaintProfilerModel = class extends SDK.SDKModel {
/**
* @param {!SDK.Target} target
* @param {string} snapshotId
*/
constructor(target, snapshotId) {
this._target = target;
this._id = snapshotId;
this._refCount = 1;
constructor(target) {
super(target);
this._layerTreeAgent = target.layerTreeAgent();
}
/**
* @param {!SDK.Target} target
* @param {!Array.<!SDK.PictureFragment>} fragments
* @return {!Promise<?SDK.PaintProfilerSnapshot>}
*/
static loadFromFragments(target, fragments) {
return target.layerTreeAgent().loadSnapshot(
fragments, (error, snapshotId) => error ? null : new SDK.PaintProfilerSnapshot(target, snapshotId));
loadSnapshotFromFragments(fragments) {
return this._layerTreeAgent.loadSnapshot(
fragments, (error, snapshotId) => error ? null : new SDK.PaintProfilerSnapshot(this, snapshotId));
}
/**
* @param {!SDK.Target} target
* @param {string} encodedPicture
* @return {!Promise<?SDK.PaintProfilerSnapshot>}
*/
static load(target, encodedPicture) {
loadSnapshot(encodedPicture) {
var fragment = {x: 0, y: 0, picture: encodedPicture};
return SDK.PaintProfilerSnapshot.loadFromFragments(target, [fragment]);
return this.loadSnapshotFromFragments([fragment]);
}
/**
* @param {string} layerId
* @return {!Promise<?SDK.PaintProfilerSnapshot>}
*/
makeSnapshot(layerId) {
return this._layerTreeAgent.makeSnapshot(
layerId, (error, snapshotId) => error ? null : new SDK.PaintProfilerSnapshot(this, snapshotId));
}
};
SDK.SDKModel.register(SDK.PaintProfilerModel, SDK.Target.Capability.DOM, false);
/**
* @typedef {!{x: number, y: number, picture: string}}
*/
SDK.PictureFragment;
SDK.PaintProfilerSnapshot = class {
/**
* @param {!SDK.PaintProfilerModel} paintProfilerModel
* @param {string} snapshotId
*/
constructor(paintProfilerModel, snapshotId) {
this._paintProfilerModel = paintProfilerModel;
this._id = snapshotId;
this._refCount = 1;
}
release() {
console.assert(this._refCount > 0, 'release is already called on the object');
if (!--this._refCount)
this._target.layerTreeAgent().releaseSnapshot(this._id);
this._paintProfilerModel._layerTreeAgent.releaseSnapshot(this._id);
}
addReference() {
......@@ -77,13 +94,6 @@ SDK.PaintProfilerSnapshot = class {
console.assert(this._refCount > 0, 'Referencing a dead object');
}
/**
* @return {!SDK.Target}
*/
target() {
return this._target;
}
/**
* @param {?number} firstStep
* @param {?number} lastStep
......@@ -91,7 +101,7 @@ SDK.PaintProfilerSnapshot = class {
* @return {!Promise<?string>}
*/
replay(firstStep, lastStep, scale) {
return this._target.layerTreeAgent().replaySnapshot(
return this._paintProfilerModel._layerTreeAgent.replaySnapshot(
this._id, firstStep || undefined, lastStep || undefined, scale || 1.0, (error, str) => error ? null : str);
}
......@@ -102,14 +112,14 @@ SDK.PaintProfilerSnapshot = class {
profile(clipRect, callback) {
var wrappedCallback =
Protocol.inspectorBackend.wrapClientCallback(callback, 'Protocol.LayerTree.profileSnapshot(): ');
this._target.layerTreeAgent().profileSnapshot(this._id, 5, 1, clipRect || undefined, wrappedCallback);
this._paintProfilerModel._layerTreeAgent.profileSnapshot(this._id, 5, 1, clipRect || undefined, wrappedCallback);
}
/**
* @return {!Promise<?Array<!SDK.PaintProfilerLogItem>>}
*/
commandLog() {
return this._target.layerTreeAgent().snapshotCommandLog(this._id, processLog);
return this._paintProfilerModel._layerTreeAgent.snapshotCommandLog(this._id, processLog);
/**
* @param {?string} error
......@@ -125,7 +135,6 @@ SDK.PaintProfilerSnapshot = class {
}
};
/**
* @typedef {!{method: string, params: ?Object<string, *>}}
*/
......
......@@ -204,11 +204,11 @@ Timeline.TimelineDetailsView = class extends UI.VBox {
* @param {!SDK.TracingModel.Event} event
*/
_showEventInPaintProfiler(event) {
const target = SDK.targetManager.mainTarget();
if (!target)
const paintProfilerModel = SDK.targetManager.models(SDK.PaintProfilerModel)[0];
if (!paintProfilerModel)
return;
const paintProfilerView = this._paintProfilerView();
const hasProfileData = paintProfilerView.setEvent(target, event);
const hasProfileData = paintProfilerView.setEvent(paintProfilerModel, event);
if (!hasProfileData)
return;
if (this._tabbedPane.hasTab(Timeline.TimelineDetailsView.Tab.PaintProfiler))
......
......@@ -32,8 +32,8 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget {
this._pendingSnapshot = null;
/** @type {?SDK.TracingModel.Event} */
this._event = null;
/** @type {?SDK.Target} */
this._target = null;
/** @type {?SDK.PaintProfilerModel} */
this._paintProfilerModel = null;
/** @type {?SDK.PaintProfilerSnapshot} */
this._lastLoadedSnapshot = null;
}
......@@ -59,13 +59,13 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget {
}
/**
* @param {!SDK.Target} target
* @param {!SDK.PaintProfilerModel} paintProfilerModel
* @param {!SDK.TracingModel.Event} event
* @return {boolean}
*/
setEvent(target, event) {
setEvent(paintProfilerModel, event) {
this._releaseSnapshot();
this._target = target;
this._paintProfilerModel = paintProfilerModel;
this._pendingSnapshot = null;
this._event = event;
......@@ -85,7 +85,7 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget {
}
_update() {
this._logTreeView.setCommandLog(null, []);
this._logTreeView.setCommandLog([]);
this._paintProfilerView.setSnapshotAndLog(null, [], null);
var snapshotPromise;
......@@ -93,10 +93,9 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget {
snapshotPromise = Promise.resolve({rect: null, snapshot: this._pendingSnapshot});
} else if (this._event.name === TimelineModel.TimelineModel.RecordType.Paint) {
var picture = TimelineModel.TimelineData.forEvent(this._event).picture;
snapshotPromise =
picture.objectPromise()
.then(data => SDK.PaintProfilerSnapshot.load(/** @type {!SDK.Target} */ (this._target), data['skp64']))
.then(snapshot => snapshot && {rect: null, snapshot: snapshot});
snapshotPromise = picture.objectPromise()
.then(data => this._paintProfilerModel.loadSnapshot(data['skp64']))
.then(snapshot => snapshot && {rect: null, snapshot: snapshot});
} else if (this._event.name === TimelineModel.TimelineModel.RecordType.RasterTask) {
snapshotPromise = this._frameModel.rasterTilePromise(this._event);
} else {
......@@ -122,7 +121,7 @@ Timeline.TimelinePaintProfilerView = class extends UI.SplitWidget {
* @this {Timeline.TimelinePaintProfilerView}
*/
function onCommandLogDone(snapshot, clipRect, log) {
this._logTreeView.setCommandLog(snapshot.target(), log || []);
this._logTreeView.setCommandLog(log || []);
this._paintProfilerView.setSnapshotAndLog(snapshot, log || [], clipRect);
}
}
......
......@@ -505,10 +505,11 @@ TimelineModel.LayerPaintEvent = class {
* @return !Promise<?{rect: !Array<number>, snapshot: !SDK.PaintProfilerSnapshot}>}
*/
snapshotPromise() {
var paintProfilerModel = this._target && this._target.model(SDK.PaintProfilerModel);
return this.picturePromise().then(picture => {
if (!picture || !this._target)
if (!picture || !paintProfilerModel)
return null;
return SDK.PaintProfilerSnapshot.load(this._target, picture.serializedPicture)
return paintProfilerModel.loadSnapshot(picture.serializedPicture)
.then(snapshot => snapshot ? {rect: picture.rect, snapshot: snapshot} : null);
});
}
......
......@@ -37,6 +37,7 @@ TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase {
super(target);
/** @type {!Map.<string, !TimelineModel.TracingLayerTile>} */
this._tileById = new Map();
this._paintProfilerModel = target && target.model(SDK.PaintProfilerModel);
}
/**
......@@ -129,7 +130,7 @@ TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase {
if (layer)
layer._reset(payload);
else
layer = new TimelineModel.TracingLayer(this.target(), payload);
layer = new TimelineModel.TracingLayer(this._paintProfilerModel, payload);
this._layersById[payload.layer_id] = layer;
if (payload.owner_node)
layer._setNode(this.backendNodeIdToNode().get(payload.owner_node) || null);
......@@ -160,11 +161,11 @@ TimelineModel.TracingLayerTree = class extends SDK.LayerTreeBase {
*/
TimelineModel.TracingLayer = class {
/**
* @param {?SDK.PaintProfilerModel} paintProfilerModel
* @param {!TimelineModel.TracingLayerPayload} payload
* @param {?SDK.Target} target
*/
constructor(target, payload) {
this._target = target;
constructor(paintProfilerModel, payload) {
this._paintProfilerModel = paintProfilerModel;
this._reset(payload);
}
......@@ -387,14 +388,14 @@ TimelineModel.TracingLayer = class {
var fragments =
pictures.filter(picture => picture && rectsOverlap(picture.rect, targetRect))
.map(picture => ({x: picture.rect[0], y: picture.rect[1], picture: picture.serializedPicture}));
if (!fragments.length || !this._target)
if (!fragments.length || !this._paintProfilerModel)
return null;
var x0 = fragments.reduce((min, item) => Math.min(min, item.x), Infinity);
var y0 = fragments.reduce((min, item) => Math.min(min, item.y), Infinity);
// Rect is in layer content coordinates, make it relative to picture by offsetting to the top left corner.
var rect = {x: targetRect[0] - x0, y: targetRect[1] - y0, width: targetRect[2], height: targetRect[3]};
return SDK.PaintProfilerSnapshot.loadFromFragments(this._target, fragments)
.then(snapshot => snapshot ? {rect: rect, snapshot: snapshot} : null);
return this._paintProfilerModel.loadSnapshotFromFragments(fragments).then(
snapshot => snapshot ? {rect: rect, snapshot: snapshot} : null);
});
/**
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment