Skip to content

Commit

Permalink
WIP use dmabuf subsurfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ids1024 committed Jan 26, 2024
1 parent 2b3773c commit 3da7d9b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
12 changes: 12 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,15 @@ opt-level = 1
# [patch."https://github.com/pop-os/libcosmic"]
# libcosmic = { path = "../libcosmic" }
# cosmic-config = { path = "../libcosmic/cosmic-config" }

[patch."https://github.com/pop-os/libcosmic"]
iced = { git = "https://github.com/ids1024/iced", branch = "subsurface" }
iced_runtime = { git = "https://github.com/ids1024/iced", branch = "subsurface" }
iced_renderer = { git = "https://github.com/ids1024/iced", branch = "subsurface" }
iced_core = { git = "https://github.com/ids1024/iced", branch = "subsurface" }
iced_widget = { git = "https://github.com/ids1024/iced", branch = "subsurface" }
iced_futures = { git = "https://github.com/ids1024/iced", branch = "subsurface" }
iced_accessibility = { git = "https://github.com/ids1024/iced", branch = "subsurface" }
iced_tiny_skia = { git = "https://github.com/ids1024/iced", branch = "subsurface" }
iced_style = { git = "https://github.com/ids1024/iced", branch = "subsurface" }
iced_sctk = { git = "https://github.com/ids1024/iced", branch = "subsurface" }
3 changes: 2 additions & 1 deletion src/view/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use cosmic::{
advanced::layout::flex::Axis,
widget::{column, row},
},
iced_sctk::subsurface_widget::Subsurface,
widget,
};
use cosmic_comp_config::workspace::{WorkspaceAmount, WorkspaceLayout};
Expand Down Expand Up @@ -274,7 +275,7 @@ fn toplevel_previews<'a>(

fn capture_image(image: Option<&CaptureImage>) -> cosmic::Element<'_, Msg> {
if let Some(image) = image {
widget::Image::new(image.img.clone()).into()
Subsurface::new(image.width, image.height, &image.wl_buffer).into()
} else {
widget::Image::new(widget::image::Handle::from_pixels(1, 1, vec![0, 0, 0, 255])).into()
}
Expand Down
6 changes: 2 additions & 4 deletions src/wayland/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,11 @@ impl AppData {
// XXX Handle other formats?
let format = wl_shm::Format::Abgr8888.into();

/*
if let Some(buffer_info) = buffer_infos
.iter()
.find(|x| x.type_ == WEnum::Value(BufferType::Dmabuf) && x.format == format)
{
match self.create_gbm_backing(buffer_info, true) {
match self.create_gbm_backing(buffer_info, false) {
Ok(Some((backing, buffer))) => {
return Buffer {
backing,
Expand All @@ -155,7 +154,6 @@ impl AppData {
Err(err) => eprintln!("Failed to create gbm buffer: {}", err),
}
}
*/

// Fallback to shm buffer
// Assume format is already known to be valid
Expand Down Expand Up @@ -216,7 +214,7 @@ impl Buffer {

impl Drop for Buffer {
fn drop(&mut self) {
self.buffer.destroy();
// self.buffer.destroy();
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use cctk::{
toplevel_management::ToplevelManagerState,
wayland_client::{
globals::registry_queue_init,
protocol::{wl_output, wl_seat},
protocol::{wl_buffer, wl_output, wl_seat},
Connection, QueueHandle,
},
workspace::WorkspaceState,
Expand Down Expand Up @@ -83,7 +83,9 @@ pub enum Event {

#[derive(Clone, Debug)]
pub struct CaptureImage {
pub img: iced::widget::image::Handle,
pub width: u32,
pub height: u32,
pub wl_buffer: wl_buffer::WlBuffer,
}

pub fn subscription(conn: Connection) -> iced::Subscription<Event> {
Expand Down
11 changes: 9 additions & 2 deletions src/wayland/screencopy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,18 @@ impl ScreencopyHandler for AppData {
session.buffers.as_mut().unwrap().rotate_left(1);

// Capture again on damage
// XXX wait for buffer release
session.attach_buffer_and_commit(&capture, conn);

let front = session.buffers.as_mut().unwrap().first_mut().unwrap();
let img = unsafe { front.to_image() };
let image = CaptureImage { img };
// let img = unsafe { front.to_image() };
// let image = CaptureImage { img };
let buffer_info = &front.buffer_info;
let image = CaptureImage {
wl_buffer: front.buffer.clone(),
width: buffer_info.width,
height: buffer_info.height,
};
match &capture.source {
CaptureSource::Toplevel(toplevel) => {
self.send_event(Event::ToplevelCapture(toplevel.clone(), image))
Expand Down

0 comments on commit 3da7d9b

Please sign in to comment.