ReactOS 0.4.15-dev-8119-g4fb2fdb
clip.c
Go to the documentation of this file.
1/*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS kernel
4 * PURPOSE: GDI Clipping Functions
5 * FILE: win32ss/gdi/eng/clip.c
6 * PROGRAMER: Jason Filby
7 */
8
9#include <win32k.h>
11
12
13static __inline int
15 const RECTL *r1,
16 const RECTL *r2)
17{
18 int Cmp;
19
20 if (r1->top < r2->top)
21 {
22 Cmp = -1;
23 }
24 else if (r2->top < r1->top)
25 {
26 Cmp = +1;
27 }
28 else
29 {
30 ASSERT(r1->bottom == r2->bottom);
31 if (r1->left < r2->left)
32 {
33 Cmp = -1;
34 }
35 else if (r2->left < r1->left)
36 {
37 Cmp = +1;
38 }
39 else
40 {
41 ASSERT(r1->right == r2->right);
42 Cmp = 0;
43 }
44 }
45
46 return Cmp;
47}
48
49static __inline int
51 const RECTL *r1,
52 const RECTL *r2)
53{
54 int Cmp;
55
56 if (r1->bottom < r2->bottom)
57 {
58 Cmp = +1;
59 }
60 else if (r2->bottom < r1->bottom)
61 {
62 Cmp = -1;
63 }
64 else
65 {
66 ASSERT(r1->top == r2->top);
67 if (r1->left < r2->left)
68 {
69 Cmp = -1;
70 }
71 else if (r2->left < r1->left)
72 {
73 Cmp = +1;
74 }
75 else
76 {
77 ASSERT(r1->right == r2->right);
78 Cmp = 0;
79 }
80 }
81
82 return Cmp;
83}
84
85static __inline int
87 const RECTL *r1,
88 const RECTL *r2)
89{
90 int Cmp;
91
92 if (r1->top < r2->top)
93 {
94 Cmp = -1;
95 }
96 else if (r2->top < r1->top)
97 {
98 Cmp = +1;
99 }
100 else
101 {
102 ASSERT(r1->bottom == r2->bottom);
103 if (r1->right < r2->right)
104 {
105 Cmp = +1;
106 }
107 else if (r2->right < r1->right)
108 {
109 Cmp = -1;
110 }
111 else
112 {
113 ASSERT(r1->left == r2->left);
114 Cmp = 0;
115 }
116 }
117
118 return Cmp;
119}
120
121static __inline int
123 const RECTL *r1,
124 const RECTL *r2)
125{
126 int Cmp;
127
128 if (r1->bottom < r2->bottom)
129 {
130 Cmp = +1;
131 }
132 else if (r2->bottom < r1->bottom)
133 {
134 Cmp = -1;
135 }
136 else
137 {
138 ASSERT(r1->top == r2->top);
139 if (r1->right < r2->right)
140 {
141 Cmp = +1;
142 }
143 else if (r2->right < r1->right)
144 {
145 Cmp = -1;
146 }
147 else
148 {
149 ASSERT(r1->left == r2->left);
150 Cmp = 0;
151 }
152 }
153 return Cmp;
154}
155
156VOID
159{
160 Clip->Rects = &Clip->rclBounds;
161}
162
165{
166 if (Clip->Rects != &Clip->rclBounds)
167 EngFreeMem(Clip->Rects);
168}
169
170
171VOID
174 XCLIPOBJ* Clip,
175 ULONG count,
176 const RECTL* pRect,
177 const RECTL* rcBounds)
178{
179 if(count > 1)
180 {
182
183 if(NewRects != NULL)
184 {
185 Clip->RectCount = count;
186 Clip->iDirection = CD_ANY;
187 RtlCopyMemory(NewRects, pRect, count * sizeof(RECTL));
188
189 Clip->iDComplexity = DC_COMPLEX;
190 Clip->iFComplexity = ((Clip->RectCount <= 4) ? FC_RECT4 : FC_COMPLEX);
191 Clip->iMode = TC_RECTANGLES;
192 Clip->rclBounds = *rcBounds;
193
194 if (Clip->Rects != &Clip->rclBounds)
195 EngFreeMem(Clip->Rects);
196 Clip->Rects = NewRects;
197 }
198 }
199 else
200 {
201 Clip->iDirection = CD_ANY;
202
203 Clip->iDComplexity = (((rcBounds->top == rcBounds->bottom) &&
204 (rcBounds->left == rcBounds->right))
205 ? DC_TRIVIAL : DC_RECT);
206
207 Clip->iFComplexity = FC_RECT;
208 Clip->iMode = TC_RECTANGLES;
209 Clip->rclBounds = *rcBounds;
210 Clip->RectCount = 1;
211 if (Clip->Rects != &Clip->rclBounds)
212 EngFreeMem(Clip->Rects);
213 Clip->Rects = &Clip->rclBounds;
214 }
215}
216
217/*
218 * @implemented
219 */
220CLIPOBJ *
223{
225 if(Clip != NULL)
226 {
227 IntEngInitClipObj(Clip);
228 TRACE("Created Clip Obj %p.\n", Clip);
229 return (CLIPOBJ *)Clip;
230 }
231
232 ERR("Clip object allocation failed!\n");
233 return NULL;
234}
235
236/*
237 * @implemented
238 */
239VOID
243{
244 XCLIPOBJ* pxco = (XCLIPOBJ *)pco;
245 TRACE("Deleting %p.\n", pco);
247 EngFreeMem(pxco);
248}
249
250/*
251 * @implemented
252 */
253ULONG
257 _In_ BOOL bAll,
259 _In_ ULONG iDirection,
260 _In_ ULONG cMaxRects)
261{
262 XCLIPOBJ* Clip = (XCLIPOBJ *)pco;
263 SORTCOMP CompareFunc;
264
265 Clip->bAll = bAll;
266 Clip->iType = iType;
267 Clip->EnumPos = 0;
268 Clip->EnumMax = (cMaxRects > 0) ? cMaxRects : Clip->RectCount;
269
270 if (CD_ANY != iDirection && Clip->iDirection != iDirection)
271 {
272 switch (iDirection)
273 {
274 case CD_RIGHTDOWN:
275 CompareFunc = (SORTCOMP) CompareRightDown;
276 break;
277
278 case CD_RIGHTUP:
279 CompareFunc = (SORTCOMP) CompareRightUp;
280 break;
281
282 case CD_LEFTDOWN:
283 CompareFunc = (SORTCOMP) CompareLeftDown;
284 break;
285
286 case CD_LEFTUP:
287 CompareFunc = (SORTCOMP) CompareLeftUp;
288 break;
289
290 default:
291 ERR("Invalid iDirection %lu\n", iDirection);
292 iDirection = Clip->iDirection;
294 break;
295 }
296
297 if (NULL != CompareFunc)
298 {
299 EngSort((PBYTE) Clip->Rects, sizeof(RECTL), Clip->RectCount, CompareFunc);
300 }
301
302 Clip->iDirection = iDirection;
303 }
304
305 /* Return the number of rectangles enumerated */
306 if ((cMaxRects > 0) && (Clip->RectCount > cMaxRects))
307 {
308 return 0xFFFFFFFF;
309 }
310
311 return Clip->RectCount;
312}
313
314/*
315 * @implemented
316 */
317BOOL
321 _In_ ULONG cj,
322 _Out_bytecap_(cj) ULONG *pulEnumRects)
323{
324 const RECTL* src;
325 XCLIPOBJ* Clip = (XCLIPOBJ *)pco;
326 ULONG nCopy;
327 ENUMRECTS* pERects = (ENUMRECTS*)pulEnumRects;
328
329 // Calculate how many rectangles we should copy
330 nCopy = min( Clip->EnumMax - Clip->EnumPos,
331 min( Clip->RectCount - Clip->EnumPos,
332 (cj - sizeof(ULONG)) / sizeof(RECTL)));
333
334 if(nCopy == 0)
335 {
336 return FALSE;
337 }
338
339 /* Copy rectangles */
340 src = &Clip->Rects[Clip->EnumPos];
341 RtlCopyMemory(pERects->arcl, src, nCopy * sizeof(RECTL));
342
343 pERects->c = nCopy;
344
345 Clip->EnumPos+=nCopy;
346
347 return Clip->EnumPos < Clip->RectCount;
348}
349
350/* EOF */
static INT CALLBACK CompareFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
Definition: mainwnd.c:243
#define ERR(fmt,...)
Definition: debug.h:113
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
#define NULL
Definition: types.h:112
#define FALSE
Definition: types.h:117
#define APIENTRY
Definition: api.h:79
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLenum src
Definition: glext.h:6340
if(dx< 0)
Definition: linetemp.h:194
#define ASSERT(a)
Definition: mode.c:44
static DNS_RECORDW r1
Definition: record.c:37
static DNS_RECORDW r2
Definition: record.c:38
#define min(a, b)
Definition: monoChain.cc:55
#define _Post_ptr_invalid_
Definition: ms_sal.h:698
#define _Inout_
Definition: ms_sal.h:378
#define _In_
Definition: ms_sal.h:308
#define _Out_bytecap_(size)
Definition: ms_sal.h:854
#define FASTCALL
Definition: nt_native.h:50
BYTE * PBYTE
Definition: pedump.c:66
#define EngFreeMem
Definition: polytest.cpp:56
#define FL_ZERO_MEMORY
Definition: polytest.cpp:58
void * EngAllocMem(int zero, unsigned long size, int tag=0)
Definition: polytest.cpp:70
#define TRACE(s)
Definition: solgame.cpp:4
long bottom
Definition: polytest.cpp:53
long right
Definition: polytest.cpp:53
long top
Definition: polytest.cpp:53
long left
Definition: polytest.cpp:53
RECTL arcl[1]
Definition: winddi.h:577
ULONG c
Definition: winddi.h:576
ULONG iDirection
Definition: engobjects.h:71
ULONG EnumMax
Definition: engobjects.h:70
ULONG iType
Definition: engobjects.h:72
RECTL * Rects
Definition: engobjects.h:65
BOOL bAll
Definition: engobjects.h:76
DWORD RectCount
Definition: engobjects.h:78
ULONG EnumPos
Definition: engobjects.h:68
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255
#define RtlCopyMemory(Destination, Source, Length)
Definition: typedefs.h:263
uint32_t ULONG
Definition: typedefs.h:59
static __inline int CompareRightUp(const RECTL *r1, const RECTL *r2)
Definition: clip.c:50
CLIPOBJ *APIENTRY EngCreateClip(VOID)
Definition: clip.c:222
static __inline int CompareRightDown(const RECTL *r1, const RECTL *r2)
Definition: clip.c:14
VOID FASTCALL IntEngUpdateClipRegion(XCLIPOBJ *Clip, ULONG count, const RECTL *pRect, const RECTL *rcBounds)
Definition: clip.c:173
BOOL APIENTRY CLIPOBJ_bEnum(_In_ CLIPOBJ *pco, _In_ ULONG cj, _Out_bytecap_(cj) ULONG *pulEnumRects)
Definition: clip.c:319
ULONG APIENTRY CLIPOBJ_cEnumStart(_Inout_ CLIPOBJ *pco, _In_ BOOL bAll, _In_ ULONG iType, _In_ ULONG iDirection, _In_ ULONG cMaxRects)
Definition: clip.c:255
VOID FASTCALL IntEngFreeClipResources(XCLIPOBJ *Clip)
Definition: clip.c:164
static __inline int CompareLeftDown(const RECTL *r1, const RECTL *r2)
Definition: clip.c:86
VOID APIENTRY EngDeleteClip(_In_ _Post_ptr_invalid_ CLIPOBJ *pco)
Definition: clip.c:241
VOID FASTCALL IntEngInitClipObj(XCLIPOBJ *Clip)
Definition: clip.c:158
static __inline int CompareLeftUp(const RECTL *r1, const RECTL *r2)
Definition: clip.c:122
#define GDITAG_CLIPOBJ
Definition: tags.h:78
#define DC_TRIVIAL
Definition: winddi.h:259
#define FC_RECT4
Definition: winddi.h:265
#define FC_COMPLEX
Definition: winddi.h:266
#define CD_RIGHTUP
Definition: winddi.h:1323
#define CD_LEFTDOWN
Definition: winddi.h:1321
#define DC_COMPLEX
Definition: winddi.h:261
_In_ ULONG cj
Definition: winddi.h:3540
#define DC_RECT
Definition: winddi.h:260
#define CD_RIGHTDOWN
Definition: winddi.h:1320
#define CD_ANY
Definition: winddi.h:1326
_In_ ULONG iType
Definition: winddi.h:3748
ENGAPI VOID APIENTRY EngSort(_Inout_updates_bytes_(c *cjElem) PBYTE pjBuf, _In_ ULONG c, _In_ ULONG cjElem, _In_ SORTCOMP pfnComp)
#define CD_LEFTUP
Definition: winddi.h:1325
#define FC_RECT
Definition: winddi.h:264
#define TC_RECTANGLES
Definition: winddi.h:269
_In_ SURFOBJ _In_ CLIPOBJ * pco
Definition: winddi.h:3415