API for reading from Framebuffer#7
API for reading from Framebuffer#7petoknm wants to merge 2 commits intoRoysten:masterfrom petoknm:master
Conversation
| } | ||
|
|
||
| ///Reads a frame from the Framebuffer. | ||
| pub fn read_frame(&self, frame: &mut Vec<u8>) { |
There was a problem hiding this comment.
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.
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.
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.
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) |
| @@ -9,9 +9,10 @@ use libc::ioctl; | |||
| use std::error::Error; | |||
There was a problem hiding this comment.
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.
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.
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.