From 2f26431f7188c1c8fcdc33ff91bf9185f1cc5f54 Mon Sep 17 00:00:00 2001 From: Eugene Ingerman Date: Fri, 24 Jan 2003 23:25:34 +0000 Subject: [PATCH] Fixed: locking GDI objects twice when running wm_paint test. svn path=/trunk/; revision=4062 --- reactos/subsys/win32k/eng/mouse.c | 217 +++++++++++++------------ reactos/subsys/win32k/objects/region.c | 59 ++----- 2 files changed, 129 insertions(+), 147 deletions(-) diff --git a/reactos/subsys/win32k/eng/mouse.c b/reactos/subsys/win32k/eng/mouse.c index 550057b5591..e3499c75142 100644 --- a/reactos/subsys/win32k/eng/mouse.c +++ b/reactos/subsys/win32k/eng/mouse.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -/* $Id: mouse.c,v 1.15 2002/11/01 11:29:57 dwelch Exp $ +/* $Id: mouse.c,v 1.16 2003/01/24 23:25:34 ei Exp $ * * PROJECT: ReactOS kernel * PURPOSE: Mouse @@ -43,76 +43,76 @@ static LONG mouse_x, mouse_y; static UINT mouse_width = 0, mouse_height = 0; static UCHAR DefaultCursor[256] = { - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0xC0, 0x00, 0x00, - 0x00, 0xC0, 0x00, 0x00, - 0x01, 0x80, 0x00, 0x00, - 0x01, 0x80, 0x00, 0x00, - 0x03, 0x00, 0x00, 0x00, - 0x43, 0x00, 0x00, 0x00, - 0x66, 0x00, 0x00, 0x00, - 0x76, 0x00, 0x00, 0x00, - 0x7E, 0x00, 0x00, 0x00, - 0x7F, 0xC0, 0x00, 0x00, - 0x7F, 0x80, 0x00, 0x00, - 0x7F, 0x00, 0x00, 0x00, - 0x7E, 0x00, 0x00, 0x00, - 0x7C, 0x00, 0x00, 0x00, - 0x78, 0x00, 0x00, 0x00, - 0x70, 0x00, 0x00, 0x00, - 0x60, 0x00, 0x00, 0x00, - 0x40, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, + 0x00, 0xC0, 0x00, 0x00, + 0x00, 0xC0, 0x00, 0x00, + 0x01, 0x80, 0x00, 0x00, + 0x01, 0x80, 0x00, 0x00, + 0x03, 0x00, 0x00, 0x00, + 0x43, 0x00, 0x00, 0x00, + 0x66, 0x00, 0x00, 0x00, + 0x76, 0x00, 0x00, 0x00, + 0x7E, 0x00, 0x00, 0x00, + 0x7F, 0xC0, 0x00, 0x00, + 0x7F, 0x80, 0x00, 0x00, + 0x7F, 0x00, 0x00, 0x00, + 0x7E, 0x00, 0x00, 0x00, + 0x7C, 0x00, 0x00, 0x00, + 0x78, 0x00, 0x00, 0x00, + 0x70, 0x00, 0x00, 0x00, + 0x60, 0x00, 0x00, 0x00, + 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF,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C, 0x3F, 0xFF, 0xFF, + 0x7C, 0x3F, 0xFF, 0xFF, + 0x38, 0x7F, 0xFF, 0xFF, + 0x18, 0x7F, 0xFF, 0xFF, + 0x00, 0xFF, 0xFF, 0xFF, + 0x00, 0xFF, 0xFF, 0xFF, + 0x00, 0x0F, 0xFF, 0xFF, + 0x00, 0x1F, 0xFF, 0xFF, + 0x00, 0x3F, 0xFF, 0xFF, + 0x00, 0x7F, 0xFF, 0xFF, + 0x00, 0xFF, 0xFF, 0xFF, + 0x01, 0xFF, 0xFF, 0xFF, + 0x03, 0xFF, 0xFF, 0xFF, + 0x07, 0xFF, 0xFF, 0xFF, + 0x0F, 0xFF, 0xFF, 0xFF, + 0x1F, 0xFF, 0xFF, 0xFF, 0x3F, 0xFF, 0xFF, 0xFF}; /* FUNCTIONS *****************************************************************/ -INT -MouseSafetyOnDrawStart(PSURFOBJ SurfObj, PSURFGDI SurfGDI, LONG HazardX1, +INT +MouseSafetyOnDrawStart(PSURFOBJ SurfObj, PSURFGDI SurfGDI, LONG HazardX1, LONG HazardY1, LONG HazardX2, LONG HazardY2) /* * FUNCTION: Notify the mouse driver that drawing is about to begin in @@ -122,23 +122,23 @@ MouseSafetyOnDrawStart(PSURFOBJ SurfObj, PSURFGDI SurfGDI, LONG HazardX1, RECTL MouseRect; LONG tmp; - if (SurfObj == NULL) + if (SurfObj == NULL) { return(FALSE); } - if (SurfObj->iType != STYPE_DEVICE || MouseEnabled == FALSE) + if (SurfObj->iType != STYPE_DEVICE || MouseEnabled == FALSE) { return(FALSE); } - if (HazardX1 > HazardX2) - { - tmp = HazardX2; HazardX2 = HazardX1; HazardX1 = tmp; + if (HazardX1 > HazardX2) + { + tmp = HazardX2; HazardX2 = HazardX1; HazardX1 = tmp; } - if (HazardY1 > HazardY2) - { - tmp = HazardY2; HazardY2 = HazardY1; HazardY1 = tmp; + if (HazardY1 > HazardY2) + { + tmp = HazardY2; HazardY2 = HazardY1; HazardY1 = tmp; } if (((mouse_x + mouse_width) >= HazardX1) && (mouse_x <= HazardX2) && @@ -154,7 +154,7 @@ MouseSafetyOnDrawStart(PSURFOBJ SurfObj, PSURFGDI SurfGDI, LONG HazardX1, return(TRUE); } -INT +INT MouseSafetyOnDrawEnd(PSURFOBJ SurfObj, PSURFGDI SurfGDI) /* * FUNCTION: Notify the mouse driver that drawing has finished on a surface. @@ -162,12 +162,12 @@ MouseSafetyOnDrawEnd(PSURFOBJ SurfObj, PSURFGDI SurfGDI) { RECTL MouseRect; - if (SurfObj == NULL) + if (SurfObj == NULL) { return(FALSE); } - if (SurfObj->iType != STYPE_DEVICE || MouseEnabled == FALSE) + if (SurfObj->iType != STYPE_DEVICE || MouseEnabled == FALSE) { return(FALSE); } @@ -177,7 +177,7 @@ MouseSafetyOnDrawEnd(PSURFOBJ SurfObj, PSURFGDI SurfGDI) SurfGDI->MovePointer(SurfObj, mouse_x, mouse_y, &MouseRect); SafetySwitch = FALSE; } - + SafetySwitch2 = FALSE; return(TRUE); @@ -195,13 +195,13 @@ MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount) PDC dc; PSURFOBJ SurfObj; PSURFGDI SurfGDI; - RECTL MouseRect; + RECTL MouseRect; MSG Msg; ULONG j; LARGE_INTEGER LargeTickCount; ULONG TickCount; static ULONG ButtonsDown = 0; - const UINT MouseButtonDownMessage[3] = + const UINT MouseButtonDownMessage[3] = {WM_RBUTTONDOWN, WM_MBUTTONDOWN, WM_LBUTTONDOWN}; const UINT MouseButtonUpMessage[3] = {WM_RBUTTONUP, WM_MBUTTONUP, WM_LBUTTONUP}; @@ -218,7 +218,8 @@ MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount) dc = DC_HandleToPtr(hDC); SurfObj = (PSURFOBJ)AccessUserObject(dc->Surface); SurfGDI = (PSURFGDI)AccessInternalObject(dc->Surface); - + DC_ReleasePtr( hDC ); + /* Compile the total mouse movement change and dispatch button events. */ for (i = 0; i < InputCount; i++) { @@ -232,7 +233,7 @@ MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount) Msg.pt.x = mouse_x + mouse_cx; Msg.pt.y = mouse_y + mouse_cy; MsqInsertSystemMessage(&Msg); - + for (j = 0; j < 3; j++) { ULONG Flag = MouseButtonFlag[j]; @@ -245,8 +246,8 @@ MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount) MsqInsertSystemMessage(&Msg); } if (!(Data[i].ButtonData & (1 << j)) && (ButtonsDown & Flag)) - { - ButtonsDown &= ~Flag; + { + ButtonsDown &= ~Flag; Msg.wParam = ButtonsDown; Msg.message = MouseButtonUpMessage[j]; @@ -257,9 +258,9 @@ MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount) /* If the mouse moved then move the pointer. */ if (mouse_cx != 0 || mouse_cy != 0) - { + { mouse_x += mouse_cx; - mouse_y += mouse_cy; + mouse_y += mouse_cy; mouse_x = max(mouse_x, 0); mouse_y = max(mouse_y, 0); @@ -268,36 +269,46 @@ MouseGDICallBack(PMOUSE_INPUT_DATA Data, ULONG InputCount) if (SafetySwitch == FALSE && SafetySwitch2 == FALSE) { - SurfGDI->MovePointer(SurfObj, mouse_x, mouse_y, &MouseRect); + SurfGDI->MovePointer(SurfObj, mouse_x, mouse_y, &MouseRect); } } } -VOID +VOID EnableMouse(HDC hDisplayDC) { - PDC dc = DC_HandleToPtr(hDisplayDC); - PSURFOBJ SurfObj = (PSURFOBJ)AccessUserObject(dc->Surface); - PSURFGDI SurfGDI = (PSURFGDI)AccessInternalObject(dc->Surface); + PDC dc; + PSURFOBJ SurfObj; + PSURFGDI SurfGDI; HBITMAP hMouseSurf; PSURFOBJ MouseSurf; SIZEL MouseSize; RECTL MouseRect; - /* Create the default mouse cursor. */ - mouse_width = 32; - mouse_height = 32; - MouseSize.cx = 32; - MouseSize.cy = 64; - hMouseSurf = EngCreateBitmap(MouseSize, 4, BMF_1BPP, 0, DefaultCursor); - MouseSurf = (PSURFOBJ)AccessUserObject(hMouseSurf); + dc = DC_HandleToPtr(hDisplayDC); + if( dc ){ + SurfObj = (PSURFOBJ)AccessUserObject(dc->Surface); + SurfGDI = (PSURFGDI)AccessInternalObject(dc->Surface); + DC_ReleasePtr( hDisplayDC ); - /* Tell the display driver to set the pointer shape. */ - SurfGDI->SetPointerShape(SurfObj, MouseSurf, NULL, NULL, 0, 0, 320, 240, - &MouseRect, 0); + /* Create the default mouse cursor. */ + mouse_width = 32; + mouse_height = 32; + MouseSize.cx = 32; + MouseSize.cy = 64; + hMouseSurf = EngCreateBitmap(MouseSize, 4, BMF_1BPP, 0, DefaultCursor); + MouseSurf = (PSURFOBJ)AccessUserObject(hMouseSurf); - mouse_x = 320; - mouse_y = 240; - MouseEnabled = TRUE; + /* Tell the display driver to set the pointer shape. */ + SurfGDI->SetPointerShape(SurfObj, MouseSurf, NULL, NULL, 0, 0, 320, 240, + &MouseRect, 0); + + mouse_x = 320; + mouse_y = 240; + MouseEnabled = TRUE; + } + else{ + MouseEnabled = FALSE; + } } diff --git a/reactos/subsys/win32k/objects/region.c b/reactos/subsys/win32k/objects/region.c index 8238f7c0f70..e81184d12cc 100644 --- a/reactos/subsys/win32k/objects/region.c +++ b/reactos/subsys/win32k/objects/region.c @@ -314,35 +314,23 @@ empty: */ HRGN REGION_CropRgn(HRGN hDst, HRGN hSrc, const PRECT lpRect, PPOINT lpPt) { - PROSRGNDATA objSrc = RGNDATA_LockRgn(hSrc); - HRGN hNewDst; + PROSRGNDATA objSrc, rgnDst; + HRGN hNewDst, hRet = NULL; + GDIMULTILOCK Lock[2] = {{hDst, 0, GO_REGION_MAGIC}, {hSrc, 0, GO_REGION_MAGIC}}; - if(objSrc) - { - PROSRGNDATA rgnDst; - - if(hDst) - { - if(!(rgnDst = RGNDATA_LockRgn(hDst))) - { - hDst = 0; - goto done; - } - } - else{ + if( !hDst ){ if( !( hNewDst = RGNDATA_AllocRgn(1) ) ){ - RGNDATA_UnlockRgn( hSrc ); return 0; } + Lock[0].hObj = hNewDst; + } - if(!(rgnDst = RGNDATA_LockRgn(hNewDst))) - { - RGNDATA_FreeRgn( hNewDst ); - RGNDATA_UnlockRgn( hSrc ); - return 0; - } - } + GDIOBJ_LockMultipleObj( &Lock, 2 ); + rgnDst = Lock[0].pObj; + objSrc = Lock[1].pObj; + if( objSrc && rgnDst ) + { if(rgnDst) { POINT pt = { 0, 0 }; @@ -352,32 +340,15 @@ HRGN REGION_CropRgn(HRGN hDst, HRGN hSrc, const PRECT lpRect, PPOINT lpPt) if(REGION_CropAndOffsetRegion(lpPt, lpRect, objSrc, rgnDst) == FALSE) { // ve failed cleanup and return - RGNDATA_UnlockRgn( hSrc ); - - if(hDst) // unlock new region if allocated - RGNDATA_UnlockRgn( hDst ); - else - RGNDATA_UnlockRgn( hNewDst ); - - return 0; + hRet = NULL; } else{ // ve are fine. unlock the correct pointer and return correct handle - RGNDATA_UnlockRgn( hSrc ); - - if(hDst == 0){ - RGNDATA_UnlockRgn( hNewDst ); - return hNewDst; - } - else { - RGNDATA_UnlockRgn( hDst ); - return hDst; - } + hRet = Lock[0].hObj; } } -done: - RGNDATA_UnlockRgn( hSrc ); } - return 0; + GDIOBJ_UnlockMultipleObj( &Lock, 2 ); + return hRet; } /*!