From ffca6badfcf76345a1b6344923fd912eb5aef6cf Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sat, 9 Mar 2019 13:13:05 -0600 Subject: [PATCH] Squashed commit of the following: graphics/nxterm: Needs to clear display initially. Otherwise, garbage from previous display may still be present from preceding NxWM window. graphics/nxterm: Back out most of the preceding NxTerm changes related to window size. apps/examples/nxterm passed the complete NxTK window size. Those changes were needed to make aps/examples/nxterm work. But NxWM passes the the size of the NxTK main sub-window. So I needed to back out the changes and then change the applications so that they passed the same value (the size of the NxTK sub-window). --- graphics/nxterm/Make.defs | 2 +- graphics/nxterm/nx_register.c | 3 +- graphics/nxterm/nxterm.h | 6 +-- graphics/nxterm/nxterm_clear.c | 75 +++++++++++++++++++++++++++++++ graphics/nxterm/nxterm_putc.c | 8 ++-- graphics/nxterm/nxterm_register.c | 7 +-- graphics/nxterm/nxterm_scroll.c | 10 ++--- graphics/nxterm/nxtk_register.c | 26 +---------- graphics/nxterm/nxtool_register.c | 23 +--------- include/nuttx/nx/nxterm.h | 7 ++- 10 files changed, 101 insertions(+), 66 deletions(-) create mode 100644 graphics/nxterm/nxterm_clear.c diff --git a/graphics/nxterm/Make.defs b/graphics/nxterm/Make.defs index 37aa7b3a5a..32629b8f0a 100644 --- a/graphics/nxterm/Make.defs +++ b/graphics/nxterm/Make.defs @@ -37,7 +37,7 @@ ifeq ($(CONFIG_NXTERM),y) CSRCS += nx_register.c nxterm_driver.c nxterm_font.c nxterm_putc.c CSRCS += nxterm_redraw.c nxterm_register.c nxterm_scroll.c -CSRCS += nxterm_vt100.c nxtk_register.c nxtool_register.c +CSRCS += nxterm_vt100.c nxtk_register.c nxtool_register.c nxterm_clear.c ifneq ($(CONFIG_DISABLE_PSEUDOFS_OPERATIONS),y) CSRCS += nxterm_unregister.c diff --git a/graphics/nxterm/nx_register.c b/graphics/nxterm/nx_register.c index 64644a63a7..460a02d219 100644 --- a/graphics/nxterm/nx_register.c +++ b/graphics/nxterm/nx_register.c @@ -184,5 +184,6 @@ static int nxterm_bitmap(FAR struct nxterm_state_s *priv, NXTERM nx_register(NXWINDOW hwnd, FAR struct nxterm_window_s *wndo, int minor) { - return nxterm_register((NXTERM)hwnd, wndo, &wndo->wsize, &g_nxops, minor); + return nxterm_register((NXTERM)hwnd, wndo, &g_nxops, minor); } + diff --git a/graphics/nxterm/nxterm.h b/graphics/nxterm/nxterm.h index dfae4563bf..d7e451e9f5 100644 --- a/graphics/nxterm/nxterm.h +++ b/graphics/nxterm/nxterm.h @@ -124,7 +124,6 @@ struct nxterm_state_s FAR const struct nxterm_operations_s *ops; /* Window operations */ FAR void *handle; /* The window handle */ FAR struct nxterm_window_s wndo; /* Describes the window and font */ - struct nxgl_size_s wsize; /* NXTK main window size */ sem_t exclsem; /* Forces mutually exclusive access */ #ifdef CONFIG_DEBUG_FEATURES pid_t holder; /* Deadlock avoidance */ @@ -203,8 +202,8 @@ int nxterm_sempost(FAR struct nxterm_state_s *priv); /* Common device registration/un-registration */ FAR struct nxterm_state_s *nxterm_register(NXTERM handle, - FAR struct nxterm_window_s *wndo, FAR struct nxgl_size_s *wsize, - FAR const struct nxterm_operations_s *ops, int minor); + FAR struct nxterm_window_s *wndo, FAR const struct nxterm_operations_s *ops, + int minor); #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS void nxterm_unregister(FAR struct nxterm_state_s *priv); #endif @@ -223,6 +222,7 @@ enum nxterm_vt100state_e nxterm_vt100(FAR struct nxterm_state_s *priv, char ch); /* Generic text display helpers */ void nxterm_home(FAR struct nxterm_state_s *priv); +void nxterm_clear(FAR struct nxterm_state_s *priv); void nxterm_newline(FAR struct nxterm_state_s *priv); FAR const struct nxterm_bitmap_s *nxterm_addchar(FAR struct nxterm_state_s *priv, uint8_t ch); diff --git a/graphics/nxterm/nxterm_clear.c b/graphics/nxterm/nxterm_clear.c new file mode 100644 index 0000000000..d1a147231e --- /dev/null +++ b/graphics/nxterm/nxterm_clear.c @@ -0,0 +1,75 @@ +/**************************************************************************** + * nuttx/graphics/nxterm/nxterm_clear.c + * + * Copyright (C) 2019 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * 3. Neither the name NuttX nor the names of its contributors may be + * used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS + * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + ****************************************************************************/ + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include + +#include + +#include "nxterm.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxterm_clear + * + * Description: + * Clear the display. + * + ****************************************************************************/ + +void nxterm_clear(FAR struct nxterm_state_s *priv) +{ + struct nxgl_rect_s rect; + int ret; + + rect.pt1.x = 0; + rect.pt1.y = 0; + rect.pt2.x = priv->wndo.wsize.w - 1; + rect.pt2.y = priv->wndo.wsize.h - 1; + + ret = priv->ops->fill(priv, &rect, priv->wndo.wcolor); + if (ret < 0) + { + gerr("ERROR: Fill failed: %d\n", errno); + } +} diff --git a/graphics/nxterm/nxterm_putc.c b/graphics/nxterm/nxterm_putc.c index f795363171..418eb8582a 100644 --- a/graphics/nxterm/nxterm_putc.c +++ b/graphics/nxterm/nxterm_putc.c @@ -81,7 +81,7 @@ void nxterm_putc(FAR struct nxterm_state_s *priv, uint8_t ch) /* Will another character fit on this line? */ - if (priv->fpos.x + priv->fwidth > priv->wsize.w) + if (priv->fpos.x + priv->fwidth > priv->wndo.wsize.w) { #ifndef CONFIG_NXTERM_NOWRAP /* No.. move to the next line */ @@ -117,7 +117,7 @@ void nxterm_putc(FAR struct nxterm_state_s *priv, uint8_t ch) /* Check if we need to scroll up */ lineheight = (priv->fheight + CONFIG_NXTERM_LINESEPARATION); - while (priv->fpos.y >= priv->wsize.h - lineheight) + while (priv->fpos.y >= priv->wndo.wsize.h - lineheight) { nxterm_scroll(priv, lineheight); } @@ -147,7 +147,7 @@ void nxterm_showcursor(FAR struct nxterm_state_s *priv) /* Will another character fit on this line? */ - if (priv->fpos.x + priv->fwidth > priv->wsize.w) + if (priv->fpos.x + priv->fwidth > priv->wndo.wsize.w) { #ifndef CONFIG_NXTERM_NOWRAP /* No.. move to the next line */ @@ -161,7 +161,7 @@ void nxterm_showcursor(FAR struct nxterm_state_s *priv) /* Check if we need to scroll up */ lineheight = (priv->fheight + CONFIG_NXTERM_LINESEPARATION); - while (priv->fpos.y >= priv->wsize.h - lineheight) + while (priv->fpos.y >= priv->wndo.wsize.h - lineheight) { nxterm_scroll(priv, lineheight); } diff --git a/graphics/nxterm/nxterm_register.c b/graphics/nxterm/nxterm_register.c index 666e1eaa6a..ed15a3906f 100644 --- a/graphics/nxterm/nxterm_register.c +++ b/graphics/nxterm/nxterm_register.c @@ -63,7 +63,6 @@ FAR struct nxterm_state_s * nxterm_register(NXTERM handle, FAR struct nxterm_window_s *wndo, - FAR struct nxgl_size_s *wsize, FAR const struct nxterm_operations_s *ops, int minor) { FAR struct nxterm_state_s *priv; @@ -88,9 +87,7 @@ FAR struct nxterm_state_s * priv->ops = ops; priv->handle = handle; priv->minor = minor; - memcpy(&priv->wndo, wndo, sizeof(struct nxterm_window_s)); - memcpy(&priv->wsize, wsize, sizeof(struct nxgl_size_s)); nxsem_init(&priv->exclsem, 0, 1); #ifdef CONFIG_DEBUG_FEATURES @@ -141,6 +138,10 @@ FAR struct nxterm_state_s * priv->maxchars = CONFIG_NXTERM_MXCHARS; + /* Clear the display */ + + nxterm_clear(priv); + /* Set the initial display position */ nxterm_home(priv); diff --git a/graphics/nxterm/nxterm_scroll.c b/graphics/nxterm/nxterm_scroll.c index c1d3e62d1a..56cb25a8d7 100644 --- a/graphics/nxterm/nxterm_scroll.c +++ b/graphics/nxterm/nxterm_scroll.c @@ -85,7 +85,7 @@ static inline void nxterm_movedisplay(FAR struct nxterm_state_s *priv, */ rect.pt1.x = 0; - rect.pt2.x = priv->wsize.w - 1; + rect.pt2.x = priv->wndo.wsize.w - 1; for (row = CONFIG_NXTERM_LINESEPARATION; row < bottom; row += scrollheight) { @@ -118,7 +118,7 @@ static inline void nxterm_movedisplay(FAR struct nxterm_state_s *priv, /* Finally, clear the vacated part of the display */ rect.pt1.y = bottom; - rect.pt2.y = priv->wsize.h - 1; + rect.pt2.y = priv->wndo.wsize.h - 1; ret = priv->ops->fill(priv, &rect, priv->wndo.wcolor); if (ret < 0) @@ -146,8 +146,8 @@ static inline void nxterm_movedisplay(FAR struct nxterm_state_s *priv, rect.pt1.x = 0; rect.pt1.y = scrollheight; - rect.pt2.x = priv->wsize.w - 1; - rect.pt2.y = priv->wsize.h - 1; + rect.pt2.x = priv->wndo.wsize.w - 1; + rect.pt2.y = priv->wndo.wsize.h - 1; /* The offset that determines how far to move the source rectangle */ @@ -164,7 +164,7 @@ static inline void nxterm_movedisplay(FAR struct nxterm_state_s *priv, /* Finally, clear the vacated bottom part of the display */ - rect.pt1.y = priv->wsize.h - scrollheight; + rect.pt1.y = priv->wndo.wsize.h - scrollheight; ret = priv->ops->fill(priv, &rect, priv->wndo.wcolor); if (ret < 0) diff --git a/graphics/nxterm/nxtk_register.c b/graphics/nxterm/nxtk_register.c index 897e0c2065..d593df45c2 100644 --- a/graphics/nxterm/nxtk_register.c +++ b/graphics/nxterm/nxtk_register.c @@ -160,22 +160,6 @@ static int nxtkcon_bitmap(FAR struct nxterm_state_s *priv, return nxtk_bitmapwindow((NXTKWINDOW)priv->handle, dest, src, origin, stride); } -/**************************************************************************** - * Name: nxterm_tbheight - * - * Description: - * Get the current height of the toolbar. - * - ****************************************************************************/ - -static nxgl_coord_t nxterm_tbheight(NXTKWINDOW hfwnd) -{ - FAR struct nxgl_rect_s bounds; - - (void)nxtk_toolbarbounds(hfwnd, &bounds); - return bounds.pt2.y - bounds.pt1.y + 1; -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -201,13 +185,5 @@ static nxgl_coord_t nxterm_tbheight(NXTKWINDOW hfwnd) NXTERM nxtk_register(NXTKWINDOW hfwnd, FAR struct nxterm_window_s *wndo, int minor) { - struct nxgl_size_s wsize; - - /* REVISIT: What if the window or toolbar size changes? */ - - wsize.w = wndo->wsize.w - 2 * CONFIG_NXTK_BORDERWIDTH; - wsize.h = wndo->wsize.h - nxterm_tbheight(hfwnd) - - 2 * CONFIG_NXTK_BORDERWIDTH; - - return nxterm_register((NXTERM)hfwnd, wndo, &wsize, &g_nxtkops, minor); + return nxterm_register((NXTERM)hfwnd, wndo, &g_nxtkops, minor); } diff --git a/graphics/nxterm/nxtool_register.c b/graphics/nxterm/nxtool_register.c index 9217ff5dbd..04849692f3 100644 --- a/graphics/nxterm/nxtool_register.c +++ b/graphics/nxterm/nxtool_register.c @@ -160,24 +160,6 @@ static int nxtool_bitmap(FAR struct nxterm_state_s *priv, return nxtk_bitmaptoolbar((NXTKWINDOW)priv->handle, dest, src, origin, stride); } -/**************************************************************************** - * Name: nxterm_toolbar_size - * - * Description: - * Get the current size of the toolbar. - * - ****************************************************************************/ - -static void nxterm_toolbar_size(NXTKWINDOW hfwnd, - FAR struct nxgl_size_s *size) -{ - FAR struct nxgl_rect_s bounds; - - (void)nxtk_toolbarbounds(hfwnd, &bounds); - size->w = bounds.pt2.x - bounds.pt1.x + 1; - size->h = bounds.pt2.y - bounds.pt1.y + 1; -} - /**************************************************************************** * Public Functions ****************************************************************************/ @@ -204,9 +186,6 @@ static void nxterm_toolbar_size(NXTKWINDOW hfwnd, NXTERM nxtool_register(NXTKWINDOW hfwnd, FAR struct nxterm_window_s *wndo, int minor) { - FAR struct nxgl_size_s tbsize; - - nxterm_toolbar_size(hfwnd, &tbsize); - return nxterm_register((NXTERM)hfwnd, wndo, &tbsize, &g_nxtoolops, minor); + return nxterm_register((NXTERM)hfwnd, wndo, &g_nxtoolops, minor); } diff --git a/include/nuttx/nx/nxterm.h b/include/nuttx/nx/nxterm.h index c81e7041a0..50cb39bad9 100644 --- a/include/nuttx/nx/nxterm.h +++ b/include/nuttx/nx/nxterm.h @@ -200,13 +200,16 @@ typedef FAR void *NXTERM; -/* This structure describes the window and font characteristics */ +/* This structure describes the window and font characteristics. + * For raw windows, wsize if the full size of the window. For + * NxTK windows, wsize is the size of the sub-window. + */ struct nxterm_window_s { nxgl_mxpixel_t wcolor[CONFIG_NX_NPLANES]; /* Window background color */ nxgl_mxpixel_t fcolor[CONFIG_NX_NPLANES]; /* Font color */ - struct nxgl_size_s wsize; /* Window size */ + struct nxgl_size_s wsize; /* Window/Sub-window size */ int fontid; /* The ID of the font to use */ };