diff options
author | marha <marha@users.sourceforge.net> | 2010-05-16 20:50:58 +0000 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2010-05-16 20:50:58 +0000 |
commit | 1c94119ae26b94a60bb2c2b33494ed43c3b8a52f (patch) | |
tree | cfe0c736c95314edac7d9f1065be9c13026ed0c1 /xorg-server/fb | |
parent | 6b29aa4559aeb6f795caee047561654bfa0a1954 (diff) | |
download | vcxsrv-1c94119ae26b94a60bb2c2b33494ed43c3b8a52f.tar.gz vcxsrv-1c94119ae26b94a60bb2c2b33494ed43c3b8a52f.tar.bz2 vcxsrv-1c94119ae26b94a60bb2c2b33494ed43c3b8a52f.zip |
svn merge -r588:HEAD ^/branches/released .
Diffstat (limited to 'xorg-server/fb')
-rw-r--r-- | xorg-server/fb/fballpriv.c | 152 | ||||
-rw-r--r-- | xorg-server/fb/fbcmap.c | 1172 | ||||
-rw-r--r-- | xorg-server/fb/fbcopy.c | 748 | ||||
-rw-r--r-- | xorg-server/fb/fboverlay.c | 874 | ||||
-rw-r--r-- | xorg-server/fb/fbpixmap.c | 766 | ||||
-rw-r--r-- | xorg-server/fb/fbscreen.c | 582 | ||||
-rw-r--r-- | xorg-server/fb/fbseg.c | 1470 |
7 files changed, 2883 insertions, 2881 deletions
diff --git a/xorg-server/fb/fballpriv.c b/xorg-server/fb/fballpriv.c index c40796c11..6aee50bce 100644 --- a/xorg-server/fb/fballpriv.c +++ b/xorg-server/fb/fballpriv.c @@ -1,76 +1,76 @@ -/* - * Copyright © 1998 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 FB_SCREEN_PRIVATE -static int fbScreenPrivateKeyIndex; -static DevPrivateKey fbScreenPrivateKey = &fbScreenPrivateKeyIndex; -DevPrivateKey fbGetScreenPrivateKey(void) -{ - return fbScreenPrivateKey; -} -#endif - -static int fbGCPrivateKeyIndex; -static DevPrivateKey fbGCPrivateKey = &fbGCPrivateKeyIndex; -DevPrivateKey fbGetGCPrivateKey(void) -{ - return fbGCPrivateKey; -} - -static int fbWinPrivateKeyIndex; -static DevPrivateKey fbWinPrivateKey = &fbWinPrivateKeyIndex; -DevPrivateKey fbGetWinPrivateKey(void) -{ - return fbWinPrivateKey; -} - -Bool -fbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCKey) -{ - if (pGCKey) - *pGCKey = fbGCPrivateKey; - - if (!dixRequestPrivate(fbGCPrivateKey, sizeof(FbGCPrivRec))) - return FALSE; -#ifdef FB_SCREEN_PRIVATE - { - FbScreenPrivPtr pScreenPriv; - - pScreenPriv = (FbScreenPrivPtr) xalloc (sizeof (FbScreenPrivRec)); - if (!pScreenPriv) - return FALSE; - dixSetPrivate(&pScreen->devPrivates, fbScreenPrivateKey, pScreenPriv); - } -#endif - return TRUE; -} - -#ifdef FB_ACCESS_WRAPPER -ReadMemoryProcPtr wfbReadMemory; -WriteMemoryProcPtr wfbWriteMemory; -#endif +/*
+ * Copyright © 1998 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 FB_SCREEN_PRIVATE
+static int fbScreenPrivateKeyIndex;
+static DevPrivateKey fbScreenPrivateKey = &fbScreenPrivateKeyIndex;
+DevPrivateKey fbGetScreenPrivateKey(void)
+{
+ return fbScreenPrivateKey;
+}
+#endif
+
+static int fbGCPrivateKeyIndex;
+static DevPrivateKey fbGCPrivateKey = &fbGCPrivateKeyIndex;
+DevPrivateKey fbGetGCPrivateKey(void)
+{
+ return fbGCPrivateKey;
+}
+
+static int fbWinPrivateKeyIndex;
+static DevPrivateKey fbWinPrivateKey = &fbWinPrivateKeyIndex;
+DevPrivateKey fbGetWinPrivateKey(void)
+{
+ return fbWinPrivateKey;
+}
+
+Bool
+fbAllocatePrivates(ScreenPtr pScreen, DevPrivateKey *pGCKey)
+{
+ if (pGCKey)
+ *pGCKey = fbGCPrivateKey;
+
+ if (!dixRequestPrivate(fbGCPrivateKey, sizeof(FbGCPrivRec)))
+ return FALSE;
+#ifdef FB_SCREEN_PRIVATE
+ {
+ FbScreenPrivPtr pScreenPriv;
+
+ pScreenPriv = (FbScreenPrivPtr) malloc(sizeof (FbScreenPrivRec));
+ if (!pScreenPriv)
+ return FALSE;
+ dixSetPrivate(&pScreen->devPrivates, fbScreenPrivateKey, pScreenPriv);
+ }
+#endif
+ return TRUE;
+}
+
+#ifdef FB_ACCESS_WRAPPER
+ReadMemoryProcPtr wfbReadMemory;
+WriteMemoryProcPtr wfbWriteMemory;
+#endif
diff --git a/xorg-server/fb/fbcmap.c b/xorg-server/fb/fbcmap.c index b775bc335..e656c2399 100644 --- a/xorg-server/fb/fbcmap.c +++ b/xorg-server/fb/fbcmap.c @@ -1,586 +1,586 @@ -/* - * Copyright © 1987 Sun Microsystems, Inc. All rights reserved. - * - * 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 (including the next - * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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. - */ - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include <X11/X.h> -#include <X11/Xproto.h> -#include "scrnintstr.h" -#include "colormapst.h" -#include "resource.h" -#include "fb.h" - -#ifdef XFree86Server -#error "You should be compiling fbcmap_mi.c instead of fbcmap.c!" -#endif - -static int cmapScrPrivateKeyIndex; -static DevPrivateKey cmapScrPrivateKey = &cmapScrPrivateKeyIndex; - -#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey)) -#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c)) - -int -fbListInstalledColormaps(ScreenPtr pScreen, Colormap *pmaps) -{ - /* By the time we are processing requests, we can guarantee that there - * is always a colormap installed */ - *pmaps = GetInstalledColormap(pScreen)->mid; - return (1); -} - - -void -fbInstallColormap(ColormapPtr pmap) -{ - ColormapPtr oldpmap = GetInstalledColormap(pmap->pScreen); - - if(pmap != oldpmap) - { - /* Uninstall pInstalledMap. No hardware changes required, just - * notify all interested parties. */ - if(oldpmap != (ColormapPtr)None) - WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid); - /* Install pmap */ - SetInstalledColormap(pmap->pScreen, pmap); - WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid); - } -} - -void -fbUninstallColormap(ColormapPtr pmap) -{ - ColormapPtr curpmap = GetInstalledColormap(pmap->pScreen); - - if(pmap == curpmap) - { - if (pmap->mid != pmap->pScreen->defColormap) - { - dixLookupResourceByType((pointer *)&curpmap, - pmap->pScreen->defColormap, - RT_COLORMAP, - serverClient, DixInstallAccess); - (*pmap->pScreen->InstallColormap)(curpmap); - } - } -} - -void -fbResolveColor(unsigned short *pred, - unsigned short *pgreen, - unsigned short *pblue, - VisualPtr pVisual) -{ - int shift = 16 - pVisual->bitsPerRGBValue; - unsigned lim = (1 << pVisual->bitsPerRGBValue) - 1; - - if ((pVisual->class | DynamicClass) == GrayScale) - { - /* rescale to gray then rgb bits */ - *pred = (30L * *pred + 59L * *pgreen + 11L * *pblue) / 100; - *pblue = *pgreen = *pred = ((*pred >> shift) * 65535) / lim; - } - else - { - /* rescale to rgb bits */ - *pred = ((*pred >> shift) * 65535) / lim; - *pgreen = ((*pgreen >> shift) * 65535) / lim; - *pblue = ((*pblue >> shift) * 65535) / lim; - } -} - -Bool -fbInitializeColormap(ColormapPtr pmap) -{ - register unsigned i; - register VisualPtr pVisual; - unsigned lim, maxent, shift; - - pVisual = pmap->pVisual; - lim = (1 << pVisual->bitsPerRGBValue) - 1; - shift = 16 - pVisual->bitsPerRGBValue; - maxent = pVisual->ColormapEntries - 1; - if (pVisual->class == TrueColor) - { - unsigned limr, limg, limb; - - limr = pVisual->redMask >> pVisual->offsetRed; - limg = pVisual->greenMask >> pVisual->offsetGreen; - limb = pVisual->blueMask >> pVisual->offsetBlue; - for(i = 0; i <= maxent; i++) - { - /* rescale to [0..65535] then rgb bits */ - pmap->red[i].co.local.red = - ((((i * 65535) / limr) >> shift) * 65535) / lim; - pmap->green[i].co.local.green = - ((((i * 65535) / limg) >> shift) * 65535) / lim; - pmap->blue[i].co.local.blue = - ((((i * 65535) / limb) >> shift) * 65535) / lim; - } - } - else if (pVisual->class == StaticColor) - { - unsigned n; - unsigned r, g, b; - unsigned red, green, blue; - - for (n = 0; n*n*n < pVisual->ColormapEntries; n++) - ; - n--; - i = 0; - for (r = 0; r < n; r++) - { - red = (((r * 65535 / (n - 1)) >> shift) * 65535) / lim; - for (g = 0; g < n; g++) - { - green = (((g * 65535 / (n - 1)) >> shift) * 65535) / lim; - for (b = 0; b < n; b++) - { - blue = (((b * 65535 / (n - 1)) >> shift) * 65535) / lim; - pmap->red[i].co.local.red = red; - pmap->red[i].co.local.green = green; - pmap->red[i].co.local.blue = blue; - i++; - } - } - } - n = pVisual->ColormapEntries - i; - for (r = 0; r < n; r++) - { - red = (((r * 65535 / (n - 1)) >> shift) * 65535) / lim; - pmap->red[i].co.local.red = red; - pmap->red[i].co.local.green = red; - pmap->red[i].co.local.blue = red; - i++; - } - } - else if (pVisual->class == StaticGray) - { - for(i = 0; i <= maxent; i++) - { - /* rescale to [0..65535] then rgb bits */ - pmap->red[i].co.local.red = ((((i * 65535) / maxent) >> shift) - * 65535) / lim; - pmap->red[i].co.local.green = pmap->red[i].co.local.red; - pmap->red[i].co.local.blue = pmap->red[i].co.local.red; - } - } - return TRUE; -} - -/* When simulating DirectColor on PseudoColor hardware, multiple - entries of the colormap must be updated - */ - -#define AddElement(mask) { \ - pixel = red | green | blue; \ - for (i = 0; i < nresult; i++) \ - if (outdefs[i].pixel == pixel) \ - break; \ - if (i == nresult) \ - { \ - nresult++; \ - outdefs[i].pixel = pixel; \ - outdefs[i].flags = 0; \ - } \ - outdefs[i].flags |= (mask); \ - outdefs[i].red = pmap->red[red >> pVisual->offsetRed].co.local.red; \ - outdefs[i].green = pmap->green[green >> pVisual->offsetGreen].co.local.green; \ - outdefs[i].blue = pmap->blue[blue >> pVisual->offsetBlue].co.local.blue; \ -} - -int -fbExpandDirectColors (ColormapPtr pmap, - int ndef, - xColorItem *indefs, - xColorItem *outdefs) -{ - register int red, green, blue; - int maxred, maxgreen, maxblue; - int stepred, stepgreen, stepblue; - VisualPtr pVisual; - register int pixel; - register int nresult; - register int i; - - pVisual = pmap->pVisual; - - stepred = 1 << pVisual->offsetRed; - stepgreen = 1 << pVisual->offsetGreen; - stepblue = 1 << pVisual->offsetBlue; - maxred = pVisual->redMask; - maxgreen = pVisual->greenMask; - maxblue = pVisual->blueMask; - nresult = 0; - for (;ndef--; indefs++) - { - if (indefs->flags & DoRed) - { - red = indefs->pixel & pVisual->redMask; - for (green = 0; green <= maxgreen; green += stepgreen) - { - for (blue = 0; blue <= maxblue; blue += stepblue) - { - AddElement (DoRed) - } - } - } - if (indefs->flags & DoGreen) - { - green = indefs->pixel & pVisual->greenMask; - for (red = 0; red <= maxred; red += stepred) - { - for (blue = 0; blue <= maxblue; blue += stepblue) - { - AddElement (DoGreen) - } - } - } - if (indefs->flags & DoBlue) - { - blue = indefs->pixel & pVisual->blueMask; - for (red = 0; red <= maxred; red += stepred) - { - for (green = 0; green <= maxgreen; green += stepgreen) - { - AddElement (DoBlue) - } - } - } - } - return nresult; -} - -Bool -fbCreateDefColormap(ScreenPtr pScreen) -{ - unsigned short zero = 0, ones = 0xFFFF; - VisualPtr pVisual; - ColormapPtr cmap; - Pixel wp, bp; - - for (pVisual = pScreen->visuals; - pVisual->vid != pScreen->rootVisual; - pVisual++) - ; - - if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &cmap, - (pVisual->class & DynamicClass) ? AllocNone : AllocAll, - 0) - != Success) - return FALSE; - wp = pScreen->whitePixel; - bp = pScreen->blackPixel; - if ((AllocColor(cmap, &ones, &ones, &ones, &wp, 0) != - Success) || - (AllocColor(cmap, &zero, &zero, &zero, &bp, 0) != - Success)) - return FALSE; - pScreen->whitePixel = wp; - pScreen->blackPixel = bp; - (*pScreen->InstallColormap)(cmap); - return TRUE; -} - -extern int defaultColorVisualClass; - -#define _RZ(d) ((d + 2) / 3) -#define _RS(d) 0 -#define _RM(d) ((1 << _RZ(d)) - 1) -#define _GZ(d) ((d - _RZ(d) + 1) / 2) -#define _GS(d) _RZ(d) -#define _GM(d) (((1 << _GZ(d)) - 1) << _GS(d)) -#define _BZ(d) (d - _RZ(d) - _GZ(d)) -#define _BS(d) (_RZ(d) + _GZ(d)) -#define _BM(d) (((1 << _BZ(d)) - 1) << _BS(d)) -#define _CE(d) (1 << _RZ(d)) - -#define MAX_PSEUDO_DEPTH 10 /* largest DAC size I know */ - -#define StaticGrayMask (1 << StaticGray) -#define GrayScaleMask (1 << GrayScale) -#define StaticColorMask (1 << StaticColor) -#define PseudoColorMask (1 << PseudoColor) -#define TrueColorMask (1 << TrueColor) -#define DirectColorMask (1 << DirectColor) - -#define ALL_VISUALS (StaticGrayMask|\ - GrayScaleMask|\ - StaticColorMask|\ - PseudoColorMask|\ - TrueColorMask|\ - DirectColorMask) - -#define LARGE_VISUALS (TrueColorMask|\ - DirectColorMask) - -typedef struct _fbVisuals { - struct _fbVisuals *next; - int depth; - int bitsPerRGB; - int visuals; - int count; - Pixel redMask, greenMask, blueMask; -} fbVisualsRec, *fbVisualsPtr; - -static const int fbVisualPriority[] = { - PseudoColor, DirectColor, GrayScale, StaticColor, TrueColor, StaticGray -}; - -#define NUM_PRIORITY 6 - -static fbVisualsPtr fbVisuals; - -static int -popCount (int i) -{ - int count; - - count = (i >> 1) & 033333333333; - count = i - count - ((count >> 1) & 033333333333); - count = (((count + (count >> 3)) & 030707070707) % 077); /* HAKMEM 169 */ - return count; -} - -/* - * Distance to least significant one bit - */ -static int -maskShift (Pixel p) -{ - int s; - - if (!p) return 0; - s = 0; - while (!(p & 1)) - { - s++; - p >>= 1; - } - return s; -} - -Bool -fbSetVisualTypesAndMasks (int depth, int visuals, int bitsPerRGB, - Pixel redMask, Pixel greenMask, Pixel blueMask) -{ - fbVisualsPtr new, *prev, v; - - new = (fbVisualsPtr) xalloc (sizeof *new); - if (!new) - return FALSE; - if (!redMask || !greenMask || !blueMask) - { - redMask = _RM(depth); - greenMask = _GM(depth); - blueMask = _BM(depth); - } - new->next = 0; - new->depth = depth; - new->visuals = visuals; - new->bitsPerRGB = bitsPerRGB; - new->redMask = redMask; - new->greenMask = greenMask; - new->blueMask = blueMask; - new->count = popCount (visuals); - for (prev = &fbVisuals; (v = *prev); prev = &v->next); - *prev = new; - return TRUE; -} - -Bool -fbHasVisualTypes (int depth) -{ - fbVisualsPtr v; - - for (v = fbVisuals; v; v = v->next) - if (v->depth == depth) - return TRUE; - return FALSE; -} - -Bool -fbSetVisualTypes (int depth, int visuals, int bitsPerRGB) -{ - return fbSetVisualTypesAndMasks (depth, visuals, bitsPerRGB, - _RM(depth), _GM(depth), _BM(depth)); -} - -/* - * Given a list of formats for a screen, create a list - * of visuals and depths for the screen which coorespond to - * the set which can be used with this version of fb. - */ - -Bool -fbInitVisuals (VisualPtr *visualp, - DepthPtr *depthp, - int *nvisualp, - int *ndepthp, - int *rootDepthp, - VisualID *defaultVisp, - unsigned long sizes, - int bitsPerRGB) -{ - int i, j = 0, k; - VisualPtr visual; - DepthPtr depth; - VisualID *vid; - int d, b; - int f; - int ndepth, nvisual; - int nvtype; - int vtype; - fbVisualsPtr visuals, nextVisuals; - - /* none specified, we'll guess from pixmap formats */ - if (!fbVisuals) - { - for (f = 0; f < screenInfo.numPixmapFormats; f++) - { - d = screenInfo.formats[f].depth; - b = screenInfo.formats[f].bitsPerPixel; - if (sizes & (1 << (b - 1))) - { - if (d > MAX_PSEUDO_DEPTH) - vtype = LARGE_VISUALS; - else if (d == 1) - vtype = StaticGrayMask; - else - vtype = ALL_VISUALS; - } - else - vtype = 0; - if (!fbSetVisualTypes (d, vtype, bitsPerRGB)) - return FALSE; - } - } - nvisual = 0; - ndepth = 0; - for (visuals = fbVisuals; visuals; visuals = nextVisuals) - { - nextVisuals = visuals->next; - ndepth++; - nvisual += visuals->count; - } - depth = (DepthPtr) xalloc (ndepth * sizeof (DepthRec)); - visual = (VisualPtr) xalloc (nvisual * sizeof (VisualRec)); - if (!depth || !visual) - { - xfree (depth); - xfree (visual); - return FALSE; - } - *depthp = depth; - *visualp = visual; - *ndepthp = ndepth; - *nvisualp = nvisual; - for (visuals = fbVisuals; visuals; visuals = nextVisuals) - { - nextVisuals = visuals->next; - d = visuals->depth; - vtype = visuals->visuals; - nvtype = visuals->count; - vid = NULL; - if (nvtype) - { - vid = (VisualID *) xalloc (nvtype * sizeof (VisualID)); - if (!vid) - return FALSE; - } - depth->depth = d; - depth->numVids = nvtype; - depth->vids = vid; - depth++; - for (i = 0; i < NUM_PRIORITY; i++) { - if (! (vtype & (1 << fbVisualPriority[i]))) - continue; - visual->class = fbVisualPriority[i]; - visual->bitsPerRGBValue = visuals->bitsPerRGB; - visual->ColormapEntries = 1 << d; - visual->nplanes = d; - visual->vid = *vid = FakeClientID (0); - switch (visual->class) { - case PseudoColor: - case GrayScale: - case StaticGray: - case StaticColor: - visual->redMask = 0; - visual->greenMask = 0; - visual->blueMask = 0; - visual->offsetRed = 0; - visual->offsetGreen = 0; - visual->offsetBlue = 0; - break; - case DirectColor: - case TrueColor: - visual->ColormapEntries = _CE(d); - visual->redMask = visuals->redMask; - visual->greenMask = visuals->greenMask; - visual->blueMask = visuals->blueMask; - visual->offsetRed = maskShift (visuals->redMask); - visual->offsetGreen = maskShift (visuals->greenMask); - visual->offsetBlue = maskShift (visuals->blueMask); - } - vid++; - visual++; - } - xfree (visuals); - } - fbVisuals = NULL; - visual = *visualp; - depth = *depthp; - for (i = 0; i < ndepth; i++) - { - if (*rootDepthp && *rootDepthp != depth[i].depth) - continue; - for (j = 0; j < depth[i].numVids; j++) - { - for (k = 0; k < nvisual; k++) - if (visual[k].vid == depth[i].vids[j]) - break; - if (k == nvisual) - continue; - if (defaultColorVisualClass < 0 || - visual[k].class == defaultColorVisualClass) - break; - } - if (j != depth[i].numVids) - break; - } - if (i == ndepth) { - for (i = 0; i < ndepth; i++) - { - if (depth[i].numVids) - break; - } - if (i == ndepth) - return FALSE; - j = 0; - } - *rootDepthp = depth[i].depth; - *defaultVisp = depth[i].vids[j]; - return TRUE; -} +/*
+ * Copyright © 1987 Sun Microsystems, Inc. All rights reserved.
+ *
+ * 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 (including the next
+ * paragraph) 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 AUTHORS OR COPYRIGHT HOLDERS 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.
+ */
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <X11/X.h>
+#include <X11/Xproto.h>
+#include "scrnintstr.h"
+#include "colormapst.h"
+#include "resource.h"
+#include "fb.h"
+
+#ifdef XFree86Server
+#error "You should be compiling fbcmap_mi.c instead of fbcmap.c!"
+#endif
+
+static int cmapScrPrivateKeyIndex;
+static DevPrivateKey cmapScrPrivateKey = &cmapScrPrivateKeyIndex;
+
+#define GetInstalledColormap(s) ((ColormapPtr) dixLookupPrivate(&(s)->devPrivates, cmapScrPrivateKey))
+#define SetInstalledColormap(s,c) (dixSetPrivate(&(s)->devPrivates, cmapScrPrivateKey, c))
+
+int
+fbListInstalledColormaps(ScreenPtr pScreen, Colormap *pmaps)
+{
+ /* By the time we are processing requests, we can guarantee that there
+ * is always a colormap installed */
+ *pmaps = GetInstalledColormap(pScreen)->mid;
+ return (1);
+}
+
+
+void
+fbInstallColormap(ColormapPtr pmap)
+{
+ ColormapPtr oldpmap = GetInstalledColormap(pmap->pScreen);
+
+ if(pmap != oldpmap)
+ {
+ /* Uninstall pInstalledMap. No hardware changes required, just
+ * notify all interested parties. */
+ if(oldpmap != (ColormapPtr)None)
+ WalkTree(pmap->pScreen, TellLostMap, (char *)&oldpmap->mid);
+ /* Install pmap */
+ SetInstalledColormap(pmap->pScreen, pmap);
+ WalkTree(pmap->pScreen, TellGainedMap, (char *)&pmap->mid);
+ }
+}
+
+void
+fbUninstallColormap(ColormapPtr pmap)
+{
+ ColormapPtr curpmap = GetInstalledColormap(pmap->pScreen);
+
+ if(pmap == curpmap)
+ {
+ if (pmap->mid != pmap->pScreen->defColormap)
+ {
+ dixLookupResourceByType((pointer *)&curpmap,
+ pmap->pScreen->defColormap,
+ RT_COLORMAP,
+ serverClient, DixInstallAccess);
+ (*pmap->pScreen->InstallColormap)(curpmap);
+ }
+ }
+}
+
+void
+fbResolveColor(unsigned short *pred,
+ unsigned short *pgreen,
+ unsigned short *pblue,
+ VisualPtr pVisual)
+{
+ int shift = 16 - pVisual->bitsPerRGBValue;
+ unsigned lim = (1 << pVisual->bitsPerRGBValue) - 1;
+
+ if ((pVisual->class | DynamicClass) == GrayScale)
+ {
+ /* rescale to gray then rgb bits */
+ *pred = (30L * *pred + 59L * *pgreen + 11L * *pblue) / 100;
+ *pblue = *pgreen = *pred = ((*pred >> shift) * 65535) / lim;
+ }
+ else
+ {
+ /* rescale to rgb bits */
+ *pred = ((*pred >> shift) * 65535) / lim;
+ *pgreen = ((*pgreen >> shift) * 65535) / lim;
+ *pblue = ((*pblue >> shift) * 65535) / lim;
+ }
+}
+
+Bool
+fbInitializeColormap(ColormapPtr pmap)
+{
+ register unsigned i;
+ register VisualPtr pVisual;
+ unsigned lim, maxent, shift;
+
+ pVisual = pmap->pVisual;
+ lim = (1 << pVisual->bitsPerRGBValue) - 1;
+ shift = 16 - pVisual->bitsPerRGBValue;
+ maxent = pVisual->ColormapEntries - 1;
+ if (pVisual->class == TrueColor)
+ {
+ unsigned limr, limg, limb;
+
+ limr = pVisual->redMask >> pVisual->offsetRed;
+ limg = pVisual->greenMask >> pVisual->offsetGreen;
+ limb = pVisual->blueMask >> pVisual->offsetBlue;
+ for(i = 0; i <= maxent; i++)
+ {
+ /* rescale to [0..65535] then rgb bits */
+ pmap->red[i].co.local.red =
+ ((((i * 65535) / limr) >> shift) * 65535) / lim;
+ pmap->green[i].co.local.green =
+ ((((i * 65535) / limg) >> shift) * 65535) / lim;
+ pmap->blue[i].co.local.blue =
+ ((((i * 65535) / limb) >> shift) * 65535) / lim;
+ }
+ }
+ else if (pVisual->class == StaticColor)
+ {
+ unsigned n;
+ unsigned r, g, b;
+ unsigned red, green, blue;
+
+ for (n = 0; n*n*n < pVisual->ColormapEntries; n++)
+ ;
+ n--;
+ i = 0;
+ for (r = 0; r < n; r++)
+ {
+ red = (((r * 65535 / (n - 1)) >> shift) * 65535) / lim;
+ for (g = 0; g < n; g++)
+ {
+ green = (((g * 65535 / (n - 1)) >> shift) * 65535) / lim;
+ for (b = 0; b < n; b++)
+ {
+ blue = (((b * 65535 / (n - 1)) >> shift) * 65535) / lim;
+ pmap->red[i].co.local.red = red;
+ pmap->red[i].co.local.green = green;
+ pmap->red[i].co.local.blue = blue;
+ i++;
+ }
+ }
+ }
+ n = pVisual->ColormapEntries - i;
+ for (r = 0; r < n; r++)
+ {
+ red = (((r * 65535 / (n - 1)) >> shift) * 65535) / lim;
+ pmap->red[i].co.local.red = red;
+ pmap->red[i].co.local.green = red;
+ pmap->red[i].co.local.blue = red;
+ i++;
+ }
+ }
+ else if (pVisual->class == StaticGray)
+ {
+ for(i = 0; i <= maxent; i++)
+ {
+ /* rescale to [0..65535] then rgb bits */
+ pmap->red[i].co.local.red = ((((i * 65535) / maxent) >> shift)
+ * 65535) / lim;
+ pmap->red[i].co.local.green = pmap->red[i].co.local.red;
+ pmap->red[i].co.local.blue = pmap->red[i].co.local.red;
+ }
+ }
+ return TRUE;
+}
+
+/* When simulating DirectColor on PseudoColor hardware, multiple
+ entries of the colormap must be updated
+ */
+
+#define AddElement(mask) { \
+ pixel = red | green | blue; \
+ for (i = 0; i < nresult; i++) \
+ if (outdefs[i].pixel == pixel) \
+ break; \
+ if (i == nresult) \
+ { \
+ nresult++; \
+ outdefs[i].pixel = pixel; \
+ outdefs[i].flags = 0; \
+ } \
+ outdefs[i].flags |= (mask); \
+ outdefs[i].red = pmap->red[red >> pVisual->offsetRed].co.local.red; \
+ outdefs[i].green = pmap->green[green >> pVisual->offsetGreen].co.local.green; \
+ outdefs[i].blue = pmap->blue[blue >> pVisual->offsetBlue].co.local.blue; \
+}
+
+int
+fbExpandDirectColors (ColormapPtr pmap,
+ int ndef,
+ xColorItem *indefs,
+ xColorItem *outdefs)
+{
+ register int red, green, blue;
+ int maxred, maxgreen, maxblue;
+ int stepred, stepgreen, stepblue;
+ VisualPtr pVisual;
+ register int pixel;
+ register int nresult;
+ register int i;
+
+ pVisual = pmap->pVisual;
+
+ stepred = 1 << pVisual->offsetRed;
+ stepgreen = 1 << pVisual->offsetGreen;
+ stepblue = 1 << pVisual->offsetBlue;
+ maxred = pVisual->redMask;
+ maxgreen = pVisual->greenMask;
+ maxblue = pVisual->blueMask;
+ nresult = 0;
+ for (;ndef--; indefs++)
+ {
+ if (indefs->flags & DoRed)
+ {
+ red = indefs->pixel & pVisual->redMask;
+ for (green = 0; green <= maxgreen; green += stepgreen)
+ {
+ for (blue = 0; blue <= maxblue; blue += stepblue)
+ {
+ AddElement (DoRed)
+ }
+ }
+ }
+ if (indefs->flags & DoGreen)
+ {
+ green = indefs->pixel & pVisual->greenMask;
+ for (red = 0; red <= maxred; red += stepred)
+ {
+ for (blue = 0; blue <= maxblue; blue += stepblue)
+ {
+ AddElement (DoGreen)
+ }
+ }
+ }
+ if (indefs->flags & DoBlue)
+ {
+ blue = indefs->pixel & pVisual->blueMask;
+ for (red = 0; red <= maxred; red += stepred)
+ {
+ for (green = 0; green <= maxgreen; green += stepgreen)
+ {
+ AddElement (DoBlue)
+ }
+ }
+ }
+ }
+ return nresult;
+}
+
+Bool
+fbCreateDefColormap(ScreenPtr pScreen)
+{
+ unsigned short zero = 0, ones = 0xFFFF;
+ VisualPtr pVisual;
+ ColormapPtr cmap;
+ Pixel wp, bp;
+
+ for (pVisual = pScreen->visuals;
+ pVisual->vid != pScreen->rootVisual;
+ pVisual++)
+ ;
+
+ if (CreateColormap(pScreen->defColormap, pScreen, pVisual, &cmap,
+ (pVisual->class & DynamicClass) ? AllocNone : AllocAll,
+ 0)
+ != Success)
+ return FALSE;
+ wp = pScreen->whitePixel;
+ bp = pScreen->blackPixel;
+ if ((AllocColor(cmap, &ones, &ones, &ones, &wp, 0) !=
+ Success) ||
+ (AllocColor(cmap, &zero, &zero, &zero, &bp, 0) !=
+ Success))
+ return FALSE;
+ pScreen->whitePixel = wp;
+ pScreen->blackPixel = bp;
+ (*pScreen->InstallColormap)(cmap);
+ return TRUE;
+}
+
+extern int defaultColorVisualClass;
+
+#define _RZ(d) ((d + 2) / 3)
+#define _RS(d) 0
+#define _RM(d) ((1 << _RZ(d)) - 1)
+#define _GZ(d) ((d - _RZ(d) + 1) / 2)
+#define _GS(d) _RZ(d)
+#define _GM(d) (((1 << _GZ(d)) - 1) << _GS(d))
+#define _BZ(d) (d - _RZ(d) - _GZ(d))
+#define _BS(d) (_RZ(d) + _GZ(d))
+#define _BM(d) (((1 << _BZ(d)) - 1) << _BS(d))
+#define _CE(d) (1 << _RZ(d))
+
+#define MAX_PSEUDO_DEPTH 10 /* largest DAC size I know */
+
+#define StaticGrayMask (1 << StaticGray)
+#define GrayScaleMask (1 << GrayScale)
+#define StaticColorMask (1 << StaticColor)
+#define PseudoColorMask (1 << PseudoColor)
+#define TrueColorMask (1 << TrueColor)
+#define DirectColorMask (1 << DirectColor)
+
+#define ALL_VISUALS (StaticGrayMask|\
+ GrayScaleMask|\
+ StaticColorMask|\
+ PseudoColorMask|\
+ TrueColorMask|\
+ DirectColorMask)
+
+#define LARGE_VISUALS (TrueColorMask|\
+ DirectColorMask)
+
+typedef struct _fbVisuals {
+ struct _fbVisuals *next;
+ int depth;
+ int bitsPerRGB;
+ int visuals;
+ int count;
+ Pixel redMask, greenMask, blueMask;
+} fbVisualsRec, *fbVisualsPtr;
+
+static const int fbVisualPriority[] = {
+ PseudoColor, DirectColor, GrayScale, StaticColor, TrueColor, StaticGray
+};
+
+#define NUM_PRIORITY 6
+
+static fbVisualsPtr fbVisuals;
+
+static int
+popCount (int i)
+{
+ int count;
+
+ count = (i >> 1) & 033333333333;
+ count = i - count - ((count >> 1) & 033333333333);
+ count = (((count + (count >> 3)) & 030707070707) % 077); /* HAKMEM 169 */
+ return count;
+}
+
+/*
+ * Distance to least significant one bit
+ */
+static int
+maskShift (Pixel p)
+{
+ int s;
+
+ if (!p) return 0;
+ s = 0;
+ while (!(p & 1))
+ {
+ s++;
+ p >>= 1;
+ }
+ return s;
+}
+
+Bool
+fbSetVisualTypesAndMasks (int depth, int visuals, int bitsPerRGB,
+ Pixel redMask, Pixel greenMask, Pixel blueMask)
+{
+ fbVisualsPtr new, *prev, v;
+
+ new = (fbVisualsPtr) malloc(sizeof *new);
+ if (!new)
+ return FALSE;
+ if (!redMask || !greenMask || !blueMask)
+ {
+ redMask = _RM(depth);
+ greenMask = _GM(depth);
+ blueMask = _BM(depth);
+ }
+ new->next = 0;
+ new->depth = depth;
+ new->visuals = visuals;
+ new->bitsPerRGB = bitsPerRGB;
+ new->redMask = redMask;
+ new->greenMask = greenMask;
+ new->blueMask = blueMask;
+ new->count = popCount (visuals);
+ for (prev = &fbVisuals; (v = *prev); prev = &v->next);
+ *prev = new;
+ return TRUE;
+}
+
+Bool
+fbHasVisualTypes (int depth)
+{
+ fbVisualsPtr v;
+
+ for (v = fbVisuals; v; v = v->next)
+ if (v->depth == depth)
+ return TRUE;
+ return FALSE;
+}
+
+Bool
+fbSetVisualTypes (int depth, int visuals, int bitsPerRGB)
+{
+ return fbSetVisualTypesAndMasks (depth, visuals, bitsPerRGB,
+ _RM(depth), _GM(depth), _BM(depth));
+}
+
+/*
+ * Given a list of formats for a screen, create a list
+ * of visuals and depths for the screen which coorespond to
+ * the set which can be used with this version of fb.
+ */
+
+Bool
+fbInitVisuals (VisualPtr *visualp,
+ DepthPtr *depthp,
+ int *nvisualp,
+ int *ndepthp,
+ int *rootDepthp,
+ VisualID *defaultVisp,
+ unsigned long sizes,
+ int bitsPerRGB)
+{
+ int i, j = 0, k;
+ VisualPtr visual;
+ DepthPtr depth;
+ VisualID *vid;
+ int d, b;
+ int f;
+ int ndepth, nvisual;
+ int nvtype;
+ int vtype;
+ fbVisualsPtr visuals, nextVisuals;
+
+ /* none specified, we'll guess from pixmap formats */
+ if (!fbVisuals)
+ {
+ for (f = 0; f < screenInfo.numPixmapFormats; f++)
+ {
+ d = screenInfo.formats[f].depth;
+ b = screenInfo.formats[f].bitsPerPixel;
+ if (sizes & (1 << (b - 1)))
+ {
+ if (d > MAX_PSEUDO_DEPTH)
+ vtype = LARGE_VISUALS;
+ else if (d == 1)
+ vtype = StaticGrayMask;
+ else
+ vtype = ALL_VISUALS;
+ }
+ else
+ vtype = 0;
+ if (!fbSetVisualTypes (d, vtype, bitsPerRGB))
+ return FALSE;
+ }
+ }
+ nvisual = 0;
+ ndepth = 0;
+ for (visuals = fbVisuals; visuals; visuals = nextVisuals)
+ {
+ nextVisuals = visuals->next;
+ ndepth++;
+ nvisual += visuals->count;
+ }
+ depth = (DepthPtr) malloc(ndepth * sizeof (DepthRec));
+ visual = (VisualPtr) malloc(nvisual * sizeof (VisualRec));
+ if (!depth || !visual)
+ {
+ free(depth);
+ free(visual);
+ return FALSE;
+ }
+ *depthp = depth;
+ *visualp = visual;
+ *ndepthp = ndepth;
+ *nvisualp = nvisual;
+ for (visuals = fbVisuals; visuals; visuals = nextVisuals)
+ {
+ nextVisuals = visuals->next;
+ d = visuals->depth;
+ vtype = visuals->visuals;
+ nvtype = visuals->count;
+ vid = NULL;
+ if (nvtype)
+ {
+ vid = (VisualID *) malloc(nvtype * sizeof (VisualID));
+ if (!vid)
+ return FALSE;
+ }
+ depth->depth = d;
+ depth->numVids = nvtype;
+ depth->vids = vid;
+ depth++;
+ for (i = 0; i < NUM_PRIORITY; i++) {
+ if (! (vtype & (1 << fbVisualPriority[i])))
+ continue;
+ visual->class = fbVisualPriority[i];
+ visual->bitsPerRGBValue = visuals->bitsPerRGB;
+ visual->ColormapEntries = 1 << d;
+ visual->nplanes = d;
+ visual->vid = *vid = FakeClientID (0);
+ switch (visual->class) {
+ case PseudoColor:
+ case GrayScale:
+ case StaticGray:
+ case StaticColor:
+ visual->redMask = 0;
+ visual->greenMask = 0;
+ visual->blueMask = 0;
+ visual->offsetRed = 0;
+ visual->offsetGreen = 0;
+ visual->offsetBlue = 0;
+ break;
+ case DirectColor:
+ case TrueColor:
+ visual->ColormapEntries = _CE(d);
+ visual->redMask = visuals->redMask;
+ visual->greenMask = visuals->greenMask;
+ visual->blueMask = visuals->blueMask;
+ visual->offsetRed = maskShift (visuals->redMask);
+ visual->offsetGreen = maskShift (visuals->greenMask);
+ visual->offsetBlue = maskShift (visuals->blueMask);
+ }
+ vid++;
+ visual++;
+ }
+ free(visuals);
+ }
+ fbVisuals = NULL;
+ visual = *visualp;
+ depth = *depthp;
+ for (i = 0; i < ndepth; i++)
+ {
+ if (*rootDepthp && *rootDepthp != depth[i].depth)
+ continue;
+ for (j = 0; j < depth[i].numVids; j++)
+ {
+ for (k = 0; k < nvisual; k++)
+ if (visual[k].vid == depth[i].vids[j])
+ break;
+ if (k == nvisual)
+ continue;
+ if (defaultColorVisualClass < 0 ||
+ visual[k].class == defaultColorVisualClass)
+ break;
+ }
+ if (j != depth[i].numVids)
+ break;
+ }
+ if (i == ndepth) {
+ for (i = 0; i < ndepth; i++)
+ {
+ if (depth[i].numVids)
+ break;
+ }
+ if (i == ndepth)
+ return FALSE;
+ j = 0;
+ }
+ *rootDepthp = depth[i].depth;
+ *defaultVisp = depth[i].vids[j];
+ return TRUE;
+}
diff --git a/xorg-server/fb/fbcopy.c b/xorg-server/fb/fbcopy.c index 07eb663c6..30cbf7b25 100644 --- a/xorg-server/fb/fbcopy.c +++ b/xorg-server/fb/fbcopy.c @@ -1,374 +1,374 @@ -/* - * Copyright © 1998 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 <stdlib.h> - -#include "fb.h" - -/* Compatibility wrapper, to be removed at next ABI change. */ -void -fbCopyRegion (DrawablePtr pSrcDrawable, - DrawablePtr pDstDrawable, - GCPtr pGC, - RegionPtr pDstRegion, - int dx, - int dy, - fbCopyProc copyProc, - Pixel bitPlane, - void *closure) -{ - miCopyRegion(pSrcDrawable, pDstDrawable, pGC, pDstRegion, dx, dy, copyProc, bitPlane, closure); -} - -/* Compatibility wrapper, to be removed at next ABI change. */ -RegionPtr -fbDoCopy (DrawablePtr pSrcDrawable, - DrawablePtr pDstDrawable, - GCPtr pGC, - int xIn, - int yIn, - int widthSrc, - int heightSrc, - int xOut, - int yOut, - fbCopyProc copyProc, - Pixel bitPlane, - void *closure) -{ - return miDoCopy(pSrcDrawable, pDstDrawable, pGC, xIn, yIn, widthSrc, heightSrc, xOut, yOut, copyProc, bitPlane, closure); -} - -void -fbCopyNtoN (DrawablePtr pSrcDrawable, - DrawablePtr pDstDrawable, - GCPtr pGC, - BoxPtr pbox, - int nbox, - int dx, - int dy, - Bool reverse, - Bool upsidedown, - Pixel bitplane, - void *closure) -{ - CARD8 alu = pGC ? pGC->alu : GXcopy; - FbBits pm = pGC ? fbGetGCPrivate(pGC)->pm : FB_ALLONES; - FbBits *src; - FbStride srcStride; - int srcBpp; - int srcXoff, srcYoff; - FbBits *dst; - FbStride dstStride; - int dstBpp; - int dstXoff, dstYoff; - - fbGetDrawable (pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff); - fbGetDrawable (pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); - - while (nbox--) - { -#ifndef FB_ACCESS_WRAPPER /* pixman_blt() doesn't support accessors yet */ - if (pm == FB_ALLONES && alu == GXcopy && !reverse && - !upsidedown) - { - if (!pixman_blt ((uint32_t *)src, (uint32_t *)dst, srcStride, dstStride, srcBpp, dstBpp, - (pbox->x1 + dx + srcXoff), - (pbox->y1 + dy + srcYoff), - (pbox->x1 + dstXoff), - (pbox->y1 + dstYoff), - (pbox->x2 - pbox->x1), - (pbox->y2 - pbox->y1))) - goto fallback; - else - goto next; - } - fallback: -#endif - fbBlt (src + (pbox->y1 + dy + srcYoff) * srcStride, - srcStride, - (pbox->x1 + dx + srcXoff) * srcBpp, - - dst + (pbox->y1 + dstYoff) * dstStride, - dstStride, - (pbox->x1 + dstXoff) * dstBpp, - - (pbox->x2 - pbox->x1) * dstBpp, - (pbox->y2 - pbox->y1), - - alu, - pm, - dstBpp, - - reverse, - upsidedown); -#ifndef FB_ACCESS_WRAPPER - next: -#endif - pbox++; - } - fbFinishAccess (pDstDrawable); - fbFinishAccess (pSrcDrawable); -} - -void -fbCopy1toN (DrawablePtr pSrcDrawable, - DrawablePtr pDstDrawable, - GCPtr pGC, - BoxPtr pbox, - int nbox, - int dx, - int dy, - Bool reverse, - Bool upsidedown, - Pixel bitplane, - void *closure) -{ - FbGCPrivPtr pPriv = fbGetGCPrivate(pGC); - FbBits *src; - FbStride srcStride; - int srcBpp; - int srcXoff, srcYoff; - FbBits *dst; - FbStride dstStride; - int dstBpp; - int dstXoff, dstYoff; - - fbGetDrawable (pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff); - fbGetDrawable (pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); - - while (nbox--) - { - if (dstBpp == 1) - { - fbBlt (src + (pbox->y1 + dy + srcYoff) * srcStride, - srcStride, - (pbox->x1 + dx + srcXoff) * srcBpp, - - dst + (pbox->y1 + dstYoff) * dstStride, - dstStride, - (pbox->x1 + dstXoff) * dstBpp, - - (pbox->x2 - pbox->x1) * dstBpp, - (pbox->y2 - pbox->y1), - - FbOpaqueStipple1Rop(pGC->alu, - pGC->fgPixel,pGC->bgPixel), - pPriv->pm, - dstBpp, - - reverse, - upsidedown); - } - else - { - fbBltOne ((FbStip *) (src + (pbox->y1 + dy + srcYoff) * srcStride), - srcStride*(FB_UNIT/FB_STIP_UNIT), - (pbox->x1 + dx + srcXoff), - - dst + (pbox->y1 + dstYoff) * dstStride, - dstStride, - (pbox->x1 + dstXoff) * dstBpp, - dstBpp, - - (pbox->x2 - pbox->x1) * dstBpp, - (pbox->y2 - pbox->y1), - - pPriv->and, pPriv->xor, - pPriv->bgand, pPriv->bgxor); - } - pbox++; - } - - fbFinishAccess (pDstDrawable); - fbFinishAccess (pSrcDrawable); -} - -void -fbCopyNto1 (DrawablePtr pSrcDrawable, - DrawablePtr pDstDrawable, - GCPtr pGC, - BoxPtr pbox, - int nbox, - int dx, - int dy, - Bool reverse, - Bool upsidedown, - Pixel bitplane, - void *closure) -{ - FbGCPrivPtr pPriv = fbGetGCPrivate (pGC); - - while (nbox--) - { - if (pDstDrawable->bitsPerPixel == 1) - { - FbBits *src; - FbStride srcStride; - int srcBpp; - int srcXoff, srcYoff; - - FbStip *dst; - FbStride dstStride; - int dstBpp; - int dstXoff, dstYoff; - - fbGetDrawable (pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff); - fbGetStipDrawable (pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); - fbBltPlane (src + (pbox->y1+ dy + srcYoff) * srcStride, - srcStride, - (pbox->x1 + dx + srcXoff) * srcBpp, - srcBpp, - - dst + (pbox->y1 + dstYoff) * dstStride, - dstStride, - (pbox->x1 + dstXoff) * dstBpp, - - (pbox->x2 - pbox->x1) * srcBpp, - (pbox->y2 - pbox->y1), - - (FbStip) pPriv->and, (FbStip) pPriv->xor, - (FbStip) pPriv->bgand, (FbStip) pPriv->bgxor, - bitplane); - fbFinishAccess (pDstDrawable); - fbFinishAccess (pSrcDrawable); - } - else - { - FbBits *src; - FbStride srcStride; - int srcBpp; - int srcXoff, srcYoff; - - FbBits *dst; - FbStride dstStride; - int dstBpp; - int dstXoff, dstYoff; - - FbStip *tmp; - FbStride tmpStride; - int width, height; - - width = pbox->x2 - pbox->x1; - height = pbox->y2 - pbox->y1; - - tmpStride = ((width + FB_STIP_MASK) >> FB_STIP_SHIFT); - tmp = xalloc (tmpStride * height * sizeof (FbStip)); - if (!tmp) - return; - - fbGetDrawable (pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff); - fbGetDrawable (pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); - - fbBltPlane (src + (pbox->y1+ dy + srcYoff) * srcStride, - srcStride, - (pbox->x1 + dx + srcXoff) * srcBpp, - srcBpp, - - tmp, - tmpStride, - 0, - - width * srcBpp, - height, - - fbAndStip(GXcopy,FB_ALLONES,FB_ALLONES), - fbXorStip(GXcopy,FB_ALLONES,FB_ALLONES), - fbAndStip(GXcopy,0,FB_ALLONES), - fbXorStip(GXcopy,0,FB_ALLONES), - bitplane); - fbBltOne (tmp, - tmpStride, - 0, - - dst + (pbox->y1 + dstYoff) * dstStride, - dstStride, - (pbox->x1 + dstXoff) * dstBpp, - dstBpp, - - width * dstBpp, - height, - - pPriv->and, pPriv->xor, - pPriv->bgand, pPriv->bgxor); - xfree (tmp); - - fbFinishAccess (pDstDrawable); - fbFinishAccess (pSrcDrawable); - } - pbox++; - } -} - -RegionPtr -fbCopyArea (DrawablePtr pSrcDrawable, - DrawablePtr pDstDrawable, - GCPtr pGC, - int xIn, - int yIn, - int widthSrc, - int heightSrc, - int xOut, - int yOut) -{ - miCopyProc copy; - -#ifdef FB_24_32BIT - if (pSrcDrawable->bitsPerPixel != pDstDrawable->bitsPerPixel) - copy = fb24_32CopyMtoN; - else -#endif - copy = fbCopyNtoN; - return miDoCopy (pSrcDrawable, pDstDrawable, pGC, xIn, yIn, - widthSrc, heightSrc, xOut, yOut, copy, 0, 0); -} - -RegionPtr -fbCopyPlane (DrawablePtr pSrcDrawable, - DrawablePtr pDstDrawable, - GCPtr pGC, - int xIn, - int yIn, - int widthSrc, - int heightSrc, - int xOut, - int yOut, - unsigned long bitplane) -{ - if (pSrcDrawable->bitsPerPixel > 1) - return miDoCopy (pSrcDrawable, pDstDrawable, pGC, - xIn, yIn, widthSrc, heightSrc, - xOut, yOut, fbCopyNto1, (Pixel) bitplane, 0); - else if (bitplane & 1) - return miDoCopy (pSrcDrawable, pDstDrawable, pGC, xIn, yIn, - widthSrc, heightSrc, xOut, yOut, fbCopy1toN, - (Pixel) bitplane, 0); - else - return miHandleExposures(pSrcDrawable, pDstDrawable, pGC, - xIn, yIn, - widthSrc, - heightSrc, - xOut, yOut, bitplane); -} +/*
+ * Copyright © 1998 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 <stdlib.h>
+
+#include "fb.h"
+
+/* Compatibility wrapper, to be removed at next ABI change. */
+void
+fbCopyRegion (DrawablePtr pSrcDrawable,
+ DrawablePtr pDstDrawable,
+ GCPtr pGC,
+ RegionPtr pDstRegion,
+ int dx,
+ int dy,
+ fbCopyProc copyProc,
+ Pixel bitPlane,
+ void *closure)
+{
+ miCopyRegion(pSrcDrawable, pDstDrawable, pGC, pDstRegion, dx, dy, copyProc, bitPlane, closure);
+}
+
+/* Compatibility wrapper, to be removed at next ABI change. */
+RegionPtr
+fbDoCopy (DrawablePtr pSrcDrawable,
+ DrawablePtr pDstDrawable,
+ GCPtr pGC,
+ int xIn,
+ int yIn,
+ int widthSrc,
+ int heightSrc,
+ int xOut,
+ int yOut,
+ fbCopyProc copyProc,
+ Pixel bitPlane,
+ void *closure)
+{
+ return miDoCopy(pSrcDrawable, pDstDrawable, pGC, xIn, yIn, widthSrc, heightSrc, xOut, yOut, copyProc, bitPlane, closure);
+}
+
+void
+fbCopyNtoN (DrawablePtr pSrcDrawable,
+ DrawablePtr pDstDrawable,
+ GCPtr pGC,
+ BoxPtr pbox,
+ int nbox,
+ int dx,
+ int dy,
+ Bool reverse,
+ Bool upsidedown,
+ Pixel bitplane,
+ void *closure)
+{
+ CARD8 alu = pGC ? pGC->alu : GXcopy;
+ FbBits pm = pGC ? fbGetGCPrivate(pGC)->pm : FB_ALLONES;
+ FbBits *src;
+ FbStride srcStride;
+ int srcBpp;
+ int srcXoff, srcYoff;
+ FbBits *dst;
+ FbStride dstStride;
+ int dstBpp;
+ int dstXoff, dstYoff;
+
+ fbGetDrawable (pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
+ fbGetDrawable (pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+
+ while (nbox--)
+ {
+#ifndef FB_ACCESS_WRAPPER /* pixman_blt() doesn't support accessors yet */
+ if (pm == FB_ALLONES && alu == GXcopy && !reverse &&
+ !upsidedown)
+ {
+ if (!pixman_blt ((uint32_t *)src, (uint32_t *)dst, srcStride, dstStride, srcBpp, dstBpp,
+ (pbox->x1 + dx + srcXoff),
+ (pbox->y1 + dy + srcYoff),
+ (pbox->x1 + dstXoff),
+ (pbox->y1 + dstYoff),
+ (pbox->x2 - pbox->x1),
+ (pbox->y2 - pbox->y1)))
+ goto fallback;
+ else
+ goto next;
+ }
+ fallback:
+#endif
+ fbBlt (src + (pbox->y1 + dy + srcYoff) * srcStride,
+ srcStride,
+ (pbox->x1 + dx + srcXoff) * srcBpp,
+
+ dst + (pbox->y1 + dstYoff) * dstStride,
+ dstStride,
+ (pbox->x1 + dstXoff) * dstBpp,
+
+ (pbox->x2 - pbox->x1) * dstBpp,
+ (pbox->y2 - pbox->y1),
+
+ alu,
+ pm,
+ dstBpp,
+
+ reverse,
+ upsidedown);
+#ifndef FB_ACCESS_WRAPPER
+ next:
+#endif
+ pbox++;
+ }
+ fbFinishAccess (pDstDrawable);
+ fbFinishAccess (pSrcDrawable);
+}
+
+void
+fbCopy1toN (DrawablePtr pSrcDrawable,
+ DrawablePtr pDstDrawable,
+ GCPtr pGC,
+ BoxPtr pbox,
+ int nbox,
+ int dx,
+ int dy,
+ Bool reverse,
+ Bool upsidedown,
+ Pixel bitplane,
+ void *closure)
+{
+ FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
+ FbBits *src;
+ FbStride srcStride;
+ int srcBpp;
+ int srcXoff, srcYoff;
+ FbBits *dst;
+ FbStride dstStride;
+ int dstBpp;
+ int dstXoff, dstYoff;
+
+ fbGetDrawable (pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
+ fbGetDrawable (pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+
+ while (nbox--)
+ {
+ if (dstBpp == 1)
+ {
+ fbBlt (src + (pbox->y1 + dy + srcYoff) * srcStride,
+ srcStride,
+ (pbox->x1 + dx + srcXoff) * srcBpp,
+
+ dst + (pbox->y1 + dstYoff) * dstStride,
+ dstStride,
+ (pbox->x1 + dstXoff) * dstBpp,
+
+ (pbox->x2 - pbox->x1) * dstBpp,
+ (pbox->y2 - pbox->y1),
+
+ FbOpaqueStipple1Rop(pGC->alu,
+ pGC->fgPixel,pGC->bgPixel),
+ pPriv->pm,
+ dstBpp,
+
+ reverse,
+ upsidedown);
+ }
+ else
+ {
+ fbBltOne ((FbStip *) (src + (pbox->y1 + dy + srcYoff) * srcStride),
+ srcStride*(FB_UNIT/FB_STIP_UNIT),
+ (pbox->x1 + dx + srcXoff),
+
+ dst + (pbox->y1 + dstYoff) * dstStride,
+ dstStride,
+ (pbox->x1 + dstXoff) * dstBpp,
+ dstBpp,
+
+ (pbox->x2 - pbox->x1) * dstBpp,
+ (pbox->y2 - pbox->y1),
+
+ pPriv->and, pPriv->xor,
+ pPriv->bgand, pPriv->bgxor);
+ }
+ pbox++;
+ }
+
+ fbFinishAccess (pDstDrawable);
+ fbFinishAccess (pSrcDrawable);
+}
+
+void
+fbCopyNto1 (DrawablePtr pSrcDrawable,
+ DrawablePtr pDstDrawable,
+ GCPtr pGC,
+ BoxPtr pbox,
+ int nbox,
+ int dx,
+ int dy,
+ Bool reverse,
+ Bool upsidedown,
+ Pixel bitplane,
+ void *closure)
+{
+ FbGCPrivPtr pPriv = fbGetGCPrivate (pGC);
+
+ while (nbox--)
+ {
+ if (pDstDrawable->bitsPerPixel == 1)
+ {
+ FbBits *src;
+ FbStride srcStride;
+ int srcBpp;
+ int srcXoff, srcYoff;
+
+ FbStip *dst;
+ FbStride dstStride;
+ int dstBpp;
+ int dstXoff, dstYoff;
+
+ fbGetDrawable (pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
+ fbGetStipDrawable (pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+ fbBltPlane (src + (pbox->y1+ dy + srcYoff) * srcStride,
+ srcStride,
+ (pbox->x1 + dx + srcXoff) * srcBpp,
+ srcBpp,
+
+ dst + (pbox->y1 + dstYoff) * dstStride,
+ dstStride,
+ (pbox->x1 + dstXoff) * dstBpp,
+
+ (pbox->x2 - pbox->x1) * srcBpp,
+ (pbox->y2 - pbox->y1),
+
+ (FbStip) pPriv->and, (FbStip) pPriv->xor,
+ (FbStip) pPriv->bgand, (FbStip) pPriv->bgxor,
+ bitplane);
+ fbFinishAccess (pDstDrawable);
+ fbFinishAccess (pSrcDrawable);
+ }
+ else
+ {
+ FbBits *src;
+ FbStride srcStride;
+ int srcBpp;
+ int srcXoff, srcYoff;
+
+ FbBits *dst;
+ FbStride dstStride;
+ int dstBpp;
+ int dstXoff, dstYoff;
+
+ FbStip *tmp;
+ FbStride tmpStride;
+ int width, height;
+
+ width = pbox->x2 - pbox->x1;
+ height = pbox->y2 - pbox->y1;
+
+ tmpStride = ((width + FB_STIP_MASK) >> FB_STIP_SHIFT);
+ tmp = malloc(tmpStride * height * sizeof (FbStip));
+ if (!tmp)
+ return;
+
+ fbGetDrawable (pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
+ fbGetDrawable (pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+
+ fbBltPlane (src + (pbox->y1+ dy + srcYoff) * srcStride,
+ srcStride,
+ (pbox->x1 + dx + srcXoff) * srcBpp,
+ srcBpp,
+
+ tmp,
+ tmpStride,
+ 0,
+
+ width * srcBpp,
+ height,
+
+ fbAndStip(GXcopy,FB_ALLONES,FB_ALLONES),
+ fbXorStip(GXcopy,FB_ALLONES,FB_ALLONES),
+ fbAndStip(GXcopy,0,FB_ALLONES),
+ fbXorStip(GXcopy,0,FB_ALLONES),
+ bitplane);
+ fbBltOne (tmp,
+ tmpStride,
+ 0,
+
+ dst + (pbox->y1 + dstYoff) * dstStride,
+ dstStride,
+ (pbox->x1 + dstXoff) * dstBpp,
+ dstBpp,
+
+ width * dstBpp,
+ height,
+
+ pPriv->and, pPriv->xor,
+ pPriv->bgand, pPriv->bgxor);
+ free(tmp);
+
+ fbFinishAccess (pDstDrawable);
+ fbFinishAccess (pSrcDrawable);
+ }
+ pbox++;
+ }
+}
+
+RegionPtr
+fbCopyArea (DrawablePtr pSrcDrawable,
+ DrawablePtr pDstDrawable,
+ GCPtr pGC,
+ int xIn,
+ int yIn,
+ int widthSrc,
+ int heightSrc,
+ int xOut,
+ int yOut)
+{
+ miCopyProc copy;
+
+#ifdef FB_24_32BIT
+ if (pSrcDrawable->bitsPerPixel != pDstDrawable->bitsPerPixel)
+ copy = fb24_32CopyMtoN;
+ else
+#endif
+ copy = fbCopyNtoN;
+ return miDoCopy (pSrcDrawable, pDstDrawable, pGC, xIn, yIn,
+ widthSrc, heightSrc, xOut, yOut, copy, 0, 0);
+}
+
+RegionPtr
+fbCopyPlane (DrawablePtr pSrcDrawable,
+ DrawablePtr pDstDrawable,
+ GCPtr pGC,
+ int xIn,
+ int yIn,
+ int widthSrc,
+ int heightSrc,
+ int xOut,
+ int yOut,
+ unsigned long bitplane)
+{
+ if (pSrcDrawable->bitsPerPixel > 1)
+ return miDoCopy (pSrcDrawable, pDstDrawable, pGC,
+ xIn, yIn, widthSrc, heightSrc,
+ xOut, yOut, fbCopyNto1, (Pixel) bitplane, 0);
+ else if (bitplane & 1)
+ return miDoCopy (pSrcDrawable, pDstDrawable, pGC, xIn, yIn,
+ widthSrc, heightSrc, xOut, yOut, fbCopy1toN,
+ (Pixel) bitplane, 0);
+ else
+ return miHandleExposures(pSrcDrawable, pDstDrawable, pGC,
+ xIn, yIn,
+ widthSrc,
+ heightSrc,
+ xOut, yOut, bitplane);
+}
diff --git a/xorg-server/fb/fboverlay.c b/xorg-server/fb/fboverlay.c index 99939e8bf..f14187cba 100644 --- a/xorg-server/fb/fboverlay.c +++ b/xorg-server/fb/fboverlay.c @@ -1,437 +1,437 @@ -/* - * - * Copyright © 2000 SuSE, Inc. - * - * 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 SuSE not be used in advertising or - * publicity pertaining to distribution of the software without specific, - * written prior permission. SuSE makes no representations about the - * suitability of this software for any purpose. It is provided "as is" - * without express or implied warranty. - * - * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE - * 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. - * - * Author: Keith Packard, SuSE, Inc. - */ - - -#ifdef HAVE_DIX_CONFIG_H -#include <dix-config.h> -#endif - -#include <stdlib.h> - -#include "fb.h" -#include "fboverlay.h" -#include "shmint.h" - -static int fbOverlayScreenPrivateKeyIndex; -static DevPrivateKey fbOverlayScreenPrivateKey = &fbOverlayScreenPrivateKeyIndex; - -DevPrivateKey fbOverlayGetScreenPrivateKey(void) -{ - return fbOverlayScreenPrivateKey; -} - -/* - * Replace this if you want something supporting - * multiple overlays with the same depth - */ -Bool -fbOverlayCreateWindow(WindowPtr pWin) -{ - FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pWin->drawable.pScreen); - int i; - PixmapPtr pPixmap; - - if (pWin->drawable.class != InputOutput) - return TRUE; - -#ifdef FB_SCREEN_PRIVATE - if (pWin->drawable.bitsPerPixel == 32) - pWin->drawable.bitsPerPixel = fbGetScreenPrivate(pWin->drawable.pScreen)->win32bpp; -#endif - - for (i = 0; i < pScrPriv->nlayers; i++) - { - pPixmap = pScrPriv->layer[i].u.run.pixmap; - if (pWin->drawable.depth == pPixmap->drawable.depth) - { - dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(), pPixmap); - /* - * Make sure layer keys are written correctly by - * having non-root layers set to full while the - * root layer is set to empty. This will cause - * all of the layers to get painted when the root - * is mapped - */ - if (!pWin->parent) - { - REGION_EMPTY (pWin->drawable.pScreen, - &pScrPriv->layer[i].u.run.region); - } - return TRUE; - } - } - return FALSE; -} - -Bool -fbOverlayCloseScreen (int iScreen, ScreenPtr pScreen) -{ - FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pScreen); - int i; - - for (i = 0; i < pScrPriv->nlayers; i++) - { - (*pScreen->DestroyPixmap)(pScrPriv->layer[i].u.run.pixmap); - REGION_UNINIT (pScreen, &pScrPriv->layer[i].u.run.region); - } - return TRUE; -} - -/* - * Return layer containing this window - */ -int -fbOverlayWindowLayer(WindowPtr pWin) -{ - FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pWin->drawable.pScreen); - int i; - - for (i = 0; i < pScrPriv->nlayers; i++) - if (dixLookupPrivate(&pWin->devPrivates, fbGetWinPrivateKey()) == - (pointer) pScrPriv->layer[i].u.run.pixmap) - return i; - return 0; -} - -Bool -fbOverlayCreateScreenResources(ScreenPtr pScreen) -{ - int i; - FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pScreen); - PixmapPtr pPixmap; - pointer pbits; - int width; - int depth; - BoxRec box; - - if (!miCreateScreenResources(pScreen)) - return FALSE; - - box.x1 = 0; - box.y1 = 0; - box.x2 = pScreen->width; - box.y2 = pScreen->height; - for (i = 0; i < pScrPriv->nlayers; i++) - { - pbits = pScrPriv->layer[i].u.init.pbits; - width = pScrPriv->layer[i].u.init.width; - depth = pScrPriv->layer[i].u.init.depth; - pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth, 0); - if (!pPixmap) - return FALSE; - if (!(*pScreen->ModifyPixmapHeader)(pPixmap, pScreen->width, - pScreen->height, depth, - BitsPerPixel(depth), - PixmapBytePad(width, depth), - pbits)) - return FALSE; - pScrPriv->layer[i].u.run.pixmap = pPixmap; - REGION_INIT(pScreen, &pScrPriv->layer[i].u.run.region, &box, 0); - } - pScreen->devPrivate = pScrPriv->layer[0].u.run.pixmap; - return TRUE; -} - -void -fbOverlayPaintKey (DrawablePtr pDrawable, - RegionPtr pRegion, - CARD32 pixel, - int layer) -{ - fbFillRegionSolid (pDrawable, pRegion, 0, - fbReplicatePixel (pixel, pDrawable->bitsPerPixel)); -} - -/* - * Track visible region for each layer - */ -void -fbOverlayUpdateLayerRegion (ScreenPtr pScreen, - int layer, - RegionPtr prgn) -{ - FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pScreen); - int i; - RegionRec rgnNew; - - if (!prgn || !REGION_NOTEMPTY(pScreen, prgn)) - return; - for (i = 0; i < pScrPriv->nlayers; i++) - { - if (i == layer) - { - /* add new piece to this fb */ - REGION_UNION (pScreen, - &pScrPriv->layer[i].u.run.region, - &pScrPriv->layer[i].u.run.region, - prgn); - } - else if (REGION_NOTEMPTY (pScreen, - &pScrPriv->layer[i].u.run.region)) - { - /* paint new piece with chroma key */ - REGION_NULL (pScreen, &rgnNew); - REGION_INTERSECT (pScreen, - &rgnNew, - prgn, - &pScrPriv->layer[i].u.run.region); - (*pScrPriv->PaintKey) (&pScrPriv->layer[i].u.run.pixmap->drawable, - &rgnNew, - pScrPriv->layer[i].key, - i); - REGION_UNINIT(pScreen, &rgnNew); - /* remove piece from other fbs */ - REGION_SUBTRACT (pScreen, - &pScrPriv->layer[i].u.run.region, - &pScrPriv->layer[i].u.run.region, - prgn); - } - } -} - -/* - * Copy only areas in each layer containing real bits - */ -void -fbOverlayCopyWindow(WindowPtr pWin, - DDXPointRec ptOldOrg, - RegionPtr prgnSrc) -{ - ScreenPtr pScreen = pWin->drawable.pScreen; - FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pWin->drawable.pScreen); - RegionRec rgnDst; - int dx, dy; - int i; - RegionRec layerRgn[FB_OVERLAY_MAX]; - PixmapPtr pPixmap; - - dx = ptOldOrg.x - pWin->drawable.x; - dy = ptOldOrg.y - pWin->drawable.y; - - /* - * Clip to existing bits - */ - REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy); - REGION_NULL (pScreen, &rgnDst); - REGION_INTERSECT(pScreen, &rgnDst, &pWin->borderClip, prgnSrc); - REGION_TRANSLATE(pScreen, &rgnDst, dx, dy); - /* - * Compute the portion of each fb affected by this copy - */ - for (i = 0; i < pScrPriv->nlayers; i++) - { - REGION_NULL (pScreen, &layerRgn[i]); - REGION_INTERSECT(pScreen, &layerRgn[i], &rgnDst, - &pScrPriv->layer[i].u.run.region); - if (REGION_NOTEMPTY (pScreen, &layerRgn[i])) - { - REGION_TRANSLATE(pScreen, &layerRgn[i], -dx, -dy); - pPixmap = pScrPriv->layer[i].u.run.pixmap; - miCopyRegion (&pPixmap->drawable, &pPixmap->drawable, - 0, - &layerRgn[i], dx, dy, pScrPriv->CopyWindow, 0, - (void *)(long) i); - } - } - /* - * Update regions - */ - for (i = 0; i < pScrPriv->nlayers; i++) - { - if (REGION_NOTEMPTY (pScreen, &layerRgn[i])) - fbOverlayUpdateLayerRegion (pScreen, i, &layerRgn[i]); - - REGION_UNINIT(pScreen, &layerRgn[i]); - } - REGION_UNINIT(pScreen, &rgnDst); -} - -void -fbOverlayWindowExposures (WindowPtr pWin, - RegionPtr prgn, - RegionPtr other_exposed) -{ - fbOverlayUpdateLayerRegion (pWin->drawable.pScreen, - fbOverlayWindowLayer (pWin), - prgn); - miWindowExposures(pWin, prgn, other_exposed); -} - -Bool -fbOverlaySetupScreen(ScreenPtr pScreen, - pointer pbits1, - pointer pbits2, - int xsize, - int ysize, - int dpix, - int dpiy, - int width1, - int width2, - int bpp1, - int bpp2) -{ - return fbSetupScreen (pScreen, - pbits1, - xsize, - ysize, - dpix, - dpiy, - width1, - bpp1); -} - -static Bool -fb24_32OverlayCreateScreenResources(ScreenPtr pScreen) -{ - FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pScreen); - int pitch; - Bool retval; - int i; - - if((retval = fbOverlayCreateScreenResources(pScreen))) { - for (i = 0; i < pScrPriv->nlayers; i++) - { - /* fix the screen pixmap */ - PixmapPtr pPix = (PixmapPtr) pScrPriv->layer[i].u.run.pixmap; - if (pPix->drawable.bitsPerPixel == 32) { - pPix->drawable.bitsPerPixel = 24; - pitch = BitmapBytePad(pPix->drawable.width * 24); - pPix->devKind = pitch; - } - } - } - - return retval; -} - -Bool -fbOverlayFinishScreenInit(ScreenPtr pScreen, - pointer pbits1, - pointer pbits2, - int xsize, - int ysize, - int dpix, - int dpiy, - int width1, - int width2, - int bpp1, - int bpp2, - int depth1, - int depth2) -{ - VisualPtr visuals; - DepthPtr depths; - int nvisuals; - int ndepths; - int bpp = 0, imagebpp = 32; - VisualID defaultVisual; - FbOverlayScrPrivPtr pScrPriv; - - pScrPriv = xalloc (sizeof (FbOverlayScrPrivRec)); - if (!pScrPriv) - return FALSE; - -#ifdef FB_24_32BIT - if (bpp1 == 32 || bpp2 == 32) - bpp = 32; - else if (bpp1 == 24 || bpp2 == 24) - bpp = 24; - - if (bpp == 24) - { - int f; - - imagebpp = 32; - /* - * Check to see if we're advertising a 24bpp image format, - * in which case windows will use it in preference to a 32 bit - * format. - */ - for (f = 0; f < screenInfo.numPixmapFormats; f++) - { - if (screenInfo.formats[f].bitsPerPixel == 24) - { - imagebpp = 24; - break; - } - } - } -#endif -#ifdef FB_SCREEN_PRIVATE - if (imagebpp == 32) - { - fbGetScreenPrivate(pScreen)->win32bpp = bpp; - fbGetScreenPrivate(pScreen)->pix32bpp = bpp; - } - else - { - fbGetScreenPrivate(pScreen)->win32bpp = 32; - fbGetScreenPrivate(pScreen)->pix32bpp = 32; - } -#endif - - if (!fbInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &depth1, - &defaultVisual, ((unsigned long)1<<(bpp1-1)) | - ((unsigned long)1<<(bpp2-1)), 8)) - return FALSE; - if (! miScreenInit(pScreen, 0, xsize, ysize, dpix, dpiy, 0, - depth1, ndepths, depths, - defaultVisual, nvisuals, visuals)) - return FALSE; - /* MI thinks there's no frame buffer */ -#ifdef MITSHM - ShmRegisterFbFuncs(pScreen); -#endif - pScreen->minInstalledCmaps = 1; - pScreen->maxInstalledCmaps = 2; - - pScrPriv->nlayers = 2; - pScrPriv->PaintKey = fbOverlayPaintKey; - pScrPriv->CopyWindow = fbCopyWindowProc; - pScrPriv->layer[0].u.init.pbits = pbits1; - pScrPriv->layer[0].u.init.width = width1; - pScrPriv->layer[0].u.init.depth = depth1; - - pScrPriv->layer[1].u.init.pbits = pbits2; - pScrPriv->layer[1].u.init.width = width2; - pScrPriv->layer[1].u.init.depth = depth2; - - dixSetPrivate(&pScreen->devPrivates, fbOverlayScreenPrivateKey, pScrPriv); - - /* overwrite miCloseScreen with our own */ - pScreen->CloseScreen = fbOverlayCloseScreen; - pScreen->CreateScreenResources = fbOverlayCreateScreenResources; - pScreen->CreateWindow = fbOverlayCreateWindow; - pScreen->WindowExposures = fbOverlayWindowExposures; - pScreen->CopyWindow = fbOverlayCopyWindow; -#ifdef FB_24_32BIT - if (bpp == 24 && imagebpp == 32) - { - pScreen->ModifyPixmapHeader = fb24_32ModifyPixmapHeader; - pScreen->CreateScreenResources = fb24_32OverlayCreateScreenResources; - } -#endif - - return TRUE; -} +/*
+ *
+ * Copyright © 2000 SuSE, Inc.
+ *
+ * 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 SuSE not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. SuSE makes no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * SuSE DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL SuSE
+ * 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.
+ *
+ * Author: Keith Packard, SuSE, Inc.
+ */
+
+
+#ifdef HAVE_DIX_CONFIG_H
+#include <dix-config.h>
+#endif
+
+#include <stdlib.h>
+
+#include "fb.h"
+#include "fboverlay.h"
+#include "shmint.h"
+
+static int fbOverlayScreenPrivateKeyIndex;
+static DevPrivateKey fbOverlayScreenPrivateKey = &fbOverlayScreenPrivateKeyIndex;
+
+DevPrivateKey fbOverlayGetScreenPrivateKey(void)
+{
+ return fbOverlayScreenPrivateKey;
+}
+
+/*
+ * Replace this if you want something supporting
+ * multiple overlays with the same depth
+ */
+Bool
+fbOverlayCreateWindow(WindowPtr pWin)
+{
+ FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pWin->drawable.pScreen);
+ int i;
+ PixmapPtr pPixmap;
+
+ if (pWin->drawable.class != InputOutput)
+ return TRUE;
+
+#ifdef FB_SCREEN_PRIVATE
+ if (pWin->drawable.bitsPerPixel == 32)
+ pWin->drawable.bitsPerPixel = fbGetScreenPrivate(pWin->drawable.pScreen)->win32bpp;
+#endif
+
+ for (i = 0; i < pScrPriv->nlayers; i++)
+ {
+ pPixmap = pScrPriv->layer[i].u.run.pixmap;
+ if (pWin->drawable.depth == pPixmap->drawable.depth)
+ {
+ dixSetPrivate(&pWin->devPrivates, fbGetWinPrivateKey(), pPixmap);
+ /*
+ * Make sure layer keys are written correctly by
+ * having non-root layers set to full while the
+ * root layer is set to empty. This will cause
+ * all of the layers to get painted when the root
+ * is mapped
+ */
+ if (!pWin->parent)
+ {
+ REGION_EMPTY (pWin->drawable.pScreen,
+ &pScrPriv->layer[i].u.run.region);
+ }
+ return TRUE;
+ }
+ }
+ return FALSE;
+}
+
+Bool
+fbOverlayCloseScreen (int iScreen, ScreenPtr pScreen)
+{
+ FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pScreen);
+ int i;
+
+ for (i = 0; i < pScrPriv->nlayers; i++)
+ {
+ (*pScreen->DestroyPixmap)(pScrPriv->layer[i].u.run.pixmap);
+ REGION_UNINIT (pScreen, &pScrPriv->layer[i].u.run.region);
+ }
+ return TRUE;
+}
+
+/*
+ * Return layer containing this window
+ */
+int
+fbOverlayWindowLayer(WindowPtr pWin)
+{
+ FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pWin->drawable.pScreen);
+ int i;
+
+ for (i = 0; i < pScrPriv->nlayers; i++)
+ if (dixLookupPrivate(&pWin->devPrivates, fbGetWinPrivateKey()) ==
+ (pointer) pScrPriv->layer[i].u.run.pixmap)
+ return i;
+ return 0;
+}
+
+Bool
+fbOverlayCreateScreenResources(ScreenPtr pScreen)
+{
+ int i;
+ FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pScreen);
+ PixmapPtr pPixmap;
+ pointer pbits;
+ int width;
+ int depth;
+ BoxRec box;
+
+ if (!miCreateScreenResources(pScreen))
+ return FALSE;
+
+ box.x1 = 0;
+ box.y1 = 0;
+ box.x2 = pScreen->width;
+ box.y2 = pScreen->height;
+ for (i = 0; i < pScrPriv->nlayers; i++)
+ {
+ pbits = pScrPriv->layer[i].u.init.pbits;
+ width = pScrPriv->layer[i].u.init.width;
+ depth = pScrPriv->layer[i].u.init.depth;
+ pPixmap = (*pScreen->CreatePixmap)(pScreen, 0, 0, depth, 0);
+ if (!pPixmap)
+ return FALSE;
+ if (!(*pScreen->ModifyPixmapHeader)(pPixmap, pScreen->width,
+ pScreen->height, depth,
+ BitsPerPixel(depth),
+ PixmapBytePad(width, depth),
+ pbits))
+ return FALSE;
+ pScrPriv->layer[i].u.run.pixmap = pPixmap;
+ REGION_INIT(pScreen, &pScrPriv->layer[i].u.run.region, &box, 0);
+ }
+ pScreen->devPrivate = pScrPriv->layer[0].u.run.pixmap;
+ return TRUE;
+}
+
+void
+fbOverlayPaintKey (DrawablePtr pDrawable,
+ RegionPtr pRegion,
+ CARD32 pixel,
+ int layer)
+{
+ fbFillRegionSolid (pDrawable, pRegion, 0,
+ fbReplicatePixel (pixel, pDrawable->bitsPerPixel));
+}
+
+/*
+ * Track visible region for each layer
+ */
+void
+fbOverlayUpdateLayerRegion (ScreenPtr pScreen,
+ int layer,
+ RegionPtr prgn)
+{
+ FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pScreen);
+ int i;
+ RegionRec rgnNew;
+
+ if (!prgn || !REGION_NOTEMPTY(pScreen, prgn))
+ return;
+ for (i = 0; i < pScrPriv->nlayers; i++)
+ {
+ if (i == layer)
+ {
+ /* add new piece to this fb */
+ REGION_UNION (pScreen,
+ &pScrPriv->layer[i].u.run.region,
+ &pScrPriv->layer[i].u.run.region,
+ prgn);
+ }
+ else if (REGION_NOTEMPTY (pScreen,
+ &pScrPriv->layer[i].u.run.region))
+ {
+ /* paint new piece with chroma key */
+ REGION_NULL (pScreen, &rgnNew);
+ REGION_INTERSECT (pScreen,
+ &rgnNew,
+ prgn,
+ &pScrPriv->layer[i].u.run.region);
+ (*pScrPriv->PaintKey) (&pScrPriv->layer[i].u.run.pixmap->drawable,
+ &rgnNew,
+ pScrPriv->layer[i].key,
+ i);
+ REGION_UNINIT(pScreen, &rgnNew);
+ /* remove piece from other fbs */
+ REGION_SUBTRACT (pScreen,
+ &pScrPriv->layer[i].u.run.region,
+ &pScrPriv->layer[i].u.run.region,
+ prgn);
+ }
+ }
+}
+
+/*
+ * Copy only areas in each layer containing real bits
+ */
+void
+fbOverlayCopyWindow(WindowPtr pWin,
+ DDXPointRec ptOldOrg,
+ RegionPtr prgnSrc)
+{
+ ScreenPtr pScreen = pWin->drawable.pScreen;
+ FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pWin->drawable.pScreen);
+ RegionRec rgnDst;
+ int dx, dy;
+ int i;
+ RegionRec layerRgn[FB_OVERLAY_MAX];
+ PixmapPtr pPixmap;
+
+ dx = ptOldOrg.x - pWin->drawable.x;
+ dy = ptOldOrg.y - pWin->drawable.y;
+
+ /*
+ * Clip to existing bits
+ */
+ REGION_TRANSLATE(pScreen, prgnSrc, -dx, -dy);
+ REGION_NULL (pScreen, &rgnDst);
+ REGION_INTERSECT(pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
+ REGION_TRANSLATE(pScreen, &rgnDst, dx, dy);
+ /*
+ * Compute the portion of each fb affected by this copy
+ */
+ for (i = 0; i < pScrPriv->nlayers; i++)
+ {
+ REGION_NULL (pScreen, &layerRgn[i]);
+ REGION_INTERSECT(pScreen, &layerRgn[i], &rgnDst,
+ &pScrPriv->layer[i].u.run.region);
+ if (REGION_NOTEMPTY (pScreen, &layerRgn[i]))
+ {
+ REGION_TRANSLATE(pScreen, &layerRgn[i], -dx, -dy);
+ pPixmap = pScrPriv->layer[i].u.run.pixmap;
+ miCopyRegion (&pPixmap->drawable, &pPixmap->drawable,
+ 0,
+ &layerRgn[i], dx, dy, pScrPriv->CopyWindow, 0,
+ (void *)(long) i);
+ }
+ }
+ /*
+ * Update regions
+ */
+ for (i = 0; i < pScrPriv->nlayers; i++)
+ {
+ if (REGION_NOTEMPTY (pScreen, &layerRgn[i]))
+ fbOverlayUpdateLayerRegion (pScreen, i, &layerRgn[i]);
+
+ REGION_UNINIT(pScreen, &layerRgn[i]);
+ }
+ REGION_UNINIT(pScreen, &rgnDst);
+}
+
+void
+fbOverlayWindowExposures (WindowPtr pWin,
+ RegionPtr prgn,
+ RegionPtr other_exposed)
+{
+ fbOverlayUpdateLayerRegion (pWin->drawable.pScreen,
+ fbOverlayWindowLayer (pWin),
+ prgn);
+ miWindowExposures(pWin, prgn, other_exposed);
+}
+
+Bool
+fbOverlaySetupScreen(ScreenPtr pScreen,
+ pointer pbits1,
+ pointer pbits2,
+ int xsize,
+ int ysize,
+ int dpix,
+ int dpiy,
+ int width1,
+ int width2,
+ int bpp1,
+ int bpp2)
+{
+ return fbSetupScreen (pScreen,
+ pbits1,
+ xsize,
+ ysize,
+ dpix,
+ dpiy,
+ width1,
+ bpp1);
+}
+
+static Bool
+fb24_32OverlayCreateScreenResources(ScreenPtr pScreen)
+{
+ FbOverlayScrPrivPtr pScrPriv = fbOverlayGetScrPriv(pScreen);
+ int pitch;
+ Bool retval;
+ int i;
+
+ if((retval = fbOverlayCreateScreenResources(pScreen))) {
+ for (i = 0; i < pScrPriv->nlayers; i++)
+ {
+ /* fix the screen pixmap */
+ PixmapPtr pPix = (PixmapPtr) pScrPriv->layer[i].u.run.pixmap;
+ if (pPix->drawable.bitsPerPixel == 32) {
+ pPix->drawable.bitsPerPixel = 24;
+ pitch = BitmapBytePad(pPix->drawable.width * 24);
+ pPix->devKind = pitch;
+ }
+ }
+ }
+
+ return retval;
+}
+
+Bool
+fbOverlayFinishScreenInit(ScreenPtr pScreen,
+ pointer pbits1,
+ pointer pbits2,
+ int xsize,
+ int ysize,
+ int dpix,
+ int dpiy,
+ int width1,
+ int width2,
+ int bpp1,
+ int bpp2,
+ int depth1,
+ int depth2)
+{
+ VisualPtr visuals;
+ DepthPtr depths;
+ int nvisuals;
+ int ndepths;
+ int bpp = 0, imagebpp = 32;
+ VisualID defaultVisual;
+ FbOverlayScrPrivPtr pScrPriv;
+
+ pScrPriv = malloc(sizeof (FbOverlayScrPrivRec));
+ if (!pScrPriv)
+ return FALSE;
+
+#ifdef FB_24_32BIT
+ if (bpp1 == 32 || bpp2 == 32)
+ bpp = 32;
+ else if (bpp1 == 24 || bpp2 == 24)
+ bpp = 24;
+
+ if (bpp == 24)
+ {
+ int f;
+
+ imagebpp = 32;
+ /*
+ * Check to see if we're advertising a 24bpp image format,
+ * in which case windows will use it in preference to a 32 bit
+ * format.
+ */
+ for (f = 0; f < screenInfo.numPixmapFormats; f++)
+ {
+ if (screenInfo.formats[f].bitsPerPixel == 24)
+ {
+ imagebpp = 24;
+ break;
+ }
+ }
+ }
+#endif
+#ifdef FB_SCREEN_PRIVATE
+ if (imagebpp == 32)
+ {
+ fbGetScreenPrivate(pScreen)->win32bpp = bpp;
+ fbGetScreenPrivate(pScreen)->pix32bpp = bpp;
+ }
+ else
+ {
+ fbGetScreenPrivate(pScreen)->win32bpp = 32;
+ fbGetScreenPrivate(pScreen)->pix32bpp = 32;
+ }
+#endif
+
+ if (!fbInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &depth1,
+ &defaultVisual, ((unsigned long)1<<(bpp1-1)) |
+ ((unsigned long)1<<(bpp2-1)), 8))
+ return FALSE;
+ if (! miScreenInit(pScreen, 0, xsize, ysize, dpix, dpiy, 0,
+ depth1, ndepths, depths,
+ defaultVisual, nvisuals, visuals))
+ return FALSE;
+ /* MI thinks there's no frame buffer */
+#ifdef MITSHM
+ ShmRegisterFbFuncs(pScreen);
+#endif
+ pScreen->minInstalledCmaps = 1;
+ pScreen->maxInstalledCmaps = 2;
+
+ pScrPriv->nlayers = 2;
+ pScrPriv->PaintKey = fbOverlayPaintKey;
+ pScrPriv->CopyWindow = fbCopyWindowProc;
+ pScrPriv->layer[0].u.init.pbits = pbits1;
+ pScrPriv->layer[0].u.init.width = width1;
+ pScrPriv->layer[0].u.init.depth = depth1;
+
+ pScrPriv->layer[1].u.init.pbits = pbits2;
+ pScrPriv->layer[1].u.init.width = width2;
+ pScrPriv->layer[1].u.init.depth = depth2;
+
+ dixSetPrivate(&pScreen->devPrivates, fbOverlayScreenPrivateKey, pScrPriv);
+
+ /* overwrite miCloseScreen with our own */
+ pScreen->CloseScreen = fbOverlayCloseScreen;
+ pScreen->CreateScreenResources = fbOverlayCreateScreenResources;
+ pScreen->CreateWindow = fbOverlayCreateWindow;
+ pScreen->WindowExposures = fbOverlayWindowExposures;
+ pScreen->CopyWindow = fbOverlayCopyWindow;
+#ifdef FB_24_32BIT
+ if (bpp == 24 && imagebpp == 32)
+ {
+ pScreen->ModifyPixmapHeader = fb24_32ModifyPixmapHeader;
+ pScreen->CreateScreenResources = fb24_32OverlayCreateScreenResources;
+ }
+#endif
+
+ return TRUE;
+}
diff --git a/xorg-server/fb/fbpixmap.c b/xorg-server/fb/fbpixmap.c index c4c2c4aa7..4714ef22e 100644 --- a/xorg-server/fb/fbpixmap.c +++ b/xorg-server/fb/fbpixmap.c @@ -1,383 +1,383 @@ -/* - * Copyright © 1998 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 <stdlib.h> - -#include "fb.h" - -PixmapPtr -fbCreatePixmapBpp (ScreenPtr pScreen, int width, int height, int depth, int bpp, - unsigned usage_hint) -{ - PixmapPtr pPixmap; - size_t datasize; - size_t paddedWidth; - int adjust; - int base; - - paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (FbBits); - if (paddedWidth / 4 > 32767 || height > 32767) - return NullPixmap; - datasize = height * paddedWidth; - base = pScreen->totalPixmapSize; - adjust = 0; - if (base & 7) - adjust = 8 - (base & 7); - datasize += adjust; -#ifdef FB_DEBUG - datasize += 2 * paddedWidth; -#endif - pPixmap = AllocatePixmap(pScreen, datasize); - if (!pPixmap) - return NullPixmap; - pPixmap->drawable.type = DRAWABLE_PIXMAP; - pPixmap->drawable.class = 0; - pPixmap->drawable.pScreen = pScreen; - pPixmap->drawable.depth = depth; - pPixmap->drawable.bitsPerPixel = bpp; - pPixmap->drawable.id = 0; - pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER; - pPixmap->drawable.x = 0; - pPixmap->drawable.y = 0; - pPixmap->drawable.width = width; - pPixmap->drawable.height = height; - pPixmap->devKind = paddedWidth; - pPixmap->refcnt = 1; - pPixmap->devPrivate.ptr = (pointer) ((char *)pPixmap + base + adjust); -#ifdef FB_DEBUG - pPixmap->devPrivate.ptr = (void *) ((char *) pPixmap->devPrivate.ptr + paddedWidth); - fbInitializeDrawable (&pPixmap->drawable); -#endif - -#ifdef COMPOSITE - pPixmap->screen_x = 0; - pPixmap->screen_y = 0; -#endif - - pPixmap->usage_hint = usage_hint; - - return pPixmap; -} - -PixmapPtr -fbCreatePixmap (ScreenPtr pScreen, int width, int height, int depth, - unsigned usage_hint) -{ - int bpp; - bpp = BitsPerPixel (depth); -#ifdef FB_SCREEN_PRIVATE - if (bpp == 32 && depth <= 24) - bpp = fbGetScreenPrivate(pScreen)->pix32bpp; -#endif - return fbCreatePixmapBpp (pScreen, width, height, depth, bpp, usage_hint); -} - -Bool -fbDestroyPixmap (PixmapPtr pPixmap) -{ - if(--pPixmap->refcnt) - return TRUE; - dixFreePrivates(pPixmap->devPrivates); - xfree(pPixmap); - return TRUE; -} - -#define ADDRECT(reg,r,fr,rx1,ry1,rx2,ry2) \ -if (((rx1) < (rx2)) && ((ry1) < (ry2)) && \ - (!((reg)->data->numRects && \ - ((r-1)->y1 == (ry1)) && \ - ((r-1)->y2 == (ry2)) && \ - ((r-1)->x1 <= (rx1)) && \ - ((r-1)->x2 >= (rx2))))) \ -{ \ - if ((reg)->data->numRects == (reg)->data->size) \ - { \ - miRectAlloc(reg, 1); \ - fr = REGION_BOXPTR(reg); \ - r = fr + (reg)->data->numRects; \ - } \ - r->x1 = (rx1); \ - r->y1 = (ry1); \ - r->x2 = (rx2); \ - r->y2 = (ry2); \ - (reg)->data->numRects++; \ - if(r->x1 < (reg)->extents.x1) \ - (reg)->extents.x1 = r->x1; \ - if(r->x2 > (reg)->extents.x2) \ - (reg)->extents.x2 = r->x2; \ - r++; \ -} - -/* Convert bitmap clip mask into clipping region. - * First, goes through each line and makes boxes by noting the transitions - * from 0 to 1 and 1 to 0. - * Then it coalesces the current line with the previous if they have boxes - * at the same X coordinates. - */ -RegionPtr -fbPixmapToRegion(PixmapPtr pPix) -{ - register RegionPtr pReg; - FbBits *pw, w; - register int ib; - int width, h, base, rx1 = 0, crects; - FbBits *pwLineEnd; - int irectPrevStart, irectLineStart; - register BoxPtr prectO, prectN; - BoxPtr FirstRect, rects, prectLineStart; - Bool fInBox, fSame; - register FbBits mask0 = FB_ALLONES & ~FbScrRight(FB_ALLONES, 1); - FbBits *pwLine; - int nWidth; - - pReg = REGION_CREATE(pPix->drawable.pScreen, NULL, 1); - if(!pReg) - return NullRegion; - FirstRect = REGION_BOXPTR(pReg); - rects = FirstRect; - - fbPrepareAccess(&pPix->drawable); - - pwLine = (FbBits *) pPix->devPrivate.ptr; - nWidth = pPix->devKind >> (FB_SHIFT-3); - - width = pPix->drawable.width; - pReg->extents.x1 = width - 1; - pReg->extents.x2 = 0; - irectPrevStart = -1; - for(h = 0; h < pPix->drawable.height; h++) - { - pw = pwLine; - pwLine += nWidth; - irectLineStart = rects - FirstRect; - /* If the Screen left most bit of the word is set, we're starting in - * a box */ - if(READ(pw) & mask0) - { - fInBox = TRUE; - rx1 = 0; - } - else - fInBox = FALSE; - /* Process all words which are fully in the pixmap */ - pwLineEnd = pw + (width >> FB_SHIFT); - for (base = 0; pw < pwLineEnd; base += FB_UNIT) - { - w = READ(pw++); - if (fInBox) - { - if (!~w) - continue; - } - else - { - if (!w) - continue; - } - for(ib = 0; ib < FB_UNIT; ib++) - { - /* If the Screen left most bit of the word is set, we're - * starting a box */ - if(w & mask0) - { - if(!fInBox) - { - rx1 = base + ib; - /* start new box */ - fInBox = TRUE; - } - } - else - { - if(fInBox) - { - /* end box */ - ADDRECT(pReg, rects, FirstRect, - rx1, h, base + ib, h + 1); - fInBox = FALSE; - } - } - /* Shift the word VISUALLY left one. */ - w = FbScrLeft(w, 1); - } - } - if(width & FB_MASK) - { - /* Process final partial word on line */ - w = READ(pw++); - for(ib = 0; ib < (width & FB_MASK); ib++) - { - /* If the Screen left most bit of the word is set, we're - * starting a box */ - if(w & mask0) - { - if(!fInBox) - { - rx1 = base + ib; - /* start new box */ - fInBox = TRUE; - } - } - else - { - if(fInBox) - { - /* end box */ - ADDRECT(pReg, rects, FirstRect, - rx1, h, base + ib, h + 1); - fInBox = FALSE; - } - } - /* Shift the word VISUALLY left one. */ - w = FbScrLeft(w, 1); - } - } - /* If scanline ended with last bit set, end the box */ - if(fInBox) - { - ADDRECT(pReg, rects, FirstRect, - rx1, h, base + (width & FB_MASK), h + 1); - } - /* if all rectangles on this line have the same x-coords as - * those on the previous line, then add 1 to all the previous y2s and - * throw away all the rectangles from this line - */ - fSame = FALSE; - if(irectPrevStart != -1) - { - crects = irectLineStart - irectPrevStart; - if(crects == ((rects - FirstRect) - irectLineStart)) - { - prectO = FirstRect + irectPrevStart; - prectN = prectLineStart = FirstRect + irectLineStart; - fSame = TRUE; - while(prectO < prectLineStart) - { - if((prectO->x1 != prectN->x1) || (prectO->x2 != prectN->x2)) - { - fSame = FALSE; - break; - } - prectO++; - prectN++; - } - if (fSame) - { - prectO = FirstRect + irectPrevStart; - while(prectO < prectLineStart) - { - prectO->y2 += 1; - prectO++; - } - rects -= crects; - pReg->data->numRects -= crects; - } - } - } - if(!fSame) - irectPrevStart = irectLineStart; - } - if (!pReg->data->numRects) - pReg->extents.x1 = pReg->extents.x2 = 0; - else - { - pReg->extents.y1 = REGION_BOXPTR(pReg)->y1; - pReg->extents.y2 = REGION_END(pReg)->y2; - if (pReg->data->numRects == 1) - { - xfree(pReg->data); - pReg->data = (RegDataPtr)NULL; - } - } - - fbFinishAccess(&pPix->drawable); -#ifdef DEBUG - if (!miValidRegion(pReg)) - FatalError("Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__); -#endif - return(pReg); -} - -#ifdef FB_DEBUG - -#include <stdio.h> - -static Bool -fbValidateBits (FbStip *bits, int stride, FbStip data) -{ - while (stride--) - { - if (*bits != data) - { - fprintf (stderr, "fbValidateBits failed at 0x%x (is 0x%x want 0x%x)\n",bits, *bits, data); - return FALSE; - } - bits++; - } -} - -void -fbValidateDrawable (DrawablePtr pDrawable) -{ - FbStip *bits, *first, *last; - int stride, bpp; - int xoff, yoff; - int height; - Bool failed; - - if (pDrawable->type != DRAWABLE_PIXMAP) - pDrawable = (DrawablePtr) fbGetWindowPixmap(pDrawable); - fbGetStipDrawable(pDrawable, bits, stride, bpp, xoff, yoff); - first = bits - stride; - last = bits + stride * pDrawable->height; - if (!fbValidateBits (first, stride, FB_HEAD_BITS) || - !fbValidateBits (last, stride, FB_TAIL_BITS)) - fbInitializeDrawable(pDrawable); - fbFinishAccess (pDrawable); -} - -void -fbSetBits (FbStip *bits, int stride, FbStip data) -{ - while (stride--) - *bits++ = data; -} - -void -fbInitializeDrawable (DrawablePtr pDrawable) -{ - FbStip *bits, *first, *last; - int stride, bpp; - int xoff, yoff; - - fbGetStipDrawable(pDrawable, bits, stride, bpp, xoff, yoff); - first = bits - stride; - last = bits + stride * pDrawable->height; - fbSetBits (first, stride, FB_HEAD_BITS); - fbSetBits (last, stride, FB_TAIL_BITS); - fbFinishAccess (pDrawable); -} -#endif /* FB_DEBUG */ +/*
+ * Copyright © 1998 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 <stdlib.h>
+
+#include "fb.h"
+
+PixmapPtr
+fbCreatePixmapBpp (ScreenPtr pScreen, int width, int height, int depth, int bpp,
+ unsigned usage_hint)
+{
+ PixmapPtr pPixmap;
+ size_t datasize;
+ size_t paddedWidth;
+ int adjust;
+ int base;
+
+ paddedWidth = ((width * bpp + FB_MASK) >> FB_SHIFT) * sizeof (FbBits);
+ if (paddedWidth / 4 > 32767 || height > 32767)
+ return NullPixmap;
+ datasize = height * paddedWidth;
+ base = pScreen->totalPixmapSize;
+ adjust = 0;
+ if (base & 7)
+ adjust = 8 - (base & 7);
+ datasize += adjust;
+#ifdef FB_DEBUG
+ datasize += 2 * paddedWidth;
+#endif
+ pPixmap = AllocatePixmap(pScreen, datasize);
+ if (!pPixmap)
+ return NullPixmap;
+ pPixmap->drawable.type = DRAWABLE_PIXMAP;
+ pPixmap->drawable.class = 0;
+ pPixmap->drawable.pScreen = pScreen;
+ pPixmap->drawable.depth = depth;
+ pPixmap->drawable.bitsPerPixel = bpp;
+ pPixmap->drawable.id = 0;
+ pPixmap->drawable.serialNumber = NEXT_SERIAL_NUMBER;
+ pPixmap->drawable.x = 0;
+ pPixmap->drawable.y = 0;
+ pPixmap->drawable.width = width;
+ pPixmap->drawable.height = height;
+ pPixmap->devKind = paddedWidth;
+ pPixmap->refcnt = 1;
+ pPixmap->devPrivate.ptr = (pointer) ((char *)pPixmap + base + adjust);
+#ifdef FB_DEBUG
+ pPixmap->devPrivate.ptr = (void *) ((char *) pPixmap->devPrivate.ptr + paddedWidth);
+ fbInitializeDrawable (&pPixmap->drawable);
+#endif
+
+#ifdef COMPOSITE
+ pPixmap->screen_x = 0;
+ pPixmap->screen_y = 0;
+#endif
+
+ pPixmap->usage_hint = usage_hint;
+
+ return pPixmap;
+}
+
+PixmapPtr
+fbCreatePixmap (ScreenPtr pScreen, int width, int height, int depth,
+ unsigned usage_hint)
+{
+ int bpp;
+ bpp = BitsPerPixel (depth);
+#ifdef FB_SCREEN_PRIVATE
+ if (bpp == 32 && depth <= 24)
+ bpp = fbGetScreenPrivate(pScreen)->pix32bpp;
+#endif
+ return fbCreatePixmapBpp (pScreen, width, height, depth, bpp, usage_hint);
+}
+
+Bool
+fbDestroyPixmap (PixmapPtr pPixmap)
+{
+ if(--pPixmap->refcnt)
+ return TRUE;
+ dixFreePrivates(pPixmap->devPrivates);
+ free(pPixmap);
+ return TRUE;
+}
+
+#define ADDRECT(reg,r,fr,rx1,ry1,rx2,ry2) \
+if (((rx1) < (rx2)) && ((ry1) < (ry2)) && \
+ (!((reg)->data->numRects && \
+ ((r-1)->y1 == (ry1)) && \
+ ((r-1)->y2 == (ry2)) && \
+ ((r-1)->x1 <= (rx1)) && \
+ ((r-1)->x2 >= (rx2))))) \
+{ \
+ if ((reg)->data->numRects == (reg)->data->size) \
+ { \
+ miRectAlloc(reg, 1); \
+ fr = REGION_BOXPTR(reg); \
+ r = fr + (reg)->data->numRects; \
+ } \
+ r->x1 = (rx1); \
+ r->y1 = (ry1); \
+ r->x2 = (rx2); \
+ r->y2 = (ry2); \
+ (reg)->data->numRects++; \
+ if(r->x1 < (reg)->extents.x1) \
+ (reg)->extents.x1 = r->x1; \
+ if(r->x2 > (reg)->extents.x2) \
+ (reg)->extents.x2 = r->x2; \
+ r++; \
+}
+
+/* Convert bitmap clip mask into clipping region.
+ * First, goes through each line and makes boxes by noting the transitions
+ * from 0 to 1 and 1 to 0.
+ * Then it coalesces the current line with the previous if they have boxes
+ * at the same X coordinates.
+ */
+RegionPtr
+fbPixmapToRegion(PixmapPtr pPix)
+{
+ register RegionPtr pReg;
+ FbBits *pw, w;
+ register int ib;
+ int width, h, base, rx1 = 0, crects;
+ FbBits *pwLineEnd;
+ int irectPrevStart, irectLineStart;
+ register BoxPtr prectO, prectN;
+ BoxPtr FirstRect, rects, prectLineStart;
+ Bool fInBox, fSame;
+ register FbBits mask0 = FB_ALLONES & ~FbScrRight(FB_ALLONES, 1);
+ FbBits *pwLine;
+ int nWidth;
+
+ pReg = REGION_CREATE(pPix->drawable.pScreen, NULL, 1);
+ if(!pReg)
+ return NullRegion;
+ FirstRect = REGION_BOXPTR(pReg);
+ rects = FirstRect;
+
+ fbPrepareAccess(&pPix->drawable);
+
+ pwLine = (FbBits *) pPix->devPrivate.ptr;
+ nWidth = pPix->devKind >> (FB_SHIFT-3);
+
+ width = pPix->drawable.width;
+ pReg->extents.x1 = width - 1;
+ pReg->extents.x2 = 0;
+ irectPrevStart = -1;
+ for(h = 0; h < pPix->drawable.height; h++)
+ {
+ pw = pwLine;
+ pwLine += nWidth;
+ irectLineStart = rects - FirstRect;
+ /* If the Screen left most bit of the word is set, we're starting in
+ * a box */
+ if(READ(pw) & mask0)
+ {
+ fInBox = TRUE;
+ rx1 = 0;
+ }
+ else
+ fInBox = FALSE;
+ /* Process all words which are fully in the pixmap */
+ pwLineEnd = pw + (width >> FB_SHIFT);
+ for (base = 0; pw < pwLineEnd; base += FB_UNIT)
+ {
+ w = READ(pw++);
+ if (fInBox)
+ {
+ if (!~w)
+ continue;
+ }
+ else
+ {
+ if (!w)
+ continue;
+ }
+ for(ib = 0; ib < FB_UNIT; ib++)
+ {
+ /* If the Screen left most bit of the word is set, we're
+ * starting a box */
+ if(w & mask0)
+ {
+ if(!fInBox)
+ {
+ rx1 = base + ib;
+ /* start new box */
+ fInBox = TRUE;
+ }
+ }
+ else
+ {
+ if(fInBox)
+ {
+ /* end box */
+ ADDRECT(pReg, rects, FirstRect,
+ rx1, h, base + ib, h + 1);
+ fInBox = FALSE;
+ }
+ }
+ /* Shift the word VISUALLY left one. */
+ w = FbScrLeft(w, 1);
+ }
+ }
+ if(width & FB_MASK)
+ {
+ /* Process final partial word on line */
+ w = READ(pw++);
+ for(ib = 0; ib < (width & FB_MASK); ib++)
+ {
+ /* If the Screen left most bit of the word is set, we're
+ * starting a box */
+ if(w & mask0)
+ {
+ if(!fInBox)
+ {
+ rx1 = base + ib;
+ /* start new box */
+ fInBox = TRUE;
+ }
+ }
+ else
+ {
+ if(fInBox)
+ {
+ /* end box */
+ ADDRECT(pReg, rects, FirstRect,
+ rx1, h, base + ib, h + 1);
+ fInBox = FALSE;
+ }
+ }
+ /* Shift the word VISUALLY left one. */
+ w = FbScrLeft(w, 1);
+ }
+ }
+ /* If scanline ended with last bit set, end the box */
+ if(fInBox)
+ {
+ ADDRECT(pReg, rects, FirstRect,
+ rx1, h, base + (width & FB_MASK), h + 1);
+ }
+ /* if all rectangles on this line have the same x-coords as
+ * those on the previous line, then add 1 to all the previous y2s and
+ * throw away all the rectangles from this line
+ */
+ fSame = FALSE;
+ if(irectPrevStart != -1)
+ {
+ crects = irectLineStart - irectPrevStart;
+ if(crects == ((rects - FirstRect) - irectLineStart))
+ {
+ prectO = FirstRect + irectPrevStart;
+ prectN = prectLineStart = FirstRect + irectLineStart;
+ fSame = TRUE;
+ while(prectO < prectLineStart)
+ {
+ if((prectO->x1 != prectN->x1) || (prectO->x2 != prectN->x2))
+ {
+ fSame = FALSE;
+ break;
+ }
+ prectO++;
+ prectN++;
+ }
+ if (fSame)
+ {
+ prectO = FirstRect + irectPrevStart;
+ while(prectO < prectLineStart)
+ {
+ prectO->y2 += 1;
+ prectO++;
+ }
+ rects -= crects;
+ pReg->data->numRects -= crects;
+ }
+ }
+ }
+ if(!fSame)
+ irectPrevStart = irectLineStart;
+ }
+ if (!pReg->data->numRects)
+ pReg->extents.x1 = pReg->extents.x2 = 0;
+ else
+ {
+ pReg->extents.y1 = REGION_BOXPTR(pReg)->y1;
+ pReg->extents.y2 = REGION_END(pReg)->y2;
+ if (pReg->data->numRects == 1)
+ {
+ free(pReg->data);
+ pReg->data = (RegDataPtr)NULL;
+ }
+ }
+
+ fbFinishAccess(&pPix->drawable);
+#ifdef DEBUG
+ if (!miValidRegion(pReg))
+ FatalError("Assertion failed file %s, line %d: expr\n", __FILE__, __LINE__);
+#endif
+ return(pReg);
+}
+
+#ifdef FB_DEBUG
+
+#include <stdio.h>
+
+static Bool
+fbValidateBits (FbStip *bits, int stride, FbStip data)
+{
+ while (stride--)
+ {
+ if (*bits != data)
+ {
+ fprintf (stderr, "fbValidateBits failed at 0x%x (is 0x%x want 0x%x)\n",bits, *bits, data);
+ return FALSE;
+ }
+ bits++;
+ }
+}
+
+void
+fbValidateDrawable (DrawablePtr pDrawable)
+{
+ FbStip *bits, *first, *last;
+ int stride, bpp;
+ int xoff, yoff;
+ int height;
+ Bool failed;
+
+ if (pDrawable->type != DRAWABLE_PIXMAP)
+ pDrawable = (DrawablePtr) fbGetWindowPixmap(pDrawable);
+ fbGetStipDrawable(pDrawable, bits, stride, bpp, xoff, yoff);
+ first = bits - stride;
+ last = bits + stride * pDrawable->height;
+ if (!fbValidateBits (first, stride, FB_HEAD_BITS) ||
+ !fbValidateBits (last, stride, FB_TAIL_BITS))
+ fbInitializeDrawable(pDrawable);
+ fbFinishAccess (pDrawable);
+}
+
+void
+fbSetBits (FbStip *bits, int stride, FbStip data)
+{
+ while (stride--)
+ *bits++ = data;
+}
+
+void
+fbInitializeDrawable (DrawablePtr pDrawable)
+{
+ FbStip *bits, *first, *last;
+ int stride, bpp;
+ int xoff, yoff;
+
+ fbGetStipDrawable(pDrawable, bits, stride, bpp, xoff, yoff);
+ first = bits - stride;
+ last = bits + stride * pDrawable->height;
+ fbSetBits (first, stride, FB_HEAD_BITS);
+ fbSetBits (last, stride, FB_TAIL_BITS);
+ fbFinishAccess (pDrawable);
+}
+#endif /* FB_DEBUG */
diff --git a/xorg-server/fb/fbscreen.c b/xorg-server/fb/fbscreen.c index 53e2ada9f..65af64074 100644 --- a/xorg-server/fb/fbscreen.c +++ b/xorg-server/fb/fbscreen.c @@ -1,291 +1,291 @@ -/* - * Copyright © 1998 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" - -Bool -fbCloseScreen (int index, ScreenPtr pScreen) -{ - int d; - DepthPtr depths = pScreen->allowedDepths; - - for (d = 0; d < pScreen->numDepths; d++) - xfree (depths[d].vids); - xfree (depths); - xfree (pScreen->visuals); - xfree (pScreen->devPrivate); -#ifdef FB_SCREEN_PRIVATE - xfree (dixLookupPrivate(&pScreen->devPrivates, fbGetScreenPrivateKey())); -#endif - return TRUE; -} - -Bool -fbRealizeFont(ScreenPtr pScreen, FontPtr pFont) -{ - return (TRUE); -} - -Bool -fbUnrealizeFont(ScreenPtr pScreen, FontPtr pFont) -{ - return (TRUE); -} - -void -fbQueryBestSize (int class, - unsigned short *width, unsigned short *height, - ScreenPtr pScreen) -{ - unsigned short w; - - switch (class) { - case CursorShape: - if (*width > pScreen->width) - *width = pScreen->width; - if (*height > pScreen->height) - *height = pScreen->height; - break; - case TileShape: - case StippleShape: - w = *width; - if ((w & (w - 1)) && w < FB_UNIT) - { - for (w = 1; w < *width; w <<= 1) - ; - *width = w; - } - } -} - -PixmapPtr -_fbGetWindowPixmap (WindowPtr pWindow) -{ - return fbGetWindowPixmap (pWindow); -} - -void -_fbSetWindowPixmap (WindowPtr pWindow, PixmapPtr pPixmap) -{ - dixSetPrivate(&pWindow->devPrivates, fbGetWinPrivateKey(), pPixmap); -} - -Bool -fbSetupScreen(ScreenPtr pScreen, - pointer pbits, /* pointer to screen bitmap */ - int xsize, /* in pixels */ - int ysize, - int dpix, /* dots per inch */ - int dpiy, - int width, /* pixel width of frame buffer */ - int bpp) /* bits per pixel for screen */ -{ - if (!fbAllocatePrivates(pScreen, NULL)) - return FALSE; - pScreen->defColormap = FakeClientID(0); - /* let CreateDefColormap do whatever it wants for pixels */ - pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0; - pScreen->QueryBestSize = fbQueryBestSize; - /* SaveScreen */ - pScreen->GetImage = fbGetImage; - pScreen->GetSpans = fbGetSpans; - pScreen->CreateWindow = fbCreateWindow; - pScreen->DestroyWindow = fbDestroyWindow; - pScreen->PositionWindow = fbPositionWindow; - pScreen->ChangeWindowAttributes = fbChangeWindowAttributes; - pScreen->RealizeWindow = fbMapWindow; - pScreen->UnrealizeWindow = fbUnmapWindow; - pScreen->CopyWindow = fbCopyWindow; - pScreen->CreatePixmap = fbCreatePixmap; - pScreen->DestroyPixmap = fbDestroyPixmap; - pScreen->RealizeFont = fbRealizeFont; - pScreen->UnrealizeFont = fbUnrealizeFont; - pScreen->CreateGC = fbCreateGC; - pScreen->CreateColormap = fbInitializeColormap; - pScreen->DestroyColormap = (void (*)(ColormapPtr))NoopDDA; - pScreen->InstallColormap = fbInstallColormap; - pScreen->UninstallColormap = fbUninstallColormap; - pScreen->ListInstalledColormaps = fbListInstalledColormaps; - pScreen->StoreColors = (void (*)(ColormapPtr, int, xColorItem *))NoopDDA; - pScreen->ResolveColor = fbResolveColor; - pScreen->BitmapToRegion = fbPixmapToRegion; - - pScreen->GetWindowPixmap = _fbGetWindowPixmap; - pScreen->SetWindowPixmap = _fbSetWindowPixmap; - - return TRUE; -} - -#ifdef FB_ACCESS_WRAPPER -Bool -wfbFinishScreenInit(ScreenPtr pScreen, - pointer pbits, - int xsize, - int ysize, - int dpix, - int dpiy, - int width, - int bpp, - SetupWrapProcPtr setupWrap, - FinishWrapProcPtr finishWrap) -#else -Bool -fbFinishScreenInit(ScreenPtr pScreen, - pointer pbits, - int xsize, - int ysize, - int dpix, - int dpiy, - int width, - int bpp) -#endif -{ - VisualPtr visuals; - DepthPtr depths; - int nvisuals; - int ndepths; - int rootdepth; - VisualID defaultVisual; - int imagebpp = bpp; - -#ifdef FB_DEBUG - int stride; - - ysize -= 2; - stride = (width * bpp) / 8; - fbSetBits ((FbStip *) pbits, - stride / sizeof (FbStip), FB_HEAD_BITS); - pbits = (void *) ((char *) pbits + stride); - fbSetBits ((FbStip *) ((char *) pbits + stride * ysize), - stride / sizeof (FbStip), FB_TAIL_BITS); -#endif - /* - * By default, a 24bpp screen will use 32bpp images, this avoids - * problems with many applications which just can't handle packed - * pixels. If you want real 24bit images, include a 24bpp - * format in the pixmap formats - */ -#ifdef FB_24_32BIT - if (bpp == 24) - { - int f; - - imagebpp = 32; - /* - * Check to see if we're advertising a 24bpp image format, - * in which case windows will use it in preference to a 32 bit - * format. - */ - for (f = 0; f < screenInfo.numPixmapFormats; f++) - { - if (screenInfo.formats[f].bitsPerPixel == 24) - { - imagebpp = 24; - break; - } - } - } -#endif -#ifdef FB_SCREEN_PRIVATE - if (imagebpp == 32) - { - fbGetScreenPrivate(pScreen)->win32bpp = bpp; - fbGetScreenPrivate(pScreen)->pix32bpp = bpp; - } - else - { - fbGetScreenPrivate(pScreen)->win32bpp = 32; - fbGetScreenPrivate(pScreen)->pix32bpp = 32; - } -#ifdef FB_ACCESS_WRAPPER - fbGetScreenPrivate(pScreen)->setupWrap = setupWrap; - fbGetScreenPrivate(pScreen)->finishWrap = finishWrap; -#endif -#endif - rootdepth = 0; - if (!fbInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth, - &defaultVisual,((unsigned long)1<<(imagebpp-1)), 8)) - { - xfree (visuals); - xfree (depths); - return FALSE; - } - if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width, - rootdepth, ndepths, depths, - defaultVisual, nvisuals, visuals)) - return FALSE; - /* overwrite miCloseScreen with our own */ - pScreen->CloseScreen = fbCloseScreen; -#ifdef FB_24_32BIT - if (bpp == 24 && imagebpp == 32) - { - pScreen->ModifyPixmapHeader = fb24_32ModifyPixmapHeader; - pScreen->CreateScreenResources = fb24_32CreateScreenResources; - } -#endif - return TRUE; -} - -/* dts * (inch/dot) * (25.4 mm / inch) = mm */ -#ifdef FB_ACCESS_WRAPPER -Bool -wfbScreenInit(ScreenPtr pScreen, - pointer pbits, - int xsize, - int ysize, - int dpix, - int dpiy, - int width, - int bpp, - SetupWrapProcPtr setupWrap, - FinishWrapProcPtr finishWrap) -{ - if (!fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp)) - return FALSE; - if (!wfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, - width, bpp, setupWrap, finishWrap)) - return FALSE; - return TRUE; -} -#else -Bool -fbScreenInit(ScreenPtr pScreen, - pointer pbits, - int xsize, - int ysize, - int dpix, - int dpiy, - int width, - int bpp) -{ - if (!fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp)) - return FALSE; - if (!fbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, - width, bpp)) - return FALSE; - return TRUE; -} -#endif +/*
+ * Copyright © 1998 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"
+
+Bool
+fbCloseScreen (int index, ScreenPtr pScreen)
+{
+ int d;
+ DepthPtr depths = pScreen->allowedDepths;
+
+ for (d = 0; d < pScreen->numDepths; d++)
+ free(depths[d].vids);
+ free(depths);
+ free(pScreen->visuals);
+ free(pScreen->devPrivate);
+#ifdef FB_SCREEN_PRIVATE
+ free(dixLookupPrivate(&pScreen->devPrivates, fbGetScreenPrivateKey()));
+#endif
+ return TRUE;
+}
+
+Bool
+fbRealizeFont(ScreenPtr pScreen, FontPtr pFont)
+{
+ return (TRUE);
+}
+
+Bool
+fbUnrealizeFont(ScreenPtr pScreen, FontPtr pFont)
+{
+ return (TRUE);
+}
+
+void
+fbQueryBestSize (int class,
+ unsigned short *width, unsigned short *height,
+ ScreenPtr pScreen)
+{
+ unsigned short w;
+
+ switch (class) {
+ case CursorShape:
+ if (*width > pScreen->width)
+ *width = pScreen->width;
+ if (*height > pScreen->height)
+ *height = pScreen->height;
+ break;
+ case TileShape:
+ case StippleShape:
+ w = *width;
+ if ((w & (w - 1)) && w < FB_UNIT)
+ {
+ for (w = 1; w < *width; w <<= 1)
+ ;
+ *width = w;
+ }
+ }
+}
+
+PixmapPtr
+_fbGetWindowPixmap (WindowPtr pWindow)
+{
+ return fbGetWindowPixmap (pWindow);
+}
+
+void
+_fbSetWindowPixmap (WindowPtr pWindow, PixmapPtr pPixmap)
+{
+ dixSetPrivate(&pWindow->devPrivates, fbGetWinPrivateKey(), pPixmap);
+}
+
+Bool
+fbSetupScreen(ScreenPtr pScreen,
+ pointer pbits, /* pointer to screen bitmap */
+ int xsize, /* in pixels */
+ int ysize,
+ int dpix, /* dots per inch */
+ int dpiy,
+ int width, /* pixel width of frame buffer */
+ int bpp) /* bits per pixel for screen */
+{
+ if (!fbAllocatePrivates(pScreen, NULL))
+ return FALSE;
+ pScreen->defColormap = FakeClientID(0);
+ /* let CreateDefColormap do whatever it wants for pixels */
+ pScreen->blackPixel = pScreen->whitePixel = (Pixel) 0;
+ pScreen->QueryBestSize = fbQueryBestSize;
+ /* SaveScreen */
+ pScreen->GetImage = fbGetImage;
+ pScreen->GetSpans = fbGetSpans;
+ pScreen->CreateWindow = fbCreateWindow;
+ pScreen->DestroyWindow = fbDestroyWindow;
+ pScreen->PositionWindow = fbPositionWindow;
+ pScreen->ChangeWindowAttributes = fbChangeWindowAttributes;
+ pScreen->RealizeWindow = fbMapWindow;
+ pScreen->UnrealizeWindow = fbUnmapWindow;
+ pScreen->CopyWindow = fbCopyWindow;
+ pScreen->CreatePixmap = fbCreatePixmap;
+ pScreen->DestroyPixmap = fbDestroyPixmap;
+ pScreen->RealizeFont = fbRealizeFont;
+ pScreen->UnrealizeFont = fbUnrealizeFont;
+ pScreen->CreateGC = fbCreateGC;
+ pScreen->CreateColormap = fbInitializeColormap;
+ pScreen->DestroyColormap = (void (*)(ColormapPtr))NoopDDA;
+ pScreen->InstallColormap = fbInstallColormap;
+ pScreen->UninstallColormap = fbUninstallColormap;
+ pScreen->ListInstalledColormaps = fbListInstalledColormaps;
+ pScreen->StoreColors = (void (*)(ColormapPtr, int, xColorItem *))NoopDDA;
+ pScreen->ResolveColor = fbResolveColor;
+ pScreen->BitmapToRegion = fbPixmapToRegion;
+
+ pScreen->GetWindowPixmap = _fbGetWindowPixmap;
+ pScreen->SetWindowPixmap = _fbSetWindowPixmap;
+
+ return TRUE;
+}
+
+#ifdef FB_ACCESS_WRAPPER
+Bool
+wfbFinishScreenInit(ScreenPtr pScreen,
+ pointer pbits,
+ int xsize,
+ int ysize,
+ int dpix,
+ int dpiy,
+ int width,
+ int bpp,
+ SetupWrapProcPtr setupWrap,
+ FinishWrapProcPtr finishWrap)
+#else
+Bool
+fbFinishScreenInit(ScreenPtr pScreen,
+ pointer pbits,
+ int xsize,
+ int ysize,
+ int dpix,
+ int dpiy,
+ int width,
+ int bpp)
+#endif
+{
+ VisualPtr visuals;
+ DepthPtr depths;
+ int nvisuals;
+ int ndepths;
+ int rootdepth;
+ VisualID defaultVisual;
+ int imagebpp = bpp;
+
+#ifdef FB_DEBUG
+ int stride;
+
+ ysize -= 2;
+ stride = (width * bpp) / 8;
+ fbSetBits ((FbStip *) pbits,
+ stride / sizeof (FbStip), FB_HEAD_BITS);
+ pbits = (void *) ((char *) pbits + stride);
+ fbSetBits ((FbStip *) ((char *) pbits + stride * ysize),
+ stride / sizeof (FbStip), FB_TAIL_BITS);
+#endif
+ /*
+ * By default, a 24bpp screen will use 32bpp images, this avoids
+ * problems with many applications which just can't handle packed
+ * pixels. If you want real 24bit images, include a 24bpp
+ * format in the pixmap formats
+ */
+#ifdef FB_24_32BIT
+ if (bpp == 24)
+ {
+ int f;
+
+ imagebpp = 32;
+ /*
+ * Check to see if we're advertising a 24bpp image format,
+ * in which case windows will use it in preference to a 32 bit
+ * format.
+ */
+ for (f = 0; f < screenInfo.numPixmapFormats; f++)
+ {
+ if (screenInfo.formats[f].bitsPerPixel == 24)
+ {
+ imagebpp = 24;
+ break;
+ }
+ }
+ }
+#endif
+#ifdef FB_SCREEN_PRIVATE
+ if (imagebpp == 32)
+ {
+ fbGetScreenPrivate(pScreen)->win32bpp = bpp;
+ fbGetScreenPrivate(pScreen)->pix32bpp = bpp;
+ }
+ else
+ {
+ fbGetScreenPrivate(pScreen)->win32bpp = 32;
+ fbGetScreenPrivate(pScreen)->pix32bpp = 32;
+ }
+#ifdef FB_ACCESS_WRAPPER
+ fbGetScreenPrivate(pScreen)->setupWrap = setupWrap;
+ fbGetScreenPrivate(pScreen)->finishWrap = finishWrap;
+#endif
+#endif
+ rootdepth = 0;
+ if (!fbInitVisuals (&visuals, &depths, &nvisuals, &ndepths, &rootdepth,
+ &defaultVisual,((unsigned long)1<<(imagebpp-1)), 8))
+ {
+ free(visuals);
+ free(depths);
+ return FALSE;
+ }
+ if (! miScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy, width,
+ rootdepth, ndepths, depths,
+ defaultVisual, nvisuals, visuals))
+ return FALSE;
+ /* overwrite miCloseScreen with our own */
+ pScreen->CloseScreen = fbCloseScreen;
+#ifdef FB_24_32BIT
+ if (bpp == 24 && imagebpp == 32)
+ {
+ pScreen->ModifyPixmapHeader = fb24_32ModifyPixmapHeader;
+ pScreen->CreateScreenResources = fb24_32CreateScreenResources;
+ }
+#endif
+ return TRUE;
+}
+
+/* dts * (inch/dot) * (25.4 mm / inch) = mm */
+#ifdef FB_ACCESS_WRAPPER
+Bool
+wfbScreenInit(ScreenPtr pScreen,
+ pointer pbits,
+ int xsize,
+ int ysize,
+ int dpix,
+ int dpiy,
+ int width,
+ int bpp,
+ SetupWrapProcPtr setupWrap,
+ FinishWrapProcPtr finishWrap)
+{
+ if (!fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp))
+ return FALSE;
+ if (!wfbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy,
+ width, bpp, setupWrap, finishWrap))
+ return FALSE;
+ return TRUE;
+}
+#else
+Bool
+fbScreenInit(ScreenPtr pScreen,
+ pointer pbits,
+ int xsize,
+ int ysize,
+ int dpix,
+ int dpiy,
+ int width,
+ int bpp)
+{
+ if (!fbSetupScreen(pScreen, pbits, xsize, ysize, dpix, dpiy, width, bpp))
+ return FALSE;
+ if (!fbFinishScreenInit(pScreen, pbits, xsize, ysize, dpix, dpiy,
+ width, bpp))
+ return FALSE;
+ return TRUE;
+}
+#endif
diff --git a/xorg-server/fb/fbseg.c b/xorg-server/fb/fbseg.c index 80ce7404e..0236721ab 100644 --- a/xorg-server/fb/fbseg.c +++ b/xorg-server/fb/fbseg.c @@ -1,734 +1,736 @@ -/* - * Copyright © 1998 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 <stdlib.h> - -#include "fb.h" -#include "miline.h" - -#define fbBresShiftMask(mask,dir,bpp) ((bpp == FB_STIP_UNIT) ? 0 : \ - ((dir < 0) ? FbStipLeft(mask,bpp) : \ - FbStipRight(mask,bpp))) - -void -fbBresSolid (DrawablePtr pDrawable, - GCPtr pGC, - int dashOffset, - int signdx, - int signdy, - int axis, - int x1, - int y1, - int e, - int e1, - int e3, - int len) -{ - FbStip *dst; - FbStride dstStride; - int dstBpp; - int dstXoff, dstYoff; - FbGCPrivPtr pPriv = fbGetGCPrivate (pGC); - FbStip and = (FbStip) pPriv->and; - FbStip xor = (FbStip) pPriv->xor; - FbStip mask, mask0; - FbStip bits; - - fbGetStipDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); - dst += ((y1 + dstYoff) * dstStride); - x1 = (x1 + dstXoff) * dstBpp; - dst += x1 >> FB_STIP_SHIFT; - x1 &= FB_STIP_MASK; - mask0 = FbStipMask(0, dstBpp); - mask = FbStipRight (mask0, x1); - if (signdx < 0) - mask0 = FbStipRight (mask0, FB_STIP_UNIT - dstBpp); - if (signdy < 0) - dstStride = -dstStride; - if (axis == X_AXIS) - { - bits = 0; - while (len--) - { - bits |= mask; - mask = fbBresShiftMask(mask,signdx,dstBpp); - if (!mask) - { - WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, bits)); - bits = 0; - dst += signdx; - mask = mask0; - } - e += e1; - if (e >= 0) - { - WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, bits)); - bits = 0; - dst += dstStride; - e += e3; - } - } - if (bits) - WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, bits)); - } - else - { - while (len--) - { - WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, mask)); - dst += dstStride; - e += e1; - if (e >= 0) - { - e += e3; - mask = fbBresShiftMask(mask,signdx,dstBpp); - if (!mask) - { - dst += signdx; - mask = mask0; - } - } - } - } - - fbFinishAccess (pDrawable); -} - -void -fbBresDash (DrawablePtr pDrawable, - GCPtr pGC, - int dashOffset, - int signdx, - int signdy, - int axis, - int x1, - int y1, - int e, - int e1, - int e3, - int len) -{ - FbStip *dst; - FbStride dstStride; - int dstBpp; - int dstXoff, dstYoff; - FbGCPrivPtr pPriv = fbGetGCPrivate (pGC); - FbStip and = (FbStip) pPriv->and; - FbStip xor = (FbStip) pPriv->xor; - FbStip bgand = (FbStip) pPriv->bgand; - FbStip bgxor = (FbStip) pPriv->bgxor; - FbStip mask, mask0; - FbDashDeclare; - int dashlen; - Bool even; - Bool doOdd; - - fbGetStipDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); - doOdd = pGC->lineStyle == LineDoubleDash; - - FbDashInit (pGC, pPriv, dashOffset, dashlen, even); - - dst += ((y1 + dstYoff) * dstStride); - x1 = (x1 + dstXoff) * dstBpp; - dst += x1 >> FB_STIP_SHIFT; - x1 &= FB_STIP_MASK; - mask0 = FbStipMask(0, dstBpp); - mask = FbStipRight (mask0, x1); - if (signdx < 0) - mask0 = FbStipRight (mask0, FB_STIP_UNIT - dstBpp); - if (signdy < 0) - dstStride = -dstStride; - while (len--) - { - if (even) - WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, mask)); - else if (doOdd) - WRITE(dst, FbDoMaskRRop (READ(dst), bgand, bgxor, mask)); - if (axis == X_AXIS) - { - mask = fbBresShiftMask(mask,signdx,dstBpp); - if (!mask) - { - dst += signdx; - mask = mask0; - } - e += e1; - if (e >= 0) - { - dst += dstStride; - e += e3; - } - } - else - { - dst += dstStride; - e += e1; - if (e >= 0) - { - e += e3; - mask = fbBresShiftMask(mask,signdx,dstBpp); - if (!mask) - { - dst += signdx; - mask = mask0; - } - } - } - FbDashStep (dashlen, even); - } - - fbFinishAccess (pDrawable); -} - -void -fbBresFill (DrawablePtr pDrawable, - GCPtr pGC, - int dashOffset, - int signdx, - int signdy, - int axis, - int x1, - int y1, - int e, - int e1, - int e3, - int len) -{ - while (len--) - { - fbFill (pDrawable, pGC, x1, y1, 1, 1); - if (axis == X_AXIS) - { - x1 += signdx; - e += e1; - if (e >= 0) - { - e += e3; - y1 += signdy; - } - } - else - { - y1 += signdy; - e += e1; - if (e >= 0) - { - e += e3; - x1 += signdx; - } - } - } -} - -static void -fbSetFg (DrawablePtr pDrawable, - GCPtr pGC, - Pixel fg) -{ - if (fg != pGC->fgPixel) - { - DoChangeGC (pGC, GCForeground, (XID *) &fg, FALSE); - ValidateGC (pDrawable, pGC); - } -} - -void -fbBresFillDash (DrawablePtr pDrawable, - GCPtr pGC, - int dashOffset, - int signdx, - int signdy, - int axis, - int x1, - int y1, - int e, - int e1, - int e3, - int len) -{ - FbGCPrivPtr pPriv = fbGetGCPrivate (pGC); - FbDashDeclare; - int dashlen; - Bool even; - Bool doOdd; - Bool doBg; - Pixel fg, bg; - - fg = pGC->fgPixel; - bg = pGC->bgPixel; - - /* whether to fill the odd dashes */ - doOdd = pGC->lineStyle == LineDoubleDash; - /* whether to switch fg to bg when filling odd dashes */ - doBg = doOdd && (pGC->fillStyle == FillSolid || - pGC->fillStyle == FillStippled); - - /* compute current dash position */ - FbDashInit (pGC, pPriv, dashOffset, dashlen, even); - - while (len--) - { - if (even || doOdd) - { - if (doBg) - { - if (even) - fbSetFg (pDrawable, pGC, fg); - else - fbSetFg (pDrawable, pGC, bg); - } - fbFill (pDrawable, pGC, x1, y1, 1, 1); - } - if (axis == X_AXIS) - { - x1 += signdx; - e += e1; - if (e >= 0) - { - e += e3; - y1 += signdy; - } - } - else - { - y1 += signdy; - e += e1; - if (e >= 0) - { - e += e3; - x1 += signdx; - } - } - FbDashStep (dashlen, even); - } - if (doBg) - fbSetFg (pDrawable, pGC, fg); -} - -#ifdef FB_24BIT -static void -fbBresSolid24RRop (DrawablePtr pDrawable, - GCPtr pGC, - int dashOffset, - int signdx, - int signdy, - int axis, - int x1, - int y1, - int e, - int e1, - int e3, - int len) -{ - FbStip *dst; - FbStride dstStride; - int dstBpp; - int dstXoff, dstYoff; - FbGCPrivPtr pPriv = fbGetGCPrivate (pGC); - FbStip and = pPriv->and; - FbStip xor = pPriv->xor; - FbStip leftMask, rightMask; - int nl; - FbStip *d; - int x; - int rot; - FbStip andT, xorT; - - fbGetStipDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); - dst += ((y1 + dstYoff) * dstStride); - x1 = (x1 + dstXoff) * 24; - if (signdy < 0) - dstStride = -dstStride; - signdx *= 24; - while (len--) - { - d = dst + (x1 >> FB_STIP_SHIFT); - x = x1 & FB_STIP_MASK; - rot = FbFirst24Rot (x); - andT = FbRot24Stip(and,rot); - xorT = FbRot24Stip(xor,rot); - FbMaskStip (x, 24, leftMask, nl, rightMask); - if (leftMask) - { - WRITE(d, FbDoMaskRRop (READ(d), andT, xorT, leftMask)); - d++; - andT = FbNext24Stip (andT); - xorT = FbNext24Stip (xorT); - } - if (rightMask) - WRITE(d, FbDoMaskRRop (READ(d), andT, xorT, rightMask)); - if (axis == X_AXIS) - { - x1 += signdx; - e += e1; - if (e >= 0) - { - e += e3; - dst += dstStride; - } - } - else - { - dst += dstStride; - e += e1; - if (e >= 0) - { - e += e3; - x1 += signdx; - } - } - } - - fbFinishAccess (pDrawable); -} - -static void -fbBresDash24RRop (DrawablePtr pDrawable, - GCPtr pGC, - int dashOffset, - int signdx, - int signdy, - int axis, - int x1, - int y1, - int e, - int e1, - int e3, - int len) -{ - FbStip *dst; - FbStride dstStride; - int dstBpp; - int dstXoff, dstYoff; - FbGCPrivPtr pPriv = fbGetGCPrivate (pGC); - FbStip andT, xorT; - FbStip fgand = pPriv->and; - FbStip fgxor = pPriv->xor; - FbStip bgand = pPriv->bgand; - FbStip bgxor = pPriv->bgxor; - FbStip leftMask, rightMask; - int nl; - FbStip *d; - int x; - int rot; - FbDashDeclare; - int dashlen; - Bool even; - Bool doOdd; - - fbGetStipDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff); - doOdd = pGC->lineStyle == LineDoubleDash; - - /* compute current dash position */ - FbDashInit(pGC, pPriv, dashOffset, dashlen, even); - - dst += ((y1 + dstYoff) * dstStride); - x1 = (x1 + dstXoff) * 24; - if (signdy < 0) - dstStride = -dstStride; - signdx *= 24; - while (len--) - { - if (even || doOdd) - { - if (even) - { - andT = fgand; - xorT = fgxor; - } - else - { - andT = bgand; - xorT = bgxor; - } - d = dst + (x1 >> FB_STIP_SHIFT); - x = x1 & FB_STIP_MASK; - rot = FbFirst24Rot (x); - andT = FbRot24Stip (andT, rot); - xorT = FbRot24Stip (xorT, rot); - FbMaskStip (x, 24, leftMask, nl, rightMask); - if (leftMask) - { - WRITE(d, FbDoMaskRRop (READ(d), andT, xorT, leftMask)); - d++; - andT = FbNext24Stip (andT); - xorT = FbNext24Stip (xorT); - } - if (rightMask) - WRITE(d, FbDoMaskRRop (READ(d), andT, xorT, rightMask)); - } - if (axis == X_AXIS) - { - x1 += signdx; - e += e1; - if (e >= 0) - { - e += e3; - dst += dstStride; - } - } - else - { - dst += dstStride; - e += e1; - if (e >= 0) - { - e += e3; - x1 += signdx; - } - } - FbDashStep (dashlen, even); - } - - fbFinishAccess (pDrawable); -} -#endif - -/* - * For drivers that want to bail drawing some lines, this - * function takes care of selecting the appropriate rasterizer - * based on the contents of the specified GC. - */ - -FbBres * -fbSelectBres (DrawablePtr pDrawable, - GCPtr pGC) -{ - FbGCPrivPtr pPriv = fbGetGCPrivate(pGC); - int dstBpp = pDrawable->bitsPerPixel; - FbBres * bres; - - if (pGC->lineStyle == LineSolid) - { - bres = fbBresFill; - if (pGC->fillStyle == FillSolid) - { - bres = fbBresSolid; -#ifdef FB_24BIT - if (dstBpp == 24) - bres = fbBresSolid24RRop; -#endif -#ifndef FBNOPIXADDR - if (pPriv->and == 0) - { - switch (dstBpp) { - case 8: bres = fbBresSolid8; break; - case 16: bres = fbBresSolid16; break; -#ifdef FB_24BIT - case 24: bres = fbBresSolid24; break; -#endif - case 32: bres = fbBresSolid32; break; - } - } -#endif - } - } - else - { - bres = fbBresFillDash; - if (pGC->fillStyle == FillSolid) - { - bres = fbBresDash; -#ifdef FB_24BIT - if (dstBpp == 24) - bres = fbBresDash24RRop; -#endif -#ifndef FBNOPIXADDR - if (pPriv->and == 0 && - (pGC->lineStyle == LineOnOffDash || pPriv->bgand == 0)) - { - switch (dstBpp) { - case 8: bres = fbBresDash8; break; - case 16: bres = fbBresDash16; break; -#ifdef FB_24BIT - case 24: bres = fbBresDash24; break; -#endif - case 32: bres = fbBresDash32; break; - } - } -#endif - } - } - return bres; -} - -void -fbBres (DrawablePtr pDrawable, - GCPtr pGC, - int dashOffset, - int signdx, - int signdy, - int axis, - int x1, - int y1, - int e, - int e1, - int e3, - int len) -{ - (*fbSelectBres (pDrawable, pGC)) (pDrawable, pGC, dashOffset, - signdx, signdy, axis, x1, y1, - e, e1, e3, len); -} - -void -fbSegment (DrawablePtr pDrawable, - GCPtr pGC, - int x1, - int y1, - int x2, - int y2, - Bool drawLast, - int *dashOffset) -{ - FbBres * bres; - RegionPtr pClip = fbGetCompositeClip(pGC); - BoxPtr pBox; - int nBox; - int adx; /* abs values of dx and dy */ - int ady; - int signdx; /* sign of dx and dy */ - int signdy; - int e, e1, e2, e3; /* bresenham error and increments */ - int len; /* length of segment */ - int axis; /* major axis */ - int octant; - int dashoff; - int doff; - unsigned int bias = miGetZeroLineBias(pDrawable->pScreen); - unsigned int oc1; /* outcode of point 1 */ - unsigned int oc2; /* outcode of point 2 */ - - nBox = REGION_NUM_RECTS (pClip); - pBox = REGION_RECTS (pClip); - - bres = fbSelectBres (pDrawable, pGC); - - CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy, - 1, 1, octant); - - if (adx > ady) - { - axis = X_AXIS; - e1 = ady << 1; - e2 = e1 - (adx << 1); - e = e1 - adx; - len = adx; - } - else - { - axis = Y_AXIS; - e1 = adx << 1; - e2 = e1 - (ady << 1); - e = e1 - ady; - SetYMajorOctant(octant); - len = ady; - } - - FIXUP_ERROR (e, octant, bias); - - /* - * Adjust error terms to compare against zero - */ - e3 = e2 - e1; - e = e - e1; - - /* we have bresenham parameters and two points. - all we have to do now is clip and draw. - */ - - if (drawLast) - len++; - dashoff = *dashOffset; - *dashOffset = dashoff + len; - while(nBox--) - { - oc1 = 0; - oc2 = 0; - OUTCODES(oc1, x1, y1, pBox); - OUTCODES(oc2, x2, y2, pBox); - if ((oc1 | oc2) == 0) - { - (*bres) (pDrawable, pGC, dashoff, - signdx, signdy, axis, x1, y1, - e, e1, e3, len); - break; - } - else if (oc1 & oc2) - { - pBox++; - } - else - { - int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2; - int clip1 = 0, clip2 = 0; - int clipdx, clipdy; - int err; - - if (miZeroClipLine(pBox->x1, pBox->y1, pBox->x2-1, - pBox->y2-1, - &new_x1, &new_y1, &new_x2, &new_y2, - adx, ady, &clip1, &clip2, - octant, bias, oc1, oc2) == -1) - { - pBox++; - continue; - } - - if (axis == X_AXIS) - len = abs(new_x2 - new_x1); - else - len = abs(new_y2 - new_y1); - if (clip2 != 0 || drawLast) - len++; - if (len) - { - /* unwind bresenham error term to first point */ - doff = dashoff; - err = e; - if (clip1) - { - clipdx = abs(new_x1 - x1); - clipdy = abs(new_y1 - y1); - if (axis == X_AXIS) - { - doff += clipdx; - err += e3 * clipdy + e1 * clipdx; - } - else - { - doff += clipdy; - err += e3 * clipdx + e1 * clipdy; - } - } - (*bres) (pDrawable, pGC, doff, - signdx, signdy, axis, new_x1, new_y1, - err, e1, e3, len); - } - pBox++; - } - } /* while (nBox--) */ -} +/*
+ * Copyright © 1998 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 <stdlib.h>
+
+#include "fb.h"
+#include "miline.h"
+
+#define fbBresShiftMask(mask,dir,bpp) ((bpp == FB_STIP_UNIT) ? 0 : \
+ ((dir < 0) ? FbStipLeft(mask,bpp) : \
+ FbStipRight(mask,bpp)))
+
+void
+fbBresSolid (DrawablePtr pDrawable,
+ GCPtr pGC,
+ int dashOffset,
+ int signdx,
+ int signdy,
+ int axis,
+ int x1,
+ int y1,
+ int e,
+ int e1,
+ int e3,
+ int len)
+{
+ FbStip *dst;
+ FbStride dstStride;
+ int dstBpp;
+ int dstXoff, dstYoff;
+ FbGCPrivPtr pPriv = fbGetGCPrivate (pGC);
+ FbStip and = (FbStip) pPriv->and;
+ FbStip xor = (FbStip) pPriv->xor;
+ FbStip mask, mask0;
+ FbStip bits;
+
+ fbGetStipDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+ dst += ((y1 + dstYoff) * dstStride);
+ x1 = (x1 + dstXoff) * dstBpp;
+ dst += x1 >> FB_STIP_SHIFT;
+ x1 &= FB_STIP_MASK;
+ mask0 = FbStipMask(0, dstBpp);
+ mask = FbStipRight (mask0, x1);
+ if (signdx < 0)
+ mask0 = FbStipRight (mask0, FB_STIP_UNIT - dstBpp);
+ if (signdy < 0)
+ dstStride = -dstStride;
+ if (axis == X_AXIS)
+ {
+ bits = 0;
+ while (len--)
+ {
+ bits |= mask;
+ mask = fbBresShiftMask(mask,signdx,dstBpp);
+ if (!mask)
+ {
+ WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, bits));
+ bits = 0;
+ dst += signdx;
+ mask = mask0;
+ }
+ e += e1;
+ if (e >= 0)
+ {
+ WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, bits));
+ bits = 0;
+ dst += dstStride;
+ e += e3;
+ }
+ }
+ if (bits)
+ WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, bits));
+ }
+ else
+ {
+ while (len--)
+ {
+ WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, mask));
+ dst += dstStride;
+ e += e1;
+ if (e >= 0)
+ {
+ e += e3;
+ mask = fbBresShiftMask(mask,signdx,dstBpp);
+ if (!mask)
+ {
+ dst += signdx;
+ mask = mask0;
+ }
+ }
+ }
+ }
+
+ fbFinishAccess (pDrawable);
+}
+
+void
+fbBresDash (DrawablePtr pDrawable,
+ GCPtr pGC,
+ int dashOffset,
+ int signdx,
+ int signdy,
+ int axis,
+ int x1,
+ int y1,
+ int e,
+ int e1,
+ int e3,
+ int len)
+{
+ FbStip *dst;
+ FbStride dstStride;
+ int dstBpp;
+ int dstXoff, dstYoff;
+ FbGCPrivPtr pPriv = fbGetGCPrivate (pGC);
+ FbStip and = (FbStip) pPriv->and;
+ FbStip xor = (FbStip) pPriv->xor;
+ FbStip bgand = (FbStip) pPriv->bgand;
+ FbStip bgxor = (FbStip) pPriv->bgxor;
+ FbStip mask, mask0;
+ FbDashDeclare;
+ int dashlen;
+ Bool even;
+ Bool doOdd;
+
+ fbGetStipDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+ doOdd = pGC->lineStyle == LineDoubleDash;
+
+ FbDashInit (pGC, pPriv, dashOffset, dashlen, even);
+
+ dst += ((y1 + dstYoff) * dstStride);
+ x1 = (x1 + dstXoff) * dstBpp;
+ dst += x1 >> FB_STIP_SHIFT;
+ x1 &= FB_STIP_MASK;
+ mask0 = FbStipMask(0, dstBpp);
+ mask = FbStipRight (mask0, x1);
+ if (signdx < 0)
+ mask0 = FbStipRight (mask0, FB_STIP_UNIT - dstBpp);
+ if (signdy < 0)
+ dstStride = -dstStride;
+ while (len--)
+ {
+ if (even)
+ WRITE(dst, FbDoMaskRRop (READ(dst), and, xor, mask));
+ else if (doOdd)
+ WRITE(dst, FbDoMaskRRop (READ(dst), bgand, bgxor, mask));
+ if (axis == X_AXIS)
+ {
+ mask = fbBresShiftMask(mask,signdx,dstBpp);
+ if (!mask)
+ {
+ dst += signdx;
+ mask = mask0;
+ }
+ e += e1;
+ if (e >= 0)
+ {
+ dst += dstStride;
+ e += e3;
+ }
+ }
+ else
+ {
+ dst += dstStride;
+ e += e1;
+ if (e >= 0)
+ {
+ e += e3;
+ mask = fbBresShiftMask(mask,signdx,dstBpp);
+ if (!mask)
+ {
+ dst += signdx;
+ mask = mask0;
+ }
+ }
+ }
+ FbDashStep (dashlen, even);
+ }
+
+ fbFinishAccess (pDrawable);
+}
+
+void
+fbBresFill (DrawablePtr pDrawable,
+ GCPtr pGC,
+ int dashOffset,
+ int signdx,
+ int signdy,
+ int axis,
+ int x1,
+ int y1,
+ int e,
+ int e1,
+ int e3,
+ int len)
+{
+ while (len--)
+ {
+ fbFill (pDrawable, pGC, x1, y1, 1, 1);
+ if (axis == X_AXIS)
+ {
+ x1 += signdx;
+ e += e1;
+ if (e >= 0)
+ {
+ e += e3;
+ y1 += signdy;
+ }
+ }
+ else
+ {
+ y1 += signdy;
+ e += e1;
+ if (e >= 0)
+ {
+ e += e3;
+ x1 += signdx;
+ }
+ }
+ }
+}
+
+static void
+fbSetFg (DrawablePtr pDrawable,
+ GCPtr pGC,
+ Pixel fg)
+{
+ if (fg != pGC->fgPixel)
+ {
+ ChangeGCVal val;
+ val.val = fg;
+ ChangeGC (NullClient, pGC, GCForeground, &val);
+ ValidateGC (pDrawable, pGC);
+ }
+}
+
+void
+fbBresFillDash (DrawablePtr pDrawable,
+ GCPtr pGC,
+ int dashOffset,
+ int signdx,
+ int signdy,
+ int axis,
+ int x1,
+ int y1,
+ int e,
+ int e1,
+ int e3,
+ int len)
+{
+ FbGCPrivPtr pPriv = fbGetGCPrivate (pGC);
+ FbDashDeclare;
+ int dashlen;
+ Bool even;
+ Bool doOdd;
+ Bool doBg;
+ Pixel fg, bg;
+
+ fg = pGC->fgPixel;
+ bg = pGC->bgPixel;
+
+ /* whether to fill the odd dashes */
+ doOdd = pGC->lineStyle == LineDoubleDash;
+ /* whether to switch fg to bg when filling odd dashes */
+ doBg = doOdd && (pGC->fillStyle == FillSolid ||
+ pGC->fillStyle == FillStippled);
+
+ /* compute current dash position */
+ FbDashInit (pGC, pPriv, dashOffset, dashlen, even);
+
+ while (len--)
+ {
+ if (even || doOdd)
+ {
+ if (doBg)
+ {
+ if (even)
+ fbSetFg (pDrawable, pGC, fg);
+ else
+ fbSetFg (pDrawable, pGC, bg);
+ }
+ fbFill (pDrawable, pGC, x1, y1, 1, 1);
+ }
+ if (axis == X_AXIS)
+ {
+ x1 += signdx;
+ e += e1;
+ if (e >= 0)
+ {
+ e += e3;
+ y1 += signdy;
+ }
+ }
+ else
+ {
+ y1 += signdy;
+ e += e1;
+ if (e >= 0)
+ {
+ e += e3;
+ x1 += signdx;
+ }
+ }
+ FbDashStep (dashlen, even);
+ }
+ if (doBg)
+ fbSetFg (pDrawable, pGC, fg);
+}
+
+#ifdef FB_24BIT
+static void
+fbBresSolid24RRop (DrawablePtr pDrawable,
+ GCPtr pGC,
+ int dashOffset,
+ int signdx,
+ int signdy,
+ int axis,
+ int x1,
+ int y1,
+ int e,
+ int e1,
+ int e3,
+ int len)
+{
+ FbStip *dst;
+ FbStride dstStride;
+ int dstBpp;
+ int dstXoff, dstYoff;
+ FbGCPrivPtr pPriv = fbGetGCPrivate (pGC);
+ FbStip and = pPriv->and;
+ FbStip xor = pPriv->xor;
+ FbStip leftMask, rightMask;
+ int nl;
+ FbStip *d;
+ int x;
+ int rot;
+ FbStip andT, xorT;
+
+ fbGetStipDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+ dst += ((y1 + dstYoff) * dstStride);
+ x1 = (x1 + dstXoff) * 24;
+ if (signdy < 0)
+ dstStride = -dstStride;
+ signdx *= 24;
+ while (len--)
+ {
+ d = dst + (x1 >> FB_STIP_SHIFT);
+ x = x1 & FB_STIP_MASK;
+ rot = FbFirst24Rot (x);
+ andT = FbRot24Stip(and,rot);
+ xorT = FbRot24Stip(xor,rot);
+ FbMaskStip (x, 24, leftMask, nl, rightMask);
+ if (leftMask)
+ {
+ WRITE(d, FbDoMaskRRop (READ(d), andT, xorT, leftMask));
+ d++;
+ andT = FbNext24Stip (andT);
+ xorT = FbNext24Stip (xorT);
+ }
+ if (rightMask)
+ WRITE(d, FbDoMaskRRop (READ(d), andT, xorT, rightMask));
+ if (axis == X_AXIS)
+ {
+ x1 += signdx;
+ e += e1;
+ if (e >= 0)
+ {
+ e += e3;
+ dst += dstStride;
+ }
+ }
+ else
+ {
+ dst += dstStride;
+ e += e1;
+ if (e >= 0)
+ {
+ e += e3;
+ x1 += signdx;
+ }
+ }
+ }
+
+ fbFinishAccess (pDrawable);
+}
+
+static void
+fbBresDash24RRop (DrawablePtr pDrawable,
+ GCPtr pGC,
+ int dashOffset,
+ int signdx,
+ int signdy,
+ int axis,
+ int x1,
+ int y1,
+ int e,
+ int e1,
+ int e3,
+ int len)
+{
+ FbStip *dst;
+ FbStride dstStride;
+ int dstBpp;
+ int dstXoff, dstYoff;
+ FbGCPrivPtr pPriv = fbGetGCPrivate (pGC);
+ FbStip andT, xorT;
+ FbStip fgand = pPriv->and;
+ FbStip fgxor = pPriv->xor;
+ FbStip bgand = pPriv->bgand;
+ FbStip bgxor = pPriv->bgxor;
+ FbStip leftMask, rightMask;
+ int nl;
+ FbStip *d;
+ int x;
+ int rot;
+ FbDashDeclare;
+ int dashlen;
+ Bool even;
+ Bool doOdd;
+
+ fbGetStipDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
+ doOdd = pGC->lineStyle == LineDoubleDash;
+
+ /* compute current dash position */
+ FbDashInit(pGC, pPriv, dashOffset, dashlen, even);
+
+ dst += ((y1 + dstYoff) * dstStride);
+ x1 = (x1 + dstXoff) * 24;
+ if (signdy < 0)
+ dstStride = -dstStride;
+ signdx *= 24;
+ while (len--)
+ {
+ if (even || doOdd)
+ {
+ if (even)
+ {
+ andT = fgand;
+ xorT = fgxor;
+ }
+ else
+ {
+ andT = bgand;
+ xorT = bgxor;
+ }
+ d = dst + (x1 >> FB_STIP_SHIFT);
+ x = x1 & FB_STIP_MASK;
+ rot = FbFirst24Rot (x);
+ andT = FbRot24Stip (andT, rot);
+ xorT = FbRot24Stip (xorT, rot);
+ FbMaskStip (x, 24, leftMask, nl, rightMask);
+ if (leftMask)
+ {
+ WRITE(d, FbDoMaskRRop (READ(d), andT, xorT, leftMask));
+ d++;
+ andT = FbNext24Stip (andT);
+ xorT = FbNext24Stip (xorT);
+ }
+ if (rightMask)
+ WRITE(d, FbDoMaskRRop (READ(d), andT, xorT, rightMask));
+ }
+ if (axis == X_AXIS)
+ {
+ x1 += signdx;
+ e += e1;
+ if (e >= 0)
+ {
+ e += e3;
+ dst += dstStride;
+ }
+ }
+ else
+ {
+ dst += dstStride;
+ e += e1;
+ if (e >= 0)
+ {
+ e += e3;
+ x1 += signdx;
+ }
+ }
+ FbDashStep (dashlen, even);
+ }
+
+ fbFinishAccess (pDrawable);
+}
+#endif
+
+/*
+ * For drivers that want to bail drawing some lines, this
+ * function takes care of selecting the appropriate rasterizer
+ * based on the contents of the specified GC.
+ */
+
+FbBres *
+fbSelectBres (DrawablePtr pDrawable,
+ GCPtr pGC)
+{
+ FbGCPrivPtr pPriv = fbGetGCPrivate(pGC);
+ int dstBpp = pDrawable->bitsPerPixel;
+ FbBres * bres;
+
+ if (pGC->lineStyle == LineSolid)
+ {
+ bres = fbBresFill;
+ if (pGC->fillStyle == FillSolid)
+ {
+ bres = fbBresSolid;
+#ifdef FB_24BIT
+ if (dstBpp == 24)
+ bres = fbBresSolid24RRop;
+#endif
+#ifndef FBNOPIXADDR
+ if (pPriv->and == 0)
+ {
+ switch (dstBpp) {
+ case 8: bres = fbBresSolid8; break;
+ case 16: bres = fbBresSolid16; break;
+#ifdef FB_24BIT
+ case 24: bres = fbBresSolid24; break;
+#endif
+ case 32: bres = fbBresSolid32; break;
+ }
+ }
+#endif
+ }
+ }
+ else
+ {
+ bres = fbBresFillDash;
+ if (pGC->fillStyle == FillSolid)
+ {
+ bres = fbBresDash;
+#ifdef FB_24BIT
+ if (dstBpp == 24)
+ bres = fbBresDash24RRop;
+#endif
+#ifndef FBNOPIXADDR
+ if (pPriv->and == 0 &&
+ (pGC->lineStyle == LineOnOffDash || pPriv->bgand == 0))
+ {
+ switch (dstBpp) {
+ case 8: bres = fbBresDash8; break;
+ case 16: bres = fbBresDash16; break;
+#ifdef FB_24BIT
+ case 24: bres = fbBresDash24; break;
+#endif
+ case 32: bres = fbBresDash32; break;
+ }
+ }
+#endif
+ }
+ }
+ return bres;
+}
+
+void
+fbBres (DrawablePtr pDrawable,
+ GCPtr pGC,
+ int dashOffset,
+ int signdx,
+ int signdy,
+ int axis,
+ int x1,
+ int y1,
+ int e,
+ int e1,
+ int e3,
+ int len)
+{
+ (*fbSelectBres (pDrawable, pGC)) (pDrawable, pGC, dashOffset,
+ signdx, signdy, axis, x1, y1,
+ e, e1, e3, len);
+}
+
+void
+fbSegment (DrawablePtr pDrawable,
+ GCPtr pGC,
+ int x1,
+ int y1,
+ int x2,
+ int y2,
+ Bool drawLast,
+ int *dashOffset)
+{
+ FbBres * bres;
+ RegionPtr pClip = fbGetCompositeClip(pGC);
+ BoxPtr pBox;
+ int nBox;
+ int adx; /* abs values of dx and dy */
+ int ady;
+ int signdx; /* sign of dx and dy */
+ int signdy;
+ int e, e1, e2, e3; /* bresenham error and increments */
+ int len; /* length of segment */
+ int axis; /* major axis */
+ int octant;
+ int dashoff;
+ int doff;
+ unsigned int bias = miGetZeroLineBias(pDrawable->pScreen);
+ unsigned int oc1; /* outcode of point 1 */
+ unsigned int oc2; /* outcode of point 2 */
+
+ nBox = REGION_NUM_RECTS (pClip);
+ pBox = REGION_RECTS (pClip);
+
+ bres = fbSelectBres (pDrawable, pGC);
+
+ CalcLineDeltas(x1, y1, x2, y2, adx, ady, signdx, signdy,
+ 1, 1, octant);
+
+ if (adx > ady)
+ {
+ axis = X_AXIS;
+ e1 = ady << 1;
+ e2 = e1 - (adx << 1);
+ e = e1 - adx;
+ len = adx;
+ }
+ else
+ {
+ axis = Y_AXIS;
+ e1 = adx << 1;
+ e2 = e1 - (ady << 1);
+ e = e1 - ady;
+ SetYMajorOctant(octant);
+ len = ady;
+ }
+
+ FIXUP_ERROR (e, octant, bias);
+
+ /*
+ * Adjust error terms to compare against zero
+ */
+ e3 = e2 - e1;
+ e = e - e1;
+
+ /* we have bresenham parameters and two points.
+ all we have to do now is clip and draw.
+ */
+
+ if (drawLast)
+ len++;
+ dashoff = *dashOffset;
+ *dashOffset = dashoff + len;
+ while(nBox--)
+ {
+ oc1 = 0;
+ oc2 = 0;
+ OUTCODES(oc1, x1, y1, pBox);
+ OUTCODES(oc2, x2, y2, pBox);
+ if ((oc1 | oc2) == 0)
+ {
+ (*bres) (pDrawable, pGC, dashoff,
+ signdx, signdy, axis, x1, y1,
+ e, e1, e3, len);
+ break;
+ }
+ else if (oc1 & oc2)
+ {
+ pBox++;
+ }
+ else
+ {
+ int new_x1 = x1, new_y1 = y1, new_x2 = x2, new_y2 = y2;
+ int clip1 = 0, clip2 = 0;
+ int clipdx, clipdy;
+ int err;
+
+ if (miZeroClipLine(pBox->x1, pBox->y1, pBox->x2-1,
+ pBox->y2-1,
+ &new_x1, &new_y1, &new_x2, &new_y2,
+ adx, ady, &clip1, &clip2,
+ octant, bias, oc1, oc2) == -1)
+ {
+ pBox++;
+ continue;
+ }
+
+ if (axis == X_AXIS)
+ len = abs(new_x2 - new_x1);
+ else
+ len = abs(new_y2 - new_y1);
+ if (clip2 != 0 || drawLast)
+ len++;
+ if (len)
+ {
+ /* unwind bresenham error term to first point */
+ doff = dashoff;
+ err = e;
+ if (clip1)
+ {
+ clipdx = abs(new_x1 - x1);
+ clipdy = abs(new_y1 - y1);
+ if (axis == X_AXIS)
+ {
+ doff += clipdx;
+ err += e3 * clipdy + e1 * clipdx;
+ }
+ else
+ {
+ doff += clipdy;
+ err += e3 * clipdx + e1 * clipdy;
+ }
+ }
+ (*bres) (pDrawable, pGC, doff,
+ signdx, signdy, axis, new_x1, new_y1,
+ err, e1, e3, len);
+ }
+ pBox++;
+ }
+ } /* while (nBox--) */
+}
|