From 76791db0882b3715cd7d0a47fd14e1f784901b09 Mon Sep 17 00:00:00 2001 From: Adam Jackson Date: Thu, 15 Apr 2021 10:07:40 -0700 Subject: [PATCH] mesa/x11: Remove the swrast-classic-based fake libGL If you want this you will almost certainly be happier with the gallium version, giving you llvmpipe instead of swrast-classic. Reviewed-by: Emma Anholt Reviewed-by: Dylan Baker Acked-by: Jason Ekstrand Acked-by: Kenneth Graunke Part-of: --- meson.build | 18 +- meson_options.txt | 2 +- src/gallium/meson.build | 2 +- src/mesa/drivers/x11/fakeglx.c | 2900 ------------------------------ src/mesa/drivers/x11/glxapi.c | 1252 ------------- src/mesa/drivers/x11/glxapi.h | 212 --- src/mesa/drivers/x11/glxheader.h | 51 - src/mesa/drivers/x11/meson.build | 39 - src/mesa/drivers/x11/xfonts.c | 370 ---- src/mesa/drivers/x11/xfonts.h | 37 - src/mesa/drivers/x11/xm_api.c | 1773 ------------------ src/mesa/drivers/x11/xm_buffer.c | 560 ------ src/mesa/drivers/x11/xm_dd.c | 921 ---------- src/mesa/drivers/x11/xm_line.c | 540 ------ src/mesa/drivers/x11/xm_tri.c | 1151 ------------ src/mesa/drivers/x11/xmesa.h | 381 ---- src/mesa/drivers/x11/xmesaP.h | 425 ----- src/mesa/drivers/x11/xmesa_x.h | 85 - src/mesa/meson.build | 3 - 19 files changed, 8 insertions(+), 10714 deletions(-) delete mode 100644 src/mesa/drivers/x11/fakeglx.c delete mode 100644 src/mesa/drivers/x11/glxapi.c delete mode 100644 src/mesa/drivers/x11/glxapi.h delete mode 100644 src/mesa/drivers/x11/glxheader.h delete mode 100644 src/mesa/drivers/x11/meson.build delete mode 100644 src/mesa/drivers/x11/xfonts.c delete mode 100644 src/mesa/drivers/x11/xfonts.h delete mode 100644 src/mesa/drivers/x11/xm_api.c delete mode 100644 src/mesa/drivers/x11/xm_buffer.c delete mode 100644 src/mesa/drivers/x11/xm_dd.c delete mode 100644 src/mesa/drivers/x11/xm_line.c delete mode 100644 src/mesa/drivers/x11/xm_tri.c delete mode 100644 src/mesa/drivers/x11/xmesa.h delete mode 100644 src/mesa/drivers/x11/xmesaP.h delete mode 100644 src/mesa/drivers/x11/xmesa_x.h diff --git a/meson.build b/meson.build index 23b17a3e2ac..e67b45d7d9e 100644 --- a/meson.build +++ b/meson.build @@ -562,16 +562,12 @@ endif if with_glx != 'disabled' if not (with_platform_x11 and with_any_opengl) error('Cannot build GLX support without X11 platform support and at least one OpenGL API') - elif with_glx == 'gallium-xlib' - if not with_gallium - error('Gallium-xlib based GLX requires at least one gallium driver') - elif not with_gallium_softpipe - error('Gallium-xlib based GLX requires softpipe or llvmpipe.') - elif with_dri - error('gallium-xlib conflicts with any dri driver') - endif elif with_glx == 'xlib' - if with_dri + if not with_gallium + error('xlib based GLX requires at least one gallium driver') + elif not with_gallium_softpipe + error('xlib based GLX requires softpipe or llvmpipe.') + elif with_dri error('xlib conflicts with any dri driver') endif elif with_glx == 'dri' @@ -586,7 +582,7 @@ glvnd_vendor_name = get_option('glvnd-vendor-name') if with_glvnd if with_platform_windows error('glvnd cannot be used on Windows') - elif with_glx == 'xlib' or with_glx == 'gallium-xlib' + elif with_glx == 'xlib' error('Cannot build glvnd support for GLX that is not DRI based.') elif with_glx == 'disabled' and not with_egl error('glvnd requires DRI based GLX and/or EGL') @@ -2246,8 +2242,6 @@ if with_glx != 'disabled' lines += 'GLX: DRI-based' elif with_glx == 'xlib' lines += 'GLX: Xlib-based' - elif with_glx == 'gallium-xlib' - lines += 'GLX: Xlib-based (Gallium)' else lines += 'GLX: ' + with_glx endif diff --git a/meson_options.txt b/meson_options.txt index fd0d99f2f9a..0a72ed2c58f 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -290,7 +290,7 @@ option( 'glx', type : 'combo', value : 'auto', - choices : ['auto', 'disabled', 'dri', 'xlib', 'gallium-xlib'], + choices : ['auto', 'disabled', 'dri', 'xlib'], description : 'Build support for GLX platform' ) option( diff --git a/src/gallium/meson.build b/src/gallium/meson.build index 0df0e886ce8..4da81ddd673 100644 --- a/src/gallium/meson.build +++ b/src/gallium/meson.build @@ -195,7 +195,7 @@ if with_osmesa subdir('frontends/osmesa') subdir('targets/osmesa') endif -if with_glx == 'gallium-xlib' +if with_glx == 'xlib' subdir('winsys/sw/xlib') subdir('frontends/glx/xlib') subdir('targets/libgl-xlib') diff --git a/src/mesa/drivers/x11/fakeglx.c b/src/mesa/drivers/x11/fakeglx.c deleted file mode 100644 index 6dc92b8d580..00000000000 --- a/src/mesa/drivers/x11/fakeglx.c +++ /dev/null @@ -1,2900 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2008 Brian Paul All Rights Reserved. - * Copyright (C) 2009 VMware, Inc. All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* - * This is an emulation of the GLX API which allows Mesa/GLX-based programs - * to run on X servers which do not have the real GLX extension. - * - * Thanks to the contributors: - * - * Initial version: Philip Brown (phil@bolthole.com) - * Better glXGetConfig() support: Armin Liebchen (liebchen@asylum.cs.utah.edu) - * Further visual-handling refinements: Wolfram Gloger - * (wmglo@Dent.MED.Uni-Muenchen.DE). - * - * Notes: - * Don't be fooled, stereo isn't supported yet. - */ - - -#include -#include -#include "glxheader.h" -#include "glxapi.h" -#include "main/context.h" -#include "main/config.h" -#include "main/macros.h" -#include "main/mtypes.h" -#include "main/version.h" -#include "xfonts.h" -#include "xmesaP.h" -#include "util/u_math.h" - -/* This indicates the client-side GLX API and GLX encoder version. */ -#define CLIENT_MAJOR_VERSION 1 -#define CLIENT_MINOR_VERSION 4 /* but don't have 1.3's pbuffers, etc yet */ - -/* This indicates the server-side GLX decoder version. - * GLX 1.4 indicates OpenGL 1.3 support - */ -#define SERVER_MAJOR_VERSION 1 -#define SERVER_MINOR_VERSION 4 - -/* This is appended onto the glXGetClient/ServerString version strings. */ -#define MESA_GLX_VERSION "Mesa " PACKAGE_VERSION - -/* Who implemented this GLX? */ -#define VENDOR "Brian Paul" - -#define EXTENSIONS \ - "GLX_MESA_set_3dfx_mode " \ - "GLX_MESA_copy_sub_buffer " \ - "GLX_MESA_pixmap_colormap " \ - "GLX_MESA_release_buffers " \ - "GLX_ARB_create_context " \ - "GLX_ARB_get_proc_address " \ - "GLX_EXT_texture_from_pixmap " \ - "GLX_EXT_visual_info " \ - "GLX_EXT_visual_rating " \ - /*"GLX_SGI_video_sync "*/ \ - "GLX_SGIX_fbconfig " \ - "GLX_SGIX_pbuffer " - - - -/**********************************************************************/ -/*** GLX Visual Code ***/ -/**********************************************************************/ - -#define DONT_CARE -1 - - -static XMesaVisual *VisualTable = NULL; -static int NumVisuals = 0; - - -/* - * This struct and some code fragments borrowed - * from Mark Kilgard's GLUT library. - */ -typedef struct _OverlayInfo { - /* Avoid 64-bit portability problems by being careful to use - longs due to the way XGetWindowProperty is specified. Note - that these parameters are passed as CARD32s over X - protocol. */ - unsigned long overlay_visual; - long transparent_type; - long value; - long layer; -} OverlayInfo; - - - -/* Macro to handle c_class vs class field name in XVisualInfo struct */ -#if defined(__cplusplus) || defined(c_plusplus) -#define CLASS c_class -#else -#define CLASS class -#endif - - - -/* - * Test if the given XVisualInfo is usable for Mesa rendering. - */ -static GLboolean -is_usable_visual( XVisualInfo *vinfo ) -{ - switch (vinfo->CLASS) { - case StaticGray: - case GrayScale: - /* Any StaticGray/GrayScale visual works in RGB or CI mode */ - return GL_TRUE; - case StaticColor: - case PseudoColor: - /* Color-index rendering is not supported. */ - return GL_FALSE; - case TrueColor: - case DirectColor: - /* Any depth of TrueColor or DirectColor works in RGB mode */ - return GL_TRUE; - default: - /* This should never happen */ - return GL_FALSE; - } -} - - - -/** - * Get an array OverlayInfo records for specified screen. - * \param dpy the display - * \param screen screen number - * \param numOverlays returns numver of OverlayInfo records - * \return pointer to OverlayInfo array, free with XFree() - */ -static OverlayInfo * -GetOverlayInfo(Display *dpy, int screen, int *numOverlays) -{ - Atom overlayVisualsAtom; - Atom actualType; - Status status; - unsigned char *ovInfo; - unsigned long sizeData, bytesLeft; - int actualFormat; - - /* - * The SERVER_OVERLAY_VISUALS property on the root window contains - * a list of overlay visuals. Get that list now. - */ - overlayVisualsAtom = XInternAtom(dpy,"SERVER_OVERLAY_VISUALS", True); - if (overlayVisualsAtom == None) { - return 0; - } - - status = XGetWindowProperty(dpy, RootWindow(dpy, screen), - overlayVisualsAtom, 0L, (long) 10000, False, - overlayVisualsAtom, &actualType, &actualFormat, - &sizeData, &bytesLeft, - &ovInfo); - - if (status != Success || actualType != overlayVisualsAtom || - actualFormat != 32 || sizeData < 4) { - /* something went wrong */ - free((void *) ovInfo); - *numOverlays = 0; - return NULL; - } - - *numOverlays = sizeData / 4; - return (OverlayInfo *) ovInfo; -} - - - -/** - * Return the level (overlay, normal, underlay) of a given XVisualInfo. - * Input: dpy - the X display - * vinfo - the XVisualInfo to test - * Return: level of the visual: - * 0 = normal planes - * >0 = overlay planes - * <0 = underlay planes - */ -static int -level_of_visual( Display *dpy, XVisualInfo *vinfo ) -{ - OverlayInfo *overlay_info; - int numOverlaysPerScreen, i; - - overlay_info = GetOverlayInfo(dpy, vinfo->screen, &numOverlaysPerScreen); - if (!overlay_info) { - return 0; - } - - /* search the overlay visual list for the visual ID of interest */ - for (i = 0; i < numOverlaysPerScreen; i++) { - const OverlayInfo *ov = overlay_info + i; - if (ov->overlay_visual == vinfo->visualid) { - /* found the visual */ - if (/*ov->transparent_type==1 &&*/ ov->layer!=0) { - int level = ov->layer; - free((void *) overlay_info); - return level; - } - else { - free((void *) overlay_info); - return 0; - } - } - } - - /* The visual ID was not found in the overlay list. */ - free((void *) overlay_info); - return 0; -} - - - - -/* - * Given an XVisualInfo and RGB, Double, and Depth buffer flags, save the - * configuration in our list of GLX visuals. - */ -static XMesaVisual -save_glx_visual( Display *dpy, XVisualInfo *vinfo, - GLboolean alphaFlag, GLboolean dbFlag, - GLboolean stereoFlag, - GLint depth_size, GLint stencil_size, - GLint accumRedSize, GLint accumGreenSize, - GLint accumBlueSize, GLint accumAlphaSize, - GLint level, GLint numAuxBuffers ) -{ - GLboolean ximageFlag = GL_TRUE; - XMesaVisual xmvis; - GLint i; - - if (dbFlag) { - /* Check if the MESA_BACK_BUFFER env var is set */ - char *backbuffer = getenv("MESA_BACK_BUFFER"); - if (backbuffer) { - if (backbuffer[0]=='p' || backbuffer[0]=='P') { - ximageFlag = GL_FALSE; - } - else if (backbuffer[0]=='x' || backbuffer[0]=='X') { - ximageFlag = GL_TRUE; - } - else { - _mesa_warning(NULL, "Mesa: invalid value for MESA_BACK_BUFFER environment variable, using an XImage."); - } - } - } - - if (stereoFlag) { - /* stereo not supported */ - return NULL; - } - - - /* Force the visual to have an alpha channel */ - if (getenv("MESA_GLX_FORCE_ALPHA")) - alphaFlag = GL_TRUE; - - /* First check if a matching visual is already in the list */ - for (i=0; idisplay == dpy - && v->ximage_flag == ximageFlag - && v->mesa_visual.doubleBufferMode == dbFlag - && v->mesa_visual.stereoMode == stereoFlag - && (v->mesa_visual.alphaBits > 0) == alphaFlag - && (v->mesa_visual.depthBits >= depth_size || depth_size == 0) - && (v->mesa_visual.stencilBits >= stencil_size || stencil_size == 0) - && (v->mesa_visual.accumRedBits >= accumRedSize || accumRedSize == 0) - && (v->mesa_visual.accumGreenBits >= accumGreenSize || accumGreenSize == 0) - && (v->mesa_visual.accumBlueBits >= accumBlueSize || accumBlueSize == 0) - && (v->mesa_visual.accumAlphaBits >= accumAlphaSize || accumAlphaSize == 0)) { - /* now compare visual IDs */ - if (v->visinfo->visualid == vinfo->visualid) { - return v; - } - } - } - - /* Create a new visual and add it to the list. */ - - xmvis = XMesaCreateVisual( dpy, vinfo, GL_TRUE, alphaFlag, dbFlag, - stereoFlag, ximageFlag, - depth_size, stencil_size, - accumRedSize, accumBlueSize, - accumBlueSize, accumAlphaSize, 0, level, - GLX_NONE_EXT ); - if (xmvis) { - /* Allocate more space for additional visual */ - VisualTable = realloc(VisualTable, sizeof(XMesaVisual) * (NumVisuals + 1)); - /* add xmvis to the list */ - VisualTable[NumVisuals] = xmvis; - NumVisuals++; - } - return xmvis; -} - - -/** - * Return the default number of bits for the Z buffer. - * If defined, use the MESA_GLX_DEPTH_BITS env var value. - * Otherwise, use the DEFAULT_SOFTWARE_DEPTH_BITS constant. - * XXX probably do the same thing for stencil, accum, etc. - */ -static GLint -default_depth_bits(void) -{ - int zBits; - const char *zEnv = getenv("MESA_GLX_DEPTH_BITS"); - if (zEnv) - zBits = atoi(zEnv); - else - zBits = DEFAULT_SOFTWARE_DEPTH_BITS; - return zBits; -} - -static GLint -default_alpha_bits(void) -{ - int aBits; - const char *aEnv = getenv("MESA_GLX_ALPHA_BITS"); - if (aEnv) - aBits = atoi(aEnv); - else - aBits = 0; - return aBits; -} - -static GLint -default_accum_bits(void) -{ - return 16; -} - - - -/* - * Create a GLX visual from a regular XVisualInfo. - * This is called when Fake GLX is given an XVisualInfo which wasn't - * returned by glXChooseVisual. Since this is the first time we're - * considering this visual we'll take a guess at reasonable values - * for depth buffer size, stencil size, accum size, etc. - * This is the best we can do with a client-side emulation of GLX. - */ -static XMesaVisual -create_glx_visual( Display *dpy, XVisualInfo *visinfo ) -{ - int vislevel; - GLint zBits = default_depth_bits(); - GLint accBits = default_accum_bits(); - GLboolean alphaFlag = default_alpha_bits() > 0; - - vislevel = level_of_visual( dpy, visinfo ); - if (vislevel) { - /* Color-index rendering to overlays is not supported. */ - return NULL; - } - else if (is_usable_visual( visinfo )) { - /* Configure this visual as RGB, double-buffered, depth-buffered. */ - /* This is surely wrong for some people's needs but what else */ - /* can be done? They should use glXChooseVisual(). */ - return save_glx_visual( dpy, visinfo, - alphaFlag, /* alpha */ - GL_TRUE, /* double */ - GL_FALSE, /* stereo */ - zBits, - 8, /* stencil bits */ - accBits, /* r */ - accBits, /* g */ - accBits, /* b */ - accBits, /* a */ - 0, /* level */ - 0 /* numAux */ - ); - } - else { - _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n"); - return NULL; - } -} - - - -/* - * Find the GLX visual associated with an XVisualInfo. - */ -static XMesaVisual -find_glx_visual( Display *dpy, XVisualInfo *vinfo ) -{ - int i; - - /* try to match visual id */ - for (i=0;idisplay==dpy - && VisualTable[i]->visinfo->visualid == vinfo->visualid) { - return VisualTable[i]; - } - } - - return NULL; -} - - - -/** - * Return the transparent pixel value for a GLX visual. - * Input: glxvis - the glx_visual - * Return: a pixel value or -1 if no transparent pixel - */ -static int -transparent_pixel( XMesaVisual glxvis ) -{ - Display *dpy = glxvis->display; - XVisualInfo *vinfo = glxvis->visinfo; - OverlayInfo *overlay_info; - int numOverlaysPerScreen, i; - - overlay_info = GetOverlayInfo(dpy, vinfo->screen, &numOverlaysPerScreen); - if (!overlay_info) { - return -1; - } - - for (i = 0; i < numOverlaysPerScreen; i++) { - const OverlayInfo *ov = overlay_info + i; - if (ov->overlay_visual == vinfo->visualid) { - /* found it! */ - if (ov->transparent_type == 0) { - /* type 0 indicates no transparency */ - free((void *) overlay_info); - return -1; - } - else { - /* ov->value is the transparent pixel */ - free((void *) overlay_info); - return ov->value; - } - } - } - - /* The visual ID was not found in the overlay list. */ - free((void *) overlay_info); - return -1; -} - - - -/** - * Try to get an X visual which matches the given arguments. - */ -static XVisualInfo * -get_visual( Display *dpy, int scr, unsigned int depth, int xclass ) -{ - XVisualInfo temp, *vis; - long mask; - int n; - unsigned int default_depth; - int default_class; - - mask = VisualScreenMask | VisualDepthMask | VisualClassMask; - temp.screen = scr; - temp.depth = depth; - temp.CLASS = xclass; - - default_depth = DefaultDepth(dpy,scr); - default_class = DefaultVisual(dpy,scr)->CLASS; - - if (depth==default_depth && xclass==default_class) { - /* try to get root window's visual */ - temp.visualid = DefaultVisual(dpy,scr)->visualid; - mask |= VisualIDMask; - } - - vis = XGetVisualInfo( dpy, mask, &temp, &n ); - - /* In case bits/pixel > 24, make sure color channels are still <=8 bits. - * An SGI Infinite Reality system, for example, can have 30bpp pixels: - * 10 bits per color channel. Mesa's limited to a max of 8 bits/channel. - */ - if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) { - if (util_bitcount((GLuint) vis->red_mask ) <= 8 && - util_bitcount((GLuint) vis->green_mask) <= 8 && - util_bitcount((GLuint) vis->blue_mask ) <= 8) { - return vis; - } - else { - free((void *) vis); - return NULL; - } - } - - return vis; -} - - - -/* - * Retrieve the value of the given environment variable and find - * the X visual which matches it. - * Input: dpy - the display - * screen - the screen number - * varname - the name of the environment variable - * Return: an XVisualInfo pointer to NULL if error. - */ -static XVisualInfo * -get_env_visual(Display *dpy, int scr, const char *varname) -{ - char value[100], type[100]; - int depth, xclass = -1; - XVisualInfo *vis; - - if (!getenv( varname )) { - return NULL; - } - - strncpy( value, getenv(varname), 100 ); - value[99] = 0; - - sscanf( value, "%s %d", type, &depth ); - - if (strcmp(type,"TrueColor")==0) xclass = TrueColor; - else if (strcmp(type,"DirectColor")==0) xclass = DirectColor; - else if (strcmp(type,"GrayScale")==0) xclass = GrayScale; - else if (strcmp(type,"StaticGray")==0) xclass = StaticGray; - - if (xclass>-1 && depth>0) { - vis = get_visual( dpy, scr, depth, xclass ); - if (vis) { - return vis; - } - } - - _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.", - type, depth); - - return NULL; -} - - - -/* - * Select an X visual which satisfies the RGBA/CI flag and minimum depth. - * Input: dpy, screen - X display and screen number - * min_depth - minimum visual depth - * preferred_class - preferred GLX visual class or DONT_CARE - * Return: pointer to an XVisualInfo or NULL. - */ -static XVisualInfo * -choose_x_visual(Display *dpy, int screen, int min_depth, int preferred_class) -{ - XVisualInfo *vis; - int xclass, visclass = 0; - int depth; - - /* First see if the MESA_RGB_VISUAL env var is defined */ - vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" ); - if (vis) { - return vis; - } - /* Otherwise, search for a suitable visual */ - if (preferred_class==DONT_CARE) { - for (xclass=0;xclass<4;xclass++) { - switch (xclass) { - case 0: visclass = TrueColor; break; - case 1: visclass = DirectColor; break; - case 2: visclass = GrayScale; break; - case 3: visclass = StaticGray; break; - } - if (min_depth==0) { - /* start with shallowest */ - for (depth=0;depth<=32;depth++) { - vis = get_visual( dpy, screen, depth, visclass ); - if (vis) { - return vis; - } - } - } - else { - /* start with deepest */ - for (depth=32;depth>=min_depth;depth--) { - vis = get_visual( dpy, screen, depth, visclass ); - if (vis) { - return vis; - } - } - } - } - } - else { - /* search for a specific visual class */ - switch (preferred_class) { - case GLX_TRUE_COLOR_EXT: visclass = TrueColor; break; - case GLX_DIRECT_COLOR_EXT: visclass = DirectColor; break; - case GLX_GRAY_SCALE_EXT: visclass = GrayScale; break; - case GLX_STATIC_GRAY_EXT: visclass = StaticGray; break; - case GLX_PSEUDO_COLOR_EXT: - case GLX_STATIC_COLOR_EXT: - default: return NULL; - } - if (min_depth==0) { - /* start with shallowest */ - for (depth=0;depth<=32;depth++) { - vis = get_visual( dpy, screen, depth, visclass ); - if (vis) { - return vis; - } - } - } - else { - /* start with deepest */ - for (depth=32;depth>=min_depth;depth--) { - vis = get_visual( dpy, screen, depth, visclass ); - if (vis) { - return vis; - } - } - } - } - - /* didn't find a visual */ - return NULL; -} - - - -/* - * Find the deepest X over/underlay visual of at least min_depth. - * Input: dpy, screen - X display and screen number - * level - the over/underlay level - * trans_type - transparent pixel type: GLX_NONE_EXT, - * GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT, - * or DONT_CARE - * trans_value - transparent pixel value or DONT_CARE - * min_depth - minimum visual depth - * preferred_class - preferred GLX visual class or DONT_CARE - * Return: pointer to an XVisualInfo or NULL. - */ -static XVisualInfo * -choose_x_overlay_visual( Display *dpy, int scr, - int level, int trans_type, int trans_value, - int min_depth, int preferred_class ) -{ - OverlayInfo *overlay_info; - int numOverlaysPerScreen; - int i; - XVisualInfo *deepvis; - int deepest; - - /*DEBUG int tt, tv; */ - - switch (preferred_class) { - case GLX_TRUE_COLOR_EXT: preferred_class = TrueColor; break; - case GLX_DIRECT_COLOR_EXT: preferred_class = DirectColor; break; - case GLX_PSEUDO_COLOR_EXT: preferred_class = PseudoColor; break; - case GLX_STATIC_COLOR_EXT: preferred_class = StaticColor; break; - case GLX_GRAY_SCALE_EXT: preferred_class = GrayScale; break; - case GLX_STATIC_GRAY_EXT: preferred_class = StaticGray; break; - default: preferred_class = DONT_CARE; - } - - overlay_info = GetOverlayInfo(dpy, scr, &numOverlaysPerScreen); - if (!overlay_info) { - return NULL; - } - - /* Search for the deepest overlay which satisifies all criteria. */ - deepest = min_depth; - deepvis = NULL; - - for (i = 0; i < numOverlaysPerScreen; i++) { - const OverlayInfo *ov = overlay_info + i; - XVisualInfo *vislist, vistemplate; - int count; - - if (ov->layer!=level) { - /* failed overlay level criteria */ - continue; - } - if (!(trans_type==DONT_CARE - || (trans_type==GLX_TRANSPARENT_INDEX_EXT - && ov->transparent_type>0) - || (trans_type==GLX_NONE_EXT && ov->transparent_type==0))) { - /* failed transparent pixel type criteria */ - continue; - } - if (trans_value!=DONT_CARE && trans_value!=ov->value) { - /* failed transparent pixel value criteria */ - continue; - } - - /* get XVisualInfo and check the depth */ - vistemplate.visualid = ov->overlay_visual; - vistemplate.screen = scr; - vislist = XGetVisualInfo( dpy, VisualIDMask | VisualScreenMask, - &vistemplate, &count ); - - if (!vislist) { - /* no matches */ - continue; - } - - if (count!=1) { - /* something went wrong */ - free(vislist); - continue; - } - if (preferred_class!=DONT_CARE && preferred_class!=vislist->CLASS) { - /* wrong visual class */ - free(vislist); - continue; - } - - /* Color-index rendering is not supported. Make sure we have True/DirectColor */ - if (vislist->CLASS != TrueColor && vislist->CLASS != DirectColor) { - free(vislist); - continue; - } - - if (deepvis!=NULL && vislist->depth <= deepest) { - free(vislist); - continue; - } - - /* YES! found a satisfactory visual */ - free(deepvis); - deepest = vislist->depth; - deepvis = vislist; - /* DEBUG tt = ov->transparent_type;*/ - /* DEBUG tv = ov->value; */ - } - -/*DEBUG - if (deepvis) { - printf("chose 0x%x: layer=%d depth=%d trans_type=%d trans_value=%d\n", - deepvis->visualid, level, deepvis->depth, tt, tv ); - } -*/ - return deepvis; -} - - -/**********************************************************************/ -/*** Display-related functions ***/ -/**********************************************************************/ - - -/** - * Free all XMesaVisuals which are associated with the given display. - */ -static void -destroy_visuals_on_display(Display *dpy) -{ - int i; - for (i = 0; i < NumVisuals; i++) { - if (VisualTable[i]->display == dpy) { - /* remove this visual */ - int j; - XMesaDestroyVisual(VisualTable[i]); - for (j = i; j < NumVisuals - 1; j++) - VisualTable[j] = VisualTable[j + 1]; - NumVisuals--; - } - } -} - - -/** - * Called from XCloseDisplay() to let us free our display-related data. - */ -static int -close_display_callback(Display *dpy, XExtCodes *codes) -{ - destroy_visuals_on_display(dpy); - xmesa_destroy_buffers_on_display(dpy); - return 0; -} - - -/** - * Look for the named extension on given display and return a pointer - * to the _XExtension data, or NULL if extension not found. - */ -static _XExtension * -lookup_extension(Display *dpy, const char *extName) -{ - _XExtension *ext; - for (ext = dpy->ext_procs; ext; ext = ext->next) { - if (ext->name && strcmp(ext->name, extName) == 0) { - return ext; - } - } - return NULL; -} - - -/** - * Whenever we're given a new Display pointer, call this function to - * register our close_display_callback function. - */ -static void -register_with_display(Display *dpy) -{ - const char *extName = "MesaGLX"; - _XExtension *ext; - - ext = lookup_extension(dpy, extName); - if (!ext) { - XExtCodes *c = XAddExtension(dpy); - ext = dpy->ext_procs; /* new extension is at head of list */ - assert(c->extension == ext->codes.extension); - (void) c; /* silence warning */ - ext->name = strdup(extName); - ext->close_display = close_display_callback; - } -} - - -/**********************************************************************/ -/*** Begin Fake GLX API Functions ***/ -/**********************************************************************/ - - -/** - * Helper used by glXChooseVisual and glXChooseFBConfig. - * The fbConfig parameter must be GL_FALSE for the former and GL_TRUE for - * the later. - * In either case, the attribute list is terminated with the value 'None'. - */ -static XMesaVisual -choose_visual( Display *dpy, int screen, const int *list, GLboolean fbConfig ) -{ - const GLboolean rgbModeDefault = fbConfig; - const int *parselist; - XVisualInfo *vis; - int min_ci = 0; - int min_red=0, min_green=0, min_blue=0; - GLboolean rgb_flag = rgbModeDefault; - GLboolean alpha_flag = GL_FALSE; - GLboolean double_flag = GL_FALSE; - GLboolean stereo_flag = GL_FALSE; - GLint depth_size = 0; - GLint stencil_size = 0; - GLint accumRedSize = 0; - GLint accumGreenSize = 0; - GLint accumBlueSize = 0; - GLint accumAlphaSize = 0; - int level = 0; - int visual_type = DONT_CARE; - int trans_type = DONT_CARE; - int trans_value = DONT_CARE; - GLint caveat = DONT_CARE; - XMesaVisual xmvis = NULL; - int desiredVisualID = -1; - int numAux = 0; - - parselist = list; - - while (*parselist) { - - if (fbConfig && - parselist[1] == GLX_DONT_CARE && - parselist[0] != GLX_LEVEL) { - /* For glXChooseFBConfig(), skip attributes whose value is - * GLX_DONT_CARE (-1), unless it's GLX_LEVEL (which can legitimately be - * a negative value). - * - * From page 17 (23 of the pdf) of the GLX 1.4 spec: - * GLX DONT CARE may be specified for all attributes except GLX LEVEL. - */ - parselist += 2; - continue; - } - - switch (*parselist) { - case GLX_USE_GL: - if (fbConfig) { - /* invalid token */ - return NULL; - } - else { - /* skip */ - parselist++; - } - break; - case GLX_BUFFER_SIZE: - parselist++; - min_ci = *parselist++; - break; - case GLX_LEVEL: - parselist++; - level = *parselist++; - break; - case GLX_RGBA: - if (fbConfig) { - /* invalid token */ - return NULL; - } - else { - rgb_flag = GL_TRUE; - parselist++; - } - break; - case GLX_DOUBLEBUFFER: - parselist++; - if (fbConfig) { - double_flag = *parselist++; - } - else { - double_flag = GL_TRUE; - } - break; - case GLX_STEREO: - parselist++; - if (fbConfig) { - stereo_flag = *parselist++; - } - else { - stereo_flag = GL_TRUE; - } - break; - case GLX_AUX_BUFFERS: - parselist++; - numAux = *parselist++; - if (numAux > MAX_AUX_BUFFERS) - return NULL; - break; - case GLX_RED_SIZE: - parselist++; - min_red = *parselist++; - break; - case GLX_GREEN_SIZE: - parselist++; - min_green = *parselist++; - break; - case GLX_BLUE_SIZE: - parselist++; - min_blue = *parselist++; - break; - case GLX_ALPHA_SIZE: - parselist++; - { - GLint size = *parselist++; - alpha_flag = size ? GL_TRUE : GL_FALSE; - } - break; - case GLX_DEPTH_SIZE: - parselist++; - depth_size = *parselist++; - break; - case GLX_STENCIL_SIZE: - parselist++; - stencil_size = *parselist++; - break; - case GLX_ACCUM_RED_SIZE: - parselist++; - { - GLint size = *parselist++; - accumRedSize = MAX2( accumRedSize, size ); - } - break; - case GLX_ACCUM_GREEN_SIZE: - parselist++; - { - GLint size = *parselist++; - accumGreenSize = MAX2( accumGreenSize, size ); - } - break; - case GLX_ACCUM_BLUE_SIZE: - parselist++; - { - GLint size = *parselist++; - accumBlueSize = MAX2( accumBlueSize, size ); - } - break; - case GLX_ACCUM_ALPHA_SIZE: - parselist++; - { - GLint size = *parselist++; - accumAlphaSize = MAX2( accumAlphaSize, size ); - } - break; - - /* - * GLX_EXT_visual_info extension - */ - case GLX_X_VISUAL_TYPE_EXT: - parselist++; - visual_type = *parselist++; - break; - case GLX_TRANSPARENT_TYPE_EXT: - parselist++; - trans_type = *parselist++; - break; - case GLX_TRANSPARENT_INDEX_VALUE_EXT: - parselist++; - trans_value = *parselist++; - break; - case GLX_TRANSPARENT_RED_VALUE_EXT: - case GLX_TRANSPARENT_GREEN_VALUE_EXT: - case GLX_TRANSPARENT_BLUE_VALUE_EXT: - case GLX_TRANSPARENT_ALPHA_VALUE_EXT: - /* ignore */ - parselist++; - parselist++; - break; - - /* - * GLX_EXT_visual_info extension - */ - case GLX_VISUAL_CAVEAT_EXT: - parselist++; - caveat = *parselist++; /* ignored for now */ - break; - - /* - * GLX_ARB_multisample - */ - case GLX_SAMPLE_BUFFERS_ARB: - case GLX_SAMPLES_ARB: - parselist++; - if (*parselist++ != 0) - /* ms not supported */ - return NULL; - break; - - /* - * FBConfig attribs. - */ - case GLX_RENDER_TYPE: - if (!fbConfig) - return NULL; - parselist++; - if (*parselist & GLX_RGBA_BIT) { - rgb_flag = GL_TRUE; - } - else if (*parselist & GLX_COLOR_INDEX_BIT) { - rgb_flag = GL_FALSE; - } - else if (*parselist & (GLX_RGBA_FLOAT_BIT_ARB|GLX_RGBA_UNSIGNED_FLOAT_BIT_EXT)) { - rgb_flag = GL_TRUE; - } - else if (*parselist == 0) { - rgb_flag = GL_TRUE; - } - parselist++; - break; - case GLX_DRAWABLE_TYPE: - if (!fbConfig) - return NULL; - parselist++; - if (*parselist & ~(GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT)) { - return NULL; /* bad bit */ - } - parselist++; - break; - case GLX_FBCONFIG_ID: - case GLX_VISUAL_ID: - if (!fbConfig) - return NULL; - parselist++; - desiredVisualID = *parselist++; - break; - case GLX_X_RENDERABLE: - case GLX_MAX_PBUFFER_WIDTH: - case GLX_MAX_PBUFFER_HEIGHT: - case GLX_MAX_PBUFFER_PIXELS: - if (!fbConfig) - return NULL; - parselist += 2; - /* ignore */ - break; - - case GLX_BIND_TO_TEXTURE_RGB_EXT: - parselist++; /*skip*/ - break; - case GLX_BIND_TO_TEXTURE_RGBA_EXT: - parselist++; /*skip*/ - break; - case GLX_BIND_TO_MIPMAP_TEXTURE_EXT: - parselist++; /*skip*/ - break; - case GLX_BIND_TO_TEXTURE_TARGETS_EXT: - parselist++; - if (*parselist & ~(GLX_TEXTURE_1D_BIT_EXT | - GLX_TEXTURE_2D_BIT_EXT | - GLX_TEXTURE_RECTANGLE_BIT_EXT)) { - /* invalid bit */ - return NULL; - } - break; - case GLX_Y_INVERTED_EXT: - parselist++; /*skip*/ - break; - - case None: - /* end of list */ - break; - - default: - /* undefined attribute */ - _mesa_warning(NULL, "unexpected attrib 0x%x in choose_visual()", - *parselist); - return NULL; - } - } - - if (!rgb_flag) - return NULL; - - (void) caveat; - (void) min_ci; - - /* - * Since we're only simulating the GLX extension this function will never - * find any real GL visuals. Instead, all we can do is try to find an RGB - * or CI visual of appropriate depth. Other requested attributes such as - * double buffering, depth buffer, etc. will be associated with the X - * visual and stored in the VisualTable[]. - */ - if (desiredVisualID != -1) { - /* try to get a specific visual, by visualID */ - XVisualInfo temp; - int n; - temp.visualid = desiredVisualID; - temp.screen = screen; - vis = XGetVisualInfo(dpy, VisualIDMask | VisualScreenMask, &temp, &n); - if (vis) { - /* give the visual some useful GLX attributes */ - double_flag = GL_TRUE; - if (vis->depth <= 8) - return NULL; - depth_size = default_depth_bits(); - stencil_size = 8; - /* XXX accum??? */ - } - } - else { - /* RGB visual */ - int min_rgb = min_red + min_green + min_blue; - if (min_rgb>1 && min_rgb<8) { - /* a special case to be sure we can get a monochrome visual */ - min_rgb = 1; - } - - if (level==0) { - vis = choose_x_visual(dpy, screen, min_rgb, visual_type); - } - else { - vis = choose_x_overlay_visual(dpy, screen, level, - trans_type, trans_value, min_rgb, visual_type); - } - } - - if (vis) { - /* Note: we're not exactly obeying the glXChooseVisual rules here. - * When GLX_DEPTH_SIZE = 1 is specified we're supposed to choose the - * largest depth buffer size, which is 32bits/value. Instead, we - * return 16 to maintain performance with earlier versions of Mesa. - */ - if (depth_size > 24) - depth_size = 32; - else if (depth_size > 16) - depth_size = 24; - else if (depth_size > 0) { - depth_size = default_depth_bits(); - } - - if (!alpha_flag) { - alpha_flag = default_alpha_bits() > 0; - } - - /* we only support one size of stencil and accum buffers. */ - if (stencil_size > 0) - stencil_size = 8; - if (accumRedSize > 0 || accumGreenSize > 0 || accumBlueSize > 0 || - accumAlphaSize > 0) { - accumRedSize = - accumGreenSize = - accumBlueSize = default_accum_bits(); - accumAlphaSize = alpha_flag ? accumRedSize : 0; - } - - xmvis = save_glx_visual( dpy, vis, alpha_flag, double_flag, - stereo_flag, depth_size, stencil_size, - accumRedSize, accumGreenSize, - accumBlueSize, accumAlphaSize, level, numAux ); - free(vis); - } - - return xmvis; -} - - -static XVisualInfo * -Fake_glXChooseVisual( Display *dpy, int screen, int *list ) -{ - XMesaVisual xmvis; - - /* register ourselves as an extension on this display */ - register_with_display(dpy); - - xmvis = choose_visual(dpy, screen, list, GL_FALSE); - if (xmvis) { - XVisualInfo* visinfo = malloc(sizeof(XVisualInfo)); - if (visinfo) { - memcpy(visinfo, xmvis->visinfo, sizeof(XVisualInfo)); - } - return visinfo; - } - else - return NULL; -} - - -static GLXContext -Fake_glXCreateContext( Display *dpy, XVisualInfo *visinfo, - GLXContext share_list, Bool direct ) -{ - XMesaVisual xmvis; - XMesaContext xmesaCtx; - - if (!dpy || !visinfo) - return 0; - - /* deallocate unused windows/buffers */ -#if 0 - XMesaGarbageCollect(dpy); -#endif - - xmvis = find_glx_visual( dpy, visinfo ); - if (!xmvis) { - /* This visual wasn't found with glXChooseVisual() */ - xmvis = create_glx_visual( dpy, visinfo ); - if (!xmvis) { - return NULL; - } - } - - xmesaCtx = XMesaCreateContext(xmvis, (XMesaContext) share_list); - - return (GLXContext) xmesaCtx; -} - - -/* XXX these may have to be removed due to thread-safety issues. */ -static GLXContext MakeCurrent_PrevContext = 0; -static GLXDrawable MakeCurrent_PrevDrawable = 0; -static GLXDrawable MakeCurrent_PrevReadable = 0; -static XMesaBuffer MakeCurrent_PrevDrawBuffer = 0; -static XMesaBuffer MakeCurrent_PrevReadBuffer = 0; - - -/* GLX 1.3 and later */ -static Bool -Fake_glXMakeContextCurrent( Display *dpy, GLXDrawable draw, - GLXDrawable read, GLXContext ctx ) -{ - if (ctx && draw && read) { - XMesaBuffer drawBuffer, readBuffer; - XMesaContext xmctx = (XMesaContext) ctx; - - /* Find the XMesaBuffer which corresponds to the GLXDrawable 'draw' */ - if (ctx == MakeCurrent_PrevContext - && draw == MakeCurrent_PrevDrawable) { - drawBuffer = MakeCurrent_PrevDrawBuffer; - } - else { - drawBuffer = XMesaFindBuffer( dpy, draw ); - } - if (!drawBuffer) { - /* drawable must be a new window! */ - drawBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, draw ); - if (!drawBuffer) { - /* Out of memory, or context/drawable depth mismatch */ - return False; - } - } - - /* Find the XMesaBuffer which corresponds to the GLXDrawable 'read' */ - if (ctx == MakeCurrent_PrevContext - && read == MakeCurrent_PrevReadable) { - readBuffer = MakeCurrent_PrevReadBuffer; - } - else { - readBuffer = XMesaFindBuffer( dpy, read ); - } - if (!readBuffer) { - /* drawable must be a new window! */ - readBuffer = XMesaCreateWindowBuffer( xmctx->xm_visual, read ); - if (!readBuffer) { - /* Out of memory, or context/drawable depth mismatch */ - return False; - } - } - - MakeCurrent_PrevContext = ctx; - MakeCurrent_PrevDrawable = draw; - MakeCurrent_PrevReadable = read; - MakeCurrent_PrevDrawBuffer = drawBuffer; - MakeCurrent_PrevReadBuffer = readBuffer; - - /* Now make current! */ - return XMesaMakeCurrent2(xmctx, drawBuffer, readBuffer); - } - else if (!ctx && !draw && !read) { - /* release current context w/out assigning new one. */ - XMesaMakeCurrent( NULL, NULL ); - MakeCurrent_PrevContext = 0; - MakeCurrent_PrevDrawable = 0; - MakeCurrent_PrevReadable = 0; - MakeCurrent_PrevDrawBuffer = 0; - MakeCurrent_PrevReadBuffer = 0; - return True; - } - else { - /* The args must either all be non-zero or all zero. - * This is an error. - */ - return False; - } -} - - -static Bool -Fake_glXMakeCurrent( Display *dpy, GLXDrawable drawable, GLXContext ctx ) -{ - return Fake_glXMakeContextCurrent( dpy, drawable, drawable, ctx ); -} - - -static GLXPixmap -Fake_glXCreateGLXPixmap( Display *dpy, XVisualInfo *visinfo, Pixmap pixmap ) -{ - XMesaVisual v; - XMesaBuffer b; - - v = find_glx_visual( dpy, visinfo ); - if (!v) { - v = create_glx_visual( dpy, visinfo ); - if (!v) { - /* unusable visual */ - return 0; - } - } - - b = XMesaCreatePixmapBuffer( v, pixmap, 0 ); - if (!b) { - return 0; - } - return b->frontxrb->pixmap; -} - - -/*** GLX_MESA_pixmap_colormap ***/ - -static GLXPixmap -Fake_glXCreateGLXPixmapMESA( Display *dpy, XVisualInfo *visinfo, - Pixmap pixmap, Colormap cmap ) -{ - XMesaVisual v; - XMesaBuffer b; - - v = find_glx_visual( dpy, visinfo ); - if (!v) { - v = create_glx_visual( dpy, visinfo ); - if (!v) { - /* unusable visual */ - return 0; - } - } - - b = XMesaCreatePixmapBuffer( v, pixmap, cmap ); - if (!b) { - return 0; - } - return b->frontxrb->pixmap; -} - - -static void -Fake_glXDestroyGLXPixmap( Display *dpy, GLXPixmap pixmap ) -{ - XMesaBuffer b = XMesaFindBuffer(dpy, pixmap); - if (b) { - XMesaDestroyBuffer(b); - } - else if (getenv("MESA_DEBUG")) { - _mesa_warning(NULL, "Mesa: glXDestroyGLXPixmap: invalid pixmap\n"); - } -} - - -static void -Fake_glXCopyContext( Display *dpy, GLXContext src, GLXContext dst, - unsigned long mask ) -{ - XMesaContext xmSrc = (XMesaContext) src; - XMesaContext xmDst = (XMesaContext) dst; - (void) dpy; - if (MakeCurrent_PrevContext == src) { - _mesa_Flush(); - } - _mesa_copy_context( &xmSrc->mesa, &xmDst->mesa, (GLuint) mask ); -} - - -static Bool -Fake_glXQueryExtension( Display *dpy, int *errorBase, int *eventBase ) -{ - int op, ev, err; - /* Mesa's GLX isn't really an X extension but we try to act like one. */ - if (!XQueryExtension(dpy, GLX_EXTENSION_NAME, &op, &ev, &err)) - ev = err = 0; - if (errorBase) - *errorBase = err; - if (eventBase) - *eventBase = ev; - return True; /* we're faking GLX so always return success */ -} - - -extern void _kw_ungrab_all( Display *dpy ); -void _kw_ungrab_all( Display *dpy ) -{ - XUngrabPointer( dpy, CurrentTime ); - XUngrabKeyboard( dpy, CurrentTime ); -} - - -static void -Fake_glXDestroyContext( Display *dpy, GLXContext ctx ) -{ - if (ctx) { - (void) dpy; - MakeCurrent_PrevContext = 0; - MakeCurrent_PrevDrawable = 0; - MakeCurrent_PrevReadable = 0; - MakeCurrent_PrevDrawBuffer = 0; - MakeCurrent_PrevReadBuffer = 0; - XMesaDestroyContext((XMesaContext) ctx); - XMesaGarbageCollect(dpy); - } -} - - -static Bool -Fake_glXIsDirect( Display *dpy, GLXContext ctx ) -{ - XMesaContext xmCtx = (XMesaContext) ctx; - return xmCtx ? xmCtx->direct : False; -} - - - -static void -Fake_glXSwapBuffers( Display *dpy, GLXDrawable drawable ) -{ - XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable ); - - if (buffer) { - XMesaSwapBuffers(buffer); - } - else if (getenv("MESA_DEBUG")) { - _mesa_warning(NULL, "glXSwapBuffers: invalid drawable 0x%x\n", - (int) drawable); - } -} - - - -/*** GLX_MESA_copy_sub_buffer ***/ - -static void -Fake_glXCopySubBufferMESA( Display *dpy, GLXDrawable drawable, - int x, int y, int width, int height ) -{ - XMesaBuffer buffer = XMesaFindBuffer( dpy, drawable ); - if (buffer) { - XMesaCopySubBuffer(buffer, x, y, width, height); - } - else if (getenv("MESA_DEBUG")) { - _mesa_warning(NULL, "Mesa: glXCopySubBufferMESA: invalid drawable\n"); - } -} - - -static Bool -Fake_glXQueryVersion( Display *dpy, int *maj, int *min ) -{ - (void) dpy; - /* Return GLX version, not Mesa version */ - assert(CLIENT_MAJOR_VERSION == SERVER_MAJOR_VERSION); - *maj = CLIENT_MAJOR_VERSION; - *min = MIN2( CLIENT_MINOR_VERSION, SERVER_MINOR_VERSION ); - return True; -} - - -/* - * Query the GLX attributes of the given XVisualInfo. - */ -static int -get_config( XMesaVisual xmvis, int attrib, int *value, GLboolean fbconfig ) -{ - assert(xmvis); - switch(attrib) { - case GLX_USE_GL: - if (fbconfig) - return GLX_BAD_ATTRIBUTE; - *value = (int) True; - return 0; - case GLX_BUFFER_SIZE: - *value = xmvis->visinfo->depth; - return 0; - case GLX_LEVEL: - *value = 0; - return 0; - case GLX_RGBA: - if (fbconfig) - return GLX_BAD_ATTRIBUTE; - *value = True; - return 0; - case GLX_DOUBLEBUFFER: - *value = (int) xmvis->mesa_visual.doubleBufferMode; - return 0; - case GLX_STEREO: - *value = (int) xmvis->mesa_visual.stereoMode; - return 0; - case GLX_AUX_BUFFERS: - *value = 0; - return 0; - case GLX_RED_SIZE: - *value = xmvis->mesa_visual.redBits; - return 0; - case GLX_GREEN_SIZE: - *value = xmvis->mesa_visual.greenBits; - return 0; - case GLX_BLUE_SIZE: - *value = xmvis->mesa_visual.blueBits; - return 0; - case GLX_ALPHA_SIZE: - *value = xmvis->mesa_visual.alphaBits; - return 0; - case GLX_DEPTH_SIZE: - *value = xmvis->mesa_visual.depthBits; - return 0; - case GLX_STENCIL_SIZE: - *value = xmvis->mesa_visual.stencilBits; - return 0; - case GLX_ACCUM_RED_SIZE: - *value = xmvis->mesa_visual.accumRedBits; - return 0; - case GLX_ACCUM_GREEN_SIZE: - *value = xmvis->mesa_visual.accumGreenBits; - return 0; - case GLX_ACCUM_BLUE_SIZE: - *value = xmvis->mesa_visual.accumBlueBits; - return 0; - case GLX_ACCUM_ALPHA_SIZE: - *value = xmvis->mesa_visual.accumAlphaBits; - return 0; - - /* - * GLX_EXT_visual_info extension - */ - case GLX_X_VISUAL_TYPE_EXT: - switch (xmvis->visinfo->CLASS) { - case StaticGray: *value = GLX_STATIC_GRAY_EXT; return 0; - case GrayScale: *value = GLX_GRAY_SCALE_EXT; return 0; - case StaticColor: *value = GLX_STATIC_GRAY_EXT; return 0; - case PseudoColor: *value = GLX_PSEUDO_COLOR_EXT; return 0; - case TrueColor: *value = GLX_TRUE_COLOR_EXT; return 0; - case DirectColor: *value = GLX_DIRECT_COLOR_EXT; return 0; - } - return 0; - case GLX_TRANSPARENT_TYPE_EXT: - *value = GLX_NONE_EXT; - return 0; - case GLX_TRANSPARENT_INDEX_VALUE_EXT: - { - int pixel = transparent_pixel( xmvis ); - if (pixel>=0) { - *value = pixel; - } - /* else undefined */ - } - return 0; - case GLX_TRANSPARENT_RED_VALUE_EXT: - /* undefined */ - return 0; - case GLX_TRANSPARENT_GREEN_VALUE_EXT: - /* undefined */ - return 0; - case GLX_TRANSPARENT_BLUE_VALUE_EXT: - /* undefined */ - return 0; - case GLX_TRANSPARENT_ALPHA_VALUE_EXT: - /* undefined */ - return 0; - - /* - * GLX_EXT_visual_info extension - */ - case GLX_VISUAL_CAVEAT_EXT: - *value = GLX_NONE_EXT; - return 0; - - /* - * GLX_ARB_multisample - */ - case GLX_SAMPLE_BUFFERS_ARB: - *value = 0; - return 0; - case GLX_SAMPLES_ARB: - *value = 0; - return 0; - - /* - * For FBConfigs: - */ - case GLX_SCREEN_EXT: - if (!fbconfig) - return GLX_BAD_ATTRIBUTE; - *value = xmvis->visinfo->screen; - break; - case GLX_DRAWABLE_TYPE: /*SGIX too */ - if (!fbconfig) - return GLX_BAD_ATTRIBUTE; - *value = GLX_WINDOW_BIT | GLX_PIXMAP_BIT | GLX_PBUFFER_BIT; - break; - case GLX_RENDER_TYPE_SGIX: - if (!fbconfig) - return GLX_BAD_ATTRIBUTE; - if (xmvis->mesa_visual.floatMode) - *value = GLX_RGBA_FLOAT_BIT_ARB; - else - *value = GLX_RGBA_BIT; - break; - case GLX_X_RENDERABLE_SGIX: - if (!fbconfig) - return GLX_BAD_ATTRIBUTE; - *value = True; /* XXX really? */ - break; - case GLX_FBCONFIG_ID_SGIX: - if (!fbconfig) - return GLX_BAD_ATTRIBUTE; - *value = xmvis->visinfo->visualid; - break; - case GLX_MAX_PBUFFER_WIDTH: - if (!fbconfig) - return GLX_BAD_ATTRIBUTE; - /* XXX should be same as ctx->Const.MaxRenderbufferSize */ - *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen); - break; - case GLX_MAX_PBUFFER_HEIGHT: - if (!fbconfig) - return GLX_BAD_ATTRIBUTE; - *value = DisplayHeight(xmvis->display, xmvis->visinfo->screen); - break; - case GLX_MAX_PBUFFER_PIXELS: - if (!fbconfig) - return GLX_BAD_ATTRIBUTE; - *value = DisplayWidth(xmvis->display, xmvis->visinfo->screen) * - DisplayHeight(xmvis->display, xmvis->visinfo->screen); - break; - case GLX_VISUAL_ID: - if (!fbconfig) - return GLX_BAD_ATTRIBUTE; - *value = xmvis->visinfo->visualid; - break; - - case GLX_BIND_TO_TEXTURE_RGB_EXT: - *value = True; /*XXX*/ - break; - case GLX_BIND_TO_TEXTURE_RGBA_EXT: - /* XXX review */ - *value = xmvis->mesa_visual.alphaBits > 0 ? True : False; - break; - case GLX_BIND_TO_MIPMAP_TEXTURE_EXT: - *value = True; /*XXX*/ - break; - case GLX_BIND_TO_TEXTURE_TARGETS_EXT: - *value = (GLX_TEXTURE_1D_BIT_EXT | - GLX_TEXTURE_2D_BIT_EXT | - GLX_TEXTURE_RECTANGLE_BIT_EXT); /*XXX*/ - break; - case GLX_Y_INVERTED_EXT: - *value = True; /*XXX*/ - break; - - default: - return GLX_BAD_ATTRIBUTE; - } - return Success; -} - - -static int -Fake_glXGetConfig( Display *dpy, XVisualInfo *visinfo, - int attrib, int *value ) -{ - XMesaVisual xmvis; - int k; - if (!dpy || !visinfo) - return GLX_BAD_ATTRIBUTE; - - xmvis = find_glx_visual( dpy, visinfo ); - if (!xmvis) { - /* this visual wasn't obtained with glXChooseVisual */ - xmvis = create_glx_visual( dpy, visinfo ); - if (!xmvis) { - /* this visual can't be used for GL rendering */ - if (attrib==GLX_USE_GL) { - *value = (int) False; - return 0; - } - else { - return GLX_BAD_VISUAL; - } - } - } - - k = get_config(xmvis, attrib, value, GL_FALSE); - return k; -} - - -static GLXContext -Fake_glXGetCurrentContext(void) -{ - XMesaContext xmesa = XMesaGetCurrentContext(); - return (GLXContext) xmesa; -} - -static void -Fake_glXWaitGL( void ) -{ - XMesaContext xmesa = XMesaGetCurrentContext(); - XMesaFlush( xmesa ); -} - - - -static void -Fake_glXWaitX( void ) -{ - XMesaContext xmesa = XMesaGetCurrentContext(); - XMesaFlush( xmesa ); -} - - -static const char * -get_extensions( void ) -{ - return EXTENSIONS + 23; /* skip "GLX_MESA_set_3dfx_mode" */ -} - - - -/* GLX 1.1 and later */ -static const char * -Fake_glXQueryExtensionsString( Display *dpy, int screen ) -{ - (void) dpy; - (void) screen; - return get_extensions(); -} - - - -/* GLX 1.1 and later */ -static const char * -Fake_glXQueryServerString( Display *dpy, int screen, int name ) -{ - static char version[1000]; - sprintf(version, "%d.%d %s", - SERVER_MAJOR_VERSION, SERVER_MINOR_VERSION, MESA_GLX_VERSION); - - (void) dpy; - (void) screen; - - switch (name) { - case GLX_EXTENSIONS: - return get_extensions(); - case GLX_VENDOR: - return VENDOR; - case GLX_VERSION: - return version; - default: - return NULL; - } -} - - - -/* GLX 1.1 and later */ -static const char * -Fake_glXGetClientString( Display *dpy, int name ) -{ - static char version[1000]; - sprintf(version, "%d.%d %s", CLIENT_MAJOR_VERSION, - CLIENT_MINOR_VERSION, MESA_GLX_VERSION); - - (void) dpy; - - switch (name) { - case GLX_EXTENSIONS: - return get_extensions(); - case GLX_VENDOR: - return VENDOR; - case GLX_VERSION: - return version; - default: - return NULL; - } -} - - - -/* - * GLX 1.3 and later - */ - - -static int -Fake_glXGetFBConfigAttrib( Display *dpy, GLXFBConfig config, - int attribute, int *value ) -{ - XMesaVisual v = (XMesaVisual) config; - (void) dpy; - (void) config; - - if (!dpy || !config || !value) - return -1; - - return get_config(v, attribute, value, GL_TRUE); -} - - -static GLXFBConfig * -Fake_glXGetFBConfigs( Display *dpy, int screen, int *nelements ) -{ - XVisualInfo *visuals, visTemplate; - const long visMask = VisualScreenMask; - int i; - - /* Get list of all X visuals */ - visTemplate.screen = screen; - visuals = XGetVisualInfo(dpy, visMask, &visTemplate, nelements); - if (*nelements > 0) { - XMesaVisual *results; - results = malloc(*nelements * sizeof(XMesaVisual)); - if (!results) { - *nelements = 0; - return NULL; - } - for (i = 0; i < *nelements; i++) { - results[i] = create_glx_visual(dpy, visuals + i); - } - free(visuals); - return (GLXFBConfig *) results; - } - return NULL; -} - - -static GLXFBConfig * -Fake_glXChooseFBConfig( Display *dpy, int screen, - const int *attribList, int *nitems ) -{ - XMesaVisual xmvis; - - /* register ourselves as an extension on this display */ - register_with_display(dpy); - - if (!attribList || !attribList[0]) { - /* return list of all configs (per GLX_SGIX_fbconfig spec) */ - return Fake_glXGetFBConfigs(dpy, screen, nitems); - } - - xmvis = choose_visual(dpy, screen, attribList, GL_TRUE); - if (xmvis) { - GLXFBConfig *config = malloc(sizeof(XMesaVisual)); - if (!config) { - *nitems = 0; - return NULL; - } - *nitems = 1; - config[0] = (GLXFBConfig) xmvis; - return (GLXFBConfig *) config; - } - else { - *nitems = 0; - return NULL; - } -} - - -static XVisualInfo * -Fake_glXGetVisualFromFBConfig( Display *dpy, GLXFBConfig config ) -{ - if (dpy && config) { - XMesaVisual xmvis = (XMesaVisual) config; - XVisualInfo* visinfo = malloc(sizeof(XVisualInfo)); - if (visinfo) { - memcpy(visinfo, xmvis->visinfo, sizeof(XVisualInfo)); - } - return visinfo; - } - else { - return NULL; - } -} - - -static GLXWindow -Fake_glXCreateWindow( Display *dpy, GLXFBConfig config, Window win, - const int *attribList ) -{ - XMesaVisual xmvis = (XMesaVisual) config; - XMesaBuffer xmbuf; - if (!xmvis) - return 0; - - xmbuf = XMesaCreateWindowBuffer(xmvis, win); - if (!xmbuf) - return 0; - - (void) dpy; - (void) attribList; /* Ignored in GLX 1.3 */ - - return win; /* A hack for now */ -} - - -static void -Fake_glXDestroyWindow( Display *dpy, GLXWindow window ) -{ - XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable) window); - if (b) - XMesaDestroyBuffer(b); - /* don't destroy X window */ -} - - -/* XXX untested */ -static GLXPixmap -Fake_glXCreatePixmap( Display *dpy, GLXFBConfig config, Pixmap pixmap, - const int *attribList ) -{ - XMesaVisual v = (XMesaVisual) config; - XMesaBuffer b; - const int *attr; - int target = 0, format = 0, mipmap = 0; - int value; - - if (!dpy || !config || !pixmap) - return 0; - - for (attr = attribList; attr && *attr; attr++) { - switch (*attr) { - case GLX_TEXTURE_FORMAT_EXT: - attr++; - switch (*attr) { - case GLX_TEXTURE_FORMAT_NONE_EXT: - case GLX_TEXTURE_FORMAT_RGB_EXT: - case GLX_TEXTURE_FORMAT_RGBA_EXT: - format = *attr; - break; - default: - /* error */ - return 0; - } - break; - case GLX_TEXTURE_TARGET_EXT: - attr++; - switch (*attr) { - case GLX_TEXTURE_1D_EXT: - case GLX_TEXTURE_2D_EXT: - case GLX_TEXTURE_RECTANGLE_EXT: - target = *attr; - break; - default: - /* error */ - return 0; - } - break; - case GLX_MIPMAP_TEXTURE_EXT: - attr++; - if (*attr) - mipmap = 1; - break; - default: - /* error */ - return 0; - } - } - - if (format == GLX_TEXTURE_FORMAT_RGB_EXT) { - if (get_config(v, GLX_BIND_TO_TEXTURE_RGB_EXT, - &value, GL_TRUE) != Success - || !value) { - return 0; /* error! */ - } - } - else if (format == GLX_TEXTURE_FORMAT_RGBA_EXT) { - if (get_config(v, GLX_BIND_TO_TEXTURE_RGBA_EXT, - &value, GL_TRUE) != Success - || !value) { - return 0; /* error! */ - } - } - if (mipmap) { - if (get_config(v, GLX_BIND_TO_MIPMAP_TEXTURE_EXT, - &value, GL_TRUE) != Success - || !value) { - return 0; /* error! */ - } - } - if (target == GLX_TEXTURE_1D_EXT) { - if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT, - &value, GL_TRUE) != Success - || (value & GLX_TEXTURE_1D_BIT_EXT) == 0) { - return 0; /* error! */ - } - } - else if (target == GLX_TEXTURE_2D_EXT) { - if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT, - &value, GL_TRUE) != Success - || (value & GLX_TEXTURE_2D_BIT_EXT) == 0) { - return 0; /* error! */ - } - } - if (target == GLX_TEXTURE_RECTANGLE_EXT) { - if (get_config(v, GLX_BIND_TO_TEXTURE_TARGETS_EXT, - &value, GL_TRUE) != Success - || (value & GLX_TEXTURE_RECTANGLE_BIT_EXT) == 0) { - return 0; /* error! */ - } - } - - if (format || target || mipmap) { - /* texture from pixmap */ - b = XMesaCreatePixmapTextureBuffer(v, pixmap, 0, format, target, mipmap); - } - else { - b = XMesaCreatePixmapBuffer( v, pixmap, 0 ); - } - if (!b) { - return 0; - } - - return pixmap; -} - - -static void -Fake_glXDestroyPixmap( Display *dpy, GLXPixmap pixmap ) -{ - XMesaBuffer b = XMesaFindBuffer(dpy, (XMesaDrawable)pixmap); - if (b) - XMesaDestroyBuffer(b); - /* don't destroy X pixmap */ -} - - -static GLXPbuffer -Fake_glXCreatePbuffer( Display *dpy, GLXFBConfig config, - const int *attribList ) -{ - XMesaVisual xmvis = (XMesaVisual) config; - XMesaBuffer xmbuf; - const int *attrib; - int width = 0, height = 0; - GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE; - - (void) dpy; - - for (attrib = attribList; *attrib; attrib++) { - switch (*attrib) { - case GLX_PBUFFER_WIDTH: - attrib++; - width = *attrib; - break; - case GLX_PBUFFER_HEIGHT: - attrib++; - height = *attrib; - break; - case GLX_PRESERVED_CONTENTS: - attrib++; - preserveContents = *attrib; - break; - case GLX_LARGEST_PBUFFER: - attrib++; - useLargest = *attrib; - break; - default: - return 0; - } - } - - if (width == 0 || height == 0) - return 0; - - if (width > SWRAST_MAX_WIDTH || height > SWRAST_MAX_HEIGHT) { - /* If allocation would have failed and GLX_LARGEST_PBUFFER is set, - * allocate the largest possible buffer. - */ - if (useLargest) { - width = SWRAST_MAX_WIDTH; - height = SWRAST_MAX_HEIGHT; - } - } - - xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height); - /* A GLXPbuffer handle must be an X Drawable because that's what - * glXMakeCurrent takes. - */ - if (xmbuf) { - xmbuf->largestPbuffer = useLargest; - xmbuf->preservedContents = preserveContents; - return (GLXPbuffer) xmbuf->frontxrb->pixmap; - } - else { - return 0; - } -} - - -static void -Fake_glXDestroyPbuffer( Display *dpy, GLXPbuffer pbuf ) -{ - XMesaBuffer b = XMesaFindBuffer(dpy, pbuf); - if (b) { - XMesaDestroyBuffer(b); - } -} - - -static void -Fake_glXQueryDrawable( Display *dpy, GLXDrawable draw, int attribute, - unsigned int *value ) -{ - XMesaBuffer xmbuf = XMesaFindBuffer(dpy, draw); - if (!xmbuf) - return; - - /* make sure buffer's dimensions are up to date */ - xmesa_check_and_update_buffer_size(NULL, xmbuf); - - switch (attribute) { - case GLX_WIDTH: - *value = xmbuf->mesa_buffer.Width; - break; - case GLX_HEIGHT: - *value = xmbuf->mesa_buffer.Height; - break; - case GLX_PRESERVED_CONTENTS: - *value = xmbuf->preservedContents; - break; - case GLX_LARGEST_PBUFFER: - *value = xmbuf->largestPbuffer; - break; - case GLX_FBCONFIG_ID: - *value = xmbuf->xm_visual->visinfo->visualid; - return; - case GLX_TEXTURE_FORMAT_EXT: - *value = xmbuf->TextureFormat; - break; - case GLX_TEXTURE_TARGET_EXT: - *value = xmbuf->TextureTarget; - break; - case GLX_MIPMAP_TEXTURE_EXT: - *value = xmbuf->TextureMipmap; - break; - - default: - return; /* raise BadValue error */ - } -} - - -static GLXContext -Fake_glXCreateNewContext( Display *dpy, GLXFBConfig config, - int renderType, GLXContext shareList, Bool direct ) -{ - XMesaContext xmCtx; - XMesaVisual xmvis = (XMesaVisual) config; - - if (!dpy || !config || - (renderType != GLX_RGBA_TYPE && - renderType != GLX_COLOR_INDEX_TYPE && - renderType != GLX_RGBA_FLOAT_TYPE_ARB && - renderType != GLX_RGBA_UNSIGNED_FLOAT_TYPE_EXT)) - return 0; - - /* deallocate unused windows/buffers */ - XMesaGarbageCollect(dpy); - - xmCtx = XMesaCreateContext(xmvis, (XMesaContext) shareList); - - return (GLXContext) xmCtx; -} - - -static int -Fake_glXQueryContext( Display *dpy, GLXContext ctx, int attribute, int *value ) -{ - XMesaContext xmctx = (XMesaContext) ctx; - (void) dpy; - (void) ctx; - - switch (attribute) { - case GLX_FBCONFIG_ID: - *value = xmctx->xm_visual->visinfo->visualid; - break; - case GLX_RENDER_TYPE: - *value = GLX_RGBA_TYPE; - break; - case GLX_SCREEN: - *value = 0; - return Success; - default: - return GLX_BAD_ATTRIBUTE; - } - return 0; -} - - -static void -Fake_glXSelectEvent( Display *dpy, GLXDrawable drawable, unsigned long mask ) -{ - XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); - if (xmbuf) - xmbuf->selectedEvents = mask; -} - - -static void -Fake_glXGetSelectedEvent( Display *dpy, GLXDrawable drawable, - unsigned long *mask ) -{ - XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); - if (xmbuf) - *mask = xmbuf->selectedEvents; - else - *mask = 0; -} - - - -/*** GLX_SGI_swap_control ***/ - -static int -Fake_glXSwapIntervalSGI(int interval) -{ - (void) interval; - return 0; -} - - - -/*** GLX_SGI_video_sync ***/ - -static unsigned int FrameCounter = 0; - -static int -Fake_glXGetVideoSyncSGI(unsigned int *count) -{ - /* this is a bogus implementation */ - *count = FrameCounter++; - return 0; -} - -static int -Fake_glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) -{ - if (divisor <= 0 || remainder < 0) - return GLX_BAD_VALUE; - /* this is a bogus implementation */ - FrameCounter++; - while (FrameCounter % divisor != remainder) - FrameCounter++; - *count = FrameCounter; - return 0; -} - - - -/*** GLX_SGI_make_current_read ***/ - -static Bool -Fake_glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx) -{ - return Fake_glXMakeContextCurrent( dpy, draw, read, ctx ); -} - -/* not used -static GLXDrawable -Fake_glXGetCurrentReadDrawableSGI(void) -{ - return 0; -} -*/ - - -/*** GLX_SGIX_video_source ***/ -#if defined(_VL_H) - -static GLXVideoSourceSGIX -Fake_glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode) -{ - (void) dpy; - (void) screen; - (void) server; - (void) path; - (void) nodeClass; - (void) drainNode; - return 0; -} - -static void -Fake_glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src) -{ - (void) dpy; - (void) src; -} - -#endif - - -/*** GLX_EXT_import_context ***/ - -static void -Fake_glXFreeContextEXT(Display *dpy, GLXContext context) -{ - (void) dpy; - (void) context; -} - -static GLXContextID -Fake_glXGetContextIDEXT(const GLXContext context) -{ - (void) context; - return 0; -} - -static GLXContext -Fake_glXImportContextEXT(Display *dpy, GLXContextID contextID) -{ - (void) dpy; - (void) contextID; - return 0; -} - -static int -Fake_glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute, int *value) -{ - (void) dpy; - (void) context; - (void) attribute; - (void) value; - return 0; -} - - - -/*** GLX_SGIX_fbconfig ***/ - -static int -Fake_glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value) -{ - return Fake_glXGetFBConfigAttrib(dpy, config, attribute, value); -} - -static GLXFBConfigSGIX * -Fake_glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements) -{ - return (GLXFBConfig *) Fake_glXChooseFBConfig(dpy, screen, attrib_list, nelements); -} - - -static GLXPixmap -Fake_glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap) -{ - XMesaVisual xmvis = (XMesaVisual) config; - XMesaBuffer xmbuf = XMesaCreatePixmapBuffer(xmvis, pixmap, 0); - return xmbuf->frontxrb->pixmap; /* need to return an X ID */ -} - - -static GLXContext -Fake_glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct) -{ - XMesaContext xmCtx; - XMesaVisual xmvis = (XMesaVisual) config; - - /* deallocate unused windows/buffers */ - XMesaGarbageCollect(dpy); - - xmCtx = XMesaCreateContext(xmvis, (XMesaContext) share_list); - - return (GLXContext) xmCtx; -} - - -static XVisualInfo * -Fake_glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config) -{ - return Fake_glXGetVisualFromFBConfig(dpy, config); -} - - -static GLXFBConfigSGIX -Fake_glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis) -{ - XMesaVisual xmvis = find_glx_visual(dpy, vis); - if (!xmvis) { - /* This visual wasn't found with glXChooseVisual() */ - xmvis = create_glx_visual(dpy, vis); - } - - return (GLXFBConfigSGIX) xmvis; -} - - - -/*** GLX_SGIX_pbuffer ***/ - -static GLXPbufferSGIX -Fake_glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config, - unsigned int width, unsigned int height, - int *attribList) -{ - XMesaVisual xmvis = (XMesaVisual) config; - XMesaBuffer xmbuf; - const int *attrib; - GLboolean useLargest = GL_FALSE, preserveContents = GL_FALSE; - - (void) dpy; - - for (attrib = attribList; attrib && *attrib; attrib++) { - switch (*attrib) { - case GLX_PRESERVED_CONTENTS_SGIX: - attrib++; - preserveContents = *attrib; /* ignored */ - break; - case GLX_LARGEST_PBUFFER_SGIX: - attrib++; - useLargest = *attrib; /* ignored */ - break; - default: - return 0; - } - } - - /* not used at this time */ - (void) useLargest; - (void) preserveContents; - - xmbuf = XMesaCreatePBuffer( xmvis, 0, width, height); - /* A GLXPbuffer handle must be an X Drawable because that's what - * glXMakeCurrent takes. - */ - return (GLXPbuffer) xmbuf->frontxrb->pixmap; -} - - -static void -Fake_glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf) -{ - XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf); - if (xmbuf) { - XMesaDestroyBuffer(xmbuf); - } -} - - -static void -Fake_glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value) -{ - const XMesaBuffer xmbuf = XMesaFindBuffer(dpy, pbuf); - - if (!xmbuf) { - /* Generate GLXBadPbufferSGIX for bad pbuffer */ - return; - } - - switch (attribute) { - case GLX_PRESERVED_CONTENTS_SGIX: - *value = xmbuf->preservedContents; - break; - case GLX_LARGEST_PBUFFER_SGIX: - *value = xmbuf->largestPbuffer; - break; - case GLX_WIDTH_SGIX: - *value = xmbuf->mesa_buffer.Width; - break; - case GLX_HEIGHT_SGIX: - *value = xmbuf->mesa_buffer.Height; - break; - case GLX_EVENT_MASK_SGIX: - *value = 0; /* XXX might be wrong */ - break; - default: - *value = 0; - } -} - - -static void -Fake_glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask) -{ - XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); - if (xmbuf) { - /* Note: we'll never generate clobber events */ - xmbuf->selectedEvents = mask; - } -} - - -static void -Fake_glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask) -{ - XMesaBuffer xmbuf = XMesaFindBuffer(dpy, drawable); - if (xmbuf) { - *mask = xmbuf->selectedEvents; - } - else { - *mask = 0; - } -} - - - -/*** GLX_SGI_cushion ***/ - -static void -Fake_glXCushionSGI(Display *dpy, Window win, float cushion) -{ - (void) dpy; - (void) win; - (void) cushion; -} - - - -/*** GLX_SGIX_video_resize ***/ - -static int -Fake_glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window) -{ - (void) dpy; - (void) screen; - (void) channel; - (void) window; - return 0; -} - -static int -Fake_glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h) -{ - (void) dpy; - (void) screen; - (void) channel; - (void) x; - (void) y; - (void) w; - (void) h; - return 0; -} - -static int -Fake_glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h) -{ - (void) dpy; - (void) screen; - (void) channel; - (void) x; - (void) y; - (void) w; - (void) h; - return 0; -} - -static int -Fake_glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh) -{ - (void) dpy; - (void) screen; - (void) channel; - (void) dx; - (void) dy; - (void) dw; - (void) dh; - return 0; -} - -static int -Fake_glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype) -{ - (void) dpy; - (void) screen; - (void) channel; - (void) synctype; - return 0; -} - - - -/*** GLX_SGIX_dmbuffer **/ - -#if defined(_DM_BUFFER_H_) -static Bool -Fake_glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer) -{ - (void) dpy; - (void) pbuffer; - (void) params; - (void) dmbuffer; - return False; -} -#endif - - -/*** GLX_SUN_get_transparent_index ***/ - -static Status -Fake_glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, unsigned long *pTransparent) -{ - (void) dpy; - (void) overlay; - (void) underlay; - (void) pTransparent; - return 0; -} - - - -/*** GLX_MESA_release_buffers ***/ - -/* - * Release the depth, stencil, accum buffers attached to a GLXDrawable - * (a window or pixmap) prior to destroying the GLXDrawable. - */ -static Bool -Fake_glXReleaseBuffersMESA( Display *dpy, GLXDrawable d ) -{ - XMesaBuffer b = XMesaFindBuffer(dpy, d); - if (b) { - XMesaDestroyBuffer(b); - return True; - } - return False; -} - - - -/*** GLX_EXT_texture_from_pixmap ***/ - -static void -Fake_glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer, - const int *attrib_list) -{ - XMesaBuffer b = XMesaFindBuffer(dpy, drawable); - if (b) - XMesaBindTexImage(dpy, b, buffer, attrib_list); -} - -static void -Fake_glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer) -{ - XMesaBuffer b = XMesaFindBuffer(dpy, drawable); - if (b) - XMesaReleaseTexImage(dpy, b, buffer); -} - - -static GLXContext -Fake_glXCreateContextAttribs(Display *dpy, GLXFBConfig config, - GLXContext share_context, Bool direct, - const int *attrib_list) -{ - XMesaContext xmCtx; - XMesaVisual xmvis = (XMesaVisual) config; - int i; - int major = 0, minor = 0, ctxFlags = 0, profileFlags = 0; - - for (i = 0; attrib_list[i]; i += 2) { - switch (attrib_list[i]) { - case GLX_CONTEXT_MAJOR_VERSION_ARB: - major = attrib_list[i + 1]; - break; - case GLX_CONTEXT_MINOR_VERSION_ARB: - minor = attrib_list[i + 1]; - break; - case GLX_CONTEXT_FLAGS_ARB: - ctxFlags = attrib_list[i + 1]; - break; - case GLX_CONTEXT_PROFILE_MASK_ARB: - profileFlags = attrib_list[i + 1]; - break; - default: - _mesa_warning(NULL, "Unexpected attribute 0x%x in " - "glXCreateContextAttribs()\n", attrib_list[i]); - return 0; - } - } - - if (major * 10 + minor > 21) { - /* swrast only supports GL 2.1 and earlier */ - return 0; - } - - /* These are ignored for now. We'd have to enhance XMesaCreateContext - * to take these flags and the version, at least. - */ - (void) ctxFlags; - (void) profileFlags; - - /* deallocate unused windows/buffers */ - XMesaGarbageCollect(dpy); - - xmCtx = XMesaCreateContext(xmvis, (XMesaContext) share_context); - - return (GLXContext) xmCtx; -} - - -/* silence warning */ -extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void); - - -/** - * Create a new GLX API dispatch table with its function pointers - * initialized to point to Mesa's "fake" GLX API functions. - * Note: there's a similar function (_real_GetGLXDispatchTable) that - * returns a new dispatch table with all pointers initalized to point - * to "real" GLX functions (which understand GLX wire protocol, etc). - */ -struct _glxapi_table * -_mesa_GetGLXDispatchTable(void) -{ - static struct _glxapi_table glx; - - /* be sure our dispatch table size <= libGL's table */ - { - GLuint size = sizeof(struct _glxapi_table) / sizeof(void *); - (void) size; - assert(_glxapi_get_dispatch_table_size() >= size); - } - - /* initialize the whole table to no-ops */ - _glxapi_set_no_op_table(&glx); - - /* now initialize the table with the functions I implement */ - glx.ChooseVisual = Fake_glXChooseVisual; - glx.CopyContext = Fake_glXCopyContext; - glx.CreateContext = Fake_glXCreateContext; - glx.CreateGLXPixmap = Fake_glXCreateGLXPixmap; - glx.DestroyContext = Fake_glXDestroyContext; - glx.DestroyGLXPixmap = Fake_glXDestroyGLXPixmap; - glx.GetConfig = Fake_glXGetConfig; - glx.GetCurrentContext = Fake_glXGetCurrentContext; - /*glx.GetCurrentDrawable = Fake_glXGetCurrentDrawable;*/ - glx.IsDirect = Fake_glXIsDirect; - glx.MakeCurrent = Fake_glXMakeCurrent; - glx.QueryExtension = Fake_glXQueryExtension; - glx.QueryVersion = Fake_glXQueryVersion; - glx.SwapBuffers = Fake_glXSwapBuffers; - glx.UseXFont = Fake_glXUseXFont; - glx.WaitGL = Fake_glXWaitGL; - glx.WaitX = Fake_glXWaitX; - - /*** GLX_VERSION_1_1 ***/ - glx.GetClientString = Fake_glXGetClientString; - glx.QueryExtensionsString = Fake_glXQueryExtensionsString; - glx.QueryServerString = Fake_glXQueryServerString; - - /*** GLX_VERSION_1_2 ***/ - /*glx.GetCurrentDisplay = Fake_glXGetCurrentDisplay;*/ - - /*** GLX_VERSION_1_3 ***/ - glx.ChooseFBConfig = Fake_glXChooseFBConfig; - glx.CreateNewContext = Fake_glXCreateNewContext; - glx.CreatePbuffer = Fake_glXCreatePbuffer; - glx.CreatePixmap = Fake_glXCreatePixmap; - glx.CreateWindow = Fake_glXCreateWindow; - glx.DestroyPbuffer = Fake_glXDestroyPbuffer; - glx.DestroyPixmap = Fake_glXDestroyPixmap; - glx.DestroyWindow = Fake_glXDestroyWindow; - /*glx.GetCurrentReadDrawable = Fake_glXGetCurrentReadDrawable;*/ - glx.GetFBConfigAttrib = Fake_glXGetFBConfigAttrib; - glx.GetFBConfigs = Fake_glXGetFBConfigs; - glx.GetSelectedEvent = Fake_glXGetSelectedEvent; - glx.GetVisualFromFBConfig = Fake_glXGetVisualFromFBConfig; - glx.MakeContextCurrent = Fake_glXMakeContextCurrent; - glx.QueryContext = Fake_glXQueryContext; - glx.QueryDrawable = Fake_glXQueryDrawable; - glx.SelectEvent = Fake_glXSelectEvent; - - /*** GLX_SGI_swap_control ***/ - glx.SwapIntervalSGI = Fake_glXSwapIntervalSGI; - - /*** GLX_SGI_video_sync ***/ - glx.GetVideoSyncSGI = Fake_glXGetVideoSyncSGI; - glx.WaitVideoSyncSGI = Fake_glXWaitVideoSyncSGI; - - /*** GLX_SGI_make_current_read ***/ - glx.MakeCurrentReadSGI = Fake_glXMakeCurrentReadSGI; - /*glx.GetCurrentReadDrawableSGI = Fake_glXGetCurrentReadDrawableSGI;*/ - -/*** GLX_SGIX_video_source ***/ -#if defined(_VL_H) - glx.CreateGLXVideoSourceSGIX = Fake_glXCreateGLXVideoSourceSGIX; - glx.DestroyGLXVideoSourceSGIX = Fake_glXDestroyGLXVideoSourceSGIX; -#endif - - /*** GLX_EXT_import_context ***/ - glx.FreeContextEXT = Fake_glXFreeContextEXT; - glx.GetContextIDEXT = Fake_glXGetContextIDEXT; - /*glx.GetCurrentDisplayEXT = Fake_glXGetCurrentDisplayEXT;*/ - glx.ImportContextEXT = Fake_glXImportContextEXT; - glx.QueryContextInfoEXT = Fake_glXQueryContextInfoEXT; - - /*** GLX_SGIX_fbconfig ***/ - glx.GetFBConfigAttribSGIX = Fake_glXGetFBConfigAttribSGIX; - glx.ChooseFBConfigSGIX = Fake_glXChooseFBConfigSGIX; - glx.CreateGLXPixmapWithConfigSGIX = Fake_glXCreateGLXPixmapWithConfigSGIX; - glx.CreateContextWithConfigSGIX = Fake_glXCreateContextWithConfigSGIX; - glx.GetVisualFromFBConfigSGIX = Fake_glXGetVisualFromFBConfigSGIX; - glx.GetFBConfigFromVisualSGIX = Fake_glXGetFBConfigFromVisualSGIX; - - /*** GLX_SGIX_pbuffer ***/ - glx.CreateGLXPbufferSGIX = Fake_glXCreateGLXPbufferSGIX; - glx.DestroyGLXPbufferSGIX = Fake_glXDestroyGLXPbufferSGIX; - glx.QueryGLXPbufferSGIX = Fake_glXQueryGLXPbufferSGIX; - glx.SelectEventSGIX = Fake_glXSelectEventSGIX; - glx.GetSelectedEventSGIX = Fake_glXGetSelectedEventSGIX; - - /*** GLX_SGI_cushion ***/ - glx.CushionSGI = Fake_glXCushionSGI; - - /*** GLX_SGIX_video_resize ***/ - glx.BindChannelToWindowSGIX = Fake_glXBindChannelToWindowSGIX; - glx.ChannelRectSGIX = Fake_glXChannelRectSGIX; - glx.QueryChannelRectSGIX = Fake_glXQueryChannelRectSGIX; - glx.QueryChannelDeltasSGIX = Fake_glXQueryChannelDeltasSGIX; - glx.ChannelRectSyncSGIX = Fake_glXChannelRectSyncSGIX; - - /*** GLX_SGIX_dmbuffer **/ -#if defined(_DM_BUFFER_H_) - glx.AssociateDMPbufferSGIX = NULL; -#endif - - /*** GLX_SUN_get_transparent_index ***/ - glx.GetTransparentIndexSUN = Fake_glXGetTransparentIndexSUN; - - /*** GLX_MESA_copy_sub_buffer ***/ - glx.CopySubBufferMESA = Fake_glXCopySubBufferMESA; - - /*** GLX_MESA_release_buffers ***/ - glx.ReleaseBuffersMESA = Fake_glXReleaseBuffersMESA; - - /*** GLX_MESA_pixmap_colormap ***/ - glx.CreateGLXPixmapMESA = Fake_glXCreateGLXPixmapMESA; - - /*** GLX_EXT_texture_from_pixmap ***/ - glx.BindTexImageEXT = Fake_glXBindTexImageEXT; - glx.ReleaseTexImageEXT = Fake_glXReleaseTexImageEXT; - - glx.CreateContextAttribs = Fake_glXCreateContextAttribs; - return &glx; -} diff --git a/src/mesa/drivers/x11/glxapi.c b/src/mesa/drivers/x11/glxapi.c deleted file mode 100644 index fcbccd8c315..00000000000 --- a/src/mesa/drivers/x11/glxapi.c +++ /dev/null @@ -1,1252 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* - * This is the GLX API dispatcher. It uses a dispatch table but that's - * not really needed anymore since the table always points to the "fake" - * GLX functions. - */ - - -#include -#include -#include -#include -#include "main/glheader.h" -#include "glapi/glapi.h" -#include "glxapi.h" - - -extern struct _glxapi_table *_mesa_GetGLXDispatchTable(void); - - -struct display_dispatch { - Display *Dpy; - struct _glxapi_table *Table; - struct display_dispatch *Next; -}; - - -/** - * When GLX_INDIRECT_RENDERING is defined, some symbols are missing in - * libglapi.a. We need to define them here. - */ -#ifdef GLX_INDIRECT_RENDERING - -#include "glapi/glapitable.h" - -#define KEYWORD1 PUBLIC - -#define NAME(func) gl##func - -#define DISPATCH(FUNC, ARGS, MESSAGE) \ - GET_DISPATCH()->FUNC ARGS - -#define RETURN_DISPATCH(FUNC, ARGS, MESSAGE) \ - return GET_DISPATCH()->FUNC ARGS - -/* skip normal ones */ -#define _GLAPI_SKIP_NORMAL_ENTRY_POINTS -#include "glapitemp.h" - -#endif /* GLX_INDIRECT_RENDERING */ - - -static struct display_dispatch *DispatchList = NULL; - - -/* Display -> Dispatch caching */ -static Display *prevDisplay = NULL; -static struct _glxapi_table *prevTable = NULL; - - -static struct _glxapi_table * -get_dispatch(Display *dpy) -{ - if (!dpy) - return NULL; - - /* search list of display/dispatch pairs for this display */ - { - const struct display_dispatch *d = DispatchList; - while (d) { - if (d->Dpy == dpy) { - prevDisplay = dpy; - prevTable = d->Table; - return d->Table; /* done! */ - } - d = d->Next; - } - } - - /* Setup the dispatch table */ - { - struct _glxapi_table *t = _mesa_GetGLXDispatchTable(); - - if (t) { - struct display_dispatch *d; - d = malloc(sizeof(struct display_dispatch)); - if (d) { - d->Dpy = dpy; - d->Table = t; - /* insert at head of list */ - d->Next = DispatchList; - DispatchList = d; - /* update cache */ - prevDisplay = dpy; - prevTable = t; - return t; - } - } - } - - return NULL; -} - - -/* Don't use the GET_DISPATCH macro */ -#undef GET_DISPATCH - -#define GET_DISPATCH(DPY, TABLE) \ - if (DPY == prevDisplay) { \ - TABLE = prevTable; \ - } \ - else if (!DPY) { \ - TABLE = NULL; \ - } \ - else { \ - TABLE = get_dispatch(DPY); \ - } - - -/* - * GLX API entrypoints - */ - -/*** GLX_VERSION_1_0 ***/ - -XVisualInfo PUBLIC * -glXChooseVisual(Display *dpy, int screen, int *list) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return NULL; - return t->ChooseVisual(dpy, screen, list); -} - - -void PUBLIC -glXCopyContext(Display *dpy, GLXContext src, GLXContext dst, unsigned long mask) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->CopyContext(dpy, src, dst, mask); -} - - -GLXContext PUBLIC -glXCreateContext(Display *dpy, XVisualInfo *visinfo, GLXContext shareList, Bool direct) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreateContext(dpy, visinfo, shareList, direct); -} - - -GLXPixmap PUBLIC -glXCreateGLXPixmap(Display *dpy, XVisualInfo *visinfo, Pixmap pixmap) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreateGLXPixmap(dpy, visinfo, pixmap); -} - - -void PUBLIC -glXDestroyContext(Display *dpy, GLXContext ctx) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->DestroyContext(dpy, ctx); -} - - -void PUBLIC -glXDestroyGLXPixmap(Display *dpy, GLXPixmap pixmap) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->DestroyGLXPixmap(dpy, pixmap); -} - - -int PUBLIC -glXGetConfig(Display *dpy, XVisualInfo *visinfo, int attrib, int *value) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return GLX_NO_EXTENSION; - return t->GetConfig(dpy, visinfo, attrib, value); -} - - -/* declare here to avoid including xmesa.h */ -extern void *XMesaGetCurrentContext(void); - -GLXContext PUBLIC -glXGetCurrentContext(void) -{ - return (GLXContext) XMesaGetCurrentContext(); -} - - -GLXDrawable PUBLIC -glXGetCurrentDrawable(void) -{ - __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext(); - return gc ? gc->currentDrawable : 0; -} - - -Bool PUBLIC -glXIsDirect(Display *dpy, GLXContext ctx) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return False; - return t->IsDirect(dpy, ctx); -} - - -Bool PUBLIC -glXMakeCurrent(Display *dpy, GLXDrawable drawable, GLXContext ctx) -{ - Bool b; - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) { - return False; - } - b = t->MakeCurrent(dpy, drawable, ctx); - return b; -} - - -Bool PUBLIC -glXQueryExtension(Display *dpy, int *errorb, int *event) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return False; - return t->QueryExtension(dpy, errorb, event); -} - - -Bool PUBLIC -glXQueryVersion(Display *dpy, int *maj, int *min) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return False; - return t->QueryVersion(dpy, maj, min); -} - - -void PUBLIC -glXSwapBuffers(Display *dpy, GLXDrawable drawable) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->SwapBuffers(dpy, drawable); -} - - -void PUBLIC -glXUseXFont(Font font, int first, int count, int listBase) -{ - struct _glxapi_table *t; - Display *dpy = glXGetCurrentDisplay(); - GET_DISPATCH(dpy, t); - if (!t) - return; - t->UseXFont(font, first, count, listBase); -} - - -void PUBLIC -glXWaitGL(void) -{ - struct _glxapi_table *t; - Display *dpy = glXGetCurrentDisplay(); - GET_DISPATCH(dpy, t); - if (!t) - return; - t->WaitGL(); -} - - -void PUBLIC -glXWaitX(void) -{ - struct _glxapi_table *t; - Display *dpy = glXGetCurrentDisplay(); - GET_DISPATCH(dpy, t); - if (!t) - return; - t->WaitX(); -} - - - -/*** GLX_VERSION_1_1 ***/ - -const char PUBLIC * -glXGetClientString(Display *dpy, int name) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return NULL; - return t->GetClientString(dpy, name); -} - - -const char PUBLIC * -glXQueryExtensionsString(Display *dpy, int screen) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return NULL; - return t->QueryExtensionsString(dpy, screen); -} - - -const char PUBLIC * -glXQueryServerString(Display *dpy, int screen, int name) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return NULL; - return t->QueryServerString(dpy, screen, name); -} - - -/*** GLX_VERSION_1_2 ***/ - -/* declare here to avoid including xmesa.h */ -extern Display *XMesaGetCurrentDisplay(void); - -Display PUBLIC * -glXGetCurrentDisplay(void) -{ - return XMesaGetCurrentDisplay(); -} - - - -/*** GLX_VERSION_1_3 ***/ - -GLXFBConfig PUBLIC * -glXChooseFBConfig(Display *dpy, int screen, const int *attribList, int *nitems) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->ChooseFBConfig(dpy, screen, attribList, nitems); -} - - -GLXContext PUBLIC -glXCreateNewContext(Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool direct) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreateNewContext(dpy, config, renderType, shareList, direct); -} - - -GLXPbuffer PUBLIC -glXCreatePbuffer(Display *dpy, GLXFBConfig config, const int *attribList) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreatePbuffer(dpy, config, attribList); -} - - -GLXPixmap PUBLIC -glXCreatePixmap(Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attribList) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreatePixmap(dpy, config, pixmap, attribList); -} - - -GLXWindow PUBLIC -glXCreateWindow(Display *dpy, GLXFBConfig config, Window win, const int *attribList) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreateWindow(dpy, config, win, attribList); -} - - -void PUBLIC -glXDestroyPbuffer(Display *dpy, GLXPbuffer pbuf) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->DestroyPbuffer(dpy, pbuf); -} - - -void PUBLIC -glXDestroyPixmap(Display *dpy, GLXPixmap pixmap) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->DestroyPixmap(dpy, pixmap); -} - - -void PUBLIC -glXDestroyWindow(Display *dpy, GLXWindow window) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->DestroyWindow(dpy, window); -} - - -GLXDrawable PUBLIC -glXGetCurrentReadDrawable(void) -{ - __GLXcontext *gc = (__GLXcontext *) glXGetCurrentContext(); - return gc ? gc->currentReadable : 0; -} - - -int PUBLIC -glXGetFBConfigAttrib(Display *dpy, GLXFBConfig config, int attribute, int *value) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return GLX_NO_EXTENSION; - return t->GetFBConfigAttrib(dpy, config, attribute, value); -} - - -GLXFBConfig PUBLIC * -glXGetFBConfigs(Display *dpy, int screen, int *nelements) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->GetFBConfigs(dpy, screen, nelements); -} - -void PUBLIC -glXGetSelectedEvent(Display *dpy, GLXDrawable drawable, unsigned long *mask) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->GetSelectedEvent(dpy, drawable, mask); -} - - -XVisualInfo PUBLIC * -glXGetVisualFromFBConfig(Display *dpy, GLXFBConfig config) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return NULL; - return t->GetVisualFromFBConfig(dpy, config); -} - - -Bool PUBLIC -glXMakeContextCurrent(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx) -{ - Bool b; - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return False; - b = t->MakeContextCurrent(dpy, draw, read, ctx); - return b; -} - - -int PUBLIC -glXQueryContext(Display *dpy, GLXContext ctx, int attribute, int *value) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - assert(t); - if (!t) - return 0; /* XXX correct? */ - return t->QueryContext(dpy, ctx, attribute, value); -} - - -void PUBLIC -glXQueryDrawable(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->QueryDrawable(dpy, draw, attribute, value); -} - - -void PUBLIC -glXSelectEvent(Display *dpy, GLXDrawable drawable, unsigned long mask) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->SelectEvent(dpy, drawable, mask); -} - - - -/*** GLX_SGI_swap_control ***/ - -int PUBLIC -glXSwapIntervalSGI(int interval) -{ - struct _glxapi_table *t; - Display *dpy = glXGetCurrentDisplay(); - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->SwapIntervalSGI(interval); -} - - - -/*** GLX_SGI_video_sync ***/ - -int PUBLIC -glXGetVideoSyncSGI(unsigned int *count) -{ - struct _glxapi_table *t; - Display *dpy = glXGetCurrentDisplay(); - GET_DISPATCH(dpy, t); - if (!t || !glXGetCurrentContext()) - return GLX_BAD_CONTEXT; - return t->GetVideoSyncSGI(count); -} - -int PUBLIC -glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count) -{ - struct _glxapi_table *t; - Display *dpy = glXGetCurrentDisplay(); - GET_DISPATCH(dpy, t); - if (!t || !glXGetCurrentContext()) - return GLX_BAD_CONTEXT; - return t->WaitVideoSyncSGI(divisor, remainder, count); -} - - - -/*** GLX_SGI_make_current_read ***/ - -Bool PUBLIC -glXMakeCurrentReadSGI(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return False; - return t->MakeCurrentReadSGI(dpy, draw, read, ctx); -} - -GLXDrawable PUBLIC -glXGetCurrentReadDrawableSGI(void) -{ - return glXGetCurrentReadDrawable(); -} - - -#if defined(_VL_H) - -GLXVideoSourceSGIX PUBLIC -glXCreateGLXVideoSourceSGIX(Display *dpy, int screen, VLServer server, VLPath path, int nodeClass, VLNode drainNode) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreateGLXVideoSourceSGIX(dpy, screen, server, path, nodeClass, drainNode); -} - -void PUBLIC -glXDestroyGLXVideoSourceSGIX(Display *dpy, GLXVideoSourceSGIX src) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->DestroyGLXVideoSourceSGIX(dpy, src); -} - -#endif - - -/*** GLX_EXT_import_context ***/ - -void PUBLIC -glXFreeContextEXT(Display *dpy, GLXContext context) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->FreeContextEXT(dpy, context); -} - -GLXContextID PUBLIC -glXGetContextIDEXT(const GLXContext context) -{ - return ((__GLXcontext *) context)->xid; -} - -Display PUBLIC * -glXGetCurrentDisplayEXT(void) -{ - return glXGetCurrentDisplay(); -} - -GLXContext PUBLIC -glXImportContextEXT(Display *dpy, GLXContextID contextID) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->ImportContextEXT(dpy, contextID); -} - -int PUBLIC -glXQueryContextInfoEXT(Display *dpy, GLXContext context, int attribute,int *value) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; /* XXX ok? */ - return t->QueryContextInfoEXT(dpy, context, attribute, value); -} - - - -/*** GLX_SGIX_fbconfig ***/ - -int PUBLIC -glXGetFBConfigAttribSGIX(Display *dpy, GLXFBConfigSGIX config, int attribute, int *value) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->GetFBConfigAttribSGIX(dpy, config, attribute, value); -} - -GLXFBConfigSGIX PUBLIC * -glXChooseFBConfigSGIX(Display *dpy, int screen, int *attrib_list, int *nelements) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->ChooseFBConfigSGIX(dpy, screen, attrib_list, nelements); -} - -GLXPixmap PUBLIC -glXCreateGLXPixmapWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, Pixmap pixmap) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreateGLXPixmapWithConfigSGIX(dpy, config, pixmap); -} - -GLXContext PUBLIC -glXCreateContextWithConfigSGIX(Display *dpy, GLXFBConfigSGIX config, int render_type, GLXContext share_list, Bool direct) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreateContextWithConfigSGIX(dpy, config, render_type, share_list, direct); -} - -XVisualInfo PUBLIC * -glXGetVisualFromFBConfigSGIX(Display *dpy, GLXFBConfigSGIX config) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->GetVisualFromFBConfigSGIX(dpy, config); -} - -GLXFBConfigSGIX PUBLIC -glXGetFBConfigFromVisualSGIX(Display *dpy, XVisualInfo *vis) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->GetFBConfigFromVisualSGIX(dpy, vis); -} - - - -/*** GLX_SGIX_pbuffer ***/ - -GLXPbufferSGIX PUBLIC -glXCreateGLXPbufferSGIX(Display *dpy, GLXFBConfigSGIX config, unsigned int width, unsigned int height, int *attrib_list) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreateGLXPbufferSGIX(dpy, config, width, height, attrib_list); -} - -void PUBLIC -glXDestroyGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->DestroyGLXPbufferSGIX(dpy, pbuf); -} - -void PUBLIC -glXQueryGLXPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuf, int attribute, unsigned int *value) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->QueryGLXPbufferSGIX(dpy, pbuf, attribute, value); -} - -void PUBLIC -glXSelectEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long mask) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->SelectEventSGIX(dpy, drawable, mask); -} - -void PUBLIC -glXGetSelectedEventSGIX(Display *dpy, GLXDrawable drawable, unsigned long *mask) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->GetSelectedEventSGIX(dpy, drawable, mask); -} - - - -/*** GLX_SGI_cushion ***/ - -void PUBLIC -glXCushionSGI(Display *dpy, Window win, float cushion) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->CushionSGI(dpy, win, cushion); -} - - - -/*** GLX_SGIX_video_resize ***/ - -int PUBLIC -glXBindChannelToWindowSGIX(Display *dpy, int screen, int channel , Window window) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->BindChannelToWindowSGIX(dpy, screen, channel, window); -} - -int PUBLIC -glXChannelRectSGIX(Display *dpy, int screen, int channel, int x, int y, int w, int h) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->ChannelRectSGIX(dpy, screen, channel, x, y, w, h); -} - -int PUBLIC -glXQueryChannelRectSGIX(Display *dpy, int screen, int channel, int *x, int *y, int *w, int *h) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->QueryChannelRectSGIX(dpy, screen, channel, x, y, w, h); -} - -int PUBLIC -glXQueryChannelDeltasSGIX(Display *dpy, int screen, int channel, int *dx, int *dy, int *dw, int *dh) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->QueryChannelDeltasSGIX(dpy, screen, channel, dx, dy, dw, dh); -} - -int PUBLIC -glXChannelRectSyncSGIX(Display *dpy, int screen, int channel, GLenum synctype) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->ChannelRectSyncSGIX(dpy, screen, channel, synctype); -} - - - -#if defined(_DM_BUFFER_H_) - -Bool PUBLIC -glXAssociateDMPbufferSGIX(Display *dpy, GLXPbufferSGIX pbuffer, DMparams *params, DMbuffer dmbuffer) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return False; - return t->AssociateDMPbufferSGIX(dpy, pbuffer, params, dmbuffer); -} - -#endif - - -/*** GLX_SUN_get_transparent_index ***/ - -Status PUBLIC -glXGetTransparentIndexSUN(Display *dpy, Window overlay, Window underlay, unsigned long *pTransparent) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return False; - return t->GetTransparentIndexSUN(dpy, overlay, underlay, pTransparent); -} - - - -/*** GLX_MESA_copy_sub_buffer ***/ - -void PUBLIC -glXCopySubBufferMESA(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return; - t->CopySubBufferMESA(dpy, drawable, x, y, width, height); -} - - - -/*** GLX_MESA_release_buffers ***/ - -Bool PUBLIC -glXReleaseBuffersMESA(Display *dpy, Window w) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return False; - return t->ReleaseBuffersMESA(dpy, w); -} - - - -/*** GLX_MESA_pixmap_colormap ***/ - -GLXPixmap PUBLIC -glXCreateGLXPixmapMESA(Display *dpy, XVisualInfo *visinfo, Pixmap pixmap, Colormap cmap) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreateGLXPixmapMESA(dpy, visinfo, pixmap, cmap); -} - - - -/*** GLX_EXT_texture_from_pixmap */ - -void PUBLIC -glXBindTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer, - const int *attrib_list) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (t) - t->BindTexImageEXT(dpy, drawable, buffer, attrib_list); -} - -void PUBLIC -glXReleaseTexImageEXT(Display *dpy, GLXDrawable drawable, int buffer) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (t) - t->ReleaseTexImageEXT(dpy, drawable, buffer); -} - - -/**********************************************************************/ -/* GLX API management functions */ -/**********************************************************************/ - - -const char * -_glxapi_get_version(void) -{ - return "1.3"; -} - - -/* - * Return array of extension strings. - */ -const char ** -_glxapi_get_extensions(void) -{ - static const char *extensions[] = { - "GLX_EXT_import_context", - "GLX_SGI_video_sync", - "GLX_MESA_copy_sub_buffer", - "GLX_MESA_release_buffers", - "GLX_MESA_pixmap_colormap", - "GLX_SGIX_fbconfig", - "GLX_SGIX_pbuffer", - "GLX_EXT_texture_from_pixmap", - "GLX_INTEL_swap_event", - NULL - }; - return extensions; -} - - -/* - * Return size of the GLX dispatch table, in entries, not bytes. - */ -GLuint -_glxapi_get_dispatch_table_size(void) -{ - return sizeof(struct _glxapi_table) / sizeof(void *); -} - - -static int -generic_no_op_func(void) -{ - return 0; -} - - -/* - * Initialize all functions in given dispatch table to be no-ops - */ -void -_glxapi_set_no_op_table(struct _glxapi_table *t) -{ - typedef int (*nop_func)(void); - nop_func *dispatch = (nop_func *) t; - GLuint n = _glxapi_get_dispatch_table_size(); - GLuint i; - for (i = 0; i < n; i++) { - dispatch[i] = generic_no_op_func; - } -} - - -struct name_address_pair { - const char *Name; - __GLXextFuncPtr Address; -}; - -static struct name_address_pair GLX_functions[] = { - /*** GLX_VERSION_1_0 ***/ - { "glXChooseVisual", (__GLXextFuncPtr) glXChooseVisual }, - { "glXCopyContext", (__GLXextFuncPtr) glXCopyContext }, - { "glXCreateContext", (__GLXextFuncPtr) glXCreateContext }, - { "glXCreateGLXPixmap", (__GLXextFuncPtr) glXCreateGLXPixmap }, - { "glXDestroyContext", (__GLXextFuncPtr) glXDestroyContext }, - { "glXDestroyGLXPixmap", (__GLXextFuncPtr) glXDestroyGLXPixmap }, - { "glXGetConfig", (__GLXextFuncPtr) glXGetConfig }, - { "glXGetCurrentContext", (__GLXextFuncPtr) glXGetCurrentContext }, - { "glXGetCurrentDrawable", (__GLXextFuncPtr) glXGetCurrentDrawable }, - { "glXIsDirect", (__GLXextFuncPtr) glXIsDirect }, - { "glXMakeCurrent", (__GLXextFuncPtr) glXMakeCurrent }, - { "glXQueryExtension", (__GLXextFuncPtr) glXQueryExtension }, - { "glXQueryVersion", (__GLXextFuncPtr) glXQueryVersion }, - { "glXSwapBuffers", (__GLXextFuncPtr) glXSwapBuffers }, - { "glXUseXFont", (__GLXextFuncPtr) glXUseXFont }, - { "glXWaitGL", (__GLXextFuncPtr) glXWaitGL }, - { "glXWaitX", (__GLXextFuncPtr) glXWaitX }, - - /*** GLX_VERSION_1_1 ***/ - { "glXGetClientString", (__GLXextFuncPtr) glXGetClientString }, - { "glXQueryExtensionsString", (__GLXextFuncPtr) glXQueryExtensionsString }, - { "glXQueryServerString", (__GLXextFuncPtr) glXQueryServerString }, - - /*** GLX_VERSION_1_2 ***/ - { "glXGetCurrentDisplay", (__GLXextFuncPtr) glXGetCurrentDisplay }, - - /*** GLX_VERSION_1_3 ***/ - { "glXChooseFBConfig", (__GLXextFuncPtr) glXChooseFBConfig }, - { "glXCreateNewContext", (__GLXextFuncPtr) glXCreateNewContext }, - { "glXCreatePbuffer", (__GLXextFuncPtr) glXCreatePbuffer }, - { "glXCreatePixmap", (__GLXextFuncPtr) glXCreatePixmap }, - { "glXCreateWindow", (__GLXextFuncPtr) glXCreateWindow }, - { "glXDestroyPbuffer", (__GLXextFuncPtr) glXDestroyPbuffer }, - { "glXDestroyPixmap", (__GLXextFuncPtr) glXDestroyPixmap }, - { "glXDestroyWindow", (__GLXextFuncPtr) glXDestroyWindow }, - { "glXGetCurrentReadDrawable", (__GLXextFuncPtr) glXGetCurrentReadDrawable }, - { "glXGetFBConfigAttrib", (__GLXextFuncPtr) glXGetFBConfigAttrib }, - { "glXGetFBConfigs", (__GLXextFuncPtr) glXGetFBConfigs }, - { "glXGetSelectedEvent", (__GLXextFuncPtr) glXGetSelectedEvent }, - { "glXGetVisualFromFBConfig", (__GLXextFuncPtr) glXGetVisualFromFBConfig }, - { "glXMakeContextCurrent", (__GLXextFuncPtr) glXMakeContextCurrent }, - { "glXQueryContext", (__GLXextFuncPtr) glXQueryContext }, - { "glXQueryDrawable", (__GLXextFuncPtr) glXQueryDrawable }, - { "glXSelectEvent", (__GLXextFuncPtr) glXSelectEvent }, - - /*** GLX_VERSION_1_4 ***/ - { "glXGetProcAddress", (__GLXextFuncPtr) glXGetProcAddress }, - - /*** GLX_SGI_swap_control ***/ - { "glXSwapIntervalSGI", (__GLXextFuncPtr) glXSwapIntervalSGI }, - - /*** GLX_SGI_video_sync ***/ - { "glXGetVideoSyncSGI", (__GLXextFuncPtr) glXGetVideoSyncSGI }, - { "glXWaitVideoSyncSGI", (__GLXextFuncPtr) glXWaitVideoSyncSGI }, - - /*** GLX_SGI_make_current_read ***/ - { "glXMakeCurrentReadSGI", (__GLXextFuncPtr) glXMakeCurrentReadSGI }, - { "glXGetCurrentReadDrawableSGI", (__GLXextFuncPtr) glXGetCurrentReadDrawableSGI }, - - /*** GLX_SGIX_video_source ***/ -#if defined(_VL_H) - { "glXCreateGLXVideoSourceSGIX", (__GLXextFuncPtr) glXCreateGLXVideoSourceSGIX }, - { "glXDestroyGLXVideoSourceSGIX", (__GLXextFuncPtr) glXDestroyGLXVideoSourceSGIX }, -#endif - - /*** GLX_EXT_import_context ***/ - { "glXFreeContextEXT", (__GLXextFuncPtr) glXFreeContextEXT }, - { "glXGetContextIDEXT", (__GLXextFuncPtr) glXGetContextIDEXT }, - { "glXGetCurrentDisplayEXT", (__GLXextFuncPtr) glXGetCurrentDisplayEXT }, - { "glXImportContextEXT", (__GLXextFuncPtr) glXImportContextEXT }, - { "glXQueryContextInfoEXT", (__GLXextFuncPtr) glXQueryContextInfoEXT }, - - /*** GLX_SGIX_fbconfig ***/ - { "glXGetFBConfigAttribSGIX", (__GLXextFuncPtr) glXGetFBConfigAttribSGIX }, - { "glXChooseFBConfigSGIX", (__GLXextFuncPtr) glXChooseFBConfigSGIX }, - { "glXCreateGLXPixmapWithConfigSGIX", (__GLXextFuncPtr) glXCreateGLXPixmapWithConfigSGIX }, - { "glXCreateContextWithConfigSGIX", (__GLXextFuncPtr) glXCreateContextWithConfigSGIX }, - { "glXGetVisualFromFBConfigSGIX", (__GLXextFuncPtr) glXGetVisualFromFBConfigSGIX }, - { "glXGetFBConfigFromVisualSGIX", (__GLXextFuncPtr) glXGetFBConfigFromVisualSGIX }, - - /*** GLX_SGIX_pbuffer ***/ - { "glXCreateGLXPbufferSGIX", (__GLXextFuncPtr) glXCreateGLXPbufferSGIX }, - { "glXDestroyGLXPbufferSGIX", (__GLXextFuncPtr) glXDestroyGLXPbufferSGIX }, - { "glXQueryGLXPbufferSGIX", (__GLXextFuncPtr) glXQueryGLXPbufferSGIX }, - { "glXSelectEventSGIX", (__GLXextFuncPtr) glXSelectEventSGIX }, - { "glXGetSelectedEventSGIX", (__GLXextFuncPtr) glXGetSelectedEventSGIX }, - - /*** GLX_SGI_cushion ***/ - { "glXCushionSGI", (__GLXextFuncPtr) glXCushionSGI }, - - /*** GLX_SGIX_video_resize ***/ - { "glXBindChannelToWindowSGIX", (__GLXextFuncPtr) glXBindChannelToWindowSGIX }, - { "glXChannelRectSGIX", (__GLXextFuncPtr) glXChannelRectSGIX }, - { "glXQueryChannelRectSGIX", (__GLXextFuncPtr) glXQueryChannelRectSGIX }, - { "glXQueryChannelDeltasSGIX", (__GLXextFuncPtr) glXQueryChannelDeltasSGIX }, - { "glXChannelRectSyncSGIX", (__GLXextFuncPtr) glXChannelRectSyncSGIX }, - - /*** GLX_SGIX_dmbuffer **/ -#if defined(_DM_BUFFER_H_) - { "glXAssociateDMPbufferSGIX", (__GLXextFuncPtr) glXAssociateDMPbufferSGIX }, -#endif - - /*** GLX_SUN_get_transparent_index ***/ - { "glXGetTransparentIndexSUN", (__GLXextFuncPtr) glXGetTransparentIndexSUN }, - - /*** GLX_MESA_copy_sub_buffer ***/ - { "glXCopySubBufferMESA", (__GLXextFuncPtr) glXCopySubBufferMESA }, - - /*** GLX_MESA_pixmap_colormap ***/ - { "glXCreateGLXPixmapMESA", (__GLXextFuncPtr) glXCreateGLXPixmapMESA }, - - /*** GLX_MESA_release_buffers ***/ - { "glXReleaseBuffersMESA", (__GLXextFuncPtr) glXReleaseBuffersMESA }, - - /*** GLX_ARB_get_proc_address ***/ - { "glXGetProcAddressARB", (__GLXextFuncPtr) glXGetProcAddressARB }, - - /*** GLX_EXT_texture_from_pixmap ***/ - { "glXBindTexImageEXT", (__GLXextFuncPtr) glXBindTexImageEXT }, - { "glXReleaseTexImageEXT", (__GLXextFuncPtr) glXReleaseTexImageEXT }, - - /*** GLX_ARB_create_context ***/ - { "glXCreateContextAttribsARB", (__GLXextFuncPtr) glXCreateContextAttribsARB }, - - { NULL, NULL } /* end of list */ -}; - - - -/* - * Return address of named glX function, or NULL if not found. - */ -__GLXextFuncPtr -_glxapi_get_proc_address(const char *funcName) -{ - GLuint i; - for (i = 0; GLX_functions[i].Name; i++) { -#ifdef MANGLE - /* skip the "m" prefix on the name */ - if (strcmp(GLX_functions[i].Name, funcName+1) == 0) -#else - if (strcmp(GLX_functions[i].Name, funcName) == 0) -#endif - return GLX_functions[i].Address; - } - return NULL; -} - - - -/* - * This function does not get dispatched through the dispatch table - * since it's really a "meta" function. - */ -__GLXextFuncPtr PUBLIC -glXGetProcAddressARB(const GLubyte *procName) -{ - __GLXextFuncPtr f; - - f = _glxapi_get_proc_address((const char *) procName); - if (f) { - return f; - } - - f = (__GLXextFuncPtr) _glapi_get_proc_address((const char *) procName); - return f; -} - - -/* GLX 1.4 */ -void PUBLIC -(*glXGetProcAddress(const GLubyte *procName))() -{ - return glXGetProcAddressARB(procName); -} - - -/** - * Added in GLX_ARB_create_context. - */ -GLXContext PUBLIC -glXCreateContextAttribsARB(Display *dpy, GLXFBConfig config, - GLXContext share_context, Bool direct, - const int *attrib_list) -{ - struct _glxapi_table *t; - GET_DISPATCH(dpy, t); - if (!t) - return 0; - return t->CreateContextAttribs(dpy, config, share_context, direct, - attrib_list); -} diff --git a/src/mesa/drivers/x11/glxapi.h b/src/mesa/drivers/x11/glxapi.h deleted file mode 100644 index 6a1ce66a891..00000000000 --- a/src/mesa/drivers/x11/glxapi.h +++ /dev/null @@ -1,212 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -#ifndef _glxapi_h_ -#define _glxapi_h_ - - -#define GLX_GLXEXT_PROTOTYPES -#include "GL/glx.h" - - -/* The GLX API dispatcher (i.e. this code) is being built into stand-alone - * Mesa. We don't know anything about XFree86 or real GLX so we define a - * minimal __GLXContextRec here so some of the functions in this file can - * work properly. - */ -typedef struct __GLXcontextRec { - GLboolean isDirect; - GLXDrawable currentDrawable; - GLXDrawable currentReadable; - XID xid; -} __GLXcontext; - - -/* - * Almost all the GLX API functions get routed through this dispatch table. - * The exceptions are the glXGetCurrentXXX() functions. - * - * This dispatch table allows multiple GLX client-side modules to coexist. - * Specifically, a real GLX library (like SGI's or the Utah GLX) and Mesa's - * pseudo-GLX can be present at the same time. The former being used on - * GLX-enabled X servers and the later on non-GLX X servers. - * - * Red Hat has been using this since Red Hat Linux 7.0 (I think). - * This'll be a standard feature in XFree86 4.3. It basically allows one - * libGL to do both DRI-rendering and "fake GLX" rendering to X displays - * that lack the GLX extension. - */ -struct _glxapi_table { - /*** GLX_VERSION_1_0 ***/ - XVisualInfo *(*ChooseVisual)(Display *dpy, int screen, int *list); - void (*CopyContext)(Display *dpy, GLXContext src, GLXContext dst, unsigned long mask); - GLXContext (*CreateContext)(Display *dpy, XVisualInfo *visinfo, GLXContext shareList, Bool direct); - GLXPixmap (*CreateGLXPixmap)(Display *dpy, XVisualInfo *visinfo, Pixmap pixmap); - void (*DestroyContext)(Display *dpy, GLXContext ctx); - void (*DestroyGLXPixmap)(Display *dpy, GLXPixmap pixmap); - int (*GetConfig)(Display *dpy, XVisualInfo *visinfo, int attrib, int *value); - GLXContext (*GetCurrentContext)(void); - /*GLXDrawable (*GetCurrentDrawable)(void);*/ - Bool (*IsDirect)(Display *dpy, GLXContext ctx); - Bool (*MakeCurrent)(Display *dpy, GLXDrawable drawable, GLXContext ctx); - Bool (*QueryExtension)(Display *dpy, int *errorb, int *event); - Bool (*QueryVersion)(Display *dpy, int *maj, int *min); - void (*SwapBuffers)(Display *dpy, GLXDrawable drawable); - void (*UseXFont)(Font font, int first, int count, int listBase); - void (*WaitGL)(void); - void (*WaitX)(void); - - /*** GLX_VERSION_1_1 ***/ - const char *(*GetClientString)(Display *dpy, int name); - const char *(*QueryExtensionsString)(Display *dpy, int screen); - const char *(*QueryServerString)(Display *dpy, int screen, int name); - - /*** GLX_VERSION_1_2 ***/ - /*Display *(*GetCurrentDisplay)(void);*/ - - /*** GLX_VERSION_1_3 ***/ - GLXFBConfig *(*ChooseFBConfig)(Display *dpy, int screen, const int *attribList, int *nitems); - GLXContext (*CreateNewContext)(Display *dpy, GLXFBConfig config, int renderType, GLXContext shareList, Bool direct); - GLXPbuffer (*CreatePbuffer)(Display *dpy, GLXFBConfig config, const int *attribList); - GLXPixmap (*CreatePixmap)(Display *dpy, GLXFBConfig config, Pixmap pixmap, const int *attribList); - GLXWindow (*CreateWindow)(Display *dpy, GLXFBConfig config, Window win, const int *attribList); - void (*DestroyPbuffer)(Display *dpy, GLXPbuffer pbuf); - void (*DestroyPixmap)(Display *dpy, GLXPixmap pixmap); - void (*DestroyWindow)(Display *dpy, GLXWindow window); - /*GLXDrawable (*GetCurrentReadDrawable)(void);*/ - int (*GetFBConfigAttrib)(Display *dpy, GLXFBConfig config, int attribute, int *value); - GLXFBConfig *(*GetFBConfigs)(Display *dpy, int screen, int *nelements); - void (*GetSelectedEvent)(Display *dpy, GLXDrawable drawable, unsigned long *mask); - XVisualInfo *(*GetVisualFromFBConfig)(Display *dpy, GLXFBConfig config); - Bool (*MakeContextCurrent)(Display *dpy, GLXDrawable draw, GLXDrawable read, GLXContext ctx); - int (*QueryContext)(Display *dpy, GLXContext ctx, int attribute, int *value); - void (*QueryDrawable)(Display *dpy, GLXDrawable draw, int attribute, unsigned int *value); - void (*SelectEvent)(Display *dpy, GLXDrawable drawable, unsigned long mask); - - /*** GLX_SGI_swap_control ***/ - int (*SwapIntervalSGI)(int); - - /*** GLX_SGI_video_sync ***/ - int (*GetVideoSyncSGI)(unsigned int *count); - int (*WaitVideoSyncSGI)(int divisor, int remainder, unsigned int *count); - - /*** GLX_SGI_make_current_read ***/ - Bool (*MakeCurrentReadSGI)(Display *, GLXDrawable, GLXDrawable, GLXContext); - /*GLXDrawable (*GetCurrentReadDrawableSGI)(void);*/ - - /*** GLX_SGIX_video_source (needs video library) ***/ -#if defined(_VL_H_) - GLXVideoSourceSGIX (*CreateGLXVideoSourceSGIX)(Display *, int, VLServer, VLPath, int, VLNode); - void (*DestroyGLXVideoSourceSGIX)(Display *, GLXVideoSourceSGIX); -#else - void *CreateGLXVideoSourceSGIX; - void *DestroyGLXVideoSourceSGIX; -#endif - - /*** GLX_EXT_import_context ***/ - void (*FreeContextEXT)(Display *dpy, GLXContext context); - GLXContextID (*GetContextIDEXT)(const GLXContext context); - /*Display *(*GetCurrentDisplayEXT)(void);*/ - GLXContext (*ImportContextEXT)(Display *dpy, GLXContextID contextID); - int (*QueryContextInfoEXT)(Display *dpy, GLXContext context, int attribute,int *value); - - /*** GLX_SGIX_fbconfig ***/ - int (*GetFBConfigAttribSGIX)(Display *, GLXFBConfigSGIX, int, int *); - GLXFBConfigSGIX * (*ChooseFBConfigSGIX)(Display *, int, int *, int *); - GLXPixmap (*CreateGLXPixmapWithConfigSGIX)(Display *, GLXFBConfigSGIX, Pixmap); - GLXContext (*CreateContextWithConfigSGIX)(Display *, GLXFBConfigSGIX, int, GLXContext, Bool); - XVisualInfo * (*GetVisualFromFBConfigSGIX)(Display *, GLXFBConfigSGIX); - GLXFBConfigSGIX (*GetFBConfigFromVisualSGIX)(Display *, XVisualInfo *); - - /*** GLX_SGIX_pbuffer ***/ - GLXPbufferSGIX (*CreateGLXPbufferSGIX)(Display *, GLXFBConfigSGIX, unsigned int, unsigned int, int *); - void (*DestroyGLXPbufferSGIX)(Display *, GLXPbufferSGIX); - void (*QueryGLXPbufferSGIX)(Display *, GLXPbufferSGIX, int, unsigned int *); - void (*SelectEventSGIX)(Display *, GLXDrawable, unsigned long); - void (*GetSelectedEventSGIX)(Display *, GLXDrawable, unsigned long *); - - /*** GLX_SGI_cushion ***/ - void (*CushionSGI)(Display *, Window, float); - - /*** GLX_SGIX_video_resize ***/ - int (*BindChannelToWindowSGIX)(Display *, int, int, Window); - int (*ChannelRectSGIX)(Display *, int, int, int, int, int, int); - int (*QueryChannelRectSGIX)(Display *, int, int, int *, int *, int *, int *); - int (*QueryChannelDeltasSGIX)(Display *, int, int, int *, int *, int *, int *); - int (*ChannelRectSyncSGIX)(Display *, int, int, GLenum); - - /*** GLX_SGIX_dmbuffer (needs dmedia library) ***/ -#if defined (_DM_BUFFER_H_) - Bool (*AssociateDMPbufferSGIX)(Display *, GLXPbufferSGIX, DMparams *, DMbuffer); -#else - void *AssociciateDMPbufferSGIX; -#endif - - /*** GLX_SUN_get_transparent_index ***/ - Status (*GetTransparentIndexSUN)(Display *, Window, Window, unsigned long *); - - /*** GLX_MESA_copy_sub_buffer ***/ - void (*CopySubBufferMESA)(Display *dpy, GLXDrawable drawable, int x, int y, int width, int height); - - /*** GLX_MESA_release_buffers ***/ - Bool (*ReleaseBuffersMESA)(Display *dpy, Window w); - - /*** GLX_MESA_pixmap_colormap ***/ - GLXPixmap (*CreateGLXPixmapMESA)(Display *dpy, XVisualInfo *visinfo, Pixmap pixmap, Colormap cmap); - - /*** GLX_EXT_texture_from_pixmap ***/ - void (*BindTexImageEXT)(Display *dpy, GLXDrawable drawable, int buffer, - const int *attrib_list); - void (*ReleaseTexImageEXT)(Display *dpy, GLXDrawable drawable, int buffer); - - /*** GLX_ARB_create_context ***/ - GLXContext (*CreateContextAttribs)(Display *dpy, GLXFBConfig config, - GLXContext share_context, Bool direct, - const int *attrib_list); -}; - - - -extern const char * -_glxapi_get_version(void); - - -extern const char ** -_glxapi_get_extensions(void); - - -extern GLuint -_glxapi_get_dispatch_table_size(void); - - -extern void -_glxapi_set_no_op_table(struct _glxapi_table *t); - - -extern __GLXextFuncPtr -_glxapi_get_proc_address(const char *funcName); - - -#endif diff --git a/src/mesa/drivers/x11/glxheader.h b/src/mesa/drivers/x11/glxheader.h deleted file mode 100644 index b133de56ca3..00000000000 --- a/src/mesa/drivers/x11/glxheader.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -#ifndef GLX_HEADER_H -#define GLX_HEADER_H - -#include "main/glheader.h" - - -# include -# include -# include -# ifdef USE_XSHM /* was SHM */ -# include -# include -# include -# endif -# include -# include - - - - -/* this silences a compiler warning on several systems */ -struct timespec; -struct itimerspec; - - -#endif /*GLX_HEADER*/ diff --git a/src/mesa/drivers/x11/meson.build b/src/mesa/drivers/x11/meson.build deleted file mode 100644 index e828566b4cf..00000000000 --- a/src/mesa/drivers/x11/meson.build +++ /dev/null @@ -1,39 +0,0 @@ -# Copyright © 2017 Intel Corporation - -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), to deal -# in the Software without restriction, including without limitation the rights -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: - -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. - -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -# SOFTWARE. - -gl_link_with = [] -if with_shared_glapi - gl_link_with += libglapi -endif - -libgl = shared_library( - 'GL', - files( - 'fakeglx.c', 'glxapi.c', 'xfonts.c', 'xm_api.c', 'xm_buffer.c', 'xm_dd.c', - 'xm_line.c', 'xm_tri.c', - ), - include_directories : [ - inc_include, inc_src, inc_mesa, inc_mapi, inc_gallium, inc_gallium_aux - ], - link_with : [libmesa_classic, libglapi_static, gl_link_with], - dependencies : [idep_mesautil, dep_x11, dep_xext, dep_xcb, dep_thread], - version : '1.6.0', - install : true, -) diff --git a/src/mesa/drivers/x11/xfonts.c b/src/mesa/drivers/x11/xfonts.c deleted file mode 100644 index 377edcb23b3..00000000000 --- a/src/mesa/drivers/x11/xfonts.c +++ /dev/null @@ -1,370 +0,0 @@ - -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* xfonts.c -- glXUseXFont() for Mesa written by - * Copyright (C) 1995 Thorsten.Ohl @ Physik.TH-Darmstadt.de - */ - -#include -#include "glxheader.h" -#include "main/context.h" -#include "xfonts.h" - - -/* Some debugging info. */ - -#ifdef DEBUG -#include - -int debug_xfonts = 0; - -static void -dump_char_struct(XCharStruct * ch, char *prefix) -{ - printf("%slbearing = %d, rbearing = %d, width = %d\n", - prefix, ch->lbearing, ch->rbearing, ch->width); - printf("%sascent = %d, descent = %d, attributes = %u\n", - prefix, ch->ascent, ch->descent, (unsigned int) ch->attributes); -} - -static void -dump_font_struct(XFontStruct * font) -{ - printf("ascent = %d, descent = %d\n", font->ascent, font->descent); - printf("char_or_byte2 = (%u,%u)\n", - font->min_char_or_byte2, font->max_char_or_byte2); - printf("byte1 = (%u,%u)\n", font->min_byte1, font->max_byte1); - printf("all_chars_exist = %s\n", font->all_chars_exist ? "True" : "False"); - printf("default_char = %c (\\%03o)\n", - (char) (isprint(font->default_char) ? font->default_char : ' '), - font->default_char); - dump_char_struct(&font->min_bounds, "min> "); - dump_char_struct(&font->max_bounds, "max> "); -#if 0 - for (c = font->min_char_or_byte2; c <= font->max_char_or_byte2; c++) { - char prefix[8]; - sprintf(prefix, "%d> ", c); - dump_char_struct(&font->per_char[c], prefix); - } -#endif -} - -static void -dump_bitmap(unsigned int width, unsigned int height, GLubyte * bitmap) -{ - unsigned int x, y; - - printf(" "); - for (x = 0; x < 8 * width; x++) - printf("%o", 7 - (x % 8)); - putchar('\n'); - for (y = 0; y < height; y++) { - printf("%3o:", y); - for (x = 0; x < 8 * width; x++) - putchar((bitmap[width * (height - y - 1) + x / 8] & (1 << (7 - (x % - 8)))) - ? '*' : '.'); - printf(" "); - for (x = 0; x < width; x++) - printf("0x%02x, ", bitmap[width * (height - y - 1) + x]); - putchar('\n'); - } -} -#endif /* DEBUG */ - - -/* Implementation. */ - -/* Fill a BITMAP with a character C from thew current font - in the graphics context GC. WIDTH is the width in bytes - and HEIGHT is the height in bits. - - Note that the generated bitmaps must be used with - - glPixelStorei (GL_UNPACK_SWAP_BYTES, GL_FALSE); - glPixelStorei (GL_UNPACK_LSB_FIRST, GL_FALSE); - glPixelStorei (GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei (GL_UNPACK_SKIP_ROWS, 0); - glPixelStorei (GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei (GL_UNPACK_ALIGNMENT, 1); - - Possible optimizations: - - * use only one reusable pixmap with the maximum dimensions. - * draw the entire font into a single pixmap (careful with - proportional fonts!). -*/ - - -/* - * Generate OpenGL-compatible bitmap. - */ -static void -fill_bitmap(Display * dpy, Window win, GC gc, - unsigned int width, unsigned int height, - int x0, int y0, unsigned int c, GLubyte * bitmap) -{ - XImage *image; - unsigned int x, y; - Pixmap pixmap; - XChar2b char2b; - - pixmap = XCreatePixmap(dpy, win, 8 * width, height, 1); - XSetForeground(dpy, gc, 0); - XFillRectangle(dpy, pixmap, gc, 0, 0, 8 * width, height); - XSetForeground(dpy, gc, 1); - - char2b.byte1 = (c >> 8) & 0xff; - char2b.byte2 = (c & 0xff); - - XDrawString16(dpy, pixmap, gc, x0, y0, &char2b, 1); - - image = XGetImage(dpy, pixmap, 0, 0, 8 * width, height, 1, XYPixmap); - if (image) { - /* Fill the bitmap (X11 and OpenGL are upside down wrt each other). */ - for (y = 0; y < height; y++) - for (x = 0; x < 8 * width; x++) - if (XGetPixel(image, x, y)) - bitmap[width * (height - y - 1) + x / 8] |= - (1 << (7 - (x % 8))); - XDestroyImage(image); - } - - XFreePixmap(dpy, pixmap); -} - -/* - * determine if a given glyph is valid and return the - * corresponding XCharStruct. - */ -static XCharStruct * -isvalid(XFontStruct * fs, unsigned int which) -{ - unsigned int rows, pages; - unsigned int byte1 = 0, byte2 = 0; - int i, valid = 1; - - rows = fs->max_byte1 - fs->min_byte1 + 1; - pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; - - if (rows == 1) { - /* "linear" fonts */ - if ((fs->min_char_or_byte2 > which) || (fs->max_char_or_byte2 < which)) - valid = 0; - } - else { - /* "matrix" fonts */ - byte2 = which & 0xff; - byte1 = which >> 8; - if ((fs->min_char_or_byte2 > byte2) || - (fs->max_char_or_byte2 < byte2) || - (fs->min_byte1 > byte1) || (fs->max_byte1 < byte1)) - valid = 0; - } - - if (valid) { - if (fs->per_char) { - if (rows == 1) { - /* "linear" fonts */ - return (fs->per_char + (which - fs->min_char_or_byte2)); - } - else { - /* "matrix" fonts */ - i = ((byte1 - fs->min_byte1) * pages) + - (byte2 - fs->min_char_or_byte2); - return (fs->per_char + i); - } - } - else { - return (&fs->min_bounds); - } - } - return (NULL); -} - - -void -Fake_glXUseXFont(Font font, int first, int count, int listbase) -{ - Display *dpy; - Window win; - Pixmap pixmap; - GC gc; - XGCValues values; - unsigned long valuemask; - XFontStruct *fs; - GLint swapbytes, lsbfirst, rowlength; - GLint skiprows, skippixels, alignment; - unsigned int max_width, max_height, max_bm_width, max_bm_height; - GLubyte *bm; - int i; - - dpy = glXGetCurrentDisplay(); - if (!dpy) - return; /* I guess glXMakeCurrent wasn't called */ - win = RootWindow(dpy, DefaultScreen(dpy)); - - fs = XQueryFont(dpy, font); - if (!fs) { - _mesa_error(NULL, GL_INVALID_VALUE, - "Couldn't get font structure information"); - return; - } - - /* Allocate a bitmap that can fit all characters. */ - max_width = fs->max_bounds.rbearing - fs->min_bounds.lbearing; - max_height = fs->max_bounds.ascent + fs->max_bounds.descent; - max_bm_width = (max_width + 7) / 8; - max_bm_height = max_height; - - bm = malloc((max_bm_width * max_bm_height) * sizeof(GLubyte)); - if (!bm) { - XFreeFontInfo(NULL, fs, 1); - _mesa_error(NULL, GL_OUT_OF_MEMORY, - "Couldn't allocate bitmap in glXUseXFont()"); - return; - } - -#if 0 - /* get the page info */ - pages = fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1; - firstchar = (fs->min_byte1 << 8) + fs->min_char_or_byte2; - lastchar = (fs->max_byte1 << 8) + fs->max_char_or_byte2; - rows = fs->max_byte1 - fs->min_byte1 + 1; - unsigned int first_char, last_char, pages, rows; -#endif - - /* Save the current packing mode for bitmaps. */ - glGetIntegerv(GL_UNPACK_SWAP_BYTES, &swapbytes); - glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsbfirst); - glGetIntegerv(GL_UNPACK_ROW_LENGTH, &rowlength); - glGetIntegerv(GL_UNPACK_SKIP_ROWS, &skiprows); - glGetIntegerv(GL_UNPACK_SKIP_PIXELS, &skippixels); - glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment); - - /* Enforce a standard packing mode which is compatible with - fill_bitmap() from above. This is actually the default mode, - except for the (non)alignment. */ - glPixelStorei(GL_UNPACK_SWAP_BYTES, GL_FALSE); - glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE); - glPixelStorei(GL_UNPACK_ROW_LENGTH, 0); - glPixelStorei(GL_UNPACK_SKIP_ROWS, 0); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, 0); - glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - - pixmap = XCreatePixmap(dpy, win, 10, 10, 1); - values.foreground = BlackPixel(dpy, DefaultScreen(dpy)); - values.background = WhitePixel(dpy, DefaultScreen(dpy)); - values.font = fs->fid; - valuemask = GCForeground | GCBackground | GCFont; - gc = XCreateGC(dpy, pixmap, valuemask, &values); - XFreePixmap(dpy, pixmap); - -#ifdef DEBUG - if (debug_xfonts) - dump_font_struct(fs); -#endif - - for (i = 0; i < count; i++) { - unsigned int width, height, bm_width, bm_height; - GLfloat x0, y0, dx, dy; - XCharStruct *ch; - int x, y; - unsigned int c = first + i; - int list = listbase + i; - int valid; - - /* check on index validity and get the bounds */ - ch = isvalid(fs, c); - if (!ch) { - ch = &fs->max_bounds; - valid = 0; - } - else { - valid = 1; - } - -#ifdef DEBUG - if (debug_xfonts) { - char s[7]; - sprintf(s, isprint(c) ? "%c> " : "\\%03o> ", c); - dump_char_struct(ch, s); - } -#endif - - /* glBitmap()' parameters: - straight from the glXUseXFont(3) manpage. */ - width = ch->rbearing - ch->lbearing; - height = ch->ascent + ch->descent; - x0 = -ch->lbearing; - y0 = ch->descent - 0; /* XXX used to subtract 1 here */ - /* but that caused a conformace failure */ - dx = ch->width; - dy = 0; - - /* X11's starting point. */ - x = -ch->lbearing; - y = ch->ascent; - - /* Round the width to a multiple of eight. We will use this also - for the pixmap for capturing the X11 font. This is slightly - inefficient, but it makes the OpenGL part real easy. */ - bm_width = (width + 7) / 8; - bm_height = height; - - glNewList(list, GL_COMPILE); - if (valid && (bm_width > 0) && (bm_height > 0)) { - - memset(bm, '\0', bm_width * bm_height); - fill_bitmap(dpy, win, gc, bm_width, bm_height, x, y, c, bm); - - glBitmap(width, height, x0, y0, dx, dy, bm); -#ifdef DEBUG - if (debug_xfonts) { - printf("width/height = %u/%u\n", width, height); - printf("bm_width/bm_height = %u/%u\n", bm_width, bm_height); - dump_bitmap(bm_width, bm_height, bm); - } -#endif - } - else { - glBitmap(0, 0, 0.0, 0.0, dx, dy, NULL); - } - glEndList(); - } - - free(bm); - XFreeFontInfo(NULL, fs, 1); - XFreeGC(dpy, gc); - - /* Restore saved packing modes. */ - glPixelStorei(GL_UNPACK_SWAP_BYTES, swapbytes); - glPixelStorei(GL_UNPACK_LSB_FIRST, lsbfirst); - glPixelStorei(GL_UNPACK_ROW_LENGTH, rowlength); - glPixelStorei(GL_UNPACK_SKIP_ROWS, skiprows); - glPixelStorei(GL_UNPACK_SKIP_PIXELS, skippixels); - glPixelStorei(GL_UNPACK_ALIGNMENT, alignment); -} diff --git a/src/mesa/drivers/x11/xfonts.h b/src/mesa/drivers/x11/xfonts.h deleted file mode 100644 index 0fc79e1de6b..00000000000 --- a/src/mesa/drivers/x11/xfonts.h +++ /dev/null @@ -1,37 +0,0 @@ - -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -#ifndef XFONTS_H -#define XFONTS_H - -#include - - -extern void Fake_glXUseXFont( Font font, int first, int count, int listbase ); - - -#endif - diff --git a/src/mesa/drivers/x11/xm_api.c b/src/mesa/drivers/x11/xm_api.c deleted file mode 100644 index 6183a67b484..00000000000 --- a/src/mesa/drivers/x11/xm_api.c +++ /dev/null @@ -1,1773 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - -/** - * \file xm_api.c - * - * All the XMesa* API functions. - * - * - * NOTES: - * - * The window coordinate system origin (0,0) is in the lower-left corner - * of the window. X11's window coordinate origin is in the upper-left - * corner of the window. Therefore, most drawing functions in this - * file have to flip Y coordinates. - * - * Define USE_XSHM in the Makefile with -DUSE_XSHM if you want to compile - * in support for the MIT Shared Memory extension. If enabled, when you - * use an Ximage for the back buffer in double buffered mode, the "swap" - * operation will be faster. You must also link with -lXext. - * - * Byte swapping: If the Mesa host and the X display use a different - * byte order then there's some trickiness to be aware of when using - * XImages. The byte ordering used for the XImage is that of the X - * display, not the Mesa host. - * The color-to-pixel encoding for True/DirectColor must be done - * according to the display's visual red_mask, green_mask, and blue_mask. - * If XPutPixel is used to put a pixel into an XImage then XPutPixel will - * do byte swapping if needed. If one wants to directly "poke" the pixel - * into the XImage's buffer then the pixel must be byte swapped first. In - * Mesa, when byte swapping is needed we use the PF_TRUECOLOR pixel format - * and use XPutPixel everywhere except in the implementation of - * glClear(GL_COLOR_BUFFER_BIT). We want this function to be fast so - * instead of using XPutPixel we "poke" our values after byte-swapping - * the clear pixel value if needed. - * - */ - -#ifdef __CYGWIN__ -#undef WIN32 -#undef __WIN32__ -#endif - -#include -#include "glxheader.h" -#include "xmesaP.h" -#include "main/api_exec.h" -#include "main/context.h" -#include "main/extensions.h" -#include "main/framebuffer.h" -#include "main/macros.h" -#include "main/renderbuffer.h" -#include "main/state.h" -#include "main/teximage.h" -#include "main/version.h" -#include "main/vtxfmt.h" -#include "swrast/swrast.h" -#include "swrast/s_renderbuffer.h" -#include "swrast_setup/swrast_setup.h" -#include "vbo/vbo.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "tnl/t_pipeline.h" -#include "drivers/common/driverfuncs.h" -#include "drivers/common/meta.h" -#include "util/u_memory.h" - -/** - * Global X driver lock - */ -mtx_t _xmesa_lock; - - - -/**********************************************************************/ -/***** X Utility Functions *****/ -/**********************************************************************/ - - -/** - * Return the host's byte order as LSBFirst or MSBFirst ala X. - */ -static int host_byte_order( void ) -{ - int i = 1; - char *cptr = (char *) &i; - return (*cptr==1) ? LSBFirst : MSBFirst; -} - - -/** - * Check if the X Shared Memory extension is available. - * Return: 0 = not available - * 1 = shared XImage support available - * 2 = shared Pixmap support available also - */ -static int check_for_xshm( XMesaDisplay *display ) -{ -#if defined(USE_XSHM) - int ignore; - - if (XQueryExtension( display, "MIT-SHM", &ignore, &ignore, &ignore )) { - /* Note: we're no longer calling XShmQueryVersion() here. It seems - * to be flakey (triggers a spurious X protocol error when we close - * one display connection and start using a new one. XShm has been - * around a long time and hasn't changed so if MIT_SHM is supported - * we assume we're good to go. - */ - return 2; - } - else { - return 0; - } -#else - /* No XSHM support */ - return 0; -#endif -} - - -/** - * Apply gamma correction to an intensity value in [0..max]. Return the - * new intensity value. - */ -static GLint -gamma_adjust( GLfloat gamma, GLint value, GLint max ) -{ - if (gamma == 1.0) { - return value; - } - else { - double x = (double) value / (double) max; - return lroundf((GLfloat) max * pow(x, 1.0F/gamma)); - } -} - - - -/** - * Return the true number of bits per pixel for XImages. - * For example, if we request a 24-bit deep visual we may actually need/get - * 32bpp XImages. This function returns the appropriate bpp. - * Input: dpy - the X display - * visinfo - desribes the visual to be used for XImages - * Return: true number of bits per pixel for XImages - */ -static int -bits_per_pixel( XMesaVisual xmv ) -{ - XMesaDisplay *dpy = xmv->display; - XMesaVisualInfo visinfo = xmv->visinfo; - XMesaImage *img; - int bitsPerPixel; - /* Create a temporary XImage */ - img = XCreateImage( dpy, visinfo->visual, visinfo->depth, - ZPixmap, 0, /*format, offset*/ - malloc(8), /*data*/ - 1, 1, /*width, height*/ - 32, /*bitmap_pad*/ - 0 /*bytes_per_line*/ - ); - assert(img); - /* grab the bits/pixel value */ - bitsPerPixel = img->bits_per_pixel; - /* free the XImage */ - free( img->data ); - img->data = NULL; - XMesaDestroyImage( img ); - return bitsPerPixel; -} - - - -/* - * Determine if a given X window ID is valid (window exists). - * Do this by calling XGetWindowAttributes() for the window and - * checking if we catch an X error. - * Input: dpy - the display - * win - the window to check for existence - * Return: GL_TRUE - window exists - * GL_FALSE - window doesn't exist - */ -static GLboolean WindowExistsFlag; - -static int window_exists_err_handler( XMesaDisplay* dpy, XErrorEvent* xerr ) -{ - (void) dpy; - if (xerr->error_code == BadWindow) { - WindowExistsFlag = GL_FALSE; - } - return 0; -} - -static GLboolean window_exists( XMesaDisplay *dpy, Window win ) -{ - XWindowAttributes wa; - int (*old_handler)( XMesaDisplay*, XErrorEvent* ); - WindowExistsFlag = GL_TRUE; - old_handler = XSetErrorHandler(window_exists_err_handler); - XGetWindowAttributes( dpy, win, &wa ); /* dummy request */ - XSetErrorHandler(old_handler); - return WindowExistsFlag; -} - -static Status -get_drawable_size( XMesaDisplay *dpy, Drawable d, GLuint *width, GLuint *height ) -{ - Window root; - Status stat; - int xpos, ypos; - unsigned int w, h, bw, depth; - stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth); - *width = w; - *height = h; - return stat; -} - - -/** - * Return the size of the window (or pixmap) that corresponds to the - * given XMesaBuffer. - * \param width returns width in pixels - * \param height returns height in pixels - */ -void -xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b, - GLuint *width, GLuint *height) -{ - Status stat; - - mtx_lock(&_xmesa_lock); - XSync(b->xm_visual->display, 0); /* added for Chromium */ - stat = get_drawable_size(dpy, b->frontxrb->pixmap, width, height); - mtx_unlock(&_xmesa_lock); - - if (!stat) { - /* probably querying a window that's recently been destroyed */ - _mesa_warning(NULL, "XGetGeometry failed!\n"); - *width = *height = 1; - } -} - - - -/**********************************************************************/ -/***** Linked list of XMesaBuffers *****/ -/**********************************************************************/ - -XMesaBuffer XMesaBufferList = NULL; - - -/** - * Allocate a new XMesaBuffer object which corresponds to the given drawable. - * Note that XMesaBuffer is derived from struct gl_framebuffer. - * The new XMesaBuffer will not have any size (Width=Height=0). - * - * \param d the corresponding X drawable (window or pixmap) - * \param type either WINDOW, PIXMAP or PBUFFER, describing d - * \param vis the buffer's visual - * \param cmap the window's colormap, if known. - * \return new XMesaBuffer or NULL if any problem - */ -static XMesaBuffer -create_xmesa_buffer(XMesaDrawable d, BufferType type, - XMesaVisual vis, XMesaColormap cmap) -{ - XMesaBuffer b; - - assert(type == WINDOW || type == PIXMAP || type == PBUFFER); - - b = (XMesaBuffer) CALLOC_STRUCT(xmesa_buffer); - if (!b) - return NULL; - - b->display = vis->display; - b->xm_visual = vis; - b->type = type; - b->cmap = cmap; - - _mesa_initialize_window_framebuffer(&b->mesa_buffer, &vis->mesa_visual); - b->mesa_buffer.Delete = xmesa_delete_framebuffer; - - /* - * Front renderbuffer - */ - b->frontxrb = xmesa_new_renderbuffer(NULL, 0, vis, GL_FALSE); - if (!b->frontxrb) { - free(b); - return NULL; - } - b->frontxrb->Parent = b; - b->frontxrb->drawable = d; - b->frontxrb->pixmap = (XMesaPixmap) d; - _mesa_attach_and_own_rb(&b->mesa_buffer, BUFFER_FRONT_LEFT, - &b->frontxrb->Base.Base); - - /* - * Back renderbuffer - */ - if (vis->mesa_visual.doubleBufferMode) { - b->backxrb = xmesa_new_renderbuffer(NULL, 0, vis, GL_TRUE); - if (!b->backxrb) { - /* XXX free front xrb too */ - free(b); - return NULL; - } - b->backxrb->Parent = b; - /* determine back buffer implementation */ - b->db_mode = vis->ximage_flag ? BACK_XIMAGE : BACK_PIXMAP; - - _mesa_attach_and_own_rb(&b->mesa_buffer, BUFFER_BACK_LEFT, - &b->backxrb->Base.Base); - } - - /* - * Other renderbuffer (depth, stencil, etc) - */ - _swrast_add_soft_renderbuffers(&b->mesa_buffer, - GL_FALSE, /* color */ - vis->mesa_visual.depthBits > 0, - vis->mesa_visual.stencilBits > 0, - vis->mesa_visual.accumRedBits > 0, - GL_FALSE /* software alpha buffer */ ); - - /* GLX_EXT_texture_from_pixmap */ - b->TextureTarget = 0; - b->TextureFormat = GLX_TEXTURE_FORMAT_NONE_EXT; - b->TextureMipmap = 0; - - /* insert buffer into linked list */ - b->Next = XMesaBufferList; - XMesaBufferList = b; - - return b; -} - - -/** - * Find an XMesaBuffer by matching X display and colormap but NOT matching - * the notThis buffer. - */ -XMesaBuffer -xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis) -{ - XMesaBuffer b; - for (b=XMesaBufferList; b; b=b->Next) { - if (b->display==dpy && b->cmap==cmap && b!=notThis) { - return b; - } - } - return NULL; -} - - -/** - * Remove buffer from linked list, delete if no longer referenced. - */ -static void -xmesa_free_buffer(XMesaBuffer buffer) -{ - XMesaBuffer prev = NULL, b; - - for (b = XMesaBufferList; b; b = b->Next) { - if (b == buffer) { - struct gl_framebuffer *fb = &buffer->mesa_buffer; - - /* unlink buffer from list */ - if (prev) - prev->Next = buffer->Next; - else - XMesaBufferList = buffer->Next; - - /* mark as delete pending */ - fb->DeletePending = GL_TRUE; - - /* Since the X window for the XMesaBuffer is going away, we don't - * want to dereference this pointer in the future. - */ - b->frontxrb->drawable = 0; - - /* Unreference. If count = zero we'll really delete the buffer */ - _mesa_reference_framebuffer(&fb, NULL); - - return; - } - /* continue search */ - prev = b; - } - /* buffer not found in XMesaBufferList */ - _mesa_problem(NULL,"xmesa_free_buffer() - buffer not found\n"); -} - - - - -/**********************************************************************/ -/***** Misc Private Functions *****/ -/**********************************************************************/ - - -/** - * Setup RGB rendering for a window with a True/DirectColor visual. - */ -static void -setup_truecolor(XMesaVisual v, XMesaBuffer buffer, XMesaColormap cmap) -{ - unsigned long rmask, gmask, bmask; - (void) buffer; - (void) cmap; - - /* Compute red multiplier (mask) and bit shift */ - v->rshift = 0; - rmask = GET_REDMASK(v); - while ((rmask & 1)==0) { - v->rshift++; - rmask = rmask >> 1; - } - - /* Compute green multiplier (mask) and bit shift */ - v->gshift = 0; - gmask = GET_GREENMASK(v); - while ((gmask & 1)==0) { - v->gshift++; - gmask = gmask >> 1; - } - - /* Compute blue multiplier (mask) and bit shift */ - v->bshift = 0; - bmask = GET_BLUEMASK(v); - while ((bmask & 1)==0) { - v->bshift++; - bmask = bmask >> 1; - } - - /* - * Compute component-to-pixel lookup tables and dithering kernel - */ - { - static GLubyte kernel[16] = { - 0*16, 8*16, 2*16, 10*16, - 12*16, 4*16, 14*16, 6*16, - 3*16, 11*16, 1*16, 9*16, - 15*16, 7*16, 13*16, 5*16, - }; - GLint rBits = util_bitcount(rmask); - GLint gBits = util_bitcount(gmask); - GLint bBits = util_bitcount(bmask); - GLint maxBits; - GLuint i; - - /* convert pixel components in [0,_mask] to RGB values in [0,255] */ - for (i=0; i<=rmask; i++) - v->PixelToR[i] = (unsigned char) ((i * 255) / rmask); - for (i=0; i<=gmask; i++) - v->PixelToG[i] = (unsigned char) ((i * 255) / gmask); - for (i=0; i<=bmask; i++) - v->PixelToB[i] = (unsigned char) ((i * 255) / bmask); - - /* convert RGB values from [0,255] to pixel components */ - - for (i=0;i<256;i++) { - GLint r = gamma_adjust(v->RedGamma, i, 255); - GLint g = gamma_adjust(v->GreenGamma, i, 255); - GLint b = gamma_adjust(v->BlueGamma, i, 255); - v->RtoPixel[i] = (r >> (8-rBits)) << v->rshift; - v->GtoPixel[i] = (g >> (8-gBits)) << v->gshift; - v->BtoPixel[i] = (b >> (8-bBits)) << v->bshift; - } - /* overflow protection */ - for (i=256;i<512;i++) { - v->RtoPixel[i] = v->RtoPixel[255]; - v->GtoPixel[i] = v->GtoPixel[255]; - v->BtoPixel[i] = v->BtoPixel[255]; - } - - /* setup dithering kernel */ - maxBits = rBits; - if (gBits > maxBits) maxBits = gBits; - if (bBits > maxBits) maxBits = bBits; - for (i=0;i<16;i++) { - v->Kernel[i] = kernel[i] >> maxBits; - } - - v->undithered_pf = PF_Truecolor; - v->dithered_pf = (GET_VISUAL_DEPTH(v)<24) ? PF_Dither_True : PF_Truecolor; - } - - /* - * Now check for TrueColor visuals which we can optimize. - */ - if ( GET_REDMASK(v) ==0x0000ff - && GET_GREENMASK(v)==0x00ff00 - && GET_BLUEMASK(v) ==0xff0000 - && CHECK_BYTE_ORDER(v) - && v->BitsPerPixel==32 - && v->RedGamma==1.0 && v->GreenGamma==1.0 && v->BlueGamma==1.0) { - /* common 32 bpp config used on SGI, Sun */ - v->undithered_pf = v->dithered_pf = PF_8A8B8G8R; /* ABGR */ - } - else if (GET_REDMASK(v) == 0xff0000 - && GET_GREENMASK(v)== 0x00ff00 - && GET_BLUEMASK(v) == 0x0000ff - && CHECK_BYTE_ORDER(v) - && v->RedGamma == 1.0 && v->GreenGamma == 1.0 && v->BlueGamma == 1.0){ - if (v->BitsPerPixel==32) { - /* if 32 bpp, and visual indicates 8 bpp alpha channel */ - if (GET_VISUAL_DEPTH(v) == 32 && v->mesa_visual.alphaBits == 8) - v->undithered_pf = v->dithered_pf = PF_8A8R8G8B; /* ARGB */ - else - v->undithered_pf = v->dithered_pf = PF_8R8G8B; /* xRGB */ - } - else if (v->BitsPerPixel == 24) { - v->undithered_pf = v->dithered_pf = PF_8R8G8B24; /* RGB */ - } - } - else if (GET_REDMASK(v) ==0xf800 - && GET_GREENMASK(v)==0x07e0 - && GET_BLUEMASK(v) ==0x001f - && CHECK_BYTE_ORDER(v) - && v->BitsPerPixel==16 - && v->RedGamma==1.0 && v->GreenGamma==1.0 && v->BlueGamma==1.0) { - /* 5-6-5 RGB */ - v->undithered_pf = PF_5R6G5B; - v->dithered_pf = PF_Dither_5R6G5B; - } -} - - -/** - * When a context is bound for the first time, we can finally finish - * initializing the context's visual and buffer information. - * \param v the XMesaVisual to initialize - * \param b the XMesaBuffer to initialize (may be NULL) - * \param rgb_flag TRUE = RGBA mode, FALSE = color index mode - * \param window the window/pixmap we're rendering into - * \param cmap the colormap associated with the window/pixmap - * \return GL_TRUE=success, GL_FALSE=failure - */ -static GLboolean -initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, - XMesaDrawable window, - XMesaColormap cmap) -{ - const int xclass = v->visualType; - - - assert(!b || b->xm_visual == v); - - /* Save true bits/pixel */ - v->BitsPerPixel = bits_per_pixel(v); - assert(v->BitsPerPixel > 0); - - /* RGB WINDOW: - * We support RGB rendering into almost any kind of visual. - */ - if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) { - setup_truecolor( v, b, cmap ); - } - else { - _mesa_warning(NULL, "XMesa: RGB mode rendering not supported in given visual.\n"); - return GL_FALSE; - } - - if (getenv("MESA_NO_DITHER")) { - v->dithered_pf = v->undithered_pf; - } - - - /* - * If MESA_INFO env var is set print out some debugging info - * which can help Brian figure out what's going on when a user - * reports bugs. - */ - if (getenv("MESA_INFO")) { - printf("X/Mesa visual = %p\n", (void *) v); - printf("X/Mesa dithered pf = %u\n", v->dithered_pf); - printf("X/Mesa undithered pf = %u\n", v->undithered_pf); - printf("X/Mesa depth = %d\n", GET_VISUAL_DEPTH(v)); - printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel); - } - - if (b && window) { - /* Do window-specific initializations */ - - /* these should have been set in create_xmesa_buffer */ - assert(b->frontxrb->drawable == window); - assert(b->frontxrb->pixmap == (XMesaPixmap) window); - - /* Setup for single/double buffering */ - if (v->mesa_visual.doubleBufferMode) { - /* Double buffered */ - b->shm = check_for_xshm( v->display ); - } - - /* X11 graphics contexts */ - b->gc = XCreateGC( v->display, window, 0, NULL ); - XMesaSetFunction( v->display, b->gc, GXcopy ); - - /* cleargc - for glClear() */ - b->cleargc = XCreateGC( v->display, window, 0, NULL ); - XMesaSetFunction( v->display, b->cleargc, GXcopy ); - - /* - * Don't generate Graphics Expose/NoExpose events in swapbuffers(). - * Patch contributed by Michael Pichler May 15, 1995. - */ - { - XGCValues gcvalues; - gcvalues.graphics_exposures = False; - b->swapgc = XCreateGC(v->display, window, - GCGraphicsExposures, &gcvalues); - } - XMesaSetFunction( v->display, b->swapgc, GXcopy ); - } - - return GL_TRUE; -} - - - -/* - * Convert an RGBA color to a pixel value. - */ -unsigned long -xmesa_color_to_pixel(struct gl_context *ctx, - GLubyte r, GLubyte g, GLubyte b, GLubyte a, - GLuint pixelFormat) -{ - XMesaContext xmesa = XMESA_CONTEXT(ctx); - switch (pixelFormat) { - case PF_Truecolor: - { - unsigned long p; - PACK_TRUECOLOR( p, r, g, b ); - return p; - } - case PF_8A8B8G8R: - return PACK_8A8B8G8R( r, g, b, a ); - case PF_8A8R8G8B: - return PACK_8A8R8G8B( r, g, b, a ); - case PF_8R8G8B: - FALLTHROUGH; - case PF_8R8G8B24: - return PACK_8R8G8B( r, g, b ); - case PF_5R6G5B: - return PACK_5R6G5B( r, g, b ); - case PF_Dither_True: - FALLTHROUGH; - case PF_Dither_5R6G5B: - { - unsigned long p; - PACK_TRUEDITHER(p, 1, 0, r, g, b); - return p; - } - default: - _mesa_problem(ctx, "Bad pixel format in xmesa_color_to_pixel"); - } - return 0; -} - - -#define NUM_VISUAL_TYPES 6 - -/** - * Convert an X visual type to a GLX visual type. - * - * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.) - * to be converted. - * \return If \c visualType is a valid X visual type, a GLX visual type will - * be returned. Otherwise \c GLX_NONE will be returned. - * - * \note - * This code was lifted directly from lib/GL/glx/glcontextmodes.c in the - * DRI CVS tree. - */ -static GLint -xmesa_convert_from_x_visual_type( int visualType ) -{ - static const int glx_visual_types[ NUM_VISUAL_TYPES ] = { - GLX_STATIC_GRAY, GLX_GRAY_SCALE, - GLX_STATIC_COLOR, GLX_PSEUDO_COLOR, - GLX_TRUE_COLOR, GLX_DIRECT_COLOR - }; - - return ( (unsigned) visualType < NUM_VISUAL_TYPES ) - ? glx_visual_types[ visualType ] : GLX_NONE; -} - - -/**********************************************************************/ -/***** Public Functions *****/ -/**********************************************************************/ - - -/* - * Create a new X/Mesa visual. - * Input: display - X11 display - * visinfo - an XVisualInfo pointer - * rgb_flag - GL_TRUE = RGB mode, - * GL_FALSE = color index mode - * alpha_flag - alpha buffer requested? - * db_flag - GL_TRUE = double-buffered, - * GL_FALSE = single buffered - * stereo_flag - stereo visual? - * ximage_flag - GL_TRUE = use an XImage for back buffer, - * GL_FALSE = use an off-screen pixmap for back buffer - * depth_size - requested bits/depth values, or zero - * stencil_size - requested bits/stencil values, or zero - * accum_red_size - requested bits/red accum values, or zero - * accum_green_size - requested bits/green accum values, or zero - * accum_blue_size - requested bits/blue accum values, or zero - * accum_alpha_size - requested bits/alpha accum values, or zero - * num_samples - number of samples/pixel if multisampling, or zero - * level - visual level, usually 0 - * visualCaveat - ala the GLX extension, usually GLX_NONE - * Return; a new XMesaVisual or 0 if error. - */ -PUBLIC -XMesaVisual XMesaCreateVisual( XMesaDisplay *display, - XMesaVisualInfo visinfo, - GLboolean rgb_flag, - GLboolean alpha_flag, - GLboolean db_flag, - GLboolean stereo_flag, - GLboolean ximage_flag, - GLint depth_size, - GLint stencil_size, - GLint accum_red_size, - GLint accum_green_size, - GLint accum_blue_size, - GLint accum_alpha_size, - GLint num_samples, - GLint level, - GLint visualCaveat ) -{ - char *gamma; - XMesaVisual v; - GLint red_bits, green_bits, blue_bits, alpha_bits; - - /* For debugging only */ - if (getenv("MESA_XSYNC")) { - /* This makes debugging X easier. - * In your debugger, set a breakpoint on _XError to stop when an - * X protocol error is generated. - */ - XSynchronize( display, 1 ); - } - - /* Color-index rendering not supported. */ - if (!rgb_flag) - return NULL; - - v = (XMesaVisual) CALLOC_STRUCT(xmesa_visual); - if (!v) { - return NULL; - } - - v->display = display; - - /* Save a copy of the XVisualInfo struct because the user may Xfree() - * the struct but we may need some of the information contained in it - * at a later time. - */ - v->visinfo = malloc(sizeof(*visinfo)); - if(!v->visinfo) { - free(v); - return NULL; - } - memcpy(v->visinfo, visinfo, sizeof(*visinfo)); - - /* check for MESA_GAMMA environment variable */ - gamma = getenv("MESA_GAMMA"); - if (gamma) { - v->RedGamma = v->GreenGamma = v->BlueGamma = 0.0; - sscanf( gamma, "%f %f %f", &v->RedGamma, &v->GreenGamma, &v->BlueGamma ); - if (v->RedGamma<=0.0) v->RedGamma = 1.0; - if (v->GreenGamma<=0.0) v->GreenGamma = v->RedGamma; - if (v->BlueGamma<=0.0) v->BlueGamma = v->RedGamma; - } - else { - v->RedGamma = v->GreenGamma = v->BlueGamma = 1.0; - } - - v->ximage_flag = ximage_flag; - - v->mesa_visual.redMask = visinfo->red_mask; - v->mesa_visual.greenMask = visinfo->green_mask; - v->mesa_visual.blueMask = visinfo->blue_mask; - v->visualID = visinfo->visualid; - v->screen = visinfo->screen; - -#if !(defined(__cplusplus) || defined(c_plusplus)) - v->visualType = xmesa_convert_from_x_visual_type(visinfo->class); -#else - v->visualType = xmesa_convert_from_x_visual_type(visinfo->c_class); -#endif - - if (alpha_flag) - v->mesa_visual.alphaBits = 8; - - (void) initialize_visual_and_buffer( v, NULL, 0, 0 ); - - { - const int xclass = v->visualType; - if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) { - red_bits = util_bitcount(GET_REDMASK(v)); - green_bits = util_bitcount(GET_GREENMASK(v)); - blue_bits = util_bitcount(GET_BLUEMASK(v)); - } - else { - /* this is an approximation */ - int depth; - depth = GET_VISUAL_DEPTH(v); - red_bits = depth / 3; - depth -= red_bits; - green_bits = depth / 2; - depth -= green_bits; - blue_bits = depth; - alpha_bits = 0; - assert( red_bits + green_bits + blue_bits == GET_VISUAL_DEPTH(v) ); - } - alpha_bits = v->mesa_visual.alphaBits; - } - - _mesa_initialize_visual(&v->mesa_visual, - db_flag, stereo_flag, - red_bits, green_bits, - blue_bits, alpha_bits, - depth_size, - stencil_size, - accum_red_size, accum_green_size, - accum_blue_size, accum_alpha_size, - 0); - - return v; -} - - -PUBLIC -void XMesaDestroyVisual( XMesaVisual v ) -{ - free(v->visinfo); - free(v); -} - - - -/** - * Create a new XMesaContext. - * \param v the XMesaVisual - * \param share_list another XMesaContext with which to share display - * lists or NULL if no sharing is wanted. - * \return an XMesaContext or NULL if error. - */ -PUBLIC -XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list ) -{ - static GLboolean firstTime = GL_TRUE; - XMesaContext c; - struct gl_context *mesaCtx; - struct dd_function_table functions; - TNLcontext *tnl; - - if (firstTime) { - mtx_init(&_xmesa_lock, mtx_plain); - firstTime = GL_FALSE; - } - - /* Note: the XMesaContext contains a Mesa struct gl_context struct (inheritance) */ - c = (XMesaContext) CALLOC_STRUCT(xmesa_context); - if (!c) - return NULL; - - mesaCtx = &(c->mesa); - - /* initialize with default driver functions, then plug in XMesa funcs */ - _mesa_init_driver_functions(&functions); - _tnl_init_driver_draw_function(&functions); - xmesa_init_driver_functions(v, &functions); - if (!_mesa_initialize_context(mesaCtx, API_OPENGL_COMPAT, &v->mesa_visual, - share_list ? &(share_list->mesa) : (struct gl_context *) NULL, - &functions)) { - free(c); - return NULL; - } - - /* Enable this to exercise fixed function -> shader translation - * with software rendering. - */ - if (0) { - mesaCtx->VertexProgram._MaintainTnlProgram = GL_TRUE; - mesaCtx->FragmentProgram._MaintainTexEnvProgram = GL_TRUE; - _mesa_reset_vertex_processing_mode(mesaCtx); - } - - _mesa_enable_sw_extensions(mesaCtx); - -#if ENABLE_EXT_timer_query - mesaCtx->Extensions.EXT_timer_query = GL_TRUE; -#endif - - - /* finish up xmesa context initializations */ - c->direct = GL_TRUE; - c->swapbytes = CHECK_BYTE_ORDER(v) ? GL_FALSE : GL_TRUE; - c->xm_visual = v; - c->xm_buffer = NULL; /* set later by XMesaMakeCurrent */ - c->display = v->display; - c->pixelformat = v->dithered_pf; /* Dithering is enabled by default */ - - /* Initialize the software rasterizer and helper modules. - */ - if (!_swrast_CreateContext( mesaCtx ) || - !_vbo_CreateContext( mesaCtx, false ) || - !_tnl_CreateContext( mesaCtx ) || - !_swsetup_CreateContext( mesaCtx )) { - _mesa_free_context_data(&c->mesa, true); - free(c); - return NULL; - } - - /* tnl setup */ - tnl = TNL_CONTEXT(mesaCtx); - tnl->Driver.RunPipeline = _tnl_run_pipeline; - /* swrast setup */ - xmesa_register_swrast_functions( mesaCtx ); - _swsetup_Wakeup(mesaCtx); - - _mesa_meta_init(mesaCtx); - - _mesa_override_extensions(mesaCtx); - _mesa_compute_version(mesaCtx); - - /* Exec table initialization requires the version to be computed */ - _mesa_initialize_dispatch_tables(mesaCtx); - _mesa_initialize_vbo_vtxfmt(mesaCtx); - - return c; -} - - - -PUBLIC -void XMesaDestroyContext( XMesaContext c ) -{ - struct gl_context *mesaCtx = &c->mesa; - - _mesa_meta_free( mesaCtx ); - - _swsetup_DestroyContext( mesaCtx ); - _swrast_DestroyContext( mesaCtx ); - _tnl_DestroyContext( mesaCtx ); - _vbo_DestroyContext( mesaCtx ); - _mesa_free_context_data(mesaCtx, true); - free( c ); -} - - - -/** - * Private function for creating an XMesaBuffer which corresponds to an - * X window or pixmap. - * \param v the window's XMesaVisual - * \param w the window we're wrapping - * \return new XMesaBuffer or NULL if error - */ -PUBLIC XMesaBuffer -XMesaCreateWindowBuffer(XMesaVisual v, XMesaWindow w) -{ - XWindowAttributes attr; - XMesaBuffer b; - XMesaColormap cmap; - int depth; - - assert(v); - assert(w); - - /* Check that window depth matches visual depth */ - XGetWindowAttributes( v->display, w, &attr ); - depth = attr.depth; - if (GET_VISUAL_DEPTH(v) != depth) { - _mesa_warning(NULL, "XMesaCreateWindowBuffer: depth mismatch between visual (%d) and window (%d)!\n", - GET_VISUAL_DEPTH(v), depth); - return NULL; - } - - /* Find colormap */ - if (attr.colormap) { - cmap = attr.colormap; - } - else { - _mesa_warning(NULL, "Window %u has no colormap!\n", (unsigned int) w); - /* this is weird, a window w/out a colormap!? */ - /* OK, let's just allocate a new one and hope for the best */ - cmap = XCreateColormap(v->display, w, attr.visual, AllocNone); - } - - b = create_xmesa_buffer((XMesaDrawable) w, WINDOW, v, cmap); - if (!b) - return NULL; - - if (!initialize_visual_and_buffer( v, b, (XMesaDrawable) w, cmap )) { - xmesa_free_buffer(b); - return NULL; - } - - return b; -} - - - -/** - * Create a new XMesaBuffer from an X pixmap. - * - * \param v the XMesaVisual - * \param p the pixmap - * \param cmap the colormap, may be 0 if using a \c GLX_TRUE_COLOR or - * \c GLX_DIRECT_COLOR visual for the pixmap - * \returns new XMesaBuffer or NULL if error - */ -PUBLIC XMesaBuffer -XMesaCreatePixmapBuffer(XMesaVisual v, XMesaPixmap p, XMesaColormap cmap) -{ - XMesaBuffer b; - - assert(v); - - b = create_xmesa_buffer((XMesaDrawable) p, PIXMAP, v, cmap); - if (!b) - return NULL; - - if (!initialize_visual_and_buffer(v, b, (XMesaDrawable) p, cmap)) { - xmesa_free_buffer(b); - return NULL; - } - - return b; -} - - -/** - * For GLX_EXT_texture_from_pixmap - */ -XMesaBuffer -XMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p, - XMesaColormap cmap, - int format, int target, int mipmap) -{ - GET_CURRENT_CONTEXT(ctx); - XMesaBuffer b; - GLuint width, height; - - assert(v); - - b = create_xmesa_buffer((XMesaDrawable) p, PIXMAP, v, cmap); - if (!b) - return NULL; - - /* get pixmap size, update framebuffer/renderbuffer dims */ - xmesa_get_window_size(v->display, b, &width, &height); - _mesa_resize_framebuffer(NULL, &(b->mesa_buffer), width, height); - - if (target == 0) { - /* examine dims */ - if (ctx->Extensions.ARB_texture_non_power_of_two) { - target = GLX_TEXTURE_2D_EXT; - } - else if ( util_bitcount(width) == 1 - && util_bitcount(height) == 1) { - /* power of two size */ - if (height == 1) { - target = GLX_TEXTURE_1D_EXT; - } - else { - target = GLX_TEXTURE_2D_EXT; - } - } - else if (ctx->Extensions.NV_texture_rectangle) { - target = GLX_TEXTURE_RECTANGLE_EXT; - } - else { - /* non power of two textures not supported */ - XMesaDestroyBuffer(b); - return 0; - } - } - - b->TextureTarget = target; - b->TextureFormat = format; - b->TextureMipmap = mipmap; - - if (!initialize_visual_and_buffer(v, b, (XMesaDrawable) p, cmap)) { - xmesa_free_buffer(b); - return NULL; - } - - return b; -} - - - -XMesaBuffer -XMesaCreatePBuffer(XMesaVisual v, XMesaColormap cmap, - unsigned int width, unsigned int height) -{ - XMesaWindow root; - XMesaDrawable drawable; /* X Pixmap Drawable */ - XMesaBuffer b; - - /* allocate pixmap for front buffer */ - root = RootWindow( v->display, v->visinfo->screen ); - drawable = XCreatePixmap(v->display, root, width, height, - v->visinfo->depth); - if (!drawable) - return NULL; - - b = create_xmesa_buffer(drawable, PBUFFER, v, cmap); - if (!b) - return NULL; - - if (!initialize_visual_and_buffer(v, b, drawable, cmap)) { - xmesa_free_buffer(b); - return NULL; - } - - return b; -} - - - -/* - * Deallocate an XMesaBuffer structure and all related info. - */ -PUBLIC void -XMesaDestroyBuffer(XMesaBuffer b) -{ - xmesa_free_buffer(b); -} - - -/** - * Query the current window size and update the corresponding struct gl_framebuffer - * and all attached renderbuffers. - * Called when: - * 1. the first time a buffer is bound to a context. - * 2. from glViewport to poll for window size changes - * 3. from the XMesaResizeBuffers() API function. - * Note: it's possible (and legal) for xmctx to be NULL. That can happen - * when resizing a buffer when no rendering context is bound. - */ -void -xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer) -{ - GLuint width, height; - xmesa_get_window_size(drawBuffer->display, drawBuffer, &width, &height); - if (drawBuffer->mesa_buffer.Width != width || - drawBuffer->mesa_buffer.Height != height) { - struct gl_context *ctx = xmctx ? &xmctx->mesa : NULL; - _mesa_resize_framebuffer(ctx, &(drawBuffer->mesa_buffer), width, height); - } -} - - -/* - * Bind buffer b to context c and make c the current rendering context. - */ -GLboolean XMesaMakeCurrent( XMesaContext c, XMesaBuffer b ) -{ - return XMesaMakeCurrent2( c, b, b ); -} - - -/* - * Bind buffer b to context c and make c the current rendering context. - */ -PUBLIC -GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, - XMesaBuffer readBuffer ) -{ - if (c) { - if (!drawBuffer || !readBuffer) - return GL_FALSE; /* must specify buffers! */ - - if (&(c->mesa) == _mesa_get_current_context() - && c->mesa.DrawBuffer == &drawBuffer->mesa_buffer - && c->mesa.ReadBuffer == &readBuffer->mesa_buffer - && XMESA_BUFFER(c->mesa.DrawBuffer)->wasCurrent) { - /* same context and buffer, do nothing */ - return GL_TRUE; - } - - c->xm_buffer = drawBuffer; - - xmesa_check_and_update_buffer_size(c, drawBuffer); - if (readBuffer != drawBuffer) - xmesa_check_and_update_buffer_size(c, readBuffer); - - _mesa_make_current(&(c->mesa), - &drawBuffer->mesa_buffer, - &readBuffer->mesa_buffer); - - /* - * Must recompute and set these pixel values because colormap - * can be different for different windows. - */ - c->clearpixel = xmesa_color_to_pixel( &c->mesa, - c->clearcolor[0], - c->clearcolor[1], - c->clearcolor[2], - c->clearcolor[3], - c->xm_visual->undithered_pf); - XMesaSetForeground(c->display, drawBuffer->cleargc, c->clearpixel); - - /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */ - drawBuffer->wasCurrent = GL_TRUE; - } - else { - /* Detach */ - _mesa_make_current( NULL, NULL, NULL ); - } - return GL_TRUE; -} - - -/* - * Unbind the context c from its buffer. - */ -GLboolean XMesaUnbindContext( XMesaContext c ) -{ - /* A no-op for XFree86 integration purposes */ - return GL_TRUE; -} - - -XMesaContext XMesaGetCurrentContext( void ) -{ - GET_CURRENT_CONTEXT(ctx); - if (ctx) { - XMesaContext xmesa = XMESA_CONTEXT(ctx); - return xmesa; - } - else { - return 0; - } -} - - -XMesaBuffer XMesaGetCurrentBuffer( void ) -{ - GET_CURRENT_CONTEXT(ctx); - if (ctx) { - XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); - return xmbuf; - } - else { - return 0; - } -} - - -/* New in Mesa 3.1 */ -XMesaBuffer XMesaGetCurrentReadBuffer( void ) -{ - GET_CURRENT_CONTEXT(ctx); - if (ctx) { - return XMESA_BUFFER(ctx->ReadBuffer); - } - else { - return 0; - } -} - - -Display *XMesaGetCurrentDisplay(void) -{ - GET_CURRENT_CONTEXT(ctx); - XMesaContext xmctx = XMESA_CONTEXT(ctx); - return xmctx ? xmctx->display : NULL; -} - - -/** - * Swap buffers notification callback. - * - * \param ctx GL context. - * - * Called by window system just before swapping buffers. - * We have to finish any pending rendering. - */ -static void -XMesaNotifySwapBuffers(struct gl_context *ctx) -{ - if (MESA_VERBOSE & VERBOSE_SWAPBUFFERS) - _mesa_debug(ctx, "SwapBuffers\n"); - - FLUSH_VERTICES(ctx, 0, 0); - if (ctx->Driver.Flush) { - ctx->Driver.Flush(ctx, 0); - } -} - - -/* - * Copy the back buffer to the front buffer. If there's no back buffer - * this is a no-op. - */ -PUBLIC -void XMesaSwapBuffers( XMesaBuffer b ) -{ - GET_CURRENT_CONTEXT(ctx); - - if (!b->backxrb) { - /* single buffered */ - return; - } - - /* If we're swapping the buffer associated with the current context - * we have to flush any pending rendering commands first. - */ - if (ctx && ctx->DrawBuffer == &(b->mesa_buffer)) - XMesaNotifySwapBuffers(ctx); - - if (b->db_mode) { - if (b->backxrb->ximage) { - /* Copy Ximage (back buf) from client memory to server window */ -#if defined(USE_XSHM) - if (b->shm) { - /*mtx_lock(&_xmesa_lock);*/ - XShmPutImage( b->xm_visual->display, b->frontxrb->drawable, - b->swapgc, - b->backxrb->ximage, 0, 0, - 0, 0, b->mesa_buffer.Width, b->mesa_buffer.Height, - False ); - /*mtx_unlock(&_xmesa_lock);*/ - } - else -#endif - { - /*mtx_lock(&_xmesa_lock);*/ - XMesaPutImage( b->xm_visual->display, b->frontxrb->drawable, - b->swapgc, - b->backxrb->ximage, 0, 0, - 0, 0, b->mesa_buffer.Width, b->mesa_buffer.Height ); - /*mtx_unlock(&_xmesa_lock);*/ - } - } - else if (b->backxrb->pixmap) { - /* Copy pixmap (back buf) to window (front buf) on server */ - /*mtx_lock(&_xmesa_lock);*/ - XMesaCopyArea( b->xm_visual->display, - b->backxrb->pixmap, /* source drawable */ - b->frontxrb->drawable, /* dest. drawable */ - b->swapgc, - 0, 0, b->mesa_buffer.Width, b->mesa_buffer.Height, - 0, 0 /* dest region */ - ); - /*mtx_unlock(&_xmesa_lock);*/ - } - } - XSync( b->xm_visual->display, False ); -} - - - -/* - * Copy sub-region of back buffer to front buffer - */ -void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) -{ - GET_CURRENT_CONTEXT(ctx); - - /* If we're swapping the buffer associated with the current context - * we have to flush any pending rendering commands first. - */ - if (ctx && ctx->DrawBuffer == &(b->mesa_buffer)) - XMesaNotifySwapBuffers(ctx); - - if (!b->backxrb) { - /* single buffered */ - return; - } - - if (b->db_mode) { - int yTop = b->mesa_buffer.Height - y - height; - if (b->backxrb->ximage) { - /* Copy Ximage from host's memory to server's window */ -#if defined(USE_XSHM) - if (b->shm) { - /* XXX assuming width and height aren't too large! */ - XShmPutImage( b->xm_visual->display, b->frontxrb->drawable, - b->swapgc, - b->backxrb->ximage, x, yTop, - x, yTop, width, height, False ); - /* wait for finished event??? */ - } - else -#endif - { - /* XXX assuming width and height aren't too large! */ - XMesaPutImage( b->xm_visual->display, b->frontxrb->drawable, - b->swapgc, - b->backxrb->ximage, x, yTop, - x, yTop, width, height ); - } - } - else { - /* Copy pixmap to window on server */ - XMesaCopyArea( b->xm_visual->display, - b->backxrb->pixmap, /* source drawable */ - b->frontxrb->drawable, /* dest. drawable */ - b->swapgc, - x, yTop, width, height, /* source region */ - x, yTop /* dest region */ - ); - } - } -} - - -/* - * Return a pointer to the XMesa backbuffer Pixmap or XImage. This function - * is a way to get "under the hood" of X/Mesa so one can manipulate the - * back buffer directly. - * Output: pixmap - pointer to back buffer's Pixmap, or 0 - * ximage - pointer to back buffer's XImage, or NULL - * Return: GL_TRUE = context is double buffered - * GL_FALSE = context is single buffered - */ -GLboolean XMesaGetBackBuffer( XMesaBuffer b, - XMesaPixmap *pixmap, - XMesaImage **ximage ) -{ - if (b->db_mode) { - if (pixmap) - *pixmap = b->backxrb->pixmap; - if (ximage) - *ximage = b->backxrb->ximage; - return GL_TRUE; - } - else { - *pixmap = 0; - *ximage = NULL; - return GL_FALSE; - } -} - - -/* - * Return the depth buffer associated with an XMesaBuffer. - * Input: b - the XMesa buffer handle - * Output: width, height - size of buffer in pixels - * bytesPerValue - bytes per depth value (2 or 4) - * buffer - pointer to depth buffer values - * Return: GL_TRUE or GL_FALSE to indicate success or failure. - */ -GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height, - GLint *bytesPerValue, void **buffer ) -{ - struct gl_renderbuffer *rb - = b->mesa_buffer.Attachment[BUFFER_DEPTH].Renderbuffer; - struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); - - if (!xrb || !xrb->Base.Buffer) { - *width = 0; - *height = 0; - *bytesPerValue = 0; - *buffer = 0; - return GL_FALSE; - } - else { - *width = b->mesa_buffer.Width; - *height = b->mesa_buffer.Height; - *bytesPerValue = b->mesa_buffer.Visual.depthBits <= 16 - ? sizeof(GLushort) : sizeof(GLuint); - *buffer = (void *) xrb->Base.Buffer; - return GL_TRUE; - } -} - - -void XMesaFlush( XMesaContext c ) -{ - if (c && c->xm_visual) { - XSync( c->xm_visual->display, False ); - } -} - - - -const char *XMesaGetString( XMesaContext c, int name ) -{ - (void) c; - if (name==XMESA_VERSION) { - return "5.0"; - } - else if (name==XMESA_EXTENSIONS) { - return ""; - } - else { - return NULL; - } -} - - - -XMesaBuffer XMesaFindBuffer( XMesaDisplay *dpy, XMesaDrawable d ) -{ - XMesaBuffer b; - for (b=XMesaBufferList; b; b=b->Next) { - if (b->frontxrb->drawable == d && b->display == dpy) { - return b; - } - } - return NULL; -} - - -/** - * Free/destroy all XMesaBuffers associated with given display. - */ -void xmesa_destroy_buffers_on_display(XMesaDisplay *dpy) -{ - XMesaBuffer b, next; - for (b = XMesaBufferList; b; b = next) { - next = b->Next; - if (b->display == dpy) { - xmesa_free_buffer(b); - } - } -} - - -/* - * Look for XMesaBuffers whose X window has been destroyed. - * Deallocate any such XMesaBuffers. - */ -void XMesaGarbageCollect( XMesaDisplay* dpy ) -{ - XMesaBuffer b, next; - for (b=XMesaBufferList; b; b=next) { - next = b->Next; - if (b->display && b->display == dpy && b->frontxrb->drawable && b->type == WINDOW) { - XSync(b->display, False); - if (!window_exists( b->display, b->frontxrb->drawable )) { - /* found a dead window, free the ancillary info */ - XMesaDestroyBuffer( b ); - } - } - } -} - - -unsigned long XMesaDitherColor( XMesaContext xmesa, GLint x, GLint y, - GLfloat red, GLfloat green, - GLfloat blue, GLfloat alpha ) -{ - GLint r = (GLint) (red * 255.0F); - GLint g = (GLint) (green * 255.0F); - GLint b = (GLint) (blue * 255.0F); - GLint a = (GLint) (alpha * 255.0F); - - switch (xmesa->pixelformat) { - case PF_Truecolor: - { - unsigned long p; - PACK_TRUECOLOR( p, r, g, b ); - return p; - } - case PF_8A8B8G8R: - return PACK_8A8B8G8R( r, g, b, a ); - case PF_8A8R8G8B: - return PACK_8A8R8G8B( r, g, b, a ); - case PF_8R8G8B: - return PACK_8R8G8B( r, g, b ); - case PF_5R6G5B: - return PACK_5R6G5B( r, g, b ); - case PF_Dither_5R6G5B: - FALLTHROUGH; - case PF_Dither_True: - { - unsigned long p; - PACK_TRUEDITHER(p, x, y, r, g, b); - return p; - } - default: - _mesa_problem(NULL, "Bad pixel format in XMesaDitherColor"); - } - return 0; -} - - -/* - * This is typically called when the window size changes and we need - * to reallocate the buffer's back/depth/stencil/accum buffers. - */ -PUBLIC void -XMesaResizeBuffers( XMesaBuffer b ) -{ - GET_CURRENT_CONTEXT(ctx); - XMesaContext xmctx = XMESA_CONTEXT(ctx); - if (!xmctx) - return; - xmesa_check_and_update_buffer_size(xmctx, b); -} - - -static GLint -xbuffer_to_renderbuffer(int buffer) -{ - assert(MAX_AUX_BUFFERS <= 4); - - switch (buffer) { - case GLX_FRONT_LEFT_EXT: - return BUFFER_FRONT_LEFT; - case GLX_FRONT_RIGHT_EXT: - return BUFFER_FRONT_RIGHT; - case GLX_BACK_LEFT_EXT: - return BUFFER_BACK_LEFT; - case GLX_BACK_RIGHT_EXT: - return BUFFER_BACK_RIGHT; - case GLX_AUX0_EXT: - case GLX_AUX1_EXT: - case GLX_AUX2_EXT: - case GLX_AUX3_EXT: - case GLX_AUX4_EXT: - case GLX_AUX5_EXT: - case GLX_AUX6_EXT: - case GLX_AUX7_EXT: - case GLX_AUX8_EXT: - case GLX_AUX9_EXT: - default: - /* BadValue error */ - return -1; - } -} - - -PUBLIC void -XMesaBindTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer, - const int *attrib_list) -{ -#if 0 - GET_CURRENT_CONTEXT(ctx); - const GLuint unit = ctx->Texture.CurrentUnit; - struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit]; - struct gl_texture_object *texObj; -#endif - struct gl_renderbuffer *rb; - struct xmesa_renderbuffer *xrb; - GLint b; - XMesaImage *img = NULL; - GLboolean freeImg = GL_FALSE; - - b = xbuffer_to_renderbuffer(buffer); - if (b < 0) - return; - - if (drawable->TextureFormat == GLX_TEXTURE_FORMAT_NONE_EXT) - return; /* BadMatch error */ - - rb = drawable->mesa_buffer.Attachment[b].Renderbuffer; - if (!rb) { - /* invalid buffer */ - return; - } - xrb = xmesa_renderbuffer(rb); - -#if 0 - switch (drawable->TextureTarget) { - case GLX_TEXTURE_1D_EXT: - texObj = texUnit->CurrentTex[TEXTURE_1D_INDEX]; - break; - case GLX_TEXTURE_2D_EXT: - texObj = texUnit->CurrentTex[TEXTURE_2D_INDEX]; - break; - case GLX_TEXTURE_RECTANGLE_EXT: - texObj = texUnit->CurrentTex[TEXTURE_RECT_INDEX]; - break; - default: - return; /* BadMatch error */ - } -#endif - - /* - * The following is a quick and simple way to implement - * BindTexImage. The better way is to write some new FetchTexel() - * functions which would extract texels from XImages. We'd still - * need to use GetImage when texturing from a Pixmap (front buffer) - * but texturing from a back buffer (XImage) would avoid an image - * copy. - */ - - /* get XImage */ - if (xrb->pixmap) { - img = XMesaGetImage(dpy, xrb->pixmap, 0, 0, rb->Width, rb->Height, ~0L, - ZPixmap); - freeImg = GL_TRUE; - } - else if (xrb->ximage) { - img = xrb->ximage; - } - - /* store the XImage as a new texture image */ - if (img) { - GLenum format, type, intFormat; - if (img->bits_per_pixel == 32) { - format = GL_BGRA; - type = GL_UNSIGNED_BYTE; - intFormat = GL_RGBA; - } - else if (img->bits_per_pixel == 24) { - format = GL_BGR; - type = GL_UNSIGNED_BYTE; - intFormat = GL_RGB; - } - else if (img->bits_per_pixel == 16) { - format = GL_BGR; - type = GL_UNSIGNED_SHORT_5_6_5; - intFormat = GL_RGB; - } - else { - _mesa_problem(NULL, "Unexpected XImage format in XMesaBindTexImage"); - return; - } - if (drawable->TextureFormat == GLX_TEXTURE_FORMAT_RGBA_EXT) { - intFormat = GL_RGBA; - } - else if (drawable->TextureFormat == GLX_TEXTURE_FORMAT_RGB_EXT) { - intFormat = GL_RGB; - } - - _mesa_TexImage2D(GL_TEXTURE_2D, 0, intFormat, rb->Width, rb->Height, 0, - format, type, img->data); - - if (freeImg) { - XMesaDestroyImage(img); - } - } -} - - - -PUBLIC void -XMesaReleaseTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer) -{ - const GLint b = xbuffer_to_renderbuffer(buffer); - if (b < 0) - return; - - /* no-op for now */ -} - diff --git a/src/mesa/drivers/x11/xm_buffer.c b/src/mesa/drivers/x11/xm_buffer.c deleted file mode 100644 index 664de8dda77..00000000000 --- a/src/mesa/drivers/x11/xm_buffer.c +++ /dev/null @@ -1,560 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -/** - * \file xm_buffer.h - * Framebuffer and renderbuffer-related functions. - */ - - -#include "glxheader.h" -#include "xmesaP.h" -#include "main/errors.h" -#include "main/formats.h" -#include "main/framebuffer.h" -#include "main/renderbuffer.h" -#include "swrast/s_renderbuffer.h" -#include "util/u_memory.h" - - -#define XMESA_RENDERBUFFER 0x1234 - - -#if defined(USE_XSHM) -static volatile int mesaXErrorFlag = 0; - -/** - * Catches potential Xlib errors. - */ -static int -mesaHandleXError(XMesaDisplay *dpy, XErrorEvent *event) -{ - (void) dpy; - (void) event; - mesaXErrorFlag = 1; - return 0; -} - -/** - * Allocate a shared memory XImage back buffer for the given XMesaBuffer. - * Return: GL_TRUE if success, GL_FALSE if error - */ -static GLboolean -alloc_back_shm_ximage(XMesaBuffer b, GLuint width, GLuint height) -{ - /* - * We have to do a _lot_ of error checking here to be sure we can - * really use the XSHM extension. It seems different servers trigger - * errors at different points if the extension won't work. Therefore - * we have to be very careful... - */ - GC gc; - int (*old_handler)(XMesaDisplay *, XErrorEvent *); - - if (width == 0 || height == 0) { - /* this will be true the first time we're called on 'b' */ - return GL_FALSE; - } - - b->backxrb->ximage = XShmCreateImage(b->xm_visual->display, - b->xm_visual->visinfo->visual, - b->xm_visual->visinfo->depth, - ZPixmap, NULL, &b->shminfo, - width, height); - if (b->backxrb->ximage == NULL) { - _mesa_warning(NULL, "alloc_back_buffer: Shared memory error (XShmCreateImage), disabling.\n"); - b->shm = 0; - return GL_FALSE; - } - - /* 0600 = user read+write */ - b->shminfo.shmid = shmget(IPC_PRIVATE, b->backxrb->ximage->bytes_per_line - * b->backxrb->ximage->height, IPC_CREAT | 0600); - if (b->shminfo.shmid < 0) { - _mesa_warning(NULL, "shmget failed while allocating back buffer.\n"); - XDestroyImage(b->backxrb->ximage); - b->backxrb->ximage = NULL; - _mesa_warning(NULL, "alloc_back_buffer: Shared memory error (shmget), disabling.\n"); - b->shm = 0; - return GL_FALSE; - } - - b->shminfo.shmaddr = b->backxrb->ximage->data - = (char*)shmat(b->shminfo.shmid, 0, 0); - if (b->shminfo.shmaddr == (char *) -1) { - _mesa_warning(NULL, "shmat() failed while allocating back buffer.\n"); - XDestroyImage(b->backxrb->ximage); - shmctl(b->shminfo.shmid, IPC_RMID, 0); - b->backxrb->ximage = NULL; - _mesa_warning(NULL, "alloc_back_buffer: Shared memory error (shmat), disabling.\n"); - b->shm = 0; - return GL_FALSE; - } - - b->shminfo.readOnly = False; - mesaXErrorFlag = 0; - old_handler = XSetErrorHandler(mesaHandleXError); - /* This may trigger the X protocol error we're ready to catch: */ - XShmAttach(b->xm_visual->display, &b->shminfo); - XSync(b->xm_visual->display, False); - - if (mesaXErrorFlag) { - /* we are on a remote display, this error is normal, don't print it */ - XFlush(b->xm_visual->display); - mesaXErrorFlag = 0; - XDestroyImage(b->backxrb->ximage); - shmdt(b->shminfo.shmaddr); - shmctl(b->shminfo.shmid, IPC_RMID, 0); - b->backxrb->ximage = NULL; - b->shm = 0; - (void) XSetErrorHandler(old_handler); - return GL_FALSE; - } - - shmctl(b->shminfo.shmid, IPC_RMID, 0); /* nobody else needs it */ - - /* Finally, try an XShmPutImage to be really sure the extension works */ - gc = XCreateGC(b->xm_visual->display, b->frontxrb->drawable, 0, NULL); - XShmPutImage(b->xm_visual->display, b->frontxrb->drawable, gc, - b->backxrb->ximage, 0, 0, 0, 0, 1, 1 /*one pixel*/, False); - XSync(b->xm_visual->display, False); - XFreeGC(b->xm_visual->display, gc); - (void) XSetErrorHandler(old_handler); - if (mesaXErrorFlag) { - XFlush(b->xm_visual->display); - mesaXErrorFlag = 0; - XDestroyImage(b->backxrb->ximage); - shmdt(b->shminfo.shmaddr); - shmctl(b->shminfo.shmid, IPC_RMID, 0); - b->backxrb->ximage = NULL; - b->shm = 0; - return GL_FALSE; - } - - return GL_TRUE; -} -#else -static GLboolean -alloc_back_shm_ximage(XMesaBuffer b, GLuint width, GLuint height) -{ - /* Can't compile XSHM support */ - return GL_FALSE; -} -#endif - - - -/** - * Setup an off-screen pixmap or Ximage to use as the back buffer. - * Input: b - the X/Mesa buffer - */ -static void -alloc_back_buffer(XMesaBuffer b, GLuint width, GLuint height) -{ - if (b->db_mode == BACK_XIMAGE) { - /* Deallocate the old backxrb->ximage, if any */ - if (b->backxrb->ximage) { -#if defined(USE_XSHM) - if (b->shm) { - XShmDetach(b->xm_visual->display, &b->shminfo); - XDestroyImage(b->backxrb->ximage); - shmdt(b->shminfo.shmaddr); - } - else -#endif - XMesaDestroyImage(b->backxrb->ximage); - b->backxrb->ximage = NULL; - } - - if (width == 0 || height == 0) - return; - - /* Allocate new back buffer */ - if (b->shm == 0 || !alloc_back_shm_ximage(b, width, height)) { - /* Allocate a regular XImage for the back buffer. */ - b->backxrb->ximage = XCreateImage(b->xm_visual->display, - b->xm_visual->visinfo->visual, - GET_VISUAL_DEPTH(b->xm_visual), - ZPixmap, 0, /* format, offset */ - NULL, - width, height, - 8, 0); /* pad, bytes_per_line */ - if (!b->backxrb->ximage) { - _mesa_warning(NULL, "alloc_back_buffer: XCreateImage failed.\n"); - return; - } - b->backxrb->ximage->data = malloc(b->backxrb->ximage->height - * b->backxrb->ximage->bytes_per_line); - if (!b->backxrb->ximage->data) { - _mesa_warning(NULL, "alloc_back_buffer: MALLOC failed.\n"); - XMesaDestroyImage(b->backxrb->ximage); - b->backxrb->ximage = NULL; - } - } - b->backxrb->pixmap = None; - } - else if (b->db_mode == BACK_PIXMAP) { - /* Free the old back pixmap */ - if (b->backxrb->pixmap) { - XMesaFreePixmap(b->xm_visual->display, b->backxrb->pixmap); - b->backxrb->pixmap = 0; - } - - if (width > 0 && height > 0) { - /* Allocate new back pixmap */ - b->backxrb->pixmap = XMesaCreatePixmap(b->xm_visual->display, - b->frontxrb->drawable, - width, height, - GET_VISUAL_DEPTH(b->xm_visual)); - } - - b->backxrb->ximage = NULL; - b->backxrb->drawable = b->backxrb->pixmap; - } -} - - -static void -xmesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb) -{ - /* XXX Note: the ximage or Pixmap attached to this renderbuffer - * should probably get freed here, but that's currently done in - * XMesaDestroyBuffer(). - */ - free(rb); -} - - -/** - * Reallocate renderbuffer storage for front color buffer. - * Called via gl_renderbuffer::AllocStorage() - */ -static GLboolean -xmesa_alloc_front_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, - GLenum internalFormat, GLuint width, GLuint height) -{ - struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); - - /* just clear these to be sure we don't accidentally use them */ - xrb->origin2 = NULL; - xrb->origin3 = NULL; - xrb->origin4 = NULL; - - /* for the FLIP macro: */ - xrb->bottom = height - 1; - - rb->Width = width; - rb->Height = height; - rb->InternalFormat = internalFormat; - - return GL_TRUE; -} - - -/** - * Reallocate renderbuffer storage for back color buffer. - * Called via gl_renderbuffer::AllocStorage() - */ -static GLboolean -xmesa_alloc_back_storage(struct gl_context *ctx, struct gl_renderbuffer *rb, - GLenum internalFormat, GLuint width, GLuint height) -{ - struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); - - /* reallocate the back buffer XImage or Pixmap */ - assert(xrb->Parent); - alloc_back_buffer(xrb->Parent, width, height); - - /* same as front buffer */ - /* XXX why is this here? */ - (void) xmesa_alloc_front_storage(ctx, rb, internalFormat, width, height); - - /* plus... */ - if (xrb->ximage) { - /* Needed by PIXELADDR2 macro */ - xrb->width2 = xrb->ximage->bytes_per_line / 2; - xrb->origin2 = (GLushort *) xrb->ximage->data + xrb->width2 * (height - 1); - - /* Needed by PIXELADDR3 macro */ - xrb->width3 = xrb->ximage->bytes_per_line; - xrb->origin3 = (GLubyte *) xrb->ximage->data + xrb->width3 * (height - 1); - - /* Needed by PIXELADDR4 macro */ - xrb->width4 = xrb->ximage->width; - xrb->origin4 = (GLuint *) xrb->ximage->data + xrb->width4 * (height - 1); - } - else { - /* out of memory or buffer size is 0 x 0 */ - xrb->width2 = xrb->width3 = xrb->width4 = 0; - xrb->origin2 = NULL; - xrb->origin3 = NULL; - xrb->origin4 = NULL; - } - - return GL_TRUE; -} - - -/** - * Used for allocating front/back renderbuffers for an X window. - */ -struct xmesa_renderbuffer * -xmesa_new_renderbuffer(struct gl_context *ctx, GLuint name, - const struct xmesa_visual *xmvis, - GLboolean backBuffer) -{ - struct xmesa_renderbuffer *xrb = CALLOC_STRUCT(xmesa_renderbuffer); - if (xrb) { - GLuint name = 0; - _mesa_init_renderbuffer(&xrb->Base.Base, name); - - xrb->Base.Base.Delete = xmesa_delete_renderbuffer; - if (backBuffer) - xrb->Base.Base.AllocStorage = xmesa_alloc_back_storage; - else - xrb->Base.Base.AllocStorage = xmesa_alloc_front_storage; - - xrb->Base.Base.InternalFormat = GL_RGBA; - xrb->Base.Base._BaseFormat = GL_RGBA; - xrb->Base.Base.ClassID = XMESA_RENDERBUFFER; - - switch (xmvis->undithered_pf) { - case PF_8R8G8B: - /* This will really only happen for pixmaps. We'll access the - * pixmap via a temporary XImage which will be 32bpp. - */ - xrb->Base.Base.Format = MESA_FORMAT_B8G8R8X8_UNORM; - break; - case PF_8A8R8G8B: - xrb->Base.Base.Format = MESA_FORMAT_B8G8R8A8_UNORM; - break; - case PF_8A8B8G8R: - xrb->Base.Base.Format = MESA_FORMAT_R8G8B8A8_UNORM; - break; - case PF_5R6G5B: - xrb->Base.Base.Format = MESA_FORMAT_B5G6R5_UNORM; - break; - default: - _mesa_warning(ctx, "Bad pixel format in xmesa_new_renderbuffer"); - xrb->Base.Base.Format = MESA_FORMAT_B8G8R8A8_UNORM; - break; - } - - /* only need to set Red/Green/EtcBits fields for user-created RBs */ - } - return xrb; -} - - -/** - * Called via gl_framebuffer::Delete() method when this buffer - * is _really_ being deleted. - */ -void -xmesa_delete_framebuffer(struct gl_framebuffer *fb) -{ - XMesaBuffer b = XMESA_BUFFER(fb); - - if (b->num_alloced > 0) { - /* If no other buffer uses this X colormap then free the colors. */ - if (!xmesa_find_buffer(b->display, b->cmap, b)) { - XFreeColors(b->display, b->cmap, - b->alloced_colors, b->num_alloced, 0); - } - } - - if (b->gc) - XMesaFreeGC(b->display, b->gc); - if (b->cleargc) - XMesaFreeGC(b->display, b->cleargc); - if (b->swapgc) - XMesaFreeGC(b->display, b->swapgc); - - if (fb->Visual.doubleBufferMode) { - /* free back ximage/pixmap/shmregion */ - if (b->backxrb->ximage) { -#if defined(USE_XSHM) - if (b->shm) { - XShmDetach( b->display, &b->shminfo ); - XDestroyImage( b->backxrb->ximage ); - shmdt( b->shminfo.shmaddr ); - } - else -#endif - XMesaDestroyImage( b->backxrb->ximage ); - b->backxrb->ximage = NULL; - } - if (b->backxrb->pixmap) { - XMesaFreePixmap( b->display, b->backxrb->pixmap ); - } - } - - _mesa_free_framebuffer_data(fb); - free(fb); -} - - -/** - * Called via ctx->Driver.MapRenderbuffer() - */ -void -xmesa_MapRenderbuffer(struct gl_context *ctx, - struct gl_renderbuffer *rb, - GLuint x, GLuint y, GLuint w, GLuint h, - GLbitfield mode, - GLubyte **mapOut, GLint *rowStrideOut, - bool flip_y) -{ - struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); - - if (xrb->Base.Base.ClassID == XMESA_RENDERBUFFER) { - XImage *ximage = xrb->ximage; - - assert(!xrb->map_mode); /* only a single mapping allowed */ - - xrb->map_mode = mode; - xrb->map_x = x; - xrb->map_y = y; - xrb->map_w = w; - xrb->map_h = h; - - if (ximage) { - int y2 = rb->Height - y - 1; - - *mapOut = (GLubyte *) ximage->data - + y2 * ximage->bytes_per_line - + x * ximage->bits_per_pixel / 8; - } - else { - /* this must be a pixmap/window renderbuffer */ - int (*old_handler)(XMesaDisplay *, XErrorEvent *); - int y2 = rb->Height - y - h; - - assert(xrb->pixmap); - - /* Install error handler for XGetImage() in case the window - * isn't mapped. If we fail we'll create a temporary XImage. - */ - mesaXErrorFlag = 0; - old_handler = XSetErrorHandler(mesaHandleXError); - - /* read pixel data out of the pixmap/window into an XImage */ - ximage = XGetImage(xrb->Parent->display, - xrb->pixmap, x, y2, w, h, - AllPlanes, ZPixmap); - - XSetErrorHandler(old_handler); - - if (mesaXErrorFlag) { - /* create new, temporary XImage */ - int bytes_per_line = - _mesa_format_row_stride(xrb->Base.Base.Format, - xrb->Base.Base.Width); - char *image = malloc(bytes_per_line * - xrb->Base.Base.Height); - ximage = XCreateImage(xrb->Parent->display, - xrb->Parent->xm_visual->visinfo->visual, - xrb->Parent->xm_visual->visinfo->depth, - ZPixmap, /* format */ - 0, /* offset */ - image, /* data */ - xrb->Base.Base.Width, - xrb->Base.Base.Height, - 8, /* pad */ - bytes_per_line); - } - - if (!ximage) { - *mapOut = NULL; - *rowStrideOut = 0; - return; - } - - xrb->map_ximage = ximage; - - /* the first row of the OpenGL image is last row of the XImage */ - *mapOut = (GLubyte *) ximage->data - + (h - 1) * ximage->bytes_per_line; - } - - /* We return a negative stride here since XImage data is upside down - * with respect to OpenGL images. - */ - *rowStrideOut = -ximage->bytes_per_line; - return; - } - - /* otherwise, this is an ordinary malloc-based renderbuffer */ - _swrast_map_soft_renderbuffer(ctx, rb, x, y, w, h, mode, - mapOut, rowStrideOut, false); -} - - -/** - * Called via ctx->Driver.UnmapRenderbuffer() - */ -void -xmesa_UnmapRenderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb) -{ - struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); - - if (xrb->Base.Base.ClassID == XMESA_RENDERBUFFER) { - XImage *ximage = xrb->ximage; - - if (!ximage) { - /* this must be a pixmap/window renderbuffer */ - assert(xrb->pixmap); - assert(xrb->map_ximage); - if (xrb->map_ximage) { - if (xrb->map_mode & GL_MAP_WRITE_BIT) { - /* put modified ximage data back into the pixmap/window */ - int y2 = rb->Height - xrb->map_y - xrb->map_h; - GC gc = XCreateGC(xrb->Parent->display, xrb->pixmap, 0, NULL); - - XPutImage(xrb->Parent->display, - xrb->pixmap, /* dest */ - gc, - xrb->map_ximage, /* source */ - 0, 0, /* src x, y */ - xrb->map_x, y2, /* dest x, y */ - xrb->map_w, xrb->map_h); /* size */ - - XFreeGC(xrb->Parent->display, gc); - } - XMesaDestroyImage(xrb->map_ximage); - xrb->map_ximage = NULL; - } - } - - xrb->map_mode = 0x0; - - return; - } - - /* otherwise, this is an ordinary malloc-based renderbuffer */ - _swrast_unmap_soft_renderbuffer(ctx, rb); -} - - diff --git a/src/mesa/drivers/x11/xm_dd.c b/src/mesa/drivers/x11/xm_dd.c deleted file mode 100644 index 4b50a3ce9b3..00000000000 --- a/src/mesa/drivers/x11/xm_dd.c +++ /dev/null @@ -1,921 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -/** - * \file xm_dd.h - * General device driver functions for Xlib driver. - */ - -#include "glxheader.h" -#include "main/bufferobj.h" -#include "main/context.h" -#include "main/colormac.h" -#include "main/fbobject.h" -#include "main/framebuffer.h" -#include "main/macros.h" -#include "main/mipmap.h" -#include "main/image.h" -#include "main/mtypes.h" -#include "main/pbo.h" -#include "main/texformat.h" -#include "swrast/swrast.h" -#include "swrast/s_context.h" -#include "swrast_setup/swrast_setup.h" -#include "tnl/tnl.h" -#include "tnl/t_context.h" -#include "drivers/common/meta.h" -#include "xmesaP.h" -#include "util/u_memory.h" - - -static void -finish(struct gl_context *ctx) -{ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - if (xmesa) { - mtx_lock(&_xmesa_lock); - XSync( xmesa->display, False ); - mtx_unlock(&_xmesa_lock); - } -} - - -static void -flush(struct gl_context *ctx, unsigned gallium_flush_flags) -{ - finish(ctx); -} - - -/* Implements glColorMask() */ -static void -color_mask(struct gl_context *ctx, - GLboolean rmask, GLboolean gmask, GLboolean bmask, GLboolean amask) -{ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - XMesaBuffer xmbuf; - const int xclass = xmesa->xm_visual->visualType; - (void) amask; - - if (_mesa_is_user_fbo(ctx->DrawBuffer)) - return; - - xmbuf = XMESA_BUFFER(ctx->DrawBuffer); - - if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) { - unsigned long m; - if (rmask && gmask && bmask) { - m = ((unsigned long)~0L); - } - else { - m = 0; - if (rmask) m |= GET_REDMASK(xmesa->xm_visual); - if (gmask) m |= GET_GREENMASK(xmesa->xm_visual); - if (bmask) m |= GET_BLUEMASK(xmesa->xm_visual); - } - XMesaSetPlaneMask( xmesa->display, xmbuf->cleargc, m ); - } -} - - - -/**********************************************************************/ -/*** glClear implementations ***/ -/**********************************************************************/ - - -/** - * Clear the front or back color buffer, if it's implemented with a pixmap. - */ -static void -clear_pixmap(struct gl_context *ctx, struct xmesa_renderbuffer *xrb, - GLint x, GLint y, GLint width, GLint height) -{ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); - - assert(xmbuf); - assert(xrb->pixmap); - assert(xmesa); - assert(xmesa->display); - assert(xrb->pixmap); - assert(xmbuf->cleargc); - - XMesaFillRectangle( xmesa->display, xrb->pixmap, xmbuf->cleargc, - x, xrb->Base.Base.Height - y - height, - width, height ); -} - - -static void -clear_16bit_ximage( struct gl_context *ctx, struct xmesa_renderbuffer *xrb, - GLint x, GLint y, GLint width, GLint height) -{ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - GLuint pixel = (GLuint) xmesa->clearpixel; - GLint i, j; - - if (xmesa->swapbytes) { - pixel = ((pixel >> 8) & 0x00ff) | ((pixel << 8) & 0xff00); - } - - for (j = 0; j < height; j++) { - GLushort *ptr2 = PIXEL_ADDR2(xrb, x, y + j); - for (i = 0; i < width; i++) { - ptr2[i] = pixel; - } - } -} - - -/* Optimized code provided by Nozomi Ytow */ -static void -clear_24bit_ximage(struct gl_context *ctx, struct xmesa_renderbuffer *xrb, - GLint x, GLint y, GLint width, GLint height) -{ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - const GLubyte r = xmesa->clearcolor[0]; - const GLubyte g = xmesa->clearcolor[1]; - const GLubyte b = xmesa->clearcolor[2]; - - if (r == g && g == b) { - /* same value for all three components (gray) */ - GLint j; - for (j = 0; j < height; j++) { - bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y + j); - memset(ptr3, r, 3 * width); - } - } - else { - /* non-gray clear color */ - GLint i, j; - for (j = 0; j < height; j++) { - bgr_t *ptr3 = PIXEL_ADDR3(xrb, x, y + j); - for (i = 0; i < width; i++) { - ptr3->r = r; - ptr3->g = g; - ptr3->b = b; - ptr3++; - } - } - } -} - - -static void -clear_32bit_ximage(struct gl_context *ctx, struct xmesa_renderbuffer *xrb, - GLint x, GLint y, GLint width, GLint height) -{ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - register GLuint pixel = (GLuint) xmesa->clearpixel; - - if (!xrb->ximage) - return; - - if (xmesa->swapbytes) { - pixel = ((pixel >> 24) & 0x000000ff) - | ((pixel >> 8) & 0x0000ff00) - | ((pixel << 8) & 0x00ff0000) - | ((pixel << 24) & 0xff000000); - } - - if (width == xrb->Base.Base.Width && height == xrb->Base.Base.Height) { - /* clearing whole buffer */ - const GLuint n = xrb->Base.Base.Width * xrb->Base.Base.Height; - GLuint *ptr4 = (GLuint *) xrb->ximage->data; - if (pixel == 0) { - /* common case */ - memset(ptr4, pixel, 4 * n); - } - else { - GLuint i; - for (i = 0; i < n; i++) - ptr4[i] = pixel; - } - } - else { - /* clearing scissored region */ - GLint i, j; - for (j = 0; j < height; j++) { - GLuint *ptr4 = PIXEL_ADDR4(xrb, x, y + j); - for (i = 0; i < width; i++) { - ptr4[i] = pixel; - } - } - } -} - - -static void -clear_nbit_ximage(struct gl_context *ctx, struct xmesa_renderbuffer *xrb, - GLint x, GLint y, GLint width, GLint height) -{ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - XMesaImage *img = xrb->ximage; - GLint i, j; - - /* TODO: optimize this */ - y = YFLIP(xrb, y); - for (j = 0; j < height; j++) { - for (i = 0; i < width; i++) { - XMesaPutPixel(img, x+i, y-j, xmesa->clearpixel); - } - } -} - - - -static void -clear_buffers(struct gl_context *ctx, GLbitfield buffers) -{ - if (_mesa_is_winsys_fbo(ctx->DrawBuffer)) { - /* this is a window system framebuffer */ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - XMesaBuffer b = XMESA_BUFFER(ctx->DrawBuffer); - const GLint x = ctx->DrawBuffer->_Xmin; - const GLint y = ctx->DrawBuffer->_Ymin; - const GLint width = ctx->DrawBuffer->_Xmax - x; - const GLint height = ctx->DrawBuffer->_Ymax - y; - - _mesa_unclamped_float_rgba_to_ubyte(xmesa->clearcolor, - ctx->Color.ClearColor.f); - xmesa->clearpixel = xmesa_color_to_pixel(ctx, - xmesa->clearcolor[0], - xmesa->clearcolor[1], - xmesa->clearcolor[2], - xmesa->clearcolor[3], - xmesa->xm_visual->undithered_pf); - XMesaSetForeground(xmesa->display, b->cleargc, xmesa->clearpixel); - - /* we can't handle color or index masking */ - if (GET_COLORMASK(ctx->Color.ColorMask, 0) == 0xf && - ctx->Color.IndexMask == 0xffffffff) { - if (buffers & BUFFER_BIT_FRONT_LEFT) { - /* clear front color buffer */ - struct gl_renderbuffer *frontRb - = ctx->DrawBuffer->Attachment[BUFFER_FRONT_LEFT].Renderbuffer; - if (b->frontxrb == xmesa_renderbuffer(frontRb)) { - /* renderbuffer is not wrapped - great! */ - b->frontxrb->clearFunc(ctx, b->frontxrb, x, y, width, height); - buffers &= ~BUFFER_BIT_FRONT_LEFT; - } - else { - /* we can't directly clear an alpha-wrapped color buffer */ - } - } - if (buffers & BUFFER_BIT_BACK_LEFT) { - /* clear back color buffer */ - struct gl_renderbuffer *backRb - = ctx->DrawBuffer->Attachment[BUFFER_BACK_LEFT].Renderbuffer; - if (b->backxrb == xmesa_renderbuffer(backRb)) { - /* renderbuffer is not wrapped - great! */ - b->backxrb->clearFunc(ctx, b->backxrb, x, y, width, height); - buffers &= ~BUFFER_BIT_BACK_LEFT; - } - } - } - } - if (buffers) - _swrast_Clear(ctx, buffers); -} - - -/* XXX these functions haven't been tested in the Xserver environment */ - - -/** - * Check if we can do an optimized glDrawPixels into an 8R8G8B visual. - */ -static GLboolean -can_do_DrawPixels_8R8G8B(struct gl_context *ctx, GLenum format, GLenum type) -{ - if (format == GL_BGRA && - type == GL_UNSIGNED_BYTE && - ctx->DrawBuffer && - _mesa_is_winsys_fbo(ctx->DrawBuffer) && - ctx->Pixel.ZoomX == 1.0 && /* no zooming */ - ctx->Pixel.ZoomY == 1.0 && - ctx->_ImageTransferState == 0 /* no color tables, scale/bias, etc */) { - const SWcontext *swrast = SWRAST_CONTEXT(ctx); - - if (swrast->NewState) - _swrast_validate_derived( ctx ); - - if ((swrast->_RasterMask & ~CLIP_BIT) == 0) /* no blend, z-test, etc */ { - struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; - if (rb) { - struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); - if (xrb && - xrb->pixmap && /* drawing to pixmap or window */ - _mesa_get_format_bits(xrb->Base.Base.Format, GL_ALPHA_BITS) == 0) { - return GL_TRUE; - } - } - } - } - return GL_FALSE; -} - - -/** - * This function implements glDrawPixels() with an XPutImage call when - * drawing to the front buffer (X Window drawable). - * The image format must be GL_BGRA to match the PF_8R8G8B pixel format. - */ -static void -xmesa_DrawPixels_8R8G8B( struct gl_context *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ) -{ - if (can_do_DrawPixels_8R8G8B(ctx, format, type)) { - const SWcontext *swrast = SWRAST_CONTEXT( ctx ); - struct gl_pixelstore_attrib clippedUnpack = *unpack; - int dstX = x; - int dstY = y; - int w = width; - int h = height; - - if (swrast->NewState) - _swrast_validate_derived( ctx ); - - if (unpack->BufferObj) { - /* unpack from PBO */ - GLubyte *buf; - if (!_mesa_validate_pbo_access(2, unpack, width, height, 1, - format, type, INT_MAX, pixels)) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glDrawPixels(invalid PBO access)"); - return; - } - buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, - unpack->BufferObj->Size, - GL_MAP_READ_BIT, - unpack->BufferObj, - MAP_INTERNAL); - if (!buf) { - return; /* error */ - } - pixels = ADD_POINTERS(buf, pixels); - } - - if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &clippedUnpack)) { - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - XMesaDisplay *dpy = xmesa->xm_visual->display; - XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); - const XMesaGC gc = xmbuf->cleargc; /* effected by glColorMask */ - struct xmesa_renderbuffer *xrb - = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]); - const int srcX = clippedUnpack.SkipPixels; - const int srcY = clippedUnpack.SkipRows; - const int rowLength = clippedUnpack.RowLength; - XMesaImage ximage; - - assert(xmesa->xm_visual->dithered_pf == PF_8R8G8B); - assert(xmesa->xm_visual->undithered_pf == PF_8R8G8B); - assert(dpy); - assert(gc); - - /* This is a little tricky since all coordinates up to now have - * been in the OpenGL bottom-to-top orientation. X is top-to-bottom - * so we have to carefully compute the Y coordinates/addresses here. - */ - memset(&ximage, 0, sizeof(XMesaImage)); - ximage.width = width; - ximage.height = height; - ximage.format = ZPixmap; - ximage.data = (char *) pixels - + ((srcY + h - 1) * rowLength + srcX) * 4; - ximage.byte_order = LSBFirst; - ximage.bitmap_unit = 32; - ximage.bitmap_bit_order = LSBFirst; - ximage.bitmap_pad = 32; - ximage.depth = 32; - ximage.bits_per_pixel = 32; - ximage.bytes_per_line = -rowLength * 4; /* negative to flip image */ - /* it seems we don't need to set the ximage.red/green/blue_mask fields */ - /* flip Y axis for dest position */ - dstY = YFLIP(xrb, dstY) - h + 1; - XPutImage(dpy, xrb->pixmap, gc, &ximage, 0, 0, dstX, dstY, w, h); - } - - if (unpack->BufferObj) { - ctx->Driver.UnmapBuffer(ctx, unpack->BufferObj, MAP_INTERNAL); - } - } - else { - /* software fallback */ - _swrast_DrawPixels(ctx, x, y, width, height, - format, type, unpack, pixels); - } -} - - - -/** - * Check if we can do an optimized glDrawPixels into an 5R6G5B visual. - */ -static GLboolean -can_do_DrawPixels_5R6G5B(struct gl_context *ctx, GLenum format, GLenum type) -{ - if (format == GL_RGB && - type == GL_UNSIGNED_SHORT_5_6_5 && - !ctx->Color.DitherFlag && /* no dithering */ - ctx->DrawBuffer && - _mesa_is_winsys_fbo(ctx->DrawBuffer) && - ctx->Pixel.ZoomX == 1.0 && /* no zooming */ - ctx->Pixel.ZoomY == 1.0 && - ctx->_ImageTransferState == 0 /* no color tables, scale/bias, etc */) { - const SWcontext *swrast = SWRAST_CONTEXT(ctx); - - if (swrast->NewState) - _swrast_validate_derived( ctx ); - - if ((swrast->_RasterMask & ~CLIP_BIT) == 0) /* no blend, z-test, etc */ { - struct gl_renderbuffer *rb = ctx->DrawBuffer->_ColorDrawBuffers[0]; - if (rb) { - struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb); - if (xrb && - xrb->pixmap && /* drawing to pixmap or window */ - _mesa_get_format_bits(xrb->Base.Base.Format, GL_ALPHA_BITS) == 0) { - return GL_TRUE; - } - } - } - } - return GL_FALSE; -} - - -/** - * This function implements glDrawPixels() with an XPutImage call when - * drawing to the front buffer (X Window drawable). The image format - * must be GL_RGB and image type must be GL_UNSIGNED_SHORT_5_6_5 to - * match the PF_5R6G5B pixel format. - */ -static void -xmesa_DrawPixels_5R6G5B( struct gl_context *ctx, - GLint x, GLint y, GLsizei width, GLsizei height, - GLenum format, GLenum type, - const struct gl_pixelstore_attrib *unpack, - const GLvoid *pixels ) -{ - if (can_do_DrawPixels_5R6G5B(ctx, format, type)) { - const SWcontext *swrast = SWRAST_CONTEXT( ctx ); - struct gl_pixelstore_attrib clippedUnpack = *unpack; - int dstX = x; - int dstY = y; - int w = width; - int h = height; - - if (swrast->NewState) - _swrast_validate_derived( ctx ); - - if (unpack->BufferObj) { - /* unpack from PBO */ - GLubyte *buf; - if (!_mesa_validate_pbo_access(2, unpack, width, height, 1, - format, type, INT_MAX, pixels)) { - _mesa_error(ctx, GL_INVALID_OPERATION, - "glDrawPixels(invalid PBO access)"); - return; - } - buf = (GLubyte *) ctx->Driver.MapBufferRange(ctx, 0, - unpack->BufferObj->Size, - GL_MAP_READ_BIT, - unpack->BufferObj, - MAP_INTERNAL); - if (!buf) { - return; /* error */ - } - pixels = ADD_POINTERS(buf, pixels); - } - - if (_mesa_clip_drawpixels(ctx, &dstX, &dstY, &w, &h, &clippedUnpack)) { - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - XMesaDisplay *dpy = xmesa->xm_visual->display; - XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); - const XMesaGC gc = xmbuf->cleargc; /* effected by glColorMask */ - struct xmesa_renderbuffer *xrb - = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]); - const int srcX = clippedUnpack.SkipPixels; - const int srcY = clippedUnpack.SkipRows; - const int rowLength = clippedUnpack.RowLength; - XMesaImage ximage; - - assert(xmesa->xm_visual->undithered_pf == PF_5R6G5B); - assert(dpy); - assert(gc); - - /* This is a little tricky since all coordinates up to now have - * been in the OpenGL bottom-to-top orientation. X is top-to-bottom - * so we have to carefully compute the Y coordinates/addresses here. - */ - memset(&ximage, 0, sizeof(XMesaImage)); - ximage.width = width; - ximage.height = height; - ximage.format = ZPixmap; - ximage.data = (char *) pixels - + ((srcY + h - 1) * rowLength + srcX) * 2; - ximage.byte_order = LSBFirst; - ximage.bitmap_unit = 16; - ximage.bitmap_bit_order = LSBFirst; - ximage.bitmap_pad = 16; - ximage.depth = 16; - ximage.bits_per_pixel = 16; - ximage.bytes_per_line = -rowLength * 2; /* negative to flip image */ - /* it seems we don't need to set the ximage.red/green/blue_mask fields */ - /* flip Y axis for dest position */ - dstY = YFLIP(xrb, dstY) - h + 1; - XPutImage(dpy, xrb->pixmap, gc, &ximage, 0, 0, dstX, dstY, w, h); - } - - if (unpack->BufferObj) { - ctx->Driver.UnmapBuffer(ctx, unpack->BufferObj, MAP_INTERNAL); - } - } - else { - /* software fallback */ - _swrast_DrawPixels(ctx, x, y, width, height, - format, type, unpack, pixels); - } -} - - -/** - * Determine if we can do an optimized glCopyPixels. - */ -static GLboolean -can_do_CopyPixels(struct gl_context *ctx, GLenum type) -{ - if (type == GL_COLOR && - ctx->_ImageTransferState == 0 && /* no color tables, scale/bias, etc */ - ctx->Pixel.ZoomX == 1.0 && /* no zooming */ - ctx->Pixel.ZoomY == 1.0 && - ctx->Color.DrawBuffer[0] == GL_FRONT && /* copy to front buf */ - ctx->Pixel.ReadBuffer == GL_FRONT && /* copy from front buf */ - ctx->ReadBuffer->_ColorReadBuffer && - ctx->DrawBuffer->_ColorDrawBuffers[0]) { - const SWcontext *swrast = SWRAST_CONTEXT( ctx ); - - if (swrast->NewState) - _swrast_validate_derived( ctx ); - - if ((swrast->_RasterMask & ~CLIP_BIT) == 0x0 && - ctx->ReadBuffer && - ctx->ReadBuffer->_ColorReadBuffer && - ctx->DrawBuffer && - ctx->DrawBuffer->_ColorDrawBuffers[0]) { - struct xmesa_renderbuffer *srcXrb - = xmesa_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer); - struct xmesa_renderbuffer *dstXrb - = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]); - if (srcXrb->pixmap && dstXrb->pixmap) { - return GL_TRUE; - } - } - } - return GL_FALSE; -} - - -/** - * Implement glCopyPixels for the front color buffer (or back buffer Pixmap) - * for the color buffer. Don't support zooming, pixel transfer, etc. - * We do support copying from one window to another, ala glXMakeCurrentRead. - */ -static void -xmesa_CopyPixels( struct gl_context *ctx, - GLint srcx, GLint srcy, GLsizei width, GLsizei height, - GLint destx, GLint desty, GLenum type ) -{ - if (can_do_CopyPixels(ctx, type)) { - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - XMesaDisplay *dpy = xmesa->xm_visual->display; - XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); - const XMesaGC gc = xmbuf->cleargc; /* effected by glColorMask */ - struct xmesa_renderbuffer *srcXrb - = xmesa_renderbuffer(ctx->ReadBuffer->_ColorReadBuffer); - struct xmesa_renderbuffer *dstXrb - = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]); - - assert(dpy); - assert(gc); - - /* Note: we don't do any special clipping work here. We could, - * but X will do it for us. - */ - srcy = YFLIP(srcXrb, srcy) - height + 1; - desty = YFLIP(dstXrb, desty) - height + 1; - XCopyArea(dpy, srcXrb->pixmap, dstXrb->pixmap, gc, - srcx, srcy, width, height, destx, desty); - } - else { - _swrast_CopyPixels(ctx, srcx, srcy, width, height, destx, desty, type ); - } -} - - - - -/* - * Every driver should implement a GetString function in order to - * return a meaningful GL_RENDERER string. - */ -static const GLubyte * -get_string( struct gl_context *ctx, GLenum name ) -{ - (void) ctx; - switch (name) { - case GL_RENDERER: - return (const GLubyte *) "Mesa X11"; - case GL_VENDOR: - return NULL; - default: - return NULL; - } -} - - -/* - * We implement the glEnable function only because we care about - * dither enable/disable. - */ -static void -enable( struct gl_context *ctx, GLenum pname, GLboolean state ) -{ - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - - switch (pname) { - case GL_DITHER: - if (state) - xmesa->pixelformat = xmesa->xm_visual->dithered_pf; - else - xmesa->pixelformat = xmesa->xm_visual->undithered_pf; - break; - default: - ; /* silence compiler warning */ - } -} - - -/** - * Called when the driver should update its state, based on the new_state - * flags. - */ -static void -xmesa_update_state(struct gl_context *ctx) -{ - GLbitfield new_state = ctx->NewState; - const XMesaContext xmesa = XMESA_CONTEXT(ctx); - - if (new_state & (_NEW_SCISSOR | _NEW_BUFFERS | _NEW_VIEWPORT)) - _mesa_update_draw_buffer_bounds(ctx, ctx->DrawBuffer); - - /* Propagate statechange information to swrast and swrast_setup - * modules. The X11 driver has no internal GL-dependent state. - */ - _swrast_InvalidateState( ctx, new_state ); - _tnl_InvalidateState( ctx, new_state ); - _swsetup_InvalidateState( ctx, new_state ); - - if (_mesa_is_user_fbo(ctx->DrawBuffer)) - return; - - /* - * GL_DITHER, GL_READ/DRAW_BUFFER, buffer binding state, etc. effect - * renderbuffer span/clear funcs. - * Check _NEW_COLOR to detect dither enable/disable. - */ - if (new_state & (_NEW_COLOR | _NEW_BUFFERS)) { - XMesaBuffer xmbuf = XMESA_BUFFER(ctx->DrawBuffer); - struct xmesa_renderbuffer *front_xrb, *back_xrb; - - front_xrb = xmbuf->frontxrb; - if (front_xrb) { - front_xrb->clearFunc = clear_pixmap; - } - - back_xrb = xmbuf->backxrb; - if (back_xrb) { - if (xmbuf->backxrb->pixmap) { - back_xrb->clearFunc = clear_pixmap; - } - else { - switch (xmesa->xm_visual->BitsPerPixel) { - case 16: - back_xrb->clearFunc = clear_16bit_ximage; - break; - case 24: - back_xrb->clearFunc = clear_24bit_ximage; - break; - case 32: - back_xrb->clearFunc = clear_32bit_ximage; - break; - default: - back_xrb->clearFunc = clear_nbit_ximage; - break; - } - } - } - } -} - - -/** - * Called by glViewport. - * This is a good time for us to poll the current X window size and adjust - * our renderbuffers to match the current window size. - * Remember, we have no opportunity to respond to conventional - * X Resize/StructureNotify events since the X driver has no event loop. - * Thus, we poll. - * Note that this trick isn't fool-proof. If the application never calls - * glViewport, our notion of the current window size may be incorrect. - * That problem led to the GLX_MESA_resize_buffers extension. - */ -static void -xmesa_viewport(struct gl_context *ctx) -{ - XMesaContext xmctx = XMESA_CONTEXT(ctx); - XMesaBuffer xmdrawbuf = XMESA_BUFFER(ctx->WinSysDrawBuffer); - XMesaBuffer xmreadbuf = XMESA_BUFFER(ctx->WinSysReadBuffer); - xmesa_check_and_update_buffer_size(xmctx, xmdrawbuf); - xmesa_check_and_update_buffer_size(xmctx, xmreadbuf); -} - - -#if ENABLE_EXT_timer_query - -/* - * The GL_EXT_timer_query extension is not enabled for the XServer - * indirect renderer. Not sure about how/if wrapping of gettimeofday() - * is done, etc. - */ - -struct xmesa_query_object -{ - struct gl_query_object Base; - struct timeval StartTime; -}; - - -static struct gl_query_object * -xmesa_new_query_object(struct gl_context *ctx, GLuint id) -{ - struct xmesa_query_object *q = CALLOC_STRUCT(xmesa_query_object); - if (q) { - q->Base.Id = id; - q->Base.Ready = GL_TRUE; - } - return &q->Base; -} - - -static void -xmesa_begin_query(struct gl_context *ctx, struct gl_query_object *q) -{ - if (q->Target == GL_TIME_ELAPSED_EXT) { - struct xmesa_query_object *xq = (struct xmesa_query_object *) q; - (void) gettimeofday(&xq->StartTime, NULL); - } -} - - -/** - * Return the difference between the two given times in microseconds. - */ -static GLuint64EXT -time_diff(const struct timeval *t0, const struct timeval *t1) -{ - GLuint64EXT seconds0 = t0->tv_sec & 0xff; /* 0 .. 255 seconds */ - GLuint64EXT seconds1 = t1->tv_sec & 0xff; /* 0 .. 255 seconds */ - GLuint64EXT nanosec0 = (seconds0 * 1000000 + t0->tv_usec) * 1000; - GLuint64EXT nanosec1 = (seconds1 * 1000000 + t1->tv_usec) * 1000; - return nanosec1 - nanosec0; -} - - -static void -xmesa_end_query(struct gl_context *ctx, struct gl_query_object *q) -{ - if (q->Target == GL_TIME_ELAPSED_EXT) { - struct xmesa_query_object *xq = (struct xmesa_query_object *) q; - struct timeval endTime; - (void) gettimeofday(&endTime, NULL); - /* result is in nanoseconds! */ - q->Result = time_diff(&xq->StartTime, &endTime); - } - q->Ready = GL_TRUE; -} - -#endif /* ENABLE_timer_query */ - - -/** - * Initialize the device driver function table with the functions - * we implement in this driver. - */ -void -xmesa_init_driver_functions( XMesaVisual xmvisual, - struct dd_function_table *driver ) -{ - driver->GetString = get_string; - driver->UpdateState = xmesa_update_state; - driver->Flush = flush; - driver->Finish = finish; - driver->ColorMask = color_mask; - driver->Enable = enable; - driver->Viewport = xmesa_viewport; - if (TEST_META_FUNCS) { - driver->Clear = _mesa_meta_Clear; - driver->CopyPixels = _mesa_meta_CopyPixels; - driver->BlitFramebuffer = _mesa_meta_and_swrast_BlitFramebuffer; - driver->DrawPixels = _mesa_meta_DrawPixels; - driver->Bitmap = _mesa_meta_Bitmap; - } - else { - driver->Clear = clear_buffers; - driver->CopyPixels = xmesa_CopyPixels; - if (xmvisual->undithered_pf == PF_8R8G8B && - xmvisual->dithered_pf == PF_8R8G8B && - xmvisual->BitsPerPixel == 32) { - driver->DrawPixels = xmesa_DrawPixels_8R8G8B; - } - else if (xmvisual->undithered_pf == PF_5R6G5B) { - driver->DrawPixels = xmesa_DrawPixels_5R6G5B; - } - } - - driver->MapRenderbuffer = xmesa_MapRenderbuffer; - driver->UnmapRenderbuffer = xmesa_UnmapRenderbuffer; - - driver->GenerateMipmap = _mesa_generate_mipmap; - -#if ENABLE_EXT_timer_query - driver->NewQueryObject = xmesa_new_query_object; - driver->BeginQuery = xmesa_begin_query; - driver->EndQuery = xmesa_end_query; -#endif -} - - -#define XMESA_NEW_POINT (_NEW_POINT | \ - _NEW_RENDERMODE | \ - _SWRAST_NEW_RASTERMASK) - -#define XMESA_NEW_LINE (_NEW_LINE | \ - _NEW_TEXTURE | \ - _NEW_LIGHT | \ - _NEW_DEPTH | \ - _NEW_RENDERMODE | \ - _SWRAST_NEW_RASTERMASK) - -#define XMESA_NEW_TRIANGLE (_NEW_POLYGON | \ - _NEW_TEXTURE | \ - _NEW_LIGHT | \ - _NEW_DEPTH | \ - _NEW_RENDERMODE | \ - _SWRAST_NEW_RASTERMASK) - - -/** - * Extend the software rasterizer with our line/point/triangle - * functions. - * Called during context creation only. - */ -void xmesa_register_swrast_functions( struct gl_context *ctx ) -{ - SWcontext *swrast = SWRAST_CONTEXT( ctx ); - - swrast->choose_point = xmesa_choose_point; - swrast->choose_line = xmesa_choose_line; - swrast->choose_triangle = xmesa_choose_triangle; - - /* XXX these lines have no net effect. Remove??? */ - swrast->InvalidatePointMask |= XMESA_NEW_POINT; - swrast->InvalidateLineMask |= XMESA_NEW_LINE; - swrast->InvalidateTriangleMask |= XMESA_NEW_TRIANGLE; -} diff --git a/src/mesa/drivers/x11/xm_line.c b/src/mesa/drivers/x11/xm_line.c deleted file mode 100644 index 056ebf1edb0..00000000000 --- a/src/mesa/drivers/x11/xm_line.c +++ /dev/null @@ -1,540 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* - * This file contains "accelerated" point, line, and triangle functions. - * It should be fairly easy to write new special-purpose point, line or - * triangle functions and hook them into this module. - */ - - -#include "glxheader.h" -#include "main/macros.h" -#include "main/mtypes.h" -#include "xmesaP.h" - -/* Internal swrast includes: - */ -#include "swrast/s_depth.h" -#include "swrast/s_points.h" -#include "swrast/s_lines.h" -#include "swrast/s_context.h" - - -/**********************************************************************/ -/*** Point rendering ***/ -/**********************************************************************/ - - -/* - * Render an array of points into a pixmap, any pixel format. - */ -#if 000 -/* XXX don't use this, it doesn't dither correctly */ -static void draw_points_ANY_pixmap( struct gl_context *ctx, const SWvertex *vert ) -{ - XMesaContext xmesa = XMESA_CONTEXT(ctx); - XMesaDisplay *dpy = xmesa->xm_visual->display; - XMesaDrawable buffer = xmesa->xm_buffer->buffer; - XMesaGC gc = xmesa->xm_buffer->gc; - - if (xmesa->xm_visual->mesa_visual.RGBAflag) { - register int x, y; - const GLubyte *color = vert->color; - unsigned long pixel = xmesa_color_to_pixel( xmesa, - color[0], color[1], - color[2], color[3], - xmesa->pixelformat); - XMesaSetForeground( dpy, gc, pixel ); - x = (GLint) vert->win[0]; - y = YFLIP( xrb, (GLint) vert->win[1] ); - XMesaDrawPoint( dpy, buffer, gc, x, y); - } - else { - /* Color index mode */ - register int x, y; - XMesaSetForeground( dpy, gc, vert->index ); - x = (GLint) vert->win[0]; - y = YFLIP( xrb, (GLint) vert->win[1] ); - XMesaDrawPoint( dpy, buffer, gc, x, y); - } -} -#endif - - -/* Override the swrast point-selection function. Try to use one of - * our internal point functions, otherwise fall back to the standard - * swrast functions. - */ -void xmesa_choose_point( struct gl_context *ctx ) -{ -#if 0 - XMesaContext xmesa = XMESA_CONTEXT(ctx); - SWcontext *swrast = SWRAST_CONTEXT(ctx); - - if (ctx->RenderMode == GL_RENDER - && ctx->Point.Size == 1.0F && !ctx->Point.SmoothFlag - && swrast->_RasterMask == 0 - && ctx->Texture._MaxEnabledTexImageUnit == -1 - && xmesa->xm_buffer->buffer != XIMAGE) { - swrast->Point = draw_points_ANY_pixmap; - } - else { - _swrast_choose_point( ctx ); - } -#else - _swrast_choose_point( ctx ); -#endif -} - - - -/**********************************************************************/ -/*** Line rendering ***/ -/**********************************************************************/ - - -#if CHAN_BITS == 8 - - -#define GET_XRB(XRB) struct xmesa_renderbuffer *XRB = \ - xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]) - - -/* - * Draw a flat-shaded, PF_TRUECOLOR line into an XImage. - */ -#define NAME flat_TRUECOLOR_line -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; \ - unsigned long pixel; \ - PACK_TRUECOLOR( pixel, color[0], color[1], color[2] ); -#define CLIP_HACK 1 -#define PLOT(X,Y) XMesaPutPixel(xrb->ximage, X, YFLIP(xrb, Y), pixel ); -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, PF_8A8B8G8R line into an XImage. - */ -#define NAME flat_8A8B8G8R_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; \ - GLuint pixel = PACK_8A8B8G8R(color[0], color[1], color[2], color[3]); -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) *pixelPtr = pixel; -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, PF_8A8R8G8B line into an XImage. - */ -#define NAME flat_8A8R8G8B_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; \ - GLuint pixel = PACK_8A8R8G8B(color[0], color[1], color[2], color[3]); -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) *pixelPtr = pixel; -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, PF_8R8G8B line into an XImage. - */ -#define NAME flat_8R8G8B_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; \ - GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] ); -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) *pixelPtr = pixel; -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, PF_8R8G8B24 line into an XImage. - */ -#define NAME flat_8R8G8B24_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; -#define PIXEL_TYPE bgr_t -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) { \ - pixelPtr->r = color[RCOMP]; \ - pixelPtr->g = color[GCOMP]; \ - pixelPtr->b = color[BCOMP]; \ -} -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, PF_5R6G5B line into an XImage. - */ -#define NAME flat_5R6G5B_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; \ - GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] ); -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) *pixelPtr = pixel; -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, PF_DITHER_5R6G5B line into an XImage. - */ -#define NAME flat_DITHER_5R6G5B_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - const GLubyte *color = vert1->color; -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) PACK_TRUEDITHER( *pixelPtr, X, Y, color[0], color[1], color[2] ); -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, Z-less, PF_TRUECOLOR line into an XImage. - */ -#define NAME flat_TRUECOLOR_z_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - const GLubyte *color = vert1->color; \ - unsigned long pixel; \ - PACK_TRUECOLOR( pixel, color[0], color[1], color[2] ); -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define CLIP_HACK 1 -#define PLOT(X,Y) \ - if (Z < *zPtr) { \ - *zPtr = Z; \ - XMesaPutPixel(xrb->ximage, X, YFLIP(xrb, Y), pixel); \ - } -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, Z-less, PF_8A8B8G8R line into an XImage. - */ -#define NAME flat_8A8B8G8R_z_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; \ - GLuint pixel = PACK_8A8B8G8R(color[0], color[1], color[2], color[3]); -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X,Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) \ - if (Z < *zPtr) { \ - *zPtr = Z; \ - *pixelPtr = pixel; \ - } -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, Z-less, PF_8A8R8G8B line into an XImage. - */ -#define NAME flat_8A8R8G8B_z_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; \ - GLuint pixel = PACK_8A8R8G8B(color[0], color[1], color[2], color[3]); -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X,Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) \ - if (Z < *zPtr) { \ - *zPtr = Z; \ - *pixelPtr = pixel; \ - } -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, Z-less, PF_8R8G8B line into an XImage. - */ -#define NAME flat_8R8G8B_z_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; \ - GLuint pixel = PACK_8R8G8B( color[0], color[1], color[2] ); -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X,Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) \ - if (Z < *zPtr) { \ - *zPtr = Z; \ - *pixelPtr = pixel; \ - } -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, Z-less, PF_8R8G8B24 line into an XImage. - */ -#define NAME flat_8R8G8B24_z_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_TYPE bgr_t -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X,Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) \ - if (Z < *zPtr) { \ - *zPtr = Z; \ - pixelPtr->r = color[RCOMP]; \ - pixelPtr->g = color[GCOMP]; \ - pixelPtr->b = color[BCOMP]; \ - } -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, Z-less, PF_5R6G5B line into an XImage. - */ -#define NAME flat_5R6G5B_z_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = vert1->color; \ - GLushort pixel = PACK_5R6G5B( color[0], color[1], color[2] ); -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X,Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) \ - if (Z < *zPtr) { \ - *zPtr = Z; \ - *pixelPtr = pixel; \ - } -#include "swrast/s_linetemp.h" - - - -/* - * Draw a flat-shaded, Z-less, PF_DITHER_5R6G5B line into an XImage. - */ -#define NAME flat_DITHER_5R6G5B_z_line -#define SETUP_CODE \ - GET_XRB(xrb); \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - const GLubyte *color = vert1->color; -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X,Y) -#define CLIP_HACK 1 -#define PLOT(X,Y) \ - if (Z < *zPtr) { \ - *zPtr = Z; \ - PACK_TRUEDITHER(*pixelPtr, X, Y, color[0], color[1], color[2]); \ - } -#include "swrast/s_linetemp.h" - - - -/** - * Draw fast, XOR line with XDrawLine in front color buffer. - * WARNING: this isn't fully OpenGL conformant because different pixels - * will be hit versus using the other line functions. - * Don't use the code in X server GLcore module since we need a wrapper - * for the XSetLineAttributes() function call. - */ -static void -xor_line(struct gl_context *ctx, const SWvertex *vert0, const SWvertex *vert1) -{ - XMesaContext xmesa = XMESA_CONTEXT(ctx); - XMesaDisplay *dpy = xmesa->xm_visual->display; - XMesaGC gc = xmesa->xm_buffer->gc; - GET_XRB(xrb); - unsigned long pixel = xmesa_color_to_pixel(ctx, - vert1->color[0], vert1->color[1], - vert1->color[2], vert1->color[3], - xmesa->pixelformat); - int x0 = (GLint) vert0->attrib[VARYING_SLOT_POS][0]; - int y0 = YFLIP(xrb, (GLint) vert0->attrib[VARYING_SLOT_POS][1]); - int x1 = (GLint) vert1->attrib[VARYING_SLOT_POS][0]; - int y1 = YFLIP(xrb, (GLint) vert1->attrib[VARYING_SLOT_POS][1]); - XMesaSetForeground(dpy, gc, pixel); - XMesaSetFunction(dpy, gc, GXxor); - XSetLineAttributes(dpy, gc, (int) ctx->Line.Width, - LineSolid, CapButt, JoinMiter); - XDrawLine(dpy, xrb->pixmap, gc, x0, y0, x1, y1); - XMesaSetFunction(dpy, gc, GXcopy); /* this gc is used elsewhere */ -} - - -#endif /* CHAN_BITS == 8 */ - - -/** - * Return pointer to line drawing function, or NULL if we should use a - * swrast fallback. - */ -static swrast_line_func -get_line_func(struct gl_context *ctx) -{ -#if CHAN_BITS == 8 - SWcontext *swrast = SWRAST_CONTEXT(ctx); - XMesaContext xmesa = XMESA_CONTEXT(ctx); - const struct xmesa_renderbuffer *xrb; - - if ((ctx->DrawBuffer->_ColorDrawBufferIndexes[0] != BUFFER_BIT_FRONT_LEFT) && - (ctx->DrawBuffer->_ColorDrawBufferIndexes[0] != BUFFER_BIT_BACK_LEFT)) - return (swrast_line_func) NULL; - if (ctx->RenderMode != GL_RENDER) return (swrast_line_func) NULL; - if (ctx->Line.SmoothFlag) return (swrast_line_func) NULL; - if (ctx->Texture._MaxEnabledTexImageUnit != -1) return (swrast_line_func) NULL; - if (ctx->Light.ShadeModel != GL_FLAT) return (swrast_line_func) NULL; - if (ctx->Line.StippleFlag) return (swrast_line_func) NULL; - if (swrast->_RasterMask & MULTI_DRAW_BIT) return (swrast_line_func) NULL; - - xrb = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]); - - if (xrb->ximage - && swrast->_RasterMask==DEPTH_BIT - && ctx->Depth.Func==GL_LESS - && ctx->Depth.Mask==GL_TRUE - && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS - && ctx->Line.Width==1.0F) { - switch (xmesa->pixelformat) { - case PF_Truecolor: - return flat_TRUECOLOR_z_line; - case PF_8A8B8G8R: - return flat_8A8B8G8R_z_line; - case PF_8A8R8G8B: - return flat_8A8R8G8B_z_line; - case PF_8R8G8B: - return flat_8R8G8B_z_line; - case PF_8R8G8B24: - return flat_8R8G8B24_z_line; - case PF_5R6G5B: - return flat_5R6G5B_z_line; - case PF_Dither_5R6G5B: - return flat_DITHER_5R6G5B_z_line; - default: - return (swrast_line_func)NULL; - } - } - if (xrb->ximage - && swrast->_RasterMask==0 - && ctx->Line.Width==1.0F) { - switch (xmesa->pixelformat) { - case PF_Truecolor: - return flat_TRUECOLOR_line; - case PF_8A8B8G8R: - return flat_8A8B8G8R_line; - case PF_8A8R8G8B: - return flat_8A8R8G8B_line; - case PF_8R8G8B: - return flat_8R8G8B_line; - case PF_8R8G8B24: - return flat_8R8G8B24_line; - case PF_5R6G5B: - return flat_5R6G5B_line; - case PF_Dither_5R6G5B: - return flat_DITHER_5R6G5B_line; - default: - return (swrast_line_func)NULL; - } - } - - if (ctx->DrawBuffer->_NumColorDrawBuffers == 1 - && ctx->DrawBuffer->_ColorDrawBufferIndexes[0] == BUFFER_FRONT_LEFT - && swrast->_RasterMask == LOGIC_OP_BIT - && ctx->Color.LogicOp == GL_XOR - && !ctx->Line.StippleFlag - && !ctx->Line.SmoothFlag) { - return xor_line; - } - -#endif /* CHAN_BITS == 8 */ - return (swrast_line_func) NULL; -} - - -/** - * Override for the swrast line-selection function. Try to use one - * of our internal line functions, otherwise fall back to the - * standard swrast functions. - */ -void -xmesa_choose_line(struct gl_context *ctx) -{ - SWcontext *swrast = SWRAST_CONTEXT(ctx); - - if (!(swrast->Line = get_line_func( ctx ))) - _swrast_choose_line( ctx ); -} diff --git a/src/mesa/drivers/x11/xm_tri.c b/src/mesa/drivers/x11/xm_tri.c deleted file mode 100644 index fff2af05a18..00000000000 --- a/src/mesa/drivers/x11/xm_tri.c +++ /dev/null @@ -1,1151 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* - * This file contains "accelerated" triangle functions. It should be - * fairly easy to write new special-purpose triangle functions and hook - * them into this module. - */ - - -#include -#include "c99_math.h" -#include "main/mtypes.h" -#include "glxheader.h" -#include "xmesaP.h" - -/* Internal swrast includes: - */ -#include "swrast/s_context.h" -#include "swrast/s_depth.h" -#include "swrast/s_triangle.h" - - -#define GET_XRB(XRB) struct xmesa_renderbuffer *XRB = \ - xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]) - - -/**********************************************************************/ -/*** Triangle rendering ***/ -/**********************************************************************/ - - -#if CHAN_BITS == 8 - -/* - * XImage, smooth, depth-buffered, PF_TRUECOLOR triangle. - */ -#define NAME smooth_TRUECOLOR_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define INTERP_RGB 1 -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); - -#define RENDER_SPAN( span ) { \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - GLuint i; \ - for (i = 0; i < span.end; i++, x++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - unsigned long p; \ - PACK_TRUECOLOR(p, FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue)); \ - XMesaPutPixel(xrb->ximage, x, y, p); \ - zRow[i] = z; \ - } \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - span.z += span.zStep; \ - } } - -#include "swrast/s_tritemp.h" - - - - -/* - * XImage, smooth, depth-buffered, PF_8A8B8G8R triangle. - */ -#define NAME smooth_8A8B8G8R_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define INTERP_RGB 1 -#define INTERP_ALPHA 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - pRow[i] = PACK_8A8B8G8R(FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue), \ - FixedToInt(span.alpha)); \ - zRow[i] = z; \ - } \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - span.alpha += span.alphaStep; \ - span.z += span.zStep; \ - } } - -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, depth-buffered, PF_8A8R8G8B triangle. - */ -#define NAME smooth_8A8R8G8B_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define INTERP_RGB 1 -#define INTERP_ALPHA 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); - -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - pRow[i] = PACK_8A8R8G8B(FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue), \ - FixedToInt(span.alpha)); \ - zRow[i] = z; \ - } \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - span.alpha += span.alphaStep; \ - span.z += span.zStep; \ - } } - -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, depth-buffered, PF_8R8G8B triangle. - */ -#define NAME smooth_8R8G8B_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define INTERP_RGB 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); - -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - pRow[i] = PACK_8R8G8B(FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue)); \ - zRow[i] = z; \ - } \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - span.z += span.zStep; \ - } } - -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, depth-buffered, PF_8R8G8B24 triangle. - */ -#define NAME smooth_8R8G8B24_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define INTERP_RGB 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y) -#define PIXEL_TYPE bgr_t -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - PIXEL_TYPE *ptr = pRow + i; \ - ptr->r = FixedToInt(span.red); \ - ptr->g = FixedToInt(span.green); \ - ptr->b = FixedToInt(span.blue); \ - zRow[i] = z; \ - } \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, depth-buffered, PF_TRUEDITHER triangle. - */ -#define NAME smooth_TRUEDITHER_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define INTERP_RGB 1 -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - unsigned long p; \ - PACK_TRUEDITHER(p, x, y, FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue)); \ - XMesaPutPixel(xrb->ximage, x, y, p); \ - zRow[i] = z; \ - } \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, depth-buffered, PF_5R6G5B triangle. - */ -#define NAME smooth_5R6G5B_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define INTERP_RGB 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - pRow[i] = PACK_5R6G5B(FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue)); \ - zRow[i] = z; \ - } \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, depth-buffered, PF_DITHER_5R6G5B triangle. - */ -#define NAME smooth_DITHER_5R6G5B_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define INTERP_RGB 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue)); \ - zRow[i] = z; \ - } \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, depth-buffered, PF_TRUECOLOR triangle. - */ -#define NAME flat_TRUECOLOR_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); \ - XMesaImage *img = xrb->ximage; \ - unsigned long pixel; \ - PACK_TRUECOLOR(pixel, v2->color[0], v2->color[1], v2->color[2]); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - XMesaPutPixel(img, x, y, pixel); \ - zRow[i] = z; \ - } \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, depth-buffered, PF_8A8B8G8R triangle. - */ -#define NAME flat_8A8B8G8R_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); \ - GLuint p = PACK_8A8B8G8R( v2->color[0], v2->color[1],\ - v2->color[2], v2->color[3]); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - pRow[i] = (PIXEL_TYPE) p; \ - zRow[i] = z; \ - } \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, depth-buffered, PF_8A8R8G8B triangle. - */ -#define NAME flat_8A8R8G8B_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); \ - GLuint p = PACK_8A8R8G8B(v2->color[0], v2->color[1], \ - v2->color[2], v2->color[3]); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - pRow[i] = (PIXEL_TYPE) p; \ - zRow[i] = z; \ - } \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, depth-buffered, PF_8R8G8B triangle. - */ -#define NAME flat_8R8G8B_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); \ - GLuint p = PACK_8R8G8B( v2->color[0], v2->color[1], v2->color[2] ); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - pRow[i] = (PIXEL_TYPE) p; \ - zRow[i] = z; \ - } \ - span.z += span.zStep; \ - } } - -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, depth-buffered, PF_8R8G8B24 triangle. - */ -#define NAME flat_8R8G8B24_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y) -#define PIXEL_TYPE bgr_t -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = v2->color; -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - PIXEL_TYPE *ptr = pRow + i; \ - ptr->r = color[RCOMP]; \ - ptr->g = color[GCOMP]; \ - ptr->b = color[BCOMP]; \ - zRow[i] = z; \ - } \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, depth-buffered, PF_TRUEDITHER triangle. - */ -#define NAME flat_TRUEDITHER_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); \ - XMesaImage *img = xrb->ximage; -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - unsigned long p; \ - PACK_TRUEDITHER(p, x, y, v2->color[0], \ - v2->color[1], v2->color[2]); \ - XMesaPutPixel(img, x, y, p); \ - zRow[i] = z; \ - } \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, depth-buffered, PF_5R6G5B triangle. - */ -#define NAME flat_5R6G5B_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); \ - GLushort p = PACK_5R6G5B( v2->color[0], v2->color[1], v2->color[2] ); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - pRow[i] = (PIXEL_TYPE) p; \ - zRow[i] = z; \ - } \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, depth-buffered, PF_DITHER_5R6G5B triangle. - */ -#define NAME flat_DITHER_5R6G5B_z_triangle -#define INTERP_Z 1 -#define DEPTH_TYPE DEFAULT_SOFTWARE_DEPTH_TYPE -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); \ - const GLubyte *color = v2->color; -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - const DEPTH_TYPE z = FixedToDepth(span.z); \ - if (z < zRow[i]) { \ - PACK_TRUEDITHER(pRow[i], x, y, color[RCOMP], \ - color[GCOMP], color[BCOMP]); \ - zRow[i] = z; \ - } \ - span.z += span.zStep; \ - } } -#include "swrast/s_tritemp.h" - - -/* - * XImage, smooth, NON-depth-buffered, PF_TRUECOLOR triangle. - */ -#define NAME smooth_TRUECOLOR_triangle -#define INTERP_RGB 1 -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); \ - XMesaImage *img = xrb->ximage; -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - unsigned long p; \ - PACK_TRUECOLOR(p, FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue)); \ - XMesaPutPixel(img, x, y, p); \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, NON-depth-buffered, PF_8A8B8G8R triangle. - */ -#define NAME smooth_8A8B8G8R_triangle -#define INTERP_RGB 1 -#define INTERP_ALPHA 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - pRow[i] = PACK_8A8B8G8R(FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue), \ - FixedToInt(span.alpha)); \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - span.alpha += span.alphaStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, NON-depth-buffered, PF_8A8R8G8B triangle. - */ -#define NAME smooth_8A8R8G8B_triangle -#define INTERP_RGB 1 -#define INTERP_ALPHA 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - pRow[i] = PACK_8A8R8G8B(FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue), \ - FixedToInt(span.alpha)); \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - span.alpha += span.alphaStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle. - */ -#define NAME smooth_8R8G8B_triangle -#define INTERP_RGB 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - pRow[i] = PACK_8R8G8B(FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue) ); \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, NON-depth-buffered, PF_8R8G8B triangle. - */ -#define NAME smooth_8R8G8B24_triangle -#define INTERP_RGB 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y) -#define PIXEL_TYPE bgr_t -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - PIXEL_TYPE *pixel = pRow; \ - for (i = 0; i < span.end; i++, pixel++) { \ - pixel->r = FixedToInt(span.red); \ - pixel->g = FixedToInt(span.green); \ - pixel->b = FixedToInt(span.blue); \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, NON-depth-buffered, PF_TRUEDITHER triangle. - */ -#define NAME smooth_TRUEDITHER_triangle -#define INTERP_RGB 1 -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); \ - XMesaImage *img = xrb->ximage; -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - unsigned long p; \ - PACK_TRUEDITHER(p, x, y, FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue)); \ - XMesaPutPixel(img, x, y, p ); \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, NON-depth-buffered, PF_5R6G5B triangle. - */ -#define NAME smooth_5R6G5B_triangle -#define INTERP_RGB 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - pRow[i] = (PIXEL_TYPE) PACK_5R6G5B(FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue)); \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, smooth, NON-depth-buffered, PF_DITHER_5R6G5B triangle. - */ -#define NAME smooth_DITHER_5R6G5B_triangle -#define INTERP_RGB 1 -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - PACK_TRUEDITHER(pRow[i], x, y, FixedToInt(span.red), \ - FixedToInt(span.green), FixedToInt(span.blue)); \ - span.red += span.redStep; \ - span.green += span.greenStep; \ - span.blue += span.blueStep; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, NON-depth-buffered, PF_TRUECOLOR triangle. - */ -#define NAME flat_TRUECOLOR_triangle -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); \ - XMesaImage *img = xrb->ximage; \ - unsigned long pixel; \ - PACK_TRUECOLOR(pixel, v2->color[0], v2->color[1], v2->color[2]); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - XMesaPutPixel(img, x, y, pixel); \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, NON-depth-buffered, PF_8A8B8G8R triangle. - */ -#define NAME flat_8A8B8G8R_triangle -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); \ - unsigned long p = PACK_8B8G8R( v2->color[0], \ - v2->color[1], v2->color[2] ); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - pRow[i] = (PIXEL_TYPE) p; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, NON-depth-buffered, PF_8A8R8G8B triangle. - */ -#define NAME flat_8A8R8G8B_triangle -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); \ - unsigned long p = PACK_8R8G8B( v2->color[0], \ - v2->color[1], v2->color[2] ); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - pRow[i] = (PIXEL_TYPE) p; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, NON-depth-buffered, PF_8R8G8B triangle. - */ -#define NAME flat_8R8G8B_triangle -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR4(xrb, X, Y) -#define PIXEL_TYPE GLuint -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); \ - unsigned long p = PACK_8R8G8B( v2->color[0], \ - v2->color[1], v2->color[2] ); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - pRow[i] = (PIXEL_TYPE) p; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, NON-depth-buffered, PF_8R8G8B24 triangle. - */ -#define NAME flat_8R8G8B24_triangle -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR3(xrb, X, Y) -#define PIXEL_TYPE bgr_t -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); \ - const GLubyte *color = v2->color; -#define RENDER_SPAN( span ) { \ - GLuint i; \ - PIXEL_TYPE *pixel = pRow; \ - for (i = 0; i < span.end; i++, pixel++) { \ - pixel->r = color[RCOMP]; \ - pixel->g = color[GCOMP]; \ - pixel->b = color[BCOMP]; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, NON-depth-buffered, PF_TRUEDITHER triangle. - */ -#define NAME flat_TRUEDITHER_triangle -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); \ - XMesaImage *img = xrb->ximage; -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - unsigned long p; \ - PACK_TRUEDITHER(p, x, y, v2->color[0], \ - v2->color[1], v2->color[2] ); \ - XMesaPutPixel(img, x, y, p); \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, NON-depth-buffered, PF_5R6G5B triangle. - */ -#define NAME flat_5R6G5B_triangle -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - GET_XRB(xrb); \ - unsigned long p = PACK_5R6G5B( v2->color[0], \ - v2->color[1], v2->color[2] ); -#define RENDER_SPAN( span ) { \ - GLuint i; \ - for (i = 0; i < span.end; i++) { \ - pRow[i] = (PIXEL_TYPE) p; \ - } } -#include "swrast/s_tritemp.h" - - - -/* - * XImage, flat, NON-depth-buffered, PF_DITHER_5R6G5B triangle. - */ -#define NAME flat_DITHER_5R6G5B_triangle -#define PIXEL_ADDRESS(X,Y) PIXEL_ADDR2(xrb, X, Y) -#define PIXEL_TYPE GLushort -#define BYTES_PER_ROW (xrb->ximage->bytes_per_line) -#define SETUP_CODE \ - XMesaContext xmesa = XMESA_CONTEXT(ctx); \ - GET_XRB(xrb); \ - const GLubyte *color = v2->color; -#define RENDER_SPAN( span ) { \ - GLuint i; \ - GLint x = span.x, y = YFLIP(xrb, span.y); \ - for (i = 0; i < span.end; i++, x++) { \ - PACK_TRUEDITHER(pRow[i], x, y, color[RCOMP], \ - color[GCOMP], color[BCOMP]); \ - } } -#include "swrast/s_tritemp.h" - - - -#endif /* CHAN_BITS == 8 */ - - -#if defined(DEBUG) && CHAN_BITS == 8 -extern void _xmesa_print_triangle_func( swrast_tri_func triFunc ); -void _xmesa_print_triangle_func( swrast_tri_func triFunc ) -{ - printf("XMesa tri func = "); - if (triFunc ==smooth_TRUECOLOR_z_triangle) - printf("smooth_TRUECOLOR_z_triangle\n"); - else if (triFunc ==smooth_8A8B8G8R_z_triangle) - printf("smooth_8A8B8G8R_z_triangle\n"); - else if (triFunc ==smooth_8A8R8G8B_z_triangle) - printf("smooth_8A8R8G8B_z_triangle\n"); - else if (triFunc ==smooth_8R8G8B_z_triangle) - printf("smooth_8R8G8B_z_triangle\n"); - else if (triFunc ==smooth_8R8G8B24_z_triangle) - printf("smooth_8R8G8B24_z_triangle\n"); - else if (triFunc ==smooth_TRUEDITHER_z_triangle) - printf("smooth_TRUEDITHER_z_triangle\n"); - else if (triFunc ==smooth_5R6G5B_z_triangle) - printf("smooth_5R6G5B_z_triangle\n"); - else if (triFunc ==smooth_DITHER_5R6G5B_z_triangle) - printf("smooth_DITHER_5R6G5B_z_triangle\n"); - else if (triFunc ==flat_TRUECOLOR_z_triangle) - printf("flat_TRUECOLOR_z_triangle\n"); - else if (triFunc ==flat_8A8B8G8R_z_triangle) - printf("flat_8A8B8G8R_z_triangle\n"); - else if (triFunc ==flat_8A8R8G8B_z_triangle) - printf("flat_8A8R8G8B_z_triangle\n"); - else if (triFunc ==flat_8R8G8B_z_triangle) - printf("flat_8R8G8B_z_triangle\n"); - else if (triFunc ==flat_8R8G8B24_z_triangle) - printf("flat_8R8G8B24_z_triangle\n"); - else if (triFunc ==flat_TRUEDITHER_z_triangle) - printf("flat_TRUEDITHER_z_triangle\n"); - else if (triFunc ==flat_5R6G5B_z_triangle) - printf("flat_5R6G5B_z_triangle\n"); - else if (triFunc ==flat_DITHER_5R6G5B_z_triangle) - printf("flat_DITHER_5R6G5B_z_triangle\n"); - else if (triFunc ==smooth_TRUECOLOR_triangle) - printf("smooth_TRUECOLOR_triangle\n"); - else if (triFunc ==smooth_8A8B8G8R_triangle) - printf("smooth_8A8B8G8R_triangle\n"); - else if (triFunc ==smooth_8A8R8G8B_triangle) - printf("smooth_8A8R8G8B_triangle\n"); - else if (triFunc ==smooth_8R8G8B_triangle) - printf("smooth_8R8G8B_triangle\n"); - else if (triFunc ==smooth_8R8G8B24_triangle) - printf("smooth_8R8G8B24_triangle\n"); - else if (triFunc ==smooth_TRUEDITHER_triangle) - printf("smooth_TRUEDITHER_triangle\n"); - else if (triFunc ==smooth_5R6G5B_triangle) - printf("smooth_5R6G5B_triangle\n"); - else if (triFunc ==smooth_DITHER_5R6G5B_triangle) - printf("smooth_DITHER_5R6G5B_triangle\n"); - else if (triFunc ==flat_TRUECOLOR_triangle) - printf("flat_TRUECOLOR_triangle\n"); - else if (triFunc ==flat_TRUEDITHER_triangle) - printf("flat_TRUEDITHER_triangle\n"); - else if (triFunc ==flat_8A8B8G8R_triangle) - printf("flat_8A8B8G8R_triangle\n"); - else if (triFunc ==flat_8A8R8G8B_triangle) - printf("flat_8A8R8G8B_triangle\n"); - else if (triFunc ==flat_8R8G8B_triangle) - printf("flat_8R8G8B_triangle\n"); - else if (triFunc ==flat_8R8G8B24_triangle) - printf("flat_8R8G8B24_triangle\n"); - else if (triFunc ==flat_5R6G5B_triangle) - printf("flat_5R6G5B_triangle\n"); - else if (triFunc ==flat_DITHER_5R6G5B_triangle) - printf("flat_DITHER_5R6G5B_triangle\n"); - else - printf("???\n"); -} -#endif - - -#ifdef DEBUG - -/* record the current triangle function name */ -static const char *triFuncName = NULL; - -#define USE(triFunc) \ -do { \ - triFuncName = #triFunc; \ - return triFunc; \ -} while (0) - -#else - -#define USE(triFunc) return triFunc - -#endif - - -/** - * Return pointer to line drawing function, or NULL if we should use a - * swrast fallback. - */ -static swrast_tri_func -get_triangle_func(struct gl_context *ctx) -{ -#if CHAN_BITS == 8 - SWcontext *swrast = SWRAST_CONTEXT(ctx); - XMesaContext xmesa = XMESA_CONTEXT(ctx); - const struct xmesa_renderbuffer *xrb; - -#ifdef DEBUG - triFuncName = NULL; -#endif - - /* trivial fallback tests */ - if ((ctx->DrawBuffer->_ColorDrawBufferIndexes[0] != BUFFER_BIT_FRONT_LEFT) && - (ctx->DrawBuffer->_ColorDrawBufferIndexes[0] != BUFFER_BIT_BACK_LEFT)) - return (swrast_tri_func) NULL; - if (ctx->RenderMode != GL_RENDER) - return (swrast_tri_func) NULL; - if (ctx->Polygon.SmoothFlag) - return (swrast_tri_func) NULL; - if (ctx->Texture._MaxEnabledTexImageUnit != -1) - return (swrast_tri_func) NULL; - if (swrast->_RasterMask & MULTI_DRAW_BIT) - return (swrast_tri_func) NULL; - if (ctx->Polygon.CullFlag && - ctx->Polygon.CullFaceMode == GL_FRONT_AND_BACK) - return (swrast_tri_func) NULL; - - xrb = xmesa_renderbuffer(ctx->DrawBuffer->_ColorDrawBuffers[0]); - - if (xrb->ximage) { - if ( ctx->Light.ShadeModel==GL_SMOOTH - && swrast->_RasterMask==DEPTH_BIT - && ctx->Depth.Func==GL_LESS - && ctx->Depth.Mask==GL_TRUE - && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS - && ctx->Polygon.StippleFlag==GL_FALSE) { - switch (xmesa->pixelformat) { - case PF_Truecolor: - USE(smooth_TRUECOLOR_z_triangle); - case PF_8A8B8G8R: - USE(smooth_8A8B8G8R_z_triangle); - case PF_8A8R8G8B: - USE(smooth_8A8R8G8B_z_triangle); - case PF_8R8G8B: - USE(smooth_8R8G8B_z_triangle); - case PF_8R8G8B24: - USE(smooth_8R8G8B24_z_triangle); - case PF_Dither_True: - USE(smooth_TRUEDITHER_z_triangle); - case PF_5R6G5B: - USE(smooth_5R6G5B_z_triangle); - case PF_Dither_5R6G5B: - USE(smooth_DITHER_5R6G5B_z_triangle); - default: - return (swrast_tri_func) NULL; - } - } - if ( ctx->Light.ShadeModel==GL_FLAT - && swrast->_RasterMask==DEPTH_BIT - && ctx->Depth.Func==GL_LESS - && ctx->Depth.Mask==GL_TRUE - && ctx->Visual.depthBits == DEFAULT_SOFTWARE_DEPTH_BITS - && ctx->Polygon.StippleFlag==GL_FALSE) { - switch (xmesa->pixelformat) { - case PF_Truecolor: - USE(flat_TRUECOLOR_z_triangle); - case PF_8A8B8G8R: - USE(flat_8A8B8G8R_z_triangle); - case PF_8A8R8G8B: - USE(flat_8A8R8G8B_z_triangle); - case PF_8R8G8B: - USE(flat_8R8G8B_z_triangle); - case PF_8R8G8B24: - USE(flat_8R8G8B24_z_triangle); - case PF_Dither_True: - USE(flat_TRUEDITHER_z_triangle); - case PF_5R6G5B: - USE(flat_5R6G5B_z_triangle); - case PF_Dither_5R6G5B: - USE(flat_DITHER_5R6G5B_z_triangle); - default: - return (swrast_tri_func) NULL; - } - } - if ( swrast->_RasterMask==0 /* no depth test */ - && ctx->Light.ShadeModel==GL_SMOOTH - && ctx->Polygon.StippleFlag==GL_FALSE) { - switch (xmesa->pixelformat) { - case PF_Truecolor: - USE(smooth_TRUECOLOR_triangle); - case PF_8A8B8G8R: - USE(smooth_8A8B8G8R_triangle); - case PF_8A8R8G8B: - USE(smooth_8A8R8G8B_triangle); - case PF_8R8G8B: - USE(smooth_8R8G8B_triangle); - case PF_8R8G8B24: - USE(smooth_8R8G8B24_triangle); - case PF_Dither_True: - USE(smooth_TRUEDITHER_triangle); - case PF_5R6G5B: - USE(smooth_5R6G5B_triangle); - case PF_Dither_5R6G5B: - USE(smooth_DITHER_5R6G5B_triangle); - default: - return (swrast_tri_func) NULL; - } - } - - if ( swrast->_RasterMask==0 /* no depth test */ - && ctx->Light.ShadeModel==GL_FLAT - && ctx->Polygon.StippleFlag==GL_FALSE) { - switch (xmesa->pixelformat) { - case PF_Truecolor: - USE(flat_TRUECOLOR_triangle); - case PF_Dither_True: - USE(flat_TRUEDITHER_triangle); - case PF_8A8B8G8R: - USE(flat_8A8B8G8R_triangle); - case PF_8A8R8G8B: - USE(flat_8A8R8G8B_triangle); - case PF_8R8G8B: - USE(flat_8R8G8B_triangle); - case PF_8R8G8B24: - USE(flat_8R8G8B24_triangle); - case PF_5R6G5B: - USE(flat_5R6G5B_triangle); - case PF_Dither_5R6G5B: - USE(flat_DITHER_5R6G5B_triangle); - default: - return (swrast_tri_func) NULL; - } - } - } -#endif /* CHAN_BITS == 8 */ - - return (swrast_tri_func) NULL; -} - - -/* Override for the swrast tri-selection function. Try to use one - * of our internal tri functions, otherwise fall back to the - * standard swrast functions. - */ -void xmesa_choose_triangle( struct gl_context *ctx ) -{ - SWcontext *swrast = SWRAST_CONTEXT(ctx); - - if (!(swrast->Triangle = get_triangle_func( ctx ))) - _swrast_choose_triangle( ctx ); -} - diff --git a/src/mesa/drivers/x11/xmesa.h b/src/mesa/drivers/x11/xmesa.h deleted file mode 100644 index 562b9f38cde..00000000000 --- a/src/mesa/drivers/x11/xmesa.h +++ /dev/null @@ -1,381 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -/* - * Mesa/X11 interface. This header file serves as the documentation for - * the Mesa/X11 interface functions. - * - * Note: this interface isn't intended for user programs. It's primarily - * just for implementing the pseudo-GLX interface. - */ - - -/* Sample Usage: - -In addition to the usual X calls to select a visual, create a colormap -and create a window, you must do the following to use the X/Mesa interface: - -1. Call XMesaCreateVisual() to make an XMesaVisual from an XVisualInfo. - -2. Call XMesaCreateContext() to create an X/Mesa rendering context, given - the XMesaVisual. - -3. Call XMesaCreateWindowBuffer() to create an XMesaBuffer from an X window - and XMesaVisual. - -4. Call XMesaMakeCurrent() to bind the XMesaBuffer to an XMesaContext and - to make the context the current one. - -5. Make gl* calls to render your graphics. - -6. Use XMesaSwapBuffers() when double buffering to swap front/back buffers. - -7. Before the X window is destroyed, call XMesaDestroyBuffer(). - -8. Before exiting, call XMesaDestroyVisual and XMesaDestroyContext. - -*/ - - - - -#ifndef XMESA_H -#define XMESA_H - -#include -#include -#include "xmesa_x.h" -#include "GL/gl.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define XMESA_MAJOR_VERSION 6 -#define XMESA_MINOR_VERSION 3 - - - -/* - * Values passed to XMesaGetString: - */ -#define XMESA_VERSION 1 -#define XMESA_EXTENSIONS 2 - - -typedef struct xmesa_context *XMesaContext; - -typedef struct xmesa_visual *XMesaVisual; - -typedef struct xmesa_buffer *XMesaBuffer; - - - -/* - * Create a new X/Mesa visual. - * Input: display - X11 display - * visinfo - an XVisualInfo pointer - * rgb_flag - GL_TRUE = RGB mode, - * GL_FALSE = color index mode - * alpha_flag - alpha buffer requested? - * db_flag - GL_TRUE = double-buffered, - * GL_FALSE = single buffered - * stereo_flag - stereo visual? - * ximage_flag - GL_TRUE = use an XImage for back buffer, - * GL_FALSE = use an off-screen pixmap for back buffer - * depth_size - requested bits/depth values, or zero - * stencil_size - requested bits/stencil values, or zero - * accum_red_size - requested bits/red accum values, or zero - * accum_green_size - requested bits/green accum values, or zero - * accum_blue_size - requested bits/blue accum values, or zero - * accum_alpha_size - requested bits/alpha accum values, or zero - * num_samples - number of samples/pixel if multisampling, or zero - * level - visual level, usually 0 - * visualCaveat - ala the GLX extension, usually GLX_NONE_EXT - * Return; a new XMesaVisual or 0 if error. - */ -extern XMesaVisual XMesaCreateVisual( XMesaDisplay *display, - XMesaVisualInfo visinfo, - GLboolean rgb_flag, - GLboolean alpha_flag, - GLboolean db_flag, - GLboolean stereo_flag, - GLboolean ximage_flag, - GLint depth_size, - GLint stencil_size, - GLint accum_red_size, - GLint accum_green_size, - GLint accum_blue_size, - GLint accum_alpha_size, - GLint num_samples, - GLint level, - GLint visualCaveat ); - -/* - * Destroy an XMesaVisual, but not the associated XVisualInfo. - */ -extern void XMesaDestroyVisual( XMesaVisual v ); - - - -/* - * Create a new XMesaContext for rendering into an X11 window. - * - * Input: visual - an XMesaVisual - * share_list - another XMesaContext with which to share display - * lists or NULL if no sharing is wanted. - * Return: an XMesaContext or NULL if error. - */ -extern XMesaContext XMesaCreateContext( XMesaVisual v, - XMesaContext share_list ); - - -/* - * Destroy a rendering context as returned by XMesaCreateContext() - */ -extern void XMesaDestroyContext( XMesaContext c ); - - - - -/* - * Create an XMesaBuffer from an X window. - */ -extern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, XMesaWindow w ); - - -/* - * Create an XMesaBuffer from an X pixmap. - */ -extern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v, - XMesaPixmap p, - XMesaColormap cmap ); - - -/* - * Destroy an XMesaBuffer, but not the corresponding window or pixmap. - */ -extern void XMesaDestroyBuffer( XMesaBuffer b ); - - -/* - * Return the XMesaBuffer handle which corresponds to an X drawable, if any. - * - * New in Mesa 2.3. - */ -extern XMesaBuffer XMesaFindBuffer( XMesaDisplay *dpy, - XMesaDrawable d ); - - - -/* - * Bind a buffer to a context and make the context the current one. - */ -extern GLboolean XMesaMakeCurrent( XMesaContext c, - XMesaBuffer b ); - - -/* - * Bind two buffers (read and draw) to a context and make the - * context the current one. - * New in Mesa 3.3 - */ -extern GLboolean XMesaMakeCurrent2( XMesaContext c, - XMesaBuffer drawBuffer, - XMesaBuffer readBuffer ); - - -/* - * Unbind the current context from its buffer. - */ -extern GLboolean XMesaUnbindContext( XMesaContext c ); - - -/* - * Return a handle to the current context. - */ -extern XMesaContext XMesaGetCurrentContext( void ); - - -/* - * Return handle to the current (draw) buffer. - */ -extern XMesaBuffer XMesaGetCurrentBuffer( void ); - - -/* - * Return handle to the current read buffer. - * New in Mesa 3.3 - */ -extern XMesaBuffer XMesaGetCurrentReadBuffer( void ); - - -/* - * Return display of current context. - */ -extern Display *XMesaGetCurrentDisplay( void ); - - -/* - * Swap the front and back buffers for the given buffer. No action is - * taken if the buffer is not double buffered. - */ -extern void XMesaSwapBuffers( XMesaBuffer b ); - - -/* - * Copy a sub-region of the back buffer to the front buffer. - * - * New in Mesa 2.6 - */ -extern void XMesaCopySubBuffer( XMesaBuffer b, - int x, - int y, - int width, - int height ); - - -/* - * Return a pointer to the Pixmap or XImage being used as the back - * color buffer of an XMesaBuffer. This function is a way to get "under - * the hood" of X/Mesa so one can manipulate the back buffer directly. - * Input: b - the XMesaBuffer - * Output: pixmap - pointer to back buffer's Pixmap, or 0 - * ximage - pointer to back buffer's XImage, or NULL - * Return: GL_TRUE = context is double buffered - * GL_FALSE = context is single buffered - */ -extern GLboolean XMesaGetBackBuffer( XMesaBuffer b, - XMesaPixmap *pixmap, - XMesaImage **ximage ); - - - -/* - * Return the depth buffer associated with an XMesaBuffer. - * Input: b - the XMesa buffer handle - * Output: width, height - size of buffer in pixels - * bytesPerValue - bytes per depth value (2 or 4) - * buffer - pointer to depth buffer values - * Return: GL_TRUE or GL_FALSE to indicate success or failure. - * - * New in Mesa 2.4. - */ -extern GLboolean XMesaGetDepthBuffer( XMesaBuffer b, - GLint *width, - GLint *height, - GLint *bytesPerValue, - void **buffer ); - - - -/* - * Flush/sync a context - */ -extern void XMesaFlush( XMesaContext c ); - - - -/* - * Get an X/Mesa-specific string. - * Input: name - either XMESA_VERSION or XMESA_EXTENSIONS - */ -extern const char *XMesaGetString( XMesaContext c, int name ); - - - -/* - * Scan for XMesaBuffers whose window/pixmap has been destroyed, then free - * any memory used by that buffer. - * - * New in Mesa 2.3. - */ -extern void XMesaGarbageCollect( XMesaDisplay* dpy ); - - - -/* - * Return a dithered pixel value. - * Input: c - XMesaContext - * x, y - window coordinate - * red, green, blue, alpha - color components in [0,1] - * Return: pixel value - * - * New in Mesa 2.3. - */ -extern unsigned long XMesaDitherColor( XMesaContext xmesa, - GLint x, - GLint y, - GLfloat red, - GLfloat green, - GLfloat blue, - GLfloat alpha ); - - - -/* - * Reallocate the back/depth/stencil/accum/etc/ buffers associated with - * buffer if its size has changed. - * - * New in Mesa 4.0.2 - */ -extern void XMesaResizeBuffers( XMesaBuffer b ); - - - -/* - * Create a pbuffer. - * New in Mesa 4.1 - */ -extern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, XMesaColormap cmap, - unsigned int width, unsigned int height); - - - -/* - * Texture from Pixmap - * New in Mesa 7.1 - */ -extern void -XMesaBindTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer, - const int *attrib_list); - -extern void -XMesaReleaseTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer); - - -extern XMesaBuffer -XMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p, - XMesaColormap cmap, - int format, int target, int mipmap); - - - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/src/mesa/drivers/x11/xmesaP.h b/src/mesa/drivers/x11/xmesaP.h deleted file mode 100644 index 97f15aba9b3..00000000000 --- a/src/mesa/drivers/x11/xmesaP.h +++ /dev/null @@ -1,425 +0,0 @@ -/* - * Mesa 3-D graphics library - * - * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included - * in all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR - * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR - * OTHER DEALINGS IN THE SOFTWARE. - */ - - -#ifndef XMESAP_H -#define XMESAP_H - - -#include "c11/threads.h" -#include "xmesa.h" -#include "main/mtypes.h" -#include "swrast/s_context.h" - - -extern mtx_t _xmesa_lock; - -extern XMesaBuffer XMesaBufferList; - -/* for PF_8R8G8B24 pixel format */ -typedef struct { - GLubyte b; - GLubyte g; - GLubyte r; -} bgr_t; - - -struct xmesa_renderbuffer; - - -/* Function pointer for clearing color buffers */ -typedef void (*ClearFunc)( struct gl_context *ctx, struct xmesa_renderbuffer *xrb, - GLint x, GLint y, GLint width, GLint height ); - - - - -/** Framebuffer pixel formats */ -enum pixel_format { - PF_Truecolor, /**< TrueColor or DirectColor, any depth */ - PF_Dither_True, /**< TrueColor with dithering */ - PF_8A8R8G8B, /**< 32-bit TrueColor: 8-A, 8-R, 8-G, 8-B bits */ - PF_8A8B8G8R, /**< 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R bits */ - PF_8R8G8B, /**< 32-bit TrueColor: 8-R, 8-G, 8-B bits */ - PF_8R8G8B24, /**< 24-bit TrueColor: 8-R, 8-G, 8-B bits */ - PF_5R6G5B, /**< 16-bit TrueColor: 5-R, 6-G, 5-B bits */ - PF_Dither_5R6G5B /**< 16-bit dithered TrueColor: 5-R, 6-G, 5-B */ -}; - - -/** - * Visual inforation, derived from struct gl_config. - * Basically corresponds to an XVisualInfo. - */ -struct xmesa_visual { - struct gl_config mesa_visual; /* Device independent visual parameters */ - XMesaDisplay *display; /* The X11 display */ - int screen, visualID; - int visualType; - XMesaVisualInfo visinfo; /* X's visual info (pointer to private copy) */ - GLint BitsPerPixel; /* True bits per pixel for XImages */ - - GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */ - - enum pixel_format dithered_pf; /* Pixel format when dithering */ - enum pixel_format undithered_pf;/* Pixel format when not dithering */ - - GLfloat RedGamma; /* Gamma values, 1.0 is default */ - GLfloat GreenGamma; - GLfloat BlueGamma; - - /* For PF_TRUECOLOR */ - GLint rshift, gshift, bshift;/* Pixel color component shifts */ - GLubyte Kernel[16]; /* Dither kernel */ - unsigned long RtoPixel[512]; /* RGB to pixel conversion */ - unsigned long GtoPixel[512]; - unsigned long BtoPixel[512]; - GLubyte PixelToR[256]; /* Pixel to RGB conversion */ - GLubyte PixelToG[256]; - GLubyte PixelToB[256]; -}; - - -/** - * Context info, derived from struct gl_context. - * Basically corresponds to a GLXContext. - */ -struct xmesa_context { - struct gl_context mesa; /* the core library context (containment) */ - XMesaVisual xm_visual; /* Describes the buffers */ - XMesaBuffer xm_buffer; /* current span/point/line/triangle buffer */ - - XMesaDisplay *display; /* == xm_visual->display */ - GLboolean swapbytes; /* Host byte order != display byte order? */ - GLboolean direct; /* Direct rendering context? */ - - enum pixel_format pixelformat; - - GLubyte clearcolor[4]; /* current clearing color */ - unsigned long clearpixel; /* current clearing pixel value */ -}; - - -/** - * Types of X/GLX drawables we might render into. - */ -typedef enum { - WINDOW, /* An X window */ - GLXWINDOW, /* GLX window */ - PIXMAP, /* GLX pixmap */ - PBUFFER /* GLX Pbuffer */ -} BufferType; - - -/** Values for db_mode: */ -/*@{*/ -#define BACK_PIXMAP 1 -#define BACK_XIMAGE 2 -/*@}*/ - - -/** - * An xmesa_renderbuffer represents the back or front color buffer. - * For the front color buffer: - * is the X window - * For the back color buffer: - * Either or will be used, never both. - * In any case, always equals . - * For stand-alone Mesa, we could merge and into one - * field. We don't do that for the server-side GLcore module because - * pixmaps and drawables are different and we'd need a bunch of casts. - */ -struct xmesa_renderbuffer -{ - struct swrast_renderbuffer Base; /* Base class */ - - XMesaBuffer Parent; /**< The XMesaBuffer this renderbuffer belongs to */ - XMesaDrawable drawable; /* Usually the X window ID */ - XMesaPixmap pixmap; /* Back color buffer */ - XMesaImage *ximage; /* The back buffer, if not using a Pixmap */ - - GLushort *origin2; /* used for PIXEL_ADDR2 macro */ - GLint width2; - GLubyte *origin3; /* used for PIXEL_ADDR3 macro */ - GLint width3; - GLuint *origin4; /* used for PIXEL_ADDR4 macro */ - GLint width4; - - GLint bottom; /* used for FLIP macro, equals height - 1 */ - - ClearFunc clearFunc; - - GLuint map_x, map_y, map_w, map_h; - GLbitfield map_mode; - XMesaImage *map_ximage; -}; - - -/** - * Framebuffer information, derived from. - * Basically corresponds to a GLXDrawable. - */ -struct xmesa_buffer { - struct gl_framebuffer mesa_buffer; /* depth, stencil, accum, etc buffers */ - /* This MUST BE FIRST! */ - GLboolean wasCurrent; /* was ever the current buffer? */ - XMesaVisual xm_visual; /* the X/Mesa visual */ - - XMesaDisplay *display; - BufferType type; /* window, pixmap, pbuffer or glxwindow */ - - GLboolean largestPbuffer; /**< for pbuffers */ - GLboolean preservedContents; /**< for pbuffers */ - - struct xmesa_renderbuffer *frontxrb; /* front color renderbuffer */ - struct xmesa_renderbuffer *backxrb; /* back color renderbuffer */ - - XMesaColormap cmap; /* the X colormap */ - - unsigned long selectedEvents;/* for pbuffers only */ - - GLint db_mode; /* 0 = single buffered */ - /* BACK_PIXMAP = use Pixmap for back buffer */ - /* BACK_XIMAGE = use XImage for back buffer */ - GLuint shm; /* X Shared Memory extension status: */ - /* 0 = not available */ - /* 1 = XImage support available */ - /* 2 = Pixmap support available too */ -#if defined(USE_XSHM) - XShmSegmentInfo shminfo; -#endif - - // XMesaImage *rowimage; /* Used for optimized span writing */ - XMesaPixmap stipple_pixmap; /* For polygon stippling */ - XMesaGC stipple_gc; /* For polygon stippling */ - - XMesaGC gc; /* scratch GC for span, line, tri drawing */ - XMesaGC cleargc; /* GC for clearing the color buffer */ - XMesaGC swapgc; /* GC for swapping the color buffers */ - - /* The following are here instead of in the XMesaVisual - * because they depend on the window's colormap. - */ - - /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */ - unsigned long color_table[576]; /* RGB -> pixel value */ - - /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */ - GLubyte pixel_to_r[65536]; /* pixel value -> red */ - GLubyte pixel_to_g[65536]; /* pixel value -> green */ - GLubyte pixel_to_b[65536]; /* pixel value -> blue */ - - /* Used to do XAllocColor/XFreeColors accounting: */ - int num_alloced; - unsigned long alloced_colors[256]; - - /* GLX_EXT_texture_from_pixmap */ - GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */ - GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */ - GLint TextureMipmap; /** 0 or 1 */ - - struct xmesa_buffer *Next; /* Linked list pointer: */ -}; - - -/** - * If pixelformat==PF_TRUECOLOR: - */ -#define PACK_TRUECOLOR( PIXEL, R, G, B ) \ - PIXEL = xmesa->xm_visual->RtoPixel[R] \ - | xmesa->xm_visual->GtoPixel[G] \ - | xmesa->xm_visual->BtoPixel[B]; - - -/** - * If pixelformat==PF_TRUEDITHER: - */ -#define PACK_TRUEDITHER( PIXEL, X, Y, R, G, B ) \ -{ \ - int d = xmesa->xm_visual->Kernel[((X)&3) | (((Y)&3)<<2)]; \ - PIXEL = xmesa->xm_visual->RtoPixel[(R)+d] \ - | xmesa->xm_visual->GtoPixel[(G)+d] \ - | xmesa->xm_visual->BtoPixel[(B)+d]; \ -} - - - -/** - * If pixelformat==PF_8A8B8G8R: - */ -#define PACK_8A8B8G8R( R, G, B, A ) \ - ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) ) - - -/** - * Like PACK_8A8B8G8R() but don't use alpha. This is usually an acceptable - * shortcut. - */ -#define PACK_8B8G8R( R, G, B ) ( ((B) << 16) | ((G) << 8) | (R) ) - - - -/** - * If pixelformat==PF_8R8G8B: - */ -#define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) ) - - -/** - * If pixelformat==PF_5R6G5B: - */ -#define PACK_5R6G5B( R, G, B) ( (((R) & 0xf8) << 8) | (((G) & 0xfc) << 3) | ((B) >> 3) ) - - -/** - * If pixelformat==PF_8A8R8G8B: - */ -#define PACK_8A8R8G8B( R, G, B, A ) \ - ( ((A) << 24) | ((R) << 16) | ((G) << 8) | (B) ) - - - - -/** - * Converts a GL window Y coord to an X window Y coord: - */ -#define YFLIP(XRB, Y) ((XRB)->bottom - (Y)) - - -/** - * Return the address of a 2, 3 or 4-byte pixel in the buffer's XImage: - * X==0 is left, Y==0 is bottom. - */ -#define PIXEL_ADDR2(XRB, X, Y) \ - ( (XRB)->origin2 - (Y) * (XRB)->width2 + (X) ) - -#define PIXEL_ADDR3(XRB, X, Y) \ - ( (bgr_t *) ( (XRB)->origin3 - (Y) * (XRB)->width3 + 3 * (X) )) - -#define PIXEL_ADDR4(XRB, X, Y) \ - ( (XRB)->origin4 - (Y) * (XRB)->width4 + (X) ) - - - -/* - * External functions: - */ - -extern struct xmesa_renderbuffer * -xmesa_new_renderbuffer(struct gl_context *ctx, GLuint name, - const struct xmesa_visual *xmvis, - GLboolean backBuffer); - -extern void -xmesa_delete_framebuffer(struct gl_framebuffer *fb); - -extern XMesaBuffer -xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis); - -extern unsigned long -xmesa_color_to_pixel( struct gl_context *ctx, - GLubyte r, GLubyte g, GLubyte b, GLubyte a, - GLuint pixelFormat ); - -extern void -xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b, - GLuint *width, GLuint *height); - -extern void -xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer); - -extern void -xmesa_init_driver_functions( XMesaVisual xmvisual, - struct dd_function_table *driver ); - -extern void -xmesa_MapRenderbuffer(struct gl_context *ctx, - struct gl_renderbuffer *rb, - GLuint x, GLuint y, GLuint w, GLuint h, - GLbitfield mode, - GLubyte **mapOut, GLint *rowStrideOut, - bool flip_y); - -extern void -xmesa_UnmapRenderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb); - -extern void -xmesa_destroy_buffers_on_display(XMesaDisplay *dpy); - - -/** - * Using a function instead of an ordinary cast is safer. - */ -static inline struct xmesa_renderbuffer * -xmesa_renderbuffer(struct gl_renderbuffer *rb) -{ - return (struct xmesa_renderbuffer *) rb; -} - - -/** - * Return pointer to XMesaContext corresponding to a Mesa struct gl_context. - * Since we're using structure containment, it's just a cast!. - */ -static inline XMesaContext -XMESA_CONTEXT(struct gl_context *ctx) -{ - return (XMesaContext) ctx; -} - - -/** - * Return pointer to XMesaBuffer corresponding to a Mesa struct gl_framebuffer. - * Since we're using structure containment, it's just a cast!. - */ -static inline XMesaBuffer -XMESA_BUFFER(struct gl_framebuffer *b) -{ - return (XMesaBuffer) b; -} - - -/* Plugged into the software rasterizer. Try to use internal - * swrast-style point, line and triangle functions. - */ -extern void xmesa_choose_point( struct gl_context *ctx ); -extern void xmesa_choose_line( struct gl_context *ctx ); -extern void xmesa_choose_triangle( struct gl_context *ctx ); - - -extern void xmesa_register_swrast_functions( struct gl_context *ctx ); - - - -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L -#define ENABLE_EXT_timer_query 1 /* should have 64-bit GLuint64EXT */ -#else -#define ENABLE_EXT_timer_query 0 /* may not have 64-bit GLuint64EXT */ -#endif - - -#define TEST_META_FUNCS 0 - - -#endif diff --git a/src/mesa/drivers/x11/xmesa_x.h b/src/mesa/drivers/x11/xmesa_x.h deleted file mode 100644 index f557cbb3016..00000000000 --- a/src/mesa/drivers/x11/xmesa_x.h +++ /dev/null @@ -1,85 +0,0 @@ - -/************************************************************************** - -Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas. -All Rights Reserved. - -Permission is hereby granted, free of charge, to any person obtaining a -copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sub license, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice (including the -next paragraph) shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS -OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. -IN NO EVENT SHALL PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR -ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -**************************************************************************/ - -/* - * Authors: - * Kevin E. Martin - * - * When we're building the XMesa driver for stand-alone Mesa we - * include this file when building the xm_*.c files. - * We need to define some types and macros differently when building - * in the Xserver vs. stand-alone Mesa. - */ - -#ifndef _XMESA_X_H_ -#define _XMESA_X_H_ - -typedef Display XMesaDisplay; -typedef Pixmap XMesaPixmap; -typedef Colormap XMesaColormap; -typedef Drawable XMesaDrawable; -typedef Window XMesaWindow; -typedef GC XMesaGC; -typedef XVisualInfo *XMesaVisualInfo; -typedef XImage XMesaImage; -typedef XPoint XMesaPoint; -typedef XColor XMesaColor; - -#define XMesaDestroyImage XDestroyImage - -#define XMesaPutPixel XPutPixel -#define XMesaGetPixel XGetPixel - -#define XMesaSetForeground XSetForeground -#define XMesaSetBackground XSetBackground -#define XMesaSetPlaneMask XSetPlaneMask -#define XMesaSetFunction XSetFunction -#define XMesaSetFillStyle XSetFillStyle -#define XMesaSetTile XSetTile - -#define XMesaDrawPoint XDrawPoint -#define XMesaDrawPoints XDrawPoints -#define XMesaDrawLine XDrawLine -#define XMesaFillRectangle XFillRectangle -#define XMesaGetImage XGetImage -#define XMesaPutImage XPutImage -#define XMesaCopyArea XCopyArea - -#define XMesaCreatePixmap XCreatePixmap -#define XMesaFreePixmap XFreePixmap -#define XMesaFreeGC XFreeGC - -#define GET_COLORMAP_SIZE(__v) __v->visinfo->colormap_size -#define GET_REDMASK(__v) __v->mesa_visual.redMask -#define GET_GREENMASK(__v) __v->mesa_visual.greenMask -#define GET_BLUEMASK(__v) __v->mesa_visual.blueMask -#define GET_VISUAL_DEPTH(__v) __v->visinfo->depth -#define GET_BLACK_PIXEL(__v) BlackPixel(__v->display, __v->screen) -#define CHECK_BYTE_ORDER(__v) host_byte_order()==ImageByteOrder(__v->display) - -#endif diff --git a/src/mesa/meson.build b/src/mesa/meson.build index 4cdf0f41f1e..ef1de6b41e4 100644 --- a/src/mesa/meson.build +++ b/src/mesa/meson.build @@ -758,9 +758,6 @@ libmesa_gallium = static_library( ) subdir('drivers/dri') -if with_glx == 'xlib' - subdir('drivers/x11') -endif if with_tests subdir('main/tests') endif