vdr-plugin-softhddevice-drm-gles 1.5.9-20e15de
drmplane.cpp
Go to the documentation of this file.
1
24#include <cerrno>
25#include <cinttypes>
26#include <cstdlib>
27#include <cstring>
28
29#include <xf86drm.h>
30#include <xf86drmMode.h>
31
32#include "drmplane.h"
33#include "logger.h"
34
35/*****************************************************************************
36 * cDrmPlane class
37 ****************************************************************************/
38
47{
48 drmModeObjectProperties *props = drmModeObjectGetProperties(fd, GetId(), DRM_MODE_OBJECT_PLANE);
49 if (!props) {
50 LOGERROR("drmplane: %s: could not get %u properties: %s", __FUNCTION__, GetId(), strerror(errno));
51 return;
52 }
53
54 SetProps(props);
55
56 m_propsInfo = (drmModePropertyRes **)calloc(m_props->count_props, sizeof(*m_propsInfo));
57 for (uint32_t i = 0; i < m_props->count_props; i++) {
58 m_propsInfo[i] = drmModeGetProperty(fd, m_props->props[i]);
59 }
60}
61
66{
67 if (!GetProps())
68 return;
69
70 if (!GetPropsInfo())
71 return;
72
73 for (uint32_t i = 0; i < m_props->count_props; i++) {
74 if (m_propsInfo[i])
75 drmModeFreeProperty(m_propsInfo[i]);
76
77 }
78 drmModeFreeObjectProperties(m_props);
79 free(m_propsInfo);
80}
81
98void cDrmPlane::SetParams(uint64_t crtcId, uint64_t fbId,
99 uint64_t crtcX, uint64_t crtcY, uint64_t crtcW, uint64_t crtcH,
100 uint64_t srcX, uint64_t srcY, uint64_t srcW, uint64_t srcH)
101{
102 m_crtcId = crtcId;
103 m_fbId = fbId;
104 m_crtcX = crtcX;
105 m_crtcY = crtcY;
106 m_crtcW = crtcW;
107 m_crtcH = crtcH;
108 m_srcX = srcX;
109 m_srcY = srcY;
110 m_srcW = srcW;
111 m_srcH = srcH;
112}
113
121int cDrmPlane::SetPropertyRequest(drmModeAtomicReqPtr ModeReq, const char *propName, uint64_t value)
122{
123 int id = -1;
124
125 for (int i = 0; i < GetCountProps(); i++) {
126 if (strcmp(GetPropsInfoName(i), propName) == 0) {
127 id = GetPropsInfoPropId(i);
128 break;
129 }
130 }
131
132 if (id < 0) {
133 LOGDEBUG("drmplane: %s: Unable to find value for property \'%s\'.",
134 __FUNCTION__, propName);
135 return -EINVAL;
136 }
137
138 return drmModeAtomicAddProperty(ModeReq, GetId(), id, value);
139}
140
146void cDrmPlane::SetPlaneZpos(drmModeAtomicReqPtr ModeReq)
147{
148 SetPropertyRequest(ModeReq, "zpos", GetZpos());
149}
150
156void cDrmPlane::SetPlane(drmModeAtomicReqPtr ModeReq)
157{
158 SetPropertyRequest(ModeReq, "CRTC_ID", GetCrtcId());
159 SetPropertyRequest(ModeReq, "FB_ID", GetFbId());
160
161 SetPropertyRequest(ModeReq, "CRTC_X", GetCrtcX());
162 SetPropertyRequest(ModeReq, "CRTC_Y", GetCrtcY());
163 SetPropertyRequest(ModeReq, "CRTC_W", GetCrtcW());
164 SetPropertyRequest(ModeReq, "CRTC_H", GetCrtcH());
165
166 SetPropertyRequest(ModeReq, "SRC_X", GetSrcX());
167 SetPropertyRequest(ModeReq, "SRC_Y", GetSrcY());
168 SetPropertyRequest(ModeReq, "SRC_W", GetSrcW() << 16);
169 SetPropertyRequest(ModeReq, "SRC_H", GetSrcH() << 16);
170}
171
177void cDrmPlane::ClearPlane(drmModeAtomicReqPtr ModeReq)
178{
179 SetPropertyRequest(ModeReq, "FB_ID", 0);
180 SetPropertyRequest(ModeReq, "CRTC_ID", 0);
181}
182
191int cDrmPlane::HasZpos(int fdDrm)
192{
193 drmModeAtomicReqPtr ModeReq;
194 const uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET;
195
196 if (!(ModeReq = drmModeAtomicAlloc())) {
197 LOGERROR("drmplane: %s: cannot allocate atomic request (%d): %m", __FUNCTION__, errno);
198 return 0;
199 }
200
201 SetPlaneZpos(ModeReq);
202
203 if (drmModeAtomicCommit(fdDrm, ModeReq, flags, NULL) != 0) {
204 LOGDEBUG2(L_DRM, "drmplane: %s: cannot set atomic mode (%d), don't use zpos change: %m",
205 __FUNCTION__, errno);
206 drmModeAtomicFree(ModeReq);
207 return 0;
208 }
209
210 drmModeAtomicFree(ModeReq);
211
212 return 1;
213}
214
218void cDrmPlane::DumpParameters(const char *id)
219{
220 LOGERROR("DumpParameters (plane_id = %d | %s):", GetId(), id);
221 LOGERROR(" CRTC ID: %" PRIu64 "", GetCrtcId());
222 LOGERROR(" FB ID : %" PRIu64 "", GetFbId());
223 LOGERROR(" CRTC X : %" PRIu64 "", GetCrtcX());
224 LOGERROR(" CRTC Y : %" PRIu64 "", GetCrtcY());
225 LOGERROR(" CRTC W : %" PRIu64 "", GetCrtcW());
226 LOGERROR(" CRTC H : %" PRIu64 "", GetCrtcH());
227 LOGERROR(" SRC X : %" PRIu64 "", GetSrcX());
228 LOGERROR(" SRC Y : %" PRIu64 "", GetSrcY());
229 LOGERROR(" SRC W : %" PRIu64 "", GetSrcW());
230 LOGERROR(" SRC H : %" PRIu64 "", GetSrcH());
231 LOGERROR(" ZPOS : %" PRIu64 "", GetZpos());
232}
uint64_t m_crtcX
CRTC_X.
Definition drmplane.h:80
uint64_t GetCrtcX(void)
Definition drmplane.h:51
uint64_t m_fbId
FB_ID.
Definition drmplane.h:79
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:98
uint64_t GetCrtcId(void)
Definition drmplane.h:49
void ClearPlane(drmModeAtomicReqPtr)
Clear plane from drm.
Definition drmplane.cpp:177
uint64_t GetCrtcH(void)
Definition drmplane.h:54
uint64_t m_crtcId
CRTC_ID.
Definition drmplane.h:78
void SetProps(drmModeObjectProperties *props)
Definition drmplane.h:66
uint64_t GetSrcH(void)
Definition drmplane.h:58
uint32_t GetPropsInfoPropId(int prop)
Definition drmplane.h:64
int SetPropertyRequest(drmModeAtomicReqPtr, const char *, uint64_t)
Add the properties to the mode setting request.
Definition drmplane.cpp:121
uint64_t GetZpos(void)
Definition drmplane.h:59
int HasZpos(int)
Check, if the plane is able to set the zpos property.
Definition drmplane.cpp:191
void FillProperties(int)
Fill the plane properties.
Definition drmplane.cpp:46
char * GetPropsInfoName(int prop)
Definition drmplane.h:63
uint64_t GetSrcY(void)
Definition drmplane.h:56
uint64_t m_crtcW
CRTC_W.
Definition drmplane.h:82
uint64_t m_srcW
SRC_W.
Definition drmplane.h:86
uint64_t GetFbId(void)
Definition drmplane.h:50
drmModeObjectProperties * m_props
Definition drmplane.h:74
drmModePropertyRes ** GetPropsInfo(void)
Definition drmplane.h:67
uint64_t m_crtcH
CRTC_H.
Definition drmplane.h:83
void FreeProperties(void)
Free the previously filled plane properties.
Definition drmplane.cpp:65
void SetPlane(drmModeAtomicReqPtr)
Set all other plane properties.
Definition drmplane.cpp:156
int GetCountProps(void)
Definition drmplane.h:62
drmModePropertyRes ** m_propsInfo
Definition drmplane.h:75
uint64_t m_crtcY
CRTC_Y.
Definition drmplane.h:81
void SetPlaneZpos(drmModeAtomicReqPtr)
Set the plane zpos property.
Definition drmplane.cpp:146
uint64_t GetSrcW(void)
Definition drmplane.h:57
uint64_t m_srcY
SRC_Y.
Definition drmplane.h:85
uint64_t m_srcH
SRC_H.
Definition drmplane.h:87
drmModeObjectProperties * GetProps(void)
Definition drmplane.h:65
uint64_t GetSrcX(void)
Definition drmplane.h:55
uint64_t GetCrtcW(void)
Definition drmplane.h:53
uint64_t m_srcX
SRC_X.
Definition drmplane.h:84
uint32_t GetId(void)
Definition drmplane.h:45
uint64_t GetCrtcY(void)
Definition drmplane.h:52
void DumpParameters(const char *)
Dump the plane parameter modesetting values.
Definition drmplane.cpp:218
DRM plane class header.
Logger class header file.
#define LOGDEBUG2
Definition logger.h:45
#define LOGDEBUG
Definition logger.h:44
#define LOGERROR
Definition logger.h:41
#define L_DRM
Definition logger.h:57