Add width and height to CanvasRenderingContext2D

RESOLVED INVALID

Status

()

Core
Canvas: 2D
RESOLVED INVALID
2 years ago
2 years ago

People

(Reporter: xidorn, Assigned: fatseng)

Tracking

(Blocks: 1 bug)

Firefox Tracking Flags

(Not tracked)

Details

(Whiteboard: [gfx-noted])

(Reporter)

Description

2 years ago
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
Blocks: 1119470
Keywords: dev-doc-needed
Whiteboard: [gfx-noted]
(Reporter)

Comment 2

2 years ago
Probably the same. We may just need to expose it in the WebIDL file.

Comment 3

2 years ago
(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

Comment 4

2 years ago
I will assign this bug to Farmer because he is interested in looking into it
Assignee: vliu → fatseng
(Assignee)

Comment 5

2 years ago
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)
(Reporter)

Comment 6

2 years ago
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
Last Resolved: 2 years ago
Flags: needinfo?(bugzilla)
Resolution: --- → INVALID
Keywords: dev-doc-needed
You need to log in before you can comment on or make changes to this bug.