forked from zillevdr/vdr-plugin-softhddevice-drm
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdrmplane.cpp
More file actions
220 lines (192 loc) · 5.83 KB
/
Copy pathdrmplane.cpp
File metadata and controls
220 lines (192 loc) · 5.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
// SPDX-License-Identifier: AGPL-3.0-or-later
/**
* @file drmplane.cpp
* DRM Plane
*
* This file defines cDrmPlane, which is a class to describe
* planes, that are used for modesetting in the DRM system.
*
* @copyright 2018 by zille. All Rights Reserved.
* @copyright 2025 - 2026 by Andreas Baierl. All Rights Reserved.
*
* @license{AGPL-3.0-or-later}
*/
#include <cerrno>
#include <cinttypes>
#include <cstdlib>
#include <cstring>
#include <xf86drm.h>
#include <xf86drmMode.h>
#include "drmplane.h"
#include "logger.h"
/**
* Fill the plane properties
*
* This "caches" the properties within the class
*
* @param fd drm file descriptor
*/
void cDrmPlane::FillProperties(int fd)
{
drmModeObjectProperties *props = drmModeObjectGetProperties(fd, GetId(), DRM_MODE_OBJECT_PLANE);
if (!props) {
LOGERROR("drmplane: %s: could not get %u properties: %s", __FUNCTION__, GetId(), strerror(errno));
return;
}
SetProps(props);
m_propsInfo = (drmModePropertyRes **)calloc(m_props->count_props, sizeof(*m_propsInfo));
for (uint32_t i = 0; i < m_props->count_props; i++) {
m_propsInfo[i] = drmModeGetProperty(fd, m_props->props[i]);
}
}
/**
* Free the previously filled plane properties
*/
void cDrmPlane::FreeProperties(void)
{
if (!GetProps())
return;
if (!GetPropsInfo())
return;
for (uint32_t i = 0; i < m_props->count_props; i++) {
if (m_propsInfo[i])
drmModeFreeProperty(m_propsInfo[i]);
}
drmModeFreeObjectProperties(m_props);
free(m_propsInfo);
}
/**
* Caches the modesetting parameters of a plane
*
* These values are used for drm modesetting
*
* @param crtcId Mode object ID of the crtc
* @param fbId Mode object ID of the drm framebuffer
* @param crtcX X offset of the destination rect
* @param crtcY Y offset of the destination rect
* @param crtcW width of the destination rect
* @param crtcH height of the destination rect
* @param srcX X offset of the source rect
* @param srcY Y offset of the source rect
* @param srcW width of the source rect
* @param srccH height of the source rect
*/
void cDrmPlane::SetParams(uint64_t crtcId, uint64_t fbId,
uint64_t crtcX, uint64_t crtcY, uint64_t crtcW, uint64_t crtcH,
uint64_t srcX, uint64_t srcY, uint64_t srcW, uint64_t srcH)
{
m_crtcId = crtcId;
m_fbId = fbId;
m_crtcX = crtcX;
m_crtcY = crtcY;
m_crtcW = crtcW;
m_crtcH = crtcH;
m_srcX = srcX;
m_srcY = srcY;
m_srcW = srcW;
m_srcH = srcH;
}
/**
* Add the properties to the mode setting request
*
* @param ModeReq pointer to the atomic mode request
* @param propName name of the property to set
* @param value property value
*/
int cDrmPlane::SetPropertyRequest(drmModeAtomicReqPtr ModeReq, const char *propName, uint64_t value)
{
int id = -1;
for (int i = 0; i < GetCountProps(); i++) {
if (strcmp(GetPropsInfoName(i), propName) == 0) {
id = GetPropsInfoPropId(i);
break;
}
}
if (id < 0) {
LOGDEBUG("drmplane: %s: Unable to find value for property \'%s\'.",
__FUNCTION__, propName);
return -EINVAL;
}
return drmModeAtomicAddProperty(ModeReq, GetId(), id, value);
}
/**
* Set the plane zpos property
*
* @param ModeReq pointer to the atomic mode request
*/
void cDrmPlane::SetPlaneZpos(drmModeAtomicReqPtr ModeReq)
{
SetPropertyRequest(ModeReq, "zpos", GetZpos());
}
/**
* Set all plane properties (except zpos)
*
* @param ModeReq pointer to the atomic mode request
*/
void cDrmPlane::SetPlane(drmModeAtomicReqPtr ModeReq)
{
SetPropertyRequest(ModeReq, "CRTC_ID", GetCrtcId());
SetPropertyRequest(ModeReq, "FB_ID", GetFbId());
SetPropertyRequest(ModeReq, "CRTC_X", GetCrtcX());
SetPropertyRequest(ModeReq, "CRTC_Y", GetCrtcY());
SetPropertyRequest(ModeReq, "CRTC_W", GetCrtcW());
SetPropertyRequest(ModeReq, "CRTC_H", GetCrtcH());
SetPropertyRequest(ModeReq, "SRC_X", GetSrcX());
SetPropertyRequest(ModeReq, "SRC_Y", GetSrcY());
SetPropertyRequest(ModeReq, "SRC_W", GetSrcW() << 16);
SetPropertyRequest(ModeReq, "SRC_H", GetSrcH() << 16);
}
/**
* Clear plane from drm
*
* @param ModeReq pointer to the atomic mode request
*/
void cDrmPlane::ClearPlane(drmModeAtomicReqPtr ModeReq)
{
SetPropertyRequest(ModeReq, "FB_ID", 0);
SetPropertyRequest(ModeReq, "CRTC_ID", 0);
}
/**
* Check, if the plane is able to set the zpos property
*
* @param fdDrm drm file descriptor
*
* @retval 1 plane can use zpos
* @retval 0 plane can't use zpos
*/
int cDrmPlane::HasZpos(int fdDrm)
{
drmModeAtomicReqPtr ModeReq;
const uint32_t flags = DRM_MODE_ATOMIC_ALLOW_MODESET;
if (!(ModeReq = drmModeAtomicAlloc())) {
LOGERROR("drmplane: %s: cannot allocate atomic request (%d): %m", __FUNCTION__, errno);
return 0;
}
SetPlaneZpos(ModeReq);
if (drmModeAtomicCommit(fdDrm, ModeReq, flags, NULL) != 0) {
LOGDEBUG2(L_DRM, "drmplane: %s: cannot set atomic mode (%d), don't use zpos change: %m",
__FUNCTION__, errno);
drmModeAtomicFree(ModeReq);
return 0;
}
drmModeAtomicFree(ModeReq);
return 1;
}
/**
* Dump the cached plane parameter modesetting values
*/
void cDrmPlane::DumpParameters(const char *id)
{
LOGERROR("DumpParameters (plane_id = %d | %s):", GetId(), id);
LOGERROR(" CRTC ID: %" PRIu64 "", GetCrtcId());
LOGERROR(" FB ID : %" PRIu64 "", GetFbId());
LOGERROR(" CRTC X : %" PRIu64 "", GetCrtcX());
LOGERROR(" CRTC Y : %" PRIu64 "", GetCrtcY());
LOGERROR(" CRTC W : %" PRIu64 "", GetCrtcW());
LOGERROR(" CRTC H : %" PRIu64 "", GetCrtcH());
LOGERROR(" SRC X : %" PRIu64 "", GetSrcX());
LOGERROR(" SRC Y : %" PRIu64 "", GetSrcY());
LOGERROR(" SRC W : %" PRIu64 "", GetSrcW());
LOGERROR(" SRC H : %" PRIu64 "", GetSrcH());
LOGERROR(" ZPOS : %" PRIu64 "", GetZpos());
}