Quoting Aykut KOÇAK:
> void cl_create_window( IDirectFBWindow** in, IDirectFBSurface** in2, int x,
> int y, int w, int h )
> {
> DFBWindowDescription desc;
>
> desc.flags = ( DWDESC_POSX | DWDESC_POSY |
> DWDESC_WIDTH | DWDESC_HEIGHT ); //| DWDESC_CAPS );
> desc.posx = x;
> desc.posy = y;
> desc.width = w;
> desc.height = h;
> // desc.caps = DWCAPS_ALPHACHANNEL;
>
> DFBCHECK( layer->CreateWindow( layer, &desc, in ) );
> (*in)->GetSurface( *in, in2 );
> (*in)->SetOpacity( *in, 0xff );
> // (*in)->SetColorKey( *in, 0x00, 0x00, 0x00 );
> // (*in)->SetOptions( *in, DWOP_COLORKEYING ); //|
> DWOP_ALPHACHANNEL );
> }
You shouldn't make a window visible prior to rendering its content the first
time.
If you don't have content at the time you want to show the window, you should at
least clear the surface.
With the following order:
- create
- render
- show
You will achieve the best user experience!
> int dfb_init( int argc, char* argv[] )
> {
> fprintf( stderr, "Starting DirectFB\t: " );
> DFBCHECK( DirectFBInit( &argc, &argv ) );
> DFBCHECK( DirectFBCreate( &dfb ) );
> DFBCHECK( dfb->GetDisplayLayer( dfb, 0, &layer ) ); // 0 primary layer...
> DFBCHECK( layer->SetCooperativeLevel( layer, DLSCL_EXCLUSIVE ) );
> DFBCHECK( layer->GetSurface(layer, &primary) );
> DFBCHECK( primary->GetSize( primary, &ScreenW, &ScreenH ) );
> printf("Screen Res. = %04d,%04d\n", ScreenW, ScreenH );
> DFBCHECK( primary->Clear( primary, 0,0,0,0 ) );
> DFBCHECK( primary->Flip( primary, NULL, DSFLIP_ONSYNC) );
> DFBCHECK( primary->Clear( primary, 0,0,0,0 ) );
> DFBCHECK( primary->SetColor( primary, 0xff, 0xff, 0xff, 0xff ) );
Do you mix direct layer surface access with showing windows?
> DFBResult df_drawPixel( IDirectFBSurface *surface, int x, int y, __u8 r, __u8
> g, __u8 b )
> {
> DFBResult ret;
> void *data;
> int pitch;
> int width, height;
> DFBSurfacePixelFormat format;
>
> uint8_t *dst8;
> uint16_t *dst16;
> uint32_t *dst32;
>
> surface->GetSize( surface, &width, &height );
> surface->GetPixelFormat( surface, &format );
>
> fprintf ( stderr, "pixel : %x\n", format );
>
> ret = surface->Lock( surface, DSLF_WRITE, &data, &pitch );
> if (ret)
> {
> DirectFBError( "IDirectFBSurface::Lock() failed", ret );
> return ret;
> }
>
> switch (format)
> {
> case DSPF_RGB32:
> dst32 = data + y * pitch;
> dst32[x] = PIXEL_RGB32( r, g, b );
> break;
> case DSPF_RGB16:
> dst16 = data + y * pitch;
> dst16[x] = PIXEL_RGB16( r, g, b );
> break;
> case DSPF_ARGB1555:
> dst16 = data + y * pitch;
> dst16[x] = PIXEL_ARGB1555( 0xff, r, g, b );
> break;
> case DSPF_ARGB:
> dst32 = data + y * pitch;
> dst32[x] = PIXEL_ARGB( 0xff, r, g, b );
> break;
> case DSPF_RGB332:
> dst8 = data + y * pitch;
> dst8[x] = PIXEL_RGB332( r, g, b );
> break;
> default:
> fprintf( stderr, "Unhandled pixel format 0x%08x!\n", format );
> break;
> }
>
> surface->Unlock( surface );
>
> return DFB_OK;
> }
If you just draw a single pixel each time, you could also use FillRectangle()
with 1x1 size.
But if you can, you should just Lock() and Unlock() just once and draw more
pixels in between.
> static void hLine( IDirectFBSurface* surface, int x1, int x2, int y )
> {
> assert( surface != NULL );
> if ( x1 < 0 )
> x1=0;
> if ( x2 < 0 )
> x2=0;
> if ( y < 0 )
> y=0;
> DFBCHECK( surface->DrawLine( surface, x1, y, x2, y ) );
> }
FillRectangle( x1, y, x2 - x1 + 1, 1 ) would much more likely be accelerated.
If you have more horizontal lines following directly below, use FillSpans().
> void df_drawArc( IDirectFBSurface* surface, int * vx, int * vy, int n)
> {
> int i;
> assert( surface != NULL );
> assert( vx != NULL );
> assert( vy != NULL );
>
> if ( n < 2 )
> return;
>
> for ( i=0;i< (n - 1);i++)
> {
> surface->DrawLine( surface, vx[i],vy[i],vx[i+1],vy[i+1] );
> }
> }
Better prepare an array of lines and pass it to ONE call to DrawLines().
This should give a big performance improvement.
--
Best regards,
Denis Oliver Kropp
.------------------------------------------.
| DirectFB - Hardware accelerated graphics |
| http://www.directfb.org/ |
"------------------------------------------"
_______________________________________________
directfb-users mailing list
[email protected]
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-users