OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 | 5 |
6 /** | 6 /** |
7 * @fileoverview Renders an array of slices into the provided div, | 7 * @fileoverview Renders an array of slices into the provided div, |
8 * using a child canvas element. Uses a FastRectRenderer to draw only | 8 * using a child canvas element. Uses a FastRectRenderer to draw only |
9 * the visible slices. | 9 * the visible slices. |
10 */ | 10 */ |
11 cr.define('gpu', function() { | 11 cr.define('tracing', function() { |
12 | 12 |
13 const palletteBase = [ | 13 const palletteBase = [ |
14 {r: 138, g: 113, b: 152}, | 14 {r: 138, g: 113, b: 152}, |
15 {r: 175, g: 112, b: 133}, | 15 {r: 175, g: 112, b: 133}, |
16 {r: 127, g: 135, b: 225}, | 16 {r: 127, g: 135, b: 225}, |
17 {r: 93, g: 81, b: 137}, | 17 {r: 93, g: 81, b: 137}, |
18 {r: 116, g: 143, b: 119}, | 18 {r: 116, g: 143, b: 119}, |
19 {r: 178, g: 214, b: 122}, | 19 {r: 178, g: 214, b: 122}, |
20 {r: 87, g: 109, b: 147}, | 20 {r: 87, g: 109, b: 147}, |
21 {r: 119, g: 155, b: 95}, | 21 {r: 119, g: 155, b: 95}, |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 } | 269 } |
270 ctx.strokeStyle = 'rgba(255,0,0,0.25)'; | 270 ctx.strokeStyle = 'rgba(255,0,0,0.25)'; |
271 ctx.stroke(); | 271 ctx.stroke(); |
272 } | 272 } |
273 | 273 |
274 // begin rendering in world space | 274 // begin rendering in world space |
275 ctx.save(); | 275 ctx.save(); |
276 vp.applyTransformToCanavs(ctx); | 276 vp.applyTransformToCanavs(ctx); |
277 | 277 |
278 // tracks | 278 // tracks |
279 var tr = new gpu.FastRectRenderer(ctx, viewLWorld, 2 * pixWidth, | 279 var tr = new tracing.FastRectRenderer(ctx, viewLWorld, 2 * pixWidth, |
280 2 * pixWidth, viewRWorld, pallette); | 280 2 * pixWidth, viewRWorld, pallette); |
281 tr.setYandH(0, canvasH); | 281 tr.setYandH(0, canvasH); |
282 var slices = this.slices_; | 282 var slices = this.slices_; |
283 for (var i = 0; i < slices.length; ++i) { | 283 for (var i = 0; i < slices.length; ++i) { |
284 var slice = slices[i]; | 284 var slice = slices[i]; |
285 var x = slice.start; | 285 var x = slice.start; |
286 // Less than 0.001 causes short events to disappear when zoomed in. | 286 // Less than 0.001 causes short events to disappear when zoomed in. |
287 var w = Math.max(slice.duration, 0.001); | 287 var w = Math.max(slice.duration, 0.001); |
288 var colorId; | 288 var colorId; |
289 colorId = slice.selected ? | 289 colorId = slice.selected ? |
290 slice.colorId + selectedIdBoost : | 290 slice.colorId + selectedIdBoost : |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 * @param {number} wY Y location to search at, in offset space. | 352 * @param {number} wY Y location to search at, in offset space. |
353 * offset space. | 353 * offset space. |
354 * @param {function():*} onHitCallback Callback to call with the slice, | 354 * @param {function():*} onHitCallback Callback to call with the slice, |
355 * if one is found. | 355 * if one is found. |
356 * @return {boolean} true if a slice was found, otherwise false. | 356 * @return {boolean} true if a slice was found, otherwise false. |
357 */ | 357 */ |
358 pick: function(wX, wY, onHitCallback) { | 358 pick: function(wX, wY, onHitCallback) { |
359 var clientRect = this.getBoundingClientRect(); | 359 var clientRect = this.getBoundingClientRect(); |
360 if (wY < clientRect.top || wY >= clientRect.bottom) | 360 if (wY < clientRect.top || wY >= clientRect.bottom) |
361 return false; | 361 return false; |
362 var x = gpu.findLowIndexInSortedIntervals(this.slices_, | 362 var x = tracing.findLowIndexInSortedIntervals(this.slices_, |
363 function(x) { return x.start; }, | 363 function(x) { return x.start; }, |
364 function(x) { return x.duration; }, | 364 function(x) { return x.duration; }, |
365 wX); | 365 wX); |
366 if (x >= 0 && x < this.slices_.length) { | 366 if (x >= 0 && x < this.slices_.length) { |
367 onHitCallback('slice', this, this.slices_[x]); | 367 onHitCallback('slice', this, this.slices_[x]); |
368 return true; | 368 return true; |
369 } | 369 } |
370 return false; | 370 return false; |
371 }, | 371 }, |
372 | 372 |
(...skipping 14 matching lines...) Expand all Loading... |
387 var clientRect = this.getBoundingClientRect(); | 387 var clientRect = this.getBoundingClientRect(); |
388 var a = Math.max(loY, clientRect.top); | 388 var a = Math.max(loY, clientRect.top); |
389 var b = Math.min(hiY, clientRect.bottom); | 389 var b = Math.min(hiY, clientRect.bottom); |
390 if (a > b) | 390 if (a > b) |
391 return; | 391 return; |
392 | 392 |
393 var that = this; | 393 var that = this; |
394 function onPickHit(slice) { | 394 function onPickHit(slice) { |
395 onHitCallback('slice', that, slice); | 395 onHitCallback('slice', that, slice); |
396 } | 396 } |
397 gpu.iterateOverIntersectingIntervals(this.slices_, | 397 tracing.iterateOverIntersectingIntervals(this.slices_, |
398 function(x) { return x.start; }, | 398 function(x) { return x.start; }, |
399 function(x) { return x.duration; }, | 399 function(x) { return x.duration; }, |
400 loWX, hiWX, | 400 loWX, hiWX, |
401 onPickHit); | 401 onPickHit); |
402 }, | 402 }, |
403 | 403 |
404 /** | 404 /** |
405 * Find the index for the given slice. | 405 * Find the index for the given slice. |
406 * @return {index} Index of the given slice, or undefined. | 406 * @return {index} Index of the given slice, or undefined. |
407 * @private | 407 * @private |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
449 return index != undefined ? this.slices_[index] : undefined; | 449 return index != undefined ? this.slices_[index] : undefined; |
450 }, | 450 }, |
451 | 451 |
452 }; | 452 }; |
453 | 453 |
454 return { | 454 return { |
455 TimelineSliceTrack: TimelineSliceTrack, | 455 TimelineSliceTrack: TimelineSliceTrack, |
456 TimelineThreadTrack: TimelineThreadTrack | 456 TimelineThreadTrack: TimelineThreadTrack |
457 }; | 457 }; |
458 }); | 458 }); |
OLD | NEW |