vdr-plugin-softhddevice-drm-gles 1.4.0
drmplane.cpp
Go to the documentation of this file.
1
24#include <xf86drm.h>
25#include <xf86drmMode.h>
26#include <cinttypes>
27
28#include "drmplane.h"
29#include "logger.h"
30
31/*****************************************************************************
32 * cDrmPlane class
33 ****************************************************************************/
34
36{
37 m_planeId = 0;
38 m_zpos = 0;
39}
40
42{
43}
44
53{
54 drmModeObjectProperties *props = drmModeObjectGetProperties(fd, GetId(), DRM_MODE_OBJECT_PLANE);
55 if (!props) {
56 LOGERROR("drmplane: %s: could not get %u properties: %s", __FUNCTION__, GetId(), strerror(errno));
57 return;
58 }
59
60 SetProps(props);
61
62 m_propsInfo = (drmModePropertyRes **)calloc(m_props->count_props, sizeof(*m_propsInfo));
63 for (uint32_t i = 0; i < m_props->count_props; i++) {
64 m_propsInfo[i] = drmModeGetProperty(fd, m_props->props[i]);
65 }
66}
67
72{
73 if (!GetProps())
74 return;
75
76 if (!GetPropsInfo())
77 return;
78
79 for (uint32_t i = 0; i < m_props->count_props; i++) {
80 if (m_propsInfo[i])
81 drmModeFreeProperty(m_propsInfo[i]);
82
83 }
84 drmModeFreeObjectProperties(m_props);
85 free(m_propsInfo);
86}
87
104void cDrmPlane::SetParams(uint64_t crtcId, uint64_t fbId,
105 uint64_t crtcX, uint64_t crtcY, uint64_t crtcW, uint64_t crtcH,
106 uint64_t srcX, uint64_t srcY, uint64_t srcW, uint64_t srcH)
107{
108 m_crtcId = crtcId;
109 m_fbId = fbId;
110 m_crtcX = crtcX;
111 m_crtcY = crtcY;
112 m_crtcW = crtcW;
113 m_crtcH = crtcH;
114 m_srcX = srcX;
115 m_srcY = srcY;
116 m_srcW = srcW;
117 m_srcH = srcH;
118}
119
127int cDrmPlane::SetPropertyRequest(drmModeAtomicReqPtr ModeReq, const char *propName, uint64_t value)
128{
129 int id = -1;
130
131 for (int i = 0; i < GetCountProps(); i++) {
132 if (strcmp(GetPropsInfoName(i), propName) == 0) {
133 id = GetPropsInfoPropId(i);
134 break;
135 }
136 }
137
138 if (id < 0) {
139 LOGERROR("drmplane: %s: Unable to find value for property \'%s\'.",
140 __FUNCTION__, propName);
141 return -EINVAL;
142 }
143
144 return drmModeAtomicAddProperty(ModeReq, GetId(), id, value);
145}
146
152void cDrmPlane::SetPlaneZpos(drmModeAtomicReqPtr ModeReq)
153{
154 SetPropertyRequest(ModeReq, "zpos", GetZpos());
155}
156
162void cDrmPlane::SetPlane(drmModeAtomicReqPtr ModeReq)
163{
164 SetPropertyRequest(ModeReq, "CRTC_ID", GetCrtcId());
165 SetPropertyRequest(ModeReq, "FB_ID", GetFbId());
166
167 SetPropertyRequest(ModeReq, "CRTC_X", GetCrtcX());
168 SetPropertyRequest(ModeReq, "CRTC_Y", GetCrtcY());
169 SetPropertyRequest(ModeReq, "CRTC_W", GetCrtcW());
170 SetPropertyRequest(ModeReq, "CRTC_H", GetCrtcH());
171
172 SetPropertyRequest(ModeReq, "SRC_X", GetSrcX());
173 SetPropertyRequest(ModeReq, "SRC_Y", GetSrcY());
174 SetPropertyRequest(ModeReq, "SRC_W", GetSrcW() << 16);
175 SetPropertyRequest(ModeReq, "SRC_H", GetSrcH() << 16);
176}
177
183void cDrmPlane::ClearPlane(drmModeAtomicReqPtr ModeReq)
184{
185 SetPropertyRequest(ModeReq, "FB_ID", 0);
186}
187
196int cDrmPlane::HasZpos(int fdDrm)
197{
198 drmModeAtomicReqPtr ModeReq;
199 const uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET;
200
201 if (!(ModeReq = drmModeAtomicAlloc())) {
202 LOGERROR("drmplane: %s: cannot allocate atomic request (%d): %m", __FUNCTION__, errno);
203 return 0;
204 }
205
206 SetPlaneZpos(ModeReq);
207
208 if (drmModeAtomicCommit(fdDrm, ModeReq, flags, NULL) != 0) {
209 LOGDEBUG2(L_DRM, "drmplane: %s: cannot set atomic mode (%d), don't use zpos change: %m",
210 __FUNCTION__, errno);
211 drmModeAtomicFree(ModeReq);
212 return 0;
213 }
214
215 drmModeAtomicFree(ModeReq);
216
217 return 1;
218}
219
223void cDrmPlane::DumpParameters(const char *id)
224{
225 LOGERROR("DumpParameters (plane_id = %d | %s):", GetId(), id);
226 LOGERROR(" CRTC ID: %" PRIu64 "", GetCrtcId());
227 LOGERROR(" FB ID : %" PRIu64 "", GetFbId());
228 LOGERROR(" CRTC X : %" PRIu64 "", GetCrtcX());
229 LOGERROR(" CRTC Y : %" PRIu64 "", GetCrtcY());
230 LOGERROR(" CRTC W : %" PRIu64 "", GetCrtcW());
231 LOGERROR(" CRTC H : %" PRIu64 "", GetCrtcH());
232 LOGERROR(" SRC X : %" PRIu64 "", GetSrcX());
233 LOGERROR(" SRC Y : %" PRIu64 "", GetSrcY());
234 LOGERROR(" SRC W : %" PRIu64 "", GetSrcW());
235 LOGERROR(" SRC H : %" PRIu64 "", GetSrcH());
236 LOGERROR(" ZPOS : %" PRIu64 "", GetZpos());
237}
uint64_t m_crtcX
CRTC_X.
Definition: drmplane.h:81
uint64_t GetCrtcX(void)
Definition: drmplane.h:52
uint64_t m_fbId
FB_ID.
Definition: drmplane.h:80
cDrmPlane(void)
Definition: drmplane.cpp:35
void SetParams(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t, uint64_t)
Set the modesetting parameters of a plane.
Definition: drmplane.cpp:104
uint64_t GetCrtcId(void)
Definition: drmplane.h:50
void ClearPlane(drmModeAtomicReqPtr)
Clear plane from drm.
Definition: drmplane.cpp:183
uint64_t GetCrtcH(void)
Definition: drmplane.h:55
uint64_t m_crtcId
CRTC_ID.
Definition: drmplane.h:79
void SetProps(drmModeObjectProperties *props)
Definition: drmplane.h:67
uint64_t GetSrcH(void)
Definition: drmplane.h:59
uint32_t GetPropsInfoPropId(int prop)
Definition: drmplane.h:65
int SetPropertyRequest(drmModeAtomicReqPtr, const char *, uint64_t)
Add the properties to the mode setting request.
Definition: drmplane.cpp:127
uint64_t GetZpos(void)
Definition: drmplane.h:60
int HasZpos(int)
Check, if the plane is able to set the zpos property.
Definition: drmplane.cpp:196
void FillProperties(int)
Fill the plane properties.
Definition: drmplane.cpp:52
char * GetPropsInfoName(int prop)
Definition: drmplane.h:64
uint64_t GetSrcY(void)
Definition: drmplane.h:57
uint64_t m_zpos
ZPOS.
Definition: drmplane.h:89
uint64_t m_crtcW
CRTC_W.
Definition: drmplane.h:83
uint64_t m_srcW
SRC_W.
Definition: drmplane.h:87
uint64_t GetFbId(void)
Definition: drmplane.h:51
drmModeObjectProperties * m_props
Definition: drmplane.h:75
drmModePropertyRes ** GetPropsInfo(void)
Definition: drmplane.h:68
uint64_t m_crtcH
CRTC_H.
Definition: drmplane.h:84
void FreeProperties(void)
Free the previously filled plane properties.
Definition: drmplane.cpp:71
void SetPlane(drmModeAtomicReqPtr)
Set all other plane properties.
Definition: drmplane.cpp:162
int GetCountProps(void)
Definition: drmplane.h:63
drmModePropertyRes ** m_propsInfo
Definition: drmplane.h:76
uint64_t m_crtcY
CRTC_Y.
Definition: drmplane.h:82
void SetPlaneZpos(drmModeAtomicReqPtr)
Set the plane zpos property.
Definition: drmplane.cpp:152
uint32_t m_planeId
the plane's ID
Definition: drmplane.h:72
uint64_t GetSrcW(void)
Definition: drmplane.h:58
uint64_t m_srcY
SRC_Y.
Definition: drmplane.h:86
uint64_t m_srcH
SRC_H.
Definition: drmplane.h:88
drmModeObjectProperties * GetProps(void)
Definition: drmplane.h:66
uint64_t GetSrcX(void)
Definition: drmplane.h:56
uint64_t GetCrtcW(void)
Definition: drmplane.h:54
virtual ~cDrmPlane(void)
Definition: drmplane.cpp:41
uint64_t m_srcX
SRC_X.
Definition: drmplane.h:85
uint32_t GetId(void)
Definition: drmplane.h:46
uint64_t GetCrtcY(void)
Definition: drmplane.h:53
void DumpParameters(const char *)
Dump the plane parameter modesetting values.
Definition: drmplane.cpp:223
DRM plane class header.
Logger class header file.
#define LOGDEBUG2
Definition: logger.h:50
#define LOGERROR
Definition: logger.h:46
#define L_DRM
Definition: logger.h:62