Merge svn changes up to r28537
[mplayer/glamo.git] / libvo / vo_svga.c
blobb72a6aded73491a9209d8cea9c7a3a88ac7cb95f
1 /*
2 * video driver for SVGAlib
3 * by Zoltan Mark Vician <se7en@sch.bme.hu>
4 * Code started: Mon Apr 1 23:25:47 2001
5 * Some changes by Matan Ziv-Av <matan@svgalib.org>
6 * complete rewrite by Ivan Kalvachev 19 Mar 2003
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * MPlayer is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License along
21 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 Wrangings:
27 - 1bpp doesn't work right for me with '-double' and svgalib 1.4.3,
28 but works OK with svgalib 1.9.17
29 - The HW acceleration is not tested - svgalibs supports few chipsets,
30 and i don't have any of them. If it works for you then let me know.
31 I will remove this warning after confirm its status.
32 - retrace sync works only in doublebuffer mode.
33 - the retrace sync may slow down decoding a lot - mplayer is blocked while
34 waiting for retrace
35 - denoise3d fails to find common colorspace, use -vf denoise3d,scale
37 TODO:
38 - let choose_best_mode take aspect into account
39 - set palette from mpi->palette or mpi->plane[1]
40 - make faster OSD black bars clear - need some OSD changes
41 - Make nicer CONFIG parsing
42 - change video mode logical width to match img->stride[0] - for HW only
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
49 #include <vga.h>
51 #include <limits.h>
53 #include "config.h"
54 #include "video_out.h"
55 #include "video_out_internal.h"
56 #include "fastmemcpy.h"
57 #include "osdep/getch2.h"
58 #ifdef CONFIG_VIDIX
59 #include "vosub_vidix.h"
60 #endif
62 #include "sub.h"
64 #include "mp_msg.h"
65 #include "help_mp.h"
66 //#include "mp_image.h"
68 #include <assert.h>
70 //silence warnings, probably it have to go in some global header
71 #define UNUSED(x) ((void)(x))
74 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
75 unsigned char *srca, int stride);
76 static uint32_t get_image(mp_image_t *mpi);
78 #define MAXPAGES 16
79 #define PAGE_EMPTY 0
80 #define PAGE_BUSY 1
82 #define CAP_ACCEL_CLEAR 8
83 #define CAP_ACCEL_PUTIMAGE 4
84 #define CAP_ACCEL_BACKGR 2
85 #define CAP_LINEAR 1
87 static uint8_t zerobuf[8192];//used when clear screen with vga_draw
89 static int squarepix;
90 static int force_vm=0;
91 static int force_native=0;
92 static int sync_flip=0;
93 static int blackbar_osd=0;
94 static int cpage,max_pages,old_page;
96 static vga_modeinfo * modeinfo;
97 static int mode_stride; //keep it in case of vga_setlogicalwidth
98 static int stride_granularity; //not yet used
99 static int mode_bpp;
100 static int mode_capabilities;
102 static int image_width,image_height; // used by OSD
103 static int x_pos, y_pos;
105 static struct {
106 int yoffset;//y position of the page
107 int doffset;//display start of the page
108 uint8_t * vbase;//memory start address of the page
109 int locks;
110 }PageStore[MAXPAGES];
112 static const vo_info_t info = {
113 "SVGAlib",
114 "svga",
115 "Ivan Kalvachev <iive@users.sf.net>",
119 #ifdef CONFIG_VIDIX
120 static char vidix_name[32] = "";
121 static vidix_grkey_t gr_key;
122 #endif
124 LIBVO_EXTERN(svga)
127 //return number of 1'st free page or -1 if no free one
128 static inline int page_find_free(void){
129 int i;
130 for(i=0;i<max_pages;i++)
131 if(PageStore[i].locks == PAGE_EMPTY) return i;
132 return -1;
135 static int preinit(const char *arg)
137 int i,rez;
138 char s[64];
140 getch2_disable();
141 memset(zerobuf,0,sizeof(zerobuf));
142 force_vm=force_native=squarepix=0;
143 sync_flip=vo_vsync;
144 blackbar_osd=0;
146 if(arg)while(*arg) {
147 #ifdef CONFIG_VIDIX
148 if(memcmp(arg,"vidix",5)==0) {
149 i=6;
150 while(arg[i] && arg[i]!=':') i++;
151 strncpy(vidix_name, arg+6, i-6);
152 vidix_name[i-5]=0;
153 if(arg[i]==':')i++;
154 arg+=i;
155 vidix_preinit(vidix_name, video_out_svga.old_functions);
157 #endif
158 if(!strncmp(arg,"sq",2)) {
159 squarepix=1;
160 arg+=2;
161 if( *arg == ':' ) arg++;
164 if(!strncmp(arg,"native",6)) {
165 force_native=1;
166 arg+=6;
167 if( *arg == ':' ) arg++;
170 if(!strncmp(arg,"bbosd",5)) {
171 blackbar_osd=1;
172 arg+=5;
173 if( *arg == ':' ) arg++;
176 if(!strncmp(arg,"retrace",7)) {
177 sync_flip=1;
178 arg+=7;
179 if( *arg == ':' ) arg++;
182 if(*arg) {
183 i=0;
184 while(arg[i] && arg[i]!=':')i++;
185 if(i<64){
186 strncpy(s, arg, i);
187 s[i]=0;
189 force_vm=vga_getmodenumber(s);
190 if(force_vm>0) {
191 if( mp_msg_test(MSGT_VO,MSGL_V) ) mp_msg(MSGT_VO,MSGL_V, "vo_svga: Forcing mode %i\n",force_vm);
192 }else{
193 force_vm = 0;
196 arg+=i;
197 if(*arg==':')arg++;
201 rez = vga_init();
202 if(rez != 0){
203 mp_msg(MSGT_VO,MSGL_ERR, "vo_svga: vga_init() returned error=%d\n",rez);
205 return !!rez;
208 static void svga_clear_box(int x,int y,int w,int h){
209 uint8_t * rgbplane;
210 int i;
212 if (mode_capabilities&CAP_ACCEL_CLEAR){
213 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
214 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with HW acceleration\n",
215 x,y,w,h);
216 if(mode_capabilities&CAP_ACCEL_BACKGR)
217 vga_accel(ACCEL_SYNC);
218 vga_accel(ACCEL_SETFGCOLOR,0);//black
219 vga_accel(ACCEL_FILLBOX,x,y,w,h);
220 return;
222 if (mode_capabilities & CAP_LINEAR){
223 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
224 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with memset\n",x,y,w,h);
225 rgbplane=PageStore[0].vbase + (y*mode_stride) + (x*modeinfo->bytesperpixel);
226 for(i=0;i<h;i++){
227 //i'm afraid that memcpy is better optimized than memset;)
228 fast_memcpy(rgbplane,zerobuf,w*modeinfo->bytesperpixel);
229 // memset(rgbplane,0,w*modeinfo->bytesperpixel);
230 rgbplane+=mode_stride;
232 return;
234 //native
235 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
236 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with native draw \n",x,y,w,h);
237 if(modeinfo->bytesperpixel!=0) w*=modeinfo->bytesperpixel;
238 for(i=0;i<h;i++){
239 vga_drawscansegment(zerobuf,x,y+i,w);
243 static uint32_t svga_draw_image(mp_image_t *mpi){
244 int i,x,y,w,h;
245 int stride;
246 uint8_t *rgbplane, *base;
247 int bytesperline;
248 int page;
250 if(mpi->flags & MP_IMGFLAG_DIRECT){
251 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
252 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: drawing direct rendered surface\n");
253 cpage=(uint32_t)mpi->priv;
254 assert((cpage>=0)&&(cpage<max_pages));
255 return VO_TRUE; //it's already done
257 // if (mpi->flags&MP_IMGFLAGS_DRAWBACK)
258 // return VO_TRUE;//direct render method 2
260 //find a free page to draw into
261 //if there is no one then use the current one
262 page = page_find_free();
263 if(page>=0) cpage=page;
264 PageStore[cpage].locks=PAGE_BUSY;
266 // these variables are used in loops
267 x = mpi->x;
268 y = mpi->y;
269 w = mpi->w;
270 h = mpi->h;
271 stride = mpi->stride[0];
272 rgbplane = mpi->planes[0] + y*stride + (x*mpi->bpp)/8;
273 x+=x_pos;//center
274 y+=y_pos;
276 if(mpi->bpp >= 8){//for modes<8 use only native
277 if( (mode_capabilities&CAP_ACCEL_PUTIMAGE) && (x==0) && (w==mpi->width) &&
278 (stride == mode_stride) ){ //only monolite image can be accelerated
279 w=(stride*8)/mpi->bpp;//we transfer pixels in the stride so the source
280 //ACCELERATE
281 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
282 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using HW PutImage (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
283 if(mode_capabilities & CAP_ACCEL_BACKGR)
284 vga_accel(ACCEL_SYNC);
286 vga_accel(ACCEL_PUTIMAGE,x,y+PageStore[cpage].yoffset,w,h,rgbplane);
287 return VO_TRUE;
290 if( mode_capabilities&CAP_LINEAR){
291 //DIRECT
292 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
293 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using Direct memcpy (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
294 bytesperline=(w*mpi->bpp)/8;
295 base=PageStore[cpage].vbase + (y*mode_stride) + (x*mpi->bpp)/8;
297 for(i=0;i<h;i++){
298 mem2agpcpy(base,rgbplane,bytesperline);
299 base+=mode_stride;
300 rgbplane+=stride;
302 return VO_TRUE;
304 }//(modebpp>=8
307 //NATIVE
309 int length;
310 length=(w*mpi->bpp)/8;
311 //one byte per pixel! svgalib innovation
312 if(mpi->imgfmt==IMGFMT_RG4B || mpi->imgfmt==IMGFMT_BG4B) length=w;
314 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
315 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);
316 y+=PageStore[cpage].yoffset;//y position of the page beggining
317 for(i=0;i<h;i++){
318 vga_drawscansegment(rgbplane,x,y+i,length);
319 rgbplane+=stride;
322 return VO_TRUE;
325 static int bpp_from_vminfo(vga_modeinfo *vminfo){
326 switch(vminfo->colors){
327 case 2: return 1;
328 case 16: return 4;
329 case 256: return 8;
330 case 32768: return 15;
331 case 65536: return 16;
332 case 1<<24: return 8*vminfo->bytesperpixel;
334 return 0;
337 static int find_best_svga_mode(int req_w,int req_h, int req_bpp){
338 int badness,prev_badness;
339 int bestmode,lastmode;
340 int i;
341 vga_modeinfo *vminfo;
342 //int best aspect mode // best linear mode // best normal mode (no modeX)
344 prev_badness = 0;//take care of special case below
345 bestmode = 0; //0 is the TEXT mode
346 lastmode = vga_lastmodenumber();
347 for(i=1;i<=lastmode;i++){
348 vminfo = vga_getmodeinfo(i);
349 if( vminfo == NULL ) continue;
350 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
351 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: testing mode %d (%s)\n",i,vga_getmodename(i));
352 if( vga_hasmode(i) == 0 ) continue;
353 if( req_bpp != bpp_from_vminfo(vminfo) )continue;
354 if( (vminfo->width < req_w) || (vminfo->height < req_h) ) continue;
355 badness=(vminfo->width * vminfo->height) - (req_h * req_w);
356 //put here aspect calculations
357 if(squarepix)
358 if( vminfo->width*3 != vminfo->height*4 ) continue;
360 if( bestmode==0 || prev_badness >= badness ){//modeX etc...
361 prev_badness=badness;
362 bestmode=i;
363 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
364 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: found good mode %d with badness %d\n",i,badness);
367 return bestmode;
370 static int control(uint32_t request, void *data)
372 switch (request) {
373 case VOCTRL_QUERY_FORMAT:
374 return query_format(*((uint32_t*)data));
375 case VOCTRL_DRAW_IMAGE:
376 return svga_draw_image( (mp_image_t *)data);
377 case VOCTRL_GET_IMAGE:
378 return get_image(data);
381 #ifdef CONFIG_VIDIX
382 if (vidix_name[0])
383 return vidix_control(request, data);
384 #endif
386 return VO_NOTIMPL;
390 // This function is called to init the video driver for specific mode
392 static int config(uint32_t width, uint32_t height, uint32_t d_width,
393 uint32_t d_height, uint32_t flags, char *title,
394 uint32_t format) {
395 int32_t req_w = width;// (d_width > 0 ? d_width : width);
396 int32_t req_h = height;// (d_height > 0 ? d_height : height);
397 uint16_t vid_mode = 0;
398 int32_t req_bpp;
400 uint32_t accflags;
401 if( mp_msg_test(MSGT_VO,MSGL_V) )
402 mp_msg(MSGT_VO,MSGL_V, "vo_svga: config(%i, %i, %i, %i, %08x, %s, %08x)\n", width, height,
403 d_width, d_height, flags, title, format);
404 //Only RGB modes supported
405 if (!IMGFMT_IS_RGB(format) && !IMGFMT_IS_BGR(format)) {assert(0);return -1;}
406 req_bpp = IMGFMT_BGR_DEPTH(format);
408 if( vo_dbpp!=0 && vo_dbpp!=req_bpp) {assert(0);return-1;}
410 if(!force_vm) {
411 if ( mp_msg_test(MSGT_VO,MSGL_V) ) {
412 mp_msg(MSGT_VO,MSGL_V, "vo_svga: Looking for the best resolution...\n");
413 mp_msg(MSGT_VO,MSGL_V, "vo_svga: req_w: %d, req_h: %d, bpp: %d\n",req_w,req_h,req_bpp);
415 vid_mode=find_best_svga_mode(req_w,req_h,req_bpp);
416 if(vid_mode==0)
417 return 1;
418 modeinfo=vga_getmodeinfo(vid_mode);
419 }else{//force_vm
420 vid_mode=force_vm;
421 if(vga_hasmode(vid_mode) == 0){
422 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeNotAvailable,
423 vid_mode,vga_getmodename(vid_mode));
424 return 1; //error;
426 modeinfo=vga_getmodeinfo(vid_mode);
427 if( (modeinfo->width < req_w) || (modeinfo->height < req_h) ){
428 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeTooSmall,
429 vid_mode,vga_getmodename(vid_mode));
430 return 1;
433 mode_bpp=bpp_from_vminfo(modeinfo);
435 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_Vidmode,
436 vid_mode,modeinfo->width,modeinfo->height,mode_bpp);
438 if (vga_setmode(vid_mode) == -1) {
439 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_VgasetmodeFailed,vid_mode);
440 uninit();
441 return 1; // error
443 /* set 332 palette for 8 bpp */
444 if(mode_bpp==8){
445 int i;
446 for(i=0; i<256; i++)
447 vga_setpalette(i, ((i>>5)&7)*9, ((i>>2)&7)*9, (i&3)*21);
449 /* set 121 palette for 4 bpp */
450 else if(mode_bpp==4){
451 int i;
452 for(i=0; i<16; i++)
453 vga_setpalette(i, ((i>>3)&1)*63, ((i>>1)&3)*21, (i&1)*63);
455 //if we change the logical width, we should know the granularity
456 stride_granularity=8;//according to man vga_logicalwidth
457 if(modeinfo->flags & EXT_INFO_AVAILABLE){
458 stride_granularity=modeinfo->linewidth_unit;
460 //look for hardware acceleration
461 mode_capabilities=0;//NATIVE;
462 if(!force_native){//if we want to use only native drawers
463 if(modeinfo->flags & HAVE_EXT_SET){//support for hwaccel interface
464 accflags=vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_ACCEL);
465 if(accflags & ACCELFLAG_FILLBOX) // clear screen
466 mode_capabilities|=CAP_ACCEL_CLEAR;
467 if(accflags & ACCELFLAG_PUTIMAGE)//support for mem->vid transfer
468 mode_capabilities|=CAP_ACCEL_PUTIMAGE;
469 if((accflags & ACCELFLAG_SETMODE) && (accflags & ACCELFLAG_SYNC)){
470 vga_accel(ACCEL_SETMODE,BLITS_IN_BACKGROUND);
471 mode_capabilities|=CAP_ACCEL_BACKGR;//can draw in backgraund
474 if(modeinfo->flags & IS_LINEAR){
475 mode_capabilities|=CAP_LINEAR; //don't use bank & vga_draw
477 else{
478 if(modeinfo->flags & CAPABLE_LINEAR){
479 int vid_mem_size;
480 vid_mem_size = vga_setlinearaddressing();
481 if(vid_mem_size != -1){
482 modeinfo=vga_getmodeinfo(vid_mode);//sometimes they change parameters
483 mode_capabilities|=CAP_LINEAR;
487 }//fi force native
488 if(mode_capabilities&CAP_LINEAR){
489 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeIsLinearAndMemcpyCouldBeUsed);
491 if(mode_capabilities&CAP_ACCEL_PUTIMAGE){
492 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeHasHardwareAcceleration);
493 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_IfItWorksForYouIWouldLikeToKnow);
496 //here is the place to handle strides for accel_ modes;
497 mode_stride=modeinfo->linewidth;
498 //we may try to set a bigger stride for video mode that will match the mpi->stride,
499 //this way we will transfer more data, but HW put_image can do it in backgraund!
501 //now let's see how many pages we can use
502 max_pages = modeinfo->maxpixels/(modeinfo->height * modeinfo->width);
503 if(max_pages > MAXPAGES) max_pages = MAXPAGES;
504 if(!vo_doublebuffering) max_pages=1;
505 //fill PageStore structs
507 int i;
508 uint8_t * GRAPH_MEM;
509 int dof;
510 GRAPH_MEM=vga_getgraphmem();
511 for(i=0;i<max_pages;i++){
512 //calculate display offset
513 dof = i * modeinfo->height * modeinfo->width;
514 if(modeinfo->bytesperpixel != 0) dof*=modeinfo->bytesperpixel;
515 //check video chip limitations
516 if( dof != (dof & modeinfo->startaddressrange) ){
517 max_pages=i;//page 0 will never come here
518 break;
520 PageStore[i].yoffset = i * modeinfo->height;//starting y offset
521 PageStore[i].vbase = GRAPH_MEM + i*modeinfo->height*mode_stride; //memory base address
522 PageStore[i].doffset = dof; //display offset
523 PageStore[i].locks = PAGE_EMPTY;
526 assert(max_pages>0);
527 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeHas,max_pages);
528 //15bpp
529 if(modeinfo->bytesperpixel!=0)
530 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * modeinfo->bytesperpixel);
531 else
532 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * mode_bpp / 8);
534 cpage=old_page=0;
535 svga_clear_box(0,0,modeinfo->width,modeinfo->height * max_pages);
537 image_height=req_h;
538 image_width=req_w;
539 x_pos = (modeinfo->width - req_w) / 2;
540 y_pos = (modeinfo->height - req_h) / 2;
541 x_pos &= ~(15); //align x offset position to 16 pixels
542 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_CenteringImageStartAt,x_pos,y_pos);
544 #ifdef CONFIG_VIDIX
546 if(vidix_name[0]){
547 vidix_init(width, height, x_pos, y_pos, modeinfo->width, modeinfo->height,
548 format, mode_bpp, modeinfo->width,modeinfo->height);
549 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_UsingVidix,width,height,
550 modeinfo->width,modeinfo->height);
551 vidix_start();
552 /*set colorkey*/
553 if(vidix_grkey_support()){
554 vidix_grkey_get(&gr_key);
555 gr_key.key_op = KEYS_PUT;
556 if (!(vo_colorkey & 0xFF000000)) {
557 gr_key.ckey.op = CKEY_TRUE;
558 gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
559 gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
560 gr_key.ckey.blue = vo_colorkey & 0x000000FF;
561 } else
562 gr_key.ckey.op = CKEY_FALSE;
563 vidix_grkey_set(&gr_key);
566 #endif
568 vga_setdisplaystart(0);
569 return 0;
572 static int draw_slice(uint8_t *image[],int stride[],
573 int w, int h, int x, int y) {
574 assert(0);
575 UNUSED(image);UNUSED(stride);
576 UNUSED(w);UNUSED(h);
577 UNUSED(x);UNUSED(y);
579 return VO_ERROR;//this is yv12 only -> vf_scale should do all transforms
582 static int draw_frame(uint8_t *src[]) {
583 assert(0);
584 UNUSED(src);
585 return VO_ERROR;//this one should not be called
588 static void draw_osd(void)
590 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
591 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: draw_osd()\n");
592 //only modes with bytesperpixel>0 can draw OSD
593 if(modeinfo->bytesperpixel==0) return;
594 if(!(mode_capabilities&CAP_LINEAR)) return;//force_native will remove OSD
596 if(blackbar_osd){
597 //111
598 //3 4
599 //222
600 svga_clear_box(0,0 + PageStore[cpage].yoffset,
601 modeinfo->width, y_pos);
602 svga_clear_box(0, image_height + y_pos + PageStore[cpage].yoffset,
603 modeinfo->width, modeinfo->height-(image_height+ y_pos));
604 svga_clear_box(0, y_pos + PageStore[cpage].yoffset,
605 x_pos, image_height);
606 svga_clear_box(image_width + x_pos, y_pos + PageStore[cpage].yoffset,
607 modeinfo->width-(x_pos+image_width), image_height);
608 // vo_remove_text(modeinfo->width, modeinfo->height, clear_alpha);
609 vo_draw_text(modeinfo->width, modeinfo->height, draw_alpha);
610 }else{
611 vo_draw_text(image_width, image_height, draw_alpha);
615 static void flip_page(void) {
616 PageStore[old_page].locks=PAGE_EMPTY;
617 PageStore[cpage].locks=PAGE_BUSY;
619 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
620 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: viewing page %d\n",cpage);
621 if(sync_flip && old_page!=cpage){
622 if( mp_msg_test(MSGT_VO,MSGL_DBG3) ) mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga:vga_waitretrace\n");
623 vga_waitretrace();
625 vga_setdisplaystart(PageStore[cpage].doffset);
627 old_page=cpage;//cpage will be overwriten on next draw_image
630 static void check_events(void) {
633 static void uninit(void) {
635 #ifdef CONFIG_VIDIX
636 if(vidix_name[0])vidix_term();
637 #endif
638 vga_setmode(TEXT);
641 /* --------------------------------------------------------------------- */
642 static int query_format(uint32_t format) {
643 int32_t req_bpp,flags;
644 int i,lastmode;
645 vga_modeinfo * vminfo;
647 if ( mp_msg_test(MSGT_VO,MSGL_DBG4) )
648 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: query_format=%X \n",format);
649 //only RGB modes supported
650 if( (!IMGFMT_IS_RGB(format)) && (!IMGFMT_IS_BGR(format)) ) return 0;
652 // Reject different endian
653 #ifdef WORDS_BIGENDIAN
654 if (IMGFMT_IS_BGR(format)) return 0;
655 #else
656 if (IMGFMT_IS_RGB(format)) return 0;
657 #endif
659 //svgalib supports only BG4B! if we want BGR4 we have to emulate it (sw)
660 if( format==IMGFMT_BGR4 || format==IMGFMT_RGB4) return 0;
661 req_bpp = IMGFMT_RGB_DEPTH(format);
662 if( vo_dbpp>0 && vo_dbpp!=req_bpp ) return 0; //support -bpp options
663 //scan all modes
664 lastmode = vga_lastmodenumber();
665 for(i=1;i<=lastmode;i++){
666 vminfo = vga_getmodeinfo(i);
667 if( vminfo == NULL ) continue;
668 if( vga_hasmode(i) == 0 ) continue;
669 if( req_bpp != bpp_from_vminfo(vminfo) ) continue;
670 if( (force_vm > 0) && (force_vm != i) ) continue;//quick hack
671 flags = VFCAP_CSP_SUPPORTED|
672 VFCAP_CSP_SUPPORTED_BY_HW|
673 VFCAP_ACCEPT_STRIDE|
675 if(req_bpp>8) flags|=VFCAP_OSD;
676 return flags;
678 return 0;
681 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
682 unsigned char *srca, int stride) {
683 char* base;
685 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
686 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",
687 x0,y0,w,h,src,srca,stride);
688 if(!blackbar_osd) {
689 //drawing in the image, so place the stuff there
690 x0+=x_pos;
691 y0+=y_pos;
694 if( mp_msg_test(MSGT_VO,MSGL_DBG4) )
695 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: OSD draw in page %d\n",cpage);
696 base=PageStore[cpage].vbase + y0*mode_stride + x0*modeinfo->bytesperpixel;
697 switch (mode_bpp) {
698 case 32:
699 vo_draw_alpha_rgb32(w, h, src, srca, stride, base, mode_stride);
700 break;
701 case 24:
702 vo_draw_alpha_rgb24(w, h, src, srca, stride, base, mode_stride);
703 break;
704 case 16:
705 vo_draw_alpha_rgb16(w, h, src, srca, stride, base, mode_stride);
706 break;
707 case 15:
708 vo_draw_alpha_rgb15(w, h, src, srca, stride, base, mode_stride);
709 break;
713 static uint32_t get_image(mp_image_t *mpi){
714 int page;
716 if(!IMGFMT_IS_BGR(mpi->imgfmt) && !IMGFMT_IS_RGB(mpi->imgfmt) ){
717 assert(0);//should never happen
718 return VO_FALSE;
721 if (
722 ( (mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) ||
723 (mpi->flags & MP_IMGFLAG_PLANAR) ||
724 (mpi->flags & MP_IMGFLAG_YUV)
726 return VO_FALSE;
728 //reading from video memory is horribly slow
729 if( !(mpi->flags & MP_IMGFLAG_READABLE) && vo_directrendering &&
730 (mode_capabilities & CAP_LINEAR) ){
732 //find free page and reserve it
733 page=page_find_free();
734 if(page >= 0){
735 PageStore[page].locks=PAGE_BUSY;
737 mpi->flags |= MP_IMGFLAG_DIRECT;
738 mpi->stride[0] = mode_stride;
739 mpi->planes[0] = PageStore[page].vbase +
740 y_pos*mode_stride + (x_pos*mpi->bpp)/8;
741 mpi->priv=(void *)page;
742 if( mp_msg_test(MSGT_VO,MSGL_DBG3) )
743 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: direct render allocated! page=%d\n",page);
744 return VO_TRUE;
748 return VO_FALSE;