[WIN32K]
[reactos.git] / reactos / win32ss / user / ntuser / windc.c
index 8921d0c..0e71267 100644 (file)
@@ -46,21 +46,47 @@ DceCreateDisplayDC(VOID)
   return IntGdiCreateDC(&DriverName, NULL, NULL, NULL, FALSE);
 }
 
+/* Returns the DCE pointer from the HDC handle */
+DCE*
+FASTCALL
+DceGetDceFromDC(HDC hdc)
+{
+    LIST_ENTRY* Entry = LEDce.Flink;
+    DCE* dce;
+
+    while (Entry != &LEDce)
+    {
+        dce = CONTAINING_RECORD(Entry, DCE, List);
+        if (dce->hDC == hdc)
+            return dce;
+        Entry = Entry->Flink;
+    }
+
+    return NULL;
+}
+
 static
-HRGN FASTCALL
+PREGION FASTCALL
 DceGetVisRgn(PWND Window, ULONG Flags, HWND hWndChild, ULONG CFlags)
 {
-  HRGN VisRgn;
+  PREGION RetRgn;
+  HRGN hVisRgn;
+  hVisRgn = VIS_ComputeVisibleRegion( Window,
+                                      0 == (Flags & DCX_WINDOW),
+                                      0 != (Flags & DCX_CLIPCHILDREN),
+                                      0 != (Flags & DCX_CLIPSIBLINGS));
 
-  VisRgn = VIS_ComputeVisibleRegion( Window,
-                                     0 == (Flags & DCX_WINDOW),
-                                     0 != (Flags & DCX_CLIPCHILDREN),
-                                     0 != (Flags & DCX_CLIPSIBLINGS));
+  RetRgn = IntSysCreateRectpRgn(0, 0, 0, 0);
 
-  if (VisRgn == NULL)
-      VisRgn = IntSysCreateRectRgn(0, 0, 0, 0);
+  if (hVisRgn != NULL)
+  {
+      PREGION VisRgn = REGION_LockRgn(hVisRgn);
+      IntGdiCombineRgn(RetRgn, VisRgn, NULL, RGN_COPY);
+      REGION_UnlockRgn(VisRgn);
+      GreDeleteObject(hVisRgn);
+  }
 
-  return VisRgn;
+  return RetRgn;
 }
 
 PDCE FASTCALL
@@ -98,7 +124,7 @@ DceAllocDCE(PWND Window OPTIONAL, DCE_TYPE Type)
   }
   else
   {
-     TRACE("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %x\n", pDce->hDC);
+     TRACE("FREE DCATTR!!!! NOT DCE_WINDOW_DC!!!!! hDC-> %p\n", pDce->hDC);
      GreSetDCOwner(pDce->hDC, GDI_OBJ_HMGR_NONE);
      pDce->ptiOwner = NULL;
   }
@@ -150,6 +176,7 @@ DceSetDrawable( PWND Window OPTIONAL,
          dc->ptlDCOrig.y = Window->rcClient.top;
       }
   }
+  dc->fs |= DC_FLAG_DIRTY_RAO;
   DC_UnlockDc(dc);
 }
 
@@ -175,10 +202,11 @@ DceDeleteClipRgn(DCE* Dce)
    IntGdiSetHookFlags(Dce->hDC, DCHF_INVALIDATEVISRGN);
 }
 
