Skip to content

Commit

Permalink
remove old-style notcurses_ rendering functions
Browse files Browse the repository at this point in the history
Make notcurses_render() a static inline wrapper around
ncpile_render(). Remove the deprecated
notcurses_render_to_file() and ncpile_render_to_file().
ABI3 work #1777.
  • Loading branch information
dankamongmen committed Oct 11, 2021
1 parent b9fa292 commit 1221312
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 70 deletions.
6 changes: 4 additions & 2 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,10 @@ int notcurses_render(struct notcurses* nc);
// must be freed by the caller.
int ncpile_render_to_buffer(struct ncplane* p, char** buf, size_t* buflen);

// Write the last rendered frame, in its entirety, to 'fp'. If
// notcurses_render() has not yet been called, nothing will be written.
// Write the last rendered frame, in its entirety, to 'fp'. If a frame has
// not yet been rendered, nothing will be written.
int ncpile_render_to_file(struct ncplane* p, FILE* fp);

int ncpile_render_to_file(struct ncplane* p, FILE* fp);

// Retrieve the contents of the specified cell as last rendered. The EGC is
Expand Down
97 changes: 49 additions & 48 deletions include/notcurses/notcurses.h
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,45 @@ API int notcurses_enter_alternate_screen(struct notcurses* nc)
API int notcurses_leave_alternate_screen(struct notcurses* nc)
__attribute__ ((nonnull (1)));

// Get a reference to the standard plane (one matching our current idea of the
// terminal size) for this terminal. The standard plane always exists, and its
// origin is always at the uppermost, leftmost cell of the terminal.
API struct ncplane* notcurses_stdplane(struct notcurses* nc);
API const struct ncplane* notcurses_stdplane_const(const struct notcurses* nc);

// Return the dimensions of this ncplane. y or x may be NULL.
API void ncplane_dim_yx(const struct ncplane* n, int* RESTRICT y, int* RESTRICT x)
__attribute__ ((nonnull (1)));

static inline int
ncplane_dim_y(const struct ncplane* n){
int dimy;
ncplane_dim_yx(n, &dimy, NULL);
return dimy;
}

static inline int
ncplane_dim_x(const struct ncplane* n){
int dimx;
ncplane_dim_yx(n, NULL, &dimx);
return dimx;
}

// notcurses_stdplane(), plus free bonus dimensions written to non-NULL y/x!
static inline struct ncplane*
notcurses_stddim_yx(struct notcurses* nc, int* RESTRICT y, int* RESTRICT x){
struct ncplane* s = notcurses_stdplane(nc); // can't fail
ncplane_dim_yx(s, y, x); // accepts NULL
return s;
}

static inline const struct ncplane*
notcurses_stddim_yx_const(const struct notcurses* nc, int* RESTRICT y, int* RESTRICT x){
const struct ncplane* s = notcurses_stdplane_const(nc); // can't fail
ncplane_dim_yx(s, y, x); // accepts NULL
return s;
}

// Return the topmost plane of the pile containing 'n'.
API struct ncplane* ncpile_top(struct ncplane* n);

Expand All @@ -993,16 +1032,23 @@ API int ncpile_render(struct ncplane* n);
API int ncpile_rasterize(struct ncplane* n);

// Renders and rasterizes the standard pile in one shot. Blocking call.
API int notcurses_render(struct notcurses* nc);
static inline int
notcurses_render(struct notcurses* nc){
struct ncplane* stdn = notcurses_stdplane(nc);
if(ncpile_render(stdn)){
return -1;
}
return ncpile_rasterize(stdn);
}

// Perform the rendering and rasterization portion of ncpile_render() and
// ncpile_rasterize(), but do not write the resulting buffer out to the
// terminal. Using this function, the user can control the writeout process.
// The returned buffer must be freed by the caller.
API int ncpile_render_to_buffer(struct ncplane* p, char** buf, size_t* buflen);

// Write the last rendered frame, in its entirety, to 'fp'. If
// notcurses_render() has not yet been called, nothing will be written.
// Write the last rendered frame, in its entirety, to 'fp'. If a frame has
// not yet been rendered, nothing will be written.
API int ncpile_render_to_file(struct ncplane* p, FILE* fp);

// Return the topmost ncplane of the standard pile.
Expand Down Expand Up @@ -1156,45 +1202,6 @@ API struct notcurses* ncplane_notcurses(const struct ncplane* n)
API const struct notcurses* ncplane_notcurses_const(const struct ncplane* n)
__attribute__ ((nonnull (1)));

