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++)
{
CoordDPtoLP ( dc, &Points[i] );
}
} }
for (i = 0; i < Count; i++) DC_UnlockDc( hDC );
{
CoordDPtoLP(Dc, &Points[i]); MmCopyToCaller( UnsafePoints, Points, Count*sizeof(POINT) );
}
DC_UnlockDc( hDC ); }
ExFreePool ( Points );
MmCopyToCaller( UnsafePoints, Points, Count*sizeof(POINT) );
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,84 +213,87 @@ 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 ) ASSERT(Points);
if ( !Points )
return FALSE; return FALSE;
Points = (LPPOINT)ExAllocatePool ( PagedPool, Count*sizeof(POINT) ); dc = DC_LockDc ( hDC );
ASSERT ( Points ); if ( dc )
{
ret = TRUE;
MmCopyFromCaller( Points, UnsafePoints, Count*sizeof(POINT) ); MmCopyFromCaller( Points, UnsafePoints, Count*sizeof(POINT) );
IntLPtoDP ( dc, UnsafePoints, Count ); IntLPtoDP ( dc, UnsafePoints, 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
STDCALL STDCALL
NtGdiModifyWorldTransform(HDC hDC, NtGdiModifyWorldTransform(HDC hDC,
CONST LPXFORM UnsafeXForm, CONST LPXFORM UnsafeXForm,
DWORD Mode) DWORD Mode)
{ {
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 ); /* Check that graphics mode is GM_ADVANCED */
return FALSE; if ( dc->w.GraphicsMode == GM_ADVANCED )
} {
if (!XForm) ret = TRUE; // switch to a default of success
{ switch (Mode)
return FALSE; {
} case MWT_IDENTITY:
dc->w.xformWorld2Wnd.eM11 = 1.0f;
dc->w.xformWorld2Wnd.eM12 = 0.0f;
dc->w.xformWorld2Wnd.eM21 = 0.0f;
dc->w.xformWorld2Wnd.eM22 = 1.0f;
dc->w.xformWorld2Wnd.eDx = 0.0f;
dc->w.xformWorld2Wnd.eDy = 0.0f;
break;
/* Check that graphics mode is GM_ADVANCED */ case MWT_LEFTMULTIPLY:
if (dc->w.GraphicsMode!=GM_ADVANCED) NtGdiCombineTransform(&dc->w.xformWorld2Wnd, XForm, &dc->w.xformWorld2Wnd );
{ break;
return FALSE;
case MWT_RIGHTMULTIPLY:
NtGdiCombineTransform(&dc->w.xformWorld2Wnd, &dc->w.xformWorld2Wnd, XForm);
break;
default:
ret = FALSE;
break;
}
if ( ret )
DC_UpdateXforms ( dc );
}
DC_UnlockDc ( hDC );
} }
switch (Mode) ExFreePool ( XForm );
{ return ret;
case MWT_IDENTITY:
dc->w.xformWorld2Wnd.eM11 = 1.0f;
dc->w.xformWorld2Wnd.eM12 = 0.0f;
dc->w.xformWorld2Wnd.eM21 = 0.0f;
dc->w.xformWorld2Wnd.eM22 = 1.0f;
dc->w.xformWorld2Wnd.eDx = 0.0f;
dc->w.xformWorld2Wnd.eDy = 0.0f;
break;
case MWT_LEFTMULTIPLY:
NtGdiCombineTransform(&dc->w.xformWorld2Wnd, XForm, &dc->w.xformWorld2Wnd );
break;
case MWT_RIGHTMULTIPLY:
NtGdiCombineTransform(&dc->w.xformWorld2Wnd, &dc->w.xformWorld2Wnd, XForm);
break;
default:
DC_UnlockDc( hDC );
return FALSE;
}
DC_UpdateXforms (dc);
DC_UnlockDc( hDC );
return TRUE;
} }
BOOL BOOL
@ -283,35 +303,39 @@ NtGdiOffsetViewportOrgEx(HDC hDC,
int YOffset, int YOffset,
LPPOINT UnsafePoint) LPPOINT UnsafePoint)
{ {
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 )
{
ret = TRUE;
if (NULL != UnsafePoint)
{
Point.x = dc->vportOrgX;
Point.y = dc->vportOrgY;
Status = MmCopyToCaller(UnsafePoint, &Point, sizeof(POINT));
if ( !NT_SUCCESS(Status) )
{
SetLastNtError(Status);
ret = FALSE;
}
}
if ( ret )
{ {
return FALSE; dc->vportOrgX += XOffset;
dc->vportOrgY += YOffset;
DC_UpdateXforms(dc);
dc->w.DCOrgX += XOffset;
dc->w.DCOrgY += YOffset;
} }
if (NULL != UnsafePoint) DC_UnlockDc ( hDC );
{ }
Point.x = dc->vportOrgX;
Point.y = dc->vportOrgY;
Status = MmCopyToCaller(UnsafePoint, &Point, sizeof(POINT));
if (! NT_SUCCESS(Status))
{
SetLastNtError(Status);
return FALSE;
}
}
dc->vportOrgX += XOffset;
dc->vportOrgY += YOffset;
DC_UpdateXforms(dc);
dc->w.DCOrgX += XOffset;
dc->w.DCOrgY += YOffset;
return TRUE; return TRUE;
} }
@ -403,37 +427,35 @@ NtGdiSetGraphicsMode(HDC hDC,
int int
STDCALL STDCALL
NtGdiSetMapMode(HDC hDC, NtGdiSetMapMode(HDC hDC,
int MapMode) int MapMode)
{ {
int PrevMapMode; int PrevMapMode;
PDC dc; PDC dc;
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;
} }
BOOL BOOL
STDCALL STDCALL
NtGdiSetViewportExtEx(HDC hDC, NtGdiSetViewportExtEx(HDC hDC,
int XExtent, int XExtent,
int YExtent, int YExtent,
LPSIZE Size) LPSIZE Size)
{ {
PDC dc; PDC dc;
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,19 +594,17 @@ NtGdiSetWorldTransform(HDC hDC,
{ {
PDC dc; PDC dc;
dc = DC_LockDc (hDC);
if (!dc)
{
return FALSE;
}
if (!XForm) if (!XForm)
return FALSE;
dc = DC_LockDc (hDC);
if ( !dc )
{ {
DC_UnlockDc( hDC );
return FALSE; 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 )
{ {
DC_UnlockDc( hDC ); DC_UnlockDc( hDC );
return FALSE; return FALSE;