3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS kernel
5 * PURPOSE: Coordinate systems
6 * FILE: subsys/win32k/objects/coord.c
10 /* INCLUDES ******************************************************************/
13 #include <ddk/ntddk.h>
14 #include <internal/safe.h>
15 #include <win32k/coord.h>
16 #include <win32k/dc.h>
18 #include <win32k/debug1.h>
20 /* FUNCTIONS *****************************************************************/
22 BOOL STDCALL W32kCombineTransform(LPXFORM UnsafeXFormResult,
23 CONST LPXFORM Unsafexform1,
24 CONST LPXFORM Unsafexform2)
29 /* Check for illegal parameters */
30 if (!UnsafeXFormResult || !Unsafexform1 || !Unsafexform2)
35 MmCopyFromCaller( &xform1, Unsafexform1, sizeof(XFORM) );
36 MmCopyFromCaller( &xform2, Unsafexform2, sizeof(XFORM) );
38 /* Create the result in a temporary XFORM, since xformResult may be
39 * equal to xform1 or xform2 */
40 xformTemp.eM11 = xform1.eM11 * xform2.eM11 + xform1.eM12 * xform2.eM21;
41 xformTemp.eM12 = xform1.eM11 * xform2.eM12 + xform1.eM12 * xform2.eM22;
42 xformTemp.eM21 = xform1.eM21 * xform2.eM11 + xform1.eM22 * xform2.eM21;
43 xformTemp.eM22 = xform1.eM21 * xform2.eM12 + xform1.eM22 * xform2.eM22;
44 xformTemp.eDx = xform1.eDx * xform2.eM11 + xform1.eDy * xform2.eM21 + xform2.eDx;
45 xformTemp.eDy = xform1.eDx * xform2.eM12 + xform1.eDy * xform2.eM22 + xform2.eDy;
47 /* Copy the result to xformResult */
48 MmCopyToCaller( UnsafeXFormResult, &xformTemp, sizeof(XFORM) );
54 CoordDPtoLP(PDC Dc, LPPOINT Point)
59 Point->x = x * Dc->w.xformVport2World.eM11 +
60 y * Dc->w.xformVport2World.eM21 + Dc->w.xformVport2World.eDx;
61 Point->y = x * Dc->w.xformVport2World.eM12 +
62 y * Dc->w.xformVport2World.eM22 + Dc->w.xformVport2World.eDy;
66 * Converts points from device coordinates into logical coordinates. Conversion depends on the mapping mode,
67 * world transfrom, viewport origin settings for the given device context.
68 * \param hDC device context.
69 * \param Points an array of POINT structures (in/out).
70 * \param Count number of elements in the array of POINT structures.
71 * \return TRUE if success.
80 LPPOINT Points = (LPPOINT) ExAllocatePool( PagedPool, Count*sizeof(POINT));
83 MmCopyFromCaller( Points, UnsafePoints, Count*sizeof(POINT) );
85 Dc = DC_HandleToPtr (hDC);
86 if (Dc == NULL || !Dc->w.vport2WorldValid)
91 for (i = 0; i < Count; i++)
93 CoordDPtoLP(Dc, &Points[i]);
97 MmCopyToCaller( UnsafePoints, Points, Count*sizeof(POINT) );
103 W32kGetGraphicsMode(HDC hDC)
108 dc = DC_HandleToPtr (hDC);
114 GraphicsMode = dc->w.GraphicsMode;
115 DC_ReleasePtr( hDC );
121 W32kGetWorldTransform(HDC hDC,
126 dc = DC_HandleToPtr (hDC);
135 *XForm = dc->w.xformWorld2Wnd;
136 DC_ReleasePtr( hDC );
141 CoordLPtoDP(PDC Dc, LPPOINT Point)
146 Point->x = x * Dc->w.xformWorld2Vport.eM11 +
147 y * Dc->w.xformWorld2Vport.eM21 + Dc->w.xformWorld2Vport.eDx;
148 Point->y = x * Dc->w.xformWorld2Vport.eM12 +
149 y * Dc->w.xformWorld2Vport.eM22 + Dc->w.xformWorld2Vport.eDy;
153 * Converts points from logical coordinates into device coordinates. Conversion depends on the mapping mode,
154 * world transfrom, viewport origin settings for the given device context.
155 * \param hDC device context.
156 * \param Points an array of POINT structures (in/out).
157 * \param Count number of elements in the array of POINT structures.
158 * \return TRUE if success.
161 W32kLPtoDP(HDC hDC, LPPOINT UnsafePoints, INT Count)
165 LPPOINT Points = (LPPOINT) ExAllocatePool( PagedPool, Count*sizeof(POINT));
168 MmCopyFromCaller( Points, UnsafePoints, Count*sizeof(POINT) );
170 Dc = DC_HandleToPtr (hDC);
176 for (i = 0; i < Count; i++)
178 CoordLPtoDP(Dc, &Points[i]);
180 DC_ReleasePtr( hDC );
181 MmCopyToCaller( UnsafePoints, Points, Count*sizeof(POINT) );
187 W32kModifyWorldTransform(HDC hDC,
188 CONST LPXFORM UnsafeXForm,
192 LPXFORM XForm = (LPXFORM) ExAllocatePool( PagedPool, sizeof( XFORM ) );
196 MmCopyFromCaller( XForm, UnsafeXForm, sizeof( XFORM ) );
198 dc = DC_HandleToPtr (hDC);
201 // SetLastError( ERROR_INVALID_HANDLE );
209 /* Check that graphics mode is GM_ADVANCED */
210 if (dc->w.GraphicsMode!=GM_ADVANCED)
217 dc->w.xformWorld2Wnd.eM11 = 1.0f;
218 dc->w.xformWorld2Wnd.eM12 = 0.0f;
219 dc->w.xformWorld2Wnd.eM21 = 0.0f;
220 dc->w.xformWorld2Wnd.eM22 = 1.0f;
221 dc->w.xformWorld2Wnd.eDx = 0.0f;
222 dc->w.xformWorld2Wnd.eDy = 0.0f;
225 case MWT_LEFTMULTIPLY:
226 W32kCombineTransform(&dc->w.xformWorld2Wnd, XForm, &dc->w.xformWorld2Wnd );
229 case MWT_RIGHTMULTIPLY:
230 W32kCombineTransform(&dc->w.xformWorld2Wnd, &dc->w.xformWorld2Wnd, XForm);
234 DC_ReleasePtr( hDC );
237 DC_UpdateXforms (dc);
238 DC_ReleasePtr( hDC );
244 W32kOffsetViewportOrgEx(HDC hDC,
254 W32kOffsetWindowOrgEx(HDC hDC,
264 W32kScaleViewportExtEx(HDC hDC,
276 W32kScaleWindowExtEx(HDC hDC,
288 W32kSetGraphicsMode(HDC hDC,
294 dc = DC_HandleToPtr (hDC);
300 /* One would think that setting the graphics mode to GM_COMPATIBLE
301 * would also reset the world transformation matrix to the unity
302 * matrix. However, in Windows, this is not the case. This doesn't
303 * make a lot of sense to me, but that's the way it is.
306 if ((Mode != GM_COMPATIBLE) && (Mode != GM_ADVANCED))
308 DC_ReleasePtr( hDC );
311 ret = dc->w.GraphicsMode;
312 dc->w.GraphicsMode = Mode;
313 DC_ReleasePtr( hDC );
319 W32kSetMapMode(HDC hDC,
327 W32kSetViewportExtEx(HDC hDC,
337 W32kSetViewportOrgEx(HDC hDC,
347 W32kSetWindowExtEx(HDC hDC,
357 W32kSetWindowOrgEx(HDC hDC,
367 W32kSetWorldTransform(HDC hDC,
372 dc = DC_HandleToPtr (hDC);
379 DC_ReleasePtr( hDC );
383 /* Check that graphics mode is GM_ADVANCED */
384 if (dc->w.GraphicsMode != GM_ADVANCED)
386 DC_ReleasePtr( hDC );
389 dc->w.xformWorld2Wnd = *XForm;
390 DC_UpdateXforms (dc);
391 DC_ReleasePtr( hDC );