Ejemplo n.º 1
0
NTSTATUS
NTAPI
InitVideo()
{
    ULONG iDevNum, iVGACompatible = -1, ulMaxObjectNumber = 0;
    WCHAR awcDeviceName[20];
    WCHAR awcBuffer[256];
    NTSTATUS Status;
    PGRAPHICS_DEVICE pGraphicsDevice;
    ULONG cbValue;
    HKEY hkey;

    TRACE("----------------------------- InitVideo() -------------------------------\n");

    /* Open the key for the boot command line */
    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)
            {
                ERR("VGA mode requested.\n");
                gbBaseVideo = TRUE;
            }
        }

        ZwClose(hkey);
    }

    /* Open the key for the adapters */
    Status = RegOpenKey(KEY_VIDEO, &hkey);
    if (!NT_SUCCESS(Status))
    {
        ERR("Could not open HARDWARE\\DEVICEMAP\\VIDEO registry key:0x%lx\n", Status);
        return Status;
    }

    /* 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]);
        ERR("VGA adapter = %ld\n", iVGACompatible);
    }

    /* Get the maximum mumber of adapters */
    if (!RegReadDWORD(hkey, L"MaxObjectNumber", &ulMaxObjectNumber))
    {
        ERR("Could not read MaxObjectNumber, defaulting to 0.\n");
    }

    TRACE("Found %ld devices\n", ulMaxObjectNumber + 1);

    /* Loop through all adapters */
    for (iDevNum = 0; iDevNum <= ulMaxObjectNumber; iDevNum++)
    {
        /* Create the adapter's key name */
        swprintf(awcDeviceName, L"\\Device\\Video%lu", iDevNum);

        /* Read the reg key name */
        cbValue = sizeof(awcBuffer);
        Status = RegQueryValue(hkey, awcDeviceName, REG_SZ, awcBuffer, &cbValue);
        if (!NT_SUCCESS(Status))
        {
            ERR("failed to query the registry path:0x%lx\n", Status);
            continue;
        }

        /* Initialize the driver for this device */
        pGraphicsDevice = InitDisplayDriver(awcDeviceName, awcBuffer);
        if (!pGraphicsDevice) continue;

        /* Check if this is a VGA compatible adapter */
        if (pGraphicsDevice->StateFlags & DISPLAY_DEVICE_VGA_COMPATIBLE)
        {
            /* Save this as the VGA adapter */
            if (!gpVgaGraphicsDevice)
                gpVgaGraphicsDevice = pGraphicsDevice;
            TRACE("gpVgaGraphicsDevice = %p\n", gpVgaGraphicsDevice);
        }
        else
        {
            /* Set the first one as primary device */
            if (!gpPrimaryGraphicsDevice)
                gpPrimaryGraphicsDevice = pGraphicsDevice;
            TRACE("gpPrimaryGraphicsDevice = %p\n", gpPrimaryGraphicsDevice);
        }
    }

    /* Close the device map registry key */
    ZwClose(hkey);

    /* Was VGA mode requested? */
    if (gbBaseVideo)
    {
        /* Check if we found a VGA compatible device */
        if (gpVgaGraphicsDevice)
        {
            /* Set the VgaAdapter as primary */
            gpPrimaryGraphicsDevice = gpVgaGraphicsDevice;
            // FIXME: DEVMODE
        }
        else
        {
            ERR("Could not find VGA compatible driver. Trying normal.\n");
        }
    }

    /* Check if we had any success */
    if (!gpPrimaryGraphicsDevice)
    {
        /* Check if there is a VGA device we skipped */
        if (gpVgaGraphicsDevice)
        {
            /* There is, use the VGA device */
            gpPrimaryGraphicsDevice = gpVgaGraphicsDevice;
        }
        else
        {
            ERR("No usable display driver was found.\n");
            return STATUS_UNSUCCESSFUL;
        }
    }

    InitSysParams();

    return 1;
}
Ejemplo n.º 2
0
BOOL
FASTCALL
InitMetrics(VOID)
{
    INT *piSysMet = gpsi->aiSysMet;
    ULONG Width, Height;

    /* note: used for the SM_CLEANBOOT metric */
    DWORD dwValue = 0;
    HKEY hKey = 0;

    /* Clean boot */
    piSysMet[SM_CLEANBOOT] = 0; // fallback value of 0 (normal mode)
    if(NT_SUCCESS(RegOpenKey(L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Control\\SafeBoot\\Option", &hKey)))
    {
        if(RegReadDWORD(hKey, L"OptionValue", &dwValue)) piSysMet[SM_CLEANBOOT] = (INT)dwValue;
        ZwClose(hKey);
    }

    /* FIXME: HACK, due to missing PDEV on first init */
    if (!pPrimarySurface)
    {
        Width = 640;
        Height = 480;
    }
    else
    {
        Width = pPrimarySurface->gdiinfo.ulHorzRes;
        Height = pPrimarySurface->gdiinfo.ulVertRes;
    }

    /* Screen sizes */
    piSysMet[SM_CXSCREEN] = Width;
    piSysMet[SM_CYSCREEN] = Height;
    piSysMet[SM_XVIRTUALSCREEN] = 0;
    piSysMet[SM_YVIRTUALSCREEN] = 0;
    piSysMet[SM_CXVIRTUALSCREEN] = Width;
    piSysMet[SM_CYVIRTUALSCREEN] = Height;

    /* NC area sizes */
    piSysMet[SM_CYCAPTION] = gspv.ncm.iCaptionHeight + 1; // 19
    piSysMet[SM_CYSMCAPTION] = gspv.ncm.iSmCaptionHeight + 1; // 15;
    piSysMet[SM_CXSIZE] = gspv.ncm.iCaptionHeight; // 18;
    piSysMet[SM_CYSIZE] = gspv.ncm.iCaptionHeight; // 18;
    piSysMet[SM_CXSMSIZE] = gspv.ncm.iSmCaptionWidth; // 12; xp: piSysMet(SM_CYSMCAPTION) - 1
    piSysMet[SM_CYSMSIZE] = gspv.ncm.iSmCaptionHeight; // 14;
    piSysMet[SM_CXBORDER] = 1; // seems to be hardcoded
    piSysMet[SM_CYBORDER] = 1; // seems to be hardcoded
    piSysMet[SM_CXFOCUSBORDER] = 1;
    piSysMet[SM_CYFOCUSBORDER] = 1;
    piSysMet[SM_CXDLGFRAME] = 3;
    piSysMet[SM_CYDLGFRAME] = 3;
    piSysMet[SM_CXEDGE] = 2;
    piSysMet[SM_CYEDGE] = 2;
    piSysMet[SM_CXFRAME] = piSysMet[SM_CXDLGFRAME] + gspv.ncm.iBorderWidth; // 4
    piSysMet[SM_CYFRAME] = piSysMet[SM_CYDLGFRAME] + gspv.ncm.iBorderWidth; // 4
#if (_WIN32_WINNT >= 0x0600)
    piSysMet[SM_CXPADDEDBORDER] = 0;
#endif

    /* Window sizes */
    TRACE("ncm.iCaptionWidth=%d,GetSystemMetrics(SM_CYSIZE)=%d,GetSystemMetrics(SM_CXFRAME)=%d,avcwCaption=%d \n",
           gspv.ncm.iCaptionWidth, piSysMet[SM_CYSIZE],piSysMet[SM_CXFRAME], gspv.tmCaptionFont.tmAveCharWidth);

    piSysMet[SM_CXMIN] = 3 * max(gspv.ncm.iCaptionWidth, 8) // 112
                         + piSysMet[SM_CYSIZE] + 4
                         + 4 * gspv.tmCaptionFont.tmAveCharWidth
                         + 2 * piSysMet[SM_CXFRAME];
    piSysMet[SM_CYMIN] = piSysMet[SM_CYCAPTION] + 2 * piSysMet[SM_CYFRAME];// 27
    piSysMet[SM_CXMAXIMIZED] = piSysMet[SM_CXSCREEN] + 2 * piSysMet[SM_CXFRAME];
    piSysMet[SM_CYMAXIMIZED] = piSysMet[SM_CYSCREEN] - 20;
    piSysMet[SM_CXFULLSCREEN] = piSysMet[SM_CXSCREEN];
    piSysMet[SM_CYFULLSCREEN] = piSysMet[SM_CYMAXIMIZED] - piSysMet[SM_CYMIN];
    piSysMet[SM_CYKANJIWINDOW] = 0;
    piSysMet[SM_CXMINIMIZED] = gspv.mm.iWidth + 6;
    piSysMet[SM_CYMINIMIZED] = piSysMet[SM_CYCAPTION] + 5;
    piSysMet[SM_CXMINSPACING] = piSysMet[SM_CXMINIMIZED] + gspv.mm.iHorzGap;
    piSysMet[SM_CYMINSPACING] = piSysMet[SM_CYMINIMIZED] + gspv.mm.iVertGap;
    piSysMet[SM_CXMAXTRACK] = piSysMet[SM_CXVIRTUALSCREEN] + 4
                              + 2 * piSysMet[SM_CXFRAME];
    piSysMet[SM_CYMAXTRACK] = piSysMet[SM_CYVIRTUALSCREEN] + 4
                              + 2 * piSysMet[SM_CYFRAME];

    /* Icon */
    piSysMet[SM_CXVSCROLL] = gspv.ncm.iScrollWidth; //16;
    piSysMet[SM_CYVTHUMB] = gspv.ncm.iScrollHeight; //16;
    piSysMet[SM_CYHSCROLL] = gspv.ncm.iScrollWidth; //16;
    piSysMet[SM_CXHTHUMB] = gspv.ncm.iScrollHeight; //16;
    piSysMet[SM_CYVSCROLL] = gspv.ncm.iScrollHeight; // 16
    piSysMet[SM_CXHSCROLL] = gspv.ncm.iScrollHeight; // 16;
    piSysMet[SM_CXICON] = 32;
    piSysMet[SM_CYICON] = 32;
    piSysMet[SM_CXSMICON] = 16;
    piSysMet[SM_CYSMICON] = 16;
    piSysMet[SM_CXICONSPACING] = gspv.im.iHorzSpacing;// 64;
    piSysMet[SM_CYICONSPACING] = gspv.im.iVertSpacing; // 64;
    piSysMet[SM_CXCURSOR] = 32;
    piSysMet[SM_CYCURSOR] = 32;
    piSysMet[SM_CXMINTRACK] = piSysMet[SM_CXMIN]; // 117
    piSysMet[SM_CYMINTRACK] = piSysMet[SM_CYMIN]; // 27
    piSysMet[SM_CXDRAG] = 4;
    piSysMet[SM_CYDRAG] = 4;
    piSysMet[SM_ARRANGE] = gspv.mm.iArrange; // 8;

    /* Menu */
    piSysMet[SM_CYMENU] = gspv.ncm.iMenuHeight + 1;//19;
    piSysMet[SM_MENUDROPALIGNMENT] = gspv.bMenuDropAlign;
    piSysMet[SM_CXMENUCHECK] = ((1 + gspv.tmMenuFont.tmHeight +
                                 gspv.tmMenuFont.tmExternalLeading) & ~1) - 1; // 13;
    piSysMet[SM_CYMENUCHECK] = piSysMet[SM_CXMENUCHECK];
    piSysMet[SM_CXMENUSIZE] = gspv.ncm.iMenuWidth; //18;
    piSysMet[SM_CYMENUSIZE] = gspv.ncm.iMenuHeight; //18;

    /* Mouse */
    piSysMet[SM_MOUSEPRESENT] = 1;
    piSysMet[SM_MOUSEWHEELPRESENT] = 1;
    piSysMet[SM_CMOUSEBUTTONS] = 2;
    piSysMet[SM_SWAPBUTTON] = gspv.bMouseBtnSwap ? 1 : 0;
    piSysMet[SM_CXDOUBLECLK] = gspv.iDblClickWidth;
    piSysMet[SM_CYDOUBLECLK] = gspv.iDblClickHeight;
#if (_WIN32_WINNT >= 0x0600)
    piSysMet[SM_MOUSEHORIZONTALWHEELPRESENT] = 0;
#endif

    /* Version info */
    piSysMet[SM_TABLETPC] = 0;
    piSysMet[SM_MEDIACENTER] = 0;
    piSysMet[SM_STARTER] = 0;
    piSysMet[SM_SERVERR2] = 0;
    piSysMet[SM_PENWINDOWS] = 0;

    /* Other */
    piSysMet[SM_DEBUG] = 0;
    piSysMet[SM_NETWORK] = 3;
    piSysMet[SM_SLOWMACHINE] = 0;
    piSysMet[SM_SECURE] = 0;
    piSysMet[SM_DBCSENABLED] = 0;
    piSysMet[SM_SHOWSOUNDS] = gspv.bShowSounds;
    piSysMet[SM_MIDEASTENABLED] = 0;
    piSysMet[SM_CMONITORS] = 1;
    piSysMet[SM_SAMEDISPLAYFORMAT] = 1;
    piSysMet[SM_IMMENABLED] = 0;

    /* Reserved */
    piSysMet[SM_RESERVED1] = 0;
    piSysMet[SM_RESERVED2] = 0;
    piSysMet[SM_RESERVED3] = 0;
    piSysMet[SM_RESERVED4] = 0;
    piSysMet[64] = 0;
    piSysMet[65] = 0;
    piSysMet[66] = 0;
#if (_WIN32_WINNT >= 0x0600)
    piSysMet[90] = 0;
#endif

    gpsi->dwSRVIFlags |= SRVINFO_METRICS;
    Setup = TRUE;

    return TRUE;
}