some fixes to accented characters
[tangerine.git] / rom / graphics / graphics_driver.c
blobc9f08e1eb8d23fb46accd3ed22e67beba424fddf
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);
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 01,03,00,00,00,00,00,00,00,00,00,
527 02,01,03,03,00,00,00,00,00,00,00,
528 00,02,01,01,03,03,00,00,00,00,00,
529 00,02,01,01,01,01,03,03,00,00,00,
530 00,00,02,01,01,01,01,01,03,03,00,
531 00,00,02,01,01,01,01,01,01,01,00,
532 00,00,00,02,01,01,01,03,00,00,00,
533 00,00,00,02,01,01,03,01,03,00,00,
534 00,00,00,00,02,01,00,02,01,03,00,
535 00,00,00,00,02,01,00,00,02,01,03,
536 00,00,00,00,00,00,00,00,00,01,01
539 #define DEF_POINTER_WIDTH 11
540 #define DEF_POINTER_HEIGHT 11
541 #define DEF_POINTER_DEPTH 4
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] = {0};
568 col[0].red = 0x0000;
569 col[0].green = 0x0000;
570 col[0].blue = 0x0000;
571 col[0].alpha = 0x0000;
572 col[1].red = 0xE0E0;
573 col[1].green = 0x4040;
574 col[1].blue = 0x4040;
575 col[1].alpha = 0x0000;
576 col[2].red = 0x0000;
577 col[2].green = 0x0000;
578 col[2].blue = 0x0000;
579 col[2].alpha = 0x0000;
580 col[3].red = 0xE0E0;
581 col[3].green = 0xE0E0;
582 col[3].blue = 0xC0C0;
583 col[3].alpha = 0x0000;
585 HIDD_BM_SetColors(SDD(GfxBase)->pointerbm, col, 0, DEF_POINTER_DEPTH);
587 OOP_SetAttrs(gc, gc_tags);
588 #if 0
589 /* PutImageLUT not yet implemented in gfx baseclass */
590 HIDD_BM_PutImageLUT(SDD(GfxBase)->pointerbm, gc
591 , (UBYTE *)def_pointer_shape
592 , DEF_POINTER_WIDTH
593 , 0, 0
594 , DEF_POINTER_WIDTH, DEF_POINTER_HEIGHT
595 , &plut
597 #else
598 HIDD_BM_PutImage(SDD(GfxBase)->pointerbm, gc
599 , (UBYTE *)def_pointer_shape
600 , DEF_POINTER_WIDTH
601 , 0, 0
602 , DEF_POINTER_WIDTH, DEF_POINTER_HEIGHT
603 , vHidd_StdPixFmt_LUT8
606 #endif
607 release_cache_object(SDD(GfxBase)->gc_cache, gc, GfxBase);
609 if (HIDD_Gfx_SetCursorShape(SDD(GfxBase)->gfxhidd, SDD(GfxBase)->pointerbm)) {
610 D(bug("CURSOR SHAPE SET\n"));
611 /* Make it visible */
612 HIDD_Gfx_SetCursorVisible(SDD(GfxBase)->gfxhidd, TRUE);
614 return TRUE;
619 cleanup_cursor(GfxBase);
621 return FALSE;
624 static VOID cleanup_cursor(struct GfxBase *GfxBase)
626 if (NULL != SDD(GfxBase)->pointerbm) {
627 OOP_DisposeObject(SDD(GfxBase)->pointerbm);
628 SDD(GfxBase)->pointerbm = NULL;
632 BOOL driver_LateGfxInit (APTR data, struct GfxBase *GfxBase)
635 /* Supplied data is really the librarybase of a HIDD */
636 STRPTR gfxhiddname = (STRPTR)data;
637 struct TagItem tags[] = {
638 { TAG_DONE, 0UL },
640 EnterFunc(bug("driver_LateGfxInit(gfxhiddname=%s)\n", gfxhiddname));
642 /* Create a new GfxHidd object */
644 SDD(GfxBase)->gfxhidd = SDD(GfxBase)->gfxhidd_orig = OOP_NewObject(NULL, gfxhiddname, tags);
645 D(bug("driver_LateGfxInit: gfxhidd=%p\n", SDD(GfxBase)->gfxhidd));
647 if (NULL != SDD(GfxBase)->gfxhidd) {
648 IPTR hwcursor = 0;
649 IPTR noframebuffer = 0;
650 BOOL ok = TRUE;
652 /* Get method id here, to avoid any possible semaphore involment when calling the method */
653 SDD(GfxBase)->hiddGfxShowImminentReset_MethodID = OOP_GetMethodID(IID_Hidd_Gfx, moHidd_Gfx_ShowImminentReset);
655 OOP_GetAttr(SDD(GfxBase)->gfxhidd, aHidd_Gfx_SupportsHWCursor, &hwcursor);
656 OOP_GetAttr(SDD(GfxBase)->gfxhidd, aHidd_Gfx_NoFrameBuffer, &noframebuffer);
657 SDD(GfxBase)->has_hw_cursor = (BOOL)hwcursor;
658 if (!hwcursor) {
659 OOP_Object *fgh;
660 D(bug("There's no hardware cursor\n"));
662 fgh = init_fakegfxhidd(SDD(GfxBase)->gfxhidd
663 , &SDD(GfxBase)->fakegfx_staticdata
664 , GfxBase);
666 if (NULL != fgh) {
667 SDD(GfxBase)->gfxhidd = fgh;
668 SDD(GfxBase)->fakegfx_inited = TRUE;
669 } else {
670 ok = FALSE;
674 if (ok) {
675 struct TagItem gc_create_tags[] = { { TAG_DONE, 0UL } };
676 D(bug("Ok\n"));
677 SDD(GfxBase)->gc_cache = create_object_cache(NULL, IID_Hidd_GC, gc_create_tags, GfxBase);
678 if (NULL != SDD(GfxBase)->gc_cache) {
680 struct TagItem bm_create_tags[] = {
681 #warning Maybe make this class private and create the object through the graphicshidd
682 { aHidd_BitMap_GfxHidd, (IPTR)SDD(GfxBase)->gfxhidd_orig },
683 { aHidd_BitMap_Displayable, FALSE },
684 { aHidd_PlanarBM_AllocPlanes, FALSE },
685 { TAG_DONE, 0UL }
688 D(bug("Cache created\n"));
689 SDD(GfxBase)->planarbm_cache = create_object_cache(NULL, CLID_Hidd_PlanarBM, bm_create_tags, GfxBase);
691 if (NULL != SDD(GfxBase)->planarbm_cache) {
693 /* Move the modes into the displayinfo DB */
694 SDD(GfxBase)->dispinfo_db = build_dispinfo_db(GfxBase);
695 if (NULL != SDD(GfxBase)->dispinfo_db) {
696 if (!noframebuffer)
697 SDD(GfxBase)->framebuffer = create_framebuffer(GfxBase);
698 if (noframebuffer || SDD(GfxBase)->framebuffer) {
699 D(bug("FRAMEBUFFER OK: %p\n", SDD(GfxBase)->framebuffer));
700 if (init_cursor(GfxBase)) {
701 D(bug("MOUSE INITED\n"));
702 ReturnBool("driver_LateGfxInit", TRUE);
705 if (SDD(GfxBase)->framebuffer)
706 OOP_DisposeObject(SDD(GfxBase)->framebuffer);
707 destroy_dispinfo_db(SDD(GfxBase)->dispinfo_db, GfxBase);
708 SDD(GfxBase)->dispinfo_db = NULL;
709 } /* if (displayinfo db inited) */
710 delete_object_cache(SDD(GfxBase)->planarbm_cache, GfxBase);
711 SDD(GfxBase)->planarbm_cache = NULL;
712 } /* if (planarbm cache created) */
713 delete_object_cache(SDD(GfxBase)->gc_cache, GfxBase);
714 SDD(GfxBase)->gc_cache = NULL;
715 } /* if (gc object cache ok) */
717 } /* if (fake gfx stuff ok) */
719 if (SDD(GfxBase)->fakegfx_inited) {
720 cleanup_fakegfxhidd(&SDD(GfxBase)->fakegfx_staticdata, GfxBase);
721 SDD(GfxBase)->fakegfx_inited = FALSE;
723 OOP_DisposeObject(SDD(GfxBase)->gfxhidd_orig);
724 SDD(GfxBase)->gfxhidd_orig = NULL;
728 ReturnBool("driver_LateGfxInit", FALSE);
733 #if 0 /* Unused? */
735 static ULONG getbitmappixel(struct BitMap *bm
736 , LONG x
737 , LONG y
738 , UBYTE depth
739 , UBYTE plane_mask)
741 UBYTE i;
742 ULONG idx;
744 ULONG mask;
745 ULONG pen = 0;
747 idx = COORD_TO_BYTEIDX(x, y, bm->BytesPerRow);
748 mask = XCOORD_TO_MASK( x );
750 for (i = depth - 1; depth; i -- , depth -- )
752 pen <<= 1; /* stegerg: moved to here, was inside if!? */
754 if ((1L << i) & plane_mask)
756 UBYTE *plane = bm->Planes[i];
758 if (plane == (PLANEPTR)-1)
760 pen |= 1;
762 else if (plane != NULL)
764 if ((plane[idx] & mask) != 0)
765 pen |= 1;
770 return pen;
773 #endif
776 #define dumprect(rect) \
777 kprintf(#rect " : (%d,%d) - (%d,%d)\n",(rect)->MinX,(rect)->MinY,(rect)->MaxX,(rect)->MaxY)
780 struct bgf_render_data {
781 WORD fbm_xsrc;
782 OOP_Object *fbm;
785 static ULONG bgf_render(APTR bgfr_data
786 , LONG srcx, LONG srcy
787 , OOP_Object *dstbm_obj, OOP_Object *dst_gc
788 , LONG x1, LONG y1, LONG x2, LONG y2
789 , struct GfxBase *GfxBase)
791 struct bgf_render_data *bgfrd;
792 ULONG width, height;
794 width = x2 - x1 + 1;
795 height = y2 - y1 + 1;
797 ASSERT(width > 0 && height > 0);
799 bgfrd = (struct bgf_render_data *)bgfr_data;
801 HIDD_BM_BlitColorExpansion( dstbm_obj
802 , dst_gc
803 , bgfrd->fbm
804 , srcx + bgfrd->fbm_xsrc, srcy /* stegerg: instead of srcy there was a 0 */
805 , x1, y1
806 , width, height
809 return width * height;
813 void blit_glyph_fast(struct RastPort *rp, OOP_Object *fontbm, WORD xsrc
814 , WORD destx, WORD desty, UWORD width, UWORD height
815 , struct GfxBase * GfxBase)
818 struct Rectangle rr;
819 struct bgf_render_data bgfrd;
821 EnterFunc(bug("blit_glyph_fast(%d, %d, %d, %d, %d)\n"
822 , xsrc, destx, desty, width, height));
825 ASSERT(width > 0 && height > 0);
827 bgfrd.fbm_xsrc = xsrc;
828 bgfrd.fbm = fontbm;
830 rr.MinX = destx;
831 rr.MinY = desty;
832 rr.MaxX = destx + width - 1;
833 rr.MaxY = desty + height - 1;
835 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
836 ReturnVoid("blit_glyph_fast");
838 do_render_func(rp, NULL, &rr, bgf_render, &bgfrd, FALSE, GfxBase);
840 RELEASE_DRIVERDATA(rp, GfxBase);
842 ReturnVoid("blit_glyph_fast");
847 #define NUMCHARS(tf) ((tf->tf_HiChar - tf->tf_LoChar) + 2)
848 #define CTF(x) ((struct ColorTextFont *)x)
850 void driver_Text (struct RastPort * rp, CONST_STRPTR string, LONG len,
851 struct GfxBase * GfxBase)
854 #warning Does not handle color textfonts
855 WORD render_y;
856 struct TextFont *tf;
857 WORD current_x;
858 OOP_Object *fontbm = NULL;
860 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
861 return;
863 if ((rp->DrawMode & ~INVERSVID) == JAM2)
865 struct TextExtent te;
866 ULONG old_drmd = GetDrMd(rp);
868 /* This is actually needed, because below only the
869 part of the glyph which contains data is rendered:
871 ...1100...
872 ...1100...
873 ...1100...
874 ...1111...
876 '.' at left side can be there because of kerning.
877 '.' at the right side can be there because of
878 CharSpace being bigger than glyph bitmap data
879 width.
882 TextExtent(rp, string, len, &te);
883 SetDrMd(rp, old_drmd ^ INVERSVID);
884 RectFill(rp, rp->cp_x + te.te_Extent.MinX,
885 rp->cp_y + te.te_Extent.MinY,
886 rp->cp_x + te.te_Extent.MaxX,
887 rp->cp_y + te.te_Extent.MaxY);
888 SetDrMd(rp, old_drmd);
891 /* does this rastport have a layer. If yes, lock the layer it.*/
892 if (NULL != rp->Layer)
893 LockLayerRom(rp->Layer);
895 tf = rp->Font;
897 if (ExtendFont(tf, NULL))
899 fontbm = ((struct TextFontExtension_intern *)(tf->tf_Extension))->hash->font_bitmap;
902 /* Check if font has character data as a HIDD bitmap */
904 if (NULL == fontbm)
906 D(bug("FONT HAS NO HIDD BITMAP ! Won't render text\n"));
907 RELEASE_DRIVERDATA(rp, GfxBase);
908 return;
912 /* Render along font's baseline */
913 render_y = rp->cp_y - tf->tf_Baseline;
914 current_x = rp->cp_x;
916 while ( len -- )
918 ULONG charloc;
919 ULONG idx;
921 if (*string < tf->tf_LoChar || *string > tf->tf_HiChar )
923 /* A character which there is no glyph for. We just
924 draw the last glyph in the font
926 idx = NUMCHARS(tf) - 1;
928 else
930 idx = *string - tf->tf_LoChar;
933 charloc = ((ULONG *)tf->tf_CharLoc)[idx];
935 if (tf->tf_CharKern)
937 current_x += ((WORD *)tf->tf_CharKern)[idx];
940 if ((tf->tf_Style & FSF_COLORFONT) &&
941 !(CTF(tf)->ctf_Flags & CT_ANTIALIAS))
943 #warning Handle color fonts
945 else
947 WORD
948 glyphXOffset = charloc >> 16,
949 glyphWidth = charloc & 0xFFFF;
951 ASSERT(tf->tf_YSize > 0);
953 /* blit the glypth if it has data in the bitmap */
954 if (glyphWidth > 0)
956 blit_glyph_fast(rp, fontbm, glyphXOffset, current_x, render_y,
957 glyphWidth, tf->tf_YSize, GfxBase);
961 if (tf->tf_CharSpace)
962 current_x += ((WORD *)tf->tf_CharSpace)[idx];
963 else
964 current_x += tf->tf_XSize; /* Add glyph width */
966 current_x += rp->TxSpacing;
968 string ++;
969 } /* for (each character to render) */
971 Move(rp, current_x, rp->cp_y);
973 if (NULL != rp->Layer)
974 UnlockLayerRom(rp->Layer);
976 RELEASE_DRIVERDATA(rp, GfxBase);
978 return;
982 /***********************************************/
983 /* CYBERGFX CALLS ***/
986 struct wpa_render_data
988 UBYTE *array;
989 HIDDT_StdPixFmt pixfmt;
990 ULONG modulo;
991 ULONG bppix;
994 static ULONG wpa_render(APTR wpar_data
995 , LONG srcx, LONG srcy
996 , OOP_Object *dstbm_obj
997 , OOP_Object *dst_gc
998 , LONG x1, LONG y1, LONG x2, LONG y2
999 , struct GfxBase *GfxBase)
1001 struct wpa_render_data *wpard;
1002 ULONG width, height;
1003 UBYTE *array;
1005 width = x2 - x1 + 1;
1006 height = y2 - y1 + 1;
1008 wpard = (struct wpa_render_data *)wpar_data;
1010 array = wpard->array + wpard->modulo * srcy + wpard->bppix * srcx;
1012 HIDD_BM_PutImage(dstbm_obj
1013 , dst_gc, array
1014 , wpard->modulo
1015 , x1, y1
1016 , width, height
1017 , wpard->pixfmt
1020 return width * height;
1023 struct wpaa_render_data
1025 UBYTE *array;
1026 ULONG modulo;
1029 static ULONG wpaa_render(APTR wpaar_data
1030 , LONG srcx, LONG srcy
1031 , OOP_Object *dstbm_obj
1032 , OOP_Object *dst_gc
1033 , LONG x1, LONG y1, LONG x2, LONG y2
1034 , struct GfxBase *GfxBase)
1036 struct wpaa_render_data *wpaard;
1037 ULONG width, height;
1038 UBYTE *array;
1040 width = x2 - x1 + 1;
1041 height = y2 - y1 + 1;
1043 wpaard = (struct wpaa_render_data *)wpaar_data;
1045 array = wpaard->array + wpaard->modulo * srcy + 4 * srcx;
1047 HIDD_BM_PutAlphaImage(dstbm_obj
1048 , dst_gc, array
1049 , wpaard->modulo
1050 , x1, y1
1051 , width, height
1054 return width * height;
1057 struct bta_render_data
1059 UBYTE *array;
1060 ULONG modulo;
1061 UBYTE invertalpha;
1064 static ULONG bta_render(APTR bta_data
1065 , LONG srcx, LONG srcy
1066 , OOP_Object *dstbm_obj
1067 , OOP_Object *dst_gc
1068 , LONG x1, LONG y1, LONG x2, LONG y2
1069 , struct GfxBase *GfxBase)
1071 struct bta_render_data *btard;
1072 ULONG width, height;
1073 UBYTE *array;
1075 width = x2 - x1 + 1;
1076 height = y2 - y1 + 1;
1078 btard = (struct bta_render_data *)bta_data;
1080 array = btard->array + btard->modulo * srcy + srcx;
1082 HIDD_BM_PutAlphaTemplate(dstbm_obj
1083 , dst_gc, array
1084 , btard->modulo
1085 , x1, y1
1086 , width, height
1087 , btard->invertalpha
1090 return width * height;
1093 struct rpa_render_data {
1094 UBYTE *array;
1095 HIDDT_StdPixFmt pixfmt;
1096 ULONG modulo;
1097 ULONG bppix;
1100 static ULONG rpa_render(APTR rpar_data
1101 , LONG srcx, LONG srcy
1102 , OOP_Object *dstbm_obj
1103 , OOP_Object *dst_gc
1104 , LONG x1, LONG y1, LONG x2, LONG y2
1105 , struct GfxBase *GfxBase)
1107 struct rpa_render_data *rpard;
1108 ULONG width, height;
1109 UBYTE *array;
1111 width = x2 - x1 + 1;
1112 height = y2 - y1 + 1;
1114 rpard = (struct rpa_render_data *)rpar_data;
1116 array = rpard->array + rpard->modulo * srcy + rpard->bppix * srcx;
1118 HIDD_BM_GetImage(dstbm_obj
1119 , array
1120 , rpard->modulo
1121 , x1, y1
1122 , width, height
1123 , rpard->pixfmt
1126 return width * height;
1129 static LONG pix_read(APTR pr_data
1130 , OOP_Object *bm, OOP_Object *gc
1131 , LONG x, LONG y
1132 , struct GfxBase *GfxBase)
1134 struct rgbpix_render_data *prd;
1136 prd = (struct rgbpix_render_data *)pr_data;
1138 prd->pixel = HIDD_BM_GetPixel(bm, x, y);
1141 return 0;
1145 struct extcol_render_data {
1146 struct render_special_info rsi;
1147 struct BitMap *destbm;
1148 HIDDT_Pixel pixel;
1152 static VOID buf_to_extcol(struct extcol_render_data *ecrd
1153 , LONG srcx, LONG srcy
1154 , LONG dstx, LONG dsty
1155 , ULONG width, ULONG height
1156 , HIDDT_Pixel *pixbuf
1157 , OOP_Object *bm_obj
1158 , HIDDT_Pixel *pixtab)
1160 LONG y;
1161 struct BitMap *bm;
1162 bm = ecrd->destbm;
1163 for (y = 0; y < height; y ++) {
1164 LONG x;
1166 for (x = 0; x < width; x ++) {
1167 if (*pixbuf ++ == ecrd->pixel) {
1169 UBYTE *plane;
1170 ULONG i;
1171 /* Set the according bit in the bitmap */
1172 for (i = 0; i < bm->Depth; i ++) {
1173 plane = bm->Planes[i];
1174 if (NULL != plane) {
1175 UBYTE mask;
1177 plane += COORD_TO_BYTEIDX(x + dstx, y + dsty, bm->BytesPerRow);
1178 mask = XCOORD_TO_MASK(x + dstx);
1180 /* Set the pixel */
1181 *plane |= mask;
1183 } /* if (plane allocated) */
1184 } /* for (plane) */
1185 } /* if (color match) */
1186 } /* for (x) */
1187 } /* for (y) */
1189 return;
1194 static ULONG extcol_render(APTR funcdata
1195 , LONG dstx, LONG dsty
1196 , OOP_Object *dstbm_obj
1197 , OOP_Object *dst_gc
1198 , LONG x1, LONG y1, LONG x2, LONG y2
1199 , struct GfxBase *GfxBase)
1201 /* Get the info from the hidd */
1202 struct extcol_render_data *ecrd;
1204 ecrd = (struct extcol_render_data *)funcdata;
1206 hidd2buf_fast(ecrd->rsi.curbm
1207 , x1, y1
1208 , (APTR)ecrd
1209 , dstx, dsty
1210 , x2 - x1 + 1
1211 , y2 - y1 + 1
1212 , buf_to_extcol
1213 , GfxBase
1216 return (x2 - x1 + 1) * (y2 - y1 + 1);
1220 struct dm_message {
1221 APTR memptr;
1222 ULONG offsetx;
1223 ULONG offsety;
1224 ULONG xsize;
1225 ULONG ysize;
1226 UWORD bytesperrow;
1227 UWORD bytesperpix;
1228 UWORD colormodel;
1232 struct dm_render_data {
1233 struct dm_message msg;
1234 OOP_Object *pf;
1235 struct Hook *hook;
1236 struct RastPort *rp;
1237 IPTR stdpf;
1238 OOP_Object *gc;
1242 static ULONG dm_render(APTR dmr_data
1243 , LONG srcx, LONG srcy
1244 , OOP_Object *dstbm_obj
1245 , OOP_Object *dst_gc
1246 , LONG x1, LONG y1, LONG x2, LONG y2
1247 , struct GfxBase *GfxBase)
1249 struct dm_render_data *dmrd;
1250 UBYTE *addr;
1251 struct dm_message *msg;
1252 IPTR bytesperpixel;
1253 ULONG width, height, fb_width, fb_height;
1254 ULONG banksize, memsize;
1256 dmrd = (struct dm_render_data *)dmr_data;
1257 width = x2 - x1 + 1;
1258 height = y2 - y1 + 1;;
1259 msg = &dmrd->msg;
1260 #if 1
1261 msg->offsetx = x1;
1262 msg->offsety = y1;
1263 #else
1264 #warning "Not sure about this one . Set it to 0 since we adjust msg->memptr to x1/y1 lower down"
1265 msg->offsetx = 0; // x1;
1266 msg->offsety = 0; // y1;
1267 #endif
1268 msg->xsize = width;
1269 msg->ysize = height;
1271 /* Get the baseadress from where to render */
1272 if (HIDD_BM_ObtainDirectAccess(dstbm_obj
1273 , &addr
1274 , &fb_height, &fb_width
1275 , &banksize, &memsize)) {
1277 OOP_GetAttr(dmrd->pf, aHidd_PixFmt_BytesPerPixel, &bytesperpixel);
1278 msg->bytesperpix = (UWORD)bytesperpixel;
1280 /* Colormodel allready set */
1282 /* Compute the adress for the start pixel */
1283 #warning "We should maybe use something else than the BytesPerLine method since we may have alignment"
1284 msg->bytesperrow = HIDD_BM_BytesPerLine(dstbm_obj, dmrd->stdpf, width);
1285 #if 1
1286 msg->memptr = addr;
1287 #else
1288 msg->memptr = addr + (msg->bytesperrow * y1) + (bytesperpixel * x1);
1289 #endif
1291 HIDD_BM_ReleaseDirectAccess(dstbm_obj);
1293 CallHookPkt(dmrd->hook, dmrd->rp, msg);
1295 } else {
1296 /* We are unable to gain direct access to the framebuffer,
1297 so we have to emulate it
1299 ULONG bytesperrow;
1300 ULONG tocopy_h, max_tocopy_h;
1301 ULONG lines_todo;
1303 lines_todo = height;
1305 /* The HIDD bm does not have a base adress so we have to render into
1306 it using a temporary buffer
1308 OOP_GetAttr(dmrd->pf, aHidd_PixFmt_BytesPerPixel, &bytesperpixel);
1309 //bytesperrow = HIDD_BM_BytesPerLine(dstbm_obj, dmrd->stdpf, width);
1310 bytesperrow = width * bytesperpixel;
1313 kprintf("width %d bytesperrow %d bytesperpixel %d\n", width, bytesperrow, bytesperpixel);
1314 kprintf(" colormodel %d\n", msg->colormodel);
1316 if (PIXELBUF_SIZE < bytesperrow) {
1317 D(bug("!!! NOT ENOUGH SPACE IN TEMP BUFFER FOR A SINGLE LINE IN DoCDrawMethodTagList() !!!\n"));
1318 return 0;
1321 /* Calculate number of lines we might copy */
1322 max_tocopy_h = PIXELBUF_SIZE / bytesperrow;
1324 #if 1
1325 msg->offsetx = 0;
1326 msg->offsety = 0;
1327 #endif
1328 /* Get the maximum number of lines */
1329 while (lines_todo != 0) {
1331 struct TagItem gc_tags[] = {
1332 { aHidd_GC_DrawMode, vHidd_GC_DrawMode_Copy },
1333 { TAG_DONE, 0UL }
1336 IPTR old_drmd;
1338 tocopy_h = MIN(lines_todo, max_tocopy_h);
1339 msg->memptr = PrivGBase(GfxBase)->pixel_buf;
1340 msg->bytesperrow = bytesperrow;
1342 msg->bytesperpix = (UWORD)bytesperpixel;
1344 LOCK_PIXBUF
1345 HIDD_BM_GetImage(dstbm_obj
1346 , (UBYTE *)PrivGBase(GfxBase)->pixel_buf
1347 , bytesperrow
1348 , x1, y1 + height - lines_todo, width, lines_todo
1349 , dmrd->stdpf
1352 /* Use the hook to set some pixels */
1353 CallHookPkt(dmrd->hook, dmrd->rp, msg);
1355 OOP_GetAttr(dmrd->gc, aHidd_GC_DrawMode, &old_drmd);
1356 OOP_SetAttrs(dmrd->gc, gc_tags);
1357 HIDD_BM_PutImage(dstbm_obj, dmrd->gc
1358 , (UBYTE *)PrivGBase(GfxBase)->pixel_buf
1359 , bytesperrow
1360 , x1, y1 + height - lines_todo, width, lines_todo
1361 , dmrd->stdpf
1363 gc_tags[0].ti_Data = (IPTR)old_drmd;
1364 OOP_SetAttrs(dmrd->gc, gc_tags);
1366 ULOCK_PIXBUF
1368 lines_todo -= tocopy_h;
1373 return width * height;
1378 LONG driver_WriteLUTPixelArray(APTR srcrect,
1379 UWORD srcx, UWORD srcy,
1380 UWORD srcmod, struct RastPort *rp, APTR ctable,
1381 UWORD destx, UWORD desty,
1382 UWORD sizex, UWORD sizey,
1383 UBYTE ctabformat,
1384 struct GfxBase *GfxBase)
1386 ULONG depth;
1388 HIDDT_PixelLUT pixlut;
1389 HIDDT_Pixel pixtab[256];
1391 HIDDT_Color col;
1392 ULONG i;
1394 LONG pixwritten = 0;
1395 UBYTE *buf;
1397 /* This is cybergraphx. We only work wih HIDD bitmaps */
1398 if (!IS_HIDD_BM(rp->BitMap)) {
1399 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WriteLUTPixelArray()!!!\n"));
1400 return 0;
1403 pixlut.entries = 256;
1404 pixlut.pixels = pixtab;
1406 depth = GetBitMapAttr(rp->BitMap, BMA_DEPTH);
1408 /* This call does only support bitmaps with depth > 8. Use WritePixelArray8
1409 for other bitmaps
1412 if (depth <= 8) {
1413 D(bug("!!! TRYING TO USE WriteLUTPixelArray() ON BITMAP WITH DEPTH < 8\n"));
1414 return 0;
1417 /* Curently only one format is supported */
1418 if (CTABFMT_XRGB8 != ctabformat) {
1419 D(bug("!!! WriteLUTPixelArray() CALLED WITH UNSUPPORTED CTAB FORMAT %d\n"
1420 , ctabformat));
1421 return 0;
1423 col.alpha = 0;
1425 /* Convert the coltab into native pixels */
1426 for (i = 0; i < 256; i ++) {
1427 register ULONG rgb = ((ULONG *)ctable)[i];
1428 col.red = (HIDDT_ColComp)((rgb & 0x00FF0000) >> 8);
1429 col.green = (HIDDT_ColComp)(rgb & 0x0000FF00);
1430 col.blue = (HIDDT_ColComp)((rgb & 0x000000FF) << 8);
1432 pixtab[i] = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
1435 buf = (UBYTE *)srcrect;
1437 buf += CHUNKY8_COORD_TO_BYTEIDX(srcx, srcy, srcmod);
1439 pixwritten = write_pixels_8(rp
1440 , buf
1441 , srcmod
1442 , destx, desty
1443 , destx + sizex - 1, desty + sizey - 1
1444 , &pixlut
1445 , GfxBase
1449 /* Now blit the colors onto the screen */
1451 return pixwritten;
1455 LONG driver_WritePixelArray(APTR src, UWORD srcx, UWORD srcy
1456 , UWORD srcmod, struct RastPort *rp, UWORD destx, UWORD desty
1457 , UWORD width, UWORD height, UBYTE srcformat, struct GfxBase *GfxBase)
1460 OOP_Object *pf = 0;
1461 HIDDT_StdPixFmt srcfmt_hidd = 0, morphfmt_hidd = 0;
1462 ULONG start_offset;
1463 IPTR bppix;
1465 LONG pixwritten = 0;
1467 struct wpa_render_data wpard;
1468 struct Rectangle rr;
1470 if (RECTFMT_GREY8 == srcformat)
1472 static ULONG greytab[256];
1474 /* Ignore possible race conditions during
1475 initialization. Have no bad effect. Just
1476 double initializations. */
1478 /* FIXME/KILLME: evil static array which goes into BSS section
1479 which x86 native AROS regards as evil! */
1481 if (greytab[255] == 0)
1483 WORD i;
1485 for(i = 0; i < 256; i++)
1487 greytab[i] = i * 0x010101;
1491 return driver_WriteLUTPixelArray(src, srcx, srcy, srcmod,
1492 rp, greytab, destx, desty,
1493 width, height, CTABFMT_XRGB8,
1494 GfxBase);
1497 /* This is cybergraphx. We only work wih HIDD bitmaps */
1498 if (!IS_HIDD_BM(rp->BitMap))
1500 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WritePixelArray() !!!\n"));
1501 return 0;
1504 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
1505 return 0;
1507 if (RECTFMT_LUT8 == srcformat)
1510 HIDDT_PixelLUT pixlut = { 256, HIDD_BM_PIXTAB(rp->BitMap) };
1511 UBYTE * array = (UBYTE *)src;
1513 if (rp->BitMap->Flags & BMF_SPECIALFMT)
1515 RELEASE_DRIVERDATA(rp, GfxBase);
1516 D(bug("!!! No CLUT in driver_WritePixelArray\n"));
1517 return 0;
1520 array += CHUNKY8_COORD_TO_BYTEIDX(srcx, srcy, srcmod);
1522 pixwritten = write_pixels_8(rp
1523 , array, srcmod
1524 , destx, desty
1525 , destx + width - 1, desty + height - 1
1526 , &pixlut
1527 , GfxBase);
1529 RELEASE_DRIVERDATA(rp, GfxBase);
1531 return pixwritten;
1534 switch (srcformat)
1536 case RECTFMT_RGB15 : srcfmt_hidd = vHidd_StdPixFmt_RGB15 ; break;
1537 case RECTFMT_BGR15 : srcfmt_hidd = vHidd_StdPixFmt_BGR15 ; break;
1538 case RECTFMT_RGB15PC: srcfmt_hidd = vHidd_StdPixFmt_RGB15_LE; break;
1539 case RECTFMT_BGR15PC: srcfmt_hidd = vHidd_StdPixFmt_BGR15_LE; break;
1540 case RECTFMT_RGB16 : srcfmt_hidd = vHidd_StdPixFmt_RGB16 ; break;
1541 case RECTFMT_BGR16 : srcfmt_hidd = vHidd_StdPixFmt_BGR16 ; break;
1542 case RECTFMT_RGB16PC: srcfmt_hidd = vHidd_StdPixFmt_RGB16_LE; break;
1543 case RECTFMT_BGR16PC: srcfmt_hidd = vHidd_StdPixFmt_BGR16_LE; break;
1544 case RECTFMT_RGB24 : srcfmt_hidd = vHidd_StdPixFmt_RGB24 ; break;
1545 case RECTFMT_BGR24 : srcfmt_hidd = vHidd_StdPixFmt_BGR24 ; break;
1546 case RECTFMT_0RGB32 : srcfmt_hidd = vHidd_StdPixFmt_0RGB32 ; break;
1547 case RECTFMT_BGR032 : srcfmt_hidd = vHidd_StdPixFmt_BGR032 ; break;
1548 case RECTFMT_RGB032 : srcfmt_hidd = vHidd_StdPixFmt_RGB032 ; break;
1549 case RECTFMT_0BGR32 : srcfmt_hidd = vHidd_StdPixFmt_0BGR32 ; break;
1550 case RECTFMT_ARGB32 : srcfmt_hidd = vHidd_StdPixFmt_ARGB32 ; morphfmt_hidd = vHidd_StdPixFmt_0RGB32; break;
1551 case RECTFMT_BGRA32 : srcfmt_hidd = vHidd_StdPixFmt_BGRA32 ; morphfmt_hidd = vHidd_StdPixFmt_BGR032; break;
1552 case RECTFMT_RGBA32 : srcfmt_hidd = vHidd_StdPixFmt_RGBA32 ; morphfmt_hidd = vHidd_StdPixFmt_RGB032; break;
1553 case RECTFMT_ABGR32 : srcfmt_hidd = vHidd_StdPixFmt_ABGR32 ; morphfmt_hidd = vHidd_StdPixFmt_0BGR32; break;
1554 case RECTFMT_RAW : srcfmt_hidd = vHidd_StdPixFmt_Native; break;
1557 /* Compute the start of the array */
1559 #warning Get rid of the below code ?
1560 /* This can be done by passing the srcx and srcy parameters on to
1561 the HIDD bitmap and let it take care of it itself.
1562 This means that HIDD_BM_PutImage() gets a lot of parameters,
1563 which may not be necessary in real life.
1565 Compromise: convert from *CyberGfx* pixfmt to bppix using a table lookup.
1566 This is faster
1568 if ((srcfmt_hidd == vHidd_StdPixFmt_Native) || (morphfmt_hidd != 0))
1570 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&pf);
1573 if (srcfmt_hidd != vHidd_StdPixFmt_Native)
1575 /* RECTFMT_ARGB32 on vHidd_StdPixFmt_0RGB32 bitmap ==> use vHidd_StdPixFmt_0RGB32 */
1576 /* RECTFMT_BGRA32 on vHidd_StdPixFmt_BGR032 bitmap ==> use vHidd_StdPixFmt_BGR032 */
1577 /* RECTFMT_RGBA32 on vHidd_StdPixFmt_RGB032 bitmap ==> use vHidd_StdPixFmt_RGB032 */
1578 /* RECTFMT_ABGR32 on vHidd_StdPixFmt_0BGR32 bitmap ==> use vHidd_StdPixFmt_0BGR32 */
1580 if (morphfmt_hidd != 0)
1582 IPTR stdpf;
1584 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, (IPTR *)&stdpf);
1585 if (stdpf == morphfmt_hidd) srcfmt_hidd = morphfmt_hidd;
1588 pf = HIDD_Gfx_GetPixFmt(SDD(GfxBase)->gfxhidd, srcfmt_hidd);
1591 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, &bppix);
1593 start_offset = ((ULONG)srcy) * srcmod + srcx * bppix;
1595 wpard.array = ((UBYTE *)src) + start_offset;
1596 wpard.pixfmt = srcfmt_hidd;
1597 wpard.modulo = srcmod;
1598 wpard.bppix = bppix;
1600 rr.MinX = destx;
1601 rr.MinY = desty;
1602 rr.MaxX = destx + width - 1;
1603 rr.MaxY = desty + height - 1;
1605 pixwritten = do_render_func(rp, NULL, &rr, wpa_render, &wpard, FALSE, GfxBase);
1607 RELEASE_DRIVERDATA(rp, GfxBase);
1609 return pixwritten;
1612 LONG driver_WritePixelArrayAlpha(APTR src, UWORD srcx, UWORD srcy
1613 , UWORD srcmod, struct RastPort *rp, UWORD destx, UWORD desty
1614 , UWORD width, UWORD height, ULONG globalalpha, struct GfxBase *GfxBase)
1616 ULONG start_offset;
1617 LONG pixwritten = 0;
1618 struct wpaa_render_data wpaard;
1619 struct Rectangle rr;
1621 /* This is cybergraphx. We only work wih HIDD bitmaps */
1622 if (!IS_HIDD_BM(rp->BitMap))
1624 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WritePixelArrayAlpha() !!!\n"));
1625 return 0;
1628 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
1629 return 0;
1631 /* Compute the start of the array */
1633 start_offset = ((ULONG)srcy) * srcmod + srcx * 4;
1635 wpaard.array = ((UBYTE *)src) + start_offset;
1636 wpaard.modulo = srcmod;
1638 rr.MinX = destx;
1639 rr.MinY = desty;
1640 rr.MaxX = destx + width - 1;
1641 rr.MaxY = desty + height - 1;
1643 pixwritten = do_render_func(rp, NULL, &rr, wpaa_render, &wpaard, FALSE, GfxBase);
1645 RELEASE_DRIVERDATA(rp, GfxBase);
1647 return pixwritten;
1650 LONG driver_ReadPixelArray(APTR dst, UWORD destx, UWORD desty
1651 , UWORD dstmod, struct RastPort *rp, UWORD srcx, UWORD srcy
1652 , UWORD width, UWORD height, UBYTE dstformat, struct GfxBase *GfxBase)
1655 OOP_Object *pf = 0;
1656 HIDDT_StdPixFmt dstfmt_hidd = 0, morphfmt_hidd = 0;
1658 ULONG start_offset;
1659 IPTR bppix;
1661 LONG pixread = 0;
1662 IPTR old_drmd;
1663 OOP_Object *gc;
1665 struct Rectangle rr;
1666 struct rpa_render_data rpard;
1668 struct TagItem gc_tags[] =
1670 { aHidd_GC_DrawMode , vHidd_GC_DrawMode_Copy},
1671 { TAG_DONE }
1674 /* This is cybergraphx. We only work wih HIDD bitmaps */
1675 if (!IS_HIDD_BM(rp->BitMap))
1677 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in ReadPixelArray() !!!\n"));
1678 return 0;
1681 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
1682 return 0;
1684 gc = GetDriverData(rp)->dd_GC;
1686 /* Preserve old drawmode */
1687 OOP_GetAttr(gc, aHidd_GC_DrawMode, &old_drmd);
1688 OOP_SetAttrs(gc, gc_tags);
1691 switch (dstformat)
1693 case RECTFMT_RGB15 : dstfmt_hidd = vHidd_StdPixFmt_RGB15 ; break;
1694 case RECTFMT_BGR15 : dstfmt_hidd = vHidd_StdPixFmt_BGR15 ; break;
1695 case RECTFMT_RGB15PC: dstfmt_hidd = vHidd_StdPixFmt_RGB15_LE; break;
1696 case RECTFMT_BGR15PC: dstfmt_hidd = vHidd_StdPixFmt_BGR15_LE; break;
1697 case RECTFMT_RGB16 : dstfmt_hidd = vHidd_StdPixFmt_RGB16 ; break;
1698 case RECTFMT_BGR16 : dstfmt_hidd = vHidd_StdPixFmt_BGR16 ; break;
1699 case RECTFMT_RGB16PC: dstfmt_hidd = vHidd_StdPixFmt_RGB16_LE; break;
1700 case RECTFMT_BGR16PC: dstfmt_hidd = vHidd_StdPixFmt_BGR16_LE; break;
1701 case RECTFMT_RGB24 : dstfmt_hidd = vHidd_StdPixFmt_RGB24 ; break;
1702 case RECTFMT_BGR24 : dstfmt_hidd = vHidd_StdPixFmt_BGR24 ; break;
1703 case RECTFMT_0RGB32 : dstfmt_hidd = vHidd_StdPixFmt_0RGB32 ; break;
1704 case RECTFMT_BGR032 : dstfmt_hidd = vHidd_StdPixFmt_BGR032 ; break;
1705 case RECTFMT_RGB032 : dstfmt_hidd = vHidd_StdPixFmt_RGB032 ; break;
1706 case RECTFMT_0BGR32 : dstfmt_hidd = vHidd_StdPixFmt_0BGR32 ; break;
1707 case RECTFMT_ARGB32 : dstfmt_hidd = vHidd_StdPixFmt_ARGB32 ; morphfmt_hidd = vHidd_StdPixFmt_0RGB32; break;
1708 case RECTFMT_BGRA32 : dstfmt_hidd = vHidd_StdPixFmt_BGRA32 ; morphfmt_hidd = vHidd_StdPixFmt_BGR032; break;
1709 case RECTFMT_RGBA32 : dstfmt_hidd = vHidd_StdPixFmt_RGBA32 ; morphfmt_hidd = vHidd_StdPixFmt_RGB032; break;
1710 case RECTFMT_ABGR32 : dstfmt_hidd = vHidd_StdPixFmt_ABGR32 ; morphfmt_hidd = vHidd_StdPixFmt_0BGR32; break;
1711 case RECTFMT_RAW : dstfmt_hidd = vHidd_StdPixFmt_Native; break;
1714 #warning Get rid of the below code ?
1715 /* This can be done by passing the srcx and srcy parameters on to
1716 the HIDD bitmap and let it take care of it itself.
1717 This means that HIDD_BM_PutImage() gets a lot of parameters,
1718 which may not be necessary in real life.
1720 Compromise: convert from *CyberGfx* pixfmt to bppix using a table lookup.
1721 This is faster
1723 if ((dstfmt_hidd == vHidd_StdPixFmt_Native) || (morphfmt_hidd != 0))
1725 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&pf);
1728 if (dstfmt_hidd != vHidd_StdPixFmt_Native)
1730 /* RECTFMT_ARGB32 on vHidd_StdPixFmt_0RGB32 bitmap ==> use vHidd_StdPixFmt_0RGB32 */
1731 /* RECTFMT_BGRA32 on vHidd_StdPixFmt_BGR032 bitmap ==> use vHidd_StdPixFmt_BGR032 */
1732 /* RECTFMT_RGBA32 on vHidd_StdPixFmt_RGB032 bitmap ==> use vHidd_StdPixFmt_RGB032 */
1733 /* RECTFMT_ABGR32 on vHidd_StdPixFmt_0BGR32 bitmap ==> use vHidd_StdPixFmt_0BGR32 */
1735 if (morphfmt_hidd != 0)
1737 IPTR stdpf;
1739 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, (IPTR *)&stdpf);
1740 if (stdpf == morphfmt_hidd) dstfmt_hidd = morphfmt_hidd;
1743 pf = HIDD_Gfx_GetPixFmt(SDD(GfxBase)->gfxhidd, dstfmt_hidd);
1746 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, &bppix);
1748 start_offset = ((ULONG)desty) * dstmod + destx * bppix;
1750 rpard.array = ((UBYTE *)dst) + start_offset;
1751 rpard.pixfmt = dstfmt_hidd;
1752 rpard.modulo = dstmod;
1753 rpard.bppix = bppix;
1755 rr.MinX = srcx;
1756 rr.MinY = srcy;
1757 rr.MaxX = srcx + width - 1;
1758 rr.MaxY = srcy + height - 1;
1760 pixread = do_render_func(rp, NULL, &rr, rpa_render, &rpard, FALSE, GfxBase);
1762 /* restore old gc values */
1763 gc_tags[0].ti_Data = (IPTR)old_drmd;
1764 OOP_SetAttrs(gc, gc_tags);
1766 RELEASE_DRIVERDATA(rp, GfxBase);
1768 return pixread;
1771 LONG driver_InvertPixelArray(struct RastPort *rp
1772 , UWORD destx, UWORD desty, UWORD width, UWORD height
1773 , struct GfxBase *GfxBase)
1776 /* This is cybergraphx. We only work wih HIDD bitmaps */
1777 if (!IS_HIDD_BM(rp->BitMap))
1779 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap InvertPixelArray() !!!\n"));
1780 return 0;
1783 return (LONG)fillrect_pendrmd(rp
1784 , destx, desty
1785 , destx + width - 1
1786 , desty + height - 1
1787 , 0xFF
1788 , vHidd_GC_DrawMode_Invert
1789 , GfxBase);
1792 LONG driver_FillPixelArray(struct RastPort *rp
1793 , UWORD destx, UWORD desty, UWORD width, UWORD height
1794 , ULONG pixel, struct GfxBase *GfxBase)
1796 HIDDT_Color col;
1797 HIDDT_Pixel pix;
1799 /* HIDDT_ColComp are 16 Bit */
1800 col.alpha = (HIDDT_ColComp)((pixel >> 16) & 0x0000FF00);
1801 col.red = (HIDDT_ColComp)((pixel >> 8) & 0x0000FF00);
1802 col.green = (HIDDT_ColComp)(pixel & 0x0000FF00);
1803 col.blue = (HIDDT_ColComp)((pixel << 8) & 0x0000FF00);
1805 pix = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
1807 return (LONG)fillrect_pendrmd(rp
1808 , destx, desty
1809 , destx + width - 1
1810 , desty + height - 1
1811 , pix
1812 , vHidd_GC_DrawMode_Copy
1813 , GfxBase
1817 ULONG driver_MovePixelArray(UWORD srcx, UWORD srcy, struct RastPort *rp
1818 , UWORD destx, UWORD desty, UWORD width, UWORD height
1819 , struct GfxBase *GfxBase)
1821 ClipBlit(rp
1822 , srcx, srcy
1823 , rp
1824 , destx, desty
1825 , width, height
1826 , 0x00C0 /* Copy */
1828 return width * height;
1833 LONG driver_WriteRGBPixel(struct RastPort *rp, UWORD x, UWORD y
1834 , ULONG pixel, struct GfxBase *GfxBase)
1837 struct rgbpix_render_data prd;
1838 HIDDT_Color col;
1839 LONG retval;
1841 /* This is cybergraphx. We only work wih HIDD bitmaps */
1842 if (!IS_HIDD_BM(rp->BitMap))
1844 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in WriteRGBPixel() !!!\n"));
1845 return 0;
1848 if (!OBTAIN_DRIVERDATA(rp, GfxBase)) return -1;
1850 /* HIDDT_ColComp are 16 Bit */
1852 col.alpha = (HIDDT_ColComp)((pixel >> 16) & 0x0000FF00);
1853 col.red = (HIDDT_ColComp)((pixel >> 8) & 0x0000FF00);
1854 col.green = (HIDDT_ColComp)(pixel & 0x0000FF00);
1855 col.blue = (HIDDT_ColComp)((pixel << 8) & 0x0000FF00);
1857 prd.pixel = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
1859 retval = do_pixel_func(rp, x, y, rgbpix_write, &prd, GfxBase);
1861 RELEASE_DRIVERDATA(rp, GfxBase);
1863 return retval;
1868 ULONG driver_ReadRGBPixel(struct RastPort *rp, UWORD x, UWORD y
1869 , struct GfxBase *GfxBase)
1871 struct rgbpix_render_data prd;
1873 /* Get the HIDD pixel val */
1874 HIDDT_Color col;
1875 HIDDT_Pixel pix;
1876 LONG ret;
1878 /* This is cybergraphx. We only work wih HIDD bitmaps */
1879 if (!IS_HIDD_BM(rp->BitMap))
1881 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in ReadRGBPixel()!!!\n"));
1882 return (ULONG)-1;
1885 if (!OBTAIN_DRIVERDATA(rp, GfxBase)) return (ULONG)-1;
1887 ret = do_pixel_func(rp, x, y, pix_read, &prd, GfxBase);
1889 RELEASE_DRIVERDATA(rp, GfxBase);
1891 if (-1 == ret)
1892 return (ULONG)-1;
1894 HIDD_BM_UnmapPixel(HIDD_BM_OBJ(rp->BitMap), prd.pixel, &col);
1896 /* HIDDT_ColComp are 16 Bit */
1898 pix = ((col.alpha & 0xFF00) << 16)
1899 | ((col.red & 0xFF00) << 8)
1900 | (col.green & 0xFF00)
1901 | ((col.blue & 0xFF00) >> 8);
1903 return pix;
1908 ULONG driver_GetCyberMapAttr(struct BitMap *bitMap, ULONG attribute, struct GfxBase *GfxBase)
1910 OOP_Object *bm_obj;
1911 OOP_Object *pf;
1913 IPTR retval;
1915 /* This is cybergraphx. We only work wih HIDD bitmaps */
1916 if (!IS_HIDD_BM(bitMap)) {
1917 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in GetCyberMapAttr() !!!\n"));
1918 return 0;
1921 bm_obj = HIDD_BM_OBJ(bitMap);
1923 OOP_GetAttr(bm_obj, aHidd_BitMap_PixFmt, (IPTR *)&pf);
1925 switch (attribute) {
1926 case CYBRMATTR_XMOD:
1927 OOP_GetAttr(bm_obj, aHidd_BitMap_BytesPerRow, &retval);
1928 break;
1930 case CYBRMATTR_BPPIX:
1931 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, &retval);
1932 break;
1934 case CYBRMATTR_PIXFMT:
1935 case CYBRMATTR_PIXFMT_ALPHA: {
1936 IPTR stdpf;
1937 UWORD cpf;
1938 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, (IPTR *)&stdpf);
1940 /* Convert to cybergfx */
1941 cpf = hidd2cyber_pixfmt(stdpf, GfxBase);
1943 /* CYBRMATTR_PIXFMT doesn't know about non-alpha 32-bit modes */
1944 if (attribute == CYBRMATTR_PIXFMT) {
1945 switch (cpf) {
1946 case PIXFMT_0RGB32: cpf = PIXFMT_ARGB32; break;
1947 case PIXFMT_BGR032: cpf = PIXFMT_BGRA32; break;
1948 case PIXFMT_RGB032: cpf = PIXFMT_RGBA32; break;
1949 case PIXFMT_0BGR32: cpf = PIXFMT_ABGR32; break;
1953 if (cpf == (UWORD)-1) {
1954 D(bug("!!! UNKNOWN PIXEL FORMAT IN GetCyberMapAttr()\n"));
1957 retval = (IPTR)cpf;
1958 break;
1962 case CYBRMATTR_WIDTH:
1963 #if 0 /* stegerg: doesn't really work, because of framebuffer bitmap object stuff */
1964 OOP_GetAttr(bm_obj, aHidd_BitMap_Width, &retval);
1965 #else
1966 retval = GetBitMapAttr(bitMap, BMA_WIDTH);
1967 #endif
1968 break;
1970 case CYBRMATTR_HEIGHT:
1971 #if 0 /* stegerg: doesn't really work, because of framebuffer bitmap object stuff */
1972 OOP_GetAttr(bm_obj, aHidd_BitMap_Height, &retval);
1973 #else
1974 retval = GetBitMapAttr(bitMap, BMA_HEIGHT);
1975 #endif
1976 break;
1978 case CYBRMATTR_DEPTH:
1979 #if 0 /* stegerg: might not really work, because of framebuffer bitmap object stuff */
1980 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &retval);
1981 #else
1982 retval = GetBitMapAttr(bitMap, BMA_DEPTH);
1983 #endif
1984 break;
1986 case CYBRMATTR_ISCYBERGFX: {
1987 IPTR depth;
1989 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &depth);
1991 if (depth < 8) {
1992 retval = 0;
1993 } else {
1994 /* We allways have a HIDD bitmap */
1995 retval = 0xFFFFFFFF; /* Some apps seem to rely on this retval */
1997 break; }
1999 case CYBRMATTR_ISLINEARMEM:
2000 OOP_GetAttr(bm_obj, aHidd_BitMap_IsLinearMem, &retval);
2001 break;
2003 default:
2004 D(bug("!!! UNKNOWN ATTRIBUTE PASSED TO GetCyberMapAttr()\n"));
2005 break;
2008 } /* switch (attribute) */
2010 return retval;
2014 VOID driver_CVideoCtrlTagList(struct ViewPort *vp, struct TagItem *tags, struct GfxBase *GfxBase)
2016 struct TagItem *tag, *tstate;
2017 ULONG dpmslevel = 0;
2019 struct TagItem htags[] =
2021 { aHidd_Gfx_DPMSLevel, 0UL },
2022 { TAG_DONE, 0UL }
2025 BOOL dpms_found = FALSE;
2027 HIDDT_DPMSLevel hdpms = 0;
2029 for (tstate = tags; (tag = NextTagItem((const struct TagItem **)&tstate)); )
2031 switch (tag->ti_Tag)
2033 case SETVC_DPMSLevel:
2034 dpmslevel = tag->ti_Data;
2035 dpms_found = TRUE;
2036 break;
2038 default:
2039 D(bug("!!! UNKNOWN TAG IN CVideoCtrlTagList(): %x !!!\n"
2040 , tag->ti_Tag));
2041 break;
2043 } /* switch() */
2045 } /* for (each tagitem) */
2048 if (dpms_found)
2051 /* Convert to hidd dpms level */
2052 switch (dpmslevel)
2054 case DPMS_ON:
2055 hdpms = vHidd_Gfx_DPMSLevel_On;
2056 break;
2058 case DPMS_STANDBY:
2059 hdpms = vHidd_Gfx_DPMSLevel_Standby;
2060 break;
2062 case DPMS_SUSPEND:
2063 hdpms = vHidd_Gfx_DPMSLevel_Suspend;
2064 break;
2066 case DPMS_OFF:
2067 hdpms = vHidd_Gfx_DPMSLevel_Off;
2068 break;
2070 default:
2071 D(bug("!!! UNKNOWN DPMS LEVEL IN CVideoCtrlTagList(): %x !!!\n"
2072 , dpmslevel));
2074 dpms_found = FALSE;
2075 break;
2080 if (dpms_found)
2082 htags[0].ti_Data = hdpms;
2084 else
2086 htags[0].ti_Tag = TAG_IGNORE;
2089 OOP_SetAttrs(SDD(GfxBase)->gfxhidd, htags);
2091 return;
2095 ULONG driver_ExtractColor(struct RastPort *rp, struct BitMap *bm
2096 , ULONG color, ULONG srcx, ULONG srcy, ULONG width, ULONG height
2097 , struct GfxBase *GfxBase)
2099 struct Rectangle rr;
2100 LONG pixread = 0;
2101 struct extcol_render_data ecrd;
2102 OOP_Object *pf;
2103 IPTR colmod;
2105 if (!IS_HIDD_BM(rp->BitMap))
2107 D(bug("!!! CALLING ExtractColor() ON NO-HIDD BITMAP !!!\n"));
2108 return FALSE;
2111 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
2112 return FALSE;
2114 rr.MinX = srcx;
2115 rr.MinY = srcy;
2116 rr.MaxX = srcx + width - 1;
2117 rr.MaxY = srcy + height - 1;
2119 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&pf);
2121 OOP_GetAttr(pf, aHidd_PixFmt_ColorModel, (IPTR *)&colmod);
2123 if (vHidd_ColorModel_Palette == colmod)
2125 ecrd.pixel = color;
2127 else
2129 HIDDT_Color col;
2131 col.alpha = (color >> 16) & 0x0000FF00;
2132 col.red = (color >> 8 ) & 0x0000FF00;
2133 col.green = color & 0x0000FF00;
2134 col.blue = (color << 8) & 0x0000FF00;
2136 ecrd.pixel = HIDD_BM_MapColor(HIDD_BM_OBJ(rp->BitMap), &col);
2140 ecrd.destbm = bm;
2142 pixread = do_render_func(rp, NULL, &rr, extcol_render, &ecrd, TRUE, GfxBase);
2144 RELEASE_DRIVERDATA(rp, GfxBase);
2146 if (pixread != (width * height))
2147 return FALSE;
2149 return TRUE;
2153 VOID driver_DoCDrawMethodTagList(struct Hook *hook, struct RastPort *rp, struct TagItem *tags, struct GfxBase *GfxBase)
2156 struct dm_render_data dmrd;
2157 struct Rectangle rr;
2158 struct Layer *L;
2160 if (!IS_HIDD_BM(rp->BitMap))
2162 D(bug("!!! NO HIDD BITMAP IN CALL TO DoCDrawMethodTagList() !!!\n"));
2163 return;
2166 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
2167 return;
2169 /* Get the bitmap std pixfmt */
2170 OOP_GetAttr(HIDD_BM_OBJ(rp->BitMap), aHidd_BitMap_PixFmt, (IPTR *)&dmrd.pf);
2171 OOP_GetAttr(dmrd.pf, aHidd_PixFmt_StdPixFmt, &dmrd.stdpf);
2172 dmrd.msg.colormodel = hidd2cyber_pixfmt(dmrd.stdpf, GfxBase);
2173 dmrd.hook = hook;
2174 dmrd.rp = rp;
2176 if (((UWORD)-1) == dmrd.msg.colormodel)
2178 RELEASE_DRIVERDATA(rp, GfxBase);
2179 D(bug("!!! UNKNOWN HIDD PIXFMT IN DoCDrawMethodTagList() !!!\n"));
2180 return;
2184 L = rp->Layer;
2186 rr.MinX = 0;
2187 rr.MinY = 0;
2189 if (NULL == L)
2191 rr.MaxX = GetBitMapAttr(rp->BitMap, BMA_WIDTH) - 1;
2192 rr.MaxY = GetBitMapAttr(rp->BitMap, BMA_HEIGHT) - 1;
2194 else
2196 /* Lock the layer */
2197 LockLayerRom(L);
2199 rr.MaxX = rr.MinX + (L->bounds.MaxX - L->bounds.MinX) - 1;
2200 rr.MaxY = rr.MinY + (L->bounds.MaxY - L->bounds.MinY) - 1;
2203 dmrd.gc = GetDriverData(rp)->dd_GC;
2204 do_render_func(rp, NULL, &rr, dm_render, &dmrd, FALSE, GfxBase);
2206 RELEASE_DRIVERDATA(rp, GfxBase);
2208 if (NULL != L)
2210 UnlockLayerRom(L);
2213 return;
2216 APTR driver_LockBitMapTagList(struct BitMap *bm, struct TagItem *tags, struct GfxBase *GfxBase)
2218 struct TagItem *tag;
2219 UBYTE *baseaddress;
2220 ULONG width, height, banksize, memsize;
2221 OOP_Object *pf;
2222 IPTR stdpf;
2223 UWORD cpf;
2225 if (!IS_HIDD_BM(bm))
2227 D(bug("!!! TRYING TO CALL LockBitMapTagList() ON NON-HIDD BM !!!\n"));
2228 return NULL;
2231 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_PixFmt, (IPTR *)&pf);
2233 OOP_GetAttr(pf, aHidd_PixFmt_StdPixFmt, &stdpf);
2234 cpf = hidd2cyber_pixfmt(stdpf, GfxBase);
2235 if (((UWORD)-1) == cpf)
2237 D(bug("!!! TRYING TO CALL LockBitMapTagList() ON NON-CYBER PIXFMT BITMAP !!!\n"));
2238 return NULL;
2241 /* Get some info from the bitmap object */
2242 if (!HIDD_BM_ObtainDirectAccess(HIDD_BM_OBJ(bm), &baseaddress, &width, &height, &banksize, &memsize))
2243 return NULL;
2246 while ((tag = NextTagItem((const struct TagItem **)&tags)))
2248 switch (tag->ti_Tag)
2250 case LBMI_BASEADDRESS:
2251 *((IPTR **)tag->ti_Data) = (IPTR *)baseaddress;
2252 break;
2254 case LBMI_BYTESPERROW:
2255 *((IPTR *)tag->ti_Data) =
2256 (ULONG)HIDD_BM_BytesPerLine(HIDD_BM_OBJ(bm), stdpf, width);
2257 break;
2259 case LBMI_BYTESPERPIX:
2260 OOP_GetAttr(pf, aHidd_PixFmt_BytesPerPixel, (IPTR *)tag->ti_Data);
2261 break;
2263 case LBMI_PIXFMT:
2264 *((IPTR *)tag->ti_Data) = (IPTR)cpf;
2265 break;
2267 case LBMI_DEPTH:
2268 OOP_GetAttr(pf, aHidd_PixFmt_Depth, (IPTR *)tag->ti_Data);
2269 break;
2271 case LBMI_WIDTH:
2272 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_Width, (IPTR *)tag->ti_Data);
2273 break;
2275 case LBMI_HEIGHT:
2276 OOP_GetAttr(HIDD_BM_OBJ(bm), aHidd_BitMap_Height, (IPTR *)tag->ti_Data);
2277 break;
2279 default:
2280 D(bug("!!! UNKNOWN TAG PASSED TO LockBitMapTagList() !!!\n"));
2281 break;
2285 return HIDD_BM_OBJ(bm);
2288 VOID driver_UnLockBitMap(APTR handle, struct GfxBase *GfxBase)
2290 if (handle) HIDD_BM_ReleaseDirectAccess((OOP_Object *)handle);
2293 VOID driver_UnLockBitMapTagList(APTR handle, struct TagItem *tags, struct GfxBase *GfxBase)
2295 struct TagItem *tag;
2296 BOOL reallyunlock = TRUE;
2298 while ((tag = NextTagItem((const struct TagItem **)&tags)))
2300 switch (tag->ti_Tag)
2302 case UBMI_REALLYUNLOCK:
2303 reallyunlock = (BOOL)tag->ti_Data;
2304 break;
2306 case UBMI_UPDATERECTS:
2308 struct RectList *rl;
2310 rl = (struct RectList *)tag->ti_Data;
2312 #warning Dunno what to do with this
2314 break;
2317 default:
2318 D(bug("!!! UNKNOWN TAG PASSED TO UnLockBitMapTagList() !!!\n"));
2319 break;
2323 if (reallyunlock)
2325 HIDD_BM_ReleaseDirectAccess((OOP_Object *)handle);
2329 void driver_BltTemplateAlpha(UBYTE *src, LONG srcx, LONG srcmod
2330 , struct RastPort *rp, LONG destx, LONG desty, LONG width, LONG height
2331 , struct GfxBase *GfxBase)
2333 struct bta_render_data btard;
2334 struct Rectangle rr;
2336 /* This is cybergraphx. We only work wih HIDD bitmaps */
2337 if (!IS_HIDD_BM(rp->BitMap)) {
2338 D(bug("!!!!! Trying to use CGFX call on non-hidd bitmap in BltTemplateAlpha() !!!\n"));
2339 return;
2342 if (!OBTAIN_DRIVERDATA(rp, GfxBase))
2343 return;
2345 /* Compute the start of the array */
2347 btard.array = src + srcx;
2348 btard.modulo = srcmod;
2349 btard.invertalpha = (rp->DrawMode & INVERSVID) ? TRUE : FALSE;
2350 rr.MinX = destx;
2351 rr.MinY = desty;
2352 rr.MaxX = destx + width - 1;
2353 rr.MaxY = desty + height - 1;
2355 do_render_func(rp, NULL, &rr, bta_render, &btard, FALSE, GfxBase);
2357 RELEASE_DRIVERDATA(rp, GfxBase);
2360 /******************************************/
2361 /* Support stuff for cybergfx */
2362 /******************************************/
2364 #undef GfxBase