aboutsummaryrefslogtreecommitdiffstats
path: root/src/newt/native/WindowsWindow.c
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2010-06-10 09:35:06 +0200
committerSven Gothel <[email protected]>2010-06-10 09:35:06 +0200
commit1d333a771ce0bc7c8594e21d031703f698f06a46 (patch)
tree933d470582896320855fa1d98c1a917edc412c24 /src/newt/native/WindowsWindow.c
parent4512900ddcb9ce9a498411d257b1b6d6010ec006 (diff)
Fix: Locking/Threading; Common IntIntHashMap and Buffers; Fix: glMap*Buffer*; GLX/WGL/CgGL: All runtime dynamic; Misc ..
TODO: Compile and test on MacOSX .. Fix: ===== Multithreading/Locking: See jogl/doc/Implementation/MultiThreading.txt - Locking layer is not platform agnostic, ie GLContextImpl, GLDrawableImpl, .. and NEWT: Window/Display - No more use of JAWT global lock necessary, removed. - No need for X11 Display lock, on the contrary, this made the NV driver hang. - Use common window/surface lock - All NativeWindow surfaceLock's are recursive now glMapBuffer: If size is 0, don't do cont with the native call. glMapBufferRange: Fix capacity. glNamedBufferDataEXT: Track the size. glMapNamedBufferEXT: Manual impl. - use the tracked size glXGetVisualFromFBConfig, glXChooseFBConfig, glXChooseVisual: Instead of ignoring and implement a renamed version (*Copied), we just use ManualImplementation for the proper copy-result code. DesktopGLDynamicLookupHelper: Initialize _hasGLBinding* attributes in the determing loadGLJNILibrary() method, which is called by super(). Otherwise static init will overwrite them after the super() call. X11GLXDrawableFactory: Don't release anything at shutdown (removed sharedContext.destroy()), since this caused a freeze/SEGV sometimes. Fixed NEWT's reparentWindow() functionality incl NewtCanvasAWT usage. - Native: if not visible, don't focus, etc - NewtCanvasAWT: Use the container size to start with - Run the command on the EDT Using GlueGen's new DynamicLibraryBundle utility: - X11, Windows and MacOSX OpenGL adapted to DynamicLibraryBundleInfo. - X11GLXDynamicLookupHelper -> X11GLXDynamicLibraryBundleInfo - Remove all path from lib names. - GL order: libGL.so.1, libGL.so, GL - shallLinkGlobal: true -> to server some 'old' DRI systems -> http://dri.sourceforge.net/doc/DRIuserguide.html - shallLookupGlobal: false - Try both : glXGetProcAddressARB and glXGetProcAddress - Using bootstrap: GLX.glXGetProcAddress(long glxGetProcAddressHandle, String glFuncName) Found the issue with LIBGL_DRIVERS_PATH, ie if not set no valid GL instance can be found (ie ATI fglrx/DRI). This may happen if using a differen user than the desktop user for whom the env var is set within some /etc/X11/Xsession.d/ script. Enhancements: ============= GLBufferSizeTracker: Use IntIntHashMap and add DirectState size tracking. GLBufferStateTracker: Use IntIntHashMap. GLStateTracker: Use IntIntHashMap. GLDynamicLookupHelper: More generic (global loading/lookup and GetProcAddress function name list), remove redundant code. FIXME: MacOSXCGLDynamicLookupHelper: - Not tested - Not using NSImage lookup anymore as recommended by OSX API Doc, so dlsym is used always (to be tested) WindowsWGLDynamicLookupHelper: - Not tested GLX/WGL/CgGL is all runtime-dynamic as now, ie loaded and looked-up at runtime, no compile time dependencies to GL anymore, nor a need to specify CgGL. Split up WGL in GDI and WGL, to allow proper dynamic runtime linkage of OpenGL32 while using static binding to GDI32 NEWT events generated by native code are enqueued and not send directly. This should ease locking mechanisms .. if any are necessary. NEWT: More platform specific code moved to *Impl method, simplifying the generic code of the superclass and impl protocol. Cleanup: ========= Replace all InternalBufferUtil's with com.jogamp.common.nio.Buffers Removed all InternalBufferUtil's from repository Removed GLContextImpl notion of 'optimized' surface locking, where the surface gets unlocked during makeCurrent/release. This just makes no sense and would impact multithreading in a horrible way.
Diffstat (limited to 'src/newt/native/WindowsWindow.c')
-rwxr-xr-xsrc/newt/native/WindowsWindow.c159
1 files changed, 86 insertions, 73 deletions
diff --git a/src/newt/native/WindowsWindow.c b/src/newt/native/WindowsWindow.c
index 37fd9c621..5e3311d3b 100755
--- a/src/newt/native/WindowsWindow.c
+++ b/src/newt/native/WindowsWindow.c
@@ -115,8 +115,8 @@ static jmethodID positionChangedID = NULL;
static jmethodID focusChangedID = NULL;
static jmethodID windowDestroyNotifyID = NULL;
static jmethodID windowDestroyedID = NULL;
-static jmethodID sendMouseEventID = NULL;
-static jmethodID sendKeyEventID = NULL;
+static jmethodID enqueueMouseEventID = NULL;
+static jmethodID enqueueKeyEventID = NULL;
static jmethodID sendPaintEventID = NULL;
static RECT* UpdateInsets(JNIEnv *env, HWND hwnd, jobject window);
@@ -506,7 +506,7 @@ static int WmChar(JNIEnv *env, jobject window, UINT character, UINT repCnt,
if (character == VK_RETURN) {
character = J_VK_ENTER;
}
- (*env)->CallVoidMethod(env, window, sendKeyEventID,
+ (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
(jint) EVENT_KEY_TYPED,
GetModifiers(),
(jint) -1,
@@ -551,7 +551,7 @@ static int WmKeyDown(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
character = WindowsKeyToJavaChar(wkey, modifiers, SAVE);
*/
- (*env)->CallVoidMethod(env, window, sendKeyEventID,
+ (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
(jint) EVENT_KEY_PRESSED,
modifiers,
(jint) jkey,
@@ -562,7 +562,7 @@ static int WmKeyDown(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
WM_KEYDOWN.
*/
if (jkey == J_VK_DELETE) {
- (*env)->CallVoidMethod(env, window, sendKeyEventID,
+ (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
(jint) EVENT_KEY_TYPED,
GetModifiers(),
(jint) -1,
@@ -586,7 +586,7 @@ static int WmKeyUp(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
character = WindowsKeyToJavaChar(wkey, modifiers, SAVE);
*/
- (*env)->CallVoidMethod(env, window, sendKeyEventID,
+ (*env)->CallVoidMethod(env, window, enqueueKeyEventID,
(jint) EVENT_KEY_RELEASED,
modifiers,
(jint) jkey,
@@ -595,11 +595,23 @@ static int WmKeyUp(JNIEnv *env, jobject window, UINT wkey, UINT repCnt,
return 0;
}
-static void NewtWindows_requestFocus (HWND hwnd) {
+static void NewtWindows_requestFocus (HWND hwnd, BOOL topLevel, BOOL reparented) {
+ DBG_PRINT("*** WindowsWindow: requestFocus.0 window %p\n", (void*)hwnd);
if (IsWindow(hwnd)) {
- SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE);
+ UINT flags = SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
+ if(reparented) {
+ flags |= SWP_FRAMECHANGED;
+ }
+ SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, flags);
+ DBG_PRINT("*** WindowsWindow: requestFocus.1\n");
SetForegroundWindow(hwnd); // Slightly Higher Priority
+ DBG_PRINT("*** WindowsWindow: requestFocus.2\n");
SetFocus(hwnd);// Sets Keyboard Focus To TheWindow
+ DBG_PRINT("*** WindowsWindow: requestFocus.3\n");
+ if(topLevel) {
+ SetActiveWindow(hwnd);
+ }
+ DBG_PRINT("*** WindowsWindow: requestFocus.X\n");
}
}
@@ -786,8 +798,8 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
case WM_LBUTTONDOWN:
- NewtWindows_requestFocus ( wnd ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
+ (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -796,7 +808,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_LBUTTONUP:
- (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -805,8 +817,8 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MBUTTONDOWN:
- NewtWindows_requestFocus ( wnd ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
+ (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -815,7 +827,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MBUTTONUP:
- (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -824,8 +836,8 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_RBUTTONDOWN:
- NewtWindows_requestFocus ( wnd ); // request focus on this window, if not already ..
- (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ NewtWindows_requestFocus ( wnd, FALSE, FALSE ); // request focus on this window, if not already ..
+ (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
(jint) EVENT_MOUSE_PRESSED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -834,7 +846,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_RBUTTONUP:
- (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
(jint) EVENT_MOUSE_RELEASED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -843,7 +855,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
break;
case WM_MOUSEMOVE:
- (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
(jint) EVENT_MOUSE_MOVED,
GetModifiers(),
(jint) LOWORD(lParam), (jint) HIWORD(lParam),
@@ -859,7 +871,7 @@ static LRESULT CALLBACK wndProc(HWND wnd, UINT message,
eventPt.x = x;
eventPt.y = y;
ScreenToClient(wnd, &eventPt);
- (*env)->CallVoidMethod(env, window, sendMouseEventID,
+ (*env)->CallVoidMethod(env, window, enqueueMouseEventID,
(jint) EVENT_MOUSE_WHEEL_MOVED,
GetModifiers(),
(jint) eventPt.x, (jint) eventPt.y,
@@ -1046,8 +1058,8 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initI
focusChangedID = (*env)->GetMethodID(env, clazz, "focusChanged", "(JZ)V");
windowDestroyNotifyID = (*env)->GetMethodID(env, clazz, "windowDestroyNotify", "()V");
windowDestroyedID = (*env)->GetMethodID(env, clazz, "windowDestroyed", "()V");
- sendMouseEventID = (*env)->GetMethodID(env, clazz, "sendMouseEvent", "(IIIIII)V");
- sendKeyEventID = (*env)->GetMethodID(env, clazz, "sendKeyEvent", "(IIIC)V");
+ enqueueMouseEventID = (*env)->GetMethodID(env, clazz, "enqueueMouseEvent", "(IIIIII)V");
+ enqueueKeyEventID = (*env)->GetMethodID(env, clazz, "enqueueKeyEvent", "(IIIC)V");
sendPaintEventID = (*env)->GetMethodID(env, clazz, "sendPaintEvent", "(IIIII)V");
if (sizeChangedID == NULL ||
insetsChangedID == NULL ||
@@ -1055,9 +1067,9 @@ JNIEXPORT jboolean JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_initI
focusChangedID == NULL ||
windowDestroyNotifyID == NULL ||
windowDestroyedID == NULL ||
- sendMouseEventID == NULL ||
+ enqueueMouseEventID == NULL ||
sendPaintEventID == NULL ||
- sendKeyEventID == NULL)
+ enqueueKeyEventID == NULL)
{
return JNI_FALSE;
}
@@ -1130,7 +1142,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi
ShowWindow(window, SW_SHOWNORMAL);
if(NULL!=parentWindow) {
- NewtWindows_requestFocus ( window ); // request focus on this window, if not already ..
+ NewtWindows_requestFocus ( window, FALSE, FALSE ); // request focus on this window, if not already ..
} /* else {
// top level already capable of receiving [keyboard] events
} */
@@ -1154,6 +1166,7 @@ JNIEXPORT jlong JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_CreateWi
JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_DestroyWindow0
(JNIEnv *env, jobject obj, jlong window)
{
+ DBG_PRINT("*** WindowsWindow: DestroyWindow window %p\n", window);
DestroyWindow((HWND) (intptr_t) window);
}
@@ -1279,25 +1292,34 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setPositi
}
}
-/*
- * Class: com_jogamp_newt_impl_windows_WindowsWindow
- * Method: setFullscreen
- * Signature: (JIIIIZ)V
- */
-JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setFullscreen0
- (JNIEnv *env, jobject obj, jlong parent, jlong window, jint x, jint y, jint width, jint height, jboolean bIsUndecorated)
+static void NewtWindows_reparentWindow(HWND hwndP, HWND hwnd, jint x, jint y, jint width, jint height, jboolean bIsUndecorated)
{
UINT flags;
- HWND hwndP = (HWND) (intptr_t) parent;
- HWND hwnd = (HWND) (intptr_t) window;
HWND hWndInsertAfter;
- DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
+ DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN ;
+ BOOL isVisible = IsWindowVisible(hwnd);
+
+ DBG_PRINT("*** WindowsWindow: reparentWindow.1 parent %p, window %p, %d/%d %dx%d undeco %d visible %d\n", (void*)hwndP, (void*)hwnd, x, y, width, height, bIsUndecorated, isVisible);
+ if (!IsWindow(hwnd)) {
+ DBG_PRINT("*** WindowsWindow: reparentWindow failure: Passed window %p is invalid\n", (void*)hwnd);
+ return;
+ }
+ if (NULL!=hwndP && !IsWindow(hwndP)) {
+ DBG_PRINT("*** WindowsWindow: reparentWindow failure: Passed parent window %p is invalid\n", (void*)hwndP);
+ return;
+ }
+
+ if (isVisible) {
+ windowStyle |= WS_VISIBLE;
+ }
// order of call sequence: (MS documentation)
- // SetParent(.., NULL), SetWindowLong ( WS_POPUP )
- // SetParent(.., PARENT), SetWindowLong ( WS_CHILD )
+ // TOP: SetParent(.., NULL); Clear WS_CHILD [, Set WS_POPUP]
+ // CHILD: Set WS_CHILD [, Clear WS_POPUP]; SetParent(.., PARENT)
+ //
if ( NULL == hwndP ) {
SetParent(hwnd, NULL);
+ DBG_PRINT("*** WindowsWindow: reparentWindow.2\n");
}
if(NULL!=hwndP) {
@@ -1308,32 +1330,26 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setFullsc
windowStyle |= WS_OVERLAPPEDWINDOW;
}
SetWindowLong(hwnd, GWL_STYLE, windowStyle);
+ DBG_PRINT("*** WindowsWindow: reparentWindow.3\n");
if ( NULL != hwndP ) {
SetParent(hwnd, hwndP );
+ DBG_PRINT("*** WindowsWindow: reparentWindow.4\n");
}
- if ( NULL == hwndP ) {
- flags = SWP_SHOWWINDOW;
- hWndInsertAfter = HWND_TOPMOST;
- } else {
- flags = SWP_NOACTIVATE | SWP_NOZORDER;
- hWndInsertAfter = 0;
+ if(isVisible) {
+ NewtWindows_requestFocus ( hwnd, ( NULL == hwndP ) ? TRUE : FALSE, TRUE );
}
- SetWindowPos(hwnd, hWndInsertAfter, x, y, width, height, flags);
-
- NewtWindows_requestFocus ( hwnd );
-
- (*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height);
+ DBG_PRINT("*** WindowsWindow: reparentWindow.X\n");
}
/*
* Class: com_jogamp_newt_impl_windows_WindowsWindow
- * Method: reparentWindow0
+ * Method: setFullscreen
* Signature: (JIIIIZ)V
*/
-JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_reparentWindow0
+JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setFullscreen0
(JNIEnv *env, jobject obj, jlong parent, jlong window, jint x, jint y, jint width, jint height, jboolean bIsUndecorated)
{
UINT flags;
@@ -1341,28 +1357,13 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_reparentW
HWND hwnd = (HWND) (intptr_t) window;
HWND hWndInsertAfter;
DWORD windowStyle = WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_VISIBLE;
+ BOOL isVisible = IsWindowVisible(hwnd);
- // order of call sequence: (MS documentation)
- // SetParent(.., NULL), SetWindowLong ( WS_POPUP )
- // SetParent(.., PARENT), SetWindowLong ( WS_CHILD )
- if ( NULL == hwndP ) {
- SetParent(hwnd, NULL);
- }
+ DBG_PRINT("*** WindowsWindow: setFullscreen.1 parent %p, window %p, %d/%d %dx%d undeco %d visible\n",
+ parent, window, x, y, width, height, bIsUndecorated, isVisible);
- if(NULL!=hwndP) {
- windowStyle |= WS_CHILD ;
- } else if (bIsUndecorated) {
- windowStyle |= WS_POPUP | WS_SYSMENU | WS_MAXIMIZEBOX | WS_MINIMIZEBOX;
- } else {
- windowStyle |= WS_OVERLAPPEDWINDOW;
- }
- SetWindowLong(hwnd, GWL_STYLE, windowStyle);
+ NewtWindows_reparentWindow(hwndP, hwnd, x, y, width, height, bIsUndecorated);
- if ( NULL != hwndP ) {
- SetParent(hwnd, hwndP );
- }
-
- /**
if ( NULL == hwndP ) {
flags = SWP_SHOWWINDOW;
hWndInsertAfter = HWND_TOPMOST;
@@ -1372,11 +1373,23 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_reparentW
}
SetWindowPos(hwnd, hWndInsertAfter, x, y, width, height, flags);
- */
- NewtWindows_requestFocus ( hwnd );
+ DBG_PRINT("*** WindowsWindow: setFullscreen.X\n");
+ (*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height); // resize necessary ..
+}
+
+/*
+ * Class: com_jogamp_newt_impl_windows_WindowsWindow
+ * Method: reparentWindow0
+ * Signature: (JIIIIZ)V
+ */
+JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_reparentWindow0
+ (JNIEnv *env, jobject obj, jlong parent, jlong window, jint x, jint y, jint width, jint height, jboolean bIsUndecorated)
+{
+ HWND hwndP = (HWND) (intptr_t) parent;
+ HWND hwnd = (HWND) (intptr_t) window;
- // (*env)->CallVoidMethod(env, obj, sizeChangedID, (jint) width, (jint) height);
+ NewtWindows_reparentWindow(hwndP, hwnd, x, y, width, height, bIsUndecorated);
}
/*
@@ -1403,8 +1416,8 @@ JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_setTitle0
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_jogamp_newt_impl_windows_WindowsWindow_requestFocus0
- (JNIEnv *env, jclass clazz, jlong window)
+ (JNIEnv *env, jclass clazz, jlong parent, jlong window)
{
- NewtWindows_requestFocus ( (HWND) (intptr_t) window ) ;
+ NewtWindows_requestFocus ( (HWND) (intptr_t) window, (0 == parent) ? TRUE : FALSE, FALSE ) ;
}