1 #include <inttypes.h>
2 #include <X11/Xlib.h>
3 #include <X11/Xutil.h>
4 #include <GL/glx.h>
5 /* Linux headers don't work properly */
6 #define __USE_GNU
7 #include <dlfcn.h>
8 #undef __USE_GNU
9 
10 /* Current versions of Solaris don't expose the XF86 extensions,
11    although with the recent transition to Xorg this will probably
12    happen in an upcoming release */
13 #if !defined(__sun) && !defined(_HPUX)
14 #include <X11/extensions/xf86vmode.h>
15 #else
16 /* Need to provide stubs for these */
XF86VidModeGetGammaRampSize(Display * display,int screen,int * size)17 Bool XF86VidModeGetGammaRampSize(
18     Display *display,
19     int screen,
20     int* size)
21 {
22   return False;
23 }
24 
XF86VidModeGetGammaRamp(Display * display,int screen,int size,unsigned short * red_array,unsigned short * green_array,unsigned short * blue_array)25 Bool XF86VidModeGetGammaRamp(
26     Display *display,
27     int screen,
28     int size,
29     unsigned short *red_array,
30     unsigned short *green_array,
31     unsigned short *blue_array) {
32   return False;
33 }
XF86VidModeSetGammaRamp(Display * display,int screen,int size,unsigned short * red_array,unsigned short * green_array,unsigned short * blue_array)34 Bool XF86VidModeSetGammaRamp(
35     Display *display,
36     int screen,
37     int size,
38     unsigned short *red_array,
39     unsigned short *green_array,
40     unsigned short *blue_array) {
41   return False;
42 }
43 #endif
44 
45 /* HP-UX doesn't define RTLD_DEFAULT. */
46 #if defined(_HPUX) && !defined(RTLD_DEFAULT)
47 #define RTLD_DEFAULT NULL
48 #endif
49 
50 /* Need to expose DefaultScreen and RootWindow macros to Java */
51 JNIEXPORT jlong JNICALL
Java_com_sun_opengl_impl_x11_GLX_DefaultScreen(JNIEnv * env,jclass _unused,jlong display)52 Java_com_sun_opengl_impl_x11_GLX_DefaultScreen(JNIEnv *env, jclass _unused, jlong display) {
53   return DefaultScreen((Display*) (intptr_t) display);
54 }
55 JNIEXPORT jlong JNICALL
Java_com_sun_opengl_impl_x11_GLX_RootWindow(JNIEnv * env,jclass _unused,jlong display,jint screen)56 Java_com_sun_opengl_impl_x11_GLX_RootWindow(JNIEnv *env, jclass _unused, jlong display, jint screen) {
57   return RootWindow((Display*) (intptr_t) display, screen);
58 }
59 
60 JNIEXPORT jlong JNICALL
Java_com_sun_opengl_impl_x11_GLX_dlopen(JNIEnv * env,jclass _unused,jstring name)61 Java_com_sun_opengl_impl_x11_GLX_dlopen(JNIEnv *env, jclass _unused, jstring name) {
62   const jbyte* chars;
63   void* res;
64   chars = (*env)->GetStringUTFChars(env, name, NULL);
65   res = dlopen(chars, RTLD_LAZY | RTLD_GLOBAL);
66   (*env)->ReleaseStringUTFChars(env, name, chars);
67   return (jlong) ((intptr_t) res);
68 }
69 
70 JNIEXPORT jlong JNICALL
Java_com_sun_opengl_impl_x11_GLX_dlsym(JNIEnv * env,jclass _unused,jstring name)71 Java_com_sun_opengl_impl_x11_GLX_dlsym(JNIEnv *env, jclass _unused, jstring name) {
72   const jbyte* chars;
73   void* res;
74   chars = (*env)->GetStringUTFChars(env, name, NULL);
75   res = dlsym(RTLD_DEFAULT, chars);
76   (*env)->ReleaseStringUTFChars(env, name, chars);
77   return (jlong) ((intptr_t) res);
78 }
79 
80 /* We expect glXGetProcAddressARB to be defined */
81 extern __GLXextFuncPtr glXGetProcAddressARB (const GLubyte *);
82 
83 /* Need to pull this in as we don't have a stub header for it */
84 extern Bool XineramaEnabled(Display* display);
85