[SHLWAPI_APITEST]: Use the 'add_rostests_file' command from Colin ;)
[reactos.git] / rostests / dxtest / ddraw / Surface / blt.cpp
1
2 DWORD GetPixel (LPDIRECTDRAWSURFACE7 Surface, UINT x, UINT y)
3 {
4 DWORD ret;
5 RECT rect = {x, y, x+1, y+1};
6 DDSURFACEDESC2 desc = {0};
7 desc.dwSize = sizeof(DDSURFACEDESC2);
8
9 if(Surface->Lock(&rect, &desc, DDLOCK_READONLY | DDLOCK_WAIT, NULL))
10 {
11 printf("ERROR: Unable to lock surface\n");
12 return 0xdeadbeef;
13 }
14
15 ret = *((DWORD *)desc.lpSurface);
16
17 if(Surface->Unlock (&rect) != DD_OK)
18 {
19 printf("ERROR: Unable to unlock surface ?!\n");
20 }
21
22 return ret;
23 }
24
25 VOID Blt_Test (LPDIRECTDRAWSURFACE7 Surface, INT* passed, INT* failed)
26 {
27 LPDIRECTDRAWSURFACE7 Source;
28 if(!CreateSurface(&Source))
29 return;
30
31 // The following has been tested with Nvidea hardware
32 // the results might differently with other graphic
33 // card drivers. - mbosma
34
35 // FIXME: Test Color Key (DDBLT_KEYDEST / DDBLT_KEYSRC / DDBLT_KEYDESTOVERRIDE / DDBLT_KEYSRCOVERRIDE)
36
37 // General Tests
38 DDBLTFX bltfx;
39 TEST (Surface->Blt(NULL, NULL, NULL, 0, NULL) == DDERR_INVALIDPARAMS);
40 TEST (Surface->Blt(NULL, Surface, NULL, 0, NULL) == DD_OK ); // blting to itself
41
42 TEST (Surface->Blt(NULL, NULL, NULL, DDBLT_WAIT|DDBLT_DDFX, &bltfx) == DDERR_INVALIDPARAMS);
43 bltfx.dwDDFX = DDBLTFX_NOTEARING;
44 TEST (Surface->Blt(NULL, NULL, NULL, DDBLT_WAIT|DDBLT_DDFX, &bltfx) == DDERR_INVALIDPARAMS);
45 bltfx.dwSize = sizeof(DDBLTFX);
46 TEST (Surface->Blt(NULL, NULL, NULL, DDBLT_WAIT, &bltfx) == DDERR_INVALIDPARAMS);
47 TEST (Surface->Blt(NULL, Source, NULL, DDBLT_WAIT|DDBLT_DDFX, &bltfx) == DD_OK); // don't know why this works on a offscreen surfaces
48
49 // Test color filling
50 bltfx.dwFillColor = RGB(0, 255, 0);
51 TEST (Source->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &bltfx) == DD_OK);
52 RECT rect = {100, 100, 200, 200};
53 bltfx.dwFillColor = RGB(255, 255, 0);
54 TEST (Source->Blt(&rect, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &bltfx) == DD_OK);
55 TEST (GetPixel(Source, 0, 0) == RGB(0, 255, 0));
56 TEST (GetPixel(Source, 100, 100) == RGB(255, 255, 0));
57
58 // Test DestRect and SrcRect
59 RECT SourceRect = {100, 100, 200, 200};
60 RECT DestRect = {0, 0, 200, 100};
61
62 TEST (Surface->Blt(&SourceRect, Source, &DestRect, 0, NULL) == DD_OK);
63 TEST (GetPixel(Surface, 100, 100) == RGB(0, 255, 0)); // Src bigger: normal blt
64
65 TEST (Surface->Blt(&DestRect, Source, &SourceRect, 0, NULL) == DD_OK);
66 TEST (GetPixel(Surface, 0, 0) == 0x00ffbf); // Dest bigger: wtf ??
67
68 DestRect.right = 100; // both are same size now
69 TEST (Surface->Blt(&DestRect, Source, &SourceRect, 0, NULL) == DD_OK);
70 TEST (GetPixel(Surface, 0, 0) == RGB(255, 255, 0));
71
72 RECT TooBig = {100, 100, 200, 250};
73 TEST (Surface->Blt(&TooBig, Source, &SourceRect, 0, NULL) == DDERR_INVALIDRECT);
74 TEST (Surface->Blt(&DestRect, Source, &TooBig, 0, NULL) == DDERR_INVALIDRECT);
75
76 // Test Rotation
77 bltfx.dwDDFX = DDBLTFX_MIRRORLEFTRIGHT|DDBLTFX_MIRRORUPDOWN;
78 TEST (Surface->Blt(NULL, Source, NULL, DDBLT_WAIT|DDBLT_DDFX, &bltfx) == DD_OK);
79 TEST (GetPixel(Surface, 0, 0) == RGB(255, 255, 0));
80
81 bltfx.dwDDFX = DDBLTFX_ROTATE180;
82 TEST (Surface->Blt(NULL, Source, NULL, DDBLT_DDFX, &bltfx) == DDERR_NOROTATIONHW);
83
84 //bltfx.dwRotationAngle =
85 TEST (Surface->Blt(NULL, Source, NULL, DDBLT_ROTATIONANGLE, &bltfx) == DDERR_NOROTATIONHW);
86
87 // Test Raster Operations
88 bltfx.dwROP = BLACKNESS;
89 TEST (Surface->Blt(NULL, Source, NULL, DDBLT_WAIT|DDBLT_ROP, &bltfx) == DD_OK);
90 TEST(GetPixel(Surface, 0, 0) == RGB(0, 0, 0));
91 bltfx.dwROP = WHITENESS;
92 TEST (Surface->Blt(NULL, Source, NULL, DDBLT_WAIT|DDBLT_ROP, &bltfx) == DD_OK);
93 TEST(GetPixel(Surface, 0, 0) == RGB(255, 255, 255));
94 bltfx.dwROP = SRCCOPY; // this flag actually does nothing
95 TEST (Surface->Blt(NULL, Source, NULL, DDBLT_WAIT|DDBLT_ROP, &bltfx) == DD_OK);
96 TEST(GetPixel(Surface, 0, 0) == RGB(0, 255, 0));
97 bltfx.dwROP = SRCAND;
98 TEST (Surface->Blt(NULL, Source, NULL, DDBLT_WAIT|DDBLT_ROP, &bltfx) == DDERR_NORASTEROPHW);
99
100 // Test Direct Draw Raster Operations
101 bltfx.dwDDROP = 0x123;
102 TEST (Surface->Blt(NULL, Source, NULL, DDBLT_WAIT|DDBLT_DDROPS, &bltfx) == DDERR_NODDROPSHW);
103
104 // Streching
105 bltfx.dwDDFX = DDBLTFX_ARITHSTRETCHY;
106 TEST (Surface->Blt(NULL, Source, NULL, DDBLT_WAIT|DDBLT_DDFX, &bltfx) == DDERR_NOSTRETCHHW);
107 }
108
109 VOID GetBltStatus_Test (LPDIRECTDRAWSURFACE7 Surface, INT* passed, INT* failed)
110 {
111 TEST (Surface->GetBltStatus(0) == DDERR_INVALIDPARAMS);
112 TEST (Surface->GetBltStatus(DDGBS_CANBLT) == DD_OK);
113 //TEST (Surface->GetBltStatus(DDGBS_ISBLTDONE) == DD_OK);
114
115 // Lock Surface
116 DDSURFACEDESC2 desc = {0};
117 desc.dwSize = sizeof(DDSURFACEDESC2);
118 Surface->Lock(NULL, &desc, DDLOCK_WAIT, NULL);
119 TEST (Surface->GetBltStatus(DDGBS_ISBLTDONE) == DD_OK);
120 TEST (Surface->GetBltStatus(DDGBS_CANBLT) == DD_OK); // does not return DDERR_SURFACEBUSY for me as msdn says (xp,nvidea)
121 Surface->Unlock (NULL);
122
123 // Try to produce busy surface by filling it 500 times
124 DDBLTFX bltfx;
125 bltfx.dwSize = sizeof(DDBLTFX);
126 bltfx.dwFillColor = RGB(0, 0, 0);
127
128 int i;
129 for(i=0; i<500; i++)
130 Surface->Blt(NULL, NULL, NULL, DDBLT_COLORFILL, &bltfx);
131
132 TEST (Surface->GetBltStatus(DDGBS_ISBLTDONE) == DDERR_WASSTILLDRAWING);
133 TEST (Surface->GetBltStatus(DDGBS_CANBLT) == DD_OK);
134 }
135
136 BOOL Test_Blt (INT* passed, INT* failed)
137 {
138 LPDIRECTDRAWSURFACE7 Surface;
139 if(!CreateSurface(&Surface))
140 return FALSE;
141
142 // Test GetPixel (needs Lock API)
143 DDBLTFX bltfx;
144 bltfx.dwSize = sizeof(DDBLTFX);
145 bltfx.dwFillColor = RGB(0, 0, 0);
146 Surface->Blt(NULL, NULL, NULL, DDBLT_COLORFILL | DDBLT_WAIT, &bltfx);
147 if(GetPixel(Surface, 0, 0) != RGB(0, 0, 0))
148 return FALSE;
149
150 // The tests
151 TEST(Surface->BltBatch(NULL, 0, 0) == DDERR_UNSUPPORTED);
152 Blt_Test (Surface, passed, failed);
153 GetBltStatus_Test (Surface, passed, failed);
154
155 Surface->Release();
156 return TRUE;
157 }