Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Side by Side Diff: tools/cc-frame-viewer/src/model.js

Issue 12287014: [cc-frame-viewer] Show layers and levels of detail (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tools/cc-frame-viewer/src/lthi_view.js ('k') | tools/cc-frame-viewer/src/model/layer_impl.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be 2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file. 3 * found in the LICENSE file.
4 */ 4 */
5 'use strict'; 5 'use strict';
6 6
7 base.require('model.layer_tree_host_impl'); 7 base.require('model.layer_tree_host_impl');
8 8
9 base.exportTo('ccfv', function() { 9 base.exportTo('ccfv', function() {
10 10
11 var constants = ccfv.model.constants;
12
11 function unquoteIfNeeded(val) { 13 function unquoteIfNeeded(val) {
12 if (typeof val !== 'string') 14 if (typeof val !== 'string')
13 return val; 15 return val;
14 if (val[0] == '{' && val[val.length - 1] == '}') { 16 if (val[0] == '{' && val[val.length - 1] == '}') {
15 return JSON.parse(val); 17 return JSON.parse(val);
16 } else { 18 } else {
17 return val; 19 return val;
18 } 20 }
19 } 21 }
20 22
21 /** 23 /**
22 * A generic container for data from a cc trace. 24 * A generic container for data from a cc trace.
23 * 25 *
24 * @constructor 26 * @constructor
25 */ 27 */
26 function Model() { 28 function Model() {
27 this.lthiHistories = {}; 29 this.lthiHistories = {};
28 } 30 }
29 Model.prototype = { 31 Model.prototype = {
30 getOrCreateLTHIHistory: function(id) { 32 getOrCreateLTHIHistory: function(id) {
31 if (this.lthiHistories[id] === undefined) 33 if (this.lthiHistories[id] === undefined)
32 this.lthiHistories[id] = new ccfv.model.LayerTreeHostImplHistory(id); 34 this.lthiHistories[id] = new ccfv.model.LayerTreeHostImplHistory(id);
33 return this.lthiHistories[id]; 35 return this.lthiHistories[id];
34 }, 36 },
35 37
36 initFromTraceEvents: function(trace) { 38 initFromTraceEvents: function(trace) {
37 var importer = new TraceImporter(); 39 var importer = new TraceImporter(this);
38 importer.importTraceIntoModel(this, trace); 40 importer.importTrace(trace);
41 },
42
43 initFromFrameData: function(frameData) {
44 var importer = new TraceImporter(this);
45 importer.importFrameData(frameData);
39 } 46 }
40 }; 47 };
41 48
42 function TraceImporter() { 49 function TraceImporter(model) {
50 this.model = model;
43 }; 51 };
44 52
45 TraceImporter.prototype = { 53 TraceImporter.prototype = {
46 addWarning: function(msg) {}, 54 addWarning: function(msg) {},
47 55
48 importTraceIntoModel: function(model, trace) { 56 importTrace: function(trace) {
49 this.model = model;
50
51 var events = trace.traceEvents; 57 var events = trace.traceEvents;
52 for (var i = 0; i < events.length; i++) { 58 for (var i = 0; i < events.length; i++) {
53 var event = events[i]; 59 var event = events[i];
54 if (event.name == 'Frame') 60 if (event.name == 'Frame') {
55 this.handleFrameEvent(event); 61 if (event.args.frame === 'undefined') {
62 throw new Error(
63 'Expected Frame to have args.frame of type string.');
64 }
65 var frameData = unquoteIfNeeded(event.args.frame);
66 this.importFrameData(frameData);
67 }
56 } 68 }
57 }, 69 },
58 70
59 handleFrameEvent: function(event) { 71 importFrameData: function(frameData) {
60 if (event.args.frame === 'undefined')
61 throw new Error('Expected Frame to have args.frame of type string.');
62 var frameData = unquoteIfNeeded(event.args.frame);
63 72
64 var lthiID; 73 var lthiID;
65 if (frameData.lthi_id === undefined) { 74 if (frameData.lthi_id === undefined) {
66 // Old versions used compositor_instance instead of lthiID. 75 // Old versions used compositor_instance instead of lthiID.
67 if (frameData.compositor_instance === undefined) 76 if (frameData.compositor_instance === undefined)
68 throw new Error('Expected Frame to have a lthi_id field.'); 77 throw new Error('Expected Frame to have a lthi_id field.');
69 lthiID = frameData.compositor_instance; 78 lthiID = frameData.compositor_instance;
70 } else { 79 } else {
71 lthiID = frameData.lthi_id; 80 lthiID = frameData.lthi_id;
72 } 81 }
73 82
74 var lthiHistory = this.model.getOrCreateLTHIHistory(lthiID); 83 var lthiHistory = this.model.getOrCreateLTHIHistory(lthiID);
75 84
76 var lthi = lthiHistory.createNewLTHI(); 85 var lthi = lthiHistory.createNewLTHI();
77 86
78 // Basic properties. 87 // Basic properties.
79 if (frameData.device_viewport_size === undefined) 88 if (frameData.device_viewport_size === undefined)
80 throw new Error('Expected device_viewport'); 89 throw new Error('Expected device_viewport');
81 lthi.deviceViewportSize = frameData.device_viewport_size; 90 lthi.deviceViewportSize = frameData.device_viewport_size;
82 91
83 // Tiles. 92 // Tiles.
84 if (frameData.tiles === undefined) 93 if (frameData.tiles === undefined)
85 throw new Error('Expected tiles'); 94 throw new Error('Expected tiles');
86 frameData.tiles.forEach(function(tile) { 95 frameData.tiles.forEach(function(tile) {
87 this.handleFrameTile(lthi, tile); 96 this.handleFrameTile(lthi, tile);
88 }, this); 97 }, this);
98
99 // Layers
100 var activeTreeLayers = frameData.active_tree || [];
101 activeTreeLayers.forEach(function(layerImpl) {
102 this.handleLayerImpl(lthi, constants.ACTIVE_TREE, layerImpl);
103 }, this);
89 }, 104 },
90 105
91 handleFrameTile: function(lthi, tileData) { 106 handleFrameTile: function(lthi, tileData) {
92 var tileID; 107 var tileID;
93 if (!tileData.id) { 108 if (!tileData.id) {
94 // Some old files dont have id fields. Use picture_pile for backup id. 109 // Some old files dont have id fields. Use picture_pile for backup id.
95 if (!tileData.picture_pile) 110 if (!tileData.picture_pile)
96 throw new Error('Tiles must have id'); 111 throw new Error('Tiles must have id');
97 tileID = tileData.picture_pile; 112 tileID = tileData.picture_pile;
98 } else { 113 } else {
99 tileID = tileData.id; 114 tileID = tileData.id;
100 } 115 }
101 var tile = lthi.getOrCreateTile(tileID); 116 var tile = lthi.getOrCreateTile(tileID);
102 117
118 tile.history.layerID = tileData.layer_id;
103 tile.history.picturePile = tileData.picture_pile; 119 tile.history.picturePile = tileData.picture_pile;
104 tile.history.contentsScale = tileData.contents_scale; 120 tile.history.contentsScale = tileData.contents_scale;
105 121
106 tile.priority[0] = tileData.priority[0]; 122 tile.priority[0] = tileData.priority[0];
107 tile.priority[1] = tileData.priority[1]; 123 tile.priority[1] = tileData.priority[1];
108 tile.managedState = tileData.managed_state; 124 tile.managedState = tileData.managed_state;
125 },
126
127 handleLayerImpl: function(lthi, whichTree, layerImplData) {
128 var layerID;
129 if (!layerImplData.id)
130 throw new Error('LayerImpls must have id');
131 layerID = layerImplData.id;
132
133 var layerImpl = lthi.getTree(whichTree).getOrCreateLayerImpl(layerID);
134 for (var k in layerImplData)
135 layerImpl.args[k] = layerImplData[k];
109 } 136 }
110 }; 137 };
111 138
112 139
113 return { 140 return {
114 Model: Model, 141 Model: Model,
115 } 142 }
116 }); 143 });
117 144
OLDNEW
« no previous file with comments | « tools/cc-frame-viewer/src/lthi_view.js ('k') | tools/cc-frame-viewer/src/model/layer_impl.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698