audio: fill small AO buffers more often in audio-only case
[mplayer.git] / libvo / vo_svga.c
blob3afb8e36a235187e864c57f64453053f1d5ee01c
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"
59 #include "sub/sub.h"
61 #include "mp_msg.h"
62 //#include "mp_image.h"
64 #include <assert.h>
67 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
68 unsigned char *srca, int stride);
69 static uint32_t get_image(mp_image_t *mpi);
71 #define MAXPAGES 16
72 #define PAGE_EMPTY 0
73 #define PAGE_BUSY 1
75 #define CAP_ACCEL_CLEAR 8
76 #define CAP_ACCEL_PUTIMAGE 4
77 #define CAP_ACCEL_BACKGR 2
78 #define CAP_LINEAR 1
80 static uint8_t zerobuf[8192];//used when clear screen with vga_draw
82 static int squarepix;
83 static int force_vm=0;
84 static int force_native=0;
85 static int sync_flip=0;
86 static int blackbar_osd=0;
87 static int cpage,max_pages,old_page;
89 static vga_modeinfo * modeinfo;
90 static int mode_stride; //keep it in case of vga_setlogicalwidth
91 static int stride_granularity; //not yet used
92 static int mode_bpp;
93 static int mode_capabilities;
95 static int image_width,image_height; // used by OSD
96 static int x_pos, y_pos;
98 static struct {
99 int yoffset;//y position of the page
100 int doffset;//display start of the page
101 uint8_t * vbase;//memory start address of the page
102 int locks;
103 }PageStore[MAXPAGES];
105 static const vo_info_t info = {
106 "SVGAlib",
107 "svga",
108 "Ivan Kalvachev <iive@users.sf.net>",
112 LIBVO_EXTERN(svga)
115 //return number of 1'st free page or -1 if no free one
116 static inline int page_find_free(void){
117 int i;
118 for(i=0;i<max_pages;i++)
119 if(PageStore[i].locks == PAGE_EMPTY) return i;
120 return -1;
123 static int preinit(const char *arg)
125 int i,rez;
126 char s[64];
128 getch2_disable();
129 memset(zerobuf,0,sizeof(zerobuf));
130 force_vm=force_native=squarepix=0;
131 sync_flip=vo_vsync;
132 blackbar_osd=0;
134 if(arg)while(*arg) {
135 if(!strncmp(arg,"sq",2)) {
136 squarepix=1;
137 arg+=2;
138 if( *arg == ':' ) arg++;
141 if(!strncmp(arg,"native",6)) {
142 force_native=1;
143 arg+=6;
144 if( *arg == ':' ) arg++;
147 if(!strncmp(arg,"bbosd",5)) {
148 blackbar_osd=1;
149 arg+=5;
150 if( *arg == ':' ) arg++;
153 if(!strncmp(arg,"retrace",7)) {
154 sync_flip=1;
155 arg+=7;
156 if( *arg == ':' ) arg++;
159 if(*arg) {
160 i=0;
161 while(arg[i] && arg[i]!=':')i++;
162 if(i<64){
163 strncpy(s, arg, i);
164 s[i]=0;
166 force_vm=vga_getmodenumber(s);
167 if(force_vm>0) {
168 mp_msg(MSGT_VO,MSGL_V, "vo_svga: Forcing mode %i\n",force_vm);
169 }else{
170 force_vm = 0;
173 arg+=i;
174 if(*arg==':')arg++;
178 rez = vga_init();
179 if(rez != 0){
180 mp_msg(MSGT_VO,MSGL_ERR, "vo_svga: vga_init() returned error=%d\n",rez);
182 return !!rez;
185 static void svga_clear_box(int x,int y,int w,int h){
186 uint8_t * rgbplane;
187 int i;
189 if (mode_capabilities&CAP_ACCEL_CLEAR){
190 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with HW acceleration\n",
191 x,y,w,h);
192 if(mode_capabilities&CAP_ACCEL_BACKGR)
193 vga_accel(ACCEL_SYNC);
194 vga_accel(ACCEL_SETFGCOLOR,0);//black
195 vga_accel(ACCEL_FILLBOX,x,y,w,h);
196 return;
198 if (mode_capabilities & CAP_LINEAR){
199 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with memset\n",x,y,w,h);
200 rgbplane=PageStore[0].vbase + (y*mode_stride) + (x*modeinfo->bytesperpixel);
201 for(i=0;i<h;i++){
202 //i'm afraid that memcpy is better optimized than memset;)
203 fast_memcpy(rgbplane,zerobuf,w*modeinfo->bytesperpixel);
204 // memset(rgbplane,0,w*modeinfo->bytesperpixel);
205 rgbplane+=mode_stride;
207 return;
209 //native
210 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with native draw \n",x,y,w,h);
211 if(modeinfo->bytesperpixel!=0) w*=modeinfo->bytesperpixel;
212 for(i=0;i<h;i++){
213 vga_drawscansegment(zerobuf,x,y+i,w);
217 static uint32_t svga_draw_image(mp_image_t *mpi){
218 int i,x,y,w,h;
219 int stride;
220 uint8_t *rgbplane, *base;
221 int bytesperline;
222 int page;
224 if(mpi->flags & MP_IMGFLAG_DIRECT){
225 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: drawing direct rendered surface\n");
226 cpage=(uint32_t)mpi->priv;
227 assert((cpage>=0)&&(cpage<max_pages));
228 return VO_TRUE; //it's already done
230 // if (mpi->flags&MP_IMGFLAGS_DRAWBACK)
231 // return VO_TRUE;//direct render method 2
233 //find a free page to draw into
234 //if there is no one then use the current one
235 page = page_find_free();
236 if(page>=0) cpage=page;
237 PageStore[cpage].locks=PAGE_BUSY;
239 // these variables are used in loops
240 x = mpi->x;
241 y = mpi->y;
242 w = mpi->w;
243 h = mpi->h;
244 stride = mpi->stride[0];
245 rgbplane = mpi->planes[0] + y*stride + (x*mpi->bpp)/8;
246 x+=x_pos;//center
247 y+=y_pos;
249 if(mpi->bpp >= 8){//for modes<8 use only native
250 if( (mode_capabilities&CAP_ACCEL_PUTIMAGE) && (x==0) && (w==mpi->width) &&
251 (stride == mode_stride) ){ //only monolite image can be accelerated
252 w=(stride*8)/mpi->bpp;//we transfer pixels in the stride so the source
253 //ACCELERATE
254 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using HW PutImage (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
255 if(mode_capabilities & CAP_ACCEL_BACKGR)
256 vga_accel(ACCEL_SYNC);
258 vga_accel(ACCEL_PUTIMAGE,x,y+PageStore[cpage].yoffset,w,h,rgbplane);
259 return VO_TRUE;
262 if( mode_capabilities&CAP_LINEAR){
263 //DIRECT
264 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using Direct memcpy (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
265 bytesperline=(w*mpi->bpp)/8;
266 base=PageStore[cpage].vbase + (y*mode_stride) + (x*mpi->bpp)/8;
268 for(i=0;i<h;i++){
269 mem2agpcpy(base,rgbplane,bytesperline);
270 base+=mode_stride;
271 rgbplane+=stride;
273 return VO_TRUE;
275 }//(modebpp>=8
278 //NATIVE
280 int length;
281 length=(w*mpi->bpp)/8;
282 //one byte per pixel! svgalib innovation
283 if(mpi->imgfmt==IMGFMT_RG4B || mpi->imgfmt==IMGFMT_BG4B) length=w;
285 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);
286 y+=PageStore[cpage].yoffset;//y position of the page beggining
287 for(i=0;i<h;i++){
288 vga_drawscansegment(rgbplane,x,y+i,length);
289 rgbplane+=stride;
292 return VO_TRUE;
295 static int bpp_from_vminfo(vga_modeinfo *vminfo){
296 switch(vminfo->colors){
297 case 2: return 1;
298 case 16: return 4;
299 case 256: return 8;
300 case 32768: return 15;
301 case 65536: return 16;
302 case 1<<24: return 8*vminfo->bytesperpixel;
304 return 0;
307 static int find_best_svga_mode(int req_w,int req_h, int req_bpp){
308 int badness,prev_badness;
309 int bestmode,lastmode;
310 int i;
311 vga_modeinfo *vminfo;
312 //int best aspect mode // best linear mode // best normal mode (no modeX)
314 prev_badness = 0;//take care of special case below
315 bestmode = 0; //0 is the TEXT mode
316 lastmode = vga_lastmodenumber();
317 for(i=1;i<=lastmode;i++){
318 vminfo = vga_getmodeinfo(i);
319 if( vminfo == NULL ) continue;
320 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: testing mode %d (%s)\n",i,vga_getmodename(i));
321 if( vga_hasmode(i) == 0 ) continue;
322 if( req_bpp != bpp_from_vminfo(vminfo) )continue;
323 if( (vminfo->width < req_w) || (vminfo->height < req_h) ) continue;
324 badness=(vminfo->width * vminfo->height) - (req_h * req_w);
325 //put here aspect calculations
326 if(squarepix)
327 if( vminfo->width*3 != vminfo->height*4 ) continue;
329 if( bestmode==0 || prev_badness >= badness ){//modeX etc...
330 prev_badness=badness;
331 bestmode=i;
332 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: found good mode %d with badness %d\n",i,badness);
335 return bestmode;
338 static int control(uint32_t request, void *data)
340 switch (request) {
341 case VOCTRL_QUERY_FORMAT:
342 return query_format(*((uint32_t*)data));
343 case VOCTRL_DRAW_IMAGE:
344 return svga_draw_image( (mp_image_t *)data);
345 case VOCTRL_GET_IMAGE:
346 return get_image(data);
349 return VO_NOTIMPL;
353 // This function is called to init the video driver for specific mode
355 static int config(uint32_t width, uint32_t height, uint32_t d_width,
356 uint32_t d_height, uint32_t flags, char *title,
357 uint32_t format) {
358 int32_t req_w = width;// (d_width > 0 ? d_width : width);
359 int32_t req_h = height;// (d_height > 0 ? d_height : height);
360 uint16_t vid_mode = 0;
361 int32_t req_bpp;
363 uint32_t accflags;
364 mp_msg(MSGT_VO,MSGL_V, "vo_svga: config(%i, %i, %i, %i, %08x, %s, %08x)\n", width, height,
365 d_width, d_height, flags, title, format);
366 //Only RGB modes supported
367 if (!IMGFMT_IS_RGB(format) && !IMGFMT_IS_BGR(format)) {assert(0);return -1;}
368 req_bpp = IMGFMT_BGR_DEPTH(format);
370 if( vo_dbpp!=0 && vo_dbpp!=req_bpp) {assert(0);return-1;}
372 if(!force_vm) {
373 mp_msg(MSGT_VO,MSGL_V, "vo_svga: Looking for the best resolution...\n");
374 mp_msg(MSGT_VO,MSGL_V, "vo_svga: req_w: %d, req_h: %d, bpp: %d\n",req_w,req_h,req_bpp);
375 vid_mode=find_best_svga_mode(req_w,req_h,req_bpp);
376 if(vid_mode==0)
377 return 1;
378 modeinfo=vga_getmodeinfo(vid_mode);
379 }else{//force_vm
380 vid_mode=force_vm;
381 if(vga_hasmode(vid_mode) == 0){
382 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_SVGA] Forced vid_mode %d (%s) not available.\n",
383 vid_mode,vga_getmodename(vid_mode));
384 return 1; //error;
386 modeinfo=vga_getmodeinfo(vid_mode);
387 if( (modeinfo->width < req_w) || (modeinfo->height < req_h) ){
388 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_SVGA] Forced vid_mode %d (%s) too small.\n",
389 vid_mode,vga_getmodename(vid_mode));
390 return 1;
393 mode_bpp=bpp_from_vminfo(modeinfo);
395 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Vid_mode: %d, %dx%d %dbpp.\n",
396 vid_mode,modeinfo->width,modeinfo->height,mode_bpp);
398 if (vga_setmode(vid_mode) == -1) {
399 mp_tmsg(MSGT_VO,MSGL_ERR, "[VO_SVGA] Vga_setmode(%d) failed.\n",vid_mode);
400 uninit();
401 return 1; // error
403 /* set 332 palette for 8 bpp */
404 if(mode_bpp==8){
405 int i;
406 for(i=0; i<256; i++)
407 vga_setpalette(i, ((i>>5)&7)*9, ((i>>2)&7)*9, (i&3)*21);
409 /* set 121 palette for 4 bpp */
410 else if(mode_bpp==4){
411 int i;
412 for(i=0; i<16; i++)
413 vga_setpalette(i, ((i>>3)&1)*63, ((i>>1)&3)*21, (i&1)*63);
415 //if we change the logical width, we should know the granularity
416 stride_granularity=8;//according to man vga_logicalwidth
417 if(modeinfo->flags & EXT_INFO_AVAILABLE){
418 stride_granularity=modeinfo->linewidth_unit;
420 //look for hardware acceleration
421 mode_capabilities=0;//NATIVE;
422 if(!force_native){//if we want to use only native drawers
423 if(modeinfo->flags & HAVE_EXT_SET){//support for hwaccel interface
424 accflags=vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_ACCEL);
425 if(accflags & ACCELFLAG_FILLBOX) // clear screen
426 mode_capabilities|=CAP_ACCEL_CLEAR;
427 if(accflags & ACCELFLAG_PUTIMAGE)//support for mem->vid transfer
428 mode_capabilities|=CAP_ACCEL_PUTIMAGE;
429 if((accflags & ACCELFLAG_SETMODE) && (accflags & ACCELFLAG_SYNC)){
430 vga_accel(ACCEL_SETMODE,BLITS_IN_BACKGROUND);
431 mode_capabilities|=CAP_ACCEL_BACKGR;//can draw in backgraund
434 if(modeinfo->flags & IS_LINEAR){
435 mode_capabilities|=CAP_LINEAR; //don't use bank & vga_draw
437 else{
438 if(modeinfo->flags & CAPABLE_LINEAR){
439 int vid_mem_size;
440 vid_mem_size = vga_setlinearaddressing();
441 if(vid_mem_size != -1){
442 modeinfo=vga_getmodeinfo(vid_mode);//sometimes they change parameters
443 mode_capabilities|=CAP_LINEAR;
447 }//fi force native
448 if(mode_capabilities&CAP_LINEAR){
449 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Video mode is linear and memcpy could be used for image transfer.\n");
451 if(mode_capabilities&CAP_ACCEL_PUTIMAGE){
452 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Video mode has hardware acceleration and put_image could be used.\n");
453 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");
456 //here is the place to handle strides for accel_ modes;
457 mode_stride=modeinfo->linewidth;
458 //we may try to set a bigger stride for video mode that will match the mpi->stride,
459 //this way we will transfer more data, but HW put_image can do it in backgraund!
461 //now let's see how many pages we can use
462 max_pages = modeinfo->maxpixels/(modeinfo->height * modeinfo->width);
463 if(max_pages > MAXPAGES) max_pages = MAXPAGES;
464 if(!vo_doublebuffering) max_pages=1;
465 //fill PageStore structs
467 int i;
468 uint8_t * GRAPH_MEM;
469 int dof;
470 GRAPH_MEM=vga_getgraphmem();
471 for(i=0;i<max_pages;i++){
472 //calculate display offset
473 dof = i * modeinfo->height * modeinfo->width;
474 if(modeinfo->bytesperpixel != 0) dof*=modeinfo->bytesperpixel;
475 //check video chip limitations
476 if( dof != (dof & modeinfo->startaddressrange) ){
477 max_pages=i;//page 0 will never come here
478 break;
480 PageStore[i].yoffset = i * modeinfo->height;//starting y offset
481 PageStore[i].vbase = GRAPH_MEM + i*modeinfo->height*mode_stride; //memory base address
482 PageStore[i].doffset = dof; //display offset
483 PageStore[i].locks = PAGE_EMPTY;
486 assert(max_pages>0);
487 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Video mode has %d page(s).\n",max_pages);
488 //15bpp
489 if(modeinfo->bytesperpixel!=0)
490 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * modeinfo->bytesperpixel);
491 else
492 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * mode_bpp / 8);
494 cpage=old_page=0;
495 svga_clear_box(0,0,modeinfo->width,modeinfo->height * max_pages);
497 image_height=req_h;
498 image_width=req_w;
499 x_pos = (modeinfo->width - req_w) / 2;
500 y_pos = (modeinfo->height - req_h) / 2;
501 x_pos &= ~(15); //align x offset position to 16 pixels
502 mp_tmsg(MSGT_VO,MSGL_INFO, "[VO_SVGA] Centering image. Starting at (%d,%d)\n",x_pos,y_pos);
504 vga_setdisplaystart(0);
505 return 0;
508 static int draw_slice(uint8_t *image[],int stride[],
509 int w, int h, int x, int y) {
510 assert(0);
511 return VO_ERROR;//this is yv12 only -> vf_scale should do all transforms
514 static int draw_frame(uint8_t *src[]) {
515 assert(0);
516 return VO_ERROR;//this one should not be called
519 static void draw_osd(void)
521 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: draw_osd()\n");
522 //only modes with bytesperpixel>0 can draw OSD
523 if(modeinfo->bytesperpixel==0) return;
524 if(!(mode_capabilities&CAP_LINEAR)) return;//force_native will remove OSD
526 if(blackbar_osd){
527 //111
528 //3 4
529 //222
530 svga_clear_box(0,0 + PageStore[cpage].yoffset,
531 modeinfo->width, y_pos);
532 svga_clear_box(0, image_height + y_pos + PageStore[cpage].yoffset,
533 modeinfo->width, modeinfo->height-(image_height+ y_pos));
534 svga_clear_box(0, y_pos + PageStore[cpage].yoffset,
535 x_pos, image_height);
536 svga_clear_box(image_width + x_pos, y_pos + PageStore[cpage].yoffset,
537 modeinfo->width-(x_pos+image_width), image_height);
538 // vo_remove_text(modeinfo->width, modeinfo->height, clear_alpha);
539 vo_draw_text(modeinfo->width, modeinfo->height, draw_alpha);
540 }else{
541 vo_draw_text(image_width, image_height, draw_alpha);
545 static void flip_page(void) {
546 PageStore[old_page].locks=PAGE_EMPTY;
547 PageStore[cpage].locks=PAGE_BUSY;
549 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: viewing page %d\n",cpage);
550 if(sync_flip && old_page!=cpage){
551 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga:vga_waitretrace\n");
552 vga_waitretrace();
554 vga_setdisplaystart(PageStore[cpage].doffset);
556 old_page=cpage;//cpage will be overwriten on next draw_image
559 static void check_events(void) {
562 static void uninit(void) {
563 vga_setmode(TEXT);
566 /* --------------------------------------------------------------------- */
567 static int query_format(uint32_t format) {
568 int32_t req_bpp,flags;
569 int i,lastmode;
570 vga_modeinfo * vminfo;
572 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: query_format=%X \n",format);
573 //only RGB modes supported
574 if( (!IMGFMT_IS_RGB(format)) && (!IMGFMT_IS_BGR(format)) ) return 0;
576 // Reject different endian
577 #if HAVE_BIGENDIAN
578 if (IMGFMT_IS_BGR(format)) return 0;
579 #else
580 if (IMGFMT_IS_RGB(format)) return 0;
581 #endif
583 //svgalib supports only BG4B! if we want BGR4 we have to emulate it (sw)
584 if( format==IMGFMT_BGR4 || format==IMGFMT_RGB4) return 0;
585 req_bpp = IMGFMT_RGB_DEPTH(format);
586 if( vo_dbpp>0 && vo_dbpp!=req_bpp ) return 0; //support -bpp options
587 //scan all modes
588 lastmode = vga_lastmodenumber();
589 for(i=1;i<=lastmode;i++){
590 vminfo = vga_getmodeinfo(i);
591 if( vminfo == NULL ) continue;
592 if( vga_hasmode(i) == 0 ) continue;
593 if( req_bpp != bpp_from_vminfo(vminfo) ) continue;
594 if( (force_vm > 0) && (force_vm != i) ) continue;//quick hack
595 flags = VFCAP_CSP_SUPPORTED|
596 VFCAP_CSP_SUPPORTED_BY_HW|
597 VFCAP_ACCEPT_STRIDE|
599 if(req_bpp>8) flags|=VFCAP_OSD;
600 return flags;
602 return 0;
605 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
606 unsigned char *srca, int stride) {
607 char* base;
609 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",
610 x0,y0,w,h,src,srca,stride);
611 if(!blackbar_osd) {
612 //drawing in the image, so place the stuff there
613 x0+=x_pos;
614 y0+=y_pos;
617 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: OSD draw in page %d\n",cpage);
618 base=PageStore[cpage].vbase + y0*mode_stride + x0*modeinfo->bytesperpixel;
619 switch (mode_bpp) {
620 case 32:
621 vo_draw_alpha_rgb32(w, h, src, srca, stride, base, mode_stride);
622 break;
623 case 24:
624 vo_draw_alpha_rgb24(w, h, src, srca, stride, base, mode_stride);
625 break;
626 case 16:
627 vo_draw_alpha_rgb16(w, h, src, srca, stride, base, mode_stride);
628 break;
629 case 15:
630 vo_draw_alpha_rgb15(w, h, src, srca, stride, base, mode_stride);
631 break;
635 static uint32_t get_image(mp_image_t *mpi){
636 int page;
638 if(!IMGFMT_IS_BGR(mpi->imgfmt) && !IMGFMT_IS_RGB(mpi->imgfmt) ){
639 assert(0);//should never happen
640 return VO_FALSE;
643 if (
644 ( (mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) ||
645 (mpi->flags & MP_IMGFLAG_PLANAR) ||
646 (mpi->flags & MP_IMGFLAG_YUV)
648 return VO_FALSE;
650 //reading from video memory is horribly slow
651 if( !(mpi->flags & MP_IMGFLAG_READABLE) && vo_directrendering &&
652 (mode_capabilities & CAP_LINEAR) ){
654 //find free page and reserve it
655 page=page_find_free();
656 if(page >= 0){
657 PageStore[page].locks=PAGE_BUSY;
659 mpi->flags |= MP_IMGFLAG_DIRECT;
660 mpi->stride[0] = mode_stride;
661 mpi->planes[0] = PageStore[page].vbase +
662 y_pos*mode_stride + (x_pos*mpi->bpp)/8;
663 mpi->priv=(void *)page;
664 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: direct render allocated! page=%d\n",page);
665 return VO_TRUE;
669 return VO_FALSE;