Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / amiga / dev / grfabs.c
blob2e692228d18498c2ac12113438c17abefba6b6e5
1 /* $NetBSD: grfabs.c,v 1.6 2002/01/26 13:40:55 aymeric Exp $ */
3 /*
4 * Copyright (c) 1994 Christian E. Hopps
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Christian E. Hopps.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD$");
37 * amiga abstract graphics driver.
39 #include <sys/param.h>
40 #include <sys/queue.h>
42 #include <amiga/amiga/color.h>
43 #include <amiga/amiga/cc.h>
44 #include <amiga/dev/grfabs_reg.h>
47 * General and init.
50 /* add your monitor here. */
51 monitor_t *cc_init_monitor (void);
53 /* and here. */
54 monitor_t *(*init_monitor[])(void) = {
55 cc_init_monitor,
56 NULL
59 struct monitor_list instance_monitors, *monitors;
61 struct vbl_node grf_vbl_node;
63 #define ABS(type, val) \
64 (type) (((int)(val) < 0) ? -(val) : (val))
66 void grf_vbl_function(void *data);
67 dmode_t *get_best_display_mode(u_long, u_long, u_char);
70 void
71 grf_vbl_function(void *data)
73 monitor_t *m;
75 if (monitors == NULL)
76 return;
78 for (m = monitors->lh_first; m != NULL; m = m->link.le_next) {
79 if (m->vbl_handler)
80 m->vbl_handler(m);
85 * XXX: called from ite console init routine.
86 * Does just what configure will do later but without printing anything.
89 int
90 grfcc_probe(void)
92 int i = 0;
94 grf_vbl_node.function = grf_vbl_function;
96 if (NULL == monitors) {
97 LIST_INIT(&instance_monitors);
98 monitors = &instance_monitors;
100 while (init_monitor[i]) {
101 init_monitor[i] ();
102 i++;
104 if (i) {
105 add_vbl_function(&grf_vbl_node, 1, 0);
106 return(1);
108 return(0);
110 return(1);
113 dmode_t *
114 get_best_display_mode(u_long width, u_long height, u_char depth)
116 monitor_t *m;
117 dmode_t *d, *save;
118 dimen_t dim;
119 long dx, dy, ct, dt = 0;
121 save = NULL;
122 for (m = monitors->lh_first; m != NULL; m = m->link.le_next) {
123 dim.width = width;
124 dim.height = height;
125 d = m->get_best_mode(&dim, depth);
126 if (d) {
127 dx = ABS(long, (d->nominal_size.width - width));
128 dy = ABS(long, (d->nominal_size.height - height));
129 ct = dx + dy;
131 if (ct < dt || save == NULL) {
132 save = d;
133 dt = ct;
137 return(save);
142 * Monitor stuff.
145 dmode_t *
146 grf_get_next_mode(monitor_t *m, dmode_t *d)
148 return(m->get_next_mode(d));
151 dmode_t *
152 grf_get_current_mode(monitor_t *m)
154 return(m->get_current_mode());
157 dmode_t *
158 grf_get_best_mode(monitor_t *m, dimen_t *size, u_char depth)
160 return(m->get_best_mode(size, depth));
163 bmap_t *
164 grf_alloc_bitmap(monitor_t *m, u_short w, u_short h, u_short d, u_short f)
166 return(m->alloc_bitmap(w, h, d, f));
169 void
170 grf_free_bitmap(monitor_t *m, bmap_t *bm)
172 m->free_bitmap(bm);
176 * Mode stuff.
179 view_t *
180 grf_get_current_view(dmode_t *d)
182 return(d->get_current_view(d));
185 monitor_t *
186 grf_get_monitor(dmode_t *d)
188 return(d->get_monitor(d));
192 * View stuff.
195 void
196 grf_display_view(view_t *v)
198 v->display_view(v);
201 view_t *
202 grf_alloc_view(dmode_t *d, dimen_t *dim, u_char depth)
204 if (!d)
205 d = get_best_display_mode(dim->width, dim->height, depth);
206 if (d)
207 return(d->alloc_view(d, dim, depth));
208 return(NULL);
211 void
212 grf_remove_view(view_t *v)
214 v->remove_view(v);
217 void
218 grf_free_view(view_t *v)
220 v->free_view(v);
223 dmode_t *
224 grf_get_display_mode(view_t *v)
226 return(v->get_display_mode(v));
230 grf_get_colormap(view_t *v, colormap_t *cm)
232 return(v->get_colormap(v, cm));
236 grf_use_colormap(view_t *v, colormap_t *cm)
238 return(v->use_colormap(v, cm));