add ExtFramebuffer ctr for fds
authorTomi Valkeinen <tomi.valkeinen@ti.com>
Sat, 26 Mar 2016 13:12:11 +0000 (15:12 +0200)
committerTomi Valkeinen <tomi.valkeinen@ti.com>
Sat, 26 Mar 2016 13:12:49 +0000 (15:12 +0200)
libkms++/extframebuffer.cpp
libkms++/extframebuffer.h

index 35fead8f1cf86e932c252eb8f7c0f49059e19864..2dd290338bcd30c131551e01e9467966bd7c1994 100644 (file)
@@ -35,6 +35,31 @@ ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, Pixe
        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());
index 8c17a299c35c48695b4efaa0a0b033f5d6509312..7ed3434ac2d6ad4d5048c4e2abc925f8b9b6b36f 100644 (file)
@@ -12,6 +12,8 @@ public:
        ExtFramebuffer(Card& card, uint32_t width, uint32_t height, uint32_t depth, uint32_t bpp, uint32_t stride, uint32_t handle);
        ExtFramebuffer(Card& card, uint32_t width, uint32_t height, PixelFormat format,
                       uint32_t handles[4], uint32_t pitches[4], uint32_t offsets[4]);
+       ExtFramebuffer(Card& card, uint32_t width, uint32_t height, PixelFormat format,
+                      int fds[4], uint32_t pitches[4], uint32_t offsets[4]);
        virtual ~ExtFramebuffer();
 
 private: