Optimize ClientToScreen(), ScreenToClient() and MapWindowPoints()

svn path=/trunk/; revision=30495
This commit is contained in:
Thomas Bluemel 2007-11-16 08:03:04 +00:00
parent 43eb284cea
commit cb75e8f462
5 changed files with 86 additions and 29 deletions

View file

@ -87,3 +87,5 @@ SharedPtrToKernel(PVOID Ptr)
PCALLPROC FASTCALL ValidateCallProc(HANDLE hCallProc);
PWINDOW FASTCALL ValidateHwnd(HWND hwnd);
PWINDOW FASTCALL ValidateHwndOrDesk(HWND hwnd);
PWINDOW FASTCALL GetThreadDesktopWnd(VOID);

View file

@ -148,6 +148,19 @@ GetW32ProcessInfo(VOID)
return pi;
}
static PDESKTOP
GetThreadDesktopInfo(VOID)
{
PW32THREADINFO ti;
PDESKTOP di = NULL;
ti = GetW32ThreadInfo();
if (ti != NULL)
di = DesktopPtrToUser(ti->Desktop);
return di;
}
/*
* GetUserObjectSecurity
@ -429,6 +442,7 @@ PWINDOW
FASTCALL
ValidateHwnd(HWND hwnd)
{
PWINDOW Wnd;
PW32CLIENTINFO ClientInfo = GetWin32ClientInfo();
ASSERT(ClientInfo != NULL);
@ -436,7 +450,7 @@ ValidateHwnd(HWND hwnd)
if (hwnd == ClientInfo->hWND)
return ClientInfo->pvWND;
PWINDOW Wnd = ValidateHandle((HANDLE)hwnd, VALIDATE_TYPE_WIN);
Wnd = ValidateHandle((HANDLE)hwnd, VALIDATE_TYPE_WIN);
if (Wnd != NULL)
{
/* FIXME: Check if handle table entry is marked as deleting and
@ -459,3 +473,26 @@ ValidateHwnd(HWND hwnd)
return NULL;
}
PWINDOW
FASTCALL
GetThreadDesktopWnd(VOID)
{
PWINDOW Wnd = GetThreadDesktopInfo()->Wnd;
if (Wnd != NULL)
Wnd = DesktopPtrToUser(Wnd);
return Wnd;
}
//
// Validate a window handle and return the pointer to the object.
//
PWINDOW
FASTCALL
ValidateHwndOrDesk(HWND hwnd)
{
if (hwnd == HWND_DESKTOP)
return GetThreadDesktopWnd();
return ValidateHwnd(hwnd);
}

View file

@ -1577,36 +1577,28 @@ WindowFromPoint(POINT Point)
int STDCALL
MapWindowPoints(HWND hWndFrom, HWND hWndTo, LPPOINT lpPoints, UINT cPoints)
{
POINT FromOffset, ToOffset;
LONG XMove, YMove;
ULONG i;
PWINDOW FromWnd, ToWnd;
POINT Delta;
UINT i;
if (hWndFrom == NULL)
{
FromOffset.x = FromOffset.y = 0;
} else
if(!NtUserGetClientOrigin(hWndFrom, &FromOffset))
{
return 0;
}
FromWnd = ValidateHwndOrDesk(hWndFrom);
if (!FromWnd)
return 0;
if (hWndTo == NULL)
{
ToOffset.x = ToOffset.y = 0;
} else
if(!NtUserGetClientOrigin(hWndTo, &ToOffset))
{
return 0;
}
XMove = FromOffset.x - ToOffset.x;
YMove = FromOffset.y - ToOffset.y;
ToWnd = ValidateHwndOrDesk(hWndTo);
if (!ToWnd)
return 0;
for (i = 0; i < cPoints; i++)
Delta.x = FromWnd->ClientRect.left - ToWnd->ClientRect.left;
Delta.y = FromWnd->ClientRect.top - ToWnd->ClientRect.top;
for (i = 0; i != cPoints; i++)
{
lpPoints[i].x += XMove;
lpPoints[i].y += YMove;
lpPoints[i].x += Delta.x;
lpPoints[i].y += Delta.y;
}
return(MAKELONG(LOWORD(XMove), LOWORD(YMove)));
return MAKELONG(LOWORD(Delta.x), LOWORD(Delta.y));
}
@ -1616,7 +1608,18 @@ MapWindowPoints(HWND hWndFrom, HWND hWndTo, LPPOINT lpPoints, UINT cPoints)
BOOL STDCALL
ScreenToClient(HWND hWnd, LPPOINT lpPoint)
{
return(MapWindowPoints(NULL, hWnd, lpPoint, 1) != 0);
PWINDOW Wnd, DesktopWnd;
Wnd = ValidateHwnd(hWnd);
if (!Wnd)
return FALSE;
DesktopWnd = GetThreadDesktopWnd();
lpPoint->x += DesktopWnd->ClientRect.left - Wnd->ClientRect.left;
lpPoint->y += DesktopWnd->ClientRect.top - Wnd->ClientRect.top;
return TRUE;
}
@ -1626,7 +1629,18 @@ ScreenToClient(HWND hWnd, LPPOINT lpPoint)
BOOL STDCALL
ClientToScreen(HWND hWnd, LPPOINT lpPoint)
{
return (MapWindowPoints( hWnd, NULL, lpPoint, 1 ) != 0);
PWINDOW Wnd, DesktopWnd;
Wnd = ValidateHwnd(hWnd);
if (!Wnd)
return FALSE;
DesktopWnd = GetThreadDesktopWnd();
lpPoint->x += Wnd->ClientRect.left - DesktopWnd->ClientRect.left;
lpPoint->y += Wnd->ClientRect.top - DesktopWnd->ClientRect.top;
return TRUE;
}

View file

@ -3,6 +3,7 @@
struct _W32PROCESSINFO;
struct _W32THREADINFO;
struct _WINDOW;
typedef struct _REGISTER_SYSCLASS
{
@ -22,9 +23,11 @@ typedef struct _DESKTOP
{
HANDLE hKernelHeap;
ULONG_PTR HeapLimit;
WCHAR szDesktopName[1];
HWND hTaskManWindow;
HWND hProgmanWindow;
struct _WINDOW *Wnd;
WCHAR szDesktopName[1];
} DESKTOP, *PDESKTOP;
typedef struct _CALLPROC

View file

@ -1600,6 +1600,7 @@ AllocErr:
{
/* If there is no desktop window yet, we must be creating it */
PsGetCurrentThreadWin32Thread()->Desktop->DesktopWindow = hWnd;
PsGetCurrentThreadWin32Thread()->Desktop->DesktopInfo->Wnd = Wnd;
}
/*