Exemple #1
0
static void _initClazzAccess(JNIEnv *env) {
    jclass c;

    if(NULL!=clazzRuntimeException) return ;

    c = (*env)->FindClass(env, ClazzNameRuntimeException);
    if(NULL==c) {
        _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameRuntimeException);
    }
    clazzRuntimeException = (jclass)(*env)->NewGlobalRef(env, c);
    (*env)->DeleteLocalRef(env, c);
    if(NULL==clazzRuntimeException) {
        _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameRuntimeException);
    }

    c = (*env)->FindClass(env, ClazzNameBuffers);
    if(NULL==c) {
        _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameBuffers);
    }
    clazzBuffers = (jclass)(*env)->NewGlobalRef(env, c);
    (*env)->DeleteLocalRef(env, c);
    if(NULL==clazzBuffers) {
        _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameBuffers);
    }
    c = (*env)->FindClass(env, ClazzNameByteBuffer);
    if(NULL==c) {
        _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNameByteBuffer);
    }
    clazzByteBuffer = (jclass)(*env)->NewGlobalRef(env, c);
    (*env)->DeleteLocalRef(env, c);
    if(NULL==c) {
        _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNameByteBuffer);
    }

    cstrBuffers = (*env)->GetStaticMethodID(env, clazzBuffers, 
                            ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature);
    if(NULL==cstrBuffers) {
        _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't create %s.%s %s",
            ClazzNameBuffers, ClazzNameBuffersStaticCstrName, ClazzNameBuffersStaticCstrSignature);
    }

    c = (*env)->FindClass(env, ClazzNamePoint);
    if(NULL==c) {
        _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't find %s", ClazzNamePoint);
    }
    pointClz = (jclass)(*env)->NewGlobalRef(env, c);
    (*env)->DeleteLocalRef(env, c);
    if(NULL==pointClz) {
        _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't use %s", ClazzNamePoint);
    }
    pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature);
    if(NULL==pointCstr) {
        _FatalError(env, "FatalError Java_com_jogamp_nativewindow_impl_x11_X11Lib: can't fetch %s.%s %s",
            ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature);
    }
}
Exemple #2
0
/*   Java->C glue code:
 *   Java package: com.jogamp.nativewindow.impl.x11.X11Lib
 *    Java method: void XUnlockDisplay(long display)
 *     C function: void XUnlockDisplay(Display *  display);
 */
JNIEXPORT void JNICALL 
Java_com_jogamp_nativewindow_impl_x11_X11Lib_XUnlockDisplay__J(JNIEnv *env, jclass _unused, jlong display) {
  if(0==display) {
      _FatalError(env, "invalid display connection..");
  }
  XUnlockDisplay((Display *) (intptr_t) display);
}
Exemple #3
0
/*   Java->C glue code:
 *   Java package: com.jogamp.nativewindow.impl.x11.X11Lib
 *    Java method: XVisualInfo XGetVisualInfo(long arg0, long arg1, XVisualInfo arg2, java.nio.IntBuffer arg3)
 *     C function: XVisualInfo *  XGetVisualInfo(Display * , long, XVisualInfo * , int * );
 */
JNIEXPORT jobject JNICALL
Java_com_jogamp_nativewindow_impl_x11_X11Lib_XGetVisualInfo1__JJLjava_nio_ByteBuffer_2Ljava_lang_Object_2I(JNIEnv *env, jclass _unused, jlong arg0, jlong arg1, jobject arg2, jobject arg3, jint arg3_byte_offset) {
  XVisualInfo * _ptr2 = NULL;
  int * _ptr3 = NULL;
  XVisualInfo *  _res;
  int count;
  jobject jbyteSource;
  jobject jbyteCopy;
    if(0==arg0) {
        _FatalError(env, "invalid display connection..");
    }
    if (arg2 != NULL) {
        _ptr2 = (XVisualInfo *) (((char*) (*env)->GetDirectBufferAddress(env, arg2)) + 0);
    }
  if (arg3 != NULL) {
    _ptr3 = (int *) (((char*) (*env)->GetPrimitiveArrayCritical(env, arg3, NULL)) + arg3_byte_offset);
  }
  x11ErrorHandlerEnable((Display *) (intptr_t) arg0, 1, env);
  _res = XGetVisualInfo((Display *) (intptr_t) arg0, (long) arg1, (XVisualInfo *) _ptr2, (int *) _ptr3);
  x11ErrorHandlerEnable((Display *) (intptr_t) arg0, 0, env);
  count = _ptr3[0];
  if (arg3 != NULL) {
    (*env)->ReleasePrimitiveArrayCritical(env, arg3, _ptr3, 0);
  }
  if (_res == NULL) return NULL;

  jbyteSource = (*env)->NewDirectByteBuffer(env, _res, count * sizeof(XVisualInfo));
  jbyteCopy   = (*env)->CallStaticObjectMethod(env, clazzBuffers, cstrBuffers, jbyteSource);

  XFree(_res);

  return jbyteCopy;
}
Exemple #4
0
/*   Java->C glue code:
 *   Java package: com.jogamp.nativewindow.impl.x11.X11Lib
 *    Java method: int XCloseDisplay(long display)
 *     C function: int XCloseDisplay(Display *  display);
 */
