You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/02/11 20:15:19 UTC
[incubator-nuttx] 02/04: arch/sim: Drive up_x11update by work to
simplify up_idle.
This is an automated email from the ASF dual-hosted git repository.
aguettouche pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit e6c67bdd788406da1da315607fe0e3a1c837ca84
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Feb 10 01:38:45 2020 +0800
arch/sim: Drive up_x11update by work to simplify up_idle.
---
arch/sim/Kconfig | 2 +
arch/sim/src/sim/up_framebuffer.c | 36 ++++++++++----
arch/sim/src/sim/up_idle.c | 36 +-------------
arch/sim/src/sim/up_internal.h | 5 +-
arch/sim/src/sim/up_x11framebuffer.c | 95 ++++++++++++++++--------------------
5 files changed, 74 insertions(+), 100 deletions(-)
diff --git a/arch/sim/Kconfig b/arch/sim/Kconfig
index 62c977a..f85c460 100644
--- a/arch/sim/Kconfig
+++ b/arch/sim/Kconfig
@@ -177,6 +177,8 @@ if SIM_FRAMEBUFFER
config SIM_X11FB
bool "Use X11 window"
default n
+ select SCHED_LPWORK
+ select SIM_WALLTIME
---help---
Use an X11 graphics window to simulate the graphics device"
diff --git a/arch/sim/src/sim/up_framebuffer.c b/arch/sim/src/sim/up_framebuffer.c
index fbccf3f..ab0ffac 100644
--- a/arch/sim/src/sim/up_framebuffer.c
+++ b/arch/sim/src/sim/up_framebuffer.c
@@ -44,6 +44,8 @@
#include <errno.h>
#include <debug.h>
+#include <nuttx/clock.h>
+#include <nuttx/wqueue.h>
#include <nuttx/nx/nx.h>
#include <nuttx/nx/nxglib.h>
#include <nuttx/video/fb.h>
@@ -144,6 +146,8 @@ static const struct fb_planeinfo_s g_planeinfo =
.bpp = CONFIG_SIM_FBBPP,
};
#else
+static struct work_s g_updatework;
+
/* This structure describes the single, X11 color plane */
static struct fb_planeinfo_s g_planeinfo;
@@ -180,10 +184,6 @@ struct fb_vtable_s g_fbobject =
};
/****************************************************************************
- * Public Data
- ****************************************************************************/
-
-/****************************************************************************
* Private Functions
****************************************************************************/
@@ -347,6 +347,18 @@ static int up_setcursor(FAR struct fb_vtable_s *vtable,
#endif
/****************************************************************************
+ * Name: up_updatework
+ ****************************************************************************/
+
+#ifdef CONFIG_SIM_X11FB
+static void up_updatework(FAR void *arg)
+{
+ work_queue(LPWORK, &g_updatework, up_updatework, NULL, MSEC2TICK(33));
+ up_x11update();
+}
+#endif
+
+/****************************************************************************
* Public Functions
****************************************************************************/
@@ -368,13 +380,19 @@ static int up_setcursor(FAR struct fb_vtable_s *vtable,
int up_fbinitialize(int display)
{
+ int ret = OK;
+
#ifdef CONFIG_SIM_X11FB
- return up_x11initialize(CONFIG_SIM_FBWIDTH, CONFIG_SIM_FBHEIGHT,
- &g_planeinfo.fbmem, &g_planeinfo.fblen,
- &g_planeinfo.bpp, &g_planeinfo.stride);
-#else
- return OK;
+ ret = up_x11initialize(CONFIG_SIM_FBWIDTH, CONFIG_SIM_FBHEIGHT,
+ &g_planeinfo.fbmem, &g_planeinfo.fblen,
+ &g_planeinfo.bpp, &g_planeinfo.stride);
+ if (ret == OK)
+ {
+ work_queue(LPWORK, &g_updatework, up_updatework, NULL, MSEC2TICK(33));
+ }
#endif
+
+ return ret;
}
/****************************************************************************
diff --git a/arch/sim/src/sim/up_idle.c b/arch/sim/src/sim/up_idle.c
index a8d3862..0aae79b 100644
--- a/arch/sim/src/sim/up_idle.c
+++ b/arch/sim/src/sim/up_idle.c
@@ -40,9 +40,8 @@
#include <nuttx/config.h>
-#include <time.h>
-
#include <nuttx/arch.h>
+#include <nuttx/power/pm.h>
#include "up_internal.h"
@@ -53,22 +52,6 @@
#define PM_IDLE_DOMAIN 0 /* Revisit */
/****************************************************************************
- * Private Data
- ****************************************************************************/
-
-#ifdef CONFIG_SIM_X11FB
-static int g_x11refresh = 0;
-#endif
-
-/****************************************************************************
- * Public Function Prototypes
- ****************************************************************************/
-
-#ifdef CONFIG_SIM_X11FB
-extern void up_x11update(void);
-#endif
-
-/****************************************************************************
* Public Functions
****************************************************************************/
@@ -142,26 +125,11 @@ void up_idle(void)
}
#endif
-#if defined(CONFIG_SIM_WALLTIME) || defined(CONFIG_SIM_X11FB)
+#ifdef CONFIG_SIM_WALLTIME
/* Wait a bit so that the nxsched_process_timer() is called close to the
* correct rate.
*/
up_hostusleep(1000000 / CLK_TCK);
-
- /* Handle X11-related events */
-
-#ifdef CONFIG_SIM_X11FB
- if (g_x11initialized)
- {
- /* Update the display periodically */
-
- g_x11refresh += 1000000 / CLK_TCK;
- if (g_x11refresh > 500000)
- {
- up_x11update();
- }
- }
-#endif
#endif
}
diff --git a/arch/sim/src/sim/up_internal.h b/arch/sim/src/sim/up_internal.h
index b536c78..e0b2f91 100644
--- a/arch/sim/src/sim/up_internal.h
+++ b/arch/sim/src/sim/up_internal.h
@@ -197,10 +197,6 @@
#ifndef __ASSEMBLY__
-#ifdef CONFIG_SIM_X11FB
-extern int g_x11initialized;
-#endif
-
#ifdef CONFIG_SMP
/* These spinlocks are used in the SMP configuration in order to implement
* up_cpu_pause(). The protocol for CPUn to pause CPUm is as follows
@@ -288,6 +284,7 @@ unsigned long up_getwalltime(void);
int up_x11initialize(unsigned short width, unsigned short height,
void **fbmem, size_t *fblen, unsigned char *bpp,
unsigned short *stride);
+void up_x11update(void);
#ifdef CONFIG_FB_CMAP
int up_x11cmap(unsigned short first, unsigned short len,
unsigned char *red, unsigned char *green,
diff --git a/arch/sim/src/sim/up_x11framebuffer.c b/arch/sim/src/sim/up_x11framebuffer.c
index 8704a85..2cd767b 100644
--- a/arch/sim/src/sim/up_x11framebuffer.c
+++ b/arch/sim/src/sim/up_x11framebuffer.c
@@ -56,7 +56,6 @@
/* Also used in up_x11eventloop */
Display *g_display;
-int g_x11initialized;
/****************************************************************************
* Private Data
@@ -191,37 +190,33 @@ static int up_x11untraperrors(void)
static void up_x11uninitX(void)
{
- if (g_x11initialized)
- {
#ifndef CONFIG_SIM_X11NOSHM
- if (g_shmcheckpoint > 4)
- {
- XShmDetach(g_display, &g_xshminfo);
- }
+ if (g_shmcheckpoint > 4)
+ {
+ XShmDetach(g_display, &g_xshminfo);
+ }
- if (g_shmcheckpoint > 3)
- {
- shmdt(g_xshminfo.shmaddr);
- }
+ if (g_shmcheckpoint > 3)
+ {
+ shmdt(g_xshminfo.shmaddr);
+ }
- if (g_shmcheckpoint > 2)
- {
- shmctl(g_xshminfo.shmid, IPC_RMID, 0);
- }
+ if (g_shmcheckpoint > 2)
+ {
+ shmctl(g_xshminfo.shmid, IPC_RMID, 0);
+ }
#endif
- if (g_shmcheckpoint > 1)
- {
- XDestroyImage(g_image);
- }
+ if (g_shmcheckpoint > 1)
+ {
+ XDestroyImage(g_image);
+ }
- /* Un-grab the mouse buttons */
+ /* Un-grab the mouse buttons */
#if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK)
- XUngrabButton(g_display, Button1, AnyModifier, g_window);
+ XUngrabButton(g_display, Button1, AnyModifier, g_window);
#endif
- g_x11initialized = 0;
- }
XCloseDisplay(g_display);
}
@@ -364,46 +359,40 @@ int up_x11initialize(unsigned short width, unsigned short height,
int depth;
int ret;
- /* Check if we are already initialized */
-
- if (!g_x11initialized)
- {
- /* Save inputs */
+ /* Save inputs */
- g_fbpixelwidth = width;
- g_fbpixelheight = height;
+ g_fbpixelwidth = width;
+ g_fbpixelheight = height;
- /* Create the X11 window */
+ /* Create the X11 window */
- ret = up_x11createframe();
- if (ret < 0)
- {
- return ret;
- }
+ ret = up_x11createframe();
+ if (ret < 0)
+ {
+ return ret;
+ }
- /* Determine the supported pixel bpp of the current window */
+ /* Determine the supported pixel bpp of the current window */
- XGetWindowAttributes(g_display, DefaultRootWindow(g_display), &windowAttributes);
+ XGetWindowAttributes(g_display, DefaultRootWindow(g_display), &windowAttributes);
- /* Get the pixel depth. If the depth is 24-bits, use 32 because X expects
- * 32-bit aligment anyway.
- */
+ /* Get the pixel depth. If the depth is 24-bits, use 32 because X expects
+ * 32-bit aligment anyway.
+ */
- depth = windowAttributes.depth;
- if (depth == 24)
- {
- depth = 32;
- }
+ depth = windowAttributes.depth;
+ if (depth == 24)
+ {
+ depth = 32;
+ }
- *bpp = depth;
- *stride = (depth * width / 8);
- *fblen = (*stride * height);
+ *bpp = depth;
+ *stride = (depth * width / 8);
+ *fblen = (*stride * height);
- /* Map the window to shared memory */
+ /* Map the window to shared memory */
- up_x11mapsharedmem(windowAttributes.depth, *fblen);
- g_x11initialized = 1;
- }
+ up_x11mapsharedmem(windowAttributes.depth, *fblen);
*fbmem = (void *)g_framebuffer;
return 0;