Clone of mesa.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

glxdpyinfo.c 30KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  1. /*
  2. * $TOG: xdpyinfo.c /main/35 1998/02/09 13:57:05 kaleb $
  3. *
  4. * xdpyinfo - print information about X display connecton
  5. *
  6. *
  7. Copyright 1988, 1998 The Open Group
  8. All Rights Reserved.
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
  15. AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  16. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall not be
  18. used in advertising or otherwise to promote the sale, use or other dealings
  19. in this Software without prior written authorization from The Open Group.
  20. *
  21. * Author: Jim Fulton, MIT X Consortium
  22. * GLX and Overlay support added by Jamie Zawinski <jwz@jwz.org>, 11-Nov-99
  23. *
  24. * To compile:
  25. * cc -DHAVE_GLX glxdpyinfo.c -o glxdpyinfo -lGL -lX11 -lXext -lm
  26. *
  27. * Other defines to consider:
  28. * -DHAVE_XIE -DHAVE_XTEST -DHAVE_XRECORD
  29. */
  30. #define HAVE_GLX /* added by Brian Paul */
  31. #include <X11/Xlib.h>
  32. #include <X11/Xutil.h>
  33. #include <X11/Xproto.h> /* for CARD32 */
  34. #include <X11/extensions/multibuf.h>
  35. #ifdef HAVE_XIE
  36. #include <X11/extensions/XIElib.h>
  37. #endif /* HAVE_XIE */
  38. #ifdef HAVE_XTEST
  39. #include <X11/extensions/XTest.h>
  40. #endif /* HAVE_XTEST */
  41. #include <X11/extensions/sync.h>
  42. #include <X11/extensions/Xdbe.h>
  43. #ifdef HAVE_XRECORD
  44. #include <X11/extensions/record.h>
  45. #endif /* HAVE_XRECORD */
  46. #ifdef MITSHM
  47. #include <X11/extensions/XShm.h>
  48. #endif
  49. #include <X11/Xos.h>
  50. #include <stdio.h>
  51. #ifdef HAVE_GLX
  52. # include <GL/gl.h>
  53. # include <GL/glx.h>
  54. #endif /* HAVE_GLX */
  55. #define HAVE_OVERLAY /* jwz: no compile-time deps, so do this all the time */
  56. char *ProgramName;
  57. Bool queryExtensions = False;
  58. static int StrCmp(a, b)
  59. char **a, **b;
  60. {
  61. return strcmp(*a, *b);
  62. }
  63. #ifdef HAVE_GLX /* Added by jwz, 11-Nov-99 */
  64. static void
  65. print_glx_versions (dpy)
  66. Display *dpy;
  67. {
  68. /* Note: with Mesa 3.0, this lies: it prints the info from the
  69. client's GL library, rather than the info from the GLX server.
  70. Note also that we can't protect these calls by only doing
  71. them when the GLX extension is present, because with Mesa,
  72. the server doesn't have that extension (but the GL library
  73. works anyway.)
  74. */
  75. int scr = DefaultScreen (dpy);
  76. const char *vend, *vers;
  77. vend = glXQueryServerString (dpy, scr, GLX_VENDOR);
  78. if (!vend) return;
  79. vers = glXQueryServerString (dpy, scr, GLX_VERSION);
  80. printf ("GLX vendor: %s (%s)\n",
  81. vend, (vers ? vers : "unknown version"));
  82. }
  83. static void
  84. print_glx_visual_info (dpy, vip)
  85. Display *dpy;
  86. XVisualInfo *vip;
  87. {
  88. int status, value = False;
  89. status = glXGetConfig (dpy, vip, GLX_USE_GL, &value);
  90. if (status == GLX_NO_EXTENSION)
  91. /* dpy does not support the GLX extension. */
  92. return;
  93. if (status == GLX_BAD_VISUAL || value == False)
  94. {
  95. printf (" GLX supported: no\n");
  96. return;
  97. }
  98. else
  99. {
  100. printf (" GLX supported: yes\n");
  101. }
  102. if (!glXGetConfig (dpy, vip, GLX_LEVEL, &value) &&
  103. value != 0)
  104. printf (" GLX level: %d\n", value);
  105. if (!glXGetConfig (dpy, vip, GLX_RGBA, &value) && value)
  106. {
  107. int r=0, g=0, b=0, a=0;
  108. glXGetConfig (dpy, vip, GLX_RED_SIZE, &r);
  109. glXGetConfig (dpy, vip, GLX_GREEN_SIZE, &g);
  110. glXGetConfig (dpy, vip, GLX_BLUE_SIZE, &b);
  111. glXGetConfig (dpy, vip, GLX_ALPHA_SIZE, &a);
  112. printf (" GLX type: RGBA (%2d, %2d, %2d, %2d)\n",
  113. r, g, b, a);
  114. r=0, g=0, b=0, a=0;
  115. glXGetConfig (dpy, vip, GLX_ACCUM_RED_SIZE, &r);
  116. glXGetConfig (dpy, vip, GLX_ACCUM_GREEN_SIZE, &g);
  117. glXGetConfig (dpy, vip, GLX_ACCUM_BLUE_SIZE, &b);
  118. glXGetConfig (dpy, vip, GLX_ACCUM_ALPHA_SIZE, &a);
  119. printf (" GLX accum: RGBA (%2d, %2d, %2d, %2d)\n",
  120. r, g, b, a);
  121. }
  122. else
  123. {
  124. value = 0;
  125. glXGetConfig (dpy, vip, GLX_BUFFER_SIZE, &value);
  126. printf (" GLX type: indexed (%d)\n", value);
  127. }
  128. # if 0 /* redundant */
  129. if (!glXGetConfig (dpy, vip, GLX_X_VISUAL_TYPE_EXT, &value))
  130. printf (" GLX class: %s\n",
  131. (value == GLX_TRUE_COLOR_EXT ? "TrueColor" :
  132. value == GLX_DIRECT_COLOR_EXT ? "DirectColor" :
  133. value == GLX_PSEUDO_COLOR_EXT ? "PseudoColor" :
  134. value == GLX_STATIC_COLOR_EXT ? "StaticColor" :
  135. value == GLX_GRAY_SCALE_EXT ? "Grayscale" :
  136. value == GLX_STATIC_GRAY_EXT ? "StaticGray" : "???"));
  137. # endif
  138. # ifdef GLX_VISUAL_CAVEAT_EXT
  139. if (!glXGetConfig (dpy, vip, GLX_VISUAL_CAVEAT_EXT, &value) &&
  140. value != GLX_NONE_EXT)
  141. printf (" GLX rating: %s\n",
  142. (value == GLX_NONE_EXT ? "none" :
  143. value == GLX_SLOW_VISUAL_EXT ? "slow" :
  144. # ifdef GLX_NON_CONFORMANT_EXT
  145. value == GLX_NON_CONFORMANT_EXT ? "non-conformant" :
  146. # endif
  147. "???"));
  148. # endif
  149. if (!glXGetConfig (dpy, vip, GLX_DOUBLEBUFFER, &value))
  150. printf (" GLX double-buffer: %s\n", (value ? "yes" : "no"));
  151. if (!glXGetConfig (dpy, vip, GLX_STEREO, &value) &&
  152. value)
  153. printf (" GLX stereo: %s\n", (value ? "yes" : "no"));
  154. if (!glXGetConfig (dpy, vip, GLX_AUX_BUFFERS, &value) &&
  155. value != 0)
  156. printf (" GLX aux buffers: %d\n", value);
  157. if (!glXGetConfig (dpy, vip, GLX_DEPTH_SIZE, &value))
  158. printf (" GLX depth size: %d\n", value);
  159. if (!glXGetConfig (dpy, vip, GLX_STENCIL_SIZE, &value) &&
  160. value != 0)
  161. printf (" GLX stencil size: %d\n", value);
  162. # ifdef GLX_SAMPLE_BUFFERS_SGIS
  163. if (!glXGetConfig (dpy, vip, GLX_SAMPLE_BUFFERS_SGIS, &value) &&
  164. value != 0)
  165. {
  166. int bufs = value;
  167. if (!glXGetConfig (dpy, vip, GLX_SAMPLES_SGIS, &value))
  168. printf (" GLX multisamplers: %d (%d)\n", bufs, value);
  169. }
  170. # endif
  171. if (!glXGetConfig (dpy, vip, GLX_TRANSPARENT_TYPE_EXT, &value) &&
  172. value != GLX_NONE_EXT)
  173. {
  174. if (value == GLX_NONE_EXT)
  175. printf (" GLX transparency: none\n");
  176. else if (value == GLX_TRANSPARENT_INDEX_EXT)
  177. {
  178. if (!glXGetConfig (dpy, vip, GLX_TRANSPARENT_INDEX_VALUE_EXT,&value))
  179. printf (" GLX transparency: indexed (%d)\n", value);
  180. }
  181. else if (value == GLX_TRANSPARENT_RGB_EXT)
  182. {
  183. int r=0, g=0, b=0, a=0;
  184. glXGetConfig (dpy, vip, GLX_TRANSPARENT_RED_VALUE_EXT, &r);
  185. glXGetConfig (dpy, vip, GLX_TRANSPARENT_GREEN_VALUE_EXT, &g);
  186. glXGetConfig (dpy, vip, GLX_TRANSPARENT_BLUE_VALUE_EXT, &b);
  187. glXGetConfig (dpy, vip, GLX_TRANSPARENT_ALPHA_VALUE_EXT, &a);
  188. printf (" GLX transparency: RGBA (%2d, %2d, %2d, %2d)\n",
  189. r, g, b, a);
  190. }
  191. }
  192. }
  193. #endif /* HAVE_GLX */
  194. #ifdef HAVE_OVERLAY /* Added by jwz, 11-Nov-99 */
  195. /* If the server's root window contains a SERVER_OVERLAY_VISUALS property,
  196. then that identifies the visuals which correspond to the video hardware's
  197. overlay planes. Windows created in these kinds of visuals may have
  198. transparent pixels that let other layers shine through.
  199. This might not be an X Consortium standard, but it turns out that
  200. SGI, HP, DEC, and IBM all use this same mechanism. So that's close
  201. enough for me.
  202. Documentation on the SERVER_OVERLAY_VISUALS property can be found at:
  203. http://www.hp.com/xwindow/sharedInfo/Whitepapers/Visuals/server_overlay_visuals.html
  204. */
  205. struct overlay
  206. {
  207. CARD32 visual_id;
  208. CARD32 transparency; /* 0: none; 1: pixel; 2: mask */
  209. CARD32 value; /* the transparent pixel */
  210. CARD32 layer; /* -1: underlay; 0: normal; 1: popup; 2: overlay */
  211. };
  212. struct overlay_list
  213. {
  214. int count;
  215. struct overlay *list;
  216. };
  217. static struct overlay_list *overlays = 0;
  218. static void
  219. find_overlay_info (dpy)
  220. Display *dpy;
  221. {
  222. int screen;
  223. Atom OVERLAY = XInternAtom (dpy, "SERVER_OVERLAY_VISUALS", False);
  224. overlays = (struct overlay_list *) calloc (sizeof (struct overlay_list),
  225. ScreenCount (dpy));
  226. for (screen = 0; screen < ScreenCount (dpy); screen++)
  227. {
  228. Window window = RootWindow (dpy, screen);
  229. Atom actual_type;
  230. int actual_format;
  231. unsigned long nitems, bytes_after;
  232. struct overlay *data = 0;
  233. int result = XGetWindowProperty (dpy, window, OVERLAY,
  234. 0, (65536 / sizeof (long)), False,
  235. OVERLAY, &actual_type, &actual_format,
  236. &nitems, &bytes_after,
  237. (unsigned char **) &data);
  238. if (result == Success &&
  239. actual_type == OVERLAY &&
  240. actual_format == 32 &&
  241. nitems > 0)
  242. {
  243. overlays[screen].count = (nitems /
  244. (sizeof(struct overlay) / sizeof(CARD32)));
  245. overlays[screen].list = data;
  246. }
  247. else if (data)
  248. XFree((char *) data);
  249. }
  250. }
  251. static void
  252. print_overlay_visual_info (vip)
  253. XVisualInfo *vip;
  254. {
  255. int i;
  256. int vis = vip->visualid;
  257. int scr = vip->screen;
  258. if (!overlays) return;
  259. for (i = 0; i < overlays[scr].count; i++)
  260. if (vis == overlays[scr].list[i].visual_id)
  261. {
  262. struct overlay *ov = &overlays[scr].list[i];
  263. printf (" Overlay info: layer %ld (%s), ",
  264. (long) ov->layer,
  265. (ov->layer == -1 ? "underlay" :
  266. ov->layer == 0 ? "normal" :
  267. ov->layer == 1 ? "popup" :
  268. ov->layer == 2 ? "overlay" : "???"));
  269. if (ov->transparency == 1)
  270. printf ("transparent pixel %lu\n", (unsigned long) ov->value);
  271. else if (ov->transparency == 2)
  272. printf ("transparent mask 0x%x\n", (unsigned long) ov->value);
  273. else
  274. printf ("opaque\n");
  275. }
  276. }
  277. #endif /* HAVE_OVERLAY */
  278. void
  279. print_extension_info (dpy)
  280. Display *dpy;
  281. {
  282. int n = 0;
  283. char **extlist = XListExtensions (dpy, &n);
  284. printf ("number of extensions: %d\n", n);
  285. if (extlist) {
  286. register int i;
  287. int opcode, event, error;
  288. qsort(extlist, n, sizeof(char *), StrCmp);
  289. for (i = 0; i < n; i++) {
  290. if (!queryExtensions) {
  291. printf (" %s\n", extlist[i]);
  292. continue;
  293. }
  294. XQueryExtension(dpy, extlist[i], &opcode, &event, &error);
  295. printf (" %s (opcode: %d", extlist[i], opcode);
  296. if (event)
  297. printf (", base event: %d", event);
  298. if (error)
  299. printf (", base error: %d", error);
  300. printf(")\n");
  301. }
  302. /* do not free, Xlib can depend on contents being unaltered */
  303. /* XFreeExtensionList (extlist); */
  304. }
  305. }
  306. void
  307. print_display_info (dpy)
  308. Display *dpy;
  309. {
  310. char dummybuf[40];
  311. char *cp;
  312. int minkeycode, maxkeycode;
  313. int i, n;
  314. long req_size;
  315. XPixmapFormatValues *pmf;
  316. Window focuswin;
  317. int focusrevert;
  318. printf ("name of display: %s\n", DisplayString (dpy));
  319. printf ("version number: %d.%d\n",
  320. ProtocolVersion (dpy), ProtocolRevision (dpy));
  321. printf ("vendor string: %s\n", ServerVendor (dpy));
  322. printf ("vendor release number: %d\n", VendorRelease (dpy));
  323. #ifdef HAVE_GLX
  324. print_glx_versions (dpy);
  325. #endif /* HAVE_GLX */
  326. req_size = XExtendedMaxRequestSize (dpy);
  327. if (!req_size) req_size = XMaxRequestSize (dpy);
  328. printf ("maximum request size: %ld bytes\n", req_size * 4);
  329. printf ("motion buffer size: %d\n", XDisplayMotionBufferSize (dpy));
  330. switch (BitmapBitOrder (dpy)) {
  331. case LSBFirst: cp = "LSBFirst"; break;
  332. case MSBFirst: cp = "MSBFirst"; break;
  333. default:
  334. sprintf (dummybuf, "unknown order %d", BitmapBitOrder (dpy));
  335. cp = dummybuf;
  336. break;
  337. }
  338. printf ("bitmap unit, bit order, padding: %d, %s, %d\n",
  339. BitmapUnit (dpy), cp, BitmapPad (dpy));
  340. switch (ImageByteOrder (dpy)) {
  341. case LSBFirst: cp = "LSBFirst"; break;
  342. case MSBFirst: cp = "MSBFirst"; break;
  343. default:
  344. sprintf (dummybuf, "unknown order %d", ImageByteOrder (dpy));
  345. cp = dummybuf;
  346. break;
  347. }
  348. printf ("image byte order: %s\n", cp);
  349. pmf = XListPixmapFormats (dpy, &n);
  350. printf ("number of supported pixmap formats: %d\n", n);
  351. if (pmf) {
  352. printf ("supported pixmap formats:\n");
  353. for (i = 0; i < n; i++) {
  354. printf (" depth %d, bits_per_pixel %d, scanline_pad %d\n",
  355. pmf[i].depth, pmf[i].bits_per_pixel, pmf[i].scanline_pad);
  356. }
  357. XFree ((char *) pmf);
  358. }
  359. /*
  360. * when we get interfaces to the PixmapFormat stuff, insert code here
  361. */
  362. XDisplayKeycodes (dpy, &minkeycode, &maxkeycode);
  363. printf ("keycode range: minimum %d, maximum %d\n",
  364. minkeycode, maxkeycode);
  365. XGetInputFocus (dpy, &focuswin, &focusrevert);
  366. printf ("focus: ");
  367. switch (focuswin) {
  368. case PointerRoot:
  369. printf ("PointerRoot\n");
  370. break;
  371. case None:
  372. printf ("None\n");
  373. break;
  374. default:
  375. printf("window 0x%lx, revert to ", focuswin);
  376. switch (focusrevert) {
  377. case RevertToParent:
  378. printf ("Parent\n");
  379. break;
  380. case RevertToNone:
  381. printf ("None\n");
  382. break;
  383. case RevertToPointerRoot:
  384. printf ("PointerRoot\n");
  385. break;
  386. default: /* should not happen */
  387. printf ("%d\n", focusrevert);
  388. break;
  389. }
  390. break;
  391. }
  392. print_extension_info (dpy);
  393. printf ("default screen number: %d\n", DefaultScreen (dpy));
  394. printf ("number of screens: %d\n", ScreenCount (dpy));
  395. }
  396. void
  397. print_visual_info (vip)
  398. XVisualInfo *vip;
  399. {
  400. char errorbuf[40]; /* for sprintfing into */
  401. char *class = NULL; /* for printing */
  402. switch (vip->class) {
  403. case StaticGray: class = "StaticGray"; break;
  404. case GrayScale: class = "GrayScale"; break;
  405. case StaticColor: class = "StaticColor"; break;
  406. case PseudoColor: class = "PseudoColor"; break;
  407. case TrueColor: class = "TrueColor"; break;
  408. case DirectColor: class = "DirectColor"; break;
  409. default:
  410. sprintf (errorbuf, "unknown class %d", vip->class);
  411. class = errorbuf;
  412. break;
  413. }
  414. printf (" visual:\n");
  415. printf (" visual id: 0x%lx\n", vip->visualid);
  416. printf (" class: %s\n", class);
  417. printf (" depth: %d plane%s\n", vip->depth,
  418. vip->depth == 1 ? "" : "s");
  419. if (vip->class == TrueColor || vip->class == DirectColor)
  420. printf (" available colormap entries: %d per subfield\n",
  421. vip->colormap_size);
  422. else
  423. printf (" available colormap entries: %d\n",
  424. vip->colormap_size);
  425. printf (" red, green, blue masks: 0x%lx, 0x%lx, 0x%lx\n",
  426. vip->red_mask, vip->green_mask, vip->blue_mask);
  427. printf (" significant bits in color specification: %d bits\n",
  428. vip->bits_per_rgb);
  429. }
  430. void
  431. print_screen_info (dpy, scr)
  432. Display *dpy;
  433. int scr;
  434. {
  435. Screen *s = ScreenOfDisplay (dpy, scr); /* opaque structure */
  436. XVisualInfo viproto; /* fill in for getting info */
  437. XVisualInfo *vip; /* retured info */
  438. int nvi; /* number of elements returned */
  439. int i; /* temp variable: iterator */
  440. char eventbuf[80]; /* want 79 chars per line + nul */
  441. static char *yes = "YES", *no = "NO", *when = "WHEN MAPPED";
  442. double xres, yres;
  443. int ndepths = 0, *depths = NULL;
  444. unsigned int width, height;
  445. /*
  446. * there are 2.54 centimeters to an inch; so there are 25.4 millimeters.
  447. *
  448. * dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch))
  449. * = N pixels / (M inch / 25.4)
  450. * = N * 25.4 pixels / M inch
  451. */
  452. xres = ((((double) DisplayWidth(dpy,scr)) * 25.4) /
  453. ((double) DisplayWidthMM(dpy,scr)));
  454. yres = ((((double) DisplayHeight(dpy,scr)) * 25.4) /
  455. ((double) DisplayHeightMM(dpy,scr)));
  456. printf ("\n");
  457. printf ("screen #%d:\n", scr);
  458. printf (" dimensions: %dx%d pixels (%dx%d millimeters)\n",
  459. DisplayWidth (dpy, scr), DisplayHeight (dpy, scr),
  460. DisplayWidthMM(dpy, scr), DisplayHeightMM (dpy, scr));
  461. printf (" resolution: %dx%d dots per inch\n",
  462. (int) (xres + 0.5), (int) (yres + 0.5));
  463. depths = XListDepths (dpy, scr, &ndepths);
  464. if (!depths) ndepths = 0;
  465. printf (" depths (%d): ", ndepths);
  466. for (i = 0; i < ndepths; i++) {
  467. printf ("%d", depths[i]);
  468. if (i < ndepths - 1) {
  469. putchar (',');
  470. putchar (' ');
  471. }
  472. }
  473. putchar ('\n');
  474. if (depths) XFree ((char *) depths);
  475. printf (" root window id: 0x%lx\n", RootWindow (dpy, scr));
  476. printf (" depth of root window: %d plane%s\n",
  477. DisplayPlanes (dpy, scr),
  478. DisplayPlanes (dpy, scr) == 1 ? "" : "s");
  479. printf (" number of colormaps: minimum %d, maximum %d\n",
  480. MinCmapsOfScreen(s), MaxCmapsOfScreen(s));
  481. printf (" default colormap: 0x%lx\n", DefaultColormap (dpy, scr));
  482. printf (" default number of colormap cells: %d\n",
  483. DisplayCells (dpy, scr));
  484. printf (" preallocated pixels: black %d, white %d\n",
  485. BlackPixel (dpy, scr), WhitePixel (dpy, scr));
  486. printf (" options: backing-store %s, save-unders %s\n",
  487. (DoesBackingStore (s) == NotUseful) ? no :
  488. ((DoesBackingStore (s) == Always) ? yes : when),
  489. DoesSaveUnders (s) ? yes : no);
  490. XQueryBestSize (dpy, CursorShape, RootWindow (dpy, scr), 65535, 65535,
  491. &width, &height);
  492. if (width == 65535 && height == 65535)
  493. printf (" largest cursor: unlimited\n");
  494. else
  495. printf (" largest cursor: %dx%d\n", width, height);
  496. printf (" current input event mask: 0x%lx\n", EventMaskOfScreen (s));
  497. (void) print_event_mask (eventbuf, 79, 4, EventMaskOfScreen (s));
  498. nvi = 0;
  499. viproto.screen = scr;
  500. vip = XGetVisualInfo (dpy, VisualScreenMask, &viproto, &nvi);
  501. printf (" number of visuals: %d\n", nvi);
  502. printf (" default visual id: 0x%lx\n",
  503. XVisualIDFromVisual (DefaultVisual (dpy, scr)));
  504. for (i = 0; i < nvi; i++) {
  505. print_visual_info (vip+i);
  506. #ifdef HAVE_OVERLAY
  507. print_overlay_visual_info (vip+i);
  508. #endif /* HAVE_OVERLAY */
  509. #ifdef HAVE_GLX
  510. print_glx_visual_info (dpy, vip+i);
  511. #endif /* HAVE_GLX */
  512. }
  513. if (vip) XFree ((char *) vip);
  514. }
  515. /*
  516. * The following routine prints out an event mask, wrapping events at nice
  517. * boundaries.
  518. */
  519. #define MASK_NAME_WIDTH 25
  520. static struct _event_table {
  521. char *name;
  522. long value;
  523. } event_table[] = {
  524. { "KeyPressMask ", KeyPressMask },
  525. { "KeyReleaseMask ", KeyReleaseMask },
  526. { "ButtonPressMask ", ButtonPressMask },
  527. { "ButtonReleaseMask ", ButtonReleaseMask },
  528. { "EnterWindowMask ", EnterWindowMask },
  529. { "LeaveWindowMask ", LeaveWindowMask },
  530. { "PointerMotionMask ", PointerMotionMask },
  531. { "PointerMotionHintMask ", PointerMotionHintMask },
  532. { "Button1MotionMask ", Button1MotionMask },
  533. { "Button2MotionMask ", Button2MotionMask },
  534. { "Button3MotionMask ", Button3MotionMask },
  535. { "Button4MotionMask ", Button4MotionMask },
  536. { "Button5MotionMask ", Button5MotionMask },
  537. { "ButtonMotionMask ", ButtonMotionMask },
  538. { "KeymapStateMask ", KeymapStateMask },
  539. { "ExposureMask ", ExposureMask },
  540. { "VisibilityChangeMask ", VisibilityChangeMask },
  541. { "StructureNotifyMask ", StructureNotifyMask },
  542. { "ResizeRedirectMask ", ResizeRedirectMask },
  543. { "SubstructureNotifyMask ", SubstructureNotifyMask },
  544. { "SubstructureRedirectMask ", SubstructureRedirectMask },
  545. { "FocusChangeMask ", FocusChangeMask },
  546. { "PropertyChangeMask ", PropertyChangeMask },
  547. { "ColormapChangeMask ", ColormapChangeMask },
  548. { "OwnerGrabButtonMask ", OwnerGrabButtonMask },
  549. { NULL, 0 }};
  550. int print_event_mask (buf, lastcol, indent, mask)
  551. char *buf; /* string to write into */
  552. int lastcol; /* strlen(buf)+1 */
  553. int indent; /* amount by which to indent */
  554. long mask; /* event mask */
  555. {
  556. struct _event_table *etp;
  557. int len;
  558. int bitsfound = 0;
  559. buf[0] = buf[lastcol] = '\0'; /* just in case */
  560. #define INDENT() { register int i; len = indent; \
  561. for (i = 0; i < indent; i++) buf[i] = ' '; }
  562. INDENT ();
  563. for (etp = event_table; etp->name; etp++) {
  564. if (mask & etp->value) {
  565. if (len + MASK_NAME_WIDTH > lastcol) {
  566. puts (buf);
  567. INDENT ();
  568. }
  569. strcpy (buf+len, etp->name);
  570. len += MASK_NAME_WIDTH;
  571. bitsfound++;
  572. }
  573. }
  574. if (bitsfound) puts (buf);
  575. #undef INDENT
  576. return (bitsfound);
  577. }
  578. void
  579. print_standard_extension_info(dpy, extname, majorrev, minorrev)
  580. Display *dpy;
  581. char *extname;
  582. int majorrev, minorrev;
  583. {
  584. int opcode, event, error;
  585. printf("%s version %d.%d ", extname, majorrev, minorrev);
  586. XQueryExtension(dpy, extname, &opcode, &event, &error);
  587. printf ("opcode: %d", opcode);
  588. if (event)
  589. printf (", base event: %d", event);
  590. if (error)
  591. printf (", base error: %d", error);
  592. printf("\n");
  593. }
  594. int
  595. print_multibuf_info(dpy, extname)
  596. Display *dpy;
  597. char *extname;
  598. {
  599. int i, j; /* temp variable: iterator */
  600. int nmono, nstereo; /* count */
  601. XmbufBufferInfo *mono_info = NULL, *stereo_info = NULL; /* arrays */
  602. static char *fmt =
  603. " visual id, max buffers, depth: 0x%lx, %d, %d\n";
  604. int scr = 0;
  605. int majorrev, minorrev;
  606. if (!XmbufGetVersion(dpy, &majorrev, &minorrev))
  607. return 0;
  608. print_standard_extension_info(dpy, extname, majorrev, minorrev);
  609. for (i = 0; i < ScreenCount (dpy); i++)
  610. {
  611. if (!XmbufGetScreenInfo (dpy, RootWindow(dpy, scr), &nmono, &mono_info,
  612. &nstereo, &stereo_info)) {
  613. fprintf (stderr,
  614. "%s: unable to get multibuffer info for screen %d\n",
  615. ProgramName, scr);
  616. } else {
  617. printf (" screen %d number of mono multibuffer types: %d\n", i, nmono);
  618. for (j = 0; j < nmono; j++) {
  619. printf (fmt, mono_info[j].visualid, mono_info[j].max_buffers,
  620. mono_info[j].depth);
  621. }
  622. printf (" number of stereo multibuffer types: %d\n", nstereo);
  623. for (j = 0; j < nstereo; j++) {
  624. printf (fmt, stereo_info[j].visualid,
  625. stereo_info[j].max_buffers, stereo_info[j].depth);
  626. }
  627. if (mono_info) XFree ((char *) mono_info);
  628. if (stereo_info) XFree ((char *) stereo_info);
  629. }
  630. }
  631. return 1;
  632. } /* end print_multibuf_info */
  633. /* XIE stuff */
  634. #ifdef HAVE_XIE
  635. char *subset_names[] = { NULL, "FULL", "DIS" };
  636. char *align_names[] = { NULL, "Alignable", "Arbitrary" };
  637. char *group_names[] = { /* 0 */ "Default",
  638. /* 2 */ "ColorAlloc",
  639. /* 4 */ "Constrain",
  640. /* 6 */ "ConvertFromRGB",
  641. /* 8 */ "ConvertToRGB",
  642. /* 10 */ "Convolve",
  643. /* 12 */ "Decode",
  644. /* 14 */ "Dither",
  645. /* 16 */ "Encode",
  646. /* 18 */ "Gamut",
  647. /* 20 */ "Geometry",
  648. /* 22 */ "Histogram",
  649. /* 24 */ "WhiteAdjust"
  650. };
  651. int
  652. print_xie_info(dpy, extname)
  653. Display *dpy;
  654. char *extname;
  655. {
  656. XieExtensionInfo *xieInfo;
  657. int i;
  658. int ntechs;
  659. XieTechnique *techs;
  660. XieTechniqueGroup prevGroup;
  661. if (!XieInitialize(dpy, &xieInfo ))
  662. return 0;
  663. print_standard_extension_info(dpy, extname,
  664. xieInfo->server_major_rev, xieInfo->server_minor_rev);
  665. printf(" service class: %s\n", subset_names[xieInfo->service_class]);
  666. printf(" alignment: %s\n", align_names[xieInfo->alignment]);
  667. printf(" uncnst_mantissa: %d\n", xieInfo->uncnst_mantissa);
  668. printf(" uncnst_min_exp: %d\n", xieInfo->uncnst_min_exp);
  669. printf(" uncnst_max_exp: %d\n", xieInfo->uncnst_max_exp);
  670. printf(" cnst_levels:");
  671. for (i = 0; i < xieInfo->n_cnst_levels; i++)
  672. printf(" %d", xieInfo->cnst_levels[i]);
  673. printf("\n");
  674. if (!XieQueryTechniques(dpy, xieValAll, &ntechs, &techs))
  675. return 1;
  676. prevGroup = -1;
  677. for (i = 0; i < ntechs; i++)
  678. {
  679. if (techs[i].group != prevGroup)
  680. {
  681. printf(" technique group: %s\n", group_names[techs[i].group >> 1]);
  682. prevGroup = techs[i].group;
  683. }
  684. printf(" %s\tspeed: %d needs_param: %s number: %d\n",
  685. techs[i].name,
  686. techs[i].speed, (techs[i].needs_param ? "True " : "False"),
  687. techs[i].number);
  688. }
  689. return 1;
  690. } /* end print_xie_info */
  691. #endif /* HAVE_XIE */
  692. #ifdef HAVE_XTEST
  693. int
  694. print_xtest_info(dpy, extname)
  695. Display *dpy;
  696. char *extname;
  697. {
  698. int majorrev, minorrev, foo;
  699. if (!XTestQueryExtension(dpy, &foo, &foo, &majorrev, &minorrev))
  700. return 0;
  701. print_standard_extension_info(dpy, extname, majorrev, minorrev);
  702. return 1;
  703. }
  704. #endif /* HAVE_XTEST */
  705. int
  706. print_sync_info(dpy, extname)
  707. Display *dpy;
  708. char *extname;
  709. {
  710. int majorrev, minorrev;
  711. XSyncSystemCounter *syscounters;
  712. int ncounters, i;
  713. if (!XSyncInitialize(dpy, &majorrev, &minorrev))
  714. return 0;
  715. print_standard_extension_info(dpy, extname, majorrev, minorrev);
  716. syscounters = XSyncListSystemCounters(dpy, &ncounters);
  717. printf(" system counters: %d\n", ncounters);
  718. for (i = 0; i < ncounters; i++)
  719. {
  720. printf(" %s id: 0x%08x resolution_lo: %d resolution_hi: %d\n",
  721. syscounters[i].name, syscounters[i].counter,
  722. XSyncValueLow32(syscounters[i].resolution),
  723. XSyncValueHigh32(syscounters[i].resolution));
  724. }
  725. XSyncFreeSystemCounterList(syscounters);
  726. return 1;
  727. }
  728. int
  729. print_shape_info(dpy, extname)
  730. Display *dpy;
  731. char *extname;
  732. {
  733. int majorrev, minorrev;
  734. if (!XShapeQueryVersion(dpy, &majorrev, &minorrev))
  735. return 0;
  736. print_standard_extension_info(dpy, extname, majorrev, minorrev);
  737. return 1;
  738. }
  739. #ifdef MITSHM
  740. int
  741. print_mitshm_info(dpy, extname)
  742. Display *dpy;
  743. char *extname;
  744. {
  745. int majorrev, minorrev;
  746. Bool sharedPixmaps;
  747. if (!XShmQueryVersion(dpy, &majorrev, &minorrev, &sharedPixmaps))
  748. return 0;
  749. print_standard_extension_info(dpy, extname, majorrev, minorrev);
  750. printf(" shared pixmaps: ");
  751. if (sharedPixmaps)
  752. {
  753. int format = XShmPixmapFormat(dpy);
  754. printf("yes, format: %d\n", format);
  755. }
  756. else
  757. {
  758. printf("no\n");
  759. }
  760. return 1;
  761. }
  762. #endif /* MITSHM */
  763. int
  764. print_dbe_info(dpy, extname)
  765. Display *dpy;
  766. char *extname;
  767. {
  768. int majorrev, minorrev;
  769. XdbeScreenVisualInfo *svi;
  770. int numscreens = 0;
  771. int iscrn, ivis;
  772. if (!XdbeQueryExtension(dpy, &majorrev, &minorrev))
  773. return 0;
  774. print_standard_extension_info(dpy, extname, majorrev, minorrev);
  775. svi = XdbeGetVisualInfo(dpy, (Drawable *)NULL, &numscreens);
  776. for (iscrn = 0; iscrn < numscreens; iscrn++)
  777. {
  778. printf(" Double-buffered visuals on screen %d\n", iscrn);
  779. for (ivis = 0; ivis < svi[iscrn].count; ivis++)
  780. {
  781. printf(" visual id 0x%lx depth %d perflevel %d\n",
  782. svi[iscrn].visinfo[ivis].visual,
  783. svi[iscrn].visinfo[ivis].depth,
  784. svi[iscrn].visinfo[ivis].perflevel);
  785. }
  786. }
  787. XdbeFreeVisualInfo(svi);
  788. return 1;
  789. }
  790. #ifdef HAVE_XRECORD
  791. int
  792. print_record_info(dpy, extname)
  793. Display *dpy;
  794. char *extname;
  795. {
  796. int majorrev, minorrev;
  797. if (!XRecordQueryVersion(dpy, &majorrev, &minorrev))
  798. return 0;
  799. print_standard_extension_info(dpy, extname, majorrev, minorrev);
  800. return 1;
  801. }
  802. #endif /* HAVE_XRECORD */
  803. /* utilities to manage the list of recognized extensions */
  804. typedef int (*ExtensionPrintFunc)(
  805. #if NeedFunctionPrototypes
  806. Display *, char *
  807. #endif
  808. );
  809. typedef struct {
  810. char *extname;
  811. ExtensionPrintFunc printfunc;
  812. Bool printit;
  813. } ExtensionPrintInfo;
  814. ExtensionPrintInfo known_extensions[] =
  815. {
  816. #ifdef MITSHM
  817. {"MIT-SHM", print_mitshm_info, False},
  818. #endif /* MITSHM */
  819. {MULTIBUFFER_PROTOCOL_NAME, print_multibuf_info, False},
  820. {"SHAPE", print_shape_info, False},
  821. {SYNC_NAME, print_sync_info, False},
  822. #ifdef HAVE_XIE
  823. {xieExtName, print_xie_info, False},
  824. #endif /* HAVE_XIE */
  825. #ifdef HAVE_XTEST
  826. {XTestExtensionName, print_xtest_info, False},
  827. #endif /* HAVE_XTEST */
  828. {"DOUBLE-BUFFER", print_dbe_info, False},
  829. #ifdef HAVE_XRECORD
  830. {"RECORD", print_record_info, False}
  831. #endif /* HAVE_XRECORD */
  832. /* add new extensions here */
  833. /* wish list: PEX XKB LBX */
  834. };
  835. int num_known_extensions = sizeof known_extensions / sizeof known_extensions[0];
  836. void
  837. print_known_extensions(f)
  838. FILE *f;
  839. {
  840. int i;
  841. for (i = 0; i < num_known_extensions; i++)
  842. {
  843. fprintf(f, "%s ", known_extensions[i].extname);
  844. }
  845. }
  846. void
  847. mark_extension_for_printing(extname)
  848. char *extname;
  849. {
  850. int i;
  851. if (strcmp(extname, "all") == 0)
  852. {
  853. for (i = 0; i < num_known_extensions; i++)
  854. known_extensions[i].printit = True;
  855. }
  856. else
  857. {
  858. for (i = 0; i < num_known_extensions; i++)
  859. {
  860. if (strcmp(extname, known_extensions[i].extname) == 0)
  861. {
  862. known_extensions[i].printit = True;
  863. return;
  864. }
  865. }
  866. printf("%s extension not supported by %s\n", extname, ProgramName);
  867. }
  868. }
  869. void
  870. print_marked_extensions(dpy)
  871. Display *dpy;
  872. {
  873. int i;
  874. for (i = 0; i < num_known_extensions; i++)
  875. {
  876. if (known_extensions[i].printit)
  877. {
  878. printf("\n");
  879. if (! (*known_extensions[i].printfunc)(dpy,
  880. known_extensions[i].extname))
  881. {
  882. printf("%s extension not supported by server\n",
  883. known_extensions[i].extname);
  884. }
  885. }
  886. }
  887. }
  888. static void usage ()
  889. {
  890. fprintf (stderr, "usage: %s [options]\n", ProgramName);
  891. fprintf (stderr, "-display displayname\tserver to query\n");
  892. fprintf (stderr, "-queryExtensions\tprint info returned by XQueryExtension\n");
  893. fprintf (stderr, "-ext all\t\tprint detailed info for all supported extensions\n");
  894. fprintf (stderr, "-ext extension-name\tprint detailed info for extension-name if one of:\n ");
  895. print_known_extensions(stderr);
  896. fprintf (stderr, "\n");
  897. exit (1);
  898. }
  899. int main (argc, argv)
  900. int argc;
  901. char *argv[];
  902. {
  903. Display *dpy; /* X connection */
  904. char *displayname = NULL; /* server to contact */
  905. int i; /* temp variable: iterator */
  906. Bool multibuf = False;
  907. int mbuf_event_base, mbuf_error_base;
  908. ProgramName = argv[0];
  909. for (i = 1; i < argc; i++) {
  910. char *arg = argv[i];
  911. int len = strlen(arg);
  912. if (!strncmp("-display", arg, len)) {
  913. if (++i >= argc) usage ();
  914. displayname = argv[i];
  915. } else if (!strncmp("-queryExtensions", arg, len)) {
  916. queryExtensions = True;
  917. } else if (!strncmp("-ext", arg, len)) {
  918. if (++i >= argc) usage ();
  919. mark_extension_for_printing(argv[i]);
  920. } else
  921. usage ();
  922. }
  923. dpy = XOpenDisplay (displayname);
  924. if (!dpy) {
  925. fprintf (stderr, "%s: unable to open display \"%s\".\n",
  926. ProgramName, XDisplayName (displayname));
  927. exit (1);
  928. }
  929. #ifdef HAVE_OVERLAY
  930. find_overlay_info (dpy);
  931. #endif /* HAVE_OVERLAY */
  932. print_display_info (dpy);
  933. for (i = 0; i < ScreenCount (dpy); i++) {
  934. print_screen_info (dpy, i);
  935. }
  936. print_marked_extensions(dpy);
  937. XCloseDisplay (dpy);
  938. exit (0);
  939. }