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, 0.5); |
| 34 var colorRedHi = new Color(0, 0, 255, 0.5); |
| 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, 0.4); |
| 52 var colorGreenHi = new Color(0, 255, 0, 0.4); |
| 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, 0.5).toString(), |
| 93 'SOON_BIN': new Color(255, 255, 0, 0.5).toString(), |
| 94 'EVENTUALLY_BIN': new Color(0, 255, 255, 0.5).toString(), |
| 95 'NEVER_BIN': new Color(128, 128, 128, 0.25).toString() |
| 96 }; |
| 97 |
| 98 allTileColorMaps.push({ |
| 99 title: 'bin[HIGH_PRIORITY]', |
| 100 getValueForTile: function(tile, priority) { |
| 101 var bin = tile.managedState.bin[constants.HIGH_PRIORITY_BIN]; |
| 102 if (binToColorAsString[bin] === undefined) |
| 103 throw new Error('Something has gone very wrong'); |
| 104 return bin; |
| 105 }, |
| 106 getBackgroundColorForValue: function(value) { |
| 107 return binToColorAsString[value]; |
| 108 }, |
| 109 }); |
| 110 |
| 111 allTileColorMaps.push({ |
| 112 title: 'bin[LOW_PRIORITY]', |
| 113 getValueForTile: function(tile, priority) { |
| 114 var bin = tile.managedState.bin[constants.LOW_PRIORITY_BIN]; |
| 115 if (binToColorAsString[bin] === undefined) |
| 116 throw new Error('Something has gone very wrong'); |
| 117 return bin; |
| 118 }, |
| 119 getBackgroundColorForValue: function(value) { |
| 120 return binToColorAsString[value]; |
| 121 }, |
| 122 }); |
| 123 |
| 124 allTileColorMaps.push({ |
| 125 title: 'gpu_memmgr_stats_bin', |
| 126 getValueForTile: function(tile, priority) { |
| 127 var bin = tile.managedState.gpu_memmgr_stats_bin; |
| 128 if (binToColorAsString[bin] === undefined) |
| 129 throw new Error('Something has gone very wrong'); |
| 130 return bin; |
| 131 }, |
| 132 getBackgroundColorForValue: function(value) { |
| 133 return binToColorAsString[value]; |
| 134 }, |
| 135 }); |
| 136 |
| 137 return { |
| 138 ALL_TILE_COLOR_MAPS: allTileColorMaps |
| 139 }; |
| 140 }) |
OLD | NEW |