1
0
Fork 0
forked from wry/wry

gfx: handle context change when buffer is attached to multiple surfaces

This commit is contained in:
Julian Orth 2026-02-10 18:48:47 +01:00
parent ca5cc67fa2
commit b53f40e85f
4 changed files with 40 additions and 33 deletions

View file

@ -7,6 +7,7 @@ use {
clm::{CL_CHANGED_DESTROYED, CL_CHANGED_NEW, ClMatcherChange}, clm::{CL_CHANGED_DESTROYED, CL_CHANGED_NEW, ClMatcherChange},
}, },
ifs::{ ifs::{
wl_buffer::WlBuffer,
wl_display::WlDisplay, wl_display::WlDisplay,
wl_registry::WlRegistry, wl_registry::WlRegistry,
wl_surface::{WlSurface, commit_timeline::CommitTimelines}, wl_surface::{WlSurface, commit_timeline::CommitTimelines},
@ -21,6 +22,7 @@ use {
buffd::{MsgFormatter, MsgParser, MsgParserError, OutBufferSwapchain}, buffd::{MsgFormatter, MsgParser, MsgParserError, OutBufferSwapchain},
copyhashmap::{CopyHashMap, Locked}, copyhashmap::{CopyHashMap, Locked},
errorfmt::ErrorFmt, errorfmt::ErrorFmt,
event_listener::EventSource,
numcell::NumCell, numcell::NumCell,
pending_serial::PendingSerial, pending_serial::PendingSerial,
pid_info::{PidInfo, get_pid_info, get_socket_creds}, pid_info::{PidInfo, get_pid_info, get_socket_creds},
@ -194,6 +196,7 @@ impl Clients {
changed_properties: Default::default(), changed_properties: Default::default(),
destroyed: Default::default(), destroyed: Default::default(),
acceptor: acceptor.clone(), acceptor: acceptor.clone(),
gfx_ctx_changed: Default::default(),
}); });
track!(data, data); track!(data, data);
global.update_capabilities(&data, bounding_caps, set_bounding_caps_for_children); global.update_capabilities(&data, bounding_caps, set_bounding_caps_for_children);
@ -321,6 +324,7 @@ pub struct Client {
pub changed_properties: Cell<ClMatcherChange>, pub changed_properties: Cell<ClMatcherChange>,
pub destroyed: CopyHashMap<CritMatcherId, Weak<dyn CritDestroyListener<Rc<Self>>>>, pub destroyed: CopyHashMap<CritMatcherId, Weak<dyn CritDestroyListener<Rc<Self>>>>,
pub acceptor: Rc<AcceptorMetadata>, pub acceptor: Rc<AcceptorMetadata>,
pub gfx_ctx_changed: EventSource<WlBuffer>,
} }
pub const NUM_CACHED_SERIAL_RANGES: usize = 64; pub const NUM_CACHED_SERIAL_RANGES: usize = 64;

View file

@ -8,7 +8,7 @@ use {
leaks::Tracker, leaks::Tracker,
object::{Object, Version}, object::{Object, Version},
rect::{Rect, Region}, rect::{Rect, Region},
utils::{errorfmt::ErrorFmt, page_size::page_size}, utils::{errorfmt::ErrorFmt, event_listener::EventListener, page_size::page_size},
video::{ video::{
LINEAR_MODIFIER, LINEAR_MODIFIER,
dmabuf::{DmaBuf, DmaBufPlane}, dmabuf::{DmaBuf, DmaBufPlane},
@ -61,6 +61,7 @@ pub struct WlBuffer {
pub color: Option<[u32; 4]>, pub color: Option<[u32; 4]>,
width: i32, width: i32,
height: i32, height: i32,
gfx_ctx_changed: EventListener<WlBuffer>,
pub tracker: Tracker<Self>, pub tracker: Tracker<Self>,
} }
@ -84,7 +85,7 @@ impl WlBuffer {
shm: bool, shm: bool,
color: Option<[u32; 4]>, color: Option<[u32; 4]>,
) -> Rc<Self> { ) -> Rc<Self> {
Rc::new(Self { let slf = Rc::new_cyclic(|slf| Self {
id, id,
destroyed: Cell::new(false), destroyed: Cell::new(false),
client: client.clone(), client: client.clone(),
@ -98,7 +99,10 @@ impl WlBuffer {
shm, shm,
tracker: Default::default(), tracker: Default::default(),
color, color,
}) gfx_ctx_changed: EventListener::new(slf.clone()),
});
slf.gfx_ctx_changed.attach(&client.gfx_ctx_changed);
slf
} }
pub fn new_dmabuf( pub fn new_dmabuf(
@ -210,22 +214,23 @@ impl WlBuffer {
) )
} }
pub fn handle_gfx_context_change(&self, surface: Option<&WlSurface>) { pub fn handle_gfx_context_change(&self) -> bool {
let ctx_version = self.client.state.render_ctx_version.get(); let ctx_version = self.client.state.render_ctx_version.get();
if self.render_ctx_version.replace(ctx_version) == ctx_version { let up_to_date = self.render_ctx_version.replace(ctx_version) == ctx_version;
return;
}
let had_texture = self.reset_gfx_objects(surface);
if had_texture && let Some(surface) = surface {
self.update_texture_or_log(surface, true);
}
}
fn reset_gfx_objects(&self, surface: Option<&WlSurface>) -> bool {
let mut storage = self.storage.borrow_mut(); let mut storage = self.storage.borrow_mut();
let Some(s) = &mut *storage else { let Some(s) = &mut *storage else {
return false; return false;
}; };
if up_to_date {
let tex = match s {
WlBufferStorage::Shm {
dmabuf_buffer_params: DmabufBufferParams { tex, .. },
..
} => tex,
WlBufferStorage::Dmabuf { tex, .. } => tex,
};
return tex.is_some();
}
let had_texture = match s { let had_texture = match s {
WlBufferStorage::Shm { WlBufferStorage::Shm {
dmabuf_buffer_params: dmabuf_buffer_params:
@ -241,13 +246,8 @@ impl WlBuffer {
} => { } => {
host_buffer.take(); host_buffer.take();
*host_buffer_impossible = *udmabuf_impossible; *host_buffer_impossible = *udmabuf_impossible;
let mut had_texture = tex.take().is_some(); let had_texture = tex.take().is_some();
*tex_impossible = *udmabuf_impossible; *tex_impossible = *udmabuf_impossible;
if let Some(s) = surface {
s.shm_staging.take();
s.shm_textures.back().tex.take();
had_texture |= s.shm_textures.front().tex.take().is_some();
}
return had_texture; return had_texture;
} }
WlBufferStorage::Dmabuf { tex, .. } => tex.is_some(), WlBufferStorage::Dmabuf { tex, .. } => tex.is_some(),

View file

@ -1481,12 +1481,14 @@ impl WlSurface {
Ok(()) Ok(())
} }
pub fn reset_shm_textures(&self) { pub fn reset_shm_textures(&self) -> bool {
let had_texture = self.shm_textures.front().tex.is_some();
self.shm_staging.take(); self.shm_staging.take();
for tex in &*self.shm_textures { for tex in &*self.shm_textures {
tex.tex.take(); tex.tex.take();
tex.damage.clear(); tex.damage.clear();
} }
had_texture
} }
fn apply_damage(&self, pending: &PendingState) { fn apply_damage(&self, pending: &PendingState) {

View file

@ -133,7 +133,7 @@ use {
}, },
xwayland::{self, XWaylandEvent}, xwayland::{self, XWaylandEvent},
}, },
ahash::{AHashMap, AHashSet}, ahash::AHashMap,
bstr::ByteSlice, bstr::ByteSlice,
jay_config::{ jay_config::{
PciId, PciId,
@ -676,19 +676,20 @@ impl State {
} }
} }
Walker.visit_display(&self.root); Walker.visit_display(&self.root);
let mut updated_buffers = AHashMap::new();
for client in self.clients.clients.borrow_mut().values() { for client in self.clients.clients.borrow_mut().values() {
let mut updated_buffers = AHashSet::new(); updated_buffers.clear();
for surface in client.data.objects.surfaces.lock().values() { for buffer in client.data.gfx_ctx_changed.iter() {
if let Some(buffer) = surface.buffer.get() { let had_buffer_texture = buffer.handle_gfx_context_change();
updated_buffers.insert(buffer.buffer.id); updated_buffers.insert(buffer.id, had_buffer_texture);
buffer.buffer.handle_gfx_context_change(Some(surface));
} else {
surface.reset_shm_textures();
}
} }
for buffer in client.data.objects.buffers.lock().values() { for surface in client.data.objects.surfaces.lock().values() {
if !updated_buffers.contains(&buffer.id) { let had_shm_texture = surface.reset_shm_textures();
buffer.handle_gfx_context_change(None); if let Some(buffer) = surface.buffer.get() {
let had_buffer_texture = *updated_buffers.get(&buffer.buffer.id).unwrap();
if had_shm_texture || had_buffer_texture {
buffer.buffer.update_texture_or_log(surface, true);
}
} }
} }
} }