Merge remote branch 'upstream/gallium-0.2' into nouveau-gallium-0.2
[mesa.git] / src / libXvMC / tests / test_surface.c
1 #include <assert.h>
2 #include <error.h>
3 #include "testlib.h"
4
5 int main(int argc, char **argv)
6 {
7 const unsigned int width = 16, height = 16;
8 const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
9
10 Display *display;
11 XvPortID port_num;
12 int surface_type_id;
13 unsigned int is_overlay, intra_unsigned;
14 int colorkey;
15 XvMCContext context;
16 XvMCSurface surface = {0};
17
18 display = XOpenDisplay(NULL);
19
20 if (!GetPort
21 (
22 display,
23 width,
24 height,
25 XVMC_CHROMA_FORMAT_420,
26 mc_types,
27 2,
28 &port_num,
29 &surface_type_id,
30 &is_overlay,
31 &intra_unsigned
32 ))
33 {
34 XCloseDisplay(display);
35 error(1, 0, "Error, unable to find a good port.\n");
36 }
37
38 if (is_overlay)
39 {
40 Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
41 XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
42 }
43
44 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
45
46 /* Test NULL context */
47 assert(XvMCCreateSurface(display, NULL, &surface) == XvMCBadContext);
48 /* Test NULL surface */
49 assert(XvMCCreateSurface(display, &context, NULL) == XvMCBadSurface);
50 /* Test valid params */
51 assert(XvMCCreateSurface(display, &context, &surface) == Success);
52 /* Test surface id assigned */
53 assert(surface.surface_id != 0);
54 /* Test context id assigned and correct */
55 assert(surface.context_id == context.context_id);
56 /* Test surface type id assigned and correct */
57 assert(surface.surface_type_id == surface_type_id);
58 /* Test width & height assigned and correct */
59 assert(surface.width == width && surface.height == height);
60 /* Test valid params */
61 assert(XvMCDestroySurface(display, &surface) == Success);
62 /* Test NULL surface */
63 assert(XvMCDestroySurface(display, NULL) == XvMCBadSurface);
64
65 assert(XvMCDestroyContext(display, &context) == Success);
66
67 XvUngrabPort(display, port_num, CurrentTime);
68 XCloseDisplay(display);
69
70 return 0;
71 }
72