X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fglx%2Fdri_common.c;h=fb8a29f099343ec4cec33d836d3cf96833d20c6f;hb=a95ec13879d4f04d01fc04a62503578e85c846a8;hp=0dd8982a18b39bf9fafa1937add12d1aeadc3d5e;hpb=867d7c0e108a4e6511305f82b18ea6f606a18427;p=mesa.git diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index 0dd8982a18b..fb8a29f0993 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -73,9 +73,8 @@ dri_message(int level, const char *f, ...) } } -#ifndef DEFAULT_DRIVER_DIR -/* this is normally defined in Mesa/configs/default with DRI_DRIVER_SEARCH_PATH */ -#define DEFAULT_DRIVER_DIR "/usr/local/lib/dri" +#ifndef GL_LIB_NAME +#define GL_LIB_NAME "libGL.so.1" #endif /** @@ -86,98 +85,32 @@ dri_message(int level, const char *f, ...) * order to find the driver. * * \param driverName - a name like "i965", "radeon", "nouveau", etc. + * \param out_driver_handle - Address to return the resulting dlopen() handle. * * \returns - * A handle from \c dlopen, or \c NULL if driver file not found. + * The __DRIextension entrypoint table for the driver, or \c NULL if driver + * file not found. */ -_X_HIDDEN void * -driOpenDriver(const char *driverName) +_X_HIDDEN const __DRIextension ** +driOpenDriver(const char *driverName, void **out_driver_handle) { - void *glhandle, *handle; - const char *libPaths, *p, *next; - char realDriverName[200]; - int len; + void *glhandle; /* Attempt to make sure libGL symbols will be visible to the driver */ - glhandle = dlopen("libGL.so.1", RTLD_NOW | RTLD_GLOBAL); - - libPaths = NULL; - if (geteuid() == getuid()) { - /* don't allow setuid apps to use LIBGL_DRIVERS_PATH */ - libPaths = getenv("LIBGL_DRIVERS_PATH"); - if (!libPaths) - libPaths = getenv("LIBGL_DRIVERS_DIR"); /* deprecated */ - } - if (libPaths == NULL) - libPaths = DEFAULT_DRIVER_DIR; - - handle = NULL; - for (p = libPaths; *p; p = next) { - next = strchr(p, ':'); - if (next == NULL) { - len = strlen(p); - next = p + len; - } - else { - len = next - p; - next++; - } + glhandle = dlopen(GL_LIB_NAME, RTLD_NOW | RTLD_GLOBAL); -#ifdef GLX_USE_TLS - snprintf(realDriverName, sizeof realDriverName, - "%.*s/tls/%s_dri.so", len, p, driverName); - InfoMessageF("OpenDriver: trying %s\n", realDriverName); - handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL); -#endif + static const char *search_path_vars[] = { + "LIBGL_DRIVERS_PATH", + "LIBGL_DRIVERS_DIR", /* deprecated */ + NULL + }; - if (handle == NULL) { - snprintf(realDriverName, sizeof realDriverName, - "%.*s/%s_dri.so", len, p, driverName); - InfoMessageF("OpenDriver: trying %s\n", realDriverName); - handle = dlopen(realDriverName, RTLD_NOW | RTLD_GLOBAL); - } - - if (handle != NULL) - break; - else - ErrorMessageF("dlopen %s failed (%s)\n", realDriverName, dlerror()); - } - - if (!handle) - ErrorMessageF("unable to load driver: %s_dri.so\n", driverName); + const __DRIextension **extensions = + loader_open_driver(driverName, out_driver_handle, search_path_vars); if (glhandle) dlclose(glhandle); - return handle; -} - -_X_HIDDEN const __DRIextension ** -driGetDriverExtensions(void *handle, const char *driver_name) -{ - const __DRIextension **extensions = NULL; - const __DRIextension **(*get_extensions)(void); - char *get_extensions_name; - - if (asprintf(&get_extensions_name, "%s_%s", - __DRI_DRIVER_GET_EXTENSIONS, driver_name) != -1) { - get_extensions = dlsym(handle, get_extensions_name); - if (get_extensions) { - free(get_extensions_name); - return get_extensions(); - } else { - InfoMessageF("driver does not expose %s(): %s\n", - get_extensions_name, dlerror()); - free(get_extensions_name); - } - } - - extensions = dlsym(handle, __DRI_DRIVER_EXTENSIONS); - if (extensions == NULL) { - ErrorMessageF("driver exports no extensions (%s)\n", dlerror()); - return NULL; - } - return extensions; } @@ -192,9 +125,10 @@ __driGetMSCRate(__DRIdrawable *draw, } _X_HIDDEN const __DRIsystemTimeExtension systemTimeExtension = { - {__DRI_SYSTEM_TIME, __DRI_SYSTEM_TIME_VERSION}, - __glXGetUST, - __driGetMSCRate + .base = {__DRI_SYSTEM_TIME, 1 }, + + .getUST = __glXGetUST, + .getMSCRate = __driGetMSCRate }; #define __ATTRIB(attrib, field) \ @@ -238,10 +172,8 @@ static const struct __ATTRIB(__DRI_ATTRIB_MAX_PBUFFER_PIXELS, maxPbufferPixels), __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_WIDTH, optimalPbufferWidth), __ATTRIB(__DRI_ATTRIB_OPTIMAL_PBUFFER_HEIGHT, optimalPbufferHeight), -#if 0 __ATTRIB(__DRI_ATTRIB_SWAP_METHOD, swapMethod), -#endif -__ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb), + __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb), __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba), __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture), @@ -252,8 +184,7 @@ __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb), static int scalarEqual(struct glx_config *mode, unsigned int attrib, unsigned int value) { - unsigned int glxValue; - int i; + unsigned glxValue, i; for (i = 0; i < ARRAY_SIZE(attribMap); i++) if (attribMap[i].attrib == attrib) { @@ -316,6 +247,19 @@ driConfigEqual(const __DRIcoreExtension *core, return GL_FALSE; break; + case __DRI_ATTRIB_SWAP_METHOD: + if (value == __DRI_ATTRIB_SWAP_EXCHANGE) + glxValue = GLX_SWAP_EXCHANGE_OML; + else if (value == __DRI_ATTRIB_SWAP_COPY) + glxValue = GLX_SWAP_COPY_OML; + else + glxValue = GLX_SWAP_UNDEFINED_OML; + + if (!scalarEqual(config, attrib, glxValue)) + return GL_FALSE; + + break; + default: if (!scalarEqual(config, attrib, value)) return GL_FALSE; @@ -382,16 +326,32 @@ driDestroyConfigs(const __DRIconfig **configs) free(configs); } +static struct glx_config * +driInferDrawableConfig(struct glx_screen *psc, GLXDrawable draw) +{ + unsigned int fbconfig = 0; + + if (__glXGetDrawableAttribute(psc->dpy, draw, GLX_FBCONFIG_ID, &fbconfig)) { + return glx_config_find_fbconfig(psc->configs, fbconfig); + } + + return NULL; +} + _X_HIDDEN __GLXDRIdrawable * driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable) { struct glx_display *const priv = __glXInitialize(gc->psc->dpy); __GLXDRIdrawable *pdraw; struct glx_screen *psc; + struct glx_config *config = gc->config; if (priv == NULL) return NULL; + if (glxDrawable == None) + return NULL; + psc = priv->screens[gc->screen]; if (priv->drawHash == NULL) return NULL; @@ -401,8 +361,13 @@ driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable) return pdraw; } - pdraw = psc->driScreen->createDrawable(psc, glxDrawable, - glxDrawable, gc->config); + if (config == NULL) + config = driInferDrawableConfig(gc->psc, glxDrawable); + if (config == NULL) + return NULL; + + pdraw = psc->driScreen->createDrawable(psc, glxDrawable, glxDrawable, + config); if (pdraw == NULL) { ErrorMessageF("failed to create drawable\n"); @@ -458,7 +423,7 @@ _X_HIDDEN bool dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs, unsigned *major_ver, unsigned *minor_ver, uint32_t *render_type, uint32_t *flags, unsigned *api, - int *reset, unsigned *error) + int *reset, int *release, unsigned *error) { unsigned i; bool got_profile = false; @@ -468,6 +433,7 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs, *minor_ver = 0; *render_type = GLX_RGBA_TYPE; *reset = __DRI_CTX_RESET_NO_NOTIFICATION; + *release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH; *flags = 0; *api = __DRI_API_OPENGL; @@ -513,6 +479,19 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs, return false; } break; + case GLX_CONTEXT_RELEASE_BEHAVIOR_ARB: + switch (attribs[i * 2 + 1]) { + case GLX_CONTEXT_RELEASE_BEHAVIOR_NONE_ARB: + *release = __DRI_CTX_RELEASE_BEHAVIOR_NONE; + break; + case GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB: + *release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH; + break; + default: + *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE; + return false; + } + break; default: /* If an unknown attribute is received, fail. */ @@ -540,9 +519,18 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs, case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB: *api = __DRI_API_OPENGL; break; - case GLX_CONTEXT_ES2_PROFILE_BIT_EXT: - *api = __DRI_API_GLES2; - break; + case GLX_CONTEXT_ES_PROFILE_BIT_EXT: + if (*major_ver >= 3) + *api = __DRI_API_GLES3; + else if (*major_ver == 2 && *minor_ver == 0) + *api = __DRI_API_GLES2; + else if (*major_ver == 1 && *minor_ver < 2) + *api = __DRI_API_GLES; + else { + *error = __DRI_CTX_ERROR_BAD_API; + return false; + } + break; default: *error = __DRI_CTX_ERROR_BAD_API; return false; @@ -573,19 +561,6 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs, return false; } - /* The GLX_EXT_create_context_es2_profile spec says: - * - * "... If the version requested is 2.0, and the - * GLX_CONTEXT_ES2_PROFILE_BIT_EXT bit is set in the - * GLX_CONTEXT_PROFILE_MASK_ARB attribute (see below), then the context - * returned will implement OpenGL ES 2.0. This is the only way in which - * an implementation may request an OpenGL ES 2.0 context." - */ - if (*api == __DRI_API_GLES2 && (*major_ver != 2 || *minor_ver != 0)) { - *error = __DRI_CTX_ERROR_BAD_API; - return false; - } - *error = __DRI_CTX_ERROR_SUCCESS; return true; }