Added basic implementation of destroying a GPT table: just delete the
[AROS.git] / rom / graphics / graphics_intern.h
blob8f64504e63f50674090d5f09fe43e0f892c892bc
1 #ifndef GRAPHICS_INTERN_H
2 #define GRAPHICS_INTERN_H
3 /*
4 Copyright © 1995-2011, 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 "fontsupport.h"
28 #include "objcache.h"
30 #define BITMAP_CLIPPING 1
31 #define REGIONS_USE_MEMPOOL 1
32 /* Setting BMDEPTH_COMPATIBILITY to 1 will cause bitmap->Depth
33 to be never bigger than 8. The same seems to be the case under
34 AmigaOS with CyberGraphX/Picasso96. GetBitMapAttr() OTOH will
35 actually return the real depth. */
36 #define BMDEPTH_COMPATIBILITY 1
37 #define SIZERECTBUF 128
39 struct RegionRectangleExt
41 struct RegionRectangle RR;
42 IPTR Counter;
45 struct RegionRectangleExtChunk
47 struct RegionRectangleExt Rects[SIZERECTBUF];
48 struct RegionRectangleExtChunk *FirstChunk;
51 #define RRE(x) ((struct RegionRectangleExt *)(x))
52 #define Counter(x) (RRE(x)->Counter)
53 #define Chunk(x) ((x) ? ((struct RegionRectangleExtChunk *)&RRE(x)[-Counter(x)]) : NULL)
54 #define Head(x) ((x) ? (&((struct RegionRectangleExtChunk *)&RRE(x)[-Counter(x)])->FirstChunk->Rects[0].RR) : NULL)
56 /* PaletteExtra internals */
58 typedef WORD PalExtra_RefCnt_Type;
59 typedef WORD PalExtra_AllocList_Type;
61 #define PALEXTRA_REFCNT(pe,n) (((PalExtra_RefCnt_Type *)(pe)->pe_RefCnt)[(n)])
62 #define PALEXTRA_ALLOCLIST(pe,n) (((PalExtra_AllocList_Type *)(pe)->pe_AllocList)[(n)])
64 /*
65 * Display mode database item. A pointer to this structure is used as a DisplayInfoHandle.
66 * In future, if needed, this structure can be extended to hold static bunches of associated
67 * DisplayInfoData.
70 struct monitor_driverdata;
72 struct DisplayInfoHandle
74 HIDDT_ModeID id; /* HIDD Mode ID (without card ID) */
75 struct monitor_driverdata *drv; /* Points back to display driver descriptor */
78 #define DIH(x) ((struct DisplayInfoHandle *)x)
80 /* Monitor driver data. Describes a single physical display. */
81 struct monitor_driverdata
83 struct monitor_driverdata *next; /* Next driver data in chain */
84 ULONG id; /* Card ID (part of display mode ID) */
85 ULONG mask; /* Mask of mode ID */
86 OOP_Object *gfxhidd; /* Graphics driver to use (can be fakegfx object) */
87 UWORD flags; /* Flags, see below */
89 APTR userdata; /* Associated data from notification callback */
90 struct HIDD_ViewPortData *display; /* What is currently displayed */
92 /* FakeGfx-related */
93 OOP_Object *gfxhidd_orig; /* Real graphics driver object */
95 /* Composer-related */
96 OOP_Object *composer; /* composition HIDD object */
98 /* Framebuffer stuff */
99 struct BitMap *frontbm; /* Currently shown bitmap */
100 OOP_Object *framebuffer; /* Framebuffer bitmap object */
101 OOP_Object *bm_bak; /* Original shown bitmap object */
102 OOP_Object *colmap_bak; /* Original colormap object of shown bitmap */
103 HIDDT_ColorModel colmod_bak; /* Original colormodel of shown bitmap */
105 /* Display mode database. */
106 struct DisplayInfoHandle modes[1]; /* Display modes array */
109 /* Driver flags */
110 #define DF_BootMode 0x0001 /* Boot mode driver */
111 #define DF_UseFakeGfx 0x0002 /* Software mouse sprite is in use */
112 #define DF_SoftCompose 0x0004 /* Software screen composition requested */
113 #define DF_DirectFB 0x0008 /* Driver uses a direct-mode framebuffer */
115 /* Common driver data data to all monitors */
116 struct common_driverdata
118 /* The order of these fields match struct monitor_driverdata */
119 struct monitor_driverdata *monitors; /* First monitor driver */
120 ULONG invalid_id; /* INVALID_ID, for GET_BM_MODEID() */
121 ULONG last_id; /* Last card ID */
122 OOP_Object *memorygfx; /* Memory graphics driver */
123 UWORD flags; /* Always zero */
125 /* End of driverdata */
126 APTR notify_data; /* User data for notification callback */
127 APTR (*DriverNotify)(APTR obj, BOOL add, APTR userdata); /* Display driver notification callback */
128 struct SignalSemaphore displaydb_sem; /* Display mode database semaphore */
130 ObjectCache *gc_cache; /* GC cache */
131 ObjectCache *planarbm_cache; /* Planar bitmaps cache */
133 /* HIDD classes */
134 OOP_Class *fakegfxclass; /* Fakegfx (SW sprite) classes */
135 OOP_Class *fakefbclass;
136 OOP_Class *composerClass; /* Composer class */
137 OOP_Class *gcClass; /* GC class */
139 /* Attribute bases */
140 OOP_AttrBase hiddBitMapAttrBase;
141 OOP_AttrBase hiddGCAttrBase;
142 OOP_AttrBase hiddSyncAttrBase;
143 OOP_AttrBase hiddPixFmtAttrBase;
144 OOP_AttrBase hiddPlanarBMAttrBase;
145 OOP_AttrBase hiddGfxAttrBase;
146 OOP_AttrBase hiddFakeGfxHiddAttrBase;
147 OOP_AttrBase hiddFakeFBAttrBase;
148 OOP_AttrBase hiddCompositingAttrBase;
151 #define CDD(base) ((struct common_driverdata *)&PrivGBase(base)->shared_driverdata)
153 #define __IHidd_BitMap CDD(GfxBase)->hiddBitMapAttrBase
154 #define __IHidd_GC CDD(GfxBase)->hiddGCAttrBase
155 #define __IHidd_Sync CDD(GfxBase)->hiddSyncAttrBase
156 #define __IHidd_PixFmt CDD(GfxBase)->hiddPixFmtAttrBase
157 #define __IHidd_PlanarBM CDD(GfxBase)->hiddPlanarBMAttrBase
158 #define __IHidd_Gfx CDD(GfxBase)->hiddGfxAttrBase
159 #define __IHidd_FakeGfxHidd CDD(GfxBase)->hiddFakeGfxHiddAttrBase
160 #define __IHidd_FakeFB CDD(GfxBase)->hiddFakeFBAttrBase
161 #define HiddCompositingAttrBase CDD(GfxBase)->hiddCompositingAttrBase
163 /* Hashtable sizes. Must be powers of two */
164 #define GFXASSOCIATE_HASHSIZE 8
165 #define TFE_HASHTABSIZE 16
166 #define DRIVERDATALIST_HASHSIZE 256
168 /* Internal GFXBase struct */
169 struct GfxBase_intern
171 struct GfxBase gfxbase;
173 ULONG displays; /* Number of display drivers installed in the system */
174 struct common_driverdata shared_driverdata; /* Driver data shared between all monitors (allocated once) */
175 struct SignalSemaphore monitors_sema; /* Monitor list semaphore */
176 struct SignalSemaphore hashtab_sema; /* hash_table arbitration semaphore */
177 struct SignalSemaphore view_sema; /* ActiView arbitration semaphore */
179 /* TextFontExtension pool */
180 struct tfe_hashnode * tfe_hashtab[TFE_HASHTABSIZE];
181 struct SignalSemaphore tfe_hashtab_sema;
182 struct SignalSemaphore fontsem;
184 #if REGIONS_USE_MEMPOOL
185 /* Regions pool */
186 struct SignalSemaphore regionsem;
187 APTR regionpool;
188 struct MinList ChunkPoolList;
189 #endif
191 /* Semaphores */
192 struct SignalSemaphore blit_sema;
194 /* Private library bases */
195 struct Library *CyberGfxBase;
196 struct Library *OOPBase;
197 struct Library *UtilityBase;
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 HiddCompositingMethodBase;
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)
226 #define OOPBase (PrivGBase(GfxBase)->OOPBase)
227 #define UtilityBase (PrivGBase(GfxBase)->UtilityBase)
228 #define SysBase (GfxBase->ExecBase)
230 #define WIDTH_TO_BYTES(width) ((( (width) + 15) & ~15) >> 3)
231 #define WIDTH_TO_WORDS(width) ((( (width) + 15) & ~15) >> 4)
233 #define XCOORD_TO_BYTEIDX( x ) (( x ) >> 3)
234 #define XCOORD_TO_WORDIDX( x ) (( x ) >> 4)
236 #define COORD_TO_BYTEIDX(x, y, bytes_per_row) \
237 ( ( (y) * (bytes_per_row)) + XCOORD_TO_BYTEIDX(x))
239 #define CHUNKY8_COORD_TO_BYTEIDX(x, y, bytes_per_row) \
240 ( ( (y) * (bytes_per_row)) + (x) )
242 #define XCOORD_TO_MASK(x) (128L >> ((x) & 0x07))
244 /* For vsprite sorting */
246 #define JOIN_XY_COORDS(x,y) (LONG)( ( ((UWORD)(y)) << 16) + ( ( ((UWORD)(x)) + 0x8000 ) & 0xFFFF ) )
248 #define TFE(tfe) (*(struct TextFontExtension**)&tfe)
250 #define TFE_MATCHWORD 0xDFE7 /* randomly invented */
252 /* Defines for flags in areainfo->FlagPtr */
254 #define AREAINFOFLAG_MOVE 0x00
255 #define AREAINFOFLAG_DRAW 0x01
256 #define AREAINFOFLAG_CLOSEDRAW 0x02
257 #define AREAINFOFLAG_ELLIPSE 0x03
259 /* Forward declaration */
260 struct ViewPort;
262 /* Hash index calculation */
263 extern ULONG CalcHashIndex(IPTR n, UWORD size);
265 struct gfx_driverdata *AllocDriverData(struct RastPort *rp, BOOL alloc, struct GfxBase *GfxBase);
267 /* a function needed by ClipBlit */
268 void internal_ClipBlit(struct RastPort * srcRP,
269 WORD xSrc,
270 WORD ySrc,
271 struct RastPort * destRP,
272 WORD xDest,
273 WORD yDest,
274 WORD xSize,
275 WORD ySize,
276 UBYTE minterm,
277 struct GfxBase * GfxBase);
279 /* Driver prototypes */
281 typedef ULONG (*VIEW_FUNC)(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
283 extern ULONG driver_PrepareViewPorts(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
284 extern ULONG driver_LoadViewPorts(struct HIDD_ViewPortData *vpd, struct View *v, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
285 extern struct monitor_driverdata *driver_Setup(OOP_Object *gfxhidd, struct GfxBase *GfxBase);
286 extern void driver_Expunge(struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
287 extern struct HIDD_ViewPortData *driver_FindViewPorts(struct View *view, struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
288 extern ULONG DoViewFunction(struct View *view, VIEW_FUNC fn, struct GfxBase *GfxBase);
289 extern void InstallFB(struct monitor_driverdata *mdd, struct GfxBase *GfxBase);
290 extern void UninstallFB(struct monitor_driverdata *mdd);
292 /* functions in support.c */
293 extern BOOL pattern_pen(struct RastPort *rp
294 , WORD x, WORD y
295 , ULONG apen, ULONG bpen
296 , ULONG *pixval_ptr
297 , struct GfxBase *GfxBase);
299 /* function for area opeartions */
300 BOOL areafillpolygon(struct RastPort * rp,
301 struct Rectangle * bounds,
302 UWORD first_idx,
303 UWORD last_idx,
304 ULONG bytesperrow,
305 struct GfxBase * GfxBase);
307 void areafillellipse(struct RastPort * rp,
308 struct Rectangle * bounds,
309 UWORD * CurVctr,
310 ULONG BytesPerRow,
311 struct GfxBase * GfxBase);
313 void areaclosepolygon(struct AreaInfo *areainfo);
315 /* functions in color_support */
316 ULONG color_distance(struct ColorMap * cm,
317 ULONG r,
318 ULONG g,
319 ULONG b,
320 ULONG index);
322 BOOL color_equal(struct ColorMap * cm,
323 ULONG r,
324 ULONG g,
325 ULONG b,
326 ULONG index);
328 VOID color_get(struct ColorMap *cm,
329 ULONG *r,
330 ULONG *g,
331 ULONG *b,
332 ULONG index);
334 void _DisposeRegionRectangleList
336 struct RegionRectangle *RR,
337 struct GfxBase *GfxBase
340 struct RegionRectangle *_NewRegionRectangle
342 struct RegionRectangle **LastRectPtr,
343 struct GfxBase *GfxBase
346 BOOL _LinkRegionRectangleList
348 struct RegionRectangle *src,
349 struct RegionRectangle **dstptr,
350 struct GfxBase *GfxBase
353 #if REGIONS_USE_POOL
354 # define GFX_ALLOC(Size) \
355 ({ \
356 APTR Mem; \
358 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
360 Mem = AllocPooled \
362 PrivGBase(GfxBase)->regionpool, \
363 Size \
364 ); \
366 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
368 Mem; \
371 # define GFX_FREE(Mem, Size) \
373 APTR Mem; \
375 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
377 FreePooled \
379 PrivGBase(GfxBase)->regionpool, \
380 Mem, \
381 size \
382 ); \
384 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
386 #else
387 # define GFX_ALLOC(Size) AllocMem(Size, MEMF_ANY)
388 # define GFX_FREE(Mem, Size) FreeMem(Mem, Size)
389 #endif
391 #define _NewRegionRectangleExtChunk() \
392 __NewRegionRectangleExtChunk(GfxBase)
394 #define _DisposeRegionRectangleExtChunk(_chunk) \
395 __DisposeRegionRectangleExtChunk(_chunk, GfxBase)
397 #define SIZECHUNKBUF 20
399 struct ChunkExt
401 struct RegionRectangleExtChunk Chunk;
402 struct ChunkPool *Owner;
405 struct ChunkPool
407 struct MinNode Node;
408 struct ChunkExt Chunks[SIZECHUNKBUF];
409 struct MinList ChunkList;
410 LONG NumChunkFree;
413 void __DisposeRegionRectangleExtChunk
415 struct RegionRectangleExtChunk *Chunk,
416 struct GfxBase *GfxBase
419 struct BlitWaitQNode
421 struct MinNode node;
422 struct Task *task;
425 #endif /* GRAPHICS_INTERN_H */