1ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/* 2ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Mesa 3-D graphics library 3ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Version: 7.1 4ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 5ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 6ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 7ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Permission is hereby granted, free of charge, to any person obtaining a 8ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * copy of this software and associated documentation files (the "Software"), 9ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * to deal in the Software without restriction, including without limitation 10ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * and/or sell copies of the Software, and to permit persons to whom the 12ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Software is furnished to do so, subject to the following conditions: 13ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 14ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * The above copyright notice and this permission notice shall be included 15ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * in all copies or substantial portions of the Software. 16ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 17ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 24ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 25ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 26ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \file xm_api.c 27ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 28ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * All the XMesa* API functions. 29ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 30ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 31ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * NOTES: 32ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 33ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * The window coordinate system origin (0,0) is in the lower-left corner 34ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * of the window. X11's window coordinate origin is in the upper-left 35ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * corner of the window. Therefore, most drawing functions in this 36ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * file have to flip Y coordinates. 37ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 38ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 39ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Byte swapping: If the Mesa host and the X display use a different 40ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * byte order then there's some trickiness to be aware of when using 41ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * XImages. The byte ordering used for the XImage is that of the X 42ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * display, not the Mesa host. 43ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * The color-to-pixel encoding for True/DirectColor must be done 44ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * according to the display's visual red_mask, green_mask, and blue_mask. 45ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * If XPutPixel is used to put a pixel into an XImage then XPutPixel will 46ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * do byte swapping if needed. If one wants to directly "poke" the pixel 47749d723287df348bd36ee43f96de6892a3eba09fBrian * into the XImage's buffer then the pixel must be byte swapped first. 48ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 49ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 50ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 51ef25c496d52f4f6c45816b64b4c0999321476cd7Brian#ifdef __CYGWIN__ 52ef25c496d52f4f6c45816b64b4c0999321476cd7Brian#undef WIN32 53ef25c496d52f4f6c45816b64b4c0999321476cd7Brian#undef __WIN32__ 54ef25c496d52f4f6c45816b64b4c0999321476cd7Brian#endif 55ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 5625deb852f84ad0e4519a2a3fb7abc1d098ad3f8eKeith Whitwell#include "xm_api.h" 57576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu#include "xm_st.h" 58ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 5900ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin#include "pipe/p_context.h" 60ef25c496d52f4f6c45816b64b4c0999321476cd7Brian#include "pipe/p_defines.h" 61969ff9e9bf3dfae08d087bbc47ce43f17d107bfcJosé Fonseca#include "pipe/p_screen.h" 6200ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin#include "pipe/p_state.h" 6300ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 645d2fad5444ebe0e2a66c49bd6254e2bc81618f6eThomas Hellstrom#include "util/u_atomic.h" 6500ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin#include "util/u_inlines.h" 66ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 67d0aea650320fec0b8e01110eeee22b1f3700d587Keith Whitwell#include "xm_public.h" 6805f8e41b9567695e9b96276d3ac5734ed2b268a8Keith Whitwell#include <GL/glx.h> 69c474f1fb9088528af998168717783b52e5c2f0a2Zack Rusin 702f19fecd583a4406385708de6362b3bdef23811eKeith Whitwell 712f19fecd583a4406385708de6362b3bdef23811eKeith Whitwell/* Driver interface routines, set up by xlib backend on library 722f19fecd583a4406385708de6362b3bdef23811eKeith Whitwell * _init(). These are global in the same way that function names are 732f19fecd583a4406385708de6362b3bdef23811eKeith Whitwell * global. 742f19fecd583a4406385708de6362b3bdef23811eKeith Whitwell */ 752f19fecd583a4406385708de6362b3bdef23811eKeith Whitwellstatic struct xm_driver driver; 766632915e957149c153a3f793c400a532b4995b18Chia-I Wustatic struct st_api *stapi; 772f19fecd583a4406385708de6362b3bdef23811eKeith Whitwell 7842719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell/* Default strict invalidate to false. This means we will not call 7942719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * XGetGeometry after every swapbuffers, which allows swapbuffers to 8042719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * remain asynchronous. For apps running at 100fps with synchronous 8142719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * swapping, a 10% boost is typical. For gears, I see closer to 20% 8242719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * speedup. 8342719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * 8442719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * Note that the work of copying data on swapbuffers doesn't disappear 8542719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * - this change just allows the X server to execute the PutImage 8642719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * asynchronously without us effectively blocked until its completion. 8742719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * 8842719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * This speeds up even llvmpipe's threaded rasterization as the 8942719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * swapbuffers operation was a large part of the serial component of 9042719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * an llvmpipe frame. 9142719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * 9242719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * The downside of this is correctness - applications which don't call 9342719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * glViewport on window resizes will get incorrect rendering. A 9442719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * better solution would be to have per-frame but asynchronous 9542719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * invalidation. Xcb almost looks as if it could provide this, but 9642719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell * the API doesn't seem to quite be there. 9742719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell */ 9842719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwellboolean xmesa_strict_invalidate = FALSE; 9942719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell 1002f19fecd583a4406385708de6362b3bdef23811eKeith Whitwellvoid xmesa_set_driver( const struct xm_driver *templ ) 1012f19fecd583a4406385708de6362b3bdef23811eKeith Whitwell{ 1022f19fecd583a4406385708de6362b3bdef23811eKeith Whitwell driver = *templ; 1036632915e957149c153a3f793c400a532b4995b18Chia-I Wu stapi = driver.create_st_api(); 10442719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell 10542719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell xmesa_strict_invalidate = 10642719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell debug_get_bool_option("XMESA_STRICT_INVALIDATE", FALSE); 1072f19fecd583a4406385708de6362b3bdef23811eKeith Whitwell} 1082f19fecd583a4406385708de6362b3bdef23811eKeith Whitwell 1098ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul 1108ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul/* 1118ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul * XXX replace this with a linked list, or better yet, try to attach the 1128ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul * gallium/mesa extra bits to the X Display object with XAddExtension(). 1138ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul */ 1148ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul#define MAX_DISPLAYS 10 1158ba47561dd45e1cd737992544545d7fa0f61918bBrian Paulstatic struct xmesa_display Displays[MAX_DISPLAYS]; 1168ba47561dd45e1cd737992544545d7fa0f61918bBrian Paulstatic int NumDisplays = 0; 1178ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul 1185f66363f8ed26d6f3fc8fcccde804fe1fea1bbaaJakob Bornecrantzstatic int 1195f66363f8ed26d6f3fc8fcccde804fe1fea1bbaaJakob Bornecrantzxmesa_get_param(struct st_manager *smapi, 12083adf8c3a4fd75b7877e1894f6f32a04a4d0bf06Brian Paul enum st_manager_param param) 1215f66363f8ed26d6f3fc8fcccde804fe1fea1bbaaJakob Bornecrantz{ 12242719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell switch(param) { 12342719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell case ST_MANAGER_BROKEN_INVALIDATE: 12442719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell return !xmesa_strict_invalidate; 12542719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell default: 12642719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell return 0; 12742719df0b866a00ea4a7739e82e1639c9943fcfdKeith Whitwell } 1285f66363f8ed26d6f3fc8fcccde804fe1fea1bbaaJakob Bornecrantz} 1298ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul 1306632915e957149c153a3f793c400a532b4995b18Chia-I Wustatic XMesaDisplay 1316632915e957149c153a3f793c400a532b4995b18Chia-I Wuxmesa_init_display( Display *display ) 1326632915e957149c153a3f793c400a532b4995b18Chia-I Wu{ 1336632915e957149c153a3f793c400a532b4995b18Chia-I Wu pipe_static_mutex(init_mutex); 1346632915e957149c153a3f793c400a532b4995b18Chia-I Wu XMesaDisplay xmdpy; 1358ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul int i; 1368ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul 1376632915e957149c153a3f793c400a532b4995b18Chia-I Wu pipe_mutex_lock(init_mutex); 1386632915e957149c153a3f793c400a532b4995b18Chia-I Wu 1398ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul /* Look for XMesaDisplay which corresponds to 'display' */ 1408ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul for (i = 0; i < NumDisplays; i++) { 1418ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul if (Displays[i].display == display) { 1428ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul /* Found it */ 1438ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul pipe_mutex_unlock(init_mutex); 1448ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul return &Displays[i]; 1458ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul } 1468ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul } 1478ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul 1488ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul /* Create new XMesaDisplay */ 1498ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul 1508ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul assert(NumDisplays < MAX_DISPLAYS); 1518ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul xmdpy = &Displays[NumDisplays]; 1528ba47561dd45e1cd737992544545d7fa0f61918bBrian Paul NumDisplays++; 1536632915e957149c153a3f793c400a532b4995b18Chia-I Wu 1546632915e957149c153a3f793c400a532b4995b18Chia-I Wu if (!xmdpy->display && display) { 1556632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmdpy->display = display; 1566632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmdpy->screen = driver.create_pipe_screen(display); 1576632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmdpy->smapi = CALLOC_STRUCT(st_manager); 1585f66363f8ed26d6f3fc8fcccde804fe1fea1bbaaJakob Bornecrantz if (xmdpy->smapi) { 1596632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmdpy->smapi->screen = xmdpy->screen; 1605f66363f8ed26d6f3fc8fcccde804fe1fea1bbaaJakob Bornecrantz xmdpy->smapi->get_param = xmesa_get_param; 1615f66363f8ed26d6f3fc8fcccde804fe1fea1bbaaJakob Bornecrantz } 1626632915e957149c153a3f793c400a532b4995b18Chia-I Wu 1636632915e957149c153a3f793c400a532b4995b18Chia-I Wu if (xmdpy->screen && xmdpy->smapi) { 1646632915e957149c153a3f793c400a532b4995b18Chia-I Wu pipe_mutex_init(xmdpy->mutex); 1656632915e957149c153a3f793c400a532b4995b18Chia-I Wu } 1666632915e957149c153a3f793c400a532b4995b18Chia-I Wu else { 1676632915e957149c153a3f793c400a532b4995b18Chia-I Wu if (xmdpy->screen) { 1686632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmdpy->screen->destroy(xmdpy->screen); 1696632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmdpy->screen = NULL; 1706632915e957149c153a3f793c400a532b4995b18Chia-I Wu } 1716632915e957149c153a3f793c400a532b4995b18Chia-I Wu if (xmdpy->smapi) { 1726632915e957149c153a3f793c400a532b4995b18Chia-I Wu FREE(xmdpy->smapi); 1736632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmdpy->smapi = NULL; 1746632915e957149c153a3f793c400a532b4995b18Chia-I Wu } 175ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1766632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmdpy->display = NULL; 1776632915e957149c153a3f793c400a532b4995b18Chia-I Wu } 1786632915e957149c153a3f793c400a532b4995b18Chia-I Wu } 1796632915e957149c153a3f793c400a532b4995b18Chia-I Wu if (!xmdpy->display || xmdpy->display != display) 1806632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmdpy = NULL; 181ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1826632915e957149c153a3f793c400a532b4995b18Chia-I Wu pipe_mutex_unlock(init_mutex); 1836632915e957149c153a3f793c400a532b4995b18Chia-I Wu 1846632915e957149c153a3f793c400a532b4995b18Chia-I Wu return xmdpy; 1856632915e957149c153a3f793c400a532b4995b18Chia-I Wu} 186ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 187ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/**********************************************************************/ 188ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/***** X Utility Functions *****/ 189ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/**********************************************************************/ 190ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 191ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 192ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 193ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Return the host's byte order as LSBFirst or MSBFirst ala X. 194ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 195ef25c496d52f4f6c45816b64b4c0999321476cd7Brianstatic int host_byte_order( void ) 196ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 197ef25c496d52f4f6c45816b64b4c0999321476cd7Brian int i = 1; 198ef25c496d52f4f6c45816b64b4c0999321476cd7Brian char *cptr = (char *) &i; 199ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return (*cptr==1) ? LSBFirst : MSBFirst; 200ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 201ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 202ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 203ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 204ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 205ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 206ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Return the true number of bits per pixel for XImages. 207ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * For example, if we request a 24-bit deep visual we may actually need/get 208ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 32bpp XImages. This function returns the appropriate bpp. 209ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Input: dpy - the X display 210ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * visinfo - desribes the visual to be used for XImages 211ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Return: true number of bits per pixel for XImages 212ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 213ef25c496d52f4f6c45816b64b4c0999321476cd7Brianstatic int 214ef25c496d52f4f6c45816b64b4c0999321476cd7Brianbits_per_pixel( XMesaVisual xmv ) 215ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 216153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell Display *dpy = xmv->display; 217153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell XVisualInfo * visinfo = xmv->visinfo; 218153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell XImage *img; 219ef25c496d52f4f6c45816b64b4c0999321476cd7Brian int bitsPerPixel; 220ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* Create a temporary XImage */ 221ef25c496d52f4f6c45816b64b4c0999321476cd7Brian img = XCreateImage( dpy, visinfo->visual, visinfo->depth, 222ef25c496d52f4f6c45816b64b4c0999321476cd7Brian ZPixmap, 0, /*format, offset*/ 223ef25c496d52f4f6c45816b64b4c0999321476cd7Brian (char*) MALLOC(8), /*data*/ 224ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1, 1, /*width, height*/ 225ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 32, /*bitmap_pad*/ 226ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 0 /*bytes_per_line*/ 227ef25c496d52f4f6c45816b64b4c0999321476cd7Brian ); 228ef25c496d52f4f6c45816b64b4c0999321476cd7Brian assert(img); 229ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* grab the bits/pixel value */ 230ef25c496d52f4f6c45816b64b4c0999321476cd7Brian bitsPerPixel = img->bits_per_pixel; 231ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* free the XImage */ 23232f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free( img->data ); 233ef25c496d52f4f6c45816b64b4c0999321476cd7Brian img->data = NULL; 2342b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell XDestroyImage( img ); 235ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return bitsPerPixel; 236ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 237ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 238ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 239ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 240ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/* 241ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Determine if a given X window ID is valid (window exists). 242ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Do this by calling XGetWindowAttributes() for the window and 243ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * checking if we catch an X error. 244ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Input: dpy - the display 245ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * win - the window to check for existance 246ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Return: GL_TRUE - window exists 247ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * GL_FALSE - window doesn't exist 248ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 249ef25c496d52f4f6c45816b64b4c0999321476cd7Brianstatic GLboolean WindowExistsFlag; 250ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 251153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwellstatic int window_exists_err_handler( Display* dpy, XErrorEvent* xerr ) 252ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 253ef25c496d52f4f6c45816b64b4c0999321476cd7Brian (void) dpy; 254ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (xerr->error_code == BadWindow) { 255ef25c496d52f4f6c45816b64b4c0999321476cd7Brian WindowExistsFlag = GL_FALSE; 256ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 257ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return 0; 258ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 259ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 260153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwellstatic GLboolean window_exists( Display *dpy, Window win ) 261ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 262ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XWindowAttributes wa; 263153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell int (*old_handler)( Display*, XErrorEvent* ); 264ef25c496d52f4f6c45816b64b4c0999321476cd7Brian WindowExistsFlag = GL_TRUE; 265ef25c496d52f4f6c45816b64b4c0999321476cd7Brian old_handler = XSetErrorHandler(window_exists_err_handler); 266ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XGetWindowAttributes( dpy, win, &wa ); /* dummy request */ 267ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XSetErrorHandler(old_handler); 268ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return WindowExistsFlag; 269ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 270ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 271ef25c496d52f4f6c45816b64b4c0999321476cd7Brianstatic Status 272153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwellget_drawable_size( Display *dpy, Drawable d, uint *width, uint *height ) 273ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 274ef25c496d52f4f6c45816b64b4c0999321476cd7Brian Window root; 275ef25c496d52f4f6c45816b64b4c0999321476cd7Brian Status stat; 276ef25c496d52f4f6c45816b64b4c0999321476cd7Brian int xpos, ypos; 277ef25c496d52f4f6c45816b64b4c0999321476cd7Brian unsigned int w, h, bw, depth; 278ef25c496d52f4f6c45816b64b4c0999321476cd7Brian stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth); 279ef25c496d52f4f6c45816b64b4c0999321476cd7Brian *width = w; 280ef25c496d52f4f6c45816b64b4c0999321476cd7Brian *height = h; 281ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return stat; 282ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 283ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 284ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 285ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 286ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Return the size of the window (or pixmap) that corresponds to the 287ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * given XMesaBuffer. 288ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param width returns width in pixels 289ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param height returns height in pixels 290ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 2910526100a5cbd928fa28d38abdafd6beb024b0828Brian Paulvoid 292153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwellxmesa_get_window_size(Display *dpy, XMesaBuffer b, 293ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLuint *width, GLuint *height) 294ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 2956632915e957149c153a3f793c400a532b4995b18Chia-I Wu XMesaDisplay xmdpy = xmesa_init_display(dpy); 296ef25c496d52f4f6c45816b64b4c0999321476cd7Brian Status stat; 297ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 2986632915e957149c153a3f793c400a532b4995b18Chia-I Wu pipe_mutex_lock(xmdpy->mutex); 2991675d05f911fbd569efb5248674aa71cb755c75bKeith Whitwell stat = get_drawable_size(dpy, b->ws.drawable, width, height); 3006632915e957149c153a3f793c400a532b4995b18Chia-I Wu pipe_mutex_unlock(xmdpy->mutex); 301ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 302ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!stat) { 303ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* probably querying a window that's recently been destroyed */ 304ef25c496d52f4f6c45816b64b4c0999321476cd7Brian _mesa_warning(NULL, "XGetGeometry failed!\n"); 305ef25c496d52f4f6c45816b64b4c0999321476cd7Brian *width = *height = 1; 306ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 307ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 308ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 3092b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell#define GET_REDMASK(__v) __v->mesa_visual.redMask 3102b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell#define GET_GREENMASK(__v) __v->mesa_visual.greenMask 3112b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell#define GET_BLUEMASK(__v) __v->mesa_visual.blueMask 3122b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell 313ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 31420eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian/** 31520eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian * Choose the pixel format for the given visual. 31620eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian * This will tell the gallium driver how to pack pixel data into 31720eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian * drawing surfaces. 31820eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian */ 31920eae595faa20dba8a59d8a4bfd01aa6b458cecdBrianstatic GLuint 32020eae595faa20dba8a59d8a4bfd01aa6b458cecdBrianchoose_pixel_format(XMesaVisual v) 32120eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian{ 3222b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell boolean native_byte_order = (host_byte_order() == 3232b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell ImageByteOrder(v->display)); 3242b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell 32520eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian if ( GET_REDMASK(v) == 0x0000ff 32620eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian && GET_GREENMASK(v) == 0x00ff00 32720eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian && GET_BLUEMASK(v) == 0xff0000 32820eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian && v->BitsPerPixel == 32) { 3292b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell if (native_byte_order) { 33020eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian /* no byteswapping needed */ 33188e640fc14c3146966b6ba886d7f79874e745b35José Fonseca return PIPE_FORMAT_R8G8B8A8_UNORM; 33220eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian } 33320eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian else { 33441b80461b77abbd595d7597bea2a2585875e8a74José Fonseca return PIPE_FORMAT_A8B8G8R8_UNORM; 33520eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian } 33620eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian } 33720eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian else if ( GET_REDMASK(v) == 0xff0000 33820eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian && GET_GREENMASK(v) == 0x00ff00 33920eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian && GET_BLUEMASK(v) == 0x0000ff 34020eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian && v->BitsPerPixel == 32) { 3412b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell if (native_byte_order) { 34220eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian /* no byteswapping needed */ 34341b80461b77abbd595d7597bea2a2585875e8a74José Fonseca return PIPE_FORMAT_B8G8R8A8_UNORM; 34420eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian } 34520eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian else { 34641b80461b77abbd595d7597bea2a2585875e8a74José Fonseca return PIPE_FORMAT_A8R8G8B8_UNORM; 34720eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian } 34820eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian } 3499f0495aa765ae53b877b1e7fdffba70f4ee1a056Michel Dänzer else if ( GET_REDMASK(v) == 0x0000ff00 3509f0495aa765ae53b877b1e7fdffba70f4ee1a056Michel Dänzer && GET_GREENMASK(v) == 0x00ff0000 3519f0495aa765ae53b877b1e7fdffba70f4ee1a056Michel Dänzer && GET_BLUEMASK(v) == 0xff000000 3529f0495aa765ae53b877b1e7fdffba70f4ee1a056Michel Dänzer && v->BitsPerPixel == 32) { 3539f0495aa765ae53b877b1e7fdffba70f4ee1a056Michel Dänzer if (native_byte_order) { 3549f0495aa765ae53b877b1e7fdffba70f4ee1a056Michel Dänzer /* no byteswapping needed */ 35541b80461b77abbd595d7597bea2a2585875e8a74José Fonseca return PIPE_FORMAT_A8R8G8B8_UNORM; 3569f0495aa765ae53b877b1e7fdffba70f4ee1a056Michel Dänzer } 3579f0495aa765ae53b877b1e7fdffba70f4ee1a056Michel Dänzer else { 35841b80461b77abbd595d7597bea2a2585875e8a74José Fonseca return PIPE_FORMAT_B8G8R8A8_UNORM; 3599f0495aa765ae53b877b1e7fdffba70f4ee1a056Michel Dänzer } 3609f0495aa765ae53b877b1e7fdffba70f4ee1a056Michel Dänzer } 36120eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian else if ( GET_REDMASK(v) == 0xf800 36220eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian && GET_GREENMASK(v) == 0x07e0 36320eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian && GET_BLUEMASK(v) == 0x001f 3642b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell && native_byte_order 36520eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian && v->BitsPerPixel == 16) { 36620eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian /* 5-6-5 RGB */ 36741b80461b77abbd595d7597bea2a2585875e8a74José Fonseca return PIPE_FORMAT_B5G6R5_UNORM; 36820eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian } 36920eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian 370c1a392ac4c6a7da4026653de556c2c7698f86860Chia-I Wu return PIPE_FORMAT_NONE; 37120eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian} 37220eae595faa20dba8a59d8a4bfd01aa6b458cecdBrian 373ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul 374a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul/** 375ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul * Choose a depth/stencil format that satisfies the given depth and 3763475e88442c16fb2b50b903fe246b3ebe49da226Chia-I Wu * stencil sizes. 377a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul */ 378576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wustatic enum pipe_format 3796632915e957149c153a3f793c400a532b4995b18Chia-I Wuchoose_depth_stencil_format(XMesaDisplay xmdpy, int depth, int stencil) 380a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul{ 381a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul const enum pipe_texture_target target = PIPE_TEXTURE_2D; 382287c94ea4987033f9c99a2f91c5750c9083504caKeith Whitwell const unsigned tex_usage = PIPE_BIND_DEPTH_STENCIL; 383685bb6941681f89f71a9169594d87c8e314b94d0Roland Scheidegger const unsigned sample_count = 0; 384576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu enum pipe_format formats[8], fmt; 385576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu int count, i; 386a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul 387576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu count = 0; 388ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul 389ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul if (depth <= 16 && stencil == 0) { 390ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul formats[count++] = PIPE_FORMAT_Z16_UNORM; 391ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul } 392ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul if (depth <= 24 && stencil == 0) { 393ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul formats[count++] = PIPE_FORMAT_X8Z24_UNORM; 394ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul formats[count++] = PIPE_FORMAT_Z24X8_UNORM; 395ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul } 3963475e88442c16fb2b50b903fe246b3ebe49da226Chia-I Wu if (depth <= 24 && stencil <= 8) { 397866f9b18c68ede63c00917ec9c3dae3524ca8826Dave Airlie formats[count++] = PIPE_FORMAT_S8_UINT_Z24_UNORM; 398866f9b18c68ede63c00917ec9c3dae3524ca8826Dave Airlie formats[count++] = PIPE_FORMAT_Z24_UNORM_S8_UINT; 3993475e88442c16fb2b50b903fe246b3ebe49da226Chia-I Wu } 400ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul if (depth <= 32 && stencil == 0) { 401ef2664da6c4db1b52ef351641e3ee949b87f9c7bBrian Paul formats[count++] = PIPE_FORMAT_Z32_UNORM; 402576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu } 403a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul 404576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu fmt = PIPE_FORMAT_NONE; 405576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu for (i = 0; i < count; i++) { 4066632915e957149c153a3f793c400a532b4995b18Chia-I Wu if (xmdpy->screen->is_format_supported(xmdpy->screen, formats[i], 407685bb6941681f89f71a9169594d87c8e314b94d0Roland Scheidegger target, sample_count, 408e968975cb57eb854769292f7c6ff773c64a386c3Marek Olšák tex_usage)) { 409576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu fmt = formats[i]; 410a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul break; 411a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul } 412a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul } 413a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul 414576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu return fmt; 415a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul} 416a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul 417a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul 418a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul 419ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/**********************************************************************/ 420ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/***** Linked list of XMesaBuffers *****/ 421ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/**********************************************************************/ 422ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 4236632915e957149c153a3f793c400a532b4995b18Chia-I Wustatic XMesaBuffer XMesaBufferList = NULL; 424ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 425ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 426ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 427ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Allocate a new XMesaBuffer object which corresponds to the given drawable. 42831aca27c08d6a385c595d34fe4ee06390bf5b0e8Kristian Høgsberg * Note that XMesaBuffer is derived from struct gl_framebuffer. 429ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * The new XMesaBuffer will not have any size (Width=Height=0). 430ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 431ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param d the corresponding X drawable (window or pixmap) 432ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param type either WINDOW, PIXMAP or PBUFFER, describing d 433ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param vis the buffer's visual 434ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param cmap the window's colormap, if known. 435ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \return new XMesaBuffer or NULL if any problem 436ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 437ef25c496d52f4f6c45816b64b4c0999321476cd7Brianstatic XMesaBuffer 438153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwellcreate_xmesa_buffer(Drawable d, BufferType type, 439153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell XMesaVisual vis, Colormap cmap) 440ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 4416632915e957149c153a3f793c400a532b4995b18Chia-I Wu XMesaDisplay xmdpy = xmesa_init_display(vis->display); 442ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer b; 443c664302c3e34a29b4bbb02fd3789dd3f7d92849cBrian uint width, height; 444ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 445ef25c496d52f4f6c45816b64b4c0999321476cd7Brian ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER); 446ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 4476632915e957149c153a3f793c400a532b4995b18Chia-I Wu if (!xmdpy) 448576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu return NULL; 449576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu 450ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b = (XMesaBuffer) CALLOC_STRUCT(xmesa_buffer); 451ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!b) 452ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 453ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 454c3ef232315a4e9c18b3d812dbb28ffac6830d6f8Stéphane Marchesin b->ws.drawable = d; 4551675d05f911fbd569efb5248674aa71cb755c75bKeith Whitwell b->ws.visual = vis->visinfo->visual; 4561675d05f911fbd569efb5248674aa71cb755c75bKeith Whitwell b->ws.depth = vis->visinfo->depth; 457749d723287df348bd36ee43f96de6892a3eba09fBrian 458ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b->xm_visual = vis; 459ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b->type = type; 460ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b->cmap = cmap; 461ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 462c664302c3e34a29b4bbb02fd3789dd3f7d92849cBrian get_drawable_size(vis->display, d, &width, &height); 463c664302c3e34a29b4bbb02fd3789dd3f7d92849cBrian 464e39f1b4cbea6d41dc09430bd3d811cb7bbdea5f8Brian /* 465e39f1b4cbea6d41dc09430bd3d811cb7bbdea5f8Brian * Create framebuffer, but we'll plug in our own renderbuffers below. 466e39f1b4cbea6d41dc09430bd3d811cb7bbdea5f8Brian */ 46748bc3cca89f7aecc40d1661e695796113df6e583Chia-I Wu b->stfb = xmesa_create_st_framebuffer(xmdpy, b); 468e39f1b4cbea6d41dc09430bd3d811cb7bbdea5f8Brian 469ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* GLX_EXT_texture_from_pixmap */ 470ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b->TextureTarget = 0; 471ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b->TextureFormat = GLX_TEXTURE_FORMAT_NONE_EXT; 472ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b->TextureMipmap = 0; 473ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 474ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* insert buffer into linked list */ 475ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b->Next = XMesaBufferList; 476ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBufferList = b; 477ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 478ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return b; 479ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 480ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 481ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 482ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 483ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Find an XMesaBuffer by matching X display and colormap but NOT matching 484ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * the notThis buffer. 485ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 486ef25c496d52f4f6c45816b64b4c0999321476cd7BrianXMesaBuffer 487153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwellxmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis) 488ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 489ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer b; 490749d723287df348bd36ee43f96de6892a3eba09fBrian for (b = XMesaBufferList; b; b = b->Next) { 491749d723287df348bd36ee43f96de6892a3eba09fBrian if (b->xm_visual->display == dpy && 492749d723287df348bd36ee43f96de6892a3eba09fBrian b->cmap == cmap && 493749d723287df348bd36ee43f96de6892a3eba09fBrian b != notThis) { 494ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return b; 495ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 496ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 497ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 498ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 499ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 500ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 501ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 502ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Remove buffer from linked list, delete if no longer referenced. 503ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 504ef25c496d52f4f6c45816b64b4c0999321476cd7Brianstatic void 505ef25c496d52f4f6c45816b64b4c0999321476cd7Brianxmesa_free_buffer(XMesaBuffer buffer) 506ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 507ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer prev = NULL, b; 508ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 509ef25c496d52f4f6c45816b64b4c0999321476cd7Brian for (b = XMesaBufferList; b; b = b->Next) { 510ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (b == buffer) { 511ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* unlink buffer from list */ 512ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (prev) 513ef25c496d52f4f6c45816b64b4c0999321476cd7Brian prev->Next = buffer->Next; 514ef25c496d52f4f6c45816b64b4c0999321476cd7Brian else 515ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBufferList = buffer->Next; 516ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 517ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* Since the X window for the XMesaBuffer is going away, we don't 518ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * want to dereference this pointer in the future. 519ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 5201675d05f911fbd569efb5248674aa71cb755c75bKeith Whitwell b->ws.drawable = 0; 521ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 522576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu /* XXX we should move the buffer to a delete-pending list and destroy 523576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu * the buffer until it is no longer current. 524576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu */ 525576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu xmesa_destroy_st_framebuffer(buffer->stfb); 526ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 527f44e2f14d24b6d2730e7ff85e96695867ee96cbeBrian free(buffer); 528f44e2f14d24b6d2730e7ff85e96695867ee96cbeBrian 529ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return; 530ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 531ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* continue search */ 532ef25c496d52f4f6c45816b64b4c0999321476cd7Brian prev = b; 533ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 534ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* buffer not found in XMesaBufferList */ 535ef25c496d52f4f6c45816b64b4c0999321476cd7Brian _mesa_problem(NULL,"xmesa_free_buffer() - buffer not found\n"); 536ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 537ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 538ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 539ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 540ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/**********************************************************************/ 541ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/***** Misc Private Functions *****/ 542ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/**********************************************************************/ 543ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 544ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 545ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 546ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * When a context is bound for the first time, we can finally finish 547ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * initializing the context's visual and buffer information. 548ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param v the XMesaVisual to initialize 549ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param b the XMesaBuffer to initialize (may be NULL) 550ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param rgb_flag TRUE = RGBA mode, FALSE = color index mode 551ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param window the window/pixmap we're rendering into 552ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param cmap the colormap associated with the window/pixmap 553ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \return GL_TRUE=success, GL_FALSE=failure 554ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 555ef25c496d52f4f6c45816b64b4c0999321476cd7Brianstatic GLboolean 556ef25c496d52f4f6c45816b64b4c0999321476cd7Brianinitialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b, 557153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell GLboolean rgb_flag, Drawable window, 558153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell Colormap cmap) 559ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 560ef25c496d52f4f6c45816b64b4c0999321476cd7Brian ASSERT(!b || b->xm_visual == v); 561ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 562ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* Save true bits/pixel */ 563ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->BitsPerPixel = bits_per_pixel(v); 564ef25c496d52f4f6c45816b64b4c0999321476cd7Brian assert(v->BitsPerPixel > 0); 565ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 566ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (rgb_flag == GL_FALSE) { 567749d723287df348bd36ee43f96de6892a3eba09fBrian /* COLOR-INDEXED WINDOW: not supported*/ 568749d723287df348bd36ee43f96de6892a3eba09fBrian return GL_FALSE; 569ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 570ef25c496d52f4f6c45816b64b4c0999321476cd7Brian else { 571ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* RGB WINDOW: 572ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * We support RGB rendering into almost any kind of visual. 573ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 574705e142dda047f24b563fc2bea0f922173e91d1bKristian Høgsberg const int xclass = v->visualType; 575749d723287df348bd36ee43f96de6892a3eba09fBrian if (xclass != GLX_TRUE_COLOR && xclass == !GLX_DIRECT_COLOR) { 576749d723287df348bd36ee43f96de6892a3eba09fBrian _mesa_warning(NULL, 577749d723287df348bd36ee43f96de6892a3eba09fBrian "XMesa: RGB mode rendering not supported in given visual.\n"); 578ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return GL_FALSE; 579ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 580ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->mesa_visual.indexBits = 0; 5815935b16ff5d8cbe07c97f2990e281a9c5986d0a1Brian 5825935b16ff5d8cbe07c97f2990e281a9c5986d0a1Brian if (v->BitsPerPixel == 32) { 5835935b16ff5d8cbe07c97f2990e281a9c5986d0a1Brian /* We use XImages for all front/back buffers. If an X Window or 5845935b16ff5d8cbe07c97f2990e281a9c5986d0a1Brian * X Pixmap is 32bpp, there's no guarantee that the alpha channel 5855935b16ff5d8cbe07c97f2990e281a9c5986d0a1Brian * will be preserved. For XImages we're in luck. 5865935b16ff5d8cbe07c97f2990e281a9c5986d0a1Brian */ 5875935b16ff5d8cbe07c97f2990e281a9c5986d0a1Brian v->mesa_visual.alphaBits = 8; 5885935b16ff5d8cbe07c97f2990e281a9c5986d0a1Brian } 589ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 590ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 591ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* 592ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * If MESA_INFO env var is set print out some debugging info 593ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * which can help Brian figure out what's going on when a user 594ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * reports bugs. 595ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 596ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (_mesa_getenv("MESA_INFO")) { 597298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("X/Mesa visual = %p\n", (void *) v); 598298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("X/Mesa level = %d\n", v->mesa_visual.level); 599298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("X/Mesa depth = %d\n", v->visinfo->depth); 600298be2b028263b2c343a707662c6fbfa18293cb2Kristian Høgsberg printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel); 601ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 602ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 603ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return GL_TRUE; 604ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 605ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 606ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 607ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 608ef25c496d52f4f6c45816b64b4c0999321476cd7Brian#define NUM_VISUAL_TYPES 6 609ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 610ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 611ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Convert an X visual type to a GLX visual type. 612ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 613ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.) 614ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * to be converted. 615ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \return If \c visualType is a valid X visual type, a GLX visual type will 616ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * be returned. Otherwise \c GLX_NONE will be returned. 617ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 618ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \note 619ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * This code was lifted directly from lib/GL/glx/glcontextmodes.c in the 620ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * DRI CVS tree. 621ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 622ef25c496d52f4f6c45816b64b4c0999321476cd7Brianstatic GLint 623ef25c496d52f4f6c45816b64b4c0999321476cd7Brianxmesa_convert_from_x_visual_type( int visualType ) 624ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 625ef25c496d52f4f6c45816b64b4c0999321476cd7Brian static const int glx_visual_types[ NUM_VISUAL_TYPES ] = { 626ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLX_STATIC_GRAY, GLX_GRAY_SCALE, 627ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLX_STATIC_COLOR, GLX_PSEUDO_COLOR, 628ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLX_TRUE_COLOR, GLX_DIRECT_COLOR 629ef25c496d52f4f6c45816b64b4c0999321476cd7Brian }; 630ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 631ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return ( (unsigned) visualType < NUM_VISUAL_TYPES ) 632ef25c496d52f4f6c45816b64b4c0999321476cd7Brian ? glx_visual_types[ visualType ] : GLX_NONE; 633ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 634ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 635ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 636ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/**********************************************************************/ 637ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/***** Public Functions *****/ 638ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/**********************************************************************/ 639ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 640ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 641ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/* 642ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Create a new X/Mesa visual. 643ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Input: display - X11 display 644ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * visinfo - an XVisualInfo pointer 645ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * rgb_flag - GL_TRUE = RGB mode, 646ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * GL_FALSE = color index mode 647ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * alpha_flag - alpha buffer requested? 648ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * db_flag - GL_TRUE = double-buffered, 649ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * GL_FALSE = single buffered 650ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * stereo_flag - stereo visual? 651ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * ximage_flag - GL_TRUE = use an XImage for back buffer, 652ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * GL_FALSE = use an off-screen pixmap for back buffer 653ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * depth_size - requested bits/depth values, or zero 654ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * stencil_size - requested bits/stencil values, or zero 655ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * accum_red_size - requested bits/red accum values, or zero 656ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * accum_green_size - requested bits/green accum values, or zero 657ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * accum_blue_size - requested bits/blue accum values, or zero 658ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * accum_alpha_size - requested bits/alpha accum values, or zero 659ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * num_samples - number of samples/pixel if multisampling, or zero 660ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * level - visual level, usually 0 661ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * visualCaveat - ala the GLX extension, usually GLX_NONE 662ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Return; a new XMesaVisual or 0 if error. 663ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 664ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC 665153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith WhitwellXMesaVisual XMesaCreateVisual( Display *display, 666153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell XVisualInfo * visinfo, 667ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLboolean rgb_flag, 668ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLboolean alpha_flag, 669ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLboolean db_flag, 670ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLboolean stereo_flag, 671ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLboolean ximage_flag, 672ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLint depth_size, 673ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLint stencil_size, 674ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLint accum_red_size, 675ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLint accum_green_size, 676ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLint accum_blue_size, 677ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLint accum_alpha_size, 678ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLint num_samples, 679ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLint level, 680ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLint visualCaveat ) 681ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 6826632915e957149c153a3f793c400a532b4995b18Chia-I Wu XMesaDisplay xmdpy = xmesa_init_display(display); 683ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaVisual v; 684ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GLint red_bits, green_bits, blue_bits, alpha_bits; 685ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 6866632915e957149c153a3f793c400a532b4995b18Chia-I Wu if (!xmdpy) 6876632915e957149c153a3f793c400a532b4995b18Chia-I Wu return NULL; 688a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul 689ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* For debugging only */ 690ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (_mesa_getenv("MESA_XSYNC")) { 691ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* This makes debugging X easier. 692ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * In your debugger, set a breakpoint on _XError to stop when an 693ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * X protocol error is generated. 694ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 695ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XSynchronize( display, 1 ); 696ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 697ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 698ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v = (XMesaVisual) CALLOC_STRUCT(xmesa_visual); 699ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!v) { 700ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 701ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 702ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 703ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->display = display; 704ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 70532f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg /* Save a copy of the XVisualInfo struct because the user may Xfree() 706ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * the struct but we may need some of the information contained in it 707ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * at a later time. 708ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 709ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->visinfo = (XVisualInfo *) MALLOC(sizeof(*visinfo)); 71040636fe6f2763e6be4141516a9eba5004b371915Brian Paul if (!v->visinfo) { 71132f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(v); 712ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 713ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 714e197de56cdb86835f1437688a9161cd909792d80Brian Paul memcpy(v->visinfo, visinfo, sizeof(*visinfo)); 715ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 716ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->ximage_flag = ximage_flag; 717ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 718ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->mesa_visual.redMask = visinfo->red_mask; 719ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->mesa_visual.greenMask = visinfo->green_mask; 720ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->mesa_visual.blueMask = visinfo->blue_mask; 721705e142dda047f24b563fc2bea0f922173e91d1bKristian Høgsberg v->visualID = visinfo->visualid; 722705e142dda047f24b563fc2bea0f922173e91d1bKristian Høgsberg v->screen = visinfo->screen; 723ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 72418ad0e3a284da13ebd6bac7a5cc5a9d17ab6efc7Keith Whitwell#if !(defined(__cplusplus) || defined(c_plusplus)) 725705e142dda047f24b563fc2bea0f922173e91d1bKristian Høgsberg v->visualType = xmesa_convert_from_x_visual_type(visinfo->class); 726ef25c496d52f4f6c45816b64b4c0999321476cd7Brian#else 727705e142dda047f24b563fc2bea0f922173e91d1bKristian Høgsberg v->visualType = xmesa_convert_from_x_visual_type(visinfo->c_class); 728ef25c496d52f4f6c45816b64b4c0999321476cd7Brian#endif 729ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 730ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->mesa_visual.visualRating = visualCaveat; 731ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 732ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (alpha_flag) 733ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->mesa_visual.alphaBits = 8; 734ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 735ef25c496d52f4f6c45816b64b4c0999321476cd7Brian (void) initialize_visual_and_buffer( v, NULL, rgb_flag, 0, 0 ); 736ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 737ef25c496d52f4f6c45816b64b4c0999321476cd7Brian { 738705e142dda047f24b563fc2bea0f922173e91d1bKristian Høgsberg const int xclass = v->visualType; 739ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) { 740ef25c496d52f4f6c45816b64b4c0999321476cd7Brian red_bits = _mesa_bitcount(GET_REDMASK(v)); 741ef25c496d52f4f6c45816b64b4c0999321476cd7Brian green_bits = _mesa_bitcount(GET_GREENMASK(v)); 742ef25c496d52f4f6c45816b64b4c0999321476cd7Brian blue_bits = _mesa_bitcount(GET_BLUEMASK(v)); 743ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 744ef25c496d52f4f6c45816b64b4c0999321476cd7Brian else { 745ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* this is an approximation */ 746ef25c496d52f4f6c45816b64b4c0999321476cd7Brian int depth; 7472b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell depth = v->visinfo->depth; 748ef25c496d52f4f6c45816b64b4c0999321476cd7Brian red_bits = depth / 3; 749ef25c496d52f4f6c45816b64b4c0999321476cd7Brian depth -= red_bits; 750ef25c496d52f4f6c45816b64b4c0999321476cd7Brian green_bits = depth / 2; 751ef25c496d52f4f6c45816b64b4c0999321476cd7Brian depth -= green_bits; 752ef25c496d52f4f6c45816b64b4c0999321476cd7Brian blue_bits = depth; 753ef25c496d52f4f6c45816b64b4c0999321476cd7Brian alpha_bits = 0; 7542b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell assert( red_bits + green_bits + blue_bits == v->visinfo->depth ); 755ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 756ef25c496d52f4f6c45816b64b4c0999321476cd7Brian alpha_bits = v->mesa_visual.alphaBits; 757ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 758ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 75940fd4323b4be0eee6d4204463737a37011739333Chia-I Wu /* initialize visual */ 76040fd4323b4be0eee6d4204463737a37011739333Chia-I Wu { 761d3491e775fb07f891463b2185d74bbad62f3ed24Kristian Høgsberg struct gl_config *vis = &v->mesa_visual; 76240fd4323b4be0eee6d4204463737a37011739333Chia-I Wu 76340fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->rgbMode = GL_TRUE; 76440fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->doubleBufferMode = db_flag; 76540fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->stereoMode = stereo_flag; 76640fd4323b4be0eee6d4204463737a37011739333Chia-I Wu 76740fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->redBits = red_bits; 76840fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->greenBits = green_bits; 76940fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->blueBits = blue_bits; 77040fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->alphaBits = alpha_bits; 77140fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->rgbBits = red_bits + green_bits + blue_bits; 77240fd4323b4be0eee6d4204463737a37011739333Chia-I Wu 77340fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->indexBits = 0; 77440fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->depthBits = depth_size; 77540fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->stencilBits = stencil_size; 77640fd4323b4be0eee6d4204463737a37011739333Chia-I Wu 77740fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->accumRedBits = accum_red_size; 77840fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->accumGreenBits = accum_green_size; 77940fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->accumBlueBits = accum_blue_size; 78040fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->accumAlphaBits = accum_alpha_size; 78140fd4323b4be0eee6d4204463737a37011739333Chia-I Wu 78240fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->haveAccumBuffer = accum_red_size > 0; 78340fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->haveDepthBuffer = depth_size > 0; 78440fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->haveStencilBuffer = stencil_size > 0; 78540fd4323b4be0eee6d4204463737a37011739333Chia-I Wu 78640fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->numAuxBuffers = 0; 78740fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->level = 0; 78840fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->sampleBuffers = 0; 78940fd4323b4be0eee6d4204463737a37011739333Chia-I Wu vis->samples = 0; 79040fd4323b4be0eee6d4204463737a37011739333Chia-I Wu } 791ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 792576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu v->stvis.buffer_mask = ST_ATTACHMENT_FRONT_LEFT_MASK; 793576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu if (db_flag) 794418b9ac2990fc6809de359a862ee809d3b86343cChia-I Wu v->stvis.buffer_mask |= ST_ATTACHMENT_BACK_LEFT_MASK; 795576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu if (stereo_flag) { 796418b9ac2990fc6809de359a862ee809d3b86343cChia-I Wu v->stvis.buffer_mask |= ST_ATTACHMENT_FRONT_RIGHT_MASK; 797576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu if (db_flag) 798418b9ac2990fc6809de359a862ee809d3b86343cChia-I Wu v->stvis.buffer_mask |= ST_ATTACHMENT_BACK_RIGHT_MASK; 799576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu } 800576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu 801576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu v->stvis.color_format = choose_pixel_format(v); 802c1a392ac4c6a7da4026653de556c2c7698f86860Chia-I Wu if (v->stvis.color_format == PIPE_FORMAT_NONE) { 803c1a392ac4c6a7da4026653de556c2c7698f86860Chia-I Wu FREE(v->visinfo); 804c1a392ac4c6a7da4026653de556c2c7698f86860Chia-I Wu FREE(v); 805c1a392ac4c6a7da4026653de556c2c7698f86860Chia-I Wu return NULL; 806c1a392ac4c6a7da4026653de556c2c7698f86860Chia-I Wu } 807c1a392ac4c6a7da4026653de556c2c7698f86860Chia-I Wu 808576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu v->stvis.depth_stencil_format = 8096632915e957149c153a3f793c400a532b4995b18Chia-I Wu choose_depth_stencil_format(xmdpy, depth_size, stencil_size); 810576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu 811576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu v->stvis.accum_format = (accum_red_size + 812576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu accum_green_size + accum_blue_size + accum_alpha_size) ? 813576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu PIPE_FORMAT_R16G16B16A16_SNORM : PIPE_FORMAT_NONE; 814576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu 815576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu v->stvis.samples = num_samples; 816576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu v->stvis.render_buffer = ST_ATTACHMENT_INVALID; 817576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu 818ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* XXX minor hack */ 819ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->mesa_visual.level = level; 820ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return v; 821ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 822ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 823ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 824ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC 825ef25c496d52f4f6c45816b64b4c0999321476cd7Brianvoid XMesaDestroyVisual( XMesaVisual v ) 826ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 82732f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(v->visinfo); 82832f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(v); 829ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 830ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 831ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 832a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul/** 833997a2547d10890dbc00f2c48191cde58a2ee37c8Chia-I Wu * Return the informative name. 834997a2547d10890dbc00f2c48191cde58a2ee37c8Chia-I Wu */ 835997a2547d10890dbc00f2c48191cde58a2ee37c8Chia-I Wuconst char * 836997a2547d10890dbc00f2c48191cde58a2ee37c8Chia-I Wuxmesa_get_name(void) 837997a2547d10890dbc00f2c48191cde58a2ee37c8Chia-I Wu{ 838997a2547d10890dbc00f2c48191cde58a2ee37c8Chia-I Wu return stapi->name; 839997a2547d10890dbc00f2c48191cde58a2ee37c8Chia-I Wu} 840997a2547d10890dbc00f2c48191cde58a2ee37c8Chia-I Wu 841997a2547d10890dbc00f2c48191cde58a2ee37c8Chia-I Wu 842997a2547d10890dbc00f2c48191cde58a2ee37c8Chia-I Wu/** 8436632915e957149c153a3f793c400a532b4995b18Chia-I Wu * Do per-display initializations. 844a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul */ 845a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paulvoid 8461675d05f911fbd569efb5248674aa71cb755c75bKeith Whitwellxmesa_init( Display *display ) 847a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul{ 8486632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmesa_init_display(display); 849a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul} 850a84575cdc0c8193b2c7858734e2ec6b1ec4511b2Brian Paul 851ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 852ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 853ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Create a new XMesaContext. 854ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param v the XMesaVisual 855ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param share_list another XMesaContext with which to share display 856ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * lists or NULL if no sharing is wanted. 857ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \return an XMesaContext or NULL if error. 858ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 859ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC 8601929d52fd907b4e42e31ad459dd50a1de53df26cBrian PaulXMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list, 8611929d52fd907b4e42e31ad459dd50a1de53df26cBrian Paul GLuint major, GLuint minor, 8621929d52fd907b4e42e31ad459dd50a1de53df26cBrian Paul GLuint profileMask, GLuint contextFlags) 863ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 8646632915e957149c153a3f793c400a532b4995b18Chia-I Wu XMesaDisplay xmdpy = xmesa_init_display(v->display); 8654531356817ec8383ac35932903773de67af92e37Chia-I Wu struct st_context_attribs attribs; 8663258cd9e611bb188e4b21d23cd5dd6cb0c0ff1efAlexandre Demers enum st_context_error ctx_err = 0; 867ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaContext c; 868e39f1b4cbea6d41dc09430bd3d811cb7bbdea5f8Brian 8696632915e957149c153a3f793c400a532b4995b18Chia-I Wu if (!xmdpy) 8706632915e957149c153a3f793c400a532b4995b18Chia-I Wu return NULL; 871ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 872f9995b30756140724f41daf963fa06167912be7fKristian Høgsberg /* Note: the XMesaContext contains a Mesa struct gl_context struct (inheritance) */ 873ef25c496d52f4f6c45816b64b4c0999321476cd7Brian c = (XMesaContext) CALLOC_STRUCT(xmesa_context); 874ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!c) 875ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 876ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 877b09de96a17028c3c936f6a196e048c4f224da89fIan Romanick c->xm_visual = v; 878b09de96a17028c3c936f6a196e048c4f224da89fIan Romanick c->xm_buffer = NULL; /* set later by XMesaMakeCurrent */ 879d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom c->xm_read_buffer = NULL; 880d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom 8814531356817ec8383ac35932903773de67af92e37Chia-I Wu memset(&attribs, 0, sizeof(attribs)); 8824531356817ec8383ac35932903773de67af92e37Chia-I Wu attribs.visual = v->stvis; 88338f89c7008b5ed9a70439f4e6590f00a4e220b10Brian Paul attribs.major = major; 88438f89c7008b5ed9a70439f4e6590f00a4e220b10Brian Paul attribs.minor = minor; 88538f89c7008b5ed9a70439f4e6590f00a4e220b10Brian Paul if (contextFlags & GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB) 88638f89c7008b5ed9a70439f4e6590f00a4e220b10Brian Paul attribs.flags |= ST_CONTEXT_FLAG_FORWARD_COMPATIBLE; 88738f89c7008b5ed9a70439f4e6590f00a4e220b10Brian Paul if (contextFlags & GLX_CONTEXT_DEBUG_BIT_ARB) 88838f89c7008b5ed9a70439f4e6590f00a4e220b10Brian Paul attribs.flags |= ST_CONTEXT_FLAG_DEBUG; 88938f89c7008b5ed9a70439f4e6590f00a4e220b10Brian Paul if (contextFlags & GLX_CONTEXT_ROBUST_ACCESS_BIT_ARB) 89038f89c7008b5ed9a70439f4e6590f00a4e220b10Brian Paul attribs.flags |= ST_CONTEXT_FLAG_ROBUST_ACCESS; 891358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick 892358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick /* There are no profiles before OpenGL 3.2. The 893358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick * GLX_ARB_create_context_profile spec says: 894358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick * 895358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick * "If the requested OpenGL version is less than 3.2, 896358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick * GLX_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality of the 897358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick * context is determined solely by the requested version." 898358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick * 899358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick * The spec also says: 900358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick * 901358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick * "The default value for GLX_CONTEXT_PROFILE_MASK_ARB is 902358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick * GLX_CONTEXT_CORE_PROFILE_BIT_ARB." 903358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick */ 904358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick attribs.profile = ST_PROFILE_DEFAULT; 905358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick if ((major > 3 || (major == 3 && minor >= 2)) 906358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick && ((profileMask & GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB) == 0)) 907358ecff1ea0fa8432fd46bd3deeb8d2d694b5550Ian Romanick attribs.profile = ST_PROFILE_OPENGL_CORE; 9084531356817ec8383ac35932903773de67af92e37Chia-I Wu 9093258cd9e611bb188e4b21d23cd5dd6cb0c0ff1efAlexandre Demers c->st = stapi->create_context(stapi, xmdpy->smapi, &attribs, 9103258cd9e611bb188e4b21d23cd5dd6cb0c0ff1efAlexandre Demers &ctx_err, (share_list) ? share_list->st : NULL); 9112258f6b437705860912be300e728efbde60e2140Keith Whitwell if (c->st == NULL) 9122258f6b437705860912be300e728efbde60e2140Keith Whitwell goto fail; 913002dfb12fce045d0e124301e5df805df772149d8Keith Whitwell 914576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu c->st->st_manager_private = (void *) c; 915ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 916ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return c; 9172258f6b437705860912be300e728efbde60e2140Keith Whitwell 91840636fe6f2763e6be4141516a9eba5004b371915Brian Paulfail: 9192258f6b437705860912be300e728efbde60e2140Keith Whitwell if (c->st) 920576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu c->st->destroy(c->st); 921002dfb12fce045d0e124301e5df805df772149d8Keith Whitwell 92232f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(c); 9232258f6b437705860912be300e728efbde60e2140Keith Whitwell return NULL; 924ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 925ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 926ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 927ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 928ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC 929ef25c496d52f4f6c45816b64b4c0999321476cd7Brianvoid XMesaDestroyContext( XMesaContext c ) 930ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 931576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu c->st->destroy(c->st); 932002dfb12fce045d0e124301e5df805df772149d8Keith Whitwell 933f9e14e0daca3b2f3662a68413c2fa71c05375b8eJosé Fonseca /* FIXME: We should destroy the screen here, but if we do so, surfaces may 934f9e14e0daca3b2f3662a68413c2fa71c05375b8eJosé Fonseca * outlive it, causing segfaults 935002dfb12fce045d0e124301e5df805df772149d8Keith Whitwell struct pipe_screen *screen = c->st->pipe->screen; 936969ff9e9bf3dfae08d087bbc47ce43f17d107bfcJosé Fonseca screen->destroy(screen); 937f9e14e0daca3b2f3662a68413c2fa71c05375b8eJosé Fonseca */ 938002dfb12fce045d0e124301e5df805df772149d8Keith Whitwell 93932f2fd1c5d6088692551c80352b7d6fa35b0cd09Kristian Høgsberg free(c); 940ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 941ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 942ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 943ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 944ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 945ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Private function for creating an XMesaBuffer which corresponds to an 946ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * X window or pixmap. 947ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param v the window's XMesaVisual 948ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param w the window we're wrapping 949ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \return new XMesaBuffer or NULL if error 950ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 951ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC XMesaBuffer 952153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith WhitwellXMesaCreateWindowBuffer(XMesaVisual v, Window w) 953ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 954ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XWindowAttributes attr; 955ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer b; 956153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell Colormap cmap; 957ef25c496d52f4f6c45816b64b4c0999321476cd7Brian int depth; 958ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 959ef25c496d52f4f6c45816b64b4c0999321476cd7Brian assert(v); 960ef25c496d52f4f6c45816b64b4c0999321476cd7Brian assert(w); 961ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 962ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* Check that window depth matches visual depth */ 963ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XGetWindowAttributes( v->display, w, &attr ); 964ef25c496d52f4f6c45816b64b4c0999321476cd7Brian depth = attr.depth; 9652b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell if (v->visinfo->depth != depth) { 966ef25c496d52f4f6c45816b64b4c0999321476cd7Brian _mesa_warning(NULL, "XMesaCreateWindowBuffer: depth mismatch between visual (%d) and window (%d)!\n", 9672b960128e8c87098ed3cfa29380b6ff524df3647Keith Whitwell v->visinfo->depth, depth); 968ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 969ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 970ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 971ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* Find colormap */ 972ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (attr.colormap) { 973ef25c496d52f4f6c45816b64b4c0999321476cd7Brian cmap = attr.colormap; 974ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 975ef25c496d52f4f6c45816b64b4c0999321476cd7Brian else { 976ef25c496d52f4f6c45816b64b4c0999321476cd7Brian _mesa_warning(NULL, "Window %u has no colormap!\n", (unsigned int) w); 977ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* this is weird, a window w/out a colormap!? */ 978ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* OK, let's just allocate a new one and hope for the best */ 979ef25c496d52f4f6c45816b64b4c0999321476cd7Brian cmap = XCreateColormap(v->display, w, attr.visual, AllocNone); 980ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 981ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 982153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell b = create_xmesa_buffer((Drawable) w, WINDOW, v, cmap); 983ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!b) 984ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 985ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 986ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!initialize_visual_and_buffer( v, b, v->mesa_visual.rgbMode, 987153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell (Drawable) w, cmap )) { 988ef25c496d52f4f6c45816b64b4c0999321476cd7Brian xmesa_free_buffer(b); 989ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 990ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 991ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 992ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return b; 993ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 994ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 995ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 996ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 997ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 998ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Create a new XMesaBuffer from an X pixmap. 999ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * 1000ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param v the XMesaVisual 1001ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param p the pixmap 1002ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \param cmap the colormap, may be 0 if using a \c GLX_TRUE_COLOR or 1003ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \c GLX_DIRECT_COLOR visual for the pixmap 1004ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * \returns new XMesaBuffer or NULL if error 1005ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 1006ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC XMesaBuffer 1007153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith WhitwellXMesaCreatePixmapBuffer(XMesaVisual v, Pixmap p, Colormap cmap) 1008ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1009ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer b; 1010ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1011ef25c496d52f4f6c45816b64b4c0999321476cd7Brian assert(v); 1012ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1013153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell b = create_xmesa_buffer((Drawable) p, PIXMAP, v, cmap); 1014ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!b) 1015ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 1016ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1017ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode, 1018153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell (Drawable) p, cmap)) { 1019ef25c496d52f4f6c45816b64b4c0999321476cd7Brian xmesa_free_buffer(b); 1020ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 1021ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1022ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1023ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return b; 1024ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1025ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1026ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1027ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 1028ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * For GLX_EXT_texture_from_pixmap 1029ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 1030ef25c496d52f4f6c45816b64b4c0999321476cd7BrianXMesaBuffer 1031153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith WhitwellXMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p, 1032153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell Colormap cmap, 1033ef25c496d52f4f6c45816b64b4c0999321476cd7Brian int format, int target, int mipmap) 1034ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1035ef25c496d52f4f6c45816b64b4c0999321476cd7Brian GET_CURRENT_CONTEXT(ctx); 1036ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer b; 1037ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1038ef25c496d52f4f6c45816b64b4c0999321476cd7Brian assert(v); 1039ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1040153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell b = create_xmesa_buffer((Drawable) p, PIXMAP, v, cmap); 1041ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!b) 1042ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 1043ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1044576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu /* get pixmap size */ 1045576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu xmesa_get_window_size(v->display, b, &b->width, &b->height); 1046ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1047ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (target == 0) { 1048ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* examine dims */ 1049ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (ctx->Extensions.ARB_texture_non_power_of_two) { 1050ef25c496d52f4f6c45816b64b4c0999321476cd7Brian target = GLX_TEXTURE_2D_EXT; 1051ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1052576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu else if ( _mesa_bitcount(b->width) == 1 1053576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu && _mesa_bitcount(b->height) == 1) { 1054ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* power of two size */ 1055576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu if (b->height == 1) { 1056ef25c496d52f4f6c45816b64b4c0999321476cd7Brian target = GLX_TEXTURE_1D_EXT; 1057ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1058ef25c496d52f4f6c45816b64b4c0999321476cd7Brian else { 1059ef25c496d52f4f6c45816b64b4c0999321476cd7Brian target = GLX_TEXTURE_2D_EXT; 1060ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1061ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1062ef25c496d52f4f6c45816b64b4c0999321476cd7Brian else if (ctx->Extensions.NV_texture_rectangle) { 1063ef25c496d52f4f6c45816b64b4c0999321476cd7Brian target = GLX_TEXTURE_RECTANGLE_EXT; 1064ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1065ef25c496d52f4f6c45816b64b4c0999321476cd7Brian else { 1066ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* non power of two textures not supported */ 1067ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaDestroyBuffer(b); 1068ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return 0; 1069ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1070ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1071ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1072ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b->TextureTarget = target; 1073ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b->TextureFormat = format; 1074ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b->TextureMipmap = mipmap; 1075ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1076ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode, 1077153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell (Drawable) p, cmap)) { 1078ef25c496d52f4f6c45816b64b4c0999321476cd7Brian xmesa_free_buffer(b); 1079ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 1080ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1081ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1082ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return b; 1083ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1084ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1085ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1086ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1087ef25c496d52f4f6c45816b64b4c0999321476cd7BrianXMesaBuffer 1088153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith WhitwellXMesaCreatePBuffer(XMesaVisual v, Colormap cmap, 1089ef25c496d52f4f6c45816b64b4c0999321476cd7Brian unsigned int width, unsigned int height) 1090ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1091153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell Window root; 1092153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwell Drawable drawable; /* X Pixmap Drawable */ 1093ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer b; 1094ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1095ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* allocate pixmap for front buffer */ 1096ef25c496d52f4f6c45816b64b4c0999321476cd7Brian root = RootWindow( v->display, v->visinfo->screen ); 1097ef25c496d52f4f6c45816b64b4c0999321476cd7Brian drawable = XCreatePixmap(v->display, root, width, height, 1098ef25c496d52f4f6c45816b64b4c0999321476cd7Brian v->visinfo->depth); 1099ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!drawable) 1100ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 1101ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1102ef25c496d52f4f6c45816b64b4c0999321476cd7Brian b = create_xmesa_buffer(drawable, PBUFFER, v, cmap); 1103ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!b) 1104ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 1105ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1106ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode, 1107ef25c496d52f4f6c45816b64b4c0999321476cd7Brian drawable, cmap)) { 1108ef25c496d52f4f6c45816b64b4c0999321476cd7Brian xmesa_free_buffer(b); 1109ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 1110ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1111ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1112ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return b; 1113ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1114ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1115ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1116ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1117ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/* 1118ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Deallocate an XMesaBuffer structure and all related info. 1119ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 1120ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC void 1121ef25c496d52f4f6c45816b64b4c0999321476cd7BrianXMesaDestroyBuffer(XMesaBuffer b) 1122ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1123ef25c496d52f4f6c45816b64b4c0999321476cd7Brian xmesa_free_buffer(b); 1124ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1125ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1126ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1127ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 112803224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wu * Notify the binding context to validate the buffer. 1129ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 1130ef25c496d52f4f6c45816b64b4c0999321476cd7Brianvoid 113103224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wuxmesa_notify_invalid_buffer(XMesaBuffer b) 1132ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 11335d2fad5444ebe0e2a66c49bd6254e2bc81618f6eThomas Hellstrom p_atomic_inc(&b->stfb->stamp); 113403224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wu} 113503224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wu 113603224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wu 113703224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wu/** 113803224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wu * Query the current drawable size and notify the binding context. 113903224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wu */ 114003224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wuvoid 114103224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wuxmesa_check_buffer_size(XMesaBuffer b) 114203224f492dc9cee179ff9ed961be0443a3669dd1Chia-I Wu{ 1143a221807dc5d69598afd1d0e0a4e715fb82a9f30dThomas Hellstrom GLuint old_width, old_height; 1144a221807dc5d69598afd1d0e0a4e715fb82a9f30dThomas Hellstrom 1145576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu if (b->type == PBUFFER) 1146576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu return; 1147ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1148a221807dc5d69598afd1d0e0a4e715fb82a9f30dThomas Hellstrom old_width = b->width; 1149a221807dc5d69598afd1d0e0a4e715fb82a9f30dThomas Hellstrom old_height = b->height; 1150a221807dc5d69598afd1d0e0a4e715fb82a9f30dThomas Hellstrom 1151576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu xmesa_get_window_size(b->xm_visual->display, b, &b->width, &b->height); 1152a221807dc5d69598afd1d0e0a4e715fb82a9f30dThomas Hellstrom 1153a221807dc5d69598afd1d0e0a4e715fb82a9f30dThomas Hellstrom if (b->width != old_width || b->height != old_height) 1154a221807dc5d69598afd1d0e0a4e715fb82a9f30dThomas Hellstrom xmesa_notify_invalid_buffer(b); 1155576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu} 1156ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1157ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1158ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/* 1159ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Bind buffer b to context c and make c the current rendering context. 1160ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 1161ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC 1162ef25c496d52f4f6c45816b64b4c0999321476cd7BrianGLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer, 1163ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer readBuffer ) 1164ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1165d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom XMesaContext old_ctx = XMesaGetCurrentContext(); 1166d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom 1167d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom if (old_ctx && old_ctx != c) { 1168d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom XMesaFlush(old_ctx); 1169d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom old_ctx->xm_buffer = NULL; 1170d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom old_ctx->xm_read_buffer = NULL; 1171d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom } 1172d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom 1173ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (c) { 1174ef25c496d52f4f6c45816b64b4c0999321476cd7Brian if (!drawBuffer || !readBuffer) 1175ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return GL_FALSE; /* must specify buffers! */ 1176ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1177d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom if (c == old_ctx && 1178d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom c->xm_buffer == drawBuffer && 1179d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom c->xm_read_buffer == readBuffer) 1180d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom return GL_TRUE; 1181ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1182576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu xmesa_check_buffer_size(drawBuffer); 1183576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu if (readBuffer != drawBuffer) 1184576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu xmesa_check_buffer_size(readBuffer); 1185576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu 1186ef25c496d52f4f6c45816b64b4c0999321476cd7Brian c->xm_buffer = drawBuffer; 1187d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom c->xm_read_buffer = readBuffer; 1188ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1189576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu stapi->make_current(stapi, c->st, drawBuffer->stfb, readBuffer->stfb); 1190ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1191ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */ 1192ef25c496d52f4f6c45816b64b4c0999321476cd7Brian drawBuffer->wasCurrent = GL_TRUE; 1193ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1194ef25c496d52f4f6c45816b64b4c0999321476cd7Brian else { 1195ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* Detach */ 1196576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu stapi->make_current(stapi, NULL, NULL, NULL); 1197d405ba3151de9585a310b7e2ebcae09302c0dbe4Thomas Hellstrom 1198ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1199ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return GL_TRUE; 1200ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1201ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1202ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1203ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/* 1204ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Unbind the context c from its buffer. 1205ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 1206ef25c496d52f4f6c45816b64b4c0999321476cd7BrianGLboolean XMesaUnbindContext( XMesaContext c ) 1207ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1208ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* A no-op for XFree86 integration purposes */ 1209ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return GL_TRUE; 1210ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1211ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1212ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1213ef25c496d52f4f6c45816b64b4c0999321476cd7BrianXMesaContext XMesaGetCurrentContext( void ) 1214ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1215576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu struct st_context_iface *st = stapi->get_current(stapi); 1216576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu return (XMesaContext) (st) ? st->st_manager_private : NULL; 1217ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1218ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1219ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1220ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1221b57b6c2d2c83aee96f945ce3385a1ab8337335cbBrian Paul/** 1222b57b6c2d2c83aee96f945ce3385a1ab8337335cbBrian Paul * Swap front and back color buffers and have winsys display front buffer. 1223b57b6c2d2c83aee96f945ce3385a1ab8337335cbBrian Paul * If there's no front color buffer no swap actually occurs. 1224ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 1225ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC 1226ef25c496d52f4f6c45816b64b4c0999321476cd7Brianvoid XMesaSwapBuffers( XMesaBuffer b ) 1227ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1228576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu XMesaContext xmctx = XMesaGetCurrentContext(); 1229576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu 1230576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu if (xmctx && xmctx->xm_buffer == b) { 12317e02303497237cde958c28608477d0c355a8038bMarek Olšák xmctx->st->flush( xmctx->st, ST_FLUSH_FRONT, NULL); 1232ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1233749d723287df348bd36ee43f96de6892a3eba09fBrian 1234576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu xmesa_swap_st_framebuffer(b->stfb); 1235ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1236ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1237ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1238ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1239ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/* 1240ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Copy sub-region of back buffer to front buffer 1241ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 1242ef25c496d52f4f6c45816b64b4c0999321476cd7Brianvoid XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height ) 1243ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1244576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu xmesa_copy_st_framebuffer(b->stfb, 1245576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu ST_ATTACHMENT_BACK_LEFT, ST_ATTACHMENT_FRONT_LEFT, 1246576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu x, y, width, height); 1247ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1248ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1249ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1250ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1251ef25c496d52f4f6c45816b64b4c0999321476cd7Brianvoid XMesaFlush( XMesaContext c ) 1252ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1253749d723287df348bd36ee43f96de6892a3eba09fBrian if (c && c->xm_visual->display) { 12546632915e957149c153a3f793c400a532b4995b18Chia-I Wu XMesaDisplay xmdpy = xmesa_init_display(c->xm_visual->display); 1255576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu struct pipe_fence_handle *fence = NULL; 1256576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu 12577e02303497237cde958c28608477d0c355a8038bMarek Olšák c->st->flush(c->st, ST_FLUSH_FRONT, &fence); 1258576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu if (fence) { 1259bfe88e69988b3d3bdff0b9f6051d0428e1315653Marek Olšák xmdpy->screen->fence_finish(xmdpy->screen, fence, 1260b39bccbd4ed71e9585da4cf5acf7b887b2e90899Marek Olšák PIPE_TIMEOUT_INFINITE); 12616632915e957149c153a3f793c400a532b4995b18Chia-I Wu xmdpy->screen->fence_reference(xmdpy->screen, &fence, NULL); 1262576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu } 12638570232b3b7930bd2ef58a337e9d57b12d3a8874Keith Whitwell XFlush( c->xm_visual->display ); 1264ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1265ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1266ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1267ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1268ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1269ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1270ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1271153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith WhitwellXMesaBuffer XMesaFindBuffer( Display *dpy, Drawable d ) 1272ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1273ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer b; 127440636fe6f2763e6be4141516a9eba5004b371915Brian Paul for (b = XMesaBufferList; b; b = b->Next) { 12751675d05f911fbd569efb5248674aa71cb755c75bKeith Whitwell if (b->ws.drawable == d && b->xm_visual->display == dpy) { 1276ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return b; 1277ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1278ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1279ef25c496d52f4f6c45816b64b4c0999321476cd7Brian return NULL; 1280ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1281ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1282ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1283ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/** 1284ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Free/destroy all XMesaBuffers associated with given display. 1285ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 1286153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith Whitwellvoid xmesa_destroy_buffers_on_display(Display *dpy) 1287ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1288ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer b, next; 1289ef25c496d52f4f6c45816b64b4c0999321476cd7Brian for (b = XMesaBufferList; b; b = next) { 1290ef25c496d52f4f6c45816b64b4c0999321476cd7Brian next = b->Next; 1291749d723287df348bd36ee43f96de6892a3eba09fBrian if (b->xm_visual->display == dpy) { 1292ef25c496d52f4f6c45816b64b4c0999321476cd7Brian xmesa_free_buffer(b); 12938cbc1517c1ba508dbf4d19f6eee729cdd1df8c37Brian Paul /* delete head of list? */ 12948cbc1517c1ba508dbf4d19f6eee729cdd1df8c37Brian Paul if (XMesaBufferList == b) { 12958cbc1517c1ba508dbf4d19f6eee729cdd1df8c37Brian Paul XMesaBufferList = next; 12968cbc1517c1ba508dbf4d19f6eee729cdd1df8c37Brian Paul } 1297ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1298ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1299ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1300ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1301ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1302ef25c496d52f4f6c45816b64b4c0999321476cd7Brian/* 1303ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Look for XMesaBuffers whose X window has been destroyed. 1304ef25c496d52f4f6c45816b64b4c0999321476cd7Brian * Deallocate any such XMesaBuffers. 1305ef25c496d52f4f6c45816b64b4c0999321476cd7Brian */ 1306ef25c496d52f4f6c45816b64b4c0999321476cd7Brianvoid XMesaGarbageCollect( void ) 1307ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1308ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaBuffer b, next; 1309ef25c496d52f4f6c45816b64b4c0999321476cd7Brian for (b=XMesaBufferList; b; b=next) { 1310ef25c496d52f4f6c45816b64b4c0999321476cd7Brian next = b->Next; 1311749d723287df348bd36ee43f96de6892a3eba09fBrian if (b->xm_visual && 1312749d723287df348bd36ee43f96de6892a3eba09fBrian b->xm_visual->display && 13131675d05f911fbd569efb5248674aa71cb755c75bKeith Whitwell b->ws.drawable && 1314749d723287df348bd36ee43f96de6892a3eba09fBrian b->type == WINDOW) { 1315749d723287df348bd36ee43f96de6892a3eba09fBrian XSync(b->xm_visual->display, False); 13161675d05f911fbd569efb5248674aa71cb755c75bKeith Whitwell if (!window_exists( b->xm_visual->display, b->ws.drawable )) { 1317ef25c496d52f4f6c45816b64b4c0999321476cd7Brian /* found a dead window, free the ancillary info */ 1318ef25c496d52f4f6c45816b64b4c0999321476cd7Brian XMesaDestroyBuffer( b ); 1319ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1320ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1321ef25c496d52f4f6c45816b64b4c0999321476cd7Brian } 1322ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1323ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1324ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 132500ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesinstatic enum st_attachment_type xmesa_attachment_type(int glx_attachment) 132600ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin{ 132700ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin switch(glx_attachment) { 132800ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin case GLX_FRONT_LEFT_EXT: 132900ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin return ST_ATTACHMENT_FRONT_LEFT; 133000ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin case GLX_FRONT_RIGHT_EXT: 133100ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin return ST_ATTACHMENT_FRONT_RIGHT; 133200ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin case GLX_BACK_LEFT_EXT: 133300ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin return ST_ATTACHMENT_BACK_LEFT; 133400ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin case GLX_BACK_RIGHT_EXT: 133500ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin return ST_ATTACHMENT_BACK_RIGHT; 133600ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin default: 133700ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin assert(0); 133800ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin return ST_ATTACHMENT_FRONT_LEFT; 133900ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin } 134000ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin} 1341ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1342ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1343ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC void 1344153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith WhitwellXMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, 1345ef25c496d52f4f6c45816b64b4c0999321476cd7Brian const int *attrib_list) 1346ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 134700ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin struct st_context_iface *st = stapi->get_current(stapi); 134800ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin struct st_framebuffer_iface* stfbi = drawable->stfb; 134900ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin struct pipe_resource *res; 135000ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin int x, y, w, h; 135100ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin enum st_attachment_type st_attachment = xmesa_attachment_type(buffer); 135200ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 135300ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin x = 0; 135400ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin y = 0; 135500ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin w = drawable->width; 135600ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin h = drawable->height; 135700ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 135800ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin /* We need to validate our attachments before using them, 135900ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin * in case the texture doesn't exist yet. */ 136000ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin xmesa_st_framebuffer_validate_textures(stfbi, w, h, 1 << st_attachment); 136100ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin res = xmesa_get_attachment(stfbi, st_attachment); 136200ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 136300ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin if (res) { 136400ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin struct pipe_context* pipe = xmesa_get_context(stfbi); 136500ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin enum pipe_format internal_format = res->format; 136600ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin struct pipe_transfer *tex_xfer; 136700ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin char *map; 136800ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin int line, ximage_stride; 136927de26073b0ab385e57504d77197a33bb7b6c28fBrian Paul XImage *img; 137000ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 137100ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin internal_format = choose_pixel_format(drawable->xm_visual); 137200ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 137300ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin tex_xfer = pipe_get_transfer(pipe, res, 137400ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 0, 0, /* level, layer */ 137500ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin PIPE_TRANSFER_WRITE, 137600ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin x, y, 137700ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin w, h); 137800ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin if (!tex_xfer) 137900ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin return; 138000ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 138100ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin /* Grab the XImage that we want to turn into a texture. */ 138227de26073b0ab385e57504d77197a33bb7b6c28fBrian Paul img = XGetImage(dpy, 138327de26073b0ab385e57504d77197a33bb7b6c28fBrian Paul drawable->ws.drawable, 138427de26073b0ab385e57504d77197a33bb7b6c28fBrian Paul x, y, 138527de26073b0ab385e57504d77197a33bb7b6c28fBrian Paul w, h, 138627de26073b0ab385e57504d77197a33bb7b6c28fBrian Paul AllPlanes, 138727de26073b0ab385e57504d77197a33bb7b6c28fBrian Paul ZPixmap); 138800ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 138900ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin if (!img) { 139000ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin pipe_transfer_destroy(pipe, tex_xfer); 139100ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin return; 139200ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin } 139300ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 139400ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin map = pipe_transfer_map(pipe, tex_xfer); 139500ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 139600ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin if (!map) { 139700ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin pipe_transfer_destroy(pipe, tex_xfer); 139800ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin return; 139900ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin } 140000ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 140100ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin /* The pipe transfer has a pitch rounded up to the nearest 64 pixels. 140200ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin We assume 32 bit pixels. */ 140300ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin ximage_stride = w * 4; 140400ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 140500ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin for (line = 0; line < h; line++) 140600ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin memcpy(&map[line * tex_xfer->stride], 140700ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin &img->data[line * ximage_stride], 140800ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin ximage_stride); 140900ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 141000ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin pipe_transfer_unmap(pipe, tex_xfer); 141100ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 141200ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin pipe_transfer_destroy(pipe, tex_xfer); 141300ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 141400ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin st->teximage(st, 141500ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin ST_TEXTURE_2D, 141600ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 0, /* level */ 141700ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin internal_format, 141800ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin res, 141900ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin FALSE /* no mipmap */); 142000ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin 142100ddc7ea47fdae09ca154d8b3a15c6f9a4926d68Stéphane Marchesin } 1422ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1423ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1424ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1425ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1426ef25c496d52f4f6c45816b64b4c0999321476cd7BrianPUBLIC void 1427153b4d5cdd934812d8c24ef10bb8bbbe852eaf62Keith WhitwellXMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer) 1428ef25c496d52f4f6c45816b64b4c0999321476cd7Brian{ 1429ef25c496d52f4f6c45816b64b4c0999321476cd7Brian} 1430ef25c496d52f4f6c45816b64b4c0999321476cd7Brian 1431576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu 1432576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wuvoid 1433576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I WuXMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask) 1434576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu{ 1435576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu if (dst->st->copy) 1436576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu dst->st->copy(dst->st, src->st, mask); 1437576d9af505bd19ccaac04a68c8744f36f887bd5cChia-I Wu} 1438