[boilerplate/directfb] Gracefully handle failure to create surface.

Simply return NULL indicating failure to create the target surface rather
than aborting the test (allowing other targets to be tested).
This commit is contained in:
Chris Wilson 2008-10-19 12:11:13 +01:00
parent 801df1b87a
commit 8e0950ced8

View file

@ -19,49 +19,79 @@ make check
#include <direct/debug.h>
D_DEBUG_DOMAIN( CairoDFB_Boiler, "CairoDFB/Boiler", "Cairo DirectFB Boilerplate" );
D_DEBUG_DOMAIN (CairoDFB_Boiler, "CairoDFB/Boiler", "Cairo DirectFB Boilerplate");
/* macro for a safe call to DirectFB functions */
#define DFBCHECK(x...) \
{ \
err = x; \
if (err != DFB_OK) { \
fprintf( stderr, "%s <%d>:\n\t", __FILE__, __LINE__ ); \
DirectFBErrorFatal( #x, err ); \
} \
}
#define DFBCHECK(x...) do{ \
err = x; \
if (err != DFB_OK) { \
fprintf (stderr, "%s <%d>:\n\t", __FILE__, __LINE__); \
goto ERROR; \
} \
} while (0)
typedef struct _DFBInfo {
IDirectFB *dfb;
IDirectFBDisplayLayer *layer;
IDirectFBWindow *window;
IDirectFBSurface *surface;
} DFBInfo ;
IDirectFB *dfb;
IDirectFBDisplayLayer *layer;
IDirectFBWindow *window;
IDirectFBSurface *surface;
} DFBInfo;
static DFBInfo *init(void) {
DFBDisplayLayerConfig layer_config;
DFBGraphicsDeviceDescription desc;
int err;
DFBInfo *info = xcalloc(1,sizeof(DFBInfo));
if( !info )
return NULL;
void
_cairo_boilerplate_directfb_cleanup (void *closure)
{
DFBInfo *info = (DFBInfo *) closure;
DFBCHECK(DirectFBInit( NULL,NULL));
DFBCHECK(DirectFBCreate( &info->dfb ));
info->dfb->GetDeviceDescription(info->dfb, &desc );
if (info->surface)
info->surface->Release (info->surface);
DFBCHECK(info->dfb->GetDisplayLayer( info->dfb, DLID_PRIMARY, &info->layer ));
info->layer->SetCooperativeLevel( info->layer, DLSCL_ADMINISTRATIVE );
if (info->window)
info->window->Release (info->window);
if (!((desc.blitting_flags & DSBLIT_BLEND_ALPHACHANNEL) &&
(desc.blitting_flags & DSBLIT_BLEND_COLORALPHA )))
{
layer_config.flags = DLCONF_BUFFERMODE;
layer_config.buffermode = DLBM_BACKSYSTEM;
info->layer->SetConfiguration( info->layer, &layer_config );
}
return info;
if (info->layer)
info->layer->Release (info->layer);
if (info->dfb)
info->dfb->Release (info->dfb);
free (info);
}
static DFBInfo *
init (void)
{
DFBDisplayLayerConfig layer_config;
DFBGraphicsDeviceDescription desc;
int err;
DFBInfo *info;
info = xcalloc (1, sizeof (DFBInfo));
if (info == NULL)
return NULL;
DFBCHECK (DirectFBInit (NULL, NULL));
DFBCHECK (DirectFBCreate (&info->dfb));
info->dfb->GetDeviceDescription (info->dfb, &desc);
DFBCHECK (info->dfb->GetDisplayLayer (info->dfb,
DLID_PRIMARY, &info->layer));
info->layer->SetCooperativeLevel (info->layer, DLSCL_ADMINISTRATIVE);
if ((desc.blitting_flags & (DSBLIT_BLEND_ALPHACHANNEL |
DSBLIT_BLEND_COLORALPHA)) !=
(DSBLIT_BLEND_ALPHACHANNEL | DSBLIT_BLEND_COLORALPHA))
{
layer_config.flags = DLCONF_BUFFERMODE;
layer_config.buffermode = DLBM_BACKSYSTEM;
info->layer->SetConfiguration (info->layer, &layer_config);
}
return info;
ERROR:
if (info != NULL)
_cairo_boilerplate_directfb_cleanup (info);
return NULL;
}
static cairo_surface_t *
@ -70,34 +100,40 @@ _cairo_boilerplate_directfb_window_create_surface (DFBInfo *info,
int width,
int height)
{
DFBWindowDescription desc;
int err;
DFBWindowDescription desc;
int err;
D_DEBUG_AT( CairoDFB_Boiler, "%s( %p, %s, %dx%d )\n", __FUNCTION__, info,
content == CAIRO_CONTENT_ALPHA ? "ALPHA" :
content == CAIRO_CONTENT_COLOR ? "RGB" :
content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB" : "unknown content!",
width, height );
D_DEBUG_AT (CairoDFB_Boiler, "%s (%p, %s, %dx%d)\n", __FUNCTION__, info,
content == CAIRO_CONTENT_ALPHA ? "ALPHA" :
content == CAIRO_CONTENT_COLOR ? "RGB" :
content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB" : "unknown content!",
width, height);
desc.flags = ( DWDESC_POSX | DWDESC_POSY |
DWDESC_WIDTH | DWDESC_HEIGHT /*| DWDESC_CAPS|DSDESC_PIXELFORMAT*/ );
desc.posx = 0;
desc.posy = 0;
desc.width = width;
desc.height = height;
desc.flags = DWDESC_POSX | DWDESC_POSY |
DWDESC_WIDTH | DWDESC_HEIGHT
/*| DWDESC_CAPS|DSDESC_PIXELFORMAT*/;
desc.posx = 0;
desc.posy = 0;
desc.width = width;
desc.height = height;
#if 0 /*Test using native format by default*/
desc.caps = DWCAPS_DOUBLEBUFFER;
desc.caps |= DWCAPS_ALPHACHANNEL;
desc.pixelformat = DSPF_ARGB;
desc.caps = DWCAPS_DOUBLEBUFFER;
desc.caps |= DWCAPS_ALPHACHANNEL;
desc.pixelformat = DSPF_ARGB;
#endif
DFBCHECK(info->layer->CreateWindow( info->layer, &desc, &info->window ) );
info->window->SetOpacity( info->window, 0xFF );
info->window->GetSurface( info->window, &info->surface );
info->surface->SetColor( info->surface, 0xFF, 0xFF, 0xFF, 0xFF );
info->surface->FillRectangle( info->surface,0, 0, desc.width, desc.height );
info->surface->Flip( info->surface, NULL, 0 );
return cairo_directfb_surface_create(info->dfb,info->surface);
DFBCHECK (info->layer->CreateWindow (info->layer, &desc, &info->window));
info->window->SetOpacity (info->window, 0xFF);
info->window->GetSurface (info->window, &info->surface);
info->surface->SetColor (info->surface, 0xFF, 0xFF, 0xFF, 0xFF);
info->surface->FillRectangle (info->surface,0, 0, desc.width, desc.height);
info->surface->Flip (info->surface, NULL, 0);
return cairo_directfb_surface_create (info->dfb, info->surface);
ERROR:
_cairo_boilerplate_directfb_cleanup (info);
return NULL;
}
static cairo_surface_t *
@ -106,35 +142,27 @@ _cairo_boilerplate_directfb_bitmap_create_surface (DFBInfo *info,
int width,
int height)
{
int err;
DFBSurfaceDescription desc;
int err;
DFBSurfaceDescription desc;
D_DEBUG_AT( CairoDFB_Boiler, "%s( %p, %s, %dx%d )\n", __FUNCTION__, info,
content == CAIRO_CONTENT_ALPHA ? "ALPHA" :
content == CAIRO_CONTENT_COLOR ? "RGB" :
content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB" : "unknown content!",
width, height );
D_DEBUG_AT (CairoDFB_Boiler, "%s (%p, %s, %dx%d)\n", __FUNCTION__, info,
content == CAIRO_CONTENT_ALPHA ? "ALPHA" :
content == CAIRO_CONTENT_COLOR ? "RGB" :
content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB" : "unknown content!",
width, height);
desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
desc.caps = DSCAPS_NONE;
desc.width = width;
desc.height = height;
desc.pixelformat = DSPF_ARGB;
DFBCHECK(info->dfb->CreateSurface (info->dfb, &desc,&info->surface));
return cairo_directfb_surface_create(info->dfb,info->surface);
}
desc.flags = DSDESC_WIDTH | DSDESC_HEIGHT | DSDESC_PIXELFORMAT;
desc.caps = DSCAPS_NONE;
desc.width = width;
desc.height = height;
desc.pixelformat = DSPF_ARGB;
DFBCHECK (info->dfb->CreateSurface (info->dfb, &desc, &info->surface));
void
_cairo_boilerplate_directfb_cleanup (void* closure) {
DFBInfo *info = (DFBInfo *)closure;
if( info->surface )
info->surface->Release( info->surface );
if( info->window )
info->window->Release( info->window );
if( info->layer )
info->layer->Release( info->layer );
if( info->dfb )
info->dfb->Release( info->dfb );
return cairo_directfb_surface_create (info->dfb, info->surface);
ERROR:
_cairo_boilerplate_directfb_cleanup (info);
return NULL;
}
cairo_surface_t *
@ -149,20 +177,22 @@ _cairo_boilerplate_directfb_create_surface (const char *name,
void **closure)
{
DFBInfo* info= init();
*closure = info;
if( !info ) {
CAIRO_BOILERPLATE_LOG ("Failed to init directfb:\n");
return NULL;
}
DFBInfo *info;
D_DEBUG_AT( CairoDFB_Boiler, "%s( '%s', %s, %dx%d, %s )\n", __FUNCTION__, name,
info = init ();
if (info == NULL)
return NULL;
*closure = info;
D_DEBUG_AT (CairoDFB_Boiler, "%s ('%s', %s, %dx%d, %s)\n",
__FUNCTION__, name,
content == CAIRO_CONTENT_ALPHA ? "ALPHA" :
content == CAIRO_CONTENT_COLOR ? "RGB" :
content == CAIRO_CONTENT_COLOR_ALPHA ? "ARGB" : "unknown content!",
width, height,
mode == CAIRO_BOILERPLATE_MODE_TEST ? "TEST" :
mode == CAIRO_BOILERPLATE_MODE_PERF ? "PERF" : "unknown mode!" );
mode == CAIRO_BOILERPLATE_MODE_PERF ? "PERF" : "unknown mode!");
if (width == 0)
width = 1;