-
Notifications
You must be signed in to change notification settings - Fork 16
API for reading from Framebuffer #7
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
| } | ||
|
|
||
| ///Reads a frame from the Framebuffer. | ||
| pub fn read_frame(&self, frame: &mut Vec<u8>) { |
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.
Using &mut Vec as parameter requires the user of this function to use a Vec, which will allocate the required memory to fit the entire frame. This means that after every read the user will have to call .clear() on the vector before being able to use the same vector for the next read. Also it would not be possible to only read a small part of the frame.
Wouldn't it be better to change it to:
pub fn read_frame(&self, frame: &mut [u8]) {and then use .read_exact(frame) later on?
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.
For reading parts of the framebuffer I would suggest we implement Index<Range> so that people can read it any way they want, e.g. let v = fb[4096..8192].to_vec();.
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.
For reading the entire frame I wanted to use Vec to not have to deal with the size(preallocating memory in case of an array)... but I guess we could also solve this in terms of Index<Range> => let v = fb[..].to_vec(), let slice = fb[..], and maybe writing too using IndexMut.
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 would give the user the choice to do whatever they want with the returned slice
| ///Reads a frame from the Framebuffer. | ||
| pub fn read_frame(&self, frame: &mut Vec<u8>) { | ||
| unsafe { self.frame.as_slice() } | ||
| .read_to_end(frame) |
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.
.read_exact(frame)| @@ -9,9 +9,10 @@ use libc::ioctl; | |||
| use std::error::Error; | |||
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.
Could you give an example where you would want to read the frame? You have previously written it yourself, so why not keep this data stored somewhere?
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 have made my own display that is using SPI and I want to read the framebuffer and push it over SPI to the display. In my case the OS/applications are writing to the framebuffer and I'm just pushing it to the display.
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 want to make screenshot of the framebuffer (drawn by an another application), so I need this logic too.
I needed to read data from the framebuffer and I thought others might find it useful too.