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

CanvasRenderingContext2D API Improvements #627

Closed
1 task done
mysteryDate opened this issue Apr 27, 2021 · 3 comments
Closed
1 task done

CanvasRenderingContext2D API Improvements #627

mysteryDate opened this issue Apr 27, 2021 · 3 comments
Assignees
Labels
Resolution: satisfied The TAG is satisfied with this design Venue: WHATWG

Comments

@mysteryDate
Copy link

I'm requesting a TAG review of nine improvements to the CanvasRenderingContext2D API.

Canvas is the web’s direct mode rendering solution that closely matches traditional programming models. This is particularly targeted for games and full featured apps. Modern 2D developers sometimes have to fallback to GL for features that are expected to be available in 2D but currently aren’t supported by Canvas 2D. There's a always a balance to be struck when adding new APIs to the web. That said, it's important that Canvas2D is able to address developer's use cases in game development and text manipulation.

The current Canvas 2D API was originally proposed in 2013. Since then, a lot of 2D graphics APIs have appeared and changed what developers expect from a good 2D API. This proposal tries to modernize Canvas 2D API, considering current and future usage of Canvas and considering 3 pillars:

  1. feature parity with other 2D APIs;
  2. access to current capabilities of the Web/CSS;
  3. performance improvement.

Further details:

  • I have reviewed the TAG's Web Platform Design Principles
  • Relevant time constraints or deadlines: Trying to begin an origin trial in chrome for M92, which has a feature freeze on May 7.

We'd prefer the TAG provide feedback as:

💬 leave review feedback as a comment in this issue and @-notify mysteryDate and fserb.

@LeaVerou
Copy link
Member

Hi @mysteryDate & @fserb!

@hober and I took a look at this during a breakout this week.

Overall, we're happy to see that each of these additions is being discussed in various WHATWG HTML issues where you've gotten a lot of feedback from other stakeholders. For instance, the ongoing discussion on the reset() function has been fruitful and we look forward to seeing what conclusion everyone comes to.

Regarding using CSSColorValue for input, and as @plinss already expressed in the Houdini TF discussion on this, we don't think CSSColorValue, as currently specified, is an appropriate object to use here. CSSColorValue is intended to represent CSS syntax in Typed OM, not as a general purpose Color object for the Web Platform. It would require substantial changes to be used in that way. However, there are plans to eventually define a Color object that other APIs can use as input.

On the proposed CSS Text Modifiers, we're concerned about the choice to use camelCased names instead of the actual CSS property names. The names currently proposed are not just camelCased versions of their CSS counterparts (e.g. textLetterSpacing instead of letterSpacing) , but even if they were, there is both mental and coding overhead to converting, compared to being able to use the CSS property verbatim. It might be better to instead expose an API that accepts CSS property names if you are looking to expand the set of CSS properties that you support. The set of properties proposed is also a little surprising, for example font-variant-caps is exposed but none of the other font-variant-* properties, or even font-variant itself.

You've gotten strong implementer feedback that perspective transforms aren't feasible in at least one implementation. Perhaps it's best to leave this for the future, in case that stops being the case later on.

The syntax proposed for SVG filters is strictly less powerful than SVG filters, as pointed out previously by @smfr. Adding APIs that are very similar to other APIs but different in subtle ways is likely to be confusing to authors.

We did not see any issues with any of the other proposed additions.

@mysteryDate
Copy link
Author

Hey @LeaVerou! Thank you so much for the feedback. Very glad to hear that you all are on board with the bulk of these changes. It’s exciting to have the opportunity to make the web platform more expressive and useful! As per your concerns:

CSSColorValue as input:
As @annevk has pointed out in this issue if CSSColorValues can stringify then we can use them as style input without changing anything in the specification. A User Agent could short-circuit this and accept the object as an input, but the code would still work the same with the string translation. Would it be ok to add a note to that effect on the spec?

TextModifiers:
With the original proposal, we were trying to make sure that all text related attributes were prepended by the string text or font, which is the case for current text/font properties on CanvasRenderingContext2D. But we also see the rationale behind keeping the names equivalent to those found in HTMLElement style. Unless there’s any other mention to the contrary, we’ll go ahead and change the two affected ones: textLetterSpacing and textWordSpacing will become letterSpacing and wordSpacing, respectively.

Perspective Transforms:
We’re okay to table this feature for the time being.

SVG Filters:
The under-powering is intentional and based on implementer feedback. As @litherum mentioned here:

if we're going to add filter support, we should start with a small set of popular filters, and only expand the set if compelling needs arise. Also, we should start with the "linked-list" model of filters that the css filter() function accepts, rather than arbitrary graphs that are allowed by SVG.

This is a rather large change and it made sense to bite off a smaller chunk for the time being. The proposed syntax could be trivially extended to support DAGs in the future, by allowing CanvasFilters as parameters values.

One of the major motivations for this feature is to make filters available on WebWorkers with OffscreenCanvas. SVG and CSS are DOM dependent, and not trivially available on WebWorkers and thus a new syntax would already be necessary. This proposal has the advantage of being trivially parseable (as a regular Javascript object) and familiar to Javascript developers. Attribute names are copied verbatim from the SVG implementation also with the goal of being as un-surprising as possible.

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 28, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textWordSpacing. So
that thee attribute name wordSpacing follows the same naming conversion
of other text attributes.

Bug: 1233706

Change-Id: Ic735c7c4617572511fd37fe0928f8919e7fd3f69
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 28, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 28, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textWordSpacing. So
that thee attribute name wordSpacing follows the same naming conversion
of other text attributes.

Bug: 1233706

Change-Id: Ic735c7c4617572511fd37fe0928f8919e7fd3f69
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 28, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textWordSpacing. So
that thee attribute name wordSpacing follows the same naming conversion
of other text attributes.

Bug: 1233706

Change-Id: Ic735c7c4617572511fd37fe0928f8919e7fd3f69
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 28, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 29, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textWordSpacing. So
that thee attribute name wordSpacing follows the same naming conversion
of other text attributes.

Bug: 1233706

Change-Id: Ic735c7c4617572511fd37fe0928f8919e7fd3f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056391
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Commit-Queue: Yi Xu <yiyix@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906470}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 29, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textWordSpacing. So
that thee attribute name wordSpacing follows the same naming conversion
of other text attributes.

Bug: 1233706

Change-Id: Ic735c7c4617572511fd37fe0928f8919e7fd3f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056391
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Commit-Queue: Yi Xu <yiyix@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906470}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 29, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
blueboxd pushed a commit to blueboxd/chromium-legacy that referenced this issue Jul 29, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textWordSpacing. So
that thee attribute name wordSpacing follows the same naming conversion
of other text attributes.

Bug: 1233706

Change-Id: Ic735c7c4617572511fd37fe0928f8919e7fd3f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056391
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Commit-Queue: Yi Xu <yiyix@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906470}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 29, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 29, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056509
Commit-Queue: Yi Xu <yiyix@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906594}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Jul 29, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056509
Commit-Queue: Yi Xu <yiyix@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906594}
pull bot pushed a commit to jamlee-t/chromium that referenced this issue Jul 29, 2021
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056509
Commit-Queue: Yi Xu <yiyix@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906594}
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jul 31, 2021
…s2D.wordSpacing, a=testonly

Automatic update from web-platform-tests
Rename Canvas2D.textWordSpacing to Canvas2D.wordSpacing

Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textWordSpacing. So
that thee attribute name wordSpacing follows the same naming conversion
of other text attributes.

Bug: 1233706

Change-Id: Ic735c7c4617572511fd37fe0928f8919e7fd3f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056391
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Commit-Queue: Yi Xu <yiyix@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906470}

--

wpt-commits: 7666067297aef38ba695aac42f703e627d9c6dd9
wpt-pr: 29821
moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue Jul 31, 2021
…vas2D.letterSpacing, a=testonly

Automatic update from web-platform-tests
Rename Canvas2D.textLetterSpacing to Canvas2D.letterSpacing

Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056509
Commit-Queue: Yi Xu <yiyix@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906594}

--

wpt-commits: 34cb7e900e12fb6b9dc71b6c78d0aa9915dd18d4
wpt-pr: 29822
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Aug 4, 2021
…s2D.wordSpacing, a=testonly

Automatic update from web-platform-tests
Rename Canvas2D.textWordSpacing to Canvas2D.wordSpacing

Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textWordSpacing. So
that thee attribute name wordSpacing follows the same naming conversion
of other text attributes.

Bug: 1233706

Change-Id: Ic735c7c4617572511fd37fe0928f8919e7fd3f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056391
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Commit-Queue: Yi Xu <yiyix@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906470}

--

