First import
[xorg_rtime.git] / xorg-server-1.4 / miext / shadow / shrotpack.h
blob015a98595060948f609925a0255670b9c7695869
1 /*
3 * Copyright © 2000 Keith Packard
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, and that the name of Keith Packard not be used in
10 * advertising or publicity pertaining to distribution of the software without
11 * specific, written prior permission. Keith Packard makes no
12 * representations about the suitability of this software for any purpose. It
13 * is provided "as is" without express or implied warranty.
15 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
17 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
19 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
20 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
21 * PERFORMANCE OF THIS SOFTWARE.
25 * Thanks to Daniel Chemko <dchemko@intrinsyc.com> for making the 90 and 180
26 * orientations work.
29 #ifdef HAVE_DIX_CONFIG_H
30 #include <dix-config.h>
31 #endif
33 #include <stdlib.h>
35 #include <X11/X.h>
36 #include "scrnintstr.h"
37 #include "windowstr.h"
38 #include <X11/fonts/font.h>
39 #include "dixfontstr.h"
40 #include <X11/fonts/fontstruct.h>
41 #include "mi.h"
42 #include "regionstr.h"
43 #include "globals.h"
44 #include "gcstruct.h"
45 #include "shadow.h"
46 #include "fb.h"
48 #define DANDEBUG 0
50 #if ROTATE == 270
52 #define SCRLEFT(x,y,w,h) (pScreen->height - ((y) + (h)))
53 #define SCRY(x,y,w,h) (x)
54 #define SCRWIDTH(x,y,w,h) (h)
55 #define FIRSTSHA(x,y,w,h) (((y) + (h) - 1) * shaStride + (x))
56 #define STEPDOWN(x,y,w,h) ((w)--)
57 #define NEXTY(x,y,w,h) ((x)++)
58 #define SHASTEPX(stride) -(stride)
59 #define SHASTEPY(stride) (1)
61 #elif ROTATE == 90
63 #define SCRLEFT(x,y,w,h) (y)
64 #define SCRY(x,y,w,h) (pScreen->width - ((x) + (w)) - 1)
65 #define SCRWIDTH(x,y,w,h) (h)
66 #define FIRSTSHA(x,y,w,h) ((y) * shaStride + (x + w - 1))
67 #define STEPDOWN(x,y,w,h) ((w)--)
68 #define NEXTY(x,y,w,h) ((void)(x))
69 #define SHASTEPX(stride) (stride)
70 #define SHASTEPY(stride) (-1)
72 #elif ROTATE == 180
74 #define SCRLEFT(x,y,w,h) (pScreen->width - ((x) + (w)))
75 #define SCRY(x,y,w,h) (pScreen->height - ((y) + (h)) - 1)
76 #define SCRWIDTH(x,y,w,h) (w)
77 #define FIRSTSHA(x,y,w,h) ((y + h - 1) * shaStride + (x + w - 1))
78 #define STEPDOWN(x,y,w,h) ((h)--)
79 #define NEXTY(x,y,w,h) ((void)(y))
80 #define SHASTEPX(stride) (-1)
81 #define SHASTEPY(stride) -(stride)
83 #else
85 #define SCRLEFT(x,y,w,h) (x)
86 #define SCRY(x,y,w,h) (y)
87 #define SCRWIDTH(x,y,w,h) (w)
88 #define FIRSTSHA(x,y,w,h) ((y) * shaStride + (x))
89 #define STEPDOWN(x,y,w,h) ((h)--)
90 #define NEXTY(x,y,w,h) ((y)++)
91 #define SHASTEPX(stride) (1)
92 #define SHASTEPY(stride) (stride)
94 #endif
96 void
97 FUNC (ScreenPtr pScreen,
98 shadowBufPtr pBuf)
100 RegionPtr damage = shadowDamage (pBuf);
101 PixmapPtr pShadow = pBuf->pPixmap;
102 int nbox = REGION_NUM_RECTS (damage);
103 BoxPtr pbox = REGION_RECTS (damage);
104 FbBits *shaBits;
105 Data *shaBase, *shaLine, *sha;
106 FbStride shaStride;
107 int scrBase, scrLine, scr;
108 int shaBpp;
109 int shaXoff, shaYoff; /* XXX assumed to be zero */
110 int x, y, w, h, width;
111 int i;
112 Data *winBase = NULL, *win;
113 CARD32 winSize;
115 fbGetDrawable (&pShadow->drawable, shaBits, shaStride, shaBpp, shaXoff, shaYoff);
116 shaBase = (Data *) shaBits;
117 shaStride = shaStride * sizeof (FbBits) / sizeof (Data);
118 #if (DANDEBUG > 1)
119 ErrorF ("-> Entering Shadow Update:\r\n |- Origins: pShadow=%x, pScreen=%x, damage=%x\r\n |- Metrics: shaStride=%d, shaBase=%x, shaBpp=%d\r\n | \n", pShadow, pScreen, damage, shaStride, shaBase, shaBpp);
120 #endif
121 while (nbox--)
123 x = pbox->x1;
124 y = pbox->y1;
125 w = (pbox->x2 - pbox->x1);
126 h = pbox->y2 - pbox->y1;
128 #if (DANDEBUG > 2)
129 ErrorF (" |-> Redrawing box - Metrics: X=%d, Y=%d, Width=%d, Height=%d\n", x, y, w, h);
130 #endif
131 scrLine = SCRLEFT(x,y,w,h);
132 shaLine = shaBase + FIRSTSHA(x,y,w,h);
134 while (STEPDOWN(x,y,w,h))
136 winSize = 0;
137 scrBase = 0;
138 width = SCRWIDTH(x,y,w,h);
139 scr = scrLine;
140 sha = shaLine;
141 #if (DANDEBUG > 3)
142 ErrorF (" | |-> StepDown - Metrics: width=%d, scr=%x, sha=%x\n", width, scr, sha);
143 #endif
144 while (width)
146 /* how much remains in this window */
147 i = scrBase + winSize - scr;
148 if (i <= 0 || scr < scrBase)
150 winBase = (Data *) (*pBuf->window) (pScreen,
151 SCRY(x,y,w,h),
152 scr * sizeof (Data),
153 SHADOW_WINDOW_WRITE,
154 &winSize,
155 pBuf->closure);
156 if(!winBase)
157 return;
158 scrBase = scr;
159 winSize /= sizeof (Data);
160 i = winSize;
161 #if(DANDEBUG > 4)
162 ErrorF (" | | |-> Starting New Line - Metrics: winBase=%x, scrBase=%x, winSize=%d\r\n | | | Xstride=%d, Ystride=%d, w=%d h=%d\n", winBase, scrBase, winSize, SHASTEPX(shaStride), SHASTEPY(shaStride), w, h);
163 #endif
165 win = winBase + (scr - scrBase);
166 if (i > width)
167 i = width;
168 width -= i;
169 scr += i;
170 #if(DANDEBUG > 5)
171 ErrorF (" | | |-> Writing Line - Metrics: win=%x, sha=%x\n", win, sha);
172 #endif
173 while (i--)
175 #if(DANDEBUG > 6)
176 ErrorF (" | | |-> Writing Pixel - Metrics: win=%x, sha=%d, remaining=%d\n", win, sha, i);
177 #endif
178 *win++ = *sha;
179 sha += SHASTEPX(shaStride);
180 } /* i */
181 } /* width */
182 shaLine += SHASTEPY(shaStride);
183 NEXTY(x,y,w,h);
184 } /* STEPDOWN */
185 pbox++;
186 } /* nbox */