screencopy: re-allocate buffers on BufferConstraints error
Doesn't always seem to work immediately. Does compositor need change to not wait for damage to re-capture after constraint error?
This commit is contained in:
parent
a4b1e73a8b
commit
7933eef149
1 changed files with 22 additions and 5 deletions
|
|
@ -20,6 +20,7 @@ use std::{
|
||||||
use super::{AppData, Buffer, Capture, CaptureImage, Event};
|
use super::{AppData, Buffer, Capture, CaptureImage, Event};
|
||||||
|
|
||||||
pub struct ScreencopySession {
|
pub struct ScreencopySession {
|
||||||
|
formats: Option<Formats>,
|
||||||
// swapchain buffers
|
// swapchain buffers
|
||||||
buffers: Option<[Buffer; 2]>,
|
buffers: Option<[Buffer; 2]>,
|
||||||
session: CaptureSession,
|
session: CaptureSession,
|
||||||
|
|
@ -45,6 +46,7 @@ impl ScreencopySession {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
|
formats: None,
|
||||||
buffers: None,
|
buffers: None,
|
||||||
session,
|
session,
|
||||||
release: None,
|
release: None,
|
||||||
|
|
@ -121,8 +123,9 @@ impl ScreencopyHandler for AppData {
|
||||||
return;
|
return;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
session.formats = Some(formats.clone());
|
||||||
|
|
||||||
// Create new buffer if none, then start capturing
|
// Create new buffer if none, then start capturing
|
||||||
// XXX What if formats have changed?
|
|
||||||
if session.buffers.is_none() {
|
if session.buffers.is_none() {
|
||||||
session.buffers = Some(array::from_fn(|_| self.create_buffer(formats)));
|
session.buffers = Some(array::from_fn(|_| self.create_buffer(formats)));
|
||||||
session.attach_buffer_and_commit(&capture, conn, &self.qh);
|
session.attach_buffer_and_commit(&capture, conn, &self.qh);
|
||||||
|
|
@ -209,15 +212,29 @@ impl ScreencopyHandler for AppData {
|
||||||
|
|
||||||
fn failed(
|
fn failed(
|
||||||
&mut self,
|
&mut self,
|
||||||
_conn: &Connection,
|
conn: &Connection,
|
||||||
_qh: &QueueHandle<Self>,
|
_qh: &QueueHandle<Self>,
|
||||||
capture_frame: &CaptureFrame,
|
capture_frame: &CaptureFrame,
|
||||||
reason: WEnum<FailureReason>,
|
reason: WEnum<FailureReason>,
|
||||||
) {
|
) {
|
||||||
// TODO
|
|
||||||
log::error!("Screencopy failed: {:?}", reason);
|
|
||||||
let capture = &capture_frame.data::<FrameData>().unwrap().capture;
|
let capture = &capture_frame.data::<FrameData>().unwrap().capture;
|
||||||
if let Some(capture) = capture.upgrade() {
|
let Some(capture) = capture.upgrade() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if reason == WEnum::Value(FailureReason::BufferConstraints) {
|
||||||
|
// Re-allocate buffers, then trigger another capture
|
||||||
|
log::info!("buffer constraint failure; re-allocating");
|
||||||
|
let mut session = capture.session.lock().unwrap();
|
||||||
|
let Some(session) = session.as_mut() else {
|
||||||
|
return;
|
||||||
|
};
|
||||||
|
if let Some(formats) = &session.formats {
|
||||||
|
session.buffers = Some(array::from_fn(|_| self.create_buffer(&formats)));
|
||||||
|
}
|
||||||
|
session.attach_buffer_and_commit(&capture, conn, &self.qh);
|
||||||
|
} else {
|
||||||
|
// TODO
|
||||||
|
log::error!("Screencopy failed: {:?}", reason);
|
||||||
capture.stop();
|
capture.stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue