direct mode: optimize out redundant SETAF, nice

This commit is contained in:
nick black 2021-02-28 09:08:47 -05:00
parent dc62ce46f1
commit 4a203ef0a9
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
4 changed files with 32 additions and 24 deletions

18
NEWS.md
View File

@ -2,21 +2,21 @@ This document attempts to list user-visible changes and any major internal
rearrangements of Notcurses.
* 2.2.3 (not yet released)
* Add `SIGILL` to the set of fatal signals we handle.
* Added `NCKEY_SIGNAL`. `NCKEY_RESIZE` is now an alias for `NCKEY_SIGNAL`.
* `SIGCONT` now synthesizes a `NCKEY_SIGNAL`, just like `SIGWINCH`.
* Implemented `NCBLIT_PIXEL` for terminals reporting Sixel support.
Added `notcurses_check_pixel_support()` and its companion
`ncdirect_check_pixel_support()`, which must be called (and must return
success) before `NCBLIT_PIXEL` will be available. `NCBLIT_PIXEL` degrades
to `NCBLIT_3x2` until support is verified. This functionality ought be
considered experimental, and its behavior is subject to change.
* Add the `nctree` widget for line-oriented hierarchical data. See
the new `notcurses_tree(3)` man page for complete information.
* Ceased exporting `cell_fchannel()`, `cell_bchannel()`,
`cell_set_fchannel()`, and `cell_set_bchannel()`. These functions were
never safe for users. Everything a user might want to manipulate can be
manipulated with more granular functions.
* Implemented `NCBLIT_PIXEL` for terminals reporting Sixel support.
Added `notcurses_check_pixel_support()` and its companion
`ncdirect_check_pixel_support()`, which must be called (and must return
success) before `NCBLIT_PIXEL` will be available. `NCBLIT_PIXEL` degrades
to `NCBLIT_3x2` until support is verified. This functionality ought be
considered experimental.
* Add `SIGILL` to the set of fatal signals we handle.
* Added `NCKEY_SIGNAL`. `NCKEY_RESIZE` is now an alias for `NCKEY_SIGNAL`.
* `SIGCONT` now synthesizes a `NCKEY_SIGNAL`, just like `SIGWINCH`.
* 2.2.2 (2021-02-18):
* `notcurses_stats()` no longer qualifies its `notcurses*` argument with

View File

@ -10,21 +10,6 @@
#include "notcurses/direct.h"
#include "internal.h"
static inline uint64_t
ncdirect_channels(const ncdirect* nc){
return nc->channels;
}
static inline bool
ncdirect_fg_default_p(const struct ncdirect* nc){
return channels_fg_default_p(ncdirect_channels(nc));
}
static inline bool
ncdirect_bg_default_p(const struct ncdirect* nc){
return channels_bg_default_p(ncdirect_channels(nc));
}
int ncdirect_putstr(ncdirect* nc, uint64_t channels, const char* utf8){
if(channels_fg_default_p(channels)){
if(ncdirect_set_fg_default(nc)){

View File

@ -1179,6 +1179,21 @@ rgba_trans_p(unsigned alpha){
return false;
}
static inline uint64_t
ncdirect_channels(const ncdirect* nc){
return nc->channels;
}
static inline bool
ncdirect_fg_default_p(const struct ncdirect* nc){
return channels_fg_default_p(ncdirect_channels(nc));
}
static inline bool
ncdirect_bg_default_p(const struct ncdirect* nc){
return channels_bg_default_p(ncdirect_channels(nc));
}
int sixel_blit(ncplane* nc, int placey, int placex, int linesize,
const void* data, int begy, int begx,
int leny, int lenx, bool blendcolors);

View File

@ -1327,6 +1327,10 @@ int ncdirect_set_bg_rgb(ncdirect* nc, unsigned rgb){
if(rgb > 0xffffffu){
return -1;
}
// FIXME need verify we're not palette, either
if(!ncdirect_bg_default_p(nc) && channels_bg_rgb(nc->channels) == rgb){
return 0;
}
if(term_bg_rgb8(nc->tcache.RGBflag, nc->tcache.setab, nc->tcache.colors, nc->ttyfp,
(rgb & 0xff0000u) >> 16u, (rgb & 0xff00u) >> 8u, rgb & 0xffu,
nc->tcache.bg_collides_default)){
@ -1340,6 +1344,10 @@ int ncdirect_set_fg_rgb(ncdirect* nc, unsigned rgb){
if(rgb > 0xffffffu){
return -1;
}
// FIXME need verify we're not palette, either
if(!ncdirect_fg_default_p(nc) && channels_fg_rgb(nc->channels) == rgb){
return 0;
}
if(term_fg_rgb8(nc->tcache.RGBflag, nc->tcache.setaf, nc->tcache.colors, nc->ttyfp,
(rgb & 0xff0000u) >> 16u, (rgb & 0xff00u) >> 8u, rgb & 0xffu)){
return -1;