[Mesa-dev] [PATCH 2/4 dri] st/dri: add copy_drawable() callback

nobled nobled at dreamwidth.org
Wed Oct 19 17:16:23 PDT 2011


This moves drisw-specific code into drisw.c, making it
possible to eliminate the extra copy of dri_drawable.c.
---
 .../state_trackers/dri/common/dri_context.h        |    4 ++
 src/gallium/state_trackers/dri/drm/dri2.c          |   26 +++++++++-
 src/gallium/state_trackers/dri/sw/dri_drawable.c   |   42 +---------------
 src/gallium/state_trackers/dri/sw/drisw.c          |   55 +++++++++++++++++++-
 4 files changed, 84 insertions(+), 43 deletions(-)

diff --git a/src/gallium/state_trackers/dri/common/dri_context.h
b/src/gallium/state_trackers/dri/common/dri_context.h
index cfc8e33..e2738d2 100644
--- a/src/gallium/state_trackers/dri/common/dri_context.h
+++ b/src/gallium/state_trackers/dri/common/dri_context.h
@@ -64,6 +64,10 @@ struct dri_context
    struct st_context_iface *st;
    struct pp_queue_t *pp;
    unsigned int pp_enabled[PP_FILTERS];
+
+   /* copy the contents of the __DRIdrawable to the pipe_resource: */
+   void (*copy_drawable)(struct dri_context *, __DRIdrawable *,
+                         struct pipe_resource *);
 };

 static INLINE struct dri_context *
diff --git a/src/gallium/state_trackers/dri/drm/dri2.c
b/src/gallium/state_trackers/dri/drm/dri2.c
index f3c9e10..20a230c 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -711,6 +711,30 @@ dri2_create_buffer(__DRIscreen * sPriv,
    return TRUE;
 }

+static void
+dri2_copy_drawable(struct dri_context *ctx, __DRIdrawable *dPriv,
+                   struct pipe_resource *res)
+{
+   /* no-op */
+   (void)ctx;
+   (void)dPriv;
+   (void)res;
+}
+
+static GLboolean
+dri2_create_context(gl_api api, const struct gl_config * visual,
+                    __DRIcontext * cPriv, void *sharedContextPrivate)
+{
+   struct dri_context *ctx;
+
+   if (!dri_create_context(api, visual, cPriv, sharedContextPrivate))
+      return FALSE;
+
+   ctx = dri_context(cPriv);
+   ctx->copy_drawable = dri2_copy_drawable;
+   return TRUE;
+}
+
 /**
  * DRI driver virtual function table.
  *
@@ -720,7 +744,7 @@ const struct __DriverAPIRec driDriverAPI = {
    .InitScreen = NULL,
    .InitScreen2 = dri2_init_screen,
    .DestroyScreen = dri_destroy_screen,
-   .CreateContext = dri_create_context,
+   .CreateContext = dri2_create_context,
    .DestroyContext = dri_destroy_context,
    .CreateBuffer = dri2_create_buffer,
    .DestroyBuffer = dri_destroy_buffer,
diff --git a/src/gallium/state_trackers/dri/sw/dri_drawable.c
b/src/gallium/state_trackers/dri/sw/dri_drawable.c
index 66997fb..41e2a8d 100644
--- a/src/gallium/state_trackers/dri/sw/dri_drawable.c
+++ b/src/gallium/state_trackers/dri/sw/dri_drawable.c
@@ -38,7 +38,6 @@
 #include "util/u_memory.h"
 #include "util/u_inlines.h"

-#include "state_tracker/st_context.h"

 static boolean
 dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
@@ -187,44 +186,6 @@ dri_drawable_validate_att(struct dri_drawable *drawable,
    drawable->base.validate(&drawable->base, statts, count, NULL);
 }

-static void
-drisw_copy_drawable(struct dri_context *ctx, __DRIdrawable *dPriv,
-                    struct pipe_resource *res)
-{
-   struct st_context *stctx = (struct st_context *)ctx->st;
-   struct pipe_context *pipe = stctx->pipe;
-   struct pipe_transfer *tex_xfer;
-   char *map;
-   __DRIscreen *sPriv = dPriv->driScreenPriv;
-   int x, y, w, h, line, ximage_stride;
-
-   sPriv->swrast_loader->getDrawableInfo(dPriv, &x, &y, &w, &h,
-                                         dPriv->loaderPrivate);
-
-   tex_xfer = pipe_get_transfer(pipe, res,
-                                0, 0,    /* level, layer */
-                                PIPE_TRANSFER_WRITE,
-                                x, y,
-                                w, h);
-
-   map = pipe_transfer_map(pipe, tex_xfer);
-
-   /* Copy the Drawable content to the mapped texture buffer */
-   sPriv->swrast_loader->getImage(dPriv, x, y, w, h, map,
-                                  dPriv->loaderPrivate);
-
-   /* The pipe transfer has a pitch rounded up to the nearest 64 pixels.
-      We assume 32 bit pixels. */
-   ximage_stride = w * 4;
-   for (line = h-1; line; --line) {
-      memmove(&map[line * tex_xfer->stride],
-              &map[line * ximage_stride], ximage_stride);
-   }
-
-   pipe_transfer_unmap(pipe, tex_xfer);
-   pipe_transfer_destroy(pipe, tex_xfer);
-}
-
 /**
  * These are used for GLX_EXT_texture_from_pixmap
  */
