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