• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <algorithm>
2 #include <cstring>
3 #include <stdexcept>
4 #include <sys/mman.h>
5 #include <xf86drm.h>
6 #include <xf86drmMode.h>
7 
8 #include <kms++/kms++.h>
9 
10 using namespace std;
11 
12 namespace kms
13 {
14 
Framebuffer(Card & card,uint32_t width,uint32_t height)15 Framebuffer::Framebuffer(Card& card, uint32_t width, uint32_t height)
16 	: DrmObject(card, DRM_MODE_OBJECT_FB), m_width(width), m_height(height)
17 {
18 	card.m_framebuffers.push_back(this);
19 }
20 
Framebuffer(Card & card,uint32_t id)21 Framebuffer::Framebuffer(Card& card, uint32_t id)
22 	: DrmObject(card, id, DRM_MODE_OBJECT_FB)
23 {
24 	auto fb = drmModeGetFB(card.fd(), id);
25 
26 	if (fb) {
27 		m_width = fb->width;
28 		m_height = fb->height;
29 
30 		drmModeFreeFB(fb);
31 	} else {
32 		m_width = m_height = 0;
33 	}
34 
35 	card.m_framebuffers.push_back(this);
36 }
37 
flush()38 void Framebuffer::flush()
39 {
40 	drmModeClip clip { };
41 	clip.x1 = clip.y1 = 0;
42 	clip.x2 = width();
43 	clip.y2 = height();
44 
45 	drmModeDirtyFB(card().fd(), id(), &clip, 1);
46 }
47 
~Framebuffer()48 Framebuffer::~Framebuffer()
49 {
50 	auto& fbs = card().m_framebuffers;
51 	auto iter = find(fbs.begin(), fbs.end(), this);
52 	card().m_framebuffers.erase(iter);
53 }
54 
55 
56 }
57