diff options
-rw-r--r-- | make/config/nativewindow/win32-CustomJavaCode.java | 18 | ||||
-rw-r--r-- | make/config/nativewindow/win32-lib.cfg | 2 | ||||
-rw-r--r-- | make/stub_includes/win32/wingdi.h | 2 | ||||
-rw-r--r-- | src/nativewindow/native/windows/GDImisc.c | 63 |
4 files changed, 43 insertions, 42 deletions
diff --git a/make/config/nativewindow/win32-CustomJavaCode.java b/make/config/nativewindow/win32-CustomJavaCode.java index 54a7fa53a..0c1a3a402 100644 --- a/make/config/nativewindow/win32-CustomJavaCode.java +++ b/make/config/nativewindow/win32-CustomJavaCode.java @@ -1,28 +1,26 @@ - private static final long hInstance; - static { NWJNILibLoader.loadNativeWindow("win32"); - hInstance = initIDs0(); - if( 0 == hInstance ) { + + if( !initIDs0() ) { throw new NativeWindowException("GDI: Could not initialized native stub"); } } public static synchronized void initSingleton() { } - private static native long initIDs0(); + private static native boolean initIDs0(); - public static long getModuleHandle() { - return hInstance; - } + private static Object createDummyWindowSync = new Object(); public static long CreateDummyWindow(int x, int y, int width, int height) { - return CreateDummyWindow0(getModuleHandle(), x, y, width, height); + synchronized(createDummyWindowSync) { + return CreateDummyWindow0(x, y, width, height); + } } public static Point GetRelativeLocation(long src_win, long dest_win, int src_x, int src_y) { - return (Point) GetRelativeLocation0(src_win, dest_win, src_x, src_y); + return (Point) GetRelativeLocation0(src_win, dest_win, src_x, src_y); } private static native Object GetRelativeLocation0(long src_win, long dest_win, int src_x, int src_y); diff --git a/make/config/nativewindow/win32-lib.cfg b/make/config/nativewindow/win32-lib.cfg index 46c4f2f92..e140ed3aa 100644 --- a/make/config/nativewindow/win32-lib.cfg +++ b/make/config/nativewindow/win32-lib.cfg @@ -33,7 +33,7 @@ CustomCCode #include <stddef.h> Include ../intptr.cfg -CustomCCode extern HWND CreateDummyWindow0( HINSTANCE hInstance, int x, int y, int width, int height ) ; +CustomCCode extern HWND CreateDummyWindow0( int x, int y, int width, int height ) ; IncludeAs CustomJavaCode GDI win32-CustomJavaCode.java diff --git a/make/stub_includes/win32/wingdi.h b/make/stub_includes/win32/wingdi.h index fd4bc16a2..23506a463 100644 --- a/make/stub_includes/win32/wingdi.h +++ b/make/stub_includes/win32/wingdi.h @@ -169,7 +169,7 @@ WINGDIAPI HGDIOBJ WINAPI SelectObject(HDC, HGDIOBJ); // Routines for creation of a dummy window, device context and OpenGL // context for the purposes of getting wglChoosePixelFormatARB and // associated routines - HWND CreateDummyWindow0( HINSTANCE hInstance, int x, int y, int width, int height ) ; + HWND CreateDummyWindow0( int x, int y, int width, int height ) ; WINUSERAPI BOOL WINAPI ShowWindow(HWND hWnd, int nCmdShow); WINUSERAPI HDC WINAPI GetDC(HWND); WINUSERAPI int WINAPI ReleaseDC(HWND hWnd, HDC hDC); diff --git a/src/nativewindow/native/windows/GDImisc.c b/src/nativewindow/native/windows/GDImisc.c index 427e15d4a..0de40cf50 100644 --- a/src/nativewindow/native/windows/GDImisc.c +++ b/src/nativewindow/native/windows/GDImisc.c @@ -61,27 +61,48 @@ static jmethodID pointCstr = NULL; #define NATIVEWINDOW_DUMMY_WINDOW_NAME "__nativewindow_dummy_window" static ATOM nativewindowClass = 0; +static HINSTANCE nativeHInstance = NULL; LRESULT CALLBACK DummyWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { return DefWindowProc(hWnd,uMsg,wParam,lParam); } -HWND CreateDummyWindow0(HINSTANCE hInstance, int x, int y, int width, int height ) { - DWORD dwExStyle; - DWORD dwStyle; - HWND hWnd; +HWND CreateDummyWindow0(int x, int y, int width, int height ) { + DWORD dwExStyle; + DWORD dwStyle; + HWND hWnd; + HINSTANCE hInstance = GetModuleHandle(NULL); + if( nativeHInstance != hInstance || 0 == nativewindowClass ) { + nativeHInstance=hInstance; + WNDCLASS wc; + ZeroMemory( &wc, sizeof( wc ) ); + wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; + wc.lpfnWndProc = (WNDPROC) DummyWndProc; + wc.cbClsExtra = 0; + wc.cbWndExtra = 0; + wc.hInstance = hInstance; + wc.hIcon = NULL; + wc.hCursor = NULL; + wc.hbrBackground = NULL; + wc.lpszMenuName = NULL; + wc.lpszClassName = NATIVEWINDOW_DUMMY_WINDOW_NAME; + if( !(nativewindowClass = RegisterClass( &wc )) ) { + fprintf(stderr, "FatalError com_jogamp_nativewindow_impl_windows_GDI: RegisterClass Failed: %d\n", GetLastError() ); + return( 0 ); + } + } - dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; - dwStyle = WS_OVERLAPPEDWINDOW; - if( !(hWnd=CreateWindowEx( dwExStyle, + dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; + dwStyle = WS_OVERLAPPEDWINDOW; + if( !(hWnd=CreateWindowEx( dwExStyle, NATIVEWINDOW_DUMMY_WINDOW_NAME, NATIVEWINDOW_DUMMY_WINDOW_NAME, dwStyle | WS_CLIPSIBLINGS | WS_CLIPCHILDREN, x, y, width, height, NULL, NULL, hInstance, NULL ) ) ) { - return( 0 ); - } - return( hWnd ); + return( 0 ); + } + return( hWnd ); } /* @@ -89,7 +110,7 @@ HWND CreateDummyWindow0(HINSTANCE hInstance, int x, int y, int width, int height * Method: initIDs0 * Signature: ()Z */ -JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_windows_GDI_initIDs0 +JNIEXPORT jboolean JNICALL Java_com_jogamp_nativewindow_impl_windows_GDI_initIDs0 (JNIEnv *env, jclass clazz) { if(NULL==pointClz) { @@ -108,25 +129,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_nativewindow_impl_windows_GDI_initIDs0 ClazzNamePoint, ClazzAnyCstrName, ClazzNamePointCstrSignature); } } - HINSTANCE hInstance = GetModuleHandle(NULL); - if( !nativewindowClass ) { - WNDCLASS wc; - ZeroMemory( &wc, sizeof( wc ) ); - wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; - wc.lpfnWndProc = (WNDPROC) DummyWndProc; - wc.cbClsExtra = 0; - wc.cbWndExtra = 0; - wc.hInstance = hInstance; - wc.hIcon = NULL; - wc.hCursor = NULL; - wc.hbrBackground = NULL; - wc.lpszMenuName = NULL; - wc.lpszClassName = NATIVEWINDOW_DUMMY_WINDOW_NAME; - if( !(nativewindowClass = RegisterClass( &wc )) ) { - _FatalError(env, "FatalError com_jogamp_nativewindow_impl_windows_GDI: RegisterClass Failed: %d", GetLastError() ); - } - } - return (jlong) hInstance; + return JNI_TRUE; } /* |