3 ms·
Look first to the spec! The spec says don't check if different for canvas2d: https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-context-mode http
by jdashg 5y ago
Look first to the spec!
The spec says don't check if different for canvas2d:
https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-context-mode https://html.spec.whatwg.org/multipage/canvas.html#concept-c...
> Whenever the width and height content attributes are set, removed, changed, or redundantly set to the value they already have, then the user agent must perform the action from the row of the following table that corresponds to the canvas element's context mode.
> | 2d | Follow the steps to set bitmap dimensions to the numeric values of the width and height content attributes. |
> When the user agent is to set bitmap dimensions to width and height, it must run these steps:
> 1. Reset the rendering context to its default state.
> 2. Resize the output bitmap to the new width and height.
There's opportunity to reuse the previous surface and just clear the contents, but I'm not sure if this is done. (But the reset of state and clear are both mandatory for `.width=.width`)