JNIEXPORT jint JNICALL 
Java_com_jogamp_nativewindow_impl_x11_X11Lib_XCloseDisplay__J(JNIEnv *env, jclass _unused, jlong display) {
  int _res;
  if(0==display) {
      _FatalError(env, "invalid display connection..");
  }
  x11ErrorHandlerEnable((Display *) (intptr_t) display, 1, env);
  _res = XCloseDisplay((Display *) (intptr_t) display);
  x11ErrorHandlerEnable(NULL, 0, env);
  return _res;
}
Exemple #5
0
JNIEXPORT jlong JNICALL 
Java_com_jogamp_nativewindow_impl_x11_X11Lib_DefaultVisualID(JNIEnv *env, jclass _unused, jlong display, jint screen) {
  jlong r;
    if(0==display) {
        _FatalError(env, "invalid display connection..");
    }
  x11ErrorHandlerEnable((Display *) (intptr_t) display, 1, env);
  r = (jlong) XVisualIDFromVisual( DefaultVisual( (Display*) (intptr_t) display, screen ) );
  x11ErrorHandlerEnable((Display *) (intptr_t) display, 0, env);
  return r;
}
void boundary_transformation_init(boundary_transformation_t *t,
		double const *lower_bounds, double const *upper_bounds, unsigned long len_of_bounds)
{
	unsigned i;
	double const *ub, *lb;
	default_lower[0] = DBL_MAX / -1e2;
	default_upper[0] = DBL_MAX / 1e2;
	t->lower_bounds = lower_bounds;
	t->upper_bounds = upper_bounds;
	t->len_of_bounds = len_of_bounds;

	if (lower_bounds == NULL && len_of_bounds <= 1) /* convenience default */
		t->lower_bounds = default_lower;
	if (upper_bounds == NULL && len_of_bounds <= 1)
		t->upper_bounds = default_upper;
	if (len_of_bounds == 0) {
		t->lower_bounds = default_lower;
		t->upper_bounds = default_upper;
		t->len_of_bounds = 1;
	}

	if (t->lower_bounds == NULL || t->upper_bounds == NULL)
		_FatalError("init: input upper_bounds or lower_bounds was NULL and len_of_bounds > 1");

	/* compute boundaries in pre-image space, al and au */
	t->al = calloc(t->len_of_bounds, sizeof(double));
	t->au = calloc(t->len_of_bounds, sizeof(double));
	if (!t->al || !t->au)
		_FatalError(" in _init(): could not allocate memory");

	lb = t->lower_bounds;
	ub = t->upper_bounds;
	for(i = 0; i < t->len_of_bounds; ++i) {
		if (lb[i] == ub[i])
			_FatalError("in _init: lower and upper bounds must be different in all variables");
		/* between lb+al and ub-au transformation is the identity */
		t->al[i] = fmin((ub[i] - lb[i]) / 2., (1. + fabs(lb[i])) / 20.);
		t->au[i] = fmin((ub[i] - lb[i]) / 2., (1. + fabs(ub[i])) / 20.);
	}
}
void boundary_transformation_shift_into_feasible_preimage(
			boundary_transformation_t *t, double const *x, double *y, unsigned long len)
{
	double lb, ub, al, au, r, xlow, xup;
	unsigned long i;

	for(i = 0; i < len; ++i) {
		lb = t->lower_bounds[_index(t, i)];
		ub = t->upper_bounds[_index(t, i)];
		al = t->al[_index(t, i)];
		au = t->al[_index(t, i)];
		xlow = lb - 2 * al - (ub - lb) / 2.0;
		xup = ub + 2 * au + (ub - lb) / 2.0;
        r = 2 * (ub - lb + al + au); /* == xup - xlow == period of the transformation */

        y[i] = x[i];

		if (y[i] < xlow) { /* shift up */
			y[i] += r * (1 + (int)((xlow - y[i]) / r));
		}
		if (y[i] > xup) { /* shift down */
			y[i] -= r * (1 + (int)((y[i] - xup) / r));
			/* printf(" \n%f\n", fmod(y[i] - ub - au, r)); */
		}
		if (y[i] < lb - al) /* mirror */
			y[i] += 2 * (lb - al - y[i]);
        if (y[i] > ub + au)
        	y[i] -= 2 * (y[i] - ub - au);

		if ((y[i] < lb - al - 1e-15) || (y[i] > ub + au + 1e-15)) {
			printf("BUG in boundary_transformation_shift_into_feasible_preimage: lb=%f, ub=%f, al=%f au=%f, y=%f\n",
					lb, ub, al, au, y[i]);
			_FatalError("BUG");
		}
	}
}
Exemple #8
0
/*
 * Class:     com_jogamp_nativewindow_impl_x11_X11Lib
 * Method:    CreateDummyWindow
 * Signature: (JIJ)J
 */
JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_x11_X11Lib_CreateDummyWindow
  (JNIEnv *env, jclass unused, jlong display, jint screen_index, jlong visualID)
{
    Display * dpy  = (Display *)(intptr_t)display;
    int       scrn_idx = (int)screen_index;
    Window  windowParent = 0;
    Window  window = 0;

    XVisualInfo visualTemplate;
    XVisualInfo *pVisualQuery = NULL;
    Visual *visual = NULL;
    int depth;

    XSetWindowAttributes xswa;
    unsigned long attrMask;
    int n;

    Screen* scrn;

    if(NULL==dpy) {
        _FatalError(env, "invalid display connection..");
        return 0;
    }

    if(visualID<0) {
        _throwNewRuntimeException(NULL, env, "invalid VisualID ..");
        return 0;
    }

    x11ErrorHandlerEnable(dpy, 1, env);

    scrn = ScreenOfDisplay(dpy, scrn_idx);

    // try given VisualID on screen
    memset(&visualTemplate, 0, sizeof(XVisualInfo));
    visualTemplate.screen = scrn_idx;
    visualTemplate.visualid = (VisualID)visualID;
    pVisualQuery = XGetVisualInfo(dpy, VisualIDMask|VisualScreenMask, &visualTemplate,&n);
    if(pVisualQuery!=NULL) {
        visual   = pVisualQuery->visual;
        depth    = pVisualQuery->depth;
        visualID = (jlong)pVisualQuery->visualid;
        XFree(pVisualQuery);
        pVisualQuery=NULL;
    }
    DBG_PRINT( "X11: [CreateWindow] trying given (dpy %p, screen %d, visualID: %d, parent %p) found: %p\n", dpy, scrn_idx, (int)visualID, windowParent, visual);

    if (visual==NULL)
    { 
        x11ErrorHandlerEnable(dpy, 0, env);
        _throwNewRuntimeException(dpy, env, "could not query Visual by given VisualID, bail out!");
        return 0;
    } 

    if(pVisualQuery!=NULL) {
        XFree(pVisualQuery);
        pVisualQuery=NULL;
    }

    if(0==windowParent) {
        windowParent = XRootWindowOfScreen(scrn);
    }

    attrMask  = ( CWBackingStore | CWBackingPlanes | CWBackingPixel | CWBackPixel | 
                  CWBorderPixel | CWColormap | CWOverrideRedirect ) ;

    memset(&xswa, 0, sizeof(xswa));
    xswa.override_redirect = False; // use the window manager, always
    xswa.border_pixel = 0;
    xswa.background_pixel = 0;
    xswa.backing_store=NotUseful; /* NotUseful, WhenMapped, Always */
    xswa.backing_planes=0;        /* planes to be preserved if possible */
    xswa.backing_pixel=0;         /* value to use in restoring planes */
    xswa.event_mask = 0 ;         /* no events */

    xswa.colormap = XCreateColormap(dpy,
                                    XRootWindow(dpy, scrn_idx),
                                    visual,
                                    AllocNone);

    window = XCreateWindow(dpy,
                           windowParent,
                           0, 0,
                           64, 64,
                           0, // border width
                           depth,
                           InputOutput,
                           visual,
                           attrMask,
                           &xswa);

    XSync(dpy, False);

    XSelectInput(dpy, window, 0); // no events
    XSync(dpy, False);

    x11ErrorHandlerEnable(dpy, 0, env);

    DBG_PRINT( "X11: [CreateWindow] created window %p on display %p\n", window, dpy);

    return (jlong) window;
}