waycrate / wayshot

Mirrored at https://git.sr.ht/~shinyzenith/wayshot | screenshot tool for wlroots based compositors implementing zwlr_screencopy_v1
https://crates.io/crates/wayshot
BSD 2-Clause "Simplified" License
114 stars 20 forks source link

Add screencopy dmabuf backend #122

Closed CheerfulPianissimo closed 1 month ago

CheerfulPianissimo commented 4 months ago

This PR will contain the changes required for my Google Summer of Code 2024 project with waycrate as described here: https://cheerfulpianissimo.github.io/notes/GSOC/GSOC.html

CheerfulPianissimo commented 3 months ago

It isn't clear to me why that build is failing. Seems to be some issue with the wayland deps? A more detailed description of the changes so far is available at https://cheerfulpianissimo.github.io/notes/GSOC/GSOC%20Devlog%20(June).html#!week-4 :

Reading the code, I discovered that there are three levels of abstraction in libwayshot:

To this goal, I created the new function variants capture_output_frame_get_state_dmabuf and capture_output_frame_inner_dmabuf to replicate the lowest layer and capture_output_frame_dmabuf to replicate the public API on the level above. capture_output_frame_dmabuf would return a GBM BufferObject, a FrameGuard containing a WlBuffer and the frame format descriptor.

Two new structs DMAFrameFormat and DMAFrameGuard were created as counterparts to FrameFormat and FrameGuard.

For the most part adapting the code from the MVP into these functions was straightforward with the shm variants as a reference.

One part I have some trouble with is error handling. Using unwrap() in library code is generally frowned upon but I haven't figured out a good way to pass up errors to the caller without running into compiler errors like "? couldn't convert the error to error::Error the question mark operation (?) implicitly performs a conversion on the error value using the From trait". This requires some research.

The next phase will be testing. I will need some way to test the new API, ideally without having any VRAM->CPU copying. The simplest plan is to start with a basic wayland window demo and attach the WlBuffer obtained from the API to a WlSurface and see what the result looks like.

Shinyzenith commented 1 month ago

Apart from these minor changes, everything else looks good!

Shinyzenith commented 1 month ago

Ci is failing @CheerfulPianissimo

CheerfulPianissimo commented 1 month ago

The addition of wayland-sys as a dependency is causing it to fail I think. That library requires a preinstalled wayland system library.

CheerfulPianissimo commented 1 month ago

fixed that but it seems we need something for egl too.

CheerfulPianissimo commented 1 month ago

alright, the build is passing now but I think it may be wise to document the new deps somewhere and/or feature-gate it.

Shinyzenith commented 1 month ago

We can have it as part of changelog or release notes. Sounds good?

CheerfulPianissimo commented 1 month ago

Yeah that's fine by me. I already have a draft changelog for this at https://cheerfulpianissimo.github.io/notes/GSOC/GSoC%20Changelog.html

Shinyzenith commented 1 month ago

Congratulations and thank you for your service to the open source community @CheerfulPianissimo