aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-10-29 13:46:43 +0200
committerSven Gothel <[email protected]>2010-10-29 13:46:43 +0200
commit81ee164ec139337254ef0e8938c19119908de6ae (patch)
treeba0141b67713f4f1e5bd7c89ebf9013484c70af9 /src/newt/native
parent8e1e785f26ff57b58fe6218f7ad1c9379760d367 (diff)
Fix ScreenMode ; Add FatalError to NewtCommon.c ; Fix Windows Build
Fix ScreenMode - Avoid NPE/Out-of-memory: Return zero sized NewIntArrays instead of NULL. Fix Windows Build - ScreenMode still has a regression
Diffstat (limited to 'src/newt/native')
-rw-r--r--src/newt/native/NewtCommon.c41
-rw-r--r--src/newt/native/NewtCommon.h1
-rw-r--r--src/newt/native/WindowsWindow.c69
-rw-r--r--src/newt/native/X11Window.c55
4 files changed, 85 insertions, 81 deletions
diff --git a/src/newt/native/NewtCommon.c b/src/newt/native/NewtCommon.c
index 353dcb46f..0e3f99282 100644
--- a/src/newt/native/NewtCommon.c
+++ b/src/newt/native/NewtCommon.c
@@ -4,16 +4,41 @@
static const char * const ClazzNameRuntimeException = "java/lang/RuntimeException";
static jclass runtimeExceptionClz=NULL;
+void NewtCommon_FatalError(JNIEnv *env, const char* msg, ...)
+{
+ char buffer[512];
+ va_list ap;
+
+ va_start(ap, msg);
+ vsnprintf(buffer, sizeof(buffer), msg, ap);
+ va_end(ap);
+
+ fprintf(stderr, "%s\n", buffer);
+ (*env)->FatalError(env, buffer);
+}
+
+void NewtCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...)
+{
+ char buffer[512];
+ va_list ap;
+
+ va_start(ap, msg);
+ vsnprintf(buffer, sizeof(buffer), msg, ap);
+ va_end(ap);
+
+ (*env)->ThrowNew(env, runtimeExceptionClz, buffer);
+}
+
void NewtCommon_init(JNIEnv *env) {
if(NULL==runtimeExceptionClz) {
jclass c = (*env)->FindClass(env, ClazzNameRuntimeException);
if(NULL==c) {
- _FatalError(env, "NEWT X11Window: can't find %s", ClazzNameRuntimeException);
+ NewtCommon_FatalError(env, "NEWT X11Window: can't find %s", ClazzNameRuntimeException);
}
runtimeExceptionClz = (jclass)(*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c);
if(NULL==runtimeExceptionClz) {
- _FatalError(env, "NEWT X11Window: can't use %s", ClazzNameRuntimeException);
+ NewtCommon_FatalError(env, "NEWT X11Window: can't use %s", ClazzNameRuntimeException);
}
}
}
@@ -28,15 +53,3 @@ jchar* NewtCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str)
return strChars;
}
-void NewtCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...)
-{
- char buffer[512];
- va_list ap;
-
- va_start(ap, msg);
- vsnprintf(buffer, sizeof(buffer), msg, ap);
- va_end(ap);
-
- (*env)->ThrowNew(env, runtimeExceptionClz, buffer);
-}
-
diff --git a/src/newt/native/NewtCommon.h b/src/newt/native/NewtCommon.h
index 00ce0b643..f5835f7c8 100644
--- a/src/newt/native/NewtCommon.h
+++ b/src/newt/native/NewtCommon.h
@@ -9,6 +9,7 @@ void NewtCommon_init(JNIEnv *env);
jchar* NewtCommon_GetNullTerminatedStringChars(JNIEnv* env, jstring str);
+void NewtCommon_FatalError(JNIEnv *env, const char* msg, ...);
void NewtCommon_throwNewRuntimeException(JNIEnv *env, const char* msg, ...);
#endif
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c
index de501bfbc..54143f012 100644
--- a/src/newt/native/WindowsWindow.c
+++ b/src/newt/native/WindowsWindow.c
@@ -97,10 +97,11 @@
#include "MouseEvent.h"
#include "InputEvent.h"
#include "KeyEvent.h"
+#include "ScreenMode.h"
#include "NewtCommon.h"
-// #define VERBOSE_ON 1
+#define VERBOSE_ON 1
// #define DEBUG_KEYS 1
#ifdef VERBOSE_ON
@@ -111,19 +112,6 @@
#define STD_PRINT(...) fprintf(stderr, __VA_ARGS__); fflush(stderr)
-static void _FatalError(JNIEnv *env, const char* msg, ...)
-{
- char buffer[512];
- va_list ap;
-
- va_start(ap, msg);
- vsnprintf(buffer, sizeof(buffer), msg, ap);
- va_end(ap);
-
- fprintf(stderr, "%s\n", buffer);
- (*env)->FatalError(env, buffer);
-}
-
static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point";
static const char * const ClazzAnyCstrName = "<init>";
static const char * const ClazzNamePointCstrSignature = "(II)V";
@@ -1146,7 +1134,7 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getHeight
return (jint)GetSystemMetrics(SM_CYSCREEN);
}
-static int NewtScreen_RotationNative2Newt(int native) {
+static int NewtScreen_RotationNative2Newt(JNIEnv *env, int native) {
int rot;
switch (native) {
case DMDO_DEFAULT:
@@ -1168,18 +1156,18 @@ static int NewtScreen_RotationNative2Newt(int native) {
return rot;
}
-static LPCTSTR NewtScreen_getDisplayDeviceName(int scrn_idx) {
- DISPLAY_DEVICE device;
-
- if( FALSE == EnumDisplayDevices(NULL, scrn_idx, &device, 0) ) {
+static LPCTSTR NewtScreen_getDisplayDeviceName(DISPLAY_DEVICE * device, int scrn_idx) {
+ if( FALSE == EnumDisplayDevices(NULL, scrn_idx, device, 0) ) {
+ DBG_PRINT("*** WindowsWindow: getDisplayDeviceName.EnumDisplayDevices(scrn_idx %d) -> FALSE\n", scrn_idx);
return NULL;
}
- if( 0 == ( device.StateFlags & DISPLAY_DEVICE_ACTIVE ) ) {
+ /* if( 0 == ( device->StateFlags & DISPLAY_DEVICE_ACTIVE ) ) {
+ DBG_PRINT("*** WindowsWindow: !DISPLAY_DEVICE_ACTIVE(scrn_idx %d)\n", scrn_idx);
return NULL;
- }
+ } */
- return device.DeviceName;
+ return device->DeviceName;
}
static HDC NewtScreen_createDisplayDC(LPCTSTR displayDeviceName) {
@@ -1194,10 +1182,12 @@ static HDC NewtScreen_createDisplayDC(LPCTSTR displayDeviceName) {
JNIEXPORT jintArray JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getScreenMode0
(JNIEnv *env, jobject obj, jint scrn_idx, jint mode_idx)
{
+ DISPLAY_DEVICE device;
int prop_num = NUM_SCREEN_MODE_PROPERTIES_ALL;
- LPCTSTR deviceName = NewtScreen_getDisplayDeviceName(scrn_idx);
+ LPCTSTR deviceName = NewtScreen_getDisplayDeviceName(&device, scrn_idx);
if(NULL == deviceName) {
- return null;
+ DBG_PRINT("*** WindowsWindow: getScreenMode.getDisplayDeviceName(scrn_idx %d) -> NULL\n", scrn_idx);
+ return (*env)->NewIntArray(env, 0);
}
int widthmm, heightmm;
@@ -1214,21 +1204,21 @@ JNIEXPORT jintArray JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getS
int devModeID = (int)mode_idx;
- if(devModeID == -1) {
+ if(-1 == devModeID) {
devModeID = ENUM_CURRENT_SETTINGS;
+ } else {
prop_num++; // add 1st extra prop, mode_idx
}
- if (0 == EnumDisplaySettings(deviceName, devModeID, &dm))
- {
- return NULL;
+ if (0 == EnumDisplaySettings(deviceName, devModeID, &dm)) {
+ DBG_PRINT("*** WindowsWindow: getScreenMode.EnumDisplaySettings(mode_idx %d/%d) -> NULL\n", mode_idx, devModeID);
+ return (*env)->NewIntArray(env, 0);
}
-
jint prop[ prop_num ];
int propIndex = 0;
- if(devModeID == -1) {
+ if(-1 < devModeID ) {
prop[propIndex++] = mode_idx;
}
prop[propIndex++] = 0; // set later for verification of iterator
@@ -1238,8 +1228,8 @@ JNIEXPORT jintArray JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getS
prop[propIndex++] = widthmm;
prop[propIndex++] = heightmm;
prop[propIndex++] = dm.dmDisplayFrequency;
- prop[propIndex++] = NewtScreen_RotationNative2Newt(dm.dmDisplayOrientation);
- props[propIndex - NUM_SCREEN_MODE_PROPERTIES_ALL] = propIndex ; // count
+ prop[propIndex++] = NewtScreen_RotationNative2Newt(env, dm.dmDisplayOrientation);
+ prop[propIndex - NUM_SCREEN_MODE_PROPERTIES_ALL] = propIndex ; // count
jintArray properties = (*env)->NewIntArray(env, prop_num);
if (properties == NULL) {
@@ -1258,9 +1248,11 @@ JNIEXPORT jintArray JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_getS
JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_setScreenMode0
(JNIEnv *env, jobject object, jint scrn_idx, jint width, jint height, jint bits, jint rate, jint rot)
{
- LPCTSTR deviceName = NewtScreen_getDisplayDeviceName(scrn_idx);
+ DISPLAY_DEVICE device;
+ LPCTSTR deviceName = NewtScreen_getDisplayDeviceName(&device, scrn_idx);
if(NULL == deviceName) {
- return null;
+ DBG_PRINT("*** WindowsWindow: setScreenMode.getDisplayDeviceName(scrn_idx %d) -> NULL\n", scrn_idx);
+ return JNI_FALSE;
}
DEVMODE dm;
@@ -1269,6 +1261,7 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_setSc
dm.dmSize = sizeof(dm);
if (0 == EnumDisplaySettings(deviceName, ENUM_CURRENT_SETTINGS, &dm)) {
+ DBG_PRINT("*** WindowsWindow: setScreenMode.EnumDisplaySettings(ENUM_CURRENT_SETTINGS) -> NULL\n");
return JNI_FALSE;
}
@@ -1316,7 +1309,7 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsScreen_setSc
break;
default:
//requested rotation not available
- return SCREEN_MODE_ERROR;
+ NewtCommon_throwNewRuntimeException(env, "invalid rotation: %d", rotation);
break;
}
/** swap width and height if changing from vertical to horizantal
@@ -1347,16 +1340,16 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initI
if(NULL==pointClz) {
jclass c = (*env)->FindClass(env, ClazzNamePoint);
if(NULL==c) {
- _FatalError(env, "NEWT WindowsWindows: can't find %s", ClazzNamePoint);
+ NewtCommon_FatalError(env, "NEWT WindowsWindows: can't find %s", ClazzNamePoint);
}
pointClz = (jclass)(*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c);
if(NULL==pointClz) {
- _FatalError(env, "NEWT WindowsWindows: can't use %s", ClazzNamePoint);
+ NewtCommon_FatalError(env, "NEWT WindowsWindows: can't use %s", ClazzNamePoint);
}
pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature);
if(NULL==pointCstr) {
- _FatalError(env, "NEWT WindowsWindows: can't fetch %s.%s %s",
+ NewtCommon_FatalError(env, "NEWT WindowsWindows: can't fetch %s.%s %s",
ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature);
}
}
diff --git a/src/newt/native/X11Window.c b/src/newt/native/X11Window.c
index f105b0889..025c0e500 100644
--- a/src/newt/native/X11Window.c
+++ b/src/newt/native/X11Window.c
@@ -137,19 +137,6 @@ static jint X11KeySym2NewtVKey(KeySym keySym) {
return keySym;
}
-static void _FatalError(JNIEnv *env, const char* msg, ...)
-{
- char buffer[512];
- va_list ap;
-
- va_start(ap, msg);
- vsnprintf(buffer, sizeof(buffer), msg, ap);
- va_end(ap);
-
- fprintf(stderr, "%s\n", buffer);
- (*env)->FatalError(env, buffer);
-}
-
static const char * const ClazzNameNewtWindow = "com/jogamp/newt/Window";
static const char * const ClazzNamePoint = "javax/media/nativewindow/util/Point";
@@ -235,28 +222,28 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_x11_X11Display_initIDs0
if(NULL==newtWindowClz) {
c = (*env)->FindClass(env, ClazzNameNewtWindow);
if(NULL==c) {
- _FatalError(env, "NEWT X11Window: can't find %s", ClazzNameNewtWindow);
+ NewtCommon_FatalError(env, "NEWT X11Window: can't find %s", ClazzNameNewtWindow);
}
newtWindowClz = (jclass)(*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c);
if(NULL==newtWindowClz) {
- _FatalError(env, "NEWT X11Window: can't use %s", ClazzNameNewtWindow);
+ NewtCommon_FatalError(env, "NEWT X11Window: can't use %s", ClazzNameNewtWindow);
}
}
if(NULL==pointClz) {
c = (*env)->FindClass(env, ClazzNamePoint);
if(NULL==c) {
- _FatalError(env, "NEWT X11Windows: can't find %s", ClazzNamePoint);
+ NewtCommon_FatalError(env, "NEWT X11Windows: can't find %s", ClazzNamePoint);
}
pointClz = (jclass)(*env)->NewGlobalRef(env, c);
(*env)->DeleteLocalRef(env, c);
if(NULL==pointClz) {
- _FatalError(env, "NEWT X11Windows: can't use %s", ClazzNamePoint);
+ NewtCommon_FatalError(env, "NEWT X11Windows: can't use %s", ClazzNamePoint);
}
pointCstr = (*env)->GetMethodID(env, pointClz, ClazzAnyCstrName, ClazzNamePointCstrSignature);
if(NULL==pointCstr) {
- _FatalError(env, "NEWT X11Windows: can't fetch %s.%s %s",
+ NewtCommon_FatalError(env, "NEWT X11Windows: can't fetch %s.%s %s",
ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature);
}
}
@@ -276,7 +263,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Display_CompleteDisplay0
jlong windowDeleteAtom;
if(dpy==NULL) {
- _FatalError(env, "invalid display connection..");
+ NewtCommon_FatalError(env, "invalid display connection..");
}
javaObjectAtom = (jlong) XInternAtom(dpy, "JOGL_JAVA_OBJECT", False);
@@ -328,7 +315,7 @@ static void setJavaWindowProperty(JNIEnv *env, Display *dpy, Window window, jlon
{
jobject test = (jobject) getPtrOut32Long(jogl_java_object_data);
if( ! (jwindow==test) ) {
- _FatalError(env, "Internal Error .. Encoded Window ref not the same %p != %p !", jwindow, test);
+ NewtCommon_FatalError(env, "Internal Error .. Encoded Window ref not the same %p != %p !", jwindow, test);
}
}
@@ -789,7 +776,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_GetScreen0
DBG_PRINT("X11: X11Screen_GetScreen0 dpy %p START\n", dpy);
if(dpy==NULL) {
- _FatalError(env, "invalid display connection..");
+ NewtCommon_FatalError(env, "invalid display connection..");
}
scrn = ScreenOfDisplay(dpy,screen_index);
@@ -865,7 +852,9 @@ JNIEXPORT jintArray JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getAvailable
int major, minor;
if(False == NewtScreen_getRANDRVersion(dpy, &major, &minor)) {
+ DBG_PRINT(stderr, "Java_com_jogamp_newt_impl_x11_X11Screen_getAvailableScreenModeRotations0: RANDR not available\n");
fprintf(stderr, "RANDR not available\n");
+ return (*env)->NewIntArray(env, 0);
}
rotations_supported = XRRRotations (dpy, (int)scrn_idx, &cur_rotation);
@@ -887,8 +876,7 @@ JNIEXPORT jintArray JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getAvailable
if(num_rotations>0) {
properties = (*env)->NewIntArray(env, num_rotations);
- if (properties == NULL)
- {
+ if (properties == NULL) {
NewtCommon_throwNewRuntimeException(env, "Could not allocate int array of size %d", num_rotations);
}
@@ -911,6 +899,7 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getNumScreenModeR
Window root = RootWindow(dpy, (int)scrn_idx);
if(False == NewtScreen_hasRANDR(dpy)) {
+ DBG_PRINT(stderr, "Java_com_jogamp_newt_impl_x11_X11Screen_getNumScreenModeResolutions0: RANDR not available\n");
return 0;
}
@@ -932,7 +921,8 @@ JNIEXPORT jintArray JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getScreenMod
Window root = RootWindow(dpy, (int)scrn_idx);
if(False == NewtScreen_hasRANDR(dpy)) {
- return NULL;
+ DBG_PRINT(stderr, "Java_com_jogamp_newt_impl_x11_X11Screen_getScreenModeResolution0: RANDR not available\n");
+ return (*env)->NewIntArray(env, 0);
}
int num_sizes;
@@ -974,7 +964,8 @@ JNIEXPORT jintArray JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getScreenMod
Window root = RootWindow(dpy, (int)scrn_idx);
if(False == NewtScreen_hasRANDR(dpy)) {
- return NULL;
+ DBG_PRINT(stderr, "Java_com_jogamp_newt_impl_x11_X11Screen_getScreenModeRates0: RANDR not available\n");
+ return (*env)->NewIntArray(env, 0);
}
int num_sizes;
@@ -1017,6 +1008,7 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getCurrentScreenR
Window root = RootWindow(dpy, (int)scrn_idx);
if(False == NewtScreen_hasRANDR(dpy)) {
+ DBG_PRINT(stderr, "Java_com_jogamp_newt_impl_x11_X11Screen_getCurrentScreenRate0: RANDR not available\n");
return -1;
}
@@ -1042,6 +1034,7 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getCurrentScreenR
Window root = RootWindow(dpy, (int)scrn_idx);
if(False == NewtScreen_hasRANDR(dpy)) {
+ DBG_PRINT(stderr, "Java_com_jogamp_newt_impl_x11_X11Screen_getCurrentScreenRotation0: RANDR not available\n");
return -1;
}
@@ -1070,6 +1063,7 @@ JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_getCurrentScreenR
Window root = RootWindow(dpy, (int)scrn_idx);
if(False == NewtScreen_hasRANDR(dpy)) {
+ DBG_PRINT(stderr, "Java_com_jogamp_newt_impl_x11_X11Screen_getCurrentScreenResolutionIndex0: RANDR not available\n");
return -1;
}
@@ -1099,6 +1093,7 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_setCurrentScr
Window root = RootWindow(dpy, (int)screen_idx);
if(False == NewtScreen_hasRANDR(dpy)) {
+ DBG_PRINT(stderr, "Java_com_jogamp_newt_impl_x11_X11Screen_setCurrentScreenMode0: RANDR not available\n");
return JNI_FALSE;
}
@@ -1170,6 +1165,8 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_x11_X11Screen_setCurrentScr
//free
XRRFreeScreenConfigInfo(conf);
XSync(dpy, False);
+
+ return JNI_TRUE;
}
/**
@@ -1248,7 +1245,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CreateWindow0
Atom wm_delete_atom;
if(dpy==NULL) {
- _FatalError(env, "invalid display connection..");
+ NewtCommon_FatalError(env, "invalid display connection..");
}
if(visualID<0) {
@@ -1263,7 +1260,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CreateWindow0
windowParent = XRootWindowOfScreen(scrn);
}
if( XRootWindowOfScreen(scrn) != XRootWindow(dpy, scrn_idx) ) {
- _FatalError(env, "XRoot Malfunction: %p != %p"+XRootWindowOfScreen(scrn), XRootWindow(dpy, scrn_idx));
+ NewtCommon_FatalError(env, "XRoot Malfunction: %p != %p"+XRootWindowOfScreen(scrn), XRootWindow(dpy, scrn_idx));
}
DBG_PRINT( "X11: CreateWindow dpy %p, parent %p, %x/%d %dx%d, undeco %d\n",
(void*)dpy, (void*)windowParent, x, y, width, height, undecorated);
@@ -1364,7 +1361,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_CloseWindow0
jobject jwindow;
if(dpy==NULL) {
- _FatalError(env, "invalid display connection..");
+ NewtCommon_FatalError(env, "invalid display connection..");
}
DBG_PRINT( "X11: CloseWindow START dpy %p, win %p\n", (void*)dpy, (void*)w);
@@ -1426,7 +1423,7 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_x11_X11Window_setVisible0
DBG_PRINT( "X11: setVisible0 vis %d\n", visible);
if(dpy==NULL) {
- _FatalError(env, "invalid display connection..");
+ NewtCommon_FatalError(env, "invalid display connection..");
}
if(visible==JNI_TRUE) {