Path: blob/21.2-virgl/src/gallium/frontends/xvmc/tests/test_blocks.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 min_required_blocks = 1, min_required_macroblocks = 1;38const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};3940Display *display;41XvPortID port_num;42int surface_type_id;43unsigned int is_overlay, intra_unsigned;44int colorkey;45XvMCContext context;46XvMCSurface surface;47XvMCBlockArray blocks = {0};48XvMCMacroBlockArray macroblocks = {0};4950display = XOpenDisplay(NULL);5152if (!GetPort53(54display,55width,56height,57XVMC_CHROMA_FORMAT_420,58mc_types,592,60&port_num,61&surface_type_id,62&is_overlay,63&intra_unsigned64))65{66XCloseDisplay(display);67fprintf(stderr, "Error, unable to find a good port.\n");68exit(1);69}7071if (is_overlay)72{73Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);74XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);75}7677assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);78assert(XvMCCreateSurface(display, &context, &surface) == Success);7980/* Test NULL context */81assert(XvMCCreateBlocks(display, NULL, 1, &blocks) == XvMCBadContext);82/* Test 0 blocks */83assert(XvMCCreateBlocks(display, &context, 0, &blocks) == BadValue);84/* Test valid params */85assert(XvMCCreateBlocks(display, &context, min_required_blocks, &blocks) == Success);86/* Test context id assigned and correct */87assert(blocks.context_id == context.context_id);88/* Test number of blocks assigned and correct */89assert(blocks.num_blocks == min_required_blocks);90/* Test block pointer valid */91assert(blocks.blocks != NULL);92/* Test NULL context */93assert(XvMCCreateMacroBlocks(display, NULL, 1, ¯oblocks) == XvMCBadContext);94/* Test 0 macroblocks */95assert(XvMCCreateMacroBlocks(display, &context, 0, ¯oblocks) == BadValue);96/* Test valid params */97assert(XvMCCreateMacroBlocks(display, &context, min_required_macroblocks, ¯oblocks) == Success);98/* Test context id assigned and correct */99assert(macroblocks.context_id == context.context_id);100/* Test macroblock pointer valid */101assert(macroblocks.macro_blocks != NULL);102/* Test valid params */103assert(XvMCDestroyMacroBlocks(display, ¯oblocks) == Success);104/* Test valid params */105assert(XvMCDestroyBlocks(display, &blocks) == Success);106107assert(XvMCDestroySurface(display, &surface) == Success);108assert(XvMCDestroyContext(display, &context) == Success);109110XvUngrabPort(display, port_num, CurrentTime);111XCloseDisplay(display);112113return 0;114}115116117