2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Graphics-amiga-intui bitmap class implementation.
11 #include <proto/exec.h>
12 #include <proto/utility.h>
13 #include <proto/intuition.h>
14 #include <proto/oop.h>
16 #include <exec/memory.h>
17 #include <utility/tagitem.h>
18 #include <intuition/screens.h>
22 #include <hidd/graphics.h>
23 #include <hidd/graphics-amiga-intuition.h>
25 #include "graphics_intern.h"
30 #include <aros/debug.h>
32 #define IS_BM_ATTR(attr, idx) ( ( (idx) = (attr) - HiddBitMapAttrBase) < num_Hidd_BitMap_Attrs)
34 static AttrBase HiddBitMapAttrBase
= 0;
36 /*** BitMap::New() ************************************************************/
38 static Object
*bitmap_new(Class
*cl
, Object
*obj
, struct pRoot_New
*msg
)
40 struct TagItem tags
[] = {
41 {aHidd_BitMap_AllocBuffer
, FALSE
},
42 {TAG_MORE
, (IPTR
) NULL
}
45 struct HIDDBitMapAmigaIntuiData
*data
;
46 struct TagItem
*tag
, *tstate
, *newTagList
;
49 struct pRoot_New new_msg
;
50 struct pHidd_BitMap_PrivateSet private_set_msg
;
52 ULONG width
, height
, depth
, format
;
55 EnterFunc(bug("BitMapAmigaIntui::New()\n"));
57 new_msg
.mID
= GetMethodID(IID_Root
, moRoot_New
);
58 private_set_msg
.mID
= GetMethodID(IID_Hidd_BitMap
, moHidd_BitMap_PrivateSet
);
61 displayable
= (BOOL
) GetTagData(aHidd_BitMap_Displayable
, 0, msg
->attrList
);
64 /* let the superclass do all work */
66 obj
= (Object
*) DoSuperMethod(cl
, obj
, (Msg
) msg
);
72 aHidd_BitMap_AllocBuffer and aHidd_BitMap_Displayable must be
73 FALSE. To make this easy first a copy of the taglist is
74 created. In the new list Hidd_BitMap_Displayable is set to
75 FALSE. If the taglist contains a "aHidd_BitMap_AllocBuffer"
76 tag then ti_Data is set to FALSE else tags(see above) is
77 connected with the new list.
79 NOTE: If msg.attrList contains more than one
80 "aHidd_BitMap_AllocBuffer" we have a problem.
83 newTagList
= CloneTagItems(msg
->attrList
);
86 tag
= FindTagItem(aHidd_BitMap_Displayable
, newTagList
);
92 tag
= FindTagItem(aHidd_BitMap_AllocBuffer
, newTagList
);
96 new_msg
.attrList
= newTagList
;
100 tags
[1].ti_Data
= (IPTR
) newTagList
;
101 new_msg
.attrList
= tags
;
104 obj
= (Object
*) DoSuperMethod(cl
, obj
, (Msg
) &new_msg
);
106 FreeTagItems(newTagList
);
111 data
= INST_DATA(cl
, obj
);
113 /* clear all data and set some default values */
114 memset(data
, 0, sizeof(struct HIDDBitMapAmigaIntuiData
));
116 GetAttr(obj
, aHidd_BitMap_Width
, &width
);
117 GetAttr(obj
, aHidd_BitMap_Height
, &height
);
118 GetAttr(obj
, aHidd_BitMap_Depth
, &depth
);
119 GetAttr(obj
, aHidd_BitMap_Format
, &format
);
121 if(format
== vHIDD_BitMap_Format_Planar
)
123 /* only displayable support for planar format */
125 struct TagItem tags
[] =
130 {SA_Height
, height
},
132 {TAG_SKIP
, 1}, /* Use SA_DisplayID only wenn a display mode */
133 {SA_DisplayID
, 0}, /* is specified */
134 {SA_Title
, (ULONG
) "AROS graphics hidd"},
135 {SA_Type
, CUSTOMSCREEN
},
137 /* Will be use later */
138 /* SA_Quiet , TRUE, */
139 /* SA_BitMap , 0 On V37 double buffering could only
140 implemented with a custom bitmap */
144 data
->screen
= OpenScreenTagList(NULL
, tags
);
147 struct TagItem set
[] =
149 {aHidd_BitMap_BaseAddress
, (IPTR
) &data
->screen
->RastPort
.BitMap
->Planes
[0]},
150 {aHidd_BitMap_Format
, vHIDD_BitMap_Format_Planar
},
151 {aHidd_BitMap_Displayable
, TRUE
},
152 {aHidd_BitMap_BytesPerRow
, data
->screen
->RastPort
.BitMap
->BytesPerRow
},
156 private_set_msg
.attrList
= set
;
157 DoSuperMethod(cl
, obj
, (Msg
) &private_set_msg
);
159 } /* if(data->screen) */
160 } /* if(format == vHIDD_BitMap_Format_Planar) */
162 } /* if(!displayable) */
164 /* free all on error */
167 if(obj
) DisposeObject(obj
);
171 ReturnPtr("BitMapAmigaIntui::New", Object
*, obj
);
175 /*** BitMap::Dispose() ********************************************************/
177 static void bitmap_dispose(Class
*cl
, Object
*obj
, Msg
*msg
)
179 struct HIDDBitMapAmigaIntuiData
*data
= INST_DATA(cl
, obj
);
181 struct pHidd_BitMap_PrivateSet private_set_msg
;
184 EnterFunc(bug("BitMapAmigaIntui::Dispose()\n"));
189 We use an own buffer so set the BaseAddress to NULL to prevent
190 the superclass to free our own buffer.
193 struct TagItem set
[] =
195 {aHidd_BitMap_BaseAddress
, NULL
},
199 CloseScreen(data
->screen
);
201 private_set_msg
.mID
= GetMethodID(IID_Hidd_BitMap
, moHidd_BitMap_PrivateSet
);
202 private_set_msg
.attrList
= set
;
203 DoSuperMethod(cl
, obj
, (Msg
) &private_set_msg
);
206 DoSuperMethod(cl
, obj
, (Msg
) msg
);
208 ReturnVoid("BitMapAmigaIntui::Dispose");
212 /*** init_bitmapclass *********************************************************/
217 #define OOPBase (csd->oopbase)
218 #define SysBase (csd->sysbase)
220 #define NUM_ROOT_METHODS 2
221 #define NUM_BITMAP_METHODS 0
223 Class
*init_bitmapclass(struct class_static_data
*csd
)
225 struct MethodDescr root_descr
[NUM_ROOT_METHODS
+ 1] =
227 {(IPTR (*)())bitmap_new
, moRoot_New
},
228 {(IPTR (*)())bitmap_dispose
, moRoot_Dispose
},
232 struct MethodDescr bitMap_descr
[NUM_BITMAP_METHODS
+ 1] =
237 struct InterfaceDescr ifdescr
[] =
239 {root_descr
, IID_Root
, NUM_ROOT_METHODS
},
240 {bitMap_descr
, IID_Hidd_BitMap
, NUM_BITMAP_METHODS
},
244 AttrBase MetaAttrBase
= GetAttrBase(IID_Meta
);
246 struct TagItem tags
[] =
248 {aMeta_SuperID
, (IPTR
) CLID_Hidd_BitMap
},
249 {aMeta_InterfaceDescr
, (IPTR
) ifdescr
},
250 {aMeta_ID
, (IPTR
) CLID_Hidd_BitMapAmigaIntui
},
251 {aMeta_InstSize
, (IPTR
) sizeof(struct HIDDBitMapAmigaIntuiData
)},
257 EnterFunc(bug("init_bitmapclassAmigaIntui(csd=%p)\n", csd
));
261 cl
= NewObject(NULL
, CLID_HiddMeta
, tags
);
264 D(bug("BitMap class ok\n"));
265 csd
->bitmapclass
= cl
;
266 cl
->UserData
= (APTR
) csd
;
268 /* Get attrbase for the BitMap interface */
269 HiddBitMapAttrBase
= ObtainAttrBase(IID_Hidd_BitMap
);
270 if(HiddBitMapAttrBase
)
276 free_bitmapclass(csd
);
280 } /* if(MetaAttrBase) */
282 ReturnPtr("init_bitmapclassAmigaIntui", Class
*, cl
);
286 /*** free_bitmapclass *********************************************************/
288 void free_bitmapclass(struct class_static_data
*csd
)
290 EnterFunc(bug("free_bitmapclassAmigaIntui(csd=%p)\n", csd
));
294 RemoveClass(csd
->bitmapclass
);
295 DisposeObject((Object
*) csd
->bitmapclass
);
296 csd
->bitmapclass
= NULL
;
297 if(HiddBitMapAttrBase
) ReleaseAttrBase(IID_Hidd_BitMap
);
300 ReturnVoid("free_bitmapclassAmigaIntui");