2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
5 Desc: Offscreen bitmap class for X11 hidd.
9 /****************************************************************************************/
11 #define __OOP_NOATTRBASES__
16 #include <X11/Xutil.h>
17 #include <X11/cursorfont.h>
18 #include <X11/keysym.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>
31 #include <exec/alerts.h>
33 #include <hidd/graphics.h>
35 #include <aros/symbolsets.h>
39 #include <aros/debug.h>
41 #include LC_LIBDEFS_FILE
43 #include "x11gfx_intern.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
},
60 { IID_Hidd_X11Gfx
, &HiddX11GfxAB
},
61 { IID_Hidd_X11BitMap
, &HiddX11BitMapAB
},
65 /****************************************************************************************/
67 /* Macro trick to reuse code between offscreen and onscreen bitmap hidd
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;
91 ULONG width
, height
, depth
;
92 IPTR attrs
[num_Hidd_BitMap_Attrs
];
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");
107 if (GOT_BM_ATTR(Friend
))
108 friend = (OOP_Object
*)attrs
[AO(Friend
)];
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 */
121 OOP_GetAttr(friend, aHidd_X11BitMap_Drawable
, &friend_drawable
);
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");
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
143 depth
= DefaultDepth(display
, screen
);
148 #warning "Need this because of stipple bug in XFree86 :-("
152 D(bug("Creating X Pixmap, %p, %d, %d, %d\n", friend_drawable
, width
, height
, depth
));
155 d
= XCALL(XCreatePixmap
, display
, friend_drawable
, width
, height
, depth
);
156 XCALL(XFlush
, display
);
162 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
166 /* Delete the drawable */
171 struct bitmap_data
*data
;
174 data
= OOP_INST_DATA(cl
, o
);
177 memset(data
, 0, sizeof(struct bitmap_data
));
179 /* Get some info passed to us by the x11gfxhidd class */
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
);
187 D(bug("Creating GC\n"));
189 gcval
.plane_mask
= AllPlanes
;
190 gcval
.graphics_exposures
= False
;
193 data
->gc
= XCALL(XCreateGC
, data
->display
, DRAWABLE(data
),
194 GCPlaneMask
| GCGraphicsExposures
, &gcval
);
201 XCALL(XFlush
, data
->display
);
212 OOP_MethodID disp_mid
= OOP_GetMethodID(IID_Root
, moRoot_Dispose
);
214 OOP_CoerceMethod(cl
, o
, (OOP_Msg
) &disp_mid
);
219 } /* if (object allocated by superclass) */
222 ReturnPtr("X11Gfx.OffBitMap::New()", OOP_Object
*, o
);
226 XCALL(XFreePixmap
, display
, d
);
227 XCALL(XFlush
, display
);
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"));
245 XCALL(XFreeGC
, data
->display
, data
->gc
);
252 XCALL(XFreePixmap
, GetSysDisplay(), DRAWABLE(data
));
253 XCALL(XFlush
, GetSysDisplay() );
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
);
269 /* Get width & height from bitmap superclass */
271 OOP_GetAttr(o
, aHidd_BitMap_Width
, &width
);
272 OOP_GetAttr(o
, aHidd_BitMap_Height
, &height
);
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
);
283 /****************************************************************************************/
289 #include <aros/debug.h>
291 /****************************************************************************************/
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
);
312 /****************************************************************************************/
314 ADD2INITLIB(X11OffBM_Init
, 0);
315 ADD2EXPUNGELIB(X11OffBM_Expunge
, 0);