current_id, registry_id, and ShmPool are atomic
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use std::{error::Error, io::Write, os::unix::net::SocketAncillary, u8};
|
||||
use std::{error::Error, io::Write, os::unix::net::SocketAncillary, sync::atomic::Ordering, u8};
|
||||
use crate::wayland::{shm, surface::UnsetErr, vec_utils::WlMessage, wl_client::WlClient};
|
||||
|
||||
const STRIDE: usize = 4;
|
||||
@@ -10,19 +10,20 @@ impl WlClient {
|
||||
}
|
||||
|
||||
pub fn wl_shm_create_pool(&mut self, width: usize, height: usize) -> Result<(), Box<dyn Error>> {
|
||||
self.current_id += 1;
|
||||
self.shm_pool = Some(shm::ShmPool::new(width, height, self.current_id)?);
|
||||
self.shm_pool.as_mut().unwrap().write(&vec![0xffff0000; width * height], 0);
|
||||
self.shm_pool.as_mut().unwrap().rectangle(50, 50, 50, 50, 0xff00ff00);
|
||||
self.shm_pool.as_mut().unwrap().circle(300, 300, 200, 0xff0000ff);
|
||||
self.shm_pool.as_mut().unwrap().rounded_rectangle(450, 400, 60, 40, 16, 0xffffff00);
|
||||
let mut shm_pool = self.shm_pool.lock().unwrap();
|
||||
let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
*shm_pool = Some(shm::ShmPool::new(width, height, current_id)?);
|
||||
shm_pool.as_mut().unwrap().write(&vec![0xffff0000; width * height], 0);
|
||||
shm_pool.as_mut().unwrap().rectangle(50, 50, 50, 50, 0xff00ff00);
|
||||
shm_pool.as_mut().unwrap().circle(300, 300, 200, 0xff0000ff);
|
||||
shm_pool.as_mut().unwrap().rounded_rectangle(450, 400, 60, 40, 16, 0xffffff00);
|
||||
|
||||
let object = self.shm_id.ok_or(UnsetErr("shm_id".to_string()))?;
|
||||
const OPCODE: u16 = 0;
|
||||
const REQ_SIZE: u16 = 16;
|
||||
let id = self.shm_pool.as_ref().unwrap().id;
|
||||
let fds = [self.shm_pool.as_ref().unwrap().fd];
|
||||
let shm_size = self.shm_pool.as_ref().unwrap().size;
|
||||
let id = shm_pool.as_ref().unwrap().id;
|
||||
let fds = [shm_pool.as_ref().unwrap().fd];
|
||||
let shm_size = shm_pool.as_ref().unwrap().size;
|
||||
|
||||
let mut request = vec![0u8; REQ_SIZE as usize];
|
||||
let mut offset: usize = 0;
|
||||
@@ -57,13 +58,13 @@ impl WlClient {
|
||||
width: u32,
|
||||
height: u32
|
||||
) -> Result<(), Box<dyn Error>> {
|
||||
let object: u32 = self.shm_pool.as_ref().unwrap().id;
|
||||
let object: u32 = self.shm_pool.lock().unwrap().as_ref().unwrap().id;
|
||||
const REQ_SIZE: u16 = 32;
|
||||
const OPCODE: u16 = 0;
|
||||
|
||||
let stride: u32 = width * 4;
|
||||
self.current_id += 1;
|
||||
let id = self.current_id;
|
||||
let current_id = self.current_id.fetch_add(1, Ordering::Relaxed) + 1;
|
||||
let id = current_id;
|
||||
let format = 0;
|
||||
|
||||
let mut offset: usize = 0;
|
||||
@@ -82,7 +83,7 @@ impl WlClient {
|
||||
|
||||
self.socket.write(&request)?;
|
||||
|
||||
self.buffer_id = Some(self.current_id);
|
||||
self.buffer_id = Some(current_id);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user