wpt-commits: 7666067297aef38ba695aac42f703e627d9c6dd9
wpt-pr: 29821
jamienicol pushed a commit to jamienicol/gecko that referenced this issue Aug 4, 2021
…vas2D.letterSpacing, a=testonly

Automatic update from web-platform-tests
Rename Canvas2D.textLetterSpacing to Canvas2D.letterSpacing

Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056509
Commit-Queue: Yi Xu <yiyix@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906594}

--

wpt-commits: 34cb7e900e12fb6b9dc71b6c78d0aa9915dd18d4
wpt-pr: 29822
@torgo torgo added the Progress: propose closing we think it should be closed but are waiting on some feedback or consensus label Aug 26, 2021
@LeaVerou
Copy link
Member

Hi @mysteryDate 👋🏼

@atanassov and I looked at this during a breakout today at our virtual f2f meeting.

CSSColorValue as input:
As @annevk has pointed out in this issue if CSSColorValues can stringify then we can use them as style input without changing anything in the specification. A User Agent could short-circuit this and accept the object as an input, but the code would still work the same with the string translation. Would it be ok to add a note to that effect on the spec?

It seems like an implementation detail, so we aren't sure a note is needed, but if you want to add one, sure, go ahead.

TextModifiers:
With the original proposal, we were trying to make sure that all text related attributes were prepended by the string text or font, which is the case for current text/font properties on CanvasRenderingContext2D. But we also see the rationale behind keeping the names equivalent to those found in HTMLElement style. Unless there’s any other mention to the contrary, we’ll go ahead and change the two affected ones: textLetterSpacing and textWordSpacing will become letterSpacing and wordSpacing, respectively.

We saw there was some pushback to that, because these attributes do not have the same syntax as the corresponding CSS properties.
We still feel these should be named the same as CSS, since the functionality is the same, even if the values are not. It is more consistent that way, and it means that if the syntax is extended in the future to support more types of values, the property name is already harmonized. The fewer concepts that people need to learn, the better. Keeping names the same is better for discoverability and education.

SVG Filters:
The under-powering is intentional and based on implementer feedback. As @litherum mentioned here:

if we're going to add filter support, we should start with a small set of popular filters, and only expand the set if compelling needs arise. Also, we should start with the "linked-list" model of filters that the css filter() function accepts, rather than arbitrary graphs that are allowed by SVG.

This is a rather large change and it made sense to bite off a smaller chunk for the time being. The proposed syntax could be trivially extended to support DAGs in the future, by allowing CanvasFilters as parameters values.

One of the major motivations for this feature is to make filters available on WebWorkers with OffscreenCanvas. SVG and CSS are DOM dependent, and not trivially available on WebWorkers and thus a new syntax would already be necessary. This proposal has the advantage of being trivially parseable (as a regular Javascript object) and familiar to Javascript developers. Attribute names are copied verbatim from the SVG implementation also with the goal of being as un-surprising as possible.

That seems reasonable to us.

Thank you for working with us and being receptive to feedback. Good luck, we look forward to seeing this progress!

@LeaVerou LeaVerou added Resolution: satisfied The TAG is satisfied with this design and removed Progress: in progress Progress: propose closing we think it should be closed but are waiting on some feedback or consensus labels Sep 16, 2021
mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this issue Oct 14, 2022
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textWordSpacing. So
that thee attribute name wordSpacing follows the same naming conversion
of other text attributes.

Bug: 1233706

Change-Id: Ic735c7c4617572511fd37fe0928f8919e7fd3f69
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056391
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Commit-Queue: Yi Xu <yiyix@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906470}
NOKEYCHECK=True
GitOrigin-RevId: 561dd52fd9dd09d1b3c671a08d82f01a98866b1f
mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this issue Oct 14, 2022
Per discussion in w3ctag/design-reviews#627,
we have agreed to remove text prefix for attribute textLetterSpacing. So
that thee attribute name letterSpacing follows the same naming
conversion of other text attributes.

Bug: 1233706

Change-Id: I8b37f046f5cdbfb28848ba3930e047203b061982
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3056509
Commit-Queue: Yi Xu <yiyix@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Reviewed-by: Aaron Krajeski <aaronhk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#906594}
NOKEYCHECK=True
GitOrigin-RevId: c99f03c7e78a893b79d1d51e30913aefc7e9da2a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Resolution: satisfied The TAG is satisfied with this design Venue: WHATWG
Projects
None yet
Development

No branches or pull requests

6 participants