Mesa (pipe-video): [g3dvl] start implementing palettes for subpictures

Christian König deathsimple at kemper.freedesktop.org
Sat Mar 26 11:40:27 UTC 2011


Module: Mesa
Branch: pipe-video
Commit: 849a0b0a821ecc59a50fe53498a6354cfd0b24a4
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=849a0b0a821ecc59a50fe53498a6354cfd0b24a4

Author: Christian König <deathsimple at vodafone.de>
Date:   Sat Mar 26 11:46:07 2011 +0100

[g3dvl] start implementing palettes for subpictures

---

 src/gallium/state_trackers/xorg/xvmc/subpicture.c  |   68 ++++++++++++++++++--
 .../state_trackers/xorg/xvmc/xvmc_private.h        |    3 +
 2 files changed, 65 insertions(+), 6 deletions(-)

diff --git a/src/gallium/state_trackers/xorg/xvmc/subpicture.c b/src/gallium/state_trackers/xorg/xvmc/subpicture.c
index 2603030..07643b6 100644
--- a/src/gallium/state_trackers/xorg/xvmc/subpicture.c
+++ b/src/gallium/state_trackers/xorg/xvmc/subpicture.c
@@ -57,22 +57,45 @@ static enum pipe_format XvIDToPipe(int xvimage_id)
    }
 }
 
+static unsigned NumPaletteEntries4XvID(int xvimage_id)
+{
+   switch (xvimage_id) {
+      case FOURCC_RGB:
+         return 0;
+
+      case FOURCC_AI44:
+      case FOURCC_IA44:
+         return 16;
+
+      default:
+         XVMC_MSG(XVMC_ERR, "[XvMC] Unrecognized Xv image ID 0x%08X.\n", xvimage_id);
+         return 0;
+   }
+}
+
 static int PipeToComponentOrder(enum pipe_format format, char *component_order)
 {
    assert(component_order);
 
    switch (format) {
       case PIPE_FORMAT_B8G8R8X8_UNORM:
-      case PIPE_FORMAT_L4A4_UNORM:
          return 0;
+
+      case PIPE_FORMAT_L4A4_UNORM:
+         component_order[0] = PIPE_SWIZZLE_RED;
+         component_order[1] = PIPE_SWIZZLE_GREEN;
+         component_order[2] = PIPE_SWIZZLE_BLUE;
+         component_order[3] = PIPE_SWIZZLE_ALPHA;
+         return 4;
+
       default:
          XVMC_MSG(XVMC_ERR, "[XvMC] Unrecognized PIPE_FORMAT 0x%08X.\n", format);
          component_order[0] = 0;
          component_order[1] = 0;
          component_order[2] = 0;
          component_order[3] = 0;
+         return 0;
    }
-   return 0;
 }
 
 static Status Validate(Display *dpy, XvPortID port, int surface_type_id, int xvimage_id)
@@ -232,10 +255,29 @@ Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *
    subpicture->xvimage_id = xvimage_id;
    subpicture->width = width;
    subpicture->height = height;
-   subpicture->num_palette_entries = 0;
+   subpicture->num_palette_entries = NumPaletteEntries4XvID(xvimage_id);
    subpicture->entry_bytes = PipeToComponentOrder(tex_templ.format, subpicture->component_order);
    subpicture->privData = subpicture_priv;
 
+   if (subpicture->num_palette_entries > 0) {
+      tex_templ.target = PIPE_TEXTURE_1D;
+      tex_templ.format = PIPE_FORMAT_B8G8R8A8_UNORM;
+      tex_templ.width0 = subpicture->num_palette_entries;
+      tex_templ.height0 = 1;
+      tex_templ.usage = PIPE_USAGE_STATIC;
+
+      tex = vpipe->screen->resource_create(vpipe->screen, &tex_templ);
+
+      memset(&sampler_templ, 0, sizeof(sampler_templ));
+      u_sampler_view_default_template(&sampler_templ, tex, tex->format);
+      subpicture_priv->palette = vpipe->create_sampler_view(vpipe, tex, &sampler_templ);
+      pipe_resource_reference(&tex, NULL);
+      if (!subpicture_priv->sampler) {
+         FREE(subpicture_priv);
+         return BadAlloc;
+      }
+   }
+
    SyncHandle();
 
    XVMC_MSG(XVMC_TRACE, "[XvMC] Subpicture %p created.\n", subpicture);
@@ -325,6 +367,7 @@ Status XvMCDestroySubpicture(Display *dpy, XvMCSubpicture *subpicture)
 
    subpicture_priv = subpicture->privData;
    pipe_sampler_view_reference(&subpicture_priv->sampler, NULL);
+   pipe_sampler_view_reference(&subpicture_priv->palette, NULL);
    FREE(subpicture_priv);
 
    XVMC_MSG(XVMC_TRACE, "[XvMC] Subpicture %p destroyed.\n", subpicture);
@@ -335,15 +378,28 @@ Status XvMCDestroySubpicture(Display *dpy, XvMCSubpicture *subpicture)
 PUBLIC
 Status XvMCSetSubpicturePalette(Display *dpy, XvMCSubpicture *subpicture, unsigned char *palette)
 {
+   XvMCSubpicturePrivate *subpicture_priv;
+   XvMCContextPrivate *context_priv;
+   struct pipe_video_context *vpipe;
+   struct pipe_box dst_box = {0, 0, 0, 0, 1, 1};
+
    assert(dpy);
+   assert(palette);
 
    if (!subpicture)
       return XvMCBadSubpicture;
 
-   assert(palette);
+   subpicture_priv = subpicture->privData;
+   context_priv = subpicture_priv->context->privData;
+   vpipe = context_priv->vctx->vpipe;
 
-   /* We don't support paletted subpictures */
-   return BadMatch;
+   dst_box.width = subpicture->num_palette_entries;
+
+   vpipe->upload_sampler(vpipe, subpicture_priv->palette, &dst_box, palette, 0, 0, 0);
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Palette of Subpicture %p set.\n", subpicture);
+
+   return Success;
 }
 
 PUBLIC
diff --git a/src/gallium/state_trackers/xorg/xvmc/xvmc_private.h b/src/gallium/state_trackers/xorg/xvmc/xvmc_private.h
index 68dfb0d..5e976cb 100644
--- a/src/gallium/state_trackers/xorg/xvmc/xvmc_private.h
+++ b/src/gallium/state_trackers/xorg/xvmc/xvmc_private.h
@@ -74,6 +74,9 @@ typedef struct
 {
    struct pipe_sampler_view *sampler;
 
+   /* optional palette for this subpicture */
+   struct pipe_sampler_view *palette;
+
    /* The surface this subpicture is currently associated with, if any. */
    XvMCSurface *surface;
 




More information about the mesa-commit mailing list