wayland: implement zwp_linux_dmabuf v4
This commit is contained in:
parent
672ee88d76
commit
9ceec8f4a0
7 changed files with 268 additions and 16 deletions
124
src/ifs/zwp_linux_dmabuf_feedback_v1.rs
Normal file
124
src/ifs/zwp_linux_dmabuf_feedback_v1.rs
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
use {
|
||||
crate::{
|
||||
client::{Client, ClientError},
|
||||
drm_feedback::DrmFeedback,
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
utils::buffd::{MsgParser, MsgParserError},
|
||||
wire::{zwp_linux_dmabuf_feedback_v1::*, ZwpLinuxDmabufFeedbackV1Id},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
uapi::{c, OwnedFd},
|
||||
};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub const SCANOUT: u32 = 1;
|
||||
|
||||
pub struct ZwpLinuxDmabufFeedbackV1 {
|
||||
pub id: ZwpLinuxDmabufFeedbackV1Id,
|
||||
pub client: Rc<Client>,
|
||||
pub tracker: Tracker<Self>,
|
||||
}
|
||||
|
||||
impl ZwpLinuxDmabufFeedbackV1 {
|
||||
pub fn new(id: ZwpLinuxDmabufFeedbackV1Id, client: &Rc<Client>) -> Self {
|
||||
Self {
|
||||
id,
|
||||
client: client.clone(),
|
||||
tracker: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn send_feedback(&self, feedback: &DrmFeedback) {
|
||||
self.send_format_table(&feedback.fd, feedback.size);
|
||||
self.send_main_device(feedback.main_device);
|
||||
self.send_tranche_target_device(feedback.main_device);
|
||||
self.send_tranche_formats(&feedback.indices);
|
||||
self.send_tranche_flags(0);
|
||||
self.send_tranche_done();
|
||||
self.send_done();
|
||||
}
|
||||
|
||||
fn send_done(&self) {
|
||||
self.client.event(Done { self_id: self.id });
|
||||
}
|
||||
|
||||
fn send_format_table(&self, fd: &Rc<OwnedFd>, size: usize) {
|
||||
self.client.event(FormatTable {
|
||||
self_id: self.id,
|
||||
fd: fd.clone(),
|
||||
size: size as _,
|
||||
});
|
||||
}
|
||||
|
||||
fn send_main_device(&self, dev: c::dev_t) {
|
||||
self.client.event(MainDevice {
|
||||
self_id: self.id,
|
||||
device: dev,
|
||||
});
|
||||
}
|
||||
|
||||
fn send_tranche_done(&self) {
|
||||
self.client.event(TrancheDone { self_id: self.id });
|
||||
}
|
||||
|
||||
fn send_tranche_target_device(&self, dev: c::dev_t) {
|
||||
self.client.event(TrancheTargetDevice {
|
||||
self_id: self.id,
|
||||
device: dev,
|
||||
});
|
||||
}
|
||||
|
||||
fn send_tranche_formats(&self, indices: &[u16]) {
|
||||
self.client.event(TrancheFormats {
|
||||
self_id: self.id,
|
||||
indices,
|
||||
});
|
||||
}
|
||||
|
||||
fn send_tranche_flags(&self, flags: u32) {
|
||||
self.client.event(TrancheFlags {
|
||||
self_id: self.id,
|
||||
flags,
|
||||
});
|
||||
}
|
||||
|
||||
fn destroy(&self, parser: MsgParser<'_, '_>) -> Result<(), ZwpLinuxDmabufFeedbackV1Error> {
|
||||
let _req: Destroy = self.client.parse(self, parser)?;
|
||||
self.detach();
|
||||
self.client.remove_obj(self)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn detach(&self) {
|
||||
self.client
|
||||
.state
|
||||
.drm_feedback_consumers
|
||||
.remove(&(self.client.id, self.id));
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
self = ZwpLinuxDmabufFeedbackV1;
|
||||
|
||||
DESTROY => destroy,
|
||||
}
|
||||
|
||||
impl Object for ZwpLinuxDmabufFeedbackV1 {
|
||||
fn break_loops(&self) {
|
||||
self.detach();
|
||||
}
|
||||
}
|
||||
|
||||
simple_add_obj!(ZwpLinuxDmabufFeedbackV1);
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum ZwpLinuxDmabufFeedbackV1Error {
|
||||
#[error(transparent)]
|
||||
ClientError(Box<ClientError>),
|
||||
#[error("Parsing failed")]
|
||||
MsgParserError(#[source] Box<MsgParserError>),
|
||||
}
|
||||
efrom!(ZwpLinuxDmabufFeedbackV1Error, ClientError);
|
||||
efrom!(ZwpLinuxDmabufFeedbackV1Error, MsgParserError);
|
||||
|
|
@ -2,11 +2,14 @@ use {
|
|||
crate::{
|
||||
client::{Client, ClientError},
|
||||
globals::{Global, GlobalName},
|
||||
ifs::zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1,
|
||||
ifs::{
|
||||
zwp_linux_buffer_params_v1::ZwpLinuxBufferParamsV1,
|
||||
zwp_linux_dmabuf_feedback_v1::ZwpLinuxDmabufFeedbackV1,
|
||||
},
|
||||
leaks::Tracker,
|
||||
object::Object,
|
||||
utils::buffd::{MsgParser, MsgParserError},
|
||||
wire::{zwp_linux_dmabuf_v1::*, ZwpLinuxDmabufV1Id},
|
||||
wire::{zwp_linux_dmabuf_v1::*, ZwpLinuxDmabufFeedbackV1Id, ZwpLinuxDmabufV1Id},
|
||||
},
|
||||
std::rc::Rc,
|
||||
thiserror::Error,
|
||||
|
|
@ -35,19 +38,21 @@ impl ZwpLinuxDmabufV1Global {
|
|||
});
|
||||
track!(client, obj);
|
||||
client.add_client_obj(&obj)?;
|
||||
if let Some(ctx) = client.state.render_ctx.get() {
|
||||
let formats = ctx.formats();
|
||||
for format in formats.values() {
|
||||
if format.implicit_external_only && !ctx.supports_external_texture() {
|
||||
continue;
|
||||
}
|
||||
obj.send_format(format.format.drm);
|
||||
if version >= MODIFIERS_SINCE_VERSION {
|
||||
for modifier in format.modifiers.values() {
|
||||
if modifier.external_only && !ctx.supports_external_texture() {
|
||||
continue;
|
||||
if version < FEEDBACK_SINCE_VERSION {
|
||||
if let Some(ctx) = client.state.render_ctx.get() {
|
||||
let formats = ctx.formats();
|
||||
for format in formats.values() {
|
||||
if format.implicit_external_only && !ctx.supports_external_texture() {
|
||||
continue;
|
||||
}
|
||||
obj.send_format(format.format.drm);
|
||||
if version >= MODIFIERS_SINCE_VERSION {
|
||||
for modifier in format.modifiers.values() {
|
||||
if modifier.external_only && !ctx.supports_external_texture() {
|
||||
continue;
|
||||
}
|
||||
obj.send_modifier(format.format.drm, modifier.modifier);
|
||||
}
|
||||
obj.send_modifier(format.format.drm, modifier.modifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -57,6 +62,7 @@ impl ZwpLinuxDmabufV1Global {
|
|||
}
|
||||
|
||||
const MODIFIERS_SINCE_VERSION: u32 = 3;
|
||||
const FEEDBACK_SINCE_VERSION: u32 = 4;
|
||||
|
||||
global_base!(
|
||||
ZwpLinuxDmabufV1Global,
|
||||
|
|
@ -70,7 +76,7 @@ impl Global for ZwpLinuxDmabufV1Global {
|
|||
}
|
||||
|
||||
fn version(&self) -> u32 {
|
||||
3
|
||||
5
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,6 +122,40 @@ impl ZwpLinuxDmabufV1 {
|
|||
self.client.add_client_obj(¶ms)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_feedback(
|
||||
self: &Rc<Self>,
|
||||
id: ZwpLinuxDmabufFeedbackV1Id,
|
||||
) -> Result<(), ZwpLinuxDmabufV1Error> {
|
||||
let fb = Rc::new(ZwpLinuxDmabufFeedbackV1::new(id, &self.client));
|
||||
track!(self.client, fb);
|
||||
self.client.add_client_obj(&fb)?;
|
||||
self.client
|
||||
.state
|
||||
.drm_feedback_consumers
|
||||
.set((self.client.id, id), fb.clone());
|
||||
if let Some(feedback) = self.client.state.drm_feedback.get() {
|
||||
fb.send_feedback(&feedback);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn get_default_feedback(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwpLinuxDmabufV1Error> {
|
||||
let req: GetDefaultFeedback = self.client.parse(&**self, parser)?;
|
||||
self.get_feedback(req.id)
|
||||
}
|
||||
|
||||
fn get_surface_feedback(
|
||||
self: &Rc<Self>,
|
||||
parser: MsgParser<'_, '_>,
|
||||
) -> Result<(), ZwpLinuxDmabufV1Error> {
|
||||
let req: GetSurfaceFeedback = self.client.parse(&**self, parser)?;
|
||||
let _surface = self.client.lookup(req.surface)?;
|
||||
self.get_feedback(req.id)
|
||||
}
|
||||
}
|
||||
|
||||
object_base! {
|
||||
|
|
@ -123,6 +163,8 @@ object_base! {
|
|||
|
||||
DESTROY => destroy,
|
||||
CREATE_PARAMS => create_params,
|
||||
GET_DEFAULT_FEEDBACK => get_default_feedback if self.version >= 4,
|
||||
GET_SURFACE_FEEDBACK => get_surface_feedback if self.version >= 4,
|
||||
}
|
||||
|
||||
impl Object for ZwpLinuxDmabufV1 {}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue