285
|
1 /*
|
|
2 Video driver for SVGAlib - alpha version
|
|
3 by Zoltan Mark Vician <se7en@sch.bme.hu>
|
|
4 Code started: Mon Apr 1 23:25:47 2000
|
|
5 */
|
|
6
|
|
7 #include <stdio.h>
|
|
8 #include <stdlib.h>
|
|
9
|
|
10 #include <vga.h>
|
|
11 #include <vgagl.h>
|
|
12
|
|
13 #include "config.h"
|
|
14 #include "video_out.h"
|
|
15 #include "video_out_internal.h"
|
|
16
|
|
17 #include "yuv2rgb.h"
|
|
18
|
|
19 LIBVO_EXTERN(svga)
|
|
20
|
|
21 static vo_info_t vo_info = {
|
|
22 "SVGAlib",
|
|
23 "svga",
|
|
24 "Zoltan Mark Vician <se7en@sch.bme.hu>",
|
|
25 ""
|
|
26 };
|
|
27
|
|
28 // SVGAlib definitions
|
|
29
|
|
30 GraphicsContext *screen;
|
|
31 GraphicsContext *virt;
|
|
32
|
|
33 static uint8_t *scalebuf = NULL, *yuvbuf = NULL;
|
|
34
|
|
35 static uint32_t orig_w, orig_h, maxw, maxh; // Width, height
|
|
36 static float scaling = 0;
|
|
37 static uint32_t x_pos, y_pos; // Position
|
|
38
|
|
39 // Order must not change!
|
|
40 #define _640x480x32K 0 // 17
|
|
41 #define _640x480x64K 1 // 18
|
|
42 #define _640x480x16M 2 // 19
|
|
43 #define _640x480x16M32 3 // 34
|
|
44 #define _800x600x32K 4 // 20
|
|
45 #define _800x600x64K 5 // 21
|
|
46 #define _800x600x16M 6 // 22
|
|
47 #define _800x600x16M32 7 // 35
|
|
48 #define _1024x768x32K 8 // 23
|
|
49 #define _1024x768x64K 9 // 24
|
|
50 #define _1024x768x16M 10 // 25
|
|
51 #define _1024x768x16M32 11 // 36
|
|
52 #define VID_MODE_NUM 12
|
|
53
|
|
54 static uint8_t vid_modes[VID_MODE_NUM];
|
|
55 static uint8_t vid_mode;
|
|
56
|
|
57 static uint32_t pformat;
|
|
58
|
|
59 static uint8_t checked = 0;
|
|
60
|
286
|
61 static void checksupportedmodes() {
|
285
|
62 int i;
|
|
63
|
|
64 checked = 1;
|
|
65 vga_init();
|
|
66 vga_disabledriverreport();
|
|
67 for (i = 0; i < VID_MODE_NUM; i++) {
|
|
68 if (vga_hasmode(i) > 0)
|
|
69 vid_modes[i] = 1;
|
|
70 else vid_modes[i] = 0;
|
|
71 }
|
|
72 }
|
|
73
|
|
74 static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width,
|
|
75 uint32_t d_height, uint32_t fullscreen, char *title,
|
|
76 uint32_t format) {
|
288
|
77 static uint8_t bpp;
|
285
|
78 if (!checked) {
|
|
79 checksupportedmodes(); // Looking for available video modes
|
|
80 }
|
|
81 pformat = format;
|
288
|
82 if(format==IMGFMT_YV12) bpp=32; else bpp=format&255;
|
285
|
83 if (d_width > 800)
|
|
84 switch (bpp) {
|
|
85 case 32: vid_mode = 36; break;
|
|
86 case 24: vid_mode = 25; break;
|
|
87 case 16: vid_mode = 24; break;
|
|
88 case 15: vid_mode = 23; break;
|
|
89 }
|
|
90 else
|
|
91 if (d_width > 640)
|
|
92 switch (bpp) {
|
|
93 case 32: vid_mode = 35; break;
|
|
94 case 24: vid_mode = 22; break;
|
|
95 case 16: vid_mode = 21; break;
|
|
96 case 15: vid_mode = 20; break;
|
|
97 }
|
|
98 else
|
|
99 switch (bpp) {
|
|
100 case 32: vid_mode = 34; break;
|
|
101 case 24: vid_mode = 19; break;
|
|
102 case 16: vid_mode = 18; break;
|
|
103 case 15: vid_mode = 17; break;
|
|
104 }
|
286
|
105 if (vga_setmode(vid_mode) == -1){
|
|
106 printf("vo_svga: vga_setmode(%d) failed.\n",vid_mode);
|
285
|
107 return(1); // error
|
286
|
108 }
|
|
109 if (gl_setcontextvga(vid_mode)){
|
|
110 printf("vo_svga: gl_setcontextvga(%d) failed.\n",vid_mode);
|
285
|
111 return(1); // error
|
286
|
112 }
|
285
|
113 screen = gl_allocatecontext();
|
|
114 gl_getcontext(screen);
|
286
|
115 if (gl_setcontextvgavirtual(vid_mode)){
|
|
116 printf("vo_svga: gl_setcontextvgavirtual(%d) failed.\n",vid_mode);
|
285
|
117 return(1); // error
|
286
|
118 }
|
285
|
119 virt = gl_allocatecontext();
|
|
120 gl_getcontext(virt);
|
|
121 gl_setcontext(virt);
|
|
122 gl_clearscreen(0);
|
|
123
|
|
124 orig_w = width;
|
|
125 orig_h = height;
|
|
126 if (fullscreen && (WIDTH != orig_w)) {
|
|
127 maxw = WIDTH;
|
|
128 scaling = maxw / (orig_w*1.0);
|
|
129 maxh = (uint32_t) (orig_h * scaling);
|
|
130 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL);
|
|
131 } else {
|
|
132 maxw = orig_w;
|
|
133 maxh = orig_h;
|
|
134 }
|
|
135
|
|
136 x_pos = (WIDTH - maxw) / 2;
|
|
137 y_pos = (HEIGHT - maxh) / 2;
|
|
138
|
|
139 if (pformat == IMGFMT_YV12) {
|
|
140 yuv2rgb_init(bpp, MODE_RGB);
|
|
141 yuvbuf = malloc(maxw * maxh * BYTESPERPIXEL);
|
|
142 }
|
|
143
|
|
144 printf("SVGAlib resolution: %dx%d %dbpp - ",WIDTH,HEIGHT,bpp);
|
|
145 if (maxw != orig_w || maxh != orig_h) printf("Video scaled to: %dx%d\n",maxw,maxh);
|
|
146 else printf("No video scaling\n");
|
|
147
|
|
148 return (0);
|
|
149 }
|
|
150
|
|
151 static uint32_t query_format(uint32_t format) {
|
|
152 if (!checked)
|
|
153 checksupportedmodes(); // Looking for available video modes
|
|
154 switch (format) {
|
|
155 case IMGFMT_RGB32:
|
|
156 case IMGFMT_BGR|32: {
|
|
157 return (vid_modes[_640x480x16M32] | vid_modes[_800x600x16M32] | vid_modes[_1024x768x16M32]);
|
|
158 }
|
|
159 case IMGFMT_RGB24:
|
|
160 case IMGFMT_BGR|24: {
|
|
161 return (vid_modes[_640x480x16M] | vid_modes[_800x600x16M] | vid_modes[_1024x768x16M]);
|
|
162 }
|
|
163 case IMGFMT_RGB16:
|
|
164 case IMGFMT_BGR|16: {
|
|
165 return (vid_modes[_640x480x64K] | vid_modes[_800x600x64K] | vid_modes[_1024x768x64K]);
|
|
166 }
|
|
167 case IMGFMT_RGB15:
|
|
168 case IMGFMT_BGR|15: {
|
|
169 return (vid_modes[_640x480x32K] | vid_modes[_800x600x32K] | vid_modes[_1024x768x32K]);
|
|
170 }
|
|
171 case IMGFMT_YV12: return (1);
|
|
172 }
|
|
173 return (0);
|
|
174 }
|
|
175
|
|
176 static const vo_info_t* get_info(void) {
|
|
177 return (&vo_info);
|
|
178 }
|
|
179
|
|
180 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
|
|
181 unsigned char *srca, int stride) {
|
|
182 int x, y, i;
|
|
183 uint8_t *dest, buf;
|
|
184
|
|
185 // if (pformat == IMGFMT_YV12) {
|
|
186 for (y = 0; y < h; y++) {
|
|
187 dest = virt->vbuf + ((WIDTH * (y0 + y) + x0) * BYTESPERPIXEL);
|
|
188 for (x = 0; x < w; x++) {
|
|
189 if (srca[x]) {
|
|
190 for (i = 0; i < BYTESPERPIXEL; i++)
|
|
191 dest[i] = /*((dest[i] * srca[x]) >> 8) +*/ src[x] >> 6;
|
|
192 }
|
|
193 dest += BYTESPERPIXEL;
|
|
194 }
|
|
195 src += stride;
|
|
196 srca += stride;
|
|
197 }
|
|
198 // }
|
|
199 }
|
|
200
|
|
201 static uint32_t draw_frame(uint8_t *src[]) {
|
|
202 if (pformat == IMGFMT_YV12) {
|
|
203 yuv2rgb(yuvbuf, src[0], src[1], src[2], orig_w, orig_h, orig_w * BYTESPERPIXEL, orig_w, orig_w / 2);
|
|
204 src[0] = yuvbuf;
|
|
205 }
|
|
206 if (scalebuf) {
|
|
207 gl_scalebox(orig_w, orig_h, src[0], maxw, maxh, scalebuf);
|
|
208 src[0] = scalebuf;
|
|
209 }
|
|
210 gl_putbox(x_pos, y_pos, maxw, maxh, src[0]);
|
|
211 }
|
|
212
|
|
213 static uint32_t draw_slice(uint8_t *image[], int stride[],
|
|
214 int w, int h, int x, int y) {
|
|
215 uint8_t *src = yuvbuf;
|
|
216
|
|
217 yuv2rgb(yuvbuf, image[0], image[1], image[2], w, h, orig_w * BYTESPERPIXEL, stride[0], stride[1]);
|
|
218 if (scalebuf) {
|
|
219 gl_scalebox(w, h, yuvbuf,(int) (w * scaling), (int) (h * scaling), scalebuf);
|
|
220 src = scalebuf;
|
|
221 }
|
|
222 gl_putbox(x + x_pos, y + y_pos, (int) (w * scaling), (int) (h * scaling), src);
|
|
223 }
|
|
224
|
|
225
|
|
226 static void flip_page(void) {
|
|
227 gl_fillbox(0, 0, WIDTH, y_pos, 0);
|
|
228 gl_fillbox(0, HEIGHT - y_pos, WIDTH, y_pos, 0);
|
|
229 vo_draw_text(WIDTH, HEIGHT, draw_alpha);
|
|
230 gl_copyscreen(screen);
|
|
231 }
|
|
232
|
|
233 static void check_events(void) {
|
|
234 }
|
|
235
|
|
236 static void uninit(void) {
|
|
237 gl_freecontext(screen);
|
|
238 gl_freecontext(virt);
|
|
239 vga_setmode(TEXT);
|
|
240 if (scalebuf)
|
|
241 free(scalebuf);
|
|
242 if (yuvbuf)
|
|
243 free(yuvbuf);
|
|
244 }
|
|
245 |