st/dri: export DRI1 surface / pipe
authorGeorge Sapountzis <gsapountzis@gmail.com>
Thu, 25 Mar 2010 15:01:53 +0000 (17:01 +0200)
committerGeorge Sapountzis <gsapountzis@gmail.com>
Thu, 25 Mar 2010 15:01:53 +0000 (17:01 +0200)
They will be used by DRISW. Also, add destroy functions.

src/gallium/state_trackers/dri/Makefile
src/gallium/state_trackers/dri/SConscript
src/gallium/state_trackers/dri/dri1.c
src/gallium/state_trackers/dri/dri1.h
src/gallium/state_trackers/dri/dri1_helper.c [new file with mode: 0644]
src/gallium/state_trackers/dri/dri1_helper.h [new file with mode: 0644]
src/gallium/state_trackers/dri/dri_drawable.c
src/gallium/state_trackers/dri/dri_screen.c
src/gallium/state_trackers/dri/dri_st_api.c

index 6d95a277f822ec9f5c652b2034f8cd502451103a..f1a54e80b617ca11c11f95fc27f63c33191d6a99 100644 (file)
@@ -17,6 +17,7 @@ C_SOURCES = \
        dri_drawable.c \
        dri_extensions.c \
        dri_st_api.c \
+       dri1_helper.c \
        dri1.c \
        dri2.c
 
index d6dc126723d79428c4914fa2cccae763d5987ea7..2ca9f4206839991c3875e5ffb52ea9cf585b8072 100644 (file)
@@ -19,6 +19,7 @@ if env['dri']:
                'dri_extensions.c',
                'dri_screen.c',
                'dri_st_api.c',
+               'dri1_helper.c',
                'dri1.c',
                'dri2.c',
                ]
index 9108d41bd945fc1edc4f6aa76a6ba5b4df9bf8c5..98bdb2936a1656caac1058694a72037360c70d92 100644 (file)
@@ -41,6 +41,7 @@
 #include "dri_context.h"
 #include "dri_drawable.h"
 #include "dri_st_api.h"
+#include "dri1_helper.h"
 #include "dri1.h"
 
 static INLINE void
@@ -65,50 +66,6 @@ dri1_unlock(struct dri_context *ctx)
    DRM_UNLOCK(ctx->sPriv->fd, ctx->lock, ctx->cPriv->hHWContext);
 }
 
-static struct pipe_fence_handle *
-dri_swap_fences_pop_front(struct dri_drawable *draw)
-{
-   struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen;
-   struct pipe_fence_handle *fence = NULL;
-
-   if (draw->cur_fences >= draw->desired_fences) {
-      screen->fence_reference(screen, &fence, draw->swap_fences[draw->tail]);
-      screen->fence_reference(screen, &draw->swap_fences[draw->tail++], NULL);
-      --draw->cur_fences;
-      draw->tail &= DRI_SWAP_FENCES_MASK;
-   }
-   return fence;
-}
-
-static void
-dri_swap_fences_push_back(struct dri_drawable *draw,
-                         struct pipe_fence_handle *fence)
-{
-   struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen;
-
-   if (!fence)
-      return;
-
-   if (draw->cur_fences < DRI_SWAP_FENCES_MAX) {
-      draw->cur_fences++;
-      screen->fence_reference(screen, &draw->swap_fences[draw->head++],
-                             fence);
-      draw->head &= DRI_SWAP_FENCES_MASK;
-   }
-}
-
-void
-dri1_swap_fences_clear(struct dri_drawable *drawable)
-{
-   struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen;
-   struct pipe_fence_handle *fence;
-
-   while (drawable->cur_fences) {
-      fence = dri_swap_fences_pop_front(drawable);
-      screen->fence_reference(screen, &fence, NULL);
-   }
-}
-
 static void
 dri1_update_drawables_locked(struct dri_context *ctx,
                             __DRIdrawable * driDrawPriv,
@@ -213,39 +170,6 @@ dri1_swap_copy(struct pipe_context *pipe,
    }
 }
 
