Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | RSS feed

  1. /**************************************************************************
  2.  *
  3.  * Copyright 2009 Younes Manton.
  4.  * All Rights Reserved.
  5.  *
  6.  * Permission is hereby granted, free of charge, to any person obtaining a
  7.  * copy of this software and associated documentation files (the
  8.  * "Software"), to deal in the Software without restriction, including
  9.  * without limitation the rights to use, copy, modify, merge, publish,
  10.  * distribute, sub license, and/or sell copies of the Software, and to
  11.  * permit persons to whom the Software is furnished to do so, subject to
  12.  * the following conditions:
  13.  *
  14.  * The above copyright notice and this permission notice (including the
  15.  * next paragraph) shall be included in all copies or substantial portions
  16.  * of the Software.
  17.  *
  18.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  19.  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20.  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
  21.  * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  22.  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  23.  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  24.  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  25.  *
  26.  **************************************************************************/
  27.  
  28. #include <assert.h>
  29. #include <stdio.h>
  30. #include <stdlib.h>
  31. #include "testlib.h"
  32.  
  33. int main(int argc, char **argv)
  34. {
  35.         const unsigned int      width = 16, height = 16;
  36.         const unsigned int      mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
  37.  
  38.         Display                 *display;
  39.         XvPortID                port_num;
  40.         int                     surface_type_id;
  41.         unsigned int            is_overlay, intra_unsigned;
  42.         int                     colorkey;
  43.         XvMCContext             context = {0};
  44.  
  45.         display = XOpenDisplay(NULL);
  46.  
  47.         if (!GetPort
  48.         (
  49.                 display,
  50.                 width,
  51.                 height,
  52.                 XVMC_CHROMA_FORMAT_420,
  53.                 mc_types,
  54.                 2,
  55.                 &port_num,
  56.                 &surface_type_id,
  57.                 &is_overlay,
  58.                 &intra_unsigned
  59.         ))
  60.         {
  61.                 XCloseDisplay(display);
  62.                 fprintf(stderr, "Error, unable to find a good port.\n");
  63.                 exit(1);
  64.         }
  65.  
  66.         if (is_overlay)
  67.         {
  68.                 Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
  69.                 XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
  70.         }
  71.  
  72.         /* Test NULL context */
  73.         /* XXX: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */
  74.         assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, NULL) == XvMCBadContext);
  75.         /* Test invalid port */
  76.         /* XXX: Success and XvBadPort have the same value, if this call actually gets passed the validation step as of now we'll crash later */
  77.         assert(XvMCCreateContext(display, -1, surface_type_id, width, height, XVMC_DIRECT, &context) == XvBadPort);
  78.         /* Test invalid surface */
  79.         assert(XvMCCreateContext(display, port_num, -1, width, height, XVMC_DIRECT, &context) == BadMatch);
  80.         /* Test invalid flags */
  81.         assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, -1, &context) == BadValue);
  82.         /* Test huge width */
  83.         assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, height, XVMC_DIRECT, &context) == BadValue);
  84.         /* Test huge height */
  85.         assert(XvMCCreateContext(display, port_num, surface_type_id, width, 16384, XVMC_DIRECT, &context) == BadValue);
  86.         /* Test huge width & height */
  87.         assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, 16384, XVMC_DIRECT, &context) == BadValue);
  88.         /* Test valid params */
  89.         assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
  90.         /* Test context id assigned */
  91.         assert(context.context_id != 0);
  92.         /* Test surface type id assigned and correct */
  93.         assert(context.surface_type_id == surface_type_id);
  94.         /* Test width & height assigned and correct */
  95.         assert(context.width == width && context.height == height);
  96.         /* Test port assigned and correct */
  97.         assert(context.port == port_num);
  98.         /* Test flags assigned and correct */
  99.         assert(context.flags == XVMC_DIRECT);
  100.         /* Test NULL context */
  101.         assert(XvMCDestroyContext(display, NULL) == XvMCBadContext);
  102.         /* Test valid params */
  103.         assert(XvMCDestroyContext(display, &context) == Success);
  104.         /* Test awkward but valid width */
  105.         assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height, XVMC_DIRECT, &context) == Success);
  106.         assert(context.width >= width + 1);
  107.         assert(XvMCDestroyContext(display, &context) == Success);
  108.         /* Test awkward but valid height */
  109.         assert(XvMCCreateContext(display, port_num, surface_type_id, width, height + 1, XVMC_DIRECT, &context) == Success);
  110.         assert(context.height >= height + 1);
  111.         assert(XvMCDestroyContext(display, &context) == Success);
  112.         /* Test awkward but valid width & height */
  113.         assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height + 1, XVMC_DIRECT, &context) == Success);
  114.         assert(context.width >= width + 1 && context.height >= height + 1);
  115.         assert(XvMCDestroyContext(display, &context) == Success);
  116.  
  117.         XvUngrabPort(display, port_num, CurrentTime);
  118.         XCloseDisplay(display);
  119.  
  120.         return 0;
  121. }
  122.