• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "main/mtypes.h" /* for gl_config */
61 #include "frontend/api.h"
62 #include "os/os_thread.h"
63 
64 #include "frontend/xlibsw_api.h"
65 
66 # include <X11/Xlib.h>
67 # include <X11/Xlibint.h>
68 # include <X11/Xutil.h>
69 
70 struct hud_context;
71 
72 typedef struct xmesa_display *XMesaDisplay;
73 typedef struct xmesa_buffer *XMesaBuffer;
74 typedef struct xmesa_context *XMesaContext;
75 typedef struct xmesa_visual *XMesaVisual;
76 
77 
78 struct xmesa_display {
79    mtx_t mutex;
80 
81    Display *display;
82    struct pipe_screen *screen;
83    struct st_manager *smapi;
84 
85    struct pipe_context *pipe;
86 };
87 
88 
89 /*
90  * Create a new X/Mesa visual.
91  * Input:  display - X11 display
92  *         visinfo - an XVisualInfo pointer
93  *         rgb_flag - GL_TRUE = RGB mode,
94  *                    GL_FALSE = color index mode
95  *         alpha_flag - alpha buffer requested?
96  *         db_flag - GL_TRUE = double-buffered,
97  *                   GL_FALSE = single buffered
98  *         stereo_flag - stereo visual?
99  *         ximage_flag - GL_TRUE = use an XImage for back buffer,
100  *                       GL_FALSE = use an off-screen pixmap for back buffer
101  *         depth_size - requested bits/depth values, or zero
102  *         stencil_size - requested bits/stencil values, or zero
103  *         accum_red_size - requested bits/red accum values, or zero
104  *         accum_green_size - requested bits/green accum values, or zero
105  *         accum_blue_size - requested bits/blue accum values, or zero
106  *         accum_alpha_size - requested bits/alpha accum values, or zero
107  *         num_samples - number of samples/pixel if multisampling, or zero
108  *         level - visual level, usually 0
109  *         visualCaveat - ala the GLX extension, usually GLX_NONE_EXT
110  * Return;  a new XMesaVisual or 0 if error.
111  */
112 extern XMesaVisual XMesaCreateVisual( Display *display,
113                                       XVisualInfo * visinfo,
114                                       GLboolean rgb_flag,
115                                       GLboolean alpha_flag,
116                                       GLboolean db_flag,
117                                       GLboolean stereo_flag,
118                                       GLboolean ximage_flag,
119                                       GLint depth_size,
120                                       GLint stencil_size,
121                                       GLint accum_red_size,
122                                       GLint accum_green_size,
123                                       GLint accum_blue_size,
124                                       GLint accum_alpha_size,
125                                       GLint num_samples,
126                                       GLint level,
127                                       GLint visualCaveat );
128 
129 /*
130  * Destroy an XMesaVisual, but not the associated XVisualInfo.
131  */
132 extern void XMesaDestroyVisual( XMesaVisual v );
133 
134 
135 
136 /*
137  * Create a new XMesaContext for rendering into an X11 window.
138  *
139  * Input:  visual - an XMesaVisual
140  *         share_list - another XMesaContext with which to share display
141  *                      lists or NULL if no sharing is wanted.
142  * Return:  an XMesaContext or NULL if error.
143  */
144 extern XMesaContext XMesaCreateContext( XMesaVisual v,
145 					XMesaContext share_list,
146                                         GLuint major, GLuint minor,
147                                         GLuint profileMask,
148                                         GLuint contextFlags);
149 
150 
151 /*
152  * Destroy a rendering context as returned by XMesaCreateContext()
153  */
154 extern void XMesaDestroyContext( XMesaContext c );
155 
156 
157 
158 /*
159  * Create an XMesaBuffer from an X window.
160  */
161 extern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, Window w );
162 
163 
164 /*
165  * Create an XMesaBuffer from an X pixmap.
166  */
167 extern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v,
168 					    Pixmap p,
169 					    Colormap cmap );
170 
171 
172 /*
173  * Destroy an XMesaBuffer, but not the corresponding window or pixmap.
174  */
175 extern void XMesaDestroyBuffer( XMesaBuffer b );
176 
177 
178 /*
179  * Return the XMesaBuffer handle which corresponds to an X drawable, if any.
180  *
181  * New in Mesa 2.3.
182  */
183 extern XMesaBuffer XMesaFindBuffer( Display *dpy,
184 				    Drawable d );
185 
186 
187 
188 /*
189  * Bind two buffers (read and draw) to a context and make the
190  * context the current one.
191  * New in Mesa 3.3
192  */
193 extern GLboolean XMesaMakeCurrent2( XMesaContext c,
194                                     XMesaBuffer drawBuffer,
195                                     XMesaBuffer readBuffer );
196 
197 
198 /*
199  * Unbind the current context from its buffer.
200  */
201 extern GLboolean XMesaUnbindContext( XMesaContext c );
202 
203 
204 /*
205  * Return a handle to the current context.
206  */
207 extern XMesaContext XMesaGetCurrentContext( void );
208 
209 
210 /*
211  * Swap the front and back buffers for the given buffer.  No action is
212  * taken if the buffer is not double buffered.
213  */
214 extern void XMesaSwapBuffers( XMesaBuffer b );
215 
216 
217 /*
218  * Copy a sub-region of the back buffer to the front buffer.
219  *
220  * New in Mesa 2.6
221  */
222 extern void XMesaCopySubBuffer( XMesaBuffer b,
223 				int x,
224 				int y,
225 				int width,
226 				int height );
227 
228 
229 
230 
231 
232 /*
233  * Flush/sync a context
234  */
235 extern void XMesaFlush( XMesaContext c );
236 
237 
238 
239 /*
240  * Scan for XMesaBuffers whose window/pixmap has been destroyed, then free
241  * any memory used by that buffer.
242  *
243  * New in Mesa 2.3.
244  */
245 extern void XMesaGarbageCollect( void );
246 
247 
248 
249 /*
250  * Create a pbuffer.
251  * New in Mesa 4.1
252  */
253 extern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, Colormap cmap,
254                                       unsigned int width, unsigned int height);
255 
256 
257 
258 /*
259  * Texture from Pixmap
260  * New in Mesa 7.1
261  */
262 extern void
263 XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer,
264                   const int *attrib_list);
265 
266 extern void
267 XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer);
268 
269 
270 extern XMesaBuffer
271 XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p,
272                                Colormap cmap,
273                                int format, int target, int mipmap);
274 
275 
276 extern void
277 XMesaCopyContext(XMesaContext src, XMesaContext dst, unsigned long mask);
278 
279 
280 /***********************************************************************
281  */
282 
283 /**
284  * Visual inforation, derived from GLvisual.
285  * Basically corresponds to an XVisualInfo.
286  */
287 struct xmesa_visual {
288    struct gl_config mesa_visual;/* Device independent visual parameters */
289    int screen, visualID, visualType;
290    Display *display;	/* The X11 display */
291    XVisualInfo * visinfo;	/* X's visual info (pointer to private copy) */
292    XVisualInfo *vishandle;	/* Only used in fakeglx.c */
293    GLint BitsPerPixel;		/* True bits per pixel for XImages */
294 
295    GLboolean ximage_flag;	/* Use XImage for back buffer (not pixmap)? */
296 
297    struct st_visual stvis;
298 };
299 
300 
301 /**
302  * Context info, derived from st_context.
303  * Basically corresponds to a GLXContext.
304  */
305 struct xmesa_context {
306    struct st_context_iface *st;
307    XMesaVisual xm_visual;	/** pixel format info */
308    XMesaBuffer xm_buffer;	/** current drawbuffer */
309    XMesaBuffer xm_read_buffer;  /** current readbuffer */
310    struct hud_context *hud;
311 };
312 
313 
314 /**
315  * Types of X/GLX drawables we might render into.
316  */
317 typedef enum {
318    WINDOW,          /* An X window */
319    GLXWINDOW,       /* GLX window */
320    PIXMAP,          /* GLX pixmap */
321    PBUFFER          /* GLX Pbuffer */
322 } BufferType;
323 
324 
325 /**
326  * Framebuffer information, derived from.
327  * Basically corresponds to a GLXDrawable.
328  */
329 struct xmesa_buffer {
330    struct st_framebuffer_iface *stfb;
331    struct xlib_drawable ws;
332 
333    GLboolean wasCurrent;	/* was ever the current buffer? */
334    XMesaVisual xm_visual;	/* the X/Mesa visual */
335    Colormap cmap;		/* the X colormap */
336    BufferType type;             /* window, pixmap, pbuffer or glxwindow */
337 
338    GLboolean largestPbuffer;    /**< for pbuffers */
339    GLboolean preservedContents; /**< for pbuffers */
340 
341    XImage *tempImage;
342    unsigned long selectedEvents;/* for pbuffers only */
343 
344 
345    GC gc;			/* scratch GC for span, line, tri drawing */
346 
347    /* GLX_EXT_texture_from_pixmap */
348    GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */
349    GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */
350    GLint TextureMipmap; /** 0 or 1 */
351 
352    struct xmesa_buffer *Next;	/* Linked list pointer: */
353 
354    unsigned width, height;
355 };
356 
357 
358 
359 extern const char *
360 xmesa_get_name(void);
361 
362 extern int
363 xmesa_init(Display *dpy);
364 
365 extern XMesaBuffer
366 xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis);
367 
368 extern void
369 xmesa_get_window_size(Display *dpy, XMesaBuffer b,
370                       GLuint *width, GLuint *height);
371 
372 extern void
373 xmesa_notify_invalid_buffer(XMesaBuffer b);
374 
375 extern void
376 xmesa_check_buffer_size(XMesaBuffer b);
377 
378 extern void
379 xmesa_destroy_buffers_on_display(Display *dpy);
380 
381 extern void
382 xmesa_close_display(Display *dpy);
383 
384 static inline GLuint
xmesa_buffer_width(XMesaBuffer b)385 xmesa_buffer_width(XMesaBuffer b)
386 {
387    return b->width;
388 }
389 
390 static inline GLuint
xmesa_buffer_height(XMesaBuffer b)391 xmesa_buffer_height(XMesaBuffer b)
392 {
393    return b->height;
394 }
395 
396 extern boolean xmesa_strict_invalidate;
397 
398 #endif
399