Fixed a warning (missing type cast)
[tangerine.git] / rom / graphics / graphics_driver.c
blob5cdd1a2c43f89d90b60030bacf34087949b9fc87
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Driver for using gfxhidd for gfx output
6 Lang: english
7 */
11 #include <proto/exec.h>
12 #include <proto/graphics.h>
13 #include <proto/layers.h>
14 #include <proto/arossupport.h>
15 #include <proto/utility.h>
16 #include <proto/oop.h>
18 #include <exec/memory.h>
19 #include <exec/semaphores.h>
20 #include <clib/macros.h>
22 #include <graphics/rastport.h>
23 #include <graphics/gfxbase.h>
24 #include <graphics/text.h>
25 #include <graphics/view.h>
26 #include <graphics/layers.h>
27 #include <graphics/clip.h>
28 #include <graphics/gfxmacros.h>
29 #include <graphics/regions.h>
30 #include <graphics/scale.h>
32 #include <oop/oop.h>
33 #include <utility/tagitem.h>
34 #include <aros/asmcall.h>
36 #include <intuition/intuition.h>
38 #include <hidd/graphics.h>
40 #include <cybergraphx/cybergraphics.h>
42 #include <stdio.h>
43 #include <string.h>
45 #include "graphics_intern.h"
46 #include "graphics_internal.h"
47 #include "intregions.h"
48 #include "dispinfo.h"
49 #include "gfxfuncsupport.h"
50 #include "fontsupport.h"
52 #define SDEBUG 0
53 #define DEBUG 0
54 #include <aros/debug.h>
57 static BOOL init_cursor(struct GfxBase *GfxBase);
58 static VOID cleanup_cursor(struct GfxBase *GfxBase);
60 struct rgbpix_render_data
62 HIDDT_Pixel pixel;
66 static LONG rgbpix_write(APTR pr_data, OOP_Object *bm, OOP_Object *gc,
67 LONG x, LONG y, struct GfxBase *GfxBase)
69 struct rgbpix_render_data *prd;
71 prd = (struct rgbpix_render_data *)pr_data;
73 HIDD_BM_PutPixel(bm, x, y, prd->pixel);
75 return 0;
77 #if 0
78 OOP_AttrBase HiddBitMapAttrBase = 0;
79 OOP_AttrBase HiddGCAttrBase = 0;
80 OOP_AttrBase HiddSyncAttrBase = 0;
81 OOP_AttrBase HiddPixFmtAttrBase = 0;
82 OOP_AttrBase HiddPlanarBMAttrBase = 0;
83 OOP_AttrBase HiddGfxAttrBase = 0;
84 OOP_AttrBase HiddFakeGfxHiddAttrBase = 0;
86 static struct OOP_ABDescr attrbases[] = {
87 { IID_Hidd_BitMap, &HiddBitMapAttrBase },
88 { IID_Hidd_GC, &HiddGCAttrBase },
89 { IID_Hidd_Sync, &HiddSyncAttrBase },
90 { IID_Hidd_PixFmt, &HiddPixFmtAttrBase },
91 { IID_Hidd_PlanarBM, &HiddPlanarBMAttrBase },
92 { IID_Hidd_Gfx, &HiddGfxAttrBase },
93 { IID_Hidd_FakeGfxHidd, &HiddFakeGfxHiddAttrBase },
94 { NULL, 0UL }
97 #endif
100 struct ETextFont
102 struct TextFont etf_Font;
106 /* InitDriverData() just allocates memory for the struct. To use e.g. */
107 /* AreaPtrns, UpdateAreaPtrn() has to allocate the memory for the */
108 /* Pattern itself (and free previously used memory!) */
110 #if NEW_DRIVERDATA_CODE
112 static inline LONG CalcDriverDataHash(APTR resource)
114 LONG l1, l2, l3, l4, hash;
116 /* FIXME: Probably sucks. I have no clue about this hash stuff */
118 l1 = ((LONG)resource) & 0xFF;
119 l2 = (((LONG)resource) >> 8) & 0xFF;
120 l3 = (((LONG)resource) >> 16) & 0xFF;
121 l4 = (((LONG)resource) >> 24) & 0xFF;
123 hash = (l1 + l2 + l3 + l4) % DRIVERDATALIST_HASHSIZE;
125 return hash;
128 static inline void AddDriverDataToList(struct gfx_driverdata *dd, struct GfxBase * GfxBase)
130 LONG hash;
132 hash = CalcDriverDataHash(dd);
134 // ObtainSemaphore(&PrivGBase(GfxBase)->driverdatasem);
135 AddTail((struct List *)&PrivGBase(GfxBase)->driverdatalist[hash], (struct Node *)&dd->dd_Node);
136 // ReleaseSemaphore(&PrivGBase(GfxBase)->driverdatasem);
140 static inline void RemoveDriverDataFromList(struct gfx_driverdata *dd, struct GfxBase *GfxBase)
142 // ObtainSemaphore(&PrivGBase(GfxBase)->driverdatasem);
143 Remove((struct Node *)&dd->dd_Node);
144 // ReleaseSemaphore(&PrivGBase(GfxBase)->driverdatasem);
147 static inline BOOL FindDriverData(struct gfx_driverdata *dd, struct RastPort *rp, struct GfxBase *GfxBase)
149 struct gfx_driverdata *hn = NULL;
150 LONG hash;
151 BOOL retval = FALSE;
153 hash = CalcDriverDataHash(dd);
155 // ObtainSemaphore(&PrivGBase(GfxBase)->driverdatasem);
156 ForeachNode((struct List *)&PrivGBase(GfxBase)->driverdatalist[hash], hn)
158 if ((hn == dd) && (hn->dd_RastPort == rp))
160 retval = TRUE;
161 break;
164 // ReleaseSemaphore(&PrivGBase(GfxBase)->driverdatasem);
166 return retval;
169 BOOL ObtainDriverData(struct RastPort *rp, struct GfxBase *GfxBase)
171 struct gfx_driverdata *dd;
173 if (RP_BACKPOINTER(rp) == rp)
175 if (rp->Flags & RPF_SELF_CLEANUP)
177 if (RP_DRIVERDATA(rp)) return TRUE;
180 else
182 /* We have detected a manually cloned rastport. Mark it as 'valid'
183 (backpointer to itself) but with NULL driverdata and non-self
184 cleanup */
185 RP_DRIVERDATA(rp) = NULL;
186 rp->Flags &= ~RPF_SELF_CLEANUP;
187 RP_BACKPOINTER(rp) = rp;
190 ObtainSemaphore(&PrivGBase(GfxBase)->driverdatasem);
191 dd = RP_DRIVERDATA(rp);
192 if (dd)
194 if (!(rp->Flags & RPF_SELF_CLEANUP) && FindDriverData(dd, rp, GfxBase))
196 dd->dd_LockCount++;
198 else
200 RP_DRIVERDATA(rp) = NULL;
201 dd = NULL;
205 if (!dd)
207 dd = AllocPooled(PrivGBase(GfxBase)->driverdatapool, sizeof(*dd));
208 if (dd)
210 struct shared_driverdata *sdd;
211 struct TagItem gc_tags[] = {{ TAG_DONE}};
213 sdd = SDD(GfxBase);
215 dd->dd_GC = HIDD_Gfx_NewGC(sdd->gfxhidd, gc_tags);
216 if (dd->dd_GC)
218 dd->dd_RastPort = rp;
219 dd->dd_LockCount = 1;
221 RP_DRIVERDATA(rp) = dd;
222 rp->Flags |= RPF_DRIVER_INITED;
224 if (!(rp->Flags & RPF_SELF_CLEANUP)) AddDriverDataToList(dd, GfxBase);
226 if (rp->BitMap) SetABPenDrMd(rp, (UBYTE)rp->FgPen, (UBYTE)rp->BgPen, rp->DrawMode);
228 else
230 FreePooled(PrivGBase(GfxBase)->driverdatapool, dd, sizeof(*dd));
231 dd = NULL;
234 } /* if (dd) */
236 } /* if (!dd) */
238 ReleaseSemaphore(&PrivGBase(GfxBase)->driverdatasem);
240 return dd ? TRUE : FALSE;
243 void ReleaseDriverData(struct RastPort *rp, struct GfxBase *GfxBase)
245 struct gfx_driverdata *dd = GetDriverData(rp);
247 if (!(rp->Flags & RPF_SELF_CLEANUP))
249 /* FIXME: stegerg 23 jan 2004: needs semprotection, too! */
250 /* CHECKME: stegerg 23 feb 2005: really?? */
252 dd->dd_LockCount--;
254 // Don't do this:
256 // if (!dd->dd_LockCount) KillDriverData(rp, GfxBase);
258 // some garbage collection should later hunt for dd's with
259 // 0 lockcount and possibly non-usage for a certain amount
260 // of time and get rid of them.
264 void KillDriverData(struct RastPort *rp, struct GfxBase *GfxBase)
266 if (RP_BACKPOINTER(rp) == rp)
268 struct gfx_driverdata *dd = NULL;
270 if (rp->Flags & RPF_SELF_CLEANUP)
272 dd = RP_DRIVERDATA(rp);
274 else
276 ObtainSemaphore(&PrivGBase(GfxBase)->driverdatasem);
277 if (FindDriverData(RP_DRIVERDATA(rp), rp, GfxBase))
279 dd = RP_DRIVERDATA(rp);
280 RemoveDriverDataFromList(dd, GfxBase);
282 ReleaseSemaphore(&PrivGBase(GfxBase)->driverdatasem);
285 if (dd)
287 struct shared_driverdata *sdd;
289 sdd = SDD(GfxBase);
291 HIDD_Gfx_DisposeGC(sdd->gfxhidd, dd->dd_GC);
292 FreePooled(PrivGBase(GfxBase)->driverdatapool, dd, sizeof(*dd));
293 RP_DRIVERDATA(rp) = NULL;
300 #else
302 struct gfx_driverdata * obsolete_InitDriverData (struct RastPort * rp, struct GfxBase * GfxBase)
304 struct gfx_driverdata * dd;
305 EnterFunc(bug("InitDriverData(rp=%p)\n", rp));
307 /* Does this rastport have a bitmap ? */
308 //if (rp->BitMap)
310 D(bug("Got bitmap\n"));
311 /* Displayable ? (== rastport of a screen) */
312 //if (IS_HIDD_BM(rp->BitMap))
314 D(bug("Has HIDD bitmap (displayable)\n"));
316 /* We can use this rastport. Allocate driverdata */
317 dd = AllocMem (sizeof(struct gfx_driverdata), MEMF_CLEAR);
318 if (dd)
320 struct shared_driverdata *sdd;
321 struct TagItem gc_tags[] = {
322 { TAG_DONE, 0UL}
326 D(bug("Got driverdata\n"));
327 sdd = SDD(GfxBase);
329 dd->dd_GC = HIDD_Gfx_NewGC(sdd->gfxhidd, gc_tags);
330 if (dd->dd_GC)
333 D(bug("Got GC HIDD object\n"));
334 dd->dd_RastPort = rp;
335 SetDriverData(rp, dd);
336 rp->Flags |= RPF_DRIVER_INITED;
338 ReturnPtr("InitDriverData", struct gfx_driverdata *, dd);
341 FreeMem(dd, sizeof (struct gfx_driverdata));
347 ReturnPtr("InitDriverData", struct gfx_driverdata *, NULL);
350 void obsolete_DeinitDriverData (struct RastPort * rp, struct GfxBase * GfxBase)
352 struct gfx_driverdata * dd;
353 struct shared_driverdata *sdd;
355 EnterFunc(bug("DeInitDriverData(rp=%p)\n", rp));
357 sdd = SDD(GfxBase);
359 dd = RP_DRIVERDATA(rp);;
360 RP_DRIVERDATA(rp) = 0;
362 HIDD_Gfx_DisposeGC(sdd->gfxhidd, dd->dd_GC);
364 FreeMem (dd, sizeof(struct gfx_driverdata));
365 rp->Flags &= ~RPF_DRIVER_INITED;
367 ReturnVoid("DeinitDriverData");
370 BOOL obsolete_CorrectDriverData (struct RastPort * rp, struct GfxBase * GfxBase)
372 BOOL retval = TRUE;
373 struct gfx_driverdata * dd, * old;
375 if (!rp)
377 retval = FALSE;
379 else
381 old = GetDriverData(rp);
382 if (!old)
384 old = obsolete_InitDriverData(rp, GfxBase);
386 /* stegerg: ???? would have returned TRUE even if old == NULL
387 if (old)
388 retval = TRUE;
390 if (!old) retval = FALSE;
392 else if (rp != old->dd_RastPort)
394 /* stegerg: cloned rastport?
395 ** Make sure to clear driverdata pointer and flag
396 ** in case InitDriverData fail
398 RP_DRIVERDATA(rp) = 0;
399 rp->Flags &= ~RPF_DRIVER_INITED;
401 dd = obsolete_InitDriverData(rp, GfxBase);
403 /* stegerg: ???? would have returned TRUE even if dd = NULL
404 if (dd)
405 retval = TRUE;
408 if (!dd) retval = FALSE;
413 return retval;
416 #endif
418 int driver_init(struct GfxBase * GfxBase)
421 EnterFunc(bug("driver_init()\n"));
423 /* Initialize the semaphore used for the chunky buffer */
424 InitSemaphore(&(PrivGBase(GfxBase)->pixbuf_sema));
425 InitSemaphore(&(PrivGBase(GfxBase)->blit_sema));
427 /* Init the needed attrbases */
429 __IHidd_BitMap = OOP_ObtainAttrBase(IID_Hidd_BitMap);
430 __IHidd_GC = OOP_ObtainAttrBase(IID_Hidd_GC);
431 __IHidd_Sync = OOP_ObtainAttrBase(IID_Hidd_Sync);
432 __IHidd_PixFmt = OOP_ObtainAttrBase(IID_Hidd_PixFmt);
433 __IHidd_PlanarBM = OOP_ObtainAttrBase(IID_Hidd_PlanarBM);
434 __IHidd_Gfx = OOP_ObtainAttrBase(IID_Hidd_Gfx);
435 __IHidd_FakeGfxHidd = OOP_ObtainAttrBase(IID_Hidd_FakeGfxHidd);
438 if (__IHidd_BitMap &&
439 __IHidd_GC &&
440 __IHidd_Sync &&
441 __IHidd_PixFmt &&
442 __IHidd_PlanarBM &&
443 __IHidd_Gfx &&
444 __IHidd_FakeGfxHidd)
446 PrivGBase(GfxBase)->pixel_buf=AllocMem(PIXELBUF_SIZE,MEMF_ANY);
447 if (PrivGBase(GfxBase)->pixel_buf) {
449 ReturnInt("driver_init", int, TRUE);
451 FreeMem(PrivGBase(GfxBase)->pixel_buf, PIXELBUF_SIZE);
456 ReturnInt("driver_init", int, FALSE);
459 int driver_open (struct GfxBase * GfxBase)
461 return TRUE;
464 void driver_close (struct GfxBase * GfxBase)
466 return;
469 void driver_expunge (struct GfxBase * GfxBase)
472 /* Try to free some other stuff */
473 cleanup_cursor(GfxBase);
475 if (SDD(GfxBase)->framebuffer)
476 OOP_DisposeObject(SDD(GfxBase)->framebuffer);
478 #if 0
479 if (SDD(GfxBase)->activescreen_inited)
480 cleanup_activescreen_stuff(GfxBase);
481 #endif
482 if (SDD(GfxBase)->dispinfo_db)
483 destroy_dispinfo_db(SDD(GfxBase)->dispinfo_db, GfxBase);
485 if ( SDD(GfxBase)->planarbm_cache )
486 delete_object_cache( SDD(GfxBase)->planarbm_cache, GfxBase );
488 if ( SDD(GfxBase)->gc_cache )
489 delete_object_cache( SDD(GfxBase)->gc_cache, GfxBase );
491 if ( SDD(GfxBase)->fakegfx_inited )
492 cleanup_fakegfxhidd( &SDD(GfxBase)->fakegfx_staticdata, GfxBase);
494 if ( SDD(GfxBase)->gfxhidd_orig )
495 OOP_DisposeObject( SDD(GfxBase)->gfxhidd_orig );
497 return;
500 /* Called after DOS is up & running */
501 static OOP_Object *create_framebuffer(struct GfxBase *GfxBase)
503 struct TagItem fbtags[] = {
504 { aHidd_BitMap_FrameBuffer, TRUE },
505 { aHidd_BitMap_ModeID, 0 },
506 { TAG_DONE, 0 }
509 HIDDT_ModeID hiddmode;
510 OOP_Object *fb = NULL;
512 /* Get the highest available resolution at the best possible depth */
513 hiddmode = get_best_resolution_and_depth(GfxBase);
514 if (vHidd_ModeID_Invalid == hiddmode) {
515 D(bug("!!! create_framebuffer(): COULD NOT GET HIDD MODEID !!!\n"));
516 } else {
517 /* Create the framebuffer object */
518 fbtags[1].ti_Data = hiddmode;
519 fb = HIDD_Gfx_NewBitMap(SDD(GfxBase)->gfxhidd, fbtags);
522 return fb;
524 const UBYTE def_pointer_shape[] =
526 06,02,00,00,00,00,00,00,00,00,00,
527 01,06,02,02,00,00,00,00,00,00,00,
528 00,01,06,06,02,02,00,00,00,00,00,
529 00,01,06,06,06,06,02,02,00,00,00,
530 00,00,01,06,06,06,06,06,02,02,00,
531 00,00,01,06,06,06,06,06,06,06,00,
532 00,00,00,01,06,06,06,02,00,00,00,
533 00,00,00,01,06,06,01,06,02,00,00,
534 00,00,00,00,01,06,00,01,06,02,00,
535 00,00,00,00,01,06,00,00,01,06,02,
536 00,00,00,00,00,00,00,00,00,01,06
539 #define DEF_POINTER_WIDTH 11
540 #define DEF_POINTER_HEIGHT 11
541 #define DEF_POINTER_DEPTH 7
544 static BOOL init_cursor(struct GfxBase *GfxBase)
546 /* Create the pointer bitmap */
547 struct TagItem pbmtags[] = {
548 { aHidd_BitMap_Width, DEF_POINTER_WIDTH },
549 { aHidd_BitMap_Height, DEF_POINTER_HEIGHT },
550 { aHidd_BitMap_StdPixFmt, vHidd_StdPixFmt_LUT8 },
551 { TAG_DONE, 0UL }
553 SDD(GfxBase)->pointerbm = HIDD_Gfx_NewBitMap(SDD(GfxBase)->gfxhidd, pbmtags);
554 if (NULL != SDD(GfxBase)->pointerbm) {
555 OOP_Object *gc;
557 gc = obtain_cache_object(SDD(GfxBase)->gc_cache, GfxBase);
558 if (NULL != gc) {
559 /* Copy the default pointer image into the created pointer bitmap */
560 ULONG i;
561 struct TagItem gc_tags[] = {
562 { aHidd_GC_DrawMode, vHidd_GC_DrawMode_Copy },
563 { TAG_DONE, 0UL }
566 HIDDT_Color col[DEF_POINTER_DEPTH];
568 col[0].red = 0x0000;
569 col[0].green = 0x0000;
570 col[0].blue = 0x0000;
571 col[0].alpha = 0x0000;
572 col[1].red = 0x0000;
573 col[1].green = 0x0000;
574 col[1].blue = 0x1200;
575 col[1].alpha = 0x0000;
576 col[2].red = 0xE0E0;
577 col[2].green = 0xE0E0;
578 col[2].blue = 0xC0C0;
579 col[2].alpha = 0x0000;
580 col[6].red = 0xE0E0;
581 col[6].green = 0x4040;
582 col[6].blue = 0x4040;
583 col[6].alpha = 0x0000;
585 for (i = 3; i < 6; i ++) {
586 col[i].red = 0x0000;
587 col[i].green = 0x0000;
588 col[i].blue = 0x0000;
589 col[i].alpha = 0x0000;
591 for (i = 7; i < DEF_POINTER_DEPTH; i ++) {
592 col[i].red = 0x0000;
593 col[i].green = 0x0000;
594 col[i].blue = 0x0000;
595 col[i].alpha = 0x0000;
598 HIDD_BM_SetColors(SDD(GfxBase)->pointerbm, col, 0, DEF_POINTER_DEPTH);
600 OOP_SetAttrs(gc, gc_tags);
601 #if 0
602 /* PutImageLUT not yet implemented in gfx baseclass */
603 HIDD_BM_PutImageLUT(SDD(GfxBase)->pointerbm, gc
604 , (UBYTE *)def_pointer_shape
605 , DEF_POINTER_WIDTH
606 , 0, 0
607 , DEF_POINTER_WIDTH, DEF_POINTER_HEIGHT
608 , &plut
610 #else
611 HIDD_BM_PutImage(SDD(GfxBase)->pointerbm, gc
612 , (UBYTE *)def_pointer_shape
613 , DEF_POINTER_WIDTH
614 , 0, 0
615 , DEF_POINTER_WIDTH, DEF_POINTER_HEIGHT
616 , vHidd_StdPixFmt_LUT8
619 #endif
620 release_cache_object(SDD(GfxBase)->gc_cache, gc, GfxBase);
622 if (HIDD_Gfx_SetCursorShape(SDD(GfxBase)->gfxhidd, SDD(GfxBase)->pointerbm)) {
623 D(bug("CURSOR SHAPE SET\n"));
624 /* Make it visible */
625 HIDD_Gfx_SetCursorVisible(SDD(GfxBase)->gfxhidd, TRUE);
627 return TRUE;
632 cleanup_cursor(GfxBase);
634 return FALSE;
637 static VOID cleanup_cursor(struct GfxBase *GfxBase)
639 if (NULL != SDD(GfxBase)->pointerbm) {
640 OOP_DisposeObject(SDD(GfxBase)->pointerbm);
641 SDD(GfxBase)->pointerbm = NULL;
645 BOOL driver_LateGfxInit (APTR data, struct GfxBase *GfxBase)
648 /* Supplied data is really the librarybase of a HIDD */
649 STRPTR gfxhiddname = (STRPTR)data;
650 struct TagItem tags[] = {
651 { TAG_DONE, 0UL },
653 EnterFunc(bug("driver_LateGfxInit(gfxhiddname=%s)\n", gfxhiddname));
655 /* Create a new GfxHidd object */
657 SDD(GfxBase)->gfxhidd = SDD(GfxBase)->gfxhidd_orig = OOP_NewObject(NULL, gfxhiddname, tags);
658 D(bug("driver_LateGfxInit: gfxhidd=%p\n", SDD(GfxBase)->gfxhidd));
660 if (NULL != SDD(GfxBase)->gfxhidd) {
661 IPTR hwcursor;
662 BOOL ok = TRUE;
664 /* Get method id here, to avoid any possible semaphore involment when calling the method */
665 SDD(GfxBase)->hiddGfxShowImminentReset_MethodID = OOP_GetMethodID(IID_Hidd_Gfx, moHidd_Gfx_ShowImminentReset);
667 OOP_GetAttr(SDD(GfxBase)->gfxhidd, aHidd_Gfx_SupportsHWCursor, &hwcursor);
668 SDD(GfxBase)->has_hw_cursor = (BOOL)hwcursor;
669 if (!hwcursor) {
670 OOP_Object *fgh;
671 D(bug("There's no hardware cursor\n"));
673 fgh = init_fakegfxhidd(SDD(GfxBase)->gfxhidd
674 , &SDD(GfxBase)->fakegfx_staticdata
675 , GfxBase);
677 if (NULL != fgh) {
678 SDD(GfxBase)->gfxhidd = fgh;
679 SDD(GfxBase)->fakegfx_inited = TRUE;
680 } else {
681 ok = FALSE;
685 if (ok) {
686 struct TagItem gc_create_tags[] = { { TAG_DONE, 0UL } };
687 D(bug("Ok\n"));
688 SDD(GfxBase)->gc_cache = create_object_cache(NULL, IID_Hidd_GC, gc_create_tags, GfxBase);
689 if (NULL != SDD(GfxBase)->gc_cache) {
691 struct TagItem bm_create_tags[] = {
692 #warning Maybe make this class private and create the object through the graphicshidd
693 { aHidd_BitMap_GfxHidd, (IPTR)SDD(GfxBase)->gfxhidd_orig },
694 { aHidd_BitMap_Displayable, FALSE },
695 { aHidd_PlanarBM_AllocPlanes, FALSE },
696 { TAG_DONE, 0UL }
699 D(bug("Cache created\n"));
700 SDD(GfxBase)->planarbm_cache = create_object_cache(NULL, CLID_Hidd_PlanarBM, bm_create_tags, GfxBase);
702 if (NULL != SDD(GfxBase)->planarbm_cache) {
704 /* Move the modes into the displayinfo DB */
705 SDD(GfxBase)->dispinfo_db = build_dispinfo_db(GfxBase);
706 if (NULL != SDD(GfxBase)->dispinfo_db) {
708 SDD(GfxBase)->framebuffer = create_framebuffer(GfxBase);
709 if (NULL != SDD(GfxBase)->framebuffer) {
710 D(bug("FRAMEBUFFER OK: %p\n", SDD(GfxBase)->framebuffer));
711 if (init_cursor(GfxBase)) {
713 D(bug("MOUSE INITED\n"));
714 ReturnBool("driver_LateGfxInit", TRUE);
716 OOP_DisposeObject(SDD(GfxBase)->framebuffer);
717 } /* if (framebuffer inited) */
718 destroy_dispinfo_db(SDD(GfxBase)->dispinfo_db, GfxBase);
719 SDD(GfxBase)->dispinfo_db = NULL;
720 } /* if (displayinfo db inited) */
721 delete_object_cache(SDD(GfxBase)->planarbm_cache, GfxBase);
722 SDD(GfxBase)->planarbm_cache = NULL;
723 } /* if (planarbm cache created) */
724 delete_object_cache(SDD(GfxBase)->gc_cache, GfxBase);
725 SDD(GfxBase)->gc_cache = NULL;
726 } /* if (gc object cache ok) */
728 } /* if (fake gfx stuff ok) */
730 if (SDD(GfxBase)->fakegfx_inited) {
731 cleanup_fakegfxhidd(&SDD(GfxBase)->fakegfx_staticdata, GfxBase);
732 SDD(GfxBase)->fakegfx_inited = FALSE;
734 OOP_DisposeObject(SDD(GfxBase)->gfxhidd_orig);
735 SDD(GfxBase)->gfxhidd_orig = NULL;
739 ReturnBool("driver_LateGfxInit", FALSE);
744 #if 0 /* Unused? */
746 static ULONG getbitmappixel(struct BitMap *bm
747 , LONG x
748 , LONG y
749 , UBYTE depth
750 , UBYTE plane_mask)
752 UBYTE i;
753 ULONG idx;
755 ULONG mask;
756 ULONG pen = 0L;
758 idx = COORD_TO_BYTEIDX(x, y, bm->BytesPerRow);
759 mask = XCOORD_TO_MASK( x );
761 for (i = depth - 1; depth; i -- , depth -- )
763 pen <<= 1; /* stegerg: moved to here, was inside if!? */
765 if ((1L << i) & plane_mask)
767 UBYTE *plane = bm->Planes[i];
769 if (plane == (PLANEPTR)-1)
771 pen |= 1;
773 else if (plane != NULL)
775 if ((plane[idx] & mask) != 0)
776 pen |= 1;
781 return pen;
784 #endif
787 #define dumprect(rect) \
788 kprintf(#rect " : (%d,%d) - (%d,%d)\n",(rect)->MinX,(rect)->MinY,(rect)->MaxX,(rect)->MaxY)
791 struct bgf_render_data {
792 WORD fbm_xsrc;
793 OOP_Object *fbm;
796 static ULONG bgf_render(APTR bgfr_data
797 , LONG srcx, LONG srcy
798 , OOP_Object *dstbm_obj, OOP_Object *dst_gc
799 , LONG x1, LONG y1, LONG x2, LONG y2
800 , struct GfxBase *GfxBase)
802 struct bgf_render_data *bgfrd;
803 ULONG width, height;
805 width = x2 - x1 + 1;
806 height = y2 - y1 + 1;
808 ASSERT(width > 0 && height > 0);
810 bgfrd = (struct bgf_render_data *)bgfr_data;
812 HIDD_BM_BlitColorExpansion( dstbm_obj
813 , dst_gc
814 , bgfrd->fbm
815 , srcx + bgfrd->fbm_xsrc, srcy /* stegerg: instead of srcy there was a 0 */
816 , x1, y1
817 , width, height
820 return width * height;
824 void blit_glyph_fast(struct RastPort *rp, OOP_Object *fontbm, WORD xsrc
825 , WORD destx, WORD desty, UWORD width, UWORD height
826 , struct GfxBase * GfxBase)
829 struct Rectangle rr;
830 struct bgf_render_data bgfrd;
832 EnterFunc(bug("blit_glyph_fast(%d, %d, %d, %d, %d)\n"
833 , xsrc, destx, desty, width, height));
836 ASSERT(width > 0 && height > 0);
838 bgfrd.fbm_xsrc = xsrc;
839 bgfrd.fbm = fontbm;
841 rr.MinX = destx;
842 rr.MinY = desty;
843 rr.MaxX = destx + width - 1;
844 rr.MaxY = desty + height - 1;
846 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
847 ReturnVoid("blit_glyph_fast");
849 do_render_func(rp, NULL, &rr, bgf_render, &bgfrd, FALSE, GfxBase);
851 RELEASE_DRIVERDATA(rp, GfxBase);
853 ReturnVoid("blit_glyph_fast");
858 #define NUMCHARS(tf) ((tf->tf_HiChar - tf->tf_LoChar) + 2)
859 #define CTF(x) ((struct ColorTextFont *)x)
861 void driver_Text (struct RastPort * rp, CONST_STRPTR string, LONG len,
862 struct GfxBase * GfxBase)
865 #warning Does not handle color textfonts
866 WORD render_y;
867 struct TextFont *tf;
868 WORD current_x;
869 OOP_Object *fontbm = NULL;
871 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
872 return;
874 if ((rp->DrawMode & ~INVERSVID) == JAM2)
876 struct TextExtent te;
877 ULONG old_drmd = GetDrMd(rp);
879 /* This is actually needed, because below only the
880 part of the glyph which contains data is rendered:
882 ...1100...
883 ...1100...
884 ...1100...
885 ...1111...
887 '.' at left side can be there because of kerning.
888 '.' at the right side can be there because of
889 CharSpace being bigger than glyph bitmap data
890 width.
893 TextExtent(rp, string, len, &te);
894 SetDrMd(rp, old_drmd ^ INVERSVID);
895 RectFill(rp, rp->cp_x + te.te_Extent.MinX,
896 rp->cp_y + te.te_Extent.MinY,
897 rp->cp_x + te.te_Extent.MaxX,
898 rp->cp_y + te.te_Extent.MaxY);
899 SetDrMd(rp, old_drmd);
902 /* does this rastport have a layer. If yes, lock the layer it.*/
903 if (NULL != rp->Layer)
904 LockLayerRom(rp->Layer);
906 tf = rp->Font;
908 if (ExtendFont(tf, NULL))
910 fontbm = TFE_INTERN(tf->tf_Extension)->hash->font_bitmap;
913 /* Check if font has character data as a HIDD bitmap */
915 if (NULL == fontbm)
917 D(bug("FONT HAS NO HIDD BITMAP ! Won't render text\n"));
918 RELEASE_DRIVERDATA(rp, GfxBase);
919 return;
923 /* Render along font's baseline */
924 render_y = rp->cp_y - tf->tf_Baseline;
925 current_x = rp->cp_x;
927 while ( len -- )
929 ULONG charloc;
930 ULONG idx;
932 if (*string < tf->tf_LoChar || *string > tf->tf_HiChar )
934 /* A character which there is no glyph for. We just
935 draw the last glyph in the font
937 idx = NUMCHARS(tf) - 1;
939 else
941 idx = *string - tf->tf_LoChar;
944 charloc = ((ULONG *)tf->tf_CharLoc)[idx];
946 if (tf->tf_CharKern)
948 current_x += ((WORD *)tf->tf_CharKern)[idx];
951 if ((tf->tf_Style & FSF_COLORFONT) &&
952 !(CTF(tf)->ctf_Flags & CT_ANTIALIAS))
954 #warning Handle color fonts
956 else
958 WORD
959 glyphXOffset = charloc >> 16,
960 glyphWidth = charloc & 0xFFFF;
962 ASSERT(tf->tf_YSize > 0);
964 /* blit the glypth if it has data in the bitmap */
965 if (glyphWidth > 0)
967 blit_glyph_fast(rp, fontbm, glyphXOffset, current_x, render_y,
968 glyphWidth, tf->tf_YSize, GfxBase);
972 if (tf->tf_CharSpace)
973 current_x += ((WORD *)tf->tf_CharSpace)[idx];
974 else
975 current_x += tf->tf_XSize; /* Add glyph width */
977 current_x += rp->TxSpacing;
979 string ++;
980 } /* for (each character to render) */
982 Move(rp, current_x, rp->cp_y);
984 if (NULL != rp->Layer)
985 UnlockLayerRom(rp->Layer);
987 RELEASE_DRIVERDATA(rp, GfxBase);
989 return;
993 /***********************************************/
994 /* CYBERGFX CALLS ***/
997 struct wpa_render_data
999 UBYTE *array;
1000 HIDDT_StdPixFmt pixfmt;
1001 ULONG modulo;
1002 ULONG bppix;
1005 static ULONG wpa_render(APTR wpar_data
1006 , LONG srcx, LONG srcy
1007 , OOP_Object *dstbm_obj
1008 , OOP_Object *dst_gc
1009 , LONG x1, LONG y1, LONG x2, LONG y2
1010 , struct GfxBase *GfxBase)
1012 struct wpa_render_data *wpard;
1013 ULONG width, height;
1014 UBYTE *array;
1016 width = x2 - x1 + 1;
1017 height = y2 - y1 + 1;
1019 wpard = (struct wpa_render_data *)wpar_data;
1021 array = wpard->array + wpard->modulo * srcy + wpard->bppix * srcx;
1023 HIDD_BM_PutImage(dstbm_obj
1024 , dst_gc, array
1025 , wpard->modulo
1026 , x1, y1
1027 , width, height
1028 , wpard->pixfmt
1031 return width * height;
1034 struct wpaa_render_data
1036 UBYTE *array;
1037 ULONG modulo;
1040 static ULONG wpaa_render(APTR wpaar_data
1041 , LONG srcx, LONG srcy
1042 , OOP_Object *dstbm_obj
1043 , OOP_Object *dst_gc
1044 , LONG x1, LONG y1, LONG x2, LONG y2
1045 , struct GfxBase *GfxBase)
1047 struct wpaa_render_data *wpaard;
1048 ULONG width, height;
1049 UBYTE *array;
1051 width = x2 - x1 + 1;
1052 height = y2 - y1 + 1;
1054 wpaard = (struct wpaa_render_data *)wpaar_data;
1056 array = wpaard->array + wpaard->modulo * srcy + 4 * srcx;
1058 HIDD_BM_PutAlphaImage(dstbm_obj
1059 , dst_gc, array
1060 , wpaard->modulo
1061 , x1, y1
1062 , width, height
1065 return width * height;
1068 struct bta_render_data
1070 UBYTE *array;
1071 ULONG modulo;
1072 UBYTE invertalpha;
1075 static ULONG bta_render(APTR bta_data
1076 , LONG srcx, LONG srcy
1077 , OOP_Object *dstbm_obj
1078 , OOP_Object *dst_gc
1079 , LONG x1, LONG y1, LONG x2, LONG y2
1080 , struct GfxBase *GfxBase)
1082 struct bta_render_data *btard;
1083 ULONG width, height;
1084 UBYTE *array;
1086 width = x2 - x1 + 1;
1087 height = y2 - y1 + 1;
1089 btard = (struct bta_render_data *)bta_data;
1091 array = btard->array + btard->modulo * srcy + srcx;
1093 HIDD_BM_PutAlphaTemplate(dstbm_obj
1094 , dst_gc, array
1095 , btard->modulo
1096 , x1, y1
1097 , width, height
1098 , btard->invertalpha
1101 return width * height;
1104 struct rpa_render_data {
1105 UBYTE *array;
1106 HIDDT_StdPixFmt pixfmt;
1107 ULONG modulo;
1108 ULONG bppix;
1111 static ULONG rpa_render(APTR rpar_data
1112 , LONG srcx, LONG srcy
1113 , OOP_Object *dstbm_obj
1114 , OOP_Object *dst_gc
1115 , LONG x1, LONG y1, LONG x2, LONG y2
1116 , struct GfxBase *GfxBase)
1118 struct rpa_render_data *rpard;
1119 ULONG width, height;
1120 UBYTE *array;
1122 width = x2 - x1 + 1;
1123 height = y2 - y1 + 1;
1125 rpard = (struct rpa_render_data *)rpar_data;
1127 array = rpard->array + rpard->modulo * srcy + rpard->bppix * srcx;
1129 HIDD_BM_GetImage(dstbm_obj
1130 , array
1131 , rpard->modulo
1132 , x1, y1
1133 , width, height
1134 , rpard->pixfmt
1137 return width * height;
1140 static LONG pix_read(APTR pr_data
1141 , OOP_Object *bm, OOP_Object *gc
1142 , LONG x, LONG y
1143 , struct GfxBase *GfxBase)
1145 struct rgbpix_render_data *prd;
1147 prd = (struct rgbpix_render_data *)pr_data;
1149 prd->pixel = HIDD_BM_GetPixel(bm, x, y);
1152 return 0;
1156 struct extcol_render_data {
1157 struct render_special_info rsi;
1158 struct BitMap *destbm;
1159 HIDDT_Pixel pixel;
1163 static VOID buf_to_extcol(struct extcol_render_data *ecrd
1164 , LONG srcx, LONG srcy
1165 , LONG dstx, LONG dsty
1166 , ULONG width, ULONG height
1167 , HIDDT_Pixel *pixbuf
1168 , OOP_Object *bm_obj
1169 , HIDDT_Pixel *pixtab)
1171 LONG y;
1172 struct BitMap *bm;
1173 bm = ecrd->destbm;
1174 for (y = 0; y < height; y ++) {
1175 LONG x;
1177 for (x = 0; x < width; x ++) {
1178 if (*pixbuf ++ == ecrd->pixel) {
1180 UBYTE *plane;
1181 ULONG i;
1182 /* Set the according bit in the bitmap */
1183 for (i = 0; i < bm->Depth; i ++) {
1184 plane = bm->Planes[i];
1185 if (NULL != plane) {
1186 UBYTE mask;
1188 plane += COORD_TO_BYTEIDX(x + dstx, y + dsty, bm->BytesPerRow);
1189 mask = XCOORD_TO_MASK(x + dstx);
1191 /* Set the pixel */
1192 *plane |= mask;
1194 } /* if (plane allocated) */
1195 } /* for (plane) */
1196 } /* if (color match) */
1197 } /* for (x) */
1198 } /* for (y) */
1200 return;
1205 static ULONG extcol_render(APTR funcdata
1206 , LONG dstx, LONG dsty
1207 , OOP_Object *dstbm_obj
1208 , OOP_Object *dst_gc
1209 , LONG x1, LONG y1, LONG x2, LONG y2
1210 , struct GfxBase *GfxBase)
1212 /* Get the info from the hidd */
1213 struct extcol_render_data *ecrd;
1215 ecrd = (struct extcol_render_data *)funcdata;
1217 hidd2buf_fast(ecrd->rsi.curbm
1218 , x1, y1
1219 , (APTR)ecrd
1220 , dstx, dsty
1221 , x2 - x1 + 1
1222 , y2 - y1 + 1
1223 , buf_to_extcol
1224 , GfxBase
1227 return (x2 - x1 + 1) * (y2 - y1 + 1);
1231 struct dm_message {
1232 APTR memptr;
1233 ULONG offsetx;
1234 ULONG offsety;
1235 ULONG xsize;
1236 ULONG ysize;
1237 UWORD bytesperrow;
1238 UWORD bytesperpix;
1239 UWORD colormodel;
1243 struct dm_render_data {
1244 struct dm_message msg;
1245 OOP_Object *pf;
1246 struct Hook *hook;
1247 struct RastPort *rp;
1248 IPTR stdpf;
1249 OOP_Object *gc;
1253 static ULONG dm_render(APTR dmr_data
1254 , LONG srcx, LONG srcy
1255 , OOP_Object *dstbm_obj
1256 , OOP_Object *dst_gc
1257 , LONG x1, LONG y1, LONG x2, LONG y2
1258 , struct GfxBase *GfxBase)
1260 struct dm_render_data *dmrd;
1261 UBYTE *addr;
1262 struct dm_message *msg;
1263 IPTR bytesperpixel;
1264 ULONG width, height, fb_width, fb_height;
1265 ULONG banksize, memsize;
1267 dmrd = (struct dm_render_data *)dmr_data;
1268 width = x2 - x1 + 1;
1269 height = y2 - y1 + 1;;
1270 msg = &dmrd->msg;
1271 #if 1
1272 msg->offsetx = x1;
1273 msg->offsety = y1;
1274 #else
1275 #warning "Not sure about this one . Set it to 0 since we adjust msg->memptr to x1/y1 lower down"
1276 msg->offsetx = 0; // x1;
1277 msg->offsety = 0; // y1;
1278 #endif
1279 msg->xsize = width;
1280 msg->ysize = height;
1282 /* Get the baseadress from where to render */
1283 if (HIDD_BM_ObtainDirectAccess(dstbm_obj
1284 , &addr
1285 , &fb_height, &fb_width
1286 , &banksize, &memsize)) {
1288 OOP_GetAttr(dmrd->pf, aHidd_PixFmt_BytesPerPixel, &bytesperpixel);
1289 msg->bytesperpix = (UWORD)bytesperpixel;
1291 /* Colormodel allready set */
1293 /* Compute the adress for the start pixel */
1294 #warning "We should maybe use something else than the BytesPerLine method since we may have alignment"
1295 msg->bytesperrow = HIDD_BM_BytesPerLine(dstbm_obj, dmrd->stdpf, width);
1296 #if 1
1297 msg->memptr = addr;
1298 #else
1299 msg->memptr = addr + (msg->bytesperrow * y1) + (bytesperpixel * x1);
1300 #endif
1302 HIDD_BM_ReleaseDirectAccess(dstbm_obj);
1304 CallHookPkt(dmrd->hook, dmrd->rp, msg);
1306 } else {
1307 /* We are unable to gain direct access to the framebuffer,
1308 so we have to emulate it
1310 ULONG bytesperrow;
1311 ULONG tocopy_h, max_tocopy_h;
1312 ULONG lines_todo;
1314 lines_todo = height;
1316 /* The HIDD bm does not have a base adress so we have to render into
1317 it using a temporary buffer
1319 OOP_GetAttr(dmrd->pf, aHidd_PixFmt_BytesPerPixel, &bytesperpixel);
1320 //bytesperrow = HIDD_BM_BytesPerLine(dstbm_obj, dmrd->stdpf, width);
1321 bytesperrow = width * bytesperpixel;
1324 kprintf("width %d bytesperrow %d bytesperpixel %d\n", width, bytesperrow, bytesperpixel);
1325 kprintf(" colormodel %d\n", msg->colormodel);
1327 if (PIXELBUF_SIZE < bytesperrow) {
1328 D(bug("!!! NOT ENOUGH SPACE IN TEMP BUFFER FOR A SINGLE LINE IN DoCDrawMethodTagList() !!!\n"));
1329 return 0;
1332 /* Calculate number of lines we might copy */
1333 max_tocopy_h = PIXELBUF_SIZE / bytesperrow;
1335 #if 1
1336 msg->offsetx = 0;
1337 msg->offsety = 0;
1338 #endif
1339 /* Get the maximum number of lines */
1340 while (lines_todo != 0) {
1342 struct TagItem gc_tags[] = {
1343 { aHidd_GC_DrawMode, vHidd_GC_DrawMode_Copy },
1344 { TAG_DONE, 0UL }
1347 IPTR old_drmd;
1349 tocopy_h = MIN(lines_todo, max_tocopy_h);
1350 msg->memptr = PrivGBase(GfxBase)->pixel_buf;
1351 msg->bytesperrow = bytesperrow;
1353 msg->bytesperpix = (UWORD)bytesperpixel;
1355 LOCK_PIXBUF
1356 HIDD_BM_GetImage(dstbm_obj
1357 , (UBYTE *)PrivGBase(GfxBase)->pixel_buf
1358 , bytesperrow
1359 , x1, y1 + height - lines_todo, width, lines_todo
1360 , dmrd->stdpf
1363 /* Use the hook to set some pixels */
1364 CallHookPkt(dmrd->hook, dmrd->rp, msg);
1366 OOP_GetAttr(dmrd->gc, aHidd_GC_DrawMode, &old_drmd);
1367 OOP_SetAttrs(dmrd->gc, gc_tags);
1368 HIDD_BM_PutImage(dstbm_obj, dmrd->gc
1369 , (UBYTE *)PrivGBase(GfxBase)->pixel_buf
1370 , bytesperrow
1371 , x1, y1 + height - lines_todo, width, lines_todo
1372 , dmrd->stdpf
1374 gc_tags[0].ti_Data = (IPTR)old_drmd;
1375 OOP_SetAttrs(dmrd->gc, gc_tags);
1377 ULOCK_PIXBUF
1379 lines_todo -= tocopy_h;
1384 return width * height;
1389 LONG driver_WriteLUTPixelArray(APTR srcrect,
1390 UWORD srcx, UWORD srcy,
1391 UWORD srcmod, struct RastPort *rp, APTR ctable,
1392 UWORD destx, UWORD desty,
1393 UWORD sizex, UWORD sizey,
1394 UBYTE ctabformat,
1395 struct GfxBase *GfxBase)
1397 ULONG depth;
1399 HIDDT_PixelLUT pixlut;
1400 HIDDT_Pixel pixtab[256];
1402 HIDDT_Color col;
1403 ULONG i;
1405 LONG pixwritten = 0;
1406 UBYTE *buf;
1408 /* This is cybergraphx. We only work wih HIDD bitmaps */
1409 if (!IS_HIDD_BM(rp->BitMap)) {
1410 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WriteLUTPixelArray()!!!\n"));
1411 return 0;
1414 pixlut.entries = 256;
1415 pixlut.pixels = pixtab;
1417 depth = GetBitMapAttr(rp->BitMap, BMA_DEPTH);
1419 /* This call does only support bitmaps with depth > 8. Use WritePixelArray8
1420 for other bitmaps
1423 if (depth <= 8) {
1424 D(bug("!!! TRYING TO USE WriteLUTPixelArray() ON BITMAP WITH DEPTH < 8\n"));
1425 return 0;
1428 /* Curently only one format is supported */
1429 if (CTABFMT_XRGB8 != ctabformat) {
1430 D(bug("!!! WriteLUTPixelArray() CALLED WITH UNSUPPORTED CTAB FORMAT %d\n"
1431 , ctabformat));
1432 return 0;
1434 col.alpha = 0;
1436 /* Convert the coltab into native pixels */
1437 for (i = 0; i < 256; i ++) {
1438 register ULONG rgb = ((ULONG *)ctable)[i];
1439 col.red = (HIDDT_ColComp)((rgb & 0x00FF0000) >> 8);
1440 col.green = (HIDDT_ColComp)(rgb & 0x0000FF00);
1441 col.blue = (HIDDT_ColComp)((rgb & 0x000000FF) << 8);
1443 pixtab[i] = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
1446 buf = (UBYTE *)srcrect;
1448 buf += CHUNKY8_COORD_TO_BYTEIDX(srcx, srcy, srcmod);
1450 pixwritten = write_pixels_8(rp
1451 , buf
1452 , srcmod
1453 , destx, desty
1454 , destx + sizex - 1, desty + sizey - 1
1455 , &pixlut
1456 , GfxBase
1460 /* Now blit the colors onto the screen */
1462 return pixwritten;
1466 LONG driver_WritePixelArray(APTR src, UWORD srcx, UWORD srcy
1467 , UWORD srcmod, struct RastPort *rp, UWORD destx, UWORD desty
1468 , UWORD width, UWORD height, UBYTE srcformat, struct GfxBase *GfxBase)
1471 OOP_Object *pf = 0;
1472 HIDDT_StdPixFmt srcfmt_hidd = 0, morphfmt_hidd = 0;
1473 ULONG start_offset;
1474 IPTR bppix;
1476 LONG pixwritten = 0;
1478 struct wpa_render_data wpard;
1479 struct Rectangle rr;
1481 if (RECTFMT_GREY8 == srcformat)
1483 static ULONG greytab[256];
1485 /* Ignore possible race conditions during
1486 initialization. Have no bad effect. Just
1487 double initializations. */
1489 /* FIXME/KILLME: evil static array which goes into BSS section
1490 which x86 native AROS regards as evil! */
1492 if (greytab[255] == 0)
1494 WORD i;
1496 for(i = 0; i < 256; i++)
1498 greytab[i] = i * 0x010101;
1502 return driver_WriteLUTPixelArray(src, srcx, srcy, srcmod,
1503 rp, greytab, destx, desty,
1504 width, height, CTABFMT_XRGB8,
1505 GfxBase);
1508 /* This is cybergraphx. We only work wih HIDD bitmaps */
1509 if (!IS_HIDD_BM(rp->BitMap))
1511 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WritePixelArray() !!!\n"));
1512 return 0;
1515 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
1516 return 0;
1518 if (RECTFMT_LUT8 == srcformat)
1521 HIDDT_PixelLUT pixlut = { 256, HIDD_BM_PIXTAB(rp->BitMap) };
1522 UBYTE * array = (UBYTE *)src;
1524 if (rp->BitMap->Flags & BMF_SPECIALFMT)
1526 RELEASE_DRIVERDATA(rp, GfxBase);
1527 D(bug("!!! No CLUT in driver_WritePixelArray\n"));
1528 return 0;
1531 array += CHUNKY8_COORD_TO_BYTEIDX(srcx, srcy, srcmod);
1533 pixwritten = write_pixels_8(rp
1534 , array, srcmod
1535 , destx, desty
1536 , destx + width - 1, desty + height - 1
1537 , &pixlut
1538 , GfxBase);
1540 RELEASE_DRIVERDATA(rp, GfxBase);
1542 return pixwritten;
1545 switch (srcformat)
1547 case RECTFMT_RGB15 : srcfmt_hidd = vHidd_StdPixFmt_RGB15 ; break;
1548 case RECTFMT_BGR15 : srcfmt_hidd = vHidd_StdPixFmt_BGR15 ; break;
1549 case RECTFMT_RGB15PC: srcfmt_hidd = vHidd_StdPixFmt_RGB15_LE; break;
1550 case RECTFMT_BGR15PC: srcfmt_hidd = vHidd_StdPixFmt_BGR15_LE; break;
1551 case RECTFMT_RGB16 : srcfmt_hidd = vHidd_StdPixFmt_RGB16 ; break;
1552 case RECTFMT_BGR16 : srcfmt_hidd = vHidd_StdPixFmt_BGR16 ; break;
1553 case RECTFMT_RGB16PC: srcfmt_hidd = vHidd_StdPixFmt_RGB16_LE; break;
1554 case RECTFMT_BGR16PC: srcfmt_hidd = vHidd_StdPixFmt_BGR16_LE; break;
1555 case RECTFMT_RGB24 : srcfmt_hidd = vHidd_StdPixFmt_RGB24 ; break;
1556 case RECTFMT_BGR24 : srcfmt_hidd = vHidd_StdPixFmt_BGR24 ; break;
1557 case RECTFMT_ARGB32 : srcfmt_hidd = vHidd_StdPixFmt_ARGB32 ; morphfmt_hidd = vHidd_StdPixFmt_0RGB32; break;
1558 case RECTFMT_BGRA32 : srcfmt_hidd = vHidd_StdPixFmt_BGRA32 ; morphfmt_hidd = vHidd_StdPixFmt_BGR032; break;
1559 case RECTFMT_RGBA32 : srcfmt_hidd = vHidd_StdPixFmt_RGBA32 ; morphfmt_hidd = vHidd_StdPixFmt_RGB032; break;
1560 case RECTFMT_ABGR32 : srcfmt_hidd = vHidd_StdPixFmt_ABGR32 ; morphfmt_hidd = vHidd_StdPixFmt_0BGR32; break;
1561 case RECTFMT_RAW : srcfmt_hidd = vHidd_StdPixFmt_Native; break;
1564 /* Compute the start of the array */
1566 #warning Get rid of the below code ?
1567 /* This can be done by passing the srcx and srcy parameters on to
1568 the HIDD bitmap and let it take care of it itself.
1569 This means that HIDD_BM_PutImage() gets a lot of parameters,
1570 which may not be necessary in real life.
1572 Compromise: convert from *CyberGfx* pixfmt to bppix using a table lookup.
1573 This is faster
1575 if ((srcfmt_hidd == vHidd_StdPixFmt_Native) || (morphfmt_hidd != 0))
1577 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&pf);
1580 if (srcfmt_hidd != vHidd_StdPixFmt_Native)
1582 /* RECTFMT_ARGB32 on vHidd_StdPixFmt_0RGB32 bitmap ==> use vHidd_StdPixFmt_0RGB32 */
1583 /* RECTFMT_BGRA32 on vHidd_StdPixFmt_BGR032 bitmap ==> use vHidd_StdPixFmt_BGR032 */
1584 /* RECTFMT_RGBA32 on vHidd_StdPixFmt_RGB032 bitmap ==> use vHidd_StdPixFmt_RGB032 */
1585 /* RECTFMT_ABGR32 on vHidd_StdPixFmt_0BGR32 bitmap ==> use vHidd_StdPixFmt_0BGR32 */
1587 if (morphfmt_hidd != 0)
1589 IPTR stdpf;
1591 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, (IPTR *)&stdpf);
1592 if (stdpf == morphfmt_hidd) srcfmt_hidd = morphfmt_hidd;
1595 pf = HIDD_Gfx_GetPixFmt(SDD(GfxBase)->gfxhidd, srcfmt_hidd);
1598 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, &bppix);
1600 start_offset = ((ULONG)srcy) * srcmod + srcx * bppix;
1602 wpard.array = ((UBYTE *)src) + start_offset;
1603 wpard.pixfmt = srcfmt_hidd;
1604 wpard.modulo = srcmod;
1605 wpard.bppix = bppix;
1607 rr.MinX = destx;
1608 rr.MinY = desty;
1609 rr.MaxX = destx + width - 1;
1610 rr.MaxY = desty + height - 1;
1612 pixwritten = do_render_func(rp, NULL, &rr, wpa_render, &wpard, FALSE, GfxBase);
1614 RELEASE_DRIVERDATA(rp, GfxBase);
1616 return pixwritten;
1619 LONG driver_WritePixelArrayAlpha(APTR src, UWORD srcx, UWORD srcy
1620 , UWORD srcmod, struct RastPort *rp, UWORD destx, UWORD desty
1621 , UWORD width, UWORD height, ULONG globalalpha, struct GfxBase *GfxBase)
1623 ULONG start_offset;
1624 LONG pixwritten = 0;
1625 struct wpaa_render_data wpaard;
1626 struct Rectangle rr;
1628 /* This is cybergraphx. We only work wih HIDD bitmaps */
1629 if (!IS_HIDD_BM(rp->BitMap))
1631 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WritePixelArrayAlpha() !!!\n"));
1632 return 0;
1635 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
1636 return 0;
1638 /* Compute the start of the array */
1640 start_offset = ((ULONG)srcy) * srcmod + srcx * 4;
1642 wpaard.array = ((UBYTE *)src) + start_offset;
1643 wpaard.modulo = srcmod;
1645 rr.MinX = destx;
1646 rr.MinY = desty;
1647 rr.MaxX = destx + width - 1;
1648 rr.MaxY = desty + height - 1;
1650 pixwritten = do_render_func(rp, NULL, &rr, wpaa_render, &wpaard, FALSE, GfxBase);
1652 RELEASE_DRIVERDATA(rp, GfxBase);
1654 return pixwritten;
1657 LONG driver_ReadPixelArray(APTR dst, UWORD destx, UWORD desty
1658 , UWORD dstmod, struct RastPort *rp, UWORD srcx, UWORD srcy
1659 , UWORD width, UWORD height, UBYTE dstformat, struct GfxBase *GfxBase)
1662 OOP_Object *pf = 0;
1663 HIDDT_StdPixFmt dstfmt_hidd = 0, morphfmt_hidd = 0;
1665 ULONG start_offset;
1666 IPTR bppix;
1668 LONG pixread = 0;
1669 IPTR old_drmd;
1670 OOP_Object *gc;
1672 struct Rectangle rr;
1673 struct rpa_render_data rpard;
1675 struct TagItem gc_tags[] =
1677 { aHidd_GC_DrawMode , vHidd_GC_DrawMode_Copy},
1678 { TAG_DONE }
1681 /* This is cybergraphx. We only work wih HIDD bitmaps */
1682 if (!IS_HIDD_BM(rp->BitMap))
1684 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in ReadPixelArray() !!!\n"));
1685 return 0;
1688 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
1689 return 0;
1691 gc = GetDriverData(rp)->dd_GC;
1693 /* Preserve old drawmode */
1694 OOP_GetAttr(gc, aHidd_GC_DrawMode, &old_drmd);
1695 OOP_SetAttrs(gc, gc_tags);
1698 switch (dstformat)
1700 case RECTFMT_RGB15 : dstfmt_hidd = vHidd_StdPixFmt_RGB15 ; break;
1701 case RECTFMT_BGR15 : dstfmt_hidd = vHidd_StdPixFmt_BGR15 ; break;
1702 case RECTFMT_RGB15PC: dstfmt_hidd = vHidd_StdPixFmt_RGB15_LE; break;
1703 case RECTFMT_BGR15PC: dstfmt_hidd = vHidd_StdPixFmt_BGR15_LE; break;
1704 case RECTFMT_RGB16 : dstfmt_hidd = vHidd_StdPixFmt_RGB16 ; break;
1705 case RECTFMT_BGR16 : dstfmt_hidd = vHidd_StdPixFmt_BGR16 ; break;
1706 case RECTFMT_RGB16PC: dstfmt_hidd = vHidd_StdPixFmt_RGB16_LE; break;
1707 case RECTFMT_BGR16PC: dstfmt_hidd = vHidd_StdPixFmt_BGR16_LE; break;
1708 case RECTFMT_RGB24 : dstfmt_hidd = vHidd_StdPixFmt_RGB24 ; break;
1709 case RECTFMT_BGR24 : dstfmt_hidd = vHidd_StdPixFmt_BGR24 ; break;
1710 case RECTFMT_ARGB32 : dstfmt_hidd = vHidd_StdPixFmt_ARGB32 ; morphfmt_hidd = vHidd_StdPixFmt_0RGB32; break;
1711 case RECTFMT_BGRA32 : dstfmt_hidd = vHidd_StdPixFmt_BGRA32 ; morphfmt_hidd = vHidd_StdPixFmt_BGR032; break;
1712 case RECTFMT_RGBA32 : dstfmt_hidd = vHidd_StdPixFmt_RGBA32 ; morphfmt_hidd = vHidd_StdPixFmt_RGB032; break;
1713 case RECTFMT_ABGR32 : dstfmt_hidd = vHidd_StdPixFmt_ABGR32 ; morphfmt_hidd = vHidd_StdPixFmt_0BGR32; break;
1714 case RECTFMT_RAW : dstfmt_hidd = vHidd_StdPixFmt_Native; break;
1717 #warning Get rid of the below code ?
1718 /* This can be done by passing the srcx and srcy parameters on to
1719 the HIDD bitmap and let it take care of it itself.
1720 This means that HIDD_BM_PutImage() gets a lot of parameters,
1721 which may not be necessary in real life.
1723 Compromise: convert from *CyberGfx* pixfmt to bppix using a table lookup.
1724 This is faster
1726 if ((dstfmt_hidd == vHidd_StdPixFmt_Native) || (morphfmt_hidd != 0))
1728 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&pf);
1731 if (dstfmt_hidd != vHidd_StdPixFmt_Native)
1733 /* RECTFMT_ARGB32 on vHidd_StdPixFmt_0RGB32 bitmap ==> use vHidd_StdPixFmt_0RGB32 */
1734 /* RECTFMT_BGRA32 on vHidd_StdPixFmt_BGR032 bitmap ==> use vHidd_StdPixFmt_BGR032 */
1735 /* RECTFMT_RGBA32 on vHidd_StdPixFmt_RGB032 bitmap ==> use vHidd_StdPixFmt_RGB032 */
1736 /* RECTFMT_ABGR32 on vHidd_StdPixFmt_0BGR32 bitmap ==> use vHidd_StdPixFmt_0BGR32 */
1738 if (morphfmt_hidd != 0)
1740 IPTR stdpf;
1742 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, (IPTR *)&stdpf);
1743 if (stdpf == morphfmt_hidd) dstfmt_hidd = morphfmt_hidd;
1746 pf = HIDD_Gfx_GetPixFmt(SDD(GfxBase)->gfxhidd, dstfmt_hidd);
1749 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, &bppix);
1751 start_offset = ((ULONG)desty) * dstmod + destx * bppix;
1753 rpard.array = ((UBYTE *)dst) + start_offset;
1754 rpard.pixfmt = dstfmt_hidd;
1755 rpard.modulo = dstmod;
1756 rpard.bppix = bppix;
1758 rr.MinX = srcx;
1759 rr.MinY = srcy;
1760 rr.MaxX = srcx + width - 1;
1761 rr.MaxY = srcy + height - 1;
1763 pixread = do_render_func(rp, NULL, &rr, rpa_render, &rpard, FALSE, GfxBase);
1765 /* restore old gc values */
1766 gc_tags[0].ti_Data = (IPTR)old_drmd;
1767 OOP_SetAttrs(gc, gc_tags);
1769 RELEASE_DRIVERDATA(rp, GfxBase);
1771 return pixread;
1774 LONG driver_InvertPixelArray(struct RastPort *rp
1775 , UWORD destx, UWORD desty, UWORD width, UWORD height
1776 , struct GfxBase *GfxBase)
1779 /* This is cybergraphx. We only work wih HIDD bitmaps */
1780 if (!IS_HIDD_BM(rp->BitMap))
1782 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap InvertPixelArray() !!!\n"));
1783 return 0;
1786 return (LONG)fillrect_pendrmd(rp
1787 , destx, desty
1788 , destx + width - 1
1789 , desty + height - 1
1790 , 0 /* Source pen does not matter */
1791 , vHidd_GC_DrawMode_Invert
1792 , GfxBase);
1795 LONG driver_FillPixelArray(struct RastPort *rp
1796 , UWORD destx, UWORD desty, UWORD width, UWORD height
1797 , ULONG pixel, struct GfxBase *GfxBase)
1799 HIDDT_Color col;
1800 HIDDT_Pixel pix;
1802 /* HIDDT_ColComp are 16 Bit */
1803 col.alpha = (HIDDT_ColComp)((pixel >> 16) & 0x0000FF00);
1804 col.red = (HIDDT_ColComp)((pixel >> 8) & 0x0000FF00);
1805 col.green = (HIDDT_ColComp)(pixel & 0x0000FF00);
1806 col.blue = (HIDDT_ColComp)((pixel << 8) & 0x0000FF00);
1808 pix = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
1810 return (LONG)fillrect_pendrmd(rp
1811 , destx, desty
1812 , destx + width - 1
1813 , desty + height - 1
1814 , pix
1815 , vHidd_GC_DrawMode_Copy
1816 , GfxBase
1820 ULONG driver_MovePixelArray(UWORD srcx, UWORD srcy, struct RastPort *rp
1821 , UWORD destx, UWORD desty, UWORD width, UWORD height
1822 , struct GfxBase *GfxBase)
1824 ClipBlit(rp
1825 , srcx, srcy
1826 , rp
1827 , destx, desty
1828 , width, height
1829 , 0x00C0 /* Copy */
1831 return width * height;
1836 LONG driver_WriteRGBPixel(struct RastPort *rp, UWORD x, UWORD y
1837 , ULONG pixel, struct GfxBase *GfxBase)
1840 struct rgbpix_render_data prd;
1841 HIDDT_Color col;
1842 LONG retval;
1844 /* This is cybergraphx. We only work wih HIDD bitmaps */
1845 if (!IS_HIDD_BM(rp->BitMap))
1847 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WriteRGBPixel() !!!\n"));
1848 return 0;
1851 if (!OBTAIN_DRIVERDATA(rp, GfxBase)) return -1;
1853 /* HIDDT_ColComp are 16 Bit */
1855 col.alpha = (HIDDT_ColComp)((pixel >> 16) & 0x0000FF00);
1856 col.red = (HIDDT_ColComp)((pixel >> 8) & 0x0000FF00);
1857 col.green = (HIDDT_ColComp)(pixel & 0x0000FF00);
1858 col.blue = (HIDDT_ColComp)((pixel << 8) & 0x0000FF00);
1860 prd.pixel = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
1862 retval = do_pixel_func(rp, x, y, rgbpix_write, &prd, GfxBase);
1864 RELEASE_DRIVERDATA(rp, GfxBase);
1866 return retval;
1871 ULONG driver_ReadRGBPixel(struct RastPort *rp, UWORD x, UWORD y
1872 , struct GfxBase *GfxBase)
1874 struct rgbpix_render_data prd;
1876 /* Get the HIDD pixel val */
1877 HIDDT_Color col;
1878 HIDDT_Pixel pix;
1879 LONG ret;
1881 /* This is cybergraphx. We only work wih HIDD bitmaps */
1882 if (!IS_HIDD_BM(rp->BitMap))
1884 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in ReadRGBPixel()!!!\n"));
1885 return (ULONG)-1;
1888 if (!OBTAIN_DRIVERDATA(rp, GfxBase)) return (ULONG)-1;
1890 ret = do_pixel_func(rp, x, y, pix_read, &prd, GfxBase);
1892 RELEASE_DRIVERDATA(rp, GfxBase);
1894 if (-1 == ret)
1895 return (ULONG)-1;
1897 HIDD_BM_UnmapPixel(HIDD_BM_OBJ(rp->BitMap), prd.pixel, &col);
1899 /* HIDDT_ColComp are 16 Bit */
1901 pix = ((col.alpha & 0xFF00) << 16)
1902 | ((col.red & 0xFF00) << 8)
1903 | (col.green & 0xFF00)
1904 | ((col.blue & 0xFF00) >> 8);
1906 return pix;
1911 ULONG driver_GetCyberMapAttr(struct BitMap *bitMap, ULONG attribute, struct GfxBase *GfxBase)
1913 OOP_Object *bm_obj;
1914 OOP_Object *pf;
1916 IPTR retval;
1918 /* This is cybergraphx. We only work wih HIDD bitmaps */
1919 if (!IS_HIDD_BM(bitMap)) {
1920 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in GetCyberMapAttr() !!!\n"));
1921 return 0;
1924 bm_obj = HIDD_BM_OBJ(bitMap);
1926 OOP_GetAttr(bm_obj, aHidd_BitMap_PixFmt, (IPTR *)&pf);
1928 switch (attribute) {
1929 case CYBRMATTR_XMOD:
1930 OOP_GetAttr(bm_obj, aHidd_BitMap_BytesPerRow, &retval);
1931 break;
1933 case CYBRMATTR_BPPIX:
1934 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, &retval);
1935 break;
1937 case CYBRMATTR_PIXFMT: {
1938 IPTR stdpf;
1939 UWORD cpf;
1940 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, (IPTR *)&stdpf);
1942 /* Convert to cybergfx */
1943 cpf = hidd2cyber_pixfmt(stdpf, GfxBase);
1945 if (cpf == (UWORD)-1) {
1946 D(bug("!!! UNKNOWN PIXEL FORMAT IN GetCyberMapAttr()\n"));
1949 retval = (IPTR)cpf;
1950 break;
1954 case CYBRMATTR_WIDTH:
1955 #if 0 /* stegerg: doesn't really work, because of framebuffer bitmap object stuff */
1956 OOP_GetAttr(bm_obj, aHidd_BitMap_Width, &retval);
1957 #else
1958 retval = GetBitMapAttr(bitMap, BMA_WIDTH);
1959 #endif
1960 break;
1962 case CYBRMATTR_HEIGHT:
1963 #if 0 /* stegerg: doesn't really work, because of framebuffer bitmap object stuff */
1964 OOP_GetAttr(bm_obj, aHidd_BitMap_Height, &retval);
1965 #else
1966 retval = GetBitMapAttr(bitMap, BMA_HEIGHT);
1967 #endif
1968 break;
1970 case CYBRMATTR_DEPTH:
1971 #if 0 /* stegerg: might not really work, because of framebuffer bitmap object stuff */
1972 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &retval);
1973 #else
1974 retval = GetBitMapAttr(bitMap, BMA_DEPTH);
1975 #endif
1976 break;
1978 case CYBRMATTR_ISCYBERGFX: {
1979 IPTR depth;
1981 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &depth);
1983 if (depth < 8) {
1984 retval = 0;
1985 } else {
1986 /* We allways have a HIDD bitmap */
1987 retval = 0xFFFFFFFF; /* Some apps seem to rely on this retval */
1989 break; }
1991 case CYBRMATTR_ISLINEARMEM:
1992 OOP_GetAttr(bm_obj, aHidd_BitMap_IsLinearMem, &retval);
1993 break;
1995 default:
1996 D(bug("!!! UNKNOWN ATTRIBUTE PASSED TO GetCyberMapAttr()\n"));
1997 break;
2000 } /* switch (attribute) */
2002 return retval;
2006 VOID driver_CVideoCtrlTagList(struct ViewPort *vp, struct TagItem *tags, struct GfxBase *GfxBase)
2008 struct TagItem *tag, *tstate;
2009 ULONG dpmslevel = 0;
2011 struct TagItem htags[] =
2013 { aHidd_Gfx_DPMSLevel, 0UL },
2014 { TAG_DONE, 0UL }
2017 BOOL dpms_found = FALSE;
2019 HIDDT_DPMSLevel hdpms = 0;
2021 for (tstate = tags; (tag = NextTagItem((const struct TagItem **)&tstate)); )
2023 switch (tag->ti_Tag)
2025 case SETVC_DPMSLevel:
2026 dpmslevel = tag->ti_Data;
2027 dpms_found = TRUE;
2028 break;
2030 default:
2031 D(bug("!!! UNKNOWN TAG IN CVideoCtrlTagList(): %x !!!\n"
2032 , tag->ti_Tag));
2033 break;
2035 } /* switch() */
2037 } /* for (each tagitem) */
2040 if (dpms_found)
2043 /* Convert to hidd dpms level */
2044 switch (dpmslevel)
2046 case DPMS_ON:
2047 hdpms = vHidd_Gfx_DPMSLevel_On;
2048 break;
2050 case DPMS_STANDBY:
2051 hdpms = vHidd_Gfx_DPMSLevel_Standby;
2052 break;
2054 case DPMS_SUSPEND:
2055 hdpms = vHidd_Gfx_DPMSLevel_Suspend;
2056 break;
2058 case DPMS_OFF:
2059 hdpms = vHidd_Gfx_DPMSLevel_Off;
2060 break;
2062 default:
2063 D(bug("!!! UNKNOWN DPMS LEVEL IN CVideoCtrlTagList(): %x !!!\n"
2064 , dpmslevel));
2066 dpms_found = FALSE;
2067 break;
2072 if (dpms_found)
2074 htags[0].ti_Data = hdpms;
2076 else
2078 htags[0].ti_Tag = TAG_IGNORE;
2081 OOP_SetAttrs(SDD(GfxBase)->gfxhidd, htags);
2083 return;
2087 ULONG driver_ExtractColor(struct RastPort *rp, struct BitMap *bm
2088 , ULONG color, ULONG srcx, ULONG srcy, ULONG width, ULONG height
2089 , struct GfxBase *GfxBase)
2091 struct Rectangle rr;
2092 LONG pixread = 0;
2093 struct extcol_render_data ecrd;
2094 OOP_Object *pf;
2095 IPTR colmod;
2097 if (!IS_HIDD_BM(rp->BitMap))
2099 D(bug("!!! CALLING ExtractColor() ON NO-HIDD BITMAP !!!\n"));
2100 return FALSE;
2103 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
2104 return FALSE;
2106 rr.MinX = srcx;
2107 rr.MinY = srcy;
2108 rr.MaxX = srcx + width - 1;
2109 rr.MaxY = srcy + height - 1;
2111 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&pf);
2113 OOP_GetAttr(pf, aHidd_PixFmt_ColorModel, (IPTR *)&colmod);
2115 if (vHidd_ColorModel_Palette == colmod)
2117 ecrd.pixel = color;
2119 else
2121 HIDDT_Color col;
2123 col.alpha = (color >> 16) & 0x0000FF00;
2124 col.red = (color >> 8 ) & 0x0000FF00;
2125 col.green = color & 0x0000FF00;
2126 col.blue = (color << 8) & 0x0000FF00;
2128 ecrd.pixel = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
2132 ecrd.destbm = bm;
2134 pixread = do_render_func(rp, NULL, &rr, extcol_render, NULL, TRUE, GfxBase);
2136 RELEASE_DRIVERDATA(rp, GfxBase);
2138 if (pixread != (width * height))
2139 return FALSE;
2141 return TRUE;
2145 VOID driver_DoCDrawMethodTagList(struct Hook *hook, struct RastPort *rp, struct TagItem *tags, struct GfxBase *GfxBase)
2148 struct dm_render_data dmrd;
2149 struct Rectangle rr;
2150 struct Layer *L;
2152 if (!IS_HIDD_BM(rp->BitMap))
2154 D(bug("!!! NO HIDD BITMAP IN CALL TO DoCDrawMethodTagList() !!!\n"));
2155 return;
2158 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
2159 return;
2161 /* Get the bitmap std pixfmt */
2162 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&dmrd.pf);
2163 OOP_GetAttr(dmrd.pf, aHidd_PixFmt_StdPixFmt, &dmrd.stdpf);
2164 dmrd.msg.colormodel = hidd2cyber_pixfmt(dmrd.stdpf, GfxBase);
2165 dmrd.hook = hook;
2166 dmrd.rp = rp;
2168 if (((UWORD)-1) == dmrd.msg.colormodel)
2170 RELEASE_DRIVERDATA(rp, GfxBase);
2171 D(bug("!!! UNKNOWN HIDD PIXFMT IN DoCDrawMethodTagList() !!!\n"));
2172 return;
2176 L = rp->Layer;
2178 rr.MinX = 0;
2179 rr.MinY = 0;
2181 if (NULL == L)
2183 rr.MaxX = GetBitMapAttr(rp->BitMap, BMA_WIDTH) - 1;
2184 rr.MaxY = GetBitMapAttr(rp->BitMap, BMA_HEIGHT) - 1;
2186 else
2188 /* Lock the layer */
2189 LockLayerRom(L);
2191 rr.MaxX = rr.MinX + (L->bounds.MaxX - L->bounds.MinX) - 1;
2192 rr.MaxY = rr.MinY + (L->bounds.MaxY - L->bounds.MinY) - 1;
2195 dmrd.gc = GetDriverData(rp)->dd_GC;
2196 do_render_func(rp, NULL, &rr, dm_render, &dmrd, FALSE, GfxBase);
2198 RELEASE_DRIVERDATA(rp, GfxBase);
2200 if (NULL != L)
2202 UnlockLayerRom(L);
2205 return;
2208 APTR driver_LockBitMapTagList(struct BitMap *bm, struct TagItem *tags, struct GfxBase *GfxBase)
2210 struct TagItem *tag;
2211 UBYTE *baseaddress;
2212 ULONG width, height, banksize, memsize;
2213 OOP_Object *pf;
2214 IPTR stdpf;
2215 UWORD cpf;
2217 if (!IS_HIDD_BM(bm))
2219 D(bug("!!! TRYING TO CALL LockBitMapTagList() ON NON-HIDD BM !!!\n"));
2220 return NULL;
2223 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_PixFmt, (IPTR *)&pf);
2225 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, &stdpf);
2226 cpf = hidd2cyber_pixfmt(stdpf, GfxBase);
2227 if (((UWORD)-1) == cpf)
2229 D(bug("!!! TRYING TO CALL LockBitMapTagList() ON NON-CYBER PIXFMT BITMAP !!!\n"));
2230 return NULL;
2233 /* Get some info from the bitmap object */
2234 if (!HIDD_BM_ObtainDirectAccess(HIDD_BM_OBJ(bm), &baseaddress, &width, &height, &banksize, &memsize))
2235 return NULL;
2238 while ((tag = NextTagItem((const struct TagItem **)&tags)))
2240 switch (tag->ti_Tag)
2242 case LBMI_BASEADDRESS:
2243 *((IPTR **)tag->ti_Data) = (IPTR *)baseaddress;
2244 break;
2246 case LBMI_BYTESPERROW:
2247 *((IPTR *)tag->ti_Data) =
2248 (ULONG)HIDD_BM_BytesPerLine(HIDD_BM_OBJ(bm), stdpf, width);
2249 break;
2251 case LBMI_BYTESPERPIX:
2252 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, (IPTR *)tag->ti_Data);
2253 break;
2255 case LBMI_PIXFMT:
2256 *((IPTR *)tag->ti_Data) = (IPTR)cpf;
2257 break;
2259 case LBMI_DEPTH:
2260 OOP_GetAttr(pf, aHidd_PixFmt_Depth, (IPTR *)tag->ti_Data);
2261 break;
2263 case LBMI_WIDTH:
2264 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_Width, (IPTR *)tag->ti_Data);
2265 break;
2267 case LBMI_HEIGHT:
2268 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_Height, (IPTR *)tag->ti_Data);
2269 break;
2271 default:
2272 D(bug("!!! UNKNOWN TAG PASSED TO LockBitMapTagList() !!!\n"));
2273 break;
2277 return HIDD_BM_OBJ(bm);
2280 VOID driver_UnLockBitMap(APTR handle, struct GfxBase *GfxBase)
2282 if (handle) HIDD_BM_ReleaseDirectAccess((OOP_Object *)handle);
2285 VOID driver_UnLockBitMapTagList(APTR handle, struct TagItem *tags, struct GfxBase *GfxBase)
2287 struct TagItem *tag;
2288 BOOL reallyunlock = TRUE;
2290 while ((tag = NextTagItem((const struct TagItem **)&tags)))
2292 switch (tag->ti_Tag)
2294 case UBMI_REALLYUNLOCK:
2295 reallyunlock = (BOOL)tag->ti_Data;
2296 break;
2298 case UBMI_UPDATERECTS:
2300 struct RectList *rl;
2302 rl = (struct RectList *)tag->ti_Data;
2304 #warning Dunno what to do with this
2306 break;
2309 default:
2310 D(bug("!!! UNKNOWN TAG PASSED TO UnLockBitMapTagList() !!!\n"));
2311 break;
2315 if (reallyunlock)
2317 HIDD_BM_ReleaseDirectAccess((OOP_Object *)handle);
2321 void driver_BltTemplateAlpha(UBYTE *src, LONG srcx, LONG srcmod
2322 , struct RastPort *rp, LONG destx, LONG desty, LONG width, LONG height
2323 , struct GfxBase *GfxBase)
2325 struct bta_render_data btard;
2326 struct Rectangle rr;
2328 /* This is cybergraphx. We only work wih HIDD bitmaps */
2329 if (!IS_HIDD_BM(rp->BitMap)) {
2330 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in BltTemplateAlpha() !!!\n"));
2331 return;
2334 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
2335 return;
2337 /* Compute the start of the array */
2339 btard.array = src + srcx;
2340 btard.modulo = srcmod;
2341 btard.invertalpha = (rp->DrawMode & INVERSVID) ? TRUE : FALSE;
2342 rr.MinX = destx;
2343 rr.MinY = desty;
2344 rr.MaxX = destx + width - 1;
2345 rr.MaxY = desty + height - 1;
2347 do_render_func(rp, NULL, &rr, bta_render, &btard, FALSE, GfxBase);
2349 RELEASE_DRIVERDATA(rp, GfxBase);
2352 /******************************************/
2353 /* Support stuff for cybergfx */
2354 /******************************************/
2356 #undef GfxBase