- Rename some files for MSVC compatibility. Thanks Brezenbak.
[reactos.git] / reactos / subsys / win32k / eng / engmisc.c
1 /*
2 * ReactOS W32 Subsystem
3 * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
4 *
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.
9 *
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.
14 *
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.
18 */
19 /* $Id$ */
20
21 #include <w32k.h>
22
23 #define NDEBUG
24 #include <debug.h>
25
26 BOOL STDCALL
27 IntEngEnter(PINTENG_ENTER_LEAVE EnterLeave,
28 SURFOBJ *DestObj,
29 RECTL *DestRect,
30 BOOL ReadOnly,
31 POINTL *Translate,
32 SURFOBJ **OutputObj)
33 {
34 LONG Exchange;
35 SIZEL BitmapSize;
36 POINTL SrcPoint;
37 LONG Width;
38 RECTL ClippedDestRect;
39
40 /* Normalize */
41 if (DestRect->right < DestRect->left)
42 {
43 Exchange = DestRect->left;
44 DestRect->left = DestRect->right;
45 DestRect->right = Exchange;
46 }
47 if (DestRect->bottom < DestRect->top)
48 {
49 Exchange = DestRect->top;
50 DestRect->top = DestRect->bottom;
51 DestRect->bottom = Exchange;
52 }
53
54 if (NULL != DestObj && STYPE_BITMAP != DestObj->iType &&
55 (NULL == DestObj->pvScan0 || 0 == DestObj->lDelta))
56 {
57 /* Driver needs to support DrvCopyBits, else we can't do anything */
58 /* FIXME: Remove typecast! */
59 if (!(((BITMAPOBJ*)DestObj)->flHooks & HOOK_COPYBITS))
60 {
61 return FALSE;
62 }
63
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);
72
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;
80 if (SrcPoint.x < 0)
81 {
82 ClippedDestRect.left -= SrcPoint.x;
83 SrcPoint.x = 0;
84 }
85 if (DestObj->sizlBitmap.cx < SrcPoint.x + ClippedDestRect.right - ClippedDestRect.left)
86 {
87 ClippedDestRect.right = ClippedDestRect.left + DestObj->sizlBitmap.cx - SrcPoint.x;
88 }
89 if (SrcPoint.y < 0)
90 {
91 ClippedDestRect.top -= SrcPoint.y;
92 SrcPoint.y = 0;
93 }
94 if (DestObj->sizlBitmap.cy < SrcPoint.y + ClippedDestRect.bottom - ClippedDestRect.top)
95 {
96 ClippedDestRect.bottom = ClippedDestRect.top + DestObj->sizlBitmap.cy - SrcPoint.y;
97 }
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(
107 *OutputObj, DestObj,
108 EnterLeave->TrivialClipObj, NULL,
109 &ClippedDestRect, &SrcPoint))
110 {
111 EngDeleteClip(EnterLeave->TrivialClipObj);
112 EngFreeMem((*OutputObj)->pvBits);
113 EngUnlockSurface(*OutputObj);
114 EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
115 return FALSE;
116 }
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;
123 }
124 else
125 {
126 Translate->x = 0;
127 Translate->y = 0;
128 *OutputObj = DestObj;
129 }
130
131 if (NULL != *OutputObj
132 && 0 != (((BITMAPOBJ*) *OutputObj)->flHooks & HOOK_SYNCHRONIZE))
133 {
134 if (NULL != GDIDEVFUNCS(*OutputObj).SynchronizeSurface)
135 {
136 GDIDEVFUNCS(*OutputObj).SynchronizeSurface(*OutputObj, DestRect, 0);
137 }
138 else if (STYPE_BITMAP == (*OutputObj)->iType
139 && NULL != GDIDEVFUNCS(*OutputObj).Synchronize)
140 {
141 GDIDEVFUNCS(*OutputObj).Synchronize((*OutputObj)->dhpdev, DestRect);
142 }
143 }
144
145 EnterLeave->DestObj = DestObj;
146 EnterLeave->OutputObj = *OutputObj;
147 EnterLeave->ReadOnly = ReadOnly;
148
149 return TRUE;
150 }
151
152 BOOL STDCALL
153 IntEngLeave(PINTENG_ENTER_LEAVE EnterLeave)
154 {
155 POINTL SrcPoint;
156 BOOL Result = TRUE;
157
158 if (EnterLeave->OutputObj != EnterLeave->DestObj && NULL != EnterLeave->OutputObj)
159 {
160 if (! EnterLeave->ReadOnly)
161 {
162 SrcPoint.x = 0;
163 SrcPoint.y = 0;
164 if (EnterLeave->DestRect.left < 0)
165 {
166 SrcPoint.x = - EnterLeave->DestRect.left;
167 EnterLeave->DestRect.left = 0;
168 }
169 if (EnterLeave->DestObj->sizlBitmap.cx < EnterLeave->DestRect.right)
170 {
171 EnterLeave->DestRect.right = EnterLeave->DestObj->sizlBitmap.cx;
172 }
173 if (EnterLeave->DestRect.top < 0)
174 {
175 SrcPoint.y = - EnterLeave->DestRect.top;
176 EnterLeave->DestRect.top = 0;
177 }
178 if (EnterLeave->DestObj->sizlBitmap.cy < EnterLeave->DestRect.bottom)
179 {
180 EnterLeave->DestRect.bottom = EnterLeave->DestObj->sizlBitmap.cy;
181 }
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)
188 {
189 Result = GDIDEVFUNCS(EnterLeave->DestObj).CopyBits(
190 EnterLeave->DestObj,
191 EnterLeave->OutputObj,
192 EnterLeave->TrivialClipObj, NULL,
193 &EnterLeave->DestRect, &SrcPoint);
194 }
195 else
196 {
197 Result = TRUE;
198 }
199 }
200 EngFreeMem(EnterLeave->OutputObj->pvBits);
201 EngUnlockSurface(EnterLeave->OutputObj);
202 EngDeleteSurface((HSURF)EnterLeave->OutputBitmap);
203 EngDeleteClip(EnterLeave->TrivialClipObj);
204 }
205 else
206 {
207 Result = TRUE;
208 }
209
210 return Result;
211 }
212
213 HANDLE STDCALL
214 EngGetCurrentProcessId(VOID)
215 {
216 /* http://www.osr.com/ddk/graphics/gdifncs_5ovb.htm */
217 return PsGetCurrentProcessId();
218 }
219
220 HANDLE STDCALL
221 EngGetCurrentThreadId(VOID)
222 {
223 /* http://www.osr.com/ddk/graphics/gdifncs_25rb.htm */
224 return PsGetCurrentThreadId();
225 }
226
227 HANDLE STDCALL
228 EngGetProcessHandle(VOID)
229 {
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? */
233 return NULL;
234 }
235
236 /* EOF */