Merge remote branch 'upstream/gallium-0.2' into nouveau-gallium-0.2
[mesa.git] / src / libXvMC / tests / testlib.c
1 #include "testlib.h"
2 #include <stdio.h>
3
4 /*
5 void test(int pred, const char *pred_string, const char *doc_string, const char *file, unsigned int line)
6 {
7 fputs(doc_string, stderr);
8 if (!pred)
9 fprintf(stderr, " FAIL!\n\t\"%s\" at %s:%u\n", pred_string, file, line);
10 else
11 fputs(" PASS!\n", stderr);
12 }
13 */
14
15 int GetPort
16 (
17 Display *display,
18 unsigned int width,
19 unsigned int height,
20 unsigned int chroma_format,
21 const unsigned int *mc_types,
22 unsigned int num_mc_types,
23 XvPortID *port_id,
24 int *surface_type_id,
25 unsigned int *is_overlay,
26 unsigned int *intra_unsigned
27 )
28 {
29 unsigned int found_port = 0;
30 XvAdaptorInfo *adaptor_info;
31 unsigned int num_adaptors;
32 int num_types;
33 int ev_base, err_base;
34 unsigned int i, j, k, l;
35
36 if (!XvMCQueryExtension(display, &ev_base, &err_base))
37 return 0;
38 if (XvQueryAdaptors(display, XDefaultRootWindow(display), &num_adaptors, &adaptor_info) != Success)
39 return 0;
40
41 for (i = 0; i < num_adaptors && !found_port; ++i)
42 {
43 if (adaptor_info[i].type & XvImageMask)
44 {
45 XvMCSurfaceInfo *surface_info = XvMCListSurfaceTypes(display, adaptor_info[i].base_id, &num_types);
46
47 if (surface_info)
48 {
49 for (j = 0; j < num_types && !found_port; ++j)
50 {
51 if
52 (
53 surface_info[j].chroma_format == chroma_format &&
54 surface_info[j].max_width >= width &&
55 surface_info[j].max_height >= height
56 )
57 {
58 for (k = 0; k < num_mc_types && !found_port; ++k)
59 {
60 if (surface_info[j].mc_type == mc_types[k])
61 {
62 for (l = 0; l < adaptor_info[i].num_ports && !found_port; ++l)
63 {
64 if (XvGrabPort(display, adaptor_info[i].base_id + l, CurrentTime) == Success)
65 {
66 *port_id = adaptor_info[i].base_id + l;
67 *surface_type_id = surface_info[j].surface_type_id;
68 *is_overlay = surface_info[j].flags & XVMC_OVERLAID_SURFACE;
69 *intra_unsigned = surface_info[j].flags & XVMC_INTRA_UNSIGNED;
70 found_port = 1;
71 }
72 }
73 }
74 }
75 }
76 }
77
78 XFree(surface_info);
79 }
80 }
81 }
82
83 XvFreeAdaptorInfo(adaptor_info);
84
85 return found_port;
86 }
87