diff options
author | Sven Gothel <[email protected]> | 2009-06-13 22:52:04 +0000 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2009-06-13 22:52:04 +0000 |
commit | d5e07502834a2c1d8383e9f730e1e0ee06976a29 (patch) | |
tree | f23948eb01500331d4027ce9a58224f300917e2a | |
parent | 87f79612e25e91ccc0f8622a6793aa373939727d (diff) |
NEWT WindowsWindow cleanup, GLobalRef, using ATOM, .. - no StackOverflow .. but still the blocking window
git-svn-id: file:///usr/local/projects/SUN/JOGL/git-svn/svn-server-sync/jogl/branches/JOGL_2_SANDBOX@1945 232f8b59-042b-4e1e-8c03-345bb8c30851
-rwxr-xr-x | src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java | 25 | ||||
-rwxr-xr-x | src/newt/native/WindowsWindow.c | 122 |
2 files changed, 76 insertions, 71 deletions
diff --git a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java index 3b744234d..273be6653 100755 --- a/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java +++ b/src/newt/classes/com/sun/javafx/newt/windows/WindowsWindow.java @@ -46,7 +46,6 @@ public class WindowsWindow extends Window { // non fullscreen dimensions .. private int nfs_width, nfs_height, nfs_x, nfs_y; - private static final String WINDOW_CLASS_NAME = "NewtWindow"; static { NativeLibLoader.loadNEWT(); @@ -97,12 +96,11 @@ public class WindowsWindow extends Window { } protected void createNative(Capabilities caps) { - long wndClass = getWindowClass(); config = GraphicsConfigurationFactory.getFactory(getScreen().getDisplay().getGraphicsDevice()).chooseGraphicsConfiguration(caps, null, getScreen().getGraphicsScreen()); if (config == null) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } - windowHandle = CreateWindow(WINDOW_CLASS_NAME, getHInstance(), 0, undecorated, x, y, width, height); + windowHandle = CreateWindow(getWindowClassAtom(), WINDOW_CLASS_NAME, getHInstance(), 0, undecorated, x, y, width, height); if (windowHandle == 0) { throw new NativeWindowException("Error creating window"); } @@ -123,6 +121,7 @@ public class WindowsWindow extends Window { } protected void windowDestroyed() { + // singleton ATOM CleanupWindowResources(getWindowClassAtom(), getHInstance()); windowHandleClose = 0; super.windowDestroyed(); } @@ -208,15 +207,17 @@ public class WindowsWindow extends Window { //---------------------------------------------------------------------- // Internals only // - private static long windowClass; - private static synchronized long getWindowClass() { - if (windowClass == 0) { - windowClass = RegisterWindowClass(WINDOW_CLASS_NAME, getHInstance()); - if (windowClass == 0) { + private static final String WINDOW_CLASS_NAME = "NewtWindowClass"; + + private static int windowClassAtom = 0; + private static synchronized int getWindowClassAtom() { + if(0 == windowClassAtom) { + windowClassAtom = RegisterWindowClass(WINDOW_CLASS_NAME, getHInstance()); + if (windowClassAtom == 0) { throw new NativeWindowException("Error while registering window class"); } } - return windowClass; + return windowClassAtom; } private static long hInstance; private static synchronized long getHInstance() { @@ -231,10 +232,12 @@ public class WindowsWindow extends Window { private static native boolean initIDs(); private static native long LoadLibraryW(String libraryName); - private static native long RegisterWindowClass(String windowClassName, long hInstance); - private native long CreateWindow(String windowClassName, long hInstance, long visualID, + private static native int RegisterWindowClass(String windowClassName, long hInstance); + private native long CreateWindow(int wndClassAtom, String wndName, + long hInstance, long visualID, boolean isUndecorated, int x, int y, int width, int height); + private native void CleanupWindowResources(int wndClassAtom, long hInstance); private native void DestroyWindow(long windowHandle); private native long GetDC(long windowHandle); private native void ReleaseDC(long windowHandle, long hdc); diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index e27cd4f30..af5e2a8f2 100755 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -613,22 +613,27 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message, } switch (message) { + + // + // The signal pipeline for destruction is: + // Java::DestroyWindow(wnd) _or_ window-close-button -> + // WM_CLOSE -> Java::windowDestroyNotify -> W_DESTROY -> Java::windowDestroyed -> + // Java::CleanupWindowResources() case WM_CLOSE: (*env)->CallVoidMethod(env, window, windowDestroyNotifyID); - // Called by Window.java: DestroyWindow(wnd); break; case WM_DESTROY: - /** Results in ACCESS_VIOLATION, since this thread - * might not be the creator of the global reference .. - (*env)->DeleteGlobalRef(env, wud->jinstance); */ - free(wud); wud=NULL; + { #if defined(UNDER_CE) || _MSC_VER <= 1200 - SetWindowLong(window, GWL_USERDATA, (intptr_t) wud); + SetWindowLong(wnd, GWL_USERDATA, NULL); #else - SetWindowLongPtr(window, GWLP_USERDATA, (intptr_t) wud); + SetWindowLongPtr(wnd, GWLP_USERDATA, NULL); #endif - (*env)->CallVoidMethod(env, window, windowDestroyedID); + free(wud); wud=NULL; + (*env)->CallVoidMethod(env, window, windowDestroyedID); + (*env)->DeleteGlobalRef(env, window); + } break; case WM_SYSCHAR: @@ -837,64 +842,74 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_LoadLibra /* * Class: com_sun_javafx_newt_windows_WindowsWindow * Method: RegisterWindowClass - * Signature: (Ljava/lang/String;J)J + * Signature: (Ljava/lang/String;J)I */ -JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_RegisterWindowClass - (JNIEnv *env, jclass clazz, jstring appName, jlong hInstance) +JNIEXPORT jint JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_RegisterWindowClass + (JNIEnv *env, jclass clazz, jstring wndClassName, jlong hInstance) { - WNDCLASS* wc; + ATOM res; + WNDCLASS wc; #ifndef UNICODE - const char* _appName = NULL; + const char* _wndClassName = NULL; #endif - wc = calloc(1, sizeof(WNDCLASS)); /* register class */ - wc->style = CS_HREDRAW | CS_VREDRAW; - wc->lpfnWndProc = (WNDPROC)wndProc; - wc->cbClsExtra = 0; - wc->cbWndExtra = 0; + wc.style = CS_HREDRAW | CS_VREDRAW; + wc.lpfnWndProc = (WNDPROC)wndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; /* This cast is legal because the HMODULE for a DLL is the same as its HINSTANCE -- see MSDN docs for DllMain */ - wc->hInstance = (HINSTANCE) hInstance; - wc->hIcon = NULL; - wc->hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)); - wc->hbrBackground = GetStockObject(BLACK_BRUSH); - wc->lpszMenuName = NULL; + wc.hInstance = (HINSTANCE) hInstance; + wc.hIcon = NULL; + wc.hCursor = LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW)); + wc.hbrBackground = GetStockObject(BLACK_BRUSH); + wc.lpszMenuName = NULL; #ifdef UNICODE - wc->lpszClassName = GetNullTerminatedStringChars(env, appName); + wc.lpszClassName = GetNullTerminatedStringChars(env, wndClassName); #else - _appName = (*env)->GetStringUTFChars(env, appName, NULL); - wc->lpszClassName = strdup(_appName); - (*env)->ReleaseStringUTFChars(env, appName, _appName); + _wndClassName = (*env)->GetStringUTFChars(env, wndClassName, NULL); + wc.lpszClassName = strdup(_wndClassName); + (*env)->ReleaseStringUTFChars(env, wndClassName, _wndClassName); #endif - if (!RegisterClass(wc)) { - free((void *)wc->lpszClassName); - free(wc); - return 0; - } - return (jlong) (intptr_t) wc; + res = RegisterClass(&wc); + + free((void *)wc.lpszClassName); + + return (jint)res; +} + +/* + * Class: com_sun_javafx_newt_windows_WindowsWindow + * Method: CleanupWindowResources + * Signature: (java/lang/String;J)V + */ +JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CleanupWindowResources + (JNIEnv *env, jobject obj, jint wndClassAtom, jlong hInstance) +{ + UnregisterClass(MAKEINTATOM(wndClassAtom), (HINSTANCE) hInstance); } /* * Class: com_sun_javafx_newt_windows_WindowsWindow * Method: CreateWindow - * Signature: (Ljava/lang/String;JJZIIII)J + * Signature: (ILjava/lang/String;JJZIIII)J */ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWindow - (JNIEnv *env, jobject obj, jstring windowClassName, jlong hInstance, jlong visualID, + (JNIEnv *env, jobject obj, jint wndClassAtom, jstring jWndName, jlong hInstance, jlong visualID, jboolean bIsUndecorated, jint jx, jint jy, jint defaultWidth, jint defaultHeight) { - const TCHAR* wndClassName = NULL; + const TCHAR* wndName = NULL; DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE; int x=(int)jx, y=(int)jy; int width=(int)defaultWidth, height=(int)defaultHeight; HWND window = NULL; #ifdef UNICODE - wndClassName = GetNullTerminatedStringChars(env, windowClassName); + wndName = GetNullTerminatedStringChars(env, jWndName); #else - wndClassName = (*env)->GetStringUTFChars(env, windowClassName, NULL); + wndName = (*env)->GetStringUTFChars(env, jWndName, NULL); #endif x = CW_USEDEFAULT; @@ -907,17 +922,12 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWin (void) visualID; // FIXME: use the visualID .. - window = CreateWindow(wndClassName, wndClassName, windowStyle, + window = CreateWindow(MAKEINTATOM(wndClassAtom), wndName, windowStyle, x, y, width, height, NULL, NULL, (HINSTANCE) hInstance, NULL); -#ifdef UNICODE - free((void*) wndClassName); -#else - (*env)->ReleaseStringUTFChars(env, windowClassName, wndClassName); -#endif - + if (window != NULL) { WindowUserData * wud = (WindowUserData *) malloc(sizeof(WindowUserData)); wud->jinstance = (*env)->NewGlobalRef(env, obj); @@ -929,6 +939,13 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWin #endif ShowWindow(window, SW_SHOWNORMAL); } + +#ifdef UNICODE + free((void*) wndName); +#else + (*env)->ReleaseStringUTFChars(env, jWndName, wndName); +#endif + return (jlong) (intptr_t) window; } @@ -940,21 +957,6 @@ JNIEXPORT jlong JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_CreateWin JNIEXPORT void JNICALL Java_com_sun_javafx_newt_windows_WindowsWindow_DestroyWindow (JNIEnv *env, jobject obj, jlong window) { -/** - WindowUserData * wud; -#if defined(UNDER_CE) || _MSC_VER <= 1200 - wud = (WindowUserData *) GetWindowLong((HWND)window, GWL_USERDATA); -#else - wud = (WindowUserData *) GetWindowLongPtr((HWND)window, GWLP_USERDATA); -#endif - if(NULL==wud) { - fprintf(stderr, "INTERNAL ERROR in WindowsWindow::DestroyWindow window userdata NULL\n"); - exit(1); - } - (*env)->DeleteGlobalRef(env, wud->jinstance); - - free(wud); */ - DestroyWindow((HWND) window); } |