Change the default osd menu command for AR_MENU in comment of input.conf.
[mplayer/greg.git] / libvo / vo_svga.c
blobd8f8e393b53d57eb1831edf80568a8f1dd6c7505
1 /*
3 Video driver for SVGAlib
4 by Zoltan Mark Vician <se7en@sch.bme.hu>
5 Code started: Mon Apr 1 23:25:47 2001
6 Some changes by Matan Ziv-Av <matan@svgalib.org>
7 Compleat rewrite by Ivan Kalvachev 19 Mar 2003:
9 Wrangings:
10 - 1bpp doesn't work right for me with '-double' and svgalib 1.4.3,
11 but works OK with svgalib 1.9.17
12 - The HW acceleration is not tested - svgalibs supports few chipsets,
13 and i don't have any of them. If it works for you then let me know.
14 I will remove this warning after confirm its status.
15 - retrace sync works only in doublebuffer mode.
16 - the retrace sync may slow down decoding a lot - mplayer is blocked while
17 waiting for retrace
18 - denoise3d fails to find common colorspace, use -vf denoise3d,scale
20 TODO:
21 - let choose_best_mode take aspect into account
22 - set palette from mpi->palette or mpi->plane[1]
23 - make faster OSD black bars clear - need some OSD changes
24 - Make nicer CONFIG parsing
25 - change video mode logical width to match img->stride[0] - for HW only
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
32 #include <vga.h>
34 #include <limits.h>
36 #include "config.h"
37 #include "video_out.h"
38 #include "video_out_internal.h"
39 #include "fastmemcpy.h"
40 #include "osdep/getch2.h"
41 #ifdef CONFIG_VIDIX
42 #include "vosub_vidix.h"
43 #endif
45 #include "sub.h"
47 #include "mp_msg.h"
48 #include "help_mp.h"
49 //#include "mp_image.h"
51 #include <assert.h>
53 //silence warnings, probably it have to go in some global header
54 #define UNUSED(x) ((void)(x))
57 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
58 unsigned char *srca, int stride);
59 static uint32_t get_image(mp_image_t *mpi);
61 #define MAXPAGES 16
62 #define PAGE_EMPTY 0
63 #define PAGE_BUSY 1
65 #define CAP_ACCEL_CLEAR 8
66 #define CAP_ACCEL_PUTIMAGE 4
67 #define CAP_ACCEL_BACKGR 2
68 #define CAP_LINEAR 1
70 static uint8_t zerobuf[8192];//used when clear screen with vga_draw
72 static int squarepix;
73 static int force_vm=0;
74 static int force_native=0;
75 static int sync_flip=0;
76 static int blackbar_osd=0;
77 static int cpage,max_pages,old_page;
79 static vga_modeinfo * modeinfo;
80 static int mode_stride; //keep it in case of vga_setlogicalwidth
81 static int stride_granularity; //not yet used
82 static int mode_bpp;
83 static int mode_capabilities;
85 static int image_width,image_height; // used by OSD
86 static int x_pos, y_pos;
88 static struct {
89 int yoffset;//y position of the page
90 int doffset;//display start of the page
91 void * vbase;//memory start address of the page
92 int locks;
93 }PageStore[MAXPAGES];
95 static const vo_info_t info = {
96 "SVGAlib",
97 "svga",
98 "Ivan Kalvachev <iive@users.sf.net>",
102 #ifdef CONFIG_VIDIX
103 static char vidix_name[32] = "";
104 static vidix_grkey_t gr_key;
105 #endif
107 LIBVO_EXTERN(svga)
110 //return number of 1'st free page or -1 if no free one
111 static inline int page_find_free(void){
112 int i;
113 for(i=0;i<max_pages;i++)
114 if(PageStore[i].locks == PAGE_EMPTY) return i;
115 return -1;
118 static int preinit(const char *arg)
120 int i;
121 char s[64];
123 getch2_disable();
124 memset(zerobuf,0,sizeof(zerobuf));
125 force_vm=force_native=squarepix=0;
126 sync_flip=vo_vsync;
127 blackbar_osd=0;
129 if(arg)while(*arg) {
130 #ifdef CONFIG_VIDIX
131 if(memcmp(arg,"vidix",5)==0) {
132 i=6;
133 while(arg[i] && arg[i]!=':') i++;
134 strncpy(vidix_name, arg+6, i-6);
135 vidix_name[i-5]=0;
136 if(arg[i]==':')i++;
137 arg+=i;
138 vidix_preinit(vidix_name, &video_out_svga);
140 #endif
141 if(!strncmp(arg,"sq",2)) {
142 squarepix=1;
143 arg+=2;
144 if( *arg == ':' ) arg++;
147 if(!strncmp(arg,"native",6)) {
148 force_native=1;
149 arg+=6;
150 if( *arg == ':' ) arg++;
153 if(!strncmp(arg,"bbosd",5)) {
154 blackbar_osd=1;
155 arg+=5;
156 if( *arg == ':' ) arg++;
159 if(!strncmp(arg,"retrace",7)) {
160 sync_flip=1;
161 arg+=7;
162 if( *arg == ':' ) arg++;
165 if(*arg) {
166 i=0;
167 while(arg[i] && arg[i]!=':')i++;
168 if(i<64){
169 strncpy(s, arg, i);
170 s[i]=0;
172 force_vm=vga_getmodenumber(s);
173 if(force_vm>0) {
174 if( mp_msg_test(MSGT_VO,MSGL_V) ) mp_msg(MSGT_VO,MSGL_V, "vo_svga: Forcing mode %i\n",force_vm);
175 }else{
176 force_vm = 0;
179 arg+=i;
180 if(*arg==':')arg++;
184 vga_init();
185 return 0;
188 static void svga_clear_box(int x,int y,int w,int h){
189 uint8_t * rgbplane;
190 int i;
192 if (mode_capabilities&CAP_ACCEL_CLEAR){
193 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
194 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with HW acceleration\n",
195 x,y,w,h);
196 if(mode_capabilities&CAP_ACCEL_BACKGR)
197 vga_accel(ACCEL_SYNC);
198 vga_accel(ACCEL_SETFGCOLOR,0);//black
199 vga_accel(ACCEL_FILLBOX,x,y,w,h);
200 return;
202 if (mode_capabilities & CAP_LINEAR){
203 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
204 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with memset\n",x,y,w,h);
205 rgbplane=PageStore[0].vbase + (y*mode_stride) + (x*modeinfo->bytesperpixel);
206 for(i=0;i<h;i++){
207 //i'm afraid that memcpy is better optimized than memset;)
208 fast_memcpy(rgbplane,zerobuf,w*modeinfo->bytesperpixel);
209 // memset(rgbplane,0,w*modeinfo->bytesperpixel);
210 rgbplane+=mode_stride;
212 return;
214 //native
215 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
216 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with native draw \n",x,y,w,h);
217 if(modeinfo->bytesperpixel!=0) w*=modeinfo->bytesperpixel;
218 for(i=0;i<h;i++){
219 vga_drawscansegment(zerobuf,x,y+i,w);
223 static uint32_t svga_draw_image(mp_image_t *mpi){
224 int i,x,y,w,h;
225 int stride;
226 uint8_t *rgbplane, *base;
227 int bytesperline;
228 int page;
230 if(mpi->flags & MP_IMGFLAG_DIRECT){
231 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
232 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: drawing direct rendered surface\n");
233 cpage=(uint32_t)mpi->priv;
234 assert((cpage>=0)&&(cpage<max_pages));
235 return VO_TRUE; //it's already done
237 // if (mpi->flags&MP_IMGFLAGS_DRAWBACK)
238 // return VO_TRUE;//direct render method 2
240 //find a free page to draw into
241 //if there is no one then use the current one
242 page = page_find_free();
243 if(page>=0) cpage=page;
244 PageStore[cpage].locks=PAGE_BUSY;
246 // these variables are used in loops
247 x = mpi->x;
248 y = mpi->y;
249 w = mpi->w;
250 h = mpi->h;
251 stride = mpi->stride[0];
252 rgbplane = mpi->planes[0] + y*stride + (x*mpi->bpp)/8;
253 x+=x_pos;//center
254 y+=y_pos;
256 if(mpi->bpp >= 8){//for modes<8 use only native
257 if( (mode_capabilities&CAP_ACCEL_PUTIMAGE) && (x==0) && (w==mpi->width) &&
258 (stride == mode_stride) ){ //only monolite image can be accelerated
259 w=(stride*8)/mpi->bpp;//we transfer pixels in the stride so the source
260 //ACCELERATE
261 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
262 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using HW PutImage (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
263 if(mode_capabilities & CAP_ACCEL_BACKGR)
264 vga_accel(ACCEL_SYNC);
266 vga_accel(ACCEL_PUTIMAGE,x,y+PageStore[cpage].yoffset,w,h,rgbplane);
267 return VO_TRUE;
270 if( mode_capabilities&CAP_LINEAR){
271 //DIRECT
272 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
273 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using Direct memcpy (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
274 bytesperline=(w*mpi->bpp)/8;
275 base=PageStore[cpage].vbase + (y*mode_stride) + (x*mpi->bpp)/8;
277 for(i=0;i<h;i++){
278 mem2agpcpy(base,rgbplane,bytesperline);
279 base+=mode_stride;
280 rgbplane+=stride;
282 return VO_TRUE;
284 }//(modebpp>=8
287 //NATIVE
289 int length;
290 length=(w*mpi->bpp)/8;
291 //one byte per pixel! svgalib innovation
292 if(mpi->imgfmt==IMGFMT_RG4B || mpi->imgfmt==IMGFMT_BG4B) length=w;
294 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
295 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using Native vga_draw(x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
296 y+=PageStore[cpage].yoffset;//y position of the page beggining
297 for(i=0;i<h;i++){
298 vga_drawscansegment(rgbplane,x,y+i,length);
299 rgbplane+=stride;
302 return VO_TRUE;
305 static int bpp_from_vminfo(vga_modeinfo *vminfo){
306 switch(vminfo->colors){
307 case 2: return 1;
308 case 16: return 4;
309 case 256: return 8;
310 case 32768: return 15;
311 case 65536: return 16;
312 case 1<<24: return 8*vminfo->bytesperpixel;
314 return 0;
317 static int find_best_svga_mode(int req_w,int req_h, int req_bpp){
318 int badness,prev_badness;
319 int bestmode,lastmode;
320 int i;
321 vga_modeinfo *vminfo;
322 //int best aspect mode // best linear mode // best normal mode (no modeX)
324 prev_badness = 0;//take care of special case below
325 bestmode = 0; //0 is the TEXT mode
326 lastmode = vga_lastmodenumber();
327 for(i=1;i<=lastmode;i++){
328 vminfo = vga_getmodeinfo(i);
329 if( vminfo == NULL ) continue;
330 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
331 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: testing mode %d (%s)\n",i,vga_getmodename(i));
332 if( vga_hasmode(i) == 0 ) continue;
333 if( req_bpp != bpp_from_vminfo(vminfo) )continue;
334 if( (vminfo->width < req_w) || (vminfo->height < req_h) ) continue;
335 badness=(vminfo->width * vminfo->height) - (req_h * req_w);
336 //put here aspect calculations
337 if(squarepix)
338 if( vminfo->width*3 != vminfo->height*4 ) continue;
340 if( bestmode==0 || prev_badness >= badness ){//modeX etc...
341 prev_badness=badness;
342 bestmode=i;
343 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
344 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: found good mode %d with badness %d\n",i,badness);
347 return bestmode;
350 static int control(uint32_t request, void *data, ...)
352 switch (request) {
353 case VOCTRL_QUERY_FORMAT:
354 return query_format(*((uint32_t*)data));
355 case VOCTRL_DRAW_IMAGE:
356 return svga_draw_image( (mp_image_t *)data);
357 case VOCTRL_GET_IMAGE:
358 return get_image(data);
361 #ifdef CONFIG_VIDIX
362 if (vidix_name) {
363 switch (request) {
364 case VOCTRL_SET_EQUALIZER:
366 va_list ap;
367 int value;
369 va_start(ap, data);
370 value = va_arg(ap, int);
371 va_end(ap);
373 return vidix_control(request, data, value);
375 case VOCTRL_GET_EQUALIZER:
377 va_list ap;
378 int *value;
380 va_start(ap, data);
381 value = va_arg(ap, int*);
382 va_end(ap);
384 return vidix_control(request, data, value);
387 return vidix_control(request, data);
389 #endif
391 return VO_NOTIMPL;
395 // This function is called to init the video driver for specific mode
397 static int config(uint32_t width, uint32_t height, uint32_t d_width,
398 uint32_t d_height, uint32_t flags, char *title,
399 uint32_t format) {
400 int32_t req_w = width;// (d_width > 0 ? d_width : width);
401 int32_t req_h = height;// (d_height > 0 ? d_height : height);
402 uint16_t vid_mode = 0;
403 int32_t req_bpp;
405 uint32_t accflags;
406 if( mp_msg_test(MSGT_VO,MSGL_V) )
407 mp_msg(MSGT_VO,MSGL_V, "vo_svga: config(%i, %i, %i, %i, %08x, %s, %08x)\n", width, height,
408 d_width, d_height, flags, title, format);
409 //Only RGB modes supported
410 if (!IMGFMT_IS_RGB(format) && !IMGFMT_IS_BGR(format)) {assert(0);return -1;}
411 req_bpp = IMGFMT_BGR_DEPTH(format);
413 if( vo_dbpp!=0 && vo_dbpp!=req_bpp) {assert(0);return-1;}
415 if(!force_vm) {
416 if ( mp_msg_test(MSGT_VO,MSGL_V) ) {
417 mp_msg(MSGT_VO,MSGL_V, "vo_svga: Looking for the best resolution...\n");
418 mp_msg(MSGT_VO,MSGL_V, "vo_svga: req_w: %d, req_h: %d, bpp: %d\n",req_w,req_h,req_bpp);
420 vid_mode=find_best_svga_mode(req_w,req_h,req_bpp);
421 if(vid_mode==0)
422 return 1;
423 modeinfo=vga_getmodeinfo(vid_mode);
424 }else{//force_vm
425 vid_mode=force_vm;
426 if(vga_hasmode(vid_mode) == 0){
427 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeNotAvailable,
428 vid_mode,vga_getmodename(vid_mode));
429 return 1; //error;
431 modeinfo=vga_getmodeinfo(vid_mode);
432 if( (modeinfo->width < req_w) || (modeinfo->height < req_h) ){
433 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeTooSmall,
434 vid_mode,vga_getmodename(vid_mode));
435 return 1;
438 mode_bpp=bpp_from_vminfo(modeinfo);
440 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_Vidmode,
441 vid_mode,modeinfo->width,modeinfo->height,mode_bpp);
443 if (vga_setmode(vid_mode) == -1) {
444 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_VgasetmodeFailed,vid_mode);
445 uninit();
446 return 1; // error
448 /* set 332 palette for 8 bpp */
449 if(mode_bpp==8){
450 int i;
451 for(i=0; i<256; i++)
452 vga_setpalette(i, ((i>>5)&7)*9, ((i>>2)&7)*9, (i&3)*21);
454 /* set 121 palette for 4 bpp */
455 else if(mode_bpp==4){
456 int i;
457 for(i=0; i<16; i++)
458 vga_setpalette(i, ((i>>3)&1)*63, ((i>>1)&3)*21, (i&1)*63);
460 //if we change the logical width, we should know the granularity
461 stride_granularity=8;//according to man vga_logicalwidth
462 if(modeinfo->flags & EXT_INFO_AVAILABLE){
463 stride_granularity=modeinfo->linewidth_unit;
465 //look for hardware acceleration
466 mode_capabilities=0;//NATIVE;
467 if(!force_native){//if we want to use only native drawers
468 if(modeinfo->flags & HAVE_EXT_SET){//support for hwaccel interface
469 accflags=vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_ACCEL);
470 if(accflags & ACCELFLAG_FILLBOX) // clear screen
471 mode_capabilities|=CAP_ACCEL_CLEAR;
472 if(accflags & ACCELFLAG_PUTIMAGE)//support for mem->vid transfer
473 mode_capabilities|=CAP_ACCEL_PUTIMAGE;
474 if((accflags & ACCELFLAG_SETMODE) && (accflags & ACCELFLAG_SYNC)){
475 vga_accel(ACCEL_SETMODE,BLITS_IN_BACKGROUND);
476 mode_capabilities|=CAP_ACCEL_BACKGR;//can draw in backgraund
479 if(modeinfo->flags & IS_LINEAR){
480 mode_capabilities|=CAP_LINEAR; //don't use bank & vga_draw
482 else{
483 if(modeinfo->flags & CAPABLE_LINEAR){
484 int vid_mem_size;
485 vid_mem_size = vga_setlinearaddressing();
486 if(vid_mem_size != -1){
487 modeinfo=vga_getmodeinfo(vid_mode);//sometimes they change parameters
488 mode_capabilities|=CAP_LINEAR;
492 }//fi force native
493 if(mode_capabilities&CAP_LINEAR){
494 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeIsLinearAndMemcpyCouldBeUsed);
496 if(mode_capabilities&CAP_ACCEL_PUTIMAGE){
497 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeHasHardwareAcceleration);
498 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_IfItWorksForYouIWouldLikeToKnow);
501 //here is the place to handle strides for accel_ modes;
502 mode_stride=modeinfo->linewidth;
503 //we may try to set a bigger stride for video mode that will match the mpi->stride,
504 //this way we will transfer more data, but HW put_image can do it in backgraund!
506 //now let's see how many pages we can use
507 max_pages = modeinfo->maxpixels/(modeinfo->height * modeinfo->width);
508 if(max_pages > MAXPAGES) max_pages = MAXPAGES;
509 if(!vo_doublebuffering) max_pages=1;
510 //fill PageStore structs
512 int i;
513 uint8_t * GRAPH_MEM;
514 int dof;
515 GRAPH_MEM=vga_getgraphmem();
516 for(i=0;i<max_pages;i++){
517 //calculate display offset
518 dof = i * modeinfo->height * modeinfo->width;
519 if(modeinfo->bytesperpixel != 0) dof*=modeinfo->bytesperpixel;
520 //check video chip limitations
521 if( dof != (dof & modeinfo->startaddressrange) ){
522 max_pages=i;//page 0 will never come here
523 break;
525 PageStore[i].yoffset = i * modeinfo->height;//starting y offset
526 PageStore[i].vbase = GRAPH_MEM + i*modeinfo->height*mode_stride; //memory base address
527 PageStore[i].doffset = dof; //display offset
528 PageStore[i].locks = PAGE_EMPTY;
531 assert(max_pages>0);
532 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeHas,max_pages);
533 //15bpp
534 if(modeinfo->bytesperpixel!=0)
535 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * modeinfo->bytesperpixel);
536 else
537 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * mode_bpp / 8);
539 cpage=old_page=0;
540 svga_clear_box(0,0,modeinfo->width,modeinfo->height * max_pages);
542 image_height=req_h;
543 image_width=req_w;
544 x_pos = (modeinfo->width - req_w) / 2;
545 y_pos = (modeinfo->height - req_h) / 2;
546 x_pos &= ~(15); //align x offset position to 16 pixels
547 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_CenteringImageStartAt,x_pos,y_pos);
549 #ifdef CONFIG_VIDIX
551 if(vidix_name[0]){
552 vidix_init(width, height, x_pos, y_pos, modeinfo->width, modeinfo->height,
553 format, mode_bpp, modeinfo->width,modeinfo->height);
554 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_UsingVidix,width,height,
555 modeinfo->width,modeinfo->height);
556 vidix_start();
557 /*set colorkey*/
558 if(vidix_grkey_support()){
559 vidix_grkey_get(&gr_key);
560 gr_key.key_op = KEYS_PUT;
561 if (!(vo_colorkey & 0xFF000000)) {
562 gr_key.ckey.op = CKEY_TRUE;
563 gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
564 gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
565 gr_key.ckey.blue = vo_colorkey & 0x000000FF;
566 } else
567 gr_key.ckey.op = CKEY_FALSE;
568 vidix_grkey_set(&gr_key);
571 #endif
573 vga_setdisplaystart(0);
574 return (0);
577 static int draw_slice(uint8_t *image[],int stride[],
578 int w, int h, int x, int y) {
579 assert(0);
580 UNUSED(image);UNUSED(stride);
581 UNUSED(w);UNUSED(h);
582 UNUSED(x);UNUSED(y);
584 return VO_ERROR;//this is yv12 only -> vf_scale should do all transforms
587 static int draw_frame(uint8_t *src[]) {
588 assert(0);
589 UNUSED(src);
590 return VO_ERROR;//this one should not be called
593 static void draw_osd(void)
595 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
596 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: draw_osd()\n");
597 //only modes with bytesperpixel>0 can draw OSD
598 if(modeinfo->bytesperpixel==0) return;
599 if(!(mode_capabilities&CAP_LINEAR)) return;//force_native will remove OSD
601 if(blackbar_osd){
602 //111
603 //3 4
604 //222
605 svga_clear_box(0,0 + PageStore[cpage].yoffset,
606 modeinfo->width, y_pos);
607 svga_clear_box(0, image_height + y_pos + PageStore[cpage].yoffset,
608 modeinfo->width, modeinfo->height-(image_height+ y_pos));
609 svga_clear_box(0, y_pos + PageStore[cpage].yoffset,
610 x_pos, image_height);
611 svga_clear_box(image_width + x_pos, y_pos + PageStore[cpage].yoffset,
612 modeinfo->width-(x_pos+image_width), image_height);
613 // vo_remove_text(modeinfo->width, modeinfo->height, clear_alpha);
614 vo_draw_text(modeinfo->width, modeinfo->height, draw_alpha);
615 }else{
616 vo_draw_text(image_width, image_height, draw_alpha);
620 static void flip_page(void) {
621 PageStore[old_page].locks=PAGE_EMPTY;
622 PageStore[cpage].locks=PAGE_BUSY;
624 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
625 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: viewing page %d\n",cpage);
626 if(sync_flip && old_page!=cpage){
627 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga:vga_waitretrace\n");
628 vga_waitretrace();
630 vga_setdisplaystart(PageStore[cpage].doffset);
632 old_page=cpage;//cpage will be overwriten on next draw_image
635 static void check_events(void) {
638 static void uninit(void) {
640 #ifdef CONFIG_VIDIX
641 if(vidix_name[0])vidix_term();
642 #endif
643 vga_setmode(TEXT);
646 /* --------------------------------------------------------------------- */
647 static int query_format(uint32_t format) {
648 int32_t req_bpp,flags;
649 int i,lastmode;
650 vga_modeinfo * vminfo;
652 if ( mp_msg_test(MSGT_VO,MSGL_DBG4) )
653 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: query_format=%X \n",format);
654 //only RGB modes supported
655 if( (!IMGFMT_IS_RGB(format)) && (!IMGFMT_IS_BGR(format)) ) return 0;
657 // Reject different endian
658 #ifdef WORDS_BIGENDIAN
659 if (IMGFMT_IS_BGR(format)) return 0;
660 #else
661 if (IMGFMT_IS_RGB(format)) return 0;
662 #endif
664 //svgalib supports only BG4B! if we want BGR4 we have to emulate it (sw)
665 if( format==IMGFMT_BGR4 || format==IMGFMT_RGB4) return 0;
666 req_bpp = IMGFMT_RGB_DEPTH(format);
667 if( vo_dbpp>0 && vo_dbpp!=req_bpp ) return 0; //support -bpp options
668 //scan all modes
669 lastmode = vga_lastmodenumber();
670 for(i=1;i<=lastmode;i++){
671 vminfo = vga_getmodeinfo(i);
672 if( vminfo == NULL ) continue;
673 if( vga_hasmode(i) == 0 ) continue;
674 if( req_bpp != bpp_from_vminfo(vminfo) ) continue;
675 if( (force_vm > 0) && (force_vm != i) ) continue;//quick hack
676 flags = VFCAP_CSP_SUPPORTED|
677 VFCAP_CSP_SUPPORTED_BY_HW|
678 VFCAP_ACCEPT_STRIDE|
680 if(req_bpp>8) flags|=VFCAP_OSD;
681 return flags;
683 return 0;
686 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
687 unsigned char *srca, int stride) {
688 char* base;
690 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
691 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: draw_alpha(x0=%d,y0=%d,w=%d,h=%d,src=%p,srca=%p,stride=%d\n",
692 x0,y0,w,h,src,srca,stride);
693 if(!blackbar_osd) {
694 //drawing in the image, so place the stuff there
695 x0+=x_pos;
696 y0+=y_pos;
699 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
700 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: OSD draw in page %d\n",cpage);
701 base=PageStore[cpage].vbase + y0*mode_stride + x0*modeinfo->bytesperpixel;
702 switch (mode_bpp) {
703 case 32:
704 vo_draw_alpha_rgb32(w, h, src, srca, stride, base, mode_stride);
705 break;
706 case 24:
707 vo_draw_alpha_rgb24(w, h, src, srca, stride, base, mode_stride);
708 break;
709 case 16:
710 vo_draw_alpha_rgb16(w, h, src, srca, stride, base, mode_stride);
711 break;
712 case 15:
713 vo_draw_alpha_rgb15(w, h, src, srca, stride, base, mode_stride);
714 break;
718 static uint32_t get_image(mp_image_t *mpi){
719 int page;
721 if(!IMGFMT_IS_BGR(mpi->imgfmt) && !IMGFMT_IS_RGB(mpi->imgfmt) ){
722 assert(0);//should never happen
723 return(VO_FALSE);
726 if (
727 ( (mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) ||
728 (mpi->flags & MP_IMGFLAG_PLANAR) ||
729 (mpi->flags & MP_IMGFLAG_YUV)
731 return(VO_FALSE);
733 //reading from video memory is horribly slow
734 if( !(mpi->flags & MP_IMGFLAG_READABLE) && vo_directrendering &&
735 (mode_capabilities & CAP_LINEAR) ){
737 //find free page and reserve it
738 page=page_find_free();
739 if(page >= 0){
740 PageStore[page].locks=PAGE_BUSY;
742 mpi->flags |= MP_IMGFLAG_DIRECT;
743 mpi->stride[0] = mode_stride;
744 mpi->planes[0] = PageStore[page].vbase +
745 y_pos*mode_stride + (x_pos*mpi->bpp)/8;
746 mpi->priv=(void *)page;
747 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
748 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: direct render allocated! page=%d\n",page);
749 return(VO_TRUE);
753 return(VO_FALSE);