Skip to content

Move getContext call to InternalRenderTask #20016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ryzokuken
Copy link
Collaborator

@ryzokuken ryzokuken commented Jun 17, 2025

Move the getContext call out of _createContext and into InternalRenderTask#initializeGraphics and adapt tests accordingly.

This is a precursor to moving the call into a worker thread to let us use OffscreenCanvas. The current position wouldn't work since we make transformations to the canvas object after the getContext call, which isn't allowed for OffscreenCanvas. Also it isn't allowed to clone or transferControlToOffscreen the canvas after the getContext call.

@ryzokuken ryzokuken self-assigned this Jun 17, 2025
@ryzokuken ryzokuken force-pushed the move-getcontext branch 3 times, most recently from 2027870 to f89b738 Compare June 17, 2025 13:14
@calixteman
Copy link
Contributor

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/e6ca5fca607aefc/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/80c5eb5c6660194/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/e6ca5fca607aefc/output.txt

Total script time: 28.18 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: FAILED
  errors: 3903

Image differences available at: http://54.241.84.105:8877/e6ca5fca607aefc/reftest-analyzer.html#web=eq.log

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/80c5eb5c6660194/output.txt

Total script time: 52.70 mins

  • Unit tests: FAILED
  • Integration Tests: Passed
  • Regression tests: FAILED
  errors: 3903

Image differences available at: http://54.193.163.58:8877/80c5eb5c6660194/reftest-analyzer.html#web=eq.log

@@ -1404,7 +1404,7 @@ class PDFPageProxy {
* resolved when the page finishes rendering.
*/
render({
canvasContext,
canvas,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this an API-breaking change? If so, this patch should either be labeled as [api-minor] with a working fallback and deprecation warning, or as [api-major] if no sensible fallback can be used here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was indeed, which is also why we had all the test breakage. I think with my latest update now some of the test changes can indeed be reverted if you prefer I do that. That said, I made a change that would allow the change to not be breaking (set the default value of canvas to canvasContext.canvas and continue to accept canvasContext).

@ryzokuken ryzokuken force-pushed the move-getcontext branch 4 times, most recently from 19bf452 to 755099d Compare June 25, 2025 14:33
@calixteman
Copy link
Contributor

/botio test

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://54.193.163.58:8877/9ee77ced85e7946/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_test from @calixteman received. Current queue size: 0

Live output at: http://54.241.84.105:8877/425d8c04b161167/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Failed

Full output at http://54.241.84.105:8877/425d8c04b161167/output.txt

Total script time: 30.61 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: Passed

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Windows)


Failed

Full output at http://54.193.163.58:8877/9ee77ced85e7946/output.txt

Total script time: 58.29 mins

  • Unit tests: Passed
  • Integration Tests: FAILED
  • Regression tests: Passed

Copy link
Contributor

@calixteman calixteman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@calixteman calixteman requested a review from timvandermeij June 25, 2025 17:58
Copy link
Contributor

@timvandermeij timvandermeij left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good, but I'd like to have a final look after the comments are addressed just to make sure I didn't miss anything because this involves a (now fortunately non-breaking, so thanks for that!) API change.

* @property {CanvasRenderingContext2D} canvasContext - A 2D context of a DOM
* Canvas object.
* @property {CanvasRenderingContext2D} canvasContext - An optional
* CanvasRenderingContext2D for backwards compatibility.
Copy link
Contributor

@timvandermeij timvandermeij Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should indicate the replacement option here so that users know what to migrate towards. I would suggest "canvasContext - Deprecated 2D context of a DOM Canvas object for backwards compatibility; use the canvas parameter instead."

* @property {CanvasRenderingContext2D} canvasContext - An optional
* CanvasRenderingContext2D for backwards compatibility.
* @property {HTMLCanvasElement} canvas - A DOM Canvas object the default value
* is the canvas associated with the canvasContext paramter above.
Copy link
Contributor

@timvandermeij timvandermeij Jun 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"canvas - A DOM Canvas object. The default value is the canvas associated with the canvasContext parameter if no value is provided explicitly." (fixes the paramter typo and makes it a bit easier to read)

@@ -3131,7 +3146,8 @@ class InternalRenderTask {
this._continueBound = this._continue.bind(this);
this._scheduleNextBound = this._scheduleNext.bind(this);
this._nextBound = this._next.bind(this);
this._canvas = params.canvasContext.canvas;
this._canvas = params.canvas;
this.enableHWA = enableHWA;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this.enableHWA private here (so this._enableHWA) too to limit the API surface, or is it used in the public API somewhere?

@@ -4939,7 +4939,7 @@ Caron Broadcasting, Inc., an Ohio corporation (“Lessee”).`)
viewport.height
);
const renderTask = page.render({
canvasContext: canvasAndCtx.context,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a new test that deliberately uses the legacy canvasContext to keep coverage for it until it's eventually removed, to avoid regressions in that code path.

This is a precursor to moving the call into a
worker thread to let us use `OffscreenCanvas`. The
current position wouldn't work since we make
transformations to the canvas object after the
getContext call, which isn't allowed for
OffscreenCanvas. Also it isn't allowed to clone or
`transferControlToOffscreen` the canvas after the
`getContext` call.
@ryzokuken
Copy link
Collaborator Author

Thanks for the review and the suggestions @timvandermeij. Let me know if you think the test should suffice or if I should expect a few other things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants