Removing DGA support for SDL 1.3 - it's still buggy years later, and now
it's deprecated by the developers in favor of the render APIs.
--- a/configure.in Tue Jul 25 07:25:51 2006 +0000
+++ b/configure.in Wed Jul 26 03:06:07 2006 +0000
@@ -911,25 +911,6 @@
fi
have_video=yes
- AC_ARG_ENABLE(dga,
-AC_HELP_STRING([--enable-dga], [allow use of X11 DGA code [[default=yes]]]),
- , enable_dga=yes)
- if test x$enable_dga = xyes; then
- SOURCES="$SOURCES $srcdir/src/video/Xext/Xxf86dga/*.c"
- fi
- AC_ARG_ENABLE(video-dga,
-AC_HELP_STRING([--enable-video-dga], [use DGA 2.0 video driver [[default=yes]]]),
- , enable_video_dga=yes)
- if test x$enable_dga = xyes -a x$enable_video_dga = xyes; then
- AC_DEFINE(SDL_VIDEO_DRIVER_DGA)
- SOURCES="$SOURCES $srcdir/src/video/dga/*.c"
- fi
- AC_ARG_ENABLE(video-x11-dgamouse,
-AC_HELP_STRING([--enable-video-x11-dgamouse], [use X11 DGA for mouse events [[default=yes]]]),
- , enable_video_x11_dgamouse=yes)
- if test x$enable_dga = xyes -a x$enable_video_x11_dgamouse = xyes; then
- AC_DEFINE(SDL_VIDEO_DRIVER_X11_DGAMOUSE)
- fi
AC_ARG_ENABLE(video-x11-vm,
AC_HELP_STRING([--enable-video-x11-vm], [use X11 VM extension for fullscreen [[default=yes]]]),
, enable_video_x11_vm=yes)
--- a/include/SDL_config.h.in Tue Jul 25 07:25:51 2006 +0000
+++ b/include/SDL_config.h.in Wed Jul 26 03:06:07 2006 +0000
@@ -254,7 +254,6 @@
#undef SDL_VIDEO_DRIVER_COCOA
#undef SDL_VIDEO_DRIVER_CYBERGRAPHICS
#undef SDL_VIDEO_DRIVER_DC
-#undef SDL_VIDEO_DRIVER_DGA
#undef SDL_VIDEO_DRIVER_DIRECTFB
#undef SDL_VIDEO_DRIVER_DRAWSPROCKET
#undef SDL_VIDEO_DRIVER_DUMMY
@@ -278,7 +277,6 @@
#undef SDL_VIDEO_DRIVER_WIN32
#undef SDL_VIDEO_DRIVER_WSCONS
#undef SDL_VIDEO_DRIVER_X11
-#undef SDL_VIDEO_DRIVER_X11_DGAMOUSE
#undef SDL_VIDEO_DRIVER_X11_DPMS
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC
#undef SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT
--- a/src/video/Xext/Xxf86dga/XF86DGA.c Tue Jul 25 07:25:51 2006 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,679 +0,0 @@
-/* $XFree86: xc/lib/Xxf86dga/XF86DGA.c,v 3.19 2001/08/18 02:41:30 dawes Exp $ */
-/*
-
-Copyright (c) 1995 Jon Tombs
-Copyright (c) 1995,1996 The XFree86 Project, Inc
-
-*/
-
-/* THIS IS NOT AN X CONSORTIUM STANDARD */
-
-#ifdef __EMX__ /* needed here to override certain constants in X headers */
-#define INCL_DOS
-#define INCL_DOSIOCTL
-#include <os2.h>
-#endif
-
-#if defined(linux)
-#define HAS_MMAP_ANON
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <asm/page.h> /* PAGE_SIZE */
-#define HAS_SC_PAGESIZE /* _SC_PAGESIZE may be an enum for Linux */
-#define HAS_GETPAGESIZE
-#endif /* linux */
-
-#if defined(CSRG_BASED)
-#define HAS_MMAP_ANON
-#define HAS_GETPAGESIZE
-#include <sys/types.h>
-#include <sys/mman.h>
-#endif /* CSRG_BASED */
-
-#if defined(DGUX)
-#define HAS_GETPAGESIZE
-#define MMAP_DEV_ZERO
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#endif /* DGUX */
-
-#if defined(SVR4) && !defined(DGUX)
-#define MMAP_DEV_ZERO
-#include <sys/types.h>
-#include <sys/mman.h>
-#include <unistd.h>
-#endif /* SVR4 && !DGUX */
-
-#if defined(sun) && !defined(SVR4) /* SunOS */
-#define MMAP_DEV_ZERO /* doesn't SunOS have MAP_ANON ?? */
-#define HAS_GETPAGESIZE
-#include <sys/types.h>
-#include <sys/mman.h>
-#endif /* sun && !SVR4 */
-
-#ifdef XNO_SYSCONF
-#undef _SC_PAGESIZE
-#endif
-
-#define NEED_EVENTS
-#define NEED_REPLIES
-
-#include <X11/Xlibint.h>
-#include "../extensions/xf86dga.h"
-#include "../extensions/xf86dgastr.h"
-#include "../extensions/Xext.h"
-#include "../extensions/extutil.h"
-
-extern XExtDisplayInfo *SDL_NAME(xdga_find_display) (Display *);
-extern char *SDL_NAME(xdga_extension_name);
-
-#define XF86DGACheckExtension(dpy,i,val) \
- XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val)
-
-/*****************************************************************************
- * *
- * public XFree86-DGA Extension routines *
- * *
- *****************************************************************************/
-
-Bool SDL_NAME(XF86DGAQueryExtension) (Display * dpy,
- int *event_basep, int *error_basep)
-{
- return SDL_NAME(XDGAQueryExtension) (dpy, event_basep, error_basep);
-}
-
-Bool SDL_NAME(XF86DGAQueryVersion) (Display * dpy,
- int *majorVersion, int *minorVersion)
-{
- return SDL_NAME(XDGAQueryVersion) (dpy, majorVersion, minorVersion);
-}
-
-Bool SDL_NAME(XF86DGAGetVideoLL) (Display * dpy,
- int screen,
- int *offset,
- int *width, int *bank_size, int *ram_size)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXF86DGAGetVideoLLReply rep;
- xXF86DGAGetVideoLLReq *req;
-
- XF86DGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XF86DGAGetVideoLL, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XF86DGAGetVideoLL;
- req->screen = screen;
- if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
-
- *offset = /*(char *) */ rep.offset;
- *width = rep.width;
- *bank_size = rep.bank_size;
- *ram_size = rep.ram_size;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-
-Bool SDL_NAME(XF86DGADirectVideoLL) (Display * dpy, int screen, int enable)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXF86DGADirectVideoReq *req;
-
- XF86DGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XF86DGADirectVideo, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XF86DGADirectVideo;
- req->screen = screen;
- req->enable = enable;
- UnlockDisplay(dpy);
- SyncHandle();
- XSync(dpy, False);
- return True;
-}
-
-Bool SDL_NAME(XF86DGAGetViewPortSize) (Display * dpy,
- int screen, int *width, int *height)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXF86DGAGetViewPortSizeReply rep;
- xXF86DGAGetViewPortSizeReq *req;
-
- XF86DGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XF86DGAGetViewPortSize, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XF86DGAGetViewPortSize;
- req->screen = screen;
- if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
-
- *width = rep.width;
- *height = rep.height;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-
-Bool SDL_NAME(XF86DGASetViewPort) (Display * dpy, int screen, int x, int y)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXF86DGASetViewPortReq *req;
-
- XF86DGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XF86DGASetViewPort, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XF86DGASetViewPort;
- req->screen = screen;
- req->x = x;
- req->y = y;
- UnlockDisplay(dpy);
- SyncHandle();
- XSync(dpy, False);
- return True;
-}
-
-
-Bool SDL_NAME(XF86DGAGetVidPage) (Display * dpy, int screen, int *vpage)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXF86DGAGetVidPageReply rep;
- xXF86DGAGetVidPageReq *req;
-
- XF86DGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XF86DGAGetVidPage, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XF86DGAGetVidPage;
- req->screen = screen;
- if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
-
- *vpage = rep.vpage;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-
-Bool SDL_NAME(XF86DGASetVidPage) (Display * dpy, int screen, int vpage)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXF86DGASetVidPageReq *req;
-
- XF86DGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XF86DGASetVidPage, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XF86DGASetVidPage;
- req->screen = screen;
- req->vpage = vpage;
- UnlockDisplay(dpy);
- SyncHandle();
- XSync(dpy, False);
- return True;
-}
-
-Bool SDL_NAME(XF86DGAInstallColormap) (Display * dpy,
- int screen, Colormap cmap)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXF86DGAInstallColormapReq *req;
-
- XF86DGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XF86DGAInstallColormap, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XF86DGAInstallColormap;
- req->screen = screen;
- req->id = cmap;
- UnlockDisplay(dpy);
- SyncHandle();
- XSync(dpy, False);
- return True;
-}
-
-Bool SDL_NAME(XF86DGAQueryDirectVideo) (Display * dpy, int screen, int *flags)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXF86DGAQueryDirectVideoReply rep;
- xXF86DGAQueryDirectVideoReq *req;
-
- XF86DGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XF86DGAQueryDirectVideo, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XF86DGAQueryDirectVideo;
- req->screen = screen;
- if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- *flags = rep.flags;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool SDL_NAME(XF86DGAViewPortChanged) (Display * dpy, int screen, int n)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXF86DGAViewPortChangedReply rep;
- xXF86DGAViewPortChangedReq *req;
-
- XF86DGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XF86DGAViewPortChanged, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XF86DGAViewPortChanged;
- req->screen = screen;
- req->n = n;
- if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- UnlockDisplay(dpy);
- SyncHandle();
- return rep.result;
-}
-
-
-
-/* Helper functions */
-
-#include <X11/Xmd.h>
-#include "../extensions/xf86dga.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#if defined(ISC)
-# define HAS_SVR3_MMAP
-# include <sys/types.h>
-# include <errno.h>
-
-# include <sys/at_ansi.h>
-# include <sys/kd.h>
-
-# include <sys/sysmacros.h>
-# include <sys/immu.h>
-# include <sys/region.h>
-
-# include <sys/mmap.h>
-#else
-# if !defined(Lynx)
-# if !defined(__EMX__)
-# include <sys/mman.h>
-# endif
-# else
-# include <sys/types.h>
-# include <errno.h>
-# include <smem.h>
-# endif
-#endif
-#include <sys/wait.h>
-#include <signal.h>
-#include <unistd.h>
-
-#if defined(SVR4) && !defined(sun) && !defined(SCO325)
-#define DEV_MEM "/dev/pmem"
-#elif defined(SVR4) && defined(sun)
-#define DEV_MEM "/dev/xsvc"
-#else
-#define DEV_MEM "/dev/mem"
-#endif
-
-typedef struct
-{
- unsigned long physaddr; /* actual requested physical address */
- unsigned long size; /* actual requested map size */
- unsigned long delta; /* delta to account for page alignment */
- void *vaddr; /* mapped address, without the delta */
- int refcount; /* reference count */
-} MapRec, *MapPtr;
-
-typedef struct
-{
- Display *display;
- int screen;
- MapPtr map;
-} ScrRec, *ScrPtr;
-
-static int mapFd = -1;
-static int numMaps = 0;
-static int numScrs = 0;
-static MapPtr *mapList = NULL;
-static ScrPtr *scrList = NULL;
-
-static MapPtr
-AddMap(void)
-{
- MapPtr *old;
-
- old = mapList;
- mapList = realloc(mapList, sizeof(MapPtr) * (numMaps + 1));
- if (!mapList) {
- mapList = old;
- return NULL;
- }
- mapList[numMaps] = malloc(sizeof(MapRec));
- if (!mapList[numMaps])
- return NULL;
- return mapList[numMaps++];
-}
-
-static ScrPtr
-AddScr(void)
-{
- ScrPtr *old;
-
- old = scrList;
- scrList = realloc(scrList, sizeof(ScrPtr) * (numScrs + 1));
- if (!scrList) {
- scrList = old;
- return NULL;
- }
- scrList[numScrs] = malloc(sizeof(ScrRec));
- if (!scrList[numScrs])
- return NULL;
- return scrList[numScrs++];
-}
-
-static MapPtr
-FindMap(unsigned long address, unsigned long size)
-{
- int i;
-
- for (i = 0; i < numMaps; i++) {
- if (mapList[i]->physaddr == address && mapList[i]->size == size)
- return mapList[i];
- }
- return NULL;
-}
-
-static ScrPtr
-FindScr(Display * display, int screen)
-{
- int i;
-
- for (i = 0; i < numScrs; i++) {
- if (scrList[i]->display == display && scrList[i]->screen == screen)
- return scrList[i];
- }
- return NULL;
-}
-
-static void *
-MapPhysAddress(unsigned long address, unsigned long size)
-{
- unsigned long offset, delta;
- int pagesize = -1;
- void *vaddr;
- MapPtr mp;
-#if defined(ISC) && defined(HAS_SVR3_MMAP)
- struct kd_memloc mloc;
-#elif defined(__EMX__)
- APIRET rc;
- ULONG action;
- HFILE hfd;
-#endif
-
- if ((mp = FindMap(address, size))) {
- mp->refcount++;
- return (void *) ((unsigned long) mp->vaddr + mp->delta);
- }
-#if defined(_SC_PAGESIZE) && defined(HAS_SC_PAGESIZE)
- pagesize = sysconf(_SC_PAGESIZE);
-#endif
-#ifdef _SC_PAGE_SIZE
- if (pagesize == -1)
- pagesize = sysconf(_SC_PAGE_SIZE);
-#endif
-#ifdef HAS_GETPAGESIZE
- if (pagesize == -1)
- pagesize = getpagesize();
-#endif
-#ifdef PAGE_SIZE
- if (pagesize == -1)
- pagesize = PAGE_SIZE;
-#endif
- if (pagesize == -1)
- pagesize = 4096;
-
- delta = address % pagesize;
- offset = address - delta;
-
-#if defined(ISC) && defined(HAS_SVR3_MMAP)
- if (mapFd < 0) {
- if ((mapFd = open("/dev/mmap", O_RDWR)) < 0)
- return NULL;
- }
- mloc.vaddr = (char *) 0;
- mloc.physaddr = (char *) offset;
- mloc.length = size + delta;
- mloc.ioflg = 1;
-
- if ((vaddr = (void *) ioctl(mapFd, MAP, &mloc)) == (void *) -1)
- return NULL;
-#elif defined (__EMX__)
- /*
- * Dragon warning here! /dev/pmap$ is never closed, except on progam exit.
- * Consecutive calling of this routine will make PMAP$ driver run out
- * of memory handles. Some umap/close mechanism should be provided
- */
-
- rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN,
- OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2) NULL);
- if (rc != 0)
- return NULL;
- {
- struct map_ioctl
- {
- union
- {
- ULONG phys;
- void *user;
- } a;
- ULONG size;
- } pmap, dmap;
- ULONG plen, dlen;
-#define XFREE86_PMAP 0x76
-#define PMAP_MAP 0x44
-
- pmap.a.phys = offset;
- pmap.size = size + delta;
- rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP,
- (PULONG) & pmap, sizeof(pmap), &plen,
- (PULONG) & dmap, sizeof(dmap), &dlen);
- if (rc == 0) {
- vaddr = dmap.a.user;
- }
- }
- if (rc != 0)
- return NULL;
-#elif defined (Lynx)
- vaddr = (void *) smem_create("XF86DGA", (char *) offset,
- size + delta, SM_READ | SM_WRITE);
-#else
-#ifndef MAP_FILE
-#define MAP_FILE 0
-#endif
- if (mapFd < 0) {
- if ((mapFd = open(DEV_MEM, O_RDWR)) < 0)
- return NULL;
- }
- vaddr = (void *) mmap(NULL, size + delta, PROT_READ | PROT_WRITE,
- MAP_FILE | MAP_SHARED, mapFd, (off_t) offset);
- if (vaddr == (void *) -1)
- return NULL;
-#endif
-
- if (!vaddr) {
- if (!(mp = AddMap()))
- return NULL;
- mp->physaddr = address;
- mp->size = size;
- mp->delta = delta;
- mp->vaddr = vaddr;
- mp->refcount = 1;
- }
- return (void *) ((unsigned long) vaddr + delta);
-}
-
-/*
- * Still need to find a clean way of detecting the death of a DGA app
- * and returning things to normal - Jon
- * This is here to help debugging without rebooting... Also C-A-BS
- * should restore text mode.
- */
-
-int SDL_NAME(XF86DGAForkApp) (int screen)
-{
- pid_t pid;
- int status;
- int i;
-
- /* fork the app, parent hangs around to clean up */
- if ((pid = fork()) > 0) {
- ScrPtr sp;
-
- waitpid(pid, &status, 0);
- for (i = 0; i < numScrs; i++) {
- sp = scrList[i];
- SDL_NAME(XF86DGADirectVideoLL) (sp->display, sp->screen, 0);
- XSync(sp->display, False);
- }
- if (WIFEXITED(status))
- _exit(0);
- else
- _exit(-1);
- }
- return pid;
-}
-
-
-Bool SDL_NAME(XF86DGADirectVideo) (Display * dis, int screen, int enable)
-{
- ScrPtr sp;
- MapPtr mp = NULL;
-
- if ((sp = FindScr(dis, screen)))
- mp = sp->map;
-
- if (enable & XF86DGADirectGraphics) {
-#if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
- && !defined(__EMX__)
- if (mp && mp->vaddr)
- mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ | PROT_WRITE);
-#endif
- } else {
-#if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
- && !defined(__EMX__)
- if (mp && mp->vaddr)
- mprotect(mp->vaddr, mp->size + mp->delta, PROT_READ);
-#elif defined(Lynx)
- /* XXX this doesn't allow enable after disable */
- smem_create(NULL, mp->vaddr, mp->size + mp->delta, SM_DETACH);
- smem_remove("XF86DGA");
-#endif
- }
-
- SDL_NAME(XF86DGADirectVideoLL) (dis, screen, enable);
- return 1;
-}
-
-
-static void
-XF86cleanup(int sig)
-{
- ScrPtr sp;
- int i;
- static char beenhere = 0;
-
- if (beenhere)
- _exit(3);
- beenhere = 1;
-
- for (i = 0; i < numScrs; i++) {
- sp = scrList[i];
- SDL_NAME(XF86DGADirectVideo) (sp->display, sp->screen, 0);
- XSync(sp->display, False);
- }
- _exit(3);
-}
-
-Bool
-SDL_NAME(XF86DGAGetVideo) (Display * dis,
- int screen,
- char **addr, int *width, int *bank, int *ram)
-{
- /*unsigned long */ int offset;
- static int beenHere = 0;
- ScrPtr sp;
- MapPtr mp;
-
- if (!(sp = FindScr(dis, screen))) {
- if (!(sp = AddScr())) {
- fprintf(stderr, "XF86DGAGetVideo: malloc failure\n");
- exit(-2);
- }
- sp->display = dis;
- sp->screen = screen;
- sp->map = NULL;
- }
-
- SDL_NAME(XF86DGAGetVideoLL) (dis, screen, &offset, width, bank, ram);
-
- *addr = MapPhysAddress(offset, *bank);
- if (*addr == NULL) {
- fprintf(stderr,
- "XF86DGAGetVideo: failed to map video memory (%s)\n",
- strerror(errno));
- exit(-2);
- }
-
- if ((mp = FindMap(offset, *bank)))
- sp->map = mp;
-
- if (!beenHere) {
- beenHere = 1;
- atexit((void (*)(void)) XF86cleanup);
- /* one shot XF86cleanup attempts */
- signal(SIGSEGV, XF86cleanup);
-#ifdef SIGBUS
- signal(SIGBUS, XF86cleanup);
-#endif
- signal(SIGHUP, XF86cleanup);
- signal(SIGFPE, XF86cleanup);
- }
-
- return 1;
-}
-
-/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/Xext/Xxf86dga/XF86DGA2.c Tue Jul 25 07:25:51 2006 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,937 +0,0 @@
-/* $XFree86: xc/lib/Xxf86dga/XF86DGA2.c,v 1.18 2001/08/17 13:27:51 dawes Exp $ */
-/*
-
-Copyright (c) 1995 Jon Tombs
-Copyright (c) 1995,1996 The XFree86 Project, Inc
-
-*/
-
-/* THIS IS NOT AN X CONSORTIUM STANDARD */
-
-#ifdef __EMX__ /* needed here to override certain constants in X headers */
-#define INCL_DOS
-#define INCL_DOSIOCTL
-#include <os2.h>
-#endif
-
-#define NEED_EVENTS
-#define NEED_REPLIES
-
-#include <X11/Xlibint.h>
-#include "../extensions/xf86dga.h"
-#include "../extensions/xf86dgastr.h"
-#include "../extensions/Xext.h"
-#include "../extensions/extutil.h"
-#include <stdio.h>
-
-#if defined(ENABLE_FBCON) /* Needed for framebuffer console support */
-#include <sys/ioctl.h>
-#include <linux/fb.h>
-#endif
-
-/* If you change this, change the Bases[] array below as well */
-#define MAX_HEADS 16
-
-char *SDL_NAME(xdga_extension_name) = XF86DGANAME;
-
-static XExtensionInfo _xdga_info_data;
-static XExtensionInfo *xdga_info = &_xdga_info_data;
-
-
-Bool SDL_NAME(XDGAMapFramebuffer) (int, char *, unsigned char *, CARD32,
- CARD32, CARD32);
-void SDL_NAME(XDGAUnmapFramebuffer) (int);
-unsigned char *SDL_NAME(XDGAGetMappedMemory) (int);
-
-#define XDGACheckExtension(dpy,i,val) \
- XextCheckExtension (dpy, i, SDL_NAME(xdga_extension_name), val)
-
-/*****************************************************************************
- * *
- * private utility routines *
- * *
- *****************************************************************************/
-
-static int xdga_close_display(Display * dpy, XExtCodes * codes);
-static Bool xdga_wire_to_event(Display * dpy, XEvent * event,
- xEvent * wire_ev);
-static Status xdga_event_to_wire(Display * dpy, XEvent * event,
- xEvent * wire_ev);
-
-static XExtensionHooks xdga_extension_hooks = {
- NULL, /* create_gc */
- NULL, /* copy_gc */
- NULL, /* flush_gc */
- NULL, /* free_gc */
- NULL, /* create_font */
- NULL, /* free_font */
- xdga_close_display, /* close_display */
- xdga_wire_to_event, /* wire_to_event */
- xdga_event_to_wire, /* event_to_wire */
- NULL, /* error */
- NULL, /* error_string */
-};
-
-static
-XEXT_GENERATE_CLOSE_DISPLAY(xdga_close_display, xdga_info)
-XEXT_GENERATE_FIND_DISPLAY(SDL_NAME(xdga_find_display), xdga_info,
- "XFree86-DGA", &xdga_extension_hooks, 0, NULL)
- static Status
- xdga_event_to_wire(Display * dpy, XEvent * event, xEvent * wire_ev)
-{
- return True;
-}
-
-static Bool
-xdga_wire_to_event(Display * dpy, XEvent * event, xEvent * wire_ev)
-{
- dgaEvent *wire = (dgaEvent *) wire_ev;
- SDL_NAME(XDGAButtonEvent) * bevent;
- SDL_NAME(XDGAKeyEvent) * kevent;
- SDL_NAME(XDGAMotionEvent) * mevent;
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
-
- XDGACheckExtension(dpy, info, False);
-
- switch ((wire->u.u.type & 0x7f) - info->codes->first_event) {
- case MotionNotify:
- mevent = (SDL_NAME(XDGAMotionEvent) *) event;
- mevent->type = wire->u.u.type & 0x7F;
- mevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire);
- mevent->display = dpy;
- mevent->screen = wire->u.event.screen;
- mevent->time = wire->u.event.time;
- mevent->state = wire->u.event.state;
- mevent->dx = wire->u.event.dx;
- mevent->dy = wire->u.event.dy;
- return True;
- case ButtonPress:
- case ButtonRelease:
- bevent = (SDL_NAME(XDGAButtonEvent) *) event;
- bevent->type = wire->u.u.type & 0x7F;
- bevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire);
- bevent->display = dpy;
- bevent->screen = wire->u.event.screen;
- bevent->time = wire->u.event.time;
- bevent->state = wire->u.event.state;
- bevent->button = wire->u.u.detail;
- return True;
- case KeyPress:
- case KeyRelease:
- kevent = (SDL_NAME(XDGAKeyEvent) *) event;
- kevent->type = wire->u.u.type & 0x7F;
- kevent->serial = _XSetLastRequestRead(dpy, (xGenericReply *) wire);
- kevent->display = dpy;
- kevent->screen = wire->u.event.screen;
- kevent->time = wire->u.event.time;
- kevent->state = wire->u.event.state;
- kevent->keycode = wire->u.u.detail;
- return True;
- }
-
- return False;
-}
-
-
-Bool SDL_NAME(XDGAQueryExtension) (Display * dpy,
- int *event_basep, int *error_basep)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
-
- if (XextHasExtension(info)) {
- *event_basep = info->codes->first_event;
- *error_basep = info->codes->first_error;
- return True;
- } else {
- return False;
- }
-}
-
-
-Bool SDL_NAME(XDGAQueryVersion) (Display * dpy,
- int *majorVersion, int *minorVersion)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGAQueryVersionReply rep;
- xXDGAQueryVersionReq *req;
-
- XDGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XDGAQueryVersion, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGAQueryVersion;
- if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- *majorVersion = rep.majorVersion;
- *minorVersion = rep.minorVersion;
- UnlockDisplay(dpy);
- SyncHandle();
- if (*majorVersion >= 2) {
- int i, j;
-
- for (i = 0, j = info->codes->first_event;
- i < XF86DGANumberEvents; i++, j++) {
- XESetWireToEvent(dpy, j, xdga_wire_to_event);
- XESetEventToWire(dpy, j, xdga_event_to_wire);
- }
- SDL_NAME(XDGASetClientVersion) (dpy);
- }
- return True;
-}
-
-Bool SDL_NAME(XDGASetClientVersion) (Display * dpy)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGASetClientVersionReq *req;
-
- XDGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XDGASetClientVersion, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGASetClientVersion;
- req->major = XDGA_MAJOR_VERSION;
- req->minor = XDGA_MINOR_VERSION;
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool SDL_NAME(XDGAOpenFramebuffer) (Display * dpy, int screen)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGAOpenFramebufferReply rep;
- xXDGAOpenFramebufferReq *req;
- char *deviceName = NULL;
- Bool ret;
-
- XDGACheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(XDGAOpenFramebuffer, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGAOpenFramebuffer;
- req->screen = screen;
- if (!_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
-
- if (rep.length) {
- deviceName = Xmalloc(rep.length << 2);
- _XRead(dpy, deviceName, rep.length << 2);
- }
-
- ret = SDL_NAME(XDGAMapFramebuffer) (screen, deviceName,
- (unsigned char *) (long) rep.mem1,
- rep.size, rep.offset, rep.extra);
-
- if (deviceName)
- Xfree(deviceName);
-
- UnlockDisplay(dpy);
- SyncHandle();
- return ret;
-}
-
-void SDL_NAME(XDGACloseFramebuffer) (Display * dpy, int screen)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGACloseFramebufferReq *req;
-
- XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
-
- SDL_NAME(XDGAUnmapFramebuffer) (screen);
-
- LockDisplay(dpy);
- GetReq(XDGACloseFramebuffer, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGACloseFramebuffer;
- req->screen = screen;
- UnlockDisplay(dpy);
- SyncHandle();
-}
-
-
-
-SDL_NAME(XDGAMode) * SDL_NAME(XDGAQueryModes) (Display * dpy,
- int screen, int *num)
-{
- XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy);
- xXDGAQueryModesReply rep;
- xXDGAQueryModesReq *req;
- SDL_NAME(XDGAMode) * modes = NULL;
-
- *num = 0;
-
- XDGACheckExtension(dpy, dinfo, NULL);
-
- LockDisplay(dpy);
- GetReq(XDGAQueryModes, req);
- req->reqType = dinfo->codes->major_opcode;
- req->dgaReqType = X_XDGAQueryModes;
- req->screen = screen;
-
- if (_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
- if (rep.length) {
- xXDGAModeInfo info;
- int i, size;
- char *offset;
-
- size = rep.length << 2;
- size -= rep.number * sz_xXDGAModeInfo; /* find text size */
- modes = (SDL_NAME(XDGAMode) *)
- Xmalloc((rep.number * sizeof(SDL_NAME(XDGAMode))) + size);
- offset = (char *) (&modes[rep.number]); /* start of text */
-
-
- if (modes) {
- for (i = 0; i < rep.number; i++) {
- _XRead(dpy, (char *) (&info), sz_xXDGAModeInfo);
-
- modes[i].num = info.num;
- modes[i].verticalRefresh =
- (float) info.vsync_num / (float) info.vsync_den;
- modes[i].flags = info.flags;
- modes[i].imageWidth = info.image_width;
- modes[i].imageHeight = info.image_height;
- modes[i].pixmapWidth = info.pixmap_width;
- modes[i].pixmapHeight = info.pixmap_height;
- modes[i].bytesPerScanline = info.bytes_per_scanline;
- modes[i].byteOrder = info.byte_order;
- modes[i].depth = info.depth;
- modes[i].bitsPerPixel = info.bpp;
- modes[i].redMask = info.red_mask;
- modes[i].greenMask = info.green_mask;
- modes[i].blueMask = info.blue_mask;
- modes[i].visualClass = info.visual_class;
- modes[i].viewportWidth = info.viewport_width;
- modes[i].viewportHeight = info.viewport_height;
- modes[i].xViewportStep = info.viewport_xstep;
- modes[i].yViewportStep = info.viewport_ystep;
- modes[i].maxViewportX = info.viewport_xmax;
- modes[i].maxViewportY = info.viewport_ymax;
- modes[i].viewportFlags = info.viewport_flags;
- modes[i].reserved1 = info.reserved1;
- modes[i].reserved2 = info.reserved2;
-
- _XRead(dpy, offset, info.name_size);
- modes[i].name = offset;
- offset += info.name_size;
- }
- *num = rep.number;
- } else
- _XEatData(dpy, rep.length << 2);
- }
- }
-
- UnlockDisplay(dpy);
- SyncHandle();
-
- return modes;
-}
-
-
-SDL_NAME(XDGADevice) *
-SDL_NAME(XDGASetMode) (Display * dpy, int screen, int mode)
-{
- XExtDisplayInfo *dinfo = SDL_NAME(xdga_find_display) (dpy);
- xXDGASetModeReply rep;
- xXDGASetModeReq *req;
- SDL_NAME(XDGADevice) * dev = NULL;
- Pixmap pid;
-
- XDGACheckExtension(dpy, dinfo, NULL);
-
- LockDisplay(dpy);
- GetReq(XDGASetMode, req);
- req->reqType = dinfo->codes->major_opcode;
- req->dgaReqType = X_XDGASetMode;
- req->screen = screen;
- req->mode = mode;
- req->pid = pid = XAllocID(dpy);
-
- if (_XReply(dpy, (xReply *) & rep, 0, xFalse)) {
- if (rep.length) {
- xXDGAModeInfo info;
- int size;
-
- size = rep.length << 2;
- size -= sz_xXDGAModeInfo; /* get text size */
-
- dev = (SDL_NAME(XDGADevice) *)
- Xmalloc(sizeof(SDL_NAME(XDGADevice)) + size);
-
- if (dev) {
- _XRead(dpy, (char *) (&info), sz_xXDGAModeInfo);
-
- dev->mode.num = info.num;
- dev->mode.verticalRefresh =
- (float) info.vsync_num / (float) info.vsync_den;
- dev->mode.flags = info.flags;
- dev->mode.imageWidth = info.image_width;
- dev->mode.imageHeight = info.image_height;
- dev->mode.pixmapWidth = info.pixmap_width;
- dev->mode.pixmapHeight = info.pixmap_height;
- dev->mode.bytesPerScanline = info.bytes_per_scanline;
- dev->mode.byteOrder = info.byte_order;
- dev->mode.depth = info.depth;
- dev->mode.bitsPerPixel = info.bpp;
- dev->mode.redMask = info.red_mask;
- dev->mode.greenMask = info.green_mask;
- dev->mode.blueMask = info.blue_mask;
- dev->mode.visualClass = info.visual_class;
- dev->mode.viewportWidth = info.viewport_width;
- dev->mode.viewportHeight = info.viewport_height;
- dev->mode.xViewportStep = info.viewport_xstep;
- dev->mode.yViewportStep = info.viewport_ystep;
- dev->mode.maxViewportX = info.viewport_xmax;
- dev->mode.maxViewportY = info.viewport_ymax;
- dev->mode.viewportFlags = info.viewport_flags;
- dev->mode.reserved1 = info.reserved1;
- dev->mode.reserved2 = info.reserved2;
-
- dev->mode.name = (char *) (&dev[1]);
- _XRead(dpy, dev->mode.name, info.name_size);
-
- dev->pixmap = (rep.flags & XDGAPixmap) ? pid : 0;
- dev->data = SDL_NAME(XDGAGetMappedMemory) (screen);
-
- if (dev->data)
- dev->data += rep.offset;
- }
- /* not sure what to do if the allocation fails */
- }
- }
-
- UnlockDisplay(dpy);
- SyncHandle();
-
- return dev;
-}
-
-
-void SDL_NAME(XDGASetViewport) (Display * dpy,
- int screen, int x, int y, int flags)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGASetViewportReq *req;
-
- XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
-
- LockDisplay(dpy);
- GetReq(XDGASetViewport, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGASetViewport;
- req->screen = screen;
- req->x = x;
- req->y = y;
- req->flags = flags;
- UnlockDisplay(dpy);
- SyncHandle();
-}
-
-
-void SDL_NAME(XDGAInstallColormap) (Display * dpy, int screen, Colormap cmap)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGAInstallColormapReq *req;
-
- XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
-
- LockDisplay(dpy);
- GetReq(XDGAInstallColormap, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGAInstallColormap;
- req->screen = screen;
- req->cmap = cmap;
- UnlockDisplay(dpy);
- SyncHandle();
-}
-
-void SDL_NAME(XDGASelectInput) (Display * dpy, int screen, long mask)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGASelectInputReq *req;
-
- XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
-
- LockDisplay(dpy);
- GetReq(XDGASelectInput, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGASelectInput;
- req->screen = screen;
- req->mask = mask;
- UnlockDisplay(dpy);
- SyncHandle();
-}
-
-void SDL_NAME(XDGAFillRectangle) (Display * dpy,
- int screen,
- int x,
- int y,
- unsigned int width,
- unsigned int height, unsigned long color)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGAFillRectangleReq *req;
-
- XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
-
- LockDisplay(dpy);
- GetReq(XDGAFillRectangle, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGAFillRectangle;
- req->screen = screen;
- req->x = x;
- req->y = y;
- req->width = width;
- req->height = height;
- req->color = color;
- UnlockDisplay(dpy);
- SyncHandle();
-}
-
-void SDL_NAME(XDGACopyArea) (Display * dpy,
- int screen,
- int srcx,
- int srcy,
- unsigned int width,
- unsigned int height, int dstx, int dsty)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGACopyAreaReq *req;
-
- XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
-
- LockDisplay(dpy);
- GetReq(XDGACopyArea, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGACopyArea;
- req->screen = screen;
- req->srcx = srcx;
- req->srcy = srcy;
- req->width = width;
- req->height = height;
- req->dstx = dstx;
- req->dsty = dsty;
- UnlockDisplay(dpy);
- SyncHandle();
-}
-
-void SDL_NAME(XDGACopyTransparentArea) (Display * dpy,
- int screen,
- int srcx,
- int srcy,
- unsigned int width,
- unsigned int height,
- int dstx, int dsty, unsigned long key)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGACopyTransparentAreaReq *req;
-
- XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
-
- LockDisplay(dpy);
- GetReq(XDGACopyTransparentArea, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGACopyTransparentArea;
- req->screen = screen;
- req->srcx = srcx;
- req->srcy = srcy;
- req->width = width;
- req->height = height;
- req->dstx = dstx;
- req->dsty = dsty;
- req->key = key;
- UnlockDisplay(dpy);
- SyncHandle();
-}
-
-
-int SDL_NAME(XDGAGetViewportStatus) (Display * dpy, int screen)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGAGetViewportStatusReply rep;
- xXDGAGetViewportStatusReq *req;
- int status = 0;
-
- XDGACheckExtension(dpy, info, 0);
-
- LockDisplay(dpy);
- GetReq(XDGAGetViewportStatus, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGAGetViewportStatus;
- req->screen = screen;
- if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
- status = rep.status;
- UnlockDisplay(dpy);
- SyncHandle();
- return status;
-}
-
-void SDL_NAME(XDGASync) (Display * dpy, int screen)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGASyncReply rep;
- xXDGASyncReq *req;
-
- XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
-
- LockDisplay(dpy);
- GetReq(XDGASync, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGASync;
- req->screen = screen;
- _XReply(dpy, (xReply *) & rep, 0, xFalse);
- UnlockDisplay(dpy);
- SyncHandle();
-}
-
-
-void SDL_NAME(XDGAChangePixmapMode) (Display * dpy,
- int screen, int *x, int *y, int mode)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGAChangePixmapModeReq *req;
- xXDGAChangePixmapModeReply rep;
-
- XextSimpleCheckExtension(dpy, info, SDL_NAME(xdga_extension_name));
-
- LockDisplay(dpy);
- GetReq(XDGAChangePixmapMode, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGAChangePixmapMode;
- req->screen = screen;
- req->x = *x;
- req->y = *y;
- req->flags = mode;
- _XReply(dpy, (xReply *) & rep, 0, xFalse);
- *x = rep.x;
- *y = rep.y;
- UnlockDisplay(dpy);
- SyncHandle();
-}
-
-Colormap SDL_NAME(XDGACreateColormap) (Display * dpy,
- int screen,
- SDL_NAME(XDGADevice) * dev, int alloc)
-{
- XExtDisplayInfo *info = SDL_NAME(xdga_find_display) (dpy);
- xXDGACreateColormapReq *req;
- Colormap cid;
-
- XDGACheckExtension(dpy, info, -1);
-
- LockDisplay(dpy);
- GetReq(XDGACreateColormap, req);
- req->reqType = info->codes->major_opcode;
- req->dgaReqType = X_XDGACreateColormap;
- req->screen = screen;
- req->mode = dev->mode.num;
- req->alloc = alloc;
- cid = req->id = XAllocID(dpy);
- UnlockDisplay(dpy);
- SyncHandle();
-
- return cid;
-}
-
-
-void SDL_NAME(XDGAKeyEventToXKeyEvent) (SDL_NAME(XDGAKeyEvent) * dk,
- XKeyEvent * xk)
-{
- xk->type = dk->type;
- xk->serial = dk->serial;
- xk->send_event = False;
- xk->display = dk->display;
- xk->window = RootWindow(dk->display, dk->screen);
- xk->root = xk->window;
- xk->subwindow = None;
- xk->time = dk->time;
- xk->x = xk->y = xk->x_root = xk->y_root = 0;
- xk->state = dk->state;
- xk->keycode = dk->keycode;
- xk->same_screen = True;
-}
-
-#include <X11/Xmd.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <fcntl.h>
-#if defined(ISC)
-# define HAS_SVR3_MMAP
-# include <sys/types.h>
-# include <errno.h>
-
-# include <sys/at_ansi.h>
-# include <sys/kd.h>
-
-# include <sys/sysmacros.h>
-# include <sys/immu.h>
-# include <sys/region.h>
-
-# include <sys/mmap.h>
-#else
-# if !defined(Lynx)
-# if !defined(__EMX__)
-# include <sys/mman.h>
-# endif
-# else
-# include <sys/types.h>
-# include <errno.h>
-# include <smem.h>
-# endif
-#endif
-#include <sys/wait.h>
-#include <signal.h>
-#include <unistd.h>
-
-#if defined(SVR4) && !defined(sun) && !defined(SCO325)
-#define DEV_MEM "/dev/pmem"
-#elif defined(SVR4) && defined(sun)
-#define DEV_MEM "/dev/xsvc"
-#else
-#define DEV_MEM "/dev/mem"
-#endif
-
-
-
-typedef struct _DGAMapRec
-{
- unsigned char *physical;
- unsigned char *virtual;
- CARD32 size;
- int fd;
- int screen;
- struct _DGAMapRec *next;
-} DGAMapRec, *DGAMapPtr;
-
-static Bool
-DGAMapPhysical(int, char *, unsigned char *, CARD32, CARD32, CARD32,
- DGAMapPtr);
-static void DGAUnmapPhysical(DGAMapPtr);
-
-static DGAMapPtr _Maps = NULL;
-
-
-unsigned char *SDL_NAME(XDGAGetMappedMemory) (int screen)
-{
- DGAMapPtr pMap = _Maps;
- unsigned char *pntr = NULL;
-
- while (pMap != NULL) {
- if (pMap->screen == screen) {
- pntr = pMap->virtual;
- break;
- }
- pMap = pMap->next;
- }
-
- return pntr;
-}
-
-Bool SDL_NAME(XDGAMapFramebuffer) (int screen, char *name, /* optional device name */
- unsigned char *base, /* physical memory */
- CARD32 size, /* size */
- CARD32 offset, /* optional offset */
- CARD32 extra /* optional extra data */
- )
-{
- DGAMapPtr pMap = _Maps;
- Bool result;
-
- /* is it already mapped ? */
- while (pMap != NULL) {
- if (pMap->screen == screen)
- return True;
- pMap = pMap->next;
- }
-
- if (extra & XDGANeedRoot) {
- /* we should probably check if we have root permissions and
- return False here */
-
- }
-
- pMap = (DGAMapPtr) Xmalloc(sizeof(DGAMapRec));
-
- result = DGAMapPhysical(screen, name, base, size, offset, extra, pMap);
-
- if (result) {
- pMap->next = _Maps;
- _Maps = pMap;
- } else
- Xfree(pMap);
-
- return result;
-}
-
-void SDL_NAME(XDGAUnmapFramebuffer) (int screen)
-{
- DGAMapPtr pMap = _Maps;
- DGAMapPtr pPrev = NULL;
-
- /* is it already mapped */
- while (pMap != NULL) {
- if (pMap->screen == screen)
- break;
- pPrev = pMap;
- pMap = pMap->next;
- }
-
- if (!pMap)
- return;
-
- DGAUnmapPhysical(pMap);
-
- if (!pPrev)
- _Maps = pMap->next;
- else
- pPrev->next = pMap->next;
-
- Xfree(pMap);
-}
-
-
-static Bool
-DGAMapPhysical(int screen, char *name, /* optional device name */
- unsigned char *base, /* physical memory */
- CARD32 size, /* size */
- CARD32 offset, /* optional offset */
- CARD32 extra, /* optional extra data */
- DGAMapPtr pMap)
-{
-#if defined(ISC) && defined(HAS_SVR3_MMAP)
- struct kd_memloc mloc;
-#elif defined(__EMX__)
- APIRET rc;
- ULONG action;
- HFILE hfd;
-#endif
-
- base += offset;
-
- pMap->screen = screen;
- pMap->physical = base;
- pMap->size = size;
-
-#if defined(ISC) && defined(HAS_SVR3_MMAP)
- if ((pMap->fd = open("/dev/mmap", O_RDWR)) < 0)
- return False;
- mloc.vaddr = (char *) 0;
- mloc.physaddr = (char *) base;
- mloc.length = size;
- mloc.ioflg = 1;
-
- if ((pMap->virtual = (void *) ioctl(pMap->fd, MAP, &mloc)) == (void *) -1)
- return False;
-#elif defined (__EMX__)
- /*
- * Dragon warning here! /dev/pmap$ is never closed, except on progam exit.
- * Consecutive calling of this routine will make PMAP$ driver run out
- * of memory handles. Some umap/close mechanism should be provided
- */
-
- rc = DosOpen("/dev/pmap$", &hfd, &action, 0, FILE_NORMAL, FILE_OPEN,
- OPEN_ACCESS_READWRITE | OPEN_SHARE_DENYNONE, (PEAOP2) NULL);
- if (rc != 0)
- return False;
- {
- struct map_ioctl
- {
- union
- {
- ULONG phys;
- void *user;
- } a;
- ULONG size;
- } pmap, dmap;
- ULONG plen, dlen;
-#define XFREE86_PMAP 0x76
-#define PMAP_MAP 0x44
-
- pmap.a.phys = base;
- pmap.size = size;
- rc = DosDevIOCtl(hfd, XFREE86_PMAP, PMAP_MAP,
- (PULONG) & pmap, sizeof(pmap), &plen,
- (PULONG) & dmap, sizeof(dmap), &dlen);
- if (rc == 0) {
- pMap->virtual = dmap.a.user;
- }
- }
- if (rc != 0)
- return False;
-#elif defined (Lynx)
- pMap->virtual =
- smem_create("XF86DGA", (char *) base, size, SM_READ | SM_WRITE);
-#else
-#ifndef MAP_FILE
-#define MAP_FILE 0
-#endif
- if (!name)
- name = DEV_MEM;
- if ((pMap->fd = open(name, O_RDWR)) < 0)
-#if defined(ENABLE_FBCON)
- { /* /dev/fb0 fallback added by Sam Lantinga <hercules@lokigames.com> */
- /* Try to fall back to /dev/fb on Linux - FIXME: verify the device */
- struct fb_fix_screeninfo finfo;
-
- if ((pMap->fd = open("/dev/fb0", O_RDWR)) < 0) {
- return False;
- }
- /* The useable framebuffer console memory may not be the whole
- framebuffer that X has access to. :-(
- */
- if (ioctl(pMap->fd, FBIOGET_FSCREENINFO, &finfo) < 0) {
- close(pMap->fd);
- return False;
- }
- /* Warning: On PPC, the size and virtual need to be offset by:
- (((long)finfo.smem_start) -
- (((long)finfo.smem_start)&~(PAGE_SIZE-1)))
- */
- base = 0;
- size = pMap->size = finfo.smem_len;
- }
-#else
- return False;
-#endif
- pMap->virtual = mmap(NULL, size, PROT_READ | PROT_WRITE,
- MAP_FILE | MAP_SHARED, pMap->fd, (off_t) base);
- if (pMap->virtual == (void *) -1)
- return False;
-#endif
-
-#if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
- && !defined(__EMX__)
- mprotect(pMap->virtual, size, PROT_READ | PROT_WRITE);
-#endif
-
- return True;
-}
-
-
-
-static void
-DGAUnmapPhysical(DGAMapPtr pMap)
-{
-#if !defined(ISC) && !defined(HAS_SVR3_MMAP) && !defined(Lynx) \
- && !defined(__EMX__)
- mprotect(pMap->virtual, pMap->size, PROT_READ);
-#elif defined(Lynx)
- /* XXX this doesn't allow enable after disable */
- smem_create(NULL, pMap->virtual, pMap->size, SM_DETACH);
- smem_remove("XF86DGA");
-#endif
-
-
- /* We need to unmap and close too !!!!!!!!!! */
-}
-
-/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/dga/SDL_dgaevents.c Tue Jul 25 07:25:51 2006 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,164 +0,0 @@
-/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 1997-2006 Sam Lantinga
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
-*/
-#include "SDL_config.h"
-
-/* Handle the event stream, converting DGA events into SDL events */
-
-#include <stdio.h>
-#include <X11/Xlib.h>
-#include "../Xext/extensions/xf86dga.h"
-
-#include "../SDL_sysvideo.h"
-#include "../../events/SDL_events_c.h"
-#include "SDL_dgavideo.h"
-#include "SDL_dgaevents_c.h"
-
-/* get function pointers... */
-#include "../x11/SDL_x11dyn.h"
-
-/* Heheh we're using X11 event code */
-extern int X11_Pending(Display * display);
-extern void X11_InitKeymap(void);
-extern SDLKey X11_TranslateKeycode(Display * display, KeyCode kc);
-
-static int
-DGA_DispatchEvent(_THIS)
-{
- int posted;
- SDL_NAME(XDGAEvent) xevent;
-
- XNextEvent(DGA_Display, (XEvent *) & xevent);
-
- posted = 0;
- xevent.type -= DGA_event_base;
- switch (xevent.type) {
-
- /* Mouse motion? */
- case MotionNotify:
- {
- if (SDL_VideoSurface) {
- posted = SDL_PrivateMouseMotion(0, 1,
- xevent.xmotion.dx,
- xevent.xmotion.dy);
- }
- }
- break;
-
- /* Mouse button press? */
- case ButtonPress:
- {
- posted = SDL_PrivateMouseButton(SDL_PRESSED,
- xevent.xbutton.button, 0, 0);
- }
- break;
-
- /* Mouse button release? */
- case ButtonRelease:
- {
- posted = SDL_PrivateMouseButton(SDL_RELEASED,
- xevent.xbutton.button, 0, 0);
- }
- break;
-
- /* Key press? */
- case KeyPress:
- {
- SDL_keysym keysym;
- KeyCode keycode;
- XKeyEvent xkey;
-
- SDL_NAME(XDGAKeyEventToXKeyEvent) (&xevent.xkey, &xkey);
- keycode = xkey.keycode;
-#ifdef DEBUG_XEVENTS
- printf("KeyPress (X11 keycode = 0x%X)\n", xkey.keycode);
-#endif
- /* Get the translated SDL virtual keysym */
- keysym.scancode = keycode;
- keysym.sym = X11_TranslateKeycode(DGA_Display, keycode);
- keysym.mod = KMOD_NONE;
- keysym.unicode = 0;
-
- /* Look up the translated value for the key event */
- if (SDL_TranslateUNICODE) {
- static XComposeStatus state;
- char keybuf[32];
-
- if (XLookupString
- (&xkey, keybuf, sizeof(keybuf), NULL, &state)) {
- /*
- * FIXME: XLookupString() may yield more than one
- * character, so we need a mechanism to allow for
- * this (perhaps null keypress events with a
- * unicode value)
- */
- keysym.unicode = (Uint8) keybuf[0];
- }
- }
- posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
- }
- break;
-
- /* Key release? */
- case KeyRelease:
- {
- SDL_keysym keysym;
- KeyCode keycode;
- XKeyEvent xkey;
-
- SDL_NAME(XDGAKeyEventToXKeyEvent) (&xevent.xkey, &xkey);
- keycode = xkey.keycode;
-#ifdef DEBUG_XEVENTS
- printf("KeyRelease (X11 keycode = 0x%X)\n", xkey.keycode);
-#endif
- /* Get the translated SDL virtual keysym */
- keysym.scancode = keycode;
- keysym.sym = X11_TranslateKeycode(DGA_Display, keycode);
- keysym.mod = KMOD_NONE;
- keysym.unicode = 0;
- posted = SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
- }
- break;
-
- break;
-
- }
- return (posted);
-}
-
-void
-DGA_PumpEvents(_THIS)
-{
- /* Keep processing pending events */
- LOCK_DISPLAY();
- while (X11_Pending(DGA_Display)) {
- DGA_DispatchEvent(this);
- }
- UNLOCK_DISPLAY();
-}
-
-void
-DGA_InitOSKeymap(_THIS)
-{
- X11_InitKeymap();
-}
-
-/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/dga/SDL_dgaevents_c.h Tue Jul 25 07:25:51 2006 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,29 +0,0 @@
-/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 1997-2006 Sam Lantinga
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
-*/
-#include "SDL_config.h"
-
-#include "SDL_dgavideo.h"
-
-/* Functions to be exported */
-extern void DGA_PumpEvents(_THIS);
-extern void DGA_InitOSKeymap(_THIS);
-/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/dga/SDL_dgamouse.c Tue Jul 25 07:25:51 2006 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,37 +0,0 @@
-/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 1997-2006 Sam Lantinga
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
-*/
-#include "SDL_config.h"
-
-#include <stdio.h>
-
-#include "SDL_mouse.h"
-#include "../../events/SDL_events_c.h"
-#include "SDL_dgavideo.h"
-#include "SDL_dgamouse_c.h"
-
-
-/* The implementation dependent data for the window manager cursor */
-struct WMcursor
-{
- int unused;
-};
-/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/dga/SDL_dgamouse_c.h Tue Jul 25 07:25:51 2006 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 1997-2006 Sam Lantinga
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
-*/
-#include "SDL_config.h"
-
-#include "SDL_dgavideo.h"
-
-/* Functions to be exported */
-/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/dga/SDL_dgavideo.c Tue Jul 25 07:25:51 2006 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,1150 +0,0 @@
-/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 1997-2006 Sam Lantinga
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
-*/
-#include "SDL_config.h"
-
-/* DGA 2.0 based SDL video driver implementation.
-*/
-
-#include <stdio.h>
-
-#include <X11/Xlib.h>
-#include "../Xext/extensions/xf86dga.h"
-
-#include "SDL_video.h"
-#include "SDL_mouse.h"
-#include "../SDL_sysvideo.h"
-#include "../SDL_pixels_c.h"
-#include "../../events/SDL_events_c.h"
-#include "SDL_dgavideo.h"
-#include "SDL_dgamouse_c.h"
-#include "SDL_dgaevents_c.h"
-
-/* get function pointers... */
-#include "../x11/SDL_x11dyn.h"
-
-/*#define DGA_DEBUG*/
-
-/* Heheh we're using X11 event code */
-extern void X11_SaveScreenSaver(Display * display, int *saved_timeout,
- BOOL * dpms);
-extern void X11_DisableScreenSaver(Display * display);
-extern void X11_RestoreScreenSaver(Display * display, int saved_timeout,
- BOOL dpms);
-
-/* Initialization/Query functions */
-static int DGA_VideoInit(_THIS, SDL_PixelFormat * vformat);
-static SDL_Rect **DGA_ListModes(_THIS, SDL_PixelFormat * format,
- Uint32 flags);
-static SDL_Surface *DGA_SetVideoMode(_THIS, SDL_Surface * current, int width,
- int height, int bpp, Uint32 flags);
-static int DGA_SetColors(_THIS, int firstcolor, int ncolors,
- SDL_Color * colors);
-static int DGA_SetGammaRamp(_THIS, Uint16 * ramp);
-static void DGA_VideoQuit(_THIS);
-
-/* Hardware surface functions */
-static int DGA_InitHWSurfaces(_THIS, SDL_Surface * screen, Uint8 * base,
- int size);
-static void DGA_FreeHWSurfaces(_THIS);
-static int DGA_AllocHWSurface(_THIS, SDL_Surface * surface);
-static int DGA_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * rect,
- Uint32 color);
-static int DGA_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst);
-static int DGA_LockHWSurface(_THIS, SDL_Surface * surface);
-static void DGA_UnlockHWSurface(_THIS, SDL_Surface * surface);
-static void DGA_FreeHWSurface(_THIS, SDL_Surface * surface);
-static int DGA_FlipHWSurface(_THIS, SDL_Surface * surface);
-
-/* DGA driver bootstrap functions */
-
-static int
-DGA_Available(void)
-{
- const char *display = NULL;
- Display *dpy = NULL;
- int available = 0;
-
- /* The driver is available is available if the display is local
- and the DGA 2.0+ extension is available, and we can map mem.
- */
- if (SDL_X11_LoadSymbols()) {
- if ((SDL_strncmp(XDisplayName(display), ":", 1) == 0) ||
- (SDL_strncmp(XDisplayName(display), "unix:", 5) == 0)) {
- dpy = XOpenDisplay(display);
- if (dpy) {
- int events, errors, major, minor;
-
- if (SDL_NAME(XDGAQueryExtension)
- (dpy, &events, &errors)
- && SDL_NAME(XDGAQueryVersion) (dpy, &major, &minor)) {
- int screen;
-
- screen = DefaultScreen(dpy);
- if ((major >= 2) &&
- SDL_NAME(XDGAOpenFramebuffer) (dpy, screen)) {
- available = 1;
- SDL_NAME(XDGACloseFramebuffer) (dpy, screen);
- }
- }
- XCloseDisplay(dpy);
- }
- }
- SDL_X11_UnloadSymbols();
- }
- return (available);
-}
-
-static void
-DGA_DeleteDevice(SDL_VideoDevice * device)
-{
- if (device != NULL) {
- SDL_free(device->hidden);
- SDL_free(device);
- SDL_X11_UnloadSymbols();
- }
-}
-
-static SDL_VideoDevice *
-DGA_CreateDevice(int devindex)
-{
- SDL_VideoDevice *device = NULL;
-
- /* Initialize all variables that we clean on shutdown */
- if (SDL_X11_LoadSymbols()) {
- device = (SDL_VideoDevice *) SDL_malloc(sizeof(SDL_VideoDevice));
- if (device) {
- SDL_memset(device, 0, (sizeof *device));
- device->hidden = (struct SDL_PrivateVideoData *)
- SDL_malloc((sizeof *device->hidden));
- }
- if ((device == NULL) || (device->hidden == NULL)) {
- SDL_OutOfMemory();
- if (device) {
- SDL_free(device);
- }
- SDL_X11_UnloadSymbols();
- return (0);
- }
- SDL_memset(device->hidden, 0, (sizeof *device->hidden));
-
- /* Set the function pointers */
- device->VideoInit = DGA_VideoInit;
- device->ListModes = DGA_ListModes;
- device->SetVideoMode = DGA_SetVideoMode;
- device->SetColors = DGA_SetColors;
- device->UpdateRects = NULL;
- device->VideoQuit = DGA_VideoQuit;
- device->AllocHWSurface = DGA_AllocHWSurface;
- device->CheckHWBlit = DGA_CheckHWBlit;
- device->FillHWRect = DGA_FillHWRect;
- device->SetHWColorKey = NULL;
- device->SetHWAlpha = NULL;
- device->LockHWSurface = DGA_LockHWSurface;
- device->UnlockHWSurface = DGA_UnlockHWSurface;
- device->FlipHWSurface = DGA_FlipHWSurface;
- device->FreeHWSurface = DGA_FreeHWSurface;
- device->SetGammaRamp = DGA_SetGammaRamp;
- device->GetGammaRamp = NULL;
- device->SetCaption = NULL;
- device->SetIcon = NULL;
- device->IconifyWindow = NULL;
- device->GrabInput = NULL;
- device->GetWMInfo = NULL;
- device->InitOSKeymap = DGA_InitOSKeymap;
- device->PumpEvents = DGA_PumpEvents;
-
- device->free = DGA_DeleteDevice;
- }
-
- return device;
-}
-
-VideoBootStrap DGA_bootstrap = {
- "dga", "XFree86 DGA 2.0",
- DGA_Available, DGA_CreateDevice
-};
-
-static int
-DGA_AddMode(_THIS, int bpp, int w, int h)
-{
- SDL_Rect *mode;
- int index;
- int next_mode;
-
- /* Check to see if we already have this mode */
- if (bpp < 8) { /* Not supported */
- return (0);
- }
- index = ((bpp + 7) / 8) - 1;
- if (SDL_nummodes[index] > 0) {
- mode = SDL_modelist[index][SDL_nummodes[index] - 1];
- if ((mode->w == w) && (mode->h == h)) {
- return (0);
- }
- }
-
- /* Set up the new video mode rectangle */
- mode = (SDL_Rect *) SDL_malloc(sizeof *mode);
- if (mode == NULL) {
- SDL_OutOfMemory();
- return (-1);
- }
- mode->x = 0;
- mode->y = 0;
- mode->w = w;
- mode->h = h;
-
- /* Allocate the new list of modes, and fill in the new mode */
- next_mode = SDL_nummodes[index];
- SDL_modelist[index] = (SDL_Rect **)
- SDL_realloc(SDL_modelist[index],
- (1 + next_mode + 1) * sizeof(SDL_Rect *));
- if (SDL_modelist[index] == NULL) {
- SDL_OutOfMemory();
- SDL_nummodes[index] = 0;
- SDL_free(mode);
- return (-1);
- }
- SDL_modelist[index][next_mode] = mode;
- SDL_modelist[index][next_mode + 1] = NULL;
- SDL_nummodes[index]++;
-
- return (0);
-}
-
-/* This whole function is a hack. :) */
-static Uint32
-get_video_size(_THIS)
-{
- /* This is a non-exported function from libXxf86dga.a */
- extern unsigned char *SDL_NAME(XDGAGetMappedMemory) (int screen);
- FILE *proc;
- unsigned long mem;
- unsigned start, stop;
- char line[BUFSIZ];
- Uint32 size;
-
- mem = (unsigned long) SDL_NAME(XDGAGetMappedMemory) (DGA_Screen);
- size = 0;
- proc = fopen("/proc/self/maps", "r");
- if (proc) {
- while (fgets(line, sizeof(line) - 1, proc)) {
- SDL_sscanf(line, "%x-%x", &start, &stop);
- if (start == mem) {
- size = (Uint32) ((stop - start) / 1024);
- break;
- }
- }
- fclose(proc);
- }
- return (size);
-}
-
-#ifdef DGA_DEBUG
-static void
-PrintMode(SDL_NAME(XDGAMode) * mode)
-{
- printf("Mode: %s (%dx%d) at %d bpp (%f refresh, %d pitch) num: %d\n",
- mode->name,
- mode->viewportWidth, mode->viewportHeight,
- mode->depth == 24 ? mode->bitsPerPixel : mode->depth,
- mode->verticalRefresh, mode->bytesPerScanline, mode->num);
- printf("\tRGB: 0x%8.8x 0x%8.8x 0x%8.8x (%d - %s)\n",
- mode->redMask, mode->greenMask, mode->blueMask,
- mode->visualClass,
- mode->visualClass == TrueColor ? "truecolor" :
- mode->visualClass == DirectColor ? "directcolor" :
- mode->visualClass == PseudoColor ? "pseudocolor" : "unknown");
- printf("\tFlags: ");
- if (mode->flags & XDGAConcurrentAccess)
- printf(" XDGAConcurrentAccess");
- if (mode->flags & XDGASolidFillRect)
- printf(" XDGASolidFillRect");
- if (mode->flags & XDGABlitRect)
- printf(" XDGABlitRect");
- if (mode->flags & XDGABlitTransRect)
- printf(" XDGABlitTransRect");
- if (mode->flags & XDGAPixmap)
- printf(" XDGAPixmap");
- if (mode->flags & XDGAInterlaced)
- printf(" XDGAInterlaced");
- if (mode->flags & XDGADoublescan)
- printf(" XDGADoublescan");
- if (mode->viewportFlags & XDGAFlipRetrace)
- printf(" XDGAFlipRetrace");
- if (mode->viewportFlags & XDGAFlipImmediate)
- printf(" XDGAFlipImmediate");
- printf("\n");
-}
-#endif /* DGA_DEBUG */
-
-static int
-cmpmodes(const void *va, const void *vb)
-{
- const SDL_NAME(XDGAMode) * a = (const SDL_NAME(XDGAMode) *) va;
- const SDL_NAME(XDGAMode) * b = (const SDL_NAME(XDGAMode) *) vb;
-
- if ((a->viewportWidth == b->viewportWidth) &&
- (b->viewportHeight == a->viewportHeight)) {
- /* Prefer 32 bpp over 24 bpp, 16 bpp over 15 bpp */
- int a_bpp = a->depth == 24 ? a->bitsPerPixel : a->depth;
- int b_bpp = b->depth == 24 ? b->bitsPerPixel : b->depth;
- if (a_bpp != b_bpp) {
- return b_bpp - a_bpp;
- }
- /* Prefer DirectColor visuals, for gamma support */
- if (a->visualClass == DirectColor && b->visualClass != DirectColor)
- return -1;
- if (b->visualClass == DirectColor && a->visualClass != DirectColor)
- return 1;
- /* Maintain server refresh rate sorting */
- return a->num - b->num;
- } else if (a->viewportWidth == b->viewportWidth) {
- return b->viewportHeight - a->viewportHeight;
- } else {
- return b->viewportWidth - a->viewportWidth;
- }
-}
-static void
-UpdateHWInfo(_THIS, SDL_NAME(XDGAMode) * mode)
-{
- this->info.wm_available = 0;
- this->info.hw_available = 1;
- if (mode->flags & XDGABlitRect) {
- this->info.blit_hw = 1;
- } else {
- this->info.blit_hw = 0;
- }
- if (mode->flags & XDGABlitTransRect) {
- this->info.blit_hw_CC = 1;
- } else {
- this->info.blit_hw_CC = 0;
- }
- if (mode->flags & XDGASolidFillRect) {
- this->info.blit_fill = 1;
- } else {
- this->info.blit_fill = 0;
- }
- this->info.video_mem = get_video_size(this);
-}
-
-static int
-DGA_VideoInit(_THIS, SDL_PixelFormat * vformat)
-{
- const char *display;
- int event_base, error_base;
- int major_version, minor_version;
- Visual *visual;
- SDL_NAME(XDGAMode) * modes;
- int i, num_modes;
-
- /* Open the X11 display */
- display = NULL; /* Get it from DISPLAY environment variable */
-
- DGA_Display = XOpenDisplay(display);
- if (DGA_Display == NULL) {
- SDL_SetError("Couldn't open X11 display");
- return (-1);
- }
-
- /* Check for the DGA extension */
- if (!SDL_NAME(XDGAQueryExtension) (DGA_Display, &event_base, &error_base)
- || !SDL_NAME(XDGAQueryVersion) (DGA_Display, &major_version,
- &minor_version)) {
- SDL_SetError("DGA extension not available");
- XCloseDisplay(DGA_Display);
- return (-1);
- }
- if (major_version < 2) {
- SDL_SetError("DGA driver requires DGA 2.0 or newer");
- XCloseDisplay(DGA_Display);
- return (-1);
- }
- DGA_event_base = event_base;
-
- /* Determine the current screen size */
- this->info.current_w = DisplayWidth(DGA_Display, DGA_Screen);
- this->info.current_h = DisplayHeight(DGA_Display, DGA_Screen);
-
- /* Determine the current screen depth */
- visual = DefaultVisual(DGA_Display, DGA_Screen);
- {
- XPixmapFormatValues *pix_format;
- int i, num_formats;
-
- vformat->BitsPerPixel = DefaultDepth(DGA_Display, DGA_Screen);
- pix_format = XListPixmapFormats(DGA_Display, &num_formats);
- if (pix_format == NULL) {
- SDL_SetError("Couldn't determine screen formats");
- XCloseDisplay(DGA_Display);
- return (-1);
- }
- for (i = 0; i < num_formats; ++i) {
- if (vformat->BitsPerPixel == pix_format[i].depth)
- break;
- }
- if (i != num_formats)
- vformat->BitsPerPixel = pix_format[i].bits_per_pixel;
- XFree((char *) pix_format);
- }
- if (vformat->BitsPerPixel > 8) {
- vformat->Rmask = visual->red_mask;
- vformat->Gmask = visual->green_mask;
- vformat->Bmask = visual->blue_mask;
- }
-
- /* Open access to the framebuffer */
- if (!SDL_NAME(XDGAOpenFramebuffer) (DGA_Display, DGA_Screen)) {
- SDL_SetError("Unable to map the video memory");
- XCloseDisplay(DGA_Display);
- return (-1);
- }
-
- /* Save DPMS and screensaver settings */
- X11_SaveScreenSaver(DGA_Display, &screensaver_timeout, &dpms_enabled);
- X11_DisableScreenSaver(DGA_Display);
-
- /* Query for the list of available video modes */
- modes = SDL_NAME(XDGAQueryModes) (DGA_Display, DGA_Screen, &num_modes);
- SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
- for (i = 0; i < num_modes; ++i) {
- if (((modes[i].visualClass == PseudoColor) ||
- (modes[i].visualClass == DirectColor) ||
- (modes[i].visualClass == TrueColor)) &&
- !(modes[i].flags & (XDGAInterlaced | XDGADoublescan))) {
-#ifdef DGA_DEBUG
- PrintMode(&modes[i]);
-#endif
- DGA_AddMode(this, modes[i].bitsPerPixel,
- modes[i].viewportWidth, modes[i].viewportHeight);
- }
- }
- UpdateHWInfo(this, modes);
- XFree(modes);
-
- /* Create the hardware surface lock mutex */
- hw_lock = SDL_CreateMutex();
- if (hw_lock == NULL) {
- SDL_SetError("Unable to create lock mutex");
- DGA_VideoQuit(this);
- return (-1);
- }
-#ifdef LOCK_DGA_DISPLAY
- /* Create the event lock so we're thread-safe.. :-/ */
- event_lock = SDL_CreateMutex();
-#endif /* LOCK_DGA_DISPLAY */
-
- /* We're done! */
- return (0);
-}
-
-SDL_Rect **
-DGA_ListModes(_THIS, SDL_PixelFormat * format, Uint32 flags)
-{
- return (SDL_modelist[((format->BitsPerPixel + 7) / 8) - 1]);
-}
-
-/* Various screen update functions available */
-static void DGA_DirectUpdate(_THIS, int numrects, SDL_Rect * rects);
-
-SDL_Surface *
-DGA_SetVideoMode(_THIS, SDL_Surface * current,
- int width, int height, int bpp, Uint32 flags)
-{
- SDL_NAME(XDGAMode) * modes;
- int i, num_modes;
- SDL_NAME(XDGADevice) * mode;
- int screen_len;
- Uint8 *surfaces_mem;
- int surfaces_len;
-
- /* Free any previous colormap */
- if (DGA_colormap) {
- XFreeColormap(DGA_Display, DGA_colormap);
- DGA_colormap = 0;
- }
-
- /* Search for a matching video mode */
- modes = SDL_NAME(XDGAQueryModes) (DGA_Display, DGA_Screen, &num_modes);
- SDL_qsort(modes, num_modes, sizeof *modes, cmpmodes);
- for (i = 0; i < num_modes; ++i) {
- int depth;
-
- depth = modes[i].depth;
- if (depth == 24) { /* Distinguish between 24 and 32 bpp */
- depth = modes[i].bitsPerPixel;
- }
- if ((depth == bpp) &&
- (modes[i].viewportWidth == width) &&
- (modes[i].viewportHeight == height) &&
- ((modes[i].visualClass == PseudoColor) ||
- (modes[i].visualClass == DirectColor) ||
- (modes[i].visualClass == TrueColor)) &&
- !(modes[i].flags & (XDGAInterlaced | XDGADoublescan))) {
- break;
- }
- }
- if (i == num_modes) {
- SDL_SetError("No matching video mode found");
- return (NULL);
- }
-#ifdef DGA_DEBUG
- PrintMode(&modes[i]);
-#endif
-
- /* Set the video mode */
- mode = SDL_NAME(XDGASetMode) (DGA_Display, DGA_Screen, modes[i].num);
- XFree(modes);
- if (mode == NULL) {
- SDL_SetError("Unable to switch to requested mode");
- return (NULL);
- }
- DGA_visualClass = mode->mode.visualClass;
- memory_base = (Uint8 *) mode->data;
- memory_pitch = mode->mode.bytesPerScanline;
-
- /* Set up the new mode framebuffer */
- current->flags = (SDL_FULLSCREEN | SDL_HWSURFACE);
- current->w = mode->mode.viewportWidth;
- current->h = mode->mode.viewportHeight;
- current->pitch = memory_pitch;
- current->pixels = memory_base;
- if (!SDL_ReallocFormat(current, mode->mode.bitsPerPixel,
- mode->mode.redMask,
- mode->mode.greenMask, mode->mode.blueMask, 0)) {
- return (NULL);
- }
- screen_len = current->h * current->pitch;
-
- /* Create a colormap if necessary */
- if ((DGA_visualClass == PseudoColor) || (DGA_visualClass == DirectColor)) {
- DGA_colormap =
- SDL_NAME(XDGACreateColormap) (DGA_Display, DGA_Screen, mode,
- AllocAll);
- if (DGA_visualClass == PseudoColor) {
- current->flags |= SDL_HWPALETTE;
- } else {
- /* Initialize the colormap to the identity mapping */
- SDL_GetGammaRamp(0, 0, 0);
- this->screen = current;
- DGA_SetGammaRamp(this, this->gamma);
- this->screen = NULL;
- }
- } else {
- DGA_colormap =
- SDL_NAME(XDGACreateColormap) (DGA_Display, DGA_Screen, mode,
- AllocNone);
- }
- SDL_NAME(XDGAInstallColormap) (DGA_Display, DGA_Screen, DGA_colormap);
-
- /* Update the hardware capabilities */
- UpdateHWInfo(this, &mode->mode);
-
- /* Set up the information for hardware surfaces */
- surfaces_mem = (Uint8 *) current->pixels + screen_len;
- surfaces_len = (mode->mode.imageHeight * current->pitch - screen_len);
-
- /* Update for double-buffering, if we can */
- SDL_NAME(XDGASetViewport) (DGA_Display, DGA_Screen, 0, 0,
- XDGAFlipRetrace);
- if (flags & SDL_DOUBLEBUF) {
- if (mode->mode.imageHeight >= (current->h * 2)) {
- current->flags |= SDL_DOUBLEBUF;
- flip_page = 0;
- flip_yoffset[0] = 0;
- flip_yoffset[1] = current->h;
- flip_address[0] = memory_base;
- flip_address[1] = memory_base + screen_len;
- surfaces_mem += screen_len;
- surfaces_len -= screen_len;
- }
- }
-
- /* Allocate memory tracking for hardware surfaces */
- DGA_FreeHWSurfaces(this);
- if (surfaces_len < 0) {
- surfaces_len = 0;
- }
- DGA_InitHWSurfaces(this, current, surfaces_mem, surfaces_len);
-
- /* Expose the back buffer as surface memory */
- if (current->flags & SDL_DOUBLEBUF) {
- this->screen = current;
- DGA_FlipHWSurface(this, current);
- this->screen = NULL;
- }
-
- /* Set the update rectangle function */
- this->UpdateRects = DGA_DirectUpdate;
-
- /* Enable mouse and keyboard support */
- {
- long input_mask;
- input_mask = (KeyPressMask | KeyReleaseMask);
- input_mask |= (ButtonPressMask | ButtonReleaseMask);
- input_mask |= PointerMotionMask;
- SDL_NAME(XDGASelectInput) (DGA_Display, DGA_Screen, input_mask);
- }
-
- /* We're done */
- return (current);
-}
-
-#ifdef DGA_DEBUG
-static void
-DGA_DumpHWSurfaces(_THIS)
-{
- vidmem_bucket *bucket;
-
- printf("Memory left: %d (%d total)\n", surfaces_memleft,
- surfaces_memtotal);
- printf("\n");
- printf(" Base Size\n");
- for (bucket = &surfaces; bucket; bucket = bucket->next) {
- printf("Bucket: %p, %d (%s)\n", bucket->base, bucket->size,
- bucket->used ? "used" : "free");
- if (bucket->prev) {
- if (bucket->base != bucket->prev->base + bucket->prev->size) {
- printf("Warning, corrupt bucket list! (prev)\n");
- }
- } else {
- if (bucket != &surfaces) {
- printf("Warning, corrupt bucket list! (!prev)\n");
- }
- }
- if (bucket->next) {
- if (bucket->next->base != bucket->base + bucket->size) {
- printf("Warning, corrupt bucket list! (next)\n");
- }
- }
- }
- printf("\n");
-}
-#endif
-
-static int
-DGA_InitHWSurfaces(_THIS, SDL_Surface * screen, Uint8 * base, int size)
-{
- vidmem_bucket *bucket;
-
- surfaces_memtotal = size;
- surfaces_memleft = size;
-
- if (surfaces_memleft > 0) {
- bucket = (vidmem_bucket *) SDL_malloc(sizeof(*bucket));
- if (bucket == NULL) {
- SDL_OutOfMemory();
- return (-1);
- }
- bucket->prev = &surfaces;
- bucket->used = 0;
- bucket->dirty = 0;
- bucket->base = base;
- bucket->size = size;
- bucket->next = NULL;
- } else {
- bucket = NULL;
- }
-
- surfaces.prev = NULL;
- surfaces.used = 1;
- surfaces.dirty = 0;
- surfaces.base = screen->pixels;
- surfaces.size = (unsigned int) ((long) base - (long) surfaces.base);
- surfaces.next = bucket;
- screen->hwdata = (struct private_hwdata *) &surfaces;
- return (0);
-}
-static void
-DGA_FreeHWSurfaces(_THIS)
-{
- vidmem_bucket *bucket, *freeable;
-
- bucket = surfaces.next;
- while (bucket) {
- freeable = bucket;
- bucket = bucket->next;
- SDL_free(freeable);
- }
- surfaces.next = NULL;
-}
-
-static __inline__ void
-DGA_AddBusySurface(SDL_Surface * surface)
-{
- ((vidmem_bucket *) surface->hwdata)->dirty = 1;
-}
-
-static __inline__ int
-DGA_IsSurfaceBusy(SDL_Surface * surface)
-{
- return ((vidmem_bucket *) surface->hwdata)->dirty;
-}
-
-static __inline__ void
-DGA_WaitBusySurfaces(_THIS)
-{
- vidmem_bucket *bucket;
-
- /* Wait for graphic operations to complete */
- SDL_NAME(XDGASync) (DGA_Display, DGA_Screen);
-
- /* Clear all surface dirty bits */
- for (bucket = &surfaces; bucket; bucket = bucket->next) {
- bucket->dirty = 0;
- }
-}
-
-static int
-DGA_AllocHWSurface(_THIS, SDL_Surface * surface)
-{
- vidmem_bucket *bucket;
- int size;
- int extra;
- int retval = 0;
-
-/* Temporarily, we only allow surfaces the same width as display.
- Some blitters require the pitch between two hardware surfaces
- to be the same. Others have interesting alignment restrictions.
-*/
- if (surface->pitch > SDL_VideoSurface->pitch) {
- SDL_SetError("Surface requested wider than screen");
- return (-1);
- }
- surface->pitch = SDL_VideoSurface->pitch;
- size = surface->h * surface->pitch;
-#ifdef DGA_DEBUG
- fprintf(stderr, "Allocating bucket of %d bytes\n", size);
-#endif
- LOCK_DISPLAY();
-
- /* Quick check for available mem */
- if (size > surfaces_memleft) {
- SDL_SetError("Not enough video memory");
- retval = -1;
- goto done;
- }
-
- /* Search for an empty bucket big enough */
- for (bucket = &surfaces; bucket; bucket = bucket->next) {
- if (!bucket->used && (size <= bucket->size)) {
- break;
- }
- }
- if (bucket == NULL) {
- SDL_SetError("Video memory too fragmented");
- retval = -1;
- goto done;
- }
-
- /* Create a new bucket for left-over memory */
- extra = (bucket->size - size);
- if (extra) {
- vidmem_bucket *newbucket;
-
-#ifdef DGA_DEBUG
- fprintf(stderr, "Adding new free bucket of %d bytes\n", extra);
-#endif
- newbucket = (vidmem_bucket *) SDL_malloc(sizeof(*newbucket));
- if (newbucket == NULL) {
- SDL_OutOfMemory();
- retval = -1;
- goto done;
- }
- newbucket->prev = bucket;
- newbucket->used = 0;
- newbucket->base = bucket->base + size;
- newbucket->size = extra;
- newbucket->next = bucket->next;
- if (bucket->next) {
- bucket->next->prev = newbucket;
- }
- bucket->next = newbucket;
- }
-
- /* Set the current bucket values and return it! */
- bucket->used = 1;
- bucket->size = size;
- bucket->dirty = 0;
-#ifdef DGA_DEBUG
- fprintf(stderr, "Allocated %d bytes at %p\n", bucket->size, bucket->base);
-#endif
- surfaces_memleft -= size;
- surface->flags |= SDL_HWSURFACE;
- surface->pixels = bucket->base;
- surface->hwdata = (struct private_hwdata *) bucket;
- done:
- UNLOCK_DISPLAY();
- return (retval);
-}
-static void
-DGA_FreeHWSurface(_THIS, SDL_Surface * surface)
-{
- vidmem_bucket *bucket, *freeable;
-
- /* Wait for any pending operations involving this surface */
- if (DGA_IsSurfaceBusy(surface)) {
- LOCK_DISPLAY();
- DGA_WaitBusySurfaces(this);
- UNLOCK_DISPLAY();
- }
-
- /* Look for the bucket in the current list */
- for (bucket = &surfaces; bucket; bucket = bucket->next) {
- if (bucket == (vidmem_bucket *) surface->hwdata) {
- break;
- }
- }
- if (bucket && bucket->used) {
- /* Add the memory back to the total */
-#ifdef DGA_DEBUG
- printf("Freeing bucket of %d bytes\n", bucket->size);
-#endif
- surfaces_memleft += bucket->size;
-
- /* Can we merge the space with surrounding buckets? */
- bucket->used = 0;
- if (bucket->next && !bucket->next->used) {
-#ifdef DGA_DEBUG
- printf("Merging with next bucket, for %d total bytes\n",
- bucket->size + bucket->next->size);
-#endif
- freeable = bucket->next;
- bucket->size += bucket->next->size;
- bucket->next = bucket->next->next;
- if (bucket->next) {
- bucket->next->prev = bucket;
- }
- SDL_free(freeable);
- }
- if (bucket->prev && !bucket->prev->used) {
-#ifdef DGA_DEBUG
- printf("Merging with previous bucket, for %d total bytes\n",
- bucket->prev->size + bucket->size);
-#endif
- freeable = bucket;
- bucket->prev->size += bucket->size;
- bucket->prev->next = bucket->next;
- if (bucket->next) {
- bucket->next->prev = bucket->prev;
- }
- SDL_free(freeable);
- }
- }
- surface->pixels = NULL;
- surface->hwdata = NULL;
-}
-
-static __inline__ void
-DGA_dst_to_xy(_THIS, SDL_Surface * dst, int *x, int *y)
-{
- *x = (long) ((Uint8 *) dst->pixels - memory_base) % memory_pitch;
- *y = (long) ((Uint8 *) dst->pixels - memory_base) / memory_pitch;
-}
-
-static int
-DGA_FillHWRect(_THIS, SDL_Surface * dst, SDL_Rect * rect, Uint32 color)
-{
- int x, y;
- unsigned int w, h;
-
- /* Don't fill the visible part of the screen, wait until flipped */
- LOCK_DISPLAY();
- if (was_flipped && (dst == this->screen)) {
- while (SDL_NAME(XDGAGetViewportStatus) (DGA_Display, DGA_Screen))
- /* Keep waiting for the hardware ... */ ;
- was_flipped = 0;
- }
- DGA_dst_to_xy(this, dst, &x, &y);
- x += rect->x;
- y += rect->y;
- w = rect->w;
- h = rect->h;
-#if 0
- printf("Hardware accelerated rectangle fill: %dx%d at %d,%d\n", w, h, x,
- y);
-#endif
- SDL_NAME(XDGAFillRectangle) (DGA_Display, DGA_Screen, x, y, w, h, color);
- if (!(this->screen->flags & SDL_DOUBLEBUF)) {
- XFlush(DGA_Display);
- }
- DGA_AddBusySurface(dst);
- UNLOCK_DISPLAY();
- return (0);
-}
-
-static int
-HWAccelBlit(SDL_Surface * src, SDL_Rect * srcrect,
- SDL_Surface * dst, SDL_Rect * dstrect)
-{
- SDL_VideoDevice *this;
- int srcx, srcy;
- int dstx, dsty;
- unsigned int w, h;
-
- this = current_video;
- /* Don't blit to the visible part of the screen, wait until flipped */
- LOCK_DISPLAY();
- if (was_flipped && (dst == this->screen)) {
- while (SDL_NAME(XDGAGetViewportStatus) (DGA_Display, DGA_Screen))
- /* Keep waiting for the hardware ... */ ;
- was_flipped = 0;
- }
- DGA_dst_to_xy(this, src, &srcx, &srcy);
- srcx += srcrect->x;
- srcy += srcrect->y;
- DGA_dst_to_xy(this, dst, &dstx, &dsty);
- dstx += dstrect->x;
- dsty += dstrect->y;
- w = srcrect->w;
- h = srcrect->h;
-#if 0
- printf("Blitting %dx%d from %d,%d to %d,%d\n", w, h, srcx, srcy, dstx,
- dsty);
-#endif
- if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
- SDL_NAME(XDGACopyTransparentArea) (DGA_Display, DGA_Screen,
- srcx, srcy, w, h, dstx, dsty,
- src->format->colorkey);
- } else {
- SDL_NAME(XDGACopyArea) (DGA_Display, DGA_Screen,
- srcx, srcy, w, h, dstx, dsty);
- }
- if (!(this->screen->flags & SDL_DOUBLEBUF)) {
- XFlush(DGA_Display);
- }
- DGA_AddBusySurface(src);
- DGA_AddBusySurface(dst);
- UNLOCK_DISPLAY();
- return (0);
-}
-
-static int
-DGA_CheckHWBlit(_THIS, SDL_Surface * src, SDL_Surface * dst)
-{
- int accelerated;
-
- /* Set initial acceleration on */
- src->flags |= SDL_HWACCEL;
-
- /* Set the surface attributes */
- if ((src->flags & SDL_SRCALPHA) == SDL_SRCALPHA) {
- if (!this->info.blit_hw_A) {
- src->flags &= ~SDL_HWACCEL;
- }
- }
- if ((src->flags & SDL_SRCCOLORKEY) == SDL_SRCCOLORKEY) {
- if (!this->info.blit_hw_CC) {
- src->flags &= ~SDL_HWACCEL;
- }
- }
-
- /* Check to see if final surface blit is accelerated */
- accelerated = !!(src->flags & SDL_HWACCEL);
- if (accelerated) {
- src->map->hw_blit = HWAccelBlit;
- }
- return (accelerated);
-}
-
-static __inline__ void
-DGA_WaitFlip(_THIS)
-{
- if (was_flipped) {
- while (SDL_NAME(XDGAGetViewportStatus) (DGA_Display, DGA_Screen))
- /* Keep waiting for the hardware ... */ ;
- was_flipped = 0;
- }
-}
-
-static int
-DGA_LockHWSurface(_THIS, SDL_Surface * surface)
-{
- if (surface == this->screen) {
- SDL_mutexP(hw_lock);
- LOCK_DISPLAY();
- if (DGA_IsSurfaceBusy(surface)) {
- DGA_WaitBusySurfaces(this);
- }
- DGA_WaitFlip(this);
- UNLOCK_DISPLAY();
- } else {
- if (DGA_IsSurfaceBusy(surface)) {
- LOCK_DISPLAY();
- DGA_WaitBusySurfaces(this);
- UNLOCK_DISPLAY();
- }
- }
- return (0);
-}
-static void
-DGA_UnlockHWSurface(_THIS, SDL_Surface * surface)
-{
- if (surface == this->screen) {
- SDL_mutexV(hw_lock);
- }
-}
-
-static int
-DGA_FlipHWSurface(_THIS, SDL_Surface * surface)
-{
- /* Wait for vertical retrace and then flip display */
- LOCK_DISPLAY();
- if (DGA_IsSurfaceBusy(this->screen)) {
- DGA_WaitBusySurfaces(this);
- }
- DGA_WaitFlip(this);
- SDL_NAME(XDGASetViewport) (DGA_Display, DGA_Screen,
- 0, flip_yoffset[flip_page], XDGAFlipRetrace);
- XFlush(DGA_Display);
- UNLOCK_DISPLAY();
- was_flipped = 1;
- flip_page = !flip_page;
-
- surface->pixels = flip_address[flip_page];
- return (0);
-}
-
-static void
-DGA_DirectUpdate(_THIS, int numrects, SDL_Rect * rects)
-{
- /* The application is already updating the visible video memory */
- return;
-}
-
-static int
-DGA_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color * colors)
-{
- int i;
- XColor *xcmap;
-
- /* This happens on initialization */
- if (!DGA_colormap) {
- return (0);
- }
- xcmap = SDL_stack_alloc(XColor, ncolors);
- for (i = 0; i < ncolors; ++i) {
- xcmap[i].pixel = firstcolor + i;
- xcmap[i].red = (colors[i].r << 8) | colors[i].r;
- xcmap[i].green = (colors[i].g << 8) | colors[i].g;
- xcmap[i].blue = (colors[i].b << 8) | colors[i].b;
- xcmap[i].flags = (DoRed | DoGreen | DoBlue);
- }
- LOCK_DISPLAY();
- XStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors);
- XSync(DGA_Display, False);
- UNLOCK_DISPLAY();
- SDL_stack_free(xcmap);
-
- /* That was easy. :) */
- return (1);
-}
-
-int
-DGA_SetGammaRamp(_THIS, Uint16 * ramp)
-{
- int i, ncolors;
- XColor xcmap[256];
-
- /* See if actually setting the gamma is supported */
- if (DGA_visualClass != DirectColor) {
- SDL_SetError("Gamma correction not supported on this visual");
- return (-1);
- }
-
- /* Calculate the appropriate palette for the given gamma ramp */
- if (this->screen->format->BitsPerPixel <= 16) {
- ncolors = 64; /* Is this right? */
- } else {
- ncolors = 256;
- }
- for (i = 0; i < ncolors; ++i) {
- Uint8 c = (256 * i / ncolors);
- xcmap[i].pixel = SDL_MapRGB(this->screen->format, c, c, c);
- xcmap[i].red = ramp[0 * 256 + c];
- xcmap[i].green = ramp[1 * 256 + c];
- xcmap[i].blue = ramp[2 * 256 + c];
- xcmap[i].flags = (DoRed | DoGreen | DoBlue);
- }
- LOCK_DISPLAY();
- XStoreColors(DGA_Display, DGA_colormap, xcmap, ncolors);
- XSync(DGA_Display, False);
- UNLOCK_DISPLAY();
- return (0);
-}
-
-void
-DGA_VideoQuit(_THIS)
-{
- int i, j;
-
- if (DGA_Display) {
- /* Free colormap, if necessary */
- if (DGA_colormap) {
- XFreeColormap(DGA_Display, DGA_colormap);
- DGA_colormap = 0;
- }
-
- /* Unmap memory and reset video mode */
- SDL_NAME(XDGACloseFramebuffer) (DGA_Display, DGA_Screen);
- if (this->screen) {
- /* Tell SDL not to free the pixels */
- DGA_FreeHWSurface(this, this->screen);
- }
- SDL_NAME(XDGASetMode) (DGA_Display, DGA_Screen, 0);
-
- /* Clear the lock mutex */
- if (hw_lock != NULL) {
- SDL_DestroyMutex(hw_lock);
- hw_lock = NULL;
- }
-#ifdef LOCK_DGA_DISPLAY
- if (event_lock != NULL) {
- SDL_DestroyMutex(event_lock);
- event_lock = NULL;
- }
-#endif /* LOCK_DGA_DISPLAY */
-
- /* Clean up defined video modes */
- for (i = 0; i < NUM_MODELISTS; ++i) {
- if (SDL_modelist[i] != NULL) {
- for (j = 0; SDL_modelist[i][j]; ++j) {
- SDL_free(SDL_modelist[i][j]);
- }
- SDL_free(SDL_modelist[i]);
- SDL_modelist[i] = NULL;
- }
- }
-
- /* Clean up the memory bucket list */
- DGA_FreeHWSurfaces(this);
-
- /* Restore DPMS and screensaver settings */
- X11_RestoreScreenSaver(DGA_Display, screensaver_timeout,
- dpms_enabled);
-
- /* Close up the display */
- XCloseDisplay(DGA_Display);
- }
-}
-
-/* vi: set ts=4 sw=4 expandtab: */
--- a/src/video/dga/SDL_dgavideo.h Tue Jul 25 07:25:51 2006 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,125 +0,0 @@
-/*
- SDL - Simple DirectMedia Layer
- Copyright (C) 1997-2006 Sam Lantinga
-
- This library is free software; you can redistribute it and/or
- modify it under the terms of the GNU Lesser General Public
- License as published by the Free Software Foundation; either
- version 2.1 of the License, or (at your option) any later version.
-
- This library is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- Lesser General Public License for more details.
-
- You should have received a copy of the GNU Lesser General Public
- License along with this library; if not, write to the Free Software
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
-
- Sam Lantinga
- slouken@libsdl.org
-*/
-#include "SDL_config.h"
-
-#ifndef _SDL_dgavideo_h
-#define _SDL_dgavideo_h
-
-#include <X11/Xlib.h>
-#include <X11/Xproto.h>
-
-#include "SDL_mouse.h"
-#include "SDL_mutex.h"
-#include "../SDL_sysvideo.h"
-
-#if SDL_VIDEO_DRIVER_X11_DPMS
-#include <X11/extensions/dpms.h>
-#endif
-
-/* Hidden "this" pointer for the video functions */
-#define _THIS SDL_VideoDevice *this
-
-/* Define this if you need the DGA driver to be thread-safe */
-#define LOCK_DGA_DISPLAY
-#ifdef LOCK_DGA_DISPLAY
-#define LOCK_DISPLAY() SDL_mutexP(event_lock)
-#define UNLOCK_DISPLAY() SDL_mutexV(event_lock)
-#else
-#define LOCK_DISPLAY()
-#define UNLOCK_DISPLAY()
-#endif
-
-
-/* This is the structure we use to keep track of video memory */
-typedef struct vidmem_bucket
-{
- struct vidmem_bucket *prev;
- int used;
- int dirty;
- Uint8 *base;
- unsigned int size;
- struct vidmem_bucket *next;
-} vidmem_bucket;
-
-/* Private display data */
-struct SDL_PrivateVideoData
-{
- Display *DGA_Display;
- Colormap DGA_colormap;
- int visualClass;
-
-#define NUM_MODELISTS 4 /* 8, 16, 24, and 32 bits-per-pixel */
- int SDL_nummodes[NUM_MODELISTS];
- SDL_Rect **SDL_modelist[NUM_MODELISTS];
-
- /* Information for the video surface */
- Uint8 *memory_base;
- int memory_pitch;
- SDL_mutex *hw_lock;
- int sync_needed;
- int was_flipped;
-
- /* Information for hardware surfaces */
- vidmem_bucket surfaces;
- int surfaces_memtotal;
- int surfaces_memleft;
-
- /* Information for double-buffering */
- int flip_page;
- int flip_yoffset[2];
- Uint8 *flip_address[2];
-
- /* Used to handle DGA events */
- int event_base;
-#ifdef LOCK_DGA_DISPLAY
- SDL_mutex *event_lock;
-#endif
-
- /* Screensaver settings */
- int screensaver_timeout;
- BOOL dpms_enabled;
-};
-/* Old variable names */
-#define DGA_Display (this->hidden->DGA_Display)
-#define DGA_Screen DefaultScreen(DGA_Display)
-#define DGA_colormap (this->hidden->DGA_colormap)
-#define DGA_visualClass (this->hidden->visualClass)
-#define memory_base (this->hidden->memory_base)
-#define memory_pitch (this->hidden->memory_pitch)
-#define flip_page (this->hidden->flip_page)
-#define flip_yoffset (this->hidden->flip_yoffset)
-#define flip_address (this->hidden->flip_address)
-#define sync_needed (this->hidden->sync_needed)
-#define was_flipped (this->hidden->was_flipped)
-#define SDL_nummodes (this->hidden->SDL_nummodes)
-#define SDL_modelist (this->hidden->SDL_modelist)
-#define surfaces (this->hidden->surfaces)
-#define surfaces_memtotal (this->hidden->surfaces_memtotal)
-#define surfaces_memleft (this->hidden->surfaces_memleft)
-#define hw_lock (this->hidden->hw_lock)
-#define DGA_event_base (this->hidden->event_base)
-#define event_lock (this->hidden->event_lock)
-#define screensaver_timeout (this->hidden->screensaver_timeout)
-#define dpms_enabled (this->hidden->dpms_enabled)
-
-#endif /* _SDL_dgavideo_h */
-/* vi: set ts=4 sw=4 expandtab: */