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('base.color'); | |
8 base.require('model.constants'); | |
9 | |
10 base.exportTo('ccfv', function() { | |
11 var Color = base.Color; | |
12 var constants = ccfv.model.constants; | |
13 | |
14 | |
15 var colorInf = new Color(192, 192, 192, 0.5); | |
16 var colorYes = new Color(0, 255, 0, 0.5); | |
17 | |
18 var colorInfAsString = colorInf.toString(); | |
19 var colorYesAsString = colorYes.toString(); | |
20 | |
21 var allTileColorMaps = [ | |
22 { | |
23 title: 'None', | |
24 getValueForTile: function(tile, priority) { | |
25 return undefined; | |
26 }, | |
27 getBackgroundColorForValue: function(value) { | |
28 }, | |
29 } | |
30 ]; | |
31 | |
32 // time_to_visible_in_seconds. | |
33 var colorRedLo = new Color(255, 0, 0, 1); | |
34 var colorRedHi = new Color(0, 0, 255, 1); | |
35 allTileColorMaps.push({ | |
36 title: 'time_to_visible_in_seconds', | |
37 getValueForTile: function(tile, priority) { | |
38 return priority.time_to_visible_in_seconds; | |
39 }, | |
40 getBackgroundColorForValue: function(value) { | |
41 if (value > 1e9) | |
42 return colorInfAsString; | |
43 var percentage = Math.max(0, value / 10); | |
44 var res = Color.lerpRGBA(colorRedLo, colorRedHi, | |
45 1 - percentage) | |
46 return res.toString(); | |
47 }, | |
48 }); | |
49 | |
50 // Distance. | |
51 var colorGreenLo = new Color(0, 0, 255, 1); | |
52 var colorGreenHi = new Color(0, 255, 0, 1); | |
53 allTileColorMaps.push({ | |
54 title: 'distance_to_visible_in_pixels', | |
55 getValueForTile: function(tile, priority) { | |
56 return priority.distance_to_visible_in_pixels; | |
57 }, | |
58 getBackgroundColorForValue: function(value) { | |
59 if (value > 1e9) | |
60 return colorInfAsString; | |
61 var percentage = Math.max(0, value / 2000); | |
62 var res = Color.lerpRGBA(colorGreenLo, colorGreenHi, | |
63 1 - percentage) | |
64 return res.toString(); | |
65 }, | |
66 }); | |
67 | |
68 // can_use_gpu_memory | |
69 allTileColorMaps.push({ | |
70 title: 'can_use_gpu_memory', | |
71 getValueForTile: function(tile, priority) { | |
72 return tile.managedState.can_use_gpu_memory; | |
73 }, | |
74 getBackgroundColorForValue: function(value) { | |
75 return value ? colorYesAsString : undefined; | |
76 }, | |
77 }); | |
78 | |
79 // has_resource | |
80 allTileColorMaps.push({ | |
81 title: 'has_resource (consuming gpu memory)', | |
82 getValueForTile: function(tile, priority) { | |
83 return tile.managedState.has_resource; | |
84 }, | |
85 getBackgroundColorForValue: function(value) { | |
86 return value ? colorYesAsString : undefined; | |
87 }, | |
88 }); | |
89 | |
90 // bins of various types | |
91 var binToColorAsString = { | |
92 'NOW_BIN': new Color(0, 0, 255, 1).toString(), | |
93 'SOON_BIN': new Color(255, 255, 0, 1).toString(), | |
94 'EVENTUALLY_BIN': new Color(0, 255, 255, 1).toString(), | |
95 'NEVER_BIN': new Color(128, 128, 128, 1).toString(), | |
96 '<unknown TileManagerBin value>': new Color(255, 0, 0, 1).toString() | |
97 }; | |
98 | |
99 allTileColorMaps.push({ | |
100 title: 'bin[HIGH_PRIORITY]', | |
101 getValueForTile: function(tile, priority) { | |
102 var bin = tile.managedState.bin[constants.HIGH_PRIORITY_BIN]; | |
103 if (binToColorAsString[bin] === undefined) | |
104 throw new Error('Something has gone very wrong'); | |
105 return bin; | |
106 }, | |
107 getBackgroundColorForValue: function(value) { | |
108 return binToColorAsString[value]; | |
109 }, | |
110 }); | |
111 | |
112 allTileColorMaps.push({ | |
113 title: 'bin[LOW_PRIORITY]', | |
114 getValueForTile: function(tile, priority) { | |
115 var bin = tile.managedState.bin[constants.LOW_PRIORITY_BIN]; | |
116 if (binToColorAsString[bin] === undefined) | |
117 throw new Error('Something has gone very wrong'); | |
118 return bin; | |
119 }, | |
120 getBackgroundColorForValue: function(value) { | |
121 return binToColorAsString[value]; | |
122 }, | |
123 }); | |
124 | |
125 allTileColorMaps.push({ | |
126 title: 'gpu_memmgr_stats_bin', | |
127 getValueForTile: function(tile, priority) { | |
128 var bin = tile.managedState.gpu_memmgr_stats_bin; | |
129 if (binToColorAsString[bin] === undefined) | |
130 throw new Error('Something has gone very wrong'); | |
131 return bin; | |
132 }, | |
133 getBackgroundColorForValue: function(value) { | |
134 return binToColorAsString[value]; | |
135 }, | |
136 }); | |
137 | |
138 return { | |
139 ALL_TILE_COLOR_MAPS: allTileColorMaps | |
140 }; | |
141 }) | |
OLD | NEW |