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
7 *
8 * This file is part of MPlayer.
9 *
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.
14 *
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.
19 *
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.
23 */
24
25 /*
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
36
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
43 */
44
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <string.h>
48
49 #include <vga.h>
50
51 #include <limits.h>
52
53 #include "config.h"
54 #include "video_out.h"
55 #define NO_DRAW_FRAME
56 #define NO_DRAW_SLICE
57 #include "video_out_internal.h"
58 #include "fastmemcpy.h"
59 #include "osdep/getch2.h"
60 #include "vosub_vidix.h"
61
62 #include "sub/sub.h"
63
64 #include "mp_msg.h"
65 #include "help_mp.h"
66 //#include "mp_image.h"
67
68 #include <assert.h>
69
70
71 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
72 unsigned char *srca, int stride);
73 static uint32_t get_image(mp_image_t *mpi);
74
75 #define MAXPAGES 16
76 #define PAGE_EMPTY 0
77 #define PAGE_BUSY 1
78
79 #define CAP_ACCEL_CLEAR 8
80 #define CAP_ACCEL_PUTIMAGE 4
81 #define CAP_ACCEL_BACKGR 2
82 #define CAP_LINEAR 1
83
84 static uint8_t zerobuf[8192];//used when clear screen with vga_draw
85
86 static int squarepix;
87 static int force_vm=0;
88 static int force_native=0;
89 static int sync_flip=0;
90 static int blackbar_osd=0;
91 static int cpage,max_pages,old_page;
92
93 static vga_modeinfo * modeinfo;
94 static int mode_stride; //keep it in case of vga_setlogicalwidth
95 static int stride_granularity; //not yet used
96 static int mode_bpp;
97 static int mode_capabilities;
98
99 static int image_width,image_height; // used by OSD
100 static int x_pos, y_pos;
101
102 static struct {
103 int yoffset;//y position of the page
104 int doffset;//display start of the page
105 uint8_t * vbase;//memory start address of the page
106 int locks;
107 }PageStore[MAXPAGES];
108
109 static const vo_info_t info = {
110 "SVGAlib",
111 "svga",
112 "Ivan Kalvachev <iive@users.sf.net>",
113 ""
114 };
115
116 #ifdef CONFIG_VIDIX
117 static char vidix_name[32] = "";
118 static vidix_grkey_t gr_key;
119 #endif
120
LIBVO_EXTERN(svga)121 LIBVO_EXTERN(svga)
122
123
124 //return number of 1'st free page or -1 if no free one
125 static inline int page_find_free(void){
126 int i;
127 for(i=0;i<max_pages;i++)
128 if(PageStore[i].locks == PAGE_EMPTY) return i;
129 return -1;
130 }
131
preinit(const char * arg)132 static int preinit(const char *arg)
133 {
134 int i,rez;
135 char s[64];
136
137 getch2_disable();
138 memset(zerobuf,0,sizeof(zerobuf));
139 force_vm=force_native=squarepix=0;
140 sync_flip=vo_vsync;
141 blackbar_osd=0;
142
143 if(arg)while(*arg) {
144 #ifdef CONFIG_VIDIX
145 if(memcmp(arg,"vidix",5)==0) {
146 i=6;
147 while(arg[i] && arg[i]!=':') i++;
148 strncpy(vidix_name, arg+6, i-6);
149 vidix_name[i-5]=0;
150 if(arg[i]==':')i++;
151 arg+=i;
152 vidix_preinit(vidix_name, &video_out_svga);
153 }
154 #endif
155 if(!strncmp(arg,"sq",2)) {
156 squarepix=1;
157 arg+=2;
158 if( *arg == ':' ) arg++;
159 }
160
161 if(!strncmp(arg,"native",6)) {
162 force_native=1;
163 arg+=6;
164 if( *arg == ':' ) arg++;
165 }
166
167 if(!strncmp(arg,"bbosd",5)) {
168 blackbar_osd=1;
169 arg+=5;
170 if( *arg == ':' ) arg++;
171 }
172
173 if(!strncmp(arg,"retrace",7)) {
174 sync_flip=1;
175 arg+=7;
176 if( *arg == ':' ) arg++;
177 }
178
179 if(*arg) {
180 i=0;
181 while(arg[i] && arg[i]!=':')i++;
182 if(i<64){
183 strncpy(s, arg, i);
184 s[i]=0;
185
186 force_vm=vga_getmodenumber(s);
187 if(force_vm>0) {
188 mp_msg(MSGT_VO,MSGL_V, "vo_svga: Forcing mode %i\n",force_vm);
189 }else{
190 force_vm = 0;
191 }
192 }
193 arg+=i;
194 if(*arg==':')arg++;
195 }
196 }
197
198 rez = vga_init();
199 if(rez != 0){
200 mp_msg(MSGT_VO,MSGL_ERR, "vo_svga: vga_init() returned error=%d\n",rez);
201 }
202 return !!rez;
203 }
204
svga_clear_box(int x,int y,int w,int h)205 static void svga_clear_box(int x,int y,int w,int h){
206 uint8_t * rgbplane;
207 int i;
208
209 if (mode_capabilities&CAP_ACCEL_CLEAR){
210 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with HW acceleration\n",
211 x,y,w,h);
212 if(mode_capabilities&CAP_ACCEL_BACKGR)
213 vga_accel(ACCEL_SYNC);
214 vga_accel(ACCEL_SETFGCOLOR,0);//black
215 vga_accel(ACCEL_FILLBOX,x,y,w,h);
216 return;
217 }
218 if (mode_capabilities & CAP_LINEAR){
219 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with memset\n",x,y,w,h);
220 rgbplane=PageStore[0].vbase + (y*mode_stride) + (x*modeinfo->bytesperpixel);
221 for(i=0;i<h;i++){
222 //i'm afraid that memcpy is better optimized than memset;)
223 fast_memcpy(rgbplane,zerobuf,w*modeinfo->bytesperpixel);
224 // memset(rgbplane,0,w*modeinfo->bytesperpixel);
225 rgbplane+=mode_stride;
226 }
227 return;
228 }
229 //native
230 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: clearing box %d,%d - %d,%d with native draw \n",x,y,w,h);
231 if(modeinfo->bytesperpixel!=0) w*=modeinfo->bytesperpixel;
232 for(i=0;i<h;i++){
233 vga_drawscansegment(zerobuf,x,y+i,w);
234 }
235 };
236
svga_draw_image(mp_image_t * mpi)237 static uint32_t svga_draw_image(mp_image_t *mpi){
238 int i,x,y,w,h;
239 int stride;
240 uint8_t *rgbplane, *base;
241 int bytesperline;
242 int page;
243
244 if(mpi->flags & MP_IMGFLAG_DIRECT){
245 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: drawing direct rendered surface\n");
246 cpage=(uintptr_t)mpi->priv;
247 assert((cpage>=0)&&(cpage<max_pages));
248 return VO_TRUE; //it's already done
249 }
250 // if (mpi->flags&MP_IMGFLAGS_DRAWBACK)
251 // return VO_TRUE;//direct render method 2
252
253 //find a free page to draw into
254 //if there is no one then use the current one
255 page = page_find_free();
256 if(page>=0) cpage=page;
257 PageStore[cpage].locks=PAGE_BUSY;
258
259 // these variables are used in loops
260 x = mpi->x;
261 y = mpi->y;
262 w = mpi->w;
263 h = mpi->h;
264 stride = mpi->stride[0];
265 rgbplane = mpi->planes[0] + y*stride + (x*mpi->bpp)/8;
266 x+=x_pos;//center
267 y+=y_pos;
268
269 if(mpi->bpp >= 8){//for modes<8 use only native
270 if( (mode_capabilities&CAP_ACCEL_PUTIMAGE) && (x==0) && (w==mpi->width) &&
271 (stride == mode_stride) ){ //only monolite image can be accelerated
272 w=(stride*8)/mpi->bpp;//we transfer pixels in the stride so the source
273 //ACCELERATE
274 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using HW PutImage (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
275 if(mode_capabilities & CAP_ACCEL_BACKGR)
276 vga_accel(ACCEL_SYNC);
277
278 vga_accel(ACCEL_PUTIMAGE,x,y+PageStore[cpage].yoffset,w,h,rgbplane);
279 return VO_TRUE;
280 }
281
282 if( mode_capabilities&CAP_LINEAR){
283 //DIRECT
284 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: using Direct memcpy (x=%d,y=%d,w=%d,h=%d)\n",x,y,w,h);
285 bytesperline=(w*mpi->bpp)/8;
286 base=PageStore[cpage].vbase + (y*mode_stride) + (x*mpi->bpp)/8;
287
288 for(i=0;i<h;i++){
289 mem2agpcpy(base,rgbplane,bytesperline);
290 base+=mode_stride;
291 rgbplane+=stride;
292 }
293 return VO_TRUE;
294 }
295 }//(modebpp>=8
296
297
298 //NATIVE
299 {
300 int length;
301 length=(w*mpi->bpp)/8;
302 //one byte per pixel! svgalib innovation
303 if(mpi->imgfmt==IMGFMT_RG4B || mpi->imgfmt==IMGFMT_BG4B) length=w;
304
305 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);
306 y+=PageStore[cpage].yoffset;//y position of the page beggining
307 for(i=0;i<h;i++){
308 vga_drawscansegment(rgbplane,x,y+i,length);
309 rgbplane+=stride;
310 }
311 }
312 return VO_TRUE;
313 }
314
bpp_from_vminfo(vga_modeinfo * vminfo)315 static int bpp_from_vminfo(vga_modeinfo *vminfo){
316 switch(vminfo->colors){
317 case 2: return 1;
318 case 16: return 4;
319 case 256: return 8;
320 case 32768: return 15;
321 case 65536: return 16;
322 case 1<<24: return 8*vminfo->bytesperpixel;
323 }
324 return 0;
325 }
326
find_best_svga_mode(int req_w,int req_h,int req_bpp)327 static int find_best_svga_mode(int req_w,int req_h, int req_bpp){
328 int badness,prev_badness;
329 int bestmode,lastmode;
330 int i;
331 vga_modeinfo *vminfo;
332 //int best aspect mode // best linear mode // best normal mode (no modeX)
333
334 prev_badness = 0;//take care of special case below
335 bestmode = 0; //0 is the TEXT mode
336 lastmode = vga_lastmodenumber();
337 for(i=1;i<=lastmode;i++){
338 vminfo = vga_getmodeinfo(i);
339 if( vminfo == NULL ) continue;
340 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: testing mode %d (%s)\n",i,vga_getmodename(i));
341 if( vga_hasmode(i) == 0 ) continue;
342 if( req_bpp != bpp_from_vminfo(vminfo) )continue;
343 if( (vminfo->width < req_w) || (vminfo->height < req_h) ) continue;
344 badness=(vminfo->width * vminfo->height) - (req_h * req_w);
345 //put here aspect calculations
346 if(squarepix)
347 if( vminfo->width*3 != vminfo->height*4 ) continue;
348
349 if( bestmode==0 || prev_badness >= badness ){//modeX etc...
350 prev_badness=badness;
351 bestmode=i;
352 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: found good mode %d with badness %d\n",i,badness);
353 }
354 }
355 return bestmode;
356 }
357
control(uint32_t request,void * data)358 static int control(uint32_t request, void *data)
359 {
360 switch (request) {
361 case VOCTRL_QUERY_FORMAT:
362 return query_format(*((uint32_t*)data));
363 case VOCTRL_DRAW_IMAGE:
364 return svga_draw_image( (mp_image_t *)data);
365 case VOCTRL_GET_IMAGE:
366 return get_image(data);
367 }
368
369 #ifdef CONFIG_VIDIX
370 if (vidix_name[0]) {
371 return vidix_control(request, data);
372 }
373 #endif
374
375 return VO_NOTIMPL;
376 }
377
378 //
379 // This function is called to init the video driver for specific mode
380 //
config(uint32_t width,uint32_t height,uint32_t d_width,uint32_t d_height,uint32_t flags,char * title,uint32_t format)381 static int config(uint32_t width, uint32_t height, uint32_t d_width,
382 uint32_t d_height, uint32_t flags, char *title,
383 uint32_t format) {
384 int32_t req_w = width;// (d_width > 0 ? d_width : width);
385 int32_t req_h = height;// (d_height > 0 ? d_height : height);
386 uint16_t vid_mode = 0;
387 int32_t req_bpp;
388
389 uint32_t accflags;
390 mp_msg(MSGT_VO,MSGL_V, "vo_svga: config(%i, %i, %i, %i, %08x, %s, %08x)\n", width, height,
391 d_width, d_height, flags, title, format);
392 //Only RGB modes supported
393 if (!IMGFMT_IS_RGB(format) && !IMGFMT_IS_BGR(format)) {assert(0);return -1;}
394 req_bpp = IMGFMT_BGR_DEPTH(format);
395
396 if( vo_dbpp!=0 && vo_dbpp!=req_bpp) {assert(0);return-1;}
397
398 if(!force_vm) {
399 mp_msg(MSGT_VO,MSGL_V, "vo_svga: Looking for the best resolution...\n");
400 mp_msg(MSGT_VO,MSGL_V, "vo_svga: req_w: %d, req_h: %d, bpp: %d\n",req_w,req_h,req_bpp);
401 vid_mode=find_best_svga_mode(req_w,req_h,req_bpp);
402 if(vid_mode==0)
403 return 1;
404 modeinfo=vga_getmodeinfo(vid_mode);
405 }else{//force_vm
406 vid_mode=force_vm;
407 if(vga_hasmode(vid_mode) == 0){
408 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeNotAvailable,
409 vid_mode,vga_getmodename(vid_mode));
410 return 1; //error;
411 }
412 modeinfo=vga_getmodeinfo(vid_mode);
413 if( (modeinfo->width < req_w) || (modeinfo->height < req_h) ){
414 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeTooSmall,
415 vid_mode,vga_getmodename(vid_mode));
416 return 1;
417 }
418 }
419 mode_bpp=bpp_from_vminfo(modeinfo);
420
421 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_Vidmode,
422 vid_mode,modeinfo->width,modeinfo->height,mode_bpp);
423
424 if (vga_setmode(vid_mode) == -1) {
425 mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_VgasetmodeFailed,vid_mode);
426 uninit();
427 return 1; // error
428 }
429 /* set 332 palette for 8 bpp */
430 if(mode_bpp==8){
431 int i;
432 for(i=0; i<256; i++)
433 vga_setpalette(i, ((i>>5)&7)*9, ((i>>2)&7)*9, (i&3)*21);
434 }
435 /* set 121 palette for 4 bpp */
436 else if(mode_bpp==4){
437 int i;
438 for(i=0; i<16; i++)
439 vga_setpalette(i, ((i>>3)&1)*63, ((i>>1)&3)*21, (i&1)*63);
440 }
441 //if we change the logical width, we should know the granularity
442 stride_granularity=8;//according to man vga_logicalwidth
443 if(modeinfo->flags & EXT_INFO_AVAILABLE){
444 stride_granularity=modeinfo->linewidth_unit;
445 }
446 //look for hardware acceleration
447 mode_capabilities=0;//NATIVE;
448 if(!force_native){//if we want to use only native drawers
449 if(modeinfo->flags & HAVE_EXT_SET){//support for hwaccel interface
450 accflags=vga_ext_set(VGA_EXT_AVAILABLE,VGA_AVAIL_ACCEL);
451 if(accflags & ACCELFLAG_FILLBOX) // clear screen
452 mode_capabilities|=CAP_ACCEL_CLEAR;
453 if(accflags & ACCELFLAG_PUTIMAGE)//support for mem->vid transfer
454 mode_capabilities|=CAP_ACCEL_PUTIMAGE;
455 if((accflags & ACCELFLAG_SETMODE) && (accflags & ACCELFLAG_SYNC)){
456 vga_accel(ACCEL_SETMODE,BLITS_IN_BACKGROUND);
457 mode_capabilities|=CAP_ACCEL_BACKGR;//can draw in backgraund
458 }
459 }
460 if(modeinfo->flags & IS_LINEAR){
461 mode_capabilities|=CAP_LINEAR; //don't use bank & vga_draw
462 }
463 else{
464 if(modeinfo->flags & CAPABLE_LINEAR){
465 int vid_mem_size;
466 vid_mem_size = vga_setlinearaddressing();
467 if(vid_mem_size != -1){
468 modeinfo=vga_getmodeinfo(vid_mode);//sometimes they change parameters
469 mode_capabilities|=CAP_LINEAR;
470 }
471 }
472 }
473 }//fi force native
474 if(mode_capabilities&CAP_LINEAR){
475 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeIsLinearAndMemcpyCouldBeUsed);
476 }
477 if(mode_capabilities&CAP_ACCEL_PUTIMAGE){
478 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeHasHardwareAcceleration);
479 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_IfItWorksForYouIWouldLikeToKnow);
480 }
481
482 //here is the place to handle strides for accel_ modes;
483 mode_stride=modeinfo->linewidth;
484 //we may try to set a bigger stride for video mode that will match the mpi->stride,
485 //this way we will transfer more data, but HW put_image can do it in backgraund!
486
487 //now let's see how many pages we can use
488 max_pages = modeinfo->maxpixels/(modeinfo->height * modeinfo->width);
489 if(max_pages > MAXPAGES) max_pages = MAXPAGES;
490 if(!vo_doublebuffering) max_pages=1;
491 //fill PageStore structs
492 {
493 int i;
494 uint8_t * GRAPH_MEM;
495 int dof;
496 GRAPH_MEM=vga_getgraphmem();
497 for(i=0;i<max_pages;i++){
498 //calculate display offset
499 dof = i * modeinfo->height * modeinfo->width;
500 if(modeinfo->bytesperpixel != 0) dof*=modeinfo->bytesperpixel;
501 //check video chip limitations
502 if( dof != (dof & modeinfo->startaddressrange) ){
503 max_pages=i;//page 0 will never come here
504 break;
505 }
506 PageStore[i].yoffset = i * modeinfo->height;//starting y offset
507 PageStore[i].vbase = GRAPH_MEM + i*modeinfo->height*mode_stride; //memory base address
508 PageStore[i].doffset = dof; //display offset
509 PageStore[i].locks = PAGE_EMPTY;
510 }
511 }
512 assert(max_pages>0);
513 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_VideoModeHas,max_pages);
514 //15bpp
515 if(modeinfo->bytesperpixel!=0)
516 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * modeinfo->bytesperpixel);
517 else
518 vga_claimvideomemory(max_pages * modeinfo->height * modeinfo->width * mode_bpp / 8);
519
520 cpage=old_page=0;
521 svga_clear_box(0,0,modeinfo->width,modeinfo->height * max_pages);
522
523 image_height=req_h;
524 image_width=req_w;
525 x_pos = (modeinfo->width - req_w) / 2;
526 y_pos = (modeinfo->height - req_h) / 2;
527 x_pos &= ~(15); //align x offset position to 16 pixels
528 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_CenteringImageStartAt,x_pos,y_pos);
529
530 #ifdef CONFIG_VIDIX
531
532 if(vidix_name[0]){
533 vidix_init(width, height, x_pos, y_pos, modeinfo->width, modeinfo->height,
534 format, mode_bpp, modeinfo->width,modeinfo->height);
535 mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_UsingVidix,width,height,
536 modeinfo->width,modeinfo->height);
537 vidix_start();
538 /*set colorkey*/
539 if(vidix_grkey_support()){
540 vidix_grkey_get(&gr_key);
541 gr_key.key_op = KEYS_PUT;
542 if (!(vo_colorkey & 0xFF000000)) {
543 gr_key.ckey.op = CKEY_TRUE;
544 gr_key.ckey.red = (vo_colorkey & 0x00FF0000) >> 16;
545 gr_key.ckey.green = (vo_colorkey & 0x0000FF00) >> 8;
546 gr_key.ckey.blue = vo_colorkey & 0x000000FF;
547 } else
548 gr_key.ckey.op = CKEY_FALSE;
549 vidix_grkey_set(&gr_key);
550 }
551 }
552 #endif
553
554 vga_setdisplaystart(0);
555 return 0;
556 }
557
draw_osd(void)558 static void draw_osd(void)
559 {
560 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: draw_osd()\n");
561 //only modes with bytesperpixel>0 can draw OSD
562 if(modeinfo->bytesperpixel==0) return;
563 if(!(mode_capabilities&CAP_LINEAR)) return;//force_native will remove OSD
564
565 if(blackbar_osd){
566 //111
567 //3 4
568 //222
569 svga_clear_box(0,0 + PageStore[cpage].yoffset,
570 modeinfo->width, y_pos);
571 svga_clear_box(0, image_height + y_pos + PageStore[cpage].yoffset,
572 modeinfo->width, modeinfo->height-(image_height+ y_pos));
573 svga_clear_box(0, y_pos + PageStore[cpage].yoffset,
574 x_pos, image_height);
575 svga_clear_box(image_width + x_pos, y_pos + PageStore[cpage].yoffset,
576 modeinfo->width-(x_pos+image_width), image_height);
577 // vo_remove_text(modeinfo->width, modeinfo->height, clear_alpha);
578 vo_draw_text(modeinfo->width, modeinfo->height, draw_alpha);
579 }else{
580 vo_draw_text(image_width, image_height, draw_alpha);
581 }
582 }
583
flip_page(void)584 static void flip_page(void) {
585 PageStore[old_page].locks=PAGE_EMPTY;
586 PageStore[cpage].locks=PAGE_BUSY;
587
588 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: viewing page %d\n",cpage);
589 if(sync_flip && old_page!=cpage){
590 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga:vga_waitretrace\n");
591 vga_waitretrace();
592 }
593 vga_setdisplaystart(PageStore[cpage].doffset);
594
595 old_page=cpage;//cpage will be overwriten on next draw_image
596 }
597
check_events(void)598 static void check_events(void) {
599 }
600
uninit(void)601 static void uninit(void) {
602
603 #ifdef CONFIG_VIDIX
604 if(vidix_name[0])vidix_term();
605 #endif
606 vga_setmode(TEXT);
607 }
608
609 /* --------------------------------------------------------------------- */
query_format(uint32_t format)610 static int query_format(uint32_t format) {
611 int32_t req_bpp,flags;
612 int i,lastmode;
613 vga_modeinfo * vminfo;
614
615 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: query_format=%X \n",format);
616 //only RGB modes supported
617 if( (!IMGFMT_IS_RGB(format)) && (!IMGFMT_IS_BGR(format)) ) return 0;
618
619 // Reject different endian
620 #if HAVE_BIGENDIAN
621 if (IMGFMT_IS_BGR(format)) return 0;
622 #else
623 if (IMGFMT_IS_RGB(format)) return 0;
624 #endif
625
626 //svgalib supports only BG4B! if we want BGR4 we have to emulate it (sw)
627 if( format==IMGFMT_BGR4 || format==IMGFMT_RGB4) return 0;
628 req_bpp = IMGFMT_RGB_DEPTH(format);
629 if( vo_dbpp>0 && vo_dbpp!=req_bpp ) return 0; //support -bpp options
630 //scan all modes
631 lastmode = vga_lastmodenumber();
632 for(i=1;i<=lastmode;i++){
633 vminfo = vga_getmodeinfo(i);
634 if( vminfo == NULL ) continue;
635 if( vga_hasmode(i) == 0 ) continue;
636 if( req_bpp != bpp_from_vminfo(vminfo) ) continue;
637 if( (force_vm > 0) && (force_vm != i) ) continue;//quick hack
638 flags = VFCAP_CSP_SUPPORTED|
639 VFCAP_CSP_SUPPORTED_BY_HW|
640 VFCAP_ACCEPT_STRIDE|
641 0;
642 if(req_bpp>8) flags|=VFCAP_OSD;
643 return flags;
644 }
645 return 0;
646 }
647
draw_alpha(int x0,int y0,int w,int h,unsigned char * src,unsigned char * srca,int stride)648 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
649 unsigned char *srca, int stride) {
650 char* base;
651
652 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",
653 x0,y0,w,h,src,srca,stride);
654 if(!blackbar_osd) {
655 //drawing in the image, so place the stuff there
656 x0+=x_pos;
657 y0+=y_pos;
658 }
659
660 mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: OSD draw in page %d\n",cpage);
661 base=PageStore[cpage].vbase + y0*mode_stride + x0*modeinfo->bytesperpixel;
662 switch (mode_bpp) {
663 case 32:
664 vo_draw_alpha_rgb32(w, h, src, srca, stride, base, mode_stride);
665 break;
666 case 24:
667 vo_draw_alpha_rgb24(w, h, src, srca, stride, base, mode_stride);
668 break;
669 case 16:
670 vo_draw_alpha_rgb16(w, h, src, srca, stride, base, mode_stride);
671 break;
672 case 15:
673 vo_draw_alpha_rgb15(w, h, src, srca, stride, base, mode_stride);
674 break;
675 }
676 }
677
get_image(mp_image_t * mpi)678 static uint32_t get_image(mp_image_t *mpi){
679 int page;
680
681 if(!IMGFMT_IS_BGR(mpi->imgfmt) && !IMGFMT_IS_RGB(mpi->imgfmt) ){
682 assert(0);//should never happen
683 return VO_FALSE;
684 }
685
686 if (
687 ( (mpi->type != MP_IMGTYPE_STATIC) && (mpi->type != MP_IMGTYPE_TEMP)) ||
688 (mpi->flags & MP_IMGFLAG_PLANAR) ||
689 (mpi->flags & MP_IMGFLAG_YUV)
690 )
691 return VO_FALSE;
692
693 //reading from video memory is horribly slow
694 if( !(mpi->flags & MP_IMGFLAG_READABLE) && vo_directrendering &&
695 (mode_capabilities & CAP_LINEAR) ){
696
697 //find free page and reserve it
698 page=page_find_free();
699 if(page >= 0){
700 PageStore[page].locks=PAGE_BUSY;
701
702 mpi->flags |= MP_IMGFLAG_DIRECT;
703 mpi->stride[0] = mode_stride;
704 mpi->planes[0] = PageStore[page].vbase +
705 y_pos*mode_stride + (x_pos*mpi->bpp)/8;
706 mpi->priv=(void *)(uintptr_t)page;
707 mp_msg(MSGT_VO,MSGL_DBG3, "vo_svga: direct render allocated! page=%d\n",page);
708 return VO_TRUE;
709 }
710 }
711
712 return VO_FALSE;
713 }
714