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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
|
/*
vo_ggi.c - General Graphics Interface (GGI) Renderer for MPlayer
(C) Alex Beregszaszi
Uses libGGI - http://www.ggi-project.org/
TODO:
* check on many devices
* implement gamma handling (VAA isn't obsoleted?)
BUGS:
* palettized playback has bad colors, probably swapped palette?
* fbdev & DR produces two downscaled images
* fbdev & FLIP (& DR) produces no image
Thanks to Andreas Beck for his patches.
Many thanks to Atmosfear, he hacked this driver to work with Planar
formats, and he fixed the RGB handling.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "mp_msg.h"
#include "config.h"
#include "video_out.h"
#include "video_out_internal.h"
#include "fastmemcpy.h"
#include <ggi/ggi.h>
/* maximum buffers */
#undef GGI_FLIP
static vo_info_t info =
{
"General Graphics Interface (GGI) output",
"ggi",
"Alex Beregszaszi",
"major"
};
LIBVO_EXTERN (ggi)
static struct ggi_conf_s {
char *driver;
ggi_visual_t parentvis;
ggi_visual_t vis;
ggi_mode gmode;
/* source image format */
int srcwidth;
int srcheight;
int srcformat;
int srcdepth;
int srcbpp;
/* dirty region */
struct {
int x1, y1;
int x2, y2;
} flushregion;
/* destination */
int dstwidth;
int dstheight;
int async;
int voflags;
} ggi_conf;
static void set_graphtype(uint32_t format, ggi_mode *mode)
{
switch(format)
{
case IMGFMT_RGB4:
mode->graphtype = GT_4BIT;
break;
case IMGFMT_BGR4:
mode->graphtype = GT_4BIT;
GT_SETSUBSCHEME(mode->graphtype, GT_SUB_HIGHBIT_RIGHT);
break;
case IMGFMT_RGB8:
case IMGFMT_BGR8:
mode->graphtype = GT_8BIT;
break;
case IMGFMT_RGB15:
case IMGFMT_BGR15:
mode->graphtype = GT_15BIT;
break;
case IMGFMT_RGB16:
case IMGFMT_BGR16:
mode->graphtype = GT_16BIT;
break;
case IMGFMT_RGB24:
case IMGFMT_BGR24:
mode->graphtype = GT_24BIT;
break;
case IMGFMT_RGB32:
case IMGFMT_BGR32:
mode->graphtype = GT_32BIT;
break;
}
return;
}
static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,
uint32_t d_height, uint32_t flags, char *title, uint32_t format)
{
int i;
int rc;
ggi_mode mode = {
1, /* frames */
{ 0, 0 }, /* top, left corner */
{ width, height }, /* bottem, right corner */
{ GGI_AUTO, GGI_AUTO }, /* size */
GT_AUTO, /* graphtype */
{ GGI_AUTO, GGI_AUTO } /* dots per pixel */
};
ggi_mode parentmode =
{
1, /* frames */
{ width, height }, /* visible */
{ GGI_AUTO, GGI_AUTO }, /* virt */
{ GGI_AUTO, GGI_AUTO }, /* size */
GT_AUTO, /* graphtype */
{ GGI_AUTO, GGI_AUTO } /* dots per pixel */
};
set_graphtype(format, &parentmode);
#if 0
printf("[ggi] mode: ");
ggiPrintMode(&parentmode);
printf("\n");
#endif
ggiCheckMode(ggi_conf.parentvis, &parentmode);
if (ggiSetMode(ggi_conf.parentvis, &parentmode) < 0)
{
mp_msg(MSGT_VO, MSGL_ERR, "[ggi] unable to set display mode\n");
return(-1);
}
if (ggiGetMode(ggi_conf.parentvis, &parentmode) < 0)
{
mp_msg(MSGT_VO, MSGL_ERR, "[ggi] unable to get display mode\n");
return(-1);
}
if ((parentmode.graphtype == GT_INVALID) || (parentmode.graphtype == GT_AUTO))
{
mp_msg(MSGT_VO, MSGL_ERR, "[ggi] not supported depth/bpp\n");
return(-1);
}
/* calculate top, left corner */
mode.visible.x = (parentmode.virt.x - width) / 2;
mode.visible.y = (parentmode.virt.y - height) / 2;
/* calculate bottom, right corner */
mode.virt.x = mode.visible.x + width;
mode.virt.y = mode.visible.y + height;
ggiCheckMode(ggi_conf.vis, &mode);
if (ggiSetMode(ggi_conf.vis, &mode) < 0)
{
mp_msg(MSGT_VO, MSGL_ERR, "[ggi] unable to set video mode\n");
return(-1);
}
if (ggiGetMode(ggi_conf.vis, &mode) < 0)
{
mp_msg(MSGT_VO, MSGL_ERR, "[ggi] unable to get video mode\n");
return(-1);
}
ggi_conf.gmode = mode;
#if 0
printf("[ggi] mode: ");
ggiPrintMode(&mode);
printf("\n");
#endif
vo_depthonscreen = GT_DEPTH(parentmode.graphtype);
vo_screenwidth = parentmode.visible.x;
vo_screenheight = parentmode.visible.y;
vo_dx = vo_dy = 0;
vo_dwidth = mode.virt.x;
vo_dheight = mode.virt.y;
vo_dbpp = GT_SIZE(parentmode.graphtype);
ggi_conf.srcwidth = width;
ggi_conf.srcheight = height;
ggi_conf.srcformat = format;
ggi_conf.voflags = flags;
if (IMGFMT_IS_RGB(ggi_conf.srcformat))
{
ggi_conf.srcdepth = IMGFMT_RGB_DEPTH(ggi_conf.srcformat);
}
else
if (IMGFMT_IS_BGR(ggi_conf.srcformat))
{
ggi_conf.srcdepth = IMGFMT_BGR_DEPTH(ggi_conf.srcformat);
}
else
{
mp_msg(MSGT_VO, MSGL_FATAL, "[ggi] Unknown image format: %s\n",
vo_format_name(ggi_conf.srcformat));
return(-1);
}
vo_dwidth = ggi_conf.dstwidth = ggi_conf.gmode.virt.x;
vo_dheight = ggi_conf.dstheight = ggi_conf.gmode.virt.y;
ggiSetFlags(ggi_conf.vis, GGIFLAG_ASYNC);
if (GT_SCHEME(mode.graphtype) == GT_PALETTE)
ggiSetColorfulPalette(ggi_conf.vis);
if (ggiGetFlags(ggi_conf.vis) & GGIFLAG_ASYNC)
ggi_conf.async = 1;
mp_msg(MSGT_VO, MSGL_INFO, "[ggi] input: %dx%dx%d, output: %dx%dx%d\n",
ggi_conf.srcwidth, ggi_conf.srcheight, ggi_conf.srcdepth,
vo_dwidth, vo_dheight, vo_dbpp);
mp_msg(MSGT_VO, MSGL_INFO, "[ggi] async mode: %s\n",
ggi_conf.async ? "yes" : "no");
ggi_conf.srcbpp = (ggi_conf.srcdepth+7)/8;
ggi_conf.flushregion.x1 = ggi_conf.flushregion.y1 = 0;
ggi_conf.flushregion.x2 = ggi_conf.dstwidth;
ggi_conf.flushregion.y2 = ggi_conf.dstheight;
return(0);
}
static uint32_t get_image(mp_image_t *mpi)
{
/* GGI DirectRendering supports (yet) only BGR/RGB modes */
if (
#if 1
(IMGFMT_IS_RGB(mpi->imgfmt) &&
(IMGFMT_RGB_DEPTH(mpi->imgfmt) != vo_dbpp)) ||
(IMGFMT_IS_BGR(mpi->imgfmt) &&
(IMGFMT_BGR_DEPTH(mpi->imgfmt) != vo_dbpp)) ||
#else
(mpi->imgfmt != ggi_conf.srcformat) ||
#endif
((mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) ||
(mpi->flags & MP_IMGFLAG_PLANAR) ||
(mpi->flags & MP_IMGFLAG_YUV) ||
(mpi->width != ggi_conf.srcwidth) ||
(mpi->height != ggi_conf.srcheight)
)
{
return(VO_FALSE);
}
mpi->planes[1] = mpi->planes[2] = NULL;
mpi->stride[1] = mpi->stride[2] = 0;
mpi->planes[0] = NULL;
mpi->stride[0] = ggi_conf.srcwidth * ggi_conf.srcbpp;
mpi->flags |= MP_IMGFLAG_DIRECT;
#ifdef GGI_FLIP
if (ggi_conf.voflags & VOFLAG_FLIPPING)
{
mpi->stride[0] = -mpi->stride[0];
}
#endif
return(VO_TRUE);
}
static uint32_t draw_frame(uint8_t *src[])
{
ggiPutBox(ggi_conf.vis, 0, 0, ggi_conf.dstwidth, ggi_conf.dstheight, src[0]);
ggi_conf.flushregion.x1 = ggi_conf.flushregion.y1 = 0;
ggi_conf.flushregion.x2 = ggi_conf.dstwidth;
ggi_conf.flushregion.y2 = ggi_conf.dstheight;
return(0);
}
static void draw_osd(void)
{
return;
}
static void flip_page(void)
{
ggiFlushRegion(ggi_conf.vis, ggi_conf.flushregion.x1, ggi_conf.flushregion.y1,
ggi_conf.flushregion.x2 - ggi_conf.flushregion.x1,
ggi_conf.flushregion.y2 - ggi_conf.flushregion.y1);
ggi_conf.flushregion.x1 = ggi_conf.flushregion.x2 = ggi_conf.dstwidth / 2;
ggi_conf.flushregion.y1 = ggi_conf.flushregion.y2 = ggi_conf.dstheight / 2;
}
static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h,
int x, int y)
{
ggiPutBox(ggi_conf.vis, x, y, w, h, src[0]);
if (x < ggi_conf.flushregion.x1)
ggi_conf.flushregion.x1 = x;
if (y < ggi_conf.flushregion.y1)
ggi_conf.flushregion.y1 = y;
if ((x + w) > ggi_conf.flushregion.x2)
ggi_conf.flushregion.x2 = x + w;
if ((y + h) > ggi_conf.flushregion.y2)
ggi_conf.flushregion.y2 = y + h;
return(1);
}
static uint32_t query_format(uint32_t format)
{
ggi_mode mode;
uint32_t vfcap;
vfcap = VFCAP_CSP_SUPPORTED | VFCAP_CSP_SUPPORTED_BY_HW | VFCAP_ACCEPT_STRIDE;
if ((!vo_depthonscreen || !vo_dbpp) && ggi_conf.parentvis)
{
if (ggiGetMode(ggi_conf.parentvis, &mode) == 0)
{
vo_depthonscreen = GT_DEPTH(mode.graphtype);
vo_dbpp = GT_SIZE(mode.graphtype);
}
}
if ((IMGFMT_IS_BGR(format) && (IMGFMT_BGR_DEPTH(format) == vo_dbpp)) ||
(IMGFMT_IS_RGB(format) && (IMGFMT_RGB_DEPTH(format) == vo_dbpp)))
{
return vfcap;
}
if (IMGFMT_IS_BGR(format) || IMGFMT_IS_RGB(format))
{
set_graphtype(format, &mode);
if (ggiCheckMode(ggi_conf.parentvis, &mode) < 0) {
return 0;
} else {
return vfcap;
}
}
return(0);
}
static uint32_t preinit(const char *arg)
{
if (ggiInit() != 0)
{
mp_msg(MSGT_VO, MSGL_FATAL, "[ggi] unable to initialize GGI\n");
return(-1);
}
if ((char *)arg)
ggi_conf.driver = strdup(arg);
else
ggi_conf.driver = NULL;
ggi_conf.parentvis = ggiOpen(ggi_conf.driver);
if (ggi_conf.parentvis == NULL)
{
mp_msg(MSGT_VO, MSGL_FATAL, "[ggi] unable to open '%s' output\n",
(ggi_conf.driver == NULL) ? "default" : ggi_conf.driver);
ggiExit();
return(-1);
}
ggi_conf.vis = ggiOpen("display-sub", ggi_conf.parentvis);
if (ggi_conf.vis == NULL)
{
mp_msg(MSGT_VO, MSGL_FATAL, "[ggi] unable to open the video output\n");
ggiExit();
return(-1);
}
mp_msg(MSGT_VO, MSGL_V, "[ggi] using '%s' output\n",
(ggi_conf.driver == NULL) ? "default" : ggi_conf.driver);
return 0;
}
static void uninit(void)
{
if (ggi_conf.driver)
free(ggi_conf.driver);
ggiClose(ggi_conf.vis);
ggiClose(ggi_conf.parentvis);
ggiExit();
}
static uint32_t control(uint32_t request, void *data, ...)
{
switch(request)
{
case VOCTRL_QUERY_FORMAT:
return query_format(*((uint32_t*)data));
case VOCTRL_GET_IMAGE:
return get_image(data);
}
return VO_NOTIMPL;
}
/* EVENT handling */
#include "osdep/keycodes.h"
extern void mplayer_put_key(int code);
static void check_events(void)
{
struct timeval tv = {0, 0};
ggi_event event;
ggi_event_mask mask;
if ((mask = ggiEventPoll(ggi_conf.parentvis, emAll, &tv)))
if (ggiEventRead(ggi_conf.parentvis, &event, emAll) != 0)
{
mp_dbg(MSGT_VO, MSGL_DBG3, "type: %4x, origin: %4x, sym: %4x, label: %4x, button=%4x\n",
event.any.origin, event.any.type, event.key.sym, event.key.label, event.key.button);
switch (event.any.type) {
case evKeyPress:
switch(event.key.sym)
{
case GIIK_PAsterisk: /* PStar */
case GIIUC_Asterisk:
mplayer_put_key('*');
break;
case GIIK_PSlash:
case GIIUC_Slash:
mplayer_put_key('/');
break;
case GIIK_PPlus:
case GIIUC_Plus:
mplayer_put_key('+');
break;
case GIIK_PMinus:
case GIIUC_Minus:
mplayer_put_key('-');
break;
case GIIUC_o:
case GIIUC_O:
mplayer_put_key('o');
break;
case GIIUC_g:
case GIIUC_G:
mplayer_put_key('g');
break;
case GIIUC_z:
case GIIUC_Z:
mplayer_put_key('z');
break;
case GIIUC_x:
case GIIUC_X:
mplayer_put_key('x');
break;
case GIIUC_m:
case GIIUC_M:
mplayer_put_key('m');
break;
case GIIUC_d:
case GIIUC_D:
mplayer_put_key('d');
break;
case GIIUC_q:
case GIIUC_Q:
mplayer_put_key('q');
break;
case GIIUC_h:
case GIIUC_H:
mplayer_put_key('h');
break;
case GIIUC_l:
case GIIUC_L:
mplayer_put_key('l');
break;
case GIIUC_Space:
case GIIUC_p:
case GIIUC_P:
mplayer_put_key('p');
break;
case GIIK_Up:
mplayer_put_key(KEY_UP);
break;
case GIIK_Down:
mplayer_put_key(KEY_DOWN);
break;
case GIIK_Left:
mplayer_put_key(KEY_LEFT);
break;
case GIIK_Right:
mplayer_put_key(KEY_RIGHT);
break;
case GIIK_PageUp:
mplayer_put_key(KEY_PAGE_UP);
break;
case GIIK_PageDown:
mplayer_put_key(KEY_PAGE_DOWN);
break;
default:
break;
} /* switch */
break;
} /* switch */
} /* if */
return;
}
|