summaryrefslogtreecommitdiffstats
path: root/libvo/vo_ggi.c
blob: f1489955e717812ea50bc4436723ace2e57637ef (plain)
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
/* 
  vo_ggi.c - General Graphics Interface (GGI) Renderer for MPlayer

  (C) Alex Beregszaszi <alex@naxine.org>
  
  Uses libGGI - http://www.ggi-project.org/
*/

#define DISP

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>

#include "config.h"
#include "video_out.h"
#include "video_out_internal.h"

#include "yuv2rgb.h"

#include <ggi/ggi.h>
#include "fastmemcpy.h"

LIBVO_EXTERN (ggi)

static vo_info_t vo_info = 
{
	"General Graphics Interface (GGI) output",
	"ggi",
	"Alex Beregszaszi <alex@naxine.org>",
	""
};

extern int verbose;

static char *ggi_output_name = NULL;
static ggi_visual_t ggi_vis;
static ggi_directbuffer *ggi_buffer;
static int bpp = 0;
static uint32_t virt_width;
static uint32_t virt_height;
static ggi_pixel white;
static ggi_pixel black;

static int ggi_setmode(uint32_t d_width, uint32_t d_height, int d_depth, int format)
{
    ggi_mode mode =
    {
	1,			/* frames */
	{ GGI_AUTO, GGI_AUTO },	/* visible */
	{ GGI_AUTO, GGI_AUTO },	/* virt */
	{ GGI_AUTO, GGI_AUTO },	/* size */
	GT_AUTO,		/* graphtype */
	{ GGI_AUTO, GGI_AUTO }	/* dots per pixel */
    };
    ggi_color pal[256];
    int depth;

    mode.visible.x = mode.virt.x = d_width;
    mode.visible.y = mode.virt.y = d_height;
    
    switch(d_depth)
    {
	case 1:
	    mode.graphtype = GT_1BIT;
	    depth = 1;
	    break;
	case 2:
	    mode.graphtype = GT_2BIT;
	    depth = 2;
	    break;
	case 4:
	    mode.graphtype = GT_4BIT;
	    depth = 4;
	    break;
	case 8:
	    mode.graphtype = GT_8BIT;
	    depth = 8;
	    break;
	case 15:
	    mode.graphtype = GT_15BIT;
	    depth = 15;
	    break;
	case 16:
	    mode.graphtype = GT_16BIT;
	    depth = 16;
	    break;
	case 24:
	    mode.graphtype = GT_24BIT;
	    depth = 24;
	    break;
	case 32:
	    mode.graphtype = GT_32BIT;
	    depth = 32;
	    break;
	default:
	    printf("ggi-setmode: unknown bit depth - using auto\n");
	    mode.graphtype = GT_AUTO;
    }
    
    ggiCheckMode(ggi_vis, &mode);
    
    if (ggiSetMode(ggi_vis, &mode) != 0)
    {
	printf("ggi-setmode: unable to set mode\n");
	ggiClose(ggi_vis);
	ggiExit();
	return(-1);
    }
    
    virt_width = mode.virt.x;
    virt_height = mode.virt.y;
    vo_screenwidth = mode.visible.x;
    vo_screenheight = mode.visible.y;
    vo_depthonscreen = depth;
    bpp = depth; /* byte per pixel = depth ? */


#ifdef get_db_info
    {
	const ggi_directbuffer *db = ggiDBGetBuffer(ggi_vis, 0);
	
	if (db)
	{
	    vo_depthonscreen = db->buffer.plb.pixelformat->depth;
	    bpp = db->buffer.plb.pixelformat->size / 8;
	}
    }
#endif

    if (GT_SCHEME(mode.graphtype) == GT_PALETTE)
    {
	ggiSetColorfulPalette(ggi_vis);
	ggiGetPalette(ggi_vis, 0, 1 << bpp, pal);
    }

    if (verbose)
	printf("ggi-setmode: %dx%d (virt: %dx%d) %d depth, %d bpp\n", vo_screenwidth,
	    vo_screenheight, virt_width, virt_height, vo_depthonscreen, bpp);

    return(0);
}


