cosmetics: av_sub
[mplayer/greg.git] / libvo / vo_svga.c
blob1435d1ecdcc78b71b87b03fba8f20bed8bc3830e
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 "mp_image.h"
67 #include <assert.h>
69 //silence warnings, probably it have to go in some global header
70 #define UNUSED(x) ((void)(x))
73 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
74 unsigned char *srca, int stride);
75 static uint32_t get_image(mp_image_t *mpi);
77 #define MAXPAGES 16
78 #define PAGE_EMPTY 0
79 #define PAGE_BUSY 1
81 #define CAP_ACCEL_CLEAR 8
82 #define CAP_ACCEL_PUTIMAGE 4
83 #define CAP_ACCEL_BACKGR 2
84 #define CAP_LINEAR 1
86 static uint8_t zerobuf[8192];//used when clear screen with vga_draw
88 static int squarepix;
89 static int force_vm=0;
90 static int force_native=0;
91 static int sync_flip=0;
92 static int blackbar_osd=0;
93 static int cpage,max_pages,old_page;
95 static vga_modeinfo * modeinfo;
96 static int mode_stride; //keep it in case of vga_setlogicalwidth
97 static int stride_granularity; //not yet used
98 static int mode_bpp;
99 static int mode_capabilities;
101 static int image_width,image_height; // used by OSD
102 static int x_pos, y_pos;
104 static struct {
105 int yoffset;//y position of the page
106 int doffset;//display start of the page
107 uint8_t * vbase;//memory start address of the page
108 int locks;
109 }PageStore[MAXPAGES];
111 static const vo_info_t info = {
112 "SVGAlib",
113 "svga",
114 "Ivan Kalvachev <iive@users.sf.net>",
118 #ifdef CONFIG_VIDIX
119 static char vidix_name[32] = "";
120 static vidix_grkey_t gr_key;
121 #endif
123 LIBVO_EXTERN(svga)
126 //return number of 1'st free page or -1 if no free one
127 static inline int page_find_free(void){
128 int i;
129 for(i=0;i<max_pages;i++)
130 if(PageStore[i].locks == PAGE_EMPTY) return i;
131 return -1;
134 static int preinit(const char *arg)
136 int i,rez;
137 char s[64];
139 getch2_disable();
140 memset(zerobuf,0,sizeof(zerobuf));
141 force_vm=force_native=squarepix=0;
142 sync_flip=vo_vsync;
143 blackbar_osd=0;
145 if(arg)while(*arg) {
146 #ifdef CONFIG_VIDIX
147 if(memcmp(arg,"vidix",5)==0) {
148 i=6;
149 while(arg[i] && arg[i]!=':') i++;
150 strncpy(vidix_name, arg+6, i-6);
151 vidix_name[i-5]=0;
152 if(arg[i]==':')i++;
153 arg+=i;
154 vidix_preinit(vidix_name, video_out_svga.old_functions);
156 #endif
157 if(!strncmp(arg,"sq",2)) {
158 squarepix=1;
159 arg+=2;
160 if( *arg == ':' ) arg++;
163 if(!strncmp(arg,"native",6)) {
164 force_native=1;
165 arg+=6;
166 if( *arg == ':' ) arg++;
169 if(!strncmp(arg,"bbosd",5)) {
170 blackbar_osd=1;
171 arg+=5;
172 if( *arg == ':' ) arg++;
175 if(!strncmp(arg,"retrace",7)) {
176 sync_flip=1;
177 arg+=7;
178 if( *arg == ':' ) arg++;
181 if(*arg) {
182 i=0;
183 while(arg[i] && arg[i]!=':')i++;
184 if(i<64){
185 strncpy(s, arg, i);
186 s[i]=0;
188 force_vm=vga_getmodenumber(s);
189 if(force_vm>0) {
190 mp_msg(MSGT_VO,MSGL_V, "vo_svga: Forcing mode %i\n",force_vm);
191 }else{
192 force_vm = 0;
195 arg+=i;
196 if(*arg==':')arg++;
200 rez = vga_init();
201 if(rez != 0){
202 mp_msg(MSGT_VO,MSGL_ERR, "vo_svga: vga_init() returned error=%d\n",rez);
204 return !!rez;
207 static void svga_clear_box(int x,int y,int w,int h){
208 uint8_t * rgbplane;
209 int i;
211 if (mode_capabilities&CAP_ACCEL_CLEAR){
212 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with HW acceleration\n",
213 x,y,w,h);
214 if(mode_capabilities&CAP_ACCEL_BACKGR)
215 vga_accel(ACCEL_SYNC);
216 vga_accel(ACCEL_SETFGCOLOR,0);//black
217 vga_accel(ACCEL_FILLBOX,x,y,w,h);
218 return;
220 if (mode_capabilities & CAP_LINEAR){
221 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with memset\n",x,y,w,h);
222 rgbplane=PageStore[0].vbase + (y*mode_stride) + (x*modeinfo->bytesperpixel);
223 for(i=0;i<h;i++){
224 //i'm afraid that memcpy is better optimized than memset;)
225 fast_memcpy(rgbplane,zerobuf,w*modeinfo->bytesperpixel);
226 // memset(rgbplane,0,w*modeinfo->bytesperpixel);
227 rgbplane+=mode_stride;
229 return;
231 //native
232 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with native draw \n",x,y,w,h);
233 if(modeinfo->bytesperpixel!=0) w*=modeinfo->bytesperpixel;
234 for(i=0;i<h;i++){
235 vga_drawscansegment(zerobuf,x,y+i,w);
239 static uint32_t svga_draw_image(mp_image_t *mpi){
240 int i,x,y,w,h;
241 int stride;
242 uint8_t *rgbplane, *base;
243 int bytesperline;
244 int page;
246 if(mpi->flags & MP_IMGFLAG_DIRECT){
247 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: drawing direct rendered surface\n");
248 cpage=(uint32_t)mpi->priv;
249 assert((cpage>=0)&&(cpage<max_pages));
250 return VO_TRUE; //it's already done
252 // if (mpi->flags&MP_IMGFLAGS_DRAWBACK)
253 // return VO_TRUE;//direct render method 2
255 //find a free page to draw into
256 //if there is no one then use the current one
257 page = page_find_free();
258 if(page>=0) cpage=page;
259 PageStore[cpage].locks=PAGE_BUSY;
261 // these variables are used in loops
262 x = mpi->x;
263 y = mpi->y;
264 w = mpi->w;
265 h = mpi->h;
266 stride = mpi->stride[0];
267 rgbplane = mpi->planes[0] + y*stride + (x*mpi->bpp)/8;
268 x+=x_pos;//center
269 y+=y_pos;
271 if(mpi->bpp >= 8){//for modes<8 use only native
272 if( (mode_capabilities&CAP_ACCEL_PUTIMAGE) && (x==0) && (w==mpi->width) &&
273 (stride == mode_stride) ){ //only monolite image can be accelerated
274 w=(stride*8)/mpi->bpp;//we transfer pixels in the stride so the source
275 //ACCELERATE
276 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using HW PutImage (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
277 if(mode_capabilities & CAP_ACCEL_BACKGR)
278 vga_accel(ACCEL_SYNC);
280 vga_accel(ACCEL_PUTIMAGE,x,y+PageStore[cpage].yoffset,w,h,rgbplane);
281 return VO_TRUE;
284 if( mode_capabilities&CAP_LINEAR){
285 //DIRECT
286 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using Direct memcpy (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
287 bytesperline=(w*mpi->bpp)/8;
288 base=PageStore[cpage].vbase + (y*mode_stride) + (x*mpi->bpp)/8;
290 for(i=0;i<h;i++){
291 mem2agpcpy(base,rgbplane,bytesperline);
292 base+=mode_stride;
293 rgbplane+=stride;
295 return VO_TRUE;
297 }//(modebpp>=8
300 //NATIVE
302 int length;
303 length=(w*mpi->bpp)/8;
304 //one byte per pixel! svgalib innovation
305 if(mpi->imgfmt==IMGFMT_RG4B || mpi->imgfmt==IMGFMT_BG4B) length=w;
307 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);
308 y+=PageStore[cpage].yoffset;//y position of the page beggining
309 for(i=0;i<h;i++){
310 vga_drawscansegment(rgbplane,x,y+i,length);
311 rgbplane+=stride;
314 return VO_TRUE;
317 static int bpp_from_vminfo(vga_modeinfo *vminfo){
318 switch(vminfo->colors){
319 case 2: return 1;
320 case 16: return 4;
321 case 256: return 8;
322 case 32768: return 15;
323 case 65536: return 16;
324 case 1<<24: return 8*vminfo->bytesperpixel;
326 return 0;
329 static int find_best_svga_mode(int req_w,int req_h, int req_bpp){
330 int badness,prev_badness;
331 int bestmode,lastmode;
332 int i;
333 vga_modeinfo *vminfo;
334 //int best aspect mode // best linear mode // best normal mode (no modeX)
336 prev_badness = 0;//take care of special case below
337 bestmode = 0; //0 is the TEXT mode
338 lastmode = vga_lastmodenumber();
339 for(i=1;i<=lastmode;i++){
340 vminfo = vga_getmodeinfo(i);
341 if( vminfo == NULL ) continue;
342 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: testing mode %d (%s)\n",i,vga_getmodename(i));
343 if( vga_hasmode(i) == 0 ) continue;
344 if( req_bpp != bpp_from_vminfo(vminfo) )continue;
345 if( (vminfo->width < req_w) || (vminfo->height < req_h) ) continue;
346 badness=(vminfo->width * vminfo->height) - (req_h * req_w);
347 //put here aspect calculations
348 if(squarepix)
349 if( vminfo->width*3 != vminfo->height*4 ) continue;
351 if( bestmode==0 || prev_badness >= badness ){//modeX etc...
352 prev_badness=badness;
353 bestmode=i;
354 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: found good mode %d with badness %d\n",i,badness);
357 return bestmode;
360 static int control(uint32_t request, void *data)
362 switch (request) {
363 case VOCTRL_QUERY_FORMAT:
364 return query_format(*((uint32_t*)data));
365 case VOCTRL_DRAW_IMAGE:
366 return svga_draw_image( (mp_image_t *)data);
367 case VOCTRL_GET_IMAGE:
368 return get_image(data);
371 #ifdef CONFIG_VIDIX
372 if (vidix_name[0])
373 return vidix_control(request, data);
374 #endif
376 return VO_NOTIMPL;
380 // This function is called to init the video driver for specific mode
382 static int config(uint32_t width, uint32_t height, uint32_t d_width,
383 uint32_t d_height, uint32_t flags, char *title,
384 uint32_t format) {
385 int32_t req_w = width;// (d_width > 0 ? d_width : width);
386 int32_t req_h = height;// (d_height > 0 ? d_height : height);
387 uint16_t vid_mode = 0;
388 int32_t req_bpp;
390 uint32_t accflags;
391 mp_msg(MSGT_VO,MSGL_V, "vo_svga: config(%i, %i, %i, %i, %08x, %s, %08x)\n", width, height,
392 d_width, d_height, flags, title, format);
393 //Only RGB modes supported
394 if (!IMGFMT_IS_RGB(format) && !IMGFMT_IS_BGR(format)) {assert(0);return -1;}
395 req_bpp = IMGFMT_BGR_DEPTH(format);
397 if( vo_dbpp!=0 && vo_dbpp!=req_bpp) {assert(0);return-1;}
399 if(!force_vm) {
400 mp_msg(MSGT_VO,MSGL_V, "vo_svga: Looking for the best resolution...\n");
401 mp_msg(MSGT_VO,MSGL_V, "vo_svga: req_w: %d, req_h: %d, bpp: %d\n",req_w,req_h,req_bpp);
402 vid_mode=find_best_svga_mode(req_w,req_h,req_bpp);
403 if(vid_mode==0)
404 return 1;
405 modeinfo=vga_getmodeinfo(vid_mode);
406 }else{//force_vm
407 vid_mode=force_vm;
408 if(vga_hasmode(vid_mode) == 0){
409 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_SVGA] Forced vid_mode %d (%s) not available.\n",
410 vid_mode,vga_getmodename(vid_mode));
411 return 1; //error;
413 modeinfo=vga_getmodeinfo(vid_mode);
414 if( (modeinfo->width < req_w) || (modeinfo->height < req_h) ){
415 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_SVGA] Forced vid_mode %d (%s) too small.\n",
416 vid_mode,vga_getmodename(vid_mode));
417 return 1;
420 mode_bpp=bpp_from_vminfo(modeinfo);
422 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Vid_mode: %d, %dx%d %dbpp.\n",
423 vid_mode,modeinfo->width,modeinfo->height,mode_bpp);
425 if (vga_setmode(vid_mode) == -1) {
426 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_SVGA] Vga_setmode(%d) failed.\n",vid_mode);
427 uninit();
428 return 1; // error
430 /* set 332 palette for 8 bpp */
431 if(mode_bpp==8){
432 int i;
433 for(i=0; i<256; i++)
434 vga_setpalette(i, ((i>>5)&7)*9, ((i>>2)&7)*9, (i&3)*21);
436 /* set 121 palette for 4 bpp */
437 else if(mode_bpp==4){
438 int i;
439 for(i=0; i<16; i++)
440 vga_setpalette(i, ((i>>3)&1)*63, ((i>>1)&3)*21, (i&1)*63);
442 //if we change the logical width, we should know the granularity
443 stride_granularity=8;//according to man vga_logicalwidth
444 if(modeinfo->flags & EXT_INFO_AVAILABLE){
445 stride_granularity=modeinfo->linewidth_unit;
447 //look for hardware acceleration
448 mode_capabilities=0;//NATIVE;
449 if(!force_native){//if we want to use only native drawers
450 if(modeinfo->flags & HAVE_EXT_SET){//support for hwaccel interface
451 accflags=vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_ACCEL);
452 if(accflags & ACCELFLAG_FILLBOX) // clear screen
453 mode_capabilities|=CAP_ACCEL_CLEAR;
454 if(accflags & ACCELFLAG_PUTIMAGE)//support for mem->vid transfer
455 mode_capabilities|=CAP_ACCEL_PUTIMAGE;
456 if((accflags & ACCELFLAG_SETMODE) && (accflags & ACCELFLAG_SYNC)){
457 vga_accel(ACCEL_SETMODE,BLITS_IN_BACKGROUND);
458 mode_capabilities|=CAP_ACCEL_BACKGR;//can draw in backgraund
461 if(modeinfo->flags & IS_LINEAR){
462 mode_capabilities|=CAP_LINEAR; //don't use bank & vga_draw
464 else{
465 if(modeinfo->flags & CAPABLE_LINEAR){
466 int vid_mem_size;
467 vid_mem_size = vga_setlinearaddressing();
468 if(vid_mem_size != -1){
469 modeinfo=vga_getmodeinfo(vid_mode);//sometimes they change parameters
470 mode_capabilities|=CAP_LINEAR;
474 }//fi force native
475 if(mode_capabilities&CAP_LINEAR){
476 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Video mode is linear and memcpy could be used for image transfer.\n");
478 if(mode_capabilities&CAP_ACCEL_PUTIMAGE){
479 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Video mode has hardware acceleration and put_image could be used.\n");
480 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] If it works for you I would like to know.\n[VO_SVGA] (send log with `mplayer test.avi -v -v -v -v &> svga.log`). Thx!\n");
483 //here is the place to handle strides for accel_ modes;
484 mode_stride=modeinfo->linewidth;
485 //we may try to set a bigger stride for video mode that will match the mpi->stride,
486 //this way we will transfer more data, but HW put_image can do it in backgraund!
488 //now let's see how many pages we can use
489 max_pages = modeinfo->maxpixels/(modeinfo->height * modeinfo->width);
490 if(max_pages > MAXPAGES) max_pages = MAXPAGES;
491 if(!vo_doublebuffering) max_pages=1;
492 //fill PageStore structs
494 int i;
495 uint8_t * GRAPH_MEM;
496 int dof;
497 GRAPH_MEM=vga_getgraphmem();
498 for(i=0;i<max_pages;i++){
499 //calculate display offset
500 dof = i * modeinfo->height * modeinfo->width;
501 if(modeinfo->bytesperpixel != 0) dof*=modeinfo->bytesperpixel;
502 //check video chip limitations
503 if( dof != (dof & modeinfo->startaddressrange) ){
504 max_pages=i;//page 0 will never come here
505 break;
507 PageStore[i].yoffset = i * modeinfo->height;//starting y offset
508 PageStore[i].vbase = GRAPH_MEM + i*modeinfo->height*mode_stride; //memory base address
509 PageStore[i].doffset = dof; //display offset
510 PageStore[i].locks = PAGE_EMPTY;
513 assert(max_pages>0);
514 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Video mode has %d page(s).\n",max_pages);
515 //15bpp
516 if(modeinfo->bytesperpixel!=0)
517 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * modeinfo->bytesperpixel);
518 else
519 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * mode_bpp / 8);
521 cpage=old_page=0;
522 svga_clear_box(0,0,modeinfo->width,modeinfo->height * max_pages);
524 image_height=req_h;
525 image_width=req_w;
526 x_pos = (modeinfo->width - req_w) / 2;
527 y_pos = (modeinfo->height - req_h) / 2;
528 x_pos &= ~(15); //align x offset position to 16 pixels
529 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Centering image. Starting at (%d,%d)\n",x_pos,y_pos);
531 #ifdef CONFIG_VIDIX
533 if(vidix_name[0]){
534 vidix_init(width, height, x_pos, y_pos, modeinfo->width, modeinfo->height,
535 format, mode_bpp, modeinfo->width,modeinfo->height);
536 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Using VIDIX. w=%i h=%i mw=%i mh=%i\n",width,height,
537 modeinfo->width,modeinfo->height);
538 vidix_start();
539 /*set colorkey*/
540 if(vidix_grkey_support()){
541 vidix_grkey_get(&gr_key);
542 gr_key.key_op = KEYS_PUT;
543 if (!(vo_colorkey & 0xFF000000)) {
544 gr_key.ckey.op = CKEY_TRUE;
545 gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
546 gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
547 gr_key.ckey.blue = vo_colorkey & 0x000000FF;
548 } else
549 gr_key.ckey.op = CKEY_FALSE;
550 vidix_grkey_set(&gr_key);
553 #endif
555 vga_setdisplaystart(0);
556 return 0;
559 static int draw_slice(uint8_t *image[],int stride[],
560 int w, int h, int x, int y) {
561 assert(0);
562 UNUSED(image);UNUSED(stride);
563 UNUSED(w);UNUSED(h);
564 UNUSED(x);UNUSED(y);
566 return VO_ERROR;//this is yv12 only -> vf_scale should do all transforms
569 static int draw_frame(uint8_t *src[]) {
570 assert(0);
571 UNUSED(src);
572 return VO_ERROR;//this one should not be called
575 static void draw_osd(void)
577 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: draw_osd()\n");
578 //only modes with bytesperpixel>0 can draw OSD
579 if(modeinfo->bytesperpixel==0) return;
580 if(!(mode_capabilities&CAP_LINEAR)) return;//force_native will remove OSD
582 if(blackbar_osd){
583 //111
584 //3 4
585 //222
586 svga_clear_box(0,0 + PageStore[cpage].yoffset,
587 modeinfo->width, y_pos);
588 svga_clear_box(0, image_height + y_pos + PageStore[cpage].yoffset,
589 modeinfo->width, modeinfo->height-(image_height+ y_pos));
590 svga_clear_box(0, y_pos + PageStore[cpage].yoffset,
591 x_pos, image_height);
592 svga_clear_box(image_width + x_pos, y_pos + PageStore[cpage].yoffset,
593 modeinfo->width-(x_pos+image_width), image_height);
594 // vo_remove_text(modeinfo->width, modeinfo->height, clear_alpha);
595 vo_draw_text(modeinfo->width, modeinfo->height, draw_alpha);
596 }else{
597 vo_draw_text(image_width, image_height, draw_alpha);
601 static void flip_page(void) {
602 PageStore[old_page].locks=PAGE_EMPTY;
603 PageStore[cpage].locks=PAGE_BUSY;
605 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: viewing page %d\n",cpage);
606 if(sync_flip && old_page!=cpage){
607 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga:vga_waitretrace\n");
608 vga_waitretrace();
610 vga_setdisplaystart(PageStore[cpage].doffset);
612 old_page=cpage;//cpage will be overwriten on next draw_image
615 static void check_events(void) {
618 static void uninit(void) {
620 #ifdef CONFIG_VIDIX
621 if(vidix_name[0])vidix_term();
622 #endif
623 vga_setmode(TEXT);
626 /* --------------------------------------------------------------------- */
627 static int query_format(uint32_t format) {
628 int32_t req_bpp,flags;
629 int i,lastmode;
630 vga_modeinfo * vminfo;
632 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: query_format=%X \n",format);
633 //only RGB modes supported
634 if( (!IMGFMT_IS_RGB(format)) && (!IMGFMT_IS_BGR(format)) ) return 0;
636 // Reject different endian
637 #if HAVE_BIGENDIAN
638 if (IMGFMT_IS_BGR(format)) return 0;
639 #else
640 if (IMGFMT_IS_RGB(format)) return 0;
641 #endif
643 //svgalib supports only BG4B! if we want BGR4 we have to emulate it (sw)
644 if( format==IMGFMT_BGR4 || format==IMGFMT_RGB4) return 0;
645 req_bpp = IMGFMT_RGB_DEPTH(format);
646 if( vo_dbpp>0 && vo_dbpp!=req_bpp ) return 0; //support -bpp options
647 //scan all modes
648 lastmode = vga_lastmodenumber();
649 for(i=1;i<=lastmode;i++){
650 vminfo = vga_getmodeinfo(i);
651 if( vminfo == NULL ) continue;
652 if( vga_hasmode(i) == 0 ) continue;
653 if( req_bpp != bpp_from_vminfo(vminfo) ) continue;
654 if( (force_vm > 0) && (force_vm != i) ) continue;//quick hack
655 flags = VFCAP_CSP_SUPPORTED|
656 VFCAP_CSP_SUPPORTED_BY_HW|
657 VFCAP_ACCEPT_STRIDE|
659 if(req_bpp>8) flags|=VFCAP_OSD;
660 return flags;
662 return 0;
665 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
666 unsigned char *srca, int stride) {
667 char* base;
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 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: OSD draw in page %d\n",cpage);
678 base=PageStore[cpage].vbase + y0*mode_stride + x0*modeinfo->bytesperpixel;
679 switch (mode_bpp) {
680 case 32:
681 vo_draw_alpha_rgb32(w, h, src, srca, stride, base, mode_stride);
682 break;
683 case 24:
684 vo_draw_alpha_rgb24(w, h, src, srca, stride, base, mode_stride);
685 break;
686 case 16:
687 vo_draw_alpha_rgb16(w, h, src, srca, stride, base, mode_stride);
688 break;
689 case 15:
690 vo_draw_alpha_rgb15(w, h, src, srca, stride, base, mode_stride);
691 break;
695 static uint32_t get_image(mp_image_t *mpi){
696 int page;
698 if(!IMGFMT_IS_BGR(mpi->imgfmt) && !IMGFMT_IS_RGB(mpi->imgfmt) ){
699 assert(0);//should never happen
700 return VO_FALSE;
703 if (
704 ( (mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) ||
705 (mpi->flags & MP_IMGFLAG_PLANAR) ||
706 (mpi->flags & MP_IMGFLAG_YUV)
708 return VO_FALSE;
710 //reading from video memory is horribly slow
711 if( !(mpi->flags & MP_IMGFLAG_READABLE) && vo_directrendering &&
712 (mode_capabilities & CAP_LINEAR) ){
714 //find free page and reserve it
715 page=page_find_free();
716 if(page >= 0){
717 PageStore[page].locks=PAGE_BUSY;
719 mpi->flags |= MP_IMGFLAG_DIRECT;
720 mpi->stride[0] = mode_stride;
721 mpi->planes[0] = PageStore[page].vbase +
722 y_pos*mode_stride + (x_pos*mpi->bpp)/8;
723 mpi->priv=(void *)page;
724 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: direct render allocated! page=%d\n",page);
725 return VO_TRUE;
729 return VO_FALSE;