Merge branch 'gallium-0.1' into gallium-tex-surfaces
[mesa.git] / src / gallium / winsys / xlib / 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 "GL/xmesa.h"
31 #include "mtypes.h"
32 #ifdef XFree86Server
33 #include "xm_image.h"
34 #endif
35
36 #include "state_tracker/st_context.h"
37 #include "state_tracker/st_public.h"
38
39
40 extern _glthread_Mutex _xmesa_lock;
41
42 extern XMesaBuffer XMesaBufferList;
43
44 /*
45 */
46 #define XMESA_SOFTPIPE 1
47 #define XMESA_AUB 2
48 extern int xmesa_mode;
49
50
51 /**
52 * Visual inforation, derived from GLvisual.
53 * Basically corresponds to an XVisualInfo.
54 */
55 struct xmesa_visual {
56 GLvisual mesa_visual; /* Device independent visual parameters */
57 XMesaDisplay *display; /* The X11 display */
58 #ifdef XFree86Server
59 GLint ColormapEntries;
60 GLint nplanes;
61 #else
62 XMesaVisualInfo visinfo; /* X's visual info (pointer to private copy) */
63 XVisualInfo *vishandle; /* Only used in fakeglx.c */
64 #endif
65 GLint BitsPerPixel; /* True bits per pixel for XImages */
66
67 GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */
68 };
69
70
71 /**
72 * Context info, derived from st_context.
73 * Basically corresponds to a GLXContext.
74 */
75 struct xmesa_context {
76 struct st_context *st;
77 XMesaVisual xm_visual; /** pixel format info */
78 XMesaBuffer xm_buffer; /** current drawbuffer */
79 };
80
81
82 /**
83 * Types of X/GLX drawables we might render into.
84 */
85 typedef enum {
86 WINDOW, /* An X window */
87 GLXWINDOW, /* GLX window */
88 PIXMAP, /* GLX pixmap */
89 PBUFFER /* GLX Pbuffer */
90 } BufferType;
91
92
93 /**
94 * Framebuffer information, derived from.
95 * Basically corresponds to a GLXDrawable.
96 */
97 struct xmesa_buffer {
98 struct st_framebuffer *stfb;
99
100 GLboolean wasCurrent; /* was ever the current buffer? */
101 XMesaVisual xm_visual; /* the X/Mesa visual */
102 XMesaDrawable drawable; /* Usually the X window ID */
103 XMesaColormap cmap; /* the X colormap */
104 BufferType type; /* window, pixmap, pbuffer or glxwindow */
105
106 XMesaImage *tempImage;
107 unsigned long selectedEvents;/* for pbuffers only */
108
109 GLuint shm; /* X Shared Memory extension status: */
110 /* 0 = not available */
111 /* 1 = XImage support available */
112 /* 2 = Pixmap support available too */
113 #if defined(USE_XSHM) && !defined(XFree86Server)
114 XShmSegmentInfo shminfo;
115 #endif
116
117 XMesaGC gc; /* scratch GC for span, line, tri drawing */
118
119 /* GLX_EXT_texture_from_pixmap */
120 GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */
121 GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */
122 GLint TextureMipmap; /** 0 or 1 */
123
124 struct xmesa_buffer *Next; /* Linked list pointer: */
125 };
126
127
128
129 /** cast wrapper */
130 static INLINE XMesaContext
131 xmesa_context(GLcontext *ctx)
132 {
133 return (XMesaContext) ctx->DriverCtx;
134 }
135
136
137 /** cast wrapper */
138 static INLINE XMesaBuffer
139 xmesa_buffer(GLframebuffer *fb)
140 {
141 struct st_framebuffer *stfb = (struct st_framebuffer *) fb;
142 return (XMesaBuffer) st_framebuffer_private(stfb);
143 }
144
145
146 extern void
147 xmesa_delete_framebuffer(struct gl_framebuffer *fb);
148
149 extern XMesaBuffer
150 xmesa_find_buffer(XMesaDisplay *dpy, XMesaColormap cmap, XMesaBuffer notThis);
151
152 extern void
153 xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer);
154
155 extern void
156 xmesa_destroy_buffers_on_display(XMesaDisplay *dpy);
157
158 extern struct pipe_context *
159 xmesa_create_pipe_context(XMesaContext xm, uint pixelformat);
160
161 static INLINE GLuint
162 xmesa_buffer_width(XMesaBuffer b)
163 {
164 return b->stfb->Base.Width;
165 }
166
167 static INLINE GLuint
168 xmesa_buffer_height(XMesaBuffer b)
169 {
170 return b->stfb->Base.Height;
171 }
172
173 extern void
174 xmesa_display_surface(XMesaBuffer b, const struct pipe_surface *surf);
175
176 extern int
177 xmesa_check_for_xshm(XMesaDisplay *display);
178
179 #endif