Signed-off-by: Paul Gofman <gofmanp(a)gmail.com>
---
dlls/ddraw/surface.c | 47 +++++++++++++++++++--------------
dlls/ddraw/tests/ddraw7.c | 55 +++++++++++++++++++++++++++++----------
2 files changed, 69 insertions(+), 33 deletions(-)
diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index cf3b31f885..411267c3da 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -757,38 +757,47 @@ static ULONG WINAPI d3d_texture1_Release(IDirect3DTexture *iface)
*
*****************************************************************************/
static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *iface,
- DDSCAPS2 *Caps, IDirectDrawSurface7 **Surface)
+ DDSCAPS2 *caps, IDirectDrawSurface7 **surface)
{
- struct ddraw_surface *This = impl_from_IDirectDrawSurface7(iface);
+ struct ddraw_surface *head_surface = impl_from_IDirectDrawSurface7(iface);
struct ddraw_surface *surf;
DDSCAPS2 our_caps;
int i;
- TRACE("iface %p, caps %p, attachment %p.\n", iface, Caps, Surface);
+ TRACE("iface %p, caps %p, attachment %p.\n", iface, caps, surface);
+
+ if (IDirectDrawSurface7_IsLost(&head_surface->IDirectDrawSurface7_iface) != DD_OK)
+ {
+ WARN("Surface %p is lost.\n", head_surface);
+
+ *surface = NULL;
+ return DDERR_SURFACELOST;
+ }
wined3d_mutex_lock();
- if(This->version < 7)
+ if(head_surface->version < 7)
{
/* Earlier dx apps put garbage into these members, clear them */
- our_caps.dwCaps = Caps->dwCaps;
+ our_caps.dwCaps = caps->dwCaps;
our_caps.dwCaps2 = 0;
our_caps.dwCaps3 = 0;
our_caps.u1.dwCaps4 = 0;
}
else
{
- our_caps = *Caps;
+ our_caps = *caps;
}
- TRACE("(%p): Looking for caps: %x,%x,%x,%x\n", This, our_caps.dwCaps, our_caps.dwCaps2, our_caps.dwCaps3, our_caps.u1.dwCaps4); /* FIXME: Better debugging */
+ TRACE("head_surface %p, looking for caps %#x, %#x, %#x, %#x.\n", head_surface, our_caps.dwCaps,
+ our_caps.dwCaps2, our_caps.dwCaps3, our_caps.u1.dwCaps4); /* FIXME: Better debugging */
for(i = 0; i < MAX_COMPLEX_ATTACHED; i++)
{
- surf = This->complex_array[i];
+ surf = head_surface->complex_array[i];
if(!surf) break;
- TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf,
+ TRACE("Surface %p, caps %#x, %#x, %#x, %#x.\n", surf,
surf->surface_desc.ddsCaps.dwCaps,
surf->surface_desc.ddsCaps.dwCaps2,
surf->surface_desc.ddsCaps.dwCaps3,
@@ -803,9 +812,9 @@ static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *ifa
* Not sure how to test this.
*/
- TRACE("(%p): Returning surface %p\n", This, surf);
- *Surface = &surf->IDirectDrawSurface7_iface;
- ddraw_surface7_AddRef(*Surface);
+ TRACE("head_surface %p, returning surface %p.\n", head_surface, surf);
+ *surface = &surf->IDirectDrawSurface7_iface;
+ ddraw_surface7_AddRef(*surface);
wined3d_mutex_unlock();
return DD_OK;
@@ -813,11 +822,11 @@ static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *ifa
}
/* Next, look at the attachment chain */
- surf = This;
+ surf = head_surface;
while( (surf = surf->next_attached) )
{
- TRACE("Surface: (%p) caps: %#x, %#x, %#x, %#x.\n", surf,
+ TRACE("Surface %p, caps %#x, %#x, %#x, %#x.\n", surf,
surf->surface_desc.ddsCaps.dwCaps,
surf->surface_desc.ddsCaps.dwCaps2,
surf->surface_desc.ddsCaps.dwCaps3,
@@ -826,19 +835,19 @@ static HRESULT WINAPI ddraw_surface7_GetAttachedSurface(IDirectDrawSurface7 *ifa
if (((surf->surface_desc.ddsCaps.dwCaps & our_caps.dwCaps) == our_caps.dwCaps) &&
((surf->surface_desc.ddsCaps.dwCaps2 & our_caps.dwCaps2) == our_caps.dwCaps2)) {
- TRACE("(%p): Returning surface %p\n", This, surf);
- *Surface = &surf->IDirectDrawSurface7_iface;
- ddraw_surface7_AddRef(*Surface);
+ TRACE("head_surface %p, returning surface %p.\n", head_surface, surf);
+ *surface = &surf->IDirectDrawSurface7_iface;
+ ddraw_surface7_AddRef(*surface);
wined3d_mutex_unlock();
return DD_OK;
}
}
- TRACE("(%p) Didn't find a valid surface\n", This);
+ TRACE("head_surface %p, didn't find a valid surface.\n", head_surface);
wined3d_mutex_unlock();
- *Surface = NULL;
+ *surface = NULL;
return DDERR_NOTFOUND;
}
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 49aab667e5..171e6a5363 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -997,6 +997,7 @@ static void test_coop_level_d3d_state(void)
IDirectDraw7 *ddraw;
IDirect3D7 *d3d;
D3DCOLOR color;
+ DDSCAPS2 caps;
DWORD value;
HWND window;
HRESULT hr;
@@ -1010,44 +1011,63 @@ static void test_coop_level_d3d_state(void)
}
hr = IDirect3DDevice7_GetRenderTarget(device, &rt);
- ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
- ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
ok(!!value, "Got unexpected z-enable state %#x.\n", value);
hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
- ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
ok(!value, "Got unexpected alpha blend enable state %#x.\n", value);
hr = IDirect3DDevice7_SetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, TRUE);
- ok(SUCCEEDED(hr), "Failed to set render state, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xffff0000, 0.0f, 0);
- ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
color = get_surface_color(rt, 320, 240);
ok(compare_color(color, 0x00ff0000, 1), "Got unexpected color 0x%08x.\n", color);
hr = IDirect3DDevice7_GetDirect3D(device, &d3d);
- ok(SUCCEEDED(hr), "Failed to get d3d interface, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirect3D7_QueryInterface(d3d, &IID_IDirectDraw7, (void **)&ddraw);
- ok(SUCCEEDED(hr), "Failed to get ddraw interface, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
IDirect3D7_Release(d3d);
hr = IDirectDraw7_SetCooperativeLevel(ddraw, window, DDSCL_EXCLUSIVE | DDSCL_FULLSCREEN);
- ok(SUCCEEDED(hr), "Failed to set cooperative level, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
hr = IDirectDrawSurface7_IsLost(rt);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
+
+ memset(&caps, 0, sizeof(caps));
+ caps.dwCaps = DDSCAPS_ZBUFFER;
+ hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &surface);
+ ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
+ caps.dwCaps = DDSCAPS_FLIP;
+ hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &surface);
+ ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
+
hr = IDirectDraw7_RestoreAllSurfaces(ddraw);
- ok(SUCCEEDED(hr), "Failed to restore surfaces, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+
+ caps.dwCaps = DDSCAPS_ZBUFFER;
+ hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &surface);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
+ IDirectDrawSurface7_Release(surface);
+
+ caps.dwCaps = DDSCAPS_FLIP;
+ hr = IDirectDrawSurface7_GetAttachedSurface(rt, &caps, &surface);
+ ok(hr == DDERR_NOTFOUND, "Got unexpected hr %#x.\n", hr);
+
IDirectDraw7_Release(ddraw);
hr = IDirect3DDevice7_GetRenderTarget(device, &surface);
- ok(SUCCEEDED(hr), "Failed to get render target, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
ok(surface == rt, "Got unexpected surface %p.\n", surface);
hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ZENABLE, &value);
- ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
ok(!!value, "Got unexpected z-enable state %#x.\n", value);
hr = IDirect3DDevice7_GetRenderState(device, D3DRENDERSTATE_ALPHABLENDENABLE, &value);
- ok(SUCCEEDED(hr), "Failed to get render state, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
ok(!!value, "Got unexpected alpha blend enable state %#x.\n", value);
hr = IDirect3DDevice7_Clear(device, 0, NULL, D3DCLEAR_TARGET, 0xff00ff00, 0.0f, 0);
- ok(SUCCEEDED(hr), "Failed to clear render target, hr %#x.\n", hr);
+ ok(hr == DD_OK, "Got unexpected hr %#x.\n", hr);
color = get_surface_color(rt, 320, 240);
ok(compare_color(color, 0x0000ff00, 1), "Got unexpected color 0x%08x.\n", color);
@@ -9012,11 +9032,12 @@ static void test_vb_writeonly(void)
static void test_lost_device(void)
{
- IDirectDrawSurface7 *surface;
+ IDirectDrawSurface7 *surface, *back_buffer;
DDSURFACEDESC2 surface_desc;
HWND window1, window2;
IDirectDraw7 *ddraw;
ULONG refcount;
+ DDSCAPS2 caps;
HRESULT hr;
BOOL ret;
@@ -9186,6 +9207,12 @@ static void test_lost_device(void)
hr = IDirectDrawSurface7_Flip(surface, NULL, DDFLIP_WAIT);
ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
+ memset(&caps, 0, sizeof(caps));
+ caps.dwCaps = DDSCAPS_FLIP;
+
+ hr = IDirectDrawSurface7_GetAttachedSurface(surface, &caps, &back_buffer);
+ ok(hr == DDERR_SURFACELOST, "Got unexpected hr %#x.\n", hr);
+
IDirectDrawSurface7_Release(surface);
refcount = IDirectDraw7_Release(ddraw);
ok(!refcount, "Got unexpected refcount %u.\n", refcount);
--
2.21.0