adapt to gfx.hidd api changes.
[AROS.git] / rom / graphics / graphics_intern.h
blobcc88d2b9f7d54d6b605f6e3a3825cd10b8cc94dc
1 #ifndef GRAPHICS_INTERN_H
2 #define GRAPHICS_INTERN_H
3 /*
4 Copyright © 1995-2015, 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;
207 /* baseclass for CreateObject */
208 OOP_Class *basebm;
212 /* Macros */
214 #define PrivGBase(x) ((struct GfxBase_intern *)x)
215 /* FIXME: Remove these #define xxxBase hacks
216 Do not use this in new code !
218 #define HiddBitMapBase (PrivGBase(GfxBase)->HiddBitMapBase)
219 #define HiddColorMapBase (PrivGBase(GfxBase)->HiddColorMapBase)
220 #define HiddGCBase (PrivGBase(GfxBase)->HiddGCBase)
221 #define HiddGfxBase (PrivGBase(GfxBase)->HiddGfxBase)
222 #define HiddPlanarBMBase (PrivGBase(GfxBase)->HiddPlanarBMBase)
224 /* struct Utilitybase is used in the following file so include it
225 before defining Utilitybase
227 #include <proto/utility.h>
228 #define CyberGfxBase (PrivGBase(GfxBase)->CyberGfxBase)
230 /* For historical reasons, graphics.library has an internal
231 * copy of SysBase.
233 #define SysBase (GfxBase->ExecBase)
235 #define WIDTH_TO_BYTES(width) ((( (width) + 15) & ~15) >> 3)
236 #define WIDTH_TO_WORDS(width) ((( (width) + 15) & ~15) >> 4)
238 #define XCOORD_TO_BYTEIDX( x ) (( x ) >> 3)
239 #define XCOORD_TO_WORDIDX( x ) (( x ) >> 4)
241 #define COORD_TO_BYTEIDX(x, y, bytes_per_row) \
242 ( ( (y) * (bytes_per_row)) + XCOORD_TO_BYTEIDX(x))
244 #define CHUNKY8_COORD_TO_BYTEIDX(x, y, bytes_per_row) \
245 ( ( (y) * (bytes_per_row)) + (x) )
247 #define XCOORD_TO_MASK(x) (128L >> ((x) & 0x07))
249 /* For vsprite sorting */
251 #define JOIN_XY_COORDS(x,y) (LONG)( ( ((UWORD)(y)) << 16) + ( ( ((UWORD)(x)) + 0x8000 ) & 0xFFFF ) )
253 #define TFE(tfe) (*(struct TextFontExtension**)&tfe)
255 #define TFE_MATCHWORD 0xDFE7 /* randomly invented */
257 /* Defines for flags in areainfo->FlagPtr */
259 #define AREAINFOFLAG_MOVE 0x00
260 #define AREAINFOFLAG_DRAW 0x01
261 #define AREAINFOFLAG_CLOSEDRAW 0x02
262 #define AREAINFOFLAG_ELLIPSE 0x03
264 /* Forward declaration */
265 struct ViewPort;
267 /* Hash index calculation */
268 extern ULONG CalcHashIndex(IPTR n, UWORD size);
270 struct gfx_driverdata *AllocDriverData(struct RastPort *rp, BOOL alloc, struct GfxBase *GfxBase);
272 /* a function needed by ClipBlit */
273 void internal_ClipBlit(struct RastPort * srcRP,
274 WORD xSrc,
275 WORD ySrc,
276 struct RastPort * destRP,
277 WORD xDest,
278 WORD yDest,
279 WORD xSize,
280 WORD ySize,
281 UBYTE minterm,
282 struct GfxBase * GfxBase);
284 /* Driver prototypes */
286 typedef ULONG (*VIEW_FUNC)(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
288 extern ULONG driver_PrepareViewPorts(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
289 extern ULONG driver_LoadViewPorts(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
290 extern struct monitor_driverdata *driver_Setup(OOP_Object *gfxhidd, struct GfxBase *GfxBase);
291 extern void driver_Expunge(struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
292 extern struct HIDD_ViewPortData *driver_FindViewPorts(struct View *view, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
293 extern ULONG DoViewFunction(struct View *view, VIEW_FUNC fn, struct GfxBase *GfxBase);
294 extern void InstallFB(struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
295 extern void UninstallFB(struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
297 /* functions in support.c */
298 extern BOOL pattern_pen(struct RastPort *rp
299 , WORD x, WORD y
300 , ULONG apen, ULONG bpen
301 , ULONG *pixval_ptr
302 , struct GfxBase *GfxBase);
304 /* function for area opeartions */
305 BOOL areafillpolygon(struct RastPort * rp,
306 struct Rectangle * bounds,
307 UWORD first_idx,
308 UWORD last_idx,
309 ULONG bytesperrow,
310 struct GfxBase * GfxBase);
312 void areafillellipse(struct RastPort * rp,
313 struct Rectangle * bounds,
314 UWORD * CurVctr,
315 ULONG BytesPerRow,
316 struct GfxBase * GfxBase);
318 void areaclosepolygon(struct AreaInfo *areainfo);
320 /* functions in color_support */
321 ULONG color_distance(struct ColorMap * cm,
322 ULONG r,
323 ULONG g,
324 ULONG b,
325 ULONG index);
327 BOOL color_equal(struct ColorMap * cm,
328 ULONG r,
329 ULONG g,
330 ULONG b,
331 ULONG index);
333 VOID color_get(struct ColorMap *cm,
334 ULONG *r,
335 ULONG *g,
336 ULONG *b,
337 ULONG index);
339 void _DisposeRegionRectangleList
341 struct RegionRectangle *RR,
342 struct GfxBase *GfxBase
345 struct RegionRectangle *_NewRegionRectangle
347 struct RegionRectangle **LastRectPtr,
348 struct GfxBase *GfxBase
351 BOOL _LinkRegionRectangleList
353 struct RegionRectangle *src,
354 struct RegionRectangle **dstptr,
355 struct GfxBase *GfxBase
358 #if REGIONS_USE_POOL
359 # define GFX_ALLOC(Size) \
360 ({ \
361 APTR Mem; \
363 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
365 Mem = AllocPooled \
367 PrivGBase(GfxBase)->regionpool, \
368 Size \
369 ); \
371 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
373 Mem; \
376 # define GFX_FREE(Mem, Size) \
378 APTR Mem; \
380 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
382 FreePooled \
384 PrivGBase(GfxBase)->regionpool, \
385 Mem, \
386 size \
387 ); \
389 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
391 #else
392 # define GFX_ALLOC(Size) AllocMem(Size, MEMF_ANY)
393 # define GFX_FREE(Mem, Size) FreeMem(Mem, Size)
394 #endif
396 #define _NewRegionRectangleExtChunk() \
397 __NewRegionRectangleExtChunk(GfxBase)
399 #define _DisposeRegionRectangleExtChunk(_chunk) \
400 __DisposeRegionRectangleExtChunk(_chunk, GfxBase)
402 #define SIZECHUNKBUF 20
404 struct ChunkExt
406 struct RegionRectangleExtChunk Chunk;
407 struct ChunkPool *Owner;
410 struct ChunkPool
412 struct MinNode Node;
413 struct ChunkExt Chunks[SIZECHUNKBUF];
414 struct MinList ChunkList;
415 LONG NumChunkFree;
418 void __DisposeRegionRectangleExtChunk
420 struct RegionRectangleExtChunk *Chunk,
421 struct GfxBase *GfxBase
424 struct BlitWaitQNode
426 struct MinNode node;
427 struct Task *task;
430 #endif /* GRAPHICS_INTERN_H */