From 79b83f0c0576105ca743ec6883c64a74d662f61a Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 7 Apr 2019 13:25:20 -0600 Subject: [PATCH] graphics: Extend the definition of the cursor image structure. --- graphics/nxbe/nxbe.h | 13 +++- graphics/nxbe/nxbe_cursor.c | 14 ++-- include/nuttx/nx/nxcursor.h | 12 +++- include/nuttx/nx/nxglib.h | 81 ++-------------------- include/nuttx/nx/nxmu.h | 2 +- include/nuttx/nx/nxtypes.h | 131 +++++++++++++++++++++++++++++++++++ include/nuttx/video/cursor.h | 42 +++++++++-- libs/libnx/nxmu/nx_cursor.c | 16 ++++- 8 files changed, 214 insertions(+), 97 deletions(-) create mode 100644 include/nuttx/nx/nxtypes.h diff --git a/graphics/nxbe/nxbe.h b/graphics/nxbe/nxbe.h index 8e5476be09..781b0d49d0 100644 --- a/graphics/nxbe/nxbe.h +++ b/graphics/nxbe/nxbe.h @@ -199,6 +199,7 @@ struct nxbe_state_s struct cursor_pos_s pos; /* The current cursor position */ #ifdef CONFIG_NX_SWCURSOR FAR struct cursor_image_s image; /* Cursor image */ + FAR nxgl_mxpixel_t *bkgd; /* Cursor background */ #endif } cursor; #endif @@ -291,11 +292,17 @@ void nxbe_cursor_enable(FAR struct nxbe_state_s *be, bool enable); * Description: * Set the cursor image * + * The image is provided a a 2-bits-per-pixel image. The two bit incoding + * is as followings: + * + * 00 - The transparent background + * 01 - Color1: The main color of the cursor + * 10 - Color2: The color of any border + * 11 - Color3: A blend color for better imaging (fake anti-aliasing). + * * Input Parameters: * be - The back-end state structure instance - * image - Describes the cursor image in the expected format. For a - * software cursor, this is the format used with the display. The - * format may be different if a hardware cursor is used. + * image - Describes the cursor image in the expected format. * * Returned Value: * None diff --git a/graphics/nxbe/nxbe_cursor.c b/graphics/nxbe/nxbe_cursor.c index 0b201c845b..a5a4e35452 100644 --- a/graphics/nxbe/nxbe_cursor.c +++ b/graphics/nxbe/nxbe_cursor.c @@ -72,13 +72,19 @@ void nxbe_cursor_enable(FAR struct nxbe_state_s *be, bool enable) * Name: nxbe_cursor_setimage * * Description: - * Set the cursor image + * Set the cursor image. + * + * The image is provided a a 2-bits-per-pixel image. The two bit incoding + * is as followings: + * + * 00 - The transparent background + * 01 - Color1: The main color of the cursor + * 10 - Color2: The color of any border + * 11 - Color3: A blend color for better imaging (fake anti-aliasing). * * Input Parameters: * be - The back-end state structure instance - * image - Describes the cursor image in the expected format. For a - * software cursor, this is the format used with the display. The - * format may be different if a hardware cursor is used. + * image - Describes the cursor image in the expected format. * * Returned Value: * None diff --git a/include/nuttx/nx/nxcursor.h b/include/nuttx/nx/nxcursor.h index 0b6e083b11..f3ff842bb9 100644 --- a/include/nuttx/nx/nxcursor.h +++ b/include/nuttx/nx/nxcursor.h @@ -86,15 +86,21 @@ int nxcursor_enable(NXHANDLE hnd, bool enable); * Description: * Set the cursor image. * + * The image is provided a a 2-bits-per-pixel image. The two bit incoding + * is as followings: + * + * 00 - The transparent background + * 01 - Color1: The main color of the cursor + * 10 - Color2: The color of any border + * 11 - Color3: A blend color for better imaging (fake anti-aliasing). + * * NOTE: The NX logic will reference the user image buffer repeatedly. * That image buffer must persist for as long as the NX server connection * persists. * * Input Parameters: * hnd - The server handle returned by nx_connect() - * image - Describes the cursor image in the expected format. For a - * software cursor, this is the format used with the display. The - * format may be different if a hardware cursor is used. + * image - Describes the cursor image in the expected format. * * Returned Value: * OK on success; ERROR on failure with errno set appropriately diff --git a/include/nuttx/nx/nxglib.h b/include/nuttx/nx/nxglib.h index b5c796621d..feb9b20e30 100644 --- a/include/nuttx/nx/nxglib.h +++ b/include/nuttx/nx/nxglib.h @@ -52,6 +52,8 @@ # include #endif +#include + /**************************************************************************** * Pre-processor definitions ****************************************************************************/ @@ -98,84 +100,11 @@ * Public Types ****************************************************************************/ -/* Pixels *******************************************************************/ - -/* The size of graphics solutions can be reduced by disabling support for - * specific resolutions. One thing we can do, for example, is to select - * the smallest common pixel representation: +/* NXGLIB types are defined in nxtype.h. This is done in order to avoid + * circular include files dependencies by files included by this header + * file that also require NXGLIB types. */ -#if !defined(CONFIG_NX_DISABLE_32BPP) || !defined(CONFIG_NX_DISABLE_24BPP) -typedef uint32_t nxgl_mxpixel_t; -#elif !defined(CONFIG_NX_DISABLE_16BPP) -typedef uint16_t nxgl_mxpixel_t; -#else -typedef uint8_t nxgl_mxpixel_t; -#endif - -/* Graphics structures ******************************************************/ - -/* A given coordinate is limited to the screen height an width. If either - * of those values exceed 32,767 pixels, then the following will have to need - * to change: - */ - -typedef int16_t nxgl_coord_t; - -/* Describes a point on the display */ - -struct nxgl_point_s -{ - nxgl_coord_t x; /* X position, range: 0 to screen width - 1 */ - nxgl_coord_t y; /* Y position, range: 0 to screen height - 1 */ -}; - -/* Describes the size of a rectangular region */ - -struct nxgl_size_s -{ - nxgl_coord_t w; /* Width in pixels */ - nxgl_coord_t h; /* Height in rows */ -}; - -/* Describes a positioned rectangle on the display */ - -struct nxgl_rect_s -{ - struct nxgl_point_s pt1; /* Upper, left-hand corner */ - struct nxgl_point_s pt2; /* Lower, right-hand corner */ -}; - -/* Describes a vector starting at pt1 and extending throug pt2 */ - -struct nxgl_vector_s -{ - struct nxgl_point_s pt1; /* Start position */ - struct nxgl_point_s pt2; /* End position */ -}; - -/* Describes a run, i.e., a horizontal line. Note that the start/end positions - * have fractional precision. This is necessary for good joining of trapezoids - * when a more complex shape is decomposed into trapezoids - */ - -struct nxgl_run_s -{ - b16_t x1; /* Left X position, range: 0 to x2 */ - b16_t x2; /* Right X position, range: x1 to screen width - 1 */ - nxgl_coord_t y; /* Top Y position, range: 0 to screen height - 1 */ -}; - -/* Describes a horizontal trapezoid on the display in terms the run at the - * top of the trapezoid and the run at the bottom - */ - -struct nxgl_trapezoid_s -{ - struct nxgl_run_s top; /* Top run */ - struct nxgl_run_s bot; /* bottom run */ -}; - /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/include/nuttx/nx/nxmu.h b/include/nuttx/nx/nxmu.h index bb768b54b5..b4bfff0668 100644 --- a/include/nuttx/nx/nxmu.h +++ b/include/nuttx/nx/nxmu.h @@ -313,7 +313,7 @@ struct nxsvrmsg_curenable_s struct nxsvrmsg_curimage_s { uint32_t msgid; /* NX_SVRMSG_CURSOR_IMAGE */ - FAR struct cursor_image_s image /* True: show the cursor, false: hide the cursor */ + FAR struct cursor_image_s image /* Describes the cursor image */ }; #endif diff --git a/include/nuttx/nx/nxtypes.h b/include/nuttx/nx/nxtypes.h new file mode 100644 index 0000000000..86a63e82a6 --- /dev/null +++ b/include/nuttx/nx/nxtypes.h @@ -0,0 +1,131 @@ +/**************************************************************************** + * include/nuttx/nx/nxtypes.h + * + * Copyright (C) 2008-2011, 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. + * + ****************************************************************************/ + +#ifndef __INCLUDE_NUTTX_NX_TYPES_H +#define __INCLUDE_NUTTX_NX_TYPES_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include + +#include +#include +#include + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* Pixels *******************************************************************/ + +/* The size of graphics solutions can be reduced by disabling support for + * specific resolutions. One thing we can do, for example, is to select + * the smallest common pixel representation: + */ + +#if !defined(CONFIG_NX_DISABLE_32BPP) || !defined(CONFIG_NX_DISABLE_24BPP) +typedef uint32_t nxgl_mxpixel_t; +#elif !defined(CONFIG_NX_DISABLE_16BPP) +typedef uint16_t nxgl_mxpixel_t; +#else +typedef uint8_t nxgl_mxpixel_t; +#endif + +/* Graphics structures ******************************************************/ + +/* A given coordinate is limited to the screen height an width. If either + * of those values exceed 32,767 pixels, then the following will have to need + * to change: + */ + +typedef int16_t nxgl_coord_t; + +/* Describes a point on the display */ + +struct nxgl_point_s +{ + nxgl_coord_t x; /* X position, range: 0 to screen width - 1 */ + nxgl_coord_t y; /* Y position, range: 0 to screen height - 1 */ +}; + +/* Describes the size of a rectangular region */ + +struct nxgl_size_s +{ + nxgl_coord_t w; /* Width in pixels */ + nxgl_coord_t h; /* Height in rows */ +}; + +/* Describes a positioned rectangle on the display */ + +struct nxgl_rect_s +{ + struct nxgl_point_s pt1; /* Upper, left-hand corner */ + struct nxgl_point_s pt2; /* Lower, right-hand corner */ +}; + +/* Describes a vector starting at pt1 and extending throug pt2 */ + +struct nxgl_vector_s +{ + struct nxgl_point_s pt1; /* Start position */ + struct nxgl_point_s pt2; /* End position */ +}; + +/* Describes a run, i.e., a horizontal line. Note that the start/end positions + * have fractional precision. This is necessary for good joining of trapezoids + * when a more complex shape is decomposed into trapezoids + */ + +struct nxgl_run_s +{ + b16_t x1; /* Left X position, range: 0 to x2 */ + b16_t x2; /* Right X position, range: x1 to screen width - 1 */ + nxgl_coord_t y; /* Top Y position, range: 0 to screen height - 1 */ +}; + +/* Describes a horizontal trapezoid on the display in terms the run at the + * top of the trapezoid and the run at the bottom + */ + +struct nxgl_trapezoid_s +{ + struct nxgl_run_s top; /* Top run */ + struct nxgl_run_s bot; /* bottom run */ +}; + +#endif /* __INCLUDE_NUTTX_NX_TYPES_H */ diff --git a/include/nuttx/video/cursor.h b/include/nuttx/video/cursor.h index 22359ea90f..a2f04d7c4f 100644 --- a/include/nuttx/video/cursor.h +++ b/include/nuttx/video/cursor.h @@ -46,6 +46,12 @@ #include #include +#ifdef CONFIG_NX +# include +#else +# include +#endif + /**************************************************************************** * Pre-processor definitions ****************************************************************************/ @@ -54,25 +60,46 @@ * Public Types ****************************************************************************/ -/* If any dimension of the display exceeds 65,536 pixels, then the following - * type will need to change. This should match the types of fb_coord_t and - * nxgl_coord_t. - */ +#ifdef CONFIG_NX +/* If NX is defined, make types agree with NX */ -typedef uint16_t cursor_coord_t; +typedef nxgl_coord_t cursor_coord_t; +typedef nxgl_mxpixel_t cursor_color_t[CONFIG_NX_NPLANES]; + +#else +/* Otherwise use framebuffer and worst case types */ + +typedef fb_coord_t cursor_coord_t; +typedef uint32_t cursor_color_t; + +#endif /* For cursor controllers that support custem cursor images, this structure * is used to provide the cursor image. + * + * The image is provided a a 2-bits-per-pixel image. The two bit incoding + * is as followings: + * + * 00 - The transparent background + * 01 - Color1: The main color of the cursor + * 10 - Color2: The color of any border + * 11 - Color3: A blend color for better imaging (fake anti-aliasing). */ struct cursor_image_s { cursor_coord_t width; /* Width of the cursor image in pixels */ cursor_coord_t height; /* Height of the cursor image in pixels */ + cursor_coord_t stride; /* Width of the image in bytes */ + cursor_color_t color1; /* Color1 is main color of the cursor */ + cursor_color_t color2; /* Color2 is color of any border */ + cursor_color_t color3; /* Color3 is the blended color */ FAR const uint8_t *image; /* Pointer to bitmap image data */ }; -/* The following structure defines the cursor position */ +/* The following structure defines the cursor position. If CONFIG_NX=y, + * this structure is equivalent to struct nxgl_pos_s. + */ struct cursor_pos_s { @@ -81,7 +108,8 @@ struct cursor_pos_s }; /* If the hardware supports setting the cursor size, then this structure - * is used to provide the cursor size. + * is used to provide the cursor size. If CONFIG_NX=y, this structure is + * equivalent to struct nxgl_size_s. */ struct cursor_size_s diff --git a/libs/libnx/nxmu/nx_cursor.c b/libs/libnx/nxmu/nx_cursor.c index 615c1ab617..40a0f742da 100644 --- a/libs/libnx/nxmu/nx_cursor.c +++ b/libs/libnx/nxmu/nx_cursor.c @@ -94,15 +94,21 @@ int nxcursor_enable(NXHANDLE hnd, bool enable) * Description: * Set the cursor image. * + * The image is provided a a 2-bits-per-pixel image. The two bit incoding + * is as followings: + * + * 00 - The transparent background + * 01 - Color1: The main color of the cursor + * 10 - Color2: The color of any border + * 11 - Color3: A blend color for better imaging (fake anti-aliasing). + * * NOTE: The NX logic will reference the user image buffer repeatedly. * That image buffer must persist for as long as the NX server connection * persists. * * Input Parameters: * hnd - The server handle returned by nx_connect() - * image - Describes the cursor image in the expected format. For a - * software cursor, this is the format used with the display. The - * format may be different if a hardware cursor is used. + * image - Describes the cursor image in the expected format. * * Returned Value: * OK on success; ERROR on failure with errno set appropriately @@ -123,6 +129,10 @@ int nxcursor_setimage(NXHANDLE hnd, FAR struct cursor_image_s *image) outmsg.msgid = NX_SVRMSG_CURSOR_IMAGE; outmsg.image.width = image->width; outmsg.image.height = image->height; + outmsg.image.stride = image->stride; + outmsg.image.color1 = image->color1; + outmsg.image.color2 = image->color2; + outmsg.image.color3 = image->color3; outmsg.image.image = image->image; /* The user pointer is sent, no data */ /* We will finish the teardown upon receipt of the DISCONNECTED message */