[WIN32K] More cleanup & improvements

Use FLOATOBJs to perform device<->world transformations, avoiding use of XFORMOBJ all the time
Remove unused macros & functions
This commit is contained in:
Jérôme Gardou 2021-03-17 18:43:59 +01:00 committed by Jérôme Gardou
parent 3bad3c49e1
commit 405ce53211
5 changed files with 96 additions and 144 deletions

View file

@ -416,11 +416,11 @@ NtGdiTransformPoints(
switch (iMode)
{
case GdiDpToLp:
DC_vXformDeviceToWorld(pdc, Count, Points, Points);
ret = INTERNAL_APPLY_MATRIX(DC_pmxDeviceToWorld(pdc), Points, Count);
break;
case GdiLpToDp:
DC_vXformWorldToDevice(pdc, Count, Points, Points);
ret = INTERNAL_APPLY_MATRIX(DC_pmxWorldToDevice(pdc), Points, Count);
break;
case 2: // Not supported yet. Need testing.
@ -432,17 +432,20 @@ NtGdiTransformPoints(
}
}
_SEH2_TRY
if (ret)
{
/* Pointer was already probed! */
RtlCopyMemory(UnsafePtOut, Points, Size);
_SEH2_TRY
{
/* Pointer was already probed! */
RtlCopyMemory(UnsafePtOut, Points, Size);
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
/* Do not set last error */
ret = FALSE;
}
_SEH2_END;
}
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
{
/* Do not set last error */
ret = 0;
}
_SEH2_END;
//
// If we are getting called that means User XForms is a mess!
@ -866,22 +869,22 @@ IntGdiSetMapMode(
break;
case MM_LOENGLISH:
pdcattr->szlWindowExt.cx = MulDiv(1000, pdcattr->szlVirtualDeviceMm.cx, 254);
pdcattr->szlWindowExt.cy = MulDiv(1000, pdcattr->szlVirtualDeviceMm.cy, 254);
pdcattr->szlWindowExt.cx = EngMulDiv(1000, pdcattr->szlVirtualDeviceMm.cx, 254);
pdcattr->szlWindowExt.cy = EngMulDiv(1000, pdcattr->szlVirtualDeviceMm.cy, 254);
pdcattr->szlViewportExt.cx = pdcattr->szlVirtualDevicePixel.cx;
pdcattr->szlViewportExt.cy = -pdcattr->szlVirtualDevicePixel.cy;
break;
case MM_HIENGLISH:
pdcattr->szlWindowExt.cx = MulDiv(10000, pdcattr->szlVirtualDeviceMm.cx, 254);
pdcattr->szlWindowExt.cy = MulDiv(10000, pdcattr->szlVirtualDeviceMm.cy, 254);
pdcattr->szlWindowExt.cx = EngMulDiv(10000, pdcattr->szlVirtualDeviceMm.cx, 254);
pdcattr->szlWindowExt.cy = EngMulDiv(10000, pdcattr->szlVirtualDeviceMm.cy, 254);
pdcattr->szlViewportExt.cx = pdcattr->szlVirtualDevicePixel.cx;
pdcattr->szlViewportExt.cy = -pdcattr->szlVirtualDevicePixel.cy;
break;
case MM_TWIPS:
pdcattr->szlWindowExt.cx = MulDiv(14400, pdcattr->szlVirtualDeviceMm.cx, 254);
pdcattr->szlWindowExt.cy = MulDiv(14400, pdcattr->szlVirtualDeviceMm.cy, 254);
pdcattr->szlWindowExt.cx = EngMulDiv(14400, pdcattr->szlVirtualDeviceMm.cx, 254);
pdcattr->szlWindowExt.cy = EngMulDiv(14400, pdcattr->szlVirtualDeviceMm.cy, 254);
pdcattr->szlViewportExt.cx = pdcattr->szlVirtualDevicePixel.cx;
pdcattr->szlViewportExt.cy = -pdcattr->szlVirtualDevicePixel.cy;
break;

View file

@ -4,21 +4,58 @@
#define MIN_COORD (INT_MIN / 16)
#define MAX_COORD (INT_MAX / 16)
#define IntLPtoDP(pdc, ppt, count) do { \
DC_vUpdateWorldToDevice(pdc); \
INTERNAL_LPTODP(pdc, ppt, count); \
} while (0)
#define CoordLPtoDP(pdc, ppt) \
DC_vXformWorldToDevice(pdc, 1, (PPOINTL)(ppt), (PPOINTL)(ppt));
#define IntDPtoLP(pdc, ppt, count) do { \
DC_vUpdateDeviceToWorld(pdc); \
DC_vXformDeviceToWorld(pdc, count, (PPOINTL)(ppt), (PPOINTL)(ppt)); \
} while (0)
#define CoordDPtoLP(pdc, ppt) \
DC_vXformDeviceToWorld(pdc, 1, (PPOINTL)(ppt), (PPOINTL)(ppt));
/*
* Applies matrix (which is made of FLOATOBJs) to the points array, which are made of integers.
*/
static
inline
BOOLEAN
INTERNAL_APPLY_MATRIX(PMATRIX matrix, LPPOINT points, UINT count)
{
while (count--)
{
FLOATOBJ x, y;
FLOATOBJ tmp;
#define XForm2MatrixS(m, x) XFormToMatrix(m, (XFORML*)x)
#define MatrixS2XForm(x, m) MatrixToXForm((XFORML*)x, m)
/* x = x * matrix->efM11 + y * matrix->efM21 + matrix->efDx; */
FLOATOBJ_SetLong(&x, points[count].x);
FLOATOBJ_Mul(&x, &matrix->efM11);
tmp = matrix->efM21;
FLOATOBJ_MulLong(&tmp, points[count].y);
FLOATOBJ_Add(&x, &tmp);
FLOATOBJ_Add(&x, &matrix->efDx);
/* y = x * matrix->efM12 + y * matrix->efM22 + matrix->efDy; */
FLOATOBJ_SetLong(&y, points[count].y);
FLOATOBJ_Mul(&y, &matrix->efM22);
tmp = matrix->efM12;
FLOATOBJ_MulLong(&tmp, points[count].x);
FLOATOBJ_Add(&y, &tmp);
FLOATOBJ_Add(&y, &matrix->efDy);
if (!FLOATOBJ_bConvertToLong(&x, &points[count].x))
return FALSE;
if (!FLOATOBJ_bConvertToLong(&y, &points[count].y))
return FALSE;
}
return TRUE;
}
static
inline
BOOLEAN
INTERNAL_LPTODP(DC *dc, LPPOINT points, UINT count)
{
return INTERNAL_APPLY_MATRIX(&dc->pdcattr->mxWorldToDevice, points, count);
}
static
inline
BOOLEAN
INTERNAL_DPTOLP(DC *dc, LPPOINT points, UINT count)
{
return INTERNAL_APPLY_MATRIX(&dc->pdcattr->mxDeviceToWorld, points, count);
}
FORCEINLINE
void
@ -121,41 +158,6 @@ DC_pmxDeviceToWorld(PDC pdc)
return &pdc->pdcattr->mxDeviceToWorld;
}
FORCEINLINE
VOID
DC_vXformDeviceToWorld(
IN PDC pdc,
IN ULONG cNumPoints,
OUT PPOINTL pptlDest,
IN PPOINTL pptlSource)
{
XFORMOBJ xo;
PMATRIX pmx;
pmx = DC_pmxDeviceToWorld(pdc);
if (!MX_IsInvertible(pmx))
return;
XFORMOBJ_vInit(&xo, pmx);
XFORMOBJ_bApplyXform(&xo, XF_LTOL, cNumPoints, pptlDest, pptlSource);
}
FORCEINLINE
VOID
DC_vXformWorldToDevice(
IN PDC pdc,
IN ULONG cNumPoints,
OUT PPOINTL pptlDest,
IN PPOINTL pptlSource)
{
XFORMOBJ xo;
PMATRIX pmx;
pmx = DC_pmxWorldToDevice(pdc);
XFORMOBJ_vInit(&xo, pmx);
XFORMOBJ_bApplyXform(&xo, XF_LTOL, cNumPoints, pptlDest, pptlSource);
}
BOOL
NTAPI
GreModifyWorldTransform(
@ -173,3 +175,26 @@ BOOL WINAPI GreGetViewportExtEx( _In_ HDC hdc, _Out_ LPSIZE lpSize);
BOOL FASTCALL GreSetViewportOrgEx(HDC,int,int,LPPOINT);
BOOL WINAPI GreGetDCOrgEx(_In_ HDC, _Out_ PPOINTL, _Out_ PRECTL);
BOOL WINAPI GreSetDCOrg(_In_ HDC, _In_ LONG, _In_ LONG, _In_opt_ PRECTL);
static
inline
BOOLEAN
IntLPtoDP(DC* pdc, PPOINTL ppt, UINT count)
{
DC_vUpdateWorldToDevice(pdc);
return INTERNAL_LPTODP(pdc, (LPPOINT)ppt, count);
}
#define CoordLPtoDP(pdc, ppt) INTERNAL_LPTODP(pdc, ppt, 1)
static
inline
BOOLEAN
IntDPtoLP(DC* pdc, PPOINTL ppt, UINT count)
{
DC_vUpdateDeviceToWorld(pdc);
return INTERNAL_DPTOLP(pdc, (LPPOINT)ppt, count);
}
#define CoordDPtoLP(pdc, ppt) INTERNAL_DPTOLP(pdc, ppt, 1)
#define XForm2MatrixS(m, x) XFormToMatrix(m, (XFORML*)x)
#define MatrixS2XForm(x, m) MatrixToXForm((XFORML*)x, m)

View file

@ -743,7 +743,7 @@ NtGdiGetBoundsRect(
DPRINT(" r %d b %d\n",rc.right,rc.bottom);
ret = DCB_SET;
}
IntDPtoLP( pdc, &rc, 2 );
IntDPtoLP(pdc, (PPOINTL)&rc, 2);
DPRINT("rc1 l %d t %d\n",rc.left,rc.top);
DPRINT(" r %d b %d\n",rc.right,rc.bottom);
}
@ -838,7 +838,7 @@ NtGdiSetBoundsRect(
RECTL_vMakeWellOrdered(&rcl);
if (!(flags & DCB_WINDOWMGR))
{
{
IntLPtoDP( pdc, (POINT *)&rcl, 2 );
RECTL_bUnionRect(&pdc->erclBoundsApp, &pdc->erclBoundsApp, &rcl);
}

View file

@ -1,75 +0,0 @@
#pragma once
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable:28110) // disable "Drivers must protect floating point hardware state" warning
#endif
static __inline INT GDI_ROUND(FLOAT val)
{
return (int)floor(val + 0.5);
}
/*
* Performs a world-to-viewport transformation on the specified point,
* which is in integer format.
*/
static
inline
VOID
INTERNAL_LPTODP(DC *dc, LPPOINT point, UINT Count)
{
MATRIX* WorldToDevice = &dc->pdcattr->mxWorldToDevice;
while (Count--)
{
FLOATOBJ x, y;
FLOATOBJ tmp;
/* x = x * mxWorldToDevice.efM11 + y * mxWorldToDevice.efM21 + mxWorldToDevice.efDx; */
FLOATOBJ_SetLong(&x, point[Count].x);
FLOATOBJ_Mul(&x, &WorldToDevice->efM11);
tmp = WorldToDevice->efM21;
FLOATOBJ_MulLong(&tmp, point[Count].y);
FLOATOBJ_Add(&x, &tmp);
FLOATOBJ_Add(&x, &WorldToDevice->efDx);
/* y = x * mxWorldToDevice.efM12 + y * mxWorldToDevice.efM22 + mxWorldToDevice.efDy; */
FLOATOBJ_SetLong(&y, point[Count].y);
FLOATOBJ_Mul(&y, &WorldToDevice->efM22);
tmp = WorldToDevice->efM12;
FLOATOBJ_MulLong(&tmp, point[Count].x);
FLOATOBJ_Add(&y, &tmp);
FLOATOBJ_Add(&y, &WorldToDevice->efDy);
point[Count].x = FLOATOBJ_GetLong(&x);
point[Count].y = FLOATOBJ_GetLong(&y);
}
}
#define MulDiv( x, y, z ) EngMulDiv( x, y, z )
#define XDPTOLP(pdcattr,tx) \
(MulDiv(((tx)-(pdcattr)->ptlViewportOrg.x), (pdcattr)->szlWindowExt.cx, (pdcattr)->szlViewportExt.cx) + (pdcattr)->ptlWindowOrg.x)
#define YDPTOLP(pdcattr,ty) \
(MulDiv(((ty)-(pdcattr)->ptlViewportOrg.y), (pdcattr)->szlWindowExt.cy, (pdcattr)->szlViewportExt.cy) + (pdcattr)->ptlWindowOrg.y)
#define XLPTODP(pdcattr,tx) \
(MulDiv(((tx)-(pdcattr)->ptlWindowOrg.x), (pdcattr)->szlViewportExt.cx, (pdcattr)->szlWindowExt.cx) + (pdcattr)->ptlViewportOrg.x)
#define YLPTODP(pdcattr,ty) \
(MulDiv(((ty)-(pdcattr)->ptlWindowOrg.y), (pdcattr)->szlViewportExt.cy, (pdcattr)->szlWindowExt.cy) + (pdcattr)->ptlViewportOrg.y)
/* Device <-> logical size conversion */
#define XDSTOLS(pdcattr,tx) \
MulDiv((tx), (pdcattr)->szlWindowExt.cx, (pdcattr)->szlViewportExt.cx)
#define YDSTOLS(DC_Attr,ty) \
MulDiv((ty), (pdcattr)->szlWindowExt.cy, (pdcattr)->szlViewportExt.cy)
#define XLSTODS(pdcattr,tx) \
MulDiv((tx), (pdcattr)->szlViewportExt.cx, (pdcattr)->szlWindowExt.cx)
#define YLSTODS(pdcattr,ty) \
MulDiv((ty), (pdcattr)->szlViewportExt.cy, (pdcattr)->szlWindowExt.cy)
#ifdef _MSC_VER
#pragma warning(pop)
#endif

View file

@ -49,7 +49,6 @@ typedef struct _DC *PDC;
#include "gdi/ntgdi/pen.h"
#include "gdi/ntgdi/cliprgn.h"
#include "gdi/ntgdi/coord.h"
#include "gdi/ntgdi/gdifloat.h"
#include "gdi/ntgdi/path.h"
#include "gdi/dib/dib.h"
#include "reactx/ntddraw/intddraw.h"