graphics/traveler: Conver to use the framebuffer driver.
This commit is contained in:
parent
90d4cf6ede
commit
4bff47a80f
@ -349,7 +349,7 @@ int fb_main(int argc, char *argv[])
|
||||
printf(" bpp: %u\n", state.pinfo.bpp);
|
||||
|
||||
/* Only these pixel depths are supported. viinfo.fmt is ignored, only
|
||||
* certain color formations are supported.
|
||||
* certain color formats are supported.
|
||||
*/
|
||||
|
||||
if (state.pinfo.bpp != 32 && state.pinfo.bpp != 16 &&
|
||||
|
@ -233,9 +233,7 @@ int nxhello_main(int argc, char *argv[])
|
||||
goto errout_with_nx;
|
||||
}
|
||||
|
||||
/* Wait until we have the screen resolution. We'll have this immediately
|
||||
* unless we are dealing with the NX server.
|
||||
*/
|
||||
/* Wait until we have the screen resolution. */
|
||||
|
||||
while (!g_nxhello.havepos)
|
||||
{
|
||||
|
@ -230,14 +230,13 @@ int nximage_main(int argc, char *argv[])
|
||||
goto errout_with_nx;
|
||||
}
|
||||
|
||||
/* Wait until we have the screen resolution. We'll have this immediately
|
||||
* unless we are dealing with the NX server.
|
||||
*/
|
||||
/* Wait until we have the screen resolution. */
|
||||
|
||||
while (!g_nximage.havepos)
|
||||
{
|
||||
(void)sem_wait(&g_nximage.eventsem);
|
||||
}
|
||||
|
||||
printf("nximage_main: Screen resolution (%d,%d)\n", g_nximage.xres, g_nximage.yres);
|
||||
|
||||
/* Now, put up the NuttX logo and wait a bit so that it visible. */
|
||||
|
@ -248,9 +248,7 @@ int nxlines_main(int argc, char *argv[])
|
||||
goto errout_with_nx;
|
||||
}
|
||||
|
||||
/* Wait until we have the screen resolution. We'll have this immediately
|
||||
* unless we are dealing with the NX server.
|
||||
*/
|
||||
/* Wait until we have the screen resolution. */
|
||||
|
||||
while (!g_nxlines.havepos)
|
||||
{
|
||||
|
@ -299,9 +299,7 @@ int nxterm_main(int argc, char **argv)
|
||||
}
|
||||
printf("nxterm_main: hwnd=%p\n", g_nxterm_vars.hwnd);
|
||||
|
||||
/* Wait until we have the screen resolution. We'll have this immediately
|
||||
* unless we are dealing with the NX server.
|
||||
*/
|
||||
/* Wait until we have the screen resolution. */
|
||||
|
||||
while (!g_nxterm_vars.haveres)
|
||||
{
|
||||
|
@ -327,9 +327,7 @@ int nxtext_main(int argc, char **argv)
|
||||
goto errout_with_nx;
|
||||
}
|
||||
|
||||
/* Wait until we have the screen resolution. We'll have this immediately
|
||||
* unless we are dealing with the NX server.
|
||||
*/
|
||||
/* Wait until we have the screen resolution. */
|
||||
|
||||
while (!b_haveresolution)
|
||||
{
|
||||
|
@ -6,12 +6,38 @@
|
||||
config GRAPHICS_TRAVELER
|
||||
bool "Traveler game"
|
||||
default n
|
||||
depends on NX || VIDEO_FB
|
||||
select FSUTILS_INIFILE
|
||||
---help---
|
||||
Enable or disable the graphic Traveler game
|
||||
|
||||
if GRAPHICS_TRAVELER
|
||||
|
||||
choice
|
||||
prompt "Video interface"
|
||||
default GRAPHICS_TRAVELER_FB if VIDEO_FB
|
||||
default GRAPHICS_TRAVELER_NX if !VIDEO_FB
|
||||
|
||||
config GRAPHICS_TRAVELER_FB
|
||||
bool "Framebuffer Driver"
|
||||
depends on VIDEO_FB
|
||||
|
||||
config GRAPHICS_TRAVELER_NX
|
||||
bool "NX Graphics"
|
||||
depends on NX
|
||||
|
||||
endchoice # Video interface
|
||||
|
||||
if GRAPHICS_TRAVELER_FB
|
||||
|
||||
config GRAPHICS_TRAVELER_FBDEV
|
||||
string "Framebuffer Device"
|
||||
default "/dev/fb0"
|
||||
|
||||
endif # GRAPHICS_TRAVELER_FB
|
||||
|
||||
if GRAPHICS_TRAVELER_NX
|
||||
|
||||
comment "NX Server Configuration Options"
|
||||
|
||||
config GRAPHICS_TRAVELER_STACKSIZE
|
||||
@ -32,6 +58,8 @@ config GRAPHICS_TRAVELER_CLIENTPRIO
|
||||
---help---
|
||||
The client priority. Default: 100
|
||||
|
||||
endif # GRAPHICS_TRAVELER_NX
|
||||
|
||||
comment "Color configuration"
|
||||
|
||||
choice
|
||||
@ -94,7 +122,7 @@ choice
|
||||
prompt "Input device"
|
||||
default GRAPHICS_TRAVELER_AJOYSTICK if AJOYSTICK
|
||||
default GRAPHICS_TRAVELER_DJOYSTICK if DJOYSTICK && !AJOYSTICK
|
||||
default GRAPHICS_TRAVELER_NX_XYINPUT if NX_XYINPUT && !AJOYSTICK && !DJOYSTICK
|
||||
default GRAPHICS_TRAVELER_NX_XYINPUT if GRAPHICS_TRAVELER_NX && NX_XYINPUT && !AJOYSTICK && !DJOYSTICK
|
||||
|
||||
config GRAPHICS_TRAVELER_AJOYSTICK
|
||||
bool "Analog joystick"
|
||||
@ -108,7 +136,7 @@ config GRAPHICS_TRAVELER_DJOYSTICK
|
||||
|
||||
config GRAPHICS_TRAVELER_NX_XYINPUT
|
||||
bool "NX X/Y input"
|
||||
depends on NX_XYINPUT
|
||||
depends on GRAPHICS_TRAVELER_NX && NX_XYINPUT
|
||||
|
||||
endchoice # Input device
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
############################################################################
|
||||
# apps/graphics/traveler/Makefile
|
||||
#
|
||||
# Copyright (C) 2014, 2016 Gregory Nutt. All rights reserved.
|
||||
# Copyright (C) 2014, 2016-2017 Gregory Nutt. All rights reserved.
|
||||
# Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
#
|
||||
# Redistribution and use in source and binary forms, with or without
|
||||
@ -67,7 +67,7 @@ endif
|
||||
|
||||
MAINSRC = trv_main.c
|
||||
|
||||
ifeq ($(CONFIG_NX),y)
|
||||
ifeq ($(CONFIG_GRAPHICS_TRAVELER_NX),y)
|
||||
CSRCS += trv_nxbkgd.c trv_nxlistener.c
|
||||
endif
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
/****************************************************************************
|
||||
* apps/graphics/traveler/include/trv_graphics.h
|
||||
*
|
||||
* Copyright (C) 2014 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014, 2017 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@ -44,7 +44,7 @@
|
||||
#include <semaphore.h>
|
||||
|
||||
#include <nuttx/video/fb.h>
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
# include <nuttx/nx/nx.h>
|
||||
#endif
|
||||
|
||||
@ -83,10 +83,11 @@ struct trv_palette_s
|
||||
|
||||
struct trv_graphics_info_s
|
||||
{
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
NXHANDLE hnx; /* The connection handle */
|
||||
NXHANDLE bgwnd; /* Background window handle */
|
||||
#else
|
||||
int fb; /* Framebuffer device file descriptor */
|
||||
trv_coord_t xoffset; /* Horizontal offset to start of data (pixels) */
|
||||
trv_coord_t yoffset; /* Vertical offset to start of data (rows) */
|
||||
trv_coord_t stride; /* Length of a line (bytes) */
|
||||
@ -105,7 +106,7 @@ struct trv_graphics_info_s
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
extern FAR const struct nx_callback_s *g_trv_nxcallback;
|
||||
extern sem_t g_trv_nxevent;
|
||||
extern volatile bool g_trv_nxresolution;
|
||||
|
@ -46,9 +46,18 @@
|
||||
#include "trv_graphics.h"
|
||||
|
||||
#include <sys/boardctl.h>
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_FB
|
||||
# include <sys/ioctl.h>
|
||||
# include <sys/mman.h>
|
||||
# include <fcntl.h>
|
||||
# include <errno.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_FB
|
||||
# include <nuttx/video/fb.h>
|
||||
#endif
|
||||
#ifdef CONFIG_VNCSERVER
|
||||
# include <nuttx/video/vnc.h>
|
||||
#endif
|
||||
@ -57,7 +66,7 @@
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
FAR const struct nx_callback_s *g_trv_nxcallback;
|
||||
sem_t g_trv_nxevent = SEM_INITIZIALIZER(0);
|
||||
bool g_trv_nxresolution = false;
|
||||
@ -76,7 +85,7 @@ bool g_trv_nxrconnected = false;
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
static void trv_use_bgwindow(FAR struct trv_graphics_info_s *ginfo)
|
||||
{
|
||||
/* Get the background window */
|
||||
@ -98,42 +107,6 @@ static void trv_use_bgwindow(FAR struct trv_graphics_info_s *ginfo)
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: trv_get_fbdev
|
||||
*
|
||||
* Description:
|
||||
* Get the system framebuffer device
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NX
|
||||
static FAR struct fb_vtable_s *trv_get_fbdev(void)
|
||||
{
|
||||
FAR struct fb_vtable_s *fbdev;
|
||||
int ret;
|
||||
|
||||
/* Initialize the frame buffer device */
|
||||
|
||||
ret = up_fbinitialize(0);
|
||||
if (ret < 0)
|
||||
{
|
||||
trv_abort("ERROR: up_fbinitialize() failed: %d\n", -ret);
|
||||
}
|
||||
|
||||
/* Set up to use video plane 0. There is no support for anything but
|
||||
* video plane 0.
|
||||
*/
|
||||
|
||||
fbdev = up_fbgetvplane(0,0);
|
||||
if (!fbdev)
|
||||
{
|
||||
trv_abort("ERROR: up_fbgetvplane() failed\n");
|
||||
}
|
||||
|
||||
return fbdev;
|
||||
}
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: trv_fb_initialize
|
||||
*
|
||||
@ -142,41 +115,84 @@ static FAR struct fb_vtable_s *trv_get_fbdev(void)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_FB
|
||||
static void trv_fb_initialize(FAR struct trv_graphics_info_s *ginfo)
|
||||
{
|
||||
struct fb_videoinfo_s vinfo;
|
||||
struct fb_planeinfo_s pinfo;
|
||||
FAR struct fb_vtable_s *fbdev;
|
||||
int ret;
|
||||
|
||||
/* Get the framebuffer device */
|
||||
/* Open the framebuffer driver */
|
||||
|
||||
fbdev = trv_get_fbdev();
|
||||
ginfo->fb = open(CONFIG_GRAPHICS_TRAVELER_FBDEV, O_RDWR);
|
||||
if (ginfo->fb < 0)
|
||||
{
|
||||
int errcode = errno;
|
||||
trv_abort("ERROR: Failed to open %s: %d\n",
|
||||
CONFIG_GRAPHICS_TRAVELER_FBDEV, errcode);
|
||||
}
|
||||
|
||||
/* Get information about video plane 0 */
|
||||
/* Get the characteristics of the framebuffer */
|
||||
|
||||
ret = fbdev->getvideoinfo(fbdev, &vinfo);
|
||||
ret = ioctl(ginfo->fb, FBIOGET_VIDEOINFO,
|
||||
(unsigned long)((uintptr_t)&vinfo));
|
||||
if (ret < 0)
|
||||
{
|
||||
trv_abort("ERROR: getvideoinfo() failed\n");
|
||||
int errcode = errno;
|
||||
close(ginfo->fb);
|
||||
|
||||
trv_abort("ERROR: ioctl(FBIOGET_VIDEOINFO) failed: %d\n",
|
||||
errcode);
|
||||
}
|
||||
|
||||
if (vinfo.fmt != TRV_COLOR_FMT)
|
||||
{
|
||||
close(ginfo->fb);
|
||||
trv_abort("ERROR: Bad color format %u; supported format %u\n",
|
||||
vinfo.fmt, TRV_COLOR_FMT);
|
||||
}
|
||||
|
||||
ginfo->xres = vinfo.xres;
|
||||
ginfo->yres = vinfo.yres;
|
||||
|
||||
ret = fbdev->getplaneinfo(fbdev, 0, &pinfo);
|
||||
ret = ioctl(ginfo->fb, FBIOGET_PLANEINFO,
|
||||
(unsigned long)((uintptr_t)&pinfo));
|
||||
if (ret < 0)
|
||||
{
|
||||
trv_abort("ERROR: getplaneinfo() failed\n");
|
||||
int errcode = errno;
|
||||
close(ginfo->fb);
|
||||
|
||||
trv_abort("ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n",
|
||||
errcode);
|
||||
}
|
||||
|
||||
if (pinfo.bpp != TRV_BPP)
|
||||
{
|
||||
close(ginfo->fb);
|
||||
trv_abort("ERROR: Bad pixel depth %u BPP; supported %u BPP\n",
|
||||
pinfo.bpp, TRV_BPP);
|
||||
}
|
||||
|
||||
ginfo->stride = pinfo.stride;
|
||||
ginfo->hwbuffer = pinfo.fbmem;
|
||||
|
||||
if (vinfo.fmt != TRV_COLOR_FMT || pinfo.bpp != TRV_BPP)
|
||||
/* mmap() the framebuffer.
|
||||
*
|
||||
* NOTE: In the FLAT build the frame buffer address returned by the
|
||||
* FBIOGET_PLANEINFO IOCTL command will be the same as the framebuffer
|
||||
* address. mmap(), however, is the preferred way to get the framebuffer
|
||||
* address because in the KERNEL build, it will perform the necessary
|
||||
* address mapping to make the memory accessible to the application.
|
||||
*/
|
||||
|
||||
ginfo->hwbuffer = mmap(NULL, pinfo.fblen, PROT_READ|PROT_WRITE,
|
||||
MAP_SHARED|MAP_FILE, ginfo->fb, 0);
|
||||
if (ginfo->hwbuffer == MAP_FAILED)
|
||||
{
|
||||
trv_abort("ERROR: Bad color format(%d)/bpp(%d)\n", vinfo.fmt, pinfo.bpp);
|
||||
int errcode = errno;
|
||||
close(ginfo->fb);
|
||||
|
||||
trv_abort("ERROR: ioctl(FBIOGET_PLANEINFO) failed: %d\n",
|
||||
errcode);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -185,7 +201,7 @@ static void trv_fb_initialize(FAR struct trv_graphics_info_s *ginfo)
|
||||
* Name: trv_nx_initialize
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
static inline int trv_nx_initialize(FAR struct trv_graphics_info_s *ginfo)
|
||||
{
|
||||
struct sched_param param;
|
||||
@ -268,7 +284,7 @@ static inline int trv_nx_initialize(FAR struct trv_graphics_info_s *ginfo)
|
||||
|
||||
trv_use_bgwindow(ginfo);
|
||||
}
|
||||
#endif /* CONFIG_NX */
|
||||
#endif /* CONFIG_GRAPHICS_TRAVELER_NX */
|
||||
|
||||
/****************************************************************************
|
||||
* Name: trv_row_update
|
||||
@ -312,7 +328,7 @@ void trv_row_update(struct trv_graphics_info_s *ginfo,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
void trv_display_update(struct trv_graphics_info_s *ginfo,
|
||||
FAR dev_pixel_t *dest, trv_coord_t destrow)
|
||||
{
|
||||
@ -340,7 +356,7 @@ int trv_graphics_initialize(FAR struct trv_graphics_info_s *ginfo)
|
||||
|
||||
/* Initialize the graphics device and get information about the display */
|
||||
|
||||
#ifndef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_FB
|
||||
trv_fb_initialize(ginfo);
|
||||
#else
|
||||
trv_nx_initialize(ginfo);
|
||||
@ -404,7 +420,7 @@ int trv_graphics_initialize(FAR struct trv_graphics_info_s *ginfo)
|
||||
* image that must transferred to the window.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
ginfo->hwbuffer = (trv_pixel_t*)trv_malloc(ginfo->imgwidth);
|
||||
if (!ginfo->hwbuffer)
|
||||
{
|
||||
@ -439,7 +455,7 @@ void trv_graphics_terminate(FAR struct trv_graphics_info_s *ginfo)
|
||||
ginfo->swbuffer = NULL;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_NX
|
||||
#if defined(CONFIG_GRAPHICS_TRAVELER_NX)
|
||||
if (ginfo->hwbuffer)
|
||||
{
|
||||
trv_free(ginfo->hwbuffer);
|
||||
@ -448,6 +464,11 @@ void trv_graphics_terminate(FAR struct trv_graphics_info_s *ginfo)
|
||||
|
||||
/* Close/disconnect NX */
|
||||
#warning "Missing Logic"
|
||||
|
||||
#elif defined(CONFIG_GRAPHICS_TRAVELER_FB)
|
||||
close(ginfo->fb);
|
||||
ginfo->hwbuffer = NULL;
|
||||
ginfo->fb = -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -462,7 +483,7 @@ void trv_display_update(struct trv_graphics_info_s *ginfo)
|
||||
FAR const uint8_t *src;
|
||||
FAR uint8_t *dest;
|
||||
trv_coord_t srcrow;
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
trv_coord_t destrow;
|
||||
#else
|
||||
FAR uint8_t *first;
|
||||
@ -481,7 +502,7 @@ void trv_display_update(struct trv_graphics_info_s *ginfo)
|
||||
|
||||
/* Loop for each row in the src render buffer */
|
||||
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
destrow = 0;
|
||||
#endif
|
||||
|
||||
@ -492,7 +513,7 @@ void trv_display_update(struct trv_graphics_info_s *ginfo)
|
||||
trv_row_update(ginfo, (FAR const trv_pixel_t *)src,
|
||||
(FAR dev_pixel_t *)dest);
|
||||
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
/* Transfer the row buffer to the NX window */
|
||||
|
||||
trv_row_transfer(ginfo, dest, destrow);
|
||||
@ -506,7 +527,7 @@ void trv_display_update(struct trv_graphics_info_s *ginfo)
|
||||
|
||||
for (i = 1; i < ginfo->yscale; i++)
|
||||
{
|
||||
#ifdef CONFIG_NX
|
||||
#ifdef CONFIG_GRAPHICS_TRAVELER_NX
|
||||
/* Transfer the row buffer to the NX window */
|
||||
|
||||
trv_row_transfer(ginfo, dest, destrow);
|
||||
|
Loading…
x
Reference in New Issue
Block a user