[ros-diffs] [jimtabor] 49612: [Win32k] - Test for hooks before setting up for a hook call. This eliminates overhead.

jimtabor at svn.reactos.org jimtabor at svn.reactos.org
Thu Nov 18 16:17:59 UTC 2010


Author: jimtabor
Date: Thu Nov 18 16:17:59 2010
New Revision: 49612

URL: http://svn.reactos.org/svn/reactos?rev=49612&view=rev
Log:
[Win32k]
- Test for hooks before setting up for a hook call. This eliminates overhead.

Modified:
    trunk/reactos/subsystems/win32/win32k/ntuser/window.c

Modified: trunk/reactos/subsystems/win32/win32k/ntuser/window.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ntuser/window.c?rev=49612&r1=49611&r2=49612&view=diff
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/ntuser/window.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/ntuser/window.c [iso-8859-1] Thu Nov 18 16:17:59 2010
@@ -14,7 +14,6 @@
 
 #define NDEBUG
 #include <debug.h>
-
 
 /* dialog resources appear to pass this in 16 bits, handle them properly */
 #define CW_USEDEFAULT16 (0x8000)
@@ -402,6 +401,9 @@
 
    DestroyTimersForWindow(ThreadData, Window);
 
+   /* Unregister hot keys */
+   UnregisterWindowHotKeys (Window);
+
    /* flush the message queue */
    MsqRemoveWindowMessagesFromQueue(Window);
 
@@ -420,9 +422,6 @@
       if (Window->head.h == ThreadData->rpdesk->rpwinstaParent->ShellListView)
          ThreadData->rpdesk->rpwinstaParent->ShellListView = NULL;
    }
-
-   /* Unregister hot keys */
-   UnregisterWindowHotKeys (Window);
 
    /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
 
@@ -1909,7 +1908,7 @@
    USER_REFERENCE_ENTRY ParentRef, Ref;
    PTHREADINFO pti;
    DWORD dwShowMode = SW_SHOW;
-   CREATESTRUCTW *pCsw;
+   CREATESTRUCTW *pCsw = NULL;
    PVOID pszClass = NULL, pszName = NULL;
    DECLARE_RETURN(PWND);
 
@@ -1983,100 +1982,94 @@
    }
 
    hWnd = UserHMGetHandle(Window);
+   hwndInsertAfter = HWND_TOP;
 
    UserRefObjectCo(Window, &Ref);
    ObDereferenceObject(WinSta);
 
