comparison libvo/vo_svga.c @ 483:92f170c8b9ba

fix to newest revision after cvs rollback
author atmosfear
date Tue, 17 Apr 2001 06:22:48 +0000
parents 198b46b739d8
children dfafa47d751d
comparison
equal deleted inserted replaced
482:1a2c4f3e7a10 483:92f170c8b9ba
39 39
40 static uint32_t orig_w, orig_h, maxw, maxh; // Width, height 40 static uint32_t orig_w, orig_h, maxw, maxh; // Width, height
41 static float scaling = 1.0; 41 static float scaling = 1.0;
42 static uint32_t x_pos, y_pos; // Position 42 static uint32_t x_pos, y_pos; // Position
43 43
44 // Order must not change! 44 // SVGAlib - list of detected modes
45 #define _640x480x32K 0 // 17 45 typedef struct vga_modelist_s {
46 #define _640x480x64K 1 // 18 46 uint16_t modenum;
47 #define _640x480x16M 2 // 19 47 vga_modeinfo modeinfo;
48 #define _640x480x16M32 3 // 34 48 struct vga_modelist_s *next;
49 #define _800x600x32K 4 // 20 49 } vga_modelist_t;
50 #define _800x600x64K 5 // 21 50
51 #define _800x600x16M 6 // 22 51 vga_modelist_t *modelist = NULL;
52 #define _800x600x16M32 7 // 35 52
53 #define _1024x768x32K 8 // 23
54 #define _1024x768x64K 9 // 24
55 #define _1024x768x16M 10 // 25
56 #define _1024x768x16M32 11 // 36
57 #define VID_MODE_NUM 12
58
59 static uint8_t vid_modes[VID_MODE_NUM];
60 static vid_mode_nums[VID_MODE_NUM] = {17,18,19,34,20,21,22,35,23,24,25,36};
61 static uint8_t vid_mode;
62 static uint8_t bpp; 53 static uint8_t bpp;
63 54 static uint8_t bpp_conv = 0;
64 static uint32_t pformat; 55 static uint32_t pformat;
65 56
57 #define BPP_15 1
58 #define BPP_16 2
59 #define BPP_24 4
60 #define BPP_32 8
61 static uint8_t bpp_avail = 0;
62
66 static uint8_t checked = 0; 63 static uint8_t checked = 0;
67 static uint8_t bpp_conv = 0; 64
68 65 static int add_mode(uint16_t mode, vga_modeinfo minfo) {
69 static void checksupportedmodes() { 66 vga_modelist_t *list;
70 int i; 67
68 if (modelist == NULL) {
69 modelist = malloc(sizeof(vga_modelist_t));
70 modelist->modenum = mode;
71 modelist->modeinfo = minfo;
72 modelist->next = NULL;
73 if (modelist == NULL) {
74 printf("vo_svga: add_mode() failed. Not enough memory for modelist.");
75 return(1); // error
76 }
77 } else {
78 list = modelist;
79 while (list->next != NULL)
80 list = list->next;
81 list->next = malloc(sizeof(vga_modelist_t));
82 if (list->next == NULL) {
83 printf("vo_svga: add_mode() failed. Not enough memory for modelist.");
84 return(1); // error
85 }
86 list = list->next;
87 list->modenum = mode;
88 list->modeinfo = minfo;
89 list->next = NULL;
90 }
91 }
92
93 static int checksupportedmodes() {
94 uint16_t i;
95 vga_modeinfo *minfo;
71 96
72 checked = 1; 97 checked = 1;
73 vga_init(); 98 vga_init();
74 vga_disabledriverreport(); 99 vga_disabledriverreport();
75 for (i = 0; i < VID_MODE_NUM; i++) { 100 for (i = 1; i < vga_lastmodenumber(); i++)
76 if (vga_hasmode(vid_mode_nums[i]) > 0) 101 if (vga_hasmode(i) > 0) {
77 vid_modes[i] = 1; 102 minfo = vga_getmodeinfo(i);
78 else vid_modes[i] = 0; 103 switch (minfo->colors) {
79 } 104 case 32768: bpp_avail |= BPP_15; break;
105 case 65536: bpp_avail |= BPP_16; break;
106 }
107 switch (minfo->bytesperpixel) {
108 case 3: bpp_avail |= BPP_24; break;
109 case 4: bpp_avail |= BPP_32; break;
110 }
111 if (add_mode(i, *minfo))
112 return(1);
113 }
80 } 114 }
81 115
82 static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width, 116 static uint32_t init(uint32_t width, uint32_t height, uint32_t d_width,
83 uint32_t d_height, uint32_t fullscreen, char *title, 117 uint32_t d_height, uint32_t fullscreen, char *title,
84 uint32_t format) { 118 uint32_t format) {
85 uint32_t wid = (d_width > 0 ? d_width : width); 119 uint32_t req_w = (d_width > 0 ? d_width : width);
120 uint32_t req_h = (d_height > 0 ? d_height : height);
121 uint16_t vid_mode = 0;
122 uint8_t widescreen = (((req_w*1.0)/req_h) > (4.0/3)) ? 1 : 0;
123 vga_modelist_t *list = modelist;
86 124
87 if (!checked) { 125 if (!checked) {
88 checksupportedmodes(); // Looking for available video modes 126 if (checksupportedmodes()) // Looking for available video modes
89 } 127 return(1);
90 128 }
129
130 bpp_avail = 0;
131 while (list != NULL) {
132 if ((list->modeinfo.width >= req_w) && (list->modeinfo.height >= req_h)) {
133 switch (list->modeinfo.colors) {
134 case 32768: bpp_avail |= BPP_15; break;
135 case 65536: bpp_avail |= BPP_16; break;
136 }
137 switch (list->modeinfo.bytesperpixel) {
138 case 3: bpp_avail |= BPP_24; break;
139 case 4: bpp_avail |= BPP_32; break;
140 }
141 }
142 list = list->next;
143 }
144
91 pformat = format; 145 pformat = format;
92 146
93 // -bpp check 147 // bpp check
148 bpp_conv = 0;
94 if (!vo_dbpp) { 149 if (!vo_dbpp) {
95 if (format == IMGFMT_YV12) bpp = 32; 150 if (format == IMGFMT_YV12) bpp = 32;
96 else bpp = format & 255; 151 else bpp = format & 255;
152 switch (bpp) {
153 case 32: if (!(bpp_avail & BPP_32)) {
154 printf("vo_svga: Haven't found video mode which fit to: %dx%d %dbpp\n",req_w,req_h,bpp);
155 printf("vo_svga: Maybe you should try -bpp\n");
156 return(1);
157 }
158 break;
159 case 24: if (!(bpp_avail & BPP_24))
160 if (!(bpp_avail & BPP_32)) {
161 printf("vo_svga: Haven't found video mode which fit to: %dx%d %dbpp\n",req_w,req_h,bpp);
162 printf("vo_svga: Maybe you should try -bpp\n");
163 return(1);
164 } else {
165 bpp = 32;
166 bpp_conv = 1;
167 }
168 break;
169 case 16: if (!(bpp_avail & BPP_16)) {
170 printf("vo_svga: Haven't found video mode which fit to: %dx%d %dbpp\n",req_w,req_h,bpp);
171 printf("vo_svga: Maybe you should try -bpp\n");
172 return(1);
173 }
174 break;
175 case 15: if (!(bpp_avail & BPP_15))
176 if (!(bpp_avail & BPP_16)) {
177 printf("vo_svga: Haven't found video mode which fit to: %dx%d %dbpp\n",req_w,req_h,bpp);
178 printf("vo_svga: Maybe you should try -bpp\n");
179 return(1);
180 } else {
181 bpp = 16;
182 bpp_conv = 1;
183 }
184 break;
185 }
97 } else { 186 } else {
98 bpp = vo_dbpp; 187 bpp = vo_dbpp;
99 switch (bpp) { 188 switch (bpp) {
100 case 32: if (!(vid_modes[_640x480x16M32] | vid_modes[_800x600x16M32] | vid_modes[_1024x768x16M32])) { 189 case 32: if (!(bpp_avail & BPP_32)) {
101 printf("vo_svga: %dbpp not supported by HW or SVGAlib",bpp); 190 printf("vo_svga: %dbpp not supported by HW or SVGAlib\n",bpp);
102 return(1); 191 return(1);
103 } 192 }
104 case 24: if (!(vid_modes[_640x480x16M] | vid_modes[_800x600x16M] | vid_modes[_1024x768x16M])) { 193 case 24: if (!(bpp_avail & BPP_24)) {
105 printf("vo_svga: %dbpp not supported by HW or SVGAlib",bpp); 194 printf("vo_svga: %dbpp not supported by HW or SVGAlib\n",bpp);
106 return(1); 195 return(1);
107 } 196 }
108 case 16: if (!(vid_modes[_640x480x64K] | vid_modes[_800x600x64K] | vid_modes[_1024x768x64K])) { 197 case 16: if (!(bpp_avail & BPP_16)) {
109 printf("vo_svga: %dbpp not supported by HW or SVGAlib",bpp); 198 printf("vo_svga: %dbpp not supported by HW or SVGAlib\n",bpp);
110 return(1); 199 return(1);
111 } 200 }
112 case 15: if (!(vid_modes[_640x480x32K] | vid_modes[_800x600x32K] | vid_modes[_1024x768x32K])) { 201 case 15: if (!(bpp_avail & BPP_15)) {
113 printf("vo_svga: %dbpp not supported by HW or SVGAlib",bpp); 202 printf("vo_svga: %dbpp not supported by HW or SVGAlib\n",bpp);
114 return(1); 203 return(1);
115 } 204 }
116 } 205 }
117 } 206 }
118 207
119 if (wid > 800) 208 list = modelist;
120 switch (bpp) { 209 while ((list != NULL) && (!vid_mode)) {
121 case 32: vid_mode = 36; break; 210 if ((list->modeinfo.width >= req_w) && (list->modeinfo.height >= req_h)) {
122 case 24: vid_mode = bpp_conv ? 36 : 25; bpp = 32; break;
123 case 16: vid_mode = 24; break;
124 case 15: vid_mode = bpp_conv ? 24 : 23; bpp = 16; break;
125 }
126 else
127 if (wid > 640)
128 switch (bpp) { 211 switch (bpp) {
129 case 32: vid_mode = 35; break; 212 case 32: if (list->modeinfo.bytesperpixel == 4)
130 case 24: vid_mode = bpp_conv ? 35 : 22; bpp = 32; break; 213 vid_mode = list->modenum;
131 case 16: vid_mode = 21; break; 214 case 24: if (list->modeinfo.bytesperpixel == 3)
132 case 15: vid_mode = bpp_conv ? 21 : 20; bpp = 16; break; 215 vid_mode = list->modenum;
133 } 216 case 16: if (list->modeinfo.colors == 65536)
134 else 217 vid_mode = list->modenum;
135 switch (bpp) { 218 case 15: if (list->modeinfo.colors == 32768)
136 case 32: vid_mode = 34; break; 219 vid_mode = list->modenum;
137 case 24: vid_mode = bpp_conv ? 34 : 19; bpp = 32; break; 220 }
138 case 16: vid_mode = 18; break; 221 }
139 case 15: vid_mode = bpp_conv ? 18 : 17; bpp = 16; break; 222 list = list->next;
140 } 223 }
141 if (bpp_conv) 224
142 bppbuf = malloc(maxw * maxh * BYTESPERPIXEL);
143 if (!bppbuf) {
144 printf("vo_svga: Not enough memory for buffering!");
145 uninit();
146 return (1);
147 }
148
149 vga_setlinearaddressing(); 225 vga_setlinearaddressing();
150 if (vga_setmode(vid_mode) == -1){ 226 if (vga_setmode(vid_mode) == -1){
151 printf("vo_svga: vga_setmode(%d) failed.\n",vid_mode); 227 printf("vo_svga: vga_setmode(%d) failed.\n",vid_mode);
228 uninit();
152 return(1); // error 229 return(1); // error
153 } 230 }
154 if (gl_setcontextvga(vid_mode)){ 231 if (gl_setcontextvga(vid_mode)){
155 printf("vo_svga: gl_setcontextvga(%d) failed.\n",vid_mode); 232 printf("vo_svga: gl_setcontextvga(%d) failed.\n",vid_mode);
233 uninit();
156 return(1); // error 234 return(1); // error
157 } 235 }
158 screen = gl_allocatecontext(); 236 screen = gl_allocatecontext();
159 gl_getcontext(screen); 237 gl_getcontext(screen);
160 if (gl_setcontextvgavirtual(vid_mode)){ 238 if (gl_setcontextvgavirtual(vid_mode)){
161 printf("vo_svga: gl_setcontextvgavirtual(%d) failed.\n",vid_mode); 239 printf("vo_svga: gl_setcontextvgavirtual(%d) failed.\n",vid_mode);
240 uninit();
162 return(1); // error 241 return(1); // error
163 } 242 }
164 virt = gl_allocatecontext(); 243 virt = gl_allocatecontext();
165 gl_getcontext(virt); 244 gl_getcontext(virt);
166 gl_setcontext(virt); 245 gl_setcontext(virt);
167 gl_clearscreen(0); 246 gl_clearscreen(0);
168 247
248 if (bpp_conv)
249 bppbuf = malloc(maxw * maxh * BYTESPERPIXEL);
250 if (bppbuf == NULL) {
251 printf("vo_svga: Not enough memory for buffering!\n");
252 uninit();
253 return (1);
254 }
255
169 orig_w = width; 256 orig_w = width;
170 orig_h = height; 257 orig_h = height;
171 if ((fullscreen & 0x04) && (WIDTH != orig_w)) { 258 if ((fullscreen & 0x04) && (WIDTH != orig_w)) {
172 if (((orig_w*1.0) / orig_h) < (4.0/3)) { 259 if (!widescreen) {
173 maxh = HEIGHT; 260 maxh = HEIGHT;
174 scaling = maxh / (orig_h * 1.0); 261 scaling = maxh / (orig_h * 1.0);
175 maxw = (uint32_t) (orig_w * scaling); 262 maxw = (uint32_t) (orig_w * scaling);
176 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL); 263 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL);
177 if (!scalebuf) { 264 if (scalebuf == NULL) {
178 printf("vo_svga: Not enough memory for buffering!"); 265 printf("vo_svga: Not enough memory for buffering!\n");
179 uninit(); 266 uninit();
180 return (1); 267 return (1);
181 } 268 }
182 } else { 269 } else {
183 maxw = WIDTH; 270 maxw = WIDTH;
184 scaling = maxw / (orig_w * 1.0); 271 scaling = maxw / (orig_w * 1.0);
185 maxh = (uint32_t) (orig_h * scaling); 272 maxh = (uint32_t) (orig_h * scaling);
186 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL); 273 scalebuf = malloc(maxw * maxh * BYTESPERPIXEL);
187 if (!scalebuf) { 274 if (scalebuf == NULL) {
188 printf("vo_svga: Not enough memory for buffering!"); 275 printf("vo_svga: Not enough memory for buffering!\n");
189 uninit(); 276 uninit();
190 return (1); 277 return (1);
191 } 278 }
192 } 279 }
193 } else { 280 } else {
198 y_pos = (HEIGHT - maxh) / 2; 285 y_pos = (HEIGHT - maxh) / 2;
199 286
200 if (pformat == IMGFMT_YV12) { 287 if (pformat == IMGFMT_YV12) {
201 yuv2rgb_init(bpp, MODE_RGB); 288 yuv2rgb_init(bpp, MODE_RGB);
202 yuvbuf = malloc(maxw * maxh * BYTESPERPIXEL); 289 yuvbuf = malloc(maxw * maxh * BYTESPERPIXEL);
203 if (!yuvbuf) { 290 if (yuvbuf == NULL) {
204 printf("vo_svga: Not enough memory for buffering!"); 291 printf("vo_svga: Not enough memory for buffering!\n");
205 uninit(); 292 uninit();
206 return (1); 293 return (1);
207 } 294 }
208 } 295 }
209 296
215 } 302 }
216 303
217 static uint32_t query_format(uint32_t format) { 304 static uint32_t query_format(uint32_t format) {
218 uint8_t res = 0; 305 uint8_t res = 0;
219 306
220 if (!checked) 307 if (!checked) {
221 checksupportedmodes(); // Looking for available video modes 308 if (checksupportedmodes()) // Looking for available video modes
309 return(0);
310 }
222 switch (format) { 311 switch (format) {
223 case IMGFMT_RGB32: 312 case IMGFMT_RGB32:
224 case IMGFMT_BGR|32: { 313 case IMGFMT_BGR|32: {
225 return (vid_modes[_640x480x16M32] | vid_modes[_800x600x16M32] | vid_modes[_1024x768x16M32]); 314 return ((bpp_avail & BPP_32) ? 1 : 0);
226 } 315 }
227 case IMGFMT_RGB24: 316 case IMGFMT_RGB24:
228 case IMGFMT_BGR|24: { 317 case IMGFMT_BGR|24: {
229 res = vid_modes[_640x480x16M] | vid_modes[_800x600x16M] | vid_modes[_1024x768x16M]; 318 res = (bpp_avail & BPP_24) ? 1 : 0;
230 if (!res) { 319 if (!res) {
231 res = vid_modes[_640x480x16M32] | vid_modes[_800x600x16M32] | vid_modes[_1024x768x16M32]; 320 res = (bpp_avail & BPP_32) ? 1 : 0;
232 bpp_conv = 1; 321 bpp_conv = 1;
233 } 322 }
234 return (res); 323 return (res);
235 } 324 }
236 case IMGFMT_RGB16: 325 case IMGFMT_RGB16:
237 case IMGFMT_BGR|16: { 326 case IMGFMT_BGR|16: {
238 return (vid_modes[_640x480x64K] | vid_modes[_800x600x64K] | vid_modes[_1024x768x64K]); 327 return ((bpp_avail & BPP_16) ? 1 : 0);
239 } 328 }
240 case IMGFMT_RGB15: 329 case IMGFMT_RGB15:
241 case IMGFMT_BGR|15: { 330 case IMGFMT_BGR|15: {
242 res = vid_modes[_640x480x32K] | vid_modes[_800x600x32K] | vid_modes[_1024x768x32K]; 331 res = (bpp_avail & BPP_15) ? 1 : 0;
243 if (!res) { 332 if (!res) {
244 res = vid_modes[_640x480x64K] | vid_modes[_800x600x64K] | vid_modes[_1024x768x64K]; 333 res = (bpp_avail & BPP_16) ? 1 : 0;
245 bpp_conv = 1; 334 bpp_conv = 1;
246 } 335 }
247 return (res); 336 return (res);
248 } 337 }
249 case IMGFMT_YV12: return (1); 338 case IMGFMT_YV12: return (1);
276 static uint32_t draw_frame(uint8_t *src[]) { 365 static uint32_t draw_frame(uint8_t *src[]) {
277 if (pformat == IMGFMT_YV12) { 366 if (pformat == IMGFMT_YV12) {
278 yuv2rgb(yuvbuf, src[0], src[1], src[2], orig_w, orig_h, orig_w * BYTESPERPIXEL, orig_w, orig_w / 2); 367 yuv2rgb(yuvbuf, src[0], src[1], src[2], orig_w, orig_h, orig_w * BYTESPERPIXEL, orig_w, orig_w / 2);
279 src[0] = yuvbuf; 368 src[0] = yuvbuf;
280 } 369 }
281 if (scalebuf) { 370 if (scalebuf != NULL) {
282 gl_scalebox(orig_w, orig_h, src[0], maxw, maxh, scalebuf); 371 gl_scalebox(orig_w, orig_h, src[0], maxw, maxh, scalebuf);
283 src[0] = scalebuf; 372 src[0] = scalebuf;
284 } 373 }
285 if (bpp_conv) { 374 if (bpp_conv) {
286 uint16_t *src = (uint16_t *) src[0]; 375 uint16_t *src = (uint16_t *) src[0];
322 411
323 emms(); 412 emms();
324 sw = (uint32_t) (w * scaling); 413 sw = (uint32_t) (w * scaling);
325 sh = (uint32_t) (h * scaling); 414 sh = (uint32_t) (h * scaling);
326 yuv2rgb(yuvbuf, image[0], image[1], image[2], w, h, orig_w * BYTESPERPIXEL, stride[0], stride[1]); 415 yuv2rgb(yuvbuf, image[0], image[1], image[2], w, h, orig_w * BYTESPERPIXEL, stride[0], stride[1]);
327 if (scalebuf) { 416 if (scalebuf != NULL) {
328 gl_scalebox(w, h, yuvbuf, sw, sh, scalebuf); 417 gl_scalebox(w, h, yuvbuf, sw, sh, scalebuf);
329 src = scalebuf; 418 src = scalebuf;
330 } 419 }
331 gl_putbox((int)(x * scaling) + x_pos, (int)(y * scaling) + y_pos, sw, sh, src); 420 gl_putbox((int)(x * scaling) + x_pos, (int)(y * scaling) + y_pos, sw, sh, src);
332 } 421 }
345 434
346 static void check_events(void) { 435 static void check_events(void) {
347 } 436 }
348 437
349 static void uninit(void) { 438 static void uninit(void) {
439 vga_modelist_t *list = modelist;
440
350 gl_freecontext(screen); 441 gl_freecontext(screen);
351 gl_freecontext(virt); 442 gl_freecontext(virt);
352 vga_setmode(TEXT); 443 vga_setmode(TEXT);
353 if (bppbuf) 444 if (bppbuf != NULL)
354 free(bppbuf); 445 free(bppbuf);
355 if (scalebuf) 446 if (scalebuf != NULL)
356 free(scalebuf); 447 free(scalebuf);
357 if (yuvbuf) 448 if (yuvbuf != NULL)
358 free(yuvbuf); 449 free(yuvbuf);
450 if (modelist != NULL) {
451 while (modelist->next != NULL) {
452 list = modelist;
453 while (list->next != NULL)
454 list = list->next;
455 free(list);
456 }
457 free(modelist);
458 }
359 } 459 }
360 460