diff --git a/sunshine/platform/linux/graphics.cpp b/sunshine/platform/linux/graphics.cpp index a0b8d3af..bbf75324 100644 --- a/sunshine/platform/linux/graphics.cpp +++ b/sunshine/platform/linux/graphics.cpp @@ -472,11 +472,17 @@ std::optional import_source(display_t::pointer egl_display, const surface attribs[atti++] = EGL_LINUX_DRM_FOURCC_EXT; attribs[atti++] = xrgb.fourcc; - for(auto x = 0; x < xrgb.obj_count; ++x) { - auto plane_attr = get_plane(xrgb.plane_indices[x]); + for(auto x = 0; x < 4; ++x) { + auto fd = xrgb.fds[x]; + + if(fd < 0) { + continue; + } + + auto plane_attr = get_plane(x); attribs[atti++] = plane_attr.fd; - attribs[atti++] = xrgb.fds[x]; + attribs[atti++] = fd; attribs[atti++] = plane_attr.offset; attribs[atti++] = xrgb.offsets[x]; attribs[atti++] = plane_attr.pitch; diff --git a/sunshine/platform/linux/graphics.h b/sunshine/platform/linux/graphics.h index 127077e4..02de4d93 100644 --- a/sunshine/platform/linux/graphics.h +++ b/sunshine/platform/linux/graphics.h @@ -218,8 +218,6 @@ KITTY_USING_MOVE_T(ctx_t, (std::tuple), , { }); struct surface_descriptor_t { - int obj_count; - int width; int height; int fds[4]; @@ -227,7 +225,6 @@ struct surface_descriptor_t { std::uint64_t modifier; std::uint32_t pitches[4]; std::uint32_t offsets[4]; - std::uint32_t plane_indices[4]; }; display_t make_display(util::Either native_display); @@ -259,11 +256,13 @@ public: } void reset() { - std::for_each_n(sd.fds, sd.obj_count, [](int fd) { - close(fd); - }); + for(auto x = 0; x < 4; ++x) { + if(sd.fds[x] >= 0) { + close(sd.fds[x]); - sd.obj_count = 0; + sd.fds[x] = -1; + } + } } surface_descriptor_t sd; diff --git a/sunshine/platform/linux/kmsgrab.cpp b/sunshine/platform/linux/kmsgrab.cpp index 08668c92..6b0389f3 100644 --- a/sunshine/platform/linux/kmsgrab.cpp +++ b/sunshine/platform/linux/kmsgrab.cpp @@ -574,37 +574,29 @@ public: return capture_e::error; } - auto obj_count = 4; - - int x = 0; for(int y = 0; y < 4; ++y) { if(!fb->handles[y]) { // It's not clear wheter there could still be valid handles left. // So, continue anyway. // TODO: Is this redundent? - --obj_count; continue; } - file[x] = card.handleFD(fb->handles[x]); - if(file[x].el < 0) { + file[y] = card.handleFD(fb->handles[y]); + if(file[y].el < 0) { BOOST_LOG(error) << "Couldn't get primary file descriptor for Framebuffer ["sv << fb->fb_id << "]: "sv << strerror(errno); return capture_e::error; } - sd->fds[x] = file[x].el; - sd->offsets[x] = fb->offsets[y]; - sd->pitches[x] = fb->pitches[y]; - sd->plane_indices[x] = y; - - ++x; + sd->fds[y] = file[y].el; + sd->offsets[y] = fb->offsets[y]; + sd->pitches[y] = fb->pitches[y]; } - sd->width = fb->width; - sd->height = fb->height; - sd->modifier = fb->modifier; - sd->fourcc = fb->pixel_format; - sd->obj_count = obj_count; + sd->width = fb->width; + sd->height = fb->height; + sd->modifier = fb->modifier; + sd->fourcc = fb->pixel_format; if( fb->width != img_width || @@ -775,8 +767,8 @@ public: img->data = nullptr; img->pixel_pitch = 4; - img->sequence = 0; - img->sd.obj_count = 0; + img->sequence = 0; + std::fill_n(img->sd.fds, 4, -1); return img; } @@ -836,7 +828,7 @@ public: if(!cursor || !cursor_opt) { img_out_base->data = nullptr; - for(auto x = 0; x < img->sd.obj_count; ++x) { + for(auto x = 0; x < 4; ++x) { fb_fd[x].release(); } return capture_e::ok; @@ -847,7 +839,7 @@ public: img->x -= offset_x; img->y -= offset_y; - for(auto x = 0; x < img->sd.obj_count; ++x) { + for(auto x = 0; x < 4; ++x) { fb_fd[x].release(); } return capture_e::ok; diff --git a/sunshine/platform/linux/vaapi.cpp b/sunshine/platform/linux/vaapi.cpp index 28876f40..33646333 100644 --- a/sunshine/platform/linux/vaapi.cpp +++ b/sunshine/platform/linux/vaapi.cpp @@ -350,16 +350,14 @@ public: auto nv12_opt = egl::import_target( display.get(), std::move(fds), - { 1, - (int)prime.width, + { (int)prime.width, (int)prime.height, { prime.objects[prime.layers[0].object_index[0]].fd, -1, -1, -1 }, 0, 0, { prime.layers[0].pitch[0] }, { prime.layers[0].offset[0] } }, - { 1, - (int)prime.width / 2, + { (int)prime.width / 2, (int)prime.height / 2, { prime.objects[prime.layers[0].object_index[1]].fd, -1, -1, -1 }, 0, diff --git a/sunshine/platform/linux/wayland.cpp b/sunshine/platform/linux/wayland.cpp index 35bad4be..9b65ef8d 100644 --- a/sunshine/platform/linux/wayland.cpp +++ b/sunshine/platform/linux/wayland.cpp @@ -17,6 +17,7 @@ using namespace std::literals; // Disable warning for converting incompatible functions #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" +#pragma GCC diagnostic ignored "-Wpmf-conversions" namespace wl { int display_t::init(const char *display_name) { @@ -164,11 +165,10 @@ void dmabuf_t::frame( std::uint32_t obj_count) { auto next_frame = get_next_frame(); - next_frame->sd.fourcc = format; - next_frame->sd.width = width; - next_frame->sd.height = height; - next_frame->sd.modifier = (((std::uint64_t)high) << 32) | low; - next_frame->sd.obj_count = obj_count; + next_frame->sd.fourcc = format; + next_frame->sd.width = width; + next_frame->sd.height = height; + next_frame->sd.modifier = (((std::uint64_t)high) << 32) | low; } void dmabuf_t::object( @@ -181,10 +181,9 @@ void dmabuf_t::object( std::uint32_t plane_index) { auto next_frame = get_next_frame(); - next_frame->sd.fds[index] = fd; - next_frame->sd.pitches[index] = stride; - next_frame->sd.offsets[index] = offset; - next_frame->sd.plane_indices[index] = plane_index; + next_frame->sd.fds[plane_index] = fd; + next_frame->sd.pitches[plane_index] = stride; + next_frame->sd.offsets[plane_index] = offset; } void dmabuf_t::ready( @@ -212,12 +211,20 @@ void dmabuf_t::cancel( } void frame_t::destroy() { - for(auto x = 0; x < sd.obj_count; ++x) { - close(sd.fds[x]); + for(auto x = 0; x < 4; ++x) { + if(sd.fds[x] >= 0) { + close(sd.fds[x]); + + sd.fds[x] = -1; + } } - sd.obj_count = 0; } +frame_t::frame_t() { + // File descriptors aren't open + std::fill_n(sd.fds, 4, -1); +}; + std::vector> monitors(const char *display_name) { display_t display; diff --git a/sunshine/platform/linux/wayland.h b/sunshine/platform/linux/wayland.h index 409c3a01..d6e63843 100644 --- a/sunshine/platform/linux/wayland.h +++ b/sunshine/platform/linux/wayland.h @@ -21,6 +21,7 @@ using display_internal_t = util::safe_ptr; class frame_t { public: + frame_t(); egl::surface_descriptor_t sd; void destroy(); diff --git a/sunshine/platform/linux/wlgrab.cpp b/sunshine/platform/linux/wlgrab.cpp index c40ac483..c4ab3dbf 100644 --- a/sunshine/platform/linux/wlgrab.cpp +++ b/sunshine/platform/linux/wlgrab.cpp @@ -263,7 +263,7 @@ public: img->sd = current_frame->sd; // Prevent dmabuf from closing the file descriptors. - current_frame->sd.obj_count = 0; + std::fill_n(current_frame->sd.fds, 4, -1); return platf::capture_e::ok; } @@ -275,6 +275,9 @@ public: img->serial = std::numeric_limitsserial)>::max(); img->data = nullptr; + // File descriptors aren't open + std::fill_n(img->sd.fds, 4, -1); + return img; }