ba6b0765be53171a13bc6f2b40f14c37b10ee178
[android/external-libkmsxx.git] / libkms++ / encoder.cpp
1 #include <stdio.h>
2 #include <iostream>
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <cassert>
6 #include <xf86drm.h>
7 #include <xf86drmMode.h>
9 #include "kms++.h"
11 using namespace std;
13 namespace kms
14 {
16 struct EncoderPriv
17 {
18         drmModeEncoderPtr drm_encoder;
19 };
21 static const map<int, string> encoder_types = {
22 #define DEF_ENC(c) { DRM_MODE_ENCODER_##c, #c }
23         DEF_ENC(NONE),
24         DEF_ENC(DAC),
25         DEF_ENC(TMDS),
26         DEF_ENC(LVDS),
27         DEF_ENC(TVDAC),
28         DEF_ENC(VIRTUAL),
29         DEF_ENC(DSI),
30 #undef DEF_ENC
31 };
33 Encoder::Encoder(Card &card, uint32_t id)
34         :DrmPropObject(card, id, DRM_MODE_OBJECT_ENCODER)
35 {
36         m_priv = new EncoderPriv();
37         m_priv->drm_encoder = drmModeGetEncoder(this->card().fd(), this->id());
38         assert(m_priv->drm_encoder);
39 }
41 Encoder::~Encoder()
42 {
43         drmModeFreeEncoder(m_priv->drm_encoder);
44         delete m_priv;
45 }
47 Crtc* Encoder::get_crtc() const
48 {
49         if (m_priv->drm_encoder->crtc_id)
50                 return card().get_crtc(m_priv->drm_encoder->crtc_id);
51         else
52                 return 0;
53 }
55 vector<Crtc*> Encoder::get_possible_crtcs() const
56 {
57         unsigned bits = m_priv->drm_encoder->possible_crtcs;
58         vector<Crtc*> crtcs;
60         for (int idx = 0; bits; idx++, bits >>= 1) {
61                 if ((bits & 1) == 0)
62                         continue;
64                 auto crtc = card().get_crtc_by_index(idx);
65                 crtcs.push_back(crtc);
66         }
68         return crtcs;
69 }
71 const string& Encoder::get_encoder_type() const
72 {
73         return encoder_types.at(m_priv->drm_encoder->encoder_type);
74 }
76 }