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