1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif
4
5#include <xorg-server.h>
6#include <xorgVersion.h>
7#include <xf86Parser.h>
8
9#include "intel_options.h"
10
11const OptionInfoRec intel_options[] = {
12	{OPTION_ACCEL_ENABLE,	"Accel",	OPTV_BOOLEAN,	{0},	0},
13	{OPTION_ACCEL_METHOD,	"AccelMethod",	OPTV_STRING,	{0},	0},
14	{OPTION_BACKLIGHT,	"Backlight",	OPTV_STRING,	{0},	0},
15	{OPTION_EDID,		"CustomEDID",	OPTV_STRING,	{0},	0},
16	{OPTION_DRI,		"DRI",		OPTV_STRING,	{0},	0},
17	{OPTION_PRESENT,	"Present",	OPTV_BOOLEAN,	{0},	1},
18	{OPTION_COLOR_KEY,	"ColorKey",	OPTV_INTEGER,	{0},	0},
19	{OPTION_VIDEO_KEY,	"VideoKey",	OPTV_INTEGER,	{0},	0},
20	{OPTION_TILING_2D,	"Tiling",	OPTV_BOOLEAN,	{0},	1},
21	{OPTION_TILING_FB,	"LinearFramebuffer",	OPTV_BOOLEAN,	{0},	0},
22	{OPTION_ROTATION,	"HWRotation",	OPTV_BOOLEAN,	{0},	1},
23	{OPTION_VSYNC,		"VSync",	OPTV_BOOLEAN,	{0},	1},
24	{OPTION_PAGEFLIP,	"PageFlip",	OPTV_BOOLEAN,	{0},	1},
25	{OPTION_SWAPBUFFERS_WAIT, "SwapbuffersWait", OPTV_BOOLEAN,	{0},	1},
26	{OPTION_TRIPLE_BUFFER,	"TripleBuffer", OPTV_BOOLEAN,	{0},	1},
27	{OPTION_PREFER_OVERLAY, "XvPreferOverlay", OPTV_BOOLEAN, {0}, 0},
28	{OPTION_HOTPLUG,	"HotPlug",	OPTV_BOOLEAN,	{0},	1},
29	{OPTION_REPROBE,	"ReprobeOutputs", OPTV_BOOLEAN,	{0},	0},
30#ifdef INTEL_XVMC
31	{OPTION_XVMC,		"XvMC",		OPTV_BOOLEAN,	{0},	1},
32#endif
33#ifdef USE_SNA
34	{OPTION_ZAPHOD,		"ZaphodHeads",	OPTV_STRING,	{0},	0},
35	{OPTION_VIRTUAL,	"VirtualHeads",	OPTV_INTEGER,	{0},	0},
36	{OPTION_TEAR_FREE,	"TearFree",	OPTV_BOOLEAN,	{0},	0},
37	{OPTION_CRTC_PIXMAPS,	"PerCrtcPixmaps", OPTV_BOOLEAN,	{0},	0},
38#endif
39#ifdef USE_UXA
40	{OPTION_FALLBACKDEBUG,	"FallbackDebug",OPTV_BOOLEAN,	{0},	0},
41	{OPTION_DEBUG_FLUSH_BATCHES, "DebugFlushBatches", OPTV_BOOLEAN, {0}, 0},
42	{OPTION_DEBUG_FLUSH_CACHES, "DebugFlushCaches", OPTV_BOOLEAN, {0}, 0},
43	{OPTION_DEBUG_WAIT, "DebugWait", OPTV_BOOLEAN, {0}, 0},
44	{OPTION_BUFFER_CACHE,	"BufferCache",	OPTV_BOOLEAN,   {0},    1},
45#endif
46	{-1,			NULL,		OPTV_NONE,	{0},	0}
47};
48
49OptionInfoPtr intel_options_get(ScrnInfoPtr scrn)
50{
51	OptionInfoPtr options;
52
53	xf86CollectOptions(scrn, NULL);
54	if (!(options = malloc(sizeof(intel_options))))
55		return NULL;
56
57	memcpy(options, intel_options, sizeof(intel_options));
58	xf86ProcessOptions(scrn->scrnIndex, scrn->options, options);
59
60	return options;
61}
62
63Bool intel_option_cast_to_bool(OptionInfoPtr options, int id, Bool val)
64{
65#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,7,99,901,0)
66	xf86getBoolValue(&val, xf86GetOptValString(options, id));
67#endif
68	return val;
69}
70
71static int
72namecmp(const char *s1, const char *s2)
73{
74	char c1, c2;
75
76	if (!s1 || *s1 == 0) {
77		if (!s2 || *s2 == 0)
78			return 0;
79		else
80			return 1;
81	}
82
83	while (*s1 == '_' || *s1 == ' ' || *s1 == '\t')
84		s1++;
85
86	while (*s2 == '_' || *s2 == ' ' || *s2 == '\t')
87		s2++;
88
89	c1 = isupper(*s1) ? tolower(*s1) : *s1;
90	c2 = isupper(*s2) ? tolower(*s2) : *s2;
91	while (c1 == c2) {
92		if (c1 == '\0')
93			return 0;
94
95		s1++;
96		while (*s1 == '_' || *s1 == ' ' || *s1 == '\t')
97			s1++;
98
99		s2++;
100		while (*s2 == '_' || *s2 == ' ' || *s2 == '\t')
101			s2++;
102
103		c1 = isupper(*s1) ? tolower(*s1) : *s1;
104		c2 = isupper(*s2) ? tolower(*s2) : *s2;
105	}
106
107	return c1 - c2;
108}
109
110unsigned intel_option_cast_to_unsigned(OptionInfoPtr options, int id, unsigned val)
111{
112#if XORG_VERSION_CURRENT >= XORG_VERSION_NUMERIC(1,7,99,901,0)
113	const char *str = xf86GetOptValString(options, id);
114#else
115	const char *str = NULL;
116#endif
117	unsigned v;
118
119	if (str == NULL || *str == '\0')
120		return val;
121
122	if (namecmp(str, "on") == 0)
123		return val;
124	if (namecmp(str, "true") == 0)
125		return val;
126	if (namecmp(str, "yes") == 0)
127		return val;
128
129	if (namecmp(str, "0") == 0)
130		return 0;
131	if (namecmp(str, "off") == 0)
132		return 0;
133	if (namecmp(str, "false") == 0)
134		return 0;
135	if (namecmp(str, "no") == 0)
136		return 0;
137
138	v = atoi(str);
139	if (v)
140		return v;
141
142	return val;
143}
144