Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(224)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/timeline/TimelineEventOverview.js

Issue 1503553004: DevTools: Update filmstrip frames on UI scale. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 163
164 WebInspector.TimelineEventOverview.Network.prototype = { 164 WebInspector.TimelineEventOverview.Network.prototype = {
165 /** 165 /**
166 * @override 166 * @override
167 */ 167 */
168 update: function() 168 update: function()
169 { 169 {
170 WebInspector.TimelineEventOverview.prototype.update.call(this); 170 WebInspector.TimelineEventOverview.prototype.update.call(this);
171 var height = this._canvas.height; 171 var height = this._canvas.height;
172 var numBands = categoryBand(WebInspector.TimelineUIUtils.NetworkCategory .Other) + 1; 172 var numBands = categoryBand(WebInspector.TimelineUIUtils.NetworkCategory .Other) + 1;
173 var bandHeight = height / numBands; 173 var bandHeight = Math.floor(height / numBands);
174 if (bandHeight % 1) {
175 console.error("Network strip height should be a multiple of the cate gories number");
176 bandHeight = Math.floor(bandHeight);
177 }
178 var devicePixelRatio = window.devicePixelRatio; 174 var devicePixelRatio = window.devicePixelRatio;
179 var timeOffset = this._model.minimumRecordTime(); 175 var timeOffset = this._model.minimumRecordTime();
180 var timeSpan = this._model.maximumRecordTime() - timeOffset; 176 var timeSpan = this._model.maximumRecordTime() - timeOffset;
181 var canvasWidth = this._canvas.width; 177 var canvasWidth = this._canvas.width;
182 var scale = canvasWidth / timeSpan; 178 var scale = canvasWidth / timeSpan;
183 var ctx = this._context; 179 var ctx = this._context;
184 var requests = this._model.networkRequests(); 180 var requests = this._model.networkRequests();
185 /** @type {!Map<string,!{waiting:!Path2D,transfer:!Path2D}>} */ 181 /** @type {!Map<string,!{waiting:!Path2D,transfer:!Path2D}>} */
186 var paths = new Map(); 182 var paths = new Map();
187 requests.forEach(drawRequest); 183 requests.forEach(drawRequest);
(...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 */ 449 */
454 update: function() 450 update: function()
455 { 451 {
456 WebInspector.TimelineEventOverview.prototype.update.call(this); 452 WebInspector.TimelineEventOverview.prototype.update.call(this);
457 if (!this._filmStripModel) 453 if (!this._filmStripModel)
458 return; 454 return;
459 var frames = this._filmStripModel.frames(); 455 var frames = this._filmStripModel.frames();
460 if (!frames.length) 456 if (!frames.length)
461 return; 457 return;
462 458
463 if (this._imageWidth) { 459 var drawGeneration = Symbol("drawGeneration");
464 this._drawFrames(); 460 this._drawGeneration = drawGeneration;
465 return; 461 this._imageByFrame(frames[0]).then(image => {
466 } 462 if (this._drawGeneration !== drawGeneration)
467
468 this._imageByFrame(frames[0])
469 .then(calculateWidth.bind(this))
470 .then(this._drawFrames.bind(this));
471
472 /**
473 * @this {WebInspector.TimelineFilmStripOverview}
474 * @param {!HTMLImageElement} image
475 */
476 function calculateWidth(image)
477 {
478 var naturalHeight = image.naturalHeight;
479 if (!naturalHeight)
480 return; 463 return;
481 var naturalWidth = image.naturalWidth; 464 if (!image.naturalHeight)
482 this._imageHeight = this._canvas.height - 2 * WebInspector.TimelineF ilmStripOverview.Padding; 465 return;
483 this._imageWidth = Math.ceil(this._imageHeight * naturalWidth / natu ralHeight); 466 var imageHeight = this._canvas.height - 2 * WebInspector.TimelineFil mStripOverview.Padding;
484 } 467 var imageWidth = Math.ceil(imageHeight * image.naturalWidth / image. naturalHeight);
468 this._drawFrames(imageWidth, imageHeight);
469 });
485 }, 470 },
486 471
487 /** 472 /**
488 * @param {!WebInspector.FilmStripModel.Frame} frame 473 * @param {!WebInspector.FilmStripModel.Frame} frame
489 * @return {!Promise<!HTMLImageElement>} 474 * @return {!Promise<!HTMLImageElement>}
490 */ 475 */
491 _imageByFrame: function(frame) 476 _imageByFrame: function(frame)
492 { 477 {
493 var imagePromise = this._frameToImagePromise.get(frame); 478 var imagePromise = this._frameToImagePromise.get(frame);
494 if (!imagePromise) { 479 if (!imagePromise) {
495 imagePromise = frame.imageDataPromise().then(createImage); 480 imagePromise = frame.imageDataPromise().then(createImage);
496 this._frameToImagePromise.set(frame, imagePromise); 481 this._frameToImagePromise.set(frame, imagePromise);
497 } 482 }
498 return imagePromise; 483 return imagePromise;
499 484
500 /** 485 /**
501 * @param {?string} data 486 * @param {?string} data
502 * @return {!Promise<!HTMLImageElement>} 487 * @return {!Promise<!HTMLImageElement>}
503 */ 488 */
504 function createImage(data) 489 function createImage(data)
505 { 490 {
506 var image = /** @type {!HTMLImageElement} */ (createElement("img")); 491 var image = /** @type {!HTMLImageElement} */ (createElement("img"));
507 if (data) 492 if (data)
508 image.src = "data:image/jpg;base64," + data; 493 image.src = "data:image/jpg;base64," + data;
509 return image.completePromise(); 494 return image.completePromise();
510 } 495 }
511 }, 496 },
512 497
513 _drawFrames: function() 498 /**
499 * @param {number} imageWidth
500 * @param {number} imageHeight
501 */
502 _drawFrames: function(imageWidth, imageHeight)
514 { 503 {
515 if (!this._filmStripModel || !this._imageWidth) 504 if (!this._filmStripModel || !imageWidth)
516 return; 505 return;
517 if (!this._filmStripModel.frames().length) 506 if (!this._filmStripModel.frames().length)
518 return; 507 return;
519 var padding = WebInspector.TimelineFilmStripOverview.Padding; 508 var padding = WebInspector.TimelineFilmStripOverview.Padding;
520 var width = this._canvas.width; 509 var width = this._canvas.width;
521 var imageWidth = this._imageWidth;
522 var imageHeight = this._imageHeight;
523 var zeroTime = this._tracingModel.minimumRecordTime(); 510 var zeroTime = this._tracingModel.minimumRecordTime();
524 var spanTime = this._tracingModel.maximumRecordTime() - zeroTime; 511 var spanTime = this._tracingModel.maximumRecordTime() - zeroTime;
525 var scale = spanTime / width; 512 var scale = spanTime / width;
526 var context = this._canvas.getContext("2d"); 513 var context = this._canvas.getContext("2d");
527 var currentDrawGeneration = Symbol("drawGeneration"); 514 var drawGeneration = this._drawGeneration;
528 this._lastDrawGeneration = currentDrawGeneration;
529 515
530 context.beginPath(); 516 context.beginPath();
531 for (var x = padding; x < width; x += imageWidth + 2 * padding) { 517 for (var x = padding; x < width; x += imageWidth + 2 * padding) {
532 var time = zeroTime + (x + imageWidth / 2) * scale; 518 var time = zeroTime + (x + imageWidth / 2) * scale;
533 var frame = this._frameByTime(time); 519 var frame = this._frameByTime(time);
534 context.rect(x - 0.5, 0.5, imageWidth + 1, imageHeight + 1); 520 context.rect(x - 0.5, 0.5, imageWidth + 1, imageHeight + 1);
535 this._imageByFrame(frame).then(drawFrameImage.bind(this, x)); 521 this._imageByFrame(frame).then(drawFrameImage.bind(this, x));
536 } 522 }
537 context.strokeStyle = "#ddd"; 523 context.strokeStyle = "#ddd";
538 context.stroke(); 524 context.stroke();
539 525
540 /** 526 /**
541 * @param {number} x 527 * @param {number} x
542 * @param {!HTMLImageElement} image 528 * @param {!HTMLImageElement} image
543 * @this {WebInspector.TimelineFilmStripOverview} 529 * @this {WebInspector.TimelineFilmStripOverview}
544 */ 530 */
545 function drawFrameImage(x, image) 531 function drawFrameImage(x, image)
546 { 532 {
547 // Ignore draws deferred from a previous update call. 533 // Ignore draws deferred from a previous update call.
548 if (this._lastDrawGeneration !== currentDrawGeneration) 534 if (this._drawGeneration !== drawGeneration)
549 return; 535 return;
550 context.drawImage(image, x, 1, imageWidth, imageHeight); 536 context.drawImage(image, x, 1, imageWidth, imageHeight);
551 } 537 }
552 }, 538 },
553 539
554 /** 540 /**
555 * @param {number} time 541 * @param {number} time
556 * @return {!WebInspector.FilmStripModel.Frame} 542 * @return {!WebInspector.FilmStripModel.Frame}
557 */ 543 */
558 _frameByTime: function(time) 544 _frameByTime: function(time)
(...skipping 284 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 counters[group] = this._quantDuration; 829 counters[group] = this._quantDuration;
844 this._callback(counters); 830 this._callback(counters);
845 interval -= this._quantDuration; 831 interval -= this._quantDuration;
846 } 832 }
847 this._counters = []; 833 this._counters = [];
848 this._counters[group] = interval; 834 this._counters[group] = interval;
849 this._lastTime = time; 835 this._lastTime = time;
850 this._remainder = this._quantDuration - interval; 836 this._remainder = this._quantDuration - interval;
851 } 837 }
852 } 838 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698