Signed-off-by: Zhiyi Zhang zzhang@codeweavers.com --- dlls/dxgi/dxgi_private.h | 1 + dlls/dxgi/swapchain.c | 20 ++++--- dlls/dxgi/utils.c | 2 +- dlls/wined3d/swapchain.c | 4 -- dlls/wined3d/wined3d.spec | 2 + dlls/wined3d/wined3d_main.c | 99 +++++++++++++++++----------------- dlls/wined3d/wined3d_private.h | 2 - include/wine/wined3d.h | 8 +-- 8 files changed, 69 insertions(+), 69 deletions(-)
diff --git a/dlls/dxgi/dxgi_private.h b/dlls/dxgi/dxgi_private.h index e43ee59461c..906fe914cba 100644 --- a/dlls/dxgi/dxgi_private.h +++ b/dlls/dxgi/dxgi_private.h @@ -177,6 +177,7 @@ struct d3d11_swapchain LONG refcount; struct wined3d_private_store private_store; struct wined3d_swapchain *wined3d_swapchain; + struct wined3d_swapchain_state *state; IWineDXGIDevice *device; IDXGIFactory *factory;
diff --git a/dlls/dxgi/swapchain.c b/dlls/dxgi/swapchain.c index f3b74389d29..9d6ec0246ce 100644 --- a/dlls/dxgi/swapchain.c +++ b/dlls/dxgi/swapchain.c @@ -249,6 +249,7 @@ static ULONG STDMETHODCALLTYPE d3d11_swapchain_Release(IDXGISwapChain1 *iface) } if (swapchain->factory) IDXGIFactory_Release(swapchain->factory); + wined3d_swapchain_state_unregister(swapchain->state); wined3d_swapchain_decref(swapchain->wined3d_swapchain); if (device) IWineDXGIDevice_Release(device); @@ -388,7 +389,6 @@ static HRESULT STDMETHODCALLTYPE DECLSPEC_HOTPATCH d3d11_swapchain_SetFullscreen { struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface); struct wined3d_swapchain_desc swapchain_desc; - struct wined3d_swapchain_state *state; struct dxgi_output *dxgi_output; HRESULT hr;
@@ -412,11 +412,10 @@ static HRESULT STDMETHODCALLTYPE DECLSPEC_HOTPATCH d3d11_swapchain_SetFullscreen dxgi_output = unsafe_impl_from_IDXGIOutput(target);
wined3d_mutex_lock(); - state = wined3d_swapchain_get_state(swapchain->wined3d_swapchain); wined3d_swapchain_get_desc(swapchain->wined3d_swapchain, &swapchain_desc); swapchain_desc.output = dxgi_output->wined3d_output; swapchain_desc.windowed = !fullscreen; - hr = wined3d_swapchain_state_set_fullscreen(state, &swapchain_desc, NULL); + hr = wined3d_swapchain_state_set_fullscreen(swapchain->state, &swapchain_desc, NULL); wined3d_mutex_unlock(); if (FAILED(hr)) { @@ -556,13 +555,10 @@ static HRESULT STDMETHODCALLTYPE d3d11_swapchain_ResizeTarget(IDXGISwapChain1 *i const DXGI_MODE_DESC *target_mode_desc) { struct d3d11_swapchain *swapchain = d3d11_swapchain_from_IDXGISwapChain1(iface); - struct wined3d_swapchain_state *state;
TRACE("iface %p, target_mode_desc %p.\n", iface, target_mode_desc);
- state = wined3d_swapchain_get_state(swapchain->wined3d_swapchain); - - return dxgi_swapchain_resize_target(state, target_mode_desc); + return dxgi_swapchain_resize_target(swapchain->state, target_mode_desc); }
static HRESULT STDMETHODCALLTYPE d3d11_swapchain_GetContainingOutput(IDXGISwapChain1 *iface, IDXGIOutput **output) @@ -814,6 +810,7 @@ static const struct wined3d_parent_ops d3d11_swapchain_wined3d_parent_ops = HRESULT d3d11_swapchain_init(struct d3d11_swapchain *swapchain, struct dxgi_device *device, struct wined3d_swapchain_desc *desc) { + struct wined3d *wined3d; BOOL fullscreen; HRESULT hr;
@@ -856,13 +853,14 @@ HRESULT d3d11_swapchain_init(struct d3d11_swapchain *swapchain, struct dxgi_devi goto cleanup; }
+ swapchain->state = wined3d_swapchain_get_state(swapchain->wined3d_swapchain); + wined3d = wined3d_device_get_wined3d(device->wined3d_device); + wined3d_swapchain_state_register(swapchain->state, wined3d); + swapchain->target = NULL; if (fullscreen) { - struct wined3d_swapchain_state *state; - desc->windowed = FALSE; - state = wined3d_swapchain_get_state(swapchain->wined3d_swapchain);
if (FAILED(hr = IDXGISwapChain1_GetContainingOutput(&swapchain->IDXGISwapChain1_iface, &swapchain->target))) @@ -872,7 +870,7 @@ HRESULT d3d11_swapchain_init(struct d3d11_swapchain *swapchain, struct dxgi_devi goto cleanup; }
- if (FAILED(hr = wined3d_swapchain_state_set_fullscreen(state, desc, NULL))) + if (FAILED(hr = wined3d_swapchain_state_set_fullscreen(swapchain->state, desc, NULL))) { WARN("Failed to set fullscreen state, hr %#x.\n", hr); IDXGIOutput_Release(swapchain->target); diff --git a/dlls/dxgi/utils.c b/dlls/dxgi/utils.c index 665413e4c62..0c83b912c6f 100644 --- a/dlls/dxgi/utils.c +++ b/dlls/dxgi/utils.c @@ -520,7 +520,7 @@ unsigned int wined3d_bind_flags_from_dxgi_usage(DXGI_USAGE dxgi_usage)
#define DXGI_WINED3D_SWAPCHAIN_FLAGS \ (WINED3D_SWAPCHAIN_USE_CLOSEST_MATCHING_MODE | WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT \ - | WINED3D_SWAPCHAIN_HOOK | WINED3D_SWAPCHAIN_RESTORE_WINDOW_STATE) + | WINED3D_SWAPCHAIN_RESTORE_WINDOW_STATE)
unsigned int dxgi_swapchain_flags_from_wined3d(unsigned int wined3d_flags) { diff --git a/dlls/wined3d/swapchain.c b/dlls/wined3d/swapchain.c index d0d93417a18..2cf36d189cb 100644 --- a/dlls/wined3d/swapchain.c +++ b/dlls/wined3d/swapchain.c @@ -34,7 +34,6 @@ void wined3d_swapchain_cleanup(struct wined3d_swapchain *swapchain)
TRACE("Destroying swapchain %p.\n", swapchain);
- wined3d_unhook_swapchain(swapchain); wined3d_swapchain_set_gamma_ramp(swapchain, 0, &swapchain->orig_gamma);
/* Release the swapchain's draw buffers. Make sure swapchain->back_buffers[0] @@ -1627,9 +1626,6 @@ HRESULT CDECL wined3d_swapchain_create(struct wined3d_device *device, struct win desc, parent, parent_ops, &object))) return hr;
- if (desc->flags & WINED3D_SWAPCHAIN_HOOK) - wined3d_hook_swapchain(object); - if (desc->flags & WINED3D_SWAPCHAIN_IMPLICIT) { wined3d_mutex_lock(); diff --git a/dlls/wined3d/wined3d.spec b/dlls/wined3d/wined3d.spec index d11e06d0c34..816108e8b3b 100644 --- a/dlls/wined3d/wined3d.spec +++ b/dlls/wined3d/wined3d.spec @@ -292,8 +292,10 @@ @ cdecl wined3d_swapchain_state_create(ptr ptr ptr) @ cdecl wined3d_swapchain_state_destroy(ptr) @ cdecl wined3d_swapchain_state_is_windowed(ptr) +@ cdecl wined3d_swapchain_state_register(ptr ptr) @ cdecl wined3d_swapchain_state_resize_target(ptr ptr) @ cdecl wined3d_swapchain_state_set_fullscreen(ptr ptr ptr) +@ cdecl wined3d_swapchain_state_unregister(ptr)
@ cdecl wined3d_texture_add_dirty_region(ptr long ptr) @ cdecl wined3d_texture_blt(ptr long ptr ptr long ptr long ptr long) diff --git a/dlls/wined3d/wined3d_main.c b/dlls/wined3d/wined3d_main.c index c98aee18bdd..bb3ad7ffa51 100644 --- a/dlls/wined3d/wined3d_main.c +++ b/dlls/wined3d/wined3d_main.c @@ -56,25 +56,26 @@ struct wined3d_window_hook unsigned int count; };
-struct wined3d_hooked_swapchain +struct wined3d_registered_swapchain_state { - struct wined3d_swapchain *swapchain; + struct wined3d_swapchain_state *state; + struct wined3d *wined3d; DWORD thread_id; };
-struct wined3d_hook_table +struct wined3d_swapchain_state_table { struct wined3d_window_hook *hooks; SIZE_T hooks_size; SIZE_T hook_count;
- struct wined3d_hooked_swapchain *swapchains; - SIZE_T swapchains_size; - SIZE_T swapchain_count; + struct wined3d_registered_swapchain_state *states; + SIZE_T states_size; + SIZE_T state_count; };
static struct wined3d_wndproc_table wndproc_table; -static struct wined3d_hook_table hook_table; +static struct wined3d_swapchain_state_table swapchain_state_table;
static CRITICAL_SECTION wined3d_cs; static CRITICAL_SECTION_DEBUG wined3d_cs_debug = @@ -425,13 +426,13 @@ static BOOL wined3d_dll_destroy(HINSTANCE hInstDLL) } heap_free(wndproc_table.entries);
- heap_free(hook_table.swapchains); - for (i = 0; i < hook_table.hook_count; ++i) + heap_free(swapchain_state_table.states); + for (i = 0; i < swapchain_state_table.hook_count; ++i) { - WARN("Leftover hook table entry %p.\n", &hook_table.hooks[i]); - UnhookWindowsHookEx(hook_table.hooks[i].hook); + WARN("Leftover swapchain state hook %p.\n", &swapchain_state_table.hooks[i]); + UnhookWindowsHookEx(swapchain_state_table.hooks[i].hook); } - heap_free(hook_table.hooks); + heap_free(swapchain_state_table.hooks);
heap_free(wined3d_settings.logo); UnregisterClassA(WINED3D_OPENGL_WINDOW_CLASS_NAME, hInstDLL); @@ -573,8 +574,8 @@ static LRESULT CALLBACK wined3d_wndproc(HWND window, UINT message, WPARAM wparam
static LRESULT CALLBACK wined3d_hook_proc(int code, WPARAM wparam, LPARAM lparam) { + struct wined3d_registered_swapchain_state *registered_state; struct wined3d_swapchain_desc swapchain_desc; - struct wined3d_swapchain *swapchain; struct wined3d_wndproc *entry; struct wined3d_output *output; MSG *msg = (MSG *)lparam; @@ -586,28 +587,28 @@ static LRESULT CALLBACK wined3d_hook_proc(int code, WPARAM wparam, LPARAM lparam { wined3d_wndproc_mutex_lock();
- for (i = 0; i < hook_table.swapchain_count; ++i) + for (i = 0; i < swapchain_state_table.state_count; ++i) { - swapchain = hook_table.swapchains[i].swapchain; + registered_state = &swapchain_state_table.states[i];
- if (swapchain->state.device_window != msg->hwnd) + if (registered_state->state->device_window != msg->hwnd) continue;
- if ((entry = wined3d_find_wndproc(msg->hwnd, swapchain->device->wined3d)) + if ((entry = wined3d_find_wndproc(msg->hwnd, registered_state->wined3d)) && (entry->flags & (WINED3D_REGISTER_WINDOW_NO_WINDOW_CHANGES | WINED3D_REGISTER_WINDOW_NO_ALT_ENTER))) continue;
- wined3d_swapchain_get_desc(swapchain, &swapchain_desc); + swapchain_desc = registered_state->state->desc; swapchain_desc.windowed = !swapchain_desc.windowed; - if (!(output = wined3d_get_output_from_window(swapchain->device->wined3d, - swapchain->state.device_window))) + if (!(output = wined3d_get_output_from_window(registered_state->wined3d, + registered_state->state->device_window))) { - ERR("Failed to get output from window %p.\n", swapchain->state.device_window); + ERR("Failed to get output from window %p.\n", registered_state->state->device_window); break; } swapchain_desc.output = output; - wined3d_swapchain_state_set_fullscreen(&swapchain->state, &swapchain_desc, NULL); + wined3d_swapchain_state_set_fullscreen(registered_state->state, &swapchain_desc, NULL);
wined3d_wndproc_mutex_unlock();
@@ -764,82 +765,84 @@ static struct wined3d_window_hook *wined3d_find_hook(DWORD thread_id) { unsigned int i;
- for (i = 0; i < hook_table.hook_count; ++i) + for (i = 0; i < swapchain_state_table.hook_count; ++i) { - if (hook_table.hooks[i].thread_id == thread_id) - return &hook_table.hooks[i]; + if (swapchain_state_table.hooks[i].thread_id == thread_id) + return &swapchain_state_table.hooks[i]; }
return NULL; }
-void wined3d_hook_swapchain(struct wined3d_swapchain *swapchain) +void CDECL wined3d_swapchain_state_register(struct wined3d_swapchain_state *state, + struct wined3d *wined3d) { - struct wined3d_hooked_swapchain *swapchain_entry; + struct wined3d_registered_swapchain_state *state_entry; struct wined3d_window_hook *hook;
wined3d_wndproc_mutex_lock();
- if (!wined3d_array_reserve((void **)&hook_table.swapchains, &hook_table.swapchains_size, - hook_table.swapchain_count + 1, sizeof(*swapchain_entry))) + if (!wined3d_array_reserve((void **)&swapchain_state_table.states, &swapchain_state_table.states_size, + swapchain_state_table.state_count + 1, sizeof(*state_entry))) { wined3d_wndproc_mutex_unlock(); return; }
- swapchain_entry = &hook_table.swapchains[hook_table.swapchain_count++]; - swapchain_entry->swapchain = swapchain; - swapchain_entry->thread_id = GetWindowThreadProcessId(swapchain->state.device_window, NULL); + state_entry = &swapchain_state_table.states[swapchain_state_table.state_count++]; + state_entry->state = state; + state_entry->wined3d = wined3d; + state_entry->thread_id = GetWindowThreadProcessId(state->device_window, NULL);
- if ((hook = wined3d_find_hook(swapchain_entry->thread_id))) + if ((hook = wined3d_find_hook(state_entry->thread_id))) { ++hook->count; wined3d_wndproc_mutex_unlock(); return; }
- if (!wined3d_array_reserve((void **)&hook_table.hooks, &hook_table.hooks_size, - hook_table.hook_count + 1, sizeof(*hook))) + if (!wined3d_array_reserve((void **)&swapchain_state_table.hooks, &swapchain_state_table.hooks_size, + swapchain_state_table.hook_count + 1, sizeof(*hook))) { - --hook_table.swapchain_count; + --swapchain_state_table.state_count; wined3d_wndproc_mutex_unlock(); return; }
- hook = &hook_table.hooks[hook_table.hook_count++]; - hook->thread_id = swapchain_entry->thread_id; + hook = &swapchain_state_table.hooks[swapchain_state_table.hook_count++]; + hook->thread_id = state_entry->thread_id; hook->hook = SetWindowsHookExW(WH_GETMESSAGE, wined3d_hook_proc, 0, hook->thread_id); hook->count = 1;
wined3d_wndproc_mutex_unlock(); }
-void wined3d_unhook_swapchain(struct wined3d_swapchain *swapchain) +void CDECL wined3d_swapchain_state_unregister(struct wined3d_swapchain_state *state) { - struct wined3d_hooked_swapchain *swapchain_entry, *last_swapchain_entry; + struct wined3d_registered_swapchain_state *state_entry, *last_state_entry; struct wined3d_window_hook *hook, *last_hook; unsigned int i;
wined3d_wndproc_mutex_lock();
- for (i = 0; i < hook_table.swapchain_count; ++i) + for (i = 0; i < swapchain_state_table.state_count; ++i) { - swapchain_entry = &hook_table.swapchains[i]; + state_entry = &swapchain_state_table.states[i];
- if (swapchain_entry->swapchain != swapchain) + if (state_entry->state != state) continue;
- if ((hook = wined3d_find_hook(swapchain_entry->thread_id)) && !--hook->count) + if ((hook = wined3d_find_hook(state_entry->thread_id)) && !--hook->count) { UnhookWindowsHookEx(hook->hook); - last_hook = &hook_table.hooks[--hook_table.hook_count]; + last_hook = &swapchain_state_table.hooks[--swapchain_state_table.hook_count]; if (hook != last_hook) *hook = *last_hook; }
- last_swapchain_entry = &hook_table.swapchains[--hook_table.swapchain_count]; - if (swapchain_entry != last_swapchain_entry) - *swapchain_entry = *last_swapchain_entry; + last_state_entry = &swapchain_state_table.states[--swapchain_state_table.state_count]; + if (state_entry != last_state_entry) + *state_entry = *last_state_entry;
break; } diff --git a/dlls/wined3d/wined3d_private.h b/dlls/wined3d/wined3d_private.h index 1c783d28bc2..7c88e04f5e7 100644 --- a/dlls/wined3d/wined3d_private.h +++ b/dlls/wined3d/wined3d_private.h @@ -3514,9 +3514,7 @@ struct wined3d };
BOOL wined3d_filter_messages(HWND window, BOOL filter) DECLSPEC_HIDDEN; -void wined3d_hook_swapchain(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN; HRESULT wined3d_init(struct wined3d *wined3d, DWORD flags) DECLSPEC_HIDDEN; -void wined3d_unhook_swapchain(struct wined3d_swapchain *swapchain) DECLSPEC_HIDDEN; void wined3d_unregister_window(HWND window) DECLSPEC_HIDDEN;
BOOL wined3d_get_app_name(char *app_name, unsigned int app_name_size) DECLSPEC_HIDDEN; diff --git a/include/wine/wined3d.h b/include/wine/wined3d.h index 238961006a0..3f2361e55a5 100644 --- a/include/wine/wined3d.h +++ b/include/wine/wined3d.h @@ -904,9 +904,8 @@ enum wined3d_shader_type #define WINED3D_SWAPCHAIN_RESTORE_WINDOW_RECT 0x00004000u #define WINED3D_SWAPCHAIN_GDI_COMPATIBLE 0x00008000u #define WINED3D_SWAPCHAIN_IMPLICIT 0x00010000u -#define WINED3D_SWAPCHAIN_HOOK 0x00020000u -#define WINED3D_SWAPCHAIN_NO_WINDOW_CHANGES 0x00040000u -#define WINED3D_SWAPCHAIN_RESTORE_WINDOW_STATE 0x00080000u +#define WINED3D_SWAPCHAIN_NO_WINDOW_CHANGES 0x00020000u +#define WINED3D_SWAPCHAIN_RESTORE_WINDOW_STATE 0x00040000u
#define WINED3DDP_MAXTEXCOORD 8
@@ -2807,10 +2806,13 @@ HRESULT __cdecl wined3d_swapchain_state_create(const struct wined3d_swapchain_de HWND window, struct wined3d_swapchain_state **state); void __cdecl wined3d_swapchain_state_destroy(struct wined3d_swapchain_state *state); BOOL __cdecl wined3d_swapchain_state_is_windowed(const struct wined3d_swapchain_state *state); +void __cdecl wined3d_swapchain_state_register(struct wined3d_swapchain_state *state, + struct wined3d *wined3d); HRESULT __cdecl wined3d_swapchain_state_resize_target(struct wined3d_swapchain_state *state, const struct wined3d_display_mode *mode); HRESULT __cdecl wined3d_swapchain_state_set_fullscreen(struct wined3d_swapchain_state *state, const struct wined3d_swapchain_desc *desc, const struct wined3d_display_mode *mode); +void __cdecl wined3d_swapchain_state_unregister(struct wined3d_swapchain_state *state);
HRESULT __cdecl wined3d_texture_add_dirty_region(struct wined3d_texture *texture, UINT layer, const struct wined3d_box *dirty_region);