-static VOID FASTCALL
+VOID
+FASTCALL
 DceUpdateVisRgn(DCE *Dce, PWND Window, ULONG Flags)
 {
-   HANDLE hRgnVisible = NULL;
+   PREGION RgnVisible = NULL;
    ULONG DcxFlags;
    PWND DesktopWindow;
 
@@ -189,7 +217,7 @@ DceUpdateVisRgn(DCE *Dce, PWND Window, ULONG Flags)
       Parent = Window->spwndParent;
       if(!Parent)
       {
-         hRgnVisible = NULL;
+         RgnVisible = NULL;
          goto noparent;
       }
 
@@ -202,23 +230,23 @@ DceUpdateVisRgn(DCE *Dce, PWND Window, ULONG Flags)
       {
          DcxFlags = Flags & ~(DCX_CLIPSIBLINGS | DCX_CLIPCHILDREN | DCX_WINDOW);
       }
-      hRgnVisible = DceGetVisRgn(Parent, DcxFlags, Window->head.h, Flags);
+      RgnVisible = DceGetVisRgn(Parent, DcxFlags, Window->head.h, Flags);
    }
    else if (Window == NULL)
    {
       DesktopWindow = UserGetWindowObject(IntGetDesktopWindow());
       if (NULL != DesktopWindow)
       {
-         hRgnVisible = IntSysCreateRectRgnIndirect(&DesktopWindow->rcWindow);
+         RgnVisible = IntSysCreateRectpRgnIndirect(&DesktopWindow->rcWindow);
       }
       else
       {
-         hRgnVisible = NULL;
+         RgnVisible = NULL;
       }
    }
    else
    {
-      hRgnVisible = DceGetVisRgn(Window, Flags, 0, 0);
+      RgnVisible = DceGetVisRgn(Window, Flags, 0, 0);
    }
 
 noparent:
@@ -226,33 +254,35 @@ noparent:
    {
       if(Dce->hrgnClip != NULL)
       {
-         NtGdiCombineRgn(hRgnVisible, hRgnVisible, Dce->hrgnClip, RGN_AND);
+         PREGION RgnClip = REGION_LockRgn(Dce->hrgnClip);
+         IntGdiCombineRgn(RgnVisible, RgnVisible, RgnClip, RGN_AND);
+         REGION_UnlockRgn(RgnClip);
       }
       else
       {
-         if(hRgnVisible != NULL)
+         if(RgnVisible != NULL)
          {
-            GreDeleteObject(hRgnVisible);
+            REGION_Delete(RgnVisible);
          }
-         hRgnVisible = IntSysCreateRectRgn(0, 0, 0, 0);
+         RgnVisible = IntSysCreateRectpRgn(0, 0, 0, 0);
       }
    }
-   else if (Flags & DCX_EXCLUDERGN && Dce->hrgnClip != NULL)
+   else if ((Flags & DCX_EXCLUDERGN) && Dce->hrgnClip != NULL)
    {
-      NtGdiCombineRgn(hRgnVisible, hRgnVisible, Dce->hrgnClip, RGN_DIFF);
+       PREGION RgnClip = REGION_LockRgn(Dce->hrgnClip);
+       IntGdiCombineRgn(RgnVisible, RgnVisible, RgnClip, RGN_DIFF);
+       REGION_UnlockRgn(RgnClip);
    }
 
    Dce->DCXFlags &= ~DCX_DCEDIRTY;
-   GdiSelectVisRgn(Dce->hDC, hRgnVisible);
-
-   if (Window != NULL)
-   {
-      IntEngWindowChanged(Window, WOC_RGN_CLIENT);
-   }
+   GdiSelectVisRgn(Dce->hDC, RgnVisible);
+   /* Tell GDI driver */
+   if (Window)
+       IntEngWindowChanged(Window, WOC_RGN_CLIENT);
 
-   if (hRgnVisible != NULL)
+   if (RgnVisible != NULL)
    {
-      GreDeleteObject(hRgnVisible);
+      REGION_Delete(RgnVisible);
    }
 }
 
@@ -296,7 +326,7 @@ DceReleaseDC(DCE* dce, BOOL EndPaint)
          }
       }
       dce->DCXFlags &= ~DCX_DCEBUSY;
-      TRACE("Exit!!!!! DCX_CACHE!!!!!!   hDC-> %x \n", dce->hDC);
+      TRACE("Exit!!!!! DCX_CACHE!!!!!!   hDC-> %p \n", dce->hDC);
       if (!GreSetDCOwner(dce->hDC, GDI_OBJ_HMGR_NONE))
          return 0;
       dce->ptiOwner = NULL; // Reset ownership.
