3ad3ddfa62c8503d25e8f4146becb684bd1dc2fb
[android/external-libkmsxx.git] / libkms++ / plane.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 PlanePriv
17 {
18         drmModePlanePtr drm_plane;
19 };
21 Plane::Plane(Card &card, uint32_t id)
22         :DrmObject(card, id, DRM_MODE_OBJECT_PLANE)
23 {
24         m_priv = new PlanePriv();
25         m_priv->drm_plane = drmModeGetPlane(this->card().fd(), this->id());
26         assert(m_priv->drm_plane);
27 }
29 Plane::~Plane()
30 {
31         drmModeFreePlane(m_priv->drm_plane);
32         delete m_priv;
33 }
35 void Plane::print_short() const
36 {
37         auto p = m_priv->drm_plane;
39         printf("Plane %d, %d modes, %d,%d -> %dx%d\n", id(),
40                p->count_formats,
41                p->crtc_x, p->crtc_y, p->x, p->y);
43         printf("\t");
44         for (unsigned i = 0; i < p->count_formats; ++i) {
45                 uint32_t f = p->formats[i];
46                 printf("%c%c%c%c ",
47                        (f >> 0) & 0xff,
48                        (f >> 8) & 0xff,
49                        (f >> 16) & 0xff,
50                        (f >> 24) & 0xff);
51         }
52         printf("\n");
53 }
55 bool Plane::supports_crtc(Crtc* crtc) const
56 {
57         return m_priv->drm_plane->possible_crtcs & (1 << crtc->idx());
58 }
60 bool Plane::supports_format(PixelFormat fmt) const
61 {
62         auto p = m_priv->drm_plane;
64         for (unsigned i = 0; i < p->count_formats; ++i)
65                 if ((uint32_t)fmt == p->formats[i])
66                         return true;
68         return false;
69 }
71 PlaneType Plane::plane_type() const
72 {
73         if (card().has_has_universal_planes())
74                 return (PlaneType)get_prop_value("type");
75         else
76                 return PlaneType::Overlay;
77 }
79 vector<PixelFormat> Plane::get_formats() const
80 {
81         auto p = m_priv->drm_plane;
82         vector<PixelFormat> r;
84         for (unsigned i = 0; i < p->count_formats; ++i)
85                 r.push_back((PixelFormat) p->formats[i]);
87         return r;
88 }
90 uint32_t Plane::crtc_id() const
91 {
92         return m_priv->drm_plane->crtc_id;
93 }
95 uint32_t Plane::fb_id() const
96 {
97         return m_priv->drm_plane->fb_id;
98 }
100 uint32_t Plane::crtc_x() const
102         return m_priv->drm_plane->crtc_x;
105 uint32_t Plane::crtc_y() const
107         return m_priv->drm_plane->crtc_y;
110 uint32_t Plane::x() const
112         return m_priv->drm_plane->x;
115 uint32_t Plane::y() const
117         return m_priv->drm_plane->y;
120 uint32_t Plane::gamma_size() const
122         return m_priv->drm_plane->gamma_size;