MythTV  master
mythdrmplane.cpp
Go to the documentation of this file.
1 // MythTV
4 
5 #define LOC QString("DRMPlane: ")
6 
12 QString 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 
20 DRMPlane 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 
29 MythDRMPlane::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 
80 DRMPlanes 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 
199 uint32_t MythDRMPlane::GetAlphaFormat(const FOURCCVec &Formats)
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 }
DRM_FORMAT_NV12
static constexpr uint32_t DRM_FORMAT_NV12
Definition: mythegldmabuf.cpp:251
MythDRMPlane::Create
static DRMPlane Create(int FD, uint32_t Id, uint32_t Index)
Definition: mythdrmplane.cpp:20
MythDRMPlane::m_fbId
uint32_t m_fbId
Definition: mythdrmplane.h:73
FOURCCVec
std::vector< uint32_t > FOURCCVec
Definition: mythdrmplane.h:49
DRM_FORMAT_XBGR16161616F
#define DRM_FORMAT_XBGR16161616F
Definition: mythdrmplane.h:40
MythDRMPlane::FilterPrimaryPlanes
static DRMPlanes FilterPrimaryPlanes(const DRMPlanes &Planes)
Definition: mythdrmplane.cpp:104
MythDRMPlane::FormatToString
static QString FormatToString(uint32_t Format)
Definition: mythdrmplane.cpp:124
MythDRMPlane::PlaneTypeToString
static QString PlaneTypeToString(uint64_t Type)
Definition: mythdrmplane.cpp:12
MythDate::Format
Format
Definition: mythdate.h:15
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
MythDRMPlane::HasOverlayFormat
static bool HasOverlayFormat(const FOURCCVec &Formats)
Enusure list of supplied formats contains a format that is suitable for OpenGL/Vulkan.
Definition: mythdrmplane.cpp:181
MythDRMPlane::m_crtcXProp
DRMProp m_crtcXProp
Definition: mythdrmplane.h:83
MythDRMPlane::FormatsToString
static QString FormatsToString(const FOURCCVec &Formats)
Definition: mythdrmplane.cpp:151
DRM_FORMAT_P030
#define DRM_FORMAT_P030
Definition: mythdrmplane.h:34
DRM_FORMAT_P210
#define DRM_FORMAT_P210
Definition: mythdrmplane.h:22
DRM_FORMAT_NV21
static constexpr uint32_t DRM_FORMAT_NV21
Definition: mythegldmabuf.cpp:252
MythDRMPlane::m_crtcId
uint32_t m_crtcId
Definition: mythdrmplane.h:74
DRM_FORMAT_YVU420
static constexpr uint32_t DRM_FORMAT_YVU420
Definition: mythegldmabuf.cpp:254
MythDRMEnumProperty
Definition: mythdrmproperty.h:62
DRM_FORMAT_INVALID
#define DRM_FORMAT_INVALID
Definition: mythdrmplane.h:13
MythDRMProperty::GetProperty
static DRMProp GetProperty(const QString &Name, const DRMProps &Properties)
Definition: mythdrmproperty.cpp:55
MythDRMPlane::Description
QString Description() const
Definition: mythdrmplane.cpp:73
MythDRMPlane::GetAlphaFormat
static uint32_t GetAlphaFormat(const FOURCCVec &Formats)
Definition: mythdrmplane.cpp:199
DRM_FORMAT_ARGB16161616F
#define DRM_FORMAT_ARGB16161616F
Definition: mythdrmplane.h:43
mythlogging.h
MythDRMPlane::m_index
uint32_t m_index
Definition: mythdrmplane.h:70
MythDRMPlane::m_srcYProp
DRMProp m_srcYProp
Definition: mythdrmplane.h:80
DRM_FORMAT_P016
#define DRM_FORMAT_P016
Definition: mythdrmplane.h:31
formats
const std::array< const std::string, 8 > formats
Definition: vbilut.cpp:189
mythdrmplane.h
DRMPlanes
std::vector< DRMPlane > DRMPlanes
Definition: mythdrmplane.h:51
MythDRMPlane::m_videoFormats
FOURCCVec m_videoFormats
Definition: mythdrmplane.h:89
MythDRMPlane::FormatIsVideo
static bool FormatIsVideo(uint32_t Format)
Definition: mythdrmplane.cpp:159
MythDRMPlane::m_crtcYProp
DRMProp m_crtcYProp
Definition: mythdrmplane.h:84
MythDRMPlane::m_crtcIdProp
DRMProp m_crtcIdProp
Definition: mythdrmplane.h:78
MythDRMPlane::m_id
uint32_t m_id
Definition: mythdrmplane.h:69
MythDRMPlane::m_srcHProp
DRMProp m_srcHProp
Definition: mythdrmplane.h:82
DRM_FORMAT_NV15
#define DRM_FORMAT_NV15
Definition: mythdrmplane.h:16
DRM_FORMAT_P012
#define DRM_FORMAT_P012
Definition: mythdrmplane.h:28
MythDRMPlane::m_crtcWProp
DRMProp m_crtcWProp
Definition: mythdrmplane.h:85
DRM_FORMAT_XRGB16161616F
#define DRM_FORMAT_XRGB16161616F
Definition: mythdrmplane.h:37
DRM_FORMAT_YUV420
static constexpr uint32_t DRM_FORMAT_YUV420
Definition: mythegldmabuf.cpp:253
MythDRMPlane::m_possibleCrtcs
uint32_t m_possibleCrtcs
Definition: mythdrmplane.h:72
MythDRMPlane::m_formats
FOURCCVec m_formats
Definition: mythdrmplane.h:88
MythDRMPlane::m_type
uint64_t m_type
Definition: mythdrmplane.h:71
MythDRMPlane::m_srcXProp
DRMProp m_srcXProp
Definition: mythdrmplane.h:79
MythDRMPlane::MythDRMPlane
MythDRMPlane(int FD, uint32_t Id, uint32_t Index)
Definition: mythdrmplane.cpp:29
DRMPlane
std::shared_ptr< class MythDRMPlane > DRMPlane
Definition: mythdrmplane.h:50
MythDRMPlane::m_fbIdProp
DRMProp m_fbIdProp
Definition: mythdrmplane.h:77
MythDRMPlane::GetPlanes
static DRMPlanes GetPlanes(int FD, int CRTCFilter=-1)
Definition: mythdrmplane.cpp:80
MythDRMPlane::FilterOverlayPlanes
static DRMPlanes FilterOverlayPlanes(const DRMPlanes &Planes)
Definition: mythdrmplane.cpp:114
DRM_FORMAT_P010
#define DRM_FORMAT_P010
Definition: mythdrmplane.h:25
MythDRMPlane::m_properties
DRMProps m_properties
Definition: mythdrmplane.h:75
MythDRMPlane::m_srcWProp
DRMProp m_srcWProp
Definition: mythdrmplane.h:81
MythDRMPlane::m_crtcHProp
DRMProp m_crtcHProp
Definition: mythdrmplane.h:86
DRM_FORMAT_ABGR16161616F
#define DRM_FORMAT_ABGR16161616F
Definition: mythdrmplane.h:46
MythDRMProperty::GetProperties
static DRMProps GetProperties(int FD, uint32_t ObjectId, uint32_t ObjectType)
Definition: mythdrmproperty.cpp:25
find
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)
Definition: dvbstreamhandler.cpp:363
DRM_FORMAT_NV20
#define DRM_FORMAT_NV20
Definition: mythdrmplane.h:19