xlib: remove a ton of old xlib driver cruft
[mesa.git] / src / mesa / drivers / x11 / xmesaP.h
1 /*
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 #ifndef XMESAP_H
27 #define XMESAP_H
28
29
30 #include "xmesa.h"
31 #include "main/mtypes.h"
32
33
34 extern _glthread_Mutex _xmesa_lock;
35
36 extern XMesaBuffer XMesaBufferList;
37
38 /* for PF_8R8G8B24 pixel format */
39 typedef struct {
40 GLubyte b;
41 GLubyte g;
42 GLubyte r;
43 } bgr_t;
44
45
46 struct xmesa_renderbuffer;
47
48
49 /* Function pointer for clearing color buffers */
50 typedef void (*ClearFunc)( struct gl_context *ctx, struct xmesa_renderbuffer *xrb,
51 GLint x, GLint y, GLint width, GLint height );
52
53
54
55
56 /** Framebuffer pixel formats */
57 enum pixel_format {
58 PF_Truecolor, /**< TrueColor or DirectColor, any depth */
59 PF_Dither_True, /**< TrueColor with dithering */
60 PF_8A8R8G8B, /**< 32-bit TrueColor: 8-A, 8-R, 8-G, 8-B bits */
61 PF_8A8B8G8R, /**< 32-bit TrueColor: 8-A, 8-B, 8-G, 8-R bits */
62 PF_8R8G8B, /**< 32-bit TrueColor: 8-R, 8-G, 8-B bits */
63 PF_8R8G8B24, /**< 24-bit TrueColor: 8-R, 8-G, 8-B bits */
64 PF_5R6G5B, /**< 16-bit TrueColor: 5-R, 6-G, 5-B bits */
65 PF_Dither_5R6G5B /**< 16-bit dithered TrueColor: 5-R, 6-G, 5-B */
66 };
67
68
69 /**
70 * Visual inforation, derived from struct gl_config.
71 * Basically corresponds to an XVisualInfo.
72 */
73 struct xmesa_visual {
74 struct gl_config mesa_visual; /* Device independent visual parameters */
75 XMesaDisplay *display; /* The X11 display */
76 int screen, visualID;
77 int visualType;
78 XMesaVisualInfo visinfo; /* X's visual info (pointer to private copy) */
79 XVisualInfo *vishandle; /* Only used in fakeglx.c */
80 GLint BitsPerPixel; /* True bits per pixel for XImages */
81
82 GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */
83
84 enum pixel_format dithered_pf; /* Pixel format when dithering */
85 enum pixel_format undithered_pf;/* Pixel format when not dithering */
86
87 GLfloat RedGamma; /* Gamma values, 1.0 is default */
88 GLfloat GreenGamma;
89 GLfloat BlueGamma;
90
91 /* For PF_TRUECOLOR */
92 GLint rshift, gshift, bshift;/* Pixel color component shifts */
93 GLubyte Kernel[16]; /* Dither kernel */
94 unsigned long RtoPixel[512]; /* RGB to pixel conversion */
95 unsigned long GtoPixel[512];
96 unsigned long BtoPixel[512];
97 GLubyte PixelToR[256]; /* Pixel to RGB conversion */
98 GLubyte PixelToG[256];
99 GLubyte PixelToB[256];
100 };
101
102
103 /**
104 * Context info, derived from struct gl_context.
105 * Basically corresponds to a GLXContext.
106 */
107 struct xmesa_context {
108 struct gl_context mesa; /* the core library context (containment) */
109 XMesaVisual xm_visual; /* Describes the buffers */
110 XMesaBuffer xm_buffer; /* current span/point/line/triangle buffer */
111
112 XMesaDisplay *display; /* == xm_visual->display */
113 GLboolean swapbytes; /* Host byte order != display byte order? */
114 GLboolean direct; /* Direct rendering context? */
115
116 enum pixel_format pixelformat;
117
118 GLubyte clearcolor[4]; /* current clearing color */
119 unsigned long clearpixel; /* current clearing pixel value */
120 };
121
122
123 /**
124 * Types of X/GLX drawables we might render into.
125 */
126 typedef enum {
127 WINDOW, /* An X window */
128 GLXWINDOW, /* GLX window */
129 PIXMAP, /* GLX pixmap */
130 PBUFFER /* GLX Pbuffer */
131 } BufferType;
132
133
134 /** Values for db_mode: */
135 /*@{*/
136 #define BACK_PIXMAP 1
137 #define BACK_XIMAGE 2
138 /*@}*/
139
140
141 /**
142 * An xmesa_renderbuffer represents the back or front color buffer.
143 * For the front color buffer:
144 * <drawable> is the X window
145 * For the back color buffer:
146 * Either <ximage> or <pixmap> will be used, never both.
147 * In any case, <drawable> always equals <pixmap>.
148 * For stand-alone Mesa, we could merge <drawable> and <pixmap> into one
149 * field. We don't do that for the server-side GLcore module because
150 * pixmaps and drawables are different and we'd need a bunch of casts.
151 */
152 struct xmesa_renderbuffer
153 {
154 struct gl_renderbuffer Base; /* Base class */
155
156 XMesaBuffer Parent; /**< The XMesaBuffer this renderbuffer belongs to */
157 XMesaDrawable drawable; /* Usually the X window ID */
158 XMesaPixmap pixmap; /* Back color buffer */
159 XMesaImage *ximage; /* The back buffer, if not using a Pixmap */
160
161 GLushort *origin2; /* used for PIXEL_ADDR2 macro */
162 GLint width2;
163 GLubyte *origin3; /* used for PIXEL_ADDR3 macro */
164 GLint width3;
165 GLuint *origin4; /* used for PIXEL_ADDR4 macro */
166 GLint width4;
167
168 GLint bottom; /* used for FLIP macro, equals height - 1 */
169
170 ClearFunc clearFunc;
171
172 GLuint map_x, map_y, map_w, map_h;
173 GLbitfield map_mode;
174 XMesaImage *map_ximage;
175 };
176
177
178 /**
179 * Framebuffer information, derived from.
180 * Basically corresponds to a GLXDrawable.
181 */
182 struct xmesa_buffer {
183 struct gl_framebuffer mesa_buffer; /* depth, stencil, accum, etc buffers */
184 /* This MUST BE FIRST! */
185 GLboolean wasCurrent; /* was ever the current buffer? */
186 XMesaVisual xm_visual; /* the X/Mesa visual */
187
188 XMesaDisplay *display;
189 BufferType type; /* window, pixmap, pbuffer or glxwindow */
190
191 GLboolean largestPbuffer; /**< for pbuffers */
192 GLboolean preservedContents; /**< for pbuffers */
193
194 struct xmesa_renderbuffer *frontxrb; /* front color renderbuffer */
195 struct xmesa_renderbuffer *backxrb; /* back color renderbuffer */
196
197 XMesaColormap cmap; /* the X colormap */
198
199 unsigned long selectedEvents;/* for pbuffers only */
200
201 GLint db_mode; /* 0 = single buffered */
202 /* BACK_PIXMAP = use Pixmap for back buffer */
203 /* BACK_XIMAGE = use XImage for back buffer */
204 GLuint shm; /* X Shared Memory extension status: */
205 /* 0 = not available */
206 /* 1 = XImage support available */
207 /* 2 = Pixmap support available too */
208 #if defined(USE_XSHM)
209 XShmSegmentInfo shminfo;
210 #endif
211
212 XMesaImage *rowimage; /* Used for optimized span writing */
213 XMesaPixmap stipple_pixmap; /* For polygon stippling */
214 XMesaGC stipple_gc; /* For polygon stippling */
215
216 XMesaGC gc; /* scratch GC for span, line, tri drawing */
217 XMesaGC cleargc; /* GC for clearing the color buffer */
218 XMesaGC swapgc; /* GC for swapping the color buffers */
219
220 /* The following are here instead of in the XMesaVisual
221 * because they depend on the window's colormap.
222 */
223
224 /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */
225 unsigned long color_table[576]; /* RGB -> pixel value */
226
227 /* For PF_DITHER, PF_LOOKUP, PF_GRAYSCALE */
228 GLubyte pixel_to_r[65536]; /* pixel value -> red */
229 GLubyte pixel_to_g[65536]; /* pixel value -> green */
230 GLubyte pixel_to_b[65536]; /* pixel value -> blue */
231
232 /* Used to do XAllocColor/XFreeColors accounting: */
233 int num_alloced;
234 unsigned long alloced_colors[256];
235
236 /* GLX_EXT_texture_from_pixmap */
237 GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */
238 GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */
239 GLint TextureMipmap; /** 0 or 1 */
240
241 struct xmesa_buffer *Next; /* Linked list pointer: */
242 };
243
244
245 /**
246 * If pixelformat==PF_TRUECOLOR:
247 */
248 #define PACK_TRUECOLOR( PIXEL, R, G, B ) \
249 PIXEL = xmesa->xm_visual->RtoPixel[R] \
250 | xmesa->xm_visual->GtoPixel[G] \
251 | xmesa->xm_visual->BtoPixel[B]; \
252
253
254 /**
255 * If pixelformat==PF_TRUEDITHER:
256 */
257 #define PACK_TRUEDITHER( PIXEL, X, Y, R, G, B ) \
258 { \
259 int d = xmesa->xm_visual->Kernel[((X)&3) | (((Y)&3)<<2)]; \
260 PIXEL = xmesa->xm_visual->RtoPixel[(R)+d] \
261 | xmesa->xm_visual->GtoPixel[(G)+d] \
262 | xmesa->xm_visual->BtoPixel[(B)+d]; \
263 }
264
265
266
267 /**
268 * If pixelformat==PF_8A8B8G8R:
269 */
270 #define PACK_8A8B8G8R( R, G, B, A ) \
271 ( ((A) << 24) | ((B) << 16) | ((G) << 8) | (R) )
272
273
274 /**
275 * Like PACK_8A8B8G8R() but don't use alpha. This is usually an acceptable
276 * shortcut.
277 */
278 #define PACK_8B8G8R( R, G, B ) ( ((B) << 16) | ((G) << 8) | (R) )
279
280
281
282 /**
283 * If pixelformat==PF_8R8G8B:
284 */
285 #define PACK_8R8G8B( R, G, B) ( ((R) << 16) | ((G) << 8) | (B) )
286
287
288 /**
289 * If pixelformat==PF_5R6G5B:
290 */
291 #define PACK_5R6G5B( R, G, B) ( (((R) & 0xf8) << 8) | (((G) & 0xfc) << 3) | ((B) >> 3) )
292
293
294 /**
295 * If pixelformat==PF_8A8R8G8B:
296 */
297 #define PACK_8A8R8G8B( R, G, B, A ) \
298 ( ((A) << 24) | ((R) << 16) | ((G) << 8) | (B) )
299
300
301
302
303 /**
304 * Converts a GL window Y coord to an X window Y coord:
305 */
306 #define YFLIP(XRB, Y) ((XRB)->bottom - (Y))
307
308
309 /**
310 * Return the address of a 2, 3 or 4-byte pixel in the buffer's XImage:
311 * X==0 is left, Y==0 is bottom.
312 */
313 #define PIXEL_ADDR2(XRB, X, Y) \
314 ( (XRB)->origin2 - (Y) * (XRB)->width2 + (X) )
315
316 #define PIXEL_ADDR3(XRB, X, Y) \
317 ( (bgr_t *) ( (XRB)->origin3 - (Y) * (XRB)->width3 + 3 * (X) ))
318
319 #define PIXEL_ADDR4(XRB, X, Y) \
320 ( (XRB)->origin4 - (Y) * (XRB)->width4 + (X) )
321
322
323
324 /*
325 * External functions:
326 */
327
328 extern struct xmesa_renderbuffer *
329 xmesa_new_renderbuffer(struct gl_context *ctx, GLuint name,
330 const struct xmesa_visual *xmvis,
331 GLboolean backBuffer);
332
333 extern void
334 xmesa_delete_framebuffer(struct gl_framebuffer *fb);
335
336 extern XMesaBuffer
337 xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis);
338
339 extern unsigned long
340 xmesa_color_to_pixel( struct gl_context *ctx,
341 GLubyte r, GLubyte g, GLubyte b, GLubyte a,
342 GLuint pixelFormat );
343
344 extern void
345 xmesa_get_window_size(XMesaDisplay *dpy, XMesaBuffer b,
346 GLuint *width, GLuint *height);
347
348 extern void
349 xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer);
350
351 extern void
352 xmesa_init_driver_functions( XMesaVisual xmvisual,
353 struct dd_function_table *driver );
354
355 extern void
356 xmesa_update_state( struct gl_context *ctx, GLbitfield new_state );
357
358 extern void
359 xmesa_set_renderbuffer_funcs(struct xmesa_renderbuffer *xrb,
360 enum pixel_format pixelformat, GLint depth);
361
362 extern void
363 xmesa_MapRenderbuffer(struct gl_context *ctx,
364 struct gl_renderbuffer *rb,
365 GLuint x, GLuint y, GLuint w, GLuint h,
366 GLbitfield mode,
367 GLubyte **mapOut, GLint *rowStrideOut);
368
369 extern void
370 xmesa_UnmapRenderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb);
371
372 extern void
373 xmesa_destroy_buffers_on_display(XMesaDisplay *dpy);
374
375
376 /**
377 * Using a function instead of an ordinary cast is safer.
378 */
379 static INLINE struct xmesa_renderbuffer *
380 xmesa_renderbuffer(struct gl_renderbuffer *rb)
381 {
382 return (struct xmesa_renderbuffer *) rb;
383 }
384
385
386 /**
387 * Return pointer to XMesaContext corresponding to a Mesa struct gl_context.
388 * Since we're using structure containment, it's just a cast!.
389 */
390 static INLINE XMesaContext
391 XMESA_CONTEXT(struct gl_context *ctx)
392 {
393 return (XMesaContext) ctx;
394 }
395
396
397 /**
398 * Return pointer to XMesaBuffer corresponding to a Mesa struct gl_framebuffer.
399 * Since we're using structure containment, it's just a cast!.
400 */
401 static INLINE XMesaBuffer
402 XMESA_BUFFER(struct gl_framebuffer *b)
403 {
404 return (XMesaBuffer) b;
405 }
406
407
408 /* Plugged into the software rasterizer. Try to use internal
409 * swrast-style point, line and triangle functions.
410 */
411 extern void xmesa_choose_point( struct gl_context *ctx );
412 extern void xmesa_choose_line( struct gl_context *ctx );
413 extern void xmesa_choose_triangle( struct gl_context *ctx );
414
415
416 extern void xmesa_register_swrast_functions( struct gl_context *ctx );
417
418
419
420 #define ENABLE_EXT_texure_compression_s3tc 0 /* SW texture compression */
421
422 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
423 #define ENABLE_EXT_timer_query 1 /* should have 64-bit GLuint64EXT */
424 #else
425 #define ENABLE_EXT_timer_query 0 /* may not have 64-bit GLuint64EXT */
426 #endif
427
428
429 #define TEST_META_FUNCS 0
430
431
432 #endif