-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Pixel format API design #98
Comments
Here is an API I wrote a while back for an image crate I was writing (abandoned as of now). The idea is that is specifies RGBA channels, their sizes, their order and whether or not they are present. It's based on the setup that What if we made it so, no matter what format the buffer is, it's transcoded to the proper format? However, the API would expose a "transcode-free formats" function (maybe an |
Technically that doesn't cover every possible format. Wayland for instance supports things like YUV, indexed color, etc. But I doubt YUV is useful for softbuffer consumers, and indexed color (hopefully) isn't relevant these days, nor is it useful without knowing the palette. 😆 I guess that iterator would be returned by a method of But still, we have the fact |
The most obvious way to specify formats would be to provide an Of course we also need to handle conversion some way. Which is simple for variations on RGBA of the same bit depth but in different orders. Transparency support is somewhat special. We can't really convert RGBA to RGBX and have that to work as expected (but can do the reverse). The application needs to know if transparency is supported. Also a particular backend might only support RGBA here, but have a hint to indicate that the surface is opaque. This seems to be the case with |
I agree with the |
The complication there is format conversion. And whether or not transparency is supported at all. BGRX can be converted to BGRA by setting the last component of each pixel to 255. But converting BGRA to BGRX isn't possible without losing the alpha channel, which the caller probably doesn't want. So do we not allow that conversion, and require an application to check for a format with alpha before trying to use transparency? |
I'm in favor of doing no conversion at all. We take what the user supplies and that's it. The user has to supply it correctly.
One way I imagine we could "require to check the format" could be to make the format part of the buffer, basically: enum Buffer<'a> {
Bgrx(BgrxBuffer<'a>),
Bgra(BgraBuffer<'a>),
Rgba(RgbaBuffer<'a>),
} I'm don't think I'm in favor of this API, because the API of each of these types would be exactly the same. Having a In any case, I'm in favor of not doing any conversions at all. |
Not doing conversions makes things simpler, definitely. The trouble there is if there is no format that is supported on all backends. If we don't do conversion, does that mean the So this compromises the goal of making We could also provide helpers or a wrapper to do format conversion. At least we'd need to make the examples demonstrate what is needed for a portable application. |
Yes, that is what I would be in favor of.
Maybe I'm thinking about this wrong. The goal is to create a single portable API. But the reason we are here discussing different formats, is because not all backends work the same and there are differences that we can't bridge without introducing overhead. That is the reason why I want to have conversions not happen in So my thinking now was instead of introducing helpers, maybe it would make more sense indeed to do the conversion in Alternatively, we could also introduce To summarize my braindump here:
All APIs suggested here would be available on all platforms, non-portable just means the user has to handle multiple ways to draw the image to handle different formats for different platforms. Currently I'm in favor of the last one. |
Basically is the conclusion I came to after a bunch of back and forth here (just an Which basically still leaves open the two problems posed by @ids1024.
I think the first problem can be addressed by providing conversion free methods. Alternatively the "multiple Transparency conversion is problematic, but we could apply the "pre-multiplied alpha" strategy, which is the best I can think of. Alternatively, again, could be addressed with the "multiple |
Making Having the core API always use a native format, and then providing some sort of helper for conversion, seems better now that I think of it. "Explicit is better than implicit", and done well that should still provide an easy to use API. Though that still needs a good API. A |
If we're unsure about non-u32 formats, we can leave those out for now, and update the ABI for that later (possibly in a breaking way). I'd definitely say the priorities are:
I'd like to fix those and get them in a tagged release. Those seem like the main limitations of softbuffer currently. #39 and #90 could be added with non-breaking changes, as an enhancement. For most purposes on current platforms, you don't need pixel formats smaller than 32-bit. And higher bit depth (for things like HDR) is still niche and probably not something that you'd use a software renderer for. |
True, I didn't think this through.
I'm not sure I properly understand how #90 plays a role here, could you elaborate? My first thought was to do in-place conversion on present. I was also just thinking that reading pixels will be pretty weird as well, because it might not be the format users are using to write. Maybe I was thinking about this wrongly, but it might be better to decide on the texture format on |
The goal of buffer age is to allow redrawing only part of the buffer, because the buffer matches what you presented So I guess the format conversion wrapper could provide an
Basically the same issue as buffer age. So if we want to support it, it would have to convert back. Which couldn't be done in-place for a front buffer that the display server is also accessing.
Can we assume the formats supported by the display are the same for each surface, in all backends? Then |
We have access to the But yeah, this seems like a viable solution to me. |
Creating a So on Wayland the With |
Ah, I mixed it up, we have access to the That shouldn't really stop us, but makes the API more awkward, to get the preferred format for a surface we need to have Maybe the solution here could be to create a
Uhm, that sounds very weird. Maybe we just want to document that and not handle it otherwise? Or is this a common scenario? |
We're not currently using that API for the Wayland backend, we're currently using So I don't know that this is an issue with any current platform, but it's at least a potential concern, that could limit changes to backends or future backends. Yeah, a |
We need an API to list available pixel formats, and select one. Some considerations:
IOSurface
on macOS #95, it seems BGRA is supported, but not BGRX. So we need to make sure to set alpha to 255.wl_shm
can support many formats, but only two are required to be supported by compositors.So some questions here:
The text was updated successfully, but these errors were encountered: