Closed Bug 1250090 Opened 8 years ago Closed 8 years ago

Add width and height to CanvasRenderingContext2D

Categories

(Core :: Graphics: Canvas2D, defect)

defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: xidorn, Assigned: fatseng)

References

(Blocks 1 open bug)

Details

(Whiteboard: [gfx-noted])

The HTML spec includes "width" and "height" attribute for CanvasRenderingContext2D to get the dimensions of the canvas. [1]

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 [2]), which hurts the performance because of triggering flush.

[1] https://html.spec.whatwg.org/multipage/scripting.html#2dcontext
[2] https://github.com/mdn/pointer-lock-demo/blob/3f6cfe118e5e2b205314680c69dd94f34978b8ed/app.js#L41
Whiteboard: [gfx-noted]
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. [1]
But found they are in htmlcanvaselement. [2]
Do ctx.canvas.width and ctx.canvas.height also hurt performance?


[1] https://html.spec.whatwg.org/multipage/scripting.html#2dcontext
[2] https://html.spec.whatwg.org/multipage/scripting.html#htmlcanvaselement
Flags: needinfo?(bugzilla)
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: 8 years ago
Flags: needinfo?(bugzilla)
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.