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
* 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
* PROJECT: ReactOS kernel
@ -94,26 +94,37 @@ NtGdiDPtoLP(HDC hDC,
LPPOINT UnsafePoints,
int Count)
{
PDC Dc;
PDC dc;
INT i;
LPPOINT Points = (LPPOINT) ExAllocatePool( PagedPool, Count*sizeof(POINT));
BOOL ret = FALSE; // default to failure
ASSERT(Points);
if ( !Points )
return ret;
MmCopyFromCaller( Points, UnsafePoints, Count*sizeof(POINT) );
Dc = DC_LockDc (hDC);
if (Dc == NULL || !Dc->w.vport2WorldValid)
dc = DC_LockDc (hDC);
if ( dc )
{
ret = TRUE;
if ( dc->w.vport2WorldValid )
{
return(FALSE);
}
for (i = 0; i < Count; i++)
{
CoordDPtoLP(Dc, &Points[i]);
CoordDPtoLP ( dc, &Points[i] );
}
}
DC_UnlockDc( hDC );
MmCopyToCaller( UnsafePoints, Points, Count*sizeof(POINT) );
}
ExFreePool ( Points );
return(TRUE);
}
@ -148,17 +159,17 @@ NtGdiGetWorldTransform(HDC hDC,
{
PDC dc;
if (!XForm)
return FALSE;
dc = DC_LockDc (hDC);
if (!dc)
{
return FALSE;
}
if (!XForm)
{
return FALSE;
}
*XForm = dc->w.xformWorld2Wnd;
DC_UnlockDc ( hDC );
return TRUE;
}
@ -167,6 +178,10 @@ FASTCALL
CoordLPtoDP ( PDC Dc, LPPOINT Point )
{
FLOAT x, y;
ASSERT ( Dc );
ASSERT ( Point );
x = (FLOAT)Point->x;
y = (FLOAT)Point->y;
Point->x = x * Dc->w.xformWorld2Vport.eM11 +
@ -181,6 +196,8 @@ IntLPtoDP ( PDC dc, LPPOINT Points, INT Count )
{
INT i;
ASSERT ( Points );
for ( i = 0; i < Count; i++ )
CoordLPtoDP ( dc, &Points[i] );
}
@ -196,15 +213,19 @@ IntLPtoDP ( PDC dc, LPPOINT Points, INT Count )
BOOL STDCALL
NtGdiLPtoDP ( HDC hDC, LPPOINT UnsafePoints, INT Count )
{
PDC dc = DC_LockDc ( hDC );
LPPOINT Points;
if ( !dc )
return FALSE;
Points = (LPPOINT)ExAllocatePool ( PagedPool, Count*sizeof(POINT) );
PDC dc;
LPPOINT Points = (LPPOINT)ExAllocatePool ( PagedPool, Count*sizeof(POINT) );
BOOL ret = FALSE; // default to failure
ASSERT(Points);
if ( !Points )
return FALSE;
dc = DC_LockDc ( hDC );
if ( dc )
{
ret = TRUE;
MmCopyFromCaller( Points, UnsafePoints, Count*sizeof(POINT) );
@ -212,11 +233,12 @@ NtGdiLPtoDP ( HDC hDC, LPPOINT UnsafePoints, INT Count )
MmCopyToCaller ( UnsafePoints, Points, Count*sizeof(POINT) );
DC_UnlockDc ( hDC );
}
ExFreePool ( Points );
DC_UnlockDc ( hDC );
return TRUE;
return ret;
}
BOOL
@ -227,27 +249,21 @@ NtGdiModifyWorldTransform(HDC hDC,
{
PDC dc;
LPXFORM XForm = (LPXFORM) ExAllocatePool( PagedPool, sizeof( XFORM ) );
BOOL ret = FALSE; // default to failure
ASSERT( XForm );
if (!XForm)
return FALSE;
MmCopyFromCaller( XForm, UnsafeXForm, sizeof( XFORM ) );
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 */
if (dc->w.GraphicsMode!=GM_ADVANCED)
if ( dc->w.GraphicsMode == GM_ADVANCED )
{
return FALSE;
}
ret = TRUE; // switch to a default of success
switch (Mode)
{
case MWT_IDENTITY:
@ -268,12 +284,16 @@ NtGdiModifyWorldTransform(HDC hDC,
break;
default:
DC_UnlockDc( hDC );
return FALSE;
ret = FALSE;
break;
}
if ( ret )
DC_UpdateXforms ( dc );
}
DC_UnlockDc ( hDC );
return TRUE;
}
ExFreePool ( XForm );
return ret;
}
BOOL
@ -286,13 +306,12 @@ NtGdiOffsetViewportOrgEx(HDC hDC,
PDC dc;
POINT Point;
NTSTATUS Status;
BOOL ret = FALSE; // default to failure
dc = DC_LockDc ( hDC );
if (NULL == dc)
if ( dc )
{
return FALSE;
}
ret = TRUE;
if (NULL != UnsafePoint)
{
Point.x = dc->vportOrgX;
@ -301,17 +320,22 @@ NtGdiOffsetViewportOrgEx(HDC hDC,
if ( !NT_SUCCESS(Status) )
{
SetLastNtError(Status);
return FALSE;
ret = FALSE;
}
}
if ( ret )
{
dc->vportOrgX += XOffset;
dc->vportOrgY += YOffset;
DC_UpdateXforms(dc);
dc->w.DCOrgX += XOffset;
dc->w.DCOrgY += YOffset;
}
DC_UnlockDc ( hDC );
}
return TRUE;
}
@ -410,13 +434,13 @@ NtGdiSetMapMode(HDC hDC,
dc = DC_LockDc(hDC);
if (!dc)
{
return FALSE;
}
return 0;
PrevMapMode = dc->w.MapMode;
dc->w.MapMode = MapMode;
DC_UnlockDc ( hDC );
return PrevMapMode;
}
@ -431,9 +455,7 @@ NtGdiSetViewportExtEx(HDC hDC,
dc = DC_LockDc(hDC);
if ( !dc )
{
return FALSE;
}
switch (dc->w.MapMode)
{
@ -572,16 +594,14 @@ NtGdiSetWorldTransform(HDC hDC,
{
PDC dc;
if (!XForm)
return FALSE;
dc = DC_LockDc (hDC);
if ( !dc )
{
return FALSE;
}
if (!XForm)
{
DC_UnlockDc( hDC );
return FALSE;
}
/* Check that graphics mode is GM_ADVANCED */
if ( dc->w.GraphicsMode != GM_ADVANCED )