First import
[xorg_rtime.git] / xorg-server-1.4 / cfb / cfbimage.c
blob396e1fcb241123aa9a00a561cf7ac5b0da0ef0d6
1 /***********************************************************
3 Copyright 1987, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
9 documentation.
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
26 Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
28 All Rights Reserved
30 Permission to use, copy, modify, and distribute this software and its
31 documentation for any purpose and without fee is hereby granted,
32 provided that the above copyright notice appear in all copies and that
33 both that copyright notice and this permission notice appear in
34 supporting documentation, and that the name of Digital not be
35 used in advertising or publicity pertaining to distribution of the
36 software without specific, written prior permission.
38 DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40 DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 SOFTWARE.
46 ******************************************************************/
48 #ifdef HAVE_DIX_CONFIG_H
49 #include <dix-config.h>
50 #endif
52 #include <string.h>
54 #include <X11/X.h>
55 #include "windowstr.h"
56 #include "pixmapstr.h"
57 #include "scrnintstr.h"
58 #include "gcstruct.h"
59 #include "cfb.h"
60 #include "cfbmskbits.h"
61 #include "servermd.h"
62 #include "mi.h"
64 void
65 cfbPutImage(pDraw, pGC, depth, x, y, w, h, leftPad, format, pImage)
66 DrawablePtr pDraw;
67 GCPtr pGC;
68 int depth, x, y, w, h;
69 int leftPad;
70 int format;
71 char *pImage;
73 PixmapPtr pPixmap;
75 if ((w == 0) || (h == 0))
76 return;
78 if (format != XYPixmap)
80 pPixmap = GetScratchPixmapHeader(pDraw->pScreen, w+leftPad, h, depth,
81 BitsPerPixel(depth), PixmapBytePad(w+leftPad, depth),
82 (pointer)pImage);
83 if (!pPixmap)
84 return;
86 pGC->fExpose = FALSE;
87 if (format == ZPixmap)
88 (void)(*pGC->ops->CopyArea)((DrawablePtr)pPixmap, pDraw, pGC,
89 leftPad, 0, w, h, x, y);
90 else
91 (void)(*pGC->ops->CopyPlane)((DrawablePtr)pPixmap, pDraw, pGC,
92 leftPad, 0, w, h, x, y, 1);
93 pGC->fExpose = TRUE;
94 FreeScratchPixmapHeader(pPixmap);
96 else
98 CfbBits oldFg, oldBg;
99 XID gcv[3];
100 CfbBits oldPlanemask;
101 unsigned long i;
102 long bytesPer;
104 depth = pGC->depth;
105 oldPlanemask = pGC->planemask;
106 oldFg = pGC->fgPixel;
107 oldBg = pGC->bgPixel;
108 gcv[0] = ~0L;
109 gcv[1] = 0;
110 DoChangeGC(pGC, GCForeground | GCBackground, gcv, 0);
111 bytesPer = (long)h * BitmapBytePad(w + leftPad);
113 for (i = 1 << (depth-1); i != 0; i >>= 1, pImage += bytesPer)
115 if (i & oldPlanemask)
117 gcv[0] = i;
118 DoChangeGC(pGC, GCPlaneMask, gcv, 0);
119 ValidateGC(pDraw, pGC);
120 (*pGC->ops->PutImage)(pDraw, pGC, 1, x, y, w, h, leftPad,
121 XYBitmap, pImage);
124 gcv[0] = oldPlanemask;
125 gcv[1] = oldFg;
126 gcv[2] = oldBg;
127 DoChangeGC(pGC, GCPlaneMask | GCForeground | GCBackground, gcv, 0);
128 ValidateGC(pDraw, pGC);
132 void
133 cfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine)
134 DrawablePtr pDrawable;
135 int sx, sy, w, h;
136 unsigned int format;
137 unsigned long planeMask;
138 char *pdstLine;
140 BoxRec box;
141 DDXPointRec ptSrc;
142 RegionRec rgnDst;
143 ScreenPtr pScreen;
144 PixmapPtr pPixmap;
146 if ((w == 0) || (h == 0))
147 return;
148 if (pDrawable->bitsPerPixel == 1)
150 mfbGetImage(pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
151 return;
153 pScreen = pDrawable->pScreen;
155 * XFree86 DDX empties the root borderClip when the VT is
156 * switched away; this checks for that case
158 if (!cfbDrawableEnabled (pDrawable))
159 return;
160 if (format == ZPixmap)
162 pPixmap = GetScratchPixmapHeader(pScreen, w, h,
163 pDrawable->depth, pDrawable->bitsPerPixel,
164 PixmapBytePad(w,pDrawable->depth), (pointer)pdstLine);
165 if (!pPixmap)
166 return;
167 if ((planeMask & PMSK) != PMSK)
168 bzero((char *)pdstLine, pPixmap->devKind * h);
169 ptSrc.x = sx + pDrawable->x;
170 ptSrc.y = sy + pDrawable->y;
171 box.x1 = 0;
172 box.y1 = 0;
173 box.x2 = w;
174 box.y2 = h;
175 REGION_INIT(pScreen, &rgnDst, &box, 1);
176 cfbDoBitblt(pDrawable, (DrawablePtr)pPixmap, GXcopy, &rgnDst,
177 &ptSrc, planeMask);
178 REGION_UNINIT(pScreen, &rgnDst);
179 FreeScratchPixmapHeader(pPixmap);
181 else
184 #if IMAGE_BYTE_ORDER == LSBFirst
186 pPixmap = GetScratchPixmapHeader(pScreen, w, h, /*depth*/ 1,
187 /*bpp*/ 1, BitmapBytePad(w), (pointer)pdstLine);
188 if (!pPixmap)
189 return;
191 ptSrc.x = sx + pDrawable->x;
192 ptSrc.y = sy + pDrawable->y;
193 box.x1 = 0;
194 box.y1 = 0;
195 box.x2 = w;
196 box.y2 = h;
197 REGION_INIT(pScreen, &rgnDst, &box, 1);
198 cfbCopyImagePlane (pDrawable, (DrawablePtr)pPixmap, GXcopy, &rgnDst,
199 &ptSrc, planeMask);
200 REGION_UNINIT(pScreen, &rgnDst);
201 FreeScratchPixmapHeader(pPixmap);
202 #else
203 miGetImage (pDrawable, sx, sy, w, h, format, planeMask, pdstLine);
204 #endif