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

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

Issue 1863883002: DevTools: Fix first paint screenshot. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 months 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
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 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 return; 454 return;
455 var frames = this._filmStripModel.frames(); 455 var frames = this._filmStripModel.frames();
456 if (!frames.length) 456 if (!frames.length)
457 return; 457 return;
458 458
459 var drawGeneration = Symbol("drawGeneration"); 459 var drawGeneration = Symbol("drawGeneration");
460 this._drawGeneration = drawGeneration; 460 this._drawGeneration = drawGeneration;
461 this._imageByFrame(frames[0]).then(image => { 461 this._imageByFrame(frames[0]).then(image => {
462 if (this._drawGeneration !== drawGeneration) 462 if (this._drawGeneration !== drawGeneration)
463 return; 463 return;
464 if (!image.naturalHeight) 464 if (!image.naturalWidth || !image.naturalHeight)
465 return; 465 return;
466 var imageHeight = this._canvas.height - 2 * WebInspector.TimelineFil mStripOverview.Padding; 466 var imageHeight = this._canvas.height - 2 * WebInspector.TimelineFil mStripOverview.Padding;
467 var imageWidth = Math.ceil(imageHeight * image.naturalWidth / image. naturalHeight); 467 var imageWidth = Math.ceil(imageHeight * image.naturalWidth / image. naturalHeight);
468 var popoverScale = Math.min(200 / image.naturalWidth, 1);
469 this._emptyImage = new Image(image.naturalWidth * popoverScale, imag e.naturalHeight * popoverScale);
caseq 2016/04/06 00:00:39 Can we make it evident that the screenshot is not
468 this._drawFrames(imageWidth, imageHeight); 470 this._drawFrames(imageWidth, imageHeight);
469 }); 471 });
470 }, 472 },
471 473
472 /** 474 /**
473 * @param {!WebInspector.FilmStripModel.Frame} frame 475 * @param {!WebInspector.FilmStripModel.Frame} frame
474 * @return {!Promise<!HTMLImageElement>} 476 * @return {!Promise<!HTMLImageElement>}
475 */ 477 */
476 _imageByFrame: function(frame) 478 _imageByFrame: function(frame)
477 { 479 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 var width = this._canvas.width; 511 var width = this._canvas.width;
510 var zeroTime = this._tracingModel.minimumRecordTime(); 512 var zeroTime = this._tracingModel.minimumRecordTime();
511 var spanTime = this._tracingModel.maximumRecordTime() - zeroTime; 513 var spanTime = this._tracingModel.maximumRecordTime() - zeroTime;
512 var scale = spanTime / width; 514 var scale = spanTime / width;
513 var context = this._canvas.getContext("2d"); 515 var context = this._canvas.getContext("2d");
514 var drawGeneration = this._drawGeneration; 516 var drawGeneration = this._drawGeneration;
515 517
516 context.beginPath(); 518 context.beginPath();
517 for (var x = padding; x < width; x += imageWidth + 2 * padding) { 519 for (var x = padding; x < width; x += imageWidth + 2 * padding) {
518 var time = zeroTime + (x + imageWidth / 2) * scale; 520 var time = zeroTime + (x + imageWidth / 2) * scale;
519 var frame = this._frameByTime(time); 521 var frame = this._filmStripModel.frameByTimestamp(time);
522 if (!frame)
523 continue;
520 context.rect(x - 0.5, 0.5, imageWidth + 1, imageHeight + 1); 524 context.rect(x - 0.5, 0.5, imageWidth + 1, imageHeight + 1);
521 this._imageByFrame(frame).then(drawFrameImage.bind(this, x)); 525 this._imageByFrame(frame).then(drawFrameImage.bind(this, x));
522 } 526 }
523 context.strokeStyle = "#ddd"; 527 context.strokeStyle = "#ddd";
524 context.stroke(); 528 context.stroke();
525 529
526 /** 530 /**
527 * @param {number} x 531 * @param {number} x
528 * @param {!HTMLImageElement} image 532 * @param {!HTMLImageElement} image
529 * @this {WebInspector.TimelineFilmStripOverview} 533 * @this {WebInspector.TimelineFilmStripOverview}
530 */ 534 */
531 function drawFrameImage(x, image) 535 function drawFrameImage(x, image)
532 { 536 {
533 // Ignore draws deferred from a previous update call. 537 // Ignore draws deferred from a previous update call.
534 if (this._drawGeneration !== drawGeneration) 538 if (this._drawGeneration !== drawGeneration)
535 return; 539 return;
536 context.drawImage(image, x, 1, imageWidth, imageHeight); 540 context.drawImage(image, x, 1, imageWidth, imageHeight);
537 } 541 }
538 }, 542 },
539 543
540 /** 544 /**
541 * @param {number} time
542 * @return {!WebInspector.FilmStripModel.Frame}
543 */
544 _frameByTime: function(time)
545 {
546 /**
547 * @param {number} time
548 * @param {!WebInspector.FilmStripModel.Frame} frame
549 * @return {number}
550 */
551 function comparator(time, frame)
552 {
553 return time - frame.timestamp;
554 }
555 // Using the first frame to fill the interval between recording start
556 // and a moment the frame is taken.
557 var frames = this._filmStripModel.frames();
558 var index = Math.max(frames.upperBound(time, comparator) - 1, 0);
559 return frames[index];
560 },
561
562 /**
563 * @override 545 * @override
564 * @param {number} x 546 * @param {number} x
565 * @return {!Promise<?Element>} 547 * @return {!Promise<?Element>}
566 */ 548 */
567 popoverElementPromise: function(x) 549 popoverElementPromise: function(x)
568 { 550 {
569 if (!this._filmStripModel || !this._filmStripModel.frames().length) 551 if (!this._filmStripModel || !this._filmStripModel.frames().length)
570 return Promise.resolve(/** @type {?Element} */ (null)); 552 return Promise.resolve(/** @type {?Element} */ (null));
571 553
572 var time = this._calculator.positionToTime(x); 554 var time = this._calculator.positionToTime(x);
573 var frame = this._frameByTime(time); 555 var frame = this._filmStripModel.frameByTimestamp(time);
574 if (frame === this._lastFrame) 556 if (frame === this._lastFrame)
575 return Promise.resolve(this._lastElement); 557 return Promise.resolve(this._lastElement);
576 return this._imageByFrame(frame).then(createFrameElement.bind(this)); 558 var imagePromise = frame ? this._imageByFrame(frame) : Promise.resolve(t his._emptyImage);
559 return imagePromise.then(createFrameElement.bind(this));
577 560
578 /** 561 /**
579 * @this {WebInspector.TimelineFilmStripOverview} 562 * @this {WebInspector.TimelineFilmStripOverview}
580 * @param {!HTMLImageElement} image 563 * @param {!HTMLImageElement} image
581 * @return {?Element} 564 * @return {?Element}
582 */ 565 */
583 function createFrameElement(image) 566 function createFrameElement(image)
584 { 567 {
585 var element = createElementWithClass("div", "frame"); 568 var element = createElementWithClass("div", "frame");
586 element.createChild("div", "thumbnail").appendChild(image); 569 element.createChild("div", "thumbnail").appendChild(image);
587 WebInspector.appendStyle(element, "timeline/timelinePanel.css"); 570 WebInspector.appendStyle(element, "timeline/timelinePanel.css");
588 this._lastFrame = frame; 571 this._lastFrame = frame;
589 this._lastElement = element; 572 this._lastElement = element;
590 return element; 573 return element;
591 } 574 }
592 }, 575 },
593 576
594 /** 577 /**
595 * @override 578 * @override
596 */ 579 */
597 reset: function() 580 reset: function()
598 { 581 {
599 this._lastFrame = null; 582 this._lastFrame = undefined;
600 this._lastElement = null; 583 this._lastElement = null;
601 this._filmStripModel = new WebInspector.FilmStripModel(this._tracingMode l); 584 this._filmStripModel = new WebInspector.FilmStripModel(this._tracingMode l);
602 /** @type {!Map<!WebInspector.FilmStripModel.Frame,!Promise<!HTMLImageEl ement>>} */ 585 /** @type {!Map<!WebInspector.FilmStripModel.Frame,!Promise<!HTMLImageEl ement>>} */
603 this._frameToImagePromise = new Map(); 586 this._frameToImagePromise = new Map();
604 this._imageWidth = 0; 587 this._imageWidth = 0;
605 }, 588 },
606 589
607 __proto__: WebInspector.TimelineEventOverview.prototype 590 __proto__: WebInspector.TimelineEventOverview.prototype
608 } 591 }
609 592
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 counters[group] = this._quantDuration; 812 counters[group] = this._quantDuration;
830 this._callback(counters); 813 this._callback(counters);
831 interval -= this._quantDuration; 814 interval -= this._quantDuration;
832 } 815 }
833 this._counters = []; 816 this._counters = [];
834 this._counters[group] = interval; 817 this._counters[group] = interval;
835 this._lastTime = time; 818 this._lastTime = time;
836 this._remainder = this._quantDuration - interval; 819 this._remainder = this._quantDuration - interval;
837 } 820 }
838 } 821 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698