From 622a6cc576f1e5b97abcb78441ed04674217bfe6 Mon Sep 17 00:00:00 2001 From: patacongo Date: Wed, 20 Jul 2011 02:13:08 +0000 Subject: Use a handle instead of an ID in each font lookup; this saves doing the font set lookup each time git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3802 42af7a65-404d-4744-a932-0658087f49c3 --- apps/examples/nx/nx_internal.h | 7 ++++++- apps/examples/nx/nx_kbdin.c | 2 +- apps/examples/nx/nx_main.c | 16 +++++++++++++++- apps/examples/nxhello/nxhello.h | 4 +++- apps/examples/nxhello/nxhello_bkgd.c | 6 +++--- apps/examples/nxhello/nxhello_main.c | 12 ++++++++++++ apps/examples/nxtext/nxtext_bkgd.c | 2 +- apps/examples/nxtext/nxtext_internal.h | 5 +++++ apps/examples/nxtext/nxtext_main.c | 15 +++++++++++++++ apps/examples/nxtext/nxtext_popup.c | 2 +- apps/examples/nxtext/nxtext_putc.c | 4 ++-- 11 files changed, 64 insertions(+), 11 deletions(-) (limited to 'apps/examples') diff --git a/apps/examples/nx/nx_internal.h b/apps/examples/nx/nx_internal.h index 96e84a958..897c09722 100644 --- a/apps/examples/nx/nx_internal.h +++ b/apps/examples/nx/nx_internal.h @@ -196,6 +196,7 @@ enum exitcode_e NXEXIT_LCDINITIALIZE, NXEXIT_LCDGETDEV, NXEXIT_NXOPEN, + NXEXIT_FONTOPEN, NXEXIT_NXOPENTOOLBAR, NXEXIT_NXCONNECT, NXEXIT_NXSETBGCOLOR, @@ -251,7 +252,7 @@ struct nxeg_state_s * Public Variables ****************************************************************************/ -/* The connecton handler */ +/* The connecton handle */ extern NXHANDLE g_hnx; @@ -262,6 +263,10 @@ extern const struct nx_callback_s g_nxcb; extern const struct nx_callback_s g_tbcb; #endif +/* The font handle */ + +extern NXHANDLE g_fonthandle; + /* The screen resolution */ extern nxgl_coord_t g_xres; diff --git a/apps/examples/nx/nx_kbdin.c b/apps/examples/nx/nx_kbdin.c index 66d54b046..b2a40d352 100644 --- a/apps/examples/nx/nx_kbdin.c +++ b/apps/examples/nx/nx_kbdin.c @@ -323,7 +323,7 @@ nxeg_getglyph(FAR struct nxeg_state_s *st, uint8_t ch) { /* No, it is not cached... Does the code map to a glyph? */ - bm = nxf_getbitmap(ch, NXFONT_DEFAULT); + bm = nxf_getbitmap(g_fonthandle, ch); if (!bm) { /* No, there is no glyph for this code. Use space */ diff --git a/apps/examples/nx/nx_main.c b/apps/examples/nx/nx_main.c index 72e8fe2ca..6d85d0fb7 100644 --- a/apps/examples/nx/nx_main.c +++ b/apps/examples/nx/nx_main.c @@ -102,6 +102,10 @@ static const uint8_t g_kbdmsg1[] = "NuttX is cool!"; static const uint8_t g_kbdmsg2[] = "NuttX is fun!"; #endif +/* The font handle */ + +NXHANDLE g_fonthandle; + /**************************************************************************** * Public Data ****************************************************************************/ @@ -179,7 +183,7 @@ static void nxeg_initstate(FAR struct nxeg_state_s *st, int wnum, */ #ifdef CONFIG_NX_KBD - fontset = nxf_getfontset(NXFONT_DEFAULT); + fontset = nxf_getfontset(g_fonthandle); st->nchars = 0; st->nglyphs = 0; st->height = fontset->mxheight; @@ -637,6 +641,16 @@ int user_start(int argc, char *argv[]) goto errout; } + /* Get the default font handle */ + + g_fonthandle = nxf_getfonthandle(NXFONT_DEFAULT); + if (!g_fonthandle) + { + message("user_start: Failed to get font handle: %d\n", errno); + g_exitcode = NXEXIT_FONTOPEN; + goto errout; + } + /* Set the background to the configured background color */ message("user_start: Set background color=%d\n", CONFIG_EXAMPLES_NX_BGCOLOR); diff --git a/apps/examples/nxhello/nxhello.h b/apps/examples/nxhello/nxhello.h index d5d5c724b..b7343a054 100644 --- a/apps/examples/nxhello/nxhello.h +++ b/apps/examples/nxhello/nxhello.h @@ -120,6 +120,7 @@ enum exitcode_e NXEXIT_LCDINITIALIZE, NXEXIT_LCDGETDEV, NXEXIT_NXOPEN, + NXEXIT_FONTOPEN, NXEXIT_NXREQUESTBKGD, NXEXIT_NXSETBGCOLOR }; @@ -147,10 +148,11 @@ struct nxhello_bitmap_s struct nxhello_data_s { - /* The NX handle */ + /* The NX handles */ NXHANDLE hnx; NXHANDLE hbkgd; + NXHANDLE hfont; /* The screen resolution */ diff --git a/apps/examples/nxhello/nxhello_bkgd.c b/apps/examples/nxhello/nxhello_bkgd.c index 9ec3e5141..f3c6b8add 100644 --- a/apps/examples/nxhello/nxhello_bkgd.c +++ b/apps/examples/nxhello/nxhello_bkgd.c @@ -228,7 +228,7 @@ static void nxhello_center(FAR struct nxgl_point_s *pos, { /* Get the font bitmap for this character */ - fbm = nxf_getbitmap(*ptr, NXFONT_DEFAULT); + fbm = nxf_getbitmap(g_nxhello.hfont, *ptr); if (fbm) { /* Add the font size */ @@ -353,7 +353,7 @@ void nxhello_hello(NXWINDOW hwnd) /* Get information about the font we are going to use */ - fontset = nxf_getfontset(NXFONT_DEFAULT); + fontset = nxf_getfontset(g_nxhello.hfont); /* Allocate a bit of memory to hold the largest rendered font */ @@ -377,7 +377,7 @@ void nxhello_hello(NXWINDOW hwnd) { /* Get the bitmap font for this ASCII code */ - fbm = nxf_getbitmap(*ptr, NXFONT_DEFAULT); + fbm = nxf_getbitmap(g_nxhello.hfont, *ptr); if (fbm) { uint8_t fheight; /* Height of this glyph (in rows) */ diff --git a/apps/examples/nxhello/nxhello_main.c b/apps/examples/nxhello/nxhello_main.c index 02b2f17a2..98b16bb1d 100644 --- a/apps/examples/nxhello/nxhello_main.c +++ b/apps/examples/nxhello/nxhello_main.c @@ -61,6 +61,7 @@ #include #include #include +#include #include "nxhello.h" @@ -101,6 +102,7 @@ struct nxhello_data_s g_nxhello = { NULL, /* hnx */ NULL, /* hbkgd */ + NULL, /* hfont */ 0, /* xres */ 0, /* yres */ false, /* havpos */ @@ -228,6 +230,16 @@ int MAIN_NAME(int argc, char *argv[]) goto errout; } + /* Get the default font handle */ + + g_nxhello.hfont = nxf_getfonthandle(NXFONT_DEFAULT); + if (!g_nxhello.hfont) + { + message("user_start: Failed to get font handle: %d\n", errno); + g_nxhello.code = NXEXIT_FONTOPEN; + goto errout; + } + /* Set the background to the configured background color */ message(MAIN_NAME_STRING ": Set background color=%d\n", diff --git a/apps/examples/nxtext/nxtext_bkgd.c b/apps/examples/nxtext/nxtext_bkgd.c index e711c84bb..37894e20c 100644 --- a/apps/examples/nxtext/nxtext_bkgd.c +++ b/apps/examples/nxtext/nxtext_bkgd.c @@ -402,7 +402,7 @@ FAR struct nxtext_state_s *nxbg_getstate(void) * state structure */ - fontset = nxf_getfontset(NXFONT_DEFAULT); + fontset = nxf_getfontset(g_fonthandle); g_bgstate.fheight = fontset->mxheight; g_bgstate.fwidth = fontset->mxwidth; g_bgstate.spwidth = fontset->spwidth; diff --git a/apps/examples/nxtext/nxtext_internal.h b/apps/examples/nxtext/nxtext_internal.h index 16f8bb08a..eb7543329 100644 --- a/apps/examples/nxtext/nxtext_internal.h +++ b/apps/examples/nxtext/nxtext_internal.h @@ -191,6 +191,7 @@ enum exitcode_e NXEXIT_LCDINITIALIZE, NXEXIT_LCDGETDEV, NXEXIT_NXOPEN, + NXEXIT_FONTOPEN, NXEXIT_NXREQUESTBKGD, NXEXIT_NXCONNECT, NXEXIT_NXSETBGCOLOR, @@ -262,6 +263,10 @@ extern NXHANDLE g_hnx; extern NXHANDLE g_bgwnd; +/* The font handle */ + +extern NXHANDLE g_fonthandle; + /* NX callback vtables */ extern const struct nx_callback_s g_bgcb; diff --git a/apps/examples/nxtext/nxtext_main.c b/apps/examples/nxtext/nxtext_main.c index 6a53f9d2c..a9d9207e6 100644 --- a/apps/examples/nxtext/nxtext_main.c +++ b/apps/examples/nxtext/nxtext_main.c @@ -61,6 +61,7 @@ #include #include #include +#include #include "nxtext_internal.h" @@ -134,6 +135,10 @@ static const char *g_bgmsg[BGMSG_LINES] = NXHANDLE g_hnx = NULL; +/* The font handle */ + +NXHANDLE g_fonthandle = NULL; + /* The screen resolution */ nxgl_coord_t g_xres; @@ -366,6 +371,16 @@ int user_start(int argc, char *argv[]) goto errout; } + /* Get the default font handle */ + + g_fonthandle = nxf_getfonthandle(NXFONT_DEFAULT); + if (!g_fonthandle) + { + message("user_start: Failed to get font handle: %d\n", errno); + g_exitcode = NXEXIT_FONTOPEN; + goto errout; + } + /* Set the background to the configured background color */ message("user_start: Set background color=%d\n", CONFIG_EXAMPLES_NXTEXT_BGCOLOR); diff --git a/apps/examples/nxtext/nxtext_popup.c b/apps/examples/nxtext/nxtext_popup.c index bf9fbae19..8cc72a89e 100644 --- a/apps/examples/nxtext/nxtext_popup.c +++ b/apps/examples/nxtext/nxtext_popup.c @@ -304,7 +304,7 @@ static inline void nxpu_initstate(void) */ #ifdef CONFIG_NX_KBD - fontset = nxf_getfontset(NXFONT_DEFAULT); + fontset = nxf_getfontset(g_fonthandle); g_pustate.fheight = fontset->mxheight; g_pustate.fwidth = fontset->mxwidth; g_pustate.spwidth = fontset->spwidth; diff --git a/apps/examples/nxtext/nxtext_putc.c b/apps/examples/nxtext/nxtext_putc.c index 87da2ad6e..b4e31bb73 100644 --- a/apps/examples/nxtext/nxtext_putc.c +++ b/apps/examples/nxtext/nxtext_putc.c @@ -332,7 +332,7 @@ static int nxtext_fontsize(uint8_t ch, FAR struct nxgl_size_s *size) /* No, it is not cached... Does the code map to a font? */ - fbm = nxf_getbitmap(ch, NXFONT_DEFAULT); + fbm = nxf_getbitmap(g_fonthandle, ch); if (fbm) { /* Yes.. return the font size */ @@ -362,7 +362,7 @@ nxtext_getglyph(FAR struct nxtext_state_s *st, uint8_t ch) { /* No, it is not cached... Does the code map to a font? */ - fbm = nxf_getbitmap(ch, NXFONT_DEFAULT); + fbm = nxf_getbitmap(g_fonthandle, ch); if (fbm) { /* Yes.. render the glyph */ -- cgit v1.2.3