make fat.handler build again with debug enabled
[tangerine.git] / rom / graphics / graphics_driver.c
blobc7fa60d6fcd5fbf28584ee438afffd0237af27bf
1 /*
2 Copyright © 1995-2009, 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);
477 SDD(GfxBase)->framebuffer = NULL;
480 #if 0
481 if (SDD(GfxBase)->activescreen_inited)
482 cleanup_activescreen_stuff(GfxBase);
483 #endif
484 if (SDD(GfxBase)->dispinfo_db) {
485 destroy_dispinfo_db(SDD(GfxBase)->dispinfo_db, GfxBase);
486 SDD(GfxBase)->dispinfo_db = NULL;
489 if ( SDD(GfxBase)->planarbm_cache ) {
490 delete_object_cache( SDD(GfxBase)->planarbm_cache, GfxBase );
491 SDD(GfxBase)->planarbm_cache = NULL;
494 if ( SDD(GfxBase)->gc_cache ) {
495 delete_object_cache( SDD(GfxBase)->gc_cache, GfxBase );
496 SDD(GfxBase)->gc_cache = NULL;
499 if ( SDD(GfxBase)->fakegfx_inited ) {
500 cleanup_fakegfxhidd( &SDD(GfxBase)->fakegfx_staticdata, GfxBase);
501 SDD(GfxBase)->fakegfx_inited = FALSE;
504 if ( SDD(GfxBase)->gfxhidd_orig ) {
505 OOP_DisposeObject( SDD(GfxBase)->gfxhidd_orig );
506 SDD(GfxBase)->gfxhidd_orig = NULL;
509 return;
512 /* Called after DOS is up & running */
513 static OOP_Object *create_framebuffer(struct GfxBase *GfxBase)
515 struct TagItem fbtags[] = {
516 { aHidd_BitMap_FrameBuffer, TRUE },
517 { aHidd_BitMap_ModeID, 0 },
518 { TAG_DONE, 0 }
521 HIDDT_ModeID hiddmode;
522 OOP_Object *fb = NULL;
524 /* Get the highest available resolution at the best possible depth */
525 hiddmode = get_best_resolution_and_depth(GfxBase);
526 if (vHidd_ModeID_Invalid == hiddmode) {
527 D(bug("!!! create_framebuffer(): COULD NOT GET HIDD MODEID !!!\n"));
528 } else {
529 /* Create the framebuffer object */
530 fbtags[1].ti_Data = hiddmode;
531 fb = HIDD_Gfx_NewBitMap(SDD(GfxBase)->gfxhidd, fbtags);
534 return fb;
536 const UBYTE def_pointer_shape[] =
538 01,03,00,00,00,00,00,00,00,00,00,
539 02,01,03,03,00,00,00,00,00,00,00,
540 00,02,01,01,03,03,00,00,00,00,00,
541 00,02,01,01,01,01,03,03,00,00,00,
542 00,00,02,01,01,01,01,01,03,03,00,
543 00,00,02,01,01,01,01,01,01,01,00,
544 00,00,00,02,01,01,01,03,00,00,00,
545 00,00,00,02,01,01,03,01,03,00,00,
546 00,00,00,00,02,01,00,02,01,03,00,
547 00,00,00,00,02,01,00,00,02,01,03,
548 00,00,00,00,00,00,00,00,00,01,01
551 #define DEF_POINTER_WIDTH 11
552 #define DEF_POINTER_HEIGHT 11
553 #define DEF_POINTER_DEPTH 4
556 static BOOL init_cursor(struct GfxBase *GfxBase)
558 /* Create the pointer bitmap */
559 struct TagItem pbmtags[] = {
560 { aHidd_BitMap_Width, DEF_POINTER_WIDTH },
561 { aHidd_BitMap_Height, DEF_POINTER_HEIGHT },
562 { aHidd_BitMap_StdPixFmt, vHidd_StdPixFmt_LUT8 },
563 { TAG_DONE, 0UL }
565 SDD(GfxBase)->pointerbm = HIDD_Gfx_NewBitMap(SDD(GfxBase)->gfxhidd, pbmtags);
566 if (NULL != SDD(GfxBase)->pointerbm) {
567 OOP_Object *gc;
569 gc = obtain_cache_object(SDD(GfxBase)->gc_cache, GfxBase);
570 if (NULL != gc) {
571 /* Copy the default pointer image into the created pointer bitmap */
572 struct TagItem gc_tags[] = {
573 { aHidd_GC_DrawMode, vHidd_GC_DrawMode_Copy },
574 { TAG_DONE, 0UL }
577 HIDDT_Color col[DEF_POINTER_DEPTH] = {{0}};
579 col[0].red = 0x0000;
580 col[0].green = 0x0000;
581 col[0].blue = 0x0000;
582 col[0].alpha = 0x0000;
583 col[1].red = 0xE0E0;
584 col[1].green = 0x4040;
585 col[1].blue = 0x4040;
586 col[1].alpha = 0x0000;
587 col[2].red = 0x0000;
588 col[2].green = 0x0000;
589 col[2].blue = 0x0000;
590 col[2].alpha = 0x0000;
591 col[3].red = 0xE0E0;
592 col[3].green = 0xE0E0;
593 col[3].blue = 0xC0C0;
594 col[3].alpha = 0x0000;
596 HIDD_BM_SetColors(SDD(GfxBase)->pointerbm, col, 0, DEF_POINTER_DEPTH);
598 OOP_SetAttrs(gc, gc_tags);
599 #if 0
600 /* PutImageLUT not yet implemented in gfx baseclass */
601 HIDD_BM_PutImageLUT(SDD(GfxBase)->pointerbm, gc
602 , (UBYTE *)def_pointer_shape
603 , DEF_POINTER_WIDTH
604 , 0, 0
605 , DEF_POINTER_WIDTH, DEF_POINTER_HEIGHT
606 , &plut
608 #else
609 HIDD_BM_PutImage(SDD(GfxBase)->pointerbm, gc
610 , (UBYTE *)def_pointer_shape
611 , DEF_POINTER_WIDTH
612 , 0, 0
613 , DEF_POINTER_WIDTH, DEF_POINTER_HEIGHT
614 , vHidd_StdPixFmt_LUT8
617 #endif
618 release_cache_object(SDD(GfxBase)->gc_cache, gc, GfxBase);
620 if (HIDD_Gfx_SetCursorShape(SDD(GfxBase)->gfxhidd, SDD(GfxBase)->pointerbm)) {
621 D(bug("CURSOR SHAPE SET\n"));
622 /* Make it visible */
623 HIDD_Gfx_SetCursorVisible(SDD(GfxBase)->gfxhidd, TRUE);
625 return TRUE;
630 cleanup_cursor(GfxBase);
632 return FALSE;
635 static VOID cleanup_cursor(struct GfxBase *GfxBase)
637 if (NULL != SDD(GfxBase)->pointerbm) {
638 OOP_DisposeObject(SDD(GfxBase)->pointerbm);
639 SDD(GfxBase)->pointerbm = NULL;
643 BOOL driver_LateGfxInit (APTR data, struct GfxBase *GfxBase)
646 /* Supplied data is really the librarybase of a HIDD */
647 STRPTR gfxhiddname = (STRPTR)data;
648 struct TagItem tags[] = {
649 { TAG_DONE, 0UL },
651 EnterFunc(bug("driver_LateGfxInit(gfxhiddname=%s)\n", gfxhiddname));
653 driver_expunge(GfxBase);
654 D(bug("[GFX] Cleanup complete\n"));
656 /* Create a new GfxHidd object */
658 SDD(GfxBase)->gfxhidd = SDD(GfxBase)->gfxhidd_orig = OOP_NewObject(NULL, gfxhiddname, tags);
659 D(bug("driver_LateGfxInit: gfxhidd=%p\n", SDD(GfxBase)->gfxhidd));
661 if (NULL != SDD(GfxBase)->gfxhidd) {
662 IPTR hwcursor = 0;
663 IPTR noframebuffer = 0;
664 BOOL ok = TRUE;
666 /* Get method id here, to avoid any possible semaphore involment when calling the method */
667 SDD(GfxBase)->hiddGfxShowImminentReset_MethodID = OOP_GetMethodID(IID_Hidd_Gfx, moHidd_Gfx_ShowImminentReset);
669 OOP_GetAttr(SDD(GfxBase)->gfxhidd, aHidd_Gfx_SupportsHWCursor, &hwcursor);
670 OOP_GetAttr(SDD(GfxBase)->gfxhidd, aHidd_Gfx_NoFrameBuffer, &noframebuffer);
671 SDD(GfxBase)->has_hw_cursor = (BOOL)hwcursor;
672 if (!hwcursor) {
673 OOP_Object *fgh;
674 D(bug("There's no hardware cursor\n"));
676 fgh = init_fakegfxhidd(SDD(GfxBase)->gfxhidd
677 , &SDD(GfxBase)->fakegfx_staticdata
678 , GfxBase);
680 if (NULL != fgh) {
681 SDD(GfxBase)->gfxhidd = fgh;
682 SDD(GfxBase)->fakegfx_inited = TRUE;
683 } else {
684 ok = FALSE;
688 if (ok) {
689 struct TagItem gc_create_tags[] = { { TAG_DONE, 0UL } };
690 D(bug("Ok\n"));
691 SDD(GfxBase)->gc_cache = create_object_cache(NULL, IID_Hidd_GC, gc_create_tags, GfxBase);
692 if (NULL != SDD(GfxBase)->gc_cache) {
694 struct TagItem bm_create_tags[] = {
695 #warning Maybe make this class private and create the object through the graphicshidd
696 { aHidd_BitMap_GfxHidd, (IPTR)SDD(GfxBase)->gfxhidd_orig },
697 { aHidd_BitMap_Displayable, FALSE },
698 { aHidd_PlanarBM_AllocPlanes, FALSE },
699 { TAG_DONE, 0UL }
702 D(bug("Cache created\n"));
703 SDD(GfxBase)->planarbm_cache = create_object_cache(NULL, CLID_Hidd_PlanarBM, bm_create_tags, GfxBase);
705 if (NULL != SDD(GfxBase)->planarbm_cache) {
707 /* Move the modes into the displayinfo DB */
708 SDD(GfxBase)->dispinfo_db = build_dispinfo_db(GfxBase);
709 if (NULL != SDD(GfxBase)->dispinfo_db) {
710 if (!noframebuffer)
711 SDD(GfxBase)->framebuffer = create_framebuffer(GfxBase);
712 if (noframebuffer || SDD(GfxBase)->framebuffer) {
713 D(bug("FRAMEBUFFER OK: %p\n", SDD(GfxBase)->framebuffer));
714 if (init_cursor(GfxBase)) {
715 D(bug("MOUSE INITED\n"));
716 ReturnBool("driver_LateGfxInit", TRUE);
719 if (SDD(GfxBase)->framebuffer)
720 OOP_DisposeObject(SDD(GfxBase)->framebuffer);
721 destroy_dispinfo_db(SDD(GfxBase)->dispinfo_db, GfxBase);
722 SDD(GfxBase)->dispinfo_db = NULL;
723 } /* if (displayinfo db inited) */
724 delete_object_cache(SDD(GfxBase)->planarbm_cache, GfxBase);
725 SDD(GfxBase)->planarbm_cache = NULL;
726 } /* if (planarbm cache created) */
727 delete_object_cache(SDD(GfxBase)->gc_cache, GfxBase);
728 SDD(GfxBase)->gc_cache = NULL;
729 } /* if (gc object cache ok) */
731 } /* if (fake gfx stuff ok) */
733 if (SDD(GfxBase)->fakegfx_inited) {
734 cleanup_fakegfxhidd(&SDD(GfxBase)->fakegfx_staticdata, GfxBase);
735 SDD(GfxBase)->fakegfx_inited = FALSE;
737 OOP_DisposeObject(SDD(GfxBase)->gfxhidd_orig);
738 SDD(GfxBase)->gfxhidd_orig = NULL;
742 ReturnBool("driver_LateGfxInit", FALSE);
747 #if 0 /* Unused? */
749 static ULONG getbitmappixel(struct BitMap *bm
750 , LONG x
751 , LONG y
752 , UBYTE depth
753 , UBYTE plane_mask)
755 UBYTE i;
756 ULONG idx;
758 ULONG mask;
759 ULONG pen = 0;
761 idx = COORD_TO_BYTEIDX(x, y, bm->BytesPerRow);
762 mask = XCOORD_TO_MASK( x );
764 for (i = depth - 1; depth; i -- , depth -- )
766 pen <<= 1; /* stegerg: moved to here, was inside if!? */
768 if ((1L << i) & plane_mask)
770 UBYTE *plane = bm->Planes[i];
772 if (plane == (PLANEPTR)-1)
774 pen |= 1;
776 else if (plane != NULL)
778 if ((plane[idx] & mask) != 0)
779 pen |= 1;
784 return pen;
787 #endif
790 #define dumprect(rect) \
791 kprintf(#rect " : (%d,%d) - (%d,%d)\n",(rect)->MinX,(rect)->MinY,(rect)->MaxX,(rect)->MaxY)
794 struct bgf_render_data {
795 WORD fbm_xsrc;
796 OOP_Object *fbm;
799 static ULONG bgf_render(APTR bgfr_data
800 , LONG srcx, LONG srcy
801 , OOP_Object *dstbm_obj, OOP_Object *dst_gc
802 , LONG x1, LONG y1, LONG x2, LONG y2
803 , struct GfxBase *GfxBase)
805 struct bgf_render_data *bgfrd;
806 ULONG width, height;
808 width = x2 - x1 + 1;
809 height = y2 - y1 + 1;
811 ASSERT(width > 0 && height > 0);
813 bgfrd = (struct bgf_render_data *)bgfr_data;
815 HIDD_BM_BlitColorExpansion( dstbm_obj
816 , dst_gc
817 , bgfrd->fbm
818 , srcx + bgfrd->fbm_xsrc, srcy /* stegerg: instead of srcy there was a 0 */
819 , x1, y1
820 , width, height
823 return width * height;
827 void blit_glyph_fast(struct RastPort *rp, OOP_Object *fontbm, WORD xsrc
828 , WORD destx, WORD desty, UWORD width, UWORD height
829 , struct GfxBase * GfxBase)
832 struct Rectangle rr;
833 struct bgf_render_data bgfrd;
835 EnterFunc(bug("blit_glyph_fast(%d, %d, %d, %d, %d)\n"
836 , xsrc, destx, desty, width, height));
839 ASSERT(width > 0 && height > 0);
841 bgfrd.fbm_xsrc = xsrc;
842 bgfrd.fbm = fontbm;
844 rr.MinX = destx;
845 rr.MinY = desty;
846 rr.MaxX = destx + width - 1;
847 rr.MaxY = desty + height - 1;
849 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
850 ReturnVoid("blit_glyph_fast");
852 do_render_func(rp, NULL, &rr, bgf_render, &bgfrd, FALSE, GfxBase);
854 RELEASE_DRIVERDATA(rp, GfxBase);
856 ReturnVoid("blit_glyph_fast");
861 #define NUMCHARS(tf) ((tf->tf_HiChar - tf->tf_LoChar) + 2)
862 #define CTF(x) ((struct ColorTextFont *)x)
864 void driver_Text (struct RastPort * rp, CONST_STRPTR string, LONG len,
865 struct GfxBase * GfxBase)
868 #warning Does not handle color textfonts
869 WORD render_y;
870 struct TextFont *tf;
871 WORD current_x;
872 OOP_Object *fontbm = NULL;
874 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
875 return;
877 if ((rp->DrawMode & ~INVERSVID) == JAM2)
879 struct TextExtent te;
880 ULONG old_drmd = GetDrMd(rp);
882 /* This is actually needed, because below only the
883 part of the glyph which contains data is rendered:
885 ...1100...
886 ...1100...
887 ...1100...
888 ...1111...
890 '.' at left side can be there because of kerning.
891 '.' at the right side can be there because of
892 CharSpace being bigger than glyph bitmap data
893 width.
896 TextExtent(rp, string, len, &te);
897 SetDrMd(rp, old_drmd ^ INVERSVID);
898 RectFill(rp, rp->cp_x + te.te_Extent.MinX,
899 rp->cp_y + te.te_Extent.MinY,
900 rp->cp_x + te.te_Extent.MaxX,
901 rp->cp_y + te.te_Extent.MaxY);
902 SetDrMd(rp, old_drmd);
905 /* does this rastport have a layer. If yes, lock the layer it.*/
906 if (NULL != rp->Layer)
907 LockLayerRom(rp->Layer);
909 tf = rp->Font;
911 if (ExtendFont(tf, NULL))
913 fontbm = ((struct TextFontExtension_intern *)(tf->tf_Extension))->hash->font_bitmap;
916 /* Check if font has character data as a HIDD bitmap */
918 if (NULL == fontbm)
920 D(bug("FONT HAS NO HIDD BITMAP ! Won't render text\n"));
921 RELEASE_DRIVERDATA(rp, GfxBase);
922 return;
926 /* Render along font's baseline */
927 render_y = rp->cp_y - tf->tf_Baseline;
928 current_x = rp->cp_x;
930 while ( len -- )
932 ULONG charloc;
933 ULONG idx;
935 if (*string < tf->tf_LoChar || *string > tf->tf_HiChar )
937 /* A character which there is no glyph for. We just
938 draw the last glyph in the font
940 idx = NUMCHARS(tf) - 1;
942 else
944 idx = *string - tf->tf_LoChar;
947 charloc = ((ULONG *)tf->tf_CharLoc)[idx];
949 if (tf->tf_CharKern)
951 current_x += ((WORD *)tf->tf_CharKern)[idx];
954 if ((tf->tf_Style & FSF_COLORFONT) &&
955 !(CTF(tf)->ctf_Flags & CT_ANTIALIAS))
957 #warning Handle color fonts
959 else
961 WORD
962 glyphXOffset = charloc >> 16,
963 glyphWidth = charloc & 0xFFFF;
965 ASSERT(tf->tf_YSize > 0);
967 /* blit the glypth if it has data in the bitmap */
968 if (glyphWidth > 0)
970 blit_glyph_fast(rp, fontbm, glyphXOffset, current_x, render_y,
971 glyphWidth, tf->tf_YSize, GfxBase);
975 if (tf->tf_CharSpace)
976 current_x += ((WORD *)tf->tf_CharSpace)[idx];
977 else
978 current_x += tf->tf_XSize; /* Add glyph width */
980 current_x += rp->TxSpacing;
982 string ++;
983 } /* for (each character to render) */
985 Move(rp, current_x, rp->cp_y);
987 if (NULL != rp->Layer)
988 UnlockLayerRom(rp->Layer);
990 RELEASE_DRIVERDATA(rp, GfxBase);
992 return;
996 /***********************************************/
997 /* CYBERGFX CALLS ***/
1000 struct wpa_render_data
1002 UBYTE *array;
1003 HIDDT_StdPixFmt pixfmt;
1004 ULONG modulo;
1005 ULONG bppix;
1008 static ULONG wpa_render(APTR wpar_data
1009 , LONG srcx, LONG srcy
1010 , OOP_Object *dstbm_obj
1011 , OOP_Object *dst_gc
1012 , LONG x1, LONG y1, LONG x2, LONG y2
1013 , struct GfxBase *GfxBase)
1015 struct wpa_render_data *wpard;
1016 ULONG width, height;
1017 UBYTE *array;
1019 width = x2 - x1 + 1;
1020 height = y2 - y1 + 1;
1022 wpard = (struct wpa_render_data *)wpar_data;
1024 array = wpard->array + wpard->modulo * srcy + wpard->bppix * srcx;
1026 HIDD_BM_PutImage(dstbm_obj
1027 , dst_gc, array
1028 , wpard->modulo
1029 , x1, y1
1030 , width, height
1031 , wpard->pixfmt
1034 return width * height;
1037 struct wpaa_render_data
1039 UBYTE *array;
1040 ULONG modulo;
1043 static ULONG wpaa_render(APTR wpaar_data
1044 , LONG srcx, LONG srcy
1045 , OOP_Object *dstbm_obj
1046 , OOP_Object *dst_gc
1047 , LONG x1, LONG y1, LONG x2, LONG y2
1048 , struct GfxBase *GfxBase)
1050 struct wpaa_render_data *wpaard;
1051 ULONG width, height;
1052 UBYTE *array;
1054 width = x2 - x1 + 1;
1055 height = y2 - y1 + 1;
1057 wpaard = (struct wpaa_render_data *)wpaar_data;
1059 array = wpaard->array + wpaard->modulo * srcy + 4 * srcx;
1061 HIDD_BM_PutAlphaImage(dstbm_obj
1062 , dst_gc, array
1063 , wpaard->modulo
1064 , x1, y1
1065 , width, height
1068 return width * height;
1071 struct bta_render_data
1073 UBYTE *array;
1074 ULONG modulo;
1075 UBYTE invertalpha;
1078 static ULONG bta_render(APTR bta_data
1079 , LONG srcx, LONG srcy
1080 , OOP_Object *dstbm_obj
1081 , OOP_Object *dst_gc
1082 , LONG x1, LONG y1, LONG x2, LONG y2
1083 , struct GfxBase *GfxBase)
1085 struct bta_render_data *btard;
1086 ULONG width, height;
1087 UBYTE *array;
1089 width = x2 - x1 + 1;
1090 height = y2 - y1 + 1;
1092 btard = (struct bta_render_data *)bta_data;
1094 array = btard->array + btard->modulo * srcy + srcx;
1096 HIDD_BM_PutAlphaTemplate(dstbm_obj
1097 , dst_gc, array
1098 , btard->modulo
1099 , x1, y1
1100 , width, height
1101 , btard->invertalpha
1104 return width * height;
1107 struct rpa_render_data {
1108 UBYTE *array;
1109 HIDDT_StdPixFmt pixfmt;
1110 ULONG modulo;
1111 ULONG bppix;
1114 static ULONG rpa_render(APTR rpar_data
1115 , LONG srcx, LONG srcy
1116 , OOP_Object *dstbm_obj
1117 , OOP_Object *dst_gc
1118 , LONG x1, LONG y1, LONG x2, LONG y2
1119 , struct GfxBase *GfxBase)
1121 struct rpa_render_data *rpard;
1122 ULONG width, height;
1123 UBYTE *array;
1125 width = x2 - x1 + 1;
1126 height = y2 - y1 + 1;
1128 rpard = (struct rpa_render_data *)rpar_data;
1130 array = rpard->array + rpard->modulo * srcy + rpard->bppix * srcx;
1132 HIDD_BM_GetImage(dstbm_obj
1133 , array
1134 , rpard->modulo
1135 , x1, y1
1136 , width, height
1137 , rpard->pixfmt
1140 return width * height;
1143 static LONG pix_read(APTR pr_data
1144 , OOP_Object *bm, OOP_Object *gc
1145 , LONG x, LONG y
1146 , struct GfxBase *GfxBase)
1148 struct rgbpix_render_data *prd;
1150 prd = (struct rgbpix_render_data *)pr_data;
1152 prd->pixel = HIDD_BM_GetPixel(bm, x, y);
1155 return 0;
1159 struct extcol_render_data {
1160 struct render_special_info rsi;
1161 struct BitMap *destbm;
1162 HIDDT_Pixel pixel;
1166 static VOID buf_to_extcol(struct extcol_render_data *ecrd
1167 , LONG srcx, LONG srcy
1168 , LONG dstx, LONG dsty
1169 , ULONG width, ULONG height
1170 , HIDDT_Pixel *pixbuf
1171 , OOP_Object *bm_obj
1172 , HIDDT_Pixel *pixtab)
1174 LONG y;
1175 struct BitMap *bm;
1176 bm = ecrd->destbm;
1177 for (y = 0; y < height; y ++) {
1178 LONG x;
1180 for (x = 0; x < width; x ++) {
1181 if (*pixbuf ++ == ecrd->pixel) {
1183 UBYTE *plane;
1184 ULONG i;
1185 /* Set the according bit in the bitmap */
1186 for (i = 0; i < bm->Depth; i ++) {
1187 plane = bm->Planes[i];
1188 if (NULL != plane) {
1189 UBYTE mask;
1191 plane += COORD_TO_BYTEIDX(x + dstx, y + dsty, bm->BytesPerRow);
1192 mask = XCOORD_TO_MASK(x + dstx);
1194 /* Set the pixel */
1195 *plane |= mask;
1197 } /* if (plane allocated) */
1198 } /* for (plane) */
1199 } /* if (color match) */
1200 } /* for (x) */
1201 } /* for (y) */
1203 return;
1208 static ULONG extcol_render(APTR funcdata
1209 , LONG dstx, LONG dsty
1210 , OOP_Object *dstbm_obj
1211 , OOP_Object *dst_gc
1212 , LONG x1, LONG y1, LONG x2, LONG y2
1213 , struct GfxBase *GfxBase)
1215 /* Get the info from the hidd */
1216 struct extcol_render_data *ecrd;
1218 ecrd = (struct extcol_render_data *)funcdata;
1220 hidd2buf_fast(ecrd->rsi.curbm
1221 , x1, y1
1222 , (APTR)ecrd
1223 , dstx, dsty
1224 , x2 - x1 + 1
1225 , y2 - y1 + 1
1226 , buf_to_extcol
1227 , GfxBase
1230 return (x2 - x1 + 1) * (y2 - y1 + 1);
1234 struct dm_message {
1235 APTR memptr;
1236 ULONG offsetx;
1237 ULONG offsety;
1238 ULONG xsize;
1239 ULONG ysize;
1240 UWORD bytesperrow;
1241 UWORD bytesperpix;
1242 UWORD colormodel;
1246 struct dm_render_data {
1247 struct dm_message msg;
1248 OOP_Object *pf;
1249 struct Hook *hook;
1250 struct RastPort *rp;
1251 IPTR stdpf;
1252 OOP_Object *gc;
1256 static ULONG dm_render(APTR dmr_data
1257 , LONG srcx, LONG srcy
1258 , OOP_Object *dstbm_obj
1259 , OOP_Object *dst_gc
1260 , LONG x1, LONG y1, LONG x2, LONG y2
1261 , struct GfxBase *GfxBase)
1263 struct dm_render_data *dmrd;
1264 UBYTE *addr;
1265 struct dm_message *msg;
1266 IPTR bytesperpixel;
1267 ULONG width, height, fb_width, fb_height;
1268 ULONG banksize, memsize;
1270 dmrd = (struct dm_render_data *)dmr_data;
1271 width = x2 - x1 + 1;
1272 height = y2 - y1 + 1;;
1273 msg = &dmrd->msg;
1274 #if 1
1275 msg->offsetx = x1;
1276 msg->offsety = y1;
1277 #else
1278 #warning "Not sure about this one . Set it to 0 since we adjust msg->memptr to x1/y1 lower down"
1279 msg->offsetx = 0; // x1;
1280 msg->offsety = 0; // y1;
1281 #endif
1282 msg->xsize = width;
1283 msg->ysize = height;
1285 /* Get the baseadress from where to render */
1286 if (HIDD_BM_ObtainDirectAccess(dstbm_obj
1287 , &addr
1288 , &fb_height, &fb_width
1289 , &banksize, &memsize)) {
1291 OOP_GetAttr(dmrd->pf, aHidd_PixFmt_BytesPerPixel, &bytesperpixel);
1292 msg->bytesperpix = (UWORD)bytesperpixel;
1294 /* Colormodel allready set */
1296 /* Compute the adress for the start pixel */
1297 #warning "We should maybe use something else than the BytesPerLine method since we may have alignment"
1298 msg->bytesperrow = HIDD_BM_BytesPerLine(dstbm_obj, dmrd->stdpf, width);
1299 #if 1
1300 msg->memptr = addr;
1301 #else
1302 msg->memptr = addr + (msg->bytesperrow * y1) + (bytesperpixel * x1);
1303 #endif
1305 HIDD_BM_ReleaseDirectAccess(dstbm_obj);
1307 CallHookPkt(dmrd->hook, dmrd->rp, msg);
1309 } else {
1310 /* We are unable to gain direct access to the framebuffer,
1311 so we have to emulate it
1313 ULONG bytesperrow;
1314 ULONG tocopy_h, max_tocopy_h;
1315 ULONG lines_todo;
1317 lines_todo = height;
1319 /* The HIDD bm does not have a base adress so we have to render into
1320 it using a temporary buffer
1322 OOP_GetAttr(dmrd->pf, aHidd_PixFmt_BytesPerPixel, &bytesperpixel);
1323 //bytesperrow = HIDD_BM_BytesPerLine(dstbm_obj, dmrd->stdpf, width);
1324 bytesperrow = width * bytesperpixel;
1327 kprintf("width %d bytesperrow %d bytesperpixel %d\n", width, bytesperrow, bytesperpixel);
1328 kprintf(" colormodel %d\n", msg->colormodel);
1330 if (PIXELBUF_SIZE < bytesperrow) {
1331 D(bug("!!! NOT ENOUGH SPACE IN TEMP BUFFER FOR A SINGLE LINE IN DoCDrawMethodTagList() !!!\n"));
1332 return 0;
1335 /* Calculate number of lines we might copy */
1336 max_tocopy_h = PIXELBUF_SIZE / bytesperrow;
1338 #if 1
1339 msg->offsetx = 0;
1340 msg->offsety = 0;
1341 #endif
1342 /* Get the maximum number of lines */
1343 while (lines_todo != 0) {
1345 struct TagItem gc_tags[] = {
1346 { aHidd_GC_DrawMode, vHidd_GC_DrawMode_Copy },
1347 { TAG_DONE, 0UL }
1350 IPTR old_drmd;
1352 tocopy_h = MIN(lines_todo, max_tocopy_h);
1353 msg->memptr = PrivGBase(GfxBase)->pixel_buf;
1354 msg->bytesperrow = bytesperrow;
1356 msg->bytesperpix = (UWORD)bytesperpixel;
1358 LOCK_PIXBUF
1359 HIDD_BM_GetImage(dstbm_obj
1360 , (UBYTE *)PrivGBase(GfxBase)->pixel_buf
1361 , bytesperrow
1362 , x1, y1 + height - lines_todo, width, lines_todo
1363 , dmrd->stdpf
1366 /* Use the hook to set some pixels */
1367 CallHookPkt(dmrd->hook, dmrd->rp, msg);
1369 OOP_GetAttr(dmrd->gc, aHidd_GC_DrawMode, &old_drmd);
1370 OOP_SetAttrs(dmrd->gc, gc_tags);
1371 HIDD_BM_PutImage(dstbm_obj, dmrd->gc
1372 , (UBYTE *)PrivGBase(GfxBase)->pixel_buf
1373 , bytesperrow
1374 , x1, y1 + height - lines_todo, width, lines_todo
1375 , dmrd->stdpf
1377 gc_tags[0].ti_Data = (IPTR)old_drmd;
1378 OOP_SetAttrs(dmrd->gc, gc_tags);
1380 ULOCK_PIXBUF
1382 lines_todo -= tocopy_h;
1387 return width * height;
1392 LONG driver_WriteLUTPixelArray(APTR srcrect,
1393 UWORD srcx, UWORD srcy,
1394 UWORD srcmod, struct RastPort *rp, APTR ctable,
1395 UWORD destx, UWORD desty,
1396 UWORD sizex, UWORD sizey,
1397 UBYTE ctabformat,
1398 struct GfxBase *GfxBase)
1400 ULONG depth;
1402 HIDDT_PixelLUT pixlut;
1403 HIDDT_Pixel pixtab[256];
1405 HIDDT_Color col;
1406 ULONG i;
1408 LONG pixwritten = 0;
1409 UBYTE *buf;
1411 /* This is cybergraphx. We only work wih HIDD bitmaps */
1412 if (!IS_HIDD_BM(rp->BitMap)) {
1413 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WriteLUTPixelArray()!!!\n"));
1414 return 0;
1417 pixlut.entries = 256;
1418 pixlut.pixels = pixtab;
1420 depth = GetBitMapAttr(rp->BitMap, BMA_DEPTH);
1422 /* This call does only support bitmaps with depth > 8. Use WritePixelArray8
1423 for other bitmaps
1426 if (depth <= 8) {
1427 D(bug("!!! TRYING TO USE WriteLUTPixelArray() ON BITMAP WITH DEPTH < 8\n"));
1428 return 0;
1431 /* Curently only one format is supported */
1432 if (CTABFMT_XRGB8 != ctabformat) {
1433 D(bug("!!! WriteLUTPixelArray() CALLED WITH UNSUPPORTED CTAB FORMAT %d\n"
1434 , ctabformat));
1435 return 0;
1437 col.alpha = 0;
1439 /* Convert the coltab into native pixels */
1440 for (i = 0; i < 256; i ++) {
1441 register ULONG rgb = ((ULONG *)ctable)[i];
1442 col.red = (HIDDT_ColComp)((rgb & 0x00FF0000) >> 8);
1443 col.green = (HIDDT_ColComp)(rgb & 0x0000FF00);
1444 col.blue = (HIDDT_ColComp)((rgb & 0x000000FF) << 8);
1446 pixtab[i] = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
1449 buf = (UBYTE *)srcrect;
1451 buf += CHUNKY8_COORD_TO_BYTEIDX(srcx, srcy, srcmod);
1453 pixwritten = write_pixels_8(rp
1454 , buf
1455 , srcmod
1456 , destx, desty
1457 , destx + sizex - 1, desty + sizey - 1
1458 , &pixlut
1459 , GfxBase
1463 /* Now blit the colors onto the screen */
1465 return pixwritten;
1469 LONG driver_WritePixelArray(APTR src, UWORD srcx, UWORD srcy
1470 , UWORD srcmod, struct RastPort *rp, UWORD destx, UWORD desty
1471 , UWORD width, UWORD height, UBYTE srcformat, struct GfxBase *GfxBase)
1474 OOP_Object *pf = 0;
1475 HIDDT_StdPixFmt srcfmt_hidd = 0, morphfmt_hidd = 0;
1476 ULONG start_offset;
1477 IPTR bppix;
1479 LONG pixwritten = 0;
1481 struct wpa_render_data wpard;
1482 struct Rectangle rr;
1484 if (RECTFMT_GREY8 == srcformat)
1486 static ULONG greytab[256];
1488 /* Ignore possible race conditions during
1489 initialization. Have no bad effect. Just
1490 double initializations. */
1492 /* FIXME/KILLME: evil static array which goes into BSS section
1493 which x86 native AROS regards as evil! */
1495 if (greytab[255] == 0)
1497 WORD i;
1499 for(i = 0; i < 256; i++)
1501 greytab[i] = i * 0x010101;
1505 return driver_WriteLUTPixelArray(src, srcx, srcy, srcmod,
1506 rp, greytab, destx, desty,
1507 width, height, CTABFMT_XRGB8,
1508 GfxBase);
1511 /* This is cybergraphx. We only work wih HIDD bitmaps */
1512 if (!IS_HIDD_BM(rp->BitMap))
1514 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WritePixelArray() !!!\n"));
1515 return 0;
1518 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
1519 return 0;
1521 if (RECTFMT_LUT8 == srcformat)
1524 HIDDT_PixelLUT pixlut = { 256, HIDD_BM_PIXTAB(rp->BitMap) };
1525 UBYTE * array = (UBYTE *)src;
1527 if (rp->BitMap->Flags & BMF_SPECIALFMT)
1529 RELEASE_DRIVERDATA(rp, GfxBase);
1530 D(bug("!!! No CLUT in driver_WritePixelArray\n"));
1531 return 0;
1534 array += CHUNKY8_COORD_TO_BYTEIDX(srcx, srcy, srcmod);
1536 pixwritten = write_pixels_8(rp
1537 , array, srcmod
1538 , destx, desty
1539 , destx + width - 1, desty + height - 1
1540 , &pixlut
1541 , GfxBase);
1543 RELEASE_DRIVERDATA(rp, GfxBase);
1545 return pixwritten;
1548 switch (srcformat)
1550 case RECTFMT_RGB15 : srcfmt_hidd = vHidd_StdPixFmt_RGB15 ; break;
1551 case RECTFMT_BGR15 : srcfmt_hidd = vHidd_StdPixFmt_BGR15 ; break;
1552 case RECTFMT_RGB15PC: srcfmt_hidd = vHidd_StdPixFmt_RGB15_LE; break;
1553 case RECTFMT_BGR15PC: srcfmt_hidd = vHidd_StdPixFmt_BGR15_LE; break;
1554 case RECTFMT_RGB16 : srcfmt_hidd = vHidd_StdPixFmt_RGB16 ; break;
1555 case RECTFMT_BGR16 : srcfmt_hidd = vHidd_StdPixFmt_BGR16 ; break;
1556 case RECTFMT_RGB16PC: srcfmt_hidd = vHidd_StdPixFmt_RGB16_LE; break;
1557 case RECTFMT_BGR16PC: srcfmt_hidd = vHidd_StdPixFmt_BGR16_LE; break;
1558 case RECTFMT_RGB24 : srcfmt_hidd = vHidd_StdPixFmt_RGB24 ; break;
1559 case RECTFMT_BGR24 : srcfmt_hidd = vHidd_StdPixFmt_BGR24 ; break;
1560 case RECTFMT_0RGB32 : srcfmt_hidd = vHidd_StdPixFmt_0RGB32 ; break;
1561 case RECTFMT_BGR032 : srcfmt_hidd = vHidd_StdPixFmt_BGR032 ; break;
1562 case RECTFMT_RGB032 : srcfmt_hidd = vHidd_StdPixFmt_RGB032 ; break;
1563 case RECTFMT_0BGR32 : srcfmt_hidd = vHidd_StdPixFmt_0BGR32 ; break;
1564 case RECTFMT_ARGB32 : srcfmt_hidd = vHidd_StdPixFmt_ARGB32 ; morphfmt_hidd = vHidd_StdPixFmt_0RGB32; break;
1565 case RECTFMT_BGRA32 : srcfmt_hidd = vHidd_StdPixFmt_BGRA32 ; morphfmt_hidd = vHidd_StdPixFmt_BGR032; break;
1566 case RECTFMT_RGBA32 : srcfmt_hidd = vHidd_StdPixFmt_RGBA32 ; morphfmt_hidd = vHidd_StdPixFmt_RGB032; break;
1567 case RECTFMT_ABGR32 : srcfmt_hidd = vHidd_StdPixFmt_ABGR32 ; morphfmt_hidd = vHidd_StdPixFmt_0BGR32; break;
1568 case RECTFMT_RAW : srcfmt_hidd = vHidd_StdPixFmt_Native; break;
1571 /* Compute the start of the array */
1573 #warning Get rid of the below code ?
1574 /* This can be done by passing the srcx and srcy parameters on to
1575 the HIDD bitmap and let it take care of it itself.
1576 This means that HIDD_BM_PutImage() gets a lot of parameters,
1577 which may not be necessary in real life.
1579 Compromise: convert from *CyberGfx* pixfmt to bppix using a table lookup.
1580 This is faster
1582 if ((srcfmt_hidd == vHidd_StdPixFmt_Native) || (morphfmt_hidd != 0))
1584 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&pf);
1587 if (srcfmt_hidd != vHidd_StdPixFmt_Native)
1589 /* RECTFMT_ARGB32 on vHidd_StdPixFmt_0RGB32 bitmap ==> use vHidd_StdPixFmt_0RGB32 */
1590 /* RECTFMT_BGRA32 on vHidd_StdPixFmt_BGR032 bitmap ==> use vHidd_StdPixFmt_BGR032 */
1591 /* RECTFMT_RGBA32 on vHidd_StdPixFmt_RGB032 bitmap ==> use vHidd_StdPixFmt_RGB032 */
1592 /* RECTFMT_ABGR32 on vHidd_StdPixFmt_0BGR32 bitmap ==> use vHidd_StdPixFmt_0BGR32 */
1594 if (morphfmt_hidd != 0)
1596 IPTR stdpf;
1598 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, (IPTR *)&stdpf);
1599 if (stdpf == morphfmt_hidd) srcfmt_hidd = morphfmt_hidd;
1602 pf = HIDD_Gfx_GetPixFmt(SDD(GfxBase)->gfxhidd, srcfmt_hidd);
1605 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, &bppix);
1607 start_offset = ((ULONG)srcy) * srcmod + srcx * bppix;
1609 wpard.array = ((UBYTE *)src) + start_offset;
1610 wpard.pixfmt = srcfmt_hidd;
1611 wpard.modulo = srcmod;
1612 wpard.bppix = bppix;
1614 rr.MinX = destx;
1615 rr.MinY = desty;
1616 rr.MaxX = destx + width - 1;
1617 rr.MaxY = desty + height - 1;
1619 pixwritten = do_render_func(rp, NULL, &rr, wpa_render, &wpard, FALSE, GfxBase);
1621 RELEASE_DRIVERDATA(rp, GfxBase);
1623 return pixwritten;
1626 LONG driver_WritePixelArrayAlpha(APTR src, UWORD srcx, UWORD srcy
1627 , UWORD srcmod, struct RastPort *rp, UWORD destx, UWORD desty
1628 , UWORD width, UWORD height, ULONG globalalpha, struct GfxBase *GfxBase)
1630 ULONG start_offset;
1631 LONG pixwritten = 0;
1632 struct wpaa_render_data wpaard;
1633 struct Rectangle rr;
1635 /* This is cybergraphx. We only work wih HIDD bitmaps */
1636 if (!IS_HIDD_BM(rp->BitMap))
1638 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WritePixelArrayAlpha() !!!\n"));
1639 return 0;
1642 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
1643 return 0;
1645 /* Compute the start of the array */
1647 start_offset = ((ULONG)srcy) * srcmod + srcx * 4;
1649 wpaard.array = ((UBYTE *)src) + start_offset;
1650 wpaard.modulo = srcmod;
1652 rr.MinX = destx;
1653 rr.MinY = desty;
1654 rr.MaxX = destx + width - 1;
1655 rr.MaxY = desty + height - 1;
1657 pixwritten = do_render_func(rp, NULL, &rr, wpaa_render, &wpaard, FALSE, GfxBase);
1659 RELEASE_DRIVERDATA(rp, GfxBase);
1661 return pixwritten;
1664 LONG driver_ReadPixelArray(APTR dst, UWORD destx, UWORD desty
1665 , UWORD dstmod, struct RastPort *rp, UWORD srcx, UWORD srcy
1666 , UWORD width, UWORD height, UBYTE dstformat, struct GfxBase *GfxBase)
1669 OOP_Object *pf = 0;
1670 HIDDT_StdPixFmt dstfmt_hidd = 0, morphfmt_hidd = 0;
1672 ULONG start_offset;
1673 IPTR bppix;
1675 LONG pixread = 0;
1676 IPTR old_drmd;
1677 OOP_Object *gc;
1679 struct Rectangle rr;
1680 struct rpa_render_data rpard;
1682 struct TagItem gc_tags[] =
1684 { aHidd_GC_DrawMode , vHidd_GC_DrawMode_Copy},
1685 { TAG_DONE }
1688 /* This is cybergraphx. We only work wih HIDD bitmaps */
1689 if (!IS_HIDD_BM(rp->BitMap))
1691 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in ReadPixelArray() !!!\n"));
1692 return 0;
1695 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
1696 return 0;
1698 gc = GetDriverData(rp)->dd_GC;
1700 /* Preserve old drawmode */
1701 OOP_GetAttr(gc, aHidd_GC_DrawMode, &old_drmd);
1702 OOP_SetAttrs(gc, gc_tags);
1705 switch (dstformat)
1707 case RECTFMT_RGB15 : dstfmt_hidd = vHidd_StdPixFmt_RGB15 ; break;
1708 case RECTFMT_BGR15 : dstfmt_hidd = vHidd_StdPixFmt_BGR15 ; break;
1709 case RECTFMT_RGB15PC: dstfmt_hidd = vHidd_StdPixFmt_RGB15_LE; break;
1710 case RECTFMT_BGR15PC: dstfmt_hidd = vHidd_StdPixFmt_BGR15_LE; break;
1711 case RECTFMT_RGB16 : dstfmt_hidd = vHidd_StdPixFmt_RGB16 ; break;
1712 case RECTFMT_BGR16 : dstfmt_hidd = vHidd_StdPixFmt_BGR16 ; break;
1713 case RECTFMT_RGB16PC: dstfmt_hidd = vHidd_StdPixFmt_RGB16_LE; break;
1714 case RECTFMT_BGR16PC: dstfmt_hidd = vHidd_StdPixFmt_BGR16_LE; break;
1715 case RECTFMT_RGB24 : dstfmt_hidd = vHidd_StdPixFmt_RGB24 ; break;
1716 case RECTFMT_BGR24 : dstfmt_hidd = vHidd_StdPixFmt_BGR24 ; break;
1717 case RECTFMT_0RGB32 : dstfmt_hidd = vHidd_StdPixFmt_0RGB32 ; break;
1718 case RECTFMT_BGR032 : dstfmt_hidd = vHidd_StdPixFmt_BGR032 ; break;
1719 case RECTFMT_RGB032 : dstfmt_hidd = vHidd_StdPixFmt_RGB032 ; break;
1720 case RECTFMT_0BGR32 : dstfmt_hidd = vHidd_StdPixFmt_0BGR32 ; break;
1721 case RECTFMT_ARGB32 : dstfmt_hidd = vHidd_StdPixFmt_ARGB32 ; morphfmt_hidd = vHidd_StdPixFmt_0RGB32; break;
1722 case RECTFMT_BGRA32 : dstfmt_hidd = vHidd_StdPixFmt_BGRA32 ; morphfmt_hidd = vHidd_StdPixFmt_BGR032; break;
1723 case RECTFMT_RGBA32 : dstfmt_hidd = vHidd_StdPixFmt_RGBA32 ; morphfmt_hidd = vHidd_StdPixFmt_RGB032; break;
1724 case RECTFMT_ABGR32 : dstfmt_hidd = vHidd_StdPixFmt_ABGR32 ; morphfmt_hidd = vHidd_StdPixFmt_0BGR32; break;
1725 case RECTFMT_RAW : dstfmt_hidd = vHidd_StdPixFmt_Native; break;
1728 #warning Get rid of the below code ?
1729 /* This can be done by passing the srcx and srcy parameters on to
1730 the HIDD bitmap and let it take care of it itself.
1731 This means that HIDD_BM_PutImage() gets a lot of parameters,
1732 which may not be necessary in real life.
1734 Compromise: convert from *CyberGfx* pixfmt to bppix using a table lookup.
1735 This is faster
1737 if ((dstfmt_hidd == vHidd_StdPixFmt_Native) || (morphfmt_hidd != 0))
1739 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&pf);
1742 if (dstfmt_hidd != vHidd_StdPixFmt_Native)
1744 /* RECTFMT_ARGB32 on vHidd_StdPixFmt_0RGB32 bitmap ==> use vHidd_StdPixFmt_0RGB32 */
1745 /* RECTFMT_BGRA32 on vHidd_StdPixFmt_BGR032 bitmap ==> use vHidd_StdPixFmt_BGR032 */
1746 /* RECTFMT_RGBA32 on vHidd_StdPixFmt_RGB032 bitmap ==> use vHidd_StdPixFmt_RGB032 */
1747 /* RECTFMT_ABGR32 on vHidd_StdPixFmt_0BGR32 bitmap ==> use vHidd_StdPixFmt_0BGR32 */
1749 if (morphfmt_hidd != 0)
1751 IPTR stdpf;
1753 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, (IPTR *)&stdpf);
1754 if (stdpf == morphfmt_hidd) dstfmt_hidd = morphfmt_hidd;
1757 pf = HIDD_Gfx_GetPixFmt(SDD(GfxBase)->gfxhidd, dstfmt_hidd);
1760 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, &bppix);
1762 start_offset = ((ULONG)desty) * dstmod + destx * bppix;
1764 rpard.array = ((UBYTE *)dst) + start_offset;
1765 rpard.pixfmt = dstfmt_hidd;
1766 rpard.modulo = dstmod;
1767 rpard.bppix = bppix;
1769 rr.MinX = srcx;
1770 rr.MinY = srcy;
1771 rr.MaxX = srcx + width - 1;
1772 rr.MaxY = srcy + height - 1;
1774 pixread = do_render_func(rp, NULL, &rr, rpa_render, &rpard, FALSE, GfxBase);
1776 /* restore old gc values */
1777 gc_tags[0].ti_Data = (IPTR)old_drmd;
1778 OOP_SetAttrs(gc, gc_tags);
1780 RELEASE_DRIVERDATA(rp, GfxBase);
1782 return pixread;
1785 LONG driver_InvertPixelArray(struct RastPort *rp
1786 , UWORD destx, UWORD desty, UWORD width, UWORD height
1787 , struct GfxBase *GfxBase)
1790 /* This is cybergraphx. We only work wih HIDD bitmaps */
1791 if (!IS_HIDD_BM(rp->BitMap))
1793 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap InvertPixelArray() !!!\n"));
1794 return 0;
1797 return (LONG)fillrect_pendrmd(rp
1798 , destx, desty
1799 , destx + width - 1
1800 , desty + height - 1
1801 , 0xFF
1802 , vHidd_GC_DrawMode_Invert
1803 , GfxBase);
1806 LONG driver_FillPixelArray(struct RastPort *rp
1807 , UWORD destx, UWORD desty, UWORD width, UWORD height
1808 , ULONG pixel, struct GfxBase *GfxBase)
1810 HIDDT_Color col;
1811 HIDDT_Pixel pix;
1813 /* HIDDT_ColComp are 16 Bit */
1814 col.alpha = (HIDDT_ColComp)((pixel >> 16) & 0x0000FF00);
1815 col.red = (HIDDT_ColComp)((pixel >> 8) & 0x0000FF00);
1816 col.green = (HIDDT_ColComp)(pixel & 0x0000FF00);
1817 col.blue = (HIDDT_ColComp)((pixel << 8) & 0x0000FF00);
1819 pix = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
1821 return (LONG)fillrect_pendrmd(rp
1822 , destx, desty
1823 , destx + width - 1
1824 , desty + height - 1
1825 , pix
1826 , vHidd_GC_DrawMode_Copy
1827 , GfxBase
1831 ULONG driver_MovePixelArray(UWORD srcx, UWORD srcy, struct RastPort *rp
1832 , UWORD destx, UWORD desty, UWORD width, UWORD height
1833 , struct GfxBase *GfxBase)
1835 ClipBlit(rp
1836 , srcx, srcy
1837 , rp
1838 , destx, desty
1839 , width, height
1840 , 0x00C0 /* Copy */
1842 return width * height;
1847 LONG driver_WriteRGBPixel(struct RastPort *rp, UWORD x, UWORD y
1848 , ULONG pixel, struct GfxBase *GfxBase)
1851 struct rgbpix_render_data prd;
1852 HIDDT_Color col;
1853 LONG retval;
1855 /* This is cybergraphx. We only work wih HIDD bitmaps */
1856 if (!IS_HIDD_BM(rp->BitMap))
1858 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WriteRGBPixel() !!!\n"));
1859 return 0;
1862 if (!OBTAIN_DRIVERDATA(rp, GfxBase)) return -1;
1864 /* HIDDT_ColComp are 16 Bit */
1866 col.alpha = (HIDDT_ColComp)((pixel >> 16) & 0x0000FF00);
1867 col.red = (HIDDT_ColComp)((pixel >> 8) & 0x0000FF00);
1868 col.green = (HIDDT_ColComp)(pixel & 0x0000FF00);
1869 col.blue = (HIDDT_ColComp)((pixel << 8) & 0x0000FF00);
1871 prd.pixel = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
1873 retval = do_pixel_func(rp, x, y, rgbpix_write, &prd, GfxBase);
1875 RELEASE_DRIVERDATA(rp, GfxBase);
1877 return retval;
1882 ULONG driver_ReadRGBPixel(struct RastPort *rp, UWORD x, UWORD y
1883 , struct GfxBase *GfxBase)
1885 struct rgbpix_render_data prd;
1887 /* Get the HIDD pixel val */
1888 HIDDT_Color col;
1889 HIDDT_Pixel pix;
1890 LONG ret;
1892 /* This is cybergraphx. We only work wih HIDD bitmaps */
1893 if (!IS_HIDD_BM(rp->BitMap))
1895 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in ReadRGBPixel()!!!\n"));
1896 return (ULONG)-1;
1899 if (!OBTAIN_DRIVERDATA(rp, GfxBase)) return (ULONG)-1;
1901 ret = do_pixel_func(rp, x, y, pix_read, &prd, GfxBase);
1903 RELEASE_DRIVERDATA(rp, GfxBase);
1905 if (-1 == ret)
1906 return (ULONG)-1;
1908 HIDD_BM_UnmapPixel(HIDD_BM_OBJ(rp->BitMap), prd.pixel, &col);
1910 /* HIDDT_ColComp are 16 Bit */
1912 pix = ((col.alpha & 0xFF00) << 16)
1913 | ((col.red & 0xFF00) << 8)
1914 | (col.green & 0xFF00)
1915 | ((col.blue & 0xFF00) >> 8);
1917 return pix;
1922 ULONG driver_GetCyberMapAttr(struct BitMap *bitMap, ULONG attribute, struct GfxBase *GfxBase)
1924 OOP_Object *bm_obj;
1925 OOP_Object *pf;
1927 IPTR retval;
1929 /* This is cybergraphx. We only work wih HIDD bitmaps */
1930 if (!IS_HIDD_BM(bitMap)) {
1931 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in GetCyberMapAttr() !!!\n"));
1932 return 0;
1935 bm_obj = HIDD_BM_OBJ(bitMap);
1937 OOP_GetAttr(bm_obj, aHidd_BitMap_PixFmt, (IPTR *)&pf);
1939 switch (attribute) {
1940 case CYBRMATTR_XMOD:
1941 OOP_GetAttr(bm_obj, aHidd_BitMap_BytesPerRow, &retval);
1942 break;
1944 case CYBRMATTR_BPPIX:
1945 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, &retval);
1946 break;
1948 case CYBRMATTR_PIXFMT:
1949 case CYBRMATTR_PIXFMT_ALPHA: {
1950 IPTR stdpf;
1951 UWORD cpf;
1952 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, (IPTR *)&stdpf);
1954 /* Convert to cybergfx */
1955 cpf = hidd2cyber_pixfmt(stdpf, GfxBase);
1957 /* CYBRMATTR_PIXFMT doesn't know about non-alpha 32-bit modes */
1958 if (attribute == CYBRMATTR_PIXFMT) {
1959 switch (cpf) {
1960 case PIXFMT_0RGB32: cpf = PIXFMT_ARGB32; break;
1961 case PIXFMT_BGR032: cpf = PIXFMT_BGRA32; break;
1962 case PIXFMT_RGB032: cpf = PIXFMT_RGBA32; break;
1963 case PIXFMT_0BGR32: cpf = PIXFMT_ABGR32; break;
1967 if (cpf == (UWORD)-1) {
1968 D(bug("!!! UNKNOWN PIXEL FORMAT IN GetCyberMapAttr()\n"));
1971 retval = (IPTR)cpf;
1972 break;
1976 case CYBRMATTR_WIDTH:
1977 #if 0 /* stegerg: doesn't really work, because of framebuffer bitmap object stuff */
1978 OOP_GetAttr(bm_obj, aHidd_BitMap_Width, &retval);
1979 #else
1980 retval = GetBitMapAttr(bitMap, BMA_WIDTH);
1981 #endif
1982 break;
1984 case CYBRMATTR_HEIGHT:
1985 #if 0 /* stegerg: doesn't really work, because of framebuffer bitmap object stuff */
1986 OOP_GetAttr(bm_obj, aHidd_BitMap_Height, &retval);
1987 #else
1988 retval = GetBitMapAttr(bitMap, BMA_HEIGHT);
1989 #endif
1990 break;
1992 case CYBRMATTR_DEPTH:
1993 #if 0 /* stegerg: might not really work, because of framebuffer bitmap object stuff */
1994 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &retval);
1995 #else
1996 retval = GetBitMapAttr(bitMap, BMA_DEPTH);
1997 #endif
1998 break;
2000 case CYBRMATTR_ISCYBERGFX: {
2001 IPTR depth;
2003 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &depth);
2005 if (depth < 8) {
2006 retval = 0;
2007 } else {
2008 /* We allways have a HIDD bitmap */
2009 retval = 0xFFFFFFFF; /* Some apps seem to rely on this retval */
2011 break; }
2013 case CYBRMATTR_ISLINEARMEM:
2014 OOP_GetAttr(bm_obj, aHidd_BitMap_IsLinearMem, &retval);
2015 break;
2017 default:
2018 D(bug("!!! UNKNOWN ATTRIBUTE PASSED TO GetCyberMapAttr()\n"));
2019 break;
2022 } /* switch (attribute) */
2024 return retval;
2028 VOID driver_CVideoCtrlTagList(struct ViewPort *vp, struct TagItem *tags, struct GfxBase *GfxBase)
2030 struct TagItem *tag, *tstate;
2031 ULONG dpmslevel = 0;
2033 struct TagItem htags[] =
2035 { aHidd_Gfx_DPMSLevel, 0UL },
2036 { TAG_DONE, 0UL }
2039 BOOL dpms_found = FALSE;
2041 HIDDT_DPMSLevel hdpms = 0;
2043 for (tstate = tags; (tag = NextTagItem((const struct TagItem **)&tstate)); )
2045 switch (tag->ti_Tag)
2047 case SETVC_DPMSLevel:
2048 dpmslevel = tag->ti_Data;
2049 dpms_found = TRUE;
2050 break;
2052 default:
2053 D(bug("!!! UNKNOWN TAG IN CVideoCtrlTagList(): %x !!!\n"
2054 , tag->ti_Tag));
2055 break;
2057 } /* switch() */
2059 } /* for (each tagitem) */
2062 if (dpms_found)
2065 /* Convert to hidd dpms level */
2066 switch (dpmslevel)
2068 case DPMS_ON:
2069 hdpms = vHidd_Gfx_DPMSLevel_On;
2070 break;
2072 case DPMS_STANDBY:
2073 hdpms = vHidd_Gfx_DPMSLevel_Standby;
2074 break;
2076 case DPMS_SUSPEND:
2077 hdpms = vHidd_Gfx_DPMSLevel_Suspend;
2078 break;
2080 case DPMS_OFF:
2081 hdpms = vHidd_Gfx_DPMSLevel_Off;
2082 break;
2084 default:
2085 D(bug("!!! UNKNOWN DPMS LEVEL IN CVideoCtrlTagList(): %x !!!\n"
2086 , dpmslevel));
2088 dpms_found = FALSE;
2089 break;
2094 if (dpms_found)
2096 htags[0].ti_Data = hdpms;
2098 else
2100 htags[0].ti_Tag = TAG_IGNORE;
2103 OOP_SetAttrs(SDD(GfxBase)->gfxhidd, htags);
2105 return;
2109 ULONG driver_ExtractColor(struct RastPort *rp, struct BitMap *bm
2110 , ULONG color, ULONG srcx, ULONG srcy, ULONG width, ULONG height
2111 , struct GfxBase *GfxBase)
2113 struct Rectangle rr;
2114 LONG pixread = 0;
2115 struct extcol_render_data ecrd;
2116 OOP_Object *pf;
2117 IPTR colmod;
2119 if (!IS_HIDD_BM(rp->BitMap))
2121 D(bug("!!! CALLING ExtractColor() ON NO-HIDD BITMAP !!!\n"));
2122 return FALSE;
2125 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
2126 return FALSE;
2128 rr.MinX = srcx;
2129 rr.MinY = srcy;
2130 rr.MaxX = srcx + width - 1;
2131 rr.MaxY = srcy + height - 1;
2133 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&pf);
2135 OOP_GetAttr(pf, aHidd_PixFmt_ColorModel, (IPTR *)&colmod);
2137 if (vHidd_ColorModel_Palette == colmod)
2139 ecrd.pixel = color;
2141 else
2143 HIDDT_Color col;
2145 col.alpha = (color >> 16) & 0x0000FF00;
2146 col.red = (color >> 8 ) & 0x0000FF00;
2147 col.green = color & 0x0000FF00;
2148 col.blue = (color << 8) & 0x0000FF00;
2150 ecrd.pixel = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
2154 ecrd.destbm = bm;
2156 pixread = do_render_func(rp, NULL, &rr, extcol_render, &ecrd, TRUE, GfxBase);
2158 RELEASE_DRIVERDATA(rp, GfxBase);
2160 if (pixread != (width * height))
2161 return FALSE;
2163 return TRUE;
2167 VOID driver_DoCDrawMethodTagList(struct Hook *hook, struct RastPort *rp, struct TagItem *tags, struct GfxBase *GfxBase)
2170 struct dm_render_data dmrd;
2171 struct Rectangle rr;
2172 struct Layer *L;
2174 if (!IS_HIDD_BM(rp->BitMap))
2176 D(bug("!!! NO HIDD BITMAP IN CALL TO DoCDrawMethodTagList() !!!\n"));
2177 return;
2180 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
2181 return;
2183 /* Get the bitmap std pixfmt */
2184 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&dmrd.pf);
2185 OOP_GetAttr(dmrd.pf, aHidd_PixFmt_StdPixFmt, &dmrd.stdpf);
2186 dmrd.msg.colormodel = hidd2cyber_pixfmt(dmrd.stdpf, GfxBase);
2187 dmrd.hook = hook;
2188 dmrd.rp = rp;
2190 if (((UWORD)-1) == dmrd.msg.colormodel)
2192 RELEASE_DRIVERDATA(rp, GfxBase);
2193 D(bug("!!! UNKNOWN HIDD PIXFMT IN DoCDrawMethodTagList() !!!\n"));
2194 return;
2198 L = rp->Layer;
2200 rr.MinX = 0;
2201 rr.MinY = 0;
2203 if (NULL == L)
2205 rr.MaxX = GetBitMapAttr(rp->BitMap, BMA_WIDTH) - 1;
2206 rr.MaxY = GetBitMapAttr(rp->BitMap, BMA_HEIGHT) - 1;
2208 else
2210 /* Lock the layer */
2211 LockLayerRom(L);
2213 rr.MaxX = rr.MinX + (L->bounds.MaxX - L->bounds.MinX) - 1;
2214 rr.MaxY = rr.MinY + (L->bounds.MaxY - L->bounds.MinY) - 1;
2217 dmrd.gc = GetDriverData(rp)->dd_GC;
2218 do_render_func(rp, NULL, &rr, dm_render, &dmrd, FALSE, GfxBase);
2220 RELEASE_DRIVERDATA(rp, GfxBase);
2222 if (NULL != L)
2224 UnlockLayerRom(L);
2227 return;
2230 APTR driver_LockBitMapTagList(struct BitMap *bm, struct TagItem *tags, struct GfxBase *GfxBase)
2232 struct TagItem *tag;
2233 UBYTE *baseaddress;
2234 ULONG width, height, banksize, memsize;
2235 OOP_Object *pf;
2236 IPTR stdpf;
2237 UWORD cpf;
2239 if (!IS_HIDD_BM(bm))
2241 D(bug("!!! TRYING TO CALL LockBitMapTagList() ON NON-HIDD BM !!!\n"));
2242 return NULL;
2245 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_PixFmt, (IPTR *)&pf);
2247 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, &stdpf);
2248 cpf = hidd2cyber_pixfmt(stdpf, GfxBase);
2249 if (((UWORD)-1) == cpf)
2251 D(bug("!!! TRYING TO CALL LockBitMapTagList() ON NON-CYBER PIXFMT BITMAP !!!\n"));
2252 return NULL;
2255 /* Get some info from the bitmap object */
2256 if (!HIDD_BM_ObtainDirectAccess(HIDD_BM_OBJ(bm), &baseaddress, &width, &height, &banksize, &memsize))
2257 return NULL;
2260 while ((tag = NextTagItem((const struct TagItem **)&tags)))
2262 switch (tag->ti_Tag)
2264 case LBMI_BASEADDRESS:
2265 *((IPTR **)tag->ti_Data) = (IPTR *)baseaddress;
2266 break;
2268 case LBMI_BYTESPERROW:
2269 *((IPTR *)tag->ti_Data) =
2270 (ULONG)HIDD_BM_BytesPerLine(HIDD_BM_OBJ(bm), stdpf, width);
2271 break;
2273 case LBMI_BYTESPERPIX:
2274 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, (IPTR *)tag->ti_Data);
2275 break;
2277 case LBMI_PIXFMT:
2278 *((IPTR *)tag->ti_Data) = (IPTR)cpf;
2279 break;
2281 case LBMI_DEPTH:
2282 OOP_GetAttr(pf, aHidd_PixFmt_Depth, (IPTR *)tag->ti_Data);
2283 break;
2285 case LBMI_WIDTH:
2286 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_Width, (IPTR *)tag->ti_Data);
2287 break;
2289 case LBMI_HEIGHT:
2290 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_Height, (IPTR *)tag->ti_Data);
2291 break;
2293 default:
2294 D(bug("!!! UNKNOWN TAG PASSED TO LockBitMapTagList() !!!\n"));
2295 break;
2299 return HIDD_BM_OBJ(bm);
2302 VOID driver_UnLockBitMap(APTR handle, struct GfxBase *GfxBase)
2304 if (handle) HIDD_BM_ReleaseDirectAccess((OOP_Object *)handle);
2307 VOID driver_UnLockBitMapTagList(APTR handle, struct TagItem *tags, struct GfxBase *GfxBase)
2309 struct TagItem *tag;
2310 BOOL reallyunlock = TRUE;
2312 while ((tag = NextTagItem((const struct TagItem **)&tags)))
2314 switch (tag->ti_Tag)
2316 case UBMI_REALLYUNLOCK:
2317 reallyunlock = (BOOL)tag->ti_Data;
2318 break;
2320 case UBMI_UPDATERECTS:
2322 struct RectList *rl;
2324 rl = (struct RectList *)tag->ti_Data;
2326 #warning Dunno what to do with this
2328 break;
2331 default:
2332 D(bug("!!! UNKNOWN TAG PASSED TO UnLockBitMapTagList() !!!\n"));
2333 break;
2337 if (reallyunlock)
2339 HIDD_BM_ReleaseDirectAccess((OOP_Object *)handle);
2343 void driver_BltTemplateAlpha(UBYTE *src, LONG srcx, LONG srcmod
2344 , struct RastPort *rp, LONG destx, LONG desty, LONG width, LONG height
2345 , struct GfxBase *GfxBase)
2347 struct bta_render_data btard;
2348 struct Rectangle rr;
2350 /* This is cybergraphx. We only work wih HIDD bitmaps */
2351 if (!IS_HIDD_BM(rp->BitMap)) {
2352 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in BltTemplateAlpha() !!!\n"));
2353 return;
2356 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
2357 return;
2359 /* Compute the start of the array */
2361 btard.array = src + srcx;
2362 btard.modulo = srcmod;
2363 btard.invertalpha = (rp->DrawMode & INVERSVID) ? TRUE : FALSE;
2364 rr.MinX = destx;
2365 rr.MinY = desty;
2366 rr.MaxX = destx + width - 1;
2367 rr.MaxY = desty + height - 1;
2369 do_render_func(rp, NULL, &rr, bta_render, &btard, FALSE, GfxBase);
2371 RELEASE_DRIVERDATA(rp, GfxBase);
2374 /******************************************/
2375 /* Support stuff for cybergfx */
2376 /******************************************/
2378 #undef GfxBase