From 62a47994090860b8daea0ab61121bcbcd4448ff1 Mon Sep 17 00:00:00 2001 From: jianglianfang Date: Thu, 9 Nov 2023 16:12:37 +0800 Subject: [PATCH] video/vnc: add vnc_fb_register To optimize the initialization of vnc, change it to vnc_fb_register. Signed-off-by: jianglianfang --- .../arm/samv7/samv71-xult/src/sam_bringup.c | 12 + boards/sim/sim/sim/src/sim_bringup.c | 12 + drivers/video/fb.c | 48 ---- drivers/video/vnc/vnc_fbdev.c | 244 ++++++++---------- graphics/nxmu/nxmu_start.c | 21 ++ include/nuttx/compiler.h | 6 + include/nuttx/video/fb.h | 28 +- include/nuttx/video/vnc.h | 36 +++ 8 files changed, 224 insertions(+), 183 deletions(-) diff --git a/boards/arm/samv7/samv71-xult/src/sam_bringup.c b/boards/arm/samv7/samv71-xult/src/sam_bringup.c index 9339e54980ff9..dd9f87c388fb3 100644 --- a/boards/arm/samv7/samv71-xult/src/sam_bringup.c +++ b/boards/arm/samv7/samv71-xult/src/sam_bringup.c @@ -61,6 +61,10 @@ # include #endif +#ifdef CONFIG_VNCSERVER +# include +#endif + #if defined(HAVE_RTC_DSXXXX) || defined(HAVE_RTC_PCF85263) # include # include @@ -562,11 +566,19 @@ int sam_bringup(void) #ifdef CONFIG_VIDEO_FB /* Initialize and register the LCD framebuffer driver */ +# ifdef CONFIG_VNCSERVER + ret = vnc_fb_register(0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: vnc_fb_register() failed: %d\n", ret); + } +# else ret = fb_register(0, 0); if (ret < 0) { syslog(LOG_ERR, "ERROR: fb_register() failed: %d\n", ret); } +# endif #endif /* If we got here then perhaps not all initialization was successful, but diff --git a/boards/sim/sim/sim/src/sim_bringup.c b/boards/sim/sim/sim/src/sim_bringup.c index 5bfd71ddd944b..8c7fecbd25915 100644 --- a/boards/sim/sim/sim/src/sim_bringup.c +++ b/boards/sim/sim/sim/src/sim_bringup.c @@ -61,6 +61,10 @@ #include #endif +#ifdef CONFIG_VNCSERVER +# include +#endif + #if defined(CONFIG_INPUT_BUTTONS_LOWER) && defined(CONFIG_SIM_BUTTONS) #include #endif @@ -288,11 +292,19 @@ int sim_bringup(void) #ifdef CONFIG_VIDEO_FB /* Initialize and register the simulated framebuffer driver */ +# ifdef CONFIG_VNCSERVER + ret = vnc_fb_register(0); + if (ret < 0) + { + syslog(LOG_ERR, "ERROR: vnc_fb_register() failed: %d\n", ret); + } +# else ret = fb_register(0, 0); if (ret < 0) { syslog(LOG_ERR, "ERROR: fb_register() failed: %d\n", ret); } +# endif #endif #ifdef CONFIG_SIM_CAMERA diff --git a/drivers/video/fb.c b/drivers/video/fb.c index 5dcb9b41643d5..20ad585e56315 100644 --- a/drivers/video/fb.c +++ b/drivers/video/fb.c @@ -1610,51 +1610,3 @@ int fb_register_device(int display, int plane, kmm_free(fb); return ret; } - -/**************************************************************************** - * Name: fb_register - * - * Description: - * Register the framebuffer character device at /dev/fbN where N is the - * display number if the devices supports only a single plane. If the - * hardware supports multiple color planes, then the device will be - * registered at /dev/fbN.M where N is the again display number but M - * is the display plane. - * - * Input Parameters: - * display - The display number for the case of boards supporting multiple - * displays or for hardware that supports multiple - * layers (each layer is consider a display). Typically zero. - * plane - Identifies the color plane on hardware that supports separate - * framebuffer "planes" for each color component. - * - * Returned Value: - * Zero (OK) is returned success; a negated errno value is returned on any - * failure. - * - ****************************************************************************/ - -int fb_register(int display, int plane) -{ - FAR struct fb_vtable_s *vtable; - int ret; - - /* Initialize the frame buffer device. */ - - ret = up_fbinitialize(display); - if (ret < 0) - { - gerr("ERROR: up_fbinitialize() failed for display %d: %d\n", - display, ret); - return ret; - } - - vtable = up_fbgetvplane(display, plane); - if (vtable == NULL) - { - gerr("ERROR: up_fbgetvplane() failed, vplane=%d\n", plane); - return -EINVAL; - } - - return fb_register_device(display, plane, vtable); -} diff --git a/drivers/video/vnc/vnc_fbdev.c b/drivers/video/vnc/vnc_fbdev.c index 49c2681840472..85d148bf8f5cd 100644 --- a/drivers/video/vnc/vnc_fbdev.c +++ b/drivers/video/vnc/vnc_fbdev.c @@ -581,102 +581,6 @@ static inline int vnc_wait_start(int display) * Public Functions ****************************************************************************/ -/**************************************************************************** - * Name: up_fbinitialize - * - * Description: - * Initialize the framebuffer video hardware associated with the display. - * - * Input Parameters: - * display - In the case of hardware with multiple displays, this - * specifies the display. Normally this is zero. - * - * Returned Value: - * Zero is returned on success; a negated errno value is returned on any - * failure. - * - ****************************************************************************/ - -int up_fbinitialize(int display) -{ - int ret; - FAR struct vnc_session_s *session; -#if defined (CONFIG_VNCSERVER_TOUCH) || defined (CONFIG_VNCSERVER_KBD) - char devname[NAME_MAX]; -#endif - - DEBUGASSERT(display >= 0 && display < RFB_MAX_DISPLAYS); - - /* Start the VNC server kernel thread. */ - - ret = vnc_start_server(display); - - if (ret < 0) - { - gerr("ERROR: vnc_start_server() failed: %d\n", ret); - return ret; - } - - /* Wait for the VNC server to be ready */ - - ret = vnc_wait_start(display); - - if (ret < 0) - { - gerr("ERROR: wait for vnc server start failed: %d\n", ret); - return ret; - } - - /* Save the input callout function information in the session structure. */ - - session = g_vnc_sessions[display]; - session->arg = session; - -#ifdef CONFIG_VNCSERVER_TOUCH - - ret = snprintf(devname, sizeof(devname), - CONFIG_VNCSERVER_TOUCH_DEVNAME "%d", display); - - if (ret < 0) - { - gerr("ERROR: Format vnc touch driver path failed.\n"); - return ret; - } - - ret = vnc_touch_register(devname, session); - - if (ret < 0) - { - gerr("ERROR: Initial vnc touch driver failed.\n"); - return ret; - } - - session->mouseout = vnc_touch_event; -#endif - -#ifdef CONFIG_VNCSERVER_KBD - ret = snprintf(devname, sizeof(devname), - CONFIG_VNCSERVER_KBD_DEVNAME "%d", display); - if (ret < 0) - { - gerr("ERROR: Format vnc keyboard driver path failed.\n"); - return ret; - } - - ret = vnc_kbd_register(devname, session); - - if (ret < 0) - { - gerr("ERROR: Initial vnc keyboard driver failed.\n"); - return ret; - } - - session->kbdout = vnc_kbd_event; -#endif - - return ret; -} - /**************************************************************************** * Name: vnc_fbinitialize * @@ -767,77 +671,149 @@ int vnc_fbinitialize(int display, vnc_kbdout_t kbdout, } /**************************************************************************** - * Name: up_fbgetvplane + * Name: vnc_fb_register * * Description: - * Return a a reference to the framebuffer object for the specified video - * plane of the specified plane. Many OSDs support multiple planes of - * video. + * Register the framebuffer support for the specified display. * * Input Parameters: - * display - In the case of hardware with multiple displays, this - * specifies the display. Normally this is zero. - * vplane - Identifies the plane being queried. + * display - The display number for the case of boards supporting multiple + * displays or for hardware that supports multiple + * layers (each layer is consider a display). Typically zero. * * Returned Value: - * A non-NULL pointer to the frame buffer access structure is returned on - * success; NULL is returned on any failure. + * Zero (OK) is returned success; a negated errno value is returned on any + * failure. * ****************************************************************************/ -FAR struct fb_vtable_s *up_fbgetvplane(int display, int vplane) +int vnc_fb_register(int display) { + FAR struct fb_vtable_s *vtable; FAR struct vnc_session_s *session; FAR struct vnc_fbinfo_s *fbinfo; +#if defined(CONFIG_VNCSERVER_TOUCH) || defined(CONFIG_VNCSERVER_KBD) + char devname[NAME_MAX]; +#endif + int ret; DEBUGASSERT(display >= 0 && display < RFB_MAX_DISPLAYS); - session = g_vnc_sessions[display]; - /* Verify that the session is still valid */ + /* Start the VNC server kernel thread. */ + + ret = vnc_start_server(display); + + if (ret < 0) + { + gerr("ERROR: vnc_start_server() failed: %d\n", ret); + return ret; + } + + /* Wait for the VNC server to be ready */ + + ret = vnc_wait_start(display); - if (session == NULL) + if (ret < 0) { - return NULL; + gerr("ERROR: wait for vnc server start failed: %d\n", ret); + return ret; } - if (vplane == 0) + /* Save the input callout function information in the session structure. */ + + session = g_vnc_sessions[display]; + session->arg = session; + +#ifdef CONFIG_VNCSERVER_TOUCH + ret = snprintf(devname, sizeof(devname), + CONFIG_VNCSERVER_TOUCH_DEVNAME "%d", display); + + if (ret < 0) { - /* Has the framebuffer information been initialized for this display? */ + gerr("ERROR: Format vnc touch driver path failed.\n"); + return ret; + } - fbinfo = &g_fbinfo[display]; - if (!fbinfo->initialized) - { - fbinfo->vtable.getvideoinfo = up_getvideoinfo, - fbinfo->vtable.getplaneinfo = up_getplaneinfo, + ret = vnc_touch_register(devname, session); + + if (ret < 0) + { + gerr("ERROR: Initial vnc touch driver failed.\n"); + return ret; + } + + session->mouseout = vnc_touch_event; +#endif + +#ifdef CONFIG_VNCSERVER_KBD + ret = snprintf(devname, sizeof(devname), + CONFIG_VNCSERVER_KBD_DEVNAME "%d", display); + if (ret < 0) + { + gerr("ERROR: Format vnc keyboard driver path failed.\n"); + return ret; + } + + ret = vnc_kbd_register(devname, session); + if (ret < 0) + { + gerr("ERROR: Initial vnc keyboard driver failed.\n"); + goto err_kbd_register_failed; + } + + session->kbdout = vnc_kbd_event; +#endif + + /* Has the framebuffer information been initialized for this display? */ + + fbinfo = &g_fbinfo[display]; + if (!fbinfo->initialized) + { + fbinfo->vtable.getvideoinfo = up_getvideoinfo, + fbinfo->vtable.getplaneinfo = up_getplaneinfo, #ifdef CONFIG_FB_CMAP - fbinfo->vtable.getcmap = up_getcmap, - fbinfo->vtable.putcmap = up_putcmap, + fbinfo->vtable.getcmap = up_getcmap, + fbinfo->vtable.putcmap = up_putcmap, #endif #ifdef CONFIG_FB_HWCURSOR - fbinfo->vtable.getcursor = up_getcursor, - fbinfo->vtable.setcursor = up_setcursor, + fbinfo->vtable.getcursor = up_getcursor, + fbinfo->vtable.setcursor = up_setcursor, #endif #ifdef CONFIG_FB_SYNC - fbinfo->vtable.waitforvsync = up_waitforsync; + fbinfo->vtable.waitforvsync = up_waitforsync; #endif - fbinfo->vtable.updatearea = up_updateearea, - fbinfo->display = display; - fbinfo->initialized = true; - } - - return &fbinfo->vtable; + fbinfo->vtable.updatearea = up_updateearea, + fbinfo->display = display; + fbinfo->initialized = true; } - else + + vtable = &fbinfo->vtable; + + ret = fb_register_device(display, 0, vtable); + if (ret < 0) { - return NULL; + gerr("ERROR: Initial vnc keyboard driver failed.\n"); + goto err_fb_register_failed; } + + return OK; + +err_fb_register_failed: +#ifdef CONFIG_VNCSERVER_KBD + vnc_kbd_unregister(session, devname); +err_kbd_register_failed: +#endif +#ifdef CONFIG_VNCSERVER_TOUCH + vnc_touch_unregister(session, devname); +#endif + return ret; } /**************************************************************************** - * Name: up_fbuninitialize + * Name: vnc_fb_unregister * * Description: - * Uninitialize the framebuffer support for the specified display. + * Unregister the framebuffer support for the specified display. * * Input Parameters: * display - In the case of hardware with multiple displays, this @@ -848,10 +824,10 @@ FAR struct fb_vtable_s *up_fbgetvplane(int display, int vplane) * ****************************************************************************/ -void up_fbuninitialize(int display) +void vnc_fb_unregister(int display) { FAR struct vnc_session_s *session; -#if defined(CONFIG_VNCSERVER_TOUCH) || defined (CONFIG_VNCSERVER_KBD) +#if defined(CONFIG_VNCSERVER_TOUCH) || defined(CONFIG_VNCSERVER_KBD) int ret; char devname[NAME_MAX]; #endif diff --git a/graphics/nxmu/nxmu_start.c b/graphics/nxmu/nxmu_start.c index 5bf224dc4d0af..d174ad7ecc64c 100644 --- a/graphics/nxmu/nxmu_start.c +++ b/graphics/nxmu/nxmu_start.c @@ -41,6 +41,10 @@ #include "nxmu.h" +#ifdef CONFIG_VNCSERVER +# include +#endif + /**************************************************************************** * Private Data ****************************************************************************/ @@ -108,6 +112,22 @@ static int nx_server(int argc, char *argv[]) dev->setpower(dev, ((3 * CONFIG_LCD_MAXPOWER + 3) / 4)); #else /* CONFIG_NX_LCDDRIVER */ +# ifdef CONFIG_VNCSERVER + /* Initialize the VNC server */ + int display; + + /* Get display parameters from the command line */ + + display = atoi(argv[1]); + + ret = vnc_fb_register(display); + if (ret < 0) + { + gerr("ERROR: vnc_fb_register() failed: %d\n", ret); + } + +# else /* CONFIG_VNCSERVER */ + /* Initialize the frame buffer device. */ int display; @@ -132,6 +152,7 @@ static int nx_server(int argc, char *argv[]) return EXIT_FAILURE; } +# endif /* CONFIG_VNCSERVER */ #endif /* CONFIG_NX_LCDDRIVER */ /* Then start the server (nx_run does not normally return) */ diff --git a/include/nuttx/compiler.h b/include/nuttx/compiler.h index 91cc8ee6defc5..8eeba9bec6d36 100644 --- a/include/nuttx/compiler.h +++ b/include/nuttx/compiler.h @@ -245,6 +245,7 @@ */ # define always_inline_function __attribute__((always_inline,no_instrument_function)) +# define inline_function __attribute__((always_inline)) inline # define noinline_function __attribute__((noinline)) /* The noinstrument_function attribute informs GCC don't instrument it */ @@ -557,6 +558,7 @@ /* SDCC does not support forced inlining. */ # define always_inline_function +# define inline_function inline # define noinline_function # define noinstrument_function # define nooptimiziation_function @@ -701,6 +703,7 @@ # define end_packed_struct # define naked_function # define always_inline_function +# define inline_function inline # define noinline_function # define noinstrument_function # define nooptimiziation_function @@ -813,6 +816,7 @@ # define reentrant_function # define naked_function # define always_inline_function +# define inline_function inline # define noinline_function # define noinstrument_function # define nooptimiziation_function @@ -904,6 +908,7 @@ # define reentrant_function # define naked_function # define always_inline_function +# define inline_function __forceinline # define noinline_function # define noinstrument_function # define nooptimiziation_function @@ -1049,6 +1054,7 @@ # define reentrant_function # define naked_function # define always_inline_function +# define inline_function # define noinline_function # define noinstrument_function # define nooptimiziation_function diff --git a/include/nuttx/video/fb.h b/include/nuttx/video/fb.h index f247f7375244e..9a3c659599884 100644 --- a/include/nuttx/video/fb.h +++ b/include/nuttx/video/fb.h @@ -29,7 +29,10 @@ #include #include +#include +#include +#include #include /**************************************************************************** @@ -1106,7 +1109,30 @@ int fb_register_device(int display, int plane, * ****************************************************************************/ -int fb_register(int display, int plane); +static inline_function unused_code int fb_register(int display, int plane) +{ + FAR struct fb_vtable_s *vtable; + int ret; + + /* Initialize the frame buffer device. */ + + ret = up_fbinitialize(display); + if (ret < 0) + { + gerr("ERROR: up_fbinitialize() failed for display %d: %d\n", + display, ret); + return ret; + } + + vtable = up_fbgetvplane(display, plane); + if (vtable == NULL) + { + gerr("ERROR: up_fbgetvplane() failed, vplane=%d\n", plane); + return -EINVAL; + } + + return fb_register_device(display, plane, vtable); +} #undef EXTERN #ifdef __cplusplus diff --git a/include/nuttx/video/vnc.h b/include/nuttx/video/vnc.h index 94111c3233188..42597f5b7add5 100644 --- a/include/nuttx/video/vnc.h +++ b/include/nuttx/video/vnc.h @@ -114,6 +114,42 @@ extern "C" int vnc_fbinitialize(int display, vnc_kbdout_t kbdout, vnc_mouseout_t mouseout, FAR void *arg); +/**************************************************************************** + * Name: vnc_fb_register + * + * Description: + * Register the framebuffer support for the specified display. + * + * Input Parameters: + * display - The display number for the case of boards supporting multiple + * displays or for hardware that supports multiple + * layers (each layer is consider a display). Typically zero. + * + * Returned Value: + * Zero (OK) is returned success; a negated errno value is returned on any + * failure. + * + ****************************************************************************/ + +int vnc_fb_register(int display); + +/**************************************************************************** + * Name: vnc_fb_unregister + * + * Description: + * Unregister the framebuffer support for the specified display. + * + * Input Parameters: + * display - In the case of hardware with multiple displays, this + * specifies the display. Normally this is zero. + * + * Returned Value: + * None + * + ****************************************************************************/ + +void vnc_fb_unregister(int display); + #undef EXTERN #ifdef __cplusplus }