1 #ifndef GRAPHICS_INTERN_H
2 #define GRAPHICS_INTERN_H
4 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
7 Desc: Internal header file for graphics.library
11 #ifndef AROS_LIBCALL_H
12 # include <aros/libcall.h>
14 #ifndef EXEC_EXECBASE_H
15 # include <exec/execbase.h>
18 # include <exec/lists.h>
21 # include <exec/nodes.h>
23 #ifndef EXEC_SEMAPHORE_H
24 # include <exec/semaphores.h>
26 #ifndef GRAPHICS_GFXBASE_H
27 # include <graphics/gfxbase.h>
29 #ifndef GRAPHICS_TEXT_H
30 # include <graphics/text.h>
32 #ifndef GRAPHICS_RASTPORT_H
33 # include <graphics/rastport.h>
35 #ifndef GRAPHICS_REGIONS_H
36 # include <graphics/regions.h>
41 #ifndef GRAPHICS_VIEW_H
42 # include <graphics/view.h>
44 #ifndef HIDD_GRAPHICS_H
45 # include <hidd/graphics.h>
48 #include <exec/memory.h>
49 #include <proto/exec.h>
50 #include <graphics/scale.h>
51 #include "fontsupport.h"
54 #define BITMAP_CLIPPING 1
56 #define REGIONS_USE_MEMPOOL 1
58 /* Setting BMDEPTH_COMPATIBILITY to 1 will cause bitmap->Depth
59 to be never bigger than 8. The same seems to be the case under
60 AmigaOS with CyberGraphX/Picasso96. GetBitMapAttr() OTOH will
61 actually return the real depth. */
63 #define BMDEPTH_COMPATIBILITY 1
65 #define OBTAIN_DRIVERDATA(rp,libbase) ObtainDriverData(rp, libbase)
66 #define RELEASE_DRIVERDATA(rp,libbase) ReleaseDriverData(rp, libbase)
68 #define SIZERECTBUF 128
70 struct RegionRectangleExt
72 struct RegionRectangle RR
;
76 struct RegionRectangleExtChunk
78 struct RegionRectangleExt Rects
[SIZERECTBUF
];
79 struct RegionRectangleExtChunk
*FirstChunk
;
82 #define RRE(x) ((struct RegionRectangleExt *)(x))
83 #define Counter(x) (RRE(x)->Counter)
84 #define Chunk(x) ((x) ? ((struct RegionRectangleExtChunk *)&RRE(x)[-Counter(x)]) : NULL)
86 /* PaletteExtra internals */
88 typedef WORD PalExtra_RefCnt_Type
;
89 typedef WORD PalExtra_AllocList_Type
;
91 #define PALEXTRA_REFCNT(pe,n) (((PalExtra_RefCnt_Type *)(pe)->pe_RefCnt)[(n)])
92 #define PALEXTRA_ALLOCLIST(pe,n) (((PalExtra_AllocList_Type *)(pe)->pe_AllocList)[(n)])
95 * Display mode database item. A pointer to this structure is used as a DisplayInfoHandle.
96 * In future, if needed, this structure can be extended to hold static bunches of associated
100 struct monitor_driverdata
;
102 struct DisplayInfoHandle
104 HIDDT_ModeID id
; /* HIDD Mode ID (without card ID) */
105 struct monitor_driverdata
*drv
; /* Points back to display driver descriptor */
108 #define DIH(x) ((struct DisplayInfoHandle *)x)
110 /* Monitor driver data. Describes a single physical display. */
111 struct monitor_driverdata
113 struct monitor_driverdata
*next
; /* Next driver data in chain */
114 ULONG id
; /* Card ID (part of display mode ID) */
115 ULONG mask
; /* Mask of mode ID */
116 OOP_Object
*gfxhidd
; /* Graphics driver to use (can be fakegfx object) */
117 ObjectCache
*gc_cache
; /* GC cache */
118 UWORD flags
; /* Flags, see below */
120 APTR userdata
; /* Associated data from notification callback */
121 struct HIDD_ViewPortData
*display
; /* What is currently displayed */
123 /* FakeGfx-related */
124 OOP_Object
*gfxhidd_orig
; /* Real graphics driver object */
126 /* Framebuffer stuff */
127 struct BitMap
*frontbm
; /* Currently shown bitmap */
128 OOP_Object
*framebuffer
; /* Framebuffer bitmap object */
129 OOP_Object
*bm_bak
; /* Original shown bitmap object */
130 OOP_Object
*colmap_bak
; /* Original colormap object of shown bitmap */
131 HIDDT_ColorModel colmod_bak
; /* Original colormodel of shown bitmap */
133 /* Display mode database. */
134 struct DisplayInfoHandle modes
[1]; /* Display modes array */
138 #define DF_BootMode 0x0001
139 #define DF_UseFakeGfx 0x0002
141 /* Common driver data data to all monitors */
142 struct common_driverdata
144 /* The order of these fields match struct monitor_driverdata */
145 struct monitor_driverdata
*monitors
; /* First monitor driver */
146 ULONG invalid_id
; /* INVALID_ID, for GET_BM_MODEID() */
147 ULONG last_id
; /* Last card ID */
148 OOP_Object
*memorygfx
; /* Memory graphics driver */
149 ObjectCache
*gc_cache
; /* GC cache */
150 UWORD flags
; /* Always zero */
152 /* End of driverdata */
153 APTR notify_data
; /* User data for notification callback */
154 APTR (*DriverNotify
)(APTR obj
, BOOL add
, APTR userdata
); /* Display driver notification callback */
155 struct SignalSemaphore displaydb_sem
; /* Display mode database semaphore */
157 ObjectCache
*planarbm_cache
; /* Planar bitmaps cache */
159 /* Fakegfx classes */
160 OOP_Class
*fakegfxclass
;
161 OOP_Class
*fakefbclass
;
163 /* Attribute bases */
164 OOP_AttrBase hiddBitMapAttrBase
;
165 OOP_AttrBase hiddGCAttrBase
;
166 OOP_AttrBase hiddSyncAttrBase
;
167 OOP_AttrBase hiddPixFmtAttrBase
;
168 OOP_AttrBase hiddPlanarBMAttrBase
;
169 OOP_AttrBase hiddGfxAttrBase
;
170 OOP_AttrBase hiddFakeGfxHiddAttrBase
;
171 OOP_AttrBase hiddFakeFBAttrBase
;
174 #define CDD(base) ((struct common_driverdata *)&PrivGBase(base)->shared_driverdata)
176 #define __IHidd_BitMap CDD(GfxBase)->hiddBitMapAttrBase
177 #define __IHidd_GC CDD(GfxBase)->hiddGCAttrBase
178 #define __IHidd_Sync CDD(GfxBase)->hiddSyncAttrBase
179 #define __IHidd_PixFmt CDD(GfxBase)->hiddPixFmtAttrBase
180 #define __IHidd_PlanarBM CDD(GfxBase)->hiddPlanarBMAttrBase
181 #define __IHidd_Gfx CDD(GfxBase)->hiddGfxAttrBase
182 #define __IHidd_FakeGfxHidd CDD(GfxBase)->hiddFakeGfxHiddAttrBase
183 #define __IHidd_FakeFB CDD(GfxBase)->hiddFakeFBAttrBase
185 /* Hashtable sizes. Must be powers of two */
186 #define GFXASSOCIATE_HASHSIZE 8
187 #define TFE_HASHTABSIZE 16
188 #define DRIVERDATALIST_HASHSIZE 256
190 /* Internal GFXBase struct */
191 struct GfxBase_intern
193 struct GfxBase gfxbase
;
195 ULONG displays
; /* Number of display drivers installed in the system */
196 struct common_driverdata shared_driverdata
; /* Driver data shared between all monitors (allocated once) */
197 struct SignalSemaphore monitors_sema
; /* Monitor list semaphore */
198 struct SignalSemaphore hashtab_sema
; /* hash_table arbitration semaphore */
199 struct SignalSemaphore view_sema
; /* ActiView arbitration semaphore */
201 /* TextFontExtension pool */
202 struct tfe_hashnode
* tfe_hashtab
[TFE_HASHTABSIZE
];
203 struct SignalSemaphore tfe_hashtab_sema
;
204 struct SignalSemaphore fontsem
;
206 #if REGIONS_USE_MEMPOOL
208 struct SignalSemaphore regionsem
;
210 struct MinList ChunkPoolList
;
213 /* GC driverdata pool */
214 struct SignalSemaphore driverdatasem
;
216 struct MinList driverdatalist
[DRIVERDATALIST_HASHSIZE
];
219 struct SignalSemaphore blit_sema
;
221 /* Private library bases */
222 struct Library
*CyberGfxBase
;
223 struct Library
*OOPBase
;
224 struct Library
*UtilityBase
;
226 /* Private HIDD method bases */
227 OOP_MethodID HiddBitMapBase
;
228 OOP_MethodID HiddColorMapBase
;
229 OOP_MethodID HiddGCBase
;
230 OOP_MethodID HiddGfxBase
;
231 OOP_MethodID HiddPlanarBMBase
;
237 #define PrivGBase(x) ((struct GfxBase_intern *)x)
238 /* FIXME: Remove these #define xxxBase hacks
239 Do not use this in new code !
241 #define HiddBitMapBase (PrivGBase(GfxBase)->HiddBitMapBase)
242 #define HiddColorMapBase (PrivGBase(GfxBase)->HiddColorMapBase)
243 #define HiddGCBase (PrivGBase(GfxBase)->HiddGCBase)
244 #define HiddGfxBase (PrivGBase(GfxBase)->HiddGfxBase)
245 #define HiddPlanarBMBase (PrivGBase(GfxBase)->HiddPlanarBMBase)
247 /* This must be included before defining OOPBase */
248 #include <hidd/graphics_inline.h>
250 /* struct Utilitybase is used in the following file so include it
251 before defining Utilitybase
253 #include <proto/utility.h>
254 #define CyberGfxBase (PrivGBase(GfxBase)->CyberGfxBase)
255 #define OOPBase (PrivGBase(GfxBase)->OOPBase)
256 #define UtilityBase (PrivGBase(GfxBase)->UtilityBase)
258 #define WIDTH_TO_BYTES(width) ((( (width) + 15) & ~15) >> 3)
259 #define WIDTH_TO_WORDS(width) ((( (width) + 15) & ~15) >> 4)
261 #define XCOORD_TO_BYTEIDX( x ) (( x ) >> 3)
262 #define XCOORD_TO_WORDIDX( x ) (( x ) >> 4)
264 #define COORD_TO_BYTEIDX(x, y, bytes_per_row) \
265 ( ( ((LONG)(y)) * (bytes_per_row)) + XCOORD_TO_BYTEIDX(x))
267 #define CHUNKY8_COORD_TO_BYTEIDX(x, y, bytes_per_row) \
268 ( ( ((LONG)(y)) * (bytes_per_row)) + (x) )
270 #define XCOORD_TO_MASK(x) (128L >> ((x) & 0x07))
272 /* For vsprite sorting */
274 #define JOIN_XY_COORDS(x,y) (LONG)( ( ((UWORD)(y)) << 16) + ( ( ((UWORD)(x)) + 0x8000 ) & 0xFFFF ) )
276 #define TFE(tfe) (*(struct TextFontExtension**)&tfe)
278 #define TFE_MATCHWORD 0xDFE7 /* randomly invented */
280 /* Defines for flags in areainfo->FlagPtr */
282 #define AREAINFOFLAG_MOVE 0x00
283 #define AREAINFOFLAG_DRAW 0x01
284 #define AREAINFOFLAG_CLOSEDRAW 0x02
285 #define AREAINFOFLAG_ELLIPSE 0x03
287 /* Forward declaration */
290 /* Hash index calculation */
291 extern ULONG
CalcHashIndex(IPTR n
, UWORD size
);
293 BOOL
ObtainDriverData (struct RastPort
* rp
, struct GfxBase
* GfxBase
);
294 void ReleaseDriverData (struct RastPort
* rp
, struct GfxBase
* GfxBase
);
295 void KillDriverData (struct RastPort
* rp
, struct GfxBase
* GfxBase
);
297 /* a function needed by ClipBlit */
298 void internal_ClipBlit(struct RastPort
* srcRP
,
301 struct RastPort
* destRP
,
307 struct GfxBase
* GfxBase
);
309 /* Driver prototypes */
311 typedef ULONG (*VIEW_FUNC
)(struct HIDD_ViewPortData
*vpd
, struct View
*v
, struct monitor_driverdata
*mdd
, struct GfxBase
*GfxBase
);
313 extern ULONG
driver_PrepareViewPorts(struct HIDD_ViewPortData
*vpd
, struct View
*v
, struct monitor_driverdata
*mdd
, struct GfxBase
*GfxBase
);
314 extern ULONG
driver_LoadViewPorts(struct HIDD_ViewPortData
*vpd
, struct View
*v
, struct monitor_driverdata
*mdd
, struct GfxBase
*GfxBase
);
315 extern struct monitor_driverdata
*driver_Setup(OOP_Object
*gfxhidd
, struct GfxBase
*GfxBase
);
316 extern void driver_Expunge(struct monitor_driverdata
*mdd
, struct GfxBase
*GfxBase
);
317 extern struct HIDD_ViewPortData
*driver_FindViewPorts(struct View
*view
, struct monitor_driverdata
*mdd
, struct GfxBase
*GfxBase
);
318 extern ULONG
DoViewFunction(struct View
*view
, VIEW_FUNC fn
, struct GfxBase
*GfxBase
);
320 /* functions in support.c */
321 extern BOOL
pattern_pen(struct RastPort
*rp
323 , ULONG apen
, ULONG bpen
325 , struct GfxBase
*GfxBase
);
327 /* function for area opeartions */
328 BOOL
areafillpolygon(struct RastPort
* rp
,
329 struct Rectangle
* bounds
,
333 struct GfxBase
* GfxBase
);
335 void areafillellipse(struct RastPort
* rp
,
336 struct Rectangle
* bounds
,
339 struct GfxBase
* GfxBase
);
341 void areaclosepolygon(struct AreaInfo
*areainfo
);
343 /* functions in color_support */
344 ULONG
color_distance(struct ColorMap
* cm
,
350 BOOL
color_equal(struct ColorMap
* cm
,
356 VOID
color_get(struct ColorMap
*cm
,
362 void _DisposeRegionRectangleList
364 struct RegionRectangle
*RR
,
365 struct GfxBase
*GfxBase
368 struct RegionRectangle
*_NewRegionRectangle
370 struct RegionRectangle
**LastRectPtr
,
371 struct GfxBase
*GfxBase
374 BOOL _LinkRegionRectangleList
376 struct RegionRectangle
*src
,
377 struct RegionRectangle
**dstptr
,
378 struct GfxBase
*GfxBase
382 # define GFX_ALLOC(Size) \
386 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
390 PrivGBase(GfxBase)->regionpool, \
394 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
399 # define GFX_FREE(Mem, Size) \
403 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
407 PrivGBase(GfxBase)->regionpool, \
412 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
415 # define GFX_ALLOC(Size) AllocMem(Size, MEMF_ANY)
416 # define GFX_FREE(Mem, Size) FreeMem(Mem, Size)
419 #define _NewRegionRectangleExtChunk() \
420 __NewRegionRectangleExtChunk(GfxBase)
422 #define _DisposeRegionRectangleExtChunk(_chunk) \
423 __DisposeRegionRectangleExtChunk(_chunk, GfxBase)
425 #define SIZECHUNKBUF 20
429 struct RegionRectangleExtChunk Chunk
;
430 struct ChunkPool
*Owner
;
436 struct ChunkExt Chunks
[SIZECHUNKBUF
];
437 struct MinList ChunkList
;
441 void __DisposeRegionRectangleExtChunk
443 struct RegionRectangleExtChunk
*Chunk
,
444 struct GfxBase
*GfxBase
453 #endif /* GRAPHICS_INTERN_H */