⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@madsmtm
Copy link
Member

@madsmtm madsmtm commented Jan 19, 2026

Fixes #291 and allows using IOSurface on 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_rows or pixels_iter added in #312 to stride correctly. In case they don't, I've changed the macOS and Wayland backends to require a stride % 16 when cfg!(debug_assertions), this should make it easier to see when one is not following this requirement.

@madsmtm madsmtm added enhancement New feature or request DS - Android NDK DS - CoreGraphics macOS/iOS/tvOS/watchOS/visionOS backend and removed DS - CoreGraphics macOS/iOS/tvOS/watchOS/visionOS backend labels Jan 19, 2026
/// 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 {
Copy link
Member Author

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)?

Copy link
Member Author

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?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MarijnS95
Copy link
Member

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.

@madsmtm
Copy link
Member Author

madsmtm commented Jan 20, 2026

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?

True, though I do plan to add IOSurface support on macOS before the next release, I just didn't want to do it all in one go.

Perhaps we should wait for the pixelformat / type API before landing this, which should finally enable that.

We should be able to do it after #289. I'll fix it in whichever of these PRs land last.

@madsmtm madsmtm force-pushed the madsmtm/remove-deref branch from 2944dc3 to 5cba2e5 Compare January 20, 2026 19:44
Base automatically changed from madsmtm/remove-deref to master January 20, 2026 19:50
To help with debugging incorrect stride/width calculations, it helps
that there are more common backends (than Android) that have
`stride != width * 4`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DS - Android NDK enhancement New feature or request

Development

Successfully merging this pull request may close these issues.

3 participants