2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
9 #include <exec/alerts.h>
10 #include <string.h> // memset() prototype
11 #include <aros/macros.h>
15 #include <aros/debug.h>
17 /********* BitMap::PutPixel() ***************************/
19 VOID
MNAME_BM(PutPixel
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutPixel
*msg
)
21 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
23 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
26 HIDDT_Pixel pixel
= msg
->pixel
;
28 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
32 offset
= (msg
->x
* data
->bytesperpix
) + (msg
->y
* data
->bytesperline
);
33 mem
= data
->VideoData
+ offset
;
35 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
36 offset2
= (msg
->x
* data
->bytesperpix
) + (msg
->y
* data
->data
->bytesperline
);
37 mem2
= data
->data
->framebuffer
+ offset2
;
40 switch(data
->bytesperpix
)
43 *(UBYTE
*)mem
= pixel
;
44 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
45 *(UBYTE
*)mem2
= pixel
;
50 *(UWORD
*)mem
= pixel
;
51 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
52 *(UWORD
*)mem2
= pixel
;
58 *(UBYTE
*)(mem
) = pixel
>> 16;
59 *(UBYTE
*)(mem
+ 1) = pixel
>> 8;
60 *(UBYTE
*)(mem
+ 2) = pixel
;
62 *(UBYTE
*)(mem
) = pixel
;
63 *(UBYTE
*)(mem
+ 1) = pixel
>> 8;
64 *(UBYTE
*)(mem
+ 2) = pixel
>> 16;
67 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
69 *(UBYTE
*)(mem2
) = pixel
>> 16;
70 *(UBYTE
*)(mem2
+ 1) = pixel
>> 8;
71 *(UBYTE
*)(mem2
+ 2) = pixel
;
73 *(UBYTE
*)(mem2
) = pixel
;
74 *(UBYTE
*)(mem2
+ 1) = pixel
>> 8;
75 *(UBYTE
*)(mem2
+ 2) = pixel
>> 16;
81 *(ULONG
*)mem
= pixel
;
82 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
83 *(ULONG
*)mem2
= pixel
;
91 /********* BitMap::GetPixel() *********************************/
93 HIDDT_Pixel
MNAME_BM(GetPixel
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetPixel
*msg
)
95 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
100 offset
= (msg
->x
* data
->bytesperpix
) +(msg
->y
* data
->bytesperline
);
101 mem
= data
->VideoData
+ offset
;
103 switch(data
->bytesperpix
)
106 pixel
= *(UBYTE
*)mem
;
110 pixel
= *(UWORD
*)mem
;
115 pixel
= (mem
[0] << 16) | (mem
[1] << 8) | mem
[2];
117 pixel
= (mem
[2] << 16) | (mem
[1] << 8) | mem
[0];
122 pixel
= *(ULONG
*)mem
;
134 /********* BitMap::FillRect() ***************************/
136 VOID
MNAME_BM(FillRect
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_DrawRect
*msg
)
138 struct BitmapData
*data
=OOP_INST_DATA(cl
, o
);
139 HIDDT_Pixel fg
= GC_FG(msg
->gc
);
140 HIDDT_DrawMode mode
= GC_DRMD(msg
->gc
);
143 mod
= data
->bytesperline
;
147 case vHidd_GC_DrawMode_Copy
:
148 switch(data
->bytesperpix
)
151 HIDD_BM_FillMemRect8(o
,
162 HIDD_BM_FillMemRect16(o
,
173 HIDD_BM_FillMemRect24(o
,
184 HIDD_BM_FillMemRect32(o
,
197 case vHidd_GC_DrawMode_Invert
:
198 HIDD_BM_InvertMemRect(o
,
200 msg
->minX
* data
->bytesperpix
,
202 msg
->maxX
* data
->bytesperpix
+ data
->bytesperpix
- 1,
208 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
213 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
214 LOCK_FRAMEBUFFER(XSD(cl
));
215 vesaRefreshArea(data
, msg
->minX
, msg
->minY
, msg
->maxX
, msg
->maxY
);
216 UNLOCK_FRAMEBUFFER(XSD(cl
));
220 /********* BitMap::PutImage() ***************************/
222 VOID
MNAME_BM(PutImage
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutImage
*msg
)
224 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
228 case vHidd_StdPixFmt_Native
:
229 switch(data
->bytesperpix
)
232 HIDD_BM_CopyMemBox8(o
,
246 HIDD_BM_CopyMemBox16(o
,
260 HIDD_BM_CopyMemBox24(o
,
274 HIDD_BM_CopyMemBox32(o
,
287 } /* switch(data->bytesperpix) */
290 case vHidd_StdPixFmt_Native32
:
291 switch(data
->bytesperpix
)
294 HIDD_BM_PutMem32Image8(o
,
306 HIDD_BM_PutMem32Image16(o
,
318 HIDD_BM_PutMem32Image24(o
,
330 HIDD_BM_CopyMemBox32(o
,
343 } /* switch(data->bytesperpix) */
349 APTR pixels
= msg
->pixels
;
350 APTR dstBuf
= data
->VideoData
+ msg
->y
* data
->bytesperline
+ msg
->x
* data
->bytesperpix
;
353 srcpf
= HIDD_Gfx_GetPixFmt(data
->gfxhidd
, msg
->pixFmt
);
355 HIDD_BM_ConvertPixels(o
, &pixels
, (HIDDT_PixelFormat
*)srcpf
, msg
->modulo
,
356 &dstBuf
, (HIDDT_PixelFormat
*)data
->pixfmtobj
, data
->bytesperline
,
357 msg
->width
, msg
->height
, NULL
);
361 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
365 } /* switch(msg->pixFmt) */
367 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
368 LOCK_FRAMEBUFFER(XSD(cl
));
369 vesaRefreshArea(data
, msg
->x
, msg
->y
, msg
->x
+ msg
->width
- 1, msg
->y
+ msg
->height
- 1);
370 UNLOCK_FRAMEBUFFER(XSD(cl
));
375 /********* BitMap::GetImage() ***************************/
377 VOID
MNAME_BM(GetImage
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetImage
*msg
)
379 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
383 case vHidd_StdPixFmt_Native
:
384 switch(data
->bytesperpix
)
387 HIDD_BM_CopyMemBox8(o
,
401 HIDD_BM_CopyMemBox16(o
,
415 HIDD_BM_CopyMemBox24(o
,
429 HIDD_BM_CopyMemBox32(o
,
442 } /* switch(data->bytesperpix) */
445 case vHidd_StdPixFmt_Native32
:
446 switch(data
->bytesperpix
)
449 HIDD_BM_GetMem32Image8(o
,
461 HIDD_BM_GetMem32Image16(o
,
473 HIDD_BM_GetMem32Image24(o
,
485 HIDD_BM_CopyMemBox32(o
,
498 } /* switch(data->bytesperpix) */
504 APTR pixels
= msg
->pixels
;
505 APTR srcPixels
= data
->VideoData
+ msg
->y
* data
->bytesperline
+ msg
->x
* data
->bytesperpix
;
508 dstpf
= HIDD_Gfx_GetPixFmt(data
->gfxhidd
, msg
->pixFmt
);
510 HIDD_BM_ConvertPixels(o
, &srcPixels
, (HIDDT_PixelFormat
*)data
->pixfmtobj
, data
->bytesperline
,
511 &pixels
, (HIDDT_PixelFormat
*)dstpf
, msg
->modulo
,
512 msg
->width
, msg
->height
, NULL
);
515 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
519 } /* switch(msg->pixFmt) */
523 VOID
MNAME_BM(PutImageLUT
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutImageLUT
*msg
)
525 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
527 switch(data
->bytesperpix
)
530 HIDD_BM_CopyLUTMemBox16(o
,
545 HIDD_BM_CopyLUTMemBox24(o
,
560 HIDD_BM_CopyLUTMemBox32(o
,
575 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
578 } /* switch(data->bytesperpix) */
580 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
581 LOCK_FRAMEBUFFER(XSD(cl
));
582 vesaRefreshArea(data
, msg
->x
, msg
->y
, msg
->x
+ msg
->width
- 1, msg
->y
+ msg
->height
- 1);
583 UNLOCK_FRAMEBUFFER(XSD(cl
));
588 /*** BitMap::BlitColorExpansion() **********************************************/
589 VOID
MNAME_BM(BlitColorExpansion
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_BlitColorExpansion
*msg
)
591 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
592 HIDDT_Pixel fg
, bg
, pix
;
601 cemd
= GC_COLEXP(msg
->gc
);
603 bpp
= data
->bytesperpix
;
605 mem
= data
->VideoData
+ msg
->destY
* data
->bytesperline
+ msg
->destX
* bpp
;
606 mod
= data
->bytesperline
- msg
->width
* bpp
;
608 opaque
= (cemd
& vHidd_GC_ColExp_Opaque
) ? TRUE
: FALSE
;
610 for (y
= 0; y
< msg
->height
; y
++)
612 for (x
= 0; x
< msg
->width
; x
++)
616 is_set
= HIDD_BM_GetPixel(msg
->srcBitMap
, x
+ msg
->srcX
, y
+ msg
->srcY
);
638 *((UWORD
*)mem
) = pix
;
656 *((ULONG
*)mem
) = pix
;
668 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
669 LOCK_FRAMEBUFFER(XSD(cl
));
670 vesaRefreshArea(data
, msg
->destX
, msg
->destY
, msg
->destX
+ msg
->width
- 1, msg
->destY
+ msg
->height
- 1);
671 UNLOCK_FRAMEBUFFER(XSD(cl
));
675 /*** BitMap::PutTemplate() **********************************************/
677 VOID
MNAME_BM(PutTemplate
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutTemplate
*msg
)
679 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
681 switch(data
->bytesperpix
)
684 HIDD_BM_PutMemTemplate8(o
,
695 msg
->inverttemplate
);
699 HIDD_BM_PutMemTemplate16(o
,
710 msg
->inverttemplate
);
714 HIDD_BM_PutMemTemplate24(o
,
725 msg
->inverttemplate
);
729 HIDD_BM_PutMemTemplate32(o
,
740 msg
->inverttemplate
);
744 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
747 } /* switch(data->bytesperpix) */
749 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
750 LOCK_FRAMEBUFFER(XSD(cl
));
751 vesaRefreshArea(data
, msg
->x
, msg
->y
, msg
->x
+ msg
->width
- 1, msg
->y
+ msg
->height
- 1);
752 UNLOCK_FRAMEBUFFER(XSD(cl
));
757 /*** BitMap::PutPattern() **********************************************/
759 VOID
MNAME_BM(PutPattern
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutPattern
*msg
)
761 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
763 switch(data
->bytesperpix
)
766 HIDD_BM_PutMemPattern8(o
,
787 HIDD_BM_PutMemPattern16(o
,
808 HIDD_BM_PutMemPattern24(o
,
829 HIDD_BM_PutMemPattern32(o
,
850 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
853 } /* switch(data->bytesperpix) */
855 #if defined(OnBitmap) && defined(BUFFERED_VRAM)
856 LOCK_FRAMEBUFFER(XSD(cl
));
857 vesaRefreshArea(data
, msg
->x
, msg
->y
, msg
->x
+ msg
->width
- 1, msg
->y
+ msg
->height
- 1);
858 UNLOCK_FRAMEBUFFER(XSD(cl
));
864 /*** BitMap::Get() *******************************************/
866 VOID
MNAME_ROOT(Get
)(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
868 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
871 if (IS_VesaGfxBM_ATTR(msg
->attrID
, idx
))
875 case aoHidd_VesaGfxBitMap_Drawable
:
876 *msg
->storage
= (ULONG
)data
->VideoData
;
879 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
884 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
888 /*** BitMap::SetColors() *************************************/
890 BOOL
MNAME_BM(SetColors
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_SetColors
*msg
)
892 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
893 struct HWData
*hwdata
= &XSD(cl
)->data
;
894 HIDDT_PixelFormat
*pf
;
899 HIDDT_Pixel red
, green
, blue
;
901 D(bug("[VESA] SetColors(%u, %u)\n", msg
->firstColor
, msg
->numColors
));
904 if ( vHidd_ColorModel_StaticPalette
== HIDD_PF_COLMODEL(pf
)
905 || vHidd_ColorModel_TrueColor
== HIDD_PF_COLMODEL(pf
) ) {
906 D(bug("[VESA] SetColors: not a palette bitmap\n"));
908 /* Superclass takes care of this case */
910 return OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
913 /* We have a vHidd_GT_Palette bitmap */
915 if (!OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
)) {
916 D(bug("[VESA] DoSuperMethod() failed\n"));
920 if ((msg
->firstColor
+ msg
->numColors
) > (1 << data
->bpp
))
923 for ( xc_i
= msg
->firstColor
, col_i
= 0;
924 col_i
< msg
->numColors
;
927 red
= msg
->colors
[col_i
].red
>> 8;
928 green
= msg
->colors
[col_i
].green
>> 8;
929 blue
= msg
->colors
[col_i
].blue
>> 8;
931 /* Set given color as allocated */
932 data
->cmap
[xc_i
] = 0x01000000 | red
| (green
<< 8) | (blue
<< 16);
934 /* Update DAC registers */
935 p_shift
= 8 - hwdata
->palettewidth
;
936 hwdata
->DAC
[xc_i
*3] = red
>> p_shift
;
937 hwdata
->DAC
[xc_i
*3+1] = green
>> p_shift
;
938 hwdata
->DAC
[xc_i
*3+2] = blue
>> p_shift
;
940 msg
->colors
[col_i
].pixval
= xc_i
;
943 /* Upload palette to the DAC if OnBitmap */
945 #ifdef TRACK_POINTER_PALETTE
946 if ((msg
->firstColor
<= 20) && (msg
->firstColor
+ msg
->numColors
- 1 >= 17))
947 bug("%d colors from %d changed\n", msg
->firstColor
, msg
->numColors
);
949 ObtainSemaphore(&XSD(cl
)->HW_acc
);
950 DACLoad(hwdata
, msg
->firstColor
, msg
->numColors
);
951 ReleaseSemaphore(&XSD(cl
)->HW_acc
);
952 #endif /* OnBitmap */