VirtualBox

source: vbox/trunk/src/VBox/GuestHost/OpenGL/spu_loader/spuinit.c@ 71930

Last change on this file since 71930 was 69392, checked in by vboxsync, 7 years ago

GuestHost/OpenGL: scm updates

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id Revision
File size: 5.7 KB
Line 
1/* Copyright (c) 2001, Stanford University
2 * All rights reserved
3 *
4 * See the file LICENSE.txt for information on redistributing this software.
5 */
6
7#include "cr_spu.h"
8#include "cr_error.h"
9#include "cr_string.h"
10#include <stdio.h>
11
12/**
13 * \mainpage spu_loader
14 *
15 * \section Spu_loaderIntroduction Introduction
16 *
17 * Chromium consists of all the top-level files in the cr
18 * directory. The spu_loader module basically takes care of API dispatch,
19 * and OpenGL state management.
20 *
21 */
22void crSPUInitDispatchTable( SPUDispatchTable *table )
23{
24 table->copyList = NULL;
25 table->copy_of = NULL;
26 table->mark = 0;
27 table->server = NULL;
28}
29
30#if 0 /* unused */
31
32static int validate_int( const char *response,
33 const char *min,
34 const char *max )
35{
36 int i, imin, imax;
37 if (sscanf(response, "%d", &i) != 1)
38 return 0;
39 if (min && sscanf(min, "%d", &imin) == 1 && imin > i)
40 return 0;
41 if (max && sscanf(max, "%d", &imax) == 1 && imax < i)
42 return 0;
43 return 1;
44}
45
46static int validate_float( const char *response,
47 const char *min,
48 const char *max )
49{
50 float f, fmin, fmax;
51 if (sscanf(response, "%f", &f) != 1)
52 return 0;
53 if (min && sscanf(min, "%f", &fmin) == 1 && fmin > f)
54 return 0;
55 if (max && sscanf(max, "%f", &fmax) == 1 && fmax < f)
56 return 0;
57 return 1;
58}
59
60static int validate_one_option( const SPUOptions *opt,
61 const char *response,
62 const char *min,
63 const char *max )
64{
65 switch (opt->type) {
66 case CR_BOOL:
67 return validate_int( response, "0", "1" );
68 case CR_INT:
69 return validate_int( response, min, max );
70 case CR_FLOAT:
71 return validate_float( response, min, max );
72 case CR_ENUM:
73 /* Make sure response string is present in the min string.
74 * For enums, the min string is a comma-separated list of valid values.
75 */
76 CRASSERT(opt->numValues == 1); /* an enum limitation for now */
77 {
78 const char *p = crStrstr(min, response);
79 if (!p)
80 return 0; /* invalid value! */
81 if (p[-1] != '\'')
82 return 0; /* right substring */
83 if (p[crStrlen(response)] != '\'')
84 return 0; /* left substring */
85 return 1;
86 }
87 default:
88 return 0;
89 }
90}
91
92
93/**
94 * Make sure the response matches the opt's parameters (right number
95 * and type of values, etc.)
96 * Return 1 if OK, 0 if error.
97 */
98static int validate_option( const SPUOptions *opt, const char *response )
99{
100 const char *min = opt->min;
101 const char *max = opt->max;
102 int i = 0;
103 int retval;
104
105 if (opt->type == CR_STRING)
106 return 1;
107
108 CRASSERT(opt->numValues > 0);
109
110 /* skip leading [ for multi-value options */
111 if (opt->numValues > 1) {
112 /* multi-valued options must be enclosed in brackets */
113 if (*response != '[')
114 return 0;
115 response++; /* skip [ */
116 /* make sure min and max are bracketed as well */
117 if (min) {
118 CRASSERT(*min == '['); /* error in <foo>spu_config.c code!!! */
119 min++;
120 }
121 if (max) {
122 CRASSERT(*max == '['); /* error in <foo>spu_config.c code!!! */
123 max++;
124 }
125 }
126
127 for (;;)
128 {
129 if (!validate_one_option( opt, response, min, max ))
130 {
131 retval = 0;
132 break;
133 }
134 if (++i == opt->numValues)
135 {
136 retval = 1; /* all done! */
137 break;
138 }
139 /* advance pointers to next item */
140 if (min)
141 {
142 while (*min != ' ' && *min)
143 min++;
144 while (*min == ' ')
145 min++;
146 }
147 if (max)
148 {
149 while (*max != ' ' && *max)
150 max++;
151 while (*max == ' ')
152 max++;
153 }
154 if (response)
155 {
156 while (*response != ' ' && *response)
157 response++;
158 while (*response == ' ')
159 response++;
160 }
161 }
162
163 return retval;
164}
165
166#endif /* unused */
167
168/** Use the default values for all the options:
169 */
170void crSPUSetDefaultParams( void *spu, SPUOptions *options )
171{
172 int i;
173
174 for (i = 0 ; options[i].option ; i++)
175 {
176 SPUOptions *opt = &options[i];
177 opt->cb( spu, opt->deflt );
178 }
179}
180
181
182/**
183 * Find the index of the given enum value in the SPUOption's list of
184 * possible enum values.
185 * Return the enum index, or -1 if not found.
186 */
187int crSPUGetEnumIndex( const SPUOptions *options, const char *optName, const char *value )
188{
189 const SPUOptions *opt;
190 const int valueLen = crStrlen(value);
191
192 /* first, find the right option */
193 for (opt = options; opt->option; opt++) {
194 if (crStrcmp(opt->option, optName) == 0) {
195 char **values;
196 int i;
197
198 CRASSERT(opt->type == CR_ENUM);
199
200 /* break into array of strings */
201 /* min string should be of form "'enum1', 'enum2', 'enum3', etc" */
202 values = crStrSplit(opt->min, ",");
203
204 /* search the array */
205 for (i = 0; values[i]; i++) {
206 /* find leading quote */
207 const char *e = crStrchr(values[i], '\'');
208 CRASSERT(e);
209 if (e) {
210 /* test for match */
211 if (crStrncmp(value, e + 1, valueLen) == 0 && e[valueLen + 1] == '\'') {
212 crFreeStrings(values);
213 return i;
214 }
215 }
216 }
217
218 /* enum value not found! */
219 crFreeStrings(values);
220 return -1;
221 }
222 }
223
224 return -1;
225}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette