2 Copyright 1995-2019, The AROS Development Team. All rights reserved.
5 Desc: Bitmap class for p96 rtg card drivers.
10 /****************************************************************************************/
16 #include <proto/oop.h>
17 #include <proto/utility.h>
18 #include <exec/alerts.h>
19 #include <aros/macros.h>
20 #include <exec/memory.h>
21 #include <exec/lists.h>
22 #include <graphics/rastport.h>
23 #include <graphics/gfx.h>
24 #include <graphics/gfxbase.h>
27 #include <aros/symbolsets.h>
29 #include <hardware/custom.h>
36 #include <aros/debug.h>
38 #include LC_LIBDEFS_FILE
40 #include "p96gfx_intern.h"
41 #include "p96gfx_bitmap.h"
42 #include "p96gfx_rtg.h"
46 swap bitmap between RAM <-> VRAM allowed only if this lock is held
48 the bitmap being swapped must also get LOCK_BITMAP lock, otherwise
49 gfx functions (done by other tasks) could render into wrong place while
50 bitmap is moved around.
54 /* poke 0xFF into the videodata for debugging purposes - may be dangerous on some cards! */
55 /*#define DEBUG_POKE_VIDEODATA*/
57 static BOOL
P96GFXBitmap__ToFRAM(OOP_Class
*cl
, OOP_Object
*o
, struct P96GfxBitMapData
*bm
);
59 static APTR
P96GFXBitmap__AllocVRAM(OOP_Class
*cl
, OOP_Object
*o
, struct P96GfxBitMapData
*bm
)
61 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
62 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
63 struct p96gfx_staticdata
*csd
= CSD(cl
);
66 DVRAM(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
68 SetMemoryMode(cid
, RGBFB_CLUT
);
69 vmem
= Allocate(cid
->vmem
, bm
->memsize
);
70 SetMemoryMode(cid
, bm
->rgbformat
);
73 DVRAM(bug("[P96Gfx:Bitmap] %s: Bitmap @ 0x%p (%dx%dx%d %d): %p,%d bytes VRAM allocated.\n", __func__
, bm
, bm
->width
, bm
->height
, bm
->bytesperpixel
*8, bm
->bytesperline
, vmem
, bm
->memsize
));
78 static BOOL
P96GFXBitmap__AllocBM(OOP_Class
*cl
, OOP_Object
*o
, struct P96GfxBitMapData
*bm
, BOOL usevram
)
80 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
81 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
82 struct p96gfx_staticdata
*csd
= CSD(cl
);
83 bm
->memsize
= (bm
->bytesperline
* bm
->height
+ 7) & ~7;
85 if (!(bm
->VideoData
= P96GFXBitmap__AllocVRAM(cl
, o
, bm
)))
87 if (usevram
&& bm
->memsize
< cid
->vram_size
)
89 struct P96GfxBitMapData
*bmnode
;
90 ForeachNode(&cid
->bitmaplist
, bmnode
)
92 if (bmnode
!= bm
&& bmnode
->invram
&& !bmnode
->locked
)
94 if (P96GFXBitmap__ToFRAM(cl
, o
, bmnode
))
96 if ((bm
->VideoData
= P96GFXBitmap__AllocVRAM(cl
, o
, bm
)))
98 cid
->vram_used
+= bm
->memsize
;
109 bm
->VideoData
= AllocMem(bm
->memsize
, MEMF_ANY
);
112 cid
->fram_used
+= bm
->memsize
;
118 cid
->vram_used
+= bm
->memsize
;
121 DVRAM(bug("[P96Gfx:Bitmap] %s: Bitmap @ 0x%p (%p:%d) bytes allocated from %s. VRAM=%d\n", __func__
, bm
, bm
->VideoData
, bm
->memsize
, bm
->invram
? "VRAM" : "RAM", cid
->vram_used
));
123 #ifdef DEBUG_POKE_VIDEODATA
124 /* poke 0xFF into the videodata for debugging purposes - may be dangerous on some cards! */
125 if (bm
->VideoData
!= NULL
)
129 for(i
= 0; i
< bm
->memsize
; i
++) bm
->VideoData
[i
] = 0xFF;
132 return bm
->VideoData
!= NULL
;
135 static void P96GFXBitmap__FreeBM(OOP_Class
*cl
, OOP_Object
*o
, struct P96GfxBitMapData
*bm
)
137 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
138 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
139 struct p96gfx_staticdata
*csd
= CSD(cl
);
142 bug("[P96Gfx:Bitmap] %s()\n", __func__
);
143 bug("[P96Gfx:Bitmap] %s: Bitmap @ 0x%p: freeing %p:%d from %s\n", __func__
, bm
, bm
->VideoData
, bm
->memsize
, bm
->invram
? "VRAM" : "RAM");
148 SetMemoryMode(cid
, RGBFB_CLUT
);
149 Deallocate(cid
->vmem
, bm
->VideoData
, bm
->memsize
);
150 SetMemoryMode(cid
, bm
->rgbformat
);
151 cid
->vram_used
-= bm
->memsize
;
153 else if (bm
->VideoData
)
155 FreeMem(bm
->VideoData
, bm
->memsize
);
156 cid
->fram_used
-= bm
->memsize
;
158 bm
->VideoData
= NULL
;
162 static BOOL
P96GFXBitmap__ToFRAM(OOP_Class
*cl
, OOP_Object
*o
, struct P96GfxBitMapData
*bm
)
164 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
165 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
166 struct p96gfx_staticdata
*csd
= CSD(cl
);
170 DVRAM(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
172 /* TRYLOCK here as we are in wrong locking order (could deadlock):
174 LOCK_BITMAP_MULTI -> LOCK_HW -> [...] <- UNLOCK_HW <- UNLOCK_BITMAP_MULTI
175 (Correct locking order is: LOCK_BM_MULTI -> LOCK_BM -> LOCK_HW)
177 Alternative would be to always lock all (swappable) bitmaps during bitmap
178 allocation/freeing routines. */
180 if (TRYLOCK_BITMAP(bm
))
182 vmem
= AllocMem(bm
->memsize
, MEMF_ANY
);
185 SetMemoryMode(cid
, bm
->rgbformat
);
186 CopyMemQuick(bm
->VideoData
, vmem
, bm
->memsize
);
187 P96GFXBitmap__FreeBM(cl
, o
, bm
);
188 bm
->VideoData
= vmem
;
190 cid
->fram_used
+= bm
->memsize
;
193 DVRAM(bug("[P96Gfx:Bitmap] %s: Bitmap @ 0x%p (%p:%d) %d x %d moved to RAM . VRAM=%d\n", __func__
, bm
->VideoData
, bm
->memsize
, bm
, bm
->width
, bm
->height
, cid
->vram_used
));
201 static BOOL
P96GFXBitmap__BMToVRAM(OOP_Class
*cl
, OOP_Object
*o
, struct P96GfxBitMapData
*bm
)
203 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
204 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
205 struct p96gfx_staticdata
*csd
= CSD(cl
);
208 DVRAM(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
210 vmem
= P96GFXBitmap__AllocVRAM(cl
, o
, bm
);
213 SetMemoryMode(cid
, bm
->rgbformat
);
214 CopyMemQuick(bm
->VideoData
, vmem
, bm
->memsize
);
215 P96GFXBitmap__FreeBM(cl
, o
, bm
);
216 bm
->VideoData
= vmem
;
218 cid
->vram_used
+= bm
->memsize
;
219 DVRAM(bug("[P96Gfx:Bitmap] %s: Bitmap @ 0x%p (%p:%d) %d x %d moved back to VRAM\n", __func__
, bm
, bm
->VideoData
, bm
->memsize
, bm
->width
, bm
->height
));
225 static BOOL
P96GFXBitmap__ToVRAM(OOP_Class
*cl
, OOP_Object
*o
, struct P96GfxBitMapData
*bm
)
227 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
228 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
229 struct p96gfx_staticdata
*csd
= CSD(cl
);
230 struct P96GfxBitMapData
*bmnode
;
232 DVRAM(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
237 DVRAM(bug("[P96Gfx:Bitmap] %s: Bitmap @ 0x%p (%p:%d) needs to be in VRAM...\n", __func__
, bm
, bm
->VideoData
, bm
->memsize
));
239 ForeachNode(&cid
->bitmaplist
, bmnode
)
241 if (bmnode
!= bm
&& bmnode
->invram
&& !bmnode
->locked
)
243 if (P96GFXBitmap__ToFRAM(cl
, o
, bmnode
))
245 if (P96GFXBitmap__BMToVRAM(cl
, o
, bm
))
253 DVRAM(bug("[P96Gfx:Bitmap] %s: -> not enough memory, VRAM=%d\n", __func__
, cid
->vram_used
));
259 static BOOL
maybeputinvram(OOP_Class
*cl
, OOP_Object
*o
, struct P96GfxBitMapData
*bm
)
261 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
262 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
263 struct p96gfx_staticdata
*csd
= CSD(cl
);
266 if (bm
->memsize
>= cid
->vram_size
- cid
->vram_used
)
268 return P96GFXBitmap__BMToVRAM(cl
, o
, bm
);
272 static void P96GFXBitmap__HideScreen(OOP_Class
*cl
, OOP_Object
*o
, struct P96GfxBitMapData
*bm
)
274 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
275 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
276 struct p96gfx_staticdata
*csd
= CSD(cl
);
278 D(bug("[P96Gfx:Bitmap] %s: Bitmap @ 0x%p (%p:%d)\n",
279 __func__
, bm
, bm
->VideoData
, bm
->memsize
));
281 SetInterrupt(cid
, FALSE
);
282 SetDisplay(cid
, FALSE
);
283 SetSwitch(cid
, FALSE
);
289 /****************************************************************************************/
291 #define AO(x) (aoHidd_BitMap_ ## x)
292 #define GOT_BM_ATTR(code) GOT_ATTR(code, aoHidd_BitMap, bitmap)
294 /****************************************************************************************/
296 OOP_Object
*P96GFXBitmap__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
298 struct p96gfx_staticdata
*csd
= CSD(cl
);
300 struct P96GfxBitMapData
*data
;
301 struct p96gfx_carddata
*cid
;
302 IPTR width
, height
, multi
;
304 struct TagItem tags
[2];
307 DB2(bug("[P96Gfx:Bitmap] %s(%x)\n", __func__
, o
));
309 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
315 data
= OOP_INST_DATA(cl
, o
);
316 memset(data
, 0, sizeof (*data
));
317 InitSemaphore(&data
->bmLock
);
319 OOP_GetAttr(o
, aHidd_BitMap_Width
, &width
);
320 OOP_GetAttr(o
, aHidd_BitMap_Height
, &height
);
321 OOP_GetAttr(o
, aHidd_BitMap_Displayable
, &displayable
);
322 OOP_GetAttr(o
, aHidd_BitMap_GfxHidd
, (APTR
)&data
->gfxhidd
);
323 OOP_GetAttr(o
, aHidd_BitMap_PixFmt
, (APTR
)&data
->pixfmtobj
);
324 OOP_GetAttr(data
->pixfmtobj
, aHidd_PixFmt_BytesPerPixel
, &multi
);
326 OOP_GetAttr(data
->gfxhidd
, aHidd_P96Gfx_CardData
, (APTR
)&data
->gfxCardData
);
327 DB2(bug("[P96Gfx:Bitmap] %s: Card Data @ 0x%p\n", __func__
, data
->gfxCardData
));
328 cid
= data
->gfxCardData
;
330 data
->rgbformat
= P96GFXRTG__GetFormat(csd
, cid
, data
->pixfmtobj
);
332 data
->align
= displayable
? 32 : 16;
333 width
= (width
+ data
->align
- 1) & ~(data
->align
- 1);
334 data
->bytesperline
= CalculateBytesPerRow(cid
, width
, data
->rgbformat
);
336 data
->height
= height
;
337 data
->bytesperpixel
= multi
;
341 LOCK_HW
/* alloc routines call SetMemoryMode */
342 WaitBlitter(cid
); /* in case bitmaps are swapped between RAM <-> VRAM during allocation */
343 P96GFXBitmap__AllocBM(cl
, o
, data
, TRUE
);
346 AddTail(&cid
->bitmaplist
, (struct Node
*)&data
->node
);
350 tags
[0].ti_Tag
= aHidd_BitMap_BytesPerRow
;
351 tags
[0].ti_Data
= data
->bytesperline
;
352 tags
[1].ti_Tag
= TAG_DONE
;
353 OOP_SetAttrs(o
, tags
);
355 DB2(bug("[P96Gfx:Bitmap] %s: %dx%dx%d %d RGBF=%08x P=%08x\n", __func__
, width
, height
, multi
, data
->bytesperline
, data
->rgbformat
, data
->VideoData
));
357 if (data
->VideoData
== NULL
)
361 OOP_MethodID dispose_mid
;
362 dispose_mid
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
363 OOP_CoerceMethod(cl
, o
, (OOP_Msg
)&dispose_mid
);
367 DB2(bug("[P96Gfx:Bitmap] %s: ret=%x bm=%p (%p:%d)\n", __func__
, o
, data
, data
->VideoData
, data
->memsize
));
372 VOID
P96GFXBitmap__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
374 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
375 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
376 struct p96gfx_staticdata
*csd
= CSD(cl
);
378 D(bug("[P96Gfx:Bitmap] %s(%x)\n", __func__
, o
));
383 DB2(bug("[P96Gfx:Bitmap] %s: bm=%x (%p,%d)\n", __func__
, data
, data
->VideoData
, data
->memsize
));
384 if (cid
->disp
== data
)
385 P96GFXBitmap__HideScreen(cl
, o
, data
);
389 FreeVec(data
->palette
);
393 LOCK_HW
/* free functions call SetMemoryMode */
394 P96GFXBitmap__FreeBM(cl
, o
, data
);
397 Remove((struct Node
*)&data
->node
);
401 OOP_DoSuperMethod(cl
, o
, msg
);
404 VOID
P96GFXBitmap__Root__Set(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Set
*msg
)
406 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
407 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
408 struct p96gfx_staticdata
*csd
= CSD(cl
);
409 struct TagItem
*tag
, *tstate
;
413 DB2(bug("[P96Gfx:Bitmap] %s: %p (%p:%d)\n", __func__
, data
, data
->VideoData
, data
->memsize
));
414 tstate
= msg
->attrList
;
415 while((tag
= NextTagItem(&tstate
)))
417 DB2(bug("[P96Gfx:Bitmap] %s: Tag %d/%d\n", __func__
, tag
->ti_Tag
, tag
->ti_Data
));
418 if(IS_BITMAP_ATTR(tag
->ti_Tag
, idx
))
420 DB2(bug("[P96Gfx:Bitmap] %s: BitMap Attr ->%d\n", __func__
, idx
));
423 case aoHidd_BitMap_Focus
:
425 ULONG boardType
= gl(data
->gfxCardData
->boardinfo
+ PSSO_BoardInfo_BoardType
);
426 DB2(bug("[P96Gfx:Bitmap] %s: aoHidd_BitMap_Focus\n", __func__
);)
427 if (boardType
== P96BoardType_Vampire
)
429 struct GfxBase
*GfxBase
= (struct GfxBase
*)csd
->cs_GfxBase
;
430 volatile struct Custom
*custom
= (struct Custom
*)0xdff000;
431 /* Tell the Vampire SAGA chipset we are visible */
432 custom
->bplcon0
= GfxBase
->system_bplcon0
| 0x80;
437 case aoHidd_BitMap_Visible
:
442 OOP_Object
*gfxhidd
, *sync
, *pf
;
443 IPTR modeid
= vHidd_ModeID_Invalid
;
444 IPTR dwidth
, dheight
, depth
, width
, height
;
445 struct ModeInfo
*modeinfo
;
448 height
= data
->height
;
449 OOP_GetAttr(o
, aHidd_BitMap_ModeID
, &modeid
);
450 OOP_GetAttr(o
, aHidd_BitMap_GfxHidd
, (IPTR
*)&gfxhidd
);
451 HIDD_Gfx_GetMode(gfxhidd
, modeid
, &sync
, &pf
);
452 OOP_GetAttr(sync
, aHidd_Sync_HDisp
, &dwidth
);
453 OOP_GetAttr(sync
, aHidd_Sync_VDisp
, &dheight
);
454 OOP_GetAttr(pf
, aHidd_PixFmt_Depth
, &depth
);
455 data
->rgbformat
= P96GFXRTG__GetFormat(csd
, cid
, pf
);
456 modeinfo
= P96GFXRTG__GetModeInfo(csd
, cid
, sync
, pf
, cid
->fakemodeinfo
);
457 cid
->modeinfo
= modeinfo
;
458 *cid
->rgbformat
= data
->rgbformat
;
459 pw(cid
->bitmapextra
+ PSSO_BitMapExtra_Width
, width
);
460 pw(cid
->bitmapextra
+ PSSO_BitMapExtra_Height
, height
);
461 D(bug("[P96Gfx:Bitmap] %s: Show %p: (%p:%d) %dx%dx%d (%dx%d) BF=%08x\n",
462 __func__
, data
, data
->VideoData
, data
->memsize
,
463 dwidth
, dheight
, depth
, width
, height
, data
->rgbformat
));
467 WaitBlitter(cid
); /* in case other bitmaps are swapped from VRAM to RAM */
468 if (!P96GFXBitmap__ToVRAM(cl
, o
, data
))
470 struct P96GfxBitMapData
*bmnode
;
472 /* Second try. Now lock all bitmaps first. UNLOCK_HW first, to ensure
473 correct locking order: multibm -> bm -> hw */
477 ForeachNode(&cid
->bitmaplist
, bmnode
)
479 if (bmnode
!= data
) LOCK_BITMAP(bmnode
)
483 WaitBlitter(cid
); /* in case other bitmaps are swapped from VRAM to RAM */
484 P96GFXBitmap__ToVRAM(cl
, o
, data
); /* shouldn't fail this time. If it does we are screwed ... */
487 ForeachNode(&cid
->bitmaplist
, bmnode
)
489 if (bmnode
!= data
) UNLOCK_BITMAP(bmnode
)
496 cid
->dwidth
= dwidth
;
497 cid
->dheight
= dheight
;
498 cid
->dmodeid
= modeid
;
500 if (cid
->hardwaresprite
&& depth
<= 8) {
503 UBYTE
*clut
= data
->gfxCardData
->boardinfo
+ PSSO_BoardInfo_CLUT
;
504 for (i
= cid
->spritepencnt
+ 1; i
< cid
->spritepencnt
+ 4; i
++)
506 c
.red
= clut
[i
* 3 + 0];
507 c
.green
= clut
[i
* 3 + 1];
508 c
.blue
= clut
[i
* 3 + 2];
509 HIDD_P96GFX_SetCursorPen(gfxhidd
, i
, c
);
512 SetInterrupt(cid
, FALSE
);
513 SetColorArray(cid
, 0, 256);
514 SetDisplay(cid
, FALSE
);
515 SetGC(cid
, modeinfo
, 0);
518 SetPanning(cid
, data
->VideoData
, width
, 0, 0);
519 SetDisplay(cid
, TRUE
);
520 SetSwitch(cid
, TRUE
);
521 SetInterrupt(cid
, TRUE
);
525 P96GFXBitmap__HideScreen(cl
, o
, data
);
532 case aoHidd_BitMap_LeftEdge
:
533 if (data
->leftedge
!= tag
->ti_Data
) {
534 data
->leftedge
= tag
->ti_Data
;
538 case aoHidd_BitMap_TopEdge
:
539 if (data
->topedge
!= tag
->ti_Data
) {
540 data
->topedge
= tag
->ti_Data
;
547 D(bug("[P96Gfx:Bitmap] %s: Exit\n", __func__
));
548 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
550 if (moved
&& cid
->disp
== data
)
551 setscroll(cid
, data
);
557 VOID
P96GFXBitmap__Root__Get(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
559 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
560 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
561 struct p96gfx_staticdata
*csd
= CSD(cl
);
564 //DB2(bug("P96GFXBitmap__Root__Get\n"));
565 if (IS_BITMAP_ATTR(msg
->attrID
, idx
)) {
566 //DB2(bug("=%d\n", idx));
568 case aoHidd_BitMap_LeftEdge
:
569 *msg
->storage
= 0;//data->leftedge;
571 case aoHidd_BitMap_TopEdge
:
572 *msg
->storage
= 0;//data->topedge;
574 case aoHidd_BitMap_Visible
:
575 *msg
->storage
= cid
->disp
== data
;
577 case aoHidd_BitMap_Align
:
578 *msg
->storage
= data
->align
;
580 case aoHidd_BitMap_BytesPerRow
:
581 *msg
->storage
= data
->bytesperline
;
583 case aoHidd_BitMap_IsLinearMem
:
584 *msg
->storage
= TRUE
;
588 //DB2(bug("P96GFXBitmap__Root__Get Exit\n"));
589 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
592 /****************************************************************************************/
594 static int P96GFXBitmap_Init(LIBBASETYPEPTR LIBBASE
)
596 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
597 return TRUE
; //return OOP_ObtainAttrBases(attrbases);
600 /****************************************************************************************/
602 static int P96GFXBitmap_Expunge(LIBBASETYPEPTR LIBBASE
)
604 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
605 //OOP_ReleaseAttrBases(attrbases);
609 /****************************************************************************************/
611 ADD2INITLIB(P96GFXBitmap_Init
, 0);
612 ADD2EXPUNGELIB(P96GFXBitmap_Expunge
, 0);
614 BOOL
P96GFXBitmap__Hidd_BitMap__ObtainDirectAccess(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_ObtainDirectAccess
*msg
)
616 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
617 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
618 struct p96gfx_staticdata
*csd
= CSD(cl
);
624 if (!P96GFXBitmap__ToVRAM(cl
, o
, data
))
629 *msg
->addressReturn
= data
->VideoData
;
630 *msg
->widthReturn
= data
->width
;
631 *msg
->heightReturn
= data
->height
;
632 /* undocumented, just a guess.. */
633 *msg
->bankSizeReturn
= *msg
->memSizeReturn
= data
->bytesperline
* data
->height
;
643 VOID
P96GFXBitmap__Hidd_BitMap__ReleaseDirectAccess(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_ReleaseDirectAccess
*msg
)
645 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
646 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
647 struct p96gfx_staticdata
*csd
= CSD(cl
);
654 BOOL
P96GFXBitmap__Hidd_BitMap__SetColors(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_SetColors
*msg
)
656 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
657 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
658 struct p96gfx_staticdata
*csd
= CSD(cl
);
662 DCLUT(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
664 if (!OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
))
670 clut
= data
->gfxCardData
->boardinfo
+ PSSO_BoardInfo_CLUT
;
671 DCLUT(bug("[P96Gfx:Bitmap] %s: CLUT @ %p\n", __func__
, clut
));
673 for (i
= msg
->firstColor
, j
= 0; j
< msg
->numColors
; i
++, j
++) {
674 clut
[i
* 3 + 0] = msg
->colors
[j
].red
>> 8;
675 clut
[i
* 3 + 1] = msg
->colors
[j
].green
>> 8;
676 clut
[i
* 3 + 2] = msg
->colors
[j
].blue
>> 8;
677 DCLUT(bug("[P96Gfx:Bitmap] %s: color %d %02x%02x%02x\n", __func__
, i
, msg
->colors
[j
].red
>> 8, msg
->colors
[j
].green
>> 8, msg
->colors
[j
].blue
>> 8));
679 SetColorArray(cid
, msg
->firstColor
, msg
->numColors
);
686 VOID
P96GFXBitmap__Hidd_BitMap__PutPixel(OOP_Class
*cl
, OOP_Object
*o
,
687 struct pHidd_BitMap_PutPixel
*msg
)
689 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
690 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
691 struct p96gfx_staticdata
*csd
= CSD(cl
);
693 HIDDT_Pixel pixel
= msg
->pixel
;
702 offset
= (msg
->x
* data
->bytesperpixel
) + (msg
->y
* data
->bytesperline
);
703 mem
= data
->VideoData
+ offset
;
705 switch(data
->bytesperpixel
)
708 *(UBYTE
*)mem
= pixel
;
712 *(UWORD
*)mem
= pixel
;
716 *(UBYTE
*)(mem
) = pixel
>> 16;
717 *(UBYTE
*)(mem
+ 1) = pixel
>> 8;
718 *(UBYTE
*)(mem
+ 2) = pixel
;
722 *(ULONG
*)mem
= pixel
;
731 /****************************************************************************************/
733 ULONG
P96GFXBitmap__Hidd_BitMap__GetPixel(OOP_Class
*cl
, OOP_Object
*o
,
734 struct pHidd_BitMap_GetPixel
*msg
)
736 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
737 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
738 struct p96gfx_staticdata
*csd
= CSD(cl
);
739 HIDDT_Pixel pixel
= 0;
749 offset
= (msg
->x
* data
->bytesperpixel
) +(msg
->y
* data
->bytesperline
);
750 mem
= data
->VideoData
+ offset
;
752 switch(data
->bytesperpixel
)
755 pixel
= *(UBYTE
*)mem
;
759 pixel
= *(UWORD
*)mem
;
763 pixel
= (mem
[0] << 16) | (mem
[1] << 8) | mem
[2];
767 pixel
= *(ULONG
*)mem
;
776 /****************************************************************************************/
778 VOID
P96GFXBitmap__Hidd_BitMap__DrawLine(OOP_Class
*cl
, OOP_Object
*o
,
779 struct pHidd_BitMap_DrawLine
*msg
)
781 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
782 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
783 struct p96gfx_staticdata
*csd
= CSD(cl
);
786 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
792 struct RenderInfo ri
;
793 struct Line renderLine
;
794 P96GFXRTG__MakeRenderInfo(csd
, cid
, &ri
, data
);
795 renderline
.FgPen
= GC_FG(msg
->gc
);
796 renderline
.BgPen
= GC_BG(msg
->gc
);
797 renderline
.LinePtrn
= GC_LINEPAT(gc
);
798 renderline
.X
= msg
->x1
;
799 renderline
.Y
= msg
->y1
;
800 renderline
.dX
= msg
->x2
;
801 renderline
.dY
= msg
->y2
;
802 v
= DrawLine(cid
, &ri
, &renderLine
, data
->rgbformat
);
807 if (!v
) OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
810 /****************************************************************************************/
812 VOID
P96GFXBitmap__Hidd_BitMap__GetImage(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_GetImage
*msg
)
814 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
815 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
816 struct p96gfx_staticdata
*csd
= CSD(cl
);
818 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
828 case vHidd_StdPixFmt_Native
:
829 switch(data
->bytesperpixel
)
832 HIDD_BM_CopyMemBox8(o
,
846 HIDD_BM_CopyMemBox16(o
,
860 HIDD_BM_CopyMemBox24(o
,
874 HIDD_BM_CopyMemBox32(o
,
886 } /* switch(data->bytesperpix) */
889 case vHidd_StdPixFmt_Native32
:
890 switch(data
->bytesperpixel
)
893 HIDD_BM_GetMem32Image8(o
,
905 HIDD_BM_GetMem32Image16(o
,
917 HIDD_BM_GetMem32Image24(o
,
929 HIDD_BM_CopyMemBox32(o
,
941 } /* switch(data->bytesperpix) */
946 APTR pixels
= msg
->pixels
;
947 APTR srcPixels
= data
->VideoData
+ msg
->y
* data
->bytesperline
+ msg
->x
* data
->bytesperpixel
;
950 dstpf
= HIDD_Gfx_GetPixFmt(data
->gfxhidd
, msg
->pixFmt
);
952 HIDD_BM_ConvertPixels(o
, &srcPixels
, (HIDDT_PixelFormat
*)data
->pixfmtobj
, data
->bytesperline
,
953 &pixels
, (HIDDT_PixelFormat
*)dstpf
, msg
->modulo
,
954 msg
->width
, msg
->height
, NULL
);
957 } /* switch(msg->pixFmt) */
962 /****************************************************************************************/
964 VOID
P96GFXBitmap__Hidd_BitMap__PutImage(OOP_Class
*cl
, OOP_Object
*o
,
965 struct pHidd_BitMap_PutImage
*msg
)
967 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
968 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
969 struct p96gfx_staticdata
*csd
= CSD(cl
);
972 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
982 if ((msg
->pixFmt
== vHidd_StdPixFmt_Native
983 || msg
->pixFmt
== vHidd_StdPixFmt_Native32
984 || msg
->pixFmt
== vHidd_StdPixFmt_BGRA32
985 || msg
->pixFmt
== vHidd_StdPixFmt_BGR032
))
988 struct RenderInfo ri
;
991 P96GFXRTG__MakeRenderInfo(csd
, cid
, &ri
, data
);
992 if (msg
->pixels
< data
->VideoData
)
998 // v =BlitRect(cid, &ri,
999 // WORD sx, WORD sy, WORD dx, WORD dy, msg->width, msg->height, UBYTE mask, data->rgbformat);
1006 if (!v
) switch(msg
->pixFmt
)
1008 case vHidd_StdPixFmt_Native
:
1009 switch(data
->bytesperpixel
)
1012 HIDD_BM_CopyMemBox8(o
,
1022 data
->bytesperline
);
1026 HIDD_BM_CopyMemBox16(o
,
1036 data
->bytesperline
);
1040 HIDD_BM_CopyMemBox24(o
,
1050 data
->bytesperline
);
1054 HIDD_BM_CopyMemBox32(o
,
1064 data
->bytesperline
);
1066 } /* switch(data->bytesperpix) */
1069 case vHidd_StdPixFmt_Native32
:
1070 switch(data
->bytesperpixel
)
1073 HIDD_BM_PutMem32Image8(o
,
1081 data
->bytesperline
);
1085 HIDD_BM_PutMem32Image16(o
,
1093 data
->bytesperline
);
1097 HIDD_BM_PutMem32Image24(o
,
1105 data
->bytesperline
);
1109 HIDD_BM_CopyMemBox32(o
,
1119 data
->bytesperline
);
1121 } /* switch(data->bytesperpix) */
1126 APTR pixels
= msg
->pixels
;
1127 APTR dstBuf
= data
->VideoData
+ msg
->y
* data
->bytesperline
+ msg
->x
* data
->bytesperpixel
;
1130 srcpf
= HIDD_Gfx_GetPixFmt(data
->gfxhidd
, msg
->pixFmt
);
1132 HIDD_BM_ConvertPixels(o
, &pixels
, (HIDDT_PixelFormat
*)srcpf
, msg
->modulo
,
1133 &dstBuf
, (HIDDT_PixelFormat
*)data
->pixfmtobj
, data
->bytesperline
,
1134 msg
->width
, msg
->height
, NULL
);
1137 } /* switch(msg->pixFmt) */
1142 /****************************************************************************************/
1144 VOID
P96GFXBitmap__Hidd_BitMap__PutImageLUT(OOP_Class
*cl
, OOP_Object
*o
,
1145 struct pHidd_BitMap_PutImageLUT
*msg
)
1147 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
1148 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
1149 struct p96gfx_staticdata
*csd
= CSD(cl
);
1151 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
1159 switch(data
->bytesperpixel
)
1162 HIDD_BM_CopyLUTMemBox16(o
,
1177 HIDD_BM_CopyLUTMemBox24(o
,
1192 HIDD_BM_CopyLUTMemBox32(o
,
1207 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1209 } /* switch(data->bytesperpix) */
1214 /****************************************************************************************/
1216 VOID
P96GFXBitmap__Hidd_BitMap__GetImageLUT(OOP_Class
*cl
, OOP_Object
*o
,
1217 struct pHidd_BitMap_GetImageLUT
*msg
)
1219 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
1220 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
1221 struct p96gfx_staticdata
*csd
= CSD(cl
);
1223 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
1229 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1232 /****************************************************************************************/
1234 VOID
P96GFXBitmap__Hidd_BitMap__FillRect(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_DrawRect
*msg
)
1236 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
1237 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
1238 HIDDT_DrawMode mode
= GC_DRMD(msg
->gc
);
1239 HIDDT_Pixel fg
= GC_FG(msg
->gc
);
1240 struct p96gfx_staticdata
*csd
= CSD(cl
);
1243 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
1251 maybeputinvram(cid
, data
);
1255 struct RenderInfo ri
;
1257 P96GFXRTG__MakeRenderInfo(csd
, cid
, &ri
, data
);
1261 if (mode
== vHidd_GC_DrawMode_Clear
|| mode
== vHidd_GC_DrawMode_Set
) {
1262 ULONG pen
= mode
== vHidd_GC_DrawMode_Clear
? 0x00000000 : 0xffffffff;
1263 v
= FillRect(cid
, &ri
, msg
->minX
, msg
->minY
, msg
->maxX
- msg
->minX
+ 1, msg
->maxY
- msg
->minY
+ 1, pen
, 0xff, data
->rgbformat
);
1264 } else if (mode
== vHidd_GC_DrawMode_Copy
) {
1265 v
= FillRect(cid
, &ri
, msg
->minX
, msg
->minY
, msg
->maxX
- msg
->minX
+ 1, msg
->maxY
- msg
->minY
+ 1, fg
, 0xff, data
->rgbformat
);
1266 } else if (mode
== vHidd_GC_DrawMode_Invert
) {
1267 v
= InvertRect(cid
, &ri
, msg
->minX
, msg
->minY
, msg
->maxX
- msg
->minX
+ 1, msg
->maxY
- msg
->minY
+ 1, 0xff, data
->rgbformat
);
1273 if (!v
) switch(mode
)
1275 case vHidd_GC_DrawMode_Copy
:
1276 switch(data
->bytesperpixel
)
1279 HIDD_BM_FillMemRect8(o
,
1290 HIDD_BM_FillMemRect16(o
,
1301 HIDD_BM_FillMemRect24(o
,
1312 HIDD_BM_FillMemRect32(o
,
1324 case vHidd_GC_DrawMode_Invert
:
1325 HIDD_BM_InvertMemRect(o
,
1327 msg
->minX
* data
->bytesperpixel
,
1329 msg
->maxX
* data
->bytesperpixel
+ data
->bytesperpixel
- 1,
1331 data
->bytesperline
);
1335 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1337 } /* switch(mode) */
1342 /****************************************************************************************/
1344 VOID
P96GFXBitmap__Hidd_BitMap__PutPattern(OOP_Class
*cl
, OOP_Object
*o
,
1345 struct pHidd_BitMap_PutPattern
*msg
)
1347 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
1348 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
1349 struct p96gfx_staticdata
*csd
= CSD(cl
);
1350 HIDDT_Pixel fg
= GC_FG(msg
->gc
);
1351 HIDDT_Pixel bg
= GC_BG(msg
->gc
);
1356 D(bug("[P96Gfx:Bitmap] %s(%d,%d)(%d,%d)(%x,%d,%d,%d,%d,%d)\n", __func__
,
1357 msg
->x
, msg
->y
, msg
->width
, msg
->height
,
1358 msg
->pattern
, msg
->patternsrcx
, msg
->patternsrcy
, fg
, bg
, msg
->patternheight
));
1366 if ((msg
->mask
== NULL
) && (msg
->patterndepth
== 1))
1368 switch (msg
->patternheight
)
1404 maybeputinvram(cid
, data
);
1408 struct RenderInfo ri
;
1410 P96GFXRTG__MakeRenderInfo(csd
, cid
, &ri
, data
);
1412 if (GC_COLEXP(msg
->gc
) == vHidd_GC_ColExp_Transparent
)
1414 else if (GC_DRMD(msg
->gc
) == vHidd_GC_DrawMode_Invert
)
1415 drawmode
= COMPLEMENT
;
1418 if (msg
->invertpattern
)
1419 drawmode
|= INVERSVID
;
1421 pat
.Memory
= msg
->pattern
;
1422 pat
.XOffset
= msg
->patternsrcx
;
1423 pat
.YOffset
= msg
->patternsrcy
;
1426 pat
.DrawMode
= drawmode
;
1430 v
= BlitPattern(cid
, &ri
, &pat
, msg
->x
, msg
->y
, msg
->width
, msg
->height
, 0xff, data
->rgbformat
);
1437 if (!v
) switch(data
->bytesperpixel
)
1440 HIDD_BM_PutMemPattern8(o
,
1461 HIDD_BM_PutMemPattern16(o
,
1482 HIDD_BM_PutMemPattern24(o
,
1503 HIDD_BM_PutMemPattern32(o
,
1524 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1526 } /* switch(data->bytesperpixel) */
1531 /****************************************************************************************/
1533 VOID
P96GFXBitmap__Hidd_BitMap__PutTemplate(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_PutTemplate
*msg
)
1535 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
1536 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
1537 struct p96gfx_staticdata
*csd
= CSD(cl
);
1538 HIDDT_Pixel fg
= GC_FG(msg
->gc
);
1539 HIDDT_Pixel bg
= GC_BG(msg
->gc
);
1542 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
1551 maybeputinvram(cid
, data
);
1555 struct Template tmpl
;
1556 struct RenderInfo ri
;
1559 P96GFXRTG__MakeRenderInfo(csd
, cid
, &ri
, data
);
1561 if (GC_COLEXP(msg
->gc
) == vHidd_GC_ColExp_Transparent
)
1563 else if (GC_DRMD(msg
->gc
) == vHidd_GC_DrawMode_Invert
)
1564 drawmode
= COMPLEMENT
;
1567 if (msg
->inverttemplate
)
1568 drawmode
|= INVERSVID
;
1570 /* tmpl.XOffset has only UBYTE size so we must fix params up [1] [2] */
1572 tmpl
.Memory
= msg
->masktemplate
+ ((msg
->srcx
/ 8) & ~1); /* [1] */
1573 tmpl
.BytesPerRow
= msg
->modulo
;
1574 tmpl
.XOffset
= msg
->srcx
& 0XF; /* [2] */
1575 tmpl
.DrawMode
= drawmode
;
1580 v
= BlitTemplate(cid
, &ri
, &tmpl
, msg
->x
, msg
->y
, msg
->width
, msg
->height
, 0xff, data
->rgbformat
);
1584 if (!v
) switch(data
->bytesperpixel
)
1587 HIDD_BM_PutMemTemplate8(o
,
1598 msg
->inverttemplate
);
1602 HIDD_BM_PutMemTemplate16(o
,
1613 msg
->inverttemplate
);
1617 HIDD_BM_PutMemTemplate24(o
,
1628 msg
->inverttemplate
);
1632 HIDD_BM_PutMemTemplate32(o
,
1643 msg
->inverttemplate
);
1647 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1649 } /* switch(data->bytesperpixel) */
1654 /****************************************************************************************/
1656 VOID
P96GFXBitmap__Hidd_BitMap__UpdateRect(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_UpdateRect
*msg
)
1658 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
1659 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
1660 struct p96gfx_staticdata
*csd
= CSD(cl
);
1662 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
1668 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1671 /****************************************************************************************/
1673 BOOL
P96GFXBitmap__Hidd_PlanarBM__SetBitMap(OOP_Class
*cl
, OOP_Object
*o
,
1674 struct pHidd_PlanarBM_SetBitMap
*msg
)
1676 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
1677 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
1678 struct p96gfx_staticdata
*csd
= CSD(cl
);
1680 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
1686 return OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
1689 /****************************************************************************************/
1691 BOOL
P96GFXBitmap__Hidd_PlanarBM__GetBitMap(OOP_Class
*cl
, OOP_Object
*o
,
1692 struct pHidd_PlanarBM_GetBitMap
*msg
)
1694 struct P96GfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
1695 struct p96gfx_carddata
*cid
= data
->gfxCardData
;
1696 struct p96gfx_staticdata
*csd
= CSD(cl
);
1698 D(bug("[P96Gfx:Bitmap] %s()\n", __func__
));
1704 return OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);