1 /* $NetBSD: grfabs.c,v 1.4 1994/10/26 02:03:21 cgd 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 64 grf_vbl_function(data) 65 void *data; 66 { 67 monitor_t *m; 68 69 if (monitors == NULL) 70 return; 71 72 for (m = monitors->lh_first; m != NULL; m = m->link.le_next) { 73 if (m->vbl_handler) 74 m->vbl_handler(m); 75 } 76 } 77 78 /* 79 * XXX: called from ite console init routine. 80 * Does just what configure will do later but without printing anything. 81 */ 82 83 int 84 grfcc_probe() 85 { 86 int i = 0; 87 88 grf_vbl_node.function = grf_vbl_function; 89 90 if (NULL == monitors) { 91 LIST_INIT(&instance_monitors); 92 monitors = &instance_monitors; 93 94 while (init_monitor[i]) { 95 init_monitor[i] (); 96 i++; 97 } 98 if (i) { 99 add_vbl_function(&grf_vbl_node, 1, 0); 100 return(1); 101 } 102 return(0); 103 } 104 return(1); 105 } 106 107 dmode_t * 108 get_best_display_mode(width, height, depth) 109 u_long width, height; 110 u_char depth; 111 { 112 monitor_t *m; 113 dmode_t *d, *save; 114 dimen_t dim; 115 long dx, dy, ct, dt; 116 117 save = NULL; 118 for (m = monitors->lh_first; m != NULL; m = m->link.le_next) { 119 dim.width = width; 120 dim.height = height; 121 d = m->get_best_mode(&dim, depth); 122 if (d) { 123 dx = ABS(long, (d->nominal_size.width - width)); 124 dy = ABS(long, (d->nominal_size.height - height)); 125 ct = dx + dy; 126 127 if (ct < dt || save == NULL) { 128 save = d; 129 dt = ct; 130 } 131 } 132 } 133 return(save); 134 } 135 136 137 /* 138 * Monitor stuff. 139 */ 140 141 dmode_t * 142 grf_get_next_mode(m, d) 143 monitor_t *m; 144 dmode_t *d; 145 { 146 return(m->get_next_mode(d)); 147 } 148 149 dmode_t * 150 grf_get_current_mode(m) 151 monitor_t *m; 152 { 153 return(m->get_current_mode()); 154 } 155 156 dmode_t * 157 grf_get_best_mode(m, size, depth) 158 monitor_t *m; 159 dimen_t *size; 160 u_char depth; 161 { 162 return(m->get_best_mode(size, depth)); 163 } 164 165 bmap_t * 166 grf_alloc_bitmap(m, w, h, d, f) 167 monitor_t *m; 168 u_short w, h, d, f; 169 { 170 return(m->alloc_bitmap(w, h, d, f)); 171 } 172 173 void 174 grf_free_bitmap(m, bm) 175 monitor_t *m; 176 bmap_t *bm; 177 { 178 m->free_bitmap(bm); 179 } 180 181 /* 182 * Mode stuff. 183 */ 184 185 view_t * 186 grf_get_current_view(d) 187 dmode_t *d; 188 { 189 return(d->get_current_view(d)); 190 } 191 192 monitor_t * 193 grf_get_monitor(d) 194 dmode_t *d; 195 { 196 return(d->get_monitor(d)); 197 } 198 199 /* 200 * View stuff. 201 */ 202 203 void 204 grf_display_view(v) 205 view_t *v; 206 { 207 v->display_view(v); 208 } 209 210 view_t * 211 grf_alloc_view(d, dim, depth) 212 dmode_t *d; 213 dimen_t *dim; 214 u_char depth; 215 { 216 if (!d) 217 d = get_best_display_mode(dim->width, dim->height, depth); 218 if (d) 219 return(d->alloc_view(d, dim, depth)); 220 return(NULL); 221 } 222 223 void 224 grf_remove_view(v) 225 view_t *v; 226 { 227 v->remove_view(v); 228 } 229 230 void 231 grf_free_view(v) 232 view_t *v; 233 { 234 v->free_view(v); 235 } 236 237 dmode_t * 238 grf_get_display_mode(v) 239 view_t *v; 240 { 241 return(v->get_display_mode(v)); 242 } 243 244 int 245 grf_get_colormap(v, cm) 246 view_t *v; 247 colormap_t *cm; 248 { 249 return(v->get_colormap(v, cm)); 250 } 251 252 int 253 grf_use_colormap(v, cm) 254 view_t *v; 255 colormap_t *cm; 256 { 257 return(v->use_colormap(v, cm)); 258 } 259