compiler: Support autoopening of libraries in AROS_SHxx() style programs
[AROS.git] / rom / graphics / graphics_intern.h
blob61a3c411dd556820f1f6cd28be64473c82940768
1 #ifndef GRAPHICS_INTERN_H
2 #define GRAPHICS_INTERN_H
3 /*
4 Copyright © 1995-2013, The AROS Development Team. All rights reserved.
5 $Id$
7 Desc: Internal header file for graphics.library
8 Lang: english
9 */
11 #include <aros/libcall.h>
12 #include <exec/execbase.h>
13 #include <exec/lists.h>
14 #include <exec/nodes.h>
15 #include <exec/semaphores.h>
16 #include <graphics/gfxbase.h>
17 #include <graphics/text.h>
18 #include <graphics/rastport.h>
19 #include <graphics/regions.h>
20 #include <oop/oop.h>
21 #include <graphics/view.h>
22 #include <hidd/graphics.h>
23 #include <exec/memory.h>
24 #include <proto/exec.h>
25 #include <graphics/scale.h>
27 #include LC_LIBDEFS_FILE
29 #include "fontsupport.h"
30 #include "objcache.h"
32 #define BITMAP_CLIPPING 1
33 #define REGIONS_USE_MEMPOOL 1
34 /* Setting BMDEPTH_COMPATIBILITY to 1 will cause bitmap->Depth
35 to be never bigger than 8. The same seems to be the case under
36 AmigaOS with CyberGraphX/Picasso96. GetBitMapAttr() OTOH will
37 actually return the real depth. */
38 #define BMDEPTH_COMPATIBILITY 1
39 #define SIZERECTBUF 128
41 struct RegionRectangleExt
43 struct RegionRectangle RR;
44 IPTR Counter;
47 struct RegionRectangleExtChunk
49 struct RegionRectangleExt Rects[SIZERECTBUF];
50 struct RegionRectangleExtChunk *FirstChunk;
53 #define RRE(x) ((struct RegionRectangleExt *)(x))
54 #define Counter(x) (RRE(x)->Counter)
55 #define Chunk(x) ((x) ? ((struct RegionRectangleExtChunk *)&RRE(x)[-Counter(x)]) : NULL)
56 #define Head(x) ((x) ? (&((struct RegionRectangleExtChunk *)&RRE(x)[-Counter(x)])->FirstChunk->Rects[0].RR) : NULL)
58 /* PaletteExtra internals */
60 typedef WORD PalExtra_RefCnt_Type;
61 typedef WORD PalExtra_AllocList_Type;
63 #define PALEXTRA_REFCNT(pe,n) (((PalExtra_RefCnt_Type *)(pe)->pe_RefCnt)[(n)])
64 #define PALEXTRA_ALLOCLIST(pe,n) (((PalExtra_AllocList_Type *)(pe)->pe_AllocList)[(n)])
66 /*
67 * Display mode database item. A pointer to this structure is used as a DisplayInfoHandle.
68 * In future, if needed, this structure can be extended to hold static bunches of associated
69 * DisplayInfoData.
72 struct monitor_driverdata;
74 struct DisplayInfoHandle
76 HIDDT_ModeID id; /* HIDD Mode ID (without card ID) */
77 struct monitor_driverdata *drv; /* Points back to display driver descriptor */
80 #define DIH(x) ((struct DisplayInfoHandle *)x)
82 /* Monitor driver data. Describes a single physical display. */
83 struct monitor_driverdata
85 struct monitor_driverdata *next; /* Next driver data in chain */
86 ULONG id; /* Card ID (part of display mode ID) */
87 ULONG mask; /* Mask of mode ID */
88 OOP_Object *gfxhidd; /* Graphics driver to use (can be fakegfx object) */
89 UWORD flags; /* Flags, see below */
91 APTR userdata; /* Associated data from notification callback */
92 struct HIDD_ViewPortData *display; /* What is currently displayed */
94 /* FakeGfx-related */
95 OOP_Object *gfxhidd_orig; /* Real graphics driver object */
97 /* Compositor-related */
98 OOP_Object *compositor; /* screen composition HIDD object */
100 /* Framebuffer stuff */
101 struct BitMap *frontbm; /* Currently shown bitmap */
102 OOP_Object *framebuffer; /* Framebuffer bitmap object */
103 OOP_Object *bm_bak; /* Original shown bitmap object */
104 OOP_Object *colmap_bak; /* Original colormap object of shown bitmap */
105 HIDDT_ColorModel colmod_bak; /* Original colormodel of shown bitmap */
107 /* Display mode database. */
108 struct DisplayInfoHandle modes[1]; /* Display modes array */
111 /* Driver flags */
112 #define DF_BootMode 0x0001 /* Boot mode driver */
113 #define DF_UseFakeGfx 0x0002 /* Software mouse sprite is in use */
114 #define DF_SoftCompose 0x0004 /* Software screen composition requested */
115 #define DF_DirectFB 0x0008 /* Driver uses a direct-mode framebuffer */
117 /* Common driver data data to all monitors */
118 struct common_driverdata
120 /* The order of these fields match struct monitor_driverdata */
121 struct monitor_driverdata *monitors; /* First monitor driver */
122 ULONG invalid_id; /* INVALID_ID, for GET_BM_MODEID() */
123 ULONG last_id; /* Last card ID */
124 OOP_Object *memorygfx; /* Memory graphics driver */
125 UWORD flags; /* Always zero */
127 /* End of driverdata */
128 APTR notify_data; /* User data for notification callback */
129 APTR (*DriverNotify)(APTR obj, BOOL add, APTR userdata); /* Display driver notification callback */
130 struct SignalSemaphore displaydb_sem; /* Display mode database semaphore */
132 ObjectCache *gc_cache; /* GC cache */
133 ObjectCache *planarbm_cache; /* Planar bitmaps cache */
135 /* HIDD classes */
136 OOP_Class *fakegfxclass; /* Fakegfx (SW sprite) classes */
137 OOP_Class *fakefbclass;
138 OOP_Class *compositorClass; /* Compositor class */
139 OOP_Class *gcClass; /* GC class */
141 /* Attribute bases */
142 OOP_AttrBase hiddBitMapAttrBase;
143 OOP_AttrBase hiddGCAttrBase;
144 OOP_AttrBase hiddSyncAttrBase;
145 OOP_AttrBase hiddPixFmtAttrBase;
146 OOP_AttrBase hiddPlanarBMAttrBase;
147 OOP_AttrBase hiddGfxAttrBase;
148 OOP_AttrBase hiddFakeGfxHiddAttrBase;
149 OOP_AttrBase hiddFakeFBAttrBase;
150 OOP_AttrBase hiddCompositorAttrBase;
153 #define CDD(base) ((struct common_driverdata *)&PrivGBase(base)->shared_driverdata)
155 #define __IHidd_BitMap CDD(GfxBase)->hiddBitMapAttrBase
156 #define __IHidd_GC CDD(GfxBase)->hiddGCAttrBase
157 #define __IHidd_Sync CDD(GfxBase)->hiddSyncAttrBase
158 #define __IHidd_PixFmt CDD(GfxBase)->hiddPixFmtAttrBase
159 #define __IHidd_PlanarBM CDD(GfxBase)->hiddPlanarBMAttrBase
160 #define __IHidd_Gfx CDD(GfxBase)->hiddGfxAttrBase
161 #define __IHidd_FakeGfxHidd CDD(GfxBase)->hiddFakeGfxHiddAttrBase
162 #define __IHidd_FakeFB CDD(GfxBase)->hiddFakeFBAttrBase
163 #define HiddCompositorAttrBase CDD(GfxBase)->hiddCompositorAttrBase
165 /* Hashtable sizes. Must be powers of two */
166 #define GFXASSOCIATE_HASHSIZE 8
167 #define TFE_HASHTABSIZE 16
168 #define DRIVERDATALIST_HASHSIZE 256
170 /* Internal GFXBase struct */
171 struct GfxBase_intern
173 struct GfxBase gfxbase;
175 ULONG displays; /* Number of display drivers installed in the system */
176 struct common_driverdata shared_driverdata; /* Driver data shared between all monitors (allocated once) */
177 struct SignalSemaphore monitors_sema; /* Monitor list semaphore */
178 struct SignalSemaphore hashtab_sema; /* hash_table arbitration semaphore */
179 struct SignalSemaphore view_sema; /* ActiView arbitration semaphore */
181 /* TextFontExtension pool */
182 struct tfe_hashnode * tfe_hashtab[TFE_HASHTABSIZE];
183 struct SignalSemaphore tfe_hashtab_sema;
184 struct SignalSemaphore fontsem;
186 #if REGIONS_USE_MEMPOOL
187 /* Regions pool */
188 struct SignalSemaphore regionsem;
189 APTR regionpool;
190 struct MinList ChunkPoolList;
191 #endif
193 /* Semaphores */
194 struct SignalSemaphore blit_sema;
196 /* Private library bases */
197 struct Library *CyberGfxBase;
199 /* Private HIDD method bases */
200 OOP_MethodID HiddBitMapBase;
201 OOP_MethodID HiddColorMapBase;
202 OOP_MethodID HiddGCBase;
203 OOP_MethodID HiddGfxBase;
204 OOP_MethodID HiddPlanarBMBase;
205 OOP_MethodID HiddCompositorMethodBase;
209 /* Macros */
211 #define PrivGBase(x) ((struct GfxBase_intern *)x)
212 /* FIXME: Remove these #define xxxBase hacks
213 Do not use this in new code !
215 #define HiddBitMapBase (PrivGBase(GfxBase)->HiddBitMapBase)
216 #define HiddColorMapBase (PrivGBase(GfxBase)->HiddColorMapBase)
217 #define HiddGCBase (PrivGBase(GfxBase)->HiddGCBase)
218 #define HiddGfxBase (PrivGBase(GfxBase)->HiddGfxBase)
219 #define HiddPlanarBMBase (PrivGBase(GfxBase)->HiddPlanarBMBase)
221 /* struct Utilitybase is used in the following file so include it
222 before defining Utilitybase
224 #include <proto/utility.h>
225 #define CyberGfxBase (PrivGBase(GfxBase)->CyberGfxBase)
227 /* For historical reasons, graphics.library has an internal
228 * copy of SysBase.
230 #define SysBase (GfxBase->ExecBase)
232 #define WIDTH_TO_BYTES(width) ((( (width) + 15) & ~15) >> 3)
233 #define WIDTH_TO_WORDS(width) ((( (width) + 15) & ~15) >> 4)
235 #define XCOORD_TO_BYTEIDX( x ) (( x ) >> 3)
236 #define XCOORD_TO_WORDIDX( x ) (( x ) >> 4)
238 #define COORD_TO_BYTEIDX(x, y, bytes_per_row) \
239 ( ( (y) * (bytes_per_row)) + XCOORD_TO_BYTEIDX(x))
241 #define CHUNKY8_COORD_TO_BYTEIDX(x, y, bytes_per_row) \
242 ( ( (y) * (bytes_per_row)) + (x) )
244 #define XCOORD_TO_MASK(x) (128L >> ((x) & 0x07))
246 /* For vsprite sorting */
248 #define JOIN_XY_COORDS(x,y) (LONG)( ( ((UWORD)(y)) << 16) + ( ( ((UWORD)(x)) + 0x8000 ) & 0xFFFF ) )
250 #define TFE(tfe) (*(struct TextFontExtension**)&tfe)
252 #define TFE_MATCHWORD 0xDFE7 /* randomly invented */
254 /* Defines for flags in areainfo->FlagPtr */
256 #define AREAINFOFLAG_MOVE 0x00
257 #define AREAINFOFLAG_DRAW 0x01
258 #define AREAINFOFLAG_CLOSEDRAW 0x02
259 #define AREAINFOFLAG_ELLIPSE 0x03
261 /* Forward declaration */
262 struct ViewPort;
264 /* Hash index calculation */
265 extern ULONG CalcHashIndex(IPTR n, UWORD size);
267 struct gfx_driverdata *AllocDriverData(struct RastPort *rp, BOOL alloc, struct GfxBase *GfxBase);
269 /* a function needed by ClipBlit */
270 void internal_ClipBlit(struct RastPort * srcRP,
271 WORD xSrc,
272 WORD ySrc,
273 struct RastPort * destRP,
274 WORD xDest,
275 WORD yDest,
276 WORD xSize,
277 WORD ySize,
278 UBYTE minterm,
279 struct GfxBase * GfxBase);
281 /* Driver prototypes */
283 typedef ULONG (*VIEW_FUNC)(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
285 extern ULONG driver_PrepareViewPorts(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
286 extern ULONG driver_LoadViewPorts(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
287 extern struct monitor_driverdata *driver_Setup(OOP_Object *gfxhidd, struct GfxBase *GfxBase);
288 extern void driver_Expunge(struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
289 extern struct HIDD_ViewPortData *driver_FindViewPorts(struct View *view, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
290 extern ULONG DoViewFunction(struct View *view, VIEW_FUNC fn, struct GfxBase *GfxBase);
291 extern void InstallFB(struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
292 extern void UninstallFB(struct monitor_driverdata *mdd);
294 /* functions in support.c */
295 extern BOOL pattern_pen(struct RastPort *rp
296 , WORD x, WORD y
297 , ULONG apen, ULONG bpen
298 , ULONG *pixval_ptr
299 , struct GfxBase *GfxBase);
301 /* function for area opeartions */
302 BOOL areafillpolygon(struct RastPort * rp,
303 struct Rectangle * bounds,
304 UWORD first_idx,
305 UWORD last_idx,
306 ULONG bytesperrow,
307 struct GfxBase * GfxBase);
309 void areafillellipse(struct RastPort * rp,
310 struct Rectangle * bounds,
311 UWORD * CurVctr,
312 ULONG BytesPerRow,
313 struct GfxBase * GfxBase);
315 void areaclosepolygon(struct AreaInfo *areainfo);
317 /* functions in color_support */
318 ULONG color_distance(struct ColorMap * cm,
319 ULONG r,
320 ULONG g,
321 ULONG b,
322 ULONG index);
324 BOOL color_equal(struct ColorMap * cm,
325 ULONG r,
326 ULONG g,
327 ULONG b,
328 ULONG index);
330 VOID color_get(struct ColorMap *cm,
331 ULONG *r,
332 ULONG *g,
333 ULONG *b,
334 ULONG index);
336 void _DisposeRegionRectangleList
338 struct RegionRectangle *RR,
339 struct GfxBase *GfxBase
342 struct RegionRectangle *_NewRegionRectangle
344 struct RegionRectangle **LastRectPtr,
345 struct GfxBase *GfxBase
348 BOOL _LinkRegionRectangleList
350 struct RegionRectangle *src,
351 struct RegionRectangle **dstptr,
352 struct GfxBase *GfxBase
355 #if REGIONS_USE_POOL
356 # define GFX_ALLOC(Size) \
357 ({ \
358 APTR Mem; \
360 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
362 Mem = AllocPooled \
364 PrivGBase(GfxBase)->regionpool, \
365 Size \
366 ); \
368 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
370 Mem; \
373 # define GFX_FREE(Mem, Size) \
375 APTR Mem; \
377 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
379 FreePooled \
381 PrivGBase(GfxBase)->regionpool, \
382 Mem, \
383 size \
384 ); \
386 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
388 #else
389 # define GFX_ALLOC(Size) AllocMem(Size, MEMF_ANY)
390 # define GFX_FREE(Mem, Size) FreeMem(Mem, Size)
391 #endif
393 #define _NewRegionRectangleExtChunk() \
394 __NewRegionRectangleExtChunk(GfxBase)
396 #define _DisposeRegionRectangleExtChunk(_chunk) \
397 __DisposeRegionRectangleExtChunk(_chunk, GfxBase)
399 #define SIZECHUNKBUF 20
401 struct ChunkExt
403 struct RegionRectangleExtChunk Chunk;
404 struct ChunkPool *Owner;
407 struct ChunkPool
409 struct MinNode Node;
410 struct ChunkExt Chunks[SIZECHUNKBUF];
411 struct MinList ChunkList;
412 LONG NumChunkFree;
415 void __DisposeRegionRectangleExtChunk
417 struct RegionRectangleExtChunk *Chunk,
418 struct GfxBase *GfxBase
421 struct BlitWaitQNode
423 struct MinNode node;
424 struct Task *task;
427 #endif /* GRAPHICS_INTERN_H */