162074f44bb5944593b65d6203deae6300bead42dYounes Manton/************************************************************************** 2dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König * 362074f44bb5944593b65d6203deae6300bead42dYounes Manton * Copyright 2009 Younes Manton. 462074f44bb5944593b65d6203deae6300bead42dYounes Manton * All Rights Reserved. 5dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König * 662074f44bb5944593b65d6203deae6300bead42dYounes Manton * Permission is hereby granted, free of charge, to any person obtaining a 762074f44bb5944593b65d6203deae6300bead42dYounes Manton * copy of this software and associated documentation files (the 862074f44bb5944593b65d6203deae6300bead42dYounes Manton * "Software"), to deal in the Software without restriction, including 962074f44bb5944593b65d6203deae6300bead42dYounes Manton * without limitation the rights to use, copy, modify, merge, publish, 1062074f44bb5944593b65d6203deae6300bead42dYounes Manton * distribute, sub license, and/or sell copies of the Software, and to 1162074f44bb5944593b65d6203deae6300bead42dYounes Manton * permit persons to whom the Software is furnished to do so, subject to 1262074f44bb5944593b65d6203deae6300bead42dYounes Manton * the following conditions: 13dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König * 1462074f44bb5944593b65d6203deae6300bead42dYounes Manton * The above copyright notice and this permission notice (including the 1562074f44bb5944593b65d6203deae6300bead42dYounes Manton * next paragraph) shall be included in all copies or substantial portions 1662074f44bb5944593b65d6203deae6300bead42dYounes Manton * of the Software. 17dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König * 1862074f44bb5944593b65d6203deae6300bead42dYounes Manton * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1962074f44bb5944593b65d6203deae6300bead42dYounes Manton * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 2062074f44bb5944593b65d6203deae6300bead42dYounes Manton * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 2162074f44bb5944593b65d6203deae6300bead42dYounes Manton * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 2262074f44bb5944593b65d6203deae6300bead42dYounes Manton * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 2362074f44bb5944593b65d6203deae6300bead42dYounes Manton * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 2462074f44bb5944593b65d6203deae6300bead42dYounes Manton * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König * 2662074f44bb5944593b65d6203deae6300bead42dYounes Manton **************************************************************************/ 2762074f44bb5944593b65d6203deae6300bead42dYounes Manton 2862074f44bb5944593b65d6203deae6300bead42dYounes Manton#include <assert.h> 2962074f44bb5944593b65d6203deae6300bead42dYounes Manton#include <error.h> 3062074f44bb5944593b65d6203deae6300bead42dYounes Manton#include "testlib.h" 3162074f44bb5944593b65d6203deae6300bead42dYounes Manton 3262074f44bb5944593b65d6203deae6300bead42dYounes Mantonint main(int argc, char **argv) 3362074f44bb5944593b65d6203deae6300bead42dYounes Manton{ 3462074f44bb5944593b65d6203deae6300bead42dYounes Manton const unsigned int width = 16, height = 16; 3562074f44bb5944593b65d6203deae6300bead42dYounes Manton const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; 3662074f44bb5944593b65d6203deae6300bead42dYounes Manton 3762074f44bb5944593b65d6203deae6300bead42dYounes Manton Display *display; 3862074f44bb5944593b65d6203deae6300bead42dYounes Manton XvPortID port_num; 3962074f44bb5944593b65d6203deae6300bead42dYounes Manton int surface_type_id; 4062074f44bb5944593b65d6203deae6300bead42dYounes Manton unsigned int is_overlay, intra_unsigned; 4162074f44bb5944593b65d6203deae6300bead42dYounes Manton int colorkey; 4262074f44bb5944593b65d6203deae6300bead42dYounes Manton XvMCContext context = {0}; 4362074f44bb5944593b65d6203deae6300bead42dYounes Manton 4462074f44bb5944593b65d6203deae6300bead42dYounes Manton display = XOpenDisplay(NULL); 4562074f44bb5944593b65d6203deae6300bead42dYounes Manton 4662074f44bb5944593b65d6203deae6300bead42dYounes Manton if (!GetPort 4762074f44bb5944593b65d6203deae6300bead42dYounes Manton ( 4862074f44bb5944593b65d6203deae6300bead42dYounes Manton display, 4962074f44bb5944593b65d6203deae6300bead42dYounes Manton width, 5062074f44bb5944593b65d6203deae6300bead42dYounes Manton height, 5162074f44bb5944593b65d6203deae6300bead42dYounes Manton XVMC_CHROMA_FORMAT_420, 52dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König mc_types, 53dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König 2, 54dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König &port_num, 55dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König &surface_type_id, 56dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König &is_overlay, 57dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96Christian König &intra_unsigned 5862074f44bb5944593b65d6203deae6300bead42dYounes Manton )) 5962074f44bb5944593b65d6203deae6300bead42dYounes Manton { 6062074f44bb5944593b65d6203deae6300bead42dYounes Manton XCloseDisplay(display); 6162074f44bb5944593b65d6203deae6300bead42dYounes Manton error(1, 0, "Error, unable to find a good port.\n"); 6262074f44bb5944593b65d6203deae6300bead42dYounes Manton } 6362074f44bb5944593b65d6203deae6300bead42dYounes Manton 6462074f44bb5944593b65d6203deae6300bead42dYounes Manton if (is_overlay) 6562074f44bb5944593b65d6203deae6300bead42dYounes Manton { 6662074f44bb5944593b65d6203deae6300bead42dYounes Manton Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); 6762074f44bb5944593b65d6203deae6300bead42dYounes Manton XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); 6862074f44bb5944593b65d6203deae6300bead42dYounes Manton } 6962074f44bb5944593b65d6203deae6300bead42dYounes Manton 7062074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test NULL context */ 7162074f44bb5944593b65d6203deae6300bead42dYounes Manton /* XXX: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */ 7262074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, NULL) == XvMCBadContext); 7362074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test invalid port */ 7462074f44bb5944593b65d6203deae6300bead42dYounes Manton /* XXX: Success and XvBadPort have the same value, if this call actually gets passed the validation step as of now we'll crash later */ 7562074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, -1, surface_type_id, width, height, XVMC_DIRECT, &context) == XvBadPort); 7662074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test invalid surface */ 7762074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, port_num, -1, width, height, XVMC_DIRECT, &context) == BadMatch); 7862074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test invalid flags */ 7962074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, -1, &context) == BadValue); 8062074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test huge width */ 8162074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, height, XVMC_DIRECT, &context) == BadValue); 8262074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test huge height */ 8362074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, port_num, surface_type_id, width, 16384, XVMC_DIRECT, &context) == BadValue); 8462074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test huge width & height */ 8562074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, 16384, XVMC_DIRECT, &context) == BadValue); 8662074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test valid params */ 8762074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); 8862074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test context id assigned */ 8962074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(context.context_id != 0); 9062074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test surface type id assigned and correct */ 9162074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(context.surface_type_id == surface_type_id); 9262074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test width & height assigned and correct */ 9362074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(context.width == width && context.height == height); 9462074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test port assigned and correct */ 9562074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(context.port == port_num); 9662074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test flags assigned and correct */ 9762074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(context.flags == XVMC_DIRECT); 9862074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test NULL context */ 9962074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCDestroyContext(display, NULL) == XvMCBadContext); 10062074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test valid params */ 10162074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCDestroyContext(display, &context) == Success); 10262074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test awkward but valid width */ 10362074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height, XVMC_DIRECT, &context) == Success); 10462074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(context.width >= width + 1); 10562074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCDestroyContext(display, &context) == Success); 10662074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test awkward but valid height */ 10762074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, port_num, surface_type_id, width, height + 1, XVMC_DIRECT, &context) == Success); 10862074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(context.height >= height + 1); 10962074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCDestroyContext(display, &context) == Success); 11062074f44bb5944593b65d6203deae6300bead42dYounes Manton /* Test awkward but valid width & height */ 11162074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height + 1, XVMC_DIRECT, &context) == Success); 11262074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(context.width >= width + 1 && context.height >= height + 1); 11362074f44bb5944593b65d6203deae6300bead42dYounes Manton assert(XvMCDestroyContext(display, &context) == Success); 11462074f44bb5944593b65d6203deae6300bead42dYounes Manton 11562074f44bb5944593b65d6203deae6300bead42dYounes Manton XvUngrabPort(display, port_num, CurrentTime); 11662074f44bb5944593b65d6203deae6300bead42dYounes Manton XCloseDisplay(display); 11762074f44bb5944593b65d6203deae6300bead42dYounes Manton 11862074f44bb5944593b65d6203deae6300bead42dYounes Manton return 0; 11962074f44bb5944593b65d6203deae6300bead42dYounes Manton} 120