gallium: plumb winsys-drawable-handle through to state tracker
[mesa.git] / src / gallium / state_trackers / dri / dri_context.c
index 45eaec4ed390204d2058c9e622ec4d64ec3814ee..2f991c39e33b82478eb7e9a6430ad803378ba168 100644 (file)
@@ -44,9 +44,9 @@
 
 GLboolean
 dri_create_context(const __GLcontextModes * visual,
-                  __DRIcontextPrivate * cPriv, void *sharedContextPrivate)
+                  __DRIcontext * cPriv, void *sharedContextPrivate)
 {
-   __DRIscreenPrivate *sPriv = cPriv->driScreenPriv;
+   __DRIscreen *sPriv = cPriv->driScreenPriv;
    struct dri_screen *screen = dri_screen(sPriv);
    struct dri_context *ctx = NULL;
    struct st_context *st_share = NULL;
@@ -69,14 +69,12 @@ dri_create_context(const __GLcontextModes * visual,
    driParseConfigFiles(&ctx->optionCache,
                       &screen->optionCache, sPriv->myNum, "dri");
 
-   ctx->pipe = drm_api_hooks.create_context(screen->pipe_screen);
+   ctx->pipe = screen->pipe_screen->context_create( screen->pipe_screen,
+                                                   ctx );
 
    if (ctx->pipe == NULL)
       goto fail;
 
-   /* used in dri_flush_frontbuffer */
-   ctx->pipe->priv = ctx;
-
    ctx->st = st_create_context(ctx->pipe, visual, st_share);
    if (ctx->st == NULL)
       goto fail;
@@ -97,10 +95,15 @@ dri_create_context(const __GLcontextModes * visual,
 }
 
 void
-dri_destroy_context(__DRIcontextPrivate * cPriv)
+dri_destroy_context(__DRIcontext * cPriv)
 {
    struct dri_context *ctx = dri_context(cPriv);
-   struct dri_screen *screen = dri_screen(cPriv->driScreenPriv);
+
+   /* note: we are freeing values and nothing more because
+    * driParseConfigFiles allocated values only - the rest
+    * is owned by screen optionCache.
+    */
+   FREE(ctx->optionCache.values);
 
    /* No particular reason to wait for command completion before
     * destroying a context, but it is probably worthwhile flushing it
@@ -109,9 +112,6 @@ dri_destroy_context(__DRIcontextPrivate * cPriv)
     */
    st_flush(ctx->st, 0, NULL);
 
-   if (screen->dummyContext == ctx)
-      screen->dummyContext = NULL;
-
    /* Also frees ctx->pipe?
     */
    st_destroy_context(ctx->st);
@@ -120,7 +120,7 @@ dri_destroy_context(__DRIcontextPrivate * cPriv)
 }
 
 GLboolean
-dri_unbind_context(__DRIcontextPrivate * cPriv)
+dri_unbind_context(__DRIcontext * cPriv)
 {
    if (cPriv) {
       struct dri_context *ctx = dri_context(cPriv);
@@ -128,7 +128,7 @@ dri_unbind_context(__DRIcontextPrivate * cPriv)
       if (--ctx->bind_count == 0) {
         if (ctx->st && ctx->st == st_get_current()) {
            st_flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
-           st_make_current(NULL, NULL, NULL);
+           st_make_current(NULL, NULL, NULL, NULL);
         }
       }
    }
@@ -137,13 +137,12 @@ dri_unbind_context(__DRIcontextPrivate * cPriv)
 }
 
 GLboolean
-dri_make_current(__DRIcontextPrivate * cPriv,
-                __DRIdrawablePrivate * driDrawPriv,
-                __DRIdrawablePrivate * driReadPriv)
+dri_make_current(__DRIcontext * cPriv,
+                __DRIdrawable * driDrawPriv,
+                __DRIdrawable * driReadPriv)
 {
    if (cPriv) {
       struct dri_context *ctx = dri_context(cPriv);
-      struct dri_screen *screen = dri_screen(cPriv->driScreenPriv);
       struct dri_drawable *draw = dri_drawable(driDrawPriv);
       struct dri_drawable *read = dri_drawable(driReadPriv);
       struct st_context *old_st = st_get_current();
@@ -153,11 +152,6 @@ dri_make_current(__DRIcontextPrivate * cPriv,
 
       ++ctx->bind_count;
 
-      /* This is for situations in which we need a rendering context but
-       * there may not be any currently bound.
-       */
-      screen->dummyContext = ctx;
-
       if (ctx->dPriv != driDrawPriv) {
         ctx->dPriv = driDrawPriv;
         ctx->d_stamp = driDrawPriv->lastStamp - 1;
@@ -167,18 +161,22 @@ dri_make_current(__DRIcontextPrivate * cPriv,
         ctx->r_stamp = driReadPriv->lastStamp - 1;
       }
 
-      st_make_current(ctx->st, draw->stfb, read->stfb);
+      /* DRI co-state tracker currently overrides flush_frontbuffer.
+       * When this is fixed, will need to pass the drawable in the
+       * fourth parameter here so that when Mesa calls
+       * flush_frontbuffer directly (in front-buffer rendering), it
+       * will have access to the drawable argument:
+       */
+      st_make_current(ctx->st, draw->stfb, read->stfb, NULL);
 
       if (__dri1_api_hooks) {
         dri1_update_drawables(ctx, draw, read);
       } else {
-        if (driDrawPriv)
-           dri_get_buffers(driDrawPriv);
-        if (driDrawPriv != driReadPriv && driReadPriv)
-           dri_get_buffers(driReadPriv);
+        dri_update_buffer(ctx->pipe->screen,
+                          ctx->pipe->priv);
       }
    } else {
-      st_make_current(NULL, NULL, NULL);
+      st_make_current(NULL, NULL, NULL, NULL);
    }
 
    return GL_TRUE;