diff options
-rw-r--r-- | make/build-nativewindow.xml | 10 | ||||
-rw-r--r-- | make/config/nativewindow/win32-lib.cfg | 3 | ||||
-rwxr-xr-x | make/scripts/java-win64-dbg.bat | 3 | ||||
-rwxr-xr-x | make/scripts/tests-x64.bat | 4 | ||||
-rw-r--r-- | make/stub_includes/win32/WindowsDWM.h | 33 | ||||
-rw-r--r-- | make/stub_includes/win32/window-lib.c | 1 | ||||
-rw-r--r-- | make/stub_includes/win32/windows.h | 2 | ||||
-rw-r--r-- | src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationUtil.java | 13 | ||||
-rw-r--r-- | src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java | 22 | ||||
-rw-r--r-- | src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java | 8 | ||||
-rw-r--r-- | src/nativewindow/native/windows/WindowsDWM.c | 94 | ||||
-rw-r--r-- | src/nativewindow/native/windows/WindowsDWM.h | 40 |
12 files changed, 226 insertions, 7 deletions
diff --git a/make/build-nativewindow.xml b/make/build-nativewindow.xml index bf8c8cdd9..b13e9b0ff 100644 --- a/make/build-nativewindow.xml +++ b/make/build-nativewindow.xml @@ -224,7 +224,9 @@ config="${windowlib.os.cfg}" includeRefid="stub.includes.fileset.platform" literalInclude="${stub.includes.gluegen.gg}" - emitter="com.jogamp.gluegen.JavaEmitter"> + emitter="com.jogamp.gluegen.JavaEmitter" + debug="false" + dumpCPP="false"> <classpath refid="gluegen.classpath" /> </gluegen> </target> @@ -576,6 +578,7 @@ <patternset id="c.src.files.windows"> <include name="${rootrel.generated.c}/Windows/GDI*.c"/> <include name="${rootrel.src.c}/windows/GDImisc.c"/> + <include name="${rootrel.src.c}/windows/WindowsDWM.c"/> <include name="${rootrel.src.c}/NativewindowCommon.c"/> </patternset> @@ -610,9 +613,10 @@ <sysincludepath path="${stub.includes.gluegen.cc}"/> <!-- This is for the generated headers for handwritten C code --> <includepath path="${src.generated.c}" /> - <includepath path="${src.generated.c}/X11" if="isX11"/> - <includepath path="${src.generated.c}/MacOSX" if="isOSX"/> + <includepath path="${src.generated.c}/X11" if="isX11"/> + <includepath path="${src.generated.c}/MacOSX" if="isOSX"/> <includepath path="${src.generated.c}/Windows" if="isWindows"/> + <includepath path="${src.c}/windows" if="isWindows"/> <includepath path="${src.c}"/> <!-- This must come last to not override real include paths --> diff --git a/make/config/nativewindow/win32-lib.cfg b/make/config/nativewindow/win32-lib.cfg index b8886bdac..b8ff42473 100644 --- a/make/config/nativewindow/win32-lib.cfg +++ b/make/config/nativewindow/win32-lib.cfg @@ -8,6 +8,7 @@ JavaClass GDI Style AllStatic Opaque boolean BOOL +Opaque int HRESULT Opaque long HANDLE Opaque long PROC Opaque long HINSTANCE @@ -16,6 +17,7 @@ Opaque long HBITMAP Opaque long HDC Opaque long HGDIOBJ Opaque long HGLRC +Opaque long HRGN Opaque long HPBUFFERARB Opaque long HPBUFFEREXT Opaque long void ** @@ -32,6 +34,7 @@ CustomCCode #undef WIN32_LEAN_AND_MEAN CustomCCode #include <gluegen_stdint.h> CustomCCode #include <gluegen_stddef.h> CustomCCode #include <wingdi.h> +CustomCCode #include "WindowsDWM.h" CustomCCode extern HINSTANCE GetApplicationHandle(); diff --git a/make/scripts/java-win64-dbg.bat b/make/scripts/java-win64-dbg.bat index 29828e785..3a425a479 100755 --- a/make/scripts/java-win64-dbg.bat +++ b/make/scripts/java-win64-dbg.bat @@ -21,7 +21,8 @@ REM set D_ARGS="-Djogl.debug=all" "-Dnewt.debug=all" "-Dnativewindow.debug=all" REM set D_ARGS="-Djogl.debug=all" "-Dnativewindow.debug=all"
REM set D_ARGS="-Djogl.debug=all"
REM set D_ARGS="-Djogl.debug.GLDebugMessageHandler" "-Djogl.debug.DebugGL" "-Djogl.debug.TraceGL"
-set D_ARGS="-Djogl.debug.DebugGL" "-Djogl.debug.GLDebugMessageHandler" "-Djogl.debug.GLSLCode"
+REM set D_ARGS="-Djogl.debug.DebugGL" "-Djogl.debug.GLDebugMessageHandler" "-Djogl.debug.GLSLCode"
+set D_ARGS="-Djogl.debug.GraphicsConfiguration" "-Djogl.debug.CapabilitiesChooser"
REM set D_ARGS="-Djogl.debug.GLContext" "-Dnewt.debug=all"
REM set D_ARGS="-Dnewt.debug.Window" "-Dnativewindow.debug.TraceLock"
REM set D_ARGS="-Dnativewindow.debug.TraceLock"
diff --git a/make/scripts/tests-x64.bat b/make/scripts/tests-x64.bat index 4ea678536..e76666289 100755 --- a/make/scripts/tests-x64.bat +++ b/make/scripts/tests-x64.bat @@ -10,7 +10,7 @@ REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.acore.TestGLPro REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.newt.TestGearsNEWT -time 30000 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es1.newt.TestGearsES1NEWT %1 %2 %3 -REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT %1 %2 %3 +scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestGearsES2NEWT %1 %2 %3 %4 %5 %6 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsAWT -time 5000 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.gl2.awt.TestGearsGLJPanelAWT -time 5000 REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.awt.TestAWT03GLCanvasRecreate01 @@ -78,5 +78,5 @@ REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.acore.TestGPUMe REM scripts\java-win64.bat com.jogamp.opengl.test.junit.jogl.glsl.TestRulerNEWT01 REM scripts\java-win64.bat com.jogamp.opengl.test.junit.jogl.glsl.TestFBOMRTNEWT01 -scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT %1 %2 %3 %4 +REM scripts\java-win64-dbg.bat com.jogamp.opengl.test.junit.jogl.demos.es2.newt.TestElektronenMultipliziererNEWT %1 %2 %3 %4 diff --git a/make/stub_includes/win32/WindowsDWM.h b/make/stub_includes/win32/WindowsDWM.h new file mode 100644 index 000000000..357602dae --- /dev/null +++ b/make/stub_includes/win32/WindowsDWM.h @@ -0,0 +1,33 @@ +#ifndef WGL_DWM_VERSION_1_X + +#define DWM_BB_ENABLE 1 +#define DWM_EC_DISABLECOMPOSITION 0 +#define DWM_EC_ENABLECOMPOSITION 1 + +typedef struct tagDWM_BLURBEHIND { + DWORD dwFlags; + int fEnable; /* BOOL */ + HRGN hRgnBlur; + int fTransitionOnMaximized; /* BOOL */ +} DWM_BLURBEHIND, *PDWM_BLURBEHIND; + +typedef struct tagMARGINS { + int cxLeftWidth; + int cxRightWidth; + int cyTopHeight; + int cyBottomHeight; +} MARGINS, *PMARGINS; + +#endif /* WGL_DWM_VERSION_1_X */ + +#ifndef WGL_DWM_VERSION_1_X +#define WGL_DWM_VERSION_1_X + +BOOL DwmIsExtensionAvailable(); +BOOL DwmIsCompositionEnabled(); +BOOL DwmEnableComposition( UINT uCompositionAction ); +BOOL DwmEnableBlurBehindWindow(HWND, CONST DWM_BLURBEHIND *); +BOOL DwmExtendFrameIntoClientArea(HWND, CONST MARGINS *); + +#endif /* WGL_DWM_VERSION_1_X */ + diff --git a/make/stub_includes/win32/window-lib.c b/make/stub_includes/win32/window-lib.c index c5c5d37b9..25355cdcd 100644 --- a/make/stub_includes/win32/window-lib.c +++ b/make/stub_includes/win32/window-lib.c @@ -1,2 +1,3 @@ #include <windows.h> #include <wingdi.h> +#include <WindowsDWM.h> diff --git a/make/stub_includes/win32/windows.h b/make/stub_includes/win32/windows.h index c30f99ebd..f2f3900ba 100644 --- a/make/stub_includes/win32/windows.h +++ b/make/stub_includes/win32/windows.h @@ -26,6 +26,7 @@ typedef HANDLE HMODULE; typedef HANDLE HINSTANCE; typedef HANDLE HPALETTE; typedef HANDLE HWND; +typedef HANDLE HRGN; typedef __int32 LONG; typedef const char* LPCSTR; typedef void* LPVOID; @@ -38,6 +39,7 @@ typedef unsigned short WORD; typedef unsigned short ATOM; typedef intptr_t DWORD_PTR; typedef intptr_t* PDWORD_PTR; +typedef __int32 HRESULT; /* Necessary handle typedefs for parsing wglext.h */ diff --git a/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationUtil.java b/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationUtil.java index 19a664071..cc7a578cd 100644 --- a/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationUtil.java +++ b/src/jogl/classes/jogamp/opengl/GLGraphicsConfigurationUtil.java @@ -145,4 +145,17 @@ public class GLGraphicsConfigurationUtil { return capsRequested; } + public static GLCapabilitiesImmutable fixOpaqueGLCapabilities(GLCapabilitiesImmutable capsRequested, boolean isOpaque) + { + GLCapabilities caps2 = null; + + if( capsRequested.isBackgroundOpaque() != isOpaque) { + // fix caps .. + caps2 = (GLCapabilities) capsRequested.cloneMutable(); + caps2.setBackgroundOpaque(isOpaque); + return caps2; + } + return capsRequested; + } + } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java index a82a7a38c..989906514 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfiguration.java @@ -48,7 +48,9 @@ import javax.media.opengl.GLException; import javax.media.opengl.GLPbuffer; import javax.media.opengl.GLProfile; +import jogamp.nativewindow.windows.DWM_BLURBEHIND; import jogamp.nativewindow.windows.GDI; +import jogamp.nativewindow.windows.MARGINS; import jogamp.nativewindow.windows.PIXELFORMATDESCRIPTOR; import jogamp.opengl.GLGraphicsConfigurationUtil; @@ -164,9 +166,27 @@ public class WindowsWGLGraphicsConfiguration extends DefaultGraphicsConfiguratio " for device context " + toHexString(hdc) + ": error code " + GDI.GetLastError()); } + if(!caps.isBackgroundOpaque()) { + final long hwnd = GDI.WindowFromDC(hdc); + DWM_BLURBEHIND bb = DWM_BLURBEHIND.create(); + bb.setDwFlags(GDI.DWM_BB_ENABLE); + bb.setFEnable(1); + boolean ok = GDI.DwmEnableBlurBehindWindow(hwnd, bb); + if(ok) { + MARGINS m = MARGINS.create(); + m.setCxLeftWidth(-1); + m.setCxRightWidth(-1); + m.setCyBottomHeight(-1); + m.setCyTopHeight(-1); + ok = GDI.DwmExtendFrameIntoClientArea(hwnd, m); + } + if(DEBUG) { + System.err.println("!!! translucency enabled on wnd: 0x"+Long.toHexString(hwnd)+" - ok: "+ok); + } + } if (DEBUG) { System.err.println("!!! setPixelFormat (ARB): hdc "+toHexString(hdc) +", "+caps); - } + } setCapsPFD(caps); } diff --git a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java index 1c607d2c7..178f2777c 100644 --- a/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java +++ b/src/jogl/classes/jogamp/opengl/windows/wgl/WindowsWGLGraphicsConfigurationFactory.java @@ -42,6 +42,7 @@ import javax.media.nativewindow.GraphicsConfigurationFactory; import javax.media.nativewindow.CapabilitiesImmutable; import javax.media.nativewindow.NativeSurface; import javax.media.nativewindow.NativeWindowFactory; +import javax.media.opengl.GLCapabilities; import javax.media.opengl.GLCapabilitiesImmutable; import javax.media.opengl.GLCapabilitiesChooser; import javax.media.opengl.GLContext; @@ -298,9 +299,14 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat } GLCapabilitiesImmutable capsChosen = (GLCapabilitiesImmutable) config.getChosenCapabilities(); + boolean isOpaque = capsChosen.isBackgroundOpaque() && GDI.DwmIsCompositionEnabled(); boolean onscreen = capsChosen.isOnscreen(); boolean usePBuffer = capsChosen.isPBuffer(); GLProfile glProfile = capsChosen.getGLProfile(); + + if(DEBUG) { + System.err.println("!!! translucency requested: "+(!capsChosen.isBackgroundOpaque())+", compositioning enabled: "+GDI.DwmIsCompositionEnabled()+" -> translucency "+(!isOpaque)); + } WGLGLCapabilities pixelFormatCaps = null; // chosen or preset PFD ID's caps boolean pixelFormatSet = false; // indicates a preset PFD ID [caps] @@ -316,6 +322,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat } pixelFormatSet = true; pixelFormatCaps = WindowsWGLGraphicsConfiguration.wglARBPFID2GLCapabilities(sharedResource, hdc, presetPFDID, glProfile, onscreen, usePBuffer); + pixelFormatCaps = (WGLGLCapabilities) GLGraphicsConfigurationUtil.fixOpaqueGLCapabilities(pixelFormatCaps, isOpaque); } else { int recommendedIndex = -1; // recommended index @@ -393,6 +400,7 @@ public class WindowsWGLGraphicsConfigurationFactory extends GLGraphicsConfigurat " chosen pfdID: native recommended "+ (recommendedIndex+1) + " chosen idx "+chosenIndex); } + pixelFormatCaps = (WGLGLCapabilities) GLGraphicsConfigurationUtil.fixOpaqueGLCapabilities(pixelFormatCaps, isOpaque); if (DEBUG) { System.err.println("!!! chosen pfdID (ARB): native recommended "+ (recommendedIndex+1) + " chosen "+pixelFormatCaps); diff --git a/src/nativewindow/native/windows/WindowsDWM.c b/src/nativewindow/native/windows/WindowsDWM.c new file mode 100644 index 000000000..4240e50a8 --- /dev/null +++ b/src/nativewindow/native/windows/WindowsDWM.c @@ -0,0 +1,94 @@ + +#include "WindowsDWM.h" + +#include <stdlib.h> +#include <stdio.h> + +// #define VERBOSE_ON 1 + +#ifdef VERBOSE_ON + #define DBG_PRINT(args...) fprintf(stderr, args); +#else + #define DBG_PRINT(args...) +#endif + +/* GetProcAddress doesn't exist in A/W variants under desktop Windows */ +#ifndef UNDER_CE +#define GetProcAddressA GetProcAddress +#endif + +typedef HRESULT (WINAPI *DwmEnableCompositionPROCADDR)(UINT uCompositionAction); +typedef HRESULT (WINAPI *DwmIsCompositionEnabledPROCADDR)(BOOL * pfEnabled); +typedef HRESULT (WINAPI *DwmEnableBlurBehindWindowPROCADDR)(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind); +typedef HRESULT (WINAPI *DwmExtendFrameIntoClientAreaPROCADDR)(HWND hwnd, const MARGINS *pMarInset); + +static int _init = 0; // 1: init, 2: has DWM extension +static DwmEnableCompositionPROCADDR _DwmEnableComposition = NULL; +static DwmIsCompositionEnabledPROCADDR _DwmIsCompositionEnabled = NULL; +static DwmEnableBlurBehindWindowPROCADDR _DwmEnableBlurBehindWindow = NULL; +static DwmExtendFrameIntoClientAreaPROCADDR _DwmExtendFrameIntoClientArea = NULL; + +static int initWindowsDWM() { + if(0 == _init) { + _init = 1; + HANDLE shell = LoadLibrary(TEXT("dwmapi.dll")); + if (shell) { + _DwmEnableComposition = (DwmEnableCompositionPROCADDR) GetProcAddressA (shell, "DwmEnableComposition"); + _DwmIsCompositionEnabled = (DwmIsCompositionEnabledPROCADDR) GetProcAddressA (shell, "DwmIsCompositionEnabled"); + _DwmEnableBlurBehindWindow = (DwmEnableBlurBehindWindowPROCADDR) GetProcAddressA (shell, "DwmEnableBlurBehindWindow"); + _DwmExtendFrameIntoClientArea = (DwmExtendFrameIntoClientAreaPROCADDR) GetProcAddressA (shell, "DwmExtendFrameIntoClientArea"); + if(NULL != _DwmEnableBlurBehindWindow && NULL != _DwmExtendFrameIntoClientArea) { + _init = 2; + } + } + // FreeLibrary (shell); + DBG_PRINT("DWM - initWindowsDWM: %d - s %p, e %p, c %p\n", _init, shell, _DwmEnableBlurBehindWindow, _DwmExtendFrameIntoClientArea); + } + return _init; +} + +BOOL DwmIsExtensionAvailable() { + return (2 == initWindowsDWM()) ? TRUE : FALSE; +} + +BOOL DwmIsCompositionEnabled( ) { + if(2 == initWindowsDWM()) { + BOOL fEnabled = FALSE; + if( 0 == _DwmIsCompositionEnabled(&fEnabled) ) { + DBG_PRINT("DWM - DwmIsCompositionEnabled: %d\n", fEnabled); + return fEnabled; + } + } + DBG_PRINT("DWM - DwmIsCompositionEnabled failed\n"); + return FALSE; +} + +BOOL DwmEnableComposition( UINT uCompositionAction ) { + if(2 == initWindowsDWM()) { + return 0 == _DwmEnableComposition(uCompositionAction) ? TRUE : FALSE; + } + return FALSE; +} + +BOOL DwmEnableBlurBehindWindow(HWND hwnd, const DWM_BLURBEHIND* pBlurBehind) { + if(2 == initWindowsDWM()) { + _DwmEnableBlurBehindWindow(hwnd, pBlurBehind); + DBG_PRINT("DWM - DwmEnableBlurBehindWindow: hwnd %p, f %d, on %d, %p\n", + (void *)hwnd, + (int) pBlurBehind->dwFlags, + (int) pBlurBehind->fEnable, + (void *)pBlurBehind->hRgnBlur); + return TRUE; + } + DBG_PRINT("DWM - DwmEnableBlurBehindWindow: n/a\n"); + return FALSE; +} + +BOOL DwmExtendFrameIntoClientArea(HWND hwnd, const MARGINS *pMarInset) { + if(2 == initWindowsDWM()) { + _DwmExtendFrameIntoClientArea(hwnd, pMarInset); + return TRUE; + } + return FALSE; +} + diff --git a/src/nativewindow/native/windows/WindowsDWM.h b/src/nativewindow/native/windows/WindowsDWM.h new file mode 100644 index 000000000..742db1628 --- /dev/null +++ b/src/nativewindow/native/windows/WindowsDWM.h @@ -0,0 +1,40 @@ +#ifndef _WINDOWS_DWM_H_ +#define _WINDOWS_DWM_H_ + + #include <windows.h> + + #define DWM_BB_ENABLE 0x00000001 // fEnable has been specified + #define DWM_EC_DISABLECOMPOSITION 0 + #define DWM_EC_ENABLECOMPOSITION 1 + + typedef struct _DWM_BLURBEHIND + { + DWORD dwFlags; + BOOL fEnable; + HRGN hRgnBlur; + BOOL fTransitionOnMaximized; + } DWM_BLURBEHIND, *PDWM_BLURBEHIND; + + typedef struct _MARGINS + { + int cxLeftWidth; // width of left border that retains its size + int cxRightWidth; // width of right border that retains its size + int cyTopHeight; // height of top border that retains its size + int cyBottomHeight; // height of bottom border that retains its size + } MARGINS, *PMARGINS; + + BOOL DwmIsExtensionAvailable(); + BOOL DwmIsCompositionEnabled(); + BOOL DwmEnableComposition( UINT uCompositionAction ); + BOOL DwmEnableBlurBehindWindow(HWND hwnd, const DWM_BLURBEHIND* pBlurBehind); + BOOL DwmExtendFrameIntoClientArea(HWND hwnd, const MARGINS *pMarInset); + + /* + DWM_BLURBEHIND bb = {0}; + bb.dwFlags = DWM_BB_ENABLE; + bb.fEnable = true; + bb.hRgnBlur = NULL; + DwmEnableBlurBehindWindow(hWnd, &bb); + */ + +#endif /* _WINDOWS_DWM_H_ */ |