From 79613500f185893bb2d5acb99143e97ece2ebb87 Mon Sep 17 00:00:00 2001 From: M Joonas Pihlaja Date: Sat, 19 Sep 2009 10:31:18 +0300 Subject: Make it compile with g++. --- cairosdl.c | 21 ++++++++++++++++----- cairosdl.h | 7 +++++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/cairosdl.c b/cairosdl.c index eb9af6e..fcfa8fa 100644 --- a/cairosdl.c +++ b/cairosdl.c @@ -26,6 +26,10 @@ #include #include "cairosdl.h" +#ifdef __cplusplus +extern "C" { +#endif + /* forward references */ static void _cairosdl_blit_and_unpremultiply ( @@ -50,8 +54,9 @@ _cairosdl_blit_and_premultiply ( */ /* We're hanging the SDL_Surface as a user datum on the - * cairo_surface_t representing it using this key. */ -static cairo_user_data_key_t const CAIROSDL_TARGET_KEY[1]; + * cairo_surface_t representing it using this key. Turns out we need + * to initialise it for C++. */ +static cairo_user_data_key_t const CAIROSDL_TARGET_KEY[1] = {{1}}; static void sdl_surface_destroy_func (void *param) @@ -104,7 +109,8 @@ cairosdl_surface_create ( * * However, it turns out malloc is actually safe on many (all?) * platforms so we'll just go ahead anyway. */ - target = cairo_image_surface_create_for_data (sdl_surface->pixels, + unsigned char *data = (unsigned char*)(sdl_surface->pixels); + target = cairo_image_surface_create_for_data (data, format, sdl_surface->w, sdl_surface->h, @@ -143,7 +149,8 @@ SDL_Surface * cairosdl_surface_get_target ( cairo_surface_t *surface) { - return cairo_surface_get_user_data (surface, CAIROSDL_TARGET_KEY); + void *udata = cairo_surface_get_user_data (surface, CAIROSDL_TARGET_KEY); + return (SDL_Surface*)(udata); } static cairo_status_t @@ -159,7 +166,7 @@ _cairosdl_surface_obtain_SDL_buffer( return CAIRO_STATUS_NULL_POINTER; if (OUT_buffer) - *OUT_buffer = sdl_surface->pixels; + *OUT_buffer = (unsigned char *)(sdl_surface->pixels); if (OUT_stride) *OUT_stride = sdl_surface->pitch; if (OUT_width) @@ -687,3 +694,7 @@ _cairosdl_blit_and_premultiply ( source_bytes += source_stride; } } + +#ifdef __cplusplus +} +#endif diff --git a/cairosdl.h b/cairosdl.h index beb190d..53c9430 100644 --- a/cairosdl.h +++ b/cairosdl.h @@ -27,6 +27,10 @@ #include #include +#ifdef __cplusplus +extern "C" { +#endif + /* All cairo and cairosdl functions expect the underlying SDL_Surface * to be locked or not need locking. The underlying condition is that * the ->pixels member of the SDL_Surface should be valid and not @@ -109,4 +113,7 @@ cairosdl_destroy (cairo_t *cr); #define CAIROSDL_GMASK (255U << CAIROSDL_GSHIFT) #define CAIROSDL_BMASK (255U << CAIROSDL_BSHIFT) +#ifdef __cplusplus +} +#endif #endif /* CAIROSDL_H */ -- cgit v1.2.3