2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
6 #ifndef GRAPHICS_HIDD_INTERN_H
7 #define GRAPHICS_HIDD_INTERN_H
11 #include <aros/debug.h>
12 #include <exec/libraries.h>
13 #include <exec/semaphores.h>
15 #include <hidd/graphics.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))
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)))
58 struct BitMap
*bitmap
; /* Associated BitMap structure */
59 BOOL planes_alloced
; /* Whether the BitMap was allocated by us */
64 OOP_Object
*gfxhidd
; /* Cached driver object */
65 UBYTE
*buffer
; /* Pixelbuffer */
66 ULONG bytesperrow
; /* Cached for faster access */
68 BOOL own_buffer
; /* Whether the buffer was allocated by us */
73 struct MonitorSpec
*mspc
; /* Associated MonitorSpec */
75 ULONG pixelclock
; /* pixel time in Hz */
77 ULONG hdisp
; /* Data missing from MonitorSpec */
81 ULONG flags
; /* Flags */
83 UBYTE description
[32];
85 ULONG hmin
; /* Minimum and maximum allowed bitmap size */
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 */
101 HIDDT_GC_Intern prot
;
110 /* Array of all available gfxmode PixFmts that are part of
113 struct SignalSemaphore sema
;
114 OOP_Object
**pixfmts
;
115 /* Number of pixfmts in the above array */
118 /* All the sync times that are part of any gfxmode */
120 /* Number of syncs in the above array */
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" */
140 /* Framebuffer control stuff */
141 OOP_Object
*framebuffer
;
144 /* gc used for stuff like rendering cursor */
147 /* The mode currently used (obsolete ?)
148 HIDDT_ModeID curmode; */
151 /* Private gfxhidd methods */
152 OOP_Object
*GFX__Hidd_Gfx__RegisterPixFmt(OOP_Class
*cl
, struct TagItem
*pixFmtTags
);
153 VOID
GFX__Hidd_Gfx__ReleasePixFmt(OOP_Class
*cl
, OOP_Object
*pf
);
155 /* Private bitmap methods */
156 void BM__Hidd_BitMap__SetBitMapTags(OOP_Class
*cl
, OOP_Object
*o
, struct TagItem
*bitMapTags
);
157 void BM__Hidd_BitMap__SetPixFmt(OOP_Class
*cl
, OOP_Object
*o
, OOP_Object
*pf
);
159 struct HIDDBitMapData
161 struct _hidd_bitmap_protected prot
;
163 UWORD width
; /* width of the bitmap in pixel */
164 UWORD height
; /* height of the bitmap in pixel */
165 UWORD align
; /* Default alignment */
166 BOOL displayable
; /* bitmap displayable? */
167 BOOL framebuffer
; /* is a framebuffer ? */
168 BOOL pf_registered
; /* Registered own pixelformat ? */
169 ULONG flags
; /* see hidd/graphic.h 'flags for */
170 ULONG bytesPerRow
; /* bytes per row */
171 OOP_Object
*friend; /* Friend bitmap */
172 OOP_Object
*gfxhidd
; /* Owning driver */
173 OOP_Object
*colmap
; /* Colormap */
174 OOP_Object
*gc
; /* Shared GC for copy operations */
175 HIDDT_ModeID modeid
; /* Display mode ID */
177 /* Optimize these method calls */
178 #if USE_FAST_PUTPIXEL
179 OOP_MethodFunc putpixel
;
180 OOP_Class
*putpixel_Class
;
182 #if USE_FAST_GETPIXEL
183 OOP_MethodFunc getpixel
;
184 OOP_Class
*getpixel_Class
;
186 #if USE_FAST_DRAWPIXEL
187 OOP_MethodFunc drawpixel
;
188 OOP_Class
*drawpixel_Class
;
192 #define NUM_ATTRBASES 9
193 #define NUM_METHODBASES 4
195 struct class_static_data
197 struct GfxBase
*cs_GfxBase
;
198 struct Library
*cs_UtilityBase
;
199 struct Library
*cs_OOPBase
;
202 struct SignalSemaphore sema
;
204 OOP_AttrBase attrBases
[NUM_ATTRBASES
];
205 OOP_MethodID methodBases
[NUM_METHODBASES
];
207 OOP_Class
*gfxhiddclass
; /* graphics hidd class */
208 OOP_Class
*bitmapclass
; /* bitmap class */
209 OOP_Class
*gcclass
; /* graphics context class */
210 OOP_Class
*colormapclass
; /* colormap class */
212 OOP_Class
*pixfmtclass
; /* describing bitmap pixel formats */
213 OOP_Class
*syncclass
; /* describing gfxmode sync times */
216 OOP_Class
*planarbmclass
;
217 OOP_Class
*chunkybmclass
;
220 Pixel format "database". This is a list
221 of all pixelformats currently used bu some bitmap.
222 The point of having this as a central db in the gfx hidd is
223 that if several bitmaps are of the same pixel format
224 they may point to the same PixFmt object instead
225 of allocating their own instance. Thus we are saving mem
227 struct SignalSemaphore pfsema
;
228 struct MinList pflist
;
229 /* Index of standard pixelformats for quick access */
230 HIDDT_PixelFormat
*std_pixfmts
[num_Hidd_StdPixFmt
];
232 HIDDT_RGBConversionFunction rgbconvertfuncs
[NUM_RGB_STDPIXFMT
][NUM_RGB_STDPIXFMT
];
233 struct SignalSemaphore rgbconvertfuncs_sem
;
236 #define __IHidd_BitMap (csd->attrBases[0])
237 #define __IHidd_Gfx (csd->attrBases[1])
238 #define __IHidd_GC (csd->attrBases[2])
239 #define __IHidd_ColorMap (csd->attrBases[3])
240 #define __IHidd_Overlay (csd->attrBases[4])
241 #define __IHidd_Sync (csd->attrBases[5])
242 #define __IHidd_PixFmt (csd->attrBases[6])
243 #define __IHidd_PlanarBM (csd->attrBases[7])
244 #define __IHidd_ChunkyBM (csd->attrBases[8])
247 #undef HiddBitMapBase
248 #undef HiddColorMapBase
250 #define HiddBitMapBase (csd->methodBases[0])
251 #define HiddGfxBase (csd->methodBases[1])
252 #define HiddGCBase (csd->methodBases[2])
253 #define HiddColorMapBase (csd->methodBases[3])
257 struct IntHIDDGraphicsBase
259 struct Library hdg_LibNode
;
261 struct class_static_data hdg_csd
;
265 /* pre declarations */
267 BOOL
parse_pixfmt_tags(struct TagItem
*tags
, HIDDT_PixelFormat
*pf
, ULONG attrcheck
, struct class_static_data
*csd
);
269 static inline ULONG
color_distance(UWORD a1
, UWORD r1
, UWORD g1
, UWORD b1
, UWORD a2
, UWORD r2
, UWORD g2
, UWORD b2
)
271 /* NOTE: The use of 'WORD' here and the 'UWORD' casts below are
272 * important hints to GCC to generate better code on m68k
274 WORD da
= (a1
>> 8) - (a2
>> 8);
275 WORD dr
= (r1
>> 8) - (r2
>> 8);
276 WORD dg
= (g1
>> 8) - (g2
>> 8);
277 WORD db
= (b1
>> 8) - (b2
>> 8);
279 DB2(bug("[color_distance] a1 = 0x%04X a2 = 0x%04X da = %d\n", a1
, a2
, da
));
280 DB2(bug("[color_distance] r1 = 0x%04X r2 = 0x%04X dr = %d\n", r1
, r2
, dr
));
281 DB2(bug("[color_distance] g1 = 0x%04X g2 = 0x%04X dg = %d\n", g1
, g2
, dg
));
282 DB2(bug("[color_distance] b1 = 0x%04X b2 = 0x%04X db = %d\n", b1
, b2
, db
));
284 /* '4' here is a result of trial and error. The idea behind this is to increase
285 the weight of alpha difference in order to make the function prefer colors with
286 the same alpha value. This is important for correct mouse pointer remapping. */
287 return (UWORD
)(da
*da
)*4 + (UWORD
)(dr
*dr
) + (UWORD
)(dg
*dg
) + (UWORD
)(db
*db
);
290 #define CSD(x) (&((struct IntHIDDGraphicsBase *)x->UserData)->hdg_csd)
293 /* The following calls are optimized by calling the method functions directly */
295 #if USE_FAST_GETPIXEL
296 static inline HIDDT_Pixel
GETPIXEL(OOP_Class
*cl
, OOP_Object
*o
, WORD x
, WORD y
)
298 struct pHidd_BitMap_GetPixel get_p
;
300 get_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_GetPixel
;
304 return HBM(o
)->getpixel(HBM(o
)->getpixel_Class
, o
, &get_p
.mID
);
307 #define GETPIXEL(cl, obj, x, y) HIDD_BM_GetPixel(obj, x, y)
310 #if USE_FAST_PUTPIXEL
311 static inline void PUTPIXEL(OOP_Class
*cl
, OOP_Object
*o
, WORD x
, WORD y
, HIDDT_Pixel val
)
313 struct pHidd_BitMap_PutPixel put_p
;
315 put_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_PutPixel
;
320 HBM(o
)->putpixel(HBM(o
)->putpixel_Class
, o
, &put_p
.mID
);
323 #define PUTPIXEL(cl, obj, x, y, val) HIDD_BM_PutPixel(obj, x, y, val)
326 #if USE_FAST_DRAWPIXEL
327 static inline void DRAWPIXEL(OOP_Class
*cl
, OOP_Object
*o
, OOP_Object
*gc
, WORD x
, WORD y
)
329 struct pHidd_BitMap_DrawPixel draw_p
;
331 draw_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_DrawPixel
;
336 HBM(o
)->drawpixel(HBM(o
)->drawpixel_Class
, o
, &draw_p
.mID
);
339 #define DRAWPIXEL(cl, obj, gc, x, y) HIDD_BM_PutPixel(obj, gc, x, y)
342 #endif /* GRAPHICS_HIDD_INTERN_H */