Mercurial > mplayer.hg
annotate libvo/vo_vesa.c @ 8791:668b30187d48
Check if we can open /dev/mem in preinit(), so we can exit cleanly.
author | filon |
---|---|
date | Sun, 05 Jan 2003 11:24:13 +0000 |
parents | 605c85c27e68 |
children | c2e0f2cd8666 |
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 | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
7 * of GNU General Public licence v2. |
2244 | 8 * This file is partly based on vbetest.c from lrmi distributive. |
9 */ | |
10 | |
11 /* | |
12 TODO: | |
13 - hw YUV support (need volunteers who have corresponding hardware) | |
2649 | 14 - triple buffering (if it will really speedup playback). |
2692 | 15 note: triple buffering requires VBE 3.0 - need volunteers. |
2244 | 16 */ |
2775 | 17 #include "config.h" |
7069 | 18 #include "gtf.h" |
2244 | 19 #include <stdio.h> |
2775 | 20 #ifdef HAVE_MALLOC_H |
21 #include <malloc.h> | |
22 #endif | |
2446 | 23 #include <stdlib.h> |
2244 | 24 #include <string.h> |
25 #include <stddef.h> | |
26 #include <limits.h> | |
4739 | 27 #include <unistd.h> |
28 #include <pwd.h> | |
29 #include <sys/types.h> | |
30 #include <sys/stat.h> | |
8791
668b30187d48
Check if we can open /dev/mem in preinit(), so we can exit cleanly.
filon
parents:
8786
diff
changeset
|
31 #include <fcntl.h> |
4739 | 32 |
2244 | 33 |
34 #include "video_out.h" | |
35 #include "video_out_internal.h" | |
36 | |
37 #include "fastmemcpy.h" | |
2337 | 38 #include "sub.h" |
2244 | 39 #include "linux/vbelib.h" |
40 #include "bswap.h" | |
2689 | 41 #include "aspect.h" |
3202 | 42 #include "vesa_lvo.h" |
4089 | 43 #ifdef CONFIG_VIDIX |
4030 | 44 #include "vosub_vidix.h" |
4089 | 45 #endif |
2244 | 46 |
2298 | 47 #include "../postproc/swscale.h" |
48 | |
4739 | 49 |
50 #ifdef HAVE_PNG | |
51 extern vo_functions_t video_out_png; | |
52 #endif | |
53 | |
2244 | 54 extern int verbose; |
55 | |
7069 | 56 extern char *monitor_hfreq_str; |
57 extern char *monitor_vfreq_str; | |
58 extern char *monitor_dotclock_str; | |
59 | |
2649 | 60 #define MAX_BUFFERS 3 |
61 | |
2244 | 62 #ifndef max |
63 #define max(a,b) ((a)>(b)?(a):(b)) | |
64 #endif | |
65 #ifndef min | |
66 #define min(a,b) ((a)<(b)?(a):(b)) | |
67 #endif | |
68 | |
2688 | 69 #define UNUSED(x) ((void)(x)) /**< Removes warning about unused arguments */ |
2244 | 70 |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7690
diff
changeset
|
71 static vo_info_t info = |
2244 | 72 { |
73 "VESA VBE 2.0 video output", | |
74 "vesa", | |
75 "Nick Kurshev <nickols_k@mail.ru>", | |
76 "Requires ROOT privileges" | |
77 }; | |
78 | |
8148
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7690
diff
changeset
|
79 LIBVO_EXTERN(vesa) |
5b39e79af5fe
removed get_info, using the same sheme as in libmpcodecs instead
alex
parents:
7690
diff
changeset
|
80 |
2244 | 81 /* driver data */ |
82 | |
83 struct win_frame | |
84 { | |
85 uint8_t *ptr; /* pointer to window's frame memory */ | |
86 uint32_t low; /* lowest boundary of frame */ | |
87 uint32_t high; /* highest boundary of frame */ | |
2610 | 88 char idx; /* indicates index of relocatable frame (A=0 or B=1) |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
89 special case for DGA: idx=-1 |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
90 idx=-2 indicates invalid frame, exists only in init() */ |
2244 | 91 }; |
92 | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
93 static void (*cpy_blk_fnc)(unsigned long,uint8_t *,unsigned long) = NULL; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
94 |
4537 | 95 static uint32_t srcW=0,srcH=0,srcBpp,srcFourcc; /* source image description */ |
96 static uint32_t dstBpp,dstW, dstH,dstFourcc; /* destinition image description */ | |
2298 | 97 |
4537 | 98 static SwsContext * sws = NULL; |
99 | |
2329 | 100 static int32_t x_offset,y_offset; /* to center image on screen */ |
2244 | 101 static unsigned init_mode; /* mode before run of mplayer */ |
102 static void *init_state = NULL; /* state before run of mplayer */ | |
103 static struct win_frame win; /* real-mode window to video memory */ | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
104 static uint8_t *dga_buffer = NULL; /* for yuv2rgb and sw_scaling */ |
2244 | 105 static unsigned video_mode; /* selected video mode for playback */ |
106 static struct VesaModeInfoBlock video_mode_info; | |
2331 | 107 static int flip_trigger = 0; |
2337 | 108 static void (*draw_alpha_fnc)(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride); |
2244 | 109 |
2649 | 110 /* multibuffering */ |
111 uint8_t* video_base; /* should be never changed */ | |
112 uint32_t multi_buff[MAX_BUFFERS]; /* contains offsets of buffers */ | |
113 uint8_t multi_size=0; /* total number of buffers */ | |
114 uint8_t multi_idx=0; /* active buffer */ | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
115 |
2869 | 116 /* Linux Video Overlay */ |
117 static const char *lvo_name = NULL; | |
4089 | 118 #ifdef CONFIG_VIDIX |
4030 | 119 static const char *vidix_name = NULL; |
4089 | 120 #endif |
2869 | 121 |
2649 | 122 #define HAS_DGA() (win.idx == -1) |
2244 | 123 #define MOVIE_MODE (MODE_ATTR_COLOR | MODE_ATTR_GRAPHICS) |
2649 | 124 #define FRAME_MODE (MODE_WIN_RELOCATABLE | MODE_WIN_WRITEABLE) |
125 | |
2244 | 126 static char * vbeErrToStr(int err) |
127 { | |
128 char *retval; | |
129 static char sbuff[80]; | |
130 if((err & VBE_VESA_ERROR_MASK) == VBE_VESA_ERROR_MASK) | |
131 { | |
4667 | 132 sprintf(sbuff,"VESA failed = 0x4f%02x",(err & VBE_VESA_ERRCODE_MASK)>>8); |
2244 | 133 retval = sbuff; |
134 } | |
135 else | |
136 switch(err) | |
137 { | |
138 case VBE_OK: retval = "No error"; break; | |
139 case VBE_VM86_FAIL: retval = "vm86() syscall failed"; break; | |
140 case VBE_OUT_OF_DOS_MEM: retval = "Out of DOS memory"; break; | |
141 case VBE_OUT_OF_MEM: retval = "Out of memory"; break; | |
2360 | 142 case VBE_BROKEN_BIOS: retval = "Broken BIOS or DOS TSR"; break; |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
143 default: sprintf(sbuff,"Unknown or internal error: %i",err); retval=sbuff; break; |
2244 | 144 } |
145 return retval; | |
146 } | |
147 | |
148 #define PRINT_VBE_ERR(name,err) { printf("vo_vesa: %s returns: %s\n",name,vbeErrToStr(err)); fflush(stdout); } | |
149 | |
150 static void vesa_term( void ) | |
151 { | |
152 int err; | |
2869 | 153 if(lvo_name) vlvo_term(); |
4089 | 154 #ifdef CONFIG_VIDIX |
4030 | 155 else if(vidix_name) vidix_term(); |
4089 | 156 #endif |
2244 | 157 if((err=vbeRestoreState(init_state)) != VBE_OK) PRINT_VBE_ERR("vbeRestoreState",err); |
158 if((err=vbeSetMode(init_mode,NULL)) != VBE_OK) PRINT_VBE_ERR("vbeSetMode",err); | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
159 if(HAS_DGA()) vbeUnmapVideoBuffer((unsigned long)win.ptr,win.high); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
160 if(dga_buffer && !HAS_DGA()) free(dga_buffer); |
2244 | 161 vbeDestroy(); |
4537 | 162 if(sws) freeSwsContext(sws); |
2244 | 163 } |
164 | |
165 #define VALID_WIN_FRAME(offset) (offset >= win.low && offset < win.high) | |
166 #define VIDEO_PTR(offset) (win.ptr + offset - win.low) | |
167 | |
168 static inline void __vbeSwitchBank(unsigned long offset) | |
169 { | |
170 unsigned long gran; | |
171 unsigned new_offset; | |
172 int err; | |
173 gran = video_mode_info.WinGranularity*1024; | |
174 new_offset = offset / gran; | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
175 if(HAS_DGA()) { err = -1; goto show_err; } |
2244 | 176 if((err=vbeSetWindow(win.idx,new_offset)) != VBE_OK) |
177 { | |
2610 | 178 show_err: |
2686 | 179 vesa_term(); |
2244 | 180 PRINT_VBE_ERR("vbeSetWindow",err); |
181 printf("vo_vesa: Fatal error occured! Can't continue\n"); | |
182 exit(-1); | |
183 } | |
184 win.low = new_offset * gran; | |
185 win.high = win.low + video_mode_info.WinSize*1024; | |
186 } | |
187 | |
188 static void __vbeSetPixel(int x, int y, int r, int g, int b) | |
189 { | |
190 int x_res = video_mode_info.XResolution; | |
191 int y_res = video_mode_info.YResolution; | |
192 int shift_r = video_mode_info.RedFieldPosition; | |
193 int shift_g = video_mode_info.GreenFieldPosition; | |
194 int shift_b = video_mode_info.BlueFieldPosition; | |
4537 | 195 int pixel_size = (dstBpp+7)/8; |
2244 | 196 int bpl = video_mode_info.BytesPerScanLine; |
2676 | 197 int color; |
198 unsigned offset; | |
2244 | 199 |
200 if (x < 0 || x >= x_res || y < 0 || y >= y_res) return; | |
201 r >>= 8 - video_mode_info.RedMaskSize; | |
202 g >>= 8 - video_mode_info.GreenMaskSize; | |
203 b >>= 8 - video_mode_info.BlueMaskSize; | |
204 color = (r << shift_r) | (g << shift_g) | (b << shift_b); | |
205 offset = y * bpl + (x * pixel_size); | |
206 if(!VALID_WIN_FRAME(offset)) __vbeSwitchBank(offset); | |
207 memcpy(VIDEO_PTR(offset), &color, pixel_size); | |
208 } | |
209 | |
210 /* | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
211 Copies part of frame to video memory. Data should be in the same format |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
212 as video memory. |
2244 | 213 */ |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
214 static void __vbeCopyBlockFast(unsigned long offset,uint8_t *image,unsigned long size) |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
215 { |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
216 memcpy(&win.ptr[offset],image,size); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
217 } |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
218 |
2244 | 219 static void __vbeCopyBlock(unsigned long offset,uint8_t *image,unsigned long size) |
220 { | |
221 unsigned long delta,src_idx = 0; | |
222 while(size) | |
223 { | |
4537 | 224 if(!VALID_WIN_FRAME(offset)) __vbeSwitchBank(offset); |
225 delta = min(size,win.high - offset); | |
226 memcpy(VIDEO_PTR(offset),&image[src_idx],delta); | |
227 src_idx += delta; | |
228 offset += delta; | |
229 size -= delta; | |
2244 | 230 } |
231 } | |
232 | |
233 /* | |
234 Copies frame to video memory. Data should be in the same format as video | |
235 memory. | |
236 */ | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
237 |
4537 | 238 #define PIXEL_SIZE() ((dstBpp+7)/8) |
2676 | 239 #define SCREEN_LINE_SIZE(pixel_size) (video_mode_info.XResolution*(pixel_size) ) |
4537 | 240 #define IMAGE_LINE_SIZE(pixel_size) (dstW*(pixel_size)) |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
241 |
2244 | 242 static void __vbeCopyData(uint8_t *image) |
243 { | |
2308 | 244 unsigned long i,j,image_offset,offset; |
2244 | 245 unsigned pixel_size,image_line_size,screen_line_size,x_shift; |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
246 pixel_size = PIXEL_SIZE(); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
247 screen_line_size = SCREEN_LINE_SIZE(pixel_size); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
248 image_line_size = IMAGE_LINE_SIZE(pixel_size); |
4537 | 249 if(dstW == video_mode_info.XResolution) |
2306 | 250 { |
251 /* Special case for zooming */ | |
4537 | 252 (*cpy_blk_fnc)(y_offset*screen_line_size,image,image_line_size*dstH); |
2306 | 253 } |
254 else | |
2244 | 255 { |
2306 | 256 x_shift = x_offset*pixel_size; |
4537 | 257 for(j=0,i=y_offset;j<dstH;i++,j++) |
2306 | 258 { |
259 offset = i*screen_line_size+x_shift; | |
260 image_offset = j*image_line_size; | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
261 (*cpy_blk_fnc)(offset,&image[image_offset],image_line_size); |
2306 | 262 } |
2244 | 263 } |
264 } | |
2328 | 265 |
2244 | 266 /* is called for yuv only */ |
267 static uint32_t draw_slice(uint8_t *image[], int stride[], int w,int h,int x,int y) | |
268 { | |
4537 | 269 unsigned int dstride=HAS_DGA()?video_mode_info.XResolution:dstW; |
270 uint8_t *dst[3]= {dga_buffer, NULL, NULL}; | |
271 int dstStride[3]; | |
2504 | 272 if(verbose > 2) |
273 printf("vo_vesa: draw_slice was called: w=%u h=%u x=%u y=%u\n",w,h,x,y); | |
4537 | 274 dstStride[0]=dstride*((dstBpp+7)/8); |
275 dstStride[1]= | |
276 dstStride[2]=dstStride[0]>>1; | |
277 if(HAS_DGA()) dst[0] += y_offset*SCREEN_LINE_SIZE(PIXEL_SIZE())+x_offset*PIXEL_SIZE(); | |
4554 | 278 sws->swScale(sws,image,stride,y,h,dst,dstStride); |
2331 | 279 flip_trigger = 1; |
2298 | 280 return 0; |
2244 | 281 } |
282 | |
4572 | 283 /* Please comment it out if you want have OSD within movie */ |
6825
2cbf7d447bb2
Disable OSD outside movie, because it's not redrawn currently, user can use -vop expand to get osd outisde movie.
atmos4
parents:
6203
diff
changeset
|
284 /*#define OSD_OUTSIDE_MOVIE 1*/ |
4572 | 285 |
2649 | 286 static void draw_alpha_32(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) |
287 { | |
4537 | 288 unsigned int dstride=HAS_DGA()?video_mode_info.XResolution:dstW; |
4572 | 289 #ifndef OSD_OUTSIDE_MOVIE |
290 if(HAS_DGA()) | |
291 { | |
292 x0 += x_offset; | |
293 y0 += y_offset; | |
294 } | |
295 #endif | |
2649 | 296 vo_draw_alpha_rgb32(w,h,src,srca,stride,dga_buffer+4*(y0*dstride+x0),4*dstride); |
2337 | 297 } |
298 | |
2649 | 299 static void draw_alpha_24(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) |
300 { | |
4537 | 301 unsigned int dstride=HAS_DGA()?video_mode_info.XResolution:dstW; |
4572 | 302 #ifndef OSD_OUTSIDE_MOVIE |
303 if(HAS_DGA()) | |
304 { | |
305 x0 += x_offset; | |
306 y0 += y_offset; | |
307 } | |
308 #endif | |
2649 | 309 vo_draw_alpha_rgb24(w,h,src,srca,stride,dga_buffer+3*(y0*dstride+x0),3*dstride); |
2337 | 310 } |
311 | |
2649 | 312 static void draw_alpha_16(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) |
313 { | |
4537 | 314 unsigned int dstride=HAS_DGA()?video_mode_info.XResolution:dstW; |
4572 | 315 #ifndef OSD_OUTSIDE_MOVIE |
316 if(HAS_DGA()) | |
317 { | |
318 x0 += x_offset; | |
319 y0 += y_offset; | |
320 } | |
321 #endif | |
2649 | 322 vo_draw_alpha_rgb16(w,h,src,srca,stride,dga_buffer+2*(y0*dstride+x0),2*dstride); |
2337 | 323 } |
324 | |
2649 | 325 static void draw_alpha_15(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) |
326 { | |
4537 | 327 unsigned int dstride=HAS_DGA()?video_mode_info.XResolution:dstW; |
4572 | 328 #ifndef OSD_OUTSIDE_MOVIE |
329 if(HAS_DGA()) | |
330 { | |
331 x0 += x_offset; | |
332 y0 += y_offset; | |
333 } | |
334 #endif | |
2649 | 335 vo_draw_alpha_rgb15(w,h,src,srca,stride,dga_buffer+2*(y0*dstride+x0),2*dstride); |
2337 | 336 } |
337 | |
2649 | 338 static void draw_alpha_null(int x0,int y0, int w,int h, unsigned char* src, unsigned char *srca, int stride) |
339 { | |
2688 | 340 UNUSED(x0); |
341 UNUSED(y0); | |
342 UNUSED(w); | |
343 UNUSED(h); | |
344 UNUSED(src); | |
345 UNUSED(srca); | |
346 UNUSED(stride); | |
2337 | 347 } |
348 | |
349 | |
2244 | 350 static void draw_osd(void) |
351 { | |
2649 | 352 uint32_t w,h; |
2504 | 353 if(verbose > 2) |
354 printf("vo_vesa: draw_osd was called\n"); | |
2869 | 355 { |
4572 | 356 #ifdef OSD_OUTSIDE_MOVIE |
4537 | 357 w = HAS_DGA()?video_mode_info.XResolution:dstW; |
358 h = HAS_DGA()?video_mode_info.YResolution:dstH; | |
4572 | 359 #else |
360 w = dstW; | |
361 h = dstH; | |
362 #endif | |
2869 | 363 if(dga_buffer) vo_draw_text(w,h,draw_alpha_fnc); |
364 } | |
2244 | 365 } |
366 | |
367 static void flip_page(void) | |
368 { | |
2504 | 369 if(verbose > 2) |
370 printf("vo_vesa: flip_page was called\n"); | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
371 if(flip_trigger) |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
372 { |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
373 if(!HAS_DGA()) __vbeCopyData(dga_buffer); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
374 flip_trigger = 0; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
375 } |
4493 | 376 if(vo_doublebuffering && multi_size > 1) |
2649 | 377 { |
2686 | 378 int err; |
4667 | 379 if((err=vbeSetDisplayStart(multi_buff[multi_idx],vo_vsync)) != VBE_OK) |
2686 | 380 { |
381 vesa_term(); | |
2692 | 382 PRINT_VBE_ERR("vbeSetDisplayStart",err); |
2686 | 383 printf("vo_vesa: Fatal error occured! Can't continue\n"); |
384 exit(EXIT_FAILURE); | |
385 } | |
386 multi_idx = multi_idx ? 0 : 1; | |
387 win.ptr = dga_buffer = video_base + multi_buff[multi_idx]; | |
2649 | 388 } |
389 /* | |
390 else | |
391 if(tripple_buffering) | |
392 { | |
4667 | 393 vbeSetScheduledDisplayStart(multi_buff[multi_idx],vo_vsync); |
2649 | 394 multi_idx++; |
395 if(multi_idx > 2) multi_idx = 0; | |
4667 | 396 win.ptr = dga_buffer = video_base + multi_buff[multi_idx]; |
2649 | 397 } |
398 */ | |
2244 | 399 } |
400 | |
401 /* is called for rgb only */ | |
402 static uint32_t draw_frame(uint8_t *src[]) | |
403 { | |
2504 | 404 if(verbose > 2) |
405 printf("vo_vesa: draw_frame was called\n"); | |
4537 | 406 if(sws) |
2504 | 407 { |
4537 | 408 unsigned int dstride=HAS_DGA()?video_mode_info.XResolution:dstW; |
409 int srcStride[1]; | |
410 uint8_t *dst[3]= {dga_buffer, NULL, NULL}; | |
411 int dstStride[3]; | |
412 dstStride[0]=dstride*((dstBpp+7)/8); | |
413 dstStride[1]= | |
414 dstStride[2]=dstStride[0]>>1; | |
415 if(srcFourcc == IMGFMT_RGB32 || srcFourcc == IMGFMT_BGR32) | |
416 srcStride[0] = srcW*4; | |
417 else | |
418 if(srcFourcc == IMGFMT_RGB24 || srcFourcc == IMGFMT_BGR24) | |
419 srcStride[0] = srcW*3; | |
420 else | |
421 srcStride[0] = srcW*2; | |
422 if(HAS_DGA()) dst[0] += y_offset*SCREEN_LINE_SIZE(PIXEL_SIZE())+x_offset*PIXEL_SIZE(); | |
4554 | 423 sws->swScale(sws,src,srcStride,0,srcH,dst,dstStride); |
4537 | 424 flip_trigger=1; |
425 } | |
2504 | 426 return 0; |
2244 | 427 } |
428 | |
2953
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
429 #define SUBDEV_NODGA 0x00000001UL |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
430 #define SUBDEV_FORCEDGA 0x00000002UL |
4362 | 431 static uint32_t subdev_flags = 0xFFFFFFFEUL; |
2953
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
432 static uint32_t parseSubDevice(const char *sd) |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
433 { |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
434 uint32_t flags; |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
435 flags = 0; |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
436 if(strcmp(sd,"nodga") == 0) { flags |= SUBDEV_NODGA; flags &= ~(SUBDEV_FORCEDGA); } |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
437 else |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
438 if(strcmp(sd,"dga") == 0) { flags &= ~(SUBDEV_NODGA); flags |= SUBDEV_FORCEDGA; } |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
439 else |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
440 if(memcmp(sd,"lvo:",4) == 0) lvo_name = &sd[4]; /* lvo_name will be valid within init() */ |
4089 | 441 #ifdef CONFIG_VIDIX |
4030 | 442 else |
443 if(memcmp(sd,"vidix",5) == 0) vidix_name = &sd[5]; /* vidix_name will be valid within init() */ | |
4089 | 444 #endif |
4537 | 445 else { printf("vo_vesa: Unknown subdevice: '%s'\n", sd); return 0xFFFFFFFFUL; } |
2953
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
446 return flags; |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
447 } |
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
448 |
2244 | 449 static uint32_t query_format(uint32_t format) |
450 { | |
2504 | 451 if(verbose > 2) |
452 printf("vo_vesa: query_format was called: %x (%s)\n",format,vo_format_name(format)); | |
7690 | 453 return 1 | VFCAP_OSD | VFCAP_SWSCALE | VFCAP_ACCEPT_STRIDE; /* due new SwScale code */ |
2244 | 454 } |
455 | |
2686 | 456 static void paintBkGnd( void ) |
457 { | |
458 int x_res = video_mode_info.XResolution; | |
459 int y_res = video_mode_info.YResolution; | |
460 int x, y; | |
461 | |
462 for (y = 0; y < y_res; ++y) | |
463 { | |
464 for (x = 0; x < x_res; ++x) | |
465 { | |
466 int r, g, b; | |
467 if ((x & 16) ^ (y & 16)) | |
468 { | |
469 r = x * 255 / x_res; | |
470 g = y * 255 / y_res; | |
471 b = 255 - x * 255 / x_res; | |
472 } | |
473 else | |
474 { | |
475 r = 255 - x * 255 / x_res; | |
476 g = y * 255 / y_res; | |
477 b = 255 - y * 255 / y_res; | |
478 } | |
479 __vbeSetPixel(x, y, r, g, b); | |
480 } | |
481 } | |
482 } | |
483 | |
2914 | 484 static void clear_screen( void ) |
485 { | |
486 int x_res = video_mode_info.XResolution; | |
487 int y_res = video_mode_info.YResolution; | |
488 int x, y; | |
489 | |
490 for (y = 0; y < y_res; ++y) | |
491 for (x = 0; x < x_res; ++x) | |
492 __vbeSetPixel(x, y, 0, 0, 0); | |
493 } | |
494 | |
2293 | 495 static char *model2str(unsigned char type) |
496 { | |
497 char *retval; | |
498 switch(type) | |
499 { | |
500 case memText: retval = "Text"; break; | |
501 case memCGA: retval="CGA"; break; | |
502 case memHercules: retval="Hercules"; break; | |
503 case memPL: retval="Planar"; break; | |
504 case memPK: retval="Packed pixel"; break; | |
505 case mem256: retval="256"; break; | |
506 case memRGB: retval="Direct color RGB"; break; | |
507 case memYUV: retval="Direct color YUV"; break; | |
508 default: retval="Unknown"; break; | |
509 } | |
510 return retval; | |
511 } | |
512 | |
2649 | 513 unsigned fillMultiBuffer( unsigned long vsize, unsigned nbuffs ) |
514 { | |
515 unsigned long screen_size, offset; | |
516 unsigned total,i; | |
4537 | 517 screen_size = video_mode_info.XResolution*video_mode_info.YResolution*((dstBpp+7)/8); |
2649 | 518 if(screen_size%64) screen_size=((screen_size/64)*64)+64; |
519 total = vsize / screen_size; | |
2918 | 520 if(verbose) printf("vo_vesa: Can use up to %u video buffers\n",total); |
2649 | 521 i = 0; |
522 offset = 0; | |
523 total = min(total,nbuffs); | |
524 while(i < total) { multi_buff[i++] = offset; offset += screen_size; } | |
525 if(!i) | |
526 printf("vo_vesa: Your have too small size of video memory for this mode:\n" | |
527 "vo_vesa: Requires: %08lX exists: %08lX\n", screen_size, vsize); | |
528 return i; | |
529 } | |
530 | |
7360 | 531 |
7069 | 532 static int set_refresh(unsigned x, unsigned y, unsigned mode,struct VesaCRTCInfoBlock *crtc_pass) |
533 { | |
534 unsigned pixclk; | |
535 float H_freq; | |
536 | |
537 range_t *monitor_hfreq = NULL; | |
538 range_t *monitor_vfreq = NULL; | |
539 range_t *monitor_dotclock = NULL; | |
2649 | 540 |
7069 | 541 monitor_hfreq = str2range(monitor_hfreq_str); |
542 monitor_vfreq = str2range(monitor_vfreq_str); | |
543 monitor_dotclock = str2range(monitor_dotclock_str); | |
544 | |
545 if (!monitor_hfreq || !monitor_vfreq || !monitor_dotclock) { | |
546 printf("vo_vesa: you have to specify the capabilities of" | |
547 " the monitor. Not changing refresh rate.\n"); | |
548 return 0; | |
549 } | |
550 | |
551 H_freq = range_max(monitor_hfreq)/1000; | |
552 | |
553 // printf("H_freq MAX %f\n",H_freq); | |
554 | |
555 do | |
556 { | |
7360 | 557 H_freq -= 0.01; |
7069 | 558 GTF_calcTimings(x,y,H_freq,GTF_HF,0, 0,crtc_pass); |
559 // printf("PixelCLK %d\n",(unsigned)crtc_pass->PixelClock); | |
560 } | |
7360 | 561 while ( (!in_range(monitor_vfreq,crtc_pass->RefreshRate/100)|| |
562 !in_range(monitor_hfreq,H_freq*1000))&&(H_freq>0)); | |
7069 | 563 |
564 pixclk = crtc_pass->PixelClock; | |
565 // printf("PIXclk before %d\n",pixclk); | |
566 vbeGetPixelClock(&mode,&pixclk); | |
567 // printf("PIXclk after %d\n",pixclk); | |
568 GTF_calcTimings(x,y,pixclk/1000000,GTF_PF,0,0,crtc_pass); | |
569 // printf("Flags: %x\n",(unsigned) crtc_pass->Flags); | |
570 /* | |
571 printf("hTotal %d\n",crtc_pass->hTotal); | |
572 printf("hSyncStart %d\n",crtc_pass->hSyncStart); | |
573 printf("hSyncEnd %d\n",crtc_pass->hSyncEnd); | |
574 | |
575 printf("vTotal %d\n",crtc_pass->vTotal); | |
576 printf("vSyncStart %d\n",crtc_pass->vSyncStart); | |
577 printf("vSyncEnd %d\n",crtc_pass->vSyncEnd); | |
578 | |
579 printf("RR %d\n",crtc_pass->RefreshRate); | |
580 printf("PixelCLK %d\n",(unsigned)crtc_pass->PixelClock);*/ | |
7360 | 581 |
582 if (!in_range(monitor_vfreq,crtc_pass->RefreshRate/100)|| | |
583 !in_range(monitor_hfreq,H_freq*1000)) { | |
584 printf( "vo_vesa: Unable to fit the mode into monitor's limitation." | |
585 " Not changing refresh rate.\n"); | |
586 return 0; | |
587 } | |
588 | |
7069 | 589 return 1; |
590 } | |
7360 | 591 |
2244 | 592 /* fullscreen: |
593 * bit 0 (0x01) means fullscreen (-fs) | |
594 * bit 1 (0x02) means mode switching (-vm) | |
595 * bit 2 (0x04) enables software scaling (-zoom) | |
2335 | 596 * bit 3 (0x08) enables flipping (-flip) (NK: and for what?) |
2244 | 597 */ |
7069 | 598 |
2244 | 599 static uint32_t |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
7069
diff
changeset
|
600 config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) |
2244 | 601 { |
7069 | 602 struct VbeInfoBlock vib; |
2244 | 603 struct VesaModeInfoBlock vmib; |
7069 | 604 struct VesaCRTCInfoBlock crtc_pass; |
2244 | 605 size_t i,num_modes; |
4362 | 606 uint32_t w,h; |
2244 | 607 unsigned short *mode_ptr,win_seg; |
608 unsigned bpp,best_x = UINT_MAX,best_y=UINT_MAX,best_mode_idx = UINT_MAX; | |
4601
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
609 int err,fs_mode,use_scaler=0; |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
610 srcW = dstW = width; |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
611 srcH = dstH = height; |
2336 | 612 fs_mode = 0; |
4362 | 613 if(subdev_flags == 0xFFFFFFFEUL) |
2971 | 614 { |
4362 | 615 printf("vo_vesa: detected internal fatal error: init is called before preinit\n"); |
2971 | 616 return -1; |
4362 | 617 } |
4537 | 618 if(subdev_flags == 0xFFFFFFFFUL) return -1; |
2329 | 619 if(flags & 0x8) |
2244 | 620 { |
2329 | 621 printf("vo_vesa: switch -flip is not supported\n"); |
2244 | 622 } |
4537 | 623 if(flags & 0x04) use_scaler = 1; |
2336 | 624 if(flags & 0x01) |
625 { | |
4537 | 626 if(use_scaler) use_scaler = 2; |
2336 | 627 else fs_mode = 1; |
628 } | |
2244 | 629 if((err=vbeInit()) != VBE_OK) { PRINT_VBE_ERR("vbeInit",err); return -1; } |
630 memcpy(vib.VESASignature,"VBE2",4); | |
631 if((err=vbeGetControllerInfo(&vib)) != VBE_OK) | |
632 { | |
633 PRINT_VBE_ERR("vbeGetControllerInfo",err); | |
634 printf("vo_vesa: possible reason: No VBE2 BIOS found\n"); | |
635 return -1; | |
636 } | |
637 /* Print general info here */ | |
638 printf("vo_vesa: Found VESA VBE BIOS Version %x.%x Revision: %x\n", | |
639 (int)(vib.VESAVersion >> 8) & 0xff, | |
640 (int)(vib.VESAVersion & 0xff), | |
641 (int)(vib.OemSoftwareRev & 0xffff)); | |
2255 | 642 printf("vo_vesa: Video memory: %u Kb\n",vib.TotalMemory*64); |
643 printf("vo_vesa: VESA Capabilities: %s %s %s %s %s\n" | |
644 ,vib.Capabilities & VBE_DAC_8BIT ? "8-bit DAC," : "6-bit DAC," | |
645 ,vib.Capabilities & VBE_NONVGA_CRTC ? "non-VGA CRTC,":"VGA CRTC," | |
646 ,vib.Capabilities & VBE_SNOWED_RAMDAC ? "snowed RAMDAC,":"normal RAMDAC," | |
647 ,vib.Capabilities & VBE_STEREOSCOPIC ? "stereoscopic,":"no stereoscopic," | |
648 ,vib.Capabilities & VBE_STEREO_EVC ? "Stereo EVC":"no stereo"); | |
649 printf("vo_vesa: !!! Below will be printed OEM info. !!!\n"); | |
650 printf("vo_vesa: You should watch 5 OEM related lines below else you've broken vm86\n"); | |
2244 | 651 printf("vo_vesa: OEM info: %s\n",vib.OemStringPtr); |
2255 | 652 printf("vo_vesa: OEM Revision: %x\n",vib.OemSoftwareRev); |
653 printf("vo_vesa: OEM vendor: %s\n",vib.OemVendorNamePtr); | |
654 printf("vo_vesa: OEM Product Name: %s\n",vib.OemProductNamePtr); | |
655 printf("vo_vesa: OEM Product Rev: %s\n",vib.OemProductRevPtr); | |
656 printf("vo_vesa: Hint: To get workable TV-Out you should have plugged tv-connector in\n" | |
657 "vo_vesa: before booting PC since VESA BIOS initializes itself only during POST\n"); | |
2244 | 658 /* Find best mode here */ |
659 num_modes = 0; | |
660 mode_ptr = vib.VideoModePtr; | |
661 while(*mode_ptr++ != 0xffff) num_modes++; | |
662 switch(format) | |
663 { | |
664 case IMGFMT_BGR8: | |
665 case IMGFMT_RGB8: bpp = 8; break; | |
666 case IMGFMT_BGR15: | |
667 case IMGFMT_RGB15: bpp = 15; break; | |
668 case IMGFMT_BGR16: | |
669 case IMGFMT_RGB16: bpp = 16; break; | |
670 case IMGFMT_BGR24: | |
671 case IMGFMT_RGB24: bpp = 24; break; | |
672 case IMGFMT_BGR32: | |
673 case IMGFMT_RGB32: bpp = 32; break; | |
4601
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
674 default: bpp = 16; break; |
2244 | 675 } |
4537 | 676 srcBpp = bpp; |
677 srcFourcc = format; | |
2504 | 678 if(vo_dbpp) bpp = vo_dbpp; |
2337 | 679 switch(bpp) |
680 { | |
4537 | 681 case 15: draw_alpha_fnc = draw_alpha_15; |
682 dstFourcc = IMGFMT_BGR15; | |
683 break; | |
684 case 16: draw_alpha_fnc = draw_alpha_16; | |
685 dstFourcc = IMGFMT_BGR16; | |
686 break; | |
687 case 24: draw_alpha_fnc = draw_alpha_24; | |
688 dstFourcc = IMGFMT_BGR24; | |
689 break; | |
690 case 32: draw_alpha_fnc = draw_alpha_32; | |
691 dstFourcc = IMGFMT_BGR32; | |
692 break; | |
693 default: draw_alpha_fnc = draw_alpha_null; | |
694 dstFourcc = IMGFMT_BGR16; | |
695 break; | |
2337 | 696 } |
2244 | 697 if(verbose) |
698 { | |
2304 | 699 printf("vo_vesa: Requested mode: %ux%u@%u (%s)\n",width,height,bpp,vo_format_name(format)); |
2244 | 700 printf("vo_vesa: Total modes found: %u\n",num_modes); |
701 mode_ptr = vib.VideoModePtr; | |
702 printf("vo_vesa: Mode list:"); | |
703 for(i = 0;i < num_modes;i++) | |
704 { | |
705 printf(" %04X",mode_ptr[i]); | |
706 } | |
707 printf("\nvo_vesa: Modes in detail:\n"); | |
708 } | |
709 mode_ptr = vib.VideoModePtr; | |
4537 | 710 if(use_scaler) |
2335 | 711 { |
4537 | 712 dstW = d_width; |
4601
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
713 dstH = d_height; |
2335 | 714 } |
715 if(vo_screenwidth) w = vo_screenwidth; | |
4537 | 716 else w = max(dstW,width); |
2335 | 717 if(vo_screenheight) h = vo_screenheight; |
4537 | 718 else h = max(dstH,height); |
2244 | 719 for(i=0;i < num_modes;i++) |
720 { | |
721 if((err=vbeGetModeInfo(mode_ptr[i],&vmib)) != VBE_OK) | |
722 { | |
723 PRINT_VBE_ERR("vbeGetModeInfo",err); | |
724 return -1; | |
725 } | |
2329 | 726 if(vmib.XResolution >= w && |
727 vmib.YResolution >= h && | |
2244 | 728 (vmib.ModeAttributes & MOVIE_MODE) == MOVIE_MODE && |
729 vmib.BitsPerPixel == bpp && | |
730 vmib.MemoryModel == memRGB) | |
731 { | |
2293 | 732 if(vmib.XResolution <= best_x && |
733 vmib.YResolution <= best_y) | |
2244 | 734 { |
735 best_x = vmib.XResolution; | |
736 best_y = vmib.YResolution; | |
737 best_mode_idx = i; | |
738 } | |
739 } | |
740 if(verbose) | |
741 { | |
2298 | 742 printf("vo_vesa: Mode (%03u): mode=%04X %ux%u@%u attr=%04X\n" |
2293 | 743 "vo_vesa: #planes=%u model=%u(%s) #pages=%u\n" |
744 "vo_vesa: winA=%X(attr=%u) winB=%X(attr=%u) winSize=%u winGran=%u\n" | |
2446 | 745 "vo_vesa: direct_color=%u DGA_phys_addr=%08lX\n" |
2244 | 746 ,i,mode_ptr[i],vmib.XResolution,vmib.YResolution,vmib.BitsPerPixel,vmib.ModeAttributes |
2293 | 747 ,vmib.NumberOfPlanes,vmib.MemoryModel,model2str(vmib.MemoryModel),vmib.NumberOfImagePages |
2244 | 748 ,vmib.WinASegment,vmib.WinAAttributes,vmib.WinBSegment,vmib.WinBAttributes,vmib.WinSize,vmib.WinGranularity |
749 ,vmib.DirectColorModeInfo,vmib.PhysBasePtr); | |
750 if(vmib.MemoryModel == 6 || vmib.MemoryModel == 7) | |
751 printf("vo_vesa: direct_color_info = %u:%u:%u:%u\n" | |
752 ,vmib.RedMaskSize,vmib.GreenMaskSize,vmib.BlueMaskSize,vmib.RsvdMaskSize); | |
753 fflush(stdout); | |
754 } | |
755 } | |
756 if(best_mode_idx != UINT_MAX) | |
757 { | |
758 video_mode = vib.VideoModePtr[best_mode_idx]; | |
759 fflush(stdout); | |
760 if((err=vbeGetMode(&init_mode)) != VBE_OK) | |
761 { | |
762 PRINT_VBE_ERR("vbeGetMode",err); | |
763 return -1; | |
764 } | |
765 if(verbose) printf("vo_vesa: Initial video mode: %x\n",init_mode); | |
766 if((err=vbeGetModeInfo(video_mode,&video_mode_info)) != VBE_OK) | |
767 { | |
768 PRINT_VBE_ERR("vbeGetModeInfo",err); | |
769 return -1; | |
770 } | |
7025
3bc8ff93d64e
10l bug - noticed by Emiel Neggers <emiel@neggers.net>
arpi
parents:
6825
diff
changeset
|
771 dstBpp = video_mode_info.BitsPerPixel; |
2329 | 772 printf("vo_vesa: Using VESA mode (%u) = %x [%ux%u@%u]\n" |
773 ,best_mode_idx,video_mode,video_mode_info.XResolution | |
4537 | 774 ,video_mode_info.YResolution,dstBpp); |
4362 | 775 if(subdev_flags & SUBDEV_NODGA) video_mode_info.PhysBasePtr = 0; |
4601
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
776 if(use_scaler || fs_mode) |
2298 | 777 { |
2304 | 778 /* software scale */ |
4537 | 779 if(use_scaler > 1) |
2689 | 780 { |
781 aspect_save_orig(width,height); | |
782 aspect_save_prescale(d_width,d_height); | |
783 aspect_save_screenres(video_mode_info.XResolution,video_mode_info.YResolution); | |
4537 | 784 aspect(&dstW,&dstH,A_ZOOM); |
2689 | 785 } |
2336 | 786 else |
787 if(fs_mode) | |
788 { | |
4537 | 789 dstW = video_mode_info.XResolution; |
790 dstH = video_mode_info.YResolution; | |
2336 | 791 } |
4537 | 792 use_scaler = 1; |
4601
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
793 } |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
794 if(!lvo_name |
4089 | 795 #ifdef CONFIG_VIDIX |
4601
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
796 && !vidix_name |
4089 | 797 #endif |
4601
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
798 ) |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
799 { |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
800 sws = getSwsContextFromCmdLine(srcW,srcH,srcFourcc,dstW,dstH,dstFourcc); |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
801 if(!sws) |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
802 { |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
803 printf("vo_vesa: Can't initialize SwScaler\n"); |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
804 return -1; |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
805 } |
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
806 else if(verbose) printf("vo_vesa: Using SW BES emulator\n"); |
2298 | 807 } |
2244 | 808 if((video_mode_info.WinAAttributes & FRAME_MODE) == FRAME_MODE) |
809 win.idx = 0; /* frame A */ | |
810 else | |
811 if((video_mode_info.WinBAttributes & FRAME_MODE) == FRAME_MODE) | |
812 win.idx = 1; /* frame B */ | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
813 else win.idx = -2; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
814 /* Try use DGA instead */ |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
815 if(video_mode_info.PhysBasePtr && vib.TotalMemory && (video_mode_info.ModeAttributes & MODE_ATTR_LINEAR)) |
2244 | 816 { |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
817 void *lfb; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
818 unsigned long vsize; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
819 vsize = vib.TotalMemory*64*1024; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
820 lfb = vbeMapVideoBuffer(video_mode_info.PhysBasePtr,vsize); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
821 if(lfb == NULL) |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
822 printf("vo_vesa: Can't use DGA. Force bank switching mode. :(\n"); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
823 else |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
824 { |
2649 | 825 video_base = win.ptr = lfb; |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
826 win.low = 0UL; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
827 win.high = vsize; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
828 win.idx = -1; /* HAS_DGA() is on */ |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
829 video_mode |= VESA_MODE_USE_LINEAR; |
2649 | 830 printf("vo_vesa: Using DGA (physical resources: %08lXh, %08lXh)" |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
831 ,video_mode_info.PhysBasePtr |
2649 | 832 ,vsize); |
833 if(verbose) printf(" at %08lXh",(unsigned long)lfb); | |
834 printf("\n"); | |
835 if(!(multi_size = fillMultiBuffer(vsize,2))) return -1; | |
836 if(vo_doublebuffering && multi_size < 2) | |
837 printf("vo_vesa: Can't use double buffering: not enough video memory\n"); | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
838 } |
2244 | 839 } |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
840 if(win.idx == -2) |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
841 { |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
842 printf("vo_vesa: Can't find neither DGA nor relocatable window's frame.\n"); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
843 return -1; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
844 } |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
845 if(!HAS_DGA()) |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
846 { |
4362 | 847 if(subdev_flags & SUBDEV_FORCEDGA) |
2649 | 848 { |
849 printf("vo_vesa: you've forced DGA. Exiting\n"); | |
850 return -1; | |
851 } | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
852 if(!(win_seg = win.idx == 0 ? video_mode_info.WinASegment:video_mode_info.WinBSegment)) |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
853 { |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
854 printf("vo_vesa: Can't find valid window address\n"); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
855 return -1; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
856 } |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
857 win.ptr = PhysToVirtSO(win_seg,0); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
858 win.low = 0L; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
859 win.high= video_mode_info.WinSize*1024; |
2649 | 860 printf("vo_vesa: Using bank switching mode (physical resources: %08lXh, %08lXh)\n" |
861 ,(unsigned long)win.ptr,(unsigned long)win.high); | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
862 } |
4537 | 863 if(video_mode_info.XResolution > dstW) |
864 x_offset = (video_mode_info.XResolution - dstW) / 2; | |
2329 | 865 else x_offset = 0; |
4537 | 866 if(video_mode_info.YResolution > dstH) |
867 y_offset = (video_mode_info.YResolution - dstH) / 2; | |
2329 | 868 else y_offset = 0; |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
869 if(verbose) |
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
870 printf("vo_vesa: image: %ux%u screen = %ux%u x_offset = %u y_offset = %u\n" |
4537 | 871 ,dstW,dstH |
2305
82c17b134946
Fixed half-image bug and added computing of correct aspect during zooming
nick
parents:
2304
diff
changeset
|
872 ,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
|
873 ,x_offset,y_offset); |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
874 if(HAS_DGA()) |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
875 { |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
876 dga_buffer = win.ptr; /* Trickly ;) */ |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
877 cpy_blk_fnc = __vbeCopyBlockFast; |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
878 } |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
879 else |
2610 | 880 { |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
881 cpy_blk_fnc = __vbeCopyBlock; |
4601
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
882 if(!lvo_name |
4089 | 883 #ifdef CONFIG_VIDIX |
884 && !vidix_name | |
885 #endif | |
4601
8cda24d7f074
Make code simple. Use swScaler even for fastmemcpy purposes :)
nick
parents:
4596
diff
changeset
|
886 ) |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
887 { |
4537 | 888 if(!(dga_buffer = memalign(64,video_mode_info.XResolution*video_mode_info.YResolution*dstBpp))) |
2610 | 889 { |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
890 printf("vo_vesa: Can't allocate temporary buffer\n"); |
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
891 return -1; |
2610 | 892 } |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
893 if(verbose) printf("vo_vesa: dga emulator was allocated = %p\n",dga_buffer); |
2337 | 894 } |
2504 | 895 } |
2244 | 896 if((err=vbeSaveState(&init_state)) != VBE_OK) |
897 { | |
898 PRINT_VBE_ERR("vbeSaveState",err); | |
899 return -1; | |
900 } | |
7360 | 901 |
902 /* TODO: | |
903 user might pass refresh value, | |
7069 | 904 GTF constants might be read from monitor |
7360 | 905 for best results, I don't have a spec (RM) |
7069 | 906 */ |
7360 | 907 |
7069 | 908 if (((int)(vib.VESAVersion >> 8) & 0xff) > 2) { |
909 | |
7650
7e8193475ddf
a small fix for vo_vesa, when calling set_refresh, when -nofs used.
arpi
parents:
7360
diff
changeset
|
910 if (set_refresh(video_mode_info.XResolution,video_mode_info.YResolution,video_mode,&crtc_pass)) |
7069 | 911 video_mode = video_mode | 0x800; |
912 | |
913 } | |
914 | |
915 ; | |
916 | |
917 if ((err=vbeSetMode(video_mode,&crtc_pass)) != VBE_OK) | |
2244 | 918 { |
919 PRINT_VBE_ERR("vbeSetMode",err); | |
920 return -1; | |
921 } | |
7069 | 922 |
2244 | 923 /* Now we are in video mode!!!*/ |
2337 | 924 /* Below 'return -1' is impossible */ |
2244 | 925 if(verbose) |
926 { | |
927 printf("vo_vesa: Graphics mode was activated\n"); | |
928 fflush(stdout); | |
929 } | |
2869 | 930 if(lvo_name) |
931 { | |
4537 | 932 if(vlvo_init(width,height,x_offset,y_offset,dstW,dstH,format,dstBpp) != 0) |
2869 | 933 { |
934 printf("vo_vesa: Can't initialize Linux Video Overlay\n"); | |
2953
b0cf2b649d3c
Fixed incorretc terminating of lvo stuff and improving of query_format
nick
parents:
2918
diff
changeset
|
935 lvo_name = NULL; |
2869 | 936 vesa_term(); |
937 return -1; | |
938 } | |
939 else printf("vo_vesa: Using video overlay: %s\n",lvo_name); | |
940 } | |
4089 | 941 #ifdef CONFIG_VIDIX |
4030 | 942 else |
943 if(vidix_name) | |
944 { | |
4537 | 945 if(vidix_init(width,height,x_offset,y_offset,dstW, |
946 dstH,format,dstBpp, | |
7124
eca7dbad0166
finally removed query_vaa, bes_da and vo_tune_info - the obsoleted libvo api
alex
parents:
7069
diff
changeset
|
947 video_mode_info.XResolution,video_mode_info.YResolution) != 0) |
4030 | 948 { |
949 printf("vo_vesa: Can't initialize VIDIX driver\n"); | |
950 vidix_name = NULL; | |
4548 | 951 vesa_term(); |
4030 | 952 return -1; |
953 } | |
4083 | 954 else printf("vo_vesa: Using VIDIX\n"); |
4198
7e2bf04c9a7c
added vidix_start() and vidix_stop() for better runtime-resize support ;)
alex
parents:
4089
diff
changeset
|
955 vidix_start(); |
4030 | 956 } |
4089 | 957 #endif |
2244 | 958 } |
959 else | |
960 { | |
2255 | 961 printf("vo_vesa: Can't find mode for: %ux%u@%u\n",width,height,bpp); |
2244 | 962 return -1; |
963 } | |
964 if(verbose) | |
965 { | |
966 printf("vo_vesa: VESA initialization complete\n"); | |
967 fflush(stdout); | |
968 } | |
2688 | 969 if(HAS_DGA() && vo_doublebuffering) |
2244 | 970 { |
2686 | 971 for(i=0;i<MAX_BUFFERS;i++) |
972 { | |
973 win.ptr = dga_buffer = video_base + multi_buff[i]; | |
8652
edfe94b9d578
Juste a trivial patch for vesa output. The screen were cleaned at init
arpi
parents:
8148
diff
changeset
|
974 clear_screen(); /* Clear screen for stupid BIOSes */ |
4002 | 975 if(verbose>1) paintBkGnd(); |
2686 | 976 } |
2244 | 977 } |
2686 | 978 else |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
979 { |
8652
edfe94b9d578
Juste a trivial patch for vesa output. The screen were cleaned at init
arpi
parents:
8148
diff
changeset
|
980 clear_screen(); /* Clear screen for stupid BIOSes */ |
4002 | 981 if(verbose>1) paintBkGnd(); |
2686 | 982 { |
983 int x; | |
984 x = (video_mode_info.XResolution/video_mode_info.XCharSize)/2-strlen(title)/2; | |
985 if(x < 0) x = 0; | |
986 vbeWriteString(x,0,7,title); | |
987 } | |
2633
fe5ab8c660de
Qualitative speedup decoding when video card supports DGA!
nick
parents:
2610
diff
changeset
|
988 } |
2244 | 989 return 0; |
990 } | |
991 | |
992 static void | |
993 uninit(void) | |
994 { | |
8786
605c85c27e68
Not checking it caused SIGSEV when uninitning after vesa init failed.
filon
parents:
8652
diff
changeset
|
995 // not inited |
605c85c27e68
Not checking it caused SIGSEV when uninitning after vesa init failed.
filon
parents:
8652
diff
changeset
|
996 if (!init_state) return; |
2686 | 997 vesa_term(); |
2504 | 998 if(verbose > 2) |
999 printf("vo_vesa: uninit was called\n"); | |
2244 | 1000 } |
1001 | |
1002 | |
1003 static void check_events(void) | |
1004 { | |
2504 | 1005 if(verbose > 2) |
1006 printf("vo_vesa: check_events was called\n"); | |
2244 | 1007 /* Nothing to do */ |
1008 } | |
4352 | 1009 |
1010 static uint32_t preinit(const char *arg) | |
1011 { | |
4362 | 1012 int pre_init_err = 0; |
8791
668b30187d48
Check if we can open /dev/mem in preinit(), so we can exit cleanly.
filon
parents:
8786
diff
changeset
|
1013 int fd; |
4362 | 1014 if(verbose>1) printf("vo_vesa: preinit(%s) was called\n",arg); |
1015 if(verbose > 2) | |
1016 printf("vo_vesa: subdevice %s is being initialized\n",arg); | |
1017 subdev_flags = 0; | |
1018 if(arg) subdev_flags = parseSubDevice(arg); | |
1019 if(lvo_name) pre_init_err = vlvo_preinit(lvo_name); | |
1020 #ifdef CONFIG_VIDIX | |
1021 else if(vidix_name) pre_init_err = vidix_preinit(vidix_name,&video_out_vesa); | |
1022 #endif | |
8791
668b30187d48
Check if we can open /dev/mem in preinit(), so we can exit cleanly.
filon
parents:
8786
diff
changeset
|
1023 // check if we can open /dev/mem (it will be opened later in config(), but if we |
668b30187d48
Check if we can open /dev/mem in preinit(), so we can exit cleanly.
filon
parents:
8786
diff
changeset
|
1024 // detect now that we can't we can exit cleanly) |
668b30187d48
Check if we can open /dev/mem in preinit(), so we can exit cleanly.
filon
parents:
8786
diff
changeset
|
1025 fd = open("/dev/mem", O_RDWR); |
668b30187d48
Check if we can open /dev/mem in preinit(), so we can exit cleanly.
filon
parents:
8786
diff
changeset
|
1026 if (fd < 0) |
668b30187d48
Check if we can open /dev/mem in preinit(), so we can exit cleanly.
filon
parents:
8786
diff
changeset
|
1027 return -1; |
4362 | 1028 if(verbose > 2) |
1029 printf("vo_subdevice: initialization returns: %i\n",pre_init_err); | |
1030 return pre_init_err; | |
4352 | 1031 } |
1032 | |
4596 | 1033 static uint32_t control(uint32_t request, void *data, ...) |
4352 | 1034 { |
4592
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4572
diff
changeset
|
1035 switch (request) { |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4572
diff
changeset
|
1036 case VOCTRL_QUERY_FORMAT: |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4572
diff
changeset
|
1037 return query_format(*((uint32_t*)data)); |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4572
diff
changeset
|
1038 } |
5fbfd8545c3b
query_ stuff replaced by new control() - patch by David Holm
arpi
parents:
4572
diff
changeset
|
1039 return VO_NOTIMPL; |
4352 | 1040 } |