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:
John Nunley 2023-06-01 20:09:30 -07:00 committed by GitHub
parent daf304adf9
commit 44248477be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 258 additions and 22 deletions

View file

@ -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);