cmap_grab.c revision 919
/* Copyright 1999 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice (including the next
* paragraph) shall be included in all copies or substantial portions of the
* Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*/
/*
* cmap_grab.c - the client side code for DGA colormap grabber
*/
/*
*
* Shared colormap synchronization routines.
*
* Client side
*
*
* Functions:
*
* Dga_cmap
* dga_cm_grab(devfd, filesuffix)
* int devfd ;
* unsigned long filesuffix ;
*
* Grab a colormap. 'filesuffix' is the handle returned by
* XDgaGrabColormap. 'devfd' is the file descriptor of the frame buffer
* if any, -1 otherwise. If you specify -1, dga_cm_grab will open
* the frame buffer. The frame buffer fd may be inquired from
* the returned dga_cmap structure.
*
* Returns a pointer to a dga_cmap structure on success,
* NULL on failure.
*
*
* void
* dga_cm_ungrab(cginfo,cflag)
* Dga_cmap cginfo ;
* int cflag ;
*
* Release a colormap. All resources allocated by dga_cm_grab are
* freed. The application should call XDgaUnGrabColormap after calling
* dga_cm_ungrab() so that the server may free the colormap info page
* at the other end.
*
* if cflag is nonzero, the framebuffr fd described in the info page
* is also closed. The info page is invalid after this call and
* references to it will probably result in a SIGSEGV.
*
*
*
*
* void
* dga_cm_get(cginfo,index,count, red,green,blue)
* Dga_cmap cginfo ;
* int index, count ;
* u_char *red, *green, *blue ;
*
* Read colormap values and return them to the application.
*
*
* void
* dga_cm_put(cginfo,index,count, red,green,blue)
* Dga_cmap cginfo ;
* int index, count ;
* u_char *red, *green, *blue ;
*
* Write colormap to hardware if colormap is installed, otherwise
* save them in shared memory.
*
*
*
* void
* dga_cm_write(cginfo,index,count, red,green,blue, putfunc)
* Dga_cmap cginfo ;
* int index, count ;
* u_char *red, *green, *blue ;
* int (*putfunc)();
*
* Write colormap to hardware by calling the user supplied putfunc
* if colormap is installed, otherwise save them in shared memory.
*
** void
* dga_cm_read(cginfo,index,count, red,green,blue)
* Dga_cmap cginfo ;
* int index, count ;
* u_char *red, *green, *blue ;
* int (*putfunc)();
*
* Read colormap values and return them to the application
*
* int
* dga_cm_get_devfd(cginfo)
* Dga_cmap cginfo;
*
* Return the fd of the device associated with cginfo
*
* void
* dga_cm_get_devinfo(cginfo)
* Dga_cmap cginfo;
*
* Returns pointer to the device specific info associated with
* cginfo. Used to communicate info bet server and client
*
* void
* dga_cm_set_client_infop(cginfo, client_info_ptr)
* Dga_cmap cginfo;
* void* client_info_ptr;
*
* Sets pointer to client specificr-data associated with cginfo.
*
* void *
* dga_cm_get_client_infop(cginfo)
* Dga_cmap cginfo;
*
* Returns the client specific data pointer associated with cginfo
****/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#ifdef SVR4
#ifdef SUNWINDOWS /* see note later */
#include <sys/win_screen.h>
#include <sys/win_input.h>
#include <sys/win_ioctl.h>
#endif /* SUNWINDOWS */
#include <unistd.h>
#else
#include <sunwindow/win_screen.h>
#include <sunwindow/win_input.h>
#include <sunwindow/win_ioctl.h>
#endif
#ifndef FB_CLUTPOST
struct fb_clut {
unsigned int flags; /* flags */
int index; /* CLUT id */
int offset; /* offset within the CLUT */
int count; /* nbr of entries to be posted */
unsigned char *red; /* pointer to red table */
unsigned char *green; /* pointer to green table */
unsigned char *blue; /* pointer to blue table */
};
#ifdef SVR4
#else
#endif
#endif
#include "cmap_grab.h"
/* externs */
#if 0
extern char *_SysErrorMsg[] ;
#endif
#define NDIGITS 8
static int sunwindows_open();
static void sunwindows_close();
static int cleanup_lockpages();
/*ARGSUSED*/
int fd ;
{
int lockfd, /* lock device */
devfd, /* framebuffer */
infofd, /* shared memory file */
sunwindows_def_fd, /* /dev/winXX fd */
sunwindows_inst_fd ; /* /dev/winXX fd */
int cflag = 0 ; /* close devfd */
int cmaplen ;
int filelen ;
int ok;
#ifdef MT
#endif
/* first and foremost, is this a nested grab? */
#ifdef MT
#endif
return cmap_grab;
}
}
#ifdef MT
#endif
}
/* open the file. Read in enough data to find out long it is. */
cleanup_lockpages(cmap_grab,0,0,0) ;
#ifdef MT
#endif
}
cleanup_lockpages(cmap_grab,0,0,0) ;
#ifdef MT
#endif
}
cleanup_lockpages(cmap_grab,0,0,0) ;
#ifdef MT
#endif
}
/* map the colormap info area */
(off_t)0);
/* we're all done with infofd now. If the info file becomes
* subject to growth later, we'll want to keep it open.
*/
#ifdef MT
#endif
}
/* Open framebuffer if not provided by caller */
if( fd == -1 ) {
if( devfd < 0 ) {
#ifdef DEBUG
#endif /* DEBUG */
#ifdef MT
#endif
return NULL ;
}
cflag = 1 ;
} else
switch( locktype ) {
case CM_LOCKDEV:
/* if lockdevice explicitly specified by server, we need to
* open it here, even if the calling routine has opened the
* framebuffer for us. Otherwise, we use the framebuffer device.
*/
if( lockfd < 0 ) {
#ifdef DEBUG
#endif /* DEBUG */
#ifdef MT
#endif
return NULL ;
}
} else
/* map the lock page */
if (lock == (char *)-1) {
#ifdef MT
#endif
}
/* map the unlock page */
if( unlock == (char *)-1 ) {
#ifdef MT
#endif
}
break ;
case CM_WINLOCK:
#ifdef MT
#endif
}
break ;
}
/* fill in the misc stuff */
ok = 1;
if ((sunwindows_def_fd = sunwindows_open(
infop->cm_sunwindows_def_devname)) < 0)
ok = 0;
}
if ((sunwindows_inst_fd = sunwindows_open(
infop->cm_sunwindows_inst_devname)) < 0)
ok = 0;
}
if(!ok) {
#ifdef MT
#endif
}
cmap_grab->cm_lockcnt = 0 ;
#ifdef MT
#endif
}
static int
{
int error = 0 ;
if (cginfo->cm_sunwindows_def_fd >= 0)
if (cginfo->cm_sunwindows_inst_fd >= 0)
switch( locktype ) {
case CM_LOCKDEV:
break ;
case CM_WINLOCK:
break ;
}
if( cflag )
error = 1 ;
else {
else
}
return error ? -1 : 0 ;
}
void
int cflag ;
{
int locktype ;
#ifdef MT
#endif
if( --cginfo->cm_grab_count > 0 ) {
#ifdef MT
#endif
return;
}
#ifdef MT
#endif
}
static Dga_cmap
{
#ifdef DEBUG
#endif /* DEBUG */
return NULL ;
}
/*
* Read colormap from shared memory.
* Shared memory should always be in sync
* with server's idea of this X11 colormap's
* contents.
*/
void
{
#ifdef MT
#endif
wx_cm_lock(cginfo) ;
/* REMIND: Currently, we don't need to test for any changes in the
* shared memory page; but if we did, right here is where we'd do
* it. We compare infop->cm_count against cginfo->c_chngcnt and
* react if there was a difference. After handling the change,
* we'd copy infop->cm_count to cginfo->c_chngcnt.
*/
if( count > 0 ) {
/* copy from shared memory */
short *shadow ;
short *ip ;
int n ;
}
#ifdef MT
#endif
}
/* This is the new interface that will be publicly exposed */
void
{
}
/* write colormap to shared memory, and to DACS if appropriate. */
void
{
short *shadow ;
short *op ; /* out pointer */
int n ;
#ifdef MT
#endif
wx_cm_lock(cginfo) ;
if( count > 0 ) {
/* copy to shared memory shadow of grabbed color map */
/* "stutter" the 8-bit values into 16 bits */
if( infop->cm_installed ) {
#ifdef COMMENT
/* We no longer need the hw shadow cmap but have to keep
* the structures the same size and so we will just stop
* updating it
*/
/* copy to shared memory shadow of hardware color map */
#endif
switch(infop->cm_load_method) {
#ifdef SUNWINDOWS
/* Note from V4 on, SUnwindows include files, support no
* longer exist. I am commenting out the code instead of
* removing it only for completeness. After Mars, time to
* move away from sunwindows....
*/
case SUNWINDOWS_IOCTL:
{
if( cginfo->cm_sunwindows_def_fd >= 0 ) {
/* HACK ALERT */
/* Adjust SUNWINDOWS cms segment 1st colr != last color */
{
else
}
}
if( cginfo->cm_sunwindows_inst_fd >= 0 )
{
/* HACK ALERT */
/* Adjust SUNWINDOWS cms segment 1st colr != last color */
else
}
}
}
break;
#endif /* SUNWINDOWS */
case HW_DEVICE_DIRECT: /* could have device-specific
routines here; just fall
through to device ioctl
for now */
case HW_DEVICE_IOCTL:
default:
#ifdef FBIOPUTCMAPI
if( cginfo->cm_use_new_ioctl) {
/* try new ioctl */
break;
}
#endif /* FBIOPUTCMAPI */
if( cginfo->cm_use_new_ioctl ) {
/* try FB_CLUTPOST ioctl */
break;
cginfo->cm_use_new_ioctl = 0;
}
if (cginfo->cm_use_new_ioctl == 0) {
}
break;
}
}
/* We've changed the shared memory page, flag this fact to
* the server and to any other clients
*/
}
#ifdef MT
#endif
}
/* This is the interfce that will be publicly exposed */
void
void (*putfunc)();
{
short *shadow ;
short *op ; /* out pointer */
int n ;
#ifdef MT
#endif
wx_cm_lock(cginfo) ;
if( count > 0 ) {
/* copy to shared memory shadow of grabbed color map */
/* "stutter" the 8-bit values into 16 bits */
if( infop->cm_installed ) {
#ifdef COMMENT
/* We dont need to update thie any more */
/* copy to shared memory shadow of hardware color map */
#endif
/* Now call the user supplied function for actually
* posting the cmap
*/
}
/* We've changed the shared memory page, flag this fact to
* the server and to any other clients
*/
}
#ifdef MT
#endif
}
/* Interfaces that will be exposed to the public */
int
{
}
/* This device info is shared between the server and client */
void *
{
}
/* Each client may store private info in the client info ptr */
void
void* client_info_ptr;
{
}
void *
{
}
static int
char *devname;
{
int fd;
while (dlist)
{
{
}
}
{
#ifdef DEBUG
#endif /* DEBUG */
return(-1);
}
{
#ifdef DEBUG
#endif /* DEBUG */
return(-1);
}
return(fd);
}
static void
int fd;
{
while (dlist)
{
{
{
}
return;
}
}
}
* part of the C library someday.
*
*/
/* structure for allocating lock contexts. The identification
* should be provided as the offset for mmap(2). The offset is
* the byte-offset relative to the start of the page returned
* by mmap(2).
*/
struct winlockalloc {
} ;
struct winlocktimeout {
int sy_flags ;
} ;
#ifndef WINLOCKALLOC
#ifdef SVR4
#define WINLOCKALLOC (WIOC|0)
#else /* SVR4 */
#endif /* SVR4 */
#endif /* WINLOCKALLOC */
/* flag bits */
static char *lockdev_name = "/dev/winlock" ;
static char *alt_lockdev_name = "/dev/cgsix0" ;
static int lock_fd = -1 ;
static u_long pageoffset ;
/* return non-zero if fail */
static int
init()
{
if( lock_fd == -1 ) {
return 1 ;
#ifdef SVR4
#else
pagesize = getpagesize() ;
#endif
pagemask = ~pageoffset ;
}
return 0 ;
}
int
{
{
return -1 ;
}
if( (int)ptr == -1 )
{
return -1 ;
}
if( (int)ptr == -1 )
{
return -1 ;
}
return 0 ;
}
int
{
{
return -1 ;
}
perror("_dga_winlockdt: munmap:");
perror("_dga_winlockdt: munmap:");
return 0 ;
}