d3d9: Improve d3d9_device_TestCooperativeLevel().

This commit is contained in:
Henri Verbeet 2014-06-27 08:26:59 +02:00 committed by Alexandre Julliard
parent 1b4c55df29
commit 09fda3b805
8 changed files with 67 additions and 11 deletions

View File

@ -1935,6 +1935,11 @@ static void CDECL device_parent_mode_changed(struct wined3d_device_parent *devic
TRACE("device_parent %p.\n", device_parent);
}
static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
{
TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
}
static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
void *container_parent, struct wined3d_surface *surface, void **parent,
const struct wined3d_parent_ops **parent_ops)
@ -2033,6 +2038,7 @@ static const struct wined3d_device_parent_ops d3d10_wined3d_device_parent_ops =
{
device_parent_wined3d_device_created,
device_parent_mode_changed,
device_parent_activate,
device_parent_surface_created,
device_parent_volume_created,
device_parent_create_swapchain_surface,

View File

@ -2921,6 +2921,11 @@ static void CDECL device_parent_mode_changed(struct wined3d_device_parent *devic
TRACE("device_parent %p.\n", device_parent);
}
static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
{
TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
}
static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
void *container_parent, struct wined3d_surface *surface, void **parent,
const struct wined3d_parent_ops **parent_ops)
@ -3034,6 +3039,7 @@ static const struct wined3d_device_parent_ops d3d8_wined3d_device_parent_ops =
{
device_parent_wined3d_device_created,
device_parent_mode_changed,
device_parent_activate,
device_parent_surface_created,
device_parent_volume_created,
device_parent_create_swapchain_surface,

View File

@ -139,6 +139,13 @@ struct fvf_declaration
DWORD fvf;
};
enum d3d9_device_state
{
D3D9_DEVICE_STATE_OK,
D3D9_DEVICE_STATE_LOST,
D3D9_DEVICE_STATE_NOT_RESET,
};
struct d3d9_device
{
IDirect3DDevice9Ex IDirect3DDevice9Ex_iface;
@ -157,8 +164,8 @@ struct d3d9_device
UINT index_buffer_size;
UINT index_buffer_pos;
LONG device_state;
BOOL in_destruction;
BOOL not_reset;
BOOL in_scene;
};

View File

@ -323,13 +323,21 @@ static HRESULT WINAPI d3d9_device_TestCooperativeLevel(IDirect3DDevice9Ex *iface
TRACE("iface %p.\n", iface);
if (device->not_reset)
TRACE("device state: %#x.\n", device->device_state);
if (device->d3d_parent->extended)
return D3D_OK;
switch (device->device_state)
{
TRACE("D3D9 device is marked not reset.\n");
default:
case D3D9_DEVICE_STATE_OK:
return D3D_OK;
case D3D9_DEVICE_STATE_LOST:
return D3DERR_DEVICELOST;
case D3D9_DEVICE_STATE_NOT_RESET:
return D3DERR_DEVICENOTRESET;
}
return D3D_OK;
}
static UINT WINAPI d3d9_device_GetAvailableTextureMem(IDirect3DDevice9Ex *iface)
@ -621,9 +629,9 @@ static HRESULT WINAPI DECLSPEC_HOTPATCH d3d9_device_Reset(IDirect3DDevice9Ex *if
hr = wined3d_device_reset(device->wined3d_device, &swapchain_desc,
NULL, reset_enum_callback, !device->d3d_parent->extended);
if (FAILED(hr) && !device->d3d_parent->extended)
device->not_reset = TRUE;
device->device_state = D3D9_DEVICE_STATE_NOT_RESET;
else
device->not_reset = FALSE;
device->device_state = D3D9_DEVICE_STATE_OK;
wined3d_mutex_unlock();
return hr;
@ -3414,6 +3422,23 @@ static void CDECL device_parent_mode_changed(struct wined3d_device_parent *devic
TRACE("device_parent %p.\n", device_parent);
}
static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
{
struct d3d9_device *device = device_from_device_parent(device_parent);
TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
if (!device->d3d_parent)
return;
if (!activate)
InterlockedCompareExchange(&device->device_state, D3D9_DEVICE_STATE_LOST, D3D9_DEVICE_STATE_OK);
else if (device->d3d_parent->extended)
InterlockedCompareExchange(&device->device_state, D3D9_DEVICE_STATE_OK, D3D9_DEVICE_STATE_LOST);
else
InterlockedCompareExchange(&device->device_state, D3D9_DEVICE_STATE_NOT_RESET, D3D9_DEVICE_STATE_LOST);
}
static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
void *container_parent, struct wined3d_surface *surface, void **parent,
const struct wined3d_parent_ops **parent_ops)
@ -3531,6 +3556,7 @@ static const struct wined3d_device_parent_ops d3d9_wined3d_device_parent_ops =
{
device_parent_wined3d_device_created,
device_parent_mode_changed,
device_parent_activate,
device_parent_surface_created,
device_parent_volume_created,
device_parent_create_swapchain_surface,

View File

@ -8930,7 +8930,7 @@ static void test_lost_device(void)
ret = SetForegroundWindow(GetDesktopWindow());
ok(ret, "Failed to set foreground window.\n");
hr = IDirect3DDevice9_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 = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);
@ -8939,7 +8939,7 @@ static void test_lost_device(void)
ret = SetForegroundWindow(window);
ok(ret, "Failed to set foreground window.\n");
hr = IDirect3DDevice9_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 = IDirect3DDevice9_Present(device, NULL, NULL, NULL, NULL);
todo_wine ok(hr == D3DERR_DEVICELOST, "Got unexpected hr %#x.\n", hr);

View File

@ -4722,6 +4722,11 @@ static void CDECL device_parent_mode_changed(struct wined3d_device_parent *devic
ERR("Failed to resize window.\n");
}
static void CDECL device_parent_activate(struct wined3d_device_parent *device_parent, BOOL activate)
{
TRACE("device_parent %p, activate %#x.\n", device_parent, activate);
}
static HRESULT CDECL device_parent_surface_created(struct wined3d_device_parent *device_parent,
void *container_parent, struct wined3d_surface *surface,
void **parent, const struct wined3d_parent_ops **parent_ops)
@ -4846,6 +4851,7 @@ static const struct wined3d_device_parent_ops ddraw_wined3d_device_parent_ops =
{
device_parent_wined3d_device_created,
device_parent_mode_changed,
device_parent_activate,
device_parent_surface_created,
device_parent_volume_created,
device_parent_create_swapchain_surface,

View File

@ -4775,6 +4775,10 @@ LRESULT device_process_message(struct wined3d_device *device, HWND window, BOOL
{
device->device_parent->ops->mode_changed(device->device_parent);
}
else if (message == WM_ACTIVATEAPP)
{
device->device_parent->ops->activate(device->device_parent, wparam);
}
if (unicode)
return CallWindowProcW(proc, window, message, wparam, lparam);

View File

@ -1981,6 +1981,7 @@ struct wined3d_device_parent_ops
{
void (__cdecl *wined3d_device_created)(struct wined3d_device_parent *device_parent, struct wined3d_device *device);
void (__cdecl *mode_changed)(struct wined3d_device_parent *device_parent);
void (__cdecl *activate)(struct wined3d_device_parent *device_parent, BOOL activate);
HRESULT (__cdecl *surface_created)(struct wined3d_device_parent *device_parent, void *container_parent,
struct wined3d_surface *surface, void **parent, const struct wined3d_parent_ops **parent_ops);
HRESULT (__cdecl *volume_created)(struct wined3d_device_parent *device_parent, void *container_parent,