Re: [csswg-drafts] [resize-observer] device-pixel-border-box size (#3554)

> "a frame of latency would be acceptable": are you saying you think that it's ok for the canvas to draw wrong for one frame and then fix itself?

> If part of paint needs to run, it's a tough pill to swallow to duplicate that work, which is why a frame of latency allowance helps.

> Alternatively, what about getDeviceRects?

Only being able to obtain the pixel perfect guaranteed size of a canvas asynchronously via an event does not strike as a good enough solution. That will lead to all sorts of crazy patterns where one cannot properly specify the size of a canvas in one block of code, but must do a two stage algorithm to change the size.

Further, the upcoming OffscreenCanvas specification may make such types of two-passers even more difficult, since a Worker cannot know the CSS size of a canvas, so a GL app running in a Worker will already need to postMessage to get the CSS size; ultimately this may become a jungle of async CSS size and device pixel size events ping ponging to get something as innocuous as setting up a canvas size right. Async events tend to lead to needing to carefully audit race conditions with other program flow, especially if user interactions are in the loop, which they often are (enter/exit fullscreen, resizing browser window).

I'd very much be in favor of looking for a `canvas.getDeviceRects()` style of synchronous API that one could use and be done with it. If I understood the conversation above correctly, I find it odd that "browser may need to relayout" was stated as a reason to not be able to implement such synchronous API - after all the [.getBoundingClientRect()](https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect) API already exists and that is not asynchronous either? (Iiuc calling `.getBoundingClientRect()` will require resolving a relayout if one is pending?)

-- 
GitHub Notification of comment by juj
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/3554#issuecomment-504155906 using your GitHub account

Received on Thursday, 20 June 2019 19:39:48 UTC