Author: tkreuzer
Date: Tue Mar 24 07:10:49 2009
New Revision: 40203
URL:
http://svn.reactos.org/svn/reactos?rev=40203&view=rev
Log:
More dc cleanup: make DC_AllocDC return a pointer, not a handle, like done with the other
objects, too.
Remove DC_GetnextDC and DC_SetNextDC, as they are trivial. Misc cleanup and improvements.
Modified:
trunk/reactos/subsystems/win32/win32k/objects/dclife.c
trunk/reactos/subsystems/win32/win32k/objects/dcstate.c
trunk/reactos/subsystems/win32/win32k/objects/dcutil.c
Modified: trunk/reactos/subsystems/win32/win32k/objects/dclife.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/dclife.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/dclife.c [iso-8859-1] Tue Mar 24
07:10:49 2009
@@ -57,6 +57,7 @@
}
pdcattr = NewDC->pdcattr;
+ // FIXME: no floating point in the kernel!
xformTemplate.eM11 = 1.0f;
xformTemplate.eM12 = 0.0f;
xformTemplate.eM21 = 0.0f;
@@ -67,7 +68,7 @@
XForm2MatrixS(&NewDC->dclevel.mxDeviceToWorld, &xformTemplate);
XForm2MatrixS(&NewDC->dclevel.mxWorldToPage, &xformTemplate);
-// Setup syncing bits for the dcattr data packets.
+ // Setup syncing bits for the dcattr data packets.
pdcattr->flXform = DEVICE_TO_PAGE_INVALID;
pdcattr->ulDirty_ = 0; // Server side
@@ -87,21 +88,21 @@
pdcattr->ulBackgroundClr = 0xffffff;
pdcattr->crBackgroundClr = 0xffffff;
- pdcattr->ulPenClr = RGB( 0, 0, 0 );
- pdcattr->crPenClr = RGB( 0, 0, 0 );
-
- pdcattr->ulBrushClr = RGB( 255, 255, 255 ); // Do this way too.
- pdcattr->crBrushClr = RGB( 255, 255, 255 );
+ pdcattr->ulPenClr = RGB(0, 0, 0);
+ pdcattr->crPenClr = RGB(0, 0, 0);
+
+ pdcattr->ulBrushClr = RGB(255, 255, 255); // Do this way too.
+ pdcattr->crBrushClr = RGB(255, 255, 255);
//// This fixes the default brush and pen settings. See DC_InitDC.
/* Create the default fill brush */
- pdcattr->hbrush = NtGdiGetStockObject( WHITE_BRUSH );
+ pdcattr->hbrush = NtGdiGetStockObject(WHITE_BRUSH);
NewDC->dclevel.pbrFill = BRUSH_ShareLockBrush(pdcattr->hbrush);
EBRUSHOBJ_vInit(&NewDC->eboFill, NewDC->dclevel.pbrFill, NULL);
/* Create the default pen / line brush */
- pdcattr->hpen = NtGdiGetStockObject( BLACK_PEN );
+ pdcattr->hpen = NtGdiGetStockObject(BLACK_PEN);
NewDC->dclevel.pbrLine = PEN_ShareLockPen(pdcattr->hpen);
EBRUSHOBJ_vInit(&NewDC->eboLine, NewDC->dclevel.pbrFill, NULL);
@@ -112,16 +113,14 @@
NewDC->dclevel.hpal = NtGdiGetStockObject(DEFAULT_PALETTE);
NewDC->dclevel.laPath.eMiterLimit = 10.0;
- DC_UnlockDc(NewDC);
-
- return hDC;
+ return NewDC;
}
VOID FASTCALL
DC_FreeDC(HDC DCToFree)
{
DC_FreeDcAttr(DCToFree);
- if (!IsObjectDead( DCToFree ))
+ if (!IsObjectDead(DCToFree))
{
if (!GDIOBJ_FreeObjByHandle(DCToFree, GDI_OBJECT_TYPE_DC))
{
@@ -172,6 +171,7 @@
}
DC_UnlockDc(pDC);
}
+
return TRUE;
}
@@ -248,20 +248,13 @@
}
/* Allocate a DC object */
- if ((hdc = DC_AllocDC(Driver)) == NULL)
+ pdc = DC_AllocDC(Driver);
+ if (pdc == NULL)
{
DPRINT1("DC_AllocDC() failed\n");
- return NULL;
- }
-
- pdc = DC_LockDc( hdc );
- if ( !pdc )
- {
- DC_FreeDC( hdc );
- DPRINT1("DC_LockDc() failed\n");
return NULL;
}
-
+ hdc = pdc->BaseObject.hHmgr;
pdcattr = pdc->pdcattr;
pdc->dctype = DC_TYPE_DIRECT;
@@ -298,7 +291,7 @@
{
pdc->pSurfInfo = NULL;
// pdc->dclevel.pSurface =
- DC_UnlockDc( pdc );
+ DC_UnlockDc(pdc);
/* Initialize the DC state */
DC_InitDC(hdc);
@@ -318,7 +311,7 @@
DC_vSelectSurface(pdc, NULL);
pdcattr->crBackgroundClr = pdcattr->ulBackgroundClr = RGB(255, 255, 255);
pdcattr->crForegroundClr = RGB(0, 0, 0);
- DC_UnlockDc( pdc );
+ DC_UnlockDc(pdc);
}
if (hVisRgn)
@@ -342,7 +335,7 @@
ULONG iType,
HANDLE hspool,
VOID *pDriverInfo2,
- VOID *pUMdhpdev )
+ VOID *pUMdhpdev)
{
UNICODE_STRING SafeDevice;
DEVMODEW SafeInitData;
@@ -417,17 +410,17 @@
//
if (hDC && !defaultDCstate) // Ultra HAX! Dedicated to GvG!
{ // This is a cheesy way to do this.
- PDC dc = DC_LockDc ( hDC );
+ PDC dc = DC_LockDc(hDC);
defaultDCstate = ExAllocatePoolWithTag(PagedPool, sizeof(DC), TAG_DC);
if (!defaultDCstate)
{
- DC_UnlockDc( dc );
+ DC_UnlockDc(dc);
return NULL;
}
RtlZeroMemory(defaultDCstate, sizeof(DC));
defaultDCstate->pdcattr = &defaultDCstate->dcattr;
IntGdiCopyToSaveState(dc, defaultDCstate);
- DC_UnlockDc( dc );
+ DC_UnlockDc(dc);
}
return hDC;
}
@@ -436,7 +429,7 @@
FASTCALL
IntGdiDeleteDC(HDC hDC, BOOL Force)
{
- PDC DCToDelete = DC_LockDc(hDC);
+ PDC DCToDelete = DC_LockDc(hDC);
if (DCToDelete == NULL)
{
@@ -449,7 +442,7 @@
if (DCToDelete->fs & DC_FLAG_PERMANENT)
{
DPRINT1("No! You Naughty Application!\n");
- DC_UnlockDc( DCToDelete );
+ DC_UnlockDc(DCToDelete);
return UserReleaseDC(NULL, hDC, FALSE);
}
}
@@ -460,15 +453,15 @@
PDC savedDC;
HDC savedHDC;
- savedHDC = DC_GetNextDC (DCToDelete);
- savedDC = DC_LockDc (savedHDC);
+ savedHDC = DCToDelete->hdcNext;
+ savedDC = DC_LockDc(savedHDC);
if (savedDC == NULL)
{
break;
}
- DC_SetNextDC (DCToDelete, DC_GetNextDC (savedDC));
+ DCToDelete->hdcNext = savedDC->hdcNext;
DCToDelete->dclevel.lSaveDepth--;
- DC_UnlockDc( savedDC );
+ DC_UnlockDc(savedDC);
IntGdiDeleteDC(savedHDC, Force);
}
@@ -487,11 +480,11 @@
}
if (DCToDelete->rosdc.hClipRgn)
{
- NtGdiDeleteObject (DCToDelete->rosdc.hClipRgn);
+ NtGdiDeleteObject(DCToDelete->rosdc.hClipRgn);
}
if (DCToDelete->rosdc.hVisRgn)
{
- NtGdiDeleteObject (DCToDelete->rosdc.hVisRgn);
+ NtGdiDeleteObject(DCToDelete->rosdc.hVisRgn);
}
if (NULL != DCToDelete->rosdc.CombinedClip)
{
@@ -499,12 +492,12 @@
}
if (DCToDelete->rosdc.hGCClipRgn)
{
- NtGdiDeleteObject (DCToDelete->rosdc.hGCClipRgn);
+ NtGdiDeleteObject(DCToDelete->rosdc.hGCClipRgn);
}
PATH_Delete(DCToDelete->dclevel.hPath);
- DC_UnlockDc( DCToDelete );
- DC_FreeDC ( hDC );
+ DC_UnlockDc(DCToDelete);
+ DC_FreeDC(hDC);
return TRUE;
}
@@ -553,9 +546,9 @@
HDC APIENTRY
NtGdiCreateCompatibleDC(HDC hDC)
{
- PDC NewDC, OrigDC;
+ PDC pdcNew, pdcOld;
PDC_ATTR pdcattrNew, pdcattrOld;
- HDC hNewDC, DisplayDC = NULL;
+ HDC hdcNew, DisplayDC = NULL;
HRGN hVisRgn;
UNICODE_STRING DriverName;
DWORD Layout = 0;
@@ -573,8 +566,8 @@
}
/* Allocate a new DC based on the original DC's device */
- OrigDC = DC_LockDc(hDC);
- if (NULL == OrigDC)
+ pdcOld = DC_LockDc(hDC);
+ if (NULL == pdcOld)
{
if (NULL != DisplayDC)
{
@@ -583,35 +576,28 @@
DPRINT1("Failed to lock hDC\n");
return NULL;
}
- hNewDC = DC_AllocDC(&OrigDC->rosdc.DriverName);
- if (NULL == hNewDC)
- {
- DPRINT1("Failed to create hNewDC\n");
- DC_UnlockDc(OrigDC);
- if (NULL != DisplayDC)
+ pdcNew = DC_AllocDC(&pdcOld->rosdc.DriverName);
+ if (!pdcNew)
+ {
+ DPRINT1("Failed to create pdcNew\n");
+ DC_UnlockDc(pdcOld);
+ if (DisplayDC)
{
NtGdiDeleteObjectApp(DisplayDC);
}
return NULL;
}
- NewDC = DC_LockDc( hNewDC );
-
- if (!NewDC)
- {
- DPRINT1("Failed to lock hNewDC\n");
- NtGdiDeleteObjectApp(hNewDC);
- return NULL;
- }
-
- pdcattrOld = OrigDC->pdcattr;
- pdcattrNew = NewDC->pdcattr;
+ hdcNew = pdcNew->BaseObject.hHmgr;
+
+ pdcattrOld = pdcOld->pdcattr;
+ pdcattrNew = pdcNew->pdcattr;
/* Copy information from original DC to new DC */
- NewDC->dclevel.hdcSave = hNewDC;
-
- NewDC->dhpdev = OrigDC->dhpdev;
-
- NewDC->rosdc.bitsPerPixel = OrigDC->rosdc.bitsPerPixel;
+ pdcNew->dclevel.hdcSave = hdcNew;
+
+ pdcNew->dhpdev = pdcOld->dhpdev;
+
+ pdcNew->rosdc.bitsPerPixel = pdcOld->rosdc.bitsPerPixel;
/* DriverName is copied in the AllocDC routine */
pdcattrNew->ptlWindowOrg = pdcattrOld->ptlWindowOrg;
@@ -619,10 +605,10 @@
pdcattrNew->ptlViewportOrg = pdcattrOld->ptlViewportOrg;
pdcattrNew->szlViewportExt = pdcattrOld->szlViewportExt;
- NewDC->dctype = DC_TYPE_MEMORY; // Always!
- NewDC->rosdc.hBitmap = NtGdiGetStockObject(DEFAULT_BITMAP);
- NewDC->ppdev = OrigDC->ppdev;
- NewDC->dclevel.hpal = OrigDC->dclevel.hpal;
+ pdcNew->dctype = DC_TYPE_MEMORY; // Always!
+ pdcNew->rosdc.hBitmap = NtGdiGetStockObject(DEFAULT_BITMAP);
+ pdcNew->ppdev = pdcOld->ppdev;
+ pdcNew->dclevel.hpal = pdcOld->dclevel.hpal;
pdcattrNew->lTextAlign = pdcattrOld->lTextAlign;
pdcattrNew->lBkMode = pdcattrOld->lBkMode;
@@ -630,17 +616,14 @@
pdcattrNew->jROP2 = pdcattrOld->jROP2;
pdcattrNew->dwLayout = pdcattrOld->dwLayout;
if (pdcattrOld->dwLayout & LAYOUT_ORIENTATIONMASK) Layout =
pdcattrOld->dwLayout;
- NewDC->dclevel.flPath = OrigDC->dclevel.flPath;
+ pdcNew->dclevel.flPath = pdcOld->dclevel.flPath;
pdcattrNew->ulDirty_ = pdcattrOld->ulDirty_;
pdcattrNew->iCS_CP = pdcattrOld->iCS_CP;
- NewDC->erclWindow = (RECTL)
- {
- 0,0,1,1
- };
-
- DC_UnlockDc(NewDC);
- DC_UnlockDc(OrigDC);
+ pdcNew->erclWindow = (RECTL){0, 0, 1, 1};
+
+ DC_UnlockDc(pdcNew);
+ DC_UnlockDc(pdcOld);
if (NULL != DisplayDC)
{
NtGdiDeleteObjectApp(DisplayDC);
@@ -649,19 +632,19 @@
hVisRgn = NtGdiCreateRectRgn(0, 0, 1, 1);
if (hVisRgn)
{
- GdiSelectVisRgn(hNewDC, hVisRgn);
+ GdiSelectVisRgn(hdcNew, hVisRgn);
NtGdiDeleteObject(hVisRgn);
}
- if (Layout) NtGdiSetLayout( hNewDC, -1, Layout);
-
- DC_InitDC(hNewDC);
- return hNewDC;
+ if (Layout) NtGdiSetLayout(hdcNew, -1, Layout);
+
+ DC_InitDC(hdcNew);
+ return hdcNew;
}
BOOL
APIENTRY
-NtGdiDeleteObjectApp(HANDLE DCHandle)
+NtGdiDeleteObjectApp(HANDLE DCHandle)
{
/* Complete all pending operations */
NtGdiFlushUserBatch();
Modified: trunk/reactos/subsystems/win32/win32k/objects/dcstate.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/dcstate.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/dcstate.c [iso-8859-1] Tue Mar 24
07:10:49 2009
@@ -177,34 +177,33 @@
}
HDC APIENTRY
-IntGdiGetDCState(HDC hDC)
-{
- PDC newdc, dc;
- HDC hnewdc;
-
- dc = DC_LockDc(hDC);
- if (dc == NULL)
- {
- SetLastWin32Error(ERROR_INVALID_HANDLE);
- return 0;
- }
-
- hnewdc = DC_AllocDC(NULL);
- if (hnewdc == NULL)
- {
- DC_UnlockDc(dc);
- return 0;
- }
- newdc = DC_LockDc( hnewdc );
- /* FIXME - newdc can be NULL!!!! Don't assert here!!! */
- ASSERT( newdc );
-
- newdc->dclevel.hdcSave = hnewdc;
- IntGdiCopyToSaveState( dc, newdc);
-
- DC_UnlockDc( newdc );
- DC_UnlockDc( dc );
- return hnewdc;
+IntGdiGetDCState(HDC hDC)
+{
+ PDC pdcNew, pdc;
+ HDC hdcNew;
+
+ pdc = DC_LockDc(hDC);
+ if (pdc == NULL)
+ {
+ SetLastWin32Error(ERROR_INVALID_HANDLE);
+ return 0;
+ }
+
+ pdcNew = DC_AllocDC(NULL);
+ if (pdcNew == NULL)
+ {
+ DC_UnlockDc(pdc);
+ return 0;
+ }
+ hdcNew = pdcNew->BaseObject.hHmgr;
+
+ pdcNew->dclevel.hdcSave = hdcNew;
+ IntGdiCopyToSaveState(pdc, pdcNew);
+
+ DC_UnlockDc(pdcNew);
+ DC_UnlockDc(pdc);
+
+ return hdcNew;
}
VOID
@@ -281,7 +280,7 @@
success=TRUE;
while (dc->dclevel.lSaveDepth >= SaveLevel)
{
- HDC hdcs = DC_GetNextDC (dc);
+ HDC hdcs = dc->hdcNext;
dcs = DC_LockDc (hdcs);
if (dcs == NULL)
@@ -290,7 +289,7 @@
return FALSE;
}
- DC_SetNextDC (dc, DC_GetNextDC (dcs));
+ dc->hdcNext = dcs->hdcNext;
dcs->hdcNext = 0;
if (--dc->dclevel.lSaveDepth < SaveLevel)
@@ -359,8 +358,8 @@
dcs->dclevel.hPath = dc->dclevel.hPath;
if (dcs->dclevel.hPath) dcs->dclevel.flPath |= DCPATH_SAVE;
- DC_SetNextDC (dcs, DC_GetNextDC (dc));
- DC_SetNextDC (dc, hdcs);
+ dcs->hdcNext = dc->hdcNext;
+ dc->hdcNext = hdcs;
ret = ++dc->dclevel.lSaveDepth;
DC_UnlockDc( dcs );
DC_UnlockDc( dc );
Modified: trunk/reactos/subsystems/win32/win32k/objects/dcutil.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/subsystems/win32/win32k/ob…
==============================================================================
--- trunk/reactos/subsystems/win32/win32k/objects/dcutil.c [iso-8859-1] (original)
+++ trunk/reactos/subsystems/win32/win32k/objects/dcutil.c [iso-8859-1] Tue Mar 24
07:10:49 2009
@@ -124,19 +124,6 @@
}
#endif
-// FIXME: remove me
-HDC FASTCALL
-DC_GetNextDC (PDC pDC)
-{
- return pDC->hdcNext;
-}
-
-VOID FASTCALL
-DC_SetNextDC (PDC pDC, HDC hNextDC)
-{
- pDC->hdcNext = hNextDC;
-}
-
BOOL APIENTRY
NtGdiCancelDC(HDC hDC)
@@ -144,8 +131,6 @@
UNIMPLEMENTED;
return FALSE;
}
-
-
WORD APIENTRY
@@ -191,7 +176,7 @@
DWORD *Result)
{
BOOL Ret = TRUE;
- PDC dc;
+ PDC pdc;
PDC_ATTR pdcattr;
DWORD SafeResult = 0;
@@ -203,13 +188,13 @@
return FALSE;
}
- dc = DC_LockDc(hDC);
- if (!dc)
+ pdc = DC_LockDc(hDC);
+ if (!pdc)
{
SetLastWin32Error(ERROR_INVALID_HANDLE);
return FALSE;
}
- pdcattr = dc->pdcattr;
+ pdcattr = pdc->pdcattr;
switch (u)
{
@@ -230,20 +215,20 @@
case GdiGetArcDirection:
if (pdcattr->dwLayout & LAYOUT_RTL)
- SafeResult = AD_CLOCKWISE - ((dc->dclevel.flPath &
DCPATH_CLOCKWISE) != 0);
+ SafeResult = AD_CLOCKWISE - ((pdc->dclevel.flPath &
DCPATH_CLOCKWISE) != 0);
else
- SafeResult = ((dc->dclevel.flPath & DCPATH_CLOCKWISE) != 0) +
AD_COUNTERCLOCKWISE;
+ SafeResult = ((pdc->dclevel.flPath & DCPATH_CLOCKWISE) != 0) +
AD_COUNTERCLOCKWISE;
break;
case GdiGetEMFRestorDc:
break;
case GdiGetFontLanguageInfo:
- SafeResult = IntGetFontLanguageInfo(dc);
+ SafeResult = IntGetFontLanguageInfo(pdc);
break;
case GdiGetIsMemDc:
- SafeResult = dc->dctype;
+ SafeResult = pdc->dctype;
break;
case GdiGetMapMode:
@@ -264,9 +249,7 @@
{
_SEH2_TRY
{
- ProbeForWrite(Result,
- sizeof(DWORD),
- 1);
+ ProbeForWrite(Result, sizeof(DWORD), 1);
*Result = SafeResult;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
@@ -274,16 +257,15 @@
Status = _SEH2_GetExceptionCode();
}
_SEH2_END;
- }
-
- if (!NT_SUCCESS(Status))
- {
- SetLastNtError(Status);
- DC_UnlockDc(dc);
- return FALSE;
- }
-
- DC_UnlockDc(dc);
+
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastNtError(Status);
+ Ret = FALSE;
+ }
+ }
+
+ DC_UnlockDc(pdc);
return Ret;
}
@@ -296,7 +278,7 @@
DWORD *Result)
{
BOOL Ret = TRUE;
- PDC dc;
+ PDC pdc;
PDC_ATTR pdcattr;
DWORD SafeResult = 0;
@@ -308,19 +290,19 @@
return FALSE;
}
- dc = DC_LockDc(hDC);
- if (!dc)
+ pdc = DC_LockDc(hDC);
+ if (!pdc)
{
SetLastWin32Error(ERROR_INVALID_HANDLE);
return FALSE;
}
- pdcattr = dc->pdcattr;
+ pdcattr = pdc->pdcattr;
switch (u)
{
case GdiGetSetCopyCount:
- SafeResult = dc->ulCopyCount;
- dc->ulCopyCount = dwIn;
+ SafeResult = pdc->ulCopyCount;
+ pdc->ulCopyCount = dwIn;
break;
case GdiGetSetTextAlign:
@@ -354,7 +336,7 @@
break;
case GdiGetSetMapMode:
- SafeResult = IntGdiSetMapMode(dc, dwIn);
+ SafeResult = IntGdiSetMapMode(pdc, dwIn);
break;
case GdiGetSetArcDirection:
@@ -366,23 +348,24 @@
}
if (pdcattr->dwLayout & LAYOUT_RTL) // Right to Left
{
- SafeResult = AD_CLOCKWISE - ((dc->dclevel.flPath &
DCPATH_CLOCKWISE) != 0);
+ SafeResult = AD_CLOCKWISE - ((pdc->dclevel.flPath &
DCPATH_CLOCKWISE) != 0);
if (dwIn == AD_CLOCKWISE)
{
- dc->dclevel.flPath &= ~DCPATH_CLOCKWISE;
+ pdc->dclevel.flPath &= ~DCPATH_CLOCKWISE;
break;
}
- dc->dclevel.flPath |= DCPATH_CLOCKWISE;
+ pdc->dclevel.flPath |= DCPATH_CLOCKWISE;
}
else // Left to Right
{
- SafeResult = ((dc->dclevel.flPath & DCPATH_CLOCKWISE) != 0) +
AD_COUNTERCLOCKWISE;
+ SafeResult = ((pdc->dclevel.flPath & DCPATH_CLOCKWISE) != 0) +
+ AD_COUNTERCLOCKWISE;
if (dwIn == AD_COUNTERCLOCKWISE)
{
- dc->dclevel.flPath &= ~DCPATH_CLOCKWISE;
+ pdc->dclevel.flPath &= ~DCPATH_CLOCKWISE;
break;
}
- dc->dclevel.flPath |= DCPATH_CLOCKWISE;
+ pdc->dclevel.flPath |= DCPATH_CLOCKWISE;
}
break;
@@ -396,9 +379,7 @@
{
_SEH2_TRY
{
- ProbeForWrite(Result,
- sizeof(DWORD),
- 1);
+ ProbeForWrite(Result, sizeof(DWORD), 1);
*Result = SafeResult;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
@@ -406,15 +387,14 @@
Status = _SEH2_GetExceptionCode();
}
_SEH2_END;
- }
-
- if (!NT_SUCCESS(Status))
- {
- SetLastNtError(Status);
- DC_UnlockDc(dc);
- return FALSE;
- }
-
- DC_UnlockDc(dc);
+
+ if (!NT_SUCCESS(Status))
+ {
+ SetLastNtError(Status);
+ Ret = FALSE;
+ }
+ }
+
+ DC_UnlockDc(pdc);
return Ret;
}