Re-enable index-basics-workers test to see if still times
[chromium-blink-merge.git] / tools / cc-frame-viewer / src / tree_quad_view.js
blobbd5c12e0dc31e0b6478b25b5344cf149174fb8b7
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';
7 base.require('ui');
8 base.require('color_mappings');
9 base.require('quad_view');
11 base.exportTo('ccfv', function() {
13   /**
14    * @constructor
15    */
16   function TreeQuadViewSelection(view, tiles) {
17     this.view = view;
18     this.tiles = tiles;
19   }
21   TreeQuadViewSelection.prototype = {
22     activate: function() {
23       this.tiles.forEach(function(tile) {
24         tile.selected = true;
25       });
26       this.view.updateQuads_();
27     },
29     deactivate: function() {
30       this.tiles.forEach(function(tile) {
31         tile.selected = false;
32       });
33       this.view.updateQuads_();
34     }
35   };
37   /**
38    * @constructor
39    */
40   var TreeQuadView = ui.define(ccfv.QuadView);
42   TreeQuadView.prototype = {
43     __proto__: ccfv.QuadView.prototype,
45     decorate: function() {
46       this.which_tree_ = undefined;
47       this.tiles_ = undefined;
48       this.colorMap_ = ccfv.ALL_TILE_COLOR_MAPS[0];
49     },
51     get tiles() {
52       return this.tiles_;
53     },
55     set tiles(tiles) {
56       this.tiles_ = tiles;
57       this.updateQuads_();
58     },
60     get which_tree() {
61       return this.which_tree_;
62     },
64     set which_tree(which_tree) {
65       this.which_tree_ = which_tree;
66       this.updateQuads_();
67     },
69     get colorMap() {
70       return this.colorMap_;
71     },
73     set colorMap(map) {
74       this.colorMap_ = map;
75       this.updateQuads_();
76     },
78     updateQuads_: function() {
79       if (this.which_tree_ === undefined ||
80           !this.tiles_) {
81         this.quads = undefined;
82         return;
83       }
85       var tiles = this.tiles_;
86       var which_tree = this.which_tree_;
88       var quads = [];
89       for (var i = 0; i < tiles.length; i++) {
90         var tile = tiles[i];
91         var priority = tile.priority[which_tree];
92         if (!priority.is_live)
93           continue;
95         var value = this.colorMap_.getValueForTile(tile, priority);
96         var backgroundColor = value !== undefined ?
97           this.colorMap_.getBackgroundColorForValue(value) : undefined;
99         var quad = priority.current_screen_quad;
100         quads.push({
101           backgroundColor: backgroundColor,
102           selected: tile.selected,
103           p1: quad.p1,
104           p2: quad.p2,
105           p3: quad.p3,
106           p4: quad.p4
107         });
108       }
109       this.quads = quads;
110     },
112     createSelection_: function(quadIndices) {
113       var tiles = [];
114       for (var i = 0; i < quadIndices.length; i++)
115         tiles.push(this.tiles_[quadIndices[i]]);
116       return new TreeQuadViewSelection(this, tiles);
117     }
118   }
120   return {
121     TreeQuadView: TreeQuadView,
122     TreeQuadViewSelection: TreeQuadViewSelection,
123   }