vdr-plugin-softhddevice-drm-gles 1.6.2
softhdosd.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
18#include "logger.h"
19#include "softhddevice.h"
20#include "softhdosd.h"
21
38 : cOsd(left, top, level),
39 m_pDevice(device),
40 m_osdLevel(level)
41{
42 LOGDEBUG2(L_OSD, "osd: %s: %dx%d%+d%+d, %d", __FUNCTION__, OsdWidth(), OsdHeight(), left, top, level);
43}
44
49{
50 LOGDEBUG2(L_OSD, "osd: %s: level %d", __FUNCTION__, m_osdLevel);
51
52 SetActive(false); // done by SetActive(): OsdClose();
53}
54
63{
64 LOGDEBUG2(L_OSD, "osd: %s: %d level %d", __FUNCTION__, on, m_osdLevel);
65
66 if (Active() == on)
67 return; // already active, no action
68
69 cOsd::SetActive(on);
70
71 if (on) {
72 m_dirty = true;
73 // only flush here if there are already bitmaps
74 if (GetBitmap(0)) {
75 Flush();
76 }
77 } else
79}
80
85{
86 LOGDEBUG2(L_OSD, "osd: %s: %d areas", __FUNCTION__, n);
87
88 // clear old OSD, when new areas are set
89 if (!IsTrueColor()) {
91 int i;
92
93 for (i = 0; (bitmap = GetBitmap(i)); i++)
94 bitmap->Clean();
95 }
96
97 if (Active()) {
99 m_dirty = true;
100 }
101
102 return cOsd::SetAreas(areas, n);
103}
104
109{
111
112 LOGDEBUG2(L_OSD, "osd: %s: level %d active %d", __FUNCTION__, m_osdLevel,
113 Active());
114
115 if (!Active()) // this osd is not active
116 return;
117
118 if (!IsTrueColor()) {
120 int i;
121
122 static char warned;
123
124 if (!warned) {
125 LOGDEBUG2(L_OSD, "osd: %s: FIXME: should be truecolor", __FUNCTION__);
126 warned = 1;
127 }
128
129 // draw all bitmaps
130 for (i = 0; (bitmap = GetBitmap(i)); ++i) {
131 uint8_t *argb;
132 int xs;
133 int ys;
134 int x;
135 int y;
136 int w;
137 int h;
138 int x1;
139 int y1;
140 int x2;
141 int y2;
142
143 // get dirty bounding box
144 if (m_dirty) { // forced complete update
145 x1 = 0;
146 y1 = 0;
147 x2 = bitmap->Width() - 1;
148 y2 = bitmap->Height() - 1;
149 } else if (!bitmap->Dirty(x1, y1, x2, y2)) {
150 continue; // nothing dirty continue
151 }
152
153 // convert and upload only visible dirty areas
154 xs = bitmap->X0() + Left();
155 ys = bitmap->Y0() + Top();
156
157 // FIXME: negtative position bitmaps
158 w = x2 - x1 + 1;
159 h = y2 - y1 + 1;
160
161 // clip to screen
162 int width;
163 int height;
164 double videoAspect;
165
166 if (xs < 0) {
167 if (xs + x1 < 0) {
168 x1 -= xs + x1;
169 w += xs + x1;
170 if (w <= 0)
171 continue;
172 }
173 xs = 0;
174 }
175
176 if (ys < 0) {
177 if (ys + y1 < 0) {
178 y1 -= ys + y1;
179 h += ys + y1;
180 if (h <= 0)
181 continue;
182 }
183 ys = 0;
184 }
185
186 m_pDevice->GetOsdSize(width, height, videoAspect);
187 if (w > width - xs - x1) {
188 w = width - xs - x1;
189 if (w <= 0)
190 continue;
191 x2 = x1 + w - 1;
192 }
193
194 if (h > height - ys - y1) {
195 h = height - ys - y1;
196 if (h <= 0)
197 continue;
198 y2 = y1 + h - 1;
199 }
200
201 if (w > bitmap->Width() || h > bitmap->Height())
202 LOGDEBUG2(L_OSD, "osd: %s: dirty area too big", __FUNCTION__);
203
204 argb = (uint8_t *) malloc(w * h * sizeof(uint32_t));
205 for (y = y1; y <= y2; ++y) {
206 for (x = x1; x <= x2; ++x) {
207 ((uint32_t *) argb)[x - x1 + (y - y1) * w] =
208 bitmap->GetColor(x, y);
209 }
210 }
211 LOGDEBUG2(L_OSD, "osd: %s: draw %dx%d%+d%+d bm", __FUNCTION__, w, h, xs + x1, ys + y1);
212 m_pDevice->OsdDrawARGB(0, 0, w, h, w * sizeof(uint32_t), argb, xs + x1, ys + y1);
213
214 bitmap->Clean();
215
216 // FIXME: reuse argb
217 free(argb);
218 }
219 m_dirty = false;
220 return;
221 }
222
224 while ((pm = (dynamic_cast < cPixmapMemory * >(RenderPixmaps())))) {
225 int xp;
226 int yp;
227 int stride;
228 int x;
229 int y;
230 int w;
231 int h;
232
233 x = pm->ViewPort().X();
234 y = pm->ViewPort().Y();
235 w = pm->ViewPort().Width();
236 h = pm->ViewPort().Height();
237 stride = w * sizeof(tColor);
238
239 // clip to osd
240 xp = 0;
241 if (x < 0) {
242 xp = -x;
243 w -= xp;
244 x = 0;
245 }
246
247 yp = 0;
248 if (y < 0) {
249 yp = -y;
250 h -= yp;
251 y = 0;
252 }
253
254 if (w > Width() - x)
255 w = Width() - x;
256 if (h > Height() - y)
257 h = Height() - y;
258
259 x += Left();
260 y += Top();
261
262 // clip to screen
263 int width;
264 int height;
265 double videoAspect;
266
267 if (x < 0) {
268 w += x;
269 xp += -x;
270 x = 0;
271 }
272 if (y < 0) {
273 h += y;
274 yp += -y;
275 y = 0;
276 }
277
278 m_pDevice->GetOsdSize(width, height, videoAspect);
279 if (w > width - x)
280 w = width - x;
281 if (h > height - y)
282 h = height - y;
283
284 LOGDEBUG2(L_OSD, "osd: %s: draw %dx%d%+d%+d*%d -> %+d%+d %p", __FUNCTION__, w, h, xp, yp, stride, x, y, pm->Data());
285 m_pDevice->OsdDrawARGB(xp, yp, w, h, stride, pm->Data(), x, y);
286
287 DestroyPixmap(pm);
288 }
289 m_dirty = false;
290}
291
Output Device Implementation.
int m_osdLevel
current osd level
Definition softhdosd.h:41
cSoftHdDevice * m_pDevice
pointer to the cSoftHdDevice object
Definition softhdosd.h:39
bool m_dirty
flag to force redrawing everything
Definition softhdosd.h:40
void OsdDrawARGB(int, int, int, int, int, const uint8_t *, int, int)
Draw an OSD pixmap.
virtual void GetOsdSize(int &, int &, double &)
Returns the width, height and aspect ratio the OSD.
void OsdClose(void)
Close the OSD.
#define LOGDEBUG2
log to LOG_DEBUG and add a prefix
Definition logger.h:42
@ L_OSD
osd logs
Definition logger.h:54
virtual void Flush(void)
Actually commit all data to the OSD hardware.
virtual ~cSoftOsd(void)
Shut down the OSD.
Definition softhdosd.cpp:48
virtual eOsdError SetAreas(const tArea *, int)
Set the sub-areas to the given areas.
Definition softhdosd.cpp:84
virtual void SetActive(bool)
Sets this OSD to be the active one.
Definition softhdosd.cpp:62
cSoftOsd(int, int, uint, cSoftHdDevice *)
Initializes a software based OSD with the given coordinates.
Definition softhdosd.cpp:37
Logger Header File.
Output Device Header File.
Software OSD Header File.