ReactOS  0.4.13-dev-698-g77671f0
sw_pixelformat.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS api tests
3  * LICENSE: BSD - See COPYING.ARM in the top level directory
4  * PURPOSE: Tests pixel formats exposed by the software implementation
5  * PROGRAMMERS: Jérôme Gardou
6  */
7 
8 #include <windows.h>
9 #include <wingdi.h>
10 #include <GL/gl.h>
11 #include <stdio.h>
12 
13 #include "wine/test.h"
14 
16 {
17  static char buffer[1000];
18  static char *p = buffer;
19  char* ret;
20 
21  BOOL first = TRUE;
22 
23  if (p > &buffer[800])
24  p = buffer;
25 
26  *p = 0;
27 
28 #define FLAGS_TO_STR(__x__) \
29  do { \
30  if (flags & __x__) \
31  { \
32  if (!first) strcat(p, " | "); \
33  strcat(p, #__x__); \
34  first = FALSE; \
35  flags &= ~((DWORD)__x__); \
36  } \
37  } while(0)
38 
53 #undef FLAGS_TO_STR
54 
55  if (flags)
56  {
57  char tmp[16];
58  sprintf(tmp, " | 0x%08x", (UINT)flags);
59  strcat(p, tmp);
60  }
61 
62  ret = p;
63 
64  p += strlen(p) + 1;
65 
66  return ret;
67 }
68 
69 struct test_color
70 {
79 };
80 
81 static const struct test_color test_colors_32[] =
82 {
83  {PFD_TYPE_RGBA, 32, 8, 16, 8, 8, 8, 0, 0, 0, 64, 16, 16, 16, 0},
84  {PFD_TYPE_RGBA, 32, 8, 16, 8, 8, 8, 0, 8, 0, 64, 16, 16, 16, 16},
85  {PFD_TYPE_COLORINDEX, 32, 8, 16, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0},
86 };
87 
88 static const struct test_color test_colors_24[] =
89 {
90  {PFD_TYPE_RGBA, 24, 8, 16, 8, 8, 8, 0, 0, 0, 64, 16, 16, 16, 0},
91  {PFD_TYPE_RGBA, 24, 8, 16, 8, 8, 8, 0, 8, 0, 64, 16, 16, 16, 16},
92  {PFD_TYPE_COLORINDEX, 24, 8, 16, 8, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0},
93 };
94 
95 static const struct test_color test_colors_16[] =
96 {
97  {PFD_TYPE_RGBA, 16, 5, 10, 5, 5, 5, 0, 0, 0, 32, 11, 11, 10, 0},
98  {PFD_TYPE_RGBA, 16, 5, 10, 5, 5, 5, 0, 8, 0, 32, 8, 8, 8, 8},
99  {PFD_TYPE_COLORINDEX, 16, 5, 10, 5, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0},
100 };
101 
102 static const struct test_color test_colors_16_565[] =
103 {
104  {PFD_TYPE_RGBA, 16, 5, 11, 6, 5, 5, 0, 0, 0, 32, 11, 11, 10, 0},
105  {PFD_TYPE_RGBA, 16, 5, 11, 6, 5, 5, 0, 8, 0, 32, 8, 8, 8, 8},
106  {PFD_TYPE_COLORINDEX, 16, 5, 11, 6, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0},
107 };
108 
109 static const struct test_color test_colors_8[] =
110 {
111  {PFD_TYPE_RGBA, 8, 3, 0, 3, 3, 2, 6, 0, 0, 32, 11, 11, 10, 0},
112  {PFD_TYPE_RGBA, 8, 3, 0, 3, 3, 2, 6, 8, 0, 32, 8, 8, 8, 8},
113  {PFD_TYPE_COLORINDEX, 8, 3, 0, 3, 3, 2, 6, 0, 0, 0, 0, 0, 0, 0},
114 };
115 
116 static const struct test_color test_colors_4[] =
117 {
118  {PFD_TYPE_RGBA, 4, 1, 0, 1, 1, 1, 2, 0, 0, 16, 5, 6, 5, 0},
119  {PFD_TYPE_RGBA, 4, 1, 0, 1, 1, 1, 2, 8, 0, 16, 4, 4, 4, 4},
120  {PFD_TYPE_COLORINDEX, 4, 1, 0, 1, 1, 1, 2, 0, 0, 0, 0, 0, 0, 0},
121 };
122 
127 
128 static const BYTE test_depths[] = { 32, 16 };
129 
130 static void test_format(HDC hdc, int num_pf, int pf, const struct test_color *colors, BYTE depth, BOOL is_window, BOOL is_double_buffered)
131 {
133  int ret;
134 
135  ret = DescribePixelFormat(hdc, pf, sizeof(pfd), &pfd);
136  ok(ret == num_pf, "Number of pixel formats changed!\n");
137 
138  ok(pfd.nSize == sizeof(pfd), "Wrong nSize for format %i, expected %u, got %u\n", pf, (WORD)sizeof(pfd), pfd.nSize);
139  ok(pfd.nVersion == 1, "Wrong nVersion for format %i, expected 1, got %u\n", pf, pfd.nVersion);
140  if (is_window)
141  {
143 
144  if ((pfd.cColorBits <= 8) && (pfd.iPixelType == PFD_TYPE_RGBA))
146 
147  if (is_double_buffered)
148  {
150  }
151  else
152  {
154  }
156  "Wrong dwFlags for format %i, expected %s (0x%08x), got %s(0x%08x)\n",
158  }
159  else
160  {
162  "Wrong dwFlags for format %i, expected PFD_DRAW_TO_BITMAP | PFD_SUPPORT_GDI | PFD_SUPPORT_OPENGL | PFD_GENERIC_FORMAT, got %s\n",
164  }
165 
166 #define TEST_FIELD(__x__) ok(pfd.__x__ == colors->__x__, "Wrong " #__x__ " for format %i, expected %u, got %u\n", pf, colors->__x__, pfd.__x__)
182 #undef TEST_FIELD
183  ok(pfd.cDepthBits == depth, "Wrong cDepthBit for format %i, expected %u, got %u\n", pf, depth, pfd.cDepthBits);
184 
185  /* the rest is constant */
186 #define TEST_FIELD(__x__, __y__) ok(pfd.__x__ == __y__, "Wrong " #__x__ " for format %i, expected " #__y__ ", got %u\n", pf, (UINT)pfd.__x__)
187  TEST_FIELD(cStencilBits, 8);
188  TEST_FIELD(cAuxBuffers, 0);
189  TEST_FIELD(iLayerType, 0);
190  TEST_FIELD(bReserved, 0);
191  TEST_FIELD(dwLayerMask, 0);
192  TEST_FIELD(dwVisibleMask, 0);
193  TEST_FIELD(dwDamageMask, 0);
194 #undef TEST_FIELD
195 }
196 
197 static void test_screen_colors(const struct test_color **colors)
198 {
199  int pf, num_pf, ret;
200  int i, j;
201  HDC hdc;
202  HWND hwnd;
204 
205  hwnd = CreateWindowA("static", "Title", WS_OVERLAPPEDWINDOW, 10, 10, 200, 200, NULL, NULL,
206  NULL, NULL);
207  if (!hwnd)
208  {
209  ok(hwnd != NULL, "Failed to create a window.\n");
210  return;
211  }
212 
213  hdc = GetDC( hwnd );
214  num_pf = DescribePixelFormat(hdc, 0, 0, NULL);
215  ok(num_pf > 0, "DescribePixelFormat failed.\n");
216 
217  for (pf = 1; pf <= num_pf; pf++)
218  {
219  ret = DescribePixelFormat(hdc, pf, sizeof(pfd), &pfd);
220  ok(ret == num_pf, "Number of pixel formats changed!\n");
221 
223  break;
224  }
225 
226  ok(pf < num_pf, "No generic pixel format!\n");
227 
228  /* First the formats compatible with the DC */
229  for (i = 0; i < 3; i++)
230  {
231  /* Single buffered first */
232  for (j = 0; j < ARRAY_SIZE(test_depths); j++)
233  {
234  test_format(hdc, num_pf, pf++, &colors[0][i], test_depths[j], TRUE, FALSE);
235  }
236 
237  /* Then double buffered */
238  for (j = 0; j < ARRAY_SIZE(test_depths); j++)
239  {
240  test_format(hdc, num_pf, pf++, &colors[0][i], test_depths[j], TRUE, TRUE);
241  }
242  }
243 
244  colors++;
245 
246  /* Then the rest */
247  while (*colors)
248  {
249  for (i = 0; i < 3; i++)
250  {
251  for (j = 0; j < ARRAY_SIZE(test_depths); j++)
252  {
253  test_format(hdc, num_pf, pf++, &colors[0][i], test_depths[j], FALSE, FALSE);
254  }
255  }
256  colors++;
257  }
258 
259  /* We must have tested all generic formats. */
260  ok(pf - 1 == num_pf, "We didn't test all generic formats : tested %u, total %u.\n", pf, num_pf);
261 
262  ReleaseDC( hwnd, hdc );
263  DestroyWindow( hwnd );
264 }
265 
266 static HBITMAP create_dib_section(WORD bpp, void** dstBuffer)
267 {
268  BITMAPINFO bi;
269 
270  memset(&bi, 0, sizeof(BITMAPINFO));
271  bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
272  bi.bmiHeader.biWidth = 4;
273  bi.bmiHeader.biHeight = -4;
274  bi.bmiHeader.biPlanes = 1;
275  bi.bmiHeader.biBitCount = bpp;
277 
278  return CreateDIBSection(0, &bi, DIB_RGB_COLORS, dstBuffer, NULL, 0);
279 }
280 
281 static void test_bitmap_colors(HDC hdc, const struct test_color** colors)
282 {
283  INT num_pf, pf, ret;
285  INT i, j;
286 
287  num_pf = DescribePixelFormat(hdc, 0, 0, NULL);
288  ok(num_pf > 0, "DescribePixelFormat failed.\n");
289 
290  for (pf = 1; pf <= num_pf; pf++)
291  {
292  ret = DescribePixelFormat(hdc, pf, sizeof(pfd), &pfd);
293  ok(ret == num_pf, "Number of pixel formats changed!\n");
294 
296  break;
297  }
298 
299  ok(pf < num_pf, "No generic pixel format!\n");
300 
301  /* First the formats compatible with the DC */
302  for (i = 0; i < 3; i++)
303  {
304  /* Single buffered first */
305  for (j = 0; j < ARRAY_SIZE(test_depths); j++)
306  {
307  test_format(hdc, num_pf, pf++, &colors[0][i], test_depths[j], TRUE, FALSE);
308  }
309 
310  /* Then double buffered */
311  for (j = 0; j < ARRAY_SIZE(test_depths); j++)
312  {
313  test_format(hdc, num_pf, pf++, &colors[0][i], test_depths[j], TRUE, TRUE);
314  }
315  }
316 
317  colors++;
318 
319  /* Then the rest */
320  while (*colors)
321  {
322  for (i = 0; i < 3; i++)
323  {
324  for (j = 0; j < ARRAY_SIZE(test_depths); j++)
325  {
326  test_format(hdc, num_pf, pf++, &colors[0][i], test_depths[j], FALSE, FALSE);
327  }
328  }
329  colors++;
330  }
331 
332  /* We must have tested all generic formats. */
333  ok(pf - 1 == num_pf, "We didn't test all generic formats : tested %u, total %u.\n", pf, num_pf);
334 }
335 
336 static void test_bitmap_formats(const struct test_color ** colors)
337 {
338  HBITMAP oldBmp, dib;
339  HDC hdc;
340  static const INT bpps [] = {4, 8, 16, 24, 32};
341  INT i;
342  void* dib_buffer;
343 
345  ok (hdc != NULL, "Failed creating a memory DC.\n");
346 
347  for (i = 0; i < ARRAY_SIZE(bpps); i++)
348  {
349  dib = create_dib_section(bpps[i], &dib_buffer);
350  ok(dib != NULL, "Failed to create DIB for %u bpp\n", bpps[i]);
351 
352  oldBmp = SelectObject(hdc, dib);
353  ok (oldBmp != NULL, "Failed to select the DIB\n");
354 
355  trace("testing DIB %ubpp\n", bpps[i]);
356  /* For mem DC, this is always the depth of the screen which is taken into account */
357  test_bitmap_colors(hdc, colors);
358 
359  SelectObject(hdc, oldBmp);
360  DeleteObject(dib);
361  }
362 }
363 
364 START_TEST(sw_pixelformat)
365 {
367  INT ret;
368  DWORD orig_bpp;
369  static const WORD bit_depths[] = {8, 16, 24, 32};
371  INT i;
372 
374  ok (ret != 0, "EnumDisplaySettings failed.\n");
375  orig_bpp = devMode.dmBitsPerPel;
376 
377  for (i = 0; i < ARRAY_SIZE(bit_depths); i++)
378  {
379  devMode.dmBitsPerPel = bit_depths[i];
382  {
383  trace("Testing %ubpp\n", bit_depths[i]);
384  test_screen_colors(colors[i]);
385  test_bitmap_formats(colors[i]);
386  }
387  else
388  {
389  skip("Unable to switch to %ubpp\n", bit_depths[i]);
390  }
391  }
392 
393  devMode.dmBitsPerPel = orig_bpp;
395 }
const DOCKBAR PVOID HWND HWND * hwnd
Definition: tooldock.h:22
#define trace(...)
Definition: kmt_test.h:217
#define TRUE
Definition: types.h:120
static const struct test_color * test_colors_8bpp[]
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1454
#define PFD_NEED_SYSTEM_PALETTE
Definition: wingdi.h:308
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
HDC WINAPI GetDC(_In_opt_ HWND)
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
static HGLOBAL devMode
Definition: print.c:52
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
const GLint * first
Definition: glext.h:5794
#define PFD_DRAW_TO_BITMAP
Definition: wingdi.h:303
#define PFD_NEED_PALETTE
Definition: wingdi.h:307
static HDC
Definition: imagelist.c:92
static const struct test_color test_colors_8[]
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
#define PFD_GENERIC_ACCELERATED
Definition: wingdi.h:312
GLuint buffer
Definition: glext.h:5915
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
BYTE cGreenShift
static const BYTE test_depths[]
BOOL WINAPI DestroyWindow(_In_ HWND)
int32_t INT
Definition: typedefs.h:56
#define ENUM_CURRENT_SETTINGS
Definition: winuser.h:179
static const struct test_color test_colors_32[]
BYTE cAccumBlueBits
static const struct test_color test_colors_4[]
#define TEST_FIELD(__x__)
#define PFD_DOUBLEBUFFER
Definition: wingdi.h:300
BYTE cAccumGreenBits
#define sprintf(buf, format,...)
Definition: sprintf.c:55
static void test_bitmap_colors(HDC hdc, const struct test_color **colors)
#define FLAGS_TO_STR(__x__)
LONG WINAPI ChangeDisplaySettingsExW(LPCWSTR lpszDeviceName, LPDEVMODEW lpDevMode, HWND hwnd, DWORD dwflags, LPVOID lParam)
Definition: display.c:585
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int BOOL
Definition: ntddk_ex.h:94
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
static const struct test_color test_colors_24[]
int WINAPI DescribePixelFormat(_In_ HDC hdc, _In_ int iPixelFormat, _In_ UINT nBytes, _Out_writes_bytes_opt_(nBytes) LPPIXELFORMATDESCRIPTOR ppfd)
DWORD biCompression
Definition: amvideo.idl:35
#define ok(value,...)
#define CreateWindowA(a, b, c, d, e, f, g, h, i, j, k)
Definition: winuser.h:4216
smooth NULL
Definition: ftsmooth.c:416
static const struct test_color * test_colors_24bpp[]
#define PFD_TYPE_COLORINDEX
Definition: wingdi.h:296
static const struct test_color * test_colors_16bpp[]
BOOL WINAPI EnumDisplaySettingsW(LPCWSTR lpszDeviceName, DWORD iModeNum, LPDEVMODEW lpDevMode)
Definition: display.c:408
BYTE cAlphaShift
#define PFD_SWAP_LAYER_BUFFERS
Definition: wingdi.h:311
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
static const struct test_color test_colors_16_565[]
#define PFD_SUPPORT_GDI
Definition: wingdi.h:304
static void test_format(HDC hdc, int num_pf, int pf, const struct test_color *colors, BYTE depth, BOOL is_window, BOOL is_double_buffered)
#define DISP_CHANGE_SUCCESSFUL
Definition: winuser.h:190
unsigned short WORD
Definition: ntddk_ex.h:93
unsigned long DWORD
Definition: ntddk_ex.h:95
static void test_screen_colors(const struct test_color **colors)
GLbitfield flags
Definition: glext.h:7161
#define PFD_TYPE_RGBA
Definition: wingdi.h:295
static PIXELFORMATDESCRIPTOR pfd
Definition: ssstars.c:67
static void test_bitmap_formats(const struct test_color **colors)
GLint GLint GLsizei GLsizei GLsizei depth
Definition: gl.h:1546
int ret
HDC hdc
Definition: main.c:9
#define PFD_SWAP_EXCHANGE
Definition: wingdi.h:309
#define PFD_GENERIC_FORMAT
Definition: wingdi.h:306
unsigned char BYTE
Definition: mem.h:68
#define PFD_STEREO
Definition: wingdi.h:301
#define ARRAY_SIZE(a)
Definition: main.h:24
HBITMAP WINAPI CreateDIBSection(HDC hDC, CONST BITMAPINFO *BitmapInfo, UINT Usage, VOID **Bits, HANDLE hSection, DWORD dwOffset)
Definition: bitmap.c:197
unsigned int UINT
Definition: ndis.h:50
START_TEST(sw_pixelformat)
static const BYTE dib[]
Definition: ole2.c:201
BYTE cAccumAlphaBits
#define skip(...)
#define PFD_SWAP_COPY
Definition: wingdi.h:310
#define WS_OVERLAPPEDWINDOW
Definition: pedump.c:637
DWORD bpp
Definition: surface.c:181
static HBITMAP create_dib_section(WORD bpp, void **dstBuffer)
static HBITMAP
Definition: button.c:44
#define PFD_SUPPORT_OPENGL
Definition: wingdi.h:305
GLfloat GLfloat p
Definition: glext.h:8902
#define DIB_RGB_COLORS
Definition: wingdi.h:366
#define PFD_DRAW_TO_WINDOW
Definition: wingdi.h:302
#define memset(x, y, z)
Definition: compat.h:39
#define PFD_SUPPORT_COMPOSITION
Definition: wingdi.h:313
#define BI_RGB
Definition: precomp.h:34
BYTE cAccumRedBits
static const struct test_color * test_colors_32bpp[]
static char * str_dbg_pfd_flags(DWORD flags)
static const struct test_color test_colors_16[]