1f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org/**************************************************************************
2f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
3f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Copyright 2009 Younes Manton.
4f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * All Rights Reserved.
5f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
6f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * Permission is hereby granted, free of charge, to any person obtaining a
7f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * copy of this software and associated documentation files (the
8f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * "Software"), to deal in the Software without restriction, including
9f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * without limitation the rights to use, copy, modify, merge, publish,
10f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * distribute, sub license, and/or sell copies of the Software, and to
11f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * permit persons to whom the Software is furnished to do so, subject to
12f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * the following conditions:
13f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
14f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * The above copyright notice and this permission notice (including the
15f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * next paragraph) shall be included in all copies or substantial portions
16f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * of the Software.
17f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
18f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org *
26f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org **************************************************************************/
27f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
28f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <assert.h>
29f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include <error.h>
30f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org#include "testlib.h"
31f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
32f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.orgint main(int argc, char **argv)
33f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org{
34f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	const unsigned int	width = 16, height = 16;
35f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	const unsigned int	mc_types[2] = {XVMC_MOCOMP | XVMC_MPEG_2, XVMC_IDCT | XVMC_MPEG_2};
36f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
37f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	Display			*display;
38f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	XvPortID		port_num;
39f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	int			surface_type_id;
40f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	unsigned int		is_overlay, intra_unsigned;
41f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	int			colorkey;
42f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	XvMCContext		context = {0};
43f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
44f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	display = XOpenDisplay(NULL);
45f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
46f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	if (!GetPort
47f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	(
48f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		display,
49f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		width,
50f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		height,
51f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		XVMC_CHROMA_FORMAT_420,
52f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		mc_types,
53f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		2,
54f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		&port_num,
55f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		&surface_type_id,
56f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		&is_overlay,
57f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		&intra_unsigned
58f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	))
59f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	{
60f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		XCloseDisplay(display);
61f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		error(1, 0, "Error, unable to find a good port.\n");
62f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	}
63f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
64f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	if (is_overlay)
65f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	{
66f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		Atom xv_colorkey = XInternAtom(display, "XV_COLORKEY", 0);
67f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org		XvGetPortAttribute(display, port_num, xv_colorkey, &colorkey);
68f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	}
69f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
70f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test NULL context */
71f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* XXX: XvMCBadContext not a valid return for XvMCCreateContext in the XvMC API, but openChrome driver returns it */
72f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, NULL) == XvMCBadContext);
73f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test invalid port */
74f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* XXX: Success and XvBadPort have the same value, if this call actually gets passed the validation step as of now we'll crash later */
75f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, -1, surface_type_id, width, height, XVMC_DIRECT, &context) == XvBadPort);
76f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test invalid surface */
77f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, port_num, -1, width, height, XVMC_DIRECT, &context) == BadMatch);
78f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test invalid flags */
79f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, -1, &context) == BadValue);
80f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test huge width */
81f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, height, XVMC_DIRECT, &context) == BadValue);
82f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test huge height */
83f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, port_num, surface_type_id, width, 16384, XVMC_DIRECT, &context) == BadValue);
84f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test huge width & height */
85f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, port_num, surface_type_id, 16384, 16384, XVMC_DIRECT, &context) == BadValue);
86f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test valid params */
87f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, port_num, surface_type_id, width, height, XVMC_DIRECT, &context) == Success);
88f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test context id assigned */
89f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(context.context_id != 0);
90f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test surface type id assigned and correct */
91f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(context.surface_type_id == surface_type_id);
92f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test width & height assigned and correct */
93f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(context.width == width && context.height == height);
94f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test port assigned and correct */
95f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(context.port == port_num);
96f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test flags assigned and correct */
97f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(context.flags == XVMC_DIRECT);
98f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test NULL context */
99f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCDestroyContext(display, NULL) == XvMCBadContext);
100f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test valid params */
101f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCDestroyContext(display, &context) == Success);
102f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test awkward but valid width */
103f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height, XVMC_DIRECT, &context) == Success);
104f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(context.width >= width + 1);
105f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCDestroyContext(display, &context) == Success);
106f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test awkward but valid height */
107f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, port_num, surface_type_id, width, height + 1, XVMC_DIRECT, &context) == Success);
108f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(context.height >= height + 1);
109f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCDestroyContext(display, &context) == Success);
110f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	/* Test awkward but valid width & height */
111f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCCreateContext(display, port_num, surface_type_id, width + 1, height + 1, XVMC_DIRECT, &context) == Success);
112f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(context.width >= width + 1 && context.height >= height + 1);
113f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	assert(XvMCDestroyContext(display, &context) == Success);
114f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
115f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	XvUngrabPort(display, port_num, CurrentTime);
116f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	XCloseDisplay(display);
117f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org
118f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org	return 0;
119f2ba7591b1407a7ee9209f842c50696914dc2dedkbr@chromium.org}
120