-
Notifications
You must be signed in to change notification settings - Fork 67
Remove Deref and DerefMut impls on Buffer
#313
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
Conversation
7723663 to
2944dc3
Compare
src/lib.rs
Outdated
| } | ||
|
|
||
| /// Pixel helper accessors. | ||
| /// Helper accessors for viewing the buffer's data as RGBA pixel data. |
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.
"viewing" -> not sure if we have a better word to describe "accessing/writing" as you just discouraged "reading" in the comment above.
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.
You're right. I went with:
Helper methods for writing to the buffer as RGBA pixel data.
Which is not technically correct either, as the methods only provide &mut u32, they don't actually write, but eh, close enough.
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.
Yeah that's the intended use for the mutable slice, close enough.
To make it explicit when you're accessing the buffer data as pixels.
We want to migrate towards exposing either less structured buffers (`[u8]`, useful for different formats) or more structured buffers (`[Pixel]`, useful for ergonomics). `[u32]` is kind of in a weird state in between these and has confusing interactions with endianess. Since the current impls are not zero-cost on all backends, making them be a potential invisible performance cliff for users, we'd prefer for users to instead explicitly access the buffer's data in the format they desire.
Serves as documentation for why we don't expose different `pixels` and `pixels_mut` methods.
No longer really a necessary optimization, as accessing pixel data is an explicit operation, not invisible inside `Deref[Mut]`.
It is no longer used, and likely won't be necessary in the future either.
2944dc3 to
5cba2e5
Compare
&mut [u32]as a buffer format is kinda weird and has confusing interactions with endianess, see #109. I'd like to move towards exposing buffer data in different formats instead:Buffer::data(&mut self) -> &mut [u8], useful when working with different pixel formats, see Pixel format API design #98.Buffer::data(&mut self) -> &mut [Pixel]see AddPixelstruct andDEFAULT_PIXEL_FORMATconstant #289.Removing the
Deref/DerefMutas done in this PR should make it easier to reduce our "dependency" onu32as the pixel type in the future. Users would instead explicitly use the newBuffer::pixelsor the accessors added in #312 (which this PR builds upon).Finally, the current
Deref[Mut]impls are not zero-cost on all backends (and is kinda hard to make it so on Linux because ofBufferDispatch), making them be a potential invisible performance cliff.(The
BorrowStackhack could maybe be used to fix some of this, as was done on Wayland, but it requires the stored state to be&mut Tinstead ofT, and it adds 2*pointer size toBuffer<'_>which is kinda annoying. I've removed it in this PR because I believe it will no longer be necessary).