summaryrefslogtreecommitdiff
path: root/libkms++
diff options
context:
space:
mode:
authorPeter Ujfalusi <peter.ujfalusi@ti.com>2015-10-26 15:05:31 +0200
committerTomi Valkeinen <tomi.valkeinen@ti.com>2015-11-12 16:09:46 +0200
commitdc27a456ddfa9020097c2e5faf8ec47385f4f920 (patch)
treefeacdb96947883e4bbff351aeb43759cac6def4d /libkms++
parent131a6e455743b757f8a5f79aefa956b046dce4ba (diff)
libkms++: dumbframebuffer: Get file descriptor for the FB
v4l linux needs file descriptor instead of handle.
Diffstat (limited to 'libkms++')
-rw-r--r--libkms++/dumbframebuffer.cpp20
-rw-r--r--libkms++/dumbframebuffer.h2
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;