arch/sim: Drive up_x11update by work to simplify up_idle.

This commit is contained in:
Xiang Xiao
2020-02-10 01:38:45 +08:00
committed by Ouss4
parent 14a82f40d2
commit e6c67bdd78
5 changed files with 81 additions and 107 deletions
+2
View File
@@ -177,6 +177,8 @@ if SIM_FRAMEBUFFER
config SIM_X11FB config SIM_X11FB
bool "Use X11 window" bool "Use X11 window"
default n default n
select SCHED_LPWORK
select SIM_WALLTIME
---help--- ---help---
Use an X11 graphics window to simulate the graphics device" Use an X11 graphics window to simulate the graphics device"
+27 -9
View File
@@ -44,6 +44,8 @@
#include <errno.h> #include <errno.h>
#include <debug.h> #include <debug.h>
#include <nuttx/clock.h>
#include <nuttx/wqueue.h>
#include <nuttx/nx/nx.h> #include <nuttx/nx/nx.h>
#include <nuttx/nx/nxglib.h> #include <nuttx/nx/nxglib.h>
#include <nuttx/video/fb.h> #include <nuttx/video/fb.h>
@@ -144,6 +146,8 @@ static const struct fb_planeinfo_s g_planeinfo =
.bpp = CONFIG_SIM_FBBPP, .bpp = CONFIG_SIM_FBBPP,
}; };
#else #else
static struct work_s g_updatework;
/* This structure describes the single, X11 color plane */ /* This structure describes the single, X11 color plane */
static struct fb_planeinfo_s g_planeinfo; static struct fb_planeinfo_s g_planeinfo;
@@ -179,10 +183,6 @@ struct fb_vtable_s g_fbobject =
#endif #endif
}; };
/****************************************************************************
* Public Data
****************************************************************************/
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
@@ -346,6 +346,18 @@ static int up_setcursor(FAR struct fb_vtable_s *vtable,
} }
#endif #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 * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -368,13 +380,19 @@ static int up_setcursor(FAR struct fb_vtable_s *vtable,
int up_fbinitialize(int display) int up_fbinitialize(int display)
{ {
int ret = OK;
#ifdef CONFIG_SIM_X11FB #ifdef CONFIG_SIM_X11FB
return up_x11initialize(CONFIG_SIM_FBWIDTH, CONFIG_SIM_FBHEIGHT, ret = up_x11initialize(CONFIG_SIM_FBWIDTH, CONFIG_SIM_FBHEIGHT,
&g_planeinfo.fbmem, &g_planeinfo.fblen, &g_planeinfo.fbmem, &g_planeinfo.fblen,
&g_planeinfo.bpp, &g_planeinfo.stride); &g_planeinfo.bpp, &g_planeinfo.stride);
#else if (ret == OK)
return OK; {
work_queue(LPWORK, &g_updatework, up_updatework, NULL, MSEC2TICK(33));
}
#endif #endif
return ret;
} }
/**************************************************************************** /****************************************************************************
+2 -34
View File
@@ -40,9 +40,8 @@
#include <nuttx/config.h> #include <nuttx/config.h>
#include <time.h>
#include <nuttx/arch.h> #include <nuttx/arch.h>
#include <nuttx/power/pm.h>
#include "up_internal.h" #include "up_internal.h"
@@ -52,22 +51,6 @@
#define PM_IDLE_DOMAIN 0 /* Revisit */ #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 * Public Functions
****************************************************************************/ ****************************************************************************/
@@ -142,26 +125,11 @@ void up_idle(void)
} }
#endif #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 /* Wait a bit so that the nxsched_process_timer() is called close to the
* correct rate. * correct rate.
*/ */
up_hostusleep(1000000 / CLK_TCK); 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 #endif
} }
+1 -4
View File
@@ -197,10 +197,6 @@
#ifndef __ASSEMBLY__ #ifndef __ASSEMBLY__
#ifdef CONFIG_SIM_X11FB
extern int g_x11initialized;
#endif
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
/* These spinlocks are used in the SMP configuration in order to implement /* 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 * 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, int up_x11initialize(unsigned short width, unsigned short height,
void **fbmem, size_t *fblen, unsigned char *bpp, void **fbmem, size_t *fblen, unsigned char *bpp,
unsigned short *stride); unsigned short *stride);
void up_x11update(void);
#ifdef CONFIG_FB_CMAP #ifdef CONFIG_FB_CMAP
int up_x11cmap(unsigned short first, unsigned short len, int up_x11cmap(unsigned short first, unsigned short len,
unsigned char *red, unsigned char *green, unsigned char *red, unsigned char *green,
+49 -60
View File
@@ -56,7 +56,6 @@
/* Also used in up_x11eventloop */ /* Also used in up_x11eventloop */
Display *g_display; Display *g_display;
int g_x11initialized;
/**************************************************************************** /****************************************************************************
* Private Data * Private Data
@@ -191,37 +190,33 @@ static int up_x11untraperrors(void)
static void up_x11uninitX(void) static void up_x11uninitX(void)
{ {
if (g_x11initialized)
{
#ifndef CONFIG_SIM_X11NOSHM #ifndef CONFIG_SIM_X11NOSHM
if (g_shmcheckpoint > 4) if (g_shmcheckpoint > 4)
{ {
XShmDetach(g_display, &g_xshminfo); XShmDetach(g_display, &g_xshminfo);
} }
if (g_shmcheckpoint > 3) if (g_shmcheckpoint > 3)
{ {
shmdt(g_xshminfo.shmaddr); shmdt(g_xshminfo.shmaddr);
} }
if (g_shmcheckpoint > 2) if (g_shmcheckpoint > 2)
{ {
shmctl(g_xshminfo.shmid, IPC_RMID, 0); shmctl(g_xshminfo.shmid, IPC_RMID, 0);
} }
#endif #endif
if (g_shmcheckpoint > 1) if (g_shmcheckpoint > 1)
{ {
XDestroyImage(g_image); XDestroyImage(g_image);
} }
/* Un-grab the mouse buttons */ /* Un-grab the mouse buttons */
#if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK) #if defined(CONFIG_SIM_TOUCHSCREEN) || defined(CONFIG_SIM_AJOYSTICK)
XUngrabButton(g_display, Button1, AnyModifier, g_window); XUngrabButton(g_display, Button1, AnyModifier, g_window);
#endif #endif
g_x11initialized = 0;
}
XCloseDisplay(g_display); XCloseDisplay(g_display);
} }
@@ -364,47 +359,41 @@ int up_x11initialize(unsigned short width, unsigned short height,
int depth; int depth;
int ret; int ret;
/* Check if we are already initialized */ /* Save inputs */
if (!g_x11initialized) g_fbpixelwidth = width;
g_fbpixelheight = height;
/* Create the X11 window */
ret = up_x11createframe();
if (ret < 0)
{ {
/* Save inputs */ return ret;
g_fbpixelwidth = width;
g_fbpixelheight = height;
/* Create the X11 window */
ret = up_x11createframe();
if (ret < 0)
{
return ret;
}
/* Determine the supported pixel bpp of the current window */
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.
*/
depth = windowAttributes.depth;
if (depth == 24)
{
depth = 32;
}
*bpp = depth;
*stride = (depth * width / 8);
*fblen = (*stride * height);
/* Map the window to shared memory */
up_x11mapsharedmem(windowAttributes.depth, *fblen);
g_x11initialized = 1;
} }
/* Determine the supported pixel bpp of the current window */
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.
*/
depth = windowAttributes.depth;
if (depth == 24)
{
depth = 32;
}
*bpp = depth;
*stride = (depth * width / 8);
*fblen = (*stride * height);
/* Map the window to shared memory */
up_x11mapsharedmem(windowAttributes.depth, *fblen);
*fbmem = (void *)g_framebuffer; *fbmem = (void *)g_framebuffer;
return 0; return 0;
} }