-static struct pipe_surface *
-dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex)
-{
-   struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->pipe_screen;
-   struct pipe_surface *psurf = drawable->dri1_surface;
-
-   if (!psurf || psurf->texture != ptex) {
-      pipe_surface_reference(&drawable->dri1_surface, NULL);
-
-      drawable->dri1_surface = pipe_screen->get_tex_surface(pipe_screen,
-            ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ);
-
-      psurf = drawable->dri1_surface;
-   }
-
-   return psurf;
-}
-
-static struct pipe_context *
-dri1_get_pipe_context(struct dri_drawable *drawable)
-{
-   struct dri_screen *screen = dri_screen(drawable->sPriv);
-   struct pipe_context *pipe = screen->dri1_pipe;
-
-   if (!pipe) {
-      screen->dri1_pipe =
-         screen->pipe_screen->context_create(screen->pipe_screen, NULL);
-      pipe = screen->dri1_pipe;
-   }
-
-   return pipe;
-}
-
 static void
 dri1_present_texture_locked(__DRIdrawable * dPriv,
                             struct pipe_texture *ptex,
@@ -253,6 +177,7 @@ dri1_present_texture_locked(__DRIdrawable * dPriv,
                             struct pipe_fence_handle **fence)
 {
    struct dri_drawable *drawable = dri_drawable(dPriv);
+   struct dri_screen *screen = dri_screen(drawable->sPriv);
    struct pipe_context *pipe;
    struct pipe_surface *psurf;
    struct drm_clip_rect bbox;
@@ -270,7 +195,7 @@ dri1_present_texture_locked(__DRIdrawable * dPriv,
    if (!visible)
       return;
 
-   pipe = dri1_get_pipe_context(drawable);
+   pipe = dri1_get_pipe_context(screen);
    psurf = dri1_get_pipe_surface(drawable, ptex);
    if (!pipe || !psurf)
       return;
@@ -317,6 +242,10 @@ dri1_copy_to_front(struct dri_context *ctx,
    dri1_propagate_drawable_change(ctx);
 }
 
+/*
+ * Backend functions for st_framebuffer interface and swap_buffers.
+ */
+
 void
 dri1_flush_frontbuffer(struct dri_drawable *draw,
                        enum st_attachment_type statt)
@@ -359,13 +288,13 @@ dri1_swap_buffers(__DRIdrawable * dPriv)
    ptex = draw->textures[ST_ATTACHMENT_BACK_LEFT];
    if (ptex) {
       ctx->st->flush(ctx->st, PIPE_FLUSH_RENDER_CACHE, NULL);
-      fence = dri_swap_fences_pop_front(draw);
+      fence = dri1_swap_fences_pop_front(draw);
       if (fence) {
         (void)pipe_screen->fence_finish(pipe_screen, fence, 0);
         pipe_screen->fence_reference(pipe_screen, &fence, NULL);
       }
       dri1_copy_to_front(ctx, ptex, dPriv, NULL, &fence);
-      dri_swap_fences_push_back(draw, fence);
+      dri1_swap_fences_push_back(draw, fence);
       pipe_screen->fence_reference(pipe_screen, &fence, NULL);
    }
 }
@@ -513,6 +442,10 @@ static struct dri1_api_lock_funcs dri1_lf = {
    .clear_lost_lock = st_dri_clear_lost_lock
 };
 
+/*
+ * Backend function for init_screen.
+ */
+
 static const __DRIextension *dri1_screen_extensions[] = {
    &driReadDrawableExtension,
    &driCopySubBufferExtension.base,
index f1004281b54c4085033700cbcb253313c3c83801..cced505ea97f711750b5d1d3aef5e8796bba4454 100644 (file)
@@ -56,7 +56,4 @@ void dri1_swap_buffers(__DRIdrawable * dPriv);
 void
 dri1_copy_sub_buffer(__DRIdrawable * dPriv, int x, int y, int w, int h);
 
-void
-dri1_swap_fences_clear(struct dri_drawable *drawable);
-
 #endif /* DRI1_H */
diff --git a/src/gallium/state_trackers/dri/dri1_helper.c b/src/gallium/state_trackers/dri/dri1_helper.c
new file mode 100644 (file)
index 0000000..7eeb868
--- /dev/null
@@ -0,0 +1,129 @@
+/**************************************************************************
+ *
+ * Copyright 2009, VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+/*
+ * Management of pipe objects (surface / pipe / fences) used by DRI1 and DRISW.
+ *
+ * Author: Keith Whitwell <keithw@vmware.com>
+ * Author: Jakob Bornecrantz <wallbraker@gmail.com>
+ */
+
+#include "util/u_inlines.h"
+#include "pipe/p_context.h"
+
+#include "dri_screen.h"
+#include "dri_context.h"
+#include "dri_drawable.h"
+#include "dri1_helper.h"
+
+struct pipe_fence_handle *
+dri1_swap_fences_pop_front(struct dri_drawable *draw)
+{
+   struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen;
+   struct pipe_fence_handle *fence = NULL;
+
+   if (draw->cur_fences >= draw->desired_fences) {
+      screen->fence_reference(screen, &fence, draw->swap_fences[draw->tail]);
+      screen->fence_reference(screen, &draw->swap_fences[draw->tail++], NULL);
+      --draw->cur_fences;
+      draw->tail &= DRI_SWAP_FENCES_MASK;
+   }
+   return fence;
+}
+
+void
+dri1_swap_fences_push_back(struct dri_drawable *draw,
+                           struct pipe_fence_handle *fence)
+{
+   struct pipe_screen *screen = dri_screen(draw->sPriv)->pipe_screen;
+
+   if (!fence)
+      return;
+
+   if (draw->cur_fences < DRI_SWAP_FENCES_MAX) {
+      draw->cur_fences++;
+      screen->fence_reference(screen, &draw->swap_fences[draw->head++],
+                             fence);
+      draw->head &= DRI_SWAP_FENCES_MASK;
+   }
+}
+
+void
+dri1_swap_fences_clear(struct dri_drawable *drawable)
+{
+   struct pipe_screen *screen = dri_screen(drawable->sPriv)->pipe_screen;
+   struct pipe_fence_handle *fence;
+
+   while (drawable->cur_fences) {
+      fence = dri1_swap_fences_pop_front(drawable);
+      screen->fence_reference(screen, &fence, NULL);
+   }
+}
+
+struct pipe_surface *
+dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex)
+{
+   struct pipe_screen *pipe_screen = dri_screen(drawable->sPriv)->pipe_screen;
+   struct pipe_surface *psurf = drawable->dri1_surface;
+
+   if (!psurf || psurf->texture != ptex) {
+      pipe_surface_reference(&drawable->dri1_surface, NULL);
+
+      drawable->dri1_surface = pipe_screen->get_tex_surface(pipe_screen,
+            ptex, 0, 0, 0, PIPE_BUFFER_USAGE_GPU_READ);
+
+      psurf = drawable->dri1_surface;
+   }
+
+   return psurf;
+}
+
+void
+dri1_destroy_pipe_surface(struct dri_drawable *drawable)
+{
+   pipe_surface_reference(&drawable->dri1_surface, NULL);
+}
+
+struct pipe_context *
+dri1_get_pipe_context(struct dri_screen *screen)
+{
+   struct pipe_context *pipe = screen->dri1_pipe;
+
+   if (!pipe) {
+      screen->dri1_pipe =
+         screen->pipe_screen->context_create(screen->pipe_screen, NULL);
+      pipe = screen->dri1_pipe;
+   }
+
+   return pipe;
+}
+
+void
+dri1_destroy_pipe_context(struct dri_screen *screen)
+{
+   if (screen->dri1_pipe)
+      screen->dri1_pipe->destroy(screen->dri1_pipe);
+}
diff --git a/src/gallium/state_trackers/dri/dri1_helper.h b/src/gallium/state_trackers/dri/dri1_helper.h
new file mode 100644 (file)
index 0000000..3254b7f
--- /dev/null
@@ -0,0 +1,61 @@
+/**************************************************************************
+ *
+ * Copyright 2009, VMware, Inc.
+ * All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sub license, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the
+ * next paragraph) shall be included in all copies or substantial portions
+ * of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ **************************************************************************/
+/*
+ * Author: Keith Whitwell <keithw@vmware.com>
+ * Author: Jakob Bornecrantz <wallbraker@gmail.com>
+ */
+
+#ifndef DRI1_HELPER_H
+#define DRI1_HELPER_H
+
+#include "dri_screen.h"
+#include "dri_context.h"
+#include "dri_drawable.h"
+
+struct pipe_fence_handle *
+dri1_swap_fences_pop_front(struct dri_drawable *draw);
+
+void
+dri1_swap_fences_push_back(struct dri_drawable *draw,
+                           struct pipe_fence_handle *fence);
+
+void
+dri1_swap_fences_clear(struct dri_drawable *drawable);
+
+struct pipe_surface *
+dri1_get_pipe_surface(struct dri_drawable *drawable, struct pipe_texture *ptex);
+
+void
+dri1_destroy_pipe_surface(struct dri_drawable *drawable);
+
+struct pipe_context *
+dri1_get_pipe_context(struct dri_screen *screen);
+
+void
+dri1_destroy_pipe_context(struct dri_screen *screen);
+
+#endif /* DRI1_HELPER_H */
index 9b0ae8b27a9e4597fd271873873e99e359142835..75b4cc56289307f9ca2ce7192f5a2b4c2948bdd9 100644 (file)
@@ -33,7 +33,7 @@
 #include "dri_context.h"
 #include "dri_drawable.h"
 #include "dri_st_api.h"
-#include "dri1.h"
+#include "dri1_helper.h"
 
 #include "pipe/p_screen.h"
 #include "util/u_format.h"
@@ -79,13 +79,10 @@ void
 dri_destroy_buffer(__DRIdrawable * dPriv)
 {
    struct dri_drawable *drawable = dri_drawable(dPriv);
-   int i;
 
    dri1_swap_fences_clear(drawable);
 
-   pipe_surface_reference(&drawable->dri1_surface, NULL);
-   for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
-      pipe_texture_reference(&drawable->textures[i], NULL);
+   dri1_destroy_pipe_surface(drawable);
 
    dri_destroy_st_framebuffer(drawable->stfb);
 
index 6aef2d570028aa2065fabb084bb9736ada6d3300..1d808f0f7f9a7830c0d8bac4b0dbd5f50a0c6991 100644 (file)
@@ -37,6 +37,7 @@
 #include "dri_context.h"
 #include "dri_drawable.h"
 #include "dri_st_api.h"
+#include "dri1_helper.h"
 #include "dri1.h"
 #include "dri2.h"
 
@@ -292,11 +293,11 @@ dri_destroy_screen(__DRIscreen * sPriv)
 {
    struct dri_screen *screen = dri_screen(sPriv);
 
-   if (screen->dri1_pipe)
-      screen->dri1_pipe->destroy(screen->dri1_pipe);
+   dri1_destroy_pipe_context(screen);
 
    if (screen->smapi)
       dri_destroy_st_manager(screen->smapi);
+
    if (screen->pipe_screen)
       screen->pipe_screen->destroy(screen->pipe_screen);
 
index 88cc410a9f9bd734a9311bca2570939b1de820e5..3592a782229bdf2554d70d4b162702a7597ec84c 100644 (file)
@@ -35,6 +35,7 @@
 #include "dri_context.h"
 #include "dri_drawable.h"
 #include "dri_st_api.h"
+#include "dri1_helper.h"
 #include "dri1.h"
 #include "dri2.h"
 
@@ -136,6 +137,13 @@ dri_create_st_framebuffer(struct dri_drawable *drawable)
 void
 dri_destroy_st_framebuffer(struct st_framebuffer_iface *stfbi)
 {
+   struct dri_drawable *drawable =
+      (struct dri_drawable *) stfbi->st_manager_private;
+   int i;
+
+   for (i = 0; i < ST_ATTACHMENT_COUNT; i++)
+      pipe_texture_reference(&drawable->textures[i], NULL);
+
    FREE(stfbi);
 }