1 // Copyright (c) 2013 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.
7 tvcm.require('tracing.tracks.process_track_base');
8 tvcm.require('tracing.draw_helpers');
10 tvcm.exportTo('tracing.tracks', function() {
11 var ProcessTrackBase = tracing.tracks.ProcessTrackBase;
16 var ProcessTrack = tvcm.ui.define('process-track', ProcessTrackBase);
18 ProcessTrack.prototype = {
19 __proto__: ProcessTrackBase.prototype,
21 decorate: function(viewport) {
22 tracing.tracks.ProcessTrackBase.prototype.decorate.call(this, viewport);
25 drawTrack: function(type) {
27 case tracing.tracks.DrawType.INSTANT_EVENT:
28 if (!this.processBase.instantEvents ||
29 this.processBase.instantEvents.length === 0)
32 var ctx = this.context();
34 var pixelRatio = window.devicePixelRatio || 1;
35 var bounds = this.getBoundingClientRect();
36 var canvasBounds = ctx.canvas.getBoundingClientRect();
39 ctx.translate(0, pixelRatio * (bounds.top - canvasBounds.top));
41 var dt = this.viewport.currentDisplayTransform;
42 var viewLWorld = dt.xViewToWorld(0);
43 var viewRWorld = dt.xViewToWorld(
44 bounds.width * pixelRatio);
46 tracing.drawInstantSlicesAsLines(
48 this.viewport.currentDisplayTransform,
52 this.processBase.instantEvents,
59 case tracing.tracks.DrawType.BACKGROUND:
60 this.drawBackground_();
61 // Don't bother recursing further, Process is the only level that
66 tracing.tracks.ContainerTrack.prototype.drawTrack.call(this, type);
69 drawBackground_: function() {
70 var ctx = this.context();
71 var canvasBounds = ctx.canvas.getBoundingClientRect();
72 var pixelRatio = window.devicePixelRatio || 1;
75 ctx.fillStyle = '#eee';
76 for (var i = 0; i < this.children.length; ++i) {
77 if (!(this.children[i] instanceof tracing.tracks.Track) ||
78 (this.children[i] instanceof tracing.tracks.SpacingTrack))
85 var bounds = this.children[i].getBoundingClientRect();
86 ctx.fillRect(0, pixelRatio * (bounds.top - canvasBounds.top),
87 ctx.canvas.width, pixelRatio * bounds.height);
91 // Process maps to processBase because we derive from ProcessTrackBase.
92 set process(process) {
93 this.processBase = process;
97 return this.processBase;
100 addIntersectingItemsInRangeToSelectionInWorldSpace: function(
101 loWX, hiWX, viewPixWidthWorld, selection) {
102 function onPickHit(instantEvent) {
103 selection.push(instantEvent);
105 tvcm.iterateOverIntersectingIntervals(this.processBase.instantEvents,
106 function(x) { return x.start; },
107 function(x) { return x.duration; },
109 onPickHit.bind(this));
111 tracing.tracks.ContainerTrack.prototype.
112 addIntersectingItemsInRangeToSelectionInWorldSpace.
113 apply(this, arguments);
116 addClosestEventToSelection: function(worldX, worldMaxDist, loY, hiY,
118 this.addClosestInstantEventToSelection(this.processBase.instantEvents,
119 worldX, worldMaxDist, selection);
120 tracing.tracks.ContainerTrack.prototype.addClosestEventToSelection.
121 apply(this, arguments);
126 ProcessTrack: ProcessTrack