1 #ifndef GFXFUNCSUPPORT_H
2 #define GFXFUNCSUPPORT_H
4 /****************************************************************************************/
7 Copyright © 1995-2013, 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 /* !!!! ONLY USE THE BELOW MACROS IF YOU ARE 100% SURE
28 THAT IT IS A HIDD BITMAP AND NOT ONE THE USER
29 HAS CREATED BY HAND !!!. You can use IS_HIDD_BM(bitmap) to test
30 if it is a HIDD bitmap
33 #define OBTAIN_HIDD_BM(bitmap) \
34 ( ( IS_HIDD_BM(bitmap)) \
35 ? HIDD_BM_OBJ(bitmap) \
36 : get_planarbm_object((bitmap), GfxBase) )
38 #define RELEASE_HIDD_BM(bm_obj, bitmap) \
41 if(! IS_HIDD_BM(bitmap)) \
42 release_cache_object(CDD(GfxBase)->planarbm_cache, (bm_obj), GfxBase); \
46 #define GET_BM_DEPTH(bitmap) \
47 (IS_HIDD_BM(bitmap) ? HIDD_BM_REALDEPTH(bitmap) : bitmap->Depth)
49 #define GET_BM_DRIVERDATA(bitmap) \
50 ((IS_HIDD_BM(bitmap)) \
51 ? HIDD_BM_DRVDATA(bitmap) \
52 : (struct monitor_driverdata *)CDD(GfxBase))
54 #define GET_BM_MODEID(bitmap) \
55 (HIDD_BM_DRVDATA(bitmap)->id | HIDD_BM_HIDDMODE(bitmap))
57 /* An idea for future Amiga(tm) chipset driver: it should be implemented in
58 architecture-specific part of graphics.hidd. In this case many things will
59 start working automatically */
60 #define GET_VP_DRIVERDATA(vp) \
61 ((vp->ColorMap && vp->ColorMap->NormalDisplayInfo) \
62 ? DIH(vp->ColorMap->NormalDisplayInfo)->drv \
63 : GET_BM_DRIVERDATA(vp->RasInfo->BitMap))
66 #define BM_PIXEL(bitmap, pen) ((!IS_HIDD_BM(bitmap) || !HIDD_BM_PIXTAB(bitmap)) ? (pen) : \
67 HIDD_BM_PIXTAB(bitmap)[pen])
69 #define BM_PIXEL(bitmap, pen) ((!IS_HIDD_BM(bitmap) || !HIDD_BM_COLMAP(bitmap)) ? (pen) : \
70 HIDD_CM_GetPixel(HIDD_BM_COLMAP(bitmap), pen))
75 #define HIDD_BMF_SHARED_PIXTAB 1
76 #define HIDD_BMF_SCREEN_BITMAP 512
78 /* Minterms and GC drawmodes are in opposite order */
79 #define MINTERM_TO_GCDRMD(minterm) \
80 (( ((minterm & 0x80) >> 3) \
81 | ((minterm & 0x40) >> 1) \
82 | ((minterm & 0x20) << 1) \
83 | ((minterm & 0x10) << 3) ) >> 4 )
85 #define TranslateRect(rect, dx, dy) \
88 struct Rectangle *_rect = rect; \
91 (_rect)->MinX += (_dx); \
92 (_rect)->MinY += (_dy); \
93 (_rect)->MaxX += (_dx); \
94 (_rect)->MaxY += (_dy); \
97 /****************************************************************************************/
99 /* Private Rastport flags */
100 #define RPF_NO_PENS (1L << 14) /* Are pens disabled? */
101 #define RPF_REMAP_COLORFONTS (1L << 13) /* Shall color fonts be automatically remapped? */
103 #define AROS_PALETTE_SIZE 256
104 #define AROS_PALETTE_MEMSIZE (sizeof (HIDDT_Pixel) * AROS_PALETTE_SIZE)
107 * private AROS fields in RastPort struct:
108 * longreserved[0] - pointer to GC class (see oop's _OOP_OBJECT() macro)
109 * longreserved[1] - Embedded hidd.graphics.gc object starts here
112 #define RP_GC(rp) ((APTR)&((rp)->longreserved[1]))
113 #define RP_FGCOLOR(rp) GC_FG(RP_GC(rp))
114 #define RP_BGCOLOR(rp) GC_BG(RP_GC(rp))
116 /****************************************************************************************/
118 #define LOCK_BLIT ObtainSemaphore(&(PrivGBase(GfxBase)->blit_sema));
119 #define ULOCK_BLIT ReleaseSemaphore(&(PrivGBase(GfxBase)->blit_sema));
121 #define FLG_PALETTE ( 1L << vHidd_ColorModel_Palette )
122 #define FLG_STATICPALETTE ( 1L << vHidd_ColorModel_StaticPalette )
123 #define FLG_TRUECOLOR ( 1L << vHidd_ColorModel_TrueColor )
124 #define FLG_HASCOLMAP ( 1L << num_Hidd_CM )
126 #define GET_COLMOD_FLAGS(bm) (1L << HIDD_BM_COLMOD(bm))
128 /****************************************************************************************/
130 struct render_special_info
132 struct BitMap
*curbm
;
135 #define RSI(x) ((struct render_special_info *)x)
137 /* A Pointer to this struct is stored in each RastPort->longreserved[0] */
139 struct gfx_driverdata
141 struct RastPort
* dd_RastPort
; /* This RastPort */
142 struct Rectangle dd_ClipRectangle
;
143 UBYTE dd_ClipRectangleFlags
;
146 static inline struct gfx_driverdata
*ObtainDriverData(struct RastPort
*rp
)
148 struct gfx_driverdata
*dd
= rp
->RP_Extra
;
150 if (dd
&& dd
->dd_RastPort
!= rp
)
152 /* We have detected a cloned rastport. Detach extra data from it. */
159 typedef ULONG (*RENDERFUNC
)(APTR
, WORD
, WORD
, OOP_Object
*, OOP_Object
*, struct Rectangle
*, struct GfxBase
*);
160 typedef LONG (*PIXELFUNC
)(APTR
, OOP_Object
*, OOP_Object
*, WORD
, WORD
, struct GfxBase
*);
162 /****************************************************************************************/
164 OOP_Object
*get_planarbm_object(struct BitMap
*bitmap
, struct GfxBase
*GfxBase
);
166 ULONG
do_render_func(struct RastPort
*rp
, Point
*src
, struct Rectangle
*rr
,
167 RENDERFUNC render_func
, APTR funcdata
,
168 BOOL do_update
, BOOL get_special_info
, struct GfxBase
*GfxBase
);
170 ULONG
do_render_with_gc(struct RastPort
*rp
, Point
*src
, struct Rectangle
*rr
,
171 RENDERFUNC render_func
, APTR funcdata
, OOP_Object
*gc
,
172 BOOL do_update
, BOOL get_special_info
, struct GfxBase
*GfxBase
);
174 ULONG
do_pixel_func(struct RastPort
*rp
, WORD x
, WORD y
,
175 LONG (*render_func
)(APTR
, OOP_Object
*, OOP_Object
*, WORD
, WORD
, struct GfxBase
*),
176 APTR funcdata
, BOOL do_update
, struct GfxBase
*GfxBase
);
178 ULONG
fillrect_render(APTR funcdata
, WORD srcx
, WORD srcy
,
179 OOP_Object
*dstbm_obj
, OOP_Object
*dst_gc
,
180 struct Rectangle
*rect
, struct GfxBase
*GfxBase
);
182 LONG
fillrect_pendrmd(struct RastPort
*tp
, WORD x1
, WORD y1
, WORD x2
, WORD y2
,
183 HIDDT_Pixel pix
, HIDDT_DrawMode drmd
, BOOL do_update
, struct GfxBase
*GfxBase
);
185 BOOL
int_bltbitmap(struct BitMap
*srcBitMap
, OOP_Object
*srcbm_obj
, WORD xSrc
, WORD ySrc
,
186 struct BitMap
*dstBitMap
, OOP_Object
*dstbm_obj
, WORD xDest
, WORD yDest
,
187 WORD xSize
, WORD ySize
, ULONG minterm
, OOP_Object
*gfxhidd
, OOP_Object
*gc
,
188 struct GfxBase
*GfxBase
);
191 LONG
write_pixels_8(struct RastPort
*rp
, UBYTE
*array
, ULONG modulo
,
192 WORD xstart
, WORD ystart
, WORD xstop
, WORD ystop
,
193 HIDDT_PixelLUT
*pixlut
, BOOL do_update
, struct GfxBase
*GfxBase
);
195 LONG
write_transp_pixels_8(struct RastPort
*rp
, UBYTE
*array
, ULONG modulo
,
196 WORD xstart
, WORD ystart
, WORD xstop
, WORD ystop
,
197 HIDDT_PixelLUT
*pixlut
, UBYTE transparent
,
198 BOOL do_update
, struct GfxBase
*GfxBase
);
200 void amiga2hidd_fast(APTR src_info
, OOP_Object
*hidd_gc
, WORD x_src
, WORD y_src
,
201 struct BitMap
*hidd_bm
, WORD x_dest
, WORD y_dest
,
202 ULONG xsize
, ULONG ysize
, VOID (*fillbuf_hook
)(),
203 struct GfxBase
* GfxBase
);
205 BOOL
MoveRaster (struct RastPort
* rp
, WORD dx
, WORD dy
, WORD x1
, WORD y1
,
206 WORD x2
, WORD y2
, BOOL UpdateDamageList
, struct GfxBase
* GfxBase
);
208 BOOL
GetRPClipRectangleForRect(struct RastPort
*rp
, struct Rectangle
*rect
, struct Rectangle
*r
);
209 BOOL
GetRPClipRectangleForBitMap(struct RastPort
*rp
, struct BitMap
*bm
,
210 struct Rectangle
*r
, struct GfxBase
*GfxBase
);
212 void update_bitmap(struct BitMap
*bitmap
, OOP_Object
*bm
, UWORD x
, UWORD y
, UWORD width
, UWORD height
, struct GfxBase
*GfxBase
);
214 void BltRastPortBitMap(struct RastPort
*srcRastPort
, WORD xSrc
, WORD ySrc
,
215 struct BitMap
*destBitMap
, WORD xDest
, WORD yDest
,
216 WORD xSize
, WORD ySize
, ULONG minterm
,
217 struct GfxBase
*GfxBase
);
219 /****************************************************************************************/
221 static inline BOOL
GetRPClipRectangleForLayer(struct RastPort
*rp
, struct Layer
*lay
, struct Rectangle
*r
, struct GfxBase
*GfxBase
)
223 return GetRPClipRectangleForRect(rp
, &lay
->bounds
, r
);