diff options
Diffstat (limited to 'libkms++/dumbframebuffer.cpp')
-rw-r--r-- | libkms++/dumbframebuffer.cpp | 20 |
1 files changed, 19 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); } } |