g3dvl: Move XvMC under the Xorg state tracker.
[mesa.git] / src / gallium / state_trackers / xorg / xvmc / tests / test_blocks.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 min_required_blocks = 1, min_required_macroblocks = 1;
9 const unsigned int mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
10
11 Display *display;
12 XvPortID port_num;
13 int surface_type_id;
14 unsigned int is_overlay, intra_unsigned;
15 int colorkey;
16 XvMCContext context;
17 XvMCSurface surface;
18 XvMCBlockArray blocks = {0};
19 XvMCMacroBlockArray macroblocks = {0};
20
21 display = XOpenDisplay(NULL);
22
23 if (!GetPort
24 (
25 display,
26 width,
27 height,
28 XVMC_CHROMA_FORMAT_420,
29 mc_types,
30 2,
31 &port_num,
32 &surface_type_id,
33 &is_overlay,
34 &intra_unsigned
35 ))
36 {
37 XCloseDisplay(display);
38 error(1, 0, "Error, unable to find a good port.\n");
39 }
40
41 if (is_overlay)
42 {
43 Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
44 XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
45 }
46
47 assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
48 assert(XvMCCreateSurface(display, &context, &surface) == Success);
49
50 /* Test NULL context */
51 assert(XvMCCreateBlocks(display, NULL, 1, &blocks) == XvMCBadContext);
52 /* Test 0 blocks */
53 assert(XvMCCreateBlocks(display, &context, 0, &blocks) == BadValue);
54 /* Test valid params */
55 assert(XvMCCreateBlocks(display, &context, min_required_blocks, &blocks) == Success);
56 /* Test context id assigned and correct */
57 assert(blocks.context_id == context.context_id);
58 /* Test number of blocks assigned and correct */
59 assert(blocks.num_blocks == min_required_blocks);
60 /* Test block pointer valid */
61 assert(blocks.blocks != NULL);
62 /* Test NULL context */
63 assert(XvMCCreateMacroBlocks(display, NULL, 1, &macroblocks) == XvMCBadContext);
64 /* Test 0 macroblocks */
65 assert(XvMCCreateMacroBlocks(display, &context, 0, &macroblocks) == BadValue);
66 /* Test valid params */
67 assert(XvMCCreateMacroBlocks(display, &context, min_required_macroblocks, &macroblocks) == Success);
68 /* Test context id assigned and correct */
69 assert(macroblocks.context_id == context.context_id);
70 /* Test macroblock pointer valid */
71 assert(macroblocks.macro_blocks != NULL);
72 /* Test valid params */
73 assert(XvMCDestroyMacroBlocks(display, &macroblocks) == Success);
74 /* Test valid params */
75 assert(XvMCDestroyBlocks(display, &blocks) == Success);
76
77 assert(XvMCDestroySurface(display, &surface) == Success);
78 assert(XvMCDestroyContext(display, &context) == Success);
79
80 XvUngrabPort(display, port_num, CurrentTime);
81 XCloseDisplay(display);
82
83 return 0;
84 }