Make Encoder:get_crtc() return 0 if no crtc
[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 Encoder::Encoder(Card &card, uint32_t id)
22         :DrmObject(card, id, DRM_MODE_OBJECT_ENCODER)
23 {
24         m_priv = new EncoderPriv();
25         m_priv->drm_encoder = drmModeGetEncoder(this->card().fd(), this->id());
26         assert(m_priv->drm_encoder);
27 }
29 Encoder::~Encoder()
30 {
31         drmModeFreeEncoder(m_priv->drm_encoder);
32         delete m_priv;
33 }
35 void Encoder::print_short() const
36 {
37         auto e = m_priv->drm_encoder;
39         printf("Encoder %d, %d\n", id(),
40                e->encoder_type);
41 }
43 Crtc* Encoder::get_crtc() const
44 {
45         if (m_priv->drm_encoder->crtc_id)
46                 return card().get_crtc(m_priv->drm_encoder->crtc_id);
47         else
48                 return 0;
49 }
51 vector<Crtc*> Encoder::get_possible_crtcs() const
52 {
53         unsigned bits = m_priv->drm_encoder->possible_crtcs;
54         vector<Crtc*> crtcs;
56         for (int idx = 0; bits; idx++, bits >>= 1) {
57                 if ((bits & 1) == 0)
58                         continue;
60                 auto crtc = card().get_crtc_by_index(idx);
61                 crtcs.push_back(crtc);
62         }
64         return crtcs;
65 }
66 }