OLD | NEW |
(Empty) | |
| 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 |
| 3 * found in the LICENSE file. |
| 4 */ |
| 5 'use strict'; |
| 6 |
| 7 base.require('model.layer_tree_host_impl'); |
| 8 |
| 9 base.exportTo('ccfv', function() { |
| 10 |
| 11 function unquoteIfNeeded(val) { |
| 12 if (val[0] == '{' && val[val.length - 1] == '}') { |
| 13 return JSON.parse(val); |
| 14 } else { |
| 15 return val; |
| 16 } |
| 17 } |
| 18 |
| 19 /** |
| 20 * A generic container for data from a cc trace. |
| 21 * |
| 22 * @constructor |
| 23 */ |
| 24 function Model() { |
| 25 this.lthiHistories = {}; |
| 26 } |
| 27 Model.prototype = { |
| 28 getOrCreateLTHIHistory: function(id) { |
| 29 if (this.lthiHistories[id] === undefined) |
| 30 this.lthiHistories[id] = new ccfv.model.LayerTreeHostImplHistory(id); |
| 31 return this.lthiHistories[id]; |
| 32 }, |
| 33 |
| 34 initFromTraceEvents: function(trace) { |
| 35 var importer = new TraceImporter(); |
| 36 importer.importTraceIntoModel(this, trace); |
| 37 } |
| 38 }; |
| 39 |
| 40 function TraceImporter() { |
| 41 }; |
| 42 |
| 43 TraceImporter.prototype = { |
| 44 addWarning: function(msg) {}, |
| 45 |
| 46 importTraceIntoModel: function(model, trace) { |
| 47 this.model = model; |
| 48 |
| 49 var events = trace.traceEvents; |
| 50 for (var i = 0; i < events.length; i++) { |
| 51 var event = events[i]; |
| 52 if (event.name == 'Frame') |
| 53 this.handleFrameEvent(event); |
| 54 } |
| 55 }, |
| 56 |
| 57 handleFrameEvent: function(event) { |
| 58 if (typeof event.args.frame !== 'string') |
| 59 throw new Error('Expected Frame to have args.frame of type string.'); |
| 60 var frameData = unquoteIfNeeded(event.args.frame); |
| 61 |
| 62 var lthiID; |
| 63 if (frameData.lthi_id === undefined) { |
| 64 // Old versions used compositor_instance instead of lthiID. |
| 65 if (frameData.compositor_instance === undefined) |
| 66 throw new Error('Expected Frame to have a lthi_id field.'); |
| 67 lthiID = frameData.compositor_instance; |
| 68 } else { |
| 69 lthiID = frameData.lthi_id; |
| 70 } |
| 71 |
| 72 var lthiHistory = this.model.getOrCreateLTHIHistory(lthiID); |
| 73 |
| 74 var lthi = lthiHistory.createNewLTHI(); |
| 75 |
| 76 // Basic properties. |
| 77 if (frameData.device_viewport_size === undefined) |
| 78 throw new Error('Expected device_viewport'); |
| 79 lthi.deviceViewportSize = frameData.device_viewport_size; |
| 80 |
| 81 // Tiles. |
| 82 if (frameData.tiles === undefined) |
| 83 throw new Error('Expected tiles'); |
| 84 frameData.tiles.forEach(function(tile) { |
| 85 this.handleFrameTile(lthi, tile); |
| 86 }, this); |
| 87 }, |
| 88 |
| 89 handleFrameTile: function(lthi, tileData) { |
| 90 var tileID; |
| 91 if (!tileData.id) { |
| 92 // Some old files dont have id fields. Use picture_pile for backup id. |
| 93 if (!tileData.picture_pile) |
| 94 throw new Error('Tiles must have id'); |
| 95 tileID = tileData.picture_pile; |
| 96 } else { |
| 97 tileID = tileData.id; |
| 98 } |
| 99 var tile = lthi.getOrCreateTile(tileID); |
| 100 |
| 101 tile.history.picturePile = tileData.picture_pile; |
| 102 tile.history.contentsScale = tileData.contents_scale; |
| 103 |
| 104 tile.priority[0] = tileData.priority[0]; |
| 105 tile.priority[1] = tileData.priority[1]; |
| 106 tile.managedState = tileData.managed_state; |
| 107 } |
| 108 }; |
| 109 |
| 110 |
| 111 return { |
| 112 Model: Model, |
| 113 } |
| 114 }); |
| 115 |
OLD | NEW |