screen serialize speedup + fix bad utf encode

http-comm
Ondřej Hruška 7 years ago
parent 1d6d6ee228
commit 7d6cb2b660
  1. 69
      user/screen.c

@ -7,6 +7,7 @@
#include "apars_logging.h" #include "apars_logging.h"
#include "jstring.h" #include "jstring.h"
#include "character_sets.h" #include "character_sets.h"
#include "uart_driver.h"
TerminalConfigBundle * const termconf = &persist.current.termconf; TerminalConfigBundle * const termconf = &persist.current.termconf;
TerminalConfigBundle termconf_scratch; TerminalConfigBundle termconf_scratch;
@ -1282,10 +1283,10 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
} }
Cell *cell, *cell0; Cell *cell, *cell0;
WordB2 w1, w2, w3, w4, w5; WordB2 w1;
WordB3 lw1; WordB3 lw1;
size_t remain = buf_len; int used = 0; size_t remain = buf_len;
char *bb = buffer; char *bb = buffer;
// Ideally we'd use snprintf here! // Ideally we'd use snprintf here!
@ -1294,6 +1295,34 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
if(used>0) { bb += used; remain -= used; } \ if(used>0) { bb += used; remain -= used; } \
} while(0) } while(0)
#define bufput_c(c) do { \
*bb = (char)c; bb++; \
remain--; \
} while(0)
#define bufput_2B(n) do { \
encode2B((u16) n, &w1); \
bufput_c(w1.lsb); \
bufput_c(w1.msb); \
} while(0)
#define bufput_3B(n) do { \
encode3B((u16) n, &lw1); \
bufput_c(lw1.lsb); \
bufput_c(lw1.msb); \
bufput_c(lw1.xsb); \
} while(0)
#define bufput_t2B(t, n) do { \
bufput_c(t); \
bufput_2B(n); \
} while(0)
#define bufput_t3B(t, n) do { \
bufput_c(t); \
bufput_3B(n); \
} while(0)
if (ss == NULL) { if (ss == NULL) {
*data = ss = malloc(sizeof(struct ScreenSerializeState)); *data = ss = malloc(sizeof(struct ScreenSerializeState));
ss->index = 0; ss->index = 0;
@ -1302,11 +1331,13 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
ss->lastAttrs = 0; ss->lastAttrs = 0;
memset(ss->lastChar, 0, 4); // this ensures the first char is never "repeat" memset(ss->lastChar, 0, 4); // this ensures the first char is never "repeat"
encode2B((u16) H, &w1); bufput_c('S');
encode2B((u16) W, &w2); // H W X Y Attribs
encode2B((u16) cursor.y, &w3); bufput_2B(H);
encode2B((u16) cursor.x, &w4); bufput_2B(W);
encode2B((u16) ( bufput_2B(cursor.y);
bufput_2B(cursor.x);
bufput_2B((
(scr.cursor_visible ? 1<<0 : 0) | (scr.cursor_visible ? 1<<0 : 0) |
(cursor.hanging ? 1<<1 : 0) | (cursor.hanging ? 1<<1 : 0) |
(scr.cursors_alt_mode ? 1<<2 : 0) | (scr.cursors_alt_mode ? 1<<2 : 0) |
@ -1316,11 +1347,7 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
((mouse_tracking.mode>=MTM_NORMAL) ? 1<<6 : 0) | // disables selecting ((mouse_tracking.mode>=MTM_NORMAL) ? 1<<6 : 0) | // disables selecting
(termconf_scratch.show_buttons ? 1<<7 : 0) | (termconf_scratch.show_buttons ? 1<<7 : 0) |
(termconf_scratch.show_config_links ? 1<<8 : 0) (termconf_scratch.show_config_links ? 1<<8 : 0)
) ));
, &w5);
// H W X Y Attribs
bufprint("S%c%c%c%c%c%c%c%c%c%c", w1.lsb, w1.msb, w2.lsb, w2.msb, w3.lsb, w3.msb, w4.lsb, w4.msb, w5.lsb, w5.msb);
} }
int i = ss->index; int i = ss->index;
@ -1356,25 +1383,23 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
} }
if (!changeAttrs && changeColors) { if (!changeAttrs && changeColors) {
encode2B(fg | (bg<<4), &w1); bufput_t2B('\x03', fg | (bg<<4));
bufprint("\x03%c%c", w1.lsb, w1.msb);
} }
else if (changeAttrs && !changeColors) { else if (changeAttrs && !changeColors) {
// attrs only // attrs only
encode2B(cell0->attrs, &w1); bufput_t2B('\x04', cell0->attrs);
bufprint("\x04%c%c", w1.lsb, w1.msb);
} }
else if (changeAttrs && changeColors) { else if (changeAttrs && changeColors) {
// colors and attrs // colors and attrs
encode3B((u32) (fg | (bg<<4) | (cell0->attrs<<8)), &lw1); bufput_t3B('\x01', (u32) (fg | (bg<<4) | (cell0->attrs<<8)));
bufprint("\x01%c%c%c", lw1.lsb, lw1.msb, lw1.xsb);
} }
// copy the symbol, until first 0 or reached 4 bytes // copy the symbol, until first 0 or reached 4 bytes
char c; char c;
int j = 0; int j = 0;
while ((c = cell->c[j++]) != 0 && j < 4) { while ((c = cell->c[j]) != 0 && j < 4) {
bufprint("%c", c); bufput_c(c);
j++;
} }
ss->lastFg = cell0->fg; ss->lastFg = cell0->fg;
@ -1385,12 +1410,12 @@ screenSerializeToBuffer(char *buffer, size_t buf_len, void **data)
i++; i++;
} else { } else {
// Repeat count // Repeat count
encode2B((u16) repCnt, &w1); bufput_t2B('\x02', repCnt);
bufprint("\x02%c%c", w1.lsb, w1.msb);
} }
} }
ss->index = i; ss->index = i;
bufput_c('\0'); // terminate the string
if (i < W*H-1) { if (i < W*H-1) {
return HTTPD_CGI_MORE; return HTTPD_CGI_MORE;

Loading…
Cancel
Save