@@ -462,7 +492,6 @@ UserGetDCEx(PWND Wnd OPTIONAL, HANDLE ClipRegion, ULONG Flags)
                      ((Dce->DCXFlags & DCX_CACHECOMPAREMASK) == DcxFlags))
             {
                UpdateClipOrigin = TRUE;
-               //bUpdateVisRgn = FALSE;
                break;
             }
          }
@@ -516,7 +545,7 @@ UserGetDCEx(PWND Wnd OPTIONAL, HANDLE ClipRegion, ULONG Flags)
 
    if (!GreIsHandleValid(Dce->hDC))
    {
-      ERR("FIXME: Got DCE with invalid hDC! 0x%x\n", Dce->hDC);
+      ERR("FIXME: Got DCE with invalid hDC! %p\n", Dce->hDC);
       Dce->hDC = DceCreateDisplayDC();
       /* FIXME: Handle error */
    }
@@ -578,7 +607,7 @@ UserGetDCEx(PWND Wnd OPTIONAL, HANDLE ClipRegion, ULONG Flags)
 
    if (Dce->DCXFlags & DCX_CACHE)
    {
-      TRACE("ENTER!!!!!! DCX_CACHE!!!!!!   hDC-> %x\n", Dce->hDC);
+      TRACE("ENTER!!!!!! DCX_CACHE!!!!!!   hDC-> %p\n", Dce->hDC);
       // Need to set ownership so Sync dcattr will work.
       GreSetDCOwner(Dce->hDC, GDI_OBJ_HMGR_POWNED);
       Dce->ptiOwner = GetW32ThreadInfo(); // Set the temp owning
@@ -622,7 +651,7 @@ DceFreeDCE(PDCE pdce, BOOLEAN Force)
   if (Force &&
       GreGetObjectOwner(pdce->hDC) != GDI_OBJ_HMGR_POWNED)
   {
-     TRACE("Change ownership for DCE! -> %x\n" , pdce);
+     TRACE("Change ownership for DCE! -> %p\n" , pdce);
      // NOTE: Windows sets W32PF_OWNDCCLEANUP and moves on.
      if (GreIsHandleValid(pdce->hDC))
      {
@@ -630,7 +659,8 @@ DceFreeDCE(PDCE pdce, BOOLEAN Force)
      }
      else
      {
-         ERR("Attempted to change ownership of an DCEhDC 0x%x currently being destroyed!!!\n",pdce->hDC);
+         ERR("Attempted to change ownership of an DCEhDC %p currently being destroyed!!!\n",
+             pdce->hDC);
          Hit = TRUE;
      }
   }
@@ -652,7 +682,7 @@ DceFreeDCE(PDCE pdce, BOOLEAN Force)
 
   if (IsListEmpty(&pdce->List))
   {
-      ERR("List is Empty! DCE! -> %x\n" , pdce);
+      ERR("List is Empty! DCE! -> %p\n" , pdce);
       return NULL;
   }
 
@@ -711,10 +741,11 @@ DceFreeWindowDCE(PWND Window)
               pDCE->hwndCurrent = 0;
               pDCE->pwndOrg = pDCE->pwndClip = NULL;
 
-              TRACE("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %x \n", pDCE->hDC);
+              TRACE("POWNED DCE going Cheap!! DCX_CACHE!! hDC-> %p \n",
+                    pDCE->hDC);
               if (!GreSetDCOwner( pDCE->hDC, GDI_OBJ_HMGR_NONE))
               {
-                  ERR("Fail Owner Switch hDC-> %x \n", pDCE->hDC);
+                  ERR("Fail Owner Switch hDC-> %p \n", pDCE->hDC);
                   break;
               }
               /* Do not change owner so thread can clean up! */
@@ -727,7 +758,8 @@ DceFreeWindowDCE(PWND Window)
            }
            else
            {
-              ERR("Not POWNED or CLASSDC hwndCurrent -> %x \n", pDCE->hwndCurrent);
+              ERR("Not POWNED or CLASSDC hwndCurrent -> %p \n",
+                  pDCE->hwndCurrent);
               // ASSERT(FALSE); /* bug 5320 */
            }
         }
