From feb735c5bb0cd391136f1c73476703dff82dc9b0 Mon Sep 17 00:00:00 2001 From: Dave Airlie Date: Fri, 23 Dec 2005 02:07:58 +0000 Subject: Well there were a couple of snapshots later than CVS available outside of Novell, so I've done a crazy merge to try and get them into a workable CVS, I suspect I may have failed.. there is a pre-xgldrop-merge tag if I did. --- hw/xgl/Makefile.am | 31 +- hw/xgl/egl/Makefile.am | 43 +- hw/xgl/egl/evdev.c | 76 +- hw/xgl/egl/kinput.c | 15 +- hw/xgl/egl/module/Makefile.am | 14 + hw/xgl/egl/module/xeglmodule.c | 104 + hw/xgl/egl/xegl.c | 621 +---- hw/xgl/egl/xegl.h | 251 +- hw/xgl/egl/xeglinit.c | 131 + hw/xgl/glx/Makefile.am | 31 +- hw/xgl/glx/module/Makefile.am | 14 + hw/xgl/glx/module/xglxmodule.c | 104 + hw/xgl/glx/xglx.c | 99 +- hw/xgl/glx/xglx.h | 64 + hw/xgl/glx/xglxinit.c | 131 + hw/xgl/glxext/Makefile.am | 13 + hw/xgl/glxext/module/Makefile.am | 19 + hw/xgl/glxext/module/glcoremodule.c | 38 + hw/xgl/glxext/module/glxmodule.c | 38 + hw/xgl/glxext/xglglxext.c | 5068 +++++++++++++++++++++++++++++++++++ hw/xgl/glxext/xglglxext.h | 38 + hw/xgl/xgl.h | 66 +- hw/xgl/xglcmap.c | 2 +- hw/xgl/xglglx.c | 4911 --------------------------------- hw/xgl/xglhash.c | 108 +- hw/xgl/xglinit.c | 287 ++ hw/xgl/xglloader.c | 129 + hw/xgl/xglmodule.h | 45 + hw/xgl/xglparse.c | 82 +- hw/xgl/xglpixmap.c | 30 +- hw/xgl/xglscreen.c | 33 +- hw/xgl/xglsync.c | 45 +- hw/xgl/xgltrap.c | 2 +- 33 files changed, 6875 insertions(+), 5808 deletions(-) create mode 100644 hw/xgl/egl/module/Makefile.am create mode 100644 hw/xgl/egl/module/xeglmodule.c create mode 100644 hw/xgl/egl/xeglinit.c create mode 100644 hw/xgl/glx/module/Makefile.am create mode 100644 hw/xgl/glx/module/xglxmodule.c create mode 100644 hw/xgl/glx/xglx.h create mode 100644 hw/xgl/glx/xglxinit.c create mode 100644 hw/xgl/glxext/Makefile.am create mode 100644 hw/xgl/glxext/module/Makefile.am create mode 100644 hw/xgl/glxext/module/glcoremodule.c create mode 100644 hw/xgl/glxext/module/glxmodule.c create mode 100644 hw/xgl/glxext/xglglxext.c create mode 100644 hw/xgl/glxext/xglglxext.h delete mode 100644 hw/xgl/xglglx.c create mode 100644 hw/xgl/xglinit.c create mode 100644 hw/xgl/xglloader.c create mode 100644 hw/xgl/xglmodule.h (limited to 'hw') diff --git a/hw/xgl/Makefile.am b/hw/xgl/Makefile.am index 0228c0d0a..3fc5f5915 100644 --- a/hw/xgl/Makefile.am +++ b/hw/xgl/Makefile.am @@ -1,17 +1,26 @@ -if XGLXSERVER +if GLX +GLX_SUBDIRS = glxext +endif + +if XGLX XGLX_SUBDIRS = glx endif -if XEGLSERVER +if XEGL XEGL_SUBDIRS = egl endif -SUBDIRS = . $(XGLX_SUBDIRS) $(XEGL_SUBDIRS) +SUBDIRS = \ + . \ + $(GLX_SUBDIRS) \ + $(XGLX_SUBDIRS) \ + $(XEGL_SUBDIRS) INCLUDES = \ @XGL_INCS@ \ @XSERVER_CFLAGS@ \ - @XGLSERVER_CFLAGS@ + @XGLSERVER_CFLAGS@ \ + -DMODULEPATH=\"@MODULEPATH@\" noinst_LIBRARIES = libxgl.a @@ -40,4 +49,18 @@ libxgl_a_SOURCES = \ xglglyph.c \ xgltrap.c \ xglhash.c \ + xglloader.c \ xglglx.c + +if XGLSERVER +Xgl_DEPENDENCIES = @XGL_LIBS@ +Xgl_LDFLAGS = -export-dynamic +Xgl_SOURCES = xglinit.c +Xgl_LDADD = \ + @XGL_LIBS@ \ + @XSERVER_LIBS@ \ + @XGLSERVER_LIBS@ +Xgl_programs = Xgl +endif + +bin_PROGRAMS = $(Xgl_programs) diff --git a/hw/xgl/egl/Makefile.am b/hw/xgl/egl/Makefile.am index d51b8bc90..8a9b9f539 100644 --- a/hw/xgl/egl/Makefile.am +++ b/hw/xgl/egl/Makefile.am @@ -1,22 +1,37 @@ +if XGLSERVER +MODULE_SUBDIRS = module +endif + +SUBDIRS = \ + . \ + $(MODULE_SUBDIRS) + INCLUDES = \ - @XGL_INCS@ \ + @XEGL_INCS@ \ @XSERVER_CFLAGS@ \ - @XGLXSERVER_CFLAGS@ + @XGLSERVER_CFLAGS@ \ + @XEGLSERVER_CFLAGS@ -bin_PROGRAMS = Xegl +noinst_LTLIBRARIES = libxegl.la -Xegl_SOURCES = \ - xegl.h \ - xegl.c \ - xeglinput.c \ - kkeymap.h \ - kinput.c \ +libxegl_la_SOURCES = \ + xegl.h \ + xegl.c \ + xeglinput.c \ + kkeymap.h \ + kinput.c \ evdev.c -Xegl_LDADD = \ - @XGL_LIBS@ \ - @XSERVER_LIBS@ \ +if XEGLSERVER +Xegl_DEPENDENCIES = @XEGL_LIBS@ +Xegl_LDFLAGS = -export-dynamic +Xegl_SOURCES = xeglinit.c +Xegl_LDADD = \ + @XEGL_LIBS@ \ + @XSERVER_LIBS@ \ + @XGLSERVER_LIBS@ \ @XEGLSERVER_LIBS@ +Xegl_programs = Xegl +endif -Xegl_DEPENDENCIES = @XGL_LIBS@ - +bin_PROGRAMS = $(Xegl_programs) diff --git a/hw/xgl/egl/evdev.c b/hw/xgl/egl/evdev.c index 634be73c4..43ccfb051 100644 --- a/hw/xgl/egl/evdev.c +++ b/hw/xgl/egl/evdev.c @@ -112,7 +112,7 @@ EvdevRead (int evdevPort, void *closure) { KdMouseInfo *mi = closure; Kevdev *ke = mi->driver; - int i, n; + int i, n, f = 0; struct input_event events[NUM_EVENTS]; n = read (evdevPort, &events, NUM_EVENTS * sizeof (struct input_event)); @@ -131,46 +131,26 @@ EvdevRead (int evdevPort, void *closure) ErrorF ("key %d %d\n", events[i].code, events[i].value); else ErrorF ("key 0x%x %d\n", events[i].code, events[i].value); - - if (events[i].value==1) { - switch (events[i].code) { - case BTN_LEFT: - flags |= KD_BUTTON_1; + switch (events[i].code) { + case BTN_LEFT: + f = KD_BUTTON_1; break; - case BTN_RIGHT: - flags |= KD_BUTTON_3; + case BTN_RIGHT: + f = KD_BUTTON_2; break; - case BTN_MIDDLE: - flags |= KD_BUTTON_2; + case BTN_MIDDLE: + f = KD_BUTTON_3; break; - case BTN_FORWARD: - flags |= KD_BUTTON_4; + case BTN_FORWARD: + f = KD_BUTTON_4; break; - case BTN_BACK: - flags |= KD_BUTTON_5; + case BTN_BACK: + f = KD_BUTTON_5; break; - } - } - else if (events[i].value==0) { - switch (events[i].code) { - case BTN_LEFT: - flags &= ~KD_BUTTON_1; - break; - case BTN_RIGHT: - flags &= ~KD_BUTTON_3; - break; - case BTN_MIDDLE: - flags &= ~KD_BUTTON_2; - break; - case BTN_FORWARD: - flags &= ~KD_BUTTON_4; - break; - case BTN_BACK: - flags &= ~KD_BUTTON_5; - break; - } - } - KdEnqueueMouseEvent (mi, KD_MOUSE_DELTA | flags, 0, 0); + } + flags |= f; + KdEnqueueMouseEvent (mi, KD_MOUSE_DELTA | flags, 0, 0); + ErrorF("Flags is %x\n", flags); break; case EV_REL: ke->rel[events[i].code] += events[i].value; @@ -186,12 +166,12 @@ EvdevRead (int evdevPort, void *closure) int EvdevInputType; char *kdefaultEvdev[] = { - // "/dev/input/event0", - "/dev/input/event1", - // "/dev/input/event2", - // "/dev/input/event3", - // "/dev/input/event4", - // "/dev/input/event5", +// "/dev/input/event0", +// "/dev/input/event1", +// "/dev/input/event2", +// "/dev/input/event3", +// "/dev/input/event4", + "/dev/input/event5", }; #define NUM_DEFAULT_EVDEV (sizeof (kdefaultEvdev) / sizeof (kdefaultEvdev[0])) @@ -497,12 +477,12 @@ EvdevRead1 (int evdevPort, void *closure) } char *kdefaultEvdev1[] = { - "/dev/input/event0", - // "/dev/input/event1", - // "/dev/input/event2", - // "/dev/input/event3", - // "/dev/input/event4", - // "/dev/input/event5", +// "/dev/input/event0", +// "/dev/input/event1", +// "/dev/input/event2", + "/dev/input/event3", +// "/dev/input/event4", +// "/dev/input/event5", }; #define NUM_DEFAULT_EVDEV1 (sizeof (kdefaultEvdev1) / sizeof (kdefaultEvdev1[0])) diff --git a/hw/xgl/egl/kinput.c b/hw/xgl/egl/kinput.c index 231331941..5cf4b688e 100644 --- a/hw/xgl/egl/kinput.c +++ b/hw/xgl/egl/kinput.c @@ -30,7 +30,6 @@ #include #include -#include "xgl.h" #include "xegl.h" #include "mipointer.h" #include "inputstr.h" @@ -348,7 +347,7 @@ KdMouseProc(DeviceIntPtr pDevice, int onoff) } Bool -LegalModifier(unsigned int key, DevicePtr pDev) +KdLegalModifier(unsigned int key, DevicePtr pDev) { return TRUE; } @@ -1518,12 +1517,10 @@ KdBlockHandler (int screen, } void -KdWakeupHandler (int screen, - pointer data, - unsigned long lresult, - pointer readmask) +KdWakeupHandler (pointer data, + int result, + pointer readmask) { - int result = (int) lresult; fd_set *pReadmask = (fd_set *) readmask; int i; KdMouseInfo *mi; @@ -1555,7 +1552,7 @@ KdWakeupHandler (int screen, // kdProcessSwitch (); } -#define KdScreenOrigin(pScreen) (&(KdGetScreenPriv(pScreen)->screen->origin)) +#define KdScreenOrigin(pScreen) (&(KdGetScreenPriv (pScreen)->origin)) static Bool KdCursorOffScreen(ScreenPtr *ppScreen, int *x, int *y) @@ -1673,7 +1670,7 @@ miPointerScreenFuncRec kdPointerScreenFuncs = }; void -ProcessInputEvents () +KdProcessInputEvents (void) { mieqProcessInputEvents(); miPointerUpdate(); diff --git a/hw/xgl/egl/module/Makefile.am b/hw/xgl/egl/module/Makefile.am new file mode 100644 index 000000000..c321926ba --- /dev/null +++ b/hw/xgl/egl/module/Makefile.am @@ -0,0 +1,14 @@ +INCLUDES = \ + @XEGL_INCS@ \ + @XSERVER_CFLAGS@ \ + @XEGLSERVER_CFLAGS@ + +libxegl_la_LDFLAGS = -avoid-version +libxegl_la_SOURCES = xeglmodule.c +libxegl_la_LIBADD = \ + @XEGL_MOD_LIBS@ \ + @XEGLSERVER_LIBS@ + +moduledir = @MODULEPATH@/xgl + +module_LTLIBRARIES = libxegl.la \ No newline at end of file diff --git a/hw/xgl/egl/module/xeglmodule.c b/hw/xgl/egl/module/xeglmodule.c new file mode 100644 index 000000000..ff695f614 --- /dev/null +++ b/hw/xgl/egl/module/xeglmodule.c @@ -0,0 +1,104 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#include "xglmodule.h" +#include "xegl.h" + +#include + +char * +moduleVersion (void) +{ + return VERSION; +} + +Bool +moduleInit (const char *module) +{ + glitz_egl_init (module); + + return TRUE; +} + +void +InitOutput (ScreenInfo *pScreenInfo, + int argc, + char **argv) +{ + xeglInitOutput (pScreenInfo, argc, argv); +} + +Bool +LegalModifier (unsigned int key, + DevicePtr pDev) +{ + return xeglLegalModifier (key, pDev); +} + +void +ProcessInputEvents (void) +{ + xeglProcessInputEvents (); +} + +void +InitInput (int argc, + char **argv) +{ + xeglInitInput (argc, argv); +} + +void +ddxUseMsg (void) +{ + ErrorF ("\nXegl usage:\n"); + xeglUseMsg (); +} + +int +ddxProcessArgument (int argc, + char **argv, + int i) +{ + return xeglProcessArgument (argc, argv, i); +} + +void +AbortDDX (void) +{ + xeglAbort (); +} + +void +ddxGiveUp (void) +{ + xeglGiveUp (); +} + +void +OsVendorInit (void) +{ + xeglOsVendorInit (); +} diff --git a/hw/xgl/egl/xegl.c b/hw/xgl/egl/xegl.c index 2f4b900d6..43908bdbb 100644 --- a/hw/xgl/egl/xegl.c +++ b/hw/xgl/egl/xegl.c @@ -33,7 +33,6 @@ #include -#include "xgl.h" #include "inputstr.h" #include "cursorstr.h" #include "mipointer.h" @@ -46,7 +45,7 @@ int xeglScreenGeneration = -1; int xeglScreenPrivateIndex; -#define XEGL_GET_SCREEN_PRIV(pScreen) \ +#define XEGL_GET_SCREEN_PRIV(pScreen) \ ((xeglScreenPtr) (pScreen)->devPrivates[xeglScreenPrivateIndex].ptr) #define XEGL_SET_SCREEN_PRIV(pScreen, v) \ @@ -55,34 +54,10 @@ int xeglScreenPrivateIndex; #define XEGL_SCREEN_PRIV(pScreen) \ xeglScreenPtr pScreenPriv = XEGL_GET_SCREEN_PRIV (pScreen) -typedef struct _xeglCursor { - Cursor cursor; -} xeglCursorRec, *xeglCursorPtr; - -#define XEGL_GET_CURSOR_PRIV(pCursor, pScreen) \ - ((xeglCursorPtr) (pCursor)->devPriv[(pScreen)->myNum]) - -#define XEGL_SET_CURSOR_PRIV(pCursor, pScreen, v) \ - ((pCursor)->devPriv[(pScreen)->myNum] = (pointer) v) - -#define XEGL_CURSOR_PRIV(pCursor, pScreen) \ - xeglCursorPtr pCursorPriv = XEGL_GET_CURSOR_PRIV (pCursor, pScreen) - -char *xDisplayName = NULL; -EGLDisplay xdisplay; -EGLScreenMESA xscreen; -glitz_format_t *xeglCurrentFormat; -CARD32 lastEventTime = 0; -ScreenPtr currentScreen = NULL; -Bool softCursor = TRUE; -xglScreenInfoRec xglScreenInfo = { - NULL, 0, 0, 0, 0, FALSE, - DEFAULT_GEOMETRY_DATA_TYPE, - DEFAULT_GEOMETRY_USAGE, - FALSE, - XGL_DEFAULT_PBO_MASK, - FALSE -}; +static EGLDisplay eDisplay; +static EGLScreenMESA eScreen; +static ScreenPtr currentScreen = 0; +static Bool softCursor = TRUE; extern miPointerScreenFuncRec kdPointerScreenFuncs; @@ -97,7 +72,7 @@ xeglAllocatePrivates (ScreenPtr pScreen) if (xeglScreenPrivateIndex < 0) return FALSE; - xeglScreenGeneration = serverGeneration; + xeglScreenGeneration = serverGeneration; } pScreenPriv = xalloc (sizeof (xeglScreenRec)); @@ -109,189 +84,6 @@ xeglAllocatePrivates (ScreenPtr pScreen) return TRUE; } -static void -xeglConstrainCursor (ScreenPtr pScreen, - BoxPtr pBox) -{ -} - -static void -xeglCursorLimits (ScreenPtr pScreen, - CursorPtr pCursor, - BoxPtr pHotBox, - BoxPtr pTopLeftBox) -{ - *pTopLeftBox = *pHotBox; -} - -static Bool -xeglDisplayCursor (ScreenPtr pScreen, - CursorPtr pCursor) -{ -#if 0 - XEGL_SCREEN_PRIV (pScreen); - XEGL_CURSOR_PRIV (pCursor, pScreen); - - XDefineCursor (xdisplay, pScreenPriv->win, pCursorPriv->cursor); -#endif - return TRUE; -} - -#ifdef ARGB_CURSOR - -static Bool -xeglARGBCursorSupport (void); - -static Cursor -xeglCreateARGBCursor (ScreenPtr pScreen, - CursorPtr pCursor); - -#endif - -static Bool -xeglRealizeCursor (ScreenPtr pScreen, - CursorPtr pCursor) -{ -#if 0 - xeglCursorPtr pCursorPriv; - XImage *ximage; - Pixmap source, mask; - XColor fgColor, bgColor; - GC xgc; - unsigned long valuemask; - XGCValues values; - - XEGL_SCREEN_PRIV (pScreen); - - valuemask = GCForeground | GCBackground; - - values.foreground = 1L; - values.background = 0L; - - pCursorPriv = xalloc (sizeof (xeglCursorRec)); - if (!pCursorPriv) - return FALSE; - - XEGL_SET_CURSOR_PRIV (pCursor, pScreen, pCursorPriv); - -#ifdef ARGB_CURSOR - if (pCursor->bits->argb) - { - pCursorPriv->cursor = xeglCreateARGBCursor (pScreen, pCursor); - if (pCursorPriv->cursor) - return TRUE; - } -#endif - - source = XCreatePixmap (xdisplay, - pScreenPriv->win, - pCursor->bits->width, - pCursor->bits->height, - 1); - - mask = XCreatePixmap (xdisplay, - pScreenPriv->win, - pCursor->bits->width, - pCursor->bits->height, - 1); - - xgc = XCreateGC (xdisplay, source, valuemask, &values); - - ximage = XCreateImage (xdisplay, - DefaultVisual (xdisplay, xscreen), - 1, XYBitmap, 0, - (char *) pCursor->bits->source, - pCursor->bits->width, - pCursor->bits->height, - BitmapPad (xdisplay), 0); - - XPutImage (xdisplay, source, xgc, ximage, - 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height); - - XFree (ximage); - - ximage = XCreateImage (xdisplay, - DefaultVisual (xdisplay, xscreen), - 1, XYBitmap, 0, - (char *) pCursor->bits->mask, - pCursor->bits->width, - pCursor->bits->height, - BitmapPad (xdisplay), 0); - - XPutImage (xdisplay, mask, xgc, ximage, - 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height); - - XFree (ximage); - XFreeGC (xdisplay, xgc); - - fgColor.red = pCursor->foreRed; - fgColor.green = pCursor->foreGreen; - fgColor.blue = pCursor->foreBlue; - - bgColor.red = pCursor->backRed; - bgColor.green = pCursor->backGreen; - bgColor.blue = pCursor->backBlue; - - pCursorPriv->cursor = - XCreatePixmapCursor (xdisplay, source, mask, &fgColor, &bgColor, - pCursor->bits->xhot, pCursor->bits->yhot); - - XFreePixmap (xdisplay, mask); - XFreePixmap (xdisplay, source); -#endif - return TRUE; -} - -static Bool -xeglUnrealizeCursor (ScreenPtr pScreen, - CursorPtr pCursor) -{ -#if 0 - XEGL_CURSOR_PRIV (pCursor, pScreen); - - XFreeCursor (xdisplay, pCursorPriv->cursor); - xfree (pCursorPriv); -#endif - return TRUE; -} - -static void -xeglRecolorCursor (ScreenPtr pScreen, - CursorPtr pCursor, - Bool displayed) -{ -#if 0 - XColor fgColor, bgColor; - - XEGL_CURSOR_PRIV (pCursor, pScreen); - - fgColor.red = pCursor->foreRed; - fgColor.green = pCursor->foreGreen; - fgColor.blue = pCursor->foreBlue; - - bgColor.red = pCursor->backRed; - bgColor.green = pCursor->backGreen; - bgColor.blue = pCursor->backBlue; - - XRecolorCursor (xdisplay, pCursorPriv->cursor, &fgColor, &bgColor); -#endif -} - -static Bool -xeglSetCursorPosition (ScreenPtr pScreen, - int x, - int y, - Bool generateEvent) -{ -#if 0 - XEGL_SCREEN_PRIV (pScreen); - - XWarpPointer (xdisplay, pScreenPriv->win, pScreenPriv->win, - 0, 0, 0, 0, x, y); -#endif - return TRUE; -} - static Bool xeglCloseScreen (int index, ScreenPtr pScreen) @@ -305,135 +97,29 @@ xeglCloseScreen (int index, glitz_drawable_destroy (drawable); xglClearVisualTypes (); -#if 0 - if (pScreenPriv->win) - XDestroyWindow (xdisplay, pScreenPriv->win); - if (pScreenPriv->colormap) - XFreeColormap (xdisplay, pScreenPriv->colormap); -#endif XGL_SCREEN_UNWRAP (CloseScreen); xfree (pScreenPriv); return (*pScreen->CloseScreen) (index, pScreen); } -static Bool -xeglCursorOffScreen (ScreenPtr *ppScreen, int *x, int *y) -{ - return FALSE; -} - -static void -xeglCrossScreen (ScreenPtr pScreen, Bool entering) -{ -} - -static void -xeglWarpCursor (ScreenPtr pScreen, int x, int y) -{ - miPointerWarpCursor (pScreen, x, y); -} - -miPointerScreenFuncRec xeglPointerScreenFuncs = { - xeglCursorOffScreen, - xeglCrossScreen, - xeglWarpCursor -}; - -static void -xeglMoveCursor(ScreenPtr pScreen, int x, int y) -{ -} - - -#define FB_CUR_SETIMAGE 0x01 -#define FB_CUR_SETPOS 0x02 -#define FB_CUR_SETHOT 0x04 -#define FB_CUR_SETCMAP 0x08 -#define FB_CUR_SETSHAPE 0x10 -#define FB_CUR_SETSIZE 0x20 -#define FB_CUR_SETALL 0xFF - -struct fbcurpos { - unsigned short x, y; -}; - -struct fb_cmap_user { - unsigned long start; /* First entry */ - unsigned long len; /* Number of entries */ - unsigned short *red; /* Red values */ - unsigned short *green; - unsigned short *blue; - unsigned short *transp; /* transparency, can be NULL */ -}; - -struct fb_image_user { - unsigned long dx; /* Where to place image */ - unsigned long dy; - unsigned long width; /* Size of image */ - unsigned long height; - unsigned long fg_color; /* Only used when a mono bitmap */ - unsigned long bg_color; - unsigned char depth; /* Depth of the image */ - const char *data; /* Pointer to image data */ - struct fb_cmap_user cmap; /* color map info */ -}; - -struct fb_cursor_user { - unsigned short set; /* what to set */ - unsigned short enable; /* cursor on/off */ - unsigned short rop; /* bitop operation */ - const char *mask; /* cursor mask bits */ - struct fbcurpos hot; /* cursor hot spot */ - struct fb_image_user image; /* Cursor image */ -}; -#define FBIO_CURSOR _IOWR('F', 0x08, struct fb_cursor_user) - - -static void -xeglSetCursor(ScreenPtr pScreen, CursorPtr pCursor, int x, int y) -{ -#if 0 - int fd, err; - struct fb_cursor_user cursor; - - fd = open("/dev/fb0", O_RDWR); - memset(&cursor, 0, sizeof(cursor)); - cursor.set = FB_CUR_SETPOS; - cursor.image.dx = 50; - cursor.image.dy = 50; - cursor.enable = 1; - err = ioctl(fd, FBIO_CURSOR, &cursor); - err = errno; - printf("errno %d\n", err); - close(fd); -#endif -} - -miPointerSpriteFuncRec eglPointerSpriteFuncs = { - xeglRealizeCursor, - xeglUnrealizeCursor, - xeglSetCursor, - xeglMoveCursor, -}; - static Bool xeglScreenInit (int index, ScreenPtr pScreen, int argc, char **argv) { - EGLSurface screen_surf; - EGLModeMESA mode; - int count; + EGLSurface eSurface; + EGLModeMESA mode; + int count; xeglScreenPtr pScreenPriv; glitz_drawable_format_t *format; glitz_drawable_t *drawable; const EGLint screenAttribs[] = { - EGL_WIDTH, 1024, - EGL_HEIGHT, 768, - EGL_NONE + EGL_WIDTH, 1024, + EGL_HEIGHT, 768, + EGL_NONE }; xglScreenInfo.width = 1024; @@ -448,114 +134,71 @@ xeglScreenInit (int index, pScreenPriv = XEGL_GET_SCREEN_PRIV (pScreen); - if (xglScreenInfo.fullscreen) - { -// xglScreenInfo.width = DisplayWidth (xdisplay, xscreen); -// xglScreenInfo.height = DisplayHeight (xdisplay, xscreen); -// xglScreenInfo.widthMm = DisplayWidthMM (xdisplay, xscreen); -// xglScreenInfo.heightMm = DisplayHeightMM (xdisplay, xscreen); - } - else if (xglScreenInfo.width == 0 || xglScreenInfo.height == 0) + if (xglScreenInfo.width == 0 || xglScreenInfo.height == 0) { xglScreenInfo.width = XEGL_DEFAULT_SCREEN_WIDTH; xglScreenInfo.height = XEGL_DEFAULT_SCREEN_HEIGHT; } - eglGetModesMESA(xdisplay, xscreen, &mode, 1, &count); - screen_surf = eglCreateScreenSurfaceMESA(xdisplay, format->id, screenAttribs); - if (screen_surf == EGL_NO_SURFACE) { - printf("failed to create screen surface\n"); - return FALSE; - } - - eglShowSurfaceMESA(xdisplay, xscreen, screen_surf, mode); + eglGetModesMESA (eDisplay, eScreen, &mode, 1, &count); - drawable = glitz_egl_create_surface (xdisplay, xscreen, format, screen_surf, - xglScreenInfo.width, xglScreenInfo.height); - if (!drawable) + eSurface = eglCreateScreenSurfaceMESA (eDisplay, format->id, screenAttribs); + if (eSurface == EGL_NO_SURFACE) { - ErrorF ("[%d] couldn't create glitz drawable for window\n", index); + ErrorF ("failed to create screen surface\n"); return FALSE; } -// XSelectInput (xdisplay, pScreenPriv->win, ExposureMask); -// XMapWindow (xdisplay, pScreenPriv->win); + eglShowSurfaceMESA (eDisplay, eScreen, eSurface, mode); - if (xglScreenInfo.fullscreen) + drawable = glitz_egl_create_surface (eDisplay, eScreen, format, eSurface, + xglScreenInfo.width, + xglScreenInfo.height); + if (!drawable) { -#if 0 - XClientMessageEvent xev; - - memset (&xev, 0, sizeof (xev)); - - xev.type = ClientMessage; - xev.message_type = XInternAtom (xdisplay, "_NET_WM_STATE", FALSE); - xev.display = xdisplay; - xev.window = pScreenPriv->win; - xev.format = 32; - xev.data.l[0] = 1; - xev.data.l[1] = - XInternAtom (xdisplay, "_NET_WM_STATE_FULLSCREEN", FALSE); - - XSendEvent (xdisplay, root, FALSE, SubstructureRedirectMask, - (XEvent *) &xev); -#endif + ErrorF ("[%d] couldn't create glitz drawable for window\n", index); + return FALSE; } xglScreenInfo.drawable = drawable; - if (!xglScreenInit (pScreen, &xglScreenInfo)) + if (!xglScreenInit (pScreen)) return FALSE; - XGL_SCREEN_WRAP (CloseScreen, xeglCloseScreen); - -#ifdef ARGB_CURSOR - if (!xeglARGBCursorSupport ()) - softCursor = TRUE; +#ifdef GLXEXT + if (!xglInitVisualConfigs (pScreen)) + return FALSE; #endif - miDCInitialize (pScreen, &xeglPointerScreenFuncs); - miCreateDefColormap (pScreen); -// miPointerInitialize(pScreen, &eglPointerSpriteFuncs, -// &kdPointerScreenFuncs, FALSE); + XGL_SCREEN_WRAP (CloseScreen, xeglCloseScreen); + + miDCInitialize (pScreen, &kdPointerScreenFuncs); if (!xglFinishScreenInit (pScreen)) return FALSE; -// while (XNextEvent (xdisplay, &xevent)) -// if (xevent.type == Expose) -// break; - -// XSelectInput (xdisplay, pScreenPriv->win, -// ButtonPressMask | ButtonReleaseMask | -// KeyPressMask | KeyReleaseMask | EnterWindowMask | -// PointerMotionMask); - return TRUE; } void -InitOutput (ScreenInfo *pScreenInfo, - int argc, - char **argv) +xeglInitOutput (ScreenInfo *pScreenInfo, + int argc, + char **argv) { glitz_drawable_format_t *format, templ; - int i, maj, min, count; + int i, maj, min, count; unsigned long mask; xglSetPixmapFormats (pScreenInfo); - if (!xdisplay) + if (!eDisplay) { - xdisplay = eglGetDisplay(":0"); - assert(xdisplay); + eDisplay = eglGetDisplay ("!fb_dri"); - if (!eglInitialize(xdisplay, &maj, &min)) + if (!eglInitialize (eDisplay, &maj, &min)) FatalError ("can't open display"); - eglGetScreensMESA(xdisplay, &xscreen, 1, &count); - - glitz_egl_init (NULL); + eglGetScreensMESA (eDisplay, &eScreen, 1, &count); } templ.samples = 1; @@ -564,7 +207,7 @@ InitOutput (ScreenInfo *pScreenInfo, mask = GLITZ_FORMAT_SAMPLES_MASK; - format = glitz_egl_find_config (xdisplay, xscreen, + format = glitz_egl_find_config (eDisplay, eScreen, mask, &templ, 0); if (!format) @@ -589,105 +232,52 @@ xeglBlockHandler (pointer blockData, glitz_surface_flush (pScreenPriv->surface); glitz_drawable_finish (pScreenPriv->drawable); +} -// XSync (xdisplay, FALSE); +void +xeglInitInput (int argc, + char **argv) +{ + eglInitInput (&LinuxEvdevMouseFuncs, &LinuxEvdevKeyboardFuncs); + RegisterBlockAndWakeupHandlers (xeglBlockHandler, KdWakeupHandler, NULL); } -static void -xeglWakeupHandler (pointer blockData, - int result, - pointer pReadMask) +Bool +xeglLegalModifier (unsigned int key, + DevicePtr pDev) { -#if 0 - ScreenPtr pScreen = currentScreen; - XEvent X; - xEvent x; - - while (XPending (xdisplay)) { - XNextEvent (xdisplay, &X); - - switch (X.type) { - case KeyPress: - x.u.u.type = KeyPress; - x.u.u.detail = X.xkey.keycode; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis (); - mieqEnqueue (&x); - break; - case KeyRelease: - x.u.u.type = KeyRelease; - x.u.u.detail = X.xkey.keycode; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis (); - mieqEnqueue (&x); - break; - case ButtonPress: - x.u.u.type = ButtonPress; - x.u.u.detail = X.xbutton.button; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis (); - mieqEnqueue (&x); - break; - case ButtonRelease: - x.u.u.type = ButtonRelease; - x.u.u.detail = X.xbutton.button; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis (); - mieqEnqueue (&x); - break; - case MotionNotify: - x.u.u.type = MotionNotify; - x.u.keyButtonPointer.rootX = X.xmotion.x; - x.u.keyButtonPointer.rootY = X.xmotion.y; - x.u.keyButtonPointer.time = lastEventTime = GetTimeInMillis (); - miPointerAbsoluteCursor (X.xmotion.x, X.xmotion.y, lastEventTime); - mieqEnqueue (&x); - break; - case EnterNotify: - if (X.xcrossing.detail != NotifyInferior) { - if (pScreen) { - NewCurrentScreen (pScreen, X.xcrossing.x, X.xcrossing.y); - x.u.u.type = MotionNotify; - x.u.keyButtonPointer.rootX = X.xcrossing.x; - x.u.keyButtonPointer.rootY = X.xcrossing.y; - x.u.keyButtonPointer.time = lastEventTime = - GetTimeInMillis (); - mieqEnqueue (&x); - } - } - break; - default: - break; - } - } -#endif + return KdLegalModifier (key, pDev); } void -InitInput (int argc, char **argv) +xeglProcessInputEvents (void) { - eglInitInput (&LinuxEvdevMouseFuncs, &LinuxEvdevKeyboardFuncs); - RegisterBlockAndWakeupHandlers (xeglBlockHandler, - KdWakeupHandler, - NULL); + KdProcessInputEvents (); } void -ddxUseMsg (void) +xeglUseMsg (void) { - ErrorF ("\nXegl usage:\n"); - ErrorF ("-display string display name of the real server\n"); + ErrorF ("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM] " + "specify screen characteristics\n"); ErrorF ("-softcursor force software cursor\n"); - - xglUseMsg (); } int -ddxProcessArgument (int argc, char **argv, int i) +xeglProcessArgument (int argc, + char **argv, + int i) { - if (!strcmp (argv[i], "-display")) + if (!strcmp (argv[i], "-screen")) { - if (++i < argc) { - xDisplayName = argv[i]; - return 2; + if ((i + 1) < argc) + { + xglParseScreen (argv[i + 1]); } - return 0; + else + return 1; + + return 2; } else if (!strcmp (argv[i], "-softcursor")) { @@ -695,90 +285,21 @@ ddxProcessArgument (int argc, char **argv, int i) return 1; } - return xglProcessArgument (&xglScreenInfo, argc, argv, i); + return 0; } void -AbortDDX (void) +xeglAbort (void) { } void -ddxGiveUp () +xeglGiveUp (void) { AbortDDX (); } void -OsVendorInit (void) -{ -} - -#ifdef ARGB_CURSOR - -//#include - -static Bool -xeglARGBCursorSupport (void) -{ -#if 0 - int renderMajor, renderMinor; - - if (!XRenderQueryVersion (xdisplay, &renderMajor, &renderMinor)) - renderMajor = renderMinor = -1; - - return (renderMajor > 0 || renderMinor > 4); -#endif - return TRUE; -} - -static Cursor -xeglCreateARGBCursor (ScreenPtr pScreen, - CursorPtr pCursor) +xeglOsVendorInit (void) { - Cursor cursor; -#if 0 - Pixmap xpixmap; - GC xgc; - XImage *ximage; - XRenderPictFormat *xformat; - Picture xpicture; - - XEGL_SCREEN_PRIV (pScreen); - - xpixmap = XCreatePixmap (xdisplay, - pScreenPriv->win, - pCursor->bits->width, - pCursor->bits->height, - 32); - - xgc = XCreateGC (xdisplay, xpixmap, 0, NULL); - - ximage = XCreateImage (xdisplay, - DefaultVisual (xdisplay, xscreen), - 32, ZPixmap, 0, - (char *) pCursor->bits->argb, - pCursor->bits->width, - pCursor->bits->height, - 32, pCursor->bits->width * 4); - - XPutImage (xdisplay, xpixmap, xgc, ximage, - 0, 0, 0, 0, pCursor->bits->width, pCursor->bits->height); - - XFree (ximage); - XFreeGC (xdisplay, xgc); - - xformat = XRenderFindStandardFormat (xdisplay, PictStandardARGB32); - xpicture = XRenderCreatePicture (xdisplay, xpixmap, xformat, 0, 0); - - cursor = XRenderCreateCursor (xdisplay, xpicture, - pCursor->bits->xhot, - pCursor->bits->yhot); - - XRenderFreePicture (xdisplay, xpicture); - XFreePixmap (xdisplay, xpixmap); -#endif - return cursor; } - -#endif diff --git a/hw/xgl/egl/xegl.h b/hw/xgl/egl/xegl.h index e75f233ad..cf21fca95 100644 --- a/hw/xgl/egl/xegl.h +++ b/hw/xgl/egl/xegl.h @@ -1,3 +1,33 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#ifndef _XEGL_H_ +#define _XEGL_H_ + +#include "xgl.h" + #include "randrstr.h" #define KD_BUTTON_1 0x01 @@ -8,33 +38,33 @@ #define KD_MOUSE_DELTA 0x80000000 typedef struct _KdMouseFuncs { - Bool (*Init) (void); - void (*Fini) (void); + Bool (*Init) (void); + void (*Fini) (void); } KdMouseFuncs; typedef struct _KdKeyboardFuncs { - void (*Load) (void); - int (*Init) (void); - void (*Leds) (int); - void (*Bell) (int, int, int); - void (*Fini) (void); - int LockLed; + void (*Load) (void); + int (*Init) (void); + void (*Leds) (int); + void (*Bell) (int, int, int); + void (*Fini) (void); + int LockLed; } KdKeyboardFuncs; typedef struct _KdOsFuncs { - int (*Init) (void); - void (*Enable) (void); - Bool (*SpecialKey) (KeySym); - void (*Disable) (void); - void (*Fini) (void); - void (*pollEvents) (void); + int (*Init) (void); + void (*Enable) (void); + Bool (*SpecialKey) (KeySym); + void (*Disable) (void); + void (*Fini) (void); + void (*pollEvents) (void); } KdOsFuncs; typedef struct _KdMouseMatrix { - int matrix[2][3]; + int matrix[2][3]; } KdMouseMatrix; -typedef enum _kdMouseState { +typedef enum _KdMouseState { start, button_1_pend, button_1_down, @@ -51,81 +81,134 @@ typedef enum _kdMouseState { typedef struct _KdMouseInfo { struct _KdMouseInfo *next; - void *driver; - void *closure; - char *name; - char *prot; - char map[KD_MAX_BUTTON]; - int nbutton; - Bool emulateMiddleButton; - unsigned long emulationTimeout; - Bool timeoutPending; - KdMouseState mouseState; - Bool eventHeld; - xEvent heldEvent; - unsigned char buttonState; - int emulationDx, emulationDy; - int inputType; - Bool transformCoordinates; + void *driver; + void *closure; + char *name; + char *prot; + char map[KD_MAX_BUTTON]; + int nbutton; + Bool emulateMiddleButton; + unsigned long emulationTimeout; + Bool timeoutPending; + KdMouseState mouseState; + Bool eventHeld; + xEvent heldEvent; + unsigned char buttonState; + int emulationDx, emulationDy; + int inputType; + Bool transformCoordinates; } KdMouseInfo; -typedef struct _KdScreenInfo { - struct _KdScreenInfo *next; - ScreenPtr pScreen; - void *driver; - Rotation randr; /* rotation and reflection */ - int width; - int height; - int rate; - int width_mm; - int height_mm; - int subpixel_order; - Bool dumb; - Bool softCursor; - int mynum; - DDXPointRec origin; -} KdScreenInfo; - -#define KD_MAX_FB 2 -#define KD_MAX_PSEUDO_DEPTH 8 -#define KD_MAX_PSEUDO_SIZE (1 << KD_MAX_PSEUDO_DEPTH) - typedef struct _xeglScreen { - Window win; - Colormap colormap; CloseScreenProcPtr CloseScreen; - KdScreenInfo *screen; - ColormapPtr pInstalledmap[KD_MAX_FB]; /* current colormap */ + ScreenPtr pScreen; + DDXPointRec origin; } xeglScreenRec, *xeglScreenPtr; -extern KdMouseInfo *kdMouseInfo; -extern KdOsFuncs *kdOsFuncs; -extern Bool kdDontZap; -extern Bool kdDisableZaphod; -extern int kdScreenPrivateIndex; -extern KdMouseFuncs LinuxEvdevMouseFuncs; +extern KdMouseInfo *kdMouseInfo; +extern KdOsFuncs *kdOsFuncs; +extern Bool kdDontZap; +extern Bool kdDisableZaphod; +extern int xeglScreenPrivateIndex; +extern KdMouseFuncs LinuxEvdevMouseFuncs; extern KdKeyboardFuncs LinuxEvdevKeyboardFuncs; -#define RR_Rotate_All (RR_Rotate_0|RR_Rotate_90|RR_Rotate_180|RR_Rotate_270) -#define RR_Reflect_All (RR_Reflect_X|RR_Reflect_Y) - -#define KdGetScreenPriv(pScreen) ((xeglScreenPtr) \ - (pScreen)->devPrivates[kdScreenPrivateIndex].ptr) -#define KdScreenPriv(pScreen) xeglScreenPtr pScreenPriv = KdGetScreenPriv(pScreen) - -extern void eglInitInput(KdMouseFuncs *pMouseFuncs, KdKeyboardFuncs *pKeyboardFuncs); -extern void KdParseMouse(char *arg); -extern KdMouseInfo *KdMouseInfoAdd(void); -extern void KdMouseInfoDispose(KdMouseInfo *mi); -extern int KdAllocInputType(void); -extern char *KdSaveString (char *str); -extern Bool KdRegisterFd(int type, int fd, void (*read) (int fd, void *closure), void *closure); -extern void KdUnregisterFds(int type, Bool do_close); -extern void KdEnqueueKeyboardEvent(unsigned char scan_code, unsigned char is_up); -extern void KdEnqueueMouseEvent(KdMouseInfo *mi, unsigned long flags, int rx, int ry); -extern void KdRegisterFdEnableDisable(int fd, - int (*enable)(int fd, void *closure), - void (*disable)(int fd, void *closure)); -extern void KdWakeupHandler(int screen, pointer data, unsigned long lresult, pointer readmask); +#define RR_Rotate_All \ + (RR_Rotate_0 | RR_Rotate_90 | RR_Rotate_180 | RR_Rotate_270) +#define RR_Reflect_All (RR_Reflect_X | RR_Reflect_Y) + +#define KdGetScreenPriv(pScreen) \ + ((xeglScreenPtr) ((pScreen)->devPrivates[xeglScreenPrivateIndex].ptr)) +#define KdScreenPriv(pScreen) \ + xeglScreenPtr pScreenPriv = KdGetScreenPriv (pScreen) + +void +eglInitInput (KdMouseFuncs *pMouseFuncs, + KdKeyboardFuncs *pKeyboardFuncs); + +void +KdParseMouse (char *arg); + +KdMouseInfo * +KdMouseInfoAdd (void); + +void +KdMouseInfoDispose (KdMouseInfo *mi); + +int +KdAllocInputType (void); + +char * +KdSaveString (char *str); + +Bool +KdRegisterFd (int type, + int fd, + void (*read) (int fd, void *closure), + void *closure); + +void +KdUnregisterFds (int type, + Bool do_close); + +void +KdEnqueueKeyboardEvent (unsigned char scan_code, + unsigned char is_up); + +void +KdEnqueueMouseEvent (KdMouseInfo *mi, + unsigned long flags, + int rx, + int ry); + +void +KdRegisterFdEnableDisable (int fd, + int (*enable) (int fd, void *closure), + void (*disable) (int fd, void *closure)); + +void +KdWakeupHandler (pointer data, + int result, + pointer readmask); + +Bool +KdLegalModifier (unsigned int key, + DevicePtr pDev); + +void +KdProcessInputEvents (void); + +void +xeglInitOutput (ScreenInfo *pScreenInfo, + int argc, + char **argv); + +Bool +xeglLegalModifier (unsigned int key, + DevicePtr pDev); + +void +xeglProcessInputEvents (void); + +void +xeglInitInput (int argc, + char **argv); + +void +xeglUseMsg (void); + +int +xeglProcessArgument (int argc, + char **argv, + int i); + +void +xeglAbort (void); + +void +xeglGiveUp (void); +void +xeglOsVendorInit (void); +#endif /* _XEGL_H_ */ diff --git a/hw/xgl/egl/xeglinit.c b/hw/xgl/egl/xeglinit.c new file mode 100644 index 000000000..51100a4d1 --- /dev/null +++ b/hw/xgl/egl/xeglinit.c @@ -0,0 +1,131 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#include "xegl.h" + +static xglScreenInfoRec xglScreenInfo = { + NULL, 0, 0, 0, 0, + DEFAULT_GEOMETRY_DATA_TYPE, + DEFAULT_GEOMETRY_USAGE, + FALSE, + XGL_DEFAULT_PBO_MASK, + FALSE, + FALSE +}; + +#ifdef GLXEXT +static Bool loadGlx = TRUE; +#endif + +void +InitOutput (ScreenInfo *pScreenInfo, + int argc, + char **argv) +{ + +#ifdef GLXEXT + if (loadGlx) + { + if (!xglLoadGLXModules ()) + FatalError ("No GLX modules loaded"); + } +#endif + + xeglInitOutput (pScreenInfo, argc, argv); +} + +Bool +LegalModifier (unsigned int key, + DevicePtr pDev) +{ + return xeglLegalModifier (key, pDev); +} + +void +ProcessInputEvents (void) +{ + xeglProcessInputEvents (); +} + +void +InitInput (int argc, + char **argv) +{ + xeglInitInput (argc, argv); +} + +void +ddxUseMsg (void) +{ + ErrorF ("\nXgl usage:\n"); + +#ifdef GLXEXT + ErrorF ("-noglx don't load glx extension\n"); +#endif + + xglUseMsg (); + ErrorF ("\nXegl usage:\n"); + xeglUseMsg (); +} + +int +ddxProcessArgument (int argc, + char **argv, + int i) +{ + int skip; + +#ifdef GLXEXT + if (!strcmp (argv[i], "-noglx")) + { + loadGlx = FALSE; + return 1; + } +#endif + + skip = xglProcessArgument (argc, argv, i); + if (skip) + return skip; + + return xeglProcessArgument (argc, argv, i); +} + +void +AbortDDX (void) +{ + xeglAbort (); +} + +void +ddxGiveUp (void) +{ + xeglGiveUp (); +} + +void +OsVendorInit (void) +{ + xeglOsVendorInit (); +} diff --git a/hw/xgl/glx/Makefile.am b/hw/xgl/glx/Makefile.am index 2ab66d8f6..138ee8cef 100644 --- a/hw/xgl/glx/Makefile.am +++ b/hw/xgl/glx/Makefile.am @@ -1,16 +1,33 @@ +if XGLSERVER +MODULE_SUBDIRS = module +endif + +SUBDIRS = \ + . \ + $(MODULE_SUBDIRS) + INCLUDES = \ - @XGL_INCS@ \ + @XGLX_INCS@ \ @XSERVER_CFLAGS@ \ + @XGLSERVER_CFLAGS@ \ @XGLXSERVER_CFLAGS@ -bin_PROGRAMS = Xglx +noinst_LTLIBRARIES = libxglx.la -Xglx_SOURCES = xglx.c +libxglx_la_SOURCES = \ + xglx.h \ + xglx.c -Xglx_LDADD = \ - @XGL_LIBS@ \ +if XGLXSERVER +Xglx_DEPENDENCIES = @XGLX_LIBS@ +Xglx_LDFLAGS = -export-dynamic +Xglx_SOURCES = xglxinit.c +Xglx_LDADD = \ + @XGLX_LIBS@ \ @XSERVER_LIBS@ \ + @XGLSERVER_LIBS@ \ @XGLXSERVER_LIBS@ +Xglx_programs = Xglx +endif -Xglx_DEPENDENCIES = @XGL_LIBS@ - +bin_PROGRAMS = $(Xglx_programs) diff --git a/hw/xgl/glx/module/Makefile.am b/hw/xgl/glx/module/Makefile.am new file mode 100644 index 000000000..dd5f09772 --- /dev/null +++ b/hw/xgl/glx/module/Makefile.am @@ -0,0 +1,14 @@ +INCLUDES = \ + @XGLX_INCS@ \ + @XSERVER_CFLAGS@ \ + @XGLXSERVER_CFLAGS@ + +libxglx_la_LDFLAGS = -avoid-version +libxglx_la_SOURCES = xglxmodule.c +libxglx_la_LIBADD = \ + @XGLX_MOD_LIBS@ \ + @XGLXSERVER_LIBS@ + +moduledir = @MODULEPATH@/xgl + +module_LTLIBRARIES = libxglx.la \ No newline at end of file diff --git a/hw/xgl/glx/module/xglxmodule.c b/hw/xgl/glx/module/xglxmodule.c new file mode 100644 index 000000000..066cb8082 --- /dev/null +++ b/hw/xgl/glx/module/xglxmodule.c @@ -0,0 +1,104 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#include "xglx.h" +#include "xglmodule.h" + +#include + +char * +moduleVersion (void) +{ + return VERSION; +} + +Bool +moduleInit (const char *module) +{ + glitz_glx_init (module); + + return TRUE; +} + +void +InitOutput (ScreenInfo *pScreenInfo, + int argc, + char **argv) +{ + xglxInitOutput (pScreenInfo, argc, argv); +} + +Bool +LegalModifier (unsigned int key, + DevicePtr pDev) +{ + return xglxLegalModifier (key, pDev); +} + +void +ProcessInputEvents (void) +{ + xglxProcessInputEvents (); +} + +void +InitInput (int argc, + char **argv) +{ + xglxInitInput (argc, argv); +} + +void +ddxUseMsg (void) +{ + ErrorF ("\nXglx usage:\n"); + xglxUseMsg (); +} + +int +ddxProcessArgument (int argc, + char **argv, + int i) +{ + return xglxProcessArgument (argc, argv, i); +} + +void +AbortDDX (void) +{ + xglxAbort (); +} + +void +ddxGiveUp (void) +{ + xglxGiveUp (); +} + +void +OsVendorInit (void) +{ + xglxOsVendorInit (); +} diff --git a/hw/xgl/glx/xglx.c b/hw/xgl/glx/xglx.c index 95df887df..f8ac366b1 100644 --- a/hw/xgl/glx/xglx.c +++ b/hw/xgl/glx/xglx.c @@ -27,7 +27,12 @@ #include #include -#include "xgl.h" +#include "xglx.h" + +#ifdef GLXEXT +#include "xglglxext.h" +#endif + #include "inputstr.h" #include "cursorstr.h" #include "mipointer.h" @@ -72,21 +77,13 @@ typedef struct _xglxCursor { #define XGLX_CURSOR_PRIV(pCursor, pScreen) \ xglxCursorPtr pCursorPriv = XGLX_GET_CURSOR_PRIV (pCursor, pScreen) -char *xDisplayName = NULL; -Display *xdisplay = NULL; -int xscreen; -glitz_format_t *xglxCurrentFormat; -CARD32 lastEventTime = 0; -ScreenPtr currentScreen = NULL; -Bool softCursor = FALSE; -xglScreenInfoRec xglScreenInfo = { - NULL, 0, 0, 0, 0, FALSE, - DEFAULT_GEOMETRY_DATA_TYPE, - DEFAULT_GEOMETRY_USAGE, - FALSE, - XGL_DEFAULT_PBO_MASK, - FALSE -}; +static char *xDisplayName = 0; +static Display *xdisplay = 0; +static int xscreen; +static CARD32 lastEventTime = 0; +static ScreenPtr currentScreen = 0; +static Bool softCursor = FALSE; +static Bool fullscreen = FALSE; static Bool xglxAllocatePrivates (ScreenPtr pScreen) @@ -375,7 +372,7 @@ xglxScreenInit (int index, pScreenPriv->colormap = XCreateColormap (xdisplay, root, vinfo->visual, AllocNone); - if (xglScreenInfo.fullscreen) + if (fullscreen) { xglScreenInfo.width = DisplayWidth (xdisplay, xscreen); xglScreenInfo.height = DisplayHeight (xdisplay, xscreen); @@ -405,7 +402,7 @@ xglxScreenInit (int index, normalHints->max_width = xglScreenInfo.width; normalHints->max_height = xglScreenInfo.height; - if (xglScreenInfo.fullscreen) + if (fullscreen) { normalHints->x = 0; normalHints->y = 0; @@ -444,7 +441,7 @@ xglxScreenInit (int index, XMapWindow (xdisplay, pScreenPriv->win); - if (xglScreenInfo.fullscreen) + if (fullscreen) { XClientMessageEvent xev; @@ -465,9 +462,14 @@ xglxScreenInit (int index, xglScreenInfo.drawable = drawable; - if (!xglScreenInit (pScreen, &xglScreenInfo)) + if (!xglScreenInit (pScreen)) return FALSE; - + +#ifdef GLXEXT + if (!xglInitVisualConfigs (pScreen)) + return FALSE; +#endif + XGL_SCREEN_WRAP (CloseScreen, xglxCloseScreen); #ifdef ARGB_CURSOR @@ -526,9 +528,9 @@ xglxScreenInit (int index, } void -InitOutput (ScreenInfo *pScreenInfo, - int argc, - char **argv) +xglxInitOutput (ScreenInfo *pScreenInfo, + int argc, + char **argv) { glitz_drawable_format_t *format, templ; int i; @@ -792,21 +794,22 @@ xglxKeybdProc (DeviceIntPtr pDevice, } Bool -LegalModifier (unsigned int key, - DevicePtr pDev) +xglxLegalModifier (unsigned int key, + DevicePtr pDev) { return TRUE; } void -ProcessInputEvents () +xglxProcessInputEvents (void) { mieqProcessInputEvents (); miPointerUpdate (); } void -InitInput (int argc, char **argv) +xglxInitInput (int argc, + char **argv) { DeviceIntPtr pKeyboard, pPointer; @@ -827,18 +830,36 @@ InitInput (int argc, char **argv) } void -ddxUseMsg (void) +xglxUseMsg (void) { - ErrorF ("\nXglx usage:\n"); + ErrorF ("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM] " + "specify screen characteristics\n"); + ErrorF ("-fullscreen run fullscreen\n"); ErrorF ("-display string display name of the real server\n"); ErrorF ("-softcursor force software cursor\n"); - - xglUseMsg (); } int -ddxProcessArgument (int argc, char **argv, int i) +xglxProcessArgument (int argc, + char **argv, + int i) { + if (!strcmp (argv[i], "-screen")) + { + if ((i + 1) < argc) + { + xglParseScreen (argv[i + 1]); + } + else + return 1; + + return 2; + } + else if (!strcmp (argv[i], "-fullscreen")) + { + fullscreen = TRUE; + return 1; + } if (!strcmp (argv[i], "-display")) { if (++i < argc) { @@ -853,22 +874,22 @@ ddxProcessArgument (int argc, char **argv, int i) return 1; } - return xglProcessArgument (&xglScreenInfo, argc, argv, i); + return 0; } void -AbortDDX (void) -{ +xglxAbort (void) +{ } void -ddxGiveUp () +xglxGiveUp () { AbortDDX (); } void -OsVendorInit (void) +xglxOsVendorInit (void) { } @@ -924,7 +945,7 @@ xglxCreateARGBCursor (ScreenPtr pScreen, xformat = XRenderFindStandardFormat (xdisplay, PictStandardARGB32); xpicture = XRenderCreatePicture (xdisplay, xpixmap, xformat, 0, 0); - + cursor = XRenderCreateCursor (xdisplay, xpicture, pCursor->bits->xhot, pCursor->bits->yhot); diff --git a/hw/xgl/glx/xglx.h b/hw/xgl/glx/xglx.h new file mode 100644 index 000000000..cb2ea2af1 --- /dev/null +++ b/hw/xgl/glx/xglx.h @@ -0,0 +1,64 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#ifndef _XGLX_H_ +#define _XGLX_H_ + +#include "xgl.h" + +void +xglxInitOutput (ScreenInfo *pScreenInfo, + int argc, + char **argv); + +Bool +xglxLegalModifier (unsigned int key, + DevicePtr pDev); + +void +xglxProcessInputEvents (void); + +void +xglxInitInput (int argc, + char **argv); + +void +xglxUseMsg (void); + +int +xglxProcessArgument (int argc, + char **argv, + int i); + +void +xglxAbort (void); + +void +xglxGiveUp (void); + +void +xglxOsVendorInit (void); + +#endif /* _XGLX_H_ */ diff --git a/hw/xgl/glx/xglxinit.c b/hw/xgl/glx/xglxinit.c new file mode 100644 index 000000000..18bdca1f8 --- /dev/null +++ b/hw/xgl/glx/xglxinit.c @@ -0,0 +1,131 @@ +/* + * Copyright © 2004 David Reveman + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * David Reveman not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * David Reveman makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * DAVID REVEMAN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL DAVID REVEMAN BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#include "xglx.h" + +static xglScreenInfoRec xglxScreenInfo = { + NULL, 0, 0, 0, 0, + DEFAULT_GEOMETRY_DATA_TYPE, + DEFAULT_GEOMETRY_USAGE, + FALSE, + XGL_DEFAULT_PBO_MASK, + FALSE, + FALSE +}; + +#ifdef GLXEXT +static Bool loadGlx = TRUE; +#endif + +void +InitOutput (ScreenInfo *pScreenInfo, + int argc, + char **argv) +{ + +#ifdef GLXEXT + if (loadGlx) + { + if (!xglLoadGLXModules ()) + FatalError ("No GLX modules loaded"); + } +#endif + + xglxInitOutput (&xglxScreenInfo, pScreenInfo, argc, argv); +} + +Bool +LegalModifier (unsigned int key, + DevicePtr pDev) +{ + return xglxLegalModifier (key, pDev); +} + +void +ProcessInputEvents (void) +{ + xglxProcessInputEvents (); +} + +void +InitInput (int argc, + char **argv) +{ + xglxInitInput (&xglxScreenInfo, argc, argv); +} + +void +ddxUseMsg (void) +{ + ErrorF ("\nXgl usage:\n"); + +#ifdef GLXEXT + ErrorF ("-noglx don't load glx extension\n"); +#endif + + xglUseMsg (); + ErrorF ("\nXglx usage:\n"); + xglxUseMsg (); +} + +int +ddxProcessArgument (int argc, + char **argv, + int i) +{ + int skip; + +#ifdef GLXEXT + if (!strcmp (argv[i], "-noglx")) + { + loadGlx = FALSE; + return 1; + } +#endif + + skip = xglProcessArgument (&xglxScreenInfo, argc, argv, i); + if (skip) + return skip; + + return xglxProcessArgument (&xglxScreenInfo, argc, argv, i); +} + +void +AbortDDX (void) +{ + xglxAbort (); +} + +void +ddxGiveUp (void) +{ + xglxGiveUp (); +} + +void +OsVendorInit (void) +{ + xglxOsVendorInit (); +} diff --git a/hw/xgl/glxext/Makefile.am b/hw/xgl/glxext/Makefile.am new file mode 100644 index 000000000..53d5fe841 --- /dev/null +++ b/hw/xgl/glxext/Makefile.am @@ -0,0 +1,13 @@ +SUBDIRS = module + +INCLUDES = \ + @XGL_INCS@ \ + @XSERVER_CFLAGS@ + +libxglglxext_libraries = libxglglxext.la +libxglglxext_la_SOURCES = \ + xglglxext.h \ + xglglxext.c + +noinst_LTLIBRARIES = $(libxglglxext_libraries) + diff --git a/hw/xgl/glxext/module/Makefile.am b/hw/xgl/glxext/module/Makefile.am new file mode 100644 index 000000000..8272ae514 --- /dev/null +++ b/hw/xgl/glxext/module/Makefile.am @@ -0,0 +1,19 @@ +INCLUDES = \ + @XGLX_INCS@ \ + @XSERVER_CFLAGS@ + +libglx_la_LDFLAGS = -avoid-version +libglx_la_SOURCES = glxmodule.c +libglx_la_LIBADD = $(top_builddir)/GL/glx/libglx.la +libglx_modules = libglx.la + +libglcore_la_LDFLAGS = -avoid-version +libglcore_la_SOURCES = glcoremodule.c +libglcore_la_LIBADD = $(top_builddir)/GL/mesa/libglcore.la +libglcore_modules = libglcore.la + +moduledir = @MODULEPATH@/xgl + +module_LTLIBRARIES = \ + $(libglcore_modules) \ + $(libglx_modules) \ No newline at end of file diff --git a/hw/xgl/glxext/module/glcoremodule.c b/hw/xgl/glxext/module/glcoremodule.c new file mode 100644 index 000000000..37aa9c658 --- /dev/null +++ b/hw/xgl/glxext/module/glcoremodule.c @@ -0,0 +1,38 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#include "xglmodule.h" + +char * +moduleVersion (void) +{ + return VERSION; +} + +Bool +moduleInit (const char *module) +{ + return TRUE; +} diff --git a/hw/xgl/glxext/module/glxmodule.c b/hw/xgl/glxext/module/glxmodule.c new file mode 100644 index 000000000..37aa9c658 --- /dev/null +++ b/hw/xgl/glxext/module/glxmodule.c @@ -0,0 +1,38 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#include "xglmodule.h" + +char * +moduleVersion (void) +{ + return VERSION; +} + +Bool +moduleInit (const char *module) +{ + return TRUE; +} diff --git a/hw/xgl/glxext/xglglxext.c b/hw/xgl/glxext/xglglxext.c new file mode 100644 index 000000000..df365717f --- /dev/null +++ b/hw/xgl/glxext/xglglxext.c @@ -0,0 +1,5068 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#include "xgl.h" +#include "xglglxext.h" + +#include +#include +#include + +#include "glxserver.h" +#include "glxdrawable.h" +#include "glxscreens.h" +#include "glxutil.h" +#include "unpack.h" +#include "g_disptab.h" +#include "glxext.h" +#include "micmap.h" + +#define XGL_MAX_TEXTURE_UNITS 8 + +#define XGL_TEXTURE_1D_BIT (1 << 0) +#define XGL_TEXTURE_2D_BIT (1 << 1) +#define XGL_TEXTURE_3D_BIT (1 << 2) +#define XGL_TEXTURE_RECTANGLE_BIT (1 << 3) +#define XGL_TEXTURE_CUBE_MAP_BIT (1 << 4) + +typedef Bool (*GLXScreenProbeProc) (int screen); +typedef __GLinterface *(*GLXCreateContextProc) (__GLimports *imports, + __GLcontextModes *modes, + __GLinterface *shareGC); +typedef void (*GLXCreateBufferProc) (__GLXdrawablePrivate *glxPriv); +typedef GLboolean (*GLXSwapBuffersProc) (__GLXdrawablePrivate *glxPriv); +typedef int (*GLXBindBuffersProc) (__GLXdrawablePrivate *glxPriv, + int buffer); +typedef int (*GLXReleaseBuffersProc) (__GLXdrawablePrivate *glxPriv, + int buffer); + +typedef struct _xglGLXScreenInfo { + GLXScreenProbeProc screenProbe; + GLXCreateContextProc createContext; + GLXCreateBufferProc createBuffer; +} xglGLXScreenInfoRec, *xglGLXScreenInfoPtr; + +static xglGLXScreenInfoRec screenInfoPriv; + +extern __GLXscreenInfo __glDDXScreenInfo; + +typedef GLboolean (*GLResizeBuffersProc) (__GLdrawableBuffer *buffer, + GLint x, + GLint y, + GLuint width, + GLuint height, + __GLdrawablePrivate *glPriv, + GLuint bufferMask); +typedef void (*GLFreeBuffersProc) (__GLdrawablePrivate *glPriv); + +typedef struct _xglGLBuffer { + GLXSwapBuffersProc swapBuffers; + GLXBindBuffersProc bindBuffers; + GLXReleaseBuffersProc releaseBuffers; + GLResizeBuffersProc resizeBuffers; + GLFreeBuffersProc freeBuffers; + ScreenPtr pScreen; + DrawablePtr pDrawable; + glitz_surface_t *backSurface; + PixmapPtr pPixmap; + GCPtr pGC; + RegionRec damage; + void *private; + int xOff, yOff; + int yFlip; +} xglGLBufferRec, *xglGLBufferPtr; + +typedef int xglGLXVisualConfigRec, *xglGLXVisualConfigPtr; +typedef struct _xglDisplayList *xglDisplayListPtr; + +#define XGL_LIST_OP_CALLS 0 +#define XGL_LIST_OP_DRAW 1 +#define XGL_LIST_OP_GL 2 +#define XGL_LIST_OP_LIST 3 + +typedef struct _xglGLOp { + void (*glProc) (struct _xglGLOp *pOp); + union { + GLenum enumeration; + GLbitfield bitfield; + GLsizei size; + struct { + GLint x; + GLint y; + GLsizei width; + GLsizei height; + } rect; + struct { + GLenum target; + GLuint texture; + } bind_texture; + struct { + GLenum target; + GLenum pname; + GLfloat params[4]; + } tex_parameter_fv; + struct { + GLint x; + GLint y; + GLsizei width; + GLsizei height; + GLenum type; + } copy_pixels; + struct { + GLenum target; + GLint level; + GLenum internalformat; + GLint x; + GLint y; + GLsizei width; + GLint border; + } copy_tex_image_1d; + struct { + GLenum target; + GLint level; + GLenum internalformat; + GLint x; + GLint y; + GLsizei width; + GLsizei height; + GLint border; + } copy_tex_image_2d; + struct { + GLenum target; + GLint level; + GLint xoffset; + GLint x; + GLint y; + GLsizei width; + } copy_tex_sub_image_1d; + struct { + GLenum target; + GLint level; + GLint xoffset; + GLint yoffset; + GLint x; + GLint y; + GLsizei width; + GLsizei height; + } copy_tex_sub_image_2d; + struct { + GLenum target; + GLenum internalformat; + GLint x; + GLint y; + GLsizei width; + } copy_color_table; + struct { + GLenum target; + GLsizei start; + GLint x; + GLint y; + GLsizei width; + } copy_color_sub_table; + struct { + GLenum target; + GLenum internalformat; + GLint x; + GLint y; + GLsizei width; + } copy_convolution_filter_1d; + struct { + GLenum target; + GLenum internalformat; + GLint x; + GLint y; + GLsizei width; + GLsizei height; + } copy_convolution_filter_2d; + struct { + GLenum target; + GLint level; + GLint xoffset; + GLint yoffset; + GLint zoffset; + GLint x; + GLint y; + GLsizei width; + GLsizei height; + } copy_tex_sub_image_3d; + struct { + GLfloat x; + GLfloat y; + GLfloat z; + } window_pos_3f; + } u; +} xglGLOpRec, *xglGLOpPtr; + +typedef struct _xglListOp { + int type; + union { + GLuint list; + xglGLOpPtr gl; + } u; +} xglListOpRec, *xglListOpPtr; + +typedef struct _xglDisplayList { + xglListOpPtr pOp; + int nOp; + int size; +} xglDisplayListRec; + +typedef struct _xglTexObj { + GLuint key; + GLuint name; + PixmapPtr pPixmap; + glitz_texture_object_t *object; + int refcnt; +} xglTexObjRec, *xglTexObjPtr; + +typedef struct _xglTexUnit { + GLbitfield enabled; + xglTexObjPtr p1D; + xglTexObjPtr p2D; + xglTexObjPtr p3D; + xglTexObjPtr pRect; + xglTexObjPtr pCubeMap; +} xglTexUnitRec, *xglTexUnitPtr; + +typedef struct _xglGLAttributes { + GLbitfield mask; + GLenum drawBuffer; + GLenum readBuffer; + xRectangle viewport; + xRectangle scissor; + GLboolean scissorTest; + xglTexUnitRec texUnits[XGL_MAX_TEXTURE_UNITS]; +} xglGLAttributesRec, *xglGLAttributesPtr; + +typedef struct _xglGLContext { + __GLinterface iface; + __GLinterface *mIface; + int refcnt; + struct _xglGLContext *shared; + glitz_context_t *context; + __glProcTableEXT glRenderTableEXT; + PFNGLACTIVETEXTUREARBPROC ActiveTextureARB; + PFNGLWINDOWPOS3FMESAPROC WindowPos3fMESA; + Bool needInit; + xglGLBufferPtr pDrawBuffer; + xglGLBufferPtr pReadBuffer; + GLuint fbo; + int drawXoff, drawYoff; + char *versionString; + GLenum errorValue; + GLboolean doubleBuffer; + GLint depthBits; + GLint stencilBits; + xglHashTablePtr texObjects; + xglHashTablePtr displayLists; + GLuint list; + GLenum listMode; + xglDisplayListPtr pList; + GLuint groupList; + xglGLAttributesRec attrib; + xglGLAttributesPtr pAttribStack; + int nAttribStack; + int activeTexUnit; + GLint maxTexUnits; + GLint maxListNesting; +} xglGLContextRec, *xglGLContextPtr; + +static xglGLContextPtr cctx = NULL; + +//static void +//xglSetCurrentContext (xglGLContextPtr pContext, glitz_drawable_t *drawable); +static void +xglSetCurrentContext (xglGLContextPtr pContext); + +#define XGL_GLX_INTERSECT_BOX(pBox1, pBox2) \ + { \ + if ((pBox1)->x1 < (pBox2)->x1) \ + (pBox1)->x1 = (pBox2)->x1; \ + if ((pBox1)->y1 < (pBox2)->y1) \ + (pBox1)->y1 = (pBox2)->y1; \ + if ((pBox1)->x2 > (pBox2)->x2) \ + (pBox1)->x2 = (pBox2)->x2; \ + if ((pBox1)->y2 > (pBox2)->y2) \ + (pBox1)->y2 = (pBox2)->y2; \ + } + +#define XGL_GLX_SET_SCISSOR_BOX(pBox) \ + glScissor ((pBox)->x1, \ + cctx->pDrawBuffer->yFlip - (pBox)->y2, \ + (pBox)->x2 - (pBox)->x1, \ + (pBox)->y2 - (pBox)->y1) + +#define XGL_GLX_DRAW_PROLOGUE(pBox, nBox, pScissorBox) \ + (pBox) = REGION_RECTS (cctx->pDrawBuffer->pGC->pCompositeClip); \ + (nBox) = REGION_NUM_RECTS (cctx->pDrawBuffer->pGC->pCompositeClip); \ + (pScissorBox)->x1 = cctx->attrib.scissor.x + cctx->pDrawBuffer->xOff; \ + (pScissorBox)->x2 = (pScissorBox)->x1 + cctx->attrib.scissor.width; \ + (pScissorBox)->y2 = cctx->attrib.scissor.y + cctx->pDrawBuffer->yOff; \ + (pScissorBox)->y2 = cctx->pDrawBuffer->yFlip - (pScissorBox)->y2; \ + (pScissorBox)->y1 = (pScissorBox)->y2 - cctx->attrib.scissor.height; \ + xglSetupTextures () + +#define XGL_GLX_DRAW_DAMAGE(pBox, pRegion) \ + if (cctx->attrib.drawBuffer != GL_BACK && \ + cctx->pDrawBuffer->pDrawable && \ + cctx->pDrawBuffer->pDrawable->type != DRAWABLE_PIXMAP) \ + { \ + REGION_INIT (cctx->pDrawBuffer->pGC->pScreen, pRegion, pBox, 1); \ + REGION_UNION (cctx->pDrawBuffer->pGC->pScreen, \ + &cctx->pDrawBuffer->damage, \ + &cctx->pDrawBuffer->damage, \ + pRegion); \ + REGION_UNINIT (cctx->pDrawBuffer->pGC->pScreen, pRegion); \ + } + +static void +xglRecordError (GLenum error) +{ + if (cctx->errorValue == GL_NO_ERROR) + cctx->errorValue = error; +} + +static xglDisplayListPtr +xglCreateList (void) +{ + xglDisplayListPtr pDisplayList; + + pDisplayList = xalloc (sizeof (xglDisplayListRec)); + if (!pDisplayList) + return NULL; + + pDisplayList->pOp = NULL; + pDisplayList->nOp = 0; + pDisplayList->size = 0; + + return pDisplayList; +} + +static void +xglDestroyList (xglDisplayListPtr pDisplayList) +{ + xglListOpPtr pOp = pDisplayList->pOp; + int nOp = pDisplayList->nOp; + + while (nOp--) + { + switch (pOp->type) { + case XGL_LIST_OP_CALLS: + case XGL_LIST_OP_DRAW: + glDeleteLists (pOp->u.list, 1); + break; + case XGL_LIST_OP_GL: + xfree (pOp->u.gl); + break; + case XGL_LIST_OP_LIST: + break; + } + + pOp++; + } + + if (pDisplayList->pOp) + xfree (pDisplayList->pOp); + + xfree (pDisplayList); +} + +static Bool +xglResizeList (xglDisplayListPtr pDisplayList, + int nOp) +{ + if (pDisplayList->size < nOp) + { + int size = pDisplayList->nOp ? pDisplayList->nOp : 4; + + while (size < nOp) + size <<= 1; + + pDisplayList->pOp = xrealloc (pDisplayList->pOp, + sizeof (xglListOpRec) * size); + if (!pDisplayList->pOp) + return FALSE; + + pDisplayList->size = size; + } + + return TRUE; +} + +static void +xglStartList (int type, + GLenum mode) +{ + if (!xglResizeList (cctx->pList, cctx->pList->nOp + 1)) + { + xglRecordError (GL_OUT_OF_MEMORY); + return; + } + + cctx->pList->pOp[cctx->pList->nOp].type = type; + cctx->pList->pOp[cctx->pList->nOp].u.list = glGenLists (1); + + glNewList (cctx->pList->pOp[cctx->pList->nOp].u.list, mode); + + cctx->pList->nOp++; +} + +static void +xglGLOp (xglGLOpPtr pOp) +{ + if (cctx->list) + { + xglGLOpPtr pGLOp; + + pGLOp = xalloc (sizeof (xglGLOpRec)); + if (!pGLOp) + { + xglRecordError (GL_OUT_OF_MEMORY); + return; + } + + if (!xglResizeList (cctx->pList, cctx->pList->nOp + 1)) + { + xfree (pGLOp); + xglRecordError (GL_OUT_OF_MEMORY); + return; + } + + glEndList (); + + *pGLOp = *pOp; + + cctx->pList->pOp[cctx->pList->nOp].type = XGL_LIST_OP_GL; + cctx->pList->pOp[cctx->pList->nOp].u.gl = pGLOp; + cctx->pList->nOp++; + + if (cctx->listMode == GL_COMPILE_AND_EXECUTE) + (*pOp->glProc) (pOp); + + xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); + } + else + (*pOp->glProc) (pOp); +} + +static void +xglViewportProc (xglGLOpPtr pOp) +{ + cctx->attrib.viewport.x = pOp->u.rect.x; + cctx->attrib.viewport.y = pOp->u.rect.y; + cctx->attrib.viewport.width = pOp->u.rect.width; + cctx->attrib.viewport.height = pOp->u.rect.height; + + glViewport (pOp->u.rect.x + cctx->pDrawBuffer->xOff, + pOp->u.rect.y + cctx->pDrawBuffer->yOff, + pOp->u.rect.width, + pOp->u.rect.height); +} + +static void +xglViewport (GLint x, + GLint y, + GLsizei width, + GLsizei height) +{ + xglGLOpRec gl; + + gl.glProc = xglViewportProc; + + gl.u.rect.x = x; + gl.u.rect.y = y; + gl.u.rect.width = width; + gl.u.rect.height = height; + + xglGLOp (&gl); +} + +static void +xglScissorProc (xglGLOpPtr pOp) +{ + cctx->attrib.scissor.x = pOp->u.rect.x; + cctx->attrib.scissor.y = pOp->u.rect.y; + cctx->attrib.scissor.width = pOp->u.rect.width; + cctx->attrib.scissor.height = pOp->u.rect.height; +} + +static void +xglScissor (GLint x, + GLint y, + GLsizei width, + GLsizei height) +{ + xglGLOpRec gl; + + gl.glProc = xglScissorProc; + + gl.u.rect.x = x; + gl.u.rect.y = y; + gl.u.rect.width = width; + gl.u.rect.height = height; + + xglGLOp (&gl); +} + +static void +xglDrawBufferProc (xglGLOpPtr pOp) +{ + switch (pOp->u.enumeration) { + case GL_FRONT: + case GL_FRONT_AND_BACK: + break; + case GL_BACK: + if (!cctx->doubleBuffer) + { + xglRecordError (GL_INVALID_OPERATION); + return; + } + break; + default: + xglRecordError (GL_INVALID_ENUM); + return; + } + + cctx->attrib.drawBuffer = pOp->u.enumeration; + + glDrawBuffer (pOp->u.enumeration); +} + +static void +xglDrawBuffer (GLenum mode) +{ + xglGLOpRec gl; + + gl.glProc = xglDrawBufferProc; + + gl.u.enumeration = mode; + + xglGLOp (&gl); +} + +static void +xglReadBufferProc (xglGLOpPtr pOp) +{ + switch (pOp->u.enumeration) { + case GL_FRONT: + break; + case GL_BACK: + if (!cctx->doubleBuffer) + { + xglRecordError (GL_INVALID_OPERATION); + return; + } + break; + default: + xglRecordError (GL_INVALID_ENUM); + return; + } + + cctx->attrib.readBuffer = pOp->u.enumeration; + + glReadBuffer (pOp->u.enumeration); +} + +static void +xglReadBuffer (GLenum mode) +{ + xglGLOpRec gl; + + gl.glProc = xglReadBufferProc; + + gl.u.enumeration = mode; + + xglGLOp (&gl); +} + +static void +xglDisableProc (xglGLOpPtr pOp) +{ + xglTexUnitPtr pTexUnit = &cctx->attrib.texUnits[cctx->activeTexUnit]; + + switch (pOp->u.enumeration) { + case GL_SCISSOR_TEST: + cctx->attrib.scissorTest = GL_FALSE; + return; + case GL_TEXTURE_1D: + pTexUnit->enabled &= ~XGL_TEXTURE_1D_BIT; + break; + case GL_TEXTURE_2D: + pTexUnit->enabled &= ~XGL_TEXTURE_2D_BIT; + break; + case GL_TEXTURE_3D: + pTexUnit->enabled &= ~XGL_TEXTURE_3D_BIT; + break; + case GL_TEXTURE_RECTANGLE_NV: + pTexUnit->enabled &= ~XGL_TEXTURE_RECTANGLE_BIT; + break; + case GL_TEXTURE_CUBE_MAP_ARB: + pTexUnit->enabled &= ~XGL_TEXTURE_CUBE_MAP_BIT; + break; + default: + break; + } + + glDisable (pOp->u.enumeration); +} + +static void +xglDisable (GLenum cap) +{ + xglGLOpRec gl; + + gl.glProc = xglDisableProc; + + gl.u.enumeration = cap; + + xglGLOp (&gl); +} + +static void +xglEnableProc (xglGLOpPtr pOp) +{ + xglTexUnitPtr pTexUnit = &cctx->attrib.texUnits[cctx->activeTexUnit]; + + switch (pOp->u.enumeration) { + case GL_SCISSOR_TEST: + cctx->attrib.scissorTest = GL_TRUE; + return; + case GL_DEPTH_TEST: + if (!cctx->depthBits) + return; + case GL_STENCIL_TEST: + if (!cctx->stencilBits) + return; + case GL_TEXTURE_1D: + pTexUnit->enabled |= XGL_TEXTURE_1D_BIT; + break; + case GL_TEXTURE_2D: + pTexUnit->enabled |= XGL_TEXTURE_2D_BIT; + break; + case GL_TEXTURE_3D: + pTexUnit->enabled |= XGL_TEXTURE_3D_BIT; + break; + case GL_TEXTURE_RECTANGLE_NV: + pTexUnit->enabled |= XGL_TEXTURE_RECTANGLE_BIT; + break; + case GL_TEXTURE_CUBE_MAP_ARB: + pTexUnit->enabled |= XGL_TEXTURE_CUBE_MAP_BIT; + break; + default: + break; + } + + glEnable (pOp->u.enumeration); +} + +static void +xglEnable (GLenum cap) +{ + xglGLOpRec gl; + + gl.glProc = xglEnableProc; + + gl.u.enumeration = cap; + + xglGLOp (&gl); +} + +static void +xglDeleteTexObj (xglTexObjPtr pTexObj) +{ + if (pTexObj->pPixmap) + { + ScreenPtr pScreen = pTexObj->pPixmap->drawable.pScreen; + + (*pScreen->DestroyPixmap) (pTexObj->pPixmap); + + glitz_texture_object_destroy (pTexObj->object); + } + + if (pTexObj->name) + { + glDeleteTextures (1, &pTexObj->name); + } + + pTexObj->key = 0; + pTexObj->name = 0; + pTexObj->pPixmap = NULL; + pTexObj->object = NULL; +} + +static void +xglRefTexObj (xglTexObjPtr pTexObj) +{ + if (!pTexObj) + return; + + pTexObj->refcnt++; +} + +static void +xglUnrefTexObj (xglTexObjPtr pTexObj) +{ + if (!pTexObj) + return; + + pTexObj->refcnt--; + if (pTexObj->refcnt) + return; + + xglDeleteTexObj (pTexObj); + + xfree (pTexObj); +} + +static void +xglPushAttribProc (xglGLOpPtr pOp) +{ + xglGLAttributesPtr pAttrib; + GLint depth; + + glGetIntegerv (GL_MAX_ATTRIB_STACK_DEPTH, &depth); + + if (cctx->nAttribStack == depth) + { + xglRecordError (GL_STACK_OVERFLOW); + return; + } + + cctx->pAttribStack = + realloc (cctx->pAttribStack, + sizeof (xglGLAttributesRec) * (cctx->nAttribStack + 1)); + + if (!cctx->pAttribStack) + { + xglRecordError (GL_OUT_OF_MEMORY); + return; + } + + pAttrib = &cctx->pAttribStack[cctx->nAttribStack]; + pAttrib->mask = pOp->u.bitfield; + + *pAttrib = cctx->attrib; + + if (pOp->u.bitfield & GL_TEXTURE_BIT) + { + int i; + + for (i = 0; i < cctx->maxTexUnits; i++) + { + xglRefTexObj (pAttrib->texUnits[i].p1D); + xglRefTexObj (pAttrib->texUnits[i].p2D); + xglRefTexObj (pAttrib->texUnits[i].p3D); + xglRefTexObj (pAttrib->texUnits[i].pRect); + xglRefTexObj (pAttrib->texUnits[i].pCubeMap); + } + } + + cctx->nAttribStack++; + + glPushAttrib (pOp->u.bitfield); +} + +static void +xglPushAttrib (GLbitfield mask) +{ + xglGLOpRec gl; + + gl.glProc = xglPushAttribProc; + + gl.u.bitfield = mask; + + xglGLOp (&gl); +} + +static void +xglPopAttribProc (xglGLOpPtr pOp) +{ + xglGLAttributesPtr pAttrib; + GLbitfield mask; + + if (!cctx->nAttribStack) + { + xglRecordError (GL_STACK_UNDERFLOW); + return; + } + + cctx->nAttribStack--; + + pAttrib = &cctx->pAttribStack[cctx->nAttribStack]; + mask = pAttrib->mask; + + if (mask & GL_COLOR_BUFFER_BIT) + xglDrawBuffer (pAttrib->drawBuffer); + + if (mask & GL_PIXEL_MODE_BIT) + xglReadBuffer (pAttrib->readBuffer); + + if (mask & GL_SCISSOR_BIT) + { + xglScissor (pAttrib->scissor.x, + pAttrib->scissor.y, + pAttrib->scissor.width, + pAttrib->scissor.height); + + if (pAttrib->scissorTest) + xglEnable (GL_SCISSOR_TEST); + else + xglDisable (GL_SCISSOR_TEST); + } + else if (mask & GL_ENABLE_BIT) + { + if (pAttrib->scissorTest) + xglEnable (GL_SCISSOR_TEST); + else + xglDisable (GL_SCISSOR_TEST); + } + + if (mask & GL_VIEWPORT_BIT) + xglViewport (pAttrib->viewport.x, + pAttrib->viewport.y, + pAttrib->viewport.width, + pAttrib->viewport.height); + + if (mask & GL_TEXTURE_BIT) + { + int i; + + for (i = 0; i < cctx->maxTexUnits; i++) + { + xglUnrefTexObj (cctx->attrib.texUnits[i].p1D); + xglUnrefTexObj (cctx->attrib.texUnits[i].p2D); + xglUnrefTexObj (cctx->attrib.texUnits[i].p3D); + xglUnrefTexObj (cctx->attrib.texUnits[i].pRect); + xglUnrefTexObj (cctx->attrib.texUnits[i].pCubeMap); + + cctx->attrib.texUnits[i] = pAttrib->texUnits[i]; + } + } + else if (mask & GL_ENABLE_BIT) + { + int i; + + for (i = 0; i < cctx->maxTexUnits; i++) + cctx->attrib.texUnits[i].enabled = pAttrib->texUnits[i].enabled; + } + + cctx->pAttribStack = + realloc (cctx->pAttribStack, + sizeof (xglGLAttributesRec) * cctx->nAttribStack); + + glPopAttrib (); +} + +static void +xglPopAttrib (void) +{ + xglGLOpRec gl; + + gl.glProc = xglPopAttribProc; + + xglGLOp (&gl); +} + +static GLuint +xglActiveTextureBinding (GLenum target) +{ + xglTexObjPtr pTexObj; + + switch (target) { + case GL_TEXTURE_BINDING_1D: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p1D; + break; + case GL_TEXTURE_BINDING_2D: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; + break; + case GL_TEXTURE_BINDING_3D: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p3D; + break; + case GL_TEXTURE_BINDING_RECTANGLE_NV: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; + break; + case GL_TEXTURE_BINDING_CUBE_MAP_ARB: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pCubeMap; + break; + default: + return 0; + } + + if (pTexObj) + return pTexObj->key; + + return 0; +} + +#define DOUBLE_TO_BOOLEAN(X) ((X) ? GL_TRUE : GL_FALSE) +#define INT_TO_BOOLEAN(I) ((I) ? GL_TRUE : GL_FALSE) +#define ENUM_TO_BOOLEAN(E) ((E) ? GL_TRUE : GL_FALSE) + +static void +xglGetBooleanv (GLenum pname, + GLboolean *params) +{ + switch (pname) { + case GL_CURRENT_RASTER_POSITION: + { + GLdouble v[4]; + + glGetDoublev (GL_CURRENT_RASTER_POSITION, v); + + params[0] = DOUBLE_TO_BOOLEAN (v[0] - (GLdouble) cctx->drawXoff); + params[1] = DOUBLE_TO_BOOLEAN (v[1] - (GLdouble) cctx->drawYoff); + params[2] = DOUBLE_TO_BOOLEAN (v[2]); + params[3] = DOUBLE_TO_BOOLEAN (v[3]); + } break; + case GL_DOUBLEBUFFER: + params[0] = cctx->doubleBuffer; + break; + case GL_DEPTH_BITS: + params[0] = INT_TO_BOOLEAN (cctx->depthBits); + break; + case GL_STENCIL_BITS: + params[0] = INT_TO_BOOLEAN (cctx->stencilBits); + break; + case GL_DRAW_BUFFER: + params[0] = ENUM_TO_BOOLEAN (cctx->attrib.drawBuffer); + break; + case GL_READ_BUFFER: + params[0] = ENUM_TO_BOOLEAN (cctx->attrib.readBuffer); + break; + case GL_SCISSOR_BOX: + params[0] = INT_TO_BOOLEAN (cctx->attrib.scissor.x); + params[1] = INT_TO_BOOLEAN (cctx->attrib.scissor.y); + params[2] = INT_TO_BOOLEAN (cctx->attrib.scissor.width); + params[3] = INT_TO_BOOLEAN (cctx->attrib.scissor.height); + break; + case GL_SCISSOR_TEST: + params[0] = cctx->attrib.scissorTest; + break; + case GL_VIEWPORT: + params[0] = INT_TO_BOOLEAN (cctx->attrib.viewport.x); + params[1] = INT_TO_BOOLEAN (cctx->attrib.viewport.y); + params[2] = INT_TO_BOOLEAN (cctx->attrib.viewport.width); + params[3] = INT_TO_BOOLEAN (cctx->attrib.viewport.height); + break; + case GL_TEXTURE_BINDING_1D: + case GL_TEXTURE_BINDING_2D: + case GL_TEXTURE_BINDING_3D: + case GL_TEXTURE_RECTANGLE_NV: + /* should be safe to fall-through here */ + default: + glGetBooleanv (pname, params); + } +} + +#define INT_TO_DOUBLE(I) ((GLdouble) (I)) +#define ENUM_TO_DOUBLE(E) ((GLdouble) (E)) +#define BOOLEAN_TO_DOUBLE(B) ((B) ? 1.0F : 0.0F) + +static void +xglGetDoublev (GLenum pname, + GLdouble *params) +{ + switch (pname) { + case GL_CURRENT_RASTER_POSITION: + glGetDoublev (GL_CURRENT_RASTER_POSITION, params); + + params[0] -= (GLdouble) cctx->drawXoff; + params[1] -= (GLdouble) cctx->drawYoff; + break; + case GL_DOUBLEBUFFER: + params[0] = BOOLEAN_TO_DOUBLE (cctx->doubleBuffer); + break; + case GL_DEPTH_BITS: + params[0] = INT_TO_DOUBLE (cctx->depthBits); + break; + case GL_STENCIL_BITS: + params[0] = INT_TO_DOUBLE (cctx->stencilBits); + break; + case GL_DRAW_BUFFER: + params[0] = ENUM_TO_DOUBLE (cctx->attrib.drawBuffer); + break; + case GL_READ_BUFFER: + params[0] = ENUM_TO_DOUBLE (cctx->attrib.readBuffer); + break; + case GL_SCISSOR_BOX: + params[0] = cctx->attrib.scissor.x; + params[1] = cctx->attrib.scissor.y; + params[2] = cctx->attrib.scissor.width; + params[3] = cctx->attrib.scissor.height; + break; + case GL_SCISSOR_TEST: + params[0] = BOOLEAN_TO_DOUBLE (cctx->attrib.scissorTest); + break; + case GL_VIEWPORT: + params[0] = cctx->attrib.viewport.x; + params[1] = cctx->attrib.viewport.y; + params[2] = cctx->attrib.viewport.width; + params[3] = cctx->attrib.viewport.height; + break; + case GL_TEXTURE_BINDING_1D: + case GL_TEXTURE_BINDING_2D: + case GL_TEXTURE_BINDING_3D: + case GL_TEXTURE_RECTANGLE_NV: + params[0] = xglActiveTextureBinding (pname); + break; + case GL_MAX_TEXTURE_UNITS_ARB: + params[0] = cctx->maxTexUnits; + break; + default: + glGetDoublev (pname, params); + } +} + +#define INT_TO_FLOAT(I) ((GLfloat) (I)) +#define ENUM_TO_FLOAT(E) ((GLfloat) (E)) +#define BOOLEAN_TO_FLOAT(B) ((B) ? 1.0F : 0.0F) + +static void +xglGetFloatv (GLenum pname, + GLfloat *params) +{ + switch (pname) { + case GL_CURRENT_RASTER_POSITION: + glGetFloatv (GL_CURRENT_RASTER_POSITION, params); + + params[0] -= (GLfloat) cctx->drawXoff; + params[1] -= (GLfloat) cctx->drawYoff; + break; + case GL_DOUBLEBUFFER: + params[0] = BOOLEAN_TO_FLOAT (cctx->doubleBuffer); + break; + case GL_DEPTH_BITS: + params[0] = INT_TO_FLOAT (cctx->depthBits); + break; + case GL_STENCIL_BITS: + params[0] = INT_TO_FLOAT (cctx->stencilBits); + break; + case GL_DRAW_BUFFER: + params[0] = ENUM_TO_FLOAT (cctx->attrib.drawBuffer); + break; + case GL_READ_BUFFER: + params[0] = ENUM_TO_FLOAT (cctx->attrib.readBuffer); + break; + case GL_SCISSOR_BOX: + params[0] = cctx->attrib.scissor.x; + params[1] = cctx->attrib.scissor.y; + params[2] = cctx->attrib.scissor.width; + params[3] = cctx->attrib.scissor.height; + break; + case GL_SCISSOR_TEST: + params[0] = BOOLEAN_TO_FLOAT (cctx->attrib.scissorTest); + break; + case GL_VIEWPORT: + params[0] = cctx->attrib.viewport.x; + params[1] = cctx->attrib.viewport.y; + params[2] = cctx->attrib.viewport.width; + params[3] = cctx->attrib.viewport.height; + break; + case GL_TEXTURE_BINDING_1D: + case GL_TEXTURE_BINDING_2D: + case GL_TEXTURE_BINDING_3D: + case GL_TEXTURE_RECTANGLE_NV: + params[0] = xglActiveTextureBinding (pname); + break; + case GL_MAX_TEXTURE_UNITS_ARB: + params[0] = cctx->maxTexUnits; + break; + default: + glGetFloatv (pname, params); + } +} + +#define ENUM_TO_INT(E) ((GLint) (E)) +#define BOOLEAN_TO_INT(B) ((GLint) (B)) + +static void +xglGetIntegerv (GLenum pname, + GLint *params) +{ + switch (pname) { + case GL_CURRENT_RASTER_POSITION: + glGetIntegerv (GL_CURRENT_RASTER_POSITION, params); + + params[0] -= (GLint) cctx->drawXoff; + params[1] -= (GLint) cctx->drawYoff; + break; + case GL_DOUBLEBUFFER: + params[0] = BOOLEAN_TO_INT (cctx->doubleBuffer); + break; + case GL_DEPTH_BITS: + params[0] = cctx->depthBits; + break; + case GL_STENCIL_BITS: + params[0] = cctx->stencilBits; + break; + case GL_DRAW_BUFFER: + params[0] = ENUM_TO_INT (cctx->attrib.drawBuffer); + break; + case GL_READ_BUFFER: + params[0] = ENUM_TO_INT (cctx->attrib.readBuffer); + break; + case GL_SCISSOR_BOX: + params[0] = cctx->attrib.scissor.x; + params[1] = cctx->attrib.scissor.y; + params[2] = cctx->attrib.scissor.width; + params[3] = cctx->attrib.scissor.height; + break; + case GL_SCISSOR_TEST: + params[0] = BOOLEAN_TO_INT (cctx->attrib.scissorTest); + break; + case GL_VIEWPORT: + params[0] = cctx->attrib.viewport.x; + params[1] = cctx->attrib.viewport.y; + params[2] = cctx->attrib.viewport.width; + params[3] = cctx->attrib.viewport.height; + break; + case GL_TEXTURE_BINDING_1D: + case GL_TEXTURE_BINDING_2D: + case GL_TEXTURE_BINDING_3D: + case GL_TEXTURE_RECTANGLE_NV: + params[0] = xglActiveTextureBinding (pname); + break; + case GL_MAX_TEXTURE_UNITS_ARB: + params[0] = cctx->maxTexUnits; + break; + default: + glGetIntegerv (pname, params); + } +} + +static GLboolean +xglIsEnabled (GLenum cap) +{ + switch (cap) { + case GL_SCISSOR_TEST: + return cctx->attrib.scissorTest; + default: + return glIsEnabled (cap); + } +} + +static GLenum +xglGetError (void) +{ + GLenum error = cctx->errorValue; + + if (error != GL_NO_ERROR) + { + cctx->errorValue = GL_NO_ERROR; + return error; + } + + return glGetError (); +} + +static const GLubyte * +xglGetString (GLenum name) +{ + switch (name) { + case GL_VERSION: + if (!cctx->versionString) + { + static char *version = "1.2 (%s)"; + char *nativeVersion = (char *) glGetString (GL_VERSION); + + cctx->versionString = xalloc (strlen (version) + + strlen (nativeVersion)); + if (cctx->versionString) + sprintf (cctx->versionString, version, nativeVersion); + } + return (GLubyte *) cctx->versionString; + default: + return glGetString (name); + } +} + +static void +xglGenTextures (GLsizei n, + GLuint *textures) +{ + xglTexObjPtr pTexObj; + GLuint name; + + name = xglHashFindFreeKeyBlock (cctx->shared->texObjects, n); + + glGenTextures (n, textures); + + while (n--) + { + pTexObj = xalloc (sizeof (xglTexObjRec)); + if (pTexObj) + { + pTexObj->key = name; + pTexObj->name = *textures; + pTexObj->pPixmap = NULL; + pTexObj->object = NULL; + pTexObj->refcnt = 1; + + xglHashInsert (cctx->shared->texObjects, name, pTexObj); + } + else + { + xglRecordError (GL_OUT_OF_MEMORY); + } + + *textures++ = name++; + } +} + +static void +xglBindTextureProc (xglGLOpPtr pOp) +{ + xglTexObjPtr *ppTexObj; + + switch (pOp->u.bind_texture.target) { + case GL_TEXTURE_1D: + ppTexObj = &cctx->attrib.texUnits[cctx->activeTexUnit].p1D; + break; + case GL_TEXTURE_2D: + ppTexObj = &cctx->attrib.texUnits[cctx->activeTexUnit].p2D; + break; + case GL_TEXTURE_3D: + ppTexObj = &cctx->attrib.texUnits[cctx->activeTexUnit].p3D; + break; + case GL_TEXTURE_RECTANGLE_NV: + ppTexObj = &cctx->attrib.texUnits[cctx->activeTexUnit].pRect; + break; + case GL_TEXTURE_CUBE_MAP_ARB: + ppTexObj = &cctx->attrib.texUnits[cctx->activeTexUnit].pCubeMap; + break; + default: + xglRecordError (GL_INVALID_ENUM); + return; + } + + if (pOp->u.bind_texture.texture) + { + xglTexObjPtr pTexObj; + + pTexObj = (xglTexObjPtr) xglHashLookup (cctx->shared->texObjects, + pOp->u.bind_texture.texture); + if (!pTexObj) + { + pTexObj = xalloc (sizeof (xglTexObjRec)); + if (!pTexObj) + { + xglRecordError (GL_OUT_OF_MEMORY); + return; + } + + pTexObj->key = pOp->u.bind_texture.texture; + pTexObj->pPixmap = NULL; + pTexObj->object = NULL; + pTexObj->refcnt = 1; + + glGenTextures (1, &pTexObj->name); + + xglHashInsert (cctx->shared->texObjects, + pOp->u.bind_texture.texture, + pTexObj); + } + + xglRefTexObj (pTexObj); + xglUnrefTexObj (*ppTexObj); + *ppTexObj = pTexObj; + + glBindTexture (pOp->u.bind_texture.target, pTexObj->name); + } + else + { + xglUnrefTexObj (*ppTexObj); + *ppTexObj = NULL; + + glBindTexture (pOp->u.bind_texture.target, 0); + } +} + +static void +xglBindTexture (GLenum target, + GLuint texture) +{ + xglGLOpRec gl; + + gl.glProc = xglBindTextureProc; + + gl.u.bind_texture.target = target; + gl.u.bind_texture.texture = texture; + + xglGLOp (&gl); +} + +static void +xglSetupTextures (void) +{ + xglGLContextPtr pContext = cctx; + xglTexUnitPtr pTexUnit; + xglTexObjPtr pTexObj[XGL_MAX_TEXTURE_UNITS]; + int i, activeTexUnit; + + for (i = 0; i < pContext->maxTexUnits; i++) + { + pTexObj[i] = NULL; + + pTexUnit = &pContext->attrib.texUnits[i]; + if (pTexUnit->enabled) + { + if (pTexUnit->enabled & XGL_TEXTURE_RECTANGLE_BIT) + pTexObj[i] = pTexUnit->pRect; + else if (pTexUnit->enabled & XGL_TEXTURE_2D_BIT) + pTexObj[i] = pTexUnit->p2D; + + if (pTexObj[i] && pTexObj[i]->pPixmap) + { + if (!xglSyncSurface (&pTexObj[i]->pPixmap->drawable)) + pTexObj[i] = NULL; + } + else + pTexObj[i] = NULL; + } + } + + if (pContext != cctx) + { + XGL_SCREEN_PRIV (pContext->pDrawBuffer->pGC->pScreen); + + glitz_drawable_finish (pScreenPriv->drawable); + + xglSetCurrentContext (pContext); + } + + activeTexUnit = cctx->activeTexUnit; + for (i = 0; i < pContext->maxTexUnits; i++) + { + if (pTexObj[i]) + { + if (i != activeTexUnit) + { + cctx->ActiveTextureARB (GL_TEXTURE0_ARB + i); + activeTexUnit = i; + } + glitz_context_bind_texture (cctx->context, pTexObj[i]->object); + } + } + + if (activeTexUnit != cctx->activeTexUnit) + cctx->ActiveTextureARB (cctx->activeTexUnit); +} + +static GLboolean +xglAreTexturesResident (GLsizei n, + const GLuint *textures, + GLboolean *residences) +{ + GLboolean allResident = GL_TRUE; + int i, j; + + if (n < 0) + { + xglRecordError (GL_INVALID_VALUE); + return GL_FALSE; + } + + if (!textures || !residences) + return GL_FALSE; + + for (i = 0; i < n; i++) + { + xglTexObjPtr pTexObj; + GLboolean resident; + + if (textures[i] == 0) + { + xglRecordError (GL_INVALID_VALUE); + return GL_FALSE; + } + + pTexObj = (xglTexObjPtr) xglHashLookup (cctx->shared->texObjects, + textures[i]); + if (!pTexObj) + { + xglRecordError (GL_INVALID_VALUE); + return GL_FALSE; + } + + if (pTexObj->name == 0 || + glAreTexturesResident (1, &pTexObj->name, &resident)) + { + if (!allResident) + residences[i] = GL_TRUE; + } + else + { + if (allResident) + { + allResident = GL_FALSE; + + for (j = 0; j < i; j++) + residences[j] = GL_TRUE; + } + residences[i] = GL_FALSE; + } + } + + return allResident; +} + +static void +xglDeleteTextures (GLsizei n, + const GLuint *textures) +{ + xglTexObjPtr pTexObj; + + while (n--) + { + pTexObj = (xglTexObjPtr) xglHashLookup (cctx->shared->texObjects, + *textures); + if (pTexObj) + { + xglDeleteTexObj (pTexObj); + xglUnrefTexObj (pTexObj); + xglHashRemove (cctx->shared->texObjects, *textures); + } + textures++; + } +} + +static GLboolean +xglIsTexture (GLuint texture) +{ + xglTexObjPtr pTexObj; + + if (!texture) + return GL_FALSE; + + pTexObj = (xglTexObjPtr) xglHashLookup (cctx->shared->texObjects, texture); + if (pTexObj) + return GL_TRUE; + + return GL_FALSE; +} + +static void +xglPrioritizeTextures (GLsizei n, + const GLuint *textures, + const GLclampf *priorities) +{ + xglTexObjPtr pTexObj; + int i; + + if (n < 0) + { + xglRecordError (GL_INVALID_VALUE); + return; + } + + if (!priorities) + return; + + for (i = 0; i < n; i++) + { + if (textures[i] <= 0) + continue; + + pTexObj = (xglTexObjPtr) xglHashLookup (cctx->shared->texObjects, + textures[i]); + if (pTexObj && pTexObj->name) + glPrioritizeTextures (1, &pTexObj->name, &priorities[i]); + } +} + +static glitz_texture_filter_t +xglTextureFilter (GLenum param) +{ + switch (param) { + case GL_LINEAR: + return GLITZ_TEXTURE_FILTER_LINEAR; + case GL_NEAREST: + default: + return GLITZ_TEXTURE_FILTER_NEAREST; + } +} + +static glitz_texture_wrap_t +xglTextureWrap (GLenum param) +{ + switch (param) { + case GL_CLAMP_TO_EDGE: + return GLITZ_TEXTURE_WRAP_CLAMP_TO_EDGE; + case GL_CLAMP_TO_BORDER: + return GLITZ_TEXTURE_WRAP_CLAMP_TO_BORDER; + case GL_REPEAT: + return GLITZ_TEXTURE_WRAP_REPEAT; + case GL_MIRRORED_REPEAT: + return GLITZ_TEXTURE_WRAP_MIRRORED_REPEAT; + case GL_CLAMP: + default: + return GLITZ_TEXTURE_WRAP_CLAMP; + } +} + +static void +xglTexParameterfvProc (xglGLOpPtr pOp) +{ + xglTexObjPtr pTexObj; + + glTexParameterfv (pOp->u.tex_parameter_fv.target, + pOp->u.tex_parameter_fv.pname, + pOp->u.tex_parameter_fv.params); + + switch (pOp->u.tex_parameter_fv.target) { + case GL_TEXTURE_2D: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; + break; + case GL_TEXTURE_RECTANGLE_NV: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; + break; + default: + pTexObj = NULL; + break; + } + + if (pTexObj && pTexObj->pPixmap) + { + GLfloat *params = pOp->u.tex_parameter_fv.params; + + switch (pOp->u.tex_parameter_fv.pname) { + case GL_TEXTURE_MIN_FILTER: + glitz_texture_object_set_filter (pTexObj->object, + GLITZ_TEXTURE_FILTER_TYPE_MIN, + xglTextureFilter (params[0])); + break; + case GL_TEXTURE_MAG_FILTER: + glitz_texture_object_set_filter (pTexObj->object, + GLITZ_TEXTURE_FILTER_TYPE_MAG, + xglTextureFilter (params[0])); + break; + case GL_TEXTURE_WRAP_S: + glitz_texture_object_set_wrap (pTexObj->object, + GLITZ_TEXTURE_WRAP_TYPE_S, + xglTextureWrap (params[0])); + break; + case GL_TEXTURE_WRAP_T: + glitz_texture_object_set_wrap (pTexObj->object, + GLITZ_TEXTURE_WRAP_TYPE_T, + xglTextureWrap (params[0])); + break; + case GL_TEXTURE_BORDER_COLOR: { + glitz_color_t color; + + color.red = params[0] * 0xffff; + color.green = params[1] * 0xffff; + color.blue = params[2] * 0xffff; + color.alpha = params[3] * 0xffff; + + glitz_texture_object_set_border_color (pTexObj->object, &color); + } + default: + break; + } + } +} + +static void +xglTexParameterfv (GLenum target, + GLenum pname, + const GLfloat *params) +{ + xglGLOpRec gl; + + gl.glProc = xglTexParameterfvProc; + + gl.u.tex_parameter_fv.target = target; + gl.u.tex_parameter_fv.pname = pname; + + switch (pname) { + case GL_TEXTURE_BORDER_COLOR: + gl.u.tex_parameter_fv.params[3] = params[3]; + gl.u.tex_parameter_fv.params[2] = params[2]; + gl.u.tex_parameter_fv.params[1] = params[1]; + /* fall-through */ + default: + gl.u.tex_parameter_fv.params[0] = params[0]; + break; + } + + xglGLOp (&gl); +} + +static void +xglTexParameteriv (GLenum target, + GLenum pname, + const GLint *params) +{ + xglGLOpRec gl; + + gl.glProc = xglTexParameterfvProc; + + gl.u.tex_parameter_fv.target = target; + gl.u.tex_parameter_fv.pname = pname; + + switch (pname) { + case GL_TEXTURE_BORDER_COLOR: + gl.u.tex_parameter_fv.params[3] = (GLfloat) params[3] / INT_MAX; + gl.u.tex_parameter_fv.params[2] = (GLfloat) params[2] / INT_MAX; + gl.u.tex_parameter_fv.params[1] = (GLfloat) params[1] / INT_MAX; + gl.u.tex_parameter_fv.params[0] = (GLfloat) params[0] / INT_MAX; + break; + default: + gl.u.tex_parameter_fv.params[0] = params[0]; + break; + } + + xglGLOp (&gl); +} + +static void +xglTexParameterf (GLenum target, + GLenum pname, + GLfloat param) +{ + xglTexParameterfv (target, pname, (const GLfloat *) ¶m); +} + +static void +xglTexParameteri (GLenum target, + GLenum pname, + GLint param) +{ + xglTexParameteriv (target, pname, (const GLint *) ¶m); +} + +static void +xglGetTexLevelParameterfv (GLenum target, + GLint level, + GLenum pname, + GLfloat *params) +{ + xglTexObjPtr pTexObj; + + switch (target) { + case GL_TEXTURE_2D: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; + break; + case GL_TEXTURE_RECTANGLE_NV: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; + break; + default: + pTexObj = NULL; + break; + } + + if (pTexObj && pTexObj->pPixmap) + { + glitz_context_bind_texture (cctx->context, pTexObj->object); + + glGetTexLevelParameterfv (target, level, pname, params); + glBindTexture (target, pTexObj->name); + } + else + glGetTexLevelParameterfv (target, level, pname, params); +} + +static void +xglGetTexLevelParameteriv (GLenum target, + GLint level, + GLenum pname, + GLint *params) +{ + xglTexObjPtr pTexObj; + + switch (target) { + case GL_TEXTURE_2D: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; + break; + case GL_TEXTURE_RECTANGLE_NV: + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; + break; + default: + pTexObj = NULL; + break; + } + + if (pTexObj && pTexObj->pPixmap) + { + glitz_context_bind_texture (cctx->context, pTexObj->object); + + glGetTexLevelParameteriv (target, level, pname, params); + glBindTexture (target, pTexObj->name); + } + else + glGetTexLevelParameteriv (target, level, pname, params); +} + +static GLuint +xglGenLists (GLsizei range) +{ + xglDisplayListPtr pDisplayList; + GLuint first, name; + + first = xglHashFindFreeKeyBlock (cctx->shared->displayLists, range); + + name = first; + for (name = first; range--; name++) + { + pDisplayList = xglCreateList (); + if (pDisplayList) + { + xglHashInsert (cctx->shared->displayLists, name, pDisplayList); + } + else + { + xglRecordError (GL_OUT_OF_MEMORY); + } + } + + return first; +} + +static void +xglNewList (GLuint list, + GLenum mode) +{ + if (!list) + { + xglRecordError (GL_INVALID_VALUE); + return; + } + + if (cctx->list) + { + xglRecordError (GL_INVALID_OPERATION); + return; + } + + cctx->pList = xglCreateList (); + if (!cctx->pList) + { + xglRecordError (GL_OUT_OF_MEMORY); + return; + } + + cctx->list = list; + cctx->listMode = mode; + + xglStartList (XGL_LIST_OP_CALLS, mode); +} + +static void +xglEndList (void) +{ + xglDisplayListPtr pDisplayList; + + if (!cctx->list) + { + xglRecordError (GL_INVALID_OPERATION); + return; + } + + glEndList (); + + pDisplayList = (xglDisplayListPtr) + xglHashLookup (cctx->shared->displayLists, cctx->list); + if (pDisplayList) + { + xglHashRemove (cctx->shared->displayLists, cctx->list); + xglDestroyList (pDisplayList); + } + + xglHashInsert (cctx->shared->displayLists, cctx->list, cctx->pList); + + cctx->list = 0; +} + +static void +xglDrawList (GLuint list) +{ + RegionRec region; + BoxRec scissor, box; + BoxPtr pBox; + int nBox; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + while (nBox--) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + if (box.x1 < box.x2 && box.y1 < box.y2) + { + XGL_GLX_SET_SCISSOR_BOX (&box); + + glCallList (list); + + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + } + } +} + +static void +xglCallDisplayList (GLuint list, + int nesting) +{ + if (nesting > cctx->maxListNesting) + return; + + if (!list) + { + xglRecordError (GL_INVALID_VALUE); + return; + } + + if (cctx->list) + { + if (!xglResizeList (cctx->pList, cctx->pList->nOp + 1)) + { + xglRecordError (GL_OUT_OF_MEMORY); + return; + } + + cctx->pList->pOp[cctx->pList->nOp].type = XGL_LIST_OP_LIST; + cctx->pList->pOp[cctx->pList->nOp].u.list = list; + cctx->pList->nOp++; + } + else + { + xglDisplayListPtr pDisplayList; + + pDisplayList = (xglDisplayListPtr) + xglHashLookup (cctx->shared->displayLists, list); + if (pDisplayList) + { + xglListOpPtr pOp = pDisplayList->pOp; + int nOp = pDisplayList->nOp; + + while (nOp--) + { + switch (pOp->type) { + case XGL_LIST_OP_CALLS: + glCallList (pOp->u.list); + break; + case XGL_LIST_OP_DRAW: + xglDrawList (pOp->u.list); + break; + case XGL_LIST_OP_GL: + (*pOp->u.gl->glProc) (pOp->u.gl); + break; + case XGL_LIST_OP_LIST: + xglCallDisplayList (pOp->u.list, nesting + 1); + break; + } + + pOp++; + } + } + } +} + +static void +xglCallList (GLuint list) +{ + xglCallDisplayList (list, 1); +} + +static void +xglCallLists (GLsizei n, + GLenum type, + const GLvoid *lists) +{ + GLuint list; + GLint base, i; + + glGetIntegerv (GL_LIST_BASE, &base); + + for (i = 0; i < n; i++) + { + switch (type) { + case GL_BYTE: + list = (GLuint) *(((GLbyte *) lists) + n); + break; + case GL_UNSIGNED_BYTE: + list = (GLuint) *(((GLubyte *) lists) + n); + break; + case GL_SHORT: + list = (GLuint) *(((GLshort *) lists) + n); + break; + case GL_UNSIGNED_SHORT: + list = (GLuint) *(((GLushort *) lists) + n); + break; + case GL_INT: + list = (GLuint) *(((GLint *) lists) + n); + break; + case GL_UNSIGNED_INT: + list = (GLuint) *(((GLuint *) lists) + n); + break; + case GL_FLOAT: + list = (GLuint) *(((GLfloat *) lists) + n); + break; + case GL_2_BYTES: + { + GLubyte *ubptr = ((GLubyte *) lists) + 2 * n; + list = (GLuint) *ubptr * 256 + (GLuint) *(ubptr + 1); + } break; + case GL_3_BYTES: + { + GLubyte *ubptr = ((GLubyte *) lists) + 3 * n; + list = (GLuint) * ubptr * 65536 + + (GLuint) * (ubptr + 1) * 256 + + (GLuint) * (ubptr + 2); + } break; + case GL_4_BYTES: + { + GLubyte *ubptr = ((GLubyte *) lists) + 4 * n; + list = (GLuint) * ubptr * 16777216 + + (GLuint) * (ubptr + 1) * 65536 + + (GLuint) * (ubptr + 2) * 256 + + (GLuint) * (ubptr + 3); + } break; + default: + xglRecordError (GL_INVALID_ENUM); + return; + } + + xglCallDisplayList (base + list, 1); + } +} + +static void +xglDeleteLists (GLuint list, + GLsizei range) +{ + xglDisplayListPtr pDisplayList; + GLint i; + + if (range < 0) + { + xglRecordError (GL_INVALID_VALUE); + return; + } + + for (i = 0; i < range; i++) + { + pDisplayList = (xglDisplayListPtr) + xglHashLookup (cctx->shared->displayLists, list + i); + if (pDisplayList) + { + xglHashRemove (cctx->shared->displayLists, list + i); + xglDestroyList (pDisplayList); + } + } +} + +static GLboolean +xglIsList (GLuint list) +{ + xglDisplayListPtr pDisplayList; + + if (!list) + return GL_FALSE; + + pDisplayList = (xglDisplayListPtr) + xglHashLookup (cctx->shared->displayLists, list); + if (pDisplayList) + return GL_TRUE; + + return GL_FALSE; +} + +static void +xglFlush (void) +{ + glFlush (); + + if (cctx->pDrawBuffer->pDrawable) + { + xglGLBufferPtr pBuffer = cctx->pDrawBuffer; + + if (REGION_NOTEMPTY (pBuffer->pDrawable->pScreen, &pBuffer->damage)) + { + xglAddBitDamage (pBuffer->pDrawable, &pBuffer->damage); + DamageDamageRegion (pBuffer->pDrawable, &pBuffer->damage); + REGION_EMPTY (pBuffer->pDrawable->pScreen, &pBuffer->damage); + } + } +} + +static void +xglFinish (void) +{ + glFinish (); + + if (cctx->pDrawBuffer->pDrawable) + { + xglGLBufferPtr pBuffer = cctx->pDrawBuffer; + + if (REGION_NOTEMPTY (pBuffer->pDrawable->pScreen, &pBuffer->damage)) + { + xglAddBitDamage (pBuffer->pDrawable, &pBuffer->damage); + DamageDamageRegion (pBuffer->pDrawable, &pBuffer->damage); + REGION_EMPTY (pBuffer->pDrawable->pScreen, &pBuffer->damage); + } + } +} + +static void +xglClear (GLbitfield mask) +{ + GLenum mode; + + if (cctx->list) + { + glEndList (); + xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); + glClear (mask); + glEndList (); + + mode = cctx->listMode; + } + else + mode = GL_COMPILE_AND_EXECUTE; + + if (mode == GL_COMPILE_AND_EXECUTE) + { + RegionRec region; + BoxRec scissor, box; + BoxPtr pBox; + int nBox; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + while (nBox--) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + if (box.x1 < box.x2 && box.y1 < box.y2) + { + XGL_GLX_SET_SCISSOR_BOX (&box); + + glClear (mask); + + if (mask & GL_COLOR_BUFFER_BIT) + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + } + } + } + + if (cctx->list) + xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); +} + +static void +xglAccum (GLenum op, + GLfloat value) +{ + if (op == GL_RETURN) + { + GLenum listMode; + + if (cctx->list) + { + glEndList (); + xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); + glAccum (GL_RETURN, value); + glEndList (); + + listMode = cctx->listMode; + } + else + listMode = GL_COMPILE_AND_EXECUTE; + + if (listMode == GL_COMPILE_AND_EXECUTE) + { + RegionRec region; + BoxRec scissor, box; + BoxPtr pBox; + int nBox; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + while (nBox--) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + if (box.x1 < box.x2 && box.y1 < box.y2) + { + XGL_GLX_SET_SCISSOR_BOX (&box); + + glAccum (GL_RETURN, value); + + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + } + } + } + + if (cctx->list) + xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); + } + else + glAccum (op, value); +} + +static void +xglDrawArrays (GLenum mode, + GLint first, + GLsizei count) +{ + GLenum listMode; + + if (cctx->list) + { + glEndList (); + xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); + glDrawArrays (mode, first, count); + glEndList (); + + listMode = cctx->listMode; + } + else + listMode = GL_COMPILE_AND_EXECUTE; + + if (listMode == GL_COMPILE_AND_EXECUTE) + { + RegionRec region; + BoxRec scissor, box; + BoxPtr pBox; + int nBox; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + while (nBox--) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + if (box.x1 < box.x2 && box.y1 < box.y2) + { + XGL_GLX_SET_SCISSOR_BOX (&box); + + glDrawArrays (mode, first, count); + + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + } + } + } + + if (cctx->list) + xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); +} + +static void +xglDrawElements (GLenum mode, + GLsizei count, + GLenum type, + const GLvoid *indices) +{ + GLenum listMode; + + if (cctx->list) + { + glEndList (); + xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); + glDrawElements (mode, count, type, indices); + glEndList (); + + listMode = cctx->listMode; + } + else + listMode = GL_COMPILE_AND_EXECUTE; + + if (listMode == GL_COMPILE_AND_EXECUTE) + { + RegionRec region; + BoxRec scissor, box; + BoxPtr pBox; + int nBox; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + while (nBox--) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + if (box.x1 < box.x2 && box.y1 < box.y2) + { + XGL_GLX_SET_SCISSOR_BOX (&box); + + glDrawElements (mode, count, type, indices); + + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + } + } + } + + if (cctx->list) + xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); +} + +static void +xglDrawPixels (GLsizei width, + GLsizei height, + GLenum format, + GLenum type, + const GLvoid *pixels) +{ + GLenum listMode; + + if (cctx->list) + { + glEndList (); + xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); + glDrawPixels (width, height, format, type, pixels); + glEndList (); + + listMode = cctx->listMode; + } + else + listMode = GL_COMPILE_AND_EXECUTE; + + if (listMode == GL_COMPILE_AND_EXECUTE) + { + RegionRec region; + BoxRec scissor, box; + BoxPtr pBox; + int nBox; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + while (nBox--) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + if (box.x1 < box.x2 && box.y1 < box.y2) + { + XGL_GLX_SET_SCISSOR_BOX (&box); + + glDrawPixels (width, height, format, type, pixels); + + if (format != GL_STENCIL_INDEX) + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + } + } + } + + if (cctx->list) + xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); +} + +static void +xglBitmap (GLsizei width, + GLsizei height, + GLfloat xorig, + GLfloat yorig, + GLfloat xmove, + GLfloat ymove, + const GLubyte *bitmap) +{ + GLenum listMode; + + if (cctx->list) + { + glEndList (); + xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); + glBitmap (width, height, xorig, yorig, 0, 0, bitmap); + glEndList (); + + listMode = cctx->listMode; + } + else + listMode = GL_COMPILE_AND_EXECUTE; + + if (listMode == GL_COMPILE_AND_EXECUTE && width && height) + { + RegionRec region; + BoxRec scissor, box; + BoxPtr pBox; + int nBox; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + while (nBox--) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + if (box.x1 < box.x2 && box.y1 < box.y2) + { + XGL_GLX_SET_SCISSOR_BOX (&box); + + glBitmap (width, height, xorig, yorig, 0, 0, bitmap); + + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + } + } + } + + if (cctx->list) + xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); + + glBitmap (0, 0, 0, 0, xmove, ymove, NULL); +} + +static void +xglRectdv (const GLdouble *v1, + const GLdouble *v2) +{ + GLenum listMode; + + if (cctx->list) + { + glEndList (); + xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); + glRectdv (v1, v2); + glEndList (); + + listMode = cctx->listMode; + } + else + listMode = GL_COMPILE_AND_EXECUTE; + + if (listMode == GL_COMPILE_AND_EXECUTE) + { + RegionRec region; + BoxRec scissor, box; + BoxPtr pBox; + int nBox; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + while (nBox--) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + if (box.x1 < box.x2 && box.y1 < box.y2) + { + XGL_GLX_SET_SCISSOR_BOX (&box); + + glRectdv (v1, v2); + + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + } + } + } + + if (cctx->list) + xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); +} + +static void +xglRectfv (const GLfloat *v1, + const GLfloat *v2) +{ + GLdouble dv1[2]; + GLdouble dv2[2]; + + dv1[0] = (GLdouble) v1[0]; + dv1[1] = (GLdouble) v1[1]; + dv2[0] = (GLdouble) v2[0]; + dv2[1] = (GLdouble) v2[1]; + + xglRectdv (dv1, dv2); +} + +static void +xglRectiv (const GLint *v1, + const GLint *v2) +{ + GLdouble dv1[2]; + GLdouble dv2[2]; + + dv1[0] = (GLdouble) v1[0]; + dv1[1] = (GLdouble) v1[1]; + dv2[0] = (GLdouble) v2[0]; + dv2[1] = (GLdouble) v2[1]; + + xglRectdv (dv1, dv2); +} + +static void +xglRectsv (const GLshort *v1, + const GLshort *v2) +{ + GLdouble dv1[2]; + GLdouble dv2[2]; + + dv1[0] = (GLdouble) v1[0]; + dv1[1] = (GLdouble) v1[1]; + dv2[0] = (GLdouble) v2[0]; + dv2[1] = (GLdouble) v2[1]; + + xglRectdv (dv1, dv2); +} + +static void +xglBegin (GLenum mode) +{ + if (cctx->list) + { + glEndList (); + xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); + } + else + { + BoxRec scissor; + BoxPtr pBox; + int nBox; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + if (nBox == 1) + { + BoxRec box = *pBox; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + XGL_GLX_SET_SCISSOR_BOX (&box); + } + else + { + if (!cctx->groupList) + cctx->groupList = glGenLists (1); + + glNewList (cctx->groupList, GL_COMPILE); + } + } + + glBegin (mode); +} + +static void +xglEnd (void) +{ + glEnd (); + + if (!cctx->list || cctx->listMode == GL_COMPILE_AND_EXECUTE) + { + RegionRec region; + BoxRec scissor, box; + BoxPtr pBox; + int nBox; + GLuint list; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + if (cctx->list) + { + list = cctx->pList->pOp[cctx->pList->nOp - 1].u.list; + } + else + { + if (nBox == 1) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + return; + } + + list = cctx->groupList; + } + + glEndList (); + + while (nBox--) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + if (box.x1 < box.x2 && box.y1 < box.y2) + { + XGL_GLX_SET_SCISSOR_BOX (&box); + + glCallList (list); + + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + } + } + } + + if (cctx->list) + xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); +} + +static void +xglCopyPixelsProc (xglGLOpPtr pOp) +{ + RegionRec region; + BoxRec scissor, box; + BoxPtr pBox; + int nBox; + + XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); + + while (nBox--) + { + box = *pBox++; + + if (cctx->attrib.scissorTest) + XGL_GLX_INTERSECT_BOX (&box, &scissor); + + if (box.x1 < box.x2 && box.y1 < box.y2) + { + XGL_GLX_SET_SCISSOR_BOX (&box); + + glCopyPixels (pOp->u.copy_pixels.x + cctx->pReadBuffer->xOff, + pOp->u.copy_pixels.y + cctx->pReadBuffer->yOff, + pOp->u.copy_pixels.width, + pOp->u.copy_pixels.height, + pOp->u.copy_pixels.type); + + if (pOp->u.copy_pixels.type == GL_COLOR) + XGL_GLX_DRAW_DAMAGE (&box, ®ion); + } + } +} + +static void +xglCopyPixels (GLint x, + GLint y, + GLsizei width, + GLsizei height, + GLenum type) +{ + xglGLOpRec gl; + + gl.glProc = xglCopyPixelsProc; + + gl.u.copy_pixels.x = x; + gl.u.copy_pixels.y = y; + gl.u.copy_pixels.width = width; + gl.u.copy_pixels.height = height; + gl.u.copy_pixels.type = type; + + xglGLOp (&gl); +} + +static void +xglReadPixels (GLint x, + GLint y, + GLsizei width, + GLsizei height, + GLenum format, + GLenum type, + GLvoid *pixels) +{ + glReadPixels (x + cctx->pReadBuffer->xOff, + y + cctx->pReadBuffer->yOff, + width, height, format, type, pixels); +} + +static void +xglCopyTexImage1DProc (xglGLOpPtr pOp) +{ + glCopyTexImage1D (pOp->u.copy_tex_image_1d.target, + pOp->u.copy_tex_image_1d.level, + pOp->u.copy_tex_image_1d.internalformat, + pOp->u.copy_tex_image_1d.x + cctx->pReadBuffer->xOff, + pOp->u.copy_tex_image_1d.y + cctx->pReadBuffer->yOff, + pOp->u.copy_tex_image_1d.width, + pOp->u.copy_tex_image_1d.border); +} + +static void +xglCopyTexImage1D (GLenum target, + GLint level, + GLenum internalformat, + GLint x, + GLint y, + GLsizei width, + GLint border) +{ + xglGLOpRec gl; + + gl.glProc = xglCopyTexImage1DProc; + + gl.u.copy_tex_image_1d.target = target; + gl.u.copy_tex_image_1d.level = level; + gl.u.copy_tex_image_1d.internalformat = internalformat; + gl.u.copy_tex_image_1d.x = x; + gl.u.copy_tex_image_1d.y = y; + gl.u.copy_tex_image_1d.width = width; + gl.u.copy_tex_image_1d.border = border; + + xglGLOp (&gl); +} + +static void +xglCopyTexImage2DProc (xglGLOpPtr pOp) +{ + glCopyTexImage2D (pOp->u.copy_tex_image_2d.target, + pOp->u.copy_tex_image_2d.level, + pOp->u.copy_tex_image_2d.internalformat, + pOp->u.copy_tex_image_2d.x + cctx->pReadBuffer->xOff, + pOp->u.copy_tex_image_2d.y + cctx->pReadBuffer->yOff, + pOp->u.copy_tex_image_2d.width, + pOp->u.copy_tex_image_2d.height, + pOp->u.copy_tex_image_2d.border); +} + +static void +xglCopyTexImage2D (GLenum target, + GLint level, + GLenum internalformat, + GLint x, + GLint y, + GLsizei width, + GLsizei height, + GLint border) +{ + xglGLOpRec gl; + + gl.glProc = xglCopyTexImage2DProc; + + gl.u.copy_tex_image_2d.target = target; + gl.u.copy_tex_image_2d.level = level; + gl.u.copy_tex_image_2d.internalformat = internalformat; + gl.u.copy_tex_image_2d.x = x; + gl.u.copy_tex_image_2d.y = y; + gl.u.copy_tex_image_2d.width = width; + gl.u.copy_tex_image_2d.height = height; + gl.u.copy_tex_image_2d.border = border; + + xglGLOp (&gl); +} + +static void +xglCopyTexSubImage1DProc (xglGLOpPtr pOp) +{ + glCopyTexSubImage1D (pOp->u.copy_tex_sub_image_1d.target, + pOp->u.copy_tex_sub_image_1d.level, + pOp->u.copy_tex_sub_image_1d.xoffset, + pOp->u.copy_tex_sub_image_1d.x + + cctx->pReadBuffer->xOff, + pOp->u.copy_tex_sub_image_1d.y + + cctx->pReadBuffer->yOff, + pOp->u.copy_tex_sub_image_1d.width); +} + +static void +xglCopyTexSubImage1D (GLenum target, + GLint level, + GLint xoffset, + GLint x, + GLint y, + GLsizei width) +{ + xglGLOpRec gl; + + gl.glProc = xglCopyTexSubImage1DProc; + + gl.u.copy_tex_sub_image_1d.target = target; + gl.u.copy_tex_sub_image_1d.level = level; + gl.u.copy_tex_sub_image_1d.xoffset = xoffset; + gl.u.copy_tex_sub_image_1d.x = x; + gl.u.copy_tex_sub_image_1d.y = y; + gl.u.copy_tex_sub_image_1d.width = width; + + xglGLOp (&gl); +} + +static void +xglCopyTexSubImage2DProc (xglGLOpPtr pOp) +{ + glCopyTexSubImage2D (pOp->u.copy_tex_sub_image_2d.target, + pOp->u.copy_tex_sub_image_2d.level, + pOp->u.copy_tex_sub_image_2d.xoffset, + pOp->u.copy_tex_sub_image_2d.yoffset, + pOp->u.copy_tex_sub_image_2d.x + + cctx->pReadBuffer->xOff, + pOp->u.copy_tex_sub_image_2d.y + + cctx->pReadBuffer->yOff, + pOp->u.copy_tex_sub_image_2d.width, + pOp->u.copy_tex_sub_image_2d.height); +} + +static void +xglCopyTexSubImage2D (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint x, + GLint y, + GLsizei width, + GLsizei height) +{ + xglGLOpRec gl; + + gl.glProc = xglCopyTexSubImage2DProc; + + gl.u.copy_tex_sub_image_2d.target = target; + gl.u.copy_tex_sub_image_2d.level = level; + gl.u.copy_tex_sub_image_2d.xoffset = xoffset; + gl.u.copy_tex_sub_image_2d.yoffset = yoffset; + gl.u.copy_tex_sub_image_2d.x = x; + gl.u.copy_tex_sub_image_2d.y = y; + gl.u.copy_tex_sub_image_2d.width = width; + gl.u.copy_tex_sub_image_2d.height = height; + + xglGLOp (&gl); +} + +static void +xglCopyColorTableProc (xglGLOpPtr pOp) +{ + glCopyColorTable (pOp->u.copy_color_table.target, + pOp->u.copy_color_table.internalformat, + pOp->u.copy_color_table.x + cctx->pReadBuffer->xOff, + pOp->u.copy_color_table.y + cctx->pReadBuffer->yOff, + pOp->u.copy_color_table.width); +} + +static void +xglCopyColorTable (GLenum target, + GLenum internalformat, + GLint x, + GLint y, + GLsizei width) +{ + xglGLOpRec gl; + + gl.glProc = xglCopyColorTableProc; + + gl.u.copy_color_table.target = target; + gl.u.copy_color_table.internalformat = internalformat; + gl.u.copy_color_table.x = x; + gl.u.copy_color_table.y = y; + gl.u.copy_color_table.width = width; + + xglGLOp (&gl); +} + +static void +xglCopyColorSubTableProc (xglGLOpPtr pOp) +{ + glCopyColorTable (pOp->u.copy_color_sub_table.target, + pOp->u.copy_color_sub_table.start, + pOp->u.copy_color_sub_table.x + cctx->pReadBuffer->xOff, + pOp->u.copy_color_sub_table.y + cctx->pReadBuffer->yOff, + pOp->u.copy_color_sub_table.width); +} + +static void +xglCopyColorSubTable (GLenum target, + GLsizei start, + GLint x, + GLint y, + GLsizei width) +{ + xglGLOpRec gl; + + gl.glProc = xglCopyColorSubTableProc; + + gl.u.copy_color_sub_table.target = target; + gl.u.copy_color_sub_table.start = start; + gl.u.copy_color_sub_table.x = x; + gl.u.copy_color_sub_table.y = y; + gl.u.copy_color_sub_table.width = width; + + xglGLOp (&gl); +} + +static void +xglCopyConvolutionFilter1DProc (xglGLOpPtr pOp) +{ + GLenum internalformat = pOp->u.copy_convolution_filter_1d.internalformat; + + glCopyConvolutionFilter1D (pOp->u.copy_convolution_filter_1d.target, + internalformat, + pOp->u.copy_convolution_filter_1d.x + + cctx->pReadBuffer->xOff, + pOp->u.copy_convolution_filter_1d.y + + cctx->pReadBuffer->yOff, + pOp->u.copy_convolution_filter_1d.width); +} + +static void +xglCopyConvolutionFilter1D (GLenum target, + GLenum internalformat, + GLint x, + GLint y, + GLsizei width) +{ + xglGLOpRec gl; + + gl.glProc = xglCopyConvolutionFilter1DProc; + + gl.u.copy_convolution_filter_1d.target = target; + gl.u.copy_convolution_filter_1d.internalformat = internalformat; + gl.u.copy_convolution_filter_1d.x = x; + gl.u.copy_convolution_filter_1d.y = y; + gl.u.copy_convolution_filter_1d.width = width; + + xglGLOp (&gl); +} + +static void +xglCopyConvolutionFilter2DProc (xglGLOpPtr pOp) +{ + GLenum internalformat = pOp->u.copy_convolution_filter_2d.internalformat; + + glCopyConvolutionFilter2D (pOp->u.copy_convolution_filter_2d.target, + internalformat, + pOp->u.copy_convolution_filter_2d.x + + cctx->pReadBuffer->xOff, + pOp->u.copy_convolution_filter_2d.y + + cctx->pReadBuffer->yOff, + pOp->u.copy_convolution_filter_2d.width, + pOp->u.copy_convolution_filter_2d.height); +} + +static void +xglCopyConvolutionFilter2D (GLenum target, + GLenum internalformat, + GLint x, + GLint y, + GLsizei width, + GLsizei height) +{ + xglGLOpRec gl; + + gl.glProc = xglCopyConvolutionFilter2DProc; + + gl.u.copy_convolution_filter_2d.target = target; + gl.u.copy_convolution_filter_2d.internalformat = internalformat; + gl.u.copy_convolution_filter_2d.x = x; + gl.u.copy_convolution_filter_2d.y = y; + gl.u.copy_convolution_filter_2d.width = width; + gl.u.copy_convolution_filter_2d.height = height; + + xglGLOp (&gl); +} + +static void +xglCopyTexSubImage3DProc (xglGLOpPtr pOp) +{ + glCopyTexSubImage3D (pOp->u.copy_tex_sub_image_3d.target, + pOp->u.copy_tex_sub_image_3d.level, + pOp->u.copy_tex_sub_image_3d.xoffset, + pOp->u.copy_tex_sub_image_3d.yoffset, + pOp->u.copy_tex_sub_image_3d.zoffset, + pOp->u.copy_tex_sub_image_3d.x + + cctx->pReadBuffer->xOff, + pOp->u.copy_tex_sub_image_3d.y + + cctx->pReadBuffer->yOff, + pOp->u.copy_tex_sub_image_3d.width, + pOp->u.copy_tex_sub_image_3d.height); +} + +static void +xglCopyTexSubImage3D (GLenum target, + GLint level, + GLint xoffset, + GLint yoffset, + GLint zoffset, + GLint x, + GLint y, + GLsizei width, + GLsizei height) +{ + xglGLOpRec gl; + + gl.glProc = xglCopyTexSubImage3DProc; + + gl.u.copy_tex_sub_image_3d.target = target; + gl.u.copy_tex_sub_image_3d.level = level; + gl.u.copy_tex_sub_image_3d.xoffset = xoffset; + gl.u.copy_tex_sub_image_3d.yoffset = yoffset; + gl.u.copy_tex_sub_image_3d.zoffset = zoffset; + gl.u.copy_tex_sub_image_3d.x = x; + gl.u.copy_tex_sub_image_3d.y = y; + gl.u.copy_tex_sub_image_3d.width = width; + gl.u.copy_tex_sub_image_3d.height = height; + + xglGLOp (&gl); +} + +__glProcTable __glNativeRenderTable = { + xglNewList, /* glNewList */ + xglEndList, /* glEndList */ + xglCallList, /* glCallList */ + xglCallLists, /* glCallLists */ + xglDeleteLists, /* glDeleteLists */ + xglGenLists, /* glGenLists */ + glListBase, + xglBegin, /* glBegin */ + xglBitmap, /* glBitmap */ + glColor3bv, + glColor3dv, + glColor3fv, + glColor3iv, + glColor3sv, + glColor3ubv, + glColor3uiv, + glColor3usv, + glColor4bv, + glColor4dv, + glColor4fv, + glColor4iv, + glColor4sv, + glColor4ubv, + glColor4uiv, + glColor4usv, + glEdgeFlagv, + xglEnd, /* glEnd */ + glIndexdv, + glIndexfv, + glIndexiv, + glIndexsv, + glNormal3bv, + glNormal3dv, + glNormal3fv, + glNormal3iv, + glNormal3sv, + glRasterPos2dv, + glRasterPos2fv, + glRasterPos2iv, + glRasterPos2sv, + glRasterPos3dv, + glRasterPos3fv, + glRasterPos3iv, + glRasterPos3sv, + glRasterPos4dv, + glRasterPos4fv, + glRasterPos4iv, + glRasterPos4sv, + xglRectdv, /* glRectdv */ + xglRectfv, /* glRectfv */ + xglRectiv, /* glRectiv */ + xglRectsv, /* glRectsv */ + glTexCoord1dv, + glTexCoord1fv, + glTexCoord1iv, + glTexCoord1sv, + glTexCoord2dv, + glTexCoord2fv, + glTexCoord2iv, + glTexCoord2sv, + glTexCoord3dv, + glTexCoord3fv, + glTexCoord3iv, + glTexCoord3sv, + glTexCoord4dv, + glTexCoord4fv, + glTexCoord4iv, + glTexCoord4sv, + glVertex2dv, + glVertex2fv, + glVertex2iv, + glVertex2sv, + glVertex3dv, + glVertex3fv, + glVertex3iv, + glVertex3sv, + glVertex4dv, + glVertex4fv, + glVertex4iv, + glVertex4sv, + glClipPlane, + glColorMaterial, + glCullFace, + glFogf, + glFogfv, + glFogi, + glFogiv, + glFrontFace, + glHint, + glLightf, + glLightfv, + glLighti, + glLightiv, + glLightModelf, + glLightModelfv, + glLightModeli, + glLightModeliv, + glLineStipple, + glLineWidth, + glMaterialf, + glMaterialfv, + glMateriali, + glMaterialiv, + glPointSize, + glPolygonMode, + glPolygonStipple, + xglScissor, /* glScissor */ + glShadeModel, + xglTexParameterf, /* glTexParameterf */ + xglTexParameterfv, /* glTexParameterfv */ + xglTexParameteri, /* glTexParameteri */ + xglTexParameteriv, /* glTexParameteriv */ + glTexImage1D, + glTexImage2D, + glTexEnvf, + glTexEnvfv, + glTexEnvi, + glTexEnviv, + glTexGend, + glTexGendv, + glTexGenf, + glTexGenfv, + glTexGeni, + glTexGeniv, + glFeedbackBuffer, + glSelectBuffer, + glRenderMode, + glInitNames, + glLoadName, + glPassThrough, + glPopName, + glPushName, + xglDrawBuffer, /* glDrawBuffer */ + xglClear, /* glClear */ + glClearAccum, + glClearIndex, + glClearColor, + glClearStencil, + glClearDepth, + glStencilMask, + glColorMask, + glDepthMask, + glIndexMask, + xglAccum, /* glAccum */ + xglDisable, /* glDisable */ + xglEnable, /* glEnable */ + xglFinish, /* glFinish */ + xglFlush, /* glFlush */ + xglPopAttrib, /* glPopAttrib */ + xglPushAttrib, /* glPushAttrib */ + glMap1d, + glMap1f, + glMap2d, + glMap2f, + glMapGrid1d, + glMapGrid1f, + glMapGrid2d, + glMapGrid2f, + glEvalCoord1dv, + glEvalCoord1fv, + glEvalCoord2dv, + glEvalCoord2fv, + glEvalMesh1, + glEvalPoint1, + glEvalMesh2, + glEvalPoint2, + glAlphaFunc, + glBlendFunc, + glLogicOp, + glStencilFunc, + glStencilOp, + glDepthFunc, + glPixelZoom, + glPixelTransferf, + glPixelTransferi, + glPixelStoref, + glPixelStorei, + glPixelMapfv, + glPixelMapuiv, + glPixelMapusv, + xglReadBuffer, /* glReadBuffer */ + xglCopyPixels, /* glCopyPixels */ + xglReadPixels, /* glReadPixels */ + xglDrawPixels, /* glDrawPixels */ + xglGetBooleanv, /* glGetBooleanv */ + glGetClipPlane, + xglGetDoublev, /* glGetDoublev */ + xglGetError, /* glGetError */ + xglGetFloatv, /* glGetFloatv */ + xglGetIntegerv, /* glGetIntegerv */ + glGetLightfv, + glGetLightiv, + glGetMapdv, + glGetMapfv, + glGetMapiv, + glGetMaterialfv, + glGetMaterialiv, + glGetPixelMapfv, + glGetPixelMapuiv, + glGetPixelMapusv, + glGetPolygonStipple, + xglGetString, /* glGetString */ + glGetTexEnvfv, + glGetTexEnviv, + glGetTexGendv, + glGetTexGenfv, + glGetTexGeniv, + glGetTexImage, + glGetTexParameterfv, + glGetTexParameteriv, + xglGetTexLevelParameterfv, /* glGetTexLevelParameterfv */ + xglGetTexLevelParameteriv, /* glGetTexLevelParameteriv */ + xglIsEnabled, /* glIsEnabled */ + xglIsList, /* glIsList */ + glDepthRange, + glFrustum, + glLoadIdentity, + glLoadMatrixf, + glLoadMatrixd, + glMatrixMode, + glMultMatrixf, + glMultMatrixd, + glOrtho, + glPopMatrix, + glPushMatrix, + glRotated, + glRotatef, + glScaled, + glScalef, + glTranslated, + glTranslatef, + xglViewport, /* glViewport */ + glArrayElement, + xglBindTexture, /* glBindTexture */ + glColorPointer, + glDisableClientState, + xglDrawArrays, /* glDrawArrays */ + xglDrawElements, /* glDrawElements */ + glEdgeFlagPointer, + glEnableClientState, + glIndexPointer, + glIndexubv, + glInterleavedArrays, + glNormalPointer, + glPolygonOffset, + glTexCoordPointer, + glVertexPointer, + xglAreTexturesResident, /* glAreTexturesResident */ + xglCopyTexImage1D, /* glCopyTexImage1D */ + xglCopyTexImage2D, /* glCopyTexImage2D */ + xglCopyTexSubImage1D, /* glCopyTexSubImage1D */ + xglCopyTexSubImage2D, /* glCopyTexSubImage2D */ + xglDeleteTextures, /* glDeleteTextures */ + xglGenTextures, /* glGenTextures */ + glGetPointerv, + xglIsTexture, /* glIsTexture */ + xglPrioritizeTextures, /* glPrioritizeTextures */ + glTexSubImage1D, + glTexSubImage2D, + glPopClientAttrib, + glPushClientAttrib, + glBlendColor, + glBlendEquation, + glColorTable, + glColorTableParameterfv, + glColorTableParameteriv, + xglCopyColorTable, /* glCopyColorTable */ + glGetColorTable, + glGetColorTableParameterfv, + glGetColorTableParameteriv, + glColorSubTable, + xglCopyColorSubTable, /* glCopyColorSubTable */ + glConvolutionFilter1D, + glConvolutionFilter2D, + glConvolutionParameterf, + glConvolutionParameterfv, + glConvolutionParameteri, + glConvolutionParameteriv, + xglCopyConvolutionFilter1D, /* glCopyConvolutionFilter1D */ + xglCopyConvolutionFilter2D, /* glCopyConvolutionFilter2D */ + glGetConvolutionFilter, + glGetConvolutionParameterfv, + glGetConvolutionParameteriv, + glGetSeparableFilter, + glSeparableFilter2D, + glGetHistogram, + glGetHistogramParameterfv, + glGetHistogramParameteriv, + glGetMinmax, + glGetMinmaxParameterfv, + glGetMinmaxParameteriv, + glHistogram, + glMinmax, + glResetHistogram, + glResetMinmax, + glTexImage3D, + glTexSubImage3D, + xglCopyTexSubImage3D /* glCopyTexSubImage3D */ +}; + +/* GL_ARB_multitexture */ +static void +xglNoOpActiveTextureARB (GLenum texture) {} +static void +xglActiveTextureARBProc (xglGLOpPtr pOp) +{ + GLenum texUnit; + + texUnit = pOp->u.enumeration - GL_TEXTURE0; + if (texUnit < 0 || texUnit >= cctx->maxTexUnits) + { + xglRecordError (GL_INVALID_ENUM); + } + else + { + cctx->activeTexUnit = texUnit; + (*cctx->ActiveTextureARB) (pOp->u.enumeration); + } +} +static void +xglActiveTextureARB (GLenum texture) +{ + xglGLOpRec gl; + + gl.glProc = xglActiveTextureARBProc; + + gl.u.enumeration = texture; + + xglGLOp (&gl); +} +static void +xglNoOpClientActiveTextureARB (GLenum texture) {} +static void +xglNoOpMultiTexCoord1dvARB (GLenum target, const GLdouble *v) {} +static void +xglNoOpMultiTexCoord1fvARB (GLenum target, const GLfloat *v) {} +static void +xglNoOpMultiTexCoord1ivARB (GLenum target, const GLint *v) {} +static void +xglNoOpMultiTexCoord1svARB (GLenum target, const GLshort *v) {} +static void +xglNoOpMultiTexCoord2dvARB (GLenum target, const GLdouble *v) {} +static void +xglNoOpMultiTexCoord2fvARB (GLenum target, const GLfloat *v) {} +static void +xglNoOpMultiTexCoord2ivARB (GLenum target, const GLint *v) {} +static void +xglNoOpMultiTexCoord2svARB (GLenum target, const GLshort *v) {} +static void +xglNoOpMultiTexCoord3dvARB (GLenum target, const GLdouble *v) {} +static void +xglNoOpMultiTexCoord3fvARB (GLenum target, const GLfloat *v) {} +static void +xglNoOpMultiTexCoord3ivARB (GLenum target, const GLint *v) {} +static void +xglNoOpMultiTexCoord3svARB (GLenum target, const GLshort *v) {} +static void +xglNoOpMultiTexCoord4dvARB (GLenum target, const GLdouble *v) {} +static void +xglNoOpMultiTexCoord4fvARB (GLenum target, const GLfloat *v) {} +static void +xglNoOpMultiTexCoord4ivARB (GLenum target, const GLint *v) {} +static void +xglNoOpMultiTexCoord4svARB (GLenum target, const GLshort *v) {} + +/* GL_ARB_multisample */ +static void +xglNoOpSampleCoverageARB (GLclampf value, GLboolean invert) {} + +/* GL_EXT_texture_object */ +static GLboolean +xglNoOpAreTexturesResidentEXT (GLsizei n, + const GLuint *textures, + GLboolean *residences) +{ + return GL_FALSE; +} +static void +xglNoOpGenTexturesEXT (GLsizei n, GLuint *textures) {} +static GLboolean +xglNoOpIsTextureEXT (GLuint texture) +{ + return GL_FALSE; +} + +/* GL_SGIS_multisample */ +static void +xglNoOpSampleMaskSGIS (GLclampf value, GLboolean invert) {} +static void +xglNoOpSamplePatternSGIS (GLenum pattern) {} + +/* GL_EXT_point_parameters */ +static void +xglNoOpPointParameterfEXT (GLenum pname, GLfloat param) {} +static void +xglNoOpPointParameterfvEXT (GLenum pname, const GLfloat *params) {} + +/* GL_MESA_window_pos */ +static void +xglNoOpWindowPos3fMESA (GLfloat x, GLfloat y, GLfloat z) {} +static void +xglWindowPos3fMESAProc (xglGLOpPtr pOp) +{ + (*cctx->WindowPos3fMESA) (pOp->u.window_pos_3f.x + cctx->pDrawBuffer->xOff, + pOp->u.window_pos_3f.y + cctx->pDrawBuffer->yOff, + pOp->u.window_pos_3f.z); +} +static void +xglWindowPos3fMESA (GLfloat x, GLfloat y, GLfloat z) +{ + xglGLOpRec gl; + + gl.glProc = xglWindowPos3fMESAProc; + + gl.u.window_pos_3f.x = x; + gl.u.window_pos_3f.y = y; + gl.u.window_pos_3f.z = z; + + xglGLOp (&gl); +} + +/* GL_EXT_blend_func_separate */ +static void +xglNoOpBlendFuncSeparateEXT (GLenum sfactorRGB, GLenum dfactorRGB, + GLenum sfactorAlpha, GLenum dfactorAlpha) {} + +/* GL_EXT_fog_coord */ +static void +xglNoOpFogCoordfvEXT (const GLfloat *coord) {} +static void +xglNoOpFogCoorddvEXT (const GLdouble *coord) {} +static void +xglNoOpFogCoordPointerEXT (GLenum type, GLsizei stride, + const GLvoid *pointer) {} + +/* GL_EXT_secondary_color */ +static void +xglNoOpSecondaryColor3bvEXT (const GLbyte *v) {} +static void +xglNoOpSecondaryColor3dvEXT (const GLdouble *v) {} +static void +xglNoOpSecondaryColor3fvEXT (const GLfloat *v) {} +static void +xglNoOpSecondaryColor3ivEXT (const GLint *v) {} +static void +xglNoOpSecondaryColor3svEXT (const GLshort *v) {} +static void +xglNoOpSecondaryColor3ubvEXT (const GLubyte *v) {} +static void +xglNoOpSecondaryColor3uivEXT (const GLuint *v) {} +static void +xglNoOpSecondaryColor3usvEXT (const GLushort *v) {} +static void +xglNoOpSecondaryColorPointerEXT (GLint size, GLenum type, GLsizei stride, + const GLvoid *pointer) {} + +/* GL_NV_point_sprite */ +static void +xglNoOpPointParameteriNV (GLenum pname, GLint params) {} +static void +xglNoOpPointParameterivNV (GLenum pname, const GLint *params) {} + +/* GL_EXT_stencil_two_side */ +static void +xglNoOpActiveStencilFaceEXT (GLenum face) {} + +/* GL_EXT_framebuffer_object */ +static GLboolean +xglNoOpIsRenderbufferEXT (GLuint renderbuffer) +{ + return FALSE; +} +static void +xglNoOpBindRenderbufferEXT (GLenum target, GLuint renderbuffer) {} +static void +xglNoOpDeleteRenderbuffersEXT (GLsizei n, const GLuint *renderbuffers) {} +static void +xglNoOpGenRenderbuffersEXT (GLsizei n, GLuint *renderbuffers) {} +static void +xglNoOpRenderbufferStorageEXT (GLenum target, GLenum internalformat, + GLsizei width, GLsizei height) {} +static void +xglNoOpGetRenderbufferParameterivEXT (GLenum target, GLenum pname, + GLint *params) {} +static GLboolean +xglNoOpIsFramebufferEXT (GLuint framebuffer) +{ + return FALSE; +} +static void +xglNoOpBindFramebufferEXT (GLenum target, GLuint framebuffer) {} +static void +xglNoOpDeleteFramebuffersEXT (GLsizei n, const GLuint *framebuffers) {} +static void +xglNoOpGenFramebuffersEXT (GLsizei n, GLuint *framebuffers) {} +static GLenum +xglNoOpCheckFramebufferStatusEXT (GLenum target) +{ + return GL_FRAMEBUFFER_UNSUPPORTED_EXT; +} +static void +xglNoOpFramebufferTexture1DEXT (GLenum target, GLenum attachment, + GLenum textarget, GLuint texture, + GLint level) {} +static void +xglNoOpFramebufferTexture2DEXT (GLenum target, GLenum attachment, + GLenum textarget, GLuint texture, + GLint level) {} +static void +xglNoOpFramebufferTexture3DEXT (GLenum target, GLenum attachment, + GLenum textarget, GLuint texture, + GLint level, GLint zoffset) {} +static void +xglNoOpFramebufferRenderbufferEXT (GLenum target, GLenum attachment, + GLenum renderbuffertarget, + GLuint renderbuffer) {} +static void +xglNoOpGetFramebufferAttachmentParameterivEXT (GLenum target, + GLenum attachment, + GLenum pname, + GLint *params) {} +static void +xglNoOpGenerateMipmapEXT (GLenum target) {} + + +__glProcTableEXT __glNoOpRenderTableEXT = { + xglNoOpActiveTextureARB, + xglNoOpClientActiveTextureARB, + xglNoOpMultiTexCoord1dvARB, + xglNoOpMultiTexCoord1fvARB, + xglNoOpMultiTexCoord1ivARB, + xglNoOpMultiTexCoord1svARB, + xglNoOpMultiTexCoord2dvARB, + xglNoOpMultiTexCoord2fvARB, + xglNoOpMultiTexCoord2ivARB, + xglNoOpMultiTexCoord2svARB, + xglNoOpMultiTexCoord3dvARB, + xglNoOpMultiTexCoord3fvARB, + xglNoOpMultiTexCoord3ivARB, + xglNoOpMultiTexCoord3svARB, + xglNoOpMultiTexCoord4dvARB, + xglNoOpMultiTexCoord4fvARB, + xglNoOpMultiTexCoord4ivARB, + xglNoOpMultiTexCoord4svARB, + xglNoOpSampleCoverageARB, + xglNoOpAreTexturesResidentEXT, + xglNoOpGenTexturesEXT, + xglNoOpIsTextureEXT, + xglNoOpSampleMaskSGIS, + xglNoOpSamplePatternSGIS, + xglNoOpPointParameterfEXT, + xglNoOpPointParameterfvEXT, + xglNoOpWindowPos3fMESA, + xglNoOpBlendFuncSeparateEXT, + xglNoOpFogCoordfvEXT, + xglNoOpFogCoorddvEXT, + xglNoOpFogCoordPointerEXT, + xglNoOpSecondaryColor3bvEXT, + xglNoOpSecondaryColor3dvEXT, + xglNoOpSecondaryColor3fvEXT, + xglNoOpSecondaryColor3ivEXT, + xglNoOpSecondaryColor3svEXT, + xglNoOpSecondaryColor3ubvEXT, + xglNoOpSecondaryColor3uivEXT, + xglNoOpSecondaryColor3usvEXT, + xglNoOpSecondaryColorPointerEXT, + xglNoOpPointParameteriNV, + xglNoOpPointParameterivNV, + xglNoOpActiveStencilFaceEXT, + xglNoOpIsRenderbufferEXT, + xglNoOpBindRenderbufferEXT, + xglNoOpDeleteRenderbuffersEXT, + xglNoOpGenRenderbuffersEXT, + xglNoOpRenderbufferStorageEXT, + xglNoOpGetRenderbufferParameterivEXT, + xglNoOpIsFramebufferEXT, + xglNoOpBindFramebufferEXT, + xglNoOpDeleteFramebuffersEXT, + xglNoOpGenFramebuffersEXT, + xglNoOpCheckFramebufferStatusEXT, + xglNoOpFramebufferTexture1DEXT, + xglNoOpFramebufferTexture2DEXT, + xglNoOpFramebufferTexture3DEXT, + xglNoOpFramebufferRenderbufferEXT, + xglNoOpGetFramebufferAttachmentParameterivEXT, + xglNoOpGenerateMipmapEXT +}; + +static void +xglInitExtensions (xglGLContextPtr pContext) +{ + const char *extensions; + + pContext->glRenderTableEXT = __glNoOpRenderTableEXT; + + extensions = (const char *) glGetString (GL_EXTENSIONS); + + if (strstr (extensions, "GL_ARB_multitexture")) + { + pContext->ActiveTextureARB = + (PFNGLACTIVETEXTUREARBPROC) + glitz_context_get_proc_address (pContext->context, + "glActiveTextureARB"); + pContext->glRenderTableEXT.ClientActiveTextureARB = + (PFNGLCLIENTACTIVETEXTUREARBPROC) + glitz_context_get_proc_address (pContext->context, + "glClientActiveTextureARB"); + pContext->glRenderTableEXT.MultiTexCoord1dvARB = + (PFNGLMULTITEXCOORD1DVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord1dvARB"); + pContext->glRenderTableEXT.MultiTexCoord1fvARB = + (PFNGLMULTITEXCOORD1FVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord1fvARB"); + pContext->glRenderTableEXT.MultiTexCoord1ivARB = + (PFNGLMULTITEXCOORD1IVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord1ivARB"); + pContext->glRenderTableEXT.MultiTexCoord1svARB = + (PFNGLMULTITEXCOORD1SVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord1svARB"); + pContext->glRenderTableEXT.MultiTexCoord2dvARB = + (PFNGLMULTITEXCOORD2DVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord2dvARB"); + pContext->glRenderTableEXT.MultiTexCoord2fvARB = + (PFNGLMULTITEXCOORD2FVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord2fvARB"); + pContext->glRenderTableEXT.MultiTexCoord2ivARB = + (PFNGLMULTITEXCOORD2IVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord2ivARB"); + pContext->glRenderTableEXT.MultiTexCoord2svARB = + (PFNGLMULTITEXCOORD2SVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord2svARB"); + pContext->glRenderTableEXT.MultiTexCoord3dvARB = + (PFNGLMULTITEXCOORD3DVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord3dvARB"); + pContext->glRenderTableEXT.MultiTexCoord3fvARB = + (PFNGLMULTITEXCOORD3FVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord3fvARB"); + pContext->glRenderTableEXT.MultiTexCoord3ivARB = + (PFNGLMULTITEXCOORD3IVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord3ivARB"); + pContext->glRenderTableEXT.MultiTexCoord3svARB = + (PFNGLMULTITEXCOORD3SVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord3svARB"); + pContext->glRenderTableEXT.MultiTexCoord4dvARB = + (PFNGLMULTITEXCOORD4DVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord4dvARB"); + pContext->glRenderTableEXT.MultiTexCoord4fvARB = + (PFNGLMULTITEXCOORD4FVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord4fvARB"); + pContext->glRenderTableEXT.MultiTexCoord4ivARB = + (PFNGLMULTITEXCOORD4IVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord4ivARB"); + pContext->glRenderTableEXT.MultiTexCoord4svARB = + (PFNGLMULTITEXCOORD4SVARBPROC) + glitz_context_get_proc_address (pContext->context, + "glMultiTexCoord4svARB"); + + glGetIntegerv (GL_MAX_LIST_NESTING, &pContext->maxListNesting); + glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &pContext->maxTexUnits); + if (pContext->maxTexUnits > XGL_MAX_TEXTURE_UNITS) + pContext->maxTexUnits = XGL_MAX_TEXTURE_UNITS; + + pContext->glRenderTableEXT.ActiveTextureARB = xglActiveTextureARB; + } + else + pContext->maxTexUnits = 1; + + if (strstr (extensions, "GL_ARB_multisample")) + { + pContext->glRenderTableEXT.SampleCoverageARB = + (PFNGLSAMPLECOVERAGEARBPROC) + glitz_context_get_proc_address (pContext->context, + "glSampleCoverageARB"); + } + + if (strstr (extensions, "GL_EXT_texture_object")) + { + pContext->glRenderTableEXT.AreTexturesResidentEXT = + xglAreTexturesResident; + pContext->glRenderTableEXT.GenTexturesEXT = xglGenTextures; + pContext->glRenderTableEXT.IsTextureEXT = xglIsTexture; + } + + if (strstr (extensions, "GL_SGIS_multisample")) + { + pContext->glRenderTableEXT.SampleMaskSGIS = + (PFNGLSAMPLEMASKSGISPROC) + glitz_context_get_proc_address (pContext->context, + "glSampleMaskSGIS"); + pContext->glRenderTableEXT.SamplePatternSGIS = + (PFNGLSAMPLEPATTERNSGISPROC) + glitz_context_get_proc_address (pContext->context, + "glSamplePatternSGIS"); + } + + if (strstr (extensions, "GL_EXT_point_parameters")) + { + pContext->glRenderTableEXT.PointParameterfEXT = + (PFNGLPOINTPARAMETERFEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glPointParameterfEXT"); + pContext->glRenderTableEXT.PointParameterfvEXT = + (PFNGLPOINTPARAMETERFVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glPointParameterfvEXT"); + } + + if (strstr (extensions, "GL_MESA_window_pos")) + { + pContext->WindowPos3fMESA = + (PFNGLWINDOWPOS3FMESAPROC) + glitz_context_get_proc_address (pContext->context, + "glWindowPos3fMESA"); + pContext->glRenderTableEXT.WindowPos3fMESA = xglWindowPos3fMESA; + } + + if (strstr (extensions, "GL_EXT_blend_func_separate")) + { + pContext->glRenderTableEXT.BlendFuncSeparateEXT = + (PFNGLBLENDFUNCSEPARATEEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glBlendFuncSeparateEXT"); + } + + if (strstr (extensions, "GL_EXT_fog_coord")) + { + pContext->glRenderTableEXT.FogCoordfvEXT = + (PFNGLFOGCOORDFVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glFogCoordfvEXT"); + pContext->glRenderTableEXT.FogCoorddvEXT = + (PFNGLFOGCOORDDVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glFogCoorddvEXT"); + pContext->glRenderTableEXT.FogCoordPointerEXT = + (PFNGLFOGCOORDPOINTEREXTPROC) + glitz_context_get_proc_address (pContext->context, + "glFogCoordPointerEXT"); + } + + if (strstr (extensions, "GL_EXT_secondary_color")) + { + pContext->glRenderTableEXT.SecondaryColor3bvEXT = + (PFNGLSECONDARYCOLOR3BVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glSecondaryColor3bvEXT"); + pContext->glRenderTableEXT.SecondaryColor3dvEXT = + (PFNGLSECONDARYCOLOR3DVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glSecondaryColor3dvEXT"); + pContext->glRenderTableEXT.SecondaryColor3fvEXT = + (PFNGLSECONDARYCOLOR3FVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glSecondaryColor3fvEXT"); + pContext->glRenderTableEXT.SecondaryColor3ivEXT = + (PFNGLSECONDARYCOLOR3IVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glSecondaryColor3ivEXT"); + pContext->glRenderTableEXT.SecondaryColor3svEXT = + (PFNGLSECONDARYCOLOR3SVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glSecondaryColor3svEXT"); + pContext->glRenderTableEXT.SecondaryColor3ubvEXT = + (PFNGLSECONDARYCOLOR3UBVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glSecondaryColor3ubvEXT"); + pContext->glRenderTableEXT.SecondaryColor3uivEXT = + (PFNGLSECONDARYCOLOR3UIVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glSecondaryColor3uivEXT"); + pContext->glRenderTableEXT.SecondaryColor3usvEXT = + (PFNGLSECONDARYCOLOR3USVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glSecondaryColor3usvEXT"); + pContext->glRenderTableEXT.SecondaryColorPointerEXT = + (PFNGLSECONDARYCOLORPOINTEREXTPROC) + glitz_context_get_proc_address (pContext->context, + "glSecondaryColorPointerEXT"); + } + + if (strstr (extensions, "GL_NV_point_sprite")) + { + pContext->glRenderTableEXT.PointParameteriNV = + (PFNGLPOINTPARAMETERINVPROC) + glitz_context_get_proc_address (pContext->context, + "glPointParameteriNV"); + pContext->glRenderTableEXT.PointParameterivNV = + (PFNGLPOINTPARAMETERIVNVPROC) + glitz_context_get_proc_address (pContext->context, + "glPointParameterivNV"); + } + + if (strstr (extensions, "GL_EXT_stencil_two_side")) + { + pContext->glRenderTableEXT.ActiveStencilFaceEXT = + (PFNGLACTIVESTENCILFACEEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glActiveStencilFaceEXT"); + } + + if (strstr (extensions, "GL_EXT_framebuffer_object")) + { + pContext->glRenderTableEXT.IsRenderbufferEXT = + (PFNGLISRENDERBUFFEREXTPROC) + glitz_context_get_proc_address (pContext->context, + "glIsRenderbufferEXT"); + pContext->glRenderTableEXT.BindRenderbufferEXT = + (PFNGLBINDRENDERBUFFEREXTPROC) + glitz_context_get_proc_address (pContext->context, + "glBindRenderbufferEXT"); + pContext->glRenderTableEXT.DeleteRenderbuffersEXT = + (PFNGLDELETERENDERBUFFERSEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glDeleteRenderbuffersEXT"); + pContext->glRenderTableEXT.GenRenderbuffersEXT = + (PFNGLGENRENDERBUFFERSEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glGenRenderbuffersEXT"); + pContext->glRenderTableEXT.RenderbufferStorageEXT = + (PFNGLRENDERBUFFERSTORAGEEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glRenderbufferStorageEXT"); + pContext->glRenderTableEXT.GetRenderbufferParameterivEXT = + (PFNGLGETRENDERBUFFERPARAMETERIVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glGetRenderbufferParameterivEXT"); + pContext->glRenderTableEXT.IsFramebufferEXT = + (PFNGLISFRAMEBUFFEREXTPROC) + glitz_context_get_proc_address (pContext->context, + "glIsFramebufferEXT"); + pContext->glRenderTableEXT.BindFramebufferEXT = + (PFNGLBINDFRAMEBUFFEREXTPROC) + glitz_context_get_proc_address (pContext->context, + "glBindFramebufferEXT"); + pContext->glRenderTableEXT.DeleteFramebuffersEXT = + (PFNGLDELETEFRAMEBUFFERSEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glDeleteFramebuffersEXT"); + pContext->glRenderTableEXT.GenFramebuffersEXT = + (PFNGLGENFRAMEBUFFERSEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glGenFramebuffersEXT"); + pContext->glRenderTableEXT.CheckFramebufferStatusEXT = + (PFNGLCHECKFRAMEBUFFERSTATUSEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glCheckFramebufferStatusEXT"); + pContext->glRenderTableEXT.FramebufferTexture1DEXT = + (PFNGLFRAMEBUFFERTEXTURE1DEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glFramebufferTexture1DEXT"); + pContext->glRenderTableEXT.FramebufferTexture2DEXT = + (PFNGLFRAMEBUFFERTEXTURE2DEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glFramebufferTexture2DEXT"); + pContext->glRenderTableEXT.FramebufferTexture3DEXT = + (PFNGLFRAMEBUFFERTEXTURE3DEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glFramebufferTexture3DEXT"); + pContext->glRenderTableEXT.FramebufferRenderbufferEXT = + (PFNGLFRAMEBUFFERRENDERBUFFEREXTPROC) + glitz_context_get_proc_address (pContext->context, + "glFramebufferRenderbufferEXT"); + pContext->glRenderTableEXT.GetFramebufferAttachmentParameterivEXT = + (PFNGLGETFRAMEBUFFERATTACHMENTPARAMETERIVEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glGetFramebufferAttachment" + "ParameterivEXT"); + pContext->glRenderTableEXT.GenerateMipmapEXT = + (PFNGLGENERATEMIPMAPEXTPROC) + glitz_context_get_proc_address (pContext->context, + "glGenerateMipmapEXT"); + } +} + +static void +xglSetCurrentContext (xglGLContextPtr pContext) +{ + XGL_SCREEN_PRIV (pContext->pDrawBuffer->pGC->pScreen); + cctx = pContext; + + glitz_context_make_current (cctx->context, pScreenPriv->drawable); + + GlxSetRenderTables (&__glNativeRenderTable, &cctx->glRenderTableEXT); +} + +static void +xglFreeContext (xglGLContextPtr pContext) +{ + int i; + + pContext->refcnt--; + if (pContext->shared == pContext) + pContext->refcnt--; + + if (pContext->refcnt) + return; + + if (pContext->shared != pContext) + xglFreeContext (pContext->shared); + + if (pContext->texObjects) + { + xglTexObjPtr pTexObj; + GLuint key; + + do { + key = xglHashFirstEntry (pContext->texObjects); + if (key) + { + pTexObj = (xglTexObjPtr) xglHashLookup (pContext->texObjects, + key); + if (pTexObj) + xglUnrefTexObj (pTexObj); + + xglHashRemove (pContext->texObjects, key); + } + } while (key); + + xglDeleteHashTable (pContext->texObjects); + } + + if (pContext->displayLists) + { + xglDisplayListPtr pDisplayList; + GLuint key; + + do { + key = xglHashFirstEntry (pContext->displayLists); + if (key) + { + pDisplayList = (xglDisplayListPtr) + xglHashLookup (pContext->displayLists, key); + if (pDisplayList) + xglDestroyList (pDisplayList); + + xglHashRemove (pContext->displayLists, key); + } + } while (key); + + xglDeleteHashTable (pContext->displayLists); + } + + for (i = 0; i < pContext->maxTexUnits; i++) + { + xglUnrefTexObj (pContext->attrib.texUnits[i].p1D); + xglUnrefTexObj (pContext->attrib.texUnits[i].p2D); + xglUnrefTexObj (pContext->attrib.texUnits[i].p3D); + xglUnrefTexObj (pContext->attrib.texUnits[i].pRect); + xglUnrefTexObj (pContext->attrib.texUnits[i].pCubeMap); + } + + if (pContext->groupList) + glDeleteLists (pContext->groupList, 1); + + if (pContext->pAttribStack) + xfree (pContext->pAttribStack); + + if (pContext->context) + glitz_context_destroy (pContext->context); + + if (pContext->versionString) + xfree (pContext->versionString); + + xfree (pContext); +} + +static GLboolean +xglDestroyContext (__GLcontext *gc) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + __GLinterface *iface = pContext->mIface; + + xglFreeContext (pContext); + + if (!iface) + return GL_TRUE; + + return (*iface->exports.destroyContext) ((__GLcontext *) iface); +} + +static GLboolean +xglLoseCurrent (__GLcontext *gc) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + __GLinterface *iface = pContext->mIface; + + GlxFlushContextCache (); + + if (!iface) + return GL_TRUE; + + return (*iface->exports.loseCurrent) ((__GLcontext *) iface); +} + +static GLboolean +xglMakeCurrent (__GLcontext *gc) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + __GLinterface *iface = &pContext->iface; + __GLinterface *mIface = pContext->mIface; + __GLdrawablePrivate *drawPriv = iface->imports.getDrawablePrivate (gc); + __GLdrawablePrivate *readPriv = iface->imports.getReadablePrivate (gc); + xglGLBufferPtr pDrawBufferPriv = drawPriv->private; + xglGLBufferPtr pReadBufferPriv = readPriv->private; + GLboolean status = GL_TRUE; + + if (pReadBufferPriv->pDrawable && pDrawBufferPriv->pDrawable) + { + XID values[2] = { ClipByChildren, 0 }; + int status; + +#ifdef COMPOSITE + /* XXX: temporary hack for root window drawing using + IncludeInferiors */ + if (pDrawBufferPriv->pDrawable->type == DRAWABLE_WINDOW && + (!((WindowPtr) (pDrawBufferPriv->pDrawable))->parent)) + values[0] = IncludeInferiors; +#endif + + /* this happens if client previously used this context with a buffer + not supported by the native GL stack */ + if (!pContext->context) + return GL_FALSE; + + /* XXX: GLX_SGI_make_current_read disabled for now */ + if (pDrawBufferPriv != pReadBufferPriv) + return GL_FALSE; + + pContext->pReadBuffer = pReadBufferPriv; + pContext->pDrawBuffer = pDrawBufferPriv; + + if (!pReadBufferPriv->pGC) + pReadBufferPriv->pGC = + CreateGC (pReadBufferPriv->pDrawable, + GCSubwindowMode | GCGraphicsExposures, values, + &status); + + ValidateGC (pReadBufferPriv->pDrawable, pReadBufferPriv->pGC); + + if (!pDrawBufferPriv->pGC) + pDrawBufferPriv->pGC = + CreateGC (pDrawBufferPriv->pDrawable, + GCSubwindowMode | GCGraphicsExposures, values, + &status); + + ValidateGC (pDrawBufferPriv->pDrawable, pDrawBufferPriv->pGC); + + pContext->pReadBuffer = pReadBufferPriv; + pContext->pDrawBuffer = pDrawBufferPriv; + + pReadBufferPriv->pPixmap = (PixmapPtr) 0; + pDrawBufferPriv->pPixmap = (PixmapPtr) 0; + + /* from now on this context can only be used with native GL stack */ + if (mIface) + { + (*mIface->exports.destroyContext) ((__GLcontext *) mIface); + pContext->mIface = NULL; + } + } + else + { + /* this happens if client previously used this context with a buffer + supported by the native GL stack */ + if (!mIface) + return GL_FALSE; + + drawPriv->private = pDrawBufferPriv->private; + readPriv->private = pReadBufferPriv->private; + + status = (*mIface->exports.makeCurrent) ((__GLcontext *) mIface); + + drawPriv->private = pDrawBufferPriv; + readPriv->private = pReadBufferPriv; + + /* from now on this context can not be used with native GL stack */ + if (status == GL_TRUE && pContext->context) + { + glitz_context_destroy (pContext->context); + pContext->context = NULL; + } + } + + return status; +} + +static GLboolean +xglShareContext (__GLcontext *gc, + __GLcontext *gcShare) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + xglGLContextPtr pContextShare = (xglGLContextPtr) gcShare; + __GLinterface *iface = pContext->mIface; + __GLinterface *ifaceShare = pContextShare->mIface; + + if (!iface || !ifaceShare) + return GL_TRUE; + + return (*iface->exports.shareContext) ((__GLcontext *) iface, + (__GLcontext *) ifaceShare); +} + +static GLboolean +xglCopyContext (__GLcontext *dst, + const __GLcontext *src, + GLuint mask) +{ + xglGLContextPtr pDst = (xglGLContextPtr) dst; + xglGLContextPtr pSrc = (xglGLContextPtr) src; + const __GLcontext *srcCtx = (const __GLcontext *) pSrc->mIface; + __GLinterface *dstIface = (__GLinterface *) pDst->mIface; + GLboolean status = GL_TRUE; + + if (pSrc->context && pDst->context) + glitz_context_copy (pSrc->context, pDst->context, mask); + else + status = GL_FALSE; + + if (dstIface && srcCtx) + status = (*dstIface->exports.copyContext) ((__GLcontext *) dstIface, + srcCtx, + mask); + + return status; +} + +static Bool +xglResizeBuffer (__GLdrawablePrivate *glPriv, + int x, + int y, + unsigned int width, + unsigned int height) +{ + xglGLBufferPtr pBufferPriv = glPriv->private; + DrawablePtr pDrawable = pBufferPriv->pDrawable; + + XGL_SCREEN_PRIV (pDrawable->pScreen); + XGL_DRAWABLE_PIXMAP (pBufferPriv->pDrawable); + + if (pPixmap != pScreenPriv->pScreenPixmap) + { + if (glPriv->modes->doubleBufferMode) + { + glitz_surface_t *surface = pBufferPriv->backSurface; + + if (!surface || + (glitz_surface_get_width (surface) != width || + glitz_surface_get_height (surface) != height)) + { + glitz_format_t *format; + + format = pScreenPriv->pixmapFormats[pDrawable->depth].format; + + if (surface) + glitz_surface_destroy (surface); + + pBufferPriv->backSurface = + glitz_surface_create (pScreenPriv->drawable, format, + width, height, 0, NULL); + if (!pBufferPriv->backSurface) + return FALSE; + } + } + } + else + { + if (glPriv->modes->doubleBufferMode) + { + if (!pBufferPriv->backSurface) + { + pBufferPriv->backSurface = pScreenPriv->backSurface; + glitz_surface_reference (pScreenPriv->backSurface); + } + } + } + + ValidateGC (pDrawable, pBufferPriv->pGC); + + return TRUE; +} + + +static GLboolean +xglForceCurrent (__GLcontext *gc) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + __GLinterface *iface = pContext->mIface; + GLboolean status = GL_TRUE; + + if (pContext->context) + { + cctx = pContext; + + if (cctx->pReadBuffer->pDrawable && cctx->pDrawBuffer->pDrawable) + { + DrawablePtr pDrawable; + PixmapPtr pReadPixmap, pDrawPixmap; + + pDrawable = cctx->pReadBuffer->pDrawable; + if (pDrawable->type != DRAWABLE_PIXMAP) + { + pReadPixmap = XGL_GET_WINDOW_PIXMAP (pDrawable); + cctx->pReadBuffer->xOff = pDrawable->x + + __XGL_OFF_X_WIN (pReadPixmap); + cctx->pReadBuffer->yOff = pReadPixmap->drawable.height - + ((pDrawable->y + __XGL_OFF_Y_WIN (pReadPixmap)) + + pDrawable->height); + cctx->pReadBuffer->yFlip = pReadPixmap->drawable.height; + } + else + { + pReadPixmap = (PixmapPtr) pDrawable; + cctx->pReadBuffer->xOff = cctx->pReadBuffer->yOff = 0; + cctx->pReadBuffer->yFlip = pDrawable->height; + } + + pDrawable = cctx->pDrawBuffer->pDrawable; + if (pDrawable->type != DRAWABLE_PIXMAP) + { + pDrawPixmap = XGL_GET_WINDOW_PIXMAP (pDrawable); + cctx->pDrawBuffer->xOff = pDrawable->x + + __XGL_OFF_X_WIN (pDrawPixmap); + cctx->pDrawBuffer->yOff = pDrawPixmap->drawable.height - + ((pDrawable->y + __XGL_OFF_Y_WIN (pDrawPixmap)) + + pDrawable->height); + cctx->pDrawBuffer->yFlip = pDrawPixmap->drawable.height; + } + else + { + pDrawPixmap = (PixmapPtr) pDrawable; + cctx->pDrawBuffer->xOff = cctx->pDrawBuffer->yOff = 0; + cctx->pDrawBuffer->yFlip = pDrawable->height; + } + + /* draw buffer changed */ + if (cctx->pDrawBuffer->pPixmap != pDrawPixmap || + cctx->pReadBuffer->pPixmap != pReadPixmap) + { + __GLinterface *iface = &pContext->iface; + __GLdrawablePrivate *drawPriv, *readPriv; + + if (!xglPrepareTarget (pDrawable)) + return FALSE; + + drawPriv = iface->imports.getDrawablePrivate (gc); + readPriv = iface->imports.getReadablePrivate (gc); + + if (!xglResizeBuffer (drawPriv, + pDrawable->x, + pDrawable->y, + pDrawable->width, + pDrawable->height)) + return FALSE; + + if (!xglResizeBuffer (readPriv, + cctx->pReadBuffer->pDrawable->x, + cctx->pReadBuffer->pDrawable->y, + cctx->pReadBuffer->pDrawable->width, + cctx->pReadBuffer->pDrawable->height)) + return FALSE; + + cctx->pReadBuffer->pPixmap = pReadPixmap; + cctx->pDrawBuffer->pPixmap = pDrawPixmap; + } + } + + xglSetCurrentContext (pContext);//, cctx->pDrawBuffer); + + if (cctx->needInit) + { + int i; + + xglInitExtensions (cctx); + + cctx->attrib.scissorTest = GL_FALSE; + cctx->attrib.scissor.x = cctx->attrib.scissor.y = 0; + cctx->attrib.scissor.width = cctx->pDrawBuffer->pDrawable->width; + cctx->attrib.scissor.height = cctx->pDrawBuffer->pDrawable->height; + cctx->attrib.viewport = cctx->attrib.scissor; + + cctx->activeTexUnit = 0; + + for (i = 0; i < cctx->maxTexUnits; i++) + { + cctx->attrib.texUnits[i].enabled = 0; + + cctx->attrib.texUnits[i].p1D = NULL; + cctx->attrib.texUnits[i].p2D = NULL; + cctx->attrib.texUnits[i].p3D = NULL; + cctx->attrib.texUnits[i].pRect = NULL; + cctx->attrib.texUnits[i].pCubeMap = NULL; + } + + glEnable (GL_SCISSOR_TEST); + + cctx->needInit = FALSE; + } + + /* update viewport and raster position */ + if (cctx->pDrawBuffer->xOff != cctx->drawXoff || + cctx->pDrawBuffer->yOff != cctx->drawYoff) + { + glViewport (cctx->attrib.scissor.x + cctx->pDrawBuffer->xOff, + cctx->attrib.scissor.y + cctx->pDrawBuffer->yOff, + cctx->attrib.scissor.width, + cctx->attrib.scissor.height); + + glBitmap (0, 0, 0, 0, + cctx->pDrawBuffer->xOff - cctx->drawXoff, + cctx->pDrawBuffer->yOff - cctx->drawYoff, + NULL); + + cctx->drawXoff = cctx->pDrawBuffer->xOff; + cctx->drawYoff = cctx->pDrawBuffer->yOff; + } + + glDrawBuffer (cctx->attrib.drawBuffer); + glReadBuffer (cctx->attrib.readBuffer); + } + else + { + cctx = NULL; + status = (*iface->exports.forceCurrent) ((__GLcontext *) iface); + } + + return status; +} + +static GLboolean +xglNotifyResize (__GLcontext *gc) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + __GLinterface *iface = pContext->mIface; + + if (!iface) + return GL_TRUE; + + return (*iface->exports.notifyResize) ((__GLcontext *) iface); +} + +static void +xglNotifyDestroy (__GLcontext *gc) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + __GLinterface *iface = pContext->mIface; + + if (iface) + (*iface->exports.notifyDestroy) ((__GLcontext *) iface); +} + +static void +xglNotifySwapBuffers (__GLcontext *gc) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + __GLinterface *iface = pContext->mIface; + + if (iface) + (*iface->exports.notifySwapBuffers) ((__GLcontext *) iface); +} + +static struct __GLdispatchStateRec * +xglDispatchExec (__GLcontext *gc) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + __GLinterface *iface = pContext->mIface; + + if (!iface) + return NULL; + + return (*iface->exports.dispatchExec) ((__GLcontext *) iface); +} + +static void +xglBeginDispatchOverride (__GLcontext *gc) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + __GLinterface *iface = pContext->mIface; + + if (iface) + (*iface->exports.beginDispatchOverride) ((__GLcontext *) iface); +} + +static void +xglEndDispatchOverride (__GLcontext *gc) +{ + xglGLContextPtr pContext = (xglGLContextPtr) gc; + __GLinterface *iface = pContext->mIface; + + if (iface) + (*iface->exports.endDispatchOverride) ((__GLcontext *) iface); +} + +static void +xglLoseCurrentContext (void *closure) +{ + cctx = NULL; + + GlxFlushContextCache (); +} + +static __GLinterface * +xglCreateContext (__GLimports *imports, + __GLcontextModes *modes, + __GLinterface *shareGC) +{ + glitz_drawable_format_t *format; + xglGLContextPtr pShareContext = (xglGLContextPtr) shareGC; + xglGLContextPtr pContext; + __GLinterface *shareIface = NULL; + __GLinterface *iface; + __GLXcontext *glxCtx = (__GLXcontext *) imports->other; + + XGL_SCREEN_PRIV (glxCtx->pScreen); + + format = glitz_drawable_get_format (pScreenPriv->drawable); + + pContext = xalloc (sizeof (xglGLContextRec)); + if (!pContext) + return NULL; + + pContext->context = glitz_context_create (pScreenPriv->drawable, format); + glitz_context_set_user_data (pContext->context, NULL, + xglLoseCurrentContext); + + pContext->needInit = TRUE; + pContext->versionString = NULL; + pContext->errorValue = GL_NO_ERROR; + pContext->shared = NULL; + pContext->list = 0; + pContext->groupList = 0; + pContext->pAttribStack = NULL; + pContext->nAttribStack = 0; + pContext->refcnt = 1; + pContext->doubleBuffer = glxCtx->pGlxVisual->doubleBuffer; + pContext->depthBits = glxCtx->pGlxVisual->depthSize; + pContext->stencilBits = glxCtx->pGlxVisual->stencilSize; + pContext->drawXoff = 0; + pContext->drawYoff = 0; + pContext->maxTexUnits = 0; + pContext->fbo = 0; + + if (pContext->doubleBuffer) + { + pContext->attrib.drawBuffer = GL_BACK; + pContext->attrib.readBuffer = GL_BACK; + } + else + { + pContext->attrib.drawBuffer = GL_FRONT; + pContext->attrib.readBuffer = GL_FRONT; + } + + pContext->attrib.scissorTest = GL_FALSE; + + if (shareGC) + { + pContext->texObjects = NULL; + pContext->displayLists = NULL; + + pContext->shared = pShareContext->shared; + shareIface = pShareContext->mIface; + } + else + { + pContext->texObjects = xglNewHashTable (); + if (!pContext->texObjects) + { + xglFreeContext (pContext); + return NULL; + } + + pContext->displayLists = xglNewHashTable (); + if (!pContext->displayLists) + { + xglFreeContext (pContext); + return NULL; + } + + pContext->shared = pContext; + } + + pContext->shared->refcnt++; + + iface = (*screenInfoPriv.createContext) (imports, modes, shareIface); + if (!iface) + { + xglFreeContext (pContext); + return NULL; + } + + pContext->mIface = iface; + pContext->iface.imports = *imports; + + pContext->iface.exports.destroyContext = xglDestroyContext; + pContext->iface.exports.loseCurrent = xglLoseCurrent; + pContext->iface.exports.makeCurrent = xglMakeCurrent; + pContext->iface.exports.shareContext = xglShareContext; + pContext->iface.exports.copyContext = xglCopyContext; + pContext->iface.exports.forceCurrent = xglForceCurrent; + pContext->iface.exports.notifyResize = xglNotifyResize; + pContext->iface.exports.notifyDestroy = xglNotifyDestroy; + pContext->iface.exports.notifySwapBuffers = xglNotifySwapBuffers; + pContext->iface.exports.dispatchExec = xglDispatchExec; + pContext->iface.exports.beginDispatchOverride = xglBeginDispatchOverride; + pContext->iface.exports.endDispatchOverride = xglEndDispatchOverride; + + return (__GLinterface *) pContext; +} + +static GLboolean +xglSwapBuffers (__GLXdrawablePrivate *glxPriv) +{ + __GLdrawablePrivate *glPriv = &glxPriv->glPriv; + xglGLBufferPtr pBufferPriv = glPriv->private; + DrawablePtr pDrawable = pBufferPriv->pDrawable; + GLboolean status = GL_TRUE; + + if (pDrawable) + { + if (glPriv->modes->doubleBufferMode) + { + glitz_surface_t *surface; + int xOff, yOff; + GCPtr pGC = pBufferPriv->pGC; + BoxPtr pBox = REGION_RECTS (pGC->pCompositeClip); + int nBox = REGION_NUM_RECTS (pGC->pCompositeClip); + + XGL_SCREEN_PRIV (pGC->pScreen); + + if (!xglPrepareTarget (pDrawable)) + return GL_FALSE; + + XGL_GET_DRAWABLE (pDrawable, surface, xOff, yOff); + + /* native swap buffers for fullscreen windows */ + if (surface == pScreenPriv->surface && + nBox == 1 && + pBox->x1 <= 0 && + pBox->y1 <= 0 && + pBox->x2 >= pGC->pScreen->width && + pBox->y2 >= pGC->pScreen->height) + { + glitz_drawable_swap_buffers (pScreenPriv->drawable); + } + else + { + glitz_surface_set_clip_region (surface, xOff, yOff, + (glitz_box_t *) pBox, nBox); + + glitz_copy_area (pBufferPriv->backSurface, + surface, + pDrawable->x + xOff, + pDrawable->y + yOff, + pDrawable->width, + pDrawable->height, + pDrawable->x + xOff, + pDrawable->y + yOff); + + glitz_surface_set_clip_region (surface, 0, 0, NULL, 0); + } + + xglAddBitDamage (pDrawable, pGC->pCompositeClip); + DamageDamageRegion (pDrawable, pGC->pCompositeClip); + REGION_EMPTY (pGC->pScreen, &pBufferPriv->damage); + } + } + else if (pBufferPriv->private) + { + glPriv->private = pBufferPriv->private; + status = (*pBufferPriv->swapBuffers) (glxPriv); + glPriv->private = pBufferPriv; + } + + return status; +} + +static GLboolean +xglResizeBuffers (__GLdrawableBuffer *buffer, + GLint x, + GLint y, + GLuint width, + GLuint height, + __GLdrawablePrivate *glPriv, + GLuint bufferMask) +{ + xglGLBufferPtr pBufferPriv = glPriv->private; + DrawablePtr pDrawable = pBufferPriv->pDrawable; + GLboolean status = GL_TRUE; + + if (pDrawable) + { + if (!xglResizeBuffer (glPriv, x, y, width, height)) + return GL_FALSE; + } + else if (pBufferPriv->private) + { + glPriv->private = pBufferPriv->private; + status = (*pBufferPriv->resizeBuffers) (buffer, + x, y, width, height, + glPriv, + bufferMask); + glPriv->private = pBufferPriv; + } + + return status; +} + +static int +xglBindBuffers (__GLXdrawablePrivate *glxPriv, + int buffer) +{ + __GLdrawablePrivate *glPriv = &glxPriv->glPriv; + xglGLBufferPtr pBufferPriv = glPriv->private; + + if (cctx) + { + xglTexUnitPtr pTexUnit = &cctx->attrib.texUnits[cctx->activeTexUnit]; + xglTexObjPtr pTexObj = NULL; + DrawablePtr pDrawable; + + /* XXX: front left buffer is only supported so far */ + if (buffer != GLX_FRONT_LEFT_EXT) + return BadMatch; + + /* Must be a GLXpixmap */ + if (!glxPriv->pGlxPixmap) + return BadDrawable; + + pDrawable = glxPriv->pGlxPixmap->pDraw; + + switch (glxPriv->texTarget) { + case GLX_TEXTURE_RECTANGLE_EXT: + pTexObj = pTexUnit->pRect; + break; + case GLX_TEXTURE_2D_EXT: + pTexObj = pTexUnit->p2D; + break; + default: + break; + } + + if (pTexObj) + { + glitz_texture_object_t *object; + + XGL_DRAWABLE_PIXMAP (pDrawable); + XGL_PIXMAP_PRIV (pPixmap); + + object = glitz_texture_object_create (pPixmapPriv->surface); + if (object) + { + pPixmap->refcnt++; + + if (pTexObj->pPixmap) + (*pDrawable->pScreen->DestroyPixmap) (pTexObj->pPixmap); + + if (pTexObj->object) + glitz_texture_object_destroy (pTexObj->object); + + pTexObj->pPixmap = pPixmap; + pTexObj->object = object; + + return Success; + } + } + } + else if (pBufferPriv->private) + { + int status; + + glPriv->private = pBufferPriv->private; + status = (*pBufferPriv->bindBuffers) (glxPriv, buffer); + glPriv->private = pBufferPriv; + + return status; + } + + return BadDrawable; +} + +static int +xglReleaseBuffers (__GLXdrawablePrivate *glxPriv, + int buffer) +{ + __GLdrawablePrivate *glPriv = &glxPriv->glPriv; + xglGLBufferPtr pBufferPriv = glPriv->private; + + if (cctx) + { + xglTexObjPtr pTexObj; + + /* XXX: front left buffer is only supported so far */ + if (buffer != GLX_FRONT_LEFT_EXT) + return BadMatch; + + /* Must be a GLXpixmap */ + if (glxPriv->pGlxPixmap) + { + DrawablePtr pDrawable = glxPriv->pGlxPixmap->pDraw; + + XGL_DRAWABLE_PIXMAP (pDrawable); + + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; + if (pTexObj && pTexObj->pPixmap == pPixmap) + { + (*pDrawable->pScreen->DestroyPixmap) (pTexObj->pPixmap); + pTexObj->pPixmap = NULL; + glitz_texture_object_destroy (pTexObj->object); + pTexObj->object = NULL; + + return Success; + } + else + { + pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; + if (pTexObj && pTexObj->pPixmap == pPixmap) + { + (*pDrawable->pScreen->DestroyPixmap) (pTexObj->pPixmap); + pTexObj->pPixmap = NULL; + glitz_texture_object_destroy (pTexObj->object); + pTexObj->object = NULL; + + return Success; + } + } + } + } + else if (pBufferPriv->private) + { + int status; + + glPriv->private = pBufferPriv->private; + status = (*pBufferPriv->releaseBuffers) (glxPriv, buffer); + glPriv->private = pBufferPriv; + + return status; + } + + return BadDrawable; +} + +static void +xglFreeBuffers (__GLdrawablePrivate *glPriv) +{ + xglGLBufferPtr pBufferPriv = glPriv->private; + + glPriv->private = pBufferPriv->private; + + if (pBufferPriv->freeBuffers) + (*pBufferPriv->freeBuffers) (glPriv); + + if (pBufferPriv->pGC) + FreeGC (pBufferPriv->pGC, (GContext) 0); + + if (pBufferPriv->backSurface) + glitz_surface_destroy (pBufferPriv->backSurface); + + xfree (pBufferPriv); +} + +static void +xglCreateBuffer (__GLXdrawablePrivate *glxPriv) +{ + __GLdrawablePrivate *glPriv = &glxPriv->glPriv; + DrawablePtr pDrawable = glxPriv->pDraw; + ScreenPtr pScreen = pDrawable->pScreen; + xglGLBufferPtr pBufferPriv; + + XGL_SCREEN_PRIV (pScreen); + + pBufferPriv = xalloc (sizeof (xglGLBufferRec)); + if (!pBufferPriv) + FatalError ("xglCreateBuffer: No memory\n"); + + pBufferPriv->pScreen = pScreen; + pBufferPriv->pDrawable = NULL; + pBufferPriv->pPixmap = NULL; + pBufferPriv->pGC = NULL; + pBufferPriv->backSurface = NULL; + + pBufferPriv->swapBuffers = NULL; + + pBufferPriv->bindBuffers = NULL; + pBufferPriv->releaseBuffers = NULL; + + pBufferPriv->resizeBuffers = NULL; + pBufferPriv->private = NULL; + pBufferPriv->freeBuffers = NULL; + + REGION_INIT (pScreen, &pBufferPriv->damage, NullBox, 0); + + if (pScreenPriv->fbo || + ((pDrawable->type == DRAWABLE_WINDOW) + +#ifdef COMPOSITE + /* this is a root window, can't be redirected */ + && (!((WindowPtr) pDrawable)->parent) +#endif + + )) + { + pBufferPriv->pDrawable = pDrawable; + } + +/* else if (pScreenPriv->fbo) + { + if (glxPriv->pGlxVisual->doubleBuffer) + { + int depth = pDrawable->depth; + + pBufferPriv->backSurface = + glitz_surface_create (pScreenPriv->drawable, + pScreenPriv->pixmapFormats[depth].format, + pDrawable->width, pDrawable->height, + 0, NULL); + if (pBufferPriv->backSurface) + { + if (glitz_surface_valid_target (pBufferPriv->backSurface)) + { + pBufferPriv->pDrawable = pDrawable; + ErrorF ("Backbuffer created\n"); + } + else + { + glitz_surface_destroy (pBufferPriv->backSurface); + pBufferPriv->backSurface = NULL; + } + } + } + } + */ + else + { + (*screenInfoPriv.createBuffer) (glxPriv); + + /* Wrap the swap buffers routine */ + pBufferPriv->swapBuffers = glxPriv->swapBuffers; + + /* Wrap the render texture routines */ + pBufferPriv->bindBuffers = glxPriv->bindBuffers; + pBufferPriv->releaseBuffers = glxPriv->releaseBuffers; + + /* Wrap the front buffer's resize routine */ + pBufferPriv->resizeBuffers = glPriv->frontBuffer.resize; + + /* Save Xgl's private buffer structure */ + pBufferPriv->freeBuffers = glPriv->freePrivate; + pBufferPriv->private = glPriv->private; + } + + glxPriv->texTarget = GLX_NO_TEXTURE_EXT; + + /* We enable render texture for all GLXPixmaps right now. Eventually, this + should only be enabled when fbconfig attribute GLX_RENDER_TEXTURE_RGB or + GLX_RENDER_TEXTURE_RGBA is set to TRUE. */ + if (pDrawable->type != DRAWABLE_WINDOW) + { + XGL_DRAWABLE_PIXMAP (pDrawable); + + if (xglCreatePixmapSurface (pPixmap)) + { + glitz_texture_object_t *texture; + + XGL_PIXMAP_PRIV (pPixmap); + + texture = glitz_texture_object_create (pPixmapPriv->surface); + if (texture) + { + switch (glitz_texture_object_get_target (texture)) { + case GLITZ_TEXTURE_TARGET_2D: + glxPriv->texTarget = GLX_TEXTURE_2D_EXT; + break; + case GLITZ_TEXTURE_TARGET_RECT: + glxPriv->texTarget = GLX_TEXTURE_RECTANGLE_EXT; + break; + } + + glitz_texture_object_destroy (texture); + } + } + } + + glxPriv->swapBuffers = xglSwapBuffers; + + glxPriv->bindBuffers = xglBindBuffers; + glxPriv->releaseBuffers = xglReleaseBuffers; + + glPriv->frontBuffer.resize = xglResizeBuffers; + + glPriv->private = (void *) pBufferPriv; + glPriv->freePrivate = xglFreeBuffers; +} + +static Bool +xglScreenProbe (int screen) +{ + Bool status; + + status = (*screenInfoPriv.screenProbe) (screen); + + /* Wrap createBuffer */ + if (__glDDXScreenInfo.createBuffer != xglCreateBuffer) + { + screenInfoPriv.createBuffer = __glDDXScreenInfo.createBuffer; + __glDDXScreenInfo.createBuffer = xglCreateBuffer; + } + + /* Wrap createContext */ + if (__glDDXScreenInfo.createContext != xglCreateContext) + { + screenInfoPriv.createContext = __glDDXScreenInfo.createContext; + __glDDXScreenInfo.createContext = xglCreateContext; + } + + return status; +} + +static Bool +xglDestroyWindow (WindowPtr pWin) +{ + ScreenPtr pScreen = pWin->drawable.pScreen; + Bool ret; + + XGL_SCREEN_PRIV (pScreen); + + if (cctx) + { + if (cctx->pDrawBuffer->pDrawable == &pWin->drawable) + cctx->pDrawBuffer->pDrawable = NULL; + + if (cctx->pReadBuffer->pDrawable == &pWin->drawable) + cctx->pReadBuffer->pDrawable = NULL; + } + + XGL_SCREEN_UNWRAP (DestroyWindow); + ret = (*pScreen->DestroyWindow) (pWin); + XGL_SCREEN_WRAP (DestroyWindow, xglDestroyWindow); + + return ret; +} + +Bool +xglInitVisualConfigs (ScreenPtr pScreen) +{ + miInitVisualsProcPtr initVisualsProc = NULL; + VisualPtr visuals; + int nvisuals; + DepthPtr depths; + int ndepths; + int rootDepth; + VisualID defaultVis; + glitz_drawable_format_t *format; + xglPixelFormatPtr pPixel; + __GLXvisualConfig *pConfig; + xglGLXVisualConfigPtr pConfigPriv, *ppConfigPriv; + XID *installedCmaps; + ColormapPtr installedCmap; + int numInstalledCmaps; + int numConfig = 1; + int depth, bpp, i; + + XGL_SCREEN_PRIV (pScreen); + + XGL_SCREEN_WRAP (DestroyWindow, xglDestroyWindow); + + depth = pScreenPriv->pVisual->pPixel->depth; + bpp = pScreenPriv->pVisual->pPixel->masks.bpp; + format = glitz_drawable_get_format (pScreenPriv->drawable); + pPixel = pScreenPriv->pixmapFormats[depth].pPixel; + + if (format->doublebuffer) + { + pScreenPriv->backSurface = + glitz_surface_create (pScreenPriv->drawable, + pScreenPriv->pixmapFormats[depth].format, + pScreen->width, pScreen->height, + 0, NULL); + if (!pScreenPriv->backSurface) + return FALSE; + + glitz_surface_attach (pScreenPriv->backSurface, + pScreenPriv->drawable, + GLITZ_DRAWABLE_BUFFER_BACK_COLOR); + + numConfig *= 2; + } + + pConfig = xcalloc (sizeof (__GLXvisualConfig), numConfig); + if (!pConfig) + return FALSE; + + pConfigPriv = xcalloc (sizeof (xglGLXVisualConfigRec), numConfig); + if (!pConfigPriv) + { + xfree (pConfig); + return FALSE; + } + + ppConfigPriv = xcalloc (sizeof (xglGLXVisualConfigPtr), numConfig); + if (!ppConfigPriv) + { + xfree (pConfigPriv); + xfree (pConfig); + return FALSE; + } + + installedCmaps = xalloc (pScreen->maxInstalledCmaps * sizeof (XID)); + if (!installedCmaps) + { + xfree (ppConfigPriv); + xfree (pConfigPriv); + xfree (pConfig); + return FALSE; + } + + for (i = 0; i < numConfig; i++) + { + ppConfigPriv[i] = &pConfigPriv[i]; + + pConfig[i].vid = (VisualID) (-1); + pConfig[i].class = -1; + pConfig[i].rgba = TRUE; + + pConfig[i].redSize = format->color.red_size; + pConfig[i].greenSize = format->color.green_size; + pConfig[i].blueSize = format->color.blue_size; + + pConfig[i].redMask = pPixel->masks.red_mask; + pConfig[i].greenMask = pPixel->masks.green_mask; + pConfig[i].blueMask = pPixel->masks.blue_mask; + + if (format->color.alpha_size) + { + pConfig[i].alphaSize = format->color.alpha_size; + pConfig[i].alphaMask = pPixel->masks.alpha_mask; + } + else + { + pConfig[i].alphaSize = 0; + pConfig[i].alphaMask = 0; + } + + if (i == 1) + { + pConfig[i].doubleBuffer = FALSE; + pConfig[i].depthSize = 0; + pConfig[i].stencilSize = 0; + + } + else + { + pConfig[i].doubleBuffer = TRUE; + pConfig[i].depthSize = format->depth_size; + pConfig[i].stencilSize = format->stencil_size; + } + + pConfig[i].stereo = FALSE; + + if (depth == 16) + pConfig[i].bufferSize = 16; + else + pConfig[i].bufferSize = 32; + + pConfig[i].auxBuffers = 0; + pConfig[i].level = 0; + + pConfig[i].visualRating = GLX_NONE; + + pConfig[i].transparentPixel = GLX_NONE; + pConfig[i].transparentRed = 0; + pConfig[i].transparentGreen = 0; + pConfig[i].transparentBlue = 0; + pConfig[i].transparentAlpha = 0; + pConfig[i].transparentIndex = 0; + } + + GlxSetVisualConfigs (numConfig, pConfig, (void **) ppConfigPriv); + + /* Wrap screenProbe */ + if (__glDDXScreenInfo.screenProbe != xglScreenProbe) + { + screenInfoPriv.screenProbe = __glDDXScreenInfo.screenProbe; + __glDDXScreenInfo.screenProbe = xglScreenProbe; + } + + visuals = pScreen->visuals; + nvisuals = pScreen->numVisuals; + depths = pScreen->allowedDepths; + ndepths = pScreen->numDepths; + rootDepth = pScreen->rootDepth; + defaultVis = pScreen->rootVisual; + + /* Find installed colormaps */ + numInstalledCmaps = (*pScreen->ListInstalledColormaps) (pScreen, + installedCmaps); + + GlxWrapInitVisuals (&initVisualsProc); + GlxInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootDepth, + &defaultVis, ((unsigned long) 1 << (bpp - 1)), 8, -1); + + /* Fix up any existing installed colormaps. */ + for (i = 0; i < numInstalledCmaps; i++) + { + int j; + + installedCmap = LookupIDByType (installedCmaps[i], RT_COLORMAP); + if (!installedCmap) + continue; + + j = installedCmap->pVisual - pScreen->visuals; + installedCmap->pVisual = &visuals[j]; + } + + pScreen->visuals = visuals; + pScreen->numVisuals = nvisuals; + pScreen->allowedDepths = depths; + pScreen->numDepths = ndepths; + pScreen->rootDepth = rootDepth; + pScreen->rootVisual = defaultVis; + + xfree (installedCmaps); + xfree (pConfigPriv); + xfree (pConfig); + + return TRUE; +} diff --git a/hw/xgl/glxext/xglglxext.h b/hw/xgl/glxext/xglglxext.h new file mode 100644 index 000000000..491b26881 --- /dev/null +++ b/hw/xgl/glxext/xglglxext.h @@ -0,0 +1,38 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#ifndef _XGL_GLXEXT_H_ +#define _XGL_GLXEXT_H_ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include "scrnintstr.h" + +Bool +xglInitVisualConfigs (ScreenPtr pScreen); + +#endif /* _XGL_GLXEXT_H_ */ diff --git a/hw/xgl/xgl.h b/hw/xgl/xgl.h index 8158f5bb6..ceb18ddaa 100644 --- a/hw/xgl/xgl.h +++ b/hw/xgl/xgl.h @@ -55,7 +55,7 @@ typedef struct _GCFuncs *GCFuncsPtr; extern WindowPtr *WindowTable; -#define XGL_DEFAULT_PBO_MASK 0 /* don't use PBO as default */ +#define XGL_DEFAULT_PBO_MASK 0 typedef struct _xglScreenInfo { glitz_drawable_t *drawable; @@ -63,14 +63,16 @@ typedef struct _xglScreenInfo { unsigned int height; unsigned int widthMm; unsigned int heightMm; - Bool fullscreen; int geometryDataType; int geometryUsage; Bool yInverted; int pboMask; Bool lines; + Bool fbo; } xglScreenInfoRec, *xglScreenInfoPtr; +extern xglScreenInfoRec xglScreenInfo; + typedef struct _xglPixelFormat { CARD8 depth, bitsPerRGB; glitz_pixel_masks_t masks; @@ -213,6 +215,7 @@ typedef struct _xglScreen { Bool yInverted; int pboMask; Bool lines; + Bool fbo; xglGeometryRec scratchGeometry; #ifdef RENDER @@ -489,24 +492,21 @@ xglParseFindNext (char *cur, char *last); void -xglParseScreen (xglScreenInfoPtr pScreenInfo, - char *arg); +xglParseScreen (char *arg); void xglUseMsg (void); int -xglProcessArgument (xglScreenInfoPtr pScreenInfo, - int argc, - char **argv, - int i); +xglProcessArgument (int argc, + char **argv, + int i); /* xglscreen.c */ Bool -xglScreenInit (ScreenPtr pScreen, - xglScreenInfoPtr pScreenInfo); +xglScreenInit (ScreenPtr pScreen); Bool xglFinishScreenInit (ScreenPtr pScreen); @@ -871,6 +871,10 @@ xglAddSurfaceDamage (DrawablePtr pDrawable, void xglAddCurrentSurfaceDamage (DrawablePtr pDrawable); +void +xglAddBitDamage (DrawablePtr pDrawable, + RegionPtr pRegion); + void xglAddCurrentBitDamage (DrawablePtr pDrawable); @@ -1327,10 +1331,47 @@ xglAddTraps (PicturePtr pDst, #endif +#ifdef XLOADABLE + +/* xglloader.c */ + +typedef struct _xglSymbol { + void **ptr; + const char *name; +} xglSymbolRec, *xglSymbolPtr; + +void * +xglLoadModule (const char *name); + +void +xglUnloadModule (void *handle); + +Bool +xglLookupSymbols (void *handle, + xglSymbolPtr sym, + int nSym); + +#endif + #ifdef GLXEXT +/* xglglx.c */ + +Bool +xglLoadGLXModules (void); + +void +xglUnloadGLXModules (void); + +#endif + +/* xglhash.c */ + typedef struct _xglHashTable *xglHashTablePtr; +Bool +xglLoadHashFuncs (void *handle); + xglHashTablePtr xglNewHashTable (void); @@ -1361,9 +1402,4 @@ unsigned int xglHashFindFreeKeyBlock (xglHashTablePtr pTable, unsigned int numKeys); -Bool -xglInitVisualConfigs (ScreenPtr pScreen); - -#endif - #endif /* _XGL_H_ */ diff --git a/hw/xgl/xglcmap.c b/hw/xgl/xglcmap.c index 9e383223d..f0c2ba2e4 100644 --- a/hw/xgl/xglcmap.c +++ b/hw/xgl/xglcmap.c @@ -23,6 +23,7 @@ * Author: David Reveman */ +#include #include "xgl.h" #include "colormapst.h" #include "micmap.h" @@ -147,7 +148,6 @@ xglSetVisualTypesAndMasks (ScreenInfo *pScreenInfo, nxglVisuals++; } } - } } diff --git a/hw/xgl/xglglx.c b/hw/xgl/xglglx.c deleted file mode 100644 index 88e23e2a4..000000000 --- a/hw/xgl/xglglx.c +++ /dev/null @@ -1,4911 +0,0 @@ -/* - * Copyright © 2005 Novell, Inc. - * - * Permission to use, copy, modify, distribute, and sell this software - * and its documentation for any purpose is hereby granted without - * fee, provided that the above copyright notice appear in all copies - * and that both that copyright notice and this permission notice - * appear in supporting documentation, and that the name of - * Novell, Inc. not be used in advertising or publicity pertaining to - * distribution of the software without specific, written prior permission. - * Novell, Inc. makes no representations about the suitability of this - * software for any purpose. It is provided "as is" without express or - * implied warranty. - * - * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, - * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN - * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR - * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS - * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, - * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION - * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - * - * Author: David Reveman - */ - -#include "xgl.h" - -#ifdef GLXEXT - -#include - -#include "glxserver.h" -#include "glxdrawable.h" -#include "glxscreens.h" -#include "glxutil.h" -#include "unpack.h" -#include "g_disptab.h" -#include "micmap.h" - -#define XGL_MAX_TEXTURE_UNITS 8 - -#define XGL_TEXTURE_1D_BIT (1 << 0) -#define XGL_TEXTURE_2D_BIT (1 << 1) -#define XGL_TEXTURE_3D_BIT (1 << 2) -#define XGL_TEXTURE_RECTANGLE_BIT (1 << 3) -#define XGL_TEXTURE_CUBE_MAP_BIT (1 << 4) - -extern void -GlxSetVisualConfigs (int nconfigs, - __GLXvisualConfig *configs, - void **privates); - -extern void -GlxWrapInitVisuals (miInitVisualsProcPtr *); - -extern int -GlxInitVisuals (VisualPtr *visualp, - DepthPtr *depthp, - int *nvisualp, - int *ndepthp, - int *rootDepthp, - VisualID *defaultVisp, - unsigned long sizes, - int bitsPerRGB, - int preferredVis); - -extern void -__glXFlushContextCache (void); - -extern __GLXscreenInfo __glDDXScreenInfo; - -extern __glProcTable __glMesaRenderTable; -extern __glProcTableEXT __glMesaRenderTableEXT; - -typedef Bool (*GLXScreenProbeProc) (int screen); -typedef __GLinterface *(*GLXCreateContextProc) (__GLimports *imports, - __GLcontextModes *modes, - __GLinterface *shareGC); -typedef void (*GLXCreateBufferProc) (__GLXdrawablePrivate *glxPriv); -typedef GLboolean (*GLXSwapBuffersProc) (__GLXdrawablePrivate *glxPriv); -typedef int (*GLXBindBuffersProc) (__GLXdrawablePrivate *glxPriv, - int buffer); -typedef int (*GLXReleaseBuffersProc) (__GLXdrawablePrivate *glxPriv, - int buffer); - -typedef struct _xglGLXScreenInfo { - GLXScreenProbeProc screenProbe; - GLXCreateContextProc createContext; - GLXCreateBufferProc createBuffer; -} xglGLXScreenInfoRec, *xglGLXScreenInfoPtr; - -static xglGLXScreenInfoRec screenInfoPriv; - -typedef GLboolean (*GLResizeBuffersProc) (__GLdrawableBuffer *buffer, - GLint x, - GLint y, - GLuint width, - GLuint height, - __GLdrawablePrivate *glPriv, - GLuint bufferMask); -typedef void (*GLFreeBuffersProc) (__GLdrawablePrivate *glPriv); - -typedef struct _xglGLBuffer { - GLXSwapBuffersProc swapBuffers; - GLXBindBuffersProc bindBuffers; - GLXReleaseBuffersProc releaseBuffers; - GLResizeBuffersProc resizeBuffers; - GLFreeBuffersProc freeBuffers; - ScreenPtr pScreen; - DrawablePtr pDrawable; - glitz_surface_t *backSurface; - PixmapPtr pPixmap; - GCPtr pGC; - RegionRec damage; - void *private; - int xOff, yOff; - int yFlip; -} xglGLBufferRec, *xglGLBufferPtr; - -typedef int xglGLXVisualConfigRec, *xglGLXVisualConfigPtr; -typedef struct _xglDisplayList *xglDisplayListPtr; - -#define XGL_LIST_OP_CALLS 0 -#define XGL_LIST_OP_DRAW 1 -#define XGL_LIST_OP_GL 2 -#define XGL_LIST_OP_LIST 3 - -typedef struct _xglGLOp { - void (*glProc) (struct _xglGLOp *pOp); - union { - GLenum enumeration; - GLbitfield bitfield; - GLsizei size; - struct { - GLint x; - GLint y; - GLsizei width; - GLsizei height; - } rect; - struct { - GLenum target; - GLuint texture; - } bind_texture; - struct { - GLenum target; - GLenum pname; - GLint params[4]; - } tex_parameter_iv; - struct { - GLenum target; - GLenum pname; - GLfloat params[4]; - } tex_parameter_fv; - struct { - GLint x; - GLint y; - GLsizei width; - GLsizei height; - GLenum type; - } copy_pixels; - struct { - GLenum target; - GLint level; - GLenum internalformat; - GLint x; - GLint y; - GLsizei width; - GLint border; - } copy_tex_image_1d; - struct { - GLenum target; - GLint level; - GLenum internalformat; - GLint x; - GLint y; - GLsizei width; - GLsizei height; - GLint border; - } copy_tex_image_2d; - struct { - GLenum target; - GLint level; - GLint xoffset; - GLint x; - GLint y; - GLsizei width; - } copy_tex_sub_image_1d; - struct { - GLenum target; - GLint level; - GLint xoffset; - GLint yoffset; - GLint x; - GLint y; - GLsizei width; - GLsizei height; - } copy_tex_sub_image_2d; - struct { - GLenum target; - GLenum internalformat; - GLint x; - GLint y; - GLsizei width; - } copy_color_table; - struct { - GLenum target; - GLsizei start; - GLint x; - GLint y; - GLsizei width; - } copy_color_sub_table; - struct { - GLenum target; - GLenum internalformat; - GLint x; - GLint y; - GLsizei width; - } copy_convolution_filter_1d; - struct { - GLenum target; - GLenum internalformat; - GLint x; - GLint y; - GLsizei width; - GLsizei height; - } copy_convolution_filter_2d; - struct { - GLenum target; - GLint level; - GLint xoffset; - GLint yoffset; - GLint zoffset; - GLint x; - GLint y; - GLsizei width; - GLsizei height; - } copy_tex_sub_image_3d; - struct { - GLfloat x; - GLfloat y; - GLfloat z; - } window_pos_3f; - } u; -} xglGLOpRec, *xglGLOpPtr; - -typedef struct _xglListOp { - int type; - union { - GLuint list; - xglGLOpPtr gl; - } u; -} xglListOpRec, *xglListOpPtr; - -typedef struct _xglDisplayList { - xglListOpPtr pOp; - int nOp; - int size; -} xglDisplayListRec; - -typedef struct _xglTexObj { - GLuint key; - GLuint name; - PixmapPtr pPixmap; - int refcnt; -} xglTexObjRec, *xglTexObjPtr; - -typedef struct _xglTexUnit { - GLbitfield enabled; - xglTexObjPtr p1D; - xglTexObjPtr p2D; - xglTexObjPtr p3D; - xglTexObjPtr pRect; - xglTexObjPtr pCubeMap; -} xglTexUnitRec, *xglTexUnitPtr; - -typedef struct _xglGLAttributes { - GLbitfield mask; - GLenum drawBuffer; - GLenum readBuffer; - xRectangle viewport; - xRectangle scissor; - GLboolean scissorTest; - xglTexUnitRec texUnits[XGL_MAX_TEXTURE_UNITS]; -} xglGLAttributesRec, *xglGLAttributesPtr; - -typedef struct _xglGLContext { - __GLinterface iface; - __GLinterface *mIface; - int refcnt; - struct _xglGLContext *shared; - glitz_context_t *context; - __glProcTableEXT glRenderTableEXT; - PFNGLACTIVETEXTUREARBPROC ActiveTextureARB; - PFNGLWINDOWPOS3FMESAPROC WindowPos3fMESA; - Bool needInit; - xglGLBufferPtr pDrawBuffer; - xglGLBufferPtr pReadBuffer; - int drawXoff, drawYoff; - char *versionString; - GLenum errorValue; - GLboolean doubleBuffer; - GLint depthBits; - GLint stencilBits; - xglHashTablePtr texObjects; - xglHashTablePtr displayLists; - GLuint list; - GLenum listMode; - xglDisplayListPtr pList; - GLuint groupList; - xglGLAttributesRec attrib; - xglGLAttributesPtr pAttribStack; - int nAttribStack; - int activeTexUnit; - GLint maxTexUnits; - GLint maxListNesting; -} xglGLContextRec, *xglGLContextPtr; - -static xglGLContextPtr cctx = NULL; - -static void -xglSetCurrentContext (xglGLContextPtr pContext); - -#define XGL_GLX_INTERSECT_BOX(pBox1, pBox2) \ - { \ - if ((pBox1)->x1 < (pBox2)->x1) \ - (pBox1)->x1 = (pBox2)->x1; \ - if ((pBox1)->y1 < (pBox2)->y1) \ - (pBox1)->y1 = (pBox2)->y1; \ - if ((pBox1)->x2 > (pBox2)->x2) \ - (pBox1)->x2 = (pBox2)->x2; \ - if ((pBox1)->y2 > (pBox2)->y2) \ - (pBox1)->y2 = (pBox2)->y2; \ - } - -#define XGL_GLX_SET_SCISSOR_BOX(pBox) \ - glScissor ((pBox)->x1, \ - cctx->pDrawBuffer->yFlip - (pBox)->y2, \ - (pBox)->x2 - (pBox)->x1, \ - (pBox)->y2 - (pBox)->y1) - -#define XGL_GLX_DRAW_PROLOGUE(pBox, nBox, pScissorBox) \ - (pBox) = REGION_RECTS (cctx->pDrawBuffer->pGC->pCompositeClip); \ - (nBox) = REGION_NUM_RECTS (cctx->pDrawBuffer->pGC->pCompositeClip); \ - (pScissorBox)->x1 = cctx->attrib.scissor.x + cctx->pDrawBuffer->xOff; \ - (pScissorBox)->x2 = (pScissorBox)->x1 + cctx->attrib.scissor.width; \ - (pScissorBox)->y2 = cctx->attrib.scissor.y + cctx->pDrawBuffer->yOff; \ - (pScissorBox)->y2 = cctx->pDrawBuffer->yFlip - (pScissorBox)->y2; \ - (pScissorBox)->y1 = (pScissorBox)->y2 - cctx->attrib.scissor.height; \ - xglSetupTextures () - -#define XGL_GLX_DRAW_DAMAGE(pBox, pRegion) \ - if (cctx->attrib.drawBuffer != GL_BACK && \ - cctx->pDrawBuffer->pDrawable && \ - cctx->pDrawBuffer->pDrawable->type != DRAWABLE_PIXMAP) \ - { \ - REGION_INIT (cctx->pDrawBuffer->pGC->pScreen, pRegion, pBox, 1); \ - REGION_UNION (cctx->pDrawBuffer->pGC->pScreen, \ - &cctx->pDrawBuffer->damage, \ - &cctx->pDrawBuffer->damage, \ - pRegion); \ - REGION_UNINIT (cctx->pDrawBuffer->pGC->pScreen, pRegion); \ - } - -static void -xglRecordError (GLenum error) -{ - if (cctx->errorValue == GL_NO_ERROR) - cctx->errorValue = error; -} - -static xglDisplayListPtr -xglCreateList (void) -{ - xglDisplayListPtr pDisplayList; - - pDisplayList = xalloc (sizeof (xglDisplayListRec)); - if (!pDisplayList) - return NULL; - - pDisplayList->pOp = NULL; - pDisplayList->nOp = 0; - pDisplayList->size = 0; - - return pDisplayList; -} - -static void -xglDestroyList (xglDisplayListPtr pDisplayList) -{ - xglListOpPtr pOp = pDisplayList->pOp; - int nOp = pDisplayList->nOp; - - while (nOp--) - { - switch (pOp->type) { - case XGL_LIST_OP_CALLS: - case XGL_LIST_OP_DRAW: - glDeleteLists (pOp->u.list, 1); - break; - case XGL_LIST_OP_GL: - xfree (pOp->u.gl); - break; - case XGL_LIST_OP_LIST: - break; - } - - pOp++; - } - - if (pDisplayList->pOp) - xfree (pDisplayList->pOp); - - xfree (pDisplayList); -} - -static Bool -xglResizeList (xglDisplayListPtr pDisplayList, - int nOp) -{ - if (pDisplayList->size < nOp) - { - int size = pDisplayList->nOp ? pDisplayList->nOp : 4; - - while (size < nOp) - size <<= 1; - - pDisplayList->pOp = xrealloc (pDisplayList->pOp, - sizeof (xglListOpRec) * size); - if (!pDisplayList->pOp) - return FALSE; - - pDisplayList->size = size; - } - - return TRUE; -} - -static void -xglStartList (int type, - GLenum mode) -{ - if (!xglResizeList (cctx->pList, cctx->pList->nOp + 1)) - { - xglRecordError (GL_OUT_OF_MEMORY); - return; - } - - cctx->pList->pOp[cctx->pList->nOp].type = type; - cctx->pList->pOp[cctx->pList->nOp].u.list = glGenLists (1); - - glNewList (cctx->pList->pOp[cctx->pList->nOp].u.list, mode); - - cctx->pList->nOp++; -} - -static void -xglGLOp (xglGLOpPtr pOp) -{ - if (cctx->list) - { - xglGLOpPtr pGLOp; - - pGLOp = xalloc (sizeof (xglGLOpRec)); - if (!pGLOp) - { - xglRecordError (GL_OUT_OF_MEMORY); - return; - } - - if (!xglResizeList (cctx->pList, cctx->pList->nOp + 1)) - { - xfree (pGLOp); - xglRecordError (GL_OUT_OF_MEMORY); - return; - } - - glEndList (); - - *pGLOp = *pOp; - - cctx->pList->pOp[cctx->pList->nOp].type = XGL_LIST_OP_GL; - cctx->pList->pOp[cctx->pList->nOp].u.gl = pGLOp; - cctx->pList->nOp++; - - if (cctx->listMode == GL_COMPILE_AND_EXECUTE) - (*pOp->glProc) (pOp); - - xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); - } - else - (*pOp->glProc) (pOp); -} - -static void -xglViewportProc (xglGLOpPtr pOp) -{ - cctx->attrib.viewport.x = pOp->u.rect.x; - cctx->attrib.viewport.y = pOp->u.rect.y; - cctx->attrib.viewport.width = pOp->u.rect.width; - cctx->attrib.viewport.height = pOp->u.rect.height; - - glViewport (pOp->u.rect.x + cctx->pDrawBuffer->xOff, - pOp->u.rect.y + cctx->pDrawBuffer->yOff, - pOp->u.rect.width, - pOp->u.rect.height); -} - -static void -xglViewport (GLint x, - GLint y, - GLsizei width, - GLsizei height) -{ - xglGLOpRec gl; - - gl.glProc = xglViewportProc; - - gl.u.rect.x = x; - gl.u.rect.y = y; - gl.u.rect.width = width; - gl.u.rect.height = height; - - xglGLOp (&gl); -} - -static void -xglScissorProc (xglGLOpPtr pOp) -{ - cctx->attrib.scissor.x = pOp->u.rect.x; - cctx->attrib.scissor.y = pOp->u.rect.y; - cctx->attrib.scissor.width = pOp->u.rect.width; - cctx->attrib.scissor.height = pOp->u.rect.height; -} - -static void -xglScissor (GLint x, - GLint y, - GLsizei width, - GLsizei height) -{ - xglGLOpRec gl; - - gl.glProc = xglScissorProc; - - gl.u.rect.x = x; - gl.u.rect.y = y; - gl.u.rect.width = width; - gl.u.rect.height = height; - - xglGLOp (&gl); -} - -static void -xglDrawBufferProc (xglGLOpPtr pOp) -{ - switch (pOp->u.enumeration) { - case GL_FRONT: - case GL_FRONT_AND_BACK: - break; - case GL_BACK: - if (!cctx->doubleBuffer) - { - xglRecordError (GL_INVALID_OPERATION); - return; - } - break; - default: - xglRecordError (GL_INVALID_ENUM); - return; - } - - cctx->attrib.drawBuffer = pOp->u.enumeration; - - glDrawBuffer (pOp->u.enumeration); -} - -static void -xglDrawBuffer (GLenum mode) -{ - xglGLOpRec gl; - - gl.glProc = xglDrawBufferProc; - - gl.u.enumeration = mode; - - xglGLOp (&gl); -} - -static void -xglReadBufferProc (xglGLOpPtr pOp) -{ - switch (pOp->u.enumeration) { - case GL_FRONT: - break; - case GL_BACK: - if (!cctx->doubleBuffer) - { - xglRecordError (GL_INVALID_OPERATION); - return; - } - break; - default: - xglRecordError (GL_INVALID_ENUM); - return; - } - - cctx->attrib.readBuffer = pOp->u.enumeration; - - glReadBuffer (pOp->u.enumeration); -} - -static void -xglReadBuffer (GLenum mode) -{ - xglGLOpRec gl; - - gl.glProc = xglReadBufferProc; - - gl.u.enumeration = mode; - - xglGLOp (&gl); -} - -static void -xglDisableProc (xglGLOpPtr pOp) -{ - xglTexUnitPtr pTexUnit = &cctx->attrib.texUnits[cctx->activeTexUnit]; - - switch (pOp->u.enumeration) { - case GL_SCISSOR_TEST: - cctx->attrib.scissorTest = GL_FALSE; - return; - case GL_TEXTURE_1D: - pTexUnit->enabled &= ~XGL_TEXTURE_1D_BIT; - break; - case GL_TEXTURE_2D: - pTexUnit->enabled &= ~XGL_TEXTURE_2D_BIT; - break; - case GL_TEXTURE_3D: - pTexUnit->enabled &= ~XGL_TEXTURE_3D_BIT; - break; - case GL_TEXTURE_RECTANGLE_NV: - pTexUnit->enabled &= ~XGL_TEXTURE_RECTANGLE_BIT; - break; - case GL_TEXTURE_CUBE_MAP_ARB: - pTexUnit->enabled &= ~XGL_TEXTURE_CUBE_MAP_BIT; - break; - default: - break; - } - - glDisable (pOp->u.enumeration); -} - -static void -xglDisable (GLenum cap) -{ - xglGLOpRec gl; - - gl.glProc = xglDisableProc; - - gl.u.enumeration = cap; - - xglGLOp (&gl); -} - -static void -xglEnableProc (xglGLOpPtr pOp) -{ - xglTexUnitPtr pTexUnit = &cctx->attrib.texUnits[cctx->activeTexUnit]; - - switch (pOp->u.enumeration) { - case GL_SCISSOR_TEST: - cctx->attrib.scissorTest = GL_TRUE; - return; - case GL_DEPTH_TEST: - if (!cctx->depthBits) - return; - case GL_STENCIL_TEST: - if (!cctx->stencilBits) - return; - case GL_TEXTURE_1D: - pTexUnit->enabled |= XGL_TEXTURE_1D_BIT; - break; - case GL_TEXTURE_2D: - pTexUnit->enabled |= XGL_TEXTURE_2D_BIT; - break; - case GL_TEXTURE_3D: - pTexUnit->enabled |= XGL_TEXTURE_3D_BIT; - break; - case GL_TEXTURE_RECTANGLE_NV: - pTexUnit->enabled |= XGL_TEXTURE_RECTANGLE_BIT; - break; - case GL_TEXTURE_CUBE_MAP_ARB: - pTexUnit->enabled |= XGL_TEXTURE_CUBE_MAP_BIT; - break; - default: - break; - } - - glEnable (pOp->u.enumeration); -} - -static void -xglEnable (GLenum cap) -{ - xglGLOpRec gl; - - gl.glProc = xglEnableProc; - - gl.u.enumeration = cap; - - xglGLOp (&gl); -} - -static void -xglDeleteTexObj (xglTexObjPtr pTexObj) -{ - if (pTexObj->pPixmap) - { - ScreenPtr pScreen = pTexObj->pPixmap->drawable.pScreen; - - (*pScreen->DestroyPixmap) (pTexObj->pPixmap); - } - - if (pTexObj->name) - { - glDeleteTextures (1, &pTexObj->name); - } - - pTexObj->key = 0; - pTexObj->name = 0; - pTexObj->pPixmap = NULL; -} - -static void -xglRefTexObj (xglTexObjPtr pTexObj) -{ - if (!pTexObj) - return; - - pTexObj->refcnt++; -} - -static void -xglUnrefTexObj (xglTexObjPtr pTexObj) -{ - if (!pTexObj) - return; - - pTexObj->refcnt--; - if (pTexObj->refcnt) - return; - - xglDeleteTexObj (pTexObj); - - xfree (pTexObj); -} - -static void -xglPushAttribProc (xglGLOpPtr pOp) -{ - xglGLAttributesPtr pAttrib; - GLint depth; - - glGetIntegerv (GL_MAX_ATTRIB_STACK_DEPTH, &depth); - - if (cctx->nAttribStack == depth) - { - xglRecordError (GL_STACK_OVERFLOW); - return; - } - - cctx->pAttribStack = - realloc (cctx->pAttribStack, - sizeof (xglGLAttributesRec) * (cctx->nAttribStack + 1)); - - if (!cctx->pAttribStack) - { - xglRecordError (GL_OUT_OF_MEMORY); - return; - } - - pAttrib = &cctx->pAttribStack[cctx->nAttribStack]; - pAttrib->mask = pOp->u.bitfield; - - *pAttrib = cctx->attrib; - - if (pOp->u.bitfield & GL_TEXTURE_BIT) - { - int i; - - for (i = 0; i < cctx->maxTexUnits; i++) - { - xglRefTexObj (pAttrib->texUnits[i].p1D); - xglRefTexObj (pAttrib->texUnits[i].p2D); - xglRefTexObj (pAttrib->texUnits[i].p3D); - xglRefTexObj (pAttrib->texUnits[i].pRect); - xglRefTexObj (pAttrib->texUnits[i].pCubeMap); - } - } - - cctx->nAttribStack++; - - glPushAttrib (pOp->u.bitfield); -} - -static void -xglPushAttrib (GLbitfield mask) -{ - xglGLOpRec gl; - - gl.glProc = xglPushAttribProc; - - gl.u.bitfield = mask; - - xglGLOp (&gl); -} - -static void -xglPopAttribProc (xglGLOpPtr pOp) -{ - xglGLAttributesPtr pAttrib; - GLbitfield mask; - - if (!cctx->nAttribStack) - { - xglRecordError (GL_STACK_UNDERFLOW); - return; - } - - cctx->nAttribStack--; - - pAttrib = &cctx->pAttribStack[cctx->nAttribStack]; - mask = pAttrib->mask; - - if (mask & GL_COLOR_BUFFER_BIT) - xglDrawBuffer (pAttrib->drawBuffer); - - if (mask & GL_PIXEL_MODE_BIT) - xglReadBuffer (pAttrib->readBuffer); - - if (mask & GL_SCISSOR_BIT) - { - xglScissor (pAttrib->scissor.x, - pAttrib->scissor.y, - pAttrib->scissor.width, - pAttrib->scissor.height); - - if (pAttrib->scissorTest) - xglEnable (GL_SCISSOR_TEST); - else - xglDisable (GL_SCISSOR_TEST); - } - else if (mask & GL_ENABLE_BIT) - { - if (pAttrib->scissorTest) - xglEnable (GL_SCISSOR_TEST); - else - xglDisable (GL_SCISSOR_TEST); - } - - if (mask & GL_VIEWPORT_BIT) - xglViewport (pAttrib->viewport.x, - pAttrib->viewport.y, - pAttrib->viewport.width, - pAttrib->viewport.height); - - if (mask & GL_TEXTURE_BIT) - { - int i; - - for (i = 0; i < cctx->maxTexUnits; i++) - { - xglUnrefTexObj (cctx->attrib.texUnits[i].p1D); - xglUnrefTexObj (cctx->attrib.texUnits[i].p2D); - xglUnrefTexObj (cctx->attrib.texUnits[i].p3D); - xglUnrefTexObj (cctx->attrib.texUnits[i].pRect); - xglUnrefTexObj (cctx->attrib.texUnits[i].pCubeMap); - - cctx->attrib.texUnits[i] = pAttrib->texUnits[i]; - } - } - else if (mask & GL_ENABLE_BIT) - { - int i; - - for (i = 0; i < cctx->maxTexUnits; i++) - cctx->attrib.texUnits[i].enabled = pAttrib->texUnits[i].enabled; - } - - cctx->pAttribStack = - realloc (cctx->pAttribStack, - sizeof (xglGLAttributesRec) * cctx->nAttribStack); - - glPopAttrib (); -} - -static void -xglPopAttrib (void) -{ - xglGLOpRec gl; - - gl.glProc = xglPopAttribProc; - - xglGLOp (&gl); -} - -static GLuint -xglActiveTextureBinding (GLenum target) -{ - xglTexObjPtr pTexObj; - - switch (target) { - case GL_TEXTURE_BINDING_1D: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p1D; - break; - case GL_TEXTURE_BINDING_2D: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; - break; - case GL_TEXTURE_BINDING_3D: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p3D; - break; - case GL_TEXTURE_BINDING_RECTANGLE_NV: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; - break; - case GL_TEXTURE_BINDING_CUBE_MAP_ARB: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pCubeMap; - break; - default: - return 0; - } - - if (pTexObj) - return pTexObj->key; - - return 0; -} - -#define DOUBLE_TO_BOOLEAN(X) ((X) ? GL_TRUE : GL_FALSE) -#define INT_TO_BOOLEAN(I) ((I) ? GL_TRUE : GL_FALSE) -#define ENUM_TO_BOOLEAN(E) ((E) ? GL_TRUE : GL_FALSE) - -static void -xglGetBooleanv (GLenum pname, - GLboolean *params) -{ - switch (pname) { - case GL_CURRENT_RASTER_POSITION: - { - GLdouble v[4]; - - glGetDoublev (GL_CURRENT_RASTER_POSITION, v); - - params[0] = DOUBLE_TO_BOOLEAN (v[0] - (GLdouble) cctx->drawXoff); - params[1] = DOUBLE_TO_BOOLEAN (v[1] - (GLdouble) cctx->drawYoff); - params[2] = DOUBLE_TO_BOOLEAN (v[2]); - params[3] = DOUBLE_TO_BOOLEAN (v[3]); - } break; - case GL_DOUBLEBUFFER: - params[0] = cctx->doubleBuffer; - break; - case GL_DEPTH_BITS: - params[0] = INT_TO_BOOLEAN (cctx->depthBits); - break; - case GL_STENCIL_BITS: - params[0] = INT_TO_BOOLEAN (cctx->stencilBits); - break; - case GL_DRAW_BUFFER: - params[0] = ENUM_TO_BOOLEAN (cctx->attrib.drawBuffer); - break; - case GL_READ_BUFFER: - params[0] = ENUM_TO_BOOLEAN (cctx->attrib.readBuffer); - break; - case GL_SCISSOR_BOX: - params[0] = INT_TO_BOOLEAN (cctx->attrib.scissor.x); - params[1] = INT_TO_BOOLEAN (cctx->attrib.scissor.y); - params[2] = INT_TO_BOOLEAN (cctx->attrib.scissor.width); - params[3] = INT_TO_BOOLEAN (cctx->attrib.scissor.height); - break; - case GL_SCISSOR_TEST: - params[0] = cctx->attrib.scissorTest; - break; - case GL_VIEWPORT: - params[0] = INT_TO_BOOLEAN (cctx->attrib.viewport.x); - params[1] = INT_TO_BOOLEAN (cctx->attrib.viewport.y); - params[2] = INT_TO_BOOLEAN (cctx->attrib.viewport.width); - params[3] = INT_TO_BOOLEAN (cctx->attrib.viewport.height); - break; - case GL_TEXTURE_BINDING_1D: - case GL_TEXTURE_BINDING_2D: - case GL_TEXTURE_BINDING_3D: - case GL_TEXTURE_RECTANGLE_NV: - /* should be safe to fall-through here */ - default: - glGetBooleanv (pname, params); - } -} - -#define INT_TO_DOUBLE(I) ((GLdouble) (I)) -#define ENUM_TO_DOUBLE(E) ((GLdouble) (E)) -#define BOOLEAN_TO_DOUBLE(B) ((B) ? 1.0F : 0.0F) - -static void -xglGetDoublev (GLenum pname, - GLdouble *params) -{ - switch (pname) { - case GL_CURRENT_RASTER_POSITION: - glGetDoublev (GL_CURRENT_RASTER_POSITION, params); - - params[0] -= (GLdouble) cctx->drawXoff; - params[1] -= (GLdouble) cctx->drawYoff; - break; - case GL_DOUBLEBUFFER: - params[0] = BOOLEAN_TO_DOUBLE (cctx->doubleBuffer); - break; - case GL_DEPTH_BITS: - params[0] = INT_TO_DOUBLE (cctx->depthBits); - break; - case GL_STENCIL_BITS: - params[0] = INT_TO_DOUBLE (cctx->stencilBits); - break; - case GL_DRAW_BUFFER: - params[0] = ENUM_TO_DOUBLE (cctx->attrib.drawBuffer); - break; - case GL_READ_BUFFER: - params[0] = ENUM_TO_DOUBLE (cctx->attrib.readBuffer); - break; - case GL_SCISSOR_BOX: - params[0] = cctx->attrib.scissor.x; - params[1] = cctx->attrib.scissor.y; - params[2] = cctx->attrib.scissor.width; - params[3] = cctx->attrib.scissor.height; - break; - case GL_SCISSOR_TEST: - params[0] = BOOLEAN_TO_DOUBLE (cctx->attrib.scissorTest); - break; - case GL_VIEWPORT: - params[0] = cctx->attrib.viewport.x; - params[1] = cctx->attrib.viewport.y; - params[2] = cctx->attrib.viewport.width; - params[3] = cctx->attrib.viewport.height; - break; - case GL_TEXTURE_BINDING_1D: - case GL_TEXTURE_BINDING_2D: - case GL_TEXTURE_BINDING_3D: - case GL_TEXTURE_RECTANGLE_NV: - params[0] = xglActiveTextureBinding (pname); - break; - case GL_MAX_TEXTURE_UNITS_ARB: - params[0] = cctx->maxTexUnits; - break; - default: - glGetDoublev (pname, params); - } -} - -#define INT_TO_FLOAT(I) ((GLfloat) (I)) -#define ENUM_TO_FLOAT(E) ((GLfloat) (E)) -#define BOOLEAN_TO_FLOAT(B) ((B) ? 1.0F : 0.0F) - -static void -xglGetFloatv (GLenum pname, - GLfloat *params) -{ - switch (pname) { - case GL_CURRENT_RASTER_POSITION: - glGetFloatv (GL_CURRENT_RASTER_POSITION, params); - - params[0] -= (GLfloat) cctx->drawXoff; - params[1] -= (GLfloat) cctx->drawYoff; - break; - case GL_DOUBLEBUFFER: - params[0] = BOOLEAN_TO_FLOAT (cctx->doubleBuffer); - break; - case GL_DEPTH_BITS: - params[0] = INT_TO_FLOAT (cctx->depthBits); - break; - case GL_STENCIL_BITS: - params[0] = INT_TO_FLOAT (cctx->stencilBits); - break; - case GL_DRAW_BUFFER: - params[0] = ENUM_TO_FLOAT (cctx->attrib.drawBuffer); - break; - case GL_READ_BUFFER: - params[0] = ENUM_TO_FLOAT (cctx->attrib.readBuffer); - break; - case GL_SCISSOR_BOX: - params[0] = cctx->attrib.scissor.x; - params[1] = cctx->attrib.scissor.y; - params[2] = cctx->attrib.scissor.width; - params[3] = cctx->attrib.scissor.height; - break; - case GL_SCISSOR_TEST: - params[0] = BOOLEAN_TO_FLOAT (cctx->attrib.scissorTest); - break; - case GL_VIEWPORT: - params[0] = cctx->attrib.viewport.x; - params[1] = cctx->attrib.viewport.y; - params[2] = cctx->attrib.viewport.width; - params[3] = cctx->attrib.viewport.height; - break; - case GL_TEXTURE_BINDING_1D: - case GL_TEXTURE_BINDING_2D: - case GL_TEXTURE_BINDING_3D: - case GL_TEXTURE_RECTANGLE_NV: - params[0] = xglActiveTextureBinding (pname); - break; - case GL_MAX_TEXTURE_UNITS_ARB: - params[0] = cctx->maxTexUnits; - break; - default: - glGetFloatv (pname, params); - } -} - -#define ENUM_TO_INT(E) ((GLint) (E)) -#define BOOLEAN_TO_INT(B) ((GLint) (B)) - -static void -xglGetIntegerv (GLenum pname, - GLint *params) -{ - switch (pname) { - case GL_CURRENT_RASTER_POSITION: - glGetIntegerv (GL_CURRENT_RASTER_POSITION, params); - - params[0] -= (GLint) cctx->drawXoff; - params[1] -= (GLint) cctx->drawYoff; - break; - case GL_DOUBLEBUFFER: - params[0] = BOOLEAN_TO_INT (cctx->doubleBuffer); - break; - case GL_DEPTH_BITS: - params[0] = cctx->depthBits; - break; - case GL_STENCIL_BITS: - params[0] = cctx->stencilBits; - break; - case GL_DRAW_BUFFER: - params[0] = ENUM_TO_INT (cctx->attrib.drawBuffer); - break; - case GL_READ_BUFFER: - params[0] = ENUM_TO_INT (cctx->attrib.readBuffer); - break; - case GL_SCISSOR_BOX: - params[0] = cctx->attrib.scissor.x; - params[1] = cctx->attrib.scissor.y; - params[2] = cctx->attrib.scissor.width; - params[3] = cctx->attrib.scissor.height; - break; - case GL_SCISSOR_TEST: - params[0] = BOOLEAN_TO_INT (cctx->attrib.scissorTest); - break; - case GL_VIEWPORT: - params[0] = cctx->attrib.viewport.x; - params[1] = cctx->attrib.viewport.y; - params[2] = cctx->attrib.viewport.width; - params[3] = cctx->attrib.viewport.height; - break; - case GL_TEXTURE_BINDING_1D: - case GL_TEXTURE_BINDING_2D: - case GL_TEXTURE_BINDING_3D: - case GL_TEXTURE_RECTANGLE_NV: - params[0] = xglActiveTextureBinding (pname); - break; - case GL_MAX_TEXTURE_UNITS_ARB: - params[0] = cctx->maxTexUnits; - break; - default: - glGetIntegerv (pname, params); - } -} - -static GLboolean -xglIsEnabled (GLenum cap) -{ - switch (cap) { - case GL_SCISSOR_TEST: - return cctx->attrib.scissorTest; - default: - return glIsEnabled (cap); - } -} - -static GLenum -xglGetError (void) -{ - GLenum error = cctx->errorValue; - - if (error != GL_NO_ERROR) - { - cctx->errorValue = GL_NO_ERROR; - return error; - } - - return glGetError (); -} - -static const GLubyte * -xglGetString (GLenum name) -{ - switch (name) { - case GL_VERSION: - if (!cctx->versionString) - { - static char *version = "1.2 (%s)"; - char *nativeVersion = (char *) glGetString (GL_VERSION); - - cctx->versionString = xalloc (strlen (version) + - strlen (nativeVersion)); - if (cctx->versionString) - sprintf (cctx->versionString, version, nativeVersion); - } - return (GLubyte *) cctx->versionString; - default: - return glGetString (name); - } -} - -static void -xglGenTextures (GLsizei n, - GLuint *textures) -{ - xglTexObjPtr pTexObj; - GLuint name; - - name = xglHashFindFreeKeyBlock (cctx->shared->texObjects, n); - - glGenTextures (n, textures); - - while (n--) - { - pTexObj = xalloc (sizeof (xglTexObjRec)); - if (pTexObj) - { - pTexObj->key = name; - pTexObj->name = *textures; - pTexObj->pPixmap = NULL; - pTexObj->refcnt = 1; - - xglHashInsert (cctx->shared->texObjects, name, pTexObj); - } - else - { - xglRecordError (GL_OUT_OF_MEMORY); - } - - *textures++ = name++; - } -} - -static void -xglBindTextureProc (xglGLOpPtr pOp) -{ - xglTexObjPtr *ppTexObj; - - switch (pOp->u.bind_texture.target) { - case GL_TEXTURE_1D: - ppTexObj = &cctx->attrib.texUnits[cctx->activeTexUnit].p1D; - break; - case GL_TEXTURE_2D: - ppTexObj = &cctx->attrib.texUnits[cctx->activeTexUnit].p2D; - break; - case GL_TEXTURE_3D: - ppTexObj = &cctx->attrib.texUnits[cctx->activeTexUnit].p3D; - break; - case GL_TEXTURE_RECTANGLE_NV: - ppTexObj = &cctx->attrib.texUnits[cctx->activeTexUnit].pRect; - break; - case GL_TEXTURE_CUBE_MAP_ARB: - ppTexObj = &cctx->attrib.texUnits[cctx->activeTexUnit].pCubeMap; - break; - default: - xglRecordError (GL_INVALID_ENUM); - return; - } - - if (pOp->u.bind_texture.texture) - { - xglTexObjPtr pTexObj; - - pTexObj = (xglTexObjPtr) xglHashLookup (cctx->shared->texObjects, - pOp->u.bind_texture.texture); - if (!pTexObj) - { - pTexObj = xalloc (sizeof (xglTexObjRec)); - if (!pTexObj) - { - xglRecordError (GL_OUT_OF_MEMORY); - return; - } - - pTexObj->key = pOp->u.bind_texture.texture; - pTexObj->pPixmap = NULL; - pTexObj->refcnt = 1; - - glGenTextures (1, &pTexObj->name); - - xglHashInsert (cctx->shared->texObjects, - pOp->u.bind_texture.texture, - pTexObj); - } - - xglRefTexObj (pTexObj); - xglUnrefTexObj (*ppTexObj); - *ppTexObj = pTexObj; - - glBindTexture (pOp->u.bind_texture.target, pTexObj->name); - } - else - { - xglUnrefTexObj (*ppTexObj); - *ppTexObj = NULL; - - glBindTexture (pOp->u.bind_texture.target, 0); - } -} - -static void -xglBindTexture (GLenum target, - GLuint texture) -{ - xglGLOpRec gl; - - gl.glProc = xglBindTextureProc; - - gl.u.bind_texture.target = target; - gl.u.bind_texture.texture = texture; - - xglGLOp (&gl); -} - -static void -xglSetupTextures (void) -{ - xglGLContextPtr pContext = cctx; - xglTexUnitPtr pTexUnit; - xglTexObjPtr pTexObj[XGL_MAX_TEXTURE_UNITS]; - int i, activeTexUnit; - - for (i = 0; i < pContext->maxTexUnits; i++) - { - pTexObj[i] = NULL; - - pTexUnit = &pContext->attrib.texUnits[i]; - if (pTexUnit->enabled) - { - if (pTexUnit->enabled & XGL_TEXTURE_RECTANGLE_BIT) - pTexObj[i] = pTexUnit->pRect; - else if (pTexUnit->enabled & XGL_TEXTURE_2D_BIT) - pTexObj[i] = pTexUnit->p2D; - - if (pTexObj[i] && pTexObj[i]->pPixmap) - { - if (!xglSyncSurface (&pTexObj[i]->pPixmap->drawable)) - pTexObj[i] = NULL; - } - else - pTexObj[i] = NULL; - } - } - - if (pContext != cctx) - { - XGL_SCREEN_PRIV (pContext->pDrawBuffer->pGC->pScreen); - - glitz_drawable_finish (pScreenPriv->drawable); - - xglSetCurrentContext (pContext); - } - - activeTexUnit = cctx->activeTexUnit; - for (i = 0; i < pContext->maxTexUnits; i++) - { - if (pTexObj[i]) - { - XGL_PIXMAP_PRIV (pTexObj[i]->pPixmap); - - activeTexUnit = GL_TEXTURE0_ARB + i; - cctx->ActiveTextureARB (activeTexUnit); - glitz_context_bind_texture (cctx->context, pPixmapPriv->surface); - } - } - - if (cctx->activeTexUnit != activeTexUnit) - cctx->ActiveTextureARB (cctx->activeTexUnit); -} - -static GLboolean -xglAreTexturesResident (GLsizei n, - const GLuint *textures, - GLboolean *residences) -{ - GLboolean allResident = GL_TRUE; - int i, j; - - if (n < 0) - { - xglRecordError (GL_INVALID_VALUE); - return GL_FALSE; - } - - if (!textures || !residences) - return GL_FALSE; - - for (i = 0; i < n; i++) - { - xglTexObjPtr pTexObj; - GLboolean resident; - - if (textures[i] == 0) - { - xglRecordError (GL_INVALID_VALUE); - return GL_FALSE; - } - - pTexObj = (xglTexObjPtr) xglHashLookup (cctx->shared->texObjects, - textures[i]); - if (!pTexObj) - { - xglRecordError (GL_INVALID_VALUE); - return GL_FALSE; - } - - if (pTexObj->name == 0 || - glAreTexturesResident (1, &pTexObj->name, &resident)) - { - if (!allResident) - residences[i] = GL_TRUE; - } - else - { - if (allResident) - { - allResident = GL_FALSE; - - for (j = 0; j < i; j++) - residences[j] = GL_TRUE; - } - residences[i] = GL_FALSE; - } - } - - return allResident; -} - -static void -xglDeleteTextures (GLsizei n, - const GLuint *textures) -{ - xglTexObjPtr pTexObj; - - while (n--) - { - pTexObj = (xglTexObjPtr) xglHashLookup (cctx->shared->texObjects, - *textures); - if (pTexObj) - { - xglDeleteTexObj (pTexObj); - xglUnrefTexObj (pTexObj); - xglHashRemove (cctx->shared->texObjects, *textures); - } - textures++; - } -} - -static GLboolean -xglIsTexture (GLuint texture) -{ - xglTexObjPtr pTexObj; - - if (!texture) - return GL_FALSE; - - pTexObj = (xglTexObjPtr) xglHashLookup (cctx->shared->texObjects, texture); - if (pTexObj) - return GL_TRUE; - - return GL_FALSE; -} - -static void -xglPrioritizeTextures (GLsizei n, - const GLuint *textures, - const GLclampf *priorities) -{ - xglTexObjPtr pTexObj; - int i; - - if (n < 0) - { - xglRecordError (GL_INVALID_VALUE); - return; - } - - if (!priorities) - return; - - for (i = 0; i < n; i++) - { - if (textures[i] <= 0) - continue; - - pTexObj = (xglTexObjPtr) xglHashLookup (cctx->shared->texObjects, - textures[i]); - if (pTexObj && pTexObj->name) - glPrioritizeTextures (1, &pTexObj->name, &priorities[i]); - } -} - -static void -xglTexParameterfvProc (xglGLOpPtr pOp) -{ - xglTexObjPtr pTexObj; - - glTexParameterfv (pOp->u.tex_parameter_fv.target, - pOp->u.tex_parameter_fv.pname, - pOp->u.tex_parameter_fv.params); - - switch (pOp->u.tex_parameter_fv.target) { - case GL_TEXTURE_2D: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; - break; - case GL_TEXTURE_RECTANGLE_NV: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; - break; - default: - pTexObj = NULL; - break; - } - - if (pTexObj && pTexObj->pPixmap) - { - XGL_PIXMAP_PRIV (pTexObj->pPixmap); - - /* texture parameters should eventually go into a - glitz_texture_object_t */ - glitz_context_bind_texture (cctx->context, pPixmapPriv->surface); - - glTexParameterfv (pOp->u.tex_parameter_fv.target, - pOp->u.tex_parameter_fv.pname, - pOp->u.tex_parameter_fv.params); - - glBindTexture (pOp->u.tex_parameter_fv.target, pTexObj->name); - } -} - -static void -xglTexParameterfv (GLenum target, - GLenum pname, - const GLfloat *params) -{ - xglGLOpRec gl; - - gl.glProc = xglTexParameterfvProc; - - gl.u.tex_parameter_fv.target = target; - gl.u.tex_parameter_fv.pname = pname; - - switch (pname) { - case GL_TEXTURE_BORDER_COLOR: - gl.u.tex_parameter_fv.params[3] = params[3]; - gl.u.tex_parameter_fv.params[2] = params[2]; - gl.u.tex_parameter_fv.params[1] = params[1]; - /* fall-through */ - default: - gl.u.tex_parameter_fv.params[0] = params[0]; - break; - } - - xglGLOp (&gl); -} - -static void -xglTexParameterivProc (xglGLOpPtr pOp) -{ - xglTexObjPtr pTexObj; - - glTexParameteriv (pOp->u.tex_parameter_iv.target, - pOp->u.tex_parameter_iv.pname, - pOp->u.tex_parameter_iv.params); - - switch (pOp->u.tex_parameter_iv.target) { - case GL_TEXTURE_2D: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; - break; - case GL_TEXTURE_RECTANGLE_NV: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; - break; - default: - pTexObj = NULL; - break; - } - - if (pTexObj && pTexObj->pPixmap) - { - XGL_PIXMAP_PRIV (pTexObj->pPixmap); - - /* texture parameters should eventually go into a - glitz_texture_object_t */ - glitz_context_bind_texture (cctx->context, pPixmapPriv->surface); - - glTexParameteriv (pOp->u.tex_parameter_iv.target, - pOp->u.tex_parameter_iv.pname, - pOp->u.tex_parameter_iv.params); - - glBindTexture (pOp->u.tex_parameter_iv.target, pTexObj->name); - } -} - -static void -xglTexParameteriv (GLenum target, - GLenum pname, - const GLint *params) -{ - xglGLOpRec gl; - - gl.glProc = xglTexParameterivProc; - - gl.u.tex_parameter_iv.target = target; - gl.u.tex_parameter_iv.pname = pname; - - switch (pname) { - case GL_TEXTURE_BORDER_COLOR: - gl.u.tex_parameter_iv.params[3] = params[3]; - gl.u.tex_parameter_iv.params[2] = params[2]; - gl.u.tex_parameter_iv.params[1] = params[1]; - /* fall-through */ - default: - gl.u.tex_parameter_iv.params[0] = params[0]; - break; - } - - xglGLOp (&gl); -} - -static void -xglTexParameterf (GLenum target, - GLenum pname, - GLfloat param) -{ - xglTexParameterfv (target, pname, (const GLfloat *) ¶m); -} - -static void -xglTexParameteri (GLenum target, - GLenum pname, - GLint param) -{ - xglTexParameteriv (target, pname, (const GLint *) ¶m); -} - -static void -xglGetTexLevelParameterfv (GLenum target, - GLint level, - GLenum pname, - GLfloat *params) -{ - xglTexObjPtr pTexObj; - - switch (target) { - case GL_TEXTURE_2D: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; - break; - case GL_TEXTURE_RECTANGLE_NV: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; - break; - default: - pTexObj = NULL; - break; - } - - if (pTexObj && pTexObj->pPixmap) - { - XGL_PIXMAP_PRIV (pTexObj->pPixmap); - - glitz_context_bind_texture (cctx->context, pPixmapPriv->surface); - - glGetTexLevelParameterfv (target, level, pname, params); - - glBindTexture (target, pTexObj->name); - } - else - glGetTexLevelParameterfv (target, level, pname, params); -} - -static void -xglGetTexLevelParameteriv (GLenum target, - GLint level, - GLenum pname, - GLint *params) -{ - xglTexObjPtr pTexObj; - - switch (target) { - case GL_TEXTURE_2D: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; - break; - case GL_TEXTURE_RECTANGLE_NV: - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; - break; - default: - pTexObj = NULL; - break; - } - - if (pTexObj && pTexObj->pPixmap) - { - XGL_PIXMAP_PRIV (pTexObj->pPixmap); - - glitz_context_bind_texture (cctx->context, pPixmapPriv->surface); - - glGetTexLevelParameteriv (target, level, pname, params); - - glBindTexture (target, pTexObj->name); - } - else - glGetTexLevelParameteriv (target, level, pname, params); -} - -static GLuint -xglGenLists (GLsizei range) -{ - xglDisplayListPtr pDisplayList; - GLuint first, name; - - first = xglHashFindFreeKeyBlock (cctx->shared->displayLists, range); - - name = first; - for (name = first; range--; name++) - { - pDisplayList = xglCreateList (); - if (pDisplayList) - { - xglHashInsert (cctx->shared->displayLists, name, pDisplayList); - } - else - { - xglRecordError (GL_OUT_OF_MEMORY); - } - } - - return first; -} - -static void -xglNewList (GLuint list, - GLenum mode) -{ - if (!list) - { - xglRecordError (GL_INVALID_VALUE); - return; - } - - if (cctx->list) - { - xglRecordError (GL_INVALID_OPERATION); - return; - } - - cctx->pList = xglCreateList (); - if (!cctx->pList) - { - xglRecordError (GL_OUT_OF_MEMORY); - return; - } - - cctx->list = list; - cctx->listMode = mode; - - xglStartList (XGL_LIST_OP_CALLS, mode); -} - -static void -xglEndList (void) -{ - xglDisplayListPtr pDisplayList; - - if (!cctx->list) - { - xglRecordError (GL_INVALID_OPERATION); - return; - } - - glEndList (); - - pDisplayList = (xglDisplayListPtr) - xglHashLookup (cctx->shared->displayLists, cctx->list); - if (pDisplayList) - { - xglHashRemove (cctx->shared->displayLists, cctx->list); - xglDestroyList (pDisplayList); - } - - xglHashInsert (cctx->shared->displayLists, cctx->list, cctx->pList); - - cctx->list = 0; -} - -static void -xglDrawList (GLuint list) -{ - RegionRec region; - BoxRec scissor, box; - BoxPtr pBox; - int nBox; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - while (nBox--) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - if (box.x1 < box.x2 && box.y1 < box.y2) - { - XGL_GLX_SET_SCISSOR_BOX (&box); - - glCallList (list); - - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - } - } -} - -static void -xglCallDisplayList (GLuint list, - int nesting) -{ - if (nesting > cctx->maxListNesting) - return; - - if (!list) - { - xglRecordError (GL_INVALID_VALUE); - return; - } - - if (cctx->list) - { - if (!xglResizeList (cctx->pList, cctx->pList->nOp + 1)) - { - xglRecordError (GL_OUT_OF_MEMORY); - return; - } - - cctx->pList->pOp[cctx->pList->nOp].type = XGL_LIST_OP_LIST; - cctx->pList->pOp[cctx->pList->nOp].u.list = list; - cctx->pList->nOp++; - } - else - { - xglDisplayListPtr pDisplayList; - - pDisplayList = (xglDisplayListPtr) - xglHashLookup (cctx->shared->displayLists, list); - if (pDisplayList) - { - xglListOpPtr pOp = pDisplayList->pOp; - int nOp = pDisplayList->nOp; - - while (nOp--) - { - switch (pOp->type) { - case XGL_LIST_OP_CALLS: - glCallList (pOp->u.list); - break; - case XGL_LIST_OP_DRAW: - xglDrawList (pOp->u.list); - break; - case XGL_LIST_OP_GL: - (*pOp->u.gl->glProc) (pOp->u.gl); - break; - case XGL_LIST_OP_LIST: - xglCallDisplayList (pOp->u.list, nesting + 1); - break; - } - - pOp++; - } - } - } -} - -static void -xglCallList (GLuint list) -{ - xglCallDisplayList (list, 1); -} - -static void -xglCallLists (GLsizei n, - GLenum type, - const GLvoid *lists) -{ - GLuint list; - GLint base, i; - - glGetIntegerv (GL_LIST_BASE, &base); - - for (i = 0; i < n; i++) - { - switch (type) { - case GL_BYTE: - list = (GLuint) *(((GLbyte *) lists) + n); - break; - case GL_UNSIGNED_BYTE: - list = (GLuint) *(((GLubyte *) lists) + n); - break; - case GL_SHORT: - list = (GLuint) *(((GLshort *) lists) + n); - break; - case GL_UNSIGNED_SHORT: - list = (GLuint) *(((GLushort *) lists) + n); - break; - case GL_INT: - list = (GLuint) *(((GLint *) lists) + n); - break; - case GL_UNSIGNED_INT: - list = (GLuint) *(((GLuint *) lists) + n); - break; - case GL_FLOAT: - list = (GLuint) *(((GLfloat *) lists) + n); - break; - case GL_2_BYTES: - { - GLubyte *ubptr = ((GLubyte *) lists) + 2 * n; - list = (GLuint) *ubptr * 256 + (GLuint) *(ubptr + 1); - } break; - case GL_3_BYTES: - { - GLubyte *ubptr = ((GLubyte *) lists) + 3 * n; - list = (GLuint) * ubptr * 65536 - + (GLuint) * (ubptr + 1) * 256 - + (GLuint) * (ubptr + 2); - } break; - case GL_4_BYTES: - { - GLubyte *ubptr = ((GLubyte *) lists) + 4 * n; - list = (GLuint) * ubptr * 16777216 - + (GLuint) * (ubptr + 1) * 65536 - + (GLuint) * (ubptr + 2) * 256 - + (GLuint) * (ubptr + 3); - } break; - default: - xglRecordError (GL_INVALID_ENUM); - return; - } - - xglCallDisplayList (base + list, 1); - } -} - -static void -xglDeleteLists (GLuint list, - GLsizei range) -{ - xglDisplayListPtr pDisplayList; - GLint i; - - if (range < 0) - { - xglRecordError (GL_INVALID_VALUE); - return; - } - - for (i = 0; i < range; i++) - { - pDisplayList = (xglDisplayListPtr) - xglHashLookup (cctx->shared->displayLists, list + i); - if (pDisplayList) - { - xglHashRemove (cctx->shared->displayLists, list + i); - xglDestroyList (pDisplayList); - } - } -} - -static GLboolean -xglIsList (GLuint list) -{ - xglDisplayListPtr pDisplayList; - - if (!list) - return GL_FALSE; - - pDisplayList = (xglDisplayListPtr) - xglHashLookup (cctx->shared->displayLists, list); - if (pDisplayList) - return GL_TRUE; - - return GL_FALSE; -} - -static void -xglFlush (void) -{ - glFlush (); - - if (cctx->pDrawBuffer->pDrawable) - { - xglGLBufferPtr pBuffer = cctx->pDrawBuffer; - - if (REGION_NOTEMPTY (pBuffer->pDrawable->pScreen, &pBuffer->damage)) - { - DamageDamageRegion (pBuffer->pDrawable, &pBuffer->damage); - REGION_EMPTY (pBuffer->pDrawable->pScreen, &pBuffer->damage); - } - } -} - -static void -xglFinish (void) -{ - glFinish (); - - if (cctx->pDrawBuffer->pDrawable) - { - xglGLBufferPtr pBuffer = cctx->pDrawBuffer; - - if (REGION_NOTEMPTY (pBuffer->pDrawable->pScreen, &pBuffer->damage)) - { - DamageDamageRegion (pBuffer->pDrawable, &pBuffer->damage); - REGION_EMPTY (pBuffer->pDrawable->pScreen, &pBuffer->damage); - } - } -} - -static void -xglClear (GLbitfield mask) -{ - GLenum mode; - - if (cctx->list) - { - glEndList (); - xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); - glClear (mask); - glEndList (); - - mode = cctx->listMode; - } - else - mode = GL_COMPILE_AND_EXECUTE; - - if (mode == GL_COMPILE_AND_EXECUTE) - { - RegionRec region; - BoxRec scissor, box; - BoxPtr pBox; - int nBox; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - while (nBox--) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - if (box.x1 < box.x2 && box.y1 < box.y2) - { - XGL_GLX_SET_SCISSOR_BOX (&box); - - glClear (mask); - - if (mask & GL_COLOR_BUFFER_BIT) - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - } - } - } - - if (cctx->list) - xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); -} - -static void -xglAccum (GLenum op, - GLfloat value) -{ - if (op == GL_RETURN) - { - GLenum listMode; - - if (cctx->list) - { - glEndList (); - xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); - glAccum (GL_RETURN, value); - glEndList (); - - listMode = cctx->listMode; - } - else - listMode = GL_COMPILE_AND_EXECUTE; - - if (listMode == GL_COMPILE_AND_EXECUTE) - { - RegionRec region; - BoxRec scissor, box; - BoxPtr pBox; - int nBox; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - while (nBox--) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - if (box.x1 < box.x2 && box.y1 < box.y2) - { - XGL_GLX_SET_SCISSOR_BOX (&box); - - glAccum (GL_RETURN, value); - - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - } - } - } - - if (cctx->list) - xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); - } - else - glAccum (op, value); -} - -static void -xglDrawArrays (GLenum mode, - GLint first, - GLsizei count) -{ - GLenum listMode; - - if (cctx->list) - { - glEndList (); - xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); - glDrawArrays (mode, first, count); - glEndList (); - - listMode = cctx->listMode; - } - else - listMode = GL_COMPILE_AND_EXECUTE; - - if (listMode == GL_COMPILE_AND_EXECUTE) - { - RegionRec region; - BoxRec scissor, box; - BoxPtr pBox; - int nBox; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - while (nBox--) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - if (box.x1 < box.x2 && box.y1 < box.y2) - { - XGL_GLX_SET_SCISSOR_BOX (&box); - - glDrawArrays (mode, first, count); - - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - } - } - } - - if (cctx->list) - xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); -} - -static void -xglDrawElements (GLenum mode, - GLsizei count, - GLenum type, - const GLvoid *indices) -{ - GLenum listMode; - - if (cctx->list) - { - glEndList (); - xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); - glDrawElements (mode, count, type, indices); - glEndList (); - - listMode = cctx->listMode; - } - else - listMode = GL_COMPILE_AND_EXECUTE; - - if (listMode == GL_COMPILE_AND_EXECUTE) - { - RegionRec region; - BoxRec scissor, box; - BoxPtr pBox; - int nBox; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - while (nBox--) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - if (box.x1 < box.x2 && box.y1 < box.y2) - { - XGL_GLX_SET_SCISSOR_BOX (&box); - - glDrawElements (mode, count, type, indices); - - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - } - } - } - - if (cctx->list) - xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); -} - -static void -xglDrawPixels (GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - const GLvoid *pixels) -{ - GLenum listMode; - - if (cctx->list) - { - glEndList (); - xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); - glDrawPixels (width, height, format, type, pixels); - glEndList (); - - listMode = cctx->listMode; - } - else - listMode = GL_COMPILE_AND_EXECUTE; - - if (listMode == GL_COMPILE_AND_EXECUTE) - { - RegionRec region; - BoxRec scissor, box; - BoxPtr pBox; - int nBox; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - while (nBox--) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - if (box.x1 < box.x2 && box.y1 < box.y2) - { - XGL_GLX_SET_SCISSOR_BOX (&box); - - glDrawPixels (width, height, format, type, pixels); - - if (format != GL_STENCIL_INDEX) - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - } - } - } - - if (cctx->list) - xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); -} - -static void -xglBitmap (GLsizei width, - GLsizei height, - GLfloat xorig, - GLfloat yorig, - GLfloat xmove, - GLfloat ymove, - const GLubyte *bitmap) -{ - GLenum listMode; - - if (cctx->list) - { - glEndList (); - xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); - glBitmap (width, height, xorig, yorig, 0, 0, bitmap); - glEndList (); - - listMode = cctx->listMode; - } - else - listMode = GL_COMPILE_AND_EXECUTE; - - if (listMode == GL_COMPILE_AND_EXECUTE && width && height) - { - RegionRec region; - BoxRec scissor, box; - BoxPtr pBox; - int nBox; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - while (nBox--) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - if (box.x1 < box.x2 && box.y1 < box.y2) - { - XGL_GLX_SET_SCISSOR_BOX (&box); - - glBitmap (width, height, xorig, yorig, 0, 0, bitmap); - - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - } - } - } - - if (cctx->list) - xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); - - glBitmap (0, 0, 0, 0, xmove, ymove, NULL); -} - -static void -xglRectdv (const GLdouble *v1, - const GLdouble *v2) -{ - GLenum listMode; - - if (cctx->list) - { - glEndList (); - xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); - glRectdv (v1, v2); - glEndList (); - - listMode = cctx->listMode; - } - else - listMode = GL_COMPILE_AND_EXECUTE; - - if (listMode == GL_COMPILE_AND_EXECUTE) - { - RegionRec region; - BoxRec scissor, box; - BoxPtr pBox; - int nBox; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - while (nBox--) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - if (box.x1 < box.x2 && box.y1 < box.y2) - { - XGL_GLX_SET_SCISSOR_BOX (&box); - - glRectdv (v1, v2); - - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - } - } - } - - if (cctx->list) - xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); -} - -static void -xglRectfv (const GLfloat *v1, - const GLfloat *v2) -{ - GLdouble dv1[2]; - GLdouble dv2[2]; - - dv1[0] = (GLdouble) v1[0]; - dv1[1] = (GLdouble) v1[1]; - dv2[0] = (GLdouble) v2[0]; - dv2[1] = (GLdouble) v2[1]; - - xglRectdv (dv1, dv2); -} - -static void -xglRectiv (const GLint *v1, - const GLint *v2) -{ - GLdouble dv1[2]; - GLdouble dv2[2]; - - dv1[0] = (GLdouble) v1[0]; - dv1[1] = (GLdouble) v1[1]; - dv2[0] = (GLdouble) v2[0]; - dv2[1] = (GLdouble) v2[1]; - - xglRectdv (dv1, dv2); -} - -static void -xglRectsv (const GLshort *v1, - const GLshort *v2) -{ - GLdouble dv1[2]; - GLdouble dv2[2]; - - dv1[0] = (GLdouble) v1[0]; - dv1[1] = (GLdouble) v1[1]; - dv2[0] = (GLdouble) v2[0]; - dv2[1] = (GLdouble) v2[1]; - - xglRectdv (dv1, dv2); -} - -static void -xglBegin (GLenum mode) -{ - if (cctx->list) - { - glEndList (); - xglStartList (XGL_LIST_OP_DRAW, GL_COMPILE); - } - else - { - BoxRec scissor; - BoxPtr pBox; - int nBox; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - if (nBox == 1) - { - BoxRec box = *pBox; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - XGL_GLX_SET_SCISSOR_BOX (&box); - } - else - { - if (!cctx->groupList) - cctx->groupList = glGenLists (1); - - glNewList (cctx->groupList, GL_COMPILE); - } - } - - glBegin (mode); -} - -static void -xglEnd (void) -{ - glEnd (); - - if (!cctx->list || cctx->listMode == GL_COMPILE_AND_EXECUTE) - { - RegionRec region; - BoxRec scissor, box; - BoxPtr pBox; - int nBox; - GLuint list; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - if (cctx->list) - { - list = cctx->pList->pOp[cctx->pList->nOp - 1].u.list; - } - else - { - if (nBox == 1) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - return; - } - - list = cctx->groupList; - } - - glEndList (); - - while (nBox--) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - if (box.x1 < box.x2 && box.y1 < box.y2) - { - XGL_GLX_SET_SCISSOR_BOX (&box); - - glCallList (list); - - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - } - } - } - - if (cctx->list) - xglStartList (XGL_LIST_OP_CALLS, cctx->listMode); -} - -static void -xglCopyPixelsProc (xglGLOpPtr pOp) -{ - RegionRec region; - BoxRec scissor, box; - BoxPtr pBox; - int nBox; - - XGL_GLX_DRAW_PROLOGUE (pBox, nBox, &scissor); - - while (nBox--) - { - box = *pBox++; - - if (cctx->attrib.scissorTest) - XGL_GLX_INTERSECT_BOX (&box, &scissor); - - if (box.x1 < box.x2 && box.y1 < box.y2) - { - XGL_GLX_SET_SCISSOR_BOX (&box); - - glCopyPixels (pOp->u.copy_pixels.x + cctx->pReadBuffer->xOff, - pOp->u.copy_pixels.y + cctx->pReadBuffer->yOff, - pOp->u.copy_pixels.width, - pOp->u.copy_pixels.height, - pOp->u.copy_pixels.type); - - if (pOp->u.copy_pixels.type == GL_COLOR) - XGL_GLX_DRAW_DAMAGE (&box, ®ion); - } - } -} - -static void -xglCopyPixels (GLint x, - GLint y, - GLsizei width, - GLsizei height, - GLenum type) -{ - xglGLOpRec gl; - - gl.glProc = xglCopyPixelsProc; - - gl.u.copy_pixels.x = x; - gl.u.copy_pixels.y = y; - gl.u.copy_pixels.width = width; - gl.u.copy_pixels.height = height; - gl.u.copy_pixels.type = type; - - xglGLOp (&gl); -} - -static void -xglReadPixels (GLint x, - GLint y, - GLsizei width, - GLsizei height, - GLenum format, - GLenum type, - GLvoid *pixels) -{ - glReadPixels (x + cctx->pReadBuffer->xOff, - y + cctx->pReadBuffer->yOff, - width, height, format, type, pixels); -} - -static void -xglCopyTexImage1DProc (xglGLOpPtr pOp) -{ - glCopyTexImage1D (pOp->u.copy_tex_image_1d.target, - pOp->u.copy_tex_image_1d.level, - pOp->u.copy_tex_image_1d.internalformat, - pOp->u.copy_tex_image_1d.x + cctx->pReadBuffer->xOff, - pOp->u.copy_tex_image_1d.y + cctx->pReadBuffer->yOff, - pOp->u.copy_tex_image_1d.width, - pOp->u.copy_tex_image_1d.border); -} - -static void -xglCopyTexImage1D (GLenum target, - GLint level, - GLenum internalformat, - GLint x, - GLint y, - GLsizei width, - GLint border) -{ - xglGLOpRec gl; - - gl.glProc = xglCopyTexImage1DProc; - - gl.u.copy_tex_image_1d.target = target; - gl.u.copy_tex_image_1d.level = level; - gl.u.copy_tex_image_1d.internalformat = internalformat; - gl.u.copy_tex_image_1d.x = x; - gl.u.copy_tex_image_1d.y = y; - gl.u.copy_tex_image_1d.width = width; - gl.u.copy_tex_image_1d.border = border; - - xglGLOp (&gl); -} - -static void -xglCopyTexImage2DProc (xglGLOpPtr pOp) -{ - glCopyTexImage2D (pOp->u.copy_tex_image_2d.target, - pOp->u.copy_tex_image_2d.level, - pOp->u.copy_tex_image_2d.internalformat, - pOp->u.copy_tex_image_2d.x + cctx->pReadBuffer->xOff, - pOp->u.copy_tex_image_2d.y + cctx->pReadBuffer->yOff, - pOp->u.copy_tex_image_2d.width, - pOp->u.copy_tex_image_2d.height, - pOp->u.copy_tex_image_2d.border); -} - -static void -xglCopyTexImage2D (GLenum target, - GLint level, - GLenum internalformat, - GLint x, - GLint y, - GLsizei width, - GLsizei height, - GLint border) -{ - xglGLOpRec gl; - - gl.glProc = xglCopyTexImage2DProc; - - gl.u.copy_tex_image_2d.target = target; - gl.u.copy_tex_image_2d.level = level; - gl.u.copy_tex_image_2d.internalformat = internalformat; - gl.u.copy_tex_image_2d.x = x; - gl.u.copy_tex_image_2d.y = y; - gl.u.copy_tex_image_2d.width = width; - gl.u.copy_tex_image_2d.height = height; - gl.u.copy_tex_image_2d.border = border; - - xglGLOp (&gl); -} - -static void -xglCopyTexSubImage1DProc (xglGLOpPtr pOp) -{ - glCopyTexSubImage1D (pOp->u.copy_tex_sub_image_1d.target, - pOp->u.copy_tex_sub_image_1d.level, - pOp->u.copy_tex_sub_image_1d.xoffset, - pOp->u.copy_tex_sub_image_1d.x + - cctx->pReadBuffer->xOff, - pOp->u.copy_tex_sub_image_1d.y + - cctx->pReadBuffer->yOff, - pOp->u.copy_tex_sub_image_1d.width); -} - -static void -xglCopyTexSubImage1D (GLenum target, - GLint level, - GLint xoffset, - GLint x, - GLint y, - GLsizei width) -{ - xglGLOpRec gl; - - gl.glProc = xglCopyTexSubImage1DProc; - - gl.u.copy_tex_sub_image_1d.target = target; - gl.u.copy_tex_sub_image_1d.level = level; - gl.u.copy_tex_sub_image_1d.xoffset = xoffset; - gl.u.copy_tex_sub_image_1d.x = x; - gl.u.copy_tex_sub_image_1d.y = y; - gl.u.copy_tex_sub_image_1d.width = width; - - xglGLOp (&gl); -} - -static void -xglCopyTexSubImage2DProc (xglGLOpPtr pOp) -{ - glCopyTexSubImage2D (pOp->u.copy_tex_sub_image_2d.target, - pOp->u.copy_tex_sub_image_2d.level, - pOp->u.copy_tex_sub_image_2d.xoffset, - pOp->u.copy_tex_sub_image_2d.yoffset, - pOp->u.copy_tex_sub_image_2d.x + - cctx->pReadBuffer->xOff, - pOp->u.copy_tex_sub_image_2d.y + - cctx->pReadBuffer->yOff, - pOp->u.copy_tex_sub_image_2d.width, - pOp->u.copy_tex_sub_image_2d.height); -} - -static void -xglCopyTexSubImage2D (GLenum target, - GLint level, - GLint xoffset, - GLint yoffset, - GLint x, - GLint y, - GLsizei width, - GLsizei height) -{ - xglGLOpRec gl; - - gl.glProc = xglCopyTexSubImage2DProc; - - gl.u.copy_tex_sub_image_2d.target = target; - gl.u.copy_tex_sub_image_2d.level = level; - gl.u.copy_tex_sub_image_2d.xoffset = xoffset; - gl.u.copy_tex_sub_image_2d.yoffset = yoffset; - gl.u.copy_tex_sub_image_2d.x = x; - gl.u.copy_tex_sub_image_2d.y = y; - gl.u.copy_tex_sub_image_2d.width = width; - gl.u.copy_tex_sub_image_2d.height = height; - - xglGLOp (&gl); -} - -static void -xglCopyColorTableProc (xglGLOpPtr pOp) -{ - glCopyColorTable (pOp->u.copy_color_table.target, - pOp->u.copy_color_table.internalformat, - pOp->u.copy_color_table.x + cctx->pReadBuffer->xOff, - pOp->u.copy_color_table.y + cctx->pReadBuffer->yOff, - pOp->u.copy_color_table.width); -} - -static void -xglCopyColorTable (GLenum target, - GLenum internalformat, - GLint x, - GLint y, - GLsizei width) -{ - xglGLOpRec gl; - - gl.glProc = xglCopyColorTableProc; - - gl.u.copy_color_table.target = target; - gl.u.copy_color_table.internalformat = internalformat; - gl.u.copy_color_table.x = x; - gl.u.copy_color_table.y = y; - gl.u.copy_color_table.width = width; - - xglGLOp (&gl); -} - -static void -xglCopyColorSubTableProc (xglGLOpPtr pOp) -{ - glCopyColorTable (pOp->u.copy_color_sub_table.target, - pOp->u.copy_color_sub_table.start, - pOp->u.copy_color_sub_table.x + cctx->pReadBuffer->xOff, - pOp->u.copy_color_sub_table.y + cctx->pReadBuffer->yOff, - pOp->u.copy_color_sub_table.width); -} - -static void -xglCopyColorSubTable (GLenum target, - GLsizei start, - GLint x, - GLint y, - GLsizei width) -{ - xglGLOpRec gl; - - gl.glProc = xglCopyColorSubTableProc; - - gl.u.copy_color_sub_table.target = target; - gl.u.copy_color_sub_table.start = start; - gl.u.copy_color_sub_table.x = x; - gl.u.copy_color_sub_table.y = y; - gl.u.copy_color_sub_table.width = width; - - xglGLOp (&gl); -} - -static void -xglCopyConvolutionFilter1DProc (xglGLOpPtr pOp) -{ - GLenum internalformat = pOp->u.copy_convolution_filter_1d.internalformat; - - glCopyConvolutionFilter1D (pOp->u.copy_convolution_filter_1d.target, - internalformat, - pOp->u.copy_convolution_filter_1d.x + - cctx->pReadBuffer->xOff, - pOp->u.copy_convolution_filter_1d.y + - cctx->pReadBuffer->yOff, - pOp->u.copy_convolution_filter_1d.width); -} - -static void -xglCopyConvolutionFilter1D (GLenum target, - GLenum internalformat, - GLint x, - GLint y, - GLsizei width) -{ - xglGLOpRec gl; - - gl.glProc = xglCopyConvolutionFilter1DProc; - - gl.u.copy_convolution_filter_1d.target = target; - gl.u.copy_convolution_filter_1d.internalformat = internalformat; - gl.u.copy_convolution_filter_1d.x = x; - gl.u.copy_convolution_filter_1d.y = y; - gl.u.copy_convolution_filter_1d.width = width; - - xglGLOp (&gl); -} - -static void -xglCopyConvolutionFilter2DProc (xglGLOpPtr pOp) -{ - GLenum internalformat = pOp->u.copy_convolution_filter_2d.internalformat; - - glCopyConvolutionFilter2D (pOp->u.copy_convolution_filter_2d.target, - internalformat, - pOp->u.copy_convolution_filter_2d.x + - cctx->pReadBuffer->xOff, - pOp->u.copy_convolution_filter_2d.y + - cctx->pReadBuffer->yOff, - pOp->u.copy_convolution_filter_2d.width, - pOp->u.copy_convolution_filter_2d.height); -} - -static void -xglCopyConvolutionFilter2D (GLenum target, - GLenum internalformat, - GLint x, - GLint y, - GLsizei width, - GLsizei height) -{ - xglGLOpRec gl; - - gl.glProc = xglCopyConvolutionFilter2DProc; - - gl.u.copy_convolution_filter_2d.target = target; - gl.u.copy_convolution_filter_2d.internalformat = internalformat; - gl.u.copy_convolution_filter_2d.x = x; - gl.u.copy_convolution_filter_2d.y = y; - gl.u.copy_convolution_filter_2d.width = width; - gl.u.copy_convolution_filter_2d.height = height; - - xglGLOp (&gl); -} - -static void -xglCopyTexSubImage3DProc (xglGLOpPtr pOp) -{ - glCopyTexSubImage3D (pOp->u.copy_tex_sub_image_3d.target, - pOp->u.copy_tex_sub_image_3d.level, - pOp->u.copy_tex_sub_image_3d.xoffset, - pOp->u.copy_tex_sub_image_3d.yoffset, - pOp->u.copy_tex_sub_image_3d.zoffset, - pOp->u.copy_tex_sub_image_3d.x + - cctx->pReadBuffer->xOff, - pOp->u.copy_tex_sub_image_3d.y + - cctx->pReadBuffer->yOff, - pOp->u.copy_tex_sub_image_3d.width, - pOp->u.copy_tex_sub_image_3d.height); -} - -static void -xglCopyTexSubImage3D (GLenum target, - GLint level, - GLint xoffset, - GLint yoffset, - GLint zoffset, - GLint x, - GLint y, - GLsizei width, - GLsizei height) -{ - xglGLOpRec gl; - - gl.glProc = xglCopyTexSubImage3DProc; - - gl.u.copy_tex_sub_image_3d.target = target; - gl.u.copy_tex_sub_image_3d.level = level; - gl.u.copy_tex_sub_image_3d.xoffset = xoffset; - gl.u.copy_tex_sub_image_3d.yoffset = yoffset; - gl.u.copy_tex_sub_image_3d.zoffset = zoffset; - gl.u.copy_tex_sub_image_3d.x = x; - gl.u.copy_tex_sub_image_3d.y = y; - gl.u.copy_tex_sub_image_3d.width = width; - gl.u.copy_tex_sub_image_3d.height = height; - - xglGLOp (&gl); -} - -__glProcTable __glNativeRenderTable = { - xglNewList, /* glNewList */ - xglEndList, /* glEndList */ - xglCallList, /* glCallList */ - xglCallLists, /* glCallLists */ - xglDeleteLists, /* glDeleteLists */ - xglGenLists, /* glGenLists */ - glListBase, - xglBegin, /* glBegin */ - xglBitmap, /* glBitmap */ - glColor3bv, - glColor3dv, - glColor3fv, - glColor3iv, - glColor3sv, - glColor3ubv, - glColor3uiv, - glColor3usv, - glColor4bv, - glColor4dv, - glColor4fv, - glColor4iv, - glColor4sv, - glColor4ubv, - glColor4uiv, - glColor4usv, - glEdgeFlagv, - xglEnd, /* glEnd */ - glIndexdv, - glIndexfv, - glIndexiv, - glIndexsv, - glNormal3bv, - glNormal3dv, - glNormal3fv, - glNormal3iv, - glNormal3sv, - glRasterPos2dv, - glRasterPos2fv, - glRasterPos2iv, - glRasterPos2sv, - glRasterPos3dv, - glRasterPos3fv, - glRasterPos3iv, - glRasterPos3sv, - glRasterPos4dv, - glRasterPos4fv, - glRasterPos4iv, - glRasterPos4sv, - xglRectdv, /* glRectdv */ - xglRectfv, /* glRectfv */ - xglRectiv, /* glRectiv */ - xglRectsv, /* glRectsv */ - glTexCoord1dv, - glTexCoord1fv, - glTexCoord1iv, - glTexCoord1sv, - glTexCoord2dv, - glTexCoord2fv, - glTexCoord2iv, - glTexCoord2sv, - glTexCoord3dv, - glTexCoord3fv, - glTexCoord3iv, - glTexCoord3sv, - glTexCoord4dv, - glTexCoord4fv, - glTexCoord4iv, - glTexCoord4sv, - glVertex2dv, - glVertex2fv, - glVertex2iv, - glVertex2sv, - glVertex3dv, - glVertex3fv, - glVertex3iv, - glVertex3sv, - glVertex4dv, - glVertex4fv, - glVertex4iv, - glVertex4sv, - glClipPlane, - glColorMaterial, - glCullFace, - glFogf, - glFogfv, - glFogi, - glFogiv, - glFrontFace, - glHint, - glLightf, - glLightfv, - glLighti, - glLightiv, - glLightModelf, - glLightModelfv, - glLightModeli, - glLightModeliv, - glLineStipple, - glLineWidth, - glMaterialf, - glMaterialfv, - glMateriali, - glMaterialiv, - glPointSize, - glPolygonMode, - glPolygonStipple, - xglScissor, /* glScissor */ - glShadeModel, - xglTexParameterf, /* glTexParameterf */ - xglTexParameterfv, /* glTexParameterfv */ - xglTexParameteri, /* glTexParameteri */ - xglTexParameteriv, /* glTexParameteriv */ - glTexImage1D, - glTexImage2D, - glTexEnvf, - glTexEnvfv, - glTexEnvi, - glTexEnviv, - glTexGend, - glTexGendv, - glTexGenf, - glTexGenfv, - glTexGeni, - glTexGeniv, - glFeedbackBuffer, - glSelectBuffer, - glRenderMode, - glInitNames, - glLoadName, - glPassThrough, - glPopName, - glPushName, - xglDrawBuffer, /* glDrawBuffer */ - xglClear, /* glClear */ - glClearAccum, - glClearIndex, - glClearColor, - glClearStencil, - glClearDepth, - glStencilMask, - glColorMask, - glDepthMask, - glIndexMask, - xglAccum, /* glAccum */ - xglDisable, /* glDisable */ - xglEnable, /* glEnable */ - xglFinish, /* glFinish */ - xglFlush, /* glFlush */ - xglPopAttrib, /* glPopAttrib */ - xglPushAttrib, /* glPushAttrib */ - glMap1d, - glMap1f, - glMap2d, - glMap2f, - glMapGrid1d, - glMapGrid1f, - glMapGrid2d, - glMapGrid2f, - glEvalCoord1dv, - glEvalCoord1fv, - glEvalCoord2dv, - glEvalCoord2fv, - glEvalMesh1, - glEvalPoint1, - glEvalMesh2, - glEvalPoint2, - glAlphaFunc, - glBlendFunc, - glLogicOp, - glStencilFunc, - glStencilOp, - glDepthFunc, - glPixelZoom, - glPixelTransferf, - glPixelTransferi, - glPixelStoref, - glPixelStorei, - glPixelMapfv, - glPixelMapuiv, - glPixelMapusv, - xglReadBuffer, /* glReadBuffer */ - xglCopyPixels, /* glCopyPixels */ - xglReadPixels, /* glReadPixels */ - xglDrawPixels, /* glDrawPixels */ - xglGetBooleanv, /* glGetBooleanv */ - glGetClipPlane, - xglGetDoublev, /* glGetDoublev */ - xglGetError, /* glGetError */ - xglGetFloatv, /* glGetFloatv */ - xglGetIntegerv, /* glGetIntegerv */ - glGetLightfv, - glGetLightiv, - glGetMapdv, - glGetMapfv, - glGetMapiv, - glGetMaterialfv, - glGetMaterialiv, - glGetPixelMapfv, - glGetPixelMapuiv, - glGetPixelMapusv, - glGetPolygonStipple, - xglGetString, /* glGetString */ - glGetTexEnvfv, - glGetTexEnviv, - glGetTexGendv, - glGetTexGenfv, - glGetTexGeniv, - glGetTexImage, - glGetTexParameterfv, - glGetTexParameteriv, - xglGetTexLevelParameterfv, /* glGetTexLevelParameterfv */ - xglGetTexLevelParameteriv, /* glGetTexLevelParameteriv */ - xglIsEnabled, /* glIsEnabled */ - xglIsList, /* glIsList */ - glDepthRange, - glFrustum, - glLoadIdentity, - glLoadMatrixf, - glLoadMatrixd, - glMatrixMode, - glMultMatrixf, - glMultMatrixd, - glOrtho, - glPopMatrix, - glPushMatrix, - glRotated, - glRotatef, - glScaled, - glScalef, - glTranslated, - glTranslatef, - xglViewport, /* glViewport */ - glArrayElement, - xglBindTexture, /* glBindTexture */ - glColorPointer, - glDisableClientState, - xglDrawArrays, /* glDrawArrays */ - xglDrawElements, /* glDrawElements */ - glEdgeFlagPointer, - glEnableClientState, - glIndexPointer, - glIndexubv, - glInterleavedArrays, - glNormalPointer, - glPolygonOffset, - glTexCoordPointer, - glVertexPointer, - xglAreTexturesResident, /* glAreTexturesResident */ - xglCopyTexImage1D, /* glCopyTexImage1D */ - xglCopyTexImage2D, /* glCopyTexImage2D */ - xglCopyTexSubImage1D, /* glCopyTexSubImage1D */ - xglCopyTexSubImage2D, /* glCopyTexSubImage2D */ - xglDeleteTextures, /* glDeleteTextures */ - xglGenTextures, /* glGenTextures */ - glGetPointerv, - xglIsTexture, /* glIsTexture */ - xglPrioritizeTextures, /* glPrioritizeTextures */ - glTexSubImage1D, - glTexSubImage2D, - glPopClientAttrib, - glPushClientAttrib, - glBlendColor, - glBlendEquation, - glColorTable, - glColorTableParameterfv, - glColorTableParameteriv, - xglCopyColorTable, /* glCopyColorTable */ - glGetColorTable, - glGetColorTableParameterfv, - glGetColorTableParameteriv, - glColorSubTable, - xglCopyColorSubTable, /* glCopyColorSubTable */ - glConvolutionFilter1D, - glConvolutionFilter2D, - glConvolutionParameterf, - glConvolutionParameterfv, - glConvolutionParameteri, - glConvolutionParameteriv, - xglCopyConvolutionFilter1D, /* glCopyConvolutionFilter1D */ - xglCopyConvolutionFilter2D, /* glCopyConvolutionFilter2D */ - glGetConvolutionFilter, - glGetConvolutionParameterfv, - glGetConvolutionParameteriv, - glGetSeparableFilter, - glSeparableFilter2D, - glGetHistogram, - glGetHistogramParameterfv, - glGetHistogramParameteriv, - glGetMinmax, - glGetMinmaxParameterfv, - glGetMinmaxParameteriv, - glHistogram, - glMinmax, - glResetHistogram, - glResetMinmax, - glTexImage3D, - glTexSubImage3D, - xglCopyTexSubImage3D /* glCopyTexSubImage3D */ -}; - -/* GL_ARB_multitexture */ -static void -xglNoOpActiveTextureARB (GLenum texture) {} -static void -xglActiveTextureARBProc (xglGLOpPtr pOp) -{ - GLenum texUnit; - - texUnit = pOp->u.enumeration - GL_TEXTURE0; - if (texUnit < 0 || texUnit >= cctx->maxTexUnits) - { - xglRecordError (GL_INVALID_ENUM); - } - else - { - cctx->activeTexUnit = texUnit; - (*cctx->ActiveTextureARB) (pOp->u.enumeration); - } -} -static void -xglActiveTextureARB (GLenum texture) -{ - xglGLOpRec gl; - - gl.glProc = xglActiveTextureARBProc; - - gl.u.enumeration = texture; - - xglGLOp (&gl); -} -static void -xglNoOpClientActiveTextureARB (GLenum texture) {} -static void -xglNoOpMultiTexCoord1dvARB (GLenum target, const GLdouble *v) {} -static void -xglNoOpMultiTexCoord1fvARB (GLenum target, const GLfloat *v) {} -static void -xglNoOpMultiTexCoord1ivARB (GLenum target, const GLint *v) {} -static void -xglNoOpMultiTexCoord1svARB (GLenum target, const GLshort *v) {} -static void -xglNoOpMultiTexCoord2dvARB (GLenum target, const GLdouble *v) {} -static void -xglNoOpMultiTexCoord2fvARB (GLenum target, const GLfloat *v) {} -static void -xglNoOpMultiTexCoord2ivARB (GLenum target, const GLint *v) {} -static void -xglNoOpMultiTexCoord2svARB (GLenum target, const GLshort *v) {} -static void -xglNoOpMultiTexCoord3dvARB (GLenum target, const GLdouble *v) {} -static void -xglNoOpMultiTexCoord3fvARB (GLenum target, const GLfloat *v) {} -static void -xglNoOpMultiTexCoord3ivARB (GLenum target, const GLint *v) {} -static void -xglNoOpMultiTexCoord3svARB (GLenum target, const GLshort *v) {} -static void -xglNoOpMultiTexCoord4dvARB (GLenum target, const GLdouble *v) {} -static void -xglNoOpMultiTexCoord4fvARB (GLenum target, const GLfloat *v) {} -static void -xglNoOpMultiTexCoord4ivARB (GLenum target, const GLint *v) {} -static void -xglNoOpMultiTexCoord4svARB (GLenum target, const GLshort *v) {} - -/* GL_ARB_multisample */ -static void -xglNoOpSampleCoverageARB (GLclampf value, GLboolean invert) {} - -/* GL_EXT_texture_object */ -static GLboolean -xglNoOpAreTexturesResidentEXT (GLsizei n, - const GLuint *textures, - GLboolean *residences) -{ - return GL_FALSE; -} -static void -xglNoOpGenTexturesEXT (GLsizei n, GLuint *textures) {} -static GLboolean -xglNoOpIsTextureEXT (GLuint texture) -{ - return GL_FALSE; -} - -/* GL_SGIS_multisample */ -static void -xglNoOpSampleMaskSGIS (GLclampf value, GLboolean invert) {} -static void -xglNoOpSamplePatternSGIS (GLenum pattern) {} - -/* GL_EXT_point_parameters */ -static void -xglNoOpPointParameterfEXT (GLenum pname, GLfloat param) {} -static void -xglNoOpPointParameterfvEXT (GLenum pname, const GLfloat *params) {} - -/* GL_MESA_window_pos */ -static void -xglNoOpWindowPos3fMESA (GLfloat x, GLfloat y, GLfloat z) {} -static void -xglWindowPos3fMESAProc (xglGLOpPtr pOp) -{ - (*cctx->WindowPos3fMESA) (pOp->u.window_pos_3f.x + cctx->pDrawBuffer->xOff, - pOp->u.window_pos_3f.y + cctx->pDrawBuffer->yOff, - pOp->u.window_pos_3f.z); -} -static void -xglWindowPos3fMESA (GLfloat x, GLfloat y, GLfloat z) -{ - xglGLOpRec gl; - - gl.glProc = xglWindowPos3fMESAProc; - - gl.u.window_pos_3f.x = x; - gl.u.window_pos_3f.y = y; - gl.u.window_pos_3f.z = z; - - xglGLOp (&gl); -} - -/* GL_EXT_blend_func_separate */ -static void -xglNoOpBlendFuncSeparateEXT (GLenum sfactorRGB, GLenum dfactorRGB, - GLenum sfactorAlpha, GLenum dfactorAlpha) {} - -/* GL_EXT_fog_coord */ -static void -xglNoOpFogCoordfvEXT (const GLfloat *coord) {} -static void -xglNoOpFogCoorddvEXT (const GLdouble *coord) {} -static void -xglNoOpFogCoordPointerEXT (GLenum type, GLsizei stride, - const GLvoid *pointer) {} - -/* GL_EXT_secondary_color */ -static void -xglNoOpSecondaryColor3bvEXT (const GLbyte *v) {} -static void -xglNoOpSecondaryColor3dvEXT (const GLdouble *v) {} -static void -xglNoOpSecondaryColor3fvEXT (const GLfloat *v) {} -static void -xglNoOpSecondaryColor3ivEXT (const GLint *v) {} -static void -xglNoOpSecondaryColor3svEXT (const GLshort *v) {} -static void -xglNoOpSecondaryColor3ubvEXT (const GLubyte *v) {} -static void -xglNoOpSecondaryColor3uivEXT (const GLuint *v) {} -static void -xglNoOpSecondaryColor3usvEXT (const GLushort *v) {} -static void -xglNoOpSecondaryColorPointerEXT (GLint size, GLenum type, GLsizei stride, - const GLvoid *pointer) {} - -/* GL_NV_point_sprite */ -static void -xglNoOpPointParameteriNV (GLenum pname, GLint params) {} -static void -xglNoOpPointParameterivNV (GLenum pname, const GLint *params) {} - -/* GL_EXT_stencil_two_side */ -static void -xglNoOpActiveStencilFaceEXT (GLenum face) {} - -__glProcTableEXT __glNoOpRenderTableEXT = { - xglNoOpActiveTextureARB, - xglNoOpClientActiveTextureARB, - xglNoOpMultiTexCoord1dvARB, - xglNoOpMultiTexCoord1fvARB, - xglNoOpMultiTexCoord1ivARB, - xglNoOpMultiTexCoord1svARB, - xglNoOpMultiTexCoord2dvARB, - xglNoOpMultiTexCoord2fvARB, - xglNoOpMultiTexCoord2ivARB, - xglNoOpMultiTexCoord2svARB, - xglNoOpMultiTexCoord3dvARB, - xglNoOpMultiTexCoord3fvARB, - xglNoOpMultiTexCoord3ivARB, - xglNoOpMultiTexCoord3svARB, - xglNoOpMultiTexCoord4dvARB, - xglNoOpMultiTexCoord4fvARB, - xglNoOpMultiTexCoord4ivARB, - xglNoOpMultiTexCoord4svARB, - xglNoOpSampleCoverageARB, - xglNoOpAreTexturesResidentEXT, - xglNoOpGenTexturesEXT, - xglNoOpIsTextureEXT, - xglNoOpSampleMaskSGIS, - xglNoOpSamplePatternSGIS, - xglNoOpPointParameterfEXT, - xglNoOpPointParameterfvEXT, - xglNoOpWindowPos3fMESA, - xglNoOpBlendFuncSeparateEXT, - xglNoOpFogCoordfvEXT, - xglNoOpFogCoorddvEXT, - xglNoOpFogCoordPointerEXT, - xglNoOpSecondaryColor3bvEXT, - xglNoOpSecondaryColor3dvEXT, - xglNoOpSecondaryColor3fvEXT, - xglNoOpSecondaryColor3ivEXT, - xglNoOpSecondaryColor3svEXT, - xglNoOpSecondaryColor3ubvEXT, - xglNoOpSecondaryColor3uivEXT, - xglNoOpSecondaryColor3usvEXT, - xglNoOpSecondaryColorPointerEXT, - xglNoOpPointParameteriNV, - xglNoOpPointParameterivNV, - xglNoOpActiveStencilFaceEXT -}; - -static void -xglInitExtensions (xglGLContextPtr pContext) -{ - const char *extensions; - - pContext->glRenderTableEXT = __glNoOpRenderTableEXT; - - extensions = (const char *) glGetString (GL_EXTENSIONS); - - if (strstr (extensions, "GL_ARB_multitexture")) - { - pContext->ActiveTextureARB = - (PFNGLACTIVETEXTUREARBPROC) - glitz_context_get_proc_address (pContext->context, - "glActiveTextureARB"); - pContext->glRenderTableEXT.ClientActiveTextureARB = - (PFNGLCLIENTACTIVETEXTUREARBPROC) - glitz_context_get_proc_address (pContext->context, - "glClientActiveTextureARB"); - pContext->glRenderTableEXT.MultiTexCoord1dvARB = - (PFNGLMULTITEXCOORD1DVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord1dvARB"); - pContext->glRenderTableEXT.MultiTexCoord1fvARB = - (PFNGLMULTITEXCOORD1FVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord1fvARB"); - pContext->glRenderTableEXT.MultiTexCoord1ivARB = - (PFNGLMULTITEXCOORD1IVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord1ivARB"); - pContext->glRenderTableEXT.MultiTexCoord1svARB = - (PFNGLMULTITEXCOORD1SVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord1svARB"); - pContext->glRenderTableEXT.MultiTexCoord2dvARB = - (PFNGLMULTITEXCOORD2DVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord2dvARB"); - pContext->glRenderTableEXT.MultiTexCoord2fvARB = - (PFNGLMULTITEXCOORD2FVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord2fvARB"); - pContext->glRenderTableEXT.MultiTexCoord2ivARB = - (PFNGLMULTITEXCOORD2IVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord2ivARB"); - pContext->glRenderTableEXT.MultiTexCoord2svARB = - (PFNGLMULTITEXCOORD2SVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord2svARB"); - pContext->glRenderTableEXT.MultiTexCoord3dvARB = - (PFNGLMULTITEXCOORD3DVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord3dvARB"); - pContext->glRenderTableEXT.MultiTexCoord3fvARB = - (PFNGLMULTITEXCOORD3FVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord3fvARB"); - pContext->glRenderTableEXT.MultiTexCoord3ivARB = - (PFNGLMULTITEXCOORD3IVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord3ivARB"); - pContext->glRenderTableEXT.MultiTexCoord3svARB = - (PFNGLMULTITEXCOORD3SVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord3svARB"); - pContext->glRenderTableEXT.MultiTexCoord4dvARB = - (PFNGLMULTITEXCOORD4DVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord4dvARB"); - pContext->glRenderTableEXT.MultiTexCoord4fvARB = - (PFNGLMULTITEXCOORD4FVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord4fvARB"); - pContext->glRenderTableEXT.MultiTexCoord4ivARB = - (PFNGLMULTITEXCOORD4IVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord4ivARB"); - pContext->glRenderTableEXT.MultiTexCoord4svARB = - (PFNGLMULTITEXCOORD4SVARBPROC) - glitz_context_get_proc_address (pContext->context, - "glMultiTexCoord4svARB"); - - glGetIntegerv (GL_MAX_LIST_NESTING, &pContext->maxListNesting); - glGetIntegerv (GL_MAX_TEXTURE_UNITS_ARB, &pContext->maxTexUnits); - if (pContext->maxTexUnits > XGL_MAX_TEXTURE_UNITS) - pContext->maxTexUnits = XGL_MAX_TEXTURE_UNITS; - - pContext->glRenderTableEXT.ActiveTextureARB = xglActiveTextureARB; - } - else - pContext->maxTexUnits = 1; - - if (strstr (extensions, "GL_ARB_multisample")) - { - pContext->glRenderTableEXT.SampleCoverageARB = - (PFNGLSAMPLECOVERAGEARBPROC) - glitz_context_get_proc_address (pContext->context, - "glSampleCoverageARB"); - } - - if (strstr (extensions, "GL_EXT_texture_object")) - { - pContext->glRenderTableEXT.AreTexturesResidentEXT = - xglAreTexturesResident; - pContext->glRenderTableEXT.GenTexturesEXT = xglGenTextures; - pContext->glRenderTableEXT.IsTextureEXT = xglIsTexture; - } - - if (strstr (extensions, "GL_SGIS_multisample")) - { - pContext->glRenderTableEXT.SampleMaskSGIS = - (PFNGLSAMPLEMASKSGISPROC) - glitz_context_get_proc_address (pContext->context, - "glSampleMaskSGIS"); - pContext->glRenderTableEXT.SamplePatternSGIS = - (PFNGLSAMPLEPATTERNSGISPROC) - glitz_context_get_proc_address (pContext->context, - "glSamplePatternSGIS"); - } - - if (strstr (extensions, "GL_EXT_point_parameters")) - { - pContext->glRenderTableEXT.PointParameterfEXT = - (PFNGLPOINTPARAMETERFEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glPointParameterfEXT"); - pContext->glRenderTableEXT.PointParameterfvEXT = - (PFNGLPOINTPARAMETERFVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glPointParameterfvEXT"); - } - - if (strstr (extensions, "GL_MESA_window_pos")) - { - pContext->WindowPos3fMESA = - (PFNGLWINDOWPOS3FMESAPROC) - glitz_context_get_proc_address (pContext->context, - "glWindowPos3fMESA"); - pContext->glRenderTableEXT.WindowPos3fMESA = xglWindowPos3fMESA; - } - - if (strstr (extensions, "GL_EXT_blend_func_separate")) - { - pContext->glRenderTableEXT.BlendFuncSeparateEXT = - (PFNGLBLENDFUNCSEPARATEEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glBlendFuncSeparateEXT"); - } - - if (strstr (extensions, "GL_EXT_fog_coord")) - { - pContext->glRenderTableEXT.FogCoordfvEXT = - (PFNGLFOGCOORDFVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glFogCoordfvEXT"); - pContext->glRenderTableEXT.FogCoorddvEXT = - (PFNGLFOGCOORDDVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glFogCoorddvEXT"); - pContext->glRenderTableEXT.FogCoordPointerEXT = - (PFNGLFOGCOORDPOINTEREXTPROC) - glitz_context_get_proc_address (pContext->context, - "glFogCoordPointerEXT"); - } - - if (strstr (extensions, "GL_EXT_secondary_color")) - { - pContext->glRenderTableEXT.SecondaryColor3bvEXT = - (PFNGLSECONDARYCOLOR3BVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glSecondaryColor3bvEXT"); - pContext->glRenderTableEXT.SecondaryColor3dvEXT = - (PFNGLSECONDARYCOLOR3DVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glSecondaryColor3dvEXT"); - pContext->glRenderTableEXT.SecondaryColor3fvEXT = - (PFNGLSECONDARYCOLOR3FVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glSecondaryColor3fvEXT"); - pContext->glRenderTableEXT.SecondaryColor3ivEXT = - (PFNGLSECONDARYCOLOR3IVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glSecondaryColor3ivEXT"); - pContext->glRenderTableEXT.SecondaryColor3svEXT = - (PFNGLSECONDARYCOLOR3SVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glSecondaryColor3svEXT"); - pContext->glRenderTableEXT.SecondaryColor3ubvEXT = - (PFNGLSECONDARYCOLOR3UBVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glSecondaryColor3ubvEXT"); - pContext->glRenderTableEXT.SecondaryColor3uivEXT = - (PFNGLSECONDARYCOLOR3UIVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glSecondaryColor3uivEXT"); - pContext->glRenderTableEXT.SecondaryColor3usvEXT = - (PFNGLSECONDARYCOLOR3USVEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glSecondaryColor3usvEXT"); - pContext->glRenderTableEXT.SecondaryColorPointerEXT = - (PFNGLSECONDARYCOLORPOINTEREXTPROC) - glitz_context_get_proc_address (pContext->context, - "glSecondaryColorPointerEXT"); - } - - if (strstr (extensions, "GL_NV_point_sprite")) - { - pContext->glRenderTableEXT.PointParameteriNV = - (PFNGLPOINTPARAMETERINVPROC) - glitz_context_get_proc_address (pContext->context, - "glPointParameteriNV"); - pContext->glRenderTableEXT.PointParameterivNV = - (PFNGLPOINTPARAMETERIVNVPROC) - glitz_context_get_proc_address (pContext->context, - "glPointParameterivNV"); - } - - if (strstr (extensions, "GL_EXT_stencil_two_side")) - { - pContext->glRenderTableEXT.ActiveStencilFaceEXT = - (PFNGLACTIVESTENCILFACEEXTPROC) - glitz_context_get_proc_address (pContext->context, - "glActiveStencilFaceEXT"); - } -} - -static void -xglSetCurrentContext (xglGLContextPtr pContext) -{ - XGL_SCREEN_PRIV (pContext->pDrawBuffer->pGC->pScreen); - cctx = pContext; - - glitz_context_make_current (cctx->context, pScreenPriv->drawable); - - __glRenderTable = &__glNativeRenderTable; - __glRenderTableEXT = &cctx->glRenderTableEXT; -} - -static void -xglFreeContext (xglGLContextPtr pContext) -{ - int i; - - pContext->refcnt--; - if (pContext->shared == pContext) - pContext->refcnt--; - - if (pContext->refcnt) - return; - - if (pContext->shared != pContext) - xglFreeContext (pContext->shared); - - if (pContext->texObjects) - { - xglTexObjPtr pTexObj; - GLuint key; - - do { - key = xglHashFirstEntry (pContext->texObjects); - if (key) - { - pTexObj = (xglTexObjPtr) xglHashLookup (pContext->texObjects, - key); - if (pTexObj) - xglUnrefTexObj (pTexObj); - - xglHashRemove (pContext->texObjects, key); - } - } while (key); - - xglDeleteHashTable (pContext->texObjects); - } - - if (pContext->displayLists) - { - xglDisplayListPtr pDisplayList; - GLuint key; - - do { - key = xglHashFirstEntry (pContext->displayLists); - if (key) - { - pDisplayList = (xglDisplayListPtr) - xglHashLookup (pContext->displayLists, key); - if (pDisplayList) - xglDestroyList (pDisplayList); - - xglHashRemove (pContext->displayLists, key); - } - } while (key); - - xglDeleteHashTable (pContext->displayLists); - } - - for (i = 0; i < pContext->maxTexUnits; i++) - { - xglUnrefTexObj (pContext->attrib.texUnits[i].p1D); - xglUnrefTexObj (pContext->attrib.texUnits[i].p2D); - xglUnrefTexObj (pContext->attrib.texUnits[i].p3D); - xglUnrefTexObj (pContext->attrib.texUnits[i].pRect); - xglUnrefTexObj (pContext->attrib.texUnits[i].pCubeMap); - } - - if (pContext->groupList) - glDeleteLists (pContext->groupList, 1); - - if (pContext->pAttribStack) - xfree (pContext->pAttribStack); - - if (pContext->context) - glitz_context_destroy (pContext->context); - - if (pContext->versionString) - xfree (pContext->versionString); - - xfree (pContext); -} - -static GLboolean -xglDestroyContext (__GLcontext *gc) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - __GLinterface *iface = pContext->mIface; - - xglFreeContext (pContext); - - if (!iface) - return GL_TRUE; - - return (*iface->exports.destroyContext) ((__GLcontext *) iface); -} - -static GLboolean -xglLoseCurrent (__GLcontext *gc) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - __GLinterface *iface = pContext->mIface; - - __glXFlushContextCache (); - - if (!iface) - return GL_TRUE; - - return (*iface->exports.loseCurrent) ((__GLcontext *) iface); -} - -static GLboolean -xglMakeCurrent (__GLcontext *gc) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - __GLinterface *iface = &pContext->iface; - __GLinterface *mIface = pContext->mIface; - __GLdrawablePrivate *drawPriv = iface->imports.getDrawablePrivate (gc); - __GLdrawablePrivate *readPriv = iface->imports.getReadablePrivate (gc); - xglGLBufferPtr pDrawBufferPriv = drawPriv->private; - xglGLBufferPtr pReadBufferPriv = readPriv->private; - GLboolean status = GL_TRUE; - - if (pReadBufferPriv->pDrawable && pDrawBufferPriv->pDrawable) - { - XID values[2] = { ClipByChildren, 0 }; - int status; - -#ifdef COMPOSITE - /* XXX: temporary hack for root window drawing using - IncludeInferiors */ - if (pDrawBufferPriv->pDrawable->type == DRAWABLE_WINDOW && - (!((WindowPtr) (pDrawBufferPriv->pDrawable))->parent)) - values[0] = IncludeInferiors; -#endif - - /* this happens if client previously used this context with a buffer - not supported by the native GL stack */ - if (!pContext->context) - return GL_FALSE; - - /* XXX: GLX_SGI_make_current_read disabled for now */ - if (pDrawBufferPriv != pReadBufferPriv) - return GL_FALSE; - - pContext->pReadBuffer = pReadBufferPriv; - pContext->pDrawBuffer = pDrawBufferPriv; - - if (!pReadBufferPriv->pGC) - pReadBufferPriv->pGC = - CreateGC (pReadBufferPriv->pDrawable, - GCSubwindowMode | GCGraphicsExposures, values, - &status); - - ValidateGC (pReadBufferPriv->pDrawable, pReadBufferPriv->pGC); - - if (!pDrawBufferPriv->pGC) - pDrawBufferPriv->pGC = - CreateGC (pDrawBufferPriv->pDrawable, - GCSubwindowMode | GCGraphicsExposures, values, - &status); - - ValidateGC (pDrawBufferPriv->pDrawable, pDrawBufferPriv->pGC); - - pContext->pReadBuffer = pReadBufferPriv; - pContext->pDrawBuffer = pDrawBufferPriv; - - pReadBufferPriv->pPixmap = (PixmapPtr) 0; - pDrawBufferPriv->pPixmap = (PixmapPtr) 0; - - /* from now on this context can only be used with native GL stack */ - if (mIface) - { - (*mIface->exports.destroyContext) ((__GLcontext *) mIface); - pContext->mIface = NULL; - } - } - else - { - /* this happens if client previously used this context with a buffer - supported by the native GL stack */ - if (!mIface) - return GL_FALSE; - - drawPriv->private = pDrawBufferPriv->private; - readPriv->private = pReadBufferPriv->private; - - status = (*mIface->exports.makeCurrent) ((__GLcontext *) mIface); - - drawPriv->private = pDrawBufferPriv; - readPriv->private = pReadBufferPriv; - - /* from now on this context can not be used with native GL stack */ - if (status == GL_TRUE && pContext->context) - { - glitz_context_destroy (pContext->context); - pContext->context = NULL; - } - } - - return status; -} - -static GLboolean -xglShareContext (__GLcontext *gc, - __GLcontext *gcShare) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - xglGLContextPtr pContextShare = (xglGLContextPtr) gcShare; - __GLinterface *iface = pContext->mIface; - __GLinterface *ifaceShare = pContextShare->mIface; - - if (!iface || !ifaceShare) - return GL_TRUE; - - return (*iface->exports.shareContext) ((__GLcontext *) iface, - (__GLcontext *) ifaceShare); -} - -static GLboolean -xglCopyContext (__GLcontext *dst, - const __GLcontext *src, - GLuint mask) -{ - xglGLContextPtr pDst = (xglGLContextPtr) dst; - xglGLContextPtr pSrc = (xglGLContextPtr) src; - const __GLcontext *srcCtx = (const __GLcontext *) pSrc->mIface; - __GLinterface *dstIface = (__GLinterface *) pDst->mIface; - GLboolean status = GL_TRUE; - - if (pSrc->context && pDst->context) - glitz_context_copy (pSrc->context, pDst->context, mask); - else - status = GL_FALSE; - - if (dstIface && srcCtx) - status = (*dstIface->exports.copyContext) ((__GLcontext *) dstIface, - srcCtx, - mask); - - return status; -} - -static GLboolean -xglForceCurrent (__GLcontext *gc) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - __GLinterface *iface = pContext->mIface; - GLboolean status = GL_TRUE; - - if (pContext->context) - { - cctx = pContext; - - if (cctx->pReadBuffer->pDrawable && cctx->pDrawBuffer->pDrawable) - { - DrawablePtr pDrawable; - PixmapPtr pReadPixmap, pDrawPixmap; - - pDrawable = cctx->pReadBuffer->pDrawable; - if (pDrawable->type != DRAWABLE_PIXMAP) - { - pReadPixmap = XGL_GET_WINDOW_PIXMAP (pDrawable); - cctx->pReadBuffer->xOff = pDrawable->x + - __XGL_OFF_X_WIN (pReadPixmap); - cctx->pReadBuffer->yOff = pReadPixmap->drawable.height - - ((pDrawable->y + __XGL_OFF_Y_WIN (pReadPixmap)) + - pDrawable->height); - cctx->pReadBuffer->yFlip = pReadPixmap->drawable.height; - } - else - { - pReadPixmap = (PixmapPtr) pDrawable; - cctx->pReadBuffer->xOff = cctx->pReadBuffer->yOff = 0; - cctx->pReadBuffer->yFlip = pDrawable->height; - } - - pDrawable = cctx->pDrawBuffer->pDrawable; - if (pDrawable->type != DRAWABLE_PIXMAP) - { - pDrawPixmap = XGL_GET_WINDOW_PIXMAP (pDrawable); - cctx->pDrawBuffer->xOff = pDrawable->x + - __XGL_OFF_X_WIN (pDrawPixmap); - cctx->pDrawBuffer->yOff = pDrawPixmap->drawable.height - - ((pDrawable->y + __XGL_OFF_Y_WIN (pDrawPixmap)) + - pDrawable->height); - cctx->pDrawBuffer->yFlip = pDrawPixmap->drawable.height; - } - else - { - pDrawPixmap = (PixmapPtr) pDrawable; - cctx->pDrawBuffer->xOff = cctx->pDrawBuffer->yOff = 0; - cctx->pDrawBuffer->yFlip = pDrawable->height; - } - - /* check if buffers have changed */ - if (cctx->pReadBuffer->pPixmap != pReadPixmap || - cctx->pDrawBuffer->pPixmap != pDrawPixmap) - { - XGL_SCREEN_PRIV (pDrawable->pScreen); - XGL_PIXMAP_PRIV (pDrawPixmap); - - if (!xglPrepareTarget (pDrawable)) - return FALSE; - - /* draw buffer is offscreen */ - if (pPixmapPriv->surface != pScreenPriv->surface) - { - /* NYI: framebuffer object setup */ - FatalError ("NYI: offscreen GL drawable\n"); - } - - cctx->pReadBuffer->pPixmap = pReadPixmap; - cctx->pDrawBuffer->pPixmap = pDrawPixmap; - } - } - - xglSetCurrentContext (pContext); - - if (cctx->needInit) - { - int i; - - xglInitExtensions (cctx); - - cctx->attrib.scissorTest = GL_FALSE; - cctx->attrib.scissor.x = cctx->attrib.scissor.y = 0; - cctx->attrib.scissor.width = cctx->pDrawBuffer->pDrawable->width; - cctx->attrib.scissor.height = cctx->pDrawBuffer->pDrawable->height; - cctx->attrib.viewport = cctx->attrib.scissor; - - cctx->activeTexUnit = 0; - - for (i = 0; i < cctx->maxTexUnits; i++) - { - cctx->attrib.texUnits[i].enabled = 0; - - cctx->attrib.texUnits[i].p1D = NULL; - cctx->attrib.texUnits[i].p2D = NULL; - cctx->attrib.texUnits[i].p3D = NULL; - cctx->attrib.texUnits[i].pRect = NULL; - cctx->attrib.texUnits[i].pCubeMap = NULL; - } - - glEnable (GL_SCISSOR_TEST); - - cctx->needInit = FALSE; - } - - /* update viewport and raster position */ - if (cctx->pDrawBuffer->xOff != cctx->drawXoff || - cctx->pDrawBuffer->yOff != cctx->drawYoff) - { - glViewport (cctx->attrib.scissor.x + cctx->pDrawBuffer->xOff, - cctx->attrib.scissor.y + cctx->pDrawBuffer->yOff, - cctx->attrib.scissor.width, - cctx->attrib.scissor.height); - - glBitmap (0, 0, 0, 0, - cctx->pDrawBuffer->xOff - cctx->drawXoff, - cctx->pDrawBuffer->yOff - cctx->drawYoff, - NULL); - - cctx->drawXoff = cctx->pDrawBuffer->xOff; - cctx->drawYoff = cctx->pDrawBuffer->yOff; - } - - glDrawBuffer (cctx->attrib.drawBuffer); - glReadBuffer (cctx->attrib.readBuffer); - } - else - { - cctx = NULL; - __glRenderTable = &__glMesaRenderTable; - __glRenderTableEXT = &__glMesaRenderTableEXT; - - status = (*iface->exports.forceCurrent) ((__GLcontext *) iface); - } - - return status; -} - -static GLboolean -xglNotifyResize (__GLcontext *gc) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - __GLinterface *iface = pContext->mIface; - - if (!iface) - return GL_TRUE; - - return (*iface->exports.notifyResize) ((__GLcontext *) iface); -} - -static void -xglNotifyDestroy (__GLcontext *gc) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - __GLinterface *iface = pContext->mIface; - - if (iface) - (*iface->exports.notifyDestroy) ((__GLcontext *) iface); -} - -static void -xglNotifySwapBuffers (__GLcontext *gc) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - __GLinterface *iface = pContext->mIface; - - if (iface) - (*iface->exports.notifySwapBuffers) ((__GLcontext *) iface); -} - -static struct __GLdispatchStateRec * -xglDispatchExec (__GLcontext *gc) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - __GLinterface *iface = pContext->mIface; - - if (!iface) - return NULL; - - return (*iface->exports.dispatchExec) ((__GLcontext *) iface); -} - -static void -xglBeginDispatchOverride (__GLcontext *gc) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - __GLinterface *iface = pContext->mIface; - - if (iface) - (*iface->exports.beginDispatchOverride) ((__GLcontext *) iface); -} - -static void -xglEndDispatchOverride (__GLcontext *gc) -{ - xglGLContextPtr pContext = (xglGLContextPtr) gc; - __GLinterface *iface = pContext->mIface; - - if (iface) - (*iface->exports.endDispatchOverride) ((__GLcontext *) iface); -} - -static void -xglLoseCurrentContext (void *closure) -{ - cctx = NULL; - __glRenderTable = &__glMesaRenderTable; - __glRenderTableEXT = &__glMesaRenderTableEXT; - - __glXFlushContextCache (); -} - -static __GLinterface * -xglCreateContext (__GLimports *imports, - __GLcontextModes *modes, - __GLinterface *shareGC) -{ - glitz_drawable_format_t *format; - xglGLContextPtr pShareContext = (xglGLContextPtr) shareGC; - xglGLContextPtr pContext; - __GLinterface *shareIface = NULL; - __GLinterface *iface; - __GLXcontext *glxCtx = (__GLXcontext *) imports->other; - - XGL_SCREEN_PRIV (glxCtx->pScreen); - - format = glitz_drawable_get_format (pScreenPriv->drawable); - - pContext = xalloc (sizeof (xglGLContextRec)); - if (!pContext) - return NULL; - - pContext->context = glitz_context_create (pScreenPriv->drawable, format); - glitz_context_set_user_data (pContext->context, NULL, - xglLoseCurrentContext); - - pContext->needInit = TRUE; - pContext->versionString = NULL; - pContext->errorValue = GL_NO_ERROR; - pContext->shared = NULL; - pContext->list = 0; - pContext->groupList = 0; - pContext->pAttribStack = NULL; - pContext->nAttribStack = 0; - pContext->refcnt = 1; - pContext->doubleBuffer = glxCtx->pGlxVisual->doubleBuffer; - pContext->depthBits = glxCtx->pGlxVisual->depthSize; - pContext->stencilBits = glxCtx->pGlxVisual->stencilSize; - pContext->drawXoff = 0; - pContext->drawYoff = 0; - pContext->maxTexUnits = 0; - - if (pContext->doubleBuffer) - { - pContext->attrib.drawBuffer = GL_BACK; - pContext->attrib.readBuffer = GL_BACK; - } - else - { - pContext->attrib.drawBuffer = GL_FRONT; - pContext->attrib.readBuffer = GL_FRONT; - } - - pContext->attrib.scissorTest = GL_FALSE; - - if (shareGC) - { - pContext->texObjects = NULL; - pContext->displayLists = NULL; - - pContext->shared = pShareContext->shared; - shareIface = pShareContext->mIface; - } - else - { - pContext->texObjects = xglNewHashTable (); - if (!pContext->texObjects) - { - xglFreeContext (pContext); - return NULL; - } - - pContext->displayLists = xglNewHashTable (); - if (!pContext->displayLists) - { - xglFreeContext (pContext); - return NULL; - } - - pContext->shared = pContext; - } - - pContext->shared->refcnt++; - - iface = (*screenInfoPriv.createContext) (imports, modes, shareIface); - if (!iface) - { - xglFreeContext (pContext); - return NULL; - } - - pContext->mIface = iface; - pContext->iface.imports = *imports; - - pContext->iface.exports.destroyContext = xglDestroyContext; - pContext->iface.exports.loseCurrent = xglLoseCurrent; - pContext->iface.exports.makeCurrent = xglMakeCurrent; - pContext->iface.exports.shareContext = xglShareContext; - pContext->iface.exports.copyContext = xglCopyContext; - pContext->iface.exports.forceCurrent = xglForceCurrent; - pContext->iface.exports.notifyResize = xglNotifyResize; - pContext->iface.exports.notifyDestroy = xglNotifyDestroy; - pContext->iface.exports.notifySwapBuffers = xglNotifySwapBuffers; - pContext->iface.exports.dispatchExec = xglDispatchExec; - pContext->iface.exports.beginDispatchOverride = xglBeginDispatchOverride; - pContext->iface.exports.endDispatchOverride = xglEndDispatchOverride; - - return (__GLinterface *) pContext; -} - -static GLboolean -xglSwapBuffers (__GLXdrawablePrivate *glxPriv) -{ - __GLdrawablePrivate *glPriv = &glxPriv->glPriv; - xglGLBufferPtr pBufferPriv = glPriv->private; - DrawablePtr pDrawable = pBufferPriv->pDrawable; - GLboolean status = GL_TRUE; - - if (pDrawable) - { - if (glPriv->modes->doubleBufferMode) - { - glitz_surface_t *surface; - int xOff, yOff; - GCPtr pGC = pBufferPriv->pGC; - BoxPtr pBox = REGION_RECTS (pGC->pCompositeClip); - int nBox = REGION_NUM_RECTS (pGC->pCompositeClip); - - XGL_SCREEN_PRIV (pGC->pScreen); - - if (!xglPrepareTarget (pDrawable)) - return GL_FALSE; - - XGL_GET_DRAWABLE (pDrawable, surface, xOff, yOff); - - /* native swap buffers for fullscreen windows */ - if (surface == pScreenPriv->surface && - nBox == 1 && - pBox->x1 <= 0 && - pBox->y1 <= 0 && - pBox->x2 >= pGC->pScreen->width && - pBox->y2 >= pGC->pScreen->height) - { - glitz_drawable_swap_buffers (pScreenPriv->drawable); - } - else - { - glitz_surface_set_clip_region (surface, xOff, yOff, - (glitz_box_t *) pBox, nBox); - - glitz_copy_area (pBufferPriv->backSurface, - surface, - pDrawable->x + xOff, - pDrawable->y + yOff, - pDrawable->width, - pDrawable->height, - pDrawable->x + xOff, - pDrawable->y + yOff); - - glitz_surface_set_clip_region (surface, 0, 0, NULL, 0); - } - - DamageDamageRegion (pDrawable, pGC->pCompositeClip); - REGION_EMPTY (pGC->pScreen, &pBufferPriv->damage); - } - } - else if (pBufferPriv->private) - { - glPriv->private = pBufferPriv->private; - status = (*pBufferPriv->swapBuffers) (glxPriv); - glPriv->private = pBufferPriv; - } - - return status; -} - -static GLboolean -xglResizeBuffers (__GLdrawableBuffer *buffer, - GLint x, - GLint y, - GLuint width, - GLuint height, - __GLdrawablePrivate *glPriv, - GLuint bufferMask) -{ - xglGLBufferPtr pBufferPriv = glPriv->private; - DrawablePtr pDrawable = pBufferPriv->pDrawable; - GLboolean status = GL_TRUE; - - if (pDrawable) - { - if (glPriv->modes->doubleBufferMode) - { - glitz_surface_t *surface = pBufferPriv->backSurface; - - XGL_SCREEN_PRIV (pDrawable->pScreen); - - /* FIXME: copy color buffer bits, stencil bits and depth bits */ - - if (surface != pScreenPriv->backSurface && - (glitz_surface_get_width (surface) != width || - glitz_surface_get_height (surface) != height)) - { - glitz_format_t *format; - - format = pScreenPriv->pixmapFormats[pDrawable->depth].format; - - glitz_surface_destroy (surface); - - pBufferPriv->backSurface = - glitz_surface_create (pScreenPriv->drawable, format, - width, height, 0, NULL); - if (!pBufferPriv->backSurface) - status = GL_FALSE; - } - } - - ValidateGC (pDrawable, pBufferPriv->pGC); - } - else if (pBufferPriv->private) - { - glPriv->private = pBufferPriv->private; - status = (*pBufferPriv->resizeBuffers) (buffer, - x, y, width, height, - glPriv, - bufferMask); - glPriv->private = pBufferPriv; - } - - return status; -} - -static int -xglBindBuffers (__GLXdrawablePrivate *glxPriv, - int buffer) -{ - __GLdrawablePrivate *glPriv = &glxPriv->glPriv; - xglGLBufferPtr pBufferPriv = glPriv->private; - - if (cctx) - { - xglTexUnitPtr pTexUnit = &cctx->attrib.texUnits[cctx->activeTexUnit]; - xglTexObjPtr pTexObj = NULL; - DrawablePtr pDrawable; - - /* XXX: front left buffer is only supported so far */ - if (buffer != GLX_FRONT_LEFT_EXT) - return BadMatch; - - /* Must be a GLXpixmap */ - if (!glxPriv->pGlxPixmap) - return __glXBadDrawable; - - pDrawable = glxPriv->pGlxPixmap->pDraw; - - switch (glxPriv->texTarget) { - case GLX_TEXTURE_RECTANGLE_EXT: - pTexObj = pTexUnit->pRect; - break; - case GLX_TEXTURE_2D_EXT: - pTexObj = pTexUnit->p2D; - break; - default: - break; - } - - if (pTexObj) - { - XGL_DRAWABLE_PIXMAP (pDrawable); - - pPixmap->refcnt++; - - if (pTexObj->pPixmap) - (*pDrawable->pScreen->DestroyPixmap) (pTexObj->pPixmap); - - pTexObj->pPixmap = pPixmap; - - return Success; - } - } - else if (pBufferPriv->private) - { - int status; - - glPriv->private = pBufferPriv->private; - status = (*pBufferPriv->bindBuffers) (glxPriv, buffer); - glPriv->private = pBufferPriv; - - return status; - } - - return __glXBadContext; -} - -static int -xglReleaseBuffers (__GLXdrawablePrivate *glxPriv, - int buffer) -{ - __GLdrawablePrivate *glPriv = &glxPriv->glPriv; - xglGLBufferPtr pBufferPriv = glPriv->private; - - if (cctx) - { - xglTexObjPtr pTexObj; - - /* XXX: front left buffer is only supported so far */ - if (buffer != GLX_FRONT_LEFT_EXT) - return BadMatch; - - /* Must be a GLXpixmap */ - if (glxPriv->pGlxPixmap) - { - DrawablePtr pDrawable = glxPriv->pGlxPixmap->pDraw; - - XGL_DRAWABLE_PIXMAP (pDrawable); - - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].p2D; - if (pTexObj && pTexObj->pPixmap == pPixmap) - { - (*pDrawable->pScreen->DestroyPixmap) (pTexObj->pPixmap); - pTexObj->pPixmap = NULL; - - return Success; - } - else - { - pTexObj = cctx->attrib.texUnits[cctx->activeTexUnit].pRect; - if (pTexObj && pTexObj->pPixmap == pPixmap) - { - (*pDrawable->pScreen->DestroyPixmap) (pTexObj->pPixmap); - pTexObj->pPixmap = NULL; - - return Success; - } - } - } - } - else if (pBufferPriv->private) - { - int status; - - glPriv->private = pBufferPriv->private; - status = (*pBufferPriv->releaseBuffers) (glxPriv, buffer); - glPriv->private = pBufferPriv; - - return status; - } - - return __glXBadContext; -} - -static void -xglFreeBuffers (__GLdrawablePrivate *glPriv) -{ - xglGLBufferPtr pBufferPriv = glPriv->private; - - glPriv->private = pBufferPriv->private; - - if (pBufferPriv->freeBuffers) - (*pBufferPriv->freeBuffers) (glPriv); - - if (pBufferPriv->pGC) - FreeGC (pBufferPriv->pGC, (GContext) 0); - - if (pBufferPriv->backSurface) - glitz_surface_destroy (pBufferPriv->backSurface); - - xfree (pBufferPriv); -} - -static void -xglCreateBuffer (__GLXdrawablePrivate *glxPriv) -{ - __GLdrawablePrivate *glPriv = &glxPriv->glPriv; - DrawablePtr pDrawable = glxPriv->pDraw; - ScreenPtr pScreen = pDrawable->pScreen; - xglGLBufferPtr pBufferPriv; - - XGL_SCREEN_PRIV (pScreen); - - pBufferPriv = xalloc (sizeof (xglGLBufferRec)); - if (!pBufferPriv) - FatalError ("xglCreateBuffer: No memory\n"); - - pBufferPriv->pScreen = pScreen; - pBufferPriv->pDrawable = NULL; - pBufferPriv->pPixmap = NULL; - pBufferPriv->pGC = NULL; - pBufferPriv->backSurface = NULL; - - pBufferPriv->swapBuffers = NULL; - - pBufferPriv->bindBuffers = NULL; - pBufferPriv->releaseBuffers = NULL; - - pBufferPriv->resizeBuffers = NULL; - pBufferPriv->private = NULL; - pBufferPriv->freeBuffers = NULL; - - REGION_INIT (pScreen, &pBufferPriv->damage, NullBox, 0); - - /* use native back buffer for regular windows */ - if (pDrawable->type == DRAWABLE_WINDOW - -#ifdef COMPOSITE - /* this is a root window, can't be redirected */ - && (!((WindowPtr) pDrawable)->parent) -#endif - - ) - { - pBufferPriv->pDrawable = pDrawable; - - if (glxPriv->pGlxVisual->doubleBuffer) - { - pBufferPriv->backSurface = pScreenPriv->backSurface; - glitz_surface_reference (pScreenPriv->backSurface); - } - } - else if (0) /* pScreenPriv->features & - GLITZ_FEATURE_FRAMEBUFFER_OBJECT_MASK) */ - { - pBufferPriv->pDrawable = pDrawable; - - if (glxPriv->pGlxVisual->doubleBuffer) - { - int depth = pDrawable->depth; - - pBufferPriv->backSurface = - glitz_surface_create (pScreenPriv->drawable, - pScreenPriv->pixmapFormats[depth].format, - pDrawable->width, pDrawable->height, - 0, NULL); - if (!pBufferPriv->backSurface) - FatalError ("xglCreateBuffer: glitz_surface_create\n"); - } - } - else - { - (*screenInfoPriv.createBuffer) (glxPriv); - - /* Wrap the swap buffers routine */ - pBufferPriv->swapBuffers = glxPriv->swapBuffers; - - /* Wrap the render texture routines */ - pBufferPriv->bindBuffers = glxPriv->bindBuffers; - pBufferPriv->releaseBuffers = glxPriv->releaseBuffers; - - /* Wrap the front buffer's resize routine */ - pBufferPriv->resizeBuffers = glPriv->frontBuffer.resize; - - /* Save Xgl's private buffer structure */ - pBufferPriv->freeBuffers = glPriv->freePrivate; - pBufferPriv->private = glPriv->private; - } - - glxPriv->texTarget = GLX_NO_TEXTURE_EXT; - - /* We enable render texture for all GLXPixmaps right now. Eventually, this - should only be enabled when fbconfig attribute GLX_RENDER_TEXTURE_RGB or - GLX_RENDER_TEXTURE_RGBA is set to TRUE. */ - if (pDrawable->type != DRAWABLE_WINDOW) - { - /* GL_ARB_texture_rectangle is required for sane texture coordinates. - GL_ARB_texture_border_clamp is required right now as glitz will - emulate it when missing, which means a 1 pixel translucent black - border inside textures, that cannot be exposed to clients. */ - if (pScreenPriv->features & - (GLITZ_FEATURE_TEXTURE_BORDER_CLAMP_MASK | - GLITZ_FEATURE_TEXTURE_RECTANGLE_MASK)) - { - glitz_point_fixed_t point = { 1 << 16 , 1 << 16 }; - - XGL_DRAWABLE_PIXMAP (pDrawable); - - if (xglCreatePixmapSurface (pPixmap)) - { - XGL_PIXMAP_PRIV (pPixmap); - - /* FIXME: doesn't work for 1x1 textures */ - glitz_surface_translate_point (pPixmapPriv->surface, - &point, &point); - if (point.x > (1 << 16) || point.y > (1 << 16)) - glxPriv->texTarget = GLX_TEXTURE_RECTANGLE_EXT; - else - glxPriv->texTarget = GLX_TEXTURE_2D_EXT; - } - } - } - - glxPriv->swapBuffers = xglSwapBuffers; - - glxPriv->bindBuffers = xglBindBuffers; - glxPriv->releaseBuffers = xglReleaseBuffers; - - glPriv->frontBuffer.resize = xglResizeBuffers; - - glPriv->private = (void *) pBufferPriv; - glPriv->freePrivate = xglFreeBuffers; -} - -static Bool -xglScreenProbe (int screen) -{ - Bool status; - - status = (*screenInfoPriv.screenProbe) (screen); - - /* Wrap createBuffer */ - if (__glDDXScreenInfo.createBuffer != xglCreateBuffer) - { - screenInfoPriv.createBuffer = __glDDXScreenInfo.createBuffer; - __glDDXScreenInfo.createBuffer = xglCreateBuffer; - } - - /* Wrap createContext */ - if (__glDDXScreenInfo.createContext != xglCreateContext) - { - screenInfoPriv.createContext = __glDDXScreenInfo.createContext; - __glDDXScreenInfo.createContext = xglCreateContext; - } - - return status; -} - -static int -xglXWaitX (__GLXclientState *cl, GLbyte *pc) -{ - xGLXWaitXReq *req = (xGLXWaitXReq *) pc; - __GLXcontext *cx; - - cx = (__GLXcontext *) __glXLookupContextByTag (cl, req->contextTag); - if (cx) - { - xglGLContextPtr pContext = (xglGLContextPtr) cx->gc; - __GLXcontext *glxCtx = (__GLXcontext *) - pContext->iface.imports.other; - - XGL_SCREEN_PRIV (glxCtx->pScreen); - - glitz_drawable_finish (pScreenPriv->drawable); - - return Success; - } - else - { - cl->client->errorValue = req->contextTag; - return __glXBadContextTag; - } -} - -static int -xglXSwapWaitX (__GLXclientState *cl, GLbyte *pc) -{ - xGLXWaitXReq *req = (xGLXWaitXReq *) pc; - __GLX_DECLARE_SWAP_VARIABLES; - - __GLX_SWAP_SHORT (&req->length); - __GLX_SWAP_INT (&req->contextTag); - - return xglXWaitX (cl, pc); -} - -static Bool -xglDestroyWindow (WindowPtr pWin) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - Bool ret; - - XGL_SCREEN_PRIV (pScreen); - - if (cctx) - { - if (cctx->pDrawBuffer->pDrawable == &pWin->drawable) - cctx->pDrawBuffer->pDrawable = NULL; - - if (cctx->pReadBuffer->pDrawable == &pWin->drawable) - cctx->pReadBuffer->pDrawable = NULL; - } - - XGL_SCREEN_UNWRAP (DestroyWindow); - ret = (*pScreen->DestroyWindow) (pWin); - XGL_SCREEN_WRAP (DestroyWindow, xglDestroyWindow); - - return ret; -} - -Bool -xglInitVisualConfigs (ScreenPtr pScreen) -{ - miInitVisualsProcPtr initVisualsProc = NULL; - VisualPtr visuals; - int nvisuals; - DepthPtr depths; - int ndepths; - int rootDepth; - VisualID defaultVis; - glitz_drawable_format_t *format; - xglPixelFormatPtr pPixel; - __GLXvisualConfig *pConfig; - xglGLXVisualConfigPtr pConfigPriv, *ppConfigPriv; - XID *installedCmaps; - ColormapPtr installedCmap; - int numInstalledCmaps; - int numConfig = 1; - int depth, bpp, i; - - XGL_SCREEN_PRIV (pScreen); - - XGL_SCREEN_WRAP (DestroyWindow, xglDestroyWindow); - - depth = pScreenPriv->pVisual->pPixel->depth; - bpp = pScreenPriv->pVisual->pPixel->masks.bpp; - format = glitz_drawable_get_format (pScreenPriv->drawable); - pPixel = pScreenPriv->pixmapFormats[depth].pPixel; - - if (format->doublebuffer) - { - pScreenPriv->backSurface = - glitz_surface_create (pScreenPriv->drawable, - pScreenPriv->pixmapFormats[depth].format, - pScreen->width, pScreen->height, - 0, NULL); - if (!pScreenPriv->backSurface) - return FALSE; - - glitz_surface_attach (pScreenPriv->backSurface, - pScreenPriv->drawable, - GLITZ_DRAWABLE_BUFFER_BACK_COLOR); - - numConfig *= 2; - } - - pConfig = xcalloc (sizeof (__GLXvisualConfig), numConfig); - if (!pConfig) - return FALSE; - - pConfigPriv = xcalloc (sizeof (xglGLXVisualConfigRec), numConfig); - if (!pConfigPriv) - { - xfree (pConfig); - return FALSE; - } - - ppConfigPriv = xcalloc (sizeof (xglGLXVisualConfigPtr), numConfig); - if (!ppConfigPriv) - { - xfree (pConfigPriv); - xfree (pConfig); - return FALSE; - } - - installedCmaps = xalloc (pScreen->maxInstalledCmaps * sizeof (XID)); - if (!installedCmaps) - { - xfree (ppConfigPriv); - xfree (pConfigPriv); - xfree (pConfig); - return FALSE; - } - - for (i = 0; i < numConfig; i++) - { - ppConfigPriv[i] = &pConfigPriv[i]; - - pConfig[i].vid = (VisualID) (-1); - pConfig[i].class = -1; - pConfig[i].rgba = TRUE; - - pConfig[i].redSize = format->color.red_size; - pConfig[i].greenSize = format->color.green_size; - pConfig[i].blueSize = format->color.blue_size; - - pConfig[i].redMask = pPixel->masks.red_mask; - pConfig[i].greenMask = pPixel->masks.green_mask; - pConfig[i].blueMask = pPixel->masks.blue_mask; - - if (format->color.alpha_size) - { - pConfig[i].alphaSize = format->color.alpha_size; - pConfig[i].alphaMask = pPixel->masks.alpha_mask; - } - else - { - pConfig[i].alphaSize = 0; - pConfig[i].alphaMask = 0; - } - - if (i == 1) - { - pConfig[i].doubleBuffer = FALSE; - pConfig[i].depthSize = 0; - pConfig[i].stencilSize = 0; - - } - else - { - pConfig[i].doubleBuffer = TRUE; - pConfig[i].depthSize = format->depth_size; - pConfig[i].stencilSize = format->stencil_size; - } - - pConfig[i].stereo = FALSE; - - if (depth == 16) - pConfig[i].bufferSize = 16; - else - pConfig[i].bufferSize = 32; - - pConfig[i].auxBuffers = 0; - pConfig[i].level = 0; - - pConfig[i].visualRating = GLX_NONE; - - pConfig[i].transparentPixel = GLX_NONE; - pConfig[i].transparentRed = 0; - pConfig[i].transparentGreen = 0; - pConfig[i].transparentBlue = 0; - pConfig[i].transparentAlpha = 0; - pConfig[i].transparentIndex = 0; - } - - GlxSetVisualConfigs (numConfig, pConfig, (void **) ppConfigPriv); - - /* Wrap screenProbe */ - if (__glDDXScreenInfo.screenProbe != xglScreenProbe) - { - screenInfoPriv.screenProbe = __glDDXScreenInfo.screenProbe; - __glDDXScreenInfo.screenProbe = xglScreenProbe; - - __glXSingleTable[9] = xglXWaitX; - __glXSwapSingleTable[9] = xglXSwapWaitX; - } - - visuals = pScreen->visuals; - nvisuals = pScreen->numVisuals; - depths = pScreen->allowedDepths; - ndepths = pScreen->numDepths; - rootDepth = pScreen->rootDepth; - defaultVis = pScreen->rootVisual; - - /* Find installed colormaps */ - numInstalledCmaps = (*pScreen->ListInstalledColormaps) (pScreen, - installedCmaps); - - GlxWrapInitVisuals (&initVisualsProc); - GlxInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootDepth, - &defaultVis, ((unsigned long) 1 << (bpp - 1)), 8, -1); - - /* Fix up any existing installed colormaps. */ - for (i = 0; i < numInstalledCmaps; i++) - { - int j; - - installedCmap = LookupIDByType (installedCmaps[i], RT_COLORMAP); - if (!installedCmap) - continue; - - j = installedCmap->pVisual - pScreen->visuals; - installedCmap->pVisual = &visuals[j]; - } - - pScreen->visuals = visuals; - pScreen->numVisuals = nvisuals; - pScreen->allowedDepths = depths; - pScreen->numDepths = ndepths; - pScreen->rootDepth = rootDepth; - pScreen->rootVisual = defaultVis; - - xfree (installedCmaps); - xfree (pConfigPriv); - xfree (pConfig); - - return TRUE; -} - -#endif /* GLXEXT */ diff --git a/hw/xgl/xglhash.c b/hw/xgl/xglhash.c index a541d7dd4..2635422f8 100644 --- a/hw/xgl/xglhash.c +++ b/hw/xgl/xglhash.c @@ -1,6 +1,6 @@ /* * Copyright © 2005 Novell, Inc. - * + * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without * fee, provided that the above copyright notice appear in all copies @@ -12,11 +12,11 @@ * software for any purpose. It is provided "as is" without express or * implied warranty. * - * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS - * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. * @@ -25,58 +25,77 @@ #include "xgl.h" -#ifdef GLXEXT - -/* This is just a wrapper around Mesa's hash functions. */ - -extern struct _mesa_HashTable * -_mesa_NewHashTable (void); - -extern void -_mesa_DeleteHashTable (struct _mesa_HashTable *table); - -extern void * -_mesa_HashLookup (const struct _mesa_HashTable *table, - unsigned int key); - -extern void -_mesa_HashInsert (struct _mesa_HashTable *table, - unsigned int key, - void *data); - -extern void -_mesa_HashRemove (struct _mesa_HashTable *table, - unsigned int key); - -extern unsigned int -_mesa_HashFirstEntry (struct _mesa_HashTable *table); - -extern unsigned int -_mesa_HashNextEntry (const struct _mesa_HashTable *table, - unsigned int key); +#define SYM(ptr, name) { (void **) &(ptr), (name) } + +typedef struct _xglHashFunc { + xglHashTablePtr (*NewHashTable) (void); + void (*DeleteHashTable) (xglHashTablePtr pTable); + void *(*HashLookup) (const xglHashTablePtr pTable, + unsigned int key); + void (*HashInsert) (xglHashTablePtr pTable, + unsigned int key, + void *data); + void (*HashRemove) (xglHashTablePtr pTable, + unsigned int key); + unsigned int (*HashFirstEntry) (xglHashTablePtr pTable); + unsigned int (*HashNextEntry) (const xglHashTablePtr pTable, + unsigned int key); + unsigned int (*HashFindFreeKeyBlock) (xglHashTablePtr pTable, + unsigned int numKeys); +} xglHashFuncRec; + +static xglHashFuncRec __hashFunc; + +static void *hashHandle = 0; + +Bool +xglLoadHashFuncs (void *handle) +{ -extern unsigned int -_mesa_HashFindFreeKeyBlock (struct _mesa_HashTable *table, - unsigned int numKeys); +#ifdef XLOADABLE + xglSymbolRec sym[] = { + SYM (__hashFunc.NewHashTable, "_mesa_NewHashTable"), + SYM (__hashFunc.DeleteHashTable, "_mesa_DeleteHashTable"), + SYM (__hashFunc.HashLookup, "_mesa_HashLookup"), + SYM (__hashFunc.HashInsert, "_mesa_HashInsert"), + SYM (__hashFunc.HashRemove, "_mesa_HashRemove"), + SYM (__hashFunc.HashFirstEntry, "_mesa_HashFirstEntry"), + SYM (__hashFunc.HashNextEntry, "_mesa_HashNextEntry"), + SYM (__hashFunc.HashFindFreeKeyBlock, "_mesa_HashFindFreeKeyBlock") + }; + + if (!xglLookupSymbols (handle, sym, sizeof (sym) / sizeof (sym[0]))) + return FALSE; + + hashHandle = handle; + + return TRUE; +#else + return FALSE; +#endif +} xglHashTablePtr xglNewHashTable (void) { - return (xglHashTablePtr) _mesa_NewHashTable (); + if (!hashHandle) + return 0; + + return (*__hashFunc.NewHashTable) (); } void xglDeleteHashTable (xglHashTablePtr pTable) { - _mesa_DeleteHashTable ((struct _mesa_HashTable *) pTable); + (*__hashFunc.DeleteHashTable) (pTable); } void * xglHashLookup (const xglHashTablePtr pTable, unsigned int key) { - return _mesa_HashLookup ((struct _mesa_HashTable *) pTable, key); + return (*__hashFunc.HashLookup) (pTable, key); } void @@ -84,35 +103,32 @@ xglHashInsert (xglHashTablePtr pTable, unsigned int key, void *data) { - _mesa_HashInsert ((struct _mesa_HashTable *) pTable, key, data); + (*__hashFunc.HashInsert) (pTable, key, data); } void xglHashRemove (xglHashTablePtr pTable, unsigned int key) { - _mesa_HashRemove ((struct _mesa_HashTable *) pTable, key); + (*__hashFunc.HashRemove) (pTable, key); } unsigned int xglHashFirstEntry (xglHashTablePtr pTable) { - return _mesa_HashFirstEntry ((struct _mesa_HashTable *) pTable); + return (*__hashFunc.HashFirstEntry) (pTable); } unsigned int xglHashNextEntry (const xglHashTablePtr pTable, unsigned int key) { - return _mesa_HashNextEntry ((struct _mesa_HashTable *) pTable, key); + return (*__hashFunc.HashNextEntry) (pTable, key); } unsigned int xglHashFindFreeKeyBlock (xglHashTablePtr pTable, unsigned int numKeys) { - return _mesa_HashFindFreeKeyBlock ((struct _mesa_HashTable *) pTable, - numKeys); + return (*__hashFunc.HashFindFreeKeyBlock) (pTable, numKeys); } - -#endif diff --git a/hw/xgl/xglinit.c b/hw/xgl/xglinit.c new file mode 100644 index 000000000..e6af7eef2 --- /dev/null +++ b/hw/xgl/xglinit.c @@ -0,0 +1,287 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#include "xgl.h" +#include "micmap.h" +#include "mipointer.h" +#include "fb.h" + +#define DEAFULT_DDX_MODULE_NAME "xglx" + +static char *ddxModuleName = DEAFULT_DDX_MODULE_NAME; + +xglScreenInfoRec xglScreenInfo = { + NULL, 0, 0, 0, 0, + DEFAULT_GEOMETRY_DATA_TYPE, + DEFAULT_GEOMETRY_USAGE, + FALSE, + XGL_DEFAULT_PBO_MASK, + FALSE, + FALSE +}; + +#ifdef GLXEXT +static Bool loadGlx = TRUE; +#endif + +typedef struct _xglDDXFunc { + void (*initOutput) (ScreenInfo *pScreenInfo, + int argc, + char **argv); + void (*initInput) (int argc, + char **argv); + Bool (*legalModifier) (unsigned int key, + DevicePtr pDev); + void (*processInputEvents) (void); + void (*useMsg) (void); + int (*processArgument) (int argc, + char **argv, + int i); + void (*abort) (void); + void (*giveUp) (void); + void (*osVendorInit) (void); +} xglDDXFuncRec; + +static xglDDXFuncRec __ddxFunc; + +#define SYMFUNC(name) ((void *) (name)) +#define SYMVAR(name) ((void *) &(name)) + +/* + * The following table is used to make sure that all symbols required by + * dynamically loaded modules are present in the main program. Add more symbols + * as needed. + */ + +void *symTab[] = { + SYMFUNC (xglKbdCtrl), + SYMFUNC (xglSetPixmapFormats), + SYMVAR (xglVisuals), + + SYMFUNC (mieqEnqueue), + SYMFUNC (mieqInit), + SYMFUNC (mieqProcessInputEvents), + SYMFUNC (miPointerAbsoluteCursor), + SYMFUNC (miRegisterPointerDevice), + SYMFUNC (miPointerWarpCursor), + SYMFUNC (miDCInitialize), + SYMFUNC (miPointerAbsoluteCursor), + SYMFUNC (miPointerUpdate), + SYMFUNC (miRegisterRedirectBorderClipProc) +}; + +#define SYM(ptr, name) { (void **) &(ptr), (name) } + +static Bool +xglEnsureDDXModule (void) +{ + +#ifdef XLOADABLE + static void *ddxHandle = 0; + static Bool status = TRUE; + + if (!status) + return FALSE; + + if (!ddxHandle) + { + xglSymbolRec sym[] = { + SYM (__ddxFunc.initOutput, "InitOutput"), + SYM (__ddxFunc.initInput, "InitInput"), + SYM (__ddxFunc.legalModifier, "LegalModifier"), + SYM (__ddxFunc.processInputEvents, "ProcessInputEvents"), + SYM (__ddxFunc.useMsg, "ddxUseMsg"), + SYM (__ddxFunc.processArgument, "ddxProcessArgument"), + SYM (__ddxFunc.abort, "AbortDDX"), + SYM (__ddxFunc.giveUp, "ddxGiveUp"), + SYM (__ddxFunc.osVendorInit, "OsVendorInit") + }; + + ddxHandle = xglLoadModule (ddxModuleName); + if (!ddxHandle) + return (status = FALSE); + + if (!xglLookupSymbols (ddxHandle, sym, sizeof (sym) / sizeof (sym[0]))) + { + xglUnloadModule (ddxHandle); + ddxHandle = 0; + + return (status = FALSE); + } + } + + return TRUE; +#else + return FALSE; +#endif + +} + +void +InitOutput (ScreenInfo *pScreenInfo, + int argc, + char **argv) +{ + (void) symTab; + + if (!xglEnsureDDXModule ()) + FatalError ("No DDX module loaded"); + +#ifdef GLXEXT + if (loadGlx) + { + if (!xglLoadGLXModules ()) + FatalError ("No GLX modules loaded"); + } +#endif + + (*__ddxFunc.initOutput) (pScreenInfo, argc, argv); +} + +Bool +LegalModifier (unsigned int key, + DevicePtr pDev) +{ + return (*__ddxFunc.legalModifier) (key, pDev); +} + +void +ProcessInputEvents (void) +{ + (*__ddxFunc.processInputEvents) (); +} + +void +InitInput (int argc, + char **argv) +{ + if (!xglEnsureDDXModule ()) + FatalError ("No DDX module loaded"); + + (*__ddxFunc.initInput) (argc, argv); +} + +void +ddxUseMsg (void) +{ + ErrorF ("\nXgl usage:\n"); + ErrorF ("-ddx module specify ddx module\n"); + +#ifdef GLXEXT + ErrorF ("-noglx don't load glx extension\n"); +#endif + + if (xglEnsureDDXModule ()) + (*__ddxFunc.useMsg) (); +} + +#define LOPT(s, l) { (s), (l) } +#define OPT(s) LOPT (s, 0) + +int +ddxProcessArgument (int argc, + char **argv, + int i) +{ + struct _option { + char *name; + int length; + } commonOption[] = { + LOPT (":", 1), OPT ("-a"), OPT ("-ac"), OPT ("-audit"), OPT ("-auth"), + OPT ("bc"), OPT ("-br"), OPT ("+bs"), OPT ("-bs"), OPT ("c"), OPT ("-c"), + OPT ("-cc"), OPT ("-co"), OPT ("-core"), OPT ("-dpi"), + OPT ("-deferglyphs"), OPT ("-f"), OPT ("-fc"), OPT ("-fn"), OPT ("-fp"), + OPT ("-help"), OPT ("-nolisten"), OPT ("-noreset"), OPT ("-p"), + OPT ("-pn"), OPT ("-nopn"), OPT ("r"), OPT ("-r"), OPT ("-s"), + OPT ("-su"), OPT ("-t"), OPT ("-terminate"), OPT ("-to"), OPT ("-tst"), + OPT ("v"), OPT ("-v"), OPT ("-wm"), OPT ("-x"), OPT ("-I"), + LOPT ("tty", 3) + }; + int skip, j; + + for (j = 0; j < sizeof (commonOption) / sizeof (commonOption[0]); j++) + { + if (commonOption[j].length) + { + if (!strncmp (argv[i], commonOption[j].name, commonOption[j].length)) + return 0; + } + else + { + if (!strcmp (argv[i], commonOption[j].name)) + return 0; + } + } + + if (!strcmp (argv[i], "-ddx")) + { + if ((i + 1) < argc) + { + ddxModuleName = argv[i + 1]; + } + else + return 1; + + return 2; + } + +#ifdef GLXEXT + else if (!strcmp (argv[i], "-noglx")) + { + loadGlx = FALSE; + return 1; + } +#endif + + skip = xglProcessArgument (argc, argv, i); + if (skip) + return skip; + + if (xglEnsureDDXModule ()) + return (*__ddxFunc.processArgument) (argc, argv, i); + + return 0; +} + +void +AbortDDX (void) +{ + if (xglEnsureDDXModule ()) + (*__ddxFunc.abort) (); +} + +void +ddxGiveUp (void) +{ + if (xglEnsureDDXModule ()) + (*__ddxFunc.giveUp) (); +} + +void +OsVendorInit (void) +{ + if (xglEnsureDDXModule ()) + (*__ddxFunc.osVendorInit) (); +} diff --git a/hw/xgl/xglloader.c b/hw/xgl/xglloader.c new file mode 100644 index 000000000..9a311aecd --- /dev/null +++ b/hw/xgl/xglloader.c @@ -0,0 +1,129 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#include "xgl.h" +#include "xglmodule.h" + +#ifdef XLOADABLE + +#include + +#define SYM(ptr, name) { (void **) &(ptr), (name) } + +void * +xglLoadModule (const char *name) +{ + ModuleVersionProcPtr moduleVersion; + ModuleInitProcPtr moduleInit; + void *handle = 0; + char *module; + xglSymbolRec mSym[] = { + SYM (moduleVersion, "moduleVersion"), + SYM (moduleInit, "moduleInit") + }; + + module = malloc (strlen (MODULEPATH "/xgl/lib.so") + strlen (name) + 1); + if (!module) + return 0; + + sprintf (module, MODULEPATH "/xgl/lib%s.so", name); + + handle = dlopen (module, RTLD_NOW); + if (handle) + { + if (xglLookupSymbols (handle, mSym, sizeof (mSym) / sizeof (mSym[0]))) + { + const char *version; + + version = (*moduleVersion) (); + if (strcmp (VERSION, version) == 0) + { + if (!(*moduleInit) (module)) + { + dlclose (handle); + handle = 0; + } + } + else + { + ErrorF ("Module version mismatch. " + "%s is %s Xserver is" VERSION "\n", + module, version); + + dlclose (handle); + handle = 0; + } + } + else + { + dlclose (handle); + handle = 0; + } + } + else + ErrorF ("dlopen: %s\n", dlerror ()); + + free (module); + + return handle; +} + +void +xglUnloadModule (void *handle) +{ + dlclose (handle); +} + +Bool +xglLookupSymbols (void *handle, + xglSymbolPtr sym, + int nSym) +{ + void *symbol; + char *error; + int i; + + /* avoid previous error */ + dlerror (); + + for (i = 0; i < nSym; i++) + { + symbol = dlsym (handle, sym[i].name); + if (!symbol) + { + error = dlerror (); + if (error != 0) + ErrorF ("dlsym: %s: %s\n", sym[i].name, error); + + return FALSE; + } + + *(sym[i].ptr) = symbol; + } + + return TRUE; +} + +#endif diff --git a/hw/xgl/xglmodule.h b/hw/xgl/xglmodule.h new file mode 100644 index 000000000..0dcabebca --- /dev/null +++ b/hw/xgl/xglmodule.h @@ -0,0 +1,45 @@ +/* + * Copyright © 2005 Novell, Inc. + * + * Permission to use, copy, modify, distribute, and sell this software + * and its documentation for any purpose is hereby granted without + * fee, provided that the above copyright notice appear in all copies + * and that both that copyright notice and this permission notice + * appear in supporting documentation, and that the name of + * Novell, Inc. not be used in advertising or publicity pertaining to + * distribution of the software without specific, written prior permission. + * Novell, Inc. makes no representations about the suitability of this + * software for any purpose. It is provided "as is" without express or + * implied warranty. + * + * NOVELL, INC. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN + * NO EVENT SHALL NOVELL, INC. BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS + * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, + * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION + * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Author: David Reveman + */ + +#ifndef _XGL_MODULE_H_ +#define _XGL_MODULE_H_ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include "misc.h" + +typedef const char *(*ModuleVersionProcPtr) (void); +typedef Bool (*ModuleInitProcPtr) (const char *module); + +char * +moduleVersion (void); + +Bool +moduleInit (const char *module); + +#endif /* _XGL_MODULE_H_ */ diff --git a/hw/xgl/xglparse.c b/hw/xgl/xglparse.c index 663d79872..c1f7e6527 100644 --- a/hw/xgl/xglparse.c +++ b/hw/xgl/xglparse.c @@ -44,18 +44,17 @@ xglParseFindNext (char *cur, } void -xglParseScreen (xglScreenInfoPtr pScreenInfo, - char *arg) +xglParseScreen (char *arg) { char delim; char save[1024]; int i, pixels, mm; - - pScreenInfo->width = 0; - pScreenInfo->height = 0; - pScreenInfo->widthMm = 0; - pScreenInfo->heightMm = 0; - + + xglScreenInfo.width = 0; + xglScreenInfo.height = 0; + xglScreenInfo.widthMm = 0; + xglScreenInfo.heightMm = 0; + if (!arg) return; @@ -82,13 +81,13 @@ xglParseScreen (xglScreenInfoPtr pScreenInfo, if (i == 0) { - pScreenInfo->width = pixels; - pScreenInfo->widthMm = mm; + xglScreenInfo.width = pixels; + xglScreenInfo.widthMm = mm; } else { - pScreenInfo->height = pixels; - pScreenInfo->heightMm = mm; + xglScreenInfo.height = pixels; + xglScreenInfo.heightMm = mm; } if (delim != 'x') @@ -99,79 +98,66 @@ xglParseScreen (xglScreenInfoPtr pScreenInfo, void xglUseMsg (void) { - ErrorF ("-screen WIDTH[/WIDTHMM]xHEIGHT[/HEIGHTMM] " - "specify screen characteristics\n"); - ErrorF ("-fullscreen run fullscreen\n"); ErrorF ("-vertextype [short|float] set vertex data type\n"); - ErrorF ("-vbostream " - "use vertex buffer objects for streaming of vertex data\n"); ErrorF ("-yinverted Y is upside-down\n"); - ErrorF ("-pbomask [1|4|8|16|32] " - "set bpp's to use with pixel buffer objects\n"); ErrorF ("-lines " "accelerate lines that are not vertical or horizontal\n"); + ErrorF ("-vbo " + "use vertex buffer objects for streaming of vertex data\n"); + ErrorF ("-pbomask [1|4|8|16|32] " + "set bpp's to use with pixel buffer objects\n"); + ErrorF ("-fbo " + "use frame buffer objects for accelerate offscreen drawing\n"); } int -xglProcessArgument (xglScreenInfoPtr pScreenInfo, - int argc, - char **argv, - int i) +xglProcessArgument (int argc, + char **argv, + int i) { - if (!strcmp (argv[i], "-screen")) + if (!strcmp (argv[i], "-vertextype")) { if ((i + 1) < argc) { - xglParseScreen (pScreenInfo, argv[i + 1]); + if (!strcasecmp (argv[i + 1], "short")) + xglScreenInfo.geometryDataType = GEOMETRY_DATA_TYPE_SHORT; + else if (!strcasecmp (argv[i + 1], "float")) + xglScreenInfo.geometryDataType = GEOMETRY_DATA_TYPE_FLOAT; } else return 1; return 2; } - else if (!strcmp (argv[i], "-fullscreen")) + else if (!strcmp (argv[i], "-yinverted")) { - pScreenInfo->fullscreen = TRUE; + xglScreenInfo.yInverted = TRUE; return 1; } - else if (!strcmp (argv[i], "-vertextype")) - { - if ((i + 1) < argc) - { - if (!strcasecmp (argv[i + 1], "short")) - pScreenInfo->geometryDataType = GEOMETRY_DATA_TYPE_SHORT; - else if (!strcasecmp (argv[i + 1], "float")) - pScreenInfo->geometryDataType = GEOMETRY_DATA_TYPE_FLOAT; - } - else - return 1; - - return 2; - } - else if (!strcmp (argv[i], "-vbostream")) + else if (!strcmp (argv[i], "-lines")) { - pScreenInfo->geometryUsage = GEOMETRY_USAGE_STREAM; + xglScreenInfo.lines = TRUE; return 1; } - else if (!strcmp (argv[i], "-yinverted")) + else if (!strcmp (argv[i], "-vbo")) { - pScreenInfo->yInverted = TRUE; + xglScreenInfo.geometryUsage = GEOMETRY_USAGE_STREAM; return 1; } else if (!strcmp (argv[i], "-pbomask")) { if ((i + 1) < argc) { - pScreenInfo->pboMask = atoi (argv[i + 1]); + xglScreenInfo.pboMask = atoi (argv[i + 1]); } else return 1; return 2; } - else if (!strcmp (argv[i], "-lines")) + else if (!strcmp (argv[i], "-fbo")) { - pScreenInfo->lines = TRUE; + xglScreenInfo.fbo = TRUE; return 1; } diff --git a/hw/xgl/xglpixmap.c b/hw/xgl/xglpixmap.c index c7c87f8c4..8f043081e 100644 --- a/hw/xgl/xglpixmap.c +++ b/hw/xgl/xglpixmap.c @@ -114,6 +114,8 @@ xglPixmapSurfaceInit (PixmapPtr pPixmap, if (width && height) { + XGL_SCREEN_PRIV (pPixmap->drawable.pScreen); + if (width == 1 && height == 1) { pPixmapPriv->acceleratedTile = TRUE; @@ -124,19 +126,27 @@ xglPixmapSurfaceInit (PixmapPtr pPixmap, (POWER_OF_TWO (width) && POWER_OF_TWO (height))) pPixmapPriv->acceleratedTile = TRUE; } - - pPixmapPriv->target = xglPixmapTargetOut; - - /* - * Do not allow accelerated drawing to bitmaps. - */ - if (pPixmap->drawable.depth == 1) - pPixmapPriv->target = xglPixmapTargetNo; /* - * Drawing to really small pixmaps is not worth accelerating. + * Accelerated drawing to pixmaps when using FBOs */ - if (width < 8 && height < 8) + if (pScreenPriv->fbo) + { + pPixmapPriv->target = xglPixmapTargetOut; + + /* + * Do not allow accelerated drawing to bitmaps. + */ + if (pPixmap->drawable.depth == 1) + pPixmapPriv->target = xglPixmapTargetNo; + + /* + * Drawing to really small pixmaps is not worth accelerating. + */ + if (width < 8 && height < 8) + pPixmapPriv->target = xglPixmapTargetNo; + } + else pPixmapPriv->target = xglPixmapTargetNo; } } diff --git a/hw/xgl/xglscreen.c b/hw/xgl/xglscreen.c index 76ea92241..26f2848c5 100644 --- a/hw/xgl/xglscreen.c +++ b/hw/xgl/xglscreen.c @@ -134,8 +134,7 @@ xglAllocatePrivates (ScreenPtr pScreen) } Bool -xglScreenInit (ScreenPtr pScreen, - xglScreenInfoPtr pScreenInfo) +xglScreenInit (ScreenPtr pScreen) { xglScreenPtr pScreenPriv; int depth, bpp; @@ -152,9 +151,9 @@ xglScreenInit (ScreenPtr pScreen, pScreenPriv->pScreenPixmap = NULL; pScreenPriv->pVisual = &xglVisuals[0]; - pScreenPriv->drawable = pScreenInfo->drawable; + pScreenPriv->drawable = xglScreenInfo.drawable; pScreenPriv->features = - glitz_drawable_get_features (pScreenInfo->drawable); + glitz_drawable_get_features (xglScreenInfo.drawable); depth = pScreenPriv->pVisual->pPixel->depth; bpp = pScreenPriv->pVisual->pPixel->masks.bpp; @@ -163,11 +162,12 @@ xglScreenInit (ScreenPtr pScreen, if (!pScreenPriv->pixmapFormats[depth].format) return FALSE; - pScreenPriv->geometryDataType = pScreenInfo->geometryDataType; - pScreenPriv->geometryUsage = pScreenInfo->geometryUsage; - pScreenPriv->yInverted = pScreenInfo->yInverted; - pScreenPriv->pboMask = pScreenInfo->pboMask; - pScreenPriv->lines = pScreenInfo->lines; + pScreenPriv->geometryDataType = xglScreenInfo.geometryDataType; + pScreenPriv->geometryUsage = xglScreenInfo.geometryUsage; + pScreenPriv->yInverted = xglScreenInfo.yInverted; + pScreenPriv->pboMask = xglScreenInfo.pboMask; + pScreenPriv->lines = xglScreenInfo.lines; + pScreenPriv->fbo = xglScreenInfo.fbo; GEOMETRY_INIT (pScreen, &pScreenPriv->scratchGeometry, GLITZ_GEOMETRY_TYPE_VERTEX, @@ -176,7 +176,7 @@ xglScreenInit (ScreenPtr pScreen, pScreenPriv->surface = glitz_surface_create (pScreenPriv->drawable, pScreenPriv->pixmapFormats[depth].format, - pScreenInfo->width, pScreenInfo->height, + xglScreenInfo.width, xglScreenInfo.height, 0, NULL); if (!pScreenPriv->surface) return FALSE; @@ -191,9 +191,9 @@ xglScreenInit (ScreenPtr pScreen, monitorResolution = XGL_DEFAULT_DPI; if (!fbSetupScreen (pScreen, NULL, - pScreenInfo->width, pScreenInfo->height, + xglScreenInfo.width, xglScreenInfo.height, monitorResolution, monitorResolution, - pScreenInfo->width, bpp)) + xglScreenInfo.width, bpp)) return FALSE; pScreen->SaveScreen = xglSaveScreen; @@ -202,9 +202,9 @@ xglScreenInit (ScreenPtr pScreen, pScreen->DestroyPixmap = xglDestroyPixmap; if (!fbFinishScreenInit (pScreen, NULL, - pScreenInfo->width, pScreenInfo->height, + xglScreenInfo.width, xglScreenInfo.height, monitorResolution, monitorResolution, - pScreenInfo->width, bpp)) + xglScreenInfo.width, bpp)) return FALSE; #ifdef MITSHM @@ -276,11 +276,6 @@ xglScreenInit (ScreenPtr pScreen, return FALSE; #endif -#ifdef GLXEXT - if (!xglInitVisualConfigs (pScreen)) - return FALSE; -#endif - /* Damage is required */ DamageSetup (pScreen); diff --git a/hw/xgl/xglsync.c b/hw/xgl/xglsync.c index 6299e1db8..0fa3aa05a 100644 --- a/hw/xgl/xglsync.c +++ b/hw/xgl/xglsync.c @@ -293,7 +293,13 @@ xglPrepareTarget (DrawablePtr pDrawable) switch (pPixmapPriv->target) { case xglPixmapTargetNo: + break; case xglPixmapTargetOut: + if (xglSyncSurface (pDrawable)) + { + pPixmapPriv->target = xglPixmapTargetIn; + return TRUE; + } break; case xglPixmapTargetIn: if (xglSyncSurface (pDrawable)) @@ -358,13 +364,48 @@ xglAddCurrentSurfaceDamage (DrawablePtr pDrawable) } } +void +xglAddBitDamage (DrawablePtr pDrawable, + RegionPtr pRegion) +{ + BoxPtr pBox; + BoxPtr pExt; + int nBox; + + XGL_DRAWABLE_PIXMAP_PRIV (pDrawable); + + pBox = REGION_RECTS (pRegion); + pExt = REGION_EXTENTS (pDrawable->pScreen, pRegion); + nBox = REGION_NUM_RECTS (pRegion); + + if (pExt->x1 < pPixmapPriv->bitBox.x2 && + pExt->y1 < pPixmapPriv->bitBox.y2 && + pExt->x2 > pPixmapPriv->bitBox.x1 && + pExt->y2 > pPixmapPriv->bitBox.y1) + { + while (nBox--) + { + if (pBox->x1 < pPixmapPriv->bitBox.x2 && + pBox->y1 < pPixmapPriv->bitBox.y2 && + pBox->x2 > pPixmapPriv->bitBox.x1 && + pBox->y2 > pPixmapPriv->bitBox.y1) + { + pPixmapPriv->bitBox = miEmptyBox; + pPixmapPriv->allBits = FALSE; + return; + } + + pBox++; + } + } +} + void xglAddCurrentBitDamage (DrawablePtr pDrawable) { XGL_DRAWABLE_PIXMAP_PRIV (pDrawable); - if (pPixmapPriv->target == xglPixmapTargetIn && - pPixmapPriv->damageBox.x1 < pPixmapPriv->bitBox.x2 && + if (pPixmapPriv->damageBox.x1 < pPixmapPriv->bitBox.x2 && pPixmapPriv->damageBox.y1 < pPixmapPriv->bitBox.y2 && pPixmapPriv->damageBox.x2 > pPixmapPriv->bitBox.x1 && pPixmapPriv->damageBox.y2 > pPixmapPriv->bitBox.y1) diff --git a/hw/xgl/xgltrap.c b/hw/xgl/xgltrap.c index c643f11a4..8f792a6c5 100644 --- a/hw/xgl/xgltrap.c +++ b/hw/xgl/xgltrap.c @@ -173,7 +173,7 @@ xglTrapezoids (CARD8 op, target = xglPrepareTarget (pDst->pDrawable); if (nTrap > 1 && op != PictOpAdd && maskFormat && - (overlap || op != PictOpOver)) + (!target || overlap || op != PictOpOver)) { PixmapPtr pPixmap; GCPtr pGC; -- cgit v1.2.3