⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fakeglx.c

📁 Mesa is an open-source implementation of the OpenGL specification - a system for rendering interacti
💻 C
📖 第 1 页 / 共 5 页
字号:
                                 GL_TRUE,   /* double */                                 GL_FALSE,  /* stereo */                                 zBits,                                 STENCIL_BITS,                                 accBits, /* r */                                 accBits, /* g */                                 accBits, /* b */                                 accBits, /* a */                                 0,         /* level */                                 0          /* numAux */                               );      }   }   else {      _mesa_warning(NULL, "Mesa: error in glXCreateContext: bad visual\n");      return NULL;   }}/* * Find the GLX visual associated with an XVisualInfo. */static XMesaVisualfind_glx_visual( Display *dpy, XVisualInfo *vinfo ){   int i;   /* try to match visual id */   for (i=0;i<NumVisuals;i++) {      if (VisualTable[i]->display==dpy          && VisualTable[i]->visinfo->visualid == vinfo->visualid) {         return VisualTable[i];      }   }   /* if that fails, try to match pointers */   for (i=0;i<NumVisuals;i++) {      if (VisualTable[i]->display==dpy && VisualTable[i]->vishandle==vinfo) {         return VisualTable[i];      }   }   return NULL;}/** * Return the transparent pixel value for a GLX visual. * Input:  glxvis - the glx_visual * Return:  a pixel value or -1 if no transparent pixel */static inttransparent_pixel( XMesaVisual glxvis ){   Display *dpy = glxvis->display;   XVisualInfo *vinfo = glxvis->visinfo;   OverlayInfo *overlay_info;   int numOverlaysPerScreen, i;   overlay_info = GetOverlayInfo(dpy, vinfo->screen, &numOverlaysPerScreen);   if (!overlay_info) {      return -1;   }   for (i = 0; i < numOverlaysPerScreen; i++) {      const OverlayInfo *ov = overlay_info + i;      if (ov->overlay_visual == vinfo->visualid) {         /* found it! */         if (ov->transparent_type == 0) {            /* type 0 indicates no transparency */            XFree((void *) overlay_info);            return -1;         }         else {            /* ov->value is the transparent pixel */            XFree((void *) overlay_info);            return ov->value;         }      }   }   /* The visual ID was not found in the overlay list. */   XFree((void *) overlay_info);   return -1;}/** * Try to get an X visual which matches the given arguments. */static XVisualInfo *get_visual( Display *dpy, int scr, unsigned int depth, int xclass ){   XVisualInfo temp, *vis;   long mask;   int n;   unsigned int default_depth;   int default_class;   mask = VisualScreenMask | VisualDepthMask | VisualClassMask;   temp.screen = scr;   temp.depth = depth;   temp.CLASS = xclass;   default_depth = DefaultDepth(dpy,scr);   default_class = DefaultVisual(dpy,scr)->CLASS;   if (depth==default_depth && xclass==default_class) {      /* try to get root window's visual */      temp.visualid = DefaultVisual(dpy,scr)->visualid;      mask |= VisualIDMask;   }   vis = XGetVisualInfo( dpy, mask, &temp, &n );   /* In case bits/pixel > 24, make sure color channels are still <=8 bits.    * An SGI Infinite Reality system, for example, can have 30bpp pixels:    * 10 bits per color channel.  Mesa's limited to a max of 8 bits/channel.    */   if (vis && depth > 24 && (xclass==TrueColor || xclass==DirectColor)) {      if (_mesa_bitcount((GLuint) vis->red_mask  ) <= 8 &&          _mesa_bitcount((GLuint) vis->green_mask) <= 8 &&          _mesa_bitcount((GLuint) vis->blue_mask ) <= 8) {         return vis;      }      else {         XFree((void *) vis);         return NULL;      }   }   return vis;}/* * Retrieve the value of the given environment variable and find * the X visual which matches it. * Input:  dpy - the display *         screen - the screen number *         varname - the name of the environment variable * Return:  an XVisualInfo pointer to NULL if error. */static XVisualInfo *get_env_visual(Display *dpy, int scr, const char *varname){   char value[100], type[100];   int depth, xclass = -1;   XVisualInfo *vis;   if (!_mesa_getenv( varname )) {      return NULL;   }   _mesa_strncpy( value, _mesa_getenv(varname), 100 );   value[99] = 0;   sscanf( value, "%s %d", type, &depth );   if (_mesa_strcmp(type,"TrueColor")==0)          xclass = TrueColor;   else if (_mesa_strcmp(type,"DirectColor")==0)   xclass = DirectColor;   else if (_mesa_strcmp(type,"PseudoColor")==0)   xclass = PseudoColor;   else if (_mesa_strcmp(type,"StaticColor")==0)   xclass = StaticColor;   else if (_mesa_strcmp(type,"GrayScale")==0)     xclass = GrayScale;   else if (_mesa_strcmp(type,"StaticGray")==0)    xclass = StaticGray;   if (xclass>-1 && depth>0) {      vis = get_visual( dpy, scr, depth, xclass );      if (vis) {	 return vis;      }   }   _mesa_warning(NULL, "GLX unable to find visual class=%s, depth=%d.",                 type, depth);   return NULL;}/* * Select an X visual which satisfies the RGBA/CI flag and minimum depth. * Input:  dpy, screen - X display and screen number *         rgba - GL_TRUE = RGBA mode, GL_FALSE = CI mode *         min_depth - minimum visual depth *         preferred_class - preferred GLX visual class or DONT_CARE * Return:  pointer to an XVisualInfo or NULL. */static XVisualInfo *choose_x_visual( Display *dpy, int screen, GLboolean rgba, int min_depth,                 int preferred_class ){   XVisualInfo *vis;   int xclass, visclass = 0;   int depth;   if (rgba) {      Atom hp_cr_maps = XInternAtom(dpy, "_HP_RGB_SMOOTH_MAP_LIST", True);      /* First see if the MESA_RGB_VISUAL env var is defined */      vis = get_env_visual( dpy, screen, "MESA_RGB_VISUAL" );      if (vis) {	 return vis;      }      /* Otherwise, search for a suitable visual */      if (preferred_class==DONT_CARE) {         for (xclass=0;xclass<6;xclass++) {            switch (xclass) {               case 0:  visclass = TrueColor;    break;               case 1:  visclass = DirectColor;  break;               case 2:  visclass = PseudoColor;  break;               case 3:  visclass = StaticColor;  break;               case 4:  visclass = GrayScale;    break;               case 5:  visclass = StaticGray;   break;            }            if (min_depth==0) {               /* start with shallowest */               for (depth=0;depth<=32;depth++) {                  if (visclass==TrueColor && depth==8 && !hp_cr_maps) {                     /* Special case:  try to get 8-bit PseudoColor before */                     /* 8-bit TrueColor */                     vis = get_visual( dpy, screen, 8, PseudoColor );                     if (vis) {                        return vis;                     }                  }                  vis = get_visual( dpy, screen, depth, visclass );                  if (vis) {                     return vis;                  }               }            }            else {               /* start with deepest */               for (depth=32;depth>=min_depth;depth--) {                  if (visclass==TrueColor && depth==8 && !hp_cr_maps) {                     /* Special case:  try to get 8-bit PseudoColor before */                     /* 8-bit TrueColor */                     vis = get_visual( dpy, screen, 8, PseudoColor );                     if (vis) {                        return vis;                     }                  }                  vis = get_visual( dpy, screen, depth, visclass );                  if (vis) {                     return vis;                  }               }            }         }      }      else {         /* search for a specific visual class */         switch (preferred_class) {            case GLX_TRUE_COLOR_EXT:    visclass = TrueColor;    break;            case GLX_DIRECT_COLOR_EXT:  visclass = DirectColor;  break;            case GLX_PSEUDO_COLOR_EXT:  visclass = PseudoColor;  break;            case GLX_STATIC_COLOR_EXT:  visclass = StaticColor;  break;            case GLX_GRAY_SCALE_EXT:    visclass = GrayScale;    break;            case GLX_STATIC_GRAY_EXT:   visclass = StaticGray;   break;            default:   return NULL;         }         if (min_depth==0) {            /* start with shallowest */            for (depth=0;depth<=32;depth++) {               vis = get_visual( dpy, screen, depth, visclass );               if (vis) {                  return vis;               }            }         }         else {            /* start with deepest */            for (depth=32;depth>=min_depth;depth--) {               vis = get_visual( dpy, screen, depth, visclass );               if (vis) {                  return vis;               }            }         }      }   }   else {      /* First see if the MESA_CI_VISUAL env var is defined */      vis = get_env_visual( dpy, screen, "MESA_CI_VISUAL" );      if (vis) {	 return vis;      }      /* Otherwise, search for a suitable visual, starting with shallowest */      if (preferred_class==DONT_CARE) {         for (xclass=0;xclass<4;xclass++) {            switch (xclass) {               case 0:  visclass = PseudoColor;  break;               case 1:  visclass = StaticColor;  break;               case 2:  visclass = GrayScale;    break;               case 3:  visclass = StaticGray;   break;            }            /* try 8-bit up through 16-bit */            for (depth=8;depth<=16;depth++) {               vis = get_visual( dpy, screen, depth, visclass );               if (vis) {                  return vis;               }            }            /* try min_depth up to 8-bit */            for (depth=min_depth;depth<8;depth++) {               vis = get_visual( dpy, screen, depth, visclass );               if (vis) {                  return vis;               }            }         }      }      else {         /* search for a specific visual class */         switch (preferred_class) {            case GLX_TRUE_COLOR_EXT:    visclass = TrueColor;    break;            case GLX_DIRECT_COLOR_EXT:  visclass = DirectColor;  break;            case GLX_PSEUDO_COLOR_EXT:  visclass = PseudoColor;  break;            case GLX_STATIC_COLOR_EXT:  visclass = StaticColor;  break;            case GLX_GRAY_SCALE_EXT:    visclass = GrayScale;    break;            case GLX_STATIC_GRAY_EXT:   visclass = StaticGray;   break;            default:   return NULL;         }         /* try 8-bit up through 16-bit */         for (depth=8;depth<=16;depth++) {            vis = get_visual( dpy, screen, depth, visclass );            if (vis) {               return vis;            }         }         /* try min_depth up to 8-bit */         for (depth=min_depth;depth<8;depth++) {            vis = get_visual( dpy, screen, depth, visclass );            if (vis) {               return vis;            }         }      }   }   /* didn't find a visual */   return NULL;}/* * Find the deepest X over/underlay visual of at least min_depth. * Input:  dpy, screen - X display and screen number *         level - the over/underlay level *         trans_type - transparent pixel type: GLX_NONE_EXT, *                      GLX_TRANSPARENT_RGB_EXT, GLX_TRANSPARENT_INDEX_EXT, *                      or DONT_CARE *         trans_value - transparent pixel value or DONT_CARE *         min_depth - minimum visual depth *         preferred_class - preferred GLX visual class or DONT_CARE * Return:  pointer to an XVisualInfo or NULL. */static XVisualInfo *choose_x_overlay_visual( Display *dpy, int scr, GLboolean rgbFlag,                         int level, int trans_type, int trans_value,                         int min_depth, int preferred_class ){   OverlayInfo *overlay_info;   int numOverlaysPerScreen;   int i;   XVisualInfo *deepvis;   int deepest;   /*DEBUG int tt, tv; */   switch (preferred_class) {      case GLX_TRUE_COLOR_EXT:    preferred_class = TrueColor;    break;      case GLX_DIRECT_COLOR_EXT:  preferred_class = DirectColor;  break;      case GLX_PSEUDO_COLOR_EXT:  preferred_class = PseudoColor;  break;      case GLX_STATIC_COLOR_EXT:  preferred_class = StaticColor;  break;      case GLX_GRAY_SCALE_EXT:    preferred_class = GrayScale;    break;      case GLX_STATIC_GRAY_EXT:   preferred_class = StaticGray;   break;      default:                    preferred_class = DONT_CARE;   }   overlay_info = GetOverlayInfo(dpy, scr, &numOverlaysPerScreen);   if (!overlay_info) {      return NULL;   }   /* Search for the deepest overlay which satisifies all criteria. */   deepest = min_depth;   deepvis = NULL;   for (i = 0; i < numOverlaysPerScreen; i++) {      const OverlayInfo *ov = overlay_info + i;      XVisualInfo *vislist, vistemplate;      int count;      if (ov->layer!=level) {         /* failed overlay level criteria */         continue;      }      if (!(trans_type==DONT_CARE            || (trans_type==GLX_TRANSPARENT_INDEX_EXT                && ov->transparent_type>0)            || (trans_type==GLX_NONE_EXT && ov->transparent_type==0))) {         /* failed transparent pixel type criteria */         continue;      }      if (trans_value!=DONT_CARE && trans_value!=ov->value) {         /* failed transparent pixel value criteria */         continue;      }      /* get XVisualInfo and check the depth */      vistemplate.visualid = ov->overlay_visual;      vistemplate.screen = scr;      vislist = XGetVisualInfo( dpy, VisualIDMask | VisualScreenMask,                                &vistemplate, &count );      if (count!=1) {         /* something went wrong */         continue;      }      if (preferred_class!=DONT_CARE && preferred_class!=vislist->CLASS) {         /* wrong visual class */         continue;      }      /* if RGB was requested, make sure we have True/DirectColor */      if (rgbFlag && vislist->CLASS != TrueColor          && vislist->CLASS != DirectColor)         continue;      /* if CI was requested, make sure we have a color indexed visual */      if (!rgbFlag          && (vislist->CLASS == TrueColor || vislist->CLASS == DirectColor))         continue;      if (deepvis==NULL || vislist->depth > deepest) {         /* YES!  found a satisfactory visual */         if (deepvis) {            XFree( deepvis );         }         deepest = vislist->depth;         deepvis = vislist;         /* DEBUG  tt = ov->transparent_type;*/         /* DEBUG  tv = ov->value; */      }   }/*DEBUG   if (deepvis) {      printf("chose 0x%x:  layer=%d depth=%d trans_type=%d trans_value=%d\n",             deepvis->visualid, level, deepvis->depth, tt, tv );   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -