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