Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
7.2 KiB

  1. #include <stddef.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. #include <assert.h>
  6. #include <windows.h>
  7. /*
  8. * Structures
  9. */
  10. typedef struct {
  11. char *Name;
  12. DWORD Value;
  13. } DWFLAGS;
  14. /*
  15. * Prototypes
  16. */
  17. VOID PrintPixelFormat( HDC Dc, int PixelFormatId );
  18. void PrintRangeOfPixelFormat( HDC Dc, int Start, int End );
  19. char * dwFlags2String( DWORD dwFlags, char *Buf );
  20. static char *iLayerType2String( BYTE iLayerType, char *Buf );
  21. void PrintUsage( void );
  22. void PrintHelp( void );
  23. /*
  24. * defines
  25. */
  26. #define EXIT_OK EXIT_SUCCESS
  27. #define EXIT_ERROR EXIT_FAILURE
  28. #define EXIT_USAGE 15
  29. #define EXIT_HELP 14
  30. /*
  31. * globals
  32. */
  33. char *ProgramName; /* Pointer to the name of the program */
  34. int CountOnly = 0; /* Count only flag */
  35. /*
  36. * main
  37. */
  38. int
  39. main( int argc, char **argv )
  40. {
  41. HDC Dc;
  42. int AvailableIds;
  43. int ExitCode = EXIT_OK;
  44. ProgramName = *argv;
  45. for (argc--, argv++ ; argc && '-' == **argv ; argc--, argv++ )
  46. {
  47. switch ( *(++(*argv)) )
  48. {
  49. case 'c':
  50. case 'C':
  51. CountOnly = !CountOnly;
  52. break;
  53. case 'h':
  54. case 'H':
  55. case '?':
  56. PrintHelp();
  57. exit(EXIT_HELP);
  58. break;
  59. default:
  60. PrintUsage();
  61. exit(EXIT_USAGE);
  62. break;
  63. }
  64. }
  65. /*
  66. * Get a DC for the display
  67. */
  68. Dc = GetDC(NULL);
  69. /*
  70. * Get the total number of pixel formats
  71. */
  72. AvailableIds = DescribePixelFormat( Dc, 0, 0, NULL );
  73. /*
  74. * If only a count was requested, we are done
  75. */
  76. if (CountOnly)
  77. {
  78. printf("%d\n", AvailableIds);
  79. exit(AvailableIds);
  80. }
  81. /*
  82. * If there are more arguments, print only the Ids requested
  83. */
  84. if ( argc )
  85. {
  86. for ( ; argc ; argc--, argv++ )
  87. {
  88. int StartId, EndId, Scanned;
  89. Scanned = sscanf(*argv, "%i-%i", &StartId, &EndId );
  90. if ( 1 == Scanned )
  91. {
  92. PrintPixelFormat( Dc, StartId );
  93. }
  94. else if ( 2 == Scanned )
  95. {
  96. PrintRangeOfPixelFormat( Dc, StartId, EndId );
  97. }
  98. else
  99. {
  100. fprintf(stderr, "%s: Error: expected a number, found: '%s'\n",
  101. ProgramName, *argv );
  102. }
  103. }
  104. }
  105. else
  106. {
  107. /*
  108. * Print them all
  109. */
  110. PrintRangeOfPixelFormat( Dc, 1, AvailableIds );
  111. }
  112. /*
  113. * Don't need the DC anymore
  114. */
  115. ReleaseDC( NULL, Dc );
  116. return(ExitCode);
  117. }
  118. VOID
  119. PrintPixelFormat( HDC Dc, int PixelFormatId )
  120. {
  121. char Buf[256];
  122. PIXELFORMATDESCRIPTOR Pfd;
  123. if ( DescribePixelFormat( Dc, PixelFormatId, sizeof(Pfd), &Pfd ) )
  124. {
  125. printf("PixelFormat: %d\n", PixelFormatId );
  126. printf("nSize %d\n", Pfd.nSize );
  127. printf("nVersion %d\n", Pfd.nVersion );
  128. printf("dwFlags 0x%08lX (%s)\n", Pfd.dwFlags,
  129. dwFlags2String( Pfd.dwFlags, Buf ));
  130. printf("iPixelType %d, (%s)\n", Pfd.iPixelType,
  131. (PFD_TYPE_RGBA == Pfd.iPixelType) ?
  132. "TYPE_RGBA" : "TYPE_COLORINDEX");
  133. printf("cColorBits %d\n", Pfd.cColorBits );
  134. printf("cRedBits %d\n", Pfd.cRedBits );
  135. printf("cRedShift %d\n", Pfd.cRedShift );
  136. printf("cGreenBits %d\n", Pfd.cGreenBits );
  137. printf("cGreenShift %d\n", Pfd.cGreenShift );
  138. printf("cBlueBits %d\n", Pfd.cBlueBits );
  139. printf("cBlueShift %d\n", Pfd.cBlueShift );
  140. printf("cAlphaBits %d\n", Pfd.cAlphaBits );
  141. printf("cAlphaShift %d\n", Pfd.cAlphaShift );
  142. printf("cAccumBits %d\n", Pfd.cAccumBits );
  143. printf("cAccumRedBits %d\n", Pfd.cAccumRedBits );
  144. printf("cAccumGreenBits %d\n", Pfd.cAccumGreenBits );
  145. printf("cAccumBlueBits %d\n", Pfd.cAccumBlueBits );
  146. printf("cAccumAlphaBits %d\n", Pfd.cAccumAlphaBits );
  147. printf("cDepthBits %d\n", Pfd.cDepthBits );
  148. printf("cStencilBits %d\n", Pfd.cStencilBits );
  149. printf("cAuxBuffers %d\n", Pfd.cAuxBuffers );
  150. printf("iLayerType %d, (%s)\n", Pfd.iLayerType,
  151. iLayerType2String( Pfd.iLayerType, Buf ) );
  152. printf("bReserved %d\n", Pfd.bReserved );
  153. printf("dwLayerMask %d\n", Pfd.dwLayerMask );
  154. printf("dwVisibleMask %d\n", Pfd.dwVisibleMask );
  155. printf("dwDamageMask %d\n", Pfd.dwDamageMask );
  156. printf("\n");
  157. }
  158. else
  159. {
  160. printf("Could not get pixel format id: %d\n", PixelFormatId );
  161. }
  162. }
  163. void
  164. PrintRangeOfPixelFormat( HDC Dc, int Start, int End )
  165. {
  166. if ( End >= Start )
  167. {
  168. for ( ; Start <= End; Start++ )
  169. {
  170. PrintPixelFormat( Dc, Start );
  171. }
  172. }
  173. else
  174. {
  175. for ( ; Start >= End; Start-- )
  176. {
  177. PrintPixelFormat( Dc, Start );
  178. }
  179. }
  180. }
  181. char *
  182. dwFlags2String( DWORD dwFlags, char *Buf )
  183. {
  184. int i;
  185. static DWFLAGS dwFlagsData[] = {
  186. { "PFD_DOUBLEBUFFER" , PFD_DOUBLEBUFFER },
  187. { "PFD_STEREO" , PFD_STEREO },
  188. { "PFD_DRAW_TO_WINDOW" , PFD_DRAW_TO_WINDOW },
  189. { "PFD_DRAW_TO_BITMAP" , PFD_DRAW_TO_BITMAP },
  190. { "PFD_SUPPORT_GDI" , PFD_SUPPORT_GDI },
  191. { "PFD_SUPPORT_OPENGL" , PFD_SUPPORT_OPENGL },
  192. { "PFD_GENERIC_FORMAT" , PFD_GENERIC_FORMAT },
  193. { "PFD_NEED_PALETTE" , PFD_NEED_PALETTE },
  194. { "PFD_NEED_SYSTEM_PALETTE" , PFD_NEED_SYSTEM_PALETTE },
  195. { "PFD_GENERIC_ACCELERATED" , PFD_GENERIC_ACCELERATED },
  196. { NULL , 0 }
  197. };
  198. *Buf = '\0';
  199. for ( i = 0; NULL != dwFlagsData[i].Name ; i++ )
  200. {
  201. if ( dwFlags & dwFlagsData[i].Value )
  202. {
  203. strcat( Buf, dwFlagsData[i].Name );
  204. strcat( Buf, " ");
  205. }
  206. }
  207. return( Buf );
  208. }
  209. /********************************************************************/
  210. static char *
  211. iLayerType2String( BYTE iLayerType, char *Buf )
  212. {
  213. switch ( iLayerType )
  214. {
  215. case PFD_MAIN_PLANE:
  216. strcpy( Buf, "PFD_MAIN_PLANE");
  217. break;
  218. case PFD_OVERLAY_PLANE:
  219. strcpy( Buf, "PFD_OVERLAY_PLANE");
  220. break;
  221. case PFD_UNDERLAY_PLANE:
  222. strcpy( Buf, "PFD_UNDERLAY_PLANE");
  223. break;
  224. default:
  225. strcpy( Buf, "UNKNOWN");
  226. break;
  227. }
  228. return( Buf );
  229. }
  230. void
  231. PrintUsage( void )
  232. {
  233. printf("usage: %s -ch? [PfdId[-RangePfd]...]\n", ProgramName );
  234. }
  235. void
  236. PrintHelp( void )
  237. {
  238. PrintUsage();
  239. printf("\n");
  240. printf(" -?|h Print this information.\n");
  241. printf(" -c Count the number of available pixel formats. (exit code is count)\n");
  242. printf("\n");
  243. printf("PfdId is the pixel format id requested\n");
  244. printf("A range of pixel formats is specified with StarId-EndId\n");
  245. printf("\n");
  246. printf("The following prints Ids 5 to 7: %s 5-7\n", ProgramName);
  247. }