From efe72dea94d79bb845c78dff8a2a20b6503ddaf5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sat, 7 Mar 2020 16:42:12 +0100 Subject: [PATCH] (Caca) Put everything into the struct --- gfx/common/caca_common.h | 7 +-- gfx/drivers/caca_gfx.c | 87 +++++++++++++++++------------------- gfx/drivers_font/caca_font.c | 12 ++--- 3 files changed, 51 insertions(+), 55 deletions(-) diff --git a/gfx/common/caca_common.h b/gfx/common/caca_common.h index 5a57baa1a6..b858eccce7 100644 --- a/gfx/common/caca_common.h +++ b/gfx/common/caca_common.h @@ -28,9 +28,10 @@ typedef struct caca_display caca_display_t; typedef struct caca { - caca_canvas_t **caca_cv; - caca_dither_t **caca_dither; - caca_display_t **caca_display; + caca_canvas_t *cv; + caca_dither_t *dither; + caca_display_t *display; + unsigned char *menu_frame; unsigned menu_width; unsigned menu_height; unsigned menu_pitch; diff --git a/gfx/drivers/caca_gfx.c b/gfx/drivers/caca_gfx.c index 9c38d84a79..ee9217b041 100644 --- a/gfx/drivers/caca_gfx.c +++ b/gfx/drivers/caca_gfx.c @@ -30,30 +30,25 @@ #include "../../driver.h" #include "../../verbosity.h" -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 void caca_gfx_free(void *data); static void caca_gfx_create(caca_t *caca) { - caca_display = caca_create_display(NULL); - caca_cv = caca_get_canvas(caca_display); + caca->display = caca_create_display(NULL); + 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->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->dither = caca_create_dither(16, caca->video_width, caca->video_height, caca->video_pitch, 0xf800, 0x7e0, 0x1f, 0x0); @@ -68,10 +63,6 @@ static void *caca_gfx_init(const video_info_t *video, if (!caca) return NULL; - caca->caca_cv = &caca_cv; - caca->caca_dither = &caca_dither; - caca->caca_display = &caca_display; - *input = NULL; *input_data = NULL; @@ -86,7 +77,7 @@ static void *caca_gfx_init(const video_info_t *video, caca_gfx_create(caca); - if (!caca_cv || !caca_dither || !caca_display) + if (!caca->cv || !caca->dither || !caca->display) { /* TODO: handle errors */ } @@ -128,14 +119,14 @@ static bool caca_gfx_frame(void *data, const void *frame, } } - if (!caca_cv) + if (!caca->cv) return true; - if (caca_menu_frame && video_info->menu_is_alive) - frame_to_copy = caca_menu_frame; + if (caca->menu_frame && video_info->menu_is_alive) + frame_to_copy = caca->menu_frame; - width = caca_get_canvas_width(caca_cv); - height = caca_get_canvas_height(caca_cv); + width = caca_get_canvas_width(caca->cv); + height = caca_get_canvas_height(caca->cv); if ( frame_to_copy == frame && frame_width == 4 && @@ -146,7 +137,7 @@ static bool caca_gfx_frame(void *data, const void *frame, if (video_info->menu_is_alive) draw = false; - caca_clear_canvas(caca_cv); + caca_clear_canvas(caca->cv); #ifdef HAVE_MENU menu_driver_frame(video_info); @@ -157,17 +148,17 @@ static bool caca_gfx_frame(void *data, const void *frame, if (draw) { - caca_dither_bitmap(caca_cv, 0, 0, + caca_dither_bitmap(caca->cv, 0, 0, width, height, - caca_dither, frame_to_copy); + caca->dither, frame_to_copy); - buffer = caca_export_canvas_to_memory(caca_cv, "caca", &len); + buffer = caca_export_canvas_to_memory(caca->cv, "caca", &len); if (buffer) { if (len) - caca_refresh_display(caca_display); + caca_refresh_display(caca->display); free(buffer); } @@ -177,7 +168,9 @@ static bool caca_gfx_frame(void *data, const void *frame, } static void caca_gfx_set_nonblock_state(void *data, bool a, - bool b, unsigned c) { } + bool b, unsigned c) +{ +} static bool caca_gfx_alive(void *data) { @@ -207,17 +200,19 @@ static bool caca_gfx_has_windowed(void *data) static void caca_gfx_free(void *data) { - if (caca_display) - caca_free_display(caca_display); - caca_display = NULL; + caca_t *caca = (caca_t*)data; - if (caca_dither) - caca_free_dither(caca_dither); - caca_dither = NULL; + if (caca->display) + caca_free_display(caca->display); + caca->display = NULL; - if (caca_menu_frame) - free(caca_menu_frame); - caca_menu_frame = NULL; + if (caca->dither) + caca_free_dither(caca->dither); + caca->dither = NULL; + + if (caca->menu_frame) + free(caca->menu_frame); + caca->menu_frame = NULL; } static bool caca_gfx_set_shader(void *data, @@ -247,21 +242,21 @@ static void caca_set_texture_frame(void *data, if (rgb32) pitch = width * 4; - if (caca_menu_frame) - { - free(caca_menu_frame); - caca_menu_frame = NULL; - } + if (caca->menu_frame) + free(caca->menu_frame); + caca->menu_frame = NULL; - if ( !caca_menu_frame || + if ( !caca->menu_frame || caca->menu_width != width || caca->menu_height != height || caca->menu_pitch != pitch) + { if (pitch && height) - caca_menu_frame = (unsigned char*)malloc(pitch * height); + caca->menu_frame = (unsigned char*)malloc(pitch * height); + } - if (caca_menu_frame && frame && pitch && height) - memcpy(caca_menu_frame, frame, pitch * height); + if (caca->menu_frame && frame && pitch && height) + memcpy(caca->menu_frame, frame, pitch * height); } static const video_poke_interface_t caca_poke_interface = { diff --git a/gfx/drivers_font/caca_font.c b/gfx/drivers_font/caca_font.c index d055514d3f..199ec70e64 100644 --- a/gfx/drivers_font/caca_font.c +++ b/gfx/drivers_font/caca_font.c @@ -102,12 +102,12 @@ static void caca_render_msg(video_frame_info_t *video_info, align = TEXT_ALIGN_LEFT; } - if (!font->caca || !font->caca->caca_cv || !font->caca->caca_display || - !*font->caca->caca_cv || !*font->caca->caca_display) + if (!font->caca || !font->caca->cv || !font->caca->display || + !font->caca->cv || !font->caca->display) return; - width = caca_get_canvas_width(*font->caca->caca_cv); - height = caca_get_canvas_height(*font->caca->caca_cv); + width = caca_get_canvas_width(font->caca->cv); + height = caca_get_canvas_height(font->caca->cv); newY = height - (y * height * scale); switch (align) @@ -124,9 +124,9 @@ static void caca_render_msg(video_frame_info_t *video_info, break; } - caca_put_str(*font->caca->caca_cv, newX, newY, msg); + caca_put_str(font->caca->cv, newX, newY, msg); - caca_refresh_display(*font->caca->caca_display); + caca_refresh_display(font->caca->display); } font_renderer_t caca_font = {