Skip to content

Commit

Permalink
blitting: place utf8 in tcache #1334
Browse files Browse the repository at this point in the history
  • Loading branch information
dankamongmen committed Feb 7, 2021
1 parent fdd1785 commit 568e83e
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 25 deletions.
6 changes: 3 additions & 3 deletions src/lib/blit.c
Expand Up @@ -902,8 +902,8 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v
blitter = vopts->blitter;
}
const bool degrade = !(vopts->flags & NCVISUAL_OPTION_NODEGRADE);
const struct blitset* bset = lookup_blitset(notcurses_canutf8(ncplane_notcurses(nc)),
blitter, degrade);
const notcurses* notc = ncplane_notcurses(nc);
const struct blitset* bset = lookup_blitset(&notc->tcache, blitter, degrade);
if(bset == NULL){
return -1;
}
Expand All @@ -913,5 +913,5 @@ int ncblit_rgba(const void* data, int linesize, const struct ncvisual_options* v
}

ncblitter_e ncvisual_media_defblitter(const notcurses* nc, ncscale_e scale){
return rgba_blitter_default(nc->utf8, scale, nc->tcache.sextants);
return rgba_blitter_default(nc->tcache.utf8, scale, nc->tcache.sextants);
}
16 changes: 7 additions & 9 deletions src/lib/blitset.h
Expand Up @@ -4,12 +4,12 @@
#include "notcurses/notcurses.h"

