2 * Unit tests for ddraw functions
4 * Copyright (C) 2003 Sami Aario
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/test.h"
25 static LPDIRECTDRAW lpDD = NULL;
26 static LPDIRECTDRAWSURFACE lpDDSPrimary = NULL;
27 static LPDIRECTDRAWSURFACE lpDDSBack = NULL;
31 static int modes_size;
32 static LPDDSURFACEDESC modes;
34 static void createdirectdraw(void)
38 wc.style = CS_HREDRAW | CS_VREDRAW;
39 wc.lpfnWndProc = DefWindowProcA;
42 wc.hInstance = GetModuleHandleA(0);
43 wc.hIcon = LoadIconA(wc.hInstance, IDI_APPLICATION);
44 wc.hCursor = LoadCursorA(NULL, IDC_ARROW);
45 wc.hbrBackground = (HBRUSH) GetStockObject(BLACK_BRUSH);
46 wc.lpszMenuName = NULL;
47 wc.lpszClassName = "TestWindowClass";
48 if(!RegisterClassA(&wc))
51 hwnd = CreateWindowExA(0, "TestWindowClass", "TestWindowClass",
53 GetSystemMetrics(SM_CXSCREEN),
54 GetSystemMetrics(SM_CYSCREEN),
55 NULL, NULL, GetModuleHandleA(0), NULL);
58 ShowWindow(hwnd, SW_HIDE);
62 rc = DirectDrawCreate(NULL, &lpDD, NULL);
63 ok(rc==DD_OK,"DirectDrawCreate returned: %lx\n",rc);
67 static void releasedirectdraw(void)
71 IDirectDraw_Release(lpDD);
76 static void adddisplaymode(LPDDSURFACEDESC lpddsd)
79 modes = malloc((modes_size = 2) * sizeof(DDSURFACEDESC));
80 if (modes_cnt == modes_size)
81 modes = realloc(modes, (modes_size *= 2) * sizeof(DDSURFACEDESC));
83 modes[modes_cnt++] = *lpddsd;
86 static void flushdisplaymodes(void)
90 modes_cnt = modes_size = 0;
93 HRESULT WINAPI enummodescallback(LPDDSURFACEDESC lpddsd, LPVOID lpContext)
95 trace("Width = %li, Height = %li, Refresh Rate = %li\r\n",
96 lpddsd->dwWidth, lpddsd->dwHeight,
97 U2(*lpddsd).dwRefreshRate);
98 adddisplaymode(lpddsd);
103 void enumdisplaymodes(void)
108 ZeroMemory(&ddsd, sizeof(DDSURFACEDESC));
109 ddsd.dwSize = sizeof(DDSURFACEDESC);
110 ddsd.dwFlags = DDSD_CAPS;
111 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE;
113 rc = IDirectDraw_EnumDisplayModes(lpDD,
114 DDEDM_STANDARDVGAMODES, &ddsd, 0, enummodescallback);
115 ok(rc==DD_OK || rc==E_INVALIDARG,"EnumDisplayModes returned: %lx\n",rc);
118 static void setdisplaymode(int i)
122 rc = IDirectDraw_SetCooperativeLevel(lpDD,
123 hwnd, DDSCL_ALLOWMODEX | DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
124 ok(rc==DD_OK,"SetCooperativeLevel returned: %lx\n",rc);
125 if (modes[i].dwFlags & DDSD_PIXELFORMAT)
127 if (modes[i].ddpfPixelFormat.dwFlags & DDPF_RGB)
129 rc = IDirectDraw_SetDisplayMode(lpDD,
130 modes[i].dwWidth, modes[i].dwHeight,
131 U1(modes[i].ddpfPixelFormat).dwRGBBitCount);
132 ok(DD_OK==rc || DDERR_UNSUPPORTED==rc,"SetDisplayMode returned: %lx\n",rc);
134 rc = IDirectDraw_RestoreDisplayMode(lpDD);
135 ok(DD_OK==rc,"RestoreDisplayMode returned: %lx\n",rc);
141 static void createsurface(void)
147 ddsd.dwSize = sizeof(ddsd);
148 ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT;
149 ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE |
152 ddsd.dwBackBufferCount = 1;
153 rc = IDirectDraw_CreateSurface(lpDD, &ddsd, &lpDDSPrimary, NULL );
154 ok(rc==DD_OK,"CreateSurface returned: %lx\n",rc);
155 ddscaps.dwCaps = DDSCAPS_BACKBUFFER;
156 rc = IDirectDrawSurface_GetAttachedSurface(lpDDSPrimary, &ddscaps, &lpDDSBack);
157 ok(rc==DD_OK,"GetAttachedSurface returned: %lx\n",rc);
160 static void destroysurface(void)
162 if( lpDDSPrimary != NULL )
164 IDirectDrawSurface_Release(lpDDSPrimary);
169 static void testsurface(void)
171 const char* testMsg = "ddraw device context test";
175 rc = IDirectDrawSurface_GetDC(lpDDSBack, &hdc);
176 ok(rc==DD_OK, "IDirectDrawSurface_GetDC returned: %lx\n",rc);
177 SetBkColor(hdc, RGB(0, 0, 255));
178 SetTextColor(hdc, RGB(255, 255, 0));
179 TextOut(hdc, 0, 0, testMsg, lstrlen(testMsg));
180 IDirectDrawSurface_ReleaseDC(lpDDSBack, hdc);
181 ok(rc==DD_OK, "IDirectDrawSurface_ReleaseDC returned: %lx\n",rc);
185 rc = IDirectDrawSurface_Flip(lpDDSPrimary, NULL, DDFLIP_WAIT);
186 ok(rc==DD_OK || rc==DDERR_SURFACELOST, "IDirectDrawSurface_BltFast returned: %lx\n",rc);
192 else if (rc == DDERR_SURFACELOST)
194 rc = IDirectDrawSurface_Restore(lpDDSPrimary);
195 ok(rc==DD_OK, "IDirectDrawSurface_Restore returned: %lx\n",rc);
200 static void testdisplaymodes(void)
204 for (i = 0; i < modes_cnt; ++i)
213 START_TEST(ddrawmodes)