Home | History | Annotate | Line # | Download | only in dev
grfabs.c revision 1.3
      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.3 1994/05/08 05:53:09 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 dmode_t *
    107 get_best_display_mode(width, height, depth)
    108 	u_long width, height;
    109 	u_char depth;
    110 {
    111 	monitor_t *m;
    112 	dmode_t *d, *save;
    113 	dimen_t dim;
    114 	long dx, dy, ct, dt;
    115 
    116 	save = NULL;
    117 	for (m = monitors->lh_first; m != NULL; m = m->link.le_next) {
    118 		dim.width = width;
    119 		dim.height = height;
    120 		d = m->get_best_mode(&dim, depth);
    121 		if (d) {
    122 			dx = ABS(long, (d->nominal_size.width - width));
    123 			dy = ABS(long, (d->nominal_size.height - height));
    124 			ct = dx + dy;
    125 
    126 			if (ct < dt || save == NULL) {
    127 				save = d;
    128 				dt = ct;
    129 			}
    130 		}
    131 	}
    132 	return(save);
    133 }
    134 
    135 
    136 /*
    137  * Monitor stuff.
    138  */
    139 
    140 dmode_t *
    141 grf_get_next_mode(m, d)
    142 	monitor_t *m;
    143 	dmode_t *d;
    144 {
    145 	return(m->get_next_mode(d));
    146 }
    147 
    148 dmode_t *
    149 grf_get_current_mode(m)
    150 	monitor_t *m;
    151 {
    152 	return(m->get_current_mode());
    153 }
    154 
    155 dmode_t *
    156 grf_get_best_mode(m, size, depth)
    157 	monitor_t *m;
    158 	dimen_t *size;
    159 	u_char depth;
    160 {
    161 	return(m->get_best_mode(size, depth));
    162 }
    163 
    164 bmap_t *
    165 grf_alloc_bitmap(m, w, h, d, f)
    166 	monitor_t *m;
    167 	u_short w, h, d, f;
    168 {
    169 	return(m->alloc_bitmap(w, h, d, f));
    170 }
    171 
    172 void
    173 grf_free_bitmap(m, bm)
    174 	monitor_t *m;
    175 	bmap_t *bm;
    176 {
    177 	m->free_bitmap(bm);
    178 }
    179 
    180 /*
    181  * Mode stuff.
    182  */
    183 
    184 view_t *
    185 grf_get_current_view(d)
    186 	dmode_t *d;
    187 {
    188 	return(d->get_current_view(d));
    189 }
    190 
    191 monitor_t *
    192 grf_get_monitor(d)
    193 	dmode_t *d;
    194 {
    195 	return(d->get_monitor(d));
    196 }
    197 
    198 /*
    199  * View stuff.
    200  */
    201 
    202 void
    203 grf_display_view(v)
    204 	view_t *v;
    205 {
    206 	v->display_view(v);
    207 }
    208 
    209 view_t *
    210 grf_alloc_view(d, dim, depth)
    211 	dmode_t *d;
    212 	dimen_t *dim;
    213 	u_char depth;
    214 {
    215 	if (!d)
    216 		d = get_best_display_mode(dim->width, dim->height, depth);
    217 	if (d)
    218 		return(d->alloc_view(d, dim, depth));
    219 	return(NULL);
    220 }
    221 
    222 void
    223 grf_remove_view(v)
    224 	view_t *v;
    225 {
    226 	v->remove_view(v);
    227 }
    228 
    229 void
    230 grf_free_view(v)
    231 	view_t *v;
    232 {
    233 	v->free_view(v);
    234 }
    235 
    236 dmode_t *
    237 grf_get_display_mode(v)
    238 	view_t *v;
    239 {
    240 	return(v->get_display_mode(v));
    241 }
    242 
    243 int
    244 grf_get_colormap(v, cm)
    245 	view_t *v;
    246 	colormap_t *cm;
    247 {
    248 	return(v->get_colormap(v, cm));
    249 }
    250 
    251 int
    252 grf_use_colormap(v, cm)
    253 	view_t *v;
    254 	colormap_t *cm;
    255 {
    256 	return(v->use_colormap(v, cm));
    257 }
    258