mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-03-29 07:58:01 -04:00
render: use pointers to rgba foreground/background colors
This is faster, since we don't have to copy several large doubles when swapping the colors.
This commit is contained in:
parent
4e25019ba6
commit
587a9c6ffe
1 changed files with 13 additions and 11 deletions
24
render.c
24
render.c
|
|
@ -47,28 +47,28 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
||||||
int x = col * width;
|
int x = col * width;
|
||||||
int y = row * height;
|
int y = row * height;
|
||||||
|
|
||||||
struct rgba foreground = cell->attrs.have_foreground
|
const struct rgba *foreground = cell->attrs.have_foreground
|
||||||
? cell->attrs.foreground
|
? &cell->attrs.foreground
|
||||||
: !term->reverse ? term->foreground : term->background;
|
: !term->reverse ? &term->foreground : &term->background;
|
||||||
struct rgba background = cell->attrs.have_background
|
const struct rgba *background = cell->attrs.have_background
|
||||||
? cell->attrs.background
|
? &cell->attrs.background
|
||||||
: !term->reverse ? term->background : term->foreground;
|
: !term->reverse ? &term->background : &term->foreground;
|
||||||
|
|
||||||
if (has_cursor) {
|
if (has_cursor) {
|
||||||
struct rgba swap = foreground;
|
const struct rgba *swap = foreground;
|
||||||
foreground = background;
|
foreground = background;
|
||||||
background = swap;
|
background = swap;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cell->attrs.reverse) {
|
if (cell->attrs.reverse) {
|
||||||
struct rgba swap = foreground;
|
const struct rgba *swap = foreground;
|
||||||
foreground = background;
|
foreground = background;
|
||||||
background = swap;
|
background = swap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Background */
|
/* Background */
|
||||||
cairo_set_source_rgba(
|
cairo_set_source_rgba(
|
||||||
buf->cairo, background.r, background.g, background.b, background.a);
|
buf->cairo, background->r, background->g, background->b, background->a);
|
||||||
cairo_rectangle(buf->cairo, x, y, width, height);
|
cairo_rectangle(buf->cairo, x, y, width, height);
|
||||||
cairo_fill(buf->cairo);
|
cairo_fill(buf->cairo);
|
||||||
|
|
||||||
|
|
@ -89,10 +89,11 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
||||||
|
|
||||||
if (memcmp(&cell->attrs, &gseq.attrs, sizeof(cell->attrs)) != 0 ||
|
if (memcmp(&cell->attrs, &gseq.attrs, sizeof(cell->attrs)) != 0 ||
|
||||||
gseq.count >= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]) - 10 ||
|
gseq.count >= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]) - 10 ||
|
||||||
memcmp(&gseq.foreground, &foreground, sizeof(foreground)) != 0)
|
memcmp(&gseq.foreground, foreground, sizeof(*foreground)) != 0)
|
||||||
{
|
{
|
||||||
if (gseq.count >= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]) - 10)
|
if (gseq.count >= sizeof(gseq.glyphs) / sizeof(gseq.glyphs[0]) - 10)
|
||||||
LOG_WARN("hit glyph limit");
|
LOG_WARN("hit glyph limit");
|
||||||
|
|
||||||
cairo_set_scaled_font(buf->cairo, attrs_to_font(term, &gseq.attrs));
|
cairo_set_scaled_font(buf->cairo, attrs_to_font(term, &gseq.attrs));
|
||||||
cairo_set_source_rgba(
|
cairo_set_source_rgba(
|
||||||
buf->cairo, gseq.foreground.r, gseq.foreground.g,
|
buf->cairo, gseq.foreground.r, gseq.foreground.g,
|
||||||
|
|
@ -104,7 +105,7 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell,
|
||||||
gseq.g = gseq.glyphs;
|
gseq.g = gseq.glyphs;
|
||||||
gseq.count = 0;
|
gseq.count = 0;
|
||||||
gseq.attrs = cell->attrs;
|
gseq.attrs = cell->attrs;
|
||||||
gseq.foreground = foreground;
|
gseq.foreground = *foreground;
|
||||||
}
|
}
|
||||||
|
|
||||||
int new_glyphs
|
int new_glyphs
|
||||||
|
|
@ -606,6 +607,7 @@ grid_render(struct terminal *term)
|
||||||
cairo_show_glyphs(buf->cairo, gseq.glyphs, gseq.count);
|
cairo_show_glyphs(buf->cairo, gseq.glyphs, gseq.count);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert(term->grid->offset >= 0 && term->grid->offset < term->grid->num_rows);
|
||||||
#if 0
|
#if 0
|
||||||
term->grid->offset %= term->grid->size;
|
term->grid->offset %= term->grid->size;
|
||||||
if (term->grid->offset < 0)
|
if (term->grid->offset < 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue