DXGL r30 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r29‎ | r30 | r31 >
Date:20:54, 18 December 2011
Author:admin
Status:new
Tags:
Comment:
Add mouse pointer test to DXGLTest
Fix high CPU usage in DXGLTest
Modified paths:
  • /dxgltest/Tests2D.cpp (modified) (history)
  • /dxgltest/dxgltest.cpp (modified) (history)

Diff [purge]

Index: dxgltest/Tests2D.cpp
@@ -25,6 +25,7 @@
2626 void InitTest(int test);
2727 void RunTestTimed(int test);
2828 void RunTestLooped(int test);
 29+void RunTestMouse(int test, UINT Msg, WPARAM wParam, LPARAM lParam);
2930 inline unsigned int rand32(unsigned int &n)
3031 {
3132 return n=(((unsigned int) 1103515245 * n) + (unsigned int) 12345) %
@@ -47,7 +48,7 @@
4849 HWND hWnd;
4950 int testnum;
5051 unsigned int randnum;
51 -int testtypes[] = {0,1,0,1,0,1};
 52+int testtypes[] = {0,1,0,1,0,1,2};
5253
5354 typedef struct
5455 {
@@ -70,6 +71,7 @@
7172 POINT p;
7273 RECT srcrect,destrect;
7374 HRESULT error;
 75+ PAINTSTRUCT paintstruct;
7476 switch(Msg)
7577 {
7678 case WM_CLOSE:
@@ -114,6 +116,7 @@
115117 break;
116118 case WM_SIZE:
117119 case WM_PAINT:
 120+ BeginPaint(hWnd,&paintstruct);
118121 if(!fullscreen)
119122 {
120123 p.x = 0;
@@ -124,7 +127,21 @@
125128 SetRect(&srcrect,0,0,width,height);
126129 if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
127130 }
128 - return FALSE;
 131+ EndPaint(hWnd,&paintstruct);
 132+ return 0;
 133+ case WM_MOUSEMOVE:
 134+ RunTestMouse(testnum,WM_MOUSEMOVE,wParam,lParam);
 135+ if(!fullscreen)
 136+ {
 137+ p.x = 0;
 138+ p.y = 0;
 139+ ClientToScreen(hWnd,&p);
 140+ GetClientRect(hWnd,&destrect);
 141+ OffsetRect(&destrect,p.x,p.y);
 142+ SetRect(&srcrect,0,0,width,height);
 143+ if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
 144+ }
 145+ break;
129146 default:
130147 return DefWindowProc(hWnd,Msg,wParam,lParam);
131148 }
@@ -131,10 +148,91 @@
132149 return FALSE;
133150 }
134151
 152+int ddtestnum;
 153+int ddver;
135154
 155+void RunTestMouse(int test, UINT Msg, WPARAM wParam, LPARAM lParam)
 156+{
 157+ DDSURFACEDESC2 ddsd;
 158+ ddsd.dwSize = sizeof(DDSURFACEDESC2);
 159+ DDBLTFX bltfx;
 160+ unsigned char *surface;
 161+ int bytes;
 162+ unsigned int x,y;
 163+ bool out = false;
 164+ bool msgbottom = false;
 165+ TCHAR message[256];
 166+ message[0] = 0;
 167+ HDC hDC;
 168+ switch(test)
 169+ {
 170+ case 6:
 171+ x = LOWORD(lParam);
 172+ y = HIWORD(lParam);
 173+ ZeroMemory(&bltfx,sizeof(DDBLTFX));
 174+ bltfx.dwSize = sizeof(DDBLTFX);
 175+ bltfx.dwFillColor = 0;
 176+ ddsrender->Blt(NULL,NULL,NULL,DDBLT_COLORFILL,&bltfx);
 177+ if(ddver > 3)ddsd.dwSize = sizeof(DDSURFACEDESC2);
 178+ else ddsd.dwSize = sizeof(DDSURFACEDESC);
 179+ ddsrender->GetSurfaceDesc(&ddsd);
 180+ switch(ddsd.ddpfPixelFormat.dwRGBBitCount)
 181+ {
 182+ case 8:
 183+ bytes=1;
 184+ break;
 185+ case 15:
 186+ case 16:
 187+ bytes=2;
 188+ break;
 189+ case 24:
 190+ bytes=3;
 191+ break;
 192+ case 32:
 193+ default:
 194+ bytes=4;
 195+ }
 196+ _tcscpy(message,_T("Message: "));
 197+ switch(Msg)
 198+ {
 199+ case WM_MOUSEMOVE:
 200+ _tcscat(message,_T("WM_MOUSEMOVE "));
 201+ break;
 202+ default:
 203+ _tcscat(message,_T("unknown "));
 204+ }
 205+ _tcscat(message,_T("Keys: "));
 206+ if(wParam & MK_CONTROL) _tcscat(message, _T("CTRL "));
 207+ if(wParam & MK_SHIFT) _tcscat(message,_T("SHIFT "));
 208+ _tcscat(message,_T("Buttons: "));
 209+ if(wParam & MK_LBUTTON) _tcscat(message,_T("L "));
 210+ if(wParam & MK_MBUTTON) _tcscat(message,_T("M "));
 211+ if(wParam & MK_RBUTTON) _tcscat(message,_T("R "));
 212+ if(wParam & MK_XBUTTON1) _tcscat(message,_T("X1 "));
 213+ if(wParam & MK_XBUTTON2) _tcscat(message,_T("X2 "));
 214+ // Add X and Y
 215+ ddsrender->Lock(NULL,&ddsd,DDLOCK_WAIT,NULL);
 216+ surface = (unsigned char *)ddsd.lpSurface;
 217+ if((x > ddsd.dwWidth) || (y > ddsd.dwHeight))
 218+ {
 219+ out = true;
 220+ _tcscat(message,_T(" OUT OF BOUNDS"));
 221+ }
 222+ else surface[(x*bytes)+(y*ddsd.lPitch)] = 0xFF;
 223+ ddsrender->Unlock(NULL);
 224+ ddsrender->GetDC(&hDC);
 225+ if(out)SetBkColor(hDC,RGB(255,0,0));
 226+ else SetBkColor(hDC,RGB(0,0,255));
 227+ SetTextColor(hDC,RGB(255,255,255));
 228+ if(y > ddsd.dwHeight / 2) TextOut(hDC,0,0,message,_tcslen(message));
 229+ else TextOut(hDC,0,ddsd.dwHeight-16,message,_tcslen(message));
 230+ ddsrender->ReleaseDC(hDC);
 231+ break;
 232+ default:
 233+ break;
 234+ }
 235+}
136236
137 -int ddtestnum;
138 -int ddver;
139237 const TCHAR wndclassname2d[] = _T("DDTestWndClass");
140238 void RunTest2D(int testnum, int width, int height, int bpp, int refresh, int backbuffers, int apiver,
141239 double fps, bool fullscreen, bool resizable)
@@ -168,7 +266,8 @@
169267 wc.hInstance = hinstance;
170268 wc.hIcon = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_DXGL));
171269 wc.hIconSm = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_DXGLSM));
172 - wc.hCursor = LoadCursor(NULL,IDC_ARROW);
 270+ if(testnum == 6) wc.hCursor = LoadCursor(NULL,IDC_CROSS);
 271+ else wc.hCursor = LoadCursor(NULL,IDC_ARROW);
