Path: blob/21.2-virgl/src/gallium/frontends/xvmc/tests/test_subpicture.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"3334static void PrintGUID(const char *guid)35{36int i;37printf("\tguid: ");38for (i = 0; i < 4; ++i)39printf("%c,", guid[i] == 0 ? '0' : guid[i]);40for (; i < 15; ++i)41printf("%x,", (unsigned char)guid[i]);42printf("%x\n", (unsigned int)guid[15]);43}4445static void PrintComponentOrder(const char *co)46{47int i;48printf("\tcomponent_order:\n\t ");49for (i = 0; i < 4; ++i)50printf("%c,", co[i] == 0 ? '0' : co[i]);51for (; i < 31; ++i)52printf("%x,", (unsigned int)co[i]);53printf("%x\n", (unsigned int)co[31]);54}5556int main(int argc, char **argv)57{58const unsigned int width = 16, height = 16;59const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};60const unsigned int subpic_width = 16, subpic_height = 16;6162Display *display;63XvPortID port_num;64int surface_type_id;65unsigned int is_overlay, intra_unsigned;66int colorkey;67XvMCContext context;68XvImageFormatValues *subpics;69int num_subpics;70XvMCSubpicture subpicture = {0};71int i;7273display = XOpenDisplay(NULL);7475if (!GetPort76(77display,78width,79height,80XVMC_CHROMA_FORMAT_420,81mc_types,822,83&port_num,84&surface_type_id,85&is_overlay,86&intra_unsigned87))88{89XCloseDisplay(display);90fprintf(stderr, "Error, unable to find a good port.\n");91exit(1);92}9394if (is_overlay)95{96Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);97XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);98}99100assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);101102subpics = XvMCListSubpictureTypes(display, port_num, surface_type_id, &num_subpics);103assert((subpics && num_subpics) > 0 || (!subpics && num_subpics == 0));104105for (i = 0; i < num_subpics; ++i)106{107printf("Subpicture %d:\n", i);108printf("\tid: 0x%08x\n", subpics[i].id);109printf("\ttype: %s\n", subpics[i].type == XvRGB ? "XvRGB" : (subpics[i].type == XvYUV ? "XvYUV" : "Unknown"));110printf("\tbyte_order: %s\n", subpics[i].byte_order == LSBFirst ? "LSB First" : (subpics[i].byte_order == MSBFirst ? "MSB First" : "Unknown"));111PrintGUID(subpics[i].guid);112printf("\tbpp: %u\n", subpics[i].bits_per_pixel);113printf("\tformat: %s\n", subpics[i].format == XvPacked ? "XvPacked" : (subpics[i].format == XvPlanar ? "XvPlanar" : "Unknown"));114printf("\tnum_planes: %u\n", subpics[i].num_planes);115116if (subpics[i].type == XvRGB)117{118printf("\tdepth: %u\n", subpics[i].depth);119printf("\tred_mask: 0x%08x\n", subpics[i].red_mask);120printf("\tgreen_mask: 0x%08x\n", subpics[i].green_mask);121printf("\tblue_mask: 0x%08x\n", subpics[i].blue_mask);122}123else if (subpics[i].type == XvYUV)124{125printf("\ty_sample_bits: %u\n", subpics[i].y_sample_bits);126printf("\tu_sample_bits: %u\n", subpics[i].u_sample_bits);127printf("\tv_sample_bits: %u\n", subpics[i].v_sample_bits);128printf("\thorz_y_period: %u\n", subpics[i].horz_y_period);129printf("\thorz_u_period: %u\n", subpics[i].horz_u_period);130printf("\thorz_v_period: %u\n", subpics[i].horz_v_period);131printf("\tvert_y_period: %u\n", subpics[i].vert_y_period);132printf("\tvert_u_period: %u\n", subpics[i].vert_u_period);133printf("\tvert_v_period: %u\n", subpics[i].vert_v_period);134}135PrintComponentOrder(subpics[i].component_order);136printf("\tscanline_order: %s\n", subpics[i].scanline_order == XvTopToBottom ? "XvTopToBottom" : (subpics[i].scanline_order == XvBottomToTop ? "XvBottomToTop" : "Unknown"));137}138139if (num_subpics == 0)140{141printf("Subpictures not supported, nothing to test.\n");142return 0;143}144145/* Test NULL context */146assert(XvMCCreateSubpicture(display, NULL, &subpicture, subpic_width, subpic_height, subpics[0].id) == XvMCBadContext);147/* Test NULL subpicture */148assert(XvMCCreateSubpicture(display, &context, NULL, subpic_width, subpic_height, subpics[0].id) == XvMCBadSubpicture);149/* Test invalid subpicture */150assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, -1) == BadMatch);151/* Test huge width */152assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, subpic_height, subpics[0].id) == BadValue);153/* Test huge height */154assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, 16384, subpics[0].id) == BadValue);155/* Test huge width & height */156assert(XvMCCreateSubpicture(display, &context, &subpicture, 16384, 16384, subpics[0].id) == BadValue);157for (i = 0; i < num_subpics; ++i)158{159/* Test valid params */160assert(XvMCCreateSubpicture(display, &context, &subpicture, subpic_width, subpic_height, subpics[i].id) == Success);161/* Test subpicture id assigned */162assert(subpicture.subpicture_id != 0);163/* Test context id assigned and correct */164assert(subpicture.context_id == context.context_id);165/* Test subpicture type id assigned and correct */166assert(subpicture.xvimage_id == subpics[i].id);167/* Test width & height assigned and correct */168assert(subpicture.width == width && subpicture.height == height);169if (subpics[i].type == XvRGB)170/* Test no palette support */171assert(subpicture.num_palette_entries == 0 && subpicture.entry_bytes == 0);172else173/* Test palette support */174assert(subpicture.num_palette_entries == 16 && subpicture.entry_bytes == 4);175/* Test valid params */176assert(XvMCDestroySubpicture(display, &subpicture) == Success);177}178/* Test NULL surface */179assert(XvMCDestroySubpicture(display, NULL) == XvMCBadSubpicture);180181assert(XvMCDestroyContext(display, &context) == Success);182183free(subpics);184XvUngrabPort(display, port_num, CurrentTime);185XCloseDisplay(display);186187return 0;188}189190191