xref: /netbsd/sys/arch/amiga/dev/grfabs.c (revision bf9ec67e)
1 /*	$NetBSD: grfabs.c,v 1.7 2002/01/28 09:56:57 aymeric Exp $ */
2 
3 /*
4  * Copyright (c) 1994 Christian E. Hopps
5  * All rights reserved.
6  *
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
20  *
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.
31  */
32 
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: grfabs.c,v 1.7 2002/01/28 09:56:57 aymeric Exp $");
35 
36 /*
37  *  amiga abstract graphics driver.
38  */
39 #include <sys/param.h>
40 #include <sys/queue.h>
41 
42 #include <amiga/amiga/color.h>
43 #include <amiga/amiga/cc.h>
44 #include <amiga/dev/grfabs_reg.h>
45 
46 /*
47  * General and init.
48  */
49 
50 /* add your monitor here. */
51 monitor_t *cc_init_monitor (void);
52 
53 /* and here. */
54 monitor_t *(*init_monitor[])(void) = {
55     cc_init_monitor,
56     NULL
57 };
58 
59 struct monitor_list instance_monitors, *monitors;
60 
61 struct vbl_node grf_vbl_node;
62 
63 #define ABS(type, val) \
64     (type) (((int)(val) < 0) ? -(val) : (val))
65 
66 void grf_vbl_function(void *data);
67 dmode_t *get_best_display_mode(u_long, u_long, u_char);
68 
69 
70 void
71 grf_vbl_function(void *data)
72 {
73 	monitor_t *m;
74 
75 	if (monitors == NULL)
76 		return;
77 
78 	for (m = monitors->lh_first; m != NULL; m = m->link.le_next) {
79 		if (m->vbl_handler)
80 			m->vbl_handler(m);
81 	}
82 }
83 
84 /*
85  * XXX: called from ite console init routine.
86  * Does just what configure will do later but without printing anything.
87  */
88 
89 int
90 grfcc_probe(void)
91 {
92 	int i = 0;
93 
94 	grf_vbl_node.function = grf_vbl_function;
95 
96 	if (NULL == monitors) {
97 		LIST_INIT(&instance_monitors);
98 		monitors = &instance_monitors;
99 
100 		while (init_monitor[i]) {
101 			init_monitor[i] ();
102 			i++;
103 		}
104 		if (i) {
105 			add_vbl_function(&grf_vbl_node, 1, 0);
106 			return(1);
107 		}
108 		return(0);
109 	}
110 	return(1);
111 }
112 
113 dmode_t *
114 get_best_display_mode(u_long width, u_long height, u_char depth)
115 {
116 	monitor_t *m;
117 	dmode_t *d, *save;
118 	dimen_t dim;
119 	long dx, dy, ct, dt = 0;
120 
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;
130 
131 			if (ct < dt || save == NULL) {
132 				save = d;
133 				dt = ct;
134 			}
135 		}
136 	}
137 	return(save);
138 }
139 
140 
141 /*
142  * Monitor stuff.
143  */
144 
145 dmode_t *
146 grf_get_next_mode(monitor_t *m, dmode_t *d)
147 {
148 	return(m->get_next_mode(d));
149 }
150 
151 dmode_t *
152 grf_get_current_mode(monitor_t *m)
153 {
154 	return(m->get_current_mode());
155 }
156 
157 dmode_t *
158 grf_get_best_mode(monitor_t *m, dimen_t *size, u_char depth)
159 {
160 	return(m->get_best_mode(size, depth));
161 }
162 
163 bmap_t *
164 grf_alloc_bitmap(monitor_t *m, u_short w, u_short h, u_short d, u_short f)
165 {
166 	return(m->alloc_bitmap(w, h, d, f));
167 }
168 
169 void
170 grf_free_bitmap(monitor_t *m, bmap_t *bm)
171 {
172 	m->free_bitmap(bm);
173 }
174 
175 /*
176  * Mode stuff.
177  */
178 
179 view_t *
180 grf_get_current_view(dmode_t *d)
181 {
182 	return(d->get_current_view(d));
183 }
184 
185 monitor_t *
186 grf_get_monitor(dmode_t *d)
187 {
188 	return(d->get_monitor(d));
189 }
190 
191 /*
192  * View stuff.
193  */
194 
195 void
196 grf_display_view(view_t *v)
197 {
198 	v->display_view(v);
199 }
200 
201 view_t *
202 grf_alloc_view(dmode_t *d, dimen_t *dim, u_char depth)
203 {
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);
209 }
210 
211 void
212 grf_remove_view(view_t *v)
213 {
214 	v->remove_view(v);
215 }
216 
217 void
218 grf_free_view(view_t *v)
219 {
220 	v->free_view(v);
221 }
222 
223 dmode_t *
224 grf_get_display_mode(view_t *v)
225 {
226 	return(v->get_display_mode(v));
227 }
228 
229 int
230 grf_get_colormap(view_t *v, colormap_t *cm)
231 {
232 	return(v->get_colormap(v, cm));
233 }
234 
235 int
236 grf_use_colormap(view_t *v, colormap_t *cm)
237 {
238 	return(v->use_colormap(v, cm));
239 }
240