Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / third_party / trace-viewer / trace_viewer / tracing / tracks / process_track.html
1 <!DOCTYPE html>
2 <!--
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.
6 -->
7
8 <link rel="import" href="/tracing/tracks/process_track_base.html">
9 <link rel="import" href="/tracing/draw_helpers.html">
10
11 <script>
12 'use strict';
13
14 tv.exportTo('tracing.tracks', function() {
15   var ProcessTrackBase = tracing.tracks.ProcessTrackBase;
16
17   /**
18    * @constructor
19    */
20   var ProcessTrack = tv.ui.define('process-track', ProcessTrackBase);
21
22   ProcessTrack.prototype = {
23     __proto__: ProcessTrackBase.prototype,
24
25     decorate: function(viewport) {
26       tracing.tracks.ProcessTrackBase.prototype.decorate.call(this, viewport);
27     },
28
29     drawTrack: function(type) {
30       switch (type) {
31         case tracing.tracks.DrawType.INSTANT_EVENT:
32           if (!this.processBase.instantEvents ||
33               this.processBase.instantEvents.length === 0)
34             break;
35
36           var ctx = this.context();
37
38           var pixelRatio = window.devicePixelRatio || 1;
39           var bounds = this.getBoundingClientRect();
40           var canvasBounds = ctx.canvas.getBoundingClientRect();
41
42           ctx.save();
43           ctx.translate(0, pixelRatio * (bounds.top - canvasBounds.top));
44
45           var dt = this.viewport.currentDisplayTransform;
46           var viewLWorld = dt.xViewToWorld(0);
47           var viewRWorld = dt.xViewToWorld(
48               bounds.width * pixelRatio);
49
50           tracing.drawInstantSlicesAsLines(
51               ctx,
52               this.viewport.currentDisplayTransform,
53               viewLWorld,
54               viewRWorld,
55               bounds.height,
56               this.processBase.instantEvents,
57               1);
58
59           ctx.restore();
60
61           break;
62
63         case tracing.tracks.DrawType.BACKGROUND:
64           this.drawBackground_();
65           // Don't bother recursing further, Process is the only level that
66           // draws backgrounds.
67           return;
68       }
69
70       tracing.tracks.ContainerTrack.prototype.drawTrack.call(this, type);
71     },
72
73     drawBackground_: function() {
74       var ctx = this.context();
75       var canvasBounds = ctx.canvas.getBoundingClientRect();
76       var pixelRatio = window.devicePixelRatio || 1;
77
78       var draw = false;
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))
83           continue;
84
85         draw = !draw;
86         if (!draw)
87           continue;
88
89         var bounds = this.children[i].getBoundingClientRect();
90         ctx.fillRect(0, pixelRatio * (bounds.top - canvasBounds.top),
91             ctx.canvas.width, pixelRatio * bounds.height);
92       }
93     },
94
95     // Process maps to processBase because we derive from ProcessTrackBase.
96     set process(process) {
97       this.processBase = process;
98     },
99
100     get process() {
101       return this.processBase;
102     },
103
104     addIntersectingItemsInRangeToSelectionInWorldSpace: function(
105         loWX, hiWX, viewPixWidthWorld, selection) {
106       function onPickHit(instantEvent) {
107         selection.push(instantEvent);
108       }
109       tv.iterateOverIntersectingIntervals(this.processBase.instantEvents,
110           function(x) { return x.start; },
111           function(x) { return x.duration; },
112           loWX, hiWX,
113           onPickHit.bind(this));
114
115       tracing.tracks.ContainerTrack.prototype.
116           addIntersectingItemsInRangeToSelectionInWorldSpace.
117           apply(this, arguments);
118     },
119
120     addClosestEventToSelection: function(worldX, worldMaxDist, loY, hiY,
121                                          selection) {
122       this.addClosestInstantEventToSelection(this.processBase.instantEvents,
123                                              worldX, worldMaxDist, selection);
124       tracing.tracks.ContainerTrack.prototype.addClosestEventToSelection.
125           apply(this, arguments);
126     }
127   };
128
129   return {
130     ProcessTrack: ProcessTrack
131   };
132 });
133 </script>
134