diff options
Diffstat (limited to 'src/newt')
4 files changed, 51 insertions, 126 deletions
diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java index 372859208..0556fe792 100644 --- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsDisplay.java @@ -1,5 +1,6 @@ /* * Copyright (c) 2008 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2010 JogAmp Community. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are @@ -33,73 +34,61 @@ package com.jogamp.newt.impl.windows; -import javax.media.nativewindow.*; -import javax.media.nativewindow.windows.*; -import com.jogamp.newt.*; -import com.jogamp.newt.impl.*; +import com.jogamp.newt.impl.DisplayImpl; +import com.jogamp.newt.impl.NEWTJNILibLoader; +import javax.media.nativewindow.AbstractGraphicsDevice; +import javax.media.nativewindow.NativeWindowException; +import javax.media.nativewindow.windows.RegisteredClassFactory; +import javax.media.nativewindow.windows.RegisteredClass; +import javax.media.nativewindow.windows.WindowsGraphicsDevice; public class WindowsDisplay extends DisplayImpl { - protected static final String WINDOW_CLASS_NAME = "NewtWindowClass"; - private static int windowClassAtom; - private static long hInstance; + private static final String newtClassBaseName = "_newt_clazz" ; + private static RegisteredClassFactory sharedClassFactory; static { NEWTJNILibLoader.loadNEWT(); if (!WindowsWindow.initIDs0()) { throw new NativeWindowException("Failed to initialize WindowsWindow jmethodIDs"); - } + } + sharedClassFactory = new RegisteredClassFactory(newtClassBaseName, WindowsWindow.getNewtWndProc0()); } public static void initSingleton() { // just exist to ensure static init has been run } + private RegisteredClass sharedClass; public WindowsDisplay() { } protected void createNativeImpl() { + sharedClass = sharedClassFactory.getSharedClass(); aDevice = new WindowsGraphicsDevice(AbstractGraphicsDevice.DEFAULT_UNIT); } protected void closeNativeImpl() { - // Can't do .. only at application shutdown - // UnregisterWindowClass0(getWindowClassAtom(), getHInstance()); + sharedClassFactory.releaseSharedClass(); } protected void dispatchMessagesNative() { DispatchMessages0(); } - protected static synchronized int getWindowClassAtom() { - if(0 == windowClassAtom) { - windowClassAtom = RegisterWindowClass0(WINDOW_CLASS_NAME, getHInstance()); - if (0 == windowClassAtom) { - throw new NativeWindowException("Error while registering window class"); - } - } - return windowClassAtom; + protected long getHInstance() { + return sharedClass.getHandle(); } - protected static synchronized long getHInstance() { - if(0 == hInstance) { - hInstance = LoadLibraryW0("newt"); - if (0 == hInstance) { - throw new NativeWindowException("Error finding HINSTANCE for \"newt\""); - } - } - return hInstance; + protected String getWindowClassName() { + return sharedClass.getName(); } //---------------------------------------------------------------------- // Internals only // - private static native long LoadLibraryW0(String libraryName); - private static native int RegisterWindowClass0(String windowClassName, long hInstance); - private static native void UnregisterWindowClass0(int wndClassAtom, long hInstance); - private static native void DispatchMessages0(); } diff --git a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java index d26f4dc82..eb6539c06 100644 --- a/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java +++ b/src/newt/classes/com/jogamp/newt/impl/windows/WindowsWindow.java @@ -97,9 +97,8 @@ public class WindowsWindow extends WindowImpl { if (config == null) { throw new NativeWindowException("Error choosing GraphicsConfiguration creating window: "+this); } - setWindowHandle(CreateWindow0(getParentWindowHandle(), - display.getWindowClassAtom(), display.WINDOW_CLASS_NAME, display.getHInstance(), - 0, undecorated, x, y, width, height)); + setWindowHandle(CreateWindow0(display.getHInstance(), display.getWindowClassName(), display.getWindowClassName(), + getParentWindowHandle(), 0, undecorated, x, y, width, height)); if (getWindowHandle() == 0) { throw new NativeWindowException("Error creating window"); } @@ -128,7 +127,7 @@ public class WindowsWindow extends WindowImpl { } if(windowHandleClose != 0) { try { - DestroyWindow0(windowHandleClose); + GDI.DestroyWindow(windowHandleClose); } catch (Throwable t) { if(DEBUG_IMPLEMENTATION) { Exception e = new Exception("Warning: closeNativeImpl failed - "+Thread.currentThread().getName(), t); @@ -177,12 +176,11 @@ public class WindowsWindow extends WindowImpl { // Internals only // protected static native boolean initIDs0(); - private native long CreateWindow0(long parentWindowHandle, - int wndClassAtom, String wndName, - long hInstance, long visualID, - boolean isUndecorated, - int x, int y, int width, int height); - private native void DestroyWindow0(long windowHandle); + protected static native long getNewtWndProc0(); + + private native long CreateWindow0(long hInstance, String wndClassName, String wndName, + long parentWindowHandle, long visualID, boolean isUndecorated, + int x, int y, int width, int height); private native long MonitorFromWindow0(long windowHandle); private native void setVisible0(long windowHandle, boolean visible, boolean top, int x, int y, int width, int height); private native void reconfigureWindow0(long parentWindowHandle, long windowHandle, diff --git a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java index 1aaffacb5..af05c0356 100644 --- a/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java +++ b/src/newt/classes/com/jogamp/newt/impl/x11/X11Display.java @@ -76,9 +76,8 @@ public class X11Display extends DisplayImpl { throw e; } aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.getNullToolkitLock()); - // aDevice = new X11GraphicsDevice(handle, NativeWindowFactory.createDefaultToolkitLockNoAWT(NativeWindowFactory.TYPE_X11, handle)); - // aDevice = new X11GraphicsDevice(handle); - + // aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT, NativeWindowFactory.createDefaultToolkitLockNoAWT(NativeWindowFactory.TYPE_X11, handle)); + // aDevice = new X11GraphicsDevice(handle, AbstractGraphicsDevice.DEFAULT_UNIT); } protected void closeNativeImpl() { diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c index 0a675157d..cafdaeef8 100644 --- a/src/newt/native/WindowsWindow.c +++ b/src/newt/native/WindowsWindow.c @@ -1047,71 +1047,6 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsDisplay_Dispatch } /* - * Class: com_jogamp_newt_impl_windows_WindowsDisplay - * Method: LoadLibraryW - * Signature: (Ljava/lang/String;)J - */ -JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsDisplay_LoadLibraryW0 - (JNIEnv *env, jclass clazz, jstring dllName) -{ - jchar* _dllName = NewtCommon_GetNullTerminatedStringChars(env, dllName); - HMODULE lib = LoadLibraryW(_dllName); - free(_dllName); - return (jlong) (intptr_t) lib; -} - -/* - * Class: com_jogamp_newt_impl_windows_WindowsDisplay - * Method: RegisterWindowClass - * Signature: (Ljava/lang/String;J)I - */ -JNIEXPORT jint JNICALL Java_com_jogamp_newt_impl_windows_WindowsDisplay_RegisterWindowClass0 - (JNIEnv *env, jclass clazz, jstring wndClassName, jlong hInstance) -{ - ATOM res; - WNDCLASS wc; -#ifndef UNICODE - const char* _wndClassName = NULL; -#endif - - /* register class */ - 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) (intptr_t) hInstance; - wc.hIcon = NULL; - wc.hCursor = LoadCursor( NULL, IDC_ARROW); - wc.hbrBackground = GetStockObject(BLACK_BRUSH); - wc.lpszMenuName = NULL; -#ifdef UNICODE - wc.lpszClassName = NewtCommon_GetNullTerminatedStringChars(env, wndClassName); -#else - _wndClassName = (*env)->GetStringUTFChars(env, wndClassName, NULL); - wc.lpszClassName = strdup(_wndClassName); - (*env)->ReleaseStringUTFChars(env, wndClassName, _wndClassName); -#endif - res = RegisterClass(&wc); - - free((void *)wc.lpszClassName); - - return (jint)res; -} - -/* - * Class: com_jogamp_newt_impl_windows_WindowsDisplay - * Method: CleanupWindowResources - * Signature: (java/lang/String;J)V - */ -JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsDisplay_UnregisterWindowClass0 - (JNIEnv *env, jclass clazz, jint wndClassAtom, jlong hInstance) -{ - UnregisterClass(MAKEINTATOM(wndClassAtom), (HINSTANCE) (intptr_t) hInstance); -} - -/* * Class: com_jogamp_newt_impl_windows_WindowsScreen * Method: getWidthImpl * Signature: (I)I @@ -1363,15 +1298,27 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initI /* * Class: com_jogamp_newt_impl_windows_WindowsWindow + * Method: getNewtWndProc0 + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_getNewtWndProc0 + (JNIEnv *env, jclass clazz) +{ + return (jlong) (intptr_t) wndProc; +} + +/* + * Class: com_jogamp_newt_impl_windows_WindowsWindow * Method: CreateWindow - * Signature: (JILjava/lang/String;JJZIIII)J */ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWindow0 - (JNIEnv *env, jobject obj, jlong parent, jint wndClassAtom, jstring jWndName, jlong hInstance, jlong visualID, - jboolean bIsUndecorated, - jint jx, jint jy, jint defaultWidth, jint defaultHeight) + (JNIEnv *env, jobject obj, + jlong hInstance, jstring jWndClassName, jstring jWndName, + jlong parent, jlong visualID, jboolean bIsUndecorated, + jint jx, jint jy, jint defaultWidth, jint defaultHeight) { HWND parentWindow = (HWND) (intptr_t) parent; + const TCHAR* wndClassName = NULL; const TCHAR* wndName = NULL; DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE | WS_TABSTOP; int x=(int)jx, y=(int)jy; @@ -1379,8 +1326,10 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi HWND window = NULL; #ifdef UNICODE + wndClassName = NewtCommon_GetNullTerminatedStringChars(env, jWndClassName); wndName = NewtCommon_GetNullTerminatedStringChars(env, jWndName); #else + wndClassName = (*env)->GetStringUTFChars(env, jWndClassName, NULL); wndName = (*env)->GetStringUTFChars(env, jWndName, NULL); #endif @@ -1400,13 +1349,13 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi (void) visualID; // FIXME: use the visualID .. - window = CreateWindow(MAKEINTATOM(wndClassAtom), wndName, windowStyle, + window = CreateWindow(wndClassName, wndName, windowStyle, x, y, width, height, parentWindow, NULL, (HINSTANCE) (intptr_t) hInstance, NULL); - DBG_PRINT("*** WindowsWindow: CreateWindow thread 0xX, parent %p, window %p, %d/%d %dx%d\n", + DBG_PRINT("*** WindowsWindow: CreateWindow thread 0x%X, parent %p, window %p, %d/%d %dx%d\n", (int)GetCurrentThreadId(), parentWindow, window, x, y, width, height); if (NULL == window) { @@ -1427,8 +1376,10 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi } #ifdef UNICODE + free((void*) wndClassName); free((void*) wndName); #else + (*env)->ReleaseStringUTFChars(env, jWndClassName, wndClassName); (*env)->ReleaseStringUTFChars(env, jWndName, wndName); #endif @@ -1437,18 +1388,6 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi /* * Class: com_jogamp_newt_impl_windows_WindowsWindow - * Method: DestroyWindow - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_DestroyWindow0 - (JNIEnv *env, jobject obj, jlong window) -{ - DBG_PRINT("*** WindowsWindow: DestroyWindow thread 0x%X, window %p\n", (int)GetCurrentThreadId(), window); - DestroyWindow((HWND) (intptr_t) window); -} - -/* - * Class: com_jogamp_newt_impl_windows_WindowsWindow * Method: MonitorFromWindow * Signature: (J)J */ |