@@ -258,8 +219,7 @@ dri_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
          }
       }

-      /* needed only for drisw: */
-      drisw_copy_drawable(ctx, dPriv, res);
+      ctx->copy_drawable(ctx, dPriv, res);

       ctx->st->teximage(ctx->st,
             (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT,
diff --git a/src/gallium/state_trackers/dri/sw/drisw.c
b/src/gallium/state_trackers/dri/sw/drisw.c
index 082df55..7d45b00 100644
--- a/src/gallium/state_trackers/dri/sw/drisw.c
+++ b/src/gallium/state_trackers/dri/sw/drisw.c
@@ -39,6 +39,7 @@
 #include "util/u_inlines.h"
 #include "pipe/p_context.h"
 #include "state_tracker/drisw_api.h"
+#include "state_tracker/st_context.h"

 #include "dri_screen.h"
 #include "dri_context.h"
@@ -293,6 +294,58 @@ drisw_create_buffer(__DRIscreen * sPriv,
    return TRUE;
 }

+static void
+drisw_copy_drawable(struct dri_context *ctx, __DRIdrawable *dPriv,
+                    struct pipe_resource *res)
+{
+   struct st_context *stctx = (struct st_context *)ctx->st;
+   struct pipe_context *pipe = stctx->pipe;
+   struct pipe_transfer *tex_xfer;
+   char *map;
+   __DRIscreen *sPriv = dPriv->driScreenPriv;
+   int x, y, w, h, line, ximage_stride;
+
+   sPriv->swrast_loader->getDrawableInfo(dPriv, &x, &y, &w, &h,
+                                         dPriv->loaderPrivate);
+
+   tex_xfer = pipe_get_transfer(pipe, res,
+                                0, 0,    /* level, layer */
+                                PIPE_TRANSFER_WRITE,
+                                x, y,
+                                w, h);
+
+   map = pipe_transfer_map(pipe, tex_xfer);
+
+   /* Copy the Drawable content to the mapped texture buffer */
+   sPriv->swrast_loader->getImage(dPriv, x, y, w, h, map,
+                                  dPriv->loaderPrivate);
+
+   /* The pipe transfer has a pitch rounded up to the nearest 64 pixels.
+      We assume 32 bit pixels. */
+   ximage_stride = w * 4;
+   for (line = h-1; line; --line) {
+      memmove(&map[line * tex_xfer->stride],
+              &map[line * ximage_stride], ximage_stride);
+   }
+
+   pipe_transfer_unmap(pipe, tex_xfer);
+   pipe_transfer_destroy(pipe, tex_xfer);
+}
+
+static GLboolean
+drisw_create_context(gl_api api, const struct gl_config * visual,
+                     __DRIcontext * cPriv, void *sharedContextPrivate)
+{
+   struct dri_context *ctx;
+
+   if (!dri_create_context(api, visual, cPriv, sharedContextPrivate))
+      return FALSE;
+
+   ctx = dri_context(cPriv);
+   ctx->copy_drawable = drisw_copy_drawable;
+   return TRUE;
+}
+
 /**
  * DRI driver virtual function table.
  *
@@ -301,7 +354,7 @@ drisw_create_buffer(__DRIscreen * sPriv,
 const struct __DriverAPIRec driDriverAPI = {
    .InitScreen = drisw_init_screen,
    .DestroyScreen = dri_destroy_screen,
-   .CreateContext = dri_create_context,
+   .CreateContext = drisw_create_context,
    .DestroyContext = dri_destroy_context,
    .CreateBuffer = drisw_create_buffer,
    .DestroyBuffer = dri_destroy_buffer,
-- 
1.7.6.msysgit.0
-------------- next part --------------
From f0ba9fe7da311a0764a807e030f189388331bd2a Mon Sep 17 00:00:00 2001
From: nobled <nobled at dreamwidth.org>
Date: Wed, 12 Oct 2011 13:17:37 +0000
Subject: [PATCH 2/4 dri] st/dri: add copy_drawable() callback

This moves drisw-specific code into drisw.c, making it
possible to eliminate the extra copy of dri_drawable.c.
---
 .../state_trackers/dri/common/dri_context.h        |    4 ++
 src/gallium/state_trackers/dri/drm/dri2.c          |   26 +++++++++-
 src/gallium/state_trackers/dri/sw/dri_drawable.c   |   42 +---------------
 src/gallium/state_trackers/dri/sw/drisw.c          |   55 +++++++++++++++++++-
 4 files changed, 84 insertions(+), 43 deletions(-)

diff --git a/src/gallium/state_trackers/dri/common/dri_context.h b/src/gallium/state_trackers/dri/common/dri_context.h
index cfc8e33..e2738d2 100644
--- a/src/gallium/state_trackers/dri/common/dri_context.h
+++ b/src/gallium/state_trackers/dri/common/dri_context.h
@@ -64,6 +64,10 @@ struct dri_context
    struct st_context_iface *st;
    struct pp_queue_t *pp;
    unsigned int pp_enabled[PP_FILTERS];
+
+   /* copy the contents of the __DRIdrawable to the pipe_resource: */
+   void (*copy_drawable)(struct dri_context *, __DRIdrawable *,
+                         struct pipe_resource *);
 };
 
 static INLINE struct dri_context *
diff --git a/src/gallium/state_trackers/dri/drm/dri2.c b/src/gallium/state_trackers/dri/drm/dri2.c
index f3c9e10..20a230c 100644
--- a/src/gallium/state_trackers/dri/drm/dri2.c
+++ b/src/gallium/state_trackers/dri/drm/dri2.c
@@ -711,6 +711,30 @@ dri2_create_buffer(__DRIscreen * sPriv,
    return TRUE;
 }
 
+static void
+dri2_copy_drawable(struct dri_context *ctx, __DRIdrawable *dPriv,
+                   struct pipe_resource *res)
+{
+   /* no-op */
+   (void)ctx;
+   (void)dPriv;
+   (void)res;
+}
+
+static GLboolean
+dri2_create_context(gl_api api, const struct gl_config * visual,
+                    __DRIcontext * cPriv, void *sharedContextPrivate)
+{
+   struct dri_context *ctx;
+
+   if (!dri_create_context(api, visual, cPriv, sharedContextPrivate))
+      return FALSE;
+
+   ctx = dri_context(cPriv);
+   ctx->copy_drawable = dri2_copy_drawable;
+   return TRUE;
+}
+
 /**
  * DRI driver virtual function table.
  *
@@ -720,7 +744,7 @@ const struct __DriverAPIRec driDriverAPI = {
    .InitScreen = NULL,
    .InitScreen2 = dri2_init_screen,
    .DestroyScreen = dri_destroy_screen,
-   .CreateContext = dri_create_context,
+   .CreateContext = dri2_create_context,
    .DestroyContext = dri_destroy_context,
    .CreateBuffer = dri2_create_buffer,
    .DestroyBuffer = dri_destroy_buffer,
diff --git a/src/gallium/state_trackers/dri/sw/dri_drawable.c b/src/gallium/state_trackers/dri/sw/dri_drawable.c
index 66997fb..41e2a8d 100644
--- a/src/gallium/state_trackers/dri/sw/dri_drawable.c
+++ b/src/gallium/state_trackers/dri/sw/dri_drawable.c
@@ -38,7 +38,6 @@
 #include "util/u_memory.h"
 #include "util/u_inlines.h"
 
-#include "state_tracker/st_context.h" 
 
 static boolean
 dri_st_framebuffer_validate(struct st_framebuffer_iface *stfbi,
@@ -187,44 +186,6 @@ dri_drawable_validate_att(struct dri_drawable *drawable,
    drawable->base.validate(&drawable->base, statts, count, NULL);
 }
 
-static void
-drisw_copy_drawable(struct dri_context *ctx, __DRIdrawable *dPriv,
-                    struct pipe_resource *res)
-{
-   struct st_context *stctx = (struct st_context *)ctx->st;
-   struct pipe_context *pipe = stctx->pipe;
-   struct pipe_transfer *tex_xfer;
-   char *map;
-   __DRIscreen *sPriv = dPriv->driScreenPriv;
-   int x, y, w, h, line, ximage_stride;
-
-   sPriv->swrast_loader->getDrawableInfo(dPriv, &x, &y, &w, &h,
-                                         dPriv->loaderPrivate);
-
-   tex_xfer = pipe_get_transfer(pipe, res,
-                                0, 0,    /* level, layer */
-                                PIPE_TRANSFER_WRITE,
-                                x, y,
-                                w, h);
-
-   map = pipe_transfer_map(pipe, tex_xfer);
-
-   /* Copy the Drawable content to the mapped texture buffer */
-   sPriv->swrast_loader->getImage(dPriv, x, y, w, h, map,
-                                  dPriv->loaderPrivate);
-
-   /* The pipe transfer has a pitch rounded up to the nearest 64 pixels.
-      We assume 32 bit pixels. */
-   ximage_stride = w * 4;
-   for (line = h-1; line; --line) {
-      memmove(&map[line * tex_xfer->stride],
-              &map[line * ximage_stride], ximage_stride);
-   }
-
-   pipe_transfer_unmap(pipe, tex_xfer);
-   pipe_transfer_destroy(pipe, tex_xfer);
-}
-
 /**
  * These are used for GLX_EXT_texture_from_pixmap
  */
