diff options
Diffstat (limited to 'nuttx/graphics/nxmu')
42 files changed, 6167 insertions, 0 deletions
diff --git a/nuttx/graphics/nxmu/Make.defs b/nuttx/graphics/nxmu/Make.defs new file mode 100644 index 000000000..23bf8995b --- /dev/null +++ b/nuttx/graphics/nxmu/Make.defs @@ -0,0 +1,48 @@ +############################################################################ +# graphics/nxmu/Make.defs +# +# Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved. +# Author: Gregory Nutt <gnutt@nuttx.org> +# +# 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. +# +############################################################################ + +NX_ASRCS = +NXAPI_CSRCS = nx_bitmap.c nx_closewindow.c nx_connect.c nx_disconnect.c \ + nx_eventhandler.c nx_eventnotify.c nx_fill.c nx_filltrapezoid.c \ + nx_getposition.c nx_getrectangle.c nx_kbdchin.c nx_kbdin.c nx_lower.c \ + nx_mousein.c nx_move.c nx_openwindow.c nx_raise.c \ + nx_releasebkgd.c nx_requestbkgd.c nx_setpixel.c nx_setsize.c \ + nx_setbgcolor.c nx_setposition.c nx_drawcircle.c nx_drawline.c \ + nx_fillcircle.c nx_block.c +NXMU_CSRCS = nxmu_constructwindow.c nxmu_kbdin.c nxmu_mouse.c \ + nxmu_openwindow.c nxmu_redrawreq.c nxmu_releasebkgd.c \ + nxmu_requestbkgd.c nxmu_reportposition.c nxmu_sendclient.c \ + nxmu_sendserver.c nxmu_sendwindow.c nxmu_semtake.c nxmu_server.c +NX_CSRCS = $(NXAPI_CSRCS) $(NXMU_CSRCS) diff --git a/nuttx/graphics/nxmu/nx_bitmap.c b/nuttx/graphics/nxmu/nx_bitmap.c new file mode 100644 index 000000000..a86eda96a --- /dev/null +++ b/nuttx/graphics/nxmu/nx_bitmap.c @@ -0,0 +1,130 @@ +/**************************************************************************** + * graphics/nxmu/nx_bitmap.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> + +#include "nxbe.h" +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_bitmap + * + * Description: + * Copy a rectangular region of a larger image into the rectangle in the + * specified window. + * + * Input Parameters: + * hwnd - The window that will receive the bitmap image + * dest - Describes the rectangular region on the display that will receive the + * the bit map. + * src - The start of the source image. + * origin - The origin of the upper, left-most corner of the full bitmap. + * Both dest and origin are in window coordinates, however, origin + * may lie outside of the display. + * stride - The width of the full source image in pixels. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_bitmap(NXWINDOW hwnd, FAR const struct nxgl_rect_s *dest, + FAR const void *src[CONFIG_NX_NPLANES], + FAR const struct nxgl_point_s *origin, unsigned int stride) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_bitmap_s outmsg; + int i; + +#ifdef CONFIG_DEBUG + if (!wnd || !dest || !src || !origin) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Format the bitmap command */ + + outmsg.msgid = NX_SVRMSG_BITMAP; + outmsg.wnd = wnd; + outmsg.stride = stride; + + for (i = 0; i < CONFIG_NX_NPLANES; i++) + { + outmsg.src[i] = src[i]; + } + + outmsg.origin.x = origin->x; + outmsg.origin.y = origin->y; + nxgl_rectcopy(&outmsg.dest, dest); + + /* Forward the fill command to the server */ + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_bitmap_s)); +} diff --git a/nuttx/graphics/nxmu/nx_block.c b/nuttx/graphics/nxmu/nx_block.c new file mode 100644 index 000000000..2f069f096 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_block.c @@ -0,0 +1,148 @@ +/**************************************************************************** + * graphics/nxmu/nx_block.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> + +#include "nxbe.h" +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_block + * + * Description: + * This is callback will do to things: (1) any queue a 'blocked' callback + * to the window and then (2) block any further window messaging. + * + * The 'blocked' callback is the response from nx_block (or nxtk_block). + * Those blocking interfaces are used to assure that no further messages are + * are directed to the window. Receipt of the blocked callback signifies + * that (1) there are no further pending callbacks and (2) that the + * window is now 'defunct' and will receive no further callbacks. + * + * This callback supports coordinated destruction of a window in multi- + * user mode. In multi-use mode, the client window logic must stay + * intact until all of the queued callbacks are processed. Then the + * window may be safely closed. Closing the window prior with pending + * callbacks can lead to bad behavior when the callback is executed. + * + * Multiple user mode only! + * + * Input Parameters: + * wnd - The window to be blocked + * arg - An argument that will accompany the block messages (This is arg2 + * in the blocked callback). + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_block(NXWINDOW hwnd, FAR void *arg) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_blocked_s outmsg; + int ret = OK; + +#ifdef CONFIG_DEBUG + if (!hwnd) + { + errno = EINVAL; + return NULL; + } +#endif + + /* Ignore additional attempts to block messages (no errors reported) */ + + if (!NXBE_ISBLOCKED(wnd)) + { + /* Mark the window as blocked. This will stop all messages to the window + * (EXCEPT the NX_SVRMSG_BLOCKED). Blocking the messages before sending the + * blocked message is awkward but assures that no other messages sneak into + * the message queue before we can set the blocked state. + */ + + NXBE_SETBLOCKED(wnd); + + /* Send the message inicating that the window is blocked (and because of + * queue also that there are no additional queue messages for the window) + */ + + outmsg.msgid = NX_SVRMSG_BLOCKED; + outmsg.wnd = wnd; + outmsg.arg = arg; + + /* Send the window message via nxmu_sendserver (vs. nxmu_sendwindow) so + * that it will not be blocked. + */ + + ret = nxmu_sendserver(wnd->conn, &outmsg, sizeof(struct nxbe_window_s)); + } + + return ret; +} + diff --git a/nuttx/graphics/nxmu/nx_closewindow.c b/nuttx/graphics/nxmu/nx_closewindow.c new file mode 100644 index 000000000..f9722fcd2 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_closewindow.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * graphics/nxmu/nx_closewindow.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdlib.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + + +/**************************************************************************** + * Name: nx_closewindow + * + * Description: + * Destroy a window created by nx_openwindow. + * + * Input Parameters: + * wnd - The window to be destroyed + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_closewindow(NXWINDOW hwnd) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_closewindow_s outmsg; + + /* Request destruction of the window by the server */ + + outmsg.msgid = NX_SVRMSG_CLOSEWINDOW; + outmsg.wnd = wnd; + + return nxmu_sendserver(wnd->conn, &outmsg, sizeof(struct nxsvrmsg_closewindow_s)); +} + diff --git a/nuttx/graphics/nxmu/nx_connect.c b/nuttx/graphics/nxmu/nx_connect.c new file mode 100644 index 000000000..4d91b54d5 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_connect.c @@ -0,0 +1,220 @@ +/**************************************************************************** + * graphics/nxmu/nx_connect.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <fcntl.h> +#include <mqueue.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Each client is assigned a unique ID using the g_nxcid counter. That + * counter increments as each new counter is created and is* protected for + * thread safefy with g_nxlibsem. Note that these are the only global values + * in the NX implementation. This is because the client ID must be unique + * even across all server instances. + * + * NOTE: that client ID 0 is reserved for the server(s) themselves + */ + +static sem_t g_nxlibsem = { 1 }; +static uint32_t g_nxcid = 1; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_connectinstance + * + * Description: + * Open a connection from a client to the NX server. One one client + * connection is normally needed per thread as each connection can host + * multiple windows. + * + * NOTES: + * - This function returns before the connection is fully instantiated. + * it is necessary to wait for the connection event before using the + * returned handle. + * - Multiple instances of the NX server may run at the same time, + * each with different message queue names. + * + * Input Parameters: + * svrmqname - The name for the server incoming message queue + * + * Return: + * Success: A non-NULL handle used with subsequent NX accesses + * Failure: NULL is returned and errno is set appropriately + * + ****************************************************************************/ + +NXHANDLE nx_connectinstance(FAR const char *svrmqname) +{ + FAR struct nxfe_conn_s *conn; + struct nxsvrmsg_s outmsg; + char climqname[NX_CLIENT_MXNAMELEN]; + struct mq_attr attr; + int ret; + + /* Sanity checking */ + +#ifdef CONFIG_DEBUG + if (!svrmqname) + { + errno = EINVAL; + return NULL; + } +#endif + + /* Allocate the NX client structure */ + + conn = (FAR struct nxfe_conn_s *)zalloc(sizeof(struct nxfe_conn_s)); + if (!conn) + { + errno = ENOMEM; + goto errout; + } + + /* Create the client MQ name */ + + nxmu_semtake(&g_nxlibsem); + conn->cid = g_nxcid++; + nxmu_semgive(&g_nxlibsem); + + sprintf(climqname, NX_CLIENT_MQNAMEFMT, conn->cid); + + /* Open the client MQ for reading */ + + attr.mq_maxmsg = CONFIG_NX_MXCLIENTMSGS; + attr.mq_msgsize = NX_MXCLIMSGLEN; + attr.mq_flags = 0; + +#ifdef CONFIG_NX_BLOCKING + conn->crdmq = mq_open(climqname, O_RDONLY|O_CREAT, 0666, &attr); +#else + conn->crdmq = mq_open(climqname, O_RDONLY|O_CREAT|O_NONBLOCK, 0666, &attr); +#endif + if (conn->crdmq == (mqd_t)-1) + { + gdbg("mq_open(%s) failed: %d\n", climqname, errno); + goto errout_with_conn; + } + + /* Open the server MQ for writing */ + + attr.mq_maxmsg = CONFIG_NX_MXSERVERMSGS; + attr.mq_msgsize = NX_MXSVRMSGLEN; + attr.mq_flags = 0; + + conn->cwrmq = mq_open(svrmqname, O_WRONLY|O_CREAT, 0666, &attr); + if (conn->cwrmq == (mqd_t)-1) + { + gdbg("mq_open(%s) failed: %d\n", svrmqname, errno); + goto errout_with_rmq; + } + + /* Inform the server that this client exists */ + + outmsg.msgid = NX_SVRMSG_CONNECT; + outmsg.conn = conn; + + ret = nxmu_sendserver(conn, &outmsg, sizeof(struct nxsvrmsg_s)); + if (ret < 0) + { + gdbg("nxmu_sendserver failed: %d\n", errno); + goto errout_with_wmq; + } + +#if 0 + /* Now read until we get a response to this message. The server will + * respond with either (1) NX_CLIMSG_CONNECTED, in which case the state + * will change to NX_CLISTATE_CONNECTED, or (2) NX_CLIMSG_DISCONNECTED + * in which case, nx_message will fail with errno = EHOSTDOWN. + */ + + do + { + ret = nx_eventhandler((NXHANDLE)conn); + if (ret < 0) + { + gdbg("nx_message failed: %d\n", errno); + goto errout_with_wmq; + } + usleep(300000); + } + while (conn->state != NX_CLISTATE_CONNECTED); +#endif + return (NXHANDLE)conn; + +errout_with_wmq: + mq_close(conn->cwrmq); +errout_with_rmq: + mq_close(conn->crdmq); +errout_with_conn: + free(conn); +errout: + return NULL; +} + diff --git a/nuttx/graphics/nxmu/nx_disconnect.c b/nuttx/graphics/nxmu/nx_disconnect.c new file mode 100644 index 000000000..48e1e9cc0 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_disconnect.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * graphics/nxmu/nx_disconnect.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <mqueue.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_disconnect + * + * Description: + * Disconnect a client from the NX server and/or free resources reserved + * by nx_connect/nx_connectinstance. + * + * Input Parameters: + * handle - the handle returned by nx_connect + * + * Return: + * OK on success; ERROR on failure with the errno set appropriately. + * NOTE that handle will no long be valid upon return. + * + ****************************************************************************/ + +void nx_disconnect(NXHANDLE handle) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + struct nxsvrmsg_s outmsg; + int ret; + + /* Inform the server that this client no longer exists */ + + outmsg.msgid = NX_SVRMSG_DISCONNECT; + outmsg.conn = conn; + + /* We will finish the teardown upon receipt of the DISCONNECTED message */ + + ret = nxmu_sendserver(conn, &outmsg, sizeof(struct nxsvrmsg_s)); + if (ret < 0) + { + gdbg("ERROR: nxmu_sendserver() returned %d\n", ret); + } +} + diff --git a/nuttx/graphics/nxmu/nx_drawcircle.c b/nuttx/graphics/nxmu/nx_drawcircle.c new file mode 100644 index 000000000..22424c19d --- /dev/null +++ b/nuttx/graphics/nxmu/nx_drawcircle.c @@ -0,0 +1,145 @@ +/**************************************************************************** + * graphics/nxmu/nx_drawcircle.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <sys/types.h> +#include <debug.h> +#include <errno.h> + +#include <nuttx/nx/nxglib.h> +#include <nuttx/nx/nx.h> + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ +/* Named indices into the 16 circle points generated by nxgl_circlepts */ + +#define POINT_0p0 0 +#define POINT_22p5 1 +#define POINT_45p0 2 +#define POINT_67p5 3 +#define POINT_90p0 4 +#define POINT_112p5 5 +#define POINT_135p0 6 +#define POINT_157p5 7 +#define POINT_180p0 8 +#define POINT_202p5 9 +#define POINT_225p0 10 +#define POINT_247p5 11 +#define POINT_270p0 12 +#define POINT_292p5 13 +#define POINT_315p0 14 +#define POINT_337p5 15 +#define NCIRCLE_POINTS 16 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_drawcircle + * + * Description: + * Draw a circular outline using the specified line thickness and color. + * + * Input Parameters: + * hwnd - The window handle + * center - A pointer to the point that is the center of the circle + * radius - The radius of the circle in pixels. + * width - The width of the line + * color - The color to use to fill the line + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_drawcircle(NXWINDOW hwnd, FAR const struct nxgl_point_s *center, + nxgl_coord_t radius, nxgl_coord_t width, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + struct nxgl_point_s pts[NCIRCLE_POINTS]; + FAR struct nxgl_vector_s vector; + int i; + int ret; + + /* Convert the circle to a set of 16 points */ + + nxgl_circlepts(center, radius, pts); + + /* Draw each pair of points as a vector */ + + for (i = POINT_0p0; i < POINT_337p5; i++) + { + vector.pt1.x = pts[i].x; + vector.pt1.y = pts[i].y; + vector.pt2.x = pts[i+1].x; + vector.pt2.y = pts[i+1].y; + ret = nx_drawline(hwnd, &vector, width, color); + if (ret != OK) + { + return ret; + } + } + + /* The final, closing vector is a special case */ + + vector.pt1.x = pts[POINT_337p5].x; + vector.pt1.y = pts[POINT_337p5].y; + vector.pt2.x = pts[POINT_0p0].x; + vector.pt2.y = pts[POINT_0p0].y; + return nx_drawline(hwnd, &vector, width, color); +} diff --git a/nuttx/graphics/nxmu/nx_drawline.c b/nuttx/graphics/nxmu/nx_drawline.c new file mode 100644 index 000000000..7de0af1c1 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_drawline.c @@ -0,0 +1,136 @@ +/**************************************************************************** + * graphics/nxmu/nx_drawline.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <sys/types.h> +#include <debug.h> +#include <errno.h> + +#include <nuttx/nx/nxglib.h> +#include <nuttx/nx/nx.h> + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_drawline + * + * Description: + * Fill the specified line in the window with the specified color. This + * is simply a wrapper that uses nxgl_splitline() to break the line into + * trapezoids and then calls nx_filltrapezoid() to render the line. + * + * Input Parameters: + * hwnd - The window handle + * vector - Describes the line to be drawn + * width - The width of the line + * color - The color to use to fill the line + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_drawline(NXWINDOW hwnd, FAR struct nxgl_vector_s *vector, + nxgl_coord_t width, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + struct nxgl_trapezoid_s trap[3]; + struct nxgl_rect_s rect; + int ret; + +#ifdef CONFIG_DEBUG + if (!hwnd || !vector || width < 1 || !color) + { + set_errno(EINVAL); + return ERROR; + } +#endif + + ret = nxgl_splitline(vector, trap, &rect, width); + switch (ret) + { + case 0: + ret = nx_filltrapezoid(hwnd, NULL, &trap[0], color); + if (ret == OK) + { + ret = nx_filltrapezoid(hwnd, NULL, &trap[1], color); + if (ret == OK) + { + ret = nx_filltrapezoid(hwnd, NULL, &trap[2], color); + } + } + break; + + case 1: + ret = nx_filltrapezoid(hwnd, NULL, &trap[1], color); + break; + + case 2: + ret = nx_fill(hwnd, &rect, color); + break; + + default: + set_errno(-ret); + return ERROR; + } + + return ret; +} diff --git a/nuttx/graphics/nxmu/nx_eventhandler.c b/nuttx/graphics/nxmu/nx_eventhandler.c new file mode 100644 index 000000000..944bb12d1 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_eventhandler.c @@ -0,0 +1,260 @@ +/**************************************************************************** + * graphics/nxmu/nx_eventhandler.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <stdlib.h> +#include <mqueue.h> +#include <assert.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_connected + * + * Description: + * The server has completed the connection and is ready. + * + ****************************************************************************/ + +static inline void nx_connected(FAR struct nxfe_conn_s *conn) +{ + DEBUGASSERT(conn->state == NX_CLISTATE_NOTCONNECTED); + conn->state = NX_CLISTATE_CONNECTED; +} + +/**************************************************************************** + * Name: nx_disconnected + ****************************************************************************/ + +static inline void nx_disconnected(FAR struct nxfe_conn_s *conn) +{ + /* Close the server and client MQs */ + + (void)mq_close(conn->cwrmq); + (void)mq_close(conn->crdmq); + + /* And free the client structure */ + + free(conn); +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_eventhandler + * + * Description: + * The client code must call this function periodically to process + * incoming messages from the server. If CONFIG_NX_BLOCKING is defined, + * then this function not return until a server message is received. + * + * When CONFIG_NX_BLOCKING is not defined, the client must exercise + * caution in the looping to assure that it does not eat up all of + * the CPU bandwidth calling nx_eventhandler repeatedly. nx_eventnotify + * may be called to get a signal event whenever a new incoming server + * event is avaiable. + * + * Input Parameters: + * handle - the handle returned by nx_connect + * + * Return: + * OK: No errors occurred. If CONFIG_NX_BLOCKING is defined, then + * one or more server message was processed. + * ERROR: An error occurred and errno has been set appropriately. Of + * particular interest, it will return errno == EHOSTDOWN when the + * server is disconnected. After that event, the handle can no + * longer be used. + * + ****************************************************************************/ + +int nx_eventhandler(NXHANDLE handle) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + struct nxsvrmsg_s *msg; + struct nxbe_window_s *wnd; + uint8_t buffer[NX_MXCLIMSGLEN]; + int nbytes; + + /* Get the next message from our incoming message queue */ + + do + { + nbytes = mq_receive(conn->crdmq, buffer, NX_MXCLIMSGLEN, 0); + if (nbytes < 0) + { + /* EINTR is not an error. The wait was interrupted by a signal and + * we just need to try reading again. + */ + + if (errno != EINTR) + { + if (errno == EAGAIN) + { + /* EAGAIN is not an error. It occurs because the MQ is opened with + * O_NONBLOCK and there is no message available now. + */ + + return OK; + } + else + { + gdbg("mq_receive failed: %d\n", errno); + return ERROR; + } + } + } + } + while (nbytes < 0); + + DEBUGASSERT(nbytes >= sizeof(struct nxclimsg_s)); + + /* Dispatch the message appropriately */ + + msg = (struct nxsvrmsg_s *)buffer; + gvdbg("Received msgid=%d\n", msg->msgid); + switch (msg->msgid) + { + case NX_CLIMSG_CONNECTED: + nx_connected(conn); + break; + + case NX_CLIMSG_DISCONNECTED: + nx_disconnected(conn); + errno = EHOSTDOWN; + return ERROR; + + case NX_CLIMSG_REDRAW: + { + FAR struct nxclimsg_redraw_s *redraw = (FAR struct nxclimsg_redraw_s *)buffer; + wnd = redraw->wnd; + DEBUGASSERT(wnd); + if (wnd->cb->redraw) + { + wnd->cb->redraw((NXWINDOW)wnd, &redraw->rect, redraw->more, wnd->arg); + } + } + break; + + case NX_CLIMSG_NEWPOSITION: + { + FAR struct nxclimsg_newposition_s *postn = (FAR struct nxclimsg_newposition_s *)buffer; + wnd = postn->wnd; + DEBUGASSERT(wnd); + if (wnd->cb->position) + { + wnd->cb->position((NXWINDOW)wnd, &postn->size, &postn->pos, &postn->bounds, wnd->arg); + } + } + break; + +#ifdef CONFIG_NX_MOUSE + case NX_CLIMSG_MOUSEIN: + { + FAR struct nxclimsg_mousein_s *mouse = (FAR struct nxclimsg_mousein_s *)buffer; + wnd = mouse->wnd; + DEBUGASSERT(wnd); + if (wnd->cb->mousein) + { + wnd->cb->mousein((NXWINDOW)wnd, &mouse->pos, mouse->buttons, wnd->arg); + } + } + break; +#endif + +#ifdef CONFIG_NX_KBD + case NX_CLIMSG_KBDIN: + { + FAR struct nxclimsg_kbdin_s *kbd = (FAR struct nxclimsg_kbdin_s *)buffer; + wnd = kbd->wnd; + DEBUGASSERT(wnd); + if (wnd->cb->kbdin) + { + wnd->cb->kbdin((NXWINDOW)wnd, kbd->nch, kbd->ch, wnd->arg); + } + } + break; +#endif + + case NX_CLIMSG_BLOCKED: + { + FAR struct nxclimsg_blocked_s *blocked = (FAR struct nxclimsg_blocked_s *)buffer; + wnd = blocked->wnd; + DEBUGASSERT(wnd); + if (wnd->cb->blocked) + { + wnd->cb->blocked((NXWINDOW)wnd, wnd->arg, blocked->arg); + } + } + break; + + default: + gdbg("Unrecognized message opcode: %d\n", ((FAR struct nxsvrmsg_s *)buffer)->msgid); + break; + } + + return OK; +} + diff --git a/nuttx/graphics/nxmu/nx_eventnotify.c b/nuttx/graphics/nxmu/nx_eventnotify.c new file mode 100644 index 000000000..556c9fa93 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_eventnotify.c @@ -0,0 +1,111 @@ +/**************************************************************************** + * graphics/nxmu/nx_eventnotify.c + * + * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdlib.h> +#include <mqueue.h> +#include <assert.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +#ifndef CONFIG_DISABLE_SIGNALS + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_eventnotify + * + * Description: + * Rather than calling nx_eventhandler periodically, the client may + * register to receive a signal when a server event is available. The + * client can then call nv_eventhandler() only when incoming events are + * available. + * + * Only one such event is issued. Upon receipt of the signal, if the client + * wishes further notifications, it must call nx_eventnotify again. + * + * Input Parameters: + * handle - the handle returned by nx_connect + * + * Return: + * OK: No errors occurred. If CONFIG_NX_BLOCKING is defined, then + * one or more server message was processed. + * ERROR: An error occurred and errno has been set appropriately + * + ****************************************************************************/ + +int nx_eventnotify(NXHANDLE handle, int signo) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + struct sigevent se; + + se.sigev_notify = SIGEV_SIGNAL; + se.sigev_signo = signo; + se.sigev_value.sival_ptr = (FAR void *)handle; + + return mq_notify(conn->crdmq, &se); +} + +#endif /* CONFIG_DISABLE_SIGNALS */ diff --git a/nuttx/graphics/nxmu/nx_fill.c b/nuttx/graphics/nxmu/nx_fill.c new file mode 100644 index 000000000..969acdace --- /dev/null +++ b/nuttx/graphics/nxmu/nx_fill.c @@ -0,0 +1,116 @@ +/**************************************************************************** + * graphics/nxmu/nx_fill.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <mqueue.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nxglib.h> +#include <nuttx/nx/nx.h> + +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_fill + * + * Description: + * Fill the specified rectangle in the window with the specified color + * + * Input Parameters: + * hwnd - The window handle + * rect - The location to be filled + * color - The color to use in the fill + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_fill(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_fill_s outmsg; + +#ifdef CONFIG_DEBUG + if (!wnd || !rect || !color) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Format the fill command */ + + outmsg.msgid = NX_SVRMSG_FILL; + outmsg.wnd = wnd; + + nxgl_rectcopy(&outmsg.rect, rect); + nxgl_colorcopy(outmsg.color, color); + + /* Forward the fill command to the server */ + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_fill_s)); +} diff --git a/nuttx/graphics/nxmu/nx_fillcircle.c b/nuttx/graphics/nxmu/nx_fillcircle.c new file mode 100644 index 000000000..5c9671695 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_fillcircle.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * graphics/nxsu/nx_fillcircle.c + * + * Copyright (C) 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <sys/types.h> +#include <debug.h> +#include <errno.h> + +#include <nuttx/nx/nxglib.h> +#include <nuttx/nx/nx.h> + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +#define NCIRCLE_TRAPS 8 + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_fillcircle + * + * Description: + * Fill a circular region using the specified color. + * + * Input Parameters: + * hwnd - The window handle + * center - A pointer to the point that is the center of the circle + * radius - The radius of the circle in pixels. + * color - The color to use to fill the circle. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_fillcircle(NXWINDOW hwnd, FAR const struct nxgl_point_s *center, + nxgl_coord_t radius, nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + FAR struct nxgl_trapezoid_s traps[NCIRCLE_TRAPS]; + int i; + int ret; + + /* Describe the circular region as a sequence of 8 trapezoids */ + + nxgl_circletraps(center, radius, traps); + + /* Then rend those trapezoids */ + + for (i = 0; i < NCIRCLE_TRAPS; i++) + { + ret = nx_filltrapezoid(hwnd, NULL, &traps[i], color); + if (ret != OK) + { + return ret; + } + } + return OK; +} diff --git a/nuttx/graphics/nxmu/nx_filltrapezoid.c b/nuttx/graphics/nxmu/nx_filltrapezoid.c new file mode 100644 index 000000000..bf289179e --- /dev/null +++ b/nuttx/graphics/nxmu/nx_filltrapezoid.c @@ -0,0 +1,142 @@ +/**************************************************************************** + * graphics/nxmu/nx_filltrapezoid.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <string.h> +#include <mqueue.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> + +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_filltrapezoid + * + * Description: + * Fill the specified trapezoidal region in the window with the specified color + * + * Input Parameters: + * hwnd - The window handle + * clip - Clipping region (may be null) + * trap - The trapezoidal region to be filled + * color - The color to use in the fill + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_filltrapezoid(NXWINDOW hwnd, FAR const struct nxgl_rect_s *clip, + FAR const struct nxgl_trapezoid_s *trap, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_filltrapezoid_s outmsg; + int i; + + /* Some debug-only sanity checks */ + +#ifdef CONFIG_DEBUG + if (!wnd || !trap || !color) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Format the fill command */ + + outmsg.msgid = NX_SVRMSG_FILLTRAP; + outmsg.wnd = wnd; + + /* If no clipping window was provided, then use the size of the entire window */ + + if (clip) + { + nxgl_rectcopy(&outmsg.clip, clip); + } + else + { + nxgl_rectcopy(&outmsg.clip, &wnd->bounds); + } + + /* Copy the trapezod and the color into the message */ + + nxgl_trapcopy(&outmsg.trap, trap); + +#if CONFIG_NX_NPLANES > 1 + for (i = 0; i < CONFIG_NX_NPLANES; i++) +#else + i = 0; +#endif + { + outmsg.color[i] = color[i]; + } + + /* Forward the trapezoid fill command to the server */ + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_filltrapezoid_s)); +} diff --git a/nuttx/graphics/nxmu/nx_getposition.c b/nuttx/graphics/nxmu/nx_getposition.c new file mode 100644 index 000000000..06ad2c6aa --- /dev/null +++ b/nuttx/graphics/nxmu/nx_getposition.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * graphics/nxmu/nx_getposition.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_getposition + * + * Description: + * Request the position and size information for the selected window. The + * values will be return asynchronously through the client callback function + * pointer. + * + * Input Parameters: + * hwnd - The window handle + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_getposition(NXWINDOW hwnd) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_getposition_s outmsg; + +#ifdef CONFIG_DEBUG + if (!wnd) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Request the size/position info. + * + * It is tempting to just take the positional information from the window + * structure that we have in our hands now. However, we need to run this through + * the server to keep things serialized. There might, for example, be a pending + * size/position change and, in that case, this function would return the + * wrong info. + */ + + outmsg.msgid = NX_SVRMSG_GETPOSITION; + outmsg.wnd = wnd; + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_getposition_s)); +} diff --git a/nuttx/graphics/nxmu/nx_getrectangle.c b/nuttx/graphics/nxmu/nx_getrectangle.c new file mode 100644 index 000000000..f32065129 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_getrectangle.c @@ -0,0 +1,124 @@ +/**************************************************************************** + * graphics/nxmu/nx_getrectangle.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <mqueue.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> + +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_getrectangle + * + * Description: + * Get the raw contents of graphic memory within a rectangular region. NOTE: + * Since raw graphic memory is returned, the returned memory content may be + * the memory of windows above this one and may not necessarily belong to + * this window unless you assure that this is the top window. + * + * Input Parameters: + * wnd - The window structure reference + * rect - The location to be copied + * plane - Specifies the color plane to get from. + * dest - The location to copy the memory region + * deststride - The width, in bytes, the the dest memory + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_getrectangle(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, + unsigned int plane, FAR uint8_t *dest, + unsigned int deststride) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_getrectangle_s outmsg; + +#ifdef CONFIG_DEBUG + if (!hwnd || !rect || !dest) + { + gvdbg("Invalid parameters\n"); + set_errno(EINVAL); + return ERROR; + } +#endif + + /* Format the fill command */ + + outmsg.msgid = NX_SVRMSG_GETRECTANGLE; + outmsg.wnd = wnd; + outmsg.plane = plane; + outmsg.dest = dest; + outmsg.deststride = deststride; + + nxgl_rectcopy(&outmsg.rect, rect); + + /* Forward the fill command to the server */ + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_getrectangle_s)); +} diff --git a/nuttx/graphics/nxmu/nx_kbdchin.c b/nuttx/graphics/nxmu/nx_kbdchin.c new file mode 100644 index 000000000..6c7019f51 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_kbdchin.c @@ -0,0 +1,99 @@ +/**************************************************************************** + * graphics/nxmu/nx_kbdchin.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +#ifdef CONFIG_NX_KBD + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_kbdchin + * + * Description: + * Used by a thread or interrupt handler that manages some kind of keypad + * hardware to report text information to the NX server. That text + * data will be routed by the NX server to the appropriate window client. + * + ****************************************************************************/ + +int nx_kbdchin(NXHANDLE handle, uint8_t ch) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + struct nxsvrmsg_kbdin_s outmsg; + + /* Inform the server of the new keypad data */ + + outmsg.msgid = NX_SVRMSG_KBDIN; + outmsg.nch = 1; + outmsg.ch[0] = ch; + + return nxmu_sendserver(conn, &outmsg, sizeof(struct nxsvrmsg_kbdin_s)); +} + +#endif /* CONFIG_NX_KBD */ diff --git a/nuttx/graphics/nxmu/nx_kbdin.c b/nuttx/graphics/nxmu/nx_kbdin.c new file mode 100644 index 000000000..b4b91298b --- /dev/null +++ b/nuttx/graphics/nxmu/nx_kbdin.c @@ -0,0 +1,122 @@ +/**************************************************************************** + * graphics/nxmu/nx_kbdin.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <stdlib.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +#ifdef CONFIG_NX_KBD + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_kbdin + * + * Description: + * Used by a thread or interrupt handler that manages some kind of keypad + * hardware to report text information to the NX server. That text + * data will be routed by the NX server to the appropriate window client. + * + ****************************************************************************/ + +int nx_kbdin(NXHANDLE handle, uint8_t nch, FAR const uint8_t *ch) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + FAR struct nxsvrmsg_kbdin_s *outmsg; + int size; + int ret; + int i; + + /* Allocate a bigger message to account for the variable amount of character + * data. + */ + + size = sizeof(struct nxsvrmsg_kbdin_s) + nch - 1; + outmsg = (FAR struct nxsvrmsg_kbdin_s *)malloc(size); + if (!outmsg) + { + errno = ENOMEM; + return ERROR; + } + + /* Inform the server of the new keypad data */ + + outmsg->msgid = NX_SVRMSG_KBDIN; + outmsg->nch = nch; + + for (i = 0; i < nch; i++) + { + outmsg->ch[i] = ch[i]; + } + + ret = nxmu_sendserver(conn, outmsg, size); + + free(outmsg); + return ret; +} + +#endif /* CONFIG_NX_KBD */ diff --git a/nuttx/graphics/nxmu/nx_lower.c b/nuttx/graphics/nxmu/nx_lower.c new file mode 100644 index 000000000..c9505ca49 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_lower.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * graphics/nxmu/nx_lower.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_raise + * + * Description: + * Lower the specified window to the bottom of the display. + * + * Input parameters: + * hwnd - the window to be lowered + * + * Returned value: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_lower(NXWINDOW hwnd) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_lower_s outmsg; + + /* Send the RAISE message */ + + outmsg.msgid = NX_SVRMSG_LOWER; + outmsg.wnd = wnd; + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_lower_s)); +} + diff --git a/nuttx/graphics/nxmu/nx_mousein.c b/nuttx/graphics/nxmu/nx_mousein.c new file mode 100644 index 000000000..e84278539 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_mousein.c @@ -0,0 +1,100 @@ +/**************************************************************************** + * graphics/nxmu/nx_mousein.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +#ifdef CONFIG_NX_MOUSE + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_mousein + * + * Description: + * Used by a thread or interrupt handler that manages some kind of pointing + * hardware to report new positional data to the NX server. That positional + * data will be routed by the NX server to the appropriate window client. + * + ****************************************************************************/ + +int nx_mousein(NXHANDLE handle, nxgl_coord_t x, nxgl_coord_t y, uint8_t buttons) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + struct nxsvrmsg_mousein_s outmsg; + + /* Inform the server that this client no longer exists */ + + outmsg.msgid = NX_SVRMSG_MOUSEIN; + outmsg.pt.x = x; + outmsg.pt.y = y; + outmsg.buttons = buttons; + + return nxmu_sendserver(conn, &outmsg, sizeof(struct nxsvrmsg_mousein_s)); +} + +#endif /* CONFIG_NX_MOUSE */ diff --git a/nuttx/graphics/nxmu/nx_move.c b/nuttx/graphics/nxmu/nx_move.c new file mode 100644 index 000000000..c8d4d3dfd --- /dev/null +++ b/nuttx/graphics/nxmu/nx_move.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * graphics/nxmu/nx_move.c + * + * Copyright (C) 2008-2009, 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_move + * + * Description: + * Move a rectangular region within the window + * + * Input Parameters: + * hwnd - The window within which the move is to be done + * rect - Describes the rectangular region to move + * offset - The offset to move the region + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_move(NXWINDOW hwnd, FAR const struct nxgl_rect_s *rect, + FAR const struct nxgl_point_s *offset) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_move_s outmsg; + +#ifdef CONFIG_DEBUG + if (!wnd) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Format the fill command */ + + outmsg.msgid = NX_SVRMSG_MOVE; + outmsg.wnd = wnd; + outmsg.offset.x = offset->x; + outmsg.offset.y = offset->y; + + nxgl_rectcopy(&outmsg.rect, rect); + + /* Forward the fill command to the server */ + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_move_s)); +} diff --git a/nuttx/graphics/nxmu/nx_openwindow.c b/nuttx/graphics/nxmu/nx_openwindow.c new file mode 100644 index 000000000..2975e365a --- /dev/null +++ b/nuttx/graphics/nxmu/nx_openwindow.c @@ -0,0 +1,131 @@ +/**************************************************************************** + * graphics/nxmu/nx_openwindow.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include <nuttx/kmalloc.h> + +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_openwindow + * + * Description: + * Create a new window. + * + * Input Parameters: + * handle - The handle returned by nx_connect + * cb - Callbacks used to process windo events + * arg - User provided value that will be returned with NX callbacks. + * + * Return: + * Success: A non-NULL handle used with subsequent NX accesses + * Failure: NULL is returned and errno is set appropriately + * + ****************************************************************************/ + +NXWINDOW nx_openwindow(NXHANDLE handle, FAR const struct nx_callback_s *cb, + FAR void *arg) +{ + FAR struct nxbe_window_s *wnd; + int ret; + +#ifdef CONFIG_DEBUG + if (!handle || !cb) + { + errno = EINVAL; + return NULL; + } +#endif + + /* Pre-allocate the window structure */ + + wnd = (FAR struct nxbe_window_s *)kzalloc(sizeof(struct nxbe_window_s)); + if (!wnd) + { + errno = ENOMEM; + return NULL; + } + + /* Then let nxfe_constructwindow do the rest */ + + ret = nxfe_constructwindow(handle, wnd, cb, arg); + if (ret < 0) + { + /* An error occurred, the window has been freed */ + + return NULL; + } + + /* Return the uninitialized window reference. Since the server + * serializes all operations, we can be assured that the window will + * be initialized before the first operation on the window. + */ + + return (NXWINDOW)wnd; +} + diff --git a/nuttx/graphics/nxmu/nx_raise.c b/nuttx/graphics/nxmu/nx_raise.c new file mode 100644 index 000000000..4f51810f1 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_raise.c @@ -0,0 +1,98 @@ +/**************************************************************************** + * graphics/nxmu/nx_raise.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_raise + * + * Description: + * Bring the specified window to the top of the display. + * + * Input parameters: + * hwnd - the window to be raised + * + * Returned value: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_raise(NXWINDOW hwnd) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_raise_s outmsg; + + /* Send the RAISE message */ + + outmsg.msgid = NX_SVRMSG_RAISE; + outmsg.wnd = wnd; + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_raise_s)); +} + diff --git a/nuttx/graphics/nxmu/nx_releasebkgd.c b/nuttx/graphics/nxmu/nx_releasebkgd.c new file mode 100644 index 000000000..972585663 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_releasebkgd.c @@ -0,0 +1,105 @@ +/**************************************************************************** + * graphics/nxmu/nx_releasebkgd.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_releasebkgd + * + * Description: + * Release the background window previously acquired using nx_openbgwindow + * and return control of the background to NX. + * + * Input Parameters: + * hwnd - The handle returned (indirectly) by nx_requestbkgd + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_releasebkgd(NXWINDOW hwnd) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_releasebkgd_s outmsg; + +#ifdef CONFIG_DEBUG + if (!wnd) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Request access to the background window from the server */ + + outmsg.msgid = NX_SVRMSG_RELEASEBKGD; + return nxmu_sendserver(wnd->conn, &outmsg, sizeof(struct nxsvrmsg_releasebkgd_s)); +} + diff --git a/nuttx/graphics/nxmu/nx_requestbkgd.c b/nuttx/graphics/nxmu/nx_requestbkgd.c new file mode 100644 index 000000000..c8f71ab2a --- /dev/null +++ b/nuttx/graphics/nxmu/nx_requestbkgd.c @@ -0,0 +1,136 @@ +/**************************************************************************** + * graphics/nxmu/nx_requestbkgd.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_requestbkgd + * + * Description: + * NX normally controls a separate window called the background window. + * It repaints the window as necessary using only a solid color fill. The + * background window always represents the entire screen and is always + * below other windows. It is useful for an application to control the + * background window in the following conditions: + * + * - If you want to implement a windowless solution. The single screen + * can be used to creat a truly simple graphic environment. In this + * case, you should probably also de-select CONFIG_NX_MULTIUSER as well. + * - When you want more on the background than a solid color. For + * example, if you want an image in the background, or animations in the + * background, or live video, etc. + * + * This API only requests the handle of the background window. That + * handle will be returned asynchronously in a subsequent position and + * redraw callbacks. + * + * + * Cautions: + * - The following should never be called using the background window. + * They are guaranteed to cause severe crashes: + * + * nx_setposition, nx_setsize, nx_raise, nx_lower. + * + * - Neither nx_opengbwindow or nx_closebgwindow should be called more than + * once. Multiple instances of the background window are not supported. + * + * Input Parameters: + * handle - The handle returned by nx_connect + * cb - Callbacks to use for processing background window events + * arg - User provided argument (see nx_openwindow, nx_constructwindow) + * + * Return: + * OK: Success; ERROR of failure with errno set appropriately. + * + ****************************************************************************/ + +int nx_requestbkgd(NXHANDLE handle, FAR const struct nx_callback_s *cb, + FAR void *arg) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + struct nxsvrmsg_requestbkgd_s outmsg; + +#ifdef CONFIG_DEBUG + if (!conn || !cb) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Request access to the background window from the server */ + + outmsg.msgid = NX_SVRMSG_REQUESTBKGD; + outmsg.conn = conn; + outmsg.cb = cb; + outmsg.arg = arg; + + return nxmu_sendserver(conn, &outmsg, sizeof(struct nxsvrmsg_requestbkgd_s)); +} + diff --git a/nuttx/graphics/nxmu/nx_setbgcolor.c b/nuttx/graphics/nxmu/nx_setbgcolor.c new file mode 100644 index 000000000..63fca5f55 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_setbgcolor.c @@ -0,0 +1,109 @@ +/**************************************************************************** + * graphics/nxmu/nx_setbgcolor.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_setbgcolor + * + * Description: + * Set the color of the background + * + * Input Parameters: + * handle - The connection handle + * color - The color to use in the background + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_setbgcolor(NXHANDLE handle, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + struct nxsvrmsg_setbgcolor_s outmsg; + +#ifdef CONFIG_DEBUG + if (!conn) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Format the fill command */ + + outmsg.msgid = NX_SVRMSG_SETBGCOLOR; + nxgl_colorcopy(outmsg.color, color); + + /* Forward the fill command to the server */ + + return nxmu_sendserver(conn, &outmsg, sizeof(struct nxsvrmsg_setbgcolor_s)); +} diff --git a/nuttx/graphics/nxmu/nx_setpixel.c b/nuttx/graphics/nxmu/nx_setpixel.c new file mode 100644 index 000000000..57fc12cc6 --- /dev/null +++ b/nuttx/graphics/nxmu/nx_setpixel.c @@ -0,0 +1,118 @@ +/**************************************************************************** + * graphics/nxmu/nx_setpixel.c + * + * Copyright (C) 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <mqueue.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nxglib.h> +#include <nuttx/nx/nx.h> + +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_setpixel + * + * Description: + * Set a single pixel in the window to the specified color. This is simply + * a degenerate case of nx_fill(), but may be optimized in some architectures. + * + * Input Parameters: + * wnd - The window structure reference + * pos - The pixel location to be set + * col - The color to use in the set + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_setpixel(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos, + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_setpixel_s outmsg; + +#ifdef CONFIG_DEBUG + if (!wnd || !pos || !color) + { + set_errno(EINVAL); + return ERROR; + } +#endif + + /* Format the fill command */ + + outmsg.msgid = NX_SVRMSG_SETPIXEL; + outmsg.wnd = wnd; + outmsg.pos.x = pos->x; + outmsg.pos.y = pos->y; + + nxgl_colorcopy(outmsg.color, color); + + /* Forward the fill command to the server */ + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_setpixel_s)); +} diff --git a/nuttx/graphics/nxmu/nx_setposition.c b/nuttx/graphics/nxmu/nx_setposition.c new file mode 100644 index 000000000..75b33757a --- /dev/null +++ b/nuttx/graphics/nxmu/nx_setposition.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * graphics/nxmu/nx_setposition.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_setposition + * + * Description: + * Set the position and size for the selected window + * + * Input Parameters: + * hwnd - The window handle + * pos - The new position of the window + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_setposition(NXWINDOW hwnd, FAR const struct nxgl_point_s *pos) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_setposition_s outmsg; + +#ifdef CONFIG_DEBUG + if (!wnd || !pos) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Inform the server of the changed position */ + + outmsg.msgid = NX_SVRMSG_SETPOSITION; + outmsg.wnd = wnd; + outmsg.pos.x = pos->x; + outmsg.pos.y = pos->y; + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_setposition_s)); +} diff --git a/nuttx/graphics/nxmu/nx_setsize.c b/nuttx/graphics/nxmu/nx_setsize.c new file mode 100644 index 000000000..5f538bccc --- /dev/null +++ b/nuttx/graphics/nxmu/nx_setsize.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * graphics/nxmu/nx_setsize.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_setsize + * + * Description: + * Set the size of the selected window + * + * Input Parameters: + * hwnd - The window handle + * size - The new size of the window. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nx_setsize(NXWINDOW hwnd, FAR const struct nxgl_size_s *size) +{ + FAR struct nxbe_window_s *wnd = (FAR struct nxbe_window_s *)hwnd; + struct nxsvrmsg_setsize_s outmsg; + +#ifdef CONFIG_DEBUG + if (!wnd || !size) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Then inform the server of the changed position */ + + outmsg.msgid = NX_SVRMSG_SETSIZE; + outmsg.wnd = wnd; + outmsg.size.w = size->w; + outmsg.size.h = size->h; + + return nxmu_sendwindow(wnd, &outmsg, sizeof(struct nxsvrmsg_setsize_s)); +} diff --git a/nuttx/graphics/nxmu/nxfe.h b/nuttx/graphics/nxmu/nxfe.h new file mode 100644 index 000000000..8b6a21ef4 --- /dev/null +++ b/nuttx/graphics/nxmu/nxfe.h @@ -0,0 +1,733 @@ +/**************************************************************************** + * graphics/nxmu/nxfe.h + * + * Copyright (C) 2008-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 __GRAPHICS_NXMU_NXFE_H +#define __GRAPHICS_NXMU_NXFE_H + +/**************************************************************************** + * Included Files + ****************************************************************************/ + +#include <nuttx/config.h> + +#include <stdint.h> +#include <stdbool.h> +#include <mqueue.h> +#include <semaphore.h> + +#include <nuttx/nx/nx.h> + +#include "nxbe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/* Configuration ************************************************************/ + +#ifdef CONFIG_DISABLE_MQUEUE +# error "Message queues are disabled(CONFIG_DISABLE_MQUEUE)" +#endif + +#ifndef CONFIG_NX_MXSERVERMSGS +# define CONFIG_NX_MXSERVERMSGS 32 /* Number of pending messages in server MQ */ +#endif + +#ifndef CONFIG_NX_MXCLIENTMSGS +# define CONFIG_NX_MXCLIENTMSGS 16 /* Number of pending messages in each client MQ */ +#endif + +/* Used to create unique client MQ name */ + +#define NX_CLIENT_MQNAMEFMT "/dev/nxc%d" +#define NX_CLIENT_MXNAMELEN (16) + +#define NX_MXSVRMSGLEN (64) /* Maximum size of a client->server command */ +#define NX_MXEVENTLEN (64) /* Maximum size of an event */ +#define NX_MXCLIMSGLEN (64) /* Maximum size of a server->client message */ + +/* Handy macros */ + +#define nxmu_semgive(sem) sem_post(sem) /* To match nxmu_semtake() */ + +/**************************************************************************** + * Public Types + ****************************************************************************/ + +/* Client/Connection structures *********************************************/ + +/* Client state */ + +enum nx_clistate_e +{ + NX_CLISTATE_NOTCONNECTED = 0, /* Waiting for server to acknowledge connection */ + NX_CLISTATE_CONNECTED, /* Connection established (normal state) */ + NX_CLISTATE_DISCONNECT_PENDING, /* Waiting for server to acknowledge disconnect */ +}; + +/* This structure represents a connection between the client and the server */ + +struct nxfe_conn_s +{ + /* This number uniquely identifies the client */ + + int cid; /* Client ID (CID) */ + uint8_t state; /* See enum nx_clistate_e */ + + /* These are only usable on the client side of the connection */ + + mqd_t crdmq; /* MQ to read from the server (may be non-blocking) */ + mqd_t cwrmq; /* MQ to write to the server (blocking) */ + + /* These are only usable on the server side of the connection */ + + mqd_t swrmq; /* MQ to write to the client */ +}; + +/* Server state structure ***************************************************/ + +/* This the server 'front-end' state structure */ + +struct nxfe_state_s +{ + /* The 'back-end' window status. Must be first so that instances of + * struct nxbe_state_s can be simply cast to an instance of struct + * nxfe_state_s + */ + + struct nxbe_state_s be; + + /* This is the server's connection to iself */ + + struct nxfe_conn_s conn; +}; + +/* Message IDs **************************************************************/ + +enum nxmsg_e +{ + /* Server-to-Client Messages **********************************************/ + + NX_CLIMSG_CONNECTED = 1, /* The server has completed the connection and is ready */ + NX_CLIMSG_DISCONNECTED, /* The server has disconnected */ + NX_CLIMSG_REDRAW, /* Re-draw the specified window */ + NX_CLIMSG_NEWPOSITION, /* New window size/position */ + NX_CLIMSG_MOUSEIN, /* New mouse positional data available for window */ + NX_CLIMSG_KBDIN, /* New keypad input available for window */ + NX_CLIMSG_BLOCKED, /* The window is blocked */ + + /* Client-to-Server Messages **********************************************/ + + NX_SVRMSG_CONNECT, /* Establish connection with new NX server client */ + NX_SVRMSG_DISCONNECT, /* Tear down connection with terminating client */ + NX_SVRMSG_OPENWINDOW, /* Create a new window */ + NX_SVRMSG_CLOSEWINDOW, /* Close an existing window */ + NX_SVRMSG_BLOCKED, /* The window is blocked */ + NX_SVRMSG_REQUESTBKGD, /* Open the background window */ + NX_SVRMSG_RELEASEBKGD, /* Release the background window */ + NX_SVRMSG_SETPOSITION, /* Window position has changed */ + NX_SVRMSG_SETSIZE, /* Window size has changed */ + NX_SVRMSG_GETPOSITION, /* Get the current window position and size */ + NX_SVRMSG_RAISE, /* Move the window to the top */ + NX_SVRMSG_LOWER, /* Move the window to the bottom */ + NX_SVRMSG_SETPIXEL, /* Set a single pixel in the window with a color */ + NX_SVRMSG_FILL, /* Fill a rectangle in the window with a color */ + NX_SVRMSG_GETRECTANGLE, /* Get a rectangular region in the window */ + NX_SVRMSG_FILLTRAP, /* Fill a trapezoidal region in the window with a color */ + NX_SVRMSG_MOVE, /* Move a rectangular region within the window */ + NX_SVRMSG_BITMAP, /* Copy a rectangular bitmap into the window */ + NX_SVRMSG_SETBGCOLOR, /* Set the color of the background */ + NX_SVRMSG_MOUSEIN, /* New mouse report from mouse client */ + NX_SVRMSG_KBDIN, /* New keyboard report from keyboard client */ +}; + +/* Message priorities -- they must all be at the same priority to assure + * FIFO execution. + */ + +#define NX_CLIMSG_PRIO 42 +#define NX_SVRMSG_PRIO 42 + +/* Server-to-Client Message Structures **************************************/ + +/* The generic message structure. All messages begin with this form. */ + +struct nxclimsg_s +{ + uint32_t msgid; /* Any of nxclimsg_e */ +}; + +/* The server is now connected */ + +struct nxclimsg_connected_s +{ + uint32_t msgid; /* NX_CLIMSG_REDRAW_CONNECTED */ +}; + +/* The server is now disconnected */ + +struct nxclimsg_disconnected_s +{ + uint32_t msgid; /* NX_CLIMSG_REDRAW_DISCONNECTED */ +}; + +/* This message is received when a requested window has been opened. If wnd is NULL + * then errorcode is the errno value that provides the explanation of the error. + */ + +struct nxclimsg_redraw_s +{ + uint32_t msgid; /* NX_CLIMSG_REDRAW */ + FAR struct nxbe_window_s *wnd; /* The handle to the window to redraw in */ + FAR struct nxgl_rect_s rect; /* The rectangle to be redrawn */ + bool more; /* true: more redraw messages follow */ +}; + +/* This message informs the client of the new size or position of the window */ + +struct nxclimsg_newposition_s +{ + uint32_t msgid; /* NX_CLIMSG_NEWPOSITION */ + FAR struct nxbe_window_s *wnd; /* The window whose position/size has changed */ + FAR struct nxgl_size_s size; /* The current window size */ + FAR struct nxgl_point_s pos; /* The current window position */ + FAR struct nxgl_rect_s bounds; /* Size of screen */ +}; + +/* This message reports a new mouse event to a particular window */ + +#ifdef CONFIG_NX_MOUSE +struct nxclimsg_mousein_s +{ + uint32_t msgid; /* NX_SVRMSG_MOUSEIN */ + FAR struct nxbe_window_s *wnd; /* The handle of window receiving mouse input */ + struct nxgl_point_s pos; /* Mouse X/Y position */ + uint8_t buttons; /* Mouse button set */ +}; +#endif + +/* This message reports a new keypad event to a particular window */ + +#ifdef CONFIG_NX_KBD +struct nxclimsg_kbdin_s +{ + uint32_t msgid; /* NX_CLIMSG_KBDIN */ + FAR struct nxbe_window_s *wnd; /* The handle of window receiving keypad input */ + uint8_t nch; /* Number of characters received */ + uint8_t ch[1]; /* Array of received characters */ +}; +#endif + +/* This messsage confirms that that all queued window messages have been + * flushed and that the all further window messages are blocked. + */ + +struct nxclimsg_blocked_s +{ + uint32_t msgid; /* NX_CLIMSG_BLOCKED */ + FAR struct nxbe_window_s *wnd; /* The window that is blocked */ + FAR void *arg; /* User argument */ +}; + +/* Client-to-Server Message Structures **************************************/ + +/* The generic message structure. All server messages begin with this form. Also + * messages that have no additional data fields use this structure. This includes: + * NX_SVRMSG_CONNECT and NX_SVRMSG_DISCONNECT. + */ + +struct nxsvrmsg_s /* Generic server message */ +{ + uint32_t msgid; /* One of enum nxsvrmsg_e */ + FAR struct nxfe_conn_s *conn; /* The specific connection sending the message */ +}; + +/* This message requests the server to create a new window */ + +struct nxsvrmsg_openwindow_s +{ + uint32_t msgid; /* NX_SVRMSG_OPENWINDOW */ + FAR struct nxbe_window_s *wnd; /* The pre-allocated window structure */ +}; + +/* This message informs the server that client wishes to close a window */ + +struct nxsvrmsg_closewindow_s +{ + uint32_t msgid; /* NX_SVRMSG_CLOSEWINDOW */ + FAR struct nxbe_window_s *wnd; /* The window to be closed */ +}; + +/* This messsage is just a marker that is queued and forwarded by the server + * (NX_CLIMSG_BLOCKED). Messages to the window were blocked just after this + * message was sent. Receipt of this message indicates both that the window + * blocked and that there are no further queued messages for the window. + */ + +struct nxsvrmsg_blocked_s +{ + uint32_t msgid; /* NX_SVRMSG_BLOCKED */ + FAR struct nxbe_window_s *wnd; /* The window that is blocked */ + FAR void *arg; /* User argument */ +}; + +/* This message requests the server to create a new window */ + +struct nxsvrmsg_requestbkgd_s +{ + uint32_t msgid; /* NX_SVRMSG_REQUESTBKGD */ + FAR struct nxfe_conn_s *conn; /* The specific connection sending the message */ + FAR const struct nx_callback_s *cb; /* Event handling callbacks */ + FAR void *arg; /* Client argument used with callbacks */ +}; + +/* This message informs the server that client wishes to close a window */ + +struct nxsvrmsg_releasebkgd_s +{ + uint32_t msgid; /* NX_SVRMSG_RELEASEBKGD */ +}; + +/* This message informs the server that the size or position of the window has changed */ + +struct nxsvrmsg_setposition_s +{ + uint32_t msgid; /* NX_SVRMSG_SETPOSITION */ + FAR struct nxbe_window_s *wnd; /* The window whose position/size has changed */ + FAR struct nxgl_point_s pos; /* The new window position */ +}; + +/* This message informs the server that the size or position of the window has changed */ + +struct nxsvrmsg_setsize_s +{ + uint32_t msgid; /* NX_SVRMSG_SETSIZE */ + FAR struct nxbe_window_s *wnd; /* The window whose position/size has changed */ + FAR struct nxgl_size_s size; /* The new window size */ +}; + +/* This message informs the server that the size or position of the window has changed */ + +struct nxsvrmsg_getposition_s +{ + uint32_t msgid; /* NX_SVRMSG_FETPOSITION */ + FAR struct nxbe_window_s *wnd; /* The window whose position/size has changed */ +}; + +/* This message informs the server to raise this window to the top of the display */ + +struct nxsvrmsg_raise_s +{ + uint32_t msgid; /* NX_SVRMSG_RAISE */ + FAR struct nxbe_window_s *wnd; /* The window to be raised */ +}; + +/* This message informs the server to lower this window to the bottom of the display */ + +struct nxsvrmsg_lower_s +{ + uint32_t msgid; /* NX_SVRMSG_LOWER */ + FAR struct nxbe_window_s *wnd; /* The window to be lowered */ +}; + +/* Set a single pixel in the window with a color */ + +struct nxsvrmsg_setpixel_s +{ + uint32_t msgid; /* NX_SVRMSG_SETPIXEL */ + FAR struct nxbe_window_s *wnd; /* The window to fill */ + struct nxgl_point_s pos; /* The position of the pixel in the window */ + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]; /* Color to use in the fill */ +}; + +/* Fill a rectangle in the window with a color */ + +struct nxsvrmsg_fill_s +{ + uint32_t msgid; /* NX_SVRMSG_FILL */ + FAR struct nxbe_window_s *wnd; /* The window to fill */ + struct nxgl_rect_s rect; /* The rectangle in the window to fill */ + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]; /* Color to use in the fill */ +}; + +/* Get a rectangular region from the the window */ + +struct nxsvrmsg_getrectangle_s +{ + uint32_t msgid; /* NX_SVRMSG_GETRECTANGLE */ + FAR struct nxbe_window_s *wnd; /* The window to get from */ + struct nxgl_rect_s rect; /* The rectangle in the window to get from */ + unsigned int plane; /* The plane number to read */ + FAR uint8_t *dest; /* Memory location in which to store the graphics data */ + unsigned int deststride; /* Width of the destination memory in bytes */ +}; + +/* Fill a trapezoidal region in the window with a color */ + +struct nxsvrmsg_filltrapezoid_s +{ + uint32_t msgid; /* NX_SVRMSG_FILLTRAP */ + FAR struct nxbe_window_s *wnd; /* The window to fill */ + FAR struct nxgl_rect_s clip; /* The clipping window */ + struct nxgl_trapezoid_s trap; /* The trapezoidal region in the window to fill */ + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]; /* Color to use in the fill */ +}; + +/* Move a rectangular region within the window */ + +struct nxsvrmsg_move_s +{ + uint32_t msgid; /* NX_SVRMSG_MOVE */ + FAR struct nxbe_window_s *wnd; /* The window within which the move is done */ + struct nxgl_rect_s rect; /* Describes the rectangular region to move */ + struct nxgl_point_s offset; /* The offset to move the region */ +}; + +/* Copy a rectangular bitmap into the window */ + +struct nxsvrmsg_bitmap_s +{ + uint32_t msgid; /* NX_SVRMSG_BITMAP */ + FAR struct nxbe_window_s *wnd; /* The window with will receive the bitmap image */ + struct nxgl_rect_s dest; /* Destination location of the bitmap in the window */ + FAR const void *src[CONFIG_NX_NPLANES]; /* The start of the source image. */ + struct nxgl_point_s origin; /* Offset into the source image data */ + unsigned int stride; /* The width of the full source image in pixels. */ +}; + +/* Set the color of the background */ + +struct nxsvrmsg_setbgcolor_s +{ + uint32_t msgid; /* NX_SVRMSG_SETBGCOLOR */ + nxgl_mxpixel_t color[CONFIG_NX_NPLANES]; /* Color to use in the background */ +}; + +/* This message reports a new mouse event from a hardware controller attached to + * the server as a regular client (this message may have even been sent from an + * interrupt handler). + */ + +#ifdef CONFIG_NX_MOUSE +struct nxsvrmsg_mousein_s +{ + uint32_t msgid; /* NX_SVRMSG_MOUSEIN */ + struct nxgl_point_s pt; /* Mouse X/Y position */ + uint8_t buttons; /* Mouse button set */ +}; +#endif + +/* This message reports a new keyboard event from a hardware controller attached to + * some kind of keypad (this message may have even been sent from an + * interrupt handler). + */ + +#ifdef CONFIG_NX_KBD +struct nxsvrmsg_kbdin_s +{ + uint32_t msgid; /* NX_SVRMSG_KBDIN */ + uint8_t nch ; /* Number of characters received */ + uint8_t ch[1]; /* Array of received characters */ +}; +#endif + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +#undef EXTERN +#if defined(__cplusplus) +#define EXTERN extern "C" +extern "C" { +#else +#define EXTERN extern +#endif + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxfe_constructwindow + * + * Description: + * This function is the same a nx_openwindow EXCEPT that the client provides + * the window structure instance. nx_constructwindow will initialize the + * the pre-allocated window structure for use by NX. This function is + * provided in addition to nx_open window in order to support a kind of + * inheritance: The caller's window structure may include extensions that + * are not visible to NX. + * + * NOTE: wnd must have been allocated using malloc() (or related allocators) + * Once provided to nxfe_constructwindow() that memory is owned and managed + * by NX. On certain error conditions or when the window is closed, NX will + * free() the window. + * + * Input Parameters: + * handle - The handle returned by nx_connect + * wnd - The pre-allocated window structure. + * cb - Callbacks used to process window events + * arg - User provided value that will be returned with NX callbacks. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately. In the + * case of ERROR, NX will have dealloated the pre-allocated window. + * + ****************************************************************************/ + +EXTERN int nxfe_constructwindow(NXHANDLE handle, + FAR struct nxbe_window_s *wnd, + FAR const struct nx_callback_s *cb, + FAR void *arg); + +/**************************************************************************** + * Name: nxmu_semtake + * + * Description: + * Take the semaphore, handling EINTR wakeups. See the nxmu_semgive macro. + * + * Input Parameters: + * sem - the semaphore to be taken. + * + * Return: + * None + * + ****************************************************************************/ + +EXTERN void nxmu_semtake(sem_t *sem); + +/**************************************************************************** + * Name: nxmu_sendserver + * + * Description: + * Send a message to the server at NX_SVRMSG_PRIO priority + * + * Input Parameters: + * conn - A pointer to the server connection structure + * msg - A pointer to the message to send + * msglen - The length of the message in bytes. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +EXTERN int nxmu_sendserver(FAR struct nxfe_conn_s *conn, + FAR const void *msg, size_t msglen); + +/**************************************************************************** + * Name: nxmu_sendwindow + * + * Description: + * Send a message to the server detined for a specific window at + * NX_SVRMSG_PRIO priority + * + * Input Parameters: + * wnd - A pointer to the back-end window structure + * msg - A pointer to the message to send + * msglen - The length of the message in bytes. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +EXTERN int nxmu_sendwindow(FAR struct nxbe_window_s *wnd, FAR const void *msg, + size_t msglen); + +/**************************************************************************** + * Name: nxmu_sendclient + * + * Description: + * Send a message to the client at NX_CLIMSG_PRIO priority + * + * Input Parameters: + * conn - A pointer to the server connection structure + * msg - A pointer to the message to send + * msglen - The length of the message in bytes. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +EXTERN int nxmu_sendclient(FAR struct nxfe_conn_s *conn, + FAR const void *msg, size_t msglen); + +/**************************************************************************** + * Name: nxmu_openwindow + * + * Description: + * Create a new window. + * + * Input Parameters: + * be - The back-end status structure + * wnd - The pre-allocated window structure to be initialized [IN/OUT] + * + * Return: + * None + * + ****************************************************************************/ + +EXTERN void nxmu_openwindow(FAR struct nxbe_state_s *be, + FAR struct nxbe_window_s *wnd); + +/**************************************************************************** + * Name: nxmu_requestbkgd + * + * Description: + * Perform the server-side operation for the nx_requestbkgd operation: + * Give the client control of the background window connection and receipt + * of all background window callbacks. + * + * conn - The client containing connection information [IN] + * be - The server state structure [IN] + * cb - Callbacks used to process window events + * arg - User provided argument (see nx_openwindow, nx_constructwindow) + * + * Return: + * None + * + ****************************************************************************/ + +EXTERN void nxmu_requestbkgd(FAR struct nxfe_conn_s *conn, + FAR struct nxbe_state_s *be, + FAR const struct nx_callback_s *cb, + FAR void *arg); + +/**************************************************************************** + * Name: nxmu_releasebkgd + * + * Description: + * Release the background window previously acquired using nxmu_openbgwindow + * and return control of the background to NX. + * + * Input Parameters: + * fe - The front-end state structure + * + * Return: + * None + * + ****************************************************************************/ + +EXTERN void nxmu_releasebkgd(FAR struct nxfe_state_s *fe); + +/**************************************************************************** + * Name: nxfe_reportposition + * + * Descripton: + * Report the new size/position of the window. + * + ****************************************************************************/ + +EXTERN void nxfe_reportposition(FAR struct nxbe_window_s *wnd); + +/**************************************************************************** + * Name: nxfe_redrawreq + * + * Descripton: + * Request the client that has this window to redraw the rectangular region. + * + ****************************************************************************/ + +EXTERN void nxfe_redrawreq(FAR struct nxbe_window_s *wnd, + FAR const struct nxgl_rect_s *rect); + +/**************************************************************************** + * Name: nxmu_mouseinit + * + * Description: + * Initialize with the mouse in the center of the display + * + ****************************************************************************/ + +#ifdef CONFIG_NX_MOUSE +EXTERN void nxmu_mouseinit(int x, int y); +#endif + +/**************************************************************************** + * Name: nxmu_mousereport + * + * Description: + * Report mouse position info to the specified window + * + * Input Parameters: + * wnd - The window to receive the mouse report + * + * Returned Value: + * 0: Mouse report sent; >0: Mouse report not sent; <0: An error occurred + * + ****************************************************************************/ + +#ifdef CONFIG_NX_MOUSE +EXTERN int nxmu_mousereport(struct nxbe_window_s *wnd); +#endif + +/**************************************************************************** + * Name: nxmu_mousein + * + * Description: + * New positional data has been received from the thread or interrupt + * handler that manages some kind of pointing hardware. Route that + * positional data to the appropriate window client. + * + ****************************************************************************/ + +#ifdef CONFIG_NX_MOUSE +EXTERN int nxmu_mousein(FAR struct nxfe_state_s *fe, + FAR const struct nxgl_point_s *pos, int button); +#endif + +/**************************************************************************** + * Name: nxmu_kbdin + * + * Descripton: + * New keyboard data has been received from the thread or interrupt + * handler that manages some kind of keyboard/keypad hardware. Route that + * positional data to the appropriate window client. + * + ****************************************************************************/ + +#ifdef CONFIG_NX_KBD +EXTERN void nxmu_kbdin(FAR struct nxfe_state_s *fe, uint8_t nch, FAR uint8_t *ch); +#endif + +#undef EXTERN +#if defined(__cplusplus) +} +#endif + +#endif /* __GRAPHICS_NXMU_NXFE_H */ + diff --git a/nuttx/graphics/nxmu/nxmu_constructwindow.c b/nuttx/graphics/nxmu/nxmu_constructwindow.c new file mode 100644 index 000000000..e5f6dcc9a --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_constructwindow.c @@ -0,0 +1,137 @@ +/**************************************************************************** + * graphics/nxmu/nx_openwindow.c + * + * Copyright (C) 2008, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdlib.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxfe_constructwindow + * + * Description: + * This function is the same a nx_openwindow EXCEPT that the client provides + * the window structure instance. nx_constructwindow will initialize the + * the pre-allocated window structure for use by NX. This function is + * provided in addition to nx_open window in order to support a kind of + * inheritance: The caller's window structure may include extensions that + * are not visible to NX. + * + * NOTE: wnd must have been allocated using malloc() (or related allocators) + * Once provided to nxfe_constructwindow() that memory is owned and managed + * by NX. On certain error conditions or when the window is closed, NX will + * free() the window. + * + * Input Parameters: + * handle - The handle returned by nx_connect + * wnd - The pre-allocated window structure. + * cb - Callbacks used to process window events + * arg - User provided value that will be returned with NX callbacks. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately. In the + * case of ERROR, NX will have dealloated the pre-allocated window. + * + ****************************************************************************/ + +int nxfe_constructwindow(NXHANDLE handle, FAR struct nxbe_window_s *wnd, + FAR const struct nx_callback_s *cb, FAR void *arg) +{ + FAR struct nxfe_conn_s *conn = (FAR struct nxfe_conn_s *)handle; + struct nxsvrmsg_openwindow_s outmsg; + +#ifdef CONFIG_DEBUG + if (!wnd) + { + errno = EINVAL; + return ERROR; + } + + if (!conn || !cb) + { + free(wnd); + errno = EINVAL; + return ERROR; + } +#endif + + /* Setup only the connection structure, callbacks and client private data + * reference. The server will set everything else up. + */ + + wnd->conn = conn; + wnd->cb = cb; + wnd->arg = arg; + + /* Request initialization the new window from the server */ + + outmsg.msgid = NX_SVRMSG_OPENWINDOW; + outmsg.wnd = wnd; + + return nxmu_sendserver(conn, &outmsg, sizeof(struct nxsvrmsg_openwindow_s)); +} + diff --git a/nuttx/graphics/nxmu/nxmu_kbdin.c b/nuttx/graphics/nxmu/nxmu_kbdin.c new file mode 100644 index 000000000..2c658009b --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_kbdin.c @@ -0,0 +1,117 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_kbdin.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <stdlib.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +#ifdef CONFIG_NX_KBD + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmu_kbdin + * + * Descripton: + * New keyboard data has been received from the thread or interrupt + * handler that manages some kind of keyboard/keypad hardware. Route that + * positional data to the appropriate window client. + * + ****************************************************************************/ + +void nxmu_kbdin(FAR struct nxfe_state_s *fe, uint8_t nch, FAR uint8_t *ch) +{ + FAR struct nxclimsg_kbdin_s *outmsg; + int size; + int i; + + /* Allocate a bigger message to account for the variable amount of + * character data. + */ + + size = sizeof(struct nxclimsg_kbdin_s) + nch - 1; + outmsg = (FAR struct nxclimsg_kbdin_s *)malloc(size); + if (outmsg) + { + /* Give the keypad input only to the top child */ + + outmsg->msgid = NX_CLIMSG_KBDIN; + outmsg->wnd = fe->be.topwnd; + outmsg->nch = nch; + + for (i = 0; i < nch; i++) + { + outmsg->ch[i] = ch[i]; + } + + (void)nxmu_sendclient(fe->be.topwnd->conn, outmsg, size); + free(outmsg); + } +} + +#endif /* CONFIG_NX_KBD */ + diff --git a/nuttx/graphics/nxmu/nxmu_mouse.c b/nuttx/graphics/nxmu/nxmu_mouse.c new file mode 100644 index 000000000..3ebe062d2 --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_mouse.c @@ -0,0 +1,215 @@ +/**************************************************************************** + * graphics/nxmu/nxmu__mouse.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nxglib.h> +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +#ifdef CONFIG_NX_MOUSE + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +static struct nxgl_point_s g_mpos; +static struct nxgl_point_s g_mrange; +static uint8_t g_mbutton; + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmu_mouseinit + * + * Description: + * Initialize with the mouse in the center of the display + * + ****************************************************************************/ + +void nxmu_mouseinit(int x, int y) +{ + g_mrange.x = x; + g_mrange.y = y; + g_mpos.x = x / 2; + g_mpos.y = y / 2; + g_mbutton = 0; +} + +/**************************************************************************** + * Name: nxmu_mousereport + * + * Description: + * Report mouse position info to the specified window + * + * Input Parameters: + * wnd - The window to receive the mouse report + * + * Returned Value: + * 0: Mouse report sent; >0: Mouse report not sent; <0: An error occurred + * + ****************************************************************************/ + +int nxmu_mousereport(struct nxbe_window_s *wnd) +{ + struct nxclimsg_mousein_s outmsg; + + /* Does this window support mouse callbacks? */ + + if (wnd->cb->mousein) + { + /* Yes.. Is the mouse position visible in this window? */ + + if (nxbe_visible(wnd, &g_mpos)) + { + /* Yes... Convert the mouse position to window relative + * coordinates and send it to the client + */ + + outmsg.msgid = NX_CLIMSG_MOUSEIN; + outmsg.wnd = wnd; + outmsg.buttons = g_mbutton; + nxgl_vectsubtract(&outmsg.pos, &g_mpos, &wnd->bounds.pt1); + + return nxmu_sendclient(wnd->conn, &outmsg, sizeof(struct nxclimsg_mousein_s)); + } + } + + /* No error occurred, but the mouse report was not sent */ + + return 1; +} + +/**************************************************************************** + * Name: nxmu_mousein + * + * Description: + * New positional data has been received from the thread or interrupt + * handler that manages some kind of pointing hardware. Route that + * positional data to the appropriate window client. + * + ****************************************************************************/ + +int nxmu_mousein(FAR struct nxfe_state_s *fe, + FAR const struct nxgl_point_s *pos, int buttons) +{ + struct nxbe_window_s *wnd; + nxgl_coord_t x = pos->x; + nxgl_coord_t y = pos->y; + int ret; + + /* Clip x and y to within the bounding rectangle */ + + if (x < 0) + { + x = 0; + } + else if (x >= g_mrange.x) + { + x = g_mrange.x - 1; + } + + if (y < 0) + { + y = 0; + } + else if (y >= g_mrange.y) + { + y = g_mrange.y - 1; + } + + /* Look any change in values */ + + if (x != g_mpos.x || y != g_mpos.y || buttons != g_mbutton) + { + /* Update the mouse value */ + + g_mpos.x = x; + g_mpos.y = y; + g_mbutton = buttons; + + /* Pick the window to receive the mouse event. Start with + * the top window and go down. Stop with the first window + * that gets the mouse report + */ + + for (wnd = fe->be.topwnd; wnd; wnd = wnd->below) + { + /* The background window normally has no callback structure + * (unless a client has taken control of the background via + * nx_requestbkgd()). + */ + + if (wnd->cb) + { + ret = nxmu_mousereport(wnd); + if (ret == 0) + { + break; + } + } + } + } + + return OK; +} + +#endif /* CONFIG_NX_MOUSE */ diff --git a/nuttx/graphics/nxmu/nxmu_openwindow.c b/nuttx/graphics/nxmu/nxmu_openwindow.c new file mode 100644 index 000000000..395f0a770 --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_openwindow.c @@ -0,0 +1,113 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_openwindow.c + * + * Copyright (C) 2008-2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmu_openwindow + * + * Description: + * Create a new window. + * + * Input Parameters: + * be - The back-end status structure + * wnd - The pre-allocated window structure to be initialized [IN/OUT] + * + * Return: + * None + * + ****************************************************************************/ + +void nxmu_openwindow(FAR struct nxbe_state_s *be, FAR struct nxbe_window_s *wnd) +{ + /* The window structure was allocated in nx_openwindow and all fields have + * been set to zero cb and conn which were initialized on the client side. + * On the server side, we need only initialize a few more the non zero fields + * and insert the new window at the top of the display. + */ + + wnd->be = be; + + /* Now, insert the new window at the top on the display. topwind is + * never NULL (it may point only at the background window, however) + */ + + wnd->above = NULL; + wnd->below = be->topwnd; + + be->topwnd->above = wnd; + be->topwnd = wnd; + + /* Report the initial size/position of the window to the client */ + + nxfe_reportposition(wnd); + + /* Provide the initial mouse settings to the client */ + +#ifdef CONFIG_NX_MOUSE + nxmu_mousereport(wnd); +#endif +} diff --git a/nuttx/graphics/nxmu/nxmu_redrawreq.c b/nuttx/graphics/nxmu/nxmu_redrawreq.c new file mode 100644 index 000000000..32ca477a2 --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_redrawreq.c @@ -0,0 +1,93 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_redrawreq.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdbool.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxfe_redrawreq + * + * Descripton: + * Request the client that has this window to redraw the rectangular region. + * + ****************************************************************************/ + +void nxfe_redrawreq(FAR struct nxbe_window_s *wnd, FAR const struct nxgl_rect_s *rect) +{ + struct nxclimsg_redraw_s outmsg; + + outmsg.msgid = NX_CLIMSG_REDRAW; + outmsg.wnd = wnd; + outmsg.more = false; + nxgl_rectoffset(&outmsg.rect, rect, -wnd->bounds.pt1.x, -wnd->bounds.pt1.y); + + (void)nxmu_sendclient(wnd->conn, &outmsg, sizeof(struct nxclimsg_redraw_s)); +} + + diff --git a/nuttx/graphics/nxmu/nxmu_releasebkgd.c b/nuttx/graphics/nxmu/nxmu_releasebkgd.c new file mode 100644 index 000000000..4183b223d --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_releasebkgd.c @@ -0,0 +1,110 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_releasebkgd.c + * + * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmu_releasebkgd + * + * Description: + * Release the background window previously acquired using nxmu_openbgwindow + * and return control of the background to NX. + * + * Input Parameters: + * fe - The front-end state structure + * + * Return: + * None + * + ****************************************************************************/ + +void nxmu_releasebkgd(FAR struct nxfe_state_s *fe) +{ + FAR struct nxbe_state_s *be = &fe->be; + +#ifdef CONFIG_DEBUG + if (!fe) + { + return; + } +#endif + + /* Destroy the client window callbacks* and restore the server + * connection. + */ + + be->bkgd.cb = NULL; + be->bkgd.arg = NULL; + be->bkgd.conn = &fe->conn; + + /* Redraw the background window */ + + nxfe_redrawreq(&be->bkgd, &be->bkgd.bounds); +} + diff --git a/nuttx/graphics/nxmu/nxmu_reportposition.c b/nuttx/graphics/nxmu/nxmu_reportposition.c new file mode 100644 index 000000000..f9b5f9daf --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_reportposition.c @@ -0,0 +1,108 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_reportposition.c + * + * Copyright (C) 2008-2009, 2011-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nxglib.h> +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxfe_reportposition + * + * Descripton: + * Report the new size/position of the window. + * + ****************************************************************************/ + +void nxfe_reportposition(FAR struct nxbe_window_s *wnd) +{ + FAR struct nxclimsg_newposition_s outmsg; + int ret; + + /* Send the size/position info */ + + outmsg.msgid = NX_CLIMSG_NEWPOSITION; + outmsg.wnd = wnd; + outmsg.pos.x = wnd->bounds.pt1.x; + outmsg.pos.y = wnd->bounds.pt1.y; + + nxgl_rectsize(&outmsg.size, &wnd->bounds); + + /* Provide the background window bounding box which is the screen limits + * It must always have (0,0) as its origin + */ + + nxgl_rectcopy(&outmsg.bounds, &wnd->be->bkgd.bounds); + + /* And provide this to the client */ + + ret = nxmu_sendclient(wnd->conn, &outmsg, sizeof(struct nxclimsg_newposition_s)); + if (ret < 0) + { + gdbg("nxmu_sendclient failed: %d\n", errno); + } +} diff --git a/nuttx/graphics/nxmu/nxmu_requestbkgd.c b/nuttx/graphics/nxmu/nxmu_requestbkgd.c new file mode 100644 index 000000000..47b1ad13f --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_requestbkgd.c @@ -0,0 +1,124 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_requestbkgd.c + * + * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmu_requestbkgd + * + * Description: + * Perform the server-side operation for the nx_requestbkgd operation: + * Give the client control of the background window connection and receipt + * of all background window callbacks. + * + * conn - The client containing connection information [IN] + * be - The server state structure [IN] + * cb - Callbacks used to process window events + * arg - User provided argument (see nx_openwindow, nx_constructwindow) + * + * Return: + * None + * + ****************************************************************************/ + +void nxmu_requestbkgd(FAR struct nxfe_conn_s *conn, + FAR struct nxbe_state_s *be, + FAR const struct nx_callback_s *cb, + FAR void *arg) +{ +#ifdef CONFIG_DEBUG + if (!conn || !be || !cb) + { + errno = EINVAL; + } +#endif + + /* Set the client's callback vtable and and replace the server + * connection with the clients connection. + */ + + be->bkgd.cb = cb; + be->bkgd.arg = arg; + be->bkgd.conn = conn; + + /* Report the size/position of the background window to the client */ + + nxfe_reportposition((NXWINDOW)&be->bkgd); + + /* Redraw the background window */ + + nxfe_redrawreq(&be->bkgd, &be->bkgd.bounds); + + /* Provide the mouse settings */ + +#ifdef CONFIG_NX_MOUSE + nxmu_mousereport(&be->bkgd); +#endif +} + diff --git a/nuttx/graphics/nxmu/nxmu_semtake.c b/nuttx/graphics/nxmu/nxmu_semtake.c new file mode 100644 index 000000000..164a099b8 --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_semtake.c @@ -0,0 +1,87 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_semtake.c + * + * Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <errno.h> +#include <assert.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmu_semtake + ****************************************************************************/ + +void nxmu_semtake(sem_t *sem) +{ + while (sem_wait(sem) != 0) + { + /* The only case that an error should occur here is if the wait was + * awakened by a signal. + */ + + ASSERT(errno == EINTR); + } +} diff --git a/nuttx/graphics/nxmu/nxmu_sendclient.c b/nuttx/graphics/nxmu/nxmu_sendclient.c new file mode 100644 index 000000000..8b7f12104 --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_sendclient.c @@ -0,0 +1,112 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_sendclient.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <mqueue.h> +#include <errno.h> +#include <debug.h> + +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmu_sendclient + * + * Description: + * Send a message to the client at NX_CLIMSG_PRIO priority + * + * Input Parameters: + * conn - A pointer to the server connection structure + * msg - A pointer to the message to send + * msglen - The length of the message in bytes. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nxmu_sendclient(FAR struct nxfe_conn_s *conn, FAR const void *msg, + size_t msglen) +{ + int ret; + + /* Sanity checking */ + +#ifdef CONFIG_DEBUG + if (!conn || conn->swrmq) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Send the message to the client */ + + ret = mq_send(conn->swrmq, msg, msglen, NX_CLIMSG_PRIO); + if (ret < 0) + { + gdbg("mq_send failed: %d\n", errno); + } + + return ret; +} diff --git a/nuttx/graphics/nxmu/nxmu_sendserver.c b/nuttx/graphics/nxmu/nxmu_sendserver.c new file mode 100644 index 000000000..7007b81da --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_sendserver.c @@ -0,0 +1,112 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_sendserver.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <mqueue.h> +#include <errno.h> +#include <debug.h> + +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmu_sendserver + * + * Description: + * Send a message to the server at NX_SVRMSG_PRIO priority + * + * Input Parameters: + * conn - A pointer to the server connection structure + * msg - A pointer to the message to send + * msglen - The length of the message in bytes. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nxmu_sendserver(FAR struct nxfe_conn_s *conn, FAR const void *msg, + size_t msglen) +{ + int ret; + + /* Sanity checking */ + +#ifdef CONFIG_DEBUG + if (!conn || conn->cwrmq) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Send the message to the server */ + + ret = mq_send(conn->cwrmq, msg, msglen, NX_SVRMSG_PRIO); + if (ret < 0) + { + gdbg("mq_send failed: %d\n", errno); + } + + return ret; +} diff --git a/nuttx/graphics/nxmu/nxmu_sendwindow.c b/nuttx/graphics/nxmu/nxmu_sendwindow.c new file mode 100644 index 000000000..6f64ffff2 --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_sendwindow.c @@ -0,0 +1,114 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_sendserver.c + * + * Copyright (C) 2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <mqueue.h> +#include <errno.h> +#include <debug.h> + +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmu_sendwindow + * + * Description: + * Send a message to the server detined for a specific window at + * NX_SVRMSG_PRIO priority + * + * Input Parameters: + * wnd - A pointer to the back-end window structure + * msg - A pointer to the message to send + * msglen - The length of the message in bytes. + * + * Return: + * OK on success; ERROR on failure with errno set appropriately + * + ****************************************************************************/ + +int nxmu_sendwindow(FAR struct nxbe_window_s *wnd, FAR const void *msg, + size_t msglen) +{ + int ret = OK; + + /* Sanity checking */ + +#ifdef CONFIG_DEBUG + if (!wnd || !wnd->conn) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Ignore messages destined to a blocked window (no errors reported) */ + + if (!NXBE_ISBLOCKED(wnd)) + { + /* Send the message to the server */ + + ret = nxmu_sendserver(wnd->conn, msg, msglen); + } + + return ret; +} diff --git a/nuttx/graphics/nxmu/nxmu_server.c b/nuttx/graphics/nxmu/nxmu_server.c new file mode 100644 index 000000000..2730e0ea2 --- /dev/null +++ b/nuttx/graphics/nxmu/nxmu_server.c @@ -0,0 +1,530 @@ +/**************************************************************************** + * graphics/nxmu/nxmu_server.c + * + * Copyright (C) 2008-2012 Gregory Nutt. All rights reserved. + * Author: Gregory Nutt <gnutt@nuttx.org> + * + * 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 <nuttx/config.h> + +#include <stdint.h> +#include <stdio.h> +#include <string.h> +#include <semaphore.h> +#include <mqueue.h> +#include <fcntl.h> +#include <errno.h> +#include <debug.h> + +#include <nuttx/nx/nx.h> +#include "nxfe.h" + +/**************************************************************************** + * Pre-Processor Definitions + ****************************************************************************/ + +/**************************************************************************** + * Private Types + ****************************************************************************/ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/**************************************************************************** + * Public Data + ****************************************************************************/ + +/**************************************************************************** + * Private Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nxmu_disconnect + ****************************************************************************/ + +static inline void nxmu_disconnect(FAR struct nxfe_conn_s *conn) +{ + struct nxclimsg_disconnected_s outmsg; + int ret; + + /* Send the handshake message back to the client */ + + outmsg.msgid = NX_CLIMSG_DISCONNECTED; + + ret = nxmu_sendclient(conn, &outmsg, sizeof(struct nxclimsg_disconnected_s)); + if (ret < 0) + { + gdbg("nxmu_sendclient failed: %d\n", errno); + } + + /* Close the outgoing client message queue */ + + (void)mq_close(conn->swrmq); +} + +/**************************************************************************** + * Name: nxmu_connect + ****************************************************************************/ + +static inline void nxmu_connect(FAR struct nxfe_conn_s *conn) +{ + char mqname[NX_CLIENT_MXNAMELEN]; + struct nxclimsg_connected_s outmsg; + int ret; + + /* Create the client MQ name */ + + sprintf(mqname, NX_CLIENT_MQNAMEFMT, conn->cid); + + /* Open the client MQ -- this should have already been created by the client */ + + conn->swrmq = mq_open(mqname, O_WRONLY); + if (conn->swrmq == (mqd_t)-1) + { + gdbg("mq_open(%s) failed: %d\n", mqname, errno); + outmsg.msgid = NX_CLIMSG_DISCONNECTED; + } + + /* Send the handshake message back to the client */ + + outmsg.msgid = NX_CLIMSG_CONNECTED; + ret = nxmu_sendclient(conn, &outmsg, sizeof(struct nxclimsg_connected_s)); + if (ret < 0) + { + gdbg("nxmu_sendclient failed: %d\n", errno); + } +} + +/**************************************************************************** + * Name: nxmu_shutdown + ****************************************************************************/ + +static inline void nxmu_shutdown(FAR struct nxfe_state_s *fe) +{ + FAR struct nxbe_window_s *wnd; + + /* Inform all of the clients in the window list that the server is + * exit-ting. Notes: (1) that the following loop will probably attempt to + * disconnect clients multiple times because one client may have multiple + * windows: The first disconnect will fail; subsequent will return errors + * that are ignored. (2) The final window to be disconnected will be the + * background window, thus close all of the servers message queues. + */ + + for (wnd = fe->be.topwnd; wnd; wnd = wnd->below) + { + (void)nxmu_disconnect(wnd->conn); + } +} + +/**************************************************************************** + * Name: nxmu_blocked + ****************************************************************************/ + +static inline void nxmu_blocked(FAR struct nxbe_window_s *wnd, FAR void *arg) +{ + struct nxclimsg_blocked_s outmsg; + int ret; + + outmsg.msgid = NX_CLIMSG_BLOCKED; + outmsg.wnd = wnd; + outmsg.arg = arg; + + ret = nxmu_sendclient(wnd->conn, &outmsg, sizeof(struct nxclimsg_blocked_s)); + if (ret < 0) + { + gdbg("nxmu_sendclient failed: %d\n", errno); + } +} + +/**************************************************************************** + * Name: nxmu_setup + ****************************************************************************/ + +static inline int nxmu_setup(FAR const char *mqname, FAR NX_DRIVERTYPE *dev, + FAR struct nxfe_state_s *fe) +{ + struct mq_attr attr; + int ret; + + memset(fe, 0, sizeof(struct nxfe_state_s)); + + /* Configure the framebuffer/LCD device */ + + ret = nxbe_configure(dev, &fe->be); + if (ret < 0) + { + gdbg("nxbe_configure failed: %d\n", -ret); + errno = -ret; + return ERROR; + } + +#if CONFIG_FB_CMAP + ret = nxbe_colormap(dev); + if (ret < 0) + { + gdbg("nxbe_colormap failed: %d\n", -ret); + errno = -ret; + return ERROR; + } +#endif /* CONFIG_FB_CMAP */ + + /* Initialize the non-NULL elements of the server connection structure. + * Oddly, this strcture represents the connection between the server and + * itself. + * + * Open the incoming server MQ. The server receives messages on the + * background window's incoming message queue. + */ + + attr.mq_maxmsg = CONFIG_NX_MXSERVERMSGS; + attr.mq_msgsize = NX_MXSVRMSGLEN; + attr.mq_flags = 0; + + fe->conn.crdmq = mq_open(mqname, O_RDONLY|O_CREAT, 0666, &attr); + if (fe->conn.crdmq == (mqd_t)-1) + { + gdbg("mq_open(%s) failed: %d\n", mqname, errno); + return ERROR; /* mq_open sets errno */ + } + + /* NOTE that the outgoing client MQ (cwrmq) is not initialized. The + * background window never initiates messages. + */ + + /* Open the outgoing server MQ. This is used to send messages to the + * background window which will, of course, be received and handled by + * the server message loop. + */ + + fe->conn.swrmq = mq_open(mqname, O_WRONLY); + if (fe->conn.swrmq == (mqd_t)-1) + { + gdbg("mq_open(%s) failed: %d\n", mqname, errno); + mq_close(fe->conn.crdmq); + return ERROR; /* mq_open sets errno */ + } + + /* The server is now "connected" to itself via the background window */ + + fe->conn.state = NX_CLISTATE_CONNECTED; + + /* Initialize the non-NULL elements of the background window */ + + fe->be.bkgd.conn = &fe->conn; + fe->be.bkgd.be = (FAR struct nxbe_state_s*)fe; + + fe->be.bkgd.bounds.pt2.x = fe->be.vinfo.xres - 1; + fe->be.bkgd.bounds.pt2.y = fe->be.vinfo.yres - 1; + + /* Complete initialization of the server state structure. The + * window list contains only one element: The background window + * with nothing else above or below it + */ + + fe->be.topwnd = &fe->be.bkgd; + + /* Initialize the mouse position */ + +#ifdef CONFIG_NX_MOUSE + nxmu_mouseinit(fe->be.vinfo.xres, fe->be.vinfo.yres); +#endif + return OK; +} + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: nx_runinstance + * + * Description: + * This is the server entry point. It does not return; the calling thread + * is dedicated to supporting NX server. + * + * NOTE that multiple instances of the NX server may run at the same time, + * each with different callback and message queue names. + * + * Input Parameters: + * mqname - The name for the server incoming message queue + * dev - Vtable "object" of the framebuffer/LCD "driver" to use + * + * Return: + * This function usually does not return. If it does return, it will + * return ERROR and errno will be set appropriately. + * + ****************************************************************************/ + +int nx_runinstance(FAR const char *mqname, FAR NX_DRIVERTYPE *dev) +{ + struct nxfe_state_s fe; + FAR struct nxsvrmsg_s *msg; + uint8_t buffer[NX_MXSVRMSGLEN]; + int nbytes; + int ret; + + /* Initialization *********************************************************/ + + /* Sanity checking */ + +#ifdef CONFIG_DEBUG + if (!mqname || !dev) + { + errno = EINVAL; + return ERROR; + } +#endif + + /* Initialize and configure the server */ + + ret = nxmu_setup(mqname, dev, &fe); + if (ret < 0) + { + return ret; /* nxmu_setup sets errno */ + } + + /* Produce the initial, background display */ + + nxbe_redraw(&fe.be, &fe.be.bkgd, &fe.be.bkgd.bounds); + + /* Message Loop ***********************************************************/ + + /* Then loop forever processing incoming messages */ + + for (;;) + { + /* Receive the next server message */ + + nbytes = mq_receive(fe.conn.crdmq, buffer, NX_MXSVRMSGLEN, 0); + if (nbytes < 0) + { + if (errno != EINTR) + { + gdbg("mq_receive failed: %d\n", errno); + goto errout; /* mq_receive sets errno */ + } + continue; + } + + /* Dispatch the message appropriately */ + + DEBUGASSERT(nbytes >= sizeof(struct nxsvrmsg_s)); + msg = (FAR struct nxsvrmsg_s *)buffer; + + gvdbg("Received opcode=%d nbytes=%d\n", msg->msgid, nbytes); + switch (msg->msgid) + { + /* Messages sent from clients to the NX server *********************/ + + case NX_SVRMSG_CONNECT: /* Establish connection with new NX server client */ + { + FAR struct nxsvrmsg_s *connmsg = (FAR struct nxsvrmsg_s *)buffer; + nxmu_connect(connmsg->conn); + } + break; + + case NX_SVRMSG_DISCONNECT: /* Tear down connection with terminating client */ + { + FAR struct nxsvrmsg_s *disconnmsg = (FAR struct nxsvrmsg_s *)buffer; + nxmu_disconnect(disconnmsg->conn); + } + break; + + case NX_SVRMSG_OPENWINDOW: /* Create a new window */ + { + FAR struct nxsvrmsg_openwindow_s *openmsg = (FAR struct nxsvrmsg_openwindow_s *)buffer; + nxmu_openwindow(&fe.be, openmsg->wnd); + } + break; + + case NX_SVRMSG_CLOSEWINDOW: /* Close an existing window */ + { + FAR struct nxsvrmsg_closewindow_s *closemsg = (FAR struct nxsvrmsg_closewindow_s *)buffer; + nxbe_closewindow(closemsg->wnd); + } + break; + + case NX_SVRMSG_BLOCKED: /* Block messsages to a window */ + { + FAR struct nxsvrmsg_blocked_s *blocked = (FAR struct nxsvrmsg_blocked_s *)buffer; + nxmu_blocked(blocked->wnd, blocked->arg); + } + break; + + case NX_SVRMSG_REQUESTBKGD: /* Give access to the background window */ + { + FAR struct nxsvrmsg_requestbkgd_s *rqbgmsg = (FAR struct nxsvrmsg_requestbkgd_s *)buffer; + nxmu_requestbkgd(rqbgmsg->conn, &fe.be, rqbgmsg->cb, rqbgmsg->arg); + } + break; + + case NX_SVRMSG_RELEASEBKGD: /* End access to the background window */ + { + nxmu_releasebkgd(&fe); + } + break; + + case NX_SVRMSG_SETPOSITION: /* Change window position */ + { + FAR struct nxsvrmsg_setposition_s *setposmsg = (FAR struct nxsvrmsg_setposition_s *)buffer; + nxbe_setposition(setposmsg->wnd, &setposmsg->pos); + } + break; + + case NX_SVRMSG_SETSIZE: /* Change window size */ + { + FAR struct nxsvrmsg_setsize_s *setsizemsg = (FAR struct nxsvrmsg_setsize_s *)buffer; + nxbe_setsize(setsizemsg->wnd, &setsizemsg->size); + } + break; + + case NX_SVRMSG_GETPOSITION: /* Get the window size/position */ + { + FAR struct nxsvrmsg_getposition_s *getposmsg = (FAR struct nxsvrmsg_getposition_s *)buffer; + nxfe_reportposition(getposmsg->wnd); + } + break; + + case NX_SVRMSG_RAISE: /* Move the window to the top of the display */ + { + FAR struct nxsvrmsg_raise_s *raisemsg = (FAR struct nxsvrmsg_raise_s *)buffer; + nxbe_raise(raisemsg->wnd); + } + break; + + case NX_SVRMSG_LOWER: /* Lower the window to the bottom of the display */ + { + FAR struct nxsvrmsg_lower_s *lowermsg = (FAR struct nxsvrmsg_lower_s *)buffer; + nxbe_lower(lowermsg->wnd); + } + break; + + case NX_SVRMSG_SETPIXEL: /* Set a single pixel in the window with a color */ + { + FAR struct nxsvrmsg_setpixel_s *setmsg = (FAR struct nxsvrmsg_setpixel_s *)buffer; + nxbe_setpixel(setmsg->wnd, &setmsg->pos, setmsg->color); + } + break; + + case NX_SVRMSG_FILL: /* Fill a rectangular region in the window with a color */ + { + FAR struct nxsvrmsg_fill_s *fillmsg = (FAR struct nxsvrmsg_fill_s *)buffer; + nxbe_fill(fillmsg->wnd, &fillmsg->rect, fillmsg->color); + } + break; + + case NX_SVRMSG_GETRECTANGLE: /* Get a rectangular region from the window */ + { + FAR struct nxsvrmsg_getrectangle_s *getmsg = (FAR struct nxsvrmsg_getrectangle_s *)buffer; + nxbe_getrectangle(getmsg->wnd, &getmsg->rect, getmsg->plane, getmsg->dest, getmsg->deststride); + } + break; + + case NX_SVRMSG_FILLTRAP: /* Fill a trapezoidal region in the window with a color */ + { + FAR struct nxsvrmsg_filltrapezoid_s *trapmsg = (FAR struct nxsvrmsg_filltrapezoid_s *)buffer; + nxbe_filltrapezoid(trapmsg->wnd, &trapmsg->clip, &trapmsg->trap, trapmsg->color); + } + break; + case NX_SVRMSG_MOVE: /* Move a rectangular region within the window */ + { + FAR struct nxsvrmsg_move_s *movemsg = (FAR struct nxsvrmsg_move_s *)buffer; + nxbe_move(movemsg->wnd, &movemsg->rect, &movemsg->offset); + } + break; + + case NX_SVRMSG_BITMAP: /* Copy a rectangular bitmap into the window */ + { + FAR struct nxsvrmsg_bitmap_s *bmpmsg = (FAR struct nxsvrmsg_bitmap_s *)buffer; + nxbe_bitmap(bmpmsg->wnd, &bmpmsg->dest, bmpmsg->src, &bmpmsg->origin, bmpmsg->stride); + } + break; + + case NX_SVRMSG_SETBGCOLOR: /* Set the color of the background */ + { + FAR struct nxsvrmsg_setbgcolor_s *bgcolormsg = (FAR struct nxsvrmsg_setbgcolor_s *)buffer; + nxgl_colorcopy(fe.be.bgcolor, bgcolormsg->color); + nxbe_fill(&fe.be.bkgd, &fe.be.bkgd.bounds, bgcolormsg->color); + } + break; + +#ifdef CONFIG_NX_MOUSE + case NX_SVRMSG_MOUSEIN: /* New mouse report from mouse client */ + { + FAR struct nxsvrmsg_mousein_s *mousemsg = (FAR struct nxsvrmsg_mousein_s *)buffer; + nxmu_mousein(&fe, &mousemsg->pt, mousemsg->buttons); + } + break; +#endif +#ifdef CONFIG_NX_KBD + case NX_SVRMSG_KBDIN: /* New keyboard report from keyboard client */ + { + FAR struct nxsvrmsg_kbdin_s *kbdmsg = (FAR struct nxsvrmsg_kbdin_s *)buffer; + nxmu_kbdin(&fe, kbdmsg->nch, kbdmsg->ch); + } + break; +#endif + + /* Messages sent to the backgound window ***************************/ + + case NX_CLIMSG_REDRAW: /* Re-draw the background window */ + { + FAR struct nxclimsg_redraw_s *redraw = (FAR struct nxclimsg_redraw_s *)buffer; + DEBUGASSERT(redraw->wnd == &fe.be.bkgd); + gvdbg("Re-draw background rect={(%d,%d),(%d,%d)}\n", + redraw->rect.pt1.x, redraw->rect.pt1.y, + redraw->rect.pt2.x, redraw->rect.pt2.y); + nxbe_fill(&fe.be.bkgd, &redraw->rect, fe.be.bgcolor); + } + break; + + case NX_CLIMSG_MOUSEIN: /* Ignored */ + case NX_CLIMSG_KBDIN: + break; + + case NX_CLIMSG_CONNECTED: /* Shouldn't happen */ + case NX_CLIMSG_DISCONNECTED: + default: + gdbg("Unrecognized command: %d\n", msg->msgid); + break; + } + } + +errout: + nxmu_shutdown(&fe); + return OK; +} |