Reverted r44762 (removal of USB3.0 and HC driver separation work).
[AROS.git] / rom / graphics / graphics_intern.h
blobbcb79f20e4f46c488d5432185acf11f5351ee9f3
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 /* This must be included before defining OOPBase */
222 #include <hidd/graphics_inline.h>
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)
229 #define OOPBase (PrivGBase(GfxBase)->OOPBase)
230 #define UtilityBase (PrivGBase(GfxBase)->UtilityBase)
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 ( ( ((LONG)(y)) * (bytes_per_row)) + XCOORD_TO_BYTEIDX(x))
241 #define CHUNKY8_COORD_TO_BYTEIDX(x, y, bytes_per_row) \
242 ( ( ((LONG)(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 LONG xSrc,
272 LONG ySrc,
273 struct RastPort * destRP,
274 LONG xDest,
275 LONG yDest,
276 LONG xSize,
277 LONG 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 , LONG x, LONG 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 */