summaryrefslogtreecommitdiff
path: root/kms++/extframebuffer.cpp
diff options
context:
space:
mode:
authorTomi Valkeinen <tomi.valkeinen@ti.com>2016-06-11 20:17:35 +0300
committerTomi Valkeinen <tomi.valkeinen@ti.com>2016-06-11 20:17:35 +0300
commit17d180891f1e237ea5d25835999a8b23a6e7946d (patch)
tree5963fe4d338f6272daf55c76ed355effb47afc71 /kms++/extframebuffer.cpp
parent38a71ee72c47f3287c327113ce411f236cac05ef (diff)
rename dirs
Diffstat (limited to 'kms++/extframebuffer.cpp')
-rw-r--r--kms++/extframebuffer.cpp68
1 files changed, 68 insertions, 0 deletions
diff --git a/kms++/extframebuffer.cpp b/kms++/extframebuffer.cpp
new file mode 100644
index 0000000..352c1a7
--- /dev/null
+++ b/kms++/extframebuffer.cpp
@@ -0,0 +1,68 @@
+
+#include <cstring>
+#include <stdexcept>
+#include <sys/mman.h>
+#include <xf86drm.h>
+#include <xf86drmMode.h>
+
+#include "kms++.h"
+
+using namespace std;
+
+namespace kms
+{
+
+ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, uint8_t depth, uint8_t bpp, uint32_t stride, uint32_t handle)
+ :Framebuffer(card, width, height)
+{
+ uint32_t id;
+ int r = drmModeAddFB(card.fd(), width, height, depth, bpp, stride, handle, &id);
+ if (r)
+ throw invalid_argument("fob");
+
+ set_id(id);
+}
+
+ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, PixelFormat format,
+ uint32_t handles[], uint32_t pitches[], uint32_t offsets[])
+ : Framebuffer(card, width, height)
+{
+ uint32_t id;
+ int r = drmModeAddFB2(card.fd(), width, height, (uint32_t)format, handles, pitches, offsets, &id, 0);
+ if (r)
+ throw std::invalid_argument(string("Failed to create ExtFramebuffer: ") + strerror(r));
+
+ set_id(id);
+}
+
+ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, PixelFormat format,
+ int fds[4], uint32_t pitches[4], uint32_t offsets[4])
+ : Framebuffer(card, width, height)
+{
+ int r;
+
+ const PixelFormatInfo& format_info = get_pixel_format_info(format);
+
+ uint32_t handles[4] = { 0 };
+
+ for (int i = 0; i < format_info.num_planes; ++i) {
+ r = drmPrimeFDToHandle(card.fd(), fds[i], &handles[i]);
+ if (r)
+ throw invalid_argument(string("drmPrimeFDToHandle: ") + strerror(errno));
+ }
+
+ uint32_t id;
+ r = drmModeAddFB2(card.fd(), width, height, (uint32_t)format,
+ handles, pitches, offsets, &id, 0);
+ if (r)
+ throw invalid_argument(string("drmModeAddFB2 failed: ") + strerror(errno));
+
+ set_id(id);
+}
+
+ExtFramebuffer::~ExtFramebuffer()
+{
+ drmModeRmFB(card().fd(), id());
+}
+
+}