util/os_misc: add os_get_available_system_memory()
[mesa.git] / src / util / xmlconfig.h
1 /*
2 * XML DRI client-side driver configuration
3 * Copyright (C) 2003 Felix Kuehling
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included
13 * in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * FELIX KUEHLING, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
21 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 */
24 /**
25 * \file xmlconfig.h
26 * \brief Driver-independent client-side part of the XML configuration
27 * \author Felix Kuehling
28 */
29
30 #ifndef __XMLCONFIG_H
31 #define __XMLCONFIG_H
32
33 #include "util/mesa-sha1.h"
34 #include "util/ralloc.h"
35 #include <stdint.h>
36 #include <string.h>
37
38 #define STRING_CONF_MAXLEN 25
39
40 /** \brief Option data types */
41 typedef enum driOptionType {
42 DRI_BOOL, DRI_ENUM, DRI_INT, DRI_FLOAT, DRI_STRING
43 } driOptionType;
44
45 /** \brief Option value */
46 typedef union driOptionValue {
47 unsigned char _bool; /**< \brief Boolean */
48 int _int; /**< \brief Integer or Enum */
49 float _float; /**< \brief Floating-point */
50 char *_string; /**< \brief String */
51 } driOptionValue;
52
53 /** \brief Single range of valid values
54 *
55 * For empty ranges (a single value) start == end */
56 typedef struct driOptionRange {
57 driOptionValue start; /**< \brief Start */
58 driOptionValue end; /**< \brief End */
59 } driOptionRange;
60
61 /** \brief Information about an option */
62 typedef struct driOptionInfo {
63 char *name; /**< \brief Name */
64 driOptionType type; /**< \brief Type */
65 driOptionRange *ranges; /**< \brief Array of ranges */
66 unsigned int nRanges; /**< \brief Number of ranges */
67 } driOptionInfo;
68
69 /** \brief Option cache
70 *
71 * \li One in <driver>Screen caching option info and the default values
72 * \li One in each <driver>Context with the actual values for that context */
73 typedef struct driOptionCache {
74 driOptionInfo *info;
75 /**< \brief Array of option infos
76 *
77 * Points to the same array in the screen and all contexts */
78 driOptionValue *values;
79 /**< \brief Array of option values
80 *
81 * \li Default values in screen
82 * \li Actual values in contexts
83 */
84 unsigned int tableSize;
85 /**< \brief Size of the arrays
86 *
87 * In the current implementation it's not actually a size but log2(size).
88 * The value is the same in the screen and all contexts. */
89 } driOptionCache;
90
91 /** \brief Parse XML option info from configOptions
92 *
93 * To be called in <driver>CreateScreen
94 *
95 * \param info pointer to a driOptionCache that will store the option info
96 * \param configOptions XML document describing available configuration opts
97 *
98 * For the option information to be available to external configuration tools
99 * it must be a public symbol __driConfigOptions. It is also passed as a
100 * parameter to driParseOptionInfo in order to avoid driver-independent code
101 * depending on symbols in driver-specific code. */
102 void driParseOptionInfo (driOptionCache *info,
103 const char *configOptions);
104 /** \brief Initialize option cache from info and parse configuration files
105 *
106 * To be called in <driver>CreateContext. screenNum, driverName,
107 * kernelDriverName, applicationName and engineName select device sections. */
108 void driParseConfigFiles (driOptionCache *cache, const driOptionCache *info,
109 int screenNum, const char *driverName,
110 const char *kernelDriverName,
111 const char *applicationName, uint32_t applicationVersion,
112 const char *engineName, uint32_t engineVersion);
113 /** \brief Destroy option info
114 *
115 * To be called in <driver>DestroyScreen */
116 void driDestroyOptionInfo (driOptionCache *info);
117 /** \brief Destroy option cache
118 *
119 * To be called in <driver>DestroyContext */
120 void driDestroyOptionCache (driOptionCache *cache);
121
122 /** \brief Check if there exists a certain option */
123 unsigned char driCheckOption (const driOptionCache *cache, const char *name,
124 driOptionType type);
125
126 /** \brief Query a boolean option value */
127 unsigned char driQueryOptionb (const driOptionCache *cache, const char *name);
128 /** \brief Query an integer option value */
129 int driQueryOptioni (const driOptionCache *cache, const char *name);
130 /** \brief Query a floating-point option value */
131 float driQueryOptionf (const driOptionCache *cache, const char *name);
132 /** \brief Query a string option value */
133 char *driQueryOptionstr (const driOptionCache *cache, const char *name);
134
135 /**
136 * Returns a hash of the options for this application.
137 */
138 static inline void
139 driComputeOptionsSha1(const driOptionCache *cache, unsigned char *sha1)
140 {
141 void *ctx = ralloc_context(NULL);
142 char *dri_options = ralloc_strdup(ctx, "");
143
144 for (int i = 0; i < 1 << cache->tableSize; i++) {
145 if (cache->info[i].name == NULL)
146 continue;
147
148 bool ret = false;
149 switch (cache->info[i].type) {
150 case DRI_BOOL:
151 ret = ralloc_asprintf_append(&dri_options, "%s:%u,",
152 cache->info[i].name,
153 cache->values[i]._bool);
154 break;
155 case DRI_INT:
156 case DRI_ENUM:
157 ret = ralloc_asprintf_append(&dri_options, "%s:%d,",
158 cache->info[i].name,
159 cache->values[i]._int);
160 break;
161 case DRI_FLOAT:
162 ret = ralloc_asprintf_append(&dri_options, "%s:%f,",
163 cache->info[i].name,
164 cache->values[i]._float);
165 break;
166 case DRI_STRING:
167 ret = ralloc_asprintf_append(&dri_options, "%s:%s,",
168 cache->info[i].name,
169 cache->values[i]._string);
170 break;
171 default:
172 unreachable("unsupported dri config type!");
173 }
174
175 if (!ret) {
176 break;
177 }
178 }
179
180 _mesa_sha1_compute(dri_options, strlen(dri_options), sha1);
181 ralloc_free(ctx);
182 }
183
184 #endif