X-Git-Url: https://git.libre-soc.org/?a=blobdiff_plain;f=src%2Fglx%2Fdri_common.c;h=d170aa6f7e248923624a8324dc8c6b0bd17b2e1b;hb=a8724d85f8cb2f0fb73b9c6c1f268f9084c6d473;hp=83d6e3c31082ca22420e58468be3535ce268bb66;hpb=0072acd447dc6be652e63752e50215c3105322c8;p=mesa.git diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c index 83d6e3c3108..d170aa6f7e2 100644 --- a/src/glx/dri_common.c +++ b/src/glx/dri_common.c @@ -48,6 +48,10 @@ #define RTLD_GLOBAL 0 #endif +/** + * Print informational message to stderr if LIBGL_DEBUG is set to + * "verbose". + */ _X_HIDDEN void InfoMessageF(const char *f, ...) { @@ -63,7 +67,8 @@ InfoMessageF(const char *f, ...) } /** - * Print error to stderr, unless LIBGL_DEBUG=="quiet". + * Print error message to stderr if LIBGL_DEBUG is set to anything but + * "quiet", (do nothing if LIBGL_DEBUG is unset). */ _X_HIDDEN void ErrorMessageF(const char *f, ...) @@ -79,6 +84,30 @@ ErrorMessageF(const char *f, ...) } } +/** + * Print error message unless LIBGL_DEBUG is set to "quiet". + * + * The distinction between CriticalErrorMessageF and ErrorMessageF is + * that critcial errors will be printed by default, (even when + * LIBGL_DEBUG is unset). + */ +_X_HIDDEN void +CriticalErrorMessageF(const char *f, ...) +{ + va_list args; + const char *env; + + if (!(env = getenv("LIBGL_DEBUG")) || !strstr(env, "quiet")) { + fprintf(stderr, "libGL error: "); + va_start(args, f); + vfprintf(stderr, f, args); + va_end(args); + + if (!env || !strstr(env, "verbose")) + fprintf(stderr, "libGL error: Try again with LIBGL_DEBUG=verbose for more details.\n"); + } +} + #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" @@ -91,7 +120,7 @@ ErrorMessageF(const char *f, ...) * directories specified by the \c LIBGL_DRIVERS_PATH environment variable in * order to find the driver. * - * \param driverName - a name like "tdfx", "i810", "mga", etc. + * \param driverName - a name like "i965", "radeon", "nouveau", etc. * * \returns * A handle from \c dlopen, or \c NULL if driver file not found. @@ -222,7 +251,9 @@ __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGB, bindToTextureRgb), __ATTRIB(__DRI_ATTRIB_BIND_TO_TEXTURE_RGBA, bindToTextureRgba), __ATTRIB(__DRI_ATTRIB_BIND_TO_MIPMAP_TEXTURE, bindToMipmapTexture), - __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted),}; + __ATTRIB(__DRI_ATTRIB_YINVERTED, yInverted), + __ATTRIB(__DRI_ATTRIB_FRAMEBUFFER_SRGB_CAPABLE, sRGBCapable) +}; static int scalarEqual(struct glx_config *mode, unsigned int attrib, unsigned int value) @@ -338,8 +369,6 @@ driConvertConfigs(const __DRIcoreExtension * core, tail = tail->next; } - glx_config_destroy_list(configs); - return head.next; } @@ -367,15 +396,24 @@ driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable) if (priv->drawHash == NULL) return NULL; - if (__glxHashLookup(priv->drawHash, glxDrawable, (void *) &pdraw) == 0) + if (__glxHashLookup(priv->drawHash, glxDrawable, (void *) &pdraw) == 0) { + pdraw->refcount ++; return pdraw; + } pdraw = psc->driScreen->createDrawable(psc, glxDrawable, glxDrawable, gc->config); + + if (pdraw == NULL) { + ErrorMessageF("failed to create drawable\n"); + return NULL; + } + if (__glxHashInsert(priv->drawHash, glxDrawable, pdraw)) { (*pdraw->destroyDrawable) (pdraw); return NULL; } + pdraw->refcount = 1; return pdraw; } @@ -383,7 +421,7 @@ driFetchDrawable(struct glx_context *gc, GLXDrawable glxDrawable) _X_HIDDEN void driReleaseDrawables(struct glx_context *gc) { - struct glx_display *const priv = __glXInitialize(gc->psc->dpy); + const struct glx_display *priv = gc->psc->display; __GLXDRIdrawable *pdraw; if (priv == NULL) @@ -392,19 +430,164 @@ driReleaseDrawables(struct glx_context *gc) if (__glxHashLookup(priv->drawHash, gc->currentDrawable, (void *) &pdraw) == 0) { if (pdraw->drawable == pdraw->xDrawable) { - (*pdraw->destroyDrawable)(pdraw); - __glxHashDelete(priv->drawHash, gc->currentDrawable); + pdraw->refcount --; + if (pdraw->refcount == 0) { + (*pdraw->destroyDrawable)(pdraw); + __glxHashDelete(priv->drawHash, gc->currentDrawable); + } } } - if (gc->currentDrawable != gc->currentReadable && - __glxHashLookup(priv->drawHash, + if (__glxHashLookup(priv->drawHash, gc->currentReadable, (void *) &pdraw) == 0) { if (pdraw->drawable == pdraw->xDrawable) { - (*pdraw->destroyDrawable)(pdraw); - __glxHashDelete(priv->drawHash, gc->currentReadable); + pdraw->refcount --; + if (pdraw->refcount == 0) { + (*pdraw->destroyDrawable)(pdraw); + __glxHashDelete(priv->drawHash, gc->currentReadable); + } } } + + gc->currentDrawable = None; + gc->currentReadable = None; + +} + +_X_HIDDEN bool +dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs, + unsigned *major_ver, unsigned *minor_ver, + uint32_t *flags, unsigned *api, int *reset, + unsigned *error) +{ + unsigned i; + bool got_profile = false; + uint32_t profile; + int render_type = GLX_RGBA_TYPE; + + if (num_attribs == 0) { + *api = __DRI_API_OPENGL; + return true; + } + + /* This is actually an internal error, but what the heck. + */ + if (attribs == NULL) { + *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE; + return false; + } + + *major_ver = 1; + *minor_ver = 0; + *reset = __DRI_CTX_RESET_NO_NOTIFICATION; + + for (i = 0; i < num_attribs; i++) { + switch (attribs[i * 2]) { + case GLX_CONTEXT_MAJOR_VERSION_ARB: + *major_ver = attribs[i * 2 + 1]; + break; + case GLX_CONTEXT_MINOR_VERSION_ARB: + *minor_ver = attribs[i * 2 + 1]; + break; + case GLX_CONTEXT_FLAGS_ARB: + *flags = attribs[i * 2 + 1]; + break; + case GLX_CONTEXT_PROFILE_MASK_ARB: + profile = attribs[i * 2 + 1]; + got_profile = true; + break; + case GLX_RENDER_TYPE: + render_type = attribs[i * 2 + 1]; + break; + case GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB: + switch (attribs[i * 2 + 1]) { + case GLX_NO_RESET_NOTIFICATION_ARB: + *reset = __DRI_CTX_RESET_NO_NOTIFICATION; + break; + case GLX_LOSE_CONTEXT_ON_RESET_ARB: + *reset = __DRI_CTX_RESET_LOSE_CONTEXT; + break; + default: + *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE; + return false; + } + break; + default: + /* If an unknown attribute is received, fail. + */ + *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE; + return false; + } + } + + *api = __DRI_API_OPENGL; + if (!got_profile) { + if (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2)) + *api = __DRI_API_OPENGL_CORE; + } else { + switch (profile) { + case GLX_CONTEXT_CORE_PROFILE_BIT_ARB: + /* There are no profiles before OpenGL 3.2. The + * GLX_ARB_create_context_profile spec says: + * + * "If the requested OpenGL version is less than 3.2, + * GLX_CONTEXT_PROFILE_MASK_ARB is ignored and the functionality + * of the context is determined solely by the requested version." + */ + *api = (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2)) + ? __DRI_API_OPENGL_CORE : __DRI_API_OPENGL; + break; + case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB: + *api = __DRI_API_OPENGL; + break; + case GLX_CONTEXT_ES2_PROFILE_BIT_EXT: + *api = __DRI_API_GLES2; + break; + default: + *error = __DRI_CTX_ERROR_BAD_API; + return false; + } + } + + /* Unknown flag value. + */ + if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE + | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS)) { + *error = __DRI_CTX_ERROR_UNKNOWN_FLAG; + return false; + } + + /* There are no forward-compatible contexts before OpenGL 3.0. The + * GLX_ARB_create_context spec says: + * + * "Forward-compatible contexts are defined only for OpenGL versions + * 3.0 and later." + */ + if (*major_ver < 3 && (*flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0) { + *error = __DRI_CTX_ERROR_BAD_FLAG; + return false; + } + + if (*major_ver >= 3 && render_type == GLX_COLOR_INDEX_TYPE) { + *error = __DRI_CTX_ERROR_BAD_FLAG; + 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; } #endif /* GLX_DIRECT_RENDERING */