static inline const struct blitset*
lookup_blitset(unsigned utf8, ncblitter_e setid, bool may_degrade) {
lookup_blitset(const tinfo* tcache, ncblitter_e setid, bool may_degrade) {
if(setid == NCBLIT_DEFAULT){ // ought have resolved NCBLIT_DEFAULT before now
return NULL;
}
// the only viable blitter in ASCII is NCBLIT_1x1
if(!utf8 && setid != NCBLIT_1x1){
if(!tcache->utf8 && setid != NCBLIT_1x1){
if(may_degrade){
setid = NCBLIT_1x1;
}else{
Expand Down Expand Up @@ -54,14 +54,12 @@ rgba_blitter_default(bool utf8, ncscale_e scale, bool sextants){
}

static inline const struct blitset*
rgba_blitter_low(bool utf8, bool sextants, ncscale_e scale, bool maydegrade,
rgba_blitter_low(const tinfo* tcache, bool sextants, ncscale_e scale, bool maydegrade,
ncblitter_e blitrec) {
const struct blitset* bset;
if(blitrec != NCBLIT_DEFAULT){
bset = lookup_blitset(utf8, blitrec, maydegrade);
}else{
bset = lookup_blitset(utf8, rgba_blitter_default(utf8, scale, sextants), maydegrade);
if(blitrec == NCBLIT_DEFAULT){
blitrec = rgba_blitter_default(tcache->utf8, scale, sextants);
}
const struct blitset* bset = lookup_blitset(tcache, blitrec, maydegrade);
if(bset && !bset->blit){ // FIXME remove this once all blitters are enabled
bset = NULL;
}
Expand All @@ -74,7 +72,7 @@ static inline const struct blitset*
rgba_blitter(const struct notcurses* nc, const struct ncvisual_options* opts) {
const bool maydegrade = !(opts && (opts->flags & NCVISUAL_OPTION_NODEGRADE));
const ncscale_e scale = opts ? opts->scaling : NCSCALE_NONE;
return rgba_blitter_low(notcurses_canutf8(nc), notcurses_cansextant(nc),
return rgba_blitter_low(&nc->tcache, notcurses_cansextant(nc),
scale, maydegrade, opts ? opts->blitter : NCBLIT_DEFAULT);
}

Expand Down
6 changes: 3 additions & 3 deletions src/lib/direct.cpp
Expand Up @@ -485,7 +485,7 @@ ncdirectv* ncdirect_render_frame(ncdirect* n, const char* file,
return nullptr;
}
//fprintf(stderr, "render %d/%d to %d+%d scaling: %d\n", ncv->rows, ncv->cols, leny, lenx, scale);
auto bset = rgba_blitter_low(n->utf8, n->tcache.sextants, scale, true, blitter);
auto bset = rgba_blitter_low(&n->tcache, n->tcache.sextants, scale, true, blitter);
if(!bset){
ncvisual_destroy(ncv);
return nullptr;
Expand Down Expand Up @@ -638,7 +638,7 @@ ncdirect* ncdirect_core_init(const char* termtype, FILE* outfp, uint64_t flags){
}
const char* encoding = nl_langinfo(CODESET);
if(encoding && strcmp(encoding, "UTF-8") == 0){
ret->utf8 = true;
ret->tcache.utf8 = true;
}
if(setup_signals(ret, (flags & NCDIRECT_OPTION_NO_QUIT_SIGHANDLERS),
true, ncdirect_stop_minimal)){
Expand Down Expand Up @@ -1066,7 +1066,7 @@ bool ncdirect_canopen_images(const ncdirect* n __attribute__ ((unused))){

// Is our encoding UTF-8? Requires LANG being set to a UTF8 locale.
bool ncdirect_canutf8(const ncdirect* n){
return n->utf8;
return n->tcache.utf8;
}

int ncdirect_flush(const ncdirect* nc){
Expand Down
3 changes: 1 addition & 2 deletions src/lib/internal.h
Expand Up @@ -268,6 +268,7 @@ typedef struct tinfo {
bool CCCflag; // "CCC" flag for palette set capability
bool BCEflag; // "BCE" flag for erases with background color
bool AMflag; // "AM" flag for automatic movement to next line
bool utf8; // are we using utf-8 encoding, as hoped?
char* smcup; // enter alternate mode
char* rmcup; // restore primary mode

Expand Down Expand Up @@ -304,7 +305,6 @@ typedef struct ncdirect {
uint64_t channels; // current channels
uint16_t stylemask; // current styles
ncinputlayer input; // input layer; we're in cbreak mode
bool utf8; // are we using utf-8 encoding, as hoped?
struct termios tpreserved; // terminal state upon entry
// some terminals (e.g. kmscon) return cursor coordinates inverted from the
// typical order. we detect it the first time ncdirect_cursor_yx() is called.
Expand Down Expand Up @@ -360,7 +360,6 @@ typedef struct notcurses {
int loglevel;
palette256 palette; // 256-indexed palette can be used instead of/with RGB
bool palette_damage[NCPALETTESIZE];
bool utf8; // are we using utf-8 encoding, as hoped?
bool libsixel; // do we have Sixel support?
} notcurses;

Expand Down
10 changes: 6 additions & 4 deletions src/lib/notcurses.c
Expand Up @@ -945,10 +945,11 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
init_lang(ret);
}
const char* encoding = nl_langinfo(CODESET);
bool utf8;
if(encoding && !strcmp(encoding, "UTF-8")){
ret->utf8 = true;
utf8 = true;
}else if(encoding && (!strcmp(encoding, "ANSI_X3.4-1968") || !strcmp(encoding, "US-ASCII"))){
ret->utf8 = false;
utf8 = false;
}else{
fprintf(stderr, "Encoding (\"%s\") was neither ANSI_X3.4-1968 nor UTF-8, refusing to start\n Did you call setlocale()?\n",
encoding ? encoding : "none found");
Expand Down Expand Up @@ -1028,6 +1029,7 @@ notcurses* notcurses_core_init(const notcurses_options* opts, FILE* outfp){
if(interrogate_terminfo(&ret->tcache, shortname_term)){
goto err;
}
ret->tcache.utf8 = utf8;
warn_terminfo(ret, &ret->tcache);
reset_term_attributes(ret);
if(ncinputlayer_init(&ret->input, stdin)){
Expand Down Expand Up @@ -2044,11 +2046,11 @@ int notcurses_mouse_disable(notcurses* n){
}

bool notcurses_canutf8(const notcurses* nc){
return nc->utf8;
return nc->tcache.utf8;
}

bool notcurses_cansextant(const notcurses* nc){
return nc->tcache.sextants && nc->utf8;
return nc->tcache.sextants && nc->tcache.utf8;
}

bool notcurses_canfade(const notcurses* nc){
Expand Down
4 changes: 2 additions & 2 deletions src/lib/plot.h
Expand Up @@ -42,6 +42,7 @@ class ncppplot {
ncplane_destroy(n);
return false;
}
const notcurses* notc = ncplane_notcurses(n);
ncblitter_e blitter = opts ? opts->gridtype : NCBLIT_DEFAULT;
if(blitter == NCBLIT_DEFAULT){
if(notcurses_canutf8(ncplane_notcurses(n))){
Expand All @@ -51,8 +52,7 @@ class ncppplot {
}
}
bool degrade_blitter = !(opts && (opts->flags & NCPLOT_OPTION_NODEGRADE));
auto bset = lookup_blitset(notcurses_canutf8(ncplane_notcurses(n)),
blitter, degrade_blitter);
auto bset = lookup_blitset(&notc->tcache, blitter, degrade_blitter);
if(bset == nullptr){
ncplane_destroy(n);
return false;
Expand Down
3 changes: 1 addition & 2 deletions src/lib/visual.cpp
Expand Up @@ -79,8 +79,7 @@ auto ncvisual_geom(const notcurses* nc, const ncvisual* n,
blitter = vopts->blitter;
}
const bool maydegrade = !(vopts && (vopts->flags & NCVISUAL_OPTION_NODEGRADE));
const struct blitset* bset = lookup_blitset(notcurses_canutf8(nc),
blitter, maydegrade);
const struct blitset* bset = lookup_blitset(&nc->tcache, blitter, maydegrade);
if(!bset){
return -1;
}
Expand Down

0 comments on commit 568e83e

Please sign in to comment.