From 2268a6ce8a900ae7aa9f20d5f595f811185574a9 Mon Sep 17 00:00:00 2001
From: Sven Gothel <sgothel@jausoft.com>
Date: Sat, 10 Oct 2009 04:24:26 -0700
Subject: NEWT: Add EventDispatchThread (EDT) pattern.

Due to limitations on Windows,
we need to standardize the one thread for
    - window creation, and
    - event dispatching

This was already mentioned in the previous implementation
but while integrating into another threading model (Plugin3),
it turned out that manual managing the thread is too much of a burden.

NEWT now uses a EDT per Display and Thread as the default,
where Display creation, Window creation and event dispatching is 'pipelined' into.

This can be switched off:
    NewtFactory.setUseEDT(boolean onoff);
and queried via:
    NewtFactory.useEDT();

Note this EDT impl. does not implicate a global lock or whatsoever.

The experimantal semantics of a current GL context
for input event dispatching is removed,
i.e. the GL context is no more made current for mouse/key listener.
This reduces the complexity and allows the proper impl. of
the external dispatch via EDT .. for example.
Removed:
    GLWindow: setEventHandlerMode(int) .. etc

X11Display: XLockDisplay/XUnlockDisplay
            needed to be utilized to allow the new
            multithreading (EDT/Render) Display usage.

X11Window:  lockSurface/unlockSurface
            locks X11Display as well ..

+++++

NEWT: 'getSurfaceHandle()' semantics changed.

To allow usage of the surfaceHandle for OS
where it is allocated thread local (MS-Windows),
it shall be aquired/released while lockSurface/unlockSurface.
This is done in the Windows Window implementation.
GLWindow can no more query 'getSurfaceHandle()'
to verify if 'setRealized()' was successful.

NEWT: Window surface lock is recursive and blocking now,
      as it shall be.
---
 .../wgl/WindowsWGLGraphicsConfigurationFactory.java | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

(limited to 'src/jogl/classes/com/sun/opengl/impl/windows')

diff --git a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
index add5c7b25..229042d9d 100644
--- a/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
+++ b/src/jogl/classes/com/sun/opengl/impl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java
@@ -111,7 +111,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
         long hdc = nativeWindow.getSurfaceHandle();
 
         if (DEBUG) {
-          Exception ex = new Exception("WindowsWGLGraphicsConfigurationFactory got HDC 0x"+Long.toHexString(hdc));
+          Exception ex = new Exception("WindowsWGLGraphicsConfigurationFactory got HDC "+toHexString(hdc));
           ex.printStackTrace();
           System.err.println("WindowsWGLGraphicsConfigurationFactory got NW    "+nativeWindow);
         }
@@ -128,7 +128,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
             //  - the graphics driver, copying the HDC's pixelformat to the new one,
             //  - or the Java2D/OpenGL pipeline's configuration
             if (DEBUG) {
-              System.err.println("!!!! NOTE: pixel format already chosen for HDC: 0x" + Long.toHexString(hdc)+
+              System.err.println("!!!! NOTE: pixel format already chosen for HDC: " + toHexString(hdc)+
                                  ", pixelformat "+pixelFormat);
             }
             pixelFormatSet = true;
@@ -149,6 +149,8 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
                 dummyContext.makeCurrent();
                 dummyWGLExt = (WGLExt) dummyContext.getPlatformGLExtensions();
               }
+          } else if (DEBUG) {
+              System.err.println(getThreadName() + ": Not using WGL_ARB_pixel_format, because multisampling not requested");
           }
           int recommendedPixelFormat = pixelFormat; // 1-based pixel format
           boolean haveWGLChoosePixelFormatARB = false;
@@ -189,7 +191,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
                     }
                     if (DEBUG) {
                       if (recommendedPixelFormat <= 0) {
-                        System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format");
+                        System.err.print(getThreadName() + ": wglChoosePixelFormatARB didn't recommend a pixel format: "+WGL.GetLastError());
                         if (capabilities.getSampleBuffers()) {
                           System.err.print(" for multisampled GLCapabilities");
                         }
@@ -202,6 +204,8 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
                 availableCaps = WindowsWGLGraphicsConfiguration.HDC2GLCapabilities(dummyWGLExt, hdc, -1, glProfile, pixelFormatSet, onscreen, usePBuffer);
                 gotAvailableCaps = null!=availableCaps ;
                 choosenBywGLPixelFormat = gotAvailableCaps ;
+              } else if (DEBUG) {
+                System.err.println(getThreadName() + ": wglChoosePixelFormatARB not available");
               }
             } finally {
               dummyContext.release();
@@ -212,22 +216,19 @@ public class WindowsWGLGraphicsConfigurationFactory extends GraphicsConfiguratio
 
           if (!gotAvailableCaps) {
             if (DEBUG) {
-              if (!capabilities.getSampleBuffers()) {
-                System.err.println(getThreadName() + ": Using ChoosePixelFormat because multisampling not requested");
-              } else {
-                System.err.println(getThreadName() + ": Using ChoosePixelFormat because no wglChoosePixelFormatARB");
-              }
+              System.err.println(getThreadName() + ": Using ChoosePixelFormat ... (LastError: "+WGL.GetLastError()+")");
             }
             pfd = WindowsWGLGraphicsConfiguration.GLCapabilities2PFD(capabilities);
             recommendedPixelFormat = WGL.ChoosePixelFormat(hdc, pfd);
             if (DEBUG) {
-              System.err.println(getThreadName() + ": Recommended pixel format = " + recommendedPixelFormat);
+              System.err.println(getThreadName() + ": ChoosePixelFormat(HDC "+toHexString(hdc)+") = " + recommendedPixelFormat + " (LastError: "+WGL.GetLastError()+")");
+              System.err.println(getThreadName() + ": Used " + capabilities);
             }
 
             numFormats = WGL.DescribePixelFormat(hdc, 1, 0, null);
             if (numFormats == 0) {
               throw new GLException("Unable to enumerate pixel formats of window " +
-                                    toHexString(hdc) + " for GLCapabilitiesChooser");
+                                    toHexString(hdc) + " for GLCapabilitiesChooser (LastError: "+WGL.GetLastError()+")");
             }
             availableCaps = new GLCapabilities[numFormats];
             for (int i = 0; i < numFormats; i++) {
-- 
cgit v1.2.3