2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS Win32k subsystem
4 * PURPOSE: ENG misc Functions
5 * FILE: subsystems/win32/win32k/eng/engmisc.c
6 * PROGRAMER: ReactOS Team
15 IntEngEnter(PINTENG_ENTER_LEAVE EnterLeave
,
26 RECTL ClippedDestRect
;
29 if (DestRect
->right
< DestRect
->left
)
31 Exchange
= DestRect
->left
;
32 DestRect
->left
= DestRect
->right
;
33 DestRect
->right
= Exchange
;
35 if (DestRect
->bottom
< DestRect
->top
)
37 Exchange
= DestRect
->top
;
38 DestRect
->top
= DestRect
->bottom
;
39 DestRect
->bottom
= Exchange
;
42 if (NULL
!= psoDest
&& STYPE_BITMAP
!= psoDest
->iType
&&
43 (NULL
== psoDest
->pvScan0
|| 0 == psoDest
->lDelta
))
45 /* Driver needs to support DrvCopyBits, else we can't do anything */
46 SURFACE
*psurfDest
= CONTAINING_RECORD(psoDest
, SURFACE
, SurfObj
);
47 if (!(psurfDest
->flags
& HOOK_COPYBITS
))
52 /* Allocate a temporary bitmap */
53 BitmapSize
.cx
= DestRect
->right
- DestRect
->left
;
54 BitmapSize
.cy
= DestRect
->bottom
- DestRect
->top
;
55 Width
= WIDTH_BYTES_ALIGN32(BitmapSize
.cx
, BitsPerFormat(psoDest
->iBitmapFormat
));
56 EnterLeave
->OutputBitmap
= EngCreateBitmap(BitmapSize
, Width
,
57 psoDest
->iBitmapFormat
,
58 BMF_TOPDOWN
| BMF_NOZEROINIT
, NULL
);
60 if (!EnterLeave
->OutputBitmap
)
62 DPRINT1("EngCreateBitmap() failed\n");
66 *ppsoOutput
= EngLockSurface((HSURF
)EnterLeave
->OutputBitmap
);
67 if (*ppsoOutput
== NULL
)
69 EngDeleteSurface((HSURF
)EnterLeave
->OutputBitmap
);
73 EnterLeave
->DestRect
.left
= 0;
74 EnterLeave
->DestRect
.top
= 0;
75 EnterLeave
->DestRect
.right
= BitmapSize
.cx
;
76 EnterLeave
->DestRect
.bottom
= BitmapSize
.cy
;
77 SrcPoint
.x
= DestRect
->left
;
78 SrcPoint
.y
= DestRect
->top
;
79 ClippedDestRect
= EnterLeave
->DestRect
;
82 ClippedDestRect
.left
-= SrcPoint
.x
;
85 if (psoDest
->sizlBitmap
.cx
< SrcPoint
.x
+ ClippedDestRect
.right
- ClippedDestRect
.left
)
87 ClippedDestRect
.right
= ClippedDestRect
.left
+ psoDest
->sizlBitmap
.cx
- SrcPoint
.x
;
91 ClippedDestRect
.top
-= SrcPoint
.y
;
94 if (psoDest
->sizlBitmap
.cy
< SrcPoint
.y
+ ClippedDestRect
.bottom
- ClippedDestRect
.top
)
96 ClippedDestRect
.bottom
= ClippedDestRect
.top
+ psoDest
->sizlBitmap
.cy
- SrcPoint
.y
;
98 EnterLeave
->TrivialClipObj
= EngCreateClip();
99 if (EnterLeave
->TrivialClipObj
== NULL
)
101 EngUnlockSurface(*ppsoOutput
);
102 EngDeleteSurface((HSURF
)EnterLeave
->OutputBitmap
);
105 EnterLeave
->TrivialClipObj
->iDComplexity
= DC_TRIVIAL
;
106 if (ClippedDestRect
.left
< (*ppsoOutput
)->sizlBitmap
.cx
&&
107 0 <= ClippedDestRect
.right
&&
108 SrcPoint
.x
< psoDest
->sizlBitmap
.cx
&&
109 ClippedDestRect
.top
<= (*ppsoOutput
)->sizlBitmap
.cy
&&
110 0 <= ClippedDestRect
.bottom
&&
111 SrcPoint
.y
< psoDest
->sizlBitmap
.cy
&&
112 ! GDIDEVFUNCS(psoDest
).CopyBits(
113 *ppsoOutput
, psoDest
,
114 EnterLeave
->TrivialClipObj
, NULL
,
115 &ClippedDestRect
, &SrcPoint
))
117 EngDeleteClip(EnterLeave
->TrivialClipObj
);
118 EngUnlockSurface(*ppsoOutput
);
119 EngDeleteSurface((HSURF
)EnterLeave
->OutputBitmap
);
122 EnterLeave
->DestRect
.left
= DestRect
->left
;
123 EnterLeave
->DestRect
.top
= DestRect
->top
;
124 EnterLeave
->DestRect
.right
= DestRect
->right
;
125 EnterLeave
->DestRect
.bottom
= DestRect
->bottom
;
126 Translate
->x
= - DestRect
->left
;
127 Translate
->y
= - DestRect
->top
;
133 *ppsoOutput
= psoDest
;
136 if (NULL
!= *ppsoOutput
)
138 SURFACE
* psurfOutput
= CONTAINING_RECORD(*ppsoOutput
, SURFACE
, SurfObj
);
139 if (0 != (psurfOutput
->flags
& HOOK_SYNCHRONIZE
))
141 if (NULL
!= GDIDEVFUNCS(*ppsoOutput
).SynchronizeSurface
)
143 GDIDEVFUNCS(*ppsoOutput
).SynchronizeSurface(*ppsoOutput
, DestRect
, 0);
145 else if (STYPE_BITMAP
== (*ppsoOutput
)->iType
146 && NULL
!= GDIDEVFUNCS(*ppsoOutput
).Synchronize
)
148 GDIDEVFUNCS(*ppsoOutput
).Synchronize((*ppsoOutput
)->dhpdev
, DestRect
);
154 EnterLeave
->DestObj
= psoDest
;
155 EnterLeave
->OutputObj
= *ppsoOutput
;
156 EnterLeave
->ReadOnly
= ReadOnly
;
162 IntEngLeave(PINTENG_ENTER_LEAVE EnterLeave
)
167 if (EnterLeave
->OutputObj
!= EnterLeave
->DestObj
&& NULL
!= EnterLeave
->OutputObj
)
169 if (! EnterLeave
->ReadOnly
)
173 if (EnterLeave
->DestRect
.left
< 0)
175 SrcPoint
.x
= - EnterLeave
->DestRect
.left
;
176 EnterLeave
->DestRect
.left
= 0;
178 if (EnterLeave
->DestObj
->sizlBitmap
.cx
< EnterLeave
->DestRect
.right
)
180 EnterLeave
->DestRect
.right
= EnterLeave
->DestObj
->sizlBitmap
.cx
;
182 if (EnterLeave
->DestRect
.top
< 0)
184 SrcPoint
.y
= - EnterLeave
->DestRect
.top
;
185 EnterLeave
->DestRect
.top
= 0;
187 if (EnterLeave
->DestObj
->sizlBitmap
.cy
< EnterLeave
->DestRect
.bottom
)
189 EnterLeave
->DestRect
.bottom
= EnterLeave
->DestObj
->sizlBitmap
.cy
;
191 if (SrcPoint
.x
< EnterLeave
->OutputObj
->sizlBitmap
.cx
&&
192 EnterLeave
->DestRect
.left
<= EnterLeave
->DestRect
.right
&&
193 EnterLeave
->DestRect
.left
< EnterLeave
->DestObj
->sizlBitmap
.cx
&&
194 SrcPoint
.y
< EnterLeave
->OutputObj
->sizlBitmap
.cy
&&
195 EnterLeave
->DestRect
.top
<= EnterLeave
->DestRect
.bottom
&&
196 EnterLeave
->DestRect
.top
< EnterLeave
->DestObj
->sizlBitmap
.cy
)
198 Result
= GDIDEVFUNCS(EnterLeave
->DestObj
).CopyBits(
200 EnterLeave
->OutputObj
,
201 EnterLeave
->TrivialClipObj
, NULL
,
202 &EnterLeave
->DestRect
, &SrcPoint
);
209 EngUnlockSurface(EnterLeave
->OutputObj
);
210 EngDeleteSurface((HSURF
)EnterLeave
->OutputBitmap
);
211 EngDeleteClip(EnterLeave
->TrivialClipObj
);
222 EngGetProcessHandle(VOID
)
224 /* http://www.osr.com/ddk/graphics/gdifncs_3tif.htm
225 In Windows 2000 and later, the EngGetProcessHandle function always returns NULL.
226 FIXME: What does NT4 return? */
232 EngGetCurrentCodePage(
233 _Out_ PUSHORT OemCodePage
,
234 _Out_ PUSHORT AnsiCodePage
)
236 /* Forward to kernel */
237 RtlGetDefaultCodePage(AnsiCodePage
, OemCodePage
);
242 EngQuerySystemAttribute(
243 _In_ ENG_SYSTEM_ATTRIBUTE CapNum
,
244 _Out_ PDWORD pCapability
)
246 SYSTEM_BASIC_INFORMATION sbi
;
247 SYSTEM_PROCESSOR_INFORMATION spi
;
251 case EngNumberOfProcessors
:
252 NtQuerySystemInformation(SystemBasicInformation
,
254 sizeof(SYSTEM_BASIC_INFORMATION
),
256 *pCapability
= sbi
.NumberOfProcessors
;
259 case EngProcessorFeature
:
260 NtQuerySystemInformation(SystemProcessorInformation
,
262 sizeof(SYSTEM_PROCESSOR_INFORMATION
),
264 *pCapability
= spi
.ProcessorFeatureBits
;
276 EngGetTickCount(VOID
)
279 LARGE_INTEGER TickCount
;
281 /* Get the multiplier and current tick count */
282 KeQueryTickCount(&TickCount
);
283 Multiplier
= SharedUserData
->TickCountMultiplier
;
285 /* Convert to milliseconds and return */
286 return (Int64ShrlMod32(UInt32x32To64(Multiplier
, TickCount
.LowPart
), 24) +
287 (Multiplier
* (TickCount
.HighPart
<< 8)));