feat: Add a function for retrieving the window contents
This function is useful for testing the window contents in certain cases. In addition, this means that we can now have reliable tests for softbuffer's actual functionality. Signed-off-by: John Nunley <jtnunley01@gmail.com> Co-authored-by: dAxpeDDa <daxpedda@gmail.com>
This commit is contained in:
parent
daf304adf9
commit
44248477be
12 changed files with 258 additions and 22 deletions
28
src/win32.rs
28
src/win32.rs
|
|
@ -202,6 +202,34 @@ impl Win32Impl {
|
|||
|
||||
Ok(BufferImpl(self))
|
||||
}
|
||||
|
||||
/// Fetch the buffer from the window.
|
||||
pub fn fetch(&mut self) -> Result<Vec<u32>, SoftBufferError> {
|
||||
let buffer = self.buffer.as_ref().unwrap();
|
||||
let temp_buffer = Buffer::new(self.dc, buffer.width, buffer.height);
|
||||
|
||||
// Just go the other way.
|
||||
unsafe {
|
||||
Gdi::BitBlt(
|
||||
temp_buffer.dc,
|
||||
0,
|
||||
0,
|
||||
temp_buffer.width.get(),
|
||||
temp_buffer.height.get(),
|
||||
self.dc,
|
||||
0,
|
||||
0,
|
||||
Gdi::SRCCOPY,
|
||||
);
|
||||
}
|
||||
|
||||
// Flush the operation so that it happens immediately.
|
||||
unsafe {
|
||||
Gdi::GdiFlush();
|
||||
}
|
||||
|
||||
Ok(temp_buffer.pixels().to_vec())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct BufferImpl<'a>(&'a mut Win32Impl);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue