Hello,
I sent this question to this mailing list before, but never got an
answer. Can somebody please point me in the right direction? I have
been researching this topic for a long time in the usual venues but I
couldn't get this to work (without some serious, hackish, misues of
blit()). I'd like to have a fade effect that works smoothly. I'm using
the XDirectFB technique of setting the opacity level of the top-most
window. This doesn't seem to be working.
Read more below:
using XDirectFB for inspiration, I tried to create a fade effect by
doing roughly the following:
typedef struct
{
IDirectFB *dfb; /** our directfb object */
IDirectFBImageProvider *provider; /** our image class */
IDirectFBWindow *primary_window; /** our main window.
where opacity takes place */
IDirectFBDisplayLayer *primary_layer; /** interface to our layer */
IDirectFBSurface *primary_surface; /** our main background */
IDirectFBInputDevice *keyboard; /** our main input dev */
IDirectFBEventBuffer *ev_buffer; /** our events listener */
splashy_videomode_t *mode; /** video mode
supported by surface */
splashy_textbox_t *textbox; /** text box parameters */
DFBRectangle progressbar; /** our progressbar */
__u8 opacity; /** current opacity level */
} splashy_video_t;
/*
* Fade the opacity from its current value to the specified.
* helper for video_fade_in/out()
*/
static void
_window_fade (splashy_video_t *win, __u8 opacity, long ms_duration)
{
long t1, t2;
int diff;
/*IDirectFBDisplayLayer *layer = win->primary_layer;*/
IDirectFBWindow *window = win->primary_window;
/* Retrieve its current opacity. */
window->GetOpacity (window, &win->opacity);
/* TODO how do we know the current opacity level */
/* Retrieve its current opacity. */
/*layer->GetOpacity (layer, &win->opacity);*/
/* Calculate the opacity difference. */
diff = opacity - win->opacity;
/* fprintf(stderr,"diff %d\n",diff); */
/* Initialize both time stamps. */
t1 = t2 = get_time_in_ms();
/* fprintf(stderr,"t1 %lu\n",t2); */
do {
/* Calculate an intermediate opacity. */
__u8 op = win->opacity + ((t2 - t1 + 1) * diff / ms_duration);
/* fprintf(stderr,"op %d\n",op); */
/* Set the intermediate opacity. */
window->SetOpacity (window, op);
/* layer->SetOpacity (layer, op); */
/* Update the time stamp. */
t2 = get_time_in_ms();
/* fprintf(stderr,"t2 %lu\n",t2); */
}
while (t2 - t1 < ms_duration);
}
/**
* A simple function to create the effect of "fading in" for the
* primary surface
* @see splashy_child_boot() on splashy_functions.c
* @param video main video holding our primary window
*/
void
video_fade_in (splashy_video_t * video)
{
/* fprintf(stderr,"video_fade_in called %s\n",""); */
IDirectFBWindow *window = video->primary_window;
/* start from almost black */
window->SetOpacity (window, 1);
_window_fade (video, 255, 1000);
/* Set the exact opacity. */
window->SetOpacity (window, 255);
video->opacity = 255;
}
/**
* A simple function to create the effect of "fading out" for the
* primary surface
* @see splashy_child_exit() on splashy_functions.c
* @param video main video holding our primary window
*/
void
video_fade_out (splashy_video_t * video)
{
/* fprintf(stderr,"video_fade_out called %s\n","");*/
IDirectFBWindow *window = video->primary_window;
/* start from fully opaque */
window->SetOpacity (window, 255);
_window_fade (video, 0, 1000);
/* Set the exact opacity. */
window->SetOpacity (window, 0);
video->opacity = 0;
}
When i do my image provider routine, i call video_fade_in() like:
void
video_start_splash (splashy_video_t * video, const gchar * background)
{
DFBSurfaceDescription desc;
/* DFBDisplayLayerDescription ldesc; */
DFBWindowDescription win_desc;
/*
* initializing Directfb
*/
/*
* - no-debug := suppresses debug messages
* - quiet := suppresses all messages (but debug)
* - graphics-vt := puts directfb vt in graphics mode
* - no-cursor := disallow showing a cursor
*/
_current_background = background;
DFBCHECK (DirectFBInit (NULL, NULL));
DirectFBSetOption ("quiet", NULL);
DirectFBSetOption ("no-debug", NULL);
DirectFBSetOption ("graphics-vt", NULL);
DirectFBSetOption ("no-cursor", NULL);
/*
* in window-mode our dfb seems to prefer to go to the top layer
* which masks the progress bar! commented out (libdirectfb-0.9.22)
* This also makes the progressbar draw slower!
*/
/*
* DirectFBSetOption( "force-windowed", NULL);
*/
DFBCHECK (DirectFBCreate (&video->dfb));
video->mode = g_new0 (splashy_videomode_t, 1);
/*
* set our expectation to a very big number
*/
preinit (NULL);
video->mode->out_height = fb_vinfo.yres;
video->mode->out_width = fb_vinfo.xres;
DEBUG_PRINT ("Setting min Width (x) resolution to %d",
video->mode->out_width);
DEBUG_PRINT ("Setting min Height (y) resolution to %d",
video->mode->out_height);
video_set_mode (video);
DFBCHECK (video->dfb->CreateImageProvider (video->dfb, background,
&video->provider));
DFBCHECK (video->provider->GetSurfaceDescription (video->provider,
&desc));
/*
* flags to set the default surface as main surface
*/
desc.flags = DSDESC_CAPS;
desc.caps = DSCAPS_PRIMARY;
/*
* store our primary layer as this will be use for setting the opacity
* levels later
*/
DFBCHECK (video->dfb->GetDisplayLayer(video->dfb,
DLID_PRIMARY,&video->primary_layer));
/* DFBCHECK
(video->primary_layer->GetDescription(video->primary_layer,&ldesc));
*/
/* this only applies for directfb 0.9.12 and up */
/* ldesc.caps = DLCAPS_SURFACE | DLCAPS_ALPHACHANNEL | DLCAPS_OPACITY;*/
win_desc.flags = ( DWDESC_POSX | DWDESC_POSY |
DWDESC_WIDTH | DWDESC_HEIGHT );
win_desc.posx = 0;
win_desc.posy = 0;
win_desc.width = video->mode->out_width;
win_desc.height = video->mode->out_height;
DFBCHECK (video->primary_layer->CreateWindow (video->primary_layer,
&win_desc, &video->primary_window));
DFBCHECK (video->primary_window->GetSurface(video->primary_window,
&video->primary_surface));
DFBCHECK (video->dfb->CreateSurface (video->dfb, &desc,
&video->primary_surface));
/*
* allow surface to have alpha channels
* fade in effect won't work with alpha channels in window
* because we use Opacity levels
*/
/*
DFBCHECK (video->primary_surface->SetBlittingFlags
(video->primary_surface, DSBLIT_BLEND_ALPHACHANNEL));*/
/*
* it writes on the framebuffer the background image
*/
video->provider->RenderTo (video->provider, video->primary_surface,
NULL);
/*
* fade in effect
*/
if (g_ascii_strncasecmp (xml_parser_get_text
("/splashy/fadein"),"yes",3) == 0 )
video_fade_in (video);
}
But that doesn't seem to show any fade effect... anything I'm missing?
--
----)(-----
Luis Mondesi
*NIX Guru
Kiskeyix.org
"We think basically you watch television to turn your brain off, and
you work on your computer when you want to turn your brain on" --
Steve Jobs in an interview for MacWorld Magazine 2004-Feb
No .doc: http://www.gnu.org/philosophy/no-word-attachments.es.html
--
----)(-----
Luis Mondesi
*NIX Guru
Kiskeyix.org
"We think basically you watch television to turn your brain off, and
you work on your computer when you want to turn your brain on" --
Steve Jobs in an interview for MacWorld Magazine 2004-Feb
No .doc: http://www.gnu.org/philosophy/no-word-attachments.es.html
_______________________________________________
directfb-users mailing list
[email protected]
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users