DXGL r816 - Code Review

Jump to navigation Jump to search
Repository:DXGL
Revision:r815‎ | r816 | r817 >
Date:13:30, 20 May 2018
Author:admin
Status:new
Tags:
Comment:
Add SetCursorPos() test, with validation from GetCursorPos().
Modified paths:
  • /dxglcfg/tests.cpp (modified) (history)

Diff [purge]

Index: dxglcfg/tests.cpp
@@ -395,7 +395,7 @@
396396 wc.hInstance = hinstance;
397397 wc.hIcon = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_DXGL));
398398 wc.hIconSm = LoadIcon(hinstance,MAKEINTRESOURCE(IDI_DXGLSM));
399 - if(testnum == 6) wc.hCursor = LoadCursor(NULL,IDC_CROSS);
 399+ if((testnum == 6) || (testnum == 16)) wc.hCursor = LoadCursor(NULL,IDC_CROSS);
400400 else wc.hCursor = LoadCursor(NULL,IDC_ARROW);
401401 wc.hbrBackground = NULL;
402402 wc.lpszClassName = wndclassname;
@@ -808,6 +808,7 @@
809809 HBRUSH brush;
810810 RECT r;
811811 DDCOLORKEY colorkey;
 812+ DDBLTFX bltfx;
812813 void *bmppointer;
813814 int i;
814815 const DWORD colormasks[7] = { 0xFF0000, 0xFF00, 0xFFFF00, 0xFF, 0xFF00FF, 0xFFFF, 0xFFFFFF };
@@ -817,7 +818,7 @@
818819 error = ddsrender->GetSurfaceDesc(&ddsd);
819820 switch (test)
820821 {
821 - case 0:
 822+ case 0: // Palette and gradients
822823 if (!fullscreen) backbuffers = 0;
823824 buffer = (unsigned char *)malloc(ddsd.lPitch*ddsd.dwHeight);
824825 DrawPalette(ddsd, buffer);
@@ -871,7 +872,7 @@
872873 free(buffer);
873874 if (palette) palette->Release();
874875 break;
875 - case 2:
 876+ case 2: // GDI patterns
876877 if (!fullscreen) backbuffers = 0;
877878 error = ddsrender->GetDC(&hRenderDC);
878879 DrawGDIPatterns(ddsd, hRenderDC, 0);
@@ -946,7 +947,7 @@
947948 }
948949 if (temp1) temp1->Release();
949950 break;
950 - case 4:
 951+ case 4: // BltFast sprites
951952 ddsrender->GetSurfaceDesc(&ddsd);
952953 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
953954 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
@@ -1010,7 +1011,7 @@
10111012 sprites[i].yvelocity = randfloat(5);
10121013 }
10131014 break;
1014 - case 6:
 1015+ case 6: // Mouse pointer test
10151016 ddsrender->GetSurfaceDesc(&ddsd);
10161017 ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
10171018 ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
@@ -1072,7 +1073,7 @@
10731074 DeleteDC(memorydc);
10741075 DeleteObject(bitmap);
10751076 break;
1076 - case 7:
 1077+ case 7: // ROP patterns
10771078 if (!fullscreen) backbuffers = 0;
10781079 ddsrender->GetSurfaceDesc(&ddsd);
10791080 ddsrender->GetPalette(&palette);
@@ -1115,7 +1116,7 @@
11161117 DrawROPPatterns(ddsrender, sprites, backbuffers, ddver, bpp, ddcaps.dwRops,hWnd,palette);
11171118 if (palette) palette->Release();
11181119 break;
1119 - case 8:
 1120+ case 8: // Rotated Blt patterns
11201121 ddsrender->GetSurfaceDesc(&ddsd);
11211122 sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
11221123 sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
@@ -1137,8 +1138,8 @@
11381139 ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
11391140 counter = 0;
11401141 break;
1141 - case 10:
1142 - case 11:
 1142+ case 10: // Source Key Override test
 1143+ case 11: // Destination Key Override Test
11431144 ddsrender->GetSurfaceDesc(&ddsd);
11441145 sprites[0].ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
11451146 sprites[0].ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
@@ -1179,7 +1180,7 @@
11801181 sprites[2].surface->Unlock(NULL);
11811182 counter = 0;
11821183 break;
1183 - case 12:
 1184+ case 12: // Solid cube
11841185 MakeCube3D(5, 2);
11851186 ZeroMemory(&material, sizeof(D3DMATERIAL7));
11861187 material.ambient.r = 0.5f;
@@ -1218,7 +1219,7 @@
12191220 lights[0].dvAttenuation1 = 0.4f;
12201221 error = d3d7dev->SetLight(0, &lights[0]);
12211222 break;
1222 - case 13:
 1223+ case 13: // Solid cube
12231224 MakeCube3D(5, 2);
12241225 cleartexformats();
12251226 d3d7dev->EnumTextureFormats(gettexformat, NULL);
@@ -1264,10 +1265,10 @@
12651266 lights[0].dvAttenuation1 = 0.4f;
12661267 error = d3d7dev->SetLight(0, &lights[0]);
12671268 break;
1268 - case 15:
 1269+ case 15: // Vertex pipeline test
12691270 ZeroMemory(lights, 8 * sizeof(D3DLIGHT7));
12701271 MakeLights();
1271 - case 14:
 1272+ case 14: // Pixel pipeline test
12721273 MakeCube3D(5, 8);
12731274 ZeroMemory(&material, sizeof(D3DMATERIAL7));
12741275 material.ambient.r = 1.0f;
@@ -1299,6 +1300,34 @@
13001301 error = d3d7dev->SetTransform(D3DTRANSFORMSTATE_PROJECTION, &matProj);
13011302 texshaderstate = defaulttexshaderstate;
13021303 break;
 1304+ case 16: // SetCursorPos test
 1305+ ddsrender->GetSurfaceDesc(&ddsd);
 1306+ ddsd.dwFlags = DDSD_CAPS | DDSD_HEIGHT | DDSD_WIDTH;
 1307+ ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN;
 1308+ ddsd.dwWidth = GetSystemMetrics(SM_CXCURSOR);
 1309+ ddsd.dwHeight = GetSystemMetrics(SM_CYCURSOR);
 1310+ sprites[0].width = (float)ddsd.dwWidth;
 1311+ sprites[0].height = (float)ddsd.dwHeight;
 1312+ sprites[0].rect.left = sprites[0].rect.top = 0;
 1313+ sprites[0].rect.right = ddsd.dwWidth;
 1314+ sprites[0].rect.bottom = ddsd.dwHeight;
 1315+ memcpy(&sprites[0].ddsd, &ddsd, sizeof(DDSURFACEDESC2));
 1316+ colorkey.dwColorSpaceHighValue = colorkey.dwColorSpaceLowValue = 0;
 1317+ ddinterface->CreateSurface(&sprites[0].ddsd, &sprites[0].surface, NULL);
 1318+ sprites[0].surface->SetColorKey(DDCKEY_SRCBLT, &colorkey);
 1319+ bltfx.dwSize = sizeof(DDBLTFX);
 1320+ bltfx.dwFillColor = 0;
 1321+ sprites[0].surface->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &bltfx);
 1322+ cursor = LoadCursor(NULL, IDC_ARROW);
 1323+ sprites[0].surface->GetDC(&hRenderDC);
 1324+ DrawIcon(hRenderDC, 0, 0, cursor);
 1325+ sprites[0].surface->ReleaseDC(hRenderDC);
 1326+ ddsrender->GetSurfaceDesc(&ddsd);
 1327+ sprites[0].x = randfloat((float)ddsd.dwWidth);
 1328+ sprites[0].y = randfloat((float)ddsd.dwHeight);
 1329+ sprites[0].xvelocity = randfloat(5);
 1330+ sprites[0].yvelocity = randfloat(5);
 1331+ break;
13031332 default:
13041333 break;
13051334 }
@@ -1313,7 +1342,7 @@
13141343 HDC hDCdest, hDCsrc;
13151344 RECT r1, r2;
13161345 int x, y;
1317 - POINT p;
 1346+ POINT p, p2;
13181347 RECT srcrect, destrect;
13191348 HRESULT error;
13201349 D3DMATRIX mat;
@@ -1744,7 +1773,7 @@
17451774 if (ddsurface && ddsrender) ddsurface->Blt(&r1, ddsrender, &r2, DDBLT_WAIT, NULL);
17461775 }
17471776 break;
1748 - case 12:
 1777+ case 12: // Solid cube
17491778 error = d3d7dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, bgcolor, 1.0, 0);
17501779 time = (float)clock() / (float)CLOCKS_PER_SEC;
17511780 mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
@@ -1774,7 +1803,7 @@
17751804 if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
17761805 }
17771806 break;
1778 - case 13:
 1807+ case 13: // Textured cube
17791808 error = d3d7dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, bgcolor, 1.0, 0);
17801809 time = (float)clock() / (float)CLOCKS_PER_SEC;
17811810 mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
@@ -1811,7 +1840,7 @@
18121841 if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
18131842 }
18141843 break;
1815 - case 14:
 1844+ case 14: // Pixel pipeline test
