Don't grab these two variables for every blit_line call

This commit is contained in:
twinaphex 2019-04-03 22:48:08 +02:00
parent c8b9b4ef25
commit ca56e0e91d

View File

@ -1445,73 +1445,71 @@ static void prepare_rgui_colors(rgui_t *rgui, settings_t *settings)
rgui->force_redraw = true;
}
static void blit_line(int x, int y,
const char *message, uint16_t color, uint16_t shadow_color, bool draw_shadow)
static void rgui_blit_line(
size_t pitch,
const uint8_t *font_fb,
int x, int y,
const char *message, uint16_t color,
uint16_t shadow_color, bool draw_shadow)
{
size_t pitch = menu_display_get_framebuffer_pitch();
const uint8_t *font_fb = menu_display_get_font_framebuffer();
if (font_fb)
/* We're going to do some ugly loop unswitching here
* because rendering text is *very* expensive and I don't
* want to rely on the compiler to optimise this properly... */
if (draw_shadow)
{
/* We're going to do some ugly loop unswitching here
* because rendering text is *very* expensive and I don't
* want to rely on the compiler to optimise this properly... */
if (draw_shadow)
/* Drop shadow version */
while (!string_is_empty(message))
{
/* Drop shadow version */
while (!string_is_empty(message))
unsigned i, j;
char symbol = *message++;
for (j = 0; j < FONT_HEIGHT; j++)
{
unsigned i, j;
char symbol = *message++;
for (j = 0; j < FONT_HEIGHT; j++)
for (i = 0; i < FONT_WIDTH; i++)
{
for (i = 0; i < FONT_WIDTH; i++)
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
int offset = (i + j * FONT_WIDTH) >> 3;
if ((font_fb[FONT_OFFSET(symbol) + offset] & rem) > 0)
{
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
int offset = (i + j * FONT_WIDTH) >> 3;
unsigned pixel_x = x + i;
unsigned pixel_y = y + j;
if ((font_fb[FONT_OFFSET(symbol) + offset] & rem) > 0)
{
unsigned pixel_x = x + i;
unsigned pixel_y = y + j;
/* Text pixel */
rgui_frame_buf.data[pixel_y * (pitch >> 1) + pixel_x] = color;
/* Text pixel */
rgui_frame_buf.data[pixel_y * (pitch >> 1) + pixel_x] = color;
/* Shadow pixels */
rgui_frame_buf.data[(pixel_y + 1) * (pitch >> 1) + pixel_x ] = shadow_color;
rgui_frame_buf.data[ pixel_y * (pitch >> 1) + (pixel_x + 1)] = shadow_color;
rgui_frame_buf.data[(pixel_y + 1) * (pitch >> 1) + (pixel_x + 1)] = shadow_color;
}
/* Shadow pixels */
rgui_frame_buf.data[(pixel_y + 1) * (pitch >> 1) + pixel_x ] = shadow_color;
rgui_frame_buf.data[ pixel_y * (pitch >> 1) + (pixel_x + 1)] = shadow_color;
rgui_frame_buf.data[(pixel_y + 1) * (pitch >> 1) + (pixel_x + 1)] = shadow_color;
}
}
x += FONT_WIDTH_STRIDE;
}
x += FONT_WIDTH_STRIDE;
}
else
}
else
{
/* Normal version */
while (!string_is_empty(message))
{
/* Normal version */
while (!string_is_empty(message))
unsigned i, j;
char symbol = *message++;
for (j = 0; j < FONT_HEIGHT; j++)
{
unsigned i, j;
char symbol = *message++;
for (j = 0; j < FONT_HEIGHT; j++)
for (i = 0; i < FONT_WIDTH; i++)
{
for (i = 0; i < FONT_WIDTH; i++)
{
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
int offset = (i + j * FONT_WIDTH) >> 3;
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
int offset = (i + j * FONT_WIDTH) >> 3;
if ((font_fb[FONT_OFFSET(symbol) + offset] & rem) > 0)
rgui_frame_buf.data[(y + j) * (pitch >> 1) + (x + i)] = color;
}
if ((font_fb[FONT_OFFSET(symbol) + offset] & rem) > 0)
rgui_frame_buf.data[(y + j) * (pitch >> 1) + (x + i)] = color;
}
x += FONT_WIDTH_STRIDE;
}
x += FONT_WIDTH_STRIDE;
}
}
}
@ -1662,7 +1660,8 @@ static void rgui_render_messagebox(rgui_t *rgui, const char *message)
unsigned width, glyphs_width, height;
struct string_list *list = NULL;
settings_t *settings = config_get_ptr();
size_t pitch = menu_display_get_framebuffer_pitch();
const uint8_t *font_fb = menu_display_get_font_framebuffer();
(void)settings;
if (!message || !*message)
@ -1744,15 +1743,18 @@ static void rgui_render_messagebox(rgui_t *rgui, const char *message)
}
}
for (i = 0; i < list->size; i++)
if (rgui_frame_buf.data)
{
const char *msg = list->elems[i].data;
int offset_x = (int)(FONT_WIDTH_STRIDE * (glyphs_width - utf8len(msg)) / 2);
int offset_y = (int)(FONT_HEIGHT_STRIDE * i);
for (i = 0; i < list->size; i++)
{
const char *msg = list->elems[i].data;
int offset_x = (int)(FONT_WIDTH_STRIDE * (glyphs_width - utf8len(msg)) / 2);
int offset_y = (int)(FONT_HEIGHT_STRIDE * i);
if (rgui_frame_buf.data)
blit_line(x + 8 + offset_x, y + 8 + offset_y, msg,
rgui_blit_line(pitch, font_fb,
x + 8 + offset_x, y + 8 + offset_y, msg,
rgui->colors.normal_color, rgui->colors.shadow_color, settings->bools.menu_rgui_shadows);
}
}
end:
@ -1788,6 +1790,8 @@ static void rgui_render(void *data, bool is_idle)
bool msg_force = false;
settings_t *settings = config_get_ptr();
rgui_t *rgui = (rgui_t*)data;
size_t pitch = menu_display_get_framebuffer_pitch();
const uint8_t *font_fb = menu_display_get_font_framebuffer();
static bool display_kb = false;
bool current_display_cb = false;
@ -1951,8 +1955,10 @@ static void rgui_render(void *data, bool is_idle)
title_x - 5, 0, title_width + 10, FONT_HEIGHT_STRIDE, rgui_bg_filler);
/* Draw thumbnail title */
blit_line((int)title_x, 0, thumbnail_title_buf,
rgui->colors.hover_color, rgui->colors.shadow_color, settings->bools.menu_rgui_shadows);
if (font_fb)
rgui_blit_line(pitch, font_fb,
(int)title_x, 0, thumbnail_title_buf,
rgui->colors.hover_color, rgui->colors.shadow_color, settings->bools.menu_rgui_shadows);
}
}
}
@ -2006,7 +2012,7 @@ static void rgui_render(void *data, bool is_idle)
string_to_upper(title_buf);
if (rgui_frame_buf.data)
blit_line(
rgui_blit_line(pitch, font_fb,
(int)(RGUI_TERM_START_X(fb_width) + (RGUI_TERM_WIDTH(fb_width)
- utf8len(title_buf)) * FONT_WIDTH_STRIDE / 2),
RGUI_TERM_START_Y(fb_height) - FONT_HEIGHT_STRIDE,
@ -2150,7 +2156,8 @@ static void rgui_render(void *data, bool is_idle)
}
if (rgui_frame_buf.data)
blit_line(x, y, message,
rgui_blit_line(pitch, font_fb,
x, y, message,
entry_selected ? rgui->colors.hover_color : rgui->colors.normal_color,
rgui->colors.shadow_color, settings->bools.menu_rgui_shadows);
@ -2182,7 +2189,7 @@ static void rgui_render(void *data, bool is_idle)
menu_animation_ticker(&ticker);
if (rgui_frame_buf.data)
blit_line(
rgui_blit_line(pitch, font_fb,
RGUI_TERM_START_X(fb_width) + FONT_WIDTH_STRIDE,
(RGUI_TERM_HEIGHT(fb_height) * FONT_HEIGHT_STRIDE) +
RGUI_TERM_START_Y(fb_height) + 2, sublabel_buf,
@ -2204,7 +2211,7 @@ static void rgui_render(void *data, bool is_idle)
menu_animation_ticker(&ticker);
if (rgui_frame_buf.data)
blit_line(
rgui_blit_line(pitch, font_fb,
RGUI_TERM_START_X(fb_width) + FONT_WIDTH_STRIDE,
(RGUI_TERM_HEIGHT(fb_height) * FONT_HEIGHT_STRIDE) +
RGUI_TERM_START_Y(fb_height) + 2, core_title_buf,
@ -2227,7 +2234,7 @@ static void rgui_render(void *data, bool is_idle)
menu_display_timedate(&datetime);
if (rgui_frame_buf.data)
blit_line(
rgui_blit_line(pitch, font_fb,
timedate_x,
(RGUI_TERM_HEIGHT(fb_height) * FONT_HEIGHT_STRIDE) +
RGUI_TERM_START_Y(fb_height) + 2, timedate,