Port the SB128 code to AROS.
[AROS.git] / rom / hidds / graphics / graphics_intern.h
blobd039adaa6f79f22fce37abec4920a3c8cd67a1aa
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #ifndef GRAPHICS_HIDD_INTERN_H
7 #define GRAPHICS_HIDD_INTERN_H
9 /* Include files */
11 #include <aros/debug.h>
12 #include <exec/libraries.h>
13 #include <exec/semaphores.h>
14 #include <oop/oop.h>
15 #include <hidd/graphics.h>
16 #include <dos/dos.h>
17 #include <graphics/gfxbase.h>
18 #include <graphics/monitor.h>
21 #define USE_FAST_PUTPIXEL 1
22 #define OPTIMIZE_DRAWPIXEL_FOR_COPY 1
23 #define USE_FAST_DRAWPIXEL 1
24 #define USE_FAST_GETPIXEL 1
25 #define COPYBOX_CHECK_FOR_ALIKE_PIXFMT 1
27 #define HBM(x) ((struct HIDDBitMapData *)x)
29 #define GOT_PF_ATTR(code) GOT_ATTR(code, aoHidd_PixFmt, pixfmt)
30 #define FOUND_PF_ATTR(code) FOUND_ATTR(code, aoHidd_PixFmt, pixfmt);
32 #define GOT_SYNC_ATTR(code) GOT_ATTR(code, aoHidd_Sync, sync)
33 #define FOUND_SYNC_ATTR(code) FOUND_ATTR(code, aoHidd_Sync, sync);
35 #define GOT_BM_ATTR(code) GOT_ATTR(code, aoHidd_BitMap, bitmap)
36 #define FOUND_BM_ATTR(code) FOUND_ATTR(code, aoHidd_BitMap, bitmap);
38 #define SWAPBYTES_WORD(x) ((((x) >> 8) & 0x00FF) | (((x) & 0x00FF) << 8))
40 struct colormap_data
42 HIDDT_ColorLUT clut;
45 struct pixfmt_data
47 HIDDT_PixelFormat pf; /* Public portion in the beginning */
49 struct MinNode node; /* Node for linking into the database */
50 ULONG refcount; /* Reference count */
53 /* Use this macro in order to transform node pointer to pixfmt pointer */
54 #define PIXFMT_OBJ(n) ((HIDDT_PixelFormat *)((char *)(n) - offsetof(struct pixfmt_data, node)))
56 struct planarbm_data
58 UBYTE **planes;
59 ULONG planebuf_size;
60 ULONG bytesperrow;
61 ULONG rows;
62 UBYTE depth;
63 BOOL planes_alloced;
66 struct chunkybm_data
68 OOP_Object *gfxhidd; /* Cached driver object */
69 UBYTE *buffer;
70 ULONG bytesperrow;
71 ULONG bytesperpixel;
72 BOOL own_buffer;
75 struct sync_data
77 struct MonitorSpec *mspc; /* Associated MonitorSpec */
79 ULONG pixelclock; /* pixel time in Hz */
81 ULONG hdisp; /* Data missing from MonitorSpec */
82 ULONG htotal;
83 ULONG vdisp;
85 ULONG flags; /* Flags */
87 UBYTE description[32];
89 ULONG hmin; /* Minimum and maximum allowed bitmap size */
90 ULONG hmax;
91 ULONG vmin;
92 ULONG vmax;
94 OOP_Object *gfxhidd; /* Graphics driver that owns this sync */
95 OOP_MethodID SetMode_mID; /* SetMode method ID, for do_monitor() */
96 ULONG InternalFlags; /* Internal flags, see below */
99 /* Sync internal flags */
100 #define SYNC_FREE_MONITORSPEC 0x0001 /* Allocated own MonitorSpec */
101 #define SYNC_FREE_SPECIALMONITOR 0x0002 /* Allocated own SpecialMonitor */
102 #define SYNC_VARIABLE 0x0004 /* Signal timings can be changed */
104 struct mode_bm {
105 UBYTE *bm;
106 UWORD bpr;
108 struct mode_db {
109 /* Array of all available gfxmode PixFmts that are part of
110 gfxmodes
112 struct SignalSemaphore sema;
113 OOP_Object **pixfmts;
114 /* Number of pixfmts in the above array */
115 ULONG num_pixfmts;
117 /* All the sync times that are part of any gfxmode */
118 OOP_Object **syncs;
119 /* Number of syncs in the above array */
120 ULONG num_syncs;
122 /* A bitmap of size (num_pixfmts * num_syncs), that tells if the
123 mode is displayable or not. If a particular (x, y) coordinate
124 of the bitmap is 1, it means that the pixfmt and sync objects
125 you get by indexing pixfmts[x] and syncs[y] are a valid mode.
126 If not, the mode is considered invalid
129 struct mode_bm orig_mode_bm; /* Original as supplied by subclass */
130 struct mode_bm checked_mode_bm; /* After applying monitor refresh rate checks etc. */
134 struct HIDDGraphicsData
136 /* Gfx mode "database" */
137 struct mode_db mdb;
139 /* Framebuffer control stuff */
140 OOP_Object *framebuffer;
141 OOP_Object *shownbm;
143 /* gc used for stuff like rendering cursor */
144 OOP_Object *gc;
146 /* The mode currently used (obsolete ?)
147 HIDDT_ModeID curmode; */
150 /* Private gfxhidd methods */
151 OOP_Object *GFX__Hidd_Gfx__RegisterPixFmt(OOP_Class *cl, OOP_Object *o, struct TagItem *pixFmtTags);
152 VOID GFX__Hidd_Gfx__ReleasePixFmt(OOP_Class *cl, OOP_Object *pf);
154 /* Private bitmap methods */
155 BOOL BM__Hidd_BitMap__SetBitMapTags(OOP_Class *cl, OOP_Object *o, struct TagItem *bitMapTags);
157 struct HIDDBitMapData
159 struct _hidd_bitmap_protected prot;
161 ULONG width; /* width of the bitmap in pixel */
162 ULONG height; /* height of the bitmap in pixel */
163 BOOL displayable; /* bitmap displayable? */
164 BOOL pf_registered;
165 ULONG flags; /* see hidd/graphic.h 'flags for */
166 ULONG bytesPerRow; /* bytes per row */
167 /* WARNING: structure could be extented in the future */
169 OOP_Object *friend; /* Friend bitmap */
171 OOP_Object *gfxhidd;
172 OOP_Class *classptr; /* Class pointer specified during creation */
174 OOP_Object *colmap;
176 HIDDT_ModeID modeid;
178 /* Optimize these two method calls */
179 #if USE_FAST_PUTPIXEL
180 OOP_MethodFunc putpixel;
181 OOP_Class *putpixel_Class;
182 #endif
183 #if USE_FAST_GETPIXEL
184 OOP_MethodFunc getpixel;
185 OOP_Class *getpixel_Class;
186 #endif
187 #if USE_FAST_DRAWPIXEL
188 OOP_MethodFunc drawpixel;
189 OOP_Class *drawpixel_Class;
190 #endif
193 /* Private bitmap attrs */
195 enum
197 aoHidd_BitMap_Dummy = num_Hidd_BitMap_Attrs,
198 num_Total_BitMap_Attrs
201 #if 0
202 struct HIDDGCData
204 #if 0
205 APTR bitMap; /* bitmap to which this gc is connected */
206 #endif
207 APTR userData; /* pointer to own data */
208 ULONG fg; /* foreground color */
209 ULONG bg; /* background color */
210 ULONG drMode; /* drawmode */
211 /* WARNING: type of font could be change */
212 APTR font; /* current fonts */
213 ULONG colMask; /* ColorMask prevents some color bits from changing */
214 UWORD linePat; /* LinePattern */
215 APTR planeMask; /* Pointer to a shape bitMap */
216 ULONG colExp;
218 /* WARNING: structure could be extented in the future */
220 #endif
222 #define NUM_ATTRBASES 9
223 #define NUM_METHODBASES 4
225 struct class_static_data
227 struct GfxBase *GfxBase;
228 struct SignalSemaphore sema;
230 OOP_AttrBase attrBases[NUM_ATTRBASES];
231 OOP_MethodID methodBases[NUM_METHODBASES];
233 OOP_Class *gfxhiddclass; /* graphics hidd class */
234 OOP_Class *bitmapclass; /* bitmap class */
235 OOP_Class *gcclass; /* graphics context class */
236 OOP_Class *colormapclass; /* colormap class */
238 OOP_Class *pixfmtclass; /* describing bitmap pixel formats */
239 OOP_Class *syncclass; /* describing gfxmode sync times */
242 OOP_Class *planarbmclass;
243 OOP_Class *chunkybmclass;
246 Pixel format "database". This is a list
247 of all pixelformats currently used bu some bitmap.
248 The point of having this as a central db in the gfx hidd is
249 that if several bitmaps are of the same pixel format
250 they may point to the same PixFmt object instead
251 of allocating their own instance. Thus we are saving mem
253 struct SignalSemaphore pfsema;
254 struct MinList pflist;
255 /* Index of standard pixelformats for quick access */
256 HIDDT_PixelFormat *std_pixfmts[num_Hidd_StdPixFmt];
258 HIDDT_RGBConversionFunction rgbconvertfuncs[NUM_RGB_STDPIXFMT][NUM_RGB_STDPIXFMT];
259 struct SignalSemaphore rgbconvertfuncs_sem;
262 #define __IHidd_BitMap (csd->attrBases[0])
263 #define __IHidd_Gfx (csd->attrBases[1])
264 #define __IHidd_GC (csd->attrBases[2])
265 #define __IHidd_ColorMap (csd->attrBases[3])
266 #define __IHidd_Overlay (csd->attrBases[4])
267 #define __IHidd_Sync (csd->attrBases[5])
268 #define __IHidd_PixFmt (csd->attrBases[6])
269 #define __IHidd_PlanarBM (csd->attrBases[7])
270 #define __IHidd_ChunkyBM (csd->attrBases[8])
272 #undef HiddGfxBase
273 #undef HiddBitMapBase
274 #undef HiddColorMapBase
275 #undef HiddGCBase
276 #define HiddBitMapBase (csd->methodBases[0])
277 #define HiddGfxBase (csd->methodBases[1])
278 #define HiddGCBase (csd->methodBases[2])
279 #define HiddColorMapBase (csd->methodBases[3])
281 /* Library base */
283 struct IntHIDDGraphicsBase
285 struct Library hdg_LibNode;
287 struct class_static_data hdg_csd;
291 /* pre declarations */
293 BOOL parse_pixfmt_tags(struct TagItem *tags, HIDDT_PixelFormat *pf, ULONG attrcheck, struct class_static_data *csd);
295 static inline ULONG color_distance(UWORD a1, UWORD r1, UWORD g1, UWORD b1, UWORD a2, UWORD r2, UWORD g2, UWORD b2)
297 LONG da = (a1 >> 8) - (a2 >> 8);
298 LONG dr = (r1 >> 8) - (r2 >> 8);
299 LONG dg = (g1 >> 8) - (g2 >> 8);
300 LONG db = (b1 >> 8) - (b2 >> 8);
302 DB2(bug("[color_distance] a1 = 0x%04X a2 = 0x%04X da = %d\n", a1, a2, da));
303 DB2(bug("[color_distance] r1 = 0x%04X r2 = 0x%04X dr = %d\n", r1, r2, dr));
304 DB2(bug("[color_distance] g1 = 0x%04X g2 = 0x%04X dg = %d\n", g1, g2, dg));
305 DB2(bug("[color_distance] b1 = 0x%04X b2 = 0x%04X db = %d\n", b1, b2, db));
307 /* '4' here is a result of trial and error. The idea behind this is to increase
308 the weight of alpha difference in order to make the function prefer colors with
309 the same alpha value. This is important for correct mouse pointer remapping. */
310 return da*da*4 + dr*dr + dg*dg + db*db;
313 #define CSD(x) (&((struct IntHIDDGraphicsBase *)x->UserData)->hdg_csd)
314 #define csd CSD(cl)
316 /* The following calls are optimized by calling the method functions directly */
318 #if USE_FAST_GETPIXEL
319 static inline HIDDT_Pixel GETPIXEL(OOP_Class *cl, OOP_Object *o, WORD x, WORD y)
321 struct pHidd_BitMap_GetPixel get_p;
323 get_p.mID = HiddBitMapBase + moHidd_BitMap_GetPixel;
324 get_p.x = x;
325 get_p.y = y;
327 return HBM(o)->getpixel(HBM(o)->getpixel_Class, o, &get_p.mID);
329 #else
330 #define GETPIXEL(cl, obj, x, y) HIDD_BM_GetPixel(obj, x, y)
331 #endif
333 #if USE_FAST_PUTPIXEL
334 static inline void PUTPIXEL(OOP_Class *cl, OOP_Object *o, WORD x, WORD y, HIDDT_Pixel val)
336 struct pHidd_BitMap_PutPixel put_p;
338 put_p.mID = HiddBitMapBase + moHidd_BitMap_PutPixel;
339 put_p.x = x;
340 put_p.y = y;
341 put_p.pixel = val;
343 HBM(o)->putpixel(HBM(o)->putpixel_Class, o, &put_p.mID);
345 #else
346 #define PUTPIXEL(cl, obj, x, y, val) HIDD_BM_PutPixel(obj, x, y, val)
347 #endif
349 #if USE_FAST_DRAWPIXEL
350 static inline void DRAWPIXEL(OOP_Class *cl, OOP_Object *o, OOP_Object *gc, WORD x, WORD y)
352 struct pHidd_BitMap_DrawPixel draw_p;
354 draw_p.mID = HiddBitMapBase + moHidd_BitMap_DrawPixel;
355 draw_p.gc = gc;
356 draw_p.x = x;
357 draw_p.y = y;
359 HBM(o)->drawpixel(HBM(o)->drawpixel_Class, o, &draw_p.mID);
361 #else
362 #define DRAWPIXEL(cl, obj, gc, x, y) HIDD_BM_PutPixel(obj, gc, x, y)
363 #endif
365 #endif /* GRAPHICS_HIDD_INTERN_H */