[YAROTOWS] Reintegrate the branch. For a brighter future.
authorTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 25 Oct 2010 17:36:27 +0000 (17:36 +0000)
committerTimo Kreuzer <timo.kreuzer@reactos.org>
Mon, 25 Oct 2010 17:36:27 +0000 (17:36 +0000)
Main features:
- Implement LDEVOBJ api. Responsible for loading dlls (display drivers, font drivers, keyboard layout, etc), replacing code in different locations.
- Implement PDEVOBJ api. A PDEVOBJ represents a physical device and is the core component for handling multiple display devices.
- Rewrite device locking. The new method was neccessary to allow dynamic mode switching.
- Implement support for enumerating display devices and settings.
- Implement dynamic mode switching.
- Implement a number of Eng mapping functions.
- Rewrite Eng level surface handling for cleaner code and better compatability.
- Rewrite parts of the DIB handling code.
- Rewrite DC creation and deletion. Deletion and cleanup is now completely callback based. Now we don't leak the DC objects when terminating a process, like we did before.
- Improve the XLATE and BRUSH code, removing several old hacks.
- Improve icon code.

Thanks to Jerome Gardou, Kamil Hornicek and everyone helping.

svn path=/trunk/; revision=49275

103 files changed:
reactos/base/shell/explorer/desktop/desktop.cpp
reactos/boot/bootdata/hivesys_i386.inf
reactos/boot/bootdata/packages/reactos.dff
reactos/dll/win32/gdi32/include/gdi32p.h
reactos/dll/win32/gdi32/misc/wingl.c
reactos/dll/win32/gdi32/objects/bitmap.c
reactos/dll/win32/gdi32/objects/dc.c
reactos/dll/win32/user32/include/cursor.h
reactos/dll/win32/user32/misc/display.c
reactos/dll/win32/user32/windows/class.c
reactos/dll/win32/user32/windows/cursoricon.c
reactos/dll/win32/user32/windows/draw.c
reactos/subsystems/win32/csrss/win32csr/desktopbg.c
reactos/subsystems/win32/csrss/win32csr/win32csr.rbuild
reactos/subsystems/win32/win32k/dib/alphablend.c [new file with mode: 0644]
reactos/subsystems/win32/win32k/dib/dib.c
reactos/subsystems/win32/win32k/dib/dib.h
reactos/subsystems/win32/win32k/dib/dib16bpp.c
reactos/subsystems/win32/win32k/dib/dib1bpp.c
reactos/subsystems/win32/win32k/dib/dib24bpp.c
reactos/subsystems/win32/win32k/dib/dib32bpp.c
reactos/subsystems/win32/win32k/dib/dib4bpp.c
reactos/subsystems/win32/win32k/dib/dib8bpp.c
reactos/subsystems/win32/win32k/eng/alphablend.c
reactos/subsystems/win32/win32k/eng/bitblt.c
reactos/subsystems/win32/win32k/eng/copybits.c
reactos/subsystems/win32/win32k/eng/device.c
reactos/subsystems/win32/win32k/eng/engbrush.c
reactos/subsystems/win32/win32k/eng/engmisc.c
reactos/subsystems/win32/win32k/eng/gradient.c
reactos/subsystems/win32/win32k/eng/ldevobj.c [new file with mode: 0644]
reactos/subsystems/win32/win32k/eng/lineto.c
reactos/subsystems/win32/win32k/eng/mapping.c
reactos/subsystems/win32/win32k/eng/mem.c
reactos/subsystems/win32/win32k/eng/mouse.c
reactos/subsystems/win32/win32k/eng/paint.c
reactos/subsystems/win32/win32k/eng/pdevobj.c [new file with mode: 0644]
reactos/subsystems/win32/win32k/eng/rlecomp.c [new file with mode: 0644]
reactos/subsystems/win32/win32k/eng/semaphor.c
reactos/subsystems/win32/win32k/eng/stretchblt.c
reactos/subsystems/win32/win32k/eng/surface.c
reactos/subsystems/win32/win32k/eng/transblt.c
reactos/subsystems/win32/win32k/eng/xlate.c
reactos/subsystems/win32/win32k/include/bitmaps.h
reactos/subsystems/win32/win32k/include/dc.h
reactos/subsystems/win32/win32k/include/device.h [new file with mode: 0644]
reactos/subsystems/win32/win32k/include/dib.h
reactos/subsystems/win32/win32k/include/eng.h
reactos/subsystems/win32/win32k/include/gdiobj.h
reactos/subsystems/win32/win32k/include/inteng.h
reactos/subsystems/win32/win32k/include/intgdi.h
reactos/subsystems/win32/win32k/include/ldevobj.h [new file with mode: 0644]
reactos/subsystems/win32/win32k/include/misc.h
reactos/subsystems/win32/win32k/include/mouse.h
reactos/subsystems/win32/win32k/include/palette.h
reactos/subsystems/win32/win32k/include/pdevobj.h
reactos/subsystems/win32/win32k/include/region.h
reactos/subsystems/win32/win32k/include/surface.h
reactos/subsystems/win32/win32k/include/win32kp.h
reactos/subsystems/win32/win32k/include/xlateobj.h
reactos/subsystems/win32/win32k/ldr/loader.c [deleted file]
reactos/subsystems/win32/win32k/main/dllmain.c
reactos/subsystems/win32/win32k/misc/copy.c
reactos/subsystems/win32/win32k/misc/driver.c
reactos/subsystems/win32/win32k/misc/file.c
reactos/subsystems/win32/win32k/misc/registry.c
reactos/subsystems/win32/win32k/ntddraw/dxeng.c
reactos/subsystems/win32/win32k/ntuser/clipboard.c
reactos/subsystems/win32/win32k/ntuser/cursoricon.c
reactos/subsystems/win32/win32k/ntuser/desktop.c
reactos/subsystems/win32/win32k/ntuser/display.c
reactos/subsystems/win32/win32k/ntuser/kbdlayout.c
reactos/subsystems/win32/win32k/ntuser/message.c
reactos/subsystems/win32/win32k/ntuser/metric.c
reactos/subsystems/win32/win32k/ntuser/ntstubs.c
reactos/subsystems/win32/win32k/ntuser/ntuser.c
reactos/subsystems/win32/win32k/ntuser/windc.c
reactos/subsystems/win32/win32k/objects/arc.c
reactos/subsystems/win32/win32k/objects/bitblt.c
reactos/subsystems/win32/win32k/objects/bitmaps.c
reactos/subsystems/win32/win32k/objects/brush.c
reactos/subsystems/win32/win32k/objects/cliprgn.c
reactos/subsystems/win32/win32k/objects/dcattr.c
reactos/subsystems/win32/win32k/objects/dclife.c
reactos/subsystems/win32/win32k/objects/dcobjs.c
reactos/subsystems/win32/win32k/objects/dcstate.c
reactos/subsystems/win32/win32k/objects/dcutil.c
reactos/subsystems/win32/win32k/objects/device.c
reactos/subsystems/win32/win32k/objects/dibobj.c
reactos/subsystems/win32/win32k/objects/drawing.c
reactos/subsystems/win32/win32k/objects/fillshap.c
reactos/subsystems/win32/win32k/objects/freetype.c
reactos/subsystems/win32/win32k/objects/gdibatch.c
reactos/subsystems/win32/win32k/objects/gdiobj.c
reactos/subsystems/win32/win32k/objects/icm.c
reactos/subsystems/win32/win32k/objects/line.c
reactos/subsystems/win32/win32k/objects/palette.c
reactos/subsystems/win32/win32k/objects/path.c
reactos/subsystems/win32/win32k/objects/pen.c
reactos/subsystems/win32/win32k/objects/region.c
reactos/subsystems/win32/win32k/objects/stockobj.c
reactos/subsystems/win32/win32k/stubs/stubs.c
reactos/subsystems/win32/win32k/win32k.rbuild

index aa63996..99b990b 100644 (file)
@@ -435,6 +435,12 @@ LRESULT DesktopWindow::WndProc(UINT nmsg, WPARAM wparam, LPARAM lparam)
                explorer_show_frame(SW_SHOWNORMAL);
                break;
 
+      case WM_DISPLAYCHANGE:
+        MoveWindow(_hwnd, 0, 0, LOWORD(lparam), HIWORD(lparam), TRUE);
+        MoveWindow(g_Globals._hwndShellView, 0, 0, LOWORD(lparam), HIWORD(lparam), TRUE);
+        MoveWindow(_desktopBar, 0, HIWORD(lparam) - DESKTOPBARBAR_HEIGHT, LOWORD(lparam), DESKTOPBARBAR_HEIGHT, TRUE);
+        break;
+
          case WM_GETISHELLBROWSER:
                return (LRESULT)static_cast<IShellBrowser*>(this);
 
index 9bffb34..a622fee 100644 (file)
@@ -1085,7 +1085,7 @@ HKLM,"SYSTEM\CurrentControlSet\Services\Beep","Type",0x00010001,0x00000001
 HKLM,"SYSTEM\CurrentControlSet\Services\Blue","ErrorControl",0x00010001,0x00000000
 HKLM,"SYSTEM\CurrentControlSet\Services\Blue","Group",0x00000000,"Video Init"
 HKLM,"SYSTEM\CurrentControlSet\Services\Blue","ImagePath",0x00020000,"system32\drivers\blue.sys"
-HKLM,"SYSTEM\CurrentControlSet\Services\Blue","Start",0x00010001,0x00000004
+HKLM,"SYSTEM\CurrentControlSet\Services\Blue","Start",0x00010001,0x00000001
 HKLM,"SYSTEM\CurrentControlSet\Services\Blue","Type",0x00010001,0x00000001
 
 ; Cdfs (ISO96660) filesystem driver
index d391b7b..c5e998d 100644 (file)
@@ -586,6 +586,8 @@ media\fonts\symbol.ttf                              3
 media\fonts\tahoma.ttf                              3
 media\fonts\tahomabd.ttf                            3
 
+media\vgafonts\vgafonts.cab                         4
+
 media\nls\c_037.nls                                 1
 media\nls\c_424.nls                                 1
 media\nls\c_500.nls                                 1
index 5cc0987..e8b5e63 100644 (file)
@@ -146,7 +146,7 @@ typedef BOOL (WINAPI *STARTPAGEPRINTER) (HANDLE);
 typedef BOOL (WINAPI *SEEKPRINTER) (HANDLE,LARGE_INTEGER,PLARGE_INTEGER,DWORD,BOOL);
 typedef BOOL (WINAPI *SPLREADPRINTER) (HANDLE,LPBYTE *,DWORD);
 // Same as ddk/winsplp.h DriverUnloadComplete?
-typedef BOOL (WINAPI *SPLDRIVERUNLOADCOMPLETE) (LPWSTR); 
+typedef BOOL (WINAPI *SPLDRIVERUNLOADCOMPLETE) (LPWSTR);
 // Driver support:
 // DrvDocumentEvent api/winddiui.h not W2k8 DocumentEventAW
 typedef INT (WINAPI *DOCUMENTEVENT) (HANDLE,HDC,INT,ULONG,PVOID,ULONG,PVOID);
@@ -173,10 +173,10 @@ HEAP_strdupA2W(
 VOID
 HEAP_free(LPVOID memory);
 
-VOID 
+VOID
 FASTCALL
 FONT_TextMetricWToA(
-    const TEXTMETRICW *ptmW, 
+    const TEXTMETRICW *ptmW,
     LPTEXTMETRICA ptmA
 );
 
@@ -279,7 +279,7 @@ WINAPI
 GdiSetLastError( DWORD dwErrCode );
 
 DWORD WINAPI GdiGetCodePage(HDC);
-UINT FASTCALL DIB_BitmapBitsSize( PBITMAPINFO );
+UINT FASTCALL DIB_BitmapBitsSize( CONST BITMAPINFO* );
 
 int
 WINAPI
index 5373c6f..b20ac7e 100644 (file)
@@ -166,6 +166,10 @@ SetPixelFormat(HDC  hdc,
                INT  iPixelFormat,
                CONST PIXELFORMATDESCRIPTOR * ppfd)
 {
+  /* Can only be set once */
+  INT current = GetPixelFormat(hdc);
+  if(current) return current == iPixelFormat ;
+  
   if (glSetPixelFormat == NULL)
     if (OpenGLEnable() == FALSE)
       return(0);
index 2c7d4ce..8d93036 100644 (file)
@@ -34,7 +34,7 @@ DIB_BitmapMaxBitsSize( PBITMAPINFO Info, UINT ScanLines )
 
 UINT
 FASTCALL
-DIB_BitmapBitsSize( PBITMAPINFO Info )
+DIB_BitmapBitsSize( CONST BITMAPINFO* Info )
 {
   UINT Ret;
 
@@ -43,16 +43,16 @@ DIB_BitmapBitsSize( PBITMAPINFO Info )
   if ( Info->bmiHeader.biSize == sizeof(BITMAPCOREHEADER))
   {
      PBITMAPCOREHEADER Core = (PBITMAPCOREHEADER)Info;
-     Ret = Core->bcHeight * 
+     Ret = Core->bcHeight *
           ((Core->bcWidth * Core->bcPlanes * Core->bcBitCount  + 31) & ~31 ) / 8;
   }
   else /* assume BITMAPINFOHEADER */
   {
-     if ((Info->bmiHeader.biCompression) && 
+     if ((Info->bmiHeader.biCompression) &&
          (Info->bmiHeader.biCompression != BI_BITFIELDS))
          return Info->bmiHeader.biSizeImage;
         // Make Height positive always....
-     Ret = abs(Info->bmiHeader.biHeight) * 
+     Ret = abs(Info->bmiHeader.biHeight) *
           ((Info->bmiHeader.biWidth * Info->bmiHeader.biPlanes * Info->bmiHeader.biBitCount + 31) & ~31 ) / 8;
   }
   return Ret;
@@ -132,12 +132,12 @@ WINAPI
 GdiGetBitmapBitsSize(BITMAPINFO *lpbmi)
 {
     int retSize;
-    
+
     if (lpbmi->bmiHeader.biSize == FIELD_OFFSET(BITMAPINFOHEADER, biPlanes))
     {
         /* Calc the bits Size and align it*/
-        retSize = HIWORD(lpbmi->bmiHeader.biWidth) * ((LOWORD(lpbmi->bmiHeader.biWidth) * 
-                  LOWORD(lpbmi->bmiHeader.biHeight) * HIWORD(lpbmi->bmiHeader.biHeight) + 31) 
+        retSize = HIWORD(lpbmi->bmiHeader.biWidth) * ((LOWORD(lpbmi->bmiHeader.biWidth) *
+                  LOWORD(lpbmi->bmiHeader.biHeight) * HIWORD(lpbmi->bmiHeader.biHeight) + 31)
                   & -32) / 8;
     }
     else
@@ -148,13 +148,13 @@ GdiGetBitmapBitsSize(BITMAPINFO *lpbmi)
             if (lpbmi->bmiHeader.biHeight >=0 )
             {
                 /* Calc the bits Size and align it*/
-                retSize = lpbmi->bmiHeader.biHeight * ((lpbmi->bmiHeader.biWidth * 
+                retSize = lpbmi->bmiHeader.biHeight * ((lpbmi->bmiHeader.biWidth *
                           lpbmi->bmiHeader.biPlanes * lpbmi->bmiHeader.biBitCount + 31) & -32) / 8;
             }
             else
             {
                 /* Make height postiive if it negitve then calc the bits Size and align it*/
-                retSize = (-lpbmi->bmiHeader.biHeight) * ((lpbmi->bmiHeader.biWidth * 
+                retSize = (-lpbmi->bmiHeader.biHeight) * ((lpbmi->bmiHeader.biWidth *
                           lpbmi->bmiHeader.biPlanes * lpbmi->bmiHeader.biBitCount + 31) & -32) / 8;
             }
         }
@@ -189,7 +189,7 @@ CreateDIBSection(
    {  // Verify header due to converted may == info.
       if ( pConvertedInfo->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER) )
       {
-         if ( pConvertedInfo->bmiHeader.biCompression == BI_JPEG || 
+         if ( pConvertedInfo->bmiHeader.biCompression == BI_JPEG ||
               pConvertedInfo->bmiHeader.biCompression  == BI_PNG )
          {
             SetLastError(ERROR_INVALID_PARAMETER);
@@ -319,7 +319,7 @@ CreateBitmapIndirect(const BITMAP *pbm)
         (!(pbm->bmWidthBytes & 1)) )
 
    {
-        
+
       bitmap = CreateBitmap(pbm->bmWidth,
                             pbm->bmHeight,
                             pbm->bmPlanes,
@@ -409,7 +409,7 @@ GetDIBits(
      {
         if ( lpbmi->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER) )
         {
-           if ( lpbmi->bmiHeader.biCompression == BI_JPEG || 
+           if ( lpbmi->bmiHeader.biCompression == BI_JPEG ||
                 lpbmi->bmiHeader.biCompression == BI_PNG )
            {
               SetLastError(ERROR_INVALID_PARAMETER);
@@ -461,78 +461,61 @@ CreateDIBitmap( HDC hDC,
   LONG width, height, compr, dibsize;
   WORD planes, bpp;
 //  PDC_ATTR pDc_Attr;
-  PBITMAPINFO pConvertedInfo;
-  UINT ConvertedInfoSize;
-  UINT cjBmpScanSize;
-  PVOID pvSafeBits = NULL;
+  UINT InfoSize = 0;
+  UINT cjBmpScanSize = 0;
   HBITMAP hBmp;
+  NTSTATUS Status = STATUS_SUCCESS;
 
   if (!Header) return 0;
 
-  pConvertedInfo = ConvertBitmapInfo(Data, ColorUse,
-                                          &ConvertedInfoSize, FALSE);
-
   if (DIB_GetBitmapInfo(Header, &width, &height, &planes, &bpp, &compr, &dibsize) == -1)
   {
      GdiSetLastError(ERROR_INVALID_PARAMETER);
      return NULL;
   }
 
-  if ( pConvertedInfo )
-  {
-     if ( pConvertedInfo->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER) )
-     {
-        if ( pConvertedInfo->bmiHeader.biCompression == BI_JPEG || 
-             pConvertedInfo->bmiHeader.biCompression == BI_PNG )
-        {
-           hBmp = NULL;
-           goto Exit;
-        }
-     }
-  }
-  
 // For Icm support.
 // GdiGetHandleUserData(hdc, GDI_OBJECT_TYPE_DC, (PVOID)&pDc_Attr))
 
-  cjBmpScanSize = DIB_BitmapBitsSize((LPBITMAPINFO)pConvertedInfo);
-  DPRINT("pBMI %x, Size bpp %d, dibsize %d, Conv %d, BSS %d\n", pConvertedInfo,bpp,dibsize,ConvertedInfoSize,cjBmpScanSize);
+  if(Data)
+  {
+      _SEH2_TRY
+      {
+          cjBmpScanSize = DIB_BitmapBitsSize(Data);
+          CalculateColorTableSize(&Data->bmiHeader, &ColorUse, &InfoSize);
+          InfoSize += Data->bmiHeader.biSize;
+      }
+      _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+      {
+            Status = _SEH2_GetExceptionCode();
+      }
+      _SEH2_END
+  }
+
+  if(!NT_SUCCESS(Status))
+  {
+     GdiSetLastError(ERROR_INVALID_PARAMETER);
+     return NULL;
+  }
+
+  DPRINT("pBMI %x, Size bpp %d, dibsize %d, Conv %d, BSS %d\n", Data,bpp,dibsize,InfoSize,cjBmpScanSize);
 
   if ( !width || !height )
      hBmp = GetStockObject(DEFAULT_BITMAP);
   else
   {
-     if ( Bits && Init == CBM_INIT )
-     {
-        pvSafeBits = RtlAllocateHeap(GetProcessHeap(), 0, cjBmpScanSize);
-        if (pvSafeBits == NULL)
-        {
-            hBmp = NULL;
-            goto Exit;
-        }
-        else
-        {
-           RtlCopyMemory( pvSafeBits, Bits, cjBmpScanSize);
-        }
-     }
-
      hBmp = NtGdiCreateDIBitmapInternal(hDC,
                                         width,
                                         height,
                                         Init,
-                                        (LPBYTE)pvSafeBits,
-                                        (PBITMAPINFO)pConvertedInfo,
+                                        (LPBYTE)Bits,
+                                        (LPBITMAPINFO)Data,
                                         ColorUse,
-                                        ConvertedInfoSize,
+                                        InfoSize,
                                         cjBmpScanSize,
                                         0,
                                         0);
-
-     if ( Bits && Init == CBM_INIT )
-        RtlFreeHeap(RtlGetProcessHeap(), 0, pvSafeBits);
   }
-Exit:
-  if (Data != pConvertedInfo)
-     RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
   return hBmp;
 }
 
@@ -588,7 +571,7 @@ SetDIBits(HDC hDC,
 
  if ( hOldBitmap )
  {
-    if ( hDC )    
+    if ( hDC )
       hPal = SelectPalette(SavehDC, (HPALETTE)GetDCObject(hDC, GDI_OBJECT_TYPE_PALETTE), FALSE);
 
     if ( lpbmi->bmiHeader.biSize < sizeof(BITMAPINFOHEADER))
@@ -782,7 +765,7 @@ SetDIBitsToDevice(
 /*
   if ( !pDc_Attr ||
        ((pConvertedInfo->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER)) &&
-       (pConvertedInfo->bmiHeader.biCompression == BI_JPEG || 
+       (pConvertedInfo->bmiHeader.biCompression == BI_JPEG ||
         pConvertedInfo->bmiHeader.biCompression  == BI_PNG )) )*/
   {
     LinesCopied = NtGdiSetDIBitsToDeviceInternal( hdc,
@@ -806,7 +789,7 @@ SetDIBitsToDevice(
      RtlFreeHeap(RtlGetProcessHeap(), 0, pvSafeBits);
   if (lpbmi != pConvertedInfo)
      RtlFreeHeap(RtlGetProcessHeap(), 0, pConvertedInfo);
-         
+
   return LinesCopied;
 }
 
@@ -886,17 +869,12 @@ StretchDIBits(HDC hdc,
     }
   }
 #endif
-  if ( iUsage ) // Save time, we only look at non RGB.
-  {
-     pConvertedInfo = ConvertBitmapInfo(lpBitsInfo, iUsage,
-                                      &ConvertedInfoSize, FALSE);
-     if (!pConvertedInfo)
-     {
+    pConvertedInfo = ConvertBitmapInfo(lpBitsInfo, iUsage,
+                                  &ConvertedInfoSize, FALSE);
+    if (!pConvertedInfo)
+    {
         return 0;
-     }
-  }
-  else
-     pConvertedInfo = (PBITMAPINFO)lpBitsInfo;
+    }
 
   cjBmpScanSize = DIB_BitmapBitsSize((LPBITMAPINFO)pConvertedInfo);
 
@@ -933,7 +911,7 @@ StretchDIBits(HDC hdc,
 /*
   if ( !pDc_Attr ||
        ((pConvertedInfo->bmiHeader.biSize >= sizeof(BITMAPINFOHEADER)) &&
-       (pConvertedInfo->bmiHeader.biCompression == BI_JPEG || 
+       (pConvertedInfo->bmiHeader.biCompression == BI_JPEG ||
         pConvertedInfo->bmiHeader.biCompression  == BI_PNG )) )*/
   {
      LinesCopied = NtGdiStretchDIBitsInternal( hdc,
index ddc33e5..eb9dcf2 100644 (file)
@@ -15,7 +15,7 @@ IntCreateDICW ( LPCWSTR   lpwszDriver,
 {
  UNICODE_STRING Device, Output;
  HDC hDC = NULL;
- BOOL Display = FALSE, Default = TRUE;
+ BOOL Display = FALSE, Default = FALSE;
  ULONG UMdhpdev = 0;
 
  HANDLE hspool = NULL;
@@ -31,7 +31,7 @@ IntCreateDICW ( LPCWSTR   lpwszDriver,
 
  if ((!lpwszDevice) && (!lpwszDriver))
  {
-     Default = FALSE;  // Ask Win32k to set Default device.
+     Default = TRUE;  // Ask Win32k to set Default device.
      Display = TRUE;   // Most likely to be DISPLAY.
  }
  else
@@ -60,7 +60,7 @@ IntCreateDICW ( LPCWSTR   lpwszDriver,
     DPRINT1("Not a DISPLAY device! %wZ\n", &Device);
  }
 
- hDC = NtGdiOpenDCW( (Default ? &Device : NULL),
+ hDC = NtGdiOpenDCW( (Default ? NULL : &Device),
                      (PDEVMODEW) lpInitData,
                      (lpwszOutput ? &Output : NULL),
                       iType,             // DCW 0 and ICW 1.
@@ -318,7 +318,7 @@ WINAPI
 DeleteObject(HGDIOBJ hObject)
 {
   UINT Type = 0;
-    
+
   /* From Wine: DeleteObject does not SetLastError() on a null object */
   if(!hObject) return FALSE;
 
@@ -332,7 +332,7 @@ DeleteObject(HGDIOBJ hObject)
 
   Type = GDI_HANDLE_GET_TYPE(hObject);
 
-  if ((Type == GDI_OBJECT_TYPE_METAFILE) || 
+  if ((Type == GDI_OBJECT_TYPE_METAFILE) ||
       (Type == GDI_OBJECT_TYPE_ENHMETAFILE))
      return FALSE;
 
@@ -348,7 +348,7 @@ DeleteObject(HGDIOBJ hObject)
      case GDI_OBJECT_TYPE_METADC:
        return MFDRV_DeleteObject( hObject );
      case GDI_OBJECT_TYPE_EMF:
-     {          
+     {
        PLDC pLDC = GdiGetLDC(hObject);
        if ( !pLDC ) return FALSE;
        return EMFDRV_DeleteObject( hObject );
@@ -533,7 +533,7 @@ GetDeviceCaps(HDC hDC,
         return NtGdiGetDeviceCaps(hDC,i);
   }
   DPRINT("Device CAPS2\n");
-  
+
   switch (i)
   {
     case DRIVERVERSION:
@@ -1603,7 +1603,7 @@ SelectObject(HDC hDC,
 
 #if 0
         case GDI_OBJECT_TYPE_METADC:
-            return MFDRV_SelectObject( hDC, hGdiObj); 
+            return MFDRV_SelectObject( hDC, hGdiObj);
         case GDI_OBJECT_TYPE_EMF:
             PLDC pLDC = GdiGetLDC(hDC);
             if ( !pLDC ) return NULL;
index 67d3053..a8e966e 100644 (file)
@@ -1,2 +1,12 @@
 HCURSOR
-CursorIconToCursor(HICON hIcon, BOOL SemiTransparent);
+CursorIconToCursor(HICON hIcon,
+                   BOOL SemiTransparent);
+
+HICON CreateCursorIconFromData(PVOID ImageData,
+                               ICONIMAGE* IconImage,
+                               int cxDesired,
+                               int cyDesired,
+                               int xHotspot,
+                               int yHotspot,
+                               BOOL fIcon);
+
index 9090454..e9de23e 100644 (file)
@@ -457,7 +457,6 @@ ChangeDisplaySettingsExA(
   LONG rc;
   UNICODE_STRING DeviceName;
   PUNICODE_STRING pDeviceName = &DeviceName;
-  LPDEVMODEW pDevModeW;
 
   if (lpszDeviceName != NULL)
     {
@@ -471,14 +470,19 @@ ChangeDisplaySettingsExA(
     pDeviceName = NULL;
 
   if (lpDevMode != NULL)
+  {
+    LPDEVMODEW pDevModeW;
     pDevModeW = GdiConvertToDevmodeW(lpDevMode);
+    if(pDevModeW)
+    {
+      rc = NtUserChangeDisplaySettings ( pDeviceName, pDevModeW, hwnd, dwflags, lParam );
+      RtlFreeHeap(GetProcessHeap(), 0, pDevModeW);
+    }
+    else
+      rc = DISP_CHANGE_SUCCESSFUL;
+  }
   else
-    pDevModeW = NULL;
-
-  rc = NtUserChangeDisplaySettings ( pDeviceName, pDevModeW, hwnd, dwflags, lParam );
-
-  if (pDevModeW != NULL)
-    RtlFreeHeap(GetProcessHeap(), 0, pDevModeW);
+    rc = NtUserChangeDisplaySettings ( pDeviceName, NULL, hwnd, dwflags, lParam );
 
   if (lpszDeviceName != NULL)
     RtlFreeUnicodeString ( &DeviceName );
@@ -539,6 +543,6 @@ ChangeDisplaySettingsW(
   DWORD dwflags)
 {
   if(lpDevMode)
-    lpDevMode->dmDriverExtra = 0; 
+    lpDevMode->dmDriverExtra = 0;
   return ChangeDisplaySettingsExW ( NULL, lpDevMode, NULL, dwflags, 0 );
 }
index d55d29c..70171c6 100644 (file)
@@ -298,7 +298,7 @@ IntGetWndProc(PWND pWnd, BOOL Ansi)
      }
      return Ret;
   }
-  // Wine Class tests: 
+  // Wine Class tests:
   /*  Edit controls are special - they return a wndproc handle when
       GetWindowLongPtr is called with a different A/W.
       On the other hand there is no W->A->W conversion so this control
@@ -831,7 +831,6 @@ CreateSmallIcon(HICON StdIcon)
    int SmallIconWidth;
    int SmallIconHeight;
    BITMAP StdBitmapInfo;
-   HDC hInfoDc = NULL;
    HDC hSourceDc = NULL;
    HDC hDestDc = NULL;
    ICONINFO SmallInfo;
@@ -867,15 +866,6 @@ CreateSmallIcon(HICON StdIcon)
       return StdIcon;
    }
 
-   /* Get a handle to a info DC and handles to DCs which can be used to
-      select a bitmap into. This is done to avoid triggering a switch to
-      graphics mode (if we're currently in text/blue screen mode) */
-   hInfoDc = CreateICW(NULL, NULL, NULL, NULL);
-   if (NULL == hInfoDc)
-   {
-      ERR("Failed to create info DC\n");
-      goto cleanup;
-   }
    hSourceDc = CreateCompatibleDC(NULL);
    if (NULL == hSourceDc)
    {
@@ -895,7 +885,7 @@ CreateSmallIcon(HICON StdIcon)
       ERR("Failed to select source color bitmap\n");
       goto cleanup;
    }
-   SmallInfo.hbmColor = CreateCompatibleBitmap(hInfoDc, SmallIconWidth,
+   SmallInfo.hbmColor = CreateCompatibleBitmap(hSourceDc, SmallIconWidth,
                                               SmallIconHeight);
    if (NULL == SmallInfo.hbmColor)
    {
@@ -921,8 +911,7 @@ CreateSmallIcon(HICON StdIcon)
       ERR("Failed to select source mask bitmap\n");
       goto cleanup;
    }
-   SmallInfo.hbmMask = CreateBitmap(SmallIconWidth, SmallIconHeight, 1, 1,
-                                    NULL);
+   SmallInfo.hbmMask = CreateCompatibleBitmap(hSourceDc, SmallIconWidth, SmallIconHeight);
    if (NULL == SmallInfo.hbmMask)
    {
       ERR("Failed to create mask bitmap\n");
@@ -976,10 +965,6 @@ cleanup:
    {
       DeleteDC(hSourceDc);
    }
-   if (NULL != hInfoDc)
-   {
-      DeleteDC(hInfoDc);
-   }
 
    return SmallIcon;
 }
@@ -1070,9 +1055,9 @@ RegisterClassExWOWW(WNDCLASSEXW *lpwcx,
    clsMenuName.pszClientAnsiMenuName = AnsiMenuName.Buffer;
    clsMenuName.pwszClientUnicodeMenuName = MenuName.Buffer;
    clsMenuName.pusMenuName = &MenuName;
-   
+
    Atom = NtUserRegisterClassExWOW( &WndClass,
-                                    &ClassName,  
+                                    &ClassName,
                                      NULL, //PUNICODE_STRING ClsNVersion,
                                     &clsMenuName,
                                      fnID,
index 0c88734..f7ada0b 100644 (file)
@@ -458,10 +458,16 @@ static BOOL create_icon_bitmaps( const BITMAPINFO *bmi, int width, int height,
     void *color_bits, *mask_bits;
     BOOL ret = FALSE;
     HDC hdc = 0;
+       static HDC hScreenDC = 0;
 
     if (!(info = HeapAlloc( GetProcessHeap(), 0, max( size, FIELD_OFFSET( BITMAPINFO, bmiColors[2] )))))
         return FALSE;
-    if (!(hdc = CreateCompatibleDC( 0 ))) goto done;
+       if(!hScreenDC)
+       {
+               hScreenDC = GetDC(0);
+               if(!hScreenDC) goto done;
+       }
+    if (!(hdc = CreateCompatibleDC(hScreenDC))) goto done;
 
     memcpy( info, bmi, size );
     info->bmiHeader.biHeight /= 2;
@@ -485,8 +491,8 @@ static BOOL create_icon_bitmaps( const BITMAPINFO *bmi, int width, int height,
     else
     {
         if (!(*mask = CreateBitmap( width, height, 1, 1, NULL ))) goto done;
-        if (!(*color = CreateBitmap( width, height, bmi->bmiHeader.biPlanes,
-                                     bmi->bmiHeader.biBitCount, NULL )))
+        if (!(*color = CreateBitmap( width, height, GetDeviceCaps(hScreenDC, PLANES),
+                                     GetDeviceCaps(hScreenDC, BITSPIXEL), NULL )))
         {
             DeleteObject( *mask );
             goto done;
@@ -523,7 +529,7 @@ static BOOL create_icon_bitmaps( const BITMAPINFO *bmi, int width, int height,
     ret = TRUE;
 
 done:
-    DeleteDC( hdc );
+    if(hdc) DeleteDC( hdc );
     HeapFree( GetProcessHeap(), 0, info );
     return ret;
 }
index c722dc7..dd50c75 100644 (file)
@@ -1373,9 +1373,9 @@ IntDrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
     }
 
     if (flags & DSS_DISABLED)
-        hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DHILIGHT));
+        hbrtmp = GetSysColorBrush(COLOR_3DHILIGHT);
     else if (flags & DSS_DEFAULT)
-        hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
+        hbrtmp = GetSysColorBrush(COLOR_3DSHADOW);
 
     /* Draw light or dark shadow */
     if (flags & (DSS_DISABLED|DSS_DEFAULT))
@@ -1388,13 +1388,11 @@ IntDrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp, WPARAM wp,
         if(!BitBlt(hdc, x+1, y+1, cx, cy, memdc, 0, 0, 0x00B8074A))
             goto cleanup;
         SelectObject(hdc, hbsave);
-        DeleteObject(hbrtmp);
-        hbrtmp = 0;
     }
 
     if (flags & DSS_DISABLED)
     {
-        hbr = hbrtmp = CreateSolidBrush(GetSysColor(COLOR_3DSHADOW));
+        hbr = hbrtmp = GetSysColorBrush(COLOR_3DSHADOW);
         if(!hbrtmp)
             goto cleanup;
     }
@@ -1418,8 +1416,6 @@ cleanup:
         SelectObject(hdc, hbsave);
     if(hbmsave)
         SelectObject(memdc, hbmsave);
-    if(hbrtmp)
-        DeleteObject(hbrtmp);
     if(hbm)
         DeleteObject(hbm);
     if(memdc)
index 1853ab6..14a6155 100644 (file)
@@ -68,6 +68,10 @@ DtbgWindowProc(HWND Wnd,
     case WM_CLOSE:
         return 0;
 
+    case WM_DISPLAYCHANGE:
+        MoveWindow(Wnd, 0, 0, LOWORD(lParam), HIWORD(lParam), TRUE);
+        break;
+
     case WM_NOTIFY:
     {
         PPRIVATE_NOTIFY_DESKTOP nmh = (PPRIVATE_NOTIFY_DESKTOP)lParam;
index c6d4843..0764763 100644 (file)
@@ -9,9 +9,10 @@
        <include base="console">.</include>
        <compilerflag compilerset="gcc">-fms-extensions</compilerflag>
        <library>ntdll</library>
-       <library>user32</library>
-       <library>gdi32</library>
-       <library>advapi32</library>
+       <library delayimport="true">user32</library>
+       <library delayimport="true">gdi32</library>
+       <library delayimport="true">advapi32</library>
+       <library>delayimp</library>
        <library>win32ksys</library>
        <library>psapi</library>
        <library>pseh</library>
diff --git a/reactos/subsystems/win32/win32k/dib/alphablend.c b/reactos/subsystems/win32/win32k/dib/alphablend.c
new file mode 100644 (file)
index 0000000..be269cf
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * PROJECT:         Win32 subsystem
+ * LICENSE:         See COPYING in the top level directory
+ * FILE:            subsystems/win32/win32k/dib/stretchblt.c
+ * PURPOSE:         AlphaBlend implementation suitable for all bit depths
+ * PROGRAMMERS:     Jérôme Gardou
+ */
+
+#include <win32k.h>
+
+#define NDEBUG
+#include <debug.h>
+
+typedef union
+{
+  ULONG ul;
+  struct
+  {
+    UCHAR red;
+    UCHAR green;
+    UCHAR blue;
+    UCHAR alpha;
+  } col;
+} NICEPIXEL32;
+
+static __inline UCHAR
+Clamp8(ULONG val)
+{
+  return (val > 255) ? 255 : val;
+}
+
+BOOLEAN
+DIB_XXBPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
+                     RECTL* SourceRect, CLIPOBJ* ClipRegion,
+                     XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
+{
+  INT DstX, DstY, SrcX, SrcY;
+  BLENDFUNCTION BlendFunc;
+  register NICEPIXEL32 DstPixel32;
+  register NICEPIXEL32 SrcPixel32;
+  UCHAR Alpha, SrcBpp = BitsPerFormat(Source->iBitmapFormat);
+  EXLATEOBJ* pexlo;
+  EXLATEOBJ exloSrcRGB, exloDstRGB, exloRGBSrc;
+  PFN_DIB_PutPixel pfnDibPutPixel = DibFunctionsForBitmapFormat[Dest->iBitmapFormat].DIB_PutPixel;
+
+  DPRINT("DIB_16BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
+    SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
+    DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
+
+  BlendFunc = BlendObj->BlendFunction;
+  if (BlendFunc.BlendOp != AC_SRC_OVER)
+  {
+    DPRINT1("BlendOp != AC_SRC_OVER\n");
+    return FALSE;
+  }
+  if (BlendFunc.BlendFlags != 0)
+  {
+    DPRINT1("BlendFlags != 0\n");
+    return FALSE;
+  }
+  if ((BlendFunc.AlphaFormat & ~AC_SRC_ALPHA) != 0)
+  {
+    DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc.AlphaFormat);
+    return FALSE;
+  }
+  if ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0 &&
+    SrcBpp != 32)
+  {
+    DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
+    return FALSE;
+  }
+
+  if (!ColorTranslation)
+  {
+    DPRINT1("ColorTranslation must not be NULL!\n");
+    return FALSE;
+  }
+
+  pexlo = CONTAINING_RECORD(ColorTranslation, EXLATEOBJ, xlo);
+  EXLATEOBJ_vInitialize(&exloSrcRGB, pexlo->ppalSrc, &gpalRGB, 0, 0, 0);
+  EXLATEOBJ_vInitialize(&exloDstRGB, pexlo->ppalDst, &gpalRGB, 0, 0, 0);
+  EXLATEOBJ_vInitialize(&exloRGBSrc, &gpalRGB, pexlo->ppalSrc, 0, 0, 0);
+
+  SrcY = SourceRect->top;
+  DstY = DestRect->top;
+  while ( DstY < DestRect->bottom )
+  {
+    SrcX = SourceRect->left;
+    DstX = DestRect->left;
+    while(DstX < DestRect->right)
+    {
+      SrcPixel32.ul = DIB_GetSource(Source, SrcX, SrcY, &exloSrcRGB.xlo);
+      SrcPixel32.col.red = (SrcPixel32.col.red * BlendFunc.SourceConstantAlpha) / 255;
+      SrcPixel32.col.green = (SrcPixel32.col.green * BlendFunc.SourceConstantAlpha) / 255;
+      SrcPixel32.col.blue = (SrcPixel32.col.blue * BlendFunc.SourceConstantAlpha) / 255;
+
+      Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
+           (SrcPixel32.col.alpha * BlendFunc.SourceConstantAlpha) / 255 :
+           BlendFunc.SourceConstantAlpha ;
+
+      DstPixel32.ul = DIB_GetSource(Dest, DstX, DstY, &exloDstRGB.xlo);
+      DstPixel32.col.red = Clamp8((DstPixel32.col.red * (255 - Alpha)) / 255 + SrcPixel32.col.red) ;
+      DstPixel32.col.green = Clamp8((DstPixel32.col.green * (255 - Alpha)) / 255 + SrcPixel32.col.green) ;
+      DstPixel32.col.blue = Clamp8((DstPixel32.col.blue * (255 - Alpha)) / 255 + SrcPixel32.col.blue) ;
+      DstPixel32.ul = XLATEOBJ_iXlate(&exloRGBSrc.xlo, DstPixel32.ul);
+      pfnDibPutPixel(Dest, DstX, DstY, XLATEOBJ_iXlate(ColorTranslation, DstPixel32.ul));
+
+      DstX++;
+      SrcX = SourceRect->left + ((DstX-DestRect->left)*(SourceRect->right - SourceRect->left))
+                                            /(DestRect->right-DestRect->left);
+    }
+    DstY++;
+    SrcY = SourceRect->top + ((DstY-DestRect->top)*(SourceRect->bottom - SourceRect->top))
+                                            /(DestRect->bottom-DestRect->top);
+  }
+
+  EXLATEOBJ_vCleanup(&exloDstRGB);
+  EXLATEOBJ_vCleanup(&exloRGBSrc);
+  EXLATEOBJ_vCleanup(&exloSrcRGB);
+
+  return TRUE;
+}
+
index 30591d3..2066c9e 100644 (file)
@@ -29,25 +29,25 @@ DIB_FUNCTIONS DibFunctionsForBitmapFormat[] =
   {
     DIB_1BPP_PutPixel, DIB_1BPP_GetPixel, DIB_1BPP_HLine, DIB_1BPP_VLine,
     DIB_1BPP_BitBlt, DIB_1BPP_BitBltSrcCopy, DIB_XXBPP_StretchBlt,
-    DIB_1BPP_TransparentBlt, DIB_1BPP_ColorFill, DIB_1BPP_AlphaBlend
+    DIB_1BPP_TransparentBlt, DIB_1BPP_ColorFill, DIB_XXBPP_AlphaBlend
   },
   /* BMF_4BPP */
   {
     DIB_4BPP_PutPixel, DIB_4BPP_GetPixel, DIB_4BPP_HLine, DIB_4BPP_VLine,
     DIB_4BPP_BitBlt, DIB_4BPP_BitBltSrcCopy, DIB_XXBPP_StretchBlt,
-    DIB_4BPP_TransparentBlt, DIB_4BPP_ColorFill, DIB_4BPP_AlphaBlend
+    DIB_4BPP_TransparentBlt, DIB_4BPP_ColorFill, DIB_XXBPP_AlphaBlend
   },
   /* BMF_8BPP */
   {
     DIB_8BPP_PutPixel, DIB_8BPP_GetPixel, DIB_8BPP_HLine, DIB_8BPP_VLine,
     DIB_8BPP_BitBlt, DIB_8BPP_BitBltSrcCopy, DIB_XXBPP_StretchBlt,
-    DIB_8BPP_TransparentBlt, DIB_8BPP_ColorFill, DIB_8BPP_AlphaBlend
+    DIB_8BPP_TransparentBlt, DIB_8BPP_ColorFill, DIB_XXBPP_AlphaBlend
   },
   /* BMF_16BPP */
   {
     DIB_16BPP_PutPixel, DIB_16BPP_GetPixel, DIB_16BPP_HLine, DIB_16BPP_VLine,
     DIB_16BPP_BitBlt, DIB_16BPP_BitBltSrcCopy, DIB_XXBPP_StretchBlt,
-    DIB_16BPP_TransparentBlt, DIB_16BPP_ColorFill, DIB_16BPP_AlphaBlend
+    DIB_16BPP_TransparentBlt, DIB_16BPP_ColorFill, DIB_XXBPP_AlphaBlend
   },
   /* BMF_24BPP */
   {
index bae2199..4ae455b 100644 (file)
@@ -78,7 +78,6 @@ BOOLEAN DIB_1BPP_BitBlt(PBLTINFO);
 BOOLEAN DIB_1BPP_BitBltSrcCopy(PBLTINFO);
 BOOLEAN DIB_1BPP_TransparentBlt(SURFOBJ*,SURFOBJ*,RECTL*,RECTL*,XLATEOBJ*,ULONG);
 BOOLEAN DIB_1BPP_ColorFill(SURFOBJ*, RECTL*, ULONG);
-BOOLEAN DIB_1BPP_AlphaBlend(SURFOBJ*, SURFOBJ*, RECTL*, RECTL*, CLIPOBJ*, XLATEOBJ*, BLENDOBJ*);
 
 VOID DIB_4BPP_PutPixel(SURFOBJ*,LONG,LONG,ULONG);
 ULONG DIB_4BPP_GetPixel(SURFOBJ*,LONG,LONG);
@@ -88,7 +87,6 @@ BOOLEAN DIB_4BPP_BitBlt(PBLTINFO);
 BOOLEAN DIB_4BPP_BitBltSrcCopy(PBLTINFO);
 BOOLEAN DIB_4BPP_TransparentBlt(SURFOBJ*,SURFOBJ*,RECTL*,RECTL*,XLATEOBJ*,ULONG);
 BOOLEAN DIB_4BPP_ColorFill(SURFOBJ*, RECTL*, ULONG);
-BOOLEAN DIB_4BPP_AlphaBlend(SURFOBJ*, SURFOBJ*, RECTL*, RECTL*, CLIPOBJ*, XLATEOBJ*, BLENDOBJ*);
 
 VOID DIB_8BPP_PutPixel(SURFOBJ*,LONG,LONG,ULONG);
 ULONG DIB_8BPP_GetPixel(SURFOBJ*,LONG,LONG);
@@ -98,7 +96,6 @@ BOOLEAN DIB_8BPP_BitBlt(PBLTINFO);
 BOOLEAN DIB_8BPP_BitBltSrcCopy(PBLTINFO);
 BOOLEAN DIB_8BPP_TransparentBlt(SURFOBJ*,SURFOBJ*,RECTL*,RECTL*,XLATEOBJ*,ULONG);
 BOOLEAN DIB_8BPP_ColorFill(SURFOBJ*, RECTL*, ULONG);
-BOOLEAN DIB_8BPP_AlphaBlend(SURFOBJ*, SURFOBJ*, RECTL*, RECTL*, CLIPOBJ*, XLATEOBJ*, BLENDOBJ*);
 
 VOID DIB_16BPP_PutPixel(SURFOBJ*,LONG,LONG,ULONG);
 ULONG DIB_16BPP_GetPixel(SURFOBJ*,LONG,LONG);
@@ -108,7 +105,6 @@ BOOLEAN DIB_16BPP_BitBlt(PBLTINFO);
 BOOLEAN DIB_16BPP_BitBltSrcCopy(PBLTINFO);
 BOOLEAN DIB_16BPP_TransparentBlt(SURFOBJ*,SURFOBJ*,RECTL*,RECTL*,XLATEOBJ*,ULONG);
 BOOLEAN DIB_16BPP_ColorFill(SURFOBJ*, RECTL*, ULONG);
-BOOLEAN DIB_16BPP_AlphaBlend(SURFOBJ*, SURFOBJ*, RECTL*, RECTL*, CLIPOBJ*, XLATEOBJ*, BLENDOBJ*);
 
 VOID DIB_24BPP_PutPixel(SURFOBJ*,LONG,LONG,ULONG);
 ULONG DIB_24BPP_GetPixel(SURFOBJ*,LONG,LONG);
@@ -132,6 +128,7 @@ BOOLEAN DIB_32BPP_AlphaBlend(SURFOBJ*, SURFOBJ*, RECTL*, RECTL*, CLIPOBJ*, XLATE
 
 BOOLEAN DIB_XXBPP_StretchBlt(SURFOBJ*,SURFOBJ*,SURFOBJ*,SURFOBJ*,RECTL*,RECTL*,POINTL*,BRUSHOBJ*,POINTL*,XLATEOBJ*,ROP4);
 BOOLEAN DIB_XXBPP_FloodFillSolid(SURFOBJ*, BRUSHOBJ*, RECTL*, POINTL*, ULONG, UINT);
+BOOLEAN DIB_XXBPP_AlphaBlend(SURFOBJ*, SURFOBJ*, RECTL*, RECTL*, CLIPOBJ*, XLATEOBJ*, BLENDOBJ*);
 
 extern unsigned char notmask[2];
 extern unsigned char altnotmask[2];
index de56971..a1d72ae 100644 (file)
@@ -525,174 +525,4 @@ DIB_16BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
   return TRUE;
 }
 
-typedef union
-{
-  ULONG ul;
-  struct
-  {
-    UCHAR red;
-    UCHAR green;
-    UCHAR blue;
-    UCHAR alpha;
-  } col;
-} NICEPIXEL32;
-
-typedef union
-{
-  USHORT us;
-  struct
-  {
-    USHORT  red:5,
-    green:6,
-    blue:5;
-  } col;
-} NICEPIXEL16;
-
-static __inline UCHAR
-Clamp5(ULONG val)
-{
-  return (val > 31) ? 31 : val;
-}
-
-static __inline UCHAR
-Clamp8(ULONG val)
-{
-  return (val > 255) ? 255 : val;
-}
-
-static __inline UCHAR
-Clamp6(ULONG val)
-{
-  return (val > 63) ? 63 : val;
-}
-
-BOOLEAN
-DIB_16BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
-                     RECTL* SourceRect, CLIPOBJ* ClipRegion,
-                     XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
-{
-  INT Rows, Cols, SrcX, SrcY;
-  register PUSHORT Dst;
-  ULONG DstDelta;
-  BLENDFUNCTION BlendFunc;
-  register NICEPIXEL16 SrcPixel16;
-  register NICEPIXEL16 DstPixel16;
-  register NICEPIXEL32 SrcPixel32;
-  register NICEPIXEL32 DstPixel32;
-  UCHAR Alpha, SrcBpp;
-  EXLATEOBJ *pexlo;
-  EXLATEOBJ exloDst2Src;
-
-  DPRINT("DIB_16BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
-    SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
-    DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
-
-  ASSERT(DestRect->bottom - DestRect->top == SourceRect->bottom - SourceRect->top &&
-    DestRect->right - DestRect->left == SourceRect->right - SourceRect->left);
-
-  BlendFunc = BlendObj->BlendFunction;
-  if (BlendFunc.BlendOp != AC_SRC_OVER)
-  {
-    DPRINT1("BlendOp != AC_SRC_OVER\n");
-    return FALSE;
-  }
-  if (BlendFunc.BlendFlags != 0)
-  {
-    DPRINT1("BlendFlags != 0\n");
-    return FALSE;
-  }
-  if ((BlendFunc.AlphaFormat & ~AC_SRC_ALPHA) != 0)
-  {
-    DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc.AlphaFormat);
-    return FALSE;
-  }
-  if ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0 &&
-    BitsPerFormat(Source->iBitmapFormat) != 32)
-  {
-    DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
-    return FALSE;
-  }
-
-  if (!ColorTranslation)
-  {
-    DPRINT1("ColorTranslation must not be NULL!\n");
-    return FALSE;
-  }
-
-  pexlo = CONTAINING_RECORD(ColorTranslation, EXLATEOBJ, xlo);
-  EXLATEOBJ_vInitialize(&exloDst2Src, pexlo->ppalDst, pexlo->ppalSrc, 0, 0, 0);
-
-  Dst = (PUSHORT)((ULONG_PTR)Dest->pvScan0 + (DestRect->top * Dest->lDelta) +
-    (DestRect->left << 1));
-  DstDelta = Dest->lDelta - ((DestRect->right - DestRect->left) << 1);
-  SrcBpp = BitsPerFormat(Source->iBitmapFormat);
-
-  Rows = DestRect->bottom - DestRect->top;
-  SrcY = SourceRect->top;
-  while (--Rows >= 0)
-  {
-    Cols = DestRect->right - DestRect->left;
-    SrcX = SourceRect->left;
-    while (--Cols >= 0)
-    {
-      if (SrcBpp <= 16)
-      {
-        SrcPixel16.us = DIB_GetSource(Source, SrcX++, SrcY, ColorTranslation);
-        SrcPixel32.col.red = (SrcPixel16.col.red << 3);
-        SrcPixel32.col.green = (SrcPixel16.col.green << 2);
-        SrcPixel32.col.blue = (SrcPixel16.col.blue << 3);
-
-        SrcPixel32.col.red = SrcPixel32.col.red * BlendFunc.SourceConstantAlpha / 255;
-        SrcPixel32.col.green = SrcPixel32.col.green * BlendFunc.SourceConstantAlpha / 255;
-        SrcPixel32.col.blue = SrcPixel32.col.blue * BlendFunc.SourceConstantAlpha / 255;
-        SrcPixel32.col.alpha = (SrcBpp == 32) ?
-          (SrcPixel32.col.alpha * BlendFunc.SourceConstantAlpha / 255) :
-        BlendFunc.SourceConstantAlpha;
-
-        Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
-          SrcPixel32.col.alpha : BlendFunc.SourceConstantAlpha;
-
-        DstPixel16.us = *Dst;
-        DstPixel16.col.red = Clamp5(DstPixel16.col.red * (255 - Alpha) / 255 +
-          (SrcPixel32.col.red >> 3));
-
-        DstPixel16.col.green = Clamp6(DstPixel16.col.green * (255 - Alpha) / 255 +
-          (SrcPixel32.col.green >> 2));
-
-        DstPixel16.col.blue = Clamp5(DstPixel16.col.blue * (255 - Alpha) / 255 +
-          (SrcPixel32.col.blue >> 3));
-
-        *Dst++ = DstPixel16.us;
-      }
-      else
-      {
-        SrcPixel32.ul = DIB_GetSourceIndex(Source, SrcX++, SrcY);
-
-        SrcPixel32.col.red = SrcPixel32.col.red * BlendFunc.SourceConstantAlpha  / 255;
-        SrcPixel32.col.green = SrcPixel32.col.green * BlendFunc.SourceConstantAlpha  / 255;
-        SrcPixel32.col.blue = SrcPixel32.col.blue * BlendFunc.SourceConstantAlpha / 255;
-        SrcPixel32.col.alpha = (SrcBpp == 32) ?
-          (SrcPixel32.col.alpha * BlendFunc.SourceConstantAlpha / 255) :
-        BlendFunc.SourceConstantAlpha;
-
-        Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
-          SrcPixel32.col.alpha : BlendFunc.SourceConstantAlpha;
-
-        DstPixel32.ul = XLATEOBJ_iXlate(&exloDst2Src.xlo, *Dst);
-        SrcPixel32.col.red = Clamp8(DstPixel32.col.red * (255 - Alpha) / 255 + SrcPixel32.col.red);
-        SrcPixel32.col.green = Clamp8(DstPixel32.col.green * (255 - Alpha) / 255 + SrcPixel32.col.green);
-        SrcPixel32.col.blue = Clamp8(DstPixel32.col.blue * (255 - Alpha) / 255 +  SrcPixel32.col.blue);
-        *Dst++ = XLATEOBJ_iXlate(ColorTranslation, SrcPixel32.ul);
-      }
-    }
-
-    Dst = (PUSHORT)((ULONG_PTR)Dst + DstDelta);
-    SrcY++;
-  }
-
-  EXLATEOBJ_vCleanup(&exloDst2Src);
-
-  return TRUE;
-}
-
 /* EOF */
index 3686754..b924112 100644 (file)
@@ -33,7 +33,7 @@ DIB_1BPP_GetPixel(SURFOBJ *SurfObj, LONG x, LONG y)
 VOID
 DIB_1BPP_HLine(SURFOBJ *SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
 {
-  while(x1 < x2) 
+  while(x1 < x2)
   {
     DIB_1BPP_PutPixel(SurfObj, x1, y, c);
     x1++;
@@ -43,7 +43,7 @@ DIB_1BPP_HLine(SURFOBJ *SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
 VOID
 DIB_1BPP_VLine(SURFOBJ *SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
 {
-  while(y1 < y2) 
+  while(y1 < y2)
   {
     DIB_1BPP_PutPixel(SurfObj, x, y1, c);
     y1++;
@@ -474,13 +474,4 @@ DIB_1BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
   return FALSE;
 }
 
-BOOLEAN
-DIB_1BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
-                    RECTL* SourceRect, CLIPOBJ* ClipRegion,
-                    XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
 /* EOF */
index 3810024..0642862 100644 (file)
@@ -37,7 +37,7 @@ DIB_24BPP_VLine(SURFOBJ *SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
   LONG lDelta = SurfObj->lDelta;
 
   c &= 0xFFFFFF;
-  while(y1++ < y2) 
+  while(y1++ < y2)
   {
     *(PUSHORT)(addr) = c & 0xFFFF;
     *(addr + 2) = c >> 16;
@@ -466,7 +466,6 @@ DIB_24BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
 {
    INT Rows, Cols, SrcX, SrcY;
    register PUCHAR Dst;
-   ULONG DstDelta;
    BLENDFUNCTION BlendFunc;
    register NICEPIXEL32 DstPixel, SrcPixel;
    UCHAR Alpha, SrcBpp;
@@ -475,9 +474,6 @@ DIB_24BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
           SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
           DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
 
-   ASSERT(DestRect->bottom - DestRect->top == SourceRect->bottom - SourceRect->top &&
-          DestRect->right - DestRect->left == SourceRect->right - SourceRect->left);
-
    BlendFunc = BlendObj->BlendFunction;
    if (BlendFunc.BlendOp != AC_SRC_OVER)
    {
@@ -503,39 +499,41 @@ DIB_24BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
 
    Dst = (PUCHAR)((ULONG_PTR)Dest->pvScan0 + (DestRect->top * Dest->lDelta) +
                              (DestRect->left * 3));
-   DstDelta = Dest->lDelta - ((DestRect->right - DestRect->left) * 3);
    SrcBpp = BitsPerFormat(Source->iBitmapFormat);
 
-   Rows = DestRect->bottom - DestRect->top;
+   Rows = 0;
    SrcY = SourceRect->top;
-   while (--Rows >= 0)
-   {
-      Cols = DestRect->right - DestRect->left;
-      SrcX = SourceRect->left;
-      while (--Cols >= 0)
+   while (++Rows <= DestRect->bottom - DestRect->top)
+  {
+    Cols = 0;
+    SrcX = SourceRect->left;
+    while (++Cols <= DestRect->right - DestRect->left)
+    {
+      SrcPixel.ul = DIB_GetSource(Source, SrcX, SrcY, ColorTranslation);
+      SrcPixel.col.red = (SrcPixel.col.red * BlendFunc.SourceConstantAlpha) / 255;
+      SrcPixel.col.green = (SrcPixel.col.green * BlendFunc.SourceConstantAlpha) / 255;
+      SrcPixel.col.blue = (SrcPixel.col.blue * BlendFunc.SourceConstantAlpha) / 255;
+      if (!(BlendFunc.AlphaFormat & AC_SRC_ALPHA))
       {
-         SrcPixel.ul = DIB_GetSource(Source, SrcX++, SrcY, ColorTranslation);
-         SrcPixel.col.red = SrcPixel.col.red * BlendFunc.SourceConstantAlpha / 255;
-         SrcPixel.col.green = SrcPixel.col.green * BlendFunc.SourceConstantAlpha / 255;
-         SrcPixel.col.blue = SrcPixel.col.blue * BlendFunc.SourceConstantAlpha / 255;
-         SrcPixel.col.alpha = (SrcBpp == 32) ? (SrcPixel.col.alpha * BlendFunc.SourceConstantAlpha / 255) : BlendFunc.SourceConstantAlpha;
-
-         Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
-                 SrcPixel.col.alpha : BlendFunc.SourceConstantAlpha;
-
-         /* copy only 24bits of dst */
-         DstPixel.ul = *(PUSHORT)(Dst) + (*(Dst+2) << 16);
-         DstPixel.col.red = Clamp8(DstPixel.col.red * (255 - Alpha) / 255 + SrcPixel.col.red);
-         DstPixel.col.green = Clamp8(DstPixel.col.green * (255 - Alpha) / 255 + SrcPixel.col.green);
-         DstPixel.col.blue = Clamp8(DstPixel.col.blue * (255 - Alpha) / 255 + SrcPixel.col.blue);
-         /* copy back 24bits of result */
-         *(PUSHORT)(Dst) = (USHORT)(DstPixel.ul & 0xFFFF);
-         *(Dst + 2) = (UCHAR)((DstPixel.ul >> 16) & 0xFF);
-         Dst = (PUCHAR)((ULONG_PTR)Dst + 3);
+          Alpha = BlendFunc.SourceConstantAlpha ;
       }
-      Dst = (PUCHAR)((ULONG_PTR)Dst + DstDelta);
-      SrcY++;
-   }
+      else
+      {
+        Alpha = (SrcPixel.col.alpha * BlendFunc.SourceConstantAlpha) / 255;
+      }
+
+      DstPixel.col.red = Clamp8((*Dst * (255 - Alpha)) / 255 + SrcPixel.col.red) ;
+      DstPixel.col.green = Clamp8((*(Dst+1) * (255 - Alpha) / 255 + SrcPixel.col.green)) ;
+      DstPixel.col.blue = Clamp8((*(Dst+2) * (255 - Alpha)) / 255 + SrcPixel.col.blue) ;
+      *Dst++ = DstPixel.col.red;
+      *Dst++ = DstPixel.col.green;
+      *Dst++ = DstPixel.col.blue;
+      SrcX = SourceRect->left + (Cols*(SourceRect->right - SourceRect->left))/(DestRect->right - DestRect->left);
+    }
+    Dst = (PUCHAR)((ULONG_PTR)Dest->pvScan0 + ((DestRect->top + Rows) * Dest->lDelta) +
+                (DestRect->left*3));
+    SrcY = SourceRect->top + (Rows*(SourceRect->bottom - SourceRect->top))/(DestRect->bottom - DestRect->top);
+  }
 
    return TRUE;
 }
index 6c4704b..50c8193 100644 (file)
@@ -54,8 +54,8 @@ DIB_32BPP_BitBltSrcCopy(PBLTINFO BltInfo)
   PBYTE    SourceBits_4BPP, SourceLine_4BPP;
   PDWORD   Source32, Dest32;
 
-  DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 
-    + (BltInfo->DestRect.top * BltInfo->DestSurface->lDelta) 
+  DestBits = (PBYTE)BltInfo->DestSurface->pvScan0
+    + (BltInfo->DestRect.top * BltInfo->DestSurface->lDelta)
     + 4 * BltInfo->DestRect.left;
 
   switch (BltInfo->SourceSurface->iBitmapFormat)
@@ -83,8 +83,8 @@ DIB_32BPP_BitBltSrcCopy(PBLTINFO BltInfo)
     break;
 
   case BMF_4BPP:
-    SourceBits_4BPP = (PBYTE)BltInfo->SourceSurface->pvScan0 
-      + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) 
+    SourceBits_4BPP = (PBYTE)BltInfo->SourceSurface->pvScan0
+      + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
       + (BltInfo->SourcePoint.x >> 1);
 
     for (j=BltInfo->DestRect.top; j<BltInfo->DestRect.bottom; j++)
@@ -156,8 +156,8 @@ DIB_32BPP_BitBltSrcCopy(PBLTINFO BltInfo)
     break;
 
   case BMF_24BPP:
-    SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0 
-      + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta) 
+    SourceLine = (PBYTE)BltInfo->SourceSurface->pvScan0
+      + (BltInfo->SourcePoint.y * BltInfo->SourceSurface->lDelta)
       + 3 * BltInfo->SourcePoint.x;
     DestLine = DestBits;
 
@@ -182,7 +182,7 @@ DIB_32BPP_BitBltSrcCopy(PBLTINFO BltInfo)
     break;
 
   case BMF_32BPP:
-    if (NULL == BltInfo->XlateSourceToDest || 
+    if (NULL == BltInfo->XlateSourceToDest ||
       0 != (BltInfo->XlateSourceToDest->flXlate & XO_TRIVIAL))
     {
       if (BltInfo->DestRect.top < BltInfo->SourcePoint.y)
@@ -197,10 +197,10 @@ DIB_32BPP_BitBltSrcCopy(PBLTINFO BltInfo)
       }
       else
       {
-        SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0 
-          + ((BltInfo->SourcePoint.y 
-          + BltInfo->DestRect.bottom 
-          - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta) 
+        SourceBits = (PBYTE)BltInfo->SourceSurface->pvScan0
+          + ((BltInfo->SourcePoint.y
+          + BltInfo->DestRect.bottom
+          - BltInfo->DestRect.top - 1) * BltInfo->SourceSurface->lDelta)
           + 4 * BltInfo->SourcePoint.x;
         DestBits = (PBYTE)BltInfo->DestSurface->pvScan0 + ((BltInfo->DestRect.bottom - 1) * BltInfo->DestSurface->lDelta) + 4 * BltInfo->DestRect.left;
         for (j = BltInfo->DestRect.bottom - 1; BltInfo->DestRect.top <= j; j--)
@@ -348,7 +348,6 @@ DIB_32BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
 {
   INT Rows, Cols, SrcX, SrcY;
   register PULONG Dst;
-  ULONG DstDelta;
   BLENDFUNCTION BlendFunc;
   register NICEPIXEL32 DstPixel, SrcPixel;
   UCHAR Alpha, SrcBpp;
@@ -357,9 +356,6 @@ DIB_32BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
     SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
     DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
 
-  ASSERT(DestRect->bottom - DestRect->top == SourceRect->bottom - SourceRect->top &&
-    DestRect->right - DestRect->left == SourceRect->right - SourceRect->left);
-
   BlendFunc = BlendObj->BlendFunction;
   if (BlendFunc.BlendOp != AC_SRC_OVER)
   {
@@ -385,35 +381,38 @@ DIB_32BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
 
   Dst = (PULONG)((ULONG_PTR)Dest->pvScan0 + (DestRect->top * Dest->lDelta) +
     (DestRect->left << 2));
-  DstDelta = Dest->lDelta - ((DestRect->right - DestRect->left) << 2);
   SrcBpp = BitsPerFormat(Source->iBitmapFormat);
 
-  Rows = DestRect->bottom - DestRect->top;
-  SrcY = SourceRect->top;
-  while (--Rows >= 0)
+  Rows = 0;
+   SrcY = SourceRect->top;
+   while (++Rows <= DestRect->bottom - DestRect->top)
   {
-    Cols = DestRect->right - DestRect->left;
+    Cols = 0;
     SrcX = SourceRect->left;
-    while (--Cols >= 0)
+    while (++Cols <= DestRect->right - DestRect->left)
     {
-      SrcPixel.ul = DIB_GetSource(Source, SrcX++, SrcY, ColorTranslation);
-      SrcPixel.col.red = SrcPixel.col.red * BlendFunc.SourceConstantAlpha / 255;
-      SrcPixel.col.green = SrcPixel.col.green * BlendFunc.SourceConstantAlpha / 255;
-      SrcPixel.col.blue = SrcPixel.col.blue * BlendFunc.SourceConstantAlpha / 255;
-      SrcPixel.col.alpha = (SrcBpp == 32) ? (SrcPixel.col.alpha * BlendFunc.SourceConstantAlpha / 255) : BlendFunc.SourceConstantAlpha;
+      SrcPixel.ul = DIB_GetSource(Source, SrcX, SrcY, ColorTranslation);
+      SrcPixel.col.red = (SrcPixel.col.red * BlendFunc.SourceConstantAlpha) / 255;
+      SrcPixel.col.green = (SrcPixel.col.green * BlendFunc.SourceConstantAlpha)  / 255;
+      SrcPixel.col.blue = (SrcPixel.col.blue * BlendFunc.SourceConstantAlpha) / 255;
+      SrcPixel.col.alpha = (32 == SrcBpp) ?
+                        (SrcPixel.col.alpha * BlendFunc.SourceConstantAlpha) / 255 :
+                        BlendFunc.SourceConstantAlpha ;
 
       Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
-        SrcPixel.col.alpha : BlendFunc.SourceConstantAlpha;
+           SrcPixel.col.alpha : BlendFunc.SourceConstantAlpha ;
 
       DstPixel.ul = *Dst;
-      DstPixel.col.red = Clamp8(DstPixel.col.red * (255 - Alpha) / 255 + SrcPixel.col.red);
-      DstPixel.col.green = Clamp8(DstPixel.col.green * (255 - Alpha) / 255 + SrcPixel.col.green);
-      DstPixel.col.blue = Clamp8(DstPixel.col.blue * (255 - Alpha) / 255 + SrcPixel.col.blue);
-      DstPixel.col.alpha = Clamp8(DstPixel.col.alpha * (255 - Alpha) / 255 + SrcPixel.col.alpha);
+      DstPixel.col.red = Clamp8((DstPixel.col.red * (255 - Alpha)) / 255 + SrcPixel.col.red) ;
+      DstPixel.col.green = Clamp8((DstPixel.col.green * (255 - Alpha)) / 255 + SrcPixel.col.green) ;
+      DstPixel.col.blue = Clamp8((DstPixel.col.blue * (255 - Alpha)) / 255 + SrcPixel.col.blue) ;
+      DstPixel.col.alpha = Clamp8((DstPixel.col.alpha * (255 - Alpha)) / 255 + SrcPixel.col.alpha) ;
       *Dst++ = DstPixel.ul;
+      SrcX = SourceRect->left + (Cols*(SourceRect->right - SourceRect->left))/(DestRect->right - DestRect->left);
     }
-    Dst = (PULONG)((ULONG_PTR)Dst + DstDelta);
-    SrcY++;
+    Dst = (PULONG)((ULONG_PTR)Dest->pvScan0 + ((DestRect->top + Rows) * Dest->lDelta) +
+                (DestRect->left << 2));
+    SrcY = SourceRect->top + (Rows*(SourceRect->bottom - SourceRect->top))/(DestRect->bottom - DestRect->top);
   }
 
   return TRUE;
index 1626b8e..e27c226 100644 (file)
@@ -32,7 +32,7 @@ DIB_4BPP_HLine(SURFOBJ *SurfObj, LONG x1, LONG x2, LONG y, ULONG c)
   PBYTE  addr = (PBYTE)SurfObj->pvScan0 + (x1>>1) + y * SurfObj->lDelta;
   LONG  cx = x1;
 
-  while(cx < x2) 
+  while(cx < x2)
   {
     *addr = (*addr & notmask[x1&1]) | (c << ((1-(x1&1))<<2));
     if((++x1 & 1) == 0)
@@ -48,7 +48,7 @@ DIB_4BPP_VLine(SURFOBJ *SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
   int  lDelta = SurfObj->lDelta;
 
   addr += (x>>1) + y1 * lDelta;
-  while(y1++ < y2) 
+  while(y1++ < y2)
   {
     *addr = (*addr & notmask[x&1]) | (c << ((1-(x&1))<<2));
     addr += lDelta;
@@ -81,8 +81,8 @@ DIB_4BPP_BitBltSrcCopy(PBLTINFO BltInfo)
           if(DIB_1BPP_GetPixel(BltInfo->SourceSurface, sx, sy) == 0)
           {
             DIB_4BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 0));
-          } 
-          else 
+          }
+          else
           {
             DIB_4BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 1));
           }
@@ -375,13 +375,4 @@ DIB_4BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
   return FALSE;
 }
 
-BOOLEAN
-DIB_4BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
-                    RECTL* SourceRect, CLIPOBJ* ClipRegion,
-                    XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
-{
-  UNIMPLEMENTED;
-  return FALSE;
-}
-
 /* EOF */
index 3fac604..e13331c 100644 (file)
@@ -43,7 +43,7 @@ DIB_8BPP_VLine(SURFOBJ *SurfObj, LONG x, LONG y1, LONG y2, ULONG c)
   LONG lDelta = SurfObj->lDelta;
 
   byteaddr = addr;
-  while(y1++ < y2) 
+  while(y1++ < y2)
   {
     *addr = c;
 
@@ -74,8 +74,8 @@ DIB_8BPP_BitBltSrcCopy(PBLTINFO BltInfo)
           if(DIB_1BPP_GetPixel(BltInfo->SourceSurface, sx, sy) == 0)
           {
             DIB_8BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 0));
-          } 
-          else 
+          }
+          else
           {
             DIB_8BPP_PutPixel(BltInfo->DestSurface, i, j, XLATEOBJ_iXlate(BltInfo->XlateSourceToDest, 1));
           }
@@ -362,130 +362,4 @@ DIB_8BPP_TransparentBlt(SURFOBJ *DestSurf, SURFOBJ *SourceSurf,
   return TRUE;
 }
 
-typedef union {
-  ULONG ul;
-  struct {
-    UCHAR red;
-    UCHAR green;
-    UCHAR blue;
-    UCHAR alpha;
-  } col;
-} NICEPIXEL32;
-
-typedef union {
-  USHORT us;
-  struct {
-    USHORT red:5,
-    green:6,
-    blue:5;
-  } col;
-} NICEPIXEL16;
-
-static __inline UCHAR
-Clamp8(ULONG val)
-{
-  return (val > 255) ? 255 : val;
-}
-
-BOOLEAN
-DIB_8BPP_AlphaBlend(SURFOBJ* Dest, SURFOBJ* Source, RECTL* DestRect,
-                    RECTL* SourceRect, CLIPOBJ* ClipRegion,
-                    XLATEOBJ* ColorTranslation, BLENDOBJ* BlendObj)
-{
-  INT Rows, Cols, SrcX, SrcY;
-  register PUCHAR Dst;
-  ULONG DstDelta;
-  BLENDFUNCTION BlendFunc;
-  register NICEPIXEL32 DstPixel32;
-  register NICEPIXEL32 SrcPixel32;
-  register NICEPIXEL16 SrcPixel16;
-  UCHAR Alpha, SrcBpp;
-  EXLATEOBJ exloDst2Src;
-  EXLATEOBJ* pexlo;
-
-  DPRINT("DIB_8BPP_AlphaBlend: srcRect: (%d,%d)-(%d,%d), dstRect: (%d,%d)-(%d,%d)\n",
-    SourceRect->left, SourceRect->top, SourceRect->right, SourceRect->bottom,
-    DestRect->left, DestRect->top, DestRect->right, DestRect->bottom);
-
-  ASSERT(DestRect->bottom - DestRect->top == SourceRect->bottom - SourceRect->top &&
-    DestRect->right - DestRect->left == SourceRect->right - SourceRect->left);
-
-  BlendFunc = BlendObj->BlendFunction;
-  if (BlendFunc.BlendOp != AC_SRC_OVER)
-  {
-    DPRINT1("BlendOp != AC_SRC_OVER\n");
-    return FALSE;
-  }
-  if (BlendFunc.BlendFlags != 0)
-  {
-    DPRINT1("BlendFlags != 0\n");
-    return FALSE;
-  }
-  if ((BlendFunc.AlphaFormat & ~AC_SRC_ALPHA) != 0)
-  {
-    DPRINT1("Unsupported AlphaFormat (0x%x)\n", BlendFunc.AlphaFormat);
-    return FALSE;
-  }
-  if ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0 &&
-    BitsPerFormat(Source->iBitmapFormat) != 32)
-  {
-    DPRINT1("Source bitmap must be 32bpp when AC_SRC_ALPHA is set\n");
-    return FALSE;
-  }
-  if (!ColorTranslation)
-  {
-    DPRINT1("ColorTranslation must not be NULL!\n");
-    return FALSE;
-  }
-
-  pexlo = CONTAINING_RECORD(ColorTranslation, EXLATEOBJ, xlo);
-  EXLATEOBJ_vInitialize(&exloDst2Src, pexlo->ppalDst, pexlo->ppalSrc, 0, 0, 0);
-
-  Dst = (PUCHAR)((ULONG_PTR)Dest->pvScan0 + (DestRect->top * Dest->lDelta) +
-    DestRect->left);
-  DstDelta = Dest->lDelta - (DestRect->right - DestRect->left);
-  SrcBpp = BitsPerFormat(Source->iBitmapFormat);
-
-  Rows = DestRect->bottom - DestRect->top;
-  SrcY = SourceRect->top;
-  while (--Rows >= 0)
-  {
-    Cols = DestRect->right - DestRect->left;
-    SrcX = SourceRect->left;
-    while (--Cols >= 0)
-    {
-      if (SrcBpp <= 16)
-      {
-        SrcPixel16.us = DIB_GetSource(Source, SrcX++, SrcY, ColorTranslation);
-        SrcPixel32.col.red = (SrcPixel16.col.red << 3) | (SrcPixel16.col.red >> 2);
-        SrcPixel32.col.green = (SrcPixel16.col.green << 2) | (SrcPixel16.col.green >> 4);
-        SrcPixel32.col.blue = (SrcPixel16.col.blue << 3) | (SrcPixel16.col.blue >> 2);
-      }
-      else
-      {
-        SrcPixel32.ul = DIB_GetSourceIndex(Source, SrcX++, SrcY);
-      }
-      SrcPixel32.col.red = SrcPixel32.col.red * BlendFunc.SourceConstantAlpha / 255;
-      SrcPixel32.col.green = SrcPixel32.col.green * BlendFunc.SourceConstantAlpha / 255;
-      SrcPixel32.col.blue = SrcPixel32.col.blue * BlendFunc.SourceConstantAlpha / 255;
-      SrcPixel32.col.alpha = (SrcBpp == 32) ? (SrcPixel32.col.alpha * BlendFunc.SourceConstantAlpha / 255) : BlendFunc.SourceConstantAlpha;
-
-      Alpha = ((BlendFunc.AlphaFormat & AC_SRC_ALPHA) != 0) ?
-        SrcPixel32.col.alpha : BlendFunc.SourceConstantAlpha;
-
-      DstPixel32.ul = XLATEOBJ_iXlate(&exloDst2Src.xlo, *Dst);
-      SrcPixel32.col.red = Clamp8(DstPixel32.col.red * (255 - Alpha) / 255 + SrcPixel32.col.red);
-      SrcPixel32.col.green = Clamp8(DstPixel32.col.green * (255 - Alpha) / 255 + SrcPixel32.col.green);
-      SrcPixel32.col.blue = Clamp8(DstPixel32.col.blue * (255 - Alpha) / 255 +  SrcPixel32.col.blue);
-      *Dst++ = XLATEOBJ_iXlate(ColorTranslation, SrcPixel32.ul);
-    }
-    Dst = (PUCHAR)((ULONG_PTR)Dst + DstDelta);
-    SrcY++;
-  }
-
-  EXLATEOBJ_vCleanup(&exloDst2Src);
-
-  return TRUE;
-}
-
 /* EOF */
index 34b2930..afd1b5e 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
  * COPYRIGHT:        See COPYING in the top level directory
  * PROJECT:          ReactOS kernel
  * PURPOSE:          GDI alpha blending functions
@@ -25,10 +25,6 @@ EngAlphaBlend(IN SURFOBJ *psoDest,
               IN PRECTL SourceRect,
               IN BLENDOBJ *BlendObj)
 {
-    RECTL              SourceStretchedRect;
-    SIZEL              SourceStretchedSize;
-    HBITMAP            SourceStretchedBitmap = 0;
-    SURFOBJ*           SourceStretchedObj = NULL;
     RECTL              InputRect;
     RECTL              OutputRect;
     RECTL              ClipRect;
@@ -39,7 +35,6 @@ EngAlphaBlend(IN SURFOBJ *psoDest,
     INTENG_ENTER_LEAVE EnterLeaveDest;
     SURFOBJ*           InputObj;
     SURFOBJ*           OutputObj;
-    LONG               Width;
     LONG               ClippingType;
     RECT_ENUM          RectEnum;
     BOOL               EnumMore;
@@ -71,7 +66,7 @@ EngAlphaBlend(IN SURFOBJ *psoDest,
     InputRect = *SourceRect;
     if ( (InputRect.top < 0) || (InputRect.bottom < 0) ||
          (InputRect.left < 0) || (InputRect.right < 0) ||
-         InputRect.right > psoSource->sizlBitmap.cx || 
+         InputRect.right > psoSource->sizlBitmap.cx ||
          InputRect.bottom > psoSource->sizlBitmap.cy )
     {
         SetLastWin32Error(ERROR_INVALID_PARAMETER);
@@ -111,68 +106,9 @@ EngAlphaBlend(IN SURFOBJ *psoDest,
         return TRUE;
     }
 
-    /* Stretch source if needed */
-    if (OutputRect.right - OutputRect.left != InputRect.right - InputRect.left ||
-            OutputRect.bottom - OutputRect.top != InputRect.bottom - InputRect.top)
-    {
-        SourceStretchedSize.cx = OutputRect.right - OutputRect.left;
-        SourceStretchedSize.cy = OutputRect.bottom - OutputRect.top;
-        Width = DIB_GetDIBWidthBytes(SourceStretchedSize.cx, BitsPerFormat(psoSource->iBitmapFormat));
-        /* FIXME: Maybe it is a good idea to use EngCreateDeviceBitmap and IntEngStretchBlt
-                  if possible to get a HW accelerated stretch. */
-        SourceStretchedBitmap = EngCreateBitmap(SourceStretchedSize, Width, psoSource->iBitmapFormat,
-                                                BMF_TOPDOWN | BMF_NOZEROINIT, NULL);
-        if (SourceStretchedBitmap == 0)
-        {
-            DPRINT1("EngCreateBitmap failed!\n");
-            return FALSE;
-        }
-        SourceStretchedObj = EngLockSurface((HSURF)SourceStretchedBitmap);
-        if (SourceStretchedObj == NULL)
-        {
-            DPRINT1("EngLockSurface failed!\n");
-            EngDeleteSurface((HSURF)SourceStretchedBitmap);
-            return FALSE;
-        }
-
-        SourceStretchedRect.left = 0;
-        SourceStretchedRect.right = SourceStretchedSize.cx;
-        SourceStretchedRect.top = 0;
-        SourceStretchedRect.bottom = SourceStretchedSize.cy;
-        /* FIXME: IntEngStretchBlt isn't used here atm because it results in a
-                  try to acquire an already acquired mutex (lock the already locked source surface) */
-        /*if (!IntEngStretchBlt(SourceStretchedObj, psoSource, NULL, NULL,
-                              NULL, &SourceStretchedRect, SourceRect, NULL,
-                              NULL, NULL, COLORONCOLOR))*/
-        if (!EngStretchBlt(SourceStretchedObj, psoSource, NULL, NULL, NULL,
-                           NULL, NULL, &SourceStretchedRect, &InputRect,
-                           NULL, COLORONCOLOR))
-        {
-            DPRINT1("EngStretchBlt failed!\n");
-            EngFreeMem(SourceStretchedObj->pvBits);
-            EngUnlockSurface(SourceStretchedObj);
-            EngDeleteSurface((HSURF)SourceStretchedBitmap);
-            return FALSE;
-        }
-        InputRect.top = SourceStretchedRect.top;
-        InputRect.bottom = SourceStretchedRect.bottom;
-        InputRect.left = SourceStretchedRect.left;
-        InputRect.right = SourceStretchedRect.right;
-        psoSource = SourceStretchedObj;
-    }
-
     /* Now call the DIB function */
     if (!IntEngEnter(&EnterLeaveSource, psoSource, &InputRect, TRUE, &Translate, &InputObj))
     {
-        if (SourceStretchedObj != NULL)
-        {
-            EngFreeMem(SourceStretchedObj->pvBits);
-            EngUnlockSurface(SourceStretchedObj);
-        }
-        if (SourceStretchedBitmap != 0)
-        {
-            EngDeleteSurface((HSURF)SourceStretchedBitmap);
-        }
         return FALSE;
     }
     InputRect.left +=  Translate.x;
@@ -182,16 +118,6 @@ EngAlphaBlend(IN SURFOBJ *psoDest,
 
     if (!IntEngEnter(&EnterLeaveDest, psoDest, &OutputRect, FALSE, &Translate, &OutputObj))
     {
-        IntEngLeave(&EnterLeaveSource);
-        if (SourceStretchedObj != NULL)
-        {
-            EngFreeMem(SourceStretchedObj->pvBits);
-            EngUnlockSurface(SourceStretchedObj);
-        }
-        if (SourceStretchedBitmap != 0)
-        {
-            EngDeleteSurface((HSURF)SourceStretchedBitmap);
-        }
         return FALSE;
     }
     OutputRect.left += Translate.x;
@@ -261,16 +187,6 @@ EngAlphaBlend(IN SURFOBJ *psoDest,
     IntEngLeave(&EnterLeaveDest);
     IntEngLeave(&EnterLeaveSource);
 
-    if (SourceStretchedObj != NULL)
-    {
-        EngFreeMem(SourceStretchedObj->pvBits);
-        EngUnlockSurface(SourceStretchedObj);
-    }
-    if (SourceStretchedBitmap != 0)
-    {
-        EngDeleteSurface((HSURF)SourceStretchedBitmap);
-    }
-
     return Ret;
 }
 
@@ -305,17 +221,8 @@ IntEngAlphaBlend(IN SURFOBJ *psoDest,
         return TRUE;
     }
 
-    SURFACE_LockBitmapBits(psurfDest);
-    MouseSafetyOnDrawStart(psoDest, DestRect->left, DestRect->top,
-                           DestRect->right, DestRect->bottom);
-
-    if (psoSource != psoDest)
-        SURFACE_LockBitmapBits(psurfSource);
-    MouseSafetyOnDrawStart(psoSource, SourceRect->left, SourceRect->top,
-                           SourceRect->right, SourceRect->bottom);
-
     /* Call the driver's DrvAlphaBlend if available */
-    if (psurfDest->flHooks & HOOK_ALPHABLEND)
+    if (psurfDest->flags & HOOK_ALPHABLEND)
     {
         ret = GDIDEVFUNCS(psoDest).AlphaBlend(
                   psoDest, psoSource, ClipRegion, ColorTranslation,
@@ -328,12 +235,6 @@ IntEngAlphaBlend(IN SURFOBJ *psoDest,
                             DestRect, SourceRect, BlendObj);
     }
 
-    MouseSafetyOnDrawEnd(psoSource);
-    if (psoSource != psoDest)
-        SURFACE_UnlockBitmapBits(psurfSource);
-    MouseSafetyOnDrawEnd(psoDest);
-    SURFACE_UnlockBitmapBits(psurfDest);
-
     return ret;
 }
 
index b74e890..e6dd497 100644 (file)
@@ -522,7 +522,7 @@ EngBitBlt(SURFOBJ *DestObj,
 }
 
 BOOL APIENTRY
-IntEngBitBltEx(
+IntEngBitBlt(
     SURFOBJ *psoTrg,
     SURFOBJ *psoSrc,
     SURFOBJ *psoMask,
@@ -533,8 +533,7 @@ IntEngBitBltEx(
     POINTL *pptlMask,
     BRUSHOBJ *pbo,
     POINTL *pptlBrush,
-    ROP4 rop4,
-    BOOL bRemoveMouse)
+    ROP4 rop4)
 {
     SURFACE *psurfTrg;
     SURFACE *psurfSrc = NULL;
@@ -583,28 +582,11 @@ IntEngBitBltEx(
         psurfSrc = NULL;
     }
 
-    if (bRemoveMouse)
-    {
-        SURFACE_LockBitmapBits(psurfTrg);
-
-        if (psoSrc)
-        {
-            if (psoSrc != psoTrg)
-            {
-                SURFACE_LockBitmapBits(psurfSrc);
-            }
-            MouseSafetyOnDrawStart(psoSrc, rclSrc.left, rclSrc.top,
-                                   rclSrc.right, rclSrc.bottom);
-        }
-        MouseSafetyOnDrawStart(psoTrg, rclClipped.left, rclClipped.top,
-                               rclClipped.right, rclClipped.bottom);
-    }
-
     /* Is the target surface device managed? */
-    if (psurfTrg->flHooks & HOOK_BITBLT)
+    if (psurfTrg->flags & HOOK_BITBLT)
     {
         /* Is the source a different device managed surface? */
-        if (psoSrc && psoSrc->hdev != psoTrg->hdev && psurfSrc->flHooks & HOOK_BITBLT)
+        if (psoSrc && psoSrc->hdev != psoTrg->hdev && psurfSrc->flags & HOOK_BITBLT)
         {
             DPRINT1("Need to copy to standard bitmap format!\n");
             ASSERT(FALSE);
@@ -614,7 +596,7 @@ IntEngBitBltEx(
     }
 
     /* Is the source surface device managed? */
-    else if (psoSrc && psurfSrc->flHooks & HOOK_BITBLT)
+    else if (psoSrc && psurfSrc->flags & HOOK_BITBLT)
     {
         pfnBitBlt = GDIDEVFUNCS(psoSrc).BitBlt;
     }
@@ -637,21 +619,6 @@ IntEngBitBltEx(
 
     // FIXME: cleanup temp surface!
 
-    if (bRemoveMouse)
-    {
-        MouseSafetyOnDrawEnd(psoTrg);
-        if (psoSrc)
-        {
-            MouseSafetyOnDrawEnd(psoSrc);
-            if (psoSrc != psoTrg)
-            {
-                SURFACE_UnlockBitmapBits(psurfSrc);
-            }
-        }
-
-        SURFACE_UnlockBitmapBits(psurfTrg);
-    }
-
     return bResult;
 }
 
@@ -983,27 +950,20 @@ IntEngMaskBlt(SURFOBJ *psoDest,
     ASSERT(psoDest);
     psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
 
-    SURFACE_LockBitmapBits(psurfDest);
-    MouseSafetyOnDrawStart(psoDest, OutputRect.left, OutputRect.top,
-                           OutputRect.right, OutputRect.bottom);
-
     /* Dummy BitBlt to let driver know that it should flush its changes.
        This should really be done using a call to DrvSynchronizeSurface,
        but the VMware driver doesn't hook that call. */
-    IntEngBitBltEx(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
+    IntEngBitBlt(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
                    DestRect, pptlMask, pptlMask, pbo, BrushOrigin,
-                   R4_NOOP, FALSE);
+                   R4_NOOP);
 
     ret = EngMaskBitBlt(psoDest, psoMask, ClipRegion, DestColorTranslation, SourceColorTranslation,
                         &OutputRect, &InputPoint, pbo, BrushOrigin);
 
     /* Dummy BitBlt to let driver know that something has changed. */
-    IntEngBitBltEx(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
+    IntEngBitBlt(psoDest, NULL, psoMask, ClipRegion, DestColorTranslation,
                    DestRect, pptlMask, pptlMask, pbo, BrushOrigin,
-                   R4_NOOP, FALSE);
-
-    MouseSafetyOnDrawEnd(psoDest);
-    SURFACE_UnlockBitmapBits(psurfDest);
+                   R4_NOOP);
 
     return ret;
 }
index 73a477d..afb2f16 100644 (file)
@@ -53,13 +53,7 @@ EngCopyBits(SURFOBJ *psoDest,
     ASSERT(psoDest != NULL && psoSource != NULL && DestRect != NULL && SourcePoint != NULL);
 
     psurfSource = CONTAINING_RECORD(psoSource, SURFACE, SurfObj);
-    SURFACE_LockBitmapBits(psurfSource);
-
     psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
-    if (psoDest != psoSource)
-    {
-        SURFACE_LockBitmapBits(psurfDest);
-    }
 
     // FIXME: Don't punt to the driver's DrvCopyBits immediately. Instead,
     //        mark the copy block function to be DrvCopyBits instead of the
@@ -73,7 +67,7 @@ EngCopyBits(SURFOBJ *psoDest,
         if (psoDest->iType!=STYPE_BITMAP)
         {
             /* FIXME: Eng* functions shouldn't call Drv* functions. ? */
-            if (psurfDest->flHooks & HOOK_COPYBITS)
+            if (psurfDest->flags & HOOK_COPYBITS)
             {
                 ret = GDIDEVFUNCS(psoDest).CopyBits(
                           psoDest, psoSource, Clip, ColorTranslation, DestRect, SourcePoint);
@@ -86,7 +80,7 @@ EngCopyBits(SURFOBJ *psoDest,
         if (psoSource->iType!=STYPE_BITMAP)
         {
             /* FIXME: Eng* functions shouldn't call Drv* functions. ? */
-            if (psurfSource->flHooks & HOOK_COPYBITS)
+            if (psurfSource->flags & HOOK_COPYBITS)
             {
                 ret = GDIDEVFUNCS(psoSource).CopyBits(
                           psoDest, psoSource, Clip, ColorTranslation, DestRect, SourcePoint);
@@ -180,12 +174,6 @@ EngCopyBits(SURFOBJ *psoDest,
     }
 
 cleanup:
-    if (psoDest != psoSource)
-    {
-        SURFACE_UnlockBitmapBits(psurfDest);
-    }
-    SURFACE_UnlockBitmapBits(psurfSource);
-
     return ret;
 }
 
@@ -198,20 +186,7 @@ IntEngCopyBits(
     RECTL *prclDest,
     POINTL *ptlSource)
 {
-    BOOL bResult;
-
-    MouseSafetyOnDrawStart(psoSource, ptlSource->x, ptlSource->y,
-                           (ptlSource->x + abs(prclDest->right - prclDest->left)),
-                           (ptlSource->y + abs(prclDest->bottom - prclDest->top)));
-
-    MouseSafetyOnDrawStart(psoDest, prclDest->left, prclDest->top, prclDest->right, prclDest->bottom);
-
-    bResult = EngCopyBits(psoDest, psoSource, pco, pxlo, prclDest, ptlSource);
-
-    MouseSafetyOnDrawEnd(psoDest);
-    MouseSafetyOnDrawEnd(psoSource);
-
-    return bResult;
+    return EngCopyBits(psoDest, psoSource, pco, pxlo, prclDest, ptlSource);
 }
 
 
index 0e51ea0..0965a96 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
+PGRAPHICS_DEVICE gpPrimaryGraphicsDevice;
+PGRAPHICS_DEVICE gpVgaGraphicsDevice;
+
+static PGRAPHICS_DEVICE gpGraphicsDeviceFirst = NULL;
+static PGRAPHICS_DEVICE gpGraphicsDeviceLast = NULL;
+static HSEMAPHORE ghsemGraphicsDeviceList;
+static ULONG giDevNum = 1;
+
+BOOL
+NTAPI
+InitDeviceImpl()
+{
+    ghsemGraphicsDeviceList = EngCreateSemaphore();
+    if (!ghsemGraphicsDeviceList)
+        return FALSE;
+
+    return TRUE;
+}
+
+
+PGRAPHICS_DEVICE
+NTAPI
+EngpRegisterGraphicsDevice(
+    PUNICODE_STRING pustrDeviceName,
+    PUNICODE_STRING pustrDiplayDrivers,
+    PUNICODE_STRING pustrDescription,
+    PDEVMODEW pdmDefault)
+{
+    PGRAPHICS_DEVICE pGraphicsDevice;
+    PDEVICE_OBJECT pDeviceObject;
+    PFILE_OBJECT pFileObject;
+    NTSTATUS Status;
+    PWSTR pwsz;
+    ULONG i, cj, cModes = 0;
+    BOOL bEnable = TRUE;
+    PDEVMODEINFO pdminfo;
+    PDEVMODEW pdm, pdmEnd;
+    PLDEVOBJ pldev;
+
+    DPRINT1("EngpRegisterGraphicsDevice(%S)\n", pustrDeviceName->Buffer);
+
+    /* Allocate a GRAPHICS_DEVICE structure */
+    pGraphicsDevice = ExAllocatePoolWithTag(PagedPool,
+                                            sizeof(GRAPHICS_DEVICE),
+                                            GDITAG_GDEVICE);
+    if (!pGraphicsDevice)
+    {
+        DPRINT1("ExAllocatePoolWithTag failed\n");
+        return NULL;
+    }
+
+    /* Try to open the driver */
+    Status = IoGetDeviceObjectPointer(pustrDeviceName,
+                                      FILE_READ_DATA | FILE_WRITE_DATA,
+                                      &pFileObject,
+                                      &pDeviceObject);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Could not open driver, 0x%lx\n", Status);
+        ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
+        return NULL;
+    }
+
+    /* Enable the device */
+    EngFileWrite(pFileObject, &bEnable, sizeof(BOOL), &cj);
+
+    /* Copy the device and file object pointers */
+    pGraphicsDevice->DeviceObject = pDeviceObject;
+    pGraphicsDevice->FileObject = pFileObject;
+
+    /* Copy device name */
+    wcsncpy(pGraphicsDevice->szNtDeviceName,
+            pustrDeviceName->Buffer,
+            sizeof(pGraphicsDevice->szNtDeviceName) / sizeof(WCHAR));
+
+    /* Create a win device name (FIXME: virtual devices!) */
+    swprintf(pGraphicsDevice->szWinDeviceName, L"\\\\.\\VIDEO%d", (CHAR)giDevNum);
+
+    /* Allocate a buffer for the strings */
+    cj = pustrDiplayDrivers->Length + pustrDescription->Length + sizeof(WCHAR);
+    pwsz = ExAllocatePoolWithTag(PagedPool, cj, GDITAG_DRVSUP);
+    if (!pwsz)
+    {
+        DPRINT1("Could not allocate string buffer\n");
+        ASSERT(FALSE); // FIXME
+    }
+
+    /* Copy display driver names */
+    pGraphicsDevice->pDiplayDrivers = pwsz;
+    RtlCopyMemory(pGraphicsDevice->pDiplayDrivers,
+                  pustrDiplayDrivers->Buffer,
+                  pustrDiplayDrivers->Length);
+
+    /* Copy description */
+    pGraphicsDevice->pwszDescription = pwsz + pustrDiplayDrivers->Length / sizeof(WCHAR);
+    RtlCopyMemory(pGraphicsDevice->pwszDescription,
+                  pustrDescription->Buffer,
+                  pustrDescription->Length + sizeof(WCHAR));
+
+    /* Initialize the pdevmodeInfo list and default index  */
+    pGraphicsDevice->pdevmodeInfo = NULL;
+    pGraphicsDevice->iDefaultMode = 0;
+    pGraphicsDevice->iCurrentMode = 0;
+
+    // FIXME: initialize state flags
+    pGraphicsDevice->StateFlags = 0;
+
+    /* Loop through the driver names
+     * This is a REG_MULTI_SZ string */
+    for (; *pwsz; pwsz += wcslen(pwsz) + 1)
+    {
+        DPRINT1("trying driver: %ls\n", pwsz);
+        /* Try to load the display driver */
+        pldev = EngLoadImageEx(pwsz, LDEV_DEVICE_DISPLAY);
+        if (!pldev)
+        {
+            DPRINT1("Could not load driver: '%ls'\n", pwsz);
+            continue;
+        }
+
+        /* Get the mode list from the driver */
+        pdminfo = LDEVOBJ_pdmiGetModes(pldev, pDeviceObject);
+        if (!pdminfo)
+        {
+            DPRINT1("Could not get mode list for '%ls'\n", pwsz);
+            continue;
+        }
+
+        /* Attach the mode info to the device */
+        pdminfo->pdmiNext = pGraphicsDevice->pdevmodeInfo;
+        pGraphicsDevice->pdevmodeInfo = pdminfo;
+
+        /* Count DEVMODEs */
+        pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode);
+        for (pdm = pdminfo->adevmode;
+             pdm + 1 <= pdmEnd;
+             pdm = (DEVMODEW*)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
+        {
+            cModes++;
+        }
+
+        // FIXME: release the driver again until it's used?
+    }
+
+    if (!pGraphicsDevice->pdevmodeInfo || cModes == 0)
+    {
+        DPRINT1("No devmodes\n");
+        ExFreePool(pGraphicsDevice);
+        return NULL;
+    }
+
+    /* Allocate an index buffer */
+    pGraphicsDevice->cDevModes = cModes;
+    pGraphicsDevice->pDevModeList = ExAllocatePoolWithTag(PagedPool,
+                                                          cModes * sizeof(DEVMODEENTRY),
+                                                          GDITAG_GDEVICE);
+    if (!pGraphicsDevice->pDevModeList)
+    {
+        DPRINT1("No devmode list\n");
+        ExFreePool(pGraphicsDevice);
+        return NULL;
+    }
+
+    /* Loop through all DEVMODEINFOs */
+    for (pdminfo = pGraphicsDevice->pdevmodeInfo, i = 0;
+         pdminfo;
+         pdminfo = pdminfo->pdmiNext)
+    {
+        /* Calculate End of the DEVMODEs */
+        pdmEnd = (DEVMODEW*)((PCHAR)pdminfo->adevmode + pdminfo->cbdevmode);
+
+        /* Loop through the DEVMODEs */
+        for (pdm = pdminfo->adevmode;
+             pdm + 1 <= pdmEnd;
+             pdm = (PDEVMODEW)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
+        {
+            /* Compare with the default entry */
+            if (pdm->dmBitsPerPel == pdmDefault->dmBitsPerPel &&
+                pdm->dmPelsWidth == pdmDefault->dmPelsWidth &&
+                pdm->dmPelsHeight == pdmDefault->dmPelsHeight &&
+                pdm->dmDisplayFrequency == pdmDefault->dmDisplayFrequency)
+            {
+                pGraphicsDevice->iDefaultMode = i;
+                pGraphicsDevice->iCurrentMode = i;
+                DPRINT1("Found default entry: %ld '%ls'\n", i, pdm->dmDeviceName);
+            }
+
+            /* Initialize the entry */
+            pGraphicsDevice->pDevModeList[i].dwFlags = 0;
+            pGraphicsDevice->pDevModeList[i].pdm = pdm;
+            i++;
+        }
+     }
+
+    /* Lock loader */
+    EngAcquireSemaphore(ghsemGraphicsDeviceList);
+
+    /* Insert the device into the global list */
+    pGraphicsDevice->pNextGraphicsDevice = gpGraphicsDeviceLast;
+    gpGraphicsDeviceLast = pGraphicsDevice;
+    if (!gpGraphicsDeviceFirst)
+        gpGraphicsDeviceFirst = pGraphicsDevice;
+
+    /* Increment device number */
+    giDevNum++;
+
+    /* Unlock loader */
+    EngReleaseSemaphore(ghsemGraphicsDeviceList);
+    DPRINT1("Prepared %ld modes for %ls\n", cModes, pGraphicsDevice->pwszDescription);
+
+    return pGraphicsDevice;
+}
+
+
+PGRAPHICS_DEVICE
+NTAPI
+EngpFindGraphicsDevice(
+    PUNICODE_STRING pustrDevice,
+    ULONG iDevNum,
+    DWORD dwFlags)
+{
+    UNICODE_STRING ustrCurrent;
+    PGRAPHICS_DEVICE pGraphicsDevice;
+    ULONG i;
+
+    /* Lock list */
+    EngAcquireSemaphore(ghsemGraphicsDeviceList);
+
+    if (pustrDevice)
+    {
+        /* Loop through the list of devices */
+        for (pGraphicsDevice = gpGraphicsDeviceFirst;
+             pGraphicsDevice;
+             pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice)
+        {
+            /* Compare the device name */
+            RtlInitUnicodeString(&ustrCurrent, pGraphicsDevice->szWinDeviceName);
+            if (RtlEqualUnicodeString(&ustrCurrent, pustrDevice, FALSE))
+            {
+                break;
+            }
+        }
+    }
+    else
+    {
+        /* Loop through the list of devices */
+        for (pGraphicsDevice = gpGraphicsDeviceFirst, i = 0;
+             pGraphicsDevice && i < iDevNum;
+             pGraphicsDevice = pGraphicsDevice->pNextGraphicsDevice, i++);
+    }
+
+    /* Unlock list */
+    EngReleaseSemaphore(ghsemGraphicsDeviceList);
+
+    return pGraphicsDevice;
+}
+
+
 static
 NTSTATUS
 EngpFileIoRequest(
@@ -39,7 +297,7 @@ EngpFileIoRequest(
     /* Initialize an event */
     KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
 
-    /* Build IPR */
+    /* Build IRP */
     liStartOffset.QuadPart = ullStartOffset;
     pIrp = IoBuildSynchronousFsdRequest(ulMajorFunction,
                                         pDeviceObject,
@@ -113,7 +371,7 @@ EngFileIoControl(
     /* Initialize an event */
     KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
 
-    /* Build IO control IPR */
+    /* Build IO control IRP */
     pIrp = IoBuildDeviceIoControlRequest(dwIoControlCode,
                                          pDeviceObject,
                                          lpInBuffer,
index a13d11b..c61e0e4 100644 (file)
@@ -18,8 +18,6 @@ VOID
 NTAPI
 EBRUSHOBJ_vInit(EBRUSHOBJ *pebo, PBRUSH pbrush, PDC pdc)
 {
-    HPALETTE hpal = NULL;
-
     ASSERT(pebo);
     ASSERT(pbrush);
     ASSERT(pdc);
@@ -35,14 +33,11 @@ EBRUSHOBJ_vInit(EBRUSHOBJ *pebo, PBRUSH pbrush, PDC pdc)
     pebo->crCurrentText = pdc->pdcattr->crForegroundClr;
 
     pebo->psurfTrg = pdc->dclevel.pSurface;
-//    ASSERT(pebo->psurfTrg); // FIXME: some dcs don't have a surface
+    ASSERT(pebo->psurfTrg);
+    ASSERT(pebo->psurfTrg->ppal);
 
-    if (pebo->psurfTrg)
-        hpal = pebo->psurfTrg->hDIBPalette;
-    if (!hpal) hpal = pPrimarySurface->devinfo.hpalDefault;
-    pebo->ppalSurf = PALETTE_ShareLockPalette(hpal);
-    if (!pebo->ppalSurf)
-        pebo->ppalSurf = &gpalRGB;
+    pebo->ppalSurf = pebo->psurfTrg->ppal;
+    GDIOBJ_IncrementShareCount(&pebo->ppalSurf->BaseObject);
 
     if (pbrush->flAttrs & GDIBRUSH_IS_NULL)
     {
@@ -80,7 +75,12 @@ EBRUSHOBJ_vSetSolidBrushColor(EBRUSHOBJ *pebo, COLORREF crColor)
     pebo->ulRGBColor = crColor;
 
     /* Initialize an XLATEOBJ RGB -> surface */
-    EXLATEOBJ_vInitialize(&exlo, &gpalRGB, pebo->ppalSurf, 0, 0, 0);
+    EXLATEOBJ_vInitialize(&exlo,
+                          &gpalRGB,
+                          pebo->ppalSurf,
+                          pebo->crCurrentBack,
+                          0,
+                          0);
 
     /* Translate the brush color to the target format */
     iSolidColor = XLATEOBJ_iXlate(&exlo.xlo, crColor);
@@ -109,8 +109,7 @@ EBRUSHOBJ_vCleanup(EBRUSHOBJ *pebo)
         pebo->BrushObject.pvRbrush = NULL;
     }
 
-    if (pebo->ppalSurf != &gpalRGB)
-        PALETTE_ShareUnlockPalette(pebo->ppalSurf);
+    PALETTE_ShareUnlockPalette(pebo->ppalSurf);
 }
 
 VOID
@@ -145,7 +144,7 @@ EngRealizeBrush(
     ULONG lWidth;
 
     /* Calculate width in bytes of the realized brush */
-    lWidth = DIB_GetDIBWidthBytes(psoPattern->sizlBitmap.cx,
+    lWidth = WIDTH_BYTES_ALIGN32(psoPattern->sizlBitmap.cx,
                                   BitsPerFormat(psoDst->iBitmapFormat));
 
     /* Allocate a bitmap */
@@ -192,12 +191,8 @@ EBRUSHOBJ_bRealizeBrush(EBRUSHOBJ *pebo, BOOL bCallDriver)
     PPDEVOBJ ppdev = NULL;
     EXLATEOBJ exlo;
 
-    // FIXME: all EBRUSHOBJs need a surface, see EBRUSHOBJ_vInit
-    if (!pebo->psurfTrg)
-    {
-        DPRINT1("Pattern brush has no target surface!\n");
-        return FALSE;
-    }
+    /* All EBRUSHOBJs have a surface, see EBRUSHOBJ_vInit */
+    ASSERT(pebo->psurfTrg);
 
     ppdev = (PPDEVOBJ)pebo->psurfTrg->SurfObj.hdev;
 
@@ -210,16 +205,18 @@ EBRUSHOBJ_bRealizeBrush(EBRUSHOBJ *pebo, BOOL bCallDriver)
 
     psurfPattern = SURFACE_ShareLockSurface(pebo->pbrush->hbmPattern);
     ASSERT(psurfPattern);
+    ASSERT(psurfPattern->ppal);
 
     /* FIXME: implement mask */
     psurfMask = NULL;
 
     /* Initialize XLATEOBJ for the brush */
-    EXLATEOBJ_vInitBrushXlate(&exlo,
-                              pebo->pbrush,
-                              pebo->psurfTrg,
-                              pebo->crCurrentText,
-                              pebo->crCurrentBack);
+    EXLATEOBJ_vInitialize(&exlo, 
+                          psurfPattern->ppal,
+                          pebo->psurfTrg->ppal,
+                          0,
+                          pebo->crCurrentBack,
+                          pebo->crCurrentText);
 
     /* Create the realization */
     bResult = pfnRealzizeBrush(&pebo->BrushObject,
index af544c9..31ea864 100644 (file)
@@ -56,7 +56,7 @@ IntEngEnter(PINTENG_ENTER_LEAVE EnterLeave,
     {
     /* Driver needs to support DrvCopyBits, else we can't do anything */
     SURFACE *psurfDest = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
-    if (!(psurfDest->flHooks & HOOK_COPYBITS))
+    if (!(psurfDest->flags & HOOK_COPYBITS))
     {
       return FALSE;
     }
@@ -64,7 +64,7 @@ IntEngEnter(PINTENG_ENTER_LEAVE EnterLeave,
     /* Allocate a temporary bitmap */
     BitmapSize.cx = DestRect->right - DestRect->left;
     BitmapSize.cy = DestRect->bottom - DestRect->top;
-    Width = DIB_GetDIBWidthBytes(BitmapSize.cx, BitsPerFormat(psoDest->iBitmapFormat));
+    Width = WIDTH_BYTES_ALIGN32(BitmapSize.cx, BitsPerFormat(psoDest->iBitmapFormat));
     EnterLeave->OutputBitmap = EngCreateBitmap(BitmapSize, Width,
                                                psoDest->iBitmapFormat,
                                                BMF_TOPDOWN | BMF_NOZEROINIT, NULL);
@@ -127,7 +127,6 @@ IntEngEnter(PINTENG_ENTER_LEAVE EnterLeave,
                                         &ClippedDestRect, &SrcPoint))
       {
           EngDeleteClip(EnterLeave->TrivialClipObj);
-          EngFreeMem((*ppsoOutput)->pvBits);
           EngUnlockSurface(*ppsoOutput);
           EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
           return FALSE;
@@ -149,7 +148,7 @@ IntEngEnter(PINTENG_ENTER_LEAVE EnterLeave,
   if (NULL != *ppsoOutput)
   {
     SURFACE* psurfOutput = CONTAINING_RECORD(*ppsoOutput, SURFACE, SurfObj);
-    if (0 != (psurfOutput->flHooks & HOOK_SYNCHRONIZE))
+    if (0 != (psurfOutput->flags & HOOK_SYNCHRONIZE))
     {
       if (NULL != GDIDEVFUNCS(*ppsoOutput).SynchronizeSurface)
         {
@@ -219,7 +218,6 @@ IntEngLeave(PINTENG_ENTER_LEAVE EnterLeave)
           Result = TRUE;
         }
       }
-    EngFreeMem(EnterLeave->OutputObj->pvBits);
     EngUnlockSurface(EnterLeave->OutputObj);
     EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
     EngDeleteClip(EnterLeave->TrivialClipObj);
index c3ef653..75faeae 100644 (file)
@@ -548,14 +548,7 @@ IntEngGradientFill(
   psurf = CONTAINING_RECORD(psoDest, SURFACE, SurfObj);
   ASSERT(psurf);
 
-  SURFACE_LockBitmapBits(psurf);
-  MouseSafetyOnDrawStart(
-         psoDest,
-         pco->rclBounds.left,
-         pco->rclBounds.top,
-      pco->rclBounds.right,
-         pco->rclBounds.bottom);
-  if(psurf->flHooks & HOOK_GRADIENTFILL)
+  if(psurf->flags & HOOK_GRADIENTFILL)
   {
     Ret = GDIDEVFUNCS(psoDest).GradientFill(
       psoDest, pco, pxlo, pVertex, nVertex, pMesh, nMesh,
@@ -566,8 +559,6 @@ IntEngGradientFill(
     Ret = EngGradientFill(psoDest, pco, pxlo, pVertex, nVertex, pMesh, nMesh, prclExtents,
                           pptlDitherOrg, ulMode);
   }
-  MouseSafetyOnDrawEnd(psoDest);
-  SURFACE_UnlockBitmapBits(psurf);
 
   return Ret;
 }
diff --git a/reactos/subsystems/win32/win32k/eng/ldevobj.c b/reactos/subsystems/win32/win32k/eng/ldevobj.c
new file mode 100644 (file)
index 0000000..6296a01
--- /dev/null
@@ -0,0 +1,504 @@
+/*
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * PURPOSE:          Support for logical devices
+ * FILE:             subsystems/win32/win32k/eng/ldevobj.c
+ * PROGRAMER:        Timo Kreuzer (timo.kreuzer@reactos.org)
+ */
+
+#include <win32k.h>
+
+#include <intrin.h>
+
+#define NDEBUG
+#include <debug.h>
+
+#ifndef RVA_TO_ADDR
+#define RVA_TO_ADDR(Base,Rva) ((PVOID)(((ULONG_PTR)(Base)) + (Rva)))
+#endif
+
+/** Globals *******************************************************************/
+
+HSEMAPHORE ghsemLDEVList;
+LDEVOBJ *gpldevHead = NULL;
+LDEVOBJ *gpldevWin32k = NULL;
+
+
+/** Private functions *********************************************************/
+
+BOOL
+NTAPI
+InitLDEVImpl()
+{
+    /* Initialize the loader lock */
+    ghsemLDEVList = EngCreateSemaphore();
+    if (!ghsemLDEVList)
+    {
+        return FALSE;
+    }
+
+    /* Allocate a LDEVOBJ for win32k */
+    gpldevWin32k = ExAllocatePoolWithTag(PagedPool,
+                                         sizeof(LDEVOBJ) +
+                                         sizeof(SYSTEM_GDI_DRIVER_INFORMATION),
+                                         GDITAG_LDEV);
+    if (!gpldevWin32k)
+    {
+        return FALSE;
+    }
+
+    /* Initialize the LDEVOBJ for win32k */
+    gpldevWin32k->pldevNext = NULL;
+    gpldevWin32k->pldevPrev = NULL;
+    gpldevWin32k->ldevtype = LDEV_DEVICE_DISPLAY;
+    gpldevWin32k->cRefs = 1;
+    gpldevWin32k->ulDriverVersion = GDI_ENGINE_VERSION;
+    gpldevWin32k->pGdiDriverInfo = (PVOID)(gpldevWin32k + 1);
+    RtlInitUnicodeString(&gpldevWin32k->pGdiDriverInfo->DriverName,
+                         L"\\SystemRoot\\System32\\win32k.sys");
+    gpldevWin32k->pGdiDriverInfo->ImageAddress = &__ImageBase;
+    gpldevWin32k->pGdiDriverInfo->SectionPointer = NULL;
+    gpldevWin32k->pGdiDriverInfo->EntryPoint = (PVOID)DriverEntry;
+    gpldevWin32k->pGdiDriverInfo->ExportSectionPointer = NULL;
+    gpldevWin32k->pGdiDriverInfo->ImageLength = 0; // FIXME;
+
+    return TRUE;
+}
+
+PLDEVOBJ
+NTAPI
+LDEVOBJ_AllocLDEV(LDEVTYPE ldevtype)
+{
+    PLDEVOBJ pldev;
+
+    /* Allocate the structure from paged pool */
+    pldev = ExAllocatePoolWithTag(PagedPool, sizeof(LDEVOBJ), GDITAG_LDEV);
+    if (!pldev)
+    {
+        DPRINT1("Failed to allocate LDEVOBJ.\n");
+        return NULL;
+    }
+
+    /* Zero out the structure */
+    RtlZeroMemory(pldev, sizeof(LDEVOBJ));
+
+    /* Set the ldevtype */
+    pldev->ldevtype = ldevtype;
+
+    return pldev;
+}
+
+VOID
+NTAPI
+LDEVOBJ_vFreeLDEV(PLDEVOBJ pldev)
+{
+    /* Make sure we don't have a driver loaded */
+    ASSERT(pldev && pldev->pGdiDriverInfo == NULL);
+
+    /* Free the memory */
+    ExFreePoolWithTag(pldev, TAG_LDEV);
+}
+
+PDEVMODEINFO
+NTAPI
+LDEVOBJ_pdmiGetModes(
+    PLDEVOBJ pldev,
+    HANDLE hDriver)
+{
+    ULONG cbSize, cbFull;
+    PDEVMODEINFO pdminfo;
+
+    DPRINT("LDEVOBJ_pdmiGetModes(%p, %p)\n", pldev, hDriver);
+
+    /* Call the driver to get the required size */
+    cbSize = pldev->pfn.GetModes(hDriver, 0, NULL);
+    if (!cbSize)
+    {
+        DPRINT1("DrvGetModes returned 0\n");
+        return NULL;
+    }
+
+    /* Add space for the header */
+    cbFull = cbSize + FIELD_OFFSET(DEVMODEINFO, adevmode);
+
+    /* Allocate a buffer for the DEVMODE array */
+    pdminfo = ExAllocatePoolWithTag(PagedPool, cbFull, GDITAG_DEVMODE);
+    if (!pdminfo)
+    {
+        DPRINT1("Could not allocate devmodeinfo\n");
+        return NULL;
+    }
+
+    pdminfo->pldev = pldev;
+    pdminfo->cbdevmode = cbSize;
+
+    /* Call the driver again to fill the buffer */
+    cbSize = pldev->pfn.GetModes(hDriver, cbSize, pdminfo->adevmode);
+    if (!cbSize)
+    {
+        /* Could not get modes */
+        DPRINT1("returned size %ld(%ld)\n", cbSize, pdminfo->cbdevmode);
+        ExFreePool(pdminfo);
+        pdminfo = NULL;
+    }
+
+    return pdminfo;
+}
+
+
+BOOL
+NTAPI
+LDEVOBJ_bLoadImage(
+    IN PLDEVOBJ pldev,
+    PUNICODE_STRING pstrPathName)
+{
+    PSYSTEM_GDI_DRIVER_INFORMATION pDriverInfo;
+    NTSTATUS Status;
+    ULONG cbSize;
+
+    /* Make sure no image is loaded yet */
+    ASSERT(pldev && pldev->pGdiDriverInfo == NULL);
+
+    /* Allocate a SYSTEM_GDI_DRIVER_INFORMATION structure */
+    cbSize = sizeof(SYSTEM_GDI_DRIVER_INFORMATION) + pstrPathName->Length;
+    pDriverInfo = ExAllocatePoolWithTag(PagedPool, cbSize, GDITAG_LDEV);
+    if (!pDriverInfo)
+    {
+        DPRINT1("Failed to allocate SYSTEM_GDI_DRIVER_INFORMATION\n");
+        return FALSE;
+    }
+
+    /* Initialize the UNICODE_STRING and copy the driver name */
+    RtlInitEmptyUnicodeString(&pDriverInfo->DriverName,
+                              (PWSTR)(pDriverInfo + 1),
+                              pstrPathName->Length);
+    RtlCopyUnicodeString(&pDriverInfo->DriverName, pstrPathName);
+
+    /* Try to load the driver */
+    Status = ZwSetSystemInformation(SystemLoadGdiDriverInformation,
+                                    pDriverInfo,
+                                    sizeof(SYSTEM_GDI_DRIVER_INFORMATION));
+
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to load a GDI driver: '%S', Status = 0x%lx\n", 
+                pstrPathName->Buffer, Status);
+
+        /* Free the allocated memory */
+        ExFreePoolWithTag(pDriverInfo, TAG_LDEV);
+        return FALSE;
+    }
+
+    /* Set the driver info */
+    pldev->pGdiDriverInfo = pDriverInfo;
+
+    /* Return success. */
+    return TRUE;
+}
+
+VOID
+NTAPI
+LDEVOBJ_vUnloadImage(
+    IN PLDEVOBJ pldev)
+{
+    NTSTATUS Status;
+
+    /* Make sure we have a driver info */
+    ASSERT(pldev && pldev->pGdiDriverInfo != NULL);
+
+    /* Check if we have loaded a driver */
+    if (pldev->pfn.DisableDriver)
+    {
+        /* Call the unload function */
+        pldev->pfn.DisableDriver();
+    }
+
+    /* Unload the driver */
+    Status = ZwSetSystemInformation(SystemUnloadGdiDriverInformation,
+                                    &pldev->pGdiDriverInfo->ImageAddress,
+                                    sizeof(HANDLE));
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to unload the driver, this is bad.\n");
+    }
+
+    /* Free the driver info structure */
+    ExFreePoolWithTag(pldev->pGdiDriverInfo, GDITAG_LDEV);
+    pldev->pGdiDriverInfo = NULL;
+}
+
+BOOL
+NTAPI
+LDEVOBJ_bLoadDriver(
+    IN PLDEVOBJ pldev)
+{
+    PFN_DrvEnableDriver pfnEnableDriver;
+    DRVENABLEDATA ded;
+    ULONG i;
+
+    /* Make sure we have a driver info */
+    ASSERT(pldev && pldev->pGdiDriverInfo != NULL);
+
+    /* Call the drivers DrvEnableDriver function */
+    RtlZeroMemory(&ded, sizeof(ded));
+    pfnEnableDriver = pldev->pGdiDriverInfo->EntryPoint;
+    if (!pfnEnableDriver(GDI_ENGINE_VERSION, sizeof(ded), &ded))
+    {
+        DPRINT1("DrvEnableDriver failed\n");
+
+        /* Unload the image. */
+        LDEVOBJ_vUnloadImage(pldev);
+        return FALSE;
+    }
+
+    /* Copy the returned driver version */
+    pldev->ulDriverVersion = ded.iDriverVersion;
+
+    /* Fill the driver function array */
+    for (i = 0; i < ded.c; i++)
+    {
+        pldev->apfn[ded.pdrvfn[i].iFunc] = ded.pdrvfn[i].pfn;
+    }
+
+    /* Return success. */
+    return TRUE;
+}
+
+
+PVOID
+NTAPI
+LDEVOBJ_pvFindImageProcAddress(
+    IN PLDEVOBJ pldev,
+    IN LPSTR    pszProcName)
+{
+    PVOID pvImageBase;
+    PIMAGE_EXPORT_DIRECTORY pExportDir;
+    PVOID pvProcAdress = NULL;
+    PUSHORT pOrdinals;
+    PULONG pNames, pAddresses;
+    ULONG i, cbSize;
+
+    /* Make sure we have a driver info */
+    ASSERT(pldev && pldev->pGdiDriverInfo != NULL);
+
+    /* Get the pointer to the export directory */
+    pvImageBase = pldev->pGdiDriverInfo->ImageAddress;
+    pExportDir = RtlImageDirectoryEntryToData(pvImageBase,
+                                              TRUE,
+                                              IMAGE_DIRECTORY_ENTRY_EXPORT,
+                                              &cbSize);
+    if (!pExportDir)
+    {
+        return NULL;
+    }
+
+    /* Get pointers to some tables */
+    pNames = RVA_TO_ADDR(pvImageBase, pExportDir->AddressOfNames);
+    pOrdinals = RVA_TO_ADDR(pvImageBase, pExportDir->AddressOfNameOrdinals);
+    pAddresses = RVA_TO_ADDR(pvImageBase, pExportDir->AddressOfFunctions);
+
+    /* Loop the export table */
+    for (i = 0; i < pExportDir->NumberOfNames; i++)
+    {
+        /* Compare the name */
+        if (_stricmp(pszProcName, RVA_TO_ADDR(pvImageBase, pNames[i])) == 0)
+        {
+            /* Found! Calculate the procedure address */
+            pvProcAdress = RVA_TO_ADDR(pvImageBase, pAddresses[pOrdinals[i]]);
+            break;
+        }
+    }
+
+    /* Return the address */
+    return pvProcAdress;
+}
+
+PLDEVOBJ
+NTAPI
+EngLoadImageEx(
+    LPWSTR pwszDriverName,
+    ULONG ldevtype)
+{
+    WCHAR acwBuffer[MAX_PATH];
+    PLDEVOBJ pldev;
+    UNICODE_STRING strDriverName;
+    ULONG cwcLength;
+    LPWSTR pwsz;
+
+    DPRINT("EngLoadImageEx(%ls, %ld)\n", pwszDriverName, ldevtype);
+    ASSERT(pwszDriverName);
+
+    /* Initialize buffer for the the driver name */
+    RtlInitEmptyUnicodeString(&strDriverName, acwBuffer, sizeof(acwBuffer));
+
+    /* Start path with systemroot */
+    RtlAppendUnicodeToString(&strDriverName, L"\\SystemRoot\\System32\\");
+
+    /* Get Length of given string */
+    cwcLength = wcslen(pwszDriverName);
+
+    /* Check if we have a system32 path given */
+    pwsz = pwszDriverName + cwcLength;
+    while (pwsz > pwszDriverName)
+    {
+        if (_wcsnicmp(pwsz, L"\\system32\\", 10) == 0)
+        {
+            /* Driver name starts after system32 */
+            pwsz += 10;
+            break;
+        }
+        pwsz--;
+    }
+
+    /* Append the driver name */
+    RtlAppendUnicodeToString(&strDriverName, pwsz);
+
+    /* MSDN says "The driver must include this suffix in the pwszDriver string."
+       But in fact it's optional. */
+    if (_wcsnicmp(pwszDriverName + cwcLength - 4, L".dll", 4) != 0)
+    {
+        /* Append the .dll suffix */
+        RtlAppendUnicodeToString(&strDriverName, L".dll");
+    }
+
+    /* Lock loader */
+    EngAcquireSemaphore(ghsemLDEVList);
+
+    /* Search the List of LDEVS for the driver name */
+    for (pldev = gpldevHead; pldev != NULL; pldev = pldev->pldevNext)
+    {
+        /* Check if the ldev is associated with a file */
+        if (pldev->pGdiDriverInfo)
+        {
+            /* Check for match (case insensative) */
+            if (RtlEqualUnicodeString(&pldev->pGdiDriverInfo->DriverName, &strDriverName, 1))
+            {
+                /* Image found in LDEV list */
+                break;
+            }
+        }
+    }
+
+    /* Did we find one? */
+    if (!pldev)
+    {
+        /* No, allocate a new LDEVOBJ */
+        pldev = LDEVOBJ_AllocLDEV(ldevtype);
+        if (!pldev)
+        {
+            DPRINT1("Could not allocate LDEV\n");
+            goto leave;
+        }
+
+        /* Load the image */
+        if (!LDEVOBJ_bLoadImage(pldev, &strDriverName))
+        {
+            LDEVOBJ_vFreeLDEV(pldev);
+            pldev = NULL;
+            DPRINT1("LDEVOBJ_bLoadImage failed\n");
+            goto leave;
+        }
+
+        /* Shall we load a driver? */
+        if (ldevtype != LDEV_IMAGE)
+        {
+            /* Load the driver */
+            if (!LDEVOBJ_bLoadDriver(pldev))
+            {
+                DPRINT1("LDEVOBJ_bLoadDriver failed\n");
+                LDEVOBJ_vFreeLDEV(pldev);
+                pldev = NULL;
+                goto leave;
+            }
+        }
+
+        /* Insert the LDEV into the global list */
+        pldev->pldevPrev = NULL;
+        pldev->pldevNext = gpldevHead;
+        gpldevHead = pldev;
+    }
+
+    /* Increase ref count */
+    pldev->cRefs++;
+
+leave:
+    /* Unlock loader */
+    EngReleaseSemaphore(ghsemLDEVList);
+
+    DPRINT("EngLoadImageEx returning %p\n", pldev);
+
+    return pldev;
+}
+
+
+/** Exported functions ********************************************************/
+
+HANDLE
+APIENTRY
+EngLoadImage(
+    LPWSTR pwszDriverName)
+{
+    return (HANDLE)EngLoadImageEx(pwszDriverName, LDEV_IMAGE);
+}
+
+
+VOID
+APIENTRY
+EngUnloadImage(
+    IN HANDLE hModule)
+{
+    PLDEVOBJ pldev = (PLDEVOBJ)hModule;
+
+    /* Make sure the LDEV is in the list */
+    ASSERT(pldev->pldevPrev || pldev->pldevNext);
+
+    /* Lock loader */
+    EngAcquireSemaphore(ghsemLDEVList);
+
+    /* Decrement reference count */
+    pldev->cRefs--;
+
+    /* No more references left? */
+    if (pldev->cRefs == 0)
+    {
+        /* Remove ldev from the list */
+        if (pldev->pldevPrev)
+            pldev->pldevPrev->pldevNext = pldev->pldevNext;
+        if (pldev->pldevNext)
+            pldev->pldevNext->pldevPrev = pldev->pldevPrev;
+
+        /* Unload the image */
+        LDEVOBJ_vUnloadImage(pldev);
+    }
+
+    /* Unlock loader */
+    EngReleaseSemaphore(ghsemLDEVList);
+}
+
+
+PVOID
+APIENTRY
+EngFindImageProcAddress(
+    IN HANDLE hModule,
+    IN LPSTR  lpProcName)
+{
+    PLDEVOBJ pldev = (PLDEVOBJ)hModule;
+
+    ASSERT(gpldevWin32k != NULL);
+
+    /* Check if win32k is requested */
+    if (!pldev)
+    {
+        pldev = gpldevWin32k;
+    }
+
+    /* Check if the drivers entry point is requested */
+    if (_strnicmp(lpProcName, "DrvEnableDriver", 15) == 0)
+    {
+        return pldev->pGdiDriverInfo->EntryPoint;
+    }
+
+    /* Try to find the address */
+    return LDEVOBJ_pvFindImageProcAddress(pldev, lpProcName);
+}
+
index a67b47a..d5db687 100644 (file)
@@ -565,10 +565,7 @@ IntEngLineTo(SURFOBJ *psoDest,
     if (b.left == b.right) b.right++;
     if (b.top == b.bottom) b.bottom++;
 
-    SURFACE_LockBitmapBits(psurfDest);
-    MouseSafetyOnDrawStart(psoDest, x1, y1, x2, y2);
-
-    if (psurfDest->flHooks & HOOK_LINETO)
+    if (psurfDest->flags & HOOK_LINETO)
     {
         /* Call the driver's DrvLineTo */
         ret = GDIDEVFUNCS(psoDest).LineTo(
@@ -576,7 +573,7 @@ IntEngLineTo(SURFOBJ *psoDest,
     }
 
 #if 0
-    if (! ret && (psurfDest->flHooks & HOOK_STROKEPATH))
+    if (! ret && (psurfDest->flags & HOOK_STROKEPATH))
     {
         /* FIXME: Emulate LineTo using drivers DrvStrokePath and set ret on success */
     }
@@ -587,9 +584,6 @@ IntEngLineTo(SURFOBJ *psoDest,
         ret = EngLineTo(psoDest, ClipObj, pbo, x1, y1, x2, y2, RectBounds, Mix);
     }
 
-    MouseSafetyOnDrawEnd(psoDest);
-    SURFACE_UnlockBitmapBits(psurfDest);
-
     return ret;
 }
 
index 7e445d7..0da46df 100644 (file)
@@ -3,7 +3,7 @@
  * PROJECT:           ReactOS kernel
  * PURPOSE:           Functions for mapping files and sections
  * FILE:              subsys/win32k/eng/device.c
- * PROGRAMER:
+ * PROGRAMER:         Timo Kreuzer (timo.kreuzer@reactos.org)
  */
 
 #include <win32k.h>
 #define NDEBUG
 #include <debug.h>
 
+// HACK!!!
+#define MmMapViewInSessionSpace MmMapViewInSystemSpace
+#define MmUnmapViewInSessionSpace MmUnmapViewInSystemSpace
+
+typedef struct _ENGSECTION
+{
+    PVOID pvSectionObject;
+    PVOID pvMappedBase;
+    SIZE_T cjViewSize;
+    ULONG ulTag;
+} ENGSECTION, *PENGSECTION;
+
+typedef struct _FILEVIEW
+{
+    LARGE_INTEGER  LastWriteTime;  
+    PVOID          pvKView;
+    PVOID          pvViewFD;  
+    SIZE_T         cjView;  
+    PVOID          pSection;  
+} FILEVIEW, *PFILEVIEW;   
+
+typedef struct _FONTFILEVIEW 
+{
+    FILEVIEW;
+    DWORD          reserved[2];
+    PWSTR          pwszPath;
+    SIZE_T         ulRegionSize;
+    ULONG          cKRefCount;
+    ULONG          cRefCountFD;
+    PVOID          pvSpoolerBase;
+    DWORD          dwSpoolerPid;
+} FONTFILEVIEW, *PFONTFILEVIEW;
+
+enum
+{
+    FVF_SYSTEMROOT = 1,
+    FVF_READONLY = 2,
+    FVF_FONTFILE = 4,
+};
+
+HANDLE ghSystem32Directory;
+HANDLE ghRootDirectory;
+
+
+PVOID
+NTAPI
+EngCreateSection(
+    IN ULONG fl,
+    IN SIZE_T cjSize,
+    IN ULONG ulTag)
+{
+    NTSTATUS Status;
+    PENGSECTION pSection;
+    PVOID pvSectionObject;
+    LARGE_INTEGER liSize;
+
+    /* Allocate a section object */
+    pSection = EngAllocMem(0, sizeof(ENGSECTION), 'stsU');
+    if (!pSection) return NULL;
+
+    liSize.QuadPart = cjSize;
+    Status = MmCreateSection(&pvSectionObject,
+                             SECTION_ALL_ACCESS,
+                             NULL,
+                             &liSize,
+                             PAGE_READWRITE,
+                             SEC_COMMIT,
+                             NULL,
+                             NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to create a section Status=0x%x\n", Status);
+        EngFreeMem(pSection);
+        return NULL;
+    }
+
+    /* Set the fields of the section */
+    pSection->ulTag = ulTag;
+    pSection->pvSectionObject = pvSectionObject;
+    pSection->pvMappedBase = NULL;
+    pSection->cjViewSize = cjSize;
+
+    return pSection;
+}
+
+
+BOOL
+APIENTRY
+EngMapSection(
+    IN PVOID pvSection,
+    IN BOOL bMap,
+    IN HANDLE hProcess,
+    OUT PVOID* pvBaseAddress)
+{
+    NTSTATUS Status;
+    PENGSECTION pSection = pvSection;
+    PEPROCESS pepProcess;
+
+    /* Get a pointer to the process */
+    Status = ObReferenceObjectByHandle(hProcess,
+                                       PROCESS_VM_OPERATION,
+                                       NULL,
+                                       KernelMode,
+                                       (PVOID*)&pepProcess,
+                                       NULL);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Could not access process %p, Status=0x%lx\n", hProcess, Status);
+        return FALSE;
+    }
+
+    if (bMap)
+    {
+        /* Make sure the section isn't already mapped */
+        ASSERT(pSection->pvMappedBase == NULL);
+
+        /* Map the section into the process address space */
+        Status = MmMapViewOfSection(pSection->pvSectionObject,
+                                    pepProcess,
+                                    &pSection->pvMappedBase,
+                                    0,
+                                    pSection->cjViewSize,
+                                    NULL,
+                                    &pSection->cjViewSize,
+                                    0,
+                                    0,
+                                    PAGE_READWRITE);
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT1("Failed to map a section Status=0x%x\n", Status);
+        }
+    }
+    else
+    {
+        /* Make sure the section is mapped */
+        ASSERT(pSection->pvMappedBase);
+
+        /* Unmap the section from the process address space */
+        Status = MmUnmapViewOfSection(pepProcess, pSection->pvMappedBase);
+        if (NT_SUCCESS(Status))
+        {
+            pSection->pvMappedBase = NULL;
+        }
+        else
+        {
+            DPRINT1("Failed to unmap a section @ &p Status=0x%x\n", 
+                    pSection->pvMappedBase, Status);
+        }
+    }
+
+    /* Dereference the process */
+    ObDereferenceObject(pepProcess);
+
+    /* Set the new mapping base and return bool status */
+    *pvBaseAddress = pSection->pvMappedBase;
+    return NT_SUCCESS(Status);
+}
+
+BOOL
+APIENTRY
+EngFreeSectionMem(
+    IN PVOID pvSection OPTIONAL,
+    IN PVOID pvMappedBase OPTIONAL)
+{
+    NTSTATUS Status;
+    PENGSECTION pSection = pvSection;
+    BOOL bResult = TRUE;
+
+    /* Did the caller give us a mapping base? */
+    if (pvMappedBase)
+    {
+        Status = MmUnmapViewInSessionSpace(pvMappedBase);
+        if (!NT_SUCCESS(Status))
+        {
+            DPRINT1("MmUnmapViewInSessionSpace failed: 0x%lx\n", Status);
+            bResult = FALSE;
+        }
+    }
+
+    /* Check if we should free the section as well */
+    if (pSection)
+    {
+        /* Dereference the kernel section */
+        ObDereferenceObject(pSection->pvSectionObject);
+
+        /* Finally free the section memory itself */
+        EngFreeMem(pSection);
+    }
+
+    return bResult;
+}
+
+PVOID
+APIENTRY
+EngAllocSectionMem(
+    OUT PVOID *ppvSection,
+    IN ULONG fl,
+    IN SIZE_T cjSize,
+    IN ULONG ulTag)
+{
+    NTSTATUS Status;
+    PENGSECTION pSection;
+
+    /* Check parameter */
+    if (cjSize == 0) return NULL;
+
+    /* Allocate a section object */
+    pSection = EngCreateSection(fl, cjSize, ulTag);
+    if (!pSection)
+    {
+        *ppvSection = NULL;
+        return NULL;
+    }
+
+    /* Map the section in session space */
+    Status = MmMapViewInSessionSpace(pSection->pvSectionObject,
+                                     &pSection->pvMappedBase,
+                                     &pSection->cjViewSize);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to map a section Status=0x%x\n", Status);
+        *ppvSection = NULL;
+        EngFreeSectionMem(pSection, NULL);
+        return NULL;
+    }
+
+    if (fl & FL_ZERO_MEMORY)
+    {
+        RtlZeroMemory(pSection->pvMappedBase, cjSize);
+    }
+
+    /* Set section pointer and return base address */
+    *ppvSection = pSection;
+    return pSection->pvMappedBase;
+}
+
+
+PFILEVIEW
+NTAPI
+EngLoadModuleEx(
+    LPWSTR pwsz,
+    ULONG cjSizeOfModule,
+    FLONG fl)
+{
+    PFILEVIEW pFileView = NULL;
+    OBJECT_ATTRIBUTES ObjectAttributes;
+    HANDLE hRootDir;
+    UNICODE_STRING ustrFileName;
+    IO_STATUS_BLOCK IoStatusBlock;
+    FILE_BASIC_INFORMATION FileInformation;
+    HANDLE hFile;
+    NTSTATUS Status;
+    LARGE_INTEGER liSize;
+
+    if (fl & FVF_FONTFILE)
+    {
+        pFileView = EngAllocMem(0, sizeof(FONTFILEVIEW), 'vffG');
+    }
+    else
+    {
+        pFileView = EngAllocMem(0, sizeof(FILEVIEW), 'liFg');
+    }
+
+    /* Check for success */
+    if (!pFileView) return NULL;
+
+    /* Check if the file is relative to system32 */
+    if (fl & FVF_SYSTEMROOT)
+    {
+        hRootDir = ghSystem32Directory;
+    }
+    else
+    {
+        hRootDir = ghRootDirectory;
+    }
+
+    /* Initialize unicode string and object attributes */
+    RtlInitUnicodeString(&ustrFileName, pwsz);
+    InitializeObjectAttributes(&ObjectAttributes,
+                               &ustrFileName,
+                               OBJ_CASE_INSENSITIVE|OBJ_KERNEL_HANDLE,
+                               hRootDir,
+                               NULL);
+
+    /* Now open the file */
+    Status = ZwCreateFile(&hFile,
+                          FILE_READ_DATA,
+                          &ObjectAttributes,
+                          &IoStatusBlock,
+                          NULL,
+                          FILE_ATTRIBUTE_NORMAL,
+                          0,
+                          FILE_OPEN,
+                          FILE_NON_DIRECTORY_FILE,
+                          NULL,
+                          0);
+
+    Status = ZwQueryInformationFile(hFile,
+                                    &IoStatusBlock,
+                                    &FileInformation,
+                                    sizeof(FILE_BASIC_INFORMATION),
+                                    FileBasicInformation);
+    if (NT_SUCCESS(Status))
+    {
+        pFileView->LastWriteTime = FileInformation.LastWriteTime;
+    }
+
+    /* Create a section from the file */
+    liSize.QuadPart = cjSizeOfModule;
+    Status = MmCreateSection(&pFileView->pSection,
+                             SECTION_ALL_ACCESS,
+                             NULL,
+                             cjSizeOfModule ? &liSize : NULL,
+                             fl & FVF_READONLY ? PAGE_EXECUTE_READ : PAGE_EXECUTE_READWRITE,
+                             SEC_COMMIT,
+                             hFile,
+                             NULL);
+
+    /* Close the file handle */
+    ZwClose(hFile);
+
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to create a section Status=0x%x\n", Status);
+        EngFreeMem(pFileView);
+        return NULL;
+    }
+
+
+    pFileView->pvKView = NULL;
+    pFileView->pvViewFD = NULL;
+    pFileView->cjView = 0;
+
+    return pFileView;
+}
+
 HANDLE
 APIENTRY
 EngLoadModule(LPWSTR pwsz)
 {
-    UNIMPLEMENTED;
-    return NULL;
+    /* Forward to EngLoadModuleEx */
+    return (HANDLE)EngLoadModuleEx(pwsz, 0, FVF_READONLY | FVF_SYSTEMROOT);
 }
 
 HANDLE
@@ -25,9 +361,8 @@ EngLoadModuleForWrite(
        IN LPWSTR pwsz,
        IN ULONG  cjSizeOfModule)
 {
-    // www.osr.com/ddk/graphics/gdifncs_98rr.htm
-    UNIMPLEMENTED;
-    return NULL;
+    /* Forward to EngLoadModuleEx */
+    return (HANDLE)EngLoadModuleEx(pwsz, cjSizeOfModule, FVF_SYSTEMROOT);
 }
 
 PVOID
@@ -36,17 +371,46 @@ EngMapModule(
        IN  HANDLE h,
        OUT PULONG pulSize)
 {
-    // www.osr.com/ddk/graphics/gdifncs_9b1j.htm
-    UNIMPLEMENTED;
-    return NULL;
+    PFILEVIEW pFileView = (PFILEVIEW)h;
+    NTSTATUS Status;
+
+    pFileView->cjView = 0;
+
+    /* Map the section in session space */
+    Status = MmMapViewInSessionSpace(pFileView->pSection,
+                                     &pFileView->pvKView,
+                                     &pFileView->cjView);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("Failed to map a section Status=0x%x\n", Status);
+        *pulSize = 0;
+        return NULL;
+    }
+
+    *pulSize = pFileView->cjView;
+    return pFileView->pvKView;
 }
 
 VOID
 APIENTRY
-EngFreeModule (IN HANDLE h)
+EngFreeModule(IN HANDLE h)
 {
-    // www.osr.com/ddk/graphics/gdifncs_9fzb.htm
-    UNIMPLEMENTED;
+    PFILEVIEW pFileView = (PFILEVIEW)h;
+    NTSTATUS Status;
+
+    /* Unmap the section */
+    Status = MmUnmapViewInSessionSpace(pFileView->pvKView);
+    if (!NT_SUCCESS(Status))
+    {
+        DPRINT1("MmUnmapViewInSessionSpace failed: 0x%lx\n", Status);
+        ASSERT(FALSE);
+    }
+
+    /* Dereference the section */
+    ObDereferenceObject(pFileView->pSection);
+
+    /* Free the file view memory */
+    EngFreeMem(pFileView);
 }
 
 PVOID
@@ -56,8 +420,28 @@ EngMapFile(
     IN ULONG cjSize,
     OUT ULONG_PTR *piFile)
 {
-    UNIMPLEMENTED;
-    return NULL;
+    HANDLE hModule;
+    PVOID pvBase;
+
+    /* Load the file */
+    hModule = EngLoadModuleEx(pwsz, 0, 0);
+    if (!hModule)
+    {
+        *piFile = 0;
+        return NULL;
+    }
+
+    /* Map the file */
+    pvBase = EngMapModule(hModule, &cjSize);
+    if (!pvBase)
+    {
+        EngFreeModule(hModule);
+        hModule = NULL;
+    }
+
+    /* Set iFile and return mapped base */
+    *piFile = (ULONG_PTR)hModule;
+    return pvBase;
 }
 
 BOOL
@@ -65,8 +449,11 @@ APIENTRY
 EngUnmapFile(
     IN ULONG_PTR iFile)
 {
-    UNIMPLEMENTED;
-    return FALSE;
+    HANDLE hModule = (HANDLE)iFile;
+
+    EngFreeModule(hModule);
+
+    return TRUE;
 }
 
 
@@ -110,36 +497,3 @@ EngUnmapFontFile(
     // www.osr.com/ddk/graphics/gdifncs_09wn.htm
     EngUnmapFontFileFD(iFile);
 }
-
-
-BOOLEAN
-APIENTRY
-EngMapSection(IN PVOID Section,
-              IN BOOLEAN Map,
-              IN HANDLE Process,
-              IN PVOID* BaseAddress)
-{
-    UNIMPLEMENTED;
-    return FALSE;
-}
-
-PVOID
-APIENTRY
-EngAllocSectionMem(IN PVOID SectionObject,
-                   IN ULONG Flags,
-                   IN SIZE_T MemSize,
-                   IN ULONG Tag)
-{
-    UNIMPLEMENTED;
-    return NULL;
-}
-
-
-BOOLEAN
-APIENTRY
-EngFreeSectionMem(IN PVOID SectionObject OPTIONAL,
-                  IN PVOID MappedBase)
-{
-    UNIMPLEMENTED;
-    return FALSE;
-}
index a49e4fe..1fb81b3 100644 (file)
@@ -79,6 +79,7 @@ EngAllocUserMem(SIZE_T cj, ULONG Tag)
     }
 
   /* TODO: Add allocation info to AVL tree (stored inside W32PROCESS structure) */
+  //hSecure = EngSecureMem(NewMem, cj);
 
   return NewMem;
 }
@@ -166,6 +167,7 @@ HackUnsecureVirtualMemory(
 HANDLE APIENTRY
 EngSecureMem(PVOID Address, ULONG Length)
 {
+    return (HANDLE)-1; // HACK!!!
   return MmSecureVirtualMemory(Address, Length, PAGE_READWRITE);
 }
 
@@ -175,6 +177,7 @@ EngSecureMem(PVOID Address, ULONG Length)
 VOID APIENTRY
 EngUnsecureMem(HANDLE Mem)
 {
+    if (Mem == (HANDLE)-1) return;  // HACK!!!
   MmUnsecureVirtualMemory((PVOID) Mem);
 }
 
index 93ab14d..b2db0e6 100644 (file)
@@ -37,23 +37,17 @@ EngSetPointerTag(
  */
 INT INTERNAL_CALL
 MouseSafetyOnDrawStart(
-    SURFOBJ *pso,
+    PPDEVOBJ ppdev,
     LONG HazardX1,
     LONG HazardY1,
     LONG HazardX2,
     LONG HazardY2)
 {
     LONG tmp;
-    PDEVOBJ *ppdev;
     GDIPOINTER *pgp;
 
-    ASSERT(pso != NULL);
-
-    ppdev = GDIDEV(pso);
-    if (ppdev == NULL)
-    {
-        return FALSE;
-    }
+    ASSERT(ppdev != NULL);
+    ASSERT(ppdev->pSurface != NULL);
 
     pgp = &ppdev->Pointer;
 
@@ -83,12 +77,12 @@ MouseSafetyOnDrawStart(
     }
 
     if (pgp->Exclude.right >= HazardX1
-            && pgp->Exclude.left <= HazardX2
-            && pgp->Exclude.bottom >= HazardY1
-            && pgp->Exclude.top <= HazardY2)
+        && pgp->Exclude.left <= HazardX2
+        && pgp->Exclude.bottom >= HazardY1
+        && pgp->Exclude.top <= HazardY2)
     {
         ppdev->SafetyRemoveLevel = ppdev->SafetyRemoveCount;
-        ppdev->pfnMovePointer(pso, -1, -1, NULL);
+        ppdev->pfnMovePointer(&ppdev->pSurface->SurfObj, -1, -1, NULL);
     }
 
     return(TRUE);
@@ -99,19 +93,12 @@ MouseSafetyOnDrawStart(
  */
 INT INTERNAL_CALL
 MouseSafetyOnDrawEnd(
-    SURFOBJ *pso)
+    PPDEVOBJ ppdev)
 {
-    PDEVOBJ *ppdev;
     GDIPOINTER *pgp;
 
-    ASSERT(pso != NULL);
-
-    ppdev = (PDEVOBJ*)pso->hdev;
-
-    if (ppdev == NULL)
-    {
-        return(FALSE);
-    }
+    ASSERT(ppdev != NULL);
+    ASSERT(ppdev->pSurface != NULL);
 
     pgp = &ppdev->Pointer;
 
@@ -125,7 +112,10 @@ MouseSafetyOnDrawEnd(
         return FALSE;
     }
 
-    ppdev->pfnMovePointer(pso, gpsi->ptCursor.x, gpsi->ptCursor.y, &pgp->Exclude);
+    ppdev->pfnMovePointer(&ppdev->pSurface->SurfObj,
+                          gpsi->ptCursor.x,
+                          gpsi->ptCursor.y,
+                          &pgp->Exclude);
 
     ppdev->SafetyRemoveLevel = 0;
 
@@ -175,18 +165,17 @@ IntHideMousePointer(
     ptlSave.x = rclDest.left - pt.x;
     ptlSave.y = rclDest.top - pt.y;
 
-    IntEngBitBltEx(psoDest,
-                   &pgp->psurfSave->SurfObj,
-                   NULL,
-                   NULL,
-                   NULL,
-                   &rclDest,
-                   &ptlSave,
-                   &ptlSave,
-                   NULL,
-                   NULL,
-                   ROP3_TO_ROP4(SRCCOPY),
-                   FALSE);
+    IntEngBitBlt(psoDest,
+                 &pgp->psurfSave->SurfObj,
+                 NULL,
+                 NULL,
+                 NULL,
+                 &rclDest,
+                 &ptlSave,
+                 &ptlSave,
+                 NULL,
+                 NULL,
+                 ROP3_TO_ROP4(SRCCOPY));
 }
 
 VOID
@@ -229,77 +218,72 @@ IntShowMousePointer(PDEVOBJ *ppdev, SURFOBJ *psoDest)
     rclPointer.bottom = min(pgp->Size.cy, psoDest->sizlBitmap.cy - pt.y);
 
     /* Copy the pixels under the cursor to temporary surface. */
-    IntEngBitBltEx(&pgp->psurfSave->SurfObj,
-                   psoDest,
-                   NULL,
-                   NULL,
-                   NULL,
-                   &rclPointer,
-                   (POINTL*)&rclSurf,
-                   NULL,
-                   NULL,
-                   NULL,
-                   ROP3_TO_ROP4(SRCCOPY),
-                   FALSE);
+    IntEngBitBlt(&pgp->psurfSave->SurfObj,
+                 psoDest,
+                 NULL,
+                 NULL,
+                 NULL,
+                 &rclPointer,
+                 (POINTL*)&rclSurf,
+                 NULL,
+                 NULL,
+                 NULL,
+                 ROP3_TO_ROP4(SRCCOPY));
 
     /* Blt the pointer on the screen. */
     if (pgp->psurfColor)
     {
-        IntEngBitBltEx(psoDest,
-                       &pgp->psurfMask->SurfObj,
-                       NULL,
-                       NULL,
-                       NULL,
-                       &rclSurf,
-                       (POINTL*)&rclPointer,
-                       NULL,
-                       NULL,
-                       NULL,
-                       ROP3_TO_ROP4(SRCAND),
-                       FALSE);
-
-        IntEngBitBltEx(psoDest,
-                       &pgp->psurfColor->SurfObj,
-                       NULL,
-                       NULL,
-                       NULL,
-                       &rclSurf,
-                       (POINTL*)&rclPointer,
-                       NULL,
-                       NULL,
-                       NULL,
-                       ROP3_TO_ROP4(SRCINVERT),
-                       FALSE);
+        IntEngBitBlt(psoDest,
+                     &pgp->psurfMask->SurfObj,
+                     NULL,
+                     NULL,
+                     NULL,
+                     &rclSurf,
+                     (POINTL*)&rclPointer,
+                     NULL,
+                     NULL,
+                     NULL,
+                     ROP3_TO_ROP4(SRCAND));
+
+        IntEngBitBlt(psoDest,
+                     &pgp->psurfColor->SurfObj,
+                     NULL,
+                     NULL,
+                     NULL,
+                     &rclSurf,
+                     (POINTL*)&rclPointer,
+                     NULL,
+                     NULL,
+                     NULL,
+                     ROP3_TO_ROP4(SRCINVERT));
     }
     else
     {
-        IntEngBitBltEx(psoDest,
-                       &pgp->psurfMask->SurfObj,
-                       NULL,
-                       NULL,
-                       NULL,
-                       &rclSurf,
-                       (POINTL*)&rclPointer,
-                       NULL,
-                       NULL,
-                       NULL,
-                       ROP3_TO_ROP4(SRCAND),
-                       FALSE);
+        IntEngBitBlt(psoDest,
+                     &pgp->psurfMask->SurfObj,
+                     NULL,
+                     NULL,
+                     NULL,
+                     &rclSurf,
+                     (POINTL*)&rclPointer,
+                     NULL,
+                     NULL,
+                     NULL,
+                     ROP3_TO_ROP4(SRCAND));
 
         rclPointer.top += pgp->Size.cy;
 
-        IntEngBitBltEx(psoDest,
-                       &pgp->psurfMask->SurfObj,
-                       NULL,
-                       NULL,
-                       NULL,
-                       &rclSurf,
-                       (POINTL*)&rclPointer,
-                       NULL,
-                       NULL,
-                       NULL,
-                       ROP3_TO_ROP4(SRCINVERT),
-                       FALSE);
+        IntEngBitBlt(psoDest,
+                     &pgp->psurfMask->SurfObj,
+                     NULL,
+                     NULL,
+                     NULL,
+                     &rclSurf,
+                     (POINTL*)&rclPointer,
+                     NULL,
+                     NULL,
+                     NULL,
+                     ROP3_TO_ROP4(SRCINVERT));
     }
 }
 
@@ -353,7 +337,7 @@ EngSetPointerShape(
         rectl.bottom = sizel.cy;
 
         /* Calculate lDelta for our surfaces. */
-        lDelta = DIB_GetDIBWidthBytes(sizel.cx, 
+        lDelta = WIDTH_BYTES_ALIGN32(sizel.cx, 
                                       BitsPerFormat(pso->iBitmapFormat));
 
         /* Create a bitmap for saving the pixels under the cursor. */
@@ -373,10 +357,10 @@ EngSetPointerShape(
 
         /* Create a bitmap to copy the color bitmap to */
         hbmColor = EngCreateBitmap(psoColor->sizlBitmap,
-                                   lDelta,
-                                   pso->iBitmapFormat,
-                                   BMF_TOPDOWN | BMF_NOZEROINIT,
-                                   NULL);
+                           lDelta,
+                           pso->iBitmapFormat,
+                           BMF_TOPDOWN | BMF_NOZEROINIT,
+                           NULL);
         psurfColor = SURFACE_ShareLockSurface(hbmColor);
         if (!psurfColor) goto failure;
 
@@ -540,28 +524,13 @@ EngMovePointer(
             prcl->right = prcl->left + pgp->Size.cx;
             prcl->bottom = prcl->top + pgp->Size.cy;
         }
-    } 
+    }
     else if (prcl != NULL)
     {
         prcl->left = prcl->top = prcl->right = prcl->bottom = -1;
     }
 }
 
-VOID APIENTRY
-IntEngMovePointer(
-    IN SURFOBJ *pso,
-    IN LONG x,
-    IN LONG y,
-    IN RECTL *prcl)
-{
-    SURFACE *psurf = CONTAINING_RECORD(pso, SURFACE, SurfObj);
-    PPDEVOBJ ppdev = (PPDEVOBJ)pso->hdev;
-
-    SURFACE_LockBitmapBits(psurf);
-    ppdev->pfnMovePointer(pso, x, y, prcl);
-    SURFACE_UnlockBitmapBits(psurf);
-}
-
 ULONG APIENTRY
 IntEngSetPointerShape(
    IN SURFOBJ *pso,
@@ -576,13 +545,11 @@ IntEngSetPointerShape(
    IN FLONG fl)
 {
     ULONG ulResult = SPS_DECLINE;
-    SURFACE *psurf = CONTAINING_RECORD(pso, SURFACE, SurfObj);
     PFN_DrvSetPointerShape pfnSetPointerShape;
     PPDEVOBJ ppdev = GDIDEV(pso);
 
     pfnSetPointerShape = GDIDEVFUNCS(pso).SetPointerShape;
 
-    SURFACE_LockBitmapBits(psurf);
     if (pfnSetPointerShape)
     {
         ulResult = pfnSetPointerShape(pso,
@@ -620,8 +587,6 @@ IntEngSetPointerShape(
         ppdev->pfnMovePointer = EngMovePointer;
     }
 
-    SURFACE_UnlockBitmapBits(psurf);
-
     return ulResult;
 }
 
@@ -649,10 +614,14 @@ GreSetPointerShape(
         return 0;
     }
 
-    psurf = pdc->dclevel.pSurface;
+    ASSERT(pdc->dctype == DCTYPE_DIRECT);
+    EngAcquireSemaphore(pdc->ppdev->hsemDevLock);
+    /* We're not sure DC surface is the good one */
+    psurf = pdc->ppdev->pSurface;
     if (!psurf)
     {
         DPRINT1("DC has no surface.\n");
+        EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
         DC_UnlockDc(pdc);
         return 0;
     }
@@ -668,7 +637,7 @@ GreSetPointerShape(
     {
         /* We have one, lock it */
         psurfColor = SURFACE_ShareLockSurface(hbmColor);
-        
+
         if (psurfColor)
         {
             /* Create an XLATEOBJ, no mono support */
@@ -700,6 +669,8 @@ GreSetPointerShape(
     if (psurfMask)
         SURFACE_ShareUnlockSurface(psurfMask);
 
+    EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
+
     /* Unlock the DC */
     DC_UnlockDc(pdc);
 
@@ -724,12 +695,23 @@ GreMovePointer(
         DPRINT1("Failed to lock the DC.\n");
         return;
     }
+    ASSERT(pdc->dctype == DCTYPE_DIRECT);
+
+    /* Acquire PDEV lock */
+    EngAcquireSemaphore(pdc->ppdev->hsemDevLock);
 
-    /* Store the cursor exclude position in the PDEV */
-    prcl = &pdc->ppdev->Pointer.Exclude;
+    /* Check if we need to move it */
+    if(pdc->ppdev->SafetyRemoveLevel == 0)
+    {
+        /* Store the cursor exclude position in the PDEV */
+        prcl = &pdc->ppdev->Pointer.Exclude;
+
+        /* Call Eng/Drv function */
+        pdc->ppdev->pfnMovePointer(&pdc->ppdev->pSurface->SurfObj, x, y, prcl);
+    }
 
-    /* Call Eng/Drv function */
-    IntEngMovePointer(&pdc->dclevel.pSurface->SurfObj, x, y, prcl);
+    /* Release PDEV lock */
+    EngReleaseSemaphore(pdc->ppdev->hsemDevLock);
 
     /* Unlock the DC */
     DC_UnlockDc(pdc);
index d1290b3..d59c4f2 100644 (file)
 #define NDEBUG
 #include <debug.h>
 
-static BOOL APIENTRY FillSolidUnlocked(SURFOBJ *pso, PRECTL pRect, ULONG iColor)
+BOOL APIENTRY FillSolid(SURFOBJ *pso, PRECTL pRect, ULONG iColor)
 {
   LONG y;
   ULONG LineWidth;
 
   ASSERT(pso);
   ASSERT(pRect);
-  MouseSafetyOnDrawStart(pso, pRect->left, pRect->top, pRect->right, pRect->bottom);
   LineWidth  = pRect->right - pRect->left;
   DPRINT(" LineWidth: %d, top: %d, bottom: %d\n", LineWidth, pRect->top, pRect->bottom);
   for (y = pRect->top; y < pRect->bottom; y++)
@@ -47,22 +46,9 @@ static BOOL APIENTRY FillSolidUnlocked(SURFOBJ *pso, PRECTL pRect, ULONG iColor)
     DibFunctionsForBitmapFormat[pso->iBitmapFormat].DIB_HLine(
       pso, pRect->left, pRect->right, y, iColor);
   }
-  MouseSafetyOnDrawEnd(pso);
-
   return TRUE;
 }
 
-BOOL APIENTRY FillSolid(SURFOBJ *pso, PRECTL pRect, ULONG iColor)
-{
-  SURFACE *psurf;
-  BOOL Result;
-  psurf = CONTAINING_RECORD(pso, SURFACE, SurfObj);
-  SURFACE_LockBitmapBits(psurf);
-  Result = FillSolidUnlocked(pso, pRect, iColor);
-  SURFACE_UnlockBitmapBits(psurf);
-  return Result;
-}
-
 BOOL APIENTRY
 EngPaintRgn(SURFOBJ *pso, CLIPOBJ *ClipRegion, ULONG iColor, MIX Mix,
             BRUSHOBJ *BrushObj, POINTL *BrushPoint)
@@ -85,7 +71,7 @@ EngPaintRgn(SURFOBJ *pso, CLIPOBJ *ClipRegion, ULONG iColor, MIX Mix,
 
     if (ClipRegion->iDComplexity == DC_RECT)
     {
-      FillSolidUnlocked(pso, &(ClipRegion->rclBounds), iColor);
+      FillSolid(pso, &(ClipRegion->rclBounds), iColor);
     } else {
 
       /* Enumerate all the rectangles and draw them */
@@ -94,7 +80,7 @@ EngPaintRgn(SURFOBJ *pso, CLIPOBJ *ClipRegion, ULONG iColor, MIX Mix,
       do {
         EnumMore = CLIPOBJ_bEnum(ClipRegion, sizeof(RectEnum), (PVOID) &RectEnum);
         for (i = 0; i < RectEnum.c; i++) {
-          FillSolidUnlocked(pso, RectEnum.arcl + i, iColor);
+          FillSolid(pso, RectEnum.arcl + i, iColor);
         }
       } while (EnumMore);
     }
@@ -136,18 +122,11 @@ IntEngPaint(IN SURFOBJ *pso,
 
   DPRINT("pso->iType == %d\n", pso->iType);
   /* Is the surface's Paint function hooked? */
-  if((pso->iType!=STYPE_BITMAP) && (psurf->flHooks & HOOK_PAINT))
+  if((pso->iType!=STYPE_BITMAP) && (psurf->flags & HOOK_PAINT))
   {
     // Call the driver's DrvPaint
-    SURFACE_LockBitmapBits(psurf);
-    MouseSafetyOnDrawStart(pso, ClipRegion->rclBounds.left,
-                                ClipRegion->rclBounds.top, ClipRegion->rclBounds.right,
-                                                        ClipRegion->rclBounds.bottom);
-
     ret = GDIDEVFUNCS(pso).Paint(
       pso, ClipRegion, Brush, BrushOrigin, Mix);
-    MouseSafetyOnDrawEnd(pso);
-    SURFACE_UnlockBitmapBits(psurf);
     return ret;
   }
   return EngPaint(pso, ClipRegion, Brush, BrushOrigin, Mix );
diff --git a/reactos/subsystems/win32/win32k/eng/pdevobj.c b/reactos/subsystems/win32/win32k/eng/pdevobj.c
new file mode 100644 (file)
index 0000000..26c0f4b
--- /dev/null
@@ -0,0 +1,844 @@
+/*
+ * COPYRIGHT:        See COPYING in the top level directory
+ * PROJECT:          ReactOS kernel
+ * PURPOSE:          Support for physical devices
+ * FILE:             subsystems/win32/win32k/eng/pdevobj.c
+ * PROGRAMER:        Timo Kreuzer (timo.kreuzer@reactos.org)
+ */
+
+#include <win32k.h>
+
+#include <intrin.h>
+
+#define NDEBUG
+#include <debug.h>
+
+PPDEVOBJ gppdevPrimary = NULL;
+
+static PPDEVOBJ gppdevList = NULL;
+static HSEMAPHORE ghsemPDEV;
+
+BOOL
+NTAPI
+InitPDEVImpl()
+{
+    ghsemPDEV = EngCreateSemaphore();
+    return TRUE;
+}
+
+
+PPDEVOBJ
+PDEVOBJ_AllocPDEV()
+{
+    PPDEVOBJ ppdev;
+
+    ppdev = ExAllocatePoolWithTag(PagedPool, sizeof(PDEVOBJ), GDITAG_PDEV);
+    if (!ppdev)
+        return NULL;
+
+    RtlZeroMemory(ppdev, sizeof(PDEVOBJ));
+
+    ppdev->cPdevRefs = 1;
+
+    return ppdev;
+}
+
+VOID
+NTAPI
+PDEVOBJ_vRelease(PPDEVOBJ ppdev)
+{
+    /* Lock loader */
+    EngAcquireSemaphore(ghsemPDEV);
+
+    /* Decrease reference count */
+    --ppdev->cPdevRefs;
+
+    ASSERT(ppdev->cPdevRefs >= 0) ;
+
+    /* Check if references are left */
+    if (ppdev->cPdevRefs == 0)
+    {
+        /* Do we have a surface? */
+        if(ppdev->pSurface)
+        {
+            /* Release the surface and let the driver free it */
+            SURFACE_ShareUnlockSurface(ppdev->pSurface);
+            ppdev->pfn.DisableSurface(ppdev->dhpdev);
+        }
+
+        /* Do we have a palette? */
+        if(ppdev->ppalSurf)
+        {
+            PALETTE_ShareUnlockPalette(ppdev->ppalSurf);
+        }
+
+        /* Disable PDEV */
+        ppdev->pfn.DisablePDEV(ppdev->dhpdev);
+
+        /* Remove it from list */
+        if( ppdev == gppdevList )
+            gppdevList = ppdev->ppdevNext ;
+        else
+        {
+            PPDEVOBJ ppdevCurrent = gppdevList;
+            BOOL found = FALSE ;
+            while (!found && ppdevCurrent->ppdevNext)
+            {
+                if (ppdevCurrent->ppdevNext == ppdev)
+                    found = TRUE;
+                else
+                    ppdevCurrent = ppdevCurrent->ppdevNext ;
+            }
+            if(found)
+                ppdevCurrent->ppdevNext = ppdev->ppdevNext;
+        }
+
+        /* Is this the primary one ? */
+        if (ppdev == gppdevPrimary)
+            gppdevPrimary = NULL;
+
+        /* Free it */
+        ExFreePoolWithTag(ppdev, GDITAG_PDEV );
+    }
+
+    /* Unlock loader */
+    EngReleaseSemaphore(ghsemPDEV);
+
+}
+
+BOOL
+NTAPI
+PDEVOBJ_bEnablePDEV(
+    PPDEVOBJ ppdev,
+    PDEVMODEW pdevmode,
+    PWSTR pwszLogAddress)
+{
+    PFN_DrvEnablePDEV pfnEnablePDEV;
+
+    DPRINT1("PDEVOBJ_bEnablePDEV()\n");
+
+    /* Get the DrvEnablePDEV function */
+    pfnEnablePDEV = ppdev->pldev->pfn.EnablePDEV;
+
+    /* Call the drivers DrvEnablePDEV function */
+    ppdev->dhpdev = pfnEnablePDEV(pdevmode,
+                                  pwszLogAddress,
+                                  HS_DDI_MAX,
+                                  ppdev->ahsurf,
+                                  sizeof(GDIINFO),
+                                  &ppdev->gdiinfo,
+                                  sizeof(DEVINFO),
+                                  &ppdev->devinfo,
+                                  (HDEV)ppdev,
+                                  ppdev->pGraphicsDevice->pwszDescription,
+                                  ppdev->pGraphicsDevice->DeviceObject);
+
+    /* Fix up some values */
+    if (ppdev->gdiinfo.ulLogPixelsX == 0)
+        ppdev->gdiinfo.ulLogPixelsX = 96;
+
+    if (ppdev->gdiinfo.ulLogPixelsY == 0)
+        ppdev->gdiinfo.ulLogPixelsY = 96;
+
+    /* Setup Palette */
+    GDIOBJ_SetOwnership(ppdev->devinfo.hpalDefault, NULL);
+    ppdev->ppalSurf = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault);
+
+    DPRINT1("PDEVOBJ_bEnablePDEV - dhpdev = %p\n", ppdev->dhpdev);
+
+    return TRUE;
+}
+
+VOID
+NTAPI
+PDEVOBJ_vCompletePDEV(
+    PPDEVOBJ ppdev)
+{
+    /* Call the drivers DrvCompletePDEV function */
+    ppdev->pldev->pfn.CompletePDEV(ppdev->dhpdev, (HDEV)ppdev);
+}
+
+PSURFACE
+NTAPI
+PDEVOBJ_pSurface(
+    PPDEVOBJ ppdev)
+{
+    HSURF hsurf;
+
+    /* Check if we already have a surface */
+    if (ppdev->pSurface)
+    {
+        /* Increment reference count */
+        GDIOBJ_IncrementShareCount(&ppdev->pSurface->BaseObject);
+    }
+    else
+    {
+        /* Call the drivers DrvEnableSurface */
+        hsurf = ppdev->pldev->pfn.EnableSurface(ppdev->dhpdev);
+
+        /* Lock the surface */
+        ppdev->pSurface = SURFACE_ShareLockSurface(hsurf);
+    }
+
+    DPRINT("PDEVOBJ_pSurface() returning %p\n", ppdev->pSurface);
+    return ppdev->pSurface;
+}
+
+PDEVMODEW
+NTAPI
+PDEVOBJ_pdmMatchDevMode(
+    PPDEVOBJ ppdev,
+    PDEVMODEW pdm)
+{
+    PGRAPHICS_DEVICE pGraphicsDevice;
+    PDEVMODEW pdmCurrent;
+    INT i;
+    DWORD dwFields;
+
+    pGraphicsDevice = ppdev->pGraphicsDevice;
+
+    for (i = 0; i < pGraphicsDevice->cDevModes; i++)
+    {
+        pdmCurrent = pGraphicsDevice->pDevModeList[i].pdm;
+
+        /* Compare asked DEVMODE fields
+         * Only compare those that are valid in both DEVMODE structs */
+        dwFields = pdmCurrent->dmFields & pdm->dmFields ;
+        /* For now, we only need those */
+        if ((dwFields & DM_BITSPERPEL) &&
+                (pdmCurrent->dmBitsPerPel != pdm->dmBitsPerPel))
+            continue;
+        if ((dwFields & DM_PELSWIDTH) &&
+                (pdmCurrent->dmPelsWidth != pdm->dmPelsWidth))
+            continue;
+        if ((dwFields & DM_PELSHEIGHT) &&
+                (pdmCurrent->dmPelsHeight != pdm->dmPelsHeight))
+            continue;
+        if ((dwFields & DM_DISPLAYFREQUENCY) &&
+                (pdmCurrent->dmDisplayFrequency != pdm->dmDisplayFrequency))
+            continue;
+
+        /* Match! Return the DEVMODE */
+        return pdmCurrent;
+    }
+
+    /* Nothing found */
+    return NULL;
+}
+
+static
+PPDEVOBJ
+EngpCreatePDEV(
+    PUNICODE_STRING pustrDeviceName,
+    PDEVMODEW pdm)
+{
+    PGRAPHICS_DEVICE pGraphicsDevice;
+    PPDEVOBJ ppdev;
+
+    /* Try to find the GRAPHICS_DEVICE */
+    if (pustrDeviceName)
+    {
+        pGraphicsDevice = EngpFindGraphicsDevice(pustrDeviceName, 0, 0);
+        if (!pGraphicsDevice)
+        {
+            DPRINT1("No GRAPHICS_DEVICE found for %ls!\n",
+                    pustrDeviceName ? pustrDeviceName->Buffer : 0);
+            return NULL;
+        }
+    }
+    else
+    {
+        pGraphicsDevice = gpPrimaryGraphicsDevice;
+    }
+
+    /* Allocate a new PDEVOBJ */
+    ppdev = PDEVOBJ_AllocPDEV();
+    if (!ppdev)
+    {
+        DPRINT1("failed to allocate a PDEV\n");
+        return NULL;
+    }
+
+    /* If no DEVMODEW is given, ... */
+    if (!pdm)
+    {
+        /* ... use the device's default one */
+        pdm = pGraphicsDevice->pDevModeList[pGraphicsDevice->iDefaultMode].pdm;
+        DPRINT1("Using iDefaultMode = %ld\n", pGraphicsDevice->iDefaultMode);
+    }
+
+    /* Try to get a diplay driver */
+    ppdev->pldev = EngLoadImageEx(pdm->dmDeviceName, LDEV_DEVICE_DISPLAY);
+    if (!ppdev->pldev)
+    {
+        DPRINT1("Could not load display driver '%ls'\n",
+                pGraphicsDevice->pDiplayDrivers);
+        ExFreePoolWithTag(ppdev, GDITAG_PDEV);
+        return NULL;
+    }
+
+    /* Copy the function table */
+    ppdev->pfn = ppdev->pldev->pfn;
+
+    /* Set MovePointer function */
+    ppdev->pfnMovePointer = ppdev->pfn.MovePointer;
+    if (!ppdev->pfnMovePointer)
+        ppdev->pfnMovePointer = EngMovePointer;
+
+    ppdev->pGraphicsDevice = pGraphicsDevice;
+    ppdev->hsemDevLock = EngCreateSemaphore();
+    // Should we change the ative mode of pGraphicsDevice ?
+    ppdev->pdmwDev = PDEVOBJ_pdmMatchDevMode(ppdev, pdm) ;
+
+    /* FIXME! */
+    ppdev->flFlags = PDEV_DISPLAY;
+
+    /* HACK: Don't use the pointer */
+    ppdev->Pointer.Exclude.right = -1;
+
+    /* Call the driver to enable the PDEV */
+    if (!PDEVOBJ_bEnablePDEV(ppdev, pdm, NULL))
+    {
+        DPRINT1("Failed to enable PDEV!\n");
+        ASSERT(FALSE);
+    }
+
+    /* FIXME: this must be done in a better way */
+    pGraphicsDevice->StateFlags |= DISPLAY_DEVICE_ATTACHED_TO_DESKTOP;
+
+    /* Tell the driver that the PDEV is ready */
+    PDEVOBJ_vCompletePDEV(ppdev);
+
+    /* Return the PDEV */
+    return ppdev;
+}
+
+VOID
+NTAPI
+PDEVOBJ_vSwitchPdev(
+    PPDEVOBJ ppdev,
+    PPDEVOBJ ppdev2)
+{
+    PDEVOBJ pdevTmp;
+    DWORD tmpStateFlags;
+
+    /* Exchange data */
+    pdevTmp = *ppdev;
+
+    /* Exchange driver functions */
+    ppdev->pfn = ppdev2->pfn;
+    ppdev2->pfn = pdevTmp.pfn;
+
+    /* Exchange LDEVs */
+    ppdev->pldev = ppdev2->pldev;
+    ppdev2->pldev = pdevTmp.pldev;
+
+    /* Exchange DHPDEV */
+    ppdev->dhpdev = ppdev2->dhpdev;
+    ppdev2->dhpdev = pdevTmp.dhpdev;
+
+    /* Exchange surfaces and associate them with their new PDEV */
+    ppdev->pSurface = ppdev2->pSurface;
+    ppdev2->pSurface = pdevTmp.pSurface;
+    ppdev->pSurface->SurfObj.hdev = (HDEV)ppdev;
+    ppdev2->pSurface->SurfObj.hdev = (HDEV)ppdev2;
+
+    /* Exchange devinfo */
+    ppdev->devinfo = ppdev2->devinfo;
+    ppdev2->devinfo = pdevTmp.devinfo;
+
+    /* Exchange gdiinfo */
+    ppdev->gdiinfo = ppdev2->gdiinfo;
+    ppdev2->gdiinfo = pdevTmp.gdiinfo;
+
+    /* Exchange DEVMODE */
+    ppdev->pdmwDev = ppdev2->pdmwDev;
+    ppdev2->pdmwDev = pdevTmp.pdmwDev;
+
+    /* Exchange state flags */
+    tmpStateFlags = ppdev->pGraphicsDevice->StateFlags;
+    ppdev->pGraphicsDevice->StateFlags = ppdev2->pGraphicsDevice->StateFlags;
+    ppdev2->pGraphicsDevice->StateFlags = tmpStateFlags;
+
+    /* Notify each driver instance of its new HDEV association */
+    ppdev->pfn.CompletePDEV(ppdev->dhpdev, (HDEV)ppdev);
+    ppdev2->pfn.CompletePDEV(ppdev2->dhpdev, (HDEV)ppdev2);
+}
+
+
+BOOL
+NTAPI
+PDEVOBJ_bSwitchMode(
+    PPDEVOBJ ppdev,
+    PDEVMODEW pdm)
+{
+    UNICODE_STRING ustrDevice;
+    PPDEVOBJ ppdevTmp;
+    PSURFACE pSurface;
+    BOOL retval = FALSE;
+
+    /* Lock the PDEV */
+    EngAcquireSemaphore(ppdev->hsemDevLock);
+    /* And everything else */
+    EngAcquireSemaphore(ghsemPDEV);
+
+    DPRINT1("PDEVOBJ_bSwitchMode, ppdev = %p, pSurface = %p\n", ppdev, ppdev->pSurface);
+
+    // Lookup the GraphicsDevice + select DEVMODE
+    // pdm = PDEVOBJ_pdmMatchDevMode(ppdev, pdm);
+
+    /* 1. Temporarily disable the current PDEV */
+    if (!ppdev->pfn.AssertMode(ppdev->dhpdev, FALSE))
+    {
+        DPRINT1("DrvAssertMode failed\n");
+        goto leave;
+    }
+
+    /* 2. Create new PDEV */
+    RtlInitUnicodeString(&ustrDevice, ppdev->pGraphicsDevice->szWinDeviceName);
+    ppdevTmp = EngpCreatePDEV(&ustrDevice, pdm);
+    if (!ppdevTmp)
+    {
+        DPRINT1("Failed to create a new PDEV\n");
+        goto leave;
+    }
+
+    /* 3. Create a new surface */
+    pSurface = PDEVOBJ_pSurface(ppdevTmp);
+    if (!pSurface)
+    {
+        DPRINT1("DrvEnableSurface failed\n");
+        goto leave;
+    }
+
+    /* 4. Get DirectDraw information */
+    /* 5. Enable DirectDraw Not traced */
+    /* 6. Copy old PDEV state to new PDEV instance */
+
+    /* 7. Switch the PDEVs */
+    PDEVOBJ_vSwitchPdev(ppdev, ppdevTmp);
+
+    /* 8. Disable DirectDraw */
+
+    PDEVOBJ_vRelease(ppdevTmp);
+
+    /* Update primary display capabilities */
+    if(ppdev == gppdevPrimary)
+    {
+        PDEVOBJ_vGetDeviceCaps(ppdev, &GdiHandleTable->DevCaps);
+    }
+
+    /* Success! */
+    retval = TRUE;
+leave:
+    /* Unlock PDEV */
+    EngReleaseSemaphore(ppdev->hsemDevLock);
+    EngReleaseSemaphore(ghsemPDEV);
+
+    DPRINT1("leave, ppdev = %p, pSurface = %p\n", ppdev, ppdev->pSurface);
+
+    return retval;
+}
+
+
+PPDEVOBJ
+NTAPI
+EngpGetPDEV(
+    PUNICODE_STRING pustrDeviceName)
+{
+    UNICODE_STRING ustrCurrent;
+    PPDEVOBJ ppdev;
+    PGRAPHICS_DEVICE pGraphicsDevice;
+
+    /* Acquire PDEV lock */
+    EngAcquireSemaphore(ghsemPDEV);
+
+    /* If no device name is given, ... */
+    if (!pustrDeviceName && gppdevPrimary)
+    {
+        /* ... use the primary PDEV */
+        ppdev = gppdevPrimary;
+
+        /* Reference the pdev */
+        InterlockedIncrement(&ppdev->cPdevRefs);
+        goto leave;
+    }
+
+    /* Loop all present PDEVs */
+    for (ppdev = gppdevList; ppdev; ppdev = ppdev->ppdevNext)
+    {
+        /* Get a pointer to the GRAPHICS_DEVICE */
+        pGraphicsDevice = ppdev->pGraphicsDevice;
+
+        /* Compare the name */
+        RtlInitUnicodeString(&ustrCurrent, pGraphicsDevice->szWinDeviceName);
+        if (RtlEqualUnicodeString(pustrDeviceName, &ustrCurrent, FALSE))
+        {
+            /* Found! Reference the PDEV */
+            InterlockedIncrement(&ppdev->cPdevRefs);
+            break;
+        }
+    }
+
+    /* Did we find one? */
+    if (!ppdev)
+    {
+        /* No, create a new PDEV */
+        ppdev = EngpCreatePDEV(pustrDeviceName, NULL);
+        if (ppdev)
+        {
+            /* Insert the PDEV into the list */
+            ppdev->ppdevNext = gppdevList;
+            gppdevList = ppdev;
+
+            /* Set as primary PDEV, if we don't have one yet */
+            if (!gppdevPrimary)
+            {
+                gppdevPrimary = ppdev;
+                ppdev->pGraphicsDevice->StateFlags |= DISPLAY_DEVICE_PRIMARY_DEVICE;
+            }
+        }
+    }
+
+leave:
+    /* Release PDEV lock */
+    EngReleaseSemaphore(ghsemPDEV);
+
+    return ppdev;
+}
+
+INT
+NTAPI
+PDEVOBJ_iGetColorManagementCaps(PPDEVOBJ ppdev)
+{
+    INT ret = CM_NONE;
+
+    if (ppdev->flFlags & PDEV_DISPLAY)
+    {
+        if (ppdev->devinfo.iDitherFormat == BMF_8BPP ||
+            ppdev->devinfo.flGraphicsCaps2 & GCAPS2_CHANGEGAMMARAMP)
+            ret = CM_GAMMA_RAMP;
+    }
+
+    if (ppdev->devinfo.flGraphicsCaps & GCAPS_CMYKCOLOR)
+        ret |= CM_CMYK_COLOR;
+    if (ppdev->devinfo.flGraphicsCaps & GCAPS_ICM)
+        ret |= CM_DEVICE_ICM;
+
+    return ret;
+}
+
+VOID
+NTAPI
+PDEVOBJ_vGetDeviceCaps(
+    IN PPDEVOBJ ppdev,
+    OUT PDEVCAPS pDevCaps)
+{
+    PGDIINFO pGdiInfo = &ppdev->gdiinfo;
+
+    pDevCaps->ulVersion = pGdiInfo->ulVersion;
+    pDevCaps->ulTechnology = pGdiInfo->ulTechnology;
+    pDevCaps->ulHorzSizeM = (pGdiInfo->ulHorzSize + 500) / 1000;
+    pDevCaps->ulVertSizeM = (pGdiInfo->ulVertSize + 500) / 1000;
+    pDevCaps->ulHorzSize = pGdiInfo->ulHorzSize;
+    pDevCaps->ulVertSize = pGdiInfo->ulVertSize;
+    pDevCaps->ulHorzRes = pGdiInfo->ulHorzRes;
+    pDevCaps->ulVertRes = pGdiInfo->ulVertRes;
+    pDevCaps->ulBitsPixel = pGdiInfo->cBitsPixel;
+    if (pDevCaps->ulBitsPixel == 15) pDevCaps->ulBitsPixel = 16;
+    pDevCaps->ulPlanes = pGdiInfo->cPlanes;
+    pDevCaps->ulNumPens = pGdiInfo->ulNumColors;
+    if (pDevCaps->ulNumPens != -1) pDevCaps->ulNumPens *= 5;
+    pDevCaps->ulNumFonts = 0; // PDEVOBJ_cFonts(ppdev);
+    pDevCaps->ulNumColors = pGdiInfo->ulNumColors;
+    pDevCaps->ulRasterCaps = pGdiInfo->flRaster;
+    pDevCaps->ulAspectX = pGdiInfo->ulAspectX;
+    pDevCaps->ulAspectY = pGdiInfo->ulAspectY;
+    pDevCaps->ulAspectXY = pGdiInfo->ulAspectXY;
+    pDevCaps->ulLogPixelsX = pGdiInfo->ulLogPixelsX;
+    pDevCaps->ulLogPixelsY = pGdiInfo->ulLogPixelsY;
+    pDevCaps->ulSizePalette = pGdiInfo->ulNumPalReg;
+    pDevCaps->ulColorRes = pGdiInfo->ulDACRed +
+                           pGdiInfo->ulDACGreen +
+                           pGdiInfo->ulDACBlue;
+    pDevCaps->ulPhysicalWidth = pGdiInfo->szlPhysSize.cx;
+    pDevCaps->ulPhysicalHeight = pGdiInfo->szlPhysSize.cy;
+    pDevCaps->ulPhysicalOffsetX = pGdiInfo->ptlPhysOffset.x;
+    pDevCaps->ulPhysicalOffsetY = pGdiInfo->ptlPhysOffset.y;
+    pDevCaps->ulTextCaps = pGdiInfo->flTextCaps;
+    pDevCaps->ulTextCaps |= (TC_SO_ABLE|TC_UA_ABLE|TC_CP_STROKE|TC_OP_STROKE|TC_OP_CHARACTER);
+    if (pGdiInfo->ulTechnology != DT_PLOTTER)
+        pDevCaps->ulTextCaps |= TC_VA_ABLE;
+    pDevCaps->ulVRefresh = pGdiInfo->ulVRefresh;
+    pDevCaps->ulDesktopHorzRes = pGdiInfo->ulHorzRes;
+    pDevCaps->ulDesktopVertRes = pGdiInfo->ulVertRes;
+    pDevCaps->ulBltAlignment = pGdiInfo->ulBltAlignment;
+    pDevCaps->ulPanningHorzRes = pGdiInfo->ulPanningHorzRes;
+    pDevCaps->ulPanningVertRes = pGdiInfo->ulPanningVertRes;
+    pDevCaps->xPanningAlignment = pGdiInfo->xPanningAlignment;
+    pDevCaps->yPanningAlignment = pGdiInfo->yPanningAlignment;
+    pDevCaps->ulShadeBlend = pGdiInfo->flShadeBlend;
+    pDevCaps->ulColorMgmtCaps = PDEVOBJ_iGetColorManagementCaps(ppdev);
+}
+
+
+/** Exported functions ********************************************************/
+
+LPWSTR
+APIENTRY
+EngGetDriverName(IN HDEV hdev)
+{
+    PPDEVOBJ ppdev = (PPDEVOBJ)hdev;
+    PLDEVOBJ pldev;
+
+    if (!hdev)
+        return NULL;
+
+    pldev = ppdev->pldev;
+    ASSERT(pldev);
+
+    if (!pldev->pGdiDriverInfo)
+        return NULL;
+
+    return pldev->pGdiDriverInfo->DriverName.Buffer;
+}
+
+
+INT
+APIENTRY
+NtGdiGetDeviceCaps(
+    HDC hdc,
+    INT Index)
+{
+    PDC pdc;
+    DEVCAPS devcaps;
+
+    /* Lock the given DC */
+    pdc = DC_LockDc(hdc);
+    if (!pdc)
+    {
+        SetLastWin32Error(ERROR_INVALID_HANDLE);
+        return 0;
+    }
+
+    /* Get the data */
+    PDEVOBJ_vGetDeviceCaps(pdc->ppdev, &devcaps);
+
+    /* Unlock the DC */
+    DC_UnlockDc(pdc);
+
+    /* Return capability */
+    switch (Index)
+    {
+        case DRIVERVERSION:
+            return devcaps.ulVersion;
+
+        case TECHNOLOGY:
+            return devcaps.ulTechnology;
+
+        case HORZSIZE:
+            return devcaps.ulHorzSize;
+
+        case VERTSIZE:
+            return devcaps.ulVertSize;
+
+        case HORZRES:
+            return devcaps.ulHorzRes;
+
+        case VERTRES:
+            return devcaps.ulVertRes;
+
+        case LOGPIXELSX:
+            return devcaps.ulLogPixelsX;
+
+        case LOGPIXELSY:
+            return devcaps.ulLogPixelsY;
+
+        case BITSPIXEL:
+            return devcaps.ulBitsPixel;
+
+        case PLANES:
+            return devcaps.ulPlanes;
+
+        case NUMBRUSHES:
+            return -1;
+
+        case NUMPENS:
+            return devcaps.ulNumPens;
+
+        case NUMFONTS:
+            return devcaps.ulNumFonts;
+
+        case NUMCOLORS:
+            return devcaps.ulNumColors;
+
+        case ASPECTX:
+            return devcaps.ulAspectX;
+
+        case ASPECTY:
+            return devcaps.ulAspectY;
+
+        case ASPECTXY:
+            return devcaps.ulAspectXY;
+
+        case CLIPCAPS:
+            return CP_RECTANGLE;
+
+        case SIZEPALETTE:
+            return devcaps.ulSizePalette;
+
+        case NUMRESERVED:
+            return 20;
+
+        case COLORRES:
+            return devcaps.ulColorRes;
+
+        case DESKTOPVERTRES:
+            return devcaps.ulVertRes;
+
+        case DESKTOPHORZRES:
+            return devcaps.ulHorzRes;
+
+        case BLTALIGNMENT:
+            return devcaps.ulBltAlignment;
+
+        case SHADEBLENDCAPS:
+            return devcaps.ulShadeBlend;
+
+        case COLORMGMTCAPS:
+            return devcaps.ulColorMgmtCaps;
+
+        case PHYSICALWIDTH:
+            return devcaps.ulPhysicalWidth;
+
+        case PHYSICALHEIGHT:
+            return devcaps.ulPhysicalHeight;
+
+        case PHYSICALOFFSETX:
+            return devcaps.ulPhysicalOffsetX;
+
+        case PHYSICALOFFSETY:
+            return devcaps.ulPhysicalOffsetY;
+
+        case VREFRESH:
+            return devcaps.ulVRefresh;
+
+        case RASTERCAPS:
+            return devcaps.ulRasterCaps;
+
+        case CURVECAPS:
+            return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
+                    CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
+
+        case LINECAPS:
+            return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
+                    LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
+
+        case POLYGONALCAPS:
+            return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
+                    PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
+
+        case TEXTCAPS:
+            return devcaps.ulTextCaps;
+
+        case CAPS1:
+        case PDEVICESIZE:
+        case SCALINGFACTORX:
+        case SCALINGFACTORY:
+        default:
+            return 0;
+    }
+
+    return 0;
+}
+
+
+BOOL
+APIENTRY
+NtGdiGetDeviceCapsAll(
+    IN HDC hDC,
+    OUT PDEVCAPS pDevCaps)
+{
+    PDC pdc;
+    DEVCAPS devcaps;
+    BOOL bResult = TRUE;
+
+    /* Lock the given DC */
+    pdc = DC_LockDc(hDC);
+    if (!pdc)
+    {
+        SetLastWin32Error(ERROR_INVALID_HANDLE);
+        return FALSE;
+    }
+
+    /* Get the data */
+    PDEVOBJ_vGetDeviceCaps(pdc->ppdev, &devcaps);
+
+    /* Unlock the DC */
+    DC_UnlockDc(pdc);
+
+    /* Copy data to caller */
+    _SEH2_TRY
+    {
+        ProbeForWrite(pDevCaps, sizeof(DEVCAPS), 1);
+        RtlCopyMemory(pDevCaps, &devcaps, sizeof(DEVCAPS));
+    }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+        SetLastNtError(_SEH2_GetExceptionCode());
+        bResult = FALSE;
+    }
+    _SEH2_END;
+
+    return bResult;
+}
+
+DHPDEV
+APIENTRY
+NtGdiGetDhpdev(
+    IN HDEV hdev)
+{
+    PPDEVOBJ ppdev;
+    DHPDEV dhpdev = NULL;
+
+    /* Check parameter */
+    if (!hdev || (PCHAR)hdev < (PCHAR)MmSystemRangeStart)
+        return NULL;
+
+    /* Lock PDEV list */
+    EngAcquireSemaphore(ghsemPDEV);
+
+    /* Walk through the list of PDEVs */
+    for (ppdev = gppdevList;  ppdev; ppdev = ppdev->ppdevNext)
+    {
+        /* Compare with the given HDEV */
+        if (ppdev == hdev)
+        {
+            /* Found the PDEV! Get it's dhpdev and break */
+            dhpdev = ppdev->dhpdev;
+            break;
+        }
+    }
+
+    /* Unlock PDEV list */
+    EngReleaseSemaphore(ghsemPDEV);
+
+    return dhpdev;
+}
+
+PSIZEL
+FASTCALL
+PDEVOBJ_sizl(PPDEVOBJ ppdev, PSIZEL psizl)
+{
+    if (ppdev->flFlags & PDEV_META_DEVICE)
+    {
+        psizl->cx = ppdev->ulHorzRes;
+        psizl->cy = ppdev->ulVertRes;
+    }
+    else
+    {
+        psizl->cx = ppdev->gdiinfo.ulHorzRes;
+        psizl->cy = ppdev->gdiinfo.ulVertRes;
+    }
+    return psizl;
+}
diff --git a/reactos/subsystems/win32/win32k/eng/rlecomp.c b/reactos/subsystems/win32/win32k/eng/rlecomp.c
new file mode 100644 (file)
index 0000000..dc8a071
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * COPYRIGHT:         See COPYING in the top level directory
+ * PROJECT:           ReactOS kernel
+ * PURPOSE:           RLE compression
+ * FILE:              subsystems/win32k/eng/rlecomp.c
+ * PROGRAMER:         Jason Filby
+ */
+
+#include <win32k.h>
+
+#define NDEBUG
+#include <debug.h>
+
+enum Rle_EscapeCodes
+{
+    RLE_EOL   = 0, /* End of line */
+    RLE_END   = 1, /* End of bitmap */
+    RLE_DELTA = 2  /* Delta */
+};
+
+VOID DecompressBitmap(SIZEL Size, BYTE *CompressedBits, BYTE *UncompressedBits, LONG Delta, ULONG Format)
+{
+    INT x = 0;
+    INT y = Size.cy - 1;
+    INT c;
+    INT length;
+    INT width;
+    INT height = Size.cy - 1;
+    BYTE *begin = CompressedBits;
+    BYTE *bits = CompressedBits;
+    BYTE *temp;
+    INT shift = 0;
+
+    if (Format == BMF_4RLE)
+        shift = 1;
+    else if(Format != BMF_8RLE)
+        return;
+
+    width = ((Size.cx + shift) >> shift);
+
+    _SEH2_TRY
+    {
+        while (y >= 0)
+        {
+            length = (*bits++) >> shift;
+            if (length)
+            {
+                c = *bits++;
+                while (length--)
+                {
+                    if (x >= width) break;
+                    temp = UncompressedBits + (((height - y) * Delta) + x);
+                    x++;
+                    *temp = c;
+                }
+            }
+            else
+            {
+                length = *bits++;
+                switch (length)
+                {
+                case RLE_EOL:
+                    x = 0;
+                    y--;
+                    break;
+                case RLE_END:
+                    _SEH2_YIELD(return);
+                case RLE_DELTA:
+                    x += (*bits++) >> shift;
+                    y -= (*bits++) >> shift;
+                    break;
+                default:
+                    length = length >> shift;
+                    while (length--)
+                    {
+                        c = *bits++;
+                        if (x < width)
+                        {
+                            temp = UncompressedBits + (((height - y) * Delta) + x);
+                            x++;
+                            *temp = c;
+                        }
+                    }
+                    if ((bits - begin) & 1)
+                    {
+                        bits++;
+                    }
+                }
+            }
+        }
+    }
+    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    {
+        DPRINT1("Decoding error\n");
+    }
+    _SEH2_END;
+
+    return;
+}
index d09d4c9..ce9780f 100644 (file)
@@ -69,6 +69,19 @@ EngReleaseSemaphore ( IN HSEMAPHORE hsem )
   IntGdiReleaseSemaphore ( hsem );
 }
 
+VOID
+NTAPI
+EngAcquireSemaphoreShared(
+    IN HSEMAPHORE hsem)
+{
+    PTHREADINFO pti;
+
+    ASSERT(hsem);
+    ExEnterCriticalRegionAndAcquireResourceShared((PERESOURCE)hsem);
+    pti = PsGetThreadWin32Thread(PsGetCurrentThread());
+    if (pti) ++pti->dwEngAcquireCount;
+}
+
 /*
  * @implemented
  */
index 932d93d..a6f3d4f 100644 (file)
@@ -462,25 +462,16 @@ IntEngStretchBlt(SURFOBJ *psoDest,
 
     /* No success yet */
     ret = FALSE;
-    SURFACE_LockBitmapBits(psurfDest);
-    MouseSafetyOnDrawStart(psoDest, OutputRect.left, OutputRect.top,
-                           OutputRect.right, OutputRect.bottom);
 
     if (UsesSource)
     {
         psurfSource = CONTAINING_RECORD(psoSource, SURFACE, SurfObj);
-        if (psoSource != psoDest)
-        {
-            SURFACE_LockBitmapBits(psurfSource);
-        }
-        MouseSafetyOnDrawStart(psoSource, InputRect.left, InputRect.top,
-                               InputRect.right, InputRect.bottom);
     }
 
     /* Prepare color adjustment */
 
     /* Call the driver's DrvStretchBlt if available */
-    if (psurfDest->flHooks & HOOK_STRETCHBLTROP)
+    if (psurfDest->flags & HOOK_STRETCHBLTROP)
     {
         /* Drv->StretchBltROP (look at http://www.osronline.com/ddkx/graphics/ddifncs_0z3b.htm ) */
         ret = GDIDEVFUNCS(psoDest).StretchBltROP(psoDest,
@@ -514,17 +505,6 @@ IntEngStretchBlt(SURFOBJ *psoDest,
                                ROP);
     }
 
-    if (UsesSource)
-    {
-        MouseSafetyOnDrawEnd(psoSource);
-        if (psoSource != psoDest)
-        {
-            SURFACE_UnlockBitmapBits(psurfSource);
-        }
-    }
-    MouseSafetyOnDrawEnd(psoDest);
-    SURFACE_UnlockBitmapBits(psurfDest);
-
     return ret;
 }
 
index 126ae95..622b99d 100644 (file)
@@ -3,7 +3,8 @@
  * PROJECT:           ReactOS kernel
  * PURPOSE:           GDI Driver Surace Functions
  * FILE:              subsys/win32k/eng/surface.c
- * PROGRAMER:         Jason Filby
+ * PROGRAMERS:        Jason Filby
+ *                    Timo Kreuzer
  * REVISION HISTORY:
  *                 3/7/1999: Created
  *                 9/11/2000: Updated to handle real pixel packed bitmaps (UPDATE TO DATE COMPLETED)
 #define NDEBUG
 #include <debug.h>
 
-enum Rle_EscapeCodes
-{
-    RLE_EOL   = 0, /* End of line */
-    RLE_END   = 1, /* End of bitmap */
-    RLE_DELTA = 2  /* Delta */
-};
+ULONG giUniqueSurface = 0;
 
-INT FASTCALL BitsPerFormat(ULONG Format)
+UCHAR
+gajBitsPerFormat[11] =
 {
-    switch (Format)
-    {
-        case BMF_1BPP:
-            return 1;
-
-        case BMF_4BPP:
-            /* Fall through */
-        case BMF_4RLE:
-            return 4;
-
-        case BMF_8BPP:
-            /* Fall through */
-        case BMF_8RLE:
-            return 8;
-
-        case BMF_16BPP:
-            return 16;
-
-        case BMF_24BPP:
-            return 24;
+    0, /*  0: unused */
+    1, /*  1: BMF_1BPP */
+    4, /*  2: BMF_4BPP */
+    8, /*  3: BMF_8BPP */
+   16, /*  4: BMF_16BPP */
+   24, /*  5: BMF_24BPP */
+   32, /*  6: BMF_32BPP */
+    4, /*  7: BMF_4RLE */
+    8, /*  8: BMF_8RLE */
+    0, /*  9: BMF_JPEG */
+    0, /* 10: BMF_PNG */
+};
 
-        case BMF_32BPP:
-            return 32;
-
-        default:
-            return 0;
-    }
-}
 
 ULONG FASTCALL BitmapFormat(WORD Bits, DWORD Compression)
 {
@@ -90,534 +72,238 @@ ULONG FASTCALL BitmapFormat(WORD Bits, DWORD Compression)
     }
 }
 
-BOOL INTERNAL_CALL
+BOOL
+INTERNAL_CALL
 SURFACE_Cleanup(PVOID ObjectBody)
 {
     PSURFACE psurf = (PSURFACE)ObjectBody;
     PVOID pvBits = psurf->SurfObj.pvBits;
+    NTSTATUS Status;
 
-    /* If this is an API bitmap, free the bits */
-    if (pvBits != NULL &&
-        (psurf->flFlags & BITMAPOBJ_IS_APIBITMAP))
+    /* Check if the surface has bits */
+    if (pvBits)
     {
-        /* Check if we have a DIB section */
-        if (psurf->hSecure)
+        /* Only bitmaps can have bits */
+        ASSERT(psurf->SurfObj.iType == STYPE_BITMAP);
+
+        /* Check if it is a DIB section */
+        if (psurf->hDIBSection)
         {
-            // FIXME: IMPLEMENT ME!
-            // MmUnsecureVirtualMemory(psurf->hSecure);
-            if (psurf->hDIBSection)
+            /* Unsecure the memory */
+            EngUnsecureMem(psurf->hSecure);
+
+            /* Calculate the real start of the section */
+            pvBits = (PVOID)((ULONG_PTR)pvBits - psurf->dwOffset);
+
+            /* Unmap the section */
+            Status = MmUnmapViewOfSection(PsGetCurrentProcess(), pvBits);
+            if (!NT_SUCCESS(Status))
             {
-                /* DIB was created from a section */
-                NTSTATUS Status;
-
-                pvBits = (PVOID)((ULONG_PTR)pvBits - psurf->dwOffset);
-                Status = ZwUnmapViewOfSection(NtCurrentProcess(), pvBits);
-                if (!NT_SUCCESS(Status))
-                {
-                    DPRINT1("Could not unmap section view!\n");
-                    // Should we BugCheck here?
-                }
+                DPRINT1("Could not unmap section view!\n");
+                // Should we BugCheck here?
+                ASSERT(FALSE);
             }
-            else
+        }
+        else if (psurf->SurfObj.fjBitmap & BMF_USERMEM)
+        {
+            /* Bitmap was allocated from usermode memory */
+            EngFreeUserMem(pvBits);
+        }
+        else if (psurf->SurfObj.fjBitmap & BMF_KMSECTION)
+        {
+            /* Bitmap was allocated from a kernel section */
+            if (!EngFreeSectionMem(NULL, pvBits))
             {
-                /* DIB was allocated */
-                EngFreeUserMem(pvBits);
+                DPRINT1("EngFreeSectionMem failed for %p!\n", pvBits);
+                // Should we BugCheck here?
+                ASSERT(FALSE);
             }
         }
-        else
+        else if (psurf->SurfObj.fjBitmap & BMF_RLE_HACK)
         {
-            // FIXME: use TAG
-            ExFreePool(psurf->SurfObj.pvBits);
+            /* HACK: Free RLE decompressed bits */
+            EngFreeMem(pvBits);
         }
-
-        if (psurf->hDIBPalette != NULL)
+        else
         {
-            GreDeleteObject(psurf->hDIBPalette);
+            /* There should be nothing to free */
+            ASSERT(psurf->SurfObj.fjBitmap & BMF_DONT_FREE);
         }
     }
 
-    if (NULL != psurf->BitsLock)
-    {
-        ExFreePoolWithTag(psurf->BitsLock, TAG_SURFACE);
-        psurf->BitsLock = NULL;
-    }
-
-    return TRUE;
-}
-
-BOOL INTERNAL_CALL
-SURFACE_InitBitsLock(PSURFACE psurf)
-{
-    psurf->BitsLock = ExAllocatePoolWithTag(NonPagedPool,
-                          sizeof(FAST_MUTEX),
-                          TAG_SURFACE);
-    if (NULL == psurf->BitsLock)
+    /* Free palette */
+    if(psurf->ppal)
     {
-        return FALSE;
+        PALETTE_ShareUnlockPalette(psurf->ppal);
     }
 
-    ExInitializeFastMutex(psurf->BitsLock);
-
     return TRUE;
 }
 
-void INTERNAL_CALL
-SURFACE_CleanupBitsLock(PSURFACE psurf)
-{
-    if (NULL != psurf->BitsLock)
-    {
-        ExFreePoolWithTag(psurf->BitsLock, TAG_SURFACE);
-        psurf->BitsLock = NULL;
-    }
-}
-
 
-/*
- * @implemented
- */
-HBITMAP APIENTRY
-EngCreateDeviceBitmap(IN DHSURF dhsurf,
-                      IN SIZEL Size,
-                      IN ULONG Format)
+PSURFACE
+NTAPI
+SURFACE_AllocSurface(
+    IN ULONG iType,
+    IN ULONG cx,
+    IN ULONG cy,
+    IN ULONG iFormat)
 {
-    HBITMAP NewBitmap;
+    PSURFACE psurf;
     SURFOBJ *pso;
 
-    NewBitmap = EngCreateBitmap(Size, DIB_GetDIBWidthBytes(Size.cx, BitsPerFormat(Format)), Format, 0, NULL);
-    if (!NewBitmap)
-    {
-        DPRINT1("EngCreateBitmap failed\n");
-        return 0;
-    }
-
-    pso = EngLockSurface((HSURF)NewBitmap);
-    if (!pso)
+    /* Verify format */
+    if (iFormat < BMF_1BPP || iFormat > BMF_PNG)
     {
-        DPRINT1("EngLockSurface failed on newly created bitmap!\n");
-        GreDeleteObject(NewBitmap);
+        DPRINT1("Invalid bitmap format: %ld\n", iFormat);
         return NULL;
     }
 
-    pso->dhsurf = dhsurf;
-    EngUnlockSurface(pso);
-
-    return NewBitmap;
-}
+    /* Allocate a SURFACE object */
+    psurf = (PSURFACE)GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_BITMAP);
 
-BOOL DecompressBitmap(SIZEL Size, BYTE *CompressedBits, BYTE *UncompressedBits, LONG Delta, ULONG Format)
-{
-    INT x = 0;
-    INT y = Size.cy - 1;
-    INT c;
-    INT length;
-    INT width;
-    INT height = Size.cy - 1;
-    BYTE *begin = CompressedBits;
-    BYTE *bits = CompressedBits;
-    BYTE *temp;
-    INT shift = 0;
-
-    if (Format == BMF_4RLE)
-        shift = 1;
-    else if(Format != BMF_8RLE)
-        return FALSE;
-
-    width = ((Size.cx + shift) >> shift);
-
-    _SEH2_TRY
-    {
-        while (y >= 0)
-        {
-            length = (*bits++) >> shift;
-            if (length)
-            {
-                c = *bits++;
-                while (length--)
-                {
-                    if (x >= width) break;
-                    temp = UncompressedBits + (((height - y) * Delta) + x);
-                    x++;
-                    *temp = c;
-                }
-            }
-            else
-            {
-                length = *bits++;
-                switch (length)
-                {
-                case RLE_EOL:
-                    x = 0;
-                    y--;
-                    break;
-                case RLE_END:
-                    _SEH2_YIELD(return TRUE);
-                case RLE_DELTA:
-                    x += (*bits++) >> shift;
-                    y -= (*bits++) >> shift;
-                    break;
-                default:
-                    length = length >> shift;
-                    while (length--)
-                    {
-                        c = *bits++;
-                        if (x < width)
-                        {
-                            temp = UncompressedBits + (((height - y) * Delta) + x);
-                            x++;
-                            *temp = c;
-                        }
-                    }
-                    if ((bits - begin) & 1)
-                    {
-                        bits++;
-                    }
-                }
-            }
-        }
-    }
-    _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
+    if (psurf)
     {
-        DPRINT1("Decoding error\n");
-        _SEH2_YIELD(return FALSE);
+        /* Initialize the basic fields */
+        pso = &psurf->SurfObj;
+        pso->hsurf = psurf->BaseObject.hHmgr;
+        pso->sizlBitmap.cx = cx;
+        pso->sizlBitmap.cy = cy;
+        pso->iBitmapFormat = iFormat;
+        pso->iType = iType;
+        pso->iUniq = InterlockedIncrement((PLONG)&giUniqueSurface);
+
+        /* Assign a default palette and increment its reference count */
+        psurf->ppal = appalSurfaceDefault[iFormat];
+        GDIOBJ_IncrementShareCount(&psurf->ppal->BaseObject);
     }
-    _SEH2_END;
 
-    return TRUE;
+    return psurf;
 }
 
-HBITMAP FASTCALL
-IntCreateBitmap(IN SIZEL Size,
-                IN LONG Width,
-                IN ULONG Format,
-                IN ULONG Flags,
-                IN PVOID Bits)
+BOOL
+NTAPI
+SURFACE_bSetBitmapBits(
+    IN PSURFACE psurf,
+    IN USHORT fjBitmap,
+    IN ULONG ulWidth,
+    IN PVOID pvBits OPTIONAL)
 {
-    HBITMAP hbmp;
-    SURFOBJ *pso;
-    PSURFACE psurf;
-    PVOID UncompressedBits;
-    ULONG UncompressedFormat;
+    SURFOBJ *pso = &psurf->SurfObj;
+    PVOID pvSection;
+    UCHAR cBitsPixel;
 
-    if (Format == 0)
-        return 0;
+    /* Only bitmaps can have bits */
+    ASSERT(psurf->SurfObj.iType == STYPE_BITMAP);
 
-    psurf = SURFACE_AllocSurfaceWithHandle();
-    if (psurf == NULL)
-    {
-        return 0;
-    }
-    hbmp = psurf->BaseObject.hHmgr;
+    /* Get bits per pixel from the format */
+    cBitsPixel = gajBitsPerFormat[pso->iBitmapFormat];
 
-    if (! SURFACE_InitBitsLock(psurf))
+    /* Is a width in bytes given? */
+    if (ulWidth)
     {
-        SURFACE_UnlockSurface(psurf);
-        SURFACE_FreeSurfaceByHandle(hbmp);
-        return 0;
+        /* Align the width (Windows compatibility, drivers expect that) */
+        ulWidth = WIDTH_BYTES_ALIGN32((ulWidth << 3) / cBitsPixel, cBitsPixel);
     }
-    pso = &psurf->SurfObj;
+       else
+       {
+        /* Calculate width from the bitmap width in pixels */
+        ulWidth = WIDTH_BYTES_ALIGN32(pso->sizlBitmap.cx, cBitsPixel);
+       }
 
-    if (Format == BMF_4RLE)
-    {
-        pso->lDelta = DIB_GetDIBWidthBytes(Size.cx, BitsPerFormat(BMF_4BPP));
-        pso->cjBits = pso->lDelta * Size.cy;
-        UncompressedFormat = BMF_4BPP;
-        UncompressedBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
-        DecompressBitmap(Size, (BYTE *)Bits, (BYTE *)UncompressedBits, pso->lDelta, Format);
-    }
-    else if (Format == BMF_8RLE)
-    {
-        pso->lDelta = DIB_GetDIBWidthBytes(Size.cx, BitsPerFormat(BMF_8BPP));
-        pso->cjBits = pso->lDelta * Size.cy;
-        UncompressedFormat = BMF_8BPP;
-        UncompressedBits = EngAllocMem(FL_ZERO_MEMORY, pso->cjBits, TAG_DIB);
-        DecompressBitmap(Size, (BYTE *)Bits, (BYTE *)UncompressedBits, pso->lDelta, Format);
-    }
-    else
-    {
-        pso->lDelta = abs(Width);
-        pso->cjBits = pso->lDelta * Size.cy;
-        UncompressedBits = Bits;
-        UncompressedFormat = Format;
-    }
+    /* Calculate the bitmap size in bytes */
+    pso->cjBits = ulWidth * pso->sizlBitmap.cy;
 
-    if (UncompressedBits != NULL)
+    /* Did the caller provide bits? */
+    if (pvBits)
     {
-        pso->pvBits = UncompressedBits;
+        /* Yes, so let him free it */
+        fjBitmap |= BMF_DONT_FREE;
     }
-    else
+    else if (pso->cjBits)
     {
-        if (pso->cjBits == 0)
+        /* We must allocate memory, check what kind */
+        if (fjBitmap & BMF_USERMEM)
         {
-            pso->pvBits = NULL;
+            /* User mode memory was requested */
+            pvBits = EngAllocUserMem(pso->cjBits, 0);
         }
         else
         {
-            if (0 != (Flags & BMF_USERMEM))
-            {
-                pso->pvBits = EngAllocUserMem(pso->cjBits, 0);
-            }
-            else
-            {
-                pso->pvBits = EngAllocMem(0 != (Flags & BMF_NOZEROINIT) ?
-                                                  0 : FL_ZERO_MEMORY,
-                                              pso->cjBits, TAG_DIB);
-            }
-            if (pso->pvBits == NULL)
-            {
-                SURFACE_UnlockSurface(psurf);
-                SURFACE_FreeSurfaceByHandle(hbmp);
-                SetLastWin32Error(ERROR_NOT_ENOUGH_MEMORY);
-                return 0;
-            }
+            /* Use a kernel mode section */
+            fjBitmap |= BMF_KMSECTION;
+            pvBits = EngAllocSectionMem(&pvSection,
+                                        (fjBitmap & BMF_NOZEROINIT) ?
+                                                0 : FL_ZERO_MEMORY,
+                                        pso->cjBits, TAG_DIB);
+
+            /* Free the section already, but keep the mapping */
+            if (pvBits) EngFreeSectionMem(pvSection, NULL);
         }
+
+        /* Check for failure */
+        if (!pvBits) return FALSE;
     }
 
-    if (0 == (Flags & BMF_TOPDOWN))
+    /* Set pvBits, pvScan0 and lDelta */
+    pso->pvBits = pvBits;
+    if (fjBitmap & BMF_TOPDOWN)
     {
-        pso->pvScan0 = (PVOID)((ULONG_PTR)pso->pvBits + pso->cjBits - pso->lDelta);
-        pso->lDelta = - pso->lDelta;
+        /* Topdown is the normal way */
+        pso->pvScan0 = pso->pvBits;
+        pso->lDelta = ulWidth;
     }
     else
     {
-        pso->pvScan0 = pso->pvBits;
+        /* Inversed bitmap (bottom up) */
+        pso->pvScan0 = (PVOID)((ULONG_PTR)pso->pvBits + pso->cjBits - ulWidth);
+        pso->lDelta = -ulWidth;
     }
 
-    pso->dhsurf = 0; /* device managed surface */
-    pso->hsurf = (HSURF)hbmp;
-    pso->dhpdev = NULL;
-    pso->hdev = NULL;
-    pso->sizlBitmap = Size;
-    pso->iBitmapFormat = UncompressedFormat;
-    pso->iType = STYPE_BITMAP;
-    pso->fjBitmap = Flags & (BMF_TOPDOWN | BMF_NOZEROINIT);
-    pso->iUniq = 0;
-
-    psurf->flHooks = 0;
-    psurf->flFlags = 0;
-    psurf->dimension.cx = 0;
-    psurf->dimension.cy = 0;
-    
-    psurf->hSecure = NULL;
-    psurf->hDIBSection = NULL;
-
-    SURFACE_UnlockSurface(psurf);
+    pso->fjBitmap = fjBitmap;
 
-    return hbmp;
+    /* Success */
+    return TRUE;
 }
 
-/* Name gleaned from C++ symbol information for SURFMEM::bInitDIB */
-typedef struct _DEVBITMAPINFO
-{
-    ULONG Format;
-    ULONG Width;
-    ULONG Height;
-    ULONG Flags;
-    ULONG Size;
-} DEVBITMAPINFO, *PDEVBITMAPINFO;
-
-SURFOBJ*
-FASTCALL
-SURFMEM_bCreateDib(IN PDEVBITMAPINFO BitmapInfo,
-                   IN PVOID Bits)
+HBITMAP
+APIENTRY
+EngCreateBitmap(
+    IN SIZEL sizl,
+    IN LONG lWidth,
+    IN ULONG iFormat,
+    IN ULONG fl,
+    IN PVOID pvBits)
 {
-    BOOLEAN Compressed = FALSE;
-    ULONG ScanLine = 0; // Compiler is dumb
-    ULONG Size;
-    SURFOBJ *pso;
     PSURFACE psurf;
-    SIZEL LocalSize;
-    BOOLEAN AllocatedLocally = FALSE;
-    PVOID DecompressedBits = NULL;
-
-    /*
-     * First, check the format so we can get the aligned scanline width.
-     * RLE and the newer fancy-smanshy JPG/PNG support do NOT have scanlines
-     * since they are compressed surfaces!
-     */
-    switch (BitmapInfo->Format)
-    {
-        case BMF_1BPP:
-            ScanLine = ((BitmapInfo->Width + 31) & ~31) >> 3;
-            break;
-
-        case BMF_4BPP:
-            ScanLine = ((BitmapInfo->Width + 7) & ~7) >> 1;
-            break;
-
-        case BMF_8BPP:
-            ScanLine = (BitmapInfo->Width + 3) & ~3;
-            break;
-
-        case BMF_16BPP:
-            ScanLine = ((BitmapInfo->Width + 1) & ~1) << 1;
-            break;
-
-        case BMF_24BPP:
-            ScanLine = ((BitmapInfo->Width * 3) + 3) & ~3;
-            break;
-
-        case BMF_32BPP:
-            ScanLine = BitmapInfo->Width << 2;
-            break;
-
-        case BMF_8RLE:
-            ScanLine = (BitmapInfo->Width + 3) & ~3;
-            Compressed = TRUE;
-            break;
-        case BMF_4RLE:
-            ScanLine = ((BitmapInfo->Width + 7) & ~7) >> 1;
-            Compressed = TRUE;
-            break;
-
-        case BMF_JPEG:
-        case BMF_PNG:
-            ASSERT(FALSE); // ENGDDI shouldn't be creating PNGs for drivers ;-)
-            DPRINT1("No support for JPEG and PNG formats\n");
-            return NULL;
-
-        default:
-            DPRINT1("Invalid bitmap format\n");
-            return NULL;
-    }
-
-    /* Save local bitmap size */
-    LocalSize.cy = BitmapInfo->Height;
-    LocalSize.cx = BitmapInfo->Width;
-
-    /* Does the device manage its own surface? */
-    if (!Bits)
-    {
-        /* We need to allocate bits for the caller, figure out the size */
-        if (Compressed)
-        {
-            /* Note: we should not be seeing this scenario from ENGDDI */
-            ASSERT(FALSE);
-            DPRINT1("RLE compressed bitmap requested with no valid bitmap bits\n");
-            return NULL;
-        }
-        else
-        {
-            /* The height times the bytes for each scanline */
-            Size = BitmapInfo->Height * ScanLine;
-        }
-        
-        if (Size)
-        {
-            /* Check for allocation flag */
-            if (BitmapInfo->Flags & BMF_USERMEM)
-            {
-                /* Get the bits from user-mode memory */
-                Bits = EngAllocUserMem(Size, 'mbuG');
-            }
-            else
-            {
-                /* Get kernel bits (zeroed out if requested) */
-                Bits = EngAllocMem((BitmapInfo->Flags & BMF_NOZEROINIT) ? 0 : FL_ZERO_MEMORY,
-                                   Size,
-                                   TAG_DIB);
-            }
-            AllocatedLocally = TRUE;
-            /* Bail out if that failed */
-            if (!Bits) return NULL;
-        }
-    }
-    else
-    {
-        /* Should not have asked for user memory */
-        ASSERT((BitmapInfo->Flags & BMF_USERMEM) == 0);
-
-        if (Compressed)
-        {
-            DecompressedBits = EngAllocMem(FL_ZERO_MEMORY, BitmapInfo->Height * ScanLine, TAG_DIB);
-
-            if(!DecompressedBits)
-                return NULL;
-
-            if(!DecompressBitmap(LocalSize, (BYTE *)Bits, (BYTE *)DecompressedBits, ScanLine, BitmapInfo->Format))
-            {
-                EngFreeMem(DecompressedBits);
-                return NULL;
-            }
-
-            BitmapInfo->Format = (BitmapInfo->Format == BMF_4RLE) ? BMF_4BPP : BMF_8BPP;
-        }
-    }
+    HBITMAP hbmp;
 
-    /* Allocate the actual surface object structure */
-    psurf = SURFACE_AllocSurfaceWithHandle();
+    /* Allocate a surface */
+    psurf = SURFACE_AllocSurface(STYPE_BITMAP, sizl.cx, sizl.cy, iFormat);
     if (!psurf)
     {
-        if(Bits && AllocatedLocally)
-        {
-            if(BitmapInfo->Flags & BMF_USERMEM)
-                EngFreeUserMem(Bits);
-            else
-                EngFreeMem(Bits);
-        }
-        if (DecompressedBits)
-            EngFreeMem(DecompressedBits);
+        DPRINT1("SURFACE_AllocSurface failed.\n");
         return NULL;
     }
 
-    /* Lock down the surface */
-    if (!SURFACE_InitBitsLock(psurf))
+    /* Get the handle for the bitmap */
+    hbmp = (HBITMAP)psurf->SurfObj.hsurf;
+
+    /* Set the bitmap bits */
+    if (!SURFACE_bSetBitmapBits(psurf, fl, lWidth, pvBits))
     {
         /* Bail out if that failed */
-        SURFACE_UnlockSurface(psurf);
-        SURFACE_FreeSurfaceByHandle(psurf->BaseObject.hHmgr);
+        DPRINT1("SURFACE_bSetBitmapBits failed.\n");
+        SURFACE_FreeSurfaceByHandle(hbmp);
         return NULL;
     }
 
-    /* We should now have our surface object */
-    pso = &psurf->SurfObj;
+    /* Set public ownership */
+    GDIOBJ_SetOwnership(hbmp, NULL);
 
-    /* Save format and flags */
-    pso->iBitmapFormat = BitmapInfo->Format;
-    pso->fjBitmap = BitmapInfo->Flags & (BMF_TOPDOWN | BMF_UMPDMEM | BMF_USERMEM);
-
-    /* Save size and type */
-    pso->sizlBitmap = LocalSize;
-    pso->iType = STYPE_BITMAP;
-
-    /* Device-managed surface, no flags or dimension */
-    pso->dhsurf = 0;
-    pso->dhpdev = NULL;
-    pso->hdev = NULL;
-    psurf->flFlags = 0;
-    psurf->dimension.cx = 0;
-    psurf->dimension.cy = 0;
-    psurf->hSecure = NULL;
-    psurf->hDIBSection = NULL;
-    psurf->flHooks = 0;
-
-    /* Set bits */
-     if(Compressed)
-         pso->pvBits = DecompressedBits;
-     else
-         pso->pvBits = Bits;
-
-    /* Number of bits is based on the height times the scanline */
-    pso->cjBits = BitmapInfo->Height * ScanLine;
-    if (BitmapInfo->Flags & BMF_TOPDOWN)
-    {
-        /* For topdown, the base address starts with the bits */
-        pso->pvScan0 = pso->pvBits;
-        pso->lDelta = ScanLine;
-    }
-    else
-    {
-        /* Otherwise we start with the end and go up */
-        pso->pvScan0 = (PVOID)((ULONG_PTR)pso->pvBits + pso->cjBits - ScanLine);
-        pso->lDelta = -ScanLine;
-    }
-
-    /* Finally set the handle and uniq */
-    pso->hsurf = (HSURF)psurf->BaseObject.hHmgr;
-    pso->iUniq = 0;
-    
-    /* Unlock and return the surface */
+    /* Unlock the surface and return */
     SURFACE_UnlockSurface(psurf);
-    return pso;
+    return hbmp;
 }
 
 /*
@@ -625,108 +311,66 @@ SURFMEM_bCreateDib(IN PDEVBITMAPINFO BitmapInfo,
  */
 HBITMAP
 APIENTRY
-EngCreateBitmap(IN SIZEL Size,
-                IN LONG Width,
-                IN ULONG Format,
-                IN ULONG Flags,
-                IN PVOID Bits)
+EngCreateDeviceBitmap(
+    IN DHSURF dhsurf,
+    IN SIZEL sizl,
+    IN ULONG iFormat)
 {
-    SURFOBJ* Surface;
-    DEVBITMAPINFO BitmapInfo;
-    
-    /* Capture the parameters */
-    BitmapInfo.Format = Format;
-    BitmapInfo.Width = Size.cx;
-    BitmapInfo.Height = Size.cy;
-    BitmapInfo.Flags = Flags;
-
-    /*
-     * If the display driver supports framebuffer access, use the scanline width
-     * to determine the actual width of the bitmap, and convert it to pels instead
-     * of bytes.
-     */
-    if ((Bits) && (Width))
+    PSURFACE psurf;
+    HBITMAP hbmp;
+
+    /* Allocate a surface */
+    psurf = SURFACE_AllocSurface(STYPE_DEVBITMAP, sizl.cx, sizl.cy, iFormat);
+    if (!psurf)
     {
-        switch (BitmapInfo.Format)
-        {
-            /* Do the conversion for each bit depth we support */
-            case BMF_1BPP:
-                BitmapInfo.Width = Width * 8;
-                break;
-            case BMF_4BPP:
-                BitmapInfo.Width = Width * 2;
-                break;
-            case BMF_8BPP:
-                BitmapInfo.Width = Width;
-                break;
-            case BMF_16BPP:
-                BitmapInfo.Width = Width / 2;
-                break;
-            case BMF_24BPP:
-                BitmapInfo.Width = Width / 3;
-                break;
-            case BMF_32BPP:
-                BitmapInfo.Width = Width / 4;
-                break;
-        }
+        return 0;
     }
-    
-    /* Now create the surface */
-    Surface = SURFMEM_bCreateDib(&BitmapInfo, Bits);
-    if (!Surface) return 0;
-
-    /* Set public ownership and reutrn the handle */
-    GDIOBJ_SetOwnership(Surface->hsurf, NULL);
-    return Surface->hsurf;
+
+    /* Set the device handle */
+    psurf->SurfObj.dhsurf = dhsurf;
+
+    /* Get the handle for the bitmap */
+    hbmp = (HBITMAP)psurf->SurfObj.hsurf;
+
+    /* Set public ownership */
+    GDIOBJ_SetOwnership(hbmp, NULL);
+
+    /* Unlock the surface and return */
+    SURFACE_UnlockSurface(psurf);
+    return hbmp;
 }
 
-/*
- * @unimplemented
- */
-HSURF APIENTRY
-EngCreateDeviceSurface(IN DHSURF dhsurf,
-                       IN SIZEL Size,
-                       IN ULONG Format)
+HSURF
+APIENTRY
+EngCreateDeviceSurface(
+    IN DHSURF dhsurf,
+    IN SIZEL sizl,
+    IN ULONG iFormat)
 {
-    HSURF hsurf;
-    SURFOBJ *pso;
     PSURFACE psurf;
+    HSURF hsurf;
 
-    psurf = SURFACE_AllocSurfaceWithHandle();
+    /* Allocate a surface */
+    psurf = SURFACE_AllocSurface(STYPE_DEVICE, sizl.cx, sizl.cy, iFormat);
     if (!psurf)
     {
         return 0;
     }
 
-    hsurf = psurf->BaseObject.hHmgr;
-    GDIOBJ_SetOwnership(hsurf, NULL);
+    /* Set the device handle */
+    psurf->SurfObj.dhsurf = dhsurf;
 
-    if (!SURFACE_InitBitsLock(psurf))
-    {
-        SURFACE_UnlockSurface(psurf);
-        SURFACE_FreeSurfaceByHandle(hsurf);
-        return 0;
-    }
-    pso = &psurf->SurfObj;
+    /* Get the handle for the surface */
+    hsurf = psurf->SurfObj.hsurf;
 
-    pso->dhsurf = dhsurf;
-    pso->hsurf = hsurf;
-    pso->sizlBitmap = Size;
-    pso->iBitmapFormat = Format;
-    pso->lDelta = DIB_GetDIBWidthBytes(Size.cx, BitsPerFormat(Format));
-    pso->iType = STYPE_DEVICE;
-    pso->iUniq = 0;
-
-    psurf->flHooks = 0;
+    /* Set public ownership */
+    GDIOBJ_SetOwnership(hsurf, NULL);
 
+    /* Unlock the surface and return */
     SURFACE_UnlockSurface(psurf);
-
     return hsurf;
 }
 
-/*
- * @implemented
- */
 BOOL
 APIENTRY
 EngAssociateSurface(
@@ -753,17 +397,19 @@ EngAssociateSurface(
     pso->dhpdev = ppdev->dhpdev;
 
     /* Hook up specified functions */
-    psurf->flHooks = flHooks;
+    psurf->flags &= ~HOOK_FLAGS;
+    psurf->flags |= (flHooks & HOOK_FLAGS);
+
+    /* Get palette */
+    psurf->ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault);
 
     SURFACE_UnlockSurface(psurf);
 
     return TRUE;
 }
 
-/*
- * @implemented
- */
-BOOL APIENTRY
+BOOL
+APIENTRY
 EngModifySurface(
     IN HSURF hsurf,
     IN HDEV hdev,
@@ -795,17 +441,20 @@ EngModifySurface(
     pso->dhpdev = ppdev->dhpdev;
 
     /* Hook up specified functions */
-    psurf->flHooks = flHooks;
+    psurf->flags &= ~HOOK_FLAGS;
+    psurf->flags |= (flHooks & HOOK_FLAGS);
+
+    /* Get palette */
+    psurf->ppal = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault);
 
     SURFACE_UnlockSurface(psurf);
 
     return TRUE;
 }
 
-/*
- * @implemented
- */
-BOOL APIENTRY
+
+BOOL
+APIENTRY
 EngDeleteSurface(IN HSURF hsurf)
 {
     GDIOBJ_SetOwnership(hsurf, PsGetCurrentProcess());
@@ -813,17 +462,16 @@ EngDeleteSurface(IN HSURF hsurf)
     return TRUE;
 }
 
-/*
- * @implemented
- */
-BOOL APIENTRY
-EngEraseSurface(SURFOBJ *pso,
-                RECTL *Rect,
-                ULONG iColor)
+BOOL
+APIENTRY
+EngEraseSurface(
+    SURFOBJ *pso,
+    RECTL *prcl,
+    ULONG iColor)
 {
     ASSERT(pso);
-    ASSERT(Rect);
-    return FillSolid(pso, Rect, iColor);
+    ASSERT(prcl);
+    return FillSolid(pso, prcl, iColor);
 }
 
 /*
@@ -836,10 +484,8 @@ NtGdiEngLockSurface(IN HSURF hsurf)
 }
 
 
-/*
- * @implemented
- */
-SURFOBJ * APIENTRY
+SURFOBJ *
+APIENTRY
 EngLockSurface(IN HSURF hsurf)
 {
     SURFACE *psurf = GDIOBJ_ShareLockObj(hsurf, GDI_OBJECT_TYPE_BITMAP);
@@ -850,20 +496,15 @@ EngLockSurface(IN HSURF hsurf)
     return NULL;
 }
 
-
-/*
- * @implemented
- */
-VOID APIENTRY
+VOID
+APIENTRY
 NtGdiEngUnlockSurface(IN SURFOBJ *pso)
 {
     EngUnlockSurface(pso);
 }
 
-/*
- * @implemented
- */
-VOID APIENTRY
+VOID
+APIENTRY
 EngUnlockSurface(IN SURFOBJ *pso)
 {
     if (pso != NULL)
@@ -873,5 +514,4 @@ EngUnlockSurface(IN SURFOBJ *pso)
     }
 }
 
-
 /* EOF */
index bca2244..0bfc145 100644 (file)
@@ -76,7 +76,7 @@ EngTransparentBlt(SURFOBJ *psoDest,
     OutputRect.top = DestRect->bottom;
     OutputRect.bottom = DestRect->top;
   }
-    
+
   if(Clip)
   {
     if(OutputRect.left < Clip->rclBounds.left)
@@ -284,17 +284,7 @@ IntEngTransparentBlt(SURFOBJ *psoDest,
     OutputRect = InputClippedRect;
   }
 
-  if(psoSource != psoDest)
-  {
-    SURFACE_LockBitmapBits(psurfSource);
-    MouseSafetyOnDrawStart(psoSource, InputRect.left, InputRect.top,
-                           InputRect.right, InputRect.bottom);
-  }
-  SURFACE_LockBitmapBits(psurfDest);
-  MouseSafetyOnDrawStart(psoDest, OutputRect.left, OutputRect.top,
-                         OutputRect.right, OutputRect.bottom);
-
-  if(psurfDest->flHooks & HOOK_TRANSPARENTBLT)
+  if(psurfDest->flags & HOOK_TRANSPARENTBLT)
   {
     Ret = GDIDEVFUNCS(psoDest).TransparentBlt(
       psoDest, psoSource, Clip, ColorTranslation, &OutputRect,
@@ -309,14 +299,6 @@ IntEngTransparentBlt(SURFOBJ *psoDest,
                             &OutputRect, &InputRect, iTransColor, Reserved);
   }
 
-  MouseSafetyOnDrawEnd(psoDest);
-  SURFACE_UnlockBitmapBits(psurfDest);
-  if(psoSource != psoDest)
-  {
-    MouseSafetyOnDrawEnd(psoSource);
-    SURFACE_UnlockBitmapBits(psurfSource);
-  }
-
   return Ret;
 }
 
index 77f2a21..8f99623 100644 (file)
@@ -64,7 +64,7 @@ EXLATEOBJ_iXlateRGBtoBGR(PEXLATEOBJ pxlo, ULONG iColor)
 {
     ULONG iNewColor;
 
-    /* Copy green and alpha */
+    /* Copy green */
     iNewColor = iColor & 0xff00ff00;
 
     /* Mask red and blue */
@@ -362,19 +362,19 @@ EXLATEOBJ_vInitialize(
     EXLATEOBJ_vInitTrivial(pexlo);
 
     if (ppalDst == ppalSrc || !ppalSrc || !ppalDst ||
-        ((ppalDst->Mode == PAL_RGB || ppalDst->Mode == PAL_BGR) &&
-         ppalDst->Mode == ppalSrc->Mode))
+        ((ppalDst->flFlags == PAL_RGB || ppalDst->flFlags == PAL_BGR) &&
+         ppalDst->flFlags == ppalSrc->flFlags))
     {
         return;
     }
 
     pexlo->ppalSrc = ppalSrc;
     pexlo->ppalDst = ppalDst;
-    pexlo->xlo.iSrcType = ppalSrc->Mode;
-    pexlo->xlo.iDstType = ppalDst->Mode;
+    pexlo->xlo.iSrcType = ppalSrc->flFlags;
+    pexlo->xlo.iDstType = ppalDst->flFlags;
 
     /* Chack if both of the pallettes are indexed */
-    if (!(ppalSrc->Mode & PAL_INDEXED) || !(ppalDst->Mode & PAL_INDEXED))
+    if (!(ppalSrc->flFlags & PAL_INDEXED) || !(ppalDst->flFlags & PAL_INDEXED))
     {
         /* At least one palette is not indexed, calculate shifts/masks */
         ULONG aulMasksSrc[3], aulMasksDst[3];
@@ -391,10 +391,10 @@ EXLATEOBJ_vInitialize(
         pexlo->ulBlueShift = CalculateShift(aulMasksSrc[2], aulMasksDst[2]);
     }
 
-    if (ppalSrc->Mode & PAL_MONOCHROME)
+    if (ppalSrc->flFlags & PAL_MONOCHROME)
     {
         /* This is a monochrome palette */
-        if (!(ppalDst->Mode & PAL_MONOCHROME))
+        if (!(ppalDst->flFlags & PAL_MONOCHROME))
         {
             /* Mono to color, use the dest DC's fore and back color */
             pexlo->pfnXlate = EXLATEOBJ_iXlateTable;
@@ -406,28 +406,28 @@ EXLATEOBJ_vInitialize(
                 PALETTE_ulGetNearestIndex(ppalDst, crDstBackColor);
         }
     }
-    else if (ppalDst->Mode & PAL_MONOCHROME)
+    else if (ppalDst->flFlags & PAL_MONOCHROME)
     {
         pexlo->pfnXlate = EXLATEOBJ_iXlateToMono;
         pexlo->xlo.flXlate |= XO_TO_MONO;
         pexlo->xlo.cEntries = 1;
 
-        if (ppalSrc->Mode & PAL_INDEXED)
+        if (ppalSrc->flFlags & PAL_INDEXED)
         {
             pexlo->aulXlate[0] =
                 PALETTE_ulGetNearestPaletteIndex(ppalSrc, crSrcBackColor);
         }
-        else if (ppalSrc->Mode & PAL_BGR)
+        else if (ppalSrc->flFlags & PAL_BGR)
         {
             pexlo->aulXlate[0] = crSrcBackColor;
         }
-        else if (ppalSrc->Mode & PAL_RGB)
+        else if (ppalSrc->flFlags & PAL_RGB)
         {
             pexlo->aulXlate[0] = RGB(GetBValue(crSrcBackColor),
                                      GetGValue(crSrcBackColor),
                                      GetRValue(crSrcBackColor));
         }
-        else if (ppalSrc->Mode & PAL_BITFIELDS)
+        else if (ppalSrc->flFlags & PAL_BITFIELDS)
         {
             PALETTE_vGetBitMasks(ppalSrc, &pexlo->ulRedMask);
             pexlo->ulRedShift = CalculateShift(0xFF, pexlo->ulRedMask);
@@ -437,7 +437,7 @@ EXLATEOBJ_vInitialize(
             pexlo->aulXlate[0] = EXLATEOBJ_iXlateShiftAndMask(pexlo, crSrcBackColor);
         }
     }
-    else if (ppalSrc->Mode & PAL_INDEXED)
+    else if (ppalSrc->flFlags & PAL_INDEXED)
     {
         cEntries = ppalSrc->NumColors;
 
@@ -458,7 +458,7 @@ EXLATEOBJ_vInitialize(
         pexlo->xlo.cEntries = cEntries;
 
         pexlo->pfnXlate = EXLATEOBJ_iXlateTable;
-        if (ppalDst->Mode & PAL_INDEXED)
+        if (ppalDst->flFlags & PAL_INDEXED)
         {
             pexlo->xlo.flXlate |= XO_TABLE;
 
@@ -504,78 +504,78 @@ EXLATEOBJ_vInitialize(
             }
         }
     }
-    else if (ppalSrc->Mode & PAL_RGB)
+    else if (ppalSrc->flFlags & PAL_RGB)
     {
-        if (ppalDst->Mode & PAL_INDEXED)
+        if (ppalDst->flFlags & PAL_INDEXED)
             pexlo->pfnXlate = EXLATEOBJ_iXlateRGBtoPal;
 
-        else if (ppalDst->Mode & PAL_BGR)
+        else if (ppalDst->flFlags & PAL_BGR)
             pexlo->pfnXlate = EXLATEOBJ_iXlateRGBtoBGR;
 
-        else if (ppalDst->Mode & PAL_RGB16_555)
+        else if (ppalDst->flFlags & PAL_RGB16_555)
             pexlo->pfnXlate = EXLATEOBJ_iXlateRGBto555;
 
-        else if (ppalDst->Mode & PAL_RGB16_565)
+        else if (ppalDst->flFlags & PAL_RGB16_565)
             pexlo->pfnXlate = EXLATEOBJ_iXlateRGBto565;
 
-        else if (ppalDst->Mode & PAL_BITFIELDS)
+        else if (ppalDst->flFlags & PAL_BITFIELDS)
             pexlo->pfnXlate = EXLATEOBJ_iXlateShiftAndMask;
     }
-    else if (ppalSrc->Mode & PAL_BGR)
+    else if (ppalSrc->flFlags & PAL_BGR)
     {
-        if (ppalDst->Mode & PAL_INDEXED)
+        if (ppalDst->flFlags & PAL_INDEXED)
             pexlo->pfnXlate = EXLATEOBJ_iXlateBitfieldsToPal;
 
-        else if (ppalDst->Mode & PAL_RGB)
+        else if (ppalDst->flFlags & PAL_RGB)
             /* The inverse function works the same */
             pexlo->pfnXlate = EXLATEOBJ_iXlateRGBtoBGR;
 
-        else if (ppalDst->Mode & PAL_RGB16_555)
+        else if (ppalDst->flFlags & PAL_RGB16_555)
             pexlo->pfnXlate = EXLATEOBJ_iXlateBGRto555;
 
-        else if (ppalDst->Mode & PAL_RGB16_565)
+        else if (ppalDst->flFlags & PAL_RGB16_565)
             pexlo->pfnXlate = EXLATEOBJ_iXlateBGRto565;
 
-        else if (ppalDst->Mode & PAL_BITFIELDS)
+        else if (ppalDst->flFlags & PAL_BITFIELDS)
             pexlo->pfnXlate = EXLATEOBJ_iXlateShiftAndMask;
     }
-    else if (ppalSrc->Mode & PAL_RGB16_555)
+    else if (ppalSrc->flFlags & PAL_RGB16_555)
     {
-        if (ppalDst->Mode & PAL_INDEXED)
+        if (ppalDst->flFlags & PAL_INDEXED)
             pexlo->pfnXlate = EXLATEOBJ_iXlate555toPal;
 
-        else if (ppalDst->Mode & PAL_RGB)
+        else if (ppalDst->flFlags & PAL_RGB)
             pexlo->pfnXlate = EXLATEOBJ_iXlate555toRGB;
 
-        else if (ppalDst->Mode & PAL_BGR)
+        else if (ppalDst->flFlags & PAL_BGR)
             pexlo->pfnXlate = EXLATEOBJ_iXlate555toBGR;
 
-        else if (ppalDst->Mode & PAL_RGB16_565)
+        else if (ppalDst->flFlags & PAL_RGB16_565)
             pexlo->pfnXlate = EXLATEOBJ_iXlate555to565;
 
-        else if (ppalDst->Mode & PAL_BITFIELDS)
+        else if (ppalDst->flFlags & PAL_BITFIELDS)
             pexlo->pfnXlate = EXLATEOBJ_iXlateShiftAndMask;
     }
-    else if (ppalSrc->Mode & PAL_RGB16_565)
+    else if (ppalSrc->flFlags & PAL_RGB16_565)
     {
-        if (ppalDst->Mode & PAL_INDEXED)
+        if (ppalDst->flFlags & PAL_INDEXED)
             pexlo->pfnXlate = EXLATEOBJ_iXlate565toPal;
 
-        else if (ppalDst->Mode & PAL_RGB)
+        else if (ppalDst->flFlags & PAL_RGB)
             pexlo->pfnXlate = EXLATEOBJ_iXlate565toRGB;
 
-        else if (ppalDst->Mode & PAL_BGR)
+        else if (ppalDst->flFlags & PAL_BGR)
             pexlo->pfnXlate = EXLATEOBJ_iXlate565toBGR;
 
-        else if (ppalDst->Mode & PAL_RGB16_555)
+        else if (ppalDst->flFlags & PAL_RGB16_555)
             pexlo->pfnXlate = EXLATEOBJ_iXlate565to555;
 
-        else if (ppalDst->Mode & PAL_BITFIELDS)
+        else if (ppalDst->flFlags & PAL_BITFIELDS)
             pexlo->pfnXlate = EXLATEOBJ_iXlateShiftAndMask;
     }
-    else if (ppalSrc->Mode & PAL_BITFIELDS)
+    else if (ppalSrc->flFlags & PAL_BITFIELDS)
     {
-        if (ppalDst->Mode & PAL_INDEXED)
+        if (ppalDst->flFlags & PAL_INDEXED)
             pexlo->pfnXlate = EXLATEOBJ_iXlateBitfieldsToPal;
         else
             pexlo->pfnXlate = EXLATEOBJ_iXlateShiftAndMask;
@@ -603,157 +603,24 @@ EXLATEOBJ_vInitXlateFromDCs(
     PDC pdcDst)
 {
     PSURFACE psurfDst, psurfSrc;
-    HPALETTE hpalSrc, hpalDst;
-    PPALETTE ppalSrc, ppalDst, ppalDstDc;
-
-    DPRINT("Enter EXLATEOBJ_vInitXlateFromDCs\n");
-
-    /* Do basic init */
-    EXLATEOBJ_vInitTrivial(pexlo);
 
     psurfDst = pdcDst->dclevel.pSurface;
     psurfSrc = pdcSrc->dclevel.pSurface;
 
+    /* Check for trivial color translation */
     if (psurfDst == psurfSrc)
     {
+        EXLATEOBJ_vInitTrivial(pexlo);
         return;
     }
 
-    hpalSrc = psurfSrc->hDIBPalette;
-    if (!hpalSrc) 
-        hpalSrc = pPrimarySurface->devinfo.hpalDefault;
-
-    ppalSrc = PALETTE_ShareLockPalette(hpalSrc);
-    if (!ppalSrc)
-        return;
-
-    hpalDst = psurfDst->hDIBPalette;
-    if (!hpalDst) hpalDst = pPrimarySurface->devinfo.hpalDefault;
-
-    ppalDst = PALETTE_ShareLockPalette(hpalDst);
-    if (!ppalDst)
-    {
-        PALETTE_ShareUnlockPalette(ppalSrc);
-        return;
-    }
-
-    ppalDstDc = pdcDst->dclevel.ppal;
-    ASSERT(ppalDstDc);
-
-    /* KB41464 details how to convert between mono and color */
-    if (psurfDst->SurfObj.iBitmapFormat == BMF_1BPP)
-    {
-        if (psurfSrc->SurfObj.iBitmapFormat != BMF_1BPP)
-        {
-            // HACK!! FIXME: 1bpp DDBs should have gpalMono already!
-            EXLATEOBJ_vInitialize(pexlo,
-                                  ppalSrc,
-                                  &gpalMono,
-                                  pdcSrc->pdcattr->crBackgroundClr,
-                                  pdcDst->pdcattr->crBackgroundClr,
-                                  pdcDst->pdcattr->crForegroundClr);
-        }
-    }
-    else if (psurfSrc->SurfObj.iBitmapFormat == BMF_1BPP && !psurfSrc->hSecure)
-    {
-        // HACK!! FIXME: 1bpp DDBs should have gpalMono already!
-        EXLATEOBJ_vInitialize(pexlo,
-                              &gpalMono,
-                              ppalDst,
-                              0,
-                              pdcDst->pdcattr->crBackgroundClr,
-                              pdcDst->pdcattr->crForegroundClr);
-    }
-    else
-    {
-        EXLATEOBJ_vInitialize(pexlo, ppalSrc, ppalDst, 0, 0, 0);
-    }
-
-    PALETTE_ShareUnlockPalette(ppalDst);
-    PALETTE_ShareUnlockPalette(ppalSrc);
-}
-
-
-VOID
-NTAPI
-EXLATEOBJ_vInitBrushXlate(
-    PEXLATEOBJ pexlo,
-    BRUSH *pbrush,
-    SURFACE *psurfDst,
-    COLORREF crForegroundClr,
-    COLORREF crBackgroundClr)
-{
-    HPALETTE hpalDst = NULL;
-    PPALETTE ppalDst, ppalPattern;
-    SURFACE *psurfPattern;
-
-    ASSERT(pexlo);
-    ASSERT(pbrush);
-    ASSERT(psurfDst);
-    ASSERT(!(pbrush->flAttrs & (GDIBRUSH_IS_SOLID | GDIBRUSH_IS_NULL)));
-
-    EXLATEOBJ_vInitTrivial(pexlo);
-
-    hpalDst = psurfDst->hDIBPalette;
-    if (!hpalDst) hpalDst = pPrimarySurface->devinfo.hpalDefault;
-    ppalDst = PALETTE_ShareLockPalette(hpalDst);
-    if (!ppalDst)
-    {
-        DPRINT1("No ppalDst!\n");
-        return;
-    }
-
-    psurfPattern = SURFACE_ShareLockSurface(pbrush->hbmPattern);
-    if (!psurfPattern)
-    {
-        PALETTE_ShareUnlockPalette(ppalDst);
-        return;
-    }
-
-#if 0
-    if (psurfDst->SurfObj.iBitmapFormat == BMF_1BPP)
-    {
-        if (psurfSrc->SurfObj.iBitmapFormat != BMF_1BPP)
-        {
-            // HACK!! FIXME: 1bpp DDBs should have gpalMono already!
-            EXLATEOBJ_vInitialize(pexlo,
-                                  ppalSrc,
-                                  &gpalMono,
-                                  0,
-                                  crBackgroundClr,
-                                  crForegroundClr);
-        }
-    }
-    else
-#endif
-    if (psurfPattern->SurfObj.iBitmapFormat == BMF_1BPP &&
-        !(pbrush->flAttrs & GDIBRUSH_IS_DIB))
-    {
-        /* Special case: 1 bpp pattern, not a DIB brush. */
-        if (psurfDst->SurfObj.iBitmapFormat != BMF_1BPP)
-        {
-            // HACK!! FIXME: 1bpp DDBs should have gpalMono already!
-            EXLATEOBJ_vInitialize(pexlo,
-                                  &gpalMono,
-                                  ppalDst,
-                                  0,
-                                  crBackgroundClr,
-                                  crForegroundClr);
-        }
-    }
-    else
-    {
-        /* Default: use the patterns' palette */
-        ppalPattern = PALETTE_LockPalette(psurfPattern->hDIBPalette);
-        if (ppalPattern)
-        {
-            EXLATEOBJ_vInitialize(pexlo, &gpalRGB, ppalDst, 0, 0, 0);
-            PALETTE_UnlockPalette(ppalPattern);
-        }
-    }
-
-    PALETTE_ShareUnlockPalette(ppalDst);
-    SURFACE_ShareUnlockSurface(psurfPattern);
+    /* Normal initialisation. No surface means DEFAULT_BITMAP */
+    EXLATEOBJ_vInitialize(pexlo,
+                          psurfSrc ? psurfSrc->ppal : &gpalMono,
+                          psurfDst ? psurfDst->ppal : &gpalMono,
+                          pdcSrc->pdcattr->crBackgroundClr,
+                          pdcDst->pdcattr->crBackgroundClr,
+                          pdcDst->pdcattr->crForegroundClr);
 }
 
 VOID
@@ -827,9 +694,9 @@ XLATEOBJ_cGetPalette(XLATEOBJ *pxlo, ULONG iPal, ULONG cPal, ULONG *pPalOut)
     /* Verify palette type match */
     if (!ppal ||
         ((iPal == XO_SRCPALETTE || iPal == XO_DESTPALETTE)
-            && !(ppal->Mode & PAL_INDEXED)) ||
+            && !(ppal->flFlags & PAL_INDEXED)) ||
         ((iPal == XO_SRCBITFIELDS || iPal == XO_DESTBITFIELDS)
-            && !(ppal->Mode & PAL_BITFIELDS)))
+            && !(ppal->flFlags & PAL_BITFIELDS)))
     {
         return 0;
     }
@@ -840,7 +707,7 @@ XLATEOBJ_cGetPalette(XLATEOBJ *pxlo, ULONG iPal, ULONG cPal, ULONG *pPalOut)
     }
 
     /* Copy the values into the buffer */
-    if (ppal->Mode & PAL_INDEXED)
+    if (ppal->flFlags & PAL_INDEXED)
     {
         cPal = min(cPal, ppal->NumColors);
         for (i = 0; i < cPal; i++)
index 6a5e731..802028d 100644 (file)
@@ -2,11 +2,47 @@
 
 #include "surface.h"
 
-INT     FASTCALL DIB_GetDIBWidthBytes (INT  width, INT  depth);
-int     APIENTRY  DIB_GetDIBImageBytes (INT  width, INT  height, INT  depth);
-INT     FASTCALL DIB_BitmapInfoSize (const BITMAPINFO * info, WORD coloruse);
+typedef struct tagBITMAPV5INFO
+{
+    BITMAPV5HEADER bmiHeader;
+    RGBQUAD        bmiColors[256];
+} BITMAPV5INFO, *PBITMAPV5INFO;
+
 INT     APIENTRY  BITMAP_GetObject(SURFACE * bmp, INT count, LPVOID buffer);
 HBITMAP FASTCALL IntCreateBitmap(IN SIZEL Size, IN LONG Width, IN ULONG Format, IN ULONG Flags, IN PVOID Bits);
 HBITMAP FASTCALL BITMAP_CopyBitmap (HBITMAP  hBitmap);
 UINT    FASTCALL BITMAP_GetRealBitsPixel(UINT nBitsPixel);
-INT     FASTCALL BITMAP_GetWidthBytes (INT bmWidth, INT bpp);
+
+HBITMAP
+APIENTRY
+GreCreateBitmap(
+    IN INT nWidth,
+    IN INT nHeight,
+    IN UINT cPlanes,
+    IN UINT cBitsPixel,
+    IN OPTIONAL PVOID pvBits);
+
+HBITMAP
+APIENTRY
+GreCreateBitmapEx(
+    IN INT nWidth,
+    IN INT nHeight,
+    IN ULONG cjWidthBytes,
+    IN ULONG iFormat,
+    IN USHORT fjBitmap,
+    IN ULONG cjBits,
+    IN OPTIONAL PVOID pvBits,
+       IN FLONG flags);
+
+HBITMAP
+FASTCALL
+GreCreateDIBitmapInternal(
+    IN HDC hDc,
+    IN INT cx,
+    IN INT cy,
+    IN DWORD fInit,
+    IN OPTIONAL LPBYTE pjInit,
+    IN OPTIONAL PBITMAPINFO pbmi,
+    IN DWORD iUsage,
+    IN FLONG fl,
+    IN HANDLE hcmXform);
index 41621f9..8150b16 100644 (file)
@@ -1,4 +1,5 @@
-#pragma once
+#ifndef __WIN32K_DC_H
+#define __WIN32K_DC_H
 
 typedef struct _DC *PDC;
 
@@ -22,6 +23,30 @@ typedef struct _DC *PDC;
 /* fl */
 #define DC_FL_PAL_BACK 1
 
+#define DC_DISPLAY  1
+#define DC_DIRECT 2
+#define DC_CANCELED 4
+#define DC_PERMANANT 0x08
+#define DC_DIRTY_RAO 0x10
+#define DC_ACCUM_WMGR 0x20
+#define DC_ACCUM_APP 0x40
+#define DC_RESET 0x80
+#define DC_SYNCHRONIZEACCESS 0x100
+#define DC_EPSPRINTINGESCAPE 0x200
+#define DC_TEMPINFODC 0x400
+#define DC_FULLSCREEN 0x800
+#define DC_IN_CLONEPDEV 0x1000
+#define DC_REDIRECTION 0x2000
+#define DC_SHAREACCESS 0x4000
+
+typedef enum
+{
+  DCTYPE_DIRECT = 0,
+  DCTYPE_MEMORY = 1,
+  DCTYPE_INFO = 2,
+} DCTYPE;
+
+
 /* Type definitions ***********************************************************/
 
 typedef struct _ROS_DC_INFO
@@ -29,7 +54,7 @@ typedef struct _ROS_DC_INFO
   HRGN     hClipRgn;     /* Clip region (may be 0) */
   HRGN     hGCClipRgn;   /* GC clip region (ClipRgn AND VisRgn) */
 
-  CLIPOBJ     *CombinedClip; /* Use XCLIPOBJ in DC. */
+  CLIPOBJ     *CombinedClip;
 
   UNICODE_STRING    DriverName;
 
@@ -136,13 +161,12 @@ extern PDC defaultDCstate;
 
 NTSTATUS FASTCALL InitDcImpl(VOID);
 PPDEVOBJ FASTCALL IntEnumHDev(VOID);
-HDC  FASTCALL DC_AllocDC(PUNICODE_STRING  Driver);
+PDC NTAPI DC_AllocDcWithHandle();
 VOID FASTCALL DC_InitDC(HDC  DCToInit);
-HDC  FASTCALL DC_FindOpenDC(PUNICODE_STRING  Driver);
 VOID FASTCALL DC_AllocateDcAttr(HDC);
 VOID FASTCALL DC_FreeDcAttr(HDC);
 BOOL INTERNAL_CALL DC_Cleanup(PVOID ObjectBody);
-BOOL FASTCALL DC_SetOwnership(HDC DC, PEPROCESS Owner);
+BOOL FASTCALL DC_SetOwnership(HDC hDC, PEPROCESS Owner);
 VOID FASTCALL DC_LockDisplay(HDC);
 VOID FASTCALL DC_UnlockDisplay(HDC);
 BOOL FASTCALL IntGdiDeleteDC(HDC, BOOL);
@@ -155,10 +179,16 @@ VOID FASTCALL DC_vUpdateFillBrush(PDC pdc);
 VOID FASTCALL DC_vUpdateLineBrush(PDC pdc);
 VOID FASTCALL DC_vUpdateTextBrush(PDC pdc);
 VOID FASTCALL DC_vUpdateBackgroundBrush(PDC pdc);
+VOID FASTCALL DC_vFinishBlit(PDC pdc1, PDC pdc2);
+VOID FASTCALL DC_vPrepareDCsForBlit(PDC pdc1, RECT rc1, PDC pdc2, RECT rc2);
+
+VOID NTAPI DC_vRestoreDC(IN PDC pdc, INT iSaveLevel);
 
 BOOL FASTCALL DCU_SyncDcAttrtoUser(PDC);
 BOOL FASTCALL DCU_SynchDcAttrtoUser(HDC);
 VOID FASTCALL DCU_SetDcUndeletable(HDC);
+VOID NTAPI DC_vFreeDcAttr(PDC pdc);
+VOID NTAPI DC_vInitDc(PDC pdc, DCTYPE dctype, PPDEVOBJ ppdev);
 
 COLORREF FASTCALL IntGdiSetBkColor (HDC hDC, COLORREF Color);
 INT FASTCALL IntGdiSetBkMode(HDC  hDC, INT  backgroundMode);
@@ -174,12 +204,9 @@ VOID FASTCALL IntGdiUnreferencePdev(PPDEVOBJ pPDev, DWORD CleanUpType);
 HDC FASTCALL IntGdiCreateDisplayDC(HDEV hDev, ULONG DcType, BOOL EmptyDC);
 BOOL FASTCALL IntGdiCleanDC(HDC hDC);
 VOID FASTCALL IntvGetDeviceCaps(PPDEVOBJ, PDEVCAPS);
-INT FASTCALL IntGdiGetDeviceCaps(PDC,INT);
 BOOL FASTCALL MakeInfoDC(PDC,BOOL);
 BOOL FASTCALL IntSetDefaultRegion(PDC);
 
-extern PPDEVOBJ pPrimarySurface;
-
 VOID
 FORCEINLINE
 DC_vSelectSurface(PDC pdc, PSURFACE psurfNew)
@@ -228,5 +255,6 @@ DC_vSelectPalette(PDC pdc, PPALETTE ppal)
     pdc->dclevel.ppal = ppal;
 }
 
-BOOL FASTCALL IntPrepareDriverIfNeeded(VOID);
-extern PDEVOBJ PrimarySurface;
+extern PBRUSH pbrDefaultBrush ;
+
+#endif /* not __WIN32K_DC_H */
diff --git a/reactos/subsystems/win32/win32k/include/device.h b/reactos/subsystems/win32/win32k/include/device.h
new file mode 100644 (file)
index 0000000..cdf60d7
--- /dev/null
@@ -0,0 +1,57 @@
+
+//#define _PDEVOBJ _PDEVOBJ2
+//#define PDEVOBJ PDEVOBJ2
+//#define PPDEVOBJ PPDEVOBJ2
+
+//typedef struct _PDEVOBJ *PPDEVOBJ;
+
+#define TAG_GDEV 'gdev'
+
+VOID
+APIENTRY
+EngFileWrite(
+    IN PFILE_OBJECT pFileObject,
+    IN PVOID lpBuffer,
+    IN SIZE_T nLength,
+    IN PSIZE_T lpBytesWritten);
+
+PGRAPHICS_DEVICE
+NTAPI
+EngpFindGraphicsDevice(
+    PUNICODE_STRING pustrDevice,
+    DWORD iDevNum,
+    DWORD dwFlags);
+
+PGRAPHICS_DEVICE
+NTAPI
+EngpRegisterGraphicsDevice(
+    PUNICODE_STRING pustrDeviceName,
+    PUNICODE_STRING pustrDiplayDrivers,
+    PUNICODE_STRING pustrDescription,
+    PDEVMODEW pdmDefault);
+
+BOOL
+NTAPI
+InitDeviceImpl();
+
+BOOL
+FASTCALL
+DC_AllocDcAttr(PDC pdc);
+
+//#define KeRosDumpStackFrames(Frames, Count) KdSystemDebugControl(TAG('R', 'o', 's', 'D'), (PVOID)Frames, Count, NULL, 0, NULL, KernelMode)
+NTSYSAPI ULONG APIENTRY RtlWalkFrameChain(OUT PVOID *Callers, IN ULONG Count, IN ULONG Flags);
+
+BOOL
+NTAPI
+PDEVOBJ_bSwitchMode(
+    PPDEVOBJ ppdev,
+    PDEVMODEW pdm);
+
+PDEVMODEW
+NTAPI
+PDEVOBJ_pdmMatchDevMode(
+    PPDEVOBJ ppdev,
+    PDEVMODEW pdm);
+
+extern PGRAPHICS_DEVICE gpPrimaryGraphicsDevice;
+extern PGRAPHICS_DEVICE gpVgaGraphicsDevice;
index 479476d..9d5b2b1 100644 (file)
@@ -5,15 +5,17 @@
 INT FASTCALL
 DIB_BitmapInfoSize (const BITMAPINFO * info, WORD coloruse);
 HBITMAP APIENTRY
-DIB_CreateDIBSection (PDC dc, PBITMAPINFO bmi, UINT usage, LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
-INT APIENTRY
-DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, PLONG width, PLONG height, PWORD planes, PWORD bpp, PLONG compr, PLONG size );
+DIB_CreateDIBSection (PDC dc, CONST BITMAPINFO *bmi, UINT usage, LPVOID *bits, HANDLE section, DWORD offset, DWORD ovr_pitch);
+int FASTCALL
+DIB_GetBitmapInfo( const BITMAPINFOHEADER *header, LONG *width,
+                       LONG *height, WORD *planes, WORD *bpp, DWORD *compr, DWORD *size );
 INT APIENTRY
 DIB_GetDIBImageBytes (INT  width, INT height, INT depth);
-INT FASTCALL
-DIB_GetDIBWidthBytes (INT width, INT depth);
-RGBQUAD * FASTCALL
-DIB_MapPaletteColors(PDC dc, CONST BITMAPINFO* lpbmi);
+HPALETTE FASTCALL
+DIB_MapPaletteColors(PPALETTE ppal, CONST BITMAPINFO* lpbmi);
 
 HPALETTE FASTCALL
-BuildDIBPalette (CONST BITMAPINFO *bmi, PINT paletteType);
+BuildDIBPalette (CONST BITMAPINFO *bmi);
+
+BITMAPINFO* FASTCALL DIB_ConvertBitmapInfo(CONST BITMAPINFO* bmi, DWORD Usage);
+VOID FASTCALL DIB_FreeConvertedBitmapInfo(BITMAPINFO* converted, BITMAPINFO* orig);
\ No newline at end of file
index 5d95070..3ed830a 100644 (file)
@@ -21,3 +21,19 @@ IntEngWindowChanged(
 VOID FASTCALL IntGdiAcquireSemaphore ( HSEMAPHORE hsem );
 VOID FASTCALL IntGdiReleaseSemaphore ( HSEMAPHORE hsem );
 ULONGLONG APIENTRY EngGetTickCount(VOID);
+
+BOOL
+APIENTRY
+EngFreeSectionMem(
+    IN PVOID pvSection OPTIONAL,
+    IN PVOID pvMappedBase OPTIONAL);
+
+PVOID
+APIENTRY
+EngAllocSectionMem(
+    OUT PVOID *ppvSection,
+    IN ULONG fl,
+    IN SIZE_T cjSize,
+    IN ULONG ulTag);
+
+VOID DecompressBitmap(SIZEL Size, BYTE *CompressedBits, BYTE *UncompressedBits, LONG Delta, ULONG iFormat);
index 9ce98f0..a1a56b7 100644 (file)
@@ -71,6 +71,7 @@ VOID    INTERNAL_CALL GDIOBJ_FreeObj (POBJ pObj, UCHAR ObjectType);
 BOOL    INTERNAL_CALL GDIOBJ_FreeObjByHandle (HGDIOBJ hObj, DWORD ObjectType);
 PGDIOBJ INTERNAL_CALL GDIOBJ_LockObj (HGDIOBJ hObj, DWORD ObjectType);
 PGDIOBJ INTERNAL_CALL GDIOBJ_ShareLockObj (HGDIOBJ hObj, DWORD ObjectType);
+VOID INTERNAL_CALL GDIOBJ_LockMultipleObjs(ULONG ulCount, IN HGDIOBJ* ahObj, OUT PGDIOBJ* apObj);
 
 PVOID   INTERNAL_CALL GDI_MapHandleTable(PSECTION_OBJECT SectionObject, PEPROCESS Process);
 
index dc0bc98..9bcfc0a 100644 (file)
@@ -45,7 +45,7 @@ IntEngLineTo(SURFOBJ *Surface,
              MIX mix);
 
 BOOL APIENTRY
-IntEngBitBltEx(SURFOBJ *DestObj,
+IntEngBitBlt(SURFOBJ *DestObj,
                SURFOBJ *SourceObj,
                SURFOBJ *Mask,
                CLIPOBJ *ClipRegion,
@@ -55,14 +55,7 @@ IntEngBitBltEx(SURFOBJ *DestObj,
                POINTL *MaskOrigin,
                BRUSHOBJ *Brush,
                POINTL *BrushOrigin,
-               ROP4 Rop4,
-               BOOL RemoveMouse);
-#define IntEngBitBlt(DestObj, SourceObj, Mask, ClipRegion, ColorTranslation, \
-                     DestRect, SourcePoint, MaskOrigin, Brush, BrushOrigin, \
-                     Rop4) \
-        IntEngBitBltEx((DestObj), (SourceObj), (Mask), (ClipRegion), \
-                       (ColorTranslation), (DestRect), (SourcePoint), \
-                       (MaskOrigin), (Brush), (BrushOrigin), (Rop4), TRUE)
+               ROP4 Rop4);
 
 BOOL APIENTRY
 IntEngStretchBlt(SURFOBJ *DestObj,
index d547ba4..fcbb7a0 100644 (file)
@@ -167,9 +167,6 @@ IntGetSysColor(INT nIndex);
 
 /* Other Stuff */
 
-INT FASTCALL
-IntGdiGetDeviceCaps(PDC dc, INT Index);
-
 INT
 FASTCALL
 IntGdiEscape(PDC    dc,
@@ -186,14 +183,6 @@ IntEnumDisplaySettings(
   IN OUT LPDEVMODEW pDevMode,
   IN DWORD dwFlags);
 
-LONG
-FASTCALL
-IntChangeDisplaySettings(
-  IN PUNICODE_STRING pDeviceName  OPTIONAL,
-  IN LPDEVMODEW pDevMode,
-  IN DWORD dwflags,
-  IN PVOID lParam  OPTIONAL);
-
 HBITMAP
 FASTCALL
 IntCreateCompatibleBitmap(PDC Dc,
diff --git a/reactos/subsystems/win32/win32k/include/ldevobj.h b/reactos/subsystems/win32/win32k/include/ldevobj.h
new file mode 100644 (file)
index 0000000..40070db
--- /dev/null
@@ -0,0 +1,86 @@
+
+#ifdef __GNUC__
+/* Hack, for bug in ld.  Will be removed soon.  */
+#define __ImageBase _image_base__
+#endif
+extern IMAGE_DOS_HEADER __ImageBase;
+
+
+#define TAG_LDEV 'Gldv'
+
+#define GDI_ENGINE_VERSION DDI_DRIVER_VERSION_NT5_01
+
+typedef enum
+{
+    LDEV_DEVICE_DISPLAY = 1,
+    LDEV_DEVICE_PRINTER = 2,
+    LDEV_DEVICE_META = 3,
+    LDEV_DEVICE_MIRROR = 4,
+    LDEV_IMAGE = 5,
+    LDEV_FONT = 6,
+} LDEVTYPE;
+
+typedef struct _LDEVOBJ
+{
+    struct _LDEVOBJ *pldevNext;
+    struct _LDEVOBJ *pldevPrev;
+    SYSTEM_GDI_DRIVER_INFORMATION *pGdiDriverInfo;
+    LDEVTYPE ldevtype;
+    ULONG cRefs;
+    ULONG ulDriverVersion;
+
+    union
+    {
+        PVOID apfn[INDEX_LAST];
+        DRIVER_FUNCTIONS pfn;
+    };
+
+} LDEVOBJ, *PLDEVOBJ;
+
+extern PLDEVOBJ gpldevHead;
+extern HSEMAPHORE ghsemDriverMgmt;
+
+PLDEVOBJ
+NTAPI
+LDEVOBJ_pldevLoadImage(
+    PUNICODE_STRING pusPathName,
+    LDEVTYPE ldevtype);
+
+BOOL
+NTAPI
+LDEVOBJ_bLoadDriver(
+    IN PLDEVOBJ pldev);
+
+PVOID
+NTAPI
+LDEVOBJ_pvFindImageProcAddress(
+    IN PLDEVOBJ pldev,
+    IN LPSTR    lpProcName);
+
+PDEVMODEINFO
+NTAPI
+LDEVOBJ_pdmiGetModes(
+    PLDEVOBJ pldev,
+    HANDLE hDriver);
+
+BOOL
+NTAPI
+InitLDEVImpl();
+
+PLDEVOBJ
+APIENTRY
+EngLoadImageEx(
+    LPWSTR pwszDriverName,
+    ULONG ldevtype);
+
+PLDEVOBJ
+NTAPI
+EngGetLDEV(
+    PDEVMODEW pdm);
+
+NTSTATUS
+APIENTRY
+DriverEntry (
+  IN   PDRIVER_OBJECT  DriverObject,
+  IN   PUNICODE_STRING RegistryPath);
+
index 366c44b..cfe4788 100644 (file)
@@ -29,6 +29,33 @@ VOID FASTCALL IntUserManualGuiCheck(LONG Check);
 PVOID APIENTRY HackSecureVirtualMemory(IN PVOID,IN SIZE_T,IN ULONG,OUT PVOID *);
 VOID APIENTRY HackUnsecureVirtualMemory(IN PVOID);
 
+NTSTATUS
+NTAPI
+RegOpenKey(
+    LPCWSTR pwszKeyName,
+    PHKEY phkey);
+
+NTSTATUS
+NTAPI
+RegQueryValue(
+    IN HKEY hkey,
+    IN PCWSTR pwszValueName,
+    IN ULONG ulType,
+    OUT PVOID pvData,
+    IN OUT PULONG pcbValue);
+
+VOID
+NTAPI
+RegWriteSZ(HKEY hkey, PWSTR pwszValue, PWSTR pwszData);
+
+VOID
+NTAPI
+RegWriteDWORD(HKEY hkey, PWSTR pwszValue, DWORD dwData);
+
+BOOL
+NTAPI
+RegReadDWORD(HKEY hkey, PWSTR pwszValue, PDWORD pdwData);
+
 BOOL
 NTAPI
 RegReadUserSetting(
index 0e5f68b..306148b 100644 (file)
@@ -2,8 +2,8 @@
 
 #include <include/winsta.h>
 
-INT  INTERNAL_CALL MouseSafetyOnDrawStart(SURFOBJ *SurfObj, LONG HazardX1, LONG HazardY1, LONG HazardX2, LONG HazardY2);
-INT  INTERNAL_CALL MouseSafetyOnDrawEnd(SURFOBJ *SurfObj);
+INT  INTERNAL_CALL MouseSafetyOnDrawStart(PPDEVOBJ ppdev, LONG HazardX1, LONG HazardY1, LONG HazardX2, LONG HazardY2);
+INT  INTERNAL_CALL MouseSafetyOnDrawEnd(PPDEVOBJ ppdev);
 
 #ifndef XBUTTON1
 #define XBUTTON1       (0x01)
index 76839b0..82fcb3c 100644 (file)
@@ -40,7 +40,7 @@ typedef struct _PALETTE
   PALOBJ PalObj;
   XLATEOBJ *logicalToSystem;
   HPALETTE Self;
-  ULONG Mode; // PAL_INDEXED, PAL_BITFIELDS, PAL_RGB, PAL_BGR
+  FLONG flFlags; // PAL_INDEXED, PAL_BITFIELDS, PAL_RGB, PAL_BGR
   ULONG NumColors;
   PALETTEENTRY *IndexedColors;
   ULONG RedMask;
@@ -52,8 +52,8 @@ typedef struct _PALETTE
   HDEV  hPDev;
 } PALETTE, *PPALETTE;
 
-extern PALETTE gpalRGB, gpalBGR, gpalMono;
-
+extern PALETTE gpalRGB, gpalBGR, gpalMono, gpalRGB555, gpalRGB565, *gppalDefault;
+extern PPALETTE appalSurfaceDefault[];
 
 HPALETTE FASTCALL PALETTE_AllocPalette(ULONG Mode,
                                        ULONG NumColors,
index ca0c3fa..6a19a1b 100644 (file)
@@ -1,6 +1,5 @@
-#pragma once
-
-#include <drivers/directx/directxint.h>
+#ifndef __WIN32K_PDEVOBJ_H
+#define __WIN32K_PDEVOBJ_H
 
 /* PDEVOBJ flags */
 #define PDEV_DISPLAY             0x00000001 /* Display device */
@@ -37,6 +36,21 @@ typedef struct _GDIPOINTER /* should stay private to ENG? No, part of PDEVOBJ ak
   RECTL    Exclude; /* required publicly for SPS_ACCEPT_EXCLUDE */
 } GDIPOINTER, *PGDIPOINTER;
 
+typedef struct _DEVMODEINFO
+{
+    struct _DEVMODEINFO *pdmiNext;
+    struct _LDEVOBJ *pldev;
+    ULONG cbdevmode;
+    DEVMODEW adevmode[1];
+} DEVMODEINFO, *PDEVMODEINFO;
+
+typedef struct
+{
+    DWORD dwFlags;
+    PDEVMODEW pdm;
+
+} DEVMODEENTRY, *PDEVMODEENTRY;
+
 typedef struct _GRAPHICS_DEVICE
 {
     WCHAR            szNtDeviceName[CCHDEVICENAME/2];
@@ -48,15 +62,17 @@ typedef struct _GRAPHICS_DEVICE
     DWORD            hkClassDriverConfig;
     DWORD            StateFlags;                     /* See DISPLAY_DEVICE_* */
     ULONG            cbdevmodeInfo;
-    PVOID            devmodeInfo;
-    DWORD            cbdevmodeInfo1;
-    PVOID            devmodeInfo1;
-    LPWSTR           pwszDeviceNames;
+    PDEVMODEINFO     pdevmodeInfo;
+    ULONG            cDevModes;
+    PDEVMODEENTRY    pDevModeList;
+    LPWSTR           pDiplayDrivers;
     LPWSTR           pwszDescription;
     DWORD            dwUnknown;
     PVOID            pUnknown;
     PFILE_OBJECT     FileObject;
     DWORD            ProtocolType;
+    ULONG            iDefaultMode;
+    ULONG            iCurrentMode;
 } GRAPHICS_DEVICE, *PGRAPHICS_DEVICE;
 
 typedef struct _PDEVOBJ
@@ -64,8 +80,8 @@ typedef struct _PDEVOBJ
     BASEOBJECT                BaseObject;
 
     struct _PDEVOBJ *         ppdevNext;
-    INT                       cPdevRefs;
-    INT                       cPdevOpenRefs;
+    LONG                      cPdevRefs;
+    LONG                      cPdevOpenRefs;
     struct _PDEVOBJ *         ppdevParent;
     FLONG                     flFlags;  // flags
 //  FLONG                     flAccelerated;
@@ -98,17 +114,17 @@ typedef struct _PDEVOBJ
 //  PFN_DrvSetPalette         pfnDrvSetPalette;
 //  PFN_DrvNotify             pfnDrvNotify;
 //  ULONG                     TagSig;
-//  PLDEVOBJ                  pldev;
+    struct _LDEVOBJ *         pldev;
     DHPDEV                    dhpdev;         /* DHPDEV for device. */
-    PVOID                     ppalSurf;       /* PEPALOBJ/PPALETTE for this device. */
+    struct _PALETTE*          ppalSurf;       /* PEPALOBJ/PPALETTE for this device. */
     DEVINFO                   devinfo;
     GDIINFO                   gdiinfo;
-    HSURF                     pSurface;       /* SURFACE for this device., FIXME: PSURFACE */
+    PSURFACE                  pSurface;       /* SURFACE for this device. */
 //  HANDLE                    hSpooler;       /* Handle to spooler, if spooler dev driver. */
 //  PVOID                     pDesktopId;
     PGRAPHICS_DEVICE          pGraphicsDevice;
     POINTL                    ptlOrigion;
-    PVOID                     pdmwDev;        /* Ptr->DEVMODEW.dmSize + dmDriverExtra == alloc size. */
+    PDEVMODEW                 pdmwDev;        /* Ptr->DEVMODEW.dmSize + dmDriverExtra == alloc size. */
 //  DWORD                     Unknown3;
     FLONG                     DxDd_Flags;     /* DxDD active status flags. */
 //  LONG                      devAttr;
@@ -117,15 +133,12 @@ typedef struct _PDEVOBJ
     union
     {
       DRIVER_FUNCTIONS        DriverFunctions;
+      DRIVER_FUNCTIONS        pfn;
       PVOID                   apfn[INDEX_LAST];         // B8C 0x0598
     };
 
     /* ros specific */
     ULONG         DxDd_nCount;
-    ULONG         DisplayNumber;
-    DEVMODEW      DMW;
-    PFILE_OBJECT  VideoFileObject;
-    BOOLEAN       PreparedDriver;
     GDIPOINTER    Pointer;
     /* Stuff to keep track of software cursors; win32k gdi part */
     UINT SafetyRemoveLevel; /* at what level was the cursor removed?
@@ -134,13 +147,47 @@ typedef struct _PDEVOBJ
     struct _EDD_DIRECTDRAW_GLOBAL * pEDDgpl;
 } PDEVOBJ, *PPDEVOBJ;
 
-/* PDEV and EDDX extra data container.*/
-typedef struct _PDEVEDD
-{
-    PDEVOBJ pdevobj;
-    EDD_DIRECTDRAW_GLOBAL EDDgpl;
-} PDEVEDD, *PPDEVEDD;
+/* Globals ********************************************************************/
+
+extern PPDEVOBJ gppdevPrimary;
+#define pPrimarySurface gppdevPrimary
+
+
+/* Function prototypes ********************************************************/
+
+PPDEVOBJ
+NTAPI
+EngpGetPDEV(PUNICODE_STRING pustrDevice);
+
+VOID
+NTAPI
+PDEVOBJ_vRelease(PPDEVOBJ ppdev);
+
+PSURFACE
+NTAPI
+PDEVOBJ_pSurface(
+    PPDEVOBJ ppdev);
+
+VOID
+NTAPI
+PDEVOBJ_vGetDeviceCaps(
+    PPDEVOBJ ppdev,
+    PDEVCAPS pDevCaps);
+
+BOOL
+NTAPI
+InitPDEVImpl();
+
+BOOL
+NTAPI
+InitLDEVImpl();
+
+BOOL
+NTAPI
+InitDeviceImpl();
 
-PSIZEL FASTCALL PDEV_sizl(PPDEVOBJ, PSIZEL);
+PSIZEL
+FASTCALL
+PDEVOBJ_sizl(PPDEVOBJ, PSIZEL);
 
-extern ULONG gdwDirectDrawContext;
+#endif /* !__WIN32K_PDEVOBJ_H */
index d29b1b0..5ad6e2c 100644 (file)
@@ -14,7 +14,7 @@ typedef struct _ROSRGNDATA
 
   RGNDATAHEADER rdh;
   RECTL        *Buffer;
-} ROSRGNDATA, *PROSRGNDATA, *LPROSRGNDATA;
+} ROSRGNDATA, *PROSRGNDATA, *LPROSRGNDATA, REGION, *PREGION;
 
 
 /* Functions ******************************************************************/
index 3fe9054..485f3dc 100644 (file)
@@ -8,48 +8,88 @@
 /* GDI surface object */
 typedef struct _SURFACE
 {
-  BASEOBJECT  BaseObject;
-
-  SURFOBJ     SurfObj;
-  FLONG              flHooks;
-  FLONG       flFlags;
-  struct _PALETTE  *ppal;
-
-  union
-  {
-    HANDLE    hSecureUMPD;  // if UMPD_SURFACE set
-    HANDLE    hMirrorParent;// if MIRROR_SURFACE set
-    HANDLE    hDDSurface;   // if DIRECTDRAW_SURFACE set
-  };
-
-  SIZEL       dimension;    /* For SetBitmapDimension(), do NOT use
+    BASEOBJECT  BaseObject;
+
+    SURFOBJ     SurfObj;
+    //XDCOBJ *   pdcoAA;
+    FLONG       flags;
+    struct _PALETTE  *ppal;
+    //UINT       unk_050;
+
+    union
+    {
+        HANDLE  hSecureUMPD;  // if UMPD_SURFACE set
+        HANDLE  hMirrorParent;// if MIRROR_SURFACE set
+        HANDLE  hDDSurface;   // if DIRECTDRAW_SURFACE set
+    };
+
+    SIZEL       sizlDim;      /* For SetBitmapDimension(), do NOT use
                                to get width/height of bitmap, use
                                bitmap.bmWidth/bitmap.bmHeight for
                                that */
-  
-  HDC         hDC; // Doc in "Undocumented Windows", page 546, seems to be supported with XP.
-  ULONG       cRef;         // 0x064
-  HPALETTE    hpalHint;
 
-  /* For device-independent bitmaps: */
-  HANDLE      hDIBSection;
-  HANDLE      hSecure;
-  DWORD       dwOffset;
+    HDC         hdc;          // Doc in "Undocumented Windows", page 546, seems to be supported with XP.
+    ULONG       cRef;
+    HPALETTE    hpalHint;
+
+    /* For device-independent bitmaps: */
+    HANDLE      hDIBSection;
+    HANDLE      hSecure;
+    DWORD       dwOffset;
+    //UINT       unk_078;
 
   /* reactos specific */
-  PFAST_MUTEX BitsLock;     /* You need to hold this lock before you touch
-                               the actual bits in the bitmap */
-  HPALETTE hDIBPalette;
-  DWORD dsBitfields[3]; // hack, should probably use palette instead
-  DWORD biClrUsed;
-  DWORD biClrImportant;
+    DWORD biClrImportant;
 } SURFACE, *PSURFACE;
 
-#define BITMAPOBJ_IS_APIBITMAP         0x1
+// flags field:
+//#define HOOK_BITBLT               0x00000001
+//#define HOOK_STRETCHBLT           0x00000002
+//#define HOOK_PLGBLT               0x00000004
+//#define HOOK_TEXTOUT              0x00000008
+//#define HOOK_PAINT                0x00000010
+//#define HOOK_STROKEPATH           0x00000020
+//#define HOOK_FILLPATH             0x00000040
+//#define HOOK_STROKEANDFILLPATH    0x00000080
+//#define HOOK_LINETO               0x00000100
+//#define SHAREACCESS_SURFACE       0x00000200
+//#define HOOK_COPYBITS             0x00000400
+//#define REDIRECTION_SURFACE       0x00000800 // ?
+//#define HOOK_MOVEPANNING          0x00000800
+//#define HOOK_SYNCHRONIZE          0x00001000
+//#define HOOK_STRETCHBLTROP        0x00002000
+//#define HOOK_SYNCHRONIZEACCESS    0x00004000
+//#define USE_DEVLOCK_SURFACE       0x00004000
+//#define HOOK_TRANSPARENTBLT       0x00008000
+//#define HOOK_ALPHABLEND           0x00010000
+//#define HOOK_GRADIENTFILL         0x00020000
+//#if (NTDDI_VERSION < 0x06000000)
+// #define HOOK_FLAGS               0x0003B5FF
+//#else
+// #define HOOK_FLAGS               0x0003B5EF
+//#endif
+#define UMPD_SURFACE              0x00040000
+#define MIRROR_SURFACE            0x00080000
+#define DIRECTDRAW_SURFACE        0x00100000
+#define DRIVER_CREATED_SURFACE    0x00200000
+#define ENG_CREATE_DEVICE_SURFACE 0x00400000
+#define DDB_SURFACE               0x00800000
+#define LAZY_DELETE_SURFACE       0x01000000
+#define BANDING_SURFACE           0x02000000
+#define API_BITMAP                0x04000000
+#define PALETTE_SELECT_SET        0x08000000
+#define UNREADABLE_SURFACE        0x10000000
+#define DYNAMIC_MODE_PALETTE      0x20000000
+#define ABORT_SURFACE             0x40000000
+#define PDEV_SURFACE              0x80000000
+
+
+#define BMF_DONT_FREE 0x100
+#define BMF_RLE_HACK  0x200
+
 
 /*  Internal interface  */
 
-#define SURFACE_AllocSurface()    ((PSURFACE) GDIOBJ_AllocObj(GDIObjType_SURF_TYPE))
 #define SURFACE_AllocSurfaceWithHandle()    ((PSURFACE) GDIOBJ_AllocObjWithHandle(GDI_OBJECT_TYPE_BITMAP))
 #define SURFACE_FreeSurface(pBMObj) GDIOBJ_FreeObj((POBJ) pBMObj, GDIObjType_SURF_TYPE)
 #define SURFACE_FreeSurfaceByHandle(hBMObj) GDIOBJ_FreeObjByHandle((HGDIOBJ) hBMObj, GDI_OBJECT_TYPE_BITMAP)
@@ -64,15 +104,31 @@ typedef struct _SURFACE
 #define  SURFACE_ShareUnlockSurface(pBMObj)  \
   GDIOBJ_ShareUnlockObjByPtr ((POBJ)pBMObj)
 
-#define SURFACE_LockBitmapBits(pBMObj) ExEnterCriticalRegionAndAcquireFastMutexUnsafe((pBMObj)->BitsLock)
-#define SURFACE_UnlockBitmapBits(pBMObj) ExReleaseFastMutexUnsafeAndLeaveCriticalRegion((pBMObj)->BitsLock)
-
 BOOL INTERNAL_CALL SURFACE_Cleanup(PVOID ObjectBody);
-BOOL INTERNAL_CALL SURFACE_InitBitsLock(SURFACE *pBMObj);
-void INTERNAL_CALL SURFACE_CleanupBitsLock(SURFACE *pBMObj);
+
+PSURFACE
+NTAPI
+SURFACE_AllocSurface(
+    IN ULONG iType,
+    IN ULONG cx,
+    IN ULONG cy,
+    IN ULONG iFormat);
+
+BOOL
+NTAPI
+SURFACE_bSetBitmapBits(
+    IN PSURFACE psurf,
+    IN USHORT fjBitmap,
+    IN ULONG ulWidth,
+    IN PVOID pvBits OPTIONAL);
 
 #define GDIDEV(SurfObj) ((PDEVOBJ *)((SurfObj)->hdev))
 #define GDIDEVFUNCS(SurfObj) ((PDEVOBJ *)((SurfObj)->hdev))->DriverFunctions
 
-INT   FASTCALL BitsPerFormat (ULONG Format);
 ULONG FASTCALL BitmapFormat (WORD Bits, DWORD Compression);
+extern UCHAR gajBitsPerFormat[];
+#define BitsPerFormat(Format) gajBitsPerFormat[Format]
+
+#define WIDTH_BYTES_ALIGN32(cx, bpp) ((((cx) * (bpp) + 31) & ~31) >> 3)
+#define WIDTH_BYTES_ALIGN16(cx, bpp) ((((cx) * (bpp) + 15) & ~15) >> 3)
+
index ea3bd61..8bcf046 100644 (file)
@@ -78,4 +78,6 @@
 #include <include/gdifloat.h>
 #include <include/engobjects.h>
 #include <include/engevent.h>
+#include <include/ldevobj.h>
+#include <include/device.h>
 #include <dib/dib.h>
index a2ffedb..18d2f24 100644 (file)
@@ -45,7 +45,6 @@ DbgCmpXlate(XLATEOBJ *pxlo1, XLATEOBJ *pxlo2);
 
 VOID NTAPI EXLATEOBJ_vInitialize(PEXLATEOBJ pexlo, PALETTE *ppalSrc, PALETTE *ppalDst, ULONG, ULONG, ULONG);
 VOID NTAPI EXLATEOBJ_vInitXlateFromDCs(PEXLATEOBJ pexlo, PDC pdcSrc, PDC pdcDst);
-VOID NTAPI EXLATEOBJ_vInitBrushXlate(PEXLATEOBJ pexlo, BRUSH *pbrush, SURFACE *psurf, COLORREF crForegroundClr, COLORREF crBackgroundClr);
 VOID NTAPI EXLATEOBJ_vInitSrcMonoXlate(PEXLATEOBJ pexlo, PPALETTE ppalDst, ULONG Color0, ULONG Color1);
 VOID NTAPI EXLATEOBJ_vCleanup(PEXLATEOBJ pexlo);
 
diff --git a/reactos/subsystems/win32/win32k/ldr/loader.c b/reactos/subsystems/win32/win32k/ldr/loader.c
deleted file mode 100644 (file)
index bc867c2..0000000
+++ /dev/null
@@ -1,264 +0,0 @@
-/*
- *  ReactOS W32 Subsystem
- *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-/* $Id$
- *
- */
-
-#include <win32k.h>
-
-#define NDEBUG
-#include <debug.h>
-
-
-extern LIST_ENTRY GlobalDriverListHead;
-
-
-/*
- * Blatantly stolen from ldr/utils.c in ntdll.  I can't link ntdll from
- * here, though.
- */
-NTSTATUS APIENTRY
-LdrGetProcedureAddress (IN PVOID BaseAddress,
-                        IN PANSI_STRING Name,
-                        IN ULONG Ordinal,
-                        OUT PVOID *ProcedureAddress)
-{
-   PIMAGE_EXPORT_DIRECTORY ExportDir;
-   PUSHORT OrdinalPtr;
-   PULONG NamePtr;
-   PULONG AddressPtr;
-   ULONG i = 0;
-
-   DPRINT("LdrGetProcedureAddress (BaseAddress %x Name %Z Ordinal %lu ProcedureAddress %x)\n",
-          BaseAddress, Name, Ordinal, ProcedureAddress);
-
-   /* Get the pointer to the export directory */
-   ExportDir = (PIMAGE_EXPORT_DIRECTORY)
-                RtlImageDirectoryEntryToData (BaseAddress,
-                                              TRUE,
-                                              IMAGE_DIRECTORY_ENTRY_EXPORT,
-                                              &i);
-
-   DPRINT("ExportDir %x i %lu\n", ExportDir, i);
-
-   if (!ExportDir || !i || !ProcedureAddress)
-     {
-        return STATUS_INVALID_PARAMETER;
-     }
-
-   AddressPtr = (PULONG)((ULONG_PTR)BaseAddress + (ULONG)ExportDir->AddressOfFunctions);
-   if (Name && Name->Length)
-     {
-        /* by name */
-        OrdinalPtr = (PUSHORT)((ULONG_PTR)BaseAddress + (ULONG)ExportDir->AddressOfNameOrdinals);
-        NamePtr = (PULONG)((ULONG_PTR)BaseAddress + (ULONG)ExportDir->AddressOfNames);
-        for( i = 0; i < ExportDir->NumberOfNames; i++, NamePtr++, OrdinalPtr++)
-          {
-             if (!strcmp(Name->Buffer, (char*)((ULONG_PTR)BaseAddress + *NamePtr)))
-               {
-                  *ProcedureAddress = (PVOID)((ULONG_PTR)BaseAddress + (ULONG)AddressPtr[*OrdinalPtr]);
-                  return STATUS_SUCCESS;
-               }
-          }
-        DPRINT1("LdrGetProcedureAddress: Can't resolve symbol '%Z'\n", Name);
-     }
-   else
-     {
-        /* by ordinal */
-        Ordinal &= 0x0000FFFF;
-        if (Ordinal - ExportDir->Base < ExportDir->NumberOfFunctions)
-          {
-             *ProcedureAddress = (PVOID)((ULONG_PTR)BaseAddress + (ULONG_PTR)AddressPtr[Ordinal - ExportDir->Base]);
-             return STATUS_SUCCESS;
-          }
-        DPRINT1("LdrGetProcedureAddress: Can't resolve symbol @%d\n", Ordinal);
-  }
-
-   return STATUS_PROCEDURE_NOT_FOUND;
-}
-
-PVOID APIENTRY
-EngFindImageProcAddress(IN HANDLE Module,
-                       IN LPSTR ProcName)
-{
-  PVOID Function;
-  NTSTATUS Status;
-  ANSI_STRING ProcNameString;
-  unsigned i;
-  static struct
-    {
-      PCSTR ProcName;
-      PVOID ProcAddress;
-    }
-  Win32kExports[] =
-    {
-      { "BRUSHOBJ_hGetColorTransform",    BRUSHOBJ_hGetColorTransform    },
-      { "EngAlphaBlend",                  EngAlphaBlend                  },
-      { "EngClearEvent",                  EngClearEvent                  },
-      { "EngControlSprites",              EngControlSprites              },
-      { "EngCreateEvent",                 EngCreateEvent                 },
-      { "EngDeleteEvent",                 EngDeleteEvent                 },
-      { "EngDeleteFile",                  EngDeleteFile                  },
-      { "EngDeleteSafeSemaphore",         EngDeleteSafeSemaphore         },
-      { "EngDeleteWnd",                   EngDeleteWnd                   },
-      { "EngDitherColor",                 EngDitherColor                 },
-      { "EngGetPrinterDriver",            EngGetPrinterDriver            },
-      { "EngGradientFill",                EngGradientFill                },
-      { "EngHangNotification",            EngHangNotification            },
-      { "EngInitializeSafeSemaphore",     EngInitializeSafeSemaphore     },
-      { "EngLockDirectDrawSurface",       EngLockDirectDrawSurface       },
-      { "EngLpkInstalled",                EngLpkInstalled                },
-      { "EngMapEvent",                    EngMapEvent                    },
-      { "EngMapFile",                     EngMapFile                     },
-      { "EngMapFontFileFD",               EngMapFontFileFD               },
-      { "EngModifySurface",               EngModifySurface               },
-      { "EngMovePointer",                 EngMovePointer                 },
-      { "EngPlgBlt",                      EngPlgBlt                      },
-      { "EngQueryDeviceAttribute",        EngQueryDeviceAttribute        },
-      { "EngQueryPalette",                EngQueryPalette                },
-      { "EngQuerySystemAttribute",        EngQuerySystemAttribute        },
-      { "EngReadStateEvent",              EngReadStateEvent              },
-      { "EngRestoreFloatingPointState",   EngRestoreFloatingPointState   },
-      { "EngSaveFloatingPointState",      EngSaveFloatingPointState      },
-      { "EngSetEvent",                    EngSetEvent                    },
-      { "EngSetPointerShape",             EngSetPointerShape             },
-      { "EngSetPointerTag",               EngSetPointerTag               },
-      { "EngStretchBltROP",               EngStretchBltROP               },
-      { "EngTransparentBlt",              EngTransparentBlt              },
-      { "EngUnlockDirectDrawSurface",     EngUnlockDirectDrawSurface     },
-      { "EngUnmapEvent",                  EngUnmapEvent                  },
-      { "EngUnmapFile",                   EngUnmapFile                   },
-      { "EngUnmapFontFileFD",             EngUnmapFontFileFD             },
-      { "EngWaitForSingleObject",         EngWaitForSingleObject         },
-      { "FONTOBJ_pfdg",                   FONTOBJ_pfdg                   },
-      { "FONTOBJ_pjOpenTypeTablePointer", FONTOBJ_pjOpenTypeTablePointer },
-      { "FONTOBJ_pQueryGlyphAttrs",       FONTOBJ_pQueryGlyphAttrs       },
-      { "FONTOBJ_pwszFontFilePaths",      FONTOBJ_pwszFontFilePaths      },
-      { "HeapVidMemAllocAligned",         HeapVidMemAllocAligned         },
-      { "HT_Get8BPPMaskPalette",          HT_Get8BPPMaskPalette          },
-      { "STROBJ_bEnumPositionsOnly",      STROBJ_bEnumPositionsOnly      },
-      { "STROBJ_bGetAdvanceWidths",       STROBJ_bGetAdvanceWidths       },
-      { "STROBJ_fxBreakExtra",            STROBJ_fxBreakExtra            },
-      { "STROBJ_fxCharacterExtra",        STROBJ_fxCharacterExtra        },
-      { "VidMemFree",                     VidMemFree                     },
-      { "XLATEOBJ_hGetColorTransform",    XLATEOBJ_hGetColorTransform    }
-    };
-
-  if (NULL == Module)
-    {
-      DPRINT("Looking for win32k export %s\n", ProcName);
-      for (i = 0; i < sizeof(Win32kExports) / sizeof(Win32kExports[0]); i++)
-        {
-          if (0 == strcmp(ProcName, Win32kExports[i].ProcName))
-            {
-              DPRINT("Found it index %u address %p\n", i, Win32kExports[i].ProcName);
-              return Win32kExports[i].ProcAddress;
-            }
-        }
-      return NULL;
-    }
-  RtlInitAnsiString(&ProcNameString, ProcName);
-  Status = LdrGetProcedureAddress(((PDRIVERS)Module)->BaseAddress,
-                                 &ProcNameString,
-                                 0,
-                                 &Function);
-  if (!NT_SUCCESS(Status))
-    {
-      return(NULL);
-    }
-  return(Function);
-}
-
-
-/*
- * @implemented
- */
-HANDLE
-APIENTRY
-EngLoadImage (LPWSTR DriverName)
-{
-       SYSTEM_GDI_DRIVER_INFORMATION GdiDriverInfo;
-       PDRIVERS DriverInfo = NULL;
-       NTSTATUS Status;
-
-       RtlInitUnicodeString(&GdiDriverInfo.DriverName, DriverName);
-       if( !IsListEmpty(&GlobalDriverListHead) )
-       {
-               PLIST_ENTRY CurrentEntry = GlobalDriverListHead.Flink;
-               PDRIVERS Current;
-               /* probably the driver was already loaded, let's try to find it out */
-               while( CurrentEntry != &GlobalDriverListHead )
-               {
-                       Current = CONTAINING_RECORD(CurrentEntry, DRIVERS, ListEntry);
-                       if( Current && (0 == RtlCompareUnicodeString(&GdiDriverInfo.DriverName, &Current->DriverName, FALSE)) ) {
-                               DriverInfo = Current;
-                               break;
-                       }
-                       CurrentEntry = CurrentEntry->Flink;
-               };
-       }
-
-       if( !DriverInfo )
-       {
-               /* the driver was not loaded before, so let's do that */
-               Status = ZwSetSystemInformation(SystemLoadGdiDriverInformation, &GdiDriverInfo, sizeof(SYSTEM_GDI_DRIVER_INFORMATION));
-               if (!NT_SUCCESS(Status)) {
-                       DPRINT1("ZwSetSystemInformation failed with Status 0x%lx\n", Status);
-               }
-               else {
-                       DriverInfo = ExAllocatePoolWithTag(PagedPool, sizeof(DRIVERS), TAG_DRIVER);
-                       DriverInfo->DriverName.MaximumLength = GdiDriverInfo.DriverName.MaximumLength;
-                       DriverInfo->DriverName.Length = GdiDriverInfo.DriverName.Length;
-                       DriverInfo->DriverName.Buffer = ExAllocatePoolWithTag(PagedPool, GdiDriverInfo.DriverName.MaximumLength, TAG_DRIVER);
-                       RtlCopyUnicodeString(&DriverInfo->DriverName, &GdiDriverInfo.DriverName);
-                       DriverInfo->SectionPointer = GdiDriverInfo.SectionPointer;
-            DriverInfo->BaseAddress = GdiDriverInfo.ImageAddress;
-                       InsertHeadList(&GlobalDriverListHead, &DriverInfo->ListEntry);
-               }
-       }
-
-       return DriverInfo;
-}
-
-VOID
-APIENTRY
-EngUnloadImage ( IN HANDLE hModule )
-{
-  NTSTATUS Status;
-  PDRIVERS DriverInfo = (PDRIVERS)hModule;
-
-  DPRINT("hModule 0x%x\n", hModule);
-
-  Status = ZwSetSystemInformation(SystemUnloadGdiDriverInformation,
-    DriverInfo->SectionPointer, sizeof(PVOID));
-
-  if(!NT_SUCCESS(Status))
-  {
-    DPRINT1("ZwSetSystemInformation failed with status 0x%08X\n",
-      Status);
-  }
-  else
-  {
-    ExFreePool(DriverInfo->DriverName.Buffer);
-    RemoveEntryList(&DriverInfo->ListEntry);
-    ExFreePool(DriverInfo);
-  }
-}
-
-/* EOF */
index 603dd94..b12d96f 100644 (file)
@@ -34,8 +34,6 @@ BOOL INTERNAL_CALL GDI_CleanupForProcess (struct _EPROCESS *Process);
 PGDI_HANDLE_TABLE GdiHandleTable = NULL;
 PSECTION_OBJECT GdiTableSection = NULL;
 
-LIST_ENTRY GlobalDriverListHead;
-
 HANDLE GlobalUserHeap = NULL;
 PSECTION_OBJECT GlobalUserHeapSection = NULL;
 
@@ -368,6 +366,7 @@ Win32kInitWin32Thread(PETHREAD Thread)
   return(STATUS_SUCCESS);
 }
 
+C_ASSERT(sizeof(SERVERINFO) <= PAGE_SIZE);
 
 /*
  * This definition doesn't work
@@ -423,8 +422,19 @@ DriverEntry (
         return STATUS_UNSUCCESSFUL;
     }
 
-  /* Initialize a list of loaded drivers in Win32 subsystem */
-  InitializeListHead(&GlobalDriverListHead);
+   if (!gpsi)
+   {
+      gpsi = UserHeapAlloc(sizeof(SERVERINFO));
+      if (gpsi)
+      {
+         RtlZeroMemory(gpsi, sizeof(SERVERINFO));
+         DPRINT("Global Server Data -> %x\n", gpsi);
+      }
+      else
+      {
+          ASSERT(FALSE);
+      }
+   }
 
   if(!hsemDriverMgmt) hsemDriverMgmt = EngCreateSemaphore();
 
@@ -435,6 +445,26 @@ DriverEntry (
       return STATUS_UNSUCCESSFUL;
   }
 
+  /* Initialize default palettes */
+  PALETTE_Init();
+
+  /* Create stock objects, ie. precreated objects commonly
+     used by win32 applications */
+  CreateStockObjects();
+  CreateSysColorObjects();
+
+  InitXlateImpl();
+  InitPDEVImpl();
+  InitLDEVImpl();
+  InitDeviceImpl();
+
+  Status = InitDcImpl();
+  if (!NT_SUCCESS(Status))
+  {
+    DPRINT1("Failed to initialize Device context implementation!\n");
+    return STATUS_UNSUCCESSFUL;
+  }
+
   Status = InitUserImpl();
   if (!NT_SUCCESS(Status))
   {
@@ -526,13 +556,6 @@ DriverEntry (
       return(Status);
     }
 
-  Status = InitDcImpl();
-  if (!NT_SUCCESS(Status))
-  {
-    DPRINT1("Failed to initialize Device context implementation!\n");
-    return STATUS_UNSUCCESSFUL;
-  }
-
   /* Initialize FreeType library */
   if (! InitFontSupport())
     {
@@ -540,13 +563,6 @@ DriverEntry (
       return STATUS_UNSUCCESSFUL;
     }
 
-  InitXlateImpl();
-
-  /* Create stock objects, ie. precreated objects commonly
-     used by win32 applications */
-  CreateStockObjects();
-  CreateSysColorObjects();
-
   gusLanguageID = IntGdiGetLanguageID();
 
   return STATUS_SUCCESS;
index a40a5be..6a50d55 100644 (file)
@@ -5,7 +5,7 @@ NTSTATUS _MmCopyFromCaller( PVOID Target, PVOID Source, UINT Bytes ) {
 
     _SEH2_TRY
     {
-        /* ProbeForRead(Source,Bytes,1); */
+        ProbeForRead(Source,Bytes,1);
         RtlCopyMemory(Target,Source,Bytes);
     }
     _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
index 8b25b13..8b13789 100644 (file)
@@ -1,621 +1 @@
-/*
- *  ReactOS W32 Subsystem
- *  Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License along
- *  with this program; if not, write to the Free Software Foundation, Inc.,
- *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-/* $Id$
- *
- * GDI Driver support routines
- * (mostly swiped from Wine)
- *
- */
 
-#include <win32k.h>
-
-#define NDEBUG
-#include <debug.h>
-
-/* #define TRACE_DRV_CALLS to get a log of all calls into the display driver. */
-#undef TRACE_DRV_CALLS
-
-
-typedef struct _GRAPHICS_DRIVER
-{
-  PWSTR  Name;
-  PFN_DrvEnableDriver  EnableDriver;
-  int  ReferenceCount;
-  struct _GRAPHICS_DRIVER  *Next;
-} GRAPHICS_DRIVER, *PGRAPHICS_DRIVER;
-
-static PGRAPHICS_DRIVER  DriverList;
-static PGRAPHICS_DRIVER  GenericDriver = NULL;
-
-BOOL DRIVER_RegisterDriver(LPCWSTR  Name, PFN_DrvEnableDriver  EnableDriver)
-{
-  PGRAPHICS_DRIVER  Driver;
-  
-  DPRINT( "DRIVER_RegisterDriver( Name: %S )\n", Name );
-  
-  if (GenericDriver != NULL)
-  {
-     return FALSE;
-  }
-  Driver = ExAllocatePoolWithTag(PagedPool, sizeof(*Driver), TAG_DRIVER);
-  if (!Driver)  return  FALSE;
-  Driver->ReferenceCount = 0;
-  Driver->EnableDriver = EnableDriver;
-  if (Name)
-  {
-    Driver->Name = ExAllocatePoolWithTag(PagedPool,
-                                         (wcslen(Name) + 1) * sizeof(WCHAR),
-                                         TAG_DRIVER);
-    if (Driver->Name == NULL)
-    {
-        DPRINT1("Out of memory\n");
-        ExFreePoolWithTag(Driver, TAG_DRIVER);
-        return  FALSE;
-    }
-
-    wcscpy(Driver->Name, Name);
-    Driver->Next  = DriverList;
-    DriverList = Driver;
-    return  TRUE;
-  }
-
-  GenericDriver = Driver;
-  return  TRUE;
-}
-
-PFN_DrvEnableDriver DRIVER_FindExistingDDIDriver(LPCWSTR Name)
-{
-  GRAPHICS_DRIVER *Driver = DriverList;
-  while (Driver && Name)
-  {
-    if (!_wcsicmp(Driver->Name, Name))
-    {
-      return Driver->EnableDriver;
-    }
-    Driver = Driver->Next;
-  }
-
-  return NULL;
-}
-
-PFN_DrvEnableDriver DRIVER_FindDDIDriver(LPCWSTR Name)
-{
-  static WCHAR DefaultPath[] = L"\\SystemRoot\\System32\\";
-  static WCHAR DefaultExtension[] = L".DLL";
-  PFN_DrvEnableDriver ExistingDriver;
-  SYSTEM_GDI_DRIVER_INFORMATION GdiDriverInfo;
-  NTSTATUS Status;
-  LPWSTR FullName;
-  LPCWSTR p;
-  BOOL PathSeparatorFound;
-  BOOL DotFound;
-  UINT Size;
-
-  DotFound = FALSE;
-  PathSeparatorFound = FALSE;
-  p = Name;
-  while (L'\0' != *p)
-  {
-    if (L'\\' == *p || L'/' == *p)
-    {
-      PathSeparatorFound = TRUE;
-      DotFound = FALSE;
-    }
-    else if (L'.' == *p)
-    {
-      DotFound = TRUE;
-    }
-    p++;
-  }
-
-  Size = (wcslen(Name) + 1) * sizeof(WCHAR);
-  if (! PathSeparatorFound)
-  {
-    Size += sizeof(DefaultPath) - sizeof(WCHAR);
-  }
-  if (! DotFound)
-  {
-    Size += sizeof(DefaultExtension) - sizeof(WCHAR);
-  }
-  FullName = ExAllocatePoolWithTag(PagedPool, Size, TAG_DRIVER);
-  if (NULL == FullName)
-  {
-    DPRINT1("Out of memory\n");
-    return NULL;
-  }
-  if (PathSeparatorFound)
-  {
-    FullName[0] = L'\0';
-  }
-  else
-  {
-    wcscpy(FullName, DefaultPath);
-  }
-  wcscat(FullName, Name);
-  if (! DotFound)
-  {
-    wcscat(FullName, DefaultExtension);
-  }
-
-  /* First see if the driver hasn't already been loaded */
-  ExistingDriver = DRIVER_FindExistingDDIDriver(FullName);
-  if (ExistingDriver)
-  {
-    ExFreePoolWithTag(FullName, TAG_DRIVER);
-    return ExistingDriver;
-  }
-
-  /* If not, then load it */
-  RtlInitUnicodeString (&GdiDriverInfo.DriverName, FullName);
-  Status = ZwSetSystemInformation (SystemLoadGdiDriverInformation, &GdiDriverInfo, sizeof(SYSTEM_GDI_DRIVER_INFORMATION));
-
-  if (!NT_SUCCESS(Status))
-  {
-    ExFreePoolWithTag(FullName, TAG_DRIVER);
-    return NULL;
-  }
-
-  DRIVER_RegisterDriver( L"DISPLAY", GdiDriverInfo.EntryPoint);
-  DRIVER_RegisterDriver( FullName, GdiDriverInfo.EntryPoint);
-  ExFreePoolWithTag(FullName, TAG_DRIVER);
-  return (PFN_DrvEnableDriver)GdiDriverInfo.EntryPoint;
-}
-
-#define BEGIN_FUNCTION_MAP() \
-  ULONG i; \
-  for (i = 0; i < DED->c; i++) \
-  { \
-    switch(DED->pdrvfn[i].iFunc) \
-    {
-
-#define END_FUNCTION_MAP() \
-      default: \
-        DPRINT1("Unsupported DDI function 0x%x\n", DED->pdrvfn[i].iFunc); \
-        break; \
-    } \
-  }
-
-#ifdef TRACE_DRV_CALLS
-
-typedef struct _TRACEDRVINFO
-  {
-  unsigned Index;
-  char *Name;
-  PVOID DrvRoutine;
-  }
-TRACEDRVINFO, *PTRACEDRVINFO;
-
-__asm__(
-" .text\n"
-"TraceDrv:\n"
-" pushl %eax\n"
-" call  _FindTraceInfo\n"
-" add   $4,%esp\n"
-" pushl %eax\n"
-" pushl 4(%eax)\n"
-" call  _DbgPrint\n"
-" addl  $4,%esp\n"
-" popl  %eax\n"
-" mov   8(%eax),%eax\n"
-" jmp   *%eax\n"
-);
-
-#define TRACEDRV_ROUTINE(function) \
-unsigned TraceDrvIndex##function = INDEX_Drv##function; \
-__asm__ ( \
-" .text\n" \
-"_Trace" #function ":\n" \
-" movl _TraceDrvIndex" #function ",%eax\n" \
-" jmp TraceDrv\n" \
-); \
-extern PVOID Trace##function;
-
-TRACEDRV_ROUTINE(EnablePDEV)
-TRACEDRV_ROUTINE(CompletePDEV)
-TRACEDRV_ROUTINE(DisablePDEV)
-TRACEDRV_ROUTINE(EnableSurface)
-TRACEDRV_ROUTINE(DisableSurface)
-TRACEDRV_ROUTINE(AssertMode)
-TRACEDRV_ROUTINE(Offset)
-TRACEDRV_ROUTINE(ResetPDEV)
-TRACEDRV_ROUTINE(DisableDriver)
-TRACEDRV_ROUTINE(CreateDeviceBitmap)
-TRACEDRV_ROUTINE(DeleteDeviceBitmap)
-TRACEDRV_ROUTINE(RealizeBrush)
-TRACEDRV_ROUTINE(DitherColor)
-TRACEDRV_ROUTINE(StrokePath)
-TRACEDRV_ROUTINE(FillPath)
-TRACEDRV_ROUTINE(StrokeAndFillPath)
-TRACEDRV_ROUTINE(Paint)
-TRACEDRV_ROUTINE(BitBlt)
-TRACEDRV_ROUTINE(TransparentBlt)
-TRACEDRV_ROUTINE(CopyBits)
-TRACEDRV_ROUTINE(StretchBlt)
-TRACEDRV_ROUTINE(StretchBltROP)
-TRACEDRV_ROUTINE(SetPalette)
-TRACEDRV_ROUTINE(TextOut)
-TRACEDRV_ROUTINE(Escape)
-TRACEDRV_ROUTINE(DrawEscape)
-TRACEDRV_ROUTINE(QueryFont)
-TRACEDRV_ROUTINE(QueryFontTree)
-TRACEDRV_ROUTINE(QueryFontData)
-TRACEDRV_ROUTINE(SetPointerShape)
-TRACEDRV_ROUTINE(MovePointer)
-TRACEDRV_ROUTINE(LineTo)
-TRACEDRV_ROUTINE(SendPage)
-TRACEDRV_ROUTINE(StartPage)
-TRACEDRV_ROUTINE(EndDoc)
-TRACEDRV_ROUTINE(StartDoc)
-TRACEDRV_ROUTINE(GetGlyphMode)
-TRACEDRV_ROUTINE(Synchronize)
-TRACEDRV_ROUTINE(SaveScreenBits)
-TRACEDRV_ROUTINE(GetModes)
-TRACEDRV_ROUTINE(Free)
-TRACEDRV_ROUTINE(DestroyFont)
-TRACEDRV_ROUTINE(QueryFontCaps)
-TRACEDRV_ROUTINE(LoadFontFile)
-TRACEDRV_ROUTINE(UnloadFontFile)
-TRACEDRV_ROUTINE(FontManagement)
-TRACEDRV_ROUTINE(QueryTrueTypeTable)
-TRACEDRV_ROUTINE(QueryTrueTypeOutline)
-TRACEDRV_ROUTINE(GetTrueTypeFile)
-TRACEDRV_ROUTINE(QueryFontFile)
-TRACEDRV_ROUTINE(QueryAdvanceWidths)
-TRACEDRV_ROUTINE(SetPixelFormat)
-TRACEDRV_ROUTINE(DescribePixelFormat)
-TRACEDRV_ROUTINE(SwapBuffers)
-TRACEDRV_ROUTINE(StartBanding)
-TRACEDRV_ROUTINE(NextBand)
-TRACEDRV_ROUTINE(GetDirectDrawInfo)
-TRACEDRV_ROUTINE(EnableDirectDraw)
-TRACEDRV_ROUTINE(DisableDirectDraw)
-TRACEDRV_ROUTINE(QuerySpoolType)
-TRACEDRV_ROUTINE(IcmSetDeviceGammaRamp)
-TRACEDRV_ROUTINE(GradientFill)
-TRACEDRV_ROUTINE(SynchronizeSurface)
-TRACEDRV_ROUTINE(AlphaBlend)
-
-#define TRACEDRVINFO_ENTRY(function) \
-    { INDEX_Drv##function, "Drv" #function "\n", NULL }
-static TRACEDRVINFO TraceDrvInfo[] =
-  {
-    TRACEDRVINFO_ENTRY(EnablePDEV),
-    TRACEDRVINFO_ENTRY(CompletePDEV),
-    TRACEDRVINFO_ENTRY(DisablePDEV),
-    TRACEDRVINFO_ENTRY(EnableSurface),
-    TRACEDRVINFO_ENTRY(DisableSurface),
-    TRACEDRVINFO_ENTRY(AssertMode),
-    TRACEDRVINFO_ENTRY(Offset),
-    TRACEDRVINFO_ENTRY(ResetPDEV),
-    TRACEDRVINFO_ENTRY(DisableDriver),
-    TRACEDRVINFO_ENTRY(CreateDeviceBitmap),
-    TRACEDRVINFO_ENTRY(DeleteDeviceBitmap),
-    TRACEDRVINFO_ENTRY(RealizeBrush),
-    TRACEDRVINFO_ENTRY(DitherColor),
-    TRACEDRVINFO_ENTRY(StrokePath),
-    TRACEDRVINFO_ENTRY(FillPath),
-    TRACEDRVINFO_ENTRY(StrokeAndFillPath),
-    TRACEDRVINFO_ENTRY(Paint),
-    TRACEDRVINFO_ENTRY(BitBlt),
-    TRACEDRVINFO_ENTRY(TransparentBlt),
-    TRACEDRVINFO_ENTRY(CopyBits),
-    TRACEDRVINFO_ENTRY(StretchBlt),
-    TRACEDRVINFO_ENTRY(StretchBltROP),
-    TRACEDRVINFO_ENTRY(SetPalette),
-    TRACEDRVINFO_ENTRY(TextOut),
-    TRACEDRVINFO_ENTRY(Escape),
-    TRACEDRVINFO_ENTRY(DrawEscape),
-    TRACEDRVINFO_ENTRY(QueryFont),
-    TRACEDRVINFO_ENTRY(QueryFontTree),
-    TRACEDRVINFO_ENTRY(QueryFontData),
-    TRACEDRVINFO_ENTRY(SetPointerShape),
-    TRACEDRVINFO_ENTRY(MovePointer),
-    TRACEDRVINFO_ENTRY(LineTo),
-    TRACEDRVINFO_ENTRY(SendPage),
-    TRACEDRVINFO_ENTRY(StartPage),
-    TRACEDRVINFO_ENTRY(EndDoc),
-    TRACEDRVINFO_ENTRY(StartDoc),
-    TRACEDRVINFO_ENTRY(GetGlyphMode),
-    TRACEDRVINFO_ENTRY(Synchronize),
-    TRACEDRVINFO_ENTRY(SaveScreenBits),
-    TRACEDRVINFO_ENTRY(GetModes),
-    TRACEDRVINFO_ENTRY(Free),
-    TRACEDRVINFO_ENTRY(DestroyFont),
-    TRACEDRVINFO_ENTRY(QueryFontCaps),
-    TRACEDRVINFO_ENTRY(LoadFontFile),
-    TRACEDRVINFO_ENTRY(UnloadFontFile),
-    TRACEDRVINFO_ENTRY(FontManagement),
-    TRACEDRVINFO_ENTRY(QueryTrueTypeTable),
-    TRACEDRVINFO_ENTRY(QueryTrueTypeOutline),
-    TRACEDRVINFO_ENTRY(GetTrueTypeFile),
-    TRACEDRVINFO_ENTRY(QueryFontFile),
-    TRACEDRVINFO_ENTRY(QueryAdvanceWidths),
-    TRACEDRVINFO_ENTRY(SetPixelFormat),
-    TRACEDRVINFO_ENTRY(DescribePixelFormat),
-    TRACEDRVINFO_ENTRY(SwapBuffers),
-    TRACEDRVINFO_ENTRY(StartBa