Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. /*
  2.  * (C) Copyright IBM Corporation 2003
  3.  * All Rights Reserved.
  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.  * on the rights to use, copy, modify, merge, publish, distribute, sub
  9.  * license, and/or sell copies of the Software, and to permit persons to whom
  10.  * the Software is furnished to do so, subject to the following conditions:
  11.  *
  12.  * The above copyright notice and this permission notice (including the next
  13.  * paragraph) shall be included in all copies or substantial portions of the
  14.  * Software.
  15.  *
  16.  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17.  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18.  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
  19.  * VA LINUX SYSTEM, IBM AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
  20.  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  21.  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  22.  * USE OR OTHER DEALINGS IN THE SOFTWARE.
  23.  */
  24.  
  25. /**
  26.  * \file glxconfig.c
  27.  * Utility routines for working with \c struct glx_config structures.  At
  28.  * some point most or all of these functions will be moved to the Mesa
  29.  * code base.
  30.  *
  31.  * \author Ian Romanick <idr@us.ibm.com>
  32.  */
  33.  
  34. #include <GL/glx.h>
  35. #include "GL/glxint.h"
  36. #include <stdlib.h>
  37. #include <string.h>
  38.  
  39. #include "glxconfig.h"
  40.  
  41. #define NUM_VISUAL_TYPES   6
  42.  
  43. /**
  44.  * Get data from a GLX config
  45.  *
  46.  * \param mode         GL context mode whose data is to be returned.
  47.  * \param attribute    Attribute of \c mode that is to be returned.
  48.  * \param value_return Location to store the data member of \c mode.
  49.  * \return  If \c attribute is a valid attribute of \c mode, zero is
  50.  *          returned.  Otherwise \c GLX_BAD_ATTRIBUTE is returned.
  51.  */
  52. _X_HIDDEN int
  53. glx_config_get(struct glx_config * mode, int attribute, int *value_return)
  54. {
  55.    switch (attribute) {
  56.    case GLX_USE_GL:
  57.       *value_return = GL_TRUE;
  58.       return 0;
  59.    case GLX_BUFFER_SIZE:
  60.       *value_return = mode->rgbBits;
  61.       return 0;
  62.    case GLX_RGBA:
  63.       *value_return = mode->rgbMode;
  64.       return 0;
  65.    case GLX_RED_SIZE:
  66.       *value_return = mode->redBits;
  67.       return 0;
  68.    case GLX_GREEN_SIZE:
  69.       *value_return = mode->greenBits;
  70.       return 0;
  71.    case GLX_BLUE_SIZE:
  72.       *value_return = mode->blueBits;
  73.       return 0;
  74.    case GLX_ALPHA_SIZE:
  75.       *value_return = mode->alphaBits;
  76.       return 0;
  77.    case GLX_DOUBLEBUFFER:
  78.       *value_return = mode->doubleBufferMode;
  79.       return 0;
  80.    case GLX_STEREO:
  81.       *value_return = mode->stereoMode;
  82.       return 0;
  83.    case GLX_AUX_BUFFERS:
  84.       *value_return = mode->numAuxBuffers;
  85.       return 0;
  86.    case GLX_DEPTH_SIZE:
  87.       *value_return = mode->depthBits;
  88.       return 0;
  89.    case GLX_STENCIL_SIZE:
  90.       *value_return = mode->stencilBits;
  91.       return 0;
  92.    case GLX_ACCUM_RED_SIZE:
  93.       *value_return = mode->accumRedBits;
  94.       return 0;
  95.    case GLX_ACCUM_GREEN_SIZE:
  96.       *value_return = mode->accumGreenBits;
  97.       return 0;
  98.    case GLX_ACCUM_BLUE_SIZE:
  99.       *value_return = mode->accumBlueBits;
  100.       return 0;
  101.    case GLX_ACCUM_ALPHA_SIZE:
  102.       *value_return = mode->accumAlphaBits;
  103.       return 0;
  104.    case GLX_LEVEL:
  105.       *value_return = mode->level;
  106.       return 0;
  107. #ifndef GLX_USE_APPLEGL               /* This isn't supported by CGL. */
  108.    case GLX_TRANSPARENT_TYPE_EXT:
  109.       *value_return = mode->transparentPixel;
  110.       return 0;
  111. #endif
  112.    case GLX_TRANSPARENT_RED_VALUE:
  113.       *value_return = mode->transparentRed;
  114.       return 0;
  115.    case GLX_TRANSPARENT_GREEN_VALUE:
  116.       *value_return = mode->transparentGreen;
  117.       return 0;
  118.    case GLX_TRANSPARENT_BLUE_VALUE:
  119.       *value_return = mode->transparentBlue;
  120.       return 0;
  121.    case GLX_TRANSPARENT_ALPHA_VALUE:
  122.       *value_return = mode->transparentAlpha;
  123.       return 0;
  124.    case GLX_TRANSPARENT_INDEX_VALUE:
  125.       *value_return = mode->transparentIndex;
  126.       return 0;
  127.    case GLX_X_VISUAL_TYPE:
  128.       *value_return = mode->visualType;
  129.       return 0;
  130.    case GLX_CONFIG_CAVEAT:
  131.       *value_return = mode->visualRating;
  132.       return 0;
  133.    case GLX_VISUAL_ID:
  134.       *value_return = mode->visualID;
  135.       return 0;
  136.    case GLX_DRAWABLE_TYPE:
  137.       *value_return = mode->drawableType;
  138.       return 0;
  139.    case GLX_RENDER_TYPE:
  140.       *value_return = mode->renderType;
  141.       return 0;
  142.    case GLX_X_RENDERABLE:
  143.       *value_return = mode->xRenderable;
  144.       return 0;
  145.    case GLX_FBCONFIG_ID:
  146.       *value_return = mode->fbconfigID;
  147.       return 0;
  148.    case GLX_MAX_PBUFFER_WIDTH:
  149.       *value_return = mode->maxPbufferWidth;
  150.       return 0;
  151.    case GLX_MAX_PBUFFER_HEIGHT:
  152.       *value_return = mode->maxPbufferHeight;
  153.       return 0;
  154.    case GLX_MAX_PBUFFER_PIXELS:
  155.       *value_return = mode->maxPbufferPixels;
  156.       return 0;
  157. #ifndef GLX_USE_APPLEGL               /* These aren't supported by CGL. */
  158.    case GLX_OPTIMAL_PBUFFER_WIDTH_SGIX:
  159.       *value_return = mode->optimalPbufferWidth;
  160.       return 0;
  161.    case GLX_OPTIMAL_PBUFFER_HEIGHT_SGIX:
  162.       *value_return = mode->optimalPbufferHeight;
  163.       return 0;
  164.    case GLX_SWAP_METHOD_OML:
  165.       *value_return = mode->swapMethod;
  166.       return 0;
  167. #endif
  168.    case GLX_SAMPLE_BUFFERS_SGIS:
  169.       *value_return = mode->sampleBuffers;
  170.       return 0;
  171.    case GLX_SAMPLES_SGIS:
  172.       *value_return = mode->samples;
  173.       return 0;
  174.    case GLX_BIND_TO_TEXTURE_RGB_EXT:
  175.       *value_return = mode->bindToTextureRgb;
  176.       return 0;
  177.    case GLX_BIND_TO_TEXTURE_RGBA_EXT:
  178.       *value_return = mode->bindToTextureRgba;
  179.       return 0;
  180.    case GLX_BIND_TO_MIPMAP_TEXTURE_EXT:
  181.       *value_return = mode->bindToMipmapTexture == GL_TRUE ? GL_TRUE :
  182.          GL_FALSE;
  183.       return 0;
  184.    case GLX_BIND_TO_TEXTURE_TARGETS_EXT:
  185.       *value_return = mode->bindToTextureTargets;
  186.       return 0;
  187.    case GLX_Y_INVERTED_EXT:
  188.       *value_return = mode->yInverted;
  189.       return 0;
  190.  
  191.    case GLX_FRAMEBUFFER_SRGB_CAPABLE_EXT:
  192.       *value_return = mode->sRGBCapable;
  193.       return 0;
  194.  
  195.       /* Applications are NOT allowed to query GLX_VISUAL_SELECT_GROUP_SGIX.
  196.        * It is ONLY for communication between the GLX client and the GLX
  197.        * server.
  198.        */
  199.    case GLX_VISUAL_SELECT_GROUP_SGIX:
  200.    default:
  201.       return GLX_BAD_ATTRIBUTE;
  202.    }
  203. }
  204.  
  205.  
  206. /**
  207.  * Allocate a linked list of \c struct glx_config structures.  The fields of
  208.  * each structure will be initialized to "reasonable" default values.  In
  209.  * most cases this is the default value defined by table 3.4 of the GLX
  210.  * 1.3 specification.  This means that most values are either initialized to
  211.  * zero or \c GLX_DONT_CARE (which is -1).  As support for additional
  212.  * extensions is added, the new values will be initialized to appropriate
  213.  * values from the extension specification.
  214.  *
  215.  * \param count         Number of structures to allocate.
  216.  * \param minimum_size  Minimum size of a structure to allocate.  This allows
  217.  *                      for differences in the version of the
  218.  *                      \c struct glx_config stucture used in libGL and in a
  219.  *                      DRI-based driver.
  220.  * \returns A pointer to the first element in a linked list of \c count
  221.  *          stuctures on success, or \c NULL on failure.
  222.  */
  223. _X_HIDDEN struct glx_config *
  224. glx_config_create_list(unsigned count)
  225. {
  226.    const size_t size = sizeof(struct glx_config);
  227.    struct glx_config *base = NULL;
  228.    struct glx_config **next;
  229.    unsigned i;
  230.  
  231.    next = &base;
  232.    for (i = 0; i < count; i++) {
  233.       *next = malloc(size);
  234.       if (*next == NULL) {
  235.          glx_config_destroy_list(base);
  236.          base = NULL;
  237.          break;
  238.       }
  239.  
  240.       (void) memset(*next, 0, size);
  241.       (*next)->visualID = GLX_DONT_CARE;
  242.       (*next)->visualType = GLX_DONT_CARE;
  243.       (*next)->visualRating = GLX_NONE;
  244.       (*next)->transparentPixel = GLX_NONE;
  245.       (*next)->transparentRed = GLX_DONT_CARE;
  246.       (*next)->transparentGreen = GLX_DONT_CARE;
  247.       (*next)->transparentBlue = GLX_DONT_CARE;
  248.       (*next)->transparentAlpha = GLX_DONT_CARE;
  249.       (*next)->transparentIndex = GLX_DONT_CARE;
  250.       (*next)->xRenderable = GLX_DONT_CARE;
  251.       (*next)->fbconfigID = GLX_DONT_CARE;
  252.       (*next)->swapMethod = GLX_SWAP_UNDEFINED_OML;
  253.       (*next)->bindToTextureRgb = GLX_DONT_CARE;
  254.       (*next)->bindToTextureRgba = GLX_DONT_CARE;
  255.       (*next)->bindToMipmapTexture = GLX_DONT_CARE;
  256.       (*next)->bindToTextureTargets = GLX_DONT_CARE;
  257.       (*next)->yInverted = GLX_DONT_CARE;
  258.       (*next)->sRGBCapable = GLX_DONT_CARE;
  259.  
  260.       next = &((*next)->next);
  261.    }
  262.  
  263.    return base;
  264. }
  265.  
  266. _X_HIDDEN void
  267. glx_config_destroy_list(struct glx_config *configs)
  268. {
  269.    while (configs != NULL) {
  270.       struct glx_config *const next = configs->next;
  271.  
  272.       free(configs);
  273.       configs = next;
  274.    }
  275. }
  276.  
  277.  
  278. /**
  279.  * Find a context mode matching a Visual ID.
  280.  *
  281.  * \param modes  List list of context-mode structures to be searched.
  282.  * \param vid    Visual ID to be found.
  283.  * \returns A pointer to a context-mode in \c modes if \c vid was found in
  284.  *          the list, or \c NULL if it was not.
  285.  */
  286.  
  287. _X_HIDDEN struct glx_config *
  288. glx_config_find_visual(struct glx_config *configs, int vid)
  289. {
  290.    struct glx_config *c;
  291.  
  292.    for (c = configs; c != NULL; c = c->next)
  293.       if (c->visualID == vid)
  294.          return c;
  295.  
  296.    return NULL;
  297. }
  298.  
  299. _X_HIDDEN struct glx_config *
  300. glx_config_find_fbconfig(struct glx_config *configs, int fbid)
  301. {
  302.    struct glx_config *c;
  303.  
  304.    for (c = configs; c != NULL; c = c->next)
  305.       if (c->fbconfigID == fbid)
  306.          return c;
  307.  
  308.    return NULL;
  309. }
  310.