W.I.P AROS port of SDI examples
[AROS.git] / rom / hidds / vesa / vesagfxclass.c
blobbb7d0fad7917ff0ab388535b3831632ffdac2054
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Class for Vesa.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <aros/asmcall.h>
12 #include <proto/exec.h>
13 #include <proto/oop.h>
14 #include <proto/utility.h>
15 #include <aros/symbolsets.h>
16 #include <devices/inputevent.h>
17 #include <exec/alerts.h>
18 #include <exec/memory.h>
19 #include <hardware/custom.h>
20 #include <hidd/hidd.h>
21 #include <hidd/graphics.h>
22 #include <oop/oop.h>
23 #include <clib/alib_protos.h>
24 #include <string.h>
26 #define DEBUG 0
27 #include <aros/debug.h>
29 #include "vesagfxclass.h"
30 #include "bitmap.h"
31 #include "hardware.h"
33 #include LC_LIBDEFS_FILE
35 AROS_INTH1(ResetHandler, struct HWData *, hwdata)
37 AROS_INTFUNC_INIT
39 ClearBuffer(hwdata);
41 return FALSE;
43 AROS_INTFUNC_EXIT
46 OOP_Object *PCVesa__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
48 struct TagItem pftags[] =
50 {aHidd_PixFmt_RedShift, 0}, /* 0 */
51 {aHidd_PixFmt_GreenShift, 0}, /* 1 */
52 {aHidd_PixFmt_BlueShift, 0}, /* 2 */
53 {aHidd_PixFmt_AlphaShift, 0}, /* 3 */
54 {aHidd_PixFmt_RedMask, 0}, /* 4 */
55 {aHidd_PixFmt_GreenMask, 0}, /* 5 */
56 {aHidd_PixFmt_BlueMask, 0}, /* 6 */
57 {aHidd_PixFmt_AlphaMask, 0}, /* 7 */
58 {aHidd_PixFmt_ColorModel, 0}, /* 8 */
59 {aHidd_PixFmt_Depth, 0}, /* 9 */
60 {aHidd_PixFmt_BytesPerPixel,0}, /* 10 */
61 {aHidd_PixFmt_BitsPerPixel, 0}, /* 11 */
62 {aHidd_PixFmt_StdPixFmt, vHidd_StdPixFmt_Native}, /* 12 */
63 {aHidd_PixFmt_CLUTShift, 0}, /* 13 */
64 {aHidd_PixFmt_CLUTMask, 0}, /* 14 */
65 {aHidd_PixFmt_BitMapType, vHidd_BitMapType_Chunky}, /* 15 */
66 {TAG_DONE, 0UL }
68 struct TagItem sync_mode[] =
70 {aHidd_Sync_HDisp, 0},
71 {aHidd_Sync_VDisp, 0},
72 {aHidd_Sync_HMax, 16384},
73 {aHidd_Sync_VMax, 16384},
74 {aHidd_Sync_Description, (IPTR)"VESA:%hx%v"},
75 {TAG_DONE, 0UL}
77 struct TagItem modetags[] =
79 {aHidd_Gfx_PixFmtTags, (IPTR)pftags},
80 {aHidd_Gfx_SyncTags, (IPTR)sync_mode},
81 {TAG_DONE, 0UL}
83 struct TagItem yourtags[] =
85 {aHidd_Gfx_ModeTags, (IPTR)modetags},
86 {TAG_MORE, 0UL}
88 struct pRoot_New yourmsg;
90 /* Protect against some stupid programmer wishing to
91 create one more VESA driver */
92 if (XSD(cl)->vesagfxhidd)
93 return NULL;
95 pftags[0].ti_Data = XSD(cl)->data.redshift;
96 pftags[1].ti_Data = XSD(cl)->data.greenshift;
97 pftags[2].ti_Data = XSD(cl)->data.blueshift;
98 pftags[4].ti_Data = XSD(cl)->data.redmask;
99 pftags[5].ti_Data = XSD(cl)->data.greenmask;
100 pftags[6].ti_Data = XSD(cl)->data.bluemask;
101 pftags[8].ti_Data = (XSD(cl)->data.depth > 8) ? vHidd_ColorModel_TrueColor : vHidd_ColorModel_Palette;
102 pftags[9].ti_Data = (XSD(cl)->data.depth > 24) ? 24 : XSD(cl)->data.depth;
103 pftags[10].ti_Data = XSD(cl)->data.bytesperpixel;
104 pftags[11].ti_Data = (XSD(cl)->data.bitsperpixel > 24) ? 24 : XSD(cl)->data.bitsperpixel;
105 pftags[14].ti_Data = (1 << XSD(cl)->data.depth) - 1;
107 sync_mode[0].ti_Data = XSD(cl)->data.width;
108 sync_mode[1].ti_Data = XSD(cl)->data.height;
110 yourtags[1].ti_Data = (IPTR)msg->attrList;
111 yourmsg.mID = msg->mID;
112 yourmsg.attrList = yourtags;
113 msg = &yourmsg;
114 EnterFunc(bug("VesaGfx::New()\n"));
115 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
116 if (o)
118 struct VesaGfx_data *data = OOP_INST_DATA(cl, o);
120 D(bug("Got object from super\n"));
121 XSD(cl)->vesagfxhidd = o;
123 data->ResetInterrupt.is_Code = (VOID_FUNC)ResetHandler;
124 data->ResetInterrupt.is_Data = &XSD(cl)->data;
125 AddResetCallback(&data->ResetInterrupt);
127 ReturnPtr("VesaGfx::New", OOP_Object *, o);
130 VOID PCVesa__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
132 struct VesaGfx_data *data = OOP_INST_DATA(cl, o);
134 RemResetCallback(&data->ResetInterrupt);
135 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
136 XSD(cl)->vesagfxhidd = NULL;
139 VOID PCVesa__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
141 ULONG idx;
143 if (IS_GFX_ATTR(msg->attrID, idx))
145 switch (idx)
147 case aoHidd_Gfx_NoFrameBuffer:
148 *msg->storage = TRUE;
149 return;
152 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
155 OOP_Object *PCVesa__Hidd_Gfx__NewBitMap(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_NewBitMap *msg)
157 BOOL displayable;
158 struct TagItem tags[2] =
160 {TAG_IGNORE, 0 },
161 {TAG_MORE , (IPTR)msg->attrList}
163 struct pHidd_Gfx_NewBitMap yourmsg;
165 EnterFunc(bug("VesaGfx::NewBitMap()\n"));
167 displayable = GetTagData(aHidd_BitMap_Displayable, FALSE, msg->attrList);
168 if (displayable)
170 /* Only displayable bitmaps are bitmaps of our class */
171 tags[0].ti_Tag = aHidd_BitMap_ClassPtr;
172 tags[0].ti_Data = (IPTR)XSD(cl)->bmclass;
174 else
176 /* Non-displayable friends of our bitmaps are plain chunky bitmaps */
177 OOP_Object *friend = (OOP_Object *)GetTagData(aHidd_BitMap_Friend, 0, msg->attrList);
179 if (friend && (OOP_OCLASS(friend) == XSD(cl)->bmclass))
181 tags[0].ti_Tag = aHidd_BitMap_ClassID;
182 tags[0].ti_Data = (IPTR)CLID_Hidd_ChunkyBM;
186 yourmsg.mID = msg->mID;
187 yourmsg.attrList = tags;
189 ReturnPtr("VesaGfx::NewBitMap", OOP_Object *, (OOP_Object *)OOP_DoSuperMethod(cl, o, &yourmsg.mID));
192 /********* GfxHidd::Show() ***************************/
194 OOP_Object *PCVesa__Hidd_Gfx__Show(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_Show *msg)
196 struct VesaGfx_staticdata *data = XSD(cl);
197 struct TagItem tags[] = {
198 {aHidd_BitMap_Visible, FALSE},
199 {TAG_DONE , 0 }
202 D(bug("[VesaGfx] Show(0x%p), old visible 0x%p\n", msg->bitMap, data->visible));
204 LOCK_FRAMEBUFFER(data);
206 /* Remove old bitmap from the screen */
207 if (data->visible)
209 D(bug("[VesaGfx] Hiding old bitmap\n"));
210 OOP_SetAttrs(data->visible, tags);
213 if (msg->bitMap)
215 /* If we have a bitmap to show, set it as visible */
216 D(bug("[VesaGfx] Showing new bitmap\n"));
217 tags[0].ti_Data = TRUE;
218 OOP_SetAttrs(msg->bitMap, tags);
220 else
222 D(bug("[VesaGfx] Blanking screen\n"));
223 /* Otherwise simply clear the framebuffer */
224 ClearBuffer(&data->data);
227 data->visible = msg->bitMap;
228 UNLOCK_FRAMEBUFFER(data);
230 D(bug("[VesaGfx] Show() done\n"));
231 return msg->bitMap;