Move the text attributes out of the char type

This means that more text attributes can be added in the future (there
are 8 bits available) and there is no need to keep bit twiddling when
accessing the chars themselves. Also means less data needs to be sent to
the GPU. Cell size does not change since there were currently 2 unused
bytes because of alignment.
This commit is contained in:
Kovid Goyal
2017-09-16 11:02:42 +05:30
parent 85ed5c1515
commit a92b3c605f
9 changed files with 75 additions and 70 deletions

View File

@@ -22,10 +22,11 @@ update_sprites_in_line(Cell *cells, index_type xnum) {
static inline void
set_attribute_on_line(Cell *cells, uint32_t shift, uint32_t val, index_type xnum) {
uint32_t mask = shift == DECORATION_SHIFT ? 3 : 1;
uint32_t aval = (val & mask) << (ATTRS_SHIFT + shift);
mask = ~(mask << (ATTRS_SHIFT + shift));
for (index_type i = 0; i < xnum; i++) cells[i].ch = (cells[i].ch & mask) | aval;
// Set a single attribute on all cells in the line
attrs_type mask = shift == DECORATION_SHIFT ? 3 : 1;
attrs_type aval = (val & mask) << shift;
mask = ~(mask << shift);
for (index_type i = 0; i < xnum; i++) cells[i].attrs = (cells[i].attrs & mask) | aval;
if (shift == BOLD_SHIFT || shift == ITALIC_SHIFT) update_sprites_in_line(cells, xnum);
}
@@ -42,21 +43,22 @@ copy_line(const Line *src, Line *dest) {
static inline void
clear_chars_in_line(Cell *cells, index_type xnum, char_type ch) {
// Clear only the char part of each cell, the rest must have been cleared by a memset or similar
char_type c = (1 << ATTRS_SHIFT) | ch;
for (index_type i = 0; i < xnum; i++) cells[i].ch = c;
if (ch) {
for (index_type i = 0; i < xnum; i++) { cells[i].ch = ch; cells[i].attrs = 1; }
}
}
static inline index_type
xlimit_for_line(Line *line) {
index_type xlimit = line->xnum;
if (BLANK_CHAR == 0) {
while (xlimit > 0 && (line->cells[xlimit - 1].ch & CHAR_MASK) == BLANK_CHAR) xlimit--;
while (xlimit > 0 && (line->cells[xlimit - 1].ch) == BLANK_CHAR) xlimit--;
}
return xlimit;
}
PyObject* line_text_at(char_type, combining_type);
void line_clear_text(Line *self, unsigned int at, unsigned int num, int ch);
void line_clear_text(Line *self, unsigned int at, unsigned int num, char_type ch);
void line_apply_cursor(Line *self, Cursor *cursor, unsigned int at, unsigned int num, bool clear_char);
void line_set_char(Line *, unsigned int , uint32_t , unsigned int , Cursor *, bool);
void line_right_shift(Line *, unsigned int , unsigned int );