Path: blob/21.2-virgl/src/gallium/frontends/xvmc/tests/testlib.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#include "testlib.h"28#include <stdio.h>29#include <stdlib.h>3031/*32void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line)33{34fputs(doc_string, stderr);35if (!pred)36fprintf(stderr, " FAIL!\n\t\"%s\" at %s:%u\n", pred_string, file, line);37else38fputs(" PASS!\n", stderr);39}40*/4142int GetPort43(44Display *display,45unsigned int width,46unsigned int height,47unsigned int chroma_format,48const unsigned int *mc_types,49unsigned int num_mc_types,50XvPortID *port_id,51int *surface_type_id,52unsigned int *is_overlay,53unsigned int *intra_unsigned54)55{56unsigned int found_port = 0;57XvAdaptorInfo *adaptor_info;58unsigned int num_adaptors;59int num_types;60int ev_base, err_base;61unsigned int i, j, k, l;6263if (!XvMCQueryExtension(display, &ev_base, &err_base))64return 0;65if (XvQueryAdaptors(display, XDefaultRootWindow(display), &num_adaptors, &adaptor_info) != Success)66return 0;6768for (i = 0; i < num_adaptors && !found_port; ++i)69{70if (adaptor_info[i].type & XvImageMask)71{72XvMCSurfaceInfo *surface_info = XvMCListSurfaceTypes(display, adaptor_info[i].base_id, &num_types);7374if (surface_info)75{76for (j = 0; j < num_types && !found_port; ++j)77{78if79(80surface_info[j].chroma_format == chroma_format &&81surface_info[j].max_width >= width &&82surface_info[j].max_height >= height83)84{85for (k = 0; k < num_mc_types && !found_port; ++k)86{87if ((surface_info[j].mc_type & mc_types[k]) == mc_types[k])88{89for (l = 0; l < adaptor_info[i].num_ports && !found_port; ++l)90{91if (XvGrabPort(display, adaptor_info[i].base_id + l, CurrentTime) == Success)92{93*port_id = adaptor_info[i].base_id + l;94*surface_type_id = surface_info[j].surface_type_id;95*is_overlay = surface_info[j].flags & XVMC_OVERLAID_SURFACE;96*intra_unsigned = surface_info[j].flags & XVMC_INTRA_UNSIGNED;97found_port = 1;98}99}100}101}102}103}104105free(surface_info);106}107}108}109110XvFreeAdaptorInfo(adaptor_info);111112return found_port;113}114115unsigned int align(unsigned int value, unsigned int alignment)116{117return (value + alignment - 1) & ~(alignment - 1);118}119120/* From the glibc manual */121int timeval_subtract(struct timeval *result, struct timeval *x, struct timeval *y)122{123/* Perform the carry for the later subtraction by updating y. */124if (x->tv_usec < y->tv_usec)125{126int nsec = (y->tv_usec - x->tv_usec) / 1000000 + 1;127y->tv_usec -= 1000000 * nsec;128y->tv_sec += nsec;129}130if (x->tv_usec - y->tv_usec > 1000000)131{132int nsec = (x->tv_usec - y->tv_usec) / 1000000;133y->tv_usec += 1000000 * nsec;134y->tv_sec -= nsec;135}136137/*138* Compute the time remaining to wait.139* tv_usec is certainly positive.140*/141result->tv_sec = x->tv_sec - y->tv_sec;142result->tv_usec = x->tv_usec - y->tv_usec;143144/* Return 1 if result is negative. */145return x->tv_sec < y->tv_sec;146}147148149