A little more progress toward the implementation of per-window framebuffers. Still missing:

- Logic that generates the low lever framebuffer renderers for the per-window framebuffers,
- The logic that picks off the per-window framebuffer updates from normal graphics device updates.  This logic must update both the per-window framebuffer and the graphics device (from the framebuffer).

Squashed commit of the following:

    graphics:  Add logic to allocate the per-window framebuffer.

    graphics:  A few fragmentary thoughts on how a per-window framebuffer could be represented and allocated.
This commit is contained in:
Gregory Nutt 2019-03-14 11:20:14 -06:00
parent 2f257cfd0a
commit 419c4cb6be
7 changed files with 216 additions and 32 deletions

View File

@ -1,7 +1,7 @@
/****************************************************************************
* fs/mmap/fs_mmap.c
*
* Copyright (C) 2008-2009, 2011 Gregory Nutt. All rights reserved.
* Copyright (C) 2008-2009, 2011, 2019 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -46,6 +46,8 @@
#include <errno.h>
#include <debug.h>
#include <nuttx/kmalloc.h>
#include "inode/inode.h"
#include "fs_rammap.h"
@ -92,7 +94,7 @@
* MAP_PRIVATE - Will cause an error
* MAP_FIXED - Will cause an error
* MAP_FILE - Ignored
* MAP_ANONYMOUS - Will cause an error
* MAP_ANONYMOUS - Optional
* MAP_ANON - Will cause an error
* MAP_GROWSDOWN - Ignored
* MAP_DENYWRITE - Will cause an error
@ -125,6 +127,7 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
int fd, off_t offset)
{
FAR void *addr;
int errcode;
int ret;
/* Since only a tiny subset of mmap() functionality, we have to verify many
@ -132,24 +135,60 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
*/
#ifdef CONFIG_DEBUG_FEATURES
/* Private mappings and protections are not currently supported. These
* options could be supported in the KERNEL build with an MMU, but that
* logic is not in place.
*/
if (prot == PROT_NONE ||
(flags & (MAP_PRIVATE | MAP_FIXED | MAP_ANONYMOUS | MAP_DENYWRITE)) != 0)
(flags & (MAP_PRIVATE | MAP_FIXED | MAP_DENYWRITE)) != 0)
{
ferr("ERROR: Unsupported options, prot=%x flags=%04x\n", prot, flags);
set_errno(ENOSYS);
return MAP_FAILED;
errcode = ENOSYS;
goto errout;
}
/* A length of 0 is invalid. Currently only shared mappings are supported.
* Non-shared could be implemented in the KERNEL build with an MMU.
*/
if (length == 0 || (flags & MAP_SHARED) == 0)
{
ferr("ERROR: Invalid options, lengt=%d flags=%04x\n", length, flags);
set_errno(EINVAL);
return MAP_FAILED;
ferr("ERROR: Invalid options, length=%d flags=%04x\n", length, flags);
errcode = EINVAL;
goto errout;
}
#endif
/* Check if we are just be asked to allocate memory, i.e., MAP_ANONYMOUS
* set meaning that the memory is not backed up from a file. The file
* descriptor should be -1 (or refer to opened /dev/zero) in this case.
* The file descriptor is ignored in either case.
*/
if ((flags & MAP_ANONYMOUS) != 0)
{
FAR void *alloc;
/* REVISIT: Should reside outside of the heap. That is really the
* only purpose of MAP_ANONYMOUS: To get non-heap memory. In KERNEL
* build, this could be accomplished using pgalloc(), provided that
* you had logic in place to assign a virtual address to the mapping.
*/
alloc = kumm_zalloc(length);
if (alloc == NULL)
{
ferr("ERROR: kumm_alloc() failed: %d\n", ret);
errcode = ENOMEM;
goto errout;
}
return alloc;
}
/* Okay now we can assume a shared mapping from a file. This is the
* only option supported
* only other option supported
*
* Perform the ioctl to get the base address of the file in 'mapped'
* in memory. (casting to uintptr_t first eliminates complaints on some
@ -160,9 +199,19 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
ret = ioctl(fd, FIOC_MMAP, (unsigned long)((uintptr_t)&addr));
if (ret < 0)
{
/* Not directly mappable, probably because the underlying media does
* not support random access.
*/
#ifdef CONFIG_FS_RAMMAP
/* Allocate memory and copy the file into memory. We would, of course,
* do much better in the KERNEL build using the MMU.
*/
return rammap(fd, length, offset);
#else
/* Error out. The errno value was already set by ioctl() */
ferr("ERROR: ioctl(FIOC_MMAP) failed: %d\n", get_errno());
return MAP_FAILED;
#endif
@ -171,4 +220,8 @@ FAR void *mmap(FAR void *start, size_t length, int prot, int flags,
/* Return the offset address */
return (FAR void *)(((FAR uint8_t *)addr) + offset);
errout:
set_errno(errcode);
return MAP_FAILED;
}

