Optimize ClientToScreen(), ScreenToClient() and MapWindowPoints()
authorThomas Bluemel <thomas@reactsoft.com>
Fri, 16 Nov 2007 08:03:04 +0000 (08:03 +0000)
committerThomas Bluemel <thomas@reactsoft.com>
Fri, 16 Nov 2007 08:03:04 +0000 (08:03 +0000)
svn path=/trunk/; revision=30495

reactos/dll/win32/user32/include/user32.h
reactos/dll/win32/user32/misc/misc.c
reactos/dll/win32/user32/windows/window.c
reactos/include/reactos/win32k/ntuser.h
reactos/subsystems/win32/win32k/ntuser/window.c

index 9a9d850..c39f102 100644 (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);
index 4625be8..9d2d2c6 100644 (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);
+}
index a989ff3..5d11230 100644 (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;
+
+    Delta.x = FromWnd->ClientRect.left - ToWnd->ClientRect.left;
+    Delta.y = FromWnd->ClientRect.top - ToWnd->ClientRect.top;
 
-  for (i = 0; i < cPoints; i++)
+    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;
 }
 
 
index d60d06e..43005bb 100644 (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
index dd40556..f57144d 100644 (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;
    }
 
    /*