#define NDEBUG
#include <debug.h>
-static PPDEVOBJ gppdevList = NULL;
PPDEVOBJ gppdevPrimary = NULL;
+
+static PPDEVOBJ gppdevList = NULL;
static HSEMAPHORE ghsemPDEV;
-BOOL
+INIT_FUNCTION
+NTSTATUS
NTAPI
InitPDEVImpl()
{
ghsemPDEV = EngCreateSemaphore();
- return TRUE;
+ if (!ghsemPDEV) return STATUS_INSUFFICIENT_RESOURCES;
+ return STATUS_SUCCESS;
}
ppdev->pfn.DisableSurface(ppdev->dhpdev);
}
+ /* Do we have a palette? */
+ if(ppdev->ppalSurf)
+ {
+ PALETTE_ShareUnlockPalette(ppdev->ppalSurf);
+ }
+
/* Disable PDEV */
ppdev->pfn.DisablePDEV(ppdev->dhpdev);
{
PFN_DrvEnablePDEV pfnEnablePDEV;
- DPRINT1("PDEVOBJ_bEnablePDEV()\n");
+ DPRINT("PDEVOBJ_bEnablePDEV()\n");
/* Get the DrvEnablePDEV function */
pfnEnablePDEV = ppdev->pldev->pfn.EnablePDEV;
if (ppdev->gdiinfo.ulLogPixelsY == 0)
ppdev->gdiinfo.ulLogPixelsY = 96;
- DPRINT1("PDEVOBJ_bEnablePDEV - dhpdev = %p\n", ppdev->dhpdev);
+ /* Setup Palette */
+ ppdev->ppalSurf = PALETTE_ShareLockPalette(ppdev->devinfo.hpalDefault);
+
+ DPRINT("PDEVOBJ_bEnablePDEV - dhpdev = %p\n", ppdev->dhpdev);
return TRUE;
}
if (ppdev->pSurface)
{
/* Increment reference count */
- GDIOBJ_IncrementShareCount(&ppdev->pSurface->BaseObject);
+ GDIOBJ_vReferenceObjectByPointer(&ppdev->pSurface->BaseObject);
}
else
{
PGRAPHICS_DEVICE pGraphicsDevice;
PDEVMODEW pdmCurrent;
INT i;
+ DWORD dwFields;
pGraphicsDevice = ppdev->pGraphicsDevice;
{
pdmCurrent = pGraphicsDevice->pDevModeList[i].pdm;
- /* Compare DEVMODE fields */
- if (pdmCurrent->dmBitsPerPel == pdm->dmBitsPerPel &&
- pdmCurrent->dmPelsWidth == pdm->dmPelsWidth &&
- pdmCurrent->dmPelsHeight == pdm->dmPelsHeight &&
- pdmCurrent->dmDisplayFrequency == pdm->dmDisplayFrequency)
- {
- /* Match! Return the DEVMODE */
- return pdmCurrent;
- }
+ /* 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(
PPDEVOBJ ppdev;
/* Try to find the GRAPHICS_DEVICE */
- pGraphicsDevice = EngpFindGraphicsDevice(pustrDeviceName, 0, 0);
- if (!pGraphicsDevice)
+ if (pustrDeviceName)
{
- DPRINT1("No GRAPHICS_DEVICE found for %ls!\n",
- pustrDeviceName ? pustrDeviceName->Buffer : 0);
- return NULL;
+ 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 */
{
/* ... use the device's default one */
pdm = pGraphicsDevice->pDevModeList[pGraphicsDevice->iDefaultMode].pdm;
- DPRINT1("Using iDefaultMode = %ld\n", pGraphicsDevice->iDefaultMode);
+ DPRINT("Using iDefaultMode = %ld\n", pGraphicsDevice->iDefaultMode);
}
/* Try to get a diplay driver */
- ppdev->pldev = EngLoadDriver(pdm->dmDeviceName, LDEV_DEVICE_DISPLAY);
+ ppdev->pldev = EngLoadImageEx(pdm->dmDeviceName, LDEV_DEVICE_DISPLAY);
if (!ppdev->pldev)
{
DPRINT1("Could not load display driver '%ls'\n",
PPDEVOBJ ppdev2)
{
PDEVOBJ pdevTmp;
+ DWORD tmpStateFlags;
/* Exchange data */
pdevTmp = *ppdev;
/* Exchange DEVMODE */
ppdev->pdmwDev = ppdev2->pdmwDev;
- ppdev2->pdmwDev = pdevTmp.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);
if (!gppdevPrimary)
{
gppdevPrimary = ppdev;
+ ppdev->pGraphicsDevice->StateFlags |= DISPLAY_DEVICE_PRIMARY_DEVICE;
}
}
}
pdc = DC_LockDc(hdc);
if (!pdc)
{
- SetLastWin32Error(ERROR_INVALID_HANDLE);
+ EngSetLastError(ERROR_INVALID_HANDLE);
return 0;
}
pdc = DC_LockDc(hDC);
if (!pdc)
{
- SetLastWin32Error(ERROR_INVALID_HANDLE);
+ EngSetLastError(ERROR_INVALID_HANDLE);
return FALSE;
}