Sebastian Lackner : user32: Move key state cache into a separate struct.
Alexandre Julliard
julliard at wine.codeweavers.com
Tue Apr 7 10:11:28 CDT 2015
Module: wine
Branch: master
Commit: 325c061bbd6fcd7ebaa60e62a69e52b000b61cdd
URL: http://source.winehq.org/git/wine.git/?a=commit;h=325c061bbd6fcd7ebaa60e62a69e52b000b61cdd
Author: Sebastian Lackner <sebastian at fds-team.de>
Date: Tue Apr 7 02:33:28 2015 +0200
user32: Move key state cache into a separate struct.
---
dlls/user32/hook.c | 5 ++++-
dlls/user32/input.c | 23 +++++++++++++++--------
dlls/user32/message.c | 7 ++++---
dlls/user32/user_private.h | 9 +++++++--
dlls/user32/winstation.c | 3 ++-
5 files changed, 32 insertions(+), 15 deletions(-)
diff --git a/dlls/user32/hook.c b/dlls/user32/hook.c
index 2f6b42c..f19949c 100644
--- a/dlls/user32/hook.c
+++ b/dlls/user32/hook.c
@@ -437,7 +437,10 @@ static LRESULT call_hook( struct hook_info *info, INT code, WPARAM wparam, LPARA
}
if (info->id == WH_KEYBOARD_LL || info->id == WH_MOUSE_LL)
- get_user_thread_info()->key_state_time = 0; /* force refreshing the key state cache */
+ {
+ struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
+ if (key_state_info) key_state_info->time = 0; /* force refreshing the key state cache */
+ }
return ret;
}
diff --git a/dlls/user32/input.c b/dlls/user32/input.c
index b6eecbe..6ea2c2f 100644
--- a/dlls/user32/input.c
+++ b/dlls/user32/input.c
@@ -368,7 +368,7 @@ static void check_for_events( UINT flags )
*/
SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState( INT key )
{
- struct user_thread_info *thread_info = get_user_thread_info();
+ struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
SHORT ret;
if (key < 0 || key >= 256) return 0;
@@ -377,24 +377,31 @@ SHORT WINAPI DECLSPEC_HOTPATCH GetAsyncKeyState( INT key )
if ((ret = USER_Driver->pGetAsyncKeyState( key )) == -1)
{
- if (thread_info->key_state &&
- !(thread_info->key_state[key] & 0xc0) &&
- GetTickCount() - thread_info->key_state_time < 50)
+ if (key_state_info &&
+ !(key_state_info->state[key] & 0xc0) &&
+ GetTickCount() - key_state_info->time < 50)
+ {
+ /* use cached value */
return 0;
-
- if (!thread_info->key_state) thread_info->key_state = HeapAlloc( GetProcessHeap(), 0, 256 );
+ }
+ else if (!key_state_info)
+ {
+ key_state_info = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(*key_state_info) );
+ get_user_thread_info()->key_state = key_state_info;
+ }
ret = 0;
SERVER_START_REQ( get_key_state )
{
req->tid = 0;
req->key = key;
- if (thread_info->key_state) wine_server_set_reply( req, thread_info->key_state, 256 );
+ if (key_state_info) wine_server_set_reply( req, key_state_info->state,
+ sizeof(key_state_info->state) );
if (!wine_server_call( req ))
{
if (reply->state & 0x40) ret |= 0x0001;
if (reply->state & 0x80) ret |= 0x8000;
- thread_info->key_state_time = GetTickCount();
+ if (key_state_info) key_state_info->time = GetTickCount();
}
}
SERVER_END_REQ;
diff --git a/dlls/user32/message.c b/dlls/user32/message.c
index eac4e4d..fbc11da 100644
--- a/dlls/user32/message.c
+++ b/dlls/user32/message.c
@@ -3290,7 +3290,7 @@ static BOOL send_message( struct send_message_info *info, DWORD_PTR *res_ptr, BO
*/
NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
{
- struct user_thread_info *thread_info = get_user_thread_info();
+ struct user_key_state_info *key_state_info = get_user_thread_info()->key_state;
struct send_message_info info;
int prev_x, prev_y, new_x, new_y;
NTSTATUS ret;
@@ -3329,7 +3329,8 @@ NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
req->input.hw.lparam = MAKELONG( input->u.hi.wParamL, input->u.hi.wParamH );
break;
}
- if (thread_info->key_state) wine_server_set_reply( req, thread_info->key_state, 256 );
+ if (key_state_info) wine_server_set_reply( req, key_state_info->state,
+ sizeof(key_state_info->state) );
ret = wine_server_call( req );
wait = reply->wait;
prev_x = reply->prev_x;
@@ -3341,7 +3342,7 @@ NTSTATUS send_hardware_message( HWND hwnd, const INPUT *input, UINT flags )
if (!ret)
{
- if (thread_info->key_state) thread_info->key_state_time = GetTickCount();
+ if (key_state_info) key_state_info->time = GetTickCount();
if ((flags & SEND_HWMSG_INJECTED) && (prev_x != new_x || prev_y != new_y))
USER_Driver->pSetCursorPos( new_x, new_y );
}
diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h
index 919540d..9e3a373 100644
--- a/dlls/user32/user_private.h
+++ b/dlls/user32/user_private.h
@@ -184,8 +184,7 @@ struct user_thread_info
DWORD GetMessagePosVal; /* Value for GetMessagePos */
ULONG_PTR GetMessageExtraInfoVal; /* Value for GetMessageExtraInfo */
UINT active_hooks; /* Bitmap of active hooks */
- UINT key_state_time; /* Time of last key state refresh */
- BYTE *key_state; /* Cache of global key state */
+ struct user_key_state_info *key_state; /* Cache of global key state */
HWND top_window; /* Desktop window */
HWND msg_window; /* HWND_MESSAGE parent window */
RAWINPUT *rawinput;
@@ -193,6 +192,12 @@ struct user_thread_info
C_ASSERT( sizeof(struct user_thread_info) <= sizeof(((TEB *)0)->Win32ClientInfo) );
+struct user_key_state_info
+{
+ UINT time; /* Time of last key state refresh */
+ BYTE state[256]; /* State for each key */
+};
+
struct hook_extra_info
{
HHOOK handle;
diff --git a/dlls/user32/winstation.c b/dlls/user32/winstation.c
index 12b9edc..d1353b4 100644
--- a/dlls/user32/winstation.c
+++ b/dlls/user32/winstation.c
@@ -399,9 +399,10 @@ BOOL WINAPI SetThreadDesktop( HDESK handle )
if (ret) /* reset the desktop windows */
{
struct user_thread_info *thread_info = get_user_thread_info();
+ struct user_key_state_info *key_state_info = thread_info->key_state;
thread_info->top_window = 0;
thread_info->msg_window = 0;
- thread_info->key_state_time = 0;
+ if (key_state_info) key_state_info->time = 0;
}
return ret;
}
More information about the wine-cvs
mailing list