From 243eeb574a064fe9d501ff45946b575efc9d101f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Gardou?= Date: Mon, 5 Apr 2010 10:58:43 +0000 Subject: [PATCH] [WIN32K] -Make direct DC release shared lock on surface each time they're unlocked. -Now they don't hold it unless they're locked themselves. -Do not create the device surface when switching modes, this is inconsistent with the PDEVOBJ creation, which does not. *No more "you are freeing a surface which is still hold" debug message when switching modes* svn path=/branches/reactos-yarotows/; revision=46733 --- subsystems/win32/win32k/eng/pdevobj.c | 38 ++++++++---------------- subsystems/win32/win32k/include/dc.h | 11 ++++--- subsystems/win32/win32k/objects/dclife.c | 3 +- 3 files changed, 19 insertions(+), 33 deletions(-) diff --git a/subsystems/win32/win32k/eng/pdevobj.c b/subsystems/win32/win32k/eng/pdevobj.c index 61bc0756692..5445e913724 100644 --- a/subsystems/win32/win32k/eng/pdevobj.c +++ b/subsystems/win32/win32k/eng/pdevobj.c @@ -60,8 +60,7 @@ PDEVOBJ_vRelease(PPDEVOBJ ppdev) /* Do we have a surface? */ if(ppdev->pSurface) { - /* Release the surface and let the driver free it */ - SURFACE_ShareUnlockSurface(ppdev->pSurface); + /* No one should hold a lock on this surface */ ppdev->pfn.DisableSurface(ppdev->dhpdev); } @@ -147,7 +146,7 @@ PDEVOBJ_pSurface( { HSURF hsurf; - DPRINT1("PDEVOBJ_pSurface()\n"); + DPRINT("PDEVOBJ_pSurface()\n"); /* Check if we already have a surface */ if (ppdev->pSurface) @@ -164,7 +163,7 @@ PDEVOBJ_pSurface( ppdev->pSurface = SURFACE_ShareLockSurface(hsurf); } - DPRINT1("PDEVOBJ_pSurface() returning %p\n", ppdev->pSurface); + DPRINT("PDEVOBJ_pSurface() returning %p\n", ppdev->pSurface); return ppdev->pSurface; } @@ -292,7 +291,6 @@ PDEVOBJ_vSwitchPdev( PPDEVOBJ ppdev2) { PDEVOBJ pdevTmp; - HDEV hdev; /* Exchange data */ pdevTmp = *ppdev; @@ -312,9 +310,10 @@ PDEVOBJ_vSwitchPdev( /* Exchange surface */ ppdev->pSurface = ppdev2->pSurface; ppdev2->pSurface = pdevTmp.pSurface; - hdev = ppdev->pSurface->SurfObj.hdev; - ppdev->pSurface->SurfObj.hdev = ppdev2->pSurface->SurfObj.hdev; - ppdev2->pSurface->SurfObj.hdev = hdev; + if(ppdev->pSurface) + ppdev->pSurface->SurfObj.hdev = (HDEV)ppdev; + if(ppdev2->pSurface) + ppdev2->pSurface->SurfObj.hdev = (HDEV)ppdev2; /* Exchange devinfo */ ppdev->devinfo = ppdev2->devinfo; @@ -338,7 +337,6 @@ PDEVOBJ_bSwitchMode( { UNICODE_STRING ustrDevice; PPDEVOBJ ppdevTmp; - PSURFACE pSurface; BOOL retval = FALSE; /* Lock the PDEV */ @@ -367,25 +365,14 @@ PDEVOBJ_bSwitchMode( goto leave; } - /* 3. Create a new surface */ - pSurface = PDEVOBJ_pSurface(ppdevTmp); - if (!pSurface) - { - DPRINT1("DrvEnableSurface failed\n"); - goto leave; - } + /* 3. Get DirectDraw information */ + /* 4. Enable DirectDraw Not traced */ + /* 5. Copy old PDEV state to new PDEV instance */ - ASSERT(pSurface->BitsLock); - - /* 4. Get DirectDraw information */ - /* 5. Enable DirectDraw Not traced */ - /* 6. Copy old PDEV state to new PDEV instance */ - - /* 7. Switch the PDEVs */ + /* 6. Switch the PDEVs */ PDEVOBJ_vSwitchPdev(ppdev, ppdevTmp); - ASSERT(ppdev->pSurface->BitsLock); - /* 8. Disable DirectDraw */ + /* 7. Disable DirectDraw */ PDEVOBJ_vRelease(ppdevTmp); @@ -397,7 +384,6 @@ leave: EngReleaseSemaphore(ghsemPDEV); DPRINT1("leave, ppdev = %p, pSurface = %p\n", ppdev, ppdev->pSurface); - ASSERT(ppdev->pSurface->BitsLock); return retval; } diff --git a/subsystems/win32/win32k/include/dc.h b/subsystems/win32/win32k/include/dc.h index 8578f8e7070..36ffef2a71b 100644 --- a/subsystems/win32/win32k/include/dc.h +++ b/subsystems/win32/win32k/include/dc.h @@ -176,12 +176,9 @@ DC_LockDc(HDC hdc) /* Acquire shared PDEV lock */ EngAcquireSemaphoreShared(pdc->ppdev->hsemDevLock); - /* Update Surface if needed */ - if(pdc->dclevel.pSurface != pdc->ppdev->pSurface) - { - if(pdc->dclevel.pSurface) SURFACE_ShareUnlockSurface(pdc->dclevel.pSurface); - pdc->dclevel.pSurface = PDEVOBJ_pSurface(pdc->ppdev); - } + /* Assign Surface */ + pdc->dclevel.pSurface = PDEVOBJ_pSurface(pdc->ppdev); + } return pdc; } @@ -192,6 +189,8 @@ DC_UnlockDc(PDC pdc) { if(pdc->dctype == DCTYPE_DIRECT) { + /* Release surface lock */ + SURFACE_ShareUnlockSurface(pdc->dclevel.pSurface); /* Release PDEV lock */ EngReleaseSemaphore(pdc->ppdev->hsemDevLock); } diff --git a/subsystems/win32/win32k/objects/dclife.c b/subsystems/win32/win32k/objects/dclife.c index 9e6b5b0f192..02fc6c5572c 100644 --- a/subsystems/win32/win32k/objects/dclife.c +++ b/subsystems/win32/win32k/objects/dclife.c @@ -377,7 +377,8 @@ ASSERT(pdc->rosdc.hGCClipRgn); PATH_Delete(pdc->dclevel.hPath); - if(pdc->dclevel.pSurface) + /* Ideally, no DC should hold a lock on a surface when being deleted */ + if(pdc->dclevel.pSurface && pdc->dctype != DCTYPE_DIRECT) SURFACE_ShareUnlockSurface(pdc->dclevel.pSurface); PDEVOBJ_vRelease(pdc->ppdev) ;