-
Notifications
You must be signed in to change notification settings - Fork 67
Add Buffer::byte_stride and use it on Android
#315
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
base: master
Are you sure you want to change the base?
Conversation
1240fbb to
54a8954
Compare
| /// or failing that, make sure to chunk rows by the stride instead of the width. | ||
| /// | ||
| /// This is guaranteed to be `>= width * 4`, and is guaranteed to be a multiple of 4. | ||
| pub fn byte_stride(&self) -> NonZeroU32 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I considered exposing fn stride instead, and have the buffer size be stride * height * (pixel_format.bit_depth() / 8), but I don't think that works with 24-bit formats like PixelFormat::Rgb8 that are packed into memory as [R0, G0, B0, R1, G1, B1, P0, P1] (two padding bytes at the end)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But perhaps there's a nicer way to define it that I'm not seeing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
This currently seems to be worst-of-both-worlds: exposing the extra stride to the user while not taking advantage of it on Android by removing its backing buffer? Perhaps we should wait for the pixelformat / type API before landing this, which should finally enable that. |
True, though I do plan to add
We should be able to do it after #289. I'll fix it in whichever of these PRs land last. |
2944dc3 to
5cba2e5
Compare
To help with debugging incorrect stride/width calculations, it helps that there are more common backends (than Android) that have `stride != width * 4`.
54a8954 to
c543d19
Compare
Fixes #291 and allows using
IOSurfaceon macOS in the future a la #95.This is also important for supporting pixel formats with a different bit depth than
32, see #98.Users should prefer to use
pixel_rowsorpixels_iteradded in #312 to stride correctly. In case they don't, I've changed the macOS and Wayland backends to require astride % 16whencfg!(debug_assertions), this should make it easier to see when one is not following this requirement.