revert - libatomic is still needed for target code.
[AROS.git] / rom / graphics / graphics_intern.h
blob77252919e397bb02d8adcaa2cac984e304ac69e3
1 #ifndef GRAPHICS_INTERN_H
2 #define GRAPHICS_INTERN_H
3 /*
4 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
5 $Id$
7 Desc: Internal header file for graphics.library
8 Lang: english
9 */
11 #ifndef __OOP_NOMETHODBASES__
12 #define __OOP_NOMETHODBASES__
13 #endif
15 #ifndef __OOP_NOATTRBASES__
16 #define __OOP_NOATTRBASES__
17 #endif
19 #include <aros/libcall.h>
20 #include <exec/execbase.h>
21 #include <exec/lists.h>
22 #include <exec/nodes.h>
23 #include <exec/semaphores.h>
24 #include <graphics/gfxbase.h>
25 #include <graphics/text.h>
26 #include <graphics/rastport.h>
27 #include <graphics/regions.h>
28 #include <oop/oop.h>
29 #include <graphics/view.h>
30 #include <hidd/gfx.h>
31 #include <exec/memory.h>
32 #include <proto/exec.h>
33 #include <graphics/scale.h>
35 #include LC_LIBDEFS_FILE
37 #include "fontsupport.h"
38 #include "objcache.h"
40 #define BITMAP_CLIPPING 1
41 #define REGIONS_USE_MEMPOOL 1
42 /* Setting BMDEPTH_COMPATIBILITY to 1 will cause bitmap->Depth
43 to be never bigger than 8. The same seems to be the case under
44 AmigaOS with CyberGraphX/Picasso96. GetBitMapAttr() OTOH will
45 actually return the real depth. */
46 #define BMDEPTH_COMPATIBILITY 1
47 #define SIZERECTBUF 128
49 struct RegionRectangleExt
51 struct RegionRectangle RR;
52 IPTR Counter;
55 struct RegionRectangleExtChunk
57 struct RegionRectangleExt Rects[SIZERECTBUF];
58 struct RegionRectangleExtChunk *FirstChunk;
61 #define RRE(x) ((struct RegionRectangleExt *)(x))
62 #define Counter(x) (RRE(x)->Counter)
63 #define Chunk(x) ((x) ? ((struct RegionRectangleExtChunk *)&RRE(x)[-Counter(x)]) : NULL)
64 #define Head(x) ((x) ? (&((struct RegionRectangleExtChunk *)&RRE(x)[-Counter(x)])->FirstChunk->Rects[0].RR) : NULL)
66 /* PaletteExtra internals */
68 typedef WORD PalExtra_RefCnt_Type;
69 typedef WORD PalExtra_AllocList_Type;
71 #define PALEXTRA_REFCNT(pe,n) (((PalExtra_RefCnt_Type *)(pe)->pe_RefCnt)[(n)])
72 #define PALEXTRA_ALLOCLIST(pe,n) (((PalExtra_AllocList_Type *)(pe)->pe_AllocList)[(n)])
74 /*
75 * Display mode database item. A pointer to this structure is used as a DisplayInfoHandle.
76 * In future, if needed, this structure can be extended to hold static bunches of associated
77 * DisplayInfoData.
80 struct monitor_driverdata;
82 struct DisplayInfoHandle
84 HIDDT_ModeID id; /* HIDD Mode ID (without card ID) */
85 struct monitor_driverdata *drv; /* Points back to display driver descriptor */
88 #define DIH(x) ((struct DisplayInfoHandle *)x)
90 /* Monitor driver data. Describes a single physical display. */
91 struct monitor_driverdata
93 struct monitor_driverdata *next; /* Next driver data in chain */
94 ULONG id; /* Card ID (part of display mode ID) */
95 ULONG mask; /* Mask of mode ID */
96 OOP_Object *gfxhidd; /* Graphics driver to use (can be fakegfx object) */
97 UWORD flags; /* Flags, see below */
99 APTR userdata; /* Associated data from notification callback */
100 struct HIDD_ViewPortData *display; /* What is currently displayed */
102 /* FakeGfx-related */
103 OOP_Object *gfxhidd_orig; /* Real graphics driver object */
105 /* Compositor-related */
106 OOP_Object *compositor; /* screen composition HIDD object */
108 /* Framebuffer stuff */
109 struct BitMap *frontbm; /* Currently shown bitmap */
110 OOP_Object *framebuffer; /* Framebuffer bitmap object */
111 OOP_Object *bm_bak; /* Original shown bitmap object */
112 OOP_Object *colmap_bak; /* Original colormap object of shown bitmap */
113 HIDDT_ColorModel colmod_bak; /* Original colormodel of shown bitmap */
115 /* Display mode database. */
116 struct DisplayInfoHandle modes[1]; /* Display modes array */
119 /* Driver flags */
120 #define DF_BootMode 0x0001 /* Boot mode driver */
121 #define DF_UseFakeGfx 0x0002 /* Software mouse sprite is in use */
122 #define DF_SoftCompose 0x0004 /* Software screen composition requested */
123 #define DF_DirectFB 0x0008 /* Driver uses a direct-mode framebuffer */
125 /* Common driver data data to all monitors */
126 struct common_driverdata
128 /* The order of these fields match struct monitor_driverdata */
129 struct monitor_driverdata *monitors; /* First monitor driver */
130 ULONG invalid_id; /* INVALID_ID, for GET_BM_MODEID() */
131 ULONG last_id; /* Last card ID */
132 OOP_Object *memorygfx; /* Memory graphics driver */
133 UWORD flags; /* Always zero */
135 /* End of driverdata */
136 APTR notify_data; /* User data for notification callback */
137 APTR (*DriverNotify)(APTR obj, BOOL add, APTR userdata); /* Display driver notification callback */
138 struct SignalSemaphore displaydb_sem; /* Display mode database semaphore */
140 ObjectCache *gc_cache; /* GC cache */
141 ObjectCache *planarbm_cache; /* Planar bitmaps cache */
143 /* HIDD classes */
144 OOP_Class *fakegfxclass; /* Fakegfx (SW sprite) classes */
145 OOP_Class *fakefbclass;
146 OOP_Class *compositorClass; /* Compositor class */
147 OOP_Class *gcClass; /* GC class */
149 /* Attribute bases */
150 OOP_AttrBase hiddBitMapAttrBase;
151 OOP_AttrBase hiddGCAttrBase;
152 OOP_AttrBase hiddSyncAttrBase;
153 OOP_AttrBase hiddPixFmtAttrBase;
154 OOP_AttrBase hiddPlanarBMAttrBase;
155 OOP_AttrBase hiddGfxAttrBase;
156 OOP_AttrBase hiddFakeGfxHiddAttrBase;
157 OOP_AttrBase hiddFakeFBAttrBase;
158 OOP_AttrBase hiddCompositorAttrBase;
161 #define CDD(base) ((struct common_driverdata *)&PrivGBase(base)->shared_driverdata)
163 #define __IHidd_BitMap CDD(GfxBase)->hiddBitMapAttrBase
164 #define __IHidd_GC CDD(GfxBase)->hiddGCAttrBase
165 #define __IHidd_Sync CDD(GfxBase)->hiddSyncAttrBase
166 #define __IHidd_PixFmt CDD(GfxBase)->hiddPixFmtAttrBase
167 #define __IHidd_PlanarBM CDD(GfxBase)->hiddPlanarBMAttrBase
168 #define __IHidd_Gfx CDD(GfxBase)->hiddGfxAttrBase
169 #define __IHidd_FakeGfxHidd CDD(GfxBase)->hiddFakeGfxHiddAttrBase
170 #define __IHidd_FakeFB CDD(GfxBase)->hiddFakeFBAttrBase
171 #define HiddCompositorAttrBase CDD(GfxBase)->hiddCompositorAttrBase
173 /* Hashtable sizes. Must be powers of two */
174 #define GFXASSOCIATE_HASHSIZE 8
175 #define TFE_HASHTABSIZE 16
176 #define DRIVERDATALIST_HASHSIZE 256
178 /* Internal GFXBase struct */
179 struct GfxBase_intern
181 struct GfxBase gfxbase;
183 ULONG displays; /* Number of display drivers installed in the system */
184 struct common_driverdata shared_driverdata; /* Driver data shared between all monitors (allocated once) */
185 struct SignalSemaphore monitors_sema; /* Monitor list semaphore */
186 struct SignalSemaphore hashtab_sema; /* hash_table arbitration semaphore */
187 struct SignalSemaphore view_sema; /* ActiView arbitration semaphore */
189 /* TextFontExtension pool */
190 struct tfe_hashnode * tfe_hashtab[TFE_HASHTABSIZE];
191 struct SignalSemaphore tfe_hashtab_sema;
192 struct SignalSemaphore fontsem;
194 #if REGIONS_USE_MEMPOOL
195 /* Regions pool */
196 struct SignalSemaphore regionsem;
197 APTR regionpool;
198 struct MinList ChunkPoolList;
199 #endif
201 /* Semaphores */
202 struct SignalSemaphore blit_sema;
204 /* Private library bases */
205 struct Library *CyberGfxBase;
207 /* HW Driver root */
208 OOP_Object *GfxRoot;
210 /* Private HIDD method bases */
211 OOP_MethodID HWBase;
212 OOP_MethodID HiddBitMapBase;
213 OOP_MethodID HiddColorMapBase;
214 OOP_MethodID HiddGCBase;
215 OOP_MethodID HiddGfxBase;
216 OOP_MethodID HiddPlanarBMBase;
217 OOP_MethodID HiddCompositorMethodBase;
219 /* baseclass for CreateObject */
220 OOP_Class *basebm;
224 /* Macros */
226 #define PrivGBase(x) ((struct GfxBase_intern *)x)
227 /* FIXME: Remove these #define xxxBase hacks
228 Do not use this in new code !
230 #define HWBase (PrivGBase(GfxBase)->HWBase)
231 #define HiddBitMapBase (PrivGBase(GfxBase)->HiddBitMapBase)
232 #define HiddColorMapBase (PrivGBase(GfxBase)->HiddColorMapBase)
233 #define HiddGCBase (PrivGBase(GfxBase)->HiddGCBase)
234 #define HiddGfxBase (PrivGBase(GfxBase)->HiddGfxBase)
235 #define HiddPlanarBMBase (PrivGBase(GfxBase)->HiddPlanarBMBase)
237 /* struct Utilitybase is used in the following file so include it
238 before defining Utilitybase
240 #include <proto/utility.h>
241 #define CyberGfxBase (PrivGBase(GfxBase)->CyberGfxBase)
243 /* For historical reasons, graphics.library has an internal
244 * copy of SysBase.
246 #define SysBase (GfxBase->ExecBase)
248 #define WIDTH_TO_BYTES(width) ((( (width) + 15) & ~15) >> 3)
249 #define WIDTH_TO_WORDS(width) ((( (width) + 15) & ~15) >> 4)
251 #define XCOORD_TO_BYTEIDX( x ) (( x ) >> 3)
252 #define XCOORD_TO_WORDIDX( x ) (( x ) >> 4)
254 #define COORD_TO_BYTEIDX(x, y, bytes_per_row) \
255 ( ( (y) * (bytes_per_row)) + XCOORD_TO_BYTEIDX(x))
257 #define CHUNKY8_COORD_TO_BYTEIDX(x, y, bytes_per_row) \
258 ( ( (y) * (bytes_per_row)) + (x) )
260 #define XCOORD_TO_MASK(x) (128L >> ((x) & 0x07))
262 /* For vsprite sorting */
264 #define JOIN_XY_COORDS(x,y) (LONG)( ( ((UWORD)(y)) << 16) + ( ( ((UWORD)(x)) + 0x8000 ) & 0xFFFF ) )
266 #define TFE(tfe) (*(struct TextFontExtension**)&tfe)
268 #define TFE_MATCHWORD 0xDFE7 /* randomly invented */
270 /* Defines for flags in areainfo->FlagPtr */
272 #define AREAINFOFLAG_MOVE 0x00
273 #define AREAINFOFLAG_DRAW 0x01
274 #define AREAINFOFLAG_CLOSEDRAW 0x02
275 #define AREAINFOFLAG_ELLIPSE 0x03
277 /* Forward declaration */
278 struct ViewPort;
280 /* Hash index calculation */
281 extern ULONG CalcHashIndex(IPTR n, UWORD size);
283 struct gfx_driverdata *AllocDriverData(struct RastPort *rp, BOOL alloc, struct GfxBase *GfxBase);
285 /* a function needed by ClipBlit */
286 void internal_ClipBlit(struct RastPort * srcRP,
287 WORD xSrc,
288 WORD ySrc,
289 struct RastPort * destRP,
290 WORD xDest,
291 WORD yDest,
292 WORD xSize,
293 WORD ySize,
294 UBYTE minterm,
295 struct GfxBase * GfxBase);
297 /* Driver prototypes */
299 typedef ULONG (*VIEW_FUNC)(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
301 extern ULONG driver_PrepareViewPorts(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
302 extern ULONG driver_LoadViewPorts(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
303 extern struct monitor_driverdata *driver_Setup(OOP_Object *gfxhidd, struct GfxBase *GfxBase);
304 extern void driver_Expunge(struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
305 extern struct HIDD_ViewPortData *driver_FindViewPorts(struct View *view, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
306 extern ULONG DoViewFunction(struct View *view, VIEW_FUNC fn, struct GfxBase *GfxBase);
307 extern void InstallFB(struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
308 extern void UninstallFB(struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
310 /* functions in support.c */
311 extern BOOL pattern_pen(struct RastPort *rp
312 , WORD x, WORD y
313 , ULONG apen, ULONG bpen
314 , ULONG *pixval_ptr
315 , struct GfxBase *GfxBase);
317 /* function for area opeartions */
318 BOOL areafillpolygon(struct RastPort * rp,
319 struct Rectangle * bounds,
320 UWORD first_idx,
321 UWORD last_idx,
322 ULONG bytesperrow,
323 struct GfxBase * GfxBase);
325 void areafillellipse(struct RastPort * rp,
326 struct Rectangle * bounds,
327 UWORD * CurVctr,
328 ULONG BytesPerRow,
329 struct GfxBase * GfxBase);
331 void areaclosepolygon(struct AreaInfo *areainfo);
333 /* functions in color_support */
334 ULONG color_distance(struct ColorMap * cm,
335 ULONG r,
336 ULONG g,
337 ULONG b,
338 ULONG index);
340 BOOL color_equal(struct ColorMap * cm,
341 ULONG r,
342 ULONG g,
343 ULONG b,
344 ULONG index);
346 VOID color_get(struct ColorMap *cm,
347 ULONG *r,
348 ULONG *g,
349 ULONG *b,
350 ULONG index);
352 void _DisposeRegionRectangleList
354 struct RegionRectangle *RR,
355 struct GfxBase *GfxBase
358 struct RegionRectangle *_NewRegionRectangle
360 struct RegionRectangle **LastRectPtr,
361 struct GfxBase *GfxBase
364 BOOL _LinkRegionRectangleList
366 struct RegionRectangle *src,
367 struct RegionRectangle **dstptr,
368 struct GfxBase *GfxBase
371 #if REGIONS_USE_POOL
372 # define GFX_ALLOC(Size) \
373 ({ \
374 APTR Mem; \
376 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
378 Mem = AllocPooled \
380 PrivGBase(GfxBase)->regionpool, \
381 Size \
382 ); \
384 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
386 Mem; \
389 # define GFX_FREE(Mem, Size) \
391 APTR Mem; \
393 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
395 FreePooled \
397 PrivGBase(GfxBase)->regionpool, \
398 Mem, \
399 size \
400 ); \
402 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
404 #else
405 # define GFX_ALLOC(Size) AllocMem(Size, MEMF_ANY)
406 # define GFX_FREE(Mem, Size) FreeMem(Mem, Size)
407 #endif
409 #define _NewRegionRectangleExtChunk() \
410 __NewRegionRectangleExtChunk(GfxBase)
412 #define _DisposeRegionRectangleExtChunk(_chunk) \
413 __DisposeRegionRectangleExtChunk(_chunk, GfxBase)
415 #define SIZECHUNKBUF 20
417 struct ChunkExt
419 struct RegionRectangleExtChunk Chunk;
420 struct ChunkPool *Owner;
423 struct ChunkPool
425 struct MinNode Node;
426 struct ChunkExt Chunks[SIZECHUNKBUF];
427 struct MinList ChunkList;
428 LONG NumChunkFree;
431 void __DisposeRegionRectangleExtChunk
433 struct RegionRectangleExtChunk *Chunk,
434 struct GfxBase *GfxBase
437 struct BlitWaitQNode
439 struct MinNode node;
440 struct Task *task;
443 #endif /* GRAPHICS_INTERN_H */