2 Copyright © 1995-2014, The AROS Development Team. All rights reserved.
5 Desc: X11 gfx HIDD for AROS.
11 #define __OOP_NOATTRBASES__
19 #include <X11/cursorfont.h>
20 #include <X11/Xutil.h>
25 #include <exec/libraries.h>
26 #include <exec/types.h>
27 #include <exec/resident.h>
28 #include <exec/memory.h>
29 #include <aros/libcall.h>
30 #include <proto/exec.h>
31 #include <proto/oop.h>
32 #include <proto/utility.h>
35 #include <hidd/hidd.h>
36 #include <hidd/graphics.h>
38 #include <aros/symbolsets.h>
40 #include "bitmap_class.h"
41 #include "x11gfx_intern.h"
44 #include LC_LIBDEFS_FILE
46 #define XFLUSH(x) XCALL(XFlush, x)
49 /****************************************************************************************/
51 #define IS_X11GFX_ATTR(attr, idx) ( ( (idx) = (attr) - HiddX11GfxAB) < num_Hidd_X11BitMap_Attrs)
55 /* Some attrbases needed as global vars.
56 These are write-once read-many */
58 OOP_AttrBase HiddBitMapAttrBase
;
59 OOP_AttrBase HiddX11BitMapAB
;
60 OOP_AttrBase HiddSyncAttrBase
;
61 OOP_AttrBase HiddPixFmtAttrBase
;
62 OOP_AttrBase HiddGfxAttrBase
;
63 OOP_AttrBase HiddAttrBase
;
65 static const struct OOP_ABDescr attrbases
[] =
67 { IID_Hidd_BitMap
, &HiddBitMapAttrBase
},
68 { IID_Hidd_X11BitMap
, &HiddX11BitMapAB
},
69 { IID_Hidd_Sync
, &HiddSyncAttrBase
},
70 { IID_Hidd_PixFmt
, &HiddPixFmtAttrBase
},
71 { IID_Hidd_Gfx
, &HiddGfxAttrBase
},
72 { IID_Hidd
, &HiddAttrBase
},
76 static VOID
cleanupx11stuff(struct x11_staticdata
*xsd
);
77 static BOOL
initx11stuff(struct x11_staticdata
*xsd
);
79 /****************************************************************************************/
81 OOP_Object
*X11Cl__Root__New(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_New
*msg
)
83 struct TagItem pftags
[] =
85 { aHidd_PixFmt_RedShift
, 0 }, /* 0 */
86 { aHidd_PixFmt_GreenShift
, 0 }, /* 1 */
87 { aHidd_PixFmt_BlueShift
, 0 }, /* 2 */
88 { aHidd_PixFmt_AlphaShift
, 0 }, /* 3 */
89 { aHidd_PixFmt_RedMask
, 0 }, /* 4 */
90 { aHidd_PixFmt_GreenMask
, 0 }, /* 5 */
91 { aHidd_PixFmt_BlueMask
, 0 }, /* 6 */
92 { aHidd_PixFmt_AlphaMask
, 0 }, /* 7 */
93 { aHidd_PixFmt_ColorModel
, 0 }, /* 8 */
94 { aHidd_PixFmt_Depth
, 0 }, /* 9 */
95 { aHidd_PixFmt_BytesPerPixel
, 0 }, /* 10 */
96 { aHidd_PixFmt_BitsPerPixel
, 0 }, /* 11 */
97 { aHidd_PixFmt_StdPixFmt
, 0 }, /* 12 */
98 { aHidd_PixFmt_CLUTShift
, 0 }, /* 13 */
99 { aHidd_PixFmt_CLUTMask
, 0 }, /* 14 */
100 { aHidd_PixFmt_BitMapType
, 0 }, /* 15 */
104 struct TagItem tags_160_160
[] =
106 { aHidd_Sync_HDisp
, 160 },
107 { aHidd_Sync_VDisp
, 160 },
108 { aHidd_Sync_Description
, (IPTR
)"X11:160x160" },
112 struct TagItem tags_240_320
[] =
114 { aHidd_Sync_HDisp
, 240 },
115 { aHidd_Sync_VDisp
, 320 },
116 { aHidd_Sync_Description
, (IPTR
)"X11:240x320" },
120 struct TagItem tags_320_240
[] =
122 { aHidd_Sync_HDisp
, 320 },
123 { aHidd_Sync_VDisp
, 240 },
124 { aHidd_Sync_Description
, (IPTR
)"X11:320x240" },
128 struct TagItem tags_512_384
[] =
130 { aHidd_Sync_HDisp
, 512 },
131 { aHidd_Sync_VDisp
, 384 },
132 { aHidd_Sync_Description
, (IPTR
)"X11:512x384" },
136 struct TagItem tags_640_480
[] =
138 { aHidd_Sync_HDisp
, 640 },
139 { aHidd_Sync_VDisp
, 480 },
140 { aHidd_Sync_Description
, (IPTR
)"X11:640x480" },
144 struct TagItem tags_800_600
[] =
146 { aHidd_Sync_HDisp
, 800 },
147 { aHidd_Sync_VDisp
, 600 },
148 { aHidd_Sync_Description
, (IPTR
)"X11:800x600" },
152 struct TagItem tags_1024_768
[] =
154 { aHidd_Sync_HDisp
, 1024 },
155 { aHidd_Sync_VDisp
, 768 },
156 { aHidd_Sync_Description
, (IPTR
)"X11:1024x768" },
160 struct TagItem tags_1152_864
[] =
162 { aHidd_Sync_HDisp
, 1152 },
163 { aHidd_Sync_VDisp
, 864 },
164 { aHidd_Sync_Description
, (IPTR
)"X11:1152x864" },
168 struct TagItem tags_1280_800
[] =
170 { aHidd_Sync_HDisp
, 1280 },
171 { aHidd_Sync_VDisp
, 800 },
172 { aHidd_Sync_Description
, (IPTR
)"X11:1280x800" },
176 struct TagItem tags_1280_960
[] =
178 { aHidd_Sync_HDisp
, 1280 },
179 { aHidd_Sync_VDisp
, 960 },
180 { aHidd_Sync_Description
, (IPTR
)"X11:1280x960" },
184 struct TagItem tags_1280_1024
[] =
186 { aHidd_Sync_HDisp
, 1280 },
187 { aHidd_Sync_VDisp
, 1024 },
188 { aHidd_Sync_Description
, (IPTR
)"X11:1280x1024" },
192 struct TagItem tags_1400_1050
[] =
194 { aHidd_Sync_HDisp
, 1400 },
195 { aHidd_Sync_VDisp
, 1050 },
196 { aHidd_Sync_Description
, (IPTR
)"X11:1400x1050" },
200 struct TagItem tags_1600_1200
[] =
202 { aHidd_Sync_HDisp
, 1600 },
203 { aHidd_Sync_VDisp
, 1200 },
204 { aHidd_Sync_Description
, (IPTR
)"X11:1600x1200" },
208 struct TagItem tags_1680_1050
[] =
210 { aHidd_Sync_HDisp
, 1680 },
211 { aHidd_Sync_VDisp
, 1050 },
212 { aHidd_Sync_Description
, (IPTR
)"X11:1680x1050" },
216 struct TagItem tags_1920_1080
[] =
218 { aHidd_Sync_HDisp
, 1920 },
219 { aHidd_Sync_VDisp
, 1080 },
220 { aHidd_Sync_Description
, (IPTR
)"X11:1920x1080" },
224 struct TagItem tags_1920_1200
[] =
226 { aHidd_Sync_HDisp
, 1920 },
227 { aHidd_Sync_VDisp
, 1200 },
228 { aHidd_Sync_Description
, (IPTR
)"X11:1920x1200" },
232 /* Default display modes. Used on displays which do not support Free86-VidModeExtension */
233 struct TagItem default_mode_tags
[] =
235 { aHidd_Gfx_PixFmtTags
, (IPTR
)pftags
},
236 { aHidd_Gfx_SyncTags
, (IPTR
)tags_160_160
},
237 { aHidd_Gfx_SyncTags
, (IPTR
)tags_240_320
},
238 { aHidd_Gfx_SyncTags
, (IPTR
)tags_320_240
},
239 { aHidd_Gfx_SyncTags
, (IPTR
)tags_512_384
},
240 { aHidd_Gfx_SyncTags
, (IPTR
)tags_640_480
},
241 { aHidd_Gfx_SyncTags
, (IPTR
)tags_800_600
},
242 { aHidd_Gfx_SyncTags
, (IPTR
)tags_1024_768
},
243 { aHidd_Gfx_SyncTags
, (IPTR
)tags_1152_864
},
244 { aHidd_Gfx_SyncTags
, (IPTR
)tags_1280_800
},
245 { aHidd_Gfx_SyncTags
, (IPTR
)tags_1280_960
},
246 { aHidd_Gfx_SyncTags
, (IPTR
)tags_1280_1024
},
247 { aHidd_Gfx_SyncTags
, (IPTR
)tags_1400_1050
},
248 { aHidd_Gfx_SyncTags
, (IPTR
)tags_1600_1200
},
249 { aHidd_Gfx_SyncTags
, (IPTR
)tags_1680_1050
},
250 { aHidd_Gfx_SyncTags
, (IPTR
)tags_1920_1080
},
251 { aHidd_Gfx_SyncTags
, (IPTR
)tags_1920_1200
},
255 struct TagItem
*mode_tags
= NULL
;
257 struct TagItem mytags
[] =
259 { aHidd_Gfx_ModeTags
, (IPTR
)default_mode_tags
},
260 { aHidd_Name
, (IPTR
)"x11_1.monitor" },
261 { aHidd_HardwareName
, (IPTR
)"X Window system" },
262 { aHidd_ProducerName
, (IPTR
)"X.Org Foundation" },
263 { TAG_MORE
, (IPTR
)msg
->attrList
}
266 struct pRoot_New mymsg
= { msg
->mID
, mytags
};
268 struct TagItem
*resolution
= NULL
;
269 XF86VidModeModeInfo
** modes
= NULL
;
270 static int modeNum
= 0;
276 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
278 /* Do GfxHidd initalization here */
279 if (!initx11stuff(XSD(cl
)))
281 D(bug("[X11Gfx] %s: initialisation failed!\n", __PRETTY_FUNCTION__
));
285 /* Get supported X11 resolution from RandR resources */
287 disp
= XCALL(XOpenDisplay
, NULL
);
288 screen
= XCALL(XDefaultScreen
, disp
);
289 // rootwin = XCALL(XRootWindow, disp, screen);
291 if (!(XSD(cl
)->options
& OPTION_FORCESTDMODES
))
293 XVMCALL(XF86VidModeGetAllModeLines
, disp
, screen
, &modeNum
, &modes
);
294 D(bug("[X11Gfx] Found %u modes, table at 0x%P\n", modeNum
, modes
));
298 /* Got XF86VidMode data, use it */
299 if ((resolution
= AllocMem(modeNum
* sizeof(struct TagItem
) * 4, MEMF_PUBLIC
)) == NULL
)
301 D(bug("[X11] failed to allocate memory for %d modes: %d !!!\n", modeNum
, XSD(cl
)->vi
.class));
303 XCALL(XCloseDisplay
, disp
);
304 cleanupx11stuff(XSD(cl
));
309 for(i
= 0; i
< modeNum
; i
++)
315 /* avoid duplicated resolution */
316 for(j
= 0; j
< realmode
; j
++)
318 if(resolution
[j
* 4].ti_Data
== modes
[i
]->hdisplay
&& resolution
[j
* 4 + 1].ti_Data
== modes
[i
]->vdisplay
)
319 { /* Found a matching resolution. Don't insert ! */
326 resolution
[realmode
* 4 + 0].ti_Tag
= aHidd_Sync_HDisp
;
327 resolution
[realmode
* 4 + 0].ti_Data
= modes
[i
]->hdisplay
;
329 resolution
[realmode
* 4 + 1].ti_Tag
= aHidd_Sync_VDisp
;
330 resolution
[realmode
* 4 + 1].ti_Data
= modes
[i
]->vdisplay
;
332 resolution
[realmode
* 4 + 2].ti_Tag
= aHidd_Sync_Description
;
333 resolution
[realmode
* 4 + 2].ti_Data
= (IPTR
)"X11: %hx%v";
335 resolution
[realmode
* 4 + 3].ti_Tag
= TAG_DONE
;
336 resolution
[realmode
* 4 + 3].ti_Data
= 0UL;
342 if((mode_tags
= AllocMem(sizeof(struct TagItem
) * (realmode
+ 2), MEMF_PUBLIC
)) == NULL
)
344 D(bug("[X11] failed to allocate memory for mode tag's: %d !!!\n", XSD(cl
)->vi
.class));
346 FreeMem(resolution
, modeNum
* sizeof(struct TagItem
) * 4);
347 XCALL(XCloseDisplay
, disp
);
348 cleanupx11stuff(XSD(cl
));
353 mode_tags
[0].ti_Tag
= aHidd_Gfx_PixFmtTags
;
354 mode_tags
[0].ti_Data
= (IPTR
)pftags
;
356 /* The different screenmode from XF86VMODE */
357 for(i
=0; i
< realmode
; i
++)
359 mode_tags
[1 + i
].ti_Tag
= aHidd_Gfx_SyncTags
;
360 mode_tags
[1 + i
].ti_Data
= (IPTR
)(resolution
+ i
*4);
363 mode_tags
[1 + i
].ti_Tag
= TAG_DONE
;
364 mode_tags
[1 + i
].ti_Data
= 0UL;
366 /* Use our new mode tags instead of default ones */
367 mytags
[0].ti_Data
= (IPTR
)mode_tags
;
371 /* Register gfxmodes */
372 pftags
[0].ti_Data
= XSD(cl
)->red_shift
;
373 pftags
[1].ti_Data
= XSD(cl
)->green_shift
;
374 pftags
[2].ti_Data
= XSD(cl
)->blue_shift
;
375 pftags
[3].ti_Data
= 0;
377 pftags
[4].ti_Data
= XSD(cl
)->vi
.red_mask
;
378 pftags
[5].ti_Data
= XSD(cl
)->vi
.green_mask
;
379 pftags
[6].ti_Data
= XSD(cl
)->vi
.blue_mask
;
380 pftags
[7].ti_Data
= 0x00000000;
382 if (XSD(cl
)->vi
.class == TrueColor
)
384 pftags
[8].ti_Data
= vHidd_ColorModel_TrueColor
;
386 else if (XSD(cl
)->vi
.class == PseudoColor
)
388 pftags
[8].ti_Data
= vHidd_ColorModel_Palette
;
389 pftags
[13].ti_Data
= XSD(cl
)->clut_shift
;
390 pftags
[14].ti_Data
= XSD(cl
)->clut_mask
;
394 D(bug("[X11Gfx] unsupported color model: %d\n", XSD(cl
)->vi
.class));
397 FreeMem(resolution
, modeNum
* sizeof(struct TagItem
) * 4);
398 FreeMem(mode_tags
, sizeof(struct TagItem
) * (realmode
+ 2));
400 XCALL(XCloseDisplay
, disp
);
401 cleanupx11stuff(XSD(cl
));
406 pftags
[9].ti_Data
= XSD(cl
)->depth
;
407 pftags
[10].ti_Data
= XSD(cl
)->bytes_per_pixel
;
408 pftags
[11].ti_Data
= XSD(cl
)->depth
;
409 pftags
[12].ti_Data
= vHidd_StdPixFmt_Native
;
411 /* FIXME: Do better than this */
413 /* We assume chunky */
414 pftags
[15].ti_Data
= vHidd_BitMapType_Chunky
;
416 D(bug("Calling super method\n"));
418 o
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)&mymsg
);
420 D(bug("Super method returned\n"));
422 FreeMem(resolution
, modeNum
* sizeof(struct TagItem
) * 4);
423 FreeMem(mode_tags
, sizeof(struct TagItem
) * (realmode
+ 2));
424 XCALL(XCloseDisplay
, disp
);
429 struct gfx_data
*data
= OOP_INST_DATA(cl
, o
);
432 data
->display
= XSD(cl
)->display
;
433 data
->screen
= DefaultScreen( data
->display
);
434 data
->depth
= DisplayPlanes( data
->display
, data
->screen
);
435 data
->colmap
= DefaultColormap( data
->display
, data
->screen
);
436 D(bug("x11_func.XCreateFontCursor(%x), display(%x)\n", x11_func
.XCreateFontCursor
, data
->display
));
438 data
->cursor
= XCALL(XCreateFontCursor
, data
->display
, XC_top_left_arrow
);
440 fg
.pixel
= BlackPixel(data
->display
, data
->screen
);
441 fg
.red
= 0x0000; fg
.green
= 0x0000; fg
.blue
= 0x0000;
442 fg
.flags
= (DoRed
| DoGreen
| DoBlue
);
443 bg
.pixel
= WhitePixel(data
->display
, data
->screen
);
444 bg
.red
= 0xFFFF; bg
.green
= 0xFFFF; bg
.blue
= 0xFFFF;
445 bg
.flags
= (DoRed
| DoGreen
| DoBlue
);
447 XCALL(XRecolorCursor
, data
->display
, data
->cursor
, &fg
, &bg
);
449 if (XSD(cl
)->options
& OPTION_BACKINGSTORE
)
451 switch(DoesBackingStore(ScreenOfDisplay(data
->display
, data
->screen
)))
459 "+----------------------------------------------------------+\n"
460 "| Your X Server seems to have backing store disabled! |\n"
461 "| =================================================== |\n"
463 "| If possible you should try to switch it on, otherwise |\n"
464 "| AROS will have problems with its display. When the AROS |\n"
465 "| X window is hidden by other X windows, or is dragged |\n"
466 "| off screen, then the graphics in those parts will get |\n"
467 "| lost, unless backing store support is enabled. |\n"
469 "| In case your X11 Server is XFree 4.x then switching on |\n"
470 "| backingstore support can be done by starting the X11 |\n"
471 "| server with something like \"startx -- +bs\". Depending |\n"
472 "| on what X driver you use it might also be possible |\n"
473 "| to turn it on by adding |\n"
475 "| Option \"Backingstore\" |\n"
477 "| to the Device Section of your X Window config file, |\n"
478 "| which usually is \"/etc/X11/xorg.conf\" |\n"
479 "| or \"/etc/X11/XFree86Config\" |\n"
480 "+----------------------------------------------------------+\n"
488 D(bug("[X11Gfx] Got object from super\n"));
490 data
->display
= XSD(cl
)->display
;
493 ReturnPtr("X11Gfx::New", OOP_Object
*, o
);
496 /********** GfxHidd::Dispose() ******************************/
497 VOID
X11Cl__Root__Dispose(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
499 D(bug("[X11Gfx] %s(0x%p)\n", __PRETTY_FUNCTION__
, o
));
501 cleanupx11stuff(XSD(cl
));
503 D(bug("X11Gfx::Dispose: calling super\n"));
504 OOP_DoSuperMethod(cl
, o
, msg
);
508 /****************************************************************************************/
510 OOP_Object
*X11Cl__Hidd_Gfx__NewBitMap(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_Gfx_NewBitMap
*msg
)
512 struct pHidd_Gfx_NewBitMap p
;
515 struct gfx_data
*data
;
516 struct TagItem tags
[] =
518 { aHidd_X11BitMap_SysDisplay
, 0 }, /* 0 */
519 { aHidd_X11BitMap_SysScreen
, 0 }, /* 1 */
520 { aHidd_X11BitMap_SysCursor
, 0 }, /* 2 */
521 { aHidd_X11BitMap_ColorMap
, 0 }, /* 3 */
522 { aHidd_X11BitMap_VisualClass
, 0 }, /* 4 */
523 { TAG_IGNORE
, 0 }, /* 5 */
524 { TAG_MORE
, 0 } /* 6 */
527 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
529 data
= OOP_INST_DATA(cl
, o
);
531 tags
[0].ti_Data
= (IPTR
)data
->display
;
532 tags
[1].ti_Data
= data
->screen
;
533 tags
[2].ti_Data
= (IPTR
)data
->cursor
;
534 tags
[3].ti_Data
= data
->colmap
;
535 tags
[4].ti_Data
= XSD(cl
)->vi
.class;
536 tags
[6].ti_Data
= (IPTR
)msg
->attrList
;
538 /* Displayable bitmap ? */
539 modeid
= GetTagData(aHidd_BitMap_ModeID
, vHidd_ModeID_Invalid
, msg
->attrList
);
541 if (modeid
!= vHidd_ModeID_Invalid
)
543 /* ModeID supplied, it's for sure X11 bitmap */
544 tags
[5].ti_Tag
= aHidd_BitMap_ClassPtr
;
545 tags
[5].ti_Data
= (IPTR
)XSD(cl
)->bmclass
;
548 /* !!! IMPORTANT !!! */
552 newbm
= (OOP_Object
*)OOP_DoSuperMethod(cl
, o
, (OOP_Msg
)&p
);
554 ReturnPtr("X11Gfx::NewBitMap", OOP_Object
*, newbm
);
557 /****************************************************************************************/
559 VOID
X11Cl__Root__Get(OOP_Class
*cl
, OOP_Object
*o
, struct pRoot_Get
*msg
)
563 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
565 if (IS_GFX_ATTR(msg
->attrID
, idx
))
569 case aoHidd_Gfx_IsWindowed
:
570 *msg
->storage
= TRUE
;
573 case aoHidd_Gfx_HWSpriteTypes
:
577 *msg
->storage
= vHidd_SpriteType_DirectColor
;
581 case aoHidd_Gfx_DriverName
:
582 *msg
->storage
= (IPTR
) "X11";
586 OOP_DoSuperMethod(cl
, o
, (OOP_Msg
) msg
);
589 /****************************************************************************************/
591 VOID
X11Cl__Root__Set(OOP_Class
*cl
, OOP_Object
*obj
, struct pRoot_Set
*msg
)
593 struct TagItem
*tag
, *tstate
;
595 struct x11_staticdata
*data
= XSD(cl
);
597 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
599 tstate
= msg
->attrList
;
600 while ((tag
= NextTagItem(&tstate
)))
602 if (IS_GFX_ATTR(tag
->ti_Tag
, idx
))
606 case aoHidd_Gfx_ActiveCallBack
:
607 data
->activecallback
= (void *) tag
->ti_Data
;
610 case aoHidd_Gfx_ActiveCallBackData
:
611 data
->callbackdata
= (void *) tag
->ti_Data
;
616 OOP_DoSuperMethod(cl
, obj
, &msg
->mID
);
619 /****************************************************************************************/
621 VOID
X11Cl__Hidd_Gfx__CopyBox(OOP_Class
*cl
, OOP_Object
*o
, struct pHidd_Gfx_CopyBox
*msg
)
624 Drawable src
= 0, dest
= 0;
627 struct gfx_data
*data
= OOP_INST_DATA(cl
, o
);
629 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
631 mode
= GC_DRMD(msg
->gc
);
633 OOP_GetAttr(msg
->src
, aHidd_X11BitMap_Drawable
, (IPTR
*) &src
);
634 OOP_GetAttr(msg
->dest
, aHidd_X11BitMap_Drawable
, (IPTR
*) &dest
);
636 if (0 == dest
|| 0 == src
)
639 * One of objects is not an X11 bitmap.
640 * Let the superclass do the copying in a more general way
642 OOP_DoSuperMethod(cl
, o
, &msg
->mID
);
646 OOP_GetAttr(msg
->src
, aHidd_X11BitMap_GC
, (IPTR
*) &gc
);
650 XCALL(XSetFunction
, data
->display
, gc
, mode
);
652 data
->display
, src
, dest
, gc
, msg
->srcX
, msg
->srcY
, msg
->width
, msg
->height
, msg
->destX
, msg
->destY
);
657 /****************************************************************************************/
659 BOOL
X11Cl__Hidd_Gfx__SetCursorShape(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
661 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
663 /* Dummy implementation */
667 /****************************************************************************************/
669 BOOL
X11Cl__Hidd_Gfx__SetCursorPos(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
671 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
673 /* Dummy implementation */
677 /****************************************************************************************/
679 VOID
X11Cl__Hidd_Gfx__SetCursorVisible(OOP_Class
*cl
, OOP_Object
*o
, OOP_Msg msg
)
681 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
683 /* Dummy implementation */
687 /****************************************************************************************/
689 static ULONG
mask_to_shift(ULONG mask
)
693 for (i
= 32; mask
; i
--)
706 /****************************************************************************************/
712 Inits sysdisplay, sysscreen, colormap, etc.. */
713 static BOOL
initx11stuff(struct x11_staticdata
*xsd
)
717 XVisualInfo
template;
718 XVisualInfo
*visinfo
;
723 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
730 /* Get some info on the display */
731 template.visualid
= XCALL(XVisualIDFromVisual
, DefaultVisual(xsd
->display
, DefaultScreen(xsd
->display
)));
732 template_mask
= VisualIDMask
;
734 visinfo
= XCALL(XGetVisualInfo
, xsd
->display
, template_mask
, &template, &numvisuals
);
738 D(bug("[X11Gfx] %s: got %d visualinfo from X\n", __PRETTY_FUNCTION__
, numvisuals
));
740 // CCALL(raise, SIGSTOP);
745 D(bug("[X11Gfx] %s: no visualinfo available!\n", __PRETTY_FUNCTION__
));
747 CCALL(raise
, SIGSTOP
);
753 /* Store the visual info structure */
755 memcpy(&xsd
->vi
, visinfo
, sizeof(XVisualInfo
));
757 XCALL(XFree
, visinfo
);
761 /* We only support TrueColor for now */
763 switch (visinfo
->class)
766 /* Get the pixel masks */
767 xsd
->red_shift
= mask_to_shift(xsd
->vi
.red_mask
);
768 xsd
->green_shift
= mask_to_shift(xsd
->vi
.green_mask
);
769 xsd
->blue_shift
= mask_to_shift(xsd
->vi
.blue_mask
);
774 xsd
->vi
.red_mask
= ((1 << xsd
->vi
.bits_per_rgb
) - 1) << (xsd
->vi
.bits_per_rgb
* 2);
775 xsd
->vi
.green_mask
= ((1 << xsd
->vi
.bits_per_rgb
) - 1) << (xsd
->vi
.bits_per_rgb
* 1);
776 xsd
->vi
.blue_mask
= ((1 << xsd
->vi
.bits_per_rgb
) - 1);
777 xsd
->red_shift
= mask_to_shift(xsd
->vi
.red_mask
);
778 xsd
->green_shift
= mask_to_shift(xsd
->vi
.green_mask
);
779 xsd
->blue_shift
= mask_to_shift(xsd
->vi
.blue_mask
);
784 D(bug("[X11Gfx] %s: unsupported display mode!\n", __PRETTY_FUNCTION__
));
786 CCALL(raise
, SIGSTOP
);
791 /* stegerg: based on xwininfo source */
794 XWindowAttributes win_attributes
;
796 if (!XCALL(XGetWindowAttributes
, xsd
->display
,
797 RootWindow(xsd
->display
, DefaultScreen(xsd
->display
)),
800 D(bug("[X11Gfx] %s: failed to obtain bits per pixel\n", __PRETTY_FUNCTION__
));
802 CCALL(raise
, SIGSTOP
);
804 xsd
->depth
= win_attributes
.depth
;
807 bug("[X11Gfx] %s: Display Depth = %dbit (Default = %dbit)\n", __PRETTY_FUNCTION__
, DisplayPlanes(xsd
->display
, DefaultScreen(xsd
->display
)), DefaultDepth(xsd
->display
, DefaultScreen(xsd
->display
)));
809 bug("[X11Gfx] %s: %d Bits per Pixel\n", __PRETTY_FUNCTION__
, xsd
->depth
);
814 /* Create a dummy X image to get bits per pixel */
815 testimage
= XCALL(XGetImage
, xsd
->display
, RootWindow(xsd
->display
,
816 DefaultScreen(xsd
->display
)), 0, 0, 1, 1,
819 if (NULL
!= testimage
)
821 xsd
->bytes_per_pixel
= (testimage
->bits_per_pixel
+ 7) >> 3;
822 XDestroyImage(testimage
);
826 D(bug("[X11Gfx] %s: failed to create query image\n", __PRETTY_FUNCTION__
));
827 CCALL(raise
, SIGSTOP
);
830 if (PseudoColor
== xsd
->vi
.class)
832 xsd
->clut_mask
= (1L << xsd
->depth
) - 1;
837 /* Create a dummy window for pixmaps */
838 xsd
->dummy_window_for_creating_pixmaps
= XCALL(XCreateSimpleWindow
, xsd
->display
,
839 DefaultRootWindow(xsd
->display
),
842 BlackPixel(xsd
->display
, DefaultScreen(xsd
->display
)),
843 BlackPixel(xsd
->display
, DefaultScreen(xsd
->display
)));
844 if (0 == xsd
->dummy_window_for_creating_pixmaps
)
846 D(bug("[X11Gfx] %s: failed to create pixmap window\n", __PRETTY_FUNCTION__
));
852 char *displayname
= XCALL(XDisplayName
, NULL
);
854 if ((strncmp(displayname
, ":", 1) == 0) ||
855 (strncmp(displayname
, "unix:", 5) == 0))
857 /* Display is local, not remote. XSHM is possible */
859 /* Do we have Xshm support ? */
860 xsd
->xshm_info
= init_shared_mem(xsd
->display
);
862 if (NULL
== xsd
->xshm_info
)
865 D(bug("INITIALIZATION OF XSHM FAILED !!\n"));
871 InitSemaphore(&xsd
->shm_sema
);
872 xsd
->use_xshm
= TRUE
;
874 XCALL(XQueryExtension
, xsd
->display
, "MIT-SHM", &xshm_major
, &a
, &b
);
882 ReturnBool("initx11stuff", ok
);
886 /****************************************************************************************/
888 static VOID
cleanupx11stuff(struct x11_staticdata
*xsd
)
890 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
894 /* Do nothing for now */
895 if (0 != xsd
->dummy_window_for_creating_pixmaps
)
897 XCALL(XDestroyWindow
, xsd
->display
, xsd
->dummy_window_for_creating_pixmaps
);
901 cleanup_shared_mem(xsd
->display
, xsd
->xshm_info
);
907 /****************************************************************************************/
909 //#define xsd (&LIBBASE->xsd)
910 /****************************************************************************************/
912 static int x11gfx_init(LIBBASETYPEPTR LIBBASE
)
914 D(bug("[X11Gfx] %s: initialising semaphore @ 0x%p\n", __PRETTY_FUNCTION__
, &LIBBASE
->xsd
.sema
));
916 InitSemaphore(&LIBBASE
->xsd
.sema
);
918 return OOP_ObtainAttrBases(attrbases
);
921 /****************************************************************************************/
923 static int x11gfx_expunge(LIBBASETYPEPTR LIBBASE
)
925 D(bug("[X11Gfx] %s()\n", __PRETTY_FUNCTION__
));
927 OOP_ReleaseAttrBases(attrbases
);
931 /****************************************************************************************/
933 ADD2INITLIB(x11gfx_init
, 0);
934 ADD2EXPUNGELIB(x11gfx_expunge
, 0);
936 /****************************************************************************************/