2 * Copyright 1998-1999 Precision Insight, Inc., Cedar Park, Texas.
3 * Copyright © 2008 Red Hat, Inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Soft-
7 * ware"), to deal in the Software without restriction, including without
8 * limitation the rights to use, copy, modify, merge, publish, distribute,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, provided that the above copyright
11 * notice(s) and this permission notice appear in all copies of the Soft-
12 * ware and that both the above copyright notice(s) and this permission
13 * notice appear in supporting documentation.
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABIL-
17 * ITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
18 * RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN
19 * THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSE-
20 * QUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
22 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFOR-
23 * MANCE OF THIS SOFTWARE.
25 * Except as contained in this notice, the name of a copyright holder shall
26 * not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization of
28 * the copyright holder.
31 * Kevin E. Martin <kevin@precisioninsight.com>
32 * Brian Paul <brian@precisioninsight.com>
33 * Kristian Høgsberg (krh@redhat.com)
36 #if defined(GLX_DIRECT_RENDERING) && !defined(GLX_USE_APPLEGL)
41 #include "glxclient.h"
42 #include "dri_common.h"
52 InfoMessageF(const char *f, ...)
57 if ((env = getenv("LIBGL_DEBUG")) && strstr(env, "verbose")) {
58 fprintf(stderr, "libGL: ");
60 vfprintf(stderr, f, args);
66 * Print error to stderr, unless LIBGL_DEBUG=="quiet".
69 ErrorMessageF(const char *f, ...)
74 if ((env = getenv("LIBGL_DEBUG")) && !strstr(env, "quiet")) {
75 fprintf(stderr, "libGL error: ");
77 vfprintf(stderr, f, args);
82 #ifndef DEFAULT_DRIVER_DIR
83 /* this is normally defined in Mesa/configs/default with DRI_DRIVER_SEARCH_PATH */
84 #define DEFAULT_DRIVER_DIR "/usr/local/lib/dri"
88 * Try to \c dlopen the named driver.
90 * This function adds the "_dri.so" suffix to the driver name and searches the
91 * directories specified by the \c LIBGL_DRIVERS_PATH environment variable in
92 * order to find the driver.
94 * \param driverName - a name like "tdfx", "i810", "mga", etc.
97 * A handle from \c dlopen, or \c NULL if driver file not found.
100 driOpenDriver(const char *driverName)
102 void *glhandle, *handle;
103 const char *libPaths, *p, *next;
104 char realDriverName[200];
107 /* Attempt to make sure libGL symbols will be visible to the driver */
108 glhandle = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL);
111 if (geteuid() == getuid()) {
112 /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */
113 libPaths = getenv("LIBGL_DRIVERS_PATH");
115 libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */
117 if (libPaths == NULL)
118 libPaths = DEFAULT_DRIVER_DIR;
121 for (p = libPaths; *p; p = next) {
122 next = strchr(p, ':');
133 snprintf(realDriverName, sizeof realDriverName,
134 "%.*s/tls/%s_dri.so", len, p, driverName);
135 InfoMessageF("OpenDriver: trying %s\n", realDriverName);
136 handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
139 if (handle == NULL) {
140 snprintf(realDriverName, sizeof realDriverName,
141 "%.*s/%s_dri.so", len, p, driverName);
142 InfoMessageF("OpenDriver: trying %s\n", realDriverName);
143 handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL);
149 ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror());
153 ErrorMessageF("unable to load driver: %s_dri.so\n", driverName);
162 __driGetMSCRate(__DRIdrawable *draw,
163 int32_t * numerator, int32_t * denominator,
166 __GLXDRIdrawable *glxDraw = loaderPrivate;
168 return __glxGetMscRate(glxDraw, numerator, denominator);
171 _X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension = {
172 {__DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION},
177 #define __ATTRIB(attrib, field) \
178 { attrib, offsetof(struct glx_config, field) }
182 unsigned int attrib, offset;
184 __ATTRIB(__DRI_ATTRIB_BUFFER_SIZE, rgbBits),
185 __ATTRIB(__DRI_ATTRIB_LEVEL, level),
186 __ATTRIB(__DRI_ATTRIB_RED_SIZE, redBits),
187 __ATTRIB(__DRI_ATTRIB_GREEN_SIZE, greenBits),
188 __ATTRIB(__DRI_ATTRIB_BLUE_SIZE, blueBits),
189 __ATTRIB(__DRI_ATTRIB_ALPHA_SIZE, alphaBits),
190 __ATTRIB(__DRI_ATTRIB_DEPTH_SIZE, depthBits),
191 __ATTRIB(__DRI_ATTRIB_STENCIL_SIZE, stencilBits),
192 __ATTRIB(__DRI_ATTRIB_ACCUM_RED_SIZE, accumRedBits),
193 __ATTRIB(__DRI_ATTRIB_ACCUM_GREEN_SIZE, accumGreenBits),
194 __ATTRIB(__DRI_ATTRIB_ACCUM_BLUE_SIZE, accumBlueBits),
195 __ATTRIB(__DRI_ATTRIB_ACCUM_ALPHA_SIZE, accumAlphaBits),
196 __ATTRIB(__DRI_ATTRIB_SAMPLE_BUFFERS, sampleBuffers),
197 __ATTRIB(__DRI_ATTRIB_SAMPLES, samples),
198 __ATTRIB(__DRI_ATTRIB_DOUBLE_BUFFER, doubleBufferMode),
199 __ATTRIB(__DRI_ATTRIB_STEREO, stereoMode),
200 __ATTRIB(__DRI_ATTRIB_AUX_BUFFERS, numAuxBuffers),
202 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_TYPE, transparentPixel),
203 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_INDEX_VALUE, transparentIndex),
204 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_RED_VALUE, transparentRed),
205 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_GREEN_VALUE, transparentGreen),
206 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_BLUE_VALUE, transparentBlue),
207 __ATTRIB(__DRI_ATTRIB_TRANSPARENT_ALPHA_VALUE, transparentAlpha),
208 __ATTRIB(__DRI_ATTRIB_RED_MASK, redMask),
209 __ATTRIB(__DRI_ATTRIB_GREEN_MASK, greenMask),
210 __ATTRIB(__DRI_ATTRIB_BLUE_MASK, blueMask),
211 __ATTRIB(__DRI_ATTRIB_ALPHA_MASK, alphaMask),
213 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_WIDTH, maxPbufferWidth),
214 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_HEIGHT, maxPbufferHeight),
215 __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels),
216 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth),
217 __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight),
219 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod),
221 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb),
222 __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba),
223 __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE,
224 bindToMipmapTexture),
225 __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),
226 __ATTRIB(__DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE, sRGBCapable)
230 scalarEqual(struct glx_config *mode, unsigned int attrib, unsigned int value)
232 unsigned int glxValue;
235 for (i = 0; i < ARRAY_SIZE(attribMap); i++)
236 if (attribMap[i].attrib == attrib) {
237 glxValue = *(unsigned int *) ((char *) mode + attribMap[i].offset);
238 return glxValue == GLX_DONT_CARE || glxValue == value;
241 return GL_TRUE; /* Is a non-existing attribute equal to value? */
245 driConfigEqual(const __DRIcoreExtension *core,
246 struct glx_config *config, const __DRIconfig *driConfig)
248 unsigned int attrib, value, glxValue;
252 while (core->indexConfigAttrib(driConfig, i++, &attrib, &value)) {
254 case __DRI_ATTRIB_RENDER_TYPE:
256 if (value & __DRI_ATTRIB_RGBA_BIT) {
257 glxValue |= GLX_RGBA_BIT;
259 else if (value & __DRI_ATTRIB_COLOR_INDEX_BIT) {
260 glxValue |= GLX_COLOR_INDEX_BIT;
262 if (glxValue != config->renderType)
266 case __DRI_ATTRIB_CONFIG_CAVEAT:
267 if (value & __DRI_ATTRIB_NON_CONFORMANT_CONFIG)
268 glxValue = GLX_NON_CONFORMANT_CONFIG;
269 else if (value & __DRI_ATTRIB_SLOW_BIT)
270 glxValue = GLX_SLOW_CONFIG;
273 if (glxValue != config->visualRating)
277 case __DRI_ATTRIB_BIND_TO_TEXTURE_TARGETS:
279 if (value & __DRI_ATTRIB_TEXTURE_1D_BIT)
280 glxValue |= GLX_TEXTURE_1D_BIT_EXT;
281 if (value & __DRI_ATTRIB_TEXTURE_2D_BIT)
282 glxValue |= GLX_TEXTURE_2D_BIT_EXT;
283 if (value & __DRI_ATTRIB_TEXTURE_RECTANGLE_BIT)
284 glxValue |= GLX_TEXTURE_RECTANGLE_BIT_EXT;
285 if (config->bindToTextureTargets != GLX_DONT_CARE &&
286 glxValue != config->bindToTextureTargets)
291 if (!scalarEqual(config, attrib, value))
299 static struct glx_config *
300 createDriMode(const __DRIcoreExtension * core,
301 struct glx_config *config, const __DRIconfig **driConfigs)
303 __GLXDRIconfigPrivate *driConfig;
306 for (i = 0; driConfigs[i]; i++) {
307 if (driConfigEqual(core, config, driConfigs[i]))
311 if (driConfigs[i] == NULL)
314 driConfig = Xmalloc(sizeof *driConfig);
315 if (driConfig == NULL)
318 driConfig->base = *config;
319 driConfig->driConfig = driConfigs[i];
321 return &driConfig->base;
324 _X_HIDDEN struct glx_config *
325 driConvertConfigs(const __DRIcoreExtension * core,
326 struct glx_config *configs, const __DRIconfig **driConfigs)
328 struct glx_config head, *tail, *m;
332 for (m = configs; m; m = m->next) {
333 tail->next = createDriMode(core, m, driConfigs);
334 if (tail->next == NULL) {
335 /* no matching dri config for m */
343 glx_config_destroy_list(configs);
349 driDestroyConfigs(const __DRIconfig **configs)
353 for (i = 0; configs[i]; i++)
354 free((__DRIconfig *) configs[i]);
358 _X_HIDDEN __GLXDRIdrawable *
359 driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable)
361 struct glx_display *const priv = __glXInitialize(gc->psc->dpy);
362 __GLXDRIdrawable *pdraw;
363 struct glx_screen *psc;
368 psc = priv->screens[gc->screen];
369 if (priv->drawHash == NULL)
372 if (__glxHashLookup(priv->drawHash, glxDrawable, (void *) &pdraw) == 0) {
377 pdraw = psc->driScreen->createDrawable(psc, glxDrawable,
378 glxDrawable, gc->config);
379 if (__glxHashInsert(priv->drawHash, glxDrawable, pdraw)) {
380 (*pdraw->destroyDrawable) (pdraw);
389 driReleaseDrawables(struct glx_context *gc)
391 const struct glx_display *priv = gc->psc->display;
392 __GLXDRIdrawable *pdraw;
397 if (__glxHashLookup(priv->drawHash,
398 gc->currentDrawable, (void *) &pdraw) == 0) {
399 if (pdraw->drawable == pdraw->xDrawable) {
401 if (pdraw->refcount == 0) {
402 (*pdraw->destroyDrawable)(pdraw);
403 __glxHashDelete(priv->drawHash, gc->currentDrawable);
408 if (__glxHashLookup(priv->drawHash,
409 gc->currentReadable, (void *) &pdraw) == 0) {
410 if (pdraw->drawable == pdraw->xDrawable) {
412 if (pdraw->refcount == 0) {
413 (*pdraw->destroyDrawable)(pdraw);
414 __glxHashDelete(priv->drawHash, gc->currentReadable);
419 gc->currentDrawable = None;
420 gc->currentReadable = None;
424 #endif /* GLX_DIRECT_RENDERING */