VirtualBox

source: vbox/trunk/src/VBox/Additions/x11/x11include/xorg-server-1.1.0/cfbmskbits.h@ 68495

Last change on this file since 68495 was 51223, checked in by vboxsync, 11 years ago

Additions/x11/x11include: added header files for X.Org Server 1.0 and 1.1.

  • Property svn:eol-style set to native
File size: 27.2 KB
Line 
1/* $XFree86: xc/programs/Xserver/cfb/cfbmskbits.h,v 3.13tsi Exp $ */
2/************************************************************
3Copyright 1987 by Sun Microsystems, Inc. Mountain View, CA.
4
5 All Rights Reserved
6
7Permission to use, copy, modify, and distribute this
8software and its documentation for any purpose and without
9fee is hereby granted, provided that the above copyright no-
10tice appear in all copies and that both that copyright no-
11tice and this permission notice appear in supporting docu-
12mentation, and that the names of Sun or The Open Group
13not be used in advertising or publicity pertaining to
14distribution of the software without specific prior
15written permission. Sun and The Open Group make no
16representations about the suitability of this software for
17any purpose. It is provided "as is" without any express or
18implied warranty.
19
20SUN DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
21INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FIT-
22NESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SUN BE LI-
23ABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
24ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
25PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
26OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
27THE USE OR PERFORMANCE OF THIS SOFTWARE.
28
29********************************************************/
30
31/* $Xorg: cfbmskbits.h,v 1.3 2000/08/17 19:48:14 cpqbld Exp $ */
32/* Optimizations for PSZ == 32 added by Kyle Marvin ([email protected]) */
33
34#include <X11/X.h>
35#include <X11/Xmd.h>
36#include "servermd.h"
37#if defined(XFREE86) || ( defined(__OpenBSD__) && defined(__alpha__) ) \
38 || (defined(__bsdi__))
39#include "compiler.h"
40#endif
41
42/*
43 * ==========================================================================
44 * Converted from mfb to support memory-mapped color framebuffer by smarks@sun,
45 * April-May 1987.
46 *
47 * The way I did the conversion was to consider each longword as an
48 * array of four bytes instead of an array of 32 one-bit pixels. So
49 * getbits() and putbits() retain much the same calling sequence, but
50 * they move bytes around instead of bits. Of course, this entails the
51 * removal of all of the one-bit-pixel dependencies from the other
52 * files, but the major bit-hacking stuff should be covered here.
53 *
54 * I've created some new macros that make it easier to understand what's
55 * going on in the pixel calculations, and that make it easier to change the
56 * pixel size.
57 *
58 * name explanation
59 * ---- -----------
60 * PSZ pixel size (in bits)
61 * PGSZ pixel group size (in bits)
62 * PGSZB pixel group size (in bytes)
63 * PGSZBMSK mask with lowest PGSZB bits set to 1
64 * PPW pixels per word (pixels per pixel group)
65 * PPWMSK mask with lowest PPW bits set to 1
66 * PLST index of last pixel in a word (should be PPW-1)
67 * PIM pixel index mask (index within a pixel group)
68 * PWSH pixel-to-word shift (should be log2(PPW))
69 * PMSK mask with lowest PSZ bits set to 1
70 *
71 *
72 * Here are some sample values. In the notation cfbA,B: A is PSZ, and
73 * B is PGSZB. All the other values are derived from these
74 * two. This table does not show all combinations!
75 *
76 * name cfb8,4 cfb24,4 cfb32,4 cfb8,8 cfb24,8 cfb32,8
77 * ---- ------ ------- ------ ------ ------ -------
78 * PSZ 8 24 32 8 24 32
79 * PGSZ 32 32 32 64 64 64
80 * PGSZB 4 4 4 8 8 8
81 * PGSZBMSK 0xF 0xF? 0xF 0xFF 0xFF 0xFF
82 * PPW 4 1 1 8 2 2
83 * PPWMSK 0xF 0x1 0x1 0xFF 0x3? 0x3
84 * PLST 3 0 0 7 1 1
85 * PIM 0x3 0x0 0x0 0x7 0x1? 0x1
86 * PWSH 2 0 0 3 1 1
87 * PMSK 0xFF 0xFFFFFF 0xFFFFFFFF 0xFF 0xFFFFFF 0xFFFFFFFF
88 *
89 *
90 * I have also added a new macro, PFILL, that takes one pixel and
91 * replicates it throughout a word. This macro definition is dependent
92 * upon pixel and word size; it doesn't use macros like PPW and so
93 * forth. Examples: for monochrome, PFILL(1) => 0xffffffff, PFILL(0) =>
94 * 0x00000000. For 8-bit color, PFILL(0x5d) => 0x5d5d5d5d. This macro
95 * is used primarily for replicating a plane mask into a word.
96 *
97 * Color framebuffers operations also support the notion of a plane
98 * mask. This mask determines which planes of the framebuffer can be
99 * altered; the others are left unchanged. I have added another
100 * parameter to the putbits and putbitsrop macros that is the plane
101 * mask.
102 * ==========================================================================
103 *
104 * Keith Packard ([email protected])
105 * 64bit code is no longer supported; it requires DIX support
106 * for repadding images which significantly impacts performance
107 */
108
109/*
110 * PSZ needs to be defined before we get here. Usually it comes from a
111 * -DPSZ=foo on the compilation command line.
112 */
113
114#ifndef PSZ
115#define PSZ 8
116#endif
117
118/*
119 * PixelGroup is the data type used to operate on groups of pixels.
120 * We typedef it here to CARD32 with the assumption that you
121 * want to manipulate 32 bits worth of pixels at a time as you can. If CARD32
122 * is not appropriate for your server, define it to something else
123 * before including this file. In this case you will also have to define
124 * PGSZB to the size in bytes of PixelGroup.
125 */
126#ifndef PixelGroup
127#define PixelGroup CARD32
128#define PGSZB 4
129#endif /* PixelGroup */
130
131#ifndef CfbBits
132#define CfbBits CARD32
133#endif
134
135#define PGSZ (PGSZB << 3)
136#define PPW (PGSZ/PSZ)
137#define PLST (PPW-1)
138#define PIM PLST
139#define PMSK (((PixelGroup)1 << PSZ) - 1)
140#define PPWMSK (((PixelGroup)1 << PPW) - 1) /* instead of BITMSK */
141#define PGSZBMSK (((PixelGroup)1 << PGSZB) - 1)
142
143/* set PWSH = log2(PPW) using brute force */
144
145#if PPW == 1
146#define PWSH 0
147#else
148#if PPW == 2
149#define PWSH 1
150#else
151#if PPW == 4
152#define PWSH 2
153#else
154#if PPW == 8
155#define PWSH 3
156#else
157#if PPW == 16
158#define PWSH 4
159#endif /* PPW == 16 */
160#endif /* PPW == 8 */
161#endif /* PPW == 4 */
162#endif /* PPW == 2 */
163#endif /* PPW == 1 */
164
165/* Defining PIXEL_ADDR means that individual pixels are addressable by this
166 * machine (as type PixelType). A possible CFB architecture which supported
167 * 8-bits-per-pixel on a non byte-addressable machine would not have this
168 * defined.
169 *
170 * Defining FOUR_BIT_CODE means that cfb knows how to stipple on this machine;
171 * eventually, stippling code for 16 and 32 bit devices should be written
172 * which would allow them to also use FOUR_BIT_CODE. There isn't that
173 * much to do in those cases, but it would make them quite a bit faster.
174 */
175
176#if PSZ == 8
177#define PIXEL_ADDR
178typedef CARD8 PixelType;
179#define FOUR_BIT_CODE
180#endif
181
182#if PSZ == 16
183#define PIXEL_ADDR
184typedef CARD16 PixelType;
185#endif
186
187#if PSZ == 24
188#undef PMSK
189#define PMSK 0xFFFFFF
190/*#undef PIM
191#define PIM 3*/
192#define PIXEL_ADDR
193typedef CARD32 PixelType;
194#endif
195
196#if PSZ == 32
197#undef PMSK
198#define PMSK 0xFFFFFFFF
199#define PIXEL_ADDR
200typedef CARD32 PixelType;
201#endif
202
203
204/* the following notes use the following conventions:
205SCREEN LEFT SCREEN RIGHT
206in this file and maskbits.c, left and right refer to screen coordinates,
207NOT bit numbering in registers.
208
209cfbstarttab[n]
210 pixels[0,n-1] = 0's pixels[n,PPW-1] = 1's
211cfbendtab[n] =
212 pixels[0,n-1] = 1's pixels[n,PPW-1] = 0's
213
214cfbstartpartial[], cfbendpartial[]
215 these are used as accelerators for doing putbits and masking out
216bits that are all contained between longword boudaries. the extra
217256 bytes of data seems a small price to pay -- code is smaller,
218and narrow things (e.g. window borders) go faster.
219
220the names may seem misleading; they are derived not from which end
221of the word the bits are turned on, but at which end of a scanline
222the table tends to be used.
223
224look at the tables and macros to understand boundary conditions.
225(careful readers will note that starttab[n] = ~endtab[n] for n != 0)
226
227-----------------------------------------------------------------------
228these two macros depend on the screen's bit ordering.
229in both of them x is a screen position. they are used to
230combine bits collected from multiple longwords into a
231single destination longword, and to unpack a single
232source longword into multiple destinations.
233
234SCRLEFT(dst, x)
235 takes dst[x, PPW] and moves them to dst[0, PPW-x]
236 the contents of the rest of dst are 0 ONLY IF
237 dst is UNSIGNED.
238 is cast as an unsigned.
239 this is a right shift on the VAX, left shift on
240 Sun and pc-rt.
241
242SCRRIGHT(dst, x)
243 takes dst[0,x] and moves them to dst[PPW-x, PPW]
244 the contents of the rest of dst are 0 ONLY IF
245 dst is UNSIGNED.
246 this is a left shift on the VAX, right shift on
247 Sun and pc-rt.
248
249
250the remaining macros are cpu-independent; all bit order dependencies
251are built into the tables and the two macros above.
252
253maskbits(x, w, startmask, endmask, nlw)
254 for a span of width w starting at position x, returns
255a mask for ragged pixels at start, mask for ragged pixels at end,
256and the number of whole longwords between the ends.
257
258maskpartialbits(x, w, mask)
259 works like maskbits(), except all the pixels are in the
260 same longword (i.e. (x&0xPIM + w) <= PPW)
261
262mask32bits(x, w, startmask, endmask, nlw)
263 as maskbits, but does not calculate nlw. it is used by
264 cfbGlyphBlt to put down glyphs <= PPW bits wide.
265
266getbits(psrc, x, w, dst)
267 starting at position x in psrc (x < PPW), collect w
268 pixels and put them in the screen left portion of dst.
269 psrc is a longword pointer. this may span longword boundaries.
270 it special-cases fetching all w bits from one longword.
271
272 +--------+--------+ +--------+
273 | | m |n| | ==> | m |n| |
274 +--------+--------+ +--------+
275 x x+w 0 w
276 psrc psrc+1 dst
277 m = PPW - x
278 n = w - m
279
280 implementation:
281 get m pixels, move to screen-left of dst, zeroing rest of dst;
282 get n pixels from next word, move screen-right by m, zeroing
283 lower m pixels of word.
284 OR the two things together.
285
286putbits(src, x, w, pdst, planemask)
287 starting at position x in pdst, put down the screen-leftmost
288 w bits of src. pdst is a longword pointer. this may
289 span longword boundaries.
290 it special-cases putting all w bits into the same longword.
291
292 +--------+ +--------+--------+
293 | m |n| | ==> | | m |n| |
294 +--------+ +--------+--------+
295 0 w x x+w
296 dst pdst pdst+1
297 m = PPW - x
298 n = w - m
299
300 implementation:
301 get m pixels, shift screen-right by x, zero screen-leftmost x
302 pixels; zero rightmost m bits of *pdst and OR in stuff
303 from before the semicolon.
304 shift src screen-left by m, zero bits n-32;
305 zero leftmost n pixels of *(pdst+1) and OR in the
306 stuff from before the semicolon.
307
308putbitsrop(src, x, w, pdst, planemask, ROP)
309 like putbits but calls DoRop with the rasterop ROP (see cfb.h for
310 DoRop)
311
312getleftbits(psrc, w, dst)
313 get the leftmost w (w<=PPW) bits from *psrc and put them
314 in dst. this is used by the cfbGlyphBlt code for glyphs
315 <=PPW bits wide.
316*/
317
318#if (BITMAP_BIT_ORDER == MSBFirst)
319#define BitRight(lw,n) ((lw) >> (n))
320#define BitLeft(lw,n) ((lw) << (n))
321#else /* (BITMAP_BIT_ORDER == LSBFirst) */
322#define BitRight(lw,n) ((lw) << (n))
323#define BitLeft(lw,n) ((lw) >> (n))
324#endif /* (BITMAP_BIT_ORDER == MSBFirst) */
325
326#define SCRLEFT(lw, n) BitLeft (lw, (n) * PSZ)
327#define SCRRIGHT(lw, n) BitRight(lw, (n) * PSZ)
328
329/*
330 * Note that the shift direction is independent of the byte ordering of the
331 * machine. The following is portable code.
332 */
333#if PPW == 16
334#define PFILL(p) ( ((p)&PMSK) | \
335 ((p)&PMSK) << PSZ | \
336 ((p)&PMSK) << 2*PSZ | \
337 ((p)&PMSK) << 3*PSZ | \
338 ((p)&PMSK) << 4*PSZ | \
339 ((p)&PMSK) << 5*PSZ | \
340 ((p)&PMSK) << 6*PSZ | \
341 ((p)&PMSK) << 7*PSZ | \
342 ((p)&PMSK) << 8*PSZ | \
343 ((p)&PMSK) << 9*PSZ | \
344 ((p)&PMSK) << 10*PSZ | \
345 ((p)&PMSK) << 11*PSZ | \
346 ((p)&PMSK) << 12*PSZ | \
347 ((p)&PMSK) << 13*PSZ | \
348 ((p)&PMSK) << 14*PSZ | \
349 ((p)&PMSK) << 15*PSZ )
350#define PFILL2(p, pf) { \
351 pf = (p) & PMSK; \
352 pf |= (pf << PSZ); \
353 pf |= (pf << 2*PSZ); \
354 pf |= (pf << 4*PSZ); \
355 pf |= (pf << 8*PSZ); \
356}
357#endif /* PPW == 16 */
358#if PPW == 8
359#define PFILL(p) ( ((p)&PMSK) | \
360 ((p)&PMSK) << PSZ | \
361 ((p)&PMSK) << 2*PSZ | \
362 ((p)&PMSK) << 3*PSZ | \
363 ((p)&PMSK) << 4*PSZ | \
364 ((p)&PMSK) << 5*PSZ | \
365 ((p)&PMSK) << 6*PSZ | \
366 ((p)&PMSK) << 7*PSZ )
367#define PFILL2(p, pf) { \
368 pf = (p) & PMSK; \
369 pf |= (pf << PSZ); \
370 pf |= (pf << 2*PSZ); \
371 pf |= (pf << 4*PSZ); \
372}
373#endif
374#if PPW == 4
375#define PFILL(p) ( ((p)&PMSK) | \
376 ((p)&PMSK) << PSZ | \
377 ((p)&PMSK) << 2*PSZ | \
378 ((p)&PMSK) << 3*PSZ )
379#define PFILL2(p, pf) { \
380 pf = (p) & PMSK; \
381 pf |= (pf << PSZ); \
382 pf |= (pf << 2*PSZ); \
383}
384#endif
385#if PPW == 2
386#define PFILL(p) ( ((p)&PMSK) | \
387 ((p)&PMSK) << PSZ )
388#define PFILL2(p, pf) { \
389 pf = (p) & PMSK; \
390 pf |= (pf << PSZ); \
391}
392#endif
393#if PPW == 1
394#define PFILL(p) (p)
395#define PFILL2(p,pf) (pf = (p))
396#endif
397
398/*
399 * Reduced raster op - using precomputed values, perform the above
400 * in three instructions
401 */
402
403#define DoRRop(dst, and, xor) (((dst) & (and)) ^ (xor))
404
405#define DoMaskRRop(dst, and, xor, mask) \
406 (((dst) & ((and) | ~(mask))) ^ (xor & mask))
407
408#if PSZ != 32 || PPW != 1
409
410# if (PSZ == 24 && PPW == 1)
411#define maskbits(x, w, startmask, endmask, nlw) {\
412 startmask = cfbstarttab[(x)&3]; \
413 endmask = cfbendtab[((x)+(w)) & 3]; \
414 nlw = ((((x)+(w))*3)>>2) - (((x)*3 +3)>>2); \
415}
416
417#define mask32bits(x, w, startmask, endmask) \
418 startmask = cfbstarttab[(x)&3]; \
419 endmask = cfbendtab[((x)+(w)) & 3];
420
421#define maskpartialbits(x, w, mask) \
422 mask = cfbstartpartial[(x) & 3] & cfbendpartial[((x)+(w)) & 3];
423
424#define maskbits24(x, w, startmask, endmask, nlw) \
425 startmask = cfbstarttab24[(x) & 3]; \
426 endmask = cfbendtab24[((x)+(w)) & 3]; \
427 if (startmask){ \
428 nlw = (((w) - (4 - ((x) & 3))) >> 2); \
429 } else { \
430 nlw = (w) >> 2; \
431 }
432
433#define getbits24(psrc, dst, index) {\
434 register int idx; \
435 switch(idx = ((index)&3)<<1){ \
436 case 0: \
437 dst = (*(psrc) &cfbmask[idx]); \
438 break; \
439 case 6: \
440 dst = BitLeft((*(psrc) &cfbmask[idx]), cfb24Shift[idx]); \
441 break; \
442 default: \
443 dst = BitLeft((*(psrc) &cfbmask[idx]), cfb24Shift[idx]) | \
444 BitRight(((*((psrc)+1)) &cfbmask[idx+1]), cfb24Shift[idx+1]); \
445 }; \
446}
447
448#define putbits24(src, w, pdst, planemask, index) {\
449 register PixelGroup dstpixel; \
450 register unsigned int idx; \
451 switch(idx = ((index)&3)<<1){ \
452 case 0: \
453 dstpixel = (*(pdst) &cfbmask[idx]); \
454 break; \
455 case 6: \
456 dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx]); \
457 break; \
458 default: \
459 dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx])| \
460 BitRight(((*((pdst)+1)) &cfbmask[idx+1]), cfb24Shift[idx+1]); \
461 }; \
462 dstpixel &= ~(planemask); \
463 dstpixel |= (src & planemask); \
464 *(pdst) &= cfbrmask[idx]; \
465 switch(idx){ \
466 case 0: \
467 *(pdst) |= (dstpixel & cfbmask[idx]); \
468 break; \
469 case 2: \
470 case 4: \
471 pdst++;idx++; \
472 *(pdst) = ((*(pdst)) & cfbrmask[idx]) | \
473 (BitLeft(dstpixel, cfb24Shift[idx]) & cfbmask[idx]); \
474 pdst--;idx--; \
475 case 6: \
476 *(pdst) |= (BitRight(dstpixel, cfb24Shift[idx]) & cfbmask[idx]); \
477 break; \
478 }; \
479}
480
481#define putbitsrop24(src, x, pdst, planemask, rop) \
482{ \
483 register PixelGroup t1, dstpixel; \
484 register unsigned int idx; \
485 switch(idx = (x)<<1){ \
486 case 0: \
487 dstpixel = (*(pdst) &cfbmask[idx]); \
488 break; \
489 case 6: \
490 dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx]); \
491 break; \
492 default: \
493 dstpixel = BitLeft((*(pdst) &cfbmask[idx]), cfb24Shift[idx])| \
494 BitRight(((*((pdst)+1)) &cfbmask[idx+1]), cfb24Shift[idx+1]); \
495 }; \
496 DoRop(t1, rop, (src), dstpixel); \
497 dstpixel &= ~planemask; \
498 dstpixel |= (t1 & planemask); \
499 *(pdst) &= cfbrmask[idx]; \
500 switch(idx){ \
501 case 0: \
502 *(pdst) |= (dstpixel & cfbmask[idx]); \
503 break; \
504 case 2: \
505 case 4: \
506 *((pdst)+1) = ((*((pdst)+1)) & cfbrmask[idx+1]) | \
507 (BitLeft(dstpixel, cfb24Shift[idx+1]) & (cfbmask[idx+1])); \
508 case 6: \
509 *(pdst) |= (BitRight(dstpixel, cfb24Shift[idx]) & cfbmask[idx]); \
510 }; \
511}
512# else /* PSZ == 24 && PPW == 1 */
513#define maskbits(x, w, startmask, endmask, nlw) \
514 startmask = cfbstarttab[(x)&PIM]; \
515 endmask = cfbendtab[((x)+(w)) & PIM]; \
516 if (startmask) \
517 nlw = (((w) - (PPW - ((x)&PIM))) >> PWSH); \
518 else \
519 nlw = (w) >> PWSH;
520
521#define maskpartialbits(x, w, mask) \
522 mask = cfbstartpartial[(x) & PIM] & cfbendpartial[((x) + (w)) & PIM];
523
524#define mask32bits(x, w, startmask, endmask) \
525 startmask = cfbstarttab[(x)&PIM]; \
526 endmask = cfbendtab[((x)+(w)) & PIM];
527
528/* FIXME */
529#define maskbits24(x, w, startmask, endmask, nlw) \
530 abort()
531#define getbits24(psrc, dst, index) \
532 abort()
533#define putbits24(src, w, pdst, planemask, index) \
534 abort()
535#define putbitsrop24(src, x, pdst, planemask, rop) \
536 abort()
537
538#endif /* PSZ == 24 && PPW == 1 */
539
540#define getbits(psrc, x, w, dst) \
541if ( ((x) + (w)) <= PPW) \
542{ \
543 dst = SCRLEFT(*(psrc), (x)); \
544} \
545else \
546{ \
547 int m; \
548 m = PPW-(x); \
549 dst = (SCRLEFT(*(psrc), (x)) & cfbendtab[m]) | \
550 (SCRRIGHT(*((psrc)+1), m) & cfbstarttab[m]); \
551}
552
553
554#define putbits(src, x, w, pdst, planemask) \
555if ( ((x)+(w)) <= PPW) \
556{ \
557 PixelGroup tmpmask; \
558 maskpartialbits((x), (w), tmpmask); \
559 tmpmask &= PFILL(planemask); \
560 *(pdst) = (*(pdst) & ~tmpmask) | (SCRRIGHT(src, x) & tmpmask); \
561} \
562else \
563{ \
564 unsigned int m; \
565 unsigned int n; \
566 PixelGroup pm = PFILL(planemask); \
567 m = PPW-(x); \
568 n = (w) - m; \
569 *(pdst) = (*(pdst) & (cfbendtab[x] | ~pm)) | \
570 (SCRRIGHT(src, x) & (cfbstarttab[x] & pm)); \
571 *((pdst)+1) = (*((pdst)+1) & (cfbstarttab[n] | ~pm)) | \
572 (SCRLEFT(src, m) & (cfbendtab[n] & pm)); \
573}
574#if defined(__GNUC__) && defined(mc68020)
575#undef getbits
576#define FASTGETBITS(psrc, x, w, dst) \
577 asm ("bfextu %3{%1:%2},%0" \
578 : "=d" (dst) : "di" (x), "di" (w), "o" (*(char *)(psrc)))
579
580#define getbits(psrc,x,w,dst) \
581{ \
582 FASTGETBITS(psrc, (x) * PSZ, (w) * PSZ, dst); \
583 dst = SCRLEFT(dst,PPW-(w)); \
584}
585
586#define FASTPUTBITS(src, x, w, pdst) \
587 asm ("bfins %3,%0{%1:%2}" \
588 : "=o" (*(char *)(pdst)) \
589 : "di" (x), "di" (w), "d" (src), "0" (*(char *) (pdst)))
590
591#undef putbits
592#define putbits(src, x, w, pdst, planemask) \
593{ \
594 if (planemask != PMSK) { \
595 PixelGroup _m, _pm; \
596 FASTGETBITS(pdst, (x) * PSZ , (w) * PSZ, _m); \
597 PFILL2(planemask, _pm); \
598 _m &= (~_pm); \
599 _m |= (SCRRIGHT(src, PPW-(w)) & _pm); \
600 FASTPUTBITS(_m, (x) * PSZ, (w) * PSZ, pdst); \
601 } else { \
602 FASTPUTBITS(SCRRIGHT(src, PPW-(w)), (x) * PSZ, (w) * PSZ, pdst); \
603 } \
604}
605
606
607#endif /* mc68020 */
608
609#define putbitsrop(src, x, w, pdst, planemask, rop) \
610if ( ((x)+(w)) <= PPW) \
611{ \
612 PixelGroup tmpmask; \
613 PixelGroup t1, t2; \
614 maskpartialbits((x), (w), tmpmask); \
615 PFILL2(planemask, t1); \
616 tmpmask &= t1; \
617 t1 = SCRRIGHT((src), (x)); \
618 DoRop(t2, rop, t1, *(pdst)); \
619 *(pdst) = (*(pdst) & ~tmpmask) | (t2 & tmpmask); \
620} \
621else \
622{ \
623 CfbBits m; \
624 CfbBits n; \
625 PixelGroup t1, t2; \
626 PixelGroup pm; \
627 PFILL2(planemask, pm); \
628 m = PPW-(x); \
629 n = (w) - m; \
630 t1 = SCRRIGHT((src), (x)); \
631 DoRop(t2, rop, t1, *(pdst)); \
632 *(pdst) = (*(pdst) & (cfbendtab[x] | ~pm)) | (t2 & (cfbstarttab[x] & pm));\
633 t1 = SCRLEFT((src), m); \
634 DoRop(t2, rop, t1, *((pdst) + 1)); \
635 *((pdst)+1) = (*((pdst)+1) & (cfbstarttab[n] | ~pm)) | \
636 (t2 & (cfbendtab[n] & pm)); \
637}
638
639#else /* PSZ == 32 && PPW == 1*/
640
641/*
642 * These macros can be optimized for 32-bit pixels since there is no
643 * need to worry about left/right edge masking. These macros were
644 * derived from the above using the following reductions:
645 *
646 * - x & PIW = 0 [since PIW = 0]
647 * - all masking tables are only indexed by 0 [ due to above ]
648 * - cfbstartab[0] and cfbendtab[0] = 0 [ no left/right edge masks]
649 * - cfbstartpartial[0] and cfbendpartial[0] = ~0 [no partial pixel mask]
650 *
651 * Macro reduction based upon constants cannot be performed automatically
652 * by the compiler since it does not know the contents of the masking
653 * arrays in cfbmskbits.c.
654 */
655#define maskbits(x, w, startmask, endmask, nlw) \
656 startmask = endmask = 0; \
657 nlw = (w);
658
659#define maskpartialbits(x, w, mask) \
660 mask = 0xFFFFFFFF;
661
662#define mask32bits(x, w, startmask, endmask) \
663 startmask = endmask = 0;
664
665/*
666 * For 32-bit operations, getbits(), putbits(), and putbitsrop()
667 * will only be invoked with x = 0 and w = PPW (1). The getbits()
668 * macro is only called within left/right edge logic, which doesn't
669 * happen for 32-bit pixels.
670 */
671#define getbits(psrc, x, w, dst) (dst) = *(psrc)
672
673#define putbits(src, x, w, pdst, planemask) \
674 *(pdst) = (*(pdst) & ~planemask) | (src & planemask);
675
676#define putbitsrop(src, x, w, pdst, planemask, rop) \
677{ \
678 PixelGroup t1; \
679 DoRop(t1, rop, (src), *(pdst)); \
680 *(pdst) = (*(pdst) & ~planemask) | (t1 & planemask); \
681}
682
683#endif /* PSZ != 32 */
684
685/*
686 * Use these macros only when you're using the MergeRop stuff
687 * in ../mfb/mergerop.h
688 */
689
690/* useful only when not spanning destination longwords */
691#if PSZ == 24
692#define putbitsmropshort24(src,x,w,pdst,index) {\
693 PixelGroup _tmpmask; \
694 PixelGroup _t1; \
695 maskpartialbits ((x), (w), _tmpmask); \
696 _t1 = SCRRIGHT((src), (x)); \
697 DoMaskMergeRop24(_t1, pdst, _tmpmask, index); \
698}
699#endif
700#define putbitsmropshort(src,x,w,pdst) {\
701 PixelGroup _tmpmask; \
702 PixelGroup _t1; \
703 maskpartialbits ((x), (w), _tmpmask); \
704 _t1 = SCRRIGHT((src), (x)); \
705 *pdst = DoMaskMergeRop(_t1, *pdst, _tmpmask); \
706}
707
708/* useful only when spanning destination longwords */
709#define putbitsmroplong(src,x,w,pdst) { \
710 PixelGroup _startmask, _endmask; \
711 int _m; \
712 PixelGroup _t1; \
713 _m = PPW - (x); \
714 _startmask = cfbstarttab[x]; \
715 _endmask = cfbendtab[(w) - _m]; \
716 _t1 = SCRRIGHT((src), (x)); \
717 pdst[0] = DoMaskMergeRop(_t1,pdst[0],_startmask); \
718 _t1 = SCRLEFT ((src),_m); \
719 pdst[1] = DoMaskMergeRop(_t1,pdst[1],_endmask); \
720}
721
722#define putbitsmrop(src,x,w,pdst) \
723if ((x) + (w) <= PPW) {\
724 putbitsmropshort(src,x,w,pdst); \
725} else { \
726 putbitsmroplong(src,x,w,pdst); \
727}
728
729#if GETLEFTBITS_ALIGNMENT == 1
730#define getleftbits(psrc, w, dst) dst = *((unsigned int *) psrc)
731#define getleftbits24(psrc, w, dst, idx){ \
732 regiseter int index; \
733 switch(index = ((idx)&3)<<1){ \
734 case 0: \
735 dst = (*((unsigned int *) psrc))&cfbmask[index]; \
736 break; \
737 case 2: \
738 case 4: \
739 dst = BitLeft(((*((unsigned int *) psrc))&cfbmask[index]), cfb24Shift[index]); \
740 dst |= BitRight(((*((unsigned int *) psrc)+1)&cfbmask[index]), cfb4Shift[index]); \
741 break; \
742 case 6: \
743 dst = BitLeft((*((unsigned int *) psrc)),cfb24Shift[index]); \
744 break; \
745 }; \
746}
747#endif /* GETLEFTBITS_ALIGNMENT == 1 */
748
749#define getglyphbits(psrc, x, w, dst) \
750{ \
751 dst = BitLeft((unsigned) *(psrc), (x)); \
752 if ( ((x) + (w)) > 32) \
753 dst |= (BitRight((unsigned) *((psrc)+1), 32-(x))); \
754}
755#if GETLEFTBITS_ALIGNMENT == 2
756#define getleftbits(psrc, w, dst) \
757 { \
758 if ( ((int)(psrc)) & 0x01 ) \
759 getglyphbits( ((unsigned int *)(((char *)(psrc))-1)), 8, (w), (dst) ); \
760 else \
761 dst = *((unsigned int *) psrc); \
762 }
763#endif /* GETLEFTBITS_ALIGNMENT == 2 */
764
765#if GETLEFTBITS_ALIGNMENT == 4
766#define getleftbits(psrc, w, dst) \
767 { \
768 int off, off_b; \
769 off_b = (off = ( ((int)(psrc)) & 0x03)) << 3; \
770 getglyphbits( \
771 (unsigned int *)( ((char *)(psrc)) - off), \
772 (off_b), (w), (dst) \
773 ); \
774 }
775#endif /* GETLEFTBITS_ALIGNMENT == 4 */
776
777/*
778 * getstipplepixels( psrcstip, x, w, ones, psrcpix, destpix )
779 *
780 * Converts bits to pixels in a reasonable way. Takes w (1 <= w <= PPW)
781 * bits from *psrcstip, starting at bit x; call this a quartet of bits.
782 * Then, takes the pixels from *psrcpix corresponding to the one-bits (if
783 * ones is TRUE) or the zero-bits (if ones is FALSE) of the quartet
784 * and puts these pixels into destpix.
785 *
786 * Example:
787 *
788 * getstipplepixels( &(0x08192A3B), 17, 4, 1, &(0x4C5D6E7F), dest )
789 *
790 * 0x08192A3B = 0000 1000 0001 1001 0010 1010 0011 1011
791 *
792 * This will take 4 bits starting at bit 17, so the quartet is 0x5 = 0101.
793 * It will take pixels from 0x4C5D6E7F corresponding to the one-bits in this
794 * quartet, so dest = 0x005D007F.
795 *
796 * XXX Works with both byte order.
797 * XXX This works for all values of x and w within a doubleword.
798 */
799#if (BITMAP_BIT_ORDER == MSBFirst)
800#define getstipplepixels( psrcstip, x, w, ones, psrcpix, destpix ) \
801{ \
802 PixelGroup q; \
803 int m; \
804 if ((m = ((x) - ((PPW*PSZ)-PPW))) > 0) { \
805 q = (*(psrcstip)) << m; \
806 if ( (x)+(w) > (PPW*PSZ) ) \
807 q |= *((psrcstip)+1) >> ((PPW*PSZ)-m); \
808 } \
809 else \
810 q = (*(psrcstip)) >> -m; \
811 q = QuartetBitsTable[(w)] & ((ones) ? q : ~q); \
812 *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
813}
814/* I just copied this to get the linker satisfied on PowerPC,
815 * so this may not be correct at all.
816 */
817#define getstipplepixels24(psrcstip,xt,ones,psrcpix,destpix,stipindex) \
818{ \
819 PixelGroup q; \
820 q = *(psrcstip) >> (xt); \
821 q = ((ones) ? q : ~q) & 1; \
822 *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
823}
824#else /* BITMAP_BIT_ORDER == LSB */
825
826/* this must load 32 bits worth; for most machines, thats an int */
827#define CfbFetchUnaligned(x) ldl_u(x)
828
829#define getstipplepixels( psrcstip, xt, w, ones, psrcpix, destpix ) \
830{ \
831 PixelGroup q; \
832 q = CfbFetchUnaligned(psrcstip) >> (xt); \
833 if ( ((xt)+(w)) > (PPW*PSZ) ) \
834 q |= (CfbFetchUnaligned((psrcstip)+1)) << ((PPW*PSZ)-(xt)); \
835 q = QuartetBitsTable[(w)] & ((ones) ? q : ~q); \
836 *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
837}
838#if PSZ == 24
839# if 0
840#define getstipplepixels24(psrcstip,xt,w,ones,psrcpix,destpix,stipindex,srcindex,dstindex) \
841{ \
842 PixelGroup q; \
843 CfbBits src; \
844 register unsigned int sidx; \
845 register unsigned int didx; \
846 sidx = ((srcindex) & 3)<<1; \
847 didx = ((dstindex) & 3)<<1; \
848 q = *(psrcstip) >> (xt); \
849/* if((srcindex)!=0)*/ \
850/* src = (((*(psrcpix)) << cfb24Shift[sidx]) & (cfbmask[sidx])) |*/ \
851/* (((*((psrcpix)+1)) << cfb24Shift[sidx+1]) & (cfbmask[sidx+1])); */\
852/* else */\
853 src = (*(psrcpix))&0xFFFFFF; \
854 if ( ((xt)+(w)) > PGSZ ) \
855 q |= (*((psrcstip)+1)) << (PGSZ -(xt)); \
856 q = QuartetBitsTable[(w)] & ((ones) ? q : ~q); \
857 src &= QuartetPixelMaskTable[q]; \
858 *(destpix) &= cfbrmask[didx]; \
859 switch(didx) {\
860 case 0: \
861 *(destpix) |= (src &cfbmask[didx]); \
862 break; \
863 case 2: \
864 case 4: \
865 destpix++;didx++; \
866 *(destpix) = ((*(destpix)) & (cfbrmask[didx]))| \
867 (BitLeft(src, cfb24Shift[didx]) & (cfbmask[didx])); \
868 destpix--; didx--;\
869 case 6: \
870 *(destpix) |= (BitRight(src, cfb24Shift[didx]) & cfbmask[didx]); \
871 break; \
872 }; \
873}
874# else
875#define getstipplepixels24(psrcstip,xt,ones,psrcpix,destpix,stipindex) \
876{ \
877 PixelGroup q; \
878 q = *(psrcstip) >> (xt); \
879 q = ((ones) ? q : ~q) & 1; \
880 *(destpix) = (*(psrcpix)) & QuartetPixelMaskTable[q]; \
881}
882# endif
883#endif /* PSZ == 24 */
884#endif
885
886extern PixelGroup cfbstarttab[];
887extern PixelGroup cfbendtab[];
888extern PixelGroup cfbstartpartial[];
889extern PixelGroup cfbendpartial[];
890extern PixelGroup cfbrmask[];
891extern PixelGroup cfbmask[];
892extern PixelGroup QuartetBitsTable[];
893extern PixelGroup QuartetPixelMaskTable[];
894#if PSZ == 24
895extern int cfb24Shift[];
896#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette