Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions src/platform/linux/kmsgrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ namespace platf {

class wrapper_fb {
public:
wrapper_fb(drmModeFB *fb):
wrapper_fb(uint32_t card_fd, drmModeFB *fb):
card_fd {card_fd},
fb {fb},
fb_id {fb->fb_id},
width {fb->width},
Expand All @@ -74,7 +75,8 @@ namespace platf {
pitches[0] = fb->pitch;
}

wrapper_fb(drmModeFB2 *fb2):
wrapper_fb(uint32_t card_fd, drmModeFB2 *fb2):
card_fd {card_fd},
fb2 {fb2},
fb_id {fb2->fb_id},
width {fb2->width},
Expand All @@ -88,13 +90,23 @@ namespace platf {
}

~wrapper_fb() {
std::ranges::for_each(handles, [&](auto &handle) {
if (handle) {
struct drm_gem_close close_args = {};
close_args.handle = handle;

drmIoctl(card_fd, DRM_IOCTL_GEM_CLOSE, &close_args);
}
});

if (fb) {
drmModeFreeFB(fb);
} else if (fb2) {
drmModeFreeFB2(fb2);
}
}

uint32_t card_fd;
drmModeFB *fb = nullptr;
drmModeFB2 *fb2 = nullptr;
uint32_t fb_id;
Expand Down Expand Up @@ -359,12 +371,12 @@ namespace platf {

auto fb2 = drmModeGetFB2(fd.el, plane->fb_id);
if (fb2) {
return std::make_unique<wrapper_fb>(fb2);
return std::make_unique<wrapper_fb>(fd.el, fb2);
}

auto fb = drmModeGetFB(fd.el, plane->fb_id);
if (fb) {
return std::make_unique<wrapper_fb>(fb);
return std::make_unique<wrapper_fb>(fd.el, fb);
}

return nullptr;
Expand Down
Loading