18161845 error = d3d7dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, bgcolor, 1.0, 0);
18171846 time = (float)clock() / (float)CLOCKS_PER_SEC;
18181847 mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
@@ -1841,7 +1870,7 @@
18421871 if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
18431872 }
18441873 break;
1845 - case 15:
 1874+ case 15: // Vertex pipeline test
18461875 error = d3d7dev->Clear(0, NULL, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, bgcolor, 1.0, 0);
18471876 time = (float)clock() / (float)CLOCKS_PER_SEC;
18481877 mat._11 = mat._22 = mat._33 = mat._44 = 1.0f;
@@ -1871,6 +1900,122 @@
18721901 if (ddsurface && ddsrender)error = ddsurface->Blt(&destrect, ddsrender, &srcrect, DDBLT_WAIT, NULL);
18731902 }
18741903 break;
 1904+ case 16: // SetCursorPos test
 1905+ if (backbuffers) ddsrender->GetAttachedSurface(&ddscaps, &temp1);
 1906+ else temp1 = ddsrender;
 1907+ temp1->GetDC(&hDCdest);
 1908+ brush = CreateSolidBrush(0);
 1909+ destrect.left = 0;
 1910+ destrect.right = width;
 1911+ destrect.top = 0;
 1912+ destrect.bottom = height;
 1913+ FillRect(hDCdest, &destrect, brush);
 1914+ DeleteObject(brush);
 1915+ _tcscpy(message, _T("SetCursorPos test - Mouse should follow pointer."));
 1916+ displayfonts[0] = CreateFont(16, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
 1917+ ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
 1918+ DEFAULT_PITCH, _T("Fixedsys"));
 1919+ displayfonts[1] = (HFONT)SelectObject(hDCdest, displayfonts[0]);
 1920+ SetTextColor(hDCdest, RGB(255, 255, 255));
 1921+ SetBkColor(hDCdest, RGB(0, 0, 255));
 1922+ TextOut(hDCdest, 0, 0, message, _tcslen(message));
 1923+ GetTextExtentPoint(hDCdest, _T("A"), 1, &textsize);
 1924+ sprites[0].x += sprites[0].xvelocity;
 1925+ if (sprites[0].xvelocity < 0 && sprites[0].x < 0) sprites[0].xvelocity = -sprites[0].xvelocity;
 1926+ if (sprites[0].xvelocity > 0 && sprites[0].x >= width) sprites[0].xvelocity = -sprites[0].xvelocity;
 1927+ sprites[0].y += sprites[0].yvelocity;
 1928+ if (sprites[0].yvelocity < 0 && sprites[0].y < 0) sprites[0].yvelocity = -sprites[0].yvelocity;
 1929+ if (sprites[0].yvelocity > 0 && sprites[0].y >= height) sprites[0].yvelocity = -sprites[0].yvelocity;
 1930+ // Show stats
 1931+ _tcscpy(message, _T("Requested position: X="));
 1932+ _itot(sprites[0].x, number, 10);
 1933+ _tcscat(message, number);
 1934+ _tcscat(message, _T(" Y="));
 1935+ _itot(sprites[0].y, number, 10);
 1936+ _tcscat(message, number);
 1937+ SetBkColor(hDCdest, RGB(0, 0, 127));
 1938+ TextOut(hDCdest, 0, textsize.cy, message, _tcslen(message));
 1939+ if (GetActiveWindow() == hWnd)
 1940+ {
 1941+ if (fullscreen)
 1942+ {
 1943+ SetCursorPos(sprites[0].x, sprites[0].y);
 1944+ GetCursorPos(&p2);
 1945+ }
 1946+ else
 1947+ {
 1948+ p.x = 0;
 1949+ p.y = 0;
 1950+ ClientToScreen(hWnd, &p);
 1951+ SetCursorPos((int)sprites[0].x + p.x, (int)sprites[0].y + p.y);
 1952+ GetCursorPos(&p2);
 1953+ p2.x -= p.x;
 1954+ p2.y -= p.y;
 1955+ }
 1956+ }
 1957+ _tcscpy(message, _T("Actual position: X="));
 1958+ _itot(p2.x, number, 10);
 1959+ _tcscat(message, number);
 1960+ _tcscat(message, _T(" Y="));
 1961+ _itot(p2.y, number, 10);
 1962+ _tcscat(message, number);
 1963+ _tcscat(message, _T(" "));
 1964+ TextOut(hDCdest, 0, 2*textsize.cy, message, _tcslen(message));
 1965+ x = (_tcslen(message)*textsize.cx);
 1966+ if ((p2.x == (LONG)sprites[0].x) && (p2.y == (LONG)sprites[0].y))
 1967+ {
 1968+ SetTextColor(hDCdest, RGB(0, 255, 0));
 1969+ _tcscpy(message, _T("Positions match"));
 1970+ }
 1971+ else
 1972+ {
 1973+ _tcscpy(message, _T("Positions offset by X="));
 1974+ _itot(p2.x - (LONG)sprites[0].x, number, 10);
 1975+ _tcscat(message, number);
 1976+ _tcscat(message, _T(" Y="));
 1977+ _itot(p2.y - (LONG)sprites[0].y, number, 10);
 1978+ _tcscat(message, number);
 1979+ if (((p2.x - (LONG)sprites[0].x <= 2) && (p2.x - (LONG)sprites[0].x >= -2)) &&
 1980+ ((p2.y - (LONG)sprites[0].y <= 2) && (p2.y - (LONG)sprites[0].y >= -2)))
 1981+ SetTextColor(hDCdest, RGB(255, 255, 0));
 1982+ else SetTextColor(hDCdest, RGB(255, 0, 0));
 1983+ }
 1984+ TextOut(hDCdest, x, 2 * textsize.cy, message, _tcslen(message));
 1985+ SelectObject(hDCdest, displayfonts[1]);
 1986+ DeleteObject(displayfonts[0]);
 1987+ temp1->ReleaseDC(hDCdest);
 1988+ if (backbuffers) temp1->Release();
 1989+ if (sprites[0].surface)
 1990+ {
 1991+ if (backbuffers) ddsrender->GetAttachedSurface(&ddscaps, &temp1);
 1992+ else temp1 = ddsrender;
 1993+ destrect.left = sprites[0].x;
 1994+ destrect.top = sprites[0].y;
 1995+ destrect.right = sprites[0].x + sprites[0].ddsd.dwWidth;
 1996+ if (destrect.right > width) destrect.right = width;
 1997+ destrect.bottom = sprites[0].y + sprites[0].ddsd.dwHeight;
 1998+ if (destrect.bottom > height) destrect.bottom = height;
 1999+ srcrect.left = srcrect.top = 0;
 2000+ srcrect.right = destrect.right - destrect.left;
 2001+ srcrect.bottom = destrect.bottom - destrect.top;
 2002+ temp1->Blt(&destrect, sprites[0].surface, &srcrect, DDBLT_KEYSRC | DDBLT_WAIT, NULL);
 2003+ if (backbuffers) temp1->Release();
 2004+ }
 2005+ if (fullscreen)
 2006+ {
 2007+ if (backbuffers && ddsrender) ddsrender->Flip(NULL, DDFLIP_WAIT);
 2008+ }
 2009+ else
 2010+ {
 2011+ p.x = 0;
 2012+ p.y = 0;
 2013+ ClientToScreen(hWnd, &p);
 2014+ GetClientRect(hWnd, &r1);
 2015+ OffsetRect(&r1, p.x, p.y);
 2016+ SetRect(&r2, 0, 0, width, height);
 2017+ if (ddsurface && ddsrender) ddsurface->Blt(&r1, ddsrender, &r2, DDBLT_WAIT, NULL);
 2018+ }
 2019+ break;
