blob: 83e2b529a41e73442fd52c066abae21e36a41035 [file] [log] [blame]
Brianef25c492007-10-31 14:19:09 -06001/*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25/**
26 * \file xm_api.c
27 *
28 * All the XMesa* API functions.
29 *
30 *
31 * NOTES:
32 *
33 * The window coordinate system origin (0,0) is in the lower-left corner
34 * of the window. X11's window coordinate origin is in the upper-left
35 * corner of the window. Therefore, most drawing functions in this
36 * file have to flip Y coordinates.
37 *
38 * Define USE_XSHM in the Makefile with -DUSE_XSHM if you want to compile
39 * in support for the MIT Shared Memory extension. If enabled, when you
40 * use an Ximage for the back buffer in double buffered mode, the "swap"
41 * operation will be faster. You must also link with -lXext.
42 *
43 * Byte swapping: If the Mesa host and the X display use a different
44 * byte order then there's some trickiness to be aware of when using
45 * XImages. The byte ordering used for the XImage is that of the X
46 * display, not the Mesa host.
47 * The color-to-pixel encoding for True/DirectColor must be done
48 * according to the display's visual red_mask, green_mask, and blue_mask.
49 * If XPutPixel is used to put a pixel into an XImage then XPutPixel will
50 * do byte swapping if needed. If one wants to directly "poke" the pixel
Brian749d7232007-12-07 07:57:54 -070051 * into the XImage's buffer then the pixel must be byte swapped first.
Brianef25c492007-10-31 14:19:09 -060052 *
53 */
54
55#ifdef __CYGWIN__
56#undef WIN32
57#undef __WIN32__
58#endif
59
60#include "glxheader.h"
61#include "GL/xmesa.h"
62#include "xmesaP.h"
63#include "context.h"
64#include "extensions.h"
65#include "framebuffer.h"
66#include "glthread.h"
67#include "imports.h"
68#include "macros.h"
69#include "renderbuffer.h"
70#include "teximage.h"
Brianef25c492007-10-31 14:19:09 -060071#include "vbo/vbo.h"
Brianef25c492007-10-31 14:19:09 -060072
73#include "state_tracker/st_public.h"
74#include "state_tracker/st_context.h"
Brianef25c492007-10-31 14:19:09 -060075#include "pipe/p_defines.h"
Brian749d7232007-12-07 07:57:54 -070076#include "pipe/p_context.h"
Brianef25c492007-10-31 14:19:09 -060077
Zack Rusinc474f1f2007-12-11 07:19:11 -050078#include "xm_winsys_aub.h"
79
Brianef25c492007-10-31 14:19:09 -060080/**
81 * Global X driver lock
82 */
83_glthread_Mutex _xmesa_lock;
84
85
Zack Rusinc474f1f2007-12-11 07:19:11 -050086int xmesa_mode;
87
Brianef25c492007-10-31 14:19:09 -060088
Brianef25c492007-10-31 14:19:09 -060089/**********************************************************************/
90/***** X Utility Functions *****/
91/**********************************************************************/
92
93
94/**
95 * Return the host's byte order as LSBFirst or MSBFirst ala X.
96 */
97#ifndef XFree86Server
98static int host_byte_order( void )
99{
100 int i = 1;
101 char *cptr = (char *) &i;
102 return (*cptr==1) ? LSBFirst : MSBFirst;
103}
104#endif
105
106
107/**
108 * Check if the X Shared Memory extension is available.
109 * Return: 0 = not available
110 * 1 = shared XImage support available
111 * 2 = shared Pixmap support available also
112 */
113static int check_for_xshm( XMesaDisplay *display )
114{
115#if defined(USE_XSHM) && !defined(XFree86Server)
116 int major, minor, ignore;
117 Bool pixmaps;
118
119 if (XQueryExtension( display, "MIT-SHM", &ignore, &ignore, &ignore )) {
120 if (XShmQueryVersion( display, &major, &minor, &pixmaps )==True) {
121 return (pixmaps==True) ? 2 : 1;
122 }
123 else {
124 return 0;
125 }
126 }
127 else {
128 return 0;
129 }
130#else
131 /* No XSHM support */
132 return 0;
133#endif
134}
135
136
137/**
Brianef25c492007-10-31 14:19:09 -0600138 * Return the true number of bits per pixel for XImages.
139 * For example, if we request a 24-bit deep visual we may actually need/get
140 * 32bpp XImages. This function returns the appropriate bpp.
141 * Input: dpy - the X display
142 * visinfo - desribes the visual to be used for XImages
143 * Return: true number of bits per pixel for XImages
144 */
145static int
146bits_per_pixel( XMesaVisual xmv )
147{
148#ifdef XFree86Server
149 const int depth = xmv->nplanes;
150 int i;
151 assert(depth > 0);
152 for (i = 0; i < screenInfo.numPixmapFormats; i++) {
153 if (screenInfo.formats[i].depth == depth)
154 return screenInfo.formats[i].bitsPerPixel;
155 }
156 return depth; /* should never get here, but this should be safe */
157#else
158 XMesaDisplay *dpy = xmv->display;
159 XMesaVisualInfo visinfo = xmv->visinfo;
160 XMesaImage *img;
161 int bitsPerPixel;
162 /* Create a temporary XImage */
163 img = XCreateImage( dpy, visinfo->visual, visinfo->depth,
164 ZPixmap, 0, /*format, offset*/
165 (char*) MALLOC(8), /*data*/
166 1, 1, /*width, height*/
167 32, /*bitmap_pad*/
168 0 /*bytes_per_line*/
169 );
170 assert(img);
171 /* grab the bits/pixel value */
172 bitsPerPixel = img->bits_per_pixel;
173 /* free the XImage */
174 _mesa_free( img->data );
175 img->data = NULL;
176 XMesaDestroyImage( img );
177 return bitsPerPixel;
178#endif
179}
180
181
182
183/*
184 * Determine if a given X window ID is valid (window exists).
185 * Do this by calling XGetWindowAttributes() for the window and
186 * checking if we catch an X error.
187 * Input: dpy - the display
188 * win - the window to check for existance
189 * Return: GL_TRUE - window exists
190 * GL_FALSE - window doesn't exist
191 */
192#ifndef XFree86Server
193static GLboolean WindowExistsFlag;
194
195static int window_exists_err_handler( XMesaDisplay* dpy, XErrorEvent* xerr )
196{
197 (void) dpy;
198 if (xerr->error_code == BadWindow) {
199 WindowExistsFlag = GL_FALSE;
200 }
201 return 0;
202}
203
204static GLboolean window_exists( XMesaDisplay *dpy, Window win )
205{
206 XWindowAttributes wa;
207 int (*old_handler)( XMesaDisplay*, XErrorEvent* );
208 WindowExistsFlag = GL_TRUE;
209 old_handler = XSetErrorHandler(window_exists_err_handler);
210 XGetWindowAttributes( dpy, win, &wa ); /* dummy request */
211 XSetErrorHandler(old_handler);
212 return WindowExistsFlag;
213}
214
215static Status
216get_drawable_size( XMesaDisplay *dpy, Drawable d, GLuint *width, GLuint *height )
217{
218 Window root;
219 Status stat;
220 int xpos, ypos;
221 unsigned int w, h, bw, depth;
222 stat = XGetGeometry(dpy, d, &root, &xpos, &ypos, &w, &h, &bw, &depth);
223 *width = w;
224 *height = h;
225 return stat;
226}
227#endif
228
229
230/**
231 * Return the size of the window (or pixmap) that corresponds to the
232 * given XMesaBuffer.
233 * \param width returns width in pixels
234 * \param height returns height in pixels
235 */
Brian749d7232007-12-07 07:57:54 -0700236static void
Brianef25c492007-10-31 14:19:09 -0600237xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b,
238 GLuint *width, GLuint *height)
239{
240#ifdef XFree86Server
Brian749d7232007-12-07 07:57:54 -0700241 *width = MIN2(b->drawable->width, MAX_WIDTH);
242 *height = MIN2(b->drawable->height, MAX_HEIGHT);
Brianef25c492007-10-31 14:19:09 -0600243#else
244 Status stat;
245
246 _glthread_LOCK_MUTEX(_xmesa_lock);
247 XSync(b->xm_visual->display, 0); /* added for Chromium */
Brian749d7232007-12-07 07:57:54 -0700248 stat = get_drawable_size(dpy, b->drawable, width, height);
Brianef25c492007-10-31 14:19:09 -0600249 _glthread_UNLOCK_MUTEX(_xmesa_lock);
250
251 if (!stat) {
252 /* probably querying a window that's recently been destroyed */
253 _mesa_warning(NULL, "XGetGeometry failed!\n");
254 *width = *height = 1;
255 }
256#endif
257}
258
259
260
261/**********************************************************************/
262/***** Linked list of XMesaBuffers *****/
263/**********************************************************************/
264
265XMesaBuffer XMesaBufferList = NULL;
266
267
268/**
269 * Allocate a new XMesaBuffer object which corresponds to the given drawable.
270 * Note that XMesaBuffer is derived from GLframebuffer.
271 * The new XMesaBuffer will not have any size (Width=Height=0).
272 *
273 * \param d the corresponding X drawable (window or pixmap)
274 * \param type either WINDOW, PIXMAP or PBUFFER, describing d
275 * \param vis the buffer's visual
276 * \param cmap the window's colormap, if known.
277 * \return new XMesaBuffer or NULL if any problem
278 */
279static XMesaBuffer
280create_xmesa_buffer(XMesaDrawable d, BufferType type,
281 XMesaVisual vis, XMesaColormap cmap)
282{
283 XMesaBuffer b;
Briane39f1b42007-11-05 15:59:55 -0700284 GLframebuffer *fb;
Brianef25c492007-10-31 14:19:09 -0600285
286 ASSERT(type == WINDOW || type == PIXMAP || type == PBUFFER);
287
288 b = (XMesaBuffer) CALLOC_STRUCT(xmesa_buffer);
289 if (!b)
290 return NULL;
291
Brian749d7232007-12-07 07:57:54 -0700292 b->drawable = d;
293
Brianef25c492007-10-31 14:19:09 -0600294 b->xm_visual = vis;
295 b->type = type;
296 b->cmap = cmap;
297
Briane39f1b42007-11-05 15:59:55 -0700298 /*
299 * Create framebuffer, but we'll plug in our own renderbuffers below.
300 */
Brian749d7232007-12-07 07:57:54 -0700301 b->stfb = st_create_framebuffer(&vis->mesa_visual, GL_TRUE, (void *) b);
Briane39f1b42007-11-05 15:59:55 -0700302 fb = &b->stfb->Base;
303
Brianef25c492007-10-31 14:19:09 -0600304 /*
Brian749d7232007-12-07 07:57:54 -0700305 * Create scratch XImage for xmesa_display_surface()
Brianb7611772007-10-31 19:00:23 -0600306 */
Brian749d7232007-12-07 07:57:54 -0700307 b->tempImage = XCreateImage(vis->display,
308 vis->visinfo->visual,
309 vis->visinfo->depth,
310 ZPixmap, 0, /* format, offset */
311 NULL, /* data */
312 0, 0, /* size */
313 32, /* bitmap_pad */
314 0); /* bytes_per_line */
Brianef25c492007-10-31 14:19:09 -0600315
316 /* GLX_EXT_texture_from_pixmap */
317 b->TextureTarget = 0;
318 b->TextureFormat = GLX_TEXTURE_FORMAT_NONE_EXT;
319 b->TextureMipmap = 0;
320
321 /* insert buffer into linked list */
322 b->Next = XMesaBufferList;
323 XMesaBufferList = b;
324
325 return b;
326}
327
328
329/**
330 * Find an XMesaBuffer by matching X display and colormap but NOT matching
331 * the notThis buffer.
332 */
333XMesaBuffer
334xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis)
335{
336 XMesaBuffer b;
Brian749d7232007-12-07 07:57:54 -0700337 for (b = XMesaBufferList; b; b = b->Next) {
338 if (b->xm_visual->display == dpy &&
339 b->cmap == cmap &&
340 b != notThis) {
Brianef25c492007-10-31 14:19:09 -0600341 return b;
342 }
343 }
344 return NULL;
345}
346
347
348/**
349 * Remove buffer from linked list, delete if no longer referenced.
350 */
351static void
352xmesa_free_buffer(XMesaBuffer buffer)
353{
354 XMesaBuffer prev = NULL, b;
355
356 for (b = XMesaBufferList; b; b = b->Next) {
357 if (b == buffer) {
Briane39f1b42007-11-05 15:59:55 -0700358 struct gl_framebuffer *fb = &buffer->stfb->Base;
Brianef25c492007-10-31 14:19:09 -0600359
360 /* unlink buffer from list */
361 if (prev)
362 prev->Next = buffer->Next;
363 else
364 XMesaBufferList = buffer->Next;
365
366 /* mark as delete pending */
367 fb->DeletePending = GL_TRUE;
368
369 /* Since the X window for the XMesaBuffer is going away, we don't
370 * want to dereference this pointer in the future.
371 */
Brian749d7232007-12-07 07:57:54 -0700372 b->drawable = 0;
373
374 buffer->tempImage->data = NULL;
375 XDestroyImage(buffer->tempImage);
Brianef25c492007-10-31 14:19:09 -0600376
377 /* Unreference. If count = zero we'll really delete the buffer */
378 _mesa_unreference_framebuffer(&fb);
379
380 return;
381 }
382 /* continue search */
383 prev = b;
384 }
385 /* buffer not found in XMesaBufferList */
386 _mesa_problem(NULL,"xmesa_free_buffer() - buffer not found\n");
387}
388
389
Brianef25c492007-10-31 14:19:09 -0600390
391/**********************************************************************/
392/***** Misc Private Functions *****/
393/**********************************************************************/
394
395
396/**
Brian749d7232007-12-07 07:57:54 -0700397 * Choose the pixel format for the given visual.
398 * This will tell the gallium driver how to pack pixel data into
399 * drawing surfaces.
Brianef25c492007-10-31 14:19:09 -0600400 */
Brian749d7232007-12-07 07:57:54 -0700401static GLuint
402choose_pixel_format(XMesaVisual v)
Brianef25c492007-10-31 14:19:09 -0600403{
Brian749d7232007-12-07 07:57:54 -0700404 if ( GET_REDMASK(v) == 0x0000ff
405 && GET_GREENMASK(v) == 0x00ff00
406 && GET_BLUEMASK(v) == 0xff0000
Brian749d7232007-12-07 07:57:54 -0700407 && v->BitsPerPixel == 32) {
Brian0d1669f2007-12-07 08:24:56 -0700408 if (CHECK_BYTE_ORDER(v)) {
409 /* no byteswapping needed */
410 return 0 /* PIXEL_FORMAT_U_A8_B8_G8_R8 */;
411 }
412 else {
Brian2067eed2007-12-07 16:01:31 -0700413 return PIPE_FORMAT_R8G8B8A8_UNORM;
Brian0d1669f2007-12-07 08:24:56 -0700414 }
Brianef25c492007-10-31 14:19:09 -0600415 }
Brian749d7232007-12-07 07:57:54 -0700416 else if ( GET_REDMASK(v) == 0xff0000
417 && GET_GREENMASK(v) == 0x00ff00
418 && GET_BLUEMASK(v) == 0x0000ff
Brian0d1669f2007-12-07 08:24:56 -0700419 && v->BitsPerPixel == 32) {
420 if (CHECK_BYTE_ORDER(v)) {
421 /* no byteswapping needed */
Brian2067eed2007-12-07 16:01:31 -0700422 return PIPE_FORMAT_A8R8G8B8_UNORM;
Brianef25c492007-10-31 14:19:09 -0600423 }
Brian0d1669f2007-12-07 08:24:56 -0700424 else {
Brian2067eed2007-12-07 16:01:31 -0700425 return PIPE_FORMAT_B8G8R8A8_UNORM;
Brianef25c492007-10-31 14:19:09 -0600426 }
427 }
Brian749d7232007-12-07 07:57:54 -0700428 else if ( GET_REDMASK(v) == 0xf800
429 && GET_GREENMASK(v) == 0x07e0
430 && GET_BLUEMASK(v) == 0x001f
431 && CHECK_BYTE_ORDER(v)
432 && v->BitsPerPixel == 16) {
Brianef25c492007-10-31 14:19:09 -0600433 /* 5-6-5 RGB */
Brian2067eed2007-12-07 16:01:31 -0700434 return PIPE_FORMAT_R5G6B5_UNORM;
Brianef25c492007-10-31 14:19:09 -0600435 }
Brian749d7232007-12-07 07:57:54 -0700436
437 assert(0);
438 return 0;
Brianef25c492007-10-31 14:19:09 -0600439}
440
441
Brianef25c492007-10-31 14:19:09 -0600442/**
443 * When a context is bound for the first time, we can finally finish
444 * initializing the context's visual and buffer information.
445 * \param v the XMesaVisual to initialize
446 * \param b the XMesaBuffer to initialize (may be NULL)
447 * \param rgb_flag TRUE = RGBA mode, FALSE = color index mode
448 * \param window the window/pixmap we're rendering into
449 * \param cmap the colormap associated with the window/pixmap
450 * \return GL_TRUE=success, GL_FALSE=failure
451 */
452static GLboolean
453initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b,
454 GLboolean rgb_flag, XMesaDrawable window,
455 XMesaColormap cmap)
456{
Brianef25c492007-10-31 14:19:09 -0600457#ifdef XFree86Server
Brian749d7232007-12-07 07:57:54 -0700458 int client = (window) ? CLIENT_ID(window->id) : 0;
Brianef25c492007-10-31 14:19:09 -0600459#endif
460
461 ASSERT(!b || b->xm_visual == v);
462
463 /* Save true bits/pixel */
464 v->BitsPerPixel = bits_per_pixel(v);
465 assert(v->BitsPerPixel > 0);
466
467 if (rgb_flag == GL_FALSE) {
Brian749d7232007-12-07 07:57:54 -0700468 /* COLOR-INDEXED WINDOW: not supported*/
469 return GL_FALSE;
Brianef25c492007-10-31 14:19:09 -0600470 }
471 else {
472 /* RGB WINDOW:
473 * We support RGB rendering into almost any kind of visual.
474 */
475 const int xclass = v->mesa_visual.visualType;
Brian749d7232007-12-07 07:57:54 -0700476 if (xclass != GLX_TRUE_COLOR && xclass == !GLX_DIRECT_COLOR) {
477 _mesa_warning(NULL,
478 "XMesa: RGB mode rendering not supported in given visual.\n");
Brianef25c492007-10-31 14:19:09 -0600479 return GL_FALSE;
480 }
481 v->mesa_visual.indexBits = 0;
Brianef25c492007-10-31 14:19:09 -0600482 }
483
Brianef25c492007-10-31 14:19:09 -0600484 /*
485 * If MESA_INFO env var is set print out some debugging info
486 * which can help Brian figure out what's going on when a user
487 * reports bugs.
488 */
489 if (_mesa_getenv("MESA_INFO")) {
490 _mesa_printf("X/Mesa visual = %p\n", (void *) v);
Brianef25c492007-10-31 14:19:09 -0600491 _mesa_printf("X/Mesa level = %d\n", v->mesa_visual.level);
492 _mesa_printf("X/Mesa depth = %d\n", GET_VISUAL_DEPTH(v));
493 _mesa_printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel);
494 }
495
496 if (b && window) {
Brianef25c492007-10-31 14:19:09 -0600497 /* these should have been set in create_xmesa_buffer */
Brian749d7232007-12-07 07:57:54 -0700498 ASSERT(b->drawable == window);
Brianef25c492007-10-31 14:19:09 -0600499
500 /* Setup for single/double buffering */
501 if (v->mesa_visual.doubleBufferMode) {
502 /* Double buffered */
503 b->shm = check_for_xshm( v->display );
504 }
505
Brian749d7232007-12-07 07:57:54 -0700506 /* X11 graphics context */
Brianef25c492007-10-31 14:19:09 -0600507#ifdef XFree86Server
508 b->gc = CreateScratchGC(v->display, window->depth);
509#else
510 b->gc = XCreateGC( v->display, window, 0, NULL );
511#endif
512 XMesaSetFunction( v->display, b->gc, GXcopy );
Brianef25c492007-10-31 14:19:09 -0600513 }
514
515 return GL_TRUE;
516}
517
518
519
Brianef25c492007-10-31 14:19:09 -0600520#define NUM_VISUAL_TYPES 6
521
522/**
523 * Convert an X visual type to a GLX visual type.
524 *
525 * \param visualType X visual type (i.e., \c TrueColor, \c StaticGray, etc.)
526 * to be converted.
527 * \return If \c visualType is a valid X visual type, a GLX visual type will
528 * be returned. Otherwise \c GLX_NONE will be returned.
529 *
530 * \note
531 * This code was lifted directly from lib/GL/glx/glcontextmodes.c in the
532 * DRI CVS tree.
533 */
534static GLint
535xmesa_convert_from_x_visual_type( int visualType )
536{
537 static const int glx_visual_types[ NUM_VISUAL_TYPES ] = {
538 GLX_STATIC_GRAY, GLX_GRAY_SCALE,
539 GLX_STATIC_COLOR, GLX_PSEUDO_COLOR,
540 GLX_TRUE_COLOR, GLX_DIRECT_COLOR
541 };
542
543 return ( (unsigned) visualType < NUM_VISUAL_TYPES )
544 ? glx_visual_types[ visualType ] : GLX_NONE;
545}
546
547
548/**********************************************************************/
549/***** Public Functions *****/
550/**********************************************************************/
551
552
553/*
554 * Create a new X/Mesa visual.
555 * Input: display - X11 display
556 * visinfo - an XVisualInfo pointer
557 * rgb_flag - GL_TRUE = RGB mode,
558 * GL_FALSE = color index mode
559 * alpha_flag - alpha buffer requested?
560 * db_flag - GL_TRUE = double-buffered,
561 * GL_FALSE = single buffered
562 * stereo_flag - stereo visual?
563 * ximage_flag - GL_TRUE = use an XImage for back buffer,
564 * GL_FALSE = use an off-screen pixmap for back buffer
565 * depth_size - requested bits/depth values, or zero
566 * stencil_size - requested bits/stencil values, or zero
567 * accum_red_size - requested bits/red accum values, or zero
568 * accum_green_size - requested bits/green accum values, or zero
569 * accum_blue_size - requested bits/blue accum values, or zero
570 * accum_alpha_size - requested bits/alpha accum values, or zero
571 * num_samples - number of samples/pixel if multisampling, or zero
572 * level - visual level, usually 0
573 * visualCaveat - ala the GLX extension, usually GLX_NONE
574 * Return; a new XMesaVisual or 0 if error.
575 */
576PUBLIC
577XMesaVisual XMesaCreateVisual( XMesaDisplay *display,
578 XMesaVisualInfo visinfo,
579 GLboolean rgb_flag,
580 GLboolean alpha_flag,
581 GLboolean db_flag,
582 GLboolean stereo_flag,
583 GLboolean ximage_flag,
584 GLint depth_size,
585 GLint stencil_size,
586 GLint accum_red_size,
587 GLint accum_green_size,
588 GLint accum_blue_size,
589 GLint accum_alpha_size,
590 GLint num_samples,
591 GLint level,
592 GLint visualCaveat )
593{
Brianef25c492007-10-31 14:19:09 -0600594 XMesaVisual v;
595 GLint red_bits, green_bits, blue_bits, alpha_bits;
596
597#ifndef XFree86Server
598 /* For debugging only */
599 if (_mesa_getenv("MESA_XSYNC")) {
600 /* This makes debugging X easier.
601 * In your debugger, set a breakpoint on _XError to stop when an
602 * X protocol error is generated.
603 */
604 XSynchronize( display, 1 );
605 }
606#endif
607
608 v = (XMesaVisual) CALLOC_STRUCT(xmesa_visual);
609 if (!v) {
610 return NULL;
611 }
612
613 v->display = display;
614
615 /* Save a copy of the XVisualInfo struct because the user may X_mesa_free()
616 * the struct but we may need some of the information contained in it
617 * at a later time.
618 */
619#ifndef XFree86Server
620 v->visinfo = (XVisualInfo *) MALLOC(sizeof(*visinfo));
621 if(!v->visinfo) {
622 _mesa_free(v);
623 return NULL;
624 }
625 MEMCPY(v->visinfo, visinfo, sizeof(*visinfo));
626#endif
627
Brianef25c492007-10-31 14:19:09 -0600628 v->ximage_flag = ximage_flag;
629
630#ifdef XFree86Server
631 /* We could calculate these values by ourselves. nplanes is either the sum
632 * of the red, green, and blue bits or the number index bits.
633 * ColormapEntries is either (1U << index_bits) or
634 * (1U << max(redBits, greenBits, blueBits)).
635 */
636 assert(visinfo->nplanes > 0);
637 v->nplanes = visinfo->nplanes;
638 v->ColormapEntries = visinfo->ColormapEntries;
639
640 v->mesa_visual.redMask = visinfo->redMask;
641 v->mesa_visual.greenMask = visinfo->greenMask;
642 v->mesa_visual.blueMask = visinfo->blueMask;
643 v->mesa_visual.visualID = visinfo->vid;
644 v->mesa_visual.screen = 0; /* FIXME: What should be done here? */
645#else
646 v->mesa_visual.redMask = visinfo->red_mask;
647 v->mesa_visual.greenMask = visinfo->green_mask;
648 v->mesa_visual.blueMask = visinfo->blue_mask;
649 v->mesa_visual.visualID = visinfo->visualid;
650 v->mesa_visual.screen = visinfo->screen;
651#endif
652
653#if defined(XFree86Server) || !(defined(__cplusplus) || defined(c_plusplus))
654 v->mesa_visual.visualType = xmesa_convert_from_x_visual_type(visinfo->class);
655#else
656 v->mesa_visual.visualType = xmesa_convert_from_x_visual_type(visinfo->c_class);
657#endif
658
659 v->mesa_visual.visualRating = visualCaveat;
660
661 if (alpha_flag)
662 v->mesa_visual.alphaBits = 8;
663
664 (void) initialize_visual_and_buffer( v, NULL, rgb_flag, 0, 0 );
665
666 {
667 const int xclass = v->mesa_visual.visualType;
668 if (xclass == GLX_TRUE_COLOR || xclass == GLX_DIRECT_COLOR) {
669 red_bits = _mesa_bitcount(GET_REDMASK(v));
670 green_bits = _mesa_bitcount(GET_GREENMASK(v));
671 blue_bits = _mesa_bitcount(GET_BLUEMASK(v));
672 }
673 else {
674 /* this is an approximation */
675 int depth;
676 depth = GET_VISUAL_DEPTH(v);
677 red_bits = depth / 3;
678 depth -= red_bits;
679 green_bits = depth / 2;
680 depth -= green_bits;
681 blue_bits = depth;
682 alpha_bits = 0;
683 assert( red_bits + green_bits + blue_bits == GET_VISUAL_DEPTH(v) );
684 }
685 alpha_bits = v->mesa_visual.alphaBits;
686 }
687
688 _mesa_initialize_visual( &v->mesa_visual,
689 rgb_flag, db_flag, stereo_flag,
690 red_bits, green_bits,
691 blue_bits, alpha_bits,
692 v->mesa_visual.indexBits,
693 depth_size,
694 stencil_size,
695 accum_red_size, accum_green_size,
696 accum_blue_size, accum_alpha_size,
697 0 );
698
699 /* XXX minor hack */
700 v->mesa_visual.level = level;
701 return v;
702}
703
704
705PUBLIC
706void XMesaDestroyVisual( XMesaVisual v )
707{
708#ifndef XFree86Server
709 _mesa_free(v->visinfo);
710#endif
711 _mesa_free(v);
712}
713
714
715
716/**
717 * Create a new XMesaContext.
718 * \param v the XMesaVisual
719 * \param share_list another XMesaContext with which to share display
720 * lists or NULL if no sharing is wanted.
721 * \return an XMesaContext or NULL if error.
722 */
723PUBLIC
724XMesaContext XMesaCreateContext( XMesaVisual v, XMesaContext share_list )
725{
726 static GLboolean firstTime = GL_TRUE;
Briane39f1b42007-11-05 15:59:55 -0700727 struct pipe_context *pipe;
Brianef25c492007-10-31 14:19:09 -0600728 XMesaContext c;
729 GLcontext *mesaCtx;
Brian749d7232007-12-07 07:57:54 -0700730 uint pf;
Briane39f1b42007-11-05 15:59:55 -0700731
Brianef25c492007-10-31 14:19:09 -0600732 if (firstTime) {
733 _glthread_INIT_MUTEX(_xmesa_lock);
734 firstTime = GL_FALSE;
735 }
736
737 /* Note: the XMesaContext contains a Mesa GLcontext struct (inheritance) */
738 c = (XMesaContext) CALLOC_STRUCT(xmesa_context);
739 if (!c)
740 return NULL;
741
Brian749d7232007-12-07 07:57:54 -0700742 pf = choose_pixel_format(v);
Brian0d1669f2007-12-07 08:24:56 -0700743 assert(pf);
Brian749d7232007-12-07 07:57:54 -0700744
Zack Rusinc474f1f2007-12-11 07:19:11 -0500745 if (!getenv("XM_AUB")) {
746 xmesa_mode = XMESA_SOFTPIPE;
747 pipe = xmesa_create_pipe_context( c, pf );
748 }
749 else {
750 xmesa_mode = XMESA_AUB;
751 pipe = xmesa_create_i965simple( xmesa_get_pipe_winsys_aub() );
752 }
Brianef25c492007-10-31 14:19:09 -0600753
Brian91564ee2007-11-05 16:15:43 -0700754 c->st = st_create_context(pipe, &v->mesa_visual,
755 share_list ? share_list->st : NULL);
Briane39f1b42007-11-05 15:59:55 -0700756 mesaCtx = c->st->ctx;
757 c->st->ctx->DriverCtx = c;
Brianef25c492007-10-31 14:19:09 -0600758
Briane39f1b42007-11-05 15:59:55 -0700759#if 00
Brianef25c492007-10-31 14:19:09 -0600760 _mesa_enable_sw_extensions(mesaCtx);
761 _mesa_enable_1_3_extensions(mesaCtx);
762 _mesa_enable_1_4_extensions(mesaCtx);
763 _mesa_enable_1_5_extensions(mesaCtx);
764 _mesa_enable_2_0_extensions(mesaCtx);
Briane39f1b42007-11-05 15:59:55 -0700765#endif
Brianef25c492007-10-31 14:19:09 -0600766
767#ifdef XFree86Server
768 /* If we're running in the X server, do bounds checking to prevent
769 * segfaults and server crashes!
770 */
771 mesaCtx->Const.CheckArrayBounds = GL_TRUE;
772#endif
773
774 /* finish up xmesa context initializations */
Brianef25c492007-10-31 14:19:09 -0600775 c->xm_visual = v;
776 c->xm_buffer = NULL; /* set later by XMesaMakeCurrent */
Brianef25c492007-10-31 14:19:09 -0600777
Brian749d7232007-12-07 07:57:54 -0700778 c->st->haveFramebufferSurfaces = GL_TRUE;
Brianef25c492007-10-31 14:19:09 -0600779
780 return c;
781}
782
783
784
785PUBLIC
786void XMesaDestroyContext( XMesaContext c )
787{
Brian91564ee2007-11-05 16:15:43 -0700788 st_destroy_context(c->st);
Briane39f1b42007-11-05 15:59:55 -0700789 _mesa_free(c);
Brianef25c492007-10-31 14:19:09 -0600790}
791
792
793
794/**
795 * Private function for creating an XMesaBuffer which corresponds to an
796 * X window or pixmap.
797 * \param v the window's XMesaVisual
798 * \param w the window we're wrapping
799 * \return new XMesaBuffer or NULL if error
800 */
801PUBLIC XMesaBuffer
802XMesaCreateWindowBuffer(XMesaVisual v, XMesaWindow w)
803{
804#ifndef XFree86Server
805 XWindowAttributes attr;
806#endif
807 XMesaBuffer b;
808 XMesaColormap cmap;
809 int depth;
810
811 assert(v);
812 assert(w);
813
814 /* Check that window depth matches visual depth */
815#ifdef XFree86Server
816 depth = ((XMesaDrawable)w)->depth;
817#else
818 XGetWindowAttributes( v->display, w, &attr );
819 depth = attr.depth;
820#endif
821 if (GET_VISUAL_DEPTH(v) != depth) {
822 _mesa_warning(NULL, "XMesaCreateWindowBuffer: depth mismatch between visual (%d) and window (%d)!\n",
823 GET_VISUAL_DEPTH(v), depth);
824 return NULL;
825 }
826
827 /* Find colormap */
828#ifdef XFree86Server
829 cmap = (ColormapPtr)LookupIDByType(wColormap(w), RT_COLORMAP);
830#else
831 if (attr.colormap) {
832 cmap = attr.colormap;
833 }
834 else {
835 _mesa_warning(NULL, "Window %u has no colormap!\n", (unsigned int) w);
836 /* this is weird, a window w/out a colormap!? */
837 /* OK, let's just allocate a new one and hope for the best */
838 cmap = XCreateColormap(v->display, w, attr.visual, AllocNone);
839 }
840#endif
841
842 b = create_xmesa_buffer((XMesaDrawable) w, WINDOW, v, cmap);
843 if (!b)
844 return NULL;
845
846 if (!initialize_visual_and_buffer( v, b, v->mesa_visual.rgbMode,
847 (XMesaDrawable) w, cmap )) {
848 xmesa_free_buffer(b);
849 return NULL;
850 }
851
852 return b;
853}
854
855
856
857/**
858 * Create a new XMesaBuffer from an X pixmap.
859 *
860 * \param v the XMesaVisual
861 * \param p the pixmap
862 * \param cmap the colormap, may be 0 if using a \c GLX_TRUE_COLOR or
863 * \c GLX_DIRECT_COLOR visual for the pixmap
864 * \returns new XMesaBuffer or NULL if error
865 */
866PUBLIC XMesaBuffer
867XMesaCreatePixmapBuffer(XMesaVisual v, XMesaPixmap p, XMesaColormap cmap)
868{
869 XMesaBuffer b;
870
871 assert(v);
872
873 b = create_xmesa_buffer((XMesaDrawable) p, PIXMAP, v, cmap);
874 if (!b)
875 return NULL;
876
877 if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode,
878 (XMesaDrawable) p, cmap)) {
879 xmesa_free_buffer(b);
880 return NULL;
881 }
882
883 return b;
884}
885
886
887/**
888 * For GLX_EXT_texture_from_pixmap
889 */
890XMesaBuffer
891XMesaCreatePixmapTextureBuffer(XMesaVisual v, XMesaPixmap p,
892 XMesaColormap cmap,
893 int format, int target, int mipmap)
894{
895 GET_CURRENT_CONTEXT(ctx);
896 XMesaBuffer b;
897 GLuint width, height;
898
899 assert(v);
900
901 b = create_xmesa_buffer((XMesaDrawable) p, PIXMAP, v, cmap);
902 if (!b)
903 return NULL;
904
905 /* get pixmap size, update framebuffer/renderbuffer dims */
906 xmesa_get_window_size(v->display, b, &width, &height);
Briane39f1b42007-11-05 15:59:55 -0700907 _mesa_resize_framebuffer(NULL, &(b->stfb->Base), width, height);
Brianef25c492007-10-31 14:19:09 -0600908
909 if (target == 0) {
910 /* examine dims */
911 if (ctx->Extensions.ARB_texture_non_power_of_two) {
912 target = GLX_TEXTURE_2D_EXT;
913 }
914 else if ( _mesa_bitcount(width) == 1
915 && _mesa_bitcount(height) == 1) {
916 /* power of two size */
917 if (height == 1) {
918 target = GLX_TEXTURE_1D_EXT;
919 }
920 else {
921 target = GLX_TEXTURE_2D_EXT;
922 }
923 }
924 else if (ctx->Extensions.NV_texture_rectangle) {
925 target = GLX_TEXTURE_RECTANGLE_EXT;
926 }
927 else {
928 /* non power of two textures not supported */
929 XMesaDestroyBuffer(b);
930 return 0;
931 }
932 }
933
934 b->TextureTarget = target;
935 b->TextureFormat = format;
936 b->TextureMipmap = mipmap;
937
938 if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode,
939 (XMesaDrawable) p, cmap)) {
940 xmesa_free_buffer(b);
941 return NULL;
942 }
943
944 return b;
945}
946
947
948
949XMesaBuffer
950XMesaCreatePBuffer(XMesaVisual v, XMesaColormap cmap,
951 unsigned int width, unsigned int height)
952{
953#ifndef XFree86Server
954 XMesaWindow root;
955 XMesaDrawable drawable; /* X Pixmap Drawable */
956 XMesaBuffer b;
957
958 /* allocate pixmap for front buffer */
959 root = RootWindow( v->display, v->visinfo->screen );
960 drawable = XCreatePixmap(v->display, root, width, height,
961 v->visinfo->depth);
962 if (!drawable)
963 return NULL;
964
965 b = create_xmesa_buffer(drawable, PBUFFER, v, cmap);
966 if (!b)
967 return NULL;
968
969 if (!initialize_visual_and_buffer(v, b, v->mesa_visual.rgbMode,
970 drawable, cmap)) {
971 xmesa_free_buffer(b);
972 return NULL;
973 }
974
975 return b;
976#else
977 return 0;
978#endif
979}
980
981
982
983/*
984 * Deallocate an XMesaBuffer structure and all related info.
985 */
986PUBLIC void
987XMesaDestroyBuffer(XMesaBuffer b)
988{
989 xmesa_free_buffer(b);
990}
991
992
993/**
994 * Query the current window size and update the corresponding GLframebuffer
995 * and all attached renderbuffers.
996 * Called when:
997 * 1. the first time a buffer is bound to a context.
Brian749d7232007-12-07 07:57:54 -0700998 * 2. from the XMesaResizeBuffers() API function.
999 * 3. SwapBuffers. XXX probabaly from xm_flush_frontbuffer() too...
Brianef25c492007-10-31 14:19:09 -06001000 * Note: it's possible (and legal) for xmctx to be NULL. That can happen
1001 * when resizing a buffer when no rendering context is bound.
1002 */
1003void
1004xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer)
1005{
1006 GLuint width, height;
Brian749d7232007-12-07 07:57:54 -07001007 xmesa_get_window_size(drawBuffer->xm_visual->display, drawBuffer, &width, &height);
Briane39f1b42007-11-05 15:59:55 -07001008 st_resize_framebuffer(drawBuffer->stfb, width, height);
Brianef25c492007-10-31 14:19:09 -06001009}
1010
1011
1012/*
1013 * Bind buffer b to context c and make c the current rendering context.
1014 */
1015GLboolean XMesaMakeCurrent( XMesaContext c, XMesaBuffer b )
1016{
1017 return XMesaMakeCurrent2( c, b, b );
1018}
1019
1020
1021/*
1022 * Bind buffer b to context c and make c the current rendering context.
1023 */
1024PUBLIC
1025GLboolean XMesaMakeCurrent2( XMesaContext c, XMesaBuffer drawBuffer,
1026 XMesaBuffer readBuffer )
1027{
1028 if (c) {
1029 if (!drawBuffer || !readBuffer)
1030 return GL_FALSE; /* must specify buffers! */
1031
Briane39f1b42007-11-05 15:59:55 -07001032#if 0
1033 /* XXX restore this optimization */
Brianef25c492007-10-31 14:19:09 -06001034 if (&(c->mesa) == _mesa_get_current_context()
1035 && c->mesa.DrawBuffer == &drawBuffer->mesa_buffer
1036 && c->mesa.ReadBuffer == &readBuffer->mesa_buffer
Brian749d7232007-12-07 07:57:54 -07001037 && xmesa_buffer(c->mesa.DrawBuffer)->wasCurrent) {
Brianef25c492007-10-31 14:19:09 -06001038 /* same context and buffer, do nothing */
1039 return GL_TRUE;
1040 }
Briane39f1b42007-11-05 15:59:55 -07001041#endif
Brianef25c492007-10-31 14:19:09 -06001042
1043 c->xm_buffer = drawBuffer;
1044
Brianef25c492007-10-31 14:19:09 -06001045 /* Call this periodically to detect when the user has begun using
1046 * GL rendering from multiple threads.
1047 */
1048 _glapi_check_multithread();
1049
1050 xmesa_check_and_update_buffer_size(c, drawBuffer);
1051 if (readBuffer != drawBuffer)
1052 xmesa_check_and_update_buffer_size(c, readBuffer);
1053
Briane39f1b42007-11-05 15:59:55 -07001054 st_make_current(c->st, drawBuffer->stfb, readBuffer->stfb);
Brianef25c492007-10-31 14:19:09 -06001055
Brianef25c492007-10-31 14:19:09 -06001056 /* Solution to Stephane Rehel's problem with glXReleaseBuffersMESA(): */
1057 drawBuffer->wasCurrent = GL_TRUE;
1058 }
1059 else {
1060 /* Detach */
Briane39f1b42007-11-05 15:59:55 -07001061 st_make_current( NULL, NULL, NULL );
Brianef25c492007-10-31 14:19:09 -06001062 }
1063 return GL_TRUE;
1064}
1065
1066
1067/*
1068 * Unbind the context c from its buffer.
1069 */
1070GLboolean XMesaUnbindContext( XMesaContext c )
1071{
1072 /* A no-op for XFree86 integration purposes */
1073 return GL_TRUE;
1074}
1075
1076
1077XMesaContext XMesaGetCurrentContext( void )
1078{
1079 GET_CURRENT_CONTEXT(ctx);
1080 if (ctx) {
Brian749d7232007-12-07 07:57:54 -07001081 XMesaContext xmesa = xmesa_context(ctx);
Brianef25c492007-10-31 14:19:09 -06001082 return xmesa;
1083 }
1084 else {
1085 return 0;
1086 }
1087}
1088
1089
1090XMesaBuffer XMesaGetCurrentBuffer( void )
1091{
1092 GET_CURRENT_CONTEXT(ctx);
1093 if (ctx) {
Brian749d7232007-12-07 07:57:54 -07001094 XMesaBuffer xmbuf = xmesa_buffer(ctx->DrawBuffer);
Brianef25c492007-10-31 14:19:09 -06001095 return xmbuf;
1096 }
1097 else {
1098 return 0;
1099 }
1100}
1101
1102
1103/* New in Mesa 3.1 */
1104XMesaBuffer XMesaGetCurrentReadBuffer( void )
1105{
1106 GET_CURRENT_CONTEXT(ctx);
1107 if (ctx) {
Brian749d7232007-12-07 07:57:54 -07001108 return xmesa_buffer(ctx->ReadBuffer);
Brianef25c492007-10-31 14:19:09 -06001109 }
1110 else {
1111 return 0;
1112 }
1113}
1114
1115
1116#ifdef XFree86Server
1117PUBLIC
1118GLboolean XMesaForceCurrent(XMesaContext c)
1119{
1120 if (c) {
1121 _glapi_set_dispatch(c->mesa.CurrentDispatch);
1122
1123 if (&(c->mesa) != _mesa_get_current_context()) {
1124 _mesa_make_current(&c->mesa, c->mesa.DrawBuffer, c->mesa.ReadBuffer);
1125 }
1126 }
1127 else {
1128 _mesa_make_current(NULL, NULL, NULL);
1129 }
1130 return GL_TRUE;
1131}
1132
1133
1134PUBLIC
1135GLboolean XMesaLoseCurrent(XMesaContext c)
1136{
1137 (void) c;
1138 _mesa_make_current(NULL, NULL, NULL);
1139 return GL_TRUE;
1140}
1141
1142
1143PUBLIC
1144GLboolean XMesaCopyContext( XMesaContext xm_src, XMesaContext xm_dst, GLuint mask )
1145{
1146 _mesa_copy_context(&xm_src->mesa, &xm_dst->mesa, mask);
1147 return GL_TRUE;
1148}
1149#endif /* XFree86Server */
1150
1151
1152#ifndef FX
1153GLboolean XMesaSetFXmode( GLint mode )
1154{
1155 (void) mode;
1156 return GL_FALSE;
1157}
1158#endif
1159
1160
1161
1162/*
1163 * Copy the back buffer to the front buffer. If there's no back buffer
1164 * this is a no-op.
1165 */
1166PUBLIC
1167void XMesaSwapBuffers( XMesaBuffer b )
1168{
Brian749d7232007-12-07 07:57:54 -07001169 struct pipe_surface *surf;
Brianef25c492007-10-31 14:19:09 -06001170
1171 /* If we're swapping the buffer associated with the current context
1172 * we have to flush any pending rendering commands first.
1173 */
Briane39f1b42007-11-05 15:59:55 -07001174 st_notify_swapbuffers(b->stfb);
Brianef25c492007-10-31 14:19:09 -06001175
Brian749d7232007-12-07 07:57:54 -07001176 surf = st_get_framebuffer_surface(b->stfb, ST_SURFACE_BACK_LEFT);
1177 if (surf) {
Zack Rusinc474f1f2007-12-11 07:19:11 -05001178 if (xmesa_mode == XMESA_AUB)
1179 xmesa_display_aub( surf );
1180 else
1181 xmesa_display_surface(b, surf);
Brianef25c492007-10-31 14:19:09 -06001182 }
Brian749d7232007-12-07 07:57:54 -07001183
1184 xmesa_check_and_update_buffer_size(NULL, b);
Brianef25c492007-10-31 14:19:09 -06001185}
1186
1187
1188
1189/*
1190 * Copy sub-region of back buffer to front buffer
1191 */
1192void XMesaCopySubBuffer( XMesaBuffer b, int x, int y, int width, int height )
1193{
Brian749d7232007-12-07 07:57:54 -07001194 struct pipe_surface *surf_front
1195 = st_get_framebuffer_surface(b->stfb, ST_SURFACE_FRONT_LEFT);
1196 struct pipe_surface *surf_back
1197 = st_get_framebuffer_surface(b->stfb, ST_SURFACE_BACK_LEFT);
1198 struct pipe_context *pipe = NULL; /* XXX fix */
Brianef25c492007-10-31 14:19:09 -06001199
Brian749d7232007-12-07 07:57:54 -07001200 if (!surf_front || !surf_back)
1201 return;
Briane39f1b42007-11-05 15:59:55 -07001202
Brian749d7232007-12-07 07:57:54 -07001203 pipe->surface_copy(pipe,
1204 surf_front, x, y, /* dest */
1205 surf_back, x, y, /* src */
1206 width, height);
Brianef25c492007-10-31 14:19:09 -06001207}
1208
1209
Brianef25c492007-10-31 14:19:09 -06001210
1211/*
1212 * Return the depth buffer associated with an XMesaBuffer.
1213 * Input: b - the XMesa buffer handle
1214 * Output: width, height - size of buffer in pixels
1215 * bytesPerValue - bytes per depth value (2 or 4)
1216 * buffer - pointer to depth buffer values
1217 * Return: GL_TRUE or GL_FALSE to indicate success or failure.
1218 */
1219GLboolean XMesaGetDepthBuffer( XMesaBuffer b, GLint *width, GLint *height,
1220 GLint *bytesPerValue, void **buffer )
1221{
Brian749d7232007-12-07 07:57:54 -07001222 struct pipe_surface *surf
1223 = st_get_framebuffer_surface(b->stfb, ST_SURFACE_DEPTH);
1224 if (surf) {
1225 *width = surf->width;
1226 *height = surf->pitch;
1227 *bytesPerValue = surf->cpp;
1228 *buffer = surf->map;
1229 return GL_TRUE;
1230 }
1231 else {
Brianef25c492007-10-31 14:19:09 -06001232 *width = 0;
1233 *height = 0;
1234 *bytesPerValue = 0;
1235 *buffer = 0;
1236 return GL_FALSE;
1237 }
Brianef25c492007-10-31 14:19:09 -06001238}
1239
1240
1241void XMesaFlush( XMesaContext c )
1242{
Brian749d7232007-12-07 07:57:54 -07001243 if (c && c->xm_visual->display) {
Brianef25c492007-10-31 14:19:09 -06001244#ifdef XFree86Server
1245 /* NOT_NEEDED */
1246#else
Brian749d7232007-12-07 07:57:54 -07001247 XSync( c->xm_visual->display, False );
Brianef25c492007-10-31 14:19:09 -06001248#endif
1249 }
1250}
1251
1252
1253
1254const char *XMesaGetString( XMesaContext c, int name )
1255{
1256 (void) c;
1257 if (name==XMESA_VERSION) {
1258 return "5.0";
1259 }
1260 else if (name==XMESA_EXTENSIONS) {
1261 return "";
1262 }
1263 else {
1264 return NULL;
1265 }
1266}
1267
1268
1269
1270XMesaBuffer XMesaFindBuffer( XMesaDisplay *dpy, XMesaDrawable d )
1271{
1272 XMesaBuffer b;
1273 for (b=XMesaBufferList; b; b=b->Next) {
Brian749d7232007-12-07 07:57:54 -07001274 if (b->drawable == d && b->xm_visual->display == dpy) {
Brianef25c492007-10-31 14:19:09 -06001275 return b;
1276 }
1277 }
1278 return NULL;
1279}
1280
1281
1282/**
1283 * Free/destroy all XMesaBuffers associated with given display.
1284 */
1285void xmesa_destroy_buffers_on_display(XMesaDisplay *dpy)
1286{
1287 XMesaBuffer b, next;
1288 for (b = XMesaBufferList; b; b = next) {
1289 next = b->Next;
Brian749d7232007-12-07 07:57:54 -07001290 if (b->xm_visual->display == dpy) {
Brianef25c492007-10-31 14:19:09 -06001291 xmesa_free_buffer(b);
1292 }
1293 }
1294}
1295
1296
1297/*
1298 * Look for XMesaBuffers whose X window has been destroyed.
1299 * Deallocate any such XMesaBuffers.
1300 */
1301void XMesaGarbageCollect( void )
1302{
1303 XMesaBuffer b, next;
1304 for (b=XMesaBufferList; b; b=next) {
1305 next = b->Next;
Brian749d7232007-12-07 07:57:54 -07001306 if (b->xm_visual &&
1307 b->xm_visual->display &&
1308 b->drawable &&
1309 b->type == WINDOW) {
Brianef25c492007-10-31 14:19:09 -06001310#ifdef XFree86Server
1311 /* NOT_NEEDED */
1312#else
Brian749d7232007-12-07 07:57:54 -07001313 XSync(b->xm_visual->display, False);
1314 if (!window_exists( b->xm_visual->display, b->drawable )) {
Brianef25c492007-10-31 14:19:09 -06001315 /* found a dead window, free the ancillary info */
1316 XMesaDestroyBuffer( b );
1317 }
1318#endif
1319 }
1320 }
1321}
1322
1323
1324unsigned long XMesaDitherColor( XMesaContext xmesa, GLint x, GLint y,
1325 GLfloat red, GLfloat green,
1326 GLfloat blue, GLfloat alpha )
1327{
Brian749d7232007-12-07 07:57:54 -07001328 /* no longer supported */
Brianef25c492007-10-31 14:19:09 -06001329 return 0;
1330}
1331
1332
1333/*
1334 * This is typically called when the window size changes and we need
1335 * to reallocate the buffer's back/depth/stencil/accum buffers.
1336 */
1337PUBLIC void
1338XMesaResizeBuffers( XMesaBuffer b )
1339{
1340 GET_CURRENT_CONTEXT(ctx);
Brian749d7232007-12-07 07:57:54 -07001341 XMesaContext xmctx = xmesa_context(ctx);
Brianef25c492007-10-31 14:19:09 -06001342 if (!xmctx)
1343 return;
1344 xmesa_check_and_update_buffer_size(xmctx, b);
1345}
1346
1347
Brianef25c492007-10-31 14:19:09 -06001348
1349
1350PUBLIC void
1351XMesaBindTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer,
1352 const int *attrib_list)
1353{
Brianef25c492007-10-31 14:19:09 -06001354}
1355
1356
1357
1358PUBLIC void
1359XMesaReleaseTexImage(XMesaDisplay *dpy, XMesaBuffer drawable, int buffer)
1360{
Brianef25c492007-10-31 14:19:09 -06001361}
1362