Skip to content
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

Fix accidental settings differences between CanvasRenderingContext2D and OffscreenCanvasRenderingContext2D #10904

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ccameron-chromium
Copy link
Contributor

@ccameron-chromium ccameron-chromium commented Jan 8, 2025

There is a lot of duplicated spec text for CanvasRenderingContext2D and OffscreenCanvasRenderingContext2D, especially related to how CanvasRenderingContext2DSettings is handled.

As with all things that are duplicated, there are accidental divergences. In particular, several members of CanvasRenderingContext2DSettings are accidentally ignored in the OffscreenCanvasRenderingContext2D spec text. Additionally, the getContextAttributes method was accidentally not added to OffscreenCanvasRenderingContext2D when it was added to CanvasRenderingContext2D.

This creates a new mixin interface CanvasSettings. This will unify the accidentally diverged paths, and also prevent this from happening in the future. See details here.

An archeology of where the accidental divergence came from is in this issue. To the extent that original authors are still contact-able, they have confirmed that the divergences were indeed accidental oversights.


/canvas.html ( diff )
/index.html ( diff )

Copy link
Member

@annevk annevk left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning this up!

I wish there was some kind of diffing tool that could easily show me any changes in moved text. That change makes this quite hard to review.

below, have an <dfn data-x="concept-canvas-origin-clean">origin-clean</dfn> flag, which can be
the <code>CanvasRenderingContext2D</code>, <code>OffscreenCanvasRenderingContext2D</code>, and
<code>ImageBitmapRenderingContext</code> objects below,
have an <dfn data-x="concept-canvas-origin-clean">origin-clean</dfn> flag, which can be
set to true or false. Initially, when the <code>canvas</code> element or <code>ImageBitmap</code>
object is created, its bitmap's <span data-x="concept-canvas-origin-clean">origin-clean</span>
flag must be set to true.</p>
Copy link
Member

Choose a reason for hiding this comment

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

Okay to file as a separate issue: should this also initialize it for the rendering contexts?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, this should be looked at holistically across the specs. My first inclination was that this paragraph should be hardened -- instead of reading "as well as some of the bitmaps of rendering contexts, such as ..." it could read "as well as some of the bitmaps of CanvasRenderingContext2D...", thereby being explicit about excluding WebGL and WebGPU. But a more general way could be to define it here for all contexts (and just add a note saying that WebGL and WebGPU will always have origin-clean be true). Do you want to file an issue on this, or should I (I'm still not 100% sure which way I'd prefer for it to go ... for now I just wanted to avoid the inappropriate exclusion of OffscreenCanvasRenderingContext2D).

source Outdated
Comment on lines 65692 to 65697
<p>
The <dfn>canvas settings output bitmap initialization algorithm</dfn>, which is passed
<var>canvas</var> (a <code>CanvasSettings</code> object) and
<var>settings</var> (a <code>CanvasRenderingContext2DSettings</code> object), consists
of running these steps:
</p>
Copy link
Member

Choose a reason for hiding this comment

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

Formatting of start and end tags should match the other paragraphs.

Also, for new algorithms we should follow https://infra.spec.whatwg.org/#algorithm-declaration which means that the types precede the parameter names and don't have parenthesis around them.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks, that makes things much more clear. Updated.

source Outdated
@@ -71338,7 +71357,7 @@ interface <dfn interface>OffscreenCanvas</dfn> : <span>EventTarget</span> {
data-x="offscreencanvas-bitmap">bitmap</span> to reference a newly created bitmap of the same
dimensions and color space as the previous bitmap, and with its pixels initialized to
<span>transparent black</span>, or <span>opaque black</span> if the rendering context's <span
data-x="offscreencontext2d-alpha">alpha</span> flag is set to false.</p>
data-x="concept-canvas-alpha">alpha</span> flag is set to false.</p>
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
data-x="concept-canvas-alpha">alpha</span> flag is set to false.</p>
data-x="concept-canvas-alpha">alpha</span> is false.</p>

(it's not defined as a flag (and shouldn't be as we have moved away from calling things flags))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Incorporated this suggestion.

@annevk
Copy link
Member

annevk commented Jan 13, 2025

cc @whatwg/canvas

@ccameron-chromium
Copy link
Contributor Author

Let me know if there's anything I should do to move this along.

The PRs for canvas-float support and HDR tone mapping both build on top of this, since they live in CanvasRenderingContext2DSettings.

@annevk
Copy link
Member

annevk commented Jan 16, 2025

If @whatwg/canvas has no further comments and OP gets filled out I can merge this Monday.

@ccameron-chromium
Copy link
Contributor Author

OP gets filled out

Sorry for the potentially clueless question, but is what is OP and is it something I should be doing?

@annevk
Copy link
Member

annevk commented Jan 16, 2025

I think it stands for "original post" or something like that. For this PR I'm expecting you to file an MDN issue and a WebKit bug and link them from #10904 (comment). Other people can do this as well, but generally we leave it to the person who created the PR to organize that.

Copy link
Member

@domfarolino domfarolino left a comment

Choose a reason for hiding this comment

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

This looks good, thanks @ccameron-chromium! I've also pushed up some wrapping nits found with specfmt, and I also found another bug with that tool.

@Kaiido
Copy link
Member

Kaiido commented Jan 16, 2025

Just to note, this isn't only an editorial change and I don't think any other implementer has responded yet. The checkbox in the OP shouldn't be checked yet.

@annevk
Copy link
Member

annevk commented Jan 17, 2025

Good call. I think in this case we can assume Chrome given OP and I will say yes for WebKit. Unless Gecko or anyone else objects I think we're good here.

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

Successfully merging this pull request may close these issues.

4 participants