2008-11-28 15:42:52 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* graphics/nxmu/nxmu_openwindow.c
|
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2008-11-28 15:42:52 +01:00
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-11-28 15:42:52 +01:00
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2008-11-28 15:42:52 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
2019-03-14 18:20:14 +01:00
|
|
|
#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
|
2008-11-28 15:42:52 +01:00
|
|
|
|
2011-07-24 22:49:01 +02:00
|
|
|
#include <nuttx/nx/nx.h>
|
2019-03-13 16:16:30 +01:00
|
|
|
#include "nxmu.h"
|
2008-11-28 15:42:52 +01:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxmu_openwindow
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Create a new window.
|
|
|
|
*
|
|
|
|
* Input Parameters:
|
2008-11-29 21:26:18 +01:00
|
|
|
* be - The back-end status structure
|
2010-04-17 18:00:58 +02:00
|
|
|
* wnd - The pre-allocated window structure to be initialized [IN/OUT]
|
2008-11-28 15:42:52 +01:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Returned Value:
|
2008-11-28 15:42:52 +01:00
|
|
|
* None
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2021-02-05 09:05:48 +01:00
|
|
|
void nxmu_openwindow(FAR struct nxbe_state_s *be,
|
|
|
|
FAR struct nxbe_window_s *wnd)
|
2008-11-28 15:42:52 +01:00
|
|
|
{
|
2019-03-14 18:20:14 +01:00
|
|
|
#ifdef CONFIG_NX_RAMBACKED
|
|
|
|
nxgl_coord_t width;
|
|
|
|
nxgl_coord_t height;
|
|
|
|
size_t fbsize;
|
|
|
|
unsigned int bpp;
|
|
|
|
#endif
|
|
|
|
|
2008-11-28 15:42:52 +01:00
|
|
|
/* The window structure was allocated in nx_openwindow and all fields have
|
2019-03-13 19:34:13 +01:00
|
|
|
* 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
|
|
|
|
* more the non zero fields and insert the new window at the top of the
|
|
|
|
* display.
|
2008-11-28 15:42:52 +01:00
|
|
|
*/
|
|
|
|
|
2019-03-13 19:34:13 +01:00
|
|
|
wnd->be = be;
|
2008-11-28 15:42:52 +01:00
|
|
|
|
2019-03-14 18:20:14 +01:00
|
|
|
#ifdef CONFIG_NX_RAMBACKED
|
|
|
|
/* Allocate framebuffer memory if the per-window framebuffer feature has
|
|
|
|
* been selected.
|
2019-03-15 19:15:33 +01:00
|
|
|
*
|
|
|
|
* REVISIT: This initial state of the framebuffer is uninitialized and
|
|
|
|
* not synchronized with the graphic device content. It will take a full
|
|
|
|
* screen update from the application to force the framebuffer and device
|
|
|
|
* to be consistent.
|
|
|
|
*
|
|
|
|
* REVISIT: Assumes a single color plane.
|
2019-03-14 18:20:14 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
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;
|
2019-03-16 19:31:29 +01:00
|
|
|
wnd->stride = (bpp * width + 7) >> 3;
|
2019-03-14 18:20:14 +01:00
|
|
|
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 */
|
|
|
|
|
2019-03-14 19:19:01 +01:00
|
|
|
wnd->fbmem = (FAR nxgl_mxpixel_t *)mm_pgalloc(wnd->npages);
|
|
|
|
if (wnd->fbmem == NULL)
|
2019-03-14 18:20:14 +01:00
|
|
|
{
|
|
|
|
/* Fall back to no RAM back up */
|
|
|
|
|
2019-03-16 19:31:29 +01:00
|
|
|
gerr("ERROR: mm_pgalloc() failed for fbsize=%lu, npages=%u\n",
|
|
|
|
(unsigned long)fbsize, wnd->npages);
|
|
|
|
|
2019-03-14 18:20:14 +01:00
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2019-03-14 19:19:01 +01:00
|
|
|
wnd->fbmem = (FAR nxgl_mxpixel_t *)kumm_malloc(fbsize);
|
|
|
|
if (wnd->fbmem == NULL)
|
2019-03-14 18:20:14 +01:00
|
|
|
{
|
|
|
|
/* Fall back to no RAM back up */
|
|
|
|
|
2019-03-16 19:31:29 +01:00
|
|
|
gerr("ERROR: kumm_malloc() failed for fbsize=%lu\n",
|
|
|
|
(unsigned long)fbsize);
|
|
|
|
|
2019-03-14 18:20:14 +01:00
|
|
|
wnd->stride = 0;
|
|
|
|
NXBE_CLRRAMBACKED(wnd);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-05-07 16:49:16 +02:00
|
|
|
/* Is the window being created in the hidden state? */
|
2008-11-28 15:42:52 +01:00
|
|
|
|
2019-05-07 16:49:16 +02:00
|
|
|
if (!NXBE_ISHIDDEN(wnd))
|
2019-04-05 16:24:46 +02:00
|
|
|
{
|
2019-05-07 16:49:16 +02:00
|
|
|
/* No.. Insert the new window at the correct position in the
|
|
|
|
* hierarchy. topwnd is never NULL (it may point only at the
|
|
|
|
* background window, however). If we are in a modal state, then we
|
|
|
|
* cannot insert the window at the top of the display.
|
2019-04-05 16:24:46 +02:00
|
|
|
*/
|
|
|
|
|
2019-05-07 16:49:16 +02:00
|
|
|
if (NXBE_STATE_ISMODAL(be) && be->topwnd->below != NULL)
|
|
|
|
{
|
|
|
|
/* We are in a modal state. The topwnd is not the background and
|
|
|
|
* it has focus.
|
|
|
|
*/
|
2019-04-05 16:24:46 +02:00
|
|
|
|
2019-05-07 16:49:16 +02:00
|
|
|
wnd->above = be->topwnd;
|
|
|
|
wnd->below = be->topwnd->below;
|
2008-11-28 15:42:52 +01:00
|
|
|
|
2019-05-07 16:49:16 +02:00
|
|
|
be->topwnd->below = wnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Otherwise insert the new window at the top on the display. */
|
2019-04-05 16:24:46 +02:00
|
|
|
|
2019-05-07 16:49:16 +02:00
|
|
|
wnd->above = NULL;
|
|
|
|
wnd->below = be->topwnd;
|
|
|
|
|
|
|
|
be->topwnd->above = wnd;
|
|
|
|
be->topwnd = wnd;
|
|
|
|
}
|
2019-04-05 16:24:46 +02:00
|
|
|
}
|
2008-11-28 15:42:52 +01:00
|
|
|
|
2008-11-29 15:59:02 +01:00
|
|
|
/* Report the initial size/position of the window to the client */
|
|
|
|
|
2019-03-13 16:16:30 +01:00
|
|
|
nxmu_reportposition(wnd);
|
2008-11-29 15:59:02 +01:00
|
|
|
|
2019-03-13 19:34:13 +01:00
|
|
|
#ifdef CONFIG_NX_XYINPUT
|
2008-11-29 15:59:02 +01:00
|
|
|
/* Provide the initial mouse settings to the client */
|
2008-11-28 15:42:52 +01:00
|
|
|
|
|
|
|
nxmu_mousereport(wnd);
|
|
|
|
#endif
|
|
|
|
}
|