Home | History | Annotate | Line # | Download | only in rasops
rasops.c revision 1.61.2.1
      1  1.61.2.1  uebayasi /*	 $NetBSD: rasops.c,v 1.61.2.1 2010/04/30 14:43:47 uebayasi Exp $	*/
      2       1.1        ad 
      3       1.9        ad /*-
      4       1.9        ad  * Copyright (c) 1999 The NetBSD Foundation, Inc.
      5       1.1        ad  * All rights reserved.
      6       1.1        ad  *
      7       1.9        ad  * This code is derived from software contributed to The NetBSD Foundation
      8      1.32        ad  * by Andrew Doran.
      9       1.9        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.9        ad  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.9        ad  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.9        ad  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.9        ad  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.9        ad  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.9        ad  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.9        ad  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.9        ad  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.9        ad  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.9        ad  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.9        ad  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1        ad  */
     31       1.2        ad 
     32       1.1        ad #include <sys/cdefs.h>
     33  1.61.2.1  uebayasi __KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.61.2.1 2010/04/30 14:43:47 uebayasi Exp $");
     34       1.1        ad 
     35      1.18        ad #include "opt_rasops.h"
     36       1.4        ad #include "rasops_glue.h"
     37      1.47  macallan #include "opt_wsmsgattrs.h"
     38       1.1        ad 
     39       1.1        ad #include <sys/param.h>
     40       1.1        ad #include <sys/systm.h>
     41       1.1        ad #include <sys/time.h>
     42       1.1        ad 
     43      1.50       dsl #include <sys/bswap.h>
     44       1.4        ad #include <machine/endian.h>
     45       1.3        ad 
     46       1.1        ad #include <dev/wscons/wsdisplayvar.h>
     47       1.1        ad #include <dev/wscons/wsconsio.h>
     48       1.1        ad #include <dev/wsfont/wsfont.h>
     49       1.1        ad #include <dev/rasops/rasops.h>
     50       1.1        ad 
     51      1.11        ad #ifndef _KERNEL
     52      1.11        ad #include <errno.h>
     53      1.11        ad #endif
     54      1.11        ad 
     55       1.1        ad /* ANSI colormap (R,G,B). Upper 8 are high-intensity */
     56      1.23  drochner const u_char rasops_cmap[256*3] = {
     57       1.1        ad 	0x00, 0x00, 0x00, /* black */
     58       1.1        ad 	0x7f, 0x00, 0x00, /* red */
     59       1.1        ad 	0x00, 0x7f, 0x00, /* green */
     60       1.1        ad 	0x7f, 0x7f, 0x00, /* brown */
     61       1.1        ad 	0x00, 0x00, 0x7f, /* blue */
     62       1.1        ad 	0x7f, 0x00, 0x7f, /* magenta */
     63       1.1        ad 	0x00, 0x7f, 0x7f, /* cyan */
     64       1.1        ad 	0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
     65       1.1        ad 
     66       1.1        ad 	0x7f, 0x7f, 0x7f, /* black */
     67       1.1        ad 	0xff, 0x00, 0x00, /* red */
     68       1.1        ad 	0x00, 0xff, 0x00, /* green */
     69       1.1        ad 	0xff, 0xff, 0x00, /* brown */
     70       1.1        ad 	0x00, 0x00, 0xff, /* blue */
     71       1.1        ad 	0xff, 0x00, 0xff, /* magenta */
     72       1.1        ad 	0x00, 0xff, 0xff, /* cyan */
     73       1.1        ad 	0xff, 0xff, 0xff, /* white */
     74      1.23  drochner 
     75      1.23  drochner 	/*
     76      1.23  drochner 	 * For the cursor, we need at least the last (255th)
     77      1.23  drochner 	 * color to be white. Fill up white completely for
     78      1.23  drochner 	 * simplicity.
     79      1.23  drochner 	 */
     80      1.23  drochner #define _CMWHITE 0xff, 0xff, 0xff,
     81      1.23  drochner #define _CMWHITE16	_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     82      1.23  drochner 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     83      1.23  drochner 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE \
     84      1.23  drochner 			_CMWHITE _CMWHITE _CMWHITE _CMWHITE
     85      1.23  drochner 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
     86      1.23  drochner 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16
     87      1.44       uwe 	_CMWHITE16 _CMWHITE16 _CMWHITE16 _CMWHITE16 /* but not the last one */
     88      1.23  drochner #undef _CMWHITE16
     89      1.23  drochner #undef _CMWHITE
     90      1.44       uwe 
     91      1.44       uwe 	/*
     92      1.44       uwe 	 * For the cursor the fg/bg indices are bit inverted, so
     93      1.44       uwe 	 * provide complimentary colors in the upper 16 entries.
     94      1.44       uwe 	 */
     95      1.44       uwe 	0x7f, 0x7f, 0x7f, /* black */
     96      1.44       uwe 	0xff, 0x00, 0x00, /* red */
     97      1.44       uwe 	0x00, 0xff, 0x00, /* green */
     98      1.44       uwe 	0xff, 0xff, 0x00, /* brown */
     99      1.44       uwe 	0x00, 0x00, 0xff, /* blue */
    100      1.44       uwe 	0xff, 0x00, 0xff, /* magenta */
    101      1.44       uwe 	0x00, 0xff, 0xff, /* cyan */
    102      1.44       uwe 	0xff, 0xff, 0xff, /* white */
    103      1.44       uwe 
    104      1.44       uwe 	0x00, 0x00, 0x00, /* black */
    105      1.44       uwe 	0x7f, 0x00, 0x00, /* red */
    106      1.44       uwe 	0x00, 0x7f, 0x00, /* green */
    107      1.44       uwe 	0x7f, 0x7f, 0x00, /* brown */
    108      1.44       uwe 	0x00, 0x00, 0x7f, /* blue */
    109      1.44       uwe 	0x7f, 0x00, 0x7f, /* magenta */
    110      1.44       uwe 	0x00, 0x7f, 0x7f, /* cyan */
    111      1.44       uwe 	0xc7, 0xc7, 0xc7, /* white - XXX too dim? */
    112       1.1        ad };
    113       1.1        ad 
    114       1.1        ad /* True if color is gray */
    115      1.30        pk const u_char rasops_isgray[16] = {
    116      1.30        pk 	1, 0, 0, 0,
    117       1.1        ad 	0, 0, 0, 1,
    118       1.1        ad 	1, 0, 0, 0,
    119       1.1        ad 	0, 0, 0, 1
    120       1.1        ad };
    121       1.1        ad 
    122       1.4        ad /* Generic functions */
    123      1.45     perry static void	rasops_copyrows(void *, int, int, int);
    124      1.45     perry static int	rasops_mapchar(void *, int, u_int *);
    125      1.45     perry static void	rasops_cursor(void *, int, int, int);
    126      1.45     perry static int	rasops_allocattr_color(void *, int, int, int, long *);
    127      1.45     perry static int	rasops_allocattr_mono(void *, int, int, int, long *);
    128      1.45     perry static void	rasops_do_cursor(struct rasops_info *);
    129      1.45     perry static void	rasops_init_devcmap(struct rasops_info *);
    130       1.1        ad 
    131      1.55      ober #if NRASOPS_ROTATION > 0
    132  1.61.2.1  uebayasi static void	rasops_rotate_font(int *, int);
    133      1.55      ober static void	rasops_copychar(void *, int, int, int, int);
    134  1.61.2.1  uebayasi 
    135  1.61.2.1  uebayasi /* rotate clockwise */
    136  1.61.2.1  uebayasi static void	rasops_copycols_rotated_cw(void *, int, int, int, int);
    137  1.61.2.1  uebayasi static void	rasops_copyrows_rotated_cw(void *, int, int, int);
    138  1.61.2.1  uebayasi static void	rasops_erasecols_rotated_cw(void *, int, int, int, long);
    139  1.61.2.1  uebayasi static void	rasops_eraserows_rotated_cw(void *, int, int, long);
    140  1.61.2.1  uebayasi static void	rasops_putchar_rotated_cw(void *, int, int, u_int, long);
    141  1.61.2.1  uebayasi 
    142  1.61.2.1  uebayasi /* rotate counter-clockwise */
    143  1.61.2.1  uebayasi static void	rasops_copychar_ccw(void *, int, int, int, int);
    144  1.61.2.1  uebayasi static void	rasops_copycols_rotated_ccw(void *, int, int, int, int);
    145  1.61.2.1  uebayasi static void	rasops_copyrows_rotated_ccw(void *, int, int, int);
    146  1.61.2.1  uebayasi #define rasops_erasecols_rotated_ccw rasops_erasecols_rotated_cw
    147  1.61.2.1  uebayasi #define rasops_eraserows_rotated_ccw rasops_eraserows_rotated_cw
    148  1.61.2.1  uebayasi static void	rasops_putchar_rotated_ccw(void *, int, int, u_int, long);
    149      1.55      ober 
    150      1.55      ober /*
    151      1.55      ober  * List of all rotated fonts
    152      1.55      ober  */
    153      1.55      ober SLIST_HEAD(, rotatedfont) rotatedfonts = SLIST_HEAD_INITIALIZER(rotatedfonts);
    154      1.55      ober struct rotatedfont {
    155      1.55      ober 	SLIST_ENTRY(rotatedfont) rf_next;
    156      1.55      ober 	int rf_cookie;
    157      1.55      ober 	int rf_rotated;
    158      1.55      ober };
    159      1.55      ober #endif	/* NRASOPS_ROTATION > 0 */
    160      1.55      ober 
    161       1.1        ad /*
    162      1.37       wiz  * Initialize a 'rasops_info' descriptor.
    163       1.1        ad  */
    164       1.1        ad int
    165      1.60       dsl rasops_init(struct rasops_info *ri, int wantrows, int wantcols)
    166       1.1        ad {
    167      1.20        ad 
    168      1.30        pk #ifdef _KERNEL
    169       1.1        ad 	/* Select a font if the caller doesn't care */
    170       1.1        ad 	if (ri->ri_font == NULL) {
    171       1.1        ad 		int cookie;
    172      1.30        pk 
    173       1.1        ad 		wsfont_init();
    174       1.1        ad 
    175       1.1        ad 		/* Want 8 pixel wide, don't care about aestethics */
    176      1.39        ad 		cookie = wsfont_find(NULL, 8, 0, 0, WSDISPLAY_FONTORDER_L2R,
    177      1.39        ad 		    WSDISPLAY_FONTORDER_L2R);
    178      1.39        ad 		if (cookie <= 0)
    179      1.39        ad 			cookie = wsfont_find(NULL, 0, 0, 0,
    180      1.39        ad 			    WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R);
    181       1.1        ad 
    182       1.7        ad 		if (cookie <= 0) {
    183       1.1        ad 			printf("rasops_init: font table is empty\n");
    184       1.1        ad 			return (-1);
    185       1.1        ad 		}
    186      1.30        pk 
    187      1.55      ober #if NRASOPS_ROTATION > 0
    188      1.55      ober 		/*
    189      1.55      ober 		 * Pick the rotated version of this font. This will create it
    190      1.55      ober 		 * if necessary.
    191      1.55      ober 		 */
    192  1.61.2.1  uebayasi 		if (ri->ri_flg & RI_ROTATE_MASK) {
    193  1.61.2.1  uebayasi 			if (ri->ri_flg & RI_ROTATE_CW)
    194  1.61.2.1  uebayasi 				rasops_rotate_font(&cookie, WSFONT_ROTATE_CW);
    195  1.61.2.1  uebayasi 			else if (ri->ri_flg & RI_ROTATE_CCW)
    196  1.61.2.1  uebayasi 				rasops_rotate_font(&cookie, WSFONT_ROTATE_CCW);
    197  1.61.2.1  uebayasi 		}
    198      1.55      ober #endif
    199      1.55      ober 
    200      1.39        ad 		if (wsfont_lock(cookie, &ri->ri_font)) {
    201       1.1        ad 			printf("rasops_init: couldn't lock font\n");
    202       1.1        ad 			return (-1);
    203       1.1        ad 		}
    204       1.8        ad 
    205       1.5        ad 		ri->ri_wsfcookie = cookie;
    206       1.1        ad 	}
    207       1.4        ad #endif
    208      1.30        pk 
    209       1.1        ad 	/* This should never happen in reality... */
    210       1.1        ad #ifdef DEBUG
    211      1.31  sommerfe 	if ((long)ri->ri_bits & 3) {
    212       1.1        ad 		printf("rasops_init: bits not aligned on 32-bit boundary\n");
    213       1.1        ad 		return (-1);
    214       1.1        ad 	}
    215       1.1        ad 
    216       1.1        ad 	if ((int)ri->ri_stride & 3) {
    217       1.1        ad 		printf("rasops_init: stride not aligned on 32-bit boundary\n");
    218       1.1        ad 		return (-1);
    219       1.1        ad 	}
    220       1.1        ad #endif
    221       1.4        ad 
    222      1.13        ad 	if (rasops_reconfig(ri, wantrows, wantcols))
    223       1.4        ad 		return (-1);
    224      1.46     perry 
    225       1.4        ad 	rasops_init_devcmap(ri);
    226       1.4        ad 	return (0);
    227       1.4        ad }
    228       1.4        ad 
    229       1.4        ad /*
    230      1.13        ad  * Reconfigure (because parameters have changed in some way).
    231       1.4        ad  */
    232       1.4        ad int
    233      1.60       dsl rasops_reconfig(struct rasops_info *ri, int wantrows, int wantcols)
    234       1.4        ad {
    235      1.20        ad 	int bpp, s;
    236      1.30        pk 
    237      1.13        ad 	s = splhigh();
    238      1.30        pk 
    239       1.4        ad 	if (ri->ri_font->fontwidth > 32 || ri->ri_font->fontwidth < 4)
    240      1.42    provos 		panic("rasops_init: fontwidth assumptions botched!");
    241      1.30        pk 
    242       1.4        ad 	/* Need this to frob the setup below */
    243       1.4        ad 	bpp = (ri->ri_depth == 15 ? 16 : ri->ri_depth);
    244       1.4        ad 
    245      1.13        ad 	if ((ri->ri_flg & RI_CFGDONE) != 0)
    246       1.4        ad 		ri->ri_bits = ri->ri_origbits;
    247      1.30        pk 
    248       1.1        ad 	/* Don't care if the caller wants a hideously small console */
    249       1.1        ad 	if (wantrows < 10)
    250      1.13        ad 		wantrows = 10;
    251      1.30        pk 
    252       1.1        ad 	if (wantcols < 20)
    253      1.13        ad 		wantcols = 20;
    254      1.30        pk 
    255       1.1        ad 	/* Now constrain what they get */
    256       1.1        ad 	ri->ri_emuwidth = ri->ri_font->fontwidth * wantcols;
    257       1.1        ad 	ri->ri_emuheight = ri->ri_font->fontheight * wantrows;
    258      1.30        pk 
    259       1.1        ad 	if (ri->ri_emuwidth > ri->ri_width)
    260       1.1        ad 		ri->ri_emuwidth = ri->ri_width;
    261      1.30        pk 
    262       1.1        ad 	if (ri->ri_emuheight > ri->ri_height)
    263       1.1        ad 		ri->ri_emuheight = ri->ri_height;
    264      1.30        pk 
    265       1.1        ad 	/* Reduce width until aligned on a 32-bit boundary */
    266      1.20        ad 	while ((ri->ri_emuwidth * bpp & 31) != 0)
    267       1.1        ad 		ri->ri_emuwidth--;
    268      1.30        pk 
    269      1.55      ober #if NRASOPS_ROTATION > 0
    270  1.61.2.1  uebayasi 	if (ri->ri_flg & (RI_ROTATE_CW|RI_ROTATE_CCW)) {
    271      1.55      ober 		ri->ri_rows = ri->ri_emuwidth / ri->ri_font->fontwidth;
    272      1.55      ober 		ri->ri_cols = ri->ri_emuheight / ri->ri_font->fontheight;
    273      1.55      ober 	} else
    274      1.55      ober #endif
    275      1.55      ober 	{
    276      1.55      ober 
    277      1.55      ober 		ri->ri_cols = ri->ri_emuwidth / ri->ri_font->fontwidth;
    278      1.55      ober 		ri->ri_rows = ri->ri_emuheight / ri->ri_font->fontheight;
    279      1.55      ober 	}
    280       1.4        ad 	ri->ri_emustride = ri->ri_emuwidth * bpp >> 3;
    281       1.1        ad 	ri->ri_delta = ri->ri_stride - ri->ri_emustride;
    282       1.1        ad 	ri->ri_ccol = 0;
    283       1.1        ad 	ri->ri_crow = 0;
    284       1.4        ad 	ri->ri_pelbytes = bpp >> 3;
    285      1.30        pk 
    286       1.4        ad 	ri->ri_xscale = (ri->ri_font->fontwidth * bpp) >> 3;
    287       1.1        ad 	ri->ri_yscale = ri->ri_font->fontheight * ri->ri_stride;
    288       1.1        ad 	ri->ri_fontscale = ri->ri_font->fontheight * ri->ri_font->stride;
    289       1.1        ad 
    290      1.30        pk #ifdef DEBUG
    291      1.18        ad 	if ((ri->ri_delta & 3) != 0)
    292      1.13        ad 		panic("rasops_init: ri_delta not aligned on 32-bit boundary");
    293      1.30        pk #endif
    294       1.1        ad 	/* Clear the entire display */
    295      1.13        ad 	if ((ri->ri_flg & RI_CLEAR) != 0)
    296      1.13        ad 		memset(ri->ri_bits, 0, ri->ri_stride * ri->ri_height);
    297      1.30        pk 
    298      1.30        pk 	/* Now centre our window if needs be */
    299       1.1        ad 	ri->ri_origbits = ri->ri_bits;
    300      1.61  macallan 	ri->ri_hworigbits = ri->ri_hwbits;
    301      1.30        pk 
    302      1.13        ad 	if ((ri->ri_flg & RI_CENTER) != 0) {
    303      1.46     perry 		ri->ri_bits += (((ri->ri_width * bpp >> 3) -
    304      1.36   nathanw 		    ri->ri_emustride) >> 1) & ~3;
    305      1.30        pk 		ri->ri_bits += ((ri->ri_height - ri->ri_emuheight) >> 1) *
    306       1.1        ad 		    ri->ri_stride;
    307      1.61  macallan 		if (ri->ri_hwbits != NULL) {
    308      1.61  macallan 			ri->ri_hwbits += (((ri->ri_width * bpp >> 3) -
    309      1.61  macallan 			    ri->ri_emustride) >> 1) & ~3;
    310      1.61  macallan 			ri->ri_hwbits += ((ri->ri_height - ri->ri_emuheight) >> 1) *
    311      1.61  macallan 			    ri->ri_stride;
    312      1.61  macallan 		}
    313      1.30        pk 		ri->ri_yorigin = (int)(ri->ri_bits - ri->ri_origbits)
    314       1.5        ad 		   / ri->ri_stride;
    315      1.30        pk 		ri->ri_xorigin = (((int)(ri->ri_bits - ri->ri_origbits)
    316      1.28   nathanw 		   % ri->ri_stride) * 8 / bpp);
    317       1.5        ad 	} else
    318       1.5        ad 		ri->ri_xorigin = ri->ri_yorigin = 0;
    319       1.4        ad 
    320      1.30        pk 	/*
    321       1.4        ad 	 * Fill in defaults for operations set.  XXX this nukes private
    322       1.4        ad 	 * routines used by accelerated fb drivers.
    323       1.4        ad 	 */
    324       1.1        ad 	ri->ri_ops.mapchar = rasops_mapchar;
    325       1.1        ad 	ri->ri_ops.copyrows = rasops_copyrows;
    326       1.1        ad 	ri->ri_ops.copycols = rasops_copycols;
    327       1.4        ad 	ri->ri_ops.erasecols = rasops_erasecols;
    328       1.4        ad 	ri->ri_ops.eraserows = rasops_eraserows;
    329       1.1        ad 	ri->ri_ops.cursor = rasops_cursor;
    330       1.4        ad 	ri->ri_do_cursor = rasops_do_cursor;
    331      1.30        pk 
    332      1.13        ad 	if (ri->ri_depth < 8 || (ri->ri_flg & RI_FORCEMONO) != 0) {
    333      1.41  junyoung 		ri->ri_ops.allocattr = rasops_allocattr_mono;
    334      1.24  drochner 		ri->ri_caps = WSSCREEN_UNDERLINE | WSSCREEN_REVERSE;
    335       1.4        ad 	} else {
    336      1.41  junyoung 		ri->ri_ops.allocattr = rasops_allocattr_color;
    337      1.30        pk 		ri->ri_caps = WSSCREEN_UNDERLINE | WSSCREEN_HILIT |
    338      1.24  drochner 		    WSSCREEN_WSCOLORS | WSSCREEN_REVERSE;
    339       1.4        ad 	}
    340       1.4        ad 
    341       1.1        ad 	switch (ri->ri_depth) {
    342      1.20        ad #if NRASOPS1 > 0
    343       1.1        ad 	case 1:
    344       1.1        ad 		rasops1_init(ri);
    345       1.1        ad 		break;
    346       1.1        ad #endif
    347      1.20        ad #if NRASOPS2 > 0
    348       1.4        ad 	case 2:
    349       1.4        ad 		rasops2_init(ri);
    350      1.34  takemura 		break;
    351      1.34  takemura #endif
    352      1.34  takemura #if NRASOPS4 > 0
    353      1.34  takemura 	case 4:
    354      1.34  takemura 		rasops4_init(ri);
    355       1.4        ad 		break;
    356       1.4        ad #endif
    357      1.20        ad #if NRASOPS8 > 0
    358       1.1        ad 	case 8:
    359       1.1        ad 		rasops8_init(ri);
    360       1.1        ad 		break;
    361       1.1        ad #endif
    362      1.20        ad #if NRASOPS15 > 0 || NRASOPS16 > 0
    363       1.1        ad 	case 15:
    364       1.1        ad 	case 16:
    365       1.1        ad 		rasops15_init(ri);
    366       1.1        ad 		break;
    367       1.1        ad #endif
    368      1.20        ad #if NRASOPS24 > 0
    369       1.1        ad 	case 24:
    370       1.1        ad 		rasops24_init(ri);
    371       1.1        ad 		break;
    372       1.1        ad #endif
    373      1.20        ad #if NRASOPS32 > 0
    374       1.1        ad 	case 32:
    375       1.1        ad 		rasops32_init(ri);
    376       1.1        ad 		break;
    377       1.1        ad #endif
    378       1.1        ad 	default:
    379      1.13        ad 		ri->ri_flg &= ~RI_CFGDONE;
    380      1.13        ad 		splx(s);
    381       1.1        ad 		return (-1);
    382       1.1        ad 	}
    383      1.30        pk 
    384      1.55      ober #if NRASOPS_ROTATION > 0
    385  1.61.2.1  uebayasi 	if (ri->ri_flg & RI_ROTATE_MASK) {
    386  1.61.2.1  uebayasi 		if (ri->ri_flg & RI_ROTATE_CW) {
    387  1.61.2.1  uebayasi 			ri->ri_real_ops = ri->ri_ops;
    388  1.61.2.1  uebayasi 			ri->ri_ops.copycols = rasops_copycols_rotated_cw;
    389  1.61.2.1  uebayasi 			ri->ri_ops.copyrows = rasops_copyrows_rotated_cw;
    390  1.61.2.1  uebayasi 			ri->ri_ops.erasecols = rasops_erasecols_rotated_cw;
    391  1.61.2.1  uebayasi 			ri->ri_ops.eraserows = rasops_eraserows_rotated_cw;
    392  1.61.2.1  uebayasi 			ri->ri_ops.putchar = rasops_putchar_rotated_cw;
    393  1.61.2.1  uebayasi 		} else if (ri->ri_flg & RI_ROTATE_CCW) {
    394  1.61.2.1  uebayasi 			ri->ri_real_ops = ri->ri_ops;
    395  1.61.2.1  uebayasi 			ri->ri_ops.copycols = rasops_copycols_rotated_ccw;
    396  1.61.2.1  uebayasi 			ri->ri_ops.copyrows = rasops_copyrows_rotated_ccw;
    397  1.61.2.1  uebayasi 			ri->ri_ops.erasecols = rasops_erasecols_rotated_ccw;
    398  1.61.2.1  uebayasi 			ri->ri_ops.eraserows = rasops_eraserows_rotated_ccw;
    399  1.61.2.1  uebayasi 			ri->ri_ops.putchar = rasops_putchar_rotated_ccw;
    400  1.61.2.1  uebayasi 		}
    401      1.55      ober 	}
    402      1.55      ober #endif
    403      1.55      ober 
    404      1.13        ad 	ri->ri_flg |= RI_CFGDONE;
    405      1.13        ad 	splx(s);
    406       1.1        ad 	return (0);
    407       1.1        ad }
    408       1.1        ad 
    409       1.1        ad /*
    410       1.1        ad  * Map a character.
    411       1.1        ad  */
    412       1.1        ad static int
    413      1.59       dsl rasops_mapchar(void *cookie, int c, u_int *cp)
    414       1.1        ad {
    415       1.1        ad 	struct rasops_info *ri;
    416      1.30        pk 
    417       1.1        ad 	ri = (struct rasops_info *)cookie;
    418       1.8        ad 
    419      1.30        pk #ifdef DIAGNOSTIC
    420       1.8        ad 	if (ri->ri_font == NULL)
    421      1.42    provos 		panic("rasops_mapchar: no font selected");
    422      1.30        pk #endif
    423      1.39        ad 
    424      1.35    marcus 	if (ri->ri_font->encoding != WSDISPLAY_FONTENC_ISO) {
    425      1.35    marcus 		if ( (c = wsfont_map_unichar(ri->ri_font, c)) < 0) {
    426      1.35    marcus 			*cp = ' ';
    427      1.35    marcus 			return (0);
    428      1.35    marcus 
    429      1.35    marcus 		}
    430      1.35    marcus 	}
    431      1.30        pk 
    432       1.1        ad 	if (c < ri->ri_font->firstchar) {
    433       1.1        ad 		*cp = ' ';
    434       1.1        ad 		return (0);
    435       1.1        ad 	}
    436      1.30        pk 
    437       1.1        ad 	if (c - ri->ri_font->firstchar >= ri->ri_font->numchars) {
    438       1.1        ad 		*cp = ' ';
    439       1.1        ad 		return (0);
    440       1.1        ad 	}
    441      1.30        pk 
    442       1.1        ad 	*cp = c;
    443       1.1        ad 	return (5);
    444       1.1        ad }
    445       1.1        ad 
    446       1.1        ad /*
    447       1.1        ad  * Allocate a color attribute.
    448       1.1        ad  */
    449       1.1        ad static int
    450      1.54  christos rasops_allocattr_color(void *cookie, int fg, int bg, int flg,
    451      1.53  christos     long *attr)
    452       1.1        ad {
    453       1.1        ad 	int swap;
    454       1.1        ad 
    455      1.56       mjf 	if (__predict_false((unsigned int)fg >= sizeof(rasops_isgray) ||
    456      1.56       mjf 	    (unsigned int)bg >= sizeof(rasops_isgray)))
    457      1.56       mjf 		return (EINVAL);
    458      1.56       mjf 
    459       1.1        ad #ifdef RASOPS_CLIPPING
    460       1.1        ad 	fg &= 7;
    461       1.1        ad 	bg &= 7;
    462       1.1        ad #endif
    463      1.17        ad 	if ((flg & WSATTR_BLINK) != 0)
    464       1.1        ad 		return (EINVAL);
    465      1.23  drochner 
    466      1.23  drochner 	if ((flg & WSATTR_WSCOLORS) == 0) {
    467      1.48  macallan #ifdef WS_DEFAULT_FG
    468      1.48  macallan 		fg = WS_DEFAULT_FG;
    469      1.48  macallan #else
    470      1.48  macallan 		fg = WSCOL_WHITE;
    471      1.48  macallan #endif
    472      1.48  macallan #ifdef WS_DEFAULT_BG
    473      1.48  macallan 		bg = WS_DEFAULT_BG;
    474      1.48  macallan #else
    475      1.48  macallan 		bg = WSCOL_BLACK;
    476      1.48  macallan #endif
    477      1.23  drochner 	}
    478      1.23  drochner 
    479      1.17        ad 	if ((flg & WSATTR_REVERSE) != 0) {
    480       1.1        ad 		swap = fg;
    481       1.1        ad 		fg = bg;
    482       1.1        ad 		bg = swap;
    483       1.1        ad 	}
    484       1.1        ad 
    485      1.17        ad 	if ((flg & WSATTR_HILIT) != 0)
    486       1.1        ad 		fg += 8;
    487      1.30        pk 
    488       1.1        ad 	flg = ((flg & WSATTR_UNDERLINE) ? 1 : 0);
    489      1.30        pk 
    490       1.1        ad 	if (rasops_isgray[fg])
    491       1.1        ad 		flg |= 2;
    492       1.1        ad 
    493       1.1        ad 	if (rasops_isgray[bg])
    494       1.1        ad 		flg |= 4;
    495       1.1        ad 
    496       1.1        ad 	*attr = (bg << 16) | (fg << 24) | flg;
    497      1.17        ad 	return (0);
    498       1.1        ad }
    499       1.1        ad 
    500       1.1        ad /*
    501       1.1        ad  * Allocate a mono attribute.
    502       1.1        ad  */
    503       1.1        ad static int
    504      1.54  christos rasops_allocattr_mono(void *cookie, int fg, int bg, int flg,
    505      1.53  christos     long *attr)
    506       1.1        ad {
    507       1.1        ad 	int swap;
    508       1.1        ad 
    509      1.23  drochner 	if ((flg & (WSATTR_BLINK | WSATTR_HILIT | WSATTR_WSCOLORS)) != 0)
    510       1.1        ad 		return (EINVAL);
    511      1.23  drochner 
    512      1.23  drochner 	fg = 1;
    513      1.23  drochner 	bg = 0;
    514      1.23  drochner 
    515      1.17        ad 	if ((flg & WSATTR_REVERSE) != 0) {
    516       1.1        ad 		swap = fg;
    517       1.1        ad 		fg = bg;
    518       1.1        ad 		bg = swap;
    519       1.1        ad 	}
    520       1.1        ad 
    521       1.1        ad 	*attr = (bg << 16) | (fg << 24) | ((flg & WSATTR_UNDERLINE) ? 7 : 6);
    522      1.17        ad 	return (0);
    523       1.1        ad }
    524       1.1        ad 
    525       1.1        ad /*
    526       1.1        ad  * Copy rows.
    527       1.1        ad  */
    528       1.1        ad static void
    529      1.60       dsl rasops_copyrows(void *cookie, int src, int dst, int num)
    530       1.1        ad {
    531      1.51  jmcneill 	int32_t *sp, *dp, *hp, *srp, *drp, *hrp;
    532       1.1        ad 	struct rasops_info *ri;
    533      1.18        ad 	int n8, n1, cnt, delta;
    534      1.30        pk 
    535       1.1        ad 	ri = (struct rasops_info *)cookie;
    536      1.51  jmcneill 	hp = hrp = NULL;
    537       1.1        ad 
    538       1.1        ad #ifdef RASOPS_CLIPPING
    539       1.1        ad 	if (dst == src)
    540       1.1        ad 		return;
    541      1.30        pk 
    542       1.1        ad 	if (src < 0) {
    543       1.1        ad 		num += src;
    544       1.1        ad 		src = 0;
    545       1.1        ad 	}
    546       1.1        ad 
    547       1.1        ad 	if ((src + num) > ri->ri_rows)
    548       1.1        ad 		num = ri->ri_rows - src;
    549       1.1        ad 
    550       1.1        ad 	if (dst < 0) {
    551       1.1        ad 		num += dst;
    552       1.1        ad 		dst = 0;
    553       1.1        ad 	}
    554       1.1        ad 
    555       1.1        ad 	if ((dst + num) > ri->ri_rows)
    556       1.1        ad 		num = ri->ri_rows - dst;
    557      1.30        pk 
    558       1.1        ad 	if (num <= 0)
    559       1.1        ad 		return;
    560       1.1        ad #endif
    561       1.1        ad 
    562       1.1        ad 	num *= ri->ri_font->fontheight;
    563       1.1        ad 	n8 = ri->ri_emustride >> 5;
    564       1.1        ad 	n1 = (ri->ri_emustride >> 2) & 7;
    565      1.30        pk 
    566       1.1        ad 	if (dst < src) {
    567      1.18        ad 		srp = (int32_t *)(ri->ri_bits + src * ri->ri_yscale);
    568      1.18        ad 		drp = (int32_t *)(ri->ri_bits + dst * ri->ri_yscale);
    569      1.51  jmcneill 		if (ri->ri_hwbits)
    570      1.51  jmcneill 			hrp = (int32_t *)(ri->ri_hwbits + dst *
    571      1.51  jmcneill 			    ri->ri_yscale);
    572      1.18        ad 		delta = ri->ri_stride;
    573       1.1        ad 	} else {
    574       1.1        ad 		src = ri->ri_font->fontheight * src + num - 1;
    575       1.1        ad 		dst = ri->ri_font->fontheight * dst + num - 1;
    576       1.1        ad 		srp = (int32_t *)(ri->ri_bits + src * ri->ri_stride);
    577       1.1        ad 		drp = (int32_t *)(ri->ri_bits + dst * ri->ri_stride);
    578      1.51  jmcneill 		if (ri->ri_hwbits)
    579      1.51  jmcneill 			hrp = (int32_t *)(ri->ri_hwbits + dst *
    580      1.51  jmcneill 			    ri->ri_stride);
    581      1.51  jmcneill 
    582      1.18        ad 		delta = -ri->ri_stride;
    583      1.18        ad 	}
    584      1.30        pk 
    585      1.18        ad 	while (num--) {
    586      1.18        ad 		dp = drp;
    587      1.18        ad 		sp = srp;
    588      1.51  jmcneill 		if (ri->ri_hwbits)
    589      1.51  jmcneill 			hp = hrp;
    590      1.51  jmcneill 
    591      1.18        ad 		DELTA(drp, delta, int32_t *);
    592      1.18        ad 		DELTA(srp, delta, int32_t *);
    593      1.51  jmcneill 		if (ri->ri_hwbits)
    594      1.51  jmcneill 			DELTA(hrp, delta, int32_t *);
    595      1.18        ad 
    596      1.18        ad 		for (cnt = n8; cnt; cnt--) {
    597      1.52  jmcneill 			dp[0] = sp[0];
    598      1.52  jmcneill 			dp[1] = sp[1];
    599      1.52  jmcneill 			dp[2] = sp[2];
    600      1.52  jmcneill 			dp[3] = sp[3];
    601      1.52  jmcneill 			dp[4] = sp[4];
    602      1.52  jmcneill 			dp[5] = sp[5];
    603      1.52  jmcneill 			dp[6] = sp[6];
    604      1.52  jmcneill 			dp[7] = sp[7];
    605      1.18        ad 			dp += 8;
    606      1.18        ad 			sp += 8;
    607      1.52  jmcneill 		}
    608      1.52  jmcneill 		if (ri->ri_hwbits) {
    609      1.52  jmcneill 			sp -= (8 * n8);
    610      1.52  jmcneill 			for (cnt = n8; cnt; cnt--) {
    611      1.52  jmcneill 				hp[0] = sp[0];
    612      1.52  jmcneill 				hp[1] = sp[1];
    613      1.52  jmcneill 				hp[2] = sp[2];
    614      1.52  jmcneill 				hp[3] = sp[3];
    615      1.52  jmcneill 				hp[4] = sp[4];
    616      1.52  jmcneill 				hp[5] = sp[5];
    617      1.52  jmcneill 				hp[6] = sp[6];
    618      1.52  jmcneill 				hp[7] = sp[7];
    619      1.51  jmcneill 				hp += 8;
    620      1.52  jmcneill 				sp += 8;
    621      1.52  jmcneill 			}
    622      1.18        ad 		}
    623      1.30        pk 
    624      1.51  jmcneill 		for (cnt = n1; cnt; cnt--) {
    625      1.18        ad 			*dp++ = *sp++;
    626      1.51  jmcneill 			if (ri->ri_hwbits)
    627      1.51  jmcneill 				*hp++ = *(sp - 1);
    628      1.51  jmcneill 		}
    629       1.1        ad 	}
    630       1.1        ad }
    631       1.1        ad 
    632       1.1        ad /*
    633       1.1        ad  * Copy columns. This is slow, and hard to optimize due to alignment,
    634       1.1        ad  * and the fact that we have to copy both left->right and right->left.
    635      1.43       uwe  * We simply cop-out here and use memmove(), since it handles all of
    636       1.1        ad  * these cases anyway.
    637       1.1        ad  */
    638       1.4        ad void
    639      1.60       dsl rasops_copycols(void *cookie, int row, int src, int dst, int num)
    640       1.1        ad {
    641       1.1        ad 	struct rasops_info *ri;
    642      1.51  jmcneill 	u_char *sp, *dp, *hp;
    643       1.1        ad 	int height;
    644      1.30        pk 
    645       1.1        ad 	ri = (struct rasops_info *)cookie;
    646      1.51  jmcneill 	hp = NULL;
    647       1.1        ad 
    648       1.1        ad #ifdef RASOPS_CLIPPING
    649       1.1        ad 	if (dst == src)
    650       1.1        ad 		return;
    651      1.30        pk 
    652       1.3        ad 	/* Catches < 0 case too */
    653       1.3        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
    654       1.1        ad 		return;
    655      1.30        pk 
    656       1.1        ad 	if (src < 0) {
    657       1.1        ad 		num += src;
    658       1.1        ad 		src = 0;
    659       1.1        ad 	}
    660       1.1        ad 
    661       1.1        ad 	if ((src + num) > ri->ri_cols)
    662       1.1        ad 		num = ri->ri_cols - src;
    663       1.1        ad 
    664       1.1        ad 	if (dst < 0) {
    665       1.1        ad 		num += dst;
    666       1.1        ad 		dst = 0;
    667       1.1        ad 	}
    668       1.1        ad 
    669       1.1        ad 	if ((dst + num) > ri->ri_cols)
    670       1.1        ad 		num = ri->ri_cols - dst;
    671      1.30        pk 
    672       1.1        ad 	if (num <= 0)
    673       1.1        ad 		return;
    674       1.1        ad #endif
    675      1.30        pk 
    676       1.1        ad 	num *= ri->ri_xscale;
    677       1.1        ad 	row *= ri->ri_yscale;
    678       1.1        ad 	height = ri->ri_font->fontheight;
    679      1.30        pk 
    680       1.1        ad 	sp = ri->ri_bits + row + src * ri->ri_xscale;
    681       1.1        ad 	dp = ri->ri_bits + row + dst * ri->ri_xscale;
    682      1.51  jmcneill 	if (ri->ri_hwbits)
    683      1.51  jmcneill 		hp = ri->ri_hwbits + row + dst * ri->ri_xscale;
    684      1.30        pk 
    685       1.1        ad 	while (height--) {
    686      1.43       uwe 		memmove(dp, sp, num);
    687      1.51  jmcneill 		if (ri->ri_hwbits) {
    688      1.51  jmcneill 			memcpy(hp, sp, num);
    689      1.51  jmcneill 			hp += ri->ri_stride;
    690      1.51  jmcneill 		}
    691       1.1        ad 		dp += ri->ri_stride;
    692       1.1        ad 		sp += ri->ri_stride;
    693       1.1        ad 	}
    694       1.1        ad }
    695       1.1        ad 
    696       1.1        ad /*
    697       1.1        ad  * Turn cursor off/on.
    698       1.1        ad  */
    699       1.1        ad static void
    700      1.60       dsl rasops_cursor(void *cookie, int on, int row, int col)
    701       1.1        ad {
    702       1.1        ad 	struct rasops_info *ri;
    703      1.30        pk 
    704       1.1        ad 	ri = (struct rasops_info *)cookie;
    705      1.30        pk 
    706       1.1        ad 	/* Turn old cursor off */
    707      1.13        ad 	if ((ri->ri_flg & RI_CURSOR) != 0)
    708      1.30        pk #ifdef RASOPS_CLIPPING
    709      1.13        ad 		if ((ri->ri_flg & RI_CURSORCLIP) == 0)
    710       1.1        ad #endif
    711       1.1        ad 			ri->ri_do_cursor(ri);
    712       1.1        ad 
    713       1.1        ad 	/* Select new cursor */
    714       1.1        ad #ifdef RASOPS_CLIPPING
    715      1.13        ad 	ri->ri_flg &= ~RI_CURSORCLIP;
    716      1.30        pk 
    717       1.1        ad 	if (row < 0 || row >= ri->ri_rows)
    718      1.13        ad 		ri->ri_flg |= RI_CURSORCLIP;
    719       1.1        ad 	else if (col < 0 || col >= ri->ri_cols)
    720      1.13        ad 		ri->ri_flg |= RI_CURSORCLIP;
    721       1.1        ad #endif
    722       1.1        ad 	ri->ri_crow = row;
    723       1.1        ad 	ri->ri_ccol = col;
    724       1.1        ad 
    725       1.1        ad 	if (on) {
    726      1.13        ad 		ri->ri_flg |= RI_CURSOR;
    727      1.30        pk #ifdef RASOPS_CLIPPING
    728      1.13        ad 		if ((ri->ri_flg & RI_CURSORCLIP) == 0)
    729       1.1        ad #endif
    730       1.1        ad 			ri->ri_do_cursor(ri);
    731      1.30        pk 	} else
    732      1.13        ad 		ri->ri_flg &= ~RI_CURSOR;
    733       1.1        ad }
    734       1.1        ad 
    735       1.1        ad /*
    736       1.1        ad  * Make the device colormap
    737       1.1        ad  */
    738       1.4        ad static void
    739      1.59       dsl rasops_init_devcmap(struct rasops_info *ri)
    740       1.1        ad {
    741      1.23  drochner 	const u_char *p;
    742       1.1        ad 	int i, c;
    743      1.30        pk 
    744       1.4        ad 	switch (ri->ri_depth) {
    745       1.4        ad 	case 1:
    746       1.4        ad 		ri->ri_devcmap[0] = 0;
    747       1.4        ad 		for (i = 1; i < 16; i++)
    748       1.4        ad 			ri->ri_devcmap[i] = -1;
    749       1.4        ad 		return;
    750       1.4        ad 
    751       1.4        ad 	case 2:
    752       1.4        ad 		for (i = 1; i < 15; i++)
    753       1.4        ad 			ri->ri_devcmap[i] = 0xaaaaaaaa;
    754      1.30        pk 
    755       1.4        ad 		ri->ri_devcmap[0] = 0;
    756       1.4        ad 		ri->ri_devcmap[8] = 0x55555555;
    757       1.4        ad 		ri->ri_devcmap[15] = -1;
    758       1.4        ad 		return;
    759       1.4        ad 
    760       1.4        ad 	case 8:
    761       1.4        ad 		for (i = 0; i < 16; i++)
    762       1.4        ad 			ri->ri_devcmap[i] = i | (i<<8) | (i<<16) | (i<<24);
    763       1.4        ad 		return;
    764       1.4        ad 	}
    765      1.30        pk 
    766       1.1        ad 	p = rasops_cmap;
    767      1.30        pk 
    768      1.29   nathanw 	for (i = 0; i < 16; i++) {
    769       1.1        ad 		if (ri->ri_rnum <= 8)
    770      1.12        ad 			c = (*p >> (8 - ri->ri_rnum)) << ri->ri_rpos;
    771      1.30        pk 		else
    772      1.12        ad 			c = (*p << (ri->ri_rnum - 8)) << ri->ri_rpos;
    773      1.29   nathanw 		p++;
    774       1.1        ad 
    775       1.1        ad 		if (ri->ri_gnum <= 8)
    776      1.12        ad 			c |= (*p >> (8 - ri->ri_gnum)) << ri->ri_gpos;
    777      1.30        pk 		else
    778      1.12        ad 			c |= (*p << (ri->ri_gnum - 8)) << ri->ri_gpos;
    779      1.29   nathanw 		p++;
    780       1.1        ad 
    781       1.1        ad 		if (ri->ri_bnum <= 8)
    782      1.12        ad 			c |= (*p >> (8 - ri->ri_bnum)) << ri->ri_bpos;
    783      1.30        pk 		else
    784      1.12        ad 			c |= (*p << (ri->ri_bnum - 8)) << ri->ri_bpos;
    785      1.29   nathanw 		p++;
    786       1.4        ad 
    787       1.4        ad 		/* Fill the word for generic routines, which want this */
    788       1.4        ad 		if (ri->ri_depth == 24)
    789       1.4        ad 			c = c | ((c & 0xff) << 24);
    790       1.4        ad 		else if (ri->ri_depth <= 16)
    791       1.4        ad 			c = c | (c << 16);
    792       1.1        ad 
    793       1.4        ad 		/* 24bpp does bswap on the fly. {32,16,15}bpp do it here. */
    794      1.13        ad 		if ((ri->ri_flg & RI_BSWAP) == 0)
    795       1.3        ad 			ri->ri_devcmap[i] = c;
    796       1.4        ad 		else if (ri->ri_depth == 32)
    797       1.3        ad 			ri->ri_devcmap[i] = bswap32(c);
    798       1.4        ad 		else if (ri->ri_depth == 16 || ri->ri_depth == 15)
    799       1.3        ad 			ri->ri_devcmap[i] = bswap16(c);
    800       1.4        ad 		else
    801       1.4        ad 			ri->ri_devcmap[i] = c;
    802       1.1        ad 	}
    803       1.1        ad }
    804       1.1        ad 
    805       1.1        ad /*
    806       1.1        ad  * Unpack a rasops attribute
    807       1.1        ad  */
    808       1.1        ad void
    809      1.60       dsl rasops_unpack_attr(long attr, int *fg, int *bg, int *underline)
    810       1.1        ad {
    811      1.30        pk 
    812      1.30        pk 	*fg = ((u_int)attr >> 24) & 0xf;
    813      1.30        pk 	*bg = ((u_int)attr >> 16) & 0xf;
    814      1.25        ad 	if (underline != NULL)
    815      1.24  drochner 		*underline = (u_int)attr & 1;
    816       1.4        ad }
    817       1.4        ad 
    818       1.4        ad /*
    819       1.4        ad  * Erase rows. This isn't static, since 24-bpp uses it in special cases.
    820       1.4        ad  */
    821       1.4        ad void
    822      1.60       dsl rasops_eraserows(void *cookie, int row, int num, long attr)
    823       1.4        ad {
    824       1.4        ad 	struct rasops_info *ri;
    825      1.14        ad 	int np, nw, cnt, delta;
    826      1.51  jmcneill 	int32_t *dp, *hp, clr;
    827      1.51  jmcneill 	int i;
    828      1.30        pk 
    829       1.4        ad 	ri = (struct rasops_info *)cookie;
    830      1.51  jmcneill 	hp = NULL;
    831       1.4        ad 
    832       1.4        ad #ifdef RASOPS_CLIPPING
    833       1.4        ad 	if (row < 0) {
    834       1.4        ad 		num += row;
    835       1.4        ad 		row = 0;
    836       1.4        ad 	}
    837       1.4        ad 
    838       1.4        ad 	if ((row + num) > ri->ri_rows)
    839       1.4        ad 		num = ri->ri_rows - row;
    840      1.30        pk 
    841       1.4        ad 	if (num <= 0)
    842       1.4        ad 		return;
    843       1.4        ad #endif
    844       1.4        ad 
    845      1.30        pk 	clr = ri->ri_devcmap[(attr >> 16) & 0xf];
    846       1.4        ad 
    847      1.30        pk 	/*
    848      1.20        ad 	 * XXX The wsdisplay_emulops interface seems a little deficient in
    849      1.30        pk 	 * that there is no way to clear the *entire* screen. We provide a
    850      1.30        pk 	 * workaround here: if the entire console area is being cleared, and
    851      1.13        ad 	 * the RI_FULLCLEAR flag is set, clear the entire display.
    852      1.30        pk 	 */
    853      1.13        ad 	if (num == ri->ri_rows && (ri->ri_flg & RI_FULLCLEAR) != 0) {
    854      1.13        ad 		np = ri->ri_stride >> 5;
    855      1.13        ad 		nw = (ri->ri_stride >> 2) & 7;
    856      1.13        ad 		num = ri->ri_height;
    857      1.14        ad 		dp = (int32_t *)ri->ri_origbits;
    858      1.51  jmcneill 		if (ri->ri_hwbits)
    859      1.61  macallan 			hp = (int32_t *)ri->ri_hworigbits;
    860      1.14        ad 		delta = 0;
    861      1.13        ad 	} else {
    862      1.13        ad 		np = ri->ri_emustride >> 5;
    863      1.13        ad 		nw = (ri->ri_emustride >> 2) & 7;
    864      1.13        ad 		num *= ri->ri_font->fontheight;
    865      1.14        ad 		dp = (int32_t *)(ri->ri_bits + row * ri->ri_yscale);
    866      1.51  jmcneill 		if (ri->ri_hwbits)
    867      1.51  jmcneill 			hp = (int32_t *)(ri->ri_hwbits + row *
    868      1.51  jmcneill 			    ri->ri_yscale);
    869      1.14        ad 		delta = ri->ri_delta;
    870      1.13        ad 	}
    871      1.30        pk 
    872       1.4        ad 	while (num--) {
    873       1.4        ad 		for (cnt = np; cnt; cnt--) {
    874      1.51  jmcneill 			for (i = 0; i < 8; i++) {
    875      1.51  jmcneill 				dp[i] = clr;
    876      1.51  jmcneill 				if (ri->ri_hwbits)
    877      1.51  jmcneill 					hp[i] = clr;
    878      1.51  jmcneill 			}
    879       1.4        ad 			dp += 8;
    880      1.51  jmcneill 			if (ri->ri_hwbits)
    881      1.51  jmcneill 				hp += 8;
    882       1.4        ad 		}
    883      1.30        pk 
    884       1.4        ad 		for (cnt = nw; cnt; cnt--) {
    885       1.4        ad 			*(int32_t *)dp = clr;
    886       1.4        ad 			DELTA(dp, 4, int32_t *);
    887      1.51  jmcneill 			if (ri->ri_hwbits) {
    888      1.51  jmcneill 				*(int32_t *)hp = clr;
    889      1.51  jmcneill 				DELTA(hp, 4, int32_t *);
    890      1.51  jmcneill 			}
    891      1.30        pk 		}
    892      1.30        pk 
    893      1.14        ad 		DELTA(dp, delta, int32_t *);
    894      1.51  jmcneill 		if (ri->ri_hwbits)
    895      1.51  jmcneill 			DELTA(hp, delta, int32_t *);
    896       1.4        ad 	}
    897       1.4        ad }
    898       1.4        ad 
    899       1.4        ad /*
    900       1.4        ad  * Actually turn the cursor on or off. This does the dirty work for
    901       1.4        ad  * rasops_cursor().
    902       1.4        ad  */
    903       1.4        ad static void
    904      1.59       dsl rasops_do_cursor(struct rasops_info *ri)
    905       1.4        ad {
    906      1.21        ad 	int full1, height, cnt, slop1, slop2, row, col;
    907      1.51  jmcneill 	u_char *dp, *rp, *hrp, *hp;
    908      1.51  jmcneill 
    909      1.51  jmcneill 	hrp = hp = NULL;
    910      1.30        pk 
    911      1.55      ober #if NRASOPS_ROTATION > 0
    912  1.61.2.1  uebayasi 	if (ri->ri_flg & RI_ROTATE_MASK) {
    913  1.61.2.1  uebayasi 		if (ri->ri_flg & RI_ROTATE_CW) {
    914  1.61.2.1  uebayasi 			/* Rotate rows/columns */
    915  1.61.2.1  uebayasi 			row = ri->ri_ccol;
    916  1.61.2.1  uebayasi 			col = ri->ri_rows - ri->ri_crow - 1;
    917  1.61.2.1  uebayasi 		} else if (ri->ri_flg & RI_ROTATE_CCW) {
    918  1.61.2.1  uebayasi 			/* Rotate rows/columns */
    919  1.61.2.1  uebayasi 			row = ri->ri_cols - ri->ri_ccol - 1;
    920  1.61.2.1  uebayasi 			col = ri->ri_crow;
    921  1.61.2.1  uebayasi 		} else {	/* upside-down */
    922  1.61.2.1  uebayasi 			row = ri->ri_crow;
    923  1.61.2.1  uebayasi 			col = ri->ri_ccol;
    924  1.61.2.1  uebayasi 		}
    925      1.55      ober 	} else
    926      1.55      ober #endif
    927      1.55      ober 	{
    928      1.55      ober 		row = ri->ri_crow;
    929      1.55      ober 		col = ri->ri_ccol;
    930      1.55      ober 	}
    931      1.30        pk 
    932       1.4        ad 	rp = ri->ri_bits + row * ri->ri_yscale + col * ri->ri_xscale;
    933      1.51  jmcneill 	if (ri->ri_hwbits)
    934      1.51  jmcneill 		hrp = ri->ri_hwbits + row * ri->ri_yscale + col
    935      1.51  jmcneill 		    * ri->ri_xscale;
    936       1.4        ad 	height = ri->ri_font->fontheight;
    937      1.27  nisimura 	slop1 = (4 - ((long)rp & 3)) & 3;
    938      1.30        pk 
    939       1.4        ad 	if (slop1 > ri->ri_xscale)
    940       1.4        ad 		slop1 = ri->ri_xscale;
    941      1.30        pk 
    942       1.4        ad 	slop2 = (ri->ri_xscale - slop1) & 3;
    943       1.4        ad 	full1 = (ri->ri_xscale - slop1 - slop2) >> 2;
    944      1.30        pk 
    945       1.4        ad 	if ((slop1 | slop2) == 0) {
    946       1.4        ad 		/* A common case */
    947       1.4        ad 		while (height--) {
    948       1.4        ad 			dp = rp;
    949       1.4        ad 			rp += ri->ri_stride;
    950      1.51  jmcneill 			if (ri->ri_hwbits) {
    951      1.51  jmcneill 				hp = hrp;
    952      1.51  jmcneill 				hrp += ri->ri_stride;
    953      1.51  jmcneill 			}
    954      1.30        pk 
    955       1.4        ad 			for (cnt = full1; cnt; cnt--) {
    956      1.21        ad 				*(int32_t *)dp ^= ~0;
    957       1.4        ad 				dp += 4;
    958      1.51  jmcneill 				if (ri->ri_hwbits) {
    959      1.57  jmcneill 					dp -= 4;
    960      1.57  jmcneill 					*(int32_t *)hp = *(int32_t *)dp;
    961      1.51  jmcneill 					hp += 4;
    962      1.57  jmcneill 					dp += 4;
    963      1.51  jmcneill 				}
    964       1.4        ad 			}
    965       1.4        ad 		}
    966       1.4        ad 	} else {
    967       1.4        ad 		/* XXX this is stupid.. use masks instead */
    968       1.4        ad 		while (height--) {
    969       1.4        ad 			dp = rp;
    970       1.4        ad 			rp += ri->ri_stride;
    971      1.51  jmcneill 			if (ri->ri_hwbits) {
    972      1.51  jmcneill 				hp = hrp;
    973      1.51  jmcneill 				hrp += ri->ri_stride;
    974      1.51  jmcneill 			}
    975      1.30        pk 
    976      1.51  jmcneill 			if (slop1 & 1) {
    977      1.22     enami 				*dp++ ^= ~0;
    978      1.57  jmcneill 				if (ri->ri_hwbits) {
    979      1.57  jmcneill 					*hp++ = *(dp - 1);
    980      1.57  jmcneill 				}
    981      1.51  jmcneill 			}
    982       1.4        ad 
    983       1.4        ad 			if (slop1 & 2) {
    984      1.21        ad 				*(int16_t *)dp ^= ~0;
    985       1.4        ad 				dp += 2;
    986      1.51  jmcneill 				if (ri->ri_hwbits) {
    987      1.57  jmcneill 					dp -= 2;
    988      1.57  jmcneill 					*(int16_t *)hp = *(int16_t *)dp;
    989      1.51  jmcneill 					hp += 2;
    990      1.57  jmcneill 					dp += 2;
    991      1.51  jmcneill 				}
    992       1.4        ad 			}
    993      1.30        pk 
    994       1.4        ad 			for (cnt = full1; cnt; cnt--) {
    995      1.21        ad 				*(int32_t *)dp ^= ~0;
    996       1.4        ad 				dp += 4;
    997      1.51  jmcneill 				if (ri->ri_hwbits) {
    998      1.57  jmcneill 					dp -= 4;
    999      1.57  jmcneill 					*(int32_t *)hp = *(int32_t *)dp;
   1000      1.51  jmcneill 					hp += 4;
   1001      1.57  jmcneill 					dp += 4;
   1002      1.51  jmcneill 				}
   1003       1.4        ad 			}
   1004       1.4        ad 
   1005      1.51  jmcneill 			if (slop2 & 1) {
   1006      1.21        ad 				*dp++ ^= ~0;
   1007      1.51  jmcneill 				if (ri->ri_hwbits)
   1008      1.57  jmcneill 					*hp++ = *(dp - 1);
   1009      1.51  jmcneill 			}
   1010       1.4        ad 
   1011      1.51  jmcneill 			if (slop2 & 2) {
   1012      1.21        ad 				*(int16_t *)dp ^= ~0;
   1013      1.51  jmcneill 				if (ri->ri_hwbits)
   1014      1.57  jmcneill 					*(int16_t *)hp = *(int16_t *)(dp - 2);
   1015      1.51  jmcneill 			}
   1016       1.4        ad 		}
   1017       1.4        ad 	}
   1018       1.4        ad }
   1019       1.4        ad 
   1020       1.4        ad /*
   1021       1.4        ad  * Erase columns.
   1022       1.4        ad  */
   1023       1.4        ad void
   1024      1.60       dsl rasops_erasecols(void *cookie, int row, int col, int num, long attr)
   1025       1.4        ad {
   1026       1.4        ad 	int n8, height, cnt, slop1, slop2, clr;
   1027       1.4        ad 	struct rasops_info *ri;
   1028      1.51  jmcneill 	int32_t *rp, *dp, *hrp, *hp;
   1029      1.51  jmcneill 	int i;
   1030      1.30        pk 
   1031       1.4        ad 	ri = (struct rasops_info *)cookie;
   1032      1.51  jmcneill 	hrp = hp = NULL;
   1033      1.30        pk 
   1034      1.30        pk #ifdef RASOPS_CLIPPING
   1035       1.4        ad 	if ((unsigned)row >= (unsigned)ri->ri_rows)
   1036       1.4        ad 		return;
   1037       1.4        ad 
   1038       1.4        ad 	if (col < 0) {
   1039       1.4        ad 		num += col;
   1040       1.4        ad 		col = 0;
   1041       1.4        ad 	}
   1042       1.4        ad 
   1043       1.4        ad 	if ((col + num) > ri->ri_cols)
   1044       1.4        ad 		num = ri->ri_cols - col;
   1045      1.30        pk 
   1046       1.4        ad 	if (num <= 0)
   1047       1.4        ad 		return;
   1048       1.4        ad #endif
   1049      1.30        pk 
   1050       1.4        ad 	num = num * ri->ri_xscale;
   1051       1.4        ad 	rp = (int32_t *)(ri->ri_bits + row*ri->ri_yscale + col*ri->ri_xscale);
   1052      1.51  jmcneill 	if (ri->ri_hwbits)
   1053      1.51  jmcneill 		hrp = (int32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
   1054      1.51  jmcneill 		    col*ri->ri_xscale);
   1055       1.4        ad 	height = ri->ri_font->fontheight;
   1056      1.30        pk 	clr = ri->ri_devcmap[(attr >> 16) & 0xf];
   1057      1.30        pk 
   1058       1.4        ad 	/* Don't bother using the full loop for <= 32 pels */
   1059       1.4        ad 	if (num <= 32) {
   1060       1.6        ad 		if (((num | ri->ri_xscale) & 3) == 0) {
   1061       1.6        ad 			/* Word aligned blt */
   1062       1.6        ad 			num >>= 2;
   1063       1.6        ad 
   1064       1.6        ad 			while (height--) {
   1065       1.6        ad 				dp = rp;
   1066       1.6        ad 				DELTA(rp, ri->ri_stride, int32_t *);
   1067      1.51  jmcneill 				if (ri->ri_hwbits) {
   1068      1.51  jmcneill 					hp = hrp;
   1069      1.51  jmcneill 					DELTA(hrp, ri->ri_stride, int32_t *);
   1070      1.51  jmcneill 				}
   1071      1.30        pk 
   1072      1.51  jmcneill 				for (cnt = num; cnt; cnt--) {
   1073       1.6        ad 					*dp++ = clr;
   1074      1.51  jmcneill 					if (ri->ri_hwbits)
   1075      1.51  jmcneill 						*hp++ = clr;
   1076      1.51  jmcneill 				}
   1077       1.6        ad 			}
   1078       1.6        ad 		} else if (((num | ri->ri_xscale) & 1) == 0) {
   1079      1.30        pk 			/*
   1080       1.4        ad 			 * Halfword aligned blt. This is needed so the
   1081      1.30        pk 			 * 15/16 bit ops can use this function.
   1082       1.4        ad 			 */
   1083       1.4        ad 			num >>= 1;
   1084       1.4        ad 
   1085       1.4        ad 			while (height--) {
   1086       1.4        ad 				dp = rp;
   1087       1.4        ad 				DELTA(rp, ri->ri_stride, int32_t *);
   1088      1.51  jmcneill 				if (ri->ri_hwbits) {
   1089      1.51  jmcneill 					hp = hrp;
   1090      1.51  jmcneill 					DELTA(hrp, ri->ri_stride, int32_t *);
   1091      1.51  jmcneill 				}
   1092       1.4        ad 
   1093       1.4        ad 				for (cnt = num; cnt; cnt--) {
   1094       1.4        ad 					*(int16_t *)dp = clr;
   1095       1.4        ad 					DELTA(dp, 2, int32_t *);
   1096      1.51  jmcneill 					if (ri->ri_hwbits) {
   1097      1.51  jmcneill 						*(int16_t *)hp = clr;
   1098      1.51  jmcneill 						DELTA(hp, 2, int32_t *);
   1099      1.51  jmcneill 					}
   1100       1.4        ad 				}
   1101       1.4        ad 			}
   1102       1.4        ad 		} else {
   1103       1.4        ad 			while (height--) {
   1104       1.4        ad 				dp = rp;
   1105       1.4        ad 				DELTA(rp, ri->ri_stride, int32_t *);
   1106      1.51  jmcneill 				if (ri->ri_hwbits) {
   1107      1.51  jmcneill 					hp = hrp;
   1108      1.51  jmcneill 					DELTA(hrp, ri->ri_stride, int32_t *);
   1109      1.51  jmcneill 				}
   1110       1.4        ad 
   1111       1.4        ad 				for (cnt = num; cnt; cnt--) {
   1112       1.4        ad 					*(u_char *)dp = clr;
   1113       1.4        ad 					DELTA(dp, 1, int32_t *);
   1114      1.51  jmcneill 					if (ri->ri_hwbits) {
   1115      1.51  jmcneill 						*(u_char *)hp = clr;
   1116      1.51  jmcneill 						DELTA(hp, 1, int32_t *);
   1117      1.51  jmcneill 					}
   1118       1.4        ad 				}
   1119       1.4        ad 			}
   1120       1.4        ad 		}
   1121      1.30        pk 
   1122       1.4        ad 		return;
   1123       1.4        ad 	}
   1124      1.30        pk 
   1125      1.27  nisimura 	slop1 = (4 - ((long)rp & 3)) & 3;
   1126       1.4        ad 	slop2 = (num - slop1) & 3;
   1127       1.4        ad 	num -= slop1 + slop2;
   1128       1.4        ad 	n8 = num >> 5;
   1129       1.4        ad 	num = (num >> 2) & 7;
   1130       1.4        ad 
   1131       1.4        ad 	while (height--) {
   1132       1.4        ad 		dp = rp;
   1133       1.4        ad 		DELTA(rp, ri->ri_stride, int32_t *);
   1134      1.51  jmcneill 		if (ri->ri_hwbits) {
   1135      1.51  jmcneill 			hp = hrp;
   1136      1.51  jmcneill 			DELTA(hrp, ri->ri_stride, int32_t *);
   1137      1.51  jmcneill 		}
   1138      1.30        pk 
   1139       1.4        ad 		/* Align span to 4 bytes */
   1140       1.4        ad 		if (slop1 & 1) {
   1141       1.4        ad 			*(u_char *)dp = clr;
   1142       1.4        ad 			DELTA(dp, 1, int32_t *);
   1143      1.51  jmcneill 			if (ri->ri_hwbits) {
   1144      1.51  jmcneill 				*(u_char *)hp = clr;
   1145      1.51  jmcneill 				DELTA(hp, 1, int32_t *);
   1146      1.51  jmcneill 			}
   1147       1.4        ad 		}
   1148       1.4        ad 
   1149       1.4        ad 		if (slop1 & 2) {
   1150       1.4        ad 			*(int16_t *)dp = clr;
   1151       1.4        ad 			DELTA(dp, 2, int32_t *);
   1152      1.51  jmcneill 			if (ri->ri_hwbits) {
   1153      1.51  jmcneill 				*(int16_t *)hp = clr;
   1154      1.51  jmcneill 				DELTA(hp, 2, int32_t *);
   1155      1.51  jmcneill 			}
   1156       1.4        ad 		}
   1157      1.30        pk 
   1158       1.4        ad 		/* Write 32 bytes per loop */
   1159       1.4        ad 		for (cnt = n8; cnt; cnt--) {
   1160      1.51  jmcneill 			for (i = 0; i < 8; i++) {
   1161      1.51  jmcneill 				dp[i] = clr;
   1162      1.51  jmcneill 				if (ri->ri_hwbits)
   1163      1.51  jmcneill 					hp[i] = clr;
   1164      1.51  jmcneill 			}
   1165       1.4        ad 			dp += 8;
   1166      1.51  jmcneill 			if (ri->ri_hwbits)
   1167      1.51  jmcneill 				hp += 8;
   1168       1.4        ad 		}
   1169      1.30        pk 
   1170      1.30        pk 		/* Write 4 bytes per loop */
   1171      1.51  jmcneill 		for (cnt = num; cnt; cnt--) {
   1172       1.4        ad 			*dp++ = clr;
   1173      1.51  jmcneill 			if (ri->ri_hwbits)
   1174      1.51  jmcneill 				*hp++ = clr;
   1175      1.51  jmcneill 		}
   1176      1.30        pk 
   1177      1.30        pk 		/* Write unaligned trailing slop */
   1178       1.4        ad 		if (slop2 & 1) {
   1179       1.4        ad 			*(u_char *)dp = clr;
   1180       1.4        ad 			DELTA(dp, 1, int32_t *);
   1181      1.51  jmcneill 			if (ri->ri_hwbits) {
   1182      1.51  jmcneill 				*(u_char *)hp = clr;
   1183      1.51  jmcneill 				DELTA(hp, 1, int32_t *);
   1184      1.51  jmcneill 			}
   1185       1.4        ad 		}
   1186       1.4        ad 
   1187      1.51  jmcneill 		if (slop2 & 2) {
   1188       1.4        ad 			*(int16_t *)dp = clr;
   1189      1.51  jmcneill 			if (ri->ri_hwbits)
   1190      1.51  jmcneill 				*(int16_t *)hp = clr;
   1191      1.51  jmcneill 		}
   1192       1.4        ad 	}
   1193       1.1        ad }
   1194      1.55      ober 
   1195      1.55      ober #if NRASOPS_ROTATION > 0
   1196      1.55      ober /*
   1197      1.55      ober  * Quarter clockwise rotation routines (originally intended for the
   1198      1.55      ober  * built-in Zaurus C3x00 display in 16bpp).
   1199      1.55      ober  */
   1200      1.55      ober 
   1201      1.55      ober #include <sys/malloc.h>
   1202      1.55      ober 
   1203      1.55      ober static void
   1204  1.61.2.1  uebayasi rasops_rotate_font(int *cookie, int rotate)
   1205      1.55      ober {
   1206      1.55      ober 	struct rotatedfont *f;
   1207      1.55      ober 	int ncookie;
   1208      1.55      ober 
   1209      1.55      ober 	SLIST_FOREACH(f, &rotatedfonts, rf_next) {
   1210      1.55      ober 		if (f->rf_cookie == *cookie) {
   1211      1.55      ober 			*cookie = f->rf_rotated;
   1212      1.55      ober 			return;
   1213      1.55      ober 		}
   1214      1.55      ober 	}
   1215      1.55      ober 
   1216      1.55      ober 	/*
   1217      1.55      ober 	 * We did not find a rotated version of this font. Ask the wsfont
   1218      1.55      ober 	 * code to compute one for us.
   1219      1.55      ober 	 */
   1220      1.55      ober 
   1221      1.55      ober 	f = malloc(sizeof(struct rotatedfont), M_DEVBUF, M_WAITOK);
   1222      1.55      ober 	if (f == NULL)
   1223      1.55      ober 		return;
   1224      1.55      ober 
   1225  1.61.2.1  uebayasi 	if ((ncookie = wsfont_rotate(*cookie, rotate)) == -1)
   1226      1.55      ober 		return;
   1227      1.55      ober 
   1228      1.55      ober 	f->rf_cookie = *cookie;
   1229      1.55      ober 	f->rf_rotated = ncookie;
   1230      1.55      ober 	SLIST_INSERT_HEAD(&rotatedfonts, f, rf_next);
   1231      1.55      ober 
   1232      1.55      ober 	*cookie = ncookie;
   1233      1.55      ober }
   1234      1.55      ober 
   1235      1.55      ober static void
   1236      1.60       dsl rasops_copychar(void *cookie, int srcrow, int dstrow, int srccol, int dstcol)
   1237      1.55      ober {
   1238      1.55      ober 	struct rasops_info *ri;
   1239      1.55      ober 	u_char *sp, *dp;
   1240      1.55      ober 	int height;
   1241      1.55      ober 	int r_srcrow, r_dstrow, r_srccol, r_dstcol;
   1242      1.55      ober 
   1243      1.55      ober 	ri = (struct rasops_info *)cookie;
   1244      1.55      ober 
   1245      1.55      ober 	r_srcrow = srccol;
   1246      1.55      ober 	r_dstrow = dstcol;
   1247      1.55      ober 	r_srccol = ri->ri_rows - srcrow - 1;
   1248      1.55      ober 	r_dstcol = ri->ri_rows - dstrow - 1;
   1249      1.55      ober 
   1250      1.55      ober 	r_srcrow *= ri->ri_yscale;
   1251      1.55      ober 	r_dstrow *= ri->ri_yscale;
   1252      1.55      ober 	height = ri->ri_font->fontheight;
   1253      1.55      ober 
   1254      1.55      ober 	sp = ri->ri_bits + r_srcrow + r_srccol * ri->ri_xscale;
   1255      1.55      ober 	dp = ri->ri_bits + r_dstrow + r_dstcol * ri->ri_xscale;
   1256      1.55      ober 
   1257      1.55      ober 	while (height--) {
   1258      1.55      ober 		memmove(dp, sp, ri->ri_xscale);
   1259      1.55      ober 		dp += ri->ri_stride;
   1260      1.55      ober 		sp += ri->ri_stride;
   1261      1.55      ober 	}
   1262      1.55      ober }
   1263      1.55      ober 
   1264      1.55      ober static void
   1265  1.61.2.1  uebayasi rasops_putchar_rotated_cw(void *cookie, int row, int col, u_int uc, long attr)
   1266      1.55      ober {
   1267      1.55      ober 	struct rasops_info *ri;
   1268      1.55      ober 	u_char *rp;
   1269      1.55      ober 	int height;
   1270      1.55      ober 
   1271      1.55      ober 	ri = (struct rasops_info *)cookie;
   1272      1.55      ober 
   1273      1.56       mjf 	if (__predict_false((unsigned int)row > ri->ri_rows ||
   1274      1.56       mjf 	    (unsigned int)col > ri->ri_cols))
   1275      1.56       mjf 		return;
   1276      1.56       mjf 
   1277      1.56       mjf 	/* Avoid underflow */
   1278      1.56       mjf 	if ((ri->ri_rows - row - 1) < 0)
   1279      1.56       mjf 		return;
   1280      1.56       mjf 
   1281      1.55      ober 	/* Do rotated char sans (side)underline */
   1282      1.55      ober 	ri->ri_real_ops.putchar(cookie, col, ri->ri_rows - row - 1, uc,
   1283      1.55      ober 	    attr & ~1);
   1284      1.55      ober 
   1285      1.55      ober 	/* Do rotated underline */
   1286      1.55      ober 	rp = ri->ri_bits + col * ri->ri_yscale + (ri->ri_rows - row - 1) *
   1287      1.55      ober 	    ri->ri_xscale;
   1288      1.55      ober 	height = ri->ri_font->fontheight;
   1289      1.55      ober 
   1290      1.55      ober 	/* XXX this assumes 16-bit color depth */
   1291      1.55      ober 	if ((attr & 1) != 0) {
   1292      1.55      ober 		int16_t c = (int16_t)ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
   1293      1.55      ober 
   1294      1.55      ober 		while (height--) {
   1295      1.55      ober 			*(int16_t *)rp = c;
   1296      1.55      ober 			rp += ri->ri_stride;
   1297      1.55      ober 		}
   1298      1.55      ober 	}
   1299      1.55      ober }
   1300      1.55      ober 
   1301      1.55      ober static void
   1302  1.61.2.1  uebayasi rasops_erasecols_rotated_cw(void *cookie, int row, int col, int num, long attr)
   1303      1.55      ober {
   1304      1.55      ober 	struct rasops_info *ri;
   1305      1.55      ober 	int i;
   1306      1.55      ober 
   1307      1.55      ober 	ri = (struct rasops_info *)cookie;
   1308      1.55      ober 
   1309      1.55      ober 	for (i = col; i < col + num; i++)
   1310      1.55      ober 		ri->ri_ops.putchar(cookie, row, i, ' ', attr);
   1311      1.55      ober }
   1312      1.55      ober 
   1313      1.55      ober /* XXX: these could likely be optimised somewhat. */
   1314      1.55      ober static void
   1315  1.61.2.1  uebayasi rasops_copyrows_rotated_cw(void *cookie, int src, int dst, int num)
   1316      1.55      ober {
   1317      1.55      ober 	struct rasops_info *ri = (struct rasops_info *)cookie;
   1318      1.55      ober 	int col, roff;
   1319      1.55      ober 
   1320      1.55      ober 	if (src > dst)
   1321      1.55      ober 		for (roff = 0; roff < num; roff++)
   1322      1.55      ober 			for (col = 0; col < ri->ri_cols; col++)
   1323      1.55      ober 				rasops_copychar(cookie, src + roff, dst + roff,
   1324      1.55      ober 				    col, col);
   1325      1.55      ober 	else
   1326      1.55      ober 		for (roff = num - 1; roff >= 0; roff--)
   1327      1.55      ober 			for (col = 0; col < ri->ri_cols; col++)
   1328      1.55      ober 				rasops_copychar(cookie, src + roff, dst + roff,
   1329      1.55      ober 				    col, col);
   1330      1.55      ober }
   1331      1.55      ober 
   1332      1.55      ober static void
   1333  1.61.2.1  uebayasi rasops_copycols_rotated_cw(void *cookie, int row, int src, int dst, int num)
   1334      1.55      ober {
   1335      1.55      ober 	int coff;
   1336      1.55      ober 
   1337      1.55      ober 	if (src > dst)
   1338      1.55      ober 		for (coff = 0; coff < num; coff++)
   1339      1.55      ober 			rasops_copychar(cookie, row, row, src + coff, dst + coff);
   1340      1.55      ober 	else
   1341      1.55      ober 		for (coff = num - 1; coff >= 0; coff--)
   1342      1.55      ober 			rasops_copychar(cookie, row, row, src + coff, dst + coff);
   1343      1.55      ober }
   1344      1.55      ober 
   1345      1.55      ober static void
   1346  1.61.2.1  uebayasi rasops_eraserows_rotated_cw(void *cookie, int row, int num, long attr)
   1347      1.55      ober {
   1348      1.55      ober 	struct rasops_info *ri;
   1349      1.55      ober 	int col, rn;
   1350      1.55      ober 
   1351      1.55      ober 	ri = (struct rasops_info *)cookie;
   1352      1.55      ober 
   1353      1.55      ober 	for (rn = row; rn < row + num; rn++)
   1354      1.55      ober 		for (col = 0; col < ri->ri_cols; col++)
   1355      1.55      ober 			ri->ri_ops.putchar(cookie, rn, col, ' ', attr);
   1356      1.55      ober }
   1357  1.61.2.1  uebayasi 
   1358  1.61.2.1  uebayasi /*
   1359  1.61.2.1  uebayasi  * Quarter counter-clockwise rotation routines (originally intended for the
   1360  1.61.2.1  uebayasi  * built-in Sharp W-ZERO3 display in 16bpp).
   1361  1.61.2.1  uebayasi  */
   1362  1.61.2.1  uebayasi static void
   1363  1.61.2.1  uebayasi rasops_copychar_ccw(void *cookie, int srcrow, int dstrow, int srccol, int dstcol)
   1364  1.61.2.1  uebayasi {
   1365  1.61.2.1  uebayasi 	struct rasops_info *ri;
   1366  1.61.2.1  uebayasi 	u_char *sp, *dp;
   1367  1.61.2.1  uebayasi 	int height;
   1368  1.61.2.1  uebayasi 	int r_srcrow, r_dstrow, r_srccol, r_dstcol;
   1369  1.61.2.1  uebayasi 
   1370  1.61.2.1  uebayasi 	ri = (struct rasops_info *)cookie;
   1371  1.61.2.1  uebayasi 
   1372  1.61.2.1  uebayasi 	r_srcrow = ri->ri_cols - srccol - 1;
   1373  1.61.2.1  uebayasi 	r_dstrow = ri->ri_cols - dstcol - 1;
   1374  1.61.2.1  uebayasi 	r_srccol = srcrow;
   1375  1.61.2.1  uebayasi 	r_dstcol = dstrow;
   1376  1.61.2.1  uebayasi 
   1377  1.61.2.1  uebayasi 	r_srcrow *= ri->ri_yscale;
   1378  1.61.2.1  uebayasi 	r_dstrow *= ri->ri_yscale;
   1379  1.61.2.1  uebayasi 	height = ri->ri_font->fontheight;
   1380  1.61.2.1  uebayasi 
   1381  1.61.2.1  uebayasi 	sp = ri->ri_bits + r_srcrow + r_srccol * ri->ri_xscale;
   1382  1.61.2.1  uebayasi 	dp = ri->ri_bits + r_dstrow + r_dstcol * ri->ri_xscale;
   1383  1.61.2.1  uebayasi 
   1384  1.61.2.1  uebayasi 	while (height--) {
   1385  1.61.2.1  uebayasi 		memmove(dp, sp, ri->ri_xscale);
   1386  1.61.2.1  uebayasi 		dp += ri->ri_stride;
   1387  1.61.2.1  uebayasi 		sp += ri->ri_stride;
   1388  1.61.2.1  uebayasi 	}
   1389  1.61.2.1  uebayasi }
   1390  1.61.2.1  uebayasi 
   1391  1.61.2.1  uebayasi static void
   1392  1.61.2.1  uebayasi rasops_putchar_rotated_ccw(void *cookie, int row, int col, u_int uc, long attr)
   1393  1.61.2.1  uebayasi {
   1394  1.61.2.1  uebayasi 	struct rasops_info *ri;
   1395  1.61.2.1  uebayasi 	u_char *rp;
   1396  1.61.2.1  uebayasi 	int height;
   1397  1.61.2.1  uebayasi 
   1398  1.61.2.1  uebayasi 	ri = (struct rasops_info *)cookie;
   1399  1.61.2.1  uebayasi 
   1400  1.61.2.1  uebayasi 	if (__predict_false((unsigned int)row > ri->ri_rows ||
   1401  1.61.2.1  uebayasi 	    (unsigned int)col > ri->ri_cols))
   1402  1.61.2.1  uebayasi 		return;
   1403  1.61.2.1  uebayasi 
   1404  1.61.2.1  uebayasi 	/* Avoid underflow */
   1405  1.61.2.1  uebayasi 	if ((ri->ri_cols - col - 1) < 0)
   1406  1.61.2.1  uebayasi 		return;
   1407  1.61.2.1  uebayasi 
   1408  1.61.2.1  uebayasi 	/* Do rotated char sans (side)underline */
   1409  1.61.2.1  uebayasi 	ri->ri_real_ops.putchar(cookie, ri->ri_cols - col - 1, row, uc,
   1410  1.61.2.1  uebayasi 	    attr & ~1);
   1411  1.61.2.1  uebayasi 
   1412  1.61.2.1  uebayasi 	/* Do rotated underline */
   1413  1.61.2.1  uebayasi 	rp = ri->ri_bits + (ri->ri_cols - col - 1) * ri->ri_yscale +
   1414  1.61.2.1  uebayasi 	    row * ri->ri_xscale;
   1415  1.61.2.1  uebayasi 	height = ri->ri_font->fontheight;
   1416  1.61.2.1  uebayasi 
   1417  1.61.2.1  uebayasi 	/* XXX this assumes 16-bit color depth */
   1418  1.61.2.1  uebayasi 	if ((attr & 1) != 0) {
   1419  1.61.2.1  uebayasi 		int16_t c = (int16_t)ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
   1420  1.61.2.1  uebayasi 
   1421  1.61.2.1  uebayasi 		while (height--) {
   1422  1.61.2.1  uebayasi 			*(int16_t *)rp = c;
   1423  1.61.2.1  uebayasi 			rp += ri->ri_stride;
   1424  1.61.2.1  uebayasi 		}
   1425  1.61.2.1  uebayasi 	}
   1426  1.61.2.1  uebayasi }
   1427  1.61.2.1  uebayasi 
   1428  1.61.2.1  uebayasi /* XXX: these could likely be optimised somewhat. */
   1429  1.61.2.1  uebayasi static void
   1430  1.61.2.1  uebayasi rasops_copyrows_rotated_ccw(void *cookie, int src, int dst, int num)
   1431  1.61.2.1  uebayasi {
   1432  1.61.2.1  uebayasi 	struct rasops_info *ri = (struct rasops_info *)cookie;
   1433  1.61.2.1  uebayasi 	int col, roff;
   1434  1.61.2.1  uebayasi 
   1435  1.61.2.1  uebayasi 	if (src > dst)
   1436  1.61.2.1  uebayasi 		for (roff = 0; roff < num; roff++)
   1437  1.61.2.1  uebayasi 			for (col = 0; col < ri->ri_cols; col++)
   1438  1.61.2.1  uebayasi 				rasops_copychar_ccw(cookie,
   1439  1.61.2.1  uebayasi 				    src + roff, dst + roff, col, col);
   1440  1.61.2.1  uebayasi 	else
   1441  1.61.2.1  uebayasi 		for (roff = num - 1; roff >= 0; roff--)
   1442  1.61.2.1  uebayasi 			for (col = 0; col < ri->ri_cols; col++)
   1443  1.61.2.1  uebayasi 				rasops_copychar_ccw(cookie,
   1444  1.61.2.1  uebayasi 				    src + roff, dst + roff, col, col);
   1445  1.61.2.1  uebayasi }
   1446  1.61.2.1  uebayasi 
   1447  1.61.2.1  uebayasi static void
   1448  1.61.2.1  uebayasi rasops_copycols_rotated_ccw(void *cookie, int row, int src, int dst, int num)
   1449  1.61.2.1  uebayasi {
   1450  1.61.2.1  uebayasi 	int coff;
   1451  1.61.2.1  uebayasi 
   1452  1.61.2.1  uebayasi 	if (src > dst)
   1453  1.61.2.1  uebayasi 		for (coff = 0; coff < num; coff++)
   1454  1.61.2.1  uebayasi 			rasops_copychar_ccw(cookie, row, row,
   1455  1.61.2.1  uebayasi 			    src + coff, dst + coff);
   1456  1.61.2.1  uebayasi 	else
   1457  1.61.2.1  uebayasi 		for (coff = num - 1; coff >= 0; coff--)
   1458  1.61.2.1  uebayasi 			rasops_copychar_ccw(cookie, row, row,
   1459  1.61.2.1  uebayasi 			    src + coff, dst + coff);
   1460  1.61.2.1  uebayasi }
   1461      1.55      ober #endif	/* NRASOPS_ROTATION */
   1462