Updated PCI IDs to latest snapshot.
[tangerine.git] / arch / i386-pc / drivers / vesa.hidd / vesagfxclass.c
blobb4c0be56a9b62bdb01d68cd8ef93971d7fabadf3
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Class for Vesa.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <proto/exec.h>
12 #include <proto/oop.h>
13 #include <proto/utility.h>
14 #include <aros/symbolsets.h>
15 #include <devices/inputevent.h>
16 #include <exec/alerts.h>
17 #include <exec/memory.h>
18 #include <hardware/custom.h>
19 #include <hidd/hidd.h>
20 #include <hidd/graphics.h>
21 #include <oop/oop.h>
22 #include <clib/alib_protos.h>
23 #include <string.h>
25 #define DEBUG 0
26 #include <aros/debug.h>
28 #include "vesagfxclass.h"
29 #include "bitmap.h"
30 #include "hardware.h"
32 #include LC_LIBDEFS_FILE
34 static OOP_AttrBase HiddBitMapAttrBase;
35 static OOP_AttrBase HiddPixFmtAttrBase;
36 static OOP_AttrBase HiddGfxAttrBase;
37 static OOP_AttrBase HiddSyncAttrBase;
38 static OOP_AttrBase HiddVesaGfxAttrBase;
39 static OOP_AttrBase HiddVesaGfxBitMapAttrBase;
41 static struct OOP_ABDescr attrbases[] =
43 {IID_Hidd_BitMap, &HiddBitMapAttrBase},
44 {IID_Hidd_VesaGfxBitMap, &HiddVesaGfxBitMapAttrBase},
45 {IID_Hidd_VesaGfx, &HiddVesaGfxAttrBase},
46 {IID_Hidd_PixFmt, &HiddPixFmtAttrBase},
47 {IID_Hidd_Sync, &HiddSyncAttrBase},
48 {IID_Hidd_Gfx, &HiddGfxAttrBase},
49 {NULL, NULL}
52 static UBYTE syncdescription[100];
54 OOP_Object *PCVesa__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
56 struct TagItem pftags[] =
58 {aHidd_PixFmt_RedShift, 0}, /* 0 */
59 {aHidd_PixFmt_GreenShift, 0}, /* 1 */
60 {aHidd_PixFmt_BlueShift, 0}, /* 2 */
61 {aHidd_PixFmt_AlphaShift, 0}, /* 3 */
62 {aHidd_PixFmt_RedMask, 0}, /* 4 */
63 {aHidd_PixFmt_GreenMask, 0}, /* 5 */
64 {aHidd_PixFmt_BlueMask, 0}, /* 6 */
65 {aHidd_PixFmt_AlphaMask, 0}, /* 7 */
66 {aHidd_PixFmt_ColorModel, 0}, /* 8 */
67 {aHidd_PixFmt_Depth, 0}, /* 9 */
68 {aHidd_PixFmt_BytesPerPixel,0}, /* 10 */
69 {aHidd_PixFmt_BitsPerPixel, 0}, /* 11 */
70 {aHidd_PixFmt_StdPixFmt, 0}, /* 12 */
71 {aHidd_PixFmt_CLUTShift, 0}, /* 13 */
72 {aHidd_PixFmt_CLUTMask, 0}, /* 14 */
73 {aHidd_PixFmt_BitMapType, 0}, /* 15 */
74 {TAG_DONE, 0UL }
76 struct TagItem sync_mode[] =
78 {aHidd_Sync_PixelClock, 0},
79 {aHidd_Sync_HDisp, 0},
80 {aHidd_Sync_VDisp, 0},
81 {aHidd_Sync_Description,0},
82 {aHidd_Sync_HSyncStart, 0},
83 {aHidd_Sync_HSyncEnd, 0},
84 {aHidd_Sync_HTotal, 0},
85 {aHidd_Sync_VSyncStart, 0},
86 {aHidd_Sync_VSyncEnd, 0},
87 {aHidd_Sync_VTotal, 0},
88 {TAG_DONE, 0UL}
90 struct TagItem modetags[] =
92 {aHidd_Gfx_PixFmtTags, (IPTR)pftags},
93 {aHidd_Gfx_SyncTags, (IPTR)sync_mode},
94 {TAG_DONE, 0UL}
96 struct TagItem yourtags[] =
98 {aHidd_Gfx_ModeTags, (IPTR)modetags},
99 {TAG_MORE, 0UL}
101 struct pRoot_New yourmsg;
103 pftags[0].ti_Data = XSD(cl)->data.redshift;
104 pftags[1].ti_Data = XSD(cl)->data.greenshift;
105 pftags[2].ti_Data = XSD(cl)->data.blueshift;
106 pftags[3].ti_Data = 0;
107 pftags[4].ti_Data = XSD(cl)->data.redmask;
108 pftags[5].ti_Data = XSD(cl)->data.greenmask;
109 pftags[6].ti_Data = XSD(cl)->data.bluemask;
110 pftags[7].ti_Data = 0;
111 pftags[8].ti_Data = (XSD(cl)->data.depth > 8) ? vHidd_ColorModel_TrueColor : vHidd_ColorModel_Palette;
112 pftags[9].ti_Data = (XSD(cl)->data.depth > 24) ? 24 : XSD(cl)->data.depth;
113 pftags[10].ti_Data = XSD(cl)->data.bytesperpixel;
114 pftags[11].ti_Data = (XSD(cl)->data.bitsperpixel > 24) ? 24 : XSD(cl)->data.bitsperpixel;
115 pftags[12].ti_Data = vHidd_StdPixFmt_Native;
116 pftags[14].ti_Data = (1 << XSD(cl)->data.depth) - 1;
117 pftags[15].ti_Data = vHidd_BitMapType_Chunky;
119 sync_mode[1].ti_Data = XSD(cl)->data.width;
120 sync_mode[2].ti_Data = XSD(cl)->data.height;
121 __sprintf(syncdescription, "VESA:%ldx%ld", XSD(cl)->data.width, XSD(cl)->data.height);
122 sync_mode[3].ti_Data = (IPTR)syncdescription;
124 yourtags[1].ti_Data = (IPTR)msg->attrList;
125 yourmsg.mID = msg->mID;
126 yourmsg.attrList = yourtags;
127 msg = &yourmsg;
128 EnterFunc(bug("VesaGfx::New()\n"));
129 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
130 if (o)
132 D(bug("Got object from super\n"));
133 XSD(cl)->vesagfxhidd = o;
134 XSD(cl)->mouse.shape = NULL;
135 ReturnPtr("VesaGfx::New", OOP_Object *, o);
137 ReturnPtr("VesaGfx::New", OOP_Object *, NULL);
140 VOID PCVesa__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
142 if (XSD(cl)->mouse.shape != NULL)
143 FreeVec(XSD(cl)->mouse.shape);
144 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
147 VOID PCVesa__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
149 ULONG idx;
150 BOOL found = FALSE;
152 if (IS_GFX_ATTR(msg->attrID, idx))
154 switch (idx)
156 /* Our only gettable attribute is wether we support HW cursor or not.
157 * We do not have any such support, since we are a simple VESA fb driver */
158 case aoHidd_Gfx_SupportsHWCursor:
159 *msg->storage = (IPTR)FALSE;
160 found = TRUE;
161 break;
164 if (!found)
165 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
168 OOP_Object *PCVesa__Hidd_Gfx__NewBitMap(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_NewBitMap *msg)
170 BOOL displayable;
171 BOOL framebuffer;
172 OOP_Class *classptr = NULL;
173 struct TagItem tags[2];
174 struct pHidd_Gfx_NewBitMap yourmsg;
176 EnterFunc(bug("VesaGfx::NewBitMap()\n"));
177 displayable = GetTagData(aHidd_BitMap_Displayable, FALSE, msg->attrList);
178 framebuffer = GetTagData(aHidd_BitMap_FrameBuffer, FALSE, msg->attrList);
179 if (framebuffer)
180 classptr = XSD(cl)->onbmclass;
181 else if (displayable)
182 classptr = XSD(cl)->offbmclass;
183 else
185 HIDDT_ModeID modeid;
186 modeid = (HIDDT_ModeID)GetTagData(aHidd_BitMap_ModeID, vHidd_ModeID_Invalid, msg->attrList);
187 if (modeid != vHidd_ModeID_Invalid)
188 classptr = XSD(cl)->offbmclass;
189 else
191 HIDDT_StdPixFmt stdpf;
192 stdpf = (HIDDT_StdPixFmt)GetTagData(aHidd_BitMap_StdPixFmt, vHidd_StdPixFmt_Unknown, msg->attrList);
193 if (stdpf == vHidd_StdPixFmt_Unknown)
195 OOP_Object *friend;
196 friend = (OOP_Object *)GetTagData(aHidd_BitMap_Friend, 0, msg->attrList);
197 if (friend != NULL)
199 OOP_Object *gfxhidd;
201 OOP_GetAttr(friend, aHidd_BitMap_GfxHidd, (APTR)&gfxhidd);
202 if (gfxhidd == o)
204 classptr = XSD(cl)->offbmclass;
210 if (classptr != NULL)
212 tags[0].ti_Tag = aHidd_BitMap_ClassPtr;
213 tags[0].ti_Data = (IPTR)classptr;
214 tags[1].ti_Tag = TAG_MORE;
215 tags[1].ti_Data = (IPTR)msg->attrList;
216 yourmsg.mID = msg->mID;
217 yourmsg.attrList = tags;
218 msg = &yourmsg;
220 ReturnPtr("VesaGfx::NewBitMap", OOP_Object *, (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg));
223 VOID PCVesa__Hidd_Gfx__CopyBox(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CopyBox *msg)
225 unsigned char *src = 0, *dest = 0;
226 ULONG mode;
228 mode = GC_DRMD(msg->gc);
230 OOP_GetAttr(msg->src, aHidd_VesaGfxBitMap_Drawable, (APTR)&src);
231 OOP_GetAttr(msg->dest, aHidd_VesaGfxBitMap_Drawable, (APTR)&dest);
233 if (!dest || !src ||
234 ((mode != vHidd_GC_DrawMode_Copy)))
236 /* The source and/or destination object is no VesaGfx bitmap, onscreen nor offscreen.
237 Or drawmode is not one of those we accelerate. Let the superclass do the
238 copying in a more general way
240 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
241 return;
246 struct BitmapData *data = OOP_INST_DATA(OOP_OCLASS(msg->src), msg->src);
247 struct BitmapData *ddata = OOP_INST_DATA(OOP_OCLASS(msg->dest), msg->dest);
249 switch(mode)
251 case vHidd_GC_DrawMode_Copy:
252 switch(data->bytesperpix)
254 case 1:
255 HIDD_BM_CopyMemBox8(msg->dest,
256 data->VideoData,
257 msg->srcX,
258 msg->srcY,
259 ddata->VideoData,
260 msg->destX,
261 msg->destY,
262 msg->width,
263 msg->height,
264 data->bytesperline,
265 ddata->bytesperline);
266 break;
268 case 2:
269 HIDD_BM_CopyMemBox16(msg->dest,
270 data->VideoData,
271 msg->srcX,
272 msg->srcY,
273 ddata->VideoData,
274 msg->destX,
275 msg->destY,
276 msg->width,
277 msg->height,
278 data->bytesperline,
279 ddata->bytesperline);
280 break;
283 case 3:
284 HIDD_BM_CopyMemBox24(msg->dest,
285 data->VideoData,
286 msg->srcX,
287 msg->srcY,
288 ddata->VideoData,
289 msg->destX,
290 msg->destY,
291 msg->width,
292 msg->height,
293 data->bytesperline,
294 ddata->bytesperline);
295 break;
297 case 4:
298 HIDD_BM_CopyMemBox32(msg->dest,
299 data->VideoData,
300 msg->srcX,
301 msg->srcY,
302 ddata->VideoData,
303 msg->destX,
304 msg->destY,
305 msg->width,
306 msg->height,
307 data->bytesperline,
308 ddata->bytesperline);
309 break;
311 } /* switch(data->bytesperpix) */
312 break;
314 } /* switch(mode) */
316 #if BUFFERED_VRAM
317 if (OOP_OCLASS(msg->dest) == XSD(cl)->onbmclass)
319 LOCK_FRAMEBUFFER(XSD(cl));
320 vesaRefreshArea(ddata, msg->destX, msg->destY, msg->destX + msg->width - 1, msg->destY + msg->height - 1);
321 UNLOCK_FRAMEBUFFER(XSD(cl));
323 #endif
325 } /**/
329 VOID PCVesa__Hidd_Gfx__ShowImminentReset(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
331 memset(XSD(cl)->data.framebuffer,
333 XSD(cl)->data.height * XSD(cl)->data.bytesperline);
337 static int PCVesa_InitClass(LIBBASETYPEPTR LIBBASE)
339 EnterFunc(bug("PCVesa_InitClass\n"));
341 LIBBASE->vsd.mouse.x=0;
342 LIBBASE->vsd.mouse.y=0;
343 LIBBASE->vsd.mouse.shape = NULL;
345 ReturnInt("PCVesa_InitClass", ULONG, OOP_ObtainAttrBases(attrbases));
348 static int PCVesa_ExpungeClass(LIBBASETYPEPTR LIBBASE)
350 EnterFunc(bug("free_vesagfxclass(xsd=%p)\n", xsd));
352 OOP_ReleaseAttrBases(attrbases);
353 ReturnInt("PCVesa_ExpungeClass", int, TRUE);
356 ADD2INITLIB(PCVesa_InitClass, 0)
357 ADD2EXPUNGELIB(PCVesa_ExpungeClass, 0)