i965: Clean up error handling for context creation.
[mesa.git] / src / mesa / drivers / dri / i965 / intel_context.c
index 840c1a5bf1b04ad2cc2cb8ef6a72bc11444d1806..850d9a0b0c0511731d949144d07651cbf063c413 100644 (file)
@@ -144,6 +144,7 @@ intel_flush_front(struct gl_context *ctx)
           * performance.
           */
          intel_resolve_for_dri2_flush(brw, driDrawable);
+         intel_batchbuffer_flush(brw);
 
          screen->dri2.loader->flushFrontBuffer(driDrawable,
                                                driDrawable->loaderPrivate);
@@ -349,21 +350,12 @@ intelInvalidateState(struct gl_context * ctx, GLuint new_state)
    brw->NewGLState |= new_state;
 }
 
-void
-_intel_flush(struct gl_context *ctx, const char *file, int line)
-{
-   struct brw_context *brw = brw_context(ctx);
-
-   if (brw->batch.used)
-      _intel_batchbuffer_flush(brw, file, line);
-}
-
 static void
 intel_glFlush(struct gl_context *ctx)
 {
    struct brw_context *brw = brw_context(ctx);
 
-   intel_flush(ctx);
+   intel_batchbuffer_flush(brw);
    intel_flush_front(ctx);
    if (brw->is_front_buffer_rendering)
       brw->need_throttle = true;
@@ -374,8 +366,7 @@ intelFinish(struct gl_context * ctx)
 {
    struct brw_context *brw = brw_context(ctx);
 
-   intel_flush(ctx);
-   intel_flush_front(ctx);
+   intel_glFlush(ctx);
 
    if (brw->batch.last_bo)
       drm_intel_bo_wait_rendering(brw->batch.last_bo);
@@ -400,45 +391,7 @@ intelInitDriverFunctions(struct dd_function_table *functions)
    intelInitPixelFuncs(functions);
    intelInitBufferObjectFuncs(functions);
    intel_init_syncobj_functions(functions);
-}
-
-static bool
-validate_context_version(struct intel_screen *screen,
-                         int mesa_api,
-                         unsigned major_version,
-                         unsigned minor_version,
-                         unsigned *dri_ctx_error)
-{
-   unsigned req_version = 10 * major_version + minor_version;
-   unsigned max_version = 0;
-
-   switch (mesa_api) {
-   case API_OPENGL_COMPAT:
-      max_version = screen->max_gl_compat_version;
-      break;
-   case API_OPENGL_CORE:
-      max_version = screen->max_gl_core_version;
-      break;
-   case API_OPENGLES:
-      max_version = screen->max_gl_es1_version;
-      break;
-   case API_OPENGLES2:
-      max_version = screen->max_gl_es2_version;
-      break;
-   default:
-      max_version = 0;
-      break;
-   }
-
-   if (max_version == 0) {
-      *dri_ctx_error = __DRI_CTX_ERROR_BAD_API;
-      return false;
-   } else if (req_version > max_version) {
-      *dri_ctx_error = __DRI_CTX_ERROR_BAD_VERSION;
-      return false;
-   }
-
-   return true;
+   brw_init_object_purgeable_functions(functions);
 }
 
 bool
@@ -459,17 +412,6 @@ intelInitContext(struct brw_context *brw,
    int bo_reuse_mode;
    struct gl_config visual;
 
-   /* we can't do anything without a connection to the device */
-   if (intelScreen->bufmgr == NULL) {
-      *dri_ctx_error = __DRI_CTX_ERROR_NO_MEMORY;
-      return false;
-   }
-
-   if (!validate_context_version(intelScreen,
-                                 api, major_version, minor_version,
-                                 dri_ctx_error))
-      return false;
-
    /* Can't rely on invalidate events, fall back to glViewport hack */
    if (!driContextPriv->driScreenPriv->dri2.useInvalidate) {
       brw->saved_viewport = functions->Viewport;
@@ -484,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;
@@ -491,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;
@@ -754,11 +696,15 @@ intelMakeCurrent(__DRIcontext * driContextPriv,
         driContextPriv->dri2.read_stamp = driReadPriv->dri2.stamp - 1;
       }
 
+      /* The sRGB workaround changes the renderbuffer's format. We must change
+       * the format before the renderbuffer's miptree get's allocated, otherwise
+       * the formats of the renderbuffer and its miptree will differ.
+       */
+      intel_gles3_srgb_workaround(brw, fb);
+      intel_gles3_srgb_workaround(brw, readFb);
+
       intel_prepare_render(brw);
       _mesa_make_current(ctx, fb, readFb);
-
-      intel_gles3_srgb_workaround(brw, ctx->WinSysDrawBuffer);
-      intel_gles3_srgb_workaround(brw, ctx->WinSysReadBuffer);
    }
    else {
       _mesa_make_current(NULL, NULL, NULL);
@@ -811,7 +757,7 @@ intel_query_dri2_buffers(struct brw_context *brw,
        * query, we need to make sure all the pending drawing has landed in the
        * real front buffer.
        */
-      intel_flush(&brw->ctx);
+      intel_batchbuffer_flush(brw);
       intel_flush_front(&brw->ctx);
 
       attachments[i++] = __DRI_BUFFER_FRONT_LEFT;
@@ -823,7 +769,7 @@ intel_query_dri2_buffers(struct brw_context *brw,
        * So before doing the query, make sure all the pending drawing has
        * landed in the real front buffer.
        */
-      intel_flush(&brw->ctx);
+      intel_batchbuffer_flush(brw);
       intel_flush_front(&brw->ctx);
    }