Home | History | Annotate | Line # | Download | only in rasops
rasops_bitops.h revision 1.16
      1  1.16       rin /* 	$NetBSD: rasops_bitops.h,v 1.16 2019/07/25 02:26:32 rin 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.15   tsutsui 	int lclr, rclr, clr;
     42   1.1        ad 	struct rasops_info *ri;
     43  1.15   tsutsui 	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.15   tsutsui 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3));
     68  1.12  macallan 	if (ri->ri_hwbits)
     69  1.15   tsutsui 		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.15   tsutsui 			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.15   tsutsui 				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.15   tsutsui 			DELTA(rp, ri->ri_stride, uint32_t *);
    101  1.12  macallan 			if (ri->ri_hwbits) {
    102  1.12  macallan 				hp = hrp;
    103  1.15   tsutsui 				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.15   tsutsui 	int height, row, col, num;
    140  1.15   tsutsui 	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.16       rin 	rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
    147  1.16       rin 	    ((col >> 3) & ~3));
    148  1.12  macallan 	if (ri->ri_hwbits)
    149  1.15   tsutsui 		hrp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
    150  1.12  macallan 		    ((col >> 3) & ~3));
    151   1.6        pk 
    152   1.1        ad 	if ((col & 31) + num <= 32) {
    153   1.1        ad 		lmask = rasops_pmask[col & 31][num];
    154   1.1        ad 
    155   1.1        ad 		while (height--) {
    156   1.1        ad 			dp = rp;
    157  1.15   tsutsui 			DELTA(rp, ri->ri_stride, uint32_t *);
    158   1.1        ad 			*dp ^= lmask;
    159   1.1        ad 		}
    160  1.12  macallan 		if (ri->ri_hwbits) {
    161  1.12  macallan 			height = ri->ri_font->fontheight;
    162  1.12  macallan 			while (height--) {
    163  1.12  macallan 				hp = hrp;
    164  1.15   tsutsui 				DELTA(hrp, ri->ri_stride, uint32_t *);
    165  1.12  macallan 				*hp ^= lmask;
    166  1.12  macallan 			}
    167  1.12  macallan 		}
    168   1.1        ad 	} else {
    169   1.1        ad 		lmask = ~rasops_rmask[col & 31];
    170   1.1        ad 		rmask = ~rasops_lmask[(col + num) & 31];
    171   1.1        ad 
    172   1.1        ad 		while (height--) {
    173   1.1        ad 			dp = rp;
    174  1.15   tsutsui 			DELTA(rp, ri->ri_stride, uint32_t *);
    175  1.12  macallan 			if (ri->ri_hwbits) {
    176  1.12  macallan 				hp = hrp;
    177  1.15   tsutsui 				DELTA(hrp, ri->ri_stride, uint32_t *);
    178  1.12  macallan 			}
    179  1.12  macallan 			if (lmask != -1) {
    180  1.12  macallan 				tmp = *dp ^ lmask;
    181  1.12  macallan 				*dp = tmp;
    182  1.12  macallan 				dp++;
    183  1.12  macallan 				if (ri->ri_hwbits) {
    184  1.12  macallan 					*hp = tmp;
    185  1.12  macallan 					hp++;
    186  1.12  macallan 				}
    187  1.12  macallan 			}
    188   1.1        ad 
    189  1.12  macallan 			if (rmask != -1) {
    190  1.12  macallan 				tmp = *dp ^ rmask;
    191  1.12  macallan 				*dp = tmp;
    192  1.12  macallan 				if (ri->ri_hwbits)
    193  1.12  macallan 					*hp = tmp;
    194  1.12  macallan 			}
    195   1.1        ad 		}
    196   1.1        ad 	}
    197   1.1        ad }
    198   1.1        ad 
    199   1.1        ad /*
    200   1.4        ad  * Copy columns. Ick!
    201   1.1        ad  */
    202   1.1        ad static void
    203  1.11    cegger NAME(copycols)(void *cookie, int row, int src, int dst, int num)
    204   1.1        ad {
    205  1.15   tsutsui 	int height, lnum, rnum, sb, db, cnt, full;
    206  1.15   tsutsui 	uint32_t tmp, lmask, rmask;
    207  1.15   tsutsui 	uint32_t *sp, *dp, *srp, *drp, *dhp = NULL, *hp = NULL;
    208   1.1        ad 	struct rasops_info *ri;
    209   1.6        pk 
    210   1.1        ad 	ri = (struct rasops_info *)cookie;
    211   1.1        ad 
    212   1.1        ad #ifdef RASOPS_CLIPPING
    213   1.1        ad 	if (dst == src)
    214   1.1        ad 		return;
    215   1.6        pk 
    216   1.1        ad 	/* Catches < 0 case too */
    217   1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    218   1.1        ad 		return;
    219   1.6        pk 
    220   1.1        ad 	if (src < 0) {
    221   1.1        ad 		num += src;
    222   1.1        ad 		src = 0;
    223   1.1        ad 	}
    224   1.1        ad 
    225   1.1        ad 	if ((src + num) > ri->ri_cols)
    226   1.1        ad 		num = ri->ri_cols - src;
    227   1.1        ad 
    228   1.1        ad 	if (dst < 0) {
    229   1.1        ad 		num += dst;
    230   1.1        ad 		dst = 0;
    231   1.1        ad 	}
    232   1.1        ad 
    233   1.1        ad 	if ((dst + num) > ri->ri_cols)
    234   1.1        ad 		num = ri->ri_cols - dst;
    235   1.6        pk 
    236   1.1        ad 	if (num <= 0)
    237   1.1        ad 		return;
    238   1.1        ad #endif
    239   1.6        pk 
    240   1.1        ad 	cnt = ri->ri_font->fontwidth << PIXEL_SHIFT;
    241   1.1        ad 	src *= cnt;
    242   1.1        ad 	dst *= cnt;
    243   1.1        ad 	num *= cnt;
    244   1.1        ad 	row *= ri->ri_yscale;
    245   1.1        ad 	height = ri->ri_font->fontheight;
    246   1.4        ad 	db = dst & 31;
    247   1.1        ad 
    248   1.6        pk 	if (db + num <= 32) {
    249   1.4        ad 		/* Destination is contained within a single word */
    250  1.15   tsutsui 		srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
    251  1.15   tsutsui 		drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
    252  1.12  macallan 		if (ri->ri_hwbits)
    253  1.15   tsutsui 			dhp = (uint32_t *)(ri->ri_hwbits + row +
    254  1.12  macallan 			    ((dst >> 3) & ~3));
    255   1.1        ad 		sb = src & 31;
    256   1.1        ad 
    257   1.1        ad 		while (height--) {
    258   1.1        ad 			GETBITS(srp, sb, num, tmp);
    259   1.1        ad 			PUTBITS(tmp, db, num, drp);
    260  1.12  macallan 			if (ri->ri_hwbits) {
    261  1.12  macallan 				PUTBITS(tmp, db, num, dhp);
    262  1.15   tsutsui 				DELTA(dhp, ri->ri_stride, uint32_t *);
    263  1.12  macallan 			}
    264  1.15   tsutsui 			DELTA(srp, ri->ri_stride, uint32_t *);
    265  1.15   tsutsui 			DELTA(drp, ri->ri_stride, uint32_t *);
    266   1.1        ad 		}
    267   1.6        pk 
    268   1.1        ad 		return;
    269   1.1        ad 	}
    270   1.1        ad 
    271   1.4        ad 	lmask = rasops_rmask[db];
    272   1.1        ad 	rmask = rasops_lmask[(dst + num) & 31];
    273   1.4        ad 	lnum = (32 - db) & 31;
    274   1.6        pk 	rnum = (dst + num) & 31;
    275   1.6        pk 
    276   1.1        ad 	if (lmask)
    277   1.1        ad 		full = (num - (32 - (dst & 31))) >> 5;
    278   1.1        ad 	else
    279   1.1        ad 		full = num >> 5;
    280   1.1        ad 
    281   1.4        ad 	if (src < dst && src + num > dst) {
    282   1.4        ad 		/* Copy right-to-left */
    283  1.15   tsutsui 		bool sbover;
    284  1.15   tsutsui 		int sboff;
    285  1.15   tsutsui 
    286  1.15   tsutsui 		srp = (uint32_t *)(ri->ri_bits + row +
    287  1.15   tsutsui 		    (((src + num) >> 3) & ~3));
    288  1.15   tsutsui 		drp = (uint32_t *)(ri->ri_bits + row +
    289  1.15   tsutsui 		    (((dst + num) >> 3) & ~3));
    290  1.12  macallan 		if (ri->ri_hwbits)
    291  1.15   tsutsui 			dhp = (uint32_t *)(ri->ri_hwbits + row +
    292  1.15   tsutsui 			    (((dst + num) >> 3) & ~3));
    293   1.1        ad 
    294  1.15   tsutsui 		sb = src & 31;
    295  1.15   tsutsui 		sbover = (sb + lnum) >= 32;
    296  1.15   tsutsui 		sboff = (src + num) & 31;
    297  1.15   tsutsui 		if ((sboff -= rnum) < 0) {
    298  1.14   tsutsui 			srp--;
    299  1.15   tsutsui 			sboff += 32;
    300   1.4        ad 		}
    301   1.6        pk 
    302   1.1        ad 		while (height--) {
    303   1.1        ad 			sp = srp;
    304   1.1        ad 			dp = drp;
    305  1.12  macallan 			if (ri->ri_hwbits) {
    306  1.12  macallan 				hp = dhp;
    307  1.15   tsutsui 				DELTA(dhp, ri->ri_stride, uint32_t *);
    308  1.12  macallan 			}
    309  1.15   tsutsui 			DELTA(srp, ri->ri_stride, uint32_t *);
    310  1.15   tsutsui 			DELTA(drp, ri->ri_stride, uint32_t *);
    311   1.6        pk 
    312  1.15   tsutsui 			if (rnum) {
    313  1.15   tsutsui 				GETBITS(sp, sboff, rnum, tmp);
    314  1.15   tsutsui 				PUTBITS(tmp, 0, rnum, dp);
    315  1.12  macallan 				if (ri->ri_hwbits) {
    316  1.15   tsutsui 					PUTBITS(tmp, 0, rnum, hp);
    317  1.12  macallan 				}
    318   1.1        ad 			}
    319   1.1        ad 
    320   1.4        ad 			/* Now aligned to 32-bits wrt dp */
    321  1.15   tsutsui 			for (cnt = full; cnt; cnt--) {
    322  1.15   tsutsui 				--dp;
    323  1.15   tsutsui 				--sp;
    324  1.15   tsutsui 				GETBITS(sp, sboff, 32, tmp);
    325  1.15   tsutsui 				*dp = tmp;
    326  1.15   tsutsui 				if (ri->ri_hwbits) {
    327  1.15   tsutsui 					--hp;
    328  1.15   tsutsui 					*hp = tmp;
    329  1.15   tsutsui 				}
    330   1.1        ad 			}
    331   1.1        ad 
    332   1.1        ad 			if (lmask) {
    333  1.15   tsutsui 				if (sbover)
    334  1.15   tsutsui 					--sp;
    335  1.15   tsutsui 				--dp;
    336   1.4        ad 				GETBITS(sp, sb, lnum, tmp);
    337  1.15   tsutsui 				PUTBITS(tmp, db, lnum, dp);
    338  1.12  macallan 				if (ri->ri_hwbits)
    339  1.15   tsutsui 					PUTBITS(tmp, db, lnum, hp);
    340   1.1        ad  			}
    341   1.1        ad  		}
    342   1.1        ad 	} else {
    343   1.4        ad 		/* Copy left-to-right */
    344  1.15   tsutsui 		srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
    345  1.15   tsutsui 		drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
    346  1.12  macallan 		if (ri->ri_hwbits)
    347  1.15   tsutsui 			dhp = (uint32_t *)(ri->ri_hwbits + row +
    348  1.12  macallan 			    ((dst >> 3) & ~3));
    349   1.1        ad 		db = dst & 31;
    350   1.1        ad 
    351   1.1        ad 		while (height--) {
    352   1.1        ad 			sb = src & 31;
    353   1.1        ad 			sp = srp;
    354   1.1        ad 			dp = drp;
    355  1.12  macallan 			if (ri->ri_hwbits) {
    356  1.12  macallan 				hp = dhp;
    357  1.15   tsutsui 				DELTA(dhp, ri->ri_stride, uint32_t *);
    358  1.12  macallan 			}
    359  1.15   tsutsui 			DELTA(srp, ri->ri_stride, uint32_t *);
    360  1.15   tsutsui 			DELTA(drp, ri->ri_stride, uint32_t *);
    361   1.6        pk 
    362   1.1        ad 			if (lmask) {
    363   1.1        ad 				GETBITS(sp, sb, lnum, tmp);
    364   1.1        ad 				PUTBITS(tmp, db, lnum, dp);
    365   1.1        ad 				dp++;
    366  1.12  macallan 				if (ri->ri_hwbits) {
    367  1.12  macallan 					PUTBITS(tmp, db, lnum, hp);
    368  1.12  macallan 					hp++;
    369  1.12  macallan 				}
    370   1.6        pk 
    371   1.1        ad 				if ((sb += lnum) > 31) {
    372   1.1        ad 					sp++;
    373   1.1        ad 					sb -= 32;
    374   1.1        ad 				}
    375   1.1        ad 			}
    376   1.6        pk 
    377   1.4        ad 			/* Now aligned to 32-bits wrt dp */
    378   1.4        ad 			for (cnt = full; cnt; cnt--, sp++) {
    379   1.1        ad 				GETBITS(sp, sb, 32, tmp);
    380   1.1        ad 				*dp++ = tmp;
    381  1.12  macallan 				if (ri->ri_hwbits)
    382  1.12  macallan 					*hp++ = tmp;
    383   1.1        ad 			}
    384   1.1        ad 
    385   1.1        ad 			if (rmask) {
    386   1.1        ad 				GETBITS(sp, sb, rnum, tmp);
    387   1.1        ad 				PUTBITS(tmp, 0, rnum, dp);
    388  1.12  macallan 				if (ri->ri_hwbits)
    389  1.12  macallan 					PUTBITS(tmp, 0, rnum, hp);
    390   1.1        ad  			}
    391   1.1        ad  		}
    392   1.1        ad  	}
    393   1.1        ad }
    394   1.5        ad 
    395   1.1        ad #endif /* _RASOPS_BITOPS_H_ */
    396