xm_api.h revision f21b0e9a048150569ad469ab021a62fdc986e0ae
16d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org/* 26d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * Mesa 3-D graphics library 36d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * Version: 7.1 46d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * 56d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 66d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * 76d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a 86d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * copy of this software and associated documentation files (the "Software"), 96d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * to deal in the Software without restriction, including without limitation 100a7e5b7554b066dd5879395fc114712dd234e643commit-bot@chromium.org * the rights to use, copy, modify, merge, publish, distribute, sublicense, 116d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * and/or sell copies of the Software, and to permit persons to whom the 126d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * Software is furnished to do so, subject to the following conditions: 136d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * 146d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * The above copyright notice and this permission notice shall be included 156d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * in all copies or substantial portions of the Software. 166d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * 176d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 186d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 196d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 206d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 216d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 226d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 236d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org */ 246d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org 256d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org 266d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org 276d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org/* Sample Usage: 286d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.org 296d036c2e47819ce91ba4f09edeeccead60af4320commit-bot@chromium.orgIn 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/mtypes.h" 61#include "state_tracker/st_context.h" 62#include "state_tracker/st_public.h" 63#include "pipe/p_thread.h" 64 65 66# include <X11/Xlib.h> 67# include <X11/Xlibint.h> 68# include <X11/Xutil.h> 69# ifdef USE_XSHM /* was SHM */ 70# include <sys/ipc.h> 71# include <sys/shm.h> 72# include <X11/extensions/XShm.h> 73# endif 74 75typedef struct xmesa_buffer *XMesaBuffer; 76typedef struct xmesa_context *XMesaContext; 77typedef struct xmesa_visual *XMesaVisual; 78 79 80 81/* 82 * Create a new X/Mesa visual. 83 * Input: display - X11 display 84 * visinfo - an XVisualInfo pointer 85 * rgb_flag - GL_TRUE = RGB mode, 86 * GL_FALSE = color index mode 87 * alpha_flag - alpha buffer requested? 88 * db_flag - GL_TRUE = double-buffered, 89 * GL_FALSE = single buffered 90 * stereo_flag - stereo visual? 91 * ximage_flag - GL_TRUE = use an XImage for back buffer, 92 * GL_FALSE = use an off-screen pixmap for back buffer 93 * depth_size - requested bits/depth values, or zero 94 * stencil_size - requested bits/stencil values, or zero 95 * accum_red_size - requested bits/red accum values, or zero 96 * accum_green_size - requested bits/green accum values, or zero 97 * accum_blue_size - requested bits/blue accum values, or zero 98 * accum_alpha_size - requested bits/alpha accum values, or zero 99 * num_samples - number of samples/pixel if multisampling, or zero 100 * level - visual level, usually 0 101 * visualCaveat - ala the GLX extension, usually GLX_NONE_EXT 102 * Return; a new XMesaVisual or 0 if error. 103 */ 104extern XMesaVisual XMesaCreateVisual( Display *display, 105 XVisualInfo * visinfo, 106 GLboolean rgb_flag, 107 GLboolean alpha_flag, 108 GLboolean db_flag, 109 GLboolean stereo_flag, 110 GLboolean ximage_flag, 111 GLint depth_size, 112 GLint stencil_size, 113 GLint accum_red_size, 114 GLint accum_green_size, 115 GLint accum_blue_size, 116 GLint accum_alpha_size, 117 GLint num_samples, 118 GLint level, 119 GLint visualCaveat ); 120 121/* 122 * Destroy an XMesaVisual, but not the associated XVisualInfo. 123 */ 124extern void XMesaDestroyVisual( XMesaVisual v ); 125 126 127 128/* 129 * Create a new XMesaContext for rendering into an X11 window. 130 * 131 * Input: visual - an XMesaVisual 132 * share_list - another XMesaContext with which to share display 133 * lists or NULL if no sharing is wanted. 134 * Return: an XMesaContext or NULL if error. 135 */ 136extern XMesaContext XMesaCreateContext( XMesaVisual v, 137 XMesaContext share_list ); 138 139 140/* 141 * Destroy a rendering context as returned by XMesaCreateContext() 142 */ 143extern void XMesaDestroyContext( XMesaContext c ); 144 145 146 147/* 148 * Create an XMesaBuffer from an X window. 149 */ 150extern XMesaBuffer XMesaCreateWindowBuffer( XMesaVisual v, Window w ); 151 152 153/* 154 * Create an XMesaBuffer from an X pixmap. 155 */ 156extern XMesaBuffer XMesaCreatePixmapBuffer( XMesaVisual v, 157 Pixmap p, 158 Colormap cmap ); 159 160 161/* 162 * Destroy an XMesaBuffer, but not the corresponding window or pixmap. 163 */ 164extern void XMesaDestroyBuffer( XMesaBuffer b ); 165 166 167/* 168 * Return the XMesaBuffer handle which corresponds to an X drawable, if any. 169 * 170 * New in Mesa 2.3. 171 */ 172extern XMesaBuffer XMesaFindBuffer( Display *dpy, 173 Drawable d ); 174 175 176 177/* 178 * Bind two buffers (read and draw) to a context and make the 179 * context the current one. 180 * New in Mesa 3.3 181 */ 182extern GLboolean XMesaMakeCurrent2( XMesaContext c, 183 XMesaBuffer drawBuffer, 184 XMesaBuffer readBuffer ); 185 186 187/* 188 * Unbind the current context from its buffer. 189 */ 190extern GLboolean XMesaUnbindContext( XMesaContext c ); 191 192 193/* 194 * Return a handle to the current context. 195 */ 196extern XMesaContext XMesaGetCurrentContext( void ); 197 198 199/* 200 * Swap the front and back buffers for the given buffer. No action is 201 * taken if the buffer is not double buffered. 202 */ 203extern void XMesaSwapBuffers( XMesaBuffer b ); 204 205 206/* 207 * Copy a sub-region of the back buffer to the front buffer. 208 * 209 * New in Mesa 2.6 210 */ 211extern void XMesaCopySubBuffer( XMesaBuffer b, 212 int x, 213 int y, 214 int width, 215 int height ); 216 217 218 219 220 221/* 222 * Flush/sync a context 223 */ 224extern void XMesaFlush( XMesaContext c ); 225 226 227 228/* 229 * Scan for XMesaBuffers whose window/pixmap has been destroyed, then free 230 * any memory used by that buffer. 231 * 232 * New in Mesa 2.3. 233 */ 234extern void XMesaGarbageCollect( void ); 235 236 237 238/* 239 * Create a pbuffer. 240 * New in Mesa 4.1 241 */ 242extern XMesaBuffer XMesaCreatePBuffer(XMesaVisual v, Colormap cmap, 243 unsigned int width, unsigned int height); 244 245 246 247/* 248 * Texture from Pixmap 249 * New in Mesa 7.1 250 */ 251extern void 252XMesaBindTexImage(Display *dpy, XMesaBuffer drawable, int buffer, 253 const int *attrib_list); 254 255extern void 256XMesaReleaseTexImage(Display *dpy, XMesaBuffer drawable, int buffer); 257 258 259extern XMesaBuffer 260XMesaCreatePixmapTextureBuffer(XMesaVisual v, Pixmap p, 261 Colormap cmap, 262 int format, int target, int mipmap); 263 264 265 266 267/*********************************************************************** 268 */ 269 270extern pipe_mutex _xmesa_lock; 271 272extern struct xmesa_buffer *XMesaBufferList; 273 274 275/** 276 * Visual inforation, derived from GLvisual. 277 * Basically corresponds to an XVisualInfo. 278 */ 279struct xmesa_visual { 280 GLvisual mesa_visual; /* Device independent visual parameters */ 281 Display *display; /* The X11 display */ 282 XVisualInfo * visinfo; /* X's visual info (pointer to private copy) */ 283 XVisualInfo *vishandle; /* Only used in fakeglx.c */ 284 GLint BitsPerPixel; /* True bits per pixel for XImages */ 285 286 GLboolean ximage_flag; /* Use XImage for back buffer (not pixmap)? */ 287}; 288 289 290/** 291 * Context info, derived from st_context. 292 * Basically corresponds to a GLXContext. 293 */ 294struct xmesa_context { 295 struct st_context *st; 296 XMesaVisual xm_visual; /** pixel format info */ 297 XMesaBuffer xm_buffer; /** current drawbuffer */ 298 XMesaBuffer xm_read_buffer; /** current readbuffer */ 299}; 300 301 302/** 303 * Types of X/GLX drawables we might render into. 304 */ 305typedef enum { 306 WINDOW, /* An X window */ 307 GLXWINDOW, /* GLX window */ 308 PIXMAP, /* GLX pixmap */ 309 PBUFFER /* GLX Pbuffer */ 310} BufferType; 311 312 313/** 314 * Framebuffer information, derived from. 315 * Basically corresponds to a GLXDrawable. 316 */ 317struct xmesa_buffer { 318 struct st_framebuffer *stfb; 319 320 GLboolean wasCurrent; /* was ever the current buffer? */ 321 XMesaVisual xm_visual; /* the X/Mesa visual */ 322 Drawable drawable; /* Usually the X window ID */ 323 Colormap cmap; /* the X colormap */ 324 BufferType type; /* window, pixmap, pbuffer or glxwindow */ 325 326 XImage *tempImage; 327 unsigned long selectedEvents;/* for pbuffers only */ 328 329 GLuint shm; /* X Shared Memory extension status: */ 330 /* 0 = not available */ 331 /* 1 = XImage support available */ 332 /* 2 = Pixmap support available too */ 333#if defined(USE_XSHM) 334 XShmSegmentInfo shminfo; 335#endif 336 337 GC gc; /* scratch GC for span, line, tri drawing */ 338 339 /* GLX_EXT_texture_from_pixmap */ 340 GLint TextureTarget; /** GLX_TEXTURE_1D_EXT, for example */ 341 GLint TextureFormat; /** GLX_TEXTURE_FORMAT_RGB_EXT, for example */ 342 GLint TextureMipmap; /** 0 or 1 */ 343 344 struct xmesa_buffer *Next; /* Linked list pointer: */ 345}; 346 347 348 349/** cast wrapper */ 350static INLINE XMesaContext 351xmesa_context(GLcontext *ctx) 352{ 353 return (XMesaContext) ctx->DriverCtx; 354} 355 356 357/** cast wrapper */ 358static INLINE XMesaBuffer 359xmesa_buffer(GLframebuffer *fb) 360{ 361 struct st_framebuffer *stfb = (struct st_framebuffer *) fb; 362 return (XMesaBuffer) st_framebuffer_private(stfb); 363} 364 365 366extern void 367xmesa_delete_framebuffer(struct gl_framebuffer *fb); 368 369extern XMesaBuffer 370xmesa_find_buffer(Display *dpy, Colormap cmap, XMesaBuffer notThis); 371 372extern void 373xmesa_check_and_update_buffer_size(XMesaContext xmctx, XMesaBuffer drawBuffer); 374 375extern void 376xmesa_destroy_buffers_on_display(Display *dpy); 377 378static INLINE GLuint 379xmesa_buffer_width(XMesaBuffer b) 380{ 381 return b->stfb->Base.Width; 382} 383 384static INLINE GLuint 385xmesa_buffer_height(XMesaBuffer b) 386{ 387 return b->stfb->Base.Height; 388} 389 390extern int 391xmesa_check_for_xshm(Display *display); 392 393 394#endif 395