10l initial patch by Oded Shimon <ods15 at ods15.dyndns.org>
[mplayer/greg.git] / libvo / vo_svga.c
blob62fd1b87805eb4060d2ef13cda44bfbfe17723b1
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 "mp_image.h"
50 #include <assert.h>
52 //silence warnings, probably it have to go in some global header
53 #define UNUSED(x) ((void)(x))
55 extern int vo_doublebuffering;
56 extern int vo_directrendering;
57 extern int vo_dbpp;
58 extern int verbose;
60 static uint32_t query_format(uint32_t format);
61 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
62 unsigned char *srca, int stride);
63 static uint32_t get_image(mp_image_t *mpi);
65 #define MAXPAGES 16
66 #define PAGE_EMPTY 0
67 #define PAGE_BUSY 1
69 #define CAP_ACCEL_CLEAR 8
70 #define CAP_ACCEL_PUTIMAGE 4
71 #define CAP_ACCEL_BACKGR 2
72 #define CAP_LINEAR 1
74 static uint8_t zerobuf[8192];//used when clear screen with vga_draw
76 static int squarepix;
77 static int force_vm=0;
78 static int force_native=0;
79 static int sync_flip=0;
80 static int blackbar_osd=0;
81 static int cpage,max_pages,old_page;
83 static vga_modeinfo * modeinfo;
84 static int mode_stride; //keep it in case of vga_setlogicalwidth
85 static int stride_granularity; //not yet used
86 static int mode_bpp;
87 static int mode_capabilities;
89 static int image_width,image_height; // used by OSD
90 static int x_pos, y_pos;
92 static struct {
93 int yoffset;//y position of the page
94 int doffset;//display start of the page
95 void * vbase;//memory start address of the page
96 int locks;
97 }PageStore[MAXPAGES];
99 static vo_info_t info = {
100 "SVGAlib",
101 "svga",
102 "Ivan Kalvachev <iive@users.sf.net>",
106 #ifdef CONFIG_VIDIX
107 static char vidix_name[32] = "";
108 static vidix_grkey_t gr_key;
109 #endif
111 LIBVO_EXTERN(svga)
114 //return number of 1'st free page or -1 if no free one
115 static inline int page_find_free(){
116 int i;
117 for(i=0;i<max_pages;i++)
118 if(PageStore[i].locks == PAGE_EMPTY) return i;
119 return -1;
122 static uint32_t preinit(const char *arg)
124 int i;
125 char s[64];
127 getch2_disable();
128 memset(zerobuf,0,sizeof(zerobuf));
129 force_vm=force_native=squarepix=0;
130 sync_flip=vo_vsync;
131 blackbar_osd=0;
133 if(arg)while(*arg) {
134 #ifdef CONFIG_VIDIX
135 if(memcmp(arg,"vidix",5)==0) {
136 i=6;
137 while(arg[i] && arg[i]!=':') i++;
138 strncpy(vidix_name, arg+6, i-6);
139 vidix_name[i-5]=0;
140 if(arg[i]==':')i++;
141 arg+=i;
142 vidix_preinit(vidix_name, &video_out_svga);
144 #endif
145 if(!strncmp(arg,"sq",2)) {
146 squarepix=1;
147 arg+=2;
148 if( *arg == ':' ) arg++;
151 if(!strncmp(arg,"native",6)) {
152 force_native=1;
153 arg+=6;
154 if( *arg == ':' ) arg++;
157 if(!strncmp(arg,"bbosd",5)) {
158 blackbar_osd=1;
159 arg+=5;
160 if( *arg == ':' ) arg++;
163 if(!strncmp(arg,"retrace",7)) {
164 sync_flip=1;
165 arg+=7;
166 if( *arg == ':' ) arg++;
169 if(*arg) {
170 i=0;
171 while(arg[i] && arg[i]!=':')i++;
172 if(i<64){
173 strncpy(s, arg, i);
174 s[i]=0;
176 force_vm=vga_getmodenumber(s);
177 if(force_vm>0) {
178 if(verbose) printf("vo_svga: Forcing mode %i\n",force_vm);
179 }else{
180 force_vm = 0;
183 arg+=i;
184 if(*arg==':')arg++;
188 vga_init();
189 return 0;
192 static void svga_clear_box(int x,int y,int w,int h){
193 uint8_t * rgbplane;
194 int i;
196 if (mode_capabilities&CAP_ACCEL_CLEAR){
197 if(verbose > 2)
198 printf("vo_svga: clearing box %d,%d - %d,%d with HW acceleration\n",
199 x,y,w,h);
200 if(mode_capabilities&CAP_ACCEL_BACKGR)
201 vga_accel(ACCEL_SYNC);
202 vga_accel(ACCEL_SETFGCOLOR,0);//black
203 vga_accel(ACCEL_FILLBOX,x,y,w,h);
204 return;
206 if (mode_capabilities & CAP_LINEAR){
207 if(verbose > 2)
208 printf("vo_svga: clearing box %d,%d - %d,%d with memset\n",x,y,w,h);
209 rgbplane=PageStore[0].vbase + (y*mode_stride) + (x*modeinfo->bytesperpixel);
210 for(i=0;i<h;i++){
211 //i'm afraid that memcpy is better optimized than memset;)
212 memcpy(rgbplane,zerobuf,w*modeinfo->bytesperpixel);
213 // memset(rgbplane,0,w*modeinfo->bytesperpixel);
214 rgbplane+=mode_stride;
216 return;
218 //native
219 if(verbose > 2)
220 printf("vo_svga: clearing box %d,%d - %d,%d with native draw \n",x,y,w,h);
221 if(modeinfo->bytesperpixel!=0) w*=modeinfo->bytesperpixel;
222 for(i=0;i<h;i++){
223 vga_drawscansegment(zerobuf,x,y+i,w);
227 static uint32_t svga_draw_image(mp_image_t *mpi){
228 int i,x,y,w,h;
229 int stride;
230 uint8_t *rgbplane, *base;
231 int bytesperline;
232 int page;
234 if(mpi->flags & MP_IMGFLAG_DIRECT){
235 if(verbose > 2)
236 printf("vo_svga: drawing direct rendered surface\n");
237 cpage=(uint32_t)mpi->priv;
238 assert((cpage>=0)&&(cpage<max_pages));
239 return VO_TRUE; //it's already done
241 // if (mpi->flags&MP_IMGFLAGS_DRAWBACK)
242 // return VO_TRUE;//direct render method 2
244 //find a free page to draw into
245 //if there is no one then use the current one
246 page = page_find_free();
247 if(page>=0) cpage=page;
248 PageStore[cpage].locks=PAGE_BUSY;
250 // these variables are used in loops
251 x = mpi->x;
252 y = mpi->y;
253 w = mpi->w;
254 h = mpi->h;
255 stride = mpi->stride[0];
256 rgbplane = mpi->planes[0] + y*stride + (x*mpi->bpp)/8;
257 x+=x_pos;//center
258 y+=y_pos;
260 if(mpi->bpp >= 8){//for modes<8 use only native
261 if( (mode_capabilities&CAP_ACCEL_PUTIMAGE) && (x==0) && (w==mpi->width) &&
262 (stride == mode_stride) ){ //only monolite image can be accelerated
263 w=(stride*8)/mpi->bpp;//we transfer pixels in the stride so the source
264 //ACCELERATE
265 if(verbose>2)
266 printf("vo_svga: using HW PutImage (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
267 if(mode_capabilities & CAP_ACCEL_BACKGR)
268 vga_accel(ACCEL_SYNC);
270 vga_accel(ACCEL_PUTIMAGE,x,y+PageStore[cpage].yoffset,w,h,rgbplane);
271 return VO_TRUE;
274 if( mode_capabilities&CAP_LINEAR){
275 //DIRECT
276 if(verbose>2)
277 printf("vo_svga: using Direct memcpy (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
278 bytesperline=(w*mpi->bpp)/8;
279 base=PageStore[cpage].vbase + (y*mode_stride) + (x*mpi->bpp)/8;
281 for(i=0;i<h;i++){
282 mem2agpcpy(base,rgbplane,bytesperline);
283 base+=mode_stride;
284 rgbplane+=stride;
286 return VO_TRUE;
288 }//(modebpp>=8
291 //NATIVE
293 int length;
294 length=(w*mpi->bpp)/8;
295 //one byte per pixel! svgalib innovation
296 if(mpi->imgfmt==IMGFMT_RG4B || mpi->imgfmt==IMGFMT_BG4B) length=w;
298 if(verbose>2)
299 printf("vo_svga: using Native vga_draw(x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
300 y+=PageStore[cpage].yoffset;//y position of the page beggining
301 for(i=0;i<h;i++){
302 vga_drawscansegment(rgbplane,x,y+i,length);
303 rgbplane+=stride;
306 return VO_TRUE;
309 int bpp_from_vminfo(vga_modeinfo *vminfo){
310 switch(vminfo->colors){
311 case 2: return 1;
312 case 16: return 4;
313 case 256: return 8;
314 case 32768: return 15;
315 case 65536: return 16;
316 case 1<<24: return 8*vminfo->bytesperpixel;
318 return 0;
321 int find_best_svga_mode(int req_w,int req_h, int req_bpp){
322 int badness,prev_badness;
323 int bestmode,lastmode;
324 int i;
325 vga_modeinfo *vminfo;
326 //int best aspect mode // best linear mode // best normal mode (no modeX)
328 prev_badness = 0;//take care of special case below
329 bestmode = 0; //0 is the TEXT mode
330 lastmode = vga_lastmodenumber();
331 for(i=1;i<=lastmode;i++){
332 vminfo = vga_getmodeinfo(i);
333 if( vminfo == NULL ) continue;
334 if(verbose>3)
335 printf("vo_svga: testing mode %d (%s)\n",i,vga_getmodename(i));
336 if( vga_hasmode(i) == 0 ) continue;
337 if( req_bpp != bpp_from_vminfo(vminfo) )continue;
338 if( (vminfo->width < req_w) || (vminfo->height < req_h) ) continue;
339 badness=(vminfo->width * vminfo->height) - (req_h * req_w);
340 //put here aspect calculations
341 if(squarepix)
342 if( vminfo->width*3 != vminfo->height*4 ) continue;
344 if( bestmode==0 || prev_badness >= badness ){//modeX etc...
345 prev_badness=badness;
346 bestmode=i;
347 if(verbose>3)
348 printf("vo_svga: found good mode %d with badness %d\n",i,badness);
351 return bestmode;
354 static uint32_t control(uint32_t request, void *data, ...)
356 switch (request) {
357 case VOCTRL_QUERY_FORMAT:
358 return query_format(*((uint32_t*)data));
359 case VOCTRL_DRAW_IMAGE:
360 return svga_draw_image( (mp_image_t *)data);
361 case VOCTRL_GET_IMAGE:
362 return get_image(data);
365 #ifdef CONFIG_VIDIX
366 if (vidix_name) {
367 switch (request) {
368 case VOCTRL_SET_EQUALIZER:
370 va_list ap;
371 int value;
373 va_start(ap, data);
374 value = va_arg(ap, int);
375 va_end(ap);
377 return vidix_control(request, data, (int *)value);
379 case VOCTRL_GET_EQUALIZER:
381 va_list ap;
382 int *value;
384 va_start(ap, data);
385 value = va_arg(ap, int*);
386 va_end(ap);
388 return vidix_control(request, data, value);
391 return vidix_control(request, data);
393 #endif
395 return VO_NOTIMPL;
399 // This function is called to init the video driver for specific mode
401 static uint32_t config(uint32_t width, uint32_t height, uint32_t d_width,
402 uint32_t d_height, uint32_t flags, char *title,
403 uint32_t format) {
404 int32_t req_w = width;// (d_width > 0 ? d_width : width);
405 int32_t req_h = height;// (d_height > 0 ? d_height : height);
406 uint16_t vid_mode = 0;
407 int32_t req_bpp;
409 uint32_t accflags;
410 if(verbose)
411 printf("vo_svga: config(%i, %i, %i, %i, %08x, %s, %08x)\n", width, height,
412 d_width, d_height, flags, title, format);
413 //Only RGB modes supported
414 if (!IMGFMT_IS_RGB(format) && !IMGFMT_IS_BGR(format)) {assert(0);return -1;}
415 req_bpp = IMGFMT_BGR_DEPTH(format);
417 if( vo_dbpp!=0 && vo_dbpp!=req_bpp) {assert(0);return-1;}
419 if(!force_vm) {
420 if (verbose) {
421 printf("vo_svga: Looking for the best resolution...\n");
422 printf("vo_svga: req_w: %d, req_h: %d, bpp: %d\n",req_w,req_h,req_bpp);
424 vid_mode=find_best_svga_mode(req_w,req_h,req_bpp);
425 if(vid_mode==0)
426 return 1;
427 modeinfo=vga_getmodeinfo(vid_mode);
428 }else{//force_vm
429 vid_mode=force_vm;
430 if(vga_hasmode(vid_mode) == 0){
431 printf("vo_svga: forced vid_mode %d (%s) not available\n",
432 vid_mode,vga_getmodename(vid_mode));
433 return 1; //error;
435 modeinfo=vga_getmodeinfo(vid_mode);
436 if( (modeinfo->width < req_w) || (modeinfo->height < req_h) ){
437 printf("vo_svga: forced vid_mode %d (%s) too small\n",
438 vid_mode,vga_getmodename(vid_mode));
439 return 1;
442 mode_bpp=bpp_from_vminfo(modeinfo);
444 printf("vo_svga: vid_mode: %d, %dx%d %dbpp\n",
445 vid_mode,modeinfo->width,modeinfo->height,mode_bpp);
447 if (vga_setmode(vid_mode) == -1) {
448 printf("vo_svga: vga_setmode(%d) failed.\n",vid_mode);
449 uninit();
450 return 1; // error
452 /* set 332 palette for 8 bpp */
453 if(mode_bpp==8){
454 int i;
455 for(i=0; i<256; i++)
456 vga_setpalette(i, ((i>>5)&7)*9, ((i>>2)&7)*9, (i&3)*21);
458 /* set 121 palette for 4 bpp */
459 else if(mode_bpp==4){
460 int i;
461 for(i=0; i<16; i++)
462 vga_setpalette(i, ((i>>3)&1)*63, ((i>>1)&3)*21, (i&1)*63);
464 //if we change the logical width, we should know the granularity
465 stride_granularity=8;//according to man vga_logicalwidth
466 if(modeinfo->flags & EXT_INFO_AVAILABLE){
467 stride_granularity=modeinfo->linewidth_unit;
469 //look for hardware acceleration
470 mode_capabilities=0;//NATIVE;
471 if(!force_native){//if we want to use only native drawers
472 if(modeinfo->flags & HAVE_EXT_SET){//support for hwaccel interface
473 accflags=vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_ACCEL);
474 if(accflags & ACCELFLAG_FILLBOX) // clear screen
475 mode_capabilities|=CAP_ACCEL_CLEAR;
476 if(accflags & ACCELFLAG_PUTIMAGE)//support for mem->vid transfer
477 mode_capabilities|=CAP_ACCEL_PUTIMAGE;
478 if((accflags & ACCELFLAG_SETMODE) && (accflags & ACCELFLAG_SYNC)){
479 vga_accel(ACCEL_SETMODE,BLITS_IN_BACKGROUND);
480 mode_capabilities|=CAP_ACCEL_BACKGR;//can draw in backgraund
483 if(modeinfo->flags & IS_LINEAR){
484 mode_capabilities|=CAP_LINEAR; //don't use bank & vga_draw
486 else{
487 if(modeinfo->flags & CAPABLE_LINEAR){
488 int vid_mem_size;
489 vid_mem_size = vga_setlinearaddressing();
490 if(vid_mem_size != -1){
491 modeinfo=vga_getmodeinfo(vid_mode);//sometimes they change parameters
492 mode_capabilities|=CAP_LINEAR;
496 }//fi force native
497 if(mode_capabilities&CAP_LINEAR){
498 printf("vo_svga: video mode is linear and memcpy could be used for image transfer\n");
500 if(mode_capabilities&CAP_ACCEL_PUTIMAGE){
501 printf("vo_svga: video mode have hardware acceleration and put_image could be used\n");
502 printf("vo_svga: If it works for you i would like to know \nvo_svga: (send log with `mplayer test.avi -v -v -v -v &> svga.log`). Thx\n");
505 //here is the place to handle strides for accel_ modes;
506 mode_stride=modeinfo->linewidth;
507 //we may try to set a bigger stride for video mode that will match the mpi->stride,
508 //this way we will transfer more data, but HW put_image can do it in backgraund!
510 //now let's see how many pages we can use
511 max_pages = modeinfo->maxpixels/(modeinfo->height * modeinfo->width);
512 if(max_pages > MAXPAGES) max_pages = MAXPAGES;
513 if(!vo_doublebuffering) max_pages=1;
514 //fill PageStore structs
516 int i;
517 uint8_t * GRAPH_MEM;
518 int dof;
519 GRAPH_MEM=vga_getgraphmem();
520 for(i=0;i<max_pages;i++){
521 //calculate display offset
522 dof = i * modeinfo->height * modeinfo->width;
523 if(modeinfo->bytesperpixel != 0) dof*=modeinfo->bytesperpixel;
524 //check video chip limitations
525 if( dof != (dof & modeinfo->startaddressrange) ){
526 max_pages=i;//page 0 will never come here
527 break;
529 PageStore[i].yoffset = i * modeinfo->height;//starting y offset
530 PageStore[i].vbase = GRAPH_MEM + i*modeinfo->height*mode_stride; //memory base address
531 PageStore[i].doffset = dof; //display offset
532 PageStore[i].locks = PAGE_EMPTY;
535 assert(max_pages>0);
536 printf("vo_svga: video mode have %d page(s)\n",max_pages);
537 //15bpp
538 if(modeinfo->bytesperpixel!=0)
539 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * modeinfo->bytesperpixel);
540 else
541 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * mode_bpp / 8);
543 cpage=old_page=0;
544 svga_clear_box(0,0,modeinfo->width,modeinfo->height * max_pages);
546 image_height=req_h;
547 image_width=req_w;
548 x_pos = (modeinfo->width - req_w) / 2;
549 y_pos = (modeinfo->height - req_h) / 2;
550 x_pos &= ~(15); //align x offset position to 16 pixels
551 printf("vo_svga: centering image. start at (%d,%d)\n",x_pos,y_pos);
553 #ifdef CONFIG_VIDIX
555 if(vidix_name[0]){
556 vidix_init(width, height, x_pos, y_pos, modeinfo->width, modeinfo->height,
557 format, mode_bpp, modeinfo->width,modeinfo->height);
558 printf("vo_svga: Using VIDIX. w=%i h=%i mw=%i mh=%i\n",width,height,
559 modeinfo->width,modeinfo->height);
560 vidix_start();
561 /*set colorkey*/
562 if(vidix_grkey_support()){
563 vidix_grkey_get(&gr_key);
564 gr_key.key_op = KEYS_PUT;
565 if (!(vo_colorkey & 0xFF000000)) {
566 gr_key.ckey.op = CKEY_TRUE;
567 gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
568 gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
569 gr_key.ckey.blue = vo_colorkey & 0x000000FF;
570 } else
571 gr_key.ckey.op = CKEY_FALSE;
572 vidix_grkey_set(&gr_key);
575 #endif
577 vga_setdisplaystart(0);
578 return (0);
581 static uint32_t draw_slice(uint8_t *image[],int stride[],
582 int w, int h, int x, int y) {
583 assert(0);
584 UNUSED(image);UNUSED(stride);
585 UNUSED(w);UNUSED(h);
586 UNUSED(x);UNUSED(y);
588 return VO_ERROR;//this is yv12 only -> vf_scale should do all transforms
591 static uint32_t draw_frame(uint8_t *src[]) {
592 assert(0);
593 UNUSED(src);
594 return VO_ERROR;//this one should not be called
597 static void draw_osd(void)
599 if(verbose > 3)
600 printf("vo_svga: draw_osd()\n");
601 //only modes with bytesperpixel>0 can draw OSD
602 if(modeinfo->bytesperpixel==0) return;
603 if(!(mode_capabilities&CAP_LINEAR)) return;//force_native will remove OSD
605 if(blackbar_osd){
606 //111
607 //3 4
608 //222
609 svga_clear_box(0,0 + PageStore[cpage].yoffset,
610 modeinfo->width, y_pos);
611 svga_clear_box(0, image_height + y_pos + PageStore[cpage].yoffset,
612 modeinfo->width, modeinfo->height-(image_height+ y_pos));
613 svga_clear_box(0, y_pos + PageStore[cpage].yoffset,
614 x_pos, image_height);
615 svga_clear_box(image_width + x_pos, y_pos + PageStore[cpage].yoffset,
616 modeinfo->width-(x_pos+image_width), image_height);
617 // vo_remove_text(modeinfo->width, modeinfo->height, clear_alpha);
618 vo_draw_text(modeinfo->width, modeinfo->height, draw_alpha);
619 }else{
620 vo_draw_text(image_width, image_height, draw_alpha);
624 static void flip_page(void) {
625 PageStore[old_page].locks=PAGE_EMPTY;
626 PageStore[cpage].locks=PAGE_BUSY;
628 if(verbose > 2)
629 printf("vo_svga: viewing page %d\n",cpage);
630 if(sync_flip && old_page!=cpage){
631 if(verbose > 2) printf("vo_svga:vga_waitretrace\n");
632 vga_waitretrace();
634 vga_setdisplaystart(PageStore[cpage].doffset);
636 old_page=cpage;//cpage will be overwriten on next draw_image
639 static void check_events(void) {
642 static void uninit(void) {
644 #ifdef CONFIG_VIDIX
645 if(vidix_name[0])vidix_term();
646 #endif
647 vga_setmode(TEXT);
650 /* --------------------------------------------------------------------- */
651 static uint32_t query_format(uint32_t format) {
652 int32_t req_bpp,flags;
653 int i,lastmode;
654 vga_modeinfo * vminfo;
656 if (verbose >3)
657 printf("vo_svga: query_format=%X \n",format);
658 //only RGB modes supported
659 if( (!IMGFMT_IS_RGB(format)) && (!IMGFMT_IS_BGR(format)) ) return 0;
661 // Reject different endian
662 #ifdef WORDS_BIGENDIAN
663 if (IMGFMT_IS_BGR(format)) return 0;
664 #else
665 if (IMGFMT_IS_RGB(format)) return 0;
666 #endif
668 //svgalib supports only BG4B! if we want BGR4 we have to emulate it (sw)
669 if( format==IMGFMT_BGR4 || format==IMGFMT_RGB4) return 0;
670 req_bpp = IMGFMT_RGB_DEPTH(format);
671 if( vo_dbpp>0 && vo_dbpp!=req_bpp ) return 0; //support -bpp options
672 //scan all modes
673 lastmode = vga_lastmodenumber();
674 for(i=1;i<=lastmode;i++){
675 vminfo = vga_getmodeinfo(i);
676 if( vminfo == NULL ) continue;
677 if( vga_hasmode(i) == 0 ) continue;
678 if( req_bpp != bpp_from_vminfo(vminfo) ) continue;
679 if( (force_vm > 0) && (force_vm != i) ) continue;//quick hack
680 flags = VFCAP_CSP_SUPPORTED|
681 VFCAP_CSP_SUPPORTED_BY_HW|
682 VFCAP_ACCEPT_STRIDE|
684 if(req_bpp>8) flags|=VFCAP_OSD;
685 return flags;
687 return 0;
690 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
691 unsigned char *srca, int stride) {
692 char* base;
694 if(verbose>2)
695 printf("vo_svga: draw_alpha(x0=%d,y0=%d,w=%d,h=%d,src=%p,srca=%p,stride=%d\n",
696 x0,y0,w,h,src,srca,stride);
697 if(!blackbar_osd) {
698 //drawing in the image, so place the stuff there
699 x0+=x_pos;
700 y0+=y_pos;
703 if(verbose>3)
704 printf("vo_svga: OSD draw in page %d\n",cpage);
705 base=PageStore[cpage].vbase + y0*mode_stride + x0*modeinfo->bytesperpixel;
706 switch (mode_bpp) {
707 case 32:
708 vo_draw_alpha_rgb32(w, h, src, srca, stride, base, mode_stride);
709 break;
710 case 24:
711 vo_draw_alpha_rgb24(w, h, src, srca, stride, base, mode_stride);
712 break;
713 case 16:
714 vo_draw_alpha_rgb16(w, h, src, srca, stride, base, mode_stride);
715 break;
716 case 15:
717 vo_draw_alpha_rgb15(w, h, src, srca, stride, base, mode_stride);
718 break;
722 static uint32_t get_image(mp_image_t *mpi){
723 int page;
725 if(!IMGFMT_IS_BGR(mpi->imgfmt) && !IMGFMT_IS_RGB(mpi->imgfmt) ){
726 assert(0);//should never happen
727 return(VO_FALSE);
730 if (
731 ( (mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) ||
732 (mpi->flags & MP_IMGFLAG_PLANAR) ||
733 (mpi->flags & MP_IMGFLAG_YUV)
735 return(VO_FALSE);
737 //reading from video memory is horribly slow
738 if( !(mpi->flags & MP_IMGFLAG_READABLE) && vo_directrendering &&
739 (mode_capabilities & CAP_LINEAR) ){
741 //find free page and reserve it
742 page=page_find_free();
743 if(page >= 0){
744 PageStore[page].locks=PAGE_BUSY;
746 mpi->flags |= MP_IMGFLAG_DIRECT;
747 mpi->stride[0] = mode_stride;
748 mpi->planes[0] = PageStore[page].vbase +
749 y_pos*mode_stride + (x_pos*mpi->bpp)/8;
750 mpi->priv=(void *)page;
751 if(verbose>2)
752 printf("vo_svga: direct render allocated! page=%d\n",page);
753 return(VO_TRUE);
757 return(VO_FALSE);