grub2: bring back build of aros-side grub2 tools
[AROS.git] / rom / hidds / graphics / graphics_intern.h
blob9b161e764ce9727ac51ad0148ab67000fec7496d
1 /*
2 Copyright © 1995-2015, 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 struct BitMap *bitmap; /* Associated BitMap structure */
59 BOOL planes_alloced; /* Whether the BitMap was allocated by us */
62 struct chunkybm_data
64 OOP_Object *gfxhidd; /* Cached driver object */
65 UBYTE *buffer; /* Pixelbuffer */
66 ULONG bytesperrow; /* Cached for faster access */
67 UWORD bytesperpixel;
68 BOOL own_buffer; /* Whether the buffer was allocated by us */
71 struct sync_data
73 struct MonitorSpec *mspc; /* Associated MonitorSpec */
75 ULONG pixelclock; /* pixel time in Hz */
77 ULONG hdisp; /* Data missing from MonitorSpec */
78 ULONG htotal;
79 ULONG vdisp;
81 ULONG flags; /* Flags */
83 UBYTE description[32];
85 ULONG hmin; /* Minimum and maximum allowed bitmap size */
86 ULONG hmax;
87 ULONG vmin;
88 ULONG vmax;
90 OOP_Object *gfxhidd; /* Graphics driver that owns this sync */
91 ULONG InternalFlags; /* Internal flags, see below */
94 /* Sync internal flags */
95 #define SYNC_FREE_MONITORSPEC 0x0001 /* Allocated own MonitorSpec */
96 #define SYNC_FREE_SPECIALMONITOR 0x0002 /* Allocated own SpecialMonitor */
97 #define SYNC_VARIABLE 0x0004 /* Signal timings can be changed */
99 struct gc_data
101 HIDDT_GC_Intern prot;
102 struct Rectangle cr;
105 struct mode_bm {
106 UBYTE *bm;
107 UWORD bpr;
109 struct mode_db {
110 /* Array of all available gfxmode PixFmts that are part of
111 gfxmodes
113 struct SignalSemaphore sema;
114 OOP_Object **pixfmts;
115 /* Number of pixfmts in the above array */
116 ULONG num_pixfmts;
118 /* All the sync times that are part of any gfxmode */
119 OOP_Object **syncs;
120 /* Number of syncs in the above array */
121 ULONG num_syncs;
123 /* A bitmap of size (num_pixfmts * num_syncs), that tells if the
124 mode is displayable or not. If a particular (x, y) coordinate
125 of the bitmap is 1, it means that the pixfmt and sync objects
126 you get by indexing pixfmts[x] and syncs[y] are a valid mode.
127 If not, the mode is considered invalid
130 struct mode_bm orig_mode_bm; /* Original as supplied by subclass */
131 struct mode_bm checked_mode_bm; /* After applying monitor refresh rate checks etc. */
135 struct HIDDGraphicsData
137 /* Gfx mode "database" */
138 struct mode_db mdb;
140 /* Framebuffer control stuff */
141 OOP_Object *framebuffer;
142 OOP_Object *shownbm;
143 BYTE fbmode;
144 struct SignalSemaphore fbsem;
146 /* gc used for stuff like rendering cursor */
147 OOP_Object *gc;
150 /* Private gfxhidd methods */
151 OOP_Object *GFX__Hidd_Gfx__RegisterPixFmt(OOP_Class *cl, struct TagItem *pixFmtTags);
152 VOID GFX__Hidd_Gfx__ReleasePixFmt(OOP_Class *cl, OOP_Object *pf);
154 static inline BOOL GFX__Hidd_Gfx__SetFBColors(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_SetColors *msg)
156 struct HIDDGraphicsData *data = OOP_INST_DATA(cl, o);
158 return OOP_DoMethod(data->framebuffer, &msg->mID);
161 static inline UBYTE GFX__Hidd_Gfx__GetFBModeQuick(OOP_Class *cl, OOP_Object *o)
163 struct HIDDGraphicsData *data = OOP_INST_DATA(cl, o);
165 return data->fbmode;
168 /* This has to be a #define, otherwise the HIDD_Gfx_CopyBox()
169 * macro won't expand the HiddGfxBase macro to the csd
170 * structure.
172 #define GFX__Hidd_Gfx__UpdateFB(cl, o, bm, srcX, srcY, destX, destY, xSize, ySize) \
173 do { \
174 struct HIDDGraphicsData *__data = OOP_INST_DATA(cl, o); \
175 HIDD_Gfx_CopyBox(o, bm, srcX, srcY, \
176 __data->framebuffer, destX, destY, \
177 xSize, ySize, __data->gc); \
178 } while (0)
180 /* Private bitmap methods */
181 void BM__Hidd_BitMap__SetBitMapTags(OOP_Class *cl, OOP_Object *o, struct TagItem *bitMapTags);
182 void BM__Hidd_BitMap__SetPixFmt(OOP_Class *cl, OOP_Object *o, OOP_Object *pf);
183 void BM__Hidd_BitMap__SetVisible(OOP_Class *cl, OOP_Object *o, BOOL val);
185 struct HIDDBitMapData
187 struct _hidd_bitmap_protected prot;
189 struct BitMap *bmstruct;
190 UWORD width; /* width of the bitmap in pixel */
191 UWORD height; /* height of the bitmap in pixel */
192 UWORD align; /* Default alignment */
193 IPTR displayWidth; /* Display size */
194 IPTR displayHeight;
195 struct Rectangle display; /* Display rectangle (in bitmap's coordinates !) */
196 struct SignalSemaphore lock; /* Scroll/update semaphore */
197 BOOL visible; /* bitmap visible ? */
198 BOOL displayable; /* bitmap directly displayable? */
199 BOOL compositable; /* bitmap displayable via compositor */
200 BOOL framebuffer; /* is a framebuffer ? */
201 BOOL pf_registered; /* Registered own pixelformat ? */
202 ULONG flags; /* see hidd/graphic.h 'flags for */
203 ULONG bytesPerRow; /* bytes per row */
204 OOP_Object *friend; /* Friend bitmap */
205 OOP_Object *gfxhidd; /* Owning driver */
206 OOP_Object *colmap; /* Colormap */
207 OOP_Object *gc; /* Shared GC for copy operations */
208 HIDDT_ModeID modeid; /* Display mode ID */
210 /* Optimize these method calls */
211 #if USE_FAST_PUTPIXEL
212 OOP_MethodFunc putpixel;
213 OOP_Class *putpixel_Class;
214 #endif
215 #if USE_FAST_GETPIXEL
216 OOP_MethodFunc getpixel;
217 OOP_Class *getpixel_Class;
218 #endif
219 #if USE_FAST_DRAWPIXEL
220 OOP_MethodFunc drawpixel;
221 OOP_Class *drawpixel_Class;
222 #endif
225 #define NUM_ATTRBASES 9
226 #define NUM_METHODBASES 4
228 struct class_static_data
230 struct GfxBase *cs_GfxBase;
231 struct Library *cs_UtilityBase;
232 struct Library *cs_OOPBase;
233 BPTR cs_SegList;
235 struct SignalSemaphore sema;
237 OOP_AttrBase attrBases[NUM_ATTRBASES];
238 OOP_MethodID methodBases[NUM_METHODBASES];
240 OOP_Class *gfxhiddclass; /* graphics hidd class */
241 OOP_Class *bitmapclass; /* bitmap class */
242 OOP_Class *gcclass; /* graphics context class */
243 OOP_Class *colormapclass; /* colormap class */
245 OOP_Class *pixfmtclass; /* describing bitmap pixel formats */
246 OOP_Class *syncclass; /* describing gfxmode sync times */
249 OOP_Class *planarbmclass;
250 OOP_Class *chunkybmclass;
253 Pixel format "database". This is a list
254 of all pixelformats currently used by some bitmap.
255 The point of having this as a central db in the gfx hidd is
256 that if several bitmaps are of the same pixel format
257 they may point to the same PixFmt object instead
258 of allocating their own instance. Thus we are saving mem
260 struct SignalSemaphore pfsema;
261 struct MinList pflist;
262 /* Index of standard pixelformats for quick access */
263 HIDDT_PixelFormat *std_pixfmts[num_Hidd_StdPixFmt];
265 HIDDT_RGBConversionFunction rgbconvertfuncs[NUM_RGB_STDPIXFMT][NUM_RGB_STDPIXFMT];
266 struct SignalSemaphore rgbconvertfuncs_sem;
269 #define __IHidd_BitMap (csd->attrBases[0])
270 #define __IHidd_Gfx (csd->attrBases[1])
271 #define __IHidd_GC (csd->attrBases[2])
272 #define __IHidd_ColorMap (csd->attrBases[3])
273 #define __IHidd_Overlay (csd->attrBases[4])
274 #define __IHidd_Sync (csd->attrBases[5])
275 #define __IHidd_PixFmt (csd->attrBases[6])
276 #define __IHidd_PlanarBM (csd->attrBases[7])
277 #define __IHidd_ChunkyBM (csd->attrBases[8])
279 #undef HiddGfxBase
280 #undef HiddBitMapBase
281 #undef HiddColorMapBase
282 #undef HiddGCBase
283 #define HiddBitMapBase (csd->methodBases[0])
284 #define HiddGfxBase (csd->methodBases[1])
285 #define HiddGCBase (csd->methodBases[2])
286 #define HiddColorMapBase (csd->methodBases[3])
288 /* Library base */
290 struct IntHIDDGraphicsBase
292 struct Library hdg_LibNode;
294 struct class_static_data hdg_csd;
298 /* pre declarations */
300 BOOL parse_pixfmt_tags(struct TagItem *tags, HIDDT_PixelFormat *pf, ULONG attrcheck, struct class_static_data *csd);
302 static inline ULONG color_distance(UWORD a1, UWORD r1, UWORD g1, UWORD b1, UWORD a2, UWORD r2, UWORD g2, UWORD b2)
304 /* NOTE: The use of 'WORD' here and the 'UWORD' casts below are
305 * important hints to GCC to generate better code on m68k
307 WORD da = (a1 >> 8) - (a2 >> 8);
308 WORD dr = (r1 >> 8) - (r2 >> 8);
309 WORD dg = (g1 >> 8) - (g2 >> 8);
310 WORD db = (b1 >> 8) - (b2 >> 8);
312 DB2(bug("[color_distance] a1 = 0x%04X a2 = 0x%04X da = %d\n", a1, a2, da));
313 DB2(bug("[color_distance] r1 = 0x%04X r2 = 0x%04X dr = %d\n", r1, r2, dr));
314 DB2(bug("[color_distance] g1 = 0x%04X g2 = 0x%04X dg = %d\n", g1, g2, dg));
315 DB2(bug("[color_distance] b1 = 0x%04X b2 = 0x%04X db = %d\n", b1, b2, db));
317 /* '4' here is a result of trial and error. The idea behind this is to increase
318 the weight of alpha difference in order to make the function prefer colors with
319 the same alpha value. This is important for correct mouse pointer remapping. */
320 return (UWORD)(da*da)*4 + (UWORD)(dr*dr) + (UWORD)(dg*dg) + (UWORD)(db*db);
323 #define CSD(x) (&((struct IntHIDDGraphicsBase *)x->UserData)->hdg_csd)
324 #define csd CSD(cl)
326 /* The following calls are optimized by calling the method functions directly */
328 #if USE_FAST_GETPIXEL
329 static inline HIDDT_Pixel GETPIXEL(OOP_Class *cl, OOP_Object *o, WORD x, WORD y)
331 struct pHidd_BitMap_GetPixel get_p;
333 get_p.mID = HiddBitMapBase + moHidd_BitMap_GetPixel;
334 get_p.x = x;
335 get_p.y = y;
337 return HBM(o)->getpixel(HBM(o)->getpixel_Class, o, &get_p.mID);
339 #else
340 #define GETPIXEL(cl, obj, x, y) HIDD_BM_GetPixel(obj, x, y)
341 #endif
343 #if USE_FAST_PUTPIXEL
344 static inline void PUTPIXEL(OOP_Class *cl, OOP_Object *o, WORD x, WORD y, HIDDT_Pixel val)
346 struct pHidd_BitMap_PutPixel put_p;
348 put_p.mID = HiddBitMapBase + moHidd_BitMap_PutPixel;
349 put_p.x = x;
350 put_p.y = y;
351 put_p.pixel = val;
353 HBM(o)->putpixel(HBM(o)->putpixel_Class, o, &put_p.mID);
355 #else
356 #define PUTPIXEL(cl, obj, x, y, val) HIDD_BM_PutPixel(obj, x, y, val)
357 #endif
359 #if USE_FAST_DRAWPIXEL
360 static inline void DRAWPIXEL(OOP_Class *cl, OOP_Object *o, OOP_Object *gc, WORD x, WORD y)
362 struct pHidd_BitMap_DrawPixel draw_p;
364 draw_p.mID = HiddBitMapBase + moHidd_BitMap_DrawPixel;
365 draw_p.gc = gc;
366 draw_p.x = x;
367 draw_p.y = y;
369 HBM(o)->drawpixel(HBM(o)->drawpixel_Class, o, &draw_p.mID);
371 #else
372 #define DRAWPIXEL(cl, obj, gc, x, y) HIDD_BM_PutPixel(obj, gc, x, y)
373 #endif
375 #endif /* GRAPHICS_HIDD_INTERN_H */