static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width,
    uint32_t d_height, uint32_t fullscreen, char *title, uint32_t format)
{
    printf("\nggi: THIS DRIVER IS IN PRE-ALPHA PHASE, DO NOT USE!\n\n");
    if (ggiInit() != 0)
    {
	printf("ggi-init: unable to initialize GGI\n");
	return(-1);
    }
    
    if ((ggi_vis = ggiOpen(ggi_output_name)) == NULL)
    {
	printf("ggi-init: unable to open GGI for %s output\n",
	    (ggi_output_name == NULL) ? "default" : ggi_output_name);
	ggiExit();
	return(-1);
    }

    switch(format)
    {
	case IMGFMT_RGB8:
	    bpp = 8;
	    break;
	case IMGFMT_RGB15:
	    bpp = 15;
	    break;
	case IMGFMT_RGB16:
	    bpp = 16;
	    break;
	case IMGFMT_RGB24:
	    bpp = 24;
	    break;
	case IMGFMT_RGB32:
	    bpp = 32;
	    break;
	case IMGFMT_BGR8:
	    bpp = 8;
	    break;
	case IMGFMT_BGR15:
	    bpp = 15;
	    break;
	case IMGFMT_BGR16:
	    bpp = 16;
	    break;
	case IMGFMT_BGR24:
	    bpp = 24;
	    break;
	case IMGFMT_BGR32:
	    bpp = 32;
	    break;
	case IMGFMT_YV12: /* rgb, 24bit */
	    bpp = 16;
	    yuv2rgb_init(32/*screendepth*/, MODE_RGB);
	    break;
	default:
	    printf("ggi-init: no suitable image format found\n");
	    return(-1);
    }

    ggiSetFlags(ggi_vis, GGIFLAG_ASYNC);

    if (ggi_setmode(d_width, d_height, 32/*bpp*/, format) != 0)
    {
	printf("ggi-init: setmode returned with error\n");
	return(-1);
    }    

    ggi_buffer = (ggi_directbuffer *)ggiDBGetBuffer(ggi_vis, 0);

    if (ggi_buffer == NULL)
    {
	printf("ggi-init: double buffering is not available\n");
	ggiClose(ggi_vis);
	ggiExit();
	return(-1);
    }
	
    if (!(ggi_buffer->type & GGI_DB_SIMPLE_PLB) ||
	(ggi_buffer->page_size != 0) ||
	(ggi_buffer->write == NULL) ||
	(ggi_buffer->noaccess != 0) ||
	(ggi_buffer->align != 0))
    {
	printf("ggi-init: incorrect video memory type\n");
	ggiClose(ggi_vis);
	ggiExit();
	return(-1);
    }

    /* just for fun */
    {
	ggi_color col;

	/* set black */
	col.r = col.g = col.b = 0x0000;
	black = ggiMapColor(ggi_vis, &col);

	/* set white */
	col.r = col.g = col.b = 0xffff;
	white = ggiMapColor(ggi_vis, &col);

	ggiSetGCForeground(ggi_vis, white);
	ggiSetGCBackground(ggi_vis, black);
    }

    return(0);
}

static const vo_info_t* get_info(void)
{
    return &vo_info;
}

static uint32_t draw_frame(uint8_t *src[])
{
    uint8_t *ptr;
    int y, x, i;
    /*int bppmul = vo_depthonscreen/8;*/

    ggiResourceAcquire(ggi_buffer->resource, GGI_ACTYPE_WRITE);
    ggiSetDisplayFrame(ggi_vis, ggi_buffer->frame);
    ggiSetWriteFrame(ggi_vis, ggi_buffer->frame);
    
    ptr = ggi_buffer->write;
    
//    for (i = 1; i < 3; i++)
/*	for (x = 0; x < virt_width; x++)
	    for (y = 0; y < virt_height; y++)
		*ptr++ = src[0][x*virt_height+y];*/
    memcpy(ptr,src[0],virt_width*virt_height*(bpp/8));

    ggiPuts(ggi_vis, x/2, y-10, "MPlayer GGI");
    
    ggiResourceRelease(ggi_buffer->resource);
}

static void flip_page(void)
{
    check_events();
    ggiFlush(ggi_vis);
}

static uint32_t draw_slice(uint8_t *src[], int stride[], int w, int h,
    int x, int y)
{
    uint8_t *dst;

    dst = ggi_buffer->write + (virt_width * y + x) * (bpp/8);
    yuv2rgb(dst, src[0], src[1], src[2], w, h, virt_width*(bpp/8),
	stride[0], stride[1]);
    //draw_frame(dst);

//    dst = image_data + (virt_width * y + x) * (bpp/8);
//    yuv2rgb(dst, src[0], src[1], src[2], w, h, virt_width*(bpp/8),
//	stride[0], stride[1]);
    return(0);
}

static uint32_t query_format(uint32_t format)
{
    switch(format){
    case IMGFMT_YV12:
	return 1;
    case IMGFMT_RGB8:
    case IMGFMT_RGB15:
    case IMGFMT_RGB16:
    case IMGFMT_RGB24:
    case IMGFMT_RGB32:
    case IMGFMT_BGR8:
    case IMGFMT_BGR15:
    case IMGFMT_BGR16:
    case IMGFMT_BGR24:
    case IMGFMT_BGR32:
        return 1;
    }
    return 0;
}

static void uninit(void)
{
    ggiResourceRelease(ggi_buffer->resource);
    ggiClose(ggi_vis);
    ggiExit();
}

static void check_events(void)
{
/* add ggiPollEvent stuff */
}