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