W3C home > Mailing lists > Public > public-css-archive@w3.org > February 2019

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

From: CSS Meeting Bot via GitHub <sysbot+gh@w3.org>
Date: Tue, 26 Feb 2019 18:13:41 +0000
To: public-css-archive@w3.org
Message-ID: <issue_comment.created-467550497-1551204819-sysbot+gh@w3.org>
The CSS Working Group just discussed `ResizeObserver device-pixel-border-box`.

<details><summary>The full IRC log of that discussion</summary>
&lt;gregwhitworth> Topic: ResizeObserver device-pixel-border-box<br>
&lt;gregwhitworth> Github: https://github.com/w3c/csswg-drafts/issues/3554<br>
&lt;gregwhitworth> atotic: I've been working on the spec<br>
&lt;gregwhitworth> atotic: the graphics team came to me - the problem they have is a way to determine the device pixel size of canvas<br>
&lt;gregwhitworth> atotic: why do they need to do this - the reason why they need to do this - is there is no way to do this<br>
&lt;gregwhitworth> atotic: the way the devs do hidpi in canvas it has CSS Pixels and what they do is they create the bitmap size they create the canvas in physical pixels it gets shrunk to CSS pixels so they can draw really fine hairlines<br>
&lt;gregwhitworth> atotic: device pixels are never rounded - there is no doubles or floating point, etc<br>
&lt;gregwhitworth> atotic: how we do this is by pixel snapping, there is no way for webdevs to determine this<br>
&lt;gregwhitworth> atotic: pixel snapping depends on not only pixels but also position<br>
&lt;gregwhitworth> atotic: I asked to add it to canvas, and they said sure but they also need to be notified when its resize<br>
&lt;gregwhitworth> atotic: currently the proposal will be that you will get device pixel inline and border size if its a canvas<br>
&lt;gregwhitworth> fantasai: are you proposing to add it somewhere else<br>
&lt;gregwhitworth> atotic: no<br>
&lt;gregwhitworth> fantasai: so the only way to get this is to add the resizeObserver<br>
&lt;gregwhitworth> atotic: yes<br>
&lt;gregwhitworth> dholbert: does devicePixelRatio?<br>
&lt;gregwhitworth> atotic: they get a bad pattern from hacking this because it can't do pixel snapping correctly<br>
&lt;gregwhitworth> dbaron: under what conditions does Chrome change the device pixel backing size when it's repositioned?<br>
&lt;gregwhitworth> dbaron: atotic is saying that, if you make a subpixel change in the top coordinate of a canvas, if it's 100.25 px tall<br>
&lt;gregwhitworth> dbaron: and it's top is positioned at a pixel aligned position it would round to 100, if it's further down it will be 101<br>
&lt;gregwhitworth> dbaron: do you actually change the backing store<br>
&lt;gregwhitworth> dbaron: the number of image pixels in the canvas<br>
&lt;gregwhitworth> dbaron: I guess thats the height and width<br>
&lt;gregwhitworth> dbaron: they want to change those the attrs based on the device pixel sizes<br>
&lt;gregwhitworth> atotic: the developer determines the size of the backing store, what Chrome does it will copy that bitmap to the CSS size of the canvas, if the ratio is a nice even number then we don't get moar patterns - if we don't<br>
&lt;bkardell_> how is that different from a url background image?<br>
&lt;gregwhitworth> atotic: there is a CSS size which can be fractional - but there is also the real bitmap to paint the canvas and that bitmap is in physical pixels<br>
&lt;bkardell_> " if the ratio is a nice even number then we don't get moar patterns - if we don't"<br>
&lt;bkardell_> that bit<br>
&lt;TabAtkins> s/moar/moire/g<br>
&lt;gregwhitworth> dbaron: bkardell_ is asking why don't you get moire pattern in background images<br>
&lt;gregwhitworth> atotic: it will scale, but background image is fundamentally different<br>
&lt;bkardell_> I can unmute and talk, I just dont want to interupt and don't knwo if this is enough to warrant a q<br>
&lt;gregwhitworth> atotic: we probably do get them but you usually aren't doing hidpi background image or you can't tell<br>
&lt;gregwhitworth> atotic: where they primarily have this issue is in the 3d context and they'll have patterns that look different<br>
&lt;AmeliaBR> q+<br>
&lt;gregwhitworth> bkardell_: the act of painting a thing on a canvas - the bitmap comes from an image and we rescale the image - it shoudln't matter who creates this image?<br>
&lt;gregwhitworth> atotic: you will see artifacts - but they'll create 3 different images<br>
&lt;dbaron> So I understand the use case -- but I'm a little suspicious of making it &lt;canvas>-only, though.<br>
&lt;gregwhitworth> iank_: within painting, we know where the pixel snapping is so we can account for it<br>
&lt;gregwhitworth> atotic: also we're talking about every frame in video games, it happens a lot more<br>
&lt;gregwhitworth> dbaron: I understand the usecase I just don't know if I like that it's canvas only<br>
&lt;florian> q+<br>
&lt;gregwhitworth> atotic: I agree, but there is a performance penalty to calculate them and most people don't care about this except in a canvas context<br>
&lt;dbaron> I'd have expected it to be implemented a different way, but okay...<br>
&lt;gregwhitworth> atotic: if we find that it's useful in other areas it's easy to extend it<br>
&lt;gregwhitworth> AmeliaBR: if this is a canvas thing - why are we doing this here. Especially since this is a really hacky way to do it<br>
&lt;gregwhitworth> atotic: from what I understand from the history, there was a hidpi way in which to do this but the other standard didn't go anywhere<br>
&lt;gregwhitworth> hober: we also saw that people still create the larger one<br>
&lt;gregwhitworth> atotic: I agree RO is an odd place but the dimensions change if you move around you still need to be notified<br>
&lt;gregwhitworth> liam: checking the device pixel size, it seems easy to check every frame<br>
&lt;AmeliaBR> ack me<br>
&lt;gregwhitworth> liam: why would you not check it?<br>
&lt;gregwhitworth> atotic: if you're a game developer maybe<br>
&lt;heycam> q+<br>
&lt;gregwhitworth> frremy: If you want to draw a perfect line in your table you'll need to resnap it<br>
&lt;gregwhitworth> atotic: exactly, you need it or you add it to both specs<br>
&lt;heycam> ack florian<br>
&lt;emilio> q+<br>
&lt;gregwhitworth> florian: another thing - here we know what CSS &amp; device pixel things and very easy to get confused<br>
&lt;gregwhitworth> florian: I don't know exactly what we want to add so let's not add it to too many places because it will get misused<br>
&lt;emilio> ack heycam<br>
&lt;gregwhitworth> atotic: it would only happen on canvas - you would see inlineDevicePixel and blockDevicePixel<br>
&lt;Rossen> gregwhitworth, recaps the resolution from yesterday<br>
&lt;gregwhitworth> heycam: before you were seeing a perf penalty - why not add a new box watching keyword?<br>
&lt;gregwhitworth> heycam: you can still have the device pixel border box of another element<br>
&lt;gregwhitworth> florian: but that was my point - if you make it broadly available they'll abuse it<br>
&lt;gregwhitworth> florian: they'll think they want device pixels but they'll probably be incorrect<br>
&lt;bkardell_> q+<br>
&lt;gregwhitworth> liam: to be clear, the only usecase this solves compared to RO plus having a method on canvas<br>
&lt;bkardell_> q-<br>
&lt;florian> q-<br>
&lt;dholbert> q+<br>
&lt;gregwhitworth> liam: this canvas snapping happens during painting or layout? If it happens at painting you wouldn't want to wait for painting to be done<br>
&lt;emilio> s/liam/emilio<br>
&lt;gregwhitworth> smfr: the only way to really know this you is to do it at painting you have to take transforms into account<br>
&lt;gregwhitworth> Rossen: if you have a scale it's broken<br>
&lt;florian> ScribeScribe: Florian<br>
&lt;gregwhitworth> gregwhitworth: I'm against adding this based on what smfr and liam said<br>
&lt;gregwhitworth> atotic: it will be blurry anyways so it doesn't matter<br>
&lt;emilio> s/liam/emilio again :D<br>
&lt;florian> gregwhitworth: in your use case, you may be right, but if we add this, there may be people who want to use it in the more general case that includes tranforms<br>
&lt;florian> gregwhitworth: so taking all web devs into account, this looks like a partial solution, not good enough<br>
&lt;gregwhitworth> iank_: I'll need to ask Chris, but we may compute the transforms<br>
&lt;gregwhitworth> atotic: resizeObserver doesn't watch transforms<br>
&lt;gregwhitworth> smfr: then this is the wrong API to bolt this onto<br>
&lt;gregwhitworth> atotic: ok, the hidpi with an ancestor that has a transform or something<br>
&lt;gregwhitworth> atotic: that should still work because it will then get transformed<br>
&lt;gregwhitworth> florian: then it's broken because the second you scale it's broken<br>
&lt;gregwhitworth> florian: people will assume they can and it will fail<br>
&lt;gregwhitworth> atotic: I thought one of the issues on the webplatform you don't want to expose zoom because it will break<br>
&lt;gregwhitworth> heycam: this is different<br>
&lt;heycam> s/this/pinch zooming and transforms on ancestors/<br>
&lt;gregwhitworth> atotic: we were talking about the pinch zoom of the page and they would end up with arbitrarily long page<br>
&lt;gregwhitworth> florian: pinch zoom, leaving it out - but transform?<br>
&lt;gregwhitworth> atotic: if we were going to do transforms, there will be a subset of these that should work<br>
&lt;gregwhitworth> atotic: we want this to be a size API not a quad API<br>
&lt;florian> gregwhitworth: I feel this is a chrome only perspective, safari and Firefox don't seem up to it. Should we go back to the github issue?<br>
&lt;gregwhitworth> atotic: RO itself does not work with transforms<br>
&lt;gregwhitworth> fremy: If you're going to draw a canvas you're not trying to do a transform on top of that<br>
&lt;gregwhitworth> fremy: transform is for animations<br>
&lt;gregwhitworth> fremy: why would you intend to do this if you're focused on pixel perfect drawing<br>
&lt;gregwhitworth> liam: I agree it doesn't make sense, it does make sense to center a canvas<br>
&lt;gregwhitworth> florian: offset path will also impact this as it can change the position<br>
&lt;gregwhitworth> atotic: we're going to notify you when the border box changes<br>
&lt;gregwhitworth> atotic: there's nothing that says we're not going to change on the transforms<br>
&lt;gregwhitworth> dholbert: how integral is the movement of the subpixel<br>
&lt;gregwhitworth> atotic: when you're moving it's blurry anyways, it's a video game<br>
&lt;gregwhitworth> dholbert: I'm feeling like a static API is more desirable than an RO API<br>
&lt;bkardell_> it is possible to make a subclass phase 2 of this that was specifically for observing that?<br>
&lt;bkardell_> .. or something<br>
&lt;gregwhitworth> dholbert: the canvas API makes sense to have this<br>
&lt;gregwhitworth> atotic: but people want to get an observation<br>
&lt;fremy> q+<br>
&lt;emilio> ack emilio<br>
&lt;dholbert> q-<br>
&lt;gregwhitworth> AmeliaBR: is it reasonable to trigger RO on something may have changed even if the sizes haven't changed - they then can do a canvas pixel<br>
&lt;gregwhitworth> atotic: I thought of that - but you end up getting a bunch of ROs without knowing why<br>
&lt;gregwhitworth> AmeliaBR: we have a way of adding device-pixel-border-box back?<br>
&lt;gregwhitworth> atotic: where most observers they look at the border box or content box, what is this box and creates a larger turbelance<br>
&lt;gregwhitworth> AmeliaBR: maybe I don't care about those and you're adding a perf hit<br>
&lt;gregwhitworth> heycam: you can rename the type of the box, canvas-bitmap-box if you're worried about<br>
&lt;gregwhitworth> atotic: it kind of locks us into watching the canvas only<br>
&lt;gregwhitworth> fantasai: I think agree with atotic named canvas - so we shouldn't lock that down<br>
&lt;fantasai> s/named/about not naming specific to/<br>
&lt;gregwhitworth> smfr: we simply snap device scale factor - if you're inside the scale transform we don't snap all the time, so we do need to go outside of layout a bit.<br>
&lt;fantasai> fantasai^: because there might be other elements in the future where we want to use it, and we should be able to just re-use the same thing for those cases<br>
&lt;gregwhitworth> atotic: it has a perf hit<br>
&lt;gregwhitworth> smfr: if you drag to another screen would it fire<br>
&lt;gregwhitworth> atotic: yes<br>
&lt;gregwhitworth> smfr: it's not real device pixels, because your not taking transforms into account<br>
&lt;gregwhitworth> chrishtr: its the dims of the texture of the backing store<br>
&lt;gregwhitworth> smfr: what you just said is very impl specific<br>
&lt;gregwhitworth> chrishtr: it's the CSS pixel size snapped and multiplied by the devicePixelRatio without taking into account transforms<br>
&lt;gregwhitworth> chrishtr: it has to take into account zoom<br>
&lt;gregwhitworth> smfr: ours doesn't<br>
&lt;gregwhitworth> chrishtr: the spec says to<br>
&lt;gregwhitworth> dholbert: doesn't it fire after layout?<br>
&lt;gregwhitworth> atotic: yes<br>
&lt;gregwhitworth> dholbert: so after layout<br>
&lt;gregwhitworth> dholbert: it would need to be extended to take into account after the fact<br>
&lt;gregwhitworth> liam: I don't think this a great fit<br>
&lt;gregwhitworth> iank_: it's where all other resizes are triggered, it's actually bad to try to keep it in sync with RO<br>
&lt;myles__> q+<br>
&lt;dbaron> So about 20 minutes ago there was a suggestion to take this back to the github issue... is there something we're actually going to resolve on here?<br>
&lt;gregwhitworth> fantasai: one thing to note if we have a RO if your 100 CSS pixels and I move it to the hidpi screen it's still 100 CSS pixels. And it's a canvas specific issue<br>
&lt;gregwhitworth> fantasai: it would be nice to not get the extra events unless I actually care about the device pixel border box<br>
&lt;gregwhitworth> atotic: yes<br>
&lt;gregwhitworth> fantasai: I think it should be the content box since that's what you're painting into<br>
&lt;dbaron> atotic: you could register to observer device-pixel-content-box<br>
&lt;gregwhitworth> atotic: that was my original proposal<br>
&lt;chrishtr> q+<br>
&lt;xfq> ack my<br>
&lt;gregwhitworth> myles__: so in conjuction with what fantasai was saying then you need to know the pos and size.<br>
&lt;gregwhitworth> fantasai: no only if those pixels change<br>
&lt;florian> gregwhitworth: that's already in the algo<br>
&lt;gregwhitworth> fantasai: you can resize in result of pos, but it may not<br>
&lt;Rossen> ack fremy<br>
&lt;gregwhitworth> fremy: I think it's going to be tricky in a sense, for the usecase your using - have you considered the paint() API?<br>
&lt;dbaron> (sounds like people were leaning towards registering for a separate box name rather than giving these notifications magically in some case)<br>
&lt;gregwhitworth> iank_: we don't have webgl and a bunch of other APIs<br>
&lt;gregwhitworth> fremy: oh ok<br>
&lt;fantasai> Proposal: Register for changes to devicePixelContentBox, get back sizes in device pixels, throws an error if registered on anything other than a canvas element, fires whenever device pixel size changes whether due to change in screen resolution, element position, or element resizing. Does not fire if device pixel size does not change.<br>
&lt;smfr> q+<br>
&lt;dbaron> still doesn't deal with the issues about rectilinear transforms, offset-path, etc.<br>
&lt;Rossen> ack chrishtr<br>
&lt;gregwhitworth> chrishtr: I just wanted to follow up on explicitly defining the API, in the CSS paint worklet callback you can see the device pixel backing size. It helps devs to dinstinguish between the two and can discover it. I think it would be useful to distinguish<br>
&lt;gregwhitworth> atotic: I think we have agreement to watch a seperate box?<br>
&lt;astearns> zakim, close queue<br>
&lt;Zakim> ok, astearns, the speaker queue is closed<br>
&lt;gregwhitworth> smfr: I just want to say that I don't think canvas is the only one, I think other situations may care about the same thing<br>
&lt;gregwhitworth> smfr: I think people will want it in other ways<br>
&lt;astearns> ack smfr<br>
&lt;smfr> s/in other ways/on other elements/<br>
&lt;gregwhitworth> smfr: I was proposing this is the snapped content box multiplied by device pixel ratio<br>
&lt;gregwhitworth> dbaron: but you all agree to ignore transforms?<br>
&lt;gregwhitworth> chrishtr: because it should be a paint based situation for perf<br>
&lt;gregwhitworth> dbaron: I don't think that's actually true<br>
&lt;gregwhitworth> chrishtr: unless overflow it's almost post paint<br>
&lt;gregwhitworth> krit: even SVG?<br>
&lt;AmeliaBR> I like the connection with Paint API. Even comes with a nice name, "paint size": https://drafts.css-houdini.org/css-paint-api/#paintsize<br>
&lt;gregwhitworth> Rossen: my proposed closing of the issue - let's bring the proposal back to github and then bring it back and we can resolve then<br>
&lt;gregwhitworth> atotic: thank you<br>
&lt;TabAtkins> Ooh, "paint size" sounds good.<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-467550497 using your GitHub account
Received on Tuesday, 26 February 2019 18:13:43 UTC

This archive was generated by hypermail 2.4.0 : Tuesday, 5 July 2022 06:41:44 UTC