Commit 225f142c authored by Sami Aario's avatar Sami Aario Committed by Alexandre Julliard

Added surface tests.

parent d6993619
......@@ -28,7 +28,9 @@
#define UNION_MEMBER(x, y) y
#endif
static LPDIRECTDRAW lpDD;
static LPDIRECTDRAW lpDD = NULL;
static LPDIRECTDRAWSURFACE lpDDSPrimary = NULL;
static LPDIRECTDRAWSURFACE lpDDSBack = NULL;
static WNDCLASS wc;
static HWND hwnd;
static int modes_cnt;
......@@ -57,8 +59,7 @@ static void createdirectdraw()
GetSystemMetrics(SM_CXSCREEN),
GetSystemMetrics(SM_CYSCREEN),
NULL, NULL, GetModuleHandleA(0), NULL);
if (hwnd == NULL)
assert(0);
assert(hwnd != NULL);
ShowWindow(hwnd, SW_HIDE);
UpdateWindow(hwnd);
......@@ -68,7 +69,17 @@ static void createdirectdraw()
ok(rc==DD_OK,"DirectDrawCreate returned: %lx\n",rc);
}
static void add_mode(LPDDSURFACEDESC lpddsd)
static void releasedirectdraw()
{
if( lpDD != NULL )
{
IDirectDraw_Release(lpDD);
lpDD = NULL;
}
}
static void adddisplaymode(LPDDSURFACEDESC lpddsd)
{
if (!modes)
modes = malloc((modes_size = 2) * sizeof(DDSURFACEDESC));
......@@ -78,19 +89,19 @@ static void add_mode(LPDDSURFACEDESC lpddsd)
modes[modes_cnt++] = *lpddsd;
}
static void flush_modes()
static void flushdisplaymodes()
{
free(modes);
modes = 0;
modes_cnt = modes_size = 0;
}
HRESULT WINAPI enummodes_callback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
HRESULT WINAPI enummodescallback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
{
trace("Width = %lx, Height = %lx, Refresh Rate = %lx\r\n",
trace("Width = %li, Height = %li, Refresh Rate = %li\r\n",
lpddsd->dwWidth, lpddsd->dwHeight,
lpddsd->UNION_MEMBER(2, dwRefreshRate));
add_mode(lpddsd);
adddisplaymode(lpddsd);
return DDENUMRET_OK;
}
......@@ -106,39 +117,109 @@ void enumdisplaymodes()
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
rc = IDirectDraw_EnumDisplayModes(lpDD,
DDEDM_STANDARDVGAMODES, &ddsd, 0, enummodes_callback);
DDEDM_STANDARDVGAMODES, &ddsd, 0, enummodescallback);
ok(rc==DD_OK,"EnumDisplayModes returned: %lx\n",rc);
}
static void setdisplaymode_tests()
static void setdisplaymode(int i)
{
HRESULT rc;
int i;
rc = IDirectDraw_SetCooperativeLevel(lpDD,
hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
ok(rc==DD_OK,"SetCooperativeLevel returned: %lx\n",rc);
if (modes[i].dwFlags & DDSD_PIXELFORMAT)
{
if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
{
rc = IDirectDraw_SetDisplayMode(lpDD,
modes[i].dwWidth, modes[i].dwHeight,
modes[i].ddpfPixelFormat.UNION_MEMBER(1, dwRGBBitCount));
ok(rc==DD_OK,"SetDisplayMode returned: %lx\n",rc);
rc = IDirectDraw_RestoreDisplayMode(lpDD);
ok(rc==DD_OK,"RestoreDisplayMode returned: %lx\n",rc);
}
}
}
static void createsurface()
{
DDSURFACEDESC ddsd;
DDSCAPS ddscaps;
HRESULT rc;
createdirectdraw();
enumdisplaymodes();
for (i = 0; i < modes_cnt; ++i)
ddsd.dwSize = sizeof(ddsd);
ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
DDSCAPS_FLIP |
DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount = 1;
rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
ok(rc==DD_OK,"CreateSurface returned: %lx\n",rc);
ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
ok(rc==DD_OK,"GetAttachedSurface returned: %lx\n",rc);
}
static void destroysurface()
{
if( lpDDSPrimary != NULL )
{
rc = IDirectDraw_SetCooperativeLevel(lpDD,
hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
ok(rc==DD_OK,"SetCooperativeLevel returned: %lx\n",rc);
if (modes[i].dwFlags & DDSD_PIXELFORMAT)
IDirectDrawSurface_Release(lpDDSPrimary);
lpDDSPrimary = NULL;
}
}
static void testsurface()
{
const char* testMsg = "ddraw device context test";
HDC hdc;
HRESULT rc;
rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %lx\n",rc);
SetBkColor(hdc, RGB(0, 0, 255));
SetTextColor(hdc, RGB(255, 255, 0));
TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg));
IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %lx\n",rc);
while (1)
{
rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %lx\n",rc);
if (rc == DD_OK)
{
break;
}
else if (rc == DDERR_SURFACELOST)
{
if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
{
rc = IDirectDraw_SetDisplayMode(lpDD,
modes[i].dwWidth, modes[i].dwHeight,
modes[i].ddpfPixelFormat.UNION_MEMBER(1, dwRGBBitCount));
ok(rc==DD_OK,"SetDisplayMode returned: %lx\n",rc);
rc = IDirectDraw_RestoreDisplayMode(lpDD);
ok(rc==DD_OK,"RestoreDisplayMode returned: %lx\n",rc);
}
rc = IDirectDrawSurface_Restore(lpDDSPrimary);
ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %lx\n",rc);
}
}
flush_modes();
}
static void testdisplaymodes()
{
int i;
for (i = 0; i < modes_cnt; ++i)
{
setdisplaymode(i);
createsurface();
testsurface();
destroysurface();
}
}
START_TEST(ddrawmodes)
{
setdisplaymode_tests();
createdirectdraw();
enumdisplaymodes();
testdisplaymodes();
flushdisplaymodes();
releasedirectdraw();
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment