[Mesa-dev] [PATCH 2/6][RFC] drirc: Add string support

Ian Romanick idr at freedesktop.org
Mon Jan 6 11:30:42 PST 2014


On 01/05/2014 01:26 PM, Axel Davy wrote:
> This may require changes to the driconf gui.
> 
> Signed-off-by: Axel Davy <axel.davy at ens.fr>
> ---
>  src/mesa/drivers/dri/common/xmlconfig.c | 24 ++++++++++++++++++++++++
>  src/mesa/drivers/dri/common/xmlconfig.h |  7 ++++++-
>  2 files changed, 30 insertions(+), 1 deletion(-)
> 
> diff --git a/src/mesa/drivers/dri/common/xmlconfig.c b/src/mesa/drivers/dri/common/xmlconfig.c
> index b95e452..c1dae20 100644
> --- a/src/mesa/drivers/dri/common/xmlconfig.c
> +++ b/src/mesa/drivers/dri/common/xmlconfig.c
> @@ -311,6 +311,9 @@ static GLboolean parseValue (driOptionValue *v, driOptionType type,
>        case DRI_FLOAT:
>  	v->_float = strToF (string, &tail);
>  	break;
> +      case DRI_STRING:
> +	v->_string = strndup(string, STRING_CONF_MAXLEN);
> +	return GL_TRUE;

No tabs.

>      }
>  
>      if (tail == string)
> @@ -404,6 +407,8 @@ static GLboolean checkValue (const driOptionValue *v, const driOptionInfo *info)
>  		v->_float <= info->ranges[i].end._float)
>  		return GL_TRUE;
>  	break;
> +      case DRI_STRING:
> +	break;
>        default:
>  	assert (0); /* should never happen */
>      }
> @@ -567,6 +572,8 @@ static void parseOptInfoAttr (struct OptInfoData *data, const XML_Char **attr) {
>  	cache->info[opt].type = DRI_INT;
>      else if (!strcmp (attrVal[OA_TYPE], "float"))
>  	cache->info[opt].type = DRI_FLOAT;
> +    else if (!strcmp (attrVal[OA_TYPE], "string"))
> +	cache->info[opt].type = DRI_STRING;
>      else
>  	XML_FATAL ("illegal type in option: %s.", attrVal[OA_TYPE]);
>  
> @@ -981,6 +988,15 @@ void driDestroyOptionInfo (driOptionCache *info) {
>  }
>  
>  void driDestroyOptionCache (driOptionCache *cache) {

This { should be on its own line.

> +    if (cache->info) {
> +	GLuint i, size = 1 << cache->tableSize;

For things that the application cannot see, just use unsigned.

> +	for (i = 0; i < size; ++i) {
> +	    if (cache->info[i].type == DRI_STRING) {
> +		char *str = cache->values[i]._string;
> +		free (str);
> +	    }
> +	}
> +    }
>      free(cache->values);
>  }
>  
> @@ -1013,3 +1029,11 @@ GLfloat driQueryOptionf (const driOptionCache *cache, const char *name) {
>      assert (cache->info[i].type == DRI_FLOAT);
>      return cache->values[i]._float;
>  }
> +
> +char * driQueryOptionstr (const driOptionCache *cache, const char *name) {

{

> +    GLuint i = findOption (cache, name);

unsigned

> +  /* make sure the option is defined and has the correct type */
> +    assert (cache->info[i].name != NULL);
> +    assert (cache->info[i].type == DRI_STRING);
> +    return cache->values[i]._string;
> +}
> diff --git a/src/mesa/drivers/dri/common/xmlconfig.h b/src/mesa/drivers/dri/common/xmlconfig.h
> index d0ad42c..93fd3f3 100644
> --- a/src/mesa/drivers/dri/common/xmlconfig.h
> +++ b/src/mesa/drivers/dri/common/xmlconfig.h
> @@ -30,9 +30,11 @@
>  #ifndef __XMLCONFIG_H
>  #define __XMLCONFIG_H
>  
> +#define STRING_CONF_MAXLEN 25
> +
>  /** \brief Option data types */
>  typedef enum driOptionType {
> -    DRI_BOOL, DRI_ENUM, DRI_INT, DRI_FLOAT
> +    DRI_BOOL, DRI_ENUM, DRI_INT, DRI_FLOAT, DRI_STRING
>  } driOptionType;
>  
>  /** \brief Option value */
> @@ -40,6 +42,7 @@ typedef union driOptionValue {
>      GLboolean _bool; /**< \brief Boolean */
>      GLint _int;      /**< \brief Integer or Enum */
>      GLfloat _float;  /**< \brief Floating-point */
> +    char* _string;   /**< \brief String */
>  } driOptionValue;
>  
>  /** \brief Single range of valid values
> @@ -118,5 +121,7 @@ GLboolean driQueryOptionb (const driOptionCache *cache, const char *name);
>  GLint driQueryOptioni (const driOptionCache *cache, const char *name);
>  /** \brief Query a floating-point option value */
>  GLfloat driQueryOptionf (const driOptionCache *cache, const char *name);
> +/** \brief Query a string option value */
> +char* driQueryOptionstr (const driOptionCache *cache, const char *name);
>  
>  #endif
> 



More information about the mesa-dev mailing list