diff options
-rw-r--r-- | libkms++/dumbframebuffer.cpp | 20 | ||||
-rw-r--r-- | libkms++/dumbframebuffer.h | 2 |
2 files changed, 21 insertions, 1 deletions
diff --git a/libkms++/dumbframebuffer.cpp b/libkms++/dumbframebuffer.cpp index 0779b05..46a6e5a 100644 --- a/libkms++/dumbframebuffer.cpp +++ b/libkms++/dumbframebuffer.cpp @@ -4,6 +4,8 @@ #include <sys/mman.h> #include <xf86drm.h> #include <xf86drmMode.h> +#include <fcntl.h> +#include <unistd.h> #include <drm_fourcc.h> #include <drm.h> #include <drm_mode.h> @@ -33,6 +35,19 @@ DumbFramebuffer::~DumbFramebuffer() Destroy(); } +uint32_t DumbFramebuffer::prime_fd(unsigned int plane) +{ + if (m_planes[plane].prime_fd >= 0) + return m_planes[plane].prime_fd; + + int r = drmPrimeHandleToFD(card().fd(), m_planes[plane].handle, + DRM_CLOEXEC, &m_planes[plane].prime_fd); + if (r) + throw std::runtime_error("drmPrimeHandleToFD failed\n"); + + return m_planes[plane].prime_fd; +} + struct FormatPlaneInfo { uint8_t bitspp; /* bits per (macro) pixel */ @@ -110,6 +125,8 @@ void DumbFramebuffer::Create() /* clear the framebuffer to 0 */ memset(plane.map, 0, plane.size); + + plane.prime_fd = -1; } /* create framebuffer object for the dumb-buffer */ @@ -140,7 +157,8 @@ void DumbFramebuffer::Destroy() struct drm_mode_destroy_dumb dreq = drm_mode_destroy_dumb(); dreq.handle = plane.handle; drmIoctl(card().fd(), DRM_IOCTL_MODE_DESTROY_DUMB, &dreq); - + if (plane.prime_fd >= 0) + ::close(plane.prime_fd); } } diff --git a/libkms++/dumbframebuffer.h b/libkms++/dumbframebuffer.h index 0ee0406..51f5123 100644 --- a/libkms++/dumbframebuffer.h +++ b/libkms++/dumbframebuffer.h @@ -20,12 +20,14 @@ public: uint32_t stride(unsigned plane) const { return m_planes[plane].stride; } uint32_t size(unsigned plane) const { return m_planes[plane].size; } uint32_t offset(unsigned plane) const { return m_planes[plane].offset; } + uint32_t prime_fd(unsigned plane); void clear(); private: struct FramebufferPlane { uint32_t handle; + int prime_fd; uint32_t size; uint32_t stride; uint32_t offset; |