ReactOS 0.4.16-dev-178-g8ba6102
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 * PURPOSE: ReactX DirectDraw tests
5 * COPYRIGHT: Copyright 2008 Kamil Horníček
6 *
7 */
8
9#include "precomp.h"
10
14VOID DDUpdateFrame(LPDIRECTDRAWSURFACE lpDDPrimarySurface ,LPDIRECTDRAWSURFACE lpDDBackBuffer, BOOL Fullscreen, INT *posX, INT *posY, INT *gainX, INT *gainY, RECT *rectDD);
15
16#define TEST_DURATION 10000
17#define DD_TEST_WIDTH 640
18#define DD_TEST_HEIGHT 480
19#define DD_TEST_STEP 5
20#define DD_SQUARE_SIZE 100
21#define DD_SQUARE_STEP 2
22
23
24BOOL StartDDTest(HWND hWnd, HINSTANCE hInstance, INT resTestDescription, INT resResult, INT TestNr)
25{
26 WCHAR szTestDescription[256];
27 WCHAR szCaption[256];
28 WCHAR szResult[256];
29 WCHAR szError[256];
31
32 LoadStringW(hInstance, IDS_MAIN_DIALOG, szCaption, sizeof(szCaption) / sizeof(WCHAR));
33 LoadStringW(hInstance, IDS_DDTEST_ERROR, szError, sizeof(szError) / sizeof(WCHAR));
34 LoadStringW(hInstance, resTestDescription, szTestDescription, sizeof(szTestDescription) / sizeof(WCHAR));
35 LoadStringW(hInstance, resResult, szResult, sizeof(szResult) / sizeof(WCHAR));
36
37 if(MessageBox(NULL, szTestDescription, szCaption, MB_YESNO | MB_ICONQUESTION) == IDNO)
38 return FALSE;
39
41
42 switch(TestNr){
43 case 1:
45 break;
46 case 2:
48 break;
49 case 3:
51 break;
52 default:
53 Result = FALSE;
54 }
55
57
58 if(!Result)
59 {
60 MessageBox(NULL, szError, szCaption, MB_OK | MB_ICONERROR);
61 return FALSE;
62 }
63
64 if(MessageBox(NULL, szResult, szCaption, MB_YESNO | MB_ICONQUESTION) == IDYES)
65 return TRUE;
66
67 return FALSE;
68}
69
71{
72 WNDCLASSEX winClass;
73 HWND hWnd;
76 WCHAR szCaption[256];
77
78 winClass.cbSize = sizeof(WNDCLASSEX);
80 winClass.lpfnWndProc = DefWindowProc;
81 winClass.cbClsExtra = 0;
82 winClass.cbWndExtra = 0;
83 winClass.hInstance = hInstance;
84 winClass.hIcon = 0;
85 winClass.hCursor = 0;
86 winClass.hbrBackground = (HBRUSH)GetStockObject(BLACK_BRUSH);
87 winClass.lpszMenuName = NULL;
88 winClass.lpszClassName = L"ddtest";
90
91 if (!RegisterClassEx(&winClass))
92 return;
93
98
99 if (!hWnd){
100 return;
101 }
102
104 LoadStringW(hInstance, IDS_MAIN_DIALOG, szCaption, sizeof(szCaption) / sizeof(WCHAR));
106 return;
107
111
114}
115
118 MSG msg;
119
120 LPDIRECTDRAW lpDD = NULL;
121 LPDIRECTDRAWSURFACE lpDDSurface = NULL;
122 DDSURFACEDESC DDSurfaceDesc;
123
124 if(DirectDrawCreate(NULL, &lpDD, NULL) != DD_OK)
125 return FALSE;
126
127 if(lpDD->lpVtbl->SetCooperativeLevel(lpDD, hWnd, DDSCL_NORMAL) != DD_OK)
128 {
129 lpDD->lpVtbl->Release(lpDD);
130 return FALSE;
131 }
132
133 /* create our primary surface */
134 ZeroMemory(&DDSurfaceDesc, sizeof(DDSurfaceDesc));
135 DDSurfaceDesc.dwSize = sizeof(DDSurfaceDesc);
136 DDSurfaceDesc.dwFlags = DDSD_CAPS;
137 DDSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_3DDEVICE;
138 DDSurfaceDesc.dwBackBufferCount = 0;
139
140 if(lpDD->lpVtbl->CreateSurface(lpDD, &DDSurfaceDesc, &lpDDSurface, NULL) != DD_OK)
141 {
142 lpDD->lpVtbl->Release(lpDD);
143 return FALSE;
144 }
145
147
148 while (TRUE)
149 {
150 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
151 {
152 if (msg.message == WM_TIMER && TimerID == msg.wParam)
153 break;
156 if (msg.message == WM_PAINT)
157 DDRedrawFrame(lpDDSurface);
158 }
159 }
161 lpDDSurface->lpVtbl->Release(lpDDSurface);
162 lpDD->lpVtbl->Release(lpDD);
163
164return TRUE;
165}
166
168{
169 HDC hdc;
170
171 if (lpDDSurface->lpVtbl->GetDC(lpDDSurface, &hdc) == DD_OK)
172 {
173 RECT rct;
174 HBRUSH BlackBrush, WhiteBrush;
175 BOOL Colour = FALSE;
176
181
182 BlackBrush = CreateSolidBrush(RGB(0,0,0));
183 WhiteBrush = CreateSolidBrush(RGB(255,255,255));
184
185 while((rct.bottom - rct.top) > DD_TEST_STEP){
186 (Colour)? FillRect(hdc, &rct, WhiteBrush) : FillRect(hdc, &rct, BlackBrush);
187 rct.top += DD_TEST_STEP;
188 rct.bottom -= DD_TEST_STEP;
189 rct.left += DD_TEST_STEP;
190 rct.right -= DD_TEST_STEP;
191 Colour = !Colour;
192 }
193 DeleteObject((HGDIOBJ)BlackBrush);
194 DeleteObject((HGDIOBJ)WhiteBrush);
195 lpDDSurface->lpVtbl->ReleaseDC(lpDDSurface, hdc);
196 }
197}
198
199
201 UINT_PTR TimerID, TimerIDUpdate;
202 LPDIRECTDRAW lpDD;
203 LPDIRECTDRAWSURFACE lpDDPrimarySurface;
204 LPDIRECTDRAWSURFACE lpDDBackBuffer;
205 DDSURFACEDESC DDSurfaceDesc;
206 DDSURFACEDESC DDBBSurfaceDesc;
207 DDSCAPS DDSCaps;
208 MSG msg;
209 RECT rectDD;
210 POINT wndPoint;
211 INT posX = 0, posY = 10, xGain = DD_SQUARE_STEP, yGain = DD_SQUARE_STEP;
212
213 if(DirectDrawCreate(NULL, &lpDD, NULL) != DD_OK)
214 return FALSE;
215
216 ZeroMemory(&DDSurfaceDesc, sizeof(DDSurfaceDesc));
217 DDSurfaceDesc.dwSize = sizeof(DDSurfaceDesc);
218
219 if(Fullscreen)
220 {
221 if(lpDD->lpVtbl->SetCooperativeLevel(lpDD, hWnd, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN) != DD_OK)
222 {
223 lpDD->lpVtbl->Release(lpDD);
224 return FALSE;
225 }
226 if(lpDD->lpVtbl->SetDisplayMode(lpDD, DD_TEST_WIDTH, DD_TEST_HEIGHT, 32) != DD_OK)
227 {
228 lpDD->lpVtbl->Release(lpDD);
229 return FALSE;
230 }
231 DDSurfaceDesc.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
232 DDSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX;
233 DDSurfaceDesc.dwBackBufferCount = 1;
234 }
235 else
236 {
237 if(lpDD->lpVtbl->SetCooperativeLevel(lpDD, hWnd, DDSCL_NORMAL) != DD_OK)
238 {
239 lpDD->lpVtbl->Release(lpDD);
240 return FALSE;
241 }
242 DDSurfaceDesc.dwFlags = DDSD_CAPS;
243 DDSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
244 }
245
246
247 if(lpDD->lpVtbl->CreateSurface(lpDD, &DDSurfaceDesc, &lpDDPrimarySurface, NULL) != DD_OK)
248 {
249 lpDD->lpVtbl->Release(lpDD);
250 return FALSE;
251 }
252
253 if(Fullscreen)
254 {
255 DDSCaps.dwCaps = DDSCAPS_BACKBUFFER;
256 if (lpDDPrimarySurface->lpVtbl->GetAttachedSurface(lpDDPrimarySurface, &DDSCaps,&lpDDBackBuffer) != DD_OK)
257 {
258 lpDDPrimarySurface->lpVtbl->Release(lpDDPrimarySurface);
259 lpDD->lpVtbl->Release(lpDD);
260 return FALSE;
261 }
262 }
263 else
264 {
265 /* create our offscreen back buffer */
266 ZeroMemory(&DDBBSurfaceDesc,sizeof(DDBBSurfaceDesc));
267 DDBBSurfaceDesc.dwSize = sizeof(DDBBSurfaceDesc);
268 DDBBSurfaceDesc.dwFlags = DDSD_CAPS | DDSD_WIDTH | DDSD_HEIGHT;
269 DDBBSurfaceDesc.dwHeight = DD_TEST_HEIGHT;
270 DDBBSurfaceDesc.dwWidth = DD_TEST_WIDTH;
271 DDBBSurfaceDesc.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
272
273 if(lpDD->lpVtbl->CreateSurface(lpDD, &DDBBSurfaceDesc, &lpDDBackBuffer, NULL) != DD_OK)
274 {
275 lpDD->lpVtbl->Release(lpDD);
276 lpDDPrimarySurface->lpVtbl->Release(lpDDPrimarySurface);
277 return FALSE;
278 }
279 wndPoint.x = 0;
280 wndPoint.y = 0;
281 ClientToScreen(hWnd, &wndPoint);
282 GetClientRect(hWnd, &rectDD);
283 OffsetRect(&rectDD, wndPoint.x, wndPoint.y);
284 }
285
286 /* set our timers, TimerID - for test timeout, TimerIDUpdate - for frame updating */
288 TimerIDUpdate = SetTimer(hWnd, 2, (UINT)10, NULL);
289 (void)TimerIDUpdate;
290
291 while (TRUE)
292 {
293 if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
294 {
295 if (msg.message == WM_TIMER)
296 {
297 if(msg.wParam == TimerID)
298 {
299 break;
300 }
301 else
302 {
303 DDUpdateFrame(lpDDPrimarySurface,lpDDBackBuffer, Fullscreen,&posX, &posY, &xGain, &yGain, &rectDD);
304 }
305 }
308 }
309 }
310
311 lpDDPrimarySurface->lpVtbl->Release(lpDDPrimarySurface);
312 /* backbuffer is released automatically when in fullscreen */
313 if(!Fullscreen)
314 lpDDBackBuffer->lpVtbl->Release(lpDDBackBuffer);
315 lpDD->lpVtbl->Release(lpDD);
316
317return TRUE;
318}
319
320
321VOID DDUpdateFrame(LPDIRECTDRAWSURFACE lpDDPrimarySurface ,LPDIRECTDRAWSURFACE lpDDBackBuffer, BOOL Fullscreen, INT *posX, INT *posY, INT *gainX, INT *gainY, RECT *rectDD)
322{
323 HDC hdc;
324 DDBLTFX DDBlitFx;
325
326 /* clear back buffer and paint it black */
327 ZeroMemory(&DDBlitFx, sizeof(DDBlitFx));
328 DDBlitFx.dwSize = sizeof(DDBlitFx);
329 DDBlitFx.dwFillColor = 0;
330
331 lpDDBackBuffer->lpVtbl->Blt(lpDDBackBuffer, NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &DDBlitFx);
332
333 if (lpDDBackBuffer->lpVtbl->GetDC(lpDDBackBuffer, &hdc) == DD_OK)
334 {
335 RECT rct;
336 HBRUSH WhiteBrush;
337
338 rct.left = *posX;
339 rct.right = *posX+DD_SQUARE_SIZE;
340 rct.top = *posY;
341 rct.bottom = *posY+DD_SQUARE_SIZE;
342
343 WhiteBrush = CreateSolidBrush(RGB(255,255,255));
344 FillRect(hdc, &rct, WhiteBrush);
345
346 if(*posX >= (DD_TEST_WIDTH - DD_SQUARE_SIZE)) *gainX = -(*gainX);
347 if(*posY >= (DD_TEST_HEIGHT - DD_SQUARE_SIZE)) *gainY = -(*gainY);
348 if(*posX < 0) *gainX = -1*(*gainX);
349 if(*posY < 0) *gainY = -1*(*gainY);
350
351 *posX += *gainX;
352 *posY += *gainY;
353
354 lpDDBackBuffer->lpVtbl->ReleaseDC(lpDDBackBuffer, hdc);
355
356 if(Fullscreen)
357 {
358 lpDDPrimarySurface->lpVtbl->Flip(lpDDPrimarySurface, NULL, DDFLIP_WAIT);
359 }
360 else
361 {
362 lpDDPrimarySurface->lpVtbl->Blt(lpDDPrimarySurface, rectDD, lpDDBackBuffer, NULL, DDBLT_WAIT, NULL);
363 }
364 }
365}
#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:167
BOOL StartDDTest(HWND hWnd, HINSTANCE hInstance, INT resTestDescription, INT resResult, INT TestNr)
Definition: ddtest.c:24
#define DD_SQUARE_STEP
Definition: ddtest.c:21
#define DD_TEST_HEIGHT
Definition: ddtest.c:18
#define TEST_DURATION
Definition: ddtest.c:16
BOOL DDPrimarySurfaceTest(HWND hWnd)
Definition: ddtest.c:116
VOID DDTests()
Definition: ddtest.c:70
#define DD_TEST_WIDTH
Definition: ddtest.c:17
#define DD_TEST_STEP
Definition: ddtest.c:19
VOID DDUpdateFrame(LPDIRECTDRAWSURFACE lpDDPrimarySurface, LPDIRECTDRAWSURFACE lpDDBackBuffer, BOOL Fullscreen, INT *posX, INT *posY, INT *gainX, INT *gainY, RECT *rectDD)
Definition: ddtest.c:321
#define DD_SQUARE_SIZE
Definition: ddtest.c:20
BOOL DDOffscreenBufferTest(HWND hWnd, BOOL Fullscreen)
Definition: ddtest.c:200
#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:71
unsigned int BOOL
Definition: ntddk_ex.h:94
pKey DeleteObject()
nsrefcnt Release()
HDC hdc
Definition: main.c:9
static HDC
Definition: imagelist.c:88
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:3207
HINSTANCE hInstance
Definition: winuser.h:3209
HCURSOR hCursor
Definition: winuser.h:3211
LPCSTR lpszMenuName
Definition: winuser.h:3213
HICON hIconSm
Definition: winuser.h:3215
UINT style
Definition: winuser.h:3205
int cbWndExtra
Definition: winuser.h:3208
UINT cbSize
Definition: winuser.h:3204
WNDPROC lpfnWndProc
Definition: winuser.h:3206
LPCSTR lpszClassName
Definition: winuser.h:3214
HICON hIcon
Definition: winuser.h:3210
HBRUSH hbrBackground
Definition: winuser.h:3212
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:1712
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:1623
#define CS_VREDRAW
Definition: winuser.h:658
#define CreateWindowEx
Definition: winuser.h:5767
#define SW_HIDE
Definition: winuser.h:771
BOOL WINAPI TranslateMessage(_In_ const MSG *)
BOOL WINAPI ShowWindow(_In_ HWND, _In_ int)
#define SM_CYSCREEN
Definition: winuser.h:963
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:653
#define UnregisterClass
Definition: winuser.h:5873
#define CS_DBLCLKS
Definition: winuser.h:651
#define MB_YESNO
Definition: winuser.h:820
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:704
#define MB_ICONERROR
Definition: winuser.h:790
BOOL WINAPI GetClientRect(_In_ HWND, _Out_ LPRECT)
#define RegisterClassEx
Definition: winuser.h:5849
#define WM_TIMER
Definition: winuser.h:1745
#define PM_REMOVE
Definition: winuser.h:1199
#define IDNO
Definition: winuser.h:839
#define LoadIcon
Definition: winuser.h:5825
#define PeekMessage
Definition: winuser.h:5842
WNDCLASSEXA WNDCLASSEX
Definition: winuser.h:5731
#define MB_OK
Definition: winuser.h:793
#define MB_ICONQUESTION
Definition: winuser.h:792
#define MessageBox
Definition: winuser.h:5834
BOOL WINAPI OffsetRect(_Inout_ LPRECT, _In_ int, _In_ int)
#define CS_OWNDC
Definition: winuser.h:655
#define SW_SHOW
Definition: winuser.h:778
#define SM_CXSCREEN
Definition: winuser.h:962
#define DispatchMessage
Definition: winuser.h:5777
#define IDYES
Definition: winuser.h:838
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:409
__wchar_t WCHAR
Definition: xmlstorage.h:180