Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / hidds / graphics / graphics_intern.h
blob64a678dde866ab315cef3876bd9f1755ff29eef1
1 /*
2 Copyright © 1995-2008, 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 #ifndef EXEC_LIBRARIES_H
12 # include <exec/libraries.h>
13 #endif
14 #ifndef EXEC_SEMAPHORES_H
15 # include <exec/semaphores.h>
16 #endif
17 #ifndef OOP_OOP_H
18 # include <oop/oop.h>
19 #endif
20 #ifndef HIDD_GRAPHICS_H
21 # include <hidd/graphics.h>
22 #endif
23 #include <dos/dos.h>
26 #define USE_FAST_PUTPIXEL 1
27 #define OPTIMIZE_DRAWPIXEL_FOR_COPY 1
28 #define USE_FAST_DRAWPIXEL 1
29 #define USE_FAST_GETPIXEL 1
30 #define COPYBOX_CHECK_FOR_ALIKE_PIXFMT 1
32 #define HBM(x) ((struct HIDDBitMapData *)x)
34 #define PUTPIXEL(o, msg) \
35 HBM(o)->putpixel(OOP_OCLASS(o), o, msg)
37 #define GETPIXEL(o, msg) \
38 HBM(o)->getpixel(OOP_OCLASS(o), o, msg)
40 #define DRAWPIXEL(o, msg) \
41 HBM(o)->drawpixel(OOP_OCLASS(o), o, msg)
43 #define GOT_PF_ATTR(code) GOT_ATTR(code, aoHidd_PixFmt, pixfmt)
44 #define FOUND_PF_ATTR(code) FOUND_ATTR(code, aoHidd_PixFmt, pixfmt);
46 #define GOT_SYNC_ATTR(code) GOT_ATTR(code, aoHidd_Sync, sync)
47 #define FOUND_SYNC_ATTR(code) FOUND_ATTR(code, aoHidd_Sync, sync);
49 #define GOT_BM_ATTR(code) GOT_ATTR(code, aoHidd_BitMap, bitmap)
50 #define FOUND_BM_ATTR(code) FOUND_ATTR(code, aoHidd_BitMap, bitmap);
52 #define SWAPBYTES_WORD(x) ((((x) >> 8) & 0x00FF) | (((x) & 0x00FF) << 8))
54 struct colormap_data
56 HIDDT_ColorLUT clut;
59 struct pixfmt_data
61 HIDDT_PixelFormat pf;
64 struct planarbm_data
66 UBYTE **planes;
67 ULONG planebuf_size;
68 ULONG bytesperrow;
69 ULONG rows;
70 UBYTE depth;
71 BOOL planes_alloced;
74 struct chunkybm_data
76 UBYTE *buffer;
77 ULONG bytesperrow;
78 ULONG bytesperpixel;
81 struct sync_data {
82 ULONG pixtime; /* pixel time in pico seconds */
84 ULONG hdisp;
85 ULONG left_margin;
86 ULONG right_margin;
87 ULONG hsync_length;
89 ULONG vdisp;
90 ULONG upper_margin;
91 ULONG lower_margin;
92 ULONG vsync_length;
94 UBYTE description[32];
98 /* This is the pixfmts DB. */
100 #warning Find a way to optimize searching in the pixfmt database
102 /* Organize the pf db in some other way that makes it quicker to find a certain PF */
104 struct pfnode {
105 struct MinNode node;
106 OOP_Object *pixfmt;
107 ULONG refcount;
110 /* This is used as an alias for both pfnode and ModeNode */
111 struct objectnode {
112 struct MinNode node;
113 OOP_Object *object;
114 ULONG refcount;
118 struct mode_bm {
119 UBYTE *bm;
120 UWORD bpr;
122 struct mode_db {
123 /* Array of all available gfxmode PixFmts that are part of
124 gfxmodes
126 struct SignalSemaphore sema;
127 OOP_Object **pixfmts;
128 /* Number of pixfmts in the above array */
129 ULONG num_pixfmts;
131 /* All the sync times that are part of any gfxmode */
132 OOP_Object **syncs;
133 /* Number of syncs in the above array */
134 ULONG num_syncs;
136 /* A bitmap of size (num_pixfmts * num_syncs), that tells if the
137 mode is displayable or not. If a particular (x, y) coordinate
138 of the bitmap is 1, it means that the pixfmt and sync objects
139 you get by indexing pixfmts[x] and syncs[y] are a valid mode.
140 If not, the mode is considered invalid
143 struct mode_bm orig_mode_bm; /* Original as supplied by subclass */
144 struct mode_bm checked_mode_bm; /* After applying monitor refresh rate checks etc. */
148 struct HIDDGraphicsData
150 /* Gfx mode "database" */
151 struct mode_db mdb;
155 Pixel format "database". This is a list
156 of all pixelformats currently used bu some bitmap.
157 The point of having this as a central db in the gfx hidd is
158 that if several bitmaps are of the same pixel format
159 they may point to the same PixFmt object instead
160 of allocating their own instance. Thus we are saving mem
162 struct SignalSemaphore pfsema;
163 struct MinList pflist;
165 #if 0
166 /* Software cursor stuff */
167 OOP_Object *curs_bm;
168 BOOL curs_on;
169 ULONG curs_x;
170 ULONG curs_y;
171 OOP_Object *curs_backup;
172 #endif
173 OOP_Object *framebuffer;
175 OOP_Object *shownbm;
177 /* gc used for stuff like rendering cursor */
178 OOP_Object *gc;
180 /* The mode currently used */
181 HIDDT_ModeID curmode;
184 /* Private gfxhidd methods */
185 enum {
186 moHidd_Gfx_RegisterPixFmt = num_Hidd_Gfx_Methods,
187 moHidd_Gfx_ReleasePixFmt
190 struct pHidd_Gfx_RegisterPixFmt {
191 OOP_MethodID mID;
192 struct TagItem *pixFmtTags;
196 struct pHidd_Gfx_ReleasePixFmt {
197 OOP_MethodID mID;
198 OOP_Object *pixFmt;
202 OOP_Object *HIDD_Gfx_RegisterPixFmt(OOP_Object *o, struct TagItem *pixFmtTags);
203 VOID HIDD_Gfx_ReleasePixFmt(OOP_Object *o, OOP_Object *pixFmt);
205 /* Private bitmap methods */
206 enum {
207 moHidd_BitMap_SetBitMapTags = num_Hidd_BitMap_Methods
210 struct pHidd_BitMap_SetBitMapTags {
211 OOP_MethodID mID;
212 struct TagItem *bitMapTags;
215 BOOL HIDD_BitMap_SetBitMapTags(OOP_Object *o, struct TagItem *bitMapTags);
218 struct HIDDBitMapData
220 struct _hidd_bitmap_protected prot;
222 ULONG width; /* width of the bitmap in pixel */
223 ULONG height; /* height of the bitmap in pixel */
224 ULONG reqdepth; /* Depth as requested by user */
225 BOOL displayable; /* bitmap displayable? */
226 BOOL pf_registered;
227 ULONG flags; /* see hidd/graphic.h 'flags for */
228 #if 0
229 ULONG format; /* planar or chunky */
230 ULONG bytesPerRow; /* bytes per row */
231 ULONG bytesPerPixel; /* bytes per pixel */
232 OOP_Object *bitMap;
233 #endif
234 /* WARNING: structure could be extented in the future */
236 OOP_Object *friend; /* Friend bitmap */
238 OOP_Object *gfxhidd;
240 OOP_Object *colmap;
242 HIDDT_ModeID modeid;
245 /* Optimize these two method calls */
246 #if USE_FAST_PUTPIXEL
247 IPTR (*putpixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutPixel *msg);
248 #endif
249 #if USE_FAST_GETPIXEL
250 IPTR (*getpixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_GetPixel *msg);
251 #endif
253 #if USE_FAST_DRAWPIXEL
254 IPTR (*drawpixel)(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_DrawPixel *msg);
255 #endif
261 /* Private bitmap attrs */
263 enum {
264 aoHidd_BitMap_Dummy = num_Hidd_BitMap_Attrs,
266 num_Total_BitMap_Attrs
272 #if 0
273 struct HIDDGCData
275 #if 0
276 APTR bitMap; /* bitmap to which this gc is connected */
277 #endif
278 APTR userData; /* pointer to own data */
279 ULONG fg; /* foreground color */
280 ULONG bg; /* background color */
281 ULONG drMode; /* drawmode */
282 /* WARNING: type of font could be change */
283 APTR font; /* current fonts */
284 ULONG colMask; /* ColorMask prevents some color bits from changing */
285 UWORD linePat; /* LinePattern */
286 APTR planeMask; /* Pointer to a shape bitMap */
287 ULONG colExp;
289 /* WARNING: structure could be extented in the future */
291 #endif
294 struct class_static_data
296 struct Library * utilitybase;
298 OOP_AttrBase hiddPixFmtAttrBase;
299 OOP_AttrBase hiddBitMapAttrBase;
300 OOP_AttrBase hiddGfxAttrBase;
301 OOP_AttrBase hiddSyncAttrBase;
302 OOP_AttrBase hiddGCAttrBase;
303 OOP_AttrBase hiddColorMapAttrBase;
304 OOP_AttrBase hiddPlanarBMAttrBase;
306 OOP_Class *gfxhiddclass; /* graphics hidd class */
307 OOP_Class *bitmapclass; /* bitmap class */
308 OOP_Class *gcclass; /* graphics context class */
309 OOP_Class *colormapclass; /* colormap class */
311 OOP_Class *pixfmtclass; /* descring bitmap pixel formats */
312 OOP_Class *syncclass; /* describing gfxmode sync times */
315 OOP_Class *planarbmclass;
316 OOP_Class *chunkybmclass;
318 OOP_Object *std_pixfmts[num_Hidd_StdPixFmt];
320 /* Thes calls are optimized by calling the method functions directly */
321 #if USE_FAST_PUTPIXEL
322 OOP_MethodID putpixel_mid;
323 #endif
324 #if USE_FAST_GETPIXEL
325 OOP_MethodID getpixel_mid;
326 #endif
327 #if USE_FAST_DRAWPIXEL
328 OOP_MethodID drawpixel_mid;
329 #endif
330 HIDDT_RGBConversionFunction rgbconvertfuncs[NUM_RGB_STDPIXFMT][NUM_RGB_STDPIXFMT];
331 struct SignalSemaphore rgbconvertfuncs_sem;
334 #define __IHidd_PixFmt (csd->hiddPixFmtAttrBase)
335 #define __IHidd_BitMap (csd->hiddBitMapAttrBase)
336 #define __IHidd_Gfx (csd->hiddGfxAttrBase)
337 #define __IHidd_Sync (csd->hiddSyncAttrBase)
338 #define __IHidd_GC (csd->hiddGCAttrBase)
339 #define __IHidd_ColorMap (csd->hiddColorMapAttrBase)
340 #define __IHidd_PlanarBM (csd->hiddPlanarBMAttrBase)
342 /* Library base */
344 struct IntHIDDGraphicsBase
346 struct Library hdg_LibNode;
348 struct class_static_data hdg_csd;
352 /* pre declarations */
354 inline HIDDT_Pixel int_map_truecolor(HIDDT_Color *color, HIDDT_PixelFormat *pf);
355 BOOL parse_pixfmt_tags(struct TagItem *tags, HIDDT_PixelFormat *pf, ULONG attrcheck, struct class_static_data *csd);
356 BOOL parse_sync_tags(struct TagItem *tags, struct sync_data *data, ULONG attrcheck, struct class_static_data *csd);
359 #define CSD(x) (&((struct IntHIDDGraphicsBase *)x->UserData)->hdg_csd)
360 #define csd CSD(cl)
362 #endif /* GRAPHICS_HIDD_INTERN_H */