Fb: collect fbs and destroy them in card's destructor
[android/external-libkmsxx.git] / libkms++ / framebuffer.cpp
1 #include <algorithm>
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 Framebuffer::Framebuffer(Card& card, int width, int height)
16         : DrmObject(card, DRM_MODE_OBJECT_FB), m_width(width), m_height(height)
17 {
18         card.m_framebuffers.push_back(this);
19 }
21 Framebuffer::Framebuffer(Card& card, uint32_t id)
22         : DrmObject(card, id, DRM_MODE_OBJECT_FB)
23 {
24         auto fb = drmModeGetFB(card.fd(), id);
26         m_width = fb->width;
27         m_height = fb->height;
29         drmModeFreeFB(fb);
31         card.m_framebuffers.push_back(this);
32 }
34 Framebuffer::~Framebuffer()
35 {
36         auto& fbs = card().m_framebuffers;
37         auto iter = find(fbs.begin(), fbs.end(), this);
38         card().m_framebuffers.erase(iter);
39 }
42 }