1 /* $NetBSD: rasops.h,v 1.26 2010/05/06 04:30:18 macallan Exp $ */ 2 3 /*- 4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Andrew Doran. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 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. 18 * 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. 30 */ 31 32 #ifndef _RASOPS_H_ 33 #define _RASOPS_H_ 1 34 35 #include <dev/wscons/wsconsio.h> 36 #include <dev/wsfont/wsfont.h> 37 38 /* For rasops_info::ri_flg */ 39 #define RI_FULLCLEAR 0x01 /* eraserows() hack to clear full screen */ 40 #define RI_FORCEMONO 0x02 /* monochrome output even if we can do color */ 41 #define RI_BSWAP 0x04 /* framebuffer endianness doesn't match CPU */ 42 #define RI_CURSOR 0x08 /* cursor is switched on */ 43 #define RI_CLEAR 0x10 /* clear display on startup */ 44 #define RI_CENTER 0x20 /* center onscreen output */ 45 #define RI_CURSORCLIP 0x40 /* cursor is currently clipped */ 46 #define RI_CFGDONE 0x80 /* rasops_reconfig() completed successfully */ 47 #define RI_ROTATE_CW 0x100 /* display is rotated, quarter clockwise */ 48 #define RI_ROTATE_CCW 0x200 /* display is rotated, quarter counter-clockwise */ 49 #define RI_ROTATE_UD 0x400 /* display is rotated, upside-down */ 50 #define RI_ROTATE_MASK 0x700 51 /* 52 * if you call rasops_init() or rasops_reconfig() in a context where it is not 53 * safe to call kmem_alloc(), like early on during kernel startup, you MUST set 54 * RI_NO_AUTO to keep rasops from trying to allocate memory for autogenerated 55 * box drawing characters 56 */ 57 #define RI_NO_AUTO 0x800 /* do not generate box drawing characters */ 58 59 struct rasops_info { 60 /* These must be filled in by the caller */ 61 int ri_depth; /* depth in bits */ 62 u_char *ri_bits; /* ptr to bits */ 63 int ri_width; /* width (pels) */ 64 int ri_height; /* height (pels) */ 65 int ri_stride; /* stride in bytes */ 66 67 /* 68 * If you want shadow framebuffer support, point ri_hwbits 69 * to the real framebuffer, and ri_bits to the shadow framebuffer 70 */ 71 u_char *ri_hwbits; 72 73 /* 74 * These can optionally be left zeroed out. If you fill ri_font, 75 * but aren't using wsfont, set ri_wsfcookie to -1. 76 */ 77 struct wsdisplay_font *ri_font; 78 struct wsdisplay_font ri_optfont; 79 int ri_wsfcookie; /* wsfont cookie */ 80 void *ri_hw; /* driver private data; ignored by rasops */ 81 int ri_crow; /* cursor row */ 82 int ri_ccol; /* cursor column */ 83 int ri_flg; /* various operational flags */ 84 85 /* 86 * These are optional and will default if zero. Meaningless 87 * on depths other than 15, 16, 24 and 32 bits per pel. On 88 * 24 bit displays, ri_{r,g,b}num must be 8. 89 */ 90 u_char ri_rnum; 91 /* number of bits for red */ 92 u_char ri_gnum; /* number of bits for green */ 93 u_char ri_bnum; /* number of bits for blue */ 94 u_char ri_rpos; /* which bit red starts at */ 95 u_char ri_gpos; /* which bit green starts at */ 96 u_char ri_bpos; /* which bit blue starts at */ 97 98 /* These are filled in by rasops_init() */ 99 int ri_emuwidth; /* width we actually care about */ 100 int ri_emuheight; /* height we actually care about */ 101 int ri_emustride; /* bytes per row we actually care about */ 102 int ri_rows; /* number of rows (characters, not pels) */ 103 int ri_cols; /* number of columns (characters, not pels) */ 104 int ri_delta; /* row delta in bytes */ 105 int ri_pelbytes; /* bytes per pel (may be zero) */ 106 int ri_fontscale; /* fontheight * fontstride */ 107 int ri_xscale; /* fontwidth * pelbytes */ 108 int ri_yscale; /* fontheight * stride */ 109 u_char *ri_origbits; /* where screen bits actually start */ 110 u_char *ri_hworigbits; /* where hw bits actually start */ 111 int ri_xorigin; /* where ri_bits begins (x) */ 112 int ri_yorigin; /* where ri_bits begins (y) */ 113 int32_t ri_devcmap[16]; /* color -> framebuffer data */ 114 115 /* The emulops you need to use, and the screen caps for wscons */ 116 struct wsdisplay_emulops ri_ops; 117 int ri_caps; 118 119 /* Callbacks so we can share some code */ 120 void (*ri_do_cursor)(struct rasops_info *); 121 122 #if NRASOPS_ROTATION > 0 123 /* Used to intercept putchar to permit display rotation */ 124 struct wsdisplay_emulops ri_real_ops; 125 #endif 126 }; 127 128 #define DELTA(p, d, cast) ((p) = (cast)((char *)(p) + (d))) 129 130 #define CHAR_IN_FONT(c,font) \ 131 ((c) >= (font)->firstchar && \ 132 ((c) - (font)->firstchar) < (font)->numchars) 133 134 #define PICK_FONT(ri, c) (((c & WSFONT_FLAGS_MASK) == WSFONT_FLAG_OPT) && \ 135 (ri->ri_optfont.data != NULL)) ? \ 136 &ri->ri_optfont : ri->ri_font 137 138 /* 139 * rasops_init(). 140 * 141 * Integer parameters are the number of rows and columns we'd *like*. 142 * 143 * In terms of optimization, fonts that are a multiple of 8 pixels wide 144 * work the best. 145 * 146 * rasops_init() takes care of rasops_reconfig(). The parameters to both 147 * are the same. If calling rasops_reconfig() to change the font and 148 * ri_wsfcookie >= 0, you must call wsfont_unlock() on it, and reset it 149 * to -1 (or a new, valid cookie). 150 */ 151 152 /* 153 * Per-depth initialization functions. These should not be called outside 154 * the rasops code. 155 */ 156 void rasops1_init(struct rasops_info *); 157 void rasops2_init(struct rasops_info *); 158 void rasops4_init(struct rasops_info *); 159 void rasops8_init(struct rasops_info *); 160 void rasops15_init(struct rasops_info *); 161 void rasops24_init(struct rasops_info *); 162 void rasops32_init(struct rasops_info *); 163 164 /* rasops.c */ 165 int rasops_init(struct rasops_info *, int, int); 166 int rasops_reconfig(struct rasops_info *, int, int); 167 void rasops_unpack_attr(long, int *, int *, int *); 168 void rasops_eraserows(void *, int, int, long); 169 void rasops_erasecols(void *, int, int, int, long); 170 void rasops_copycols(void *, int, int, int, int); 171 172 extern const u_char rasops_isgray[16]; 173 extern const u_char rasops_cmap[256*3]; 174 175 #endif /* _RASOPS_H_ */ 176