View File

@ -45,6 +45,10 @@
#include <nuttx/kmalloc.h>
#include <nuttx/nx/nxglib.h>
#if defined(CONFIG_NX_RAMBACKED) && defined(CONFIG_BUILD_KERNEL)
# include "nuttx/pgalloc.h"
#endif
#include "nxbe.h"
/****************************************************************************
@ -66,16 +70,17 @@
*
****************************************************************************/
void nxbe_closewindow(struct nxbe_window_s *wnd)
void nxbe_closewindow(FAR struct nxbe_window_s *wnd)
{
FAR struct nxbe_state_s *be;
#ifdef CONFIG_DEBUG_FEATURES
if (!wnd)
if (wnd == NULL)
{
return;
}
#endif
be = wnd->be;
/* The background window should never be closed */
@ -113,6 +118,25 @@ void nxbe_closewindow(struct nxbe_window_s *wnd)
nxbe_redrawbelow(be, wnd->below, &wnd->bounds);
#ifdef CONFIG_NX_RAMBACKED
/* Free any allocated, per-window framebuffer */
if (wnd->fb != NULL)
{
#ifdef CONFIG_BUILD_KERNEL
DEBUGASSERT(wnd->npages > 0);
/* Return the pages to the poll */
mm_pgfree((uintptr_t)wnd->fb, wnd->npages);
#else
/* Return the memory to the user heap */
kumm_free(wnd->fb);
#endif
}
#endif
/* Then discard the window structure. Here we assume that the user-space
* allocator was used.
*/

View File

@ -38,6 +38,16 @@
****************************************************************************/
#include <nuttx/config.h>
#include <errno.h>
#ifdef CONFIG_NX_RAMBACKED
#ifdef CONFIG_BUILD_KERNEL
# include "nuttx/pgalloc.h"
#else
# include "nuttx/kmalloc.h"
#endif
# include <nuttx/nx/nxbe.h>
#endif
#include <nuttx/nx/nx.h>
#include "nxmu.h"
@ -63,6 +73,13 @@
void nxmu_openwindow(FAR struct nxbe_state_s *be, FAR struct nxbe_window_s *wnd)
{
#ifdef CONFIG_NX_RAMBACKED
nxgl_coord_t width;
nxgl_coord_t height;
size_t fbsize;
unsigned int bpp;
#endif
/* The window structure was allocated in nx_openwindow and all fields have
* been set to zero; conn, flags, cb, and arg which were initialized on
* the client side. On the server side, we need only initialize a few
@ -72,6 +89,66 @@ void nxmu_openwindow(FAR struct nxbe_state_s *be, FAR struct nxbe_window_s *wnd)
wnd->be = be;
#ifdef CONFIG_NX_RAMBACKED
/* Allocate framebuffer memory if the per-window framebuffer feature has
* been selected.
*/
if (NXBE_ISRAMBACKED(wnd))
{
width = wnd->bounds.pt2.x - wnd->bounds.pt1.x + 1;
height = wnd->bounds.pt2.y - wnd->bounds.pt1.y + 1;
bpp = wnd->be->plane[0].pinfo.bpp;
wnd->stride = (bpp * width + 7) >> 8;
fbsize = wnd->stride * height;
#ifdef CONFIG_BUILD_KERNEL
/* Allocate memory from the page pool because:
*
* 1) The page pool is the largest memory pool and best for
* framebuffers.
* 2) The allocation will be contiguous and much easier to
* map into a user address later.
*/
/* Determine the number of pages to be allocated */
wnd->npages = (uint16_t)MM_NPAGES(fbsize);
/* Allocate the pages */
wnd->fb = (FAR nxgl_mxpixel_t *)mm_pgalloc(wnd->npages);
if (wnd->fb == NULL)
{
/* Fall back to no RAM back up */
gerr("ERROR: mm_pgalloc() failed\n");
wnd->stride = 0;
wnd->npages = 0;
NXBE_CLRRAMBACKED(wnd);
}
#else
/* Allocate memory from the user space heap because:
*
* 1) The user space heap is the larger memory pool and best for
* framebuffers (protected mode).
* 2) The user space heap is openly accessible at all privilege
* levels.
*/
wnd->fb = (FAR nxgl_mxpixel_t *)kumm_malloc(fbsize);
if (wnd->fb == NULL)
{
/* Fall back to no RAM back up */
gerr("ERROR: mm_pgalloc() failed\n");
wnd->stride = 0;
NXBE_CLRRAMBACKED(wnd);
}
#endif
}
#endif
/* Now, insert the new window at the top on the display. topwind is
* never NULL (it may point only at the background window, however)
*/

View File

@ -84,11 +84,15 @@
(((wnd)->flags & NXBE_WINDOW_BLOCKED) != 0)
#define NXBE_SETBLOCKED(wnd) \
do { (wnd)->flags |= NXBE_WINDOW_BLOCKED; } while (0)
#define NXBE_CLRBLOCKED(wnd) \
do { (wnd)->flags &= ~NXBE_WINDOW_BLOCKED; } while (0)
#define NXBE_ISRAMBACKED(wnd) \
(((wnd)->flags & NXBE_WINDOW_RAMBACKED) != 0)
#define NXBE_SETRAMBACKED(wnd) \
do { (wnd)->flags |= NXBE_WINDOW_RAMBACKED; } while (0)
#define NXBE_CLRRAMBACKED(wnd) \
do { (wnd)->flags &= ~NXBE_WINDOW_RAMBACKED; } while (0)
/****************************************************************************
* Public Types
@ -129,6 +133,18 @@ struct nxbe_window_s
uint8_t flags;
#ifdef CONFIG_NX_RAMBACKED
/* Per-window framebuffer support */
#ifdef CONFIG_BUILD_KERNEL
uint16_t npages; /* Number of pages in allocation */
#endif
nxgl_coord_t stride; /* Width of framebuffer in bytes */
FAR nxgl_mxpixel_t *fb; /* Allocated framebuffer in kernal
* address spaced. Must be contiguous.
*/
#endif
/* Client state information this is provide in window callbacks */
FAR void *arg;

View File

@ -1,7 +1,8 @@
/****************************************************************************
* include/sys/mman.h
*
* Copyright (C) 2008, 2009, 2011, 2014 Gregory Nutt. All rights reserved.
* Copyright (C) 2008, 2009, 2011, 2014, 2019 Gregory Nutt. All rights
* reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -51,30 +52,35 @@
* yet support any of these, but are provided for source level compatibility
*/
#define PROT_NONE 0x0 /* Page may not be accessed */
#define PROT_READ 0x1 /* Page may be read */
#define PROT_WRITE 0x2 /* Page may be written */
#define PROT_EXEC 0x4 /* Page may be executed */
#define PROT_NONE 0x0 /* Page may not be accessed */
#define PROT_READ (1 << 0) /* Bit 0: Page may be read */
#define PROT_WRITE (1 << 1) /* Bit 1: Page may be written */
#define PROT_EXEC (1 << 2) /* Bit 2: Page may be executed */
/* Sharing types -- ignored by NuttX. */
/* mmpa() flags bits. Only MAP_SHARED, MAP_PRIVATE, and MAP_FIXED are
* specified by OpenGroup.org. The rest are unique to NuttX or are
* definitions used by other systems.
*/
#define MAP_SHARED 0x00001 /* Share this mapping */
#define MAP_PRIVATE 0x00002 /* Create a private copy-on-write mapping */
#define MAP_TYPE 0x0000f /* Mask for type of mapping */
#define MAP_FIXED 0x00010 /* Map to specified address exactly */
#define MAP_FILE 0x00000 /* The mapping is backed by a file */
#define MAP_ANONYMOUS 0x00020 /* The mapping is not backed by any file */
#define MAP_ANON MAP_ANONYMOUS
/* Sharing types (most are not implemented). */
/* These are Linux-specific. */
#define MAP_SHARED (1 << 0) /* Bit 0: Share this mapping */
#define MAP_PRIVATE (1 << 1) /* Bit 1: Create a private copy-on-write mapping */
#define MAP_TYPE (3 << 0) /* Mask for type of mapping */
#define MAP_FIXED (1 << 2) /* Bit 2: Map to specified address exactly */
#define MAP_FILE (1 << 3) /* Bit 3: The mapping is backed by a file */
#define MAP_ANONYMOUS (1 << 4) /* Bit 4: The mapping is not backed by any file */
#define MAP_ANON MAP_ANONYMOUS /* Alias */
#define MAP_GROWSDOWN 0x00100 /* Used to stack allocations */
#define MAP_DENYWRITE 0x00800 /* Do not permit writes to file */
#define MAP_EXECUTABLE 0x01000 /* Mark it as an executable */
#define MAP_LOCKED 0x02000 /* Lock pages mapped into memory */
#define MAP_NORESERVE 0x04000 /* Do not reserve swap space for this mapping */
#define MAP_POPULATE 0x08000 /* Populate (prefault) pagetables */
#define MAP_NONBLOCK 0x10000 /* Do not block on IO */
/* These are Linux-specific (none are implemented). */
#define MAP_GROWSDOWN (1 << 5) /* Bit 5: Used to stack allocations */
#define MAP_DENYWRITE (1 << 6) /* Bit 6: Do not permit writes to file */
#define MAP_EXECUTABLE (1 << 7) /* Bit 7: Mark it as an executable */
#define MAP_LOCKED (1 << 8) /* Bit 8: Lock pages mapped into memory */
#define MAP_NORESERVE (1 << 9) /* Bit 9: Do not reserve swap space for this mapping */
#define MAP_POPULATE (1 << 10) /* Bit 10: opulate (prefault) page tables */
#define MAP_NONBLOCK (1 << 11) /* Bit 11: Do not block on IO */
/* Failure return */

View File

@ -114,6 +114,13 @@ int nx_constructwindow(NXHANDLE handle, NXWINDOW hwnd, uint8_t flags,
wnd->flags = flags;
wnd->cb = cb;
wnd->arg = arg;
#ifdef CONFIG_NX_RAMBACKED
#ifdef CONFIG_BUILD_KERNEL
wnd->npages = 0;
#endif
wnd->stride = 0;
wnd->fb = NULL;
#endif
/* Request initialization the new window from the server */

View File

@ -223,3 +223,4 @@ void mm_pginfo(FAR struct pginfo_s *info)
}
#endif /* CONFIG_MM_PGALLOC */