diff --git a/gfx/common/caca_common.h b/gfx/common/caca_common.h index ba0caf6b29..5a57baa1a6 100644 --- a/gfx/common/caca_common.h +++ b/gfx/common/caca_common.h @@ -31,6 +31,13 @@ typedef struct caca caca_canvas_t **caca_cv; caca_dither_t **caca_dither; caca_display_t **caca_display; + unsigned menu_width; + unsigned menu_height; + unsigned menu_pitch; + unsigned video_width; + unsigned video_height; + unsigned video_pitch; + bool rgb32; } caca_t; #endif diff --git a/gfx/drivers/caca_gfx.c b/gfx/drivers/caca_gfx.c index 675053598a..30f4ec86c9 100644 --- a/gfx/drivers/caca_gfx.c +++ b/gfx/drivers/caca_gfx.c @@ -34,35 +34,30 @@ static caca_canvas_t *caca_cv = NULL; static caca_dither_t *caca_dither = NULL; static caca_display_t *caca_display = NULL; static unsigned char *caca_menu_frame = NULL; -static unsigned caca_menu_width = 0; -static unsigned caca_menu_height = 0; -static unsigned caca_menu_pitch = 0; -static unsigned caca_video_width = 0; -static unsigned caca_video_height = 0; -static unsigned caca_video_pitch = 0; -static bool caca_rgb32 = false; static void caca_gfx_free(void *data); -static void caca_gfx_create(void) +static void caca_gfx_create(caca_t *caca) { caca_display = caca_create_display(NULL); - caca_cv = caca_get_canvas(caca_display); + caca_cv = caca_get_canvas(caca_display); - if(!caca_video_width || !caca_video_height) + if(!caca->video_width || !caca->video_height) { - caca_video_width = caca_get_canvas_width(caca_cv); - caca_video_height = caca_get_canvas_height(caca_cv); + caca->video_width = caca_get_canvas_width(caca_cv); + caca->video_height = caca_get_canvas_height(caca_cv); } - if (caca_rgb32) - caca_dither = caca_create_dither(32, caca_video_width, caca_video_height, caca_video_pitch, - 0x00ff0000, 0xff00, 0xff, 0x0); + if (caca->rgb32) + caca_dither = caca_create_dither(32, caca->video_width, + caca->video_height, caca->video_pitch, + 0x00ff0000, 0xff00, 0xff, 0x0); else - caca_dither = caca_create_dither(16, caca_video_width, caca_video_height, caca_video_pitch, - 0xf800, 0x7e0, 0x1f, 0x0); + caca_dither = caca_create_dither(16, caca->video_width, + caca->video_height, caca->video_pitch, + 0xf800, 0x7e0, 0x1f, 0x0); - video_driver_set_size(caca_video_width, caca_video_height); + video_driver_set_size(caca->video_width, caca->video_height); } static void *caca_gfx_init(const video_info_t *video, @@ -70,23 +65,26 @@ static void *caca_gfx_init(const video_info_t *video, { caca_t *caca = (caca_t*)calloc(1, sizeof(*caca)); - caca->caca_cv = &caca_cv; - caca->caca_dither = &caca_dither; - caca->caca_display = &caca_display; + if (!caca) + return NULL; - *input = NULL; - *input_data = NULL; + caca->caca_cv = &caca_cv; + caca->caca_dither = &caca_dither; + caca->caca_display = &caca_display; - caca_video_width = video->width; - caca_video_height = video->height; - caca_rgb32 = video->rgb32; + *input = NULL; + *input_data = NULL; + + caca->video_width = video->width; + caca->video_height = video->height; + caca->rgb32 = video->rgb32; if (video->rgb32) - caca_video_pitch = video->width * 4; + caca->video_pitch = video->width * 4; else - caca_video_pitch = video->width * 2; + caca->video_pitch = video->width * 2; - caca_gfx_create(); + caca_gfx_create(caca); if (!caca_cv || !caca_dither || !caca_display) { @@ -105,34 +103,28 @@ static bool caca_gfx_frame(void *data, const void *frame, unsigned frame_width, unsigned frame_height, uint64_t frame_count, unsigned pitch, const char *msg, video_frame_info_t *video_info) { - size_t len = 0; - void *buffer = NULL; + size_t len = 0; + void *buffer = NULL; const void *frame_to_copy = frame; - unsigned width = 0; - unsigned height = 0; - bool draw = true; - - (void)data; - (void)frame; - (void)frame_width; - (void)frame_height; - (void)pitch; - (void)msg; + unsigned width = 0; + unsigned height = 0; + bool draw = true; + caca_t *caca = (caca_t*)data; if (!frame || !frame_width || !frame_height) return true; - if ( caca_video_width != frame_width || - caca_video_height != frame_height || - caca_video_pitch != pitch) + if ( caca->video_width != frame_width || + caca->video_height != frame_height || + caca->video_pitch != pitch) { if (frame_width > 4 && frame_height > 4) { - caca_video_width = frame_width; - caca_video_height = frame_height; - caca_video_pitch = pitch; - caca_gfx_free(NULL); - caca_gfx_create(); + caca->video_width = frame_width; + caca->video_height = frame_height; + caca->video_pitch = pitch; + caca_gfx_free(caca); + caca_gfx_create(caca); } } @@ -189,8 +181,8 @@ static void caca_gfx_set_nonblock_state(void *data, bool a, static bool caca_gfx_alive(void *data) { - (void)data; - video_driver_set_size(caca_video_width, caca_video_height); + caca_t *caca = (caca_t*)data; + video_driver_set_size(caca->video_width, caca->video_height); return true; } @@ -215,7 +207,7 @@ static bool caca_gfx_has_windowed(void *data) static void caca_gfx_free(void *data) { - (void)data; + caca_t *caca = (caca_t*)data; if (caca_display) { @@ -257,6 +249,7 @@ static void caca_set_texture_frame(void *data, const void *frame, bool rgb32, unsigned width, unsigned height, float alpha) { + caca_t *caca = (caca_t*)data; unsigned pitch = width * 2; if (rgb32) @@ -269,9 +262,9 @@ static void caca_set_texture_frame(void *data, } if ( !caca_menu_frame || - caca_menu_width != width || - caca_menu_height != height || - caca_menu_pitch != pitch) + caca->menu_width != width || + caca->menu_height != height || + caca->menu_pitch != pitch) if (pitch && height) caca_menu_frame = (unsigned char*)malloc(pitch * height);