173272 wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
174273 wc.lpszClassName = wndclassname2d;
175274 if(!RegisterClassEx(&wc))
@@ -259,7 +358,7 @@
260359 }
261360 }
262361 }
263 - else
 362+ else if(testtypes[testnum] == 0)
264363 {
265364 StartTimer(hWnd,WM_APP,fps);
266365 while(GetMessage(&Msg, NULL, 0, 0) > 0)
@@ -268,6 +367,14 @@
269368 DispatchMessage(&Msg);
270369 }
271370 }
 371+ else
 372+ {
 373+ while(GetMessage(&Msg, NULL, 0, 0) > 0)
 374+ {
 375+ TranslateMessage(&Msg);
 376+ DispatchMessage(&Msg);
 377+ }
 378+ }
272379 UnregisterClass(wndclassname2d,hinstance);
273380 StopTimer();
274381 }
Index: dxgltest/dxgltest.cpp
@@ -198,7 +198,8 @@
199199 {1, 7, 0, 7, true, 1.0, false, false, _T("GDI Test patterns (GetDC() test)")},
200200 {1, 7, 0, 0, false, 0.0, false, false, _T("Random GDI patterns (does not clear screen between paints)")},
201201 {1, 7, 0, 1, true, 60.0, false, false, _T("BltFast background and sprites")},
202 - {1, 7, 0, 0, false, 0.0, false, false, _T("Random color fill Blt() patterns")}
 202+ {1, 7, 0, 0, false, 0.0, false, false, _T("Random color fill Blt() paterns")},
 203+ {1, 7, 0, 0, false, 0.0, false, false, _T("Mouse pointer event test")}
203204 };
204205 const int END_2D = __LINE__ - 4;
205206 const int numtests2d = END_2D - START_2D;