Commit 85c203ed authored by Henri Verbeet's avatar Henri Verbeet Committed by Alexandre Julliard

d3d8: Improve d3d8_device_TestCooperativeLevel().

parent ae25b1ec
...@@ -144,6 +144,13 @@ struct FvfToDecl ...@@ -144,6 +144,13 @@ struct FvfToDecl
struct d3d8_vertex_declaration *declaration; 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 struct d3d8_device
{ {
/* IUnknown fields */ /* IUnknown fields */
...@@ -166,14 +173,19 @@ struct d3d8_device ...@@ -166,14 +173,19 @@ struct d3d8_device
UINT index_buffer_size; UINT index_buffer_size;
UINT index_buffer_pos; UINT index_buffer_pos;
LONG device_state;
/* Avoids recursion with nested ReleaseRef to 0 */ /* Avoids recursion with nested ReleaseRef to 0 */
BOOL inDestruction; BOOL inDestruction;
BOOL lost;
}; };
HRESULT device_init(struct d3d8_device *device, struct d3d8 *parent, struct wined3d *wined3d, UINT adapter, 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; 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 struct d3d8_resource
{ {
LONG refcount; LONG refcount;
......
...@@ -301,11 +301,6 @@ static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d ...@@ -301,11 +301,6 @@ static void *d3d8_get_object(struct d3d8_handle_table *t, DWORD handle, enum d3d
return entry->object; 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) static HRESULT WINAPI d3d8_device_QueryInterface(IDirect3DDevice8 *iface, REFIID riid, void **out)
{ {
TRACE("iface %p, riid %s, out %p.\n", TRACE("iface %p, riid %s, out %p.\n",
...@@ -388,13 +383,18 @@ static HRESULT WINAPI d3d8_device_TestCooperativeLevel(IDirect3DDevice8 *iface) ...@@ -388,13 +383,18 @@ static HRESULT WINAPI d3d8_device_TestCooperativeLevel(IDirect3DDevice8 *iface)
TRACE("iface %p.\n", iface); TRACE("iface %p.\n", iface);
if (device->lost) TRACE("device state: %#x.\n", device->device_state);
switch (device->device_state)
{ {
TRACE("Device is lost.\n"); default:
return D3DERR_DEVICENOTRESET; 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;
} }
return D3D_OK;
} }
static UINT WINAPI d3d8_device_GetAvailableTextureMem(IDirect3DDevice8 *iface) static UINT WINAPI d3d8_device_GetAvailableTextureMem(IDirect3DDevice8 *iface)
...@@ -641,11 +641,11 @@ static HRESULT WINAPI d3d8_device_Reset(IDirect3DDevice8 *iface, ...@@ -641,11 +641,11 @@ static HRESULT WINAPI d3d8_device_Reset(IDirect3DDevice8 *iface,
NULL, reset_enum_callback, TRUE))) NULL, reset_enum_callback, TRUE)))
{ {
wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0); wined3d_device_set_render_state(device->wined3d_device, WINED3D_RS_POINTSIZE_MIN, 0);
device->lost = FALSE; device->device_state = D3D8_DEVICE_STATE_OK;
} }
else else
{ {
device->lost = TRUE; device->device_state = D3D8_DEVICE_STATE_NOT_RESET;
} }
wined3d_mutex_unlock(); wined3d_mutex_unlock();
...@@ -2923,7 +2923,14 @@ static void CDECL device_parent_mode_changed(struct wined3d_device_parent *devic ...@@ -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) 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); 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, static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
......
...@@ -6281,7 +6281,7 @@ static void test_lost_device(void) ...@@ -6281,7 +6281,7 @@ static void test_lost_device(void)
ret = SetForegroundWindow(GetDesktopWindow()); ret = SetForegroundWindow(GetDesktopWindow());
ok(ret, "Failed to set foreground window.\n"); ok(ret, "Failed to set foreground window.\n");
hr = IDirect3DDevice8_TestCooperativeLevel(device); 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); hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr); todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
...@@ -6290,7 +6290,7 @@ static void test_lost_device(void) ...@@ -6290,7 +6290,7 @@ static void test_lost_device(void)
ret = SetForegroundWindow(window); ret = SetForegroundWindow(window);
ok(ret, "Failed to set foreground window.\n"); ok(ret, "Failed to set foreground window.\n");
hr = IDirect3DDevice8_TestCooperativeLevel(device); 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); hr = IDirect3DDevice8_Present(device, NULL, NULL, NULL, NULL);
todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr); todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment