2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 Desc: Onscreen bitmap class for linux fb device
9 #define __OOP_NOATTRBASES__
15 #include <proto/oop.h>
16 #include <proto/utility.h>
19 #include <hidd/graphics.h>
21 #include <aros/symbolsets.h>
23 #include "linux_intern.h"
26 #include LC_LIBDEFS_FILE
28 static OOP_AttrBase HiddBitMapAttrBase
= 0;
30 static struct OOP_ABDescr attrbases
[] =
32 { IID_Hidd_BitMap
, &HiddBitMapAttrBase
},
37 #include <aros/debug.h>
39 /*********** BitMap::New() *************************************/
41 OOP_Object
*LinuxBM__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
45 // kill(getpid(), 19);
46 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
47 //kprintf("LINUXFB: GOT OBJ %p\n", o);
50 struct BitmapData
*data
;
54 data
= OOP_INST_DATA(cl
, o
);
56 OOP_GetAttr(o
, aHidd_BitMap_Width
, &val
); data
->width
= val
;
57 OOP_GetAttr(o
, aHidd_BitMap_Height
, &val
); data
->height
= val
;
59 framebuffer
= GetTagData(aHidd_BitMap_FrameBuffer
, FALSE
, msg
->attrList
);
62 data
->VideoData
= LSD(cl
)->baseaddr
;
63 data
->bytesperpix
= LSD(cl
)->pf
.bytes_per_pixel
;
64 data
->bytesperline
= LSD(cl
)->fsi
.line_length
;
67 data
->width
= (data
->width
+ 15) & ~15;
69 data
->RealVideoData
= data
->VideoData
;
70 data
->realbytesperline
= data
->bytesperline
;
72 data
->bytesperline
= data
->bytesperpix
* data
->width
;
73 data
->VideoData
= AllocVec(data
->bytesperline
* data
->height
, MEMF_CLEAR
);
80 data
->VideoDataAllocated
= TRUE
;
86 data
->width
= (data
->width
+ 15) & ~15;
87 data
->bytesperpix
= LSD(cl
)->pf
.bytes_per_pixel
;
88 data
->bytesperline
= data
->bytesperpix
* data
->width
;
90 data
->VideoData
= AllocVec(data
->bytesperline
* data
->height
, MEMF_CLEAR
);
97 data
->VideoDataAllocated
= TRUE
;
104 dispose_mid
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
106 OOP_CoerceMethod(cl
, o
, (OOP_Msg
)&dispose_mid
);
114 /********** Bitmap::Dispose() ***********************************/
115 VOID
LinuxBM__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
117 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
119 if (data
->VideoDataAllocated
)
120 FreeVec(data
->VideoData
);
122 OOP_DoSuperMethod(cl
, o
, msg
);
125 /********* BitMap::ObtainDirectAccess() *************************************/
126 BOOL
LinuxBM__Hidd_BitMap__ObtainDirectAccess(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_ObtainDirectAccess
*msg
)
130 /* Get width & height from bitmap object */
132 OOP_GetAttr(o
, aHidd_BitMap_Width
, &width
);
133 OOP_GetAttr(o
, aHidd_BitMap_Height
, &height
);
135 *msg
->addressReturn
= LSD(cl
)->baseaddr
;
136 *msg
->widthReturn
= LSD(cl
)->vsi
.xres_virtual
;
137 *msg
->heightReturn
= LSD(cl
)->vsi
.yres_virtual
;
138 *msg
->bankSizeReturn
= *msg
->memSizeReturn
= LSD(cl
)->fsi
.smem_len
;
143 VOID
LinuxBM__Hidd_BitMap__ReleaseDirectAccess(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_ReleaseDirectAccess
*msg
)
146 #warning Here we can use mprotect() to detect accesses while no access is granted
150 /*********** BitMap::PutPixel() ***********************************************/
151 VOID
LinuxBM__Hidd_BitMap__PutPixel(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutPixel
*msg
)
153 struct BitmapData
*data
;
155 HIDDT_Pixel pix
= msg
->pixel
;
157 data
= OOP_INST_DATA(cl
, o
);
159 addr
= data
->VideoData
+ msg
->y
* data
->bytesperline
+ msg
->x
* data
->bytesperpix
;
162 switch(data
->bytesperpix
)
169 *(UWORD
*)addr
= pix
;
174 *addr
++ = (pix
>> 16) & 0x000000FF;
175 *addr
++ = (pix
>> 8 ) & 0x000000FF;
176 *addr
++ = pix
& 0x000000FF;
178 *addr
++ = pix
& 0x000000FF;
179 *addr
++ = (pix
>> 8 ) & 0x000000FF;
180 *addr
++ = (pix
>> 16) & 0x000000FF;
186 *(ULONG
*)addr
= pix
;
191 if (data
->RealVideoData
)
193 addr
= data
->RealVideoData
+ msg
->y
* data
->realbytesperline
+ msg
->x
* data
->bytesperpix
;
195 switch(data
->bytesperpix
)
202 *(UWORD
*)addr
= pix
;
207 *addr
++ = (pix
>> 16) & 0x000000FF;
208 *addr
++ = (pix
>> 8 ) & 0x000000FF;
209 *addr
++ = pix
& 0x000000FF;
211 *addr
++ = pix
& 0x000000FF;
212 *addr
++ = (pix
>> 8 ) & 0x000000FF;
213 *addr
++ = (pix
>> 16) & 0x000000FF;
219 *(ULONG
*)addr
= pix
;
228 /*********** BitMap::GetPixel() ***********************************************/
229 HIDDT_Pixel
LinuxBM__Hidd_BitMap__GetPixel(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetPixel
*msg
)
231 struct BitmapData
*data
;
235 data
= OOP_INST_DATA(cl
, o
);
236 addr
= data
->VideoData
+ msg
->y
* data
->bytesperline
+ msg
->x
* data
->bytesperpix
;
238 /* Set pixel according to pixelformat */
240 switch(data
->bytesperpix
)
247 pix
= *(UWORD
*)addr
;
252 pix
= (addr
[0] << 16) | (addr
[1] << 8) | (addr
[2]);
254 pix
= (addr
[2] | (addr
[1] << 8) | (addr
[0] << 16));
260 pix
= *(ULONG
*)addr
;
268 /********* BitMap::FillRect() ***************************/
270 VOID
LinuxBM__Hidd_BitMap__FillRect(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_DrawRect
*msg
)
272 struct BitmapData
*data
=OOP_INST_DATA(cl
, o
);
273 HIDDT_Pixel fg
= GC_FG(msg
->gc
);
274 HIDDT_DrawMode mode
= GC_DRMD(msg
->gc
);
277 mod
= data
->bytesperline
;
281 case vHidd_GC_DrawMode_Copy
:
282 switch(data
->bytesperpix
)
285 HIDD_BM_FillMemRect8(o
,
296 HIDD_BM_FillMemRect16(o
,
307 HIDD_BM_FillMemRect24(o
,
318 HIDD_BM_FillMemRect32(o
,
331 case vHidd_GC_DrawMode_Invert
:
332 HIDD_BM_InvertMemRect(o
,
334 msg
->minX
* data
->bytesperpix
,
336 msg
->maxX
* data
->bytesperpix
+ data
->bytesperpix
- 1,
342 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
348 if (data
->RealVideoData
)
350 LOCK_FRAMEBUFFER(LSD(cl
));
351 fbRefreshArea(data
, msg
->minX
, msg
->minY
, msg
->maxX
, msg
->maxY
);
352 UNLOCK_FRAMEBUFFER(LSD(cl
));
357 /********* BitMap::PutImage() ***************************/
359 VOID
LinuxBM__Hidd_BitMap__PutImage(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutImage
*msg
)
361 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
365 case vHidd_StdPixFmt_Native
:
366 switch(data
->bytesperpix
)
369 HIDD_BM_CopyMemBox8(o
,
383 HIDD_BM_CopyMemBox16(o
,
397 HIDD_BM_CopyMemBox24(o
,
411 HIDD_BM_CopyMemBox32(o
,
424 } /* switch(data->bytesperpix) */
427 case vHidd_StdPixFmt_Native32
:
428 switch(data
->bytesperpix
)
431 HIDD_BM_PutMem32Image8(o
,
443 HIDD_BM_PutMem32Image16(o
,
455 HIDD_BM_PutMem32Image24(o
,
467 HIDD_BM_CopyMemBox32(o
,
480 } /* switch(data->bytesperpix) */
484 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
487 } /* switch(msg->pixFmt) */
490 if (data
->RealVideoData
)
492 LOCK_FRAMEBUFFER(LSD(cl
));
493 fbRefreshArea(data
, msg
->x
, msg
->y
, msg
->x
+ msg
->width
- 1, msg
->y
+ msg
->height
- 1);
494 UNLOCK_FRAMEBUFFER(LSD(cl
));
500 /********* BitMap::GetImage() ***************************/
502 VOID
LinuxBM__Hidd_BitMap__GetImage(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetImage
*msg
)
504 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
508 case vHidd_StdPixFmt_Native
:
509 switch(data
->bytesperpix
)
512 HIDD_BM_CopyMemBox8(o
,
526 HIDD_BM_CopyMemBox16(o
,
540 HIDD_BM_CopyMemBox24(o
,
554 HIDD_BM_CopyMemBox32(o
,
567 } /* switch(data->bytesperpix) */
570 case vHidd_StdPixFmt_Native32
:
571 switch(data
->bytesperpix
)
574 HIDD_BM_GetMem32Image8(o
,
586 HIDD_BM_GetMem32Image16(o
,
598 HIDD_BM_GetMem32Image24(o
,
610 HIDD_BM_CopyMemBox32(o
,
623 } /* switch(data->bytesperpix) */
627 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
630 } /* switch(msg->pixFmt) */
634 /*** BitMap::PutImageLUT() **********************************************/
636 VOID
LinuxBM__Hidd_BitMap__PutImageLUT(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutImageLUT
*msg
)
638 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
640 switch(data
->bytesperpix
)
643 HIDD_BM_CopyLUTMemBox16(o
,
658 HIDD_BM_CopyLUTMemBox24(o
,
673 HIDD_BM_CopyLUTMemBox32(o
,
688 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
690 } /* switch(data->bytesperpix) */
693 if (data
->RealVideoData
)
695 LOCK_FRAMEBUFFER(LSD(cl
));
696 fbRefreshArea(data
, msg
->x
, msg
->y
, msg
->x
+ msg
->width
- 1, msg
->y
+ msg
->height
- 1);
697 UNLOCK_FRAMEBUFFER(LSD(cl
));
703 /*** BitMap::BlitColorExpansion() **********************************************/
705 VOID
LinuxBM__Hidd_BitMap__BlitColorExpansion(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_BlitColorExpansion
*msg
)
707 struct BitmapData
*data
= OOP_INST_DATA(cl
, o
);
708 HIDDT_Pixel fg
, bg
, pix
;
717 cemd
= GC_COLEXP(msg
->gc
);
719 bpp
= data
->bytesperpix
;
721 mem
= data
->VideoData
+ msg
->destY
* data
->bytesperline
+ msg
->destX
* bpp
;
722 mod
= data
->bytesperline
- msg
->width
* bpp
;
724 opaque
= (cemd
& vHidd_GC_ColExp_Opaque
) ? TRUE
: FALSE
;
726 for (y
= 0; y
< msg
->height
; y
++)
728 for (x
= 0; x
< msg
->width
; x
++)
732 is_set
= HIDD_BM_GetPixel(msg
->srcBitMap
, x
+ msg
->srcX
, y
+ msg
->srcY
);
771 *(ULONG
*)mem
++ = pix
;
784 if (data
->RealVideoData
)
786 LOCK_FRAMEBUFFER(LSD(cl
));
787 fbRefreshArea(data
, msg
->destX
, msg
->destY
, msg
->destX
+ msg
->width
- 1, msg
->destY
+ msg
->height
- 1);
788 UNLOCK_FRAMEBUFFER(LSD(cl
));
794 /*** init_onbmclass *********************************************************/
796 static int Init_BMClass(LIBBASETYPEPTR LIBBASE
)
798 /* Get attrbase for the BitMap interface */
799 return OOP_ObtainAttrBases(attrbases
);
803 /*** free_bitmapclass *********************************************************/
805 static int Expunge_BMClass(LIBBASETYPEPTR LIBBASE
)
807 OOP_ReleaseAttrBases(attrbases
);
811 ADD2INITLIB(Init_BMClass
, 0)
812 ADD2EXPUNGELIB(Expunge_BMClass
, 0)