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