grfabs_reg.h revision 1.2 1 /*
2 * Copyright (c) 1994 Christian E. Hopps
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by Christian E. Hopps.
16 * 4. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 *
30 * $Id: grfabs_reg.h,v 1.2 1994/03/27 06:23:37 chopps Exp $
31 */
32
33 #if ! defined (_GRFABS_REG_H)
34 #define _GRFABS_REG_H
35
36 struct point {
37 long x;
38 long y;
39 };
40 typedef struct point point_t;
41
42 struct dimension {
43 u_long width;
44 u_long height;
45 };
46 typedef struct dimension dimen_t;
47
48 struct box {
49 long x;
50 long y;
51 u_long width;
52 u_long height;
53 };
54 typedef struct box box_t;
55
56 struct rectangle {
57 long left;
58 long top;
59 long right;
60 long bottom;
61 };
62
63 typedef struct rectangle rect_t;
64
65 typedef struct bitmap bmap_t;
66 typedef struct colormap colormap_t;
67 typedef struct view view_t;
68 typedef struct display_mode dmode_t;
69 typedef struct monitor monitor_t;
70
71 LIST_HEAD(monitor_list, monitor);
72 extern struct monitor_list *monitors;
73
74 /*
75 * Bitmap stuff.
76 */
77
78 /*
79 * Note structure is 5 long words big. This may come in handy for
80 * contiguous allocations
81 *
82 * Please do fill in everything correctly this is the main input for
83 * all other programs. In other words all problems with RTG start here.
84 * If you do not mimic everyone else exactly problems will appear.
85 * If you need a template look at alloc_bitmap() in grf_cc.c.
86 *
87 * WARNING: the plane array is only for convience, all data for bitplanes
88 * MUST be contiguous. This is for mapping purposes. The reason
89 * for the plane pointers and row_mod is to support interleaving
90 * on monitors that wish to support this.
91 *
92 * 2nd Warning: Also don't get funky with these pointers you are expected
93 * to place the start of mappable plane data in ``hardware_address'',
94 * ``hardware_address'' is the only thing that /dev/view checks and it
95 * expects the planes to follow with no padding in between. If you have
96 * special alignment requirements make use of the given fields
97 * so that the entire contiguous plane data is exactly:
98 * bytes_per_row*height*depth long starting at the physical address
99 * contained within hardware_address.
100 *
101 * Final Warning: Plane data must begin on a PAGE address and the allocation
102 * must be ``n'' PAGES big do to mapping requirements (otherwise the
103 * user could write over non-allocated memory.
104 *
105 */
106 struct bitmap {
107 u_short bytes_per_row; /* number of bytes per display row. */
108 u_short row_mod; /* number of bytes to reach next row. */
109 u_short rows; /* number of display rows. */
110 u_short depth; /* depth of bitmap. */
111 u_short flags; /* flags. */
112 u_short pad;
113 u_char *blit_temp; /* private monitor buffer. */
114 u_char **plane; /* plane data for bitmap. */
115 u_char *hardware_address; /* mappable bitplane pointer. */
116 };
117
118 enum bitmap_flag_bits {
119 BMB_CLEAR, /* init only. */
120 BMB_INTERLEAVED, /* init/read. */
121 };
122
123 enum bitmap_flags {
124 BMF_CLEAR = 1 << BMB_CLEAR, /* init only. */
125 BMF_INTERLEAVED = 1 << BMB_INTERLEAVED, /* init/read. */
126 };
127
128 /* Use these macros to find misc. sizes of actual bitmap */
129 #define BM_WIDTH(b) ((b)->bytes_per_row << 3)
130 #define BM_HEIGHT(b) ((b)->rows)
131 #define BM_ROW(b,p,l) \
132 ((b)->plane[p] + (((b)->bytes_per_row + (b)->row_mod) * l))
133
134 /*
135 * Colormap stuff.
136 */
137
138 /*
139 * valid masks are a bitfield of zeros followed by ones that indicate
140 * which mask are valid for each component. The ones and zeros will
141 * be contiguous so adding one to this value yields the number of
142 * levels for that component.
143 * -ch
144 */
145
146 struct colormap {
147 u_char type; /* what type of entries these are. */
148 union {
149 /* CM_GREYSCALE */
150 u_char grey;
151 #define grey_mask valid_mask.grey
152 /* CM_COLOR */
153 struct {
154 u_char red;
155 #define red_mask valid_mask.rgb_mask.red
156 u_char green;
157 #define green_mask valid_mask.rgb_mask.green
158 u_char blue;
159 #define blue_mask valid_mask.rgb_mask.blue
160 } rgb_mask;
161 } valid_mask;
162 u_short first; /* what color register does entry[0] refer to. */
163 u_short size; /* number of entries */
164 u_long *entry; /* the table of actual color values. */
165 };
166
167 enum colormap_type {
168 CM_MONO, /* only on or off allowed */
169 CM_GREYSCALE, /* grey vals. */
170 CM_COLOR /* RGB vals. */
171 };
172
173 #define CM_FIXVAL(x) (0xff & (x))
174
175 /* these macros are for creating entries */
176 #define MAKE_COLOR_ENTRY(r,g,b) \
177 (CM_FIXVAL(r) << 16 | CM_FIXVAL(g) << 8 | CM_FIXVAL(b))
178 #define MAKE_MONO_ENTRY(x) ((x) ? 1 : 0)
179 #define MAKE_GREY_ENTRY(l) CM_FIXVAL(l)
180
181 #define CM_LTOW(v) \
182 (((0x000F0000 & (v)) >> 8) | ((0x00000F00 & (v)) >> 4) | (0xF & (v)))
183 #define CM_WTOL(v) \
184 (((0xF00 & (v)) << 8) | ((0x0F0 & (v)) << 4) | (0xF & (v)))
185
186 /*
187 * View stuff.
188 */
189 typedef void remove_view_func (view_t *v);
190 typedef void free_view_func (view_t *v);
191 typedef void display_view_func (view_t *v);
192 typedef dmode_t *get_mode_func (view_t *v);
193 typedef int get_colormap_func (view_t *v, colormap_t *);
194 typedef int use_colormap_func (view_t *v, colormap_t *);
195
196 struct view {
197 bmap_t *bitmap; /* bitmap. */
198 box_t display; /* viewable area. */
199 void *data; /* view specific data. */
200
201 /* functions */
202 display_view_func *display_view; /* make this view active */
203 remove_view_func *remove_view; /* remove this view if active */
204 free_view_func *free_view; /* free this view */
205 get_mode_func *get_display_mode;/* get the mode this view belongs to */
206 get_colormap_func *get_colormap; /* get a color map for registers */
207 use_colormap_func *use_colormap; /* use color map to load registers */
208 };
209
210 #define VDISPLAY_LINE(v, p, l) ((v)->bitmap->plane[(p)] +\
211 (((v)->bitmap->bytes_per_row + (v)->bitmap->row_mod) * l))
212
213 /*
214 * Mode stuff
215 */
216
217 typedef view_t *alloc_view_func (dmode_t *mode, dimen_t *dim, u_char depth);
218 typedef view_t *get_current_view_func (dmode_t *);
219 typedef monitor_t *get_monitor_func (dmode_t *);
220
221 struct display_mode {
222 LIST_ENTRY(display_mode) link;
223 u_char *name; /* logical name for mode. */
224 dimen_t nominal_size; /* best fit. */
225 void *data; /* mode specific flags. */
226 alloc_view_func *alloc_view; /* allocate a view for this mode. */
227 get_current_view_func *get_current_view; /* get active view. */
228 get_monitor_func *get_monitor; /* get monitor that mode belongs to */
229 };
230
231 /*
232 * Monitor stuff.
233 */
234 typedef void vbl_handler_func (void *);
235 typedef dmode_t *get_next_mode_func (dmode_t *);
236 typedef dmode_t *get_current_mode_func (void);
237 typedef dmode_t *get_best_mode_func (dimen_t *size, u_char depth);
238 typedef bmap_t *alloc_bitmap_func (u_short w, u_short h, u_short d, u_short f);
239 typedef void free_bitmap_func (bmap_t *bm);
240
241 struct monitor {
242 LIST_ENTRY(monitor) link; /* a link into the database. */
243 u_char *name; /* a logical name for this monitor. */
244 void *data; /* monitor specific data. */
245 get_current_mode_func *get_current_mode;
246 vbl_handler_func *vbl_handler; /* called on every vbl if not NULL */
247 get_next_mode_func *get_next_mode; /* return next mode in list */
248 get_best_mode_func *get_best_mode; /* return mode that best fits */
249
250 alloc_bitmap_func *alloc_bitmap;
251 free_bitmap_func *free_bitmap;
252 };
253
254 /*
255 * Misc draw related macros.
256 */
257
258 #define BOX_2_RECT(b,r) do { \
259 (r)->left = (b)->x; (r)->top = (b)->y; \
260 (r)->right = (b)->x + (b)->width -1; \
261 (r)->bottom = (b)->y + (b)->height -1; \
262 } while (0)
263
264 #define RECT_2_BOX(r,b) do { \
265 (b)->x = (r)->left; \
266 (b)->y = (r)->top; \
267 (b)->width = (r)->right - (r)->left +1; \
268 (b)->height = (r)->bottom - (r)->top +1; \
269 } while(0)
270
271 #define INIT_BOX(b,xx,yy,ww,hh) do{(b)->x = xx; (b)->y = yy; (b)->width = ww; (b)->height = hh;}while (0)
272 #define INIT_RECT(rc,l,t,r,b) do{(rc)->left = l; (rc)->right = r; (rc)->top = t; (rc)->bottom = b;}while (0)
273 #define INIT_POINT(p,xx,yy) do {(p)->x = xx; (p)->y = yy;} while (0)
274 #define INIT_DIM(d,w,h) do {(d)->width = w; (d)->height = h;} while (0)
275
276
277 /*
278 * Prototypes
279 */
280
281 #if defined (__STDC__)
282 /* views */
283 view_t * grf_alloc_view (dmode_t *d, dimen_t *dim, u_char depth);
284 void grf_display_view (view_t *v);
285 void grf_remove_view (view_t *v);
286 void grf_free_view (view_t *v);
287 dmode_t *grf_get_display_mode (view_t *v);
288 int grf_get_colormap (view_t *v, colormap_t *cm);
289 int grf_use_colormap (view_t *v, colormap_t *cm);
290 /* modes */
291 view_t *grf_get_current_view (dmode_t *d);
292 monitor_t *grf_get_monitor (dmode_t *d);
293 /* monitors */
294 dmode_t * grf_get_next_mode (monitor_t *m, dmode_t *d);
295 dmode_t * grf_get_current_mode (monitor_t *);
296 dmode_t * grf_get_best_mode (monitor_t *m, dimen_t *size, u_char depth);
297 bmap_t * grf_alloc_bitmap (monitor_t *m, u_short w, u_short h, u_short d, u_short f);
298 void grf_free_bitmap (monitor_t *m, bmap_t *bm);
299 #endif /* __STDC__ */
300
301 #endif /* _GRFABS_REG_H */
302