Added missing properties.
[tangerine.git] / arch / all-x11 / hidd / offbitmap.c
blob0d84ed3b995d9c526f379605d12c1cd217b2abb1
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Offscreen bitmap class for X11 hidd.
6 Lang: English.
7 */
9 /****************************************************************************************/
11 #define __OOP_NOATTRBASES__
13 #include <stdlib.h>
14 #include <stdio.h>
15 #include <X11/Xlib.h>
16 #include <X11/Xutil.h>
17 #include <X11/cursorfont.h>
18 #include <X11/keysym.h>
20 #include <string.h>
22 #include <proto/oop.h>
23 #include <proto/utility.h>
25 #include <exec/memory.h>
26 #include <exec/lists.h>
28 #include <graphics/rastport.h>
29 #include <graphics/gfx.h>
30 #include <oop/oop.h>
31 #include <exec/alerts.h>
33 #include <hidd/graphics.h>
35 #include <aros/symbolsets.h>
37 #define SDEBUG 0
38 #define DEBUG 0
39 #include <aros/debug.h>
41 #include LC_LIBDEFS_FILE
43 #include "x11gfx_intern.h"
44 #include "x11.h"
46 #include "bitmap.h"
48 /****************************************************************************************/
50 static OOP_AttrBase HiddBitMapAttrBase;
51 static OOP_AttrBase HiddPixFmtAttrBase;
52 static OOP_AttrBase HiddX11GfxAB;
53 static OOP_AttrBase HiddX11BitMapAB;
55 static struct OOP_ABDescr attrbases[] =
57 { IID_Hidd_BitMap , &HiddBitMapAttrBase },
58 { IID_Hidd_PixFmt , &HiddPixFmtAttrBase },
59 /* Private bases */
60 { IID_Hidd_X11Gfx , &HiddX11GfxAB },
61 { IID_Hidd_X11BitMap, &HiddX11BitMapAB },
62 { NULL , NULL }
65 /****************************************************************************************/
67 /* Macro trick to reuse code between offscreen and onscreen bitmap hidd
68 (bitmap_common.c) */
70 #define DRAWABLE(data) (data)->drawable.pixmap
72 #define MNAME(x) X11OffBM__ ## x
74 /* !!! Include methods whose implementation is eqaul for windows and pixmaps
75 (except the DRAWABLE) */
77 #include "bitmap_common.c"
79 /****************************************************************************************/
81 #define AO(x) (aoHidd_BitMap_ ## x)
82 #define GOT_BM_ATTR(code) GOT_ATTR(code, aoHidd_BitMap, bitmap)
84 /****************************************************************************************/
86 OOP_Object *X11OffBM__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
88 OOP_Object *friend = NULL, *pixfmt;
89 Drawable friend_drawable = 0, d = 0;
90 Display *display;
91 ULONG width, height, depth;
92 IPTR attrs[num_Hidd_BitMap_Attrs];
93 int screen;
94 BOOL ok = TRUE;
96 DECLARE_ATTRCHECK(bitmap);
98 /* Parse the attributes */
99 if (0 != OOP_ParseAttrs(msg->attrList, attrs, num_Hidd_BitMap_Attrs,
100 &ATTRCHECK(bitmap), HiddBitMapAttrBase))
102 kprintf("!!! X11Gfx::OffBitMap() FAILED TO PARSE ATTRS !!!\n");
104 return NULL;
107 if (GOT_BM_ATTR(Friend))
108 friend = (OOP_Object *)attrs[AO(Friend)];
109 else
110 friend = NULL;
112 width = attrs[AO(Width)];
113 height = attrs[AO(Height)];
114 pixfmt = (OOP_Object *)attrs[AO(PixFmt)];
116 OOP_GetAttr(pixfmt, aHidd_PixFmt_Depth, &depth);
118 /* Get the X11 window from the friend bitmap */
119 if (NULL != friend)
121 OOP_GetAttr(friend, aHidd_X11BitMap_Drawable, &friend_drawable);
123 else
125 friend_drawable = XSD(cl)->dummy_window_for_creating_pixmaps;
128 if (0 == friend_drawable)
130 kprintf("ALERT!!! FRIEND BITMAP HAS NO DRAWABLE in config/x11/hidd/offbitmap.c\n");
131 Alert(AT_DeadEnd);
134 display = (Display *)GetTagData(aHidd_X11Gfx_SysDisplay, 0, msg->attrList);
135 screen = GetTagData(aHidd_X11Gfx_SysScreen, 0, msg->attrList);
137 /* We must only create depths that are supported by the friend drawable
138 Currently we only support the default depth, and depth 1
140 if (depth != 1)
142 LOCK_X11
143 depth = DefaultDepth(display, screen);
144 UNLOCK_X11
146 else
148 #warning "Need this because of stipple bug in XFree86 :-("
149 width += 32;
152 D(bug("Creating X Pixmap, %p, %d, %d, %d\n", friend_drawable, width, height, depth));
154 LOCK_X11
155 d = XCALL(XCreatePixmap, display, friend_drawable, width, height, depth);
156 XCALL(XFlush, display);
157 UNLOCK_X11
159 if (0 == d)
160 return NULL;
162 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
164 if (NULL == o)
166 /* Delete the drawable */
167 goto dispose_pixmap;
169 else
171 struct bitmap_data *data;
172 XGCValues gcval;
174 data = OOP_INST_DATA(cl, o);
176 /* clear all data */
177 memset(data, 0, sizeof(struct bitmap_data));
179 /* Get some info passed to us by the x11gfxhidd class */
180 DRAWABLE(data) = d;
181 data->display = display;
182 data->screen = screen;
183 data->cursor = (Cursor) GetTagData(aHidd_X11Gfx_SysCursor, 0, msg->attrList);
184 data->colmap = (Colormap) GetTagData(aHidd_X11Gfx_ColorMap, 0, msg->attrList);
186 /* Create X11 GC */
187 D(bug("Creating GC\n"));
189 gcval.plane_mask = AllPlanes;
190 gcval.graphics_exposures = False;
192 LOCK_X11
193 data->gc = XCALL(XCreateGC, data->display, DRAWABLE(data),
194 GCPlaneMask | GCGraphicsExposures, &gcval);
196 UNLOCK_X11
198 if (data->gc)
200 LOCK_X11
201 XCALL(XFlush, data->display);
202 UNLOCK_X11
204 else
206 ok = FALSE;
210 if (!ok)
212 OOP_MethodID disp_mid = OOP_GetMethodID(IID_Root, moRoot_Dispose);
214 OOP_CoerceMethod(cl, o, (OOP_Msg) &disp_mid);
215 o = NULL;
219 } /* if (object allocated by superclass) */
222 ReturnPtr("X11Gfx.OffBitMap::New()", OOP_Object *, o);
224 dispose_pixmap:
225 LOCK_X11
226 XCALL(XFreePixmap, display, d);
227 XCALL(XFlush, display);
228 UNLOCK_X11
230 ReturnPtr("X11Gfx.OffBitMap::New()", OOP_Object *, NULL);
234 /****************************************************************************************/
236 VOID X11OffBM__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
238 struct bitmap_data *data = OOP_INST_DATA(cl, o);
240 EnterFunc(bug("X11Gfx.BitMap::Dispose()\n"));
242 if (data->gc)
244 LOCK_X11
245 XCALL(XFreeGC, data->display, data->gc);
246 UNLOCK_X11
249 if (DRAWABLE(data))
251 LOCK_X11
252 XCALL(XFreePixmap, GetSysDisplay(), DRAWABLE(data));
253 XCALL(XFlush, GetSysDisplay() );
254 UNLOCK_X11
257 OOP_DoSuperMethod(cl, o, msg);
259 ReturnVoid("X11Gfx.BitMap::Dispose");
262 /****************************************************************************************/
264 VOID X11OffBM__Hidd_BitMap__Clear(OOP_Class *cl, OOP_Object *o, struct pHidd_BitMap_Clear *msg)
266 struct bitmap_data *data = OOP_INST_DATA(cl, o);
267 ULONG width, height;
269 /* Get width & height from bitmap superclass */
271 OOP_GetAttr(o, aHidd_BitMap_Width, &width);
272 OOP_GetAttr(o, aHidd_BitMap_Height, &height);
274 LOCK_X11
275 XCALL(XSetForeground, data->display, data->gc, GC_BG(msg->gc));
276 XCALL(XFillRectangle, data->display, DRAWABLE(data), data->gc,
277 0 , 0, width, height);
278 XCALL(XFlush, data->display);
279 UNLOCK_X11
283 /****************************************************************************************/
285 #undef SDEBUG
286 #undef DEBUG
287 #define SDEBUG 0
288 #define DEBUG 0
289 #include <aros/debug.h>
291 /****************************************************************************************/
294 #undef XSD
295 #define XSD(cl) (&LIBBASE->xsd)
297 /****************************************************************************************/
299 static int X11OffBM_Init(LIBBASETYPEPTR LIBBASE)
301 return OOP_ObtainAttrBases(attrbases);
304 /****************************************************************************************/
306 static int X11OffBM_Expunge(LIBBASETYPEPTR LIBBASE)
308 OOP_ReleaseAttrBases(attrbases);
309 return TRUE;
312 /****************************************************************************************/
314 ADD2INITLIB(X11OffBM_Init, 0);
315 ADD2EXPUNGELIB(X11OffBM_Expunge, 0);