First import
[xorg_rtime.git] / xorg-server-1.4 / fb / fbwindow.c
blob144f083627272ad105c5ae9c75c40e17e5c775b7
1 /*
2 * Copyright © 1998 Keith Packard
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Keith Packard not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Keith Packard makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
23 #ifdef HAVE_DIX_CONFIG_H
24 #include <dix-config.h>
25 #endif
27 #include <stdlib.h>
29 #include "fb.h"
31 Bool
32 fbCreateWindow(WindowPtr pWin)
34 #ifndef FB_NO_WINDOW_PIXMAPS
35 pWin->devPrivates[fbWinPrivateIndex].ptr =
36 (pointer) fbGetScreenPixmap(pWin->drawable.pScreen);
37 #endif
38 #ifdef FB_SCREEN_PRIVATE
39 if (pWin->drawable.bitsPerPixel == 32)
40 pWin->drawable.bitsPerPixel = fbGetScreenPrivate(pWin->drawable.pScreen)->win32bpp;
41 #endif
42 return TRUE;
45 Bool
46 fbDestroyWindow(WindowPtr pWin)
48 return TRUE;
51 Bool
52 fbMapWindow(WindowPtr pWindow)
54 return TRUE;
57 Bool
58 fbPositionWindow(WindowPtr pWin, int x, int y)
60 return TRUE;
63 Bool
64 fbUnmapWindow(WindowPtr pWindow)
66 return TRUE;
69 void
70 fbCopyWindowProc (DrawablePtr pSrcDrawable,
71 DrawablePtr pDstDrawable,
72 GCPtr pGC,
73 BoxPtr pbox,
74 int nbox,
75 int dx,
76 int dy,
77 Bool reverse,
78 Bool upsidedown,
79 Pixel bitplane,
80 void *closure)
82 FbBits *src;
83 FbStride srcStride;
84 int srcBpp;
85 int srcXoff, srcYoff;
86 FbBits *dst;
87 FbStride dstStride;
88 int dstBpp;
89 int dstXoff, dstYoff;
91 fbGetDrawable (pSrcDrawable, src, srcStride, srcBpp, srcXoff, srcYoff);
92 fbGetDrawable (pDstDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
94 while (nbox--)
96 fbBlt (src + (pbox->y1 + dy + srcYoff) * srcStride,
97 srcStride,
98 (pbox->x1 + dx + srcXoff) * srcBpp,
100 dst + (pbox->y1 + dstYoff) * dstStride,
101 dstStride,
102 (pbox->x1 + dstXoff) * dstBpp,
104 (pbox->x2 - pbox->x1) * dstBpp,
105 (pbox->y2 - pbox->y1),
107 GXcopy,
108 FB_ALLONES,
109 dstBpp,
111 reverse,
112 upsidedown);
113 pbox++;
116 fbFinishAccess (pDstDrawable);
117 fbFinishAccess (pSrcDrawable);
120 void
121 fbCopyWindow(WindowPtr pWin,
122 DDXPointRec ptOldOrg,
123 RegionPtr prgnSrc)
125 RegionRec rgnDst;
126 int dx, dy;
128 PixmapPtr pPixmap = fbGetWindowPixmap (pWin);
129 DrawablePtr pDrawable = &pPixmap->drawable;
131 dx = ptOldOrg.x - pWin->drawable.x;
132 dy = ptOldOrg.y - pWin->drawable.y;
133 REGION_TRANSLATE(pWin->drawable.pScreen, prgnSrc, -dx, -dy);
135 REGION_NULL (pWin->drawable.pScreen, &rgnDst);
137 REGION_INTERSECT(pWin->drawable.pScreen, &rgnDst, &pWin->borderClip, prgnSrc);
139 #ifdef COMPOSITE
140 if (pPixmap->screen_x || pPixmap->screen_y)
141 REGION_TRANSLATE (pWin->drawable.pScreen, &rgnDst,
142 -pPixmap->screen_x, -pPixmap->screen_y);
143 #endif
145 fbCopyRegion (pDrawable, pDrawable,
147 &rgnDst, dx, dy, fbCopyWindowProc, 0, 0);
149 REGION_UNINIT(pWin->drawable.pScreen, &rgnDst);
150 fbValidateDrawable (&pWin->drawable);
153 Bool
154 fbChangeWindowAttributes(WindowPtr pWin, unsigned long mask)
156 PixmapPtr pPixmap;
158 if (mask & CWBackPixmap)
160 if (pWin->backgroundState == BackgroundPixmap)
162 pPixmap = pWin->background.pixmap;
163 #ifdef FB_24_32BIT
164 if (pPixmap->drawable.bitsPerPixel != pWin->drawable.bitsPerPixel)
166 pPixmap = fb24_32ReformatTile (pPixmap,
167 pWin->drawable.bitsPerPixel);
168 if (pPixmap)
170 (*pWin->drawable.pScreen->DestroyPixmap) (pWin->background.pixmap);
171 pWin->background.pixmap = pPixmap;
174 #endif
175 if (FbEvenTile (pPixmap->drawable.width *
176 pPixmap->drawable.bitsPerPixel))
177 fbPadPixmap (pPixmap);
180 if (mask & CWBorderPixmap)
182 if (pWin->borderIsPixel == FALSE)
184 pPixmap = pWin->border.pixmap;
185 #ifdef FB_24_32BIT
186 if (pPixmap->drawable.bitsPerPixel !=
187 pWin->drawable.bitsPerPixel)
189 pPixmap = fb24_32ReformatTile (pPixmap,
190 pWin->drawable.bitsPerPixel);
191 if (pPixmap)
193 (*pWin->drawable.pScreen->DestroyPixmap) (pWin->border.pixmap);
194 pWin->border.pixmap = pPixmap;
197 #endif
198 if (FbEvenTile (pPixmap->drawable.width *
199 pPixmap->drawable.bitsPerPixel))
200 fbPadPixmap (pPixmap);
203 return TRUE;
206 void
207 fbFillRegionSolid (DrawablePtr pDrawable,
208 RegionPtr pRegion,
209 FbBits and,
210 FbBits xor)
212 FbBits *dst;
213 FbStride dstStride;
214 int dstBpp;
215 int dstXoff, dstYoff;
216 int n = REGION_NUM_RECTS(pRegion);
217 BoxPtr pbox = REGION_RECTS(pRegion);
219 #ifndef FB_ACCESS_WRAPPER
220 int try_mmx = 0;
221 if (!and)
222 try_mmx = 1;
223 #endif
225 fbGetDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
227 while (n--)
229 #ifndef FB_ACCESS_WRAPPER
230 if (!try_mmx || !pixman_fill (dst, dstStride, dstBpp,
231 pbox->x1 + dstXoff, pbox->y1 + dstYoff,
232 (pbox->x2 - pbox->x1),
233 (pbox->y2 - pbox->y1),
234 xor))
236 #endif
237 fbSolid (dst + (pbox->y1 + dstYoff) * dstStride,
238 dstStride,
239 (pbox->x1 + dstXoff) * dstBpp,
240 dstBpp,
241 (pbox->x2 - pbox->x1) * dstBpp,
242 pbox->y2 - pbox->y1,
243 and, xor);
244 #ifndef FB_ACCESS_WRAPPER
246 #endif
247 fbValidateDrawable (pDrawable);
248 pbox++;
251 fbFinishAccess (pDrawable);
254 #ifdef PANORAMIX
255 #include "panoramiX.h"
256 #include "panoramiXsrv.h"
257 #endif
259 void
260 fbFillRegionTiled (DrawablePtr pDrawable,
261 RegionPtr pRegion,
262 PixmapPtr pTile)
264 FbBits *dst;
265 FbStride dstStride;
266 int dstBpp;
267 int dstXoff, dstYoff;
268 FbBits *tile;
269 FbStride tileStride;
270 int tileBpp;
271 int tileXoff, tileYoff; /* XXX assumed to be zero */
272 int tileWidth, tileHeight;
273 int n = REGION_NUM_RECTS(pRegion);
274 BoxPtr pbox = REGION_RECTS(pRegion);
275 int xRot = pDrawable->x;
276 int yRot = pDrawable->y;
278 #ifdef PANORAMIX
279 if(!noPanoramiXExtension)
281 int index = pDrawable->pScreen->myNum;
282 if(&WindowTable[index]->drawable == pDrawable)
284 xRot -= panoramiXdataPtr[index].x;
285 yRot -= panoramiXdataPtr[index].y;
288 #endif
289 fbGetDrawable (pDrawable, dst, dstStride, dstBpp, dstXoff, dstYoff);
290 fbGetDrawable (&pTile->drawable, tile, tileStride, tileBpp, tileXoff, tileYoff);
291 tileWidth = pTile->drawable.width;
292 tileHeight = pTile->drawable.height;
293 xRot += dstXoff;
294 yRot += dstYoff;
296 while (n--)
298 fbTile (dst + (pbox->y1 + dstYoff) * dstStride,
299 dstStride,
300 (pbox->x1 + dstXoff) * dstBpp,
301 (pbox->x2 - pbox->x1) * dstBpp,
302 pbox->y2 - pbox->y1,
303 tile,
304 tileStride,
305 tileWidth * dstBpp,
306 tileHeight,
307 GXcopy,
308 FB_ALLONES,
309 dstBpp,
310 xRot * dstBpp,
311 yRot - (pbox->y1 + dstYoff));
312 pbox++;
315 fbFinishAccess (&pTile->drawable);
316 fbFinishAccess (pDrawable);
319 void
320 fbPaintWindow(WindowPtr pWin, RegionPtr pRegion, int what)
322 WindowPtr pBgWin;
324 switch (what) {
325 case PW_BACKGROUND:
326 switch (pWin->backgroundState) {
327 case None:
328 break;
329 case ParentRelative:
330 do {
331 pWin = pWin->parent;
332 } while (pWin->backgroundState == ParentRelative);
333 (*pWin->drawable.pScreen->PaintWindowBackground)(pWin, pRegion,
334 what);
335 break;
336 case BackgroundPixmap:
337 fbFillRegionTiled (&pWin->drawable,
338 pRegion,
339 pWin->background.pixmap);
340 break;
341 case BackgroundPixel:
342 fbFillRegionSolid (&pWin->drawable,
343 pRegion,
345 fbReplicatePixel (pWin->background.pixel,
346 pWin->drawable.bitsPerPixel));
347 break;
349 break;
350 case PW_BORDER:
351 if (pWin->borderIsPixel)
353 fbFillRegionSolid (&pWin->drawable,
354 pRegion,
356 fbReplicatePixel (pWin->border.pixel,
357 pWin->drawable.bitsPerPixel));
359 else
361 for (pBgWin = pWin;
362 pBgWin->backgroundState == ParentRelative;
363 pBgWin = pBgWin->parent);
365 fbFillRegionTiled (&pBgWin->drawable,
366 pRegion,
367 pWin->border.pixmap);
369 break;
371 fbValidateDrawable (&pWin->drawable);