1 /*
2 * Mesa 3-D graphics library
3 *
4 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26
27 /* Sample Usage:
28
29 In addition to the usual X calls to select a visual, create a colormap
30 and create a window, you must do the following to use the X/Mesa interface:
31
32 1. Call XMesaCreateVisual() to make an XMesaVisual from an XVisualInfo.
33
34 2. Call XMesaCreateContext() to create an X/Mesa rendering context, given
35 the XMesaVisual.
36
37 3. Call XMesaCreateWindowBuffer() to create an XMesaBuffer from an X window
38 and XMesaVisual.
39
40 4. Call XMesaMakeCurrent() to bind the XMesaBuffer to an XMesaContext and
41 to make the context the current one.
42
43 5. Make gl* calls to render your graphics.
44
45 6. Use XMesaSwapBuffers() when double buffering to swap front/back buffers.
46
47 7. Before the X window is destroyed, call XMesaDestroyBuffer().
48
49 8. Before exiting, call XMesaDestroyVisual and XMesaDestroyContext.
50
51 */
52
53
54
55
56 #ifndef XM_API_H
57 #define XM_API_H
58
59
60 #include <stdbool.h>
61 #include "main/glconfig.h" /* for gl_config */
62 #include "frontend/api.h"
63 #include "util/u_thread.h"
64
65 #include "frontend/xlibsw_api.h"
66
67 # include <X11/Xlib.h>
68 # include <X11/Xlibint.h>
69 # include <X11/Xutil.h>
70
71 struct st_context;
72 struct hud_context;
73
74 typedef struct xmesa_display *XMesaDisplay;
75 typedef struct xmesa_buffer *XMesaBuffer;
76 typedef struct xmesa_context *XMesaContext;
77 typedef struct xmesa_visual *XMesaVisual;
78
79
80 struct xmesa_display {
81 mtx_t mutex;
82
83 Display *display;
84 struct pipe_screen *screen;
85 struct pipe_frontend_screen *fscreen;
86
87 struct pipe_context *pipe;
88 };
89
90
91 /*
92 * Create a new X/Mesa visual.
93 * Input: display - X11 display
94 * visinfo - an XVisualInfo pointer
95 * rgb_flag - GL_TRUE = RGB mode,
96 * GL_FALSE = color index mode
97 * alpha_flag - alpha buffer requested?
98 * db_flag - GL_TRUE = double-buffered,
99 * GL_FALSE = single buffered
100 * stereo_flag - stereo visual?
101 * ximage_flag - GL_TRUE = use an XImage for back buffer,
102 * GL_FALSE = use an off-screen pixmap for back buffer
103 * depth_size - requested bits/depth values, or zero
104 * stencil_size - requested bits/stencil values, or zero
105 * accum_red_size - requested bits/red accum values, or zero
106 * accum_green_size - requested bits/green accum values, or zero
107 * accum_blue_size - requested bits/blue accum values, or zero
108 * accum_alpha_size - requested bits/alpha accum values, or zero
109 * num_samples - number of samples/pixel if multisampling, or zero
110 * level - visual level, usually 0
111 * visualCaveat - ala the GLX extension, usually GLX_NONE_EXT
112 * Return; a new XMesaVisual or 0 if error.
113 */
114 extern XMesaVisual XMesaCreateVisual( Display *display,
115 XVisualInfo * visinfo,
116 GLboolean rgb_flag,
117 GLboolean alpha_flag,
118 GLboolean db_flag,
119 GLboolean stereo_flag,
120 GLboolean ximage_flag,
121 GLint depth_size,
122 GLint stencil_size,
123 GLint accum_red_size,
124 GLint accum_green_size,
125 GLint accum_blue_size,
126 GLint accum_alpha_size,
127 GLint num_samples,
128 GLint level,
129 GLint visualCaveat );
130
131 /*
132 * Destroy an XMesaVisual, but not the associated XVisualInfo.
133 */
134 extern void XMesaDestroyVisual( XMesaVisual v );
135
136
137
138 /*
139 * Create a new XMesaContext for rendering into an X11 window.
140 *
141 * Input: visual - an XMesaVisual
142 * share_list - another XMesaContext with which to share display
143 * lists or NULL if no sharing is wanted.
144 * Return: an XMesaContext or NULL if error.
145 */
146 extern XMesaContext XMesaCreateContext( XMesaVisual v,
147 XMesaContext share_list,
148 GLuint major, GLuint minor,
149 GLuint profileMask,
150 GLuint contextFlags);
151
152
153 /*
154 * Destroy a rendering context as returned by XMesaCreateContext()
155 */
156 extern void XMesaDestroyContext( XMesaContext c );
157
158
159
160 /*
161 * Create an XMesaBuffer from an X window.
162 */
163 extern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, Window w );
164
165
166 /*
167 * Create an XMesaBuffer from an X pixmap.
168 */
169 extern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v,
170 Pixmap p,
171 Colormap cmap );
172
173
174 /*
175 * Destroy an XMesaBuffer, but not the corresponding window or pixmap.
176 */
177 extern void XMesaDestroyBuffer( XMesaBuffer b );
178
179
180 /*
181 * Return the XMesaBuffer handle which corresponds to an X drawable, if any.
182 *
183 * New in Mesa 2.3.
184 */
185 extern XMesaBuffer XMesaFindBuffer( Display *dpy,
186 Drawable d );
187
188
189
190 /*
191 * Bind two buffers (read and draw) to a context and make the
192 * context the current one.
193 * New in Mesa 3.3
194 */
195 extern GLboolean XMesaMakeCurrent2( XMesaContext c,
196 XMesaBuffer drawBuffer,
197 XMesaBuffer readBuffer );
198
199
200 /*
201 * Unbind the current context from its buffer.
202 */
203 extern GLboolean XMesaUnbindContext( XMesaContext c );
204
205
206 /*
207 * Return a handle to the current context.
208 */
209 extern XMesaContext XMesaGetCurrentContext( void );
210
211
212 /*
213 * Swap the front and back buffers for the given buffer. No action is
214 * taken if the buffer is not double buffered.
215 */
216 extern void XMesaSwapBuffers( XMesaBuffer b );
217
218
219 /*
220 * Copy a sub-region of the back buffer to the front buffer.
221 *
222 * New in Mesa 2.6
223 */
224 extern void XMesaCopySubBuffer( XMesaBuffer b,
225 int x,
226 int y,
227 int width,
228 int height );
229
230
231
232
233
234 /*
235 * Flush/sync a context
236 */
237 extern void XMesaFlush( XMesaContext c );
238
239
240
241 /*
242 * Scan for XMesaBuffers whose window/pixmap has been destroyed, then free
243 * any memory used by that buffer.
244 *
245 * New in Mesa 2.3.
246 */
247 extern void XMesaGarbageCollect( void );
248
249
250
251 /*
252 * Create a pbuffer.
253 * New in Mesa 4.1
254 */
255 extern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, Colormap cmap,
256 unsigned int width, unsigned int height);
257
258
259
260 /*
261 * Texture from Pixmap
262 * New in Mesa 7.1
263 */
264 extern void
265 XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer,
266 const int *attrib_list);
267
268 extern void
269 XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer);
270
271
272 extern XMesaBuffer
273 XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p,
274 Colormap cmap,
275 int format, int target, int mipmap);
276
277
278 extern void
279 XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask);
280
281
282 /***********************************************************************
283 */
284
285 /**
286 * Visual inforation, derived from GLvisual.
287 * Basically corresponds to an XVisualInfo.
288 */
289 struct xmesa_visual {
290 struct gl_config mesa_visual;/* Device independent visual parameters */
291 int screen, visualID, visualType;
292 Display *display; /* The X11 display */
293 XVisualInfo * visinfo; /* X's visual info (pointer to private copy) */
294 XVisualInfo *vishandle; /* Only used in fakeglx.c */
295 GLint BitsPerPixel; /* True bits per pixel for XImages */
296
297 GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */
298
299 struct st_visual stvis;
300 };
301
302
303 /**
304 * Context info, derived from st_context.
305 * Basically corresponds to a GLXContext.
306 */
307 struct xmesa_context {
308 struct st_context *st;
309 XMesaVisual xm_visual; /** pixel format info */
310 XMesaBuffer xm_buffer; /** current drawbuffer */
311 XMesaBuffer xm_read_buffer; /** current readbuffer */
312 struct hud_context *hud;
313 };
314
315
316 /**
317 * Types of X/GLX drawables we might render into.
318 */
319 typedef enum {
320 WINDOW, /* An X window */
321 GLXWINDOW, /* GLX window */
322 PIXMAP, /* GLX pixmap */
323 PBUFFER /* GLX Pbuffer */
324 } BufferType;
325
326
327 /**
328 * Framebuffer information, derived from.
329 * Basically corresponds to a GLXDrawable.
330 */
331 struct xmesa_buffer {
332 struct pipe_frontend_drawable *drawable;
333 struct xlib_drawable ws;
334
335 GLboolean wasCurrent; /* was ever the current buffer? */
336 XMesaVisual xm_visual; /* the X/Mesa visual */
337 Colormap cmap; /* the X colormap */
338 BufferType type; /* window, pixmap, pbuffer or glxwindow */
339
340 GLboolean largestPbuffer; /**< for pbuffers */
341 GLboolean preservedContents; /**< for pbuffers */
342
343 XImage *tempImage;
344 unsigned long selectedEvents;/* for pbuffers only */
345
346
347 GC gc; /* scratch GC for span, line, tri drawing */
348
349 /* GLX_EXT_texture_from_pixmap */
350 GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */
351 GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */
352 GLint TextureMipmap; /** 0 or 1 */
353
354 struct xmesa_buffer *Next; /* Linked list pointer: */
355
356 unsigned width, height;
357 };
358
359
360
361 extern const char *
362 xmesa_get_name(void);
363
364 extern int
365 xmesa_init(Display *dpy);
366
367 extern XMesaBuffer
368 xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis);
369
370 extern void
371 xmesa_get_window_size(Display *dpy, XMesaBuffer b,
372 GLuint *width, GLuint *height);
373
374 extern void
375 xmesa_notify_invalid_buffer(XMesaBuffer b);
376
377 extern void
378 xmesa_check_buffer_size(XMesaBuffer b);
379
380 extern void
381 xmesa_destroy_buffers_on_display(Display *dpy);
382
383 extern void
384 xmesa_close_display(Display *dpy);
385
386 static inline GLuint
xmesa_buffer_width(XMesaBuffer b)387 xmesa_buffer_width(XMesaBuffer b)
388 {
389 return b->width;
390 }
391
392 static inline GLuint
xmesa_buffer_height(XMesaBuffer b)393 xmesa_buffer_height(XMesaBuffer b)
394 {
395 return b->height;
396 }
397
398 bool xmesa_strict_invalidate(void);
399
400 #endif
401