fixed several dc locking bugs as well as several memory leaks

svn path=/trunk/; revision=5717
This commit is contained in:
Royce Mitchell III 2003-08-20 22:07:36 +00:00
parent e2dd45fd4a
commit 6f9d6a7c74

View file

@ -16,7 +16,7 @@
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/ */
/* $Id: coord.c,v 1.17 2003/08/20 07:45:02 gvg Exp $ /* $Id: coord.c,v 1.18 2003/08/20 22:07:36 royce Exp $
* *
* COPYRIGHT: See COPYING in the top level directory * COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel * PROJECT: ReactOS kernel
@ -94,26 +94,37 @@ NtGdiDPtoLP(HDC hDC,
LPPOINT UnsafePoints, LPPOINT UnsafePoints,
int Count) int Count)
{ {
PDC Dc; PDC dc;
INT i; INT i;
LPPOINT Points = (LPPOINT) ExAllocatePool( PagedPool, Count*sizeof(POINT)); LPPOINT Points = (LPPOINT) ExAllocatePool( PagedPool, Count*sizeof(POINT));
BOOL ret = FALSE; // default to failure
ASSERT(Points); ASSERT(Points);
if ( !Points )
return ret;
MmCopyFromCaller( Points, UnsafePoints, Count*sizeof(POINT) ); MmCopyFromCaller( Points, UnsafePoints, Count*sizeof(POINT) );
Dc = DC_LockDc (hDC); dc = DC_LockDc (hDC);
if (Dc == NULL || !Dc->w.vport2WorldValid) if ( dc )
{
ret = TRUE;
if ( dc->w.vport2WorldValid )
{ {
return(FALSE);
}
for (i = 0; i < Count; i++) for (i = 0; i < Count; i++)
{ {
CoordDPtoLP(Dc, &Points[i]); CoordDPtoLP ( dc, &Points[i] );
} }
}
DC_UnlockDc( hDC ); DC_UnlockDc( hDC );
MmCopyToCaller( UnsafePoints, Points, Count*sizeof(POINT) ); MmCopyToCaller( UnsafePoints, Points, Count*sizeof(POINT) );
}
ExFreePool ( Points );
return(TRUE); return(TRUE);
} }
@ -148,17 +159,17 @@ NtGdiGetWorldTransform(HDC hDC,
{ {
PDC dc; PDC dc;
if (!XForm)
return FALSE;
dc = DC_LockDc (hDC); dc = DC_LockDc (hDC);
if (!dc) if (!dc)
{
return FALSE; return FALSE;
}
if (!XForm)
{
return FALSE;
}
*XForm = dc->w.xformWorld2Wnd; *XForm = dc->w.xformWorld2Wnd;
DC_UnlockDc ( hDC ); DC_UnlockDc ( hDC );
return TRUE; return TRUE;
} }
@ -167,6 +178,10 @@ FASTCALL
CoordLPtoDP ( PDC Dc, LPPOINT Point ) CoordLPtoDP ( PDC Dc, LPPOINT Point )
{ {
FLOAT x, y; FLOAT x, y;
ASSERT ( Dc );
ASSERT ( Point );
x = (FLOAT)Point->x; x = (FLOAT)Point->x;
y = (FLOAT)Point->y; y = (FLOAT)Point->y;
Point->x = x * Dc->w.xformWorld2Vport.eM11 + Point->x = x * Dc->w.xformWorld2Vport.eM11 +
@ -181,6 +196,8 @@ IntLPtoDP ( PDC dc, LPPOINT Points, INT Count )
{ {
INT i; INT i;
ASSERT ( Points );
for ( i = 0; i < Count; i++ ) for ( i = 0; i < Count; i++ )
CoordLPtoDP ( dc, &Points[i] ); CoordLPtoDP ( dc, &Points[i] );
} }
@ -196,15 +213,19 @@ IntLPtoDP ( PDC dc, LPPOINT Points, INT Count )
BOOL STDCALL BOOL STDCALL
NtGdiLPtoDP ( HDC hDC, LPPOINT UnsafePoints, INT Count ) NtGdiLPtoDP ( HDC hDC, LPPOINT UnsafePoints, INT Count )
{ {
PDC dc = DC_LockDc ( hDC ); PDC dc;
LPPOINT Points; LPPOINT Points = (LPPOINT)ExAllocatePool ( PagedPool, Count*sizeof(POINT) );
BOOL ret = FALSE; // default to failure
if ( !dc )
return FALSE;
Points = (LPPOINT)ExAllocatePool ( PagedPool, Count*sizeof(POINT) );
ASSERT(Points); ASSERT(Points);
if ( !Points )
return FALSE;
dc = DC_LockDc ( hDC );
if ( dc )
{
ret = TRUE;
MmCopyFromCaller( Points, UnsafePoints, Count*sizeof(POINT) ); MmCopyFromCaller( Points, UnsafePoints, Count*sizeof(POINT) );
@ -212,11 +233,12 @@ NtGdiLPtoDP ( HDC hDC, LPPOINT UnsafePoints, INT Count )
MmCopyToCaller ( UnsafePoints, Points, Count*sizeof(POINT) ); MmCopyToCaller ( UnsafePoints, Points, Count*sizeof(POINT) );
DC_UnlockDc ( hDC );
}
ExFreePool ( Points ); ExFreePool ( Points );
DC_UnlockDc ( hDC ); return ret;
return TRUE;
} }
BOOL BOOL
@ -227,27 +249,21 @@ NtGdiModifyWorldTransform(HDC hDC,
{ {
PDC dc; PDC dc;
LPXFORM XForm = (LPXFORM) ExAllocatePool( PagedPool, sizeof( XFORM ) ); LPXFORM XForm = (LPXFORM) ExAllocatePool( PagedPool, sizeof( XFORM ) );
BOOL ret = FALSE; // default to failure
ASSERT( XForm ); ASSERT( XForm );
if (!XForm)
return FALSE;
MmCopyFromCaller( XForm, UnsafeXForm, sizeof( XFORM ) ); MmCopyFromCaller( XForm, UnsafeXForm, sizeof( XFORM ) );
dc = DC_LockDc (hDC); dc = DC_LockDc (hDC);
if (!dc) if ( dc )
{ {
// SetLastError( ERROR_INVALID_HANDLE );
return FALSE;
}
if (!XForm)
{
return FALSE;
}
/* Check that graphics mode is GM_ADVANCED */ /* Check that graphics mode is GM_ADVANCED */
if (dc->w.GraphicsMode!=GM_ADVANCED) if ( dc->w.GraphicsMode == GM_ADVANCED )
{ {
return FALSE; ret = TRUE; // switch to a default of success
}
switch (Mode) switch (Mode)
{ {
case MWT_IDENTITY: case MWT_IDENTITY:
@ -268,12 +284,16 @@ NtGdiModifyWorldTransform(HDC hDC,
break; break;
default: default:
DC_UnlockDc( hDC ); ret = FALSE;
return FALSE; break;
} }
if ( ret )
DC_UpdateXforms ( dc ); DC_UpdateXforms ( dc );
}
DC_UnlockDc ( hDC ); DC_UnlockDc ( hDC );
return TRUE; }
ExFreePool ( XForm );
return ret;
} }
BOOL BOOL
@ -286,13 +306,12 @@ NtGdiOffsetViewportOrgEx(HDC hDC,
PDC dc; PDC dc;
POINT Point; POINT Point;
NTSTATUS Status; NTSTATUS Status;
BOOL ret = FALSE; // default to failure
dc = DC_LockDc ( hDC ); dc = DC_LockDc ( hDC );
if (NULL == dc) if ( dc )
{ {
return FALSE; ret = TRUE;
}
if (NULL != UnsafePoint) if (NULL != UnsafePoint)
{ {
Point.x = dc->vportOrgX; Point.x = dc->vportOrgX;
@ -301,17 +320,22 @@ NtGdiOffsetViewportOrgEx(HDC hDC,
if ( !NT_SUCCESS(Status) ) if ( !NT_SUCCESS(Status) )
{ {
SetLastNtError(Status); SetLastNtError(Status);
return FALSE; ret = FALSE;
} }
} }
if ( ret )
{
dc->vportOrgX += XOffset; dc->vportOrgX += XOffset;
dc->vportOrgY += YOffset; dc->vportOrgY += YOffset;
DC_UpdateXforms(dc); DC_UpdateXforms(dc);
dc->w.DCOrgX += XOffset; dc->w.DCOrgX += XOffset;
dc->w.DCOrgY += YOffset; dc->w.DCOrgY += YOffset;
}
DC_UnlockDc ( hDC );
}
return TRUE; return TRUE;
} }
@ -410,13 +434,13 @@ NtGdiSetMapMode(HDC hDC,
dc = DC_LockDc(hDC); dc = DC_LockDc(hDC);
if (!dc) if (!dc)
{ return 0;
return FALSE;
}
PrevMapMode = dc->w.MapMode; PrevMapMode = dc->w.MapMode;
dc->w.MapMode = MapMode; dc->w.MapMode = MapMode;
DC_UnlockDc ( hDC );
return PrevMapMode; return PrevMapMode;
} }
@ -431,9 +455,7 @@ NtGdiSetViewportExtEx(HDC hDC,
dc = DC_LockDc(hDC); dc = DC_LockDc(hDC);
if ( !dc ) if ( !dc )
{
return FALSE; return FALSE;
}
switch (dc->w.MapMode) switch (dc->w.MapMode)
{ {
@ -572,16 +594,14 @@ NtGdiSetWorldTransform(HDC hDC,
{ {
PDC dc; PDC dc;
if (!XForm)
return FALSE;
dc = DC_LockDc (hDC); dc = DC_LockDc (hDC);
if ( !dc ) if ( !dc )
{ {
return FALSE; return FALSE;
} }
if (!XForm)
{
DC_UnlockDc( hDC );
return FALSE;
}
/* Check that graphics mode is GM_ADVANCED */ /* Check that graphics mode is GM_ADVANCED */
if ( dc->w.GraphicsMode != GM_ADVANCED ) if ( dc->w.GraphicsMode != GM_ADVANCED )