Author: tkreuzer
Date: Sun Oct 24 23:32:18 2010
New Revision: 49266
URL:
http://svn.reactos.org/svn/reactos?rev=49266&view=rev
Log:
[WIN32K]
- Rewrite InitVideo
- Move registry functions to the appropriate file
- Silence some DPRINTs
Modified:
branches/reactos-yarotows/subsystems/win32/win32k/eng/device.c
branches/reactos-yarotows/subsystems/win32/win32k/eng/ldevobj.c
branches/reactos-yarotows/subsystems/win32/win32k/eng/pdevobj.c
branches/reactos-yarotows/subsystems/win32/win32k/include/device.h
branches/reactos-yarotows/subsystems/win32/win32k/include/misc.h
branches/reactos-yarotows/subsystems/win32/win32k/misc/registry.c
branches/reactos-yarotows/subsystems/win32/win32k/ntuser/display.c
Modified: branches/reactos-yarotows/subsystems/win32/win32k/eng/device.c
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/eng/device.c [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/eng/device.c [iso-8859-1] Sun Oct 24
23:32:18 2010
@@ -11,6 +11,9 @@
#define NDEBUG
#include <debug.h>
+
+PGRAPHICS_DEVICE gpPrimaryGraphicsDevice;
+PGRAPHICS_DEVICE gpVgaGraphicsDevice;
static PGRAPHICS_DEVICE gpGraphicsDeviceFirst = NULL;
static PGRAPHICS_DEVICE gpGraphicsDeviceLast = NULL;
Modified: branches/reactos-yarotows/subsystems/win32/win32k/eng/ldevobj.c
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/eng/ldevobj.c [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/eng/ldevobj.c [iso-8859-1] Sun Oct
24 23:32:18 2010
@@ -54,7 +54,8 @@
gpldevWin32k->cRefs = 1;
gpldevWin32k->ulDriverVersion = GDI_ENGINE_VERSION;
gpldevWin32k->pGdiDriverInfo = (PVOID)(gpldevWin32k + 1);
- gpldevWin32k->pGdiDriverInfo->DriverName.Buffer = NULL; // FIXME
+ RtlInitUnicodeString(&gpldevWin32k->pGdiDriverInfo->DriverName,
+ L"\\SystemRoot\\System32\\win32k.sys");
gpldevWin32k->pGdiDriverInfo->ImageAddress = &__ImageBase;
gpldevWin32k->pGdiDriverInfo->SectionPointer = NULL;
gpldevWin32k->pGdiDriverInfo->EntryPoint = (PVOID)DriverEntry;
@@ -107,7 +108,7 @@
ULONG cbSize, cbFull;
PDEVMODEINFO pdminfo;
- DPRINT1("LDEVOBJ_pdmiGetModes(%p, %p)\n", pldev, hDriver);
+ DPRINT("LDEVOBJ_pdmiGetModes(%p, %p)\n", pldev, hDriver);
/* Call the driver to get the required size */
cbSize = pldev->pfn.GetModes(hDriver, 0, NULL);
@@ -167,16 +168,11 @@
return FALSE;
}
- /* Initialize the UNICODE_STRING */
- pDriverInfo->DriverName.Buffer = (PWSTR)(pDriverInfo + 1);
- pDriverInfo->DriverName.Length = pstrPathName->Length;
- pDriverInfo->DriverName.MaximumLength = pstrPathName->Length;
-
- /* Copy the driver name */
-// RtlCopyUnicodeString(pDriverInfo->DriverName, pstrPathName);
- RtlCopyMemory(pDriverInfo->DriverName.Buffer,
- pstrPathName->Buffer,
- pstrPathName->Length);
+ /* 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,
Modified: branches/reactos-yarotows/subsystems/win32/win32k/eng/pdevobj.c
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/eng/pdevobj.c [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/eng/pdevobj.c [iso-8859-1] Sun Oct
24 23:32:18 2010
@@ -13,8 +13,9 @@
#define NDEBUG
#include <debug.h>
+PPDEVOBJ gppdevPrimary = NULL;
+
static PPDEVOBJ gppdevList = NULL;
-PPDEVOBJ gppdevPrimary = NULL;
static HSEMAPHORE ghsemPDEV;
BOOL
@@ -225,7 +226,6 @@
return NULL;
}
-
static
PPDEVOBJ
EngpCreatePDEV(
@@ -236,12 +236,19 @@
PPDEVOBJ ppdev;
/* Try to find the GRAPHICS_DEVICE */
- pGraphicsDevice = EngpFindGraphicsDevice(pustrDeviceName, 0, 0);
- if (!pGraphicsDevice)
- {
- DPRINT1("No GRAPHICS_DEVICE found for %ls!\n",
- pustrDeviceName ? pustrDeviceName->Buffer : 0);
- return NULL;
+ 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 */
Modified: branches/reactos-yarotows/subsystems/win32/win32k/include/device.h
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/include/device.h [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/include/device.h [iso-8859-1] Sun
Oct 24 23:32:18 2010
@@ -41,22 +41,6 @@
//#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);
-
-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);
-
BOOL
NTAPI
PDEVOBJ_bSwitchMode(
@@ -68,3 +52,6 @@
PDEVOBJ_pdmMatchDevMode(
PPDEVOBJ ppdev,
PDEVMODEW pdm);
+
+extern PGRAPHICS_DEVICE gpPrimaryGraphicsDevice;
+extern PGRAPHICS_DEVICE gpVgaGraphicsDevice;
Modified: branches/reactos-yarotows/subsystems/win32/win32k/include/misc.h
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/include/misc.h [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/include/misc.h [iso-8859-1] Sun Oct
24 23:32:18 2010
@@ -29,6 +29,33 @@
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(
Modified: branches/reactos-yarotows/subsystems/win32/win32k/misc/registry.c
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/misc/registry.c [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/misc/registry.c [iso-8859-1] Sun Oct
24 23:32:18 2010
@@ -55,7 +55,7 @@
UNICODE_STRING ustrValueName;
BYTE ajBuffer[100];
PKEY_VALUE_PARTIAL_INFORMATION pInfo;
- ULONG cbInfoSize;
+ ULONG cbInfoSize, cbDataSize;
/* Check if the local buffer is sufficient */
cbInfoSize = sizeof(KEY_VALUE_PARTIAL_INFORMATION) + *pcbValue;
@@ -81,20 +81,23 @@
(PVOID)pInfo,
cbInfoSize,
&cbInfoSize);
+
+ cbDataSize = cbInfoSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
+
if (NT_SUCCESS(Status))
{
/* Did we get the right type */
if (pInfo->Type == ulType)
{
/* Copy the contents to the caller */
- RtlCopyMemory(pvData, pInfo->Data, *pcbValue);
+ RtlCopyMemory(pvData, pInfo->Data, min(*pcbValue, cbDataSize));
}
else
Status = STATUS_OBJECT_TYPE_MISMATCH;
}
/* Return the data size to the caller */
- *pcbValue = cbInfoSize - FIELD_OFFSET(KEY_VALUE_PARTIAL_INFORMATION, Data);
+ *pcbValue = cbDataSize;
/* Cleanup */
if (pInfo != (PVOID)ajBuffer)
@@ -104,6 +107,37 @@
}
+VOID
+NTAPI
+RegWriteSZ(HKEY hkey, PWSTR pwszValue, PWSTR pwszData)
+{
+ UNICODE_STRING ustrValue;
+ UNICODE_STRING ustrData;
+
+ RtlInitUnicodeString(&ustrValue, pwszValue);
+ RtlInitUnicodeString(&ustrData, pwszData);
+ ZwSetValueKey(hkey, &ustrValue, 0, REG_SZ, &ustrData, ustrData.Length +
sizeof(WCHAR));
+}
+
+VOID
+NTAPI
+RegWriteDWORD(HKEY hkey, PWSTR pwszValue, DWORD dwData)
+{
+ UNICODE_STRING ustrValue;
+
+ RtlInitUnicodeString(&ustrValue, pwszValue);
+ ZwSetValueKey(hkey, &ustrValue, 0, REG_DWORD, &dwData, sizeof(DWORD));
+}
+
+BOOL
+NTAPI
+RegReadDWORD(HKEY hkey, PWSTR pwszValue, PDWORD pdwData)
+{
+ NTSTATUS Status;
+ ULONG cbSize = sizeof(DWORD);
+ Status = RegQueryValue(hkey, pwszValue, REG_DWORD, pdwData, &cbSize);
+ return NT_SUCCESS(Status);
+}
BOOL
NTAPI
Modified: branches/reactos-yarotows/subsystems/win32/win32k/ntuser/display.c
URL:
http://svn.reactos.org/svn/reactos/branches/reactos-yarotows/subsystems/win…
==============================================================================
--- branches/reactos-yarotows/subsystems/win32/win32k/ntuser/display.c [iso-8859-1]
(original)
+++ branches/reactos-yarotows/subsystems/win32/win32k/ntuser/display.c [iso-8859-1] Sun
Oct 24 23:32:18 2010
@@ -13,48 +13,12 @@
#define NDEBUG
#include <debug.h>
-PDEVOBJ *gpdevPrimary;
-
-const PWCHAR KEY_ROOT = L"";
-const PWCHAR KEY_VIDEO = L"\\Registry\\Machine\\HARDWARE\\DEVICEMAP\\VIDEO";
-
-NTSTATUS
-NTAPI
-UserEnumDisplayDevices(
- PUNICODE_STRING pustrDevice,
- DWORD iDevNum,
- PDISPLAY_DEVICEW pdispdev,
- DWORD dwFlags);
-
-VOID
-RegWriteSZ(HKEY hkey, PWSTR pwszValue, PWSTR pwszData)
-{
- UNICODE_STRING ustrValue;
- UNICODE_STRING ustrData;
-
- RtlInitUnicodeString(&ustrValue, pwszValue);
- RtlInitUnicodeString(&ustrData, pwszData);
- ZwSetValueKey(hkey, &ustrValue, 0, REG_SZ, &ustrData, ustrData.Length +
sizeof(WCHAR));
-}
-
-VOID
-RegWriteDWORD(HKEY hkey, PWSTR pwszValue, DWORD dwData)
-{
- UNICODE_STRING ustrValue;
-
- RtlInitUnicodeString(&ustrValue, pwszValue);
- ZwSetValueKey(hkey, &ustrValue, 0, REG_DWORD, &dwData, sizeof(DWORD));
-}
-
-
-BOOL
-RegReadDWORD(HKEY hkey, PWSTR pwszValue, PDWORD pdwData)
-{
- NTSTATUS Status;
- ULONG cbSize = sizeof(DWORD);
- Status = RegQueryValue(hkey, pwszValue, REG_DWORD, pdwData, &cbSize);
- return NT_SUCCESS(Status);
-}
+BOOL InitSysParams();
+
+BOOL gbBaseVideo = 0;
+
+static const PWCHAR KEY_ROOT = L"";
+static const PWCHAR KEY_VIDEO =
L"\\Registry\\Machine\\HARDWARE\\DEVICEMAP\\VIDEO";
VOID
RegWriteDisplaySettings(HKEY hkey, PDEVMODEW pdm)
@@ -103,96 +67,12 @@
READ(dmPosition.y, "Attach.RelativeY", DM_POSITION);
}
-
-enum
-{
- VF_USEVGA = 0x1,
-};
-
-BOOL
+PGRAPHICS_DEVICE
+NTAPI
InitDisplayDriver(
- PUNICODE_STRING pustrRegPath,
- FLONG flags)
-{
-// PWSTR pwszDriverName;
- RTL_QUERY_REGISTRY_TABLE QueryTable[2];
- NTSTATUS Status;
-
- /* Setup QueryTable for direct registry query */
- RtlZeroMemory(QueryTable, sizeof(QueryTable));
- QueryTable[0].Flags = RTL_QUERY_REGISTRY_REQUIRED|RTL_QUERY_REGISTRY_DIRECT;
-
-
- /* Check if vga mode is requested */
- if (flags & VF_USEVGA)
- {
- DWORD dwVgaCompatible;
-
- /* */
- QueryTable[0].Name = L"VgaCompatible";
- QueryTable[0].EntryContext = &dwVgaCompatible;
-
- /* Check if the driver is vga */
- Status = RtlQueryRegistryValues(RTL_REGISTRY_ABSOLUTE,
- pustrRegPath->Buffer,
- QueryTable,
- NULL,
- NULL);
-
- if (!dwVgaCompatible)
- {
- /* This driver is not a vga driver */
- return FALSE;
- }
- }
-
-#if 0
-
- /* Query the adapter's registry path */
- swprintf(awcBuffer, L"\\Device\\Video%lu", iDevNum);
- QueryTable[0].Name = pGraphicsDevice->szNtDeviceName;
-
- /* Set string for the registry key */
- ustrRegistryPath.Buffer = pdispdev->DeviceKey;
- ustrRegistryPath.Length = 128;
- ustrRegistryPath.MaximumLength = 128;
- QueryTable[0].EntryContext = &ustrRegistryPath;
-
- /* Query the registry */
- Status = RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP,
- L"VIDEO",
- QueryTable,
- NULL,
- NULL);
-
- RegQueryValue(KEY_VIDEO, awcBuffer, REG_SZ, pdispdev->DeviceKey, 256);
-
- {
- HANDLE hmod;
-
- hmod = EngLoadImage(pwszDriverName);
-
- /* Jump to next name */
- pwszDriverName += wcslen(pwszDriverName) + 1;
- }
- while (pwszDriverName < 0);
-#endif
-
- return 0;
-}
-
-
-NTSTATUS
-NTAPI
-DisplayDriverQueryRoutine(
- IN PWSTR ValueName,
- IN ULONG ValueType,
- IN PVOID ValueData,
- IN ULONG ValueLength,
- IN PVOID Context,
- IN PVOID EntryContext)
-{
- PWSTR pwszRegKey = ValueData;
+ IN PWSTR pwszDeviceName,
+ IN PWSTR pwszRegKey)
+{
PGRAPHICS_DEVICE pGraphicsDevice;
UNICODE_STRING ustrDeviceName, ustrDisplayDrivers, ustrDescription;
NTSTATUS Status;
@@ -201,31 +81,16 @@
HKEY hkey;
DEVMODEW dmDefault;
- UNREFERENCED_PARAMETER(ValueLength);
- UNREFERENCED_PARAMETER(Context);
- UNREFERENCED_PARAMETER(EntryContext);
-
- DPRINT1("DisplayDriverQueryRoutine(%S, %S);\n",
- ValueName, pwszRegKey);
-
- /* Check if we have a correct entry */
- if (ValueType != REG_SZ || ValueName[0] != '\\')
- {
- /* Something else, just skip it */
- return STATUS_SUCCESS;
- }
+ DPRINT1("InitDisplayDriver(%S, %S);\n",
+ pwszDeviceName, pwszRegKey);
/* Open the driver's registry key */
Status = RegOpenKey(pwszRegKey, &hkey);
if (!NT_SUCCESS(Status))
{
- DPRINT1("Failed to open registry key\n");
- return STATUS_SUCCESS;
- }
-
-// HACK: only use 1st adapter
-//if (ValueName[13] != '0')
-// return STATUS_SUCCESS;
+ DPRINT1("Failed to open registry key: %ls\n", pwszRegKey);
+ return NULL;
+ }
/* Query the diplay drivers */
cbSize = sizeof(awcBuffer) - 10;
@@ -238,7 +103,7 @@
{
DPRINT1("Didn't find 'InstalledDisplayDrivers', status =
0x%lx\n", Status);
ZwClose(hkey);
- return STATUS_SUCCESS;
+ return NULL;
}
/* Initialize the UNICODE_STRING */
@@ -273,43 +138,118 @@
ZwClose(hkey);
/* Register the device with GDI */
- RtlInitUnicodeString(&ustrDeviceName, ValueName);
+ RtlInitUnicodeString(&ustrDeviceName, pwszDeviceName);
pGraphicsDevice = EngpRegisterGraphicsDevice(&ustrDeviceName,
&ustrDisplayDrivers,
&ustrDescription,
&dmDefault);
- // FIXME: what to do with pGraphicsDevice?
-
- return STATUS_SUCCESS;
-}
-
-BOOL InitSysParams();
+ return pGraphicsDevice;
+}
BOOL
-InitVideo(FLONG flags)
-{
- RTL_QUERY_REGISTRY_TABLE QueryTable[2];
+InitVideo(
+ PUNICODE_STRING pustrRegPath,
+ FLONG flags)
+{
+ ULONG iDevNum, iVGACompatible = -1, ulMaxObjectNumber = 0;
+ WCHAR awcDeviceName[20];
+ WCHAR awcBuffer[256];
NTSTATUS Status;
+ PGRAPHICS_DEVICE pGraphicsDevice;
+ ULONG cbValue;
+ HKEY hkey;
DPRINT1("----------------------------- InitVideo()
-------------------------------\n");
- /* Setup QueryTable for registry query */
- RtlZeroMemory(QueryTable, sizeof(QueryTable));
- QueryTable[0].QueryRoutine = DisplayDriverQueryRoutine;
-
- /* Query the registry */
- Status = RtlQueryRegistryValues(RTL_REGISTRY_DEVICEMAP,
- L"VIDEO",
- QueryTable,
- NULL,
- NULL);
+ Status =
RegOpenKey(L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Control",
&hkey);
+ if (NT_SUCCESS(Status))
+ {
+ cbValue = 256;
+ Status = RegQueryValue(hkey, L"SystemStartOptions", REG_SZ, awcBuffer,
&cbValue);
+ if (NT_SUCCESS(Status))
+ {
+ /* Check if VGA mode is requested. */
+ if (wcsstr(awcBuffer, L"/BASEVIDEO") != 0)
+ {
+ DPRINT1("VGA mode requested.\n");
+ gbBaseVideo = TRUE;
+ }
+ }
+
+ ZwClose(hkey);
+ }
+
+ /* Open the key for the adapters */
+ Status = RegOpenKey(KEY_VIDEO, &hkey);
+ if (!NT_SUCCESS(Status))
+ {
+ DPRINT1("Could not open device registry key!\n");
+ ASSERT(FALSE);
+ }
+
+ /* Read the name of the VGA adapter */
+ cbValue = 20;
+ Status = RegQueryValue(hkey, L"VgaCompatible", REG_SZ, awcDeviceName,
&cbValue);
+ if (NT_SUCCESS(Status))
+ {
+ iVGACompatible = _wtoi(&awcDeviceName[13]);
+ DPRINT1("VGA adapter = %ld\n", iVGACompatible);
+ }
+
+ /* Get the maximum mumber of adapters */
+ if (!RegReadDWORD(hkey, L"MaxObjectNumber", &ulMaxObjectNumber))
+ {
+ DPRINT1("Could not read MaxObjectNumber, defaulting to 0.\n");
+ }
+
+ DPRINT("Found %ld devices\n", ulMaxObjectNumber);
+
+ /* Loop through all adapters */
+ cbValue = 256;
+ for (iDevNum = 0; iDevNum <= ulMaxObjectNumber; iDevNum++)
+ {
+ /* Create the adapter's key name */
+ swprintf(awcDeviceName, L"\\Device\\Video%lu", iDevNum);
+
+ /* Read the reg key name */
+ Status = RegQueryValue(hkey, awcDeviceName, REG_SZ, awcBuffer, &cbValue);
+
+ pGraphicsDevice = InitDisplayDriver(awcDeviceName, awcBuffer);
+
+ /* Check if this is the VGA adapter */
+ if (iDevNum == iVGACompatible)
+ {
+ /* Set the VGA device as primary */
+ gpVgaGraphicsDevice = pGraphicsDevice;
+ DPRINT1("gpVgaGraphicsDevice = %p\n", gpVgaGraphicsDevice);
+ }
+
+ /* Set the first one as primary device */
+ if (!gpPrimaryGraphicsDevice)
+ gpPrimaryGraphicsDevice = pGraphicsDevice;
+ }
+
+ ZwClose(hkey);
+
+ if (gbBaseVideo)
+ {
+ if (gpVgaGraphicsDevice)
+ {
+ /* Set the VgaAdapter as primary */
+ gpPrimaryGraphicsDevice = gpVgaGraphicsDevice;
+ // FIXME: DEVMODE
+ }
+ else
+ {
+ DPRINT1("Could not find VGA compatible driver. Trying normal.\n");
+ }
+ }
InitSysParams();
- return 0;
-}
-
+ return 1;
+}
NTSTATUS
NTAPI