rename the directory
[AROS.git] / arch / all-hosted / hidd / x11 / x11gfx.c
blob75d26eef4aae48335d21ed874debd4e4c13d1bec
1 /*
2 Copyright © 1995-2016, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: X11 gfx HIDD for AROS.
6 Lang: English.
7 */
9 #include "x11_debug.h"
11 #define __OOP_NOATTRBASES__
13 #include <proto/utility.h>
15 #include <X11/cursorfont.h>
16 #include <signal.h>
18 #include "x11_types.h"
19 #include LC_LIBDEFS_FILE
20 #include "x11_hostlib.h"
21 #include "xshm.h"
23 #define XFLUSH(x) XCALL(XFlush, x)
25 /****************************************************************************************/
27 #define IS_X11GFX_ATTR(attr, idx) ( ( (idx) = (attr) - HiddX11GfxAB) < num_Hidd_X11BitMap_Attrs)
29 int xshm_major;
31 /* Some attrbases needed as global vars.
32 These are write-once read-many */
34 OOP_AttrBase HiddBitMapAttrBase;
35 OOP_AttrBase HiddX11BitMapAB;
36 OOP_AttrBase HiddSyncAttrBase;
37 OOP_AttrBase HiddPixFmtAttrBase;
38 OOP_AttrBase HiddGfxAttrBase;
39 OOP_AttrBase HiddAttrBase;
41 static const struct OOP_ABDescr attrbases[] =
43 { IID_Hidd_BitMap , &HiddBitMapAttrBase },
44 { IID_Hidd_BitMap_X11 , &HiddX11BitMapAB },
45 { IID_Hidd_Sync , &HiddSyncAttrBase },
46 { IID_Hidd_PixFmt , &HiddPixFmtAttrBase },
47 { IID_Hidd_Gfx , &HiddGfxAttrBase },
48 { IID_Hidd , &HiddAttrBase },
49 { NULL , NULL }
52 static VOID cleanupx11stuff(struct x11_staticdata *xsd);
53 static BOOL initx11stuff(struct x11_staticdata *xsd);
55 /****************************************************************************************/
57 OOP_Object *X11Cl__Root__New(OOP_Class *cl, OOP_Object *o, struct pRoot_New *msg)
59 struct TagItem pftags[] =
61 { aHidd_PixFmt_RedShift , 0 }, /* 0 */
62 { aHidd_PixFmt_GreenShift , 0 }, /* 1 */
63 { aHidd_PixFmt_BlueShift , 0 }, /* 2 */
64 { aHidd_PixFmt_AlphaShift , 0 }, /* 3 */
65 { aHidd_PixFmt_RedMask , 0 }, /* 4 */
66 { aHidd_PixFmt_GreenMask , 0 }, /* 5 */
67 { aHidd_PixFmt_BlueMask , 0 }, /* 6 */
68 { aHidd_PixFmt_AlphaMask , 0 }, /* 7 */
69 { aHidd_PixFmt_ColorModel , 0 }, /* 8 */
70 { aHidd_PixFmt_Depth , 0 }, /* 9 */
71 { aHidd_PixFmt_BytesPerPixel, 0 }, /* 10 */
72 { aHidd_PixFmt_BitsPerPixel , 0 }, /* 11 */
73 { aHidd_PixFmt_StdPixFmt , 0 }, /* 12 */
74 { aHidd_PixFmt_CLUTShift , 0 }, /* 13 */
75 { aHidd_PixFmt_CLUTMask , 0 }, /* 14 */
76 { aHidd_PixFmt_BitMapType , 0 }, /* 15 */
77 { TAG_DONE , 0UL }
80 struct TagItem tags_160_160[] =
82 { aHidd_Sync_HDisp , 160 },
83 { aHidd_Sync_VDisp , 160 },
84 { aHidd_Sync_Description, (IPTR)"X11:160x160" },
85 { TAG_DONE , 0UL }
88 struct TagItem tags_240_320[] =
90 { aHidd_Sync_HDisp , 240 },
91 { aHidd_Sync_VDisp , 320 },
92 { aHidd_Sync_Description, (IPTR)"X11:240x320" },
93 { TAG_DONE , 0UL }
96 struct TagItem tags_320_240[] =
98 { aHidd_Sync_HDisp , 320 },
99 { aHidd_Sync_VDisp , 240 },
100 { aHidd_Sync_Description, (IPTR)"X11:320x240" },
101 { TAG_DONE , 0UL }
104 struct TagItem tags_512_384[] =
106 { aHidd_Sync_HDisp , 512 },
107 { aHidd_Sync_VDisp , 384 },
108 { aHidd_Sync_Description, (IPTR)"X11:512x384" },
109 { TAG_DONE , 0UL }
112 struct TagItem tags_640_480[] =
114 { aHidd_Sync_HDisp , 640 },
115 { aHidd_Sync_VDisp , 480 },
116 { aHidd_Sync_Description, (IPTR)"X11:640x480" },
117 { TAG_DONE , 0UL }
120 struct TagItem tags_800_600[] =
122 { aHidd_Sync_HDisp , 800 },
123 { aHidd_Sync_VDisp , 600 },
124 { aHidd_Sync_Description, (IPTR)"X11:800x600" },
125 { TAG_DONE , 0UL }
128 struct TagItem tags_1024_768[] =
130 { aHidd_Sync_HDisp , 1024 },
131 { aHidd_Sync_VDisp , 768 },
132 { aHidd_Sync_Description, (IPTR)"X11:1024x768" },
133 { TAG_DONE , 0UL }
136 struct TagItem tags_1152_864[] =
138 { aHidd_Sync_HDisp , 1152 },
139 { aHidd_Sync_VDisp , 864 },
140 { aHidd_Sync_Description, (IPTR)"X11:1152x864" },
141 { TAG_DONE , 0UL }
144 struct TagItem tags_1280_800[] =
146 { aHidd_Sync_HDisp , 1280 },
147 { aHidd_Sync_VDisp , 800 },
148 { aHidd_Sync_Description, (IPTR)"X11:1280x800" },
149 { TAG_DONE , 0UL }
152 struct TagItem tags_1280_960[] =
154 { aHidd_Sync_HDisp , 1280 },
155 { aHidd_Sync_VDisp , 960 },
156 { aHidd_Sync_Description, (IPTR)"X11:1280x960" },
157 { TAG_DONE , 0UL }
160 struct TagItem tags_1280_1024[] =
162 { aHidd_Sync_HDisp , 1280 },
163 { aHidd_Sync_VDisp , 1024 },
164 { aHidd_Sync_Description, (IPTR)"X11:1280x1024" },
165 { TAG_DONE , 0UL }
168 struct TagItem tags_1400_1050[] =
170 { aHidd_Sync_HDisp , 1400 },
171 { aHidd_Sync_VDisp , 1050 },
172 { aHidd_Sync_Description, (IPTR)"X11:1400x1050" },
173 { TAG_DONE , 0UL }
176 struct TagItem tags_1600_1200[] =
178 { aHidd_Sync_HDisp , 1600 },
179 { aHidd_Sync_VDisp , 1200 },
180 { aHidd_Sync_Description, (IPTR)"X11:1600x1200" },
181 { TAG_DONE , 0UL }
184 struct TagItem tags_1680_1050[] =
186 { aHidd_Sync_HDisp , 1680 },
187 { aHidd_Sync_VDisp , 1050 },
188 { aHidd_Sync_Description, (IPTR)"X11:1680x1050" },
189 { TAG_DONE , 0UL }
192 struct TagItem tags_1920_1080[] =
194 { aHidd_Sync_HDisp , 1920 },
195 { aHidd_Sync_VDisp , 1080 },
196 { aHidd_Sync_Description, (IPTR)"X11:1920x1080" },
197 { TAG_DONE , 0UL }
200 struct TagItem tags_1920_1200[] =
202 { aHidd_Sync_HDisp , 1920 },
203 { aHidd_Sync_VDisp , 1200 },
204 { aHidd_Sync_Description, (IPTR)"X11:1920x1200" },
205 { TAG_DONE , 0UL }
208 /* Default display modes. Used on displays which do not support Free86-VidModeExtension */
209 struct TagItem default_mode_tags[] =
211 { aHidd_Gfx_PixFmtTags , (IPTR)pftags },
212 { aHidd_Gfx_SyncTags , (IPTR)tags_160_160 },
213 { aHidd_Gfx_SyncTags , (IPTR)tags_240_320 },
214 { aHidd_Gfx_SyncTags , (IPTR)tags_320_240 },
215 { aHidd_Gfx_SyncTags , (IPTR)tags_512_384 },
216 { aHidd_Gfx_SyncTags , (IPTR)tags_640_480 },
217 { aHidd_Gfx_SyncTags , (IPTR)tags_800_600 },
218 { aHidd_Gfx_SyncTags , (IPTR)tags_1024_768 },
219 { aHidd_Gfx_SyncTags , (IPTR)tags_1152_864 },
220 { aHidd_Gfx_SyncTags , (IPTR)tags_1280_800 },
221 { aHidd_Gfx_SyncTags , (IPTR)tags_1280_960 },
222 { aHidd_Gfx_SyncTags , (IPTR)tags_1280_1024 },
223 { aHidd_Gfx_SyncTags , (IPTR)tags_1400_1050 },
224 { aHidd_Gfx_SyncTags , (IPTR)tags_1600_1200 },
225 { aHidd_Gfx_SyncTags , (IPTR)tags_1680_1050 },
226 { aHidd_Gfx_SyncTags , (IPTR)tags_1920_1080 },
227 { aHidd_Gfx_SyncTags , (IPTR)tags_1920_1200 },
228 { TAG_DONE , 0UL }
231 struct TagItem *mode_tags = NULL;
233 struct TagItem mytags[] =
235 { aHidd_Gfx_ModeTags , (IPTR)default_mode_tags },
236 { aHidd_Name , (IPTR)"x11_1.monitor" },
237 { aHidd_HardwareName , (IPTR)"X Window system" },
238 { aHidd_ProducerName , (IPTR)"X.Org Foundation" },
239 { TAG_MORE , (IPTR)msg->attrList }
242 struct pRoot_New mymsg = { msg->mID, mytags };
244 struct TagItem *resolution = NULL;
245 XF86VidModeModeInfo** modes = NULL;
246 static int modeNum = 0;
247 ULONG realmode = 0;
249 ULONG i, screen;
250 Display *disp;
252 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__));
254 /* Do GfxHidd initalization here */
255 if (!initx11stuff(XSD(cl)))
257 D(bug("[X11Gfx] %s: initialisation failed!\n", __PRETTY_FUNCTION__));
258 return NULL;
261 /* Get supported X11 resolution from RandR resources */
263 disp = XCALL(XOpenDisplay, NULL);
264 screen = XCALL(XDefaultScreen, disp);
265 // rootwin = XCALL(XRootWindow, disp, screen);
267 if (!(XSD(cl)->options & OPTION_FORCESTDMODES))
269 XVMCALL(XF86VidModeGetAllModeLines, disp, screen, &modeNum, &modes);
270 D(bug("[X11Gfx] Found %u modes, table at 0x%P\n", modeNum, modes));
272 if (modeNum)
274 /* Got XF86VidMode data, use it */
275 if ((resolution = AllocMem(modeNum * sizeof(struct TagItem) * 4, MEMF_PUBLIC)) == NULL)
277 D(bug("[X11] failed to allocate memory for %d modes: %d !!!\n", modeNum, XSD(cl)->vi->class));
279 XCALL(XCloseDisplay, disp);
280 cleanupx11stuff(XSD(cl));
282 return NULL;
285 for(i = 0; i < modeNum; i++)
287 ULONG j;
288 BOOL insert;
289 insert = TRUE;
291 /* avoid duplicated resolution */
292 for(j = 0; j < realmode; j++)
294 if(resolution[j * 4].ti_Data == modes[i]->hdisplay && resolution[j * 4 + 1].ti_Data == modes[i]->vdisplay)
295 { /* Found a matching resolution. Don't insert ! */
296 insert = FALSE;
300 if(insert)
302 resolution[realmode * 4 + 0].ti_Tag = aHidd_Sync_HDisp;
303 resolution[realmode * 4 + 0].ti_Data = modes[i]->hdisplay;
305 resolution[realmode * 4 + 1].ti_Tag = aHidd_Sync_VDisp;
306 resolution[realmode * 4 + 1].ti_Data = modes[i]->vdisplay;
308 resolution[realmode * 4 + 2].ti_Tag = aHidd_Sync_Description;
309 resolution[realmode * 4 + 2].ti_Data = (IPTR)"X11: %hx%v";
311 resolution[realmode * 4 + 3].ti_Tag = TAG_DONE;
312 resolution[realmode * 4 + 3].ti_Data = 0UL;
314 realmode++;
318 if((mode_tags = AllocMem(sizeof(struct TagItem) * (realmode + 2), MEMF_PUBLIC)) == NULL)
320 D(bug("[X11] failed to allocate memory for mode tag's: %d !!!\n", XSD(cl)->vi->class));
322 FreeMem(resolution, modeNum * sizeof(struct TagItem) * 4);
323 XCALL(XCloseDisplay, disp);
324 cleanupx11stuff(XSD(cl));
326 return NULL;
329 mode_tags[0].ti_Tag = aHidd_Gfx_PixFmtTags;
330 mode_tags[0].ti_Data = (IPTR)pftags;
332 /* The different screenmode from XF86VMODE */
333 for(i=0; i < realmode; i++)
335 mode_tags[1 + i].ti_Tag = aHidd_Gfx_SyncTags;
336 mode_tags[1 + i].ti_Data = (IPTR)(resolution + i*4);
339 mode_tags[1 + i].ti_Tag = TAG_DONE;
340 mode_tags[1 + i].ti_Data = 0UL;
342 /* Use our new mode tags instead of default ones */
343 mytags[0].ti_Data = (IPTR)mode_tags;
347 /* Register gfxmodes */
348 pftags[0].ti_Data = XSD(cl)->red_shift;
349 pftags[1].ti_Data = XSD(cl)->green_shift;
350 pftags[2].ti_Data = XSD(cl)->blue_shift;
351 pftags[3].ti_Data = 0;
353 pftags[4].ti_Data = XSD(cl)->vi->red_mask;
354 pftags[5].ti_Data = XSD(cl)->vi->green_mask;
355 pftags[6].ti_Data = XSD(cl)->vi->blue_mask;
356 pftags[7].ti_Data = 0x00000000;
358 if (XSD(cl)->vi->class == TrueColor)
360 pftags[8].ti_Data = vHidd_ColorModel_TrueColor;
362 else if (XSD(cl)->vi->class == PseudoColor)
364 pftags[8].ti_Data = vHidd_ColorModel_Palette;
365 pftags[13].ti_Data = XSD(cl)->clut_shift;
366 pftags[14].ti_Data = XSD(cl)->clut_mask;
368 else
370 D(bug("[X11Gfx] unsupported color model: %d\n", XSD(cl)->vi->class));
371 if (resolution)
373 FreeMem(resolution, modeNum * sizeof(struct TagItem) * 4);
374 FreeMem(mode_tags, sizeof(struct TagItem) * (realmode + 2));
376 XCALL(XCloseDisplay, disp);
377 cleanupx11stuff(XSD(cl));
379 return NULL;
382 pftags[9].ti_Data = XSD(cl)->depth;
383 pftags[10].ti_Data = XSD(cl)->bytes_per_pixel;
384 pftags[11].ti_Data = XSD(cl)->depth;
385 pftags[12].ti_Data = vHidd_StdPixFmt_Native;
387 /* FIXME: Do better than this */
389 /* We assume chunky */
390 pftags[15].ti_Data = vHidd_BitMapType_Chunky;
392 D(bug("Calling super method\n"));
394 o = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)&mymsg);
396 D(bug("Super method returned\n"));
398 FreeMem(resolution, modeNum * sizeof(struct TagItem) * 4);
399 FreeMem(mode_tags, sizeof(struct TagItem) * (realmode + 2));
400 XCALL(XCloseDisplay, disp);
402 if (NULL != o)
404 XColor bg, fg;
405 struct gfx_data *data = OOP_INST_DATA(cl, o);
407 data->basebm = OOP_FindClass(CLID_Hidd_BitMap);
408 bug("[X11] BitMap class @ 0x%p\n", data->basebm);
410 LOCK_X11
411 data->display = XSD(cl)->display;
412 data->screen = DefaultScreen( data->display );
413 data->depth = DisplayPlanes( data->display, data->screen );
414 data->colmap = DefaultColormap( data->display, data->screen );
415 D(bug("x11_func.XCreateFontCursor(%x), display(%x)\n", x11_func.XCreateFontCursor, data->display));
416 /* Create cursor */
417 data->cursor = XCALL(XCreateFontCursor, data->display, XC_top_left_arrow);
419 fg.pixel = BlackPixel(data->display, data->screen);
420 fg.red = 0x0000; fg.green = 0x0000; fg.blue = 0x0000;
421 fg.flags = (DoRed | DoGreen | DoBlue);
422 bg.pixel = WhitePixel(data->display, data->screen);
423 bg.red = 0xFFFF; bg.green = 0xFFFF; bg.blue = 0xFFFF;
424 bg.flags = (DoRed | DoGreen | DoBlue);
426 XCALL(XRecolorCursor, data->display, data->cursor, &fg, &bg);
428 if (XSD(cl)->options & OPTION_BACKINGSTORE)
430 switch(DoesBackingStore(ScreenOfDisplay(data->display, data->screen)))
432 case WhenMapped:
433 case Always:
434 break;
436 case NotUseful:
437 bug("\n"
438 "+----------------------------------------------------------+\n"
439 "| Your X Server seems to have backing store disabled! |\n"
440 "| =================================================== |\n"
441 "| |\n"
442 "| If possible you should try to switch it on, otherwise |\n"
443 "| AROS will have problems with its display. When the AROS |\n"
444 "| X window is hidden by other X windows, or is dragged |\n"
445 "| off screen, then the graphics in those parts will get |\n"
446 "| lost, unless backing store support is enabled. |\n"
447 "| |\n"
448 "| In case your X11 Server is XFree 4.x then switching on |\n"
449 "| backingstore support can be done by starting the X11 |\n"
450 "| server with something like \"startx -- +bs\". Depending |\n"
451 "| on what X driver you use it might also be possible |\n"
452 "| to turn it on by adding |\n"
453 "| |\n"
454 "| Option \"Backingstore\" |\n"
455 "| |\n"
456 "| to the Device Section of your X Window config file, |\n"
457 "| which usually is \"/etc/X11/xorg.conf\" |\n"
458 "| or \"/etc/X11/XFree86Config\" |\n"
459 "+----------------------------------------------------------+\n"
460 "\n");
461 break;
465 UNLOCK_X11
467 D(bug("[X11Gfx] Got object from super\n"));
469 data->display = XSD(cl)->display;
472 ReturnPtr("X11Gfx::New", OOP_Object *, o);
475 /********** GfxHidd::Dispose() ******************************/
476 VOID X11Cl__Root__Dispose(OOP_Class *cl, OOP_Object *o, OOP_Msg msg)
478 D(bug("[X11Gfx] %s(0x%p)\n", __PRETTY_FUNCTION__, o));
480 cleanupx11stuff(XSD(cl));
482 D(bug("X11Gfx::Dispose: calling super\n"));
483 OOP_DoSuperMethod(cl, o, msg);
487 /****************************************************************************************/
489 OOP_Object *X11Cl__Hidd_Gfx__CreateObject(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CreateObject *msg)
491 struct gfx_data *data = OOP_INST_DATA(cl, o);
492 OOP_Object *object = NULL;
494 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__));
496 if (msg->cl == data->basebm)
498 struct pHidd_Gfx_CreateObject p;
499 HIDDT_ModeID modeid;
500 struct gfx_data *data;
501 struct TagItem tags[] =
503 { aHidd_X11BitMap_SysDisplay , 0 }, /* 0 */
504 { aHidd_X11BitMap_SysScreen , 0 }, /* 1 */
505 { aHidd_X11BitMap_SysCursor , 0 }, /* 2 */
506 { aHidd_X11BitMap_ColorMap , 0 }, /* 3 */
507 { aHidd_X11BitMap_VisualClass , 0 }, /* 4 */
508 { TAG_IGNORE , 0 }, /* 5 */
509 { TAG_MORE , 0 } /* 6 */
512 data = OOP_INST_DATA(cl, o);
514 tags[0].ti_Data = (IPTR)data->display;
515 tags[1].ti_Data = data->screen;
516 tags[2].ti_Data = (IPTR)data->cursor;
517 tags[3].ti_Data = data->colmap;
518 tags[4].ti_Data = XSD(cl)->vi->class;
519 tags[6].ti_Data = (IPTR)msg->attrList;
521 /* Displayable bitmap ? */
522 modeid = GetTagData(aHidd_BitMap_ModeID, vHidd_ModeID_Invalid, msg->attrList);
524 if (modeid != vHidd_ModeID_Invalid)
526 /* ModeID supplied, it's for sure X11 bitmap */
527 tags[5].ti_Tag = aHidd_BitMap_ClassPtr;
528 tags[5].ti_Data = (IPTR)XSD(cl)->bmclass;
531 p.mID = msg->mID;
532 p.cl = msg->cl;
533 p.attrList = tags;
535 object = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)&p);
537 else
538 object = (OOP_Object *)OOP_DoSuperMethod(cl, o, (OOP_Msg)msg);
540 ReturnPtr("X11Gfx::CreateObject", OOP_Object *, object);
543 /****************************************************************************************/
545 VOID X11Cl__Root__Get(OOP_Class *cl, OOP_Object *o, struct pRoot_Get *msg)
547 ULONG idx;
549 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__));
551 if (IS_GFX_ATTR(msg->attrID, idx))
553 switch (idx)
555 case aoHidd_Gfx_IsWindowed:
556 *msg->storage = TRUE;
557 return;
559 case aoHidd_Gfx_HWSpriteTypes:
560 #if X11SOFTMOUSE
561 *msg->storage = 0;
562 #else
563 *msg->storage = vHidd_SpriteType_DirectColor;
564 return;
566 case aoHidd_Gfx_SupportsHWCursor:
567 *msg->storage = TRUE;
568 #endif
569 return;
571 case aoHidd_Gfx_DriverName:
572 *msg->storage = (IPTR) "X11";
573 return;
576 OOP_DoSuperMethod(cl, o, (OOP_Msg) msg);
579 /****************************************************************************************/
581 VOID X11Cl__Root__Set(OOP_Class *cl, OOP_Object *obj, struct pRoot_Set *msg)
583 struct TagItem *tag, *tstate;
584 ULONG idx;
585 struct x11_staticdata *data = XSD(cl);
587 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__));
589 tstate = msg->attrList;
590 while ((tag = NextTagItem(&tstate)))
592 if (IS_GFX_ATTR(tag->ti_Tag, idx))
594 switch (idx)
596 case aoHidd_Gfx_ActiveCallBack:
597 data->activecallback = (void *) tag->ti_Data;
598 break;
600 case aoHidd_Gfx_ActiveCallBackData:
601 data->callbackdata = (void *) tag->ti_Data;
602 break;
606 OOP_DoSuperMethod(cl, obj, &msg->mID);
609 /****************************************************************************************/
611 VOID X11Cl__Hidd_Gfx__CopyBox(OOP_Class *cl, OOP_Object *o, struct pHidd_Gfx_CopyBox *msg)
613 ULONG mode;
614 Drawable src = 0, dest = 0;
615 GC gc = 0;
617 struct gfx_data *data = OOP_INST_DATA(cl, o);
619 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__));
621 mode = GC_DRMD(msg->gc);
623 OOP_GetAttr(msg->src, aHidd_X11BitMap_Drawable, (IPTR *) &src);
624 OOP_GetAttr(msg->dest, aHidd_X11BitMap_Drawable, (IPTR *) &dest);
626 if (0 == dest || 0 == src)
629 * One of objects is not an X11 bitmap.
630 * Let the superclass do the copying in a more general way
632 OOP_DoSuperMethod(cl, o, &msg->mID);
633 return;
636 OOP_GetAttr(msg->src, aHidd_X11BitMap_GC, (IPTR *) &gc);
638 HostLib_Lock();
640 XCALL(XSetFunction, data->display, gc, mode);
641 XCALL(XCopyArea,
642 data->display, src, dest, gc, msg->srcX, msg->srcY, msg->width, msg->height, msg->destX, msg->destY);
644 HostLib_Unlock();
647 /****************************************************************************************/
649 BOOL X11Cl__Hidd_Gfx__SetCursorShape(OOP_Class *cl, OOP_Object *o,
650 struct pHidd_Gfx_SetCursorShape *msg)
652 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__));
654 #if X11SOFTMOUSE
655 /* Dummy implementation */
656 return TRUE;
657 #else
658 BOOL success = TRUE;
659 IPTR width, height;
660 XcursorImage *image;
661 struct MsgPort *port;
662 struct notify_msg nmsg;
663 struct gfx_data *data = OOP_INST_DATA(cl, o);
665 /* Create an X11 cursor from the passed bitmap */
666 OOP_GetAttr(msg->shape, aHidd_BitMap_Width, &width);
667 OOP_GetAttr(msg->shape, aHidd_BitMap_Height, &height);
668 image = XCCALL(XcursorImageCreate, width, height);
670 HIDD_BM_GetImage(msg->shape, (UBYTE *)image->pixels, width * 4, 0, 0,
671 width, height, vHidd_StdPixFmt_BGRA32);
673 image->xhot = -msg->xoffset;
674 image->yhot = -msg->yoffset;
676 data->cursor = XCCALL(XcursorImageLoadCursor, data->display, image);
677 XCCALL(XcursorImageDestroy, image);
679 /* Tell the X11 task to change the pointer on all X windows */
680 port = CreateMsgPort();
681 if (port == NULL)
682 success = FALSE;
684 if (success)
686 nmsg.notify_type = NOTY_NEWCURSOR;
687 nmsg.xdisplay = data->display;
688 nmsg.xwindow = (Window)data->cursor;
689 nmsg.execmsg.mn_ReplyPort = port;
691 X11DoNotify(XSD(cl), &nmsg);
692 DeleteMsgPort(port);
695 return success;
696 #endif
699 /****************************************************************************************/
701 VOID X11Cl__Hidd_Gfx__SetCursorVisible(OOP_Class *cl, OOP_Object *o,
702 struct pHidd_Gfx_SetCursorVisible *msg)
704 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__));
706 #if X11SOFTMOUSE
707 /* Dummy implementation */
708 #else
709 BOOL success = TRUE;
710 struct MsgPort *port;
711 struct notify_msg nmsg;
712 struct gfx_data *data = OOP_INST_DATA(cl, o);
714 /* Tell the X11 task to change the pointer on all X windows */
715 port = CreateMsgPort();
716 if (port == NULL)
717 success = FALSE;
719 if (success)
721 nmsg.notify_type = NOTY_NEWCURSOR;
722 nmsg.xdisplay = data->display;
723 nmsg.xwindow = (Window) (msg->visible ? data->cursor : None);
724 nmsg.execmsg.mn_ReplyPort = port;
726 X11DoNotify(XSD(cl), &nmsg);
727 DeleteMsgPort(port);
729 #endif
731 return;
734 /****************************************************************************************/
736 static ULONG mask_to_shift(ULONG mask)
738 ULONG i;
740 for (i = 32; mask; i--)
742 mask >>= 1;
745 if (mask == 32)
747 i = 0;
750 return i;
753 /****************************************************************************************/
755 #undef XSD
756 #define XSD(cl) xsd
759 Inits sysdisplay, sysscreen, colormap, etc.. */
760 static BOOL initx11stuff(struct x11_staticdata *xsd)
762 /* XColor fg, bg; */
763 BOOL ok = TRUE;
764 XVisualInfo template;
765 XVisualInfo *visinfo;
766 int template_mask;
767 int numvisuals;
768 XImage *testimage;
770 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__));
772 if (!X11_Init(xsd))
773 return FALSE;
775 LOCK_X11
777 /* Get some info on the display */
778 template.visualid = XCALL(XVisualIDFromVisual, DefaultVisual(xsd->display, DefaultScreen(xsd->display)));
779 template_mask = VisualIDMask;
781 visinfo = XCALL(XGetVisualInfo, xsd->display, template_mask, &template, &numvisuals);
783 if (numvisuals > 1)
785 D(bug("[X11Gfx] %s: got %d visualinfo from X\n", __PRETTY_FUNCTION__, numvisuals));
787 // CCALL(raise, SIGSTOP);
790 if (NULL == visinfo)
792 D(bug("[X11Gfx] %s: no visualinfo available!\n", __PRETTY_FUNCTION__));
794 CCALL(raise, SIGSTOP);
796 ok = FALSE;
798 else
800 /* Store the visual info structure */
801 xsd->vi = AllocMem(sizeof(XVisualInfo), MEMF_ANY);
802 memcpy(xsd->vi, visinfo, sizeof(XVisualInfo));
804 XCALL(XFree, visinfo);
806 visinfo = xsd->vi;
808 /* We only support TrueColor for now */
810 switch (visinfo->class)
812 case TrueColor:
813 /* Get the pixel masks */
814 xsd->red_shift = mask_to_shift(xsd->vi->red_mask);
815 xsd->green_shift = mask_to_shift(xsd->vi->green_mask);
816 xsd->blue_shift = mask_to_shift(xsd->vi->blue_mask);
817 break;
819 case PseudoColor:
820 /* stegerg */
821 xsd->vi->red_mask = ((1 << xsd->vi->bits_per_rgb) - 1) << (xsd->vi->bits_per_rgb * 2);
822 xsd->vi->green_mask = ((1 << xsd->vi->bits_per_rgb) - 1) << (xsd->vi->bits_per_rgb * 1);
823 xsd->vi->blue_mask = ((1 << xsd->vi->bits_per_rgb) - 1);
824 xsd->red_shift = mask_to_shift(xsd->vi->red_mask);
825 xsd->green_shift = mask_to_shift(xsd->vi->green_mask);
826 xsd->blue_shift = mask_to_shift(xsd->vi->blue_mask);
827 /* end stegerg */
828 break;
830 default:
831 D(bug("[X11Gfx] %s: unsupported display mode!\n", __PRETTY_FUNCTION__));
833 CCALL(raise, SIGSTOP);
836 xsd->depth = 0;
838 /* stegerg: based on xwininfo source */
841 XWindowAttributes win_attributes;
843 if (!XCALL(XGetWindowAttributes, xsd->display,
844 RootWindow(xsd->display, DefaultScreen(xsd->display)),
845 &win_attributes))
847 D(bug("[X11Gfx] %s: failed to obtain bits per pixel\n", __PRETTY_FUNCTION__));
849 CCALL(raise, SIGSTOP);
851 xsd->depth = win_attributes.depth;
853 bug("\n");
854 bug("[X11Gfx] %s: Display Depth = %dbit (Default = %dbit)\n", __PRETTY_FUNCTION__, DisplayPlanes(xsd->display, DefaultScreen(xsd->display)), DefaultDepth(xsd->display, DefaultScreen(xsd->display)));
855 #if (0)
856 bug("[X11Gfx] %s: %d Bits per Pixel\n", __PRETTY_FUNCTION__, xsd->depth);
857 #endif
861 /* Create a dummy X image to get bits per pixel */
862 testimage = XCALL(XGetImage, xsd->display, RootWindow(xsd->display,
863 DefaultScreen(xsd->display)), 0, 0, 1, 1,
864 AllPlanes, ZPixmap);
866 if (NULL != testimage)
868 xsd->bytes_per_pixel = (testimage->bits_per_pixel + 7) >> 3;
869 XDestroyImage(testimage);
871 else
873 D(bug("[X11Gfx] %s: failed to create query image\n", __PRETTY_FUNCTION__));
874 CCALL(raise, SIGSTOP);
877 if (PseudoColor == xsd->vi->class)
879 xsd->clut_mask = (1L << xsd->depth) - 1;
880 xsd->clut_shift = 0;
884 /* Create a dummy window for pixmaps */
885 xsd->dummy_window_for_creating_pixmaps = XCALL(XCreateSimpleWindow, xsd->display,
886 DefaultRootWindow(xsd->display),
887 0, 0, 100, 100,
889 BlackPixel(xsd->display, DefaultScreen(xsd->display)),
890 BlackPixel(xsd->display, DefaultScreen(xsd->display)));
891 if (0 == xsd->dummy_window_for_creating_pixmaps)
893 D(bug("[X11Gfx] %s: failed to create pixmap window\n", __PRETTY_FUNCTION__));
894 ok = FALSE;
897 #if USE_XSHM
899 char *displayname = XCALL(XDisplayName, NULL);
901 if ((strncmp(displayname, ":", 1) == 0) ||
902 (strncmp(displayname, "unix:", 5) == 0))
904 /* Display is local, not remote. XSHM is possible */
906 /* Do we have Xshm support ? */
907 xsd->xshm_info = init_shared_mem(xsd->display);
909 if (NULL == xsd->xshm_info)
911 /* ok = FALSE; */
912 D(bug("INITIALIZATION OF XSHM FAILED !!\n"));
914 else
916 int a, b;
918 InitSemaphore(&xsd->shm_sema);
919 xsd->use_xshm = TRUE;
921 XCALL(XQueryExtension, xsd->display, "MIT-SHM", &xshm_major, &a, &b);
925 #endif
927 UNLOCK_X11
929 ReturnBool("initx11stuff", ok);
933 /****************************************************************************************/
935 static VOID cleanupx11stuff(struct x11_staticdata *xsd)
937 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__));
939 LOCK_X11
941 /* Do nothing for now */
942 if (0 != xsd->dummy_window_for_creating_pixmaps)
944 XCALL(XDestroyWindow, xsd->display, xsd->dummy_window_for_creating_pixmaps);
947 #if USE_XSHM
948 cleanup_shared_mem(xsd->display, xsd->xshm_info);
949 #endif
950 FreeMem(xsd->vi, sizeof(XVisualInfo));
951 xsd->vi = NULL;
953 UNLOCK_X11
956 /****************************************************************************************/
958 //#define xsd (&LIBBASE->xsd)
959 /****************************************************************************************/
961 static int x11gfx_init(LIBBASETYPEPTR LIBBASE)
963 D(bug("[X11Gfx] %s: initialising semaphore @ 0x%p\n", __PRETTY_FUNCTION__, &LIBBASE->xsd.sema));
965 InitSemaphore(&LIBBASE->xsd.sema);
967 return OOP_ObtainAttrBases(attrbases);
970 /****************************************************************************************/
972 static int x11gfx_expunge(LIBBASETYPEPTR LIBBASE)
974 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__));
976 OOP_ReleaseAttrBases(attrbases);
977 return TRUE;
980 /****************************************************************************************/
982 ADD2INITLIB(x11gfx_init, 0);
983 ADD2EXPUNGELIB(x11gfx_expunge, 0);
985 /****************************************************************************************/