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