@@ -853,7 +885,7 @@ DceResetActiveDCEs(PWND Window)
          {
             if (!pDCE->hwndCurrent)
                CurrentWindow = NULL;
-            else 
+            else
                CurrentWindow = UserGetWindowObject(pDCE->hwndCurrent);
             if (NULL == CurrentWindow)
             {
@@ -887,10 +919,10 @@ DceResetActiveDCEs(PWND Window)
                dc->ptlDCOrig.y = CurrentWindow->rcClient.top;
             }
 
-            if (NULL != dc->rosdc.hClipRgn)
+            if (NULL != dc->dclevel.prgnClip)
             {
-               NtGdiOffsetRgn(dc->rosdc.hClipRgn, DeltaX, DeltaY);
-               CLIPPING_UpdateGCRegion(dc);
+               IntGdiOffsetRgn(dc->dclevel.prgnClip, DeltaX, DeltaY);
+               dc->fs |= DC_FLAG_DIRTY_RAO;
             }
             if (NULL != pDCE->hrgnClip)
             {
@@ -901,12 +933,6 @@ DceResetActiveDCEs(PWND Window)
 
          DceUpdateVisRgn(pDCE, CurrentWindow, pDCE->DCXFlags);
          IntGdiSetHookFlags(pDCE->hDC, DCHF_VALIDATEVISRGN);
-
-         if (Window->head.h != pDCE->hwndCurrent)
-         {
-//            IntEngWindowChanged(CurrentWindow, WOC_RGN_CLIENT);
-//            UserDerefObject(CurrentWindow);
-         }
       }
       pLE = pDCE->List.Flink;
       pDCE = CONTAINING_RECORD(pLE, DCE, List);
@@ -981,22 +1007,22 @@ UserGetWindowDC(PWND Wnd)
 HWND FASTCALL
 UserGethWnd( HDC hdc, PWNDOBJ *pwndo)
 {
-  PWNDGDI pWndgdi;
+  XCLIPOBJ* Clip;
   PWND Wnd;
   HWND hWnd;
   PPROPERTY pprop;
 
   hWnd = IntWindowFromDC(hdc);
 
-  if (hWnd && !(Wnd = UserGetWindowObject(hWnd)))
+  if (hWnd && (Wnd = UserGetWindowObject(hWnd)))
   {
      pprop = IntGetProp(Wnd, AtomWndObj);
 
-     pWndgdi = (WNDGDI *)pprop->Data;
+     Clip = (XCLIPOBJ*)pprop->Data;
 
-     if ( pWndgdi && pWndgdi->Hwnd == hWnd )
+     if ( Clip && Clip->Hwnd == hWnd )
      {
-        if (pwndo) *pwndo = (PWNDOBJ)pWndgdi;
+        if (pwndo) *pwndo = &Clip->WndObj;
      }
   }
   return hWnd;
@@ -1018,7 +1044,7 @@ NtUserGetDCEx(HWND hWnd OPTIONAL, HANDLE ClipRegion, ULONG Flags)
   RETURN( UserGetDCEx(Wnd, ClipRegion, Flags));
 
 CLEANUP:
-  TRACE("Leave NtUserGetDCEx, ret=%i\n",_ret_);
+  TRACE("Leave NtUserGetDCEx, ret=%p\n", _ret_);
   UserLeave();
   END_CLEANUP;
 }
@@ -1044,7 +1070,7 @@ NtUserGetWindowDC(HWND hWnd)
 HDC APIENTRY
 NtUserGetDC(HWND hWnd)
 {
- TRACE("NtUGetDC -> %x:%x\n", hWnd, !hWnd ? DCX_CACHE | DCX_WINDOW : DCX_USESTYLE );
+ TRACE("NtUGetDC -> %p:%x\n", hWnd, !hWnd ? DCX_CACHE | DCX_WINDOW : DCX_USESTYLE);
 
   return NtUserGetDCEx(hWnd, NULL, NULL == hWnd ? DCX_CACHE | DCX_WINDOW : DCX_USESTYLE);
 }