fix(wayland): double buffer frame callbacks
This commit is contained in:
@@ -48,6 +48,7 @@ pub struct SurfaceState {
|
||||
pub geometry: Option<Geometry>,
|
||||
pub min_size: Option<Vector2<u32>>,
|
||||
pub max_size: Option<Vector2<u32>>,
|
||||
frame_callbacks: Registry<Callback>,
|
||||
}
|
||||
impl Default for SurfaceState {
|
||||
fn default() -> Self {
|
||||
@@ -57,6 +58,7 @@ impl Default for SurfaceState {
|
||||
geometry: None,
|
||||
min_size: None,
|
||||
max_size: None,
|
||||
frame_callbacks: Registry::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,7 +72,6 @@ pub struct Surface {
|
||||
state: Mutex<DoubleBuffer<SurfaceState>>,
|
||||
pub message_sink: MessageSink,
|
||||
pub role: Mutex<Option<SurfaceRole>>,
|
||||
frame_callbacks: Registry<Callback>,
|
||||
on_commit_handlers: Mutex<Vec<OnCommitCallback>>,
|
||||
material: OnceLock<Handle<BevyMaterial>>,
|
||||
pending_material_applications: Registry<ModelPart>,
|
||||
@@ -96,7 +97,6 @@ impl Surface {
|
||||
state: Default::default(),
|
||||
message_sink: client.message_sink(),
|
||||
role: Mutex::new(None),
|
||||
frame_callbacks: Registry::new(),
|
||||
on_commit_handlers: Mutex::new(Vec::new()),
|
||||
material: OnceLock::new(),
|
||||
pending_material_applications: Registry::new(),
|
||||
@@ -180,7 +180,7 @@ impl Surface {
|
||||
}
|
||||
#[tracing::instrument(level = "debug", skip_all)]
|
||||
pub fn frame_event(&self) {
|
||||
for callback in self.frame_callbacks.take_valid_contents() {
|
||||
for callback in self.current_state().frame_callbacks.take_valid_contents() {
|
||||
let _ = self.message_sink.send(Message::Frame(callback));
|
||||
}
|
||||
}
|
||||
@@ -258,7 +258,7 @@ impl WlSurface for Surface {
|
||||
callback_id: ObjectId,
|
||||
) -> Result<()> {
|
||||
let callback = client.insert(callback_id, Callback(callback_id));
|
||||
self.frame_callbacks.add_raw(&callback);
|
||||
self.state.lock().pending.frame_callbacks.add_raw(&callback);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -290,6 +290,7 @@ impl WlSurface for Surface {
|
||||
#[tracing::instrument(level = "debug", skip_all)]
|
||||
async fn commit(&self, _client: &mut Client, _sender_id: ObjectId) -> Result<()> {
|
||||
self.state.lock().apply();
|
||||
self.state.lock().pending.frame_callbacks.clear();
|
||||
let current_state = self.current_state();
|
||||
let mut handlers = self.on_commit_handlers.lock();
|
||||
handlers.retain(|f| (f)(self, ¤t_state));
|
||||
|
||||
Reference in New Issue
Block a user