18752020 }
18762021 }
18772022
@@ -1898,7 +2043,7 @@
18992044 int op;
19002045 switch(test)
19012046 {
1902 - case 1:
 2047+ case 1: // Random noise
19032048 default:
19042049 if(backbuffers)
19052050 {
@@ -1927,7 +2072,7 @@
19282073 if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
19292074 }
19302075 break;
1931 - case 3:
 2076+ case 3: // Random GDI patterns
19322077 ddsrender->GetDC(&hdc);
19332078 op = rand32(randnum) % 4;
19342079 pen = CreatePen(rand32(randnum) % 5,0,RGB(rand32(randnum)%256,rand32(randnum)%256,rand32(randnum)%256));
@@ -1971,7 +2116,7 @@
19722117 if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
19732118 }
19742119 break;
1975 - case 5:
 2120+ case 5: // Random color fill Blt
19762121 rndrect5:
19772122 destrect.bottom = rand32(randnum)%ddsd.dwHeight;
19782123 destrect.top = rand32(randnum)%ddsd.dwHeight;
@@ -2008,7 +2153,7 @@
20092154 if(ddsurface && ddsrender)error = ddsurface->Blt(&destrect,ddsrender,&srcrect,DDBLT_WAIT,NULL);
20102155 }
20112156 break;
2012 - case 9:
 2157+ case 9: // Large batch color fill
20132158 bltfx.dwSize = sizeof(DDBLTFX);
20142159 switch (bpp)
20152160 {