Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / arch / i386-pc / drivers / vga.hidd / offbitmap.c
bloba09bfd623227597e0d55b5ac019d156a46c4372d
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Offscreen bitmap class for VGA hidd.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <proto/oop.h>
12 #include <proto/utility.h>
14 #include <exec/memory.h>
15 #include <exec/lists.h>
17 #include <graphics/rastport.h>
18 #include <graphics/gfx.h>
19 #include <oop/oop.h>
20 #include <exec/alerts.h>
22 #include <aros/symbolsets.h>
24 #include <hidd/graphics.h>
26 #include <assert.h>
28 #include "vga.h"
29 #include "vgaclass.h"
31 #include LC_LIBDEFS_FILE
33 #define SDEBUG 0
34 #define DEBUG 0
35 #include <aros/debug.h>
37 #include "bitmap.h"
39 /* Don't initialize them with "= 0", otherwise they end up in the DATA segment! */
41 static OOP_AttrBase HiddBitMapAttrBase;
42 static OOP_AttrBase HiddPixFmtAttrBase;
43 static OOP_AttrBase HiddGfxAttrBase;
44 static OOP_AttrBase HiddVGAGfxAB;
45 static OOP_AttrBase HiddVGABitMapAB;
47 static struct OOP_ABDescr attrbases[] =
49 { IID_Hidd_BitMap, &HiddBitMapAttrBase },
50 { IID_Hidd_PixFmt, &HiddPixFmtAttrBase },
51 { IID_Hidd_Gfx, &HiddGfxAttrBase },
52 /* Private bases */
53 { IID_Hidd_VGAgfx, &HiddVGAGfxAB },
54 { IID_Hidd_VGABitMap, &HiddVGABitMapAB },
55 { NULL, NULL }
58 void free_offbmclass(struct vga_staticdata *);
59 void vgaRefreshArea(struct bitmap_data *, int , struct Box *);
61 #define MNAME_ROOT(x) PCVGAOffBM__Root__ ## x
62 #define MNAME_BM(x) PCVGAOffBM__Hidd_BitMap__ ## x
64 #include "bitmap_common.c"
66 /*********** BitMap::New() *************************************/
68 OOP_Object *PCVGAOffBM__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
70 EnterFunc(bug("VGAGfx.BitMap::New()\n"));
72 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
73 if (o)
75 struct bitmap_data *data;
76 IPTR width, height, depth;
78 OOP_Object *friend, *pf;
80 data = OOP_INST_DATA(cl, o);
82 /* clear all data */
83 memset(data, 0, sizeof(struct bitmap_data));
85 /* Get attr values */
86 OOP_GetAttr(o, aHidd_BitMap_Width, &width);
87 OOP_GetAttr(o, aHidd_BitMap_Height, &height);
88 #if 0
89 /* nlorentz: The aHidd_BitMap_Depth attribute no loner exist,, so we must
90 get the depth in two steps: First get pixel format, then get depth */
91 OOP_GetAttr(o, aHidd_BitMap_Depth, &depth);
92 #else
93 OOP_GetAttr(o, aHidd_BitMap_PixFmt, &pf);
94 OOP_GetAttr(pf, aHidd_PixFmt_Depth, &depth);
95 #endif
97 /* Get the friend bitmap. This should be a displayable bitmap */
98 OOP_GetAttr(o, aHidd_BitMap_Friend, &friend);
100 /* If you got a friend bitmap, copy its colormap */
101 if (friend)
103 struct bitmap_data *src = OOP_INST_DATA(cl, friend);
105 CopyMem(&src->cmap, &data->cmap, 4*16);
109 ASSERT (width != 0 && height != 0 && depth != 0);
112 We must only create depths that are supported by the friend drawable
113 Currently we only support the default depth
116 /* nlorentz: With the new HIDD design we decided in Gfx::NewBitMap()
117 that we should only create bitmaps that are alike to the friend bitmap.
118 Thus the test below is really not necessary, as we will allways
119 get the same depth
121 if (depth != 4)
123 // depth = 4; /* Do anything... */
126 #if 0
127 /* nlorentz: Not necessary with the new design */
128 /* Update the depth to the one we use */
129 depth_tags[0].ti_Data = depth;
130 SetAttrs(o, depth_tags);
131 #endif
132 data->width = width;
133 data->height = height;
134 data->bpp = depth;
135 data->disp = 0;
136 width=(width+15) & ~15;
137 data->VideoData = AllocVec(width*height,MEMF_PUBLIC|MEMF_CLEAR);
138 if (data->VideoData)
140 data->Regs = AllocVec(sizeof(struct vgaHWRec),MEMF_PUBLIC|MEMF_CLEAR);
141 if (data->Regs)
143 #if 0
144 /* nlorentz: Not necessary nor possible with the new design */
145 set_pixelformat(o);
146 #endif
147 if (XSD(cl)->activecallback)
148 XSD(cl)->activecallback(XSD(cl)->callbackdata, o, TRUE);
150 ReturnPtr("VGAGfx.BitMap::New()", OOP_Object *, o);
152 } /* if got data->VideoData */
155 OOP_MethodID disp_mid = OOP_GetMethodID(IID_Root, moRoot_Dispose);
156 OOP_CoerceMethod(cl, o, (OOP_Msg) &disp_mid);
159 o = NULL;
160 } /* if created object */
162 ReturnPtr("VGAGfx.BitMap::New()", OOP_Object *, o);
165 /********** Bitmap::Dispose() ***********************************/
167 VOID PCVGAOffBM__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
169 struct bitmap_data *data = OOP_INST_DATA(cl, o);
170 EnterFunc(bug("VGAGfx.BitMap::Dispose()\n"));
172 if (data->VideoData)
173 FreeVec(data->VideoData);
174 if (data->Regs)
175 FreeVec(data->Regs);
177 OOP_DoSuperMethod(cl, o, msg);
179 ReturnVoid("VGAGfx.BitMap::Dispose");
183 #undef SDEBUG
184 #undef DEBUG
185 #define SDEBUG 0
186 #define DEBUG 0
187 #include <aros/debug.h>
191 /*** init_bmclass *********************************************************/
193 static int PCVGAOffBM_Init(LIBBASETYPEPTR LIBBASE)
195 EnterFunc(bug("PCVGAOffBM_Init\n"));
197 ReturnInt("PCVGAOffBM_Init", ULONG, OOP_ObtainAttrBases(attrbases));
200 /*** expunge_onbmclass *******************************************************/
202 static int PCVGAOffBM_Expunge(LIBBASETYPEPTR LIBBASE)
204 EnterFunc(bug("PCVGAOffBM_Expunge\n"));
206 OOP_ReleaseAttrBases(attrbases);
207 ReturnInt("PCVGAOffBM_Expunge", int, TRUE);
210 /*****************************************************************************/
212 ADD2INITLIB(PCVGAOffBM_Init, 0)
213 ADD2EXPUNGELIB(PCVGAOffBM_Expunge, 0)