@@ -258,8 +219,7 @@ dri_set_tex_buffer2(__DRIcontext *pDRICtx, GLint target,
          }
       }
 
-      /* needed only for drisw: */
-      drisw_copy_drawable(ctx, dPriv, res);
+      ctx->copy_drawable(ctx, dPriv, res);
 
       ctx->st->teximage(ctx->st,
             (target == GL_TEXTURE_2D) ? ST_TEXTURE_2D : ST_TEXTURE_RECT,
diff --git a/src/gallium/state_trackers/dri/sw/drisw.c b/src/gallium/state_trackers/dri/sw/drisw.c
index 082df55..7d45b00 100644
--- a/src/gallium/state_trackers/dri/sw/drisw.c
+++ b/src/gallium/state_trackers/dri/sw/drisw.c
@@ -39,6 +39,7 @@
 #include "util/u_inlines.h"
 #include "pipe/p_context.h"
 #include "state_tracker/drisw_api.h"
+#include "state_tracker/st_context.h"
 
 #include "dri_screen.h"
 #include "dri_context.h"
@@ -293,6 +294,58 @@ drisw_create_buffer(__DRIscreen * sPriv,
    return TRUE;
 }
 
+static void
+drisw_copy_drawable(struct dri_context *ctx, __DRIdrawable *dPriv,
+                    struct pipe_resource *res)
+{
+   struct st_context *stctx = (struct st_context *)ctx->st;
+   struct pipe_context *pipe = stctx->pipe;
+   struct pipe_transfer *tex_xfer;
+   char *map;
+   __DRIscreen *sPriv = dPriv->driScreenPriv;
+   int x, y, w, h, line, ximage_stride;
+
+   sPriv->swrast_loader->getDrawableInfo(dPriv, &x, &y, &w, &h,
+                                         dPriv->loaderPrivate);
+
+   tex_xfer = pipe_get_transfer(pipe, res,
+                                0, 0,    /* level, layer */
+                                PIPE_TRANSFER_WRITE,
+                                x, y,
+                                w, h);
+
+   map = pipe_transfer_map(pipe, tex_xfer);
+
+   /* Copy the Drawable content to the mapped texture buffer */
+   sPriv->swrast_loader->getImage(dPriv, x, y, w, h, map,
+                                  dPriv->loaderPrivate);
+
+   /* The pipe transfer has a pitch rounded up to the nearest 64 pixels.
+      We assume 32 bit pixels. */
+   ximage_stride = w * 4;
+   for (line = h-1; line; --line) {
+      memmove(&map[line * tex_xfer->stride],
+              &map[line * ximage_stride], ximage_stride);
+   }
+
+   pipe_transfer_unmap(pipe, tex_xfer);
+   pipe_transfer_destroy(pipe, tex_xfer);
+}
+
+static GLboolean
+drisw_create_context(gl_api api, const struct gl_config * visual,
+                     __DRIcontext * cPriv, void *sharedContextPrivate)
+{
+   struct dri_context *ctx;
+
+   if (!dri_create_context(api, visual, cPriv, sharedContextPrivate))
+      return FALSE;
+
+   ctx = dri_context(cPriv);
+   ctx->copy_drawable = drisw_copy_drawable;
+   return TRUE;
+}
+
 /**
  * DRI driver virtual function table.
  *
@@ -301,7 +354,7 @@ drisw_create_buffer(__DRIscreen * sPriv,
 const struct __DriverAPIRec driDriverAPI = {
    .InitScreen = drisw_init_screen,
    .DestroyScreen = dri_destroy_screen,
-   .CreateContext = dri_create_context,
+   .CreateContext = drisw_create_context,
    .DestroyContext = dri_destroy_context,
    .CreateBuffer = drisw_create_buffer,
    .DestroyBuffer = dri_destroy_buffer,
-- 
1.7.6.msysgit.0



More information about the mesa-dev mailing list