1 /* $NetBSD: rasops_bitops.h,v 1.10 2008/04/28 20:23:56 martin Exp $ */
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #ifndef _RASOPS_BITOPS_H_
33 #define _RASOPS_BITOPS_H_ 1
39 NAME(erasecols
)(void *cookie
, int row
, int col
, int num
, long attr
)
41 int lmask
, rmask
, lclr
, rclr
, clr
;
42 struct rasops_info
*ri
;
46 ri
= (struct rasops_info
*)cookie
;
48 #ifdef RASOPS_CLIPPING
49 if ((unsigned)row
>= (unsigned)ri
->ri_rows
)
57 if ((col
+ num
) > ri
->ri_cols
)
58 num
= ri
->ri_cols
- col
;
63 col
*= ri
->ri_font
->fontwidth
<< PIXEL_SHIFT
;
64 num
*= ri
->ri_font
->fontwidth
<< PIXEL_SHIFT
;
65 height
= ri
->ri_font
->fontheight
;
66 clr
= ri
->ri_devcmap
[(attr
>> 16) & 0xf];
67 rp
= (int32_t *)(ri
->ri_bits
+ row
*ri
->ri_yscale
+ ((col
>> 3) & ~3));
69 if ((col
& 31) + num
<= 32) {
70 lmask
= ~rasops_pmask
[col
& 31][num
];
75 DELTA(rp
, ri
->ri_stride
, int32_t *);
77 *dp
= (*dp
& lmask
) | lclr
;
80 lmask
= rasops_rmask
[col
& 31];
81 rmask
= rasops_lmask
[(col
+ num
) & 31];
84 num
= (num
- (32 - (col
& 31))) >> 5;
93 DELTA(rp
, ri
->ri_stride
, int32_t *);
96 *dp
= (*dp
& lmask
) | lclr
;
100 for (cnt
= num
; cnt
> 0; cnt
--)
104 *dp
= (*dp
& rmask
) | rclr
;
110 * Actually paint the cursor.
113 NAME(do_cursor
)(struct rasops_info
*ri
)
115 int lmask
, rmask
, height
, row
, col
, num
;
119 col
= ri
->ri_ccol
* ri
->ri_font
->fontwidth
<< PIXEL_SHIFT
;
120 height
= ri
->ri_font
->fontheight
;
121 num
= ri
->ri_font
->fontwidth
<< PIXEL_SHIFT
;
122 rp
= (int32_t *)(ri
->ri_bits
+ row
* ri
->ri_yscale
+ ((col
>> 3) & ~3));
124 if ((col
& 31) + num
<= 32) {
125 lmask
= rasops_pmask
[col
& 31][num
];
129 DELTA(rp
, ri
->ri_stride
, int32_t *);
133 lmask
= ~rasops_rmask
[col
& 31];
134 rmask
= ~rasops_lmask
[(col
+ num
) & 31];
138 DELTA(rp
, ri
->ri_stride
, int32_t *);
153 NAME(copycols
)(void *cookie
, int row
, int src
, int dst
, int num
)
155 int tmp
, lmask
, rmask
, height
, lnum
, rnum
, sb
, db
, cnt
, full
;
156 int32_t *sp
, *dp
, *srp
, *drp
;
157 struct rasops_info
*ri
;
159 sp
= NULL
; /* XXX gcc */
161 ri
= (struct rasops_info
*)cookie
;
163 #ifdef RASOPS_CLIPPING
167 /* Catches < 0 case too */
168 if ((unsigned)row
>= (unsigned)ri
->ri_rows
)
176 if ((src
+ num
) > ri
->ri_cols
)
177 num
= ri
->ri_cols
- src
;
184 if ((dst
+ num
) > ri
->ri_cols
)
185 num
= ri
->ri_cols
- dst
;
191 cnt
= ri
->ri_font
->fontwidth
<< PIXEL_SHIFT
;
195 row
*= ri
->ri_yscale
;
196 height
= ri
->ri_font
->fontheight
;
199 if (db
+ num
<= 32) {
200 /* Destination is contained within a single word */
201 srp
= (int32_t *)(ri
->ri_bits
+ row
+ ((src
>> 3) & ~3));
202 drp
= (int32_t *)(ri
->ri_bits
+ row
+ ((dst
>> 3) & ~3));
206 GETBITS(srp
, sb
, num
, tmp
);
207 PUTBITS(tmp
, db
, num
, drp
);
208 DELTA(srp
, ri
->ri_stride
, int32_t *);
209 DELTA(drp
, ri
->ri_stride
, int32_t *);
215 lmask
= rasops_rmask
[db
];
216 rmask
= rasops_lmask
[(dst
+ num
) & 31];
217 lnum
= (32 - db
) & 31;
218 rnum
= (dst
+ num
) & 31;
221 full
= (num
- (32 - (dst
& 31))) >> 5;
225 if (src
< dst
&& src
+ num
> dst
) {
226 /* Copy right-to-left */
230 srp
= (int32_t *)(ri
->ri_bits
+ row
+ ((src
>> 3) & ~3));
231 drp
= (int32_t *)(ri
->ri_bits
+ row
+ ((dst
>> 3) & ~3));
237 if ((src
-= db
) < 0) {
245 DELTA(srp
, ri
->ri_stride
, int32_t *);
246 DELTA(drp
, ri
->ri_stride
, int32_t *);
249 GETBITS(sp
, src
, db
, tmp
);
250 PUTBITS(tmp
, 0, db
, dp
);
255 /* Now aligned to 32-bits wrt dp */
256 for (cnt
= full
; cnt
; cnt
--, sp
--) {
257 GETBITS(sp
, src
, 32, tmp
);
266 GETBITS(sp
, sb
, lnum
, tmp
);
267 PUTBITS(tmp
, rnum
, lnum
, dp
);
271 /* Copy left-to-right */
272 srp
= (int32_t *)(ri
->ri_bits
+ row
+ ((src
>> 3) & ~3));
273 drp
= (int32_t *)(ri
->ri_bits
+ row
+ ((dst
>> 3) & ~3));
280 DELTA(srp
, ri
->ri_stride
, int32_t *);
281 DELTA(drp
, ri
->ri_stride
, int32_t *);
284 GETBITS(sp
, sb
, lnum
, tmp
);
285 PUTBITS(tmp
, db
, lnum
, dp
);
288 if ((sb
+= lnum
) > 31) {
294 /* Now aligned to 32-bits wrt dp */
295 for (cnt
= full
; cnt
; cnt
--, sp
++) {
296 GETBITS(sp
, sb
, 32, tmp
);
301 GETBITS(sp
, sb
, rnum
, tmp
);
302 PUTBITS(tmp
, 0, rnum
, dp
);
308 #endif /* _RASOPS_BITOPS_H_ */