Split win32-specific qemu-display listeners

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
This commit is contained in:
Marc-André Lureau 2023-05-11 23:19:14 +04:00
parent 39ee45661b
commit 5ab24ab8a8
2 changed files with 148 additions and 132 deletions

View File

@ -10,6 +10,11 @@ use zbus::zvariant::Fd;
use zbus::{dbus_proxy, zvariant::ObjectPath, Connection};
use crate::{util, ConsoleListener, ConsoleListenerHandler, KeyboardProxy, MouseProxy, Result};
#[cfg(windows)]
use crate::{
ConsoleListenerD3d11, ConsoleListenerD3d11Handler, ConsoleListenerMap,
ConsoleListenerMapHandler,
};
#[dbus_proxy(default_service = "org.qemu", interface = "org.qemu.Display1.Console")]
pub trait Console {
@ -106,6 +111,41 @@ impl Console {
Ok(())
}
#[cfg(windows)]
pub async fn set_map_listener<H: ConsoleListenerMapHandler>(&self, handler: H) -> Result<bool> {
if let Some(l) = self.listener.borrow_mut().as_mut() {
return l
.object_server()
.at(
"/org/qemu/Display1/Listener",
ConsoleListenerMap::new(handler),
)
.await
.map_err(|e| e.into());
}
Err(crate::Error::Failed("Must call register first!".into()))
}
#[cfg(windows)]
pub async fn set_d3d11_listener<H: ConsoleListenerD3d11Handler>(
&self,
handler: H,
) -> Result<bool> {
if let Some(l) = self.listener.borrow_mut().as_mut() {
return l
.object_server()
.at(
"/org/qemu/Display1/Listener",
ConsoleListenerD3d11::new(handler),
)
.await
.map_err(|e| e.into());
}
Err(crate::Error::Failed("Must call register first!".into()))
}
pub fn unregister_listener(&mut self) {
self.listener.replace(None);
}

View File

@ -138,18 +138,6 @@ pub trait ConsoleListenerHandler: 'static + Send + Sync {
async fn update(&mut self, update: Update);
#[cfg(windows)]
async fn scanout_map(&mut self, scanout: ScanoutMap);
#[cfg(windows)]
async fn update_map(&mut self, update: UpdateMap);
#[cfg(windows)]
async fn scanout_d3d11_texture2d(&mut self, scanout: ScanoutD3dTexture2d);
#[cfg(windows)]
async fn update_d3d11_texture2d(&mut self, update: UpdateD3dTexture2d);
#[cfg(unix)]
async fn scanout_dmabuf(&mut self, scanout: ScanoutDMABUF);
@ -214,126 +202,6 @@ impl<H: ConsoleListenerHandler> ConsoleListener<H> {
.await;
}
#[cfg(windows)]
async fn scanout_map(
&mut self,
handle: u64,
offset: u32,
width: u32,
height: u32,
stride: u32,
format: u32,
) -> zbus::fdo::Result<()> {
let map = ScanoutMap {
handle,
offset,
width,
height,
stride,
format,
};
self.handler.scanout_map(map).await;
Ok(())
}
#[cfg(not(windows))]
async fn scanout_map(
&mut self,
_handle: u64,
_offset: u32,
_width: u32,
_height: u32,
_stride: u32,
_format: u32,
) -> zbus::fdo::Result<()> {
Err(zbus::fdo::Error::NotSupported(
"Shared map is not support on !windows".into(),
))
}
#[cfg(windows)]
async fn update_map(&mut self, x: i32, y: i32, w: i32, h: i32) -> zbus::fdo::Result<()> {
let up = UpdateMap { x, y, w, h };
self.handler.update_map(up).await;
Ok(())
}
#[cfg(not(windows))]
async fn update_map(&mut self, _x: i32, _y: i32, _w: i32, _h: i32) -> zbus::fdo::Result<()> {
Err(zbus::fdo::Error::NotSupported(
"Shared map is not support on !windows".into(),
))
}
#[cfg(windows)]
async fn scanout_d3d11_texture2d(
&mut self,
handle: u64,
tex_width: u32,
tex_height: u32,
y0_top: bool,
x: u32,
y: u32,
w: u32,
h: u32,
) -> zbus::fdo::Result<()> {
let texture = ScanoutD3dTexture2d {
handle,
tex_width,
tex_height,
y0_top,
x,
y,
w,
h,
};
self.handler.scanout_d3d11_texture2d(texture).await;
Ok(())
}
#[cfg(not(windows))]
async fn scanout_d3d11_texture2d(
&mut self,
_handle: u64,
_tex_width: u32,
_tex_height: u32,
_y0_top: bool,
_x: u32,
_y: u32,
_w: u32,
_h: u32,
) -> zbus::fdo::Result<()> {
Err(zbus::fdo::Error::NotSupported(
"D3D is not support on !windows".into(),
))
}
#[cfg(windows)]
async fn update_d3d11_texture2d(
&mut self,
x: i32,
y: i32,
w: i32,
h: i32,
) -> zbus::fdo::Result<()> {
let up = UpdateD3dTexture2d { x, y, w, h };
self.handler.update_d3d11_texture2d(up).await;
Ok(())
}
#[cfg(not(windows))]
async fn update_d3d11_texture2d(
&mut self,
_x: i32,
_y: i32,
_w: i32,
_h: i32,
) -> zbus::fdo::Result<()> {
Err(zbus::fdo::Error::NotSupported(
"D3d is not support on !windows".into(),
))
}
#[cfg(not(unix))]
#[dbus_interface(name = "ScanoutDMABUF")]
async fn scanout_dmabuf(
@ -434,3 +302,111 @@ impl<H: ConsoleListenerHandler> Drop for ConsoleListener<H> {
self.handler.disconnected();
}
}
#[cfg(windows)]
#[async_trait::async_trait]
pub trait ConsoleListenerMapHandler: 'static + Send + Sync {
async fn scanout_map(&mut self, scanout: ScanoutMap);
async fn update_map(&mut self, update: UpdateMap);
}
#[cfg(windows)]
#[derive(Debug)]
pub(crate) struct ConsoleListenerMap<H: ConsoleListenerMapHandler> {
handler: H,
}
#[cfg(windows)]
#[dbus_interface(name = "org.qemu.Display1.Listener.Win32.Map")]
impl<H: ConsoleListenerMapHandler> ConsoleListenerMap<H> {
async fn scanout_map(
&mut self,
handle: u64,
offset: u32,
width: u32,
height: u32,
stride: u32,
format: u32,
) -> zbus::fdo::Result<()> {
let map = ScanoutMap {
handle,
offset,
width,
height,
stride,
format,
};
self.handler.scanout_map(map).await;
Ok(())
}
async fn update_map(&mut self, x: i32, y: i32, w: i32, h: i32) -> zbus::fdo::Result<()> {
let up = UpdateMap { x, y, w, h };
self.handler.update_map(up).await;
Ok(())
}
}
#[cfg(windows)]
impl<H: ConsoleListenerMapHandler> ConsoleListenerMap<H> {
pub(crate) fn new(handler: H) -> Self {
Self { handler }
}
}
#[cfg(windows)]
#[async_trait::async_trait]
pub trait ConsoleListenerD3d11Handler: 'static + Send + Sync {
async fn scanout_texture2d(&mut self, scanout: ScanoutD3dTexture2d);
async fn update_texture2d(&mut self, update: UpdateD3dTexture2d);
}
#[cfg(windows)]
#[derive(Debug)]
pub(crate) struct ConsoleListenerD3d11<H: ConsoleListenerD3d11Handler> {
handler: H,
}
#[cfg(windows)]
#[dbus_interface(name = "org.qemu.Display1.Listener.Win32.D3d11")]
impl<H: ConsoleListenerD3d11Handler> ConsoleListenerD3d11<H> {
async fn scanout_texture2d(
&mut self,
handle: u64,
tex_width: u32,
tex_height: u32,
y0_top: bool,
x: u32,
y: u32,
w: u32,
h: u32,
) -> zbus::fdo::Result<()> {
let texture = ScanoutD3dTexture2d {
handle,
tex_width,
tex_height,
y0_top,
x,
y,
w,
h,
};
self.handler.scanout_texture2d(texture).await;
Ok(())
}
async fn update_texture2d(&mut self, x: i32, y: i32, w: i32, h: i32) -> zbus::fdo::Result<()> {
let up = UpdateD3dTexture2d { x, y, w, h };
self.handler.update_texture2d(up).await;
Ok(())
}
}
#[cfg(windows)]
impl<H: ConsoleListenerD3d11Handler> ConsoleListenerD3d11<H> {
pub(crate) fn new(handler: H) -> Self {
Self { handler }
}
}