diff --git a/arch/sim/Kconfig b/arch/sim/Kconfig index 62c977a166..f85c460d58 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 fbccf3f830..ab0ffac9b2 100644 --- a/arch/sim/src/sim/up_framebuffer.c +++ b/arch/sim/src/sim/up_framebuffer.c @@ -44,6 +44,8 @@ #include #include +#include +#include #include #include #include @@ -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; @@ -179,10 +183,6 @@ struct fb_vtable_s g_fbobject = #endif }; -/**************************************************************************** - * Public Data - ****************************************************************************/ - /**************************************************************************** * Private Functions ****************************************************************************/ @@ -346,6 +346,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 a8d38621d8..0aae79b1fd 100644 --- a/arch/sim/src/sim/up_idle.c +++ b/arch/sim/src/sim/up_idle.c @@ -40,9 +40,8 @@ #include -#include - #include +#include #include "up_internal.h" @@ -52,22 +51,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 b536c7867c..e0b2f91064 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 8704a85d8d..2cd767ba15 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,47 +359,41 @@ int up_x11initialize(unsigned short width, unsigned short height, int depth; 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 */ - - 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; + 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); + *fbmem = (void *)g_framebuffer; return 0; }