diff options
author | Reinhard Tartler <siretart@tauware.de> | 2011-10-10 17:47:37 +0200 |
---|---|---|
committer | Reinhard Tartler <siretart@tauware.de> | 2011-10-10 17:47:37 +0200 |
commit | 55a9311fb1df3b58f73efa575318e7341243392b (patch) | |
tree | 0444b91d9a638c1dffd5808b28a4d2c235ccd95f | |
parent | aefdef62fc10335a94cbc5bf3cb86b24c8bc1c9f (diff) | |
download | nx-libs-nx-X11/3.3.0-5.tar.gz nx-libs-nx-X11/3.3.0-5.tar.bz2 nx-libs-nx-X11/3.3.0-5.zip |
Imported nx-X11-3.3.0-5.tar.gznx-X11/3.3.0-5
Summary: Imported nx-X11-3.3.0-5.tar.gz
Keywords:
Imported nx-X11-3.3.0-5.tar.gz
into Git repository
-rw-r--r-- | nx-X11/CHANGELOG | 8 | ||||
-rw-r--r-- | nx-X11/CHANGELOG.NX.original | 8 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/fb/fbtrap.c | 3 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/fb/fbtrap.c.NX.original | 242 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/fb/fbtrap.c.X.original | 239 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/os/utils.c | 13 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/os/utils.c.NX.original | 13 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/render/renderedge.c | 1 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/render/renderedge.c.NX.original | 202 | ||||
-rw-r--r-- | nx-X11/programs/Xserver/render/renderedge.c.X.original | 201 |
10 files changed, 930 insertions, 0 deletions
diff --git a/nx-X11/CHANGELOG b/nx-X11/CHANGELOG index 800eb02bb..a6c169dd7 100644 --- a/nx-X11/CHANGELOG +++ b/nx-X11/CHANGELOG @@ -1,5 +1,13 @@ ChangeLog: +nx-X11-3.3.0-5 + +- Fixed TR01G02163. Signals need to be blocked before the call to + fork() in the Popen() utility. + +- Fixed TR01G02164. Trapezoid data need to be validated before use. + This issue was the same of CVE-2007-2437. + nx-X11-3.3.0-4 - Enabled the code resetting the Xlib buffer if an IO error occured. diff --git a/nx-X11/CHANGELOG.NX.original b/nx-X11/CHANGELOG.NX.original index 800eb02bb..a6c169dd7 100644 --- a/nx-X11/CHANGELOG.NX.original +++ b/nx-X11/CHANGELOG.NX.original @@ -1,5 +1,13 @@ ChangeLog: +nx-X11-3.3.0-5 + +- Fixed TR01G02163. Signals need to be blocked before the call to + fork() in the Popen() utility. + +- Fixed TR01G02164. Trapezoid data need to be validated before use. + This issue was the same of CVE-2007-2437. + nx-X11-3.3.0-4 - Enabled the code resetting the Xlib buffer if an IO error occured. diff --git a/nx-X11/programs/Xserver/fb/fbtrap.c b/nx-X11/programs/Xserver/fb/fbtrap.c index 39483d8cd..1940bc209 100644 --- a/nx-X11/programs/Xserver/fb/fbtrap.c +++ b/nx-X11/programs/Xserver/fb/fbtrap.c @@ -115,6 +115,9 @@ fbRasterizeTrapezoid (PicturePtr pPicture, RenderEdge l, r; xFixed t, b; + if (!xTrapezoidValid (trap)) + return; + fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff); width = pPicture->pDrawable->width; diff --git a/nx-X11/programs/Xserver/fb/fbtrap.c.NX.original b/nx-X11/programs/Xserver/fb/fbtrap.c.NX.original new file mode 100644 index 000000000..1940bc209 --- /dev/null +++ b/nx-X11/programs/Xserver/fb/fbtrap.c.NX.original @@ -0,0 +1,242 @@ +/* + * $Id: fbtrap.c,v 1.5 2005/07/03 07:01:23 daniels Exp $ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, 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 Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD 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. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "fb.h" + +#ifdef RENDER + +#include "picturestr.h" +#include "mipict.h" +#include "renderedge.h" +#include "fbpict.h" + +void +fbAddTraps (PicturePtr pPicture, + INT16 x_off, + INT16 y_off, + int ntrap, + xTrap *traps) +{ + FbBits *buf; + int bpp; + int width; + int stride; + int height; + int pxoff, pyoff; + + xFixed x_off_fixed; + xFixed y_off_fixed; + RenderEdge l, r; + xFixed t, b; + + fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff); + + width = pPicture->pDrawable->width; + height = pPicture->pDrawable->height; + x_off += pxoff; + y_off += pyoff; + + x_off_fixed = IntToxFixed(y_off); + y_off_fixed = IntToxFixed(y_off); + + while (ntrap--) + { + t = traps->top.y + y_off_fixed; + if (t < 0) + t = 0; + t = RenderSampleCeilY (t, bpp); + + b = traps->bot.y + y_off_fixed; + if (xFixedToInt (b) >= height) + b = IntToxFixed (height) - 1; + b = RenderSampleFloorY (b, bpp); + + if (b >= t) + { + /* initialize edge walkers */ + RenderEdgeInit (&l, bpp, t, + traps->top.l + x_off_fixed, + traps->top.y + y_off_fixed, + traps->bot.l + x_off_fixed, + traps->bot.y + y_off_fixed); + + RenderEdgeInit (&r, bpp, t, + traps->top.r + x_off_fixed, + traps->top.y + y_off_fixed, + traps->bot.r + x_off_fixed, + traps->bot.y + y_off_fixed); + + fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b); + } + traps++; + } +} + +void +fbRasterizeTrapezoid (PicturePtr pPicture, + xTrapezoid *trap, + int x_off, + int y_off) +{ + FbBits *buf; + int bpp; + int width; + int stride; + int height; + int pxoff, pyoff; + + xFixed x_off_fixed; + xFixed y_off_fixed; + RenderEdge l, r; + xFixed t, b; + + if (!xTrapezoidValid (trap)) + return; + + fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff); + + width = pPicture->pDrawable->width; + height = pPicture->pDrawable->height; + x_off += pxoff; + y_off += pyoff; + + x_off_fixed = IntToxFixed(x_off); + y_off_fixed = IntToxFixed(y_off); + t = trap->top + y_off_fixed; + if (t < 0) + t = 0; + t = RenderSampleCeilY (t, bpp); + + b = trap->bottom + y_off_fixed; + if (xFixedToInt (b) >= height) + b = IntToxFixed (height) - 1; + b = RenderSampleFloorY (b, bpp); + + if (b >= t) + { + /* initialize edge walkers */ + RenderLineFixedEdgeInit (&l, bpp, t, &trap->left, x_off, y_off); + RenderLineFixedEdgeInit (&r, bpp, t, &trap->right, x_off, y_off); + + fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b); + } +} + +static int +_GreaterY (xPointFixed *a, xPointFixed *b) +{ + if (a->y == b->y) + return a->x > b->x; + return a->y > b->y; +} + +/* + * Note that the definition of this function is a bit odd because + * of the X coordinate space (y increasing downwards). + */ +static int +_Clockwise (xPointFixed *ref, xPointFixed *a, xPointFixed *b) +{ + xPointFixed ad, bd; + + ad.x = a->x - ref->x; + ad.y = a->y - ref->y; + bd.x = b->x - ref->x; + bd.y = b->y - ref->y; + + return ((xFixed_32_32) bd.y * ad.x - (xFixed_32_32) ad.y * bd.x) < 0; +} + +/* FIXME -- this could be made more efficient */ +void +fbAddTriangles (PicturePtr pPicture, + INT16 x_off, + INT16 y_off, + int ntri, + xTriangle *tris) +{ + xPointFixed *top, *left, *right, *tmp; + xTrapezoid trap; + + for (; ntri; ntri--, tris++) + { + top = &tris->p1; + left = &tris->p2; + right = &tris->p3; + if (_GreaterY (top, left)) { + tmp = left; left = top; top = tmp; + } + if (_GreaterY (top, right)) { + tmp = right; right = top; top = tmp; + } + if (_Clockwise (top, right, left)) { + tmp = right; right = left; left = tmp; + } + + /* + * Two cases: + * + * + + + * / \ / \ + * / \ / \ + * / + + \ + * / -- -- \ + * / -- -- \ + * / --- --- \ + * +-- --+ + */ + + trap.top = top->y; + trap.left.p1 = *top; + trap.left.p2 = *left; + trap.right.p1 = *top; + trap.right.p2 = *right; + if (right->y < left->y) + trap.bottom = right->y; + else + trap.bottom = left->y; + fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off); + if (right->y < left->y) + { + trap.top = right->y; + trap.bottom = left->y; + trap.right.p1 = *right; + trap.right.p2 = *left; + } + else + { + trap.top = left->y; + trap.bottom = right->y; + trap.left.p1 = *left; + trap.left.p2 = *right; + } + fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off); + } +} + +#endif /* RENDER */ diff --git a/nx-X11/programs/Xserver/fb/fbtrap.c.X.original b/nx-X11/programs/Xserver/fb/fbtrap.c.X.original new file mode 100644 index 000000000..39483d8cd --- /dev/null +++ b/nx-X11/programs/Xserver/fb/fbtrap.c.X.original @@ -0,0 +1,239 @@ +/* + * $Id: fbtrap.c,v 1.5 2005/07/03 07:01:23 daniels Exp $ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, 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 Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD 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. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "fb.h" + +#ifdef RENDER + +#include "picturestr.h" +#include "mipict.h" +#include "renderedge.h" +#include "fbpict.h" + +void +fbAddTraps (PicturePtr pPicture, + INT16 x_off, + INT16 y_off, + int ntrap, + xTrap *traps) +{ + FbBits *buf; + int bpp; + int width; + int stride; + int height; + int pxoff, pyoff; + + xFixed x_off_fixed; + xFixed y_off_fixed; + RenderEdge l, r; + xFixed t, b; + + fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff); + + width = pPicture->pDrawable->width; + height = pPicture->pDrawable->height; + x_off += pxoff; + y_off += pyoff; + + x_off_fixed = IntToxFixed(y_off); + y_off_fixed = IntToxFixed(y_off); + + while (ntrap--) + { + t = traps->top.y + y_off_fixed; + if (t < 0) + t = 0; + t = RenderSampleCeilY (t, bpp); + + b = traps->bot.y + y_off_fixed; + if (xFixedToInt (b) >= height) + b = IntToxFixed (height) - 1; + b = RenderSampleFloorY (b, bpp); + + if (b >= t) + { + /* initialize edge walkers */ + RenderEdgeInit (&l, bpp, t, + traps->top.l + x_off_fixed, + traps->top.y + y_off_fixed, + traps->bot.l + x_off_fixed, + traps->bot.y + y_off_fixed); + + RenderEdgeInit (&r, bpp, t, + traps->top.r + x_off_fixed, + traps->top.y + y_off_fixed, + traps->bot.r + x_off_fixed, + traps->bot.y + y_off_fixed); + + fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b); + } + traps++; + } +} + +void +fbRasterizeTrapezoid (PicturePtr pPicture, + xTrapezoid *trap, + int x_off, + int y_off) +{ + FbBits *buf; + int bpp; + int width; + int stride; + int height; + int pxoff, pyoff; + + xFixed x_off_fixed; + xFixed y_off_fixed; + RenderEdge l, r; + xFixed t, b; + + fbGetDrawable (pPicture->pDrawable, buf, stride, bpp, pxoff, pyoff); + + width = pPicture->pDrawable->width; + height = pPicture->pDrawable->height; + x_off += pxoff; + y_off += pyoff; + + x_off_fixed = IntToxFixed(x_off); + y_off_fixed = IntToxFixed(y_off); + t = trap->top + y_off_fixed; + if (t < 0) + t = 0; + t = RenderSampleCeilY (t, bpp); + + b = trap->bottom + y_off_fixed; + if (xFixedToInt (b) >= height) + b = IntToxFixed (height) - 1; + b = RenderSampleFloorY (b, bpp); + + if (b >= t) + { + /* initialize edge walkers */ + RenderLineFixedEdgeInit (&l, bpp, t, &trap->left, x_off, y_off); + RenderLineFixedEdgeInit (&r, bpp, t, &trap->right, x_off, y_off); + + fbRasterizeEdges (buf, bpp, width, stride, &l, &r, t, b); + } +} + +static int +_GreaterY (xPointFixed *a, xPointFixed *b) +{ + if (a->y == b->y) + return a->x > b->x; + return a->y > b->y; +} + +/* + * Note that the definition of this function is a bit odd because + * of the X coordinate space (y increasing downwards). + */ +static int +_Clockwise (xPointFixed *ref, xPointFixed *a, xPointFixed *b) +{ + xPointFixed ad, bd; + + ad.x = a->x - ref->x; + ad.y = a->y - ref->y; + bd.x = b->x - ref->x; + bd.y = b->y - ref->y; + + return ((xFixed_32_32) bd.y * ad.x - (xFixed_32_32) ad.y * bd.x) < 0; +} + +/* FIXME -- this could be made more efficient */ +void +fbAddTriangles (PicturePtr pPicture, + INT16 x_off, + INT16 y_off, + int ntri, + xTriangle *tris) +{ + xPointFixed *top, *left, *right, *tmp; + xTrapezoid trap; + + for (; ntri; ntri--, tris++) + { + top = &tris->p1; + left = &tris->p2; + right = &tris->p3; + if (_GreaterY (top, left)) { + tmp = left; left = top; top = tmp; + } + if (_GreaterY (top, right)) { + tmp = right; right = top; top = tmp; + } + if (_Clockwise (top, right, left)) { + tmp = right; right = left; left = tmp; + } + + /* + * Two cases: + * + * + + + * / \ / \ + * / \ / \ + * / + + \ + * / -- -- \ + * / -- -- \ + * / --- --- \ + * +-- --+ + */ + + trap.top = top->y; + trap.left.p1 = *top; + trap.left.p2 = *left; + trap.right.p1 = *top; + trap.right.p2 = *right; + if (right->y < left->y) + trap.bottom = right->y; + else + trap.bottom = left->y; + fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off); + if (right->y < left->y) + { + trap.top = right->y; + trap.bottom = left->y; + trap.right.p1 = *right; + trap.right.p2 = *left; + } + else + { + trap.top = left->y; + trap.bottom = right->y; + trap.left.p1 = *left; + trap.left.p2 = *right; + } + fbRasterizeTrapezoid (pPicture, &trap, x_off, y_off); + } +} + +#endif /* RENDER */ diff --git a/nx-X11/programs/Xserver/os/utils.c b/nx-X11/programs/Xserver/os/utils.c index c806621ff..104ff86c6 100644 --- a/nx-X11/programs/Xserver/os/utils.c +++ b/nx-X11/programs/Xserver/os/utils.c @@ -1847,12 +1847,19 @@ Popen(char *command, char *type) if (OsVendorStartRedirectErrorFProc != NULL) { OsVendorStartRedirectErrorFProc(); } + OsBlockSignals (); #endif switch (pid = fork()) { case -1: /* error */ close(pdes[0]); close(pdes[1]); xfree(cur); +#ifdef NX_TRANS_EXIT + if (OsVendorEndRedirectErrorFProc != NULL) { + OsVendorEndRedirectErrorFProc(); + } + OsReleaseSignals (); +#endif return NULL; case 0: /* child */ if (setgid(getgid()) == -1) @@ -1917,12 +1924,18 @@ Popen(char *command, char *type) #endif + #ifdef NX_TRANS_EXIT + OsReleaseSignals (); + #endif + execl("/bin/sh", "sh", "-c", command, (char *)NULL); _exit(127); } +#ifndef NX_TRANS_EXIT /* Avoid EINTR during stdio calls */ OsBlockSignals (); +#endif /* parent */ if (*type == 'r') { diff --git a/nx-X11/programs/Xserver/os/utils.c.NX.original b/nx-X11/programs/Xserver/os/utils.c.NX.original index c806621ff..104ff86c6 100644 --- a/nx-X11/programs/Xserver/os/utils.c.NX.original +++ b/nx-X11/programs/Xserver/os/utils.c.NX.original @@ -1847,12 +1847,19 @@ Popen(char *command, char *type) if (OsVendorStartRedirectErrorFProc != NULL) { OsVendorStartRedirectErrorFProc(); } + OsBlockSignals (); #endif switch (pid = fork()) { case -1: /* error */ close(pdes[0]); close(pdes[1]); xfree(cur); +#ifdef NX_TRANS_EXIT + if (OsVendorEndRedirectErrorFProc != NULL) { + OsVendorEndRedirectErrorFProc(); + } + OsReleaseSignals (); +#endif return NULL; case 0: /* child */ if (setgid(getgid()) == -1) @@ -1917,12 +1924,18 @@ Popen(char *command, char *type) #endif + #ifdef NX_TRANS_EXIT + OsReleaseSignals (); + #endif + execl("/bin/sh", "sh", "-c", command, (char *)NULL); _exit(127); } +#ifndef NX_TRANS_EXIT /* Avoid EINTR during stdio calls */ OsBlockSignals (); +#endif /* parent */ if (*type == 'r') { diff --git a/nx-X11/programs/Xserver/render/renderedge.c b/nx-X11/programs/Xserver/render/renderedge.c index b4031944d..f095038e5 100644 --- a/nx-X11/programs/Xserver/render/renderedge.c +++ b/nx-X11/programs/Xserver/render/renderedge.c @@ -143,6 +143,7 @@ RenderEdgeInit (RenderEdge *e, dx = x_bot - x_top; dy = y_bot - y_top; e->dy = dy; + e->dx = 0; if (dy) { if (dx >= 0) diff --git a/nx-X11/programs/Xserver/render/renderedge.c.NX.original b/nx-X11/programs/Xserver/render/renderedge.c.NX.original new file mode 100644 index 000000000..f095038e5 --- /dev/null +++ b/nx-X11/programs/Xserver/render/renderedge.c.NX.original @@ -0,0 +1,202 @@ +/* + * $Id: renderedge.c,v 1.4 2005/07/03 07:02:08 daniels Exp $ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, 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 Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD 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. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "renderedge.h" + +/* + * Compute the smallest value no less than y which is on a + * grid row + */ + +xFixed +RenderSampleCeilY (xFixed y, int n) +{ + xFixed f = xFixedFrac(y); + xFixed i = xFixedFloor(y); + + f = ((f + Y_FRAC_FIRST(n)) / STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n); + if (f > Y_FRAC_LAST(n)) + { + f = Y_FRAC_FIRST(n); + i += xFixed1; + } + return (i | f); +} + +#define _div(a,b) ((a) >= 0 ? (a) / (b) : -((-(a) + (b) - 1) / (b))) + +/* + * Compute the largest value no greater than y which is on a + * grid row + */ +xFixed +RenderSampleFloorY (xFixed y, int n) +{ + xFixed f = xFixedFrac(y); + xFixed i = xFixedFloor (y); + + f = _div(f - Y_FRAC_FIRST(n), STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n); + if (f < Y_FRAC_FIRST(n)) + { + f = Y_FRAC_LAST(n); + i -= xFixed1; + } + return (i | f); +} + +/* + * Step an edge by any amount (including negative values) + */ +void +RenderEdgeStep (RenderEdge *e, int n) +{ + xFixed_48_16 ne; + + e->x += n * e->stepx; + + ne = e->e + n * (xFixed_48_16) e->dx; + + if (n >= 0) + { + if (ne > 0) + { + int nx = (ne + e->dy - 1) / e->dy; + e->e = ne - nx * (xFixed_48_16) e->dy; + e->x += nx * e->signdx; + } + } + else + { + if (ne <= -e->dy) + { + int nx = (-ne) / e->dy; + e->e = ne + nx * (xFixed_48_16) e->dy; + e->x -= nx * e->signdx; + } + } +} + +/* + * A private routine to initialize the multi-step + * elements of an edge structure + */ +static void +_RenderEdgeMultiInit (RenderEdge *e, int n, xFixed *stepx_p, xFixed *dx_p) +{ + xFixed stepx; + xFixed_48_16 ne; + + ne = n * (xFixed_48_16) e->dx; + stepx = n * e->stepx; + if (ne > 0) + { + int nx = ne / e->dy; + ne -= nx * e->dy; + stepx += nx * e->signdx; + } + *dx_p = ne; + *stepx_p = stepx; +} + +/* + * Initialize one edge structure given the line endpoints and a + * starting y value + */ +void +RenderEdgeInit (RenderEdge *e, + int n, + xFixed y_start, + xFixed x_top, + xFixed y_top, + xFixed x_bot, + xFixed y_bot) +{ + xFixed dx, dy; + + e->x = x_top; + e->e = 0; + dx = x_bot - x_top; + dy = y_bot - y_top; + e->dy = dy; + e->dx = 0; + if (dy) + { + if (dx >= 0) + { + e->signdx = 1; + e->stepx = dx / dy; + e->dx = dx % dy; + e->e = -dy; + } + else + { + e->signdx = -1; + e->stepx = -(-dx / dy); + e->dx = -dx % dy; + e->e = 0; + } + + _RenderEdgeMultiInit (e, STEP_Y_SMALL(n), &e->stepx_small, &e->dx_small); + _RenderEdgeMultiInit (e, STEP_Y_BIG(n), &e->stepx_big, &e->dx_big); + } + RenderEdgeStep (e, y_start - y_top); +} + +/* + * Initialize one edge structure given a line, starting y value + * and a pixel offset for the line + */ +void +RenderLineFixedEdgeInit (RenderEdge *e, + int n, + xFixed y, + xLineFixed *line, + int x_off, + int y_off) +{ + xFixed x_off_fixed = IntToxFixed(x_off); + xFixed y_off_fixed = IntToxFixed(y_off); + xPointFixed *top, *bot; + + if (line->p1.y <= line->p2.y) + { + top = &line->p1; + bot = &line->p2; + } + else + { + top = &line->p2; + bot = &line->p1; + } + RenderEdgeInit (e, n, y, + top->x + x_off_fixed, + top->y + y_off_fixed, + bot->x + x_off_fixed, + bot->y + y_off_fixed); +} + diff --git a/nx-X11/programs/Xserver/render/renderedge.c.X.original b/nx-X11/programs/Xserver/render/renderedge.c.X.original new file mode 100644 index 000000000..b4031944d --- /dev/null +++ b/nx-X11/programs/Xserver/render/renderedge.c.X.original @@ -0,0 +1,201 @@ +/* + * $Id: renderedge.c,v 1.4 2005/07/03 07:02:08 daniels Exp $ + * + * Copyright © 2004 Keith Packard + * + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, 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 Keith Packard not be used in + * advertising or publicity pertaining to distribution of the software without + * specific, written prior permission. Keith Packard makes no + * representations about the suitability of this software for any purpose. It + * is provided "as is" without express or implied warranty. + * + * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL KEITH PACKARD 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. + */ + +#ifdef HAVE_DIX_CONFIG_H +#include <dix-config.h> +#endif + +#include "renderedge.h" + +/* + * Compute the smallest value no less than y which is on a + * grid row + */ + +xFixed +RenderSampleCeilY (xFixed y, int n) +{ + xFixed f = xFixedFrac(y); + xFixed i = xFixedFloor(y); + + f = ((f + Y_FRAC_FIRST(n)) / STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n); + if (f > Y_FRAC_LAST(n)) + { + f = Y_FRAC_FIRST(n); + i += xFixed1; + } + return (i | f); +} + +#define _div(a,b) ((a) >= 0 ? (a) / (b) : -((-(a) + (b) - 1) / (b))) + +/* + * Compute the largest value no greater than y which is on a + * grid row + */ +xFixed +RenderSampleFloorY (xFixed y, int n) +{ + xFixed f = xFixedFrac(y); + xFixed i = xFixedFloor (y); + + f = _div(f - Y_FRAC_FIRST(n), STEP_Y_SMALL(n)) * STEP_Y_SMALL(n) + Y_FRAC_FIRST(n); + if (f < Y_FRAC_FIRST(n)) + { + f = Y_FRAC_LAST(n); + i -= xFixed1; + } + return (i | f); +} + +/* + * Step an edge by any amount (including negative values) + */ +void +RenderEdgeStep (RenderEdge *e, int n) +{ + xFixed_48_16 ne; + + e->x += n * e->stepx; + + ne = e->e + n * (xFixed_48_16) e->dx; + + if (n >= 0) + { + if (ne > 0) + { + int nx = (ne + e->dy - 1) / e->dy; + e->e = ne - nx * (xFixed_48_16) e->dy; + e->x += nx * e->signdx; + } + } + else + { + if (ne <= -e->dy) + { + int nx = (-ne) / e->dy; + e->e = ne + nx * (xFixed_48_16) e->dy; + e->x -= nx * e->signdx; + } + } +} + +/* + * A private routine to initialize the multi-step + * elements of an edge structure + */ +static void +_RenderEdgeMultiInit (RenderEdge *e, int n, xFixed *stepx_p, xFixed *dx_p) +{ + xFixed stepx; + xFixed_48_16 ne; + + ne = n * (xFixed_48_16) e->dx; + stepx = n * e->stepx; + if (ne > 0) + { + int nx = ne / e->dy; + ne -= nx * e->dy; + stepx += nx * e->signdx; + } + *dx_p = ne; + *stepx_p = stepx; +} + +/* + * Initialize one edge structure given the line endpoints and a + * starting y value + */ +void +RenderEdgeInit (RenderEdge *e, + int n, + xFixed y_start, + xFixed x_top, + xFixed y_top, + xFixed x_bot, + xFixed y_bot) +{ + xFixed dx, dy; + + e->x = x_top; + e->e = 0; + dx = x_bot - x_top; + dy = y_bot - y_top; + e->dy = dy; + if (dy) + { + if (dx >= 0) + { + e->signdx = 1; + e->stepx = dx / dy; + e->dx = dx % dy; + e->e = -dy; + } + else + { + e->signdx = -1; + e->stepx = -(-dx / dy); + e->dx = -dx % dy; + e->e = 0; + } + + _RenderEdgeMultiInit (e, STEP_Y_SMALL(n), &e->stepx_small, &e->dx_small); + _RenderEdgeMultiInit (e, STEP_Y_BIG(n), &e->stepx_big, &e->dx_big); + } + RenderEdgeStep (e, y_start - y_top); +} + +/* + * Initialize one edge structure given a line, starting y value + * and a pixel offset for the line + */ +void +RenderLineFixedEdgeInit (RenderEdge *e, + int n, + xFixed y, + xLineFixed *line, + int x_off, + int y_off) +{ + xFixed x_off_fixed = IntToxFixed(x_off); + xFixed y_off_fixed = IntToxFixed(y_off); + xPointFixed *top, *bot; + + if (line->p1.y <= line->p2.y) + { + top = &line->p1; + bot = &line->p2; + } + else + { + top = &line->p2; + bot = &line->p1; + } + RenderEdgeInit (e, n, y, + top->x + x_off_fixed, + top->y + y_off_fixed, + bot->x + x_off_fixed, + bot->y + y_off_fixed); +} + |