Home | History | Annotate | Line # | Download | only in rasops
rasops_bitops.h revision 1.22
      1  1.22       rin /* 	$NetBSD: rasops_bitops.h,v 1.22 2019/08/02 04:35:54 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.19       rin 	struct rasops_info *ri = (struct rasops_info *)cookie;
     42  1.19       rin 	uint32_t lclr, rclr, clr;
     43  1.18       rin 	uint32_t *dp, *rp, *hp, tmp, lmask, rmask;
     44   1.1        ad 	int height, cnt;
     45   1.6        pk 
     46  1.18       rin 	hp = NULL;	/* XXX GCC */
     47  1.18       rin 
     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.19       rin 	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.20       rin 
     64   1.1        ad 	col *= ri->ri_font->fontwidth << PIXEL_SHIFT;
     65   1.1        ad 	num *= ri->ri_font->fontwidth << PIXEL_SHIFT;
     66   1.1        ad 	height = ri->ri_font->fontheight;
     67  1.17       rin 	clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
     68  1.15   tsutsui 	rp = (uint32_t *)(ri->ri_bits + row*ri->ri_yscale + ((col >> 3) & ~3));
     69  1.12  macallan 	if (ri->ri_hwbits)
     70  1.18       rin 		hp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
     71  1.12  macallan 		    ((col >> 3) & ~3));
     72  1.19       rin 	col &= 31;
     73  1.19       rin 
     74  1.19       rin 	if (col + num <= 32) {
     75  1.19       rin 		lmask = ~rasops_pmask[col][num & 31];
     76   1.1        ad 		lclr = clr & ~lmask;
     77   1.1        ad 
     78   1.1        ad 		while (height--) {
     79   1.1        ad 			dp = rp;
     80  1.15   tsutsui 			DELTA(rp, ri->ri_stride, uint32_t *);
     81   1.1        ad 
     82  1.12  macallan 			tmp = (*dp & lmask) | lclr;
     83  1.12  macallan 			*dp = tmp;
     84  1.12  macallan 			if (ri->ri_hwbits) {
     85  1.18       rin 				*hp = tmp;
     86  1.18       rin 				DELTA(hp, ri->ri_stride, uint32_t *);
     87  1.12  macallan 			}
     88   1.1        ad 		}
     89   1.1        ad 	} else {
     90  1.19       rin 		lmask = rasops_rmask[col];
     91   1.1        ad 		rmask = rasops_lmask[(col + num) & 31];
     92   1.6        pk 
     93   1.1        ad 		if (lmask)
     94  1.19       rin 			num = (num - (32 - col)) >> 5;
     95   1.1        ad 		else
     96   1.1        ad 			num = num >> 5;
     97   1.6        pk 
     98   1.1        ad 		lclr = clr & ~lmask;
     99   1.1        ad 		rclr = clr & ~rmask;
    100   1.1        ad 
    101   1.1        ad 		while (height--) {
    102   1.1        ad 			dp = rp;
    103   1.1        ad 
    104   1.8   thorpej 			if (lmask) {
    105  1.18       rin 				*dp = (*dp & lmask) | lclr;
    106   1.8   thorpej 				dp++;
    107   1.8   thorpej 			}
    108   1.1        ad 
    109   1.1        ad 			for (cnt = num; cnt > 0; cnt--)
    110   1.1        ad 				*dp++ = clr;
    111  1.18       rin 
    112  1.18       rin 			if (rmask)
    113  1.18       rin 				*dp = (*dp & rmask) | rclr;
    114  1.18       rin 
    115  1.12  macallan 			if (ri->ri_hwbits) {
    116  1.18       rin 				memcpy(hp, rp, ((lmask != 0) + num +
    117  1.18       rin 				    (rmask != 0)) << 2);
    118  1.18       rin 				DELTA(hp, ri->ri_stride, uint32_t *);
    119  1.12  macallan 			}
    120  1.18       rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    121   1.1        ad 		}
    122   1.1        ad 	}
    123   1.1        ad }
    124   1.1        ad 
    125   1.1        ad /*
    126   1.1        ad  * Actually paint the cursor.
    127   1.1        ad  */
    128   1.1        ad static void
    129  1.11    cegger NAME(do_cursor)(struct rasops_info *ri)
    130   1.1        ad {
    131  1.19       rin 	int height, row, col, num, cnt;
    132  1.19       rin 	uint32_t *dp, *rp, *hp, tmp, lmask, rmask;
    133  1.18       rin 
    134  1.19       rin 	hp = NULL;	/* XXX GCC */
    135   1.6        pk 
    136   1.1        ad 	row = ri->ri_crow;
    137   1.1        ad 	col = ri->ri_ccol * ri->ri_font->fontwidth << PIXEL_SHIFT;
    138   1.1        ad 	height = ri->ri_font->fontheight;
    139   1.1        ad 	num = ri->ri_font->fontwidth << PIXEL_SHIFT;
    140  1.16       rin 	rp = (uint32_t *)(ri->ri_bits + row * ri->ri_yscale +
    141  1.16       rin 	    ((col >> 3) & ~3));
    142  1.12  macallan 	if (ri->ri_hwbits)
    143  1.19       rin 		hp = (uint32_t *)(ri->ri_hwbits + row * ri->ri_yscale +
    144  1.12  macallan 		    ((col >> 3) & ~3));
    145  1.19       rin 	col &= 31;
    146   1.6        pk 
    147  1.19       rin 	if (col + num <= 32) {
    148  1.19       rin 		lmask = rasops_pmask[col][num & 31];
    149   1.1        ad 
    150   1.1        ad 		while (height--) {
    151  1.18       rin 			tmp = *rp ^ lmask;
    152  1.18       rin 			*rp = tmp;
    153  1.18       rin 			if (ri->ri_hwbits) {
    154  1.19       rin 				*hp = tmp;
    155  1.19       rin 				DELTA(hp, ri->ri_stride, uint32_t *);
    156  1.12  macallan 			}
    157  1.18       rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    158  1.12  macallan 		}
    159   1.1        ad 	} else {
    160  1.19       rin 		lmask = ~rasops_rmask[col];
    161   1.1        ad 		rmask = ~rasops_lmask[(col + num) & 31];
    162   1.1        ad 
    163  1.19       rin 		if (lmask != -1)
    164  1.19       rin 			num = (num - (32 - col)) >> 5;
    165  1.19       rin 		else
    166  1.19       rin 			num = num >> 5;
    167  1.19       rin 
    168   1.1        ad 		while (height--) {
    169   1.1        ad 			dp = rp;
    170  1.19       rin 
    171  1.19       rin 			if (lmask != -1) {
    172  1.19       rin 				*dp = *dp ^ lmask;
    173  1.19       rin 				dp++;
    174  1.12  macallan 			}
    175  1.18       rin 
    176  1.19       rin 			for (cnt = num; cnt; cnt--) {
    177  1.19       rin 				*dp = ~*dp;
    178  1.12  macallan 				dp++;
    179  1.12  macallan 			}
    180   1.1        ad 
    181  1.19       rin 			if (rmask != -1)
    182  1.19       rin 				*dp = *dp ^ rmask;
    183  1.19       rin 
    184  1.19       rin 			if (ri->ri_hwbits) {
    185  1.19       rin 				memcpy(hp, rp, ((lmask != -1) + num +
    186  1.19       rin 				    (rmask != -1)) << 2);
    187  1.19       rin 				DELTA(hp, ri->ri_stride, uint32_t *);
    188  1.12  macallan 			}
    189  1.20       rin 
    190  1.19       rin 			DELTA(rp, ri->ri_stride, uint32_t *);
    191   1.1        ad 		}
    192   1.1        ad 	}
    193   1.1        ad }
    194   1.1        ad 
    195   1.1        ad /*
    196   1.4        ad  * Copy columns. Ick!
    197   1.1        ad  */
    198   1.1        ad static void
    199  1.11    cegger NAME(copycols)(void *cookie, int row, int src, int dst, int num)
    200   1.1        ad {
    201  1.18       rin 	struct rasops_info *ri = (struct rasops_info *)cookie;
    202  1.15   tsutsui 	int height, lnum, rnum, sb, db, cnt, full;
    203  1.15   tsutsui 	uint32_t tmp, lmask, rmask;
    204  1.18       rin 	uint32_t *sp, *dp, *srp, *drp, *dhp, *hp;
    205   1.6        pk 
    206  1.18       rin 	dhp = hp = NULL;	/* XXX GCC */
    207   1.1        ad 
    208   1.1        ad #ifdef RASOPS_CLIPPING
    209   1.1        ad 	if (dst == src)
    210   1.1        ad 		return;
    211   1.6        pk 
    212   1.1        ad 	/* Catches < 0 case too */
    213   1.1        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    214   1.1        ad 		return;
    215   1.6        pk 
    216   1.1        ad 	if (src < 0) {
    217   1.1        ad 		num += src;
    218   1.1        ad 		src = 0;
    219   1.1        ad 	}
    220   1.1        ad 
    221  1.18       rin 	if (src + num > ri->ri_cols)
    222   1.1        ad 		num = ri->ri_cols - src;
    223   1.1        ad 
    224   1.1        ad 	if (dst < 0) {
    225   1.1        ad 		num += dst;
    226   1.1        ad 		dst = 0;
    227   1.1        ad 	}
    228   1.1        ad 
    229  1.18       rin 	if (dst + num > ri->ri_cols)
    230   1.1        ad 		num = ri->ri_cols - dst;
    231   1.6        pk 
    232   1.1        ad 	if (num <= 0)
    233   1.1        ad 		return;
    234   1.1        ad #endif
    235   1.6        pk 
    236   1.1        ad 	cnt = ri->ri_font->fontwidth << PIXEL_SHIFT;
    237   1.1        ad 	src *= cnt;
    238   1.1        ad 	dst *= cnt;
    239   1.1        ad 	num *= cnt;
    240   1.1        ad 	row *= ri->ri_yscale;
    241   1.1        ad 	height = ri->ri_font->fontheight;
    242   1.4        ad 	db = dst & 31;
    243   1.1        ad 
    244   1.6        pk 	if (db + num <= 32) {
    245   1.4        ad 		/* Destination is contained within a single word */
    246  1.15   tsutsui 		srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
    247  1.15   tsutsui 		drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
    248  1.12  macallan 		if (ri->ri_hwbits)
    249  1.15   tsutsui 			dhp = (uint32_t *)(ri->ri_hwbits + row +
    250  1.12  macallan 			    ((dst >> 3) & ~3));
    251   1.1        ad 		sb = src & 31;
    252   1.1        ad 
    253   1.1        ad 		while (height--) {
    254   1.1        ad 			GETBITS(srp, sb, num, tmp);
    255   1.1        ad 			PUTBITS(tmp, db, num, drp);
    256  1.12  macallan 			if (ri->ri_hwbits) {
    257  1.12  macallan 				PUTBITS(tmp, db, num, dhp);
    258  1.15   tsutsui 				DELTA(dhp, ri->ri_stride, uint32_t *);
    259  1.12  macallan 			}
    260  1.15   tsutsui 			DELTA(srp, ri->ri_stride, uint32_t *);
    261  1.15   tsutsui 			DELTA(drp, ri->ri_stride, uint32_t *);
    262   1.1        ad 		}
    263   1.6        pk 
    264   1.1        ad 		return;
    265   1.1        ad 	}
    266   1.1        ad 
    267   1.4        ad 	lmask = rasops_rmask[db];
    268   1.1        ad 	rmask = rasops_lmask[(dst + num) & 31];
    269   1.4        ad 	lnum = (32 - db) & 31;
    270   1.6        pk 	rnum = (dst + num) & 31;
    271   1.6        pk 
    272   1.1        ad 	if (lmask)
    273  1.21       rin 		full = (num - lnum) >> 5;
    274   1.1        ad 	else
    275   1.1        ad 		full = num >> 5;
    276   1.1        ad 
    277   1.4        ad 	if (src < dst && src + num > dst) {
    278   1.4        ad 		/* Copy right-to-left */
    279  1.15   tsutsui 		bool sbover;
    280  1.15   tsutsui 		int sboff;
    281  1.15   tsutsui 
    282  1.15   tsutsui 		srp = (uint32_t *)(ri->ri_bits + row +
    283  1.15   tsutsui 		    (((src + num) >> 3) & ~3));
    284  1.15   tsutsui 		drp = (uint32_t *)(ri->ri_bits + row +
    285  1.15   tsutsui 		    (((dst + num) >> 3) & ~3));
    286  1.12  macallan 		if (ri->ri_hwbits)
    287  1.15   tsutsui 			dhp = (uint32_t *)(ri->ri_hwbits + row +
    288  1.15   tsutsui 			    (((dst + num) >> 3) & ~3));
    289   1.1        ad 
    290  1.15   tsutsui 		sb = src & 31;
    291  1.15   tsutsui 		sbover = (sb + lnum) >= 32;
    292  1.15   tsutsui 		sboff = (src + num) & 31;
    293  1.15   tsutsui 		if ((sboff -= rnum) < 0) {
    294  1.14   tsutsui 			srp--;
    295  1.15   tsutsui 			sboff += 32;
    296   1.4        ad 		}
    297   1.6        pk 
    298   1.1        ad 		while (height--) {
    299   1.1        ad 			sp = srp;
    300   1.1        ad 			dp = drp;
    301   1.6        pk 
    302  1.15   tsutsui 			if (rnum) {
    303  1.15   tsutsui 				GETBITS(sp, sboff, rnum, tmp);
    304  1.15   tsutsui 				PUTBITS(tmp, 0, rnum, dp);
    305   1.1        ad 			}
    306   1.1        ad 
    307   1.4        ad 			/* Now aligned to 32-bits wrt dp */
    308  1.15   tsutsui 			for (cnt = full; cnt; cnt--) {
    309  1.15   tsutsui 				--dp;
    310  1.15   tsutsui 				--sp;
    311  1.15   tsutsui 				GETBITS(sp, sboff, 32, tmp);
    312  1.15   tsutsui 				*dp = tmp;
    313   1.1        ad 			}
    314   1.1        ad 
    315   1.1        ad 			if (lmask) {
    316  1.15   tsutsui 				if (sbover)
    317  1.15   tsutsui 					--sp;
    318  1.15   tsutsui 				--dp;
    319   1.4        ad 				GETBITS(sp, sb, lnum, tmp);
    320  1.15   tsutsui 				PUTBITS(tmp, db, lnum, dp);
    321   1.1        ad  			}
    322  1.18       rin 
    323  1.18       rin 			if (ri->ri_hwbits) {
    324  1.18       rin 				hp = dhp;
    325  1.22       rin 				hp -= (lmask != 0) + full;
    326  1.22       rin 				memcpy(hp, dp, ((lmask != 0) + full +
    327  1.22       rin 				    (rnum != 0)) << 2);
    328  1.18       rin 				DELTA(dhp, ri->ri_stride, uint32_t *);
    329  1.18       rin 			}
    330  1.22       rin 
    331  1.22       rin 			DELTA(srp, ri->ri_stride, uint32_t *);
    332  1.22       rin 			DELTA(drp, ri->ri_stride, uint32_t *);
    333   1.1        ad  		}
    334   1.1        ad 	} else {
    335   1.4        ad 		/* Copy left-to-right */
    336  1.15   tsutsui 		srp = (uint32_t *)(ri->ri_bits + row + ((src >> 3) & ~3));
    337  1.15   tsutsui 		drp = (uint32_t *)(ri->ri_bits + row + ((dst >> 3) & ~3));
    338  1.12  macallan 		if (ri->ri_hwbits)
    339  1.15   tsutsui 			dhp = (uint32_t *)(ri->ri_hwbits + row +
    340  1.12  macallan 			    ((dst >> 3) & ~3));
    341   1.1        ad 
    342   1.1        ad 		while (height--) {
    343   1.1        ad 			sb = src & 31;
    344   1.1        ad 			sp = srp;
    345   1.1        ad 			dp = drp;
    346   1.6        pk 
    347   1.1        ad 			if (lmask) {
    348   1.1        ad 				GETBITS(sp, sb, lnum, tmp);
    349   1.1        ad 				PUTBITS(tmp, db, lnum, dp);
    350   1.1        ad 				dp++;
    351   1.6        pk 
    352  1.20       rin 				sb += lnum;
    353  1.20       rin 				if (sb > 31) {
    354   1.1        ad 					sp++;
    355   1.1        ad 					sb -= 32;
    356   1.1        ad 				}
    357   1.1        ad 			}
    358   1.6        pk 
    359   1.4        ad 			/* Now aligned to 32-bits wrt dp */
    360   1.4        ad 			for (cnt = full; cnt; cnt--, sp++) {
    361   1.1        ad 				GETBITS(sp, sb, 32, tmp);
    362   1.1        ad 				*dp++ = tmp;
    363   1.1        ad 			}
    364   1.1        ad 
    365   1.1        ad 			if (rmask) {
    366   1.1        ad 				GETBITS(sp, sb, rnum, tmp);
    367   1.1        ad 				PUTBITS(tmp, 0, rnum, dp);
    368   1.1        ad  			}
    369  1.18       rin 
    370  1.18       rin 			if (ri->ri_hwbits) {
    371  1.18       rin 				memcpy(dhp, drp, ((lmask != 0) + full +
    372  1.18       rin 				    (rmask != 0)) << 2);
    373  1.18       rin 				DELTA(dhp, ri->ri_stride, uint32_t *);
    374  1.18       rin 			}
    375  1.18       rin 
    376  1.18       rin 			DELTA(srp, ri->ri_stride, uint32_t *);
    377  1.18       rin 			DELTA(drp, ri->ri_stride, uint32_t *);
    378   1.1        ad  		}
    379   1.1        ad  	}
    380   1.1        ad }
    381   1.5        ad 
    382   1.1        ad #endif /* _RASOPS_BITOPS_H_ */
    383