mfplat: Read queue subscriber within the critical section.
[wine/zf.git] / dlls / d3dx9_36 / tests / core.c
bloba8477591e875ea8d99388f885389a61988c5a56a
1 /*
2 * Tests for the D3DX9 core interfaces
4 * Copyright 2009 Tony Wasserka
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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #define COBJMACROS
22 #include "wine/test.h"
23 #include <dxerr9.h>
24 #include "d3dx9core.h"
26 static inline int get_ref(IUnknown *obj)
28 IUnknown_AddRef(obj);
29 return IUnknown_Release(obj);
32 #define check_ref(obj, exp) _check_ref(__LINE__, obj, exp)
33 static inline void _check_ref(unsigned int line, IUnknown *obj, int exp)
35 int ref = get_ref(obj);
36 ok_(__FILE__, line)(exp == ref, "Invalid refcount. Expected %d, got %d\n", exp, ref);
39 #define check_release(obj, exp) _check_release(__LINE__, obj, exp)
40 static inline void _check_release(unsigned int line, IUnknown *obj, int exp)
42 int ref = IUnknown_Release(obj);
43 ok_(__FILE__, line)(ref == exp, "Invalid refcount. Expected %d, got %d\n", exp, ref);
46 #define admitted_error 0.0001f
47 static inline void check_mat(D3DXMATRIX got, D3DXMATRIX exp)
49 int i, j, equal=1;
50 for (i=0; i<4; i++)
51 for (j=0; j<4; j++)
52 if (fabs(U(exp).m[i][j]-U(got).m[i][j]) > admitted_error)
53 equal=0;
55 ok(equal, "Got matrix\n\t(%f,%f,%f,%f\n\t %f,%f,%f,%f\n\t %f,%f,%f,%f\n\t %f,%f,%f,%f)\n"
56 "Expected matrix=\n\t(%f,%f,%f,%f\n\t %f,%f,%f,%f\n\t %f,%f,%f,%f\n\t %f,%f,%f,%f)\n",
57 U(got).m[0][0],U(got).m[0][1],U(got).m[0][2],U(got).m[0][3],
58 U(got).m[1][0],U(got).m[1][1],U(got).m[1][2],U(got).m[1][3],
59 U(got).m[2][0],U(got).m[2][1],U(got).m[2][2],U(got).m[2][3],
60 U(got).m[3][0],U(got).m[3][1],U(got).m[3][2],U(got).m[3][3],
61 U(exp).m[0][0],U(exp).m[0][1],U(exp).m[0][2],U(exp).m[0][3],
62 U(exp).m[1][0],U(exp).m[1][1],U(exp).m[1][2],U(exp).m[1][3],
63 U(exp).m[2][0],U(exp).m[2][1],U(exp).m[2][2],U(exp).m[2][3],
64 U(exp).m[3][0],U(exp).m[3][1],U(exp).m[3][2],U(exp).m[3][3]);
67 #define check_rect(rect, left, top, right, bottom) _check_rect(__LINE__, rect, left, top, right, bottom)
68 static inline void _check_rect(unsigned int line, const RECT *rect, int left, int top, int right, int bottom)
70 ok_(__FILE__, line)(rect->left == left, "Unexpected rect.left %d\n", rect->left);
71 ok_(__FILE__, line)(rect->top == top, "Unexpected rect.top %d\n", rect->top);
72 ok_(__FILE__, line)(rect->right == right, "Unexpected rect.right %d\n", rect->right);
73 ok_(__FILE__, line)(rect->bottom == bottom, "Unexpected rect.bottom %d\n", rect->bottom);
76 static void test_ID3DXBuffer(void)
78 ID3DXBuffer *buffer;
79 HRESULT hr;
80 ULONG count;
81 DWORD size;
83 hr = D3DXCreateBuffer(10, NULL);
84 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateBuffer failed, got %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
86 hr = D3DXCreateBuffer(0, &buffer);
87 ok(hr == D3D_OK, "D3DXCreateBuffer failed, got %#x, expected %#x\n", hr, D3D_OK);
89 size = ID3DXBuffer_GetBufferSize(buffer);
90 ok(!size, "GetBufferSize failed, got %u, expected %u\n", size, 0);
92 count = ID3DXBuffer_Release(buffer);
93 ok(!count, "ID3DXBuffer has %u references left\n", count);
95 hr = D3DXCreateBuffer(3, &buffer);
96 ok(hr == D3D_OK, "D3DXCreateBuffer failed, got %#x, expected %#x\n", hr, D3D_OK);
98 size = ID3DXBuffer_GetBufferSize(buffer);
99 ok(size == 3, "GetBufferSize failed, got %u, expected %u\n", size, 3);
101 count = ID3DXBuffer_Release(buffer);
102 ok(!count, "ID3DXBuffer has %u references left\n", count);
105 static void test_ID3DXSprite(IDirect3DDevice9 *device)
107 ID3DXSprite *sprite;
108 IDirect3D9 *d3d;
109 IDirect3DDevice9 *cmpdev;
110 IDirect3DTexture9 *tex1, *tex2;
111 D3DXMATRIX mat, cmpmat;
112 D3DVIEWPORT9 vp;
113 RECT rect;
114 D3DXVECTOR3 pos, center;
115 HRESULT hr;
117 IDirect3DDevice9_GetDirect3D(device, &d3d);
118 hr = IDirect3D9_CheckDeviceFormat(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, D3DFMT_X8R8G8B8, D3DUSAGE_DYNAMIC, D3DRTYPE_TEXTURE, D3DFMT_A8R8G8B8);
119 IDirect3D9_Release(d3d);
120 ok (hr == D3D_OK, "D3DFMT_A8R8G8B8 not supported\n");
121 if (FAILED(hr)) return;
123 hr = IDirect3DDevice9_CreateTexture(device, 64, 64, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex1, NULL);
124 ok (hr == D3D_OK, "Failed to create first texture (error code: %#x)\n", hr);
125 if (FAILED(hr)) return;
127 hr = IDirect3DDevice9_CreateTexture(device, 32, 32, 1, 0, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &tex2, NULL);
128 ok (hr == D3D_OK, "Failed to create second texture (error code: %#x)\n", hr);
129 if (FAILED(hr)) {
130 IDirect3DTexture9_Release(tex1);
131 return;
134 /* Test D3DXCreateSprite */
135 hr = D3DXCreateSprite(device, NULL);
136 ok (hr == D3DERR_INVALIDCALL, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
138 hr = D3DXCreateSprite(NULL, &sprite);
139 ok (hr == D3DERR_INVALIDCALL, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
141 hr = D3DXCreateSprite(device, &sprite);
142 ok (hr == D3D_OK, "D3DXCreateSprite returned %#x, expected %#x\n", hr, D3D_OK);
145 /* Test ID3DXSprite_GetDevice */
146 hr = ID3DXSprite_GetDevice(sprite, NULL);
147 ok (hr == D3DERR_INVALIDCALL, "GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
149 hr = ID3DXSprite_GetDevice(sprite, &cmpdev); /* cmpdev == NULL */
150 ok (hr == D3D_OK, "GetDevice returned %#x, expected %#x\n", hr, D3D_OK);
152 hr = ID3DXSprite_GetDevice(sprite, &cmpdev); /* cmpdev != NULL */
153 ok (hr == D3D_OK, "GetDevice returned %#x, expected %#x\n", hr, D3D_OK);
155 IDirect3DDevice9_Release(device);
156 IDirect3DDevice9_Release(device);
159 /* Test ID3DXSprite_GetTransform */
160 hr = ID3DXSprite_GetTransform(sprite, NULL);
161 ok (hr == D3DERR_INVALIDCALL, "GetTransform returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
162 hr = ID3DXSprite_GetTransform(sprite, &mat);
163 ok (hr == D3D_OK, "GetTransform returned %#x, expected %#x\n", hr, D3D_OK);
164 if(SUCCEEDED(hr)) {
165 D3DXMATRIX identity;
166 D3DXMatrixIdentity(&identity);
167 check_mat(mat, identity);
170 /* Test ID3DXSprite_SetTransform */
171 /* Set a transform and test if it gets returned correctly */
172 U(mat).m[0][0]=2.1f; U(mat).m[0][1]=6.5f; U(mat).m[0][2]=-9.6f; U(mat).m[0][3]=1.7f;
173 U(mat).m[1][0]=4.2f; U(mat).m[1][1]=-2.5f; U(mat).m[1][2]=2.1f; U(mat).m[1][3]=5.5f;
174 U(mat).m[2][0]=-2.6f; U(mat).m[2][1]=0.3f; U(mat).m[2][2]=8.6f; U(mat).m[2][3]=8.4f;
175 U(mat).m[3][0]=6.7f; U(mat).m[3][1]=-5.1f; U(mat).m[3][2]=6.1f; U(mat).m[3][3]=2.2f;
177 hr = ID3DXSprite_SetTransform(sprite, NULL);
178 ok (hr == D3DERR_INVALIDCALL, "SetTransform returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
180 hr = ID3DXSprite_SetTransform(sprite, &mat);
181 ok (hr == D3D_OK, "SetTransform returned %#x, expected %#x\n", hr, D3D_OK);
182 if(SUCCEEDED(hr)) {
183 hr=ID3DXSprite_GetTransform(sprite, &cmpmat);
184 if(SUCCEEDED(hr)) check_mat(cmpmat, mat);
185 else skip("GetTransform returned %#x\n", hr);
188 /* Test ID3DXSprite_SetWorldViewLH/RH */
189 todo_wine {
190 hr = ID3DXSprite_SetWorldViewLH(sprite, &mat, &mat);
191 ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK);
192 hr = ID3DXSprite_SetWorldViewLH(sprite, NULL, &mat);
193 ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK);
194 hr = ID3DXSprite_SetWorldViewLH(sprite, &mat, NULL);
195 ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK);
196 hr = ID3DXSprite_SetWorldViewLH(sprite, NULL, NULL);
197 ok (hr == D3D_OK, "SetWorldViewLH returned %#x, expected %#x\n", hr, D3D_OK);
199 hr = ID3DXSprite_SetWorldViewRH(sprite, &mat, &mat);
200 ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK);
201 hr = ID3DXSprite_SetWorldViewRH(sprite, NULL, &mat);
202 ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK);
203 hr = ID3DXSprite_SetWorldViewRH(sprite, &mat, NULL);
204 ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK);
205 hr = ID3DXSprite_SetWorldViewRH(sprite, NULL, NULL);
206 ok (hr == D3D_OK, "SetWorldViewRH returned %#x, expected %#x\n", hr, D3D_OK);
208 IDirect3DDevice9_BeginScene(device);
210 /* Test ID3DXSprite_Begin*/
211 hr = ID3DXSprite_Begin(sprite, 0);
212 ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK);
214 IDirect3DDevice9_GetTransform(device, D3DTS_WORLD, &mat);
215 D3DXMatrixIdentity(&cmpmat);
216 check_mat(mat, cmpmat);
218 IDirect3DDevice9_GetTransform(device, D3DTS_VIEW, &mat);
219 check_mat(mat, cmpmat);
221 IDirect3DDevice9_GetTransform(device, D3DTS_PROJECTION, &mat);
222 IDirect3DDevice9_GetViewport(device, &vp);
223 D3DXMatrixOrthoOffCenterLH(&cmpmat, vp.X+0.5f, (float)vp.Width+vp.X+0.5f, (float)vp.Height+vp.Y+0.5f, vp.Y+0.5f, vp.MinZ, vp.MaxZ);
224 check_mat(mat, cmpmat);
226 /* Test ID3DXSprite_Flush and ID3DXSprite_End */
227 hr = ID3DXSprite_Flush(sprite);
228 ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK);
230 hr = ID3DXSprite_End(sprite);
231 ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK);
233 hr = ID3DXSprite_Flush(sprite); /* May not be called before next Begin */
234 ok (hr == D3DERR_INVALIDCALL, "Flush returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
235 hr = ID3DXSprite_End(sprite);
236 ok (hr == D3DERR_INVALIDCALL, "End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
238 /* Test ID3DXSprite_Draw */
239 hr = ID3DXSprite_Begin(sprite, 0);
240 ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK);
242 if(FAILED(hr)) skip("Couldn't ID3DXSprite_Begin, can't test ID3DXSprite_Draw\n");
243 else { /* Feed the sprite batch */
244 int texref1, texref2;
246 SetRect(&rect, 53, 12, 142, 165);
247 pos.x = 2.2f; pos.y = 4.5f; pos.z = 5.1f;
248 center.x = 11.3f; center.y = 3.4f; center.z = 1.2f;
250 texref1 = get_ref((IUnknown*)tex1);
251 texref2 = get_ref((IUnknown*)tex2);
253 hr = ID3DXSprite_Draw(sprite, NULL, &rect, &center, &pos, D3DCOLOR_XRGB(255, 255, 255));
254 ok (hr == D3DERR_INVALIDCALL, "Draw returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
256 hr = ID3DXSprite_Draw(sprite, tex1, &rect, &center, &pos, D3DCOLOR_XRGB(255, 255, 255));
257 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
258 hr = ID3DXSprite_Draw(sprite, tex2, &rect, &center, &pos, D3DCOLOR_XRGB( 3, 45, 66));
259 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
260 hr = ID3DXSprite_Draw(sprite, tex1, NULL, &center, &pos, D3DCOLOR_XRGB(255, 255, 255));
261 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
262 hr = ID3DXSprite_Draw(sprite, tex1, &rect, NULL, &pos, D3DCOLOR_XRGB(255, 255, 255));
263 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
264 hr = ID3DXSprite_Draw(sprite, tex1, &rect, &center, NULL, D3DCOLOR_XRGB(255, 255, 255));
265 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
266 hr = ID3DXSprite_Draw(sprite, tex1, NULL, NULL, NULL, 0);
267 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
269 check_ref((IUnknown*)tex1, texref1+5); check_ref((IUnknown*)tex2, texref2+1);
270 hr = ID3DXSprite_Flush(sprite);
271 ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK);
272 hr = ID3DXSprite_Flush(sprite); /* Flushing twice should work */
273 ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK);
274 check_ref((IUnknown*)tex1, texref1); check_ref((IUnknown*)tex2, texref2);
276 hr = ID3DXSprite_End(sprite);
277 ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK);
280 /* Test ID3DXSprite_OnLostDevice and ID3DXSprite_OnResetDevice */
281 /* Both can be called twice */
282 hr = ID3DXSprite_OnLostDevice(sprite);
283 ok (hr == D3D_OK, "OnLostDevice returned %#x, expected %#x\n", hr, D3D_OK);
284 hr = ID3DXSprite_OnLostDevice(sprite);
285 ok (hr == D3D_OK, "OnLostDevice returned %#x, expected %#x\n", hr, D3D_OK);
286 hr = ID3DXSprite_OnResetDevice(sprite);
287 ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK);
288 hr = ID3DXSprite_OnResetDevice(sprite);
289 ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK);
291 /* Make sure everything works like before */
292 hr = ID3DXSprite_Begin(sprite, 0);
293 ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK);
294 hr = ID3DXSprite_Draw(sprite, tex2, &rect, &center, &pos, D3DCOLOR_XRGB(255, 255, 255));
295 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
296 hr = ID3DXSprite_Flush(sprite);
297 ok (hr == D3D_OK, "Flush returned %#x, expected %#x\n", hr, D3D_OK);
298 hr = ID3DXSprite_End(sprite);
299 ok (hr == D3D_OK, "End returned %#x, expected %#x\n", hr, D3D_OK);
301 /* OnResetDevice makes the interface "forget" the Begin call */
302 hr = ID3DXSprite_Begin(sprite, 0);
303 ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK);
304 hr = ID3DXSprite_OnResetDevice(sprite);
305 ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK);
306 hr = ID3DXSprite_End(sprite);
307 ok (hr == D3DERR_INVALIDCALL, "End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
309 /* Test D3DXSPRITE_DO_NOT_ADDREF_TEXTURE */
310 hr = ID3DXSprite_Begin(sprite, D3DXSPRITE_DO_NOT_ADDREF_TEXTURE);
311 ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK);
312 hr = ID3DXSprite_Draw(sprite, tex2, &rect, &center, &pos, D3DCOLOR_XRGB(255, 255, 255));
313 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
314 hr = ID3DXSprite_OnResetDevice(sprite);
315 ok (hr == D3D_OK, "OnResetDevice returned %#x, expected %#x\n", hr, D3D_OK);
316 check_ref((IUnknown*)tex2, 1);
318 hr = ID3DXSprite_Begin(sprite, D3DXSPRITE_DO_NOT_ADDREF_TEXTURE);
319 ok (hr == D3D_OK, "Begin returned %#x, expected %#x\n", hr, D3D_OK);
320 hr = ID3DXSprite_Draw(sprite, tex2, &rect, &center, &pos, D3DCOLOR_XRGB(255, 255, 255));
321 ok (hr == D3D_OK, "Draw returned %#x, expected %#x\n", hr, D3D_OK);
323 IDirect3DDevice9_EndScene(device);
324 check_release((IUnknown*)sprite, 0);
325 check_release((IUnknown*)tex2, 0);
326 check_release((IUnknown*)tex1, 0);
329 static void test_ID3DXFont(IDirect3DDevice9 *device)
331 static const WCHAR testW[] = L"test";
332 static const char long_text[] = "Example text to test clipping and other related things";
333 static const WCHAR long_textW[] = L"Example text to test clipping and other related things";
334 static const MAT2 mat = { {0,1}, {0,0}, {0,0}, {0,1} };
335 static const struct
337 int font_height;
338 unsigned int expected_size;
339 unsigned int expected_levels;
341 tests[] =
343 { 2, 32, 2 },
344 { 6, 128, 4 },
345 { 10, 256, 5 },
346 { 12, 256, 5 },
347 { 72, 256, 8 },
348 { 250, 256, 9 },
349 { 258, 512, 10 },
350 { 512, 512, 10 },
352 const unsigned int size = ARRAY_SIZE(testW);
353 TEXTMETRICA metrics, expmetrics;
354 IDirect3DTexture9 *texture;
355 D3DSURFACE_DESC surf_desc;
356 IDirect3DDevice9 *bufdev;
357 GLYPHMETRICS glyph_metrics;
358 D3DXFONT_DESCA desc;
359 ID3DXSprite *sprite;
360 RECT rect, blackbox;
361 DWORD count, levels;
362 int ref, i, height;
363 ID3DXFont *font;
364 TEXTMETRICW tm;
365 POINT cellinc;
366 HRESULT hr;
367 WORD glyph;
368 BOOL ret;
369 HDC hdc;
370 char c;
372 /* D3DXCreateFont */
373 ref = get_ref((IUnknown*)device);
374 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font);
375 ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK);
376 check_ref((IUnknown*)device, ref + 1);
377 check_release((IUnknown*)font, 0);
378 check_ref((IUnknown*)device, ref);
380 hr = D3DXCreateFontA(device, 0, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font);
381 ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK);
382 ID3DXFont_Release(font);
384 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, NULL, &font);
385 ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK);
386 ID3DXFont_Release(font);
388 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "", &font);
389 ok(hr == D3D_OK, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3D_OK);
390 ID3DXFont_Release(font);
392 hr = D3DXCreateFontA(NULL, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font);
393 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
395 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", NULL);
396 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
398 hr = D3DXCreateFontA(NULL, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", NULL);
399 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFont returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
402 /* D3DXCreateFontIndirect */
403 desc.Height = 12;
404 desc.Width = 0;
405 desc.Weight = FW_DONTCARE;
406 desc.MipLevels = 0;
407 desc.Italic = FALSE;
408 desc.CharSet = DEFAULT_CHARSET;
409 desc.OutputPrecision = OUT_DEFAULT_PRECIS;
410 desc.Quality = DEFAULT_QUALITY;
411 desc.PitchAndFamily = DEFAULT_PITCH;
412 strcpy(desc.FaceName, "Tahoma");
413 hr = D3DXCreateFontIndirectA(device, &desc, &font);
414 ok(hr == D3D_OK, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3D_OK);
415 ID3DXFont_Release(font);
417 hr = D3DXCreateFontIndirectA(NULL, &desc, &font);
418 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
420 hr = D3DXCreateFontIndirectA(device, NULL, &font);
421 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
423 hr = D3DXCreateFontIndirectA(device, &desc, NULL);
424 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateFontIndirect returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
427 /* ID3DXFont_GetDevice */
428 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
429 DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font);
430 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
432 hr = ID3DXFont_GetDevice(font, NULL);
433 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
435 ref = get_ref((IUnknown *)device);
436 hr = ID3DXFont_GetDevice(font, &bufdev);
437 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
438 check_release((IUnknown *)bufdev, ref);
440 ID3DXFont_Release(font);
443 /* ID3DXFont_GetDesc */
444 hr = D3DXCreateFontA(device, 12, 8, FW_BOLD, 2, TRUE, ANSI_CHARSET, OUT_RASTER_PRECIS,
445 ANTIALIASED_QUALITY, VARIABLE_PITCH, "Tahoma", &font);
446 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
448 hr = ID3DXFont_GetDescA(font, NULL);
449 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
451 hr = ID3DXFont_GetDescA(font, &desc);
452 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
454 ok(desc.Height == 12, "Got unexpected height %d.\n", desc.Height);
455 ok(desc.Width == 8, "Got unexpected width %u.\n", desc.Width);
456 ok(desc.Weight == FW_BOLD, "Got unexpected weight %u.\n", desc.Weight);
457 ok(desc.MipLevels == 2, "Got unexpected miplevels %u.\n", desc.MipLevels);
458 ok(desc.Italic == TRUE, "Got unexpected italic %#x.\n", desc.Italic);
459 ok(desc.CharSet == ANSI_CHARSET, "Got unexpected charset %u.\n", desc.CharSet);
460 ok(desc.OutputPrecision == OUT_RASTER_PRECIS, "Got unexpected output precision %u.\n", desc.OutputPrecision);
461 ok(desc.Quality == ANTIALIASED_QUALITY, "Got unexpected quality %u.\n", desc.Quality);
462 ok(desc.PitchAndFamily == VARIABLE_PITCH, "Got unexpected pitch and family %#x.\n", desc.PitchAndFamily);
463 ok(!strcmp(desc.FaceName, "Tahoma"), "Got unexpected facename %s.\n", debugstr_a(desc.FaceName));
465 ID3DXFont_Release(font);
468 /* ID3DXFont_GetDC + ID3DXFont_GetTextMetrics */
469 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
470 DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font);
471 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
473 hdc = ID3DXFont_GetDC(font);
474 ok(!!hdc, "Got unexpected hdc %p.\n", hdc);
476 ret = ID3DXFont_GetTextMetricsA(font, &metrics);
477 ok(ret, "Got unexpected ret %#x.\n", ret);
478 ret = GetTextMetricsA(hdc, &expmetrics);
479 ok(ret, "Got unexpected ret %#x.\n", ret);
481 ok(metrics.tmHeight == expmetrics.tmHeight, "Got unexpected height %d, expected %d.\n",
482 metrics.tmHeight, expmetrics.tmHeight);
483 ok(metrics.tmAscent == expmetrics.tmAscent, "Got unexpected ascent %d, expected %d.\n",
484 metrics.tmAscent, expmetrics.tmAscent);
485 ok(metrics.tmDescent == expmetrics.tmDescent, "Got unexpected descent %d, expected %d.\n",
486 metrics.tmDescent, expmetrics.tmDescent);
487 ok(metrics.tmInternalLeading == expmetrics.tmInternalLeading, "Got unexpected internal leading %d, expected %d.\n",
488 metrics.tmInternalLeading, expmetrics.tmInternalLeading);
489 ok(metrics.tmExternalLeading == expmetrics.tmExternalLeading, "Got unexpected external leading %d, expected %d.\n",
490 metrics.tmExternalLeading, expmetrics.tmExternalLeading);
491 ok(metrics.tmAveCharWidth == expmetrics.tmAveCharWidth, "Got unexpected average char width %d, expected %d.\n",
492 metrics.tmAveCharWidth, expmetrics.tmAveCharWidth);
493 ok(metrics.tmMaxCharWidth == expmetrics.tmMaxCharWidth, "Got unexpected maximum char width %d, expected %d.\n",
494 metrics.tmMaxCharWidth, expmetrics.tmMaxCharWidth);
495 ok(metrics.tmWeight == expmetrics.tmWeight, "Got unexpected weight %d, expected %d.\n",
496 metrics.tmWeight, expmetrics.tmWeight);
497 ok(metrics.tmOverhang == expmetrics.tmOverhang, "Got unexpected overhang %d, expected %d.\n",
498 metrics.tmOverhang, expmetrics.tmOverhang);
499 ok(metrics.tmDigitizedAspectX == expmetrics.tmDigitizedAspectX, "Got unexpected digitized x aspect %d, expected %d.\n",
500 metrics.tmDigitizedAspectX, expmetrics.tmDigitizedAspectX);
501 ok(metrics.tmDigitizedAspectY == expmetrics.tmDigitizedAspectY, "Got unexpected digitized y aspect %d, expected %d.\n",
502 metrics.tmDigitizedAspectY, expmetrics.tmDigitizedAspectY);
503 ok(metrics.tmFirstChar == expmetrics.tmFirstChar, "Got unexpected first char %u, expected %u.\n",
504 metrics.tmFirstChar, expmetrics.tmFirstChar);
505 ok(metrics.tmLastChar == expmetrics.tmLastChar, "Got unexpected last char %u, expected %u.\n",
506 metrics.tmLastChar, expmetrics.tmLastChar);
507 ok(metrics.tmDefaultChar == expmetrics.tmDefaultChar, "Got unexpected default char %u, expected %u.\n",
508 metrics.tmDefaultChar, expmetrics.tmDefaultChar);
509 ok(metrics.tmBreakChar == expmetrics.tmBreakChar, "Got unexpected break char %u, expected %u.\n",
510 metrics.tmBreakChar, expmetrics.tmBreakChar);
511 ok(metrics.tmItalic == expmetrics.tmItalic, "Got unexpected italic %u, expected %u.\n",
512 metrics.tmItalic, expmetrics.tmItalic);
513 ok(metrics.tmUnderlined == expmetrics.tmUnderlined, "Got unexpected underlined %u, expected %u.\n",
514 metrics.tmUnderlined, expmetrics.tmUnderlined);
515 ok(metrics.tmStruckOut == expmetrics.tmStruckOut, "Got unexpected struck out %u, expected %u.\n",
516 metrics.tmStruckOut, expmetrics.tmStruckOut);
517 ok(metrics.tmPitchAndFamily == expmetrics.tmPitchAndFamily, "Got unexpected pitch and family %u, expected %u.\n",
518 metrics.tmPitchAndFamily, expmetrics.tmPitchAndFamily);
519 ok(metrics.tmCharSet == expmetrics.tmCharSet, "Got unexpected charset %u, expected %u.\n",
520 metrics.tmCharSet, expmetrics.tmCharSet);
522 ID3DXFont_Release(font);
525 /* ID3DXFont_PreloadText */
526 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
527 DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font);
528 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
530 hr = ID3DXFont_PreloadTextA(font, NULL, -1);
531 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
532 hr = ID3DXFont_PreloadTextA(font, NULL, 0);
533 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
534 hr = ID3DXFont_PreloadTextA(font, NULL, 1);
535 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
536 hr = ID3DXFont_PreloadTextA(font, "test", -1);
537 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
538 hr = ID3DXFont_PreloadTextA(font, "", 0);
539 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
540 hr = ID3DXFont_PreloadTextA(font, "", -1);
541 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
543 hr = ID3DXFont_PreloadTextW(font, NULL, -1);
544 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
545 hr = ID3DXFont_PreloadTextW(font, NULL, 0);
546 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
547 hr = ID3DXFont_PreloadTextW(font, NULL, 1);
548 ok(hr == D3DERR_INVALIDCALL, "Got unexpected hr %#x.\n", hr);
549 hr = ID3DXFont_PreloadTextW(font, testW, -1);
550 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
551 hr = ID3DXFont_PreloadTextW(font, L"", 0);
552 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
553 hr = ID3DXFont_PreloadTextW(font, L"", -1);
554 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
556 check_release((IUnknown*)font, 0);
559 /* ID3DXFont_GetGlyphData, ID3DXFont_PreloadGlyphs, ID3DXFont_PreloadCharacters */
560 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
561 DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font);
562 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
564 hdc = ID3DXFont_GetDC(font);
565 ok(!!hdc, "Got unexpected hdc %p.\n", hdc);
567 hr = ID3DXFont_GetGlyphData(font, 0, NULL, &blackbox, &cellinc);
568 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
569 hr = ID3DXFont_GetGlyphData(font, 0, &texture, NULL, &cellinc);
570 check_release((IUnknown *)texture, 1);
571 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
572 hr = ID3DXFont_GetGlyphData(font, 0, &texture, &blackbox, NULL);
573 check_release((IUnknown *)texture, 1);
574 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
576 hr = ID3DXFont_PreloadCharacters(font, 'b', 'a');
577 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
578 hr = ID3DXFont_PreloadGlyphs(font, 1, 0);
579 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
581 hr = ID3DXFont_PreloadCharacters(font, 'a', 'a');
582 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
584 for (c = 'b'; c <= 'z'; ++c)
586 count = GetGlyphIndicesA(hdc, &c, 1, &glyph, 0);
587 ok(count != GDI_ERROR, "Got unexpected count %u.\n", count);
589 hr = ID3DXFont_GetGlyphData(font, glyph, &texture, &blackbox, &cellinc);
590 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
592 levels = IDirect3DTexture9_GetLevelCount(texture);
593 todo_wine ok(levels == 5, "Character %c: got unexpected levels %u.\n", c, levels);
594 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &surf_desc);
595 ok(hr == D3D_OK, "Character %c: got unexpected hr %#x.\n", c, hr);
596 ok(surf_desc.Format == D3DFMT_A8R8G8B8, "Character %c: got unexpected format %#x.\n", c, surf_desc.Format);
597 ok(surf_desc.Usage == 0, "Character %c: got unexpected usage %#x.\n", c, surf_desc.Usage);
598 ok(surf_desc.Width == 256, "Character %c: got unexpected width %u.\n", c, surf_desc.Width);
599 ok(surf_desc.Height == 256, "Character %c: got unexpected height %u.\n", c, surf_desc.Height);
600 ok(surf_desc.Pool == D3DPOOL_MANAGED, "Character %c: got unexpected pool %u.\n", c, surf_desc.Pool);
602 count = GetGlyphOutlineW(hdc, glyph, GGO_GLYPH_INDEX | GGO_METRICS, &glyph_metrics, 0, NULL, &mat);
603 ok(count != GDI_ERROR, "Got unexpected count %#x.\n", count);
605 ret = ID3DXFont_GetTextMetricsW(font, &tm);
606 ok(ret, "Got unexpected ret %#x.\n", ret);
608 todo_wine ok(blackbox.right - blackbox.left == glyph_metrics.gmBlackBoxX + 2, "Character %c: got %d, expected %d.\n",
609 c, blackbox.right - blackbox.left, glyph_metrics.gmBlackBoxX + 2);
610 todo_wine ok(blackbox.bottom - blackbox.top == glyph_metrics.gmBlackBoxY + 2, "Character %c: got %d, expected %d.\n",
611 c, blackbox.bottom - blackbox.top, glyph_metrics.gmBlackBoxY + 2);
612 ok(cellinc.x == glyph_metrics.gmptGlyphOrigin.x - 1, "Character %c: got %d, expected %d.\n",
613 c, cellinc.x, glyph_metrics.gmptGlyphOrigin.x - 1);
614 ok(cellinc.y == tm.tmAscent - glyph_metrics.gmptGlyphOrigin.y - 1, "Character %c: got %d, expected %d.\n",
615 c, cellinc.y, tm.tmAscent - glyph_metrics.gmptGlyphOrigin.y - 1);
617 check_release((IUnknown *)texture, 1);
620 hr = ID3DXFont_PreloadCharacters(font, 'a', 'z');
621 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
623 /* Test multiple textures */
624 hr = ID3DXFont_PreloadGlyphs(font, 0, 1000);
625 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
627 /* Test glyphs that are not rendered */
628 for (glyph = 1; glyph < 4; ++glyph)
630 texture = (IDirect3DTexture9 *)0xdeadbeef;
631 hr = ID3DXFont_GetGlyphData(font, glyph, &texture, &blackbox, &cellinc);
632 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
633 ok(!texture, "Got unexpected texture %p.\n", texture);
636 check_release((IUnknown *)font, 0);
638 c = 'a';
639 for (i = 0; i < ARRAY_SIZE(tests); ++i)
641 hr = D3DXCreateFontA(device, tests[i].font_height, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET,
642 OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font);
643 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", i, hr);
645 hdc = ID3DXFont_GetDC(font);
646 ok(!!hdc, "Test %u: got unexpected hdc %p.\n", i, hdc);
648 count = GetGlyphIndicesA(hdc, &c, 1, &glyph, 0);
649 ok(count != GDI_ERROR, "Test %u: got unexpected count %u.\n", i, count);
651 hr = ID3DXFont_GetGlyphData(font, glyph, &texture, NULL, NULL);
652 ok(hr == D3D_OK, "Test %u: got unexpected hr %#x.\n", i, hr);
654 levels = IDirect3DTexture9_GetLevelCount(texture);
655 todo_wine_if(tests[i].expected_levels < 9)
656 ok(levels == tests[i].expected_levels, "Test %u: got unexpected levels %u.\n", i, levels);
658 hr = IDirect3DTexture9_GetLevelDesc(texture, 0, &surf_desc);
659 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
660 ok(surf_desc.Format == D3DFMT_A8R8G8B8, "Test %u: got unexpected format %#x.\n", i, surf_desc.Format);
661 ok(surf_desc.Usage == 0, "Test %u: got unexpected usage %#x.\n", i, surf_desc.Usage);
662 ok(surf_desc.Width == tests[i].expected_size, "Test %u: got unexpected width %u.\n", i, surf_desc.Width);
663 ok(surf_desc.Height == tests[i].expected_size, "Test %u: got unexpected height %u.\n", i, surf_desc.Height);
664 ok(surf_desc.Pool == D3DPOOL_MANAGED, "Test %u: got unexpected pool %u.\n", i, surf_desc.Pool);
666 IDirect3DTexture9_Release(texture);
668 /* ID3DXFontImpl_DrawText */
669 D3DXCreateSprite(device, &sprite);
670 SetRect(&rect, 0, 0, 640, 480);
672 IDirect3DDevice9_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff000000, 1.0f, 0);
674 IDirect3DDevice9_BeginScene(device);
675 hr = ID3DXSprite_Begin(sprite, D3DXSPRITE_ALPHABLEND);
676 ok (hr == D3D_OK, "Test %d: got unexpected hr %#x.\n", i, hr);
678 height = ID3DXFont_DrawTextW(font, sprite, testW, -1, &rect, DT_TOP, 0xffffffff);
679 ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height);
680 height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect, DT_TOP, 0xffffffff);
681 ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height);
682 height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect, DT_RIGHT, 0xffffffff);
683 ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height);
684 height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect, DT_LEFT | DT_NOCLIP, 0xffffffff);
685 ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height);
687 SetRectEmpty(&rect);
688 height = ID3DXFont_DrawTextW(font, sprite, testW, size, &rect,
689 DT_LEFT | DT_CALCRECT, 0xffffffff);
690 ok(height == tests[i].font_height, "Test %d: got unexpected height %u.\n", i, height);
691 ok(!rect.left, "Test %d: got unexpected rect left %d.\n", i, rect.left);
692 ok(!rect.top, "Test %d: got unexpected rect top %d.\n", i, rect.top);
693 ok(rect.right, "Test %d: got unexpected rect right %d.\n", i, rect.right);
694 ok(rect.bottom == tests[i].font_height, "Test %d: got unexpected rect bottom %d.\n", i, rect.bottom);
696 hr = ID3DXSprite_End(sprite);
697 ok (hr == D3D_OK, "Test %d: got unexpected hr %#x.\n", i, hr);
698 IDirect3DDevice9_EndScene(device);
699 ID3DXSprite_Release(sprite);
701 ID3DXFont_Release(font);
705 /* ID3DXFont_DrawTextA, ID3DXFont_DrawTextW */
706 hr = D3DXCreateFontA(device, 12, 0, FW_DONTCARE, 0, FALSE, DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
707 DEFAULT_QUALITY, DEFAULT_PITCH, "Tahoma", &font);
708 ok(hr == D3D_OK, "Got unexpected hr %#x.\n", hr);
710 SetRect(&rect, 10, 10, 200, 200);
712 height = ID3DXFont_DrawTextA(font, NULL, "test", -2, &rect, 0, 0xFF00FF);
713 ok(height == 12, "Got unexpected height %d.\n", height);
715 height = ID3DXFont_DrawTextA(font, NULL, "test", -1, &rect, 0, 0xFF00FF);
716 ok(height == 12, "Got unexpected height %d.\n", height);
718 height = ID3DXFont_DrawTextA(font, NULL, "test", 0, &rect, 0, 0xFF00FF);
719 ok(height == 0, "Got unexpected height %d.\n", height);
721 height = ID3DXFont_DrawTextA(font, NULL, "test", 1, &rect, 0, 0xFF00FF);
722 ok(height == 12, "Got unexpected height %d.\n", height);
724 height = ID3DXFont_DrawTextA(font, NULL, "test", 2, &rect, 0, 0xFF00FF);
725 ok(height == 12, "Got unexpected height %d.\n", height);
727 height = ID3DXFont_DrawTextA(font, NULL, "", 0, &rect, 0, 0xff00ff);
728 ok(height == 0, "Got unexpected height %d.\n", height);
730 height = ID3DXFont_DrawTextA(font, NULL, "", -1, &rect, 0, 0xff00ff);
731 ok(height == 0, "Got unexpected height %d.\n", height);
733 height = ID3DXFont_DrawTextA(font, NULL, "test", -1, NULL, 0, 0xFF00FF);
734 ok(height == 12, "Got unexpected height %d.\n", height);
736 height = ID3DXFont_DrawTextA(font, NULL, "test", -1, NULL, DT_CALCRECT, 0xFF00FF);
737 ok(height == 12, "Got unexpected height %d.\n", height);
739 height = ID3DXFont_DrawTextA(font, NULL, NULL, -1, NULL, 0, 0xFF00FF);
740 ok(height == 0, "Got unexpected height %d.\n", height);
742 SetRect(&rect, 10, 10, 50, 50);
744 height = ID3DXFont_DrawTextA(font, NULL, long_text, -1, &rect, DT_WORDBREAK, 0xff00ff);
745 todo_wine ok(height == 60, "Got unexpected height %d.\n", height);
747 height = ID3DXFont_DrawTextA(font, NULL, long_text, -1, &rect, DT_WORDBREAK | DT_NOCLIP, 0xff00ff);
748 ok(height == 96, "Got unexpected height %d.\n", height);
750 SetRect(&rect, 10, 10, 200, 200);
752 height = ID3DXFont_DrawTextW(font, NULL, testW, -1, &rect, 0, 0xFF00FF);
753 ok(height == 12, "Got unexpected height %d.\n", height);
755 height = ID3DXFont_DrawTextW(font, NULL, testW, 0, &rect, 0, 0xFF00FF);
756 ok(height == 0, "Got unexpected height %d.\n", height);
758 height = ID3DXFont_DrawTextW(font, NULL, testW, 1, &rect, 0, 0xFF00FF);
759 ok(height == 12, "Got unexpected height %d.\n", height);
761 height = ID3DXFont_DrawTextW(font, NULL, testW, 2, &rect, 0, 0xFF00FF);
762 ok(height == 12, "Got unexpected height %d.\n", height);
764 height = ID3DXFont_DrawTextW(font, NULL, L"", 0, &rect, 0, 0xff00ff);
765 ok(height == 0, "Got unexpected height %d.\n", height);
767 height = ID3DXFont_DrawTextW(font, NULL, L"", -1, &rect, 0, 0xff00ff);
768 ok(height == 0, "Got unexpected height %d.\n", height);
770 height = ID3DXFont_DrawTextW(font, NULL, testW, -1, NULL, 0, 0xFF00FF);
771 ok(height == 12, "Got unexpected height %d.\n", height);
773 height = ID3DXFont_DrawTextW(font, NULL, testW, -1, NULL, DT_CALCRECT, 0xFF00FF);
774 ok(height == 12, "Got unexpected height %d.\n", height);
776 height = ID3DXFont_DrawTextW(font, NULL, NULL, -1, NULL, 0, 0xFF00FF);
777 ok(height == 0, "Got unexpected height %d.\n", height);
779 SetRect(&rect, 10, 10, 50, 50);
781 height = ID3DXFont_DrawTextW(font, NULL, long_textW, -1, &rect, DT_WORDBREAK, 0xff00ff);
782 todo_wine ok(height == 60, "Got unexpected height %d.\n", height);
784 height = ID3DXFont_DrawTextW(font, NULL, long_textW, -1, &rect, DT_WORDBREAK | DT_NOCLIP, 0xff00ff);
785 ok(height == 96, "Got unexpected height %d.\n", height);
787 height = ID3DXFont_DrawTextW(font, NULL, L"a\na", -1, NULL, 0, 0xff00ff);
788 ok(height == 24, "Got unexpected height %d.\n", height);
790 height = ID3DXFont_DrawTextW(font, NULL, L"a\na", -1, &rect, 0, 0xff00ff);
791 ok(height == 24, "Got unexpected height %d.\n", height);
793 height = ID3DXFont_DrawTextW(font, NULL, L"a\r\na", -1, &rect, 0, 0xff00ff);
794 ok(height == 24, "Got unexpected height %d.\n", height);
796 height = ID3DXFont_DrawTextW(font, NULL, L"a\ra", -1, &rect, 0, 0xff00ff);
797 ok(height == 12, "Got unexpected height %d.\n", height);
799 height = ID3DXFont_DrawTextW(font, NULL, L"a\na", -1, &rect, DT_SINGLELINE, 0xff00ff);
800 ok(height == 12, "Got unexpected height %d.\n", height);
802 height = ID3DXFont_DrawTextW(font, NULL, L"a\naaaaa aaaa", -1, &rect, DT_SINGLELINE, 0xff00ff);
803 ok(height == 12, "Got unexpected height %d.\n", height);
805 height = ID3DXFont_DrawTextW(font, NULL, L"a\naaaaa aaaa", -1, &rect, 0, 0xff00ff);
806 ok(height == 24, "Got unexpected height %d.\n", height);
808 height = ID3DXFont_DrawTextW(font, NULL, L"a\naaaaa aaaa", -1, &rect, DT_WORDBREAK, 0xff00ff);
809 ok(height == 36, "Got unexpected height %d.\n", height);
811 height = ID3DXFont_DrawTextW(font, NULL, L"a\naaaaa aaaa", -1, &rect, DT_WORDBREAK | DT_SINGLELINE, 0xff00ff);
812 ok(height == 12, "Got unexpected height %d.\n", height);
814 height = ID3DXFont_DrawTextW(font, NULL, L"1\n2\n3\n4\n5\n6", -1, &rect, 0, 0xff00ff);
815 ok(height == 48, "Got unexpected height %d.\n", height);
817 height = ID3DXFont_DrawTextW(font, NULL, L"1\n2\n3\n4\n5\n6", -1, &rect, DT_NOCLIP, 0xff00ff);
818 ok(height == 72, "Got unexpected height %d.\n", height);
820 height = ID3DXFont_DrawTextW(font, NULL, L"\t\t\t\t\t\t\t\t\t\t", -1, &rect, DT_WORDBREAK, 0xff00ff);
821 todo_wine ok(height == 0, "Got unexpected height %d.\n", height);
823 height = ID3DXFont_DrawTextW(font, NULL, L"\t\t\t\t\t\t\t\t\t\ta", -1, &rect, DT_WORDBREAK, 0xff00ff);
824 todo_wine ok(height == 12, "Got unexpected height %d.\n", height);
826 height = ID3DXFont_DrawTextW(font, NULL, L"\taaaaaaaaaa", -1, &rect, DT_WORDBREAK, 0xff00ff);
827 todo_wine ok(height == 24, "Got unexpected height %d.\n", height);
829 height = ID3DXFont_DrawTextW(font, NULL, L"\taaaaaaaaaa", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff);
830 ok(height == 36, "Got unexpected height %d.\n", height);
832 height = ID3DXFont_DrawTextW(font, NULL, L"\taaa\taaa\taaa", -1, &rect, DT_WORDBREAK, 0xff00ff);
833 ok(height == 24, "Got unexpected height %d.\n", height);
835 height = ID3DXFont_DrawTextW(font, NULL, L"\taaa\taaa\taaa", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff);
836 todo_wine ok(height == 48, "Got unexpected height %d.\n", height);
838 height = ID3DXFont_DrawTextW(font, NULL, L"\t\t\t\t\t\t\t\t\t\t", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff);
839 todo_wine ok(height == 60, "Got unexpected height %d.\n", height);
841 height = ID3DXFont_DrawTextW(font, NULL, L"a\ta", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff);
842 ok(height == 12, "Got unexpected height %d.\n", height);
844 height = ID3DXFont_DrawTextW(font, NULL, L"a\ta\ta", -1, &rect, DT_EXPANDTABS | DT_WORDBREAK, 0xff00ff);
845 todo_wine ok(height == 24, "Got unexpected height %d.\n", height);
847 height = ID3DXFont_DrawTextW(font, NULL, L"aaaaaaaaaaaaaaaaaaaa", -1, &rect, DT_WORDBREAK, 0xff00ff);
848 ok(height == 36, "Got unexpected height %d.\n", height);
850 height = ID3DXFont_DrawTextW(font, NULL, L"a a", -1, &rect, DT_WORDBREAK, 0xff00ff);
851 ok(height == 36, "Got unexpected height %d.\n", height);
853 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK, 0xff00ff);
854 ok(height == 36, "Got unexpected height %d.\n", height);
856 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_RIGHT, 0xff00ff);
857 ok(height == 36, "Got unexpected height %d.\n", height);
859 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CENTER, 0xff00ff);
860 ok(height == 36, "Got unexpected height %d.\n", height);
862 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM, 0xff00ff);
863 ok(height == 40, "Got unexpected height %d.\n", height);
865 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER, 0xff00ff);
866 ok(height == 32, "Got unexpected height %d.\n", height);
868 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_RIGHT, 0xff00ff);
869 ok(height == 24, "Got unexpected height %d.\n", height);
871 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER, 0xff00ff);
872 ok(height == 24, "Got unexpected height %d.\n", height);
874 SetRect(&rect, 10, 10, 50, 50);
875 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CALCRECT, 0xff00ff);
876 ok(height == 24, "Got unexpected height %d.\n", height);
877 check_rect(&rect, 10, 10, 30, 34);
879 SetRect(&rect, -10, 10, 30, 50);
880 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CALCRECT, 0xff00ff);
881 ok(height == 24, "Got unexpected height %d.\n", height);
882 check_rect(&rect, -10, 10, 10, 34);
884 SetRect(&rect, 10, -10, 50, 30);
885 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CALCRECT, 0xff00ff);
886 ok(height == 24, "Got unexpected height %d.\n", height);
887 check_rect(&rect, 10, -10, 30, 14);
889 SetRect(&rect, 10, 10, -30, 50);
890 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CALCRECT, 0xff00ff);
891 ok(height == 24, "Got unexpected height %d.\n", height);
892 check_rect(&rect, 10, 10, 30, 34);
894 SetRect(&rect, 10, 10, 50, -30);
895 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CALCRECT, 0xff00ff);
896 ok(height == 24, "Got unexpected height %d.\n", height);
897 check_rect(&rect, 10, 10, 30, 34);
899 SetRect(&rect, 10, 10, 50, 50);
900 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
901 ok(height == 24, "Got unexpected height %d.\n", height);
902 check_rect(&rect, 10, 10, 30, 34);
904 SetRect(&rect, -10, 10, 30, 50);
905 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
906 ok(height == 24, "Got unexpected height %d.\n", height);
907 check_rect(&rect, -10, 10, 10, 34);
909 SetRect(&rect, 10, -10, 50, 30);
910 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
911 ok(height == 24, "Got unexpected height %d.\n", height);
912 check_rect(&rect, 10, -10, 30, 14);
914 SetRect(&rect, 10, 10, -30, 50);
915 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
916 ok(height == 12, "Got unexpected height %d.\n", height);
917 check_rect(&rect, 10, 10, 53, 22);
919 SetRect(&rect, 10, 10, 50, -30);
920 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
921 ok(height == 24, "Got unexpected height %d.\n", height);
922 check_rect(&rect, 10, 10, 30, 34);
924 SetRect(&rect, 10, 10, 50, 50);
925 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff);
926 ok(height == 40, "Got unexpected height %d.\n", height);
927 check_rect(&rect, 10, 26, 30, 50);
929 SetRect(&rect, -10, 10, 30, 50);
930 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff);
931 ok(height == 40, "Got unexpected height %d.\n", height);
932 check_rect(&rect, -10, 26, 10, 50);
934 SetRect(&rect, 10, -10, 50, 30);
935 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff);
936 ok(height == 40, "Got unexpected height %d.\n", height);
937 check_rect(&rect, 10, 6, 30, 30);
939 SetRect(&rect, 10, 10, -30, 50);
940 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff);
941 ok(height == 40, "Got unexpected height %d.\n", height);
942 check_rect(&rect, 10, 26, 30, 50);
944 SetRect(&rect, 10, 10, 50, -30);
945 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_BOTTOM | DT_CALCRECT, 0xff00ff);
946 ok(height == -40, "Got unexpected height %d.\n", height);
947 check_rect(&rect, 10, -54, 30, -30);
949 SetRect(&rect, 10, 10, 50, 50);
950 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_BOTTOM | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
951 ok(height == 40, "Got unexpected height %d.\n", height);
952 check_rect(&rect, 10, 26, 30, 50);
954 SetRect(&rect, -10, 10, 30, 50);
955 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_BOTTOM | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
956 ok(height == 40, "Got unexpected height %d.\n", height);
957 check_rect(&rect, -10, 26, 10, 50);
959 SetRect(&rect, 10, -10, 50, 30);
960 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_BOTTOM | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
961 ok(height == 40, "Got unexpected height %d.\n", height);
962 check_rect(&rect, 10, 6, 30, 30);
964 SetRect(&rect, 10, 10, -30, 50);
965 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_BOTTOM | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
966 ok(height == 40, "Got unexpected height %d.\n", height);
967 check_rect(&rect, 10, 38, 53, 50);
969 SetRect(&rect, 10, 10, 50, -30);
970 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_BOTTOM | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
971 ok(height == -40, "Got unexpected height %d.\n", height);
972 check_rect(&rect, 10, -54, 30, -30);
974 SetRect(&rect, 10, 10, 50, 50);
975 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff);
976 ok(height == 32, "Got unexpected height %d.\n", height);
977 check_rect(&rect, 10, 18, 30, 42);
979 SetRect(&rect, -10, 10, 30, 50);
980 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff);
981 ok(height == 32, "Got unexpected height %d.\n", height);
982 check_rect(&rect, -10, 18, 10, 42);
984 SetRect(&rect, 10, -10, 50, 30);
985 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff);
986 ok(height == 32, "Got unexpected height %d.\n", height);
987 check_rect(&rect, 10, -2, 30, 22);
989 SetRect(&rect, 10, 10, -30, 50);
990 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff);
991 ok(height == 32, "Got unexpected height %d.\n", height);
992 check_rect(&rect, 10, 18, 30, 42);
994 SetRect(&rect, 10, 10, 50, -30);
995 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_VCENTER | DT_CALCRECT, 0xff00ff);
996 ok(height == -8, "Got unexpected height %d.\n", height);
997 check_rect(&rect, 10, -22, 30, 2);
999 SetRect(&rect, 10, 10, 50, 50);
1000 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1001 ok(height == 32, "Got unexpected height %d.\n", height);
1002 check_rect(&rect, 10, 18, 30, 42);
1004 SetRect(&rect, -10, 10, 30, 50);
1005 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1006 ok(height == 32, "Got unexpected height %d.\n", height);
1007 check_rect(&rect, -10, 18, 10, 42);
1009 SetRect(&rect, 10, -10, 50, 30);
1010 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1011 ok(height == 32, "Got unexpected height %d.\n", height);
1012 check_rect(&rect, 10, -2, 30, 22);
1014 SetRect(&rect, 10, 10, -30, 50);
1015 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1016 ok(height == 26, "Got unexpected height %d.\n", height);
1017 check_rect(&rect, 10, 24, 53, 36);
1019 SetRect(&rect, 10, 10, 50, -30);
1020 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1021 ok(height == -8, "Got unexpected height %d.\n", height);
1022 check_rect(&rect, 10, -22, 30, 2);
1024 SetRect(&rect, 10, 10, 50, 50);
1025 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_RIGHT | DT_CALCRECT, 0xff00ff);
1026 ok(height == 24, "Got unexpected height %d.\n", height);
1027 check_rect(&rect, 30, 10, 50, 34);
1029 SetRect(&rect, -10, 10, 30, 50);
1030 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_RIGHT | DT_CALCRECT, 0xff00ff);
1031 ok(height == 24, "Got unexpected height %d.\n", height);
1032 check_rect(&rect, 10, 10, 30, 34);
1034 SetRect(&rect, 10, -10, 50, 30);
1035 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_RIGHT | DT_CALCRECT, 0xff00ff);
1036 ok(height == 24, "Got unexpected height %d.\n", height);
1037 check_rect(&rect, 30, -10, 50, 14);
1039 SetRect(&rect, 10, 10, -30, 50);
1040 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_RIGHT | DT_CALCRECT, 0xff00ff);
1041 ok(height == 24, "Got unexpected height %d.\n", height);
1042 check_rect(&rect, -50, 10, -30, 34);
1044 SetRect(&rect, 10, 10, 50, -30);
1045 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_RIGHT | DT_CALCRECT, 0xff00ff);
1046 ok(height == 24, "Got unexpected height %d.\n", height);
1047 check_rect(&rect, 30, 10, 50, 34);
1049 SetRect(&rect, 10, 10, 50, 50);
1050 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_RIGHT | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1051 ok(height == 24, "Got unexpected height %d.\n", height);
1052 check_rect(&rect, 30, 10, 50, 34);
1054 SetRect(&rect, -10, 10, 30, 50);
1055 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_RIGHT | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1056 ok(height == 24, "Got unexpected height %d.\n", height);
1057 check_rect(&rect, 10, 10, 30, 34);
1059 SetRect(&rect, 10, -10, 50, 30);
1060 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_RIGHT | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1061 ok(height == 24, "Got unexpected height %d.\n", height);
1062 check_rect(&rect, 30, -10, 50, 14);
1064 SetRect(&rect, 10, 10, -30, 50);
1065 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_RIGHT | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1066 ok(height == 12, "Got unexpected height %d.\n", height);
1067 check_rect(&rect, -73, 10, -30, 22);
1069 SetRect(&rect, 10, 10, 50, -30);
1070 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_RIGHT | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1071 ok(height == 24, "Got unexpected height %d.\n", height);
1072 check_rect(&rect, 30, 10, 50, 34);
1074 SetRect(&rect, 10, 10, 50, 50);
1075 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_CALCRECT, 0xff00ff);
1076 ok(height == 24, "Got unexpected height %d.\n", height);
1077 check_rect(&rect, 20, 10, 40, 34);
1079 SetRect(&rect, -10, 10, 30, 50);
1080 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_CALCRECT, 0xff00ff);
1081 ok(height == 24, "Got unexpected height %d.\n", height);
1082 check_rect(&rect, 0, 10, 20, 34);
1084 SetRect(&rect, 10, -10, 50, 30);
1085 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_CALCRECT, 0xff00ff);
1086 ok(height == 24, "Got unexpected height %d.\n", height);
1087 check_rect(&rect, 20, -10, 40, 14);
1089 SetRect(&rect, 10, 10, -30, 50);
1090 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_CALCRECT, 0xff00ff);
1091 ok(height == 24, "Got unexpected height %d.\n", height);
1092 check_rect(&rect, -20, 10, 0, 34);
1094 SetRect(&rect, 10, 10, 50, -30);
1095 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_CALCRECT, 0xff00ff);
1096 ok(height == 24, "Got unexpected height %d.\n", height);
1097 check_rect(&rect, 20, 10, 40, 34);
1099 SetRect(&rect, 10, 10, 50, 50);
1100 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1101 ok(height == 24, "Got unexpected height %d.\n", height);
1102 check_rect(&rect, 20, 10, 40, 34);
1104 SetRect(&rect, -10, 10, 30, 50);
1105 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1106 ok(height == 24, "Got unexpected height %d.\n", height);
1107 check_rect(&rect, 0, 10, 20, 34);
1109 SetRect(&rect, 10, -10, 50, 30);
1110 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1111 ok(height == 24, "Got unexpected height %d.\n", height);
1112 check_rect(&rect, 20, -10, 40, 14);
1114 SetRect(&rect, 10, 10, -30, 50);
1115 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1116 ok(height == 12, "Got unexpected height %d.\n", height);
1117 check_rect(&rect, -31, 10, 12, 22);
1119 SetRect(&rect, 10, 10, 50, -30);
1120 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1121 ok(height == 24, "Got unexpected height %d.\n", height);
1122 check_rect(&rect, 20, 10, 40, 34);
1124 SetRect(&rect, 10, 10, 50, 50);
1125 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_CALCRECT, 0xff00ff);
1126 ok(height == 32, "Got unexpected height %d.\n", height);
1127 check_rect(&rect, 20, 18, 40, 42);
1129 SetRect(&rect, 10, 10, 50, 50);
1130 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_CALCRECT, 0xff00ff);
1131 ok(height == 32, "Got unexpected height %d.\n", height);
1132 check_rect(&rect, 20, 18, 40, 42);
1134 SetRect(&rect, -10, 10, 30, 50);
1135 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_CALCRECT, 0xff00ff);
1136 ok(height == 32, "Got unexpected height %d.\n", height);
1137 check_rect(&rect, 0, 18, 20, 42);
1139 SetRect(&rect, 10, -10, 50, 30);
1140 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_CALCRECT, 0xff00ff);
1141 ok(height == 32, "Got unexpected height %d.\n", height);
1142 check_rect(&rect, 20, -2, 40, 22);
1144 SetRect(&rect, 10, 10, -30, 50);
1145 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_CALCRECT, 0xff00ff);
1146 ok(height == 32, "Got unexpected height %d.\n", height);
1147 check_rect(&rect, -20, 18, 0, 42);
1149 SetRect(&rect, 10, 10, 50, -30);
1150 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa\naaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_CALCRECT, 0xff00ff);
1151 ok(height == -8, "Got unexpected height %d.\n", height);
1152 check_rect(&rect, 20, -22, 40, 2);
1154 SetRect(&rect, 10, 10, 50, 50);
1155 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1156 ok(height == 32, "Got unexpected height %d.\n", height);
1157 check_rect(&rect, 20, 18, 40, 42);
1159 SetRect(&rect, 10, 10, 50, 50);
1160 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1161 ok(height == 32, "Got unexpected height %d.\n", height);
1162 check_rect(&rect, 20, 18, 40, 42);
1164 SetRect(&rect, -10, 10, 30, 50);
1165 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1166 ok(height == 32, "Got unexpected height %d.\n", height);
1167 check_rect(&rect, 0, 18, 20, 42);
1169 SetRect(&rect, 10, -10, 50, 30);
1170 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1171 ok(height == 32, "Got unexpected height %d.\n", height);
1172 check_rect(&rect, 20, -2, 40, 22);
1174 SetRect(&rect, 10, 10, -30, 50);
1175 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1176 ok(height == 26, "Got unexpected height %d.\n", height);
1177 check_rect(&rect, -31, 24, 12, 36);
1179 SetRect(&rect, 10, 10, 50, -30);
1180 height = ID3DXFont_DrawTextW(font, NULL, L"aaaa aaaa", -1, &rect, DT_CENTER | DT_VCENTER | DT_WORDBREAK | DT_CALCRECT, 0xff00ff);
1181 ok(height == -8, "Got unexpected height %d.\n", height);
1182 check_rect(&rect, 20, -22, 40, 2);
1184 ID3DXFont_Release(font);
1187 static void test_D3DXCreateRenderToSurface(IDirect3DDevice9 *device)
1189 int i;
1190 HRESULT hr;
1191 ULONG ref_count;
1192 D3DXRTS_DESC desc;
1193 ID3DXRenderToSurface *render = (void *)0xdeadbeef;
1194 static const D3DXRTS_DESC tests[] =
1196 { 0, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN },
1197 { 256, 0, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN },
1198 { 256, 0, D3DFMT_A8R8G8B8, FALSE, D3DFMT_D24S8 },
1199 { 256, 256, D3DFMT_UNKNOWN, FALSE, D3DFMT_R8G8B8 },
1200 { 0, 0, D3DFMT_UNKNOWN, FALSE, D3DFMT_UNKNOWN },
1201 { -1, -1, MAKEFOURCC('B','A','D','F'), TRUE, MAKEFOURCC('B','A','D','F') }
1204 hr = D3DXCreateRenderToSurface(NULL /* device */, 256, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, &render);
1205 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateRenderToSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1206 ok(render == (void *)0xdeadbeef, "Got %p, expected %p\n", render, (void *)0xdeadbeef);
1208 hr = D3DXCreateRenderToSurface(device, 256, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, NULL /* out */);
1209 ok(hr == D3DERR_INVALIDCALL, "D3DXCreateRenderToSurface returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1211 for (i = 0; i < ARRAY_SIZE(tests); i++)
1213 hr = D3DXCreateRenderToSurface(device, tests[i].Width, tests[i].Height, tests[i].Format, tests[i].DepthStencil,
1214 tests[i].DepthStencilFormat, &render);
1215 ok(hr == D3D_OK, "%d: D3DXCreateRenderToSurface returned %#x, expected %#x\n", i, hr, D3D_OK);
1216 if (SUCCEEDED(hr))
1218 hr = ID3DXRenderToSurface_GetDesc(render, &desc);
1219 ok(hr == D3D_OK, "%d: GetDesc failed %#x\n", i, hr);
1220 if (SUCCEEDED(hr))
1222 ok(desc.Width == tests[i].Width, "%d: Got width %u, expected %u\n", i, desc.Width, tests[i].Width);
1223 ok(desc.Height == tests[i].Height, "%d: Got height %u, expected %u\n", i, desc.Height, tests[i].Height);
1224 ok(desc.Format == tests[i].Format, "%d: Got format %#x, expected %#x\n", i, desc.Format, tests[i].Format);
1225 ok(desc.DepthStencil == tests[i].DepthStencil, "%d: Got depth stencil %d, expected %d\n",
1226 i, desc.DepthStencil, tests[i].DepthStencil);
1227 ok(desc.DepthStencilFormat == tests[i].DepthStencilFormat, "%d: Got depth stencil format %#x, expected %#x\n",
1228 i, desc.DepthStencilFormat, tests[i].DepthStencilFormat);
1230 ID3DXRenderToSurface_Release(render);
1234 /* check device ref count */
1235 ref_count = get_ref((IUnknown *)device);
1236 hr = D3DXCreateRenderToSurface(device, 0, 0, D3DFMT_UNKNOWN, FALSE, D3DFMT_UNKNOWN, &render);
1237 check_ref((IUnknown *)device, ref_count + 1);
1238 if (SUCCEEDED(hr)) ID3DXRenderToSurface_Release(render);
1241 /* runs a set of tests for the ID3DXRenderToSurface interface created with given parameters */
1242 static void check_ID3DXRenderToSurface(IDirect3DDevice9 *device, UINT width, UINT height, D3DFORMAT format,
1243 BOOL depth_stencil, D3DFORMAT depth_stencil_format, BOOL render_target)
1245 HRESULT hr;
1246 D3DFORMAT fmt;
1247 HRESULT expected_value;
1248 IDirect3DSurface9 *surface;
1249 ID3DXRenderToSurface *render;
1250 D3DVIEWPORT9 viewport = { 0, 0, width, height, 0.0, 1.0 };
1252 hr = D3DXCreateRenderToSurface(device, width, height, format, depth_stencil, depth_stencil_format, &render);
1253 if (FAILED(hr))
1255 skip("Failed to create ID3DXRenderToSurface\n");
1256 return;
1259 if (render_target)
1260 hr = IDirect3DDevice9_CreateRenderTarget(device, width, height, format, D3DMULTISAMPLE_NONE, 0, FALSE, &surface, NULL);
1261 else
1262 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, format, D3DPOOL_DEFAULT, &surface, NULL);
1263 if (FAILED(hr))
1265 skip("Failed to create surface\n");
1266 ID3DXRenderToSurface_Release(render);
1267 return;
1270 /* viewport */
1271 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
1272 ok(hr == D3D_OK, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3D_OK);
1273 check_ref((IUnknown *)surface, 2);
1274 if (SUCCEEDED(hr)) ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
1276 /* invalid viewport */
1277 viewport.Width = 2 * width;
1278 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
1279 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1281 viewport.X = width / 2;
1282 viewport.Width = width;
1283 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
1284 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1286 viewport.X = width;
1287 viewport.Width = width;
1288 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
1289 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1291 /* rendering to a part of a surface is only allowed for render target surfaces */
1292 expected_value = render_target ? D3D_OK : D3DERR_INVALIDCALL;
1294 viewport.X = 0;
1295 viewport.Width = width / 2;
1296 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
1297 ok(hr == expected_value, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, expected_value);
1298 if (SUCCEEDED(hr)) ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
1300 viewport.X = width / 2;
1301 viewport.Width = width - width / 2;
1302 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
1303 ok(hr == expected_value, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, expected_value);
1304 if (SUCCEEDED(hr)) ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
1306 check_release((IUnknown *)surface, 0);
1308 /* surfaces with different sizes */
1309 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width / 2, width / 2, format, D3DPOOL_DEFAULT, &surface, NULL);
1310 if (FAILED(hr))
1312 skip("Failed to create surface\n");
1313 ID3DXRenderToSurface_Release(render);
1314 return;
1316 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
1317 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1318 check_release((IUnknown *)surface, 0);
1320 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 2 * width, 2 * height, format, D3DPOOL_DEFAULT, &surface, NULL);
1321 if (FAILED(hr))
1323 skip("Failed to create surface\n");
1324 ID3DXRenderToSurface_Release(render);
1325 return;
1327 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
1328 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1329 viewport.X = 0;
1330 viewport.Y = 0;
1331 viewport.Width = width;
1332 viewport.Height = height;
1333 hr = ID3DXRenderToSurface_BeginScene(render, surface, &viewport);
1334 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1335 check_release((IUnknown *)surface, 0);
1337 /* surfaces with different formats */
1338 for (fmt = D3DFMT_A8R8G8B8; fmt <= D3DFMT_X8R8G8B8; fmt++)
1340 HRESULT expected_result = (fmt != format) ? D3DERR_INVALIDCALL : D3D_OK;
1342 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, width, height, fmt, D3DPOOL_DEFAULT, &surface, NULL);
1343 if (FAILED(hr))
1345 skip("Failed to create surface\n");
1346 continue;
1349 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
1350 ok(hr == expected_result, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, expected_result);
1352 if (SUCCEEDED(hr)) ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
1353 check_release((IUnknown *)surface, 0);
1356 check_release((IUnknown *)render, 0);
1359 struct device_state
1361 IDirect3DSurface9 *render_target;
1362 IDirect3DSurface9 *depth_stencil;
1363 D3DVIEWPORT9 viewport;
1366 static void release_device_state(struct device_state *state)
1368 if (state->render_target) IDirect3DSurface9_Release(state->render_target);
1369 if (state->depth_stencil) IDirect3DSurface9_Release(state->depth_stencil);
1370 memset(state, 0, sizeof(*state));
1373 static HRESULT retrieve_device_state(IDirect3DDevice9 *device, struct device_state *state)
1375 HRESULT hr;
1377 memset(state, 0, sizeof(*state));
1379 hr = IDirect3DDevice9_GetRenderTarget(device, 0, &state->render_target);
1380 if (FAILED(hr)) goto cleanup;
1382 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &state->depth_stencil);
1383 if (hr == D3DERR_NOTFOUND)
1384 state->depth_stencil = NULL;
1385 else if (FAILED(hr))
1386 goto cleanup;
1388 hr = IDirect3DDevice9_GetViewport(device, &state->viewport);
1389 if (SUCCEEDED(hr)) return hr;
1391 cleanup:
1392 release_device_state(state);
1393 return hr;
1396 static HRESULT apply_device_state(IDirect3DDevice9 *device, struct device_state *state)
1398 HRESULT hr;
1399 HRESULT status = D3D_OK;
1401 hr = IDirect3DDevice9_SetRenderTarget(device, 0, state->render_target);
1402 if (FAILED(hr)) status = hr;
1404 hr = IDirect3DDevice9_SetDepthStencilSurface(device, state->depth_stencil);
1405 if (FAILED(hr)) status = hr;
1407 hr = IDirect3DDevice9_SetViewport(device, &state->viewport);
1408 if (FAILED(hr)) status = hr;
1410 return status;
1413 static void compare_device_state(struct device_state *state1, struct device_state *state2, BOOL equal)
1415 BOOL cmp;
1416 const char *message = equal ? "differs" : "is the same";
1418 cmp = state1->render_target == state2->render_target;
1419 ok(equal ? cmp : !cmp, "Render target %s %p, %p\n", message, state1->render_target, state2->render_target);
1421 cmp = state1->depth_stencil == state2->depth_stencil;
1422 ok(equal ? cmp : !cmp, "Depth stencil surface %s %p, %p\n", message, state1->depth_stencil, state2->depth_stencil);
1424 cmp = state1->viewport.X == state2->viewport.X && state1->viewport.Y == state2->viewport.Y
1425 && state1->viewport.Width == state2->viewport.Width && state1->viewport.Height == state2->viewport.Height;
1426 ok(equal ? cmp : !cmp, "Viewport %s (%u, %u, %u, %u), (%u, %u, %u, %u)\n", message,
1427 state1->viewport.X, state1->viewport.Y, state1->viewport.Width, state1->viewport.Height,
1428 state2->viewport.X, state2->viewport.Y, state2->viewport.Width, state2->viewport.Height);
1431 static void test_ID3DXRenderToSurface_device_state(IDirect3DDevice9 *device)
1433 HRESULT hr;
1434 IDirect3DSurface9 *surface = NULL;
1435 ID3DXRenderToSurface *render = NULL;
1436 struct device_state pre_state;
1437 struct device_state current_state;
1438 IDirect3DSurface9 *depth_stencil_surface;
1440 /* make sure there is a depth stencil surface present */
1441 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &depth_stencil_surface);
1442 if (SUCCEEDED(hr))
1444 IDirect3DSurface9_Release(depth_stencil_surface);
1445 depth_stencil_surface = NULL;
1447 else if (hr == D3DERR_NOTFOUND)
1449 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 256, 256, D3DFMT_D24X8,
1450 D3DMULTISAMPLE_NONE, 0, TRUE, &depth_stencil_surface, NULL);
1451 if (SUCCEEDED(hr)) IDirect3DDevice9_SetDepthStencilSurface(device, depth_stencil_surface);
1454 if (FAILED(hr))
1456 skip("Failed to create depth stencil surface\n");
1457 return;
1460 hr = IDirect3DDevice9_CreateRenderTarget(device, 256, 256, D3DFMT_A8R8G8B8, D3DMULTISAMPLE_NONE, 0,
1461 FALSE, &surface, NULL);
1462 if (FAILED(hr))
1464 skip("Failed to create render target\n");
1465 goto cleanup;
1468 hr = retrieve_device_state(device, &pre_state);
1469 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1471 hr = D3DXCreateRenderToSurface(device, 256, 256, D3DFMT_A8R8G8B8, TRUE, D3DFMT_D24X8, &render);
1472 ok(hr == D3D_OK, "D3DXCreateRenderToSurface returned %#x, expected %#x\n", hr, D3D_OK);
1473 if (SUCCEEDED(hr))
1475 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
1476 ok(hr == D3D_OK, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3D_OK);
1478 hr = retrieve_device_state(device, &current_state);
1479 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1480 compare_device_state(&current_state, &pre_state, FALSE);
1481 release_device_state(&current_state);
1483 hr = ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
1484 ok(hr == D3D_OK, "ID3DXRenderToSurface::EndScene returned %#x, expected %#x\n", hr, D3D_OK);
1486 hr = retrieve_device_state(device, &current_state);
1487 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1488 compare_device_state(&current_state, &pre_state, TRUE);
1489 release_device_state(&current_state);
1491 check_release((IUnknown *)render, 0);
1494 hr = D3DXCreateRenderToSurface(device, 256, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, &render);
1495 if (SUCCEEDED(hr))
1497 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
1498 ok(hr == D3D_OK, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3D_OK);
1500 hr = retrieve_device_state(device, &current_state);
1501 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1502 compare_device_state(&current_state, &pre_state, FALSE);
1503 release_device_state(&current_state);
1505 hr = ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
1506 ok(hr == D3D_OK, "ID3DXRenderToSurface::EndScene returned %#x, expected %#x\n", hr, D3D_OK);
1508 hr = retrieve_device_state(device, &current_state);
1509 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1510 compare_device_state(&current_state, &pre_state, TRUE);
1511 release_device_state(&current_state);
1513 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
1514 ok(hr == D3D_OK, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3D_OK);
1516 hr = retrieve_device_state(device, &current_state);
1517 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1518 compare_device_state(&current_state, &pre_state, FALSE);
1519 release_device_state(&current_state);
1521 check_release((IUnknown *)render, 0);
1523 /* if EndScene isn't called, the device state isn't restored */
1524 hr = retrieve_device_state(device, &current_state);
1525 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1526 compare_device_state(&current_state, &pre_state, FALSE);
1527 release_device_state(&current_state);
1529 hr = apply_device_state(device, &pre_state);
1530 ok(SUCCEEDED(hr), "Failed to restore previous device state\n");
1532 IDirect3DDevice9_EndScene(device);
1535 release_device_state(&pre_state);
1537 cleanup:
1538 if (depth_stencil_surface)
1540 IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
1541 IDirect3DSurface9_Release(depth_stencil_surface);
1544 if (surface) check_release((IUnknown *)surface, 0);
1547 static void test_ID3DXRenderToSurface(IDirect3DDevice9 *device)
1549 int i;
1550 HRESULT hr;
1551 ULONG ref_count;
1552 IDirect3DDevice9 *out_device;
1553 ID3DXRenderToSurface *render;
1554 IDirect3DSurface9 *surface;
1555 D3DVIEWPORT9 viewport = { 0, 0, 256, 256, 0.0, 1.0 };
1556 D3DXRTS_DESC tests[] = {
1557 { 256, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN },
1558 { 256, 256, D3DFMT_A8R8G8B8, TRUE, D3DFMT_D24S8 },
1559 { 256, 256, D3DFMT_A8R8G8B8, TRUE, D3DFMT_D24X8 },
1560 { 512, 512, D3DFMT_X8R8G8B8, FALSE, D3DFMT_X8R8G8B8 },
1561 { 1024, 1024, D3DFMT_X8R8G8B8, TRUE, D3DFMT_D24S8 }
1564 hr = D3DXCreateRenderToSurface(device, 256, 256, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, &render);
1565 ok(hr == D3D_OK, "D3DXCreateRenderToSurface returned %#x, expected %#x\n", hr, D3D_OK);
1566 if (FAILED(hr)) return;
1568 hr = IDirect3DDevice9_CreateOffscreenPlainSurface(device, 256, 256, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &surface, NULL);
1569 if (SUCCEEDED(hr))
1571 ID3DXRenderToSurface *render_surface;
1573 /* GetDevice */
1574 hr = ID3DXRenderToSurface_GetDevice(render, NULL /* device */);
1575 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1577 ref_count = get_ref((IUnknown *)device);
1578 hr = ID3DXRenderToSurface_GetDevice(render, &out_device);
1579 ok(hr == D3D_OK, "ID3DXRenderToSurface::GetDevice returned %#x, expected %#x\n", hr, D3D_OK);
1580 check_release((IUnknown *)out_device, ref_count);
1582 /* BeginScene and EndScene */
1583 hr = ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
1584 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::EndScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1586 hr = ID3DXRenderToSurface_BeginScene(render, NULL /* surface */, &viewport);
1587 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1589 ref_count = get_ref((IUnknown *)surface);
1590 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
1591 ok(hr == D3D_OK, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3D_OK);
1592 if (SUCCEEDED(hr))
1594 check_ref((IUnknown *)surface, ref_count + 1);
1596 hr = ID3DXRenderToSurface_BeginScene(render, surface, NULL);
1597 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1599 hr = ID3DXRenderToSurface_EndScene(render, D3DX_FILTER_NONE);
1600 ok(hr == D3D_OK, "ID3DXRenderToSurface::EndScene returned %#x, expected %#x\n", hr, D3D_OK);
1602 check_ref((IUnknown *)surface, ref_count);
1605 /* error handling is deferred to BeginScene */
1606 hr = D3DXCreateRenderToSurface(device, 256, 256, D3DFMT_A8R8G8B8, TRUE, D3DFMT_UNKNOWN, &render_surface);
1607 ok(hr == D3D_OK, "D3DXCreateRenderToSurface returned %#x, expected %#x\n", hr, D3D_OK);
1608 hr = ID3DXRenderToSurface_BeginScene(render_surface, surface, NULL);
1609 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToSurface::BeginScene returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1610 check_release((IUnknown *)render_surface, 0);
1612 check_release((IUnknown *)surface, 0);
1614 else skip("Failed to create surface\n");
1616 check_release((IUnknown *)render, 0);
1618 for (i = 0; i < ARRAY_SIZE(tests); i++)
1620 check_ID3DXRenderToSurface(device, tests[i].Width, tests[i].Height, tests[i].Format, tests[i].DepthStencil, tests[i].DepthStencilFormat, TRUE);
1621 check_ID3DXRenderToSurface(device, tests[i].Width, tests[i].Height, tests[i].Format, tests[i].DepthStencil, tests[i].DepthStencilFormat, FALSE);
1624 test_ID3DXRenderToSurface_device_state(device);
1627 static void test_D3DXCreateRenderToEnvMap(IDirect3DDevice9 *device)
1629 int i;
1630 HRESULT hr;
1631 ULONG ref_count;
1632 D3DXRTE_DESC desc;
1633 ID3DXRenderToEnvMap *render;
1634 static const struct {
1635 D3DXRTE_DESC parameters;
1636 D3DXRTE_DESC expected_values;
1637 } tests[] = {
1638 { { 0, 0, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN }, { 1, 1, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN } },
1639 { { 256, 0, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN }, { 256, 9, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN } },
1640 { { 256, 4, D3DFMT_A8R8G8B8, FALSE, D3DFMT_D24S8 }, { 256, 4, D3DFMT_A8R8G8B8, FALSE, D3DFMT_D24S8 } },
1641 { { 256, 256, D3DFMT_UNKNOWN, FALSE, D3DFMT_R8G8B8 }, { 256, 9, D3DFMT_A8R8G8B8, FALSE, D3DFMT_R8G8B8 } },
1642 { { -1, -1, D3DFMT_A8R8G8B8, TRUE, D3DFMT_DXT1 }, { 256, 9, D3DFMT_A8R8G8B8, TRUE, D3DFMT_DXT1 } },
1643 { { 256, 1, D3DFMT_X8R8G8B8, TRUE, D3DFMT_UNKNOWN }, { 256, 1, D3DFMT_X8R8G8B8, TRUE, D3DFMT_UNKNOWN } }
1646 for (i = 0; i < ARRAY_SIZE(tests); i++)
1648 const D3DXRTE_DESC *parameters = &tests[i].parameters;
1649 const D3DXRTE_DESC *expected = &tests[i].expected_values;
1650 hr = D3DXCreateRenderToEnvMap(device, parameters->Size, parameters->MipLevels, parameters->Format,
1651 parameters->DepthStencil, parameters->DepthStencilFormat, &render);
1652 ok(hr == D3D_OK, "%d: D3DXCreateRenderToEnvMap returned %#x, expected %#x\n", i, hr, D3D_OK);
1653 if (SUCCEEDED(hr))
1655 hr = ID3DXRenderToEnvMap_GetDesc(render, &desc);
1656 ok(hr == D3D_OK, "%d: GetDesc failed %#x\n", i, hr);
1657 if (SUCCEEDED(hr))
1659 ok(desc.Size == expected->Size, "%d: Got size %u, expected %u\n", i, desc.Size, expected->Size);
1660 ok(desc.MipLevels == expected->MipLevels, "%d: Got miplevels %u, expected %u\n", i, desc.MipLevels, expected->MipLevels);
1661 ok(desc.Format == expected->Format, "%d: Got format %#x, expected %#x\n", i, desc.Format, expected->Format);
1662 ok(desc.DepthStencil == expected->DepthStencil, "%d: Got depth stencil %d, expected %d\n",
1663 i, expected->DepthStencil, expected->DepthStencil);
1664 ok(desc.DepthStencilFormat == expected->DepthStencilFormat, "%d: Got depth stencil format %#x, expected %#x\n",
1665 i, expected->DepthStencilFormat, expected->DepthStencilFormat);
1667 check_release((IUnknown *)render, 0);
1671 /* check device ref count */
1672 ref_count = get_ref((IUnknown *)device);
1673 hr = D3DXCreateRenderToEnvMap(device, 0, 0, D3DFMT_UNKNOWN, FALSE, D3DFMT_UNKNOWN, &render);
1674 check_ref((IUnknown *)device, ref_count + 1);
1675 if (SUCCEEDED(hr)) ID3DXRenderToEnvMap_Release(render);
1678 static void test_ID3DXRenderToEnvMap_cube_map(IDirect3DDevice9 *device)
1680 HRESULT hr;
1681 IDirect3DCubeTexture9 *cube_texture = NULL;
1682 ID3DXRenderToEnvMap *render = NULL;
1683 struct device_state pre_state;
1684 struct device_state current_state;
1686 hr = IDirect3DDevice9_CreateCubeTexture(device, 256, 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT,
1687 &cube_texture, NULL);
1688 if (FAILED(hr))
1690 skip("Failed to create cube texture\n");
1691 return;
1694 hr = retrieve_device_state(device, &pre_state);
1695 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1697 hr = D3DXCreateRenderToEnvMap(device, 256, 0, D3DFMT_A8R8G8B8, TRUE, D3DFMT_D24X8, &render);
1698 ok(hr == D3D_OK, "D3DCreateRenderToEnvMap returned %#x, expected %#x\n", hr, D3D_OK);
1699 if (SUCCEEDED(hr))
1701 DWORD face;
1703 hr = ID3DXRenderToEnvMap_End(render, D3DX_FILTER_NONE);
1704 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::End returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1706 hr = ID3DXRenderToEnvMap_BeginCube(render, cube_texture);
1707 ok(hr == D3D_OK, "ID3DXRenderToEnvMap::BeginCube returned %#x, expected %#x\n", hr, D3D_OK);
1709 hr = retrieve_device_state(device, &current_state);
1710 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1711 compare_device_state(&current_state, &pre_state, TRUE);
1712 release_device_state(&current_state);
1714 for (face = D3DCUBEMAP_FACE_POSITIVE_X; face <= D3DCUBEMAP_FACE_NEGATIVE_Z; face++)
1716 hr = ID3DXRenderToEnvMap_Face(render, face, D3DX_FILTER_POINT);
1717 ok(hr == D3D_OK, "ID3DXRenderToEnvMap::Face returned %#x, expected %#x\n", hr, D3D_OK);
1719 hr = retrieve_device_state(device, &current_state);
1720 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1721 compare_device_state(&current_state, &pre_state, FALSE);
1722 release_device_state(&current_state);
1725 hr = ID3DXRenderToEnvMap_End(render, D3DX_FILTER_POINT);
1726 ok(hr == D3D_OK, "ID3DXRenderToEnvMap::End returned %#x, expected %#x\n", hr, D3D_OK);
1728 hr = retrieve_device_state(device, &current_state);
1729 ok(SUCCEEDED(hr), "Failed to retrieve device state\n");
1730 compare_device_state(&current_state, &pre_state, TRUE);
1731 release_device_state(&current_state);
1733 check_release((IUnknown *)render, 0);
1736 release_device_state(&pre_state);
1738 check_release((IUnknown *)cube_texture, 0);
1741 static void test_ID3DXRenderToEnvMap(IDirect3DDevice9 *device)
1743 HRESULT hr;
1744 ID3DXRenderToEnvMap *render;
1745 IDirect3DSurface9 *depth_stencil_surface;
1747 hr = D3DXCreateRenderToEnvMap(device, 256, 0, D3DFMT_A8R8G8B8, FALSE, D3DFMT_UNKNOWN, &render);
1748 if (SUCCEEDED(hr))
1750 ULONG ref_count;
1751 IDirect3DDevice9 *out_device;
1753 hr = ID3DXRenderToEnvMap_GetDesc(render, NULL);
1754 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::GetDesc returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1756 hr = ID3DXRenderToEnvMap_GetDevice(render, NULL);
1757 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::GetDevice returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1759 ref_count = get_ref((IUnknown *)device);
1760 hr = ID3DXRenderToEnvMap_GetDevice(render, &out_device);
1761 ok(hr == D3D_OK, "ID3DXRenderToEnvMap::GetDevice returned %#x, expected %#x\n", hr, D3D_OK);
1762 ok(out_device == device, "ID3DXRenderToEnvMap::GetDevice returned different device\n");
1763 check_release((IUnknown *)device, ref_count);
1765 hr = ID3DXRenderToEnvMap_End(render, D3DX_FILTER_NONE);
1766 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::End returned %#x, expected %#x\n", hr, D3D_OK);
1768 hr = ID3DXRenderToEnvMap_BeginCube(render, NULL);
1769 ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::BeginCube returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1771 hr = ID3DXRenderToEnvMap_BeginHemisphere(render, NULL, NULL);
1772 todo_wine ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::BeginHemisphere returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1774 hr = ID3DXRenderToEnvMap_BeginParabolic(render, NULL, NULL);
1775 todo_wine ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::BeginParabolic returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1777 hr = ID3DXRenderToEnvMap_BeginSphere(render, NULL);
1778 todo_wine ok(hr == D3DERR_INVALIDCALL, "ID3DXRenderToEnvMap::BeginSphere returned %#x, expected %#x\n", hr, D3DERR_INVALIDCALL);
1780 check_release((IUnknown *)render, 0);
1781 } else skip("Failed to create ID3DXRenderToEnvMap\n");
1783 /* make sure there is a depth stencil surface present */
1784 hr = IDirect3DDevice9_GetDepthStencilSurface(device, &depth_stencil_surface);
1785 if (SUCCEEDED(hr))
1787 IDirect3DSurface9_Release(depth_stencil_surface);
1788 depth_stencil_surface = NULL;
1790 else if (hr == D3DERR_NOTFOUND)
1792 hr = IDirect3DDevice9_CreateDepthStencilSurface(device, 256, 256, D3DFMT_D24X8,
1793 D3DMULTISAMPLE_NONE, 0, TRUE, &depth_stencil_surface, NULL);
1794 if (SUCCEEDED(hr)) IDirect3DDevice9_SetDepthStencilSurface(device, depth_stencil_surface);
1797 if (FAILED(hr))
1799 skip("Failed to create depth stencil surface\n");
1800 return;
1803 test_ID3DXRenderToEnvMap_cube_map(device);
1805 if (depth_stencil_surface)
1807 IDirect3DDevice9_SetDepthStencilSurface(device, NULL);
1808 IDirect3DSurface9_Release(depth_stencil_surface);
1812 START_TEST(core)
1814 HWND wnd;
1815 IDirect3D9 *d3d;
1816 IDirect3DDevice9 *device;
1817 D3DPRESENT_PARAMETERS d3dpp;
1818 HRESULT hr;
1820 if (!(wnd = CreateWindowA("static", "d3dx9_test", WS_OVERLAPPEDWINDOW, 0, 0,
1821 640, 480, NULL, NULL, NULL, NULL)))
1823 skip("Couldn't create application window\n");
1824 return;
1826 if (!(d3d = Direct3DCreate9(D3D_SDK_VERSION)))
1828 skip("Couldn't create IDirect3D9 object\n");
1829 DestroyWindow(wnd);
1830 return;
1833 ZeroMemory(&d3dpp, sizeof(d3dpp));
1834 d3dpp.Windowed = TRUE;
1835 d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD;
1836 hr = IDirect3D9_CreateDevice(d3d, D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, wnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &d3dpp, &device);
1837 if(FAILED(hr)) {
1838 skip("Failed to create IDirect3DDevice9 object %#x\n", hr);
1839 IDirect3D9_Release(d3d);
1840 DestroyWindow(wnd);
1841 return;
1844 test_ID3DXBuffer();
1845 test_ID3DXSprite(device);
1846 test_ID3DXFont(device);
1847 test_D3DXCreateRenderToSurface(device);
1848 test_ID3DXRenderToSurface(device);
1849 test_D3DXCreateRenderToEnvMap(device);
1850 test_ID3DXRenderToEnvMap(device);
1852 check_release((IUnknown*)device, 0);
1853 check_release((IUnknown*)d3d, 0);
1854 if (wnd) DestroyWindow(wnd);