2 #include <cstring>
3 #include <stdexcept>
4 #include <sys/mman.h>
5 #include <xf86drm.h>
6 #include <xf86drmMode.h>
8 #include "kms++.h"
10 using namespace std;
12 namespace kms
13 {
15 ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, uint32_t depth, uint32_t bpp, uint32_t stride, uint32_t handle)
16 :Framebuffer(card, width, height)
17 {
18 uint32_t id;
19 int r = drmModeAddFB(card.fd(), width, height, depth, bpp, stride, handle, &id);
20 if (r)
21 throw invalid_argument("fob");
23 set_id(id);
24 }
26 ExtFramebuffer::ExtFramebuffer(Card& card, uint32_t width, uint32_t height, PixelFormat format,
27 uint32_t handles[], uint32_t pitches[], uint32_t offsets[])
28 : Framebuffer(card, width, height)
29 {
30 uint32_t id;
31 int r = drmModeAddFB2(card.fd(), width, height, (uint32_t)format, handles, pitches, offsets, &id, 0);
32 if (r)
33 throw std::invalid_argument(string("Failed to create ExtFramebuffer: ") + strerror(r));
35 set_id(id);
36 }
38 ExtFramebuffer::~ExtFramebuffer()
39 {
40 drmModeRmFB(card().fd(), id());
41 }
43 }