Matteo Bruni (@Mystral) commented about dlls/d3dx9_36/tests/surface.c:
+#define check_dxt_pixel_4bpp(device, dxt_surf, width, height, x, y, color, todo) _check_dxt_pixel_4bpp(__LINE__, device,\
dxt_surf, width, height, x, y, color, todo)
+static inline void _check_dxt_pixel_4bpp(unsigned int line, IDirect3DDevice9 *device, IDirect3DSurface9 *dxt_surf, int width,
int height, int x, int y, DWORD expected_color, BOOL todo)
+{
- IDirect3DSurface9 *decomp_surf;
- D3DLOCKED_RECT lockrect;
- DWORD color;
- HRESULT hr;
- RECT rect;
- hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &decomp_surf, NULL);
- ok_(__FILE__, line)(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
- hr = D3DXLoadSurfaceFromSurface(decomp_surf, NULL, NULL, dxt_surf, NULL, NULL, D3DX_FILTER_NONE, 0);
- ok_(__FILE__, line)(hr == D3D_OK, "Got unexpected hr %#lx.\n", hr);
Efficiency isn't usually the top priority in the tests, but it's nice to have quicker tests if it doesn't take a lot of effort. In particular, for this kind of operation, I suggest to introduce a set of functions like the readback helpers from e.g. the d3d9:visual tests. In this case, it could be something like: ``` get_surface_readback() get_readback_color() release_readback() ``` Then the `check_pixel_4bpp` function will only take care of the comparison itself, maybe also of the call to get_readback_color().
Relatedly, notice that you can pass a NULL rect to LockRect and it will map the whole surface.
With this kind of "toolset" you can avoid repeating the decompression and locking steps. I don't expect some crazy improvement from this since, in this particular case, the textures are small and in system memory, but it's redundant work that can be avoided without complicating things too much (IMO) and it might actually matter more if we end up reusing these helpers for other tests.