[WIN32K]
[reactos.git] / reactos / win32ss / gdi / eng / device.c
index da22999..8b3b744 100644 (file)
@@ -8,9 +8,7 @@
  */
 
 #include <win32k.h>
-
-#define NDEBUG
-#include <debug.h>
+DBG_DEFAULT_CHANNEL(EngDev)
 
 PGRAPHICS_DEVICE gpPrimaryGraphicsDevice;
 PGRAPHICS_DEVICE gpVgaGraphicsDevice;
@@ -47,12 +45,13 @@ EngpRegisterGraphicsDevice(
     NTSTATUS Status;
     PWSTR pwsz;
     ULONG i, cj, cModes = 0;
+    SIZE_T cjWritten;
     BOOL bEnable = TRUE;
     PDEVMODEINFO pdminfo;
     PDEVMODEW pdm, pdmEnd;
     PLDEVOBJ pldev;
 
-    DPRINT("EngpRegisterGraphicsDevice(%wZ)\n", pustrDeviceName);
+    TRACE("EngpRegisterGraphicsDevice(%wZ)\n", pustrDeviceName);
 
     /* Allocate a GRAPHICS_DEVICE structure */
     pGraphicsDevice = ExAllocatePoolWithTag(PagedPool,
@@ -60,7 +59,7 @@ EngpRegisterGraphicsDevice(
                                             GDITAG_GDEVICE);
     if (!pGraphicsDevice)
     {
-        DPRINT1("ExAllocatePoolWithTag failed\n");
+        ERR("ExAllocatePoolWithTag failed\n");
         return NULL;
     }
 
@@ -71,13 +70,13 @@ EngpRegisterGraphicsDevice(
                                       &pDeviceObject);
     if (!NT_SUCCESS(Status))
     {
-        DPRINT1("Could not open driver %wZ, 0x%lx\n", pustrDeviceName, Status);
+        ERR("Could not open driver %wZ, 0x%lx\n", pustrDeviceName, Status);
         ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
         return NULL;
     }
 
     /* Enable the device */
-    EngFileWrite(pFileObject, &bEnable, sizeof(BOOL), &cj);
+    EngFileWrite(pFileObject, &bEnable, sizeof(BOOL), &cjWritten);
 
     /* Copy the device and file object pointers */
     pGraphicsDevice->DeviceObject = pDeviceObject;
@@ -97,7 +96,7 @@ EngpRegisterGraphicsDevice(
     pwsz = ExAllocatePoolWithTag(PagedPool, cj, GDITAG_DRVSUP);
     if (!pwsz)
     {
-        DPRINT1("Could not allocate string buffer\n");
+        ERR("Could not allocate string buffer\n");
         ASSERT(FALSE); // FIXME
         ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
         return NULL;
@@ -127,12 +126,12 @@ EngpRegisterGraphicsDevice(
      * This is a REG_MULTI_SZ string */
     for (; *pwsz; pwsz += wcslen(pwsz) + 1)
     {
-        DPRINT("trying driver: %ls\n", pwsz);
+        TRACE("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);
+            ERR("Could not load driver: '%ls'\n", pwsz);
             continue;
         }
 
@@ -140,7 +139,7 @@ EngpRegisterGraphicsDevice(
         pdminfo = LDEVOBJ_pdmiGetModes(pldev, pDeviceObject);
         if (!pdminfo)
         {
-            DPRINT1("Could not get mode list for '%ls'\n", pwsz);
+            ERR("Could not get mode list for '%ls'\n", pwsz);
             continue;
         }
 
@@ -168,7 +167,7 @@ EngpRegisterGraphicsDevice(
 
     if (!pGraphicsDevice->pdevmodeInfo || cModes == 0)
     {
-        DPRINT1("No devmodes\n");
+        ERR("No devmodes\n");
         ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
         return NULL;
     }
@@ -180,11 +179,18 @@ EngpRegisterGraphicsDevice(
                                                           GDITAG_GDEVICE);
     if (!pGraphicsDevice->pDevModeList)
     {
-        DPRINT1("No devmode list\n");
+        ERR("No devmode list\n");
         ExFreePoolWithTag(pGraphicsDevice, GDITAG_GDEVICE);
         return NULL;
     }
 
+    TRACE("Looking for mode %lux%lux%lu(%lu Hz)\n",
+        pdm->dmDeviceName,
+        pdm->dmPelsWidth,
+        pdm->dmPelsHeight,
+        pdm->dmBitsPerPel,
+        pdm->dmDisplayFrequency);
+
     /* Loop through all DEVMODEINFOs */
     for (pdminfo = pGraphicsDevice->pdevmodeInfo, i = 0;
          pdminfo;
@@ -198,6 +204,12 @@ EngpRegisterGraphicsDevice(
              (pdm + 1 <= pdmEnd) && (pdm->dmSize != 0);
              pdm = (PDEVMODEW)((PCHAR)pdm + pdm->dmSize + pdm->dmDriverExtra))
         {
+            TRACE("    %S has mode %lux%lux%lu(%lu Hz)\n",
+                  pdm->dmDeviceName,
+                  pdm->dmPelsWidth,
+                  pdm->dmPelsHeight,
+                  pdm->dmBitsPerPel,
+                  pdm->dmDisplayFrequency);
             /* Compare with the default entry */
             if (pdm->dmBitsPerPel == pdmDefault->dmBitsPerPel &&
                 pdm->dmPelsWidth == pdmDefault->dmPelsWidth &&
@@ -206,7 +218,7 @@ EngpRegisterGraphicsDevice(
             {
                 pGraphicsDevice->iDefaultMode = i;
                 pGraphicsDevice->iCurrentMode = i;
-                DPRINT("Found default entry: %ld '%ls'\n", i, pdm->dmDeviceName);
+                TRACE("Found default entry: %lu '%ls'\n", i, pdm->dmDeviceName);
             }
 
             /* Initialize the entry */
@@ -232,7 +244,7 @@ EngpRegisterGraphicsDevice(
 
     /* Unlock loader */
     EngReleaseSemaphore(ghsemGraphicsDeviceList);
-    DPRINT("Prepared %ld modes for %ls\n", cModes, pGraphicsDevice->pwszDescription);
+    TRACE("Prepared %lu modes for %ls\n", cModes, pGraphicsDevice->pwszDescription);
 
     return pGraphicsDevice;
 }
@@ -248,7 +260,7 @@ EngpFindGraphicsDevice(
     UNICODE_STRING ustrCurrent;
     PGRAPHICS_DEVICE pGraphicsDevice;
     ULONG i;
-    DPRINT("EngpFindGraphicsDevice('%wZ', %ld, 0x%lx)\n",
+    TRACE("EngpFindGraphicsDevice('%wZ', %lu, 0x%lx)\n",
            pustrDevice, iDevNum, dwFlags);
 
     /* Lock list */
@@ -288,11 +300,11 @@ static
 NTSTATUS
 EngpFileIoRequest(
     PFILE_OBJECT pFileObject,
-    ULONG   ulMajorFunction,
-    LPVOID  lpBuffer,
-    DWORD   nBufferSize,
-    ULONGLONG  ullStartOffset,
-    OUT LPDWORD lpInformation)
+    ULONG ulMajorFunction,
+    LPVOID lpBuffer,
+    SIZE_T nBufferSize,
+    ULONGLONG ullStartOffset,
+    OUT PULONG_PTR lpInformation)
 {
     PDEVICE_OBJECT pDeviceObject;
     KEVENT Event;
@@ -316,7 +328,7 @@ EngpFileIoRequest(
     pIrp = IoBuildSynchronousFsdRequest(ulMajorFunction,
                                         pDeviceObject,
                                         lpBuffer,
-                                        nBufferSize,
+                                        (ULONG)nBufferSize,
                                         &liStartOffset,
                                         &Event,
                                         &Iosb);
@@ -367,7 +379,7 @@ EngFileIoControl(
     IN SIZE_T nInBufferSize,
     OUT PVOID lpOutBuffer,
     IN SIZE_T nOutBufferSize,
-    OUT LPDWORD lpInformation)
+    OUT PULONG_PTR lpInformation)
 {
     PDEVICE_OBJECT pDeviceObject;
     KEVENT Event;
@@ -389,9 +401,9 @@ EngFileIoControl(
     pIrp = IoBuildDeviceIoControlRequest(dwIoControlCode,
                                          pDeviceObject,
                                          lpInBuffer,
-                                         nInBufferSize,
+                                         (ULONG)nInBufferSize,
                                          lpOutBuffer,
-                                         nOutBufferSize,
+                                         (ULONG)nOutBufferSize,
                                          FALSE,
                                          &Event,
                                          &Iosb);
@@ -422,13 +434,13 @@ EngFileIoControl(
  */
 DWORD APIENTRY
 EngDeviceIoControl(
-    HANDLE  hDevice,
-    DWORD   dwIoControlCode,
-    LPVOID  lpInBuffer,
-    DWORD   nInBufferSize,
-    LPVOID  lpOutBuffer,
-    DWORD   nOutBufferSize,
-    DWORD *lpBytesReturned)
+    _In_ HANDLE hDevice,
+    _In_ DWORD dwIoControlCode,
+    _In_opt_bytecount_(cjInBufferSize) LPVOID lpInBuffer,
+    _In_ DWORD cjInBufferSize,
+    _Out_opt_bytecap_(cjOutBufferSize) LPVOID lpOutBuffer,
+    _In_ DWORD cjOutBufferSize,
+    _Out_ LPDWORD lpBytesReturned)
 {
     PIRP Irp;
     NTSTATUS Status;
@@ -436,7 +448,7 @@ EngDeviceIoControl(
     IO_STATUS_BLOCK Iosb;
     PDEVICE_OBJECT DeviceObject;
 
-    DPRINT("EngDeviceIoControl() called\n");
+    TRACE("EngDeviceIoControl() called\n");
 
     KeInitializeEvent(&Event, SynchronizationEvent, FALSE);
 
@@ -445,9 +457,12 @@ EngDeviceIoControl(
     Irp = IoBuildDeviceIoControlRequest(dwIoControlCode,
                                         DeviceObject,
                                         lpInBuffer,
-                                        nInBufferSize,
+                                        cjInBufferSize,
                                         lpOutBuffer,
-                                        nOutBufferSize, FALSE, &Event, &Iosb);
+                                        cjOutBufferSize,
+                                        FALSE,
+                                        &Event,
+                                        &Iosb);
     if (!Irp) return ERROR_NOT_ENOUGH_MEMORY;
 
     Status = IoCallDriver(DeviceObject, Irp);
@@ -458,11 +473,11 @@ EngDeviceIoControl(
         Status = Iosb.Status;
     }
 
-    DPRINT("EngDeviceIoControl(): Returning %X/%X\n", Iosb.Status,
+    TRACE("EngDeviceIoControl(): Returning %X/%X\n", Iosb.Status,
            Iosb.Information);
 
     /* Return information to the caller about the operation. */
-    *lpBytesReturned = Iosb.Information;
+    *lpBytesReturned = (DWORD)Iosb.Information;
 
     /* Convert NT status values to win32 error codes. */
     switch (Status)