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