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