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.
8 <link rel="import" href="/tracing/tracks/process_track_base.html">
9 <link rel="import" href="/tracing/draw_helpers.html">
14 tv.exportTo('tracing.tracks', function() {
15 var ProcessTrackBase = tracing.tracks.ProcessTrackBase;
20 var ProcessTrack = tv.ui.define('process-track', ProcessTrackBase);
22 ProcessTrack.prototype = {
23 __proto__: ProcessTrackBase.prototype,
25 decorate: function(viewport) {
26 tracing.tracks.ProcessTrackBase.prototype.decorate.call(this, viewport);
29 drawTrack: function(type) {
31 case tracing.tracks.DrawType.INSTANT_EVENT:
32 if (!this.processBase.instantEvents ||
33 this.processBase.instantEvents.length === 0)
36 var ctx = this.context();
38 var pixelRatio = window.devicePixelRatio || 1;
39 var bounds = this.getBoundingClientRect();
40 var canvasBounds = ctx.canvas.getBoundingClientRect();
43 ctx.translate(0, pixelRatio * (bounds.top - canvasBounds.top));
45 var dt = this.viewport.currentDisplayTransform;
46 var viewLWorld = dt.xViewToWorld(0);
47 var viewRWorld = dt.xViewToWorld(
48 bounds.width * pixelRatio);
50 tracing.drawInstantSlicesAsLines(
52 this.viewport.currentDisplayTransform,
56 this.processBase.instantEvents,
63 case tracing.tracks.DrawType.BACKGROUND:
64 this.drawBackground_();
65 // Don't bother recursing further, Process is the only level that
70 tracing.tracks.ContainerTrack.prototype.drawTrack.call(this, type);
73 drawBackground_: function() {
74 var ctx = this.context();
75 var canvasBounds = ctx.canvas.getBoundingClientRect();
76 var pixelRatio = window.devicePixelRatio || 1;
79 ctx.fillStyle = '#eee';
80 for (var i = 0; i < this.children.length; ++i) {
81 if (!(this.children[i] instanceof tracing.tracks.Track) ||
82 (this.children[i] instanceof tracing.tracks.SpacingTrack))
89 var bounds = this.children[i].getBoundingClientRect();
90 ctx.fillRect(0, pixelRatio * (bounds.top - canvasBounds.top),
91 ctx.canvas.width, pixelRatio * bounds.height);
95 // Process maps to processBase because we derive from ProcessTrackBase.
96 set process(process) {
97 this.processBase = process;
101 return this.processBase;
104 addIntersectingItemsInRangeToSelectionInWorldSpace: function(
105 loWX, hiWX, viewPixWidthWorld, selection) {
106 function onPickHit(instantEvent) {
107 selection.push(instantEvent);
109 tv.iterateOverIntersectingIntervals(this.processBase.instantEvents,
110 function(x) { return x.start; },
111 function(x) { return x.duration; },
113 onPickHit.bind(this));
115 tracing.tracks.ContainerTrack.prototype.
116 addIntersectingItemsInRangeToSelectionInWorldSpace.
117 apply(this, arguments);
120 addClosestEventToSelection: function(worldX, worldMaxDist, loY, hiY,
122 this.addClosestInstantEventToSelection(this.processBase.instantEvents,
123 worldX, worldMaxDist, selection);
124 tracing.tracks.ContainerTrack.prototype.addClosestEventToSelection.
125 apply(this, arguments);
130 ProcessTrack: ProcessTrack