1 #ifndef GRAPHICS_INTERN_H
2 #define GRAPHICS_INTERN_H
4 Copyright © 1995-2010, 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)])
94 struct class_static_data
96 struct GfxBase
*gfxbase
;
98 OOP_AttrBase hiddFakeFBAttrBase
;
100 OOP_Class
*fakegfxclass
;
101 OOP_Class
*fakefbclass
;
105 * Display mode database item. A pointer to this structure is used as a DisplayInfoHandle.
106 * In future, if needed, this structure can be extended to hold static bunches of associated
110 struct monitor_driverdata
;
112 struct DisplayInfoHandle
114 HIDDT_ModeID id
; /* HIDD Mode ID (without card ID) */
115 struct monitor_driverdata
*drv
; /* Points back to display driver descriptor */
118 #define DIH(x) ((struct DisplayInfoHandle *)x)
120 /* Monitor driver data. Describes a single physical display. */
121 struct monitor_driverdata
123 struct monitor_driverdata
*next
; /* Next driver data in chain */
124 ULONG id
; /* Card ID (part of display mode ID) */
125 ULONG mask
; /* Mask of mode ID */
126 OOP_Object
*gfxhidd
; /* Graphics driver to use (can be fakegfx object) */
127 ObjectCache
*gc_cache
; /* GC cache */
129 APTR userdata
; /* Associated data from notification callback */
130 UWORD flags
; /* Flags, see below */
131 struct HIDD_ViewPortData
*display
; /* What is currently displayed */
133 /* FakeGfx-related */
134 OOP_Object
*gfxhidd_orig
; /* Real graphics driver object */
136 /* Framebuffer stuff */
137 struct BitMap
*frontbm
; /* Currently shown bitmap */
138 OOP_Object
*framebuffer
; /* Framebuffer bitmap object */
139 OOP_Object
*bm_bak
; /* Original shown bitmap object */
140 OOP_Object
*colmap_bak
; /* Original colormap object of shown bitmap */
141 HIDDT_ColorModel colmod_bak
; /* Original colormodel of shown bitmap */
143 /* Display mode database. */
144 struct DisplayInfoHandle modes
[1]; /* Display modes array */
148 #define DF_BootMode 0x0001
149 #define DF_UseFakeGfx 0x0002
151 /* Common driver data data to all monitors */
152 struct common_driverdata
154 /* The order of these fields match struct monitor_driverdata */
155 struct monitor_driverdata
*monitors
; /* First monitor driver */
156 ULONG invalid_id
; /* INVALID_ID, for GET_BM_MODEID() */
157 ULONG last_id
; /* Last card ID */
158 OOP_Object
*memorygfx
; /* Memory graphics driver */
159 ObjectCache
*gc_cache
; /* GC cache */
161 /* End of driverdata */
162 APTR notify_data
; /* User data for notification callback */
163 APTR (*DriverNotify
)(APTR obj
, BOOL add
, APTR userdata
); /* Display driver notification callback */
164 struct SignalSemaphore displaydb_sem
; /* Display mode database semaphore */
166 ObjectCache
*planarbm_cache
; /* Planar bitmaps cache */
168 /* Attribute bases */
169 OOP_AttrBase hiddBitMapAttrBase
;
170 OOP_AttrBase hiddGCAttrBase
;
171 OOP_AttrBase hiddSyncAttrBase
;
172 OOP_AttrBase hiddPixFmtAttrBase
;
173 OOP_AttrBase hiddPlanarBMAttrBase
;
174 OOP_AttrBase hiddGfxAttrBase
;
175 OOP_AttrBase hiddFakeGfxHiddAttrBase
;
178 #define CDD(base) ((struct common_driverdata *)&PrivGBase(base)->shared_driverdata)
180 #define __IHidd_BitMap CDD(GfxBase)->hiddBitMapAttrBase
181 #define __IHidd_GC CDD(GfxBase)->hiddGCAttrBase
182 #define __IHidd_Sync CDD(GfxBase)->hiddSyncAttrBase
183 #define __IHidd_PixFmt CDD(GfxBase)->hiddPixFmtAttrBase
184 #define __IHidd_PlanarBM CDD(GfxBase)->hiddPlanarBMAttrBase
185 #define __IHidd_Gfx CDD(GfxBase)->hiddGfxAttrBase
186 #define __IHidd_FakeGfxHidd CDD(GfxBase)->hiddFakeGfxHiddAttrBase
188 /* Hashtable sizes. Must be powers of two */
189 #define GFXASSOCIATE_HASHSIZE 8
190 #define TFE_HASHTABSIZE 16
191 #define DRIVERDATALIST_HASHSIZE 256
193 /* Internal GFXBase struct */
194 struct GfxBase_intern
196 struct GfxBase gfxbase
;
198 struct class_static_data
*fakegfx_staticdata
; /* FakeGFX HIDD static data */
199 ULONG displays
; /* Number of display drivers installed in the system */
200 struct common_driverdata shared_driverdata
; /* Driver data shared between all monitors (allocated once) */
201 struct SignalSemaphore monitors_sema
; /* Monitor list semaphore */
202 struct SignalSemaphore hashtab_sema
; /* hash_table arbitration semaphore */
203 struct SignalSemaphore view_sema
; /* ActiView arbitration semaphore */
205 /* TextFontExtension pool */
206 struct tfe_hashnode
* tfe_hashtab
[TFE_HASHTABSIZE
];
207 struct SignalSemaphore tfe_hashtab_sema
;
208 struct SignalSemaphore fontsem
;
210 #if REGIONS_USE_MEMPOOL
212 struct SignalSemaphore regionsem
;
214 struct MinList ChunkPoolList
;
217 /* GC driverdata pool */
218 struct SignalSemaphore driverdatasem
;
220 struct MinList driverdatalist
[DRIVERDATALIST_HASHSIZE
];
222 /* Pixelbuffer, needed for some operations */
224 struct SignalSemaphore pixbuf_sema
;
225 struct SignalSemaphore blit_sema
;
227 /* Private library bases */
228 struct Library
*CyberGfxBase
;
234 #define PrivGBase(x) ((struct GfxBase_intern *)x)
235 #define CyberGfxBase (PrivGBase(GfxBase)->CyberGfxBase)
237 #define WIDTH_TO_BYTES(width) ((( (width) + 15) & ~15) >> 3)
238 #define WIDTH_TO_WORDS(width) ((( (width) + 15) & ~15) >> 4)
240 #define XCOORD_TO_BYTEIDX( x ) (( x ) >> 3)
241 #define XCOORD_TO_WORDIDX( x ) (( x ) >> 4)
243 #define COORD_TO_BYTEIDX(x, y, bytes_per_row) \
244 ( ( ((LONG)(y)) * (bytes_per_row)) + XCOORD_TO_BYTEIDX(x))
246 #define CHUNKY8_COORD_TO_BYTEIDX(x, y, bytes_per_row) \
247 ( ( ((LONG)(y)) * (bytes_per_row)) + (x) )
249 #define XCOORD_TO_MASK(x) (128L >> ((x) & 0x07))
251 /* For vsprite sorting */
253 #define JOIN_XY_COORDS(x,y) (LONG)( ( ((UWORD)(y)) << 16) + ( ( ((UWORD)(x)) + 0x8000 ) & 0xFFFF ) )
255 #define TFE(tfe) (*(struct TextFontExtension**)&tfe)
257 #define TFE_MATCHWORD 0xDFE7 /* randomly invented */
259 /* Defines for flags in areainfo->FlagPtr */
261 #define AREAINFOFLAG_MOVE 0x00
262 #define AREAINFOFLAG_DRAW 0x01
263 #define AREAINFOFLAG_CLOSEDRAW 0x02
264 #define AREAINFOFLAG_ELLIPSE 0x03
266 /* Forward declaration */
269 /* Hash index calculation */
270 extern ULONG
CalcHashIndex(IPTR n
, UWORD size
);
272 BOOL
ObtainDriverData (struct RastPort
* rp
, struct GfxBase
* GfxBase
);
273 void ReleaseDriverData (struct RastPort
* rp
, struct GfxBase
* GfxBase
);
274 void KillDriverData (struct RastPort
* rp
, struct GfxBase
* GfxBase
);
276 /* a function needed by ClipBlit */
277 void internal_ClipBlit(struct RastPort
* srcRP
,
280 struct RastPort
* destRP
,
286 struct GfxBase
* GfxBase
);
288 /* Driver prototypes */
289 extern void driver_LoadView(struct View
*view
, struct GfxBase
*);
291 extern struct monitor_driverdata
*driver_Setup(OOP_Object
*gfxhidd
, struct GfxBase
*GfxBase
);
292 extern void driver_Expunge(struct monitor_driverdata
*mdd
, struct GfxBase
*GfxBase
);
294 /* functions in support.c */
295 extern BOOL
pattern_pen(struct RastPort
*rp
297 , ULONG apen
, ULONG bpen
299 , struct GfxBase
*GfxBase
);
301 /* function for area opeartions */
302 BOOL
areafillpolygon(struct RastPort
* rp
,
303 struct Rectangle
* bounds
,
307 struct GfxBase
* GfxBase
);
309 void areafillellipse(struct RastPort
* rp
,
310 struct Rectangle
* bounds
,
313 struct GfxBase
* GfxBase
);
315 void areaclosepolygon(struct AreaInfo
*areainfo
);
317 /* functions in color_support */
318 ULONG
color_distance(struct ColorMap
* cm
,
324 BOOL
color_equal(struct ColorMap
* cm
,
330 VOID
color_get(struct ColorMap
*cm
,
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
356 # define GFX_ALLOC(Size) \
360 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
364 PrivGBase(GfxBase)->regionpool, \
368 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
373 # define GFX_FREE(Mem, Size) \
377 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
381 PrivGBase(GfxBase)->regionpool, \
386 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
389 # define GFX_ALLOC(Size) AllocMem(Size, MEMF_ANY)
390 # define GFX_FREE(Mem, Size) FreeMem(Mem, Size)
393 #define _NewRegionRectangleExtChunk() \
394 __NewRegionRectangleExtChunk(GfxBase)
396 #define _DisposeRegionRectangleExtChunk(_chunk) \
397 __DisposeRegionRectangleExtChunk(_chunk, GfxBase)
399 #define SIZECHUNKBUF 20
403 struct RegionRectangleExtChunk Chunk
;
404 struct ChunkPool
*Owner
;
410 struct ChunkExt Chunks
[SIZECHUNKBUF
];
411 struct MinList ChunkList
;
415 void __DisposeRegionRectangleExtChunk
417 struct RegionRectangleExtChunk
*Chunk
,
418 struct GfxBase
*GfxBase
421 #endif /* GRAPHICS_INTERN_H */