video/vnc: add vnc_fb_register

To optimize the initialization of vnc, change it to vnc_fb_register.

Signed-off-by: jianglianfang <jianglianfang@xiaomi.com>
This commit is contained in:
jianglianfang 2023-11-09 16:12:37 +08:00 committed by Xiang Xiao
parent 82acf6e6a7
commit 62a4799409
8 changed files with 225 additions and 184 deletions

View File

@ -61,6 +61,10 @@
# include <nuttx/leds/userled.h>
#endif
#ifdef CONFIG_VNCSERVER
# include <nuttx/video/vnc.h>
#endif
#if defined(HAVE_RTC_DSXXXX) || defined(HAVE_RTC_PCF85263)
# include <nuttx/clock.h>
# include <nuttx/i2c/i2c_master.h>
@ -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

View File

@ -61,6 +61,10 @@
#include <nuttx/lcd/lcd_dev.h>
#endif
#ifdef CONFIG_VNCSERVER
# include <nuttx/video/vnc.h>
#endif
#if defined(CONFIG_INPUT_BUTTONS_LOWER) && defined(CONFIG_SIM_BUTTONS)
#include <nuttx/input/buttons.h>
#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

View File

@ -1610,51 +1610,3 @@ errout_with_fb:
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);
}

View File

@ -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. */
if (session == NULL)
ret = vnc_start_server(display);
if (ret < 0)
{
return NULL;
gerr("ERROR: vnc_start_server() failed: %d\n", ret);
return ret;
}
if (vplane == 0)
{
/* Has the framebuffer information been initialized for this display? */
/* Wait for the VNC server to be ready */
fbinfo = &g_fbinfo[display];
if (!fbinfo->initialized)
{
fbinfo->vtable.getvideoinfo = up_getvideoinfo,
fbinfo->vtable.getplaneinfo = up_getplaneinfo,
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");
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;
}
fbinfo->vtable.updatearea = up_updateearea,
fbinfo->display = display;
fbinfo->initialized = true;
}
return &fbinfo->vtable;
}
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

View File

@ -41,6 +41,10 @@
#include "nxmu.h"
#ifdef CONFIG_VNCSERVER
# include <nuttx/video/vnc.h>
#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) */

View File

@ -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

View File

@ -29,7 +29,10 @@
#include <sys/types.h>
#include <stdint.h>
#include <errno.h>
#include <debug.h>
#include <nuttx/compiler.h>
#include <nuttx/fs/ioctl.h>
/****************************************************************************
@ -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

View File

@ -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
}