Re-enabled use of AROS.Boot file due to lack of general enthusiasm for
[tangerine.git] / arch / all-linux / hidd / bmclass.c
blob4e3f5231d4bb496dd5162f8f59c4ce76e426a5be
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Onscreen bitmap class for linux fb device
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <stdlib.h>
12 #include <stdio.h>
13 #include <string.h>
15 #include <proto/oop.h>
16 #include <proto/utility.h>
17 #include <oop/oop.h>
19 #include <hidd/graphics.h>
21 #include <aros/symbolsets.h>
23 #include "linux_intern.h"
24 #include "bitmap.h"
26 #include LC_LIBDEFS_FILE
28 static OOP_AttrBase HiddBitMapAttrBase = 0;
30 static struct OOP_ABDescr attrbases[] =
32 { IID_Hidd_BitMap , &HiddBitMapAttrBase },
33 { NULL , NULL }
36 #define DEBUG 0
37 #include <aros/debug.h>
39 /*********** BitMap::New() *************************************/
41 OOP_Object *LinuxBM__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
43 BOOL ok = TRUE;
45 // kill(getpid(), 19);
46 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
47 //kprintf("LINUXFB: GOT OBJ %p\n", o);
48 if (NULL != o)
50 struct BitmapData *data;
51 BOOL framebuffer;
52 IPTR val;
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);
60 if (framebuffer)
62 data->VideoData = LSD(cl)->baseaddr;
63 data->bytesperpix = LSD(cl)->pf.bytes_per_pixel;
64 data->bytesperline = LSD(cl)->fsi.line_length;
66 #if BUFFERED_VRAM
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);
74 if (!data->VideoData)
76 ok = FALSE;
78 else
80 data->VideoDataAllocated = TRUE;
82 #endif
84 else
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);
91 if (!data->VideoData)
93 ok = FALSE;
95 else
97 data->VideoDataAllocated = TRUE;
101 if (!ok)
103 ULONG dispose_mid;
104 dispose_mid = OOP_GetMethodID(IID_Root, moRoot_Dispose);
106 OOP_CoerceMethod(cl, o, (OOP_Msg)&dispose_mid);
107 o = NULL;
111 return o;
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)
128 ULONG width, height;
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;
140 return TRUE;
143 VOID LinuxBM__Hidd_BitMap__ReleaseDirectAccess(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_ReleaseDirectAccess *msg)
145 /* Do nothing */
146 #warning Here we can use mprotect() to detect accesses while no access is granted
147 return;
150 /*********** BitMap::PutPixel() ***********************************************/
151 VOID LinuxBM__Hidd_BitMap__PutPixel(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_PutPixel *msg)
153 struct BitmapData *data;
154 UBYTE *addr;
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;
160 pix = msg->pixel;
162 switch(data->bytesperpix)
164 case 1:
165 *addr = pix;
166 break;
168 case 2:
169 *(UWORD *)addr = pix;
170 break;
172 case 3:
173 #if AROS_BIG_ENDIAN
174 *addr ++ = (pix >> 16) & 0x000000FF;
175 *addr ++ = (pix >> 8 ) & 0x000000FF;
176 *addr ++ = pix & 0x000000FF;
177 #else
178 *addr ++ = pix & 0x000000FF;
179 *addr ++ = (pix >> 8 ) & 0x000000FF;
180 *addr ++ = (pix >> 16) & 0x000000FF;
181 #endif
182 break;
184 case 4:
185 default:
186 *(ULONG *)addr = pix;
187 break;
190 #if BUFFERED_VRAM
191 if (data->RealVideoData)
193 addr = data->RealVideoData + msg->y * data->realbytesperline + msg->x * data->bytesperpix;
195 switch(data->bytesperpix)
197 case 1:
198 *addr = pix;
199 break;
201 case 2:
202 *(UWORD *)addr = pix;
203 break;
205 case 3:
206 #if AROS_BIG_ENDIAN
207 *addr ++ = (pix >> 16) & 0x000000FF;
208 *addr ++ = (pix >> 8 ) & 0x000000FF;
209 *addr ++ = pix & 0x000000FF;
210 #else
211 *addr ++ = pix & 0x000000FF;
212 *addr ++ = (pix >> 8 ) & 0x000000FF;
213 *addr ++ = (pix >> 16) & 0x000000FF;
214 #endif
215 break;
217 case 4:
218 default:
219 *(ULONG *)addr = pix;
220 break;
223 #endif
225 return;
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;
232 UBYTE *addr;
233 HIDDT_Pixel pix;
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)
242 case 1:
243 pix = *addr;
244 break;
246 case 2:
247 pix = *(UWORD *)addr;
248 break;
250 case 3:
251 #if AROS_BIG_ENDIAN
252 pix = (addr[0] << 16) | (addr[1] << 8) | (addr[2]);
253 #else
254 pix = (addr[2] | (addr[1] << 8) | (addr[0] << 16));
255 #endif
256 break;
258 case 4:
259 default:
260 pix = *(ULONG *)addr;
261 break;
265 return pix;
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);
275 ULONG mod;
277 mod = data->bytesperline;
279 switch(mode)
281 case vHidd_GC_DrawMode_Copy:
282 switch(data->bytesperpix)
284 case 1:
285 HIDD_BM_FillMemRect8(o,
286 data->VideoData,
287 msg->minX,
288 msg->minY,
289 msg->maxX,
290 msg->maxY,
291 mod,
292 fg);
293 break;
295 case 2:
296 HIDD_BM_FillMemRect16(o,
297 data->VideoData,
298 msg->minX,
299 msg->minY,
300 msg->maxX,
301 msg->maxY,
302 mod,
303 fg);
304 break;
306 case 3:
307 HIDD_BM_FillMemRect24(o,
308 data->VideoData,
309 msg->minX,
310 msg->minY,
311 msg->maxX,
312 msg->maxY,
313 mod,
314 fg);
315 break;
317 case 4:
318 HIDD_BM_FillMemRect32(o,
319 data->VideoData,
320 msg->minX,
321 msg->minY,
322 msg->maxX,
323 msg->maxY,
324 mod,
325 fg);
326 break;
329 break;
331 case vHidd_GC_DrawMode_Invert:
332 HIDD_BM_InvertMemRect(o,
333 data->VideoData,
334 msg->minX * data->bytesperpix,
335 msg->minY,
336 msg->maxX * data->bytesperpix + data->bytesperpix - 1,
337 msg->maxY,
338 mod);
339 break;
341 default:
342 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
343 break;
345 } /* switch(mode) */
347 #if BUFFERED_VRAM
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));
354 #endif
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);
363 switch(msg->pixFmt)
365 case vHidd_StdPixFmt_Native:
366 switch(data->bytesperpix)
368 case 1:
369 HIDD_BM_CopyMemBox8(o,
370 msg->pixels,
373 data->VideoData,
374 msg->x,
375 msg->y,
376 msg->width,
377 msg->height,
378 msg->modulo,
379 data->bytesperline);
380 break;
382 case 2:
383 HIDD_BM_CopyMemBox16(o,
384 msg->pixels,
387 data->VideoData,
388 msg->x,
389 msg->y,
390 msg->width,
391 msg->height,
392 msg->modulo,
393 data->bytesperline);
394 break;
396 case 3:
397 HIDD_BM_CopyMemBox24(o,
398 msg->pixels,
401 data->VideoData,
402 msg->x,
403 msg->y,
404 msg->width,
405 msg->height,
406 msg->modulo,
407 data->bytesperline);
408 break;
410 case 4:
411 HIDD_BM_CopyMemBox32(o,
412 msg->pixels,
415 data->VideoData,
416 msg->x,
417 msg->y,
418 msg->width,
419 msg->height,
420 msg->modulo,
421 data->bytesperline);
422 break;
424 } /* switch(data->bytesperpix) */
425 break;
427 case vHidd_StdPixFmt_Native32:
428 switch(data->bytesperpix)
430 case 1:
431 HIDD_BM_PutMem32Image8(o,
432 msg->pixels,
433 data->VideoData,
434 msg->x,
435 msg->y,
436 msg->width,
437 msg->height,
438 msg->modulo,
439 data->bytesperline);
440 break;
442 case 2:
443 HIDD_BM_PutMem32Image16(o,
444 msg->pixels,
445 data->VideoData,
446 msg->x,
447 msg->y,
448 msg->width,
449 msg->height,
450 msg->modulo,
451 data->bytesperline);
452 break;
454 case 3:
455 HIDD_BM_PutMem32Image24(o,
456 msg->pixels,
457 data->VideoData,
458 msg->x,
459 msg->y,
460 msg->width,
461 msg->height,
462 msg->modulo,
463 data->bytesperline);
464 break;
466 case 4:
467 HIDD_BM_CopyMemBox32(o,
468 msg->pixels,
471 data->VideoData,
472 msg->x,
473 msg->y,
474 msg->width,
475 msg->height,
476 msg->modulo,
477 data->bytesperline);
478 break;
480 } /* switch(data->bytesperpix) */
481 break;
483 default:
484 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
485 break;
487 } /* switch(msg->pixFmt) */
489 #if BUFFERED_VRAM
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));
496 #endif
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);
506 switch(msg->pixFmt)
508 case vHidd_StdPixFmt_Native:
509 switch(data->bytesperpix)
511 case 1:
512 HIDD_BM_CopyMemBox8(o,
513 data->VideoData,
514 msg->x,
515 msg->y,
516 msg->pixels,
519 msg->width,
520 msg->height,
521 data->bytesperline,
522 msg->modulo);
523 break;
525 case 2:
526 HIDD_BM_CopyMemBox16(o,
527 data->VideoData,
528 msg->x,
529 msg->y,
530 msg->pixels,
533 msg->width,
534 msg->height,
535 data->bytesperline,
536 msg->modulo);
537 break;
539 case 3:
540 HIDD_BM_CopyMemBox24(o,
541 data->VideoData,
542 msg->x,
543 msg->y,
544 msg->pixels,
547 msg->width,
548 msg->height,
549 data->bytesperline,
550 msg->modulo);
551 break;
553 case 4:
554 HIDD_BM_CopyMemBox32(o,
555 data->VideoData,
556 msg->x,
557 msg->y,
558 msg->pixels,
561 msg->width,
562 msg->height,
563 data->bytesperline,
564 msg->modulo);
565 break;
567 } /* switch(data->bytesperpix) */
568 break;
570 case vHidd_StdPixFmt_Native32:
571 switch(data->bytesperpix)
573 case 1:
574 HIDD_BM_GetMem32Image8(o,
575 data->VideoData,
576 msg->x,
577 msg->y,
578 msg->pixels,
579 msg->width,
580 msg->height,
581 data->bytesperline,
582 msg->modulo);
583 break;
585 case 2:
586 HIDD_BM_GetMem32Image16(o,
587 data->VideoData,
588 msg->x,
589 msg->y,
590 msg->pixels,
591 msg->width,
592 msg->height,
593 data->bytesperline,
594 msg->modulo);
595 break;
597 case 3:
598 HIDD_BM_GetMem32Image24(o,
599 data->VideoData,
600 msg->x,
601 msg->y,
602 msg->pixels,
603 msg->width,
604 msg->height,
605 data->bytesperline,
606 msg->modulo);
607 break;
609 case 4:
610 HIDD_BM_CopyMemBox32(o,
611 data->VideoData,
612 msg->x,
613 msg->y,
614 msg->pixels,
617 msg->width,
618 msg->height,
619 data->bytesperline,
620 msg->modulo);
621 break;
623 } /* switch(data->bytesperpix) */
624 break;
626 default:
627 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
628 break;
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)
642 case 2:
643 HIDD_BM_CopyLUTMemBox16(o,
644 msg->pixels,
647 data->VideoData,
648 msg->x,
649 msg->y,
650 msg->width,
651 msg->height,
652 msg->modulo,
653 data->bytesperline,
654 msg->pixlut);
655 break;
657 case 3:
658 HIDD_BM_CopyLUTMemBox24(o,
659 msg->pixels,
662 data->VideoData,
663 msg->x,
664 msg->y,
665 msg->width,
666 msg->height,
667 msg->modulo,
668 data->bytesperline,
669 msg->pixlut);
670 break;
672 case 4:
673 HIDD_BM_CopyLUTMemBox32(o,
674 msg->pixels,
677 data->VideoData,
678 msg->x,
679 msg->y,
680 msg->width,
681 msg->height,
682 msg->modulo,
683 data->bytesperline,
684 msg->pixlut);
685 break;
687 default:
688 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
690 } /* switch(data->bytesperpix) */
692 #if BUFFERED_VRAM
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));
699 #endif
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;
709 ULONG cemd;
710 LONG x, y;
711 ULONG mod, bpp;
712 UBYTE *mem;
713 BOOL opaque;
715 fg = GC_FG(msg->gc);
716 bg = GC_BG(msg->gc);
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 ++)
730 ULONG is_set;
732 is_set = HIDD_BM_GetPixel(msg->srcBitMap, x + msg->srcX, y + msg->srcY);
733 if (is_set)
735 pix = fg;
737 else if (opaque)
739 pix = bg;
741 else
743 mem += bpp;
744 continue;
747 switch(bpp)
749 case 1:
750 *mem++ = pix;
751 break;
753 case 2:
754 *(UWORD *)mem = pix;
755 mem += 2;
756 break;
758 case 3:
759 #if AROS_BIG_ENDIAN
760 *mem++ = pix >> 16;
761 *mem++ = pix >> 8;
762 *mem++ = pix;
763 #else
764 *mem++ = pix;
765 *mem++ = pix >> 8;
766 *mem++ = pix >> 16;
767 #endif
768 break;
770 case 4:
771 *(ULONG *)mem++ = pix;
772 mem += 4;
773 break;
777 } /* for (each x) */
779 mem += mod;
781 } /* for (each y) */
783 #if BUFFERED_VRAM
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));
790 #endif
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);
808 return TRUE;
811 ADD2INITLIB(Init_BMClass, 0)
812 ADD2EXPUNGELIB(Expunge_BMClass, 0)