1 #ifndef GFXFUNCSUPPORT_H
2 #define GFXFUNCSUPPORT_H
4 /****************************************************************************************/
7 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
11 /****************************************************************************************/
13 #include <graphics/clip.h>
14 #include <graphics/gfxbase.h>
15 #include <hidd/graphics.h>
18 #define NUM_COLORS (1L << PEN_BITS)
19 #define PEN_MASK (NUM_COLORS - 1)
21 #define FIX_GFXCOORD(x) x = (WORD)x
23 /* Our own usage of some private fields in ViewPortExtra */
24 #define VPE_DATA(vpe) ((struct HIDD_ViewPortData *)(vpe)->DriverData[0])
25 #define VPE_DRIVER(vpe) ((struct monitor_driverdata *)(vpe)->DriverData[1])
27 /* Additional private flags in ViewPortExtra */
28 #define VPXF_RELEASE_BITMAP 0x8000
30 /* !!!! ONLY USE THE BELOW MACROS IF YOU ARE 100% SURE
31 THAT IT IS A HIDD BITMAP AND NOT ONE THE USER
32 HAS CREATED BY HAND !!!. You can use IS_HIDD_BM(bitmap) to test
33 if it is a HIDD bitmap
36 #define HIDD_BM_OBJ(bitmap) (*(OOP_Object **)&((bitmap)->Planes[0]))
37 #define HIDD_BM_DRVDATA(bitmap) (*(struct monitor_driverdata **)&((bitmap)->Planes[1]))
38 #define HIDD_BM_COLMAP(bitmap) (*(OOP_Object **)&((bitmap)->Planes[2]))
39 #define HIDD_BM_COLMOD(bitmap) (*(HIDDT_ColorModel *)&((bitmap)->Planes[3]))
40 #define HIDD_BM_PIXTAB(bitmap) (*(HIDDT_Pixel **)&((bitmap)->Planes[4]))
41 #define HIDD_BM_REALDEPTH(bitmap) (*(LONG *)&((bitmap)->Planes[5]))
42 #define HIDD_BM_FLAGS(bitmap) (*(ULONG *)&((bitmap)->Planes[6]))
43 #define HIDD_BM_HIDDMODE(bitmap) (*(HIDDT_ModeID *)&((bitmap)->Planes[7]))
45 #define OBTAIN_HIDD_BM(bitmap) \
46 ( ( IS_HIDD_BM(bitmap)) \
47 ? HIDD_BM_OBJ(bitmap) \
48 : get_planarbm_object((bitmap), GfxBase) )
50 #define RELEASE_HIDD_BM(bm_obj, bitmap) \
53 if(! IS_HIDD_BM(bitmap)) \
54 release_cache_object(CDD(GfxBase)->planarbm_cache, (bm_obj), GfxBase); \
58 #define GET_BM_DEPTH(bitmap) \
59 (IS_HIDD_BM(bitmap) ? HIDD_BM_REALDEPTH(bitmap) : bitmap->Depth)
61 #define GET_BM_DRIVERDATA(bitmap) \
62 ((IS_HIDD_BM(bitmap)) \
63 ? HIDD_BM_DRVDATA(bitmap) \
64 : (struct monitor_driverdata *)CDD(GfxBase))
66 #define GET_BM_MODEID(bitmap) \
67 (HIDD_BM_DRVDATA(bitmap)->id | HIDD_BM_HIDDMODE(bitmap))
69 /* An idea for future Amiga(tm) chipset driver: it should be implemented in
70 architecture-specific part of graphics.hidd. In this case many things will
71 start working automatically */
72 #define GET_VP_DRIVERDATA(vp) \
73 ((vp->ColorMap && vp->ColorMap->NormalDisplayInfo) \
74 ? DIH(vp->ColorMap->NormalDisplayInfo)->drv \
75 : GET_BM_DRIVERDATA(vp->RasInfo->BitMap))
77 #define IS_HIDD_BM(bitmap) ((bitmap)->Flags & BMF_SPECIALFMT)
80 #define BM_PIXEL(bitmap, pen) ((!IS_HIDD_BM(bitmap) || !HIDD_BM_PIXTAB(bitmap)) ? (pen) : \
81 HIDD_BM_PIXTAB(bitmap)[pen])
83 #define BM_PIXEL(bitmap, pen) ((!IS_HIDD_BM(bitmap) || !HIDD_BM_COLMAP(bitmap)) ? (pen) : \
84 HIDD_CM_GetPixel(HIDD_BM_COLMAP(bitmap), pen))
89 #define HIDD_BMF_SHARED_PIXTAB 1
90 #define HIDD_BMF_SCREEN_BITMAP 512
92 /* Minterms and GC drawmodes are in opposite order */
93 #define MINTERM_TO_GCDRMD(minterm) \
94 (( ((minterm & 0x80) >> 3) \
95 | ((minterm & 0x40) >> 1) \
96 | ((minterm & 0x20) << 1) \
97 | ((minterm & 0x10) << 3) ) >> 4 )
99 #define TranslateRect(rect, dx, dy) \
102 struct Rectangle *_rect = rect; \
105 (_rect)->MinX += (_dx); \
106 (_rect)->MinY += (_dy); \
107 (_rect)->MaxX += (_dx); \
108 (_rect)->MaxY += (_dy); \
111 /****************************************************************************************/
113 /* Private Rastport flags */
114 #define RPF_NO_PENS (1L << 14) /* Are pens disabled? */
115 #define RPF_REMAP_COLORFONTS (1L << 13) /* Shall color fonts be automatically remapped? */
117 #define AROS_PALETTE_SIZE 256
118 #define AROS_PALETTE_MEMSIZE (sizeof (HIDDT_Pixel) * AROS_PALETTE_SIZE)
121 * private AROS fields in RastPort struct:
122 * longreserved[0] - pointer to GC class (see oop's _OOP_OBJECT() macro)
123 * longreserved[1] - Enbedded hidd.graphics.gc object starts here
126 #define RP_GC(rp) ((APTR)&((rp)->longreserved[1]))
127 #define RP_FGCOLOR(rp) GC_FG(RP_GC(rp))
128 #define RP_BGCOLOR(rp) GC_BG(RP_GC(rp))
130 /****************************************************************************************/
132 #define LOCK_BLIT ObtainSemaphore(&(PrivGBase(GfxBase)->blit_sema));
133 #define ULOCK_BLIT ReleaseSemaphore(&(PrivGBase(GfxBase)->blit_sema));
135 #define FLG_PALETTE ( 1L << vHidd_ColorModel_Palette )
136 #define FLG_STATICPALETTE ( 1L << vHidd_ColorModel_StaticPalette )
137 #define FLG_TRUECOLOR ( 1L << vHidd_ColorModel_TrueColor )
138 #define FLG_HASCOLMAP ( 1L << num_Hidd_CM )
140 #define GET_COLMOD_FLAGS(bm) (1L << HIDD_BM_COLMOD(bm))
142 /****************************************************************************************/
144 struct render_special_info
146 struct BitMap
*curbm
;
149 #define RSI(x) ((struct render_special_info *)x)
151 /* A Pointer to this struct is stored in each RastPort->longreserved[0] */
153 struct gfx_driverdata
155 struct RastPort
* dd_RastPort
; /* This RastPort */
156 struct Rectangle dd_ClipRectangle
;
157 UBYTE dd_ClipRectangleFlags
;
160 static inline struct gfx_driverdata
*ObtainDriverData(struct RastPort
*rp
)
162 struct gfx_driverdata
*dd
= rp
->RP_Extra
;
164 if (dd
&& dd
->dd_RastPort
!= rp
)
166 /* We have detected a cloned rastport. Detach extra data from it. */
173 typedef ULONG (*RENDERFUNC
)(APTR
, WORD
, WORD
, OOP_Object
*, OOP_Object
*, struct Rectangle
*, struct GfxBase
*);
174 typedef LONG (*PIXELFUNC
)(APTR
, OOP_Object
*, OOP_Object
*, WORD
, WORD
, struct GfxBase
*);
176 /****************************************************************************************/
178 OOP_Object
*get_planarbm_object(struct BitMap
*bitmap
, struct GfxBase
*GfxBase
);
180 ULONG
do_render_func(struct RastPort
*rp
, Point
*src
, struct Rectangle
*rr
,
181 RENDERFUNC render_func
, APTR funcdata
,
182 BOOL do_update
, BOOL get_special_info
, struct GfxBase
*GfxBase
);
184 ULONG
do_render_with_gc(struct RastPort
*rp
, Point
*src
, struct Rectangle
*rr
,
185 RENDERFUNC render_func
, APTR funcdata
, OOP_Object
*gc
,
186 BOOL do_update
, BOOL get_special_info
, struct GfxBase
*GfxBase
);
188 ULONG
do_pixel_func(struct RastPort
*rp
, WORD x
, WORD y
,
189 LONG (*render_func
)(APTR
, OOP_Object
*, OOP_Object
*, WORD
, WORD
, struct GfxBase
*),
190 APTR funcdata
, BOOL do_update
, struct GfxBase
*GfxBase
);
192 ULONG
fillrect_render(APTR funcdata
, WORD srcx
, WORD srcy
,
193 OOP_Object
*dstbm_obj
, OOP_Object
*dst_gc
,
194 struct Rectangle
*rect
, struct GfxBase
*GfxBase
);
196 LONG
fillrect_pendrmd(struct RastPort
*tp
, WORD x1
, WORD y1
, WORD x2
, WORD y2
,
197 HIDDT_Pixel pix
, HIDDT_DrawMode drmd
, BOOL do_update
, struct GfxBase
*GfxBase
);
199 BOOL
int_bltbitmap(struct BitMap
*srcBitMap
, OOP_Object
*srcbm_obj
, WORD xSrc
, WORD ySrc
,
200 struct BitMap
*dstBitMap
, OOP_Object
*dstbm_obj
, WORD xDest
, WORD yDest
,
201 WORD xSize
, WORD ySize
, ULONG minterm
, OOP_Object
*gfxhidd
, OOP_Object
*gc
,
202 struct GfxBase
*GfxBase
);
205 LONG
write_pixels_8(struct RastPort
*rp
, UBYTE
*array
, ULONG modulo
,
206 WORD xstart
, WORD ystart
, WORD xstop
, WORD ystop
,
207 HIDDT_PixelLUT
*pixlut
, BOOL do_update
, struct GfxBase
*GfxBase
);
209 LONG
write_transp_pixels_8(struct RastPort
*rp
, UBYTE
*array
, ULONG modulo
,
210 WORD xstart
, WORD ystart
, WORD xstop
, WORD ystop
,
211 HIDDT_PixelLUT
*pixlut
, UBYTE transparent
,
212 BOOL do_update
, struct GfxBase
*GfxBase
);
214 void amiga2hidd_fast(APTR src_info
, OOP_Object
*hidd_gc
, WORD x_src
, WORD y_src
,
215 struct BitMap
*hidd_bm
, WORD x_dest
, WORD y_dest
,
216 ULONG xsize
, ULONG ysize
, VOID (*fillbuf_hook
)(),
217 struct GfxBase
* GfxBase
);
219 BOOL
MoveRaster (struct RastPort
* rp
, WORD dx
, WORD dy
, WORD x1
, WORD y1
,
220 WORD x2
, WORD y2
, BOOL UpdateDamageList
, struct GfxBase
* GfxBase
);
222 BOOL
GetRPClipRectangleForRect(struct RastPort
*rp
, struct Rectangle
*rect
, struct Rectangle
*r
);
223 BOOL
GetRPClipRectangleForBitMap(struct RastPort
*rp
, struct BitMap
*bm
,
224 struct Rectangle
*r
, struct GfxBase
*GfxBase
);
226 void update_bitmap(struct BitMap
*bitmap
, OOP_Object
*bm
, UWORD x
, UWORD y
, UWORD width
, UWORD height
, struct GfxBase
*GfxBase
);
228 void BltRastPortBitMap(struct RastPort
*srcRastPort
, WORD xSrc
, WORD ySrc
,
229 struct BitMap
*destBitMap
, WORD xDest
, WORD yDest
,
230 WORD xSize
, WORD ySize
, ULONG minterm
,
231 struct GfxBase
*GfxBase
);
233 /****************************************************************************************/
235 static inline BOOL
GetRPClipRectangleForLayer(struct RastPort
*rp
, struct Layer
*lay
, struct Rectangle
*r
, struct GfxBase
*GfxBase
)
237 return GetRPClipRectangleForRect(rp
, &lay
->bounds
, r
);