From 4e25019ba6bd1bd07925ccafc2936416ef3f7cbe Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 8 Jul 2019 13:57:31 +0200 Subject: wip: grid is now represented as a grid, not a linear array The grid is now represented with an array of row *pointers*. Each row contains an array of cells (the row's columns). The main point of having row pointers is we can now move rows around almost for free. This is useful when scrolling with scroll margins for example, where we previously had to copy the lines in the margins. Now it's just a matter of swapping two pointers. --- csi.c | 65 +++++++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 24 deletions(-) (limited to 'csi.c') diff --git a/csi.c b/csi.c index a737022f..44d6f8bc 100644 --- a/csi.c +++ b/csi.c @@ -338,25 +338,26 @@ csi_dispatch(struct terminal *term, uint8_t final) /* Erase screen */ int param = param_get(term, 0, 0); - int start = -1; - int end = -1; switch (param) { case 0: /* From cursor to end of screen */ - start = term->cursor.linear; - end = term->cols * term->rows; + term_erase( + term, + &term->cursor, + &(struct coord){term->cols - 1, term->rows - 1}); break; case 1: /* From start of screen to cursor */ - start = 0; - end = term->cursor.linear; + term_erase(term, &(struct coord){0, 0}, &term->cursor); break; case 2: /* Erase entire screen */ - start = 0; - end = term->cols * term->rows; + term_erase( + term, + &(struct coord){0, 0}, + &(struct coord){term->cols - 1, term->rows - 1}); break; default: @@ -365,8 +366,6 @@ csi_dispatch(struct terminal *term, uint8_t final) abort(); break; } - - term_erase(term, start, end); break; } @@ -374,25 +373,27 @@ csi_dispatch(struct terminal *term, uint8_t final) /* Erase line */ int param = param_get(term, 0, 0); - int start = -1; - int end = -1; switch (param) { case 0: /* From cursor to end of line */ - start = term->cursor.linear; - end = term_cursor_linear(term, term->cursor.row, term->cols); + term_erase( + term, + &term->cursor, + &(struct coord){term->cols - 1, term->cursor.row}); break; case 1: /* From start of line to cursor */ - start = term_cursor_linear(term, term->cursor.row, 0); - end = term->cursor.linear; + term_erase( + term, &(struct coord){0, term->cursor.row}, &term->cursor); break; case 2: /* Entire line */ - start = term_cursor_linear(term, term->cursor.row, 0); - end = term_cursor_linear(term, term->cursor.row, term->cols); + term_erase( + term, + &(struct coord){0, term->cursor.row}, + &(struct coord){term->cols - 1, term->cursor.row}); break; default: @@ -402,7 +403,6 @@ csi_dispatch(struct terminal *term, uint8_t final) break; } - term_erase(term, start, end); break; } @@ -453,15 +453,25 @@ csi_dispatch(struct terminal *term, uint8_t final) int remaining = term->cols - (term->cursor.col + count); /* 'Delete' characters by moving the remaining ones */ - memmove(&term->grid->cur_line[term->cursor.col], - &term->grid->cur_line[term->cursor.col + count], - remaining * sizeof(term->grid->cur_line[0])); + memmove(&term->grid->cur_row->cells[term->cursor.col], + &term->grid->cur_row->cells[term->cursor.col + count], + remaining * sizeof(term->grid->cur_row->cells[0])); +#if 0 term_damage_update(term, term->cursor.linear, remaining); +#else + term->grid->cur_row->dirty = true; +#endif /* Erase the remainder of the line */ + term_erase( + term, + &(struct coord){term->cursor.col + remaining, term->cursor.row}, + &(struct coord){term->cols - 1, term->cursor.row}); +#if 0 term_erase( term, term->cursor.linear + remaining, term->cursor.linear + remaining + count); +#endif break; } @@ -478,9 +488,16 @@ csi_dispatch(struct terminal *term, uint8_t final) int count = min( param_get(term, 0, 1), term->cols - term->cursor.col); + term_erase( + term, + &term->cursor, + &(struct coord){term->cursor.col + count, term->cursor.row}); + +#if 0 memset(&term->grid->cur_line[term->cursor.col], 0, count * sizeof(term->grid->cur_line[0])); term_damage_erase(term, term->cursor.linear, count); +#endif break; } @@ -630,8 +647,8 @@ csi_dispatch(struct terminal *term, uint8_t final) tll_free(term->alt.damage); tll_free(term->alt.scroll_damage); - grid_memclear(term->grid, 0, term->rows * term->cols); - term_damage_erase(term, 0, term->rows * term->cols); + //grid_memclear(term->grid, 0, term->rows * term->cols); + //term_damage_erase(term, 0, term->rows * term->cols); } break; -- cgit v1.3 From 1e2a7e77f041f2b6bff2c7f7babd19fe7096609e Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 8 Jul 2019 15:56:15 +0200 Subject: rgba: drop alpha channel support --- csi.c | 50 +++++++++++++++++++++++--------------------------- main.c | 4 ++-- render.c | 32 +++++++++++++------------------- terminal.h | 10 +++++----- 4 files changed, 43 insertions(+), 53 deletions(-) (limited to 'csi.c') diff --git a/csi.c b/csi.c index 44d6f8bc..a57b1a7f 100644 --- a/csi.c +++ b/csi.c @@ -16,29 +16,29 @@ #define min(x, y) ((x) < (y) ? (x) : (y)) -static const struct rgba colors_regular[] = { - {0.000000, 0.000000, 0.000000, 1.000000}, /* 0x000000ff */ - {0.800000, 0.576471, 0.576471, 1.000000}, /* 0xcc9393ff */ - {0.498039, 0.623529, 0.498039, 1.000000}, /* 0x7f9f7fff */ - {0.815686, 0.749020, 0.560784, 1.000000}, /* 0xd0bf8fff */ - {0.423529, 0.627451, 0.639216, 1.000000}, /* 0x6ca0a3ff */ - {0.862745, 0.549020, 0.764706, 1.000000}, /* 0xdc8cc3ff */ - {0.576471, 0.878431, 0.890196, 1.000000}, /* 0x93e0e3ff */ - {0.862745, 0.862745, 0.800000, 1.000000}, /* 0xdcdcccff */ +static const struct rgb colors_regular[] = { + {0.000000, 0.000000, 0.000000}, /* 0x000000 */ + {0.800000, 0.576471, 0.576471}, /* 0xcc9393 */ + {0.498039, 0.623529, 0.498039}, /* 0x7f9f7f */ + {0.815686, 0.749020, 0.560784}, /* 0xd0bf8f */ + {0.423529, 0.627451, 0.639216}, /* 0x6ca0a3 */ + {0.862745, 0.549020, 0.764706}, /* 0xdc8cc3 */ + {0.576471, 0.878431, 0.890196}, /* 0x93e0e3 */ + {0.862745, 0.862745, 0.800000}, /* 0xdcdccc */ }; -static const struct rgba colors_bright[] = { - {0.000000, 0.000000, 0.000000, 1.000000}, /* 0x000000ff */ - {0.862745, 0.639216, 0.639216, 1.000000}, /* 0xdca3a3ff */ - {0.749020, 0.921569, 0.749020, 1.000000}, /* 0xbfebbfff */ - {0.941176, 0.874510, 0.686275, 1.000000}, /* 0xf0dfafff */ - {0.549020, 0.815686, 0.827451, 1.000000}, /* 0x8cd0d3ff */ - {0.862745, 0.549020, 0.764706, 1.000000}, /* 0xdc8cc3ff */ - {0.576471, 0.878431, 0.890196, 1.000000}, /* 0x93e0e3ff */ - {1.000000, 1.000000, 1.000000, 1.000000}, /* 0xffffffff */ +static const struct rgb colors_bright[] = { + {0.000000, 0.000000, 0.000000}, /* 0x000000 */ + {0.862745, 0.639216, 0.639216}, /* 0xdca3a3 */ + {0.749020, 0.921569, 0.749020}, /* 0xbfebbf */ + {0.941176, 0.874510, 0.686275}, /* 0xf0dfaf */ + {0.549020, 0.815686, 0.827451}, /* 0x8cd0d3 */ + {0.862745, 0.549020, 0.764706}, /* 0xdc8cc3 */ + {0.576471, 0.878431, 0.890196}, /* 0x93e0e3 */ + {1.000000, 1.000000, 1.000000}, /* 0xffffff */ }; -static struct rgba colors256[256]; +static struct rgb colors256[256]; static void __attribute__((constructor)) initialize_colors256(void) @@ -51,22 +51,20 @@ initialize_colors256(void) for (size_t r = 0; r < 6; r++) { for (size_t g = 0; g < 6; g++) { for (size_t b = 0; b < 6; b++) { - colors256[16 + r * 6 * 6 + g * 6 + b] = (struct rgba) { + colors256[16 + r * 6 * 6 + g * 6 + b] = (struct rgb) { r * 51 / 255.0, g * 51 / 255.0, b * 51 / 255.0, - 1.0, }; } } } for (size_t i = 0; i < 24; i++){ - colors256[232 + i] = (struct rgba) { + colors256[232 + i] = (struct rgb) { i * 11 / 255.0, i * 11 / 255.0, i * 11 / 255.0, - 1.0 }; } } @@ -152,11 +150,10 @@ csi_sgr(struct terminal *term) uint8_t r = term->vt.params.v[i + 2].value; uint8_t g = term->vt.params.v[i + 3].value; uint8_t b = term->vt.params.v[i + 4].value; - term->vt.attrs.foreground = (struct rgba) { + term->vt.attrs.foreground = (struct rgb) { r / 255.0, g / 255.0, b / 255.0, - 1.0, }; term->vt.attrs.have_foreground = true; i += 4; @@ -199,11 +196,10 @@ csi_sgr(struct terminal *term) uint8_t r = term->vt.params.v[i + 2].value; uint8_t g = term->vt.params.v[i + 3].value; uint8_t b = term->vt.params.v[i + 4].value; - term->vt.attrs.background = (struct rgba) { + term->vt.attrs.background = (struct rgb) { r / 255.0, g / 255.0, b / 255.0, - 1.0 }; term->vt.attrs.have_background = true; i += 4; diff --git a/main.c b/main.c index 43507811..5ce9c623 100644 --- a/main.c +++ b/main.c @@ -32,8 +32,8 @@ #define min(x, y) ((x) < (y) ? (x) : (y)) #define max(x, y) ((x) > (y) ? (x) : (y)) -static const struct rgba default_foreground = {0.86, 0.86, 0.86, 1.0}; -static const struct rgba default_background = {0.067, 0.067, 0.067, 1.0}; +static const struct rgb default_foreground = {0.86, 0.86, 0.86}; +static const struct rgb default_background = {0.067, 0.067, 0.067}; static void shm_format(void *data, struct wl_shm *wl_shm, uint32_t format) diff --git a/render.c b/render.c index 09f95ff2..2e53cb7d 100644 --- a/render.c +++ b/render.c @@ -28,7 +28,7 @@ struct glyph_sequence { int count; struct attributes attrs; - struct rgba foreground; + struct rgb foreground; }; static struct glyph_sequence gseq; @@ -47,28 +47,22 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell, double x = col * width; double y = row * height; - const struct rgba *foreground = cell->attrs.have_foreground + const struct rgb *foreground = cell->attrs.have_foreground ? &cell->attrs.foreground : !term->reverse ? &term->foreground : &term->background; - const struct rgba *background = cell->attrs.have_background + const struct rgb *background = cell->attrs.have_background ? &cell->attrs.background : !term->reverse ? &term->background : &term->foreground; - if (has_cursor) { - const struct rgba *swap = foreground; - foreground = background; - background = swap; - } - - if (cell->attrs.reverse) { - const struct rgba *swap = foreground; + /* If *one* is set, we reverse */ + if (has_cursor != cell->attrs.reverse) { + const struct rgb *swap = foreground; foreground = background; background = swap; } /* Background */ - cairo_set_source_rgba( - buf->cairo, background->r, background->g, background->b, background->a); + cairo_set_source_rgb(buf->cairo, background->r, background->g, background->b); cairo_rectangle(buf->cairo, x, y, width, height); cairo_fill(buf->cairo); @@ -95,9 +89,9 @@ render_cell(struct terminal *term, struct buffer *buf, const struct cell *cell, LOG_WARN("hit glyph limit"); cairo_set_scaled_font(buf->cairo, attrs_to_font(term, &gseq.attrs)); - cairo_set_source_rgba( + cairo_set_source_rgb( buf->cairo, gseq.foreground.r, gseq.foreground.g, - gseq.foreground.b, gseq.foreground.a); + gseq.foreground.b); cairo_show_glyphs(buf->cairo, gseq.glyphs, gseq.count); @@ -469,9 +463,9 @@ grid_render(struct terminal *term) int rmargin_width = term->width - rmargin; int bmargin_height = term->height - bmargin; - const struct rgba *bg = !term->reverse ? + const struct rgb *bg = !term->reverse ? &term->background : &term->foreground; - cairo_set_source_rgba(buf->cairo, bg->r, bg->g, bg->b, bg->a); + cairo_set_source_rgb(buf->cairo, bg->r, bg->g, bg->b); cairo_rectangle(buf->cairo, rmargin, 0, rmargin_width, term->height); cairo_rectangle(buf->cairo, 0, bmargin, term->width, bmargin_height); @@ -599,9 +593,9 @@ grid_render(struct terminal *term) if (gseq.count > 0) { cairo_set_scaled_font(buf->cairo, attrs_to_font(term, &gseq.attrs)); - cairo_set_source_rgba( + cairo_set_source_rgb( buf->cairo, gseq.foreground.r, gseq.foreground.g, - gseq.foreground.b, gseq.foreground.a); + gseq.foreground.b); cairo_show_glyphs(buf->cairo, gseq.glyphs, gseq.count); } diff --git a/terminal.h b/terminal.h index 253163af..d897b10a 100644 --- a/terminal.h +++ b/terminal.h @@ -36,7 +36,7 @@ struct wayland { struct xdg_toplevel *xdg_toplevel; }; -struct rgba { double r, g, b, a; } __attribute__((packed)); +struct rgb { double r, g, b; } __attribute__((packed)); struct attributes { #if 0 @@ -60,8 +60,8 @@ struct attributes { uint8_t have_foreground:1; uint8_t have_background:1; #endif - struct rgba foreground; /* Only valid when have_foreground == true */ - struct rgba background; /* Only valid when have_background == true */ + struct rgb foreground; /* Only valid when have_foreground == true */ + struct rgb background; /* Only valid when have_background == true */ } __attribute__((packed)); struct cell { @@ -231,8 +231,8 @@ struct terminal { bool print_needs_wrap; struct scroll_region scroll_region; - struct rgba foreground; - struct rgba background; + struct rgb foreground; + struct rgb background; struct { int col; -- cgit v1.3