i965: Clean up error handling for context creation.
authorEric Anholt <eric@anholt.net>
Fri, 27 Sep 2013 00:08:28 +0000 (17:08 -0700)
committerEric Anholt <eric@anholt.net>
Thu, 10 Oct 2013 23:34:30 +0000 (16:34 -0700)
The intel_screen.c used to be a dispatch to one of 3 driver functions, but
was down to 1, so it was kind of a waste.  In addition, it was trying to
free all of the data that might have been partially freed in the kernel
3.6 check (which comes after intelInitContext, and thus might have had
driverPrivate set and result in intelDestroyContext() doing work on the
freed data).  By moving the driverPrivate setup earlier, we can use
intelDestroyContext() consistently and avoid such problems in the future.

v2: Adjust the prototype of brwCreateContext to use the proper enum
    (fixing a compiler warning in some builds)

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> (v1)
src/mesa/drivers/dri/i965/brw_context.c
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/intel_context.c
src/mesa/drivers/dri/i965/intel_screen.c

index 776d22139349b67a78966f092c5dd6b10935c613..c648d30cfaa80d7ce5511b7d8a36367c9616e185 100644 (file)
@@ -276,7 +276,7 @@ brw_initialize_context_constants(struct brw_context *brw)
 }
 
 bool
-brwCreateContext(int api,
+brwCreateContext(gl_api api,
                 const struct gl_config *mesaVis,
                 __DRIcontext *driContextPriv,
                  unsigned major_version,
@@ -311,7 +311,7 @@ brwCreateContext(int api,
                           mesaVis, driContextPriv,
                          sharedContextPrivate, &functions,
                          error)) {
-      ralloc_free(brw);
+      intelDestroyContext(driContextPriv);
       return false;
    }
 
@@ -332,7 +332,7 @@ brwCreateContext(int api,
 
       if (!brw->hw_ctx) {
          fprintf(stderr, "Gen6+ requires Kernel 3.6 or later.\n");
-         ralloc_free(brw);
+         intelDestroyContext(driContextPriv);
          return false;
       }
    }
index fee4e1a77344fb569150a7685c2e5a9fd210a52c..28ae261a68ae955551903bc90d720616369536d3 100644 (file)
@@ -1410,7 +1410,7 @@ void brwInitVtbl( struct brw_context *brw );
 /*======================================================================
  * brw_context.c
  */
-bool brwCreateContext(int api,
+bool brwCreateContext(gl_api api,
                      const struct gl_config *mesaVis,
                      __DRIcontext *driContextPriv,
                       unsigned major_version,
index 3eb5b8b8dc74487a48b54800d10671e60398e76c..850d9a0b0c0511731d949144d07651cbf063c413 100644 (file)
@@ -426,6 +426,9 @@ intelInitContext(struct brw_context *brw,
    brw->intelScreen = intelScreen;
    brw->bufmgr = intelScreen->bufmgr;
 
+   driContextPriv->driverPrivate = brw;
+   brw->driContext = driContextPriv;
+
    if (!_mesa_initialize_context(&brw->ctx, api, mesaVis, shareCtx,
                                  functions)) {
       *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
@@ -433,9 +436,6 @@ intelInitContext(struct brw_context *brw,
       return false;
    }
 
-   driContextPriv->driverPrivate = brw;
-   brw->driContext = driContextPriv;
-
    brw->gen = intelScreen->gen;
 
    const int devID = intelScreen->deviceID;
index aef3bbf7e763b4ebff4feedb9ce703821feda855..b6b4275cc00146be6c27a704ecd27c02a377b562 100644 (file)
@@ -984,32 +984,6 @@ intelDestroyBuffer(__DRIdrawable * driDrawPriv)
     _mesa_reference_framebuffer(&fb, NULL);
 }
 
-static GLboolean
-intelCreateContext(gl_api api,
-                  const struct gl_config * mesaVis,
-                   __DRIcontext * driContextPriv,
-                  unsigned major_version,
-                  unsigned minor_version,
-                  uint32_t flags,
-                  unsigned *error,
-                   void *sharedContextPrivate)
-{
-   bool success = false;
-
-   success = brwCreateContext(api, mesaVis,
-                              driContextPriv,
-                              major_version, minor_version, flags,
-                              error, sharedContextPrivate);
-
-   if (success)
-      return true;
-
-   if (driContextPriv->driverPrivate != NULL)
-      intelDestroyContext(driContextPriv);
-
-   return false;
-}
-
 static bool
 intel_init_bufmgr(struct intel_screen *intelScreen)
 {
@@ -1371,7 +1345,7 @@ intelReleaseBuffer(__DRIscreen *screen, __DRIbuffer *buffer)
 const struct __DriverAPIRec driDriverAPI = {
    .InitScreen          = intelInitScreen2,
    .DestroyScreen       = intelDestroyScreen,
-   .CreateContext       = intelCreateContext,
+   .CreateContext       = brwCreateContext,
    .DestroyContext      = intelDestroyContext,
    .CreateBuffer        = intelCreateBuffer,
    .DestroyBuffer       = intelDestroyBuffer,