From a42748f90fbc6b951bf99e2f549d9b2e07e75144 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Thu, 19 Jan 2017 16:40:20 +0100 Subject: [PATCH] Get rid of more function invocations of video_driver_get_size --- gfx/drivers_font/ctr_font.c | 53 +++++++++++++-------------- gfx/drivers_font/gl_raster_font.c | 26 ++++++------- gfx/drivers_font/vita2d_font.c | 25 ++++++------- gfx/drivers_font/vulkan_raster_font.c | 7 ++-- 4 files changed, 55 insertions(+), 56 deletions(-) diff --git a/gfx/drivers_font/ctr_font.c b/gfx/drivers_font/ctr_font.c index e1e0580b60..17462bc3e3 100644 --- a/gfx/drivers_font/ctr_font.c +++ b/gfx/drivers_font/ctr_font.c @@ -150,33 +150,31 @@ static int ctr_font_get_message_width(void* data, const char* msg, } static void ctr_font_render_line( - ctr_font_t* font, const char* msg, unsigned msg_len, - float scale, const unsigned int color, float pos_x, - float pos_y, unsigned text_align) + video_frame_info_t *video_info, + ctr_font_t* font, const char* msg, unsigned msg_len, + float scale, const unsigned int color, float pos_x, + float pos_y, unsigned text_align) { - int x, y, delta_x, delta_y; - unsigned width, height; unsigned i; + ctr_vertex_t* v = NULL; ctr_video_t* ctr = (ctr_video_t*)video_driver_get_ptr(false); - ctr_vertex_t* v; - video_driver_get_size(&width, &height); - - x = roundf(pos_x * width); - y = roundf((1.0f - pos_y) * height); - delta_x = 0; - delta_y = 0; - + unsigned width = video_info->width; + unsigned height = video_info->height; + int x = roundf(pos_x * width); + int y = roundf((1.0f - pos_y) * height); + int delta_x = 0; + int delta_y = 0; switch (text_align) { - case TEXT_ALIGN_RIGHT: - x -= ctr_font_get_message_width(font, msg, msg_len, scale); - break; + case TEXT_ALIGN_RIGHT: + x -= ctr_font_get_message_width(font, msg, msg_len, scale); + break; - case TEXT_ALIGN_CENTER: - x -= ctr_font_get_message_width(font, msg, msg_len, scale) / 2; - break; + case TEXT_ALIGN_CENTER: + x -= ctr_font_get_message_width(font, msg, msg_len, scale) / 2; + break; } if ((ctr->vertex_cache.size - (ctr->vertex_cache.current - ctr->vertex_cache.buffer)) < msg_len) @@ -305,9 +303,10 @@ static void ctr_font_render_line( } static void ctr_font_render_message( - ctr_font_t* font, const char* msg, float scale, - const unsigned int color, float pos_x, float pos_y, - unsigned text_align) + video_frame_info_t *video_info, + ctr_font_t* font, const char* msg, float scale, + const unsigned int color, float pos_x, float pos_y, + unsigned text_align) { int lines = 0; float line_height; @@ -318,7 +317,7 @@ static void ctr_font_render_message( /* If the font height is not supported just draw as usual */ if (!font->font_driver->get_line_height) { - ctr_font_render_line(font, msg, strlen(msg), + ctr_font_render_line(video_info, font, msg, strlen(msg), scale, color, pos_x, pos_y, text_align); return; } @@ -333,7 +332,7 @@ static void ctr_font_render_message( if (delim) { unsigned msg_len = delim - msg; - ctr_font_render_line(font, msg, msg_len, + ctr_font_render_line(video_info, font, msg, msg_len, scale, color, pos_x, pos_y - (float)lines * line_height, text_align); msg += msg_len + 1; @@ -342,7 +341,7 @@ static void ctr_font_render_message( else { unsigned msg_len = strlen(msg); - ctr_font_render_line(font, msg, msg_len, + ctr_font_render_line(video_info, font, msg, msg_len, scale, color, pos_x, pos_y - (float)lines * line_height, text_align); break; @@ -416,12 +415,12 @@ static void ctr_font_render_msg( alpha_dark = alpha * drop_alpha; color_dark = COLOR_ABGR(r_dark, g_dark, b_dark, alpha_dark); - ctr_font_render_message(font, msg, scale, color_dark, + ctr_font_render_message(video_info, font, msg, scale, color_dark, x + scale * drop_x / width, y + scale * drop_y / height, text_align); } - ctr_font_render_message(font, msg, scale, + ctr_font_render_message(video_info, font, msg, scale, color, x, y, text_align); } diff --git a/gfx/drivers_font/gl_raster_font.c b/gfx/drivers_font/gl_raster_font.c index d282f60187..06e181551f 100644 --- a/gfx/drivers_font/gl_raster_font.c +++ b/gfx/drivers_font/gl_raster_font.c @@ -388,13 +388,11 @@ static void gl_raster_font_render_message( } } -static void gl_raster_font_setup_viewport(gl_raster_t *font, bool full_screen) +static void gl_raster_font_setup_viewport(unsigned width, unsigned height, + gl_raster_t *font, bool full_screen) { - unsigned width, height; video_shader_ctx_info_t shader_info; - video_driver_get_size(&width, &height); - video_driver_set_viewport(width, height, full_screen, false); glEnable(GL_BLEND); @@ -410,12 +408,9 @@ static void gl_raster_font_setup_viewport(gl_raster_t *font, bool full_screen) video_shader_driver_use(shader_info); } -static void gl_raster_font_restore_viewport(gl_t *gl, bool full_screen) +static void gl_raster_font_restore_viewport(unsigned width, unsigned height, + gl_t *gl, bool full_screen) { - unsigned width, height; - - video_driver_get_size(&width, &height); - glBindTexture(GL_TEXTURE_2D, gl->texture[gl->tex_index]); glDisable(GL_BLEND); @@ -434,6 +429,8 @@ static void gl_raster_font_render_msg( bool full_screen = false ; gl_t *gl = NULL; gl_raster_t *font = (gl_raster_t*)data; + unsigned width = video_info->width; + unsigned height = video_info->height; const struct font_params *params = (const struct font_params*)userdata; if (!font || string_is_empty(msg)) @@ -487,7 +484,7 @@ static void gl_raster_font_render_msg( if (font && font->block) font->block->fullscreen = full_screen; else - gl_raster_font_setup_viewport(font, full_screen); + gl_raster_font_setup_viewport(width, height, font, full_screen); if (drop_x || drop_y) { @@ -506,7 +503,7 @@ static void gl_raster_font_render_msg( gl_raster_font_render_message(font, msg, scale, color, x, y, text_align); if (!font->block) - gl_raster_font_restore_viewport(gl, false); + gl_raster_font_restore_viewport(width, height, gl, false); } static const struct font_glyph *gl_raster_font_get_glyph( @@ -523,15 +520,18 @@ static const struct font_glyph *gl_raster_font_get_glyph( static void gl_raster_font_flush_block(void *data) { + unsigned width, height; gl_raster_t *font = (gl_raster_t*)data; video_font_raster_block_t *block = font ? font->block : NULL; if (!font || !block || !block->carr.coords.vertices) return; - gl_raster_font_setup_viewport(font, block->fullscreen); + video_driver_get_size(&width, &height); + + gl_raster_font_setup_viewport(width, height, font, block->fullscreen); gl_raster_font_draw_vertices(font, (video_coords_t*)&block->carr.coords); - gl_raster_font_restore_viewport(font->gl, block->fullscreen); + gl_raster_font_restore_viewport(width, height, font->gl, block->fullscreen); } static void gl_raster_font_bind_block(void *data, void *userdata) diff --git a/gfx/drivers_font/vita2d_font.c b/gfx/drivers_font/vita2d_font.c index 246305ab59..b8bc7a5045 100644 --- a/gfx/drivers_font/vita2d_font.c +++ b/gfx/drivers_font/vita2d_font.c @@ -139,20 +139,18 @@ static int vita2d_font_get_message_width(void *data, const char *msg, } static void vita2d_font_render_line( + video_frame_info_t *video_info, vita_font_t *font, const char *msg, unsigned msg_len, float scale, const unsigned int color, float pos_x, float pos_y, unsigned text_align) { - int x, y, delta_x, delta_y; - unsigned width, height; unsigned i; - - video_driver_get_size(&width, &height); - - x = roundf(pos_x * width); - y = roundf((1.0f - pos_y) * height); - delta_x = 0; - delta_y = 0; + unsigned width = video_info->width; + unsigned height = video_info->height; + int x = roundf(pos_x * width); + int y = roundf((1.0f - pos_y) * height); + int delta_x = 0; + int delta_y = 0; switch (text_align) { @@ -221,6 +219,7 @@ static void vita2d_font_render_line( } static void vita2d_font_render_message( + video_frame_info_t *video_info, vita_font_t *font, const char *msg, float scale, const unsigned int color, float pos_x, float pos_y, unsigned text_align) @@ -234,7 +233,7 @@ static void vita2d_font_render_message( /* If the font height is not supported just draw as usual */ if (!font->font_driver->get_line_height) { - vita2d_font_render_line(font, msg, strlen(msg), + vita2d_font_render_line(video_info, font, msg, strlen(msg), scale, color, pos_x, pos_y, text_align); return; } @@ -247,7 +246,7 @@ static void vita2d_font_render_message( const char *delim = strchr(msg, '\n'); unsigned msg_len = (delim) ? (delim - msg) : strlen(msg); - vita2d_font_render_line(font, msg, msg_len, + vita2d_font_render_line(video_info, font, msg, msg_len, scale, color, pos_x, pos_y - (float)lines * line_height, text_align); @@ -326,12 +325,12 @@ static void vita2d_font_render_msg( alpha_dark = alpha * drop_alpha; color_dark = RGBA8(r_dark,g_dark,b_dark,alpha_dark); - vita2d_font_render_message(font, msg, scale, color_dark, + vita2d_font_render_message(video_info, font, msg, scale, color_dark, x + scale * drop_x / width, y + scale * drop_y / height, text_align); } - vita2d_font_render_message(font, msg, scale, + vita2d_font_render_message(video_info, font, msg, scale, color, x, y, text_align); } diff --git a/gfx/drivers_font/vulkan_raster_font.c b/gfx/drivers_font/vulkan_raster_font.c index 0560ca4326..d94708811b 100644 --- a/gfx/drivers_font/vulkan_raster_font.c +++ b/gfx/drivers_font/vulkan_raster_font.c @@ -234,10 +234,9 @@ static void vulkan_raster_font_render_message( } static void vulkan_raster_font_setup_viewport( + unsigned width, unsigned height, vulkan_raster_t *font, bool full_screen) { - unsigned width, height; - video_driver_get_size(&width, &height); video_driver_set_viewport(width, height, full_screen, false); } @@ -269,6 +268,8 @@ static void vulkan_raster_font_render_msg( float x, y, scale, drop_mod, drop_alpha; vk_t *vk = NULL; vulkan_raster_t *font = (vulkan_raster_t*)data; + unsigned width = video_info->width; + unsigned height = video_info->height; const struct font_params *params = (const struct font_params*)userdata; if (!font || !msg || !*msg) @@ -316,7 +317,7 @@ static void vulkan_raster_font_render_msg( drop_alpha = 1.0f; } - vulkan_raster_font_setup_viewport(font, full_screen); + vulkan_raster_font_setup_viewport(width, height, font, full_screen); max_glyphs = strlen(msg); if (drop_x || drop_y)