From af353b657248844ca09240bde98c945f53dc6fc4 Mon Sep 17 00:00:00 2001 From: David Welch Date: Wed, 18 Sep 2002 23:56:48 +0000 Subject: [PATCH] Create a PDEV for the display driver only once. svn path=/trunk/; revision=3520 --- .../drivers/dd/vga/display/objects/pointer.c | 13 +- reactos/include/win32k/dc.h | 11 ++ reactos/subsys/win32k/eng/surface.c | 33 ++-- reactos/subsys/win32k/objects/dc.c | 165 ++++++++++-------- 4 files changed, 132 insertions(+), 90 deletions(-) diff --git a/reactos/drivers/dd/vga/display/objects/pointer.c b/reactos/drivers/dd/vga/display/objects/pointer.c index 93e512bfcdf..3d6897aeed9 100644 --- a/reactos/drivers/dd/vga/display/objects/pointer.c +++ b/reactos/drivers/dd/vga/display/objects/pointer.c @@ -1,7 +1,7 @@ #include "../vgaddi.h" ULONG oldx, oldy; -PUCHAR behindCursor; +static PUCHAR ImageBehindCursor; void vgaHideCursor(PPDEV ppdev); void vgaShowCursor(PPDEV ppdev); @@ -26,7 +26,8 @@ BOOL InitPointer(PPDEV ppdev) ppdev->pPointerAttributes->Row = 0; // Allocate memory for the pixels behind the cursor - behindCursor = EngAllocMem(0, ppdev->pPointerAttributes->WidthInBytes * ppdev->pPointerAttributes->Height, ALLOC_TAG); + ImageBehindCursor = + EngAllocMem(0, ppdev->pPointerAttributes->WidthInBytes * ppdev->pPointerAttributes->Height, ALLOC_TAG); return TRUE; } @@ -81,8 +82,8 @@ DrvSetPointerShape(PSURFOBJ pso, if(psoColor != NULL) RtlCopyMemory(ppdev->pPointerAttributes->Pixels + 256, psoColor->pvBits, psoColor->cjBits); ppdev->pPointerAttributes->WidthInBytes = psoMask->lDelta; - EngFreeMem(behindCursor); - behindCursor = EngAllocMem(0, ppdev->pPointerAttributes->WidthInBytes * ppdev->pPointerAttributes->Height, ALLOC_TAG); + EngFreeMem(ImageBehindCursor); + ImageBehindCursor = EngAllocMem(0, ppdev->pPointerAttributes->WidthInBytes * ppdev->pPointerAttributes->Height, ALLOC_TAG); // Set the new cursor position ppdev->xyCursor.x = x; @@ -111,7 +112,7 @@ void vgaHideCursor(PPDEV ppdev) DFB_BltToVGA(oldx, oldy, ppdev->pPointerAttributes->Width, ppdev->pPointerAttributes->Height, - behindCursor, + ImageBehindCursor, ppdev->pPointerAttributes->WidthInBytes); ppdev->pPointerAttributes->Enable = 0; @@ -130,7 +131,7 @@ void vgaShowCursor(PPDEV ppdev) // Used to repaint background DFB_BltFromVGA(ppdev->xyCursor.x, ppdev->xyCursor.y, ppdev->pPointerAttributes->Width, ppdev->pPointerAttributes->Height, - behindCursor, ppdev->pPointerAttributes->WidthInBytes); + ImageBehindCursor, ppdev->pPointerAttributes->WidthInBytes); // Display the cursor DFB_BltToVGA_Transparent(ppdev->xyCursor.x, ppdev->xyCursor.y, diff --git a/reactos/include/win32k/dc.h b/reactos/include/win32k/dc.h index 28d8dcc7159..0a4e34c6924 100644 --- a/reactos/include/win32k/dc.h +++ b/reactos/include/win32k/dc.h @@ -7,6 +7,17 @@ #include #include +typedef struct +{ + HANDLE Handle; + DHPDEV PDev; + DEVMODEW DMW; + HSURF FillPatterns[HS_DDI_MAX]; + GDIINFO GDIInfo; + DEVINFO DevInfo; + DRIVER_FUNCTIONS DriverFunctions; +} GDIDEVICE; + /* (RJJ) Taken from WINE */ typedef struct _DEVICECAPS { diff --git a/reactos/subsys/win32k/eng/surface.c b/reactos/subsys/win32k/eng/surface.c index 676ae553de5..3ec09671d6f 100644 --- a/reactos/subsys/win32k/eng/surface.c +++ b/reactos/subsys/win32k/eng/surface.c @@ -190,8 +190,9 @@ EngAssociateSurface(IN HSURF Surface, { SURFOBJ *SurfObj; SURFGDI *SurfGDI; + GDIDEVICE* Device; - PDC Dc = (PDC)Dev; + Device = (GDIDEVICE*)Dev; SurfGDI = (PVOID)AccessInternalObject((ULONG)Surface); SurfObj = (PVOID)AccessUserObject((ULONG)Surface); @@ -200,23 +201,23 @@ EngAssociateSurface(IN HSURF Surface, SurfObj->hdev = Dev; // Hook up specified functions - if(Hooks & HOOK_BITBLT) SurfGDI->BitBlt = Dc->DriverFunctions.BitBlt; - if(Hooks & HOOK_TRANSPARENTBLT) SurfGDI->TransparentBlt = Dc->DriverFunctions.TransparentBlt; - if(Hooks & HOOK_STRETCHBLT) SurfGDI->StretchBlt = (PFN_StretchBlt)Dc->DriverFunctions.StretchBlt; - if(Hooks & HOOK_TEXTOUT) SurfGDI->TextOut = Dc->DriverFunctions.TextOut; - if(Hooks & HOOK_PAINT) SurfGDI->Paint = Dc->DriverFunctions.Paint; - if(Hooks & HOOK_STROKEPATH) SurfGDI->StrokePath = Dc->DriverFunctions.StrokePath; - if(Hooks & HOOK_FILLPATH) SurfGDI->FillPath = Dc->DriverFunctions.FillPath; - if(Hooks & HOOK_STROKEANDFILLPATH) SurfGDI->StrokeAndFillPath = Dc->DriverFunctions.StrokeAndFillPath; - if(Hooks & HOOK_LINETO) SurfGDI->LineTo = Dc->DriverFunctions.LineTo; - if(Hooks & HOOK_COPYBITS) SurfGDI->CopyBits = Dc->DriverFunctions.CopyBits; - if(Hooks & HOOK_SYNCHRONIZE) SurfGDI->Synchronize = Dc->DriverFunctions.Synchronize; + if(Hooks & HOOK_BITBLT) SurfGDI->BitBlt = Device->DriverFunctions.BitBlt; + if(Hooks & HOOK_TRANSPARENTBLT) SurfGDI->TransparentBlt = Device->DriverFunctions.TransparentBlt; + if(Hooks & HOOK_STRETCHBLT) SurfGDI->StretchBlt = (PFN_StretchBlt)Device->DriverFunctions.StretchBlt; + if(Hooks & HOOK_TEXTOUT) SurfGDI->TextOut = Device->DriverFunctions.TextOut; + if(Hooks & HOOK_PAINT) SurfGDI->Paint = Device->DriverFunctions.Paint; + if(Hooks & HOOK_STROKEPATH) SurfGDI->StrokePath = Device->DriverFunctions.StrokePath; + if(Hooks & HOOK_FILLPATH) SurfGDI->FillPath = Device->DriverFunctions.FillPath; + if(Hooks & HOOK_STROKEANDFILLPATH) SurfGDI->StrokeAndFillPath = Device->DriverFunctions.StrokeAndFillPath; + if(Hooks & HOOK_LINETO) SurfGDI->LineTo = Device->DriverFunctions.LineTo; + if(Hooks & HOOK_COPYBITS) SurfGDI->CopyBits = Device->DriverFunctions.CopyBits; + if(Hooks & HOOK_SYNCHRONIZE) SurfGDI->Synchronize = Device->DriverFunctions.Synchronize; if(Hooks & HOOK_SYNCHRONIZEACCESS) SurfGDI->SynchronizeAccess = TRUE; - SurfGDI->CreateDeviceBitmap = Dc->DriverFunctions.CreateDeviceBitmap; - SurfGDI->SetPalette = Dc->DriverFunctions.SetPalette; - SurfGDI->MovePointer = Dc->DriverFunctions.MovePointer; - SurfGDI->SetPointerShape = (PFN_SetPointerShape)Dc->DriverFunctions.SetPointerShape; + SurfGDI->CreateDeviceBitmap = Device->DriverFunctions.CreateDeviceBitmap; + SurfGDI->SetPalette = Device->DriverFunctions.SetPalette; + SurfGDI->MovePointer = Device->DriverFunctions.MovePointer; + SurfGDI->SetPointerShape = (PFN_SetPointerShape)Device->DriverFunctions.SetPointerShape; return TRUE; } diff --git a/reactos/subsys/win32k/objects/dc.c b/reactos/subsys/win32k/objects/dc.c index 5ddaabbe23c..ea899a6e4b3 100644 --- a/reactos/subsys/win32k/objects/dc.c +++ b/reactos/subsys/win32k/objects/dc.c @@ -1,4 +1,4 @@ -/* $Id: dc.c,v 1.39 2002/09/17 23:43:29 dwelch Exp $ +/* $Id: dc.c,v 1.40 2002/09/18 23:56:48 dwelch Exp $ * * DC.C - Device context functions * @@ -81,6 +81,7 @@ INT STDCALL func_name( HDC hdc, INT mode ) \ return prevMode; \ } + VOID BitmapToSurf(HDC hdc, PSURFGDI SurfGDI, PSURFOBJ SurfObj, PBITMAPOBJ Bitmap); // --------------------------------------------------------- File Statics @@ -183,41 +184,22 @@ HDC STDCALL W32kCreateCompatableDC(HDC hDC) #include -HDC STDCALL W32kCreateDC(LPCWSTR Driver, - LPCWSTR Device, - LPCWSTR Output, - CONST PDEVMODEW InitData) +static GDIDEVICE PrimarySurface; +static BOOL PrimarySurfaceCreated = FALSE; + +BOOL STDCALL W32kCreatePrimarySurface(LPCWSTR Driver, + LPCWSTR Device) { PGD_ENABLEDRIVER GDEnableDriver; - HDC hNewDC; - PDC NewDC; - HDC hDC = NULL; + HANDLE DeviceDriver; DRVENABLEDATA DED; PSURFOBJ SurfObj; - /* Check for existing DC object */ - if ((hNewDC = DC_FindOpenDC(Driver)) != NULL) - { - hDC = hNewDC; - return W32kCreateCompatableDC(hDC); - } - - DPRINT("NAME: %S\n", Driver); // FIXME: Should not crash if NULL - - /* Allocate a DC object */ - if ((hNewDC = DC_AllocDC(Driver)) == NULL) - { - return NULL; - } - - NewDC = DC_HandleToPtr( hNewDC ); - ASSERT( NewDC ); - /* Open the miniport driver */ - if ((NewDC->DeviceDriver = DRIVER_FindMPDriver(Driver)) == NULL) + if ((DeviceDriver = DRIVER_FindMPDriver(Driver)) == NULL) { DPRINT("FindMPDriver failed\n"); - goto Failure; + return(FALSE); } /* Get the DDI driver's entry point */ @@ -225,7 +207,7 @@ HDC STDCALL W32kCreateDC(LPCWSTR Driver, if ((GDEnableDriver = DRIVER_FindDDIDriver(L"\\SystemRoot\\system32\\drivers\\vgaddi.dll")) == NULL) { DPRINT("FindDDIDriver failed\n"); - goto Failure; + return(FALSE); } /* Call DDI driver's EnableDriver function */ @@ -234,15 +216,15 @@ HDC STDCALL W32kCreateDC(LPCWSTR Driver, if (!GDEnableDriver(DDI_DRIVER_VERSION, sizeof(DED), &DED)) { DPRINT("DrvEnableDriver failed\n"); - goto Failure; + return(FALSE); } DPRINT("Building DDI Functions\n"); /* Construct DDI driver function dispatch table */ - if (!DRIVER_BuildDDIFunctions(&DED, &NewDC->DriverFunctions)) + if (!DRIVER_BuildDDIFunctions(&DED, &PrimarySurface.DriverFunctions)) { DPRINT("BuildDDIFunctions failed\n"); - goto Failure; + return(FALSE); } /* Allocate a phyical device handle from the driver */ @@ -251,43 +233,32 @@ HDC STDCALL W32kCreateDC(LPCWSTR Driver, DPRINT("Device in u: %u\n", Device); // wcsncpy(NewDC->DMW.dmDeviceName, Device, DMMAXDEVICENAME); FIXME: this crashes everything? } - NewDC->DMW.dmSize = sizeof(NewDC->DMW); - NewDC->DMW.dmFields = 0x000fc000; - - /* FIXME: get mode selection information from somewhere */ - - NewDC->DMW.dmLogPixels = 96; - NewDC->DMW.dmBitsPerPel = 4; - NewDC->DMW.dmPelsWidth = 640; - NewDC->DMW.dmPelsHeight = 480; - NewDC->DMW.dmDisplayFlags = 0; - NewDC->DMW.dmDisplayFrequency = 0; - - NewDC->w.bitsPerPixel = 4; // FIXME: set this here?? DPRINT("Enabling PDev\n"); - NewDC->PDev = NewDC->DriverFunctions.EnablePDev(&NewDC->DMW, - L"", - HS_DDI_MAX, - NewDC->FillPatternSurfaces, - sizeof(NewDC->GDIInfo), - (ULONG *) &NewDC->GDIInfo, - sizeof(NewDC->DevInfo), - &NewDC->DevInfo, - NULL, - L"", - NewDC->DeviceDriver); - if (NewDC->PDev == NULL) + PrimarySurface.PDev = + PrimarySurface.DriverFunctions.EnablePDev(&PrimarySurface.DMW, + L"", + HS_DDI_MAX, + PrimarySurface.FillPatterns, + sizeof(PrimarySurface.GDIInfo), + (ULONG *) &PrimarySurface.GDIInfo, + sizeof(PrimarySurface.DevInfo), + &PrimarySurface.DevInfo, + NULL, + L"", + DeviceDriver); + if (PrimarySurface.PDev == NULL) { DPRINT("DrvEnablePDEV failed\n"); - goto Failure; + return(FALSE); } DPRINT("calling completePDev\n"); /* Complete initialization of the physical device */ - NewDC->DriverFunctions.CompletePDev(NewDC->PDev, NewDC); + PrimarySurface.DriverFunctions.CompletePDev(PrimarySurface.PDev, + &PrimarySurface); DPRINT("calling DRIVER_ReferenceDriver\n"); @@ -296,11 +267,74 @@ HDC STDCALL W32kCreateDC(LPCWSTR Driver, DPRINT("calling EnableSurface\n"); /* Enable the drawing surface */ - NewDC->Surface = NewDC->DriverFunctions.EnableSurface(NewDC->PDev); // hsurf - NewDC->w.hPalette = NewDC->DevInfo.hpalDefault; + PrimarySurface.Handle = + PrimarySurface.DriverFunctions.EnableSurface(PrimarySurface.PDev); + + SurfObj = (PSURFOBJ)AccessUserObject(PrimarySurface.Handle); + SurfObj->dhpdev = PrimarySurface.PDev; +} + +HDC STDCALL W32kCreateDC(LPCWSTR Driver, + LPCWSTR Device, + LPCWSTR Output, + CONST PDEVMODEW InitData) +{ + HDC hNewDC; + PDC NewDC; + HDC hDC = NULL; + + /* Check for existing DC object */ + if ((hNewDC = DC_FindOpenDC(Driver)) != NULL) + { + hDC = hNewDC; + return W32kCreateCompatableDC(hDC); + } + + DPRINT("NAME: %S\n", Driver); // FIXME: Should not crash if NULL + + /* Allocate a DC object */ + if ((hNewDC = DC_AllocDC(Driver)) == NULL) + { + return NULL; + } - SurfObj = (PSURFOBJ)AccessUserObject(NewDC->Surface); - SurfObj->dhpdev = NewDC->PDev; + NewDC = DC_HandleToPtr( hNewDC ); + ASSERT( NewDC ); + + if (!PrimarySurfaceCreated) + { + if (!W32kCreatePrimarySurface(Driver, Device)) + { + DC_ReleasePtr( hNewDC ); + DC_FreeDC(hNewDC); + return NULL; + } + } + PrimarySurfaceCreated = TRUE; + NewDC->DMW = PrimarySurface.DMW; + NewDC->DevInfo = PrimarySurface.DevInfo; + NewDC->GDIInfo = PrimarySurface.GDIInfo; + memcpy(NewDC->FillPatternSurfaces, PrimarySurface.FillPatterns, + sizeof(NewDC->FillPatternSurfaces)); + NewDC->PDev = PrimarySurface.PDev; + NewDC->Surface = PrimarySurface.Handle; + NewDC->DriverFunctions = PrimarySurface.DriverFunctions; + + NewDC->DMW.dmSize = sizeof(NewDC->DMW); + NewDC->DMW.dmFields = 0x000fc000; + + /* FIXME: get mode selection information from somewhere */ + + NewDC->DMW.dmLogPixels = 96; + NewDC->DMW.dmBitsPerPel = 4; + NewDC->DMW.dmPelsWidth = 640; + NewDC->DMW.dmPelsHeight = 480; + NewDC->DMW.dmDisplayFlags = 0; + NewDC->DMW.dmDisplayFrequency = 0; + + NewDC->w.bitsPerPixel = 4; // FIXME: set this here?? + + NewDC->w.hPalette = NewDC->DevInfo.hpalDefault; DPRINT("Bits per pel: %u\n", NewDC->w.bitsPerPixel); @@ -313,11 +347,6 @@ HDC STDCALL W32kCreateDC(LPCWSTR Driver, DC_ReleasePtr( hNewDC ); return hNewDC; - -Failure: - DC_ReleasePtr( hNewDC ); - DC_FreeDC(hNewDC); - return NULL; } HDC STDCALL W32kCreateIC(LPCWSTR Driver, -- 2.17.1