2 * Copyright 2005 Antoine Chavasse (a.chavasse@gmail.com)
3 * Copyright 2008, 2011, 2012-2013 Stefan Dösinger for CodeWeavers
4 * Copyright 2011-2014 Henri Verbeet for CodeWeavers
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
22 #include "wine/test.h"
26 static BOOL is_ddraw64
= sizeof(DWORD
) != sizeof(DWORD
*);
27 static DEVMODEW registry_mode
;
29 static HRESULT (WINAPI
*pDwmIsCompositionEnabled
)(BOOL
*);
32 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
40 struct create_window_thread_param
43 HANDLE window_created
;
44 HANDLE destroy_window
;
48 static BOOL
compare_color(D3DCOLOR c1
, D3DCOLOR c2
, BYTE max_diff
)
50 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
52 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
54 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
56 if (abs((c1
& 0xff) - (c2
& 0xff)) > max_diff
) return FALSE
;
60 static BOOL
compare_float(float f
, float g
, unsigned int ulps
)
70 if (abs(x
- y
) > ulps
)
76 static BOOL
compare_vec4(const struct vec4
*vec
, float x
, float y
, float z
, float w
, unsigned int ulps
)
78 return compare_float(vec
->x
, x
, ulps
)
79 && compare_float(vec
->y
, y
, ulps
)
80 && compare_float(vec
->z
, z
, ulps
)
81 && compare_float(vec
->w
, w
, ulps
);
84 static IDirectDrawSurface
*create_overlay(IDirectDraw
*ddraw
,
85 unsigned int width
, unsigned int height
, DWORD format
)
87 IDirectDrawSurface
*surface
;
90 memset(&desc
, 0, sizeof(desc
));
91 desc
.dwSize
= sizeof(desc
);
92 desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
94 desc
.dwHeight
= height
;
95 desc
.ddsCaps
.dwCaps
= DDSCAPS_OVERLAY
;
96 desc
.ddpfPixelFormat
.dwSize
= sizeof(desc
.ddpfPixelFormat
);
97 desc
.ddpfPixelFormat
.dwFlags
= DDPF_FOURCC
;
98 desc
.ddpfPixelFormat
.dwFourCC
= format
;
100 if (FAILED(IDirectDraw_CreateSurface(ddraw
, &desc
, &surface
, NULL
)))
105 static DWORD WINAPI
create_window_thread_proc(void *param
)
107 struct create_window_thread_param
*p
= param
;
111 p
->window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
112 0, 0, 640, 480, 0, 0, 0, 0);
113 ret
= SetEvent(p
->window_created
);
114 ok(ret
, "SetEvent failed, last error %#x.\n", GetLastError());
120 while (PeekMessageA(&msg
, 0, 0, 0, PM_REMOVE
))
121 DispatchMessageA(&msg
);
122 res
= WaitForSingleObject(p
->destroy_window
, 100);
123 if (res
== WAIT_OBJECT_0
)
125 if (res
!= WAIT_TIMEOUT
)
127 ok(0, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
132 DestroyWindow(p
->window
);
137 static void create_window_thread(struct create_window_thread_param
*p
)
141 p
->window_created
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
142 ok(!!p
->window_created
, "CreateEvent failed, last error %#x.\n", GetLastError());
143 p
->destroy_window
= CreateEventA(NULL
, FALSE
, FALSE
, NULL
);
144 ok(!!p
->destroy_window
, "CreateEvent failed, last error %#x.\n", GetLastError());
145 p
->thread
= CreateThread(NULL
, 0, create_window_thread_proc
, p
, 0, &tid
);
146 ok(!!p
->thread
, "Failed to create thread, last error %#x.\n", GetLastError());
147 res
= WaitForSingleObject(p
->window_created
, INFINITE
);
148 ok(res
== WAIT_OBJECT_0
, "Wait failed (%#x), last error %#x.\n", res
, GetLastError());
151 static void destroy_window_thread(struct create_window_thread_param
*p
)
153 SetEvent(p
->destroy_window
);
154 WaitForSingleObject(p
->thread
, INFINITE
);
155 CloseHandle(p
->destroy_window
);
156 CloseHandle(p
->window_created
);
157 CloseHandle(p
->thread
);
160 static HRESULT
set_display_mode(IDirectDraw
*ddraw
, DWORD width
, DWORD height
)
162 if (SUCCEEDED(IDirectDraw_SetDisplayMode(ddraw
, width
, height
, 32)))
164 return IDirectDraw_SetDisplayMode(ddraw
, width
, height
, 24);
167 static D3DCOLOR
get_surface_color(IDirectDrawSurface
*surface
, UINT x
, UINT y
)
169 RECT rect
= {x
, y
, x
+ 1, y
+ 1};
170 DDSURFACEDESC surface_desc
;
174 memset(&surface_desc
, 0, sizeof(surface_desc
));
175 surface_desc
.dwSize
= sizeof(surface_desc
);
177 hr
= IDirectDrawSurface_Lock(surface
, &rect
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
178 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
182 color
= *((DWORD
*)surface_desc
.lpSurface
) & 0x00ffffff;
184 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
185 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
190 static void emit_process_vertices(void **ptr
, DWORD flags
, WORD base_idx
, DWORD vertex_count
)
192 D3DINSTRUCTION
*inst
= *ptr
;
193 D3DPROCESSVERTICES
*pv
= (D3DPROCESSVERTICES
*)(inst
+ 1);
195 inst
->bOpcode
= D3DOP_PROCESSVERTICES
;
196 inst
->bSize
= sizeof(*pv
);
200 pv
->wStart
= base_idx
;
202 pv
->dwCount
= vertex_count
;
208 static void emit_set_ts(void **ptr
, D3DTRANSFORMSTATETYPE state
, DWORD value
)
210 D3DINSTRUCTION
*inst
= *ptr
;
211 D3DSTATE
*ts
= (D3DSTATE
*)(inst
+ 1);
213 inst
->bOpcode
= D3DOP_STATETRANSFORM
;
214 inst
->bSize
= sizeof(*ts
);
217 U1(*ts
).dtstTransformStateType
= state
;
218 U2(*ts
).dwArg
[0] = value
;
223 static void emit_set_ls(void **ptr
, D3DLIGHTSTATETYPE state
, DWORD value
)
225 D3DINSTRUCTION
*inst
= *ptr
;
226 D3DSTATE
*ls
= (D3DSTATE
*)(inst
+ 1);
228 inst
->bOpcode
= D3DOP_STATELIGHT
;
229 inst
->bSize
= sizeof(*ls
);
232 U1(*ls
).dlstLightStateType
= state
;
233 U2(*ls
).dwArg
[0] = value
;
238 static void emit_set_rs(void **ptr
, D3DRENDERSTATETYPE state
, DWORD value
)
240 D3DINSTRUCTION
*inst
= *ptr
;
241 D3DSTATE
*rs
= (D3DSTATE
*)(inst
+ 1);
243 inst
->bOpcode
= D3DOP_STATERENDER
;
244 inst
->bSize
= sizeof(*rs
);
247 U1(*rs
).drstRenderStateType
= state
;
248 U2(*rs
).dwArg
[0] = value
;
253 static void emit_tquad(void **ptr
, WORD base_idx
)
255 D3DINSTRUCTION
*inst
= *ptr
;
256 D3DTRIANGLE
*tri
= (D3DTRIANGLE
*)(inst
+ 1);
258 inst
->bOpcode
= D3DOP_TRIANGLE
;
259 inst
->bSize
= sizeof(*tri
);
262 U1(*tri
).v1
= base_idx
;
263 U2(*tri
).v2
= base_idx
+ 1;
264 U3(*tri
).v3
= base_idx
+ 2;
265 tri
->wFlags
= D3DTRIFLAG_START
;
268 U1(*tri
).v1
= base_idx
+ 2;
269 U2(*tri
).v2
= base_idx
+ 1;
270 U3(*tri
).v3
= base_idx
+ 3;
271 tri
->wFlags
= D3DTRIFLAG_ODD
;
277 static void emit_tquad_tlist(void **ptr
, WORD base_idx
)
279 D3DINSTRUCTION
*inst
= *ptr
;
280 D3DTRIANGLE
*tri
= (D3DTRIANGLE
*)(inst
+ 1);
282 inst
->bOpcode
= D3DOP_TRIANGLE
;
283 inst
->bSize
= sizeof(*tri
);
286 U1(*tri
).v1
= base_idx
;
287 U2(*tri
).v2
= base_idx
+ 1;
288 U3(*tri
).v3
= base_idx
+ 2;
289 tri
->wFlags
= D3DTRIFLAG_START
;
292 U1(*tri
).v1
= base_idx
+ 2;
293 U2(*tri
).v2
= base_idx
+ 3;
294 U3(*tri
).v3
= base_idx
;
295 tri
->wFlags
= D3DTRIFLAG_START
;
301 static void emit_end(void **ptr
)
303 D3DINSTRUCTION
*inst
= *ptr
;
305 inst
->bOpcode
= D3DOP_EXIT
;
312 static void set_execute_data(IDirect3DExecuteBuffer
*execute_buffer
, UINT vertex_count
, UINT offset
, UINT len
)
314 D3DEXECUTEDATA exec_data
;
317 memset(&exec_data
, 0, sizeof(exec_data
));
318 exec_data
.dwSize
= sizeof(exec_data
);
319 exec_data
.dwVertexCount
= vertex_count
;
320 exec_data
.dwInstructionOffset
= offset
;
321 exec_data
.dwInstructionLength
= len
;
322 hr
= IDirect3DExecuteBuffer_SetExecuteData(execute_buffer
, &exec_data
);
323 ok(SUCCEEDED(hr
), "Failed to set execute data, hr %#x.\n", hr
);
326 static DWORD
get_device_z_depth(IDirect3DDevice
*device
)
328 DDSCAPS caps
= {DDSCAPS_ZBUFFER
};
329 IDirectDrawSurface
*ds
, *rt
;
333 if (FAILED(IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
)))
336 hr
= IDirectDrawSurface_GetAttachedSurface(rt
, &caps
, &ds
);
337 IDirectDrawSurface_Release(rt
);
341 desc
.dwSize
= sizeof(desc
);
342 hr
= IDirectDrawSurface_GetSurfaceDesc(ds
, &desc
);
343 IDirectDrawSurface_Release(ds
);
347 return U2(desc
).dwZBufferBitDepth
;
350 static IDirectDraw
*create_ddraw(void)
354 if (FAILED(DirectDrawCreate(NULL
, &ddraw
, NULL
)))
360 static IDirect3DDevice
*create_device(IDirectDraw
*ddraw
, HWND window
, DWORD coop_level
)
362 static const DWORD z_depths
[] = {32, 24, 16};
363 IDirectDrawSurface
*surface
, *ds
;
364 IDirect3DDevice
*device
= NULL
;
365 DDSURFACEDESC surface_desc
;
369 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, coop_level
);
370 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
372 memset(&surface_desc
, 0, sizeof(surface_desc
));
373 surface_desc
.dwSize
= sizeof(surface_desc
);
374 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
375 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
376 surface_desc
.dwWidth
= 640;
377 surface_desc
.dwHeight
= 480;
379 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
380 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
382 if (coop_level
& DDSCL_NORMAL
)
384 IDirectDrawClipper
*clipper
;
386 hr
= IDirectDraw_CreateClipper(ddraw
, 0, &clipper
, NULL
);
387 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
388 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
389 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
390 hr
= IDirectDrawSurface_SetClipper(surface
, clipper
);
391 ok(SUCCEEDED(hr
), "Failed to set surface clipper, hr %#x.\n", hr
);
392 IDirectDrawClipper_Release(clipper
);
395 /* We used to use EnumDevices() for this, but it seems
396 * D3DDEVICEDESC.dwDeviceZBufferBitDepth only has a very casual
397 * relationship with reality. */
398 for (i
= 0; i
< sizeof(z_depths
) / sizeof(*z_depths
); ++i
)
400 memset(&surface_desc
, 0, sizeof(surface_desc
));
401 surface_desc
.dwSize
= sizeof(surface_desc
);
402 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
403 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
404 U2(surface_desc
).dwZBufferBitDepth
= z_depths
[i
];
405 surface_desc
.dwWidth
= 640;
406 surface_desc
.dwHeight
= 480;
407 if (FAILED(IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
)))
410 hr
= IDirectDrawSurface_AddAttachedSurface(surface
, ds
);
411 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
412 IDirectDrawSurface_Release(ds
);
416 if (SUCCEEDED(IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DHALDevice
, (void **)&device
)))
419 IDirectDrawSurface_DeleteAttachedSurface(surface
, 0, ds
);
422 IDirectDrawSurface_Release(surface
);
426 static IDirect3DViewport
*create_viewport(IDirect3DDevice
*device
, UINT x
, UINT y
, UINT w
, UINT h
)
428 IDirect3DViewport
*viewport
;
433 hr
= IDirect3DDevice_GetDirect3D(device
, &d3d
);
434 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
435 hr
= IDirect3D_CreateViewport(d3d
, &viewport
, NULL
);
436 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
437 hr
= IDirect3DDevice_AddViewport(device
, viewport
);
438 ok(SUCCEEDED(hr
), "Failed to add viewport, hr %#x.\n", hr
);
439 memset(&vp
, 0, sizeof(vp
));
440 vp
.dwSize
= sizeof(vp
);
445 vp
.dvScaleX
= (float)w
/ 2.0f
;
446 vp
.dvScaleY
= (float)h
/ 2.0f
;
451 hr
= IDirect3DViewport_SetViewport(viewport
, &vp
);
452 ok(SUCCEEDED(hr
), "Failed to set viewport data, hr %#x.\n", hr
);
453 IDirect3D_Release(d3d
);
458 static void viewport_set_background(IDirect3DDevice
*device
, IDirect3DViewport
*viewport
,
459 IDirect3DMaterial
*material
)
461 D3DMATERIALHANDLE material_handle
;
464 hr
= IDirect3DMaterial2_GetHandle(material
, device
, &material_handle
);
465 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
466 hr
= IDirect3DViewport2_SetBackground(viewport
, material_handle
);
467 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
470 static void destroy_viewport(IDirect3DDevice
*device
, IDirect3DViewport
*viewport
)
474 hr
= IDirect3DDevice_DeleteViewport(device
, viewport
);
475 ok(SUCCEEDED(hr
), "Failed to delete viewport, hr %#x.\n", hr
);
476 IDirect3DViewport_Release(viewport
);
479 static IDirect3DMaterial
*create_material(IDirect3DDevice
*device
, D3DMATERIAL
*mat
)
481 IDirect3DMaterial
*material
;
485 hr
= IDirect3DDevice_GetDirect3D(device
, &d3d
);
486 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
487 hr
= IDirect3D_CreateMaterial(d3d
, &material
, NULL
);
488 ok(SUCCEEDED(hr
), "Failed to create material, hr %#x.\n", hr
);
489 hr
= IDirect3DMaterial_SetMaterial(material
, mat
);
490 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
491 IDirect3D_Release(d3d
);
496 static IDirect3DMaterial
*create_diffuse_material(IDirect3DDevice
*device
, float r
, float g
, float b
, float a
)
500 memset(&mat
, 0, sizeof(mat
));
501 mat
.dwSize
= sizeof(mat
);
502 U1(U(mat
).diffuse
).r
= r
;
503 U2(U(mat
).diffuse
).g
= g
;
504 U3(U(mat
).diffuse
).b
= b
;
505 U4(U(mat
).diffuse
).a
= a
;
507 return create_material(device
, &mat
);
510 static IDirect3DMaterial
*create_emissive_material(IDirect3DDevice
*device
, float r
, float g
, float b
, float a
)
514 memset(&mat
, 0, sizeof(mat
));
515 mat
.dwSize
= sizeof(mat
);
516 U1(U3(mat
).emissive
).r
= r
;
517 U2(U3(mat
).emissive
).g
= g
;
518 U3(U3(mat
).emissive
).b
= b
;
519 U4(U3(mat
).emissive
).a
= a
;
521 return create_material(device
, &mat
);
524 static void destroy_material(IDirect3DMaterial
*material
)
526 IDirect3DMaterial_Release(material
);
533 WPARAM expect_wparam
;
536 static const struct message
*expect_messages
;
538 static LRESULT CALLBACK
test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
540 if (expect_messages
&& message
== expect_messages
->message
)
542 if (expect_messages
->check_wparam
)
543 ok (wparam
== expect_messages
->expect_wparam
,
544 "Got unexpected wparam %lx for message %x, expected %lx.\n",
545 wparam
, message
, expect_messages
->expect_wparam
);
550 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
553 /* Set the wndproc back to what ddraw expects it to be, and release the ddraw
554 * interface. This prevents subsequent SetCooperativeLevel() calls on a
555 * different window from failing with DDERR_HWNDALREADYSET. */
556 static void fix_wndproc(HWND window
, LONG_PTR proc
)
561 if (!(ddraw
= create_ddraw()))
564 SetWindowLongPtrA(window
, GWLP_WNDPROC
, proc
);
565 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
566 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
567 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
568 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
570 IDirectDraw_Release(ddraw
);
573 static HRESULT CALLBACK
restore_callback(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
575 HRESULT hr
= IDirectDrawSurface_Restore(surface
);
576 ok(SUCCEEDED(hr
) || hr
== DDERR_IMPLICITLYCREATED
, "Failed to restore surface, hr %#x.\n", hr
);
577 IDirectDrawSurface_Release(surface
);
582 static HRESULT
restore_surfaces(IDirectDraw
*ddraw
)
584 return IDirectDraw_EnumSurfaces(ddraw
, DDENUMSURFACES_ALL
| DDENUMSURFACES_DOESEXIST
,
585 NULL
, NULL
, restore_callback
);
588 static void test_coop_level_create_device_window(void)
590 HWND focus_window
, device_window
;
594 focus_window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
595 0, 0, 640, 480, 0, 0, 0, 0);
596 ddraw
= create_ddraw();
597 ok(!!ddraw
, "Failed to create a ddraw object.\n");
599 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
600 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
601 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
602 ok(!device_window
, "Unexpected device window found.\n");
603 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
);
604 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
605 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
606 ok(!device_window
, "Unexpected device window found.\n");
607 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
);
608 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
609 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
610 ok(!device_window
, "Unexpected device window found.\n");
611 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
612 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
613 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
614 ok(!device_window
, "Unexpected device window found.\n");
615 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
616 ok(hr
== DDERR_NOFOCUSWINDOW
|| broken(hr
== DDERR_INVALIDPARAMS
), "Got unexpected hr %#x.\n", hr
);
617 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
618 ok(!device_window
, "Unexpected device window found.\n");
620 /* Windows versions before 98 / NT5 don't support DDSCL_CREATEDEVICEWINDOW. */
621 if (broken(hr
== DDERR_INVALIDPARAMS
))
623 win_skip("DDSCL_CREATEDEVICEWINDOW not supported, skipping test.\n");
624 IDirectDraw_Release(ddraw
);
625 DestroyWindow(focus_window
);
629 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
630 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
631 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
632 ok(!device_window
, "Unexpected device window found.\n");
633 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
634 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
635 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
636 ok(!device_window
, "Unexpected device window found.\n");
638 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
639 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
640 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
641 ok(!device_window
, "Unexpected device window found.\n");
642 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_SETFOCUSWINDOW
643 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
644 ok(hr
== DDERR_NOHWND
, "Got unexpected hr %#x.\n", hr
);
645 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
646 ok(!!device_window
, "Device window not found.\n");
648 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
649 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
650 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
651 ok(!device_window
, "Unexpected device window found.\n");
652 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
653 | DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
654 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
655 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
656 ok(!!device_window
, "Device window not found.\n");
658 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
659 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
660 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
661 ok(!device_window
, "Unexpected device window found.\n");
662 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
663 ok(hr
== DDERR_NOFOCUSWINDOW
, "Got unexpected hr %#x.\n", hr
);
664 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
665 ok(!device_window
, "Unexpected device window found.\n");
666 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, focus_window
, DDSCL_SETFOCUSWINDOW
);
667 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
668 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
669 ok(!device_window
, "Unexpected device window found.\n");
670 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_CREATEDEVICEWINDOW
| DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
671 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
672 device_window
= FindWindowA("DirectDrawDeviceWnd", "DirectDrawDeviceWnd");
673 ok(!!device_window
, "Device window not found.\n");
675 IDirectDraw_Release(ddraw
);
676 DestroyWindow(focus_window
);
679 static void test_clipper_blt(void)
681 IDirectDrawSurface
*src_surface
, *dst_surface
;
682 RECT client_rect
, src_rect
;
683 IDirectDrawClipper
*clipper
;
684 DDSURFACEDESC surface_desc
;
685 unsigned int i
, j
, x
, y
;
697 static const DWORD src_data
[] =
699 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
700 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
701 0xff0000ff, 0xff0000ff, 0xff00ff00, 0xffff0000, 0xffffffff, 0xffffffff,
703 static const D3DCOLOR expected1
[] =
705 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
706 0x000000ff, 0x0000ff00, 0x00000000, 0x00000000,
707 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
708 0x00000000, 0x00000000, 0x00ff0000, 0x00ffffff,
710 /* Nvidia on Windows seems to have an off-by-one error
711 * when processing source rectangles. Our left = 1 and
712 * right = 5 input reads from x = {1, 2, 3}. x = 4 is
713 * read as well, but only for the edge pixels on the
714 * output image. The bug happens on the y axis as well,
715 * but we only read one row there, and all source rows
716 * contain the same data. This bug is not dependent on
717 * the presence of a clipper. */
718 static const D3DCOLOR expected1_broken
[] =
720 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
721 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
722 0x00000000, 0x00000000, 0x00ff0000, 0x00ff0000,
723 0x00000000, 0x00000000, 0x0000ff00, 0x00ff0000,
725 static const D3DCOLOR expected2
[] =
727 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
728 0x000000ff, 0x000000ff, 0x00000000, 0x00000000,
729 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
730 0x00000000, 0x00000000, 0x000000ff, 0x000000ff,
733 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
734 10, 10, 640, 480, 0, 0, 0, 0);
735 ShowWindow(window
, SW_SHOW
);
736 ddraw
= create_ddraw();
737 ok(!!ddraw
, "Failed to create a ddraw object.\n");
739 ret
= GetClientRect(window
, &client_rect
);
740 ok(ret
, "Failed to get client rect.\n");
741 ret
= MapWindowPoints(window
, NULL
, (POINT
*)&client_rect
, 2);
742 ok(ret
, "Failed to map client rect.\n");
744 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
745 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
747 hr
= IDirectDraw_CreateClipper(ddraw
, 0, &clipper
, NULL
);
748 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
749 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
750 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
751 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
752 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
753 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
754 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
755 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
756 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, rgn_data
, &ret
);
757 ok(SUCCEEDED(hr
), "Failed to get clip list, hr %#x.\n", hr
);
758 ok(rgn_data
->rdh
.dwSize
== sizeof(rgn_data
->rdh
), "Got unexpected structure size %#x.\n", rgn_data
->rdh
.dwSize
);
759 ok(rgn_data
->rdh
.iType
== RDH_RECTANGLES
, "Got unexpected type %#x.\n", rgn_data
->rdh
.iType
);
760 ok(rgn_data
->rdh
.nCount
>= 1, "Got unexpected count %u.\n", rgn_data
->rdh
.nCount
);
761 ok(EqualRect(&rgn_data
->rdh
.rcBound
, &client_rect
),
762 "Got unexpected bounding rect %s, expected %s.\n",
763 wine_dbgstr_rect(&rgn_data
->rdh
.rcBound
), wine_dbgstr_rect(&client_rect
));
764 HeapFree(GetProcessHeap(), 0, rgn_data
);
766 r1
= CreateRectRgn(0, 0, 320, 240);
767 ok(!!r1
, "Failed to create region.\n");
768 r2
= CreateRectRgn(320, 240, 640, 480);
769 ok(!!r2
, "Failed to create region.\n");
770 CombineRgn(r1
, r1
, r2
, RGN_OR
);
771 ret
= GetRegionData(r1
, 0, NULL
);
772 rgn_data
= HeapAlloc(GetProcessHeap(), 0, ret
);
773 ret
= GetRegionData(r1
, ret
, rgn_data
);
774 ok(!!ret
, "Failed to get region data.\n");
779 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
780 ok(hr
== DDERR_CLIPPERISUSINGHWND
, "Got unexpected hr %#x.\n", hr
);
781 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
782 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
783 hr
= IDirectDrawClipper_SetClipList(clipper
, rgn_data
, 0);
784 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
786 HeapFree(GetProcessHeap(), 0, rgn_data
);
788 memset(&surface_desc
, 0, sizeof(surface_desc
));
789 surface_desc
.dwSize
= sizeof(surface_desc
);
790 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
791 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
792 surface_desc
.dwWidth
= 640;
793 surface_desc
.dwHeight
= 480;
794 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
795 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
796 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
797 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
798 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
799 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
801 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &src_surface
, NULL
);
802 ok(SUCCEEDED(hr
), "Failed to create source surface, hr %#x.\n", hr
);
803 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &dst_surface
, NULL
);
804 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
806 memset(&fx
, 0, sizeof(fx
));
807 fx
.dwSize
= sizeof(fx
);
808 hr
= IDirectDrawSurface_Blt(src_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
809 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
810 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
811 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
813 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
814 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
815 ok(U1(surface_desc
).lPitch
== 2560, "Got unexpected surface pitch %u.\n", U1(surface_desc
).lPitch
);
816 ptr
= surface_desc
.lpSurface
;
817 memcpy(&ptr
[ 0], &src_data
[ 0], 6 * sizeof(DWORD
));
818 memcpy(&ptr
[ 640], &src_data
[ 6], 6 * sizeof(DWORD
));
819 memcpy(&ptr
[1280], &src_data
[12], 6 * sizeof(DWORD
));
820 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
821 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
823 hr
= IDirectDrawSurface_SetClipper(dst_surface
, clipper
);
824 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
826 SetRect(&src_rect
, 1, 1, 5, 2);
827 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, &src_rect
, DDBLT_WAIT
, NULL
);
828 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
829 for (i
= 0; i
< 4; ++i
)
831 for (j
= 0; j
< 4; ++j
)
833 x
= 80 * ((2 * j
) + 1);
834 y
= 60 * ((2 * i
) + 1);
835 color
= get_surface_color(dst_surface
, x
, y
);
836 ok(compare_color(color
, expected1
[i
* 4 + j
], 1)
837 || broken(compare_color(color
, expected1_broken
[i
* 4 + j
], 1)),
838 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected1
[i
* 4 + j
], x
, y
, color
);
842 U5(fx
).dwFillColor
= 0xff0000ff;
843 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
844 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
845 for (i
= 0; i
< 4; ++i
)
847 for (j
= 0; j
< 4; ++j
)
849 x
= 80 * ((2 * j
) + 1);
850 y
= 60 * ((2 * i
) + 1);
851 color
= get_surface_color(dst_surface
, x
, y
);
852 ok(compare_color(color
, expected2
[i
* 4 + j
], 1),
853 "Expected color 0x%08x at %u,%u, got 0x%08x.\n", expected2
[i
* 4 + j
], x
, y
, color
);
857 hr
= IDirectDrawSurface_BltFast(dst_surface
, 0, 0, src_surface
, NULL
, DDBLTFAST_WAIT
);
858 ok(hr
== DDERR_BLTFASTCANTCLIP
|| broken(hr
== E_NOTIMPL
/* NT4 */), "Got unexpected hr %#x.\n", hr
);
860 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window
);
861 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
862 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
863 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
864 DestroyWindow(window
);
865 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
866 ok(hr
== E_FAIL
, "Got unexpected hr %#x.\n", hr
);
867 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, NULL
);
868 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
869 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
870 ok(SUCCEEDED(hr
), "Failed to get clip list size, hr %#x.\n", hr
);
871 hr
= IDirectDrawClipper_SetClipList(clipper
, NULL
, 0);
872 ok(SUCCEEDED(hr
), "Failed to set clip list, hr %#x.\n", hr
);
873 hr
= IDirectDrawClipper_GetClipList(clipper
, NULL
, NULL
, &ret
);
874 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
875 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
876 ok(hr
== DDERR_NOCLIPLIST
, "Got unexpected hr %#x.\n", hr
);
878 IDirectDrawSurface_Release(dst_surface
);
879 IDirectDrawSurface_Release(src_surface
);
880 refcount
= IDirectDrawClipper_Release(clipper
);
881 ok(!refcount
, "Clipper has %u references left.\n", refcount
);
882 IDirectDraw_Release(ddraw
);
885 static void test_coop_level_d3d_state(void)
887 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
888 IDirectDrawSurface
*rt
, *surface
;
889 IDirect3DMaterial
*background
;
890 IDirect3DViewport
*viewport
;
891 IDirect3DDevice
*device
;
892 D3DMATERIAL material
;
898 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
899 0, 0, 640, 480, 0, 0, 0, 0);
900 ddraw
= create_ddraw();
901 ok(!!ddraw
, "Failed to create a ddraw object.\n");
902 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
904 skip("Failed to create a 3D device, skipping test.\n");
905 IDirectDraw_Release(ddraw
);
906 DestroyWindow(window
);
910 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
911 viewport
= create_viewport(device
, 0, 0, 640, 480);
912 viewport_set_background(device
, viewport
, background
);
914 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
915 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
916 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
917 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
918 color
= get_surface_color(rt
, 320, 240);
919 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
921 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
922 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
923 hr
= IDirectDrawSurface_IsLost(rt
);
924 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
925 hr
= restore_surfaces(ddraw
);
926 ok(SUCCEEDED(hr
), "Failed to restore surfaces, hr %#x.\n", hr
);
928 memset(&material
, 0, sizeof(material
));
929 material
.dwSize
= sizeof(material
);
930 U1(U(material
).diffuse
).r
= 0.0f
;
931 U2(U(material
).diffuse
).g
= 1.0f
;
932 U3(U(material
).diffuse
).b
= 0.0f
;
933 U4(U(material
).diffuse
).a
= 1.0f
;
934 hr
= IDirect3DMaterial_SetMaterial(background
, &material
);
935 ok(SUCCEEDED(hr
), "Failed to set material data, hr %#x.\n", hr
);
937 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&surface
);
938 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
939 ok(surface
== rt
, "Got unexpected surface %p.\n", surface
);
940 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
941 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
942 color
= get_surface_color(rt
, 320, 240);
943 ok(compare_color(color
, 0x0000ff00, 1) || broken(compare_color(color
, 0x00000000, 1)),
944 "Got unexpected color 0x%08x.\n", color
);
946 destroy_viewport(device
, viewport
);
947 destroy_material(background
);
948 IDirectDrawSurface_Release(surface
);
949 IDirectDrawSurface_Release(rt
);
950 IDirect3DDevice_Release(device
);
951 IDirectDraw_Release(ddraw
);
952 DestroyWindow(window
);
955 static void test_surface_interface_mismatch(void)
957 IDirectDraw
*ddraw
= NULL
;
958 IDirectDrawSurface
*surface
= NULL
, *ds
;
959 IDirectDrawSurface3
*surface3
= NULL
;
960 IDirect3DDevice
*device
= NULL
;
961 IDirect3DViewport
*viewport
= NULL
;
962 IDirect3DMaterial
*background
= NULL
;
963 DDSURFACEDESC surface_desc
;
969 D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
971 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
972 0, 0, 640, 480, 0, 0, 0, 0);
973 ddraw
= create_ddraw();
974 ok(!!ddraw
, "Failed to create a ddraw object.\n");
975 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
977 skip("Failed to create a 3D device, skipping test.\n");
978 IDirectDraw_Release(ddraw
);
979 DestroyWindow(window
);
982 z_depth
= get_device_z_depth(device
);
983 ok(!!z_depth
, "Failed to get device z depth.\n");
984 IDirect3DDevice_Release(device
);
987 memset(&surface_desc
, 0, sizeof(surface_desc
));
988 surface_desc
.dwSize
= sizeof(surface_desc
);
989 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
990 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
991 surface_desc
.dwWidth
= 640;
992 surface_desc
.dwHeight
= 480;
994 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
995 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
997 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirectDrawSurface3
, (void **)&surface3
);
1000 skip("Failed to get the IDirectDrawSurface3 interface, skipping test.\n");
1004 memset(&surface_desc
, 0, sizeof(surface_desc
));
1005 surface_desc
.dwSize
= sizeof(surface_desc
);
1006 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_ZBUFFERBITDEPTH
| DDSD_WIDTH
| DDSD_HEIGHT
;
1007 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
1008 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
1009 surface_desc
.dwWidth
= 640;
1010 surface_desc
.dwHeight
= 480;
1011 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &ds
, NULL
);
1012 ok(SUCCEEDED(hr
), "Failed to create depth buffer, hr %#x.\n", hr
);
1016 /* Using a different surface interface version still works */
1017 hr
= IDirectDrawSurface3_AddAttachedSurface(surface3
, (IDirectDrawSurface3
*)ds
);
1018 ok(SUCCEEDED(hr
), "Failed to attach depth buffer, hr %#x.\n", hr
);
1019 refcount
= IDirectDrawSurface_Release(ds
);
1020 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
1025 hr
= IDirectDrawSurface3_QueryInterface(surface3
, &IID_IDirect3DHALDevice
, (void **)&device
);
1026 ok(SUCCEEDED(hr
), "Failed to create d3d device.\n");
1030 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1031 viewport
= create_viewport(device
, 0, 0, 640, 480);
1032 viewport_set_background(device
, viewport
, background
);
1034 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1035 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
1036 color
= get_surface_color(surface
, 320, 240);
1037 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
1041 destroy_viewport(device
, viewport
);
1043 destroy_material(background
);
1044 if (surface3
) IDirectDrawSurface3_Release(surface3
);
1045 if (surface
) IDirectDrawSurface_Release(surface
);
1046 if (device
) IDirect3DDevice_Release(device
);
1047 if (ddraw
) IDirectDraw_Release(ddraw
);
1048 DestroyWindow(window
);
1051 static void test_coop_level_threaded(void)
1053 struct create_window_thread_param p
;
1057 ddraw
= create_ddraw();
1058 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1059 create_window_thread(&p
);
1061 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, p
.window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
1062 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
1064 IDirectDraw_Release(ddraw
);
1065 destroy_window_thread(&p
);
1068 static ULONG
get_refcount(IUnknown
*test_iface
)
1070 IUnknown_AddRef(test_iface
);
1071 return IUnknown_Release(test_iface
);
1074 static void test_viewport(void)
1080 IDirect3DViewport
*viewport
, *another_vp
;
1081 IDirect3DViewport2
*viewport2
;
1082 IDirect3DViewport3
*viewport3
;
1083 IDirectDrawGammaControl
*gamma
;
1085 IDirect3DDevice
*device
;
1088 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1089 0, 0, 640, 480, 0, 0, 0, 0);
1090 ddraw
= create_ddraw();
1091 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1092 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1094 skip("Failed to create a 3D device, skipping test.\n");
1095 IDirectDraw_Release(ddraw
);
1096 DestroyWindow(window
);
1100 hr
= IDirectDraw_QueryInterface(ddraw
, &IID_IDirect3D
, (void **)&d3d
);
1101 ok(SUCCEEDED(hr
), "Failed to get d3d interface, hr %#x.\n", hr
);
1102 ref
= get_refcount((IUnknown
*) d3d
);
1103 ok(ref
== 2, "IDirect3D refcount is %d\n", ref
);
1105 hr
= IDirect3D_CreateViewport(d3d
, &viewport
, NULL
);
1106 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1107 ref
= get_refcount((IUnknown
*)viewport
);
1108 ok(ref
== 1, "Initial IDirect3DViewport refcount is %u\n", ref
);
1109 ref
= get_refcount((IUnknown
*)d3d
);
1110 ok(ref
== 2, "IDirect3D refcount is %u\n", ref
);
1112 /* E_FAIL return values are returned by Winetestbot Windows NT machines. While not supporting
1113 * newer interfaces is legitimate for old ddraw versions, E_FAIL violates Microsoft's rules
1114 * for QueryInterface, hence the broken() */
1115 gamma
= (IDirectDrawGammaControl
*)0xdeadbeef;
1116 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IDirectDrawGammaControl
, (void **)&gamma
);
1117 ok(hr
== E_NOINTERFACE
|| broken(hr
== E_FAIL
), "Got unexpected hr %#x.\n", hr
);
1118 ok(gamma
== NULL
, "Interface not set to NULL by failed QI call: %p\n", gamma
);
1119 if (SUCCEEDED(hr
)) IDirectDrawGammaControl_Release(gamma
);
1120 /* NULL iid: Segfaults */
1122 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IDirect3DViewport2
, (void **)&viewport2
);
1123 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
|| broken(hr
== E_FAIL
),
1124 "Failed to QI IDirect3DViewport2, hr %#x.\n", hr
);
1127 ref
= get_refcount((IUnknown
*)viewport
);
1128 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1129 ref
= get_refcount((IUnknown
*)viewport2
);
1130 ok(ref
== 2, "IDirect3DViewport2 refcount is %u\n", ref
);
1131 IDirect3DViewport2_Release(viewport2
);
1135 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IDirect3DViewport3
, (void **)&viewport3
);
1136 ok(SUCCEEDED(hr
) || hr
== E_NOINTERFACE
|| broken(hr
== E_FAIL
),
1137 "Failed to QI IDirect3DViewport3, hr %#x.\n", hr
);
1140 ref
= get_refcount((IUnknown
*)viewport
);
1141 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1142 ref
= get_refcount((IUnknown
*)viewport3
);
1143 ok(ref
== 2, "IDirect3DViewport3 refcount is %u\n", ref
);
1144 IDirect3DViewport3_Release(viewport3
);
1147 hr
= IDirect3DViewport_QueryInterface(viewport
, &IID_IUnknown
, (void **)&unknown
);
1148 ok(SUCCEEDED(hr
), "Failed to QI IUnknown, hr %#x.\n", hr
);
1151 ref
= get_refcount((IUnknown
*)viewport
);
1152 ok(ref
== 2, "IDirect3DViewport refcount is %u\n", ref
);
1153 ref
= get_refcount(unknown
);
1154 ok(ref
== 2, "IUnknown refcount is %u\n", ref
);
1155 IUnknown_Release(unknown
);
1158 /* AddViewport(NULL): Segfault */
1159 hr
= IDirect3DDevice_DeleteViewport(device
, NULL
);
1160 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
1162 hr
= IDirect3D_CreateViewport(d3d
, &another_vp
, NULL
);
1163 ok(SUCCEEDED(hr
), "Failed to create viewport, hr %#x.\n", hr
);
1165 hr
= IDirect3DDevice_AddViewport(device
, viewport
);
1166 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1167 ref
= get_refcount((IUnknown
*) viewport
);
1168 ok(ref
== 2, "IDirect3DViewport refcount is %d\n", ref
);
1169 hr
= IDirect3DDevice_AddViewport(device
, another_vp
);
1170 ok(SUCCEEDED(hr
), "Failed to add viewport to device, hr %#x.\n", hr
);
1171 ref
= get_refcount((IUnknown
*) another_vp
);
1172 ok(ref
== 2, "IDirect3DViewport refcount is %d\n", ref
);
1174 hr
= IDirect3DDevice_DeleteViewport(device
, another_vp
);
1175 ok(SUCCEEDED(hr
), "Failed to delete viewport from device, hr %#x.\n", hr
);
1176 ref
= get_refcount((IUnknown
*) another_vp
);
1177 ok(ref
== 1, "IDirect3DViewport refcount is %d\n", ref
);
1179 IDirect3DDevice_Release(device
);
1180 ref
= get_refcount((IUnknown
*) viewport
);
1181 ok(ref
== 1, "IDirect3DViewport refcount is %d\n", ref
);
1183 IDirect3DViewport_Release(another_vp
);
1184 IDirect3D_Release(d3d
);
1185 IDirect3DViewport_Release(viewport
);
1186 DestroyWindow(window
);
1187 IDirectDraw_Release(ddraw
);
1190 static void test_zenable(void)
1192 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1193 static D3DTLVERTEX tquad
[] =
1195 {{ 0.0f
}, {480.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1196 {{ 0.0f
}, { 0.0f
}, {-0.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1197 {{640.0f
}, {480.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1198 {{640.0f
}, { 0.0f
}, { 1.5f
}, {1.0f
}, {0xff00ff00}, {0x00000000}, {0.0f
}, {0.0f
}},
1200 IDirect3DExecuteBuffer
*execute_buffer
;
1201 D3DEXECUTEBUFFERDESC exec_desc
;
1202 IDirect3DMaterial
*background
;
1203 IDirect3DViewport
*viewport
;
1204 IDirect3DDevice
*device
;
1205 IDirectDrawSurface
*rt
;
1215 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1216 0, 0, 640, 480, 0, 0, 0, 0);
1217 ddraw
= create_ddraw();
1218 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1219 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1221 skip("Failed to create a 3D device, skipping test.\n");
1222 IDirectDraw_Release(ddraw
);
1223 DestroyWindow(window
);
1227 background
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
1228 viewport
= create_viewport(device
, 0, 0, 640, 480);
1229 viewport_set_background(device
, viewport
, background
);
1231 memset(&exec_desc
, 0, sizeof(exec_desc
));
1232 exec_desc
.dwSize
= sizeof(exec_desc
);
1233 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1234 exec_desc
.dwBufferSize
= 1024;
1235 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1237 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
1238 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
1239 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
1240 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
1241 memcpy(exec_desc
.lpData
, tquad
, sizeof(tquad
));
1242 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(tquad
);
1243 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1244 emit_set_rs(&ptr
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
1245 emit_tquad(&ptr
, 0);
1247 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
1248 inst_length
-= sizeof(tquad
);
1249 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
1250 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
1252 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1253 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1254 hr
= IDirect3DDevice_BeginScene(device
);
1255 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1256 set_execute_data(execute_buffer
, 4, sizeof(tquad
), inst_length
);
1257 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1258 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1259 hr
= IDirect3DDevice_EndScene(device
);
1260 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1262 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
1263 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1264 for (i
= 0; i
< 4; ++i
)
1266 for (j
= 0; j
< 4; ++j
)
1268 x
= 80 * ((2 * j
) + 1);
1269 y
= 60 * ((2 * i
) + 1);
1270 color
= get_surface_color(rt
, x
, y
);
1271 ok(compare_color(color
, 0x0000ff00, 1),
1272 "Expected color 0x0000ff00 at %u, %u, got 0x%08x.\n", x
, y
, color
);
1275 IDirectDrawSurface_Release(rt
);
1277 destroy_viewport(device
, viewport
);
1278 IDirect3DExecuteBuffer_Release(execute_buffer
);
1279 destroy_material(background
);
1280 IDirect3DDevice_Release(device
);
1281 IDirectDraw_Release(ddraw
);
1282 DestroyWindow(window
);
1285 static void test_ck_rgba(void)
1287 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1288 static D3DTLVERTEX tquad
[] =
1290 {{ 0.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1291 {{ 0.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1292 {{640.0f
}, {480.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1293 {{640.0f
}, { 0.0f
}, {0.25f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1294 {{ 0.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1295 {{ 0.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1296 {{640.0f
}, {480.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1297 {{640.0f
}, { 0.0f
}, {0.75f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1299 /* Supposedly there was no D3DRENDERSTATE_COLORKEYENABLE in D3D < 5.
1300 * Maybe the WARP driver on Windows 8 ignores setting it via the older
1301 * device interface but it's buggy in that the internal state is not
1302 * initialized, or possibly toggling D3DRENDERSTATE_COLORKEYENABLE /
1303 * D3DRENDERSTATE_ALPHABLENDENABLE has unintended side effects.
1304 * Checking the W8 test results it seems like test 1 fails most of the time
1305 * and test 0 fails very rarely. */
1308 D3DCOLOR fill_color
;
1311 D3DCOLOR result1
, result1_r200
, result1_warp
;
1312 D3DCOLOR result2
, result2_r200
, result2_warp
;
1316 /* r200 on Windows doesn't check the alpha component when applying the color
1317 * key, so the key matches on every texel. */
1318 {0xff00ff00, TRUE
, TRUE
, 0x00ff0000, 0x00ff0000, 0x0000ff00,
1319 0x000000ff, 0x000000ff, 0x0000ff00},
1320 {0xff00ff00, TRUE
, FALSE
, 0x00ff0000, 0x00ff0000, 0x0000ff00,
1321 0x000000ff, 0x000000ff, 0x0000ff00},
1322 {0xff00ff00, FALSE
, TRUE
, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1323 0x0000ff00, 0x0000ff00, 0x0000ff00},
1324 {0xff00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1325 0x0000ff00, 0x0000ff00, 0x0000ff00},
1326 {0x7f00ff00, TRUE
, TRUE
, 0x00807f00, 0x00ff0000, 0x00807f00,
1327 0x00807f00, 0x000000ff, 0x00807f00},
1328 {0x7f00ff00, TRUE
, FALSE
, 0x0000ff00, 0x00ff0000, 0x0000ff00,
1329 0x0000ff00, 0x000000ff, 0x0000ff00},
1330 {0x7f00ff00, FALSE
, TRUE
, 0x00807f00, 0x00807f00, 0x00807f00,
1331 0x00807f00, 0x00807f00, 0x00807f00},
1332 {0x7f00ff00, FALSE
, FALSE
, 0x0000ff00, 0x0000ff00, 0x0000ff00,
1333 0x0000ff00, 0x0000ff00, 0x0000ff00},
1336 IDirect3DExecuteBuffer
*execute_buffer
;
1337 D3DTEXTUREHANDLE texture_handle
;
1338 D3DEXECUTEBUFFERDESC exec_desc
;
1339 IDirect3DMaterial
*background
;
1340 IDirectDrawSurface
*surface
;
1341 IDirect3DViewport
*viewport
;
1342 DDSURFACEDESC surface_desc
;
1343 IDirect3DTexture
*texture
;
1344 IDirect3DDevice
*device
;
1345 IDirectDrawSurface
*rt
;
1353 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1354 0, 0, 640, 480, 0, 0, 0, 0);
1355 ddraw
= create_ddraw();
1356 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1357 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1359 skip("Failed to create a 3D device, skipping test.\n");
1360 IDirectDraw_Release(ddraw
);
1361 DestroyWindow(window
);
1365 background
= create_diffuse_material(device
, 1.0, 0.0f
, 0.0f
, 1.0f
);
1366 viewport
= create_viewport(device
, 0, 0, 640, 480);
1367 viewport_set_background(device
, viewport
, background
);
1369 memset(&surface_desc
, 0, sizeof(surface_desc
));
1370 surface_desc
.dwSize
= sizeof(surface_desc
);
1371 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1372 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1373 surface_desc
.dwWidth
= 256;
1374 surface_desc
.dwHeight
= 256;
1375 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1376 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
1377 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1378 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1379 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1380 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1381 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
1382 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0xff00ff00;
1383 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0xff00ff00;
1384 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1385 ok(SUCCEEDED(hr
), "Failed to create destination surface, hr %#x.\n", hr
);
1386 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
1387 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1388 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
1389 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1390 IDirect3DTexture_Release(texture
);
1392 memset(&exec_desc
, 0, sizeof(exec_desc
));
1393 exec_desc
.dwSize
= sizeof(exec_desc
);
1394 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1395 exec_desc
.dwBufferSize
= 1024;
1396 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1397 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
1398 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
1400 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
1401 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1403 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
1405 UINT draw1_len
, draw2_len
;
1408 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
1409 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
1410 memcpy(exec_desc
.lpData
, tquad
, sizeof(tquad
));
1411 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(tquad
);
1412 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1413 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1414 emit_set_rs(&ptr
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
1415 emit_set_rs(&ptr
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
1416 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, tests
[i
].color_key
);
1417 emit_set_rs(&ptr
, D3DRENDERSTATE_ALPHABLENDENABLE
, tests
[i
].blend
);
1418 emit_tquad(&ptr
, 0);
1420 draw1_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- sizeof(tquad
);
1421 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 4, 4);
1422 emit_tquad(&ptr
, 0);
1423 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1425 draw2_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw1_len
;
1426 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
1427 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
1429 memset(&fx
, 0, sizeof(fx
));
1430 fx
.dwSize
= sizeof(fx
);
1431 U5(fx
).dwFillColor
= tests
[i
].fill_color
;
1432 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1433 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1435 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
1436 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1437 hr
= IDirect3DDevice_BeginScene(device
);
1438 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1439 set_execute_data(execute_buffer
, 8, sizeof(tquad
), draw1_len
);
1440 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1441 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1442 hr
= IDirect3DDevice_EndScene(device
);
1443 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1445 color
= get_surface_color(rt
, 320, 240);
1446 ok(compare_color(color
, tests
[i
].result1
, 1)
1447 || broken(compare_color(color
, tests
[i
].result1_r200
, 1))
1448 || broken(compare_color(color
, tests
[i
].result1_warp
, 1)),
1449 "Got unexpected color 0x%08x for test %u.\n", color
, i
);
1451 U5(fx
).dwFillColor
= 0xff0000ff;
1452 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1453 ok(SUCCEEDED(hr
), "Failed to fill texture, hr %#x.\n", hr
);
1455 hr
= IDirect3DDevice_BeginScene(device
);
1456 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1457 set_execute_data(execute_buffer
, 8, sizeof(tquad
) + draw1_len
, draw2_len
);
1458 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1459 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1460 hr
= IDirect3DDevice_EndScene(device
);
1461 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1463 /* This tests that fragments that are masked out by the color key are
1464 * discarded, instead of just fully transparent. */
1465 color
= get_surface_color(rt
, 320, 240);
1466 ok(compare_color(color
, tests
[i
].result2
, 1)
1467 || broken(compare_color(color
, tests
[i
].result2_r200
, 1))
1468 || broken(compare_color(color
, tests
[i
].result2_warp
, 1)),
1469 "Got unexpected color 0x%08x for test %u.\n", color
, i
);
1472 IDirectDrawSurface_Release(rt
);
1473 IDirect3DExecuteBuffer_Release(execute_buffer
);
1474 IDirectDrawSurface_Release(surface
);
1475 destroy_viewport(device
, viewport
);
1476 destroy_material(background
);
1477 IDirect3DDevice_Release(device
);
1478 IDirectDraw_Release(ddraw
);
1479 DestroyWindow(window
);
1482 static void test_ck_default(void)
1484 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
1485 static D3DTLVERTEX tquad
[] =
1487 {{ 0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {0.0f
}},
1488 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {0.0f
}, {1.0f
}},
1489 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {0.0f
}},
1490 {{640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0x00000000}, {1.0f
}, {1.0f
}},
1492 IDirect3DExecuteBuffer
*execute_buffer
;
1493 IDirectDrawSurface
*surface
, *rt
;
1494 D3DTEXTUREHANDLE texture_handle
;
1495 D3DEXECUTEBUFFERDESC exec_desc
;
1496 IDirect3DMaterial
*background
;
1497 UINT draw1_offset
, draw1_len
;
1498 UINT draw2_offset
, draw2_len
;
1499 UINT draw3_offset
, draw3_len
;
1500 UINT draw4_offset
, draw4_len
;
1501 IDirect3DViewport
*viewport
;
1502 DDSURFACEDESC surface_desc
;
1503 IDirect3DTexture
*texture
;
1504 IDirect3DDevice
*device
;
1512 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1513 0, 0, 640, 480, 0, 0, 0, 0);
1514 ddraw
= create_ddraw();
1515 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1516 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1518 skip("Failed to create a 3D device, skipping test.\n");
1519 IDirectDraw_Release(ddraw
);
1520 DestroyWindow(window
);
1524 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
1525 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
1527 background
= create_diffuse_material(device
, 0.0, 1.0f
, 0.0f
, 1.0f
);
1528 viewport
= create_viewport(device
, 0, 0, 640, 480);
1529 viewport_set_background(device
, viewport
, background
);
1531 memset(&surface_desc
, 0, sizeof(surface_desc
));
1532 surface_desc
.dwSize
= sizeof(surface_desc
);
1533 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
1534 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1535 surface_desc
.dwWidth
= 256;
1536 surface_desc
.dwHeight
= 256;
1537 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
1538 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
1539 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
1540 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
1541 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
1542 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
1543 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x000000ff;
1544 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x000000ff;
1545 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1546 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1547 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
1548 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
1549 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
1550 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
1551 IDirect3DTexture_Release(texture
);
1553 memset(&fx
, 0, sizeof(fx
));
1554 fx
.dwSize
= sizeof(fx
);
1555 U5(fx
).dwFillColor
= 0x000000ff;
1556 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
1557 ok(SUCCEEDED(hr
), "Failed to fill surface, hr %#x.\n", hr
);
1559 memset(&exec_desc
, 0, sizeof(exec_desc
));
1560 exec_desc
.dwSize
= sizeof(exec_desc
);
1561 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
1562 exec_desc
.dwBufferSize
= 1024;
1563 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
1564 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
1565 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
1567 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
1568 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
1569 memcpy(exec_desc
.lpData
, tquad
, sizeof(tquad
));
1570 ptr
= (BYTE
*)exec_desc
.lpData
+ sizeof(tquad
);
1571 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1572 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
1573 emit_tquad(&ptr
, 0);
1575 draw1_offset
= sizeof(tquad
);
1576 draw1_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw1_offset
;
1577 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1578 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, FALSE
);
1579 emit_tquad(&ptr
, 0);
1581 draw2_offset
= draw1_offset
+ draw1_len
;
1582 draw2_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw2_offset
;
1583 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1584 emit_tquad(&ptr
, 0);
1586 draw3_offset
= draw2_offset
+ draw2_len
;
1587 draw3_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw3_offset
;
1588 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 4);
1589 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
1590 emit_tquad(&ptr
, 0);
1591 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
1593 draw4_offset
= draw3_offset
+ draw3_len
;
1594 draw4_len
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
- draw4_offset
;
1595 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
1596 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
1598 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1599 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1600 hr
= IDirect3DDevice_BeginScene(device
);
1601 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1602 set_execute_data(execute_buffer
, 4, draw1_offset
, draw1_len
);
1603 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1604 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1605 hr
= IDirect3DDevice_EndScene(device
);
1606 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1607 color
= get_surface_color(rt
, 320, 240);
1608 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1610 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1611 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1612 hr
= IDirect3DDevice_BeginScene(device
);
1613 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1614 set_execute_data(execute_buffer
, 4, draw2_offset
, draw2_len
);
1615 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1616 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1617 hr
= IDirect3DDevice_EndScene(device
);
1618 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1619 color
= get_surface_color(rt
, 320, 240);
1620 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1622 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1623 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1624 hr
= IDirect3DDevice_BeginScene(device
);
1625 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1626 set_execute_data(execute_buffer
, 4, draw3_offset
, draw3_len
);
1627 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1628 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1629 hr
= IDirect3DDevice_EndScene(device
);
1630 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1631 color
= get_surface_color(rt
, 320, 240);
1632 ok(compare_color(color
, 0x000000ff, 1), "Got unexpected color 0x%08x.\n", color
);
1634 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
1635 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
1636 hr
= IDirect3DDevice_BeginScene(device
);
1637 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
1638 set_execute_data(execute_buffer
, 4, draw4_offset
, draw4_len
);
1639 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
1640 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
1641 hr
= IDirect3DDevice_EndScene(device
);
1642 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
1643 color
= get_surface_color(rt
, 320, 240);
1644 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
1646 IDirect3DExecuteBuffer_Release(execute_buffer
);
1647 IDirectDrawSurface_Release(surface
);
1648 destroy_viewport(device
, viewport
);
1649 destroy_material(background
);
1650 IDirectDrawSurface_Release(rt
);
1651 IDirect3DDevice_Release(device
);
1652 IDirectDraw_Release(ddraw
);
1653 DestroyWindow(window
);
1656 static void test_ck_complex(void)
1658 IDirectDrawSurface
*surface
, *mipmap
, *tmp
;
1659 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
1660 DDSURFACEDESC surface_desc
;
1661 IDirect3DDevice
*device
;
1662 DDCOLORKEY color_key
;
1669 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1670 0, 0, 640, 480, 0, 0, 0, 0);
1671 ddraw
= create_ddraw();
1672 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1673 if (!(device
= create_device(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
)))
1675 skip("Failed to create a 3D device, skipping test.\n");
1676 DestroyWindow(window
);
1677 IDirectDraw2_Release(ddraw
);
1680 IDirect3DDevice_Release(device
);
1682 memset(&surface_desc
, 0, sizeof(surface_desc
));
1683 surface_desc
.dwSize
= sizeof(surface_desc
);
1684 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1685 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
1686 surface_desc
.dwWidth
= 128;
1687 surface_desc
.dwHeight
= 128;
1688 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1689 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1691 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1692 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1693 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1694 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1695 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1696 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1697 memset(&color_key
, 0, sizeof(color_key
));
1698 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1699 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1700 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1701 color_key
.dwColorSpaceLowValue
);
1702 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1703 color_key
.dwColorSpaceHighValue
);
1706 IDirectDrawSurface_AddRef(mipmap
);
1707 for (i
= 0; i
< 7; ++i
)
1709 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1710 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
1712 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1713 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1714 color_key
.dwColorSpaceLowValue
= 0x000000ff;
1715 color_key
.dwColorSpaceHighValue
= 0x000000ff;
1716 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1717 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x, i %u.\n", hr
, i
);
1718 memset(&color_key
, 0, sizeof(color_key
));
1719 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1720 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x, i %u.\n", hr
, i
);
1721 ok(color_key
.dwColorSpaceLowValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1722 color_key
.dwColorSpaceLowValue
, i
);
1723 ok(color_key
.dwColorSpaceHighValue
== 0x000000ff, "Got unexpected value 0x%08x, i %u.\n",
1724 color_key
.dwColorSpaceHighValue
, i
);
1726 IDirectDrawSurface_Release(mipmap
);
1730 memset(&color_key
, 0, sizeof(color_key
));
1731 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1732 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1733 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1734 color_key
.dwColorSpaceLowValue
);
1735 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1736 color_key
.dwColorSpaceHighValue
);
1738 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
1739 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
1740 IDirectDrawSurface_Release(mipmap
);
1741 refcount
= IDirectDrawSurface_Release(surface
);
1742 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1744 memset(&surface_desc
, 0, sizeof(surface_desc
));
1745 surface_desc
.dwSize
= sizeof(surface_desc
);
1746 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
1747 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
1748 surface_desc
.dwBackBufferCount
= 1;
1749 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1750 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1752 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1753 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x.\n", hr
);
1754 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1755 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1756 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1757 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1758 memset(&color_key
, 0, sizeof(color_key
));
1759 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &color_key
);
1760 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1761 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1762 color_key
.dwColorSpaceLowValue
);
1763 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1764 color_key
.dwColorSpaceHighValue
);
1766 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
1767 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
1769 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1770 ok(hr
== DDERR_NOCOLORKEY
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
1771 color_key
.dwColorSpaceLowValue
= 0x0000ff00;
1772 color_key
.dwColorSpaceHighValue
= 0x0000ff00;
1773 hr
= IDirectDrawSurface_SetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1774 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
1775 memset(&color_key
, 0, sizeof(color_key
));
1776 hr
= IDirectDrawSurface_GetColorKey(tmp
, DDCKEY_SRCBLT
, &color_key
);
1777 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
1778 ok(color_key
.dwColorSpaceLowValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1779 color_key
.dwColorSpaceLowValue
);
1780 ok(color_key
.dwColorSpaceHighValue
== 0x0000ff00, "Got unexpected value 0x%08x.\n",
1781 color_key
.dwColorSpaceHighValue
);
1783 IDirectDrawSurface_Release(tmp
);
1785 refcount
= IDirectDrawSurface_Release(surface
);
1786 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1787 refcount
= IDirectDraw_Release(ddraw
);
1788 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
1789 DestroyWindow(window
);
1795 REFIID refcount_iid
;
1799 static void test_qi(const char *test_name
, IUnknown
*base_iface
,
1800 REFIID refcount_iid
, const struct qi_test
*tests
, UINT entry_count
)
1802 ULONG refcount
, expected_refcount
;
1803 IUnknown
*iface1
, *iface2
;
1807 for (i
= 0; i
< entry_count
; ++i
)
1809 hr
= IUnknown_QueryInterface(base_iface
, tests
[i
].iid
, (void **)&iface1
);
1810 ok(hr
== tests
[i
].hr
, "Got hr %#x for test \"%s\" %u.\n", hr
, test_name
, i
);
1813 for (j
= 0; j
< entry_count
; ++j
)
1815 hr
= IUnknown_QueryInterface(iface1
, tests
[j
].iid
, (void **)&iface2
);
1816 ok(hr
== tests
[j
].hr
, "Got hr %#x for test \"%s\" %u, %u.\n", hr
, test_name
, i
, j
);
1819 expected_refcount
= 0;
1820 if (IsEqualGUID(refcount_iid
, tests
[j
].refcount_iid
))
1821 ++expected_refcount
;
1822 if (IsEqualGUID(tests
[i
].refcount_iid
, tests
[j
].refcount_iid
))
1823 ++expected_refcount
;
1824 refcount
= IUnknown_Release(iface2
);
1825 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, %u, expected %u.\n",
1826 refcount
, test_name
, i
, j
, expected_refcount
);
1830 expected_refcount
= 0;
1831 if (IsEqualGUID(refcount_iid
, tests
[i
].refcount_iid
))
1832 ++expected_refcount
;
1833 refcount
= IUnknown_Release(iface1
);
1834 ok(refcount
== expected_refcount
, "Got refcount %u for test \"%s\" %u, expected %u.\n",
1835 refcount
, test_name
, i
, expected_refcount
);
1840 static void test_surface_qi(void)
1842 static const struct qi_test tests
[] =
1844 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface
, S_OK
},
1845 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface
, S_OK
},
1846 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1847 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1848 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1849 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1850 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1851 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1852 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1853 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
1854 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
1855 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
1856 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
1857 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
1858 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
1859 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
1860 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
1861 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
1862 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
1863 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
1864 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
1865 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
1866 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
1867 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
1868 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
1869 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
1870 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
1871 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
1872 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
1873 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
1874 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
1875 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
1876 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
1877 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
1878 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1881 IDirectDrawSurface
*surface
;
1882 DDSURFACEDESC surface_desc
;
1883 IDirect3DDevice
*device
;
1888 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1890 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1894 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1895 0, 0, 640, 480, 0, 0, 0, 0);
1896 ddraw
= create_ddraw();
1897 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1898 /* Try to create a D3D device to see if the ddraw implementation supports
1899 * D3D. 64-bit ddraw in particular doesn't seem to support D3D, and
1900 * doesn't support e.g. the IDirect3DTexture interfaces. */
1901 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1903 skip("Failed to create a 3D device, skipping test.\n");
1904 IDirectDraw_Release(ddraw
);
1905 DestroyWindow(window
);
1908 IDirect3DDevice_Release(device
);
1910 memset(&surface_desc
, 0, sizeof(surface_desc
));
1911 surface_desc
.dwSize
= sizeof(surface_desc
);
1912 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
1913 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
1914 surface_desc
.dwWidth
= 512;
1915 surface_desc
.dwHeight
= 512;
1916 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
1917 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
1919 test_qi("surface_qi", (IUnknown
*)surface
, &IID_IDirectDrawSurface
, tests
, sizeof(tests
) / sizeof(*tests
));
1921 IDirectDrawSurface_Release(surface
);
1922 IDirectDraw_Release(ddraw
);
1923 DestroyWindow(window
);
1926 static void test_device_qi(void)
1928 static const struct qi_test tests
[] =
1930 {&IID_IDirect3DTexture2
, &IID_IDirectDrawSurface
, S_OK
},
1931 {&IID_IDirect3DTexture
, &IID_IDirectDrawSurface
, S_OK
},
1932 {&IID_IDirectDrawGammaControl
, &IID_IDirectDrawGammaControl
, S_OK
},
1933 {&IID_IDirectDrawColorControl
, NULL
, E_NOINTERFACE
},
1934 {&IID_IDirectDrawSurface7
, &IID_IDirectDrawSurface7
, S_OK
},
1935 {&IID_IDirectDrawSurface4
, &IID_IDirectDrawSurface4
, S_OK
},
1936 {&IID_IDirectDrawSurface3
, &IID_IDirectDrawSurface3
, S_OK
},
1937 {&IID_IDirectDrawSurface2
, &IID_IDirectDrawSurface2
, S_OK
},
1938 {&IID_IDirectDrawSurface
, &IID_IDirectDrawSurface
, S_OK
},
1939 {&IID_IDirect3DDevice7
, NULL
, E_INVALIDARG
},
1940 {&IID_IDirect3DDevice3
, NULL
, E_INVALIDARG
},
1941 {&IID_IDirect3DDevice2
, NULL
, E_INVALIDARG
},
1942 {&IID_IDirect3DDevice
, NULL
, E_INVALIDARG
},
1943 {&IID_IDirect3DHALDevice
, &IID_IDirectDrawSurface
, S_OK
},
1944 {&IID_IDirect3D7
, NULL
, E_INVALIDARG
},
1945 {&IID_IDirect3D3
, NULL
, E_INVALIDARG
},
1946 {&IID_IDirect3D2
, NULL
, E_INVALIDARG
},
1947 {&IID_IDirect3D
, NULL
, E_INVALIDARG
},
1948 {&IID_IDirectDraw7
, NULL
, E_INVALIDARG
},
1949 {&IID_IDirectDraw4
, NULL
, E_INVALIDARG
},
1950 {&IID_IDirectDraw3
, NULL
, E_INVALIDARG
},
1951 {&IID_IDirectDraw2
, NULL
, E_INVALIDARG
},
1952 {&IID_IDirectDraw
, NULL
, E_INVALIDARG
},
1953 {&IID_IDirect3DLight
, NULL
, E_INVALIDARG
},
1954 {&IID_IDirect3DMaterial
, NULL
, E_INVALIDARG
},
1955 {&IID_IDirect3DMaterial2
, NULL
, E_INVALIDARG
},
1956 {&IID_IDirect3DMaterial3
, NULL
, E_INVALIDARG
},
1957 {&IID_IDirect3DExecuteBuffer
, NULL
, E_INVALIDARG
},
1958 {&IID_IDirect3DViewport
, NULL
, E_INVALIDARG
},
1959 {&IID_IDirect3DViewport2
, NULL
, E_INVALIDARG
},
1960 {&IID_IDirect3DViewport3
, NULL
, E_INVALIDARG
},
1961 {&IID_IDirect3DVertexBuffer
, NULL
, E_INVALIDARG
},
1962 {&IID_IDirect3DVertexBuffer7
, NULL
, E_INVALIDARG
},
1963 {&IID_IDirectDrawPalette
, NULL
, E_INVALIDARG
},
1964 {&IID_IDirectDrawClipper
, NULL
, E_INVALIDARG
},
1965 {&IID_IUnknown
, &IID_IDirectDrawSurface
, S_OK
},
1969 IDirect3DDevice
*device
;
1973 if (!GetProcAddress(GetModuleHandleA("ddraw.dll"), "DirectDrawCreateEx"))
1975 win_skip("DirectDrawCreateEx not available, skipping test.\n");
1979 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
1980 0, 0, 640, 480, 0, 0, 0, 0);
1981 ddraw
= create_ddraw();
1982 ok(!!ddraw
, "Failed to create a ddraw object.\n");
1983 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
1985 skip("Failed to create a 3D device, skipping test.\n");
1986 IDirectDraw_Release(ddraw
);
1987 DestroyWindow(window
);
1991 test_qi("device_qi", (IUnknown
*)device
, &IID_IDirectDrawSurface
, tests
, sizeof(tests
) / sizeof(*tests
));
1993 IDirect3DDevice_Release(device
);
1994 IDirectDraw_Release(ddraw
);
1995 DestroyWindow(window
);
1998 static void test_wndproc(void)
2000 LONG_PTR proc
, ddraw_proc
;
2007 static struct message messages
[] =
2009 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2010 {WM_MOVE
, FALSE
, 0},
2011 {WM_SIZE
, FALSE
, 0},
2012 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2013 {WM_ACTIVATE
, FALSE
, 0},
2014 {WM_SETFOCUS
, FALSE
, 0},
2018 /* DDSCL_EXCLUSIVE replaces the window's window proc. */
2019 ddraw
= create_ddraw();
2020 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2022 wc
.lpfnWndProc
= test_proc
;
2023 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2024 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2026 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
2027 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
2029 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2030 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2031 (LONG_PTR
)test_proc
, proc
);
2032 expect_messages
= messages
;
2033 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2034 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2035 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2036 expect_messages
= NULL
;
2037 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2038 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2039 (LONG_PTR
)test_proc
, proc
);
2040 ref
= IDirectDraw_Release(ddraw
);
2041 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2042 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2043 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2044 (LONG_PTR
)test_proc
, proc
);
2046 /* DDSCL_NORMAL doesn't. */
2047 ddraw
= create_ddraw();
2048 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2049 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2050 (LONG_PTR
)test_proc
, proc
);
2051 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2052 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2053 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2054 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2055 (LONG_PTR
)test_proc
, proc
);
2056 ref
= IDirectDraw_Release(ddraw
);
2057 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2058 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2059 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2060 (LONG_PTR
)test_proc
, proc
);
2062 /* The original window proc is only restored by ddraw if the current
2063 * window proc matches the one ddraw set. This also affects switching
2064 * from DDSCL_NORMAL to DDSCL_EXCLUSIVE. */
2065 ddraw
= create_ddraw();
2066 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2067 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2068 (LONG_PTR
)test_proc
, proc
);
2069 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2070 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2071 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2072 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2073 (LONG_PTR
)test_proc
, proc
);
2075 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2076 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2077 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2078 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2079 (LONG_PTR
)test_proc
, proc
);
2080 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2081 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2082 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2083 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2084 (LONG_PTR
)test_proc
, proc
);
2085 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2086 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2087 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2088 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2089 (LONG_PTR
)DefWindowProcA
, proc
);
2090 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2091 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2092 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)ddraw_proc
);
2093 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2094 (LONG_PTR
)DefWindowProcA
, proc
);
2095 ref
= IDirectDraw_Release(ddraw
);
2096 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2097 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2098 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2099 (LONG_PTR
)test_proc
, proc
);
2101 ddraw
= create_ddraw();
2102 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2103 ok(proc
== (LONG_PTR
)test_proc
, "Expected wndproc %#lx, got %#lx.\n",
2104 (LONG_PTR
)test_proc
, proc
);
2105 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2106 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2107 proc
= SetWindowLongPtrA(window
, GWLP_WNDPROC
, (LONG_PTR
)DefWindowProcA
);
2108 ok(proc
!= (LONG_PTR
)test_proc
, "Expected wndproc != %#lx, got %#lx.\n",
2109 (LONG_PTR
)test_proc
, proc
);
2110 ref
= IDirectDraw_Release(ddraw
);
2111 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2112 proc
= GetWindowLongPtrA(window
, GWLP_WNDPROC
);
2113 ok(proc
== (LONG_PTR
)DefWindowProcA
, "Expected wndproc %#lx, got %#lx.\n",
2114 (LONG_PTR
)DefWindowProcA
, proc
);
2116 fix_wndproc(window
, (LONG_PTR
)test_proc
);
2117 expect_messages
= NULL
;
2118 DestroyWindow(window
);
2119 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2122 static void test_window_style(void)
2124 LONG style
, exstyle
, tmp
, expected_style
;
2125 RECT fullscreen_rect
, r
;
2132 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2133 0, 0, 100, 100, 0, 0, 0, 0);
2134 ddraw
= create_ddraw();
2135 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2137 style
= GetWindowLongA(window
, GWL_STYLE
);
2138 exstyle
= GetWindowLongA(window
, GWL_EXSTYLE
);
2139 SetRect(&fullscreen_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2141 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2142 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2144 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2145 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2146 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2147 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2149 GetWindowRect(window
, &r
);
2150 ok(EqualRect(&r
, &fullscreen_rect
), "Expected %s, got %s.\n",
2151 wine_dbgstr_rect(&fullscreen_rect
), wine_dbgstr_rect(&r
));
2152 GetClientRect(window
, &r
);
2153 todo_wine
ok(!EqualRect(&r
, &fullscreen_rect
), "Client rect and window rect are equal.\n");
2155 ret
= SetForegroundWindow(GetDesktopWindow());
2156 ok(ret
, "Failed to set foreground window.\n");
2158 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2159 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2160 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2161 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2163 ret
= SetForegroundWindow(window
);
2164 ok(ret
, "Failed to set foreground window.\n");
2165 /* Windows 7 (but not Vista and XP) shows the window when it receives focus. Hide it again,
2166 * the next tests expect this. */
2167 ShowWindow(window
, SW_HIDE
);
2169 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2170 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2172 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2173 todo_wine
ok(tmp
== style
, "Expected window style %#x, got %#x.\n", style
, tmp
);
2174 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2175 todo_wine
ok(tmp
== exstyle
, "Expected window extended style %#x, got %#x.\n", exstyle
, tmp
);
2177 ShowWindow(window
, SW_SHOW
);
2178 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2179 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2181 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2182 expected_style
= style
| WS_VISIBLE
;
2183 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2184 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2185 expected_style
= exstyle
| WS_EX_TOPMOST
;
2186 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2188 ret
= SetForegroundWindow(GetDesktopWindow());
2189 ok(ret
, "Failed to set foreground window.\n");
2190 tmp
= GetWindowLongA(window
, GWL_STYLE
);
2191 expected_style
= style
| WS_VISIBLE
| WS_MINIMIZE
;
2192 todo_wine
ok(tmp
== expected_style
, "Expected window style %#x, got %#x.\n", expected_style
, tmp
);
2193 tmp
= GetWindowLongA(window
, GWL_EXSTYLE
);
2194 expected_style
= exstyle
| WS_EX_TOPMOST
;
2195 todo_wine
ok(tmp
== expected_style
, "Expected window extended style %#x, got %#x.\n", expected_style
, tmp
);
2197 ref
= IDirectDraw_Release(ddraw
);
2198 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2200 DestroyWindow(window
);
2203 static void test_redundant_mode_set(void)
2205 DDSURFACEDESC surface_desc
= {0};
2212 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2213 0, 0, 100, 100, 0, 0, 0, 0);
2214 ddraw
= create_ddraw();
2215 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2217 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2218 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2220 surface_desc
.dwSize
= sizeof(surface_desc
);
2221 hr
= IDirectDraw_GetDisplayMode(ddraw
, &surface_desc
);
2222 ok(SUCCEEDED(hr
), "GetDisplayMode failed, hr %#x.\n", hr
);
2224 hr
= IDirectDraw_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2225 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
2226 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2228 GetWindowRect(window
, &r
);
2231 SetWindowPos(window
, HWND_TOP
, r
.left
, r
.top
, r
.right
, r
.bottom
, 0);
2232 GetWindowRect(window
, &s
);
2233 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2235 hr
= IDirectDraw_SetDisplayMode(ddraw
, surface_desc
.dwWidth
, surface_desc
.dwHeight
,
2236 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
);
2237 ok(SUCCEEDED(hr
), "SetDisplayMode failed, hr %#x.\n", hr
);
2239 GetWindowRect(window
, &s
);
2240 ok(EqualRect(&r
, &s
), "Expected %s, got %s.\n", wine_dbgstr_rect(&r
), wine_dbgstr_rect(&s
));
2242 ref
= IDirectDraw_Release(ddraw
);
2243 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2245 DestroyWindow(window
);
2248 static SIZE screen_size
;
2250 static LRESULT CALLBACK
mode_set_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
2252 if (message
== WM_SIZE
)
2254 screen_size
.cx
= GetSystemMetrics(SM_CXSCREEN
);
2255 screen_size
.cy
= GetSystemMetrics(SM_CYSCREEN
);
2258 return test_proc(hwnd
, message
, wparam
, lparam
);
2261 struct test_coop_level_mode_set_enum_param
2263 DWORD ddraw_width
, ddraw_height
, user32_width
, user32_height
;
2266 static HRESULT CALLBACK
test_coop_level_mode_set_enum_cb(DDSURFACEDESC
*surface_desc
, void *context
)
2268 struct test_coop_level_mode_set_enum_param
*param
= context
;
2270 if (U1(surface_desc
->ddpfPixelFormat
).dwRGBBitCount
!= registry_mode
.dmBitsPerPel
)
2271 return DDENUMRET_OK
;
2272 if (surface_desc
->dwWidth
== registry_mode
.dmPelsWidth
2273 && surface_desc
->dwHeight
== registry_mode
.dmPelsHeight
)
2274 return DDENUMRET_OK
;
2276 if (!param
->ddraw_width
)
2278 param
->ddraw_width
= surface_desc
->dwWidth
;
2279 param
->ddraw_height
= surface_desc
->dwHeight
;
2280 return DDENUMRET_OK
;
2282 if (surface_desc
->dwWidth
== param
->ddraw_width
&& surface_desc
->dwHeight
== param
->ddraw_height
)
2283 return DDENUMRET_OK
;
2285 param
->user32_width
= surface_desc
->dwWidth
;
2286 param
->user32_height
= surface_desc
->dwHeight
;
2287 return DDENUMRET_CANCEL
;
2290 static void test_coop_level_mode_set(void)
2292 IDirectDrawSurface
*primary
;
2293 RECT registry_rect
, ddraw_rect
, user32_rect
, r
;
2301 struct test_coop_level_mode_set_enum_param param
;
2306 static const struct message exclusive_messages
[] =
2308 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2309 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2310 {WM_SIZE
, FALSE
, 0},
2311 {WM_DISPLAYCHANGE
, FALSE
, 0},
2314 static const struct message exclusive_focus_loss_messages
[] =
2316 {WM_ACTIVATE
, TRUE
, WA_INACTIVE
},
2317 {WM_DISPLAYCHANGE
, FALSE
, 0},
2318 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2319 /* Like d3d8 and d3d9 ddraw seems to use SW_SHOWMINIMIZED instead of
2320 * SW_MINIMIZED, causing a recursive window activation that does not
2321 * produce the same result in Wine yet. Ignore the difference for now.
2322 * {WM_ACTIVATE, TRUE, 0x200000 | WA_ACTIVE}, */
2323 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2324 {WM_MOVE
, FALSE
, 0},
2325 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2326 {WM_ACTIVATEAPP
, TRUE
, FALSE
},
2329 static const struct message exclusive_focus_restore_messages
[] =
2331 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* From the ShowWindow(SW_RESTORE). */
2332 {WM_WINDOWPOSCHANGING
, FALSE
, 0}, /* Generated by ddraw, matches d3d9 behavior. */
2333 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching previous message. */
2334 {WM_SIZE
, FALSE
, 0}, /* DefWindowProc. */
2335 {WM_DISPLAYCHANGE
, FALSE
, 0}, /* Ddraw restores mode. */
2336 /* Native redundantly sets the window size here. */
2337 {WM_ACTIVATEAPP
, TRUE
, TRUE
}, /* End of ddraw's hooks. */
2338 {WM_WINDOWPOSCHANGED
, FALSE
, 0}, /* Matching the one from ShowWindow. */
2339 {WM_MOVE
, FALSE
, 0}, /* DefWindowProc. */
2340 {WM_SIZE
, TRUE
, SIZE_RESTORED
}, /* DefWindowProc. */
2343 static const struct message sc_restore_messages
[] =
2345 {WM_SYSCOMMAND
, TRUE
, SC_RESTORE
},
2346 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2347 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2348 {WM_SIZE
, TRUE
, SIZE_RESTORED
},
2351 static const struct message sc_minimize_messages
[] =
2353 {WM_SYSCOMMAND
, TRUE
, SC_MINIMIZE
},
2354 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2355 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2356 {WM_SIZE
, TRUE
, SIZE_MINIMIZED
},
2359 static const struct message sc_maximize_messages
[] =
2361 {WM_SYSCOMMAND
, TRUE
, SC_MAXIMIZE
},
2362 {WM_WINDOWPOSCHANGING
, FALSE
, 0},
2363 {WM_WINDOWPOSCHANGED
, FALSE
, 0},
2364 {WM_SIZE
, TRUE
, SIZE_MAXIMIZED
},
2368 static const struct message normal_messages
[] =
2370 {WM_DISPLAYCHANGE
, FALSE
, 0},
2374 ddraw
= create_ddraw();
2375 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2377 memset(¶m
, 0, sizeof(param
));
2378 hr
= IDirectDraw_EnumDisplayModes(ddraw
, 0, NULL
, ¶m
, test_coop_level_mode_set_enum_cb
);
2379 ok(SUCCEEDED(hr
), "Failed to enumerate display mode, hr %#x.\n", hr
);
2380 ref
= IDirectDraw_Release(ddraw
);
2381 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2383 if (!param
.user32_height
)
2385 skip("Fewer than 3 different modes supported, skipping mode restore test.\n");
2389 SetRect(®istry_rect
, 0, 0, registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
);
2390 SetRect(&ddraw_rect
, 0, 0, param
.ddraw_width
, param
.ddraw_height
);
2391 SetRect(&user32_rect
, 0, 0, param
.user32_width
, param
.user32_height
);
2393 memset(&devmode
, 0, sizeof(devmode
));
2394 devmode
.dmSize
= sizeof(devmode
);
2395 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2396 devmode
.dmPelsWidth
= param
.user32_width
;
2397 devmode
.dmPelsHeight
= param
.user32_height
;
2398 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2399 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2401 ddraw
= create_ddraw();
2402 ok(!!ddraw
, "Failed to create a ddraw object.\n");
2404 wc
.lpfnWndProc
= mode_set_proc
;
2405 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
2406 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
2408 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2409 0, 0, 100, 100, 0, 0, 0, 0);
2411 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2412 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2414 GetWindowRect(window
, &r
);
2415 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2416 wine_dbgstr_rect(&r
));
2418 memset(&ddsd
, 0, sizeof(ddsd
));
2419 ddsd
.dwSize
= sizeof(ddsd
);
2420 ddsd
.dwFlags
= DDSD_CAPS
;
2421 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2423 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2424 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2425 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2426 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2427 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2428 param
.user32_width
, ddsd
.dwWidth
);
2429 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2430 param
.user32_height
, ddsd
.dwHeight
);
2432 GetWindowRect(window
, &r
);
2433 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2434 wine_dbgstr_rect(&r
));
2436 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2437 expect_messages
= exclusive_messages
;
2441 hr
= IDirectDrawSurface_IsLost(primary
);
2442 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2443 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2444 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2445 hr
= IDirectDrawSurface_IsLost(primary
);
2446 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2448 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2449 expect_messages
= NULL
;
2450 ok(screen_size
.cx
== param
.ddraw_width
&& screen_size
.cy
== param
.ddraw_height
,
2451 "Expected screen size %ux%u, got %ux%u.\n",
2452 param
.ddraw_width
, param
.ddraw_height
, screen_size
.cx
, screen_size
.cy
);
2454 GetWindowRect(window
, &r
);
2455 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2456 wine_dbgstr_rect(&r
));
2458 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2459 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2460 ok(ddsd
.dwWidth
== param
.user32_width
, "Expected surface width %u, got %u.\n",
2461 param
.user32_width
, ddsd
.dwWidth
);
2462 ok(ddsd
.dwHeight
== param
.user32_height
, "Expected surface height %u, got %u.\n",
2463 param
.user32_height
, ddsd
.dwHeight
);
2464 IDirectDrawSurface_Release(primary
);
2466 memset(&ddsd
, 0, sizeof(ddsd
));
2467 ddsd
.dwSize
= sizeof(ddsd
);
2468 ddsd
.dwFlags
= DDSD_CAPS
;
2469 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2471 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2472 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2473 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2474 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2475 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2476 param
.ddraw_width
, ddsd
.dwWidth
);
2477 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2478 param
.ddraw_height
, ddsd
.dwHeight
);
2480 GetWindowRect(window
, &r
);
2481 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2482 wine_dbgstr_rect(&r
));
2484 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2485 expect_messages
= exclusive_messages
;
2489 hr
= IDirectDrawSurface_IsLost(primary
);
2490 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2491 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2492 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2493 hr
= IDirectDrawSurface_IsLost(primary
);
2494 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2496 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2497 expect_messages
= NULL
;
2498 ok(screen_size
.cx
== param
.user32_width
&& screen_size
.cy
== param
.user32_height
,
2499 "Expected screen size %ux%u, got %ux%u.\n",
2500 param
.user32_width
, param
.user32_height
, screen_size
.cx
, screen_size
.cy
);
2502 GetWindowRect(window
, &r
);
2503 ok(EqualRect(&r
, &user32_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&user32_rect
),
2504 wine_dbgstr_rect(&r
));
2506 expect_messages
= exclusive_focus_loss_messages
;
2507 ret
= SetForegroundWindow(GetDesktopWindow());
2508 ok(ret
, "Failed to set foreground window.\n");
2509 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2510 memset(&devmode
, 0, sizeof(devmode
));
2511 devmode
.dmSize
= sizeof(devmode
);
2512 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2513 ok(ret
, "Failed to get display mode.\n");
2514 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2515 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
, "Got unexpect screen size %ux%u.\n",
2516 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2518 expect_messages
= exclusive_focus_restore_messages
;
2519 ShowWindow(window
, SW_RESTORE
);
2520 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2522 GetWindowRect(window
, &r
);
2523 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2524 wine_dbgstr_rect(&r
));
2525 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2526 ok(ret
, "Failed to get display mode.\n");
2527 ok(devmode
.dmPelsWidth
== param
.ddraw_width
2528 && devmode
.dmPelsHeight
== param
.ddraw_height
, "Got unexpect screen size %ux%u.\n",
2529 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2531 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2532 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2533 /* Normally the primary should be restored here. Unfortunately this causes the
2534 * GetSurfaceDesc call after the next display mode change to crash on the Windows 8
2535 * testbot. Another Restore call would presumably avoid the crash, but it also moots
2536 * the point of the GetSurfaceDesc call. */
2538 expect_messages
= sc_minimize_messages
;
2539 SendMessageA(window
, WM_SYSCOMMAND
, SC_MINIMIZE
, 0);
2540 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2541 expect_messages
= NULL
;
2543 expect_messages
= sc_restore_messages
;
2544 SendMessageA(window
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
2545 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2546 expect_messages
= NULL
;
2548 expect_messages
= sc_maximize_messages
;
2549 SendMessageA(window
, WM_SYSCOMMAND
, SC_MAXIMIZE
, 0);
2550 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2551 expect_messages
= NULL
;
2553 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2554 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2556 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2557 expect_messages
= exclusive_messages
;
2561 hr
= IDirectDrawSurface_IsLost(primary
);
2562 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2563 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2564 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2565 hr
= IDirectDrawSurface_IsLost(primary
);
2566 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2568 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2569 expect_messages
= NULL
;
2570 ok(screen_size
.cx
== registry_mode
.dmPelsWidth
2571 && screen_size
.cy
== registry_mode
.dmPelsHeight
,
2572 "Expected screen size %ux%u, got %ux%u.\n",
2573 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
, screen_size
.cx
, screen_size
.cy
);
2575 GetWindowRect(window
, &r
);
2576 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2577 wine_dbgstr_rect(&r
));
2579 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2580 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2581 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2582 param
.ddraw_width
, ddsd
.dwWidth
);
2583 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2584 param
.ddraw_height
, ddsd
.dwHeight
);
2585 IDirectDrawSurface_Release(primary
);
2588 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2589 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2591 memset(&ddsd
, 0, sizeof(ddsd
));
2592 ddsd
.dwSize
= sizeof(ddsd
);
2593 ddsd
.dwFlags
= DDSD_CAPS
;
2594 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2596 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2597 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2598 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2599 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2600 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2601 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2602 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2603 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2605 GetWindowRect(window
, &r
);
2606 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2607 wine_dbgstr_rect(&r
));
2609 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2610 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2612 GetWindowRect(window
, &r
);
2613 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2614 wine_dbgstr_rect(&r
));
2616 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2617 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2618 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2619 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2620 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2621 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2622 IDirectDrawSurface_Release(primary
);
2624 memset(&ddsd
, 0, sizeof(ddsd
));
2625 ddsd
.dwSize
= sizeof(ddsd
);
2626 ddsd
.dwFlags
= DDSD_CAPS
;
2627 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2629 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2630 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2631 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2632 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2633 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2634 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2635 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2636 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2638 GetWindowRect(window
, &r
);
2639 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2640 wine_dbgstr_rect(&r
));
2642 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2643 expect_messages
= normal_messages
;
2647 hr
= IDirectDrawSurface_IsLost(primary
);
2648 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2649 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2650 devmode
.dmPelsWidth
= param
.user32_width
;
2651 devmode
.dmPelsHeight
= param
.user32_height
;
2652 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2653 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2654 hr
= IDirectDrawSurface_IsLost(primary
);
2655 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2657 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2658 expect_messages
= NULL
;
2659 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2661 GetWindowRect(window
, &r
);
2662 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2663 wine_dbgstr_rect(&r
));
2665 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2666 expect_messages
= normal_messages
;
2670 hr
= IDirectDrawSurface_Restore(primary
);
2671 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2672 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2673 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
2675 win_skip("Broken SetDisplayMode(), skipping remaining tests.\n");
2676 IDirectDrawSurface_Release(primary
);
2677 IDirectDraw_Release(ddraw
);
2680 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2681 hr
= IDirectDrawSurface_Restore(primary
);
2682 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2683 hr
= IDirectDrawSurface_IsLost(primary
);
2684 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2686 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2687 expect_messages
= NULL
;
2688 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2690 GetWindowRect(window
, &r
);
2691 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2692 wine_dbgstr_rect(&r
));
2694 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2695 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2696 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2697 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2698 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2699 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2700 IDirectDrawSurface_Release(primary
);
2702 memset(&ddsd
, 0, sizeof(ddsd
));
2703 ddsd
.dwSize
= sizeof(ddsd
);
2704 ddsd
.dwFlags
= DDSD_CAPS
;
2705 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2707 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2708 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2709 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2710 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2711 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2712 param
.ddraw_width
, ddsd
.dwWidth
);
2713 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2714 param
.ddraw_height
, ddsd
.dwHeight
);
2716 GetWindowRect(window
, &r
);
2717 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2718 wine_dbgstr_rect(&r
));
2720 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2721 expect_messages
= normal_messages
;
2725 hr
= IDirectDrawSurface_IsLost(primary
);
2726 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2727 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2728 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2729 hr
= IDirectDrawSurface_IsLost(primary
);
2730 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2732 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2733 expect_messages
= NULL
;
2734 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2736 GetWindowRect(window
, &r
);
2737 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2738 wine_dbgstr_rect(&r
));
2740 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2741 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2742 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2743 param
.ddraw_width
, ddsd
.dwWidth
);
2744 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2745 param
.ddraw_height
, ddsd
.dwHeight
);
2746 IDirectDrawSurface_Release(primary
);
2748 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2749 ok(ret
, "Failed to get display mode.\n");
2750 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2751 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2752 "Expected resolution %ux%u, got %ux%u.\n",
2753 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2754 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2755 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2756 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2758 memset(&ddsd
, 0, sizeof(ddsd
));
2759 ddsd
.dwSize
= sizeof(ddsd
);
2760 ddsd
.dwFlags
= DDSD_CAPS
;
2761 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2763 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2764 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2765 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2766 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2767 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2768 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2769 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2770 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2772 GetWindowRect(window
, &r
);
2773 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2774 wine_dbgstr_rect(&r
));
2776 /* DDSCL_NORMAL | DDSCL_FULLSCREEN behaves the same as just DDSCL_NORMAL.
2777 * Resizing the window on mode changes is a property of DDSCL_EXCLUSIVE,
2778 * not DDSCL_FULLSCREEN. */
2779 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
2780 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2782 GetWindowRect(window
, &r
);
2783 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2784 wine_dbgstr_rect(&r
));
2786 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2787 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2788 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2789 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2790 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2791 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2792 IDirectDrawSurface_Release(primary
);
2794 memset(&ddsd
, 0, sizeof(ddsd
));
2795 ddsd
.dwSize
= sizeof(ddsd
);
2796 ddsd
.dwFlags
= DDSD_CAPS
;
2797 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2799 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2800 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2801 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2802 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2803 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2804 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2805 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2806 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2808 GetWindowRect(window
, &r
);
2809 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2810 wine_dbgstr_rect(&r
));
2812 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2813 expect_messages
= normal_messages
;
2817 hr
= IDirectDrawSurface_IsLost(primary
);
2818 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2819 devmode
.dmFields
= DM_PELSWIDTH
| DM_PELSHEIGHT
;
2820 devmode
.dmPelsWidth
= param
.user32_width
;
2821 devmode
.dmPelsHeight
= param
.user32_height
;
2822 change_ret
= ChangeDisplaySettingsW(&devmode
, CDS_FULLSCREEN
);
2823 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2824 hr
= IDirectDrawSurface_IsLost(primary
);
2825 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2827 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2828 expect_messages
= NULL
;
2829 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2831 GetWindowRect(window
, &r
);
2832 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2833 wine_dbgstr_rect(&r
));
2835 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2836 expect_messages
= normal_messages
;
2840 hr
= IDirectDrawSurface_Restore(primary
);
2841 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2842 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2843 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2844 hr
= IDirectDrawSurface_Restore(primary
);
2845 todo_wine
ok(hr
== DDERR_WRONGMODE
, "Got unexpected hr %#x.\n", hr
);
2846 hr
= IDirectDrawSurface_IsLost(primary
);
2847 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2849 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2850 expect_messages
= NULL
;
2851 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2853 GetWindowRect(window
, &r
);
2854 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2855 wine_dbgstr_rect(&r
));
2857 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2858 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2859 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2860 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2861 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2862 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2863 IDirectDrawSurface_Release(primary
);
2865 memset(&ddsd
, 0, sizeof(ddsd
));
2866 ddsd
.dwSize
= sizeof(ddsd
);
2867 ddsd
.dwFlags
= DDSD_CAPS
;
2868 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2870 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2871 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2872 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2873 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2874 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2875 param
.ddraw_width
, ddsd
.dwWidth
);
2876 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2877 param
.ddraw_height
, ddsd
.dwHeight
);
2879 GetWindowRect(window
, &r
);
2880 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2881 wine_dbgstr_rect(&r
));
2883 PeekMessageA(&msg
, 0, 0, 0, PM_NOREMOVE
);
2884 expect_messages
= normal_messages
;
2888 hr
= IDirectDrawSurface_IsLost(primary
);
2889 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
2890 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2891 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2892 hr
= IDirectDrawSurface_IsLost(primary
);
2893 todo_wine
ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
2895 ok(!expect_messages
->message
, "Expected message %#x, but didn't receive it.\n", expect_messages
->message
);
2896 expect_messages
= NULL
;
2897 ok(!screen_size
.cx
&& !screen_size
.cy
, "Got unexpected screen size %ux%u.\n", screen_size
.cx
, screen_size
.cy
);
2899 GetWindowRect(window
, &r
);
2900 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2901 wine_dbgstr_rect(&r
));
2903 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2904 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2905 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2906 param
.ddraw_width
, ddsd
.dwWidth
);
2907 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2908 param
.ddraw_height
, ddsd
.dwHeight
);
2909 IDirectDrawSurface_Release(primary
);
2911 ret
= EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, &devmode
);
2912 ok(ret
, "Failed to get display mode.\n");
2913 ok(devmode
.dmPelsWidth
== registry_mode
.dmPelsWidth
2914 && devmode
.dmPelsHeight
== registry_mode
.dmPelsHeight
,
2915 "Expected resolution %ux%u, got %ux%u.\n",
2916 registry_mode
.dmPelsWidth
, registry_mode
.dmPelsHeight
,
2917 devmode
.dmPelsWidth
, devmode
.dmPelsHeight
);
2918 change_ret
= ChangeDisplaySettingsW(NULL
, CDS_FULLSCREEN
);
2919 ok(change_ret
== DISP_CHANGE_SUCCESSFUL
, "Failed to change display mode, ret %#x.\n", change_ret
);
2921 memset(&ddsd
, 0, sizeof(ddsd
));
2922 ddsd
.dwSize
= sizeof(ddsd
);
2923 ddsd
.dwFlags
= DDSD_CAPS
;
2924 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2926 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2927 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2928 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2929 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2930 ok(ddsd
.dwWidth
== registry_mode
.dmPelsWidth
, "Expected surface width %u, got %u.\n",
2931 registry_mode
.dmPelsWidth
, ddsd
.dwWidth
);
2932 ok(ddsd
.dwHeight
== registry_mode
.dmPelsHeight
, "Expected surface height %u, got %u.\n",
2933 registry_mode
.dmPelsHeight
, ddsd
.dwHeight
);
2934 IDirectDrawSurface_Release(primary
);
2936 GetWindowRect(window
, &r
);
2937 ok(EqualRect(&r
, ®istry_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(®istry_rect
),
2938 wine_dbgstr_rect(&r
));
2940 /* Unlike ddraw2-7, changing from EXCLUSIVE to NORMAL does not restore the resolution */
2941 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
2942 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2943 hr
= set_display_mode(ddraw
, param
.ddraw_width
, param
.ddraw_height
);
2944 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
2946 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
2947 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
2949 memset(&ddsd
, 0, sizeof(ddsd
));
2950 ddsd
.dwSize
= sizeof(ddsd
);
2951 ddsd
.dwFlags
= DDSD_CAPS
;
2952 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
2954 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
2955 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
2956 hr
= IDirectDrawSurface_GetSurfaceDesc(primary
, &ddsd
);
2957 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
2958 ok(ddsd
.dwWidth
== param
.ddraw_width
, "Expected surface width %u, got %u.\n",
2959 param
.ddraw_width
, ddsd
.dwWidth
);
2960 ok(ddsd
.dwHeight
== param
.ddraw_height
, "Expected surface height %u, got %u.\n",
2961 param
.ddraw_height
, ddsd
.dwHeight
);
2962 IDirectDrawSurface_Release(primary
);
2963 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
2964 ok(SUCCEEDED(hr
), "RestoreDisplayMode failed, hr %#x.\n", hr
);
2966 ref
= IDirectDraw_Release(ddraw
);
2967 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
2969 GetWindowRect(window
, &r
);
2970 ok(EqualRect(&r
, &ddraw_rect
), "Expected %s, got %s.\n", wine_dbgstr_rect(&ddraw_rect
),
2971 wine_dbgstr_rect(&r
));
2974 expect_messages
= NULL
;
2975 DestroyWindow(window
);
2976 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
2979 static void test_coop_level_mode_set_multi(void)
2981 IDirectDraw
*ddraw1
, *ddraw2
;
2987 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
2988 0, 0, 100, 100, 0, 0, 0, 0);
2989 ddraw1
= create_ddraw();
2990 ok(!!ddraw1
, "Failed to create a ddraw object.\n");
2992 /* With just a single ddraw object, the display mode is restored on
2994 hr
= set_display_mode(ddraw1
, 800, 600);
2995 if (hr
== DDERR_NOEXCLUSIVEMODE
/* NT4 testbot */)
2997 win_skip("Broken SetDisplayMode(), skipping test.\n");
2998 IDirectDraw_Release(ddraw1
);
2999 DestroyWindow(window
);
3002 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3003 w
= GetSystemMetrics(SM_CXSCREEN
);
3004 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3005 h
= GetSystemMetrics(SM_CYSCREEN
);
3006 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3008 ref
= IDirectDraw_Release(ddraw1
);
3009 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3010 w
= GetSystemMetrics(SM_CXSCREEN
);
3011 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3012 h
= GetSystemMetrics(SM_CYSCREEN
);
3013 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3015 /* When there are multiple ddraw objects, the display mode is restored to
3016 * the initial mode, before the first SetDisplayMode() call. */
3017 ddraw1
= create_ddraw();
3018 hr
= set_display_mode(ddraw1
, 800, 600);
3019 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3020 w
= GetSystemMetrics(SM_CXSCREEN
);
3021 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3022 h
= GetSystemMetrics(SM_CYSCREEN
);
3023 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3025 ddraw2
= create_ddraw();
3026 hr
= set_display_mode(ddraw2
, 640, 480);
3027 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3028 w
= GetSystemMetrics(SM_CXSCREEN
);
3029 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3030 h
= GetSystemMetrics(SM_CYSCREEN
);
3031 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3033 ref
= IDirectDraw_Release(ddraw2
);
3034 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3035 w
= GetSystemMetrics(SM_CXSCREEN
);
3036 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3037 h
= GetSystemMetrics(SM_CYSCREEN
);
3038 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3040 ref
= IDirectDraw_Release(ddraw1
);
3041 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3042 w
= GetSystemMetrics(SM_CXSCREEN
);
3043 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3044 h
= GetSystemMetrics(SM_CYSCREEN
);
3045 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3047 /* Regardless of release ordering. */
3048 ddraw1
= create_ddraw();
3049 hr
= set_display_mode(ddraw1
, 800, 600);
3050 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3051 w
= GetSystemMetrics(SM_CXSCREEN
);
3052 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3053 h
= GetSystemMetrics(SM_CYSCREEN
);
3054 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3056 ddraw2
= create_ddraw();
3057 hr
= set_display_mode(ddraw2
, 640, 480);
3058 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3059 w
= GetSystemMetrics(SM_CXSCREEN
);
3060 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3061 h
= GetSystemMetrics(SM_CYSCREEN
);
3062 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3064 ref
= IDirectDraw_Release(ddraw1
);
3065 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3066 w
= GetSystemMetrics(SM_CXSCREEN
);
3067 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3068 h
= GetSystemMetrics(SM_CYSCREEN
);
3069 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3071 ref
= IDirectDraw_Release(ddraw2
);
3072 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3073 w
= GetSystemMetrics(SM_CXSCREEN
);
3074 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3075 h
= GetSystemMetrics(SM_CYSCREEN
);
3076 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3078 /* But only for ddraw objects that called SetDisplayMode(). */
3079 ddraw1
= create_ddraw();
3080 ddraw2
= create_ddraw();
3081 hr
= set_display_mode(ddraw2
, 640, 480);
3082 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3083 w
= GetSystemMetrics(SM_CXSCREEN
);
3084 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3085 h
= GetSystemMetrics(SM_CYSCREEN
);
3086 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3088 ref
= IDirectDraw_Release(ddraw1
);
3089 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3090 w
= GetSystemMetrics(SM_CXSCREEN
);
3091 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3092 h
= GetSystemMetrics(SM_CYSCREEN
);
3093 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3095 ref
= IDirectDraw_Release(ddraw2
);
3096 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3097 w
= GetSystemMetrics(SM_CXSCREEN
);
3098 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3099 h
= GetSystemMetrics(SM_CYSCREEN
);
3100 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3102 /* If there's a ddraw object that's currently in exclusive mode, it blocks
3103 * restoring the display mode. */
3104 ddraw1
= create_ddraw();
3105 hr
= set_display_mode(ddraw1
, 800, 600);
3106 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3107 w
= GetSystemMetrics(SM_CXSCREEN
);
3108 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3109 h
= GetSystemMetrics(SM_CYSCREEN
);
3110 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3112 ddraw2
= create_ddraw();
3113 hr
= set_display_mode(ddraw2
, 640, 480);
3114 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3115 w
= GetSystemMetrics(SM_CXSCREEN
);
3116 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3117 h
= GetSystemMetrics(SM_CYSCREEN
);
3118 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3120 hr
= IDirectDraw_SetCooperativeLevel(ddraw2
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3121 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3123 ref
= IDirectDraw_Release(ddraw1
);
3124 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3125 w
= GetSystemMetrics(SM_CXSCREEN
);
3126 ok(w
== 640, "Got unexpected screen width %u.\n", w
);
3127 h
= GetSystemMetrics(SM_CYSCREEN
);
3128 ok(h
== 480, "Got unexpected screen height %u.\n", h
);
3130 ref
= IDirectDraw_Release(ddraw2
);
3131 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3132 w
= GetSystemMetrics(SM_CXSCREEN
);
3133 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3134 h
= GetSystemMetrics(SM_CYSCREEN
);
3135 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3137 /* Exclusive mode blocks mode setting on other ddraw objects in general. */
3138 ddraw1
= create_ddraw();
3139 hr
= set_display_mode(ddraw1
, 800, 600);
3140 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
3141 w
= GetSystemMetrics(SM_CXSCREEN
);
3142 ok(w
== 800, "Got unexpected screen width %u.\n", w
);
3143 h
= GetSystemMetrics(SM_CYSCREEN
);
3144 ok(h
== 600, "Got unexpected screen height %u.\n", h
);
3146 hr
= IDirectDraw_SetCooperativeLevel(ddraw1
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3147 ok(SUCCEEDED(hr
), "SetCooperativeLevel failed, hr %#x.\n", hr
);
3149 ddraw2
= create_ddraw();
3150 hr
= set_display_mode(ddraw2
, 640, 480);
3151 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
3153 ref
= IDirectDraw_Release(ddraw1
);
3154 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3155 w
= GetSystemMetrics(SM_CXSCREEN
);
3156 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3157 h
= GetSystemMetrics(SM_CYSCREEN
);
3158 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3160 ref
= IDirectDraw_Release(ddraw2
);
3161 ok(ref
== 0, "The ddraw object was not properly freed: refcount %u.\n", ref
);
3162 w
= GetSystemMetrics(SM_CXSCREEN
);
3163 ok(w
== registry_mode
.dmPelsWidth
, "Got unexpected screen width %u.\n", w
);
3164 h
= GetSystemMetrics(SM_CYSCREEN
);
3165 ok(h
== registry_mode
.dmPelsHeight
, "Got unexpected screen height %u.\n", h
);
3167 DestroyWindow(window
);
3170 static void test_initialize(void)
3176 ddraw
= create_ddraw();
3177 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3179 hr
= IDirectDraw_Initialize(ddraw
, NULL
);
3180 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x.\n", hr
);
3181 IDirectDraw_Release(ddraw
);
3184 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirectDraw
, (void **)&ddraw
);
3185 ok(SUCCEEDED(hr
), "Failed to create IDirectDraw instance, hr %#x.\n", hr
);
3186 hr
= IDirectDraw_QueryInterface(ddraw
, &IID_IDirect3D
, (void **)&d3d
);
3189 /* IDirect3D_Initialize() just returns DDERR_ALREADYINITIALIZED. */
3190 hr
= IDirect3D_Initialize(d3d
, NULL
);
3191 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3192 IDirect3D_Release(d3d
);
3195 skip("D3D interface is not available, skipping test.\n");
3196 hr
= IDirectDraw_Initialize(ddraw
, NULL
);
3197 ok(hr
== DD_OK
, "Initialize returned hr %#x, expected DD_OK.\n", hr
);
3198 hr
= IDirectDraw_Initialize(ddraw
, NULL
);
3199 ok(hr
== DDERR_ALREADYINITIALIZED
, "Initialize returned hr %#x, expected DDERR_ALREADYINITIALIZED.\n", hr
);
3200 IDirectDraw_Release(ddraw
);
3203 if (0) /* This crashes on the W2KPROSP4 testbot. */
3206 hr
= CoCreateInstance(&CLSID_DirectDraw
, NULL
, CLSCTX_INPROC_SERVER
, &IID_IDirect3D
, (void **)&d3d
);
3207 ok(hr
== E_NOINTERFACE
, "CoCreateInstance returned hr %#x, expected E_NOINTERFACE.\n", hr
);
3212 static void test_coop_level_surf_create(void)
3214 IDirectDrawSurface
*surface
;
3219 ddraw
= create_ddraw();
3220 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3222 memset(&ddsd
, 0, sizeof(ddsd
));
3223 ddsd
.dwSize
= sizeof(ddsd
);
3224 ddsd
.dwFlags
= DDSD_CAPS
;
3225 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
3226 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3227 ok(hr
== DDERR_NOCOOPERATIVELEVELSET
, "Surface creation returned hr %#x.\n", hr
);
3229 IDirectDraw_Release(ddraw
);
3232 static void test_coop_level_multi_window(void)
3234 HWND window1
, window2
;
3238 window1
= CreateWindowA("static", "ddraw_test1", WS_OVERLAPPEDWINDOW
,
3239 0, 0, 640, 480, 0, 0, 0, 0);
3240 window2
= CreateWindowA("static", "ddraw_test2", WS_OVERLAPPEDWINDOW
,
3241 0, 0, 640, 480, 0, 0, 0, 0);
3242 ddraw
= create_ddraw();
3243 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3245 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
3246 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3247 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
3248 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3249 ok(IsWindow(window1
), "Window 1 was destroyed.\n");
3250 ok(IsWindow(window2
), "Window 2 was destroyed.\n");
3252 IDirectDraw_Release(ddraw
);
3253 DestroyWindow(window2
);
3254 DestroyWindow(window1
);
3257 static void test_clear_rect_count(void)
3259 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
3260 IDirect3DMaterial
*white
, *red
, *green
, *blue
;
3261 IDirect3DViewport
*viewport
;
3262 IDirect3DDevice
*device
;
3263 IDirectDrawSurface
*rt
;
3269 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3270 0, 0, 640, 480, 0, 0, 0, 0);
3271 ddraw
= create_ddraw();
3272 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3273 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3275 skip("Failed to create a 3D device, skipping test.\n");
3276 IDirectDraw_Release(ddraw
);
3277 DestroyWindow(window
);
3281 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
3282 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
3284 white
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
3285 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
3286 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
3287 blue
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
3288 viewport
= create_viewport(device
, 0, 0, 640, 480);
3290 viewport_set_background(device
, viewport
, white
);
3291 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
3292 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3293 viewport_set_background(device
, viewport
, red
);
3294 hr
= IDirect3DViewport_Clear(viewport
, 0, &clear_rect
, D3DCLEAR_TARGET
);
3295 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3296 viewport_set_background(device
, viewport
, green
);
3297 hr
= IDirect3DViewport_Clear(viewport
, 0, NULL
, D3DCLEAR_TARGET
);
3298 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3299 viewport_set_background(device
, viewport
, blue
);
3300 hr
= IDirect3DViewport_Clear(viewport
, 1, NULL
, D3DCLEAR_TARGET
);
3301 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
3303 color
= get_surface_color(rt
, 320, 240);
3304 ok(compare_color(color
, 0x00ffffff, 1) || broken(compare_color(color
, 0x000000ff, 1)),
3305 "Got unexpected color 0x%08x.\n", color
);
3307 IDirectDrawSurface_Release(rt
);
3308 destroy_viewport(device
, viewport
);
3309 destroy_material(white
);
3310 destroy_material(red
);
3311 destroy_material(green
);
3312 destroy_material(blue
);
3313 IDirect3DDevice_Release(device
);
3314 IDirectDraw_Release(ddraw
);
3315 DestroyWindow(window
);
3324 } activateapp_testdata
;
3326 static LRESULT CALLBACK
activateapp_test_proc(HWND hwnd
, UINT message
, WPARAM wparam
, LPARAM lparam
)
3328 if (message
== WM_ACTIVATEAPP
)
3330 if (activateapp_testdata
.ddraw
)
3333 activateapp_testdata
.received
= FALSE
;
3334 hr
= IDirectDraw_SetCooperativeLevel(activateapp_testdata
.ddraw
,
3335 activateapp_testdata
.window
, activateapp_testdata
.coop_level
);
3336 ok(SUCCEEDED(hr
), "Recursive SetCooperativeLevel call failed, hr %#x.\n", hr
);
3337 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP during recursive SetCooperativeLevel call.\n");
3339 activateapp_testdata
.received
= TRUE
;
3342 return DefWindowProcA(hwnd
, message
, wparam
, lparam
);
3345 static void test_coop_level_activateapp(void)
3352 IDirectDrawSurface
*surface
;
3354 ddraw
= create_ddraw();
3355 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3357 wc
.lpfnWndProc
= activateapp_test_proc
;
3358 wc
.lpszClassName
= "ddraw_test_wndproc_wc";
3359 ok(RegisterClassA(&wc
), "Failed to register window class.\n");
3361 window
= CreateWindowA("ddraw_test_wndproc_wc", "ddraw_test",
3362 WS_MAXIMIZE
| WS_CAPTION
, 0, 0, 640, 480, 0, 0, 0, 0);
3364 /* Exclusive with window already active. */
3365 SetForegroundWindow(window
);
3366 activateapp_testdata
.received
= FALSE
;
3367 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3368 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3369 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP although window was already active.\n");
3370 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3371 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3373 /* Exclusive with window not active. */
3374 SetForegroundWindow(GetDesktopWindow());
3375 activateapp_testdata
.received
= FALSE
;
3376 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3377 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3378 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3379 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3380 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3382 /* Normal with window not active, then exclusive with the same window. */
3383 SetForegroundWindow(GetDesktopWindow());
3384 activateapp_testdata
.received
= FALSE
;
3385 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
3386 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3387 ok(!activateapp_testdata
.received
, "Received WM_ACTIVATEAPP when setting DDSCL_NORMAL.\n");
3388 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3389 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3390 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3391 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3392 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3394 /* Recursive set of DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN. */
3395 SetForegroundWindow(GetDesktopWindow());
3396 activateapp_testdata
.received
= FALSE
;
3397 activateapp_testdata
.ddraw
= ddraw
;
3398 activateapp_testdata
.window
= window
;
3399 activateapp_testdata
.coop_level
= DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
;
3400 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3401 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3402 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3403 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3404 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3406 /* The recursive call seems to have some bad effect on native ddraw, despite (apparently)
3407 * succeeding. Another switch to exclusive and back to normal is needed to release the
3408 * window properly. Without doing this, SetCooperativeLevel(EXCLUSIVE) will not send
3409 * WM_ACTIVATEAPP messages. */
3410 activateapp_testdata
.ddraw
= NULL
;
3411 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3412 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3413 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3414 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3416 /* Setting DDSCL_NORMAL with recursive invocation. */
3417 SetForegroundWindow(GetDesktopWindow());
3418 activateapp_testdata
.received
= FALSE
;
3419 activateapp_testdata
.ddraw
= ddraw
;
3420 activateapp_testdata
.window
= window
;
3421 activateapp_testdata
.coop_level
= DDSCL_NORMAL
;
3422 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3423 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3424 ok(activateapp_testdata
.received
, "Expected WM_ACTIVATEAPP, but did not receive it.\n");
3426 /* DDraw is in exlusive mode now. */
3427 memset(&ddsd
, 0, sizeof(ddsd
));
3428 ddsd
.dwSize
= sizeof(ddsd
);
3429 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
3430 ddsd
.dwBackBufferCount
= 1;
3431 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
3432 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3433 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
3434 IDirectDrawSurface_Release(surface
);
3436 /* Recover again, just to be sure. */
3437 activateapp_testdata
.ddraw
= NULL
;
3438 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
3439 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3440 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, NULL
, DDSCL_NORMAL
);
3441 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3443 DestroyWindow(window
);
3444 UnregisterClassA("ddraw_test_wndproc_wc", GetModuleHandleA(NULL
));
3445 IDirectDraw_Release(ddraw
);
3448 struct format_support_check
3450 const DDPIXELFORMAT
*format
;
3454 static HRESULT WINAPI
test_unsupported_formats_cb(DDSURFACEDESC
*desc
, void *ctx
)
3456 struct format_support_check
*format
= ctx
;
3458 if (!memcmp(format
->format
, &desc
->ddpfPixelFormat
, sizeof(*format
->format
)))
3460 format
->supported
= TRUE
;
3461 return DDENUMRET_CANCEL
;
3464 return DDENUMRET_OK
;
3467 static void test_unsupported_formats(void)
3470 BOOL expect_success
;
3473 IDirect3DDevice
*device
;
3474 IDirectDrawSurface
*surface
;
3477 DWORD expected_caps
;
3488 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
3489 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
3495 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
3496 {8 }, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}
3500 static const DWORD caps
[] = {0, DDSCAPS_SYSTEMMEMORY
, DDSCAPS_VIDEOMEMORY
};
3502 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3503 0, 0, 640, 480, 0, 0, 0, 0);
3504 ddraw
= create_ddraw();
3505 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3506 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3508 skip("Failed to create a 3D device, skipping test.\n");
3509 IDirectDraw_Release(ddraw
);
3510 DestroyWindow(window
);
3514 for (i
= 0; i
< sizeof(formats
) / sizeof(*formats
); i
++)
3516 struct format_support_check check
= {&formats
[i
].fmt
, FALSE
};
3517 hr
= IDirect3DDevice_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
3518 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
3520 for (j
= 0; j
< sizeof(caps
) / sizeof(*caps
); j
++)
3522 memset(&ddsd
, 0, sizeof(ddsd
));
3523 ddsd
.dwSize
= sizeof(ddsd
);
3524 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
3525 ddsd
.ddpfPixelFormat
= formats
[i
].fmt
;
3528 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| caps
[j
];
3530 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
&& !check
.supported
)
3531 expect_success
= FALSE
;
3533 expect_success
= TRUE
;
3535 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
3536 ok(SUCCEEDED(hr
) == expect_success
,
3537 "Got unexpected hr %#x for format %s, caps %#x, expected %s.\n",
3538 hr
, formats
[i
].name
, caps
[j
], expect_success
? "success" : "failure");
3542 memset(&ddsd
, 0, sizeof(ddsd
));
3543 ddsd
.dwSize
= sizeof(ddsd
);
3544 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &ddsd
);
3545 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
3547 if (caps
[j
] & DDSCAPS_VIDEOMEMORY
)
3548 expected_caps
= DDSCAPS_VIDEOMEMORY
;
3549 else if (caps
[j
] & DDSCAPS_SYSTEMMEMORY
)
3550 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
3551 else if (check
.supported
)
3552 expected_caps
= DDSCAPS_VIDEOMEMORY
;
3554 expected_caps
= DDSCAPS_SYSTEMMEMORY
;
3556 ok(ddsd
.ddsCaps
.dwCaps
& expected_caps
,
3557 "Expected capability %#x, format %s, input cap %#x.\n",
3558 expected_caps
, formats
[i
].name
, caps
[j
]);
3560 IDirectDrawSurface_Release(surface
);
3564 IDirect3DDevice_Release(device
);
3565 IDirectDraw_Release(ddraw
);
3566 DestroyWindow(window
);
3569 static void test_rt_caps(void)
3571 PALETTEENTRY palette_entries
[256];
3572 IDirectDrawPalette
*palette
;
3573 IDirect3DDevice
*device
;
3581 static const DDPIXELFORMAT p8_fmt
=
3583 sizeof(DDPIXELFORMAT
), DDPF_PALETTEINDEXED8
| DDPF_RGB
, 0,
3584 {8}, {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000},
3589 const DDPIXELFORMAT
*pf
;
3592 HRESULT create_device_hr
;
3593 BOOL create_may_fail
;
3599 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
3600 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3606 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
3607 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3613 DDSCAPS_OFFSCREENPLAIN
,
3614 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3620 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3621 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3622 D3DERR_SURFACENOTINVIDMEM
,
3627 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
3628 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
3634 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
,
3635 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3642 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3649 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3655 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3656 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3657 D3DERR_SURFACENOTINVIDMEM
,
3662 DDSCAPS_SYSTEMMEMORY
,
3663 DDSCAPS_SYSTEMMEMORY
,
3670 DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3676 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
3677 ~0U /* AMD r200 */ ,
3678 DDERR_NOPALETTEATTACHED
,
3683 DDSCAPS_OFFSCREENPLAIN
,
3684 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
,
3690 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3691 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
,
3692 DDERR_NOPALETTEATTACHED
,
3697 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
3698 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
3704 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
,
3705 DDSCAPS_3DDEVICE
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_ZBUFFER
| DDSCAPS_LOCALVIDMEM
,
3707 TRUE
/* AMD Evergreen */,
3711 DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
3712 ~0U /* AMD Evergreen */,
3719 ~0U /* AMD Evergreen */,
3725 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
3726 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_3DDEVICE
| DDSCAPS_ZBUFFER
,
3728 TRUE
/* Nvidia Kepler */,
3732 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
3733 DDSCAPS_SYSTEMMEMORY
| DDSCAPS_ZBUFFER
,
3735 TRUE
/* Nvidia Kepler */,
3739 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3740 0, 0, 640, 480, 0, 0, 0, 0);
3741 ddraw
= create_ddraw();
3742 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3743 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
3745 skip("Failed to create a 3D device, skipping test.\n");
3746 IDirectDraw_Release(ddraw
);
3747 DestroyWindow(window
);
3750 z_depth
= get_device_z_depth(device
);
3751 ok(!!z_depth
, "Failed to get device z depth.\n");
3752 IDirect3DDevice_Release(device
);
3754 memset(palette_entries
, 0, sizeof(palette_entries
));
3755 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
3756 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
3758 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
3760 IDirectDrawSurface
*surface
;
3761 DDSURFACEDESC surface_desc
;
3762 IDirect3DDevice
*device
;
3764 memset(&surface_desc
, 0, sizeof(surface_desc
));
3765 surface_desc
.dwSize
= sizeof(surface_desc
);
3766 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
3767 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
3768 if (test_data
[i
].pf
)
3770 surface_desc
.dwFlags
|= DDSD_PIXELFORMAT
;
3771 surface_desc
.ddpfPixelFormat
= *test_data
[i
].pf
;
3773 if (test_data
[i
].caps_in
& DDSCAPS_ZBUFFER
)
3775 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
3776 U2(surface_desc
).dwZBufferBitDepth
= z_depth
;
3778 surface_desc
.dwWidth
= 640;
3779 surface_desc
.dwHeight
= 480;
3780 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
3781 ok(SUCCEEDED(hr
) || broken(test_data
[i
].create_may_fail
),
3782 "Test %u: Failed to create surface with caps %#x, hr %#x.\n",
3783 i
, test_data
[i
].caps_in
, hr
);
3787 memset(&surface_desc
, 0, sizeof(surface_desc
));
3788 surface_desc
.dwSize
= sizeof(surface_desc
);
3789 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
3790 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
3791 ok(test_data
[i
].caps_out
== ~0U || surface_desc
.ddsCaps
.dwCaps
== test_data
[i
].caps_out
,
3792 "Test %u: Got unexpected caps %#x, expected %#x.\n",
3793 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
3795 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DHALDevice
, (void **)&device
);
3796 ok(hr
== test_data
[i
].create_device_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n",
3797 i
, hr
, test_data
[i
].create_device_hr
);
3798 if (hr
== DDERR_NOPALETTEATTACHED
)
3800 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
3801 ok(SUCCEEDED(hr
), "Test %u: Failed to set palette, hr %#x.\n", i
, hr
);
3802 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DHALDevice
, (void **)&device
);
3803 if (surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_VIDEOMEMORY
)
3804 ok(hr
== DDERR_INVALIDPIXELFORMAT
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
3806 ok(hr
== D3DERR_SURFACENOTINVIDMEM
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
3810 refcount
= IDirect3DDevice_Release(device
);
3811 ok(refcount
== 1, "Test %u: Got unexpected refcount %u.\n", i
, refcount
);
3814 refcount
= IDirectDrawSurface_Release(surface
);
3815 ok(refcount
== 0, "Test %u: The surface was not properly freed, refcount %u.\n", i
, refcount
);
3818 IDirectDrawPalette_Release(palette
);
3819 refcount
= IDirectDraw_Release(ddraw
);
3820 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
3821 DestroyWindow(window
);
3824 static void test_primary_caps(void)
3826 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
3827 IDirectDrawSurface
*surface
;
3828 DDSURFACEDESC surface_desc
;
3839 DWORD back_buffer_count
;
3847 DDSCAPS_PRIMARYSURFACE
,
3850 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
,
3854 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_TEXTURE
,
3861 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
3864 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
,
3868 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_BACKBUFFER
,
3875 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FLIP
,
3882 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
,
3889 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
3896 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
3903 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
3905 DDERR_NOEXCLUSIVEMODE
,
3909 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
3910 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
3916 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
3917 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
,
3920 DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
| DDSCAPS_FLIP
| DDSCAPS_COMPLEX
,
3923 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
3924 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_FRONTBUFFER
,
3930 DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
,
3931 DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| DDSCAPS_BACKBUFFER
,
3938 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
3939 0, 0, 640, 480, 0, 0, 0, 0);
3940 ddraw
= create_ddraw();
3941 ok(!!ddraw
, "Failed to create a ddraw object.\n");
3943 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
3945 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, test_data
[i
].coop_level
);
3946 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
3948 memset(&surface_desc
, 0, sizeof(surface_desc
));
3949 surface_desc
.dwSize
= sizeof(surface_desc
);
3950 surface_desc
.dwFlags
= DDSD_CAPS
;
3951 if (test_data
[i
].back_buffer_count
!= ~0u)
3952 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
3953 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps_in
;
3954 surface_desc
.dwBackBufferCount
= test_data
[i
].back_buffer_count
;
3955 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
3956 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
3960 memset(&surface_desc
, 0, sizeof(surface_desc
));
3961 surface_desc
.dwSize
= sizeof(surface_desc
);
3962 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
3963 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
3964 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == test_data
[i
].caps_out
,
3965 "Test %u: Got unexpected caps %#x, expected %#x.\n",
3966 i
, surface_desc
.ddsCaps
.dwCaps
, test_data
[i
].caps_out
);
3968 IDirectDrawSurface_Release(surface
);
3971 refcount
= IDirectDraw_Release(ddraw
);
3972 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
3973 DestroyWindow(window
);
3976 static void test_surface_lock(void)
3979 IDirectDrawSurface
*surface
;
3980 IDirect3DDevice
*device
;
3995 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
3996 "videomemory offscreenplain"
3999 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
4000 "systemmemory offscreenplain"
4003 DDSCAPS_PRIMARYSURFACE
,
4007 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
4008 "videomemory texture"
4011 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
4012 "systemmemory texture"
4015 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
,
4024 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4025 0, 0, 640, 480, 0, 0, 0, 0);
4026 ddraw
= create_ddraw();
4027 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4028 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4030 skip("Failed to create a 3D device, skipping test.\n");
4031 IDirectDraw_Release(ddraw
);
4032 DestroyWindow(window
);
4035 z_depth
= get_device_z_depth(device
);
4036 ok(!!z_depth
, "Failed to get device z depth.\n");
4037 IDirect3DDevice_Release(device
);
4039 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4041 memset(&ddsd
, 0, sizeof(ddsd
));
4042 ddsd
.dwSize
= sizeof(ddsd
);
4043 ddsd
.dwFlags
= DDSD_CAPS
;
4044 if (!(tests
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4046 ddsd
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4050 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
4052 ddsd
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
4053 U2(ddsd
).dwZBufferBitDepth
= z_depth
;
4055 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4057 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4058 ok(SUCCEEDED(hr
), "Failed to create surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4060 memset(&ddsd
, 0, sizeof(ddsd
));
4061 ddsd
.dwSize
= sizeof(ddsd
);
4062 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4063 ok(SUCCEEDED(hr
), "Failed to lock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4066 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4067 ok(SUCCEEDED(hr
), "Failed to unlock surface, type %s, hr %#x.\n", tests
[i
].name
, hr
);
4070 IDirectDrawSurface_Release(surface
);
4073 refcount
= IDirectDraw_Release(ddraw
);
4074 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4075 DestroyWindow(window
);
4078 static void test_surface_discard(void)
4081 IDirect3DDevice
*device
;
4085 IDirectDrawSurface
*surface
, *target
;
4094 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4095 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4096 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, TRUE
},
4097 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, FALSE
},
4101 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4102 0, 0, 640, 480, 0, 0, 0, 0);
4103 ddraw
= create_ddraw();
4104 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4105 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
4107 skip("Failed to create a 3D device, skipping test.\n");
4108 IDirectDraw_Release(ddraw
);
4109 DestroyWindow(window
);
4113 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&target
);
4114 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
4116 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
4120 memset(&ddsd
, 0, sizeof(ddsd
));
4121 ddsd
.dwSize
= sizeof(ddsd
);
4122 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4123 ddsd
.ddsCaps
.dwCaps
= tests
[i
].caps
;
4126 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4129 skip("Failed to create surface, skipping.\n");
4133 memset(&ddsd
, 0, sizeof(ddsd
));
4134 ddsd
.dwSize
= sizeof(ddsd
);
4135 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_WAIT
, NULL
);
4136 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4137 addr
= ddsd
.lpSurface
;
4138 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4139 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4141 memset(&ddsd
, 0, sizeof(ddsd
));
4142 ddsd
.dwSize
= sizeof(ddsd
);
4143 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4144 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4145 discarded
= ddsd
.lpSurface
!= addr
;
4146 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4147 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4149 hr
= IDirectDrawSurface_Blt(target
, NULL
, surface
, NULL
, DDBLT_WAIT
, NULL
);
4150 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
4152 memset(&ddsd
, 0, sizeof(ddsd
));
4153 ddsd
.dwSize
= sizeof(ddsd
);
4154 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &ddsd
, DDLOCK_DISCARDCONTENTS
| DDLOCK_WAIT
, NULL
);
4155 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
4156 discarded
|= ddsd
.lpSurface
!= addr
;
4157 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
4158 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
4160 IDirectDrawSurface_Release(surface
);
4162 /* Windows 7 reliably changes the address of surfaces that are discardable (Nvidia Kepler,
4163 * AMD r500, evergreen). Windows XP, at least on AMD r200, never changes the pointer. */
4164 ok(!discarded
|| tests
[i
].discard
, "Expected surface not to be discarded, case %u\n", i
);
4167 IDirectDrawSurface_Release(target
);
4168 IDirect3DDevice_Release(device
);
4169 IDirectDraw_Release(ddraw
);
4170 DestroyWindow(window
);
4173 static void test_flip(void)
4175 const DWORD placement
= DDSCAPS_LOCALVIDMEM
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_SYSTEMMEMORY
;
4176 IDirectDrawSurface
*frontbuffer
, *backbuffer1
, *backbuffer2
, *backbuffer3
, *surface
;
4177 DDSCAPS caps
= {DDSCAPS_FLIP
};
4178 DDSURFACEDESC surface_desc
;
4179 BOOL sysmem_primary
;
4181 DWORD expected_caps
;
4196 {"PRIMARYSURFACE", DDSCAPS_PRIMARYSURFACE
},
4197 {"OFFSCREENPLAIN", DDSCAPS_OFFSCREENPLAIN
},
4198 {"TEXTURE", DDSCAPS_TEXTURE
},
4201 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4202 0, 0, 640, 480, 0, 0, 0, 0);
4203 ddraw
= create_ddraw();
4204 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4206 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4207 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4209 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
4211 memset(&surface_desc
, 0, sizeof(surface_desc
));
4212 surface_desc
.dwSize
= sizeof(surface_desc
);
4213 surface_desc
.dwFlags
= DDSD_CAPS
;
4214 if (!(test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
))
4215 surface_desc
.dwFlags
|= DDSD_WIDTH
| DDSD_HEIGHT
;
4216 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
4217 surface_desc
.dwWidth
= 512;
4218 surface_desc
.dwHeight
= 512;
4219 surface_desc
.dwBackBufferCount
= 3;
4220 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4221 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4223 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_FLIP
;
4224 surface_desc
.dwFlags
|= DDSD_BACKBUFFERCOUNT
;
4225 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4226 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4228 surface_desc
.ddsCaps
.dwCaps
&= ~DDSCAPS_COMPLEX
;
4229 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_FLIP
;
4230 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4231 ok(hr
== DDERR_INVALIDCAPS
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4233 surface_desc
.ddsCaps
.dwCaps
|= DDSCAPS_COMPLEX
;
4234 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &frontbuffer
, NULL
);
4235 todo_wine_if(test_data
[i
].caps
& DDSCAPS_TEXTURE
)
4236 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
4240 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
4241 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
4242 hr
= IDirectDrawSurface_IsLost(frontbuffer
);
4243 ok(hr
== DD_OK
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4244 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4245 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
4246 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4248 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4249 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4250 ok(SUCCEEDED(hr
), "%s: Failed to set cooperative level, hr %#x.\n", test_data
[i
].name
, hr
);
4251 hr
= IDirectDrawSurface_IsLost(frontbuffer
);
4252 todo_wine
ok(hr
== DDERR_SURFACELOST
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4253 hr
= restore_surfaces(ddraw
);
4254 ok(SUCCEEDED(hr
), "%s: Failed to restore surfaces, hr %#x.\n", test_data
[i
].name
, hr
);
4256 memset(&surface_desc
, 0, sizeof(surface_desc
));
4257 surface_desc
.dwSize
= sizeof(surface_desc
);
4258 hr
= IDirectDrawSurface_GetSurfaceDesc(frontbuffer
, &surface_desc
);
4259 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4260 expected_caps
= DDSCAPS_FRONTBUFFER
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
| test_data
[i
].caps
;
4261 if (test_data
[i
].caps
& DDSCAPS_PRIMARYSURFACE
)
4262 expected_caps
|= DDSCAPS_VISIBLE
;
4263 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4264 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4265 sysmem_primary
= surface_desc
.ddsCaps
.dwCaps
& DDSCAPS_SYSTEMMEMORY
;
4267 hr
= IDirectDrawSurface_GetAttachedSurface(frontbuffer
, &caps
, &backbuffer1
);
4268 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4269 memset(&surface_desc
, 0, sizeof(surface_desc
));
4270 surface_desc
.dwSize
= sizeof(surface_desc
);
4271 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer1
, &surface_desc
);
4272 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4273 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4274 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4275 expected_caps
&= ~(DDSCAPS_VISIBLE
| DDSCAPS_PRIMARYSURFACE
| DDSCAPS_FRONTBUFFER
);
4276 expected_caps
|= DDSCAPS_BACKBUFFER
;
4277 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4278 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4280 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer1
, &caps
, &backbuffer2
);
4281 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4282 memset(&surface_desc
, 0, sizeof(surface_desc
));
4283 surface_desc
.dwSize
= sizeof(surface_desc
);
4284 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer2
, &surface_desc
);
4285 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4286 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4287 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4288 expected_caps
&= ~DDSCAPS_BACKBUFFER
;
4289 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4290 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4292 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer2
, &caps
, &backbuffer3
);
4293 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4294 memset(&surface_desc
, 0, sizeof(surface_desc
));
4295 surface_desc
.dwSize
= sizeof(surface_desc
);
4296 hr
= IDirectDrawSurface_GetSurfaceDesc(backbuffer3
, &surface_desc
);
4297 ok(SUCCEEDED(hr
), "%s: Failed to get surface desc, hr %#x.\n", test_data
[i
].name
, hr
);
4298 ok(!surface_desc
.dwBackBufferCount
, "%s: Got unexpected back buffer count %u.\n",
4299 test_data
[i
].name
, surface_desc
.dwBackBufferCount
);
4300 ok((surface_desc
.ddsCaps
.dwCaps
& ~placement
) == expected_caps
,
4301 "%s: Got unexpected caps %#x.\n", test_data
[i
].name
, surface_desc
.ddsCaps
.dwCaps
);
4303 hr
= IDirectDrawSurface_GetAttachedSurface(backbuffer3
, &caps
, &surface
);
4304 ok(SUCCEEDED(hr
), "%s: Failed to get attached surface, hr %#x.\n", test_data
[i
].name
, hr
);
4305 ok(surface
== frontbuffer
, "%s: Got unexpected surface %p, expected %p.\n",
4306 test_data
[i
].name
, surface
, frontbuffer
);
4307 IDirectDrawSurface_Release(surface
);
4309 memset(&surface_desc
, 0, sizeof(surface_desc
));
4310 surface_desc
.dwSize
= sizeof(surface_desc
);
4311 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4312 surface_desc
.ddsCaps
.dwCaps
= 0;
4313 surface_desc
.dwWidth
= 640;
4314 surface_desc
.dwHeight
= 480;
4315 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
4316 ok(SUCCEEDED(hr
), "%s: Failed to create surface, hr %#x.\n", test_data
[i
].name
, hr
);
4317 hr
= IDirectDrawSurface_Flip(frontbuffer
, surface
, DDFLIP_WAIT
);
4318 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4319 IDirectDrawSurface_Release(surface
);
4321 hr
= IDirectDrawSurface_Flip(frontbuffer
, frontbuffer
, DDFLIP_WAIT
);
4322 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4323 hr
= IDirectDrawSurface_Flip(backbuffer1
, NULL
, DDFLIP_WAIT
);
4324 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4325 hr
= IDirectDrawSurface_Flip(backbuffer2
, NULL
, DDFLIP_WAIT
);
4326 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4327 hr
= IDirectDrawSurface_Flip(backbuffer3
, NULL
, DDFLIP_WAIT
);
4328 ok(hr
== DDERR_NOTFLIPPABLE
, "%s: Got unexpected hr %#x.\n", test_data
[i
].name
, hr
);
4330 memset(&fx
, 0, sizeof(fx
));
4331 fx
.dwSize
= sizeof(fx
);
4332 U5(fx
).dwFillColor
= 0xffff0000;
4333 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4334 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4335 U5(fx
).dwFillColor
= 0xff00ff00;
4336 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4337 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4338 U5(fx
).dwFillColor
= 0xff0000ff;
4339 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4340 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4342 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4343 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4344 color
= get_surface_color(backbuffer1
, 320, 240);
4345 /* The testbot seems to just copy the contents of one surface to all the
4346 * others, instead of properly flipping. */
4347 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
4348 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4349 color
= get_surface_color(backbuffer2
, 320, 240);
4350 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4351 U5(fx
).dwFillColor
= 0xffff0000;
4352 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4353 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4355 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4356 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4357 color
= get_surface_color(backbuffer1
, 320, 240);
4358 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
4359 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4360 color
= get_surface_color(backbuffer2
, 320, 240);
4361 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4362 U5(fx
).dwFillColor
= 0xff00ff00;
4363 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4364 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4366 hr
= IDirectDrawSurface_Flip(frontbuffer
, NULL
, DDFLIP_WAIT
);
4367 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4368 color
= get_surface_color(backbuffer1
, 320, 240);
4369 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
4370 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4371 color
= get_surface_color(backbuffer2
, 320, 240);
4372 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4373 U5(fx
).dwFillColor
= 0xff0000ff;
4374 hr
= IDirectDrawSurface_Blt(backbuffer3
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4375 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4377 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer1
, DDFLIP_WAIT
);
4378 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4379 color
= get_surface_color(backbuffer2
, 320, 240);
4380 ok(compare_color(color
, 0x0000ff00, 1) || broken(sysmem_primary
&& compare_color(color
, 0x000000ff, 1)),
4381 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4382 color
= get_surface_color(backbuffer3
, 320, 240);
4383 ok(compare_color(color
, 0x000000ff, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4384 U5(fx
).dwFillColor
= 0xffff0000;
4385 hr
= IDirectDrawSurface_Blt(backbuffer1
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4386 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4388 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer2
, DDFLIP_WAIT
);
4389 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4390 color
= get_surface_color(backbuffer1
, 320, 240);
4391 ok(compare_color(color
, 0x00ff0000, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4392 color
= get_surface_color(backbuffer3
, 320, 240);
4393 ok(compare_color(color
, 0x000000ff, 1) || broken(sysmem_primary
&& compare_color(color
, 0x00ff0000, 1)),
4394 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4395 U5(fx
).dwFillColor
= 0xff00ff00;
4396 hr
= IDirectDrawSurface_Blt(backbuffer2
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4397 ok(SUCCEEDED(hr
), "%s: Failed to fill surface, hr %#x.\n", test_data
[i
].name
, hr
);
4399 hr
= IDirectDrawSurface_Flip(frontbuffer
, backbuffer3
, DDFLIP_WAIT
);
4400 ok(SUCCEEDED(hr
), "%s: Failed to flip, hr %#x.\n", test_data
[i
].name
, hr
);
4401 color
= get_surface_color(backbuffer1
, 320, 240);
4402 ok(compare_color(color
, 0x00ff0000, 1) || broken(sysmem_primary
&& compare_color(color
, 0x0000ff00, 1)),
4403 "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4404 color
= get_surface_color(backbuffer2
, 320, 240);
4405 ok(compare_color(color
, 0x0000ff00, 1), "%s: Got unexpected color 0x%08x.\n", test_data
[i
].name
, color
);
4407 IDirectDrawSurface_Release(backbuffer3
);
4408 IDirectDrawSurface_Release(backbuffer2
);
4409 IDirectDrawSurface_Release(backbuffer1
);
4410 IDirectDrawSurface_Release(frontbuffer
);
4413 refcount
= IDirectDraw_Release(ddraw
);
4414 ok(refcount
== 0, "The ddraw object was not properly freed, refcount %u.\n", refcount
);
4415 DestroyWindow(window
);
4418 static void test_sysmem_overlay(void)
4424 IDirectDrawSurface
*surface
;
4427 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4428 0, 0, 640, 480, 0, 0, 0, 0);
4429 ddraw
= create_ddraw();
4430 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4432 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4433 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4435 memset(&ddsd
, 0, sizeof(ddsd
));
4436 ddsd
.dwSize
= sizeof(ddsd
);
4437 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_PIXELFORMAT
| DDSD_WIDTH
| DDSD_HEIGHT
;
4440 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OVERLAY
;
4441 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
4442 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
4443 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
4444 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
4445 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
4446 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
4447 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
4448 ok(hr
== DDERR_NOOVERLAYHW
, "Got unexpected hr %#x.\n", hr
);
4450 ref
= IDirectDraw_Release(ddraw
);
4451 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
4452 DestroyWindow(window
);
4455 static void test_primary_palette(void)
4457 DDSCAPS surface_caps
= {DDSCAPS_FLIP
};
4458 IDirectDrawSurface
*primary
, *backbuffer
;
4459 PALETTEENTRY palette_entries
[256];
4460 IDirectDrawPalette
*palette
, *tmp
;
4461 DDSURFACEDESC surface_desc
;
4468 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4469 0, 0, 640, 480, 0, 0, 0, 0);
4470 ddraw
= create_ddraw();
4471 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4472 if (FAILED(IDirectDraw_SetDisplayMode(ddraw
, 640, 480, 8)))
4474 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
4475 IDirectDraw_Release(ddraw
);
4476 DestroyWindow(window
);
4479 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4480 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4482 memset(&surface_desc
, 0, sizeof(surface_desc
));
4483 surface_desc
.dwSize
= sizeof(surface_desc
);
4484 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
4485 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
4486 surface_desc
.dwBackBufferCount
= 1;
4487 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
4488 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4489 hr
= IDirectDrawSurface_GetAttachedSurface(primary
, &surface_caps
, &backbuffer
);
4490 ok(SUCCEEDED(hr
), "Failed to get attached surface, hr %#x.\n", hr
);
4492 memset(palette_entries
, 0, sizeof(palette_entries
));
4493 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
, palette_entries
, &palette
, NULL
);
4494 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
4495 refcount
= get_refcount((IUnknown
*)palette
);
4496 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
4498 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
4499 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
4500 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
4502 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
4503 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
4505 /* The Windows 8 testbot attaches the palette to the backbuffer as well,
4506 * and is generally somewhat broken with respect to 8 bpp / palette
4508 if (SUCCEEDED(IDirectDrawSurface_GetPalette(backbuffer
, &tmp
)))
4510 win_skip("Broken palette handling detected, skipping tests.\n");
4511 IDirectDrawPalette_Release(tmp
);
4512 IDirectDrawPalette_Release(palette
);
4513 /* The Windows 8 testbot keeps extra references to the primary and
4514 * backbuffer while in 8 bpp mode. */
4515 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
4516 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
4520 refcount
= get_refcount((IUnknown
*)palette
);
4521 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
4523 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
4524 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
4525 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_PRIMARYSURFACE
| DDPCAPS_ALLOW256
),
4526 "Got unexpected palette caps %#x.\n", palette_caps
);
4528 hr
= IDirectDrawSurface_SetPalette(primary
, NULL
);
4529 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
4530 refcount
= get_refcount((IUnknown
*)palette
);
4531 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
4533 hr
= IDirectDrawPalette_GetCaps(palette
, &palette_caps
);
4534 ok(SUCCEEDED(hr
), "Failed to get palette caps, hr %#x.\n", hr
);
4535 ok(palette_caps
== (DDPCAPS_8BIT
| DDPCAPS_ALLOW256
), "Got unexpected palette caps %#x.\n", palette_caps
);
4537 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
4538 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
4539 refcount
= get_refcount((IUnknown
*)palette
);
4540 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
4542 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
4543 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
4544 ok(tmp
== palette
, "Got unexpected palette %p, expected %p.\n", tmp
, palette
);
4545 IDirectDrawPalette_Release(tmp
);
4546 hr
= IDirectDrawSurface_GetPalette(backbuffer
, &tmp
);
4547 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
4549 refcount
= IDirectDrawPalette_Release(palette
);
4550 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
4551 refcount
= IDirectDrawPalette_Release(palette
);
4552 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4554 /* Note that this only seems to work when the palette is attached to the
4555 * primary surface. When attached to a regular surface, attempting to get
4556 * the palette here will cause an access violation. */
4557 hr
= IDirectDrawSurface_GetPalette(primary
, &tmp
);
4558 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
4561 refcount
= IDirectDrawSurface_Release(backbuffer
);
4562 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
4563 refcount
= IDirectDrawSurface_Release(primary
);
4564 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4565 refcount
= IDirectDraw_Release(ddraw
);
4566 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4567 DestroyWindow(window
);
4570 static HRESULT WINAPI
surface_counter(IDirectDrawSurface
*surface
, DDSURFACEDESC
*desc
, void *context
)
4572 UINT
*surface_count
= context
;
4575 IDirectDrawSurface_Release(surface
);
4577 return DDENUMRET_OK
;
4580 static void test_surface_attachment(void)
4582 IDirectDrawSurface
*surface1
, *surface2
, *surface3
, *surface4
;
4583 DDSCAPS caps
= {DDSCAPS_TEXTURE
};
4584 DDSURFACEDESC surface_desc
;
4591 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
4592 0, 0, 640, 480, 0, 0, 0, 0);
4593 ddraw
= create_ddraw();
4594 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4595 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4596 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4598 memset(&surface_desc
, 0, sizeof(surface_desc
));
4599 surface_desc
.dwSize
= sizeof(surface_desc
);
4600 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_MIPMAPCOUNT
;
4601 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
4602 U2(surface_desc
).dwMipMapCount
= 3;
4603 surface_desc
.dwWidth
= 128;
4604 surface_desc
.dwHeight
= 128;
4605 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
4606 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4608 hr
= IDirectDrawSurface_GetAttachedSurface(surface1
, &caps
, &surface2
);
4609 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
4610 hr
= IDirectDrawSurface_GetAttachedSurface(surface2
, &caps
, &surface3
);
4611 ok(SUCCEEDED(hr
), "Failed to get mip level, hr %#x.\n", hr
);
4612 hr
= IDirectDrawSurface_GetAttachedSurface(surface3
, &caps
, &surface4
);
4613 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
4616 IDirectDrawSurface_EnumAttachedSurfaces(surface1
, &surface_count
, surface_counter
);
4617 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
4619 IDirectDrawSurface_EnumAttachedSurfaces(surface2
, &surface_count
, surface_counter
);
4620 ok(surface_count
== 1, "Got unexpected surface_count %u.\n", surface_count
);
4622 IDirectDrawSurface_EnumAttachedSurfaces(surface3
, &surface_count
, surface_counter
);
4623 ok(!surface_count
, "Got unexpected surface_count %u.\n", surface_count
);
4625 memset(&surface_desc
, 0, sizeof(surface_desc
));
4626 surface_desc
.dwSize
= sizeof(surface_desc
);
4627 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4628 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
4629 surface_desc
.dwWidth
= 16;
4630 surface_desc
.dwHeight
= 16;
4631 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
4632 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4634 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
4635 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4636 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
4637 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4638 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
4639 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4640 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
4641 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4642 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
4643 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4644 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
4645 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4647 IDirectDrawSurface_Release(surface4
);
4649 memset(&surface_desc
, 0, sizeof(surface_desc
));
4650 surface_desc
.dwSize
= sizeof(surface_desc
);
4651 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4652 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
;
4653 surface_desc
.dwWidth
= 16;
4654 surface_desc
.dwHeight
= 16;
4655 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
4656 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4658 if (SUCCEEDED(hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
)))
4660 skip("Running on refrast, skipping some tests.\n");
4661 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface4
);
4662 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4666 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4667 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
4668 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4669 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface4
);
4670 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4671 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface3
);
4672 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4673 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface4
);
4674 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4675 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface2
);
4676 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4679 IDirectDrawSurface_Release(surface4
);
4680 IDirectDrawSurface_Release(surface3
);
4681 IDirectDrawSurface_Release(surface2
);
4682 IDirectDrawSurface_Release(surface1
);
4684 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
4685 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
4687 /* Try a single primary and two offscreen plain surfaces. */
4688 memset(&surface_desc
, 0, sizeof(surface_desc
));
4689 surface_desc
.dwSize
= sizeof(surface_desc
);
4690 surface_desc
.dwFlags
= DDSD_CAPS
;
4691 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
4692 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
4693 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4695 memset(&surface_desc
, 0, sizeof(surface_desc
));
4696 surface_desc
.dwSize
= sizeof(surface_desc
);
4697 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4698 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4699 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
4700 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
4701 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
4702 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4704 memset(&surface_desc
, 0, sizeof(surface_desc
));
4705 surface_desc
.dwSize
= sizeof(surface_desc
);
4706 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4707 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4708 surface_desc
.dwWidth
= registry_mode
.dmPelsWidth
;
4709 surface_desc
.dwHeight
= registry_mode
.dmPelsHeight
;
4710 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
4711 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4713 /* This one has a different size. */
4714 memset(&surface_desc
, 0, sizeof(surface_desc
));
4715 surface_desc
.dwSize
= sizeof(surface_desc
);
4716 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
4717 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
4718 surface_desc
.dwWidth
= 128;
4719 surface_desc
.dwHeight
= 128;
4720 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface4
, NULL
);
4721 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4723 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
4724 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4725 /* Try the reverse without detaching first. */
4726 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
4727 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
4728 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
4729 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4731 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface1
);
4732 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4733 /* Try to detach reversed. */
4734 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
4735 ok(hr
== DDERR_CANNOTDETACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4736 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface1
);
4737 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4739 hr
= IDirectDrawSurface_AddAttachedSurface(surface2
, surface3
);
4740 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4741 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface2
, 0, surface3
);
4742 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4744 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface4
);
4745 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4746 hr
= IDirectDrawSurface_AddAttachedSurface(surface4
, surface1
);
4747 ok(hr
== DDERR_CANNOTATTACHSURFACE
, "Got unexpected hr %#x.\n", hr
);
4749 IDirectDrawSurface_Release(surface4
);
4750 IDirectDrawSurface_Release(surface3
);
4751 IDirectDrawSurface_Release(surface2
);
4752 IDirectDrawSurface_Release(surface1
);
4754 /* Test DeleteAttachedSurface() and automatic detachment of attached surfaces on release. */
4755 memset(&surface_desc
, 0, sizeof(surface_desc
));
4756 surface_desc
.dwSize
= sizeof(surface_desc
);
4757 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
4758 surface_desc
.dwWidth
= 64;
4759 surface_desc
.dwHeight
= 64;
4760 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_3DDEVICE
;
4761 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
4762 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
; /* D3DFMT_R5G6B5 */
4763 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
4764 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
4765 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
4766 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
4767 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface1
, NULL
);
4768 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4769 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface3
, NULL
);
4770 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4772 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
4773 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_ZBUFFER
;
4774 U1(surface_desc
.ddpfPixelFormat
).dwZBufferBitDepth
= 16;
4775 U3(surface_desc
.ddpfPixelFormat
).dwZBitMask
= 0x0000ffff;
4776 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
4777 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
4779 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
4780 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4781 refcount
= get_refcount((IUnknown
*)surface2
);
4782 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
4783 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
4784 ok(hr
== DDERR_SURFACEALREADYATTACHED
, "Got unexpected hr %#x.\n", hr
);
4786 /* Attaching while already attached to other surface. */
4787 hr
= IDirectDrawSurface_AddAttachedSurface(surface3
, surface2
);
4788 todo_wine
ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4789 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface3
, 0, surface2
);
4790 todo_wine
ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4791 IDirectDrawSurface_Release(surface3
);
4793 hr
= IDirectDrawSurface_DeleteAttachedSurface(surface1
, 0, surface2
);
4794 ok(SUCCEEDED(hr
), "Failed to detach surface, hr %#x.\n", hr
);
4795 refcount
= get_refcount((IUnknown
*)surface2
);
4796 ok(refcount
== 1, "Got unexpected refcount %u.\n", refcount
);
4798 /* Automatic detachment on release. */
4799 hr
= IDirectDrawSurface_AddAttachedSurface(surface1
, surface2
);
4800 ok(SUCCEEDED(hr
), "Failed to attach surface, hr %#x.\n", hr
);
4801 refcount
= get_refcount((IUnknown
*)surface2
);
4802 ok(refcount
== 2, "Got unexpected refcount %u.\n", refcount
);
4803 refcount
= IDirectDrawSurface_Release(surface1
);
4804 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4805 refcount
= IDirectDrawSurface_Release(surface2
);
4806 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4807 refcount
= IDirectDraw_Release(ddraw
);
4808 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
4809 DestroyWindow(window
);
4812 static void test_pixel_format(void)
4814 HWND window
, window2
= NULL
;
4815 HDC hdc
, hdc2
= NULL
;
4817 int format
, test_format
;
4818 PIXELFORMATDESCRIPTOR pfd
;
4819 IDirectDraw
*ddraw
= NULL
;
4820 IDirectDrawClipper
*clipper
= NULL
;
4822 IDirectDrawSurface
*primary
= NULL
;
4826 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
4827 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
4830 skip("Failed to create window\n");
4834 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
| WS_VISIBLE
,
4835 100, 100, 160, 160, NULL
, NULL
, NULL
, NULL
);
4837 hdc
= GetDC(window
);
4840 skip("Failed to get DC\n");
4845 hdc2
= GetDC(window2
);
4847 gl
= LoadLibraryA("opengl32.dll");
4848 ok(!!gl
, "failed to load opengl32.dll; SetPixelFormat()/GetPixelFormat() may not work right\n");
4850 format
= GetPixelFormat(hdc
);
4851 ok(format
== 0, "new window has pixel format %d\n", format
);
4853 ZeroMemory(&pfd
, sizeof(pfd
));
4854 pfd
.nSize
= sizeof(pfd
);
4856 pfd
.dwFlags
= PFD_DRAW_TO_WINDOW
| PFD_SUPPORT_OPENGL
;
4857 pfd
.iPixelType
= PFD_TYPE_RGBA
;
4858 pfd
.iLayerType
= PFD_MAIN_PLANE
;
4859 format
= ChoosePixelFormat(hdc
, &pfd
);
4862 skip("no pixel format available\n");
4866 if (!SetPixelFormat(hdc
, format
, &pfd
) || GetPixelFormat(hdc
) != format
)
4868 skip("failed to set pixel format\n");
4872 if (!hdc2
|| !SetPixelFormat(hdc2
, format
, &pfd
) || GetPixelFormat(hdc2
) != format
)
4874 skip("failed to set pixel format on second window\n");
4877 ReleaseDC(window2
, hdc2
);
4882 ddraw
= create_ddraw();
4883 ok(!!ddraw
, "Failed to create a ddraw object.\n");
4885 test_format
= GetPixelFormat(hdc
);
4886 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4888 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
4891 skip("Failed to set cooperative level, hr %#x.\n", hr
);
4895 test_format
= GetPixelFormat(hdc
);
4896 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4900 hr
= IDirectDraw_CreateClipper(ddraw
, 0, &clipper
, NULL
);
4901 ok(SUCCEEDED(hr
), "Failed to create clipper, hr %#x.\n", hr
);
4902 hr
= IDirectDrawClipper_SetHWnd(clipper
, 0, window2
);
4903 ok(SUCCEEDED(hr
), "Failed to set clipper window, hr %#x.\n", hr
);
4905 test_format
= GetPixelFormat(hdc
);
4906 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4908 test_format
= GetPixelFormat(hdc2
);
4909 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
4912 memset(&ddsd
, 0, sizeof(ddsd
));
4913 ddsd
.dwSize
= sizeof(ddsd
);
4914 ddsd
.dwFlags
= DDSD_CAPS
;
4915 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
4917 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &primary
, NULL
);
4918 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
4920 test_format
= GetPixelFormat(hdc
);
4921 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4925 test_format
= GetPixelFormat(hdc2
);
4926 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
4931 hr
= IDirectDrawSurface_SetClipper(primary
, clipper
);
4932 ok(SUCCEEDED(hr
), "Failed to set clipper, hr %#x.\n", hr
);
4934 test_format
= GetPixelFormat(hdc
);
4935 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4937 test_format
= GetPixelFormat(hdc2
);
4938 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
4941 memset(&fx
, 0, sizeof(fx
));
4942 fx
.dwSize
= sizeof(fx
);
4943 hr
= IDirectDrawSurface_Blt(primary
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
4944 ok(SUCCEEDED(hr
), "Failed to clear source surface, hr %#x.\n", hr
);
4946 test_format
= GetPixelFormat(hdc
);
4947 ok(test_format
== format
, "window has pixel format %d, expected %d\n", test_format
, format
);
4951 test_format
= GetPixelFormat(hdc2
);
4952 ok(test_format
== format
, "second window has pixel format %d, expected %d\n", test_format
, format
);
4956 if (primary
) IDirectDrawSurface_Release(primary
);
4957 if (clipper
) IDirectDrawClipper_Release(clipper
);
4958 if (ddraw
) IDirectDraw_Release(ddraw
);
4959 if (gl
) FreeLibrary(gl
);
4960 if (hdc
) ReleaseDC(window
, hdc
);
4961 if (hdc2
) ReleaseDC(window2
, hdc2
);
4962 if (window
) DestroyWindow(window
);
4963 if (window2
) DestroyWindow(window2
);
4966 static void test_create_surface_pitch(void)
4968 IDirectDrawSurface
*surface
;
4969 DDSURFACEDESC surface_desc
;
4990 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
4992 DDSD_PITCH
, 0x100, 0x100},
4993 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
4994 DDSD_PITCH
, 0x104, DD_OK
,
4995 DDSD_PITCH
, 0x100, 0x100},
4996 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
4997 DDSD_PITCH
, 0x0f8, DD_OK
,
4998 DDSD_PITCH
, 0x100, 0x100},
4999 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
5000 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
5002 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
5004 DDSD_PITCH
, 0x100, 0x0fc},
5006 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
5007 DDSD_PITCH
, 0x104, DD_OK
,
5008 DDSD_PITCH
, 0x100, 0x0fc},
5009 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
5010 DDSD_PITCH
, 0x0f8, DD_OK
,
5011 DDSD_PITCH
, 0x100, 0x0fc},
5012 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
5013 DDSD_PITCH
| DDSD_LINEARSIZE
, 0, DD_OK
,
5014 DDSD_PITCH
, 0x100, 0x0fc},
5015 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
5016 DDSD_LPSURFACE
, 0, DDERR_INVALIDPARAMS
,
5018 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
,
5019 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
5022 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
5023 0, 0, DDERR_INVALIDCAPS
,
5025 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
5027 DDSD_PITCH
, 0x100, 0 },
5028 {DDSCAPS_VIDEOMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
5029 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDCAPS
,
5031 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_ALLOCONLOAD
,
5032 0, 0, DDERR_INVALIDCAPS
,
5034 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
5036 DDSD_PITCH
, 0x100, 0 },
5038 {DDSCAPS_SYSTEMMEMORY
| DDSCAPS_TEXTURE
| DDSCAPS_ALLOCONLOAD
,
5039 DDSD_LPSURFACE
| DDSD_PITCH
, 0x100, DDERR_INVALIDPARAMS
,
5042 DWORD flags_mask
= DDSD_PITCH
| DDSD_LPSURFACE
| DDSD_LINEARSIZE
;
5044 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5045 0, 0, 640, 480, 0, 0, 0, 0);
5046 ddraw
= create_ddraw();
5047 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5048 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5049 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5051 mem
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
, ((63 * 4) + 8) * 63);
5053 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5055 memset(&surface_desc
, 0, sizeof(surface_desc
));
5056 surface_desc
.dwSize
= sizeof(surface_desc
);
5057 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| test_data
[i
].flags_in
;
5058 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
5059 surface_desc
.dwWidth
= 63;
5060 surface_desc
.dwHeight
= 63;
5061 U1(surface_desc
).lPitch
= test_data
[i
].pitch_in
;
5062 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5063 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
5064 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5065 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5066 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5067 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5068 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5069 if (test_data
[i
].flags_in
& DDSD_LPSURFACE
)
5071 HRESULT expected_hr
= SUCCEEDED(test_data
[i
].hr
) ? DDERR_INVALIDPARAMS
: test_data
[i
].hr
;
5072 ok(hr
== expected_hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, expected_hr
);
5073 surface_desc
.lpSurface
= mem
;
5074 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5076 if ((test_data
[i
].caps
& DDSCAPS_VIDEOMEMORY
) && hr
== DDERR_NODIRECTDRAWHW
)
5078 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
5082 memset(&surface_desc
, 0, sizeof(surface_desc
));
5083 surface_desc
.dwSize
= sizeof(surface_desc
);
5084 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
5085 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5086 ok((surface_desc
.dwFlags
& flags_mask
) == test_data
[i
].flags_out
,
5087 "Test %u: Got unexpected flags %#x, expected %#x.\n",
5088 i
, surface_desc
.dwFlags
& flags_mask
, test_data
[i
].flags_out
);
5089 if (!(test_data
[i
].caps
& DDSCAPS_TEXTURE
))
5091 if (is_ddraw64
&& test_data
[i
].pitch_out32
!= test_data
[i
].pitch_out64
)
5092 todo_wine
ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out64
,
5093 "Test %u: Got unexpected pitch %u, expected %u.\n",
5094 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out64
);
5096 ok(U1(surface_desc
).lPitch
== test_data
[i
].pitch_out32
,
5097 "Test %u: Got unexpected pitch %u, expected %u.\n",
5098 i
, U1(surface_desc
).lPitch
, test_data
[i
].pitch_out32
);
5100 ok(!surface_desc
.lpSurface
, "Test %u: Got unexpected lpSurface %p.\n", i
, surface_desc
.lpSurface
);
5102 IDirectDrawSurface_Release(surface
);
5105 HeapFree(GetProcessHeap(), 0, mem
);
5106 refcount
= IDirectDraw_Release(ddraw
);
5107 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5108 DestroyWindow(window
);
5111 static void test_mipmap(void)
5113 IDirectDrawSurface
*surface
, *surface2
;
5114 DDSURFACEDESC surface_desc
;
5120 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
5129 DWORD mipmap_count_in
;
5131 DWORD mipmap_count_out
;
5135 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 3, DD_OK
, 3},
5136 {DDSD_MIPMAPCOUNT
, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDPARAMS
, 0},
5137 {0, DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 1},
5138 {0, DDSCAPS_MIPMAP
, 128, 32, 0, DDERR_INVALIDCAPS
, 0},
5139 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 128, 32, 0, DD_OK
, 6},
5140 {0, DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
, 32, 64, 0, DD_OK
, 6},
5143 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5144 0, 0, 640, 480, 0, 0, 0, 0);
5145 ddraw
= create_ddraw();
5146 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5147 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5148 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5150 memset(&hal_caps
, 0, sizeof(hal_caps
));
5151 hal_caps
.dwSize
= sizeof(hal_caps
);
5152 hr
= IDirectDraw_GetCaps(ddraw
, &hal_caps
, NULL
);
5153 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5154 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
5156 skip("Mipmapped textures not supported, skipping tests.\n");
5157 IDirectDraw_Release(ddraw
);
5158 DestroyWindow(window
);
5162 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); ++i
)
5164 memset(&surface_desc
, 0, sizeof(surface_desc
));
5165 surface_desc
.dwSize
= sizeof(surface_desc
);
5166 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| tests
[i
].flags
;
5167 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
5168 surface_desc
.dwWidth
= tests
[i
].width
;
5169 surface_desc
.dwHeight
= tests
[i
].height
;
5170 if (tests
[i
].flags
& DDSD_MIPMAPCOUNT
)
5171 U2(surface_desc
).dwMipMapCount
= tests
[i
].mipmap_count_in
;
5172 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5173 ok(hr
== tests
[i
].hr
, "Test %u: Got unexpected hr %#x.\n", i
, hr
);
5177 memset(&surface_desc
, 0, sizeof(surface_desc
));
5178 surface_desc
.dwSize
= sizeof(surface_desc
);
5179 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
5180 ok(SUCCEEDED(hr
), "Test %u: Failed to get surface desc, hr %#x.\n", i
, hr
);
5181 ok(surface_desc
.dwFlags
& DDSD_MIPMAPCOUNT
,
5182 "Test %u: Got unexpected flags %#x.\n", i
, surface_desc
.dwFlags
);
5183 ok(U2(surface_desc
).dwMipMapCount
== tests
[i
].mipmap_count_out
,
5184 "Test %u: Got unexpected mipmap count %u.\n", i
, U2(surface_desc
).dwMipMapCount
);
5186 if (U2(surface_desc
).dwMipMapCount
> 1)
5188 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &surface2
);
5189 ok(SUCCEEDED(hr
), "Test %u: Failed to get attached surface, hr %#x.\n", i
, hr
);
5191 memset(&surface_desc
, 0, sizeof(surface_desc
));
5192 surface_desc
.dwSize
= sizeof(surface_desc
);
5193 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
5194 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
5195 memset(&surface_desc
, 0, sizeof(surface_desc
));
5196 surface_desc
.dwSize
= sizeof(surface_desc
);
5197 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &surface_desc
, 0, NULL
);
5198 ok(SUCCEEDED(hr
), "Test %u: Failed to lock surface, hr %#x.\n", i
, hr
);
5199 IDirectDrawSurface_Unlock(surface2
, NULL
);
5200 IDirectDrawSurface_Unlock(surface
, NULL
);
5202 IDirectDrawSurface_Release(surface2
);
5205 IDirectDrawSurface_Release(surface
);
5208 refcount
= IDirectDraw_Release(ddraw
);
5209 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5210 DestroyWindow(window
);
5213 static void test_palette_complex(void)
5215 IDirectDrawSurface
*surface
, *mipmap
, *tmp
;
5216 DDSURFACEDESC surface_desc
;
5218 IDirectDrawPalette
*palette
, *palette2
, *palette_mipmap
;
5222 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
5224 PALETTEENTRY palette_entries
[256];
5230 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5231 0, 0, 640, 480, 0, 0, 0, 0);
5232 ddraw
= create_ddraw();
5233 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5234 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5235 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5237 memset(&hal_caps
, 0, sizeof(hal_caps
));
5238 hal_caps
.dwSize
= sizeof(hal_caps
);
5239 hr
= IDirectDraw_GetCaps(ddraw
, &hal_caps
, NULL
);
5240 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
5241 if ((hal_caps
.ddsCaps
.dwCaps
& (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
)) != (DDSCAPS_TEXTURE
| DDSCAPS_MIPMAP
))
5243 skip("Mipmapped textures not supported, skipping mipmap palette test.\n");
5244 IDirectDraw_Release(ddraw
);
5245 DestroyWindow(window
);
5249 memset(&surface_desc
, 0, sizeof(surface_desc
));
5250 surface_desc
.dwSize
= sizeof(surface_desc
);
5251 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5252 surface_desc
.dwWidth
= 128;
5253 surface_desc
.dwHeight
= 128;
5254 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
5255 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5256 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
5257 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
5258 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
5259 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5261 memset(palette_entries
, 0, sizeof(palette_entries
));
5262 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
5263 palette_entries
, &palette
, NULL
);
5264 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5266 memset(palette_entries
, 0, sizeof(palette_entries
));
5267 palette_entries
[1].peRed
= 0xff;
5268 palette_entries
[1].peGreen
= 0x80;
5269 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
5270 palette_entries
, &palette_mipmap
, NULL
);
5271 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5273 palette2
= (void *)0xdeadbeef;
5274 hr
= IDirectDrawSurface_GetPalette(surface
, &palette2
);
5275 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x.\n", hr
);
5276 ok(!palette2
, "Got unexpected palette %p.\n", palette2
);
5277 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
5278 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5279 hr
= IDirectDrawSurface_GetPalette(surface
, &palette2
);
5280 ok(SUCCEEDED(hr
), "Failed to get palette, hr %#x.\n", hr
);
5281 ok(palette
== palette2
, "Got unexpected palette %p.\n", palette2
);
5282 IDirectDrawPalette_Release(palette2
);
5285 IDirectDrawSurface_AddRef(mipmap
);
5286 for (i
= 0; i
< 7; ++i
)
5288 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
5289 ok(SUCCEEDED(hr
), "Failed to get attached surface, i %u, hr %#x.\n", i
, hr
);
5290 palette2
= (void *)0xdeadbeef;
5291 hr
= IDirectDrawSurface_GetPalette(tmp
, &palette2
);
5292 ok(hr
== DDERR_NOPALETTEATTACHED
, "Got unexpected hr %#x, i %u.\n", hr
, i
);
5293 ok(!palette2
, "Got unexpected palette %p, i %u.\n", palette2
, i
);
5295 hr
= IDirectDrawSurface_SetPalette(tmp
, palette_mipmap
);
5296 ok(SUCCEEDED(hr
), "Failed to set palette, i %u, hr %#x.\n", i
, hr
);
5298 hr
= IDirectDrawSurface_GetPalette(tmp
, &palette2
);
5299 ok(SUCCEEDED(hr
), "Failed to get palette, i %u, hr %#x.\n", i
, hr
);
5300 ok(palette_mipmap
== palette2
, "Got unexpected palette %p.\n", palette2
);
5301 IDirectDrawPalette_Release(palette2
);
5303 hr
= IDirectDrawSurface_GetDC(tmp
, &dc
);
5304 ok(SUCCEEDED(hr
), "Failed to get DC, i %u, hr %#x.\n", i
, hr
);
5305 count
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
5306 ok(count
== 1, "Expected count 1, got %u.\n", count
);
5307 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x.\n", rgbquad
.rgbRed
);
5308 ok(rgbquad
.rgbGreen
== 0x80, "Expected rgbGreen = 0x80, got %#x.\n", rgbquad
.rgbGreen
);
5309 ok(rgbquad
.rgbBlue
== 0x0, "Expected rgbBlue = 0x0, got %#x.\n", rgbquad
.rgbBlue
);
5310 hr
= IDirectDrawSurface_ReleaseDC(tmp
, dc
);
5311 ok(SUCCEEDED(hr
), "Failed to release DC, i %u, hr %#x.\n", i
, hr
);
5313 IDirectDrawSurface_Release(mipmap
);
5317 hr
= IDirectDrawSurface_GetAttachedSurface(mipmap
, &caps
, &tmp
);
5318 ok(hr
== DDERR_NOTFOUND
, "Got unexpected hr %#x.\n", hr
);
5319 IDirectDrawSurface_Release(mipmap
);
5320 refcount
= IDirectDrawSurface_Release(surface
);
5321 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5322 refcount
= IDirectDrawPalette_Release(palette_mipmap
);
5323 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5324 refcount
= IDirectDrawPalette_Release(palette
);
5325 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5327 refcount
= IDirectDraw_Release(ddraw
);
5328 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5329 DestroyWindow(window
);
5332 static BOOL
ddraw_is_warp(IDirectDraw
*ddraw
)
5334 IDirectDraw4
*ddraw4
;
5335 DDDEVICEIDENTIFIER identifier
;
5338 if (!strcmp(winetest_platform
, "wine"))
5341 hr
= IDirectDraw_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
5342 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
5343 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, &identifier
, 0);
5344 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
5345 IDirectDraw4_Release(ddraw4
);
5346 return !!strstr(identifier
.szDriver
, "warp");
5349 static void test_p8_blit(void)
5351 IDirectDrawSurface
*src
, *dst
, *dst_p8
;
5352 DDSURFACEDESC surface_desc
;
5354 IDirectDrawPalette
*palette
, *palette2
;
5358 PALETTEENTRY palette_entries
[256];
5362 static const BYTE src_data
[] = {0x10, 0x1, 0x2, 0x3, 0x4, 0x5, 0xff, 0x80};
5363 static const BYTE src_data2
[] = {0x10, 0x5, 0x4, 0x3, 0x2, 0x1, 0xff, 0x80};
5364 static const BYTE expected_p8
[] = {0x10, 0x1, 0x4, 0x3, 0x4, 0x5, 0xff, 0x80};
5365 static const D3DCOLOR expected
[] =
5367 0x00101010, 0x00010101, 0x00020202, 0x00030303,
5368 0x00040404, 0x00050505, 0x00ffffff, 0x00808080,
5372 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5373 0, 0, 640, 480, 0, 0, 0, 0);
5374 ddraw
= create_ddraw();
5375 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5376 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
5377 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
5378 is_warp
= ddraw_is_warp(ddraw
);
5380 memset(palette_entries
, 0, sizeof(palette_entries
));
5381 palette_entries
[1].peGreen
= 0xff;
5382 palette_entries
[2].peBlue
= 0xff;
5383 palette_entries
[3].peFlags
= 0xff;
5384 palette_entries
[4].peRed
= 0xff;
5385 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
5386 palette_entries
, &palette
, NULL
);
5387 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5388 palette_entries
[1].peBlue
= 0xff;
5389 palette_entries
[2].peGreen
= 0xff;
5390 palette_entries
[3].peRed
= 0xff;
5391 palette_entries
[4].peFlags
= 0x0;
5392 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
5393 palette_entries
, &palette2
, NULL
);
5394 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
5396 memset(&surface_desc
, 0, sizeof(surface_desc
));
5397 surface_desc
.dwSize
= sizeof(surface_desc
);
5398 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5399 surface_desc
.dwWidth
= 8;
5400 surface_desc
.dwHeight
= 1;
5401 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5402 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5403 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
5404 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
5405 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
5406 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5407 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &dst_p8
, NULL
);
5408 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5409 hr
= IDirectDrawSurface_SetPalette(dst_p8
, palette2
);
5410 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5412 memset(&surface_desc
, 0, sizeof(surface_desc
));
5413 surface_desc
.dwSize
= sizeof(surface_desc
);
5414 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
5415 surface_desc
.dwWidth
= 8;
5416 surface_desc
.dwHeight
= 1;
5417 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
5418 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
5419 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
5420 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
5421 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
5422 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
5423 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
5424 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
5425 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
5426 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
5428 memset(&surface_desc
, 0, sizeof(surface_desc
));
5429 surface_desc
.dwSize
= sizeof(surface_desc
);
5430 hr
= IDirectDrawSurface_Lock(src
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
5431 ok(SUCCEEDED(hr
), "Failed to lock source surface, hr %#x.\n", hr
);
5432 memcpy(surface_desc
.lpSurface
, src_data
, sizeof(src_data
));
5433 hr
= IDirectDrawSurface_Unlock(src
, NULL
);
5434 ok(SUCCEEDED(hr
), "Failed to unlock source surface, hr %#x.\n", hr
);
5436 hr
= IDirectDrawSurface_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
5437 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
5438 memcpy(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
));
5439 hr
= IDirectDrawSurface_Unlock(dst_p8
, NULL
);
5440 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
5442 hr
= IDirectDrawSurface_SetPalette(src
, palette
);
5443 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
5444 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
5445 /* The r500 Windows 7 driver returns E_NOTIMPL. r200 on Windows XP works.
5446 * The Geforce 7 driver on Windows Vista returns E_FAIL. Newer Nvidia GPUs work. */
5447 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
) || broken(hr
== E_FAIL
),
5448 "Failed to blit, hr %#x.\n", hr
);
5452 for (x
= 0; x
< sizeof(expected
) / sizeof(*expected
); x
++)
5454 color
= get_surface_color(dst
, x
, 0);
5455 todo_wine
ok(compare_color(color
, expected
[x
], 0),
5456 "Pixel %u: Got color %#x, expected %#x.\n",
5457 x
, color
, expected
[x
]);
5461 memset(&fx
, 0, sizeof(fx
));
5462 fx
.dwSize
= sizeof(fx
);
5463 fx
.ddckSrcColorkey
.dwColorSpaceHighValue
= 0x2;
5464 fx
.ddckSrcColorkey
.dwColorSpaceLowValue
= 0x2;
5465 hr
= IDirectDrawSurface_Blt(dst_p8
, NULL
, src
, NULL
, DDBLT_WAIT
| DDBLT_KEYSRCOVERRIDE
, &fx
);
5466 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
5468 hr
= IDirectDrawSurface_Lock(dst_p8
, NULL
, &surface_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
5469 ok(SUCCEEDED(hr
), "Failed to lock destination surface, hr %#x.\n", hr
);
5470 /* A color keyed P8 blit doesn't do anything on WARP - it just leaves the data in the destination
5471 * surface untouched. P8 blits without color keys work. Error checking (DDBLT_KEYSRC without a key
5472 * for example) also works as expected.
5474 * Using DDBLT_KEYSRC instead of DDBLT_KEYSRCOVERRIDE doesn't change this. Doing this blit with
5475 * the display mode set to P8 doesn't help either. */
5476 ok(!memcmp(surface_desc
.lpSurface
, expected_p8
, sizeof(expected_p8
))
5477 || broken(is_warp
&& !memcmp(surface_desc
.lpSurface
, src_data2
, sizeof(src_data2
))),
5478 "Got unexpected P8 color key blit result.\n");
5479 hr
= IDirectDrawSurface_Unlock(dst_p8
, NULL
);
5480 ok(SUCCEEDED(hr
), "Failed to unlock destination surface, hr %#x.\n", hr
);
5482 IDirectDrawSurface_Release(src
);
5483 IDirectDrawSurface_Release(dst
);
5484 IDirectDrawSurface_Release(dst_p8
);
5485 IDirectDrawPalette_Release(palette
);
5486 IDirectDrawPalette_Release(palette2
);
5488 refcount
= IDirectDraw_Release(ddraw
);
5489 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
5490 DestroyWindow(window
);
5493 static void test_material(void)
5495 IDirect3DMaterial
*background
, *material
;
5496 IDirect3DExecuteBuffer
*execute_buffer
;
5497 D3DMATERIALHANDLE mat_handle
, tmp
;
5498 D3DEXECUTEBUFFERDESC exec_desc
;
5499 IDirect3DViewport
*viewport
;
5500 IDirect3DDevice
*device
;
5501 IDirectDrawSurface
*rt
;
5512 static D3DVERTEX quad
[] =
5514 {{-1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5515 {{-1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5516 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5517 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5522 D3DCOLOR expected_color
;
5527 {FALSE
, 0x00ffffff},
5529 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
5531 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5532 0, 0, 640, 480, 0, 0, 0, 0);
5533 ddraw
= create_ddraw();
5534 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5535 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
5537 skip("Failed to create a 3D device, skipping test.\n");
5538 DestroyWindow(window
);
5542 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
5543 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
5545 background
= create_diffuse_material(device
, 0.0f
, 0.0f
, 1.0f
, 1.0f
);
5546 viewport
= create_viewport(device
, 0, 0, 640, 480);
5547 viewport_set_background(device
, viewport
, background
);
5549 material
= create_emissive_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
5550 hr
= IDirect3DMaterial_GetHandle(material
, device
, &mat_handle
);
5551 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
5553 memset(&exec_desc
, 0, sizeof(exec_desc
));
5554 exec_desc
.dwSize
= sizeof(exec_desc
);
5555 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
5556 exec_desc
.dwBufferSize
= 1024;
5557 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
5559 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
5560 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
5562 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
5564 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5565 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5567 memcpy(exec_desc
.lpData
, quad
, sizeof(quad
));
5568 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(quad
);
5569 emit_set_ls(&ptr
, D3DLIGHTSTATE_MATERIAL
, test_data
[i
].material
? mat_handle
: 0);
5570 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORMLIGHT
, 0, 4);
5571 emit_tquad(&ptr
, 0);
5573 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5574 inst_length
-= sizeof(quad
);
5576 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5577 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5579 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
| D3DCLEAR_ZBUFFER
);
5580 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5582 hr
= IDirect3DDevice_BeginScene(device
);
5583 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5584 set_execute_data(execute_buffer
, 4, sizeof(quad
), inst_length
);
5585 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5586 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5587 hr
= IDirect3DDevice_EndScene(device
);
5588 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5589 color
= get_surface_color(rt
, 320, 240);
5590 if (test_data
[i
].material
)
5591 todo_wine
ok(compare_color(color
, test_data
[i
].expected_color
, 1)
5592 /* The Windows 8 testbot appears to return undefined results. */
5594 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
5596 ok(compare_color(color
, test_data
[i
].expected_color
, 1),
5597 "Got unexpected color 0x%08x, test %u.\n", color
, i
);
5600 destroy_material(material
);
5601 material
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
5602 hr
= IDirect3DMaterial_GetHandle(material
, device
, &mat_handle
);
5603 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
5605 hr
= IDirect3DViewport_SetBackground(viewport
, mat_handle
);
5606 ok(SUCCEEDED(hr
), "Failed to set viewport background, hr %#x.\n", hr
);
5607 hr
= IDirect3DViewport_GetBackground(viewport
, &tmp
, &valid
);
5608 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
5609 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
5610 ok(valid
, "Got unexpected valid %#x.\n", valid
);
5611 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
5612 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5613 color
= get_surface_color(rt
, 320, 240);
5614 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
5616 hr
= IDirect3DViewport_SetBackground(viewport
, 0);
5617 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
5618 hr
= IDirect3DViewport_GetBackground(viewport
, &tmp
, &valid
);
5619 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
5620 ok(tmp
== mat_handle
, "Got unexpected material handle %#x, expected %#x.\n", tmp
, mat_handle
);
5621 ok(valid
, "Got unexpected valid %#x.\n", valid
);
5622 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
5623 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5624 color
= get_surface_color(rt
, 320, 240);
5625 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
5627 destroy_viewport(device
, viewport
);
5628 viewport
= create_viewport(device
, 0, 0, 640, 480);
5630 hr
= IDirect3DViewport_GetBackground(viewport
, &tmp
, &valid
);
5631 ok(SUCCEEDED(hr
), "Failed to get viewport background, hr %#x.\n", hr
);
5632 ok(!tmp
, "Got unexpected material handle %#x.\n", tmp
);
5633 ok(!valid
, "Got unexpected valid %#x.\n", valid
);
5634 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
5635 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5636 color
= get_surface_color(rt
, 320, 240);
5637 ok(compare_color(color
, 0x00000000, 1), "Got unexpected color 0x%08x.\n", color
);
5639 IDirect3DExecuteBuffer_Release(execute_buffer
);
5640 destroy_viewport(device
, viewport
);
5641 destroy_material(background
);
5642 destroy_material(material
);
5643 IDirectDrawSurface_Release(rt
);
5644 refcount
= IDirect3DDevice_Release(device
);
5645 ok(!refcount
, "Device has %u references left.\n", refcount
);
5646 refcount
= IDirectDraw_Release(ddraw
);
5647 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
5648 DestroyWindow(window
);
5651 static void test_lighting(void)
5653 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
5654 static D3DMATRIX mat
=
5656 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5657 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5658 0.0f
, 0.0f
, 1.0f
, 0.0f
,
5659 0.0f
, 0.0f
, 0.0f
, 1.0f
,
5663 1.0f
, 0.0f
, 1.0f
, 0.0f
,
5664 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5665 1.0f
, 0.0f
, 1.0f
, 0.0f
,
5666 0.0f
, 0.0f
, 0.5f
, 1.0f
,
5670 0.0f
, 0.0f
, 1.0f
, 0.0f
,
5671 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5672 -1.0f
, 0.0f
, 0.0f
, 0.0f
,
5673 10.f
, 10.0f
, 10.0f
, 1.0f
,
5677 1.0f
, 0.0f
, 0.0f
, 0.0f
,
5678 0.0f
, 1.0f
, 0.0f
, 0.0f
,
5679 0.0f
, 0.0f
, 1.0f
, -1.0f
,
5680 10.f
, 10.0f
, 10.0f
, 0.0f
,
5682 static D3DLVERTEX unlitquad
[] =
5684 {{-1.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
5685 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
5686 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
5687 {{ 0.0f
}, {-1.0f
}, {0.1f
}, 0, {0xffff0000}, {0}, {0.0f
}, {0.0f
}},
5691 {{-1.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
5692 {{-1.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
5693 {{ 0.0f
}, { 1.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
5694 {{ 0.0f
}, { 0.0f
}, {0.1f
}, 0, {0xff00ff00}, {0}, {0.0f
}, {0.0f
}},
5696 static D3DVERTEX unlitnquad
[] =
5698 {{0.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5699 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5700 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5701 {{1.0f
}, {-1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5705 {{0.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5706 {{0.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5707 {{1.0f
}, { 1.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5708 {{1.0f
}, { 0.0f
}, {0.1f
}, {1.0f
}, {1.0f
}, {1.0f
}, {0.0f
}, {0.0f
}},
5712 {{-1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5713 {{-1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5714 {{ 1.0f
}, { 1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5715 {{ 1.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5719 {{-10.0f
}, {-11.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
5720 {{-10.0f
}, { -9.0f
}, {11.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
5721 {{-10.0f
}, { -9.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
5722 {{-10.0f
}, {-11.0f
}, { 9.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}, {0.0f
}, {0.0f
}},
5726 {{-11.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5727 {{-11.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5728 {{ -9.0f
}, { -9.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5729 {{ -9.0f
}, {-11.0f
}, {-10.0f
}, {0.0f
}, {0.0f
}, {-1.0f
}, {0.0f
}, {0.0f
}},
5733 D3DMATRIX
*world_matrix
;
5736 const char *message
;
5740 {&mat
, nquad
, 0x000000ff, "Lit quad with light"},
5741 {&mat_singular
, nquad
, 0x000000b4, "Lit quad with singular world matrix"},
5742 {&mat_transf
, rotatedquad
, 0x000000ff, "Lit quad with transformation matrix"},
5743 {&mat_nonaffine
, translatedquad
, 0x000000ff, "Lit quad with non-affine matrix"},
5748 IDirect3DDevice
*device
;
5750 IDirectDrawSurface
*rt
;
5751 IDirect3DViewport
*viewport
;
5752 IDirect3DMaterial
*material
;
5753 IDirect3DLight
*light
;
5754 IDirect3DExecuteBuffer
*execute_buffer
;
5755 D3DEXECUTEBUFFERDESC exec_desc
;
5756 D3DMATERIALHANDLE mat_handle
;
5757 D3DMATRIXHANDLE world_handle
, view_handle
, proj_handle
;
5758 D3DLIGHT light_desc
;
5766 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
5767 0, 0, 640, 480, 0, 0, 0, 0);
5768 ddraw
= create_ddraw();
5769 ok(!!ddraw
, "Failed to create a ddraw object.\n");
5770 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
5772 skip("Failed to create a 3D device, skipping test.\n");
5773 IDirectDraw_Release(ddraw
);
5774 DestroyWindow(window
);
5778 hr
= IDirect3DDevice_GetDirect3D(device
, &d3d
);
5779 ok(SUCCEEDED(hr
), "Failed to get D3D interface, hr %#x.\n", hr
);
5781 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
5782 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
5784 viewport
= create_viewport(device
, 0, 0, 640, 480);
5785 material
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
5786 viewport_set_background(device
, viewport
, material
);
5788 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
5789 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5791 hr
= IDirect3DDevice_CreateMatrix(device
, &world_handle
);
5792 ok(hr
== D3D_OK
, "Creating a matrix object failed, hr %#x.\n", hr
);
5793 hr
= IDirect3DDevice_SetMatrix(device
, world_handle
, &mat
);
5794 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
5795 hr
= IDirect3DDevice_CreateMatrix(device
, &view_handle
);
5796 ok(hr
== D3D_OK
, "Creating a matrix object failed, hr %#x.\n", hr
);
5797 hr
= IDirect3DDevice_SetMatrix(device
, view_handle
, &mat
);
5798 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
5799 hr
= IDirect3DDevice_CreateMatrix(device
, &proj_handle
);
5800 ok(hr
== D3D_OK
, "Creating a matrix object failed, hr %#x.\n", hr
);
5801 hr
= IDirect3DDevice_SetMatrix(device
, proj_handle
, &mat
);
5802 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
5804 memset(&exec_desc
, 0, sizeof(exec_desc
));
5805 exec_desc
.dwSize
= sizeof(exec_desc
);
5806 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
5807 exec_desc
.dwBufferSize
= 1024;
5808 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
5810 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
5811 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
5813 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5814 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5816 memcpy(exec_desc
.lpData
, unlitquad
, sizeof(unlitquad
));
5817 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(unlitquad
);
5818 emit_set_ts(&ptr
, D3DTRANSFORMSTATE_WORLD
, world_handle
);
5819 emit_set_ts(&ptr
, D3DTRANSFORMSTATE_VIEW
, view_handle
);
5820 emit_set_ts(&ptr
, D3DTRANSFORMSTATE_PROJECTION
, proj_handle
);
5821 emit_set_rs(&ptr
, D3DRENDERSTATE_CLIPPING
, FALSE
);
5822 emit_set_rs(&ptr
, D3DRENDERSTATE_ZENABLE
, FALSE
);
5823 emit_set_rs(&ptr
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
5824 emit_set_rs(&ptr
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
5825 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORM
, 0, 4);
5826 emit_tquad_tlist(&ptr
, 0);
5828 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5829 inst_length
-= sizeof(unlitquad
);
5831 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5832 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5834 hr
= IDirect3DDevice_BeginScene(device
);
5835 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5837 set_execute_data(execute_buffer
, 4, sizeof(unlitquad
), inst_length
);
5838 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5839 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5841 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5842 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5844 memcpy(exec_desc
.lpData
, litquad
, sizeof(litquad
));
5845 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(litquad
);
5846 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORM
, 0, 4);
5847 emit_tquad_tlist(&ptr
, 0);
5849 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5850 inst_length
-= sizeof(litquad
);
5852 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5853 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5855 set_execute_data(execute_buffer
, 4, sizeof(litquad
), inst_length
);
5856 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5857 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5859 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5860 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5862 memcpy(exec_desc
.lpData
, unlitnquad
, sizeof(unlitnquad
));
5863 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(unlitnquad
);
5864 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORMLIGHT
, 0, 4);
5865 emit_tquad_tlist(&ptr
, 0);
5867 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5868 inst_length
-= sizeof(unlitnquad
);
5870 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5871 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5873 set_execute_data(execute_buffer
, 4, sizeof(unlitnquad
), inst_length
);
5874 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5875 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5877 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5878 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5880 memcpy(exec_desc
.lpData
, litnquad
, sizeof(litnquad
));
5881 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(litnquad
);
5882 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORMLIGHT
, 0, 4);
5883 emit_tquad_tlist(&ptr
, 0);
5885 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5886 inst_length
-= sizeof(litnquad
);
5888 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5889 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5891 set_execute_data(execute_buffer
, 4, sizeof(litnquad
), inst_length
);
5892 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5893 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5895 hr
= IDirect3DDevice_EndScene(device
);
5896 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5898 color
= get_surface_color(rt
, 160, 360);
5899 ok(color
== 0x00ff0000, "Unlit quad without normals has color 0x%08x.\n", color
);
5900 color
= get_surface_color(rt
, 160, 120);
5901 ok(color
== 0x0000ff00, "Lit quad without normals has color 0x%08x.\n", color
);
5902 color
= get_surface_color(rt
, 480, 360);
5903 ok(color
== 0x00ffffff, "Unlit quad with normals has color 0x%08x.\n", color
);
5904 color
= get_surface_color(rt
, 480, 120);
5905 ok(color
== 0x00ffffff, "Lit quad with normals has color 0x%08x.\n", color
);
5907 hr
= IDirect3DMaterial_GetHandle(material
, device
, &mat_handle
);
5908 ok(SUCCEEDED(hr
), "Failed to get material handle, hr %#x.\n", hr
);
5910 hr
= IDirect3D_CreateLight(d3d
, &light
, NULL
);
5911 ok(SUCCEEDED(hr
), "Failed to create a light object, hr %#x.\n", hr
);
5912 memset(&light_desc
, 0, sizeof(light_desc
));
5913 light_desc
.dwSize
= sizeof(light_desc
);
5914 light_desc
.dltType
= D3DLIGHT_DIRECTIONAL
;
5915 U1(light_desc
.dcvColor
).r
= 0.0f
;
5916 U2(light_desc
.dcvColor
).g
= 0.0f
;
5917 U3(light_desc
.dcvColor
).b
= 1.0f
;
5918 U4(light_desc
.dcvColor
).a
= 1.0f
;
5919 U3(light_desc
.dvDirection
).z
= 1.0f
;
5920 hr
= IDirect3DLight_SetLight(light
, &light_desc
);
5921 ok(SUCCEEDED(hr
), "Failed to set light, hr %#x.\n", hr
);
5922 hr
= IDirect3DViewport_AddLight(viewport
, light
);
5923 ok(SUCCEEDED(hr
), "Failed to add a light to the viewport, hr %#x.\n", hr
);
5925 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
5927 hr
= IDirect3DDevice_SetMatrix(device
, world_handle
, tests
[i
].world_matrix
);
5928 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
5930 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
5931 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
5933 hr
= IDirect3DDevice_BeginScene(device
);
5934 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
5936 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
5937 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
5939 memcpy(exec_desc
.lpData
, tests
[i
].quad
, sizeof(nquad
));
5940 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(nquad
);
5941 emit_set_ls(&ptr
, D3DLIGHTSTATE_MATERIAL
, mat_handle
);
5942 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORMLIGHT
, 0, 4);
5943 emit_tquad_tlist(&ptr
, 0);
5945 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
5946 inst_length
-= sizeof(nquad
);
5948 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
5949 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
5951 set_execute_data(execute_buffer
, 4, sizeof(nquad
), inst_length
);
5952 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
5953 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
5955 hr
= IDirect3DDevice_EndScene(device
);
5956 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
5958 color
= get_surface_color(rt
, 320, 240);
5959 todo_wine
ok(color
== tests
[i
].expected
, "%s has color 0x%08x.\n", tests
[i
].message
, color
);
5962 IDirect3DExecuteBuffer_Release(execute_buffer
);
5963 IDirect3DDevice_DeleteMatrix(device
, world_handle
);
5964 IDirect3DDevice_DeleteMatrix(device
, view_handle
);
5965 IDirect3DDevice_DeleteMatrix(device
, proj_handle
);
5966 hr
= IDirect3DViewport_DeleteLight(viewport
, light
);
5967 ok(SUCCEEDED(hr
), "Failed to remove a light from the viewport, hr %#x.\n", hr
);
5968 IDirect3DLight_Release(light
);
5969 destroy_material(material
);
5970 destroy_viewport(device
, viewport
);
5971 IDirectDrawSurface_Release(rt
);
5972 refcount
= IDirect3DDevice_Release(device
);
5973 ok(!refcount
, "Device has %u references left.\n", refcount
);
5974 IDirect3D_Release(d3d
);
5975 refcount
= IDirectDraw_Release(ddraw
);
5976 ok(!refcount
, "Ddraw object has %u references left.\n", refcount
);
5977 DestroyWindow(window
);
5980 static void test_palette_gdi(void)
5982 IDirectDrawSurface
*surface
, *primary
;
5983 DDSURFACEDESC surface_desc
;
5985 IDirectDrawPalette
*palette
, *palette2
;
5989 PALETTEENTRY palette_entries
[256];
5995 /* On the Windows 8 testbot palette index 0 of the onscreen palette is forced to
5996 * r = 0, g = 0, b = 0. Do not attempt to set it to something else as this is
5997 * not the point of this test. */
5998 static const RGBQUAD expected1
[] =
6000 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
6001 {0x03, 0x00, 0x00, 0x00}, {0x15, 0x14, 0x13, 0x00},
6003 static const RGBQUAD expected2
[] =
6005 {0x00, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x01, 0x00}, {0x00, 0x02, 0x00, 0x00},
6006 {0x03, 0x00, 0x00, 0x00}, {0x25, 0x24, 0x23, 0x00},
6008 static const RGBQUAD expected3
[] =
6010 {0x00, 0x00, 0x00, 0x00}, {0x40, 0x00, 0x00, 0x00}, {0x00, 0x00, 0x40, 0x00},
6011 {0x00, 0x40, 0x00, 0x00}, {0x56, 0x34, 0x12, 0x00},
6013 HPALETTE ddraw_palette_handle
;
6014 /* Similar to index 0, index 255 is r = 0xff, g = 0xff, b = 0xff on the Win8 VMs. */
6015 RGBQUAD rgbquad
[255];
6016 static const RGBQUAD rgb_zero
= {0, 0, 0, 0};
6018 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6019 0, 0, 640, 480, 0, 0, 0, 0);
6020 ddraw
= create_ddraw();
6021 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6022 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6023 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6025 memset(&surface_desc
, 0, sizeof(surface_desc
));
6026 surface_desc
.dwSize
= sizeof(surface_desc
);
6027 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6028 surface_desc
.dwWidth
= 16;
6029 surface_desc
.dwHeight
= 16;
6030 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6031 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6032 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_PALETTEINDEXED8
| DDPF_RGB
;
6033 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 8;
6034 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6035 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6037 /* Avoid colors from the Windows default palette. */
6038 memset(palette_entries
, 0, sizeof(palette_entries
));
6039 palette_entries
[1].peRed
= 0x01;
6040 palette_entries
[2].peGreen
= 0x02;
6041 palette_entries
[3].peBlue
= 0x03;
6042 palette_entries
[4].peRed
= 0x13;
6043 palette_entries
[4].peGreen
= 0x14;
6044 palette_entries
[4].peBlue
= 0x15;
6045 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6046 palette_entries
, &palette
, NULL
);
6047 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6049 /* If there is no palette assigned and the display mode is not 8 bpp, some
6050 * drivers refuse to create a DC while others allow it. If a DC is created,
6051 * the DIB color table is uninitialized and contains random colors. No error
6052 * is generated when trying to read pixels and random garbage is returned.
6054 * The most likely explanation is that if the driver creates a DC, it (or
6055 * the higher-level runtime) uses GetSystemPaletteEntries to find the
6056 * palette, but GetSystemPaletteEntries fails when bpp > 8 and the palette
6057 * contains uninitialized garbage. See comments below for the P8 case. */
6059 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
6060 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6061 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
6062 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6063 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
6064 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
),
6065 "Got unexpected palette %p, expected %p.\n",
6066 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
6068 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
6069 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
6070 for (i
= 0; i
< sizeof(expected1
) / sizeof(*expected1
); i
++)
6072 ok(!memcmp(&rgbquad
[i
], &expected1
[i
], sizeof(rgbquad
[i
])),
6073 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6074 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
6075 expected1
[i
].rgbRed
, expected1
[i
].rgbGreen
, expected1
[i
].rgbBlue
);
6077 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
6079 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
6080 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6081 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
6084 /* Update the palette while the DC is in use. This does not modify the DC. */
6085 palette_entries
[4].peRed
= 0x23;
6086 palette_entries
[4].peGreen
= 0x24;
6087 palette_entries
[4].peBlue
= 0x25;
6088 hr
= IDirectDrawPalette_SetEntries(palette
, 0, 4, 1, &palette_entries
[4]);
6089 ok(SUCCEEDED(hr
), "Failed to set palette entries, hr %#x.\n", hr
);
6091 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
6092 ok(i
== 1, "Expected count 1, got %u.\n", i
);
6093 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
6094 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6095 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
6096 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
6098 /* Neither does re-setting the palette. */
6099 hr
= IDirectDrawSurface_SetPalette(surface
, NULL
);
6100 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6101 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
6102 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6104 i
= GetDIBColorTable(dc
, 4, 1, &rgbquad
[4]);
6105 ok(i
== 1, "Expected count 1, got %u.\n", i
);
6106 ok(!memcmp(&rgbquad
[4], &expected1
[4], sizeof(rgbquad
[4])),
6107 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6108 i
, rgbquad
[4].rgbRed
, rgbquad
[4].rgbGreen
, rgbquad
[4].rgbBlue
,
6109 expected1
[4].rgbRed
, expected1
[4].rgbGreen
, expected1
[4].rgbBlue
);
6111 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
6112 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6114 /* Refresh the DC. This updates the palette. */
6115 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
6116 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6117 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
6118 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
6119 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
6121 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
6122 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6123 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
6124 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
6126 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
6128 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
6129 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6130 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
6132 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
6133 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6135 refcount
= IDirectDrawSurface_Release(surface
);
6136 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6138 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_FULLSCREEN
| DDSCL_EXCLUSIVE
);
6139 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6140 if (FAILED(IDirectDraw_SetDisplayMode(ddraw
, 640, 480, 8)))
6142 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6143 IDirectDrawPalette_Release(palette
);
6144 IDirectDraw_Release(ddraw
);
6145 DestroyWindow(window
);
6148 ok(SUCCEEDED(hr
), "Failed to set display mode, hr %#x.\n", hr
);
6150 memset(&surface_desc
, 0, sizeof(surface_desc
));
6151 surface_desc
.dwSize
= sizeof(surface_desc
);
6152 surface_desc
.dwFlags
= DDSD_CAPS
;
6153 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6154 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
6155 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6157 memset(&fx
, 0, sizeof(fx
));
6158 fx
.dwSize
= sizeof(fx
);
6160 SetRect(&r
, 0, 0, 319, 479);
6161 hr
= IDirectDrawSurface_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6162 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
6163 SetRect(&r
, 320, 0, 639, 479);
6165 hr
= IDirectDrawSurface_Blt(primary
, &r
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6166 ok(SUCCEEDED(hr
), "Failed to clear surface, hr %#x.\n", hr
);
6168 hr
= IDirectDrawSurface_SetPalette(primary
, palette
);
6169 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6170 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
6171 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6173 color
= GetPixel(dc
, 160, 240);
6174 ok(color
== 0x00030000, "Clear index 3: Got unexpected color 0x%08x.\n", color
);
6175 color
= GetPixel(dc
, 480, 240);
6176 ok(color
== 0x00252423, "Clear index 4: Got unexpected color 0x%08x.\n", color
);
6178 ddraw_palette_handle
= SelectPalette(dc
, GetStockObject(DEFAULT_PALETTE
), FALSE
);
6179 /* Windows 2000 on the testbot assigns a different palette to the primary. Refrast? */
6180 ok(ddraw_palette_handle
== GetStockObject(DEFAULT_PALETTE
) || broken(TRUE
),
6181 "Got unexpected palette %p, expected %p.\n",
6182 ddraw_palette_handle
, GetStockObject(DEFAULT_PALETTE
));
6183 SelectPalette(dc
, ddraw_palette_handle
, FALSE
);
6185 /* The primary uses the system palette. In exclusive mode, the system palette matches
6186 * the ddraw palette attached to the primary, so the result is what you would expect
6187 * from a regular surface. Tests for the interaction between the ddraw palette and
6188 * the system palette are not included pending an application that depends on this.
6189 * The relation between those causes problems on Windows Vista and newer for games
6190 * like Age of Empires or StarCraft. Don't emulate it without a real need. */
6191 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
6192 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
6193 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
6195 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
6196 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6197 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
6198 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
6200 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
6202 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
6203 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6204 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
6206 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
6207 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6209 memset(&surface_desc
, 0, sizeof(surface_desc
));
6210 surface_desc
.dwSize
= sizeof(surface_desc
);
6211 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6212 surface_desc
.dwWidth
= 16;
6213 surface_desc
.dwHeight
= 16;
6214 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6215 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6216 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6218 /* Here the offscreen surface appears to use the primary's palette,
6219 * but in all likelihood it is actually the system palette. */
6220 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
6221 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6222 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
6223 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
6224 for (i
= 0; i
< sizeof(expected2
) / sizeof(*expected2
); i
++)
6226 ok(!memcmp(&rgbquad
[i
], &expected2
[i
], sizeof(rgbquad
[i
])),
6227 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6228 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
6229 expected2
[i
].rgbRed
, expected2
[i
].rgbGreen
, expected2
[i
].rgbBlue
);
6231 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
6233 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
6234 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6235 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
6237 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
6238 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6240 /* On real hardware a change to the primary surface's palette applies immediately,
6241 * even on device contexts from offscreen surfaces that do not have their own
6242 * palette. On the testbot VMs this is not the case. Don't test this until we
6243 * know of an application that depends on this. */
6245 memset(palette_entries
, 0, sizeof(palette_entries
));
6246 palette_entries
[1].peBlue
= 0x40;
6247 palette_entries
[2].peRed
= 0x40;
6248 palette_entries
[3].peGreen
= 0x40;
6249 palette_entries
[4].peRed
= 0x12;
6250 palette_entries
[4].peGreen
= 0x34;
6251 palette_entries
[4].peBlue
= 0x56;
6252 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_8BIT
| DDPCAPS_ALLOW256
,
6253 palette_entries
, &palette2
, NULL
);
6254 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6255 hr
= IDirectDrawSurface_SetPalette(surface
, palette2
);
6256 ok(SUCCEEDED(hr
), "Failed to set palette, hr %#x.\n", hr
);
6258 /* A palette assigned to the offscreen surface overrides the primary / system
6260 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
6261 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
6262 i
= GetDIBColorTable(dc
, 0, sizeof(rgbquad
) / sizeof(*rgbquad
), rgbquad
);
6263 ok(i
== sizeof(rgbquad
) / sizeof(*rgbquad
), "Expected count 255, got %u.\n", i
);
6264 for (i
= 0; i
< sizeof(expected3
) / sizeof(*expected3
); i
++)
6266 ok(!memcmp(&rgbquad
[i
], &expected3
[i
], sizeof(rgbquad
[i
])),
6267 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=%#x g=%#x b=%#x.\n",
6268 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
,
6269 expected3
[i
].rgbRed
, expected3
[i
].rgbGreen
, expected3
[i
].rgbBlue
);
6271 for (; i
< sizeof(rgbquad
) / sizeof(*rgbquad
); i
++)
6273 ok(!memcmp(&rgbquad
[i
], &rgb_zero
, sizeof(rgbquad
[i
])),
6274 "Got color table entry %u r=%#x g=%#x b=%#x, expected r=0 g=0 b=0.\n",
6275 i
, rgbquad
[i
].rgbRed
, rgbquad
[i
].rgbGreen
, rgbquad
[i
].rgbBlue
);
6277 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
6278 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6280 refcount
= IDirectDrawSurface_Release(surface
);
6281 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6283 /* The Windows 8 testbot keeps extra references to the primary and
6284 * backbuffer while in 8 bpp mode. */
6285 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
6286 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
6288 refcount
= IDirectDrawSurface_Release(primary
);
6289 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6290 refcount
= IDirectDrawPalette_Release(palette2
);
6291 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6292 refcount
= IDirectDrawPalette_Release(palette
);
6293 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6294 refcount
= IDirectDraw_Release(ddraw
);
6295 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6296 DestroyWindow(window
);
6299 static void test_palette_alpha(void)
6301 IDirectDrawSurface
*surface
;
6302 DDSURFACEDESC surface_desc
;
6304 IDirectDrawPalette
*palette
;
6308 PALETTEENTRY palette_entries
[256];
6313 BOOL attach_allowed
;
6318 {DDSCAPS_OFFSCREENPLAIN
, DDSD_WIDTH
| DDSD_HEIGHT
, FALSE
, "offscreenplain"},
6319 {DDSCAPS_TEXTURE
, DDSD_WIDTH
| DDSD_HEIGHT
, TRUE
, "texture"},
6320 {DDSCAPS_PRIMARYSURFACE
, 0, FALSE
, "primary"}
6323 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6324 0, 0, 640, 480, 0, 0, 0, 0);
6325 ddraw
= create_ddraw();
6326 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6327 if (FAILED(IDirectDraw_SetDisplayMode(ddraw
, 640, 480, 8)))
6329 win_skip("Failed to set 8 bpp display mode, skipping test.\n");
6330 IDirectDraw_Release(ddraw
);
6331 DestroyWindow(window
);
6334 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6335 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6337 memset(palette_entries
, 0, sizeof(palette_entries
));
6338 palette_entries
[1].peFlags
= 0x42;
6339 palette_entries
[2].peFlags
= 0xff;
6340 palette_entries
[3].peFlags
= 0x80;
6341 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
, palette_entries
, &palette
, NULL
);
6342 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6344 memset(palette_entries
, 0x66, sizeof(palette_entries
));
6345 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
6346 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
6347 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6348 palette_entries
[0].peFlags
);
6349 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6350 palette_entries
[1].peFlags
);
6351 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
6352 palette_entries
[2].peFlags
);
6353 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
6354 palette_entries
[3].peFlags
);
6356 IDirectDrawPalette_Release(palette
);
6358 memset(palette_entries
, 0, sizeof(palette_entries
));
6359 palette_entries
[1].peFlags
= 0x42;
6360 palette_entries
[1].peRed
= 0xff;
6361 palette_entries
[2].peFlags
= 0xff;
6362 palette_entries
[3].peFlags
= 0x80;
6363 hr
= IDirectDraw_CreatePalette(ddraw
, DDPCAPS_ALLOW256
| DDPCAPS_8BIT
| DDPCAPS_ALPHA
,
6364 palette_entries
, &palette
, NULL
);
6365 ok(SUCCEEDED(hr
), "Failed to create palette, hr %#x.\n", hr
);
6367 memset(palette_entries
, 0x66, sizeof(palette_entries
));
6368 hr
= IDirectDrawPalette_GetEntries(palette
, 0, 1, 4, palette_entries
);
6369 ok(SUCCEEDED(hr
), "Failed to get palette entries, hr %#x.\n", hr
);
6370 ok(palette_entries
[0].peFlags
== 0x42, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6371 palette_entries
[0].peFlags
);
6372 ok(palette_entries
[1].peFlags
== 0xff, "Got unexpected peFlags 0x%02x, expected 0xff.\n",
6373 palette_entries
[1].peFlags
);
6374 ok(palette_entries
[2].peFlags
== 0x80, "Got unexpected peFlags 0x%02x, expected 0x80.\n",
6375 palette_entries
[2].peFlags
);
6376 ok(palette_entries
[3].peFlags
== 0x00, "Got unexpected peFlags 0x%02x, expected 0x00.\n",
6377 palette_entries
[3].peFlags
);
6379 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); i
++)
6381 memset(&surface_desc
, 0, sizeof(surface_desc
));
6382 surface_desc
.dwSize
= sizeof(surface_desc
);
6383 surface_desc
.dwFlags
= DDSD_CAPS
| test_data
[i
].flags
;
6384 surface_desc
.dwWidth
= 128;
6385 surface_desc
.dwHeight
= 128;
6386 surface_desc
.ddsCaps
.dwCaps
= test_data
[i
].caps
;
6387 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6388 ok(SUCCEEDED(hr
), "Failed to create %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
6390 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
6391 if (test_data
[i
].attach_allowed
)
6392 ok(SUCCEEDED(hr
), "Failed to attach palette to %s surface, hr %#x.\n", test_data
[i
].name
, hr
);
6394 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
6402 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
6403 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_CANTCREATEDC
) /* Win2k testbot */,
6404 "Failed to get DC, hr %#x, %s surface.\n", hr
, test_data
[i
].name
);
6407 retval
= GetDIBColorTable(dc
, 1, 1, &rgbquad
);
6408 ok(retval
== 1, "GetDIBColorTable returned unexpected result %u.\n", retval
);
6409 ok(rgbquad
.rgbRed
== 0xff, "Expected rgbRed = 0xff, got %#x, %s surface.\n",
6410 rgbquad
.rgbRed
, test_data
[i
].name
);
6411 ok(rgbquad
.rgbGreen
== 0, "Expected rgbGreen = 0, got %#x, %s surface.\n",
6412 rgbquad
.rgbGreen
, test_data
[i
].name
);
6413 ok(rgbquad
.rgbBlue
== 0, "Expected rgbBlue = 0, got %#x, %s surface.\n",
6414 rgbquad
.rgbBlue
, test_data
[i
].name
);
6415 todo_wine
ok(rgbquad
.rgbReserved
== 0, "Expected rgbReserved = 0, got %u, %s surface.\n",
6416 rgbquad
.rgbReserved
, test_data
[i
].name
);
6417 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
6418 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
6421 IDirectDrawSurface_Release(surface
);
6424 /* Test INVALIDSURFACETYPE vs INVALIDPIXELFORMAT. */
6425 memset(&surface_desc
, 0, sizeof(surface_desc
));
6426 surface_desc
.dwSize
= sizeof(surface_desc
);
6427 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
6428 surface_desc
.dwWidth
= 128;
6429 surface_desc
.dwHeight
= 128;
6430 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6431 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
6432 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6433 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6434 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6435 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6436 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6437 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6438 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6439 hr
= IDirectDrawSurface_SetPalette(surface
, palette
);
6440 ok(hr
== DDERR_INVALIDSURFACETYPE
, "Got unexpected hr %#x.\n", hr
);
6441 IDirectDrawSurface_Release(surface
);
6443 /* The Windows 8 testbot keeps extra references to the primary
6444 * while in 8 bpp mode. */
6445 hr
= IDirectDraw_RestoreDisplayMode(ddraw
);
6446 ok(SUCCEEDED(hr
), "Failed to restore display mode, hr %#x.\n", hr
);
6448 refcount
= IDirectDrawPalette_Release(palette
);
6449 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6450 refcount
= IDirectDraw_Release(ddraw
);
6451 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6452 DestroyWindow(window
);
6455 static void test_lost_device(void)
6457 IDirectDrawSurface
*surface
;
6458 DDSURFACEDESC surface_desc
;
6459 HWND window1
, window2
;
6465 window1
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6466 0, 0, 640, 480, 0, 0, 0, 0);
6467 window2
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6468 0, 0, 640, 480, 0, 0, 0, 0);
6469 ddraw
= create_ddraw();
6470 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6471 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6472 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6474 memset(&surface_desc
, 0, sizeof(surface_desc
));
6475 surface_desc
.dwSize
= sizeof(surface_desc
);
6476 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6477 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6478 surface_desc
.dwBackBufferCount
= 1;
6479 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6480 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6482 hr
= IDirectDrawSurface_IsLost(surface
);
6483 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6484 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6485 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6487 ret
= SetForegroundWindow(GetDesktopWindow());
6488 ok(ret
, "Failed to set foreground window.\n");
6489 hr
= IDirectDrawSurface_IsLost(surface
);
6490 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6491 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6492 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6494 ret
= SetForegroundWindow(window1
);
6495 ok(ret
, "Failed to set foreground window.\n");
6496 hr
= IDirectDrawSurface_IsLost(surface
);
6497 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6498 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6499 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6501 hr
= restore_surfaces(ddraw
);
6502 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6503 hr
= IDirectDrawSurface_IsLost(surface
);
6504 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6505 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6506 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6508 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
6509 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6510 hr
= IDirectDrawSurface_IsLost(surface
);
6511 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6512 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6513 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
6515 /* Trying to restore the primary will crash, probably because flippable
6516 * surfaces can't exist in DDSCL_NORMAL. */
6517 IDirectDrawSurface_Release(surface
);
6518 memset(&surface_desc
, 0, sizeof(surface_desc
));
6519 surface_desc
.dwSize
= sizeof(surface_desc
);
6520 surface_desc
.dwFlags
= DDSD_CAPS
;
6521 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
6522 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6523 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6525 hr
= IDirectDrawSurface_IsLost(surface
);
6526 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6528 ret
= SetForegroundWindow(GetDesktopWindow());
6529 ok(ret
, "Failed to set foreground window.\n");
6530 hr
= IDirectDrawSurface_IsLost(surface
);
6531 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6533 ret
= SetForegroundWindow(window1
);
6534 ok(ret
, "Failed to set foreground window.\n");
6535 hr
= IDirectDrawSurface_IsLost(surface
);
6536 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6538 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6539 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6540 hr
= IDirectDrawSurface_IsLost(surface
);
6541 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6543 hr
= restore_surfaces(ddraw
);
6544 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6545 hr
= IDirectDrawSurface_IsLost(surface
);
6546 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6548 IDirectDrawSurface_Release(surface
);
6549 memset(&surface_desc
, 0, sizeof(surface_desc
));
6550 surface_desc
.dwSize
= sizeof(surface_desc
);
6551 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_BACKBUFFERCOUNT
;
6552 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
| DDSCAPS_COMPLEX
| DDSCAPS_FLIP
;
6553 U5(surface_desc
).dwBackBufferCount
= 1;
6554 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6555 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6557 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window1
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6558 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6559 hr
= IDirectDrawSurface_IsLost(surface
);
6560 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6561 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6562 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6564 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
6565 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6566 hr
= IDirectDrawSurface_IsLost(surface
);
6567 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6568 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6569 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
6571 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window1
, DDSCL_NORMAL
);
6572 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6573 hr
= IDirectDrawSurface_IsLost(surface
);
6574 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6575 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6576 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
6578 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
);
6579 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6580 hr
= IDirectDrawSurface_IsLost(surface
);
6581 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6582 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6583 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
6585 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window2
, DDSCL_NORMAL
| DDSCL_FULLSCREEN
);
6586 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6587 hr
= IDirectDrawSurface_IsLost(surface
);
6588 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6589 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6590 ok(hr
== DDERR_NOEXCLUSIVEMODE
, "Got unexpected hr %#x.\n", hr
);
6592 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window2
, DDSCL_EXCLUSIVE
| DDSCL_FULLSCREEN
);
6593 ok(hr
== DD_OK
, "Got unexpected hr %#x.\n", hr
);
6594 hr
= IDirectDrawSurface_IsLost(surface
);
6595 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6596 hr
= IDirectDrawSurface_Flip(surface
, NULL
, DDFLIP_WAIT
);
6597 ok(hr
== DDERR_SURFACELOST
, "Got unexpected hr %#x.\n", hr
);
6599 IDirectDrawSurface_Release(surface
);
6600 refcount
= IDirectDraw_Release(ddraw
);
6601 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6602 DestroyWindow(window2
);
6603 DestroyWindow(window1
);
6606 static void test_surface_desc_lock(void)
6608 IDirectDrawSurface
*surface
;
6609 DDSURFACEDESC surface_desc
;
6615 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6616 0, 0, 640, 480, 0, 0, 0, 0);
6617 ddraw
= create_ddraw();
6618 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6619 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
6620 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
6622 memset(&surface_desc
, 0, sizeof(surface_desc
));
6623 surface_desc
.dwSize
= sizeof(surface_desc
);
6624 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
;
6625 surface_desc
.dwWidth
= 16;
6626 surface_desc
.dwHeight
= 16;
6627 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
6628 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
6629 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6631 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
6632 surface_desc
.dwSize
= sizeof(surface_desc
);
6633 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
6634 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6635 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
6637 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
6638 surface_desc
.dwSize
= sizeof(surface_desc
);
6639 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, 0, NULL
);
6640 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
6641 ok(surface_desc
.lpSurface
!= NULL
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
6642 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
6643 surface_desc
.dwSize
= sizeof(surface_desc
);
6644 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
6645 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6646 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
6647 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
6648 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
6650 memset(&surface_desc
, 0xaa, sizeof(surface_desc
));
6651 surface_desc
.dwSize
= sizeof(surface_desc
);
6652 hr
= IDirectDrawSurface_GetSurfaceDesc(surface
, &surface_desc
);
6653 ok(SUCCEEDED(hr
), "Failed to get surface desc, hr %#x.\n", hr
);
6654 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
6656 IDirectDrawSurface_Release(surface
);
6657 refcount
= IDirectDraw_Release(ddraw
);
6658 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
6659 DestroyWindow(window
);
6662 static void test_texturemapblend(void)
6666 D3DEXECUTEBUFFERDESC exec_desc
;
6668 static RECT rect
= {0, 0, 64, 128};
6669 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
6671 IDirectDrawSurface
*surface
, *rt
;
6672 IDirect3DTexture
*texture
;
6673 D3DTEXTUREHANDLE texture_handle
;
6676 IDirect3DDevice
*device
;
6677 IDirect3DMaterial
*material
;
6678 IDirect3DViewport
*viewport
;
6679 IDirect3DExecuteBuffer
*execute_buffer
;
6685 static const D3DTLVERTEX test1_quads
[] =
6687 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {0.0f
}},
6688 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {0.0f
}, {1.0f
}},
6689 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {0.0f
}},
6690 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0xffffffff}, {0}, {1.0f
}, {1.0f
}},
6691 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {0.0f
}},
6692 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {0.0f
}, {1.0f
}},
6693 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {0.0f
}},
6694 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x80ffffff}, {0}, {1.0f
}, {1.0f
}},
6698 {{0.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {0.0f
}},
6699 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {0.0f
}, {1.0f
}},
6700 {{640.0f
}, {0.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {0.0f
}},
6701 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x00ff0080}, {0}, {1.0f
}, {1.0f
}},
6702 {{0.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {0.0f
}},
6703 {{0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {0.0f
}, {1.0f
}},
6704 {{640.0f
}, {240.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {0.0f
}},
6705 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x008000ff}, {0}, {1.0f
}, {1.0f
}},
6708 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
6709 0, 0, 640, 480, 0, 0, 0, 0);
6710 ddraw
= create_ddraw();
6711 ok(!!ddraw
, "Failed to create a ddraw object.\n");
6712 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
6714 skip("Failed to create a 3D device, skipping test.\n");
6715 DestroyWindow(window
);
6716 IDirectDraw_Release(ddraw
);
6720 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
6721 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
6723 material
= create_diffuse_material(device
, 0.0f
, 0.0f
, 0.0f
, 1.0f
);
6724 viewport
= create_viewport(device
, 0, 0, 640, 480);
6725 viewport_set_background(device
, viewport
, material
);
6727 memset(&exec_desc
, 0, sizeof(exec_desc
));
6728 exec_desc
.dwSize
= sizeof(exec_desc
);
6729 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
6730 exec_desc
.dwBufferSize
= 1024;
6731 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
6732 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
6733 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
6735 /* Test alpha with DDPF_ALPHAPIXELS texture - should be taken from texture alpha channel.
6737 * The vertex alpha is completely ignored in this case, so case 1 and 2 combined are not
6738 * a D3DTOP_MODULATE with texture alpha = 0xff in case 2 (no alpha in texture). */
6739 memset(&ddsd
, 0, sizeof(ddsd
));
6740 ddsd
.dwSize
= sizeof(ddsd
);
6741 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
6742 ddsd
.dwHeight
= 128;
6744 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6745 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
6746 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6747 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6748 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6749 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6750 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6751 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6752 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6753 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6755 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
6756 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
6757 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
6758 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
6760 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6761 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
6763 memset(&fx
, 0, sizeof(fx
));
6764 fx
.dwSize
= sizeof(fx
);
6765 U5(fx
).dwFillColor
= 0xff0000ff;
6766 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6767 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6768 U5(fx
).dwFillColor
= 0x800000ff;
6769 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6770 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6772 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
6773 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
6775 memcpy(exec_desc
.lpData
, test1_quads
, sizeof(test1_quads
));
6777 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(test1_quads
);
6778 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 8);
6779 emit_set_rs(&ptr
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
6780 emit_set_rs(&ptr
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
6781 emit_set_rs(&ptr
, D3DRENDERSTATE_SRCBLEND
, D3DBLEND_SRCALPHA
);
6782 emit_set_rs(&ptr
, D3DRENDERSTATE_DESTBLEND
, D3DBLEND_INVSRCALPHA
);
6783 /* The history of D3DRENDERSTATE_ALPHABLENDENABLE is quite a mess. In the
6784 * first D3D release there was a D3DRENDERSTATE_BLENDENABLE (enum value 27).
6785 * D3D5 introduced a new and separate D3DRENDERSTATE_ALPHABLENDENABLE (42)
6786 * together with D3DRENDERSTATE_COLORKEYENABLE (41). The docs aren't all
6787 * that clear but they mention that D3DRENDERSTATE_BLENDENABLE overrides the
6789 * Then D3D6 came and got rid of the new D3DRENDERSTATE_ALPHABLENDENABLE
6790 * state (42), renaming the older D3DRENDERSTATE_BLENDENABLE enum (27)
6791 * as D3DRENDERSTATE_ALPHABLENDENABLE.
6792 * There is a comment in the D3D6 docs which mentions that hardware
6793 * rasterizers always used D3DRENDERSTATE_BLENDENABLE to just toggle alpha
6794 * blending while prior to D3D5 software rasterizers toggled both color
6795 * keying and alpha blending according to it. What I gather is that, from
6796 * D3D6 onwards, D3DRENDERSTATE_ALPHABLENDENABLE always only toggles the
6797 * alpha blending state.
6798 * These tests seem to show that actual, current hardware follows the D3D6
6799 * behavior even when using the original D3D interfaces, for the HAL device
6801 emit_set_rs(&ptr
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
6802 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATE
);
6803 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
6805 emit_tquad(&ptr
, 0);
6806 emit_tquad(&ptr
, 4);
6809 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
6810 inst_length
-= sizeof(test1_quads
);
6811 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
6812 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
6813 set_execute_data(execute_buffer
, 8, sizeof(test1_quads
), inst_length
);
6815 hr
= IDirect3DDevice_BeginScene(device
);
6816 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6817 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_UNCLIPPED
);
6818 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
6819 hr
= IDirect3DDevice_EndScene(device
);
6820 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6822 color
= get_surface_color(rt
, 5, 5);
6823 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
6824 color
= get_surface_color(rt
, 400, 5);
6825 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
6826 color
= get_surface_color(rt
, 5, 245);
6827 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
6828 color
= get_surface_color(rt
, 400, 245);
6829 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
6831 IDirect3DTexture_Release(texture
);
6832 ref
= IDirectDrawSurface_Release(surface
);
6833 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
6835 /* Test alpha with texture that has no alpha channel - alpha should be taken from diffuse vertex color. */
6836 memset(&ddsd
, 0, sizeof(ddsd
));
6837 ddsd
.dwSize
= sizeof(ddsd
);
6838 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
6839 ddsd
.dwHeight
= 128;
6841 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6842 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
6843 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6844 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6845 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6846 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6847 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6849 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6850 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6852 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
6853 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
6854 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
6855 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
6857 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6858 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
6860 U5(fx
).dwFillColor
= 0xff0000ff;
6861 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6862 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6863 U5(fx
).dwFillColor
= 0x800000ff;
6864 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6865 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6867 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
6868 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
6870 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(test1_quads
);
6871 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 8);
6872 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
6874 emit_tquad(&ptr
, 0);
6875 emit_tquad(&ptr
, 4);
6878 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
6879 inst_length
-= sizeof(test1_quads
);
6880 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
6881 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
6882 set_execute_data(execute_buffer
, 8, sizeof(test1_quads
), inst_length
);
6884 hr
= IDirect3DDevice_BeginScene(device
);
6885 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6886 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_UNCLIPPED
);
6887 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
6888 hr
= IDirect3DDevice_EndScene(device
);
6889 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6891 color
= get_surface_color(rt
, 5, 5);
6892 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
6893 color
= get_surface_color(rt
, 400, 5);
6894 ok(compare_color(color
, 0x000000ff, 2), "Got unexpected color 0x%08x.\n", color
);
6895 color
= get_surface_color(rt
, 5, 245);
6896 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
6897 color
= get_surface_color(rt
, 400, 245);
6898 ok(compare_color(color
, 0x00000080, 2), "Got unexpected color 0x%08x.\n", color
);
6900 IDirect3DTexture_Release(texture
);
6901 ref
= IDirectDrawSurface_Release(surface
);
6902 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
6904 /* Test RGB - should multiply color components from diffuse vertex color and texture. */
6905 memset(&ddsd
, 0, sizeof(ddsd
));
6906 ddsd
.dwSize
= sizeof(ddsd
);
6907 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
6908 ddsd
.dwHeight
= 128;
6910 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6911 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
6912 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
| DDPF_ALPHAPIXELS
;
6913 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 32;
6914 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
6915 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
6916 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
6917 U5(ddsd
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0xff000000;
6918 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
6919 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
6921 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
6922 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
6923 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
6924 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
6926 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
6927 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
6929 U5(fx
).dwFillColor
= 0x00ffffff;
6930 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6931 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6932 U5(fx
).dwFillColor
= 0x00ffff80;
6933 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
6934 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
6936 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
6937 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
6939 memcpy(exec_desc
.lpData
, test2_quads
, sizeof(test2_quads
));
6941 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(test2_quads
);
6942 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 8);
6943 emit_set_rs(&ptr
, D3DRENDERSTATE_ALPHABLENDENABLE
, FALSE
);
6944 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
6946 emit_tquad(&ptr
, 0);
6947 emit_tquad(&ptr
, 4);
6950 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
6951 inst_length
-= sizeof(test2_quads
);
6952 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
6953 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
6954 set_execute_data(execute_buffer
, 8, sizeof(test2_quads
), inst_length
);
6956 hr
= IDirect3DDevice_BeginScene(device
);
6957 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
6958 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_UNCLIPPED
);
6959 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
6960 hr
= IDirect3DDevice_EndScene(device
);
6961 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
6963 /* WARP (Win8 testbot) emulates color keying with the alpha channel like Wine does,
6964 * but even applies it when there's no color key assigned. The surface alpha is zero
6965 * here, so nothing gets drawn.
6967 * The ddraw2 version of this test draws these quads with color keying off due to
6968 * different defaults in ddraw1 and ddraw2. */
6969 color
= get_surface_color(rt
, 5, 5);
6970 ok(compare_color(color
, 0x00ff0040, 2) || broken(compare_color(color
, 0x00000000, 1)),
6971 "Got unexpected color 0x%08x.\n", color
);
6972 color
= get_surface_color(rt
, 400, 5);
6973 ok(compare_color(color
, 0x00ff0080, 2) || broken(compare_color(color
, 0x00000000, 1)),
6974 "Got unexpected color 0x%08x.\n", color
);
6975 color
= get_surface_color(rt
, 5, 245);
6976 ok(compare_color(color
, 0x00800080, 2) || broken(compare_color(color
, 0x00000000, 1)),
6977 "Got unexpected color 0x%08x.\n", color
);
6978 color
= get_surface_color(rt
, 400, 245);
6979 ok(compare_color(color
, 0x008000ff, 2) || broken(compare_color(color
, 0x00000000, 1)),
6980 "Got unexpected color 0x%08x.\n", color
);
6982 IDirect3DTexture_Release(texture
);
6983 ref
= IDirectDrawSurface_Release(surface
);
6984 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
6986 /* Test alpha again, now with color keyed texture (colorkey emulation in wine can interfere). */
6987 memset(&ddsd
, 0, sizeof(ddsd
));
6988 ddsd
.dwSize
= sizeof(ddsd
);
6989 ddsd
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
6990 ddsd
.dwHeight
= 128;
6992 ddsd
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
6993 ddsd
.ddpfPixelFormat
.dwSize
= sizeof(ddsd
.ddpfPixelFormat
);
6994 ddsd
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
6995 U1(ddsd
.ddpfPixelFormat
).dwRGBBitCount
= 16;
6996 U2(ddsd
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
6997 U3(ddsd
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
6998 U4(ddsd
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
7000 hr
= IDirectDraw_CreateSurface(ddraw
, &ddsd
, &surface
, NULL
);
7001 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7003 hr
= IDirectDrawSurface_QueryInterface(surface
, &IID_IDirect3DTexture
, (void **)&texture
);
7004 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
7005 hr
= IDirect3DTexture_GetHandle(texture
, device
, &texture_handle
);
7006 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
7008 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7009 ok(SUCCEEDED(hr
), "Failed to clear render target, hr %#x.\n", hr
);
7011 U5(fx
).dwFillColor
= 0xf800;
7012 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7013 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7014 U5(fx
).dwFillColor
= 0x001f;
7015 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7016 ok(SUCCEEDED(hr
), "Failed to clear texture, hr %#x.\n", hr
);
7018 ckey
.dwColorSpaceLowValue
= 0x001f;
7019 ckey
.dwColorSpaceHighValue
= 0x001f;
7020 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
7021 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
7023 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
7024 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
7026 memcpy(exec_desc
.lpData
, test1_quads
, sizeof(test1_quads
));
7028 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(test1_quads
);
7029 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 8);
7030 emit_set_rs(&ptr
, D3DRENDERSTATE_ALPHABLENDENABLE
, TRUE
);
7031 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, texture_handle
);
7032 /* D3DRENDERSTATE_COLORKEYENABLE is supposed to be on by default on version
7033 * 1 devices, but for some reason it randomly defaults to FALSE on the W8
7034 * testbot. This is either the fault of Windows 8 or the WARP driver.
7035 * Also D3DRENDERSTATE_COLORKEYENABLE was introduced in D3D 5 aka version 2
7036 * devices only, which might imply this doesn't actually do anything on
7038 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
7040 emit_tquad(&ptr
, 0);
7041 emit_tquad(&ptr
, 4);
7044 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
7045 inst_length
-= sizeof(test1_quads
);
7046 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
7047 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
7048 set_execute_data(execute_buffer
, 8, sizeof(test1_quads
), inst_length
);
7050 hr
= IDirect3DDevice_BeginScene(device
);
7051 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7052 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_UNCLIPPED
);
7053 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
7054 hr
= IDirect3DDevice_EndScene(device
);
7055 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7057 /* Allow broken WARP results (colorkey disabled). */
7058 color
= get_surface_color(rt
, 5, 5);
7059 ok(compare_color(color
, 0x00000000, 2) || broken(compare_color(color
, 0x000000ff, 2)),
7060 "Got unexpected color 0x%08x.\n", color
);
7061 color
= get_surface_color(rt
, 400, 5);
7062 ok(compare_color(color
, 0x00ff0000, 2), "Got unexpected color 0x%08x.\n", color
);
7063 color
= get_surface_color(rt
, 5, 245);
7064 ok(compare_color(color
, 0x00000000, 2) || broken(compare_color(color
, 0x00000080, 2)),
7065 "Got unexpected color 0x%08x.\n", color
);
7066 color
= get_surface_color(rt
, 400, 245);
7067 ok(compare_color(color
, 0x00800000, 2), "Got unexpected color 0x%08x.\n", color
);
7069 IDirect3DTexture_Release(texture
);
7070 ref
= IDirectDrawSurface_Release(surface
);
7071 ok(ref
== 0, "Surface not properly released, refcount %u.\n", ref
);
7073 ref
= IDirect3DExecuteBuffer_Release(execute_buffer
);
7074 ok(ref
== 0, "Execute buffer not properly released, refcount %u.\n", ref
);
7075 destroy_viewport(device
, viewport
);
7076 ref
= IDirect3DMaterial_Release(material
);
7077 ok(ref
== 0, "Material not properly released, refcount %u.\n", ref
);
7078 IDirectDrawSurface_Release(rt
);
7079 IDirect3DDevice_Release(device
);
7080 ref
= IDirectDraw_Release(ddraw
);
7081 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
7082 DestroyWindow(window
);
7085 static void test_viewport_clear_rect(void)
7088 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7089 static D3DRECT clear_rect2
= {{90}, {90}, {110}, {110}};
7090 IDirectDrawSurface
*rt
;
7093 IDirect3DDevice
*device
;
7094 IDirect3DMaterial
*red
, *green
;
7095 IDirect3DViewport
*viewport
, *viewport2
;
7099 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7100 0, 0, 640, 480, 0, 0, 0, 0);
7101 ddraw
= create_ddraw();
7102 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7103 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
7105 skip("Failed to create a 3D device, skipping test.\n");
7106 DestroyWindow(window
);
7107 IDirectDraw_Release(ddraw
);
7111 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
7112 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
7114 red
= create_diffuse_material(device
, 1.0f
, 0.0f
, 0.0f
, 1.0f
);
7115 viewport
= create_viewport(device
, 0, 0, 640, 480);
7116 viewport_set_background(device
, viewport
, red
);
7117 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7118 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7120 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 1.0f
);
7121 viewport2
= create_viewport(device
, 100, 100, 20, 20);
7122 viewport_set_background(device
, viewport2
, green
);
7123 hr
= IDirect3DViewport_Clear(viewport2
, 1, &clear_rect2
, D3DCLEAR_TARGET
);
7124 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
7126 color
= get_surface_color(rt
, 85, 85); /* Outside both. */
7127 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
7128 color
= get_surface_color(rt
, 95, 95); /* Outside vp, inside rect. */
7129 /* AMD GPUs ignore the viewport dimensions and only care about the rectangle. */
7130 ok(compare_color(color
, 0x00ff0000, 1) || broken(compare_color(color
, 0x0000ff00, 1)),
7131 "Got unexpected color 0x%08x.\n", color
);
7132 color
= get_surface_color(rt
, 105, 105); /* Inside both. */
7133 ok(compare_color(color
, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color
);
7134 color
= get_surface_color(rt
, 115, 115); /* Inside vp, outside rect. */
7135 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
7136 color
= get_surface_color(rt
, 125, 125); /* Outside both. */
7137 ok(compare_color(color
, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color
);
7139 destroy_viewport(device
, viewport2
);
7140 destroy_material(green
);
7141 destroy_viewport(device
, viewport
);
7142 destroy_material(red
);
7143 IDirectDrawSurface_Release(rt
);
7144 IDirect3DDevice_Release(device
);
7145 ref
= IDirectDraw_Release(ddraw
);
7146 ok(ref
== 0, "Ddraw object not properly released, refcount %u.\n", ref
);
7147 DestroyWindow(window
);
7150 static void test_color_fill(void)
7153 IDirect3DDevice
*device
;
7155 IDirectDrawSurface
*surface
, *surface2
;
7156 DDSURFACEDESC surface_desc
;
7161 RECT rect
= {5, 5, 7, 7};
7163 DWORD num_fourcc_codes
, *fourcc_codes
;
7165 BOOL support_uyvy
= FALSE
, support_yuy2
= FALSE
;
7169 HRESULT colorfill_hr
, depthfill_hr
;
7174 DDPIXELFORMAT format
;
7179 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
7180 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain RGB", 0xdeadbeef, TRUE
,
7182 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
7183 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7187 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
7188 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain RGB", 0xdeadbeef, TRUE
,
7190 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
7191 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7195 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
7196 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem texture RGB", 0xdeadbeef, TRUE
,
7198 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
7199 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7203 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
7204 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem texture RGB", 0xdeadbeef, TRUE
,
7206 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
7207 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}
7211 DDSCAPS_ZBUFFER
| DDSCAPS_VIDEOMEMORY
,
7212 DDERR_INVALIDPARAMS
, DD_OK
, TRUE
, "vidmem zbuffer", 0, FALSE
,
7213 {0, 0, 0, {0}, {0}, {0}, {0}, {0}}
7216 /* Colorfill on YUV surfaces always returns DD_OK, but the content is
7217 * different afterwards. DX9+ GPUs set one of the two luminance values
7218 * in each block, but AMD and Nvidia GPUs disagree on which luminance
7219 * value they set. r200 (dx8) just sets the entire block to the clear
7221 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
7222 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain YUY2", 0, FALSE
,
7224 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
7225 {0}, {0}, {0}, {0}, {0}
7229 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
7230 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem offscreenplain UYVY", 0, FALSE
,
7232 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
7233 {0}, {0}, {0}, {0}, {0}
7237 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
7238 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay YUY2", 0, FALSE
,
7240 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('Y', 'U', 'Y', '2'),
7241 {0}, {0}, {0}, {0}, {0}
7245 DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
,
7246 DD_OK
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem overlay UYVY", 0, FALSE
,
7248 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('U', 'Y', 'V', 'Y'),
7249 {0}, {0}, {0}, {0}, {0}
7253 DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
,
7254 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "vidmem texture DXT1", 0, FALSE
,
7256 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
7257 {0}, {0}, {0}, {0}, {0}
7261 DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
,
7262 E_NOTIMPL
, DDERR_INVALIDPARAMS
, FALSE
, "sysmem texture DXT1", 0, FALSE
,
7264 sizeof(DDPIXELFORMAT
), DDPF_FOURCC
, MAKEFOURCC('D', 'X', 'T', '1'),
7265 {0}, {0}, {0}, {0}, {0}
7269 /* The testbot fills this with 0x00 instead of the blue channel. The sysmem
7270 * surface works, presumably because it is handled by the runtime instead of
7272 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
,
7273 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "vidmem offscreenplain P8", 0xefefefef, FALSE
,
7275 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
7276 {8}, {0}, {0}, {0}, {0}
7280 DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
,
7281 DD_OK
, DDERR_INVALIDPARAMS
, TRUE
, "sysmem offscreenplain P8", 0xefefefef, TRUE
,
7283 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_PALETTEINDEXED8
, 0,
7284 {8}, {0}, {0}, {0}, {0}
7296 {SRCCOPY
, "SRCCOPY", DD_OK
},
7297 {SRCPAINT
, "SRCPAINT", DDERR_NORASTEROPHW
},
7298 {SRCAND
, "SRCAND", DDERR_NORASTEROPHW
},
7299 {SRCINVERT
, "SRCINVERT", DDERR_NORASTEROPHW
},
7300 {SRCERASE
, "SRCERASE", DDERR_NORASTEROPHW
},
7301 {NOTSRCCOPY
, "NOTSRCCOPY", DDERR_NORASTEROPHW
},
7302 {NOTSRCERASE
, "NOTSRCERASE", DDERR_NORASTEROPHW
},
7303 {MERGECOPY
, "MERGECOPY", DDERR_NORASTEROPHW
},
7304 {MERGEPAINT
, "MERGEPAINT", DDERR_NORASTEROPHW
},
7305 {PATCOPY
, "PATCOPY", DDERR_NORASTEROPHW
},
7306 {PATPAINT
, "PATPAINT", DDERR_NORASTEROPHW
},
7307 {PATINVERT
, "PATINVERT", DDERR_NORASTEROPHW
},
7308 {DSTINVERT
, "DSTINVERT", DDERR_NORASTEROPHW
},
7309 {BLACKNESS
, "BLACKNESS", DD_OK
},
7310 {WHITENESS
, "WHITENESS", DD_OK
},
7311 {0xaa0029, "0xaa0029", DDERR_NORASTEROPHW
} /* noop */
7314 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7315 0, 0, 640, 480, 0, 0, 0, 0);
7316 ddraw
= create_ddraw();
7317 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7318 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
7320 skip("Failed to create a 3D device, skipping test.\n");
7321 DestroyWindow(window
);
7322 IDirectDraw_Release(ddraw
);
7326 hr
= IDirectDraw_GetFourCCCodes(ddraw
, &num_fourcc_codes
, NULL
);
7327 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
7328 fourcc_codes
= HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY
,
7329 num_fourcc_codes
* sizeof(*fourcc_codes
));
7332 hr
= IDirectDraw_GetFourCCCodes(ddraw
, &num_fourcc_codes
, fourcc_codes
);
7333 ok(SUCCEEDED(hr
), "Failed to get fourcc codes %#x.\n", hr
);
7334 for (i
= 0; i
< num_fourcc_codes
; i
++)
7336 if (fourcc_codes
[i
] == MAKEFOURCC('Y', 'U', 'Y', '2'))
7337 support_yuy2
= TRUE
;
7338 else if (fourcc_codes
[i
] == MAKEFOURCC('U', 'Y', 'V', 'Y'))
7339 support_uyvy
= TRUE
;
7341 HeapFree(GetProcessHeap(), 0, fourcc_codes
);
7343 memset(&hal_caps
, 0, sizeof(hal_caps
));
7344 hal_caps
.dwSize
= sizeof(hal_caps
);
7345 hr
= IDirectDraw_GetCaps(ddraw
, &hal_caps
, NULL
);
7346 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
7348 if ((!support_yuy2
&& !support_uyvy
) || !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
7349 skip("Overlays or some YUV formats not supported, skipping YUV colorfill tests.\n");
7351 for (i
= 0; i
< sizeof(tests
) / sizeof(*tests
); i
++)
7353 /* Some Windows drivers modify dwFillColor when it is used on P8 or FourCC formats. */
7354 memset(&fx
, 0, sizeof(fx
));
7355 fx
.dwSize
= sizeof(fx
);
7356 U5(fx
).dwFillColor
= 0xdeadbeef;
7358 memset(&surface_desc
, 0, sizeof(surface_desc
));
7359 surface_desc
.dwSize
= sizeof(surface_desc
);
7360 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7361 surface_desc
.dwWidth
= 64;
7362 surface_desc
.dwHeight
= 64;
7363 surface_desc
.ddpfPixelFormat
= tests
[i
].format
;
7364 surface_desc
.ddsCaps
.dwCaps
= tests
[i
].caps
;
7366 if (tests
[i
].caps
& DDSCAPS_TEXTURE
)
7368 struct format_support_check check
= {&tests
[i
].format
, FALSE
};
7369 hr
= IDirect3DDevice_EnumTextureFormats(device
, test_unsupported_formats_cb
, &check
);
7370 ok(SUCCEEDED(hr
), "Failed to enumerate texture formats %#x.\n", hr
);
7371 if (!check
.supported
)
7375 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('Y','U','Y','2') && !support_yuy2
)
7377 if (tests
[i
].format
.dwFourCC
== MAKEFOURCC('U','Y','V','Y') && !support_uyvy
)
7379 if (tests
[i
].caps
& DDSCAPS_OVERLAY
&& !(hal_caps
.dwCaps
& DDCAPS_OVERLAY
))
7382 if (tests
[i
].caps
& DDSCAPS_ZBUFFER
)
7384 surface_desc
.dwFlags
&= ~DDSD_PIXELFORMAT
;
7385 surface_desc
.dwFlags
|= DDSD_ZBUFFERBITDEPTH
;
7386 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
7389 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7390 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7392 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7393 todo_wine_if (tests
[i
].format
.dwFourCC
)
7394 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
7395 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
7397 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7398 todo_wine_if (tests
[i
].format
.dwFourCC
)
7399 ok(hr
== tests
[i
].colorfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
7400 hr
, tests
[i
].colorfill_hr
, tests
[i
].name
);
7402 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
7404 memset(&surface_desc
, 0, sizeof(surface_desc
));
7405 surface_desc
.dwSize
= sizeof(surface_desc
);
7406 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
7407 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7408 color
= surface_desc
.lpSurface
;
7409 ok(*color
== tests
[i
].result
, "Got clear result 0x%08x, expected 0x%08x, surface %s.\n",
7410 *color
, tests
[i
].result
, tests
[i
].name
);
7411 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
7412 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7415 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7416 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
7417 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
7418 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7419 ok(hr
== tests
[i
].depthfill_hr
, "Blt returned %#x, expected %#x, surface %s.\n",
7420 hr
, tests
[i
].depthfill_hr
, tests
[i
].name
);
7422 U5(fx
).dwFillColor
= 0xdeadbeef;
7423 fx
.dwROP
= BLACKNESS
;
7424 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7425 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
7426 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
7427 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
7428 U5(fx
).dwFillColor
, tests
[i
].name
);
7430 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
7432 memset(&surface_desc
, 0, sizeof(surface_desc
));
7433 surface_desc
.dwSize
= sizeof(surface_desc
);
7434 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
7435 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7436 color
= surface_desc
.lpSurface
;
7437 ok(*color
== 0, "Got clear result 0x%08x, expected 0x00000000, surface %s.\n",
7438 *color
, tests
[i
].name
);
7439 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
7440 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7443 fx
.dwROP
= WHITENESS
;
7444 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7445 ok(FAILED(hr
) == !tests
[i
].rop_success
, "Blt returned %#x, expected %s, surface %s.\n",
7446 hr
, tests
[i
].rop_success
? "success" : "failure", tests
[i
].name
);
7447 ok(U5(fx
).dwFillColor
== 0xdeadbeef, "dwFillColor was set to 0x%08x, surface %s\n",
7448 U5(fx
).dwFillColor
, tests
[i
].name
);
7450 if (SUCCEEDED(hr
) && tests
[i
].check_result
)
7452 memset(&surface_desc
, 0, sizeof(surface_desc
));
7453 surface_desc
.dwSize
= sizeof(surface_desc
);
7454 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_READONLY
, 0);
7455 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7456 color
= surface_desc
.lpSurface
;
7457 /* WHITENESS sets the alpha channel to 0x00. Ignore this for now. */
7458 ok((*color
& 0x00ffffff) == 0x00ffffff, "Got clear result 0x%08x, expected 0xffffffff, surface %s.\n",
7459 *color
, tests
[i
].name
);
7460 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
7461 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, surface %s.\n", hr
, tests
[i
].name
);
7464 IDirectDrawSurface_Release(surface
);
7467 memset(&fx
, 0, sizeof(fx
));
7468 fx
.dwSize
= sizeof(fx
);
7469 U5(fx
).dwFillColor
= 0xdeadbeef;
7470 fx
.dwROP
= WHITENESS
;
7472 memset(&surface_desc
, 0, sizeof(surface_desc
));
7473 surface_desc
.dwSize
= sizeof(surface_desc
);
7474 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7475 surface_desc
.dwWidth
= 64;
7476 surface_desc
.dwHeight
= 64;
7477 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
7478 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
7479 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
7480 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
7481 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
7482 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
7483 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
;
7484 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7485 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7486 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
7487 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7490 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, NULL
);
7491 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7492 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, NULL
);
7493 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7495 /* Unused source rectangle. */
7496 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7497 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7498 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7499 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7501 /* Unused source surface. */
7502 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7503 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7504 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7505 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7506 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7507 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7508 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7509 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7511 /* Inverted destination or source rectangle. */
7512 SetRect(&rect
, 5, 7, 7, 5);
7513 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7514 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7515 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7516 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7517 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7518 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7519 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7520 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7521 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7522 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7524 /* Negative rectangle. */
7525 SetRect(&rect
, -1, -1, 5, 5);
7526 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7527 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7528 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7529 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7530 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7531 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7532 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7533 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7534 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7535 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7537 /* Out of bounds rectangle. */
7538 SetRect(&rect
, 0, 0, 65, 65);
7539 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7540 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7541 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7542 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7544 /* Combine multiple flags. */
7545 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7546 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7547 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7548 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7549 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7550 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7552 for (i
= 0; i
< sizeof(rops
) / sizeof(*rops
); i
++)
7554 fx
.dwROP
= rops
[i
].rop
;
7555 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_ROP
| DDBLT_WAIT
, &fx
);
7556 ok(hr
== rops
[i
].hr
, "Got unexpected hr %#x for rop %s.\n", hr
, rops
[i
].name
);
7559 IDirectDrawSurface_Release(surface2
);
7560 IDirectDrawSurface_Release(surface
);
7562 memset(&surface_desc
, 0, sizeof(surface_desc
));
7563 surface_desc
.dwSize
= sizeof(surface_desc
);
7564 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_ZBUFFERBITDEPTH
;
7565 surface_desc
.dwWidth
= 64;
7566 surface_desc
.dwHeight
= 64;
7567 U2(surface_desc
).dwZBufferBitDepth
= get_device_z_depth(device
);
7568 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_ZBUFFER
;
7569 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
7570 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7571 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface2
, NULL
);
7572 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7575 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, NULL
);
7576 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7578 /* Unused source rectangle. */
7579 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7580 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7582 /* Unused source surface. */
7583 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7584 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7585 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7586 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7588 /* Inverted destination or source rectangle. */
7589 SetRect(&rect
, 5, 7, 7, 5);
7590 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7591 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7592 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7593 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7594 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7595 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7596 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7597 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7599 /* Negative rectangle. */
7600 SetRect(&rect
, -1, -1, 5, 5);
7601 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7602 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7603 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7604 ok(SUCCEEDED(hr
), "Got unexpected hr %#x.\n", hr
);
7605 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7606 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7607 hr
= IDirectDrawSurface_Blt(surface
, &rect
, surface2
, &rect
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7608 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7610 /* Out of bounds rectangle. */
7611 SetRect(&rect
, 0, 0, 65, 65);
7612 hr
= IDirectDrawSurface_Blt(surface
, &rect
, NULL
, NULL
, DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7613 ok(hr
== DDERR_INVALIDRECT
, "Got unexpected hr %#x.\n", hr
);
7615 /* Combine multiple flags. */
7616 hr
= IDirectDrawSurface_Blt(surface
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_DEPTHFILL
| DDBLT_WAIT
, &fx
);
7617 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
7619 IDirectDrawSurface_Release(surface2
);
7620 IDirectDrawSurface_Release(surface
);
7623 IDirect3DDevice_Release(device
);
7624 refcount
= IDirectDraw_Release(ddraw
);
7625 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
7626 DestroyWindow(window
);
7629 static BOOL
ddraw_is_nvidia(IDirectDraw
*ddraw
)
7631 IDirectDraw4
*ddraw4
;
7632 DDDEVICEIDENTIFIER identifier
;
7635 if (!strcmp(winetest_platform
, "wine"))
7638 hr
= IDirectDraw_QueryInterface(ddraw
, &IID_IDirectDraw4
, (void **)&ddraw4
);
7639 ok(SUCCEEDED(hr
), "Failed to get IDirectDraw4 interface, hr %#x.\n", hr
);
7640 hr
= IDirectDraw4_GetDeviceIdentifier(ddraw4
, &identifier
, 0);
7641 ok(SUCCEEDED(hr
), "Failed to get device identifier, hr %#x.\n", hr
);
7642 IDirectDraw4_Release(ddraw4
);
7643 return identifier
.dwVendorId
== 0x10de;
7646 static void test_colorkey_precision(void)
7648 static D3DTLVERTEX quad
[] =
7650 {{ 0.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x00000000}, {0x00000000}, {0.0f
}, {1.0f
}},
7651 {{ 0.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0x00000000}, {0x00000000}, {0.0f
}, {0.0f
}},
7652 {{640.0f
}, {480.0f
}, {0.0f
}, {1.0f
}, {0x00000000}, {0x00000000}, {1.0f
}, {1.0f
}},
7653 {{640.0f
}, { 0.0f
}, {0.0f
}, {1.0f
}, {0x00000000}, {0x00000000}, {1.0f
}, {0.0f
}},
7655 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
7656 IDirect3DDevice
*device
;
7658 IDirectDrawSurface
*rt
;
7659 IDirect3DViewport
*viewport
;
7660 IDirect3DExecuteBuffer
*execute_buffer
;
7661 D3DEXECUTEBUFFERDESC exec_desc
;
7666 IDirectDrawSurface
*src
, *dst
, *texture
;
7667 D3DTEXTUREHANDLE handle
;
7668 IDirect3DTexture
*d3d_texture
;
7669 IDirect3DMaterial
*green
;
7670 DDSURFACEDESC surface_desc
, lock_desc
;
7676 DWORD data
[4] = {0}, color_mask
;
7677 BOOL is_nvidia
, is_warp
;
7680 unsigned int max
, shift
, bpp
, clear
;
7688 255, 0, 4, 0x00345678, "D3DFMT_X8R8G8B8", FALSE
,
7690 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
7691 {32}, {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}
7696 63, 5, 2, 0x5678, "D3DFMT_R5G6B5, G channel", FALSE
,
7698 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
7699 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
7704 31, 0, 2, 0x5678, "D3DFMT_R5G6B5, B channel", FALSE
,
7706 sizeof(DDPIXELFORMAT
), DDPF_RGB
, 0,
7707 {16}, {0xf800}, {0x07e0}, {0x001f}, {0x0000}
7712 15, 0, 2, 0x0678, "D3DFMT_A4R4G4B4", TRUE
,
7714 sizeof(DDPIXELFORMAT
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0,
7715 {16}, {0x0f00}, {0x00f0}, {0x000f}, {0xf000}
7720 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7721 0, 0, 640, 480, 0, 0, 0, 0);
7722 ddraw
= create_ddraw();
7723 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7724 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
7726 skip("Failed to create a 3D device, skipping test.\n");
7727 DestroyWindow(window
);
7728 IDirectDraw_Release(ddraw
);
7731 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
7732 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
7734 is_nvidia
= ddraw_is_nvidia(ddraw
);
7735 /* The Windows 8 WARP driver has plenty of false negatives in X8R8G8B8
7736 * (color key doesn't match although the values are equal), and a false
7737 * positive when the color key is 0 and the texture contains the value 1.
7738 * I don't want to mark this broken unconditionally since this would
7739 * essentially disable the test on Windows. Also on random occasions
7740 * 254 == 255 and 255 != 255.*/
7741 is_warp
= ddraw_is_warp(ddraw
);
7743 green
= create_diffuse_material(device
, 0.0f
, 1.0f
, 0.0f
, 0.0f
);
7744 viewport
= create_viewport(device
, 0, 0, 640, 480);
7745 viewport_set_background(device
, viewport
, green
);
7747 memset(&exec_desc
, 0, sizeof(exec_desc
));
7748 exec_desc
.dwSize
= sizeof(exec_desc
);
7749 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
7750 exec_desc
.dwBufferSize
= 1024;
7751 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
7752 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
7753 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
7755 memset(&fx
, 0, sizeof(fx
));
7756 fx
.dwSize
= sizeof(fx
);
7757 memset(&lock_desc
, 0, sizeof(lock_desc
));
7758 lock_desc
.dwSize
= sizeof(lock_desc
);
7760 for (t
= 0; t
< sizeof(tests
) / sizeof(*tests
); ++t
)
7762 if (is_nvidia
&& tests
[t
].skip_nv
)
7764 win_skip("Skipping test %s on Nvidia Windows drivers.\n", tests
[t
].name
);
7768 memset(&surface_desc
, 0, sizeof(surface_desc
));
7769 surface_desc
.dwSize
= sizeof(surface_desc
);
7770 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
7771 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
7772 surface_desc
.dwWidth
= 4;
7773 surface_desc
.dwHeight
= 1;
7774 surface_desc
.ddpfPixelFormat
= tests
[t
].fmt
;
7775 /* Windows XP (at least with the r200 driver, other drivers untested) produces
7776 * garbage when doing color keyed texture->texture blits. */
7777 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &src
, NULL
);
7778 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7779 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &dst
, NULL
);
7780 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7782 fx
.dwFillColor
= tests
[t
].clear
;
7783 /* On the w8 testbot (WARP driver) the blit result has different values in the
7785 color_mask
= U2(tests
[t
].fmt
).dwRBitMask
7786 | U3(tests
[t
].fmt
).dwGBitMask
7787 | U4(tests
[t
].fmt
).dwBBitMask
;
7789 for (c
= 0; c
<= tests
[t
].max
; ++c
)
7791 /* The idiotic Nvidia Windows driver can't change the color key on a d3d
7792 * texture after it has been set once... */
7793 surface_desc
.dwFlags
|= DDSD_CKSRCBLT
;
7794 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
7795 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
7796 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
7797 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &texture
, NULL
);
7798 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
7800 hr
= IDirectDrawSurface_QueryInterface(texture
, &IID_IDirect3DTexture
, (void **)&d3d_texture
);
7801 ok(SUCCEEDED(hr
), "Failed to get texture interface, hr %#x.\n", hr
);
7802 hr
= IDirect3DTexture_GetHandle(d3d_texture
, device
, &handle
);
7803 ok(SUCCEEDED(hr
), "Failed to get texture handle, hr %#x.\n", hr
);
7804 IDirect3DTexture_Release(d3d_texture
);
7806 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
7807 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
7809 memcpy(exec_desc
.lpData
, quad
, sizeof(quad
));
7811 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(quad
);
7812 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_COPY
, 0, 8);
7813 emit_set_rs(&ptr
, D3DRENDERSTATE_ZENABLE
, D3DZB_FALSE
);
7814 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, handle
);
7815 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREMAPBLEND
, D3DTBLEND_MODULATEALPHA
);
7816 /* D3DRENDERSTATE_COLORKEYENABLE is supposed to be on by default on version
7817 * 1 devices, but for some reason it randomly defaults to FALSE on the W8
7818 * testbot. This is either the fault of Windows 8 or the WARP driver.
7819 * Also D3DRENDERSTATE_COLORKEYENABLE was introduced in D3D 5 aka version 2
7820 * devices only, which might imply this doesn't actually do anything on
7822 emit_set_rs(&ptr
, D3DRENDERSTATE_COLORKEYENABLE
, TRUE
);
7824 emit_tquad(&ptr
, 0);
7825 emit_tquad(&ptr
, 4);
7826 emit_set_rs(&ptr
, D3DRENDERSTATE_TEXTUREHANDLE
, 0);
7829 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
7830 inst_length
-= sizeof(quad
);
7831 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
7832 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
7833 set_execute_data(execute_buffer
, 8, sizeof(quad
), inst_length
);
7835 hr
= IDirectDrawSurface_Blt(dst
, NULL
, NULL
, NULL
, DDBLT_COLORFILL
| DDBLT_WAIT
, &fx
);
7836 ok(SUCCEEDED(hr
), "Failed to clear destination surface, hr %#x.\n", hr
);
7838 hr
= IDirectDrawSurface_Lock(src
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
7839 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7840 switch (tests
[t
].bpp
)
7843 ((DWORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
7844 ((DWORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
7845 ((DWORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
7846 ((DWORD
*)lock_desc
.lpSurface
)[3] = 0xffffffff;
7850 ((WORD
*)lock_desc
.lpSurface
)[0] = (c
? c
- 1 : 0) << tests
[t
].shift
;
7851 ((WORD
*)lock_desc
.lpSurface
)[1] = c
<< tests
[t
].shift
;
7852 ((WORD
*)lock_desc
.lpSurface
)[2] = min(c
+ 1, tests
[t
].max
) << tests
[t
].shift
;
7853 ((WORD
*)lock_desc
.lpSurface
)[3] = 0xffff;
7856 hr
= IDirectDrawSurface_Unlock(src
, 0);
7857 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7858 hr
= IDirectDrawSurface_Blt(texture
, NULL
, src
, NULL
, DDBLT_WAIT
, NULL
);
7859 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
7861 ckey
.dwColorSpaceLowValue
= c
<< tests
[t
].shift
;
7862 ckey
.dwColorSpaceHighValue
= c
<< tests
[t
].shift
;
7863 hr
= IDirectDrawSurface_SetColorKey(src
, DDCKEY_SRCBLT
, &ckey
);
7864 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
7866 hr
= IDirectDrawSurface_Blt(dst
, NULL
, src
, NULL
, DDBLT_KEYSRC
| DDBLT_WAIT
, NULL
);
7867 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
7869 /* Don't make this read only, it somehow breaks the detection of the Nvidia bug below. */
7870 hr
= IDirectDrawSurface_Lock(dst
, NULL
, &lock_desc
, DDLOCK_WAIT
, NULL
);
7871 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
7872 switch (tests
[t
].bpp
)
7875 data
[0] = ((DWORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
7876 data
[1] = ((DWORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
7877 data
[2] = ((DWORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
7878 data
[3] = ((DWORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
7882 data
[0] = ((WORD
*)lock_desc
.lpSurface
)[0] & color_mask
;
7883 data
[1] = ((WORD
*)lock_desc
.lpSurface
)[1] & color_mask
;
7884 data
[2] = ((WORD
*)lock_desc
.lpSurface
)[2] & color_mask
;
7885 data
[3] = ((WORD
*)lock_desc
.lpSurface
)[3] & color_mask
;
7888 hr
= IDirectDrawSurface_Unlock(dst
, 0);
7889 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
7893 ok(data
[0] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7894 tests
[t
].clear
, data
[0], tests
[t
].name
, c
);
7896 if (data
[3] == tests
[t
].clear
)
7898 /* My Geforce GTX 460 on Windows 7 misbehaves when A4R4G4B4 is blitted with color
7899 * keying: The blit takes ~0.5 seconds, and subsequent color keying draws are broken,
7900 * even when a different surface is used. The blit itself doesn't draw anything,
7901 * so we can detect the bug by looking at the otherwise unused 4th texel. It should
7902 * never be masked out by the key.
7904 * On Windows 10 the problem is worse, Blt just hangs. For this reason the ARGB4444
7905 * test is disabled entirely.
7907 * Also appears to affect the testbot in some way with R5G6B5. Color keying is
7908 * terrible on WARP. */
7909 skip("Nvidia A4R4G4B4 color keying blit bug detected, skipping.\n");
7910 IDirectDrawSurface_Release(texture
);
7911 IDirectDrawSurface_Release(src
);
7912 IDirectDrawSurface_Release(dst
);
7917 ok(data
[0] == (c
- 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7918 (c
- 1) << tests
[t
].shift
, data
[0], tests
[t
].name
, c
);
7920 ok(data
[1] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7921 tests
[t
].clear
, data
[1], tests
[t
].name
, c
);
7923 if (c
== tests
[t
].max
)
7924 ok(data
[2] == tests
[t
].clear
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7925 tests
[t
].clear
, data
[2], tests
[t
].name
, c
);
7927 ok(data
[2] == (c
+ 1) << tests
[t
].shift
, "Expected surface content %#x, got %#x, format %s, c=%u.\n",
7928 (c
+ 1) << tests
[t
].shift
, data
[2], tests
[t
].name
, c
);
7930 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
7931 ok(SUCCEEDED(hr
), "Failed to clear, hr %#x.\n", hr
);
7933 hr
= IDirect3DDevice_BeginScene(device
);
7934 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
7935 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_UNCLIPPED
);
7936 ok(SUCCEEDED(hr
), "Failed to draw, hr %#x.\n", hr
);
7937 hr
= IDirect3DDevice_EndScene(device
);
7938 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
7940 color
= get_surface_color(rt
, 80, 240);
7942 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
7943 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7944 color
, tests
[t
].name
, c
);
7946 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
7947 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7948 color
, tests
[t
].name
, c
);
7950 color
= get_surface_color(rt
, 240, 240);
7951 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
7952 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7953 color
, tests
[t
].name
, c
);
7955 color
= get_surface_color(rt
, 400, 240);
7956 if (c
== tests
[t
].max
)
7957 ok(compare_color(color
, 0x0000ff00, 1) || broken(is_warp
&& compare_color(color
, 0x00000000, 1)),
7958 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7959 color
, tests
[t
].name
, c
);
7961 ok(compare_color(color
, 0x00000000, 1) || broken(is_warp
&& compare_color(color
, 0x0000ff00, 1)),
7962 "Got unexpected color 0x%08x, format %s, c=%u.\n",
7963 color
, tests
[t
].name
, c
);
7965 IDirectDrawSurface_Release(texture
);
7967 IDirectDrawSurface_Release(src
);
7968 IDirectDrawSurface_Release(dst
);
7972 destroy_viewport(device
, viewport
);
7973 destroy_material(green
);
7974 IDirectDrawSurface_Release(rt
);
7975 IDirect3DExecuteBuffer_Release(execute_buffer
);
7976 IDirect3DDevice_Release(device
);
7977 refcount
= IDirectDraw_Release(ddraw
);
7978 ok(refcount
== 0, "Ddraw object not properly released, refcount %u.\n", refcount
);
7979 DestroyWindow(window
);
7982 static void test_range_colorkey(void)
7987 IDirectDrawSurface
*surface
;
7988 DDSURFACEDESC surface_desc
;
7992 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
7993 0, 0, 640, 480, 0, 0, 0, 0);
7994 ddraw
= create_ddraw();
7995 ok(!!ddraw
, "Failed to create a ddraw object.\n");
7996 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
7997 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
7999 memset(&surface_desc
, 0, sizeof(surface_desc
));
8000 surface_desc
.dwSize
= sizeof(surface_desc
);
8001 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CKSRCBLT
;
8002 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8003 surface_desc
.dwWidth
= 1;
8004 surface_desc
.dwHeight
= 1;
8005 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8006 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8007 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0x00ff0000;
8008 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x0000ff00;
8009 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x000000ff;
8010 U5(surface_desc
.ddpfPixelFormat
).dwRGBAlphaBitMask
= 0x00000000;
8012 /* Creating a surface with a range color key fails with DDERR_NOCOLORKEY. */
8013 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
8014 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
8015 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8016 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8018 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
8019 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
8020 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8021 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8023 /* Same for DDSCAPS_OFFSCREENPLAIN. */
8024 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8025 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
8026 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000001;
8027 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8028 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8030 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000001;
8031 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
8032 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8033 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8035 surface_desc
.ddckCKSrcBlt
.dwColorSpaceLowValue
= 0x00000000;
8036 surface_desc
.ddckCKSrcBlt
.dwColorSpaceHighValue
= 0x00000000;
8037 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8038 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8040 /* Setting a range color key without DDCKEY_COLORSPACE collapses the key. */
8041 ckey
.dwColorSpaceLowValue
= 0x00000000;
8042 ckey
.dwColorSpaceHighValue
= 0x00000001;
8043 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8044 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8046 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8047 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
8048 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
8049 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
8051 ckey
.dwColorSpaceLowValue
= 0x00000001;
8052 ckey
.dwColorSpaceHighValue
= 0x00000000;
8053 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8054 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8056 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8057 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
8058 ok(ckey
.dwColorSpaceLowValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
8059 ok(ckey
.dwColorSpaceHighValue
== 0x00000001, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
8061 /* DDCKEY_COLORSPACE is ignored if the key is a single value. */
8062 ckey
.dwColorSpaceLowValue
= 0x00000000;
8063 ckey
.dwColorSpaceHighValue
= 0x00000000;
8064 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
8065 ok(SUCCEEDED(hr
), "Failed to set color key, hr %#x.\n", hr
);
8067 /* Using it with a range key results in DDERR_NOCOLORKEYHW. */
8068 ckey
.dwColorSpaceLowValue
= 0x00000001;
8069 ckey
.dwColorSpaceHighValue
= 0x00000000;
8070 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
8071 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8072 ckey
.dwColorSpaceLowValue
= 0x00000000;
8073 ckey
.dwColorSpaceHighValue
= 0x00000001;
8074 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
8075 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8076 /* Range destination keys don't work either. */
8077 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_DESTBLT
| DDCKEY_COLORSPACE
, &ckey
);
8078 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8080 /* Just to show it's not because of A, R, and G having equal values. */
8081 ckey
.dwColorSpaceLowValue
= 0x00000000;
8082 ckey
.dwColorSpaceHighValue
= 0x01010101;
8083 hr
= IDirectDrawSurface_SetColorKey(surface
, DDCKEY_SRCBLT
| DDCKEY_COLORSPACE
, &ckey
);
8084 ok(hr
== DDERR_NOCOLORKEYHW
, "Got unexpected hr %#x.\n", hr
);
8086 /* None of these operations modified the key. */
8087 hr
= IDirectDrawSurface_GetColorKey(surface
, DDCKEY_SRCBLT
, &ckey
);
8088 ok(SUCCEEDED(hr
), "Failed to get color key, hr %#x.\n", hr
);
8089 ok(!ckey
.dwColorSpaceLowValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceLowValue
);
8090 ok(!ckey
.dwColorSpaceHighValue
, "Got unexpected value 0x%08x.\n", ckey
.dwColorSpaceHighValue
);
8092 IDirectDrawSurface_Release(surface
),
8093 refcount
= IDirectDraw_Release(ddraw
);
8094 ok(!refcount
, "Got unexpected refcount %u.\n", refcount
);
8095 DestroyWindow(window
);
8098 static void test_shademode(void)
8100 static D3DRECT clear_rect
= {{0}, {0}, {640}, {480}};
8101 IDirect3DExecuteBuffer
*execute_buffer
;
8102 D3DEXECUTEBUFFERDESC exec_desc
;
8103 IDirect3DMaterial
*background
;
8104 IDirect3DViewport
*viewport
;
8105 IDirect3DDevice
*device
;
8106 IDirectDrawSurface
*rt
;
8107 const D3DLVERTEX
*quad
;
8108 DWORD color0
, color1
;
8109 UINT i
, inst_length
;
8115 static const D3DLVERTEX quad_strip
[] =
8117 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
8118 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
8119 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
8120 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
8124 {{ 1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xff0000ff}},
8125 {{-1.0f
}, {-1.0f
}, {0.0f
}, 0, {0xffff0000}},
8126 {{-1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xff00ff00}},
8127 {{ 1.0f
}, { 1.0f
}, {0.0f
}, 0, {0xffffffff}},
8133 DWORD color0
, color1
;
8137 {D3DPT_TRIANGLESTRIP
, D3DSHADE_FLAT
, 0x00ff0000, 0x000000ff},
8138 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
8139 {D3DPT_TRIANGLESTRIP
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
8140 {D3DPT_TRIANGLESTRIP
, D3DSHADE_PHONG
, 0x000dca28, 0x000d45c7},
8141 {D3DPT_TRIANGLELIST
, D3DSHADE_FLAT
, 0x000000ff, 0x0000ff00},
8142 {D3DPT_TRIANGLELIST
, D3DSHADE_GOURAUD
, 0x000dca28, 0x000d45c7},
8145 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8146 0, 0, 640, 480, 0, 0, 0, 0);
8147 ddraw
= create_ddraw();
8148 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8149 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8151 skip("Failed to create a 3D device, skipping test.\n");
8152 IDirectDraw_Release(ddraw
);
8153 DestroyWindow(window
);
8157 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
8158 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8160 background
= create_diffuse_material(device
, 1.0f
, 1.0f
, 1.0f
, 1.0f
);
8161 viewport
= create_viewport(device
, 0, 0, 640, 480);
8162 viewport_set_background(device
, viewport
, background
);
8164 memset(&exec_desc
, 0, sizeof(exec_desc
));
8165 exec_desc
.dwSize
= sizeof(exec_desc
);
8166 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
8167 exec_desc
.dwBufferSize
= 1024;
8168 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
8170 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
8171 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
8173 /* Try it first with a TRIANGLESTRIP. Do it with different geometry because
8174 * the color fixups we have to do for FLAT shading will be dependent on that. */
8176 for (i
= 0; i
< sizeof(tests
) / sizeof(tests
[0]); ++i
)
8178 hr
= IDirect3DViewport_Clear(viewport
, 1, &clear_rect
, D3DCLEAR_TARGET
);
8179 ok(SUCCEEDED(hr
), "Failed to clear viewport, hr %#x.\n", hr
);
8181 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
8182 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
8184 quad
= tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
? quad_strip
: quad_list
;
8185 memcpy(exec_desc
.lpData
, quad
, sizeof(quad_strip
));
8186 ptr
= ((BYTE
*)exec_desc
.lpData
) + sizeof(quad_strip
);
8187 emit_set_rs(&ptr
, D3DRENDERSTATE_CLIPPING
, FALSE
);
8188 emit_set_rs(&ptr
, D3DRENDERSTATE_ZENABLE
, FALSE
);
8189 emit_set_rs(&ptr
, D3DRENDERSTATE_FOGENABLE
, FALSE
);
8190 emit_set_rs(&ptr
, D3DRENDERSTATE_CULLMODE
, D3DCULL_NONE
);
8191 emit_set_rs(&ptr
, D3DRENDERSTATE_SHADEMODE
, tests
[i
].shademode
);
8193 emit_process_vertices(&ptr
, D3DPROCESSVERTICES_TRANSFORM
, 0, 4);
8194 if (tests
[i
].primtype
== D3DPT_TRIANGLESTRIP
)
8195 emit_tquad(&ptr
, 0);
8197 emit_tquad_tlist(&ptr
, 0);
8199 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
8200 inst_length
-= sizeof(quad_strip
);
8202 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
8203 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
8205 hr
= IDirect3DDevice2_BeginScene(device
);
8206 set_execute_data(execute_buffer
, 4, sizeof(quad_strip
), inst_length
);
8207 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
8208 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
8209 hr
= IDirect3DDevice2_EndScene(device
);
8210 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
8212 color0
= get_surface_color(rt
, 100, 100); /* Inside first triangle */
8213 color1
= get_surface_color(rt
, 500, 350); /* Inside second triangle */
8215 /* For D3DSHADE_FLAT it should take the color of the first vertex of
8216 * each triangle. This requires EXT_provoking_vertex or similar
8217 * functionality being available. */
8218 /* PHONG should be the same as GOURAUD, since no hardware implements
8220 ok(compare_color(color0
, tests
[i
].color0
, 1), "Test %u shading has color0 %08x, expected %08x.\n",
8221 i
, color0
, tests
[i
].color0
);
8222 ok(compare_color(color1
, tests
[i
].color1
, 1), "Test %u shading has color1 %08x, expected %08x.\n",
8223 i
, color1
, tests
[i
].color1
);
8226 IDirect3DExecuteBuffer_Release(execute_buffer
);
8227 destroy_viewport(device
, viewport
);
8228 destroy_material(background
);
8229 IDirectDrawSurface_Release(rt
);
8230 refcount
= IDirect3DDevice_Release(device
);
8231 ok(!refcount
, "Device has %u references left.\n", refcount
);
8232 IDirectDraw_Release(ddraw
);
8233 DestroyWindow(window
);
8236 static void test_lockrect_invalid(void)
8240 IDirectDrawSurface
*surface
;
8243 DDSURFACEDESC surface_desc
;
8245 DWORD needed_caps
= DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
;
8246 static RECT valid
[] =
8254 static RECT invalid
[] =
8256 {68, 60, 60, 68}, /* left > right */
8257 {60, 68, 68, 60}, /* top > bottom */
8258 {-8, 60, 0, 68}, /* left < surface */
8259 {60, -8, 68, 0}, /* top < surface */
8260 {-16, 60, -8, 68}, /* right < surface */
8261 {60, -16, 68, -8}, /* bottom < surface */
8262 {60, 60, 136, 68}, /* right > surface */
8263 {60, 60, 68, 136}, /* bottom > surface */
8264 {136, 60, 144, 68}, /* left > surface */
8265 {60, 136, 68, 144}, /* top > surface */
8275 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_SYSTEMMEMORY
, "sysmem offscreenplain", DDERR_INVALIDPARAMS
},
8276 {DDSCAPS_OFFSCREENPLAIN
| DDSCAPS_VIDEOMEMORY
, "vidmem offscreenplain", DDERR_INVALIDPARAMS
},
8277 {DDSCAPS_TEXTURE
| DDSCAPS_SYSTEMMEMORY
, "sysmem texture", DDERR_INVALIDPARAMS
},
8278 {DDSCAPS_TEXTURE
| DDSCAPS_VIDEOMEMORY
, "vidmem texture", DDERR_INVALIDPARAMS
},
8281 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8282 0, 0, 640, 480, 0, 0, 0, 0);
8283 ddraw
= create_ddraw();
8284 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8285 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8286 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8288 memset(&hal_caps
, 0, sizeof(hal_caps
));
8289 hal_caps
.dwSize
= sizeof(hal_caps
);
8290 hr
= IDirectDraw_GetCaps(ddraw
, &hal_caps
, NULL
);
8291 ok(SUCCEEDED(hr
), "Failed to get caps, hr %#x.\n", hr
);
8292 if ((hal_caps
.ddsCaps
.dwCaps
& needed_caps
) != needed_caps
)
8294 skip("Required surface types not supported, skipping test.\n");
8298 for (r
= 0; r
< sizeof(resources
) / sizeof(*resources
); ++r
)
8300 memset(&surface_desc
, 0, sizeof(surface_desc
));
8301 surface_desc
.dwSize
= sizeof(surface_desc
);
8302 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8303 surface_desc
.ddsCaps
.dwCaps
= resources
[r
].caps
;
8304 surface_desc
.dwWidth
= 128;
8305 surface_desc
.dwHeight
= 128;
8306 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
8307 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8308 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 32;
8309 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xff0000;
8310 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x00ff00;
8311 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x0000ff;
8313 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8314 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
8316 hr
= IDirectDrawSurface_Lock(surface
, NULL
, NULL
, DDLOCK_WAIT
, NULL
);
8317 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x, type %s.\n", hr
, resources
[r
].name
);
8319 for (i
= 0; i
< sizeof(valid
) / sizeof(*valid
); ++i
)
8321 RECT
*rect
= &valid
[i
];
8323 memset(&surface_desc
, 0, sizeof(surface_desc
));
8324 surface_desc
.dwSize
= sizeof(surface_desc
);
8326 hr
= IDirectDrawSurface_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
8327 ok(SUCCEEDED(hr
), "Lock failed (%#x) for rect %s, type %s.\n",
8328 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
8330 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8331 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
8334 for (i
= 0; i
< sizeof(invalid
) / sizeof(*invalid
); ++i
)
8336 RECT
*rect
= &invalid
[i
];
8338 memset(&surface_desc
, 1, sizeof(surface_desc
));
8339 surface_desc
.dwSize
= sizeof(surface_desc
);
8341 hr
= IDirectDrawSurface_Lock(surface
, rect
, &surface_desc
, DDLOCK_WAIT
, NULL
);
8342 ok(hr
== resources
[r
].hr
, "Lock returned %#x for rect %s, type %s.\n",
8343 hr
, wine_dbgstr_rect(rect
), resources
[r
].name
);
8346 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8347 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
8350 ok(!surface_desc
.lpSurface
, "Got unexpected lpSurface %p.\n", surface_desc
.lpSurface
);
8353 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
8354 ok(SUCCEEDED(hr
), "Lock(rect = NULL) failed, hr %#x, type %s.\n",
8355 hr
, resources
[r
].name
);
8356 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &surface_desc
, DDLOCK_WAIT
, NULL
);
8357 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = NULL) returned %#x, type %s.\n",
8358 hr
, resources
[r
].name
);
8359 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8360 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
8362 hr
= IDirectDrawSurface_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
8363 ok(SUCCEEDED(hr
), "Lock(rect = %s) failed (%#x).\n", wine_dbgstr_rect(&valid
[0]), hr
);
8364 hr
= IDirectDrawSurface_Lock(surface
, &valid
[0], &surface_desc
, DDLOCK_WAIT
, NULL
);
8365 ok(hr
== DDERR_SURFACEBUSY
, "Double lock(rect = %s) failed (%#x).\n",
8366 wine_dbgstr_rect(&valid
[0]), hr
);
8368 /* Locking a different rectangle returns DD_OK, but it seems to break the surface.
8369 * Afterwards unlocking the surface fails(NULL rectangle or both locked rectangles) */
8371 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8372 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x, type %s.\n", hr
, resources
[r
].name
);
8374 IDirectDrawSurface_Release(surface
);
8378 IDirectDraw_Release(ddraw
);
8379 DestroyWindow(window
);
8382 static void test_yv12_overlay(void)
8384 IDirectDrawSurface
*src_surface
, *dst_surface
;
8385 RECT rect
= {13, 17, 14, 18};
8386 unsigned int offset
, y
;
8387 unsigned char *base
;
8393 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8394 0, 0, 640, 480, 0, 0, 0, 0);
8395 ddraw
= create_ddraw();
8396 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8397 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8398 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8400 if (!(src_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
8402 skip("Failed to create a YV12 overlay, skipping test.\n");
8406 memset(&desc
, 0, sizeof(desc
));
8407 desc
.dwSize
= sizeof(desc
);
8408 hr
= IDirectDrawSurface_Lock(src_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
8409 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8411 ok(desc
.dwFlags
== (DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
| DDSD_CAPS
| DDSD_PITCH
),
8412 "Got unexpected flags %#x.\n", desc
.dwFlags
);
8413 ok(desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
| DDSCAPS_HWCODEC
)
8414 || desc
.ddsCaps
.dwCaps
== (DDSCAPS_OVERLAY
| DDSCAPS_VIDEOMEMORY
| DDSCAPS_LOCALVIDMEM
),
8415 "Got unexpected caps %#x.\n", desc
.ddsCaps
.dwCaps
);
8416 ok(desc
.dwWidth
== 256, "Got unexpected width %u.\n", desc
.dwWidth
);
8417 ok(desc
.dwHeight
== 256, "Got unexpected height %u.\n", desc
.dwHeight
);
8418 /* The overlay pitch seems to have 256 byte alignment. */
8419 ok(!(U1(desc
).lPitch
& 0xff), "Got unexpected pitch %u.\n", U1(desc
).lPitch
);
8421 /* Fill the surface with some data for the blit test. */
8422 base
= desc
.lpSurface
;
8424 for (y
= 0; y
< desc
.dwHeight
; ++y
)
8426 memset(base
+ U1(desc
).lPitch
* y
, 0x10, desc
.dwWidth
);
8429 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 4; ++y
)
8431 memset(base
+ U1(desc
).lPitch
* y
, 0x20, desc
.dwWidth
);
8434 for (; y
< desc
.dwHeight
+ desc
.dwHeight
/ 2; ++y
)
8436 memset(base
+ U1(desc
).lPitch
* y
, 0x30, desc
.dwWidth
);
8439 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
8440 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8442 /* YV12 uses 2x2 blocks with 6 bytes per block (4*Y, 1*U, 1*V). Unlike
8443 * other block-based formats like DXT the entire Y channel is stored in
8444 * one big chunk of memory, followed by the chroma channels. So partial
8445 * locks do not really make sense. Show that they are allowed nevertheless
8446 * and the offset points into the luminance data. */
8447 hr
= IDirectDrawSurface_Lock(src_surface
, &rect
, &desc
, DDLOCK_WAIT
, NULL
);
8448 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8449 offset
= ((const unsigned char *)desc
.lpSurface
- base
);
8450 ok(offset
== rect
.top
* U1(desc
).lPitch
+ rect
.left
, "Got unexpected offset %u, expected %u.\n",
8451 offset
, rect
.top
* U1(desc
).lPitch
+ rect
.left
);
8452 hr
= IDirectDrawSurface_Unlock(src_surface
, NULL
);
8453 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8455 if (!(dst_surface
= create_overlay(ddraw
, 256, 256, MAKEFOURCC('Y','V','1','2'))))
8457 /* Windows XP with a Radeon X1600 GPU refuses to create a second
8458 * overlay surface, DDERR_NOOVERLAYHW, making the blit tests moot. */
8459 skip("Failed to create a second YV12 surface, skipping blit test.\n");
8460 IDirectDrawSurface_Release(src_surface
);
8464 hr
= IDirectDrawSurface_Blt(dst_surface
, NULL
, src_surface
, NULL
, DDBLT_WAIT
, NULL
);
8465 /* VMware rejects YV12 blits. This behavior has not been seen on real
8466 * hardware yet, so mark it broken. */
8467 ok(SUCCEEDED(hr
) || broken(hr
== E_NOTIMPL
), "Failed to blit, hr %#x.\n", hr
);
8471 memset(&desc
, 0, sizeof(desc
));
8472 desc
.dwSize
= sizeof(desc
);
8473 hr
= IDirectDrawSurface_Lock(dst_surface
, NULL
, &desc
, DDLOCK_WAIT
, NULL
);
8474 ok(SUCCEEDED(hr
), "Failed to lock surface, hr %#x.\n", hr
);
8476 base
= desc
.lpSurface
;
8477 ok(base
[0] == 0x10, "Got unexpected Y data 0x%02x.\n", base
[0]);
8478 base
+= desc
.dwHeight
* U1(desc
).lPitch
;
8479 todo_wine
ok(base
[0] == 0x20, "Got unexpected V data 0x%02x.\n", base
[0]);
8480 base
+= desc
.dwHeight
/ 4 * U1(desc
).lPitch
;
8481 todo_wine
ok(base
[0] == 0x30, "Got unexpected U data 0x%02x.\n", base
[0]);
8483 hr
= IDirectDrawSurface_Unlock(dst_surface
, NULL
);
8484 ok(SUCCEEDED(hr
), "Failed to unlock surface, hr %#x.\n", hr
);
8487 IDirectDrawSurface_Release(dst_surface
);
8488 IDirectDrawSurface_Release(src_surface
);
8490 IDirectDraw_Release(ddraw
);
8491 DestroyWindow(window
);
8494 static BOOL
dwm_enabled(void)
8498 if (!strcmp(winetest_platform
, "wine"))
8500 if (!pDwmIsCompositionEnabled
)
8502 if (FAILED(pDwmIsCompositionEnabled(&ret
)))
8507 static void test_offscreen_overlay(void)
8509 IDirectDrawSurface
*overlay
, *offscreen
, *primary
;
8510 DDSURFACEDESC surface_desc
;
8516 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8517 0, 0, 640, 480, 0, 0, 0, 0);
8518 ddraw
= create_ddraw();
8519 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8520 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8521 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8523 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
8525 skip("Failed to create a UYVY overlay, skipping test.\n");
8529 memset(&surface_desc
, 0, sizeof(surface_desc
));
8530 surface_desc
.dwSize
= sizeof(surface_desc
);
8531 surface_desc
.dwFlags
= DDSD_CAPS
;
8532 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8533 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
8534 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
8536 /* On Windows 7, and probably Vista, UpdateOverlay() will return
8537 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
8538 * surface prevents this by disabling the dwm. */
8539 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
8540 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8541 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
8542 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8544 /* Try to overlay a NULL surface. */
8545 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_SHOW
, NULL
);
8546 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8547 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, NULL
, NULL
, DDOVER_HIDE
, NULL
);
8548 ok(hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8550 /* Try to overlay an offscreen surface. */
8551 memset(&surface_desc
, 0, sizeof(surface_desc
));
8552 surface_desc
.dwSize
= sizeof(surface_desc
);
8553 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_HEIGHT
| DDSD_WIDTH
| DDSD_PIXELFORMAT
;
8554 surface_desc
.dwWidth
= 64;
8555 surface_desc
.dwHeight
= 64;
8556 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8557 surface_desc
.ddpfPixelFormat
.dwSize
= sizeof(surface_desc
.ddpfPixelFormat
);
8558 surface_desc
.ddpfPixelFormat
.dwFlags
= DDPF_RGB
;
8559 surface_desc
.ddpfPixelFormat
.dwFourCC
= 0;
8560 U1(surface_desc
.ddpfPixelFormat
).dwRGBBitCount
= 16;
8561 U2(surface_desc
.ddpfPixelFormat
).dwRBitMask
= 0xf800;
8562 U3(surface_desc
.ddpfPixelFormat
).dwGBitMask
= 0x07e0;
8563 U4(surface_desc
.ddpfPixelFormat
).dwBBitMask
= 0x001f;
8564 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &offscreen
, NULL
);
8565 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
8567 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, offscreen
, NULL
, DDOVER_SHOW
, NULL
);
8568 ok(SUCCEEDED(hr
) || broken(hr
== DDERR_OUTOFCAPS
&& dwm_enabled()),
8569 "Failed to update overlay, hr %#x.\n", hr
);
8571 /* Try to overlay the primary with a non-overlay surface. */
8572 hr
= IDirectDrawSurface_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
8573 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
8574 hr
= IDirectDrawSurface_UpdateOverlay(offscreen
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
8575 ok(hr
== DDERR_NOTAOVERLAYSURFACE
, "Got unexpected hr %#x.\n", hr
);
8577 IDirectDrawSurface_Release(offscreen
);
8578 IDirectDrawSurface_Release(primary
);
8579 IDirectDrawSurface_Release(overlay
);
8581 IDirectDraw_Release(ddraw
);
8582 DestroyWindow(window
);
8585 static void test_overlay_rect(void)
8587 IDirectDrawSurface
*overlay
, *primary
= NULL
;
8588 DDSURFACEDESC surface_desc
;
8589 RECT rect
= {0, 0, 64, 64};
8596 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8597 0, 0, 640, 480, 0, 0, 0, 0);
8598 ddraw
= create_ddraw();
8599 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8600 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8601 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8603 if (!(overlay
= create_overlay(ddraw
, 64, 64, MAKEFOURCC('U','Y','V','Y'))))
8605 skip("Failed to create a UYVY overlay, skipping test.\n");
8609 memset(&surface_desc
, 0, sizeof(surface_desc
));
8610 surface_desc
.dwSize
= sizeof(surface_desc
);
8611 surface_desc
.dwFlags
= DDSD_CAPS
;
8612 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_PRIMARYSURFACE
;
8613 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &primary
, NULL
);
8614 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n",hr
);
8616 /* On Windows 7, and probably Vista, UpdateOverlay() will return
8617 * DDERR_OUTOFCAPS if the dwm is active. Calling GetDC() on the primary
8618 * surface prevents this by disabling the dwm. */
8619 hr
= IDirectDrawSurface_GetDC(primary
, &dc
);
8620 ok(SUCCEEDED(hr
), "Failed to get DC, hr %#x.\n", hr
);
8621 hr
= IDirectDrawSurface_ReleaseDC(primary
, dc
);
8622 ok(SUCCEEDED(hr
), "Failed to release DC, hr %#x.\n", hr
);
8624 /* On Windows 8 and newer DWM can't be turned off, making overlays unusable. */
8627 win_skip("Cannot disable DWM, skipping overlay test.\n");
8631 /* The dx sdk sort of implies that rect must be set when DDOVER_SHOW is
8632 * used. This is not true in Windows Vista and earlier, but changed in
8634 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
8635 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
8636 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_HIDE
, NULL
);
8637 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
8638 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, DDOVER_SHOW
, NULL
);
8639 ok(hr
== DD_OK
|| hr
== DDERR_INVALIDPARAMS
, "Got unexpected hr %#x.\n", hr
);
8641 /* Show that the overlay position is the (top, left) coordinate of the
8642 * destination rectangle. */
8643 OffsetRect(&rect
, 32, 16);
8644 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_SHOW
, NULL
);
8645 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
8646 pos_x
= -1; pos_y
= -1;
8647 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
8648 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
8649 ok(pos_x
== rect
.left
, "Got unexpected pos_x %d, expected %d.\n", pos_x
, rect
.left
);
8650 ok(pos_y
== rect
.top
, "Got unexpected pos_y %d, expected %d.\n", pos_y
, rect
.top
);
8652 /* Passing a NULL dest rect sets the position to 0/0. Visually it can be
8653 * seen that the overlay overlays the whole primary(==screen). */
8654 hr2
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, NULL
, 0, NULL
);
8655 ok(hr2
== DD_OK
|| hr2
== DDERR_INVALIDPARAMS
|| hr2
== DDERR_OUTOFCAPS
, "Got unexpected hr %#x.\n", hr2
);
8656 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
8657 ok(SUCCEEDED(hr
), "Failed to get overlay position, hr %#x.\n", hr
);
8660 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
8661 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
8665 ok(pos_x
== 32, "Got unexpected pos_x %d.\n", pos_x
);
8666 ok(pos_y
== 16, "Got unexpected pos_y %d.\n", pos_y
);
8669 /* The position cannot be retrieved when the overlay is not shown. */
8670 hr
= IDirectDrawSurface_UpdateOverlay(overlay
, NULL
, primary
, &rect
, DDOVER_HIDE
, NULL
);
8671 ok(SUCCEEDED(hr
), "Failed to update overlay, hr %#x.\n", hr
);
8672 pos_x
= -1; pos_y
= -1;
8673 hr
= IDirectDrawSurface_GetOverlayPosition(overlay
, &pos_x
, &pos_y
);
8674 ok(hr
== DDERR_OVERLAYNOTVISIBLE
, "Got unexpected hr %#x.\n", hr
);
8675 ok(!pos_x
, "Got unexpected pos_x %d.\n", pos_x
);
8676 ok(!pos_y
, "Got unexpected pos_y %d.\n", pos_y
);
8678 IDirectDrawSurface_Release(overlay
);
8681 IDirectDrawSurface_Release(primary
);
8682 IDirectDraw_Release(ddraw
);
8683 DestroyWindow(window
);
8686 static void test_blt(void)
8688 IDirectDrawSurface
*surface
, *rt
;
8689 DDSURFACEDESC surface_desc
;
8690 IDirect3DDevice
*device
;
8705 {{160, 0, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit. */
8706 {{160, 480, 640, 0}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, flipped source. */
8707 {{640, 0, 160, 480}, { 0, 0, 480, 480}, DDERR_INVALIDRECT
}, /* Overlapped blit, mirrored source. */
8708 {{160, 0, 480, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched x. */
8709 {{160, 160, 640, 480}, { 0, 0, 480, 480}, DD_OK
}, /* Overlapped blit, stretched y. */
8710 {{ 0, 0, 640, 480}, { 0, 0, 640, 480}, DD_OK
}, /* Full surface blit. */
8711 {{ 0, 0, 640, 480}, { 0, 480, 640, 0}, DDERR_INVALIDRECT
}, /* Full surface, flipped destination. */
8712 {{ 0, 0, 640, 480}, {640, 0, 0, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored destination. */
8713 {{ 0, 480, 640, 0}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, flipped source. */
8714 {{640, 0, 0, 480}, { 0, 0, 640, 480}, DDERR_INVALIDRECT
}, /* Full surface, mirrored source. */
8717 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8718 0, 0, 640, 480, 0, 0, 0, 0);
8719 ddraw
= create_ddraw();
8720 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8721 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
8723 skip("Failed to create a 3D device, skipping test.\n");
8724 IDirectDraw_Release(ddraw
);
8725 DestroyWindow(window
);
8729 hr
= IDirect3DDevice_QueryInterface(device
, &IID_IDirectDrawSurface
, (void **)&rt
);
8730 ok(SUCCEEDED(hr
), "Failed to get render target, hr %#x.\n", hr
);
8732 memset(&surface_desc
, 0, sizeof(surface_desc
));
8733 surface_desc
.dwSize
= sizeof(surface_desc
);
8734 surface_desc
.dwFlags
= DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_CAPS
;
8735 surface_desc
.dwWidth
= 640;
8736 surface_desc
.dwHeight
= 480;
8737 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8738 hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
);
8739 ok(SUCCEEDED(hr
), "Failed to create surface, hr %#x.\n", hr
);
8741 hr
= IDirectDrawSurface_Blt(surface
, NULL
, surface
, NULL
, 0, NULL
);
8742 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
8744 hr
= IDirectDrawSurface_Blt(surface
, NULL
, rt
, NULL
, 0, NULL
);
8745 ok(SUCCEEDED(hr
), "Failed to blit, hr %#x.\n", hr
);
8747 for (i
= 0; i
< sizeof(test_data
) / sizeof(*test_data
); ++i
)
8749 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
8750 surface
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
8751 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
8753 hr
= IDirectDrawSurface_Blt(surface
, &test_data
[i
].dst_rect
,
8754 rt
, &test_data
[i
].src_rect
, DDBLT_WAIT
, NULL
);
8755 ok(hr
== test_data
[i
].hr
, "Test %u: Got unexpected hr %#x, expected %#x.\n", i
, hr
, test_data
[i
].hr
);
8758 IDirectDrawSurface_Release(surface
);
8759 IDirectDrawSurface_Release(rt
);
8760 refcount
= IDirect3DDevice_Release(device
);
8761 ok(!refcount
, "Device has %u references left.\n", refcount
);
8762 IDirectDraw_Release(ddraw
);
8763 DestroyWindow(window
);
8766 static void test_getdc(void)
8768 IDirectDrawSurface
*surface
, *surface2
, *tmp
;
8769 DDSURFACEDESC surface_desc
, map_desc
;
8770 DDSCAPS caps
= {DDSCAPS_COMPLEX
};
8780 DDPIXELFORMAT format
;
8781 BOOL getdc_supported
;
8786 {"D3DFMT_A8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
8787 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0xff000000}}, TRUE
},
8788 {"D3DFMT_X8R8G8B8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
8789 {0x00ff0000}, {0x0000ff00}, {0x000000ff}, {0x00000000}}, TRUE
},
8790 {"D3DFMT_R5G6B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
8791 {0x0000f800}, {0x000007e0}, {0x0000001f}, {0x00000000}}, TRUE
},
8792 {"D3DFMT_X1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
8793 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00000000}}, TRUE
},
8794 {"D3DFMT_A1R5G5B5", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
8795 {0x00007c00}, {0x000003e0}, {0x0000001f}, {0x00008000}}, TRUE
},
8796 {"D3DFMT_A4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {16},
8797 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x0000f000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
8798 {"D3DFMT_X4R4G4B4", {sizeof(test_data
->format
), DDPF_RGB
, 0, {16},
8799 {0x00000f00}, {0x000000f0}, {0x0000000f}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
8800 {"D3DFMT_A2R10G10B10", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
8801 {0xc0000000}, {0x3ff00000}, {0x000ffc00}, {0x000003ff}}, TRUE
},
8802 {"D3DFMT_A8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
| DDPF_ALPHAPIXELS
, 0, {32},
8803 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0xff000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
8804 {"D3DFMT_X8B8G8R8", {sizeof(test_data
->format
), DDPF_RGB
, 0, {32},
8805 {0x000000ff}, {0x0000ff00}, {0x00ff0000}, {0x00000000}}, TRUE
, DDERR_CANTCREATEDC
/* Vista+ */},
8806 {"D3DFMT_R3G3B2", {sizeof(test_data
->format
), DDPF_RGB
, 0, {8},
8807 {0x000000e0}, {0x0000001c}, {0x00000003}, {0x00000000}}, FALSE
},
8808 /* GetDC() on a P8 surface fails unless the display mode is 8 bpp.
8809 * This is not implemented in wine yet, so disable the test for now.
8810 * Succeeding P8 GetDC() calls are tested in the ddraw:visual test.
8811 {"D3DFMT_P8", {sizeof(test_data->format), DDPF_PALETTEINDEXED8 | DDPF_RGB, 0, {8 },
8812 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE},
8814 {"D3DFMT_L8", {sizeof(test_data
->format
), DDPF_LUMINANCE
, 0, {8},
8815 {0x000000ff}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
8816 {"D3DFMT_A8L8", {sizeof(test_data
->format
), DDPF_ALPHAPIXELS
| DDPF_LUMINANCE
, 0, {16},
8817 {0x000000ff}, {0x00000000}, {0x00000000}, {0x0000ff00}}, FALSE
},
8818 {"D3DFMT_DXT1", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','1'), {0},
8819 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
8820 {"D3DFMT_DXT2", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','2'), {0},
8821 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
8822 {"D3DFMT_DXT3", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','3'), {0},
8823 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
8824 {"D3DFMT_DXT4", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','4'), {0},
8825 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
8826 {"D3DFMT_DXT5", {sizeof(test_data
->format
), DDPF_FOURCC
, MAKEFOURCC('D','X','T','5'), {0},
8827 {0x00000000}, {0x00000000}, {0x00000000}, {0x00000000}}, FALSE
},
8830 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
8831 0, 0, 640, 480, 0, 0, 0, 0);
8832 ddraw
= create_ddraw();
8833 ok(!!ddraw
, "Failed to create a ddraw object.\n");
8834 hr
= IDirectDraw_SetCooperativeLevel(ddraw
, window
, DDSCL_NORMAL
);
8835 ok(SUCCEEDED(hr
), "Failed to set cooperative level, hr %#x.\n", hr
);
8837 for (i
= 0; i
< (sizeof(test_data
) / sizeof(*test_data
)); ++i
)
8839 memset(&surface_desc
, 0, sizeof(surface_desc
));
8840 surface_desc
.dwSize
= sizeof(surface_desc
);
8841 surface_desc
.dwFlags
= DDSD_CAPS
| DDSD_WIDTH
| DDSD_HEIGHT
| DDSD_PIXELFORMAT
;
8842 surface_desc
.dwWidth
= 64;
8843 surface_desc
.dwHeight
= 64;
8844 U4(surface_desc
).ddpfPixelFormat
= test_data
[i
].format
;
8845 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_OFFSCREENPLAIN
;
8847 if (FAILED(IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
8849 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
;
8850 if (FAILED(hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
8852 skip("Failed to create surface for format %s (hr %#x), skipping tests.\n", test_data
[i
].name
, hr
);
8857 dc
= (void *)0x1234;
8858 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
8859 if (test_data
[i
].getdc_supported
)
8860 ok(SUCCEEDED(hr
) || (test_data
[i
].alt_result
&& hr
== test_data
[i
].alt_result
),
8861 "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
8863 ok(FAILED(hr
), "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
8867 unsigned int width_bytes
;
8873 type
= GetObjectType(dc
);
8874 ok(type
== OBJ_MEMDC
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
8875 bitmap
= GetCurrentObject(dc
, OBJ_BITMAP
);
8876 type
= GetObjectType(bitmap
);
8877 ok(type
== OBJ_BITMAP
, "Got unexpected object type %#x for format %s.\n", type
, test_data
[i
].name
);
8879 size
= GetObjectA(bitmap
, sizeof(dib
), &dib
);
8880 ok(size
== sizeof(dib
), "Got unexpected size %d for format %s.\n", size
, test_data
[i
].name
);
8881 ok(!dib
.dsBm
.bmType
, "Got unexpected type %#x for format %s.\n",
8882 dib
.dsBm
.bmType
, test_data
[i
].name
);
8883 ok(dib
.dsBm
.bmWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
8884 dib
.dsBm
.bmWidth
, test_data
[i
].name
);
8885 ok(dib
.dsBm
.bmHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
8886 dib
.dsBm
.bmHeight
, test_data
[i
].name
);
8887 width_bytes
= ((dib
.dsBm
.bmWidth
* U1(test_data
[i
].format
).dwRGBBitCount
+ 31) >> 3) & ~3;
8888 ok(dib
.dsBm
.bmWidthBytes
== width_bytes
, "Got unexpected width bytes %d for format %s.\n",
8889 dib
.dsBm
.bmWidthBytes
, test_data
[i
].name
);
8890 ok(dib
.dsBm
.bmPlanes
== 1, "Got unexpected plane count %d for format %s.\n",
8891 dib
.dsBm
.bmPlanes
, test_data
[i
].name
);
8892 ok(dib
.dsBm
.bmBitsPixel
== U1(test_data
[i
].format
).dwRGBBitCount
,
8893 "Got unexpected bit count %d for format %s.\n",
8894 dib
.dsBm
.bmBitsPixel
, test_data
[i
].name
);
8895 ok(!!dib
.dsBm
.bmBits
, "Got unexpected bits %p for format %s.\n",
8896 dib
.dsBm
.bmBits
, test_data
[i
].name
);
8898 ok(dib
.dsBmih
.biSize
== sizeof(dib
.dsBmih
), "Got unexpected size %u for format %s.\n",
8899 dib
.dsBmih
.biSize
, test_data
[i
].name
);
8900 ok(dib
.dsBmih
.biWidth
== surface_desc
.dwWidth
, "Got unexpected width %d for format %s.\n",
8901 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
8902 ok(dib
.dsBmih
.biHeight
== surface_desc
.dwHeight
, "Got unexpected height %d for format %s.\n",
8903 dib
.dsBmih
.biHeight
, test_data
[i
].name
);
8904 ok(dib
.dsBmih
.biPlanes
== 1, "Got unexpected plane count %u for format %s.\n",
8905 dib
.dsBmih
.biPlanes
, test_data
[i
].name
);
8906 ok(dib
.dsBmih
.biBitCount
== U1(test_data
[i
].format
).dwRGBBitCount
,
8907 "Got unexpected bit count %u for format %s.\n",
8908 dib
.dsBmih
.biBitCount
, test_data
[i
].name
);
8909 ok(dib
.dsBmih
.biCompression
== (U1(test_data
[i
].format
).dwRGBBitCount
== 16 ? BI_BITFIELDS
: BI_RGB
)
8910 || broken(U2(test_data
[i
].format
).dwRGBBitCount
== 32 && dib
.dsBmih
.biCompression
== BI_BITFIELDS
),
8911 "Got unexpected compression %#x for format %s.\n",
8912 dib
.dsBmih
.biCompression
, test_data
[i
].name
);
8913 ok(!dib
.dsBmih
.biSizeImage
, "Got unexpected image size %u for format %s.\n",
8914 dib
.dsBmih
.biSizeImage
, test_data
[i
].name
);
8915 ok(!dib
.dsBmih
.biXPelsPerMeter
, "Got unexpected horizontal resolution %d for format %s.\n",
8916 dib
.dsBmih
.biXPelsPerMeter
, test_data
[i
].name
);
8917 ok(!dib
.dsBmih
.biYPelsPerMeter
, "Got unexpected vertical resolution %d for format %s.\n",
8918 dib
.dsBmih
.biYPelsPerMeter
, test_data
[i
].name
);
8919 ok(!dib
.dsBmih
.biClrUsed
, "Got unexpected used colour count %u for format %s.\n",
8920 dib
.dsBmih
.biClrUsed
, test_data
[i
].name
);
8921 ok(!dib
.dsBmih
.biClrImportant
, "Got unexpected important colour count %u for format %s.\n",
8922 dib
.dsBmih
.biClrImportant
, test_data
[i
].name
);
8924 if (dib
.dsBmih
.biCompression
== BI_BITFIELDS
)
8926 ok((dib
.dsBitfields
[0] == U2(test_data
[i
].format
).dwRBitMask
8927 && dib
.dsBitfields
[1] == U3(test_data
[i
].format
).dwGBitMask
8928 && dib
.dsBitfields
[2] == U4(test_data
[i
].format
).dwBBitMask
)
8929 || broken(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2]),
8930 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
8931 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
8935 ok(!dib
.dsBitfields
[0] && !dib
.dsBitfields
[1] && !dib
.dsBitfields
[2],
8936 "Got unexpected colour masks 0x%08x 0x%08x 0x%08x for format %s.\n",
8937 dib
.dsBitfields
[0], dib
.dsBitfields
[1], dib
.dsBitfields
[2], test_data
[i
].name
);
8939 ok(!dib
.dshSection
, "Got unexpected section %p for format %s.\n", dib
.dshSection
, test_data
[i
].name
);
8940 ok(!dib
.dsOffset
, "Got unexpected offset %u for format %s.\n", dib
.dsOffset
, test_data
[i
].name
);
8942 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
8943 ok(hr
== DD_OK
, "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8947 ok(!dc
, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
8950 IDirectDrawSurface_Release(surface
);
8955 surface_desc
.ddsCaps
.dwCaps
= DDSCAPS_TEXTURE
| DDSCAPS_COMPLEX
| DDSCAPS_MIPMAP
;
8956 if (FAILED(hr
= IDirectDraw_CreateSurface(ddraw
, &surface_desc
, &surface
, NULL
)))
8958 skip("Failed to create mip-mapped texture for format %s (hr %#x), skipping tests.\n",
8959 test_data
[i
].name
, hr
);
8963 hr
= IDirectDrawSurface_GetAttachedSurface(surface
, &caps
, &tmp
);
8964 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8965 hr
= IDirectDrawSurface_GetAttachedSurface(tmp
, &caps
, &surface2
);
8966 ok(SUCCEEDED(hr
), "Failed to get attached surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8967 IDirectDrawSurface_Release(tmp
);
8969 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
8970 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8971 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
8972 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8973 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
8974 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8975 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
8976 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8978 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
8979 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8980 dc2
= (void *)0x1234;
8981 hr
= IDirectDrawSurface_GetDC(surface
, &dc2
);
8982 ok(hr
== DDERR_DCALREADYCREATED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
8983 ok(dc2
== (void *)0x1234, "Got unexpected dc %p for format %s.\n", dc
, test_data
[i
].name
);
8984 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
8985 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8986 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
8987 ok(hr
== DDERR_NODC
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
8989 map_desc
.dwSize
= sizeof(map_desc
);
8990 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
8991 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8992 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
8993 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
8994 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8995 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
8996 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
8997 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
8999 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
9000 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9001 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
9002 ok(hr
== DDERR_SURFACEBUSY
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
9003 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
9004 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9006 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
9007 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9008 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
9009 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9010 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
9011 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9012 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
9013 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9015 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
9016 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9017 hr
= IDirectDrawSurface_GetDC(surface2
, &dc2
);
9018 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9019 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc2
);
9020 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9021 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
9022 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9024 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
9025 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9026 hr
= IDirectDrawSurface_GetDC(surface
, &dc2
);
9027 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9028 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc2
);
9029 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9030 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
9031 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9033 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
9034 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9035 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
9036 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9037 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
9038 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9039 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
9040 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9042 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
9043 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9044 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
9045 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9046 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
9047 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9048 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
9049 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9051 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
9052 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9053 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
9054 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9055 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
9056 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9057 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
9058 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9060 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
9061 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9062 hr
= IDirectDrawSurface_Lock(surface2
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
9063 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9064 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
9065 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9066 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
9067 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9069 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
9070 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9071 hr
= IDirectDrawSurface_Lock(surface
, NULL
, &map_desc
, DDLOCK_READONLY
| DDLOCK_WAIT
, NULL
);
9072 ok(SUCCEEDED(hr
), "Failed to map surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9073 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
9074 ok(SUCCEEDED(hr
), "Failed to unmap surface for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9075 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
9076 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9078 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
9079 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
9080 hr
= IDirectDrawSurface_GetDC(surface2
, &dc
);
9081 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9082 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
9083 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
9084 hr
= IDirectDrawSurface_ReleaseDC(surface2
, dc
);
9085 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9086 hr
= IDirectDrawSurface_Unlock(surface
, NULL
);
9087 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
9089 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
9090 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
9091 hr
= IDirectDrawSurface_GetDC(surface
, &dc
);
9092 ok(SUCCEEDED(hr
), "Failed to get DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9093 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
9094 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
9095 hr
= IDirectDrawSurface_ReleaseDC(surface
, dc
);
9096 ok(SUCCEEDED(hr
), "Failed to release DC for format %s, hr %#x.\n", test_data
[i
].name
, hr
);
9097 hr
= IDirectDrawSurface_Unlock(surface2
, NULL
);
9098 ok(hr
== DDERR_NOTLOCKED
, "Got unexpected hr %#x for format %s.\n", hr
, test_data
[i
].name
);
9100 IDirectDrawSurface_Release(surface2
);
9101 IDirectDrawSurface_Release(surface
);
9104 IDirectDraw_Release(ddraw
);
9105 DestroyWindow(window
);
9108 /* TransformVertices always writes 32 bytes regardless of the input / output stride.
9109 * The stride is honored for navigating to the next vertex. 3 floats input position
9110 * are read, and 16 bytes extra vertex data are copied around. */
9111 struct transform_input
9113 float x
, y
, z
, unused1
; /* Position data, transformed. */
9114 DWORD v1
, v2
, v3
, v4
; /* Extra data, e.g. color and texture coords, copied. */
9118 struct transform_output
9121 DWORD v1
, v2
, v3
, v4
;
9122 DWORD unused3
, unused4
;
9125 static void test_transform_vertices(void)
9127 IDirect3DDevice
*device
;
9132 IDirect3DViewport
*viewport
;
9133 IDirect3DExecuteBuffer
*execute_buffer
;
9134 D3DEXECUTEBUFFERDESC exec_desc
;
9137 D3DMATRIXHANDLE world_handle
, view_handle
, proj_handle
;
9138 static struct transform_input position_tests
[] =
9140 { 0.0f
, 0.0f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
9141 { 1.0f
, 1.0f
, 1.0f
, 8.0f
, 6, 7, 8, 9, 10},
9142 {-1.0f
, -1.0f
, -1.0f
, 4.0f
, 11, 12, 13, 14, 15},
9143 { 0.5f
, 0.5f
, 0.5f
, 2.0f
, 16, 17, 18, 19, 20},
9144 {-0.5f
, -0.5f
, -0.5f
, 1.0f
, ~1U, ~2U, ~3U, ~4U, ~5U},
9145 {-0.5f
, -0.5f
, 0.0f
, 0.0f
, ~6U, ~7U, ~8U, ~9U, ~0U},
9147 static struct transform_input cliptest
[] =
9149 { 25.59f
, 25.59f
, 1.0f
, 0.0f
, 1, 2, 3, 4, 5},
9150 { 25.61f
, 25.61f
, 1.01f
, 0.0f
, 1, 2, 3, 4, 5},
9151 {-25.59f
, -25.59f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
9152 {-25.61f
, -25.61f
, -0.01f
, 0.0f
, 1, 2, 3, 4, 5},
9154 static struct transform_input offscreentest
[] =
9156 {128.1f
, 0.0f
, 0.0f
, 0.0f
, 1, 2, 3, 4, 5},
9158 struct transform_output out
[ARRAY_SIZE(position_tests
)];
9159 D3DHVERTEX out_h
[ARRAY_SIZE(position_tests
)];
9160 D3DTRANSFORMDATA transformdata
;
9161 static const D3DVIEWPORT vp_template
=
9163 sizeof(vp_template
), 0, 0, 256, 256, 5.0f
, 5.0f
, 256.0f
, 256.0f
, -25.0f
, 60.0f
9165 D3DVIEWPORT vp_data
=
9167 sizeof(vp_data
), 0, 0, 256, 256, 1.0f
, 1.0f
, 256.0f
, 256.0f
, 0.0f
, 1.0f
9171 static D3DMATRIX mat_scale
=
9173 2.0f
, 0.0f
, 0.0f
, 0.0f
,
9174 0.0f
, 2.0f
, 0.0f
, 0.0f
,
9175 0.0f
, 0.0f
, 2.0f
, 0.0f
,
9176 0.0f
, 0.0f
, 0.0f
, 1.0f
,
9180 1.0f
, 0.0f
, 0.0f
, 0.0f
,
9181 0.0f
, 1.0f
, 0.0f
, 0.0f
,
9182 0.0f
, 0.0f
, 1.0f
, 0.0f
,
9183 1.0f
, 0.0f
, 0.0f
, 1.0f
,
9187 1.0f
, 0.0f
, 0.0f
, 0.0f
,
9188 0.0f
, 1.0f
, 0.0f
, 0.0f
,
9189 0.0f
, 0.0f
, 1.0f
, 0.0f
,
9190 0.0f
, 1.0f
, 0.0f
, 1.0f
,
9194 for (i
= 0; i
< ARRAY_SIZE(out
); ++i
)
9196 out
[i
].unused3
= 0xdeadbeef;
9197 out
[i
].unused4
= 0xcafecafe;
9200 window
= CreateWindowA("static", "ddraw_test", WS_OVERLAPPEDWINDOW
,
9201 0, 0, 640, 480, 0, 0, 0, 0);
9202 ddraw
= create_ddraw();
9203 ok(!!ddraw
, "Failed to create a ddraw object.\n");
9204 if (!(device
= create_device(ddraw
, window
, DDSCL_NORMAL
)))
9206 skip("Failed to create a 3D device, skipping test.\n");
9207 IDirectDraw_Release(ddraw
);
9208 DestroyWindow(window
);
9212 viewport
= create_viewport(device
, 0, 0, 256, 256);
9213 hr
= IDirect3DViewport_SetViewport(viewport
, &vp_data
);
9214 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
9216 memset(&transformdata
, 0, sizeof(transformdata
));
9217 transformdata
.dwSize
= sizeof(transformdata
);
9218 transformdata
.lpIn
= position_tests
;
9219 transformdata
.dwInSize
= sizeof(position_tests
[0]);
9220 transformdata
.lpOut
= out
;
9221 transformdata
.dwOutSize
= sizeof(out
[0]);
9222 transformdata
.lpHOut
= NULL
;
9224 hr
= IDirect3DViewport_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
9225 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
9226 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9227 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9229 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
9231 static const struct vec4 cmp
[] =
9233 {128.0f
, 128.0f
, 0.0f
, 1.0f
}, {129.0f
, 127.0f
, 1.0f
, 1.0f
}, {127.0f
, 129.0f
, -1.0f
, 1.0f
},
9234 {128.5f
, 127.5f
, 0.5f
, 1.0f
}, {127.5f
, 128.5f
, -0.5f
, 1.0f
}, {127.5f
, 128.5f
, 0.0f
, 1.0f
}
9237 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
9238 "Vertex %u differs. Got %f %f %f %f.\n", i
,
9239 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
9240 ok(out
[i
].v1
== position_tests
[i
].v1
&& out
[i
].v2
== position_tests
[i
].v2
9241 && out
[i
].v3
== position_tests
[i
].v3
&& out
[i
].v4
== position_tests
[i
].v4
,
9242 "Vertex %u payload is %u %u %u %u.\n", i
, out
[i
].v1
, out
[i
].v2
, out
[i
].v3
, out
[i
].v4
);
9243 ok(out
[i
].unused3
== 0xdeadbeef && out
[i
].unused4
== 0xcafecafe,
9244 "Vertex %u unused data is %#x, %#x.\n", i
, out
[i
].unused3
, out
[i
].unused4
);
9247 vp_data
= vp_template
;
9248 hr
= IDirect3DViewport_SetViewport(viewport
, &vp_data
);
9249 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
9250 offscreen
= 0xdeadbeef;
9251 hr
= IDirect3DViewport_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
9252 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
9253 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9254 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9256 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
9258 static const struct vec4 cmp
[] =
9260 {128.0f
, 128.0f
, 0.0f
, 1.0f
}, {133.0f
, 123.0f
, 1.0f
, 1.0f
}, {123.0f
, 133.0f
, -1.0f
, 1.0f
},
9261 {130.5f
, 125.5f
, 0.5f
, 1.0f
}, {125.5f
, 130.5f
, -0.5f
, 1.0f
}, {125.5f
, 130.5f
, 0.0f
, 1.0f
}
9263 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
9264 "Vertex %u differs. Got %f %f %f %f.\n", i
,
9265 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
9270 hr
= IDirect3DViewport_SetViewport(viewport
, &vp_data
);
9271 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
9272 offscreen
= 0xdeadbeef;
9273 hr
= IDirect3DViewport_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
9274 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
9275 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9276 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9277 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
9279 static const struct vec4 cmp
[] =
9281 {138.0f
, 148.0f
, 0.0f
, 1.0f
}, {143.0f
, 143.0f
, 1.0f
, 1.0f
}, {133.0f
, 153.0f
, -1.0f
, 1.0f
},
9282 {140.5f
, 145.5f
, 0.5f
, 1.0f
}, {135.5f
, 150.5f
, -0.5f
, 1.0f
}, {135.5f
, 150.5f
, 0.0f
, 1.0f
}
9284 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
9285 "Vertex %u differs. Got %f %f %f %f.\n", i
,
9286 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
9289 transformdata
.lpHOut
= out_h
;
9290 offscreen
= 0xdeadbeef;
9291 hr
= IDirect3DViewport_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
9292 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9293 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9294 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9295 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
9297 static const D3DHVERTEX cmp_h
[] =
9299 {0, { 0.0f
}, { 0.0f
}, { 0.0f
}}, {0, { 1.0f
}, { 1.0f
}, {1.0f
}},
9300 {D3DCLIP_FRONT
, {-1.0f
}, {-1.0f
}, {-1.0f
}}, {0, { 0.5f
}, { 0.5f
}, {0.5f
}},
9301 {D3DCLIP_FRONT
, {-0.5f
}, {-0.5f
}, {-0.5f
}}, {0, {-0.5f
}, {-0.5f
}, {0.0f
}}
9303 ok(compare_float(U1(cmp_h
[i
]).hx
, U1(out_h
[i
]).hx
, 4096)
9304 && compare_float(U1(cmp_h
[i
]).hy
, U1(out_h
[i
]).hy
, 4096)
9305 && compare_float(U1(cmp_h
[i
]).hz
, U1(out_h
[i
]).hz
, 4096)
9306 && cmp_h
[i
].dwFlags
== out_h
[i
].dwFlags
,
9307 "HVertex %u differs. Got %#x %f %f %f.\n", i
,
9308 out_h
[i
].dwFlags
, U1(out_h
[i
]).hx
, U2(out_h
[i
]).hy
, U3(out_h
[i
]).hz
);
9310 /* No scheme has been found behind those return values. It seems to be
9311 * whatever data windows has when throwing the vertex away. Modify the
9312 * input test vertices to test this more. Depending on the input data
9313 * it can happen that the z coord gets written into y, or similar things. */
9316 static const struct vec4 cmp
[] =
9318 {138.0f
, 148.0f
, 0.0f
, 1.0f
}, {143.0f
, 143.0f
, 1.0f
, 1.0f
}, { -1.0f
, -1.0f
, 0.5f
, 1.0f
},
9319 {140.5f
, 145.5f
, 0.5f
, 1.0f
}, { -0.5f
, -0.5f
, -0.5f
, 1.0f
}, {135.5f
, 150.5f
, 0.0f
, 1.0f
}
9321 ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
9322 "Vertex %u differs. Got %f %f %f %f.\n", i
,
9323 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
9327 transformdata
.lpIn
= cliptest
;
9328 transformdata
.dwInSize
= sizeof(cliptest
[0]);
9329 offscreen
= 0xdeadbeef;
9330 hr
= IDirect3DViewport_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
9331 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9332 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9333 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9334 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
9336 static const DWORD flags
[] =
9339 D3DCLIP_RIGHT
| D3DCLIP_BACK
| D3DCLIP_TOP
,
9341 D3DCLIP_LEFT
| D3DCLIP_BOTTOM
| D3DCLIP_FRONT
,
9343 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
9346 vp_data
= vp_template
;
9347 vp_data
.dwWidth
= 10;
9348 vp_data
.dwHeight
= 1000;
9349 hr
= IDirect3DViewport_SetViewport(viewport
, &vp_data
);
9350 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
9351 offscreen
= 0xdeadbeef;
9352 hr
= IDirect3DViewport_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
9353 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9354 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9355 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9356 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
9358 static const DWORD flags
[] =
9361 D3DCLIP_RIGHT
| D3DCLIP_BACK
,
9363 D3DCLIP_LEFT
| D3DCLIP_FRONT
,
9365 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
9368 vp_data
= vp_template
;
9369 vp_data
.dwWidth
= 256;
9370 vp_data
.dwHeight
= 256;
9371 vp_data
.dvScaleX
= 1;
9372 vp_data
.dvScaleY
= 1;
9373 hr
= IDirect3DViewport_SetViewport(viewport
, &vp_data
);
9374 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
9375 hr
= IDirect3DViewport_TransformVertices(viewport
, ARRAY_SIZE(cliptest
),
9376 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9377 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9378 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9379 for (i
= 0; i
< ARRAY_SIZE(cliptest
); ++i
)
9381 static const DWORD flags
[] =
9388 ok(flags
[i
] == out_h
[i
].dwFlags
, "Cliptest %u returned %#x.\n", i
, out_h
[i
].dwFlags
);
9391 /* Finally try to figure out how the DWORD dwOffscreen works.
9392 * It is a logical AND of the vertices' dwFlags members. */
9393 vp_data
= vp_template
;
9394 vp_data
.dwWidth
= 5;
9395 vp_data
.dwHeight
= 5;
9396 vp_data
.dvScaleX
= 10000.0f
;
9397 vp_data
.dvScaleY
= 10000.0f
;
9398 hr
= IDirect3DViewport_SetViewport(viewport
, &vp_data
);
9399 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
9400 transformdata
.lpIn
= cliptest
;
9401 offscreen
= 0xdeadbeef;
9402 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9403 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
9404 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9405 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9407 offscreen
= 0xdeadbeef;
9408 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9409 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9410 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9411 ok(offscreen
== (D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
9412 offscreen
= 0xdeadbeef;
9413 hr
= IDirect3DViewport_TransformVertices(viewport
, 2,
9414 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9415 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9416 ok(offscreen
== (D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
9417 hr
= IDirect3DViewport_TransformVertices(viewport
, 3,
9418 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9419 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9420 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9422 transformdata
.lpIn
= cliptest
+ 1;
9423 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9424 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9425 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9426 ok(offscreen
== (D3DCLIP_BACK
| D3DCLIP_RIGHT
| D3DCLIP_TOP
), "Offscreen is %x.\n", offscreen
);
9428 transformdata
.lpIn
= cliptest
+ 2;
9429 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9430 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9431 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9432 ok(offscreen
== (D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
9433 offscreen
= 0xdeadbeef;
9434 hr
= IDirect3DViewport_TransformVertices(viewport
, 2,
9435 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9436 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9437 ok(offscreen
== (D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
9439 transformdata
.lpIn
= cliptest
+ 3;
9440 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9441 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9442 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9443 ok(offscreen
== (D3DCLIP_FRONT
| D3DCLIP_BOTTOM
| D3DCLIP_LEFT
), "Offscreen is %x.\n", offscreen
);
9445 transformdata
.lpIn
= offscreentest
;
9446 transformdata
.dwInSize
= sizeof(offscreentest
[0]);
9447 vp_data
= vp_template
;
9448 vp_data
.dwWidth
= 257;
9449 vp_data
.dwHeight
= 257;
9450 vp_data
.dvScaleX
= 1.0f
;
9451 vp_data
.dvScaleY
= 1.0f
;
9452 hr
= IDirect3DViewport_SetViewport(viewport
, &vp_data
);
9453 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
9454 offscreen
= 0xdeadbeef;
9455 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9456 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9457 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9458 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9460 vp_data
.dwWidth
= 256;
9461 vp_data
.dwHeight
= 256;
9462 hr
= IDirect3DViewport_SetViewport(viewport
, &vp_data
);
9463 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
9464 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9465 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9466 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9467 ok(offscreen
== D3DCLIP_RIGHT
, "Offscreen is %x.\n", offscreen
);
9469 /* Test the effect of Matrices.
9471 * Basically the x coodinate ends up as ((x + 1) * 2 + 0) * 5 and
9472 * y as ((y + 0) * 2 + 1) * 5. The 5 comes from dvScaleX/Y, 2 from
9473 * the view matrix and the +1's from the world and projection matrix. */
9476 vp_data
.dwWidth
= 256;
9477 vp_data
.dwHeight
= 256;
9478 vp_data
.dvScaleX
= 5.0f
;
9479 vp_data
.dvScaleY
= 5.0f
;
9480 vp_data
.dvMinZ
= 0.0f
;
9481 vp_data
.dvMaxZ
= 1.0f
;
9482 hr
= IDirect3DViewport_SetViewport(viewport
, &vp_data
);
9483 ok(SUCCEEDED(hr
), "Failed to set viewport, hr %#x.\n", hr
);
9485 hr
= IDirect3DDevice_CreateMatrix(device
, &world_handle
);
9486 ok(hr
== D3D_OK
, "Creating a matrix object failed, hr %#x.\n", hr
);
9487 hr
= IDirect3DDevice_SetMatrix(device
, world_handle
, &mat_translate1
);
9488 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
9490 hr
= IDirect3DDevice_CreateMatrix(device
, &view_handle
);
9491 ok(hr
== D3D_OK
, "Creating a matrix object failed, hr %#x.\n", hr
);
9492 hr
= IDirect3DDevice_SetMatrix(device
, view_handle
, &mat_scale
);
9493 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
9495 hr
= IDirect3DDevice_CreateMatrix(device
, &proj_handle
);
9496 ok(hr
== D3D_OK
, "Creating a matrix object failed, hr %#x.\n", hr
);
9497 hr
= IDirect3DDevice_SetMatrix(device
, proj_handle
, &mat_translate2
);
9498 ok(hr
== D3D_OK
, "Setting a matrix object failed, hr %#x.\n", hr
);
9500 memset(&exec_desc
, 0, sizeof(exec_desc
));
9501 exec_desc
.dwSize
= sizeof(exec_desc
);
9502 exec_desc
.dwFlags
= D3DDEB_BUFSIZE
| D3DDEB_CAPS
;
9503 exec_desc
.dwBufferSize
= 1024;
9504 exec_desc
.dwCaps
= D3DDEBCAPS_SYSTEMMEMORY
;
9505 hr
= IDirect3DDevice_CreateExecuteBuffer(device
, &exec_desc
, &execute_buffer
, NULL
);
9506 ok(SUCCEEDED(hr
), "Failed to create execute buffer, hr %#x.\n", hr
);
9508 hr
= IDirect3DExecuteBuffer_Lock(execute_buffer
, &exec_desc
);
9509 ok(SUCCEEDED(hr
), "Failed to lock execute buffer, hr %#x.\n", hr
);
9510 ptr
= (BYTE
*)exec_desc
.lpData
;
9511 emit_set_ts(&ptr
, D3DTRANSFORMSTATE_WORLD
, world_handle
);
9512 emit_set_ts(&ptr
, D3DTRANSFORMSTATE_VIEW
, view_handle
);
9513 emit_set_ts(&ptr
, D3DTRANSFORMSTATE_PROJECTION
, proj_handle
);
9515 inst_length
= (BYTE
*)ptr
- (BYTE
*)exec_desc
.lpData
;
9516 hr
= IDirect3DExecuteBuffer_Unlock(execute_buffer
);
9517 ok(SUCCEEDED(hr
), "Failed to unlock execute buffer, hr %#x.\n", hr
);
9519 set_execute_data(execute_buffer
, 0, 0, inst_length
);
9520 hr
= IDirect3DDevice_BeginScene(device
);
9521 ok(SUCCEEDED(hr
), "Failed to begin scene, hr %#x.\n", hr
);
9522 hr
= IDirect3DDevice_Execute(device
, execute_buffer
, viewport
, D3DEXECUTE_CLIPPED
);
9523 ok(SUCCEEDED(hr
), "Failed to execute exec buffer, hr %#x.\n", hr
);
9524 hr
= IDirect3DDevice_EndScene(device
);
9525 ok(SUCCEEDED(hr
), "Failed to end scene, hr %#x.\n", hr
);
9527 transformdata
.lpIn
= position_tests
;
9528 transformdata
.dwInSize
= sizeof(position_tests
[0]);
9529 hr
= IDirect3DViewport_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
9530 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
9531 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9533 for (i
= 0; i
< ARRAY_SIZE(position_tests
); ++i
)
9535 static const struct vec4 cmp
[] =
9537 {138.0f
, 123.0f
, 0.0f
, 1.0f
}, {148.0f
, 113.0f
, 2.0f
, 1.0f
}, {128.0f
, 133.0f
, -2.0f
, 1.0f
},
9538 {143.0f
, 118.0f
, 1.0f
, 1.0f
}, {133.0f
, 128.0f
, -1.0f
, 1.0f
}, {133.0f
, 128.0f
, 0.0f
, 1.0f
}
9541 todo_wine
ok(compare_vec4(&cmp
[i
], out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
, 4096),
9542 "Vertex %u differs. Got %f %f %f %f.\n", i
,
9543 out
[i
].x
, out
[i
].y
, out
[i
].z
, out
[i
].w
);
9546 /* Invalid flags. */
9547 offscreen
= 0xdeadbeef;
9548 hr
= IDirect3DViewport_TransformVertices(viewport
, ARRAY_SIZE(position_tests
),
9549 &transformdata
, 0, &offscreen
);
9550 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
9551 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
9553 /* NULL transform data. */
9554 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9555 NULL
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
9556 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
9557 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
9558 hr
= IDirect3DViewport_TransformVertices(viewport
, 0,
9559 NULL
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
9560 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
9561 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
9563 /* NULL transform data and NULL dwOffscreen.
9565 * Valid transform data + NULL dwOffscreen -> crash. */
9566 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9567 NULL
, D3DTRANSFORM_UNCLIPPED
, NULL
);
9568 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
9571 hr
= IDirect3DViewport_TransformVertices(viewport
, 0,
9572 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
9573 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9574 ok(!offscreen
, "Offscreen is %x.\n", offscreen
);
9575 hr
= IDirect3DViewport_TransformVertices(viewport
, 0,
9576 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9577 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9578 ok(offscreen
== ~0U, "Offscreen is %x.\n", offscreen
);
9580 /* Invalid sizes. */
9581 offscreen
= 0xdeadbeef;
9582 transformdata
.dwSize
= sizeof(transformdata
) - 1;
9583 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9584 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
9585 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
9586 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
9587 transformdata
.dwSize
= sizeof(transformdata
) + 1;
9588 hr
= IDirect3DViewport_TransformVertices(viewport
, 1,
9589 &transformdata
, D3DTRANSFORM_UNCLIPPED
, &offscreen
);
9590 ok(hr
== DDERR_INVALIDPARAMS
, "TransformVertices returned %#x.\n", hr
);
9591 ok(offscreen
== 0xdeadbeef, "Offscreen is %x.\n", offscreen
);
9593 /* NULL lpIn or lpOut -> crash, except when transforming 0 vertices. */
9594 transformdata
.dwSize
= sizeof(transformdata
);
9595 transformdata
.lpIn
= NULL
;
9596 transformdata
.lpOut
= NULL
;
9597 offscreen
= 0xdeadbeef;
9598 hr
= IDirect3DViewport_TransformVertices(viewport
, 0,
9599 &transformdata
, D3DTRANSFORM_CLIPPED
, &offscreen
);
9600 ok(SUCCEEDED(hr
), "Failed to transform vertices, hr %#x.\n", hr
);
9601 ok(offscreen
== ~0U, "Offscreen is %x.\n", offscreen
);
9603 IDirect3DDevice_DeleteMatrix(device
, world_handle
);
9604 IDirect3DDevice_DeleteMatrix(device
, view_handle
);
9605 IDirect3DDevice_DeleteMatrix(device
, proj_handle
);
9606 IDirect3DExecuteBuffer_Release(execute_buffer
);
9608 destroy_viewport(device
, viewport
);
9609 refcount
= IDirect3DDevice_Release(device
);
9610 ok(!refcount
, "Device has %u references left.\n", refcount
);
9611 IDirectDraw_Release(ddraw
);
9612 DestroyWindow(window
);
9618 DEVMODEW current_mode
;
9621 if (!(ddraw
= create_ddraw()))
9623 skip("Failed to create a ddraw object, skipping tests.\n");
9626 IDirectDraw_Release(ddraw
);
9628 memset(¤t_mode
, 0, sizeof(current_mode
));
9629 current_mode
.dmSize
= sizeof(current_mode
);
9630 ok(EnumDisplaySettingsW(NULL
, ENUM_CURRENT_SETTINGS
, ¤t_mode
), "Failed to get display mode.\n");
9631 registry_mode
.dmSize
= sizeof(registry_mode
);
9632 ok(EnumDisplaySettingsW(NULL
, ENUM_REGISTRY_SETTINGS
, ®istry_mode
), "Failed to get display mode.\n");
9633 if (registry_mode
.dmPelsWidth
!= current_mode
.dmPelsWidth
9634 || registry_mode
.dmPelsHeight
!= current_mode
.dmPelsHeight
)
9636 skip("Current mode does not match registry mode, skipping test.\n");
9640 if ((dwmapi
= LoadLibraryA("dwmapi.dll")))
9641 pDwmIsCompositionEnabled
= (void *)GetProcAddress(dwmapi
, "DwmIsCompositionEnabled");
9643 test_coop_level_create_device_window();
9645 test_coop_level_d3d_state();
9646 test_surface_interface_mismatch();
9647 test_coop_level_threaded();
9656 test_window_style();
9657 test_redundant_mode_set();
9658 test_coop_level_mode_set();
9659 test_coop_level_mode_set_multi();
9661 test_coop_level_surf_create();
9662 test_coop_level_multi_window();
9663 test_clear_rect_count();
9664 test_coop_level_activateapp();
9665 test_unsupported_formats();
9667 test_primary_caps();
9668 test_surface_lock();
9669 test_surface_discard();
9671 test_sysmem_overlay();
9672 test_primary_palette();
9673 test_surface_attachment();
9674 test_pixel_format();
9675 test_create_surface_pitch();
9677 test_palette_complex();
9682 test_palette_alpha();
9684 test_surface_desc_lock();
9685 test_texturemapblend();
9686 test_viewport_clear_rect();
9688 test_colorkey_precision();
9689 test_range_colorkey();
9691 test_lockrect_invalid();
9692 test_yv12_overlay();
9693 test_offscreen_overlay();
9694 test_overlay_rect();
9697 test_transform_vertices();