[Mesa-dev] [PATCH 02/20] st-api: Have context_create explain why creation failed

Ian Romanick idr at freedesktop.org
Tue Dec 20 12:31:05 PST 2011


From: Ian Romanick <ian.d.romanick at intel.com>

This won't be used in the client-side libGL, but the xserver has to
generate a different protocol error depending on the reason context
creation failed.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/gallium/include/state_tracker/st_api.h         |   14 ++++++++++++++
 .../state_trackers/dri/common/dri_context.c        |    4 +++-
 src/gallium/state_trackers/vega/vg_manager.c       |   14 +++++++++++---
 src/mesa/state_tracker/st_manager.c                |    9 ++++++++-
 4 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/src/gallium/include/state_tracker/st_api.h b/src/gallium/include/state_tracker/st_api.h
index 3267cb2..da49dc8 100644
--- a/src/gallium/include/state_tracker/st_api.h
+++ b/src/gallium/include/state_tracker/st_api.h
@@ -80,6 +80,19 @@ enum st_profile_type
 #define ST_CONTEXT_FLAG_ROBUST_ACCESS       (1 << 2)
 
 /**
+ * Reasons that context creation might fail.
+ */
+enum st_context_error {
+   ST_CONTEXT_SUCCESS = 0,
+   ST_CONTEXT_ERROR_NO_MEMORY,
+   ST_CONTEXT_ERROR_BAD_API,
+   ST_CONTEXT_ERROR_BAD_VERSION,
+   ST_CONTEXT_ERROR_BAD_FLAG,
+   ST_CONTEXT_ERROR_UNKNOWN_ATTRIBUTE,
+   ST_CONTEXT_ERROR_UNKNOWN_FLAG
+};
+
+/**
  * Used in st_context_iface->teximage.
  */
 enum st_texture_type {
@@ -434,6 +447,7 @@ struct st_api
    struct st_context_iface *(*create_context)(struct st_api *stapi,
                                               struct st_manager *smapi,
                                               const struct st_context_attribs *attribs,
+                                              enum st_context_error *error,
                                               struct st_context_iface *stsharei);
 
    /**
diff --git a/src/gallium/state_trackers/dri/common/dri_context.c b/src/gallium/state_trackers/dri/common/dri_context.c
index e9e0049..3e5a040 100644
--- a/src/gallium/state_trackers/dri/common/dri_context.c
+++ b/src/gallium/state_trackers/dri/common/dri_context.c
@@ -58,6 +58,7 @@ dri_create_context(gl_api api, const struct gl_config * visual,
    struct dri_context *ctx = NULL;
    struct st_context_iface *st_share = NULL;
    struct st_context_attribs attribs;
+   enum st_context_error ctx_err = 0;
 
    memset(&attribs, 0, sizeof(attribs));
    switch (api) {
@@ -88,7 +89,8 @@ dri_create_context(gl_api api, const struct gl_config * visual,
 		       &screen->optionCache, sPriv->myNum, "dri");
 
    dri_fill_st_visual(&attribs.visual, screen, visual);
-   ctx->st = stapi->create_context(stapi, &screen->base, &attribs, st_share);
+   ctx->st = stapi->create_context(stapi, &screen->base, &attribs, &ctx_err,
+				   st_share);
    if (ctx->st == NULL)
       goto fail;
    ctx->st->st_manager_private = (void *) ctx;
diff --git a/src/gallium/state_trackers/vega/vg_manager.c b/src/gallium/state_trackers/vega/vg_manager.c
index dec1581..e88f5f1 100644
--- a/src/gallium/state_trackers/vega/vg_manager.c
+++ b/src/gallium/state_trackers/vega/vg_manager.c
@@ -163,28 +163,36 @@ vg_context_destroy(struct st_context_iface *stctxi)
 static struct st_context_iface *
 vg_api_create_context(struct st_api *stapi, struct st_manager *smapi,
                       const struct st_context_attribs *attribs,
+                      enum st_context_error *error,
                       struct st_context_iface *shared_stctxi)
 {
    struct vg_context *shared_ctx = (struct vg_context *) shared_stctxi;
    struct vg_context *ctx;
    struct pipe_context *pipe;
 
-   if (!(stapi->profile_mask & (1 << attribs->profile)))
+   if (!(stapi->profile_mask & (1 << attribs->profile))) {
+      *error = ST_CONTEXT_ERROR_BAD_API;
       return NULL;
+   }
 
    /* only 1.0 is supported */
-   if (attribs->major > 1 || (attribs->major == 1 && attribs->minor > 0))
+   if (attribs->major > 1 || (attribs->major == 1 && attribs->minor > 0)) {
+      *error = ST_CONTEXT_ERROR_BAD_VERSION;
       return NULL;
+   }
 
    /* for VGHandle / pointer lookups */
    init_handles();
 
    pipe = smapi->screen->context_create(smapi->screen, NULL);
-   if (!pipe)
+   if (!pipe) {
+      *error = ST_CONTEXT_ERROR_NO_MEMORY;
       return NULL;
+   }
    ctx = vg_create_context(pipe, NULL, shared_ctx);
    if (!ctx) {
       pipe->destroy(pipe);
+      *error = ST_CONTEXT_ERROR_NO_MEMORY;
       return NULL;
    }
 
diff --git a/src/mesa/state_tracker/st_manager.c b/src/mesa/state_tracker/st_manager.c
index 55699e7..828f0d8 100644
--- a/src/mesa/state_tracker/st_manager.c
+++ b/src/mesa/state_tracker/st_manager.c
@@ -600,6 +600,7 @@ st_context_destroy(struct st_context_iface *stctxi)
 static struct st_context_iface *
 st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
                       const struct st_context_attribs *attribs,
+                      enum st_context_error *error,
                       struct st_context_iface *shared_stctxi)
 {
    struct st_context *shared_ctx = (struct st_context *) shared_stctxi;
@@ -623,17 +624,21 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
       break;
    case ST_PROFILE_OPENGL_CORE:
    default:
+      *error = ST_CONTEXT_ERROR_BAD_API;
       return NULL;
       break;
    }
 
    pipe = smapi->screen->context_create(smapi->screen, NULL);
-   if (!pipe)
+   if (!pipe) {
+      *error = ST_CONTEXT_ERROR_NO_MEMORY;
       return NULL;
+   }
 
    st_visual_to_context_mode(&attribs->visual, &mode);
    st = st_create_context(api, pipe, &mode, shared_ctx);
    if (!st) {
+      *error = ST_CONTEXT_ERROR_NO_MEMORY;
       pipe->destroy(pipe);
       return NULL;
    }
@@ -645,6 +650,7 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
       /* is the actual version less than the requested version? */
       if (st->ctx->VersionMajor * 10 + st->ctx->VersionMinor <
           attribs->major * 10 + attribs->minor) {
+	 *error = ST_CONTEXT_ERROR_BAD_VERSION;
          st_destroy_context(st);
          return NULL;
       }
@@ -660,6 +666,7 @@ st_api_create_context(struct st_api *stapi, struct st_manager *smapi,
    st->iface.share = st_context_share;
    st->iface.st_context_private = (void *) smapi;
 
+   *error = ST_CONTEXT_SUCCESS;
    return &st->iface;
 }
 
-- 
1.7.6.4



More information about the mesa-dev mailing list