2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 IntEngEnter(PINTENG_ENTER_LEAVE EnterLeave
,
38 RECTL ClippedDestRect
;
41 if (DestRect
->right
< DestRect
->left
)
43 Exchange
= DestRect
->left
;
44 DestRect
->left
= DestRect
->right
;
45 DestRect
->right
= Exchange
;
47 if (DestRect
->bottom
< DestRect
->top
)
49 Exchange
= DestRect
->top
;
50 DestRect
->top
= DestRect
->bottom
;
51 DestRect
->bottom
= Exchange
;
54 if (NULL
!= DestObj
&& STYPE_BITMAP
!= DestObj
->iType
&&
55 (NULL
== DestObj
->pvScan0
|| 0 == DestObj
->lDelta
))
57 /* Driver needs to support DrvCopyBits, else we can't do anything */
58 /* FIXME: Remove typecast! */
59 if (!(((BITMAPOBJ
*)DestObj
)->flHooks
& HOOK_COPYBITS
))
64 /* Allocate a temporary bitmap */
65 BitmapSize
.cx
= DestRect
->right
- DestRect
->left
;
66 BitmapSize
.cy
= DestRect
->bottom
- DestRect
->top
;
67 Width
= DIB_GetDIBWidthBytes(BitmapSize
.cx
, BitsPerFormat(DestObj
->iBitmapFormat
));
68 EnterLeave
->OutputBitmap
= EngCreateBitmap(BitmapSize
, Width
,
69 DestObj
->iBitmapFormat
,
70 BMF_TOPDOWN
| BMF_NOZEROINIT
, NULL
);
71 *OutputObj
= EngLockSurface((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 (DestObj
->sizlBitmap
.cx
< SrcPoint
.x
+ ClippedDestRect
.right
- ClippedDestRect
.left
)
87 ClippedDestRect
.right
= ClippedDestRect
.left
+ DestObj
->sizlBitmap
.cx
- SrcPoint
.x
;
91 ClippedDestRect
.top
-= SrcPoint
.y
;
94 if (DestObj
->sizlBitmap
.cy
< SrcPoint
.y
+ ClippedDestRect
.bottom
- ClippedDestRect
.top
)
96 ClippedDestRect
.bottom
= ClippedDestRect
.top
+ DestObj
->sizlBitmap
.cy
- SrcPoint
.y
;
98 EnterLeave
->TrivialClipObj
= EngCreateClip();
99 EnterLeave
->TrivialClipObj
->iDComplexity
= DC_TRIVIAL
;
100 if (ClippedDestRect
.left
< (*OutputObj
)->sizlBitmap
.cx
&&
101 0 <= ClippedDestRect
.right
&&
102 SrcPoint
.x
< DestObj
->sizlBitmap
.cx
&&
103 ClippedDestRect
.top
<= (*OutputObj
)->sizlBitmap
.cy
&&
104 0 <= ClippedDestRect
.bottom
&&
105 SrcPoint
.y
< DestObj
->sizlBitmap
.cy
&&
106 ! GDIDEVFUNCS(DestObj
).CopyBits(
108 EnterLeave
->TrivialClipObj
, NULL
,
109 &ClippedDestRect
, &SrcPoint
))
111 EngDeleteClip(EnterLeave
->TrivialClipObj
);
112 EngFreeMem((*OutputObj
)->pvBits
);
113 EngUnlockSurface(*OutputObj
);
114 EngDeleteSurface((HSURF
)EnterLeave
->OutputBitmap
);
117 EnterLeave
->DestRect
.left
= DestRect
->left
;
118 EnterLeave
->DestRect
.top
= DestRect
->top
;
119 EnterLeave
->DestRect
.right
= DestRect
->right
;
120 EnterLeave
->DestRect
.bottom
= DestRect
->bottom
;
121 Translate
->x
= - DestRect
->left
;
122 Translate
->y
= - DestRect
->top
;
128 *OutputObj
= DestObj
;
131 if (NULL
!= *OutputObj
132 && 0 != (((BITMAPOBJ
*) *OutputObj
)->flHooks
& HOOK_SYNCHRONIZE
))
134 if (NULL
!= GDIDEVFUNCS(*OutputObj
).SynchronizeSurface
)
136 GDIDEVFUNCS(*OutputObj
).SynchronizeSurface(*OutputObj
, DestRect
, 0);
138 else if (STYPE_BITMAP
== (*OutputObj
)->iType
139 && NULL
!= GDIDEVFUNCS(*OutputObj
).Synchronize
)
141 GDIDEVFUNCS(*OutputObj
).Synchronize((*OutputObj
)->dhpdev
, DestRect
);
145 EnterLeave
->DestObj
= DestObj
;
146 EnterLeave
->OutputObj
= *OutputObj
;
147 EnterLeave
->ReadOnly
= ReadOnly
;
153 IntEngLeave(PINTENG_ENTER_LEAVE EnterLeave
)
158 if (EnterLeave
->OutputObj
!= EnterLeave
->DestObj
&& NULL
!= EnterLeave
->OutputObj
)
160 if (! EnterLeave
->ReadOnly
)
164 if (EnterLeave
->DestRect
.left
< 0)
166 SrcPoint
.x
= - EnterLeave
->DestRect
.left
;
167 EnterLeave
->DestRect
.left
= 0;
169 if (EnterLeave
->DestObj
->sizlBitmap
.cx
< EnterLeave
->DestRect
.right
)
171 EnterLeave
->DestRect
.right
= EnterLeave
->DestObj
->sizlBitmap
.cx
;
173 if (EnterLeave
->DestRect
.top
< 0)
175 SrcPoint
.y
= - EnterLeave
->DestRect
.top
;
176 EnterLeave
->DestRect
.top
= 0;
178 if (EnterLeave
->DestObj
->sizlBitmap
.cy
< EnterLeave
->DestRect
.bottom
)
180 EnterLeave
->DestRect
.bottom
= EnterLeave
->DestObj
->sizlBitmap
.cy
;
182 if (SrcPoint
.x
< EnterLeave
->OutputObj
->sizlBitmap
.cx
&&
183 EnterLeave
->DestRect
.left
<= EnterLeave
->DestRect
.right
&&
184 EnterLeave
->DestRect
.left
< EnterLeave
->DestObj
->sizlBitmap
.cx
&&
185 SrcPoint
.y
< EnterLeave
->OutputObj
->sizlBitmap
.cy
&&
186 EnterLeave
->DestRect
.top
<= EnterLeave
->DestRect
.bottom
&&
187 EnterLeave
->DestRect
.top
< EnterLeave
->DestObj
->sizlBitmap
.cy
)
189 Result
= GDIDEVFUNCS(EnterLeave
->DestObj
).CopyBits(
191 EnterLeave
->OutputObj
,
192 EnterLeave
->TrivialClipObj
, NULL
,
193 &EnterLeave
->DestRect
, &SrcPoint
);
200 EngFreeMem(EnterLeave
->OutputObj
->pvBits
);
201 EngUnlockSurface(EnterLeave
->OutputObj
);
202 EngDeleteSurface((HSURF
)EnterLeave
->OutputBitmap
);
203 EngDeleteClip(EnterLeave
->TrivialClipObj
);
214 EngGetCurrentProcessId(VOID
)
216 /* http://www.osr.com/ddk/graphics/gdifncs_5ovb.htm */
217 return PsGetCurrentProcessId();
221 EngGetCurrentThreadId(VOID
)
223 /* http://www.osr.com/ddk/graphics/gdifncs_25rb.htm */
224 return PsGetCurrentThreadId();
228 EngGetProcessHandle(VOID
)
230 /* http://www.osr.com/ddk/graphics/gdifncs_3tif.htm
231 In Windows 2000 and later, the EngGetProcessHandle function always returns NULL.
232 FIXME - what does NT4 return? */