Hi, I've been playing with Cairo and DirectFB and I've written a very
small program which just starts up both and then shuts down.
Unfortunately, when I upgraded to DirectFB 1.1, my code stopped
working and now just hangs at a black screen.

Below is the code I'm using.. it SHOULD just open up and then exit.
I'm compiling with the command:

gcc -Wall  -o cairo -L/usr/local/lib -ldirectfb -lcairo `pkg-config
--cflags directfb cairo` -DDEBUG main.c


#include <stdio.h>
#include <stdlib.h>

#include <cairo.h>
#include <cairo-directfb.h>
#include <directfb.h>

void cairo_init(cairo_t **gfx_context, cairo_surface_t **gfx_surface,
IDirectFB *dfb_context, IDirectFBSurface *dfb_surface);
void cairo_cleanup(cairo_t **gfx_context, cairo_surface_t **gfx_surface);

int main(int argc, char *argv[]) {
    /*  DirectFB variables  */
    IDirectFB           *dfb_context    = NULL;
    IDirectFBSurface    *dfb_surface    = NULL;
    DFBSurfaceDescription dfb_surface_opt;

    /*  Cairo variables     */
    cairo_surface_t *gfx_surface    = NULL;
    cairo_t         *gfx_context    = NULL;

        /*      Initialize DirectFB context     */
        DirectFBInit(&argc, &argv);
    if (DirectFBCreate(&dfb_context) != DFB_OK)
        exit(-1);

    /*  Set DirectFB surface options    */
    dfb_surface_opt.flags       = DSDESC_CAPS | DSDESC_PIXELFORMAT |
DSDESC_WIDTH | DSDESC_HEIGHT;
    dfb_surface_opt.caps        = DSCAPS_PRIMARY;
    dfb_surface_opt.pixelformat = DSPF_ARGB;
    dfb_surface_opt.width       = 1024;
    dfb_surface_opt.height      = 768;

        /*      Build primary DirectFB surface  */
    dfb_context->CreateSurface(dfb_context, &dfb_surface_opt, &dfb_surface);

    /*  Do Cairo operations */
    cairo_init(&gfx_context, &gfx_surface, dfb_context, dfb_surface);
    cairo_cleanup(&gfx_context, &gfx_surface);

        /*      Clean up DirectFB       */
    dfb_surface->Release(dfb_surface);
    dfb_context->Release(dfb_context);

    exit(0);
}

/*  Create a primary Cairo context and surface  */
void cairo_init(cairo_t **gfx_context, cairo_surface_t **gfx_surface,
IDirectFB *dfb_context, IDirectFBSurface *dfb_surface) {
    /*  Create a Cairo surface from a DirectFB context/surface  */
    *gfx_surface = cairo_directfb_surface_create(dfb_context, dfb_surface);

    /*  Make sure it worked */
    if (cairo_surface_status(*gfx_surface) != CAIRO_STATUS_SUCCESS) {
        printf("init gfx_surface failed: %s\n",
cairo_status_to_string(cairo_surface_status(*gfx_surface)));
        cairo_cleanup(gfx_context, gfx_surface);
        exit(-1);
    }

    /*  Create a Cairo graphics context */
    *gfx_context = cairo_create(*gfx_surface);

    /*  Make sure it worked */
    if (cairo_status(*gfx_context) != CAIRO_STATUS_SUCCESS) {
        printf("init gfx_context failed: %s\n",
cairo_status_to_string(cairo_status(*gfx_context)));
        cairo_cleanup(gfx_context, gfx_surface);
        exit(-1);
    }

#ifdef DEBUG
    printf("gfx_surface: %p\n", (void *) gfx_surface);
    printf("gfx_context: %p\n", (void *) gfx_context);
#endif
}

/*  Destroy the primary Cairo context and surface */
void cairo_cleanup(cairo_t **gfx_context, cairo_surface_t **gfx_surface) {
    cairo_surface_destroy(*gfx_surface);
    cairo_destroy(*gfx_context);
#ifdef DEBUG
    /*  Clean up for valgrind memcheck  */
    cairo_debug_reset_static_data();
#endif

    *gfx_surface = NULL;
    *gfx_context = NULL;
}

_______________________________________________
directfb-dev mailing list
[email protected]
http://mail.directfb.org/cgi-bin/mailman/listinfo/directfb-dev

Reply via email to