Module: wine
Branch: master
Commit: 85c203edad900039726c0d2e959b3b14dff8249b
URL:
http://source.winehq.org/git/wine.git/?a=commit;h=85c203edad900039726c0d2e9…
Author: Henri Verbeet <hverbeet(a)codeweavers.com>
Date: Mon Jun 30 11:17:01 2014 +0200
d3d8: Improve d3d8_device_TestCooperativeLevel().
---
dlls/d3d8/d3d8_private.h | 14 +++++++++++++-
dlls/d3d8/device.c | 31 +++++++++++++++++++------------
dlls/d3d8/tests/device.c | 4 ++--
3 files changed, 34 insertions(+), 15 deletions(-)
diff --git a/dlls/d3d8/d3d8_private.h b/dlls/d3d8/d3d8_private.h
index 54bbe1c..0961503 100644
--- a/dlls/d3d8/d3d8_private.h
+++ b/dlls/d3d8/d3d8_private.h
@@ -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;
diff --git a/dlls/d3d8/device.c b/dlls/d3d8/device.c
index 53a832e..b3aefe1 100644
--- a/dlls/d3d8/device.c
+++ b/dlls/d3d8/device.c
@@ -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 state: %#x.\n", device->device_state);
+
+ switch (device->device_state)
{
- TRACE("Device is lost.\n");
- return D3DERR_DEVICENOTRESET;
+ 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;
}
-
- return D3D_OK;
}
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,
diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c
index 376097e..9100ebf 100644
--- a/dlls/d3d8/tests/device.c
+++ b/dlls/d3d8/tests/device.c
@@ -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);