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