ReactOS 0.4.15-dev-5667-ged97270
ddtest.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactX Diagnosis Application
3 * LICENSE: LGPL - See COPYING in the top level directory
4 * FILE: base/applications/dxdiag/ddtest.c
5 * PURPOSE: ReactX DirectDraw tests
6 * COPYRIGHT: Copyright 2008 Kamil Hornicek
7 *
8 */
9
10#include "precomp.h"
11
15VOID DDUpdateFrame(LPDIRECTDRAWSURFACE lpDDPrimarySurface ,LPDIRECTDRAWSURFACE lpDDBackBuffer, BOOL Fullscreen, INT *posX, INT *posY, INT *gainX, INT *gainY, RECT *rectDD);
16
17#define TEST_DURATION 10000
18#define DD_TEST_WIDTH 640
19#define DD_TEST_HEIGHT 480
20#define DD_TEST_STEP 5
21#define DD_SQUARE_SIZE 100
22#define DD_SQUARE_STEP 2
23
24
25BOOL StartDDTest(HWND hWnd, HINSTANCE hInstance, INT resTestDescription, INT resResult, INT TestNr)
26{
27 WCHAR szTestDescription[256];
28 WCHAR szCaption[256];
29 WCHAR szResult[256];
30 WCHAR szError[256];
32
33 LoadStringW(hInstance, IDS_MAIN_DIALOG, szCaption, sizeof(szCaption) / sizeof(WCHAR));
34 LoadStringW(hInstance, IDS_DDTEST_ERROR, szError, sizeof(szError) / sizeof(WCHAR));
35 LoadStringW(hInstance, resTestDescription, szTestDescription, sizeof(szTestDescription) / sizeof(WCHAR));
36 LoadStringW(hInstance, resResult, szResult, sizeof(szResult) / sizeof(WCHAR));
37
38 if(MessageBox(NULL, szTestDescription, szCaption, MB_YESNO | MB_ICONQUESTION) == IDNO)
39 return FALSE;
40
42
43 switch(TestNr){
44 case 1:
46 break;
47 case 2:
49 break;
50 case 3:
52 break;
53 default:
54 Result = FALSE;
55 }
56
58
59 if(!Result)
60 {
61 MessageBox(NULL, szError, szCaption, MB_OK | MB_ICONERROR);
62 return FALSE;
63 }
64
65 if(MessageBox(NULL, szResult, szCaption, MB_YESNO | MB_ICONQUESTION) == IDYES)
66 return TRUE;
67
68 return FALSE;
69}
70
72{
73 WNDCLASSEX winClass;
74 HWND hWnd;
77 WCHAR szCaption[256];
78
79 winClass.cbSize = sizeof(WNDCLASSEX);
81 winClass.lpfnWndProc = DefWindowProc;
82 winClass.cbClsExtra = 0;
83 winClass.cbWndExtra = 0;
84 winClass.hInstance = hInstance;
85 winClass.hIcon = 0;
86 winClass.hCursor = 0;
87 winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
88 winClass.lpszMenuName = NULL;
89 winClass.lpszClassName = L"ddtest";
91
92 if (!RegisterClassEx(&winClass))
93 return;
94
99
100 if (!hWnd){
101 return;
102 }
103
105 LoadStringW(hInstance, IDS_MAIN_DIALOG, szCaption, sizeof(szCaption) / sizeof(WCHAR));
107 return;
108
112
115}
116
119 MSG msg;
120
121 LPDIRECTDRAW lpDD = NULL;
122 LPDIRECTDRAWSURFACE lpDDSurface = NULL;
123 DDSURFACEDESC DDSurfaceDesc;
124
125 if(DirectDrawCreate(NULL, &lpDD, NULL) != DD_OK)
126 return FALSE;
127
128 if(lpDD->lpVtbl->SetCooperativeLevel(lpDD, hWnd, DDSCL_NORMAL) != DD_OK)
129 {
130 lpDD->lpVtbl->Release(lpDD);
131 return FALSE;
132 }
133
134 /* create our primary surface */
135 ZeroMemory(&DDSurfaceDesc, sizeof(DDSurfaceDesc));
136 DDSurfaceDesc.dwSize = sizeof(DDSurfaceDesc);
137 DDSurfaceDesc.dwFlags = DDSD_CAPS;
138 DDSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
139 DDSurfaceDesc.dwBackBufferCount = 0;
140
141 if(lpDD->lpVtbl->CreateSurface(lpDD, &DDSurfaceDesc, &lpDDSurface, NULL) != DD_OK)
142 {
143 lpDD->lpVtbl->Release(lpDD);
144 return FALSE;
145 }
146
148
149 while (TRUE)
150 {
151 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
152 {
153 if (msg.message == WM_TIMER && TimerID == msg.wParam)
154 break;
157 if (msg.message == WM_PAINT)
158 DDRedrawFrame(lpDDSurface);
159 }
160 }
162 lpDDSurface->lpVtbl->Release(lpDDSurface);
163 lpDD->lpVtbl->Release(lpDD);
164
165return TRUE;
166}
167
169{
170 HDC hdc;
171
172 if (lpDDSurface->lpVtbl->GetDC(lpDDSurface, &hdc) == DD_OK)
173 {
174 RECT rct;
175 HBRUSH BlackBrush, WhiteBrush;
176 BOOL Colour = FALSE;
177
182
183 BlackBrush = CreateSolidBrush(RGB(0,0,0));
184 WhiteBrush = CreateSolidBrush(RGB(255,255,255));
185
186 while((rct.bottom - rct.top) > DD_TEST_STEP){
187 (Colour)? FillRect(hdc, &rct, WhiteBrush) : FillRect(hdc, &rct, BlackBrush);
188 rct.top += DD_TEST_STEP;
189 rct.bottom -= DD_TEST_STEP;
190 rct.left += DD_TEST_STEP;
191 rct.right -= DD_TEST_STEP;
192 Colour = !Colour;
193 }
194 DeleteObject((HGDIOBJ)BlackBrush);
195 DeleteObject((HGDIOBJ)WhiteBrush);
196 lpDDSurface->lpVtbl->ReleaseDC(lpDDSurface, hdc);
197 }
198}
199
200
202 UINT_PTR TimerID, TimerIDUpdate;
203 LPDIRECTDRAW lpDD;
204 LPDIRECTDRAWSURFACE lpDDPrimarySurface;
205 LPDIRECTDRAWSURFACE lpDDBackBuffer;
206 DDSURFACEDESC DDSurfaceDesc;
207 DDSURFACEDESC DDBBSurfaceDesc;
208 DDSCAPS DDSCaps;
209 MSG msg;
210 RECT rectDD;
211 POINT wndPoint;
212 INT posX = 0, posY = 10, xGain = DD_SQUARE_STEP, yGain = DD_SQUARE_STEP;
213
214 if(DirectDrawCreate(NULL, &lpDD, NULL) != DD_OK)
215 return FALSE;
216
217 ZeroMemory(&DDSurfaceDesc, sizeof(DDSurfaceDesc));
218 DDSurfaceDesc.dwSize = sizeof(DDSurfaceDesc);
219
220 if(Fullscreen)
221 {
222 if(lpDD->lpVtbl->SetCooperativeLevel(lpDD, hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) != DD_OK)
223 {
224 lpDD->lpVtbl->Release(lpDD);
225 return FALSE;
226 }
227 if(lpDD->lpVtbl->SetDisplayMode(lpDD, DD_TEST_WIDTH, DD_TEST_HEIGHT, 32) != DD_OK)
228 {
229 lpDD->lpVtbl->Release(lpDD);
230 return FALSE;
231 }
232 DDSurfaceDesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
233 DDSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
234 DDSurfaceDesc.dwBackBufferCount = 1;
235 }
236 else
237 {
238 if(lpDD->lpVtbl->SetCooperativeLevel(lpDD, hWnd, DDSCL_NORMAL) != DD_OK)
239 {
240 lpDD->lpVtbl->Release(lpDD);
241 return FALSE;
242 }
243 DDSurfaceDesc.dwFlags = DDSD_CAPS;
244 DDSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
245 }
246
247
248 if(lpDD->lpVtbl->CreateSurface(lpDD, &DDSurfaceDesc, &lpDDPrimarySurface, NULL) != DD_OK)
249 {
250 lpDD->lpVtbl->Release(lpDD);
251 return FALSE;
252 }
253
254 if(Fullscreen)
255 {
256 DDSCaps.dwCaps = DDSCAPS_BACKBUFFER;
257 if (lpDDPrimarySurface->lpVtbl->GetAttachedSurface(lpDDPrimarySurface, &DDSCaps,&lpDDBackBuffer) != DD_OK)
258 {
259 lpDDPrimarySurface->lpVtbl->Release(lpDDPrimarySurface);
260 lpDD->lpVtbl->Release(lpDD);
261 return FALSE;
262 }
263 }
264 else
265 {
266 /* create our offscreen back buffer */
267 ZeroMemory(&DDBBSurfaceDesc,sizeof(DDBBSurfaceDesc));
268 DDBBSurfaceDesc.dwSize = sizeof(DDBBSurfaceDesc);
269 DDBBSurfaceDesc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
270 DDBBSurfaceDesc.dwHeight = DD_TEST_HEIGHT;
271 DDBBSurfaceDesc.dwWidth = DD_TEST_WIDTH;
272 DDBBSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
273
274 if(lpDD->lpVtbl->CreateSurface(lpDD, &DDBBSurfaceDesc, &lpDDBackBuffer, NULL) != DD_OK)
275 {
276 lpDD->lpVtbl->Release(lpDD);
277 lpDDPrimarySurface->lpVtbl->Release(lpDDPrimarySurface);
278 return FALSE;
279 }
280 wndPoint.x = 0;
281 wndPoint.y = 0;
282 ClientToScreen(hWnd, &wndPoint);
283 GetClientRect(hWnd, &rectDD);
284 OffsetRect(&rectDD, wndPoint.x, wndPoint.y);
285 }
286
287 /* set our timers, TimerID - for test timeout, TimerIDUpdate - for frame updating */
289 TimerIDUpdate = SetTimer(hWnd, 2, (UINT)10, NULL);
290 (void)TimerIDUpdate;
291
292 while (TRUE)
293 {
294 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
295 {
296 if (msg.message == WM_TIMER)
297 {
298 if(msg.wParam == TimerID)
299 {
300 break;
301 }
302 else
303 {
304 DDUpdateFrame(lpDDPrimarySurface,lpDDBackBuffer, Fullscreen,&posX, &posY, &xGain, &yGain, &rectDD);
305 }
306 }
309 }
310 }
311
312 lpDDPrimarySurface->lpVtbl->Release(lpDDPrimarySurface);
313 /* backbuffer is released automatically when in fullscreen */
314 if(!Fullscreen)
315 lpDDBackBuffer->lpVtbl->Release(lpDDBackBuffer);
316 lpDD->lpVtbl->Release(lpDD);
317
318return TRUE;
319}
320
321
322VOID DDUpdateFrame(LPDIRECTDRAWSURFACE lpDDPrimarySurface ,LPDIRECTDRAWSURFACE lpDDBackBuffer, BOOL Fullscreen, INT *posX, INT *posY, INT *gainX, INT *gainY, RECT *rectDD)
323{
324 HDC hdc;
325 DDBLTFX DDBlitFx;
326
327 /* clear back buffer and paint it black */
328 ZeroMemory(&DDBlitFx, sizeof(DDBlitFx));
329 DDBlitFx.dwSize = sizeof(DDBlitFx);
330 DDBlitFx.dwFillColor = 0;
331
332 lpDDBackBuffer->lpVtbl->Blt(lpDDBackBuffer, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &DDBlitFx);
333
334 if (lpDDBackBuffer->lpVtbl->GetDC(lpDDBackBuffer, &hdc) == DD_OK)
335 {
336 RECT rct;
337 HBRUSH WhiteBrush;
338
339 rct.left = *posX;
340 rct.right = *posX+DD_SQUARE_SIZE;
341 rct.top = *posY;
342 rct.bottom = *posY+DD_SQUARE_SIZE;
343
344 WhiteBrush = CreateSolidBrush(RGB(255,255,255));
345 FillRect(hdc, &rct, WhiteBrush);
346
347 if(*posX >= (DD_TEST_WIDTH - DD_SQUARE_SIZE)) *gainX = -(*gainX);
348 if(*posY >= (DD_TEST_HEIGHT - DD_SQUARE_SIZE)) *gainY = -(*gainY);
349 if(*posX < 0) *gainX = -1*(*gainX);
350 if(*posY < 0) *gainY = -1*(*gainY);
351
352 *posX += *gainX;
353 *posY += *gainY;
354
355 lpDDBackBuffer->lpVtbl->ReleaseDC(lpDDBackBuffer, hdc);
356
357 if(Fullscreen)
358 {
359 lpDDPrimarySurface->lpVtbl->Flip(lpDDPrimarySurface, NULL, DDFLIP_WAIT);
360 }
361 else
362 {
363 lpDDPrimarySurface->lpVtbl->Blt(lpDDPrimarySurface, rectDD, lpDDBackBuffer, NULL, DDBLT_WAIT, NULL);
364 }
365 }
366}
#define msg(x)
Definition: auth_time.c:54
HWND hWnd
Definition: settings.c:17
#define IDS_DDPRIMARY_DESCRIPTION
Definition: resource.h:143
#define IDS_DDTEST_ERROR
Definition: resource.h:141
#define IDS_DDTEST_DESCRIPTION
Definition: resource.h:142
#define IDS_DDFULLSCREEN_DESCRIPTION
Definition: resource.h:147
#define IDS_DDOFFSCREEN_RESULT
Definition: resource.h:146
#define IDS_MAIN_DIALOG
Definition: resource.h:103
#define IDS_DDOFFSCREEN_DESCRIPTION
Definition: resource.h:145
#define IDS_DDPRIMARY_RESULT
Definition: resource.h:144
#define IDS_DDFULLSCREEN_RESULT
Definition: resource.h:148
HINSTANCE hInstance
Definition: charmap.c:19
MMRESULT TimerID
Definition: cylfrac.c:37
VOID DDRedrawFrame(LPDIRECTDRAWSURFACE lpDDSurface)
Definition: ddtest.c:168
BOOL StartDDTest(HWND hWnd, HINSTANCE hInstance, INT resTestDescription, INT resResult, INT TestNr)
Definition: ddtest.c:25
#define DD_SQUARE_STEP
Definition: ddtest.c:22
#define DD_TEST_HEIGHT
Definition: ddtest.c:19
#define TEST_DURATION
Definition: ddtest.c:17
BOOL DDPrimarySurfaceTest(HWND hWnd)
Definition: ddtest.c:117
VOID DDTests()
Definition: ddtest.c:71
#define DD_TEST_WIDTH
Definition: ddtest.c:18
#define DD_TEST_STEP
Definition: ddtest.c:20
VOID DDUpdateFrame(LPDIRECTDRAWSURFACE lpDDPrimarySurface, LPDIRECTDRAWSURFACE lpDDBackBuffer, BOOL Fullscreen, INT *posX, INT *posY, INT *gainX, INT *gainY, RECT *rectDD)
Definition: ddtest.c:322
#define DD_SQUARE_SIZE
Definition: ddtest.c:21
BOOL DDOffscreenBufferTest(HWND hWnd, BOOL Fullscreen)
Definition: ddtest.c:201
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
HRESULT WINAPI DirectDrawCreate(LPGUID lpGUID, LPDIRECTDRAW *lplpDD, LPUNKNOWN pUnkOuter)
Definition: main.c:86
static const WCHAR szDescription[]
Definition: provider.c:55
#define RGB(r, g, b)
Definition: precomp.h:62
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
nsrefcnt Release()
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:92
unsigned __int3264 UINT_PTR
Definition: mstsclib_h.h:274
unsigned int UINT
Definition: ndis.h:50
#define L(x)
Definition: ntvdm.h:50
#define WS_POPUP
Definition: pedump.c:616
#define DefWindowProc
Definition: ros2win.h:31
#define DDBLT_COLORFILL
Definition: ddraw.h:555
#define DDSD_WIDTH
Definition: ddraw.h:210
#define DDSCL_NORMAL
Definition: ddraw.h:535
#define DDSD_HEIGHT
Definition: ddraw.h:209
#define DDSCAPS_PRIMARYSURFACE
Definition: ddraw.h:258
#define DDSCL_EXCLUSIVE
Definition: ddraw.h:536
#define DDSCAPS_OFFSCREENPLAIN
Definition: ddraw.h:255
struct IDirectDraw * LPDIRECTDRAW
Definition: ddraw.h:710
#define DD_OK
Definition: ddraw.h:186
#define DDSCAPS_FLIP
Definition: ddraw.h:253
#define DDBLT_WAIT
Definition: ddraw.h:569
#define DDSCAPS_BACKBUFFER
Definition: ddraw.h:251
#define DDSCAPS_3DDEVICE
Definition: ddraw.h:263
#define DDFLIP_WAIT
Definition: ddraw.h:583
#define DDSD_CAPS
Definition: ddraw.h:208
#define DDSD_BACKBUFFERCOUNT
Definition: ddraw.h:212
#define DDSCAPS_COMPLEX
Definition: ddraw.h:252
#define DDSCL_FULLSCREEN
Definition: ddraw.h:532
DWORD dwSize
Definition: ddraw.h:1272
DWORD dwFillColor
Definition: ddraw.h:1310
DWORD dwCaps
Definition: ddraw.h:727
int cbClsExtra
Definition: winuser.h:3194
HINSTANCE hInstance
Definition: winuser.h:3196
HCURSOR hCursor
Definition: winuser.h:3198
LPCSTR lpszMenuName
Definition: winuser.h:3200
HICON hIconSm
Definition: winuser.h:3202
UINT style
Definition: winuser.h:3192
int cbWndExtra
Definition: winuser.h:3195
UINT cbSize
Definition: winuser.h:3191
WNDPROC lpfnWndProc
Definition: winuser.h:3193
LPCSTR lpszClassName
Definition: winuser.h:3201
HICON hIcon
Definition: winuser.h:3197
HBRUSH hbrBackground
Definition: winuser.h:3199
long y
Definition: polytest.cpp:48
long x
Definition: polytest.cpp:48
LONG right
Definition: windef.h:308
LONG bottom
Definition: windef.h:309
LONG top
Definition: windef.h:307
LONG left
Definition: windef.h:306
TW_UINT32 TW_UINT16 TW_UINT16 MSG
Definition: twain.h:1829
int32_t INT
Definition: typedefs.h:58
#define ZeroMemory
Definition: winbase.h:1670
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define BLACK_BRUSH
Definition: wingdi.h:896
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define WM_PAINT
Definition: winuser.h:1610
#define CS_VREDRAW
Definition: winuser.h:653
#define CreateWindowEx
Definition: winuser.h:5745
#define SW_HIDE
Definition: winuser.h:762
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define SM_CYSCREEN
Definition: winuser.h:954
int WINAPI LoadStringW(_In_opt_ HINSTANCE hInstance, _In_ UINT uID, _Out_writes_to_(cchBufferMax, return+1) LPWSTR lpBuffer, _In_ int cchBufferMax)
#define CS_HREDRAW
Definition: winuser.h:648
#define UnregisterClass
Definition: winuser.h:5851
#define CS_DBLCLKS
Definition: winuser.h:646
#define MB_YESNO
Definition: winuser.h:811
BOOL WINAPI ClientToScreen(_In_ HWND, _Inout_ LPPOINT)
UINT_PTR WINAPI SetTimer(_In_opt_ HWND, _In_ UINT_PTR, _In_ UINT, _In_opt_ TIMERPROC)
#define IDI_APPLICATION
Definition: winuser.h:699
#define MB_ICONERROR
Definition: winuser.h:781
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define RegisterClassEx
Definition: winuser.h:5827
#define WM_TIMER
Definition: winuser.h:1732
#define PM_REMOVE
Definition: winuser.h:1186
#define IDNO
Definition: winuser.h:830
#define LoadIcon
Definition: winuser.h:5803
#define PeekMessage
Definition: winuser.h:5820
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5709
#define MB_OK
Definition: winuser.h:784
#define MB_ICONQUESTION
Definition: winuser.h:783
#define MessageBox
Definition: winuser.h:5812
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define CS_OWNDC
Definition: winuser.h:650
#define SW_SHOW
Definition: winuser.h:769
#define SM_CXSCREEN
Definition: winuser.h:953
#define DispatchMessage
Definition: winuser.h:5755
#define IDYES
Definition: winuser.h:829
BOOL WINAPI KillTimer(_In_opt_ HWND, _In_ UINT_PTR)
BOOL WINAPI DestroyWindow(_In_ HWND)
int WINAPI GetSystemMetrics(_In_ int)
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
__wchar_t WCHAR
Definition: xmlstorage.h:180