Mesa (main): glx/dri: Collect the GLX context attributes in a struct
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Aug 18 22:21:08 UTC 2021
Module: Mesa
Branch: main
Commit: a521b502b93ac4a055d08804c677a692f296e9d2
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=a521b502b93ac4a055d08804c677a692f296e9d2
Author: Adam Jackson <ajax at redhat.com>
Date: Fri Aug 6 16:32:56 2021 -0400
glx/dri: Collect the GLX context attributes in a struct
dri2_convert_glx_attribs had way too many arguments, let's fix that.
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12456>
---
src/glx/dri2_glx.c | 41 +++++++-----------
src/glx/dri3_glx.c | 40 +++++++----------
src/glx/dri_common.c | 120 ++++++++++++++++++++++-----------------------------
src/glx/dri_common.h | 18 +++++---
src/glx/drisw_glx.c | 37 ++++++----------
5 files changed, 109 insertions(+), 147 deletions(-)
diff --git a/src/glx/dri2_glx.c b/src/glx/dri2_glx.c
index fe6438ad82f..2c14ccec3f3 100644
--- a/src/glx/dri2_glx.c
+++ b/src/glx/dri2_glx.c
@@ -190,29 +190,20 @@ dri2_create_context_attribs(struct glx_screen *base,
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
__DRIcontext *shared = NULL;
- uint32_t minor_ver;
- uint32_t major_ver;
- uint32_t renderType;
- uint32_t flags;
- unsigned api;
- int reset;
- int release;
+ struct dri_ctx_attribs dca;
uint32_t ctx_attribs[2 * 6];
unsigned num_ctx_attribs = 0;
- /* Remap the GLX tokens to DRI2 tokens.
- */
- if (!dri2_convert_glx_attribs(num_attribs, attribs,
- &major_ver, &minor_ver, &renderType, &flags,
- &api, &reset, &release, error))
+ *error = dri_convert_glx_attribs(num_attribs, attribs, &dca);
+ if (*error != __DRI_CTX_ERROR_SUCCESS)
goto error_exit;
- if (!dri2_check_no_error(flags, shareList, major_ver, error)) {
+ if (!dri2_check_no_error(dca.flags, shareList, dca.major_ver, error)) {
goto error_exit;
}
/* Check the renderType value */
- if (!validate_renderType_against_config(config_base, renderType))
+ if (!validate_renderType_against_config(config_base, dca.render_type))
goto error_exit;
if (shareList) {
@@ -234,44 +225,44 @@ dri2_create_context_attribs(struct glx_screen *base,
goto error_exit;
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
- ctx_attribs[num_ctx_attribs++] = major_ver;
+ ctx_attribs[num_ctx_attribs++] = dca.major_ver;
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
- ctx_attribs[num_ctx_attribs++] = minor_ver;
+ ctx_attribs[num_ctx_attribs++] = dca.minor_ver;
/* Only send a value when the non-default value is requested. By doing
* this we don't have to check the driver's DRI2 version before sending the
* default value.
*/
- if (reset != __DRI_CTX_RESET_NO_NOTIFICATION) {
+ if (dca.reset != __DRI_CTX_RESET_NO_NOTIFICATION) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_RESET_STRATEGY;
- ctx_attribs[num_ctx_attribs++] = reset;
+ ctx_attribs[num_ctx_attribs++] = dca.reset;
}
- if (release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
+ if (dca.release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR;
- ctx_attribs[num_ctx_attribs++] = release;
+ ctx_attribs[num_ctx_attribs++] = dca.release;
}
- if (flags != 0) {
+ if (dca.flags != 0) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
/* The current __DRI_CTX_FLAG_* values are identical to the
* GLX_CONTEXT_*_BIT values.
*/
- ctx_attribs[num_ctx_attribs++] = flags;
+ ctx_attribs[num_ctx_attribs++] = dca.flags;
}
/* The renderType is retrieved from attribs, or set to default
* of GLX_RGBA_TYPE.
*/
- pcp->base.renderType = renderType;
+ pcp->base.renderType = dca.render_type;
- if (flags & __DRI_CTX_FLAG_NO_ERROR)
+ if (dca.flags & __DRI_CTX_FLAG_NO_ERROR)
pcp->base.noError = GL_TRUE;
pcp->driContext =
(*psc->dri2->createContextAttribs) (psc->driScreen,
- api,
+ dca.api,
config ? config->driConfig : NULL,
shared,
num_ctx_attribs / 2,
diff --git a/src/glx/dri3_glx.c b/src/glx/dri3_glx.c
index 0bccefdb041..b551a29d66a 100644
--- a/src/glx/dri3_glx.c
+++ b/src/glx/dri3_glx.c
@@ -241,30 +241,20 @@ dri3_create_context_attribs(struct glx_screen *base,
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
__DRIcontext *shared = NULL;
- uint32_t minor_ver = 1;
- uint32_t major_ver = 2;
- uint32_t flags = 0;
- unsigned api;
- int reset = __DRI_CTX_RESET_NO_NOTIFICATION;
- int release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH;
+ struct dri_ctx_attribs dca;
uint32_t ctx_attribs[2 * 6];
unsigned num_ctx_attribs = 0;
- uint32_t render_type;
- /* Remap the GLX tokens to DRI2 tokens.
- */
- if (!dri2_convert_glx_attribs(num_attribs, attribs,
- &major_ver, &minor_ver,
- &render_type, &flags, &api,
- &reset, &release, error))
+ *error = dri_convert_glx_attribs(num_attribs, attribs, &dca);
+ if (*error != __DRI_CTX_ERROR_SUCCESS)
goto error_exit;
- if (!dri2_check_no_error(flags, shareList, major_ver, error)) {
+ if (!dri2_check_no_error(dca.flags, shareList, dca.major_ver, error)) {
goto error_exit;
}
/* Check the renderType value */
- if (!validate_renderType_against_config(config_base, render_type))
+ if (!validate_renderType_against_config(config_base, dca.render_type))
goto error_exit;
if (shareList) {
@@ -286,39 +276,39 @@ dri3_create_context_attribs(struct glx_screen *base,
goto error_exit;
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
- ctx_attribs[num_ctx_attribs++] = major_ver;
+ ctx_attribs[num_ctx_attribs++] = dca.major_ver;
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
- ctx_attribs[num_ctx_attribs++] = minor_ver;
+ ctx_attribs[num_ctx_attribs++] = dca.minor_ver;
/* Only send a value when the non-default value is requested. By doing
* this we don't have to check the driver's DRI3 version before sending the
* default value.
*/
- if (reset != __DRI_CTX_RESET_NO_NOTIFICATION) {
+ if (dca.reset != __DRI_CTX_RESET_NO_NOTIFICATION) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_RESET_STRATEGY;
- ctx_attribs[num_ctx_attribs++] = reset;
+ ctx_attribs[num_ctx_attribs++] = dca.reset;
}
- if (release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
+ if (dca.release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR;
- ctx_attribs[num_ctx_attribs++] = release;
+ ctx_attribs[num_ctx_attribs++] = dca.release;
}
- if (flags != 0) {
+ if (dca.flags != 0) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
/* The current __DRI_CTX_FLAG_* values are identical to the
* GLX_CONTEXT_*_BIT values.
*/
- ctx_attribs[num_ctx_attribs++] = flags;
+ ctx_attribs[num_ctx_attribs++] = dca.flags;
- if (flags & __DRI_CTX_FLAG_NO_ERROR)
+ if (dca.flags & __DRI_CTX_FLAG_NO_ERROR)
pcp->base.noError = GL_TRUE;
}
pcp->driContext =
(*psc->image_driver->createContextAttribs) (psc->driScreen,
- api,
+ dca.api,
config ? config->driConfig
: NULL,
shared,
diff --git a/src/glx/dri_common.c b/src/glx/dri_common.c
index 8fe8802bed7..95df0704fde 100644
--- a/src/glx/dri_common.c
+++ b/src/glx/dri_common.c
@@ -418,46 +418,40 @@ driReleaseDrawables(struct glx_context *gc)
}
-_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, int *release, unsigned *error)
+_X_HIDDEN int
+dri_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
+ struct dri_ctx_attribs *dca)
{
unsigned i;
bool got_profile = false;
int no_error = 0;
uint32_t profile;
- *major_ver = 1;
- *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;
+ dca->major_ver = 1;
+ dca->minor_ver = 0;
+ dca->render_type = GLX_RGBA_TYPE;
+ dca->reset = __DRI_CTX_RESET_NO_NOTIFICATION;
+ dca->release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH;
+ dca->flags = 0;
+ dca->api = __DRI_API_OPENGL;
- if (num_attribs == 0) {
- return true;
- }
+ if (num_attribs == 0)
+ return __DRI_CTX_ERROR_SUCCESS;
- /* This is actually an internal error, but what the heck.
- */
- if (attribs == NULL) {
- *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
- return false;
- }
+ /* This is actually an internal error, but what the heck. */
+ if (attribs == NULL)
+ return __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
for (i = 0; i < num_attribs; i++) {
switch (attribs[i * 2]) {
case GLX_CONTEXT_MAJOR_VERSION_ARB:
- *major_ver = attribs[i * 2 + 1];
+ dca->major_ver = attribs[i * 2 + 1];
break;
case GLX_CONTEXT_MINOR_VERSION_ARB:
- *minor_ver = attribs[i * 2 + 1];
+ dca->minor_ver = attribs[i * 2 + 1];
break;
case GLX_CONTEXT_FLAGS_ARB:
- *flags = attribs[i * 2 + 1];
+ dca->flags = attribs[i * 2 + 1];
break;
case GLX_CONTEXT_OPENGL_NO_ERROR_ARB:
no_error = attribs[i * 2 + 1];
@@ -467,53 +461,50 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
got_profile = true;
break;
case GLX_RENDER_TYPE:
- *render_type = attribs[i * 2 + 1];
+ dca->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;
+ dca->reset = __DRI_CTX_RESET_NO_NOTIFICATION;
break;
case GLX_LOSE_CONTEXT_ON_RESET_ARB:
- *reset = __DRI_CTX_RESET_LOSE_CONTEXT;
+ dca->reset = __DRI_CTX_RESET_LOSE_CONTEXT;
break;
default:
- *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
- return false;
+ return __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
}
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;
+ dca->release = __DRI_CTX_RELEASE_BEHAVIOR_NONE;
break;
case GLX_CONTEXT_RELEASE_BEHAVIOR_FLUSH_ARB:
- *release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH;
+ dca->release = __DRI_CTX_RELEASE_BEHAVIOR_FLUSH;
break;
default:
- *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
- return false;
+ return __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
}
break;
case GLX_SCREEN:
/* Implies GLX_EXT_no_config_context */
- *render_type = GLX_DONT_CARE;
+ dca->render_type = GLX_DONT_CARE;
break;
default:
/* If an unknown attribute is received, fail.
*/
- *error = __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
- return false;
+ return __DRI_CTX_ERROR_UNKNOWN_ATTRIBUTE;
}
}
if (no_error) {
- *flags |= __DRI_CTX_FLAG_NO_ERROR;
+ dca->flags |= __DRI_CTX_FLAG_NO_ERROR;
}
if (!got_profile) {
- if (*major_ver > 3 || (*major_ver == 3 && *minor_ver >= 2))
- *api = __DRI_API_OPENGL_CORE;
+ if (dca->major_ver > 3 || (dca->major_ver == 3 && dca->minor_ver >= 2))
+ dca->api = __DRI_API_OPENGL_CORE;
} else {
switch (profile) {
case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
@@ -524,38 +515,34 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
* 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))
+ dca->api = (dca->major_ver > 3 || (dca->major_ver == 3 && dca->minor_ver >= 2))
? __DRI_API_OPENGL_CORE : __DRI_API_OPENGL;
break;
case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
- *api = __DRI_API_OPENGL;
+ dca->api = __DRI_API_OPENGL;
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;
+ if (dca->major_ver >= 3)
+ dca->api = __DRI_API_GLES3;
+ else if (dca->major_ver == 2 && dca->minor_ver == 0)
+ dca->api = __DRI_API_GLES2;
+ else if (dca->major_ver == 1 && dca->minor_ver < 2)
+ dca->api = __DRI_API_GLES;
else {
- *error = __DRI_CTX_ERROR_BAD_API;
- return false;
+ return __DRI_CTX_ERROR_BAD_API;
}
break;
default:
- *error = __DRI_CTX_ERROR_BAD_API;
- return false;
+ return __DRI_CTX_ERROR_BAD_API;
}
}
- /* Unknown flag value.
- */
- if (*flags & ~(__DRI_CTX_FLAG_DEBUG | __DRI_CTX_FLAG_FORWARD_COMPATIBLE
- | __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS
- | __DRI_CTX_FLAG_NO_ERROR)) {
- *error = __DRI_CTX_ERROR_UNKNOWN_FLAG;
- return false;
- }
+ /* Unknown flag value */
+ if (dca->flags & ~(__DRI_CTX_FLAG_DEBUG |
+ __DRI_CTX_FLAG_FORWARD_COMPATIBLE |
+ __DRI_CTX_FLAG_ROBUST_BUFFER_ACCESS |
+ __DRI_CTX_FLAG_NO_ERROR))
+ return __DRI_CTX_ERROR_UNKNOWN_FLAG;
/* There are no forward-compatible contexts before OpenGL 3.0. The
* GLX_ARB_create_context spec says:
@@ -563,18 +550,13 @@ dri2_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
* "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 (dca->major_ver < 3 && (dca->flags & __DRI_CTX_FLAG_FORWARD_COMPATIBLE) != 0)
+ return __DRI_CTX_ERROR_BAD_FLAG;
- if (*major_ver >= 3 && *render_type == GLX_COLOR_INDEX_TYPE) {
- *error = __DRI_CTX_ERROR_BAD_FLAG;
- return false;
- }
+ if (dca->major_ver >= 3 && dca->render_type == GLX_COLOR_INDEX_TYPE)
+ return __DRI_CTX_ERROR_BAD_FLAG;
- *error = __DRI_CTX_ERROR_SUCCESS;
- return true;
+ return __DRI_CTX_ERROR_SUCCESS;
}
_X_HIDDEN bool
diff --git a/src/glx/dri_common.h b/src/glx/dri_common.h
index 5a5ab0e626f..455e8541ed8 100644
--- a/src/glx/dri_common.h
+++ b/src/glx/dri_common.h
@@ -66,11 +66,19 @@ driReleaseDrawables(struct glx_context *gc);
extern const __DRIextension **driOpenDriver(const char *driverName,
void **out_driver_handle);
-extern 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, int *release, unsigned *error);
+struct dri_ctx_attribs {
+ unsigned major_ver;
+ unsigned minor_ver;
+ uint32_t render_type;
+ uint32_t flags;
+ unsigned api;
+ int reset;
+ int release;
+};
+
+extern int
+dri_convert_glx_attribs(unsigned num_attribs, const uint32_t *attribs,
+ struct dri_ctx_attribs *dca);
extern bool
dri2_check_no_error(uint32_t flags, struct glx_context *share_context,
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index ea5c733ebb8..b1e9a1f4760 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -509,13 +509,7 @@ drisw_create_context_attribs(struct glx_screen *base,
struct drisw_screen *psc = (struct drisw_screen *) base;
__DRIcontext *shared = NULL;
- uint32_t minor_ver;
- uint32_t major_ver;
- uint32_t renderType;
- uint32_t flags;
- unsigned api;
- int reset;
- int release;
+ struct dri_ctx_attribs dca;
uint32_t ctx_attribs[2 * 5];
unsigned num_ctx_attribs = 0;
@@ -525,18 +519,15 @@ drisw_create_context_attribs(struct glx_screen *base,
if (psc->swrast->base.version < 3)
return NULL;
- /* Remap the GLX tokens to DRI2 tokens.
- */
- if (!dri2_convert_glx_attribs(num_attribs, attribs,
- &major_ver, &minor_ver, &renderType, &flags,
- &api, &reset, &release, error))
+ *error = dri_convert_glx_attribs(num_attribs, attribs, &dca);
+ if (*error != __DRI_CTX_ERROR_SUCCESS)
return NULL;
- if (!dri2_check_no_error(flags, shareList, major_ver, error))
+ if (!dri2_check_no_error(dca.flags, shareList, dca.major_ver, error))
return NULL;
/* Check the renderType value */
- if (!validate_renderType_against_config(config_base, renderType)) {
+ if (!validate_renderType_against_config(config_base, dca.render_type)) {
return NULL;
}
@@ -559,31 +550,31 @@ drisw_create_context_attribs(struct glx_screen *base,
}
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
- ctx_attribs[num_ctx_attribs++] = major_ver;
+ ctx_attribs[num_ctx_attribs++] = dca.major_ver;
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
- ctx_attribs[num_ctx_attribs++] = minor_ver;
- if (release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
+ ctx_attribs[num_ctx_attribs++] = dca.minor_ver;
+ if (dca.release != __DRI_CTX_RELEASE_BEHAVIOR_FLUSH) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_RELEASE_BEHAVIOR;
- ctx_attribs[num_ctx_attribs++] = release;
+ ctx_attribs[num_ctx_attribs++] = dca.release;
}
- if (flags != 0) {
+ if (dca.flags != 0) {
ctx_attribs[num_ctx_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
/* The current __DRI_CTX_FLAG_* values are identical to the
* GLX_CONTEXT_*_BIT values.
*/
- ctx_attribs[num_ctx_attribs++] = flags;
+ ctx_attribs[num_ctx_attribs++] = dca.flags;
- if (flags & __DRI_CTX_FLAG_NO_ERROR)
+ if (dca.flags & __DRI_CTX_FLAG_NO_ERROR)
pcp->base.noError = GL_TRUE;
}
- pcp->base.renderType = renderType;
+ pcp->base.renderType = dca.render_type;
pcp->driContext =
(*psc->swrast->createContextAttribs) (psc->driScreen,
- api,
+ dca.api,
config ? config->driConfig : 0,
shared,
num_ctx_attribs / 2,
More information about the mesa-commit
mailing list