xmlconfig.h revision 01e04c3f
101e04c3fSmrg/*
201e04c3fSmrg * XML DRI client-side driver configuration
301e04c3fSmrg * Copyright (C) 2003 Felix Kuehling
401e04c3fSmrg *
501e04c3fSmrg * Permission is hereby granted, free of charge, to any person obtaining a
601e04c3fSmrg * copy of this software and associated documentation files (the "Software"),
701e04c3fSmrg * to deal in the Software without restriction, including without limitation
801e04c3fSmrg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
901e04c3fSmrg * and/or sell copies of the Software, and to permit persons to whom the
1001e04c3fSmrg * Software is furnished to do so, subject to the following conditions:
1101e04c3fSmrg *
1201e04c3fSmrg * The above copyright notice and this permission notice shall be included
1301e04c3fSmrg * in all copies or substantial portions of the Software.
1401e04c3fSmrg *
1501e04c3fSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
1601e04c3fSmrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1701e04c3fSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1801e04c3fSmrg * FELIX KUEHLING, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
1901e04c3fSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
2001e04c3fSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
2101e04c3fSmrg * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2201e04c3fSmrg *
2301e04c3fSmrg */
2401e04c3fSmrg/**
2501e04c3fSmrg * \file xmlconfig.h
2601e04c3fSmrg * \brief Driver-independent client-side part of the XML configuration
2701e04c3fSmrg * \author Felix Kuehling
2801e04c3fSmrg */
2901e04c3fSmrg
3001e04c3fSmrg#ifndef __XMLCONFIG_H
3101e04c3fSmrg#define __XMLCONFIG_H
3201e04c3fSmrg
3301e04c3fSmrg#include "util/mesa-sha1.h"
3401e04c3fSmrg#include "util/ralloc.h"
3501e04c3fSmrg#include <string.h>
3601e04c3fSmrg
3701e04c3fSmrg#define STRING_CONF_MAXLEN 25
3801e04c3fSmrg
3901e04c3fSmrg/** \brief Option data types */
4001e04c3fSmrgtypedef enum driOptionType {
4101e04c3fSmrg    DRI_BOOL, DRI_ENUM, DRI_INT, DRI_FLOAT, DRI_STRING
4201e04c3fSmrg} driOptionType;
4301e04c3fSmrg
4401e04c3fSmrg/** \brief Option value */
4501e04c3fSmrgtypedef union driOptionValue {
4601e04c3fSmrg    unsigned char _bool; /**< \brief Boolean */
4701e04c3fSmrg    int _int;      /**< \brief Integer or Enum */
4801e04c3fSmrg    float _float;  /**< \brief Floating-point */
4901e04c3fSmrg    char *_string;   /**< \brief String */
5001e04c3fSmrg} driOptionValue;
5101e04c3fSmrg
5201e04c3fSmrg/** \brief Single range of valid values
5301e04c3fSmrg *
5401e04c3fSmrg * For empty ranges (a single value) start == end */
5501e04c3fSmrgtypedef struct driOptionRange {
5601e04c3fSmrg    driOptionValue start; /**< \brief Start */
5701e04c3fSmrg    driOptionValue end;   /**< \brief End */
5801e04c3fSmrg} driOptionRange;
5901e04c3fSmrg
6001e04c3fSmrg/** \brief Information about an option */
6101e04c3fSmrgtypedef struct driOptionInfo {
6201e04c3fSmrg    char *name;             /**< \brief Name */
6301e04c3fSmrg    driOptionType type;     /**< \brief Type */
6401e04c3fSmrg    driOptionRange *ranges; /**< \brief Array of ranges */
6501e04c3fSmrg    unsigned int nRanges;   /**< \brief Number of ranges */
6601e04c3fSmrg} driOptionInfo;
6701e04c3fSmrg
6801e04c3fSmrg/** \brief Option cache
6901e04c3fSmrg *
7001e04c3fSmrg * \li One in <driver>Screen caching option info and the default values
7101e04c3fSmrg * \li One in each <driver>Context with the actual values for that context */
7201e04c3fSmrgtypedef struct driOptionCache {
7301e04c3fSmrg    driOptionInfo *info;
7401e04c3fSmrg  /**< \brief Array of option infos
7501e04c3fSmrg   *
7601e04c3fSmrg   * Points to the same array in the screen and all contexts */
7701e04c3fSmrg    driOptionValue *values;
7801e04c3fSmrg  /**< \brief Array of option values
7901e04c3fSmrg   *
8001e04c3fSmrg   * \li Default values in screen
8101e04c3fSmrg   * \li Actual values in contexts
8201e04c3fSmrg   */
8301e04c3fSmrg    unsigned int tableSize;
8401e04c3fSmrg  /**< \brief Size of the arrays
8501e04c3fSmrg   *
8601e04c3fSmrg   * In the current implementation it's not actually a size but log2(size).
8701e04c3fSmrg   * The value is the same in the screen and all contexts. */
8801e04c3fSmrg} driOptionCache;
8901e04c3fSmrg
9001e04c3fSmrg/** \brief Parse XML option info from configOptions
9101e04c3fSmrg *
9201e04c3fSmrg * To be called in <driver>CreateScreen
9301e04c3fSmrg *
9401e04c3fSmrg * \param info    pointer to a driOptionCache that will store the option info
9501e04c3fSmrg * \param configOptions   XML document describing available configuration opts
9601e04c3fSmrg *
9701e04c3fSmrg * For the option information to be available to external configuration tools
9801e04c3fSmrg * it must be a public symbol __driConfigOptions. It is also passed as a
9901e04c3fSmrg * parameter to driParseOptionInfo in order to avoid driver-independent code
10001e04c3fSmrg * depending on symbols in driver-specific code. */
10101e04c3fSmrgvoid driParseOptionInfo (driOptionCache *info,
10201e04c3fSmrg			 const char *configOptions);
10301e04c3fSmrg/** \brief Initialize option cache from info and parse configuration files
10401e04c3fSmrg *
10501e04c3fSmrg * To be called in <driver>CreateContext. screenNum, driverName and
10601e04c3fSmrg * kernelDriverName select device sections. */
10701e04c3fSmrgvoid driParseConfigFiles (driOptionCache *cache, const driOptionCache *info,
10801e04c3fSmrg			  int screenNum, const char *driverName,
10901e04c3fSmrg			  const char *kernelDriverName);
11001e04c3fSmrg/** \brief Destroy option info
11101e04c3fSmrg *
11201e04c3fSmrg * To be called in <driver>DestroyScreen */
11301e04c3fSmrgvoid driDestroyOptionInfo (driOptionCache *info);
11401e04c3fSmrg/** \brief Destroy option cache
11501e04c3fSmrg *
11601e04c3fSmrg * To be called in <driver>DestroyContext */
11701e04c3fSmrgvoid driDestroyOptionCache (driOptionCache *cache);
11801e04c3fSmrg
11901e04c3fSmrg/** \brief Check if there exists a certain option */
12001e04c3fSmrgunsigned char driCheckOption (const driOptionCache *cache, const char *name,
12101e04c3fSmrg			  driOptionType type);
12201e04c3fSmrg
12301e04c3fSmrg/** \brief Query a boolean option value */
12401e04c3fSmrgunsigned char driQueryOptionb (const driOptionCache *cache, const char *name);
12501e04c3fSmrg/** \brief Query an integer option value */
12601e04c3fSmrgint driQueryOptioni (const driOptionCache *cache, const char *name);
12701e04c3fSmrg/** \brief Query a floating-point option value */
12801e04c3fSmrgfloat driQueryOptionf (const driOptionCache *cache, const char *name);
12901e04c3fSmrg/** \brief Query a string option value */
13001e04c3fSmrgchar *driQueryOptionstr (const driOptionCache *cache, const char *name);
13101e04c3fSmrg
13201e04c3fSmrg/**
13301e04c3fSmrg * Returns a hash of the options for this application.
13401e04c3fSmrg */
13501e04c3fSmrgstatic inline void
13601e04c3fSmrgdriComputeOptionsSha1(const driOptionCache *cache, unsigned char *sha1)
13701e04c3fSmrg{
13801e04c3fSmrg   void *ctx = ralloc_context(NULL);
13901e04c3fSmrg   char *dri_options = ralloc_strdup(ctx, "");
14001e04c3fSmrg
14101e04c3fSmrg   for (int i = 0; i < 1 << cache->tableSize; i++) {
14201e04c3fSmrg      if (cache->info[i].name == NULL)
14301e04c3fSmrg         continue;
14401e04c3fSmrg
14501e04c3fSmrg      bool ret = false;
14601e04c3fSmrg      switch (cache->info[i].type) {
14701e04c3fSmrg      case DRI_BOOL:
14801e04c3fSmrg         ret = ralloc_asprintf_append(&dri_options, "%s:%u,",
14901e04c3fSmrg                                      cache->info[i].name,
15001e04c3fSmrg                                      cache->values[i]._bool);
15101e04c3fSmrg         break;
15201e04c3fSmrg      case DRI_INT:
15301e04c3fSmrg      case DRI_ENUM:
15401e04c3fSmrg         ret = ralloc_asprintf_append(&dri_options, "%s:%d,",
15501e04c3fSmrg                                      cache->info[i].name,
15601e04c3fSmrg                                      cache->values[i]._int);
15701e04c3fSmrg         break;
15801e04c3fSmrg      case DRI_FLOAT:
15901e04c3fSmrg         ret = ralloc_asprintf_append(&dri_options, "%s:%f,",
16001e04c3fSmrg                                      cache->info[i].name,
16101e04c3fSmrg                                      cache->values[i]._float);
16201e04c3fSmrg         break;
16301e04c3fSmrg      case DRI_STRING:
16401e04c3fSmrg         ret = ralloc_asprintf_append(&dri_options, "%s:%s,",
16501e04c3fSmrg                                      cache->info[i].name,
16601e04c3fSmrg                                      cache->values[i]._string);
16701e04c3fSmrg         break;
16801e04c3fSmrg      default:
16901e04c3fSmrg         unreachable("unsupported dri config type!");
17001e04c3fSmrg      }
17101e04c3fSmrg
17201e04c3fSmrg      if (!ret) {
17301e04c3fSmrg         break;
17401e04c3fSmrg      }
17501e04c3fSmrg   }
17601e04c3fSmrg
17701e04c3fSmrg   _mesa_sha1_compute(dri_options, strlen(dri_options), sha1);
17801e04c3fSmrg   ralloc_free(ctx);
17901e04c3fSmrg}
18001e04c3fSmrg
18101e04c3fSmrg#endif
182