pw_utils: borrow SHM buffers when rendering and clearing
Browse files at this commit6e6e829c113312e3076e42d5dbcf8f5c7bd9ab4eParent: 7256ccf1 changed file +15 -16
- src/screencasting/pw_utils.rs +15 -16
src/screencasting/pw_utils.rsmodified+15 -16
| @@ -1292,7 +1292,7 @@ impl Cast { | ||
| 1292 | 1292 | .map(|x| (x, SharingBuf::Dma)) |
| 1293 | 1293 | } |
| 1294 | 1294 | x if x == DataType::MemFd.as_raw() => { |
| 1295 | - let shmbuf = inner_.shmbufs[&fd].clone(); | |
| 1295 | + let shmbuf = &inner_.shmbufs[&fd]; | |
| 1296 | 1296 | |
| 1297 | 1297 | let fourcc = if alpha { |
| 1298 | 1298 | Fourcc::Argb8888 |
| @@ -1300,8 +1300,8 @@ impl Cast { | ||
| 1300 | 1300 | Fourcc::Xrgb8888 |
| 1301 | 1301 | }; |
| 1302 | 1302 | |
| 1303 | - render_to_shmbuf(renderer, damage_tracker, &shmbuf, fourcc, elements, states) | |
| 1304 | - .map(|()| (SyncPoint::signaled(), SharingBuf::Shm(shmbuf))) | |
| 1303 | + render_to_shmbuf(renderer, damage_tracker, shmbuf, fourcc, elements, states) | |
| 1304 | + .map(|()| (SyncPoint::signaled(), SharingBuf::Shm(shmbuf.layout))) | |
| 1305 | 1305 | } |
| 1306 | 1306 | _ => Err(anyhow::anyhow!( |
| 1307 | 1307 | "unknown data type in dequeue_buffer_and_render" |
| @@ -1361,8 +1361,10 @@ impl Cast { | ||
| 1361 | 1361 | clear_dmabuf(renderer, dmabuf).map(|x| (x, SharingBuf::Dma)) |
| 1362 | 1362 | } |
| 1363 | 1363 | x if x == DataType::MemFd.as_raw() => { |
| 1364 | - let shmbuf = self.inner.borrow().shmbufs[&fd].clone(); | |
| 1365 | - clear_shmbuf(&shmbuf).map(|()| (SyncPoint::signaled(), SharingBuf::Shm(shmbuf))) | |
| 1364 | + let inner = self.inner.borrow(); | |
| 1365 | + let shmbuf = &inner.shmbufs[&fd]; | |
| 1366 | + clear_shmbuf(shmbuf) | |
| 1367 | + .map(|()| (SyncPoint::signaled(), SharingBuf::Shm(shmbuf.layout))) | |
| 1366 | 1368 | } |
| 1367 | 1369 | _ => Err(anyhow::anyhow!( |
| 1368 | 1370 | "unknown data type in dequeue_buffer_and_clear" |
| @@ -1616,9 +1618,9 @@ fn allocate_dmabuf( | ||
| 1616 | 1618 | Ok(dmabuf) |
| 1617 | 1619 | } |
| 1618 | 1620 | |
| 1619 | -#[derive(Debug, Clone)] | |
| 1621 | +#[derive(Debug)] | |
| 1620 | 1622 | pub struct Shmbuf { |
| 1621 | - fd: Rc<OwnedFd>, | |
| 1623 | + fd: OwnedFd, | |
| 1622 | 1624 | layout: ShmLayout, |
| 1623 | 1625 | } |
| 1624 | 1626 | |
| @@ -1651,7 +1653,7 @@ impl ShmLayout { | ||
| 1651 | 1653 | |
| 1652 | 1654 | enum SharingBuf { |
| 1653 | 1655 | Dma, |
| 1654 | - Shm(Shmbuf), | |
| 1656 | + Shm(ShmLayout), | |
| 1655 | 1657 | } |
| 1656 | 1658 | |
| 1657 | 1659 | fn allocate_shmbuf(size: Size<u32, Physical>) -> anyhow::Result<Shmbuf> { |
| @@ -1664,10 +1666,7 @@ fn allocate_shmbuf(size: Size<u32, Physical>) -> anyhow::Result<Shmbuf> { | ||
| 1664 | 1666 | ftruncate(&fd, layout.size.into()).context("error setting size of the fd")?; |
| 1665 | 1667 | fcntl_add_seals(&fd, SealFlags::SEAL | SealFlags::SHRINK | SealFlags::GROW) |
| 1666 | 1668 | .context("error sealing the fd")?; |
| 1667 | - Ok(Shmbuf { | |
| 1668 | - fd: fd.into(), | |
| 1669 | - layout, | |
| 1670 | - }) | |
| 1669 | + Ok(Shmbuf { fd, layout }) | |
| 1671 | 1670 | } |
| 1672 | 1671 | |
| 1673 | 1672 | unsafe fn return_unused_buffer(stream: &Stream, pw_buffer: NonNull<pw_buffer>) { |
| @@ -1706,8 +1705,8 @@ unsafe fn mark_buffer_as_good(pw_buffer: NonNull<pw_buffer>, sequence: &mut u64, | ||
| 1706 | 1705 | // Clear the corrupted flag we may have set before. |
| 1707 | 1706 | (*chunk).flags = SPA_CHUNK_FLAG_NONE as i32; |
| 1708 | 1707 | } |
| 1709 | - SharingBuf::Shm(shmbuf) => { | |
| 1710 | - (*chunk).size = shmbuf.layout.size; | |
| 1708 | + SharingBuf::Shm(layout) => { | |
| 1709 | + (*chunk).size = layout.size; | |
| 1711 | 1710 | (*chunk).flags = SPA_CHUNK_FLAG_NONE as i32; |
| 1712 | 1711 | } |
| 1713 | 1712 | } |
| @@ -1905,7 +1904,7 @@ fn render_to_shmbuf( | ||
| 1905 | 1904 | buffer.layout.size_usize(), |
| 1906 | 1905 | ProtFlags::READ | ProtFlags::WRITE, |
| 1907 | 1906 | MapFlags::SHARED, |
| 1908 | - buffer.fd.clone(), | |
| 1907 | + &buffer.fd, | |
| 1909 | 1908 | 0, |
| 1910 | 1909 | )?; |
| 1911 | 1910 | { |
| @@ -1926,7 +1925,7 @@ fn clear_shmbuf(buffer: &Shmbuf) -> anyhow::Result<()> { | ||
| 1926 | 1925 | buffer.layout.size_usize(), |
| 1927 | 1926 | ProtFlags::READ | ProtFlags::WRITE, |
| 1928 | 1927 | MapFlags::SHARED, |
| 1929 | - buffer.fd.clone(), | |
| 1928 | + &buffer.fd, | |
| 1930 | 1929 | 0, |
| 1931 | 1930 | )?; |
| 1932 | 1931 | { |