Added missing properties.
[tangerine.git] / arch / all-x11 / hidd / x11gfx.c
blob14dbb711bb4fd736489eafae3bacf0d519084bd4
1 /*
2 Copyright © 1995-2006, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: X11 gfx HIDD for AROS.
6 Lang: English.
7 */
9 #define __OOP_NOATTRBASES__
11 #include <stddef.h>
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
16 #include <X11/Xlib.h>
17 #include <X11/cursorfont.h>
18 #include <X11/Xutil.h>
20 #include <signal.h>
21 #include <string.h>
23 #include <exec/libraries.h>
24 #include <exec/types.h>
25 #include <exec/resident.h>
26 #include <exec/memory.h>
27 #include <aros/libcall.h>
28 #include <proto/exec.h>
29 #include <proto/oop.h>
30 #include <proto/utility.h>
31 #include <oop/oop.h>
33 #include <hidd/hidd.h>
34 #include <hidd/graphics.h>
36 #include <aros/symbolsets.h>
38 #include "x11gfx_intern.h"
39 #include "x11.h"
40 #include "bitmap.h"
42 #include LC_LIBDEFS_FILE
44 #define SDEBUG 0
45 #define DEBUG 0
46 #include <aros/debug.h>
48 #define XFLUSH(x) XCALL(XFlush, x)
49 //#define XFLUSH(x)
51 /****************************************************************************************/
53 #define IS_X11GFX_ATTR(attr, idx) ( ( (idx) = (attr) - HiddX11GfxAB) < num_Hidd_X11Gfx_Attrs)
56 /* Some attrbases needed as global vars.
57 These are write-once read-many */
59 static OOP_AttrBase HiddBitMapAttrBase;
60 static OOP_AttrBase HiddX11GfxAB;
61 static OOP_AttrBase HiddX11BitMapAB;
62 static OOP_AttrBase HiddSyncAttrBase;
63 static OOP_AttrBase HiddPixFmtAttrBase;
64 static OOP_AttrBase HiddGfxAttrBase;
66 static struct OOP_ABDescr attrbases[] =
68 { IID_Hidd_BitMap , &HiddBitMapAttrBase },
69 { IID_Hidd_X11Gfx , &HiddX11GfxAB },
70 { IID_Hidd_X11BitMap, &HiddX11BitMapAB },
71 { IID_Hidd_Sync , &HiddSyncAttrBase },
72 { IID_Hidd_PixFmt , &HiddPixFmtAttrBase },
73 { IID_Hidd_Gfx , &HiddGfxAttrBase },
74 { NULL , NULL }
78 static VOID cleanupx11stuff(struct x11_staticdata *xsd);
79 static BOOL initx11stuff(struct x11_staticdata *xsd);
81 /****************************************************************************************/
83 OOP_Object *X11Cl__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
85 struct TagItem pftags[] =
87 { aHidd_PixFmt_RedShift , 0 }, /* 0 */
88 { aHidd_PixFmt_GreenShift , 0 }, /* 1 */
89 { aHidd_PixFmt_BlueShift , 0 }, /* 2 */
90 { aHidd_PixFmt_AlphaShift , 0 }, /* 3 */
91 { aHidd_PixFmt_RedMask , 0 }, /* 4 */
92 { aHidd_PixFmt_GreenMask , 0 }, /* 5 */
93 { aHidd_PixFmt_BlueMask , 0 }, /* 6 */
94 { aHidd_PixFmt_AlphaMask , 0 }, /* 7 */
95 { aHidd_PixFmt_ColorModel , 0 }, /* 8 */
96 { aHidd_PixFmt_Depth , 0 }, /* 9 */
97 { aHidd_PixFmt_BytesPerPixel, 0 }, /* 10 */
98 { aHidd_PixFmt_BitsPerPixel , 0 }, /* 11 */
99 { aHidd_PixFmt_StdPixFmt , 0 }, /* 12 */
100 { aHidd_PixFmt_CLUTShift , 0 }, /* 13 */
101 { aHidd_PixFmt_CLUTMask , 0 }, /* 14 */
102 { aHidd_PixFmt_BitMapType , 0 }, /* 15 */
103 { TAG_DONE , 0UL }
106 struct TagItem tags_160_160[] =
108 { aHidd_Sync_HDisp , 160 },
109 { aHidd_Sync_VDisp , 160 },
110 { aHidd_Sync_Description, (IPTR)"X11:160x160" },
111 { TAG_DONE , 0UL }
114 struct TagItem tags_240_320[] =
116 { aHidd_Sync_HDisp , 240 },
117 { aHidd_Sync_VDisp , 320 },
118 { aHidd_Sync_Description, (IPTR)"X11:240x320" },
119 { TAG_DONE , 0UL }
122 struct TagItem tags_320_240[] =
124 { aHidd_Sync_HDisp , 320 },
125 { aHidd_Sync_VDisp , 240 },
126 { aHidd_Sync_Description, (IPTR)"X11:320x240" },
127 { TAG_DONE , 0UL }
130 struct TagItem tags_512_384[] =
132 { aHidd_Sync_HDisp , 512 },
133 { aHidd_Sync_VDisp , 384 },
134 { aHidd_Sync_Description, (IPTR)"X11:512x384" },
135 { TAG_DONE , 0UL }
138 struct TagItem tags_640_480[] =
140 { aHidd_Sync_HDisp , 640 },
141 { aHidd_Sync_VDisp , 480 },
142 { aHidd_Sync_Description, (IPTR)"X11:640x480" },
143 { TAG_DONE , 0UL }
146 struct TagItem tags_800_600[] =
148 { aHidd_Sync_HDisp , 800 },
149 { aHidd_Sync_VDisp , 600 },
150 { aHidd_Sync_Description, (IPTR)"X11:800x600" },
151 { TAG_DONE , 0UL }
154 struct TagItem tags_1024_768[] =
156 { aHidd_Sync_HDisp , 1024 },
157 { aHidd_Sync_VDisp , 768 },
158 { aHidd_Sync_Description, (IPTR)"X11:1024x768" },
159 { TAG_DONE , 0UL }
162 struct TagItem tags_1152_864[] =
164 { aHidd_Sync_HDisp , 1152 },
165 { aHidd_Sync_VDisp , 864 },
166 { aHidd_Sync_Description, (IPTR)"X11:1152x864" },
167 { TAG_DONE , 0UL }
170 struct TagItem tags_1280_960[] =
172 { aHidd_Sync_HDisp , 1280 },
173 { aHidd_Sync_VDisp , 960 },
174 { aHidd_Sync_Description, (IPTR)"X11:1280x960" },
175 { TAG_DONE , 0UL }
178 struct TagItem tags_1280_1024[] =
180 { aHidd_Sync_HDisp , 1280 },
181 { aHidd_Sync_VDisp , 1024 },
182 { aHidd_Sync_Description, (IPTR)"X11:1280x1024" },
183 { TAG_DONE , 0UL }
186 struct TagItem tags_1600_1200[] =
188 { aHidd_Sync_HDisp , 1600 },
189 { aHidd_Sync_VDisp , 1200 },
190 { aHidd_Sync_Description, (IPTR)"X11:1600x1200" },
191 { TAG_DONE , 0UL }
194 struct TagItem mode_tags[] =
196 { aHidd_Gfx_PixFmtTags , (IPTR)pftags },
198 /* Default values for the sync attributes */
199 { aHidd_Sync_PixelClock , 100000000 }, /* Oh boy, this X11 pixelclock is fast ;-) */
200 { aHidd_Sync_LeftMargin , 0 },
201 { aHidd_Sync_RightMargin, 0 },
202 { aHidd_Sync_HSyncLength, 0 },
203 { aHidd_Sync_UpperMargin, 0 },
204 { aHidd_Sync_LowerMargin, 0 },
205 { aHidd_Sync_VSyncLength, 0 },
207 /* The different syncmodes. The default attribute values above
208 will be applied to each of these. Note that
209 you can alter the defaults between the tags bewlow
211 { aHidd_Gfx_SyncTags , (IPTR)tags_160_160 },
212 { aHidd_Gfx_SyncTags , (IPTR)tags_240_320 },
213 { aHidd_Gfx_SyncTags , (IPTR)tags_320_240 },
214 { aHidd_Gfx_SyncTags , (IPTR)tags_512_384 },
215 { aHidd_Gfx_SyncTags , (IPTR)tags_640_480 },
216 { aHidd_Gfx_SyncTags , (IPTR)tags_800_600 },
217 { aHidd_Gfx_SyncTags , (IPTR)tags_1024_768 },
218 { aHidd_Gfx_SyncTags , (IPTR)tags_1152_864 },
219 { aHidd_Gfx_SyncTags , (IPTR)tags_1280_960 },
220 { aHidd_Gfx_SyncTags , (IPTR)tags_1280_1024 },
221 { aHidd_Gfx_SyncTags , (IPTR)tags_1600_1200 },
222 { TAG_DONE , 0UL }
225 struct TagItem mytags[] =
227 { aHidd_Gfx_ModeTags , (IPTR)mode_tags },
228 { TAG_MORE , (IPTR)msg->attrList }
230 struct pRoot_New mymsg = { msg->mID, mytags };
232 EnterFunc(bug("X11Gfx::New()\n"));
234 /* Do GfxHidd initalization here */
235 if (!initx11stuff(XSD(cl)))
237 kprintf("!!! initx11stuff() FAILED IN X11Gfx::New() !!!\n");
238 ReturnPtr("X11Gfx::New()", OOP_Object *, NULL);
241 /* Register gfxmodes */
242 pftags[0].ti_Data = XSD(cl)->red_shift;
243 pftags[1].ti_Data = XSD(cl)->green_shift;
244 pftags[2].ti_Data = XSD(cl)->blue_shift;
245 pftags[3].ti_Data = 0;
247 pftags[4].ti_Data = XSD(cl)->vi.red_mask;
248 pftags[5].ti_Data = XSD(cl)->vi.green_mask;
249 pftags[6].ti_Data = XSD(cl)->vi.blue_mask;
250 pftags[7].ti_Data = 0x00000000;
252 if (XSD(cl)->vi.class == TrueColor)
254 pftags[8].ti_Data = vHidd_ColorModel_TrueColor;
256 else if (XSD(cl)->vi.class == PseudoColor)
258 pftags[8].ti_Data = vHidd_ColorModel_Palette;
259 pftags[13].ti_Data = XSD(cl)->clut_shift;
260 pftags[14].ti_Data = XSD(cl)->clut_mask;
262 else
264 kprintf("!!! UNHANDLED COLOR MODEL IN X11Gfx:New(): %d !!!\n", XSD(cl)->vi.class);
265 cleanupx11stuff(XSD(cl));
266 ReturnPtr("X11Gfx::New", OOP_Object *, NULL);
269 pftags[9].ti_Data = XSD(cl)->depth;
270 pftags[10].ti_Data = XSD(cl)->bytes_per_pixel;
271 pftags[11].ti_Data = XSD(cl)->depth;
272 pftags[12].ti_Data = vHidd_StdPixFmt_Native;
274 #warning Do better than this
276 /* We assume chunky */
277 pftags[15].ti_Data = vHidd_BitMapType_Chunky;
279 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)&mymsg);
280 if (NULL != o)
282 XColor bg, fg;
283 struct gfx_data *data = OOP_INST_DATA(cl, o);
285 LOCK_X11
286 data->display = XSD(cl)->display;
287 data->screen = DefaultScreen( data->display );
288 data->depth = DisplayPlanes( data->display, data->screen );
289 data->colmap = DefaultColormap( data->display, data->screen );
290 /* Create cursor */
291 data->cursor = XCALL(XCreateFontCursor, data->display, XC_top_left_arrow);
293 fg.pixel = BlackPixel(data->display, data->screen);
294 fg.red = 0x0000; fg.green = 0x0000; fg.blue = 0x0000;
295 fg.flags = (DoRed | DoGreen | DoBlue);
296 bg.pixel = WhitePixel(data->display, data->screen);
297 bg.red = 0xFFFF; bg.green = 0xFFFF; bg.blue = 0xFFFF;
298 bg.flags = (DoRed | DoGreen | DoBlue);
300 XCALL(XRecolorCursor, data->display, data->cursor, &fg, &bg);
302 switch(DoesBackingStore(ScreenOfDisplay(data->display, data->screen)))
304 case WhenMapped:
305 case Always:
306 break;
308 case NotUseful:
309 bug("\n"
310 "+----------------------------------------------------------|\n"
311 "| Your X Server seems to have backing store disabled! |\n"
312 "| =================================================== |\n"
313 "| |\n"
314 "| If possible you should try to switch it on, otherwise |\n"
315 "| AROS will have problems with it's display. When AROS |\n"
316 "| X window is hidden by other X windows, or is dragged |\n"
317 "| off screen, then the gfx in those parts will get lost, |\n"
318 "| unless backing store support is enabled. |\n"
319 "| |\n"
320 "| In case your X11 Server is XFree 4.x then switching on |\n"
321 "| backingstore support can be done by starting the X11 |\n"
322 "| server with something like \"startx -- +bs\". Depending |\n"
323 "| on what gfxcard driver you use it might also be possible |\n"
324 "| to turn it on by adding |\n"
325 "| |\n"
326 "| Option \"Backingstore\" |\n"
327 "| |\n"
328 "| to the Device Section of your XFree86 config file, which |\n"
329 "| usually is \"/etc/X11/XF86Config\". |\n"
330 "+----------------------------------------------------------+\n"
331 "\n");
332 break;
336 UNLOCK_X11
338 D(bug("X11Gfx::New(): Got object from super\n"));
340 data->display = XSD(cl)->display;
343 ReturnPtr("X11Gfx::New", OOP_Object *, o);
346 /********** GfxHidd::Dispose() ******************************/
347 VOID X11Cl__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
349 struct gfx_data *data;
351 EnterFunc(bug("X11Gfx::Dispose(o=%p)\n", o));
353 data = OOP_INST_DATA(cl, o);
354 cleanupx11stuff(XSD(cl));
356 D(bug("X11Gfx::Dispose: calling super\n"));
357 OOP_DoSuperMethod(cl, o, msg);
359 ReturnVoid("X11Gfx::Dispose");
362 /****************************************************************************************/
364 OOP_Object *X11Cl__Hidd_Gfx__NewBitMap(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_NewBitMap *msg)
366 BOOL displayable, framebuffer;
367 struct pHidd_Gfx_NewBitMap p;
368 OOP_Object *newbm;
369 IPTR drawable;
371 struct gfx_data *data;
372 struct TagItem tags[] =
374 { aHidd_X11Gfx_SysDisplay , (IPTR) NULL }, /* 0 */
375 { aHidd_X11Gfx_SysScreen , 0UL }, /* 1 */
376 { aHidd_X11Gfx_SysCursor , 0UL }, /* 2 */
377 { aHidd_X11Gfx_ColorMap , 0UL }, /* 3 */
378 { aHidd_X11Gfx_VisualClass , 0UL }, /* 4 */
379 { TAG_IGNORE , 0UL }, /* 5 */
380 { TAG_MORE , (IPTR) NULL } /* 6 */
383 EnterFunc(bug("X11Gfx::NewBitMap()\n"));
385 data = OOP_INST_DATA(cl, o);
387 tags[0].ti_Data = (IPTR)data->display;
388 tags[1].ti_Data = data->screen;
389 tags[2].ti_Data = (IPTR)data->cursor;
390 tags[3].ti_Data = data->colmap;
391 tags[4].ti_Data = XSD(cl)->vi.class;
392 tags[6].ti_Data = (IPTR)msg->attrList;
394 /* Displayable bitmap ? */
395 displayable = GetTagData(aHidd_BitMap_Displayable, FALSE, msg->attrList);
396 framebuffer = GetTagData(aHidd_BitMap_FrameBuffer, FALSE, msg->attrList);
398 if (framebuffer)
400 tags[5].ti_Tag = aHidd_BitMap_ClassPtr;
401 tags[5].ti_Data = (IPTR)XSD(cl)->onbmclass;
403 else if (displayable)
405 tags[5].ti_Tag = aHidd_BitMap_ClassPtr;
406 tags[5].ti_Data = (IPTR)XSD(cl)->offbmclass;
408 else
410 /* When do we create an x11 offscreen bitmap ?
411 - For 1-plane bitmaps.
412 - Bitmaps that have a friend that is an X11 bitmap
413 and there is no standard pixfmt supplied
414 - If the user supplied a modeid.
416 OOP_Object *friend;
417 BOOL usex11 = FALSE;
418 HIDDT_StdPixFmt stdpf;
420 friend = (OOP_Object *)GetTagData(aHidd_BitMap_Friend, 0, msg->attrList);
421 stdpf = (HIDDT_StdPixFmt)GetTagData(aHidd_BitMap_StdPixFmt, vHidd_StdPixFmt_Unknown, msg->attrList);
423 if (NULL != friend)
425 if (vHidd_StdPixFmt_Unknown == stdpf)
427 Drawable d;
429 /* Is the friend ann X11 bitmap ? */
430 d = (Drawable)OOP_GetAttr(friend, aHidd_X11BitMap_Drawable, (IPTR *)&d);
431 if (0 != d)
433 usex11 = TRUE;
438 if (!usex11)
440 if (vHidd_StdPixFmt_Plane == stdpf)
442 usex11 = TRUE;
444 else
446 HIDDT_ModeID modeid;
448 modeid = (HIDDT_ModeID)GetTagData(aHidd_BitMap_ModeID, vHidd_ModeID_Invalid, msg->attrList);
450 if (vHidd_ModeID_Invalid != modeid)
452 usex11 = TRUE;
457 if (usex11)
459 tags[5].ti_Tag = aHidd_BitMap_ClassPtr;
460 tags[5].ti_Data = (IPTR)XSD(cl)->offbmclass;
463 else
465 /* Let the superclass allocate if it is a standard pixelformat thus do nothing */
467 kprintf("x11 hidd: Could not create offscreen bitmap for supplied attrs! Superclass hopefully can.\n");
469 // *((ULONG *)0) = 0;
473 /* !!! IMPORTANT !!! */
475 p.mID = msg->mID;
476 p.attrList = tags;
478 newbm = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)&p);
480 if (NULL != newbm && framebuffer)
482 OOP_GetAttr(newbm, aHidd_X11BitMap_Drawable, &drawable);
483 data->fbwin = (Window)drawable;
484 #if ADJUST_XWIN_SIZE
485 OOP_GetAttr(newbm, aHidd_X11BitMap_MasterWindow, &drawable);
486 data->masterwin = (Window)drawable;
487 #endif
490 ReturnPtr("X11Gfx::NewBitMap", OOP_Object *, newbm);
493 /****************************************************************************************/
495 VOID X11Cl__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
497 struct gfx_data *data = OOP_INST_DATA(cl, o);
498 ULONG idx;
500 if (IS_X11GFX_ATTR(msg->attrID, idx))
502 switch (idx)
504 case aoHidd_X11Gfx_SysDisplay:
505 *msg->storage = (IPTR)data->display;
506 break;
508 case aoHidd_X11Gfx_SysScreen:
509 *msg->storage = (IPTR)data->screen;
510 break;
512 default:
513 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
514 break;
517 else if (IS_GFX_ATTR(msg->attrID, idx))
519 switch (idx)
521 case aoHidd_Gfx_IsWindowed:
522 *msg->storage = (IPTR)TRUE;
523 break;
525 case aoHidd_Gfx_SupportsHWCursor:
526 #if X11SOFTMOUSE
527 *msg->storage = (IPTR)FALSE;
528 #else
529 *msg->storage = (IPTR)TRUE;
530 #endif
531 break;
533 default:
534 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
535 break;
538 else
540 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
543 return;
546 /****************************************************************************************/
548 OOP_Object *X11Cl__Hidd_Gfx__Show(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_Show *msg)
550 OOP_Object *fb = 0;
551 IPTR width, height, modeid;
552 OOP_Object *pf, *sync;
553 struct gfx_data *data;
555 data = OOP_INST_DATA(cl, o);
557 if (!msg->bitMap)
559 return (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
562 OOP_GetAttr(msg->bitMap, aHidd_BitMap_ModeID, &modeid);
563 if ( HIDD_Gfx_GetMode(o, (HIDDT_ModeID)modeid, &sync, &pf))
565 struct MsgPort *port;
567 #if 1
568 OOP_GetAttr(msg->bitMap, aHidd_BitMap_Width, &width);
569 OOP_GetAttr(msg->bitMap, aHidd_BitMap_Height, &height);
570 #else
571 OOP_GetAttr(sync, aHidd_Sync_HDisp, &width);
572 OOP_GetAttr(sync, aHidd_Sync_VDisp, &height);
573 #endif
575 #if ADJUST_XWIN_SIZE
576 /* Send resize message to the x11 task */
577 port = CreateMsgPort();
578 if (NULL != port)
580 struct notify_msg *nmsg;
582 nmsg = AllocMem(sizeof (*nmsg), MEMF_PUBLIC);
583 if (NULL != nmsg)
585 nmsg->notify_type = NOTY_RESIZEWINDOW;
586 nmsg->xdisplay = data->display;
587 nmsg->xwindow = data->fbwin;
588 nmsg->masterxwindow = data->masterwin;
589 nmsg->width = width;
590 nmsg->height = height;
591 nmsg->execmsg.mn_ReplyPort = port;
593 PutMsg(XSD(cl)->x11task_notify_port, (struct Message *)nmsg);
595 WaitPort(port);
596 FreeMem(nmsg, sizeof (*nmsg));
597 #endif
599 fb = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
600 #if ADJUST_XWIN_SIZE
602 DeleteMsgPort(port);
605 #endif
608 return fb;
611 /****************************************************************************************/
613 VOID X11Cl__Hidd_Gfx__CopyBox(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CopyBox *msg)
615 ULONG mode;
616 Drawable src = 0, dest = 0;
617 struct gfx_data *data;
618 struct bitmap_data *bmdata;
620 data = OOP_INST_DATA(cl, o);
622 mode = GC_DRMD(msg->gc);
624 OOP_GetAttr(msg->src, aHidd_X11BitMap_Drawable, (IPTR *)&src);
625 OOP_GetAttr(msg->dest, aHidd_X11BitMap_Drawable, (IPTR *)&dest);
627 if (0 == dest || 0 == src)
629 /* The destination object is no X11 bitmap, onscreen nor offscreen.
630 Let the superclass do the copying in a more general way
632 OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
634 return;
637 LOCK_X11
639 /* This may seem ugly, but we know nobody has subclassed
640 the x11 class, since it's private
642 bmdata = OOP_INST_DATA(XSD(cl)->onbmclass, msg->src);
644 XCALL(XSetFunction, data->display, bmdata->gc, mode);
646 XCALL(XCopyArea, data->display
647 , src /* src */
648 , dest /* dest */
649 , bmdata->gc
650 , msg->srcX
651 , msg->srcY
652 , msg->width
653 , msg->height
654 , msg->destX
655 , msg->destY
658 XFLUSH(data->display);
660 UNLOCK_X11
664 /****************************************************************************************/
666 BOOL X11Cl__Hidd_Gfx__SetCursorShape(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
668 /* Dummy implementation */
669 return TRUE;
672 /****************************************************************************************/
674 BOOL X11Cl__Hidd_Gfx__SetCursorPos(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
676 /* Dummy implementation */
677 return TRUE;
680 /****************************************************************************************/
682 VOID X11Cl__Hidd_Gfx__SetCursorVisible(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
684 /* Dummy implementation */
685 return;
688 /****************************************************************************************/
690 static ULONG mask_to_shift(ULONG mask)
692 ULONG i;
694 for (i = 32; mask; i --)
696 mask >>= 1;
699 if (mask == 32)
701 i = 0;
704 return i;
707 /****************************************************************************************/
709 #undef XSD
710 #define XSD(cl) xsd
713 Inits sysdisplay, sysscreen, colormap, etc.. */
714 static BOOL initx11stuff(struct x11_staticdata *xsd)
716 /* XColor fg, bg; */
717 BOOL ok = TRUE;
718 XVisualInfo template;
719 XVisualInfo *visinfo;
720 int template_mask;
721 int numvisuals;
722 XImage *testimage;
725 EnterFunc(bug("initx11stuff()\n"));
727 LOCK_X11
729 /* Get some info on the display */
730 template.visualid = XCALL(XVisualIDFromVisual, DefaultVisual(xsd->display, DefaultScreen(xsd->display)));
731 template_mask = VisualIDMask;
733 visinfo = XCALL(XGetVisualInfo, xsd->display, template_mask, &template, &numvisuals);
735 if (numvisuals > 1)
737 kprintf("!!! GOT MORE THAN ONE VISUAL FROM X !!!\n");
738 // CCALL(raise, SIGSTOP);
741 if (NULL == visinfo)
743 kprintf("!!! COULD NOT GET X VISUAL INFO !!!\n");
744 CCALL(raise, SIGSTOP);
746 ok = FALSE;
748 else
750 /* Store the visual info structure */
752 memcpy(&xsd->vi, visinfo, sizeof (XVisualInfo));
754 XCALL(XFree, visinfo);
756 visinfo = &xsd->vi;
758 /* We only support TrueColor for now */
760 switch (visinfo->class)
762 case TrueColor:
763 /* Get the pixel masks */
764 xsd->red_shift = mask_to_shift(xsd->vi.red_mask);
765 xsd->green_shift = mask_to_shift(xsd->vi.green_mask);
766 xsd->blue_shift = mask_to_shift(xsd->vi.blue_mask);
767 break;
769 case PseudoColor:
770 /* stegerg */
771 xsd->vi.red_mask = ((1 << xsd->vi.bits_per_rgb) - 1) << (xsd->vi.bits_per_rgb * 2);
772 xsd->vi.green_mask = ((1 << xsd->vi.bits_per_rgb) - 1) << (xsd->vi.bits_per_rgb * 1);
773 xsd->vi.blue_mask = ((1 << xsd->vi.bits_per_rgb) - 1);
774 xsd->red_shift = mask_to_shift(xsd->vi.red_mask);
775 xsd->green_shift = mask_to_shift(xsd->vi.green_mask);
776 xsd->blue_shift = mask_to_shift(xsd->vi.blue_mask);
777 /* end stegerg */
778 break;
780 default:
781 kprintf("!!! GFX HIDD only supports truecolor and pseudocolor diplays for now !!!\n");
782 CCALL(raise, SIGSTOP);
785 xsd->depth = 0;
787 /* stegerg: based on xwininfo source */
790 XWindowAttributes win_attributes;
792 if (!XCALL(XGetWindowAttributes, xsd->display,
793 RootWindow(xsd->display, DefaultScreen(xsd->display)),
794 &win_attributes))
796 kprintf("!!! X11gfx could not get bits per pixel\n");
797 CCALL(raise, SIGSTOP);
799 xsd->depth = win_attributes.depth;
800 kprintf("\n");
801 kprintf("DisplayPlanes = %d\n", DisplayPlanes(xsd->display, DefaultScreen(xsd->display)));
802 kprintf("DefaultDepth = %d\n", DefaultDepth(xsd->display, DefaultScreen(xsd->display)));
804 kprintf("\n\n BITS PER PIXEL = %d \n\n\n", xsd->depth);
807 /* Create a dummy X image to get bits per pixel */
808 testimage = XCALL(XGetImage, xsd->display, RootWindow(xsd->display,
809 DefaultScreen(xsd->display)), 0, 0, 1, 1,
810 AllPlanes, ZPixmap);
812 if (NULL != testimage)
814 xsd->bytes_per_pixel = (testimage->bits_per_pixel + 7) >> 3;
815 XDestroyImage(testimage);
817 else
819 kprintf("!!! X11gfx could not get bits per pixel\n");
820 CCALL(raise, SIGSTOP);
823 if (PseudoColor == xsd->vi.class)
825 xsd->clut_mask = (1L << xsd->depth) - 1;
826 xsd->clut_shift = 0;
830 /* Create a dummy window for pixmaps */
832 xsd->dummy_window_for_creating_pixmaps = XCALL(XCreateSimpleWindow, xsd->display,
833 DefaultRootWindow(xsd->display),
834 0, 0, 100, 100,
836 BlackPixel(xsd->display, DefaultScreen(xsd->display)),
837 BlackPixel(xsd->display, DefaultScreen(xsd->display)));
838 if (0 == xsd->dummy_window_for_creating_pixmaps)
840 ok = FALSE;
843 #if USE_XSHM
844 /* Do we have Xshm support ? */
845 xsd->xshm_info = init_shared_mem(xsd->display);
847 if (NULL == xsd->xshm_info)
849 /* ok = FALSE; */
850 kprintf("INITIALIZATION OF XSHM FAILED !!\n");
852 else
854 InitSemaphore(&xsd->shm_sema);
855 xsd->use_xshm = TRUE;
857 #endif
860 UNLOCK_X11
862 ReturnBool("initx11stuff", ok);
866 /****************************************************************************************/
868 static VOID cleanupx11stuff(struct x11_staticdata *xsd)
870 LOCK_X11
872 /* Do nothing for now */
873 if (0 != xsd->dummy_window_for_creating_pixmaps)
875 XCALL(XDestroyWindow, xsd->display, xsd->dummy_window_for_creating_pixmaps);
878 #if USE_XSHM
879 cleanup_shared_mem(xsd->display, xsd->xshm_info);
880 #endif
882 UNLOCK_X11
885 /****************************************************************************************/
887 #define xsd (&LIBBASE->xsd)
889 /****************************************************************************************/
891 static int x11gfx_init(LIBBASETYPEPTR LIBBASE)
893 return OOP_ObtainAttrBases(attrbases);
896 /****************************************************************************************/
898 static int x11gfx_expunge(LIBBASETYPEPTR LIBBASE)
900 OOP_ReleaseAttrBases(attrbases);
901 return TRUE;
904 /****************************************************************************************/
906 ADD2INITLIB(x11gfx_init, 0);
907 ADD2EXPUNGELIB(x11gfx_expunge, 0);
909 /****************************************************************************************/