Home | History | Annotate | Line # | Download | only in rasops
rasops_bitops.h revision 1.12.18.2
      1  1.12.18.1       tls /* 	$NetBSD: rasops_bitops.h,v 1.12.18.2 2014/08/20 00:03:50 tls Exp $	*/
      2        1.1        ad 
      3        1.3        ad /*-
      4        1.3        ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5        1.1        ad  * All rights reserved.
      6        1.1        ad  *
      7        1.3        ad  * This code is derived from software contributed to The NetBSD Foundation
      8        1.7        ad  * by Andrew Doran.
      9        1.3        ad  *
     10        1.1        ad  * Redistribution and use in source and binary forms, with or without
     11        1.1        ad  * modification, are permitted provided that the following conditions
     12        1.1        ad  * are met:
     13        1.1        ad  * 1. Redistributions of source code must retain the above copyright
     14        1.1        ad  *    notice, this list of conditions and the following disclaimer.
     15        1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16        1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     17        1.1        ad  *    documentation and/or other materials provided with the distribution.
     18        1.1        ad  *
     19        1.3        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20        1.3        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21        1.3        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22        1.3        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23        1.3        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24        1.3        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25        1.3        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26        1.3        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27        1.3        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28        1.3        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29        1.3        ad  * POSSIBILITY OF SUCH DAMAGE.
     30        1.1        ad  */
     31        1.1        ad 
     32        1.1        ad #ifndef _RASOPS_BITOPS_H_
     33        1.1        ad #define _RASOPS_BITOPS_H_ 1
     34        1.1        ad 
     35        1.1        ad /*
     36        1.1        ad  * Erase columns.
     37        1.1        ad  */
     38        1.1        ad static void
     39       1.11    cegger NAME(erasecols)(void *cookie, int row, int col, int num, long attr)
     40        1.1        ad {
     41  1.12.18.2       tls 	int lclr, rclr, clr;
     42        1.1        ad 	struct rasops_info *ri;
     43  1.12.18.2       tls 	uint32_t *dp, *rp, *hrp = NULL, *hp = NULL, tmp, lmask, rmask;
     44        1.1        ad 	int height, cnt;
     45        1.6        pk 
     46        1.1        ad 	ri = (struct rasops_info *)cookie;
     47        1.1        ad 
     48        1.6        pk #ifdef RASOPS_CLIPPING
     49        1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
     50        1.1        ad 		return;
     51        1.1        ad 
     52        1.1        ad 	if (col < 0) {
     53        1.1        ad 		num += col;
     54        1.1        ad 		col = 0;
     55        1.1        ad 	}
     56        1.1        ad 
     57        1.1        ad 	if ((col + num) > ri->ri_cols)
     58        1.1        ad 		num = ri->ri_cols - col;
     59        1.6        pk 
     60        1.1        ad 	if (num <= 0)
     61        1.1        ad 		return;
     62        1.1        ad #endif
     63        1.1        ad 	col *= ri->ri_font->fontwidth << PIXEL_SHIFT;
     64        1.1        ad 	num *= ri->ri_font->fontwidth << PIXEL_SHIFT;
     65        1.1        ad 	height = ri->ri_font->fontheight;
     66        1.6        pk 	clr = ri->ri_devcmap[(attr >> 16) & 0xf];
     67  1.12.18.2       tls 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3));
     68       1.12  macallan 	if (ri->ri_hwbits)
     69  1.12.18.2       tls 		hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
     70       1.12  macallan 		    ((col >> 3) & ~3));
     71        1.1        ad 	if ((col & 31) + num <= 32) {
     72        1.1        ad 		lmask = ~rasops_pmask[col & 31][num];
     73        1.1        ad 		lclr = clr & ~lmask;
     74        1.1        ad 
     75        1.1        ad 		while (height--) {
     76        1.1        ad 			dp = rp;
     77  1.12.18.2       tls 			DELTA(rp, ri->ri_stride, uint32_t *);
     78        1.1        ad 
     79       1.12  macallan 			tmp = (*dp & lmask) | lclr;
     80       1.12  macallan 			*dp = tmp;
     81       1.12  macallan 			if (ri->ri_hwbits) {
     82       1.12  macallan 				*hrp = tmp;
     83  1.12.18.2       tls 				DELTA(hrp, ri->ri_stride, uint32_t *);
     84       1.12  macallan 			}
     85        1.1        ad 		}
     86        1.1        ad 	} else {
     87        1.1        ad 		lmask = rasops_rmask[col & 31];
     88        1.1        ad 		rmask = rasops_lmask[(col + num) & 31];
     89        1.6        pk 
     90        1.1        ad 		if (lmask)
     91        1.1        ad 			num = (num - (32 - (col & 31))) >> 5;
     92        1.1        ad 		else
     93        1.1        ad 			num = num >> 5;
     94        1.6        pk 
     95        1.1        ad 		lclr = clr & ~lmask;
     96        1.1        ad 		rclr = clr & ~rmask;
     97        1.1        ad 
     98        1.1        ad 		while (height--) {
     99        1.1        ad 			dp = rp;
    100  1.12.18.2       tls 			DELTA(rp, ri->ri_stride, uint32_t *);
    101       1.12  macallan 			if (ri->ri_hwbits) {
    102       1.12  macallan 				hp = hrp;
    103  1.12.18.2       tls 				DELTA(hrp, ri->ri_stride, uint32_t *);
    104       1.12  macallan 			}
    105        1.1        ad 
    106        1.8   thorpej 			if (lmask) {
    107       1.12  macallan 				tmp = (*dp & lmask) | lclr;
    108       1.12  macallan 				*dp = tmp;
    109        1.8   thorpej 				dp++;
    110       1.12  macallan 				if (ri->ri_hwbits) {
    111       1.12  macallan 					*hp = tmp;
    112       1.12  macallan 					hp++;
    113       1.12  macallan 				}
    114        1.8   thorpej 			}
    115        1.1        ad 
    116        1.1        ad 			for (cnt = num; cnt > 0; cnt--)
    117        1.1        ad 				*dp++ = clr;
    118       1.12  macallan 			if (ri->ri_hwbits) {
    119       1.12  macallan 				for (cnt = num; cnt > 0; cnt--)
    120       1.12  macallan 					*hp++ = clr;
    121       1.12  macallan 			}
    122        1.1        ad 
    123       1.12  macallan 			if (rmask) {
    124       1.12  macallan 				tmp = (*dp & rmask) | rclr;
    125       1.12  macallan 				*dp = tmp;
    126       1.12  macallan 				if (ri->ri_hwbits)
    127       1.12  macallan 					*hp = tmp;
    128       1.12  macallan 			}
    129        1.1        ad 		}
    130        1.1        ad 	}
    131        1.1        ad }
    132        1.1        ad 
    133        1.1        ad /*
    134        1.1        ad  * Actually paint the cursor.
    135        1.1        ad  */
    136        1.1        ad static void
    137       1.11    cegger NAME(do_cursor)(struct rasops_info *ri)
    138        1.1        ad {
    139  1.12.18.2       tls 	int height, row, col, num;
    140  1.12.18.2       tls 	uint32_t *dp, *rp, *hp = NULL, *hrp = NULL, tmp, lmask, rmask;
    141        1.6        pk 
    142        1.1        ad 	row = ri->ri_crow;
    143        1.1        ad 	col = ri->ri_ccol * ri->ri_font->fontwidth << PIXEL_SHIFT;
    144        1.1        ad 	height = ri->ri_font->fontheight;
    145        1.1        ad 	num = ri->ri_font->fontwidth << PIXEL_SHIFT;
    146  1.12.18.2       tls 	rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale + ((col >> 3) & ~3));
    147       1.12  macallan 	if (ri->ri_hwbits)
    148  1.12.18.2       tls 		hrp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
    149       1.12  macallan 		    ((col >> 3) & ~3));
    150        1.6        pk 
    151        1.1        ad 	if ((col & 31) + num <= 32) {
    152        1.1        ad 		lmask = rasops_pmask[col & 31][num];
    153        1.1        ad 
    154        1.1        ad 		while (height--) {
    155        1.1        ad 			dp = rp;
    156  1.12.18.2       tls 			DELTA(rp, ri->ri_stride, uint32_t *);
    157        1.1        ad 			*dp ^= lmask;
    158        1.1        ad 		}
    159       1.12  macallan 		if (ri->ri_hwbits) {
    160       1.12  macallan 			height = ri->ri_font->fontheight;
    161       1.12  macallan 			while (height--) {
    162       1.12  macallan 				hp = hrp;
    163  1.12.18.2       tls 				DELTA(hrp, ri->ri_stride, uint32_t *);
    164       1.12  macallan 				*hp ^= lmask;
    165       1.12  macallan 			}
    166       1.12  macallan 		}
    167        1.1        ad 	} else {
    168        1.1        ad 		lmask = ~rasops_rmask[col & 31];
    169        1.1        ad 		rmask = ~rasops_lmask[(col + num) & 31];
    170        1.1        ad 
    171        1.1        ad 		while (height--) {
    172        1.1        ad 			dp = rp;
    173  1.12.18.2       tls 			DELTA(rp, ri->ri_stride, uint32_t *);
    174       1.12  macallan 			if (ri->ri_hwbits) {
    175       1.12  macallan 				hp = hrp;
    176  1.12.18.2       tls 				DELTA(hrp, ri->ri_stride, uint32_t *);
    177       1.12  macallan 			}
    178       1.12  macallan 			if (lmask != -1) {
    179       1.12  macallan 				tmp = *dp ^ lmask;
    180       1.12  macallan 				*dp = tmp;
    181       1.12  macallan 				dp++;
    182       1.12  macallan 				if (ri->ri_hwbits) {
    183       1.12  macallan 					*hp = tmp;
    184       1.12  macallan 					hp++;
    185       1.12  macallan 				}
    186       1.12  macallan 			}
    187        1.1        ad 
    188       1.12  macallan 			if (rmask != -1) {
    189       1.12  macallan 				tmp = *dp ^ rmask;
    190       1.12  macallan 				*dp = tmp;
    191       1.12  macallan 				if (ri->ri_hwbits)
    192       1.12  macallan 					*hp = tmp;
    193       1.12  macallan 			}
    194        1.1        ad 		}
    195        1.1        ad 	}
    196        1.1        ad }
    197        1.1        ad 
    198        1.1        ad /*
    199        1.4        ad  * Copy columns. Ick!
    200        1.1        ad  */
    201        1.1        ad static void
    202       1.11    cegger NAME(copycols)(void *cookie, int row, int src, int dst, int num)
    203        1.1        ad {
    204  1.12.18.2       tls 	int height, lnum, rnum, sb, db, cnt, full;
    205  1.12.18.2       tls 	uint32_t tmp, lmask, rmask;
    206  1.12.18.2       tls 	uint32_t *sp, *dp, *srp, *drp, *dhp = NULL, *hp = NULL;
    207        1.1        ad 	struct rasops_info *ri;
    208        1.6        pk 
    209        1.1        ad 	ri = (struct rasops_info *)cookie;
    210        1.1        ad 
    211        1.1        ad #ifdef RASOPS_CLIPPING
    212        1.1        ad 	if (dst == src)
    213        1.1        ad 		return;
    214        1.6        pk 
    215        1.1        ad 	/* Catches < 0 case too */
    216        1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    217        1.1        ad 		return;
    218        1.6        pk 
    219        1.1        ad 	if (src < 0) {
    220        1.1        ad 		num += src;
    221        1.1        ad 		src = 0;
    222        1.1        ad 	}
    223        1.1        ad 
    224        1.1        ad 	if ((src + num) > ri->ri_cols)
    225        1.1        ad 		num = ri->ri_cols - src;
    226        1.1        ad 
    227        1.1        ad 	if (dst < 0) {
    228        1.1        ad 		num += dst;
    229        1.1        ad 		dst = 0;
    230        1.1        ad 	}
    231        1.1        ad 
    232        1.1        ad 	if ((dst + num) > ri->ri_cols)
    233        1.1        ad 		num = ri->ri_cols - dst;
    234        1.6        pk 
    235        1.1        ad 	if (num <= 0)
    236        1.1        ad 		return;
    237        1.1        ad #endif
    238        1.6        pk 
    239        1.1        ad 	cnt = ri->ri_font->fontwidth << PIXEL_SHIFT;
    240        1.1        ad 	src *= cnt;
    241        1.1        ad 	dst *= cnt;
    242        1.1        ad 	num *= cnt;
    243        1.1        ad 	row *= ri->ri_yscale;
    244        1.1        ad 	height = ri->ri_font->fontheight;
    245        1.4        ad 	db = dst & 31;
    246        1.1        ad 
    247        1.6        pk 	if (db + num <= 32) {
    248        1.4        ad 		/* Destination is contained within a single word */
    249  1.12.18.2       tls 		srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
    250  1.12.18.2       tls 		drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
    251       1.12  macallan 		if (ri->ri_hwbits)
    252  1.12.18.2       tls 			dhp = (uint32_t *)(ri->ri_hwbits + row +
    253       1.12  macallan 			    ((dst >> 3) & ~3));
    254        1.1        ad 		sb = src & 31;
    255        1.1        ad 
    256        1.1        ad 		while (height--) {
    257        1.1        ad 			GETBITS(srp, sb, num, tmp);
    258        1.1        ad 			PUTBITS(tmp, db, num, drp);
    259       1.12  macallan 			if (ri->ri_hwbits) {
    260       1.12  macallan 				PUTBITS(tmp, db, num, dhp);
    261  1.12.18.2       tls 				DELTA(dhp, ri->ri_stride, uint32_t *);
    262       1.12  macallan 			}
    263  1.12.18.2       tls 			DELTA(srp, ri->ri_stride, uint32_t *);
    264  1.12.18.2       tls 			DELTA(drp, ri->ri_stride, uint32_t *);
    265        1.1        ad 		}
    266        1.6        pk 
    267        1.1        ad 		return;
    268        1.1        ad 	}
    269        1.1        ad 
    270        1.4        ad 	lmask = rasops_rmask[db];
    271        1.1        ad 	rmask = rasops_lmask[(dst + num) & 31];
    272        1.4        ad 	lnum = (32 - db) & 31;
    273        1.6        pk 	rnum = (dst + num) & 31;
    274        1.6        pk 
    275        1.1        ad 	if (lmask)
    276        1.1        ad 		full = (num - (32 - (dst & 31))) >> 5;
    277        1.1        ad 	else
    278        1.1        ad 		full = num >> 5;
    279        1.1        ad 
    280        1.4        ad 	if (src < dst && src + num > dst) {
    281        1.4        ad 		/* Copy right-to-left */
    282  1.12.18.2       tls 		bool sbover;
    283  1.12.18.2       tls 		int sboff;
    284        1.1        ad 
    285  1.12.18.2       tls 		srp = (uint32_t *)(ri->ri_bits + row +
    286  1.12.18.2       tls 		    (((src + num) >> 3) & ~3));
    287  1.12.18.2       tls 		drp = (uint32_t *)(ri->ri_bits + row +
    288  1.12.18.2       tls 		    (((dst + num) >> 3) & ~3));
    289  1.12.18.2       tls 		if (ri->ri_hwbits)
    290  1.12.18.2       tls 			dhp = (uint32_t *)(ri->ri_hwbits + row +
    291  1.12.18.2       tls 			    (((dst + num) >> 3) & ~3));
    292        1.6        pk 
    293  1.12.18.2       tls 		sb = src & 31;
    294  1.12.18.2       tls 		sbover = (sb + lnum) >= 32;
    295  1.12.18.2       tls 		sboff = (src + num) & 31;
    296  1.12.18.2       tls 		if ((sboff -= rnum) < 0) {
    297  1.12.18.1       tls 			srp--;
    298  1.12.18.2       tls 			sboff += 32;
    299        1.4        ad 		}
    300        1.6        pk 
    301        1.1        ad 		while (height--) {
    302        1.1        ad 			sp = srp;
    303        1.1        ad 			dp = drp;
    304       1.12  macallan 			if (ri->ri_hwbits) {
    305       1.12  macallan 				hp = dhp;
    306  1.12.18.2       tls 				DELTA(dhp, ri->ri_stride, uint32_t *);
    307       1.12  macallan 			}
    308  1.12.18.2       tls 			DELTA(srp, ri->ri_stride, uint32_t *);
    309  1.12.18.2       tls 			DELTA(drp, ri->ri_stride, uint32_t *);
    310        1.6        pk 
    311  1.12.18.2       tls 			if (rnum) {
    312  1.12.18.2       tls 				GETBITS(sp, sboff, rnum, tmp);
    313  1.12.18.2       tls 				PUTBITS(tmp, 0, rnum, dp);
    314       1.12  macallan 				if (ri->ri_hwbits) {
    315  1.12.18.2       tls 					PUTBITS(tmp, 0, rnum, hp);
    316       1.12  macallan 				}
    317        1.1        ad 			}
    318        1.1        ad 
    319        1.4        ad 			/* Now aligned to 32-bits wrt dp */
    320  1.12.18.2       tls 			for (cnt = full; cnt; cnt--) {
    321  1.12.18.2       tls 				--dp;
    322  1.12.18.2       tls 				--sp;
    323  1.12.18.2       tls 				GETBITS(sp, sboff, 32, tmp);
    324  1.12.18.2       tls 				*dp = tmp;
    325  1.12.18.2       tls 				if (ri->ri_hwbits) {
    326  1.12.18.2       tls 					--hp;
    327  1.12.18.2       tls 					*hp = tmp;
    328  1.12.18.2       tls 				}
    329        1.1        ad 			}
    330        1.1        ad 
    331        1.1        ad 			if (lmask) {
    332  1.12.18.2       tls 				if (sbover)
    333  1.12.18.2       tls 					--sp;
    334  1.12.18.2       tls 				--dp;
    335        1.4        ad 				GETBITS(sp, sb, lnum, tmp);
    336  1.12.18.2       tls 				PUTBITS(tmp, db, lnum, dp);
    337       1.12  macallan 				if (ri->ri_hwbits)
    338  1.12.18.2       tls 					PUTBITS(tmp, db, lnum, hp);
    339        1.1        ad  			}
    340        1.1        ad  		}
    341        1.1        ad 	} else {
    342        1.4        ad 		/* Copy left-to-right */
    343  1.12.18.2       tls 		srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
    344  1.12.18.2       tls 		drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
    345       1.12  macallan 		if (ri->ri_hwbits)
    346  1.12.18.2       tls 			dhp = (uint32_t *)(ri->ri_hwbits + row +
    347       1.12  macallan 			    ((dst >> 3) & ~3));
    348        1.1        ad 		db = dst & 31;
    349        1.1        ad 
    350        1.1        ad 		while (height--) {
    351        1.1        ad 			sb = src & 31;
    352        1.1        ad 			sp = srp;
    353        1.1        ad 			dp = drp;
    354       1.12  macallan 			if (ri->ri_hwbits) {
    355       1.12  macallan 				hp = dhp;
    356  1.12.18.2       tls 				DELTA(dhp, ri->ri_stride, uint32_t *);
    357       1.12  macallan 			}
    358  1.12.18.2       tls 			DELTA(srp, ri->ri_stride, uint32_t *);
    359  1.12.18.2       tls 			DELTA(drp, ri->ri_stride, uint32_t *);
    360        1.6        pk 
    361        1.1        ad 			if (lmask) {
    362        1.1        ad 				GETBITS(sp, sb, lnum, tmp);
    363        1.1        ad 				PUTBITS(tmp, db, lnum, dp);
    364        1.1        ad 				dp++;
    365       1.12  macallan 				if (ri->ri_hwbits) {
    366       1.12  macallan 					PUTBITS(tmp, db, lnum, hp);
    367       1.12  macallan 					hp++;
    368       1.12  macallan 				}
    369        1.6        pk 
    370        1.1        ad 				if ((sb += lnum) > 31) {
    371        1.1        ad 					sp++;
    372        1.1        ad 					sb -= 32;
    373        1.1        ad 				}
    374        1.1        ad 			}
    375        1.6        pk 
    376        1.4        ad 			/* Now aligned to 32-bits wrt dp */
    377        1.4        ad 			for (cnt = full; cnt; cnt--, sp++) {
    378        1.1        ad 				GETBITS(sp, sb, 32, tmp);
    379        1.1        ad 				*dp++ = tmp;
    380       1.12  macallan 				if (ri->ri_hwbits)
    381       1.12  macallan 					*hp++ = tmp;
    382        1.1        ad 			}
    383        1.1        ad 
    384        1.1        ad 			if (rmask) {
    385        1.1        ad 				GETBITS(sp, sb, rnum, tmp);
    386        1.1        ad 				PUTBITS(tmp, 0, rnum, dp);
    387       1.12  macallan 				if (ri->ri_hwbits)
    388       1.12  macallan 					PUTBITS(tmp, 0, rnum, hp);
    389        1.1        ad  			}
    390        1.1        ad  		}
    391        1.1        ad  	}
    392        1.1        ad }
    393        1.5        ad 
    394        1.1        ad #endif /* _RASOPS_BITOPS_H_ */
    395