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