MythTV master
mythdrmplane.cpp
Go to the documentation of this file.
1// MythTV
4
5#define LOC QString("DRMPlane: ")
6
12QString MythDRMPlane::PlaneTypeToString(uint64_t Type)
13{
14 if (Type == DRM_PLANE_TYPE_OVERLAY) return "Overlay";
15 if (Type == DRM_PLANE_TYPE_CURSOR) return "Cursor";
16 if (Type == DRM_PLANE_TYPE_PRIMARY) return "Primary";
17 return "Unknown";
18}
19
20DRMPlane MythDRMPlane::Create(int FD, uint32_t Id, uint32_t Index)
21{
22 if (FD && Id)
23 if (auto plane = std::shared_ptr<MythDRMPlane>(new MythDRMPlane(FD, Id, Index)); plane && plane->m_id)
24 return plane;
25
26 return nullptr;
27}
28
29MythDRMPlane::MythDRMPlane(int FD, uint32_t Id, uint32_t Index)
30{
31 if (auto * plane = drmModeGetPlane(FD, Id); plane)
32 {
33 auto id = plane->plane_id;
34 m_index = Index;
35 m_id = id;
36 m_fbId = plane->fb_id;
37 m_crtcId = plane->crtc_id;
38 m_possibleCrtcs = plane->possible_crtcs;
39
40 for (uint32_t j = 0; j < plane->count_formats; ++j)
41 {
42 m_formats.emplace_back(plane->formats[j]);
43 if (FormatIsVideo(plane->formats[j]))
44 m_videoFormats.emplace_back(plane->formats[j]);
45 }
46
47 m_properties = MythDRMProperty::GetProperties(FD, m_id, DRM_MODE_OBJECT_PLANE);
48
49 // Add generic properties
51 if (auto * enumt = dynamic_cast<MythDRMEnumProperty*>(type.get()); enumt)
52 m_type = enumt->m_value;
53
54 // Add video specific properties
55 if (!m_videoFormats.empty())
56 {
67 }
68
69 drmModeFreePlane(plane);
70 }
71}
72
74{
75 return QString("Plane #%1 %2 Index: %3 FB: %4 CRTC: %5 Formats: %6")
78}
79
80DRMPlanes MythDRMPlane::GetPlanes(int FD, int CRTCFilter)
81{
82 DRMPlanes result;
83 auto * planes = drmModeGetPlaneResources(FD);
84 if (!planes)
85 {
86 LOG(VB_GENERAL, LOG_ERR, QString(drmGetDeviceNameFromFd2(FD)) + ": Failed to retrieve planes");
87 return result;
88 }
89
90 for (uint32_t index = 0; index < planes->count_planes; ++index)
91 {
92 if (auto plane = MythDRMPlane::Create(FD, planes->planes[index], index); plane)
93 {
94 if ((CRTCFilter > -1) && !(plane->m_possibleCrtcs & (1 << CRTCFilter)))
95 continue;
96 result.emplace_back(plane);
97 }
98 }
99
100 drmModeFreePlaneResources(planes);
101 return result;
102}
103
105{
106 DRMPlanes result;
107 for (const auto & plane : Planes)
108 if ((plane->m_type == DRM_PLANE_TYPE_PRIMARY) && !plane->m_videoFormats.empty())
109 result.emplace_back(plane);
110
111 return result;
112}
113
115{
116 DRMPlanes result;
117 for (const auto & plane : Planes)
118 if ((plane->m_type == DRM_PLANE_TYPE_OVERLAY) && HasOverlayFormat(plane->m_formats))
119 result.emplace_back(plane);
120
121 return result;
122}
123
125{
126 switch (Format)
127 {
128 // Note: These match the string literals in QKmsDevice config parsing (but
129 // must be used lower case in the KMS config file)
130 case DRM_FORMAT_RGB565: return "RGB565";
131 case DRM_FORMAT_XRGB8888: return "XRGB8888";
132 case DRM_FORMAT_XBGR8888: return "XBGR8888";
133 case DRM_FORMAT_ARGB8888: return "ARGB8888";
134 case DRM_FORMAT_RGBA8888: return "RGBA8888";
135 case DRM_FORMAT_ABGR8888: return "ABGR8888";
136 case DRM_FORMAT_BGRA8888: return "BGRA8888";
137 case DRM_FORMAT_XRGB2101010: return "XRGB2101010";
138 case DRM_FORMAT_XBGR2101010: return "XBGR2101010";
139 case DRM_FORMAT_ARGB2101010: return "ARGB2101010";
140 case DRM_FORMAT_ABGR2101010: return "ABGR2101010";
141 // Not supported by Qt as overlay formats
142 case DRM_FORMAT_XRGB16161616F: return "XRGB16F";
143 case DRM_FORMAT_XBGR16161616F: return "XBGR16F";
144 case DRM_FORMAT_ARGB16161616F: return "ARGB16F";
145 case DRM_FORMAT_ABGR16161616F: return "ABGR16F";
146 default: break;
147 }
148 return QString::asprintf("%c%c%c%c", Format, Format >> 8, Format >> 16, Format >> 24);
149}
150
152{
153 QStringList formats;
154 for (auto format : Formats)
155 formats.append(FormatToString(format));
156 return formats.join(",");
157}
158
160{
161 static const FOURCCVec s_yuvFormats =
162 {
163 // Bi-planar
164 DRM_FORMAT_NV12, DRM_FORMAT_NV21, DRM_FORMAT_NV16, DRM_FORMAT_NV61,
165 DRM_FORMAT_NV24, DRM_FORMAT_NV42, DRM_FORMAT_P210, DRM_FORMAT_P010,
168 // Tri-planar formats
169 DRM_FORMAT_YUV410, DRM_FORMAT_YVU410, DRM_FORMAT_YUV411, DRM_FORMAT_YVU411,
170 DRM_FORMAT_YUV420, DRM_FORMAT_YVU420, DRM_FORMAT_YUV422, DRM_FORMAT_YVU422,
171 DRM_FORMAT_YUV444, DRM_FORMAT_YVU444,
172 // Packed formats
173 DRM_FORMAT_YUYV, DRM_FORMAT_YVYU, DRM_FORMAT_UYVY, DRM_FORMAT_VYUY
174 };
175
176 return std::find(s_yuvFormats.cbegin(), s_yuvFormats.cend(), Format) != s_yuvFormats.cend();
177}
178
182{
183 // Formats as deemed suitable by QKmsDevice
184 static const FOURCCVec s_rgbFormats =
185 {
186 DRM_FORMAT_XRGB8888, DRM_FORMAT_XRGB8888, DRM_FORMAT_XBGR8888,
187 DRM_FORMAT_ARGB8888, DRM_FORMAT_ABGR8888, DRM_FORMAT_RGB565,
188 DRM_FORMAT_BGR565, DRM_FORMAT_XRGB2101010, DRM_FORMAT_XBGR2101010,
189 DRM_FORMAT_ARGB2101010, DRM_FORMAT_ABGR2101010
190 };
191
192 for (auto format : Formats)
193 if (std::any_of(s_rgbFormats.cbegin(), s_rgbFormats.cend(), [&format](auto Format) { return Format == format; }))
194 return true;
195
196 return false;
197}
198
200{
201 // N.B. Prioritised list
202 static const FOURCCVec s_alphaFormats =
203 {
204 DRM_FORMAT_ARGB8888, DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB2101010, DRM_FORMAT_ABGR2101010
205 };
206
207 for (auto format : s_alphaFormats)
208 if (std::any_of(Formats.cbegin(), Formats.cend(), [&format](auto Format) { return Format == format; }))
209 return format;
210
211 return DRM_FORMAT_INVALID;
212}
DRMProp m_crtcXProp
Definition: mythdrmplane.h:83
uint32_t m_crtcId
Definition: mythdrmplane.h:74
DRMProp m_srcYProp
Definition: mythdrmplane.h:80
static QString FormatsToString(const FOURCCVec &Formats)
DRMProps m_properties
Definition: mythdrmplane.h:75
uint32_t m_id
Definition: mythdrmplane.h:69
static bool FormatIsVideo(uint32_t Format)
QString Description() const
DRMProp m_crtcIdProp
Definition: mythdrmplane.h:78
static DRMPlanes GetPlanes(int FD, int CRTCFilter=-1)
static bool HasOverlayFormat(const FOURCCVec &Formats)
Enusure list of supplied formats contains a format that is suitable for OpenGL/Vulkan.
DRMProp m_crtcHProp
Definition: mythdrmplane.h:86
static QString FormatToString(uint32_t Format)
FOURCCVec m_videoFormats
Definition: mythdrmplane.h:89
DRMProp m_srcWProp
Definition: mythdrmplane.h:81
static QString PlaneTypeToString(uint64_t Type)
uint32_t m_fbId
Definition: mythdrmplane.h:73
uint64_t m_type
Definition: mythdrmplane.h:71
FOURCCVec m_formats
Definition: mythdrmplane.h:88
DRMProp m_srcXProp
Definition: mythdrmplane.h:79
DRMProp m_fbIdProp
Definition: mythdrmplane.h:77
static uint32_t GetAlphaFormat(const FOURCCVec &Formats)
DRMProp m_crtcYProp
Definition: mythdrmplane.h:84
uint32_t m_possibleCrtcs
Definition: mythdrmplane.h:72
static DRMPlanes FilterPrimaryPlanes(const DRMPlanes &Planes)
MythDRMPlane(int FD, uint32_t Id, uint32_t Index)
DRMProp m_srcHProp
Definition: mythdrmplane.h:82
uint32_t m_index
Definition: mythdrmplane.h:70
DRMProp m_crtcWProp
Definition: mythdrmplane.h:85
static DRMPlane Create(int FD, uint32_t Id, uint32_t Index)
static DRMPlanes FilterOverlayPlanes(const DRMPlanes &Planes)
static DRMProp GetProperty(const QString &Name, const DRMProps &Properties)
static DRMProps GetProperties(int FD, uint32_t ObjectId, uint32_t ObjectType)
static pid_list_t::iterator find(const PIDInfoMap &map, pid_list_t &list, pid_list_t::iterator begin, pid_list_t::iterator end, bool find_open)
#define DRM_FORMAT_INVALID
Definition: mythdrmplane.h:13
#define DRM_FORMAT_P016
Definition: mythdrmplane.h:31
std::vector< DRMPlane > DRMPlanes
Definition: mythdrmplane.h:51
#define DRM_FORMAT_NV20
Definition: mythdrmplane.h:19
#define DRM_FORMAT_NV15
Definition: mythdrmplane.h:16
#define DRM_FORMAT_XRGB16161616F
Definition: mythdrmplane.h:37
#define DRM_FORMAT_P210
Definition: mythdrmplane.h:22
#define DRM_FORMAT_ARGB16161616F
Definition: mythdrmplane.h:43
std::shared_ptr< class MythDRMPlane > DRMPlane
Definition: mythdrmplane.h:50
#define DRM_FORMAT_P010
Definition: mythdrmplane.h:25
#define DRM_FORMAT_P012
Definition: mythdrmplane.h:28
#define DRM_FORMAT_XBGR16161616F
Definition: mythdrmplane.h:40
std::vector< uint32_t > FOURCCVec
Definition: mythdrmplane.h:49
#define DRM_FORMAT_ABGR16161616F
Definition: mythdrmplane.h:46
#define DRM_FORMAT_P030
Definition: mythdrmplane.h:34
static constexpr uint32_t DRM_FORMAT_NV12
static constexpr uint32_t DRM_FORMAT_NV21
static constexpr uint32_t DRM_FORMAT_YVU420
static constexpr uint32_t DRM_FORMAT_YUV420
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
const std::array< const std::string, 8 > formats
Definition: vbilut.cpp:189