MythTV master
mythdrmplane.cpp
Go to the documentation of this file.
1// MythTV
4
5#include <algorithm>
6
7#define LOC QString("DRMPlane: ")
8
14QString MythDRMPlane::PlaneTypeToString(uint64_t Type)
15{
16 if (Type == DRM_PLANE_TYPE_OVERLAY) return "Overlay";
17 if (Type == DRM_PLANE_TYPE_CURSOR) return "Cursor";
18 if (Type == DRM_PLANE_TYPE_PRIMARY) return "Primary";
19 return "Unknown";
20}
21
22DRMPlane MythDRMPlane::Create(int FD, uint32_t Id, uint32_t Index)
23{
24 if (FD && Id)
25 if (auto plane = std::shared_ptr<MythDRMPlane>(new MythDRMPlane(FD, Id, Index)); plane && plane->m_id)
26 return plane;
27
28 return nullptr;
29}
30
31MythDRMPlane::MythDRMPlane(int FD, uint32_t Id, uint32_t Index)
32{
33 if (auto * plane = drmModeGetPlane(FD, Id); plane)
34 {
35 auto id = plane->plane_id;
36 m_index = Index;
37 m_id = id;
38 m_fbId = plane->fb_id;
39 m_crtcId = plane->crtc_id;
40 m_possibleCrtcs = plane->possible_crtcs;
41
42 for (uint32_t j = 0; j < plane->count_formats; ++j)
43 {
44 m_formats.emplace_back(plane->formats[j]);
45 if (FormatIsVideo(plane->formats[j]))
46 m_videoFormats.emplace_back(plane->formats[j]);
47 }
48
49 m_properties = MythDRMProperty::GetProperties(FD, m_id, DRM_MODE_OBJECT_PLANE);
50
51 // Add generic properties
53 if (auto * enumt = dynamic_cast<MythDRMEnumProperty*>(type.get()); enumt)
54 m_type = enumt->m_value;
55
56 // Add video specific properties
57 if (!m_videoFormats.empty())
58 {
69 }
70
71 drmModeFreePlane(plane);
72 }
73}
74
76{
77 return QString("Plane #%1 %2 Index: %3 FB: %4 CRTC: %5 Formats: %6")
80}
81
82DRMPlanes MythDRMPlane::GetPlanes(int FD, int CRTCFilter)
83{
84 DRMPlanes result;
85 auto * planes = drmModeGetPlaneResources(FD);
86 if (!planes)
87 {
88 LOG(VB_GENERAL, LOG_ERR, QString(drmGetDeviceNameFromFd2(FD)) + ": Failed to retrieve planes");
89 return result;
90 }
91
92 for (uint32_t index = 0; index < planes->count_planes; ++index)
93 {
94 if (auto plane = MythDRMPlane::Create(FD, planes->planes[index], index); plane)
95 {
96 if ((CRTCFilter > -1) && !(plane->m_possibleCrtcs & (1 << CRTCFilter)))
97 continue;
98 result.emplace_back(plane);
99 }
100 }
101
102 drmModeFreePlaneResources(planes);
103 return result;
104}
105
107{
108 DRMPlanes result;
109 for (const auto & plane : Planes)
110 if ((plane->m_type == DRM_PLANE_TYPE_PRIMARY) && !plane->m_videoFormats.empty())
111 result.emplace_back(plane);
112
113 return result;
114}
115
117{
118 DRMPlanes result;
119 for (const auto & plane : Planes)
120 if ((plane->m_type == DRM_PLANE_TYPE_OVERLAY) && HasOverlayFormat(plane->m_formats))
121 result.emplace_back(plane);
122
123 return result;
124}
125
127{
128 switch (Format)
129 {
130 // Note: These match the string literals in QKmsDevice config parsing (but
131 // must be used lower case in the KMS config file)
132 case DRM_FORMAT_RGB565: return "RGB565";
133 case DRM_FORMAT_XRGB8888: return "XRGB8888";
134 case DRM_FORMAT_XBGR8888: return "XBGR8888";
135 case DRM_FORMAT_ARGB8888: return "ARGB8888";
136 case DRM_FORMAT_RGBA8888: return "RGBA8888";
137 case DRM_FORMAT_ABGR8888: return "ABGR8888";
138 case DRM_FORMAT_BGRA8888: return "BGRA8888";
139 case DRM_FORMAT_XRGB2101010: return "XRGB2101010";
140 case DRM_FORMAT_XBGR2101010: return "XBGR2101010";
141 case DRM_FORMAT_ARGB2101010: return "ARGB2101010";
142 case DRM_FORMAT_ABGR2101010: return "ABGR2101010";
143 // Not supported by Qt as overlay formats
144 case DRM_FORMAT_XRGB16161616F: return "XRGB16F";
145 case DRM_FORMAT_XBGR16161616F: return "XBGR16F";
146 case DRM_FORMAT_ARGB16161616F: return "ARGB16F";
147 case DRM_FORMAT_ABGR16161616F: return "ABGR16F";
148 default: break;
149 }
150 return QString::asprintf("%c%c%c%c", Format, Format >> 8, Format >> 16, Format >> 24);
151}
152
154{
155 QStringList formats;
156 for (auto format : Formats)
157 formats.append(FormatToString(format));
158 return formats.join(",");
159}
160
162{
163 static const FOURCCVec s_yuvFormats =
164 {
165 // Bi-planar
166 DRM_FORMAT_NV12, DRM_FORMAT_NV21, DRM_FORMAT_NV16, DRM_FORMAT_NV61,
167 DRM_FORMAT_NV24, DRM_FORMAT_NV42, DRM_FORMAT_P210, DRM_FORMAT_P010,
170 // Tri-planar formats
171 DRM_FORMAT_YUV410, DRM_FORMAT_YVU410, DRM_FORMAT_YUV411, DRM_FORMAT_YVU411,
172 DRM_FORMAT_YUV420, DRM_FORMAT_YVU420, DRM_FORMAT_YUV422, DRM_FORMAT_YVU422,
173 DRM_FORMAT_YUV444, DRM_FORMAT_YVU444,
174 // Packed formats
175 DRM_FORMAT_YUYV, DRM_FORMAT_YVYU, DRM_FORMAT_UYVY, DRM_FORMAT_VYUY
176 };
177
178#ifdef __cpp_lib_ranges_contains
179 return std::ranges::contains(s_yuvFormats, Format);
180#else
181 return std::ranges::find(s_yuvFormats, Format) != s_yuvFormats.end();
182#endif
183}
184
188{
189 // Formats as deemed suitable by QKmsDevice
190 static const FOURCCVec s_rgbFormats =
191 {
192 DRM_FORMAT_XRGB8888, DRM_FORMAT_XRGB8888, DRM_FORMAT_XBGR8888,
193 DRM_FORMAT_ARGB8888, DRM_FORMAT_ABGR8888, DRM_FORMAT_RGB565,
194 DRM_FORMAT_BGR565, DRM_FORMAT_XRGB2101010, DRM_FORMAT_XBGR2101010,
195 DRM_FORMAT_ARGB2101010, DRM_FORMAT_ABGR2101010
196 };
197
198 return std::ranges::any_of(Formats,
199 [](uint32_t format) {
200#ifdef __cpp_lib_ranges_contains
201 return std::ranges::contains(s_rgbFormats, format);
202#else
203 return std::ranges::any_of(s_rgbFormats,
204 [&format](auto Format) { return Format == format; });
205#endif
206 });
207}
208
210{
211 // N.B. Prioritised list
212 static const FOURCCVec s_alphaFormats =
213 {
214 DRM_FORMAT_ARGB8888, DRM_FORMAT_ABGR8888, DRM_FORMAT_ARGB2101010, DRM_FORMAT_ABGR2101010
215 };
216
217 for (auto format : s_alphaFormats)
218 {
219#ifdef __cpp_lib_ranges_contains
220 if (std::ranges::contains(Formats, format))
221#else
222 if (std::ranges::any_of(Formats,
223 [&format](auto Format) { return Format == format; }))
224#endif
225 return format;
226 }
227
228 return DRM_FORMAT_INVALID;
229}
static const std::array< const std::string, 8 > formats
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