d3d8: Improve d3d8_device_TestCooperativeLevel().

This commit is contained in:
Henri Verbeet 2014-06-30 11:17:01 +02:00 committed by Alexandre Julliard
parent ae25b1eca5
commit 85c203edad
3 changed files with 35 additions and 16 deletions

View File

@ -144,6 +144,13 @@ struct FvfToDecl
struct d3d8_vertex_declaration *declaration;
};
enum d3d8_device_state
{
D3D8_DEVICE_STATE_OK,
D3D8_DEVICE_STATE_LOST,
D3D8_DEVICE_STATE_NOT_RESET,
};
struct d3d8_device
{
/* IUnknown fields */
@ -166,14 +173,19 @@ struct d3d8_device
UINT index_buffer_size;
UINT index_buffer_pos;
LONG device_state;
/* Avoids recursion with nested ReleaseRef to 0 */
BOOL inDestruction;
BOOL lost;
};
HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wined3d *wined3d, UINT adapter,
D3DDEVTYPE device_type, HWND focus_window, DWORD flags, D3DPRESENT_PARAMETERS *parameters) DECLSPEC_HIDDEN;
static inline struct d3d8_device *impl_from_IDirect3DDevice8(IDirect3DDevice8 *iface)
{
return CONTAINING_RECORD(iface, struct d3d8_device, IDirect3DDevice8_iface);
}
struct d3d8_resource
{
LONG refcount;

View File

@ -301,11 +301,6 @@ static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d
return entry->object;
}
static inline struct d3d8_device *impl_from_IDirect3DDevice8(IDirect3DDevice8 *iface)
{
return CONTAINING_RECORD(iface, struct d3d8_device, IDirect3DDevice8_iface);
}
static HRESULT WINAPI d3d8_device_QueryInterface(IDirect3DDevice8 *iface, REFIID riid, void **out)
{
TRACE("iface %p, riid %s, out %p.\n",
@ -388,13 +383,18 @@ static HRESULT WINAPI d3d8_device_TestCooperativeLevel(IDirect3DDevice8 *iface)
TRACE("iface %p.\n", iface);
if (device->lost)
{
TRACE("Device is lost.\n");
return D3DERR_DEVICENOTRESET;
}
TRACE("device state: %#x.\n", device->device_state);
return D3D_OK;
switch (device->device_state)
{
default:
case D3D8_DEVICE_STATE_OK:
return D3D_OK;
case D3D8_DEVICE_STATE_LOST:
return D3DERR_DEVICELOST;
case D3D8_DEVICE_STATE_NOT_RESET:
return D3DERR_DEVICENOTRESET;
}
}
static UINT WINAPI d3d8_device_GetAvailableTextureMem(IDirect3DDevice8 *iface)
@ -641,11 +641,11 @@ static HRESULT WINAPI d3d8_device_Reset(IDirect3DDevice8 *iface,
NULL, reset_enum_callback, TRUE)))
{
wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0);
device->lost = FALSE;
device->device_state = D3D8_DEVICE_STATE_OK;
}
else
{
device->lost = TRUE;
device->device_state = D3D8_DEVICE_STATE_NOT_RESET;
}
wined3d_mutex_unlock();
@ -2923,7 +2923,14 @@ static void CDECL device_parent_mode_changed(struct wined3d_device_parent *devic
static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
{
struct d3d8_device *device = device_from_device_parent(device_parent);
TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
if (!activate)
InterlockedCompareExchange(&device->device_state, D3D8_DEVICE_STATE_LOST, D3D8_DEVICE_STATE_OK);
else
InterlockedCompareExchange(&device->device_state, D3D8_DEVICE_STATE_NOT_RESET, D3D8_DEVICE_STATE_LOST);
}
static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,

View File

@ -6281,7 +6281,7 @@ static void test_lost_device(void)
ret = SetForegroundWindow(GetDesktopWindow());
ok(ret, "Failed to set foreground window.\n");
hr = IDirect3DDevice8_TestCooperativeLevel(device);
todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
@ -6290,7 +6290,7 @@ static void test_lost_device(void)
ret = SetForegroundWindow(window);
ok(ret, "Failed to set foreground window.\n");
hr = IDirect3DDevice8_TestCooperativeLevel(device);
todo_wine ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
ok(hr == D3DERR_DEVICENOTRESET, "Got unexpected hr %#x.\n", hr);
hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);