Repository: mozilla/pdf.js
File: web/base_pdf_page_view.js (JavaScript)

Code before:
        this.#startTime = 0;
        break;
    }
  }

  _createCanvas(onShow, hideUntilComplete = false) {
    const { pageColors } = this;
    const hasHCM = !!(pageColors?.background && pageColors?.foreground);
    const prevCanvas = this.canvas;

    // In HCM, a final filter is applied on the canvas which means that
    // before it's applied we've normal colors. Consequently, to avoid to
    // have a final flash we just display it once all the drawing is done.
    const updateOnFirstShow = !prevCanvas && !hasHCM && !hideUntilComplete;

    let canvas = (this.canvas = document.createElement("canvas"));

    this.#showCanvas = isLastShow => {
      let tempCanvas = this.#tempCanvas;
      if (updateOnFirstShow) {
        if (!isLastShow && this.#minDurationToUpdateCanvas > 0) {
          // We draw on the canvas at 60fps (in using `requestAnimationFrame`),
          // so if the canvas is large, updating it at 60fps can be a way too
          // much and can cause some serious performance issues.
          // To avoid that we only update the canvas every
          // minDurationToUpdateCanvas ms.

          if (Date.now() - this.#startTime < this.#minDurationToUpdateCanvas) {
            return;
          }
          if (!tempCanvas) {
            tempCanvas = this.#tempCanvas = canvas;
            canvas = this.canvas = canvas.cloneNode(false);
            onShow(canvas);
          }
        }

        if (tempCanvas) {
          const ctx = canvas.getContext("2d", {
            alpha: false,
          });
          ctx.drawImage(tempCanvas, 0, 0);
          if (isLastShow) {
            this.#resetTempCanvas();
          } else {
            this.#startTime = Date.now();
          }
          return;
        }

        // Don't add the canvas until the first draw callback, or until

Review comment (suggestion):
Nit: To account for this now longer being a code constant (as in first version of the patch).
```suggestion
          // To avoid that we only update the canvas every
          // `this.#minDurationToUpdateCanvas` ms.
```

Code after:
        this.#startTime = 0;
        break;
    }
  }

  _createCanvas(onShow, hideUntilComplete = false) {
    const { pageColors } = this;
    const hasHCM = !!(pageColors?.background && pageColors?.foreground);
    const prevCanvas = this.canvas;

    // In HCM, a final filter is applied on the canvas which means that
    // before it's applied we've normal colors. Consequently, to avoid to
    // have a final flash we just display it once all the drawing is done.
    const updateOnFirstShow = !prevCanvas && !hasHCM && !hideUntilComplete;

    let canvas = (this.canvas = document.createElement("canvas"));

    this.#showCanvas = isLastShow => {
      if (updateOnFirstShow) {
        let tempCanvas = this.#tempCanvas;
        if (!isLastShow && this.#minDurationToUpdateCanvas > 0) {
          // We draw on the canvas at 60fps (in using `requestAnimationFrame`),
          // so if the canvas is large, updating it at 60fps can be a way too
          // much and can cause some serious performance issues.
          // To avoid that we only update the canvas every
          // `this.#minDurationToUpdateCanvas` ms.

          if (Date.now() - this.#startTime < this.#minDurationToUpdateCanvas) {
            return;
          }
          if (!tempCanvas) {
            tempCanvas = this.#tempCanvas = canvas;
            canvas = this.canvas = canvas.cloneNode(false);
            onShow(canvas);
          }
        }

        if (tempCanvas) {
          const ctx = canvas.getContext("2d", {
            alpha: false,
          });
          ctx.drawImage(tempCanvas, 0, 0);
          if (isLastShow) {
            this.#resetTempCanvas();
          } else {
            this.#startTime = Date.now();
          }
          return;
        }

        // Don't add the canvas until the first draw callback, or until