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