Merge svn changes up to r27441
[mplayer.git] / libvo / vo_svga.c
blob522ea8c83a594821bb3c4a2b3dee5e4fa1a8e920
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 uint8_t * 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,rez;
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.old_functions);
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 rez = vga_init();
185 if(rez != 0){
186 mp_msg(MSGT_VO,MSGL_ERR, "vo_svga: vga_init() returned error=%d\n",rez);
188 return !!rez;
191 static void svga_clear_box(int x,int y,int w,int h){
192 uint8_t * rgbplane;
193 int i;
195 if (mode_capabilities&CAP_ACCEL_CLEAR){
196 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
197 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with HW acceleration\n",
198 x,y,w,h);
199 if(mode_capabilities&CAP_ACCEL_BACKGR)
200 vga_accel(ACCEL_SYNC);
201 vga_accel(ACCEL_SETFGCOLOR,0);//black
202 vga_accel(ACCEL_FILLBOX,x,y,w,h);
203 return;
205 if (mode_capabilities & CAP_LINEAR){
206 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
207 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with memset\n",x,y,w,h);
208 rgbplane=PageStore[0].vbase + (y*mode_stride) + (x*modeinfo->bytesperpixel);
209 for(i=0;i<h;i++){
210 //i'm afraid that memcpy is better optimized than memset;)
211 fast_memcpy(rgbplane,zerobuf,w*modeinfo->bytesperpixel);
212 // memset(rgbplane,0,w*modeinfo->bytesperpixel);
213 rgbplane+=mode_stride;
215 return;
217 //native
218 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
219 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with native draw \n",x,y,w,h);
220 if(modeinfo->bytesperpixel!=0) w*=modeinfo->bytesperpixel;
221 for(i=0;i<h;i++){
222 vga_drawscansegment(zerobuf,x,y+i,w);
226 static uint32_t svga_draw_image(mp_image_t *mpi){
227 int i,x,y,w,h;
228 int stride;
229 uint8_t *rgbplane, *base;
230 int bytesperline;
231 int page;
233 if(mpi->flags & MP_IMGFLAG_DIRECT){
234 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
235 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: drawing direct rendered surface\n");
236 cpage=(uint32_t)mpi->priv;
237 assert((cpage>=0)&&(cpage<max_pages));
238 return VO_TRUE; //it's already done
240 // if (mpi->flags&MP_IMGFLAGS_DRAWBACK)
241 // return VO_TRUE;//direct render method 2
243 //find a free page to draw into
244 //if there is no one then use the current one
245 page = page_find_free();
246 if(page>=0) cpage=page;
247 PageStore[cpage].locks=PAGE_BUSY;
249 // these variables are used in loops
250 x = mpi->x;
251 y = mpi->y;
252 w = mpi->w;
253 h = mpi->h;
254 stride = mpi->stride[0];
255 rgbplane = mpi->planes[0] + y*stride + (x*mpi->bpp)/8;
256 x+=x_pos;//center
257 y+=y_pos;
259 if(mpi->bpp >= 8){//for modes<8 use only native
260 if( (mode_capabilities&CAP_ACCEL_PUTIMAGE) && (x==0) && (w==mpi->width) &&
261 (stride == mode_stride) ){ //only monolite image can be accelerated
262 w=(stride*8)/mpi->bpp;//we transfer pixels in the stride so the source
263 //ACCELERATE
264 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
265 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using HW PutImage (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
266 if(mode_capabilities & CAP_ACCEL_BACKGR)
267 vga_accel(ACCEL_SYNC);
269 vga_accel(ACCEL_PUTIMAGE,x,y+PageStore[cpage].yoffset,w,h,rgbplane);
270 return VO_TRUE;
273 if( mode_capabilities&CAP_LINEAR){
274 //DIRECT
275 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
276 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using Direct memcpy (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
277 bytesperline=(w*mpi->bpp)/8;
278 base=PageStore[cpage].vbase + (y*mode_stride) + (x*mpi->bpp)/8;
280 for(i=0;i<h;i++){
281 mem2agpcpy(base,rgbplane,bytesperline);
282 base+=mode_stride;
283 rgbplane+=stride;
285 return VO_TRUE;
287 }//(modebpp>=8
290 //NATIVE
292 int length;
293 length=(w*mpi->bpp)/8;
294 //one byte per pixel! svgalib innovation
295 if(mpi->imgfmt==IMGFMT_RG4B || mpi->imgfmt==IMGFMT_BG4B) length=w;
297 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
298 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);
299 y+=PageStore[cpage].yoffset;//y position of the page beggining
300 for(i=0;i<h;i++){
301 vga_drawscansegment(rgbplane,x,y+i,length);
302 rgbplane+=stride;
305 return VO_TRUE;
308 static int bpp_from_vminfo(vga_modeinfo *vminfo){
309 switch(vminfo->colors){
310 case 2: return 1;
311 case 16: return 4;
312 case 256: return 8;
313 case 32768: return 15;
314 case 65536: return 16;
315 case 1<<24: return 8*vminfo->bytesperpixel;
317 return 0;
320 static int find_best_svga_mode(int req_w,int req_h, int req_bpp){
321 int badness,prev_badness;
322 int bestmode,lastmode;
323 int i;
324 vga_modeinfo *vminfo;
325 //int best aspect mode // best linear mode // best normal mode (no modeX)
327 prev_badness = 0;//take care of special case below
328 bestmode = 0; //0 is the TEXT mode
329 lastmode = vga_lastmodenumber();
330 for(i=1;i<=lastmode;i++){
331 vminfo = vga_getmodeinfo(i);
332 if( vminfo == NULL ) continue;
333 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
334 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: testing mode %d (%s)\n",i,vga_getmodename(i));
335 if( vga_hasmode(i) == 0 ) continue;
336 if( req_bpp != bpp_from_vminfo(vminfo) )continue;
337 if( (vminfo->width < req_w) || (vminfo->height < req_h) ) continue;
338 badness=(vminfo->width * vminfo->height) - (req_h * req_w);
339 //put here aspect calculations
340 if(squarepix)
341 if( vminfo->width*3 != vminfo->height*4 ) continue;
343 if( bestmode==0 || prev_badness >= badness ){//modeX etc...
344 prev_badness=badness;
345 bestmode=i;
346 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
347 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: found good mode %d with badness %d\n",i,badness);
350 return bestmode;
353 static int control(uint32_t request, void *data)
355 switch (request) {
356 case VOCTRL_QUERY_FORMAT:
357 return query_format(*((uint32_t*)data));
358 case VOCTRL_DRAW_IMAGE:
359 return svga_draw_image( (mp_image_t *)data);
360 case VOCTRL_GET_IMAGE:
361 return get_image(data);
364 #ifdef CONFIG_VIDIX
365 if (vidix_name[0])
366 return vidix_control(request, data);
367 #endif
369 return VO_NOTIMPL;
373 // This function is called to init the video driver for specific mode
375 static int config(uint32_t width, uint32_t height, uint32_t d_width,
376 uint32_t d_height, uint32_t flags, char *title,
377 uint32_t format) {
378 int32_t req_w = width;// (d_width > 0 ? d_width : width);
379 int32_t req_h = height;// (d_height > 0 ? d_height : height);
380 uint16_t vid_mode = 0;
381 int32_t req_bpp;
383 uint32_t accflags;
384 if( mp_msg_test(MSGT_VO,MSGL_V) )
385 mp_msg(MSGT_VO,MSGL_V, "vo_svga: config(%i, %i, %i, %i, %08x, %s, %08x)\n", width, height,
386 d_width, d_height, flags, title, format);
387 //Only RGB modes supported
388 if (!IMGFMT_IS_RGB(format) && !IMGFMT_IS_BGR(format)) {assert(0);return -1;}
389 req_bpp = IMGFMT_BGR_DEPTH(format);
391 if( vo_dbpp!=0 && vo_dbpp!=req_bpp) {assert(0);return-1;}
393 if(!force_vm) {
394 if ( mp_msg_test(MSGT_VO,MSGL_V) ) {
395 mp_msg(MSGT_VO,MSGL_V, "vo_svga: Looking for the best resolution...\n");
396 mp_msg(MSGT_VO,MSGL_V, "vo_svga: req_w: %d, req_h: %d, bpp: %d\n",req_w,req_h,req_bpp);
398 vid_mode=find_best_svga_mode(req_w,req_h,req_bpp);
399 if(vid_mode==0)
400 return 1;
401 modeinfo=vga_getmodeinfo(vid_mode);
402 }else{//force_vm
403 vid_mode=force_vm;
404 if(vga_hasmode(vid_mode) == 0){
405 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeNotAvailable,
406 vid_mode,vga_getmodename(vid_mode));
407 return 1; //error;
409 modeinfo=vga_getmodeinfo(vid_mode);
410 if( (modeinfo->width < req_w) || (modeinfo->height < req_h) ){
411 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeTooSmall,
412 vid_mode,vga_getmodename(vid_mode));
413 return 1;
416 mode_bpp=bpp_from_vminfo(modeinfo);
418 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_Vidmode,
419 vid_mode,modeinfo->width,modeinfo->height,mode_bpp);
421 if (vga_setmode(vid_mode) == -1) {
422 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_VgasetmodeFailed,vid_mode);
423 uninit();
424 return 1; // error
426 /* set 332 palette for 8 bpp */
427 if(mode_bpp==8){
428 int i;
429 for(i=0; i<256; i++)
430 vga_setpalette(i, ((i>>5)&7)*9, ((i>>2)&7)*9, (i&3)*21);
432 /* set 121 palette for 4 bpp */
433 else if(mode_bpp==4){
434 int i;
435 for(i=0; i<16; i++)
436 vga_setpalette(i, ((i>>3)&1)*63, ((i>>1)&3)*21, (i&1)*63);
438 //if we change the logical width, we should know the granularity
439 stride_granularity=8;//according to man vga_logicalwidth
440 if(modeinfo->flags & EXT_INFO_AVAILABLE){
441 stride_granularity=modeinfo->linewidth_unit;
443 //look for hardware acceleration
444 mode_capabilities=0;//NATIVE;
445 if(!force_native){//if we want to use only native drawers
446 if(modeinfo->flags & HAVE_EXT_SET){//support for hwaccel interface
447 accflags=vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_ACCEL);
448 if(accflags & ACCELFLAG_FILLBOX) // clear screen
449 mode_capabilities|=CAP_ACCEL_CLEAR;
450 if(accflags & ACCELFLAG_PUTIMAGE)//support for mem->vid transfer
451 mode_capabilities|=CAP_ACCEL_PUTIMAGE;
452 if((accflags & ACCELFLAG_SETMODE) && (accflags & ACCELFLAG_SYNC)){
453 vga_accel(ACCEL_SETMODE,BLITS_IN_BACKGROUND);
454 mode_capabilities|=CAP_ACCEL_BACKGR;//can draw in backgraund
457 if(modeinfo->flags & IS_LINEAR){
458 mode_capabilities|=CAP_LINEAR; //don't use bank & vga_draw
460 else{
461 if(modeinfo->flags & CAPABLE_LINEAR){
462 int vid_mem_size;
463 vid_mem_size = vga_setlinearaddressing();
464 if(vid_mem_size != -1){
465 modeinfo=vga_getmodeinfo(vid_mode);//sometimes they change parameters
466 mode_capabilities|=CAP_LINEAR;
470 }//fi force native
471 if(mode_capabilities&CAP_LINEAR){
472 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeIsLinearAndMemcpyCouldBeUsed);
474 if(mode_capabilities&CAP_ACCEL_PUTIMAGE){
475 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeHasHardwareAcceleration);
476 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_IfItWorksForYouIWouldLikeToKnow);
479 //here is the place to handle strides for accel_ modes;
480 mode_stride=modeinfo->linewidth;
481 //we may try to set a bigger stride for video mode that will match the mpi->stride,
482 //this way we will transfer more data, but HW put_image can do it in backgraund!
484 //now let's see how many pages we can use
485 max_pages = modeinfo->maxpixels/(modeinfo->height * modeinfo->width);
486 if(max_pages > MAXPAGES) max_pages = MAXPAGES;
487 if(!vo_doublebuffering) max_pages=1;
488 //fill PageStore structs
490 int i;
491 uint8_t * GRAPH_MEM;
492 int dof;
493 GRAPH_MEM=vga_getgraphmem();
494 for(i=0;i<max_pages;i++){
495 //calculate display offset
496 dof = i * modeinfo->height * modeinfo->width;
497 if(modeinfo->bytesperpixel != 0) dof*=modeinfo->bytesperpixel;
498 //check video chip limitations
499 if( dof != (dof & modeinfo->startaddressrange) ){
500 max_pages=i;//page 0 will never come here
501 break;
503 PageStore[i].yoffset = i * modeinfo->height;//starting y offset
504 PageStore[i].vbase = GRAPH_MEM + i*modeinfo->height*mode_stride; //memory base address
505 PageStore[i].doffset = dof; //display offset
506 PageStore[i].locks = PAGE_EMPTY;
509 assert(max_pages>0);
510 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeHas,max_pages);
511 //15bpp
512 if(modeinfo->bytesperpixel!=0)
513 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * modeinfo->bytesperpixel);
514 else
515 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * mode_bpp / 8);
517 cpage=old_page=0;
518 svga_clear_box(0,0,modeinfo->width,modeinfo->height * max_pages);
520 image_height=req_h;
521 image_width=req_w;
522 x_pos = (modeinfo->width - req_w) / 2;
523 y_pos = (modeinfo->height - req_h) / 2;
524 x_pos &= ~(15); //align x offset position to 16 pixels
525 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_CenteringImageStartAt,x_pos,y_pos);
527 #ifdef CONFIG_VIDIX
529 if(vidix_name[0]){
530 vidix_init(width, height, x_pos, y_pos, modeinfo->width, modeinfo->height,
531 format, mode_bpp, modeinfo->width,modeinfo->height);
532 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_UsingVidix,width,height,
533 modeinfo->width,modeinfo->height);
534 vidix_start();
535 /*set colorkey*/
536 if(vidix_grkey_support()){
537 vidix_grkey_get(&gr_key);
538 gr_key.key_op = KEYS_PUT;
539 if (!(vo_colorkey & 0xFF000000)) {
540 gr_key.ckey.op = CKEY_TRUE;
541 gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
542 gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
543 gr_key.ckey.blue = vo_colorkey & 0x000000FF;
544 } else
545 gr_key.ckey.op = CKEY_FALSE;
546 vidix_grkey_set(&gr_key);
549 #endif
551 vga_setdisplaystart(0);
552 return 0;
555 static int draw_slice(uint8_t *image[],int stride[],
556 int w, int h, int x, int y) {
557 assert(0);
558 UNUSED(image);UNUSED(stride);
559 UNUSED(w);UNUSED(h);
560 UNUSED(x);UNUSED(y);
562 return VO_ERROR;//this is yv12 only -> vf_scale should do all transforms
565 static int draw_frame(uint8_t *src[]) {
566 assert(0);
567 UNUSED(src);
568 return VO_ERROR;//this one should not be called
571 static void draw_osd(void)
573 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
574 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: draw_osd()\n");
575 //only modes with bytesperpixel>0 can draw OSD
576 if(modeinfo->bytesperpixel==0) return;
577 if(!(mode_capabilities&CAP_LINEAR)) return;//force_native will remove OSD
579 if(blackbar_osd){
580 //111
581 //3 4
582 //222
583 svga_clear_box(0,0 + PageStore[cpage].yoffset,
584 modeinfo->width, y_pos);
585 svga_clear_box(0, image_height + y_pos + PageStore[cpage].yoffset,
586 modeinfo->width, modeinfo->height-(image_height+ y_pos));
587 svga_clear_box(0, y_pos + PageStore[cpage].yoffset,
588 x_pos, image_height);
589 svga_clear_box(image_width + x_pos, y_pos + PageStore[cpage].yoffset,
590 modeinfo->width-(x_pos+image_width), image_height);
591 // vo_remove_text(modeinfo->width, modeinfo->height, clear_alpha);
592 vo_draw_text(modeinfo->width, modeinfo->height, draw_alpha);
593 }else{
594 vo_draw_text(image_width, image_height, draw_alpha);
598 static void flip_page(void) {
599 PageStore[old_page].locks=PAGE_EMPTY;
600 PageStore[cpage].locks=PAGE_BUSY;
602 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
603 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: viewing page %d\n",cpage);
604 if(sync_flip && old_page!=cpage){
605 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga:vga_waitretrace\n");
606 vga_waitretrace();
608 vga_setdisplaystart(PageStore[cpage].doffset);
610 old_page=cpage;//cpage will be overwriten on next draw_image
613 static void check_events(void) {
616 static void uninit(void) {
618 #ifdef CONFIG_VIDIX
619 if(vidix_name[0])vidix_term();
620 #endif
621 vga_setmode(TEXT);
624 /* --------------------------------------------------------------------- */
625 static int query_format(uint32_t format) {
626 int32_t req_bpp,flags;
627 int i,lastmode;
628 vga_modeinfo * vminfo;
630 if ( mp_msg_test(MSGT_VO,MSGL_DBG4) )
631 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: query_format=%X \n",format);
632 //only RGB modes supported
633 if( (!IMGFMT_IS_RGB(format)) && (!IMGFMT_IS_BGR(format)) ) return 0;
635 // Reject different endian
636 #ifdef WORDS_BIGENDIAN
637 if (IMGFMT_IS_BGR(format)) return 0;
638 #else
639 if (IMGFMT_IS_RGB(format)) return 0;
640 #endif
642 //svgalib supports only BG4B! if we want BGR4 we have to emulate it (sw)
643 if( format==IMGFMT_BGR4 || format==IMGFMT_RGB4) return 0;
644 req_bpp = IMGFMT_RGB_DEPTH(format);
645 if( vo_dbpp>0 && vo_dbpp!=req_bpp ) return 0; //support -bpp options
646 //scan all modes
647 lastmode = vga_lastmodenumber();
648 for(i=1;i<=lastmode;i++){
649 vminfo = vga_getmodeinfo(i);
650 if( vminfo == NULL ) continue;
651 if( vga_hasmode(i) == 0 ) continue;
652 if( req_bpp != bpp_from_vminfo(vminfo) ) continue;
653 if( (force_vm > 0) && (force_vm != i) ) continue;//quick hack
654 flags = VFCAP_CSP_SUPPORTED|
655 VFCAP_CSP_SUPPORTED_BY_HW|
656 VFCAP_ACCEPT_STRIDE|
658 if(req_bpp>8) flags|=VFCAP_OSD;
659 return flags;
661 return 0;
664 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
665 unsigned char *srca, int stride) {
666 char* base;
668 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
669 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",
670 x0,y0,w,h,src,srca,stride);
671 if(!blackbar_osd) {
672 //drawing in the image, so place the stuff there
673 x0+=x_pos;
674 y0+=y_pos;
677 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
678 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: OSD draw in page %d\n",cpage);
679 base=PageStore[cpage].vbase + y0*mode_stride + x0*modeinfo->bytesperpixel;
680 switch (mode_bpp) {
681 case 32:
682 vo_draw_alpha_rgb32(w, h, src, srca, stride, base, mode_stride);
683 break;
684 case 24:
685 vo_draw_alpha_rgb24(w, h, src, srca, stride, base, mode_stride);
686 break;
687 case 16:
688 vo_draw_alpha_rgb16(w, h, src, srca, stride, base, mode_stride);
689 break;
690 case 15:
691 vo_draw_alpha_rgb15(w, h, src, srca, stride, base, mode_stride);
692 break;
696 static uint32_t get_image(mp_image_t *mpi){
697 int page;
699 if(!IMGFMT_IS_BGR(mpi->imgfmt) && !IMGFMT_IS_RGB(mpi->imgfmt) ){
700 assert(0);//should never happen
701 return VO_FALSE;
704 if (
705 ( (mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) ||
706 (mpi->flags & MP_IMGFLAG_PLANAR) ||
707 (mpi->flags & MP_IMGFLAG_YUV)
709 return VO_FALSE;
711 //reading from video memory is horribly slow
712 if( !(mpi->flags & MP_IMGFLAG_READABLE) && vo_directrendering &&
713 (mode_capabilities & CAP_LINEAR) ){
715 //find free page and reserve it
716 page=page_find_free();
717 if(page >= 0){
718 PageStore[page].locks=PAGE_BUSY;
720 mpi->flags |= MP_IMGFLAG_DIRECT;
721 mpi->stride[0] = mode_stride;
722 mpi->planes[0] = PageStore[page].vbase +
723 y_pos*mode_stride + (x_pos*mpi->bpp)/8;
724 mpi->priv=(void *)page;
725 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
726 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: direct render allocated! page=%d\n",page);
727 return VO_TRUE;
731 return VO_FALSE;