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

The CSS Working Group just discussed `ResizeObserver Device Pixel Border Box`.

<details><summary>The full IRC log of that discussion</summary>
&lt;fantasai> Topic: ResizeObserver Device Pixel Border Box<br>
&lt;fantasai> ScribeNick: fantasai<br>
&lt;fantasai> chrishtr: device-pixel-border-box is the actual device pixel bounds of a canvas element<br>
&lt;fantasai> chrishtr: including pixel-snapping feature which is ued by browsers to avoid blurriness by snapping to pixel grid<br>
&lt;fantasai> chrishtr: fundamental problem with no complete solution<br>
&lt;fantasai> chrishtr: authors that use canvas<br>
&lt;fantasai> chrishtr: have no reliable method to determine on-screen pixel size of the canvase<br>
&lt;fantasai> chrishtr: if off by one pixel due to pixel-snapping, rounding, or other issue<br>
&lt;fantasai> chrishtr: will end up with wrong or blurry results<br>
&lt;fantasai> chrishtr: pixel-snapping is intentionally not specced to allow UAs to do their best<br>
&lt;fantasai> chrishtr: acocunt for varying rendering architecture<br>
&lt;fantasai> chrishtr: and evolution<br>
&lt;fantasai> chrishtr: so no way to reliably find this size<br>
&lt;fantasai> chrishtr: proposal is to add a box that observes device pixel border box<br>
&lt;fantasai> chrishtr: to ResizeObserver<br>
&lt;fantasai> chrishtr: which will notify if that box changes<br>
&lt;fantasai> chrishtr: will happen at similar timing as other ResizeObserver<br>
&lt;astearns> github: https://github.com/w3c/csswg-drafts/issues/3554<br>
&lt;fantasai> chrishtr: there were two main objections to adding this<br>
&lt;fantasai> chrishtr: one was raised by Jeff Gilbert<br>
&lt;fantasai> chrishtr: had a long discussion with him and Kem Russel, our WebGL expert (?)<br>
&lt;fantasai> chrishtr: have a compromise proposal that both of us agree to<br>
&lt;heycam> s/Kem Russel/Ken Russell/<br>
&lt;fantasai> chrishtr: objection he raised was that if you have a WebGL-centric application<br>
&lt;fantasai> chrishtr: e.g. full-screen game that uses WebAssembly and only DOM in minimal way<br>
&lt;fantasai> chrishtr: want to have a continuous requestAnimationFrame loop<br>
&lt;fantasai> chrishtr: drawing the canvas<br>
&lt;fantasai> chrishtr: in that model where you are canvas-centric<br>
&lt;fantasai> chrishtr: it still lives in a DOM shell or browser window that has a size<br>
&lt;fantasai> chrishtr: need to observe that size<br>
&lt;fantasai> chrishtr: where pixel snapping will work<br>
&lt;fantasai> chrishtr: but ... not in JS<br>
&lt;heycam> s/.../in Web Assembly/<br>
&lt;fantasai> chrishtr: most convenient to query device border box directly from canvas during rAF loop<br>
&lt;fantasai> chrishtr: rather than by observer<br>
&lt;fantasai> chrishtr: if layout was dirty at the time during making the query, it will force layout and other things in order to compute pixel snapping<br>
&lt;fantasai> chrishtr: in taht use case maybe it's OK<br>
&lt;fantasai> chrishtr: other use case, which I was most focused on<br>
&lt;fantasai> chrishtr: you have canvas element embedded in a DOM-centric website<br>
&lt;fantasai> chrishtr: maybe photo-app or ad or widget,<br>
&lt;fantasai> chrishtr: potential multi-actor scenario<br>
&lt;fantasai> chrishtr: want to avoid layout thrashing<br>
&lt;fantasai> chrishtr: cases for which ResizeObserver was designed<br>
&lt;fantasai> chrishtr: this makes most sense<br>
&lt;fantasai> chrishtr: compromise proposal is that we just have both APIs<br>
&lt;fantasai> chrishtr: The End! :D<br>
&lt;fantasai> jeff: ....<br>
&lt;fantasai> jgilbert: ... moving forward with both propsoals works out<br>
&lt;fantasai> jgilbert: having it be in ResizeObserver also makes sense<br>
&lt;fantasai> jgilbert: like you went over, there was some concerns about it covering espeically more easily some more trivial cases<br>
&lt;fantasai> jgilbert: having both lets people pick and choose appropriate API<br>
&lt;fantasai> jgilbert: default should be to use ResizeObserver, most reliable<br>
&lt;fantasai> jgilbert: kindof like getClientBOundingRect() , need to be careful if calling that often<br>
&lt;fantasai> jgilbert: maybe warn in UA<br>
&lt;fantasai> jgilbert: if called too often<br>
&lt;fantasai> jgilbert: but getDeviceClientRect() API alone ...<br>
&lt;fantasai> chrishtr: 2nd objection smfr raised<br>
&lt;fantasai> chrishtr: pixel-snapping requires more information than just layout in today's engines<br>
&lt;fantasai> chrishtr: in Chrome requires pre-paint step<br>
&lt;fantasai> chrishtr: in Safari requires paint<br>
&lt;fantasai> chrishtr: don't have solution to that problem<br>
&lt;fantasai> chrishtr: just note readback method for rAF<br>
&lt;fantasai> chrishtr: canvas.getThing<br>
&lt;fantasai> chrishtr: also has to run the same steps<br>
&lt;fantasai> Rossen_: but that's not blocking to accept the proposla<br>
&lt;fantasai> smfr: in some ways make sit worse<br>
&lt;fantasai> smfr: because 2 places we have to do this painting calculation<br>
&lt;fantasai> Rossen_: was asking if this second objection is blocking accepting the proposal<br>
&lt;fantasai> smfr: so to clarify the proposal is having API to return the box on canvas and also in ResizeObserver<br>
&lt;fantasai> smfr: I'm not a fan of doing partial paitn to get this info<br>
&lt;fantasai> smfr: I would expect for games , especially in full-screen, to position on ? boundaries<br>
&lt;fantasai> smfr: surprised if using fractional pixel positioning<br>
&lt;fantasai> jgilbert: for full-screen, unlikely, but for partial screen almost always get this<br>
&lt;fantasai> jgilbert: both on Windows and on Android, I believe, Windows will happily give you 1.6574 device pixel ratio<br>
&lt;fantasai> jgilbert: you just have to deal with it<br>
&lt;fantasai> jgilbert: you end up trying to reverse-engineer what pixel-snapping is to figure that out<br>
&lt;fantasai> jgilbert: pre-snap a rect to a non-integre CSS size , if that works out to integer pixels... then no artifacts? but it's a huge mess<br>
&lt;fantasai> smfr: other case that's confusing is on our iPhone's that have retina displays<br>
&lt;fantasai> smfr: already 2.7? scaling factors<br>
&lt;fantasai> smfr: so can cause hairlines to disappear aetc.<br>
&lt;fantasai> smfr: seems like also on windows, too<br>
&lt;fantasai> smfr: getting pixel perfection, seems like OS is doing scaling behind your back, how can you expect it to work?<br>
&lt;fantasai> jgilbert: out of the box cases where if you play around with virtual scaling<br>
&lt;fantasai> jgilbert: on a Mac and play with scaling on a retina screen<br>
&lt;fantasai> jgilbert: no way to get 1-1 device pixel<br>
&lt;fantasai> myles: even worse, the default ratio is not 1-1 or 2-1<br>
&lt;fantasai> jgilbert: it really depends on how the OS is doing this sort of scaling<br>
&lt;fantasai> jgilbert: I'll add that what you end up with, for instance in Mac, when you have this OS-level virtual resolution scaling<br>
&lt;fantasai> jgilbert: can't get one to one<br>
&lt;fantasai> jgilbert: if can't get 1-1 in application, can still get moire effects<br>
&lt;fantasai> jgilbert: can't entirely eliminate scaling artifacts, but can do better<br>
&lt;fantasai> jgilbert: than naively try to grid on the screen and hope it looks good<br>
&lt;fantasai> mattwoodrow: difference is on Windows the scaling isn't hidden<br>
&lt;fantasai> mattwoodrow: can attempt to match<br>
&lt;fantasai> jgilbert: windows 10 implements scaling that llows 1-1 rendering, not virtual scaling as default<br>
&lt;fantasai> jgilbert: Mac doesn't expose effective scaling, just says 2x all the time<br>
&lt;fantasai> jgilbert: Android says 3x all the time<br>
&lt;Rossen_> q?<br>
&lt;fantasai> ??: regarldess of what operating systems do, if application renders pixel -perfect<br>
&lt;fantasai> ??: Result will be better than if it wasn't<br>
&lt;fantasai> ??: I think we agree on that<br>
&lt;fantasai> myles: if goal is to get hairlines, even if you get a little closer to hairline, can still disappear<br>
&lt;fantasai> ??: Display scaling might give you smoother color if checkerboard is pixel-perfect before the scaling<br>
&lt;fantasai> ??: and if you have checkerboard before scaling, then less smooth design<br>
&lt;fantasai> s/??/mstage/<br>
&lt;jgilbert> s/mstage/mstange/<br>
&lt;fantasai> mstange: still discussing value of getting an accurate box? what's status?<br>
&lt;fantasai> jgilbert: if we decide that we don't want to give ppl this box, then ?<br>
&lt;fantasai> jgilbert: do we want to get into that? or do we want to take it as a given that we're trying to give ppl most correct idea of device pixel than we can?<br>
&lt;fantasai> mstange: what we would need to do in Firefox to get this result<br>
&lt;fantasai> mstange: Firefox takes into account the full zoom, and takes into account CSS Transforms<br>
&lt;fantasai> mstange: space in which we snap is established by the closest non-animated transform or the root<br>
&lt;fantasai> mstange: we only know this info during painting<br>
&lt;fantasai> mstange: so would need to run more steps before giving info<br>
&lt;fantasai> smfr: this device border box would not be affected by transforms<br>
&lt;fantasai> smfr: so would have to do *special* calculation<br>
&lt;fantasai> jgilbert: 3D transforms no idea what to fee dback<br>
&lt;fantasai> jgilbert: pixel-snapped bounding box?<br>
&lt;fantasai> atotic: if you're doing transforms won't be pixel-perfect anyway, so don't worry about it<br>
&lt;fantasai> atotic: your'e also talking about implementation that you need to get this nformation during pre-painting<br>
&lt;fantasai> atotic: remember you had this information ??<br>
&lt;fantasai> atotic: Might be ok to deliver incorrect information and not have to paint<br>
&lt;fantasai> myles: there's a chance of you never get correct info<br>
&lt;mstange> s/closest non-animated transform/closest animated ancestor transform/<br>
&lt;fantasai> atotic: I think you want, once things have settled down want accurate box size<br>
&lt;fantasai> atotic: if animating, don't care so much<br>
&lt;fantasai> jgilbert: deliver informmation lately<br>
&lt;fantasai> jgilbert: would be nice if we could try so that you could do 1-1 perfect every time within certain set of constraints<br>
&lt;fantasai> jgilbert: be nice if we didn't immediately settle on a 1 frame late policy<br>
&lt;fantasai> jgilbert: matching what native APIs are able to do<br>
&lt;fantasai> jgilbert: don't want to suffer if dont' have to suffer on native<br>
&lt;fantasai> myles: if it is one frame late then the exact timeline that we drop frames is exposed to the Web so don't think we want<br>
&lt;fantasai> myles: similarly, worried that we'd have to reverse-engineer chrome's pixel-snapping strategy<br>
&lt;fantasai> jgilbert: shouldn't have to do more normalziation than you do today, I think<br>
&lt;fantasai> jgilbert: if trying to use this to get anti-moire, in order to do this today have to ??<br>
&lt;fantasai> smfr: one frame late version also problem of which rectangle to trust<br>
&lt;fantasai> chrishtr: not late if layout occured<br>
&lt;fantasai> chrishtr: only late if you have a threaded animation<br>
&lt;fantasai> smfr: thought it would be late because we woudl collect info at paint time<br>
&lt;fantasai> chrishtr: I don't think we shoudl do that, disagree with atotic<br>
&lt;fantasai> chrishtr: think we can do it therefore we should<br>
&lt;fantasai> chrishtr: in cases where layout has occured<br>
&lt;fantasai> chrishtr: agree with point about threaded animations and not syncing with JS thread<br>
&lt;fantasai> smfr: want to tie together two of previous points, first that if we implement this paint day device pxel border box, will be more expensive for us<br>
&lt;fantasai> smfr: secondly because of physical mismatch, wouldn't have some user benefit<br>
&lt;fantasai> smfr: display is scaling anyway<br>
&lt;fantasai> smfr: can we get examples?<br>
&lt;fantasai> smfr: want to try on Apple devices, see what would happen if looks right<br>
&lt;fantasai> atotic: moire patter<br>
&lt;fantasai> atotic: if you're moving canvas around the screen, the moire is animated. looks really bad<br>
&lt;fantasai> smfr: please give us some tests<br>
&lt;fantasai> chrishtr: I think time is up?<br>
&lt;fantasai> chrishtr: propose to add the feature?<br>
&lt;fantasai> Rossen_: does the group feel there's enough merit to add this?<br>
&lt;fantasai> Rossen_: would be adding both APIs<br>
&lt;fantasai> Rossen_: is there any objection?<br>
&lt;fantasai> smfr: I dont' think we can accept new API without evidence that it's so much better that it's worth the extra cost<br>
&lt;fantasai> fremy: you can agree with the API and just return some approximate result if you feel it's good enough<br>
&lt;fantasai> myles: your'e saying implement the API without implementing teh API<br>
&lt;fantasai> fremy: might not be useful on your device<br>
&lt;fantasai> fremy: but might be useful on Android<br>
&lt;fantasai> fremy: so just return the result<br>
&lt;fantasai> AmeliaBR: Not having an API is better than having API with bad results<br>
&lt;fantasai> AmeliaBR: if a particular browser has particular concerns about implementing the particular API<br>
&lt;jgilbert> fantasai: in this case it would be, if you as an author were trying to do this thing, and you had this browser gives me the actual DPR, and this one gives me some approximation of the size<br>
&lt;jgilbert> ... I still need to size my box either way<br>
&lt;jgilbert> ... if my choice is I can get teh actual device pixel size from Chrome, but calcaulate it myself from widht/height props in WebKit, and get an approx result, then I don't know it might be better to have an API that does that calculation for me<br>
&lt;jgilbert> ... then I only need to write one code flow<br>
&lt;fantasai> AmeliaBR: might make sense, but have existing cases where you can't trust the API<br>
&lt;fantasai> florian: In general I agree with your statement, this doesn't seem to be such a case<br>
&lt;fantasai> Rossen_: I woudld like to end this topic<br>
&lt;fantasai> Rossen_: going to call for objections to adding the API, if we have objections we'll deal with them and have additional conversatiosn with the TAG and whatnot<br>
&lt;fantasai> Rossen_: any objections to having these APIs?<br>
&lt;fantasai> smfr: Can we wait until we ahve the examples?<br>
&lt;fantasai> astearns: I might object because seems like we need more data<br>
&lt;fantasai> astearns: so I will object on Safari's behalf<br>
&lt;fantasai> Rossen_: so back to you to get test cases, we'll discuss again on telecon<br>
</details>


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

Received on Tuesday, 17 September 2019 05:36:06 UTC