Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / cc / layer_tree_host_impl.html
1 <!DOCTYPE html>
2 <!--
3 Copyright (c) 2013 The Chromium Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style license that can be
5 found in the LICENSE file.
6 -->
7
8 <link rel="import" href="/cc/constants.html">
9 <link rel="import" href="/cc/layer_tree_impl.html">
10 <link rel="import" href="/cc/util.html">
11 <link rel="import" href="/tvcm/bbox2.html">
12 <link rel="import" href="/tracing/trace_model/object_instance.html">
13
14 <script>
15 'use strict';
16
17 /**
18  * @fileoverview Provides the LayerTreeHostImpl model-level objects.
19  */
20 tvcm.exportTo('cc', function() {
21   var constants = cc.constants;
22
23   var ObjectSnapshot = tracing.trace_model.ObjectSnapshot;
24   var ObjectInstance = tracing.trace_model.ObjectInstance;
25
26   /**
27    * @constructor
28    */
29   function LayerTreeHostImplSnapshot() {
30     ObjectSnapshot.apply(this, arguments);
31   }
32
33   LayerTreeHostImplSnapshot.prototype = {
34     __proto__: ObjectSnapshot.prototype,
35
36     preInitialize: function() {
37       cc.preInitializeObject(this);
38     },
39
40     initialize: function() {
41       cc.moveRequiredFieldsFromArgsToToplevel(
42           this, ['deviceViewportSize',
43             'activeTree']);
44       cc.moveOptionalFieldsFromArgsToToplevel(
45           this, ['pendingTree',
46             'tiles']);
47
48       if (!this.tiles)
49         this.tiles = [];
50
51       this.activeTree.layerTreeHostImpl = this;
52       this.activeTree.whichTree = constants.ACTIVE_TREE;
53       if (this.pendingTree) {
54         this.pendingTree.layerTreeHostImpl = this;
55         this.pendingTree.whichTree = constants.PENDING_TREE;
56       }
57     },
58
59     /**
60      * Get all of tile scales and their associated names.
61      */
62     getContentsScaleNames: function() {
63       var scales = {};
64       for (var i = 0; i < this.tiles.length; ++i) {
65         var tile = this.tiles[i];
66         // Return scale -> scale name mappings.
67         // Example:
68         //  0.25 -> LOW_RESOLUTION
69         //  1.0 -> HIGH_RESOLUTION
70         //  0.75 -> NON_IDEAL_RESOLUTION
71         scales[tile.contentsScale] = tile.resolution;
72       }
73       return scales;
74     },
75
76     getTree: function(whichTree) {
77       if (whichTree == constants.ACTIVE_TREE)
78         return this.activeTree;
79       if (whichTree == constants.PENDING_TREE)
80         return this.pendingTree;
81       throw new Exception('Unknown tree type + ' + whichTree);
82     },
83
84     get tilesHaveGpuMemoryUsageInfo() {
85       if (this.tilesHaveGpuMemoryUsageInfo_ !== undefined)
86         return this.tilesHaveGpuMemoryUsageInfo_;
87
88       for (var i = 0; i < this.tiles.length; i++) {
89         if (this.tiles[i].gpuMemoryUsageInBytes === undefined)
90           continue;
91         this.tilesHaveGpuMemoryUsageInfo_ = true;
92         return true;
93       }
94       this.tilesHaveGpuMemoryUsageInfo_ = false;
95       return false;
96     },
97
98     get gpuMemoryUsageInBytes() {
99       if (!this.tilesHaveGpuMemoryUsageInfo)
100         return;
101
102       var usage = 0;
103       for (var i = 0; i < this.tiles.length; i++) {
104         var u = this.tiles[i].gpuMemoryUsageInBytes;
105         if (u !== undefined)
106           usage += u;
107       }
108       return usage;
109     }
110   };
111
112   ObjectSnapshot.register('cc::LayerTreeHostImpl', LayerTreeHostImplSnapshot);
113
114   /**
115    * @constructor
116    */
117   function LayerTreeHostImplInstance() {
118     ObjectInstance.apply(this, arguments);
119
120     this.allLayersBBox_ = undefined;
121   }
122
123   LayerTreeHostImplInstance.prototype = {
124     __proto__: ObjectInstance.prototype,
125
126     get allContentsScales() {
127       if (this.allContentsScales_)
128         return this.allContentsScales_;
129
130       var scales = {};
131       for (var tileID in this.allTileHistories_) {
132         var tileHistory = this.allTileHistories_[tileID];
133         scales[tileHistory.contentsScale] = true;
134       }
135       this.allContentsScales_ = tvcm.dictionaryKeys(scales);
136       return this.allContentsScales_;
137     },
138
139     get allLayersBBox() {
140       if (this.allLayersBBox_)
141         return this.allLayersBBox_;
142       var bbox = new tvcm.BBox2();
143       function handleTree(tree) {
144         tree.renderSurfaceLayerList.forEach(function(layer) {
145           bbox.addQuad(layer.layerQuad);
146         });
147       }
148       this.snapshots.forEach(function(lthi) {
149         handleTree(lthi.activeTree);
150         if (lthi.pendingTree)
151           handleTree(lthi.pendingTree);
152       });
153       this.allLayersBBox_ = bbox;
154       return this.allLayersBBox_;
155     }
156   };
157
158   ObjectInstance.register('cc::LayerTreeHostImpl', LayerTreeHostImplInstance);
159
160   return {
161     LayerTreeHostImplSnapshot: LayerTreeHostImplSnapshot,
162     LayerTreeHostImplInstance: LayerTreeHostImplInstance
163
164   };
165 });
166 </script>