1706f2543Smrg/***********************************************************
2706f2543Smrg
3706f2543SmrgCopyright 1987, 1998  The Open Group
4706f2543Smrg
5706f2543SmrgPermission to use, copy, modify, distribute, and sell this software and its
6706f2543Smrgdocumentation for any purpose is hereby granted without fee, provided that
7706f2543Smrgthe above copyright notice appear in all copies and that both that
8706f2543Smrgcopyright notice and this permission notice appear in supporting
9706f2543Smrgdocumentation.
10706f2543Smrg
11706f2543SmrgThe above copyright notice and this permission notice shall be included in
12706f2543Smrgall copies or substantial portions of the Software.
13706f2543Smrg
14706f2543SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15706f2543SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16706f2543SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17706f2543SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18706f2543SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19706f2543SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20706f2543Smrg
21706f2543SmrgExcept as contained in this notice, the name of The Open Group shall not be
22706f2543Smrgused in advertising or otherwise to promote the sale, use or other dealings
23706f2543Smrgin this Software without prior written authorization from The Open Group.
24706f2543Smrg
25706f2543Smrg
26706f2543SmrgCopyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts.
27706f2543Smrg
28706f2543Smrg                        All Rights Reserved
29706f2543Smrg
30706f2543SmrgPermission to use, copy, modify, and distribute this software and its
31706f2543Smrgdocumentation for any purpose and without fee is hereby granted,
32706f2543Smrgprovided that the above copyright notice appear in all copies and that
33706f2543Smrgboth that copyright notice and this permission notice appear in
34706f2543Smrgsupporting documentation, and that the name of Digital not be
35706f2543Smrgused in advertising or publicity pertaining to distribution of the
36706f2543Smrgsoftware without specific, written prior permission.
37706f2543Smrg
38706f2543SmrgDIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
39706f2543SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
40706f2543SmrgDIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
41706f2543SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
42706f2543SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
43706f2543SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44706f2543SmrgSOFTWARE.
45706f2543Smrg
46706f2543Smrg******************************************************************/
47706f2543Smrg
48706f2543Smrg#ifndef SERVERMD_H
49706f2543Smrg#define SERVERMD_H 1
50706f2543Smrg
51706f2543Smrg/*
52706f2543Smrg * Note: much of this is vestigial from mfb/cfb times.  This should
53706f2543Smrg * really be simplified even further.
54706f2543Smrg */
55706f2543Smrg
56706f2543Smrg/*
57706f2543Smrg * Machine dependent values:
58706f2543Smrg * GLYPHPADBYTES should be chosen with consideration for the space-time
59706f2543Smrg * trade-off.  Padding to 0 bytes means that there is no wasted space
60706f2543Smrg * in the font bitmaps (both on disk and in memory), but that access of
61706f2543Smrg * the bitmaps will cause odd-address memory references.  Padding to
62706f2543Smrg * 2 bytes would ensure even address memory references and would
63706f2543Smrg * be suitable for a 68010-class machine, but at the expense of wasted
64706f2543Smrg * space in the font bitmaps.  Padding to 4 bytes would be good
65706f2543Smrg * for real 32 bit machines, etc.  Be sure that you tell the font
66706f2543Smrg * compiler what kind of padding you want because its defines are
67706f2543Smrg * kept separate from this.  See server/include/font.h for how
68706f2543Smrg * GLYPHPADBYTES is used.
69706f2543Smrg */
70706f2543Smrg
71706f2543Smrg#if defined(vax) || defined(__vax__)
72706f2543Smrg#define IMAGE_BYTE_ORDER	LSBFirst        /* Values for the VAX only */
73706f2543Smrg#define BITMAP_BIT_ORDER	LSBFirst
74706f2543Smrg#define	GLYPHPADBYTES		4
75706f2543Smrg#define GETLEFTBITS_ALIGNMENT	1
76706f2543Smrg#define FAST_UNALIGNED_READS
77706f2543Smrg#endif /* __vax__ */
78706f2543Smrg
79706f2543Smrg#ifdef __avr32__
80706f2543Smrg#define IMAGE_BYTE_ORDER        MSBFirst
81706f2543Smrg#define BITMAP_BIT_ORDER        MSBFirst
82706f2543Smrg#define GLYPHPADBYTES           4
83706f2543Smrg
84706f2543Smrg#endif /* __avr32__ */
85706f2543Smrg
86706f2543Smrg#if defined(__arm32__) || defined(__arm__)
87706f2543Smrg
88706f2543Smrg#ifdef __ARMEB__
89706f2543Smrg#define IMAGE_BYTE_ORDER        MSBFirst
90706f2543Smrg#define BITMAP_BIT_ORDER        MSBFirst
91706f2543Smrg#else
92706f2543Smrg#define IMAGE_BYTE_ORDER        LSBFirst
93706f2543Smrg#define BITMAP_BIT_ORDER        LSBFirst
94706f2543Smrg#endif
95706f2543Smrg#define GLYPHPADBYTES           4
96706f2543Smrg
97706f2543Smrg#endif /* __arm32__ */
98706f2543Smrg
99706f2543Smrg#if defined(__nds32__)
100706f2543Smrg
101706f2543Smrg#define IMAGE_BYTE_ORDER	LSBFirst
102706f2543Smrg
103706f2543Smrg#if defined(XF86MONOVGA) || defined(XF86VGA16) || defined(XF86MONO)
104706f2543Smrg# define BITMAP_BIT_ORDER	MSBFirst
105706f2543Smrg#else
106706f2543Smrg# define BITMAP_BIT_ORDER	LSBFirst
107706f2543Smrg#endif
108706f2543Smrg
109706f2543Smrg#if defined(XF86MONOVGA) || defined(XF86VGA16)
110706f2543Smrg# define BITMAP_SCANLINE_UNIT	8
111706f2543Smrg#endif
112706f2543Smrg
113706f2543Smrg#define GLYPHPADBYTES		4
114706f2543Smrg#define GETLEFTBITS_ALIGNMENT	1
115706f2543Smrg#define LARGE_INSTRUCTION_CACHE
116706f2543Smrg#define AVOID_MEMORY_READ
117706f2543Smrg
118706f2543Smrg#endif /* __nds32__ */
119706f2543Smrg
120706f2543Smrg#if defined __hppa__
121706f2543Smrg
122706f2543Smrg#define IMAGE_BYTE_ORDER	MSBFirst
123706f2543Smrg#define BITMAP_BIT_ORDER	MSBFirst
124706f2543Smrg#define GLYPHPADBYTES		4	/* to make fb work */
125706f2543Smrg					/* byte boundries */
126706f2543Smrg#endif /* hpux || __hppa__ */
127706f2543Smrg
128706f2543Smrg#if defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__)
129706f2543Smrg
130706f2543Smrg#define IMAGE_BYTE_ORDER        MSBFirst
131706f2543Smrg#define BITMAP_BIT_ORDER        MSBFirst
132706f2543Smrg#define GLYPHPADBYTES           4
133706f2543Smrg
134706f2543Smrg#endif /* PowerPC */
135706f2543Smrg
136706f2543Smrg#if defined(__sh__)
137706f2543Smrg
138706f2543Smrg#if defined(__BIG_ENDIAN__)
139706f2543Smrg# define IMAGE_BYTE_ORDER	MSBFirst
140706f2543Smrg# define BITMAP_BIT_ORDER	MSBFirst
141706f2543Smrg# define GLYPHPADBYTES		4
142706f2543Smrg#else
143706f2543Smrg# define IMAGE_BYTE_ORDER	LSBFirst
144706f2543Smrg# define BITMAP_BIT_ORDER	LSBFirst
145706f2543Smrg# define GLYPHPADBYTES		4
146706f2543Smrg#endif
147706f2543Smrg
148706f2543Smrg#endif /* SuperH */
149706f2543Smrg
150706f2543Smrg#if defined(__m32r__)
151706f2543Smrg
152706f2543Smrg#if defined(__BIG_ENDIAN__)
153706f2543Smrg# define IMAGE_BYTE_ORDER      MSBFirst
154706f2543Smrg# define BITMAP_BIT_ORDER      MSBFirst
155706f2543Smrg# define GLYPHPADBYTES         4
156706f2543Smrg#else
157706f2543Smrg# define IMAGE_BYTE_ORDER      LSBFirst
158706f2543Smrg# define BITMAP_BIT_ORDER      LSBFirst
159706f2543Smrg# define GLYPHPADBYTES         4
160706f2543Smrg#endif
161706f2543Smrg
162706f2543Smrg#endif /* __m32r__ */
163706f2543Smrg
164706f2543Smrg#if (defined(sun) && (defined(__sparc) || defined(sparc))) || \
165706f2543Smrg    (defined(__uxp__) && (defined(sparc) || defined(mc68000))) || \
166706f2543Smrg    defined(__sparc__) || defined(__mc68000__)
167706f2543Smrg
168706f2543Smrg#if defined(__sparc) || defined(__sparc__)
169706f2543Smrg# if !defined(sparc)
170706f2543Smrg#  define sparc 1
171706f2543Smrg# endif
172706f2543Smrg#endif
173706f2543Smrg
174706f2543Smrg#if defined(sun386) || defined(sun5)
175706f2543Smrg# define IMAGE_BYTE_ORDER	LSBFirst        /* Values for the SUN only */
176706f2543Smrg# define BITMAP_BIT_ORDER	LSBFirst
177706f2543Smrg#else
178706f2543Smrg# define IMAGE_BYTE_ORDER	MSBFirst        /* Values for the SUN only */
179706f2543Smrg# define BITMAP_BIT_ORDER	MSBFirst
180706f2543Smrg#endif
181706f2543Smrg
182706f2543Smrg#define	GLYPHPADBYTES		4
183706f2543Smrg
184706f2543Smrg#endif /* sun && !(i386 && SVR4) */
185706f2543Smrg
186706f2543Smrg
187706f2543Smrg#if defined(ibm032) || defined (ibm)
188706f2543Smrg
189706f2543Smrg#ifdef __i386__
190706f2543Smrg# define IMAGE_BYTE_ORDER	LSBFirst	/* Value for PS/2 only */
191706f2543Smrg#else
192706f2543Smrg# define IMAGE_BYTE_ORDER	MSBFirst        /* Values for the RT only*/
193706f2543Smrg#endif
194706f2543Smrg#define BITMAP_BIT_ORDER	MSBFirst
195706f2543Smrg#define	GLYPHPADBYTES		1
196706f2543Smrg/* ibm pcc doesn't understand pragmas. */
197706f2543Smrg
198706f2543Smrg#ifdef __i386__
199706f2543Smrg#define BITMAP_SCANLINE_UNIT	8
200706f2543Smrg#endif
201706f2543Smrg
202706f2543Smrg#endif /* ibm */
203706f2543Smrg
204706f2543Smrg#if (defined(mips) || defined(__mips))
205706f2543Smrg
206706f2543Smrg#if defined(MIPSEL) || defined(__MIPSEL__)
207706f2543Smrg# define IMAGE_BYTE_ORDER	LSBFirst        /* Values for the PMAX only */
208706f2543Smrg# define BITMAP_BIT_ORDER	LSBFirst
209706f2543Smrg# define GLYPHPADBYTES		4
210706f2543Smrg#else
211706f2543Smrg# define IMAGE_BYTE_ORDER	MSBFirst        /* Values for the MIPS only */
212706f2543Smrg# define BITMAP_BIT_ORDER	MSBFirst
213706f2543Smrg# define GLYPHPADBYTES		4
214706f2543Smrg#endif
215706f2543Smrg
216706f2543Smrg#endif /* mips */
217706f2543Smrg
218706f2543Smrg#if defined(__alpha) || defined(__alpha__)
219706f2543Smrg# define IMAGE_BYTE_ORDER	LSBFirst	/* Values for the Alpha only */
220706f2543Smrg# define BITMAP_BIT_ORDER       LSBFirst
221706f2543Smrg# define GLYPHPADBYTES		4
222706f2543Smrg
223706f2543Smrg#endif /* alpha */
224706f2543Smrg
225706f2543Smrg#if defined (linux) && defined (__s390__)
226706f2543Smrg
227706f2543Smrg#define IMAGE_BYTE_ORDER      	MSBFirst
228706f2543Smrg#define BITMAP_BIT_ORDER      	MSBFirst
229706f2543Smrg#define GLYPHPADBYTES         	4
230706f2543Smrg
231706f2543Smrg#define BITMAP_SCANLINE_UNIT	8
232706f2543Smrg#define FAST_UNALIGNED_READ
233706f2543Smrg
234706f2543Smrg#endif /* linux/s390 */
235706f2543Smrg
236706f2543Smrg#if defined (linux) && defined (__s390x__)
237706f2543Smrg
238706f2543Smrg#define IMAGE_BYTE_ORDER       MSBFirst
239706f2543Smrg#define BITMAP_BIT_ORDER       MSBFirst
240706f2543Smrg#define GLYPHPADBYTES          4
241706f2543Smrg
242706f2543Smrg#define BITMAP_SCANLINE_UNIT	8
243706f2543Smrg#define FAST_UNALIGNED_READ
244706f2543Smrg
245706f2543Smrg#endif /* linux/s390x */
246706f2543Smrg
247706f2543Smrg
248706f2543Smrg#if defined(__ia64__) || defined(ia64)
249706f2543Smrg
250706f2543Smrg# define IMAGE_BYTE_ORDER	LSBFirst
251706f2543Smrg# define BITMAP_BIT_ORDER       LSBFirst
252706f2543Smrg# define GLYPHPADBYTES		4
253706f2543Smrg
254706f2543Smrg#endif /* ia64 */
255706f2543Smrg
256706f2543Smrg#if defined(__amd64__) || defined(amd64) || defined(__amd64)
257706f2543Smrg# define IMAGE_BYTE_ORDER	LSBFirst
258706f2543Smrg# define BITMAP_BIT_ORDER       LSBFirst
259706f2543Smrg# define GLYPHPADBYTES		4
260706f2543Smrg/* ???? */
261706f2543Smrg#endif /* AMD64 */
262706f2543Smrg
263706f2543Smrg#if	defined(SVR4) && (defined(__i386__) || defined(__i386) ) ||	\
264706f2543Smrg	defined(__alpha__) || defined(__alpha) || \
265706f2543Smrg	defined(__i386__) || \
266706f2543Smrg	defined(__s390x__) || defined(__s390__)
267706f2543Smrg
268706f2543Smrg#ifndef IMAGE_BYTE_ORDER
269706f2543Smrg#define IMAGE_BYTE_ORDER	LSBFirst
270706f2543Smrg#endif
271706f2543Smrg
272706f2543Smrg#ifndef BITMAP_BIT_ORDER
273706f2543Smrg# define BITMAP_BIT_ORDER      LSBFirst
274706f2543Smrg#endif
275706f2543Smrg
276706f2543Smrg#ifndef GLYPHPADBYTES
277706f2543Smrg#define GLYPHPADBYTES           4
278706f2543Smrg#endif
279706f2543Smrg
280706f2543Smrg#endif /* SVR4 / BSD / i386 */
281706f2543Smrg
282706f2543Smrg#if defined (linux) && defined (__mc68000__)
283706f2543Smrg
284706f2543Smrg#define IMAGE_BYTE_ORDER       MSBFirst
285706f2543Smrg#define BITMAP_BIT_ORDER       MSBFirst
286706f2543Smrg#define GLYPHPADBYTES          4
287706f2543Smrg
288706f2543Smrg#endif /* linux/m68k */
289706f2543Smrg
290706f2543Smrg
291706f2543Smrg/* linux on ARM */
292706f2543Smrg#if defined(linux) && defined(__arm__)
293706f2543Smrg#define IMAGE_BYTE_ORDER	LSBFirst
294706f2543Smrg#define BITMAP_BIT_ORDER	LSBFirst
295706f2543Smrg#define GLYPHPADBYTES		4
296706f2543Smrg#endif
297706f2543Smrg
298706f2543Smrg/* linux on IBM S/390 */
299706f2543Smrg#if defined (linux) && defined (__s390__)
300706f2543Smrg#define IMAGE_BYTE_ORDER	MSBFirst
301706f2543Smrg#define BITMAP_BIT_ORDER	MSBFirst
302706f2543Smrg#define GLYPHPADBYTES		4
303706f2543Smrg#endif /* linux/s390 */
304706f2543Smrg
305706f2543Smrg/* size of buffer to use with GetImage, measured in bytes. There's obviously
306706f2543Smrg * a trade-off between the amount of heap used and the number of times the
307706f2543Smrg * ddx routine has to be called.
308706f2543Smrg */
309706f2543Smrg#ifndef IMAGE_BUFSIZE
310706f2543Smrg#define IMAGE_BUFSIZE		(64*1024)
311706f2543Smrg#endif
312706f2543Smrg
313706f2543Smrg/* pad scanline to a longword */
314706f2543Smrg#ifndef BITMAP_SCANLINE_UNIT
315706f2543Smrg#define BITMAP_SCANLINE_UNIT	32
316706f2543Smrg#endif
317706f2543Smrg
318706f2543Smrg#ifndef BITMAP_SCANLINE_PAD
319706f2543Smrg#define BITMAP_SCANLINE_PAD  32
320706f2543Smrg#define LOG2_BITMAP_PAD		5
321706f2543Smrg#define LOG2_BYTES_PER_SCANLINE_PAD	2
322706f2543Smrg#endif
323706f2543Smrg
324706f2543Smrg#include <X11/Xfuncproto.h>
325706f2543Smrg/*
326706f2543Smrg *   This returns the number of padding units, for depth d and width w.
327706f2543Smrg * For bitmaps this can be calculated with the macros above.
328706f2543Smrg * Other depths require either grovelling over the formats field of the
329706f2543Smrg * screenInfo or hardwired constants.
330706f2543Smrg */
331706f2543Smrg
332706f2543Smrgtypedef struct _PaddingInfo {
333706f2543Smrg	int     padRoundUp;	/* pixels per pad unit - 1 */
334706f2543Smrg	int	padPixelsLog2;	/* log 2 (pixels per pad unit) */
335706f2543Smrg	int     padBytesLog2;	/* log 2 (bytes per pad unit) */
336706f2543Smrg	int	notPower2;	/* bitsPerPixel not a power of 2 */
337706f2543Smrg	int	bytesPerPixel;	/* only set when notPower2 is TRUE */
338706f2543Smrg	int	bitsPerPixel;	/* bits per pixel */
339706f2543Smrg} PaddingInfo;
340706f2543Smrgextern _X_EXPORT PaddingInfo PixmapWidthPaddingInfo[];
341706f2543Smrg
342706f2543Smrg/* The only portable way to get the bpp from the depth is to look it up */
343706f2543Smrg#define BitsPerPixel(d) (PixmapWidthPaddingInfo[d].bitsPerPixel)
344706f2543Smrg
345706f2543Smrg#define PixmapWidthInPadUnits(w, d) \
346706f2543Smrg    (PixmapWidthPaddingInfo[d].notPower2 ? \
347706f2543Smrg    (((int)(w) * PixmapWidthPaddingInfo[d].bytesPerPixel +  \
348706f2543Smrg	         PixmapWidthPaddingInfo[d].bytesPerPixel) >> \
349706f2543Smrg	PixmapWidthPaddingInfo[d].padBytesLog2) : \
350706f2543Smrg    ((int)((w) + PixmapWidthPaddingInfo[d].padRoundUp) >> \
351706f2543Smrg	PixmapWidthPaddingInfo[d].padPixelsLog2))
352706f2543Smrg
353706f2543Smrg/*
354706f2543Smrg *	Return the number of bytes to which a scanline of the given
355706f2543Smrg * depth and width will be padded.
356706f2543Smrg */
357706f2543Smrg#define PixmapBytePad(w, d) \
358706f2543Smrg    (PixmapWidthInPadUnits(w, d) << PixmapWidthPaddingInfo[d].padBytesLog2)
359706f2543Smrg
360706f2543Smrg#define BitmapBytePad(w) \
361706f2543Smrg    (((int)((w) + BITMAP_SCANLINE_PAD - 1) >> LOG2_BITMAP_PAD) << LOG2_BYTES_PER_SCANLINE_PAD)
362706f2543Smrg
363706f2543Smrg#define PixmapWidthInPadUnitsProto(w, d) PixmapWidthInPadUnits(w, d)
364706f2543Smrg#define PixmapBytePadProto(w, d) PixmapBytePad(w, d)
365706f2543Smrg#define BitmapBytePadProto(w) BitmapBytePad(w)
366706f2543Smrg
367706f2543Smrg#endif /* SERVERMD_H */
368