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

Expose willReadFrequently attribute for Canvas2D to improve performance and avoid warnings #1690

Open
Poobslag opened this issue May 23, 2023 · 3 comments

Comments

@Poobslag
Copy link

Poobslag commented May 23, 2023

I am developing an HTML5 game with HaxeFlixel and get numerous warnings in Chrome's developer console:

ImageCanvasUtil.hx:212 Canvas2D: Multiple readback operations using getImageData are faster with the willReadFrequently attribute set to true. See: https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently

This 'willReadFrequently' attribute is not set by ImageCanvasUtil.hx and I do not see any way to set this attribute with the current API.

@player-03
Copy link
Contributor

Pretty sure that would be a net performance loss. Faster reading at the expense of slower rendering.

Unless you're doing something that specifically requires reading from an image but not rendering it directly? Something like BitmapData.copyPixels()?

@Poobslag
Copy link
Author

Poobslag commented May 23, 2023

Pretty sure that would be a net performance loss. Faster reading at the expense of slower rendering.

That is a reasonable prediction and I don't know enough about Canvas2D to debate it. I am simply relaying the warning as communicated by Chrome's developer console, some of the HaxeFlixel demos report many, many Canvas2D warnings with this message.

image

The FlxPieDial Demo reports 33 warnings for example. Most demos report zero. TurnBasedRPG reports one if you play it through to the end.

@player-03
Copy link
Contributor

Are these warnings mainly during setup? Looks like FlxPieDial makes multiple calls to copyPixels(), but I'm pretty sure that's only during setup.

If copyPixels() and similar operations are in fact the culprit, we may want to add an argument to the BitmapData constructor. Let you set it per bitmap. Maybe call the argument willReadFrequently like in JS, or maybe useSoftwareRenderer to be explicit about the effects.

JS was the only one to print a warning, but the hardware/software tradeoff should be comparable on all targets. If we decide to add this, we should make it cross-platform.

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

No branches or pull requests

2 participants