mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 00:14:22 +08:00
Graphics: Initial separation of font cache from graphics/nxterm. Now in libnx/nxfronts
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* nuttx/graphics/nxterm/nxterm.h
|
* nuttx/graphics/nxterm/nxterm.h
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012, 2014 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012, 2014, 2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -33,8 +33,8 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __GRAPHICS_NXTERM_NXTERM_INTERNAL_H
|
#ifndef __GRAPHICS_NXTERM_NXTERM_H
|
||||||
#define __GRAPHICS_NXTERM_NXTERM_INTERNAL_H
|
#define __GRAPHICS_NXTERM_NXTERM_H
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
@@ -61,10 +61,6 @@
|
|||||||
#define BMFLAGS_NOGLYPH (1 << 0) /* No glyph available, use space */
|
#define BMFLAGS_NOGLYPH (1 << 0) /* No glyph available, use space */
|
||||||
#define BM_ISSPACE(bm) (((bm)->flags & BMFLAGS_NOGLYPH) != 0)
|
#define BM_ISSPACE(bm) (((bm)->flags & BMFLAGS_NOGLYPH) != 0)
|
||||||
|
|
||||||
/* Sizes and maximums */
|
|
||||||
|
|
||||||
#define MAX_USECNT 255 /* Limit to range of a uint8_t */
|
|
||||||
|
|
||||||
/* Device path formats */
|
/* Device path formats */
|
||||||
|
|
||||||
#define NX_DEVNAME_FORMAT "/dev/nxterm%d"
|
#define NX_DEVNAME_FORMAT "/dev/nxterm%d"
|
||||||
@@ -81,6 +77,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/* Identifies the state of the VT100 escape sequence processing */
|
/* Identifies the state of the VT100 escape sequence processing */
|
||||||
|
|
||||||
enum nxterm_vt100state_e
|
enum nxterm_vt100state_e
|
||||||
@@ -111,18 +108,6 @@ struct nxterm_operations_s
|
|||||||
unsigned int stride);
|
unsigned int stride);
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Describes one cached glyph bitmap */
|
|
||||||
|
|
||||||
struct nxterm_glyph_s
|
|
||||||
{
|
|
||||||
uint8_t code; /* Character code */
|
|
||||||
uint8_t height; /* Height of this glyph (in rows) */
|
|
||||||
uint8_t width; /* Width of this glyph (in pixels) */
|
|
||||||
uint8_t stride; /* Width of the glyph row (in bytes) */
|
|
||||||
uint8_t usecnt; /* Use count */
|
|
||||||
FAR uint8_t *bitmap; /* Allocated bitmap memory */
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Describes on character on the display */
|
/* Describes on character on the display */
|
||||||
|
|
||||||
struct nxterm_bitmap_s
|
struct nxterm_bitmap_s
|
||||||
@@ -138,8 +123,7 @@ struct nxterm_state_s
|
|||||||
{
|
{
|
||||||
FAR const struct nxterm_operations_s *ops; /* Window operations */
|
FAR const struct nxterm_operations_s *ops; /* Window operations */
|
||||||
FAR void *handle; /* The window handle */
|
FAR void *handle; /* The window handle */
|
||||||
FAR struct nxterm_window_s wndo; /* Describes the window and font */
|
FAR struct nxterm_window_s wndo; /* Describes the window and font */
|
||||||
NXHANDLE font; /* The current font handle */
|
|
||||||
sem_t exclsem; /* Forces mutually exclusive access */
|
sem_t exclsem; /* Forces mutually exclusive access */
|
||||||
#ifdef CONFIG_DEBUG_FEATURES
|
#ifdef CONFIG_DEBUG_FEATURES
|
||||||
pid_t holder; /* Deadlock avoidance */
|
pid_t holder; /* Deadlock avoidance */
|
||||||
@@ -151,7 +135,6 @@ struct nxterm_state_s
|
|||||||
uint8_t fheight; /* Max height of a font in pixels */
|
uint8_t fheight; /* Max height of a font in pixels */
|
||||||
uint8_t fwidth; /* Max width of a font in pixels */
|
uint8_t fwidth; /* Max width of a font in pixels */
|
||||||
uint8_t spwidth; /* The width of a space */
|
uint8_t spwidth; /* The width of a space */
|
||||||
uint8_t maxglyphs; /* Size of the glyph[] array */
|
|
||||||
|
|
||||||
uint16_t maxchars; /* Size of the bm[] array */
|
uint16_t maxchars; /* Size of the bm[] array */
|
||||||
uint16_t nchars; /* Number of chars in the bm[] array */
|
uint16_t nchars; /* Number of chars in the bm[] array */
|
||||||
@@ -165,13 +148,10 @@ struct nxterm_state_s
|
|||||||
|
|
||||||
/* Font cache data storage */
|
/* Font cache data storage */
|
||||||
|
|
||||||
|
FCACHE fcache; /* Font cache handle */
|
||||||
struct nxterm_bitmap_s cursor;
|
struct nxterm_bitmap_s cursor;
|
||||||
struct nxterm_bitmap_s bm[CONFIG_NXTERM_MXCHARS];
|
struct nxterm_bitmap_s bm[CONFIG_NXTERM_MXCHARS];
|
||||||
|
|
||||||
/* Glyph cache data storage */
|
|
||||||
|
|
||||||
struct nxterm_glyph_s glyph[CONFIG_NXTERM_CACHESIZE];
|
|
||||||
|
|
||||||
/* Keyboard input support */
|
/* Keyboard input support */
|
||||||
|
|
||||||
#ifdef CONFIG_NXTERM_NXKBDIN
|
#ifdef CONFIG_NXTERM_NXKBDIN
|
||||||
@@ -235,8 +215,8 @@ enum nxterm_vt100state_e nxterm_vt100(FAR struct nxterm_state_s *priv, char ch);
|
|||||||
|
|
||||||
void nxterm_home(FAR struct nxterm_state_s *priv);
|
void nxterm_home(FAR struct nxterm_state_s *priv);
|
||||||
void nxterm_newline(FAR struct nxterm_state_s *priv);
|
void nxterm_newline(FAR struct nxterm_state_s *priv);
|
||||||
FAR const struct nxterm_bitmap_s *nxterm_addchar(NXHANDLE hfont,
|
FAR const struct nxterm_bitmap_s *nxterm_addchar(FAR struct nxterm_state_s *priv,
|
||||||
FAR struct nxterm_state_s *priv, uint8_t ch);
|
uint8_t ch);
|
||||||
int nxterm_hidechar(FAR struct nxterm_state_s *priv,
|
int nxterm_hidechar(FAR struct nxterm_state_s *priv,
|
||||||
FAR const struct nxterm_bitmap_s *bm);
|
FAR const struct nxterm_bitmap_s *bm);
|
||||||
int nxterm_backspace(FAR struct nxterm_state_s *priv);
|
int nxterm_backspace(FAR struct nxterm_state_s *priv);
|
||||||
@@ -251,4 +231,4 @@ void nxterm_hidecursor(FAR struct nxterm_state_s *priv);
|
|||||||
|
|
||||||
void nxterm_scroll(FAR struct nxterm_state_s *priv, int scrollheight);
|
void nxterm_scroll(FAR struct nxterm_state_s *priv, int scrollheight);
|
||||||
|
|
||||||
#endif /* __GRAPHICS_NXTERM_NXTERM_INTERNAL_H */
|
#endif /* __GRAPHICS_NXTERM_NXTERM_H */
|
||||||
|
|||||||
+20
-321
@@ -48,294 +48,26 @@
|
|||||||
|
|
||||||
#include "nxterm.h"
|
#include "nxterm.h"
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/* Select renderer -- Some additional logic would be required to support
|
|
||||||
* pixel depths that are not directly addressable (1,2,4, and 24).
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if CONFIG_NXTERM_BPP == 1
|
|
||||||
# define RENDERER nxf_convert_1bpp
|
|
||||||
#elif CONFIG_NXTERM_BPP == 2
|
|
||||||
# define RENDERER nxf_convert_2bpp
|
|
||||||
#elif CONFIG_NXTERM_BPP == 4
|
|
||||||
# define RENDERER nxf_convert_4bpp
|
|
||||||
#elif CONFIG_NXTERM_BPP == 8
|
|
||||||
# define RENDERER nxf_convert_8bpp
|
|
||||||
#elif CONFIG_NXTERM_BPP == 16
|
|
||||||
# define RENDERER nxf_convert_16bpp
|
|
||||||
#elif CONFIG_NXTERM_BPP == 24
|
|
||||||
# define RENDERER nxf_convert_24bpp
|
|
||||||
#elif CONFIG_NXTERM_BPP == 32
|
|
||||||
# define RENDERER nxf_convert_32bpp
|
|
||||||
#else
|
|
||||||
# error "Unsupported CONFIG_NXTERM_BPP"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Types
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Public Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Private Functions
|
* Private Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: nxterm_freeglyph
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static void nxterm_freeglyph(FAR struct nxterm_glyph_s *glyph)
|
|
||||||
{
|
|
||||||
if (glyph->bitmap)
|
|
||||||
{
|
|
||||||
kmm_free(glyph->bitmap);
|
|
||||||
}
|
|
||||||
memset(glyph, 0, sizeof(struct nxterm_glyph_s));
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: nxterm_allocglyph
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static inline FAR struct nxterm_glyph_s *
|
|
||||||
nxterm_allocglyph(FAR struct nxterm_state_s *priv)
|
|
||||||
{
|
|
||||||
FAR struct nxterm_glyph_s *glyph = NULL;
|
|
||||||
FAR struct nxterm_glyph_s *luglyph = NULL;
|
|
||||||
uint8_t luusecnt;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* Search through the glyph cache looking for an unused glyph. Also, keep
|
|
||||||
* track of the least used glyph as well. We need that if we have to replace
|
|
||||||
* a glyph in the cache.
|
|
||||||
*/
|
|
||||||
|
|
||||||
for (i = 0; i < priv->maxglyphs; i++)
|
|
||||||
{
|
|
||||||
/* Is this glyph in use? */
|
|
||||||
|
|
||||||
glyph = &priv->glyph[i];
|
|
||||||
if (!glyph->usecnt)
|
|
||||||
{
|
|
||||||
/* No.. return this glyph with a use count of one */
|
|
||||||
|
|
||||||
glyph->usecnt = 1;
|
|
||||||
return glyph;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Yes.. check for the least recently used */
|
|
||||||
|
|
||||||
if (!luglyph || glyph->usecnt < luglyph->usecnt)
|
|
||||||
{
|
|
||||||
luglyph = glyph;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* If we get here, the glyph cache is full. We replace the least used
|
|
||||||
* glyph with the one we need now. (luglyph can't be NULL).
|
|
||||||
*/
|
|
||||||
|
|
||||||
luusecnt = luglyph->usecnt;
|
|
||||||
nxterm_freeglyph(luglyph);
|
|
||||||
|
|
||||||
/* But lets decrement all of the usecnts so that the new one one be so
|
|
||||||
* far behind in the counts as the older ones.
|
|
||||||
*/
|
|
||||||
|
|
||||||
if (luusecnt > 1)
|
|
||||||
{
|
|
||||||
uint8_t decr = luusecnt - 1;
|
|
||||||
|
|
||||||
for (i = 0; i < priv->maxglyphs; i++)
|
|
||||||
{
|
|
||||||
/* Is this glyph in use? */
|
|
||||||
|
|
||||||
glyph = &priv->glyph[i];
|
|
||||||
if (glyph->usecnt > decr)
|
|
||||||
{
|
|
||||||
glyph->usecnt -= decr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Then return the least used glyph */
|
|
||||||
|
|
||||||
luglyph->usecnt = 1;
|
|
||||||
return luglyph;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: nxterm_findglyph
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static FAR struct nxterm_glyph_s *
|
|
||||||
nxterm_findglyph(FAR struct nxterm_state_s *priv, uint8_t ch)
|
|
||||||
{
|
|
||||||
int i;
|
|
||||||
|
|
||||||
/* First, try to find the glyph in the cache of pre-rendered glyphs */
|
|
||||||
|
|
||||||
for (i = 0; i < priv->maxglyphs; i++)
|
|
||||||
{
|
|
||||||
FAR struct nxterm_glyph_s *glyph = &priv->glyph[i];
|
|
||||||
if (glyph->usecnt > 0 && glyph->code == ch)
|
|
||||||
{
|
|
||||||
/* Increment the use count (unless it is already at the max) */
|
|
||||||
|
|
||||||
if (glyph->usecnt < MAX_USECNT)
|
|
||||||
{
|
|
||||||
glyph->usecnt++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* And return the glyph that we found */
|
|
||||||
|
|
||||||
return glyph;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: nxterm_renderglyph
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static inline FAR struct nxterm_glyph_s *
|
|
||||||
nxterm_renderglyph(FAR struct nxterm_state_s *priv,
|
|
||||||
FAR const struct nx_fontbitmap_s *fbm, uint8_t ch)
|
|
||||||
{
|
|
||||||
FAR struct nxterm_glyph_s *glyph = NULL;
|
|
||||||
FAR nxgl_mxpixel_t *ptr;
|
|
||||||
#if CONFIG_NXTERM_BPP < 8
|
|
||||||
nxgl_mxpixel_t pixel;
|
|
||||||
#endif
|
|
||||||
int bmsize;
|
|
||||||
int row;
|
|
||||||
int col;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
/* Allocate the glyph (always succeeds) */
|
|
||||||
|
|
||||||
glyph = nxterm_allocglyph(priv);
|
|
||||||
glyph->code = ch;
|
|
||||||
|
|
||||||
/* Get the dimensions of the glyph */
|
|
||||||
|
|
||||||
glyph->width = fbm->metric.width + fbm->metric.xoffset;
|
|
||||||
glyph->height = fbm->metric.height + fbm->metric.yoffset;
|
|
||||||
|
|
||||||
/* Get the physical width of the glyph in bytes */
|
|
||||||
|
|
||||||
glyph->stride = (glyph->width * CONFIG_NXTERM_BPP + 7) / 8;
|
|
||||||
|
|
||||||
/* Allocate memory to hold the glyph with its offsets */
|
|
||||||
|
|
||||||
bmsize = glyph->stride * glyph->height;
|
|
||||||
glyph->bitmap = (FAR uint8_t *)kmm_malloc(bmsize);
|
|
||||||
|
|
||||||
if (glyph->bitmap)
|
|
||||||
{
|
|
||||||
/* Initialize the glyph memory to the background color using the
|
|
||||||
* hard-coded bits-per-pixel (BPP).
|
|
||||||
*
|
|
||||||
* TODO: The rest of NX is configured to support multiple devices
|
|
||||||
* with differing BPP. They logic should be extended to support
|
|
||||||
* differing BPP's as well.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#if CONFIG_NXTERM_BPP < 8
|
|
||||||
pixel = priv->wndo.wcolor[0];
|
|
||||||
|
|
||||||
# if CONFIG_NXTERM_BPP == 1
|
|
||||||
|
|
||||||
/* Pack 1-bit pixels into a 2-bits */
|
|
||||||
|
|
||||||
pixel &= 0x01;
|
|
||||||
pixel = (pixel) << 1 | pixel;
|
|
||||||
|
|
||||||
# endif
|
|
||||||
# if CONFIG_NXTERM_BPP < 4
|
|
||||||
|
|
||||||
/* Pack 2-bit pixels into a nibble */
|
|
||||||
|
|
||||||
pixel &= 0x03;
|
|
||||||
pixel = (pixel) << 2 | pixel;
|
|
||||||
|
|
||||||
# endif
|
|
||||||
|
|
||||||
/* Pack 4-bit nibbles into a byte */
|
|
||||||
|
|
||||||
pixel &= 0x0f;
|
|
||||||
pixel = (pixel) << 4 | pixel;
|
|
||||||
|
|
||||||
ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
|
|
||||||
for (row = 0; row < glyph->height; row++)
|
|
||||||
{
|
|
||||||
for (col = 0; col < glyph->stride; col++)
|
|
||||||
{
|
|
||||||
/* Transfer the packed bytes into the buffer */
|
|
||||||
|
|
||||||
*ptr++ = pixel;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#elif CONFIG_NXTERM_BPP == 24
|
|
||||||
# error "Additional logic is needed here for 24bpp support"
|
|
||||||
|
|
||||||
#else /* CONFIG_NXTERM_BPP = {8,16,32} */
|
|
||||||
|
|
||||||
ptr = (FAR nxgl_mxpixel_t *)glyph->bitmap;
|
|
||||||
for (row = 0; row < glyph->height; row++)
|
|
||||||
{
|
|
||||||
/* Just copy the color value into the glyph memory */
|
|
||||||
|
|
||||||
for (col = 0; col < glyph->width; col++)
|
|
||||||
{
|
|
||||||
*ptr++ = priv->wndo.wcolor[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Then render the glyph into the allocated memory */
|
|
||||||
|
|
||||||
ret = RENDERER((FAR nxgl_mxpixel_t *)glyph->bitmap,
|
|
||||||
glyph->height, glyph->width, glyph->stride,
|
|
||||||
fbm, priv->wndo.fcolor[0]);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
/* Actually, the RENDERER never returns a failure */
|
|
||||||
|
|
||||||
gerr("ERROR: nxterm_renderglyph: RENDERER failed\n");
|
|
||||||
nxterm_freeglyph(glyph);
|
|
||||||
glyph = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return glyph;
|
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: nxterm_fontsize
|
* Name: nxterm_fontsize
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
static int nxterm_fontsize(NXHANDLE hfont, uint8_t ch, FAR struct nxgl_size_s *size)
|
static int nxterm_fontsize(FAR struct nxterm_state_s *priv, uint8_t ch,
|
||||||
|
FAR struct nxgl_size_s *size)
|
||||||
{
|
{
|
||||||
FAR const struct nx_fontbitmap_s *fbm;
|
FAR const struct nx_fontbitmap_s *fbm;
|
||||||
|
NXHANDLE hfont;
|
||||||
|
|
||||||
/* No, it is not cached... Does the code map to a font? */
|
/* Get the handle of the font managed by the font cache */
|
||||||
|
|
||||||
|
hfont = nxf_cache_getfonthandle(priv->fcache);
|
||||||
|
DEBUGASSERT(hfront != NULL);
|
||||||
|
|
||||||
|
/* Does the character code map to a font? */
|
||||||
|
|
||||||
fbm = nxf_getbitmap(hfont, ch);
|
fbm = nxf_getbitmap(hfont, ch);
|
||||||
if (fbm)
|
if (fbm)
|
||||||
@@ -347,40 +79,7 @@ static int nxterm_fontsize(NXHANDLE hfont, uint8_t ch, FAR struct nxgl_size_s *s
|
|||||||
return OK;
|
return OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
return ERROR;
|
return -ENOENT;
|
||||||
}
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Name: nxterm_getglyph
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
static FAR struct nxterm_glyph_s *
|
|
||||||
nxterm_getglyph(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
|
|
||||||
{
|
|
||||||
FAR struct nxterm_glyph_s *glyph;
|
|
||||||
FAR const struct nx_fontbitmap_s *fbm;
|
|
||||||
|
|
||||||
/* First, try to find the glyph in the cache of pre-rendered glyphs */
|
|
||||||
|
|
||||||
glyph = nxterm_findglyph(priv, ch);
|
|
||||||
if (glyph)
|
|
||||||
{
|
|
||||||
/* We found it in the cache .. return the cached glyph */
|
|
||||||
|
|
||||||
return glyph;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* No, it is not cached... Does the code map to a font? */
|
|
||||||
|
|
||||||
fbm = nxf_getbitmap(hfont, ch);
|
|
||||||
if (fbm)
|
|
||||||
{
|
|
||||||
/* Yes.. render the glyph */
|
|
||||||
|
|
||||||
glyph = nxterm_renderglyph(priv, fbm, ch);
|
|
||||||
}
|
|
||||||
|
|
||||||
return glyph;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@@ -397,10 +96,10 @@ nxterm_getglyph(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
FAR const struct nxterm_bitmap_s *
|
FAR const struct nxterm_bitmap_s *
|
||||||
nxterm_addchar(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
|
nxterm_addchar(FAR struct nxterm_state_s *priv, uint8_t ch)
|
||||||
{
|
{
|
||||||
FAR struct nxterm_bitmap_s *bm = NULL;
|
FAR struct nxterm_bitmap_s *bm = NULL;
|
||||||
FAR struct nxterm_glyph_s *glyph;
|
FAR struct nxfonts_glyph_s *glyph;
|
||||||
|
|
||||||
/* Is there space for another character on the display? */
|
/* Is there space for another character on the display? */
|
||||||
|
|
||||||
@@ -416,7 +115,7 @@ nxterm_addchar(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
|
|||||||
|
|
||||||
/* Find (or create) the matching glyph */
|
/* Find (or create) the matching glyph */
|
||||||
|
|
||||||
glyph = nxterm_getglyph(hfont, priv, ch);
|
glyph = nxf_cache_getglyph(priv->fcache, ch);
|
||||||
if (!glyph)
|
if (!glyph)
|
||||||
{
|
{
|
||||||
/* No, there is no font for this code. Just mark this as a space. */
|
/* No, there is no font for this code. Just mark this as a space. */
|
||||||
@@ -449,6 +148,7 @@ nxterm_addchar(NXHANDLE hfont, FAR struct nxterm_state_s *priv, uint8_t ch)
|
|||||||
* Erase a character from the window.
|
* Erase a character from the window.
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int nxterm_hidechar(FAR struct nxterm_state_s *priv,
|
int nxterm_hidechar(FAR struct nxterm_state_s *priv,
|
||||||
FAR const struct nxterm_bitmap_s *bm)
|
FAR const struct nxterm_bitmap_s *bm)
|
||||||
{
|
{
|
||||||
@@ -461,7 +161,7 @@ int nxterm_hidechar(FAR struct nxterm_state_s *priv,
|
|||||||
* modification is required (not an error).
|
* modification is required (not an error).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
ret = nxterm_fontsize(priv->font, bm->code, &fsize);
|
ret = nxterm_fontsize(priv, bm->code, &fsize);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
/* It was rendered as a space. */
|
/* It was rendered as a space. */
|
||||||
@@ -572,10 +272,10 @@ void nxterm_newline(FAR struct nxterm_state_s *priv)
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
void nxterm_fillchar(FAR struct nxterm_state_s *priv,
|
void nxterm_fillchar(FAR struct nxterm_state_s *priv,
|
||||||
FAR const struct nxgl_rect_s *rect,
|
FAR const struct nxgl_rect_s *rect,
|
||||||
FAR const struct nxterm_bitmap_s *bm)
|
FAR const struct nxterm_bitmap_s *bm)
|
||||||
{
|
{
|
||||||
FAR struct nxterm_glyph_s *glyph;
|
FAR struct nxfonts_glyph_s *glyph;
|
||||||
struct nxgl_rect_s bounds;
|
struct nxgl_rect_s bounds;
|
||||||
struct nxgl_rect_s intersection;
|
struct nxgl_rect_s intersection;
|
||||||
struct nxgl_size_s fsize;
|
struct nxgl_size_s fsize;
|
||||||
@@ -590,7 +290,7 @@ void nxterm_fillchar(FAR struct nxterm_state_s *priv,
|
|||||||
|
|
||||||
/* Get the size of the font glyph (which may not have been created yet) */
|
/* Get the size of the font glyph (which may not have been created yet) */
|
||||||
|
|
||||||
ret = nxterm_fontsize(priv->font, bm->code, &fsize);
|
ret = nxterm_fontsize(priv, bm->code, &fsize);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
/* This would mean that there is no bitmap for the character code and
|
/* This would mean that there is no bitmap for the character code and
|
||||||
@@ -632,7 +332,7 @@ void nxterm_fillchar(FAR struct nxterm_state_s *priv,
|
|||||||
|
|
||||||
/* Find (or create) the glyph that goes with this font */
|
/* Find (or create) the glyph that goes with this font */
|
||||||
|
|
||||||
glyph = nxterm_getglyph(priv->font, priv, bm->code);
|
glyph = nxf_cache_getglyph(priv->fcache, bm->code);
|
||||||
if (!glyph)
|
if (!glyph)
|
||||||
{
|
{
|
||||||
/* Shouldn't happen */
|
/* Shouldn't happen */
|
||||||
@@ -648,4 +348,3 @@ void nxterm_fillchar(FAR struct nxterm_state_s *priv,
|
|||||||
DEBUGASSERT(ret >= 0);
|
DEBUGASSERT(ret >= 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ void nxterm_putc(FAR struct nxterm_state_s *priv, uint8_t ch)
|
|||||||
* display.
|
* display.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
bm = nxterm_addchar(priv->font, priv, ch);
|
bm = nxterm_addchar(priv, ch);
|
||||||
if (bm)
|
if (bm)
|
||||||
{
|
{
|
||||||
nxterm_fillchar(priv, NULL, bm);
|
nxterm_fillchar(priv, NULL, bm);
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* nuttx/graphics/nxterm/nxterm_register.c
|
* nuttx/graphics/nxterm/nxterm_register.c
|
||||||
*
|
*
|
||||||
* Copyright (C) 2012, 2016 Gregory Nutt. All rights reserved.
|
* Copyright (C) 2012, 2016-2017 Gregory Nutt. All rights reserved.
|
||||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -66,7 +66,9 @@ FAR struct nxterm_state_s *
|
|||||||
FAR const struct nxterm_operations_s *ops, int minor)
|
FAR const struct nxterm_operations_s *ops, int minor)
|
||||||
{
|
{
|
||||||
FAR struct nxterm_state_s *priv;
|
FAR struct nxterm_state_s *priv;
|
||||||
|
FAR const struct nx_font_s *fontset;
|
||||||
char devname[NX_DEVNAME_SIZE];
|
char devname[NX_DEVNAME_SIZE];
|
||||||
|
NXHANDLE hfont;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
DEBUGASSERT(handle && wndo && ops && (unsigned)minor < 256);
|
DEBUGASSERT(handle && wndo && ops && (unsigned)minor < 256);
|
||||||
@@ -101,22 +103,32 @@ FAR struct nxterm_state_s *
|
|||||||
sem_setprotocol(&priv->waitsem, SEM_PRIO_NONE);
|
sem_setprotocol(&priv->waitsem, SEM_PRIO_NONE);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Select the font */
|
/* Connect to the font cache for the configured font characteristics */
|
||||||
|
|
||||||
priv->font = nxf_getfonthandle(wndo->fontid);
|
priv->fcache = nxf_cache_connect(wndo->fontid, wndo->fcolor[0],
|
||||||
if (!priv->font)
|
wndo->wcolor[0], CONFIG_NXTERM_BPP);
|
||||||
|
if (priv->fcache == NULL)
|
||||||
{
|
{
|
||||||
gerr("ERROR: Failed to get font ID %d: %d\n", wndo->fontid, errno);
|
gerr("ERROR: Failed to connect to font cache for font ID %d: %d\n",
|
||||||
|
wndo->fontid, errno);
|
||||||
goto errout;
|
goto errout;
|
||||||
}
|
}
|
||||||
|
|
||||||
FAR const struct nx_font_s *fontset;
|
/* Get the handle of the font managed by the font cache */
|
||||||
|
|
||||||
|
hfont = nxf_cache_getfonthandle(priv->fcache);
|
||||||
|
if (hfont == NULL)
|
||||||
|
{
|
||||||
|
gerr("ERROR: Failed to get handlr for font ID %d: %d\n",
|
||||||
|
wndo->fontid, errno);
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
/* Get information about the font set being used and save this in the
|
/* Get information about the font set being used and save this in the
|
||||||
* state structure
|
* state structure
|
||||||
*/
|
*/
|
||||||
|
|
||||||
fontset = nxf_getfontset(priv->font);
|
fontset = nxf_getfontset(hfont);
|
||||||
priv->fheight = fontset->mxheight;
|
priv->fheight = fontset->mxheight;
|
||||||
priv->fwidth = fontset->mxwidth;
|
priv->fwidth = fontset->mxwidth;
|
||||||
priv->spwidth = fontset->spwidth;
|
priv->spwidth = fontset->spwidth;
|
||||||
@@ -125,10 +137,6 @@ FAR struct nxterm_state_s *
|
|||||||
|
|
||||||
priv->maxchars = CONFIG_NXTERM_MXCHARS;
|
priv->maxchars = CONFIG_NXTERM_MXCHARS;
|
||||||
|
|
||||||
/* Set up the font glyph bitmap cache */
|
|
||||||
|
|
||||||
priv->maxglyphs = CONFIG_NXTERM_CACHESIZE;
|
|
||||||
|
|
||||||
/* Set the initial display position */
|
/* Set the initial display position */
|
||||||
|
|
||||||
nxterm_home(priv);
|
nxterm_home(priv);
|
||||||
@@ -146,6 +154,7 @@ FAR struct nxterm_state_s *
|
|||||||
{
|
{
|
||||||
gerr("ERROR: Failed to register %s\n", devname);
|
gerr("ERROR: Failed to register %s\n", devname);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (NXTERM)priv;
|
return (NXTERM)priv;
|
||||||
|
|
||||||
errout:
|
errout:
|
||||||
|
|||||||
@@ -50,22 +50,6 @@
|
|||||||
|
|
||||||
#include "nxterm.h"
|
#include "nxterm.h"
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Pre-processor Definitions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Function Prototypes
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Data
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
|
||||||
* Private Functions
|
|
||||||
****************************************************************************/
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -89,7 +73,6 @@ void nxterm_unregister(NXTERM handle)
|
|||||||
{
|
{
|
||||||
FAR struct nxterm_state_s *priv;
|
FAR struct nxterm_state_s *priv;
|
||||||
char devname[NX_DEVNAME_SIZE];
|
char devname[NX_DEVNAME_SIZE];
|
||||||
int i;
|
|
||||||
|
|
||||||
DEBUGASSERT(handle);
|
DEBUGASSERT(handle);
|
||||||
|
|
||||||
@@ -101,16 +84,9 @@ void nxterm_unregister(NXTERM handle)
|
|||||||
sem_destroy(&priv->waitsem);
|
sem_destroy(&priv->waitsem);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Free all allocated glyph bitmap */
|
/* Free the font cache */
|
||||||
|
|
||||||
for (i = 0; i < CONFIG_NXTERM_CACHESIZE; i++)
|
nxf_cache_disconnect(priv->fcache);
|
||||||
{
|
|
||||||
FAR struct nxterm_glyph_s *glyph = &priv->glyph[i];
|
|
||||||
if (glyph->bitmap)
|
|
||||||
{
|
|
||||||
kmm_free(glyph->bitmap);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Unregister the driver */
|
/* Unregister the driver */
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,7 @@
|
|||||||
* Pre-processor definitions
|
* Pre-processor definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Font Definitions *********************************************************/
|
||||||
/* Select the default font. If no fonts are selected, then a compilation
|
/* Select the default font. If no fonts are selected, then a compilation
|
||||||
* error is likely down the road.
|
* error is likely down the road.
|
||||||
*/
|
*/
|
||||||
@@ -202,10 +203,16 @@
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Font Cache Definitions (**************************************************/
|
||||||
|
/* Limit to range of font cache usage count */
|
||||||
|
|
||||||
|
#define MAX_USECNT 255 /* Limit to range of a uint8_t */
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* Font Types ***************************************************************/
|
||||||
/* Font IDs */
|
/* Font IDs */
|
||||||
|
|
||||||
enum nx_fontid_e
|
enum nx_fontid_e
|
||||||
@@ -453,6 +460,23 @@ struct nx_fontpackage_s
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Font Cache ***************************************************************/
|
||||||
|
/* Opaque handle used to reference a font cache */
|
||||||
|
|
||||||
|
typedef FAR void *FCACHE;
|
||||||
|
|
||||||
|
/* Describes one cached font glyph */
|
||||||
|
|
||||||
|
struct nxfonts_glyph_s
|
||||||
|
{
|
||||||
|
uint8_t code; /* Character code */
|
||||||
|
uint8_t height; /* Height of this glyph (in rows) */
|
||||||
|
uint8_t width; /* Width of this glyph (in pixels) */
|
||||||
|
uint8_t stride; /* Width of the glyph row (in bytes) */
|
||||||
|
uint8_t usecnt; /* Use count */
|
||||||
|
FAR uint8_t *bitmap; /* Allocated bitmap memory */
|
||||||
|
};
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@@ -480,6 +504,9 @@ extern "C"
|
|||||||
* Input Parameters:
|
* Input Parameters:
|
||||||
* fontid: Identifies the font set to get
|
* fontid: Identifies the font set to get
|
||||||
*
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* One success, a non-NULL font handle is returned.
|
||||||
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
NXHANDLE nxf_getfonthandle(enum nx_fontid_e fontid);
|
NXHANDLE nxf_getfonthandle(enum nx_fontid_e fontid);
|
||||||
@@ -564,6 +591,83 @@ int nxf_convert_32bpp(FAR uint32_t *dest, uint16_t height,
|
|||||||
FAR const struct nx_fontbitmap_s *bm,
|
FAR const struct nx_fontbitmap_s *bm,
|
||||||
nxgl_mxpixel_t color);
|
nxgl_mxpixel_t color);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nxf_cache_connect
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Create a new font cache for the provided 'fontid'. If the cache
|
||||||
|
* already, then just increment a reference count return the handler for
|
||||||
|
* the existing font cache.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* fontid - Identifies the font supported by this cache
|
||||||
|
*
|
||||||
|
* Returned value:
|
||||||
|
* On success a non-NULL handle is returned that then may sequently be
|
||||||
|
* used with nxf_getglyph() to extract fonts from the font cache. NULL
|
||||||
|
* returned on any failure with the errno value set to indicate the nature
|
||||||
|
* of the error.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
FCACHE nxf_cache_connect(enum nx_fontid_e fontid,
|
||||||
|
nxgl_mxpixel_t fgcolor, nxgl_mxpixel_t bgcolor,
|
||||||
|
int bpp);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nxf_cache_disconnect
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Decrement the reference count on the font cache and, if the reference
|
||||||
|
* count goes to zero, free all resources used by the font cache. The
|
||||||
|
* font handler is invalid upon return in either case.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* fcache - A font cache handler previously returned by nxf_cache_connect();
|
||||||
|
*
|
||||||
|
* Returned value:
|
||||||
|
* None
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
void nxf_cache_disconnect(FCACHE fcache);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nxf_cache_getfonthandle
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Return the handle to the font set used by this instance of the font
|
||||||
|
* cache.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* fcache - A font cache handle previously returned by nxf_cache_connect();
|
||||||
|
*
|
||||||
|
* Returned value:
|
||||||
|
* Zero (OK) is returned if the metrics were
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* One success, a non-NULL font handle is returned.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
NXHANDLE nxf_cache_getfonthandle(FCACHE fcache);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: nxf_cache_getglyph
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the font glyph for the character code 'ch' from the font cache. If
|
||||||
|
* the glyph for that character code does not exist in the font cache, it
|
||||||
|
* be rendered.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* On success, a non-NULL pointer to the rendered glyph in the font cache
|
||||||
|
* is returned. NULL is returned on any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
FAR struct nxfonts_glyph_s *nxf_cache_getglyph(FCACHE fcache, uint8_t ch);
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -37,7 +37,7 @@
|
|||||||
|
|
||||||
ifeq ($(CONFIG_NX),y)
|
ifeq ($(CONFIG_NX),y)
|
||||||
|
|
||||||
CSRCS += nxfonts_getfont.c
|
CSRCS += nxfonts_getfont.c nxfonts_cache.c
|
||||||
CSRCS += nxfonts_convert_1bpp.c nxfonts_convert_2bpp.c
|
CSRCS += nxfonts_convert_1bpp.c nxfonts_convert_2bpp.c
|
||||||
CSRCS += nxfonts_convert_4bpp.c nxfonts_convert_8bpp.c
|
CSRCS += nxfonts_convert_4bpp.c nxfonts_convert_8bpp.c
|
||||||
CSRCS += nxfonts_convert_16bpp.c nxfonts_convert_24bpp.c
|
CSRCS += nxfonts_convert_16bpp.c nxfonts_convert_24bpp.c
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user