-   //// Call the WH_CBT hook ////
-
-   // Allocate the calling structures Justin Case this goes Global.
-   pCsw = ExAllocatePoolWithTag(NonPagedPool, sizeof(CREATESTRUCTW), TAG_HOOK);
-   pCbtCreate = ExAllocatePoolWithTag(NonPagedPool, sizeof(CBT_CREATEWNDW), TAG_HOOK);
-
-   /* Fill the new CREATESTRUCTW */
-   pCsw->lpCreateParams = Cs->lpCreateParams;
-   pCsw->hInstance = Cs->hInstance;
-   pCsw->hMenu = Cs->hMenu;
-   pCsw->hwndParent = Cs->hwndParent;
-   pCsw->cx = Cs->cx;
-   pCsw->cy = Cs->cy;
-   pCsw->x = Cs->x;
-   pCsw->y = Cs->y;
-   pCsw->dwExStyle = Cs->dwExStyle;
-   dwStyle = Cs->style;       // Save it anyway.
-   pCsw->style = Window->style; /* HCBT_CREATEWND needs the real window style */
-   pCsw->lpszName  = Cs->lpszName;
-   pCsw->lpszClass = Cs->lpszClass;
-
-   // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
-   if (!IS_ATOM(ClassName->Buffer))
-   {
-      if (Window->state & WNDS_ANSICREATOR)
-      {
-         ANSI_STRING AnsiString;
-         AnsiString.MaximumLength = RtlUnicodeStringToAnsiSize(ClassName)+sizeof(CHAR);
-         pszClass = UserHeapAlloc(AnsiString.MaximumLength);
-         RtlZeroMemory(pszClass, AnsiString.MaximumLength);
-         AnsiString.Buffer = (PCHAR)pszClass;
-         RtlUnicodeStringToAnsiString(&AnsiString, ClassName, FALSE);
-      }
-      else
-      {
-         UNICODE_STRING UnicodeString;
-         UnicodeString.MaximumLength = ClassName->Length + sizeof(UNICODE_NULL);
-         pszClass = UserHeapAlloc(UnicodeString.MaximumLength);
-         RtlZeroMemory(pszClass, UnicodeString.MaximumLength);
-         UnicodeString.Buffer = (PWSTR)pszClass;
-         RtlCopyUnicodeString(&UnicodeString, ClassName);
-      }
-      if (pszClass) pCsw->lpszClass = UserHeapAddressToUser(pszClass);
-   }
-   if (WindowName->Length)
-   {
-      UNICODE_STRING Name;
-      Name.Buffer = WindowName->Buffer;
-      Name.Length = WindowName->Length;
-      Name.MaximumLength = WindowName->MaximumLength;
-
-      if (Window->state & WNDS_ANSICREATOR)
-      {
-         ANSI_STRING AnsiString;
-         AnsiString.MaximumLength = RtlUnicodeStringToAnsiSize(&Name)+sizeof(CHAR);
-         pszName = UserHeapAlloc(AnsiString.MaximumLength);
-         RtlZeroMemory(pszName, AnsiString.MaximumLength);
-         AnsiString.Buffer = (PCHAR)pszName;
-         RtlUnicodeStringToAnsiString(&AnsiString, &Name, FALSE);
-      }
-      else
-      {
-         UNICODE_STRING UnicodeString;
-         UnicodeString.MaximumLength = Name.Length + sizeof(UNICODE_NULL);
-         pszName = UserHeapAlloc(UnicodeString.MaximumLength);
-         RtlZeroMemory(pszName, UnicodeString.MaximumLength);
-         UnicodeString.Buffer = (PWSTR)pszName; 
-         RtlCopyUnicodeString(&UnicodeString, &Name);
-      }
-      if (pszName) pCsw->lpszName = UserHeapAddressToUser(pszName);
-   }
-
-   pCbtCreate->lpcs = pCsw;
-   pCbtCreate->hwndInsertAfter = HWND_TOP;
-
-   Result = co_HOOK_CallHooks(WH_CBT, HCBT_CREATEWND, (WPARAM) hWnd, (LPARAM) pCbtCreate);
-   if (Result != 0)
-   {
-      DPRINT1("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result);
-      RETURN( (PWND) NULL);
-   }
-   // Write back changes.
-   Cs->cx = pCsw->cx;
-   Cs->cy = pCsw->cy;
-   Cs->x = pCsw->x;
-   Cs->y = pCsw->y;
-   hwndInsertAfter = pCbtCreate->hwndInsertAfter;
+   dwStyle = Window->style;
+
+   //// Check for a hook to eliminate overhead. ////
+   if ( ISITHOOKED(WH_CBT) ||  (pti->rpdesk->pDeskInfo->fsHooks & HOOKID_TO_FLAG(WH_CBT)) )
+   {
+      // Allocate the calling structures Justin Case this goes Global.
+      pCsw = ExAllocatePoolWithTag(NonPagedPool, sizeof(CREATESTRUCTW), TAG_HOOK);
+      pCbtCreate = ExAllocatePoolWithTag(NonPagedPool, sizeof(CBT_CREATEWNDW), TAG_HOOK);
+
+      /* Fill the new CREATESTRUCTW */
+      RtlCopyMemory(pCsw, Cs, sizeof(CREATESTRUCTW));
+      pCsw->style = dwStyle; /* HCBT_CREATEWND needs the real window style */
+
+      // Based on the assumption this is from "unicode source" user32, ReactOS, answer is yes.
+      if (!IS_ATOM(ClassName->Buffer))
+      {
+         if (Window->state & WNDS_ANSICREATOR)
+         {
+            ANSI_STRING AnsiString;
+            AnsiString.MaximumLength = RtlUnicodeStringToAnsiSize(ClassName)+sizeof(CHAR);
+            pszClass = UserHeapAlloc(AnsiString.MaximumLength);
+            RtlZeroMemory(pszClass, AnsiString.MaximumLength);
+            AnsiString.Buffer = (PCHAR)pszClass;
+            RtlUnicodeStringToAnsiString(&AnsiString, ClassName, FALSE);
+         }
+         else
+         {
+            UNICODE_STRING UnicodeString;
+            UnicodeString.MaximumLength = ClassName->Length + sizeof(UNICODE_NULL);
+            pszClass = UserHeapAlloc(UnicodeString.MaximumLength);
+            RtlZeroMemory(pszClass, UnicodeString.MaximumLength);
+            UnicodeString.Buffer = (PWSTR)pszClass;
+            RtlCopyUnicodeString(&UnicodeString, ClassName);
+         }
+         if (pszClass) pCsw->lpszClass = UserHeapAddressToUser(pszClass);
+      }
+      if (WindowName->Length)
+      {
+         UNICODE_STRING Name;
+         Name.Buffer = WindowName->Buffer;
+         Name.Length = WindowName->Length;
+         Name.MaximumLength = WindowName->MaximumLength;
+
+         if (Window->state & WNDS_ANSICREATOR)
+         {
+            ANSI_STRING AnsiString;
+            AnsiString.MaximumLength = RtlUnicodeStringToAnsiSize(&Name)+sizeof(CHAR);
+            pszName = UserHeapAlloc(AnsiString.MaximumLength);
+            RtlZeroMemory(pszName, AnsiString.MaximumLength);
+            AnsiString.Buffer = (PCHAR)pszName;
+            RtlUnicodeStringToAnsiString(&AnsiString, &Name, FALSE);
+         }
+         else
+         {
+            UNICODE_STRING UnicodeString;
+            UnicodeString.MaximumLength = Name.Length + sizeof(UNICODE_NULL);
+            pszName = UserHeapAlloc(UnicodeString.MaximumLength);
+            RtlZeroMemory(pszName, UnicodeString.MaximumLength);
+            UnicodeString.Buffer = (PWSTR)pszName; 
+            RtlCopyUnicodeString(&UnicodeString, &Name);
+         }
+         if (pszName) pCsw->lpszName = UserHeapAddressToUser(pszName);
+      }
+
+      pCbtCreate->lpcs = pCsw;
+      pCbtCreate->hwndInsertAfter = hwndInsertAfter;
+
+      //// Call the WH_CBT hook ////
+      Result = co_HOOK_CallHooks(WH_CBT, HCBT_CREATEWND, (WPARAM) hWnd, (LPARAM) pCbtCreate);
+      if (Result != 0)
+      {
+         DPRINT1("WH_CBT HCBT_CREATEWND hook failed! 0x%x\n", Result);
+         RETURN( (PWND) NULL);
+      }
+      // Write back changes.
+      Cs->cx = pCsw->cx;
+      Cs->cy = pCsw->cy;
+      Cs->x = pCsw->x;
+      Cs->y = pCsw->y;
+      hwndInsertAfter = pCbtCreate->hwndInsertAfter;
+   }
 
    /* NCCREATE and WM_NCCALCSIZE need the original values */
-   Cs->style = dwStyle;
    Cs->lpszName = (LPCWSTR) WindowName;
    Cs->lpszClass = (LPCWSTR) ClassName;
 
@@ -2115,7 +2108,7 @@
       if ((dwStyle & (WS_CHILD|WS_MAXIMIZE)) == WS_CHILD)
           IntLinkHwnd(Window, HWND_BOTTOM);
       else
-          IntLinkHwnd(Window, HWND_TOP);
+          IntLinkHwnd(Window, hwndInsertAfter);
    }
    
    /* Send the NCCREATE message */
@@ -2219,6 +2212,7 @@
 CLEANUP:
    if (!_ret_)
    {
+       DPRINT("co_UserCreateWindowEx(): Error Created window!\n");
        /* If the window was created, the class will be dereferenced by co_UserDestroyWindow */
        if (Window) 
             co_UserDestroyWindow(Window);




More information about the Ros-diffs mailing list