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