Update to lasso handling. Adjust scroll amount based on difference between mouse...
[AROS.git] / rom / graphics / graphics_intern.h
blob1eb8a80239b31a0c7f7eec2ea7c8acb1bdf2791c
1 #ifndef GRAPHICS_INTERN_H
2 #define GRAPHICS_INTERN_H
3 /*
4 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 $Id$
7 Desc: Internal header file for graphics.library
8 Lang: english
9 */
11 #ifndef AROS_LIBCALL_H
12 # include <aros/libcall.h>
13 #endif
14 #ifndef EXEC_EXECBASE_H
15 # include <exec/execbase.h>
16 #endif
17 #ifndef EXEC_LISTS_H
18 # include <exec/lists.h>
19 #endif
20 #ifndef EXEC_NODES_H
21 # include <exec/nodes.h>
22 #endif
23 #ifndef EXEC_SEMAPHORE_H
24 # include <exec/semaphores.h>
25 #endif
26 #ifndef GRAPHICS_GFXBASE_H
27 # include <graphics/gfxbase.h>
28 #endif
29 #ifndef GRAPHICS_TEXT_H
30 # include <graphics/text.h>
31 #endif
32 #ifndef GRAPHICS_RASTPORT_H
33 # include <graphics/rastport.h>
34 #endif
35 #ifndef GRAPHICS_REGIONS_H
36 # include <graphics/regions.h>
37 #endif
38 #ifndef OOP_OOP_H
39 # include <oop/oop.h>
40 #endif
41 #ifndef GRAPHICS_VIEW_H
42 # include <graphics/view.h>
43 #endif
44 #ifndef HIDD_GRAPHICS_H
45 # include <hidd/graphics.h>
46 #endif
48 #include <exec/memory.h>
49 #include <proto/exec.h>
50 #include <graphics/scale.h>
51 #include "fontsupport.h"
52 #include "objcache.h"
54 #define REGIONS_USE_MEMPOOL 1
56 /* Setting BMDEPTH_COMPATIBILITY to 1 will cause bitmap->Depth
57 to be never bigger than 8. The same seems to be the case under
58 AmigaOS with CyberGraphX/Picasso96. GetBitMapAttr() OTOH will
59 actually return the real depth. */
61 #define BMDEPTH_COMPATIBILITY 1
63 /* New driverdata code (driverdata is gfx driver stuff connected
64 to rastports, ie. a GC object) which is prepared for garbage
65 collection. Really need this, as relying on all rastports
66 to be un-initialized with AROS specific DeinitRastPort() just
67 will not work. Best example: 68k binaries, if we should ever
68 have some kind of 68k emu */
70 #define NEW_DRIVERDATA_CODE 0
72 #if NEW_DRIVERDATA_CODE
73 #define OBTAIN_DRIVERDATA(rp,libbase) ObtainDriverData(rp, libbase)
74 #define RELEASE_DRIVERDATA(rp,libbase) ReleaseDriverData(rp, libbase)
75 #define KILL_DRIVERDATA(rp,libbase) KillDriverData(rp, libbase)
76 #else
77 #define OBTAIN_DRIVERDATA(rp,libbase) obsolete_CorrectDriverData(rp, libbase)
78 #define RELEASE_DRIVERDATA(rp,libbase)
79 #define KILL_DRIVERDATA(rp,libbase)
80 #endif
82 #define SIZERECTBUF 128
84 struct RegionRectangleExt
86 struct RegionRectangle RR;
87 IPTR Counter;
90 struct RegionRectangleExtChunk
92 struct RegionRectangleExt Rects[SIZERECTBUF];
93 struct RegionRectangleExtChunk *FirstChunk;
96 #define RRE(x) ((struct RegionRectangleExt *)(x))
97 #define Counter(x) (RRE(x)->Counter)
98 #define Chunk(x) ((x) ? ((struct RegionRectangleExtChunk *)&RRE(x)[-Counter(x)]) : NULL)
100 /* PaletteExtra internals */
102 typedef WORD PalExtra_RefCnt_Type;
103 typedef WORD PalExtra_AllocList_Type;
105 #define PALEXTRA_REFCNT(pe,n) (((PalExtra_RefCnt_Type *)(pe)->pe_RefCnt)[(n)])
106 #define PALEXTRA_ALLOCLIST(pe,n) (((PalExtra_AllocList_Type *)(pe)->pe_AllocList)[(n)])
108 struct class_static_data
110 struct GfxBase *gfxbase;
112 OOP_AttrBase hiddFakeFBAttrBase;
114 OOP_Class *fakegfxclass;
115 OOP_Class *fakefbclass;
116 OOP_Class *fakedbmclass;
118 OOP_Object *fakegfxobj;
121 struct shared_driverdata
123 OOP_Object *gfxhidd;
124 OOP_Object *gfxhidd_orig;
125 OOP_Object *gfxhidd_fake;
127 ObjectCache *gc_cache;
128 ObjectCache *planarbm_cache;
130 OOP_Object *framebuffer;
132 OOP_Object *bm_bak;
133 OOP_Object *colmap_bak;
134 HIDDT_ColorModel colmod_bak;
136 OOP_AttrBase hiddBitMapAttrBase;
137 OOP_AttrBase hiddGCAttrBase;
138 OOP_AttrBase hiddSyncAttrBase;
139 OOP_AttrBase hiddPixFmtAttrBase;
140 OOP_AttrBase hiddPlanarBMAttrBase;
141 OOP_AttrBase hiddGfxAttrBase;
142 OOP_AttrBase hiddFakeGfxHiddAttrBase;
143 OOP_MethodID hiddGfxShowImminentReset_MethodID;
145 /* The frontmost screen's bitmap */
146 struct BitMap *frontbm;
148 /* Does the gfx hidd support hardware pointers ? */
149 BOOL has_hw_cursor;
151 /* This is used if the gfx hidd does not support hardware mouse pointers */
152 OOP_Object *pointerbm;
153 LONG pointer_x;
154 LONG pointer_y;
156 struct class_static_data fakegfx_staticdata;
157 BOOL fakegfx_inited;
159 #if 0
160 /* Has the code to handle active screens been activated ? */
161 BOOL activescreen_inited;
162 #endif
163 APTR dispinfo_db; /* Display info database */
166 #define SDD(base) ((struct shared_driverdata *)&PrivGBase(base)->shared_driverdata)
167 #define __IHidd_BitMap SDD(GfxBase)->hiddBitMapAttrBase
168 #define __IHidd_GC SDD(GfxBase)->hiddGCAttrBase
169 #define __IHidd_Sync SDD(GfxBase)->hiddSyncAttrBase
170 #define __IHidd_PixFmt SDD(GfxBase)->hiddPixFmtAttrBase
171 #define __IHidd_PlanarBM SDD(GfxBase)->hiddPlanarBMAttrBase
172 #define __IHidd_Gfx SDD(GfxBase)->hiddGfxAttrBase
173 #define __IHidd_FakeGfxHidd SDD(GfxBase)->hiddFakeGfxHiddAttrBase
176 #define DRIVERDATALIST_HASHSIZE 256
178 /* Internal GFXBase struct */
179 struct GfxBase_intern
181 struct GfxBase gfxbase;
183 /* Driver data shared between all rastports (allocated once) */
184 struct shared_driverdata shared_driverdata;
187 #define TFE_HASHTABSIZE 16 /* This MUST be a power of two */
189 struct tfe_hashnode * tfe_hashtab[TFE_HASHTABSIZE];
190 struct SignalSemaphore tfe_hashtab_sema;
191 struct SignalSemaphore fontsem;
192 #if REGIONS_USE_MEMPOOL
193 struct SignalSemaphore regionsem;
194 APTR regionpool;
195 struct MinList ChunkPoolList;
196 #endif
197 struct SignalSemaphore driverdatasem;
198 APTR driverdatapool;
199 struct MinList driverdatalist[DRIVERDATALIST_HASHSIZE];
200 ULONG *pixel_buf; // used in graphics_driver
201 struct SignalSemaphore pixbuf_sema;
202 struct SignalSemaphore blit_sema;
206 /* Macros */
208 #define PrivGBase(x) ((struct GfxBase_intern *)x)
210 #define WIDTH_TO_BYTES(width) ((( (width) + 15) & ~15) >> 3)
211 #define WIDTH_TO_WORDS(width) ((( (width) + 15) & ~15) >> 4)
213 #define XCOORD_TO_BYTEIDX( x ) (( x ) >> 3)
214 #define XCOORD_TO_WORDIDX( x ) (( x ) >> 4)
216 #define COORD_TO_BYTEIDX(x, y, bytes_per_row) \
217 ( ( ((LONG)(y)) * (bytes_per_row)) + XCOORD_TO_BYTEIDX(x))
219 #define CHUNKY8_COORD_TO_BYTEIDX(x, y, bytes_per_row) \
220 ( ( ((LONG)(y)) * (bytes_per_row)) + (x) )
222 #define XCOORD_TO_MASK(x) (128L >> ((x) & 0x07))
224 /* For vsprite sorting */
226 #define JOIN_XY_COORDS(x,y) (LONG)( ( ((UWORD)(y)) << 16) + ( ( ((UWORD)(x)) + 0x8000 ) & 0xFFFF ) )
228 /* Defines */
229 #define BMT_STANDARD 0x0000 /* Standard bitmap */
230 #define BMT_RGB 0x1234 /* RTG Bitmap. 24bit RGB chunky */
231 #define BMT_RGBA 0x1238 /* RTG Bitmap. 32bit RGBA chunky */
232 #define BMT_DRIVER 0x8000 /* Special RTG bitmap.
233 Use this as an offset. */
235 #define TFE(tfe) (*(struct TextFontExtension**)&tfe)
237 #define TFE_MATCHWORD 0xDFE7 /* randomly invented */
239 /* Defines for flags in areainfo->FlagPtr */
241 #define AREAINFOFLAG_MOVE 0x00
242 #define AREAINFOFLAG_DRAW 0x01
243 #define AREAINFOFLAG_CLOSEDRAW 0x02
244 #define AREAINFOFLAG_ELLIPSE 0x03
246 /* Forward declaration */
247 struct ViewPort;
249 /* a function needed by GfxAssocate(), GfxLookUp(), GfxFree() */
250 extern ULONG CalcHashIndex(ULONG n);
252 BOOL obsolete_CorrectDriverData (struct RastPort * rp, struct GfxBase * GfxBase);
253 #if NEW_DRIVERDATA_CODE
254 BOOL ObtainDriverData (struct RastPort * rp, struct GfxBase * GfxBase);
255 void ReleaseDriverData (struct RastPort * rp, struct GfxBase * GfxBase);
256 void KillDriverData (struct RastPort * rp, struct GfxBase * GfxBase);
257 #endif
259 /* a function needed by ClipBlit */
260 void internal_ClipBlit(struct RastPort * srcRP,
261 LONG xSrc,
262 LONG ySrc,
263 struct RastPort * destRP,
264 LONG xDest,
265 LONG yDest,
266 LONG xSize,
267 LONG ySize,
268 UBYTE minterm,
269 struct GfxBase * GfxBase);
271 /* Driver prototypes */
272 extern BOOL driver_LateGfxInit(APTR, struct GfxBase *GfxBase);
274 extern void driver_Text (struct RastPort *, CONST_STRPTR, LONG, struct GfxBase *);
276 /* functions in support.c */
277 extern BOOL pattern_pen(struct RastPort *rp
278 , LONG x, LONG y
279 , ULONG apen, ULONG bpen
280 , ULONG *pixval_ptr
281 , struct GfxBase *GfxBase);
283 /* function for area opeartions */
284 BOOL areafillpolygon(struct RastPort * rp,
285 struct Rectangle * bounds,
286 UWORD first_idx,
287 UWORD last_idx,
288 ULONG bytesperrow,
289 struct GfxBase * GfxBase);
291 void areafillellipse(struct RastPort * rp,
292 struct Rectangle * bounds,
293 UWORD * CurVctr,
294 ULONG BytesPerRow,
295 struct GfxBase * GfxBase);
297 void areaclosepolygon(struct AreaInfo *areainfo);
299 /* functions in color_support */
300 ULONG color_distance(struct ColorMap * cm,
301 ULONG r,
302 ULONG g,
303 ULONG b,
304 ULONG index);
306 BOOL color_equal(struct ColorMap * cm,
307 ULONG r,
308 ULONG g,
309 ULONG b,
310 ULONG index);
312 VOID color_set(struct ColorMap * cm,
313 ULONG r,
314 ULONG g,
315 ULONG b,
316 ULONG index);
318 VOID color_get(struct ColorMap *cm,
319 ULONG *r,
320 ULONG *g,
321 ULONG *b,
322 ULONG index);
324 void _DisposeRegionRectangleList
326 struct RegionRectangle *RR,
327 struct GfxBase *GfxBase
330 struct RegionRectangle *_NewRegionRectangle
332 struct RegionRectangle **LastRectPtr,
333 struct GfxBase *GfxBase
336 BOOL _LinkRegionRectangleList
338 struct RegionRectangle *src,
339 struct RegionRectangle **dstptr,
340 struct GfxBase *GfxBase
343 #if REGIONS_USE_POOL
344 # define GFX_ALLOC(Size) \
345 ({ \
346 APTR Mem; \
348 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
350 Mem = AllocPooled \
352 PrivGBase(GfxBase)->regionpool, \
353 Size \
354 ); \
356 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
358 Mem; \
361 # define GFX_FREE(Mem, Size) \
363 APTR Mem; \
365 ObtainSemaphore(&PrivGBase(GfxBase)->regionsem); \
367 FreePooled \
369 PrivGBase(GfxBase)->regionpool, \
370 Mem, \
371 size \
372 ); \
374 ReleaseSemaphore(&PrivGBase(GfxBase)->regionsem); \
376 #else
377 # define GFX_ALLOC(Size) AllocMem(Size, MEMF_ANY)
378 # define GFX_FREE(Mem, Size) FreeMem(Mem, Size)
379 #endif
381 #define _NewRegionRectangleExtChunk() \
382 __NewRegionRectangleExtChunk(GfxBase)
384 #define _DisposeRegionRectangleExtChunk(_chunk) \
385 __DisposeRegionRectangleExtChunk(_chunk, GfxBase)
387 #define SIZECHUNKBUF 20
389 struct ChunkExt
391 struct RegionRectangleExtChunk Chunk;
392 struct ChunkPool *Owner;
395 struct ChunkPool
397 struct MinNode Node;
398 struct ChunkExt Chunks[SIZECHUNKBUF];
399 struct MinList ChunkList;
400 LONG NumChunkFree;
403 void __DisposeRegionRectangleExtChunk
405 struct RegionRectangleExtChunk *Chunk,
406 struct GfxBase *GfxBase
409 #endif /* GRAPHICS_INTERN_H */