// Return the dimensions of this ncplane. y or x may be NULL.
API void ncplane_dim_yx(const struct ncplane* n, int* RESTRICT y, int* RESTRICT x)
__attribute__ ((nonnull (1)));

// Get a reference to the standard plane (one matching our current idea of the
// terminal size) for this terminal. The standard plane always exists, and its
// origin is always at the uppermost, leftmost cell of the terminal.
API struct ncplane* notcurses_stdplane(struct notcurses* nc);
API const struct ncplane* notcurses_stdplane_const(const struct notcurses* nc);

// notcurses_stdplane(), plus free bonus dimensions written to non-NULL y/x!
static inline struct ncplane*
notcurses_stddim_yx(struct notcurses* nc, int* RESTRICT y, int* RESTRICT x){
struct ncplane* s = notcurses_stdplane(nc); // can't fail
ncplane_dim_yx(s, y, x); // accepts NULL
return s;
}

static inline const struct ncplane*
notcurses_stddim_yx_const(const struct notcurses* nc, int* RESTRICT y, int* RESTRICT x){
const struct ncplane* s = notcurses_stdplane_const(nc); // can't fail
ncplane_dim_yx(s, y, x); // accepts NULL
return s;
}

static inline int
ncplane_dim_y(const struct ncplane* n){
int dimy;
ncplane_dim_yx(n, &dimy, NULL);
return dimy;
}

static inline int
ncplane_dim_x(const struct ncplane* n){
int dimx;
ncplane_dim_yx(n, NULL, &dimx);
return dimx;
}

// Retrieve pixel geometry for the display region ('pxy', 'pxx'), each cell
// ('celldimy', 'celldimx'), and the maximum displayable bitmap ('maxbmapy',
// 'maxbmapx'). If bitmaps are not supported, 'maxbmapy' and 'maxbmapx' will
Expand Down Expand Up @@ -4123,12 +4130,6 @@ API void palette256_free(ncpalette* p) __attribute__ ((deprecated));
API __attribute__ ((deprecated)) int ncvisual_inflate(struct ncvisual* n, int scale)
__attribute__ ((nonnull (1)));

API int notcurses_render_to_buffer(struct notcurses* nc, char** buf, size_t* buflen)
__attribute__ ((deprecated));

API int notcurses_render_to_file(struct notcurses* nc, FILE* fp)
__attribute__ ((deprecated));

API void notcurses_debug_caps(const struct notcurses* nc, FILE* debugfp)
__attribute__ ((deprecated)) __attribute__ ((nonnull (1, 2)));

Expand Down
20 changes: 0 additions & 20 deletions src/lib/render.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,10 +1428,6 @@ int ncpile_render_to_file(ncplane* n, FILE* fp){
return ret;
}

int notcurses_render_to_file(notcurses* nc, FILE* fp){
return ncpile_render_to_file(notcurses_stdplane(nc), fp);
}

// We execute the painter's algorithm, starting from our topmost plane. The
// damagevector should be all zeros on input. On success, it will reflect
// which cells were changed. We solve for each coordinate's cell by walking
Expand Down Expand Up @@ -1526,18 +1522,6 @@ int ncpile_render(ncplane* n){
return 0;
}

int notcurses_render(notcurses* nc){
//fprintf(stderr, "--------------- BEGIN RENDER\n");
//notcurses_debug(nc, stderr);
ncplane* stdn = notcurses_stdplane(nc);
if(ncpile_render(stdn)){
return -1;
}
int i = ncpile_rasterize(stdn);
//fprintf(stderr, "----------------- END RENDER\n");
return i;
}

// for now, we just run the top half of notcurses_render(), and copy out the
// memstream from within rstate. we want to allocate our own here, and return
// it, to avoid the copy, but we need feed the params through to do so FIXME.
Expand All @@ -1563,10 +1547,6 @@ int ncpile_render_to_buffer(ncplane* p, char** buf, size_t* buflen){
return 0;
}

int notcurses_render_to_buffer(notcurses* nc, char** buf, size_t* buflen){
return ncpile_render_to_buffer(notcurses_stdplane(nc), buf, buflen);
}

// copy the UTF8-encoded EGC out of the cell, whether simple or complex. the
// result is not tied to the ncplane, and persists across erases / destruction.
static inline char*
Expand Down

0 comments on commit 1221312

Please sign in to comment.