fix(wayland/surface): keep frame callback order
This commit is contained in:
@@ -57,7 +57,7 @@ pub struct SurfaceState {
|
|||||||
pub geometry: Option<Geometry>,
|
pub geometry: Option<Geometry>,
|
||||||
pub min_size: Option<Vector2<u32>>,
|
pub min_size: Option<Vector2<u32>>,
|
||||||
pub max_size: Option<Vector2<u32>>,
|
pub max_size: Option<Vector2<u32>>,
|
||||||
frame_callbacks: Registry<Callback>,
|
frame_callbacks: Vec<Arc<Callback>>,
|
||||||
}
|
}
|
||||||
impl Default for SurfaceState {
|
impl Default for SurfaceState {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
@@ -67,7 +67,7 @@ impl Default for SurfaceState {
|
|||||||
geometry: None,
|
geometry: None,
|
||||||
min_size: None,
|
min_size: None,
|
||||||
max_size: None,
|
max_size: None,
|
||||||
frame_callbacks: Registry::new(),
|
frame_callbacks: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -90,7 +90,7 @@ pub struct Surface {
|
|||||||
pub role: OnceLock<SurfaceRole>,
|
pub role: OnceLock<SurfaceRole>,
|
||||||
pub panel_item: Mutex<Weak<PanelItem<XdgBackend>>>,
|
pub panel_item: Mutex<Weak<PanelItem<XdgBackend>>>,
|
||||||
on_commit_handlers: Mutex<Vec<OnCommitCallback>>,
|
on_commit_handlers: Mutex<Vec<OnCommitCallback>>,
|
||||||
frame_callbacks: Registry<Callback>,
|
frame_callbacks: Mutex<Vec<Arc<Callback>>>,
|
||||||
material: OnceLock<Handle<BevyMaterial>>,
|
material: OnceLock<Handle<BevyMaterial>>,
|
||||||
pending_material_applications: Registry<ModelPart>,
|
pending_material_applications: Registry<ModelPart>,
|
||||||
presentation_feedback: Mutex<Vec<Arc<PresentationFeedback>>>,
|
presentation_feedback: Mutex<Vec<Arc<PresentationFeedback>>>,
|
||||||
@@ -123,7 +123,7 @@ impl Surface {
|
|||||||
role: OnceLock::new(),
|
role: OnceLock::new(),
|
||||||
panel_item: Mutex::new(Weak::default()),
|
panel_item: Mutex::new(Weak::default()),
|
||||||
on_commit_handlers: Mutex::new(Vec::new()),
|
on_commit_handlers: Mutex::new(Vec::new()),
|
||||||
frame_callbacks: Registry::new(),
|
frame_callbacks: Mutex::new(Vec::new()),
|
||||||
material: OnceLock::new(),
|
material: OnceLock::new(),
|
||||||
pending_material_applications: Registry::new(),
|
pending_material_applications: Registry::new(),
|
||||||
presentation_feedback: Mutex::default(),
|
presentation_feedback: Mutex::default(),
|
||||||
@@ -234,7 +234,7 @@ impl Surface {
|
|||||||
}
|
}
|
||||||
#[tracing::instrument(level = "debug", skip_all)]
|
#[tracing::instrument(level = "debug", skip_all)]
|
||||||
pub fn frame_event(&self) {
|
pub fn frame_event(&self) {
|
||||||
let callbacks = self.frame_callbacks.take_valid_contents();
|
let callbacks = std::mem::take(&mut *self.frame_callbacks.lock());
|
||||||
if !callbacks.is_empty() {
|
if !callbacks.is_empty() {
|
||||||
let _ = self.message_sink.send(Message::Frame(callbacks));
|
let _ = self.message_sink.send(Message::Frame(callbacks));
|
||||||
}
|
}
|
||||||
@@ -369,7 +369,7 @@ impl WlSurface for Surface {
|
|||||||
callback_id: ObjectId,
|
callback_id: ObjectId,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let callback = client.insert(callback_id, Callback(callback_id));
|
let callback = client.insert(callback_id, Callback(callback_id));
|
||||||
self.state.lock().pending.frame_callbacks.add_raw(&callback);
|
self.state.lock().pending.frame_callbacks.push(callback);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -413,10 +413,12 @@ impl WlSurface for Surface {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
self.state.lock().apply();
|
self.state.lock().apply();
|
||||||
for callback in self.current_state().frame_callbacks.get_valid_contents() {
|
|
||||||
self.frame_callbacks.add_raw(&callback)
|
self.state.lock().pending.frame_callbacks.clear();
|
||||||
}
|
|
||||||
let current_state = self.current_state();
|
let current_state = self.current_state();
|
||||||
|
self.frame_callbacks
|
||||||
|
.lock()
|
||||||
|
.extend(current_state.frame_callbacks.iter().cloned());
|
||||||
let mut handlers = self.on_commit_handlers.lock();
|
let mut handlers = self.on_commit_handlers.lock();
|
||||||
handlers.retain(|f| (f)(self, ¤t_state));
|
handlers.retain(|f| (f)(self, ¤t_state));
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user