glx: Handle create_context in terms of create_context_attribs

For the DRI backends we factor this out to a dri_common_create_context
method. Indirect gets the same transformation but doesn't use the common
method since it can't rely on DRI being built.

Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7660>
This commit is contained in:
Adam Jackson 2020-11-10 16:06:47 -05:00 committed by Marge Bot
parent c4ed0e8f3f
commit 63822802ef
6 changed files with 49 additions and 150 deletions

View file

@ -176,57 +176,6 @@ dri2_unbind_context(struct glx_context *context, struct glx_context *new)
(*psc->core->unbindContext) (pcp->driContext);
}
static struct glx_context *
dri2_create_context(struct glx_screen *base,
struct glx_config *config_base,
struct glx_context *shareList, int renderType)
{
struct dri2_context *pcp, *pcp_shared;
struct dri2_screen *psc = (struct dri2_screen *) base;
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
__DRIcontext *shared = NULL;
/* Check the renderType value */
if (!validate_renderType_against_config(config_base, renderType))
return NULL;
if (shareList) {
/* If the shareList context is not a DRI2 context, we cannot possibly
* create a DRI2 context that shares it.
*/
if (shareList->vtable->destroy != dri2_destroy_context) {
return NULL;
}
pcp_shared = (struct dri2_context *) shareList;
shared = pcp_shared->driContext;
}
pcp = calloc(1, sizeof *pcp);
if (pcp == NULL)
return NULL;
if (!glx_context_init(&pcp->base, &psc->base, &config->base)) {
free(pcp);
return NULL;
}
pcp->base.renderType = renderType;
pcp->driContext =
(*psc->dri2->createNewContext) (psc->driScreen,
config->driConfig, shared, pcp);
if (pcp->driContext == NULL) {
free(pcp);
return NULL;
}
pcp->base.vtable = &dri2_context_vtable;
return &pcp->base;
}
static struct glx_context *
dri2_create_context_attribs(struct glx_screen *base,
struct glx_config *config_base,
@ -1219,7 +1168,7 @@ dri2_get_driver_name(struct glx_screen *glx_screen)
}
static const struct glx_screen_vtable dri2_screen_vtable = {
.create_context = dri2_create_context,
.create_context = dri_common_create_context,
.create_context_attribs = dri2_create_context_attribs,
.query_renderer_integer = dri2_query_renderer_integer,
.query_renderer_string = dri2_query_renderer_string,

View file

@ -343,18 +343,6 @@ error_exit:
return NULL;
}
static struct glx_context *
dri3_create_context(struct glx_screen *base,
struct glx_config *config_base,
struct glx_context *shareList, int renderType)
{
unsigned int error;
uint32_t attribs[2] = { GLX_RENDER_TYPE, renderType };
return dri3_create_context_attribs(base, config_base, shareList,
1, attribs, &error);
}
static void
dri3_destroy_drawable(__GLXDRIdrawable *base)
{
@ -822,7 +810,7 @@ dri3_get_driver_name(struct glx_screen *glx_screen)
}
static const struct glx_screen_vtable dri3_screen_vtable = {
.create_context = dri3_create_context,
.create_context = dri_common_create_context,
.create_context_attribs = dri3_create_context_attribs,
.query_renderer_integer = dri3_query_renderer_integer,
.query_renderer_string = dri3_query_renderer_string,

View file

@ -602,6 +602,20 @@ dri2_check_no_error(uint32_t flags, struct glx_context *share_context,
return true;
}
struct glx_context *
dri_common_create_context(struct glx_screen *base,
struct glx_config *config_base,
struct glx_context *shareList,
int renderType)
{
unsigned int error;
uint32_t attribs[2] = { GLX_RENDER_TYPE, renderType };
return base->vtable->create_context_attribs(base, config_base, shareList,
1, attribs, &error);
}
/*
* Given a display pointer and screen number, determine the name of
* the DRI driver for the screen (i.e., "i965", "radeon", "nouveau", etc).

View file

@ -83,6 +83,12 @@ dri2_check_no_error(uint32_t flags, struct glx_context *share_context,
int major, unsigned *error);
extern struct glx_context *
dri_common_create_context(struct glx_screen *base,
struct glx_config *config_base,
struct glx_context *shareList,
int renderType);
#endif /* GLX_DIRECT_RENDERING */
#endif /* _DRI_COMMON_H */

View file

@ -482,59 +482,6 @@ static const struct glx_context_vtable drisw_context_vtable = {
.get_proc_address = NULL,
};
static struct glx_context *
drisw_create_context(struct glx_screen *base,
struct glx_config *config_base,
struct glx_context *shareList, int renderType)
{
struct drisw_context *pcp, *pcp_shared;
__GLXDRIconfigPrivate *config = (__GLXDRIconfigPrivate *) config_base;
struct drisw_screen *psc = (struct drisw_screen *) base;
__DRIcontext *shared = NULL;
if (!psc->base.driScreen)
return NULL;
/* Check the renderType value */
if (!validate_renderType_against_config(config_base, renderType))
return NULL;
if (shareList) {
/* If the shareList context is not a DRISW context, we cannot possibly
* create a DRISW context that shares it.
*/
if (shareList->vtable->destroy != drisw_destroy_context) {
return NULL;
}
pcp_shared = (struct drisw_context *) shareList;
shared = pcp_shared->driContext;
}
pcp = calloc(1, sizeof *pcp);
if (pcp == NULL)
return NULL;
if (!glx_context_init(&pcp->base, &psc->base, &config->base)) {
free(pcp);
return NULL;
}
pcp->base.renderType = renderType;
pcp->driContext =
(*psc->core->createNewContext) (psc->driScreen,
config->driConfig, shared, pcp);
if (pcp->driContext == NULL) {
free(pcp);
return NULL;
}
pcp->base.vtable = &drisw_context_vtable;
return &pcp->base;
}
static struct glx_context *
drisw_create_context_attribs(struct glx_screen *base,
struct glx_config *config_base,
@ -782,7 +729,7 @@ drisw_get_driver_name(struct glx_screen *glx_screen)
}
static const struct glx_screen_vtable drisw_screen_vtable = {
.create_context = drisw_create_context,
.create_context = dri_common_create_context,
.create_context_attribs = drisw_create_context_attribs,
.query_renderer_integer = drisw_query_renderer_integer,
.query_renderer_string = drisw_query_renderer_string,

View file

@ -348,6 +348,18 @@ static const struct glx_context_vtable indirect_context_vtable = {
.get_proc_address = NULL,
};
_X_HIDDEN struct glx_context *
indirect_create_context(struct glx_screen *psc,
struct glx_config *mode,
struct glx_context *shareList, int renderType)
{
unsigned error = 0;
const uint32_t attribs[] = { GLX_RENDER_TYPE, renderType };
return indirect_create_context_attribs(psc, mode, shareList,
1, attribs, &error);
}
/**
* \todo Eliminate \c __glXInitVertexArrayState. Replace it with a new
* function called \c __glXAllocateClientState that allocates the memory and
@ -358,20 +370,31 @@ static const struct glx_context_vtable indirect_context_vtable = {
* parameters. It is just the allocator for the \c glx_context.
*/
_X_HIDDEN struct glx_context *
indirect_create_context(struct glx_screen *psc,
struct glx_config *mode,
struct glx_context *shareList, int renderType)
indirect_create_context_attribs(struct glx_screen *psc,
struct glx_config *mode,
struct glx_context *shareList,
unsigned num_attribs,
const uint32_t *attribs,
unsigned *error)
{
struct glx_context *gc;
int bufSize;
CARD8 opcode;
__GLXattribute *state;
int i, renderType = GLX_RGBA_TYPE;
opcode = __glXSetupForCommand(psc->dpy);
if (!opcode) {
return NULL;
}
for (i = 0; i < num_attribs; i++) {
uint32_t attr = attribs[i*2], val = attribs[i*2 + 1];
if (attr == GLX_RENDER_TYPE)
renderType = val;
}
/* Allocate our context record */
gc = calloc(1, sizeof *gc);
if (!gc) {
@ -449,34 +472,6 @@ indirect_create_context(struct glx_screen *psc,
return gc;
}
_X_HIDDEN struct glx_context *
indirect_create_context_attribs(struct glx_screen *base,
struct glx_config *config_base,
struct glx_context *shareList,
unsigned num_attribs,
const uint32_t *attribs,
unsigned *error)
{
int renderType = GLX_RGBA_TYPE;
unsigned i;
/* The error parameter is only used on the server so that correct GLX
* protocol errors can be generated. On the client, it can be ignored.
*/
(void) error;
/* All of the attribute validation for indirect contexts is handled on the
* server, so there's not much to do here. Still, we need to parse the
* attributes to correctly set renderType.
*/
for (i = 0; i < num_attribs; i++) {
if (attribs[i * 2] == GLX_RENDER_TYPE)
renderType = attribs[i * 2 + 1];
}
return indirect_create_context(base, config_base, shareList, renderType);
}
static const struct glx_screen_vtable indirect_screen_vtable = {
.create_context = indirect_create_context,
.create_context_attribs = indirect_create_context_attribs,