test_subpicture.c revision dcf8ee7d6ac89bb2a9d608618a51604a3c78fe96
15f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer/************************************************************************** 25f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * 35f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * Copyright 2009 Younes Manton. 45f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * All Rights Reserved. 50bc735ffcfb223c0186419547abaa5c84482663eChris Lattner * 60bc735ffcfb223c0186419547abaa5c84482663eChris Lattner * Permission is hereby granted, free of charge, to any person obtaining a 75f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * copy of this software and associated documentation files (the 85f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * "Software"), to deal in the Software without restriction, including 95f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * without limitation the rights to use, copy, modify, merge, publish, 105f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * distribute, sub license, and/or sell copies of the Software, and to 115f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * permit persons to whom the Software is furnished to do so, subject to 125f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * the following conditions: 135f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * 145f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer * The above copyright notice and this permission notice (including the 15bdc601b196c48d4cd56a5ceb45d41ae4e87371abKen Dyck * next paragraph) shall be included in all copies or substantial portions 1649aa7ff1245abd03e6e998e01302df31e4c6f8f6Argyrios Kyrtzidis * of the Software. 17980e508ca70d6de75d2abfd96b4681fc98bb2698Steve Naroff * 18aaba5e346dffdbad5d1c42765a89e4a7afb0da67Douglas Gregor * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19b17166c8077cd900cca83a895c43b30ea6660598Argyrios Kyrtzidis * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21ea1471e0e967548c596a71469702f8846dbaf3c0John McCall * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 222cf2634ffdb4f7c8d46cef3f8e60a55993f1c57aDouglas Gregor * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 237b90340c9c7d07aef4e301e72b5e8a30d5f4f0c8Argyrios Kyrtzidis * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 2419cc4abea06a9b49e0e16a50d335c064cd723572Anders Carlsson * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 251b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner * 26a9376d470ccb0eac74fe09a6b2a18a890f1d17c4Chris Lattner **************************************************************************/ 275f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer 28f5942a44880be26878592eb052b737579349411eBenjamin Kramer#include <assert.h> 2985f9bceab1542aafff012d4d28e998f4ba16e362Anders Carlsson#include <error.h> 306fe7c8aa8c7546743ecd0ac0138c2cf5d8155386Nate Begeman#include <stdio.h> 31f5942a44880be26878592eb052b737579349411eBenjamin Kramer#include "testlib.h" 32071cc7deffad608165b1ddd5263e8bf181861520Charles Davis 3329445a0542d128cd7ee587ee52229670b9b54a12Anders Carlssonstatic void PrintGUID(const char *guid) 345f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer{ 355f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer int i; 361827403a7138946305c0058f262e02b595cf882fDouglas Gregor printf("\tguid: "); 371827403a7138946305c0058f262e02b595cf882fDouglas Gregor for (i = 0; i < 4; ++i) 38225843186e3972ce798d3de00f86da9008b15a0eDouglas Gregor printf("%C,", guid[i] == 0 ? '0' : guid[i]); 39225843186e3972ce798d3de00f86da9008b15a0eDouglas Gregor for (; i < 15; ++i) 40a376d10acfacf19d6dfa41069f7929739a18dd7aDouglas Gregor printf("%x,", (unsigned char)guid[i]); 41a376d10acfacf19d6dfa41069f7929739a18dd7aDouglas Gregor printf("%x\n", (unsigned int)guid[15]); 424923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregor} 434923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregor 444923aa25eb39d64106a5817c02d560a3aecf8b2cDouglas Gregorstatic void PrintComponentOrder(const char *co) 455f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer{ 465f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer int i; 475f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer printf("\tcomponent_order:\n\t "); 485f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer for (i = 0; i < 4; ++i) 493e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("%C,", co[i] == 0 ? '0' : co[i]); 503e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor for (; i < 31; ++i) 513e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("%x,", (unsigned int)co[i]); 523e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("%x\n", (unsigned int)co[31]); 533e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor} 5461c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor 553e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregorint main(int argc, char **argv) 563e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor{ 573e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor const unsigned int width = 16, height = 16; 583e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2}; 593e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor const unsigned int subpic_width = 16, subpic_height = 16; 603e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 613e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Display *display; 623e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor XvPortID port_num; 633e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor int surface_type_id; 643e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor unsigned int is_overlay, intra_unsigned; 653e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor int colorkey; 663e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor XvMCContext context; 673e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor XvImageFormatValues *subpics; 683e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor int num_subpics; 6961c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor XvMCSubpicture subpicture = {0}; 703e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor int i; 713e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 723e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor display = XOpenDisplay(NULL); 733e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 743e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (!GetPort 753e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor ( 763e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor display, 773e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor width, 783e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor height, 793e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor XVMC_CHROMA_FORMAT_420, 803e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor mc_types, 813e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 2, 824ba2a17694148e16eaa8d3917f657ffcd3667be4Jay Foad &port_num, 833e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor &surface_type_id, 843e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor &is_overlay, 853e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor &intra_unsigned 863e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor )) 873e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor { 883e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor XCloseDisplay(display); 893e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor error(1, 0, "Error, unable to find a good port.\n"); 903e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 913e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 923e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (is_overlay) 933e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor { 943e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0); 953e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey); 963e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 973e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 983e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success); 993e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 1003e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor subpics = XvMCListSubpictureTypes(display, port_num, surface_type_id, &num_subpics); 1013e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor assert((subpics && num_subpics) > 0 || (!subpics && num_subpics == 0)); 1023e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 1033e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor for (i = 0; i < num_subpics; ++i) 1043e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor { 1053e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("Subpicture %d:\n", i); 1063e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tid: 0x%08x\n", subpics[i].id); 1073e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\ttype: %s\n", subpics[i].type == XvRGB ? "XvRGB" : (subpics[i].type == XvYUV ? "XvYUV" : "Unknown")); 1083e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tbyte_order: %s\n", subpics[i].byte_order == LSBFirst ? "LSB First" : (subpics[i].byte_order == MSBFirst ? "MSB First" : "Unknown")); 1093e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor PrintGUID(subpics[i].guid); 1103e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tbpp: %u\n", subpics[i].bits_per_pixel); 1113e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tformat: %s\n", subpics[i].format == XvPacked ? "XvPacked" : (subpics[i].format == XvPlanar ? "XvPlanar" : "Unknown")); 11210738d36b150aa65206890c1c845cdba076e4200Douglas Gregor printf("\tnum_planes: %u\n", subpics[i].num_planes); 1133e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 1143e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (subpics[i].type == XvRGB) 1153e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor { 1163e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tdepth: %u\n", subpics[i].depth); 1173e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tred_mask: 0x%08x\n", subpics[i].red_mask); 1183e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tgreen_mask: 0x%08x\n", subpics[i].green_mask); 1193e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tblue_mask: 0x%08x\n", subpics[i].blue_mask); 1203e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 1213e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor else if (subpics[i].type == XvYUV) 12261c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor { 12361c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor printf("\ty_sample_bits: %u\n", subpics[i].y_sample_bits); 12461c4d28e36cd3f1be392cb77f07436d1fa6b0f9fDouglas Gregor printf("\tu_sample_bits: %u\n", subpics[i].u_sample_bits); 1253e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tv_sample_bits: %u\n", subpics[i].v_sample_bits); 1263e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\thorz_y_period: %u\n", subpics[i].horz_y_period); 1273e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\thorz_u_period: %u\n", subpics[i].horz_u_period); 1283e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\thorz_v_period: %u\n", subpics[i].horz_v_period); 1293e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tvert_y_period: %u\n", subpics[i].vert_y_period); 1303e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tvert_u_period: %u\n", subpics[i].vert_u_period); 1313e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tvert_v_period: %u\n", subpics[i].vert_v_period); 1323e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 1333e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor PrintComponentOrder(subpics[i].component_order); 1343e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("\tscanline_order: %s\n", subpics[i].scanline_order == XvTopToBottom ? "XvTopToBottom" : (subpics[i].scanline_order == XvBottomToTop ? "XvBottomToTop" : "Unknown")); 1353e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 1363e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor 1373e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor if (num_subpics == 0) 1383e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor { 1393e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor printf("Subpictures not supported, nothing to test.\n"); 1403e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor return 0; 1413e1274f2b99cb99c03cc8e2c6517c37d330b597aDouglas Gregor } 142071cc7deffad608165b1ddd5263e8bf181861520Charles Davis 143ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall /* Test NULL context */ 144ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall assert(XvMCCreateSubpicture(display, NULL, &subpicture, subpic_width, subpic_height, subpics[0].id) == XvMCBadContext); 14520cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis /* Test NULL subpicture */ 146ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall assert(XvMCCreateSubpicture(display, &context, NULL, subpic_width, subpic_height, subpics[0].id) == XvMCBadSubpicture); 147ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall /* Test invalid subpicture */ 148ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, -1) == BadMatch); 149071cc7deffad608165b1ddd5263e8bf181861520Charles Davis /* Test huge width */ 15020cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, subpic_height, subpics[0].id) == BadValue); 15120cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis /* Test huge height */ 15220cf717034ba1f20fc47c025ecb72ed9b631ad13Charles Davis assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, 16384, subpics[0].id) == BadValue); 153ee79a4c30e5d1c5285551c9a25b8ec6d45d46aa7John McCall /* Test huge width & height */ 154071cc7deffad608165b1ddd5263e8bf181861520Charles Davis assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, 16384, subpics[0].id) == BadValue); 155071cc7deffad608165b1ddd5263e8bf181861520Charles Davis for (i = 0; i < num_subpics; ++i) 15661710854be2b098428aff5316e64bd34b30fbcb7Chris Lattner { 157444be7366d0a1e172c0290a1ea54c1cb16b5947cDaniel Dunbar /* Test valid params */ 158e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, subpics[i].id) == Success); 1591b63e4f732dbc73d90abf886b4d21f8e3a165f6dChris Lattner /* Test subpicture id assigned */ 16063fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor assert(subpicture.subpicture_id != 0); 161ef99001908e799c388f1363b1e607dad5f5b57d3John McCall /* Test context id assigned and correct */ 162ef99001908e799c388f1363b1e607dad5f5b57d3John McCall assert(subpicture.context_id == context.context_id); 163006113841bdae1edb77aef75ba1ffdf2e55a3094Argyrios Kyrtzidis /* Test subpicture type id assigned and correct */ 164006113841bdae1edb77aef75ba1ffdf2e55a3094Argyrios Kyrtzidis assert(subpicture.xvimage_id == subpics[i].id); 165782fa308a765aeac2acb39c4e697c937ec21185bMike Stump /* Test width & height assigned and correct */ 166083c25eea14bb4cc4ecc3ec763c60e2e609e22bdMike Stump assert(subpicture.width == width && subpicture.height == height); 167bf1a028246d884a540aeafa38e89be59a269b072John McCall /* Test no palette support */ 168071cc7deffad608165b1ddd5263e8bf181861520Charles Davis assert(subpicture.num_palette_entries == 0 && subpicture.entry_bytes == 0); 1692e22253e03e175144aeb9d13350a12fd83f858beDouglas Gregor /* Test valid params */ 170ac9590effa90406767a544005ed1de52e258306bTed Kremenek assert(XvMCDestroySubpicture(display, &subpicture) == Success); 171ac9590effa90406767a544005ed1de52e258306bTed Kremenek } 1729a44b5f5593bd8a385d06b07c564795f643ec8daArgyrios Kyrtzidis /* Test NULL surface */ 173f057bf78a69d37ee511430c88852a85eea19ad15Ted Kremenek assert(XvMCDestroySubpicture(display, NULL) == XvMCBadSubpicture); 174f057bf78a69d37ee511430c88852a85eea19ad15Ted Kremenek 1750f436560640a1cff5b6d96f80f540770f139453fDavid Chisnall assert(XvMCDestroyContext(display, &context) == Success); 1760f436560640a1cff5b6d96f80f540770f139453fDavid Chisnall 17763fe86bee66fc145942c56b2cc564ea0b9b9ea12Douglas Gregor XFree(subpics); 1781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump XvUngrabPort(display, port_num, CurrentTime); 179e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar XCloseDisplay(display); 18014108da7f7fc059772711e4ffee1322a27b152a7Steve Naroff 181e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar return 0; 182e91593ef084479340582b2ba177b44be50a717b7Daniel Dunbar} 1835f016e2cb5d11daeb237544de1c5d59f20fe1a6eReid Spencer