2 DWORD
GetPixel (LPDIRECTDRAWSURFACE7 Surface
, UINT x
, UINT y
)
5 RECT rect
= {x
, y
, x
+1, y
+1};
6 DDSURFACEDESC2 desc
= {0};
7 desc
.dwSize
= sizeof(DDSURFACEDESC2
);
9 if(Surface
->Lock(&rect
, &desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
))
11 printf("ERROR: Unable to lock surface\n");
15 ret
= *((DWORD
*)desc
.lpSurface
);
17 if(Surface
->Unlock (&rect
) != DD_OK
)
19 printf("ERROR: Unable to unlock surface ?!\n");
25 VOID
Blt_Test (LPDIRECTDRAWSURFACE7 Surface
, INT
* passed
, INT
* failed
)
27 LPDIRECTDRAWSURFACE7 Source
;
28 if(!CreateSurface(&Source
))
31 // The following has been tested with Nvidea hardware
32 // the results might differently with other graphic
33 // card drivers. - mbosma
35 // FIXME: Test Color Key (DDBLT_KEYDEST / DDBLT_KEYSRC / DDBLT_KEYDESTOVERRIDE / DDBLT_KEYSRCOVERRIDE)
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
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
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));
58 // Test DestRect and SrcRect
59 RECT SourceRect
= {100, 100, 200, 200};
60 RECT DestRect
= {0, 0, 200, 100};
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
65 TEST (Surface
->Blt(&DestRect
, Source
, &SourceRect
, 0, NULL
) == DD_OK
);
66 TEST (GetPixel(Surface
, 0, 0) == 0x00ffbf); // Dest bigger: wtf ??
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));
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
);
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));
81 bltfx
.dwDDFX
= DDBLTFX_ROTATE180
;
82 TEST (Surface
->Blt(NULL
, Source
, NULL
, DDBLT_DDFX
, &bltfx
) == DDERR_NOROTATIONHW
);
84 //bltfx.dwRotationAngle =
85 TEST (Surface
->Blt(NULL
, Source
, NULL
, DDBLT_ROTATIONANGLE
, &bltfx
) == DDERR_NOROTATIONHW
);
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));
98 TEST (Surface
->Blt(NULL
, Source
, NULL
, DDBLT_WAIT
|DDBLT_ROP
, &bltfx
) == DDERR_NORASTEROPHW
);
100 // Test Direct Draw Raster Operations
101 bltfx
.dwDDROP
= 0x123;
102 TEST (Surface
->Blt(NULL
, Source
, NULL
, DDBLT_WAIT
|DDBLT_DDROPS
, &bltfx
) == DDERR_NODDROPSHW
);
105 bltfx
.dwDDFX
= DDBLTFX_ARITHSTRETCHY
;
106 TEST (Surface
->Blt(NULL
, Source
, NULL
, DDBLT_WAIT
|DDBLT_DDFX
, &bltfx
) == DDERR_NOSTRETCHHW
);
109 VOID
GetBltStatus_Test (LPDIRECTDRAWSURFACE7 Surface
, INT
* passed
, INT
* failed
)
111 TEST (Surface
->GetBltStatus(0) == DDERR_INVALIDPARAMS
);
112 TEST (Surface
->GetBltStatus(DDGBS_CANBLT
) == DD_OK
);
113 //TEST (Surface->GetBltStatus(DDGBS_ISBLTDONE) == DD_OK);
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
);
123 // Try to produce busy surface by filling it 500 times
125 bltfx
.dwSize
= sizeof(DDBLTFX
);
126 bltfx
.dwFillColor
= RGB(0, 0, 0);
130 Surface
->Blt(NULL
, NULL
, NULL
, DDBLT_COLORFILL
, &bltfx
);
132 TEST (Surface
->GetBltStatus(DDGBS_ISBLTDONE
) == DDERR_WASSTILLDRAWING
);
133 TEST (Surface
->GetBltStatus(DDGBS_CANBLT
) == DD_OK
);
136 BOOL
Test_Blt (INT
* passed
, INT
* failed
)
138 LPDIRECTDRAWSURFACE7 Surface
;
139 if(!CreateSurface(&Surface
))
142 // Test GetPixel (needs Lock API)
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))
151 TEST(Surface
->BltBatch(NULL
, 0, 0) == DDERR_UNSUPPORTED
);
152 Blt_Test (Surface
, passed
, failed
);
153 GetBltStatus_Test (Surface
, passed
, failed
);