diff options
| author | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2025-04-26 19:38:51 +0300 |
|---|---|---|
| committer | Tomi Valkeinen <tomi.valkeinen@ideasonboard.com> | 2025-04-26 19:38:51 +0300 |
| commit | f6a23b8e7e0d0089453367876a9f90abfeb2b394 (patch) | |
| tree | 1e174883d65b2dc7274a148c0b6b42eddd0d465f | |
| parent | 07d9958c9028062135bb0dd51ab76b3e15f40298 (diff) | |
dmabuffb: dup() the fds
Use dup() on the given fds, and take ownership of them. close() at
destructor.
Fixes: #46
| -rw-r--r-- | kms++/src/dmabufframebuffer.cpp | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/kms++/src/dmabufframebuffer.cpp b/kms++/src/dmabufframebuffer.cpp index f303799..3d5b133 100644 --- a/kms++/src/dmabufframebuffer.cpp +++ b/kms++/src/dmabufframebuffer.cpp @@ -39,9 +39,9 @@ DmabufFramebuffer::DmabufFramebuffer(Card& card, uint32_t width, uint32_t height for (int i = 0; i < format_info.num_planes; ++i) { FramebufferPlane& plane = m_planes.at(i); - plane.prime_fd = fds[i]; + plane.prime_fd = dup(fds[i]); - r = drmPrimeFDToHandle(card.fd(), fds[i], &plane.handle); + r = drmPrimeFDToHandle(card.fd(), plane.prime_fd, &plane.handle); if (r) throw invalid_argument(string("drmPrimeFDToHandle: ") + strerror(errno)); @@ -76,6 +76,16 @@ DmabufFramebuffer::DmabufFramebuffer(Card& card, uint32_t width, uint32_t height DmabufFramebuffer::~DmabufFramebuffer() { drmModeRmFB(card().fd(), id()); + + for (uint i = 0; i < m_num_planes; ++i) { + FramebufferPlane& plane = m_planes.at(i); + + if (plane.map) + munmap(plane.map, plane.size); + + if (plane.prime_fd >= 0) + ::close(plane.prime_fd); + } } uint8_t* DmabufFramebuffer::map(unsigned plane) |
