lime
lime copied to clipboard
Expose willReadFrequently attribute for Canvas2D to improve performance and avoid warnings
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.
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()
?
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.
The FlxPieDial Demo reports 33 warnings for example. Most demos report zero. TurnBasedRPG reports one if you play it through to the end.
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.