1
0
Fork 0
forked from wry/wry

wl_surface: handle alpha modes

This commit is contained in:
Julian Orth 2026-02-21 14:24:38 +01:00
parent 37674a229c
commit 69ca5d92e7
10 changed files with 82 additions and 25 deletions

View file

@ -30,7 +30,7 @@ use {
drm_feedback::DrmFeedback,
fixed::Fixed,
gfx_api::{
AsyncShmGfxTexture, BufferResv, BufferResvUser, GfxError, GfxStagingBuffer,
AlphaMode, AsyncShmGfxTexture, BufferResv, BufferResvUser, GfxError, GfxStagingBuffer,
ReleaseSync, SampleRect, SyncFile,
},
ifs::{
@ -353,6 +353,7 @@ pub struct WlSurface {
CopyHashMap<WpColorManagementSurfaceFeedbackV1Id, Rc<WpColorManagementSurfaceFeedbackV1>>,
color_description: CloneCell<Option<Rc<ColorDescription>>>,
color_representation_surface: CloneCell<Option<Rc<WpColorRepresentationSurfaceV1>>>,
alpha_mode: Cell<AlphaMode>,
}
impl Debug for WlSurface {
@ -490,6 +491,7 @@ struct PendingState {
tray_item_ack_serial: Option<u32>,
color_description: Option<Option<Rc<ColorDescription>>>,
serial: Option<u64>,
alpha_mode: Option<AlphaMode>,
}
struct AttachedSubsurfaceState {
@ -544,6 +546,7 @@ impl PendingState {
opt!(tray_item_ack_serial);
opt!(color_description);
opt!(serial);
opt!(alpha_mode);
{
let (dx1, dy1) = self.offset;
let (dx2, dy2) = mem::take(&mut next.offset);
@ -708,6 +711,7 @@ impl WlSurface {
color_management_feedback: Default::default(),
color_description: Default::default(),
color_representation_surface: Default::default(),
alpha_mode: Default::default(),
}
}
@ -1202,6 +1206,12 @@ impl WlSurface {
color_description_changed = true;
self.color_description.set(desc);
}
let mut alpha_mode_changed = false;
if let Some(alpha_mode) = pending.alpha_mode.take()
&& self.alpha_mode.replace(alpha_mode) != alpha_mode
{
alpha_mode_changed = true;
}
let mut alpha_changed = false;
if let Some(alpha) = pending.alpha_multiplier.take() {
alpha_changed = true;
@ -1213,7 +1223,8 @@ impl WlSurface {
|| buffer_transform_changed
|| viewport_changed
|| alpha_changed
|| color_description_changed;
|| color_description_changed
|| alpha_mode_changed;
let mut buffer_changed = false;
let mut old_raw_size = None;
let (mut dx, mut dy) = mem::take(&mut pending.offset);
@ -1725,6 +1736,10 @@ impl WlSurface {
self.alpha.get()
}
pub fn alpha_mode(&self) -> AlphaMode {
self.alpha_mode.get()
}
pub fn opaque(&self) -> bool {
self.is_opaque.get()
}

View file

@ -1,6 +1,7 @@
use {
crate::{
client::{Client, ClientError},
gfx_api::AlphaMode,
ifs::wl_surface::WlSurface,
leaks::Tracker,
object::{Object, Version},
@ -22,12 +23,11 @@ pub struct WpColorRepresentationSurfaceV1 {
pub version: Version,
pub tracker: Tracker<Self>,
pub surface: Rc<WlSurface>,
pub supports_alpha_modes: bool,
}
pub const AM_PREMULTIPLIED_ELECTRICAL: u32 = 0;
#[expect(dead_code)]
pub const AM_PREMULTIPLIED_OPTICAL: u32 = 1;
#[expect(dead_code)]
pub const AM_STRAIGHT: u32 = 2;
impl WpColorRepresentationSurfaceV1 {
@ -47,16 +47,22 @@ impl WpColorRepresentationSurfaceV1RequestHandler for WpColorRepresentationSurfa
fn destroy(&self, _req: Destroy, _slf: &Rc<Self>) -> Result<(), Self::Error> {
self.surface.color_representation_surface.take();
self.surface.pending.borrow_mut().alpha_mode = Some(Default::default());
self.client.remove_obj(self)?;
Ok(())
}
fn set_alpha_mode(&self, req: SetAlphaMode, _slf: &Rc<Self>) -> Result<(), Self::Error> {
if req.alpha_mode != AM_PREMULTIPLIED_ELECTRICAL {
return Err(WpColorRepresentationSurfaceV1Error::UnsupportedAlphaMode(
req.alpha_mode,
));
}
let sam = self.supports_alpha_modes;
let alpha_mode = match req.alpha_mode {
AM_PREMULTIPLIED_ELECTRICAL => AlphaMode::PremultipliedElectrical,
AM_PREMULTIPLIED_OPTICAL if sam => AlphaMode::PremultipliedOptical,
AM_STRAIGHT if sam => AlphaMode::Straight,
n => {
return Err(WpColorRepresentationSurfaceV1Error::UnsupportedAlphaMode(n));
}
};
self.surface.pending.borrow_mut().alpha_mode = Some(alpha_mode);
Ok(())
}

View file

@ -3,8 +3,8 @@ use {
client::{Client, ClientError},
globals::{Global, GlobalName},
ifs::wl_surface::wp_color_representation_surface_v1::{
AM_PREMULTIPLIED_ELECTRICAL, WpColorRepresentationSurfaceV1,
WpColorRepresentationSurfaceV1Error,
AM_PREMULTIPLIED_ELECTRICAL, AM_PREMULTIPLIED_OPTICAL, AM_STRAIGHT,
WpColorRepresentationSurfaceV1, WpColorRepresentationSurfaceV1Error,
},
leaks::Tracker,
object::{Object, Version},
@ -35,11 +35,18 @@ impl WpColorRepresentationManagerV1Global {
client: &Rc<Client>,
version: Version,
) -> Result<(), WpColorRepresentationManagerV1Error> {
let mut supports_alpha_modes = false;
if let Some(ctx) = client.state.render_ctx.get()
&& ctx.supports_alpha_modes()
{
supports_alpha_modes = true;
}
let obj = Rc::new(WpColorRepresentationManagerV1 {
id,
client: client.clone(),
tracker: Default::default(),
version,
supports_alpha_modes,
});
track!(client, obj);
client.add_client_obj(&obj)?;
@ -53,11 +60,16 @@ pub struct WpColorRepresentationManagerV1 {
pub client: Rc<Client>,
pub version: Version,
pub tracker: Tracker<Self>,
pub supports_alpha_modes: bool,
}
impl WpColorRepresentationManagerV1 {
fn send_capabilities(&self) {
self.send_supported_alpha_mode(AM_PREMULTIPLIED_ELECTRICAL);
if self.supports_alpha_modes {
self.send_supported_alpha_mode(AM_PREMULTIPLIED_OPTICAL);
self.send_supported_alpha_mode(AM_STRAIGHT);
}
self.send_done();
}
@ -89,6 +101,7 @@ impl WpColorRepresentationManagerV1RequestHandler for WpColorRepresentationManag
version: self.version,
tracker: Default::default(),
surface: surface.clone(),
supports_alpha_modes: self.supports_alpha_modes,
});
track!(self.client, obj);
self.client.add_client_obj(&obj)?;