grfabs_reg.h revision 1.3 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.3 1994/06/29 13:13:08 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 BMB_ALIGN64, /* init/read. */
122 };
123
124 enum bitmap_flags {
125 BMF_CLEAR = 1 << BMB_CLEAR, /* init only. */
126 BMF_INTERLEAVED = 1 << BMB_INTERLEAVED, /* init/read. */
127 BMF_ALIGN64 = 1 << BMB_ALIGN64 /* init/read. */
128 };
129
130 /* Use these macros to find misc. sizes of actual bitmap */
131 #define BM_WIDTH(b) ((b)->bytes_per_row << 3)
132 #define BM_HEIGHT(b) ((b)->rows)
133 #define BM_ROW(b,p,l) \
134 ((b)->plane[p] + (((b)->bytes_per_row + (b)->row_mod) * l))
135
136 /*
137 * Colormap stuff.
138 */
139
140 /*
141 * valid masks are a bitfield of zeros followed by ones that indicate
142 * which mask are valid for each component. The ones and zeros will
143 * be contiguous so adding one to this value yields the number of
144 * levels for that component.
145 * -ch
146 */
147
148 struct colormap {
149 u_char type; /* what type of entries these are. */
150 union {
151 /* CM_GREYSCALE */
152 u_char grey;
153 #define grey_mask valid_mask.grey
154 /* CM_COLOR */
155 struct {
156 u_char red;
157 #define red_mask valid_mask.rgb_mask.red
158 u_char green;
159 #define green_mask valid_mask.rgb_mask.green
160 u_char blue;
161 #define blue_mask valid_mask.rgb_mask.blue
162 } rgb_mask;
163 } valid_mask;
164 u_short first; /* what color register does entry[0] refer to. */
165 u_short size; /* number of entries */
166 u_long *entry; /* the table of actual color values. */
167 };
168
169 enum colormap_type {
170 CM_MONO, /* only on or off allowed */
171 CM_GREYSCALE, /* grey vals. */
172 CM_COLOR /* RGB vals. */
173 };
174
175 #define CM_FIXVAL(x) (0xff & (x))
176
177 /* these macros are for creating entries */
178 #define MAKE_COLOR_ENTRY(r,g,b) \
179 (CM_FIXVAL(r) << 16 | CM_FIXVAL(g) << 8 | CM_FIXVAL(b))
180 #define MAKE_MONO_ENTRY(x) ((x) ? 1 : 0)
181 #define MAKE_GREY_ENTRY(l) CM_FIXVAL(l)
182
183 #define CM_LTOW(v) \
184 (((0x000F0000 & (v)) >> 8) | ((0x00000F00 & (v)) >> 4) | (0xF & (v)))
185 #define CM_WTOL(v) \
186 (((0xF00 & (v)) << 8) | ((0x0F0 & (v)) << 4) | (0xF & (v)))
187
188 /*
189 * View stuff.
190 */
191 typedef void remove_view_func (view_t *v);
192 typedef void free_view_func (view_t *v);
193 typedef void display_view_func (view_t *v);
194 typedef dmode_t *get_mode_func (view_t *v);
195 typedef int get_colormap_func (view_t *v, colormap_t *);
196 typedef int use_colormap_func (view_t *v, colormap_t *);
197
198 struct view {
199 bmap_t *bitmap; /* bitmap. */
200 box_t display; /* viewable area. */
201 void *data; /* view specific data. */
202
203 /* functions */
204 display_view_func *display_view; /* make this view active */
205 remove_view_func *remove_view; /* remove this view if active */
206 free_view_func *free_view; /* free this view */
207 get_mode_func *get_display_mode;/* get the mode this view belongs to */
208 get_colormap_func *get_colormap; /* get a color map for registers */
209 use_colormap_func *use_colormap; /* use color map to load registers */
210 };
211
212 #define VDISPLAY_LINE(v, p, l) ((v)->bitmap->plane[(p)] +\
213 (((v)->bitmap->bytes_per_row + (v)->bitmap->row_mod) * l))
214
215 /*
216 * Mode stuff
217 */
218
219 typedef view_t *alloc_view_func (dmode_t *mode, dimen_t *dim, u_char depth);
220 typedef view_t *get_current_view_func (dmode_t *);
221 typedef monitor_t *get_monitor_func (dmode_t *);
222
223 struct display_mode {
224 LIST_ENTRY(display_mode) link;
225 u_char *name; /* logical name for mode. */
226 dimen_t nominal_size; /* best fit. */
227 void *data; /* mode specific flags. */
228 alloc_view_func *alloc_view; /* allocate a view for this mode. */
229 get_current_view_func *get_current_view; /* get active view. */
230 get_monitor_func *get_monitor; /* get monitor that mode belongs to */
231 };
232
233 /*
234 * Monitor stuff.
235 */
236 typedef void vbl_handler_func (void *);
237 typedef dmode_t *get_next_mode_func (dmode_t *);
238 typedef dmode_t *get_current_mode_func (void);
239 typedef dmode_t *get_best_mode_func (dimen_t *size, u_char depth);
240 typedef bmap_t *alloc_bitmap_func (u_short w, u_short h, u_short d, u_short f);
241 typedef void free_bitmap_func (bmap_t *bm);
242
243 struct monitor {
244 LIST_ENTRY(monitor) link; /* a link into the database. */
245 u_char *name; /* a logical name for this monitor. */
246 void *data; /* monitor specific data. */
247 get_current_mode_func *get_current_mode;
248 vbl_handler_func *vbl_handler; /* called on every vbl if not NULL */
249 get_next_mode_func *get_next_mode; /* return next mode in list */
250 get_best_mode_func *get_best_mode; /* return mode that best fits */
251
252 alloc_bitmap_func *alloc_bitmap;
253 free_bitmap_func *free_bitmap;
254 };
255
256 /*
257 * Misc draw related macros.
258 */
259
260 #define BOX_2_RECT(b,r) do { \
261 (r)->left = (b)->x; (r)->top = (b)->y; \
262 (r)->right = (b)->x + (b)->width -1; \
263 (r)->bottom = (b)->y + (b)->height -1; \
264 } while (0)
265
266 #define RECT_2_BOX(r,b) do { \
267 (b)->x = (r)->left; \
268 (b)->y = (r)->top; \
269 (b)->width = (r)->right - (r)->left +1; \
270 (b)->height = (r)->bottom - (r)->top +1; \
271 } while(0)
272
273 #define INIT_BOX(b,xx,yy,ww,hh) do{(b)->x = xx; (b)->y = yy; (b)->width = ww; (b)->height = hh;}while (0)
274 #define INIT_RECT(rc,l,t,r,b) do{(rc)->left = l; (rc)->right = r; (rc)->top = t; (rc)->bottom = b;}while (0)
275 #define INIT_POINT(p,xx,yy) do {(p)->x = xx; (p)->y = yy;} while (0)
276 #define INIT_DIM(d,w,h) do {(d)->width = w; (d)->height = h;} while (0)
277
278
279 /*
280 * Prototypes
281 */
282
283 #if defined (__STDC__)
284 /* views */
285 view_t * grf_alloc_view (dmode_t *d, dimen_t *dim, u_char depth);
286 void grf_display_view (view_t *v);
287 void grf_remove_view (view_t *v);
288 void grf_free_view (view_t *v);
289 dmode_t *grf_get_display_mode (view_t *v);
290 int grf_get_colormap (view_t *v, colormap_t *cm);
291 int grf_use_colormap (view_t *v, colormap_t *cm);
292 /* modes */
293 view_t *grf_get_current_view (dmode_t *d);
294 monitor_t *grf_get_monitor (dmode_t *d);
295 /* monitors */
296 dmode_t * grf_get_next_mode (monitor_t *m, dmode_t *d);
297 dmode_t * grf_get_current_mode (monitor_t *);
298 dmode_t * grf_get_best_mode (monitor_t *m, dimen_t *size, u_char depth);
299 bmap_t * grf_alloc_bitmap (monitor_t *m, u_short w, u_short h, u_short d, u_short f);
300 void grf_free_bitmap (monitor_t *m, bmap_t *bm);
301 #endif /* __STDC__ */
302
303 #endif /* _GRFABS_REG_H */
304