mpcommon.c: Remove dvdsub_id checks that should not be necessary
[mplayer/glamo.git] / libvo / vo_directfb2.c
blob0c2fb9b423c2db48df7935947d5bc5677830ebf4
1 /*
2 * MPlayer video driver for DirectFramebuffer device
4 * copyright (C) 2002 Jiri Svoboda <Jiri.Svoboda@seznam.cz>
6 * based on vo_directfb2.c
8 * This file is part of MPlayer.
10 * MPlayer is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (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 GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with MPlayer; if not, write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25 // directfb includes
27 #include <directfb.h>
29 #define DFB_VERSION(a,b,c) (((a)<<16)|((b)<<8)|(c))
31 // other things
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
37 #include "config.h"
38 #include "video_out.h"
39 #include "video_out_internal.h"
40 #include "fastmemcpy.h"
41 #include "sub.h"
42 #include "mp_msg.h"
43 #include "aspect.h"
44 #include "subopt-helper.h"
45 #include "mp_fifo.h"
47 #ifndef min
48 #define min(x,y) (((x)<(y))?(x):(y))
49 #endif
51 #if DIRECTFBVERSION > DFB_VERSION(0,9,17)
52 // triple buffering
53 #define TRIPLE 1
54 #endif
56 static const vo_info_t info = {
57 "Direct Framebuffer Device",
58 "directfb",
59 "Jiri Svoboda Jiri.Svoboda@seznam.cz",
60 "v 2.0 (for DirectFB version >=0.9.13)"
63 const LIBVO_EXTERN(directfb)
65 /******************************
66 * vo_directfb globals *
67 ******************************/
69 #define DFBCHECK(x...) \
70 { \
71 DFBResult err = x; \
73 if (err != DFB_OK) \
74 { \
75 fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
76 DirectFBErrorFatal( #x, err ); \
77 } \
81 * filled by preinit
84 // main DirectFB handle
85 static IDirectFB *dfb = NULL;
86 // keyboard handle
87 static IDirectFBInputDevice *keyboard = NULL;
88 // A buffer for input events.
89 static IDirectFBEventBuffer *buffer = NULL;
92 * filled during config
95 // handle of used layer
96 static IDirectFBDisplayLayer *layer = NULL;
97 // surface of used layer
98 static IDirectFBSurface *primary = NULL;
99 static int primarylocked = 0;
100 // handle of temporary surface (if used)
101 static IDirectFBSurface *frame = NULL;
102 static int framelocked = 0;
103 // flipping mode flag (layer/surface)
104 static int flipping = 0;
105 // scaling flag
106 static int stretch = 0;
107 // picture position
108 static int xoffset=0,yoffset=0;
109 // picture size
110 static int out_width=0,out_height=0;
111 // frame/primary size
112 static int width=0,height=0;
113 // frame primary format
114 DFBSurfacePixelFormat pixel_format;
116 static void (*draw_alpha_p)(int w, int h, unsigned char *src,
117 unsigned char *srca, int stride, unsigned char *dst,
118 int dstride);
121 /******************************
122 * cmd line parameteres *
123 ******************************/
125 /* command line/config file options */
126 static int layer_id = -1;
127 static int buffer_mode = 1;
128 static int use_input = 1;
129 static int field_parity = -1;
131 /******************************
132 * implementation *
133 ******************************/
135 void unlock(void) {
136 if (frame && framelocked) frame->Unlock(frame);
137 if (primary && primarylocked) primary->Unlock(primary);
140 static int get_parity(strarg_t *arg) {
141 if (strargcmp(arg, "top") == 0)
142 return 0;
143 if (strargcmp(arg, "bottom") == 0)
144 return 1;
145 return -1;
148 static int check_parity(void *arg) {
149 return get_parity(arg) != -1;
152 static int get_mode(strarg_t *arg) {
153 if (strargcmp(arg, "single") == 0)
154 return 1;
155 if (strargcmp(arg, "double") == 0)
156 return 2;
157 if (strargcmp(arg, "triple") == 0)
158 return 3;
159 return 0;
162 static int check_mode(void *arg) {
163 return get_mode(arg) != 0;
166 static int preinit(const char *arg)
168 DFBResult ret;
169 strarg_t mode_str = {0, NULL};
170 strarg_t par_str = {0, NULL};
171 strarg_t dfb_params = {0, NULL};
172 const opt_t subopts[] = {
173 {"input", OPT_ARG_BOOL, &use_input, NULL},
174 {"buffermode", OPT_ARG_STR, &mode_str, check_mode},
175 {"fieldparity", OPT_ARG_STR, &par_str, check_parity},
176 {"layer", OPT_ARG_INT, &layer_id, NULL},
177 {"dfbopts", OPT_ARG_STR, &dfb_params, NULL},
178 {NULL}
181 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit entered\n");
183 if (dfb) return 0; // we are already initialized!
185 // set defaults
186 buffer_mode = 1 + vo_doublebuffering; // honor -double switch
187 layer_id = -1;
188 use_input = 1;
189 field_parity = -1;
190 if (subopt_parse(arg, subopts) != 0) {
191 mp_msg( MSGT_VO, MSGL_ERR,
192 "\n-vo directfb command line help:\n"
193 "Example: mplayer -vo directfb:layer=1:buffermode=single\n"
194 "\nOptions (use 'no' prefix to disable):\n"
195 " input Use DirectFB for keyboard input\n"
196 "\nOther options:\n"
197 " layer=n\n"
198 " n=0..xx Use layer with id n for output (0=primary)\n"
199 " buffermode=(single|double|triple)\n"
200 " single Use single buffering\n"
201 " double Use double buffering\n"
202 " triple Use triple buffering\n"
203 " fieldparity=(top|bottom)\n"
204 " top Top field first\n"
205 " bottom Bottom field first\n"
206 " dfbopts=<str>\n"
207 " Specify a parameter list for DirectFB\n"
208 "\n" );
209 return -1;
211 if (mode_str.len)
212 buffer_mode = get_mode(&mode_str);
213 if (par_str.len)
214 field_parity = get_parity(&par_str);
217 if (dfb_params.len > 0)
219 int argc = 2;
220 char arg0[10] = "mplayer";
221 char *arg1 = malloc(dfb_params.len + 7);
222 char* argv[3];
223 char ** a;
225 a = &argv[0];
227 strcpy(arg1, "--dfb:");
228 strncat(arg1, dfb_params.str, dfb_params.len);
230 argv[0]=arg0;
231 argv[1]=arg1;
232 argv[2]=NULL;
234 DFBCHECK (DirectFBInit (&argc,&a));
236 free(arg1);
237 } else {
239 DFBCHECK (DirectFBInit (NULL,NULL));
242 if (((directfb_major_version <= 0) &&
243 (directfb_minor_version <= 9) &&
244 (directfb_micro_version < 13)))
246 mp_msg(MSGT_VO, MSGL_ERR,"DirectFB: Unsupported DirectFB version\n");
247 return 1;
251 * (set options)
254 // uncomment this if you do not wish to create a new VT for DirectFB
255 // DFBCHECK (DirectFBSetOption ("no-vt-switch",""));
257 // uncomment this if you want to allow VT switching
258 // DFBCHECK (DirectFBSetOption ("vt-switching",""));
260 // uncomment this if you want to hide gfx cursor (req dfb >=0.9.9)
261 DFBCHECK (DirectFBSetOption ("no-cursor",""));
263 // bg color fix
264 DFBCHECK (DirectFBSetOption ("bg-color","00000000"));
267 * (Initialize)
270 DFBCHECK (DirectFBCreate (&dfb));
272 #if DIRECTFBVERSION < DFB_VERSION(0,9,17)
273 if (DFB_OK != dfb->SetCooperativeLevel (dfb, DFSCL_FULLSCREEN)) {
274 mp_msg(MSGT_VO, MSGL_WARN,"DirectFB: Warning - cannot switch to fullscreen mode");
276 #endif
279 * (Get keyboard)
282 if (use_input) {
283 ret = dfb->GetInputDevice (dfb, DIDID_KEYBOARD, &keyboard);
284 if (ret==DFB_OK) {
285 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Keyboard init OK\n");
286 } else {
287 keyboard = NULL;
288 mp_msg(MSGT_VO, MSGL_ERR,"DirectFB: Keyboard init FAILED\n");
294 * Create an input buffer for the keyboard.
296 if (keyboard) DFBCHECK (keyboard->CreateEventBuffer (keyboard, &buffer));
298 // just to start clean ...
299 if (buffer) buffer->Reset(buffer);
301 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Preinit OK\n");
303 return 0;
307 DFBSurfacePixelFormat convformat(uint32_t format)
309 // add more formats !!!
310 switch (format) {
311 case IMGFMT_RGB32: return DSPF_RGB32; break;
312 case IMGFMT_BGR32: return DSPF_RGB32; break;
313 case IMGFMT_RGB24: return DSPF_RGB24; break;
314 case IMGFMT_BGR24: return DSPF_RGB24; break;
315 case IMGFMT_RGB16: return DSPF_RGB16; break;
316 case IMGFMT_BGR16: return DSPF_RGB16; break;
317 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
318 case IMGFMT_RGB15: return DSPF_ARGB1555; break;
319 case IMGFMT_BGR15: return DSPF_ARGB1555; break;
320 case IMGFMT_RGB12: return DSPF_ARGB4444; break;
321 case IMGFMT_BGR12: return DSPF_ARGB4444; break;
322 #else
323 case IMGFMT_RGB15: return DSPF_RGB15; break;
324 case IMGFMT_BGR15: return DSPF_RGB15; break;
325 case IMGFMT_RGB12: return DSPF_RGB12; break;
326 case IMGFMT_BGR12: return DSPF_RGB12; break;
327 #endif
328 case IMGFMT_YUY2: return DSPF_YUY2; break;
329 case IMGFMT_UYVY: return DSPF_UYVY; break;
330 case IMGFMT_YV12: return DSPF_YV12; break;
331 case IMGFMT_I420: return DSPF_I420; break;
332 // case IMGFMT_IYUV: return DSPF_IYUV; break;
333 case IMGFMT_RGB8: return DSPF_RGB332; break;
334 case IMGFMT_BGR8: return DSPF_RGB332; break;
336 default: return 0;
338 return 0;
341 typedef struct enum1_s {
342 uint32_t format;
343 int scale;
344 int result;
345 unsigned int id;
346 unsigned int width;
347 unsigned int height;
348 int setsize;
349 } enum1_t;
351 DFBEnumerationResult test_format_callback( unsigned int id,
352 DFBDisplayLayerDescription desc,
353 void *data)
355 enum1_t *params =(enum1_t *)data;
356 IDirectFBDisplayLayer *layer;
357 DFBResult ret;
359 if ((layer_id == -1 )||(layer_id == id)) {
361 ret = dfb->GetDisplayLayer( dfb, id, &layer);
362 if (ret) {
363 DirectFBError( "dfb->GetDisplayLayer failed", ret );
364 return DFENUM_OK;
365 } else {
366 DFBDisplayLayerConfig dlc;
368 if (params->setsize) {
369 dlc.flags = DLCONF_WIDTH |DLCONF_HEIGHT;
370 dlc.width = params->width;
371 dlc.height = params->height;
372 layer->SetConfiguration(layer,&dlc);
376 dlc.flags = DLCONF_PIXELFORMAT;
377 dlc.pixelformat = convformat(params->format);
379 layer->SetOpacity(layer,0);
381 ret = layer->TestConfiguration(layer,&dlc,NULL);
383 layer->Release(layer);
385 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Test format - layer %i scale/pos %i\n",id,(desc.caps & DLCAPS_SCREEN_LOCATION));
387 if (ret==DFB_OK) {
388 // printf("Test OK\n");
389 if (params->result) {
390 if ((!params->scale) && (desc.caps & DLCAPS_SCREEN_LOCATION)) {
391 params->scale=1;
392 params->id=id;
393 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Test format - added layer %i scale/pos %i\n",id,(desc.caps & DLCAPS_SCREEN_LOCATION));
395 } else {
396 params->result=1;
397 params->id=id;
398 if (desc.caps & DLCAPS_SCREEN_LOCATION) params->scale=1;
399 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Test format - added layer %i scale/pos %i\n",id,(desc.caps & DLCAPS_SCREEN_LOCATION));
406 return DFENUM_OK;
409 static int query_format(uint32_t format)
411 int ret = VFCAP_CSP_SUPPORTED|VFCAP_CSP_SUPPORTED_BY_HW|VFCAP_OSD; // osd should be removed the in future -> will be handled outside...
412 enum1_t params;
415 if (!convformat(format)) return 0;
416 // temporarily disable YV12
417 // if (format == IMGFMT_YV12) return 0;
418 // if (format == IMGFMT_I420) return 0;
419 if (format == IMGFMT_IYUV) return 0;
421 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Format query: %s\n",vo_format_name(format));
423 params.format=format;
424 params.scale=0;
425 params.result=0;
426 params.setsize=0;
428 DFBCHECK (dfb->EnumDisplayLayers(dfb,test_format_callback,&params));
430 if (params.result) {
431 if (params.scale) ret |=VFCAP_HWSCALE_UP|VFCAP_HWSCALE_DOWN;
432 return ret;
435 return 0;
438 typedef struct videomode_s {
439 int width;
440 int height;
441 int out_width;
442 int out_height;
443 int overx;
444 int overy;
445 int bpp;
446 } videomode_t;
449 DFBEnumerationResult video_modes_callback( int width,int height,int bpp, void *data)
451 videomode_t *params =(videomode_t *)data;
453 int overx=0,overy=0,closer=0,over=0;
454 int we_are_under=0;
456 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Validator entered %i %i %i\n",width,height,bpp);
458 overx=width-params->out_width;
459 overy=height-params->out_height;
461 if (!params->width) {
462 params->width=width;
463 params->height=height;
464 params->overx=overx;
465 params->overy=overy;
466 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Mode added %i %i %i\n",width,height,bpp);
469 if ((params->overy<0)||(params->overx<0)) we_are_under=1; // stored mode is smaller than req mode
470 if (abs(overx*overy)<abs(params->overx * params->overy)) closer=1; // current mode is closer to desired res
471 if ((overx>=0)&&(overy>=0)) over=1; // current mode is bigger or equaul to desired res
472 if ((closer && (over || we_are_under)) || (we_are_under && over)) {
473 params->width=width;
474 params->height=height;
475 params->overx=overx;
476 params->overy=overy;
477 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Better mode added %i %i %i\n",width,height,bpp);
480 return DFENUM_OK;
483 #define CONFIG_ERROR -1
485 static int config(uint32_t s_width, uint32_t s_height, uint32_t d_width,
486 uint32_t d_height, uint32_t flags, char *title,
487 uint32_t format)
490 * (Locals)
493 // decode flags
495 int fs = flags & VOFLAG_FULLSCREEN;
496 int vm = flags & VOFLAG_MODESWITCHING;
498 DFBSurfaceDescription dsc;
499 DFBResult ret;
500 DFBDisplayLayerConfig dlc;
501 DFBSurfaceCapabilities caps;
503 enum1_t params;
505 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Config entered [%ix%i]\n",s_width,s_height);
506 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: With requested format: %s\n",vo_format_name(format));
508 // initial cleanup
509 if (frame) {
510 frame->Release(frame);
511 frame=NULL;
514 if (primary) {
515 primary->Release(primary);
516 primary=NULL;
519 if (layer) {
520 layer->Release(layer);
521 layer=NULL;
525 // vm things
527 if (vm) {
528 videomode_t params;
529 params.out_width=d_width;
530 params.out_height=d_height;
531 params.width=0;
532 params.height=0;
533 switch (format) {
534 case IMGFMT_RGB32:
535 case IMGFMT_BGR32:
536 params.bpp=32;
537 break;
538 case IMGFMT_RGB24:
539 case IMGFMT_BGR24:
540 params.bpp=24;
541 break;
542 case IMGFMT_RGB16:
543 case IMGFMT_BGR16:
544 case IMGFMT_RGB15:
545 case IMGFMT_BGR15:
546 case IMGFMT_RGB12:
547 case IMGFMT_BGR12:
548 params.bpp=16;
549 break;
550 default: params.bpp=0;
553 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Config - trying to change videomode\n");
554 DFBCHECK (dfb->EnumVideoModes(dfb,video_modes_callback,&params));
555 ret=dfb->SetVideoMode(dfb,params.width,params.height,params.bpp);
556 if (ret) {
557 ret=dfb->SetVideoMode(dfb,params.width,params.height,24);
558 if (ret) {
559 ret=dfb->SetVideoMode(dfb,params.width,params.height,32);
560 if (ret) {
561 ret=dfb->SetVideoMode(dfb,params.width,params.height,16);
562 if (ret) {
563 ret=dfb->SetVideoMode(dfb,params.width,params.height,8);
568 } // vm end
570 // just to be sure clear primary layer
571 #if DIRECTFBVERSION > DFB_VERSION(0,9,13)
572 ret = dfb->GetDisplayLayer( dfb, DLID_PRIMARY, &layer);
573 if (ret==DFB_OK) {
574 ret = layer->GetSurface(layer,&primary);
575 if (ret==DFB_OK) {
576 primary->Clear(primary,0,0,0,0xff);
577 ret = primary->Flip(primary,NULL,0);
578 if (ret==DFB_OK) {
579 primary->Clear(primary,0,0,0,0xff);
581 primary->Release(primary);
583 primary=NULL;
584 layer->Release(layer);
586 layer=NULL;
587 #endif
589 // find best layer
591 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Config - looking for suitable layer\n");
592 params.format=format;
593 params.scale=0;
594 params.result=0;
595 params.width=s_width;
596 params.height=s_height;
597 params.setsize=1;
599 DFBCHECK (dfb->EnumDisplayLayers(dfb,test_format_callback,&params));
601 if (!params.result) {
602 mp_msg(MSGT_VO, MSGL_ERR,"DirectFB: ConfigError - no suitable layer found\n");
603 params.id = DLID_PRIMARY;
606 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Config - layer %i\n",params.id);
608 // setup layer
610 DFBCHECK (dfb->GetDisplayLayer( dfb, params.id, &layer));
612 #if DIRECTFBVERSION > DFB_VERSION(0,9,16)
613 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Config - switching layer to exclusive mode\n");
614 ret = layer->SetCooperativeLevel (layer, DLSCL_EXCLUSIVE);
616 if (DFB_OK != ret) {
617 mp_msg(MSGT_VO, MSGL_WARN,"DirectFB: Warning - cannot switch layer to exclusive mode. This could cause\nproblems. You may need to select correct pixel format manually!\n");
618 DirectFBError("MPlayer - Switch layer to exlusive mode.",ret);
620 #endif
621 if (params.scale) {
622 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Config - changing layer configuration (size)\n");
623 dlc.flags = DLCONF_WIDTH | DLCONF_HEIGHT;
624 dlc.width = s_width;
625 dlc.height = s_height;
627 ret = layer->SetConfiguration(layer,&dlc);
629 if (ret) {
630 mp_msg(MSGT_VO, MSGL_ERR,"DirectFB: ConfigError in layer configuration (size)\n");
631 DirectFBError("MPlayer - Layer size change.",ret);
635 // look if we need to change the pixel format of the layer
636 // and just to be sure also fetch all layer properties
637 dlc.flags = DLCONF_PIXELFORMAT | DLCONF_WIDTH | DLCONF_HEIGHT | DLCONF_OPTIONS | DLCONF_BUFFERMODE;
639 ret = layer->GetConfiguration(layer,&dlc);
641 dlc.flags = DLCONF_PIXELFORMAT | DLCONF_WIDTH | DLCONF_HEIGHT;
643 if (ret) {
644 mp_msg(MSGT_VO, MSGL_WARN,"DirectFB: Warning - could not get layer properties!\n");
645 } else {
646 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Layer reports format:%x\n",dlc.pixelformat);
649 if ((dlc.pixelformat != convformat(params.format)) || (ret != DFB_OK)) {
651 dlc.flags = DLCONF_PIXELFORMAT;
652 dlc.pixelformat = convformat(params.format);
654 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Desired pixelformat: %x\n",dlc.pixelformat);
656 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Config - changing layer configuration (format)\n");
657 ret = layer->SetConfiguration(layer,&dlc);
659 if (ret) {
660 unsigned int bpp;
661 mp_msg(MSGT_VO, MSGL_ERR,"DirectFB: ConfigError in layer configuration (format, flags=%x)\n",dlc.flags);
662 DirectFBError("MPlayer - layer pixelformat change",ret);
664 // ugly fbdev workaround - try to switch pixelformat via videomode change
665 switch (dlc.pixelformat) {
666 case DSPF_ARGB:
667 case DSPF_RGB32: bpp=32;break;
668 case DSPF_RGB24: bpp=24;break;
669 case DSPF_RGB16: bpp=16;break;
670 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
671 case DSPF_ARGB1555: bpp=15;break;
672 case DSPF_ARGB4444: bpp=12; break;
673 #else
674 case DSPF_RGB15: bpp=15;break;
675 case DSPF_RGB12: bpp=12; break;
676 #endif
677 case DSPF_RGB332 : bpp=8;break;
680 switch (dlc.pixelformat) {
681 case DSPF_ARGB:
682 case DSPF_RGB32:
683 case DSPF_RGB24:
684 case DSPF_RGB16:
685 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
686 case DSPF_ARGB1555:
687 case DSPF_ARGB4444:
688 #else
689 case DSPF_RGB15:
690 case DSPF_RGB12:
691 #endif
692 case DSPF_RGB332:
693 mp_msg(MSGT_VO, MSGL_V,"DirectFB: Trying to recover via videomode change (VM).\n");
694 // get size
695 dlc.flags = DLCONF_WIDTH | DLCONF_HEIGHT;
696 if (DFB_OK==layer->GetConfiguration(layer,&dlc)) {
697 // try to set videomode
698 mp_msg(MSGT_VO, MSGL_V,"DirectFB: Videomode %ix%i BPP %i\n",dlc.width,dlc.height,bpp);
699 ret = dfb->SetVideoMode(dfb,dlc.width,dlc.height,bpp);
700 if (ret) DirectFBError("MPlayer - VM - pixelformat change",ret);
704 //get current pixel format
705 dlc.flags = DLCONF_PIXELFORMAT;
706 ret = layer->GetConfiguration(layer,&dlc);
707 if (ret) {
708 DirectFBError("MPlayer - VM - Layer->GetConfiguration",ret);
709 } else {
710 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Layer now has pixelformat [%x]\n",dlc.pixelformat);
713 // check if we were succesful
714 if ((dlc.pixelformat != convformat(params.format)) || (ret != DFB_OK)) {
715 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Recovery failed!.\n");
716 return CONFIG_ERROR;
719 break;
721 default: return CONFIG_ERROR;
727 // flipping of layer
728 // try triple, double... buffering
730 dlc.flags = DLCONF_BUFFERMODE;
731 #ifdef TRIPLE
732 if (buffer_mode > 2) {
733 dlc.buffermode = DLBM_TRIPLE;
734 ret = layer->SetConfiguration( layer, &dlc );
735 } else {
736 ret=!DFB_OK;
739 if (ret!=DFB_OK) {
740 #endif
741 if (buffer_mode > 1) {
742 dlc.buffermode = DLBM_BACKVIDEO;
743 ret = layer->SetConfiguration( layer, &dlc );
744 if (ret!=DFB_OK) {
745 dlc.buffermode = DLBM_BACKSYSTEM;
746 ret = layer->SetConfiguration( layer, &dlc );
749 if (ret == DFB_OK) {
750 mp_msg(MSGT_VO, MSGL_V,"DirectFB: Double buffering is active\n");
752 #ifdef TRIPLE
753 } else {
754 mp_msg(MSGT_VO, MSGL_V,"DirectFB: Triple buffering is active\n");
756 #endif
758 #if DIRECTFBVERSION > DFB_VERSION(0,9,16)
759 if (field_parity != -1) {
760 dlc.flags = DLCONF_OPTIONS;
761 ret = layer->GetConfiguration( layer, &dlc );
762 if (ret==DFB_OK) {
763 dlc.options |= DLOP_FIELD_PARITY;
764 ret = layer->SetConfiguration( layer, &dlc );
765 if (ret==DFB_OK) {
766 layer->SetFieldParity( layer, field_parity );
770 mp_msg( MSGT_VO, MSGL_DBG2, "DirectFB: Requested field parity: ");
771 switch (field_parity) {
772 case -1:
773 mp_msg( MSGT_VO, MSGL_DBG2, "Don't care\n");
774 break;
775 case 0:
776 mp_msg( MSGT_VO, MSGL_DBG2, "Top field first\n");
777 break;
778 case 1:
779 mp_msg( MSGT_VO, MSGL_DBG2, "Bottom field first\n");
780 break;
783 #endif
786 // get layer surface
788 ret = layer->GetSurface(layer,&primary);
790 if (ret) {
791 mp_msg(MSGT_VO, MSGL_ERR,"DirectFB: ConfigError - could not get surface\n");
792 return CONFIG_ERROR; // what shall we report on failure?
795 // test surface for flipping
796 DFBCHECK(primary->GetCapabilities(primary,&caps));
797 #if DIRECTFBVERSION > DFB_VERSION(0,9,13)
798 primary->Clear(primary,0,0,0,0xff);
799 #endif
800 flipping = 0;
801 if (caps & (DSCAPS_FLIPPING
802 #ifdef TRIPLE
803 | DSCAPS_TRIPLE
804 #endif
805 )) {
806 ret = primary->Flip(primary,NULL,0);
807 if (ret==DFB_OK) {
808 flipping = 1;
809 #if DIRECTFBVERSION > DFB_VERSION(0,9,13)
810 primary->Clear(primary,0,0,0,0xff);
811 #ifdef TRIPLE
812 // if we have 3 buffers clean once more
813 if (caps & DSCAPS_TRIPLE) {
814 primary->Flip(primary,NULL,0);
815 primary->Clear(primary,0,0,0,0xff);
816 flipping = 2;
818 #endif
819 #endif
823 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Config - flipping = %i\n",flipping);
825 // is scale needed ? Aspect ratio and layer pos/size
828 // get surface size
829 DFBCHECK(primary->GetSize(primary,&width,&height));
831 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Config - surface size = %ix%i\n",width,height);
833 aspect_save_orig(s_width,s_height);
834 aspect_save_prescale(d_width,d_height);
835 if (params.scale) {
836 aspect_save_screenres(10000,10000);
837 aspect(&out_width,&out_height,A_ZOOM);
839 ret = layer->SetScreenLocation(layer,(1-(float)out_width/10000)/2,(1-(float)out_height/10000)/2,((float)out_width/10000),((float)out_height/10000));
841 if (ret) mp_msg(MSGT_VO, MSGL_ERR,"DirectFB: ConfigError in layer configuration (position)\n");
843 xoffset = 0;
844 yoffset = 0;
846 } else {
848 aspect_save_screenres(width,height);
850 if(fs) /* -fs */
851 aspect(&out_width,&out_height,A_ZOOM);
852 else
853 aspect(&out_width,&out_height,A_NOZOOM);
856 xoffset = (width - out_width) / 2;
857 yoffset = (height - out_height) / 2;
860 if (((s_width==out_width)&&(s_height==out_height)) || (params.scale)) {
861 stretch = 0;
862 } else {
863 stretch = 1;
867 // temporary buffer in case of not flipping or scaling
868 if ((!flipping) || stretch) {
870 DFBCHECK (primary->GetPixelFormat (primary, &dsc.pixelformat));
872 dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH;
874 dsc.width = s_width;
875 dsc.height = s_height;
877 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &frame));
878 DFBCHECK(frame->GetSize(frame,&width,&height));
879 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Frame is active.\n");
882 // get format for draw_alpha - should be removed soon - osd will be rendered outside vo driver
883 if (frame) {
884 DFBCHECK (frame->GetPixelFormat(frame,&pixel_format));
885 } else {
886 DFBCHECK (primary->GetPixelFormat(primary,&pixel_format));
889 // finally turn on layer
890 layer->SetOpacity(layer,255);
892 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Config finished [%ix%i] - [%ix%i]\n",out_width,out_height,width,height);
894 return 0;
897 #include "osdep/keycodes.h"
899 static void check_events(void)
902 if (buffer) {
904 DFBInputEvent event;
906 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events entered\n");
907 if (buffer->GetEvent(buffer, DFB_EVENT (&event)) == DFB_OK) {
909 if (event.type == DIET_KEYPRESS) {
910 switch (event.key_symbol) {
911 case DIKS_ESCAPE:
912 mplayer_put_key(KEY_ESC);
913 break;
914 case DIKS_PAGE_UP: mplayer_put_key(KEY_PAGE_UP);break;
915 case DIKS_PAGE_DOWN: mplayer_put_key(KEY_PAGE_DOWN);break;
916 case DIKS_CURSOR_UP: mplayer_put_key(KEY_UP);break;
917 case DIKS_CURSOR_DOWN: mplayer_put_key(KEY_DOWN);break;
918 case DIKS_CURSOR_LEFT: mplayer_put_key(KEY_LEFT);break;
919 case DIKS_CURSOR_RIGHT: mplayer_put_key(KEY_RIGHT);break;
920 case DIKS_INSERT: mplayer_put_key(KEY_INSERT);break;
921 case DIKS_DELETE: mplayer_put_key(KEY_DELETE);break;
922 case DIKS_HOME: mplayer_put_key(KEY_HOME);break;
923 case DIKS_END: mplayer_put_key(KEY_END);break;
925 default:mplayer_put_key(event.key_symbol);
929 // empty buffer, because of repeating (keyboard repeat is faster than key handling
930 // and this causes problems during seek)
931 // temporary workaround should be solved in the future
932 buffer->Reset(buffer);
935 //if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf ("DirectFB: Check events finished\n");
938 static void flip_page(void)
940 DFBSurfaceBlittingFlags flags=DSBLIT_NOFX;
942 unlock(); // unlock frame & primary
944 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Flip page entered");
946 DFBCHECK (primary->SetBlittingFlags(primary,flags));
948 if (frame) {
949 if (stretch) {
950 DFBRectangle rect;
951 rect.x=xoffset;
952 rect.y=yoffset;
953 rect.w=out_width;
954 rect.h=out_height;
956 DFBCHECK (primary->StretchBlit(primary,frame,NULL,&rect));
958 } else {
960 DFBCHECK (primary->Blit(primary,frame,NULL,xoffset,yoffset));
966 #ifdef TRIPLE
967 switch (flipping) {
968 case 1: DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAIT));
969 break;
970 case 2: DFBCHECK (primary->Flip (primary, NULL, DSFLIP_ONSYNC));
971 break;
972 default:; // should never be reached
974 #else
975 if (flipping) {
976 DFBCHECK (primary->Flip (primary, NULL, DSFLIP_WAITFORSYNC));
978 #endif
984 static void uninit(void)
987 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit entered\n");
989 unlock();
992 * (Release)
995 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing buffer\n");
996 if (buffer) buffer->Release (buffer);
997 mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing keyboard\n");
998 if (keyboard) keyboard->Release (keyboard);
1000 if (frame) {
1001 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Releasing frame\n");
1002 frame->Release (frame);
1003 frame = NULL;
1006 // switch off BES
1007 // if (layer) layer->SetOpacity(layer,0);
1009 if (layer) {
1010 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Releasing layer\n");
1011 layer->Release(layer);
1012 layer = NULL;
1015 if (primary) {
1016 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: Releasing primary\n");
1017 primary->Release (primary);
1018 primary = NULL;
1022 /* mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Releasing DirectFB library\n");
1024 dfb->Release (dfb);
1026 //mp_msg(MSGT_VO, MSGL_INFO,"DirectFB: Uninit done.\n");
1030 static uint32_t directfb_set_video_eq(char *data, int value) //data==name
1033 DFBColorAdjustment ca;
1034 float factor = (float)0xffff / 200.0;
1036 DFBDisplayLayerDescription desc;
1038 unlock();
1040 if (layer) {
1042 layer->GetDescription(layer,&desc);
1044 ca.flags=DCAF_NONE;
1046 if (! strcmp( data,"brightness" )) {
1047 if (desc.caps & DLCAPS_BRIGHTNESS) {
1048 ca.brightness = value * factor +0x8000;
1049 ca.flags |= DCAF_BRIGHTNESS;
1050 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: SetVEq Brightness 0x%X %i\n",ca.brightness,value);
1051 } else return VO_FALSE;
1054 if (! strcmp( data,"contrast" )) {
1055 if ((desc.caps & DLCAPS_CONTRAST)) {
1056 ca.contrast = value * factor + 0x8000;
1057 ca.flags |= DCAF_CONTRAST;
1058 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: SetVEq Contrast 0x%X %i\n",ca.contrast,value);
1059 } else return VO_FALSE;
1062 if (! strcmp( data,"hue" )) {
1063 if ((desc.caps & DLCAPS_HUE)) {
1064 ca.hue = value * factor + 0x8000;
1065 ca.flags |= DCAF_HUE;
1066 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: SetVEq Hue 0x%X %i\n",ca.hue,value);
1067 } else return VO_FALSE;
1070 if (! strcmp( data,"saturation" )) {
1071 if ((desc.caps & DLCAPS_SATURATION)) {
1072 ca.saturation = value * factor + 0x8000;
1073 ca.flags |= DCAF_SATURATION;
1074 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: SetVEq Saturation 0x%X %i\n",ca.saturation,value);
1075 } else return VO_FALSE;
1078 if (ca.flags != DCAF_NONE) {
1079 layer->SetColorAdjustment(layer,&ca);
1080 return VO_TRUE;
1084 return VO_FALSE;
1088 static uint32_t directfb_get_video_eq(char *data, int *value) // data==name
1091 DFBColorAdjustment ca;
1092 float factor = 200.0 / (float)0xffff;
1094 DFBDisplayLayerDescription desc;
1096 if (layer) {
1098 unlock();
1100 layer->GetDescription(layer,&desc);
1102 layer->GetColorAdjustment(layer,&ca);
1104 if (! strcmp( data,"brightness" )) {
1105 if (desc.caps & DLCAPS_BRIGHTNESS) {
1106 *value = (int) ((ca.brightness-0x8000) * factor);
1107 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: GetVEq Brightness 0x%X %i\n",ca.brightness,*value);
1108 return VO_TRUE;
1109 } else return VO_FALSE;
1112 if (! strcmp( data,"contrast" )) {
1113 if ((desc.caps & DLCAPS_CONTRAST)) {
1114 *value = (int) ((ca.contrast-0x8000) * factor);
1115 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: GetVEq Contrast 0x%X %i\n",ca.contrast,*value);
1116 return VO_TRUE;
1117 } else return VO_FALSE;
1120 if (! strcmp( data,"hue" )) {
1121 if ((desc.caps & DLCAPS_HUE)) {
1122 *value = (int) ((ca.hue-0x8000) * factor);
1123 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: GetVEq Hue 0x%X %i\n",ca.hue,*value);
1124 return VO_TRUE;
1125 } else return VO_FALSE;
1128 if (! strcmp( data,"saturation" )) {
1129 if ((desc.caps & DLCAPS_SATURATION)) {
1130 *value = (int) ((ca.saturation-0x8000) * factor);
1131 mp_msg(MSGT_VO, MSGL_DBG2,"DirectFB: GetVEq Saturation 0x%X %i\n",ca.saturation,*value);
1132 return VO_TRUE;
1133 } else return VO_FALSE;
1136 return VO_FALSE;
1139 static uint32_t get_image(mp_image_t *mpi)
1142 int err;
1143 uint8_t *dst;
1144 int pitch;
1146 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() called\n");
1147 if(mpi->flags&MP_IMGFLAG_READABLE) return VO_FALSE; // slow video ram
1148 if(mpi->type==MP_IMGTYPE_STATIC) return VO_FALSE; // it is not static
1150 // printf("width=%d vs. pitch=%d, flags=0x%X \n",mpi->width,pitch,mpi->flags);
1152 if(mpi->flags&(MP_IMGFLAG_ACCEPT_STRIDE|MP_IMGFLAG_ACCEPT_WIDTH)){
1153 // we're lucky or codec accepts stride => ok, let's go!
1155 if (frame) {
1156 err = frame->Lock(frame,DSLF_WRITE|DSLF_READ,(void *)&dst,&pitch);
1157 framelocked=1;
1158 } else {
1159 err = primary->Lock(primary,DSLF_WRITE,(void *)&dst,&pitch);
1160 primarylocked=1;
1163 if (err) {
1164 mp_msg(MSGT_VO, MSGL_ERR,"DirectFB: DR lock failed!");
1165 return VO_FALSE;
1168 if(mpi->flags&MP_IMGFLAG_PLANAR){
1169 //YV12 format
1170 mpi->planes[0]=dst;
1171 if(mpi->flags&MP_IMGFLAG_SWAPPED){
1172 mpi->planes[1]=dst + pitch*height;
1173 mpi->planes[2]=mpi->planes[1] + pitch*height/4;
1174 } else {
1175 mpi->planes[2]=dst + pitch*height;
1176 mpi->planes[1]=mpi->planes[2] + pitch*height/4;
1178 mpi->width=width;
1179 mpi->stride[0]=pitch;
1180 mpi->stride[1]=mpi->stride[2]=pitch/2;
1181 } else {
1182 //YUY2 and RGB formats
1183 mpi->planes[0]=dst;
1184 mpi->width=width;
1185 mpi->stride[0]=pitch;
1188 // center image
1190 if (!frame) {
1191 if(mpi->flags&MP_IMGFLAG_PLANAR){
1192 mpi->planes[0]= dst + yoffset * pitch + xoffset;
1193 mpi->planes[1]+= ((yoffset * pitch) >> 2) + (xoffset >> 1);
1194 mpi->planes[2]+= ((yoffset * pitch) >> 2) + (xoffset >> 1);
1195 } else {
1196 mpi->planes[0]=dst + yoffset * pitch + xoffset * (mpi->bpp >> 3);
1200 mpi->flags|=MP_IMGFLAG_DIRECT;
1201 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: get_image() SUCCESS -> Direct Rendering ENABLED\n");
1202 return VO_TRUE;
1205 return VO_FALSE;
1208 static int draw_slice(uint8_t *src[], int stride[], int w, int h, int x, int y)
1210 int i;
1211 unsigned int pitch;
1212 uint8_t *dst;
1213 uint8_t *dst2;
1214 uint8_t *srcp;
1215 unsigned int p;
1217 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: draw_slice entered\n");
1219 unlock();
1221 if (frame) {
1222 DFBCHECK (frame->Lock(frame,DSLF_WRITE|DSLF_READ,(void *)&dst,&pitch));
1223 framelocked = 1;
1224 } else {
1225 DFBCHECK (primary->Lock(primary,DSLF_WRITE,(void *)&dst,&pitch));
1226 primarylocked = 1;
1229 p=min(w,pitch);
1231 dst += y*pitch + x;
1232 dst2 = dst + pitch*height - y*pitch + y*pitch/4 - x/2;
1233 srcp = src[0];
1235 for (i=0;i<h;i++) {
1236 fast_memcpy(dst,srcp,p);
1237 dst += pitch;
1238 srcp += stride[0];
1241 if (pixel_format == DSPF_YV12) {
1243 dst = dst2;
1244 srcp = src[2];
1245 p = p/2;
1247 for (i=0;i<h/2;i++) {
1248 fast_memcpy(dst,srcp,p);
1249 dst += pitch/2;
1250 srcp += stride[2];
1253 dst = dst2 + pitch*height/4;
1254 srcp = src[1];
1256 for (i=0;i<h/2;i++) {
1257 fast_memcpy(dst,srcp,p);
1258 dst += pitch/2;
1259 srcp += stride[1];
1262 } else {
1264 dst = dst2;
1265 srcp = src[1];
1266 p = p/2;
1268 for (i=0;i<h/2;i++) {
1269 fast_memcpy(dst,srcp,p);
1270 dst += pitch/2;
1271 srcp += stride[1];
1274 dst = dst2 + pitch*height/4;
1275 srcp = src[2];
1277 for (i=0;i<h/2;i++) {
1278 fast_memcpy(dst,srcp,p);
1279 dst += pitch/2;
1280 srcp += stride[2];
1285 unlock();
1287 return 0;
1291 static uint32_t put_image(mp_image_t *mpi){
1294 // static IDirectFBSurface *tmp = NULL;
1295 // DFBSurfaceDescription dsc;
1296 // DFBRectangle rect;
1298 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image entered %i %i %i %i %i %i\n",mpi->x,mpi->y,mpi->w,mpi->h,mpi->width,mpi->height);
1300 unlock();
1302 // already out?
1303 if((mpi->flags&(MP_IMGFLAG_DIRECT|MP_IMGFLAG_DRAW_CALLBACK))) {
1304 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - nothing to do\n");
1305 return VO_TRUE;
1308 if (mpi->flags&MP_IMGFLAG_PLANAR) {
1309 // memcpy all planes - sad but necessary
1310 int i;
1311 unsigned int pitch;
1312 uint8_t *dst;
1313 uint8_t *src;
1314 unsigned int p;
1316 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - planar branch\n");
1317 if (frame) {
1318 DFBCHECK (frame->Lock(frame,DSLF_WRITE|DSLF_READ,(void *)&dst,&pitch));
1319 framelocked = 1;
1320 } else {
1321 DFBCHECK (primary->Lock(primary,DSLF_WRITE,(void *)&dst,&pitch));
1322 primarylocked = 1;
1325 p=min(mpi->w,pitch);
1327 src = mpi->planes[0]+mpi->y*mpi->stride[0]+mpi->x;
1329 for (i=0;i<mpi->h;i++) {
1330 fast_memcpy(dst+i*pitch,src+i*mpi->stride[0],p);
1334 if (pixel_format == DSPF_YV12) {
1336 dst += pitch*height;
1337 p = p/2;
1338 src = mpi->planes[2]+mpi->y*mpi->stride[2]+mpi->x/2;
1340 for (i=0;i<mpi->h/2;i++) {
1341 fast_memcpy(dst+i*pitch/2,src+i*mpi->stride[2],p);
1344 dst += pitch*height/4;
1345 src = mpi->planes[1]+mpi->y*mpi->stride[1]+mpi->x/2;
1347 for (i=0;i<mpi->h/2;i++) {
1348 fast_memcpy(dst+i*pitch/2,src+i*mpi->stride[1],p);
1351 } else {
1353 dst += pitch*height;
1354 p = p/2;
1355 src = mpi->planes[1]+mpi->y*mpi->stride[1]+mpi->x/2;
1357 for (i=0;i<mpi->h/2;i++) {
1358 fast_memcpy(dst+i*pitch/2,src+i*mpi->stride[1],p);
1361 dst += pitch*height/4;
1362 src = mpi->planes[2]+mpi->y*mpi->stride[2]+mpi->x/2;
1364 for (i=0;i<mpi->h/2;i++) {
1365 fast_memcpy(dst+i*pitch/2,src+i*mpi->stride[2],p);
1369 unlock();
1371 } else {
1372 // I had to disable native directfb blit because it wasn't working under some conditions :-(
1375 dsc.flags = DSDESC_HEIGHT | DSDESC_PIXELFORMAT | DSDESC_WIDTH | DSDESC_PREALLOCATED;
1376 dsc.preallocated[0].data = mpi->planes[0];
1377 dsc.preallocated[0].pitch = mpi->stride[0];
1378 dsc.width = mpi->width;
1379 dsc.height = mpi->height;
1380 dsc.pixelformat = convformat(mpi->imgfmt);
1382 DFBCHECK (dfb->CreateSurface( dfb, &dsc, &tmp));
1384 rect.x=mpi->x;
1385 rect.y=mpi->y;
1386 rect.w=mpi->w;
1387 rect.h=mpi->h;
1389 if (frame) {
1390 DFBCHECK (tmp->Blit(tmp,frame,&rect,0,0));
1391 } else {
1392 DFBCHECK (tmp->Blit(tmp,primary,&rect,xoffset,yoffset));
1394 tmp->Release(tmp);
1397 unsigned int pitch;
1398 uint8_t *dst;
1400 // if ( mp_msg_test(MSGT_VO,MSGL_V) ) printf("DirectFB: Put_image - non-planar branch\n");
1401 if (frame) {
1402 DFBCHECK (frame->Lock(frame,DSLF_WRITE,(void *)&dst,&pitch));
1403 framelocked = 1;
1404 mem2agpcpy_pic(dst,mpi->planes[0] + mpi->y * mpi->stride[0] + mpi->x * (mpi->bpp >> 3) ,mpi->w * (mpi->bpp >> 3),mpi->h,pitch,mpi->stride[0]);
1405 } else {
1406 DFBCHECK (primary->Lock(primary,DSLF_WRITE,(void *)&dst,&pitch));
1407 primarylocked = 1;
1408 mem2agpcpy_pic(dst + yoffset * pitch + xoffset * (mpi->bpp >> 3),mpi->planes[0] + mpi->y * mpi->stride[0] + mpi->x * (mpi->bpp >> 3) ,mpi->w * (mpi->bpp >> 3),mpi->h,pitch,mpi->stride[0]);
1410 unlock();
1413 return VO_TRUE;
1418 static int control(uint32_t request, void *data)
1420 switch (request) {
1421 case VOCTRL_QUERY_FORMAT:
1422 return query_format(*((uint32_t*)data));
1423 case VOCTRL_GET_IMAGE:
1424 return get_image(data);
1425 case VOCTRL_DRAW_IMAGE:
1426 return put_image(data);
1427 case VOCTRL_SET_EQUALIZER:
1429 struct voctrl_set_equalizer_args *args = data;
1430 return directfb_set_video_eq(args->name, args->value);
1432 case VOCTRL_GET_EQUALIZER:
1434 struct voctrl_get_equalizer_args *args = data;
1435 return directfb_get_video_eq(args->name, args->valueptr);
1438 return VO_NOTIMPL;
1441 // unused function
1443 static int draw_frame(uint8_t *src[])
1445 return -1;
1448 // hopefully will be removed soon
1450 static void draw_alpha(int x0, int y0, int w, int h, unsigned char *src,
1451 unsigned char *srca, int stride)
1453 void *dst;
1454 int pitch;
1456 unlock(); // isn't it silly I have to unlock surface and then lock it again :-)
1458 if (frame) {
1459 DFBCHECK (frame->Lock(frame,DSLF_WRITE|DSLF_READ,&dst,&pitch));
1460 framelocked = 1;
1461 } else {
1462 DFBCHECK (primary->Lock(primary,DSLF_WRITE,&dst,&pitch));
1463 primarylocked = 1;
1466 switch(pixel_format) {
1467 case DSPF_RGB32:
1468 case DSPF_ARGB:
1469 vo_draw_alpha_rgb32(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 4*x0,pitch);
1470 break;
1472 case DSPF_RGB24:
1473 vo_draw_alpha_rgb24(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 3*x0,pitch);
1474 break;
1476 case DSPF_RGB16:
1477 vo_draw_alpha_rgb16(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 2*x0,pitch);
1478 break;
1479 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
1480 case DSPF_ARGB1555:
1481 #else
1482 case DSPF_RGB15:
1483 #endif
1484 vo_draw_alpha_rgb15(w,h,src,srca,stride,((uint8_t *) dst)+pitch*y0 + 2*x0,pitch);
1485 break;
1486 #if DIRECTFBVERSION > DFB_VERSION(0,9,15)
1487 case DSPF_ARGB4444:
1488 #else
1489 case DSPF_RGB12:
1490 #endif
1491 vo_draw_alpha_rgb12(w, h, src, srca, stride,
1492 ((uint8_t *) dst) + pitch * y0 + 2 * x0,
1493 pitch);
1494 break;
1496 case DSPF_YUY2:
1497 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + 2*x0,pitch);
1498 break;
1500 case DSPF_UYVY:
1501 vo_draw_alpha_yuy2(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + 2*x0 + 1,pitch);
1502 break;
1504 case DSPF_I420:
1505 case DSPF_YV12:
1506 vo_draw_alpha_yv12(w,h,src,srca,stride,((uint8_t *) dst) + pitch*y0 + 1*x0,pitch);
1507 break;
1510 unlock();
1513 static void draw_osd(void)
1515 vo_draw_text(width,height,draw_alpha);