Keep image on vram if at all possible with wlroots based compositors

This commit is contained in:
Loki
2021-08-26 22:06:59 +02:00
parent ec184fb2ab
commit b59df48dde
8 changed files with 280 additions and 121 deletions

View File

@@ -133,7 +133,7 @@ void interface_t::del_interface(wl_registry *registry, uint32_t id) {
}
dmabuf_t::dmabuf_t()
: status { REINIT }, frames {}, current_frame { &frames[0] }, listener {
: status { READY }, frames {}, current_frame { &frames[0] }, listener {
(decltype(zwlr_export_dmabuf_frame_v1_listener::frame))&dmabuf_t::frame,
(decltype(zwlr_export_dmabuf_frame_v1_listener::object))&dmabuf_t::object,
(decltype(zwlr_export_dmabuf_frame_v1_listener::ready))&dmabuf_t::ready,
@@ -141,26 +141,6 @@ dmabuf_t::dmabuf_t()
} {
}
int dmabuf_t::init(wl_display *display_p) {
display = egl::make_display(display_p);
if(!display) {
return -1;
}
auto ctx_opt = egl::make_ctx(display.get());
if(!ctx_opt) {
return -1;
}
ctx = std::move(*ctx_opt);
status = READY;
return 0;
}
void dmabuf_t::listen(zwlr_export_dmabuf_manager_v1 *dmabuf_manager, wl_output *output, bool blend_cursor) {
auto frame = zwlr_export_dmabuf_manager_v1_capture_output(dmabuf_manager, blend_cursor, output);
zwlr_export_dmabuf_frame_v1_add_listener(frame, &listener, this);
@@ -211,27 +191,9 @@ void dmabuf_t::object(
void dmabuf_t::ready(
zwlr_export_dmabuf_frame_v1 *frame,
std::uint32_t tv_sec_hi, std::uint32_t tv_sec_lo, std::uint32_t tv_nsec) {
auto next_frame = get_next_frame();
auto rgb_opt = egl::import_source(display.get(),
{
next_frame->fds[0],
(int)next_frame->width,
(int)next_frame->height,
(int)next_frame->offsets[0],
(int)next_frame->strides[0],
});
if(!rgb_opt) {
status = REINIT;
return;
}
next_frame->rgb = std::move(*rgb_opt);
current_frame->destroy();
current_frame = next_frame;
current_frame = get_next_frame();
status = READY;
}
@@ -254,8 +216,6 @@ void frame_t::destroy() {
close(fds[x]);
}
rgb = egl::rgb_t {};
frame = nullptr;
obj_count = 0;
}