Mercurial > mplayer.hg
annotate libvo/vo_vesa.c @ 2415:58ea110b4036
libmad (ARM) patch by jeroen.dobbelaere@acunia.com
author | arpi |
---|---|
date | Tue, 23 Oct 2001 12:03:41 +0000 |
parents | 27ca5ad3c7e9 |
children | 6fb598bd7ede |
rev | line source |
---|---|
2244 | 1 /* |
2 * video_out_vesa.c | |
3 * | |
4 * Copyright (C) Nick Kurshev <nickols_k@mail.ru> - Oct 2001 | |
5 * | |
6 * You can redistribute this file under terms and conditions | |
7 * GNU General Public licence v2. | |
8 * This file is partly based on vbetest.c from lrmi distributive. | |
9 */ | |
10 | |
11 /* | |
12 TODO: | |
13 - DGA support (need volunteers who have corresponding hardware) | |
14 - hw YUV support (need volunteers who have corresponding hardware) | |
15 - double (triple) buffering (if it will really speedup playback). | |
16 - refresh rate support (need additional info from mplayer) | |
17 */ | |
18 #include <stdio.h> | |
19 #include <string.h> | |
20 #include <stddef.h> | |
21 #include <limits.h> | |
22 | |
23 #include "config.h" | |
24 #include "video_out.h" | |
25 #include "video_out_internal.h" | |
26 | |
27 #include "fastmemcpy.h" | |
28 #include "yuv2rgb.h" | |
2337 | 29 #include "sub.h" |
2244 | 30 #include "linux/vbelib.h" |
31 #include "bswap.h" | |
32 | |
2298 | 33 #include "../postproc/swscale.h" |
34 | |
2244 | 35 LIBVO_EXTERN(vesa) |
36 extern int verbose; | |
37 | |
38 #ifndef max | |
39 #define max(a,b) ((a)>(b)?(a):(b)) | |
40 #endif | |
41 #ifndef min | |
42 #define min(a,b) ((a)<(b)?(a):(b)) | |
43 #endif | |
44 | |
45 | |
46 static vo_info_t vo_info = | |
47 { | |
48 "VESA VBE 2.0 video output", | |
49 "vesa", | |
50 "Nick Kurshev <nickols_k@mail.ru>", | |
51 "Requires ROOT privileges" | |
52 }; | |
53 | |
54 /* driver data */ | |
55 | |
56 /* | |
57 TODO: for linear framebuffer mode: | |
58 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
59 win.ptr = linear address of frame buffer; | |
60 win.low = 0; | |
61 win.high = vide_memory_size; | |
62 */ | |
63 struct win_frame | |
64 { | |
65 uint8_t *ptr; /* pointer to window's frame memory */ | |
66 uint32_t low; /* lowest boundary of frame */ | |
67 uint32_t high; /* highest boundary of frame */ | |
68 uint8_t idx; /* indicates index of relocatable frame (A or B) */ | |
69 }; | |
70 | |
2298 | 71 static int vesa_zoom=0; /* software scaling */ |
72 static unsigned int scale_xinc=0; | |
73 static unsigned int scale_yinc=0; | |
74 | |
2244 | 75 static uint32_t image_width, image_height; /* source image dimension */ |
2329 | 76 static int32_t x_offset,y_offset; /* to center image on screen */ |
2244 | 77 static unsigned init_mode; /* mode before run of mplayer */ |
78 static void *init_state = NULL; /* state before run of mplayer */ | |
79 static struct win_frame win; /* real-mode window to video memory */ | |
2308 | 80 static uint8_t *yuv_buffer = NULL; /* for yuv2rgb and sw_scaling */ |
2244 | 81 static unsigned video_mode; /* selected video mode for playback */ |
82 static struct VesaModeInfoBlock video_mode_info; | |
2331 | 83 static int flip_trigger = 0; |
2337 | 84 static void (*draw_alpha_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride); |
2244 | 85 |
86 #define MOVIE_MODE (MODE_ATTR_COLOR | MODE_ATTR_GRAPHICS) | |
87 #define FRAME_MODE (MODE_WIN_RELOCATABLE | MODE_WIN_READABLE | MODE_WIN_WRITEABLE) | |
88 static char * vbeErrToStr(int err) | |
89 { | |
90 char *retval; | |
91 static char sbuff[80]; | |
92 if((err & VBE_VESA_ERROR_MASK) == VBE_VESA_ERROR_MASK) | |
93 { | |
2255 | 94 sprintf(sbuff,"VESA failed = 0x4f%x",(err & VBE_VESA_ERRCODE_MASK)>>8); |
2244 | 95 retval = sbuff; |
96 } | |
97 else | |
98 switch(err) | |
99 { | |
100 case VBE_OK: retval = "No error"; break; | |
101 case VBE_VM86_FAIL: retval = "vm86() syscall failed"; break; | |
102 case VBE_OUT_OF_DOS_MEM: retval = "Out of DOS memory"; break; | |
103 case VBE_OUT_OF_MEM: retval = "Out of memory"; break; | |
2360 | 104 case VBE_BROKEN_BIOS: retval = "Broken BIOS or DOS TSR"; break; |
2244 | 105 default: sprintf(sbuff,"Uknown error: %i",err); retval=sbuff; break; |
106 } | |
107 return retval; | |
108 } | |
109 | |
110 #define PRINT_VBE_ERR(name,err) { printf("vo_vesa: %s returns: %s\n",name,vbeErrToStr(err)); fflush(stdout); } | |
111 | |
112 static void vesa_term( void ) | |
113 { | |
114 int err; | |
115 if((err=vbeRestoreState(init_state)) != VBE_OK) PRINT_VBE_ERR("vbeRestoreState",err); | |
116 if((err=vbeSetMode(init_mode,NULL)) != VBE_OK) PRINT_VBE_ERR("vbeSetMode",err); | |
2337 | 117 if(yuv_buffer) free(yuv_buffer); |
2244 | 118 vbeDestroy(); |
119 } | |
120 | |
121 #define VALID_WIN_FRAME(offset) (offset >= win.low && offset < win.high) | |
122 #define VIDEO_PTR(offset) (win.ptr + offset - win.low) | |
123 | |
124 static inline void __vbeSwitchBank(unsigned long offset) | |
125 { | |
126 unsigned long gran; | |
127 unsigned new_offset; | |
128 int err; | |
129 gran = video_mode_info.WinGranularity*1024; | |
130 new_offset = offset / gran; | |
131 if((err=vbeSetWindow(win.idx,new_offset)) != VBE_OK) | |
132 { | |
133 PRINT_VBE_ERR("vbeSetWindow",err); | |
134 printf("vo_vesa: Fatal error occured! Can't continue\n"); | |
135 vesa_term(); | |
136 exit(-1); | |
137 } | |
138 win.low = new_offset * gran; | |
139 win.high = win.low + video_mode_info.WinSize*1024; | |
140 } | |
141 | |
142 static void __vbeSetPixel(int x, int y, int r, int g, int b) | |
143 { | |
144 int x_res = video_mode_info.XResolution; | |
145 int y_res = video_mode_info.YResolution; | |
146 int shift_r = video_mode_info.RedFieldPosition; | |
147 int shift_g = video_mode_info.GreenFieldPosition; | |
148 int shift_b = video_mode_info.BlueFieldPosition; | |
149 int pixel_size = (video_mode_info.BitsPerPixel+7)/8; | |
150 int bpl = video_mode_info.BytesPerScanLine; | |
151 int color, offset; | |
152 | |
153 if (x < 0 || x >= x_res || y < 0 || y >= y_res) return; | |
154 r >>= 8 - video_mode_info.RedMaskSize; | |
155 g >>= 8 - video_mode_info.GreenMaskSize; | |
156 b >>= 8 - video_mode_info.BlueMaskSize; | |
157 color = (r << shift_r) | (g << shift_g) | (b << shift_b); | |
158 offset = y * bpl + (x * pixel_size); | |
159 if(!VALID_WIN_FRAME(offset)) __vbeSwitchBank(offset); | |
160 memcpy(VIDEO_PTR(offset), &color, pixel_size); | |
161 } | |
162 | |
163 /* | |
164 Copies line of frame to video memory. Data should be in the same format as video | |
165 memory. | |
166 */ | |
167 static void __vbeCopyBlock(unsigned long offset,uint8_t *image,unsigned long size) | |
168 { | |
169 unsigned long delta,src_idx = 0; | |
170 while(size) | |
171 { | |
172 if(!VALID_WIN_FRAME(offset)) __vbeSwitchBank(offset); | |
173 delta = min(size,win.high - offset); | |
174 memcpy(VIDEO_PTR(offset),&image[src_idx],delta); | |
175 src_idx += delta; | |
176 offset += delta; | |
177 size -= delta; | |
178 } | |
179 } | |
180 | |
181 static void __vbeCopyBlockSwap(unsigned long offset,uint8_t *image,unsigned long size) | |
182 { | |
183 unsigned byte_len; | |
184 uint8_t ch; | |
185 while(size) | |
186 { | |
187 switch(video_mode_info.BitsPerPixel) | |
188 { | |
189 case 8: byte_len = 1; break; | |
190 default: | |
191 case 15: | |
192 printf("vo_vesa: Can't swap non byte aligned data\n"); | |
193 vesa_term(); | |
194 exit(-1); | |
195 case 16: *(image + offset) = ByteSwap16(*(image + offset)); | |
196 byte_len = 2; break; | |
197 case 24: ch = *(image+offset); | |
198 *(image+offset) = *(image+offset+3); | |
199 *(image+offset+3) = ch; | |
200 byte_len = 3; break; | |
201 case 32: *(image + offset) = ByteSwap32(*(image + offset)); | |
202 byte_len = 4; break; | |
203 } | |
204 __vbeCopyBlock(offset,image,byte_len); | |
205 size -= byte_len; | |
206 image += byte_len; | |
207 offset += byte_len; | |
208 } | |
209 } | |
210 | |
211 /* | |
212 Copies frame to video memory. Data should be in the same format as video | |
213 memory. | |
214 */ | |
215 static void __vbeCopyData(uint8_t *image) | |
216 { | |
2308 | 217 unsigned long i,j,image_offset,offset; |
2244 | 218 unsigned pixel_size,image_line_size,screen_line_size,x_shift; |
219 pixel_size = (video_mode_info.BitsPerPixel+7)/8; | |
220 screen_line_size = video_mode_info.XResolution*pixel_size; | |
221 image_line_size = image_width*pixel_size; | |
2306 | 222 if(image_width == video_mode_info.XResolution) |
223 { | |
224 /* Special case for zooming */ | |
225 __vbeCopyBlock(y_offset*screen_line_size,image,image_line_size*image_height); | |
226 } | |
227 else | |
2244 | 228 { |
2306 | 229 x_shift = x_offset*pixel_size; |
2308 | 230 for(j=0,i=y_offset;j<image_height;i++,j++) |
2306 | 231 { |
232 offset = i*screen_line_size+x_shift; | |
233 image_offset = j*image_line_size; | |
234 __vbeCopyBlock(offset,&image[image_offset],image_line_size); | |
235 } | |
2244 | 236 } |
237 } | |
2328 | 238 |
2244 | 239 /* is called for yuv only */ |
240 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
241 { | |
2298 | 242 if(vesa_zoom) |
243 { | |
244 SwScale_YV12slice_brg24(image,stride,y,h, | |
245 yuv_buffer, | |
246 image_width*((video_mode_info.BitsPerPixel+7)/8), | |
247 image_width, video_mode_info.BitsPerPixel, | |
248 scale_xinc, scale_yinc); | |
249 } | |
250 else | |
251 { | |
2331 | 252 uint8_t *yuv_slice; |
253 yuv_slice=yuv_buffer+(image_width*y+x)*((video_mode_info.BitsPerPixel+7)/8); | |
254 yuv2rgb(yuv_slice, image[0], image[1], image[2], w, h, | |
2293 | 255 image_width * ((video_mode_info.BitsPerPixel+7)/8), |
2244 | 256 stride[0], stride[1]); |
2298 | 257 } |
2331 | 258 flip_trigger = 1; |
2298 | 259 return 0; |
2244 | 260 } |
261 | |
2337 | 262 static void draw_alpha_32(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ |
263 vo_draw_alpha_rgb32(w,h,src,srca,stride,yuv_buffer+4*(y0*image_width+x0),4*image_width); | |
264 } | |
265 | |
266 static void draw_alpha_24(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
267 vo_draw_alpha_rgb24(w,h,src,srca,stride,yuv_buffer+3*(y0*image_width+x0),3*image_width); | |
268 } | |
269 | |
270 static void draw_alpha_16(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
271 vo_draw_alpha_rgb16(w,h,src,srca,stride,yuv_buffer+2*(y0*image_width+x0),2*image_width); | |
272 } | |
273 | |
274 static void draw_alpha_15(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
275 vo_draw_alpha_rgb15(w,h,src,srca,stride,yuv_buffer+2*(y0*image_width+x0),2*image_width); | |
276 } | |
277 | |
278 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride){ | |
279 } | |
280 | |
281 | |
2244 | 282 static void draw_osd(void) |
283 { | |
2337 | 284 if(yuv_buffer) vo_draw_text(image_width,image_height,draw_alpha_fnc); |
2244 | 285 } |
286 | |
287 static void flip_page(void) | |
288 { | |
2331 | 289 if(flip_trigger) { __vbeCopyData(yuv_buffer); flip_trigger = 0; } |
2244 | 290 } |
291 | |
292 /* is called for rgb only */ | |
293 static uint32_t draw_frame(uint8_t *src[]) | |
294 { | |
295 __vbeCopyData(src[0]); | |
296 return 0; | |
297 } | |
298 | |
299 static uint32_t query_format(uint32_t format) | |
300 { | |
301 uint32_t retval; | |
302 switch(format) | |
303 { | |
304 case IMGFMT_YV12: | |
2296 | 305 #if 0 /* Should be tested better */ |
2244 | 306 case IMGFMT_I420: |
307 case IMGFMT_IYUV: | |
308 #endif | |
309 case IMGFMT_RGB8: | |
310 case IMGFMT_RGB15: | |
311 case IMGFMT_RGB16: | |
312 case IMGFMT_RGB24: | |
313 case IMGFMT_RGB32: | |
314 case IMGFMT_BGR8: | |
315 case IMGFMT_BGR15: | |
316 case IMGFMT_BGR16: | |
317 case IMGFMT_BGR24: | |
318 case IMGFMT_BGR32: | |
319 retval = 1; break; | |
320 default: | |
321 if(verbose) | |
322 printf("vo_vesa: unknown format: %x = %s\n",format,vo_format_name(format)); | |
323 retval = 0; | |
324 } | |
325 return retval; | |
326 } | |
327 | |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
328 static void vesa_aspect(uint32_t width,uint32_t height, |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
329 uint32_t xres,uint32_t yres, |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
330 uint32_t *image_width,uint32_t *image_height) |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
331 { |
2331 | 332 float aspect_factor; |
2328 | 333 aspect_factor = (float)width / height; |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
334 *image_width = xres; |
2328 | 335 *image_height = xres /aspect_factor; |
336 if(verbose) printf("vo_vesa: aspect factor = %f(%ux%u) *image=%ux%u screen=%ux%u\n",aspect_factor,width,height,*image_width,*image_height,xres,yres); | |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
337 if((*image_height) > yres) |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
338 { |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
339 *image_height = yres; |
2328 | 340 *image_width = yres * aspect_factor; |
2329 | 341 if(verbose) printf("vo_vesa: Y > X therefore *image=%ux%u\n",*image_width,*image_height); |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
342 } |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
343 } |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
344 |
2293 | 345 static char *model2str(unsigned char type) |
346 { | |
347 char *retval; | |
348 switch(type) | |
349 { | |
350 case memText: retval = "Text"; break; | |
351 case memCGA: retval="CGA"; break; | |
352 case memHercules: retval="Hercules"; break; | |
353 case memPL: retval="Planar"; break; | |
354 case memPK: retval="Packed pixel"; break; | |
355 case mem256: retval="256"; break; | |
356 case memRGB: retval="Direct color RGB"; break; | |
357 case memYUV: retval="Direct color YUV"; break; | |
358 default: retval="Unknown"; break; | |
359 } | |
360 return retval; | |
361 } | |
362 | |
2244 | 363 /* fullscreen: |
364 * bit 0 (0x01) means fullscreen (-fs) | |
365 * bit 1 (0x02) means mode switching (-vm) | |
366 * bit 2 (0x04) enables software scaling (-zoom) | |
2335 | 367 * bit 3 (0x08) enables flipping (-flip) (NK: and for what?) |
2244 | 368 */ |
369 static uint32_t | |
2329 | 370 init(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
2244 | 371 { |
372 struct VbeInfoBlock vib; | |
373 struct VesaModeInfoBlock vmib; | |
374 size_t i,num_modes; | |
2329 | 375 uint32_t w,h; |
2244 | 376 unsigned short *mode_ptr,win_seg; |
377 unsigned bpp,best_x = UINT_MAX,best_y=UINT_MAX,best_mode_idx = UINT_MAX; | |
2337 | 378 int err,fs_mode,yuv_fmt; |
2244 | 379 image_width = width; |
380 image_height = height; | |
2336 | 381 fs_mode = 0; |
2329 | 382 if(flags & 0x8) |
2244 | 383 { |
2329 | 384 printf("vo_vesa: switch -flip is not supported\n"); |
2244 | 385 } |
2329 | 386 if(flags & 0x04) vesa_zoom = 1; |
2336 | 387 if(flags & 0x01) |
388 { | |
389 if(vesa_zoom) vesa_zoom = 2; | |
390 else fs_mode = 1; | |
391 } | |
2244 | 392 if((err=vbeInit()) != VBE_OK) { PRINT_VBE_ERR("vbeInit",err); return -1; } |
393 memcpy(vib.VESASignature,"VBE2",4); | |
394 if((err=vbeGetControllerInfo(&vib)) != VBE_OK) | |
395 { | |
396 PRINT_VBE_ERR("vbeGetControllerInfo",err); | |
397 printf("vo_vesa: possible reason: No VBE2 BIOS found\n"); | |
398 return -1; | |
399 } | |
400 /* Print general info here */ | |
401 printf("vo_vesa: Found VESA VBE BIOS Version %x.%x Revision: %x\n", | |
402 (int)(vib.VESAVersion >> 8) & 0xff, | |
403 (int)(vib.VESAVersion & 0xff), | |
404 (int)(vib.OemSoftwareRev & 0xffff)); | |
2255 | 405 printf("vo_vesa: Video memory: %u Kb\n",vib.TotalMemory*64); |
406 printf("vo_vesa: VESA Capabilities: %s %s %s %s %s\n" | |
407 ,vib.Capabilities & VBE_DAC_8BIT ? "8-bit DAC," : "6-bit DAC," | |
408 ,vib.Capabilities & VBE_NONVGA_CRTC ? "non-VGA CRTC,":"VGA CRTC," | |
409 ,vib.Capabilities & VBE_SNOWED_RAMDAC ? "snowed RAMDAC,":"normal RAMDAC," | |
410 ,vib.Capabilities & VBE_STEREOSCOPIC ? "stereoscopic,":"no stereoscopic," | |
411 ,vib.Capabilities & VBE_STEREO_EVC ? "Stereo EVC":"no stereo"); | |
412 printf("vo_vesa: !!! Below will be printed OEM info. !!!\n"); | |
413 printf("vo_vesa: You should watch 5 OEM related lines below else you've broken vm86\n"); | |
2244 | 414 printf("vo_vesa: OEM info: %s\n",vib.OemStringPtr); |
2255 | 415 printf("vo_vesa: OEM Revision: %x\n",vib.OemSoftwareRev); |
416 printf("vo_vesa: OEM vendor: %s\n",vib.OemVendorNamePtr); | |
417 printf("vo_vesa: OEM Product Name: %s\n",vib.OemProductNamePtr); | |
418 printf("vo_vesa: OEM Product Rev: %s\n",vib.OemProductRevPtr); | |
419 printf("vo_vesa: Hint: To get workable TV-Out you should have plugged tv-connector in\n" | |
420 "vo_vesa: before booting PC since VESA BIOS initializes itself only during POST\n"); | |
2244 | 421 /* Find best mode here */ |
422 num_modes = 0; | |
423 mode_ptr = vib.VideoModePtr; | |
424 while(*mode_ptr++ != 0xffff) num_modes++; | |
2337 | 425 yuv_fmt = format == IMGFMT_YV12 || format == IMGFMT_I420 || format == IMGFMT_IYUV; |
2329 | 426 if(vo_dbpp) |
427 { | |
428 bpp = vo_dbpp; | |
2337 | 429 if(yuv_fmt) yuv2rgb_init(bpp, MODE_RGB); |
2329 | 430 } |
431 else | |
2244 | 432 switch(format) |
433 { | |
434 case IMGFMT_BGR8: | |
435 case IMGFMT_RGB8: bpp = 8; break; | |
436 case IMGFMT_BGR15: | |
437 case IMGFMT_RGB15: bpp = 15; break; | |
438 case IMGFMT_YV12: | |
439 case IMGFMT_I420: | |
2296 | 440 case IMGFMT_IYUV: bpp=16; |
441 yuv2rgb_init(bpp, MODE_RGB); | |
2244 | 442 default: |
443 case IMGFMT_BGR16: | |
444 case IMGFMT_RGB16: bpp = 16; break; | |
445 case IMGFMT_BGR24: | |
446 case IMGFMT_RGB24: bpp = 24; break; | |
447 case IMGFMT_BGR32: | |
448 case IMGFMT_RGB32: bpp = 32; break; | |
449 } | |
2337 | 450 switch(bpp) |
451 { | |
452 case 15: draw_alpha_fnc = draw_alpha_15; break; | |
453 case 16: draw_alpha_fnc = draw_alpha_16; break; | |
454 case 24: draw_alpha_fnc = draw_alpha_24; break; | |
455 case 32: draw_alpha_fnc = draw_alpha_32; break; | |
456 default: draw_alpha_fnc = draw_alpha_null; break; | |
457 } | |
2244 | 458 if(verbose) |
459 { | |
2304 | 460 printf("vo_vesa: Requested mode: %ux%u@%u (%s)\n",width,height,bpp,vo_format_name(format)); |
2244 | 461 printf("vo_vesa: Total modes found: %u\n",num_modes); |
462 mode_ptr = vib.VideoModePtr; | |
463 printf("vo_vesa: Mode list:"); | |
464 for(i = 0;i < num_modes;i++) | |
465 { | |
466 printf(" %04X",mode_ptr[i]); | |
467 } | |
468 printf("\nvo_vesa: Modes in detail:\n"); | |
469 } | |
470 mode_ptr = vib.VideoModePtr; | |
2335 | 471 if(vesa_zoom) |
472 { | |
473 image_width = d_width; | |
474 image_height= d_height; | |
475 } | |
476 if(vo_screenwidth) w = vo_screenwidth; | |
477 else w = max(image_width,width); | |
478 if(vo_screenheight) h = vo_screenheight; | |
479 else h = max(image_height,height); | |
2244 | 480 for(i=0;i < num_modes;i++) |
481 { | |
482 if((err=vbeGetModeInfo(mode_ptr[i],&vmib)) != VBE_OK) | |
483 { | |
484 PRINT_VBE_ERR("vbeGetModeInfo",err); | |
485 return -1; | |
486 } | |
2329 | 487 if(vmib.XResolution >= w && |
488 vmib.YResolution >= h && | |
2244 | 489 (vmib.ModeAttributes & MOVIE_MODE) == MOVIE_MODE && |
490 vmib.BitsPerPixel == bpp && | |
491 vmib.MemoryModel == memRGB) | |
492 { | |
2293 | 493 if(vmib.XResolution <= best_x && |
494 vmib.YResolution <= best_y) | |
2244 | 495 { |
496 best_x = vmib.XResolution; | |
497 best_y = vmib.YResolution; | |
498 best_mode_idx = i; | |
499 } | |
500 } | |
501 if(verbose) | |
502 { | |
2298 | 503 printf("vo_vesa: Mode (%03u): mode=%04X %ux%u@%u attr=%04X\n" |
2293 | 504 "vo_vesa: #planes=%u model=%u(%s) #pages=%u\n" |
505 "vo_vesa: winA=%X(attr=%u) winB=%X(attr=%u) winSize=%u winGran=%u\n" | |
506 "vo_vesa: direct_color=%u DGA_phys_addr=%08X\n" | |
2244 | 507 ,i,mode_ptr[i],vmib.XResolution,vmib.YResolution,vmib.BitsPerPixel,vmib.ModeAttributes |
2293 | 508 ,vmib.NumberOfPlanes,vmib.MemoryModel,model2str(vmib.MemoryModel),vmib.NumberOfImagePages |
2244 | 509 ,vmib.WinASegment,vmib.WinAAttributes,vmib.WinBSegment,vmib.WinBAttributes,vmib.WinSize,vmib.WinGranularity |
510 ,vmib.DirectColorModeInfo,vmib.PhysBasePtr); | |
511 if(vmib.MemoryModel == 6 || vmib.MemoryModel == 7) | |
512 printf("vo_vesa: direct_color_info = %u:%u:%u:%u\n" | |
513 ,vmib.RedMaskSize,vmib.GreenMaskSize,vmib.BlueMaskSize,vmib.RsvdMaskSize); | |
514 fflush(stdout); | |
515 } | |
516 } | |
517 if(best_mode_idx != UINT_MAX) | |
518 { | |
519 video_mode = vib.VideoModePtr[best_mode_idx]; | |
520 fflush(stdout); | |
521 if((err=vbeGetMode(&init_mode)) != VBE_OK) | |
522 { | |
523 PRINT_VBE_ERR("vbeGetMode",err); | |
524 return -1; | |
525 } | |
526 if(verbose) printf("vo_vesa: Initial video mode: %x\n",init_mode); | |
527 if((err=vbeGetModeInfo(video_mode,&video_mode_info)) != VBE_OK) | |
528 { | |
529 PRINT_VBE_ERR("vbeGetModeInfo",err); | |
530 return -1; | |
531 } | |
2329 | 532 printf("vo_vesa: Using VESA mode (%u) = %x [%ux%u@%u]\n" |
533 ,best_mode_idx,video_mode,video_mode_info.XResolution | |
534 ,video_mode_info.YResolution,video_mode_info.BitsPerPixel); | |
2336 | 535 if( vesa_zoom || fs_mode ) |
2298 | 536 { |
2304 | 537 if( format==IMGFMT_YV12 ) |
538 { | |
539 /* software scale */ | |
2329 | 540 if(vesa_zoom > 1) |
2335 | 541 vesa_aspect(image_width,image_height, |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
542 video_mode_info.XResolution,video_mode_info.YResolution, |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
543 &image_width,&image_height); |
2336 | 544 else |
545 if(fs_mode) | |
546 { | |
547 image_width = video_mode_info.XResolution; | |
548 image_height = video_mode_info.YResolution; | |
549 vesa_zoom = 1; | |
550 } | |
2304 | 551 scale_xinc=(width << 16) / image_width - 2; /* needed for proper rounding */ |
552 scale_yinc=(height << 16) / image_height + 2; | |
553 SwScale_Init(); | |
554 if(verbose) printf("vo_vesa: Using SCALE\n"); | |
555 } | |
556 else | |
557 { | |
558 printf("vo_vesa: Can't apply zooming to non YV12 formats\n"); | |
559 return -1; | |
560 } | |
2298 | 561 } |
2244 | 562 if((video_mode_info.WinAAttributes & FRAME_MODE) == FRAME_MODE) |
563 win.idx = 0; /* frame A */ | |
564 else | |
565 if((video_mode_info.WinBAttributes & FRAME_MODE) == FRAME_MODE) | |
566 win.idx = 1; /* frame B */ | |
567 else { printf("vo_vesa: Can't find usable frame of window\n"); return -1; } | |
568 if(!(win_seg = win.idx == 0 ? video_mode_info.WinASegment:video_mode_info.WinBSegment)) | |
569 { | |
570 printf("vo_vesa: Can't find valid window address\n"); | |
571 if(video_mode_info.ModeAttributes & MODE_ATTR_LINEAR) | |
572 printf("vo_vesa: Your BIOS supports DGA access which is not implemented for now\n"); | |
573 return -1; | |
574 } | |
575 win.ptr = PhysToVirtSO(win_seg,0); | |
576 win.low = 0L; | |
577 win.high= video_mode_info.WinSize*1024; | |
2329 | 578 if(video_mode_info.XResolution > image_width) |
579 x_offset = (video_mode_info.XResolution - image_width) / 2; | |
580 else x_offset = 0; | |
581 if(video_mode_info.YResolution > image_height) | |
582 y_offset = (video_mode_info.YResolution - image_height) / 2; | |
583 else y_offset = 0; | |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
584 if(verbose) |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
585 printf("vo_vesa: image: %ux%u screen = %ux%u x_offset = %u y_offset = %u\n" |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
586 ,image_width,image_height |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
587 ,video_mode_info.XResolution,video_mode_info.YResolution |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
588 ,x_offset,y_offset); |
2337 | 589 if(yuv_fmt) |
590 if(!(yuv_buffer = malloc(image_width*image_height*bpp))) | |
591 { | |
592 printf("vo_vesa: Can't allocate temporary buffer\n"); | |
593 return -1; | |
594 } | |
2244 | 595 if((err=vbeSaveState(&init_state)) != VBE_OK) |
596 { | |
597 PRINT_VBE_ERR("vbeSaveState",err); | |
598 return -1; | |
599 } | |
600 if((err=vbeSetMode(video_mode,NULL)) != VBE_OK) | |
601 { | |
602 PRINT_VBE_ERR("vbeSetMode",err); | |
603 return -1; | |
604 } | |
605 /* Now we are in video mode!!!*/ | |
2337 | 606 /* Below 'return -1' is impossible */ |
2244 | 607 if(verbose) |
608 { | |
609 printf("vo_vesa: Graphics mode was activated\n"); | |
610 fflush(stdout); | |
611 } | |
612 } | |
613 else | |
614 { | |
2255 | 615 printf("vo_vesa: Can't find mode for: %ux%u@%u\n",width,height,bpp); |
2244 | 616 return -1; |
617 } | |
618 if(verbose) | |
619 { | |
620 printf("vo_vesa: VESA initialization complete\n"); | |
621 fflush(stdout); | |
622 } | |
623 if(verbose) | |
624 { | |
625 int x_res = video_mode_info.XResolution; | |
626 int y_res = video_mode_info.YResolution; | |
627 int x, y; | |
628 | |
629 for (y = 0; y < y_res; ++y) | |
630 { | |
631 for (x = 0; x < x_res; ++x) | |
632 { | |
633 int r, g, b; | |
634 if ((x & 16) ^ (y & 16)) | |
635 { | |
636 r = x * 255 / x_res; | |
637 g = y * 255 / y_res; | |
638 b = 255 - x * 255 / x_res; | |
639 } | |
640 else | |
641 { | |
642 r = 255 - x * 255 / x_res; | |
643 g = y * 255 / y_res; | |
644 b = 255 - y * 255 / y_res; | |
645 } | |
646 | |
647 __vbeSetPixel(x, y, r, g, b); | |
648 } | |
649 } | |
650 } | |
2410 | 651 vbeWriteString(0,0,7,title); |
2244 | 652 return 0; |
653 } | |
654 | |
655 static const vo_info_t* | |
656 get_info(void) | |
657 { | |
658 return &vo_info; | |
659 } | |
660 | |
661 static void | |
662 uninit(void) | |
663 { | |
664 vesa_term(); | |
665 } | |
666 | |
667 | |
668 static void check_events(void) | |
669 { | |
670 /* Nothing to do */ | |
671 } |