summaryrefslogtreecommitdiff
path: root/common/xv_attribute.c
blob: 8a08d1db832ee0d99a881bbe547859e3cd934bbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <X11/extensions/Xv.h>

#include "xf86xv.h"

#include "xv_attribute.h"

static const struct xv_attr_data *xv_attr_find_attribute(
	const struct xv_attr_data *attrs, size_t n_attr, Atom attribute)
{
	while (n_attr--) {
		if (attribute == attrs->x_atom)
			return attrs;
		attrs++;
	}
	return NULL;
}

int xv_attr_SetPortAttribute(const struct xv_attr_data *attrs,
	size_t n_attr, ScrnInfoPtr pScrn, Atom attribute,
	INT32 value, pointer data)
{
	const struct xv_attr_data *attr =
		xv_attr_find_attribute(attrs, n_attr, attribute);

	if (!attr || !attr->set || !(attr->attr->flags & XvSettable))
		return BadMatch;

	if (value < attr->attr->min_value ||
	    value > attr->attr->max_value)
		return BadValue;

	return attr->set(pScrn, attr, value + attr->offset, data);
}

int xv_attr_GetPortAttribute(const struct xv_attr_data *attrs,
	size_t n_attr, ScrnInfoPtr pScrn, Atom attribute,
	INT32 *value, pointer data)
{
	const struct xv_attr_data *attr =
		xv_attr_find_attribute(attrs, n_attr, attribute);
	int ret;

	if (!attr || !attr->get || !(attr->attr->flags & XvGettable))
		return BadMatch;

	ret = attr->get(pScrn, attr, value, data);
	if (ret == Success)
		*value -= attr->offset;
	return ret;
}

#define MAKE_ATOM(a) MakeAtom(a, strlen(a), TRUE)

Bool xv_attr_init(struct xv_attr_data *attrs, size_t n_attr)
{
	if (attrs->x_atom)
		return TRUE;

	while (n_attr--) {
		attrs->x_atom = MAKE_ATOM(attrs->attr->name);
		if (attrs->x_atom == BAD_RESOURCE)
			return FALSE;
		attrs++;
	}

	return TRUE;
}