Closed Bug 1250090 Opened 5 years ago Closed 5 years ago
Add width and height to Canvas
The HTML spec includes "width" and "height" attribute for CanvasRenderingContext2D to get the dimensions of the canvas.  This would be useful because otherwise there is no efficient way to get the geometry inside the rAF loop. Some apps use clientWidth and clientHeight to get the width and height (e.g. MDN's pointerlock demo ), which hurts the performance because of triggering flush.  https://html.spec.whatwg.org/multipage/scripting.html#2dcontext  https://github.com/mdn/pointer-lock-demo/blob/3f6cfe118e5e2b205314680c69dd94f34978b8ed/app.js#L41
This is different from the width and height that we have today? https://dxr.mozilla.org/mozilla-central/source/dom/canvas/CanvasRenderingContext2D.h#428
Probably the same. We may just need to expose it in the WebIDL file.
(In reply to Xidorn Quan [:xidorn] (UTC+8) from comment #2) > Probably the same. We may just need to expose it in the WebIDL file. I can take this bug for the following things based on requirement.
Assignee: nobody → vliu
I will assign this bug to Farmer because he is interested in looking into it
Assignee: vliu → fatseng
I can't find width and height attributes in CanvasRenderingContext2D spec.  But found they are in htmlcanvaselement.  Do ctx.canvas.width and ctx.canvas.height also hurt performance?  https://html.spec.whatwg.org/multipage/scripting.html#2dcontext  https://html.spec.whatwg.org/multipage/scripting.html#htmlcanvaselement
It seems it is removed a while ago: https://github.com/whatwg/html/pull/1074 And yes, canvas.width / canvas.height should be the right way to go, which I wasn't aware of.
Status: NEW → RESOLVED
Closed: 5 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.