Home | History | Annotate | Line # | Download | only in dev
grfabs_reg.h 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_reg.h,v 1.1 1994/02/13 21:10:36 chopps Exp $
     31  */
     32 
     33 #if ! defined (_GRFABS_REG_H)
     34 #define _GRFABS_REG_H
     35 
     36 typedef struct point {
     37     long x;
     38     long y;
     39 } point_t;
     40 
     41 typedef struct dimension {
     42     u_long width;
     43     u_long height;
     44 } dimen_t;
     45 
     46 typedef struct box {
     47     long x;
     48     long y;
     49     u_long width;
     50     u_long height;
     51 } box_t;
     52 
     53 typedef struct rectangle {
     54     long left;
     55     long top;
     56     long right;
     57     long bottom;
     58 } rect_t;
     59 
     60 typedef struct bitmap bmap_t;
     61 typedef struct colormap colormap_t;
     62 typedef struct view view_t;
     63 typedef struct display_mode dmode_t;
     64 typedef struct monitor monitor_t;
     65 
     66 /*
     67  * Bitmap stuff.
     68  */
     69 
     70 /* Note structure is 5 long words big.  This may come in handy for
     71  * contiguous allocations
     72  *
     73  * Please do fill in everything correctly this is the main input for
     74  * all other programs.  In other words all problems with RTG start here.
     75  * If you do not mimic everyone else exactly problems will appear.
     76  * If you need a template look at alloc_bitmap() in grf_cc.c.
     77  *
     78  * WARNING: the plane array is only for convience, all data for bitplanes
     79  *          MUST be contiguous.  This is for mapping purposes.  The reason
     80  *          for the plane pointers and row_mod is to support interleaving
     81  *          on monitors that wish to support this.
     82  *
     83  * 2nd Warning: Also don't get funky with these pointers you are expected
     84  *              to place the start of mappable plane data in ``hardware_address'',
     85  *              ``hardware_address'' is the only thing that /dev/view checks and it expects
     86  *              the planes to follow with no padding in between.  If you have
     87  *              special alignment requirements make use of the given fields
     88  *              so that the entire contiguous plane data is exactly:
     89  *              bytes_per_row*height*depth long starting at the physical address
     90  *              contained within hardware_address.
     91  *
     92  * Final Warning: Plane data must begin on a PAGE address and the allocation must
     93  *                be ``n'' PAGES big do to mapping requirements (otherwise the
     94  *                user could write over non-allocated memory.
     95  *
     96  */
     97 struct bitmap {
     98     u_short   bytes_per_row;			  /* number of bytes per display row. */
     99     u_short   row_mod;				  /* number of bytes to reach next row. */
    100     u_short   rows;				  /* number of display rows. */
    101     u_short   depth;				  /* depth of bitmap. */
    102     u_short   flags;				  /* flags. */
    103     u_short   pad;
    104     u_char  *blit_temp;				  /* private monitor buffer. */
    105     u_char **plane;				  /* plane data for bitmap. */
    106     u_char  *hardware_address;			  /* mappable bitplane pointer. */
    107 };
    108 
    109 enum bitmap_flag_bits {
    110     BMB_CLEAR,					  /* init only. */
    111     BMB_INTERLEAVED,				  /* init/read. */
    112 };
    113 
    114 enum bitmap_flags {
    115     BMF_CLEAR = 1 << BMB_CLEAR,			  /* init only. */
    116     BMF_INTERLEAVED = 1 << BMB_INTERLEAVED,	  /* init/read. */
    117 };
    118 
    119 /* Use these macros to find misc. sizes of actual bitmap */
    120 #define BM_WIDTH(b)        (b->bytes_per_row << 3)
    121 #define BM_HEIGHT(b)	   (b->rows)
    122 #define BM_ROW(b,p,l)	   (b->plane[p] + ((b->bytes_per_row+b->row_mod)*l))
    123 
    124 /*
    125  * Colormap stuff.
    126  */
    127 
    128 /* valid masks are a bitfield of zeros followed by ones that indicate
    129  * which mask are valid for each component.  The ones and zeros will
    130  * be contiguous so adding one to this value yields the number of
    131  * levels for that component.
    132  * -ch
    133  */
    134 
    135 struct colormap {
    136     u_char type;	/* what type of entries these are. */
    137     union {
    138         /* CM_GREYSCALE */
    139         u_char grey;
    140 #define grey_mask  valid_mask.grey
    141         /* CM_COLOR */
    142         struct {
    143             u_char red;
    144 #define red_mask   valid_mask.rgb_mask.red
    145             u_char green;
    146 #define green_mask valid_mask.rgb_mask.green
    147             u_char blue;
    148 #define blue_mask  valid_mask.rgb_mask.blue
    149         } rgb_mask;
    150     } valid_mask;
    151     u_short first;	/* what color register does entry[0] refer to. */
    152     u_short size;	/* number of entries */
    153     u_long *entry;/* the table of actual color values. */
    154 };
    155 
    156 enum colormap_type {
    157     CM_MONO,			/* only on or off allowed */
    158     CM_GREYSCALE,		/* grey vals. */
    159     CM_COLOR			/* RGB vals. */
    160 };
    161 
    162 #define CM_FIXVAL(x) (0xff&x)
    163 
    164 /* these macros are for creating entries */
    165 #define MAKE_COLOR_ENTRY(r,g,b) (CM_FIXVAL(r) << 16 | CM_FIXVAL(g) << 8 | CM_FIXVAL(b))
    166 #define MAKE_MONO_ENTRY(x)	(x ? 1 : 0)
    167 #define MAKE_GREY_ENTRY(l)      CM_FIXVAL(l)
    168 
    169 #define CM_LTOW(v) (((0x000F0000&v)>>8)|((0x00000F00&v)>>4)|(0xF&v))
    170 #define CM_WTOL(v) (((0xF00&v)<<8)|((0x0F0&v)<<4)|(0xF&v))
    171 
    172 /*
    173  * View stuff.
    174  */
    175 typedef void remove_view_func (view_t *v);
    176 typedef void free_view_func (view_t *v);
    177 typedef void display_view_func (view_t *v);
    178 typedef dmode_t *get_mode_func (view_t *v);
    179 typedef int get_colormap_func (view_t *v, colormap_t *);
    180 typedef int use_colormap_func (view_t *v, colormap_t *);
    181 
    182 struct view {
    183     bmap_t  *bitmap;				  /* bitmap. */
    184     box_t    display;				  /* viewable area. */
    185     void    *data;				  /* view specific data. */
    186 
    187     /* functions */
    188     display_view_func *display_view;		  /* make this view active */
    189     remove_view_func  *remove_view;		  /* remove this view if active */
    190     free_view_func    *free_view;		  /* free this view */
    191     get_mode_func     *get_display_mode;	  /* get the mode this view belongs to */
    192     get_colormap_func *get_colormap;		  /* get a color map for registers */
    193     use_colormap_func *use_colormap;		  /* use color map to load registers */
    194 };
    195 
    196 #define VDISPLAY_LINE(v, p, l) ((v)->bitmap->plane[p] +\
    197 	(((v)->bitmap->bytes_per_row+(v)->bitmap->row_mod)*l))
    198 
    199 /*
    200  * Mode stuff
    201  */
    202 
    203 typedef view_t *alloc_view_func (dmode_t *mode, dimen_t *dim, u_char depth);
    204 typedef view_t *get_current_view_func (dmode_t *);
    205 typedef monitor_t  *get_monitor_func (dmode_t *);
    206 
    207 struct display_mode {
    208     dll_node_t node;				  /* a link into a monitor's mode list. */
    209     u_char    *name;				  /* logical name for mode. */
    210     dimen_t    nominal_size;			  /* best fit. */
    211     void      *data;				  /* mode specific flags. */
    212 
    213     /* mode functions */
    214     alloc_view_func       *alloc_view;		  /* allocate a view for this mode. */
    215     get_current_view_func *get_current_view;	  /* get active view. */
    216     get_monitor_func      *get_monitor;		  /* get monitor that mode belongs to */
    217 };
    218 
    219 /*
    220  * Monitor stuff.
    221  */
    222 typedef void     vbl_handler_func (void *);
    223 typedef dmode_t *get_next_mode_func (dmode_t *);
    224 typedef dmode_t *get_current_mode_func (void);
    225 typedef dmode_t *get_best_mode_func (dimen_t *size, u_char depth);
    226 typedef bmap_t *alloc_bitmap_func (u_short w, u_short h, u_short d, u_short f);
    227 typedef void    free_bitmap_func (bmap_t *bm);
    228 
    229 struct monitor {
    230     dll_node_t  node;				  /* a link into the database. */
    231     u_char     *name;				  /* a logical name for this monitor. */
    232     void       *data;				  /* monitor specific data. */
    233 
    234     /* funciton interface to this monitor. */
    235     vbl_handler_func       *vbl_handler;	  /* gets called on every vbl if not NULL */
    236     get_next_mode_func     *get_next_mode;	  /* return next mode in list */
    237     get_current_mode_func  *get_current_mode;	  /* return active mode or NULL */
    238     get_best_mode_func     *get_best_mode;	  /* return mode that best fits */
    239 
    240     alloc_bitmap_func      *alloc_bitmap;	  /* allocate a bitmap for use with this monitor */
    241     free_bitmap_func       *free_bitmap;	  /* free a bitmap */
    242 };
    243 
    244 /*
    245  * Misc draw related macros.
    246  */
    247 
    248 #define BOX_2_RECT(b,r) do { \
    249 			     (r)->left = (b)->x; (r)->top = (b)->y; \
    250 			     (r)->right = (b)->x + (b)->width -1; \
    251 			     (r)->bottom = (b)->y + (b)->height -1; \
    252 		       } while (0)
    253 
    254 #define RECT_2_BOX(r,b) do { \
    255 			     (b)->x = (r)->left; \
    256 			     (b)->y = (r)->top; \
    257 		             (b)->width = (r)->right - (r)->left +1; \
    258 			     (b)->height = (r)->bottom - (r)->top +1; \
    259 		       } while (0)
    260 
    261 #define INIT_BOX(b,xx,yy,ww,hh) do{(b)->x = xx; (b)->y = yy; (b)->width = ww; (b)->height = hh;}while (0)
    262 #define INIT_RECT(rc,l,t,r,b) do{(rc)->left = l; (rc)->right = r; (rc)->top = t; (rc)->bottom = b;}while (0)
    263 #define INIT_POINT(p,xx,yy) do {(p)->x = xx; (p)->y = yy;} while (0)
    264 #define INIT_DIM(d,w,h) do {(d)->width = w; (d)->height = h;} while (0)
    265 
    266 
    267 /*
    268  * Prototypes
    269  */
    270 
    271 #if defined (__STDC__)
    272 /* views */
    273 view_t * grf_alloc_view (dmode_t *d, dimen_t *dim, u_char depth);
    274 void grf_display_view (view_t *v);
    275 void grf_remove_view (view_t *v);
    276 void grf_free_view (view_t *v);
    277 dmode_t *grf_get_display_mode (view_t *v);
    278 int grf_get_colormap (view_t *v, colormap_t *cm);
    279 int grf_use_colormap (view_t *v, colormap_t *cm);
    280 /* modes */
    281 view_t *grf_get_current_view (dmode_t *d);
    282 monitor_t *grf_get_monitor (dmode_t *d);
    283 /* monitors */
    284 dmode_t * grf_get_next_mode (monitor_t *m, dmode_t *d);
    285 dmode_t * grf_get_current_mode (monitor_t *);
    286 dmode_t * grf_get_best_mode (monitor_t *m, dimen_t *size, u_char depth);
    287 bmap_t  * grf_alloc_bitmap (monitor_t *m, u_short w, u_short h, u_short d, u_short f);
    288 void grf_free_bitmap (monitor_t *m, bmap_t *bm);
    289 #endif /* __STDC__ */
    290 
    291 #endif /* _GRFABS_REG_H */
    292