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