test_blocks.c revision dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96
1fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek/************************************************************************** 2fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * 3fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * Copyright 2009 Younes Manton. 4fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * All Rights Reserved. 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner * 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner * Permission is hereby granted, free of charge, to any person obtaining a 7fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * copy of this software and associated documentation files (the 8fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * "Software"), to deal in the Software without restriction, including 9fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * without limitation the rights to use, copy, modify, merge, publish, 10fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * distribute, sub license, and/or sell copies of the Software, and to 11fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * permit persons to whom the Software is furnished to do so, subject to 12fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * the following conditions: 13fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * 14fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * The above copyright notice and this permission notice (including the 15cd881d534517f09a2fae10445f9b865f49ccc6c8Ted Kremenek * next paragraph) shall be included in all copies or substantial portions 16cd881d534517f09a2fae10445f9b865f49ccc6c8Ted Kremenek * of the Software. 17cd881d534517f09a2fae10445f9b865f49ccc6c8Ted Kremenek * 18852274d4257134906995cb252fb3dfd2d71deae8Ted Kremenek * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 197dba8607e59096014b7139ff20ef00870041d518Ted Kremenek * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20ce1eb34bbea1e0408f1952776d7d52ccde1bd275Ted Kremenek * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21852274d4257134906995cb252fb3dfd2d71deae8Ted Kremenek * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 22ee82d9bdc5025b82de8ce2a4ad4685e0a8b79da9Ted Kremenek * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23079bd72439448b78629a28da6b1f8abe2cdeaf4dMike Stump * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24c1581a0d64b0ee4f822ed2fca4442a111d03569aHartmut Kaiser * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek * 26e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner **************************************************************************/ 27e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner 28e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner#include <assert.h> 292a4cd498ff9b2b126de3e370b768ab307c221ab8Marcin Swiderski#include <error.h> 30fddd51853f8ccaa1df2476376e6fd74d2f315c73Ted Kremenek#include "testlib.h" 31b978a441c7d8bf59e7fede938e1f3b672573b443Mike Stump 3242a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenekint main(int argc, char **argv) 3363f5887f316fb52d243fcbb3631c039de6c4b993Ted Kremenek{ 347c625d8ffc20b92fff9e1690cd2484fcb6498183Marcin Swiderski const unsigned int width = 16, height = 16; 351cff132e48e0ccc253c34e5a2fb12718bd4e7d2eMarcin Swiderski const unsigned int min_required_blocks = 1, min_required_macroblocks = 1; 361cff132e48e0ccc253c34e5a2fb12718bd4e7d2eMarcin Swiderski const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; 377c625d8ffc20b92fff9e1690cd2484fcb6498183Marcin Swiderski 388599e7677e067fd01d3b2ee4c0875747d367fd8eMarcin Swiderski Display *display; 3942a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek XvPortID port_num; 4042a509f6a4f71bb805cc4abbb26722a34dffdddeTed Kremenek int surface_type_id; 41e4f2142d00fa5fdb580c4e2413da91882d955381Chris Lattner unsigned int is_overlay, intra_unsigned; 42e5af3ce53ec58995b09381ba645ab2117a46647bMike Stump int colorkey; 43e5af3ce53ec58995b09381ba645ab2117a46647bMike Stump XvMCContext context; 44852274d4257134906995cb252fb3dfd2d71deae8Ted Kremenek XvMCSurface surface; 45852274d4257134906995cb252fb3dfd2d71deae8Ted Kremenek XvMCBlockArray blocks = {0}; 46852274d4257134906995cb252fb3dfd2d71deae8Ted Kremenek XvMCMacroBlockArray macroblocks = {0}; 47b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu 48b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu display = XOpenDisplay(NULL); 49b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu 50b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu if (!GetPort 51b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu ( 52b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu display, 53b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu width, 54b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu height, 55b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu XVMC_CHROMA_FORMAT_420, 56b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu mc_types, 57b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu 2, 58b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu &port_num, 59b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu &surface_type_id, 60b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu &is_overlay, 61b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu &intra_unsigned 62b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu )) 63b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu { 64b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu XCloseDisplay(display); 65b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu error(1, 0, "Error, unable to find a good port.\n"); 66b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu } 671cff132e48e0ccc253c34e5a2fb12718bd4e7d2eMarcin Swiderski 681cff132e48e0ccc253c34e5a2fb12718bd4e7d2eMarcin Swiderski if (is_overlay) 691cff132e48e0ccc253c34e5a2fb12718bd4e7d2eMarcin Swiderski { 701cff132e48e0ccc253c34e5a2fb12718bd4e7d2eMarcin Swiderski Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); 71b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); 72b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu } 73b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu 74b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); 75b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCCreateSurface(display, &context, &surface) == Success); 76b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu 77b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test NULL context */ 78b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCCreateBlocks(display, NULL, 1, &blocks) == XvMCBadContext); 79b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test 0 blocks */ 80b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCCreateBlocks(display, &context, 0, &blocks) == BadValue); 81b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test valid params */ 82b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCCreateBlocks(display, &context, min_required_blocks, &blocks) == Success); 83b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test context id assigned and correct */ 84b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(blocks.context_id == context.context_id); 85b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test number of blocks assigned and correct */ 86b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(blocks.num_blocks == min_required_blocks); 87b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test block pointer valid */ 88b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(blocks.blocks != NULL); 89b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test NULL context */ 90b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCCreateMacroBlocks(display, NULL, 1, ¯oblocks) == XvMCBadContext); 91b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test 0 macroblocks */ 92b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCCreateMacroBlocks(display, &context, 0, ¯oblocks) == BadValue); 93b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test valid params */ 94b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCCreateMacroBlocks(display, &context, min_required_macroblocks, ¯oblocks) == Success); 95b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test context id assigned and correct */ 96b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(macroblocks.context_id == context.context_id); 97b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test macroblock pointer valid */ 98b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(macroblocks.macro_blocks != NULL); 99b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu /* Test valid params */ 100b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCDestroyMacroBlocks(display, ¯oblocks) == Success); 101852274d4257134906995cb252fb3dfd2d71deae8Ted Kremenek /* Test valid params */ 102b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCDestroyBlocks(display, &blocks) == Success); 103b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu 104b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCDestroySurface(display, &surface) == Success); 105b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu assert(XvMCDestroyContext(display, &context) == Success); 106b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu 107b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu XvUngrabPort(display, port_num, CurrentTime); 108b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu XCloseDisplay(display); 109b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu 110b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu return 0; 111b36cd3e1757fb4fcd9509f35558c847b04bef35fZhongxing Xu} 1121cff132e48e0ccc253c34e5a2fb12718bd4e7d2eMarcin Swiderski