st/xvmc: move xvmc state tracker out of xorg subdir
authorChristian König <deathsimple@vodafone.de>
Wed, 15 Feb 2012 16:30:58 +0000 (17:30 +0100)
committerChristian König <deathsimple@vodafone.de>
Sat, 25 Feb 2012 11:14:26 +0000 (12:14 +0100)
The xvmc state tracker is completely seperate and
doesn't shares code or anything else with the
xorg state tracker.

Signed-off-by: Christian König <deathsimple@vodafone.de>
36 files changed:
configure.ac
src/gallium/state_trackers/xorg/xvmc/Makefile [deleted file]
src/gallium/state_trackers/xorg/xvmc/attributes.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/block.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/context.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/subpicture.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/surface.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/tests/.gitignore [deleted file]
src/gallium/state_trackers/xorg/xvmc/tests/Makefile [deleted file]
src/gallium/state_trackers/xorg/xvmc/tests/test_blocks.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/tests/test_context.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/tests/test_rendering.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/tests/test_subpicture.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/tests/test_surface.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/tests/testlib.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/tests/testlib.h [deleted file]
src/gallium/state_trackers/xorg/xvmc/tests/xvmc_bench.c [deleted file]
src/gallium/state_trackers/xorg/xvmc/xvmc_private.h [deleted file]
src/gallium/state_trackers/xvmc/Makefile [new file with mode: 0644]
src/gallium/state_trackers/xvmc/attributes.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/block.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/context.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/subpicture.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/surface.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/tests/.gitignore [new file with mode: 0644]
src/gallium/state_trackers/xvmc/tests/Makefile [new file with mode: 0644]
src/gallium/state_trackers/xvmc/tests/test_blocks.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/tests/test_context.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/tests/test_rendering.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/tests/test_subpicture.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/tests/test_surface.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/tests/testlib.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/tests/testlib.h [new file with mode: 0644]
src/gallium/state_trackers/xvmc/tests/xvmc_bench.c [new file with mode: 0644]
src/gallium/state_trackers/xvmc/xvmc_private.h [new file with mode: 0644]
src/gallium/targets/Makefile.xvmc

index 846b62300a77ac2deb80e32b2b2c8052f3695a42..627f9c2289ccc9efa2cb37f7cd3cb514420135d5 100644 (file)
@@ -1582,7 +1582,7 @@ fi
 
 if test "x$enable_xvmc" = xyes; then
     PKG_CHECK_MODULES([XVMC], [xvmc >= 1.0.6])
-    GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xorg/xvmc"
+    GALLIUM_STATE_TRACKERS_DIRS="$GALLIUM_STATE_TRACKERS_DIRS xvmc"
     HAVE_ST_XVMC="yes"
 fi
 
diff --git a/src/gallium/state_trackers/xorg/xvmc/Makefile b/src/gallium/state_trackers/xorg/xvmc/Makefile
deleted file mode 100644 (file)
index c468099..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-TOP = ../../../../..
-include $(TOP)/configs/current
-
-LIBNAME = xvmctracker
-
-LIBRARY_INCLUDES = \
-       $(shell $(PKG_CONFIG) --cflags-only-I xvmc) \
-       -I$(TOP)/src/gallium/winsys/g3dvl
-
-C_SOURCES = block.c \
-            surface.c \
-            context.c \
-            subpicture.c \
-            attributes.c
-
-include ../../../Makefile.template
diff --git a/src/gallium/state_trackers/xorg/xvmc/attributes.c b/src/gallium/state_trackers/xorg/xvmc/attributes.c
deleted file mode 100644 (file)
index d40a7b1..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <stdlib.h>
-
-#include <X11/Xlib.h>
-#include <X11/extensions/Xvlib.h>
-#include <X11/extensions/XvMClib.h>
-
-#include "vl/vl_compositor.h"
-
-#include "xvmc_private.h"
-
-#define XV_BRIGHTNESS "XV_BRIGHTNESS"
-#define XV_CONTRAST   "XV_CONTRAST"
-#define XV_SATURATION "XV_SATURATION"
-#define XV_HUE        "XV_HUE"
-#define XV_COLORSPACE "XV_COLORSPACE"
-
-static const XvAttribute attributes[] = {
-   { XvGettable | XvSettable, -1000, 1000, XV_BRIGHTNESS },
-   { XvGettable | XvSettable, -1000, 1000, XV_CONTRAST },
-   { XvGettable | XvSettable, -1000, 1000, XV_SATURATION },
-   { XvGettable | XvSettable, -1000, 1000, XV_HUE },
-   { XvGettable | XvSettable, 0, 1, XV_COLORSPACE }
-};
-
-PUBLIC
-XvAttribute* XvMCQueryAttributes(Display *dpy, XvMCContext *context, int *number)
-{
-   XvAttribute *result;
-
-   assert(dpy && number);
-
-   if (!context || !context->privData)
-      return NULL;
-
-   result = malloc(sizeof(attributes));
-   if (!result)
-      return NULL;
-
-   memcpy(result, attributes, sizeof(attributes));
-   *number = sizeof(attributes) / sizeof(XvAttribute);
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Returning %d attributes for context %p.\n", *number, context);
-
-   return result;
-}
-
-PUBLIC
-Status XvMCSetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int value)
-{
-   XvMCContextPrivate *context_priv;
-   const char *attr;
-   float csc[16];
-
-   assert(dpy);
-
-   if (!context || !context->privData)
-      return XvMCBadContext;
-
-   context_priv = context->privData;
-
-   attr = XGetAtomName(dpy, attribute);
-   if (!attr)
-      return XvMCBadContext;
-
-   if (strcmp(attr, XV_BRIGHTNESS))
-      context_priv->procamp.brightness = value / 1000.0f;
-   else if (strcmp(attr, XV_CONTRAST))
-      context_priv->procamp.contrast = value / 1000.0f + 1.0f;
-   else if (strcmp(attr, XV_SATURATION))
-      context_priv->procamp.saturation = value / 1000.0f + 1.0f;
-   else if (strcmp(attr, XV_HUE))
-      context_priv->procamp.hue = value / 1000.0f;
-   else if (strcmp(attr, XV_COLORSPACE))
-      context_priv->color_standard = value ?
-         VL_CSC_COLOR_STANDARD_BT_601 :
-         VL_CSC_COLOR_STANDARD_BT_709;
-   else
-      return BadName;
-
-   vl_csc_get_matrix
-   (
-      context_priv->color_standard,
-      &context_priv->procamp, true, csc
-   );
-   vl_compositor_set_csc_matrix(&context_priv->compositor, csc);
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Set attribute %s to value %d.\n", attr, value);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCGetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int *value)
-{
-   XvMCContextPrivate *context_priv;
-   const char *attr;
-
-   assert(dpy);
-
-   if (!context || !context->privData)
-      return XvMCBadContext;
-
-   context_priv = context->privData;
-
-   attr = XGetAtomName(dpy, attribute);
-   if (!attr)
-      return XvMCBadContext;
-
-   if (strcmp(attr, XV_BRIGHTNESS))
-      *value = context_priv->procamp.brightness * 1000;
-   else if (strcmp(attr, XV_CONTRAST))
-      *value = context_priv->procamp.contrast * 1000 - 1000;
-   else if (strcmp(attr, XV_SATURATION))
-      *value = context_priv->procamp.saturation * 1000 + 1000;
-   else if (strcmp(attr, XV_HUE))
-      *value = context_priv->procamp.hue * 1000;
-   else if (strcmp(attr, XV_COLORSPACE))
-      *value = context_priv->color_standard == VL_CSC_COLOR_STANDARD_BT_709;
-   else
-      return BadName;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Got value %d for attribute %s.\n", *value, attr);
-
-   return Success;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/block.c b/src/gallium/state_trackers/xorg/xvmc/block.c
deleted file mode 100644 (file)
index 64f8497..0000000
+++ /dev/null
@@ -1,95 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-
-#include <X11/Xlib.h>
-#include <X11/extensions/XvMClib.h>
-
-#include "util/u_memory.h"
-
-#include "xvmc_private.h"
-
-PUBLIC
-Status XvMCCreateBlocks(Display *dpy, XvMCContext *context, unsigned int num_blocks, XvMCBlockArray *blocks)
-{
-   assert(dpy);
-
-   if (!context)
-      return XvMCBadContext;
-   if (num_blocks == 0)
-      return BadValue;
-
-   assert(blocks);
-
-   blocks->context_id = context->context_id;
-   blocks->num_blocks = num_blocks;
-   blocks->blocks = MALLOC(BLOCK_SIZE_BYTES * num_blocks);
-   blocks->privData = NULL;
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCDestroyBlocks(Display *dpy, XvMCBlockArray *blocks)
-{
-   assert(dpy);
-   assert(blocks);
-   FREE(blocks->blocks);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCCreateMacroBlocks(Display *dpy, XvMCContext *context, unsigned int num_blocks, XvMCMacroBlockArray *blocks)
-{
-   assert(dpy);
-
-   if (!context)
-      return XvMCBadContext;
-   if (num_blocks == 0)
-      return BadValue;
-
-   assert(blocks);
-
-   blocks->context_id = context->context_id;
-   blocks->num_blocks = num_blocks;
-   blocks->macro_blocks = MALLOC(sizeof(XvMCMacroBlock) * num_blocks);
-   blocks->privData = NULL;
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCDestroyMacroBlocks(Display *dpy, XvMCMacroBlockArray *blocks)
-{
-   assert(dpy);
-   assert(blocks);
-   FREE(blocks->macro_blocks);
-
-   return Success;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/context.c b/src/gallium/state_trackers/xorg/xvmc/context.c
deleted file mode 100644 (file)
index e9ba06b..0000000
+++ /dev/null
@@ -1,329 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-
-#include <X11/Xlibint.h>
-#include <X11/extensions/XvMClib.h>
-
-#include "pipe/p_screen.h"
-#include "pipe/p_video_decoder.h"
-#include "pipe/p_video_state.h"
-#include "pipe/p_state.h"
-
-#include "util/u_memory.h"
-
-#include "vl/vl_csc.h"
-#include "vl_winsys.h"
-
-#include "xvmc_private.h"
-
-static Status Validate(Display *dpy, XvPortID port, int surface_type_id,
-                       unsigned int width, unsigned int height, int flags,
-                       bool *found_port, int *screen, int *chroma_format,
-                       int *mc_type, int *surface_flags,
-                       unsigned short *subpic_max_w,
-                       unsigned short *subpic_max_h)
-{
-   bool found_surface = false;
-   XvAdaptorInfo *adaptor_info;
-   unsigned int num_adaptors;
-   int num_types;
-   unsigned int max_width = 0, max_height = 0;
-   Status ret;
-
-   assert(dpy);
-   assert(found_port);
-   assert(screen);
-   assert(chroma_format);
-   assert(mc_type);
-   assert(surface_flags);
-   assert(subpic_max_w);
-   assert(subpic_max_h);
-
-   *found_port = false;
-
-   for (unsigned int i = 0; i < XScreenCount(dpy); ++i) {
-      ret = XvQueryAdaptors(dpy, XRootWindow(dpy, i), &num_adaptors, &adaptor_info);
-      if (ret != Success)
-         return ret;
-
-      for (unsigned int j = 0; j < num_adaptors && !*found_port; ++j) {
-         for (unsigned int k = 0; k < adaptor_info[j].num_ports && !*found_port; ++k) {
-            XvMCSurfaceInfo *surface_info;
-
-            if (adaptor_info[j].base_id + k != port)
-               continue;
-
-            *found_port = true;
-
-            surface_info = XvMCListSurfaceTypes(dpy, adaptor_info[j].base_id, &num_types);
-            if (!surface_info) {
-               XvFreeAdaptorInfo(adaptor_info);
-               return BadAlloc;
-            }
-
-            for (unsigned int l = 0; l < num_types && !found_surface; ++l) {
-               if (surface_info[l].surface_type_id != surface_type_id)
-                  continue;
-
-               found_surface = true;
-               max_width = surface_info[l].max_width;
-               max_height = surface_info[l].max_height;
-               *chroma_format = surface_info[l].chroma_format;
-               *mc_type = surface_info[l].mc_type;
-               *surface_flags = surface_info[l].flags;
-               *subpic_max_w = surface_info[l].subpicture_max_width;
-               *subpic_max_h = surface_info[l].subpicture_max_height;
-               *screen = i;
-
-               XVMC_MSG(XVMC_TRACE, "[XvMC] Found requested context surface format.\n" \
-                                    "[XvMC]   screen=%u, port=%u\n" \
-                                    "[XvMC]   id=0x%08X\n" \
-                                    "[XvMC]   max width=%u, max height=%u\n" \
-                                    "[XvMC]   chroma format=0x%08X\n" \
-                                    "[XvMC]   acceleration level=0x%08X\n" \
-                                    "[XvMC]   flags=0x%08X\n" \
-                                    "[XvMC]   subpicture max width=%u, max height=%u\n",
-                                    i, port, surface_type_id, max_width, max_height, *chroma_format,
-                                    *mc_type, *surface_flags, *subpic_max_w, *subpic_max_h);
-            }
-
-            XFree(surface_info);
-         }
-      }
-
-      XvFreeAdaptorInfo(adaptor_info);
-   }
-
-   if (!*found_port) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Could not find a suitable port.\n");
-      return XvBadPort;
-   }
-   if (!found_surface) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Could not find a suitable surface.\n");
-      return BadMatch;
-   }
-   if (width > max_width || height > max_height) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Requested context dimensions (w=%u,h=%u) too large (max w=%u,h=%u).\n",
-               width, height, max_width, max_height);
-      return BadValue;
-   }
-   if (flags != XVMC_DIRECT && flags != 0) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Invalid context flags 0x%08X.\n", flags);
-      return BadValue;
-   }
-
-   return Success;
-}
-
-static enum pipe_video_profile ProfileToPipe(int xvmc_profile)
-{
-   if (xvmc_profile & XVMC_MPEG_1)
-      assert(0);
-   if (xvmc_profile & XVMC_MPEG_2)
-      return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
-   if (xvmc_profile & XVMC_H263)
-      assert(0);
-   if (xvmc_profile & XVMC_MPEG_4)
-      assert(0);
-
-   assert(0);
-
-   XVMC_MSG(XVMC_ERR, "[XvMC] Unrecognized profile 0x%08X.\n", xvmc_profile);
-
-   return -1;
-}
-
-static enum pipe_video_chroma_format FormatToPipe(int xvmc_format)
-{
-   switch (xvmc_format) {
-      case XVMC_CHROMA_FORMAT_420:
-         return PIPE_VIDEO_CHROMA_FORMAT_420;
-      case XVMC_CHROMA_FORMAT_422:
-         return PIPE_VIDEO_CHROMA_FORMAT_422;
-      case XVMC_CHROMA_FORMAT_444:
-         return PIPE_VIDEO_CHROMA_FORMAT_444;
-      default:
-         assert(0);
-   }
-
-   XVMC_MSG(XVMC_ERR, "[XvMC] Unrecognized format 0x%08X.\n", xvmc_format);
-
-   return -1;
-}
-
-PUBLIC
-Status XvMCCreateContext(Display *dpy, XvPortID port, int surface_type_id,
-                         int width, int height, int flags, XvMCContext *context)
-{
-   bool found_port;
-   int scrn = 0;
-   int chroma_format = 0;
-   int mc_type = 0;
-   int surface_flags = 0;
-   unsigned short subpic_max_w = 0;
-   unsigned short subpic_max_h = 0;
-   Status ret;
-   struct vl_screen *vscreen;
-   struct pipe_context *pipe;
-   XvMCContextPrivate *context_priv;
-   float csc[16];
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Creating context %p.\n", context);
-
-   assert(dpy);
-
-   if (!context)
-      return XvMCBadContext;
-
-   ret = Validate(dpy, port, surface_type_id, width, height, flags,
-                  &found_port, &scrn, &chroma_format, &mc_type, &surface_flags,
-                  &subpic_max_w, &subpic_max_h);
-
-   /* Success and XvBadPort have the same value */
-   if (ret != Success || !found_port)
-      return ret;
-
-   /* XXX: Current limits */
-   if (chroma_format != XVMC_CHROMA_FORMAT_420) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Cannot decode requested surface type. Unsupported chroma format.\n");
-      return BadImplementation;
-   }
-   if ((mc_type & ~XVMC_IDCT) != (XVMC_MOCOMP | XVMC_MPEG_2)) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Cannot decode requested surface type. Non-MPEG2/Mocomp/iDCT acceleration unsupported.\n");
-      return BadImplementation;
-   }
-   if (surface_flags & XVMC_INTRA_UNSIGNED) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Cannot decode requested surface type. Unsigned intra unsupported.\n");
-      return BadImplementation;
-   }
-
-   context_priv = CALLOC(1, sizeof(XvMCContextPrivate));
-   if (!context_priv)
-      return BadAlloc;
-
-   /* TODO: Reuse screen if process creates another context */
-   vscreen = vl_screen_create(dpy, scrn);
-
-   if (!vscreen) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL screen.\n");
-      FREE(context_priv);
-      return BadAlloc;
-   }
-
-   pipe = vscreen->pscreen->context_create(vscreen->pscreen, vscreen);
-   if (!pipe) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL context.\n");
-      vl_screen_destroy(vscreen);
-      FREE(context_priv);
-      return BadAlloc;
-   }
-
-   context_priv->decoder = pipe->create_video_decoder
-   (
-      pipe, ProfileToPipe(mc_type),
-      (mc_type & XVMC_IDCT) ? PIPE_VIDEO_ENTRYPOINT_IDCT : PIPE_VIDEO_ENTRYPOINT_MC,
-      FormatToPipe(chroma_format),
-      width, height, 2,
-      true
-   );
-
-   if (!context_priv->decoder) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL decoder.\n");
-      pipe->destroy(pipe);
-      vl_screen_destroy(vscreen);
-      FREE(context_priv);
-      return BadAlloc;
-   }
-
-   if (!vl_compositor_init(&context_priv->compositor, pipe)) {
-      XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL compositor.\n");
-      context_priv->decoder->destroy(context_priv->decoder);
-      pipe->destroy(pipe);
-      vl_screen_destroy(vscreen);
-      FREE(context_priv);
-      return BadAlloc;
-   }
-
-   context_priv->color_standard =
-      debug_get_bool_option("G3DVL_NO_CSC", FALSE) ?
-      VL_CSC_COLOR_STANDARD_IDENTITY : VL_CSC_COLOR_STANDARD_BT_601;
-   context_priv->procamp = vl_default_procamp;
-
-   vl_csc_get_matrix
-   (
-      context_priv->color_standard,
-      &context_priv->procamp, true, csc
-   );
-   vl_compositor_set_csc_matrix(&context_priv->compositor, csc);
-
-   context_priv->vscreen = vscreen;
-   context_priv->pipe = pipe;
-   context_priv->subpicture_max_width = subpic_max_w;
-   context_priv->subpicture_max_height = subpic_max_h;
-
-   context->context_id = XAllocID(dpy);
-   context->surface_type_id = surface_type_id;
-   context->width = width;
-   context->height = height;
-   context->flags = flags;
-   context->port = port;
-   context->privData = context_priv;
-
-   SyncHandle();
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Context %p created.\n", context);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCDestroyContext(Display *dpy, XvMCContext *context)
-{
-   XvMCContextPrivate *context_priv;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Destroying context %p.\n", context);
-
-   assert(dpy);
-
-   if (!context || !context->privData)
-      return XvMCBadContext;
-
-   context_priv = context->privData;
-   pipe_surface_reference(&context_priv->drawable_surface, NULL);
-   context_priv->decoder->destroy(context_priv->decoder);
-   vl_compositor_cleanup(&context_priv->compositor);
-   context_priv->pipe->destroy(context_priv->pipe);
-   vl_screen_destroy(context_priv->vscreen);
-   FREE(context_priv);
-   context->privData = NULL;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Context %p destroyed.\n", context);
-
-   return Success;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/subpicture.c b/src/gallium/state_trackers/xorg/xvmc/subpicture.c
deleted file mode 100644 (file)
index d6be28e..0000000
+++ /dev/null
@@ -1,534 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-
-#include <X11/Xlibint.h>
-#include <X11/extensions/XvMClib.h>
-
-#include "pipe/p_screen.h"
-#include "pipe/p_video_decoder.h"
-#include "pipe/p_state.h"
-
-#include "util/u_memory.h"
-#include "util/u_math.h"
-#include "util/u_format.h"
-#include "util/u_sampler.h"
-#include "util/u_rect.h"
-
-#include "vl_winsys.h"
-
-#include "xvmc_private.h"
-
-#define FOURCC_RGB 0x0000003
-#define FOURCC_AI44 0x34344941
-#define FOURCC_IA44 0x34344149
-
-static enum pipe_format XvIDToPipe(int xvimage_id)
-{
-   switch (xvimage_id) {
-      case FOURCC_RGB:
-         return PIPE_FORMAT_B8G8R8X8_UNORM;
-
-      case FOURCC_AI44:
-         return PIPE_FORMAT_A4R4_UNORM;
-
-      case FOURCC_IA44:
-         return PIPE_FORMAT_R4A4_UNORM;
-
-      default:
-         XVMC_MSG(XVMC_ERR, "[XvMC] Unrecognized Xv image ID 0x%08X.\n", xvimage_id);
-         return PIPE_FORMAT_NONE;
-   }
-}
-
-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:
-         return 0;
-
-      case PIPE_FORMAT_R4A4_UNORM:
-      case PIPE_FORMAT_A4R4_UNORM:
-         component_order[0] = 'Y';
-         component_order[1] = 'U';
-         component_order[2] = 'V';
-         component_order[3] = 'A';
-         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;
-   }
-}
-
-static Status Validate(Display *dpy, XvPortID port, int surface_type_id, int xvimage_id)
-{
-   XvImageFormatValues *subpictures;
-   int num_subpics;
-   unsigned int i;
-
-   subpictures = XvMCListSubpictureTypes(dpy, port, surface_type_id, &num_subpics);
-   if (num_subpics < 1) {
-      if (subpictures)
-         XFree(subpictures);
-      return BadMatch;
-   }
-   if (!subpictures)
-      return BadAlloc;
-
-   for (i = 0; i < num_subpics; ++i) {
-      if (subpictures[i].id == xvimage_id) {
-         XVMC_MSG(XVMC_TRACE, "[XvMC] Found requested subpicture format.\n" \
-                              "[XvMC]   port=%u\n" \
-                              "[XvMC]   surface id=0x%08X\n" \
-                              "[XvMC]   image id=0x%08X\n" \
-                              "[XvMC]   type=%08X\n" \
-                              "[XvMC]   byte order=%08X\n" \
-                              "[XvMC]   bits per pixel=%u\n" \
-                              "[XvMC]   format=%08X\n" \
-                              "[XvMC]   num planes=%d\n",
-                              port, surface_type_id, xvimage_id, subpictures[i].type, subpictures[i].byte_order,
-                              subpictures[i].bits_per_pixel, subpictures[i].format, subpictures[i].num_planes);
-         if (subpictures[i].type == XvRGB) {
-            XVMC_MSG(XVMC_TRACE, "[XvMC]   depth=%d\n" \
-                                 "[XvMC]   red mask=0x%08X\n" \
-                                 "[XvMC]   green mask=0x%08X\n" \
-                                 "[XvMC]   blue mask=0x%08X\n",
-                                 subpictures[i].depth, subpictures[i].red_mask,
-                                 subpictures[i].green_mask, subpictures[i].blue_mask);
-         }
-         else if (subpictures[i].type == XvYUV) {
-            XVMC_MSG(XVMC_TRACE, "[XvMC]   y sample bits=0x%08X\n" \
-                                 "[XvMC]   u sample bits=0x%08X\n" \
-                                 "[XvMC]   v sample bits=0x%08X\n" \
-                                 "[XvMC]   horz y period=%u\n" \
-                                 "[XvMC]   horz u period=%u\n" \
-                                 "[XvMC]   horz v period=%u\n" \
-                                 "[XvMC]   vert y period=%u\n" \
-                                 "[XvMC]   vert u period=%u\n" \
-                                 "[XvMC]   vert v period=%u\n",
-                                 subpictures[i].y_sample_bits, subpictures[i].u_sample_bits, subpictures[i].v_sample_bits,
-                                 subpictures[i].horz_y_period, subpictures[i].horz_u_period, subpictures[i].horz_v_period,
-                                 subpictures[i].vert_y_period, subpictures[i].vert_u_period, subpictures[i].vert_v_period);
-         }
-         break;
-      }
-   }
-
-   XFree(subpictures);
-
-   return i < num_subpics ? Success : BadMatch;
-}
-
-static void
-upload_sampler(struct pipe_context *pipe, struct pipe_sampler_view *dst,
-               const struct pipe_box *dst_box, const void *src, unsigned src_stride,
-               unsigned src_x, unsigned src_y)
-{
-   struct pipe_transfer *transfer;
-   void *map;
-
-   transfer = pipe->get_transfer(pipe, dst->texture, 0, PIPE_TRANSFER_WRITE, dst_box);
-   if (!transfer)
-      return;
-
-   map = pipe->transfer_map(pipe, transfer);
-   if (map) {
-      util_copy_rect(map, dst->texture->format, transfer->stride, 0, 0,
-                     dst_box->width, dst_box->height,
-                     src, src_stride, src_x, src_y);
-
-      pipe->transfer_unmap(pipe, transfer);
-   }
-
-   pipe->transfer_destroy(pipe, transfer);
-}
-
-PUBLIC
-Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *subpicture,
-                            unsigned short width, unsigned short height, int xvimage_id)
-{
-   XvMCContextPrivate *context_priv;
-   XvMCSubpicturePrivate *subpicture_priv;
-   struct pipe_context *pipe;
-   struct pipe_resource tex_templ, *tex;
-   struct pipe_sampler_view sampler_templ;
-   Status ret;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Creating subpicture %p.\n", subpicture);
-
-   assert(dpy);
-
-   if (!context)
-      return XvMCBadContext;
-
-   context_priv = context->privData;
-   pipe = context_priv->pipe;
-
-   if (!subpicture)
-      return XvMCBadSubpicture;
-
-   if (width > context_priv->subpicture_max_width ||
-       height > context_priv->subpicture_max_height)
-      return BadValue;
-
-   ret = Validate(dpy, context->port, context->surface_type_id, xvimage_id);
-   if (ret != Success)
-      return ret;
-
-   subpicture_priv = CALLOC(1, sizeof(XvMCSubpicturePrivate));
-   if (!subpicture_priv)
-      return BadAlloc;
-
-   memset(&tex_templ, 0, sizeof(tex_templ));
-   tex_templ.target = PIPE_TEXTURE_2D;
-   tex_templ.format = XvIDToPipe(xvimage_id);
-   tex_templ.last_level = 0;
-   if (pipe->screen->get_video_param(pipe->screen,
-                                     PIPE_VIDEO_PROFILE_UNKNOWN,
-                                     PIPE_VIDEO_CAP_NPOT_TEXTURES)) {
-      tex_templ.width0 = width;
-      tex_templ.height0 = height;
-   }
-   else {
-      tex_templ.width0 = util_next_power_of_two(width);
-      tex_templ.height0 = util_next_power_of_two(height);
-   }
-   tex_templ.depth0 = 1;
-   tex_templ.array_size = 1;
-   tex_templ.usage = PIPE_USAGE_DYNAMIC;
-   tex_templ.bind = PIPE_BIND_SAMPLER_VIEW;
-   tex_templ.flags = 0;
-
-   tex = pipe->screen->resource_create(pipe->screen, &tex_templ);
-
-   memset(&sampler_templ, 0, sizeof(sampler_templ));
-   u_sampler_view_default_template(&sampler_templ, tex, tex->format);
-
-   subpicture_priv->sampler = pipe->create_sampler_view(pipe, tex, &sampler_templ);
-   pipe_resource_reference(&tex, NULL);
-   if (!subpicture_priv->sampler) {
-      FREE(subpicture_priv);
-      return BadAlloc;
-   }
-
-   subpicture_priv->context = context;
-   subpicture->subpicture_id = XAllocID(dpy);
-   subpicture->context_id = context->context_id;
-   subpicture->xvimage_id = xvimage_id;
-   subpicture->width = width;
-   subpicture->height = height;
-   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_R8G8B8X8_UNORM;
-      tex_templ.width0 = subpicture->num_palette_entries;
-      tex_templ.height0 = 1;
-      tex_templ.usage = PIPE_USAGE_STATIC;
-
-      tex = pipe->screen->resource_create(pipe->screen, &tex_templ);
-
-      memset(&sampler_templ, 0, sizeof(sampler_templ));
-      u_sampler_view_default_template(&sampler_templ, tex, tex->format);
-      sampler_templ.swizzle_a = PIPE_SWIZZLE_ONE;
-      subpicture_priv->palette = pipe->create_sampler_view(pipe, 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);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCClearSubpicture(Display *dpy, XvMCSubpicture *subpicture, short x, short y,
-                           unsigned short width, unsigned short height, unsigned int color)
-{
-   XvMCSubpicturePrivate *subpicture_priv;
-   XvMCContextPrivate *context_priv;
-   struct pipe_context *pipe;
-   struct pipe_sampler_view *dst;
-   struct pipe_box dst_box = {x, y, 0, width, height, 1};
-   struct pipe_transfer *transfer;
-   union util_color uc;
-   void *map;
-
-   assert(dpy);
-
-   if (!subpicture)
-      return XvMCBadSubpicture;
-
-   /* Convert color to float */
-   util_format_read_4f(PIPE_FORMAT_B8G8R8A8_UNORM,
-                       uc.f, 1, &color, 4,
-                       0, 0, 1, 1);
-
-   subpicture_priv = subpicture->privData;
-   context_priv = subpicture_priv->context->privData;
-   pipe = context_priv->pipe;
-   dst = subpicture_priv->sampler;
-   
-   /* TODO: Assert clear rect is within bounds? Or clip? */
-   transfer = pipe->get_transfer(pipe, dst->texture, 0, PIPE_TRANSFER_WRITE, &dst_box);
-   if (!transfer)
-      return XvMCBadSubpicture;
-
-   map = pipe->transfer_map(pipe, transfer);
-   if (map) {
-      util_fill_rect(map, dst->texture->format, transfer->stride, 0, 0,
-                     dst_box.width, dst_box.height, &uc);
-
-      pipe->transfer_unmap(pipe, transfer);
-   }
-
-   pipe->transfer_destroy(pipe, transfer);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCCompositeSubpicture(Display *dpy, XvMCSubpicture *subpicture, XvImage *image,
-                               short srcx, short srcy, unsigned short width, unsigned short height,
-                               short dstx, short dsty)
-{
-   XvMCSubpicturePrivate *subpicture_priv;
-   XvMCContextPrivate *context_priv;
-   struct pipe_context *pipe;
-   struct pipe_box dst_box = {dstx, dsty, 0, width, height, 1};
-   unsigned src_stride;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Compositing subpicture %p.\n", subpicture);
-
-   assert(dpy);
-
-   if (!subpicture)
-      return XvMCBadSubpicture;
-
-   assert(image);
-
-   if (subpicture->xvimage_id != image->id)
-      return BadMatch;
-
-   /* No planar support for now */
-   if (image->num_planes != 1)
-      return BadMatch;
-
-   subpicture_priv = subpicture->privData;
-   context_priv = subpicture_priv->context->privData;
-   pipe = context_priv->pipe;
-
-   /* clipping should be done by upload_sampler and regardles what the documentation
-   says image->pitches[0] doesn't seems to be in bytes, so don't use it */
-   src_stride = image->width * util_format_get_blocksize(subpicture_priv->sampler->texture->format);
-   upload_sampler(pipe, subpicture_priv->sampler, &dst_box, image->data, src_stride, srcx, srcy);
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Subpicture %p composited.\n", subpicture);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCDestroySubpicture(Display *dpy, XvMCSubpicture *subpicture)
-{
-   XvMCSubpicturePrivate *subpicture_priv;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Destroying subpicture %p.\n", subpicture);
-
-   assert(dpy);
-
-   if (!subpicture)
-      return XvMCBadSubpicture;
-
-   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);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCSetSubpicturePalette(Display *dpy, XvMCSubpicture *subpicture, unsigned char *palette)
-{
-   XvMCSubpicturePrivate *subpicture_priv;
-   XvMCContextPrivate *context_priv;
-   struct pipe_context *pipe;
-   struct pipe_box dst_box = {0, 0, 0, 0, 1, 1};
-
-   assert(dpy);
-   assert(palette);
-
-   if (!subpicture)
-      return XvMCBadSubpicture;
-
-   subpicture_priv = subpicture->privData;
-   context_priv = subpicture_priv->context->privData;
-   pipe = context_priv->pipe;
-
-   dst_box.width = subpicture->num_palette_entries;
-
-   upload_sampler(pipe, subpicture_priv->palette, &dst_box, palette, 0, 0, 0);
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Palette of Subpicture %p set.\n", subpicture);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCBlendSubpicture(Display *dpy, XvMCSurface *target_surface, XvMCSubpicture *subpicture,
-                           short subx, short suby, unsigned short subw, unsigned short subh,
-                           short surfx, short surfy, unsigned short surfw, unsigned short surfh)
-{
-   struct pipe_video_rect src_rect = {subx, suby, subw, subh};
-   struct pipe_video_rect dst_rect = {surfx, surfy, surfw, surfh};
-
-   XvMCSurfacePrivate *surface_priv;
-   XvMCSubpicturePrivate *subpicture_priv;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Associating subpicture %p with surface %p.\n", subpicture, target_surface);
-
-   assert(dpy);
-
-   if (!target_surface)
-      return XvMCBadSurface;
-
-   if (!subpicture)
-      return XvMCBadSubpicture;
-
-   if (target_surface->context_id != subpicture->context_id)
-      return BadMatch;
-
-   /* TODO: Verify against subpicture independent scaling */
-
-   surface_priv = target_surface->privData;
-   subpicture_priv = subpicture->privData;
-
-   /* TODO: Assert rects are within bounds? Or clip? */
-   subpicture_priv->src_rect = src_rect;
-   subpicture_priv->dst_rect = dst_rect;
-
-   surface_priv->subpicture = subpicture;
-   subpicture_priv->surface = target_surface;
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCBlendSubpicture2(Display *dpy, XvMCSurface *source_surface, XvMCSurface *target_surface,
-                            XvMCSubpicture *subpicture, short subx, short suby, unsigned short subw, unsigned short subh,
-                            short surfx, short surfy, unsigned short surfw, unsigned short surfh)
-{
-   assert(dpy);
-
-   if (!source_surface || !target_surface)
-      return XvMCBadSurface;
-
-   if (!subpicture)
-      return XvMCBadSubpicture;
-
-   if (source_surface->context_id != subpicture->context_id)
-      return BadMatch;
-
-   if (source_surface->context_id != subpicture->context_id)
-      return BadMatch;
-
-   /* TODO: Assert rects are within bounds? Or clip? */
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCSyncSubpicture(Display *dpy, XvMCSubpicture *subpicture)
-{
-   assert(dpy);
-
-   if (!subpicture)
-      return XvMCBadSubpicture;
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCFlushSubpicture(Display *dpy, XvMCSubpicture *subpicture)
-{
-   assert(dpy);
-
-   if (!subpicture)
-      return XvMCBadSubpicture;
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCGetSubpictureStatus(Display *dpy, XvMCSubpicture *subpicture, int *status)
-{
-   assert(dpy);
-
-   if (!subpicture)
-      return XvMCBadSubpicture;
-
-   assert(status);
-
-   /* TODO */
-   *status = 0;
-
-   return Success;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/surface.c b/src/gallium/state_trackers/xorg/xvmc/surface.c
deleted file mode 100644 (file)
index 293e7ad..0000000
+++ /dev/null
@@ -1,537 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <stdio.h>
-
-#include <X11/Xlibint.h>
-
-#include "pipe/p_video_decoder.h"
-#include "pipe/p_video_state.h"
-#include "pipe/p_state.h"
-
-#include "util/u_inlines.h"
-#include "util/u_memory.h"
-#include "util/u_math.h"
-
-#include "vl_winsys.h"
-
-#include "xvmc_private.h"
-
-static void
-MacroBlocksToPipe(XvMCContextPrivate *context,
-                  XvMCSurfacePrivate *surface,
-                  unsigned int xvmc_picture_structure,
-                  const XvMCMacroBlock *xvmc_mb,
-                  const XvMCBlockArray *xvmc_blocks,
-                  struct pipe_mpeg12_macroblock *mb,
-                  unsigned int num_macroblocks)
-{
-   unsigned int i, j, k;
-
-   assert(xvmc_mb);
-   assert(xvmc_blocks);
-   assert(num_macroblocks);
-
-   for (; num_macroblocks > 0; --num_macroblocks) {
-      mb->base.codec = PIPE_VIDEO_CODEC_MPEG12;
-      mb->x = xvmc_mb->x;
-      mb->y = xvmc_mb->y;
-      mb->macroblock_type = xvmc_mb->macroblock_type;
-
-      switch (xvmc_picture_structure) {
-      case XVMC_FRAME_PICTURE:
-         mb->macroblock_modes.bits.frame_motion_type = xvmc_mb->motion_type;
-         mb->macroblock_modes.bits.field_motion_type = 0;
-         break;
-
-      case XVMC_TOP_FIELD:
-      case XVMC_BOTTOM_FIELD:
-         mb->macroblock_modes.bits.frame_motion_type = 0;
-         mb->macroblock_modes.bits.field_motion_type = xvmc_mb->motion_type;
-         break;
-
-      default:
-         assert(0);
-      }
-
-      mb->macroblock_modes.bits.dct_type = xvmc_mb->dct_type;
-      mb->motion_vertical_field_select = xvmc_mb->motion_vertical_field_select;
-
-      for (i = 0; i < 2; ++i)
-         for (j = 0; j < 2; ++j)
-            for (k = 0; k < 2; ++k)
-               mb->PMV[i][j][k] = xvmc_mb->PMV[i][j][k];
-
-      mb->coded_block_pattern = xvmc_mb->coded_block_pattern;
-      mb->blocks = xvmc_blocks->blocks + xvmc_mb->index * BLOCK_SIZE_SAMPLES;
-      mb->num_skipped_macroblocks = 0;
-
-      ++xvmc_mb;
-      ++mb;
-   }
-}
-
-static void
-GetPictureDescription(XvMCSurfacePrivate *surface, struct pipe_mpeg12_picture_desc *desc)
-{
-   unsigned i, num_refs = 0;
-
-   assert(surface && desc);
-
-   memset(desc, 0, sizeof(*desc));
-   desc->base.profile = PIPE_VIDEO_PROFILE_MPEG1;
-   desc->picture_structure = surface->picture_structure;
-   for (i = 0; i < 2; ++i) {
-      if (surface->ref[i]) {
-         XvMCSurfacePrivate *ref = surface->ref[i]->privData;
-
-         if (ref)
-            desc->ref[num_refs++] = ref->video_buffer;
-      }
-   }
-}
-
-static void
-RecursiveEndFrame(XvMCSurfacePrivate *surface)
-{
-   XvMCContextPrivate *context_priv;
-   unsigned i;
-
-   assert(surface);
-
-   context_priv = surface->context->privData;
-
-   for ( i = 0; i < 2; ++i ) {
-      if (surface->ref[i]) {
-         XvMCSurface *ref = surface->ref[i];
-
-         assert(ref);
-
-         surface->ref[i] = NULL;
-         RecursiveEndFrame(ref->privData);
-         surface->ref[i] = ref;
-      }
-   }
-
-   if (surface->picture_structure) {
-      struct pipe_mpeg12_picture_desc desc;
-      GetPictureDescription(surface, &desc);
-      surface->picture_structure = 0;
-
-      for (i = 0; i < 2; ++i)
-         surface->ref[i] = NULL;
-
-      context_priv->decoder->end_frame(context_priv->decoder, surface->video_buffer, &desc.base);
-   }
-}
-
-PUBLIC
-Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surface)
-{
-   XvMCContextPrivate *context_priv;
-   struct pipe_context *pipe;
-   XvMCSurfacePrivate *surface_priv;
-   struct pipe_video_buffer tmpl;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Creating surface %p.\n", surface);
-
-   assert(dpy);
-
-   if (!context)
-      return XvMCBadContext;
-   if (!surface)
-      return XvMCBadSurface;
-
-   context_priv = context->privData;
-   pipe = context_priv->pipe;
-
-   surface_priv = CALLOC(1, sizeof(XvMCSurfacePrivate));
-   if (!surface_priv)
-      return BadAlloc;
-
-   memset(&tmpl, 0, sizeof(tmpl));
-   tmpl.buffer_format = pipe->screen->get_video_param
-   (
-      pipe->screen,
-      PIPE_VIDEO_PROFILE_MPEG2_MAIN,
-      PIPE_VIDEO_CAP_PREFERED_FORMAT
-   );
-   tmpl.chroma_format = context_priv->decoder->chroma_format;
-   tmpl.width = context_priv->decoder->width;
-   tmpl.height = context_priv->decoder->height;
-   tmpl.interlaced = pipe->screen->get_video_param
-   (
-      pipe->screen,
-      PIPE_VIDEO_PROFILE_MPEG2_MAIN,
-      PIPE_VIDEO_CAP_PREFERS_INTERLACED
-   );
-
-   surface_priv->video_buffer = pipe->create_video_buffer(pipe, &tmpl);
-   surface_priv->context = context;
-
-   surface->surface_id = XAllocID(dpy);
-   surface->context_id = context->context_id;
-   surface->surface_type_id = context->surface_type_id;
-   surface->width = context->width;
-   surface->height = context->height;
-   surface->privData = surface_priv;
-
-   SyncHandle();
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Surface %p created.\n", surface);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCRenderSurface(Display *dpy, XvMCContext *context, unsigned int picture_structure,
-                         XvMCSurface *target_surface, XvMCSurface *past_surface, XvMCSurface *future_surface,
-                         unsigned int flags, unsigned int num_macroblocks, unsigned int first_macroblock,
-                         XvMCMacroBlockArray *macroblocks, XvMCBlockArray *blocks
-)
-{
-   struct pipe_mpeg12_macroblock mb[num_macroblocks];
-   struct pipe_video_decoder *decoder;
-   struct pipe_mpeg12_picture_desc desc;
-
-   XvMCContextPrivate *context_priv;
-   XvMCSurfacePrivate *target_surface_priv;
-   XvMCSurfacePrivate *past_surface_priv;
-   XvMCSurfacePrivate *future_surface_priv;
-   XvMCMacroBlock *xvmc_mb;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Rendering to surface %p, with past %p and future %p\n",
-            target_surface, past_surface, future_surface);
-
-   assert(dpy);
-
-   if (!context || !context->privData)
-      return XvMCBadContext;
-   if (!target_surface || !target_surface->privData)
-      return XvMCBadSurface;
-
-   if (picture_structure != XVMC_TOP_FIELD &&
-       picture_structure != XVMC_BOTTOM_FIELD &&
-       picture_structure != XVMC_FRAME_PICTURE)
-      return BadValue;
-   /* Bkwd pred equivalent to fwd (past && !future) */
-   if (future_surface && !past_surface)
-      return BadMatch;
-
-   assert(context->context_id == target_surface->context_id);
-   assert(!past_surface || context->context_id == past_surface->context_id);
-   assert(!future_surface || context->context_id == future_surface->context_id);
-
-   assert(macroblocks);
-   assert(blocks);
-
-   assert(macroblocks->context_id == context->context_id);
-   assert(blocks->context_id == context->context_id);
-
-   assert(flags == 0 || flags == XVMC_SECOND_FIELD);
-
-   context_priv = context->privData;
-   decoder = context_priv->decoder;
-
-   target_surface_priv = target_surface->privData;
-   past_surface_priv = past_surface ? past_surface->privData : NULL;
-   future_surface_priv = future_surface ? future_surface->privData : NULL;
-
-   assert(target_surface_priv->context == context);
-   assert(!past_surface || past_surface_priv->context == context);
-   assert(!future_surface || future_surface_priv->context == context);
-
-   // call end frame on all referenced frames
-   if (past_surface)
-      RecursiveEndFrame(past_surface->privData);
-
-   if (future_surface)
-      RecursiveEndFrame(future_surface->privData);
-
-   xvmc_mb = macroblocks->macro_blocks + first_macroblock;
-
-   /* If the surface we're rendering hasn't changed the ref frames shouldn't change. */
-   if (target_surface_priv->picture_structure > 0 && (
-       target_surface_priv->picture_structure != picture_structure ||
-       target_surface_priv->ref[0] != past_surface ||
-       target_surface_priv->ref[1] != future_surface ||
-       (xvmc_mb->x == 0 && xvmc_mb->y == 0))) {
-
-      // If they change anyway we must assume that the current frame is ended
-      RecursiveEndFrame(target_surface_priv);
-   }
-
-   target_surface_priv->ref[0] = past_surface;
-   target_surface_priv->ref[1] = future_surface;
-
-   if (target_surface_priv->picture_structure)
-      GetPictureDescription(target_surface_priv, &desc);
-   else {
-      target_surface_priv->picture_structure = picture_structure;
-      GetPictureDescription(target_surface_priv, &desc);
-      decoder->begin_frame(decoder, target_surface_priv->video_buffer, &desc.base);
-   }
-
-   MacroBlocksToPipe(context_priv, target_surface_priv, picture_structure,
-                     xvmc_mb, blocks, mb, num_macroblocks);
-
-   context_priv->decoder->decode_macroblock(context_priv->decoder,
-                                            target_surface_priv->video_buffer,
-                                            &desc.base,
-                                            &mb[0].base, num_macroblocks);
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Submitted surface %p for rendering.\n", target_surface);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCFlushSurface(Display *dpy, XvMCSurface *surface)
-{
-   assert(dpy);
-
-   if (!surface)
-      return XvMCBadSurface;
-
-   // don't call flush here, because this is usually
-   // called once for every slice instead of every frame
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Flushing surface %p\n", surface);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCSyncSurface(Display *dpy, XvMCSurface *surface)
-{
-   assert(dpy);
-
-   if (!surface)
-      return XvMCBadSurface;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Syncing surface %p\n", surface);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCPutSurface(Display *dpy, XvMCSurface *surface, Drawable drawable,
-                      short srcx, short srcy, unsigned short srcw, unsigned short srch,
-                      short destx, short desty, unsigned short destw, unsigned short desth,
-                      int flags)
-{
-   static int dump_window = -1;
-
-   struct pipe_context *pipe;
-   struct vl_compositor *compositor;
-
-   XvMCSurfacePrivate *surface_priv;
-   XvMCContextPrivate *context_priv;
-   XvMCSubpicturePrivate *subpicture_priv;
-   XvMCContext *context;
-   struct pipe_video_rect src_rect = {srcx, srcy, srcw, srch};
-   struct pipe_video_rect dst_rect = {destx, desty, destw, desth};
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Displaying surface %p.\n", surface);
-
-   assert(dpy);
-
-   if (!surface || !surface->privData)
-      return XvMCBadSurface;
-
-   surface_priv = surface->privData;
-   context = surface_priv->context;
-   context_priv = context->privData;
-
-   assert(flags == XVMC_TOP_FIELD || flags == XVMC_BOTTOM_FIELD || flags == XVMC_FRAME_PICTURE);
-   assert(srcx + srcw - 1 < surface->width);
-   assert(srcy + srch - 1 < surface->height);
-
-   subpicture_priv = surface_priv->subpicture ? surface_priv->subpicture->privData : NULL;
-   pipe = context_priv->pipe;
-   compositor = &context_priv->compositor;
-
-   if (!context_priv->drawable_surface ||
-       context_priv->dst_rect.x != dst_rect.x || context_priv->dst_rect.y != dst_rect.y ||
-       context_priv->dst_rect.w != dst_rect.w || context_priv->dst_rect.h != dst_rect.h) {
-
-      struct pipe_surface surf_templ;
-      struct pipe_resource *tex = vl_screen_texture_from_drawable(
-         context_priv->vscreen, drawable);
-
-      pipe_surface_reference(&context_priv->drawable_surface, NULL);
-
-      memset(&surf_templ, 0, sizeof(surf_templ));
-      surf_templ.format = tex->format;
-      surf_templ.usage = PIPE_BIND_RENDER_TARGET;
-      context_priv->drawable_surface = pipe->create_surface(pipe, tex, &surf_templ);
-      vl_compositor_reset_dirty_area(&context_priv->dirty_area);
-      context_priv->dst_rect = dst_rect;
-   }
-
-   if (!context_priv->drawable_surface)
-      return BadDrawable;
-
-   /*
-    * Some apps (mplayer) hit these asserts because they call
-    * this function after the window has been resized by the WM
-    * but before they've handled the corresponding XEvent and
-    * know about the new dimensions. The output should be clipped
-    * until the app updates destw and desth.
-    */
-   /*
-   assert(destx + destw - 1 < drawable_surface->width);
-   assert(desty + desth - 1 < drawable_surface->height);
-    */
-
-   RecursiveEndFrame(surface_priv);
-
-   context_priv->decoder->flush(context_priv->decoder);
-
-   vl_compositor_clear_layers(compositor);
-   vl_compositor_set_buffer_layer(compositor, 0, surface_priv->video_buffer,
-                                  &src_rect, NULL, VL_COMPOSITOR_WEAVE);
-
-   if (subpicture_priv) {
-      XVMC_MSG(XVMC_TRACE, "[XvMC] Surface %p has subpicture %p.\n", surface, surface_priv->subpicture);
-
-      assert(subpicture_priv->surface == surface);
-
-      if (subpicture_priv->palette)
-         vl_compositor_set_palette_layer(compositor, 1, subpicture_priv->sampler, subpicture_priv->palette,
-                                         &subpicture_priv->src_rect, &subpicture_priv->dst_rect, true);
-      else
-         vl_compositor_set_rgba_layer(compositor, 1, subpicture_priv->sampler,
-                                      &subpicture_priv->src_rect, &subpicture_priv->dst_rect);
-
-      surface_priv->subpicture = NULL;
-      subpicture_priv->surface = NULL;
-   }
-
-   // Workaround for r600g, there seems to be a bug in the fence refcounting code
-   pipe->screen->fence_reference(pipe->screen, &surface_priv->fence, NULL);
-
-   vl_compositor_render(compositor, context_priv->drawable_surface, &dst_rect, NULL, &context_priv->dirty_area);
-                        
-   pipe->flush(pipe, &surface_priv->fence);
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Submitted surface %p for display. Pushing to front buffer.\n", surface);
-
-   pipe->screen->flush_frontbuffer
-   (
-      pipe->screen, context_priv->drawable_surface->texture, 0, 0,
-      vl_screen_get_private(context_priv->vscreen)
-   );
-
-   if(dump_window == -1) {
-      dump_window = debug_get_num_option("XVMC_DUMP", 0);
-   }
-
-   if(dump_window) {
-      static unsigned int framenum = 0;
-      char cmd[256];
-
-      sprintf(cmd, "xwd -id %d -out xvmc_frame_%08d.xwd", (int)drawable, ++framenum);
-      if (system(cmd) != 0)
-         XVMC_MSG(XVMC_ERR, "[XvMC] Dumping surface %p failed.\n", surface);
-   }
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Pushed surface %p to front buffer.\n", surface);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCGetSurfaceStatus(Display *dpy, XvMCSurface *surface, int *status)
-{
-   struct pipe_context *pipe;
-   XvMCSurfacePrivate *surface_priv;
-   XvMCContextPrivate *context_priv;
-
-   assert(dpy);
-
-   if (!surface)
-      return XvMCBadSurface;
-
-   assert(status);
-
-   surface_priv = surface->privData;
-   context_priv = surface_priv->context->privData;
-   pipe = context_priv->pipe;
-
-   *status = 0;
-
-   if (surface_priv->fence)
-      if (!pipe->screen->fence_signalled(pipe->screen, surface_priv->fence))
-         *status |= XVMC_RENDERING;
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCDestroySurface(Display *dpy, XvMCSurface *surface)
-{
-   XvMCSurfacePrivate *surface_priv;
-   XvMCContextPrivate *context_priv;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Destroying surface %p.\n", surface);
-
-   assert(dpy);
-
-   if (!surface || !surface->privData)
-      return XvMCBadSurface;
-
-   surface_priv = surface->privData;
-   context_priv = surface_priv->context->privData;
-   
-   if (surface_priv->picture_structure) {
-      struct pipe_mpeg12_picture_desc desc;
-      GetPictureDescription(surface_priv, &desc);
-      context_priv->decoder->end_frame(context_priv->decoder, surface_priv->video_buffer, &desc.base);
-   }
-   surface_priv->video_buffer->destroy(surface_priv->video_buffer);
-   FREE(surface_priv);
-   surface->privData = NULL;
-
-   XVMC_MSG(XVMC_TRACE, "[XvMC] Surface %p destroyed.\n", surface);
-
-   return Success;
-}
-
-PUBLIC
-Status XvMCHideSurface(Display *dpy, XvMCSurface *surface)
-{
-   assert(dpy);
-
-   if (!surface || !surface->privData)
-      return XvMCBadSurface;
-
-   /* No op, only for overlaid rendering */
-
-   return Success;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/.gitignore b/src/gallium/state_trackers/xorg/xvmc/tests/.gitignore
deleted file mode 100644 (file)
index 9a8e05d..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-test_context
-test_surface
-test_subpicture
-test_blocks
-test_rendering
-xvmc_bench
diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/Makefile b/src/gallium/state_trackers/xorg/xvmc/tests/Makefile
deleted file mode 100644 (file)
index 88b0376..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-TOP = ../../../../../..
-include $(TOP)/configs/current
-
-LIBS = -lXvMCW -lXvMC -lXv -lX11
-
-#############################################
-
-.PHONY: default clean
-
-default: test_context test_surface test_subpicture test_blocks test_rendering xvmc_bench
-
-test_context: test_context.o testlib.o
-       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-test_surface: test_surface.o testlib.o
-       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-test_subpicture: test_subpicture.o testlib.o
-       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-test_blocks: test_blocks.o testlib.o
-       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-test_rendering: test_rendering.o testlib.o
-       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-xvmc_bench: xvmc_bench.o testlib.o
-       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
-
-clean:
-       $(RM) -rf *.o test_context test_surface test_subpicture test_blocks test_rendering xvmc_bench
diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/test_blocks.c b/src/gallium/state_trackers/xorg/xvmc/tests/test_blocks.c
deleted file mode 100644 (file)
index 994e3ca..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- * 
- **************************************************************************/
-
-#include <assert.h>
-#include <error.h>
-#include "testlib.h"
-
-int main(int argc, char **argv)
-{
-       const unsigned int      width = 16, height = 16;
-       const unsigned int      min_required_blocks = 1, min_required_macroblocks = 1;
-       const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
-
-       Display                 *display;
-       XvPortID                port_num;
-       int                     surface_type_id;
-       unsigned int            is_overlay, intra_unsigned;
-       int                     colorkey;
-       XvMCContext             context;
-       XvMCSurface             surface;
-       XvMCBlockArray          blocks = {0};
-       XvMCMacroBlockArray     macroblocks = {0};
-
-       display = XOpenDisplay(NULL);
-
-       if (!GetPort
-       (
-               display,
-               width,
-               height,
-               XVMC_CHROMA_FORMAT_420,
-               mc_types,
-               2,
-               &port_num,
-               &surface_type_id,
-               &is_overlay,
-               &intra_unsigned
-       ))
-       {
-               XCloseDisplay(display);
-               error(1, 0, "Error, unable to find a good port.\n");
-       }
-
-       if (is_overlay)
-       {
-               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
-               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
-       }
-
-       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
-       assert(XvMCCreateSurface(display, &context, &surface) == Success);
-
-       /* Test NULL context */
-       assert(XvMCCreateBlocks(display, NULL, 1, &blocks) == XvMCBadContext);
-       /* Test 0 blocks */
-       assert(XvMCCreateBlocks(display, &context, 0, &blocks) == BadValue);
-       /* Test valid params */
-       assert(XvMCCreateBlocks(display, &context, min_required_blocks, &blocks) == Success);
-       /* Test context id assigned and correct */
-       assert(blocks.context_id == context.context_id);
-       /* Test number of blocks assigned and correct */
-       assert(blocks.num_blocks == min_required_blocks);
-       /* Test block pointer valid */
-       assert(blocks.blocks != NULL);
-       /* Test NULL context */
-       assert(XvMCCreateMacroBlocks(display, NULL, 1, &macroblocks) == XvMCBadContext);
-       /* Test 0 macroblocks */
-       assert(XvMCCreateMacroBlocks(display, &context, 0, &macroblocks) == BadValue);
-       /* Test valid params */
-       assert(XvMCCreateMacroBlocks(display, &context, min_required_macroblocks, &macroblocks) == Success);
-       /* Test context id assigned and correct */
-       assert(macroblocks.context_id == context.context_id);
-       /* Test macroblock pointer valid */
-       assert(macroblocks.macro_blocks != NULL);
-       /* Test valid params */
-       assert(XvMCDestroyMacroBlocks(display, &macroblocks) == Success);
-       /* Test valid params */
-       assert(XvMCDestroyBlocks(display, &blocks) == Success);
-
-       assert(XvMCDestroySurface(display, &surface) == Success);
-       assert(XvMCDestroyContext(display, &context) == Success);
-
-       XvUngrabPort(display, port_num, CurrentTime);
-       XCloseDisplay(display);
-
-       return 0;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/test_context.c b/src/gallium/state_trackers/xorg/xvmc/tests/test_context.c
deleted file mode 100644 (file)
index 3da957c..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- * 
- **************************************************************************/
-
-#include <assert.h>
-#include <error.h>
-#include "testlib.h"
-
-int main(int argc, char **argv)
-{
-       const unsigned int      width = 16, height = 16;
-       const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
-
-       Display                 *display;
-       XvPortID                port_num;
-       int                     surface_type_id;
-       unsigned int            is_overlay, intra_unsigned;
-       int                     colorkey;
-       XvMCContext             context = {0};
-
-       display = XOpenDisplay(NULL);
-
-       if (!GetPort
-       (
-               display,
-               width,
-               height,
-               XVMC_CHROMA_FORMAT_420,
-               mc_types,
-               2,
-               &port_num,
-               &surface_type_id,
-               &is_overlay,
-               &intra_unsigned
-       ))
-       {
-               XCloseDisplay(display);
-               error(1, 0, "Error, unable to find a good port.\n");
-       }
-
-       if (is_overlay)
-       {
-               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
-               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
-       }
-
-       /* Test NULL context */
-       /* XXX: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */
-       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, NULL) == XvMCBadContext);
-       /* Test invalid port */
-       /* XXX: Success and XvBadPort have the same value, if this call actually gets passed the validation step as of now we'll crash later */
-       assert(XvMCCreateContext(display, -1, surface_type_id, width, height, XVMC_DIRECT, &context) == XvBadPort);
-       /* Test invalid surface */
-       assert(XvMCCreateContext(display, port_num, -1, width, height, XVMC_DIRECT, &context) == BadMatch);
-       /* Test invalid flags */
-       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, -1, &context) == BadValue);
-       /* Test huge width */
-       assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, height, XVMC_DIRECT, &context) == BadValue);
-       /* Test huge height */
-       assert(XvMCCreateContext(display, port_num, surface_type_id, width, 16384, XVMC_DIRECT, &context) == BadValue);
-       /* Test huge width & height */
-       assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, 16384, XVMC_DIRECT, &context) == BadValue);
-       /* Test valid params */
-       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
-       /* Test context id assigned */
-       assert(context.context_id != 0);
-       /* Test surface type id assigned and correct */
-       assert(context.surface_type_id == surface_type_id);
-       /* Test width & height assigned and correct */
-       assert(context.width == width && context.height == height);
-       /* Test port assigned and correct */
-       assert(context.port == port_num);
-       /* Test flags assigned and correct */
-       assert(context.flags == XVMC_DIRECT);
-       /* Test NULL context */
-       assert(XvMCDestroyContext(display, NULL) == XvMCBadContext);
-       /* Test valid params */
-       assert(XvMCDestroyContext(display, &context) == Success);
-       /* Test awkward but valid width */
-       assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height, XVMC_DIRECT, &context) == Success);
-       assert(context.width >= width + 1);
-       assert(XvMCDestroyContext(display, &context) == Success);
-       /* Test awkward but valid height */
-       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height + 1, XVMC_DIRECT, &context) == Success);
-       assert(context.height >= height + 1);
-       assert(XvMCDestroyContext(display, &context) == Success);
-       /* Test awkward but valid width & height */
-       assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height + 1, XVMC_DIRECT, &context) == Success);
-       assert(context.width >= width + 1 && context.height >= height + 1);
-       assert(XvMCDestroyContext(display, &context) == Success);
-
-       XvUngrabPort(display, port_num, CurrentTime);
-       XCloseDisplay(display);
-
-       return 0;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/test_rendering.c b/src/gallium/state_trackers/xorg/xvmc/tests/test_rendering.c
deleted file mode 100644 (file)
index 94ac7d4..0000000
+++ /dev/null
@@ -1,327 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- * 
- **************************************************************************/
-
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include <error.h>
-#include "testlib.h"
-
-#define BLOCK_WIDTH                    8
-#define BLOCK_HEIGHT                   8
-#define BLOCK_SIZE                     (BLOCK_WIDTH * BLOCK_HEIGHT)
-#define MACROBLOCK_WIDTH               16
-#define MACROBLOCK_HEIGHT              16
-#define MACROBLOCK_WIDTH_IN_BLOCKS     (MACROBLOCK_WIDTH / BLOCK_WIDTH)
-#define MACROBLOCK_HEIGHT_IN_BLOCKS    (MACROBLOCK_HEIGHT / BLOCK_HEIGHT)
-#define BLOCKS_PER_MACROBLOCK          6
-
-#define INPUT_WIDTH                    64
-#define INPUT_HEIGHT                   64
-#define INPUT_WIDTH_IN_MACROBLOCKS     (INPUT_WIDTH / MACROBLOCK_WIDTH)
-#define INPUT_HEIGHT_IN_MACROBLOCKS    (INPUT_HEIGHT / MACROBLOCK_HEIGHT)
-#define NUM_MACROBLOCKS                        (INPUT_WIDTH_IN_MACROBLOCKS * INPUT_HEIGHT_IN_MACROBLOCKS)
-
-#define DEFAULT_OUTPUT_WIDTH           INPUT_WIDTH
-#define DEFAULT_OUTPUT_HEIGHT          INPUT_HEIGHT
-#define DEFAULT_ACCEPTABLE_ERR         0.01
-
-void ParseArgs(int argc, char **argv, unsigned int *output_width, unsigned int *output_height, double *acceptable_error, int *prompt);
-
-void ParseArgs(int argc, char **argv, unsigned int *output_width, unsigned int *output_height, double *acceptable_error, int *prompt)
-{
-       int fail = 0;
-       int i;
-
-       *output_width = DEFAULT_OUTPUT_WIDTH;
-       *output_height = DEFAULT_OUTPUT_HEIGHT;
-       *acceptable_error = DEFAULT_ACCEPTABLE_ERR;
-       *prompt = 1;
-
-       for (i = 1; i < argc && !fail; ++i)
-       {
-               if (!strcmp(argv[i], "-w"))
-               {
-                       if (sscanf(argv[++i], "%u", output_width) != 1)
-                               fail = 1;
-               }
-               else if (!strcmp(argv[i], "-h"))
-               {
-                       if (sscanf(argv[++i], "%u", output_height) != 1)
-                               fail = 1;
-               }
-               else if (!strcmp(argv[i], "-e"))
-               {
-                       if (sscanf(argv[++i], "%lf", acceptable_error) != 1)
-                               fail = 1;
-               }
-               else if (strcmp(argv[i], "-n"))
-                       *prompt = 0;
-               else
-                       fail = 1;
-       }
-
-       if (fail)
-               error
-               (
-                       1, 0,
-                       "Bad argument.\n"
-                       "\n"
-                       "Usage: %s [options]\n"
-                       "\t-w <width>\tOutput width\n"
-                       "\t-h <height>\tOutput height\n"
-                       "\t-e <error>\tAcceptable margin of error per pixel, from 0 to 1\n"
-                       "\t-n\tDon't prompt for quit\n",
-                       argv[0]
-               );
-}
-
-static void Gradient(short *block, unsigned int start, unsigned int stop, int horizontal, unsigned int intra_unsigned)
-{
-       unsigned int x, y;
-       unsigned int range = stop - start;
-
-       if (horizontal)
-       {
-               for (y = 0; y < BLOCK_HEIGHT; ++y)
-                       for (x = 0; x < BLOCK_WIDTH; ++x) {
-                               *block = (short)(start + range * (x / (float)(BLOCK_WIDTH - 1)));
-                               if (intra_unsigned)
-                                       *block += 1 << 10;
-                               block++;
-                       }
-       }
-       else
-       {
-               for (y = 0; y < BLOCK_HEIGHT; ++y)
-                       for (x = 0; x < BLOCK_WIDTH; ++x) {
-                               *block = (short)(start + range * (y / (float)(BLOCK_WIDTH - 1)));
-                               if (intra_unsigned)
-                                       *block += 1 << 10;
-                               block++;
-                       }
-       }
-}
-
-int main(int argc, char **argv)
-{
-       unsigned int            output_width;
-       unsigned int            output_height;
-       double                  acceptable_error;
-       int                     prompt;
-       Display                 *display;
-       Window                  root, window;
-       const unsigned int      mc_types[] = {XVMC_MOCOMP | XVMC_MPEG_2};
-       XvPortID                port_num;
-       int                     surface_type_id;
-       unsigned int            is_overlay, intra_unsigned;
-       int                     colorkey;
-       XvMCContext             context;
-       XvMCSurface             surface;
-       XvMCBlockArray          block_array;
-       XvMCMacroBlockArray     mb_array;
-       int                     mbx, mby, bx, by;
-       XvMCMacroBlock          *mb;
-       short                   *blocks;
-       int                     quit = 0;
-
-       ParseArgs(argc, argv, &output_width, &output_height, &acceptable_error, &prompt);
-
-       display = XOpenDisplay(NULL);
-
-       if (!GetPort
-       (
-               display,
-               INPUT_WIDTH,
-               INPUT_HEIGHT,
-               XVMC_CHROMA_FORMAT_420,
-               mc_types,
-               sizeof(mc_types)/sizeof(*mc_types),
-               &port_num,
-               &surface_type_id,
-               &is_overlay,
-               &intra_unsigned
-       ))
-       {
-               XCloseDisplay(display);
-               error(1, 0, "Error, unable to find a good port.\n");
-       }
-
-       if (is_overlay)
-       {
-               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
-               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
-       }
-
-       root = XDefaultRootWindow(display);
-       window = XCreateSimpleWindow(display, root, 0, 0, output_width, output_height, 0, 0, colorkey);
-
-       assert(XvMCCreateContext(display, port_num, surface_type_id, INPUT_WIDTH, INPUT_HEIGHT, XVMC_DIRECT, &context) == Success);
-       assert(XvMCCreateSurface(display, &context, &surface) == Success);
-       assert(XvMCCreateBlocks(display, &context, NUM_MACROBLOCKS * BLOCKS_PER_MACROBLOCK, &block_array) == Success);
-       assert(XvMCCreateMacroBlocks(display, &context, NUM_MACROBLOCKS, &mb_array) == Success);
-
-       mb = mb_array.macro_blocks;
-       blocks = block_array.blocks;
-
-       for (mby = 0; mby < INPUT_HEIGHT_IN_MACROBLOCKS; ++mby)
-               for (mbx = 0; mbx < INPUT_WIDTH_IN_MACROBLOCKS; ++mbx)
-               {
-                       mb->x = mbx;
-                       mb->y = mby;
-                       mb->macroblock_type = XVMC_MB_TYPE_INTRA;
-                       /*mb->motion_type = ;*/
-                       /*mb->motion_vertical_field_select = ;*/
-                       mb->dct_type = XVMC_DCT_TYPE_FRAME;
-                       /*mb->PMV[0][0][0] = ;
-                       mb->PMV[0][0][1] = ;
-                       mb->PMV[0][1][0] = ;
-                       mb->PMV[0][1][1] = ;
-                       mb->PMV[1][0][0] = ;
-                       mb->PMV[1][0][1] = ;
-                       mb->PMV[1][1][0] = ;
-                       mb->PMV[1][1][1] = ;*/
-                       mb->index = (mby * INPUT_WIDTH_IN_MACROBLOCKS + mbx) * BLOCKS_PER_MACROBLOCK;
-                       mb->coded_block_pattern = 0x3F;
-
-                       mb++;
-
-                       for (by = 0; by < MACROBLOCK_HEIGHT_IN_BLOCKS; ++by)
-                               for (bx = 0; bx < MACROBLOCK_WIDTH_IN_BLOCKS; ++bx)
-                               {
-                                       const int start = 16, stop = 235, range = stop - start;
-
-                                       Gradient
-                                       (
-                                               blocks,
-                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))),
-                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))),
-                                               1,
-                                               intra_unsigned
-                                       );
-
-                                       blocks += BLOCK_SIZE;
-                               }
-
-                       for (by = 0; by < MACROBLOCK_HEIGHT_IN_BLOCKS / 2; ++by)
-                               for (bx = 0; bx < MACROBLOCK_WIDTH_IN_BLOCKS / 2; ++bx)
-                               {
-                                       const int start = 16, stop = 240, range = stop - start;
-
-                                       Gradient
-                                       (
-                                               blocks,
-                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))),
-                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))),
-                                               1,
-                                               intra_unsigned
-                                       );
-
-                                       blocks += BLOCK_SIZE;
-
-                                       Gradient
-                                       (
-                                               blocks,
-                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))),
-                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))),
-                                               1,
-                                               intra_unsigned
-                                       );
-
-                                       blocks += BLOCK_SIZE;
-                               }
-               }
-
-       XSelectInput(display, window, ExposureMask | KeyPressMask);
-       XMapWindow(display, window);
-       XSync(display, 0);
-
-       /* Test NULL context */
-       assert(XvMCRenderSurface(display, NULL, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == XvMCBadContext);
-       /* Test NULL surface */
-       assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, NULL, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == XvMCBadSurface);
-       /* Test bad picture structure */
-       assert(XvMCRenderSurface(display, &context, 0, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == BadValue);
-       /* Test valid params */
-       assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == Success);
-
-       /* Test NULL surface */
-       assert(XvMCPutSurface(display, NULL, window, 0, 0, INPUT_WIDTH, INPUT_HEIGHT, 0, 0, output_width, output_height, XVMC_FRAME_PICTURE) == XvMCBadSurface);
-       /* Test bad window */
-       /* XXX: X halts with a bad drawable for some reason, doesn't return BadDrawable as expected */
-       /*assert(XvMCPutSurface(display, &surface, 0, 0, 0, width, height, 0, 0, width, height, XVMC_FRAME_PICTURE) == BadDrawable);*/
-
-       if (prompt)
-       {
-               puts("Press any button to quit...");
-
-               while (!quit)
-               {
-                       if (XPending(display) > 0)
-                       {
-                               XEvent event;
-
-                               XNextEvent(display, &event);
-
-                               switch (event.type)
-                               {
-                                       case Expose:
-                                       {
-                                               /* Test valid params */
-                                               assert
-                                               (
-                                                       XvMCPutSurface
-                                                       (
-                                                               display, &surface, window,
-                                                               0, 0, INPUT_WIDTH, INPUT_HEIGHT,
-                                                               0, 0, output_width, output_height,
-                                                               XVMC_FRAME_PICTURE
-                                                       ) == Success
-                                               );
-                                               break;
-                                       }
-                                       case KeyPress:
-                                       {
-                                               quit = 1;
-                                               break;
-                                       }
-                               }
-                       }
-               }
-       }
-
-       assert(XvMCDestroyBlocks(display, &block_array) == Success);
-       assert(XvMCDestroyMacroBlocks(display, &mb_array) == Success);
-       assert(XvMCDestroySurface(display, &surface) == Success);
-       assert(XvMCDestroyContext(display, &context) == Success);
-
-       XvUngrabPort(display, port_num, CurrentTime);
-       XDestroyWindow(display, window);
-       XCloseDisplay(display);
-
-       return 0;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/test_subpicture.c b/src/gallium/state_trackers/xorg/xvmc/tests/test_subpicture.c
deleted file mode 100644 (file)
index 20d0907..0000000
+++ /dev/null
@@ -1,182 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#include <assert.h>
-#include <error.h>
-#include <stdio.h>
-#include "testlib.h"
-
-static void PrintGUID(const char *guid)
-{
-       int i;
-       printf("\tguid: ");
-       for (i = 0; i < 4; ++i)
-               printf("%C,", guid[i] == 0 ? '0' : guid[i]);
-       for (; i < 15; ++i)
-               printf("%x,", (unsigned char)guid[i]);
-       printf("%x\n", (unsigned int)guid[15]);
-}
-
-static void PrintComponentOrder(const char *co)
-{
-       int i;
-       printf("\tcomponent_order:\n\t   ");
-       for (i = 0; i < 4; ++i)
-               printf("%C,", co[i] == 0 ? '0' : co[i]);
-       for (; i < 31; ++i)
-               printf("%x,", (unsigned int)co[i]);
-       printf("%x\n", (unsigned int)co[31]);
-}
-
-int main(int argc, char **argv)
-{
-       const unsigned int      width = 16, height = 16;
-       const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
-       const unsigned int      subpic_width = 16, subpic_height = 16;
-
-       Display                 *display;
-       XvPortID                port_num;
-       int                     surface_type_id;
-       unsigned int            is_overlay, intra_unsigned;
-       int                     colorkey;
-       XvMCContext             context;
-       XvImageFormatValues     *subpics;
-       int                     num_subpics;
-       XvMCSubpicture          subpicture = {0};
-       int                     i;
-
-       display = XOpenDisplay(NULL);
-
-       if (!GetPort
-       (
-               display,
-               width,
-               height,
-               XVMC_CHROMA_FORMAT_420,
-               mc_types,
-               2,
-               &port_num,
-               &surface_type_id,
-               &is_overlay,
-               &intra_unsigned
-       ))
-       {
-               XCloseDisplay(display);
-               error(1, 0, "Error, unable to find a good port.\n");
-       }
-
-       if (is_overlay)
-       {
-               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
-               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
-       }
-
-       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
-       
-       subpics = XvMCListSubpictureTypes(display, port_num, surface_type_id, &num_subpics);
-       assert((subpics && num_subpics) > 0 || (!subpics && num_subpics == 0));
-       
-       for (i = 0; i < num_subpics; ++i)
-       {
-               printf("Subpicture %d:\n", i);
-               printf("\tid: 0x%08x\n", subpics[i].id);
-               printf("\ttype: %s\n", subpics[i].type == XvRGB ? "XvRGB" : (subpics[i].type == XvYUV ? "XvYUV" : "Unknown"));
-               printf("\tbyte_order: %s\n", subpics[i].byte_order == LSBFirst ? "LSB First" : (subpics[i].byte_order == MSBFirst ? "MSB First" : "Unknown"));
-               PrintGUID(subpics[i].guid);
-               printf("\tbpp: %u\n", subpics[i].bits_per_pixel);
-               printf("\tformat: %s\n", subpics[i].format == XvPacked ? "XvPacked" : (subpics[i].format == XvPlanar ? "XvPlanar" : "Unknown"));
-               printf("\tnum_planes: %u\n", subpics[i].num_planes);
-               
-               if (subpics[i].type == XvRGB)
-               {
-                       printf("\tdepth: %u\n", subpics[i].depth);
-                       printf("\tred_mask: 0x%08x\n", subpics[i].red_mask);
-                       printf("\tgreen_mask: 0x%08x\n", subpics[i].green_mask);
-                       printf("\tblue_mask: 0x%08x\n", subpics[i].blue_mask);
-               }
-               else if (subpics[i].type == XvYUV)
-               {
-                       printf("\ty_sample_bits: %u\n", subpics[i].y_sample_bits);
-                       printf("\tu_sample_bits: %u\n", subpics[i].u_sample_bits);
-                       printf("\tv_sample_bits: %u\n", subpics[i].v_sample_bits);
-                       printf("\thorz_y_period: %u\n", subpics[i].horz_y_period);
-                       printf("\thorz_u_period: %u\n", subpics[i].horz_u_period);
-                       printf("\thorz_v_period: %u\n", subpics[i].horz_v_period);
-                       printf("\tvert_y_period: %u\n", subpics[i].vert_y_period);
-                       printf("\tvert_u_period: %u\n", subpics[i].vert_u_period);
-                       printf("\tvert_v_period: %u\n", subpics[i].vert_v_period);
-               }
-               PrintComponentOrder(subpics[i].component_order);
-               printf("\tscanline_order: %s\n", subpics[i].scanline_order == XvTopToBottom ? "XvTopToBottom" : (subpics[i].scanline_order == XvBottomToTop ? "XvBottomToTop" : "Unknown"));
-       }
-       
-       if (num_subpics == 0)
-       {
-               printf("Subpictures not supported, nothing to test.\n");
-               return 0;
-       }
-
-       /* Test NULL context */
-       assert(XvMCCreateSubpicture(display, NULL, &subpicture, subpic_width, subpic_height, subpics[0].id) == XvMCBadContext);
-       /* Test NULL subpicture */
-       assert(XvMCCreateSubpicture(display, &context, NULL, subpic_width, subpic_height, subpics[0].id) == XvMCBadSubpicture);
-       /* Test invalid subpicture */
-       assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, -1) == BadMatch);
-       /* Test huge width */
-       assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, subpic_height, subpics[0].id) == BadValue);
-       /* Test huge height */
-       assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, 16384, subpics[0].id) == BadValue);
-       /* Test huge width & height */
-       assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, 16384, subpics[0].id) == BadValue);
-       for (i = 0; i < num_subpics; ++i)
-       {
-               /* Test valid params */
-               assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, subpics[i].id) == Success);
-               /* Test subpicture id assigned */
-               assert(subpicture.subpicture_id != 0);
-               /* Test context id assigned and correct */
-               assert(subpicture.context_id == context.context_id);
-               /* Test subpicture type id assigned and correct */
-               assert(subpicture.xvimage_id == subpics[i].id);
-               /* Test width & height assigned and correct */
-               assert(subpicture.width == width && subpicture.height == height);
-               /* Test no palette support */
-               assert(subpicture.num_palette_entries == 0 && subpicture.entry_bytes == 0);
-               /* Test valid params */
-               assert(XvMCDestroySubpicture(display, &subpicture) == Success);
-       }
-       /* Test NULL surface */
-       assert(XvMCDestroySubpicture(display, NULL) == XvMCBadSubpicture);
-
-       assert(XvMCDestroyContext(display, &context) == Success);
-
-       XFree(subpics);
-       XvUngrabPort(display, port_num, CurrentTime);
-       XCloseDisplay(display);
-
-       return 0;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/test_surface.c b/src/gallium/state_trackers/xorg/xvmc/tests/test_surface.c
deleted file mode 100644 (file)
index b65eb26..0000000
+++ /dev/null
@@ -1,98 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- * 
- **************************************************************************/
-
-#include <assert.h>
-#include <error.h>
-#include "testlib.h"
-
-int main(int argc, char **argv)
-{
-       const unsigned int      width = 16, height = 16;
-       const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
-
-       Display                 *display;
-       XvPortID                port_num;
-       int                     surface_type_id;
-       unsigned int            is_overlay, intra_unsigned;
-       int                     colorkey;
-       XvMCContext             context;
-       XvMCSurface             surface = {0};
-
-       display = XOpenDisplay(NULL);
-
-       if (!GetPort
-       (
-               display,
-               width,
-               height,
-               XVMC_CHROMA_FORMAT_420,
-               mc_types,
-               2,
-               &port_num,
-               &surface_type_id,
-               &is_overlay,
-               &intra_unsigned
-       ))
-       {
-               XCloseDisplay(display);
-               error(1, 0, "Error, unable to find a good port.\n");
-       }
-
-       if (is_overlay)
-       {
-               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
-               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
-       }
-
-       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
-
-       /* Test NULL context */
-       assert(XvMCCreateSurface(display, NULL, &surface) == XvMCBadContext);
-       /* Test NULL surface */
-       assert(XvMCCreateSurface(display, &context, NULL) == XvMCBadSurface);
-       /* Test valid params */
-       assert(XvMCCreateSurface(display, &context, &surface) == Success);
-       /* Test surface id assigned */
-       assert(surface.surface_id != 0);
-       /* Test context id assigned and correct */
-       assert(surface.context_id == context.context_id);
-       /* Test surface type id assigned and correct */
-       assert(surface.surface_type_id == surface_type_id);
-       /* Test width & height assigned and correct */
-       assert(surface.width == width && surface.height == height);
-       /* Test valid params */
-       assert(XvMCDestroySurface(display, &surface) == Success);
-       /* Test NULL surface */
-       assert(XvMCDestroySurface(display, NULL) == XvMCBadSurface);
-
-       assert(XvMCDestroyContext(display, &context) == Success);
-
-       XvUngrabPort(display, port_num, CurrentTime);
-       XCloseDisplay(display);
-
-       return 0;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/testlib.c b/src/gallium/state_trackers/xorg/xvmc/tests/testlib.c
deleted file mode 100644 (file)
index 142c09b..0000000
+++ /dev/null
@@ -1,146 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- * 
- **************************************************************************/
-
-#include "testlib.h"
-#include <stdio.h>
-
-/*
-void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line)
-{
-       fputs(doc_string, stderr);
-       if (!pred)
-               fprintf(stderr, " FAIL!\n\t\"%s\" at %s:%u\n", pred_string, file, line);
-       else
-               fputs(" PASS!\n", stderr);
-}
-*/
-
-int GetPort
-(
-       Display *display,
-       unsigned int width,
-       unsigned int height,
-       unsigned int chroma_format,
-       const unsigned int *mc_types,
-       unsigned int num_mc_types,
-       XvPortID *port_id,
-       int *surface_type_id,
-       unsigned int *is_overlay,
-       unsigned int *intra_unsigned
-)
-{
-       unsigned int    found_port = 0;
-       XvAdaptorInfo   *adaptor_info;
-       unsigned int    num_adaptors;
-       int             num_types;
-       int             ev_base, err_base;
-       unsigned int    i, j, k, l;
-
-       if (!XvMCQueryExtension(display, &ev_base, &err_base))
-               return 0;
-       if (XvQueryAdaptors(display, XDefaultRootWindow(display), &num_adaptors, &adaptor_info) != Success)
-               return 0;
-
-       for (i = 0; i < num_adaptors && !found_port; ++i)
-       {
-               if (adaptor_info[i].type & XvImageMask)
-               {
-                       XvMCSurfaceInfo *surface_info = XvMCListSurfaceTypes(display, adaptor_info[i].base_id, &num_types);
-
-                       if (surface_info)
-                       {
-                               for (j = 0; j < num_types && !found_port; ++j)
-                               {
-                                       if
-                                       (
-                                               surface_info[j].chroma_format == chroma_format &&
-                                               surface_info[j].max_width >= width &&
-                                               surface_info[j].max_height >= height
-                                       )
-                                       {
-                                               for (k = 0; k < num_mc_types && !found_port; ++k)
-                                               {
-                                                       if (surface_info[j].mc_type == mc_types[k])
-                                                       {
-                                                               for (l = 0; l < adaptor_info[i].num_ports && !found_port; ++l)
-                                                               {
-                                                                       if (XvGrabPort(display, adaptor_info[i].base_id + l, CurrentTime) == Success)
-                                                                       {
-                                                                               *port_id = adaptor_info[i].base_id + l;
-                                                                               *surface_type_id = surface_info[j].surface_type_id;
-                                                                               *is_overlay = surface_info[j].flags & XVMC_OVERLAID_SURFACE;
-                                                                               *intra_unsigned = surface_info[j].flags & XVMC_INTRA_UNSIGNED;
-                                                                               found_port = 1;
-                                                                       }
-                                                               }
-                                                       }
-                                               }
-                                       }
-                               }
-
-                               XFree(surface_info);
-                       }
-               }
-       }
-
-       XvFreeAdaptorInfo(adaptor_info);
-
-       return found_port;
-}
-
-unsigned int align(unsigned int value, unsigned int alignment)
-{
-       return (value + alignment - 1) & ~(alignment - 1);
-}
-
-/* From the glibc manual */
-int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
-{
-       /* Perform the carry for the later subtraction by updating y. */
-       if (x->tv_usec < y->tv_usec)
-       {
-               int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
-               y->tv_usec -= 1000000 * nsec;
-               y->tv_sec += nsec;
-       }
-       if (x->tv_usec - y->tv_usec > 1000000)
-       {
-               int nsec = (x->tv_usec - y->tv_usec) / 1000000;
-               y->tv_usec += 1000000 * nsec;
-               y->tv_sec -= nsec;
-       }
-
-       /*
-        * Compute the time remaining to wait.
-        * tv_usec is certainly positive.
-        */
-       result->tv_sec = x->tv_sec - y->tv_sec;
-       result->tv_usec = x->tv_usec - y->tv_usec;
-
-       /* Return 1 if result is negative. */
-       return x->tv_sec < y->tv_sec;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/testlib.h b/src/gallium/state_trackers/xorg/xvmc/tests/testlib.h
deleted file mode 100644 (file)
index 0438e52..0000000
+++ /dev/null
@@ -1,69 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- * 
- **************************************************************************/
-
-#ifndef testlib_h
-#define testlib_h
-
-/*
-#define TEST(pred, doc)        test(pred, #pred, doc, __FILE__, __LINE__)
-
-void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line);
-*/
-
-#include <sys/time.h>
-#include <X11/Xlib.h>
-#include <X11/extensions/XvMClib.h>
-
-/*
- * display: IN                 A valid X display
- * width, height: IN           Surface size that the port must display
- * chroma_format: IN           Chroma format that the port must display
- * mc_types, num_mc_types: IN  List of MC types that the port must support, first port that matches the first mc_type will be returned
- * port_id: OUT                        Your port's ID
- * surface_type_id: OUT                Your port's surface ID
- * is_overlay: OUT             If 1, port uses overlay surfaces, you need to set a colorkey
- * intra_unsigned: OUT         If 1, port uses unsigned values for intra-coded blocks
- */
-int GetPort
-(
-       Display *display,
-       unsigned int width,
-       unsigned int height,
-       unsigned int chroma_format,
-       const unsigned int *mc_types,
-       unsigned int num_mc_types,
-       XvPortID *port_id,
-       int *surface_type_id,
-       unsigned int *is_overlay,
-       unsigned int *intra_unsigned
-);
-
-unsigned int align(unsigned int value, unsigned int alignment);
-
-int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y);
-
-#endif
diff --git a/src/gallium/state_trackers/xorg/xvmc/tests/xvmc_bench.c b/src/gallium/state_trackers/xorg/xvmc/tests/xvmc_bench.c
deleted file mode 100644 (file)
index bf94d85..0000000
+++ /dev/null
@@ -1,300 +0,0 @@
-/**************************************************************************
- * 
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- * 
- **************************************************************************/
-
-#include <assert.h>
-#include <stdio.h>
-#include <string.h>
-#include <error.h>
-#include <sys/time.h>
-#include "testlib.h"
-
-#define MACROBLOCK_WIDTH               16
-#define MACROBLOCK_HEIGHT              16
-#define BLOCKS_PER_MACROBLOCK          6
-
-#define DEFAULT_INPUT_WIDTH            720
-#define DEFAULT_INPUT_HEIGHT           480
-#define DEFAULT_REPS                   100
-
-#define PIPELINE_STEP_MC               1
-#define PIPELINE_STEP_CSC              2
-#define PIPELINE_STEP_SWAP             4
-
-#define MB_TYPE_I                      1
-#define MB_TYPE_P                      2
-#define MB_TYPE_B                      4
-
-struct Config
-{
-       unsigned int input_width;
-       unsigned int input_height;
-       unsigned int output_width;
-       unsigned int output_height;
-       unsigned int pipeline;
-       unsigned int mb_types;
-       unsigned int reps;
-};
-
-void ParseArgs(int argc, char **argv, struct Config *config);
-
-void ParseArgs(int argc, char **argv, struct Config *config)
-{
-       int fail = 0;
-       int i;
-
-       config->input_width = DEFAULT_INPUT_WIDTH;
-       config->input_height = DEFAULT_INPUT_HEIGHT;
-       config->output_width = 0;
-       config->output_height = 0;
-       config->pipeline = 0;
-       config->mb_types = 0;
-       config->reps = DEFAULT_REPS;
-
-       for (i = 1; i < argc && !fail; ++i)
-       {
-               if (!strcmp(argv[i], "-iw"))
-               {
-                       if (sscanf(argv[++i], "%u", &config->input_width) != 1)
-                               fail = 1;
-               }
-               else if (!strcmp(argv[i], "-ih"))
-               {
-                       if (sscanf(argv[++i], "%u", &config->input_height) != 1)
-                               fail = 1;
-               }
-               else if (!strcmp(argv[i], "-ow"))
-               {
-                       if (sscanf(argv[++i], "%u", &config->output_width) != 1)
-                               fail = 1;
-               }
-               else if (!strcmp(argv[i], "-oh"))
-               {
-                       if (sscanf(argv[++i], "%u", &config->output_height) != 1)
-                               fail = 1;
-               }
-               else if (!strcmp(argv[i], "-p"))
-               {
-                       char *token = strtok(argv[++i], ",");
-
-                       while (token && !fail)
-                       {
-                               if (!strcmp(token, "mc"))
-                                       config->pipeline |= PIPELINE_STEP_MC;
-                               else if (!strcmp(token, "csc"))
-                                       config->pipeline |= PIPELINE_STEP_CSC;
-                               else if (!strcmp(token, "swp"))
-                                       config->pipeline |= PIPELINE_STEP_SWAP;
-                               else
-                                       fail = 1;
-
-                               if (!fail)
-                                       token = strtok(NULL, ",");
-                       }
-               }
-               else if (!strcmp(argv[i], "-mb"))
-               {
-                       char *token = strtok(argv[++i], ",");
-
-                       while (token && !fail)
-                       {
-                               if (strcmp(token, "i"))
-                                       config->mb_types |= MB_TYPE_I;
-                               else if (strcmp(token, "p"))
-                                       config->mb_types |= MB_TYPE_P;
-                               else if (strcmp(token, "b"))
-                                       config->mb_types |= MB_TYPE_B;
-                               else
-                                       fail = 1;
-
-                               if (!fail)
-                                       token = strtok(NULL, ",");
-                       }
-               }
-               else if (!strcmp(argv[i], "-r"))
-               {
-                       if (sscanf(argv[++i], "%u", &config->reps) != 1)
-                               fail = 1;
-               }
-               else
-                       fail = 1;
-       }
-
-       if (fail)
-               error
-               (
-                       1, 0,
-                       "Bad argument.\n"
-                       "\n"
-                       "Usage: %s [options]\n"
-                       "\t-iw <width>\tInput width\n"
-                       "\t-ih <height>\tInput height\n"
-                       "\t-ow <width>\tOutput width\n"
-                       "\t-oh <height>\tOutput height\n"
-                       "\t-p <pipeline>\tPipeline to test\n"
-                       "\t-mb <mb type>\tMacroBlock types to use\n"
-                       "\t-r <reps>\tRepetitions\n\n"
-                       "\tPipeline steps: mc,csc,swap\n"
-                       "\tMB types: i,p,b\n",
-                       argv[0]
-               );
-
-       if (config->output_width == 0)
-               config->output_width = config->input_width;
-       if (config->output_height == 0)
-               config->output_height = config->input_height;
-       if (!config->pipeline)
-               config->pipeline = PIPELINE_STEP_MC | PIPELINE_STEP_CSC | PIPELINE_STEP_SWAP;
-       if (!config->mb_types)
-               config->mb_types = MB_TYPE_I | MB_TYPE_P | MB_TYPE_B;
-}
-
-int main(int argc, char **argv)
-{
-       struct Config           config;
-       Display                 *display;
-       Window                  root, window;
-       const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
-       XvPortID                port_num;
-       int                     surface_type_id;
-       unsigned int            is_overlay, intra_unsigned;
-       int                     colorkey;
-       XvMCContext             context;
-       XvMCSurface             surface;
-       XvMCBlockArray          block_array;
-       XvMCMacroBlockArray     mb_array;
-       unsigned int            mbw, mbh;
-       unsigned int            mbx, mby;
-       unsigned int            reps;
-       struct timeval          start, stop, diff;
-       double                  diff_secs;
-
-       ParseArgs(argc, argv, &config);
-
-       mbw = align(config.input_width, MACROBLOCK_WIDTH) / MACROBLOCK_WIDTH;
-       mbh = align(config.input_height, MACROBLOCK_HEIGHT) / MACROBLOCK_HEIGHT;
-
-       display = XOpenDisplay(NULL);
-
-       if (!GetPort
-       (
-               display,
-               config.input_width,
-               config.input_height,
-               XVMC_CHROMA_FORMAT_420,
-               mc_types,
-               2,
-               &port_num,
-               &surface_type_id,
-               &is_overlay,
-               &intra_unsigned
-       ))
-       {
-               XCloseDisplay(display);
-               error(1, 0, "Error, unable to find a good port.\n");
-       }
-
-       if (is_overlay)
-       {
-               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
-               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
-       }
-
-       root = XDefaultRootWindow(display);
-       window = XCreateSimpleWindow(display, root, 0, 0, config.output_width, config.output_height, 0, 0, colorkey);
-
-       assert(XvMCCreateContext(display, port_num, surface_type_id, config.input_width, config.input_height, XVMC_DIRECT, &context) == Success);
-       assert(XvMCCreateSurface(display, &context, &surface) == Success);
-       assert(XvMCCreateBlocks(display, &context, mbw * mbh * BLOCKS_PER_MACROBLOCK, &block_array) == Success);
-       assert(XvMCCreateMacroBlocks(display, &context, mbw * mbh, &mb_array) == Success);
-
-       for (mby = 0; mby < mbh; ++mby)
-               for (mbx = 0; mbx < mbw; ++mbx)
-               {
-                       mb_array.macro_blocks[mby * mbw + mbx].x = mbx;
-                       mb_array.macro_blocks[mby * mbw + mbx].y = mby;
-                       mb_array.macro_blocks[mby * mbw + mbx].macroblock_type = XVMC_MB_TYPE_INTRA;
-                       /*mb->motion_type = ;*/
-                       /*mb->motion_vertical_field_select = ;*/
-                       mb_array.macro_blocks[mby * mbw + mbx].dct_type = XVMC_DCT_TYPE_FRAME;
-                       /*mb->PMV[0][0][0] = ;
-                       mb->PMV[0][0][1] = ;
-                       mb->PMV[0][1][0] = ;
-                       mb->PMV[0][1][1] = ;
-                       mb->PMV[1][0][0] = ;
-                       mb->PMV[1][0][1] = ;
-                       mb->PMV[1][1][0] = ;
-                       mb->PMV[1][1][1] = ;*/
-                       mb_array.macro_blocks[mby * mbw + mbx].index = (mby * mbw + mbx) * BLOCKS_PER_MACROBLOCK;
-                       mb_array.macro_blocks[mby * mbw + mbx].coded_block_pattern = 0x3F;
-               }
-
-       XSelectInput(display, window, ExposureMask | KeyPressMask);
-       XMapWindow(display, window);
-       XSync(display, 0);
-
-       gettimeofday(&start, NULL);
-
-       for (reps = 0; reps < config.reps; ++reps)
-       {
-               if (config.pipeline & PIPELINE_STEP_MC)
-               {
-                       assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, mbw * mbh, 0, &mb_array, &block_array) == Success);
-                       assert(XvMCFlushSurface(display, &surface) == Success);
-               }
-               if (config.pipeline & PIPELINE_STEP_CSC)
-                       assert(XvMCPutSurface(display, &surface, window, 0, 0, config.input_width, config.input_height, 0, 0, config.output_width, config.output_height, XVMC_FRAME_PICTURE) == Success);
-       }
-
-       gettimeofday(&stop, NULL);
-
-       timeval_subtract(&diff, &stop, &start);
-       diff_secs = (double)diff.tv_sec + (double)diff.tv_usec / 1000000.0;
-
-       printf("XvMC Benchmark\n");
-       printf("Input: %u,%u\nOutput: %u,%u\n", config.input_width, config.input_height, config.output_width, config.output_height);
-       printf("Pipeline: ");
-       if (config.pipeline & PIPELINE_STEP_MC)
-               printf("|mc|");
-       if (config.pipeline & PIPELINE_STEP_CSC)
-               printf("|csc|");
-       if (config.pipeline & PIPELINE_STEP_SWAP)
-               printf("|swap|");
-       printf("\n");
-       printf("Reps: %u\n", config.reps);
-       printf("Total time: %.2lf (%.2lf reps / sec)\n", diff_secs, config.reps / diff_secs);
-
-       assert(XvMCDestroyBlocks(display, &block_array) == Success);
-       assert(XvMCDestroyMacroBlocks(display, &mb_array) == Success);
-       assert(XvMCDestroySurface(display, &surface) == Success);
-       assert(XvMCDestroyContext(display, &context) == Success);
-
-       XvUngrabPort(display, port_num, CurrentTime);
-       XDestroyWindow(display, window);
-       XCloseDisplay(display);
-
-       return 0;
-}
diff --git a/src/gallium/state_trackers/xorg/xvmc/xvmc_private.h b/src/gallium/state_trackers/xorg/xvmc/xvmc_private.h
deleted file mode 100644 (file)
index b9519a7..0000000
+++ /dev/null
@@ -1,129 +0,0 @@
-/**************************************************************************
- *
- * Copyright 2009 Younes Manton.
- * 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 TUNGSTEN GRAPHICS 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.
- *
- **************************************************************************/
-
-#ifndef xvmc_private_h
-#define xvmc_private_h
-
-#include <X11/Xlib.h>
-#include <X11/extensions/XvMClib.h>
-
-#include "pipe/p_video_state.h"
-
-#include "util/u_debug.h"
-#include "util/u_math.h"
-#include "util/u_rect.h"
-
-#include "vl/vl_csc.h"
-#include "vl/vl_compositor.h"
-
-#define BLOCK_SIZE_SAMPLES 64
-#define BLOCK_SIZE_BYTES (BLOCK_SIZE_SAMPLES * 2)
-
-struct pipe_video_decoder;
-struct pipe_video_buffer;
-
-struct pipe_sampler_view;
-struct pipe_fence_handle;
-
-typedef struct
-{
-   struct vl_screen *vscreen;
-   struct pipe_context *pipe;
-   struct pipe_video_decoder *decoder;
-
-   enum VL_CSC_COLOR_STANDARD color_standard;
-   struct vl_procamp procamp;
-   struct vl_compositor compositor;
-
-   unsigned short subpicture_max_width;
-   unsigned short subpicture_max_height;
-
-   struct pipe_video_rect dst_rect;
-   struct pipe_surface *drawable_surface;
-   struct u_rect dirty_area;
-
-} XvMCContextPrivate;
-
-typedef struct
-{
-   struct pipe_video_buffer *video_buffer;
-
-   /* nonzero if this picture is already being decoded */
-   int picture_structure;
-
-   XvMCSurface *ref[2];
-
-   struct pipe_fence_handle *fence;
-
-   /* The subpicture associated with this surface, if any. */
-   XvMCSubpicture *subpicture;
-
-   /* Some XvMC functions take a surface but not a context,
-      so we keep track of which context each surface belongs to. */
-   XvMCContext *context;
-} XvMCSurfacePrivate;
-
-typedef struct
-{
-   struct pipe_sampler_view *sampler;
-
-   /* optional palette for this subpicture */
-   struct pipe_sampler_view *palette;
-
-   struct pipe_video_rect src_rect;
-   struct pipe_video_rect dst_rect;
-
-   /* The surface this subpicture is currently associated with, if any. */
-   XvMCSurface *surface;
-
-   /* Some XvMC functions take a subpicture but not a context,
-      so we keep track of which context each subpicture belongs to. */
-   XvMCContext *context;
-} XvMCSubpicturePrivate;
-
-#define XVMC_OUT   0
-#define XVMC_ERR   1
-#define XVMC_WARN  2
-#define XVMC_TRACE 3
-
-static INLINE void XVMC_MSG(unsigned int level, const char *fmt, ...)
-{
-   static int debug_level = -1;
-
-   if (debug_level == -1) {
-      debug_level = MAX2(debug_get_num_option("XVMC_DEBUG", 0), 0);
-   }
-
-   if (level <= debug_level) {
-      va_list ap;
-      va_start(ap, fmt);
-      _debug_vprintf(fmt, ap);
-      va_end(ap);
-   }
-}
-
-#endif /* xvmc_private_h */
diff --git a/src/gallium/state_trackers/xvmc/Makefile b/src/gallium/state_trackers/xvmc/Makefile
new file mode 100644 (file)
index 0000000..179446f
--- /dev/null
@@ -0,0 +1,16 @@
+TOP = ../../../..
+include $(TOP)/configs/current
+
+LIBNAME = xvmctracker
+
+LIBRARY_INCLUDES = \
+       $(shell $(PKG_CONFIG) --cflags-only-I xvmc) \
+       -I$(TOP)/src/gallium/winsys/g3dvl
+
+C_SOURCES = block.c \
+            surface.c \
+            context.c \
+            subpicture.c \
+            attributes.c
+
+include ../../Makefile.template
diff --git a/src/gallium/state_trackers/xvmc/attributes.c b/src/gallium/state_trackers/xvmc/attributes.c
new file mode 100644 (file)
index 0000000..d40a7b1
--- /dev/null
@@ -0,0 +1,153 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+#include <stdlib.h>
+
+#include <X11/Xlib.h>
+#include <X11/extensions/Xvlib.h>
+#include <X11/extensions/XvMClib.h>
+
+#include "vl/vl_compositor.h"
+
+#include "xvmc_private.h"
+
+#define XV_BRIGHTNESS "XV_BRIGHTNESS"
+#define XV_CONTRAST   "XV_CONTRAST"
+#define XV_SATURATION "XV_SATURATION"
+#define XV_HUE        "XV_HUE"
+#define XV_COLORSPACE "XV_COLORSPACE"
+
+static const XvAttribute attributes[] = {
+   { XvGettable | XvSettable, -1000, 1000, XV_BRIGHTNESS },
+   { XvGettable | XvSettable, -1000, 1000, XV_CONTRAST },
+   { XvGettable | XvSettable, -1000, 1000, XV_SATURATION },
+   { XvGettable | XvSettable, -1000, 1000, XV_HUE },
+   { XvGettable | XvSettable, 0, 1, XV_COLORSPACE }
+};
+
+PUBLIC
+XvAttribute* XvMCQueryAttributes(Display *dpy, XvMCContext *context, int *number)
+{
+   XvAttribute *result;
+
+   assert(dpy && number);
+
+   if (!context || !context->privData)
+      return NULL;
+
+   result = malloc(sizeof(attributes));
+   if (!result)
+      return NULL;
+
+   memcpy(result, attributes, sizeof(attributes));
+   *number = sizeof(attributes) / sizeof(XvAttribute);
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Returning %d attributes for context %p.\n", *number, context);
+
+   return result;
+}
+
+PUBLIC
+Status XvMCSetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int value)
+{
+   XvMCContextPrivate *context_priv;
+   const char *attr;
+   float csc[16];
+
+   assert(dpy);
+
+   if (!context || !context->privData)
+      return XvMCBadContext;
+
+   context_priv = context->privData;
+
+   attr = XGetAtomName(dpy, attribute);
+   if (!attr)
+      return XvMCBadContext;
+
+   if (strcmp(attr, XV_BRIGHTNESS))
+      context_priv->procamp.brightness = value / 1000.0f;
+   else if (strcmp(attr, XV_CONTRAST))
+      context_priv->procamp.contrast = value / 1000.0f + 1.0f;
+   else if (strcmp(attr, XV_SATURATION))
+      context_priv->procamp.saturation = value / 1000.0f + 1.0f;
+   else if (strcmp(attr, XV_HUE))
+      context_priv->procamp.hue = value / 1000.0f;
+   else if (strcmp(attr, XV_COLORSPACE))
+      context_priv->color_standard = value ?
+         VL_CSC_COLOR_STANDARD_BT_601 :
+         VL_CSC_COLOR_STANDARD_BT_709;
+   else
+      return BadName;
+
+   vl_csc_get_matrix
+   (
+      context_priv->color_standard,
+      &context_priv->procamp, true, csc
+   );
+   vl_compositor_set_csc_matrix(&context_priv->compositor, csc);
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Set attribute %s to value %d.\n", attr, value);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCGetAttribute(Display *dpy, XvMCContext *context, Atom attribute, int *value)
+{
+   XvMCContextPrivate *context_priv;
+   const char *attr;
+
+   assert(dpy);
+
+   if (!context || !context->privData)
+      return XvMCBadContext;
+
+   context_priv = context->privData;
+
+   attr = XGetAtomName(dpy, attribute);
+   if (!attr)
+      return XvMCBadContext;
+
+   if (strcmp(attr, XV_BRIGHTNESS))
+      *value = context_priv->procamp.brightness * 1000;
+   else if (strcmp(attr, XV_CONTRAST))
+      *value = context_priv->procamp.contrast * 1000 - 1000;
+   else if (strcmp(attr, XV_SATURATION))
+      *value = context_priv->procamp.saturation * 1000 + 1000;
+   else if (strcmp(attr, XV_HUE))
+      *value = context_priv->procamp.hue * 1000;
+   else if (strcmp(attr, XV_COLORSPACE))
+      *value = context_priv->color_standard == VL_CSC_COLOR_STANDARD_BT_709;
+   else
+      return BadName;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Got value %d for attribute %s.\n", *value, attr);
+
+   return Success;
+}
diff --git a/src/gallium/state_trackers/xvmc/block.c b/src/gallium/state_trackers/xvmc/block.c
new file mode 100644 (file)
index 0000000..64f8497
--- /dev/null
@@ -0,0 +1,95 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+
+#include <X11/Xlib.h>
+#include <X11/extensions/XvMClib.h>
+
+#include "util/u_memory.h"
+
+#include "xvmc_private.h"
+
+PUBLIC
+Status XvMCCreateBlocks(Display *dpy, XvMCContext *context, unsigned int num_blocks, XvMCBlockArray *blocks)
+{
+   assert(dpy);
+
+   if (!context)
+      return XvMCBadContext;
+   if (num_blocks == 0)
+      return BadValue;
+
+   assert(blocks);
+
+   blocks->context_id = context->context_id;
+   blocks->num_blocks = num_blocks;
+   blocks->blocks = MALLOC(BLOCK_SIZE_BYTES * num_blocks);
+   blocks->privData = NULL;
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCDestroyBlocks(Display *dpy, XvMCBlockArray *blocks)
+{
+   assert(dpy);
+   assert(blocks);
+   FREE(blocks->blocks);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCCreateMacroBlocks(Display *dpy, XvMCContext *context, unsigned int num_blocks, XvMCMacroBlockArray *blocks)
+{
+   assert(dpy);
+
+   if (!context)
+      return XvMCBadContext;
+   if (num_blocks == 0)
+      return BadValue;
+
+   assert(blocks);
+
+   blocks->context_id = context->context_id;
+   blocks->num_blocks = num_blocks;
+   blocks->macro_blocks = MALLOC(sizeof(XvMCMacroBlock) * num_blocks);
+   blocks->privData = NULL;
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCDestroyMacroBlocks(Display *dpy, XvMCMacroBlockArray *blocks)
+{
+   assert(dpy);
+   assert(blocks);
+   FREE(blocks->macro_blocks);
+
+   return Success;
+}
diff --git a/src/gallium/state_trackers/xvmc/context.c b/src/gallium/state_trackers/xvmc/context.c
new file mode 100644 (file)
index 0000000..e9ba06b
--- /dev/null
@@ -0,0 +1,329 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+
+#include <X11/Xlibint.h>
+#include <X11/extensions/XvMClib.h>
+
+#include "pipe/p_screen.h"
+#include "pipe/p_video_decoder.h"
+#include "pipe/p_video_state.h"
+#include "pipe/p_state.h"
+
+#include "util/u_memory.h"
+
+#include "vl/vl_csc.h"
+#include "vl_winsys.h"
+
+#include "xvmc_private.h"
+
+static Status Validate(Display *dpy, XvPortID port, int surface_type_id,
+                       unsigned int width, unsigned int height, int flags,
+                       bool *found_port, int *screen, int *chroma_format,
+                       int *mc_type, int *surface_flags,
+                       unsigned short *subpic_max_w,
+                       unsigned short *subpic_max_h)
+{
+   bool found_surface = false;
+   XvAdaptorInfo *adaptor_info;
+   unsigned int num_adaptors;
+   int num_types;
+   unsigned int max_width = 0, max_height = 0;
+   Status ret;
+
+   assert(dpy);
+   assert(found_port);
+   assert(screen);
+   assert(chroma_format);
+   assert(mc_type);
+   assert(surface_flags);
+   assert(subpic_max_w);
+   assert(subpic_max_h);
+
+   *found_port = false;
+
+   for (unsigned int i = 0; i < XScreenCount(dpy); ++i) {
+      ret = XvQueryAdaptors(dpy, XRootWindow(dpy, i), &num_adaptors, &adaptor_info);
+      if (ret != Success)
+         return ret;
+
+      for (unsigned int j = 0; j < num_adaptors && !*found_port; ++j) {
+         for (unsigned int k = 0; k < adaptor_info[j].num_ports && !*found_port; ++k) {
+            XvMCSurfaceInfo *surface_info;
+
+            if (adaptor_info[j].base_id + k != port)
+               continue;
+
+            *found_port = true;
+
+            surface_info = XvMCListSurfaceTypes(dpy, adaptor_info[j].base_id, &num_types);
+            if (!surface_info) {
+               XvFreeAdaptorInfo(adaptor_info);
+               return BadAlloc;
+            }
+
+            for (unsigned int l = 0; l < num_types && !found_surface; ++l) {
+               if (surface_info[l].surface_type_id != surface_type_id)
+                  continue;
+
+               found_surface = true;
+               max_width = surface_info[l].max_width;
+               max_height = surface_info[l].max_height;
+               *chroma_format = surface_info[l].chroma_format;
+               *mc_type = surface_info[l].mc_type;
+               *surface_flags = surface_info[l].flags;
+               *subpic_max_w = surface_info[l].subpicture_max_width;
+               *subpic_max_h = surface_info[l].subpicture_max_height;
+               *screen = i;
+
+               XVMC_MSG(XVMC_TRACE, "[XvMC] Found requested context surface format.\n" \
+                                    "[XvMC]   screen=%u, port=%u\n" \
+                                    "[XvMC]   id=0x%08X\n" \
+                                    "[XvMC]   max width=%u, max height=%u\n" \
+                                    "[XvMC]   chroma format=0x%08X\n" \
+                                    "[XvMC]   acceleration level=0x%08X\n" \
+                                    "[XvMC]   flags=0x%08X\n" \
+                                    "[XvMC]   subpicture max width=%u, max height=%u\n",
+                                    i, port, surface_type_id, max_width, max_height, *chroma_format,
+                                    *mc_type, *surface_flags, *subpic_max_w, *subpic_max_h);
+            }
+
+            XFree(surface_info);
+         }
+      }
+
+      XvFreeAdaptorInfo(adaptor_info);
+   }
+
+   if (!*found_port) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Could not find a suitable port.\n");
+      return XvBadPort;
+   }
+   if (!found_surface) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Could not find a suitable surface.\n");
+      return BadMatch;
+   }
+   if (width > max_width || height > max_height) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Requested context dimensions (w=%u,h=%u) too large (max w=%u,h=%u).\n",
+               width, height, max_width, max_height);
+      return BadValue;
+   }
+   if (flags != XVMC_DIRECT && flags != 0) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Invalid context flags 0x%08X.\n", flags);
+      return BadValue;
+   }
+
+   return Success;
+}
+
+static enum pipe_video_profile ProfileToPipe(int xvmc_profile)
+{
+   if (xvmc_profile & XVMC_MPEG_1)
+      assert(0);
+   if (xvmc_profile & XVMC_MPEG_2)
+      return PIPE_VIDEO_PROFILE_MPEG2_MAIN;
+   if (xvmc_profile & XVMC_H263)
+      assert(0);
+   if (xvmc_profile & XVMC_MPEG_4)
+      assert(0);
+
+   assert(0);
+
+   XVMC_MSG(XVMC_ERR, "[XvMC] Unrecognized profile 0x%08X.\n", xvmc_profile);
+
+   return -1;
+}
+
+static enum pipe_video_chroma_format FormatToPipe(int xvmc_format)
+{
+   switch (xvmc_format) {
+      case XVMC_CHROMA_FORMAT_420:
+         return PIPE_VIDEO_CHROMA_FORMAT_420;
+      case XVMC_CHROMA_FORMAT_422:
+         return PIPE_VIDEO_CHROMA_FORMAT_422;
+      case XVMC_CHROMA_FORMAT_444:
+         return PIPE_VIDEO_CHROMA_FORMAT_444;
+      default:
+         assert(0);
+   }
+
+   XVMC_MSG(XVMC_ERR, "[XvMC] Unrecognized format 0x%08X.\n", xvmc_format);
+
+   return -1;
+}
+
+PUBLIC
+Status XvMCCreateContext(Display *dpy, XvPortID port, int surface_type_id,
+                         int width, int height, int flags, XvMCContext *context)
+{
+   bool found_port;
+   int scrn = 0;
+   int chroma_format = 0;
+   int mc_type = 0;
+   int surface_flags = 0;
+   unsigned short subpic_max_w = 0;
+   unsigned short subpic_max_h = 0;
+   Status ret;
+   struct vl_screen *vscreen;
+   struct pipe_context *pipe;
+   XvMCContextPrivate *context_priv;
+   float csc[16];
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Creating context %p.\n", context);
+
+   assert(dpy);
+
+   if (!context)
+      return XvMCBadContext;
+
+   ret = Validate(dpy, port, surface_type_id, width, height, flags,
+                  &found_port, &scrn, &chroma_format, &mc_type, &surface_flags,
+                  &subpic_max_w, &subpic_max_h);
+
+   /* Success and XvBadPort have the same value */
+   if (ret != Success || !found_port)
+      return ret;
+
+   /* XXX: Current limits */
+   if (chroma_format != XVMC_CHROMA_FORMAT_420) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Cannot decode requested surface type. Unsupported chroma format.\n");
+      return BadImplementation;
+   }
+   if ((mc_type & ~XVMC_IDCT) != (XVMC_MOCOMP | XVMC_MPEG_2)) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Cannot decode requested surface type. Non-MPEG2/Mocomp/iDCT acceleration unsupported.\n");
+      return BadImplementation;
+   }
+   if (surface_flags & XVMC_INTRA_UNSIGNED) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Cannot decode requested surface type. Unsigned intra unsupported.\n");
+      return BadImplementation;
+   }
+
+   context_priv = CALLOC(1, sizeof(XvMCContextPrivate));
+   if (!context_priv)
+      return BadAlloc;
+
+   /* TODO: Reuse screen if process creates another context */
+   vscreen = vl_screen_create(dpy, scrn);
+
+   if (!vscreen) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL screen.\n");
+      FREE(context_priv);
+      return BadAlloc;
+   }
+
+   pipe = vscreen->pscreen->context_create(vscreen->pscreen, vscreen);
+   if (!pipe) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL context.\n");
+      vl_screen_destroy(vscreen);
+      FREE(context_priv);
+      return BadAlloc;
+   }
+
+   context_priv->decoder = pipe->create_video_decoder
+   (
+      pipe, ProfileToPipe(mc_type),
+      (mc_type & XVMC_IDCT) ? PIPE_VIDEO_ENTRYPOINT_IDCT : PIPE_VIDEO_ENTRYPOINT_MC,
+      FormatToPipe(chroma_format),
+      width, height, 2,
+      true
+   );
+
+   if (!context_priv->decoder) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL decoder.\n");
+      pipe->destroy(pipe);
+      vl_screen_destroy(vscreen);
+      FREE(context_priv);
+      return BadAlloc;
+   }
+
+   if (!vl_compositor_init(&context_priv->compositor, pipe)) {
+      XVMC_MSG(XVMC_ERR, "[XvMC] Could not create VL compositor.\n");
+      context_priv->decoder->destroy(context_priv->decoder);
+      pipe->destroy(pipe);
+      vl_screen_destroy(vscreen);
+      FREE(context_priv);
+      return BadAlloc;
+   }
+
+   context_priv->color_standard =
+      debug_get_bool_option("G3DVL_NO_CSC", FALSE) ?
+      VL_CSC_COLOR_STANDARD_IDENTITY : VL_CSC_COLOR_STANDARD_BT_601;
+   context_priv->procamp = vl_default_procamp;
+
+   vl_csc_get_matrix
+   (
+      context_priv->color_standard,
+      &context_priv->procamp, true, csc
+   );
+   vl_compositor_set_csc_matrix(&context_priv->compositor, csc);
+
+   context_priv->vscreen = vscreen;
+   context_priv->pipe = pipe;
+   context_priv->subpicture_max_width = subpic_max_w;
+   context_priv->subpicture_max_height = subpic_max_h;
+
+   context->context_id = XAllocID(dpy);
+   context->surface_type_id = surface_type_id;
+   context->width = width;
+   context->height = height;
+   context->flags = flags;
+   context->port = port;
+   context->privData = context_priv;
+
+   SyncHandle();
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Context %p created.\n", context);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCDestroyContext(Display *dpy, XvMCContext *context)
+{
+   XvMCContextPrivate *context_priv;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Destroying context %p.\n", context);
+
+   assert(dpy);
+
+   if (!context || !context->privData)
+      return XvMCBadContext;
+
+   context_priv = context->privData;
+   pipe_surface_reference(&context_priv->drawable_surface, NULL);
+   context_priv->decoder->destroy(context_priv->decoder);
+   vl_compositor_cleanup(&context_priv->compositor);
+   context_priv->pipe->destroy(context_priv->pipe);
+   vl_screen_destroy(context_priv->vscreen);
+   FREE(context_priv);
+   context->privData = NULL;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Context %p destroyed.\n", context);
+
+   return Success;
+}
diff --git a/src/gallium/state_trackers/xvmc/subpicture.c b/src/gallium/state_trackers/xvmc/subpicture.c
new file mode 100644 (file)
index 0000000..6b1b091
--- /dev/null
@@ -0,0 +1,534 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+
+#include <X11/Xlibint.h>
+#include <X11/extensions/XvMClib.h>
+
+#include "pipe/p_screen.h"
+#include "pipe/p_video_decoder.h"
+#include "pipe/p_state.h"
+
+#include "util/u_memory.h"
+#include "util/u_math.h"
+#include "util/u_format.h"
+#include "util/u_sampler.h"
+#include "util/u_rect.h"
+
+#include "vl_winsys.h"
+
+#include "xvmc_private.h"
+
+#define FOURCC_RGB 0x0000003
+#define FOURCC_AI44 0x34344941
+#define FOURCC_IA44 0x34344149
+
+static enum pipe_format XvIDToPipe(int xvimage_id)
+{
+   switch (xvimage_id) {
+      case FOURCC_RGB:
+         return PIPE_FORMAT_B8G8R8X8_UNORM;
+
+      case FOURCC_AI44:
+         return PIPE_FORMAT_A4R4_UNORM;
+
+      case FOURCC_IA44:
+         return PIPE_FORMAT_R4A4_UNORM;
+
+      default:
+         XVMC_MSG(XVMC_ERR, "[XvMC] Unrecognized Xv image ID 0x%08X.\n", xvimage_id);
+         return PIPE_FORMAT_NONE;
+   }
+}
+
+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:
+         return 0;
+
+      case PIPE_FORMAT_R4A4_UNORM:
+      case PIPE_FORMAT_A4R4_UNORM:
+         component_order[0] = 'Y';
+         component_order[1] = 'U';
+         component_order[2] = 'V';
+         component_order[3] = 'A';
+         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;
+   }
+}
+
+static Status Validate(Display *dpy, XvPortID port, int surface_type_id, int xvimage_id)
+{
+   XvImageFormatValues *subpictures;
+   int num_subpics;
+   unsigned int i;
+
+   subpictures = XvMCListSubpictureTypes(dpy, port, surface_type_id, &num_subpics);
+   if (num_subpics < 1) {
+      if (subpictures)
+         XFree(subpictures);
+      return BadMatch;
+   }
+   if (!subpictures)
+      return BadAlloc;
+
+   for (i = 0; i < num_subpics; ++i) {
+      if (subpictures[i].id == xvimage_id) {
+         XVMC_MSG(XVMC_TRACE, "[XvMC] Found requested subpicture format.\n" \
+                              "[XvMC]   port=%u\n" \
+                              "[XvMC]   surface id=0x%08X\n" \
+                              "[XvMC]   image id=0x%08X\n" \
+                              "[XvMC]   type=%08X\n" \
+                              "[XvMC]   byte order=%08X\n" \
+                              "[XvMC]   bits per pixel=%u\n" \
+                              "[XvMC]   format=%08X\n" \
+                              "[XvMC]   num planes=%d\n",
+                              port, surface_type_id, xvimage_id, subpictures[i].type, subpictures[i].byte_order,
+                              subpictures[i].bits_per_pixel, subpictures[i].format, subpictures[i].num_planes);
+         if (subpictures[i].type == XvRGB) {
+            XVMC_MSG(XVMC_TRACE, "[XvMC]   depth=%d\n" \
+                                 "[XvMC]   red mask=0x%08X\n" \
+                                 "[XvMC]   green mask=0x%08X\n" \
+                                 "[XvMC]   blue mask=0x%08X\n",
+                                 subpictures[i].depth, subpictures[i].red_mask,
+                                 subpictures[i].green_mask, subpictures[i].blue_mask);
+         }
+         else if (subpictures[i].type == XvYUV) {
+            XVMC_MSG(XVMC_TRACE, "[XvMC]   y sample bits=0x%08X\n" \
+                                 "[XvMC]   u sample bits=0x%08X\n" \
+                                 "[XvMC]   v sample bits=0x%08X\n" \
+                                 "[XvMC]   horz y period=%u\n" \
+                                 "[XvMC]   horz u period=%u\n" \
+                                 "[XvMC]   horz v period=%u\n" \
+                                 "[XvMC]   vert y period=%u\n" \
+                                 "[XvMC]   vert u period=%u\n" \
+                                 "[XvMC]   vert v period=%u\n",
+                                 subpictures[i].y_sample_bits, subpictures[i].u_sample_bits, subpictures[i].v_sample_bits,
+                                 subpictures[i].horz_y_period, subpictures[i].horz_u_period, subpictures[i].horz_v_period,
+                                 subpictures[i].vert_y_period, subpictures[i].vert_u_period, subpictures[i].vert_v_period);
+         }
+         break;
+      }
+   }
+
+   XFree(subpictures);
+
+   return i < num_subpics ? Success : BadMatch;
+}
+
+static void
+upload_sampler(struct pipe_context *pipe, struct pipe_sampler_view *dst,
+               const struct pipe_box *dst_box, const void *src, unsigned src_stride,
+               unsigned src_x, unsigned src_y)
+{
+   struct pipe_transfer *transfer;
+   void *map;
+
+   transfer = pipe->get_transfer(pipe, dst->texture, 0, PIPE_TRANSFER_WRITE, dst_box);
+   if (!transfer)
+      return;
+
+   map = pipe->transfer_map(pipe, transfer);
+   if (map) {
+      util_copy_rect(map, dst->texture->format, transfer->stride, 0, 0,
+                     dst_box->width, dst_box->height,
+                     src, src_stride, src_x, src_y);
+
+      pipe->transfer_unmap(pipe, transfer);
+   }
+
+   pipe->transfer_destroy(pipe, transfer);
+}
+
+PUBLIC
+Status XvMCCreateSubpicture(Display *dpy, XvMCContext *context, XvMCSubpicture *subpicture,
+                            unsigned short width, unsigned short height, int xvimage_id)
+{
+   XvMCContextPrivate *context_priv;
+   XvMCSubpicturePrivate *subpicture_priv;
+   struct pipe_context *pipe;
+   struct pipe_resource tex_templ, *tex;
+   struct pipe_sampler_view sampler_templ;
+   Status ret;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Creating subpicture %p.\n", subpicture);
+
+   assert(dpy);
+
+   if (!context)
+      return XvMCBadContext;
+
+   context_priv = context->privData;
+   pipe = context_priv->pipe;
+
+   if (!subpicture)
+      return XvMCBadSubpicture;
+
+   if (width > context_priv->subpicture_max_width ||
+       height > context_priv->subpicture_max_height)
+      return BadValue;
+
+   ret = Validate(dpy, context->port, context->surface_type_id, xvimage_id);
+   if (ret != Success)
+      return ret;
+
+   subpicture_priv = CALLOC(1, sizeof(XvMCSubpicturePrivate));
+   if (!subpicture_priv)
+      return BadAlloc;
+
+   memset(&tex_templ, 0, sizeof(tex_templ));
+   tex_templ.target = PIPE_TEXTURE_2D;
+   tex_templ.format = XvIDToPipe(xvimage_id);
+   tex_templ.last_level = 0;
+   if (pipe->screen->get_video_param(pipe->screen,
+                                     PIPE_VIDEO_PROFILE_UNKNOWN,
+                                     PIPE_VIDEO_CAP_NPOT_TEXTURES)) {
+      tex_templ.width0 = width;
+      tex_templ.height0 = height;
+   }
+   else {
+      tex_templ.width0 = util_next_power_of_two(width);
+      tex_templ.height0 = util_next_power_of_two(height);
+   }
+   tex_templ.depth0 = 1;
+   tex_templ.array_size = 1;
+   tex_templ.usage = PIPE_USAGE_DYNAMIC;
+   tex_templ.bind = PIPE_BIND_SAMPLER_VIEW;
+   tex_templ.flags = 0;
+
+   tex = pipe->screen->resource_create(pipe->screen, &tex_templ);
+
+   memset(&sampler_templ, 0, sizeof(sampler_templ));
+   u_sampler_view_default_template(&sampler_templ, tex, tex->format);
+
+   subpicture_priv->sampler = pipe->create_sampler_view(pipe, tex, &sampler_templ);
+   pipe_resource_reference(&tex, NULL);
+   if (!subpicture_priv->sampler) {
+      FREE(subpicture_priv);
+      return BadAlloc;
+   }
+
+   subpicture_priv->context = context;
+   subpicture->subpicture_id = XAllocID(dpy);
+   subpicture->context_id = context->context_id;
+   subpicture->xvimage_id = xvimage_id;
+   subpicture->width = width;
+   subpicture->height = height;
+   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_R8G8B8X8_UNORM;
+      tex_templ.width0 = subpicture->num_palette_entries;
+      tex_templ.height0 = 1;
+      tex_templ.usage = PIPE_USAGE_STATIC;
+
+      tex = pipe->screen->resource_create(pipe->screen, &tex_templ);
+
+      memset(&sampler_templ, 0, sizeof(sampler_templ));
+      u_sampler_view_default_template(&sampler_templ, tex, tex->format);
+      sampler_templ.swizzle_a = PIPE_SWIZZLE_ONE;
+      subpicture_priv->palette = pipe->create_sampler_view(pipe, 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);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCClearSubpicture(Display *dpy, XvMCSubpicture *subpicture, short x, short y,
+                           unsigned short width, unsigned short height, unsigned int color)
+{
+   XvMCSubpicturePrivate *subpicture_priv;
+   XvMCContextPrivate *context_priv;
+   struct pipe_context *pipe;
+   struct pipe_sampler_view *dst;
+   struct pipe_box dst_box = {x, y, 0, width, height, 1};
+   struct pipe_transfer *transfer;
+   union util_color uc;
+   void *map;
+
+   assert(dpy);
+
+   if (!subpicture)
+      return XvMCBadSubpicture;
+
+   /* Convert color to float */
+   util_format_read_4f(PIPE_FORMAT_B8G8R8A8_UNORM,
+                       uc.f, 1, &color, 4,
+                       0, 0, 1, 1);
+
+   subpicture_priv = subpicture->privData;
+   context_priv = subpicture_priv->context->privData;
+   pipe = context_priv->pipe;
+   dst = subpicture_priv->sampler;
+
+   /* TODO: Assert clear rect is within bounds? Or clip? */
+   transfer = pipe->get_transfer(pipe, dst->texture, 0, PIPE_TRANSFER_WRITE, &dst_box);
+   if (!transfer)
+      return XvMCBadSubpicture;
+
+   map = pipe->transfer_map(pipe, transfer);
+   if (map) {
+      util_fill_rect(map, dst->texture->format, transfer->stride, 0, 0,
+                     dst_box.width, dst_box.height, &uc);
+
+      pipe->transfer_unmap(pipe, transfer);
+   }
+
+   pipe->transfer_destroy(pipe, transfer);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCCompositeSubpicture(Display *dpy, XvMCSubpicture *subpicture, XvImage *image,
+                               short srcx, short srcy, unsigned short width, unsigned short height,
+                               short dstx, short dsty)
+{
+   XvMCSubpicturePrivate *subpicture_priv;
+   XvMCContextPrivate *context_priv;
+   struct pipe_context *pipe;
+   struct pipe_box dst_box = {dstx, dsty, 0, width, height, 1};
+   unsigned src_stride;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Compositing subpicture %p.\n", subpicture);
+
+   assert(dpy);
+
+   if (!subpicture)
+      return XvMCBadSubpicture;
+
+   assert(image);
+
+   if (subpicture->xvimage_id != image->id)
+      return BadMatch;
+
+   /* No planar support for now */
+   if (image->num_planes != 1)
+      return BadMatch;
+
+   subpicture_priv = subpicture->privData;
+   context_priv = subpicture_priv->context->privData;
+   pipe = context_priv->pipe;
+
+   /* clipping should be done by upload_sampler and regardles what the documentation
+   says image->pitches[0] doesn't seems to be in bytes, so don't use it */
+   src_stride = image->width * util_format_get_blocksize(subpicture_priv->sampler->texture->format);
+   upload_sampler(pipe, subpicture_priv->sampler, &dst_box, image->data, src_stride, srcx, srcy);
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Subpicture %p composited.\n", subpicture);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCDestroySubpicture(Display *dpy, XvMCSubpicture *subpicture)
+{
+   XvMCSubpicturePrivate *subpicture_priv;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Destroying subpicture %p.\n", subpicture);
+
+   assert(dpy);
+
+   if (!subpicture)
+      return XvMCBadSubpicture;
+
+   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);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCSetSubpicturePalette(Display *dpy, XvMCSubpicture *subpicture, unsigned char *palette)
+{
+   XvMCSubpicturePrivate *subpicture_priv;
+   XvMCContextPrivate *context_priv;
+   struct pipe_context *pipe;
+   struct pipe_box dst_box = {0, 0, 0, 0, 1, 1};
+
+   assert(dpy);
+   assert(palette);
+
+   if (!subpicture)
+      return XvMCBadSubpicture;
+
+   subpicture_priv = subpicture->privData;
+   context_priv = subpicture_priv->context->privData;
+   pipe = context_priv->pipe;
+
+   dst_box.width = subpicture->num_palette_entries;
+
+   upload_sampler(pipe, subpicture_priv->palette, &dst_box, palette, 0, 0, 0);
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Palette of Subpicture %p set.\n", subpicture);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCBlendSubpicture(Display *dpy, XvMCSurface *target_surface, XvMCSubpicture *subpicture,
+                           short subx, short suby, unsigned short subw, unsigned short subh,
+                           short surfx, short surfy, unsigned short surfw, unsigned short surfh)
+{
+   struct pipe_video_rect src_rect = {subx, suby, subw, subh};
+   struct pipe_video_rect dst_rect = {surfx, surfy, surfw, surfh};
+
+   XvMCSurfacePrivate *surface_priv;
+   XvMCSubpicturePrivate *subpicture_priv;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Associating subpicture %p with surface %p.\n", subpicture, target_surface);
+
+   assert(dpy);
+
+   if (!target_surface)
+      return XvMCBadSurface;
+
+   if (!subpicture)
+      return XvMCBadSubpicture;
+
+   if (target_surface->context_id != subpicture->context_id)
+      return BadMatch;
+
+   /* TODO: Verify against subpicture independent scaling */
+
+   surface_priv = target_surface->privData;
+   subpicture_priv = subpicture->privData;
+
+   /* TODO: Assert rects are within bounds? Or clip? */
+   subpicture_priv->src_rect = src_rect;
+   subpicture_priv->dst_rect = dst_rect;
+
+   surface_priv->subpicture = subpicture;
+   subpicture_priv->surface = target_surface;
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCBlendSubpicture2(Display *dpy, XvMCSurface *source_surface, XvMCSurface *target_surface,
+                            XvMCSubpicture *subpicture, short subx, short suby, unsigned short subw, unsigned short subh,
+                            short surfx, short surfy, unsigned short surfw, unsigned short surfh)
+{
+   assert(dpy);
+
+   if (!source_surface || !target_surface)
+      return XvMCBadSurface;
+
+   if (!subpicture)
+      return XvMCBadSubpicture;
+
+   if (source_surface->context_id != subpicture->context_id)
+      return BadMatch;
+
+   if (source_surface->context_id != subpicture->context_id)
+      return BadMatch;
+
+   /* TODO: Assert rects are within bounds? Or clip? */
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCSyncSubpicture(Display *dpy, XvMCSubpicture *subpicture)
+{
+   assert(dpy);
+
+   if (!subpicture)
+      return XvMCBadSubpicture;
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCFlushSubpicture(Display *dpy, XvMCSubpicture *subpicture)
+{
+   assert(dpy);
+
+   if (!subpicture)
+      return XvMCBadSubpicture;
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCGetSubpictureStatus(Display *dpy, XvMCSubpicture *subpicture, int *status)
+{
+   assert(dpy);
+
+   if (!subpicture)
+      return XvMCBadSubpicture;
+
+   assert(status);
+
+   /* TODO */
+   *status = 0;
+
+   return Success;
+}
diff --git a/src/gallium/state_trackers/xvmc/surface.c b/src/gallium/state_trackers/xvmc/surface.c
new file mode 100644 (file)
index 0000000..834841c
--- /dev/null
@@ -0,0 +1,537 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+
+#include <X11/Xlibint.h>
+
+#include "pipe/p_video_decoder.h"
+#include "pipe/p_video_state.h"
+#include "pipe/p_state.h"
+
+#include "util/u_inlines.h"
+#include "util/u_memory.h"
+#include "util/u_math.h"
+
+#include "vl_winsys.h"
+
+#include "xvmc_private.h"
+
+static void
+MacroBlocksToPipe(XvMCContextPrivate *context,
+                  XvMCSurfacePrivate *surface,
+                  unsigned int xvmc_picture_structure,
+                  const XvMCMacroBlock *xvmc_mb,
+                  const XvMCBlockArray *xvmc_blocks,
+                  struct pipe_mpeg12_macroblock *mb,
+                  unsigned int num_macroblocks)
+{
+   unsigned int i, j, k;
+
+   assert(xvmc_mb);
+   assert(xvmc_blocks);
+   assert(num_macroblocks);
+
+   for (; num_macroblocks > 0; --num_macroblocks) {
+      mb->base.codec = PIPE_VIDEO_CODEC_MPEG12;
+      mb->x = xvmc_mb->x;
+      mb->y = xvmc_mb->y;
+      mb->macroblock_type = xvmc_mb->macroblock_type;
+
+      switch (xvmc_picture_structure) {
+      case XVMC_FRAME_PICTURE:
+         mb->macroblock_modes.bits.frame_motion_type = xvmc_mb->motion_type;
+         mb->macroblock_modes.bits.field_motion_type = 0;
+         break;
+
+      case XVMC_TOP_FIELD:
+      case XVMC_BOTTOM_FIELD:
+         mb->macroblock_modes.bits.frame_motion_type = 0;
+         mb->macroblock_modes.bits.field_motion_type = xvmc_mb->motion_type;
+         break;
+
+      default:
+         assert(0);
+      }
+
+      mb->macroblock_modes.bits.dct_type = xvmc_mb->dct_type;
+      mb->motion_vertical_field_select = xvmc_mb->motion_vertical_field_select;
+
+      for (i = 0; i < 2; ++i)
+         for (j = 0; j < 2; ++j)
+            for (k = 0; k < 2; ++k)
+               mb->PMV[i][j][k] = xvmc_mb->PMV[i][j][k];
+
+      mb->coded_block_pattern = xvmc_mb->coded_block_pattern;
+      mb->blocks = xvmc_blocks->blocks + xvmc_mb->index * BLOCK_SIZE_SAMPLES;
+      mb->num_skipped_macroblocks = 0;
+
+      ++xvmc_mb;
+      ++mb;
+   }
+}
+
+static void
+GetPictureDescription(XvMCSurfacePrivate *surface, struct pipe_mpeg12_picture_desc *desc)
+{
+   unsigned i, num_refs = 0;
+
+   assert(surface && desc);
+
+   memset(desc, 0, sizeof(*desc));
+   desc->base.profile = PIPE_VIDEO_PROFILE_MPEG1;
+   desc->picture_structure = surface->picture_structure;
+   for (i = 0; i < 2; ++i) {
+      if (surface->ref[i]) {
+         XvMCSurfacePrivate *ref = surface->ref[i]->privData;
+
+         if (ref)
+            desc->ref[num_refs++] = ref->video_buffer;
+      }
+   }
+}
+
+static void
+RecursiveEndFrame(XvMCSurfacePrivate *surface)
+{
+   XvMCContextPrivate *context_priv;
+   unsigned i;
+
+   assert(surface);
+
+   context_priv = surface->context->privData;
+
+   for ( i = 0; i < 2; ++i ) {
+      if (surface->ref[i]) {
+         XvMCSurface *ref = surface->ref[i];
+
+         assert(ref);
+
+         surface->ref[i] = NULL;
+         RecursiveEndFrame(ref->privData);
+         surface->ref[i] = ref;
+      }
+   }
+
+   if (surface->picture_structure) {
+      struct pipe_mpeg12_picture_desc desc;
+      GetPictureDescription(surface, &desc);
+      surface->picture_structure = 0;
+
+      for (i = 0; i < 2; ++i)
+         surface->ref[i] = NULL;
+
+      context_priv->decoder->end_frame(context_priv->decoder, surface->video_buffer, &desc.base);
+   }
+}
+
+PUBLIC
+Status XvMCCreateSurface(Display *dpy, XvMCContext *context, XvMCSurface *surface)
+{
+   XvMCContextPrivate *context_priv;
+   struct pipe_context *pipe;
+   XvMCSurfacePrivate *surface_priv;
+   struct pipe_video_buffer tmpl;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Creating surface %p.\n", surface);
+
+   assert(dpy);
+
+   if (!context)
+      return XvMCBadContext;
+   if (!surface)
+      return XvMCBadSurface;
+
+   context_priv = context->privData;
+   pipe = context_priv->pipe;
+
+   surface_priv = CALLOC(1, sizeof(XvMCSurfacePrivate));
+   if (!surface_priv)
+      return BadAlloc;
+
+   memset(&tmpl, 0, sizeof(tmpl));
+   tmpl.buffer_format = pipe->screen->get_video_param
+   (
+      pipe->screen,
+      PIPE_VIDEO_PROFILE_MPEG2_MAIN,
+      PIPE_VIDEO_CAP_PREFERED_FORMAT
+   );
+   tmpl.chroma_format = context_priv->decoder->chroma_format;
+   tmpl.width = context_priv->decoder->width;
+   tmpl.height = context_priv->decoder->height;
+   tmpl.interlaced = pipe->screen->get_video_param
+   (
+      pipe->screen,
+      PIPE_VIDEO_PROFILE_MPEG2_MAIN,
+      PIPE_VIDEO_CAP_PREFERS_INTERLACED
+   );
+
+   surface_priv->video_buffer = pipe->create_video_buffer(pipe, &tmpl);
+   surface_priv->context = context;
+
+   surface->surface_id = XAllocID(dpy);
+   surface->context_id = context->context_id;
+   surface->surface_type_id = context->surface_type_id;
+   surface->width = context->width;
+   surface->height = context->height;
+   surface->privData = surface_priv;
+
+   SyncHandle();
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Surface %p created.\n", surface);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCRenderSurface(Display *dpy, XvMCContext *context, unsigned int picture_structure,
+                         XvMCSurface *target_surface, XvMCSurface *past_surface, XvMCSurface *future_surface,
+                         unsigned int flags, unsigned int num_macroblocks, unsigned int first_macroblock,
+                         XvMCMacroBlockArray *macroblocks, XvMCBlockArray *blocks
+)
+{
+   struct pipe_mpeg12_macroblock mb[num_macroblocks];
+   struct pipe_video_decoder *decoder;
+   struct pipe_mpeg12_picture_desc desc;
+
+   XvMCContextPrivate *context_priv;
+   XvMCSurfacePrivate *target_surface_priv;
+   XvMCSurfacePrivate *past_surface_priv;
+   XvMCSurfacePrivate *future_surface_priv;
+   XvMCMacroBlock *xvmc_mb;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Rendering to surface %p, with past %p and future %p\n",
+            target_surface, past_surface, future_surface);
+
+   assert(dpy);
+
+   if (!context || !context->privData)
+      return XvMCBadContext;
+   if (!target_surface || !target_surface->privData)
+      return XvMCBadSurface;
+
+   if (picture_structure != XVMC_TOP_FIELD &&
+       picture_structure != XVMC_BOTTOM_FIELD &&
+       picture_structure != XVMC_FRAME_PICTURE)
+      return BadValue;
+   /* Bkwd pred equivalent to fwd (past && !future) */
+   if (future_surface && !past_surface)
+      return BadMatch;
+
+   assert(context->context_id == target_surface->context_id);
+   assert(!past_surface || context->context_id == past_surface->context_id);
+   assert(!future_surface || context->context_id == future_surface->context_id);
+
+   assert(macroblocks);
+   assert(blocks);
+
+   assert(macroblocks->context_id == context->context_id);
+   assert(blocks->context_id == context->context_id);
+
+   assert(flags == 0 || flags == XVMC_SECOND_FIELD);
+
+   context_priv = context->privData;
+   decoder = context_priv->decoder;
+
+   target_surface_priv = target_surface->privData;
+   past_surface_priv = past_surface ? past_surface->privData : NULL;
+   future_surface_priv = future_surface ? future_surface->privData : NULL;
+
+   assert(target_surface_priv->context == context);
+   assert(!past_surface || past_surface_priv->context == context);
+   assert(!future_surface || future_surface_priv->context == context);
+
+   // call end frame on all referenced frames
+   if (past_surface)
+      RecursiveEndFrame(past_surface->privData);
+
+   if (future_surface)
+      RecursiveEndFrame(future_surface->privData);
+
+   xvmc_mb = macroblocks->macro_blocks + first_macroblock;
+
+   /* If the surface we're rendering hasn't changed the ref frames shouldn't change. */
+   if (target_surface_priv->picture_structure > 0 && (
+       target_surface_priv->picture_structure != picture_structure ||
+       target_surface_priv->ref[0] != past_surface ||
+       target_surface_priv->ref[1] != future_surface ||
+       (xvmc_mb->x == 0 && xvmc_mb->y == 0))) {
+
+      // If they change anyway we must assume that the current frame is ended
+      RecursiveEndFrame(target_surface_priv);
+   }
+
+   target_surface_priv->ref[0] = past_surface;
+   target_surface_priv->ref[1] = future_surface;
+
+   if (target_surface_priv->picture_structure)
+      GetPictureDescription(target_surface_priv, &desc);
+   else {
+      target_surface_priv->picture_structure = picture_structure;
+      GetPictureDescription(target_surface_priv, &desc);
+      decoder->begin_frame(decoder, target_surface_priv->video_buffer, &desc.base);
+   }
+
+   MacroBlocksToPipe(context_priv, target_surface_priv, picture_structure,
+                     xvmc_mb, blocks, mb, num_macroblocks);
+
+   context_priv->decoder->decode_macroblock(context_priv->decoder,
+                                            target_surface_priv->video_buffer,
+                                            &desc.base,
+                                            &mb[0].base, num_macroblocks);
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Submitted surface %p for rendering.\n", target_surface);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCFlushSurface(Display *dpy, XvMCSurface *surface)
+{
+   assert(dpy);
+
+   if (!surface)
+      return XvMCBadSurface;
+
+   // don't call flush here, because this is usually
+   // called once for every slice instead of every frame
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Flushing surface %p\n", surface);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCSyncSurface(Display *dpy, XvMCSurface *surface)
+{
+   assert(dpy);
+
+   if (!surface)
+      return XvMCBadSurface;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Syncing surface %p\n", surface);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCPutSurface(Display *dpy, XvMCSurface *surface, Drawable drawable,
+                      short srcx, short srcy, unsigned short srcw, unsigned short srch,
+                      short destx, short desty, unsigned short destw, unsigned short desth,
+                      int flags)
+{
+   static int dump_window = -1;
+
+   struct pipe_context *pipe;
+   struct vl_compositor *compositor;
+
+   XvMCSurfacePrivate *surface_priv;
+   XvMCContextPrivate *context_priv;
+   XvMCSubpicturePrivate *subpicture_priv;
+   XvMCContext *context;
+   struct pipe_video_rect src_rect = {srcx, srcy, srcw, srch};
+   struct pipe_video_rect dst_rect = {destx, desty, destw, desth};
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Displaying surface %p.\n", surface);
+
+   assert(dpy);
+
+   if (!surface || !surface->privData)
+      return XvMCBadSurface;
+
+   surface_priv = surface->privData;
+   context = surface_priv->context;
+   context_priv = context->privData;
+
+   assert(flags == XVMC_TOP_FIELD || flags == XVMC_BOTTOM_FIELD || flags == XVMC_FRAME_PICTURE);
+   assert(srcx + srcw - 1 < surface->width);
+   assert(srcy + srch - 1 < surface->height);
+
+   subpicture_priv = surface_priv->subpicture ? surface_priv->subpicture->privData : NULL;
+   pipe = context_priv->pipe;
+   compositor = &context_priv->compositor;
+
+   if (!context_priv->drawable_surface ||
+       context_priv->dst_rect.x != dst_rect.x || context_priv->dst_rect.y != dst_rect.y ||
+       context_priv->dst_rect.w != dst_rect.w || context_priv->dst_rect.h != dst_rect.h) {
+
+      struct pipe_surface surf_templ;
+      struct pipe_resource *tex = vl_screen_texture_from_drawable(
+         context_priv->vscreen, drawable);
+
+      pipe_surface_reference(&context_priv->drawable_surface, NULL);
+
+      memset(&surf_templ, 0, sizeof(surf_templ));
+      surf_templ.format = tex->format;
+      surf_templ.usage = PIPE_BIND_RENDER_TARGET;
+      context_priv->drawable_surface = pipe->create_surface(pipe, tex, &surf_templ);
+      vl_compositor_reset_dirty_area(&context_priv->dirty_area);
+      context_priv->dst_rect = dst_rect;
+   }
+
+   if (!context_priv->drawable_surface)
+      return BadDrawable;
+
+   /*
+    * Some apps (mplayer) hit these asserts because they call
+    * this function after the window has been resized by the WM
+    * but before they've handled the corresponding XEvent and
+    * know about the new dimensions. The output should be clipped
+    * until the app updates destw and desth.
+    */
+   /*
+   assert(destx + destw - 1 < drawable_surface->width);
+   assert(desty + desth - 1 < drawable_surface->height);
+    */
+
+   RecursiveEndFrame(surface_priv);
+
+   context_priv->decoder->flush(context_priv->decoder);
+
+   vl_compositor_clear_layers(compositor);
+   vl_compositor_set_buffer_layer(compositor, 0, surface_priv->video_buffer,
+                                  &src_rect, NULL, VL_COMPOSITOR_WEAVE);
+
+   if (subpicture_priv) {
+      XVMC_MSG(XVMC_TRACE, "[XvMC] Surface %p has subpicture %p.\n", surface, surface_priv->subpicture);
+
+      assert(subpicture_priv->surface == surface);
+
+      if (subpicture_priv->palette)
+         vl_compositor_set_palette_layer(compositor, 1, subpicture_priv->sampler, subpicture_priv->palette,
+                                         &subpicture_priv->src_rect, &subpicture_priv->dst_rect, true);
+      else
+         vl_compositor_set_rgba_layer(compositor, 1, subpicture_priv->sampler,
+                                      &subpicture_priv->src_rect, &subpicture_priv->dst_rect);
+
+      surface_priv->subpicture = NULL;
+      subpicture_priv->surface = NULL;
+   }
+
+   // Workaround for r600g, there seems to be a bug in the fence refcounting code
+   pipe->screen->fence_reference(pipe->screen, &surface_priv->fence, NULL);
+
+   vl_compositor_render(compositor, context_priv->drawable_surface, &dst_rect, NULL, &context_priv->dirty_area);
+
+   pipe->flush(pipe, &surface_priv->fence);
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Submitted surface %p for display. Pushing to front buffer.\n", surface);
+
+   pipe->screen->flush_frontbuffer
+   (
+      pipe->screen, context_priv->drawable_surface->texture, 0, 0,
+      vl_screen_get_private(context_priv->vscreen)
+   );
+
+   if(dump_window == -1) {
+      dump_window = debug_get_num_option("XVMC_DUMP", 0);
+   }
+
+   if(dump_window) {
+      static unsigned int framenum = 0;
+      char cmd[256];
+
+      sprintf(cmd, "xwd -id %d -out xvmc_frame_%08d.xwd", (int)drawable, ++framenum);
+      if (system(cmd) != 0)
+         XVMC_MSG(XVMC_ERR, "[XvMC] Dumping surface %p failed.\n", surface);
+   }
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Pushed surface %p to front buffer.\n", surface);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCGetSurfaceStatus(Display *dpy, XvMCSurface *surface, int *status)
+{
+   struct pipe_context *pipe;
+   XvMCSurfacePrivate *surface_priv;
+   XvMCContextPrivate *context_priv;
+
+   assert(dpy);
+
+   if (!surface)
+      return XvMCBadSurface;
+
+   assert(status);
+
+   surface_priv = surface->privData;
+   context_priv = surface_priv->context->privData;
+   pipe = context_priv->pipe;
+
+   *status = 0;
+
+   if (surface_priv->fence)
+      if (!pipe->screen->fence_signalled(pipe->screen, surface_priv->fence))
+         *status |= XVMC_RENDERING;
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCDestroySurface(Display *dpy, XvMCSurface *surface)
+{
+   XvMCSurfacePrivate *surface_priv;
+   XvMCContextPrivate *context_priv;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Destroying surface %p.\n", surface);
+
+   assert(dpy);
+
+   if (!surface || !surface->privData)
+      return XvMCBadSurface;
+
+   surface_priv = surface->privData;
+   context_priv = surface_priv->context->privData;
+
+   if (surface_priv->picture_structure) {
+      struct pipe_mpeg12_picture_desc desc;
+      GetPictureDescription(surface_priv, &desc);
+      context_priv->decoder->end_frame(context_priv->decoder, surface_priv->video_buffer, &desc.base);
+   }
+   surface_priv->video_buffer->destroy(surface_priv->video_buffer);
+   FREE(surface_priv);
+   surface->privData = NULL;
+
+   XVMC_MSG(XVMC_TRACE, "[XvMC] Surface %p destroyed.\n", surface);
+
+   return Success;
+}
+
+PUBLIC
+Status XvMCHideSurface(Display *dpy, XvMCSurface *surface)
+{
+   assert(dpy);
+
+   if (!surface || !surface->privData)
+      return XvMCBadSurface;
+
+   /* No op, only for overlaid rendering */
+
+   return Success;
+}
diff --git a/src/gallium/state_trackers/xvmc/tests/.gitignore b/src/gallium/state_trackers/xvmc/tests/.gitignore
new file mode 100644 (file)
index 0000000..9a8e05d
--- /dev/null
@@ -0,0 +1,6 @@
+test_context
+test_surface
+test_subpicture
+test_blocks
+test_rendering
+xvmc_bench
diff --git a/src/gallium/state_trackers/xvmc/tests/Makefile b/src/gallium/state_trackers/xvmc/tests/Makefile
new file mode 100644 (file)
index 0000000..fa19045
--- /dev/null
@@ -0,0 +1,31 @@
+TOP = ../../../../..
+include $(TOP)/configs/current
+
+LIBS = -lXvMCW -lXvMC -lXv -lX11
+
+#############################################
+
+.PHONY: default clean
+
+default: test_context test_surface test_subpicture test_blocks test_rendering xvmc_bench
+
+test_context: test_context.o testlib.o
+       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+test_surface: test_surface.o testlib.o
+       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+test_subpicture: test_subpicture.o testlib.o
+       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+test_blocks: test_blocks.o testlib.o
+       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+test_rendering: test_rendering.o testlib.o
+       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+xvmc_bench: xvmc_bench.o testlib.o
+       $(CC) $(LDFLAGS) -o $@ $^ $(LIBS)
+
+clean:
+       $(RM) -rf *.o test_context test_surface test_subpicture test_blocks test_rendering xvmc_bench
diff --git a/src/gallium/state_trackers/xvmc/tests/test_blocks.c b/src/gallium/state_trackers/xvmc/tests/test_blocks.c
new file mode 100644 (file)
index 0000000..f8fc2f5
--- /dev/null
@@ -0,0 +1,111 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+#include <error.h>
+#include "testlib.h"
+
+int main(int argc, char **argv)
+{
+       const unsigned int      width = 16, height = 16;
+       const unsigned int      min_required_blocks = 1, min_required_macroblocks = 1;
+       const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
+
+       Display                 *display;
+       XvPortID                port_num;
+       int                     surface_type_id;
+       unsigned int            is_overlay, intra_unsigned;
+       int                     colorkey;
+       XvMCContext             context;
+       XvMCSurface             surface;
+       XvMCBlockArray          blocks = {0};
+       XvMCMacroBlockArray     macroblocks = {0};
+
+       display = XOpenDisplay(NULL);
+
+       if (!GetPort
+       (
+               display,
+               width,
+               height,
+               XVMC_CHROMA_FORMAT_420,
+               mc_types,
+               2,
+               &port_num,
+               &surface_type_id,
+               &is_overlay,
+               &intra_unsigned
+       ))
+       {
+               XCloseDisplay(display);
+               error(1, 0, "Error, unable to find a good port.\n");
+       }
+
+       if (is_overlay)
+       {
+               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
+               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
+       }
+
+       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
+       assert(XvMCCreateSurface(display, &context, &surface) == Success);
+
+       /* Test NULL context */
+       assert(XvMCCreateBlocks(display, NULL, 1, &blocks) == XvMCBadContext);
+       /* Test 0 blocks */
+       assert(XvMCCreateBlocks(display, &context, 0, &blocks) == BadValue);
+       /* Test valid params */
+       assert(XvMCCreateBlocks(display, &context, min_required_blocks, &blocks) == Success);
+       /* Test context id assigned and correct */
+       assert(blocks.context_id == context.context_id);
+       /* Test number of blocks assigned and correct */
+       assert(blocks.num_blocks == min_required_blocks);
+       /* Test block pointer valid */
+       assert(blocks.blocks != NULL);
+       /* Test NULL context */
+       assert(XvMCCreateMacroBlocks(display, NULL, 1, &macroblocks) == XvMCBadContext);
+       /* Test 0 macroblocks */
+       assert(XvMCCreateMacroBlocks(display, &context, 0, &macroblocks) == BadValue);
+       /* Test valid params */
+       assert(XvMCCreateMacroBlocks(display, &context, min_required_macroblocks, &macroblocks) == Success);
+       /* Test context id assigned and correct */
+       assert(macroblocks.context_id == context.context_id);
+       /* Test macroblock pointer valid */
+       assert(macroblocks.macro_blocks != NULL);
+       /* Test valid params */
+       assert(XvMCDestroyMacroBlocks(display, &macroblocks) == Success);
+       /* Test valid params */
+       assert(XvMCDestroyBlocks(display, &blocks) == Success);
+
+       assert(XvMCDestroySurface(display, &surface) == Success);
+       assert(XvMCDestroyContext(display, &context) == Success);
+
+       XvUngrabPort(display, port_num, CurrentTime);
+       XCloseDisplay(display);
+
+       return 0;
+}
diff --git a/src/gallium/state_trackers/xvmc/tests/test_context.c b/src/gallium/state_trackers/xvmc/tests/test_context.c
new file mode 100644 (file)
index 0000000..eed9a08
--- /dev/null
@@ -0,0 +1,119 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+#include <error.h>
+#include "testlib.h"
+
+int main(int argc, char **argv)
+{
+       const unsigned int      width = 16, height = 16;
+       const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
+
+       Display                 *display;
+       XvPortID                port_num;
+       int                     surface_type_id;
+       unsigned int            is_overlay, intra_unsigned;
+       int                     colorkey;
+       XvMCContext             context = {0};
+
+       display = XOpenDisplay(NULL);
+
+       if (!GetPort
+       (
+               display,
+               width,
+               height,
+               XVMC_CHROMA_FORMAT_420,
+               mc_types,
+               2,
+               &port_num,
+               &surface_type_id,
+               &is_overlay,
+               &intra_unsigned
+       ))
+       {
+               XCloseDisplay(display);
+               error(1, 0, "Error, unable to find a good port.\n");
+       }
+
+       if (is_overlay)
+       {
+               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
+               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
+       }
+
+       /* Test NULL context */
+       /* XXX: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */
+       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, NULL) == XvMCBadContext);
+       /* Test invalid port */
+       /* XXX: Success and XvBadPort have the same value, if this call actually gets passed the validation step as of now we'll crash later */
+       assert(XvMCCreateContext(display, -1, surface_type_id, width, height, XVMC_DIRECT, &context) == XvBadPort);
+       /* Test invalid surface */
+       assert(XvMCCreateContext(display, port_num, -1, width, height, XVMC_DIRECT, &context) == BadMatch);
+       /* Test invalid flags */
+       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, -1, &context) == BadValue);
+       /* Test huge width */
+       assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, height, XVMC_DIRECT, &context) == BadValue);
+       /* Test huge height */
+       assert(XvMCCreateContext(display, port_num, surface_type_id, width, 16384, XVMC_DIRECT, &context) == BadValue);
+       /* Test huge width & height */
+       assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, 16384, XVMC_DIRECT, &context) == BadValue);
+       /* Test valid params */
+       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
+       /* Test context id assigned */
+       assert(context.context_id != 0);
+       /* Test surface type id assigned and correct */
+       assert(context.surface_type_id == surface_type_id);
+       /* Test width & height assigned and correct */
+       assert(context.width == width && context.height == height);
+       /* Test port assigned and correct */
+       assert(context.port == port_num);
+       /* Test flags assigned and correct */
+       assert(context.flags == XVMC_DIRECT);
+       /* Test NULL context */
+       assert(XvMCDestroyContext(display, NULL) == XvMCBadContext);
+       /* Test valid params */
+       assert(XvMCDestroyContext(display, &context) == Success);
+       /* Test awkward but valid width */
+       assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height, XVMC_DIRECT, &context) == Success);
+       assert(context.width >= width + 1);
+       assert(XvMCDestroyContext(display, &context) == Success);
+       /* Test awkward but valid height */
+       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height + 1, XVMC_DIRECT, &context) == Success);
+       assert(context.height >= height + 1);
+       assert(XvMCDestroyContext(display, &context) == Success);
+       /* Test awkward but valid width & height */
+       assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height + 1, XVMC_DIRECT, &context) == Success);
+       assert(context.width >= width + 1 && context.height >= height + 1);
+       assert(XvMCDestroyContext(display, &context) == Success);
+
+       XvUngrabPort(display, port_num, CurrentTime);
+       XCloseDisplay(display);
+
+       return 0;
+}
diff --git a/src/gallium/state_trackers/xvmc/tests/test_rendering.c b/src/gallium/state_trackers/xvmc/tests/test_rendering.c
new file mode 100644 (file)
index 0000000..a7a6bda
--- /dev/null
@@ -0,0 +1,327 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <error.h>
+#include "testlib.h"
+
+#define BLOCK_WIDTH                    8
+#define BLOCK_HEIGHT                   8
+#define BLOCK_SIZE                     (BLOCK_WIDTH * BLOCK_HEIGHT)
+#define MACROBLOCK_WIDTH               16
+#define MACROBLOCK_HEIGHT              16
+#define MACROBLOCK_WIDTH_IN_BLOCKS     (MACROBLOCK_WIDTH / BLOCK_WIDTH)
+#define MACROBLOCK_HEIGHT_IN_BLOCKS    (MACROBLOCK_HEIGHT / BLOCK_HEIGHT)
+#define BLOCKS_PER_MACROBLOCK          6
+
+#define INPUT_WIDTH                    64
+#define INPUT_HEIGHT                   64
+#define INPUT_WIDTH_IN_MACROBLOCKS     (INPUT_WIDTH / MACROBLOCK_WIDTH)
+#define INPUT_HEIGHT_IN_MACROBLOCKS    (INPUT_HEIGHT / MACROBLOCK_HEIGHT)
+#define NUM_MACROBLOCKS                        (INPUT_WIDTH_IN_MACROBLOCKS * INPUT_HEIGHT_IN_MACROBLOCKS)
+
+#define DEFAULT_OUTPUT_WIDTH           INPUT_WIDTH
+#define DEFAULT_OUTPUT_HEIGHT          INPUT_HEIGHT
+#define DEFAULT_ACCEPTABLE_ERR         0.01
+
+void ParseArgs(int argc, char **argv, unsigned int *output_width, unsigned int *output_height, double *acceptable_error, int *prompt);
+
+void ParseArgs(int argc, char **argv, unsigned int *output_width, unsigned int *output_height, double *acceptable_error, int *prompt)
+{
+       int fail = 0;
+       int i;
+
+       *output_width = DEFAULT_OUTPUT_WIDTH;
+       *output_height = DEFAULT_OUTPUT_HEIGHT;
+       *acceptable_error = DEFAULT_ACCEPTABLE_ERR;
+       *prompt = 1;
+
+       for (i = 1; i < argc && !fail; ++i)
+       {
+               if (!strcmp(argv[i], "-w"))
+               {
+                       if (sscanf(argv[++i], "%u", output_width) != 1)
+                               fail = 1;
+               }
+               else if (!strcmp(argv[i], "-h"))
+               {
+                       if (sscanf(argv[++i], "%u", output_height) != 1)
+                               fail = 1;
+               }
+               else if (!strcmp(argv[i], "-e"))
+               {
+                       if (sscanf(argv[++i], "%lf", acceptable_error) != 1)
+                               fail = 1;
+               }
+               else if (strcmp(argv[i], "-n"))
+                       *prompt = 0;
+               else
+                       fail = 1;
+       }
+
+       if (fail)
+               error
+               (
+                       1, 0,
+                       "Bad argument.\n"
+                       "\n"
+                       "Usage: %s [options]\n"
+                       "\t-w <width>\tOutput width\n"
+                       "\t-h <height>\tOutput height\n"
+                       "\t-e <error>\tAcceptable margin of error per pixel, from 0 to 1\n"
+                       "\t-n\tDon't prompt for quit\n",
+                       argv[0]
+               );
+}
+
+static void Gradient(short *block, unsigned int start, unsigned int stop, int horizontal, unsigned int intra_unsigned)
+{
+       unsigned int x, y;
+       unsigned int range = stop - start;
+
+       if (horizontal)
+       {
+               for (y = 0; y < BLOCK_HEIGHT; ++y)
+                       for (x = 0; x < BLOCK_WIDTH; ++x) {
+                               *block = (short)(start + range * (x / (float)(BLOCK_WIDTH - 1)));
+                               if (intra_unsigned)
+                                       *block += 1 << 10;
+                               block++;
+                       }
+       }
+       else
+       {
+               for (y = 0; y < BLOCK_HEIGHT; ++y)
+                       for (x = 0; x < BLOCK_WIDTH; ++x) {
+                               *block = (short)(start + range * (y / (float)(BLOCK_WIDTH - 1)));
+                               if (intra_unsigned)
+                                       *block += 1 << 10;
+                               block++;
+                       }
+       }
+}
+
+int main(int argc, char **argv)
+{
+       unsigned int            output_width;
+       unsigned int            output_height;
+       double                  acceptable_error;
+       int                     prompt;
+       Display                 *display;
+       Window                  root, window;
+       const unsigned int      mc_types[] = {XVMC_MOCOMP | XVMC_MPEG_2};
+       XvPortID                port_num;
+       int                     surface_type_id;
+       unsigned int            is_overlay, intra_unsigned;
+       int                     colorkey;
+       XvMCContext             context;
+       XvMCSurface             surface;
+       XvMCBlockArray          block_array;
+       XvMCMacroBlockArray     mb_array;
+       int                     mbx, mby, bx, by;
+       XvMCMacroBlock          *mb;
+       short                   *blocks;
+       int                     quit = 0;
+
+       ParseArgs(argc, argv, &output_width, &output_height, &acceptable_error, &prompt);
+
+       display = XOpenDisplay(NULL);
+
+       if (!GetPort
+       (
+               display,
+               INPUT_WIDTH,
+               INPUT_HEIGHT,
+               XVMC_CHROMA_FORMAT_420,
+               mc_types,
+               sizeof(mc_types)/sizeof(*mc_types),
+               &port_num,
+               &surface_type_id,
+               &is_overlay,
+               &intra_unsigned
+       ))
+       {
+               XCloseDisplay(display);
+               error(1, 0, "Error, unable to find a good port.\n");
+       }
+
+       if (is_overlay)
+       {
+               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
+               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
+       }
+
+       root = XDefaultRootWindow(display);
+       window = XCreateSimpleWindow(display, root, 0, 0, output_width, output_height, 0, 0, colorkey);
+
+       assert(XvMCCreateContext(display, port_num, surface_type_id, INPUT_WIDTH, INPUT_HEIGHT, XVMC_DIRECT, &context) == Success);
+       assert(XvMCCreateSurface(display, &context, &surface) == Success);
+       assert(XvMCCreateBlocks(display, &context, NUM_MACROBLOCKS * BLOCKS_PER_MACROBLOCK, &block_array) == Success);
+       assert(XvMCCreateMacroBlocks(display, &context, NUM_MACROBLOCKS, &mb_array) == Success);
+
+       mb = mb_array.macro_blocks;
+       blocks = block_array.blocks;
+
+       for (mby = 0; mby < INPUT_HEIGHT_IN_MACROBLOCKS; ++mby)
+               for (mbx = 0; mbx < INPUT_WIDTH_IN_MACROBLOCKS; ++mbx)
+               {
+                       mb->x = mbx;
+                       mb->y = mby;
+                       mb->macroblock_type = XVMC_MB_TYPE_INTRA;
+                       /*mb->motion_type = ;*/
+                       /*mb->motion_vertical_field_select = ;*/
+                       mb->dct_type = XVMC_DCT_TYPE_FRAME;
+                       /*mb->PMV[0][0][0] = ;
+                       mb->PMV[0][0][1] = ;
+                       mb->PMV[0][1][0] = ;
+                       mb->PMV[0][1][1] = ;
+                       mb->PMV[1][0][0] = ;
+                       mb->PMV[1][0][1] = ;
+                       mb->PMV[1][1][0] = ;
+                       mb->PMV[1][1][1] = ;*/
+                       mb->index = (mby * INPUT_WIDTH_IN_MACROBLOCKS + mbx) * BLOCKS_PER_MACROBLOCK;
+                       mb->coded_block_pattern = 0x3F;
+
+                       mb++;
+
+                       for (by = 0; by < MACROBLOCK_HEIGHT_IN_BLOCKS; ++by)
+                               for (bx = 0; bx < MACROBLOCK_WIDTH_IN_BLOCKS; ++bx)
+                               {
+                                       const int start = 16, stop = 235, range = stop - start;
+
+                                       Gradient
+                                       (
+                                               blocks,
+                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))),
+                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))),
+                                               1,
+                                               intra_unsigned
+                                       );
+
+                                       blocks += BLOCK_SIZE;
+                               }
+
+                       for (by = 0; by < MACROBLOCK_HEIGHT_IN_BLOCKS / 2; ++by)
+                               for (bx = 0; bx < MACROBLOCK_WIDTH_IN_BLOCKS / 2; ++bx)
+                               {
+                                       const int start = 16, stop = 240, range = stop - start;
+
+                                       Gradient
+                                       (
+                                               blocks,
+                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))),
+                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))),
+                                               1,
+                                               intra_unsigned
+                                       );
+
+                                       blocks += BLOCK_SIZE;
+
+                                       Gradient
+                                       (
+                                               blocks,
+                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH) / (float)(INPUT_WIDTH - 1))),
+                                               (short)(start + range * ((mbx * MACROBLOCK_WIDTH + bx * BLOCK_WIDTH + BLOCK_WIDTH - 1) / (float)(INPUT_WIDTH - 1))),
+                                               1,
+                                               intra_unsigned
+                                       );
+
+                                       blocks += BLOCK_SIZE;
+                               }
+               }
+
+       XSelectInput(display, window, ExposureMask | KeyPressMask);
+       XMapWindow(display, window);
+       XSync(display, 0);
+
+       /* Test NULL context */
+       assert(XvMCRenderSurface(display, NULL, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == XvMCBadContext);
+       /* Test NULL surface */
+       assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, NULL, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == XvMCBadSurface);
+       /* Test bad picture structure */
+       assert(XvMCRenderSurface(display, &context, 0, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == BadValue);
+       /* Test valid params */
+       assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, NUM_MACROBLOCKS, 0, &mb_array, &block_array) == Success);
+
+       /* Test NULL surface */
+       assert(XvMCPutSurface(display, NULL, window, 0, 0, INPUT_WIDTH, INPUT_HEIGHT, 0, 0, output_width, output_height, XVMC_FRAME_PICTURE) == XvMCBadSurface);
+       /* Test bad window */
+       /* XXX: X halts with a bad drawable for some reason, doesn't return BadDrawable as expected */
+       /*assert(XvMCPutSurface(display, &surface, 0, 0, 0, width, height, 0, 0, width, height, XVMC_FRAME_PICTURE) == BadDrawable);*/
+
+       if (prompt)
+       {
+               puts("Press any button to quit...");
+
+               while (!quit)
+               {
+                       if (XPending(display) > 0)
+                       {
+                               XEvent event;
+
+                               XNextEvent(display, &event);
+
+                               switch (event.type)
+                               {
+                                       case Expose:
+                                       {
+                                               /* Test valid params */
+                                               assert
+                                               (
+                                                       XvMCPutSurface
+                                                       (
+                                                               display, &surface, window,
+                                                               0, 0, INPUT_WIDTH, INPUT_HEIGHT,
+                                                               0, 0, output_width, output_height,
+                                                               XVMC_FRAME_PICTURE
+                                                       ) == Success
+                                               );
+                                               break;
+                                       }
+                                       case KeyPress:
+                                       {
+                                               quit = 1;
+                                               break;
+                                       }
+                               }
+                       }
+               }
+       }
+
+       assert(XvMCDestroyBlocks(display, &block_array) == Success);
+       assert(XvMCDestroyMacroBlocks(display, &mb_array) == Success);
+       assert(XvMCDestroySurface(display, &surface) == Success);
+       assert(XvMCDestroyContext(display, &context) == Success);
+
+       XvUngrabPort(display, port_num, CurrentTime);
+       XDestroyWindow(display, window);
+       XCloseDisplay(display);
+
+       return 0;
+}
diff --git a/src/gallium/state_trackers/xvmc/tests/test_subpicture.c b/src/gallium/state_trackers/xvmc/tests/test_subpicture.c
new file mode 100644 (file)
index 0000000..9683a1a
--- /dev/null
@@ -0,0 +1,182 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+#include <error.h>
+#include <stdio.h>
+#include "testlib.h"
+
+static void PrintGUID(const char *guid)
+{
+       int i;
+       printf("\tguid: ");
+       for (i = 0; i < 4; ++i)
+               printf("%C,", guid[i] == 0 ? '0' : guid[i]);
+       for (; i < 15; ++i)
+               printf("%x,", (unsigned char)guid[i]);
+       printf("%x\n", (unsigned int)guid[15]);
+}
+
+static void PrintComponentOrder(const char *co)
+{
+       int i;
+       printf("\tcomponent_order:\n\t   ");
+       for (i = 0; i < 4; ++i)
+               printf("%C,", co[i] == 0 ? '0' : co[i]);
+       for (; i < 31; ++i)
+               printf("%x,", (unsigned int)co[i]);
+       printf("%x\n", (unsigned int)co[31]);
+}
+
+int main(int argc, char **argv)
+{
+       const unsigned int      width = 16, height = 16;
+       const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
+       const unsigned int      subpic_width = 16, subpic_height = 16;
+
+       Display                 *display;
+       XvPortID                port_num;
+       int                     surface_type_id;
+       unsigned int            is_overlay, intra_unsigned;
+       int                     colorkey;
+       XvMCContext             context;
+       XvImageFormatValues     *subpics;
+       int                     num_subpics;
+       XvMCSubpicture          subpicture = {0};
+       int                     i;
+
+       display = XOpenDisplay(NULL);
+
+       if (!GetPort
+       (
+               display,
+               width,
+               height,
+               XVMC_CHROMA_FORMAT_420,
+               mc_types,
+               2,
+               &port_num,
+               &surface_type_id,
+               &is_overlay,
+               &intra_unsigned
+       ))
+       {
+               XCloseDisplay(display);
+               error(1, 0, "Error, unable to find a good port.\n");
+       }
+
+       if (is_overlay)
+       {
+               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
+               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
+       }
+
+       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
+
+       subpics = XvMCListSubpictureTypes(display, port_num, surface_type_id, &num_subpics);
+       assert((subpics && num_subpics) > 0 || (!subpics && num_subpics == 0));
+
+       for (i = 0; i < num_subpics; ++i)
+       {
+               printf("Subpicture %d:\n", i);
+               printf("\tid: 0x%08x\n", subpics[i].id);
+               printf("\ttype: %s\n", subpics[i].type == XvRGB ? "XvRGB" : (subpics[i].type == XvYUV ? "XvYUV" : "Unknown"));
+               printf("\tbyte_order: %s\n", subpics[i].byte_order == LSBFirst ? "LSB First" : (subpics[i].byte_order == MSBFirst ? "MSB First" : "Unknown"));
+               PrintGUID(subpics[i].guid);
+               printf("\tbpp: %u\n", subpics[i].bits_per_pixel);
+               printf("\tformat: %s\n", subpics[i].format == XvPacked ? "XvPacked" : (subpics[i].format == XvPlanar ? "XvPlanar" : "Unknown"));
+               printf("\tnum_planes: %u\n", subpics[i].num_planes);
+
+               if (subpics[i].type == XvRGB)
+               {
+                       printf("\tdepth: %u\n", subpics[i].depth);
+                       printf("\tred_mask: 0x%08x\n", subpics[i].red_mask);
+                       printf("\tgreen_mask: 0x%08x\n", subpics[i].green_mask);
+                       printf("\tblue_mask: 0x%08x\n", subpics[i].blue_mask);
+               }
+               else if (subpics[i].type == XvYUV)
+               {
+                       printf("\ty_sample_bits: %u\n", subpics[i].y_sample_bits);
+                       printf("\tu_sample_bits: %u\n", subpics[i].u_sample_bits);
+                       printf("\tv_sample_bits: %u\n", subpics[i].v_sample_bits);
+                       printf("\thorz_y_period: %u\n", subpics[i].horz_y_period);
+                       printf("\thorz_u_period: %u\n", subpics[i].horz_u_period);
+                       printf("\thorz_v_period: %u\n", subpics[i].horz_v_period);
+                       printf("\tvert_y_period: %u\n", subpics[i].vert_y_period);
+                       printf("\tvert_u_period: %u\n", subpics[i].vert_u_period);
+                       printf("\tvert_v_period: %u\n", subpics[i].vert_v_period);
+               }
+               PrintComponentOrder(subpics[i].component_order);
+               printf("\tscanline_order: %s\n", subpics[i].scanline_order == XvTopToBottom ? "XvTopToBottom" : (subpics[i].scanline_order == XvBottomToTop ? "XvBottomToTop" : "Unknown"));
+       }
+
+       if (num_subpics == 0)
+       {
+               printf("Subpictures not supported, nothing to test.\n");
+               return 0;
+       }
+
+       /* Test NULL context */
+       assert(XvMCCreateSubpicture(display, NULL, &subpicture, subpic_width, subpic_height, subpics[0].id) == XvMCBadContext);
+       /* Test NULL subpicture */
+       assert(XvMCCreateSubpicture(display, &context, NULL, subpic_width, subpic_height, subpics[0].id) == XvMCBadSubpicture);
+       /* Test invalid subpicture */
+       assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, -1) == BadMatch);
+       /* Test huge width */
+       assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, subpic_height, subpics[0].id) == BadValue);
+       /* Test huge height */
+       assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, 16384, subpics[0].id) == BadValue);
+       /* Test huge width & height */
+       assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, 16384, subpics[0].id) == BadValue);
+       for (i = 0; i < num_subpics; ++i)
+       {
+               /* Test valid params */
+               assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, subpics[i].id) == Success);
+               /* Test subpicture id assigned */
+               assert(subpicture.subpicture_id != 0);
+               /* Test context id assigned and correct */
+               assert(subpicture.context_id == context.context_id);
+               /* Test subpicture type id assigned and correct */
+               assert(subpicture.xvimage_id == subpics[i].id);
+               /* Test width & height assigned and correct */
+               assert(subpicture.width == width && subpicture.height == height);
+               /* Test no palette support */
+               assert(subpicture.num_palette_entries == 0 && subpicture.entry_bytes == 0);
+               /* Test valid params */
+               assert(XvMCDestroySubpicture(display, &subpicture) == Success);
+       }
+       /* Test NULL surface */
+       assert(XvMCDestroySubpicture(display, NULL) == XvMCBadSubpicture);
+
+       assert(XvMCDestroyContext(display, &context) == Success);
+
+       XFree(subpics);
+       XvUngrabPort(display, port_num, CurrentTime);
+       XCloseDisplay(display);
+
+       return 0;
+}
diff --git a/src/gallium/state_trackers/xvmc/tests/test_surface.c b/src/gallium/state_trackers/xvmc/tests/test_surface.c
new file mode 100644 (file)
index 0000000..1705a26
--- /dev/null
@@ -0,0 +1,98 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+#include <error.h>
+#include "testlib.h"
+
+int main(int argc, char **argv)
+{
+       const unsigned int      width = 16, height = 16;
+       const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
+
+       Display                 *display;
+       XvPortID                port_num;
+       int                     surface_type_id;
+       unsigned int            is_overlay, intra_unsigned;
+       int                     colorkey;
+       XvMCContext             context;
+       XvMCSurface             surface = {0};
+
+       display = XOpenDisplay(NULL);
+
+       if (!GetPort
+       (
+               display,
+               width,
+               height,
+               XVMC_CHROMA_FORMAT_420,
+               mc_types,
+               2,
+               &port_num,
+               &surface_type_id,
+               &is_overlay,
+               &intra_unsigned
+       ))
+       {
+               XCloseDisplay(display);
+               error(1, 0, "Error, unable to find a good port.\n");
+       }
+
+       if (is_overlay)
+       {
+               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
+               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
+       }
+
+       assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
+
+       /* Test NULL context */
+       assert(XvMCCreateSurface(display, NULL, &surface) == XvMCBadContext);
+       /* Test NULL surface */
+       assert(XvMCCreateSurface(display, &context, NULL) == XvMCBadSurface);
+       /* Test valid params */
+       assert(XvMCCreateSurface(display, &context, &surface) == Success);
+       /* Test surface id assigned */
+       assert(surface.surface_id != 0);
+       /* Test context id assigned and correct */
+       assert(surface.context_id == context.context_id);
+       /* Test surface type id assigned and correct */
+       assert(surface.surface_type_id == surface_type_id);
+       /* Test width & height assigned and correct */
+       assert(surface.width == width && surface.height == height);
+       /* Test valid params */
+       assert(XvMCDestroySurface(display, &surface) == Success);
+       /* Test NULL surface */
+       assert(XvMCDestroySurface(display, NULL) == XvMCBadSurface);
+
+       assert(XvMCDestroyContext(display, &context) == Success);
+
+       XvUngrabPort(display, port_num, CurrentTime);
+       XCloseDisplay(display);
+
+       return 0;
+}
diff --git a/src/gallium/state_trackers/xvmc/tests/testlib.c b/src/gallium/state_trackers/xvmc/tests/testlib.c
new file mode 100644 (file)
index 0000000..86d4b1c
--- /dev/null
@@ -0,0 +1,146 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include "testlib.h"
+#include <stdio.h>
+
+/*
+void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line)
+{
+       fputs(doc_string, stderr);
+       if (!pred)
+               fprintf(stderr, " FAIL!\n\t\"%s\" at %s:%u\n", pred_string, file, line);
+       else
+               fputs(" PASS!\n", stderr);
+}
+*/
+
+int GetPort
+(
+       Display *display,
+       unsigned int width,
+       unsigned int height,
+       unsigned int chroma_format,
+       const unsigned int *mc_types,
+       unsigned int num_mc_types,
+       XvPortID *port_id,
+       int *surface_type_id,
+       unsigned int *is_overlay,
+       unsigned int *intra_unsigned
+)
+{
+       unsigned int    found_port = 0;
+       XvAdaptorInfo   *adaptor_info;
+       unsigned int    num_adaptors;
+       int             num_types;
+       int             ev_base, err_base;
+       unsigned int    i, j, k, l;
+
+       if (!XvMCQueryExtension(display, &ev_base, &err_base))
+               return 0;
+       if (XvQueryAdaptors(display, XDefaultRootWindow(display), &num_adaptors, &adaptor_info) != Success)
+               return 0;
+
+       for (i = 0; i < num_adaptors && !found_port; ++i)
+       {
+               if (adaptor_info[i].type & XvImageMask)
+               {
+                       XvMCSurfaceInfo *surface_info = XvMCListSurfaceTypes(display, adaptor_info[i].base_id, &num_types);
+
+                       if (surface_info)
+                       {
+                               for (j = 0; j < num_types && !found_port; ++j)
+                               {
+                                       if
+                                       (
+                                               surface_info[j].chroma_format == chroma_format &&
+                                               surface_info[j].max_width >= width &&
+                                               surface_info[j].max_height >= height
+                                       )
+                                       {
+                                               for (k = 0; k < num_mc_types && !found_port; ++k)
+                                               {
+                                                       if (surface_info[j].mc_type == mc_types[k])
+                                                       {
+                                                               for (l = 0; l < adaptor_info[i].num_ports && !found_port; ++l)
+                                                               {
+                                                                       if (XvGrabPort(display, adaptor_info[i].base_id + l, CurrentTime) == Success)
+                                                                       {
+                                                                               *port_id = adaptor_info[i].base_id + l;
+                                                                               *surface_type_id = surface_info[j].surface_type_id;
+                                                                               *is_overlay = surface_info[j].flags & XVMC_OVERLAID_SURFACE;
+                                                                               *intra_unsigned = surface_info[j].flags & XVMC_INTRA_UNSIGNED;
+                                                                               found_port = 1;
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+
+                               XFree(surface_info);
+                       }
+               }
+       }
+
+       XvFreeAdaptorInfo(adaptor_info);
+
+       return found_port;
+}
+
+unsigned int align(unsigned int value, unsigned int alignment)
+{
+       return (value + alignment - 1) & ~(alignment - 1);
+}
+
+/* From the glibc manual */
+int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)
+{
+       /* Perform the carry for the later subtraction by updating y. */
+       if (x->tv_usec < y->tv_usec)
+       {
+               int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;
+               y->tv_usec -= 1000000 * nsec;
+               y->tv_sec += nsec;
+       }
+       if (x->tv_usec - y->tv_usec > 1000000)
+       {
+               int nsec = (x->tv_usec - y->tv_usec) / 1000000;
+               y->tv_usec += 1000000 * nsec;
+               y->tv_sec -= nsec;
+       }
+
+       /*
+        * Compute the time remaining to wait.
+        * tv_usec is certainly positive.
+        */
+       result->tv_sec = x->tv_sec - y->tv_sec;
+       result->tv_usec = x->tv_usec - y->tv_usec;
+
+       /* Return 1 if result is negative. */
+       return x->tv_sec < y->tv_sec;
+}
diff --git a/src/gallium/state_trackers/xvmc/tests/testlib.h b/src/gallium/state_trackers/xvmc/tests/testlib.h
new file mode 100644 (file)
index 0000000..c27fc3c
--- /dev/null
@@ -0,0 +1,69 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#ifndef testlib_h
+#define testlib_h
+
+/*
+#define TEST(pred, doc)        test(pred, #pred, doc, __FILE__, __LINE__)
+
+void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line);
+*/
+
+#include <sys/time.h>
+#include <X11/Xlib.h>
+#include <X11/extensions/XvMClib.h>
+
+/*
+ * display: IN                 A valid X display
+ * width, height: IN           Surface size that the port must display
+ * chroma_format: IN           Chroma format that the port must display
+ * mc_types, num_mc_types: IN  List of MC types that the port must support, first port that matches the first mc_type will be returned
+ * port_id: OUT                        Your port's ID
+ * surface_type_id: OUT                Your port's surface ID
+ * is_overlay: OUT             If 1, port uses overlay surfaces, you need to set a colorkey
+ * intra_unsigned: OUT         If 1, port uses unsigned values for intra-coded blocks
+ */
+int GetPort
+(
+       Display *display,
+       unsigned int width,
+       unsigned int height,
+       unsigned int chroma_format,
+       const unsigned int *mc_types,
+       unsigned int num_mc_types,
+       XvPortID *port_id,
+       int *surface_type_id,
+       unsigned int *is_overlay,
+       unsigned int *intra_unsigned
+);
+
+unsigned int align(unsigned int value, unsigned int alignment);
+
+int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y);
+
+#endif
diff --git a/src/gallium/state_trackers/xvmc/tests/xvmc_bench.c b/src/gallium/state_trackers/xvmc/tests/xvmc_bench.c
new file mode 100644 (file)
index 0000000..4c37b8d
--- /dev/null
@@ -0,0 +1,300 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#include <assert.h>
+#include <stdio.h>
+#include <string.h>
+#include <error.h>
+#include <sys/time.h>
+#include "testlib.h"
+
+#define MACROBLOCK_WIDTH               16
+#define MACROBLOCK_HEIGHT              16
+#define BLOCKS_PER_MACROBLOCK          6
+
+#define DEFAULT_INPUT_WIDTH            720
+#define DEFAULT_INPUT_HEIGHT           480
+#define DEFAULT_REPS                   100
+
+#define PIPELINE_STEP_MC               1
+#define PIPELINE_STEP_CSC              2
+#define PIPELINE_STEP_SWAP             4
+
+#define MB_TYPE_I                      1
+#define MB_TYPE_P                      2
+#define MB_TYPE_B                      4
+
+struct Config
+{
+       unsigned int input_width;
+       unsigned int input_height;
+       unsigned int output_width;
+       unsigned int output_height;
+       unsigned int pipeline;
+       unsigned int mb_types;
+       unsigned int reps;
+};
+
+void ParseArgs(int argc, char **argv, struct Config *config);
+
+void ParseArgs(int argc, char **argv, struct Config *config)
+{
+       int fail = 0;
+       int i;
+
+       config->input_width = DEFAULT_INPUT_WIDTH;
+       config->input_height = DEFAULT_INPUT_HEIGHT;
+       config->output_width = 0;
+       config->output_height = 0;
+       config->pipeline = 0;
+       config->mb_types = 0;
+       config->reps = DEFAULT_REPS;
+
+       for (i = 1; i < argc && !fail; ++i)
+       {
+               if (!strcmp(argv[i], "-iw"))
+               {
+                       if (sscanf(argv[++i], "%u", &config->input_width) != 1)
+                               fail = 1;
+               }
+               else if (!strcmp(argv[i], "-ih"))
+               {
+                       if (sscanf(argv[++i], "%u", &config->input_height) != 1)
+                               fail = 1;
+               }
+               else if (!strcmp(argv[i], "-ow"))
+               {
+                       if (sscanf(argv[++i], "%u", &config->output_width) != 1)
+                               fail = 1;
+               }
+               else if (!strcmp(argv[i], "-oh"))
+               {
+                       if (sscanf(argv[++i], "%u", &config->output_height) != 1)
+                               fail = 1;
+               }
+               else if (!strcmp(argv[i], "-p"))
+               {
+                       char *token = strtok(argv[++i], ",");
+
+                       while (token && !fail)
+                       {
+                               if (!strcmp(token, "mc"))
+                                       config->pipeline |= PIPELINE_STEP_MC;
+                               else if (!strcmp(token, "csc"))
+                                       config->pipeline |= PIPELINE_STEP_CSC;
+                               else if (!strcmp(token, "swp"))
+                                       config->pipeline |= PIPELINE_STEP_SWAP;
+                               else
+                                       fail = 1;
+
+                               if (!fail)
+                                       token = strtok(NULL, ",");
+                       }
+               }
+               else if (!strcmp(argv[i], "-mb"))
+               {
+                       char *token = strtok(argv[++i], ",");
+
+                       while (token && !fail)
+                       {
+                               if (strcmp(token, "i"))
+                                       config->mb_types |= MB_TYPE_I;
+                               else if (strcmp(token, "p"))
+                                       config->mb_types |= MB_TYPE_P;
+                               else if (strcmp(token, "b"))
+                                       config->mb_types |= MB_TYPE_B;
+                               else
+                                       fail = 1;
+
+                               if (!fail)
+                                       token = strtok(NULL, ",");
+                       }
+               }
+               else if (!strcmp(argv[i], "-r"))
+               {
+                       if (sscanf(argv[++i], "%u", &config->reps) != 1)
+                               fail = 1;
+               }
+               else
+                       fail = 1;
+       }
+
+       if (fail)
+               error
+               (
+                       1, 0,
+                       "Bad argument.\n"
+                       "\n"
+                       "Usage: %s [options]\n"
+                       "\t-iw <width>\tInput width\n"
+                       "\t-ih <height>\tInput height\n"
+                       "\t-ow <width>\tOutput width\n"
+                       "\t-oh <height>\tOutput height\n"
+                       "\t-p <pipeline>\tPipeline to test\n"
+                       "\t-mb <mb type>\tMacroBlock types to use\n"
+                       "\t-r <reps>\tRepetitions\n\n"
+                       "\tPipeline steps: mc,csc,swap\n"
+                       "\tMB types: i,p,b\n",
+                       argv[0]
+               );
+
+       if (config->output_width == 0)
+               config->output_width = config->input_width;
+       if (config->output_height == 0)
+               config->output_height = config->input_height;
+       if (!config->pipeline)
+               config->pipeline = PIPELINE_STEP_MC | PIPELINE_STEP_CSC | PIPELINE_STEP_SWAP;
+       if (!config->mb_types)
+               config->mb_types = MB_TYPE_I | MB_TYPE_P | MB_TYPE_B;
+}
+
+int main(int argc, char **argv)
+{
+       struct Config           config;
+       Display                 *display;
+       Window                  root, window;
+       const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
+       XvPortID                port_num;
+       int                     surface_type_id;
+       unsigned int            is_overlay, intra_unsigned;
+       int                     colorkey;
+       XvMCContext             context;
+       XvMCSurface             surface;
+       XvMCBlockArray          block_array;
+       XvMCMacroBlockArray     mb_array;
+       unsigned int            mbw, mbh;
+       unsigned int            mbx, mby;
+       unsigned int            reps;
+       struct timeval          start, stop, diff;
+       double                  diff_secs;
+
+       ParseArgs(argc, argv, &config);
+
+       mbw = align(config.input_width, MACROBLOCK_WIDTH) / MACROBLOCK_WIDTH;
+       mbh = align(config.input_height, MACROBLOCK_HEIGHT) / MACROBLOCK_HEIGHT;
+
+       display = XOpenDisplay(NULL);
+
+       if (!GetPort
+       (
+               display,
+               config.input_width,
+               config.input_height,
+               XVMC_CHROMA_FORMAT_420,
+               mc_types,
+               2,
+               &port_num,
+               &surface_type_id,
+               &is_overlay,
+               &intra_unsigned
+       ))
+       {
+               XCloseDisplay(display);
+               error(1, 0, "Error, unable to find a good port.\n");
+       }
+
+       if (is_overlay)
+       {
+               Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
+               XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
+       }
+
+       root = XDefaultRootWindow(display);
+       window = XCreateSimpleWindow(display, root, 0, 0, config.output_width, config.output_height, 0, 0, colorkey);
+
+       assert(XvMCCreateContext(display, port_num, surface_type_id, config.input_width, config.input_height, XVMC_DIRECT, &context) == Success);
+       assert(XvMCCreateSurface(display, &context, &surface) == Success);
+       assert(XvMCCreateBlocks(display, &context, mbw * mbh * BLOCKS_PER_MACROBLOCK, &block_array) == Success);
+       assert(XvMCCreateMacroBlocks(display, &context, mbw * mbh, &mb_array) == Success);
+
+       for (mby = 0; mby < mbh; ++mby)
+               for (mbx = 0; mbx < mbw; ++mbx)
+               {
+                       mb_array.macro_blocks[mby * mbw + mbx].x = mbx;
+                       mb_array.macro_blocks[mby * mbw + mbx].y = mby;
+                       mb_array.macro_blocks[mby * mbw + mbx].macroblock_type = XVMC_MB_TYPE_INTRA;
+                       /*mb->motion_type = ;*/
+                       /*mb->motion_vertical_field_select = ;*/
+                       mb_array.macro_blocks[mby * mbw + mbx].dct_type = XVMC_DCT_TYPE_FRAME;
+                       /*mb->PMV[0][0][0] = ;
+                       mb->PMV[0][0][1] = ;
+                       mb->PMV[0][1][0] = ;
+                       mb->PMV[0][1][1] = ;
+                       mb->PMV[1][0][0] = ;
+                       mb->PMV[1][0][1] = ;
+                       mb->PMV[1][1][0] = ;
+                       mb->PMV[1][1][1] = ;*/
+                       mb_array.macro_blocks[mby * mbw + mbx].index = (mby * mbw + mbx) * BLOCKS_PER_MACROBLOCK;
+                       mb_array.macro_blocks[mby * mbw + mbx].coded_block_pattern = 0x3F;
+               }
+
+       XSelectInput(display, window, ExposureMask | KeyPressMask);
+       XMapWindow(display, window);
+       XSync(display, 0);
+
+       gettimeofday(&start, NULL);
+
+       for (reps = 0; reps < config.reps; ++reps)
+       {
+               if (config.pipeline & PIPELINE_STEP_MC)
+               {
+                       assert(XvMCRenderSurface(display, &context, XVMC_FRAME_PICTURE, &surface, NULL, NULL, 0, mbw * mbh, 0, &mb_array, &block_array) == Success);
+                       assert(XvMCFlushSurface(display, &surface) == Success);
+               }
+               if (config.pipeline & PIPELINE_STEP_CSC)
+                       assert(XvMCPutSurface(display, &surface, window, 0, 0, config.input_width, config.input_height, 0, 0, config.output_width, config.output_height, XVMC_FRAME_PICTURE) == Success);
+       }
+
+       gettimeofday(&stop, NULL);
+
+       timeval_subtract(&diff, &stop, &start);
+       diff_secs = (double)diff.tv_sec + (double)diff.tv_usec / 1000000.0;
+
+       printf("XvMC Benchmark\n");
+       printf("Input: %u,%u\nOutput: %u,%u\n", config.input_width, config.input_height, config.output_width, config.output_height);
+       printf("Pipeline: ");
+       if (config.pipeline & PIPELINE_STEP_MC)
+               printf("|mc|");
+       if (config.pipeline & PIPELINE_STEP_CSC)
+               printf("|csc|");
+       if (config.pipeline & PIPELINE_STEP_SWAP)
+               printf("|swap|");
+       printf("\n");
+       printf("Reps: %u\n", config.reps);
+       printf("Total time: %.2lf (%.2lf reps / sec)\n", diff_secs, config.reps / diff_secs);
+
+       assert(XvMCDestroyBlocks(display, &block_array) == Success);
+       assert(XvMCDestroyMacroBlocks(display, &mb_array) == Success);
+       assert(XvMCDestroySurface(display, &surface) == Success);
+       assert(XvMCDestroyContext(display, &context) == Success);
+
+       XvUngrabPort(display, port_num, CurrentTime);
+       XDestroyWindow(display, window);
+       XCloseDisplay(display);
+
+       return 0;
+}
diff --git a/src/gallium/state_trackers/xvmc/xvmc_private.h b/src/gallium/state_trackers/xvmc/xvmc_private.h
new file mode 100644 (file)
index 0000000..b9519a7
--- /dev/null
@@ -0,0 +1,129 @@
+/**************************************************************************
+ *
+ * Copyright 2009 Younes Manton.
+ * 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 TUNGSTEN GRAPHICS 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.
+ *
+ **************************************************************************/
+
+#ifndef xvmc_private_h
+#define xvmc_private_h
+
+#include <X11/Xlib.h>
+#include <X11/extensions/XvMClib.h>
+
+#include "pipe/p_video_state.h"
+
+#include "util/u_debug.h"
+#include "util/u_math.h"
+#include "util/u_rect.h"
+
+#include "vl/vl_csc.h"
+#include "vl/vl_compositor.h"
+
+#define BLOCK_SIZE_SAMPLES 64
+#define BLOCK_SIZE_BYTES (BLOCK_SIZE_SAMPLES * 2)
+
+struct pipe_video_decoder;
+struct pipe_video_buffer;
+
+struct pipe_sampler_view;
+struct pipe_fence_handle;
+
+typedef struct
+{
+   struct vl_screen *vscreen;
+   struct pipe_context *pipe;
+   struct pipe_video_decoder *decoder;
+
+   enum VL_CSC_COLOR_STANDARD color_standard;
+   struct vl_procamp procamp;
+   struct vl_compositor compositor;
+
+   unsigned short subpicture_max_width;
+   unsigned short subpicture_max_height;
+
+   struct pipe_video_rect dst_rect;
+   struct pipe_surface *drawable_surface;
+   struct u_rect dirty_area;
+
+} XvMCContextPrivate;
+
+typedef struct
+{
+   struct pipe_video_buffer *video_buffer;
+
+   /* nonzero if this picture is already being decoded */
+   int picture_structure;
+
+   XvMCSurface *ref[2];
+
+   struct pipe_fence_handle *fence;
+
+   /* The subpicture associated with this surface, if any. */
+   XvMCSubpicture *subpicture;
+
+   /* Some XvMC functions take a surface but not a context,
+      so we keep track of which context each surface belongs to. */
+   XvMCContext *context;
+} XvMCSurfacePrivate;
+
+typedef struct
+{
+   struct pipe_sampler_view *sampler;
+
+   /* optional palette for this subpicture */
+   struct pipe_sampler_view *palette;
+
+   struct pipe_video_rect src_rect;
+   struct pipe_video_rect dst_rect;
+
+   /* The surface this subpicture is currently associated with, if any. */
+   XvMCSurface *surface;
+
+   /* Some XvMC functions take a subpicture but not a context,
+      so we keep track of which context each subpicture belongs to. */
+   XvMCContext *context;
+} XvMCSubpicturePrivate;
+
+#define XVMC_OUT   0
+#define XVMC_ERR   1
+#define XVMC_WARN  2
+#define XVMC_TRACE 3
+
+static INLINE void XVMC_MSG(unsigned int level, const char *fmt, ...)
+{
+   static int debug_level = -1;
+
+   if (debug_level == -1) {
+      debug_level = MAX2(debug_get_num_option("XVMC_DEBUG", 0), 0);
+   }
+
+   if (level <= debug_level) {
+      va_list ap;
+      va_start(ap, fmt);
+      _debug_vprintf(fmt, ap);
+      va_end(ap);
+   }
+}
+
+#endif /* xvmc_private_h */
index 8c7b7f4de5b86f6280b995f5bf555442cab6bb79..a46183e8de687b63453c5548a4bcce151da39bb4 100644 (file)
@@ -12,7 +12,7 @@ INCLUDES = -I$(TOP)/src/gallium/include \
           $(DRIVER_INCLUDES)
 DEFINES = -DGALLIUM_TRACE $(DRIVER_DEFINES)
 LIBS = $(EXTRA_LIB_PATH) $(DRIVER_LIBS) -lXv -lX11 -lm
-STATE_TRACKER_LIB = $(TOP)/src/gallium/state_trackers/xorg/xvmc/libxvmctracker.a
+STATE_TRACKER_LIB = $(TOP)/src/gallium/state_trackers/xvmc/libxvmctracker.a
 
 ifeq ($(MESA_LLVM),1)
 LDFLAGS += $(LLVM_LDFLAGS)
@@ -29,7 +29,7 @@ endif
 # XXX: Hack, XvMC public funcs aren't exported if we link to libxvmctracker.a :(
 OBJECTS = $(C_SOURCES:.c=.o) \
          $(ASM_SOURCES:.S=.o) \
-         $(TOP)/src/gallium/state_trackers/xorg/xvmc/*.o
+         $(TOP)/src/gallium/state_trackers/xvmc/*.o
 
 ##### RULES #####