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_GETPIXEL 1
22 #define USE_FAST_PUTPIXEL 1
23 #define OPTIMIZE_DRAWPIXEL_FOR_COPY 1
24 #define USE_FAST_DRAWPIXEL 1
25 #define USE_FAST_DRAWLINE 1
26 #define USE_FAST_GETIMAGE 1
27 #define USE_FAST_PUTIMAGE 1
28 #define USE_FAST_CONVERTPIXELS 1
29 #define USE_FAST_UNMAPPIXEL 1
30 #define USE_FAST_MAPCOLOR 1
31 #define COPYBOX_CHECK_FOR_ALIKE_PIXFMT 1
37 #define HBM(x) ((struct HIDDBitMapData *)x)
39 #define GOT_PF_ATTR(code) GOT_ATTR(code, aoHidd_PixFmt, pixfmt)
40 #define FOUND_PF_ATTR(code) FOUND_ATTR(code, aoHidd_PixFmt, pixfmt);
42 #define GOT_SYNC_ATTR(code) GOT_ATTR(code, aoHidd_Sync, sync)
43 #define FOUND_SYNC_ATTR(code) FOUND_ATTR(code, aoHidd_Sync, sync);
45 #define GOT_BM_ATTR(code) GOT_ATTR(code, aoHidd_BitMap, bitmap)
46 #define FOUND_BM_ATTR(code) FOUND_ATTR(code, aoHidd_BitMap, bitmap);
48 #define SWAPBYTES_WORD(x) ((((x) >> 8) & 0x00FF) | (((x) & 0x00FF) << 8))
57 HIDDT_PixelFormat pf
; /* Public portion in the beginning */
59 struct MinNode node
; /* Node for linking into the database */
60 ULONG refcount
; /* Reference count */
63 /* Use this macro in order to transform node pointer to pixfmt pointer */
64 #define PIXFMT_OBJ(n) ((HIDDT_PixelFormat *)((char *)(n) - offsetof(struct pixfmt_data, node)))
68 struct BitMap
*bitmap
; /* Associated BitMap structure */
69 BOOL planes_alloced
; /* Whether the BitMap was allocated by us */
74 OOP_Object
*gfxhidd
; /* Cached driver object */
75 UBYTE
*buffer
; /* Pixelbuffer */
76 ULONG bytesperrow
; /* Cached for faster access */
78 BOOL own_buffer
; /* Whether the buffer was allocated by us */
83 struct MonitorSpec
*mspc
; /* Associated MonitorSpec */
85 ULONG pixelclock
; /* pixel time in Hz */
87 ULONG hdisp
; /* Data missing from MonitorSpec */
91 ULONG flags
; /* Flags */
93 UBYTE description
[32];
95 ULONG hmin
; /* Minimum and maximum allowed bitmap size */
100 OOP_Object
*gfxhidd
; /* Graphics driver that owns this sync */
101 ULONG InternalFlags
; /* Internal flags, see below */
104 /* Sync internal flags */
105 #define SYNC_FREE_MONITORSPEC 0x0001 /* Allocated own MonitorSpec */
106 #define SYNC_FREE_SPECIALMONITOR 0x0002 /* Allocated own SpecialMonitor */
107 #define SYNC_VARIABLE 0x0004 /* Signal timings can be changed */
111 HIDDT_GC_Intern prot
;
120 /* Array of all available gfxmode PixFmts that are part of
123 struct SignalSemaphore sema
;
124 OOP_Object
**pixfmts
;
125 /* Number of pixfmts in the above array */
128 /* All the sync times that are part of any gfxmode */
130 /* Number of syncs in the above array */
133 /* A bitmap of size (num_pixfmts * num_syncs), that tells if the
134 mode is displayable or not. If a particular (x, y) coordinate
135 of the bitmap is 1, it means that the pixfmt and sync objects
136 you get by indexing pixfmts[x] and syncs[y] are a valid mode.
137 If not, the mode is considered invalid
140 struct mode_bm orig_mode_bm
; /* Original as supplied by subclass */
141 struct mode_bm checked_mode_bm
; /* After applying monitor refresh rate checks etc. */
147 /* Gfx mode "database" */
150 /* Framebuffer control stuff */
151 OOP_Object
*framebuffer
;
154 struct SignalSemaphore fbsem
;
156 /* gc used for stuff like rendering cursor */
160 /* Private gfxhidd methods */
161 OOP_Object
*GFXHIDD__Hidd_Gfx__RegisterPixFmt(OOP_Class
*cl
, struct TagItem
*pixFmtTags
);
162 VOID
GFXHIDD__Hidd_Gfx__ReleasePixFmt(OOP_Class
*cl
, OOP_Object
*pf
);
164 static inline BOOL
GFXHIDD__Hidd_Gfx__SetFBColors(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_SetColors
*msg
)
166 struct HiddGfxData
*data
= OOP_INST_DATA(cl
, o
);
168 return OOP_DoMethod(data
->framebuffer
, &msg
->mID
);
171 static inline UBYTE
GFXHIDD__Hidd_Gfx__GetFBModeQuick(OOP_Class
*cl
, OOP_Object
*o
)
173 struct HiddGfxData
*data
= OOP_INST_DATA(cl
, o
);
178 /* This has to be a #define, otherwise the HIDD_Gfx_CopyBox()
179 * macro won't expand the HiddGfxBase macro to the csd
182 #define GFXHIDD__Hidd_Gfx__UpdateFB(cl, o, bm, srcX, srcY, destX, destY, xSize, ySize) \
184 struct HiddGfxData *__data = OOP_INST_DATA(cl, o); \
185 HIDD_Gfx_CopyBox(o, bm, srcX, srcY, \
186 __data->framebuffer, destX, destY, \
187 xSize, ySize, __data->gc); \
190 /* Private bitmap methods */
191 void BM__Hidd_BitMap__SetBitMapTags(OOP_Class
*cl
, OOP_Object
*o
, struct TagItem
*bitMapTags
);
192 void BM__Hidd_BitMap__SetPixFmt(OOP_Class
*cl
, OOP_Object
*o
, OOP_Object
*pf
);
193 void BM__Hidd_BitMap__SetVisible(OOP_Class
*cl
, OOP_Object
*o
, BOOL val
);
195 struct HIDDBitMapData
197 struct _hidd_bitmap_protected prot
;
199 struct BitMap
*bmstruct
;
200 UWORD width
; /* width of the bitmap in pixel */
201 UWORD height
; /* height of the bitmap in pixel */
202 UWORD align
; /* Default alignment */
203 IPTR displayWidth
; /* Display size */
205 struct Rectangle display
; /* Display rectangle (in bitmap's coordinates !) */
206 struct SignalSemaphore lock
; /* Scroll/update semaphore */
207 BOOL visible
; /* bitmap visible ? */
208 BOOL displayable
; /* bitmap directly displayable? */
209 BOOL compositable
; /* bitmap displayable via compositor */
210 BOOL framebuffer
; /* is a framebuffer ? */
211 BOOL pf_registered
; /* Registered own pixelformat ? */
212 ULONG flags
; /* see hidd/graphic.h 'flags for */
213 ULONG bytesPerRow
; /* bytes per row */
214 OOP_Object
*friend; /* Friend bitmap */
215 OOP_Object
*gfxhidd
; /* Owning driver */
216 OOP_Object
*colmap
; /* Colormap */
217 OOP_Object
*gc
; /* Shared GC for copy operations */
218 HIDDT_ModeID modeid
; /* Display mode ID */
220 /* Optimize these method calls */
221 #if USE_FAST_PUTPIXEL
222 OOP_MethodFunc putpixel
;
223 OOP_Class
*putpixel_Class
;
225 #if USE_FAST_GETPIXEL
226 OOP_MethodFunc getpixel
;
227 OOP_Class
*getpixel_Class
;
229 #if USE_FAST_DRAWPIXEL
230 OOP_MethodFunc drawpixel
;
231 OOP_Class
*drawpixel_Class
;
233 #if USE_FAST_DRAWLINE
234 OOP_MethodFunc drawline
;
235 OOP_Class
*drawline_Class
;
237 #if USE_FAST_GETIMAGE
238 OOP_MethodFunc getimage
;
239 OOP_Class
*getimage_Class
;
241 #if USE_FAST_PUTIMAGE
242 OOP_MethodFunc putimage
;
243 OOP_Class
*putimage_Class
;
245 #if USE_FAST_CONVERTPIXELS
246 OOP_MethodFunc convertpixels
;
247 OOP_Class
*convertpixels_Class
;
249 #if USE_FAST_UNMAPPIXEL
250 OOP_MethodFunc unmappixel
;
251 OOP_Class
*unmappixel_Class
;
253 #if USE_FAST_MAPCOLOR
254 OOP_MethodFunc mapcolor
;
255 OOP_Class
*mapcolor_Class
;
259 #define NUM_ATTRBASES 11
260 #define NUM_METHODBASES 5
262 struct class_static_data
264 struct GfxBase
*cs_GfxBase
;
265 struct Library
*cs_UtilityBase
;
266 struct Library
*cs_OOPBase
;
269 struct SignalSemaphore sema
;
271 OOP_AttrBase attrBases
[NUM_ATTRBASES
];
272 OOP_MethodID methodBases
[NUM_METHODBASES
];
274 OOP_Class
*gfxhwclass
; /* graphics hw enumerator class */
275 OOP_Class
*gfxhiddclass
; /* graphics hidd class */
276 OOP_Class
*bitmapclass
; /* bitmap class */
277 OOP_Class
*gcclass
; /* graphics context class */
278 OOP_Class
*colormapclass
; /* colormap class */
280 OOP_Class
*pixfmtclass
; /* describing bitmap pixel formats */
281 OOP_Class
*syncclass
; /* describing gfxmode sync times */
283 OOP_Class
*planarbmclass
;
284 OOP_Class
*chunkybmclass
;
286 OOP_Object
*gfxhwinstance
;
289 Pixel format "database". This is a list
290 of all pixelformats currently used by some bitmap.
291 The point of having this as a central db in the gfx hidd is
292 that if several bitmaps are of the same pixel format
293 they may point to the same PixFmt object instead
294 of allocating their own instance. Thus we are saving mem
296 struct SignalSemaphore pfsema
;
297 struct MinList pflist
;
298 /* Index of standard pixelformats for quick access */
299 HIDDT_PixelFormat
*std_pixfmts
[num_Hidd_StdPixFmt
];
301 HIDDT_RGBConversionFunction rgbconvertfuncs
[NUM_RGB_STDPIXFMT
][NUM_RGB_STDPIXFMT
];
302 struct SignalSemaphore rgbconvertfuncs_sem
;
305 #define __IHidd_BitMap (csd->attrBases[0])
306 #define __IHidd_Gfx (csd->attrBases[1])
307 #define __IHidd_GC (csd->attrBases[2])
308 #define __IHidd_ColorMap (csd->attrBases[3])
309 #define __IHW (csd->attrBases[4])
310 #define __IHidd (csd->attrBases[5])
311 #define __IHidd_Overlay (csd->attrBases[6])
312 #define __IHidd_Sync (csd->attrBases[7])
313 #define __IHidd_PixFmt (csd->attrBases[8])
314 #define __IHidd_PlanarBM (csd->attrBases[9])
315 #define __IHidd_ChunkyBM (csd->attrBases[10])
318 #undef HiddBitMapBase
319 #undef HiddColorMapBase
322 #define HiddBitMapBase (csd->methodBases[0])
323 #define HiddGfxBase (csd->methodBases[1])
324 #define HiddGCBase (csd->methodBases[2])
325 #define HiddColorMapBase (csd->methodBases[3])
326 #define HWBase (csd->methodBases[4])
330 struct IntHIDDGraphicsBase
332 struct Library hdg_LibNode
;
334 struct class_static_data hdg_csd
;
338 /* pre declarations */
340 BOOL
parse_pixfmt_tags(struct TagItem
*tags
, HIDDT_PixelFormat
*pf
, ULONG attrcheck
, struct class_static_data
*csd
);
342 static inline ULONG
color_distance(UWORD a1
, UWORD r1
, UWORD g1
, UWORD b1
, UWORD a2
, UWORD r2
, UWORD g2
, UWORD b2
)
344 /* NOTE: The use of 'WORD' here and the 'UWORD' casts below are
345 * important hints to GCC to generate better code on m68k
347 WORD da
= (a1
>> 8) - (a2
>> 8);
348 WORD dr
= (r1
>> 8) - (r2
>> 8);
349 WORD dg
= (g1
>> 8) - (g2
>> 8);
350 WORD db
= (b1
>> 8) - (b2
>> 8);
352 DB2(bug("[color_distance] a1 = 0x%04X a2 = 0x%04X da = %d\n", a1
, a2
, da
));
353 DB2(bug("[color_distance] r1 = 0x%04X r2 = 0x%04X dr = %d\n", r1
, r2
, dr
));
354 DB2(bug("[color_distance] g1 = 0x%04X g2 = 0x%04X dg = %d\n", g1
, g2
, dg
));
355 DB2(bug("[color_distance] b1 = 0x%04X b2 = 0x%04X db = %d\n", b1
, b2
, db
));
357 /* '4' here is a result of trial and error. The idea behind this is to increase
358 the weight of alpha difference in order to make the function prefer colors with
359 the same alpha value. This is important for correct mouse pointer remapping. */
360 return (UWORD
)(da
*da
)*4 + (UWORD
)(dr
*dr
) + (UWORD
)(dg
*dg
) + (UWORD
)(db
*db
);
363 #define CSD(x) (&((struct IntHIDDGraphicsBase *)x->UserData)->hdg_csd)
366 /* The following calls are optimized by calling the method functions directly */
368 #if USE_FAST_GETPIXEL
369 static inline HIDDT_Pixel
GETPIXEL(OOP_Class
*cl
, OOP_Object
*o
, WORD x
, WORD y
)
371 struct pHidd_BitMap_GetPixel getp_p
;
373 getp_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_GetPixel
;
377 return HBM(o
)->getpixel(HBM(o
)->getpixel_Class
, o
, &getp_p
.mID
);
380 #define GETPIXEL(cl, obj, x, y) HIDD_BM_GetPixel(obj, x, y)
383 #if USE_FAST_PUTPIXEL
384 static inline void PUTPIXEL(OOP_Class
*cl
, OOP_Object
*o
, WORD x
, WORD y
, HIDDT_Pixel val
)
386 struct pHidd_BitMap_PutPixel putp_p
;
388 putp_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_PutPixel
;
393 HBM(o
)->putpixel(HBM(o
)->putpixel_Class
, o
, &putp_p
.mID
);
396 #define PUTPIXEL(cl, obj, x, y, val) HIDD_BM_PutPixel(obj, x, y, val)
399 #if USE_FAST_DRAWPIXEL
400 static inline void DRAWPIXEL(OOP_Class
*cl
, OOP_Object
*o
, OOP_Object
*gc
, WORD x
, WORD y
)
402 struct pHidd_BitMap_DrawPixel drawp_p
;
404 drawp_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_DrawPixel
;
409 HBM(o
)->drawpixel(HBM(o
)->drawpixel_Class
, o
, &drawp_p
.mID
);
412 #define DRAWPIXEL(cl, obj, gc, x, y) HIDD_BM_PutPixel(obj, gc, x, y)
415 #if USE_FAST_DRAWLINE
416 static inline void DRAWLINE(OOP_Class
*cl
, OOP_Object
*o
, OOP_Object
*gc
, WORD x1
, WORD y1
, WORD x2
, WORD y2
)
418 struct pHidd_BitMap_DrawLine drawl_p
;
420 drawl_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_DrawLine
;
427 HBM(o
)->drawline(HBM(o
)->drawline_Class
, o
, &drawl_p
.mID
);
430 #define DRAWLINE(cl, obj, gc, x1, y1, x2, y2) HIDD_BM_DrawLine(obj, gc, x1, y1, x2, y2)
433 #if USE_FAST_GETIMAGE
434 static inline void GETIMAGE(OOP_Class
*cl
, OOP_Object
*o
, UBYTE
*pixels
, ULONG modulo
, WORD x
, WORD y
,
435 WORD width
, WORD height
, HIDDT_StdPixFmt pixFmt
)
437 struct pHidd_BitMap_GetImage geti_p
;
439 geti_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_GetImage
;
440 geti_p
.pixels
= pixels
;
441 geti_p
.modulo
= modulo
;
444 geti_p
.width
= width
;
445 geti_p
.height
= height
;
446 geti_p
.pixFmt
= pixFmt
;
448 HBM(o
)->getimage(HBM(o
)->getimage_Class
, o
, &geti_p
.mID
);
451 #define GETIMAGE(cl, o, obj, pixels, modulo, x, y, width, height, pixFmt) HIDD_BM_GetImage(o, obj, pixels, modulo, x, y, width, height, pixFmt)
454 #if USE_FAST_PUTIMAGE
455 static inline void PUTIMAGE(OOP_Class
*cl
, OOP_Object
*o
, OOP_Object
*gc
, UBYTE
*pixels
, ULONG modulo
,
456 WORD x
, WORD y
, WORD width
, WORD height
, HIDDT_StdPixFmt pixFmt
)
458 struct pHidd_BitMap_PutImage puti_p
;
460 puti_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_PutImage
;
462 puti_p
.pixels
= pixels
;
463 puti_p
.modulo
= modulo
;
466 puti_p
.width
= width
;
467 puti_p
.height
= height
;
468 puti_p
.pixFmt
= pixFmt
;
470 HBM(o
)->putimage(HBM(o
)->putimage_Class
, o
, &puti_p
.mID
);
473 #define PUTIMAGE(cl, obj, gc, pixels, modulo, x, y, width, height, pixFmt) HIDD_BM_PutImage(obj, gc, pixels, modulo, x, y, width, height, pixFmt)
476 #if USE_FAST_CONVERTPIXELS
477 static inline void CONVERTPIXELS(OOP_Class
*cl
, OOP_Object
*o
, APTR
*srcPixels
, HIDDT_PixelFormat
*srcPixFmt
, ULONG srcMod
, APTR
*dstBuf
, HIDDT_PixelFormat
*dstPixFmt
, ULONG dstMod
, UWORD width
, UWORD height
, HIDDT_PixelLUT
*pixlut
)
479 struct pHidd_BitMap_ConvertPixels convp_p
;
481 convp_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_ConvertPixels
;
482 convp_p
.srcPixels
= srcPixels
;
483 convp_p
.srcPixFmt
= srcPixFmt
;
484 convp_p
.srcMod
= srcMod
;
485 convp_p
.dstBuf
= dstBuf
;
486 convp_p
.dstPixFmt
= dstPixFmt
;
487 convp_p
.dstMod
= dstMod
;
488 convp_p
.width
= width
;
489 convp_p
.height
= height
;
490 convp_p
.pixlut
= pixlut
;
492 HBM(o
)->convertpixels(HBM(o
)->convertpixels_Class
, o
, &convp_p
.mID
);
495 #define CONVERTPIXELS(cl, obj, srcPixels, srcPixFmt, srcMod, dstBuf, dstPixFmt, dstMod, width, height, pixlut) HIDD_BM_ConvertPixels(obj, srcPixels, srcPixFmt, srcMod, dstBuf, dstPixFmt, dstMod, width, height, pixlut)
498 #if USE_FAST_UNMAPPIXEL
499 static inline void UNMAPPIXEL(OOP_Class
*cl
, OOP_Object
*o
, HIDDT_Pixel pixel
, HIDDT_Color
*color
)
501 struct pHidd_BitMap_UnmapPixel unmpp_p
;
503 unmpp_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_UnmapPixel
;
504 unmpp_p
.pixel
= pixel
;
505 unmpp_p
.color
= color
;
507 HBM(o
)->unmappixel(HBM(o
)->unmappixel_Class
, o
, &unmpp_p
.mID
);
510 #define UNMAPPIXEL(cl, obj, pixel, color) HIDD_BM_UnmapPixel(obj, pixel, color)
513 //HIDD_BM_MapColor(o, &col)
514 #if USE_FAST_MAPCOLOR
515 static inline HIDDT_Pixel
MAPCOLOR(OOP_Class
*cl
, OOP_Object
*o
, HIDDT_Color
*color
)
517 struct pHidd_BitMap_MapColor mapc_p
;
519 mapc_p
.mID
= HiddBitMapBase
+ moHidd_BitMap_MapColor
;
520 mapc_p
.color
= color
;
522 return HBM(o
)->mapcolor(HBM(o
)->mapcolor_Class
, o
, &mapc_p
.mID
);
525 #define MAPCOLOR(cl, obj, color) HIDD_BM_MapColor(obj, color)
528 #endif /* GFX_HIDD_INTERN_H */