2003-05-18 17:16:18 +00:00
|
|
|
/*
|
|
|
|
* ReactOS W32 Subsystem
|
|
|
|
* Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003 ReactOS Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
2009-10-27 10:34:16 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
2003-05-18 17:16:18 +00:00
|
|
|
*/
|
2004-05-18 15:25:25 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* GDI region objects. Shamelessly ripped out from the X11 distribution
|
|
|
|
* Thanks for the nice licence.
|
|
|
|
*
|
|
|
|
* Copyright 1993, 1994, 1995 Alexandre Julliard
|
|
|
|
* Modifications and additions: Copyright 1998 Huw Davies
|
2014-12-18 08:11:13 +00:00
|
|
|
* 1999 Alex Korobka
|
2004-05-18 15:25:25 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
2009-10-27 10:34:16 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2004-05-18 15:25:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
/************************************************************************
|
|
|
|
|
|
|
|
Copyright (c) 1987, 1988 X Consortium
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of the X Consortium shall not be
|
|
|
|
used in advertising or otherwise to promote the sale, use or other dealings
|
|
|
|
in this Software without prior written authorization from the X Consortium.
|
|
|
|
|
|
|
|
|
|
|
|
Copyright 1987, 1988 by Digital Equipment Corporation, Maynard, Massachusetts.
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
All Rights Reserved
|
2004-05-18 15:25:25 +00:00
|
|
|
|
|
|
|
Permission to use, copy, modify, and distribute this software and its
|
|
|
|
documentation for any purpose and without fee is hereby granted,
|
|
|
|
provided that the above copyright notice appear in all copies and that
|
|
|
|
both that copyright notice and this permission notice appear in
|
|
|
|
supporting documentation, and that the name of Digital not be
|
|
|
|
used in advertising or publicity pertaining to distribution of the
|
|
|
|
software without specific, written prior permission.
|
|
|
|
|
|
|
|
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
|
|
|
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
|
|
|
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
|
|
|
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
|
|
|
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
|
|
|
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
|
|
|
SOFTWARE.
|
|
|
|
|
|
|
|
************************************************************************/
|
|
|
|
/*
|
|
|
|
* The functions in this file implement the Region abstraction, similar to one
|
|
|
|
* used in the X11 sample server. A Region is simply an area, as the name
|
|
|
|
* implies, and is implemented as a "y-x-banded" array of rectangles. To
|
|
|
|
* explain: Each Region is made up of a certain number of rectangles sorted
|
|
|
|
* by y coordinate first, and then by x coordinate.
|
|
|
|
*
|
|
|
|
* Furthermore, the rectangles are banded such that every rectangle with a
|
|
|
|
* given upper-left y coordinate (y1) will have the same lower-right y
|
|
|
|
* coordinate (y2) and vice versa. If a rectangle has scanlines in a band, it
|
|
|
|
* will span the entire vertical distance of the band. This means that some
|
|
|
|
* areas that could be merged into a taller rectangle will be represented as
|
|
|
|
* several shorter rectangles to account for shorter rectangles to its left
|
|
|
|
* or right but within its "vertical scope".
|
|
|
|
*
|
|
|
|
* An added constraint on the rectangles is that they must cover as much
|
|
|
|
* horizontal area as possible. E.g. no two rectangles in a band are allowed
|
|
|
|
* to touch.
|
|
|
|
*
|
|
|
|
* Whenever possible, bands will be merged together to cover a greater vertical
|
|
|
|
* distance (and thus reduce the number of rectangles). Two bands can be merged
|
|
|
|
* only if the bottom of one touches the top of the other and they have
|
|
|
|
* rectangles in the same places (of the same width, of course). This maintains
|
|
|
|
* the y-x-banding that's so nice to have...
|
|
|
|
*/
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
// X11 sources for ReactOS region processing.
|
|
|
|
//
|
|
|
|
// libX11/src/PolyReg.c
|
|
|
|
// libX11/src/Region.c
|
|
|
|
//
|
|
|
|
//
|
|
|
|
|
|
|
|
|
2010-04-26 13:58:46 +00:00
|
|
|
#include <win32k.h>
|
2012-12-16 11:32:56 +00:00
|
|
|
#include <suppress.h>
|
1999-07-23 19:57:18 +00:00
|
|
|
|
2005-06-29 07:09:25 +00:00
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION prgnDefault = NULL;
|
|
|
|
HRGN hrgnDefault = NULL;
|
2008-06-17 05:19:08 +00:00
|
|
|
|
2002-07-18 21:59:18 +00:00
|
|
|
// Internal Functions
|
|
|
|
|
2004-12-12 01:40:39 +00:00
|
|
|
#if 1
|
|
|
|
#define COPY_RECTS(dest, src, nRects) \
|
|
|
|
do { \
|
2014-12-18 08:11:19 +00:00
|
|
|
PRECTL xDest = (dest); \
|
|
|
|
PRECTL xSrc = (src); \
|
2004-12-12 01:40:39 +00:00
|
|
|
UINT xRects = (nRects); \
|
2014-12-18 08:11:19 +00:00
|
|
|
while (xRects-- > 0) { \
|
2004-12-12 01:40:39 +00:00
|
|
|
*(xDest++) = *(xSrc++); \
|
|
|
|
} \
|
2014-12-18 08:11:19 +00:00
|
|
|
} while (0)
|
2004-12-12 01:40:39 +00:00
|
|
|
#else
|
2009-03-19 01:42:34 +00:00
|
|
|
#define COPY_RECTS(dest, src, nRects) RtlCopyMemory(dest, src, (nRects) * sizeof(RECTL))
|
2004-12-12 01:40:39 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-18 21:59:18 +00:00
|
|
|
#define EMPTY_REGION(pReg) { \
|
|
|
|
(pReg)->rdh.nCount = 0; \
|
|
|
|
(pReg)->rdh.rcBound.left = (pReg)->rdh.rcBound.top = 0; \
|
|
|
|
(pReg)->rdh.rcBound.right = (pReg)->rdh.rcBound.bottom = 0; \
|
2008-05-23 00:29:08 +00:00
|
|
|
(pReg)->rdh.iType = RDH_RECTANGLES; \
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#define REGION_NOT_EMPTY(pReg) pReg->rdh.nCount
|
|
|
|
|
|
|
|
#define INRECT(r, x, y) \
|
|
|
|
( ( ((r).right > x)) && \
|
|
|
|
( ((r).left <= x)) && \
|
|
|
|
( ((r).bottom > y)) && \
|
|
|
|
( ((r).top <= y)) )
|
|
|
|
|
|
|
|
/* 1 if two RECTs overlap.
|
|
|
|
* 0 if two RECTs do not overlap.
|
|
|
|
*/
|
|
|
|
#define EXTENTCHECK(r1, r2) \
|
2014-12-18 08:11:13 +00:00
|
|
|
((r1)->right > (r2)->left && \
|
|
|
|
(r1)->left < (r2)->right && \
|
|
|
|
(r1)->bottom > (r2)->top && \
|
|
|
|
(r1)->top < (r2)->bottom)
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2004-05-18 15:25:25 +00:00
|
|
|
/*
|
|
|
|
* In scan converting polygons, we want to choose those pixels
|
|
|
|
* which are inside the polygon. Thus, we add .5 to the starting
|
|
|
|
* x coordinate for both left and right edges. Now we choose the
|
|
|
|
* first pixel which is inside the pgon for the left edge and the
|
|
|
|
* first pixel which is outside the pgon for the right edge.
|
|
|
|
* Draw the left pixel, but not the right.
|
|
|
|
*
|
|
|
|
* How to add .5 to the starting x coordinate:
|
|
|
|
* If the edge is moving to the right, then subtract dy from the
|
|
|
|
* error term from the general form of the algorithm.
|
|
|
|
* If the edge is moving to the left, then add dy to the error term.
|
|
|
|
*
|
|
|
|
* The reason for the difference between edges moving to the left
|
|
|
|
* and edges moving to the right is simple: If an edge is moving
|
|
|
|
* to the right, then we want the algorithm to flip immediately.
|
|
|
|
* If it is moving to the left, then we don't want it to flip until
|
|
|
|
* we traverse an entire pixel.
|
|
|
|
*/
|
|
|
|
#define BRESINITPGON(dy, x1, x2, xStart, d, m, m1, incr1, incr2) { \
|
2011-12-14 04:07:06 +00:00
|
|
|
int dx; /* Local storage */ \
|
2004-05-18 15:25:25 +00:00
|
|
|
\
|
|
|
|
/* \
|
2011-12-14 04:07:06 +00:00
|
|
|
* If the edge is horizontal, then it is ignored \
|
2004-05-18 15:25:25 +00:00
|
|
|
* and assumed not to be processed. Otherwise, do this stuff. \
|
|
|
|
*/ \
|
|
|
|
if ((dy) != 0) { \
|
|
|
|
xStart = (x1); \
|
|
|
|
dx = (x2) - xStart; \
|
|
|
|
if (dx < 0) { \
|
|
|
|
m = dx / (dy); \
|
|
|
|
m1 = m - 1; \
|
|
|
|
incr1 = -2 * dx + 2 * (dy) * m1; \
|
|
|
|
incr2 = -2 * dx + 2 * (dy) * m; \
|
|
|
|
d = 2 * m * (dy) - 2 * dx - 2 * (dy); \
|
|
|
|
} else { \
|
|
|
|
m = dx / (dy); \
|
|
|
|
m1 = m + 1; \
|
|
|
|
incr1 = 2 * dx - 2 * (dy) * m1; \
|
|
|
|
incr2 = 2 * dx - 2 * (dy) * m; \
|
|
|
|
d = -2 * m * (dy) + 2 * dx; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define BRESINCRPGON(d, minval, m, m1, incr1, incr2) { \
|
|
|
|
if (m1 > 0) { \
|
|
|
|
if (d > 0) { \
|
|
|
|
minval += m1; \
|
|
|
|
d += incr1; \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
minval += m; \
|
|
|
|
d += incr2; \
|
|
|
|
} \
|
|
|
|
} else {\
|
|
|
|
if (d >= 0) { \
|
|
|
|
minval += m1; \
|
|
|
|
d += incr1; \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
minval += m; \
|
|
|
|
d += incr2; \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2014-12-18 08:11:19 +00:00
|
|
|
* This structure contains all of the information needed
|
|
|
|
* to run the bresenham algorithm.
|
|
|
|
* The variables may be hardcoded into the declarations
|
|
|
|
* instead of using this structure to make use of
|
|
|
|
* register declarations.
|
2004-05-18 15:25:25 +00:00
|
|
|
*/
|
2008-02-21 02:40:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
INT minor_axis; /* Minor axis */
|
|
|
|
INT d; /* Decision variable */
|
|
|
|
INT m, m1; /* Slope and slope+1 */
|
|
|
|
INT incr1, incr2; /* Error increments */
|
2004-05-18 15:25:25 +00:00
|
|
|
} BRESINFO;
|
|
|
|
|
|
|
|
|
|
|
|
#define BRESINITPGONSTRUCT(dmaj, min1, min2, bres) \
|
2014-12-18 08:11:13 +00:00
|
|
|
BRESINITPGON(dmaj, min1, min2, bres.minor_axis, bres.d, \
|
2004-05-18 15:25:25 +00:00
|
|
|
bres.m, bres.m1, bres.incr1, bres.incr2)
|
|
|
|
|
|
|
|
#define BRESINCRPGONSTRUCT(bres) \
|
|
|
|
BRESINCRPGON(bres.d, bres.minor_axis, bres.m, bres.m1, bres.incr1, bres.incr2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These are the data structures needed to scan
|
|
|
|
* convert regions. Two different scan conversion
|
|
|
|
* methods are available -- the even-odd method, and
|
|
|
|
* the winding number method.
|
|
|
|
* The even-odd rule states that a point is inside
|
|
|
|
* the polygon if a ray drawn from that point in any
|
|
|
|
* direction will pass through an odd number of
|
|
|
|
* path segments.
|
|
|
|
* By the winding number rule, a point is decided
|
|
|
|
* to be inside the polygon if a ray drawn from that
|
|
|
|
* point in any direction passes through a different
|
|
|
|
* number of clockwise and counter-clockwise path
|
|
|
|
* segments.
|
|
|
|
*
|
|
|
|
* These data structures are adapted somewhat from
|
|
|
|
* the algorithm in (Foley/Van Dam) for scan converting
|
|
|
|
* polygons.
|
|
|
|
* The basic algorithm is to start at the top (smallest y)
|
|
|
|
* of the polygon, stepping down to the bottom of
|
|
|
|
* the polygon by incrementing the y coordinate. We
|
|
|
|
* keep a list of edges which the current scanline crosses,
|
|
|
|
* sorted by x. This list is called the Active Edge Table (AET)
|
|
|
|
* As we change the y-coordinate, we update each entry in
|
|
|
|
* in the active edge table to reflect the edges new xcoord.
|
|
|
|
* This list must be sorted at each scanline in case
|
|
|
|
* two edges intersect.
|
|
|
|
* We also keep a data structure known as the Edge Table (ET),
|
|
|
|
* which keeps track of all the edges which the current
|
|
|
|
* scanline has not yet reached. The ET is basically a
|
2014-12-18 08:11:19 +00:00
|
|
|
* list of SCANLINE_LIST structures containing a list of
|
2004-05-18 15:25:25 +00:00
|
|
|
* edges which are entered at a given scanline. There is one
|
2014-12-18 08:11:19 +00:00
|
|
|
* SCANLINE_LIST per scanline at which an edge is entered.
|
2004-05-18 15:25:25 +00:00
|
|
|
* When we enter a new edge, we move it from the ET to the AET.
|
|
|
|
*
|
|
|
|
* From the AET, we can implement the even-odd rule as in
|
|
|
|
* (Foley/Van Dam).
|
|
|
|
* The winding number rule is a little trickier. We also
|
2014-12-18 08:11:19 +00:00
|
|
|
* keep the EDGE_TABLEEntries in the AET linked by the
|
|
|
|
* nextWETE (winding EDGE_TABLE_ENTRY) link. This allows
|
2004-05-18 15:25:25 +00:00
|
|
|
* the edges to be linked just as before for updating
|
|
|
|
* purposes, but only uses the edges linked by the nextWETE
|
|
|
|
* link as edges representing spans of the polygon to
|
|
|
|
* drawn (as with the even-odd rule).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2011-12-14 04:07:06 +00:00
|
|
|
* For the winding number rule
|
2004-05-18 15:25:25 +00:00
|
|
|
*/
|
|
|
|
#define CLOCKWISE 1
|
|
|
|
#define COUNTERCLOCKWISE -1
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
typedef struct _EDGE_TABLE_ENTRY
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
INT ymax; /* ycoord at which we exit this edge. */
|
|
|
|
BRESINFO bres; /* Bresenham info to run the edge */
|
2014-12-18 08:11:19 +00:00
|
|
|
struct _EDGE_TABLE_ENTRY *next; /* Next in the list */
|
|
|
|
struct _EDGE_TABLE_ENTRY *back; /* For insertion sort */
|
|
|
|
struct _EDGE_TABLE_ENTRY *nextWETE; /* For winding num rule */
|
|
|
|
INT ClockWise; /* Flag for winding number rule */
|
|
|
|
} EDGE_TABLE_ENTRY;
|
2004-05-18 15:25:25 +00:00
|
|
|
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
typedef struct _SCANLINE_LIST
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
INT scanline; /* The scanline represented */
|
2014-12-18 08:11:19 +00:00
|
|
|
EDGE_TABLE_ENTRY *edgelist; /* Header node */
|
|
|
|
struct _SCANLINE_LIST *next; /* Next in the list */
|
|
|
|
} SCANLINE_LIST;
|
2004-05-18 15:25:25 +00:00
|
|
|
|
|
|
|
|
2008-02-21 02:40:23 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
INT ymax; /* ymax for the polygon */
|
|
|
|
INT ymin; /* ymin for the polygon */
|
2014-12-18 08:11:19 +00:00
|
|
|
SCANLINE_LIST scanlines; /* Header node */
|
|
|
|
} EDGE_TABLE;
|
2004-05-18 15:25:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here is a struct to help with storage allocation
|
|
|
|
* so we can allocate a big chunk at a time, and then take
|
|
|
|
* pieces from this heap when we need to.
|
|
|
|
*/
|
|
|
|
#define SLLSPERBLOCK 25
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
typedef struct _SCANLINE_LISTBLOCK
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
SCANLINE_LIST SLLs[SLLSPERBLOCK];
|
|
|
|
struct _SCANLINE_LISTBLOCK *next;
|
|
|
|
} SCANLINE_LISTBLOCK;
|
2004-05-18 15:25:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2011-12-14 04:07:06 +00:00
|
|
|
* A few macros for the inner loops of the fill code where
|
2004-05-18 15:25:25 +00:00
|
|
|
* performance considerations don't allow a procedure call.
|
|
|
|
*
|
|
|
|
* Evaluate the given edge at the given scanline.
|
|
|
|
* If the edge has expired, then we leave it and fix up
|
|
|
|
* the active edge table; otherwise, we increment the
|
|
|
|
* x value to be ready for the next scanline.
|
|
|
|
* The winding number rule is in effect, so we must notify
|
|
|
|
* the caller when the edge has been removed so he
|
|
|
|
* can reorder the Winding Active Edge Table.
|
|
|
|
*/
|
|
|
|
#define EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET) { \
|
2011-12-14 04:07:06 +00:00
|
|
|
if (pAET->ymax == y) { /* Leaving this edge */ \
|
2004-05-18 15:25:25 +00:00
|
|
|
pPrevAET->next = pAET->next; \
|
|
|
|
pAET = pPrevAET->next; \
|
|
|
|
fixWAET = 1; \
|
|
|
|
if (pAET) \
|
|
|
|
pAET->back = pPrevAET; \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
BRESINCRPGONSTRUCT(pAET->bres); \
|
|
|
|
pPrevAET = pAET; \
|
|
|
|
pAET = pAET->next; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Evaluate the given edge at the given scanline.
|
|
|
|
* If the edge has expired, then we leave it and fix up
|
|
|
|
* the active edge table; otherwise, we increment the
|
|
|
|
* x value to be ready for the next scanline.
|
|
|
|
* The even-odd rule is in effect.
|
|
|
|
*/
|
|
|
|
#define EVALUATEEDGEEVENODD(pAET, pPrevAET, y) { \
|
2011-12-14 04:07:06 +00:00
|
|
|
if (pAET->ymax == y) { /* Leaving this edge */ \
|
2004-05-18 15:25:25 +00:00
|
|
|
pPrevAET->next = pAET->next; \
|
|
|
|
pAET = pPrevAET->next; \
|
|
|
|
if (pAET) \
|
|
|
|
pAET->back = pPrevAET; \
|
|
|
|
} \
|
|
|
|
else { \
|
|
|
|
BRESINCRPGONSTRUCT(pAET->bres); \
|
|
|
|
pPrevAET = pAET; \
|
|
|
|
pAET = pAET->next; \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
|
|
|
|
/**************************************************************************
|
|
|
|
*
|
|
|
|
* Poly Regions
|
|
|
|
*
|
|
|
|
*************************************************************************/
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
#define LARGE_COORDINATE INT_MAX
|
|
|
|
#define SMALL_COORDINATE INT_MIN
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
REGION_bGrowBufferSize(
|
|
|
|
_Inout_ PREGION prgn,
|
|
|
|
_In_ UINT cRects)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:12:55 +00:00
|
|
|
ULONG cjNewSize;
|
|
|
|
PVOID pvBuffer;
|
|
|
|
NT_ASSERT(cRects > 0);
|
|
|
|
|
|
|
|
/* Make sure we don't overflow */
|
|
|
|
if (cRects > MAXULONG / sizeof(RECTL))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:12:55 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
/* Calculate new buffer size */
|
|
|
|
cjNewSize = cRects * sizeof(RECTL);
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
/* Avoid allocating too often, by duplicating the old buffer size
|
|
|
|
Note: we don't do an overflow check, since the old size will never
|
|
|
|
get that large before running out of memory. */
|
|
|
|
if (2 * prgn->rdh.nRgnSize > cjNewSize)
|
|
|
|
{
|
|
|
|
cjNewSize = 2 * prgn->rdh.nRgnSize;
|
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
/* Allocate the new buffer */
|
|
|
|
pvBuffer = ExAllocatePoolWithTag(PagedPool, cjNewSize, TAG_REGION);
|
|
|
|
if (pvBuffer == NULL)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
/* Copy the rects into the new buffer */
|
|
|
|
COPY_RECTS(pvBuffer, prgn->Buffer, prgn->rdh.nCount);
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
/* Free the old buffer */
|
|
|
|
if (prgn->Buffer != &prgn->rdh.rcBound)
|
|
|
|
{
|
|
|
|
ExFreePoolWithTag(prgn->Buffer, TAG_REGION);
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2014-12-18 08:12:55 +00:00
|
|
|
|
|
|
|
/* Set the new buffer */
|
|
|
|
prgn->Buffer = pvBuffer;
|
|
|
|
prgn->rdh.nRgnSize = cjNewSize;
|
|
|
|
|
|
|
|
return TRUE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
static __inline
|
|
|
|
BOOL
|
|
|
|
REGION_bEnsureBufferSize(
|
|
|
|
_Inout_ PREGION prgn,
|
|
|
|
_In_ UINT cRects)
|
|
|
|
{
|
|
|
|
/* Check if the current region size is too small */
|
|
|
|
if (cRects > prgn->rdh.nRgnSize / sizeof(RECTL))
|
|
|
|
{
|
|
|
|
/* Allocate a new buffer */
|
|
|
|
return REGION_bGrowBufferSize(prgn, cRects);
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
FORCEINLINE
|
|
|
|
VOID
|
|
|
|
REGION_vAddRect(
|
|
|
|
_Inout_ PREGION prgn,
|
|
|
|
_In_ LONG left,
|
|
|
|
_In_ LONG top,
|
|
|
|
_In_ LONG right,
|
|
|
|
_In_ LONG bottom)
|
|
|
|
{
|
|
|
|
PRECTL prcl;
|
|
|
|
NT_ASSERT((prgn->rdh.nCount + 1) * sizeof(RECT) <= prgn->rdh.nRgnSize);
|
|
|
|
|
|
|
|
prcl = &prgn->Buffer[prgn->rdh.nCount];
|
|
|
|
prcl->left = left;
|
|
|
|
prcl->top = top;
|
|
|
|
prcl->right = right;
|
|
|
|
prcl->bottom = bottom;
|
|
|
|
prgn->rdh.nCount++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline
|
|
|
|
BOOL
|
|
|
|
REGION_bAddRect(
|
|
|
|
_Inout_ PREGION prgn,
|
|
|
|
_In_ LONG left,
|
|
|
|
_In_ LONG top,
|
|
|
|
_In_ LONG right,
|
|
|
|
_In_ LONG bottom)
|
|
|
|
{
|
|
|
|
if (!REGION_bEnsureBufferSize(prgn, prgn->rdh.nCount + 1))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
REGION_vAddRect(prgn, left, top, right, bottom);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
typedef BOOL (FASTCALL *overlapProcp)(PREGION, PRECT, PRECT, PRECT, PRECT, INT, INT);
|
|
|
|
typedef BOOL (FASTCALL *nonOverlapProcp)(PREGION, PRECT, PRECT, INT, INT);
|
2002-07-18 21:59:18 +00:00
|
|
|
|
|
|
|
// Number of points to buffer before sending them off to scanlines() : Must be an even number
|
|
|
|
#define NUMPTSTOBUFFER 200
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
#define RGN_DEFAULT_RECTS 2
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2011-12-14 04:07:06 +00:00
|
|
|
// Used to allocate buffers for points and link the buffers together
|
2008-02-21 02:40:23 +00:00
|
|
|
typedef struct _POINTBLOCK
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
POINT pts[NUMPTSTOBUFFER];
|
|
|
|
struct _POINTBLOCK *next;
|
2002-07-18 21:59:18 +00:00
|
|
|
} POINTBLOCK;
|
2002-07-04 19:56:38 +00:00
|
|
|
|
2004-04-24 14:21:37 +00:00
|
|
|
#ifndef NDEBUG
|
2003-11-18 20:49:39 +00:00
|
|
|
/*
|
|
|
|
* This function is left there for debugging purposes.
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2003-11-18 20:49:39 +00:00
|
|
|
IntDumpRegion(HRGN hRgn)
|
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION Data;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
Data = REGION_LockRgn(hRgn);
|
2008-02-21 02:40:23 +00:00
|
|
|
if (Data == NULL)
|
|
|
|
{
|
|
|
|
DbgPrint("IntDumpRegion called with invalid region!\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
DbgPrint("IntDumpRegion(%x): %d,%d-%d,%d %d\n",
|
|
|
|
hRgn,
|
|
|
|
Data->rdh.rcBound.left,
|
|
|
|
Data->rdh.rcBound.top,
|
|
|
|
Data->rdh.rcBound.right,
|
|
|
|
Data->rdh.rcBound.bottom,
|
|
|
|
Data->rdh.iType);
|
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(Data);
|
2003-11-18 20:49:39 +00:00
|
|
|
}
|
2011-12-14 04:07:06 +00:00
|
|
|
#endif /* Not NDEBUG */
|
2003-11-18 20:49:39 +00:00
|
|
|
|
2008-05-21 22:32:13 +00:00
|
|
|
|
|
|
|
INT
|
|
|
|
FASTCALL
|
2014-09-23 20:21:13 +00:00
|
|
|
REGION_Complexity(PREGION prgn)
|
2008-05-21 22:32:13 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
if (prgn == NULL)
|
2014-12-18 08:11:13 +00:00
|
|
|
return NULLREGION;
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
DPRINT("Region Complexity -> %lu", prgn->rdh.nCount);
|
2014-12-18 08:11:13 +00:00
|
|
|
switch (prgn->rdh.nCount)
|
2008-05-21 22:32:13 +00:00
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
case 0:
|
|
|
|
return NULLREGION;
|
|
|
|
case 1:
|
|
|
|
return SIMPLEREGION;
|
|
|
|
default:
|
|
|
|
return COMPLEXREGION;
|
2008-05-21 22:32:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-02-21 02:40:23 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
REGION_CopyRegion(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION dst,
|
|
|
|
PREGION src)
|
2002-07-04 19:56:38 +00:00
|
|
|
{
|
2014-12-18 08:12:41 +00:00
|
|
|
/* Only copy if source and dest are not equal */
|
2014-12-18 08:11:19 +00:00
|
|
|
if (dst != src)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
/* Check if we need to increase our buffer */
|
2008-02-21 02:40:23 +00:00
|
|
|
if (dst->rdh.nRgnSize < src->rdh.nCount * sizeof(RECT))
|
|
|
|
{
|
2009-03-19 01:42:34 +00:00
|
|
|
PRECTL temp;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
/* Allocate a new buffer */
|
|
|
|
temp = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
src->rdh.nCount * sizeof(RECT),
|
|
|
|
TAG_REGION);
|
|
|
|
if (temp == NULL)
|
2008-02-21 02:40:23 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
/* Free the old buffer */
|
|
|
|
if ((dst->Buffer != NULL) && (dst->Buffer != &dst->rdh.rcBound))
|
|
|
|
ExFreePoolWithTag(dst->Buffer, TAG_REGION);
|
|
|
|
|
|
|
|
/* Set the new buffer and the size */
|
2008-02-21 02:40:23 +00:00
|
|
|
dst->Buffer = temp;
|
2014-12-18 08:11:19 +00:00
|
|
|
dst->rdh.nRgnSize = src->rdh.nCount * sizeof(RECT);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
dst->rdh.nCount = src->rdh.nCount;
|
2008-02-21 02:40:23 +00:00
|
|
|
dst->rdh.rcBound.left = src->rdh.rcBound.left;
|
|
|
|
dst->rdh.rcBound.top = src->rdh.rcBound.top;
|
|
|
|
dst->rdh.rcBound.right = src->rdh.rcBound.right;
|
|
|
|
dst->rdh.rcBound.bottom = src->rdh.rcBound.bottom;
|
|
|
|
dst->rdh.iType = src->rdh.iType;
|
|
|
|
COPY_RECTS(dst->Buffer, src->Buffer, src->rdh.nCount);
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2008-02-21 02:40:23 +00:00
|
|
|
return TRUE;
|
2002-07-04 19:56:38 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2014-12-18 08:11:19 +00:00
|
|
|
VOID
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
|
|
|
REGION_SetExtents(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION pReg)
|
2002-07-04 19:56:38 +00:00
|
|
|
{
|
2009-03-19 01:42:34 +00:00
|
|
|
RECTL *pRect, *pRectEnd, *pExtents;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
/* Quick check for NULLREGION */
|
2002-07-18 21:59:18 +00:00
|
|
|
if (pReg->rdh.nCount == 0)
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
pReg->rdh.rcBound.left = 0;
|
|
|
|
pReg->rdh.rcBound.top = 0;
|
|
|
|
pReg->rdh.rcBound.right = 0;
|
|
|
|
pReg->rdh.rcBound.bottom = 0;
|
2008-05-23 00:29:08 +00:00
|
|
|
pReg->rdh.iType = RDH_RECTANGLES;
|
2008-02-21 02:40:23 +00:00
|
|
|
return;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pExtents = &pReg->rdh.rcBound;
|
2009-03-19 01:42:34 +00:00
|
|
|
pRect = pReg->Buffer;
|
|
|
|
pRectEnd = pReg->Buffer + pReg->rdh.nCount - 1;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Since pRect is the first rectangle in the region, it must have the
|
2002-07-18 21:59:18 +00:00
|
|
|
* smallest top and since pRectEnd is the last rectangle in the region,
|
|
|
|
* it must have the largest bottom, because of banding. Initialize left and
|
|
|
|
* right from pRect and pRectEnd, resp., as good things to initialize them
|
2014-12-18 08:11:13 +00:00
|
|
|
* to... */
|
2002-07-18 21:59:18 +00:00
|
|
|
pExtents->left = pRect->left;
|
|
|
|
pExtents->top = pRect->top;
|
|
|
|
pExtents->right = pRectEnd->right;
|
|
|
|
pExtents->bottom = pRectEnd->bottom;
|
|
|
|
|
|
|
|
while (pRect <= pRectEnd)
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
if (pRect->left < pExtents->left)
|
|
|
|
pExtents->left = pRect->left;
|
|
|
|
if (pRect->right > pExtents->right)
|
|
|
|
pExtents->right = pRect->right;
|
|
|
|
pRect++;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2008-05-23 00:29:08 +00:00
|
|
|
pReg->rdh.iType = RDH_RECTANGLES;
|
2002-07-04 19:56:38 +00:00
|
|
|
}
|
|
|
|
|
2014-11-04 20:20:45 +00:00
|
|
|
// FIXME: This function needs review and testing
|
2002-07-18 21:59:18 +00:00
|
|
|
/***********************************************************************
|
2014-12-18 08:11:56 +00:00
|
|
|
* REGION_CropRegion
|
2002-07-18 21:59:18 +00:00
|
|
|
*/
|
2014-09-23 20:21:13 +00:00
|
|
|
INT
|
|
|
|
FASTCALL
|
2014-12-18 08:11:31 +00:00
|
|
|
REGION_CropRegion(
|
2014-09-23 20:21:13 +00:00
|
|
|
PREGION rgnDst,
|
|
|
|
PREGION rgnSrc,
|
2014-12-18 08:11:31 +00:00
|
|
|
const RECTL *rect)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2014-12-18 08:11:31 +00:00
|
|
|
PRECTL lpr, rpr;
|
|
|
|
ULONG i, j, clipa, clipb, nRgnSize;
|
|
|
|
INT left = MAXLONG;
|
|
|
|
INT right = MINLONG;
|
|
|
|
INT top = MAXLONG;
|
|
|
|
INT bottom = MINLONG;
|
|
|
|
|
|
|
|
if ((rect->left >= rect->right) ||
|
|
|
|
(rect->top >= rect->bottom) ||
|
|
|
|
(EXTENTCHECK(rect, &rgnSrc->rdh.rcBound) == 0))
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2014-12-18 08:11:31 +00:00
|
|
|
goto empty;
|
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Skip all rects that are completely above our intersect rect */
|
|
|
|
for (clipa = 0; clipa < rgnSrc->rdh.nCount; clipa++)
|
|
|
|
{
|
|
|
|
/* bottom is exclusive, so break when we go above it */
|
|
|
|
if (rgnSrc->Buffer[clipa].bottom > rect->top) break;
|
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Bail out, if there is nothing left */
|
|
|
|
if (clipa == rgnSrc->rdh.nCount) goto empty;
|
2010-07-12 16:52:10 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Find the last rect that is still within the intersect rect (exclusive) */
|
|
|
|
for (clipb = clipa; clipb < rgnSrc->rdh.nCount; clipb++)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:11:31 +00:00
|
|
|
/* bottom is exclusive, so stop, when we start at that y pos */
|
|
|
|
if (rgnSrc->Buffer[clipb].top >= rect->bottom) break;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-11-04 20:20:45 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Bail out, if there is nothing left */
|
|
|
|
if (clipb == clipa) goto empty;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
// clipa - index of the first rect in the first intersecting band
|
|
|
|
// clipb - index of the last rect in the last intersecting band plus 1
|
2014-11-04 20:20:45 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Check if the buffer in the dest region is large enough,
|
|
|
|
otherwise allocate a new one */
|
|
|
|
nRgnSize = (clipb - clipa) * sizeof(RECT);
|
|
|
|
if ((rgnDst != rgnSrc) && (rgnDst->rdh.nRgnSize < nRgnSize))
|
|
|
|
{
|
|
|
|
PRECTL temp;
|
|
|
|
temp = ExAllocatePoolWithTag(PagedPool, nRgnSize, TAG_REGION);
|
|
|
|
if (temp == NULL)
|
|
|
|
return ERROR;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Free the old buffer */
|
|
|
|
if (rgnDst->Buffer && (rgnDst->Buffer != &rgnDst->rdh.rcBound))
|
|
|
|
ExFreePoolWithTag(rgnDst->Buffer, TAG_REGION);
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
rgnDst->Buffer = temp;
|
|
|
|
rgnDst->rdh.nCount = 0;
|
|
|
|
rgnDst->rdh.nRgnSize = nRgnSize;
|
|
|
|
rgnDst->rdh.iType = RDH_RECTANGLES;
|
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Loop all rects within the intersect rect from the y perspective */
|
|
|
|
for (i = clipa, j = 0; i < clipb ; i++)
|
|
|
|
{
|
|
|
|
/* i - src index, j - dst index, j is always <= i for obvious reasons */
|
2014-11-04 20:20:45 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
lpr = &rgnSrc->Buffer[i];
|
|
|
|
|
|
|
|
/* Make sure the source rect is not retarded */
|
2015-01-22 21:03:46 +00:00
|
|
|
ASSERT(lpr->bottom > lpr->top);
|
|
|
|
ASSERT(lpr->right > lpr->left);
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* We already checked above, this should hold true */
|
|
|
|
ASSERT(lpr->bottom > rect->top);
|
|
|
|
ASSERT(lpr->top < rect->bottom);
|
|
|
|
|
|
|
|
/* Check if this rect is really inside the intersect rect */
|
|
|
|
if ((lpr->left < rect->right) && (lpr->right > rect->left))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:11:31 +00:00
|
|
|
rpr = &rgnDst->Buffer[j];
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2015-01-22 21:03:46 +00:00
|
|
|
/* Crop the rect with the intersect rect */
|
2014-12-18 08:11:31 +00:00
|
|
|
rpr->top = max(lpr->top, rect->top);
|
|
|
|
rpr->bottom = min(lpr->bottom, rect->bottom);
|
|
|
|
rpr->left = max(lpr->left, rect->left);
|
|
|
|
rpr->right = min(lpr->right, rect->right);
|
2014-11-04 20:20:45 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Make sure the resulting rect is not retarded */
|
2015-01-22 21:03:46 +00:00
|
|
|
ASSERT(rpr->bottom > rpr->top);
|
|
|
|
ASSERT(rpr->right > rpr->left);
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Track new bounds */
|
|
|
|
if (rpr->left < left) left = rpr->left;
|
|
|
|
if (rpr->right > right) right = rpr->right;
|
|
|
|
if (rpr->top < top) top = rpr->top;
|
|
|
|
if (rpr->bottom > bottom) bottom = rpr->bottom;
|
|
|
|
|
|
|
|
/* Next target rect */
|
|
|
|
j++;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:31 +00:00
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
if (j == 0) goto empty;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Update the bounds rect */
|
|
|
|
rgnDst->rdh.rcBound.left = left;
|
|
|
|
rgnDst->rdh.rcBound.right = right;
|
|
|
|
rgnDst->rdh.rcBound.top = top;
|
|
|
|
rgnDst->rdh.rcBound.bottom = bottom;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:31 +00:00
|
|
|
/* Set new rect count */
|
|
|
|
rgnDst->rdh.nCount = j;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-09-23 20:21:13 +00:00
|
|
|
return REGION_Complexity(rgnDst);
|
2002-07-18 21:59:18 +00:00
|
|
|
|
|
|
|
empty:
|
2014-12-18 08:11:19 +00:00
|
|
|
if (rgnDst->Buffer == NULL)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-11-04 20:20:45 +00:00
|
|
|
rgnDst->Buffer = &rgnDst->rdh.rcBound;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-11-04 20:20:45 +00:00
|
|
|
|
2008-02-21 02:40:23 +00:00
|
|
|
EMPTY_REGION(rgnDst);
|
2014-09-23 20:21:13 +00:00
|
|
|
return NULLREGION;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2003-01-19 01:01:21 +00:00
|
|
|
/*!
|
2002-07-18 21:59:18 +00:00
|
|
|
* Attempt to merge the rects in the current band with those in the
|
|
|
|
* previous one. Used only by REGION_RegionOp.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* The new index for the previous band.
|
|
|
|
*
|
2003-01-19 01:01:21 +00:00
|
|
|
* \note Side Effects:
|
2002-07-18 21:59:18 +00:00
|
|
|
* If coalescing takes place:
|
|
|
|
* - rectangles in the previous band will have their bottom fields
|
|
|
|
* altered.
|
|
|
|
* - pReg->numRects will be decreased.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
|
|
|
INT
|
|
|
|
FASTCALL
|
2008-02-21 02:40:23 +00:00
|
|
|
REGION_Coalesce(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION pReg, /* Region to coalesce */
|
|
|
|
INT prevStart, /* Index of start of previous band */
|
|
|
|
INT curStart) /* Index of start of current band */
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
RECTL *pPrevRect; /* Current rect in previous band */
|
|
|
|
RECTL *pCurRect; /* Current rect in current band */
|
|
|
|
RECTL *pRegEnd; /* End of region */
|
|
|
|
INT curNumRects; /* Number of rectangles in current band */
|
|
|
|
INT prevNumRects; /* Number of rectangles in previous band */
|
|
|
|
INT bandtop; /* Top coordinate for current band */
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2009-03-19 01:42:34 +00:00
|
|
|
pRegEnd = pReg->Buffer + pReg->rdh.nCount;
|
|
|
|
pPrevRect = pReg->Buffer + prevStart;
|
2002-07-18 21:59:18 +00:00
|
|
|
prevNumRects = curStart - prevStart;
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Figure out how many rectangles are in the current band. Have to do
|
2002-07-18 21:59:18 +00:00
|
|
|
* this because multiple bands could have been added in REGION_RegionOp
|
2014-12-18 08:11:13 +00:00
|
|
|
* at the end when one region has been exhausted. */
|
2009-03-19 01:42:34 +00:00
|
|
|
pCurRect = pReg->Buffer + curStart;
|
2002-07-18 21:59:18 +00:00
|
|
|
bandtop = pCurRect->top;
|
|
|
|
for (curNumRects = 0;
|
2014-12-18 08:11:13 +00:00
|
|
|
(pCurRect != pRegEnd) && (pCurRect->top == bandtop);
|
|
|
|
curNumRects++)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
pCurRect++;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (pCurRect != pRegEnd)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* If more than one band was added, we have to find the start
|
2008-02-21 02:40:23 +00:00
|
|
|
* of the last band added so the next coalescing job can start
|
|
|
|
* at the right place... (given when multiple bands are added,
|
2014-12-18 08:11:13 +00:00
|
|
|
* this may be pointless -- see above). */
|
2008-02-21 02:40:23 +00:00
|
|
|
pRegEnd--;
|
|
|
|
while ((pRegEnd-1)->top == pRegEnd->top)
|
|
|
|
{
|
|
|
|
pRegEnd--;
|
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2009-03-19 01:42:34 +00:00
|
|
|
curStart = pRegEnd - pReg->Buffer;
|
|
|
|
pRegEnd = pReg->Buffer + pReg->rdh.nCount;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((curNumRects == prevNumRects) && (curNumRects != 0))
|
|
|
|
{
|
|
|
|
pCurRect -= curNumRects;
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* The bands may only be coalesced if the bottom of the previous
|
|
|
|
* matches the top scanline of the current. */
|
2008-02-21 02:40:23 +00:00
|
|
|
if (pPrevRect->bottom == pCurRect->top)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Make sure the bands have rects in the same places. This
|
2008-02-21 02:40:23 +00:00
|
|
|
* assumes that rects have been added in such a way that they
|
|
|
|
* cover the most area possible. I.e. two rects in a band must
|
2014-12-18 08:11:13 +00:00
|
|
|
* have some horizontal space between them. */
|
2008-02-21 02:40:23 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if ((pPrevRect->left != pCurRect->left) ||
|
2014-12-18 08:11:13 +00:00
|
|
|
(pPrevRect->right != pCurRect->right))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* The bands don't line up so they can't be coalesced. */
|
2008-02-21 02:40:23 +00:00
|
|
|
return (curStart);
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2008-02-21 02:40:23 +00:00
|
|
|
pPrevRect++;
|
|
|
|
pCurRect++;
|
|
|
|
prevNumRects -= 1;
|
|
|
|
}
|
|
|
|
while (prevNumRects != 0);
|
|
|
|
|
|
|
|
pReg->rdh.nCount -= curNumRects;
|
|
|
|
pCurRect -= curNumRects;
|
|
|
|
pPrevRect -= curNumRects;
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* The bands may be merged, so set the bottom of each rect
|
2008-02-21 02:40:23 +00:00
|
|
|
* in the previous band to that of the corresponding rect in
|
2014-12-18 08:11:13 +00:00
|
|
|
* the current band. */
|
2008-02-21 02:40:23 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
pPrevRect->bottom = pCurRect->bottom;
|
|
|
|
pPrevRect++;
|
|
|
|
pCurRect++;
|
|
|
|
curNumRects -= 1;
|
|
|
|
}
|
|
|
|
while (curNumRects != 0);
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* If only one band was added to the region, we have to backup
|
2008-02-21 02:40:23 +00:00
|
|
|
* curStart to the start of the previous band.
|
|
|
|
*
|
|
|
|
* If more than one band was added to the region, copy the
|
|
|
|
* other bands down. The assumption here is that the other bands
|
|
|
|
* came from the same region as the current one and no further
|
|
|
|
* coalescing can be done on them since it's all been done
|
2014-12-18 08:11:13 +00:00
|
|
|
* already... curStart is already in the right place. */
|
2008-02-21 02:40:23 +00:00
|
|
|
if (pCurRect == pRegEnd)
|
|
|
|
{
|
|
|
|
curStart = prevStart;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
*pPrevRect++ = *pCurRect++;
|
|
|
|
}
|
|
|
|
while (pCurRect != pRegEnd);
|
|
|
|
}
|
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2002-07-18 21:59:18 +00:00
|
|
|
return (curStart);
|
|
|
|
}
|
|
|
|
|
2003-01-19 01:01:21 +00:00
|
|
|
/*!
|
2002-07-18 21:59:18 +00:00
|
|
|
* Apply an operation to two regions. Called by REGION_Union,
|
|
|
|
* REGION_Inverse, REGION_Subtract, REGION_Intersect...
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
|
|
|
* Side Effects:
|
|
|
|
* The new region is overwritten.
|
|
|
|
*
|
2003-01-19 01:01:21 +00:00
|
|
|
*\note The idea behind this function is to view the two regions as sets.
|
2002-07-18 21:59:18 +00:00
|
|
|
* Together they cover a rectangle of area that this function divides
|
|
|
|
* into horizontal bands where points are covered only by one region
|
|
|
|
* or by both. For the first case, the nonOverlapFunc is called with
|
|
|
|
* each the band and the band's upper and lower extents. For the
|
|
|
|
* second, the overlapFunc is called to process the entire band. It
|
|
|
|
* is responsible for clipping the rectangles in the band, though
|
|
|
|
* this function provides the boundaries.
|
|
|
|
* At the end of each band, the new region is coalesced, if possible,
|
|
|
|
* to reduce the number of rectangles in the region.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2003-08-13 00:50:25 +00:00
|
|
|
REGION_RegionOp(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION newReg, /* Place to store result */
|
|
|
|
PREGION reg1, /* First region in operation */
|
|
|
|
PREGION reg2, /* 2nd region in operation */
|
2008-02-21 02:40:23 +00:00
|
|
|
overlapProcp overlapFunc, /* Function to call for over-lapping bands */
|
|
|
|
nonOverlapProcp nonOverlap1Func, /* Function to call for non-overlapping bands in region 1 */
|
2014-12-18 08:11:13 +00:00
|
|
|
nonOverlapProcp nonOverlap2Func) /* Function to call for non-overlapping bands in region 2 */
|
2003-08-13 00:50:25 +00:00
|
|
|
{
|
2009-03-19 01:42:34 +00:00
|
|
|
RECTL *r1; /* Pointer into first region */
|
|
|
|
RECTL *r2; /* Pointer into 2d region */
|
|
|
|
RECTL *r1End; /* End of 1st region */
|
|
|
|
RECTL *r2End; /* End of 2d region */
|
2014-12-18 08:11:13 +00:00
|
|
|
INT ybot; /* Bottom of intersection */
|
|
|
|
INT ytop; /* Top of intersection */
|
2009-03-19 01:42:34 +00:00
|
|
|
RECTL *oldRects; /* Old rects for newReg */
|
2014-12-18 08:11:13 +00:00
|
|
|
ULONG prevBand; /* Index of start of
|
|
|
|
* Previous band in newReg */
|
|
|
|
ULONG curBand; /* Index of start of current band in newReg */
|
2009-03-19 01:42:34 +00:00
|
|
|
RECTL *r1BandEnd; /* End of current band in r1 */
|
|
|
|
RECTL *r2BandEnd; /* End of current band in r2 */
|
2014-12-18 08:11:13 +00:00
|
|
|
ULONG top; /* Top of non-overlapping band */
|
|
|
|
ULONG bot; /* Bottom of non-overlapping band */
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Initialization:
|
2002-07-18 21:59:18 +00:00
|
|
|
* set r1, r2, r1End and r2End appropriately, preserve the important
|
|
|
|
* parts of the destination region until the end in case it's one of
|
|
|
|
* the two source regions, then mark the "new" region empty, allocating
|
2014-12-18 08:11:13 +00:00
|
|
|
* another array of rectangles for it to use. */
|
2009-03-19 01:42:34 +00:00
|
|
|
r1 = reg1->Buffer;
|
|
|
|
r2 = reg2->Buffer;
|
2002-07-18 21:59:18 +00:00
|
|
|
r1End = r1 + reg1->rdh.nCount;
|
|
|
|
r2End = r2 + reg2->rdh.nCount;
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* newReg may be one of the src regions so we can't empty it. We keep a
|
2002-07-18 21:59:18 +00:00
|
|
|
* note of its rects pointer (so that we can free them later), preserve its
|
2014-12-18 08:11:13 +00:00
|
|
|
* extents and simply set numRects to zero. */
|
2009-03-19 01:42:34 +00:00
|
|
|
oldRects = newReg->Buffer;
|
2002-07-18 21:59:18 +00:00
|
|
|
newReg->rdh.nCount = 0;
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Allocate a reasonable number of rectangles for the new region. The idea
|
2002-07-18 21:59:18 +00:00
|
|
|
* is to allocate enough so the individual functions don't need to
|
|
|
|
* reallocate and copy the array, which is time consuming, yet we don't
|
|
|
|
* have to worry about using too much memory. I hope to be able to
|
2014-12-18 08:11:13 +00:00
|
|
|
* nuke the Xrealloc() at the end of this function eventually. */
|
|
|
|
newReg->rdh.nRgnSize = max(reg1->rdh.nCount + 1, reg2->rdh.nCount) * 2 * sizeof(RECT);
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
newReg->Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
newReg->rdh.nRgnSize,
|
|
|
|
TAG_REGION);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (newReg->Buffer == NULL)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
newReg->rdh.nRgnSize = 0;
|
2019-04-17 19:43:24 +00:00
|
|
|
return FALSE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Initialize ybot and ytop.
|
2002-07-18 21:59:18 +00:00
|
|
|
* In the upcoming loop, ybot and ytop serve different functions depending
|
|
|
|
* on whether the band being handled is an overlapping or non-overlapping
|
|
|
|
* band.
|
|
|
|
* In the case of a non-overlapping band (only one of the regions
|
|
|
|
* has points in the band), ybot is the bottom of the most recent
|
|
|
|
* intersection and thus clips the top of the rectangles in that band.
|
|
|
|
* ytop is the top of the next intersection between the two regions and
|
|
|
|
* serves to clip the bottom of the rectangles in the current band.
|
|
|
|
* For an overlapping band (where the two regions intersect), ytop clips
|
2014-12-18 08:11:13 +00:00
|
|
|
* the top of the rectangles of both regions and ybot clips the bottoms. */
|
2002-07-18 21:59:18 +00:00
|
|
|
if (reg1->rdh.rcBound.top < reg2->rdh.rcBound.top)
|
2008-02-21 02:40:23 +00:00
|
|
|
ybot = reg1->rdh.rcBound.top;
|
2002-07-18 21:59:18 +00:00
|
|
|
else
|
2008-02-21 02:40:23 +00:00
|
|
|
ybot = reg2->rdh.rcBound.top;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* prevBand serves to mark the start of the previous band so rectangles
|
2002-07-18 21:59:18 +00:00
|
|
|
* can be coalesced into larger rectangles. qv. miCoalesce, above.
|
|
|
|
* In the beginning, there is no previous band, so prevBand == curBand
|
|
|
|
* (curBand is set later on, of course, but the first band will always
|
|
|
|
* start at index 0). prevBand and curBand must be indices because of
|
|
|
|
* the possible expansion, and resultant moving, of the new region's
|
2014-12-18 08:11:13 +00:00
|
|
|
* array of rectangles. */
|
2002-07-18 21:59:18 +00:00
|
|
|
prevBand = 0;
|
|
|
|
do
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
curBand = newReg->rdh.nCount;
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* This algorithm proceeds one source-band (as opposed to a
|
2008-02-21 02:40:23 +00:00
|
|
|
* destination band, which is determined by where the two regions
|
|
|
|
* intersect) at a time. r1BandEnd and r2BandEnd serve to mark the
|
|
|
|
* rectangle after the last one in the current band for their
|
2014-12-18 08:11:13 +00:00
|
|
|
* respective regions. */
|
2008-02-21 02:40:23 +00:00
|
|
|
r1BandEnd = r1;
|
|
|
|
while ((r1BandEnd != r1End) && (r1BandEnd->top == r1->top))
|
|
|
|
{
|
|
|
|
r1BandEnd++;
|
|
|
|
}
|
|
|
|
|
|
|
|
r2BandEnd = r2;
|
|
|
|
while ((r2BandEnd != r2End) && (r2BandEnd->top == r2->top))
|
|
|
|
{
|
|
|
|
r2BandEnd++;
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* First handle the band that doesn't intersect, if any.
|
2008-02-21 02:40:23 +00:00
|
|
|
*
|
|
|
|
* Note that attention is restricted to one band in the
|
|
|
|
* non-intersecting region at once, so if a region has n
|
|
|
|
* bands between the current position and the next place it overlaps
|
2014-12-18 08:11:13 +00:00
|
|
|
* the other, this entire loop will be passed through n times. */
|
2008-02-21 02:40:23 +00:00
|
|
|
if (r1->top < r2->top)
|
|
|
|
{
|
|
|
|
top = max(r1->top,ybot);
|
|
|
|
bot = min(r1->bottom,r2->top);
|
|
|
|
|
|
|
|
if ((top != bot) && (nonOverlap1Func != NULL))
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!(*nonOverlap1Func)(newReg, r1, r1BandEnd, top, bot)) return FALSE;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ytop = r2->top;
|
|
|
|
}
|
|
|
|
else if (r2->top < r1->top)
|
|
|
|
{
|
|
|
|
top = max(r2->top,ybot);
|
|
|
|
bot = min(r2->bottom,r1->top);
|
|
|
|
|
|
|
|
if ((top != bot) && (nonOverlap2Func != NULL))
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!(*nonOverlap2Func)(newReg, r2, r2BandEnd, top, bot) ) return FALSE;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ytop = r1->top;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ytop = r1->top;
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* If any rectangles got added to the region, try and coalesce them
|
2008-02-21 02:40:23 +00:00
|
|
|
* with rectangles from the previous band. Note we could just do
|
|
|
|
* this test in miCoalesce, but some machines incur a not
|
2014-12-18 08:11:13 +00:00
|
|
|
* inconsiderable cost for function calls, so... */
|
2008-02-21 02:40:23 +00:00
|
|
|
if (newReg->rdh.nCount != curBand)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
prevBand = REGION_Coalesce(newReg, prevBand, curBand);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Now see if we've hit an intersecting band. The two bands only
|
|
|
|
* intersect if ybot > ytop */
|
2008-02-21 02:40:23 +00:00
|
|
|
ybot = min(r1->bottom, r2->bottom);
|
|
|
|
curBand = newReg->rdh.nCount;
|
|
|
|
if (ybot > ytop)
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!(*overlapFunc)(newReg, r1, r1BandEnd, r2, r2BandEnd, ytop, ybot)) return FALSE;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newReg->rdh.nCount != curBand)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
prevBand = REGION_Coalesce(newReg, prevBand, curBand);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* If we've finished with a band (bottom == ybot) we skip forward
|
|
|
|
* in the region to the next band. */
|
2008-02-21 02:40:23 +00:00
|
|
|
if (r1->bottom == ybot)
|
|
|
|
{
|
|
|
|
r1 = r1BandEnd;
|
|
|
|
}
|
|
|
|
if (r2->bottom == ybot)
|
|
|
|
{
|
|
|
|
r2 = r2BandEnd;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while ((r1 != r1End) && (r2 != r2End));
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Deal with whichever region still has rectangles left. */
|
2002-07-18 21:59:18 +00:00
|
|
|
curBand = newReg->rdh.nCount;
|
|
|
|
if (r1 != r1End)
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
if (nonOverlap1Func != NULL)
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
r1BandEnd = r1;
|
|
|
|
while ((r1BandEnd < r1End) && (r1BandEnd->top == r1->top))
|
|
|
|
{
|
|
|
|
r1BandEnd++;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!(*nonOverlap1Func)(newReg,
|
2014-12-18 08:11:13 +00:00
|
|
|
r1,
|
|
|
|
r1BandEnd,
|
|
|
|
max(r1->top,ybot),
|
2019-04-17 19:43:24 +00:00
|
|
|
r1->bottom))
|
|
|
|
return FALSE;
|
2008-02-21 02:40:23 +00:00
|
|
|
r1 = r1BandEnd;
|
|
|
|
}
|
|
|
|
while (r1 != r1End);
|
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2003-07-11 09:48:24 +00:00
|
|
|
else if ((r2 != r2End) && (nonOverlap2Func != NULL))
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
r2BandEnd = r2;
|
|
|
|
while ((r2BandEnd < r2End) && (r2BandEnd->top == r2->top))
|
|
|
|
{
|
|
|
|
r2BandEnd++;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!(*nonOverlap2Func)(newReg,
|
2014-12-18 08:11:13 +00:00
|
|
|
r2,
|
|
|
|
r2BandEnd,
|
|
|
|
max(r2->top,ybot),
|
2019-04-17 19:43:24 +00:00
|
|
|
r2->bottom))
|
|
|
|
return FALSE;
|
2008-02-21 02:40:23 +00:00
|
|
|
r2 = r2BandEnd;
|
|
|
|
}
|
|
|
|
while (r2 != r2End);
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (newReg->rdh.nCount != curBand)
|
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
(VOID)REGION_Coalesce(newReg, prevBand, curBand);
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* A bit of cleanup. To keep regions from growing without bound,
|
2002-07-18 21:59:18 +00:00
|
|
|
* we shrink the array of rectangles to match the new number of
|
|
|
|
* rectangles in the region. This never goes to 0, however...
|
|
|
|
*
|
|
|
|
* Only do this stuff if the number of rectangles allocated is more than
|
2014-12-18 08:11:13 +00:00
|
|
|
* twice the number of rectangles in the region (a simple optimization...). */
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((newReg->rdh.nRgnSize > (2 * newReg->rdh.nCount * sizeof(RECT))) &&
|
|
|
|
(newReg->rdh.nCount > 2))
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
if (REGION_NOT_EMPTY(newReg))
|
|
|
|
{
|
2009-03-19 01:42:34 +00:00
|
|
|
RECTL *prev_rects = newReg->Buffer;
|
2014-12-18 08:11:13 +00:00
|
|
|
newReg->Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
newReg->rdh.nCount * sizeof(RECT),
|
|
|
|
TAG_REGION);
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
if (newReg->Buffer == NULL)
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
newReg->Buffer = prev_rects;
|
2014-12-18 08:11:19 +00:00
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
newReg->rdh.nRgnSize = newReg->rdh.nCount*sizeof(RECT);
|
|
|
|
COPY_RECTS(newReg->Buffer, prev_rects, newReg->rdh.nCount);
|
|
|
|
if (prev_rects != &newReg->rdh.rcBound)
|
2008-11-04 23:49:07 +00:00
|
|
|
ExFreePoolWithTag(prev_rects, TAG_REGION);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* No point in doing the extra work involved in an Xrealloc if
|
|
|
|
* the region is empty */
|
2008-02-21 02:40:23 +00:00
|
|
|
newReg->rdh.nRgnSize = sizeof(RECT);
|
|
|
|
if (newReg->Buffer != &newReg->rdh.rcBound)
|
2008-11-04 23:49:07 +00:00
|
|
|
ExFreePoolWithTag(newReg->Buffer, TAG_REGION);
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
newReg->Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(RECT),
|
|
|
|
TAG_REGION);
|
2008-02-21 02:40:23 +00:00
|
|
|
ASSERT(newReg->Buffer);
|
|
|
|
}
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2008-05-27 01:38:01 +00:00
|
|
|
newReg->rdh.iType = RDH_RECTANGLES;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
|
|
|
if (oldRects != &newReg->rdh.rcBound)
|
2008-11-04 23:49:07 +00:00
|
|
|
ExFreePoolWithTag(oldRects, TAG_REGION);
|
2019-04-17 19:43:24 +00:00
|
|
|
return TRUE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* Region Intersection
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
|
2003-01-19 01:01:21 +00:00
|
|
|
/*!
|
2002-07-18 21:59:18 +00:00
|
|
|
* Handle an overlapping band for REGION_Intersect.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
2003-01-19 01:01:21 +00:00
|
|
|
* \note Side Effects:
|
2002-07-18 21:59:18 +00:00
|
|
|
* Rectangles may be added to the region.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2008-02-21 02:40:23 +00:00
|
|
|
REGION_IntersectO(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION pReg,
|
|
|
|
PRECTL r1,
|
|
|
|
PRECTL r1End,
|
|
|
|
PRECTL r2,
|
|
|
|
PRECTL r2End,
|
|
|
|
INT top,
|
|
|
|
INT bottom)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2014-12-18 08:12:55 +00:00
|
|
|
INT left, right;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
|
|
|
while ((r1 != r1End) && (r2 != r2End))
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
left = max(r1->left, r2->left);
|
2014-12-18 08:11:13 +00:00
|
|
|
right = min(r1->right, r2->right);
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* If there's any overlap between the two rectangles, add that
|
2008-02-21 02:40:23 +00:00
|
|
|
* overlap to the new region.
|
|
|
|
* There's no need to check for subsumption because the only way
|
|
|
|
* such a need could arise is if some region has two rectangles
|
2014-12-18 08:11:13 +00:00
|
|
|
* right next to each other. Since that should never happen... */
|
2008-02-21 02:40:23 +00:00
|
|
|
if (left < right)
|
|
|
|
{
|
2014-12-18 08:12:55 +00:00
|
|
|
if (!REGION_bAddRect(pReg, left, top, right, bottom))
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
return FALSE;
|
2014-12-18 08:12:55 +00:00
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Need to advance the pointers. Shift the one that extends
|
2008-02-21 02:40:23 +00:00
|
|
|
* to the right the least, since the other still has a chance to
|
2014-12-18 08:11:13 +00:00
|
|
|
* overlap with that region's next rectangle, if you see what I mean. */
|
2008-02-21 02:40:23 +00:00
|
|
|
if (r1->right < r2->right)
|
|
|
|
{
|
|
|
|
r1++;
|
|
|
|
}
|
|
|
|
else if (r2->right < r1->right)
|
|
|
|
{
|
|
|
|
r2++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
r1++;
|
|
|
|
r2++;
|
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
return TRUE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2014-12-18 08:11:13 +00:00
|
|
|
* REGION_IntersectRegion
|
2002-07-18 21:59:18 +00:00
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2008-02-21 02:40:23 +00:00
|
|
|
REGION_IntersectRegion(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION newReg,
|
|
|
|
PREGION reg1,
|
|
|
|
PREGION reg2)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2011-12-14 04:07:06 +00:00
|
|
|
/* Check for trivial reject */
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((reg1->rdh.nCount == 0) ||
|
|
|
|
(reg2->rdh.nCount == 0) ||
|
|
|
|
(EXTENTCHECK(®1->rdh.rcBound, ®2->rdh.rcBound) == 0))
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
newReg->rdh.nCount = 0;
|
2014-12-18 08:11:19 +00:00
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
else
|
2014-12-18 08:11:19 +00:00
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!REGION_RegionOp(newReg,
|
2014-12-18 08:11:13 +00:00
|
|
|
reg1,
|
|
|
|
reg2,
|
|
|
|
REGION_IntersectO,
|
|
|
|
NULL,
|
2019-04-17 19:43:24 +00:00
|
|
|
NULL))
|
|
|
|
return FALSE;
|
2014-12-18 08:11:19 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
|
|
|
/* Can't alter newReg's extents before we call miRegionOp because
|
2002-07-18 21:59:18 +00:00
|
|
|
* it might be one of the source regions and miRegionOp depends
|
|
|
|
* on the extents of those regions being the same. Besides, this
|
|
|
|
* way there's no checking against rectangles that will be nuked
|
2014-12-18 08:11:13 +00:00
|
|
|
* due to coalescing, so we have to examine fewer rectangles. */
|
2002-07-18 21:59:18 +00:00
|
|
|
REGION_SetExtents(newReg);
|
2019-04-17 19:43:24 +00:00
|
|
|
return TRUE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2014-12-18 08:11:13 +00:00
|
|
|
* Region Union
|
2002-07-18 21:59:18 +00:00
|
|
|
***********************************************************************/
|
|
|
|
|
2003-01-19 01:01:21 +00:00
|
|
|
/*!
|
2002-07-18 21:59:18 +00:00
|
|
|
* Handle a non-overlapping band for the union operation. Just
|
|
|
|
* Adds the rectangles into the region. Doesn't have to check for
|
|
|
|
* subsumption or anything.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
2003-01-19 01:01:21 +00:00
|
|
|
* \note Side Effects:
|
2002-07-18 21:59:18 +00:00
|
|
|
* pReg->numRects is incremented and the final rectangles overwritten
|
|
|
|
* with the rectangles we're passed.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
|
|
|
REGION_UnionNonO(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION pReg,
|
|
|
|
PRECTL r,
|
|
|
|
PRECTL rEnd,
|
|
|
|
INT top,
|
|
|
|
INT bottom)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2014-12-18 08:12:55 +00:00
|
|
|
if (r != rEnd)
|
|
|
|
{
|
|
|
|
if (!REGION_bEnsureBufferSize(pReg, pReg->rdh.nCount + (rEnd - r)))
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
return FALSE;
|
2014-12-18 08:12:55 +00:00
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
REGION_vAddRect(pReg, r->left, top, r->right, bottom);
|
|
|
|
r++;
|
|
|
|
}
|
|
|
|
while (r != rEnd);
|
|
|
|
}
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
return TRUE;
|
2014-12-18 08:12:55 +00:00
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
static __inline
|
|
|
|
BOOL
|
|
|
|
REGION_bMergeRect(
|
|
|
|
_Inout_ PREGION prgn,
|
|
|
|
_In_ LONG left,
|
|
|
|
_In_ LONG top,
|
|
|
|
_In_ LONG right,
|
|
|
|
_In_ LONG bottom)
|
|
|
|
{
|
|
|
|
if ((prgn->rdh.nCount != 0) &&
|
|
|
|
(prgn->Buffer[prgn->rdh.nCount - 1].top == top) &&
|
|
|
|
(prgn->Buffer[prgn->rdh.nCount - 1].bottom == bottom) &&
|
|
|
|
(prgn->Buffer[prgn->rdh.nCount - 1].right >= left))
|
|
|
|
{
|
|
|
|
if (prgn->Buffer[prgn->rdh.nCount - 1].right < right)
|
|
|
|
{
|
|
|
|
prgn->Buffer[prgn->rdh.nCount - 1].right = right;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2014-12-18 08:12:55 +00:00
|
|
|
if (!REGION_bAddRect(prgn, left, top, right, bottom))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
return TRUE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
2003-01-19 01:01:21 +00:00
|
|
|
/*!
|
2002-07-18 21:59:18 +00:00
|
|
|
* Handle an overlapping band for the union operation. Picks the
|
|
|
|
* left-most rectangle each time and merges it into the region.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
2003-01-19 01:01:21 +00:00
|
|
|
* \note Side Effects:
|
2002-07-18 21:59:18 +00:00
|
|
|
* Rectangles are overwritten in pReg->rects and pReg->numRects will
|
|
|
|
* be changed.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2003-08-13 00:50:25 +00:00
|
|
|
REGION_UnionO (
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION pReg,
|
|
|
|
PRECTL r1,
|
|
|
|
PRECTL r1End,
|
|
|
|
PRECTL r2,
|
|
|
|
PRECTL r2End,
|
|
|
|
INT top,
|
|
|
|
INT bottom)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
|
|
|
while ((r1 != r1End) && (r2 != r2End))
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
if (r1->left < r2->left)
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!REGION_bMergeRect(pReg, r1->left, top, r1->right, bottom)) return FALSE;
|
2014-12-18 08:12:55 +00:00
|
|
|
r1++;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!REGION_bMergeRect(pReg, r2->left, top, r2->right, bottom)) return FALSE;
|
2014-12-18 08:12:55 +00:00
|
|
|
r2++;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (r1 != r1End)
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
do
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!REGION_bMergeRect(pReg, r1->left, top, r1->right, bottom)) return FALSE;
|
2014-12-18 08:12:55 +00:00
|
|
|
r1++;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
while (r1 != r1End);
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
else
|
2014-12-18 08:11:19 +00:00
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
while (r2 != r2End)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!REGION_bMergeRect(pReg, r2->left, top, r2->right, bottom)) return FALSE;
|
2014-12-18 08:12:55 +00:00
|
|
|
r2++;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
return TRUE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2014-12-18 08:11:13 +00:00
|
|
|
* REGION_UnionRegion
|
2002-07-18 21:59:18 +00:00
|
|
|
*/
|
2014-12-18 08:11:19 +00:00
|
|
|
static
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:19 +00:00
|
|
|
FASTCALL
|
2008-02-21 02:40:23 +00:00
|
|
|
REGION_UnionRegion(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION newReg,
|
|
|
|
PREGION reg1,
|
|
|
|
PREGION reg2)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Checks all the simple cases
|
|
|
|
* Region 1 and 2 are the same or region 1 is empty */
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((reg1 == reg2) || (reg1->rdh.nCount == 0) ||
|
|
|
|
(reg1->rdh.rcBound.right <= reg1->rdh.rcBound.left) ||
|
|
|
|
(reg1->rdh.rcBound.bottom <= reg1->rdh.rcBound.top))
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
if (newReg != reg2)
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
ret = REGION_CopyRegion(newReg, reg2);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
return ret;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* If nothing to union (region 2 empty) */
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((reg2->rdh.nCount == 0) ||
|
|
|
|
(reg2->rdh.rcBound.right <= reg2->rdh.rcBound.left) ||
|
|
|
|
(reg2->rdh.rcBound.bottom <= reg2->rdh.rcBound.top))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
|
|
|
if (newReg != reg1)
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
ret = REGION_CopyRegion(newReg, reg1);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
return ret;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Region 1 completely subsumes region 2 */
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((reg1->rdh.nCount == 1) &&
|
|
|
|
(reg1->rdh.rcBound.left <= reg2->rdh.rcBound.left) &&
|
|
|
|
(reg1->rdh.rcBound.top <= reg2->rdh.rcBound.top) &&
|
|
|
|
(reg2->rdh.rcBound.right <= reg1->rdh.rcBound.right) &&
|
|
|
|
(reg2->rdh.rcBound.bottom <= reg1->rdh.rcBound.bottom))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
|
|
|
if (newReg != reg1)
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
ret = REGION_CopyRegion(newReg, reg1);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
return ret;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Region 2 completely subsumes region 1 */
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((reg2->rdh.nCount == 1) &&
|
|
|
|
(reg2->rdh.rcBound.left <= reg1->rdh.rcBound.left) &&
|
|
|
|
(reg2->rdh.rcBound.top <= reg1->rdh.rcBound.top) &&
|
|
|
|
(reg1->rdh.rcBound.right <= reg2->rdh.rcBound.right) &&
|
|
|
|
(reg1->rdh.rcBound.bottom <= reg2->rdh.rcBound.bottom))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
|
|
|
if (newReg != reg2)
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
ret = REGION_CopyRegion(newReg, reg2);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
return ret;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
if ((ret = REGION_RegionOp(newReg,
|
2014-12-18 08:11:19 +00:00
|
|
|
reg1,
|
|
|
|
reg2,
|
|
|
|
REGION_UnionO,
|
|
|
|
REGION_UnionNonO,
|
2019-04-17 19:43:24 +00:00
|
|
|
REGION_UnionNonO)))
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
newReg->rdh.rcBound.left = min(reg1->rdh.rcBound.left, reg2->rdh.rcBound.left);
|
|
|
|
newReg->rdh.rcBound.top = min(reg1->rdh.rcBound.top, reg2->rdh.rcBound.top);
|
|
|
|
newReg->rdh.rcBound.right = max(reg1->rdh.rcBound.right, reg2->rdh.rcBound.right);
|
|
|
|
newReg->rdh.rcBound.bottom = max(reg1->rdh.rcBound.bottom, reg2->rdh.rcBound.bottom);
|
2019-04-17 19:43:24 +00:00
|
|
|
}
|
|
|
|
return ret;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2014-12-18 08:11:13 +00:00
|
|
|
* Region Subtraction
|
2002-07-18 21:59:18 +00:00
|
|
|
***********************************************************************/
|
|
|
|
|
2003-01-19 01:01:21 +00:00
|
|
|
/*!
|
2002-07-18 21:59:18 +00:00
|
|
|
* Deal with non-overlapping band for subtraction. Any parts from
|
|
|
|
* region 2 we discard. Anything from region 1 we add to the region.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
2003-01-19 01:01:21 +00:00
|
|
|
* \note Side Effects:
|
2002-07-18 21:59:18 +00:00
|
|
|
* pReg may be affected.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2008-02-21 02:40:23 +00:00
|
|
|
REGION_SubtractNonO1(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION pReg,
|
|
|
|
PRECTL r,
|
|
|
|
PRECTL rEnd,
|
|
|
|
INT top,
|
|
|
|
INT bottom)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2014-12-18 08:12:55 +00:00
|
|
|
if (r != rEnd)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2014-12-18 08:12:55 +00:00
|
|
|
if (!REGION_bEnsureBufferSize(pReg, pReg->rdh.nCount + (rEnd - r)))
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
return FALSE;
|
2014-12-18 08:12:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
REGION_vAddRect(pReg, r->left, top, r->right, bottom);
|
|
|
|
r++;
|
|
|
|
}
|
|
|
|
while (r != rEnd);
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
return TRUE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-19 01:01:21 +00:00
|
|
|
/*!
|
2002-07-18 21:59:18 +00:00
|
|
|
* Overlapping band subtraction. x1 is the left-most point not yet
|
|
|
|
* checked.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* None.
|
|
|
|
*
|
2003-01-19 01:01:21 +00:00
|
|
|
* \note Side Effects:
|
2002-07-18 21:59:18 +00:00
|
|
|
* pReg may have rectangles added to it.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2008-02-21 02:40:23 +00:00
|
|
|
REGION_SubtractO(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION pReg,
|
|
|
|
PRECTL r1,
|
|
|
|
PRECTL r1End,
|
|
|
|
PRECTL r2,
|
|
|
|
PRECTL r2End,
|
|
|
|
INT top,
|
|
|
|
INT bottom)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
|
|
|
INT left;
|
|
|
|
|
|
|
|
left = r1->left;
|
|
|
|
|
|
|
|
while ((r1 != r1End) && (r2 != r2End))
|
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
if (r2->right <= left)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Subtrahend missed the boat: go to next subtrahend. */
|
2008-02-21 02:40:23 +00:00
|
|
|
r2++;
|
|
|
|
}
|
|
|
|
else if (r2->left <= left)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Subtrahend preceeds minuend: nuke left edge of minuend. */
|
2008-02-21 02:40:23 +00:00
|
|
|
left = r2->right;
|
|
|
|
if (left >= r1->right)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Minuend completely covered: advance to next minuend and
|
|
|
|
* reset left fence to edge of new minuend. */
|
2008-02-21 02:40:23 +00:00
|
|
|
r1++;
|
|
|
|
if (r1 != r1End)
|
|
|
|
left = r1->left;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Subtrahend now used up since it doesn't extend beyond
|
|
|
|
* minuend */
|
2008-02-21 02:40:23 +00:00
|
|
|
r2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (r2->left < r1->right)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Left part of subtrahend covers part of minuend: add uncovered
|
|
|
|
* part of minuend to region and skip to next subtrahend. */
|
2014-12-18 08:12:55 +00:00
|
|
|
if (!REGION_bAddRect(pReg, left, top, r2->left, bottom))
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
return FALSE;
|
2014-12-18 08:12:55 +00:00
|
|
|
}
|
|
|
|
|
2008-02-21 02:40:23 +00:00
|
|
|
left = r2->right;
|
|
|
|
if (left >= r1->right)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Minuend used up: advance to new... */
|
2008-02-21 02:40:23 +00:00
|
|
|
r1++;
|
|
|
|
if (r1 != r1End)
|
|
|
|
left = r1->left;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Subtrahend used up */
|
2008-02-21 02:40:23 +00:00
|
|
|
r2++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Minuend used up: add any remaining piece before advancing. */
|
2008-02-21 02:40:23 +00:00
|
|
|
if (r1->right > left)
|
|
|
|
{
|
2014-12-18 08:12:55 +00:00
|
|
|
if (!REGION_bAddRect(pReg, left, top, r1->right, bottom))
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
return FALSE;
|
2014-12-18 08:12:55 +00:00
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2008-02-21 02:40:23 +00:00
|
|
|
r1++;
|
2010-01-03 00:05:15 +00:00
|
|
|
if (r1 != r1End)
|
|
|
|
left = r1->left;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:12:55 +00:00
|
|
|
/* Make sure the buffer is large enough for all remaining operations */
|
|
|
|
if (r1 != r1End)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2014-12-18 08:12:55 +00:00
|
|
|
if (!REGION_bEnsureBufferSize(pReg, pReg->rdh.nCount + (r1End - r1)))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
return FALSE;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:12:55 +00:00
|
|
|
|
|
|
|
/* Add remaining minuend rectangles to region. */
|
|
|
|
do
|
|
|
|
{
|
|
|
|
REGION_vAddRect(pReg, left, top, r1->right, bottom);
|
|
|
|
r1++;
|
|
|
|
if (r1 != r1End)
|
|
|
|
{
|
|
|
|
left = r1->left;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (r1 != r1End);
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
return TRUE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
2003-01-19 01:01:21 +00:00
|
|
|
/*!
|
2002-07-18 21:59:18 +00:00
|
|
|
* Subtract regS from regM and leave the result in regD.
|
|
|
|
* S stands for subtrahend, M for minuend and D for difference.
|
|
|
|
*
|
|
|
|
* Results:
|
|
|
|
* TRUE.
|
|
|
|
*
|
2003-01-19 01:01:21 +00:00
|
|
|
* \note Side Effects:
|
2002-07-18 21:59:18 +00:00
|
|
|
* regD is overwritten.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2008-02-21 02:40:23 +00:00
|
|
|
REGION_SubtractRegion(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION regD,
|
|
|
|
PREGION regM,
|
|
|
|
PREGION regS)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2011-12-14 04:07:06 +00:00
|
|
|
/* Check for trivial reject */
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((regM->rdh.nCount == 0) ||
|
|
|
|
(regS->rdh.nCount == 0) ||
|
|
|
|
(EXTENTCHECK(®M->rdh.rcBound, ®S->rdh.rcBound) == 0))
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
return REGION_CopyRegion(regD, regM);
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!REGION_RegionOp(regD,
|
2014-12-18 08:11:13 +00:00
|
|
|
regM,
|
|
|
|
regS,
|
|
|
|
REGION_SubtractO,
|
|
|
|
REGION_SubtractNonO1,
|
2019-04-17 19:43:24 +00:00
|
|
|
NULL))
|
|
|
|
return FALSE;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Can't alter newReg's extents before we call miRegionOp because
|
2002-07-18 21:59:18 +00:00
|
|
|
* it might be one of the source regions and miRegionOp depends
|
|
|
|
* on the extents of those regions being the unaltered. Besides, this
|
|
|
|
* way there's no checking against rectangles that will be nuked
|
2014-12-18 08:11:13 +00:00
|
|
|
* due to coalescing, so we have to examine fewer rectangles. */
|
|
|
|
REGION_SetExtents(regD);
|
2019-04-17 19:43:24 +00:00
|
|
|
return TRUE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
2014-12-18 08:11:13 +00:00
|
|
|
* REGION_XorRegion
|
2002-07-18 21:59:18 +00:00
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2008-02-21 02:40:23 +00:00
|
|
|
REGION_XorRegion(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION dr,
|
|
|
|
PREGION sra,
|
|
|
|
PREGION srb)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
HRGN htra, htrb;
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION tra, trb;
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL ret;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2011-12-14 04:07:06 +00:00
|
|
|
// FIXME: Don't use a handle
|
2008-03-17 22:17:48 +00:00
|
|
|
tra = REGION_AllocRgnWithHandle(sra->rdh.nCount + 1);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (tra == NULL)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
return FALSE;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2008-03-17 22:17:48 +00:00
|
|
|
htra = tra->BaseObject.hHmgr;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2011-12-14 04:07:06 +00:00
|
|
|
// FIXME: Don't use a handle
|
2008-03-17 22:17:48 +00:00
|
|
|
trb = REGION_AllocRgnWithHandle(srb->rdh.nCount + 1);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (trb == NULL)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(tra);
|
2009-03-25 20:24:34 +00:00
|
|
|
GreDeleteObject(htra);
|
2019-04-17 19:43:24 +00:00
|
|
|
return FALSE;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2008-03-17 22:17:48 +00:00
|
|
|
htrb = trb->BaseObject.hHmgr;
|
2003-09-23 19:33:29 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
ret = REGION_SubtractRegion(tra, sra, srb) &&
|
|
|
|
REGION_SubtractRegion(trb, srb, sra) &&
|
|
|
|
REGION_UnionRegion(dr, tra, trb);
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(tra);
|
|
|
|
REGION_UnlockRgn(trb);
|
2003-09-23 19:33:29 +00:00
|
|
|
|
2009-03-25 20:24:34 +00:00
|
|
|
GreDeleteObject(htra);
|
|
|
|
GreDeleteObject(htrb);
|
2019-04-17 19:43:24 +00:00
|
|
|
return ret;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-01-19 01:01:21 +00:00
|
|
|
/*!
|
|
|
|
* Adds a rectangle to a REGION
|
2002-07-18 21:59:18 +00:00
|
|
|
*/
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2008-03-17 22:17:48 +00:00
|
|
|
REGION_UnionRectWithRgn(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION rgn,
|
2014-12-18 08:11:13 +00:00
|
|
|
const RECTL *rect)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
REGION region;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2004-04-09 20:03:21 +00:00
|
|
|
region.Buffer = ®ion.rdh.rcBound;
|
2002-07-18 21:59:18 +00:00
|
|
|
region.rdh.nCount = 1;
|
2008-02-21 02:40:23 +00:00
|
|
|
region.rdh.nRgnSize = sizeof(RECT);
|
2002-07-18 21:59:18 +00:00
|
|
|
region.rdh.rcBound = *rect;
|
2019-04-17 19:43:24 +00:00
|
|
|
return REGION_UnionRegion(rgn, rgn, ®ion);
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
2014-09-24 21:23:03 +00:00
|
|
|
INT
|
|
|
|
FASTCALL
|
|
|
|
REGION_SubtractRectFromRgn(
|
|
|
|
PREGION prgnDest,
|
|
|
|
PREGION prgnSrc,
|
|
|
|
const RECTL *prcl)
|
|
|
|
{
|
|
|
|
REGION rgnLocal;
|
|
|
|
|
|
|
|
rgnLocal.Buffer = &rgnLocal.rdh.rcBound;
|
|
|
|
rgnLocal.rdh.nCount = 1;
|
|
|
|
rgnLocal.rdh.nRgnSize = sizeof(RECT);
|
|
|
|
rgnLocal.rdh.rcBound = *prcl;
|
|
|
|
REGION_SubtractRegion(prgnDest, prgnSrc, &rgnLocal);
|
|
|
|
return REGION_Complexity(prgnDest);
|
|
|
|
}
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
REGION_bCopy(
|
|
|
|
PREGION dst,
|
|
|
|
PREGION src)
|
|
|
|
{
|
|
|
|
if ( !dst || !src ) return FALSE;
|
|
|
|
return REGION_CopyRegion( dst, src);
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
REGION_bIntersectRegion(
|
|
|
|
PREGION newReg,
|
|
|
|
PREGION reg1,
|
|
|
|
PREGION reg2)
|
|
|
|
{
|
|
|
|
if ( !newReg || !reg1 || !reg2 ) return FALSE;
|
|
|
|
return REGION_IntersectRegion( newReg, reg1, reg2);
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
static
|
2014-12-18 08:11:13 +00:00
|
|
|
BOOL
|
2014-12-18 08:12:51 +00:00
|
|
|
REGION_bMakeSimpleFrameRgn(
|
|
|
|
_Inout_ PREGION prgn,
|
|
|
|
_In_ PRECTL prclSrc,
|
|
|
|
_In_ INT cx,
|
|
|
|
_In_ INT cy)
|
2007-10-28 20:07:28 +00:00
|
|
|
{
|
2014-12-18 08:12:51 +00:00
|
|
|
RECTL arcl[4];
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
NT_ASSERT((cx >= 0) && (cy >= 0));
|
|
|
|
NT_ASSERT((prclSrc->bottom > prclSrc->top) &&
|
|
|
|
(prclSrc->right > prclSrc->left));
|
2007-10-28 20:07:28 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Start with an empty region */
|
|
|
|
EMPTY_REGION(prgn);
|
|
|
|
|
|
|
|
/* Check for the case where the frame covers the whole rect */
|
|
|
|
if (((prclSrc->bottom - prclSrc->top) <= cy * 2) ||
|
|
|
|
((prclSrc->right - prclSrc->left) <= cx * 2))
|
2007-10-28 20:07:28 +00:00
|
|
|
{
|
2014-12-18 08:12:51 +00:00
|
|
|
prgn->rdh.rcBound = *prclSrc;
|
|
|
|
prgn->Buffer[0] = *prclSrc;
|
|
|
|
prgn->rdh.nCount = 1;
|
|
|
|
return TRUE;
|
|
|
|
}
|
2007-10-28 20:07:28 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
i = 0;
|
2007-10-28 20:07:28 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
if (cy != 0)
|
|
|
|
{
|
|
|
|
/* Top rectangle */
|
|
|
|
arcl[i].left = prclSrc->left;
|
|
|
|
arcl[i].top = prclSrc->top;
|
|
|
|
arcl[i].right = prclSrc->right;
|
|
|
|
arcl[i].bottom = prclSrc->top + cy;
|
|
|
|
i++;
|
|
|
|
}
|
2007-10-28 20:07:28 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
if (cx != 0)
|
|
|
|
{
|
|
|
|
/* Left rectangle */
|
|
|
|
arcl[i].left = prclSrc->left;
|
|
|
|
arcl[i].top = prclSrc->top + cy;
|
|
|
|
arcl[i].right = prclSrc->left + cx;
|
|
|
|
arcl[i].bottom = prclSrc->bottom - cy;
|
|
|
|
i++;
|
|
|
|
|
|
|
|
/* Right rectangle */
|
|
|
|
arcl[i].left = prclSrc->right - cx;
|
|
|
|
arcl[i].top = prclSrc->top + cy;
|
|
|
|
arcl[i].right = prclSrc->right;
|
|
|
|
arcl[i].bottom = prclSrc->bottom - cy;
|
|
|
|
i++;
|
|
|
|
}
|
2007-10-28 20:07:28 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
if (cy != 0)
|
|
|
|
{
|
|
|
|
/* Bottom rectangle */
|
|
|
|
arcl[i].left = prclSrc->left;
|
|
|
|
arcl[i].top = prclSrc->bottom - cy;
|
|
|
|
arcl[i].right = prclSrc->right;
|
|
|
|
arcl[i].bottom = prclSrc->bottom;
|
|
|
|
i++;
|
|
|
|
}
|
2007-10-28 20:07:28 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
if (i != 0)
|
|
|
|
{
|
|
|
|
/* The frame results in a complex region. rcBounds remains
|
|
|
|
the same, though. */
|
|
|
|
prgn->rdh.nCount = i;
|
|
|
|
NT_ASSERT(prgn->rdh.nCount > 1);
|
|
|
|
prgn->rdh.nRgnSize = prgn->rdh.nCount * sizeof(RECT);
|
|
|
|
NT_ASSERT(prgn->Buffer == &prgn->rdh.rcBound);
|
|
|
|
prgn->Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
prgn->rdh.nRgnSize,
|
|
|
|
TAG_REGION);
|
|
|
|
if (prgn->Buffer == NULL)
|
|
|
|
{
|
|
|
|
prgn->rdh.nRgnSize = 0;
|
|
|
|
return FALSE;
|
2007-10-28 20:07:28 +00:00
|
|
|
}
|
2014-12-18 08:12:51 +00:00
|
|
|
|
|
|
|
_PRAGMA_WARNING_SUPPRESS(__WARNING_MAYBE_UNINIT_VAR) // arcl is initialized
|
|
|
|
COPY_RECTS(prgn->Buffer, arcl, prgn->rdh.nCount);
|
2007-10-28 20:07:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:50 +00:00
|
|
|
static
|
2014-12-18 08:11:19 +00:00
|
|
|
BOOL
|
2014-12-18 08:11:50 +00:00
|
|
|
REGION_bMakeFrameRegion(
|
|
|
|
_Inout_ PREGION prgnDest,
|
2014-12-18 08:12:51 +00:00
|
|
|
_Inout_ PREGION prgnSrc,
|
2014-12-18 08:11:50 +00:00
|
|
|
_In_ INT cx,
|
|
|
|
_In_ INT cy)
|
2004-04-24 14:21:37 +00:00
|
|
|
{
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Handle negative cx / cy */
|
|
|
|
cx = abs(cx);
|
|
|
|
cy = abs(cy);
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Check border size (the cast is necessary to catch cx/cy == INT_MIN!) */
|
|
|
|
if (((UINT)cx > MAX_COORD) || ((UINT)cy > MAX_COORD))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Fail on empty source region */
|
|
|
|
if (!REGION_NOT_EMPTY(prgnSrc))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Handle trivial case */
|
|
|
|
if ((cx == 0) && (cy == 0))
|
|
|
|
{
|
|
|
|
EMPTY_REGION(prgnDest);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle simple source region */
|
2014-12-18 08:11:50 +00:00
|
|
|
if (REGION_Complexity(prgnSrc) == SIMPLEREGION)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:12:51 +00:00
|
|
|
return REGION_bMakeSimpleFrameRgn(prgnDest, &prgnSrc->rdh.rcBound, cx, cy);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:12:51 +00:00
|
|
|
|
|
|
|
/* Check if we can move the region to create the frame region */
|
|
|
|
if ((prgnSrc->rdh.rcBound.left < (MIN_COORD + cx)) ||
|
|
|
|
(prgnSrc->rdh.rcBound.top < (MIN_COORD + cy)) ||
|
|
|
|
(prgnSrc->rdh.rcBound.right > (MAX_COORD - cx)) ||
|
|
|
|
(prgnSrc->rdh.rcBound.bottom > (MAX_COORD - cy)))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Copy the source region */
|
|
|
|
if (!REGION_CopyRegion(prgnDest, prgnSrc))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:12:51 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Move the source region to the bottom-right */
|
|
|
|
NT_VERIFY(REGION_bOffsetRgn(prgnSrc, cx, cy));
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Intersect with the source region (this crops the top-left frame) */
|
|
|
|
REGION_IntersectRegion(prgnDest, prgnDest, prgnSrc);
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Move the source region to the bottom-left */
|
|
|
|
NT_VERIFY(REGION_bOffsetRgn(prgnSrc, -2 * cx, 0));
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Intersect with the source region (this crops the top-right frame) */
|
|
|
|
REGION_IntersectRegion(prgnDest, prgnDest, prgnSrc);
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Move the source region to the top-left */
|
|
|
|
NT_VERIFY(REGION_bOffsetRgn(prgnSrc, 0, -2 * cy));
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Intersect with the source region (this crops the bottom-right frame) */
|
|
|
|
REGION_IntersectRegion(prgnDest, prgnDest, prgnSrc);
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Move the source region to the top-right */
|
|
|
|
NT_VERIFY(REGION_bOffsetRgn(prgnSrc, 2 * cx, 0));
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Intersect with the source region (this crops the bottom-left frame) */
|
|
|
|
REGION_IntersectRegion(prgnDest, prgnDest, prgnSrc);
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2014-12-18 08:12:51 +00:00
|
|
|
/* Move the source region back to the original position */
|
|
|
|
NT_VERIFY(REGION_bOffsetRgn(prgnSrc, -cx, cy));
|
|
|
|
|
|
|
|
/* Finally subtract the cropped region from the source */
|
|
|
|
REGION_SubtractRegion(prgnDest, prgnSrc, prgnDest);
|
2008-02-21 02:40:23 +00:00
|
|
|
|
|
|
|
return TRUE;
|
2004-04-24 14:21:37 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:50 +00:00
|
|
|
HRGN
|
|
|
|
FASTCALL
|
|
|
|
GreCreateFrameRgn(
|
|
|
|
HRGN hrgn,
|
|
|
|
INT cx,
|
|
|
|
INT cy)
|
|
|
|
{
|
|
|
|
PREGION prgnFrame, prgnSrc;
|
|
|
|
HRGN hrgnFrame;
|
|
|
|
|
|
|
|
/* Allocate a new region */
|
|
|
|
prgnFrame = REGION_AllocUserRgnWithHandle(1);
|
|
|
|
if (prgnFrame == NULL)
|
|
|
|
{
|
|
|
|
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Lock the source region */
|
2014-12-19 10:34:52 +00:00
|
|
|
prgnSrc = REGION_LockRgn(hrgn);
|
2014-12-18 08:11:50 +00:00
|
|
|
if (prgnSrc == NULL)
|
|
|
|
{
|
|
|
|
REGION_Delete(prgnFrame);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (REGION_bMakeFrameRegion(prgnFrame, prgnSrc, cx, cy))
|
|
|
|
{
|
|
|
|
hrgnFrame = prgnFrame->BaseObject.hHmgr;
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(prgnFrame);
|
2014-12-18 08:11:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
REGION_Delete(prgnFrame);
|
|
|
|
hrgnFrame = NULL;
|
|
|
|
}
|
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(prgnSrc);
|
2014-12-18 08:11:50 +00:00
|
|
|
return hrgnFrame;
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
2014-12-18 08:12:06 +00:00
|
|
|
REGION_bXformRgn(
|
|
|
|
_Inout_ PREGION prgn,
|
|
|
|
_In_ PMATRIX pmx)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2014-12-18 08:12:06 +00:00
|
|
|
XFORMOBJ xo;
|
|
|
|
ULONG i, j, cjSize;
|
|
|
|
PPOINT ppt;
|
|
|
|
PULONG pcPoints;
|
|
|
|
RECT rect;
|
|
|
|
BOOL bResult;
|
|
|
|
|
2017-02-22 10:48:41 +00:00
|
|
|
/* Check for zero rectangles and return TRUE for translation only matrices */
|
|
|
|
if (prgn->rdh.nCount < 1)
|
2017-02-22 21:18:18 +00:00
|
|
|
return (pmx->flAccel & XFORM_UNITY) != 0;
|
2017-02-22 10:48:41 +00:00
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Check if this is a scaling only matrix (off-diagonal elements are 0 */
|
|
|
|
if (pmx->flAccel & XFORM_SCALE)
|
|
|
|
{
|
|
|
|
/* Check if this is a translation only matrix */
|
|
|
|
if (pmx->flAccel & XFORM_UNITY)
|
|
|
|
{
|
|
|
|
/* Just offset the region */
|
2014-12-18 08:12:41 +00:00
|
|
|
return REGION_bOffsetRgn(prgn, (pmx->fxDx + 8) / 16, (pmx->fxDy + 8) / 16);
|
2014-12-18 08:12:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Initialize the xform object */
|
|
|
|
XFORMOBJ_vInit(&xo, pmx);
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Scaling can move the rects out of the coordinate space, so
|
|
|
|
* we first need to check whether we can apply the transformation
|
|
|
|
* on the bounds rect without modifying the region */
|
|
|
|
if (!XFORMOBJ_bApplyXform(&xo, XF_LTOL, 2, &prgn->rdh.rcBound, &rect))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Apply the xform to the rects in the region */
|
|
|
|
if (!XFORMOBJ_bApplyXform(&xo,
|
|
|
|
XF_LTOL,
|
|
|
|
prgn->rdh.nCount * 2,
|
|
|
|
prgn->Buffer,
|
|
|
|
prgn->Buffer))
|
|
|
|
{
|
|
|
|
/* This can not happen, since we already checked the bounds! */
|
|
|
|
NT_ASSERT(FALSE);
|
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Reset bounds */
|
|
|
|
RECTL_vSetEmptyRect(&prgn->rdh.rcBound);
|
|
|
|
|
|
|
|
/* Loop all rects in the region */
|
|
|
|
for (i = 0; i < prgn->rdh.nCount; i++)
|
|
|
|
{
|
|
|
|
/* Make sure the rect is well-ordered after the xform */
|
|
|
|
RECTL_vMakeWellOrdered(&prgn->Buffer[i]);
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Update bounds */
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!RECTL_bUnionRect(&prgn->rdh.rcBound,
|
2014-12-18 08:12:06 +00:00
|
|
|
&prgn->rdh.rcBound,
|
2019-04-17 19:43:24 +00:00
|
|
|
&prgn->Buffer[i]))
|
|
|
|
{
|
|
|
|
DPRINT1("NULL Set in Union Rects\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-12-18 08:12:06 +00:00
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Loop all rects in the region */
|
|
|
|
for (i = 0; i < prgn->rdh.nCount - 1; i++)
|
|
|
|
{
|
|
|
|
for (j = i; i < prgn->rdh.nCount; i++)
|
|
|
|
{
|
|
|
|
NT_ASSERT(prgn->Buffer[i].top < prgn->Buffer[i].bottom);
|
|
|
|
NT_ASSERT(prgn->Buffer[j].top >= prgn->Buffer[i].top);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Allocate a buffer for the polygons */
|
|
|
|
cjSize = prgn->rdh.nCount * (4 * sizeof(POINT) + sizeof(ULONG));
|
|
|
|
ppt = ExAllocatePoolWithTag(PagedPool, cjSize, GDITAG_REGION);
|
|
|
|
if (ppt == NULL)
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Fill the buffer with the rects */
|
|
|
|
pcPoints = (PULONG)&ppt[4 * prgn->rdh.nCount];
|
|
|
|
for (i = 0; i < prgn->rdh.nCount; i++)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Make sure the rect is within the legal range */
|
|
|
|
pcPoints[i] = 4;
|
|
|
|
ppt[4 * i + 0].x = prgn->Buffer[i].left;
|
|
|
|
ppt[4 * i + 0].y = prgn->Buffer[i].top;
|
|
|
|
ppt[4 * i + 1].x = prgn->Buffer[i].right;
|
|
|
|
ppt[4 * i + 1].y = prgn->Buffer[i].top;
|
|
|
|
ppt[4 * i + 2].x = prgn->Buffer[i].right;
|
|
|
|
ppt[4 * i + 2].y = prgn->Buffer[i].bottom;
|
|
|
|
ppt[4 * i + 3].x = prgn->Buffer[i].left;
|
|
|
|
ppt[4 * i + 3].y = prgn->Buffer[i].bottom;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Initialize the xform object */
|
|
|
|
XFORMOBJ_vInit(&xo, pmx);
|
|
|
|
|
|
|
|
/* Apply the xform to the rects in the buffer */
|
|
|
|
if (!XFORMOBJ_bApplyXform(&xo,
|
|
|
|
XF_LTOL,
|
|
|
|
prgn->rdh.nCount * 2,
|
|
|
|
ppt,
|
|
|
|
ppt))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:12:06 +00:00
|
|
|
/* This means, there were coordinates that would go outside of
|
|
|
|
the coordinate space after the transformation */
|
|
|
|
ExFreePoolWithTag(ppt, GDITAG_REGION);
|
|
|
|
return FALSE;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
/* Now use the polygons to create a polygon region */
|
|
|
|
bResult = REGION_SetPolyPolygonRgn(prgn,
|
|
|
|
ppt,
|
|
|
|
pcPoints,
|
|
|
|
prgn->rdh.nCount,
|
|
|
|
WINDING);
|
|
|
|
|
|
|
|
/* Free the polygon buffer */
|
|
|
|
ExFreePoolWithTag(ppt, GDITAG_REGION);
|
|
|
|
|
|
|
|
return bResult;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION
|
2008-04-06 23:20:31 +00:00
|
|
|
FASTCALL
|
2014-12-18 08:11:13 +00:00
|
|
|
REGION_AllocRgnWithHandle(
|
|
|
|
INT nReg)
|
2002-07-18 21:59:18 +00:00
|
|
|
{
|
2011-09-11 16:56:56 +00:00
|
|
|
//HRGN hReg;
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION pReg;
|
2010-07-12 16:52:10 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
pReg = (PREGION)GDIOBJ_AllocateObject(GDIObjType_RGN_TYPE,
|
|
|
|
sizeof(REGION),
|
|
|
|
BASEFLAG_LOOKASIDE);
|
|
|
|
if (pReg == NULL)
|
2004-04-03 20:36:56 +00:00
|
|
|
{
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
DPRINT1("Could not allocate a palette.\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-09-11 16:56:56 +00:00
|
|
|
//hReg = pReg->BaseObject.hHmgr;
|
2004-04-03 20:36:56 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((nReg == 0) || (nReg == 1))
|
2008-04-06 23:20:31 +00:00
|
|
|
{
|
|
|
|
/* Testing shows that > 95% of all regions have only 1 rect.
|
|
|
|
Including that here saves us from having to do another allocation */
|
|
|
|
pReg->Buffer = &pReg->rdh.rcBound;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
pReg->Buffer = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
nReg * sizeof(RECT),
|
|
|
|
TAG_REGION);
|
|
|
|
if (pReg->Buffer == NULL)
|
2004-04-03 20:36:56 +00:00
|
|
|
{
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
DPRINT1("Could not allocate region buffer\n");
|
|
|
|
GDIOBJ_vDeleteObject(&pReg->BaseObject);
|
2008-04-06 23:20:31 +00:00
|
|
|
return NULL;
|
2004-04-03 20:36:56 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2008-04-06 23:20:31 +00:00
|
|
|
EMPTY_REGION(pReg);
|
|
|
|
pReg->rdh.dwSize = sizeof(RGNDATAHEADER);
|
|
|
|
pReg->rdh.nCount = nReg;
|
|
|
|
pReg->rdh.nRgnSize = nReg * sizeof(RECT);
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
pReg->prgnattr = &pReg->rgnattr;
|
2008-04-06 23:20:31 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Initialize the region attribute */
|
|
|
|
pReg->rgnattr.AttrFlags = 0;
|
|
|
|
pReg->rgnattr.iComplexity = SIMPLEREGION;
|
|
|
|
pReg->rgnattr.Rect = pReg->rdh.rcBound;
|
|
|
|
|
|
|
|
/* Finally insert the region into the handle table */
|
|
|
|
if (!GDIOBJ_hInsertObject(&pReg->BaseObject, GDI_OBJ_HMGR_POWNED))
|
|
|
|
{
|
|
|
|
DPRINT1("Could not insert palette into handle table.\n");
|
|
|
|
GDIOBJ_vFreeObject(&pReg->BaseObject);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2008-04-06 23:20:31 +00:00
|
|
|
return pReg;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
|
|
|
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
BOOL
|
|
|
|
NTAPI
|
2014-12-18 08:11:13 +00:00
|
|
|
REGION_bAllocRgnAttr(
|
|
|
|
PREGION prgn)
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
PPROCESSINFO ppi;
|
|
|
|
PRGN_ATTR prgnattr;
|
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
NT_ASSERT(prgn->prgnattr == &prgn->rgnattr);
|
|
|
|
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
ppi = PsGetCurrentProcessWin32Process();
|
|
|
|
ASSERT(ppi);
|
|
|
|
|
|
|
|
prgnattr = GdiPoolAllocate(ppi->pPoolRgnAttr);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (prgnattr == NULL)
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Could not allocate RGN attr\n");
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Copy the current region attribute */
|
|
|
|
*prgnattr = prgn->rgnattr;
|
|
|
|
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
/* Set the object attribute in the handle table */
|
|
|
|
prgn->prgnattr = prgnattr;
|
|
|
|
GDIOBJ_vSetObjectAttr(&prgn->BaseObject, prgnattr);
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-25 01:33:01 +00:00
|
|
|
//
|
|
|
|
// Allocate User Space Region Handle.
|
|
|
|
//
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION
|
2010-01-25 01:33:01 +00:00
|
|
|
FASTCALL
|
2014-12-18 08:11:13 +00:00
|
|
|
REGION_AllocUserRgnWithHandle(
|
|
|
|
INT nRgn)
|
2010-01-25 01:33:01 +00:00
|
|
|
{
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
PREGION prgn;
|
|
|
|
|
|
|
|
prgn = REGION_AllocRgnWithHandle(nRgn);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (prgn == NULL)
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2010-01-25 01:33:01 +00:00
|
|
|
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
if (!REGION_bAllocRgnAttr(prgn))
|
2010-01-25 01:33:01 +00:00
|
|
|
{
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
ASSERT(FALSE);
|
2010-01-25 01:33:01 +00:00
|
|
|
}
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
|
|
|
|
return prgn;
|
2010-01-25 01:33:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:13:06 +00:00
|
|
|
static
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
VOID
|
2014-12-18 08:11:13 +00:00
|
|
|
REGION_vSyncRegion(
|
2015-03-10 00:11:29 +00:00
|
|
|
_In_ PREGION prgn)
|
2009-12-26 19:19:33 +00:00
|
|
|
{
|
2014-12-18 08:13:06 +00:00
|
|
|
PRGN_ATTR prgnattr;
|
|
|
|
|
|
|
|
NT_ASSERT(prgn != NULL);
|
|
|
|
NT_ASSERT(prgn->prgnattr != NULL);
|
|
|
|
NT_ASSERT((prgn->prgnattr == &prgn->rgnattr) ||
|
|
|
|
(prgn->prgnattr->AttrFlags & ATTR_RGN_VALID));
|
2009-12-26 19:19:33 +00:00
|
|
|
|
2014-12-18 08:13:06 +00:00
|
|
|
/* Get the region attribute and check if it's dirty (modified) */
|
|
|
|
prgnattr = prgn->prgnattr;
|
|
|
|
if (prgnattr->AttrFlags & ATTR_RGN_DIRTY)
|
2014-12-18 08:11:13 +00:00
|
|
|
{
|
2014-12-18 08:13:06 +00:00
|
|
|
NT_ASSERT(GreGetObjectOwner(prgn->BaseObject.hHmgr) == GDI_OBJ_HMGR_POWNED);
|
|
|
|
NT_ASSERT(prgnattr != &prgn->rgnattr);
|
2009-12-30 22:56:09 +00:00
|
|
|
|
2014-12-18 08:13:06 +00:00
|
|
|
if (prgnattr->iComplexity == NULLREGION)
|
2009-12-30 22:56:09 +00:00
|
|
|
{
|
2014-12-18 08:13:06 +00:00
|
|
|
EMPTY_REGION(prgn);
|
|
|
|
}
|
|
|
|
else if (prgnattr->iComplexity == SIMPLEREGION)
|
|
|
|
{
|
|
|
|
REGION_SetRectRgn(prgn,
|
|
|
|
prgnattr->Rect.left,
|
|
|
|
prgnattr->Rect.top,
|
|
|
|
prgnattr->Rect.right,
|
|
|
|
prgnattr->Rect.bottom);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Should not happen, region attribute is corrupted! */
|
|
|
|
DPRINT1("Region attribute is corrupted, ignoring\n");
|
|
|
|
NT_ASSERT(FALSE);
|
2009-12-30 22:56:09 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
}
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
|
2014-12-18 08:13:06 +00:00
|
|
|
/* Reset the flags */
|
|
|
|
prgnattr->AttrFlags &= ~(ATTR_RGN_DIRTY | ATTR_RGN_VALID);
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
FASTCALL
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_LockRgn(
|
|
|
|
_In_ HRGN hrgn)
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
{
|
2014-12-19 10:34:52 +00:00
|
|
|
PREGION prgn;
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
prgn = GDIOBJ_LockObject(hrgn, GDIObjType_RGN_TYPE);
|
|
|
|
if (prgn == NULL)
|
2014-12-18 08:11:19 +00:00
|
|
|
return NULL;
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_vSyncRegion(prgn);
|
|
|
|
return prgn;
|
2009-12-26 19:19:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
VOID
|
|
|
|
FASTCALL
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(
|
|
|
|
_In_ PREGION prgn)
|
2009-12-26 19:19:33 +00:00
|
|
|
{
|
2014-12-18 08:13:06 +00:00
|
|
|
PRGN_ATTR prgnattr;
|
2009-12-26 19:19:33 +00:00
|
|
|
|
2014-12-18 08:13:06 +00:00
|
|
|
NT_ASSERT(prgn != NULL);
|
|
|
|
NT_ASSERT(prgn->prgnattr != NULL);
|
2009-12-30 22:56:09 +00:00
|
|
|
|
2014-12-18 08:13:06 +00:00
|
|
|
/* Get the region attribute and check if it's user mode */
|
|
|
|
prgnattr = prgn->prgnattr;
|
|
|
|
if (prgnattr != &prgn->rgnattr)
|
|
|
|
{
|
|
|
|
NT_ASSERT(GreGetObjectOwner(prgn->BaseObject.hHmgr) == GDI_OBJ_HMGR_POWNED);
|
|
|
|
prgnattr->iComplexity = REGION_Complexity(prgn);
|
|
|
|
prgnattr->Rect.left = prgn->rdh.rcBound.left;
|
|
|
|
prgnattr->Rect.top = prgn->rdh.rcBound.top;
|
|
|
|
prgnattr->Rect.right = prgn->rdh.rcBound.right;
|
|
|
|
prgnattr->Rect.bottom = prgn->rdh.rcBound.bottom;
|
|
|
|
prgnattr->AttrFlags |= ATTR_RGN_VALID;
|
2014-12-18 08:11:13 +00:00
|
|
|
}
|
2014-12-18 08:13:06 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
GDIOBJ_vUnlockObject(&prgn->BaseObject);
|
2009-12-26 19:19:33 +00:00
|
|
|
}
|
|
|
|
|
2010-01-21 00:14:06 +00:00
|
|
|
/*
|
|
|
|
System Regions:
|
|
|
|
These regions do not use attribute sections and when allocated, use gdiobj
|
|
|
|
level functions.
|
|
|
|
*/
|
2010-01-21 02:58:52 +00:00
|
|
|
//
|
|
|
|
// System Region Functions
|
|
|
|
//
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION
|
2010-01-21 02:58:52 +00:00
|
|
|
FASTCALL
|
2014-12-18 08:11:13 +00:00
|
|
|
IntSysCreateRectpRgn(
|
|
|
|
INT LeftRect,
|
|
|
|
INT TopRect,
|
|
|
|
INT RightRect,
|
|
|
|
INT BottomRect)
|
2010-01-21 02:58:52 +00:00
|
|
|
{
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
PREGION prgn;
|
2010-01-21 02:58:52 +00:00
|
|
|
|
2015-06-09 17:43:00 +00:00
|
|
|
/* Allocate a region, without a handle */
|
2014-09-17 09:54:27 +00:00
|
|
|
prgn = (PREGION)GDIOBJ_AllocateObject(GDIObjType_RGN_TYPE, sizeof(REGION), BASEFLAG_LOOKASIDE);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (prgn == NULL)
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize it */
|
|
|
|
prgn->Buffer = &prgn->rdh.rcBound;
|
|
|
|
prgn->prgnattr = &prgn->rgnattr;
|
2014-12-18 08:13:06 +00:00
|
|
|
prgn->prgnattr->AttrFlags = ATTR_RGN_VALID;
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
REGION_SetRectRgn(prgn, LeftRect, TopRect, RightRect, BottomRect);
|
|
|
|
|
|
|
|
return prgn;
|
2010-01-25 01:33:01 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
VOID
|
|
|
|
NTAPI
|
2014-05-22 11:45:53 +00:00
|
|
|
REGION_vCleanup(PVOID ObjectBody)
|
2002-07-17 21:04:57 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION pRgn = (PREGION)ObjectBody;
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
PPROCESSINFO ppi = PsGetCurrentProcessWin32Process();
|
|
|
|
ASSERT(ppi);
|
|
|
|
|
|
|
|
ASSERT(pRgn->prgnattr);
|
|
|
|
if (pRgn->prgnattr != &pRgn->rgnattr)
|
|
|
|
GdiPoolFree(ppi->pPoolRgnAttr, pRgn->prgnattr);
|
|
|
|
|
2008-02-21 02:40:23 +00:00
|
|
|
if (pRgn->Buffer && pRgn->Buffer != &pRgn->rdh.rcBound)
|
2010-07-12 16:52:10 +00:00
|
|
|
ExFreePoolWithTag(pRgn->Buffer, TAG_REGION);
|
2002-07-17 21:04:57 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
2014-12-18 08:11:19 +00:00
|
|
|
REGION_Delete(PREGION pRgn)
|
2008-06-17 05:19:08 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
if (pRgn == prgnDefault)
|
|
|
|
return;
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
GDIOBJ_vDeleteObject(&pRgn->BaseObject);
|
2008-06-17 05:19:08 +00:00
|
|
|
}
|
|
|
|
|
2011-03-29 23:44:22 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
IntGdiSetRegionOwner(HRGN hRgn, DWORD OwnerMask)
|
|
|
|
{
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
PREGION prgn;
|
|
|
|
PRGN_ATTR prgnattr;
|
|
|
|
PPROCESSINFO ppi;
|
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
prgn = REGION_LockRgn(hRgn);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (prgn == NULL)
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
prgnattr = prgn->prgnattr;
|
2014-09-17 11:40:21 +00:00
|
|
|
if (prgnattr != &prgn->rgnattr)
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
GDIOBJ_vSetObjectAttr(&prgn->BaseObject, NULL);
|
2014-09-17 11:40:21 +00:00
|
|
|
prgn->prgnattr = &prgn->rgnattr;
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
ppi = PsGetCurrentProcessWin32Process();
|
|
|
|
GdiPoolFree(ppi->pPoolRgnAttr, prgnattr);
|
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(prgn);
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
|
2014-09-17 11:40:21 +00:00
|
|
|
return GreSetObjectOwner(hRgn, OwnerMask);
|
2011-03-29 23:44:22 +00:00
|
|
|
}
|
|
|
|
|
2008-05-21 22:32:13 +00:00
|
|
|
INT
|
|
|
|
FASTCALL
|
2012-04-24 18:35:50 +00:00
|
|
|
IntGdiCombineRgn(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION prgnDest,
|
|
|
|
PREGION prgnSrc1,
|
|
|
|
PREGION prgnSrc2,
|
2012-04-24 18:35:50 +00:00
|
|
|
INT iCombineMode)
|
2008-05-21 22:32:13 +00:00
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
BOOL Ret = TRUE;
|
2008-05-21 22:32:13 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
if (prgnDest == NULL)
|
2012-04-24 18:35:50 +00:00
|
|
|
{
|
|
|
|
DPRINT("IntGdiCombineRgn: hDest unavailable\n");
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
if (prgnSrc1 == NULL)
|
2012-04-24 18:35:50 +00:00
|
|
|
{
|
2009-12-29 21:07:04 +00:00
|
|
|
DPRINT("IntGdiCombineRgn: hSrc1 unavailable\n");
|
2012-04-24 18:35:50 +00:00
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (iCombineMode == RGN_COPY)
|
|
|
|
{
|
|
|
|
if (!REGION_CopyRegion(prgnDest, prgnSrc1))
|
|
|
|
return ERROR;
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2012-04-24 18:35:50 +00:00
|
|
|
return REGION_Complexity(prgnDest);
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
if (prgnSrc2 == NULL)
|
2012-04-24 18:35:50 +00:00
|
|
|
{
|
|
|
|
DPRINT1("IntGdiCombineRgn requires hSrc2 != NULL for combine mode %d!\n", iCombineMode);
|
|
|
|
ASSERT(FALSE);
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (iCombineMode)
|
|
|
|
{
|
|
|
|
case RGN_AND:
|
2019-04-17 19:43:24 +00:00
|
|
|
Ret = REGION_IntersectRegion(prgnDest, prgnSrc1, prgnSrc2);
|
2012-04-24 18:35:50 +00:00
|
|
|
break;
|
|
|
|
case RGN_OR:
|
2019-04-17 19:43:24 +00:00
|
|
|
Ret = REGION_UnionRegion(prgnDest, prgnSrc1, prgnSrc2);
|
2012-04-24 18:35:50 +00:00
|
|
|
break;
|
|
|
|
case RGN_XOR:
|
2019-04-17 19:43:24 +00:00
|
|
|
Ret = REGION_XorRegion(prgnDest, prgnSrc1, prgnSrc2);
|
2012-04-24 18:35:50 +00:00
|
|
|
break;
|
|
|
|
case RGN_DIFF:
|
2019-04-17 19:43:24 +00:00
|
|
|
Ret = REGION_SubtractRegion(prgnDest, prgnSrc1, prgnSrc2);
|
2012-04-24 18:35:50 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
return Ret ? REGION_Complexity(prgnDest) : ERROR;
|
2008-05-21 22:32:13 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
INT
|
|
|
|
FASTCALL
|
2010-01-04 01:36:24 +00:00
|
|
|
REGION_GetRgnBox(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION Rgn,
|
2014-12-18 08:11:13 +00:00
|
|
|
PRECTL pRect)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
DWORD ret;
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
if (Rgn != NULL)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
*pRect = Rgn->rdh.rcBound;
|
|
|
|
ret = REGION_Complexity(Rgn);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2011-12-14 04:07:06 +00:00
|
|
|
return 0; // If invalid region return zero
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2008-05-27 01:38:01 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
INT
|
|
|
|
APIENTRY
|
2010-01-04 01:36:24 +00:00
|
|
|
IntGdiGetRgnBox(
|
|
|
|
HRGN hRgn,
|
2014-12-18 08:11:13 +00:00
|
|
|
PRECTL pRect)
|
1999-07-23 19:57:18 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION Rgn;
|
2010-01-04 01:36:24 +00:00
|
|
|
DWORD ret;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
Rgn = REGION_LockRgn(hRgn);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (Rgn == NULL)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
return ERROR;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2008-03-17 22:17:48 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
ret = REGION_GetRgnBox(Rgn, pRect);
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(Rgn);
|
2008-03-17 22:17:48 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
return ret;
|
1999-07-23 19:57:18 +00:00
|
|
|
}
|
|
|
|
|
2003-11-08 22:54:26 +00:00
|
|
|
|
2014-07-23 16:05:47 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
REGION_PtInRegion(
|
|
|
|
PREGION prgn,
|
|
|
|
INT X,
|
|
|
|
INT Y)
|
|
|
|
{
|
|
|
|
ULONG i;
|
|
|
|
PRECT r;
|
|
|
|
|
|
|
|
if (prgn->rdh.nCount > 0 && INRECT(prgn->rdh.rcBound, X, Y))
|
|
|
|
{
|
|
|
|
r = prgn->Buffer;
|
|
|
|
for (i = 0; i < prgn->rdh.nCount; i++)
|
|
|
|
{
|
|
|
|
if (INRECT(r[i], X, Y))
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
REGION_RectInRegion(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION Rgn,
|
2014-12-18 08:11:13 +00:00
|
|
|
const RECTL *rect)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
PRECTL pCurRect, pRectEnd;
|
|
|
|
RECT rc;
|
2003-11-08 22:54:26 +00:00
|
|
|
|
2011-12-14 04:07:06 +00:00
|
|
|
/* Swap the coordinates to make right >= left and bottom >= top */
|
2010-01-04 01:36:24 +00:00
|
|
|
/* (region building rectangles are normalized the same way) */
|
2014-12-18 08:11:19 +00:00
|
|
|
if (rect->top > rect->bottom)
|
2014-12-18 08:11:13 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
rc.top = rect->bottom;
|
|
|
|
rc.bottom = rect->top;
|
2014-12-18 08:11:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
rc.top = rect->top;
|
|
|
|
rc.bottom = rect->bottom;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
if (rect->right < rect->left)
|
2014-12-18 08:11:13 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
rc.right = rect->left;
|
|
|
|
rc.left = rect->right;
|
2014-12-18 08:11:13 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
rc.right = rect->right;
|
|
|
|
rc.left = rect->left;
|
|
|
|
}
|
2003-11-08 22:54:26 +00:00
|
|
|
|
2011-12-14 04:07:06 +00:00
|
|
|
/* This is (just) a useful optimization */
|
2010-01-04 01:36:24 +00:00
|
|
|
if ((Rgn->rdh.nCount > 0) && EXTENTCHECK(&Rgn->rdh.rcBound, &rc))
|
|
|
|
{
|
|
|
|
for (pCurRect = Rgn->Buffer, pRectEnd = pCurRect +
|
2014-12-18 08:11:13 +00:00
|
|
|
Rgn->rdh.nCount; pCurRect < pRectEnd; pCurRect++)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
if (pCurRect->bottom <= rc.top)
|
2014-12-18 08:11:13 +00:00
|
|
|
continue; /* Not far enough down yet */
|
2003-11-08 22:54:26 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if (pCurRect->top >= rc.bottom)
|
2011-12-14 04:07:06 +00:00
|
|
|
break; /* Too far down */
|
2003-11-08 22:54:26 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if (pCurRect->right <= rc.left)
|
2011-12-14 04:07:06 +00:00
|
|
|
continue; /* Not far enough over yet */
|
2003-11-08 22:54:26 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
if (pCurRect->left >= rc.right)
|
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
2003-11-08 22:54:26 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
return TRUE;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2003-11-08 22:54:26 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
VOID
|
|
|
|
FASTCALL
|
|
|
|
REGION_SetRectRgn(
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION rgn,
|
2010-01-04 01:36:24 +00:00
|
|
|
INT LeftRect,
|
|
|
|
INT TopRect,
|
|
|
|
INT RightRect,
|
2014-12-18 08:11:13 +00:00
|
|
|
INT BottomRect)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
PRECTL firstRect;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if (LeftRect > RightRect)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
INT tmp = LeftRect;
|
|
|
|
LeftRect = RightRect;
|
|
|
|
RightRect = tmp;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if (TopRect > BottomRect)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
INT tmp = TopRect;
|
|
|
|
TopRect = BottomRect;
|
|
|
|
BottomRect = tmp;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if ((LeftRect != RightRect) && (TopRect != BottomRect))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
firstRect = rgn->Buffer;
|
|
|
|
ASSERT(firstRect);
|
|
|
|
firstRect->left = rgn->rdh.rcBound.left = LeftRect;
|
|
|
|
firstRect->top = rgn->rdh.rcBound.top = TopRect;
|
|
|
|
firstRect->right = rgn->rdh.rcBound.right = RightRect;
|
|
|
|
firstRect->bottom = rgn->rdh.rcBound.bottom = BottomRect;
|
|
|
|
rgn->rdh.nCount = 1;
|
|
|
|
rgn->rdh.iType = RDH_RECTANGLES;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
else
|
2009-04-09 12:16:51 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
EMPTY_REGION(rgn);
|
2009-04-09 12:16:51 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2009-04-09 12:16:51 +00:00
|
|
|
|
2014-12-18 08:12:41 +00:00
|
|
|
BOOL
|
2010-01-25 01:33:01 +00:00
|
|
|
FASTCALL
|
2014-12-18 08:12:41 +00:00
|
|
|
REGION_bOffsetRgn(
|
|
|
|
_Inout_ PREGION prgn,
|
|
|
|
_In_ INT cx,
|
|
|
|
_In_ INT cy)
|
2010-07-12 16:52:10 +00:00
|
|
|
{
|
2014-12-18 08:12:41 +00:00
|
|
|
PRECTL prcl;
|
|
|
|
UINT i;
|
|
|
|
|
|
|
|
NT_ASSERT(prgn != NULL);
|
|
|
|
|
|
|
|
/* Check for trivial case */
|
|
|
|
if ((cx == 0) && (cy == 0))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check for empty regions, we ignore the offset values here */
|
|
|
|
if (prgn->rdh.nCount == 0)
|
2010-01-25 01:33:01 +00:00
|
|
|
{
|
2014-12-18 08:12:41 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure the offset is within the legal range */
|
|
|
|
if ((cx > MAX_COORD) || (cx < MIN_COORD) ||
|
|
|
|
(cy > MAX_COORD) || (cy < MIN_COORD))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-01-25 01:33:01 +00:00
|
|
|
|
2014-12-18 08:12:41 +00:00
|
|
|
/* Are we moving right? */
|
|
|
|
if (cx > 0)
|
|
|
|
{
|
|
|
|
/* Check if we stay inside the bounds on the right side */
|
|
|
|
if (prgn->rdh.rcBound.right > (MAX_COORD - cx))
|
2010-01-25 01:33:01 +00:00
|
|
|
{
|
2014-12-18 08:12:41 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Check if we stay inside the bounds on the left side */
|
|
|
|
if (prgn->rdh.rcBound.left < (MIN_COORD - cx))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:12:41 +00:00
|
|
|
/* Are we moving down? */
|
|
|
|
if (cy > 0)
|
|
|
|
{
|
|
|
|
/* Check if we stay inside the bounds on the right side */
|
|
|
|
if (prgn->rdh.rcBound.bottom > (MAX_COORD - cy))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Check if we stay inside the bounds on the left side */
|
|
|
|
if (prgn->rdh.rcBound.top < (MIN_COORD - cy))
|
|
|
|
{
|
|
|
|
return FALSE;
|
2010-01-25 01:33:01 +00:00
|
|
|
}
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:12:41 +00:00
|
|
|
/* Loop to move the rects */
|
|
|
|
prcl = prgn->Buffer;
|
|
|
|
for (i = 0; i < prgn->rdh.nCount; i++)
|
|
|
|
{
|
|
|
|
prcl[i].left += cx;
|
|
|
|
prcl[i].right += cx;
|
|
|
|
prcl[i].top += cy;
|
|
|
|
prcl[i].bottom += cy;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Finally update the bounds rect */
|
|
|
|
if (prgn->Buffer != &prgn->rdh.rcBound)
|
|
|
|
{
|
|
|
|
prgn->rdh.rcBound.left += cx;
|
|
|
|
prgn->rdh.rcBound.right += cx;
|
|
|
|
prgn->rdh.rcBound.top += cy;
|
|
|
|
prgn->rdh.rcBound.bottom += cy;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
2010-01-25 01:33:01 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* REGION_InsertEdgeInET
|
|
|
|
*
|
|
|
|
* Insert the given edge into the edge table.
|
|
|
|
* First we must find the correct bucket in the
|
|
|
|
* Edge table, then find the right slot in the
|
|
|
|
* bucket. Finally, we can insert it.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2014-12-18 08:11:19 +00:00
|
|
|
VOID
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2010-01-04 01:36:24 +00:00
|
|
|
REGION_InsertEdgeInET(
|
2014-12-18 08:11:19 +00:00
|
|
|
EDGE_TABLE *ET,
|
|
|
|
EDGE_TABLE_ENTRY *ETE,
|
2010-01-04 01:36:24 +00:00
|
|
|
INT scanline,
|
2014-12-18 08:11:19 +00:00
|
|
|
SCANLINE_LISTBLOCK **SLLBlock,
|
2014-12-18 08:11:13 +00:00
|
|
|
INT *iSLLBlock)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
EDGE_TABLE_ENTRY *start, *prev;
|
|
|
|
SCANLINE_LIST *pSLL, *pPrevSLL;
|
|
|
|
SCANLINE_LISTBLOCK *tmpSLLBlock;
|
2003-11-08 22:54:26 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Find the right bucket to put the edge into */
|
2010-01-04 01:36:24 +00:00
|
|
|
pPrevSLL = &ET->scanlines;
|
|
|
|
pSLL = pPrevSLL->next;
|
|
|
|
while (pSLL && (pSLL->scanline < scanline))
|
2003-11-08 22:54:26 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
pPrevSLL = pSLL;
|
|
|
|
pSLL = pSLL->next;
|
2003-11-08 22:54:26 +00:00
|
|
|
}
|
1999-07-23 19:57:18 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
/* Reassign pSLL (pointer to SCANLINE_LIST) if necessary */
|
2010-01-04 01:36:24 +00:00
|
|
|
if ((!pSLL) || (pSLL->scanline > scanline))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
if (*iSLLBlock > SLLSPERBLOCK-1)
|
2008-09-09 13:19:10 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
tmpSLLBlock = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(SCANLINE_LISTBLOCK),
|
|
|
|
TAG_REGION);
|
|
|
|
if (tmpSLLBlock == NULL)
|
2008-09-09 13:19:10 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
DPRINT1("REGION_InsertEdgeInETL(): Can't alloc SLLB\n");
|
2011-12-14 04:07:06 +00:00
|
|
|
/* FIXME: Free resources? */
|
2010-01-04 01:36:24 +00:00
|
|
|
return;
|
2008-09-09 13:19:10 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
(*SLLBlock)->next = tmpSLLBlock;
|
2014-12-18 08:11:19 +00:00
|
|
|
tmpSLLBlock->next = (SCANLINE_LISTBLOCK *)NULL;
|
2010-01-04 01:36:24 +00:00
|
|
|
*SLLBlock = tmpSLLBlock;
|
|
|
|
*iSLLBlock = 0;
|
2008-09-09 13:19:10 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
pSLL = &((*SLLBlock)->SLLs[(*iSLLBlock)++]);
|
|
|
|
|
|
|
|
pSLL->next = pPrevSLL->next;
|
2014-12-18 08:11:19 +00:00
|
|
|
pSLL->edgelist = (EDGE_TABLE_ENTRY *)NULL;
|
2010-01-04 01:36:24 +00:00
|
|
|
pPrevSLL->next = pSLL;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
pSLL->scanline = scanline;
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Now insert the edge in the right bucket */
|
2014-12-18 08:11:19 +00:00
|
|
|
prev = (EDGE_TABLE_ENTRY *)NULL;
|
2010-01-04 01:36:24 +00:00
|
|
|
start = pSLL->edgelist;
|
|
|
|
while (start && (start->bres.minor_axis < ETE->bres.minor_axis))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
prev = start;
|
|
|
|
start = start->next;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
ETE->next = start;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if (prev)
|
|
|
|
prev->next = ETE;
|
|
|
|
else
|
|
|
|
pSLL->edgelist = ETE;
|
1999-07-23 19:57:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* REGION_loadAET
|
|
|
|
*
|
2014-12-18 08:11:19 +00:00
|
|
|
* This routine moves EDGE_TABLEEntries from the
|
|
|
|
* EDGE_TABLE into the Active Edge Table,
|
2010-01-04 01:36:24 +00:00
|
|
|
* leaving them sorted by smaller x coordinate.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2014-12-18 08:11:19 +00:00
|
|
|
VOID
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2010-01-04 01:36:24 +00:00
|
|
|
REGION_loadAET(
|
2014-12-18 08:11:19 +00:00
|
|
|
EDGE_TABLE_ENTRY *AET,
|
|
|
|
EDGE_TABLE_ENTRY *ETEs)
|
1999-07-23 19:57:18 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
EDGE_TABLE_ENTRY *pPrevAET;
|
|
|
|
EDGE_TABLE_ENTRY *tmp;
|
2003-07-10 21:36:39 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
pPrevAET = AET;
|
|
|
|
AET = AET->next;
|
|
|
|
while (ETEs)
|
2003-07-15 08:55:52 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
while (AET && (AET->bres.minor_axis < ETEs->bres.minor_axis))
|
|
|
|
{
|
|
|
|
pPrevAET = AET;
|
|
|
|
AET = AET->next;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
tmp = ETEs->next;
|
|
|
|
ETEs->next = AET;
|
|
|
|
if (AET)
|
|
|
|
AET->back = ETEs;
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
ETEs->back = pPrevAET;
|
|
|
|
pPrevAET->next = ETEs;
|
|
|
|
pPrevAET = ETEs;
|
2003-07-10 21:36:39 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
ETEs = tmp;
|
2003-07-15 08:55:52 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2003-07-15 08:55:52 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* REGION_computeWAET
|
|
|
|
*
|
|
|
|
* This routine links the AET by the
|
2014-12-18 08:11:19 +00:00
|
|
|
* nextWETE (winding EDGE_TABLE_ENTRY) link for
|
2010-01-04 01:36:24 +00:00
|
|
|
* use by the winding number rule. The final
|
|
|
|
* Active Edge Table (AET) might look something
|
|
|
|
* like:
|
|
|
|
*
|
|
|
|
* AET
|
|
|
|
* ---------- --------- ---------
|
|
|
|
* |ymax | |ymax | |ymax |
|
|
|
|
* | ... | |... | |... |
|
|
|
|
* |next |->|next |->|next |->...
|
|
|
|
* |nextWETE| |nextWETE| |nextWETE|
|
|
|
|
* --------- --------- ^--------
|
|
|
|
* | | |
|
|
|
|
* V-------------------> V---> ...
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2014-12-18 08:11:19 +00:00
|
|
|
VOID
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
|
|
|
REGION_computeWAET(
|
2014-12-18 08:11:19 +00:00
|
|
|
EDGE_TABLE_ENTRY *AET)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
register EDGE_TABLE_ENTRY *pWETE;
|
|
|
|
register INT inside = 1;
|
|
|
|
register INT isInside = 0;
|
2003-07-10 21:36:39 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
AET->nextWETE = (EDGE_TABLE_ENTRY *)NULL;
|
2010-01-04 01:36:24 +00:00
|
|
|
pWETE = AET;
|
|
|
|
AET = AET->next;
|
|
|
|
while (AET)
|
|
|
|
{
|
|
|
|
if (AET->ClockWise)
|
|
|
|
isInside++;
|
|
|
|
else
|
|
|
|
isInside--;
|
2003-07-10 21:36:39 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
if ((!inside && !isInside) ||
|
|
|
|
( inside && isInside))
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
pWETE->nextWETE = AET;
|
|
|
|
pWETE = AET;
|
|
|
|
inside = !inside;
|
|
|
|
}
|
|
|
|
AET = AET->next;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
pWETE->nextWETE = (EDGE_TABLE_ENTRY *)NULL;
|
1999-07-23 19:57:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* REGION_InsertionSort
|
|
|
|
*
|
|
|
|
* Just a simple insertion sort using
|
|
|
|
* pointers and back pointers to sort the Active
|
|
|
|
* Edge Table.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
REGION_InsertionSort(
|
2014-12-18 08:11:19 +00:00
|
|
|
EDGE_TABLE_ENTRY *AET)
|
1999-07-23 19:57:18 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
EDGE_TABLE_ENTRY *pETEchase;
|
|
|
|
EDGE_TABLE_ENTRY *pETEinsert;
|
|
|
|
EDGE_TABLE_ENTRY *pETEchaseBackTMP;
|
2010-01-04 01:36:24 +00:00
|
|
|
BOOL changed = FALSE;
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
AET = AET->next;
|
|
|
|
while (AET)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
pETEinsert = AET;
|
|
|
|
pETEchase = AET;
|
|
|
|
while (pETEchase->back->bres.minor_axis > AET->bres.minor_axis)
|
|
|
|
pETEchase = pETEchase->back;
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
AET = AET->next;
|
|
|
|
if (pETEchase != pETEinsert)
|
|
|
|
{
|
|
|
|
pETEchaseBackTMP = pETEchase->back;
|
|
|
|
pETEinsert->back->next = AET;
|
|
|
|
if (AET)
|
|
|
|
AET->back = pETEinsert->back;
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
pETEinsert->next = pETEchase;
|
|
|
|
pETEchase->back->next = pETEinsert;
|
|
|
|
pETEchase->back = pETEinsert;
|
|
|
|
pETEinsert->back = pETEchaseBackTMP;
|
|
|
|
changed = TRUE;
|
|
|
|
}
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
return changed;
|
1999-07-23 19:57:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* REGION_FreeStorage
|
|
|
|
*
|
|
|
|
* Clean up our act.
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2014-12-18 08:11:19 +00:00
|
|
|
VOID
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
|
|
|
REGION_FreeStorage(
|
2014-12-18 08:11:19 +00:00
|
|
|
SCANLINE_LISTBLOCK *pSLLBlock)
|
1999-07-23 19:57:18 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
SCANLINE_LISTBLOCK *tmpSLLBlock;
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
while (pSLLBlock)
|
2002-09-01 20:39:56 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
tmpSLLBlock = pSLLBlock->next;
|
2012-10-06 20:15:36 +00:00
|
|
|
ExFreePoolWithTag(pSLLBlock, TAG_REGION);
|
2010-01-04 01:36:24 +00:00
|
|
|
pSLLBlock = tmpSLLBlock;
|
2002-09-01 20:39:56 +00:00
|
|
|
}
|
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/***********************************************************************
|
|
|
|
* REGION_PtsToRegion
|
|
|
|
*
|
|
|
|
* Create an array of rectangles from a list of points.
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
|
|
|
INT
|
|
|
|
FASTCALL
|
2010-01-04 01:36:24 +00:00
|
|
|
REGION_PtsToRegion(
|
2014-12-18 08:11:19 +00:00
|
|
|
INT numFullPtBlocks,
|
|
|
|
INT iCurPtBlock,
|
2010-01-04 01:36:24 +00:00
|
|
|
POINTBLOCK *FirstPtBlock,
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION reg)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
RECTL *rects;
|
|
|
|
POINT *pts;
|
|
|
|
POINTBLOCK *CurPtBlock;
|
2014-12-18 08:11:19 +00:00
|
|
|
INT i;
|
2010-01-04 01:36:24 +00:00
|
|
|
RECTL *extents, *temp;
|
|
|
|
INT numRects;
|
2008-05-23 00:29:08 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
extents = ®->rdh.rcBound;
|
2008-05-23 00:29:08 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
numRects = ((numFullPtBlocks * NUMPTSTOBUFFER) + iCurPtBlock) >> 1;
|
2007-07-29 13:12:20 +00:00
|
|
|
|
2012-09-18 22:01:38 +00:00
|
|
|
/* Make sure, we have at least one rect */
|
|
|
|
if (numRects == 0)
|
|
|
|
{
|
|
|
|
numRects = 1;
|
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
temp = ExAllocatePoolWithTag(PagedPool, numRects * sizeof(RECT), TAG_REGION);
|
|
|
|
if (temp == NULL)
|
2007-07-29 13:12:20 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
return 0;
|
2007-07-29 13:12:20 +00:00
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if (reg->Buffer != NULL)
|
2007-07-29 13:12:20 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
COPY_RECTS(temp, reg->Buffer, reg->rdh.nCount);
|
|
|
|
if (reg->Buffer != ®->rdh.rcBound)
|
|
|
|
ExFreePoolWithTag(reg->Buffer, TAG_REGION);
|
2007-07-29 13:12:20 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
reg->Buffer = temp;
|
|
|
|
|
|
|
|
reg->rdh.nCount = numRects;
|
|
|
|
CurPtBlock = FirstPtBlock;
|
|
|
|
rects = reg->Buffer - 1;
|
|
|
|
numRects = 0;
|
|
|
|
extents->left = LARGE_COORDINATE, extents->right = SMALL_COORDINATE;
|
|
|
|
|
|
|
|
for ( ; numFullPtBlocks >= 0; numFullPtBlocks--)
|
|
|
|
{
|
2011-12-14 04:07:06 +00:00
|
|
|
/* The loop uses 2 points per iteration */
|
2010-01-04 01:36:24 +00:00
|
|
|
i = NUMPTSTOBUFFER >> 1;
|
2014-12-18 08:11:19 +00:00
|
|
|
if (numFullPtBlocks == 0)
|
2010-01-04 01:36:24 +00:00
|
|
|
i = iCurPtBlock >> 1;
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
for (pts = CurPtBlock->pts; i--; pts += 2)
|
2007-08-08 00:28:08 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
if (pts->x == pts[1].x)
|
|
|
|
continue;
|
2014-12-18 08:11:19 +00:00
|
|
|
|
|
|
|
if ((numRects && pts->x == rects->left) &&
|
|
|
|
(pts->y == rects->bottom) &&
|
|
|
|
(pts[1].x == rects->right) &&
|
|
|
|
((numRects == 1) || (rects[-1].top != rects->top)) &&
|
|
|
|
(i && pts[2].y > pts[1].y))
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
rects->bottom = pts[1].y + 1;
|
|
|
|
continue;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
numRects++;
|
|
|
|
rects++;
|
|
|
|
rects->left = pts->x;
|
|
|
|
rects->top = pts->y;
|
|
|
|
rects->right = pts[1].x;
|
|
|
|
rects->bottom = pts[1].y + 1;
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if (rects->left < extents->left)
|
|
|
|
extents->left = rects->left;
|
|
|
|
if (rects->right > extents->right)
|
|
|
|
extents->right = rects->right;
|
2007-08-08 00:28:08 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
CurPtBlock = CurPtBlock->next;
|
2007-07-29 13:12:20 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
|
|
|
|
if (numRects)
|
2007-07-29 13:12:20 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
extents->top = reg->Buffer->top;
|
|
|
|
extents->bottom = rects->bottom;
|
2007-07-29 13:12:20 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
extents->left = 0;
|
|
|
|
extents->top = 0;
|
|
|
|
extents->right = 0;
|
|
|
|
extents->bottom = 0;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
reg->rdh.nCount = numRects;
|
2007-07-29 13:12:20 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
return(TRUE);
|
2007-07-29 13:12:20 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/***********************************************************************
|
2014-12-18 08:11:56 +00:00
|
|
|
* REGION_CreateETandAET
|
2010-01-04 01:36:24 +00:00
|
|
|
*
|
|
|
|
* This routine creates the edge table for
|
|
|
|
* scan converting polygons.
|
|
|
|
* The Edge Table (ET) looks like:
|
|
|
|
*
|
2014-12-18 08:11:19 +00:00
|
|
|
* EDGE_TABLE
|
2010-01-04 01:36:24 +00:00
|
|
|
* --------
|
2014-12-18 08:11:19 +00:00
|
|
|
* | ymax | SCANLINE_LISTs
|
2010-01-04 01:36:24 +00:00
|
|
|
* |scanline|-->------------>-------------->...
|
|
|
|
* -------- |scanline| |scanline|
|
|
|
|
* |edgelist| |edgelist|
|
|
|
|
* --------- ---------
|
|
|
|
* | |
|
|
|
|
* | |
|
|
|
|
* V V
|
|
|
|
* list of ETEs list of ETEs
|
|
|
|
*
|
2014-12-18 08:11:19 +00:00
|
|
|
* where ETE is an EDGE_TABLE_ENTRY data structure,
|
|
|
|
* and there is one SCANLINE_LIST per scanline at
|
2010-01-04 01:36:24 +00:00
|
|
|
* which an edge is initially entered.
|
|
|
|
*
|
|
|
|
*/
|
2014-12-18 08:11:13 +00:00
|
|
|
static
|
2014-12-18 08:11:19 +00:00
|
|
|
VOID
|
2014-12-18 08:11:13 +00:00
|
|
|
FASTCALL
|
2010-01-04 01:36:24 +00:00
|
|
|
REGION_CreateETandAET(
|
|
|
|
const ULONG *Count,
|
|
|
|
INT nbpolygons,
|
|
|
|
const POINT *pts,
|
2014-12-18 08:11:19 +00:00
|
|
|
EDGE_TABLE *ET,
|
|
|
|
EDGE_TABLE_ENTRY *AET,
|
|
|
|
EDGE_TABLE_ENTRY *pETEs,
|
|
|
|
SCANLINE_LISTBLOCK *pSLLBlock)
|
2007-10-26 22:08:53 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
const POINT *top, *bottom;
|
|
|
|
const POINT *PrevPt, *CurrPt, *EndPt;
|
|
|
|
INT poly, count;
|
2014-12-18 08:11:19 +00:00
|
|
|
INT iSLLBlock = 0;
|
|
|
|
INT dy;
|
2007-10-26 22:08:53 +00:00
|
|
|
|
2014-12-18 08:11:56 +00:00
|
|
|
/* Initialize the Active Edge Table */
|
2014-12-18 08:11:19 +00:00
|
|
|
AET->next = (EDGE_TABLE_ENTRY *)NULL;
|
|
|
|
AET->back = (EDGE_TABLE_ENTRY *)NULL;
|
|
|
|
AET->nextWETE = (EDGE_TABLE_ENTRY *)NULL;
|
2010-01-04 01:36:24 +00:00
|
|
|
AET->bres.minor_axis = SMALL_COORDINATE;
|
2007-10-26 22:08:53 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Initialize the Edge Table. */
|
2014-12-18 08:11:19 +00:00
|
|
|
ET->scanlines.next = (SCANLINE_LIST *)NULL;
|
2010-01-04 01:36:24 +00:00
|
|
|
ET->ymax = SMALL_COORDINATE;
|
|
|
|
ET->ymin = LARGE_COORDINATE;
|
2014-12-18 08:11:19 +00:00
|
|
|
pSLLBlock->next = (SCANLINE_LISTBLOCK *)NULL;
|
2002-09-01 20:39:56 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
EndPt = pts - 1;
|
|
|
|
for (poly = 0; poly < nbpolygons; poly++)
|
2004-03-22 20:14:29 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
count = Count[poly];
|
|
|
|
EndPt += count;
|
|
|
|
if (count < 2)
|
|
|
|
continue;
|
2004-03-22 20:14:29 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
PrevPt = EndPt;
|
2003-09-09 09:39:21 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* For each vertex in the array of points.
|
2010-01-04 01:36:24 +00:00
|
|
|
* In this loop we are dealing with two vertices at
|
2014-12-18 08:11:13 +00:00
|
|
|
* a time -- these make up one edge of the polygon. */
|
2010-01-04 01:36:24 +00:00
|
|
|
while (count--)
|
|
|
|
{
|
|
|
|
CurrPt = pts++;
|
2003-09-09 09:39:21 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Find out which point is above and which is below. */
|
2010-01-04 01:36:24 +00:00
|
|
|
if (PrevPt->y > CurrPt->y)
|
|
|
|
{
|
|
|
|
bottom = PrevPt, top = CurrPt;
|
|
|
|
pETEs->ClockWise = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
bottom = CurrPt, top = PrevPt;
|
|
|
|
pETEs->ClockWise = 1;
|
|
|
|
}
|
1999-07-23 19:57:18 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Don't add horizontal edges to the Edge table. */
|
2010-01-04 01:36:24 +00:00
|
|
|
if (bottom->y != top->y)
|
|
|
|
{
|
|
|
|
/* -1 so we don't get last scanline */
|
2014-12-18 08:11:13 +00:00
|
|
|
pETEs->ymax = bottom->y - 1;
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Initialize integer edge algorithm */
|
2010-01-04 01:36:24 +00:00
|
|
|
dy = bottom->y - top->y;
|
|
|
|
BRESINITPGONSTRUCT(dy, top->x, bottom->x, pETEs->bres);
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
REGION_InsertEdgeInET(ET,
|
|
|
|
pETEs,
|
|
|
|
top->y,
|
|
|
|
&pSLLBlock,
|
2010-01-04 01:36:24 +00:00
|
|
|
&iSLLBlock);
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if (PrevPt->y > ET->ymax)
|
|
|
|
ET->ymax = PrevPt->y;
|
|
|
|
if (PrevPt->y < ET->ymin)
|
|
|
|
ET->ymin = PrevPt->y;
|
|
|
|
pETEs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
PrevPt = CurrPt;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2004-04-23 13:34:04 +00:00
|
|
|
}
|
1999-07-23 19:57:18 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
2014-12-18 08:11:56 +00:00
|
|
|
REGION_SetPolyPolygonRgn(
|
|
|
|
_Inout_ PREGION prgn,
|
|
|
|
_In_ const POINT *ppt,
|
|
|
|
_In_ const ULONG *pcPoints,
|
|
|
|
_In_ ULONG cPolygons,
|
|
|
|
_In_ INT iMode)
|
1999-07-23 19:57:18 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
EDGE_TABLE_ENTRY *pAET; /* Active Edge Table */
|
|
|
|
INT y; /* Current scanline */
|
|
|
|
INT iPts = 0; /* Number of pts in buffer */
|
|
|
|
EDGE_TABLE_ENTRY *pWETE; /* Winding Edge Table Entry */
|
|
|
|
SCANLINE_LIST *pSLL; /* Current SCANLINE_LIST */
|
|
|
|
POINT *pts; /* Output buffer */
|
|
|
|
EDGE_TABLE_ENTRY *pPrevAET; /* Pointer to previous AET */
|
|
|
|
EDGE_TABLE ET; /* Header node for ET */
|
|
|
|
EDGE_TABLE_ENTRY AET; /* Header node for AET */
|
|
|
|
EDGE_TABLE_ENTRY *pETEs; /* EDGE_TABLEEntries pool */
|
|
|
|
SCANLINE_LISTBLOCK SLLBlock; /* Header for SCANLINE_LIST */
|
|
|
|
INT fixWAET = FALSE;
|
|
|
|
POINTBLOCK FirstPtBlock, *curPtBlock; /* PtBlock buffers */
|
2010-01-04 01:36:24 +00:00
|
|
|
POINTBLOCK *tmpPtBlock;
|
2014-12-18 08:11:56 +00:00
|
|
|
UINT numFullPtBlocks = 0;
|
|
|
|
UINT poly, total;
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2014-12-18 08:11:56 +00:00
|
|
|
/* Check if iMode is valid */
|
|
|
|
if ((iMode != ALTERNATE) && (iMode != WINDING))
|
2015-05-17 14:34:49 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Invalid iMode: %lu\n", iMode);
|
2014-12-18 08:11:56 +00:00
|
|
|
return FALSE;
|
2015-05-17 14:34:49 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2011-12-14 04:07:06 +00:00
|
|
|
/* Special case a rectangle */
|
2014-12-18 08:11:56 +00:00
|
|
|
if (((cPolygons == 1) && ((pcPoints[0] == 4) ||
|
|
|
|
((pcPoints[0] == 5) && (ppt[4].x == ppt[0].x) && (ppt[4].y == ppt[0].y)))) &&
|
|
|
|
(((ppt[0].y == ppt[1].y) &&
|
|
|
|
(ppt[1].x == ppt[2].x) &&
|
|
|
|
(ppt[2].y == ppt[3].y) &&
|
|
|
|
(ppt[3].x == ppt[0].x)) ||
|
|
|
|
((ppt[0].x == ppt[1].x) &&
|
|
|
|
(ppt[1].y == ppt[2].y) &&
|
|
|
|
(ppt[2].x == ppt[3].x) &&
|
|
|
|
(ppt[3].y == ppt[0].y))))
|
|
|
|
{
|
|
|
|
REGION_SetRectRgn(prgn,
|
|
|
|
min(ppt[0].x, ppt[2].x),
|
|
|
|
min(ppt[0].y, ppt[2].y),
|
|
|
|
max(ppt[0].x, ppt[2].x),
|
|
|
|
max(ppt[0].y, ppt[2].y));
|
2014-09-17 09:54:27 +00:00
|
|
|
return TRUE;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:11:56 +00:00
|
|
|
for (poly = total = 0; poly < cPolygons; poly++)
|
|
|
|
total += pcPoints[poly];
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
pETEs = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(EDGE_TABLE_ENTRY) * total,
|
|
|
|
TAG_REGION);
|
|
|
|
if (pETEs == NULL)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2015-05-17 14:34:49 +00:00
|
|
|
DPRINT1("Failed to allocate %lu edge entries\n", total);
|
2014-09-17 09:54:27 +00:00
|
|
|
return FALSE;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
pts = FirstPtBlock.pts;
|
2014-12-18 08:11:56 +00:00
|
|
|
REGION_CreateETandAET(pcPoints, cPolygons, ppt, &ET, &AET, pETEs, &SLLBlock);
|
2010-01-04 01:36:24 +00:00
|
|
|
pSLL = ET.scanlines.next;
|
|
|
|
curPtBlock = &FirstPtBlock;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:11:56 +00:00
|
|
|
if (iMode != WINDING)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* For each scanline */
|
2010-01-04 01:36:24 +00:00
|
|
|
for (y = ET.ymin; y < ET.ymax; y++)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Add a new edge to the active edge table when we
|
|
|
|
* get to the next edge. */
|
2010-01-04 01:36:24 +00:00
|
|
|
if (pSLL != NULL && y == pSLL->scanline)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
REGION_loadAET(&AET, pSLL->edgelist);
|
|
|
|
pSLL = pSLL->next;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
pPrevAET = &AET;
|
|
|
|
pAET = AET.next;
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* For each active edge */
|
2010-01-04 01:36:24 +00:00
|
|
|
while (pAET)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
pts->x = pAET->bres.minor_axis, pts->y = y;
|
|
|
|
pts++, iPts++;
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Send out the buffer */
|
2010-01-04 01:36:24 +00:00
|
|
|
if (iPts == NUMPTSTOBUFFER)
|
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
tmpPtBlock = ExAllocatePoolWithTag(PagedPool,
|
|
|
|
sizeof(POINTBLOCK),
|
|
|
|
TAG_REGION);
|
|
|
|
if (tmpPtBlock == NULL)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2015-05-17 14:34:49 +00:00
|
|
|
DPRINT1("Can't alloc tmpPtBlock\n");
|
2010-01-04 01:36:24 +00:00
|
|
|
ExFreePoolWithTag(pETEs, TAG_REGION);
|
2014-09-17 09:54:27 +00:00
|
|
|
return FALSE;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
curPtBlock->next = tmpPtBlock;
|
|
|
|
curPtBlock = tmpPtBlock;
|
|
|
|
pts = curPtBlock->pts;
|
|
|
|
numFullPtBlocks++;
|
|
|
|
iPts = 0;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
EVALUATEEDGEEVENODD(pAET, pPrevAET, y);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
REGION_InsertionSort(&AET);
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
else
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* For each scanline */
|
2010-01-04 01:36:24 +00:00
|
|
|
for (y = ET.ymin; y < ET.ymax; y++)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Add a new edge to the active edge table when we
|
|
|
|
* get to the next edge. */
|
2010-01-04 01:36:24 +00:00
|
|
|
if (pSLL != NULL && y == pSLL->scanline)
|
|
|
|
{
|
|
|
|
REGION_loadAET(&AET, pSLL->edgelist);
|
|
|
|
REGION_computeWAET(&AET);
|
|
|
|
pSLL = pSLL->next;
|
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
pPrevAET = &AET;
|
|
|
|
pAET = AET.next;
|
|
|
|
pWETE = pAET;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* For each active edge */
|
2010-01-04 01:36:24 +00:00
|
|
|
while (pAET)
|
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Add to the buffer only those edges that
|
|
|
|
* are in the Winding active edge table. */
|
2010-01-04 01:36:24 +00:00
|
|
|
if (pWETE == pAET)
|
|
|
|
{
|
2014-12-18 08:12:06 +00:00
|
|
|
pts->x = pAET->bres.minor_axis;
|
|
|
|
pts->y = y;
|
|
|
|
pts++;
|
|
|
|
iPts++;
|
2009-04-01 01:49:18 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Send out the buffer */
|
2010-01-04 01:36:24 +00:00
|
|
|
if (iPts == NUMPTSTOBUFFER)
|
|
|
|
{
|
|
|
|
tmpPtBlock = ExAllocatePoolWithTag(PagedPool,
|
2014-12-18 08:11:19 +00:00
|
|
|
sizeof(POINTBLOCK),
|
|
|
|
TAG_REGION);
|
|
|
|
if (tmpPtBlock == NULL)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
DPRINT1("Can't alloc tPB\n");
|
|
|
|
ExFreePoolWithTag(pETEs, TAG_REGION);
|
2014-09-17 09:54:27 +00:00
|
|
|
return FALSE;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
|
|
|
curPtBlock->next = tmpPtBlock;
|
|
|
|
curPtBlock = tmpPtBlock;
|
|
|
|
pts = curPtBlock->pts;
|
|
|
|
numFullPtBlocks++;
|
|
|
|
iPts = 0;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
pWETE = pWETE->nextWETE;
|
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
EVALUATEEDGEWINDING(pAET, pPrevAET, y, fixWAET);
|
|
|
|
}
|
2008-06-27 10:58:11 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Recompute the winding active edge table if
|
|
|
|
* we just resorted or have exited an edge. */
|
2010-01-04 01:36:24 +00:00
|
|
|
if (REGION_InsertionSort(&AET) || fixWAET)
|
|
|
|
{
|
|
|
|
REGION_computeWAET(&AET);
|
|
|
|
fixWAET = FALSE;
|
|
|
|
}
|
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
REGION_FreeStorage(SLLBlock.next);
|
2014-12-18 08:11:56 +00:00
|
|
|
REGION_PtsToRegion(numFullPtBlocks, iPts, &FirstPtBlock, prgn);
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:12:06 +00:00
|
|
|
for (curPtBlock = FirstPtBlock.next; numFullPtBlocks-- > 0;)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
tmpPtBlock = curPtBlock->next;
|
|
|
|
ExFreePoolWithTag(curPtBlock, TAG_REGION);
|
|
|
|
curPtBlock = tmpPtBlock;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
ExFreePoolWithTag(pETEs, TAG_REGION);
|
2014-09-17 09:54:27 +00:00
|
|
|
return TRUE;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:11:56 +00:00
|
|
|
HRGN
|
|
|
|
NTAPI
|
|
|
|
GreCreatePolyPolygonRgn(
|
|
|
|
_In_ const POINT *ppt,
|
|
|
|
_In_ const ULONG *pcPoints,
|
|
|
|
_In_ ULONG cPolygons,
|
|
|
|
_In_ INT iMode)
|
|
|
|
{
|
|
|
|
PREGION prgn;
|
|
|
|
HRGN hrgn;
|
|
|
|
|
|
|
|
/* Allocate a new region */
|
|
|
|
prgn = REGION_AllocUserRgnWithHandle(0);
|
|
|
|
if (prgn == NULL)
|
|
|
|
{
|
|
|
|
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Call the internal function and check for success */
|
|
|
|
if (REGION_SetPolyPolygonRgn(prgn, ppt, pcPoints, cPolygons, iMode))
|
|
|
|
{
|
|
|
|
/* Success, get the handle and unlock the region */
|
|
|
|
hrgn = prgn->BaseObject.hHmgr;
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(prgn);
|
2014-12-18 08:11:56 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Failure, delete the region */
|
|
|
|
REGION_Delete(prgn);
|
|
|
|
hrgn = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hrgn;
|
|
|
|
}
|
|
|
|
|
2011-03-21 02:20:24 +00:00
|
|
|
BOOL
|
|
|
|
FASTCALL
|
|
|
|
IntRectInRegion(
|
|
|
|
HRGN hRgn,
|
2014-12-18 08:11:13 +00:00
|
|
|
LPRECTL rc)
|
2011-03-21 02:20:24 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION Rgn;
|
2011-03-21 02:20:24 +00:00
|
|
|
BOOL Ret;
|
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
Rgn = REGION_LockRgn(hRgn);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (Rgn == NULL)
|
2011-03-21 02:20:24 +00:00
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ret = REGION_RectInRegion(Rgn, rc);
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(Rgn);
|
2011-03-21 02:20:24 +00:00
|
|
|
return Ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
//
|
|
|
|
// NtGdi Exported Functions
|
|
|
|
//
|
|
|
|
INT
|
|
|
|
APIENTRY
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
NtGdiCombineRgn(
|
|
|
|
IN HRGN hrgnDst,
|
|
|
|
IN HRGN hrgnSrc1,
|
|
|
|
IN HRGN hrgnSrc2,
|
|
|
|
IN INT iMode)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
HRGN ahrgn[3];
|
|
|
|
PREGION aprgn[3];
|
|
|
|
INT iResult;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
/* Validate the combine mode */
|
|
|
|
if ((iMode < RGN_AND) || (iMode > RGN_COPY))
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
/* Validate that we have the required regions */
|
|
|
|
if ((hrgnDst == NULL) ||
|
|
|
|
(hrgnSrc1 == NULL) ||
|
|
|
|
((iMode != RGN_COPY) && (hrgnSrc2 == NULL)))
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
{
|
2014-12-19 10:34:52 +00:00
|
|
|
DPRINT1("NtGdiCombineRgn invalid parameters: %p, %p, %p, %d\n",
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
hrgnDst, hrgnSrc1, hrgnSrc2, iMode);
|
2016-09-11 17:27:59 +00:00
|
|
|
EngSetLastError(ERROR_INVALID_HANDLE);
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
return ERROR;
|
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
/* Lock all regions */
|
|
|
|
ahrgn[0] = hrgnDst;
|
|
|
|
ahrgn[1] = hrgnSrc1;
|
|
|
|
ahrgn[2] = iMode != RGN_COPY ? hrgnSrc2 : NULL;
|
2012-05-02 19:29:33 +00:00
|
|
|
if (!GDIOBJ_bLockMultipleObjects(3, (HGDIOBJ*)ahrgn, (PVOID*)aprgn, GDIObjType_RGN_TYPE))
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
{
|
2014-12-19 10:34:52 +00:00
|
|
|
DPRINT1("NtGdiCombineRgn failed to lock regions: %p, %p, %p, %d\n",
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
hrgnDst, hrgnSrc1, hrgnSrc2, iMode);
|
|
|
|
return ERROR;
|
|
|
|
}
|
1999-07-23 19:57:18 +00:00
|
|
|
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
/* HACK: Sync usermode attributes */
|
|
|
|
REGION_vSyncRegion(aprgn[0]);
|
2014-12-18 08:13:06 +00:00
|
|
|
if (aprgn[1] != aprgn[0])
|
|
|
|
REGION_vSyncRegion(aprgn[1]);
|
|
|
|
if ((aprgn[2] != NULL) && (aprgn[2] != aprgn[0]) && (aprgn[2] != aprgn[1]))
|
|
|
|
REGION_vSyncRegion(aprgn[2]);
|
2008-02-21 02:40:23 +00:00
|
|
|
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
/* Call the internal function */
|
|
|
|
iResult = IntGdiCombineRgn(aprgn[0], aprgn[1], aprgn[2], iMode);
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:13:06 +00:00
|
|
|
/* Unlock and return */
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(aprgn[0]);
|
|
|
|
REGION_UnlockRgn(aprgn[1]);
|
2014-12-18 08:13:06 +00:00
|
|
|
if (aprgn[2] != NULL)
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(aprgn[2]);
|
2014-12-18 08:11:19 +00:00
|
|
|
|
[WIN32K]
Rewrite of the GDI handle manager
- The old handle manager used a completely retarded spinlock in combination with KeDelayExecutionThread() for both exclusive
and shared locks. This is probably the most uneffective algorithm possible. It was also duplicating code everywhere and it was a overall mess It
is now replaced with a lock-free reference counter for shared locks and a pushlock for exclusive locks. -> Better performance and scalability.
- Allocate user mode object attributes from the new gdi pool. This way, we don't need any caching, since the pool serves as a cache. Its also
much faster and uses much less memory.
- Allow object allocations of different size, instead of fixed size from a table. This way a single allocation can take care of actual needs.
- Allow allcoating objects without a handle and insert them into the handle table later
- Properly synchronize the process GDIHandleCount. Now gdiview and taskmanager show the correct number of gdi handles.
- Implement a new event tracking system, that is capable of tracking all reverences and locks of objects and pool allocations to help track
possible leaks
- Make sure that all objects of a process are deleted in cleanup
- Make sure all usermode memory allocations are freed, when cleaning up the process pool.
- Make sure that each object type is using the correct type of lock (either shared or exclusive, not a mixture)
- Fix some object / reference leaks
- Lots of inferface improvements
- Use global variables for certain things instead of members in the mapped gdi handle table
- Make IntSysCreateRectpRgn create a region without a handle
- Fix detection od source and mask use in GreStretchBltMask
- Use GDIOBJ_bLockMultipleObjects in NtGdiCombineRegion to avoid possible deadlocks
- Fix NtGdiAbortPath to reset DCPATH_ACTIVE flag in the dc and only bail out on error, instead of always
- Replace DC_AllocateDcAttr and DC_AllocDcAttr with DC_bAllocDcAttr using the new user mode pool
- Remove DCU_SyncDcAttrtoUser and DCU_SynchDcAttrtoUser. Those functions were unused and didn't do anything useful anyway,
- Replace IntGdiSetDCOwnerEx and DC_SetOwnership with GreSetDCOwner, remove unused NoSetBrush parameter
- Replace GDIOBJ_bValidateHandle and IsObjectDead with GreIsHandleValid
- Chage GDIOBJ_bLockMultipleObjects: pass object type, return a BOOL, whether all objects could be locked, cleanup on failure
svn path=/trunk/; revision=51470
2011-04-28 08:26:46 +00:00
|
|
|
return iResult;
|
1999-07-23 19:57:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
HRGN
|
|
|
|
APIENTRY
|
|
|
|
NtGdiCreateEllipticRgn(
|
|
|
|
INT Left,
|
|
|
|
INT Top,
|
|
|
|
INT Right,
|
2014-12-18 08:11:13 +00:00
|
|
|
INT Bottom)
|
1999-07-23 19:57:18 +00:00
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
return NtGdiCreateRoundRectRgn(Left,
|
|
|
|
Top,
|
|
|
|
Right, Bottom,
|
|
|
|
Right - Left,
|
|
|
|
Bottom - Top);
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2009-10-17 21:04:04 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
HRGN
|
|
|
|
APIENTRY
|
|
|
|
NtGdiCreateRectRgn(
|
|
|
|
INT LeftRect,
|
|
|
|
INT TopRect,
|
|
|
|
INT RightRect,
|
|
|
|
INT BottomRect)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION pRgn;
|
2010-01-04 01:36:24 +00:00
|
|
|
HRGN hRgn;
|
2005-05-08 02:11:54 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/* Allocate region data structure with space for 1 RECTL */
|
2014-12-18 08:11:19 +00:00
|
|
|
pRgn = REGION_AllocUserRgnWithHandle(1);
|
|
|
|
if (pRgn == NULL)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2010-12-25 11:01:14 +00:00
|
|
|
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2010-01-04 01:36:24 +00:00
|
|
|
return NULL;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
hRgn = pRgn->BaseObject.hHmgr;
|
|
|
|
|
|
|
|
REGION_SetRectRgn(pRgn, LeftRect, TopRect, RightRect, BottomRect);
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(pRgn);
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2014-09-17 12:12:28 +00:00
|
|
|
DPRINT("Returning %p.\n", hRgn);
|
2014-09-17 09:54:27 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
return hRgn;
|
1999-07-23 19:57:18 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
HRGN
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2010-01-04 01:36:24 +00:00
|
|
|
NtGdiCreateRoundRectRgn(
|
|
|
|
INT left,
|
|
|
|
INT top,
|
|
|
|
INT right,
|
|
|
|
INT bottom,
|
|
|
|
INT ellipse_width,
|
2014-12-18 08:11:13 +00:00
|
|
|
INT ellipse_height)
|
2003-09-09 09:39:21 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION obj;
|
2010-01-04 01:36:24 +00:00
|
|
|
HRGN hrgn;
|
2019-04-17 19:43:24 +00:00
|
|
|
int a, b, i, x, y;
|
|
|
|
INT64 asq, bsq, dx, dy, err;
|
|
|
|
RECT *rects;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/* Make the dimensions sensible */
|
|
|
|
if (left > right)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
INT tmp = left;
|
|
|
|
left = right;
|
|
|
|
right = tmp;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if (top > bottom)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
INT tmp = top;
|
|
|
|
top = bottom;
|
|
|
|
bottom = tmp;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
/* the region is for the rectangle interior, but only at right and bottom for some reason */
|
|
|
|
right--;
|
|
|
|
bottom--;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
ellipse_width = min( right - left, abs( ellipse_width ));
|
|
|
|
ellipse_height = min( bottom - top, abs( ellipse_height ));
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/* Check if we can do a normal rectangle instead */
|
2019-04-17 19:43:24 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if ((ellipse_width < 2) || (ellipse_height < 2))
|
|
|
|
return NtGdiCreateRectRgn(left, top, right, bottom);
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
obj = REGION_AllocUserRgnWithHandle( ellipse_height );
|
2014-12-18 08:11:19 +00:00
|
|
|
if (obj == NULL)
|
2014-12-18 08:11:13 +00:00
|
|
|
return 0;
|
2014-12-18 08:11:19 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
hrgn = obj->BaseObject.hHmgr;
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
obj->rdh.rcBound.left = left;
|
|
|
|
obj->rdh.rcBound.top = top;
|
|
|
|
obj->rdh.rcBound.right = right;
|
|
|
|
obj->rdh.rcBound.bottom = bottom;
|
|
|
|
rects = obj->Buffer;
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
/* based on an algorithm by Alois Zingl */
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
a = ellipse_width - 1;
|
|
|
|
b = ellipse_height - 1;
|
|
|
|
asq = (INT64)8 * a * a;
|
|
|
|
bsq = (INT64)8 * b * b;
|
|
|
|
dx = (INT64)4 * b * b * (1 - a);
|
|
|
|
dy = (INT64)4 * a * a * (1 + (b % 2));
|
|
|
|
err = dx + dy + a * a * (b % 2);
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
x = 0;
|
|
|
|
y = ellipse_height / 2;
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
rects[y].left = left;
|
|
|
|
rects[y].right = right;
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
while (x <= ellipse_width / 2)
|
|
|
|
{
|
|
|
|
INT64 e2 = 2 * err;
|
|
|
|
if (e2 >= dx)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
x++;
|
|
|
|
err += dx += bsq;
|
|
|
|
}
|
|
|
|
if (e2 <= dy)
|
|
|
|
{
|
|
|
|
y++;
|
|
|
|
err += dy += asq;
|
|
|
|
rects[y].left = left + x;
|
|
|
|
rects[y].right = right - x;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2019-04-17 19:43:24 +00:00
|
|
|
for (i = 0; i < ellipse_height / 2; i++)
|
|
|
|
{
|
|
|
|
rects[i].left = rects[b - i].left;
|
|
|
|
rects[i].right = rects[b - i].right;
|
|
|
|
rects[i].top = top + i;
|
|
|
|
rects[i].bottom = rects[i].top + 1;
|
|
|
|
}
|
|
|
|
for (; i < ellipse_height; i++)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
rects[i].top = bottom - ellipse_height + i;
|
|
|
|
rects[i].bottom = rects[i].top + 1;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2019-04-17 19:43:24 +00:00
|
|
|
rects[ellipse_height / 2].top = top + ellipse_height / 2; /* extend to top of rectangle */
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(obj);
|
2010-01-04 01:36:24 +00:00
|
|
|
return hrgn;
|
2008-03-17 22:17:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
BOOL
|
2008-11-29 22:48:58 +00:00
|
|
|
APIENTRY
|
2010-01-04 01:36:24 +00:00
|
|
|
NtGdiEqualRgn(
|
|
|
|
HRGN hSrcRgn1,
|
2014-12-18 08:11:13 +00:00
|
|
|
HRGN hSrcRgn2)
|
2008-03-17 22:17:48 +00:00
|
|
|
{
|
2014-12-19 10:34:52 +00:00
|
|
|
HRGN ahrgn[2];
|
|
|
|
PREGION aprgn[2];
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION rgn1, rgn2;
|
2010-01-04 01:36:24 +00:00
|
|
|
PRECTL tRect1, tRect2;
|
|
|
|
ULONG i;
|
|
|
|
BOOL bRet = FALSE;
|
2008-03-17 22:17:48 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
/* Check if we got 2 regions */
|
|
|
|
if ((hSrcRgn1 == NULL) || (hSrcRgn2 == NULL))
|
|
|
|
{
|
|
|
|
return FALSE;
|
|
|
|
}
|
2014-12-18 08:12:01 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
/* Check if these are the same regions */
|
|
|
|
if (hSrcRgn1 == hSrcRgn2)
|
|
|
|
{
|
|
|
|
/* Make sure this region is valid */
|
|
|
|
if ((GDI_HANDLE_GET_TYPE(hSrcRgn1) == GDILoObjType_LO_REGION_TYPE) &&
|
|
|
|
GreIsHandleValid(hSrcRgn1))
|
|
|
|
{
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
/* Lock both regions */
|
|
|
|
ahrgn[0] = hSrcRgn1;
|
|
|
|
ahrgn[1] = hSrcRgn2;
|
|
|
|
if (!GDIOBJ_bLockMultipleObjects(2, (HGDIOBJ*)ahrgn, (PVOID*)aprgn, GDIObjType_RGN_TYPE))
|
2008-03-17 22:17:48 +00:00
|
|
|
{
|
2014-12-19 10:34:52 +00:00
|
|
|
DPRINT1("NtGdiEqualRgn failed to lock regions: %p, %p\n",
|
|
|
|
hSrcRgn1, hSrcRgn2);
|
|
|
|
return FALSE;
|
2008-03-17 22:17:48 +00:00
|
|
|
}
|
2002-07-18 21:59:18 +00:00
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_vSyncRegion(aprgn[0]);
|
|
|
|
REGION_vSyncRegion(aprgn[1]);
|
|
|
|
|
|
|
|
rgn1 = aprgn[0];
|
|
|
|
rgn2 = aprgn[1];
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
if (rgn1->rdh.nCount != rgn2->rdh.nCount)
|
|
|
|
goto exit;
|
2010-02-23 03:17:37 +00:00
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
if (rgn1->rdh.nCount == 0)
|
2010-02-23 03:17:37 +00:00
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
bRet = TRUE;
|
|
|
|
goto exit;
|
2010-02-23 03:17:37 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((rgn1->rdh.rcBound.left != rgn2->rdh.rcBound.left) ||
|
|
|
|
(rgn1->rdh.rcBound.right != rgn2->rdh.rcBound.right) ||
|
|
|
|
(rgn1->rdh.rcBound.top != rgn2->rdh.rcBound.top) ||
|
|
|
|
(rgn1->rdh.rcBound.bottom != rgn2->rdh.rcBound.bottom))
|
2014-12-18 08:11:13 +00:00
|
|
|
goto exit;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
tRect1 = rgn1->Buffer;
|
|
|
|
tRect2 = rgn2->Buffer;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((tRect1 == NULL) || (tRect2 == NULL))
|
2014-12-18 08:11:13 +00:00
|
|
|
goto exit;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
for (i=0; i < rgn1->rdh.nCount; i++)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((tRect1[i].left != tRect2[i].left) ||
|
|
|
|
(tRect1[i].right != tRect2[i].right) ||
|
|
|
|
(tRect1[i].top != tRect2[i].top) ||
|
|
|
|
(tRect1[i].bottom != tRect2[i].bottom))
|
2014-12-18 08:11:13 +00:00
|
|
|
goto exit;
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
bRet = TRUE;
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
exit:
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(rgn1);
|
|
|
|
REGION_UnlockRgn(rgn2);
|
2010-01-04 01:36:24 +00:00
|
|
|
return bRet;
|
2002-07-18 21:59:18 +00:00
|
|
|
}
|
2002-07-22 07:55:49 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
HRGN
|
|
|
|
APIENTRY
|
|
|
|
NtGdiExtCreateRegion(
|
|
|
|
OPTIONAL LPXFORM Xform,
|
|
|
|
DWORD Count,
|
2014-12-18 08:11:13 +00:00
|
|
|
LPRGNDATA RgnData)
|
2002-07-22 07:55:49 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
HRGN hRgn;
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION Region;
|
2010-01-04 01:36:24 +00:00
|
|
|
DWORD nCount = 0;
|
|
|
|
DWORD iType = 0;
|
|
|
|
DWORD dwSize = 0;
|
2014-12-18 08:11:13 +00:00
|
|
|
UINT i;
|
|
|
|
RECT* rects;
|
2005-07-26 12:22:55 +00:00
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
2010-01-04 01:36:24 +00:00
|
|
|
MATRIX matrix;
|
2011-01-09 23:23:42 +00:00
|
|
|
XFORMOBJ xo;
|
2002-07-22 07:55:49 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
DPRINT("NtGdiExtCreateRegion\n");
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_TRY
|
2005-07-26 12:22:55 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
ProbeForRead(RgnData, Count, 1);
|
|
|
|
nCount = RgnData->rdh.nCount;
|
|
|
|
iType = RgnData->rdh.iType;
|
|
|
|
dwSize = RgnData->rdh.dwSize;
|
2014-12-18 08:11:13 +00:00
|
|
|
rects = (RECT*)RgnData->Buffer;
|
2005-07-26 12:22:55 +00:00
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2005-07-26 12:22:55 +00:00
|
|
|
{
|
2008-11-30 19:28:11 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2005-07-26 12:22:55 +00:00
|
|
|
}
|
2008-11-30 19:28:11 +00:00
|
|
|
_SEH2_END;
|
2014-12-18 08:11:13 +00:00
|
|
|
|
2008-02-21 02:40:23 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
2005-07-26 12:22:55 +00:00
|
|
|
{
|
2008-02-21 02:40:23 +00:00
|
|
|
SetLastNtError(Status);
|
2010-01-04 01:36:24 +00:00
|
|
|
return NULL;
|
2005-07-26 12:22:55 +00:00
|
|
|
}
|
2002-07-22 07:55:49 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/* Check parameters, but don't set last error here */
|
2014-12-18 08:11:19 +00:00
|
|
|
if ((Count < sizeof(RGNDATAHEADER) + nCount * sizeof(RECT)) ||
|
|
|
|
(iType != RDH_RECTANGLES) ||
|
|
|
|
(dwSize != sizeof(RGNDATAHEADER)))
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
return NULL;
|
|
|
|
}
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2010-01-25 01:33:01 +00:00
|
|
|
Region = REGION_AllocUserRgnWithHandle(nCount);
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
if (Region == NULL)
|
2004-05-18 15:25:25 +00:00
|
|
|
{
|
2010-12-25 11:01:14 +00:00
|
|
|
EngSetLastError(ERROR_NOT_ENOUGH_MEMORY);
|
2010-01-04 01:36:24 +00:00
|
|
|
return FALSE;
|
2004-05-18 15:25:25 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
hRgn = Region->BaseObject.hHmgr;
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
_SEH2_TRY
|
2004-05-18 15:25:25 +00:00
|
|
|
{
|
2014-12-18 08:11:13 +00:00
|
|
|
/* Insert the rectangles one by one */
|
|
|
|
for(i=0; i<nCount; i++)
|
|
|
|
{
|
2019-03-31 18:31:59 +00:00
|
|
|
if ( rects[i].left < rects[i].right && rects[i].top < rects[i].bottom )
|
|
|
|
{
|
2019-04-17 19:43:24 +00:00
|
|
|
if (!REGION_UnionRectWithRgn(Region, &rects[i]))
|
|
|
|
{
|
|
|
|
REGION_UnlockRgn(Region);
|
|
|
|
GreDeleteObject(hRgn);
|
|
|
|
hRgn = NULL;
|
|
|
|
_SEH2_LEAVE;
|
|
|
|
}
|
2019-03-31 18:31:59 +00:00
|
|
|
}
|
2014-12-18 08:11:13 +00:00
|
|
|
}
|
2014-12-18 08:11:19 +00:00
|
|
|
|
|
|
|
if (Xform != NULL)
|
2004-05-18 15:25:25 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
ULONG ret;
|
|
|
|
|
|
|
|
/* Init the XFORMOBJ from the Xform struct */
|
|
|
|
Status = STATUS_INVALID_PARAMETER;
|
2011-01-09 23:23:42 +00:00
|
|
|
XFORMOBJ_vInit(&xo, &matrix);
|
|
|
|
ret = XFORMOBJ_iSetXform(&xo, (XFORML*)Xform);
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2014-11-12 10:15:09 +00:00
|
|
|
/* Check for error */
|
|
|
|
if (ret != DDI_ERROR)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
/* Apply the coordinate transformation on the rects */
|
2011-01-09 23:23:42 +00:00
|
|
|
if (XFORMOBJ_bApplyXform(&xo,
|
2010-01-04 01:36:24 +00:00
|
|
|
XF_LTOL,
|
2013-06-02 14:30:48 +00:00
|
|
|
Region->rdh.nCount * 2,
|
|
|
|
Region->Buffer,
|
2010-01-04 01:36:24 +00:00
|
|
|
Region->Buffer))
|
|
|
|
{
|
|
|
|
Status = STATUS_SUCCESS;
|
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2004-05-18 15:25:25 +00:00
|
|
|
}
|
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2004-05-18 15:25:25 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2004-05-18 15:25:25 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
_SEH2_END;
|
|
|
|
if (!NT_SUCCESS(Status))
|
2004-05-18 15:25:25 +00:00
|
|
|
{
|
2010-12-25 11:01:14 +00:00
|
|
|
EngSetLastError(ERROR_INVALID_PARAMETER);
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(Region);
|
2010-01-04 01:36:24 +00:00
|
|
|
GreDeleteObject(hRgn);
|
|
|
|
return NULL;
|
2004-05-18 15:25:25 +00:00
|
|
|
}
|
|
|
|
|
2019-04-17 19:43:24 +00:00
|
|
|
if (hRgn) REGION_UnlockRgn(Region);
|
2010-01-04 01:36:24 +00:00
|
|
|
|
|
|
|
return hRgn;
|
2004-05-18 15:25:25 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 08:11:13 +00:00
|
|
|
INT
|
|
|
|
APIENTRY
|
2010-01-04 01:36:24 +00:00
|
|
|
NtGdiGetRgnBox(
|
|
|
|
HRGN hRgn,
|
2014-12-18 08:11:13 +00:00
|
|
|
PRECTL pRect)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2014-12-18 08:11:19 +00:00
|
|
|
PREGION Rgn;
|
2010-01-04 01:36:24 +00:00
|
|
|
RECTL SafeRect;
|
|
|
|
DWORD ret;
|
|
|
|
NTSTATUS Status = STATUS_SUCCESS;
|
|
|
|
|
2014-12-19 10:34:52 +00:00
|
|
|
Rgn = REGION_LockRgn(hRgn);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (Rgn == NULL)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = REGION_GetRgnBox(Rgn, &SafeRect);
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(Rgn);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (ret == ERROR)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
ProbeForWrite(pRect, sizeof(RECT), 1);
|
|
|
|
*pRect = SafeRect;
|
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
Status = _SEH2_GetExceptionCode();
|
2008-02-21 02:40:23 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
_SEH2_END;
|
|
|
|
if (!NT_SUCCESS(Status))
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2010-01-04 01:36:24 +00:00
|
|
|
return ERROR;
|
2004-05-18 15:25:25 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
return ret;
|
2004-05-18 15:25:25 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
INT
|
|
|
|
APIENTRY
|
|
|
|
NtGdiOffsetRgn(
|
2015-03-08 23:36:14 +00:00
|
|
|
_In_ HRGN hrgn,
|
|
|
|
_In_ INT cx,
|
|
|
|
_In_ INT cy)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2015-03-08 23:36:14 +00:00
|
|
|
PREGION prgn;
|
|
|
|
INT iResult;
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
DPRINT("NtGdiOffsetRgn: hrgn %p cx %d cy %d\n", hrgn, cx, cy);
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Lock the region */
|
|
|
|
prgn = REGION_LockRgn(hrgn);
|
|
|
|
if (prgn == NULL)
|
2004-05-18 15:25:25 +00:00
|
|
|
{
|
2015-03-08 23:36:14 +00:00
|
|
|
DPRINT1("NtGdiOffsetRgn: failed to lock region %p\n", hrgn);
|
2010-01-04 01:36:24 +00:00
|
|
|
return ERROR;
|
|
|
|
}
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Call the internal function */
|
|
|
|
if (!REGION_bOffsetRgn(prgn, cx, cy))
|
2014-12-18 08:12:41 +00:00
|
|
|
{
|
2015-03-08 23:36:14 +00:00
|
|
|
iResult = ERROR;
|
2014-12-18 08:12:41 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-08 23:36:14 +00:00
|
|
|
iResult = REGION_Complexity(prgn);
|
2014-12-18 08:12:41 +00:00
|
|
|
}
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Unlock and return the result */
|
|
|
|
REGION_UnlockRgn(prgn);
|
|
|
|
return iResult;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
NtGdiPtInRegion(
|
2015-03-08 23:36:14 +00:00
|
|
|
_In_ HRGN hrgn,
|
|
|
|
_In_ INT x,
|
|
|
|
_In_ INT y)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2014-07-23 16:05:47 +00:00
|
|
|
PREGION prgn;
|
2015-03-08 23:36:14 +00:00
|
|
|
BOOL bResult;
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Lock the region */
|
|
|
|
prgn = REGION_LockRgn(hrgn);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (prgn == NULL)
|
2015-03-08 23:36:14 +00:00
|
|
|
{
|
|
|
|
DPRINT1("NtGdiPtInRegion: hrgn error\n");
|
2010-01-04 01:36:24 +00:00
|
|
|
return FALSE;
|
2015-03-08 23:36:14 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Call the internal function */
|
|
|
|
bResult = REGION_PtInRegion(prgn, x, y);
|
2014-07-23 16:05:47 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Unlock and return the result */
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(prgn);
|
2015-03-08 23:36:14 +00:00
|
|
|
return bResult;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2008-02-21 02:40:23 +00:00
|
|
|
|
2015-03-10 00:11:29 +00:00
|
|
|
__kernel_entry
|
2010-01-04 01:36:24 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
NtGdiRectInRegion(
|
2015-03-08 23:36:14 +00:00
|
|
|
_In_ HRGN hrgn,
|
2015-03-10 00:11:29 +00:00
|
|
|
_Inout_ LPRECT prclUnsafe)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2015-03-08 23:36:14 +00:00
|
|
|
RECTL rcTemp;
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Probe and copy the rect */
|
2010-01-04 01:36:24 +00:00
|
|
|
_SEH2_TRY
|
|
|
|
{
|
2015-03-08 23:36:14 +00:00
|
|
|
ProbeForRead(prclUnsafe, sizeof(RECT), 1);
|
|
|
|
rcTemp = *prclUnsafe;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
2015-03-08 23:36:14 +00:00
|
|
|
DPRINT1("NtGdiRectInRegion: Exception accessing the rect\n");
|
|
|
|
return FALSE;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
|
|
|
_SEH2_END;
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Call the internal function */
|
|
|
|
return IntRectInRegion(hrgn, &rcTemp);
|
2004-05-18 15:25:25 +00:00
|
|
|
}
|
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
BOOL
|
|
|
|
APIENTRY
|
|
|
|
NtGdiSetRectRgn(
|
2015-03-08 23:36:14 +00:00
|
|
|
_In_ HRGN hrgn,
|
|
|
|
_In_ INT xLeft,
|
|
|
|
_In_ INT yTop,
|
|
|
|
_In_ INT xRight,
|
|
|
|
_In_ INT yBottom)
|
2004-05-18 15:25:25 +00:00
|
|
|
{
|
2015-03-08 23:36:14 +00:00
|
|
|
PREGION prgn;
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Lock the region */
|
|
|
|
prgn = REGION_LockRgn(hrgn);
|
|
|
|
if (prgn == NULL)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2015-03-08 23:36:14 +00:00
|
|
|
return FALSE;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2008-10-07 23:02:41 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Call the internal API */
|
|
|
|
REGION_SetRectRgn(prgn, xLeft, yTop, xRight, yBottom);
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2015-03-08 23:36:14 +00:00
|
|
|
/* Unlock the region and return success */
|
|
|
|
REGION_UnlockRgn(prgn);
|
2010-01-04 01:36:24 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2010-01-04 01:36:24 +00:00
|
|
|
/*!
|
|
|
|
* MSDN: GetRegionData, Return Values:
|
|
|
|
*
|
|
|
|
* "If the function succeeds and dwCount specifies an adequate number of bytes,
|
|
|
|
* the return value is always dwCount. If dwCount is too small or the function
|
|
|
|
* fails, the return value is 0. If lpRgnData is NULL, the return value is the
|
|
|
|
* required number of bytes.
|
|
|
|
*
|
|
|
|
* If the function fails, the return value is zero."
|
|
|
|
*/
|
2012-12-18 21:44:58 +00:00
|
|
|
_Success_(return!=0)
|
2015-03-10 00:11:29 +00:00
|
|
|
__kernel_entry
|
2012-12-18 21:44:58 +00:00
|
|
|
ULONG
|
|
|
|
APIENTRY
|
2010-01-04 01:36:24 +00:00
|
|
|
NtGdiGetRegionData(
|
2012-12-18 21:44:58 +00:00
|
|
|
_In_ HRGN hrgn,
|
|
|
|
_In_ ULONG cjBuffer,
|
2015-03-10 00:11:29 +00:00
|
|
|
_Out_writes_bytes_to_opt_(cjBuffer, return) LPRGNDATA lpRgnData)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2012-12-19 22:01:54 +00:00
|
|
|
ULONG cjRects, cjSize;
|
2012-12-18 21:44:58 +00:00
|
|
|
PREGION prgn;
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2012-12-18 21:44:58 +00:00
|
|
|
/* Lock the region */
|
2014-12-19 10:34:52 +00:00
|
|
|
prgn = REGION_LockRgn(hrgn);
|
2014-12-18 08:11:19 +00:00
|
|
|
if (prgn == NULL)
|
2010-01-04 01:36:24 +00:00
|
|
|
{
|
2012-12-18 21:44:58 +00:00
|
|
|
EngSetLastError(ERROR_INVALID_HANDLE);
|
|
|
|
return 0;
|
2010-01-04 01:36:24 +00:00
|
|
|
}
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2012-12-19 22:01:54 +00:00
|
|
|
/* Calculate the region sizes */
|
|
|
|
cjRects = prgn->rdh.nCount * sizeof(RECT);
|
|
|
|
cjSize = cjRects + sizeof(RGNDATAHEADER);
|
2004-05-18 15:25:25 +00:00
|
|
|
|
2012-12-18 21:44:58 +00:00
|
|
|
/* Check if region data is requested */
|
|
|
|
if (lpRgnData)
|
2008-02-21 02:40:23 +00:00
|
|
|
{
|
2012-12-18 21:44:58 +00:00
|
|
|
/* Check if the buffer is large enough */
|
|
|
|
if (cjBuffer >= cjSize)
|
|
|
|
{
|
|
|
|
/* Probe the buffer and copy the data */
|
|
|
|
_SEH2_TRY
|
|
|
|
{
|
|
|
|
ProbeForWrite(lpRgnData, cjSize, sizeof(ULONG));
|
|
|
|
RtlCopyMemory(lpRgnData, &prgn->rdh, sizeof(RGNDATAHEADER));
|
2012-12-19 22:01:54 +00:00
|
|
|
RtlCopyMemory(lpRgnData->Buffer, prgn->Buffer, cjRects);
|
2014-11-04 20:20:45 +00:00
|
|
|
lpRgnData->rdh.iType = RDH_RECTANGLES;
|
2017-04-04 10:07:07 +00:00
|
|
|
lpRgnData->rdh.nRgnSize = cjRects;
|
2012-12-18 21:44:58 +00:00
|
|
|
}
|
|
|
|
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
|
|
|
|
{
|
|
|
|
EngSetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
cjSize = 0;
|
|
|
|
}
|
|
|
|
_SEH2_END;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Buffer is too small */
|
|
|
|
EngSetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
cjSize = 0;
|
|
|
|
}
|
2004-05-18 15:25:25 +00:00
|
|
|
}
|
2010-01-04 01:36:24 +00:00
|
|
|
|
2012-12-18 21:44:58 +00:00
|
|
|
/* Unlock the region and return the size */
|
2014-12-19 10:34:52 +00:00
|
|
|
REGION_UnlockRgn(prgn);
|
2012-12-18 21:44:58 +00:00
|
|
|
return cjSize;
|
2004-05-18 15:25:25 +00:00
|
|
|
}
|
|
|
|
|
2003-05-18 17:16:18 +00:00
|
|
|
/* EOF */
|