2 Copyright © 1995-2017, The AROS Development Team. All rights reserved.
6 #ifndef GFX_HIDD_INTERN_H
7 #define GFX_HIDD_INTERN_H
11 #include <aros/debug.h>
12 #include <exec/libraries.h>
13 #include <exec/semaphores.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
31 #define HBM(x) ((struct HIDDBitMapData *)x)
33 #define GOT_PF_ATTR(code) GOT_ATTR(code, aoHidd_PixFmt, pixfmt)
34 #define FOUND_PF_ATTR(code) FOUND_ATTR(code, aoHidd_PixFmt, pixfmt);
36 #define GOT_SYNC_ATTR(code) GOT_ATTR(code, aoHidd_Sync, sync)
37 #define FOUND_SYNC_ATTR(code) FOUND_ATTR(code, aoHidd_Sync, sync);
39 #define GOT_BM_ATTR(code) GOT_ATTR(code, aoHidd_BitMap, bitmap)
40 #define FOUND_BM_ATTR(code) FOUND_ATTR(code, aoHidd_BitMap, bitmap);
42 #define SWAPBYTES_WORD(x) ((((x) >> 8) & 0x00FF) | (((x) & 0x00FF) << 8))
51 HIDDT_PixelFormat pf
; /* Public portion in the beginning */
53 struct MinNode node
; /* Node for linking into the database */
54 ULONG refcount
; /* Reference count */
57 /* Use this macro in order to transform node pointer to pixfmt pointer */
58 #define PIXFMT_OBJ(n) ((HIDDT_PixelFormat *)((char *)(n) - offsetof(struct pixfmt_data, node)))
62 struct BitMap
*bitmap
; /* Associated BitMap structure */
63 BOOL planes_alloced
; /* Whether the BitMap was allocated by us */
68 OOP_Object
*gfxhidd
; /* Cached driver object */
69 UBYTE
*buffer
; /* Pixelbuffer */
70 ULONG bytesperrow
; /* Cached for faster access */
72 BOOL own_buffer
; /* Whether the buffer was allocated by us */
77 struct MonitorSpec
*mspc
; /* Associated MonitorSpec */
79 ULONG pixelclock
; /* pixel time in Hz */
81 ULONG hdisp
; /* Data missing from MonitorSpec */
85 ULONG flags
; /* Flags */
87 UBYTE description
[32];
89 ULONG hmin
; /* Minimum and maximum allowed bitmap size */
94 OOP_Object
*gfxhidd
; /* Graphics driver that owns this sync */
95 ULONG InternalFlags
; /* Internal flags, see below */
98 /* Sync internal flags */
99 #define SYNC_FREE_MONITORSPEC 0x0001 /* Allocated own MonitorSpec */
100 #define SYNC_FREE_SPECIALMONITOR 0x0002 /* Allocated own SpecialMonitor */
101 #define SYNC_VARIABLE 0x0004 /* Signal timings can be changed */
105 HIDDT_GC_Intern prot
;
114 /* Array of all available gfxmode PixFmts that are part of
117 struct SignalSemaphore sema
;
118 OOP_Object
**pixfmts
;
119 /* Number of pixfmts in the above array */
122 /* All the sync times that are part of any gfxmode */
124 /* Number of syncs in the above array */
127 /* A bitmap of size (num_pixfmts * num_syncs), that tells if the
128 mode is displayable or not. If a particular (x, y) coordinate
129 of the bitmap is 1, it means that the pixfmt and sync objects
130 you get by indexing pixfmts[x] and syncs[y] are a valid mode.
131 If not, the mode is considered invalid
134 struct mode_bm orig_mode_bm
; /* Original as supplied by subclass */
135 struct mode_bm checked_mode_bm
; /* After applying monitor refresh rate checks etc. */
141 /* Gfx mode "database" */
144 /* Framebuffer control stuff */
145 OOP_Object
*framebuffer
;
148 struct SignalSemaphore fbsem
;
150 /* gc used for stuff like rendering cursor */
154 /* Private gfxhidd methods */
155 OOP_Object
*GFXHIDD__Hidd_Gfx__RegisterPixFmt(OOP_Class
*cl
, struct TagItem
*pixFmtTags
);
156 VOID
GFXHIDD__Hidd_Gfx__ReleasePixFmt(OOP_Class
*cl
, OOP_Object
*pf
);
158 static inline BOOL
GFXHIDD__Hidd_Gfx__SetFBColors(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_SetColors
*msg
)
160 struct HiddGfxData
*data
= OOP_INST_DATA(cl
, o
);
162 return OOP_DoMethod(data
->framebuffer
, &msg
->mID
);
165 static inline UBYTE
GFXHIDD__Hidd_Gfx__GetFBModeQuick(OOP_Class
*cl
, OOP_Object
*o
)
167 struct HiddGfxData
*data
= OOP_INST_DATA(cl
, o
);
172 /* This has to be a #define, otherwise the HIDD_Gfx_CopyBox()
173 * macro won't expand the HiddGfxBase macro to the csd
176 #define GFXHIDD__Hidd_Gfx__UpdateFB(cl, o, bm, srcX, srcY, destX, destY, xSize, ySize) \
178 struct HiddGfxData *__data = OOP_INST_DATA(cl, o); \
179 HIDD_Gfx_CopyBox(o, bm, srcX, srcY, \
180 __data->framebuffer, destX, destY, \
181 xSize, ySize, __data->gc); \
184 /* Private bitmap methods */
185 void BM__Hidd_BitMap__SetBitMapTags(OOP_Class
*cl
, OOP_Object
*o
, struct TagItem
*bitMapTags
);
186 void BM__Hidd_BitMap__SetPixFmt(OOP_Class
*cl
, OOP_Object
*o
, OOP_Object
*pf
);
187 void BM__Hidd_BitMap__SetVisible(OOP_Class
*cl
, OOP_Object
*o
, BOOL val
);
189 struct HIDDBitMapData
191 struct _hidd_bitmap_protected prot
;
193 struct BitMap
*bmstruct
;
194 UWORD width
; /* width of the bitmap in pixel */
195 UWORD height
; /* height of the bitmap in pixel */
196 UWORD align
; /* Default alignment */
197 IPTR displayWidth
; /* Display size */
199 struct Rectangle display
; /* Display rectangle (in bitmap's coordinates !) */
200 struct SignalSemaphore lock
; /* Scroll/update semaphore */
201 BOOL visible
; /* bitmap visible ? */
202 BOOL displayable
; /* bitmap directly displayable? */
203 BOOL compositable
; /* bitmap displayable via compositor */
204 BOOL framebuffer
; /* is a framebuffer ? */
205 BOOL pf_registered
; /* Registered own pixelformat ? */
206 ULONG flags
; /* see hidd/graphic.h 'flags for */
207 ULONG bytesPerRow
; /* bytes per row */
208 OOP_Object
*friend; /* Friend bitmap */
209 OOP_Object
*gfxhidd
; /* Owning driver */
210 OOP_Object
*colmap
; /* Colormap */
211 OOP_Object
*gc
; /* Shared GC for copy operations */
212 HIDDT_ModeID modeid
; /* Display mode ID */
214 /* Optimize these method calls */
215 #if USE_FAST_PUTPIXEL
216 OOP_MethodFunc putpixel
;
217 OOP_Class
*putpixel_Class
;
219 #if USE_FAST_GETPIXEL
220 OOP_MethodFunc getpixel
;
221 OOP_Class
*getpixel_Class
;
223 #if USE_FAST_DRAWPIXEL
224 OOP_MethodFunc drawpixel
;
225 OOP_Class
*drawpixel_Class
;
229 #define NUM_ATTRBASES 11
230 #define NUM_METHODBASES 5
232 struct class_static_data
234 struct GfxBase
*cs_GfxBase
;
235 struct Library
*cs_UtilityBase
;
236 struct Library
*cs_OOPBase
;
239 struct SignalSemaphore sema
;
241 OOP_AttrBase attrBases
[NUM_ATTRBASES
];
242 OOP_MethodID methodBases
[NUM_METHODBASES
];
244 OOP_Class
*gfxhwclass
; /* graphics hw enumerator class */
245 OOP_Class
*gfxhiddclass
; /* graphics hidd class */
246 OOP_Class
*bitmapclass
; /* bitmap class */
247 OOP_Class
*gcclass
; /* graphics context class */
248 OOP_Class
*colormapclass
; /* colormap class */
250 OOP_Class
*pixfmtclass
; /* describing bitmap pixel formats */
251 OOP_Class
*syncclass
; /* describing gfxmode sync times */
253 OOP_Class
*planarbmclass
;
254 OOP_Class
*chunkybmclass
;
256 OOP_Object
*gfxhwinstance
;
259 Pixel format "database". This is a list
260 of all pixelformats currently used by some bitmap.
261 The point of having this as a central db in the gfx hidd is
262 that if several bitmaps are of the same pixel format
263 they may point to the same PixFmt object instead
264 of allocating their own instance. Thus we are saving mem
266 struct SignalSemaphore pfsema
;
267 struct MinList pflist
;
268 /* Index of standard pixelformats for quick access */
269 HIDDT_PixelFormat
*std_pixfmts
[num_Hidd_StdPixFmt
];
271 HIDDT_RGBConversionFunction rgbconvertfuncs
[NUM_RGB_STDPIXFMT
][NUM_RGB_STDPIXFMT
];
272 struct SignalSemaphore rgbconvertfuncs_sem
;
275 #define __IHidd_BitMap (csd->attrBases[0])
276 #define __IHidd_Gfx (csd->attrBases[1])
277 #define __IHidd_GC (csd->attrBases[2])
278 #define __IHidd_ColorMap (csd->attrBases[3])
279 #define __IHW (csd->attrBases[4])
280 #define __IHidd (csd->attrBases[5])
281 #define __IHidd_Overlay (csd->attrBases[6])
282 #define __IHidd_Sync (csd->attrBases[7])
283 #define __IHidd_PixFmt (csd->attrBases[8])
284 #define __IHidd_PlanarBM (csd->attrBases[9])
285 #define __IHidd_ChunkyBM (csd->attrBases[10])
288 #undef HiddBitMapBase
289 #undef HiddColorMapBase
292 #define HiddBitMapBase (csd->methodBases[0])
293 #define HiddGfxBase (csd->methodBases[1])
294 #define HiddGCBase (csd->methodBases[2])
295 #define HiddColorMapBase (csd->methodBases[3])
296 #define HWBase (csd->methodBases[4])
300 struct IntHIDDGraphicsBase
302 struct Library hdg_LibNode
;
304 struct class_static_data hdg_csd
;
308 /* pre declarations */
310 BOOL
parse_pixfmt_tags(struct TagItem
*tags
, HIDDT_PixelFormat
*pf
, ULONG attrcheck
, struct class_static_data
*csd
);
312 static inline ULONG
color_distance(UWORD a1
, UWORD r1
, UWORD g1
, UWORD b1
, UWORD a2
, UWORD r2
, UWORD g2
, UWORD b2
)
314 /* NOTE: The use of 'WORD' here and the 'UWORD' casts below are
315 * important hints to GCC to generate better code on m68k
317 WORD da
= (a1
>> 8) - (a2
>> 8);
318 WORD dr
= (r1
>> 8) - (r2
>> 8);
319 WORD dg
= (g1
>> 8) - (g2
>> 8);
320 WORD db
= (b1
>> 8) - (b2
>> 8);
322 DB2(bug("[color_distance] a1 = 0x%04X a2 = 0x%04X da = %d\n", a1
, a2
, da
));
323 DB2(bug("[color_distance] r1 = 0x%04X r2 = 0x%04X dr = %d\n", r1
, r2
, dr
));
324 DB2(bug("[color_distance] g1 = 0x%04X g2 = 0x%04X dg = %d\n", g1
, g2
, dg
));
325 DB2(bug("[color_distance] b1 = 0x%04X b2 = 0x%04X db = %d\n", b1
, b2
, db
));
327 /* '4' here is a result of trial and error. The idea behind this is to increase
328 the weight of alpha difference in order to make the function prefer colors with
329 the same alpha value. This is important for correct mouse pointer remapping. */
330 return (UWORD
)(da
*da
)*4 + (UWORD
)(dr
*dr
) + (UWORD
)(dg
*dg
) + (UWORD
)(db
*db
);
333 #define CSD(x) (&((struct IntHIDDGraphicsBase *)x->UserData)->hdg_csd)
336 /* The following calls are optimized by calling the method functions directly */
338 #if USE_FAST_GETPIXEL
339 static inline HIDDT_Pixel
GETPIXEL(OOP_Class
*cl
, OOP_Object
*o
, WORD x
, WORD y
)
341 struct pHidd_BitMap_GetPixel get_p
;
343 get_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_GetPixel
;
347 return HBM(o
)->getpixel(HBM(o
)->getpixel_Class
, o
, &get_p
.mID
);
350 #define GETPIXEL(cl, obj, x, y) HIDD_BM_GetPixel(obj, x, y)
353 #if USE_FAST_PUTPIXEL
354 static inline void PUTPIXEL(OOP_Class
*cl
, OOP_Object
*o
, WORD x
, WORD y
, HIDDT_Pixel val
)
356 struct pHidd_BitMap_PutPixel put_p
;
358 put_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_PutPixel
;
363 HBM(o
)->putpixel(HBM(o
)->putpixel_Class
, o
, &put_p
.mID
);
366 #define PUTPIXEL(cl, obj, x, y, val) HIDD_BM_PutPixel(obj, x, y, val)
369 #if USE_FAST_DRAWPIXEL
370 static inline void DRAWPIXEL(OOP_Class
*cl
, OOP_Object
*o
, OOP_Object
*gc
, WORD x
, WORD y
)
372 struct pHidd_BitMap_DrawPixel draw_p
;
374 draw_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_DrawPixel
;
379 HBM(o
)->drawpixel(HBM(o
)->drawpixel_Class
, o
, &draw_p
.mID
);
382 #define DRAWPIXEL(cl, obj, gc, x, y) HIDD_BM_PutPixel(obj, gc, x, y)
385 #endif /* GFX_HIDD_INTERN_H */