Owned pixel buffer for no-copy presentation
This is based on the API that will be used for no-copy presentation. But wraps it in `set_buffer`. This also fixes the Wayland buffer code to set `self.width` and `self.height` on resize, and set the length of the shared memory file when the buffer is created. Co-authored-by: jtnunley <jtnunley01@gmail.com>
This commit is contained in:
parent
e5d546ff9e
commit
a09e4cf679
19 changed files with 1176 additions and 438 deletions
|
|
@ -3,6 +3,7 @@
|
|||
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "freebsd")))]
|
||||
mod example {
|
||||
use raw_window_handle::{RawDisplayHandle, RawWindowHandle, XcbDisplayHandle, XcbWindowHandle};
|
||||
use std::num::NonZeroU32;
|
||||
use x11rb::{
|
||||
connection::Connection,
|
||||
protocol::{
|
||||
|
|
@ -12,6 +13,8 @@ mod example {
|
|||
xcb_ffi::XCBConnection,
|
||||
};
|
||||
|
||||
const RED: u32 = 255 << 16;
|
||||
|
||||
pub(crate) fn run() {
|
||||
// Create a new XCB connection
|
||||
let (conn, screen) = XCBConnection::connect(None).expect("Failed to connect to X server");
|
||||
|
|
@ -96,13 +99,15 @@ mod example {
|
|||
match event {
|
||||
Event::Expose(_) => {
|
||||
// Draw a width x height red rectangle.
|
||||
let red = 255 << 16;
|
||||
let source = std::iter::repeat(red)
|
||||
.take((width as usize * height as usize) as _)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
// Draw the buffer.
|
||||
surface.set_buffer(&source, width, height);
|
||||
surface
|
||||
.resize(
|
||||
NonZeroU32::new(width.into()).unwrap(),
|
||||
NonZeroU32::new(height.into()).unwrap(),
|
||||
)
|
||||
.unwrap();
|
||||
let mut buffer = surface.buffer_mut().unwrap();
|
||||
buffer.fill(RED);
|
||||
buffer.present().unwrap();
|
||||
}
|
||||
Event::ConfigureNotify(configure_notify) => {
|
||||
width = configure_notify.width;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue