libkms++/encoder: Add methods for getting details of the DRM object
[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         :DrmObject(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 void Encoder::print_short() const
48 {
49         auto e = m_priv->drm_encoder;
51         printf("Encoder %d, %d\n", id(),
52                e->encoder_type);
53 }
55 Crtc* Encoder::get_crtc() const
56 {
57         if (m_priv->drm_encoder->crtc_id)
58                 return card().get_crtc(m_priv->drm_encoder->crtc_id);
59         else
60                 return 0;
61 }
63 vector<Crtc*> Encoder::get_possible_crtcs() const
64 {
65         unsigned bits = m_priv->drm_encoder->possible_crtcs;
66         vector<Crtc*> crtcs;
68         for (int idx = 0; bits; idx++, bits >>= 1) {
69                 if ((bits & 1) == 0)
70                         continue;
72                 auto crtc = card().get_crtc_by_index(idx);
73                 crtcs.push_back(crtc);
74         }
76         return crtcs;
77 }
79 const string& Encoder::get_encoder_type() const
80 {
81         return encoder_types.at(m_priv->drm_encoder->encoder_type);
82 }
84 }