2 Copyright © 1995-2018, The AROS Development Team. All rights reserved.
5 Desc: Bitmap class for VESA Gfx hidd.
9 #define __OOP_NOATTRBASES__
11 #include <proto/oop.h>
12 #include <proto/utility.h>
14 #include <exec/memory.h>
15 #include <exec/lists.h>
16 #include <graphics/rastport.h>
17 #include <graphics/gfx.h>
20 #include <aros/symbolsets.h>
22 #include <aros/debug.h>
26 #include "vesagfx_hidd.h"
28 #include LC_LIBDEFS_FILE
30 #define MNAME_ROOT(x) VESAGfxBM__Root__ ## x
31 #define MNAME_BM(x) VESAGfxBM__Hidd_BitMap__ ## x
33 /*********** BitMap::New() *************************************/
34 OOP_Object
*MNAME_ROOT(New
)(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
36 EnterFunc(bug("VESAGfx.BitMap::New()\n"));
38 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
41 OOP_MethodID disp_mid
;
42 struct VESAGfxBitMapData
*data
;
44 OOP_Object
*sync
, *pf
;
46 data
= OOP_INST_DATA(cl
, o
);
49 OOP_GetAttr(o
, aHidd_BitMap_GfxHidd
, (APTR
)&data
->gfxhidd
);
50 OOP_GetAttr(o
, aHidd_BitMap_PixFmt
, (APTR
)&data
->pixfmtobj
);
51 OOP_GetAttr(o
, aHidd_BitMap_ModeID
, &modeid
);
52 OOP_GetAttr(o
, aHidd_ChunkyBM_Buffer
, (IPTR
*)&data
->VideoData
);
54 HIDD_Gfx_GetMode(data
->gfxhidd
, modeid
, &sync
, &pf
);
56 data
->width
= OOP_GET(o
, aHidd_BitMap_Width
);
57 data
->height
= OOP_GET(o
, aHidd_BitMap_Height
);
58 data
->bytesperline
= OOP_GET(o
, aHidd_BitMap_BytesPerRow
);
59 data
->bytesperpix
= OOP_GET(data
->pixfmtobj
, aHidd_PixFmt_BytesPerPixel
);
60 data
->bpp
= OOP_GET(data
->pixfmtobj
, aHidd_PixFmt_BitsPerPixel
);
61 data
->disp_width
= OOP_GET(sync
, aHidd_Sync_HDisp
);
62 data
->disp_height
= OOP_GET(sync
, aHidd_Sync_VDisp
);
64 D(bug("[VESAGfx:BitMap] Bitmap %ld x %ld, %u bytes per pixel, %u bytes per line\n",
65 data
->width
, data
->height
, data
->bytesperpix
, data
->bytesperline
));
66 D(bug("[VESAGfx:BitMap] Video data at 0x%p (%u bytes)\n", data
->VideoData
, data
->bytesperline
* data
->height
));
68 if (OOP_GET(data
->pixfmtobj
, aHidd_PixFmt_ColorModel
) != vHidd_ColorModel_Palette
)
69 ReturnPtr("VESAGfx.BitMap::New()", OOP_Object
*, o
);
71 data
->DAC
= AllocMem(768, MEMF_ANY
);
72 D(bug("[VESAGfx:BitMap] Palette data at 0x%p\n", data
->DAC
));
74 ReturnPtr("VESAGfx.BitMap::New()", OOP_Object
*, o
);
76 disp_mid
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
78 OOP_CoerceMethod(cl
, o
, (OOP_Msg
) &disp_mid
);
80 } /* if created object */
82 ReturnPtr("VESAGfx.BitMap::New()", OOP_Object
*, o
);
85 /********** Bitmap::Dispose() ***********************************/
86 VOID
MNAME_ROOT(Dispose
)(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
88 struct VESAGfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
90 D(bug("[VESAGfx:BitMap] Dispose(0x%p)\n", o
));
93 FreeMem(data
->DAC
, 768);
95 OOP_DoSuperMethod(cl
, o
, msg
);
97 ReturnVoid("VESAGfx.BitMap::Dispose");
100 /*** BitMap::Get() *******************************************/
102 VOID
MNAME_ROOT(Get
)(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
104 struct VESAGfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
107 if (IS_BM_ATTR(msg
->attrID
, idx
))
111 case aoHidd_BitMap_Visible
:
112 *msg
->storage
= data
->disp
;
116 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
119 /*** BitMap::Set() *******************************************/
121 VOID
MNAME_ROOT(Set
)(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Set
*msg
)
123 struct VESAGfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
124 struct TagItem
*tag
, *tstate
;
126 IPTR xoffset
= data
->xoffset
;
127 IPTR yoffset
= data
->yoffset
;
129 tstate
= msg
->attrList
;
130 while((tag
= NextTagItem(&tstate
)))
132 if(IS_BM_ATTR(tag
->ti_Tag
, idx
))
136 case aoHidd_BitMap_Visible
:
137 D(bug("[VESAGfx:BitMap] Setting Visible to %d\n", tag
->ti_Data
));
138 data
->disp
= tag
->ti_Data
;
141 DACLoad(XSD(cl
), data
->DAC
, 0, 256);
148 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
);
150 /* Bring local X/Y offsets back into sync with validated values */
151 OOP_GetAttr(o
, aHidd_BitMap_LeftEdge
, &xoffset
);
152 OOP_GetAttr(o
, aHidd_BitMap_TopEdge
, &yoffset
);
154 if ((xoffset
!= data
->xoffset
) || (yoffset
!= data
->yoffset
))
156 D(bug("[VESAGfx:BitMap] Scroll to (%d, %d)\n", xoffset
, yoffset
));
157 data
->xoffset
= xoffset
;
158 data
->yoffset
= yoffset
;
162 LOCK_FRAMEBUFFER(XSD(cl
));
163 vesaDoRefreshArea(&XSD(cl
)->data
, data
, 0, 0, data
->width
, data
->height
);
164 UNLOCK_FRAMEBUFFER(XSD(cl
));
169 /*** BitMap::SetColors() *************************************/
171 BOOL
MNAME_BM(SetColors
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_SetColors
*msg
)
173 struct VESAGfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
174 struct HWData
*hwdata
= &XSD(cl
)->data
;
177 UWORD red
, green
, blue
;
179 D(bug("[VESAGfx:BitMap] SetColors(%u, %u)\n", msg
->firstColor
, msg
->numColors
));
181 if (!OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)msg
)) {
182 D(bug("[VESAGfx:BitMap] DoSuperMethod() failed\n"));
186 if ((msg
->firstColor
+ msg
->numColors
) > (1 << data
->bpp
))
190 for ( xc_i
= msg
->firstColor
, col_i
= 0;
191 col_i
< msg
->numColors
;
193 red
= msg
->colors
[col_i
].red
>> 8;
194 green
= msg
->colors
[col_i
].green
>> 8;
195 blue
= msg
->colors
[col_i
].blue
>> 8;
197 /* Update DAC register values */
198 p_shift
= 8 - hwdata
->palettewidth
;
199 data
->DAC
[xc_i
*3] = red
>> p_shift
;
200 data
->DAC
[xc_i
*3+1] = green
>> p_shift
;
201 data
->DAC
[xc_i
*3+2] = blue
>> p_shift
;
204 /* Upload palette to the DAC if the current bitmap is on display */
206 DACLoad(XSD(cl
), data
->DAC
, msg
->firstColor
, msg
->numColors
);
211 VOID
MNAME_BM(UpdateRect
)(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_BitMap_UpdateRect
*msg
)
213 struct VESAGfxBitMapData
*data
= OOP_INST_DATA(cl
, o
);
215 D(bug("[VESAGfx:BitMap] UpdateRect(%d, %d, %d, %d), bitmap 0x%p\n", msg
->x
, msg
->y
, msg
->width
, msg
->height
, o
));
217 LOCK_FRAMEBUFFER(XSD(cl
));
218 vesaDoRefreshArea(&XSD(cl
)->data
, data
, msg
->x
, msg
->y
, msg
->x
+ msg
->width
, msg
->y
+ msg
->height
);
219 UNLOCK_FRAMEBUFFER(XSD(cl
));