diff options
Diffstat (limited to 'src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp')
-rw-r--r-- | src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp | 94 |
1 files changed, 88 insertions, 6 deletions
diff --git a/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp b/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp index 89e488c33..398e17d27 100644 --- a/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp +++ b/src/windows/native/sun/windows/awt_Win32GraphicsEnv.cpp @@ -1,5 +1,5 @@ /* - * Copyright 1999-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1999-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,8 @@ #include "awt_Win32GraphicsDevice.h" #include "Devices.h" #include "WindowsFlags.h" -#include "dxInit.h" + +BOOL DWMIsCompositionEnabled(); void initScreens(JNIEnv *env) { @@ -39,8 +40,6 @@ void initScreens(JNIEnv *env) { JNU_ThrowInternalError(env, "Could not update the devices array."); return; } - - InitDirectX(); } /** @@ -54,7 +53,7 @@ void initScreens(JNIEnv *env) { static void SetProcessDPIAwareProperty() { - typedef BOOL SetProcessDPIAwareFunc(void); + typedef BOOL (WINAPI SetProcessDPIAwareFunc)(void); static BOOL bAlreadySet = FALSE; // setHighDPIAware is set in WindowsFlags.cpp @@ -64,7 +63,7 @@ SetProcessDPIAwareProperty() bAlreadySet = TRUE; - HINSTANCE hLibUser32Dll = ::LoadLibrary(TEXT("user32.dll")); + HMODULE hLibUser32Dll = ::LoadLibrary(TEXT("user32.dll")); if (hLibUser32Dll != NULL) { SetProcessDPIAwareFunc *lpSetProcessDPIAware = @@ -77,6 +76,76 @@ SetProcessDPIAwareProperty() } } +#define DWM_COMP_UNDEFINED (~(TRUE|FALSE)) +static int dwmIsCompositionEnabled = DWM_COMP_UNDEFINED; + +/** + * This function is called from toolkit event handling code when + * WM_DWMCOMPOSITIONCHANGED event is received + */ +void DWMResetCompositionEnabled() { + dwmIsCompositionEnabled = DWM_COMP_UNDEFINED; + (void)DWMIsCompositionEnabled(); +} + +/** + * Returns true if dwm composition is enabled, false if it is not applicable + * (if the OS is not Vista) or dwm composition is disabled. + * + * Note: since DWM composition state changes are very rare we load/unload the + * dll on every change. + */ +BOOL DWMIsCompositionEnabled() { + typedef HRESULT (WINAPI DwmIsCompositionEnabledFunc)(BOOL*); + + // cheaper to check than whether it's vista or not + if (dwmIsCompositionEnabled != DWM_COMP_UNDEFINED) { + return (BOOL)dwmIsCompositionEnabled; + } + + if (!IS_WINVISTA) { + dwmIsCompositionEnabled = FALSE; + return FALSE; + } + + BOOL bRes = FALSE; + HMODULE hDwmApiDll = ::LoadLibrary(TEXT("dwmapi.dll")); + + if (hDwmApiDll != NULL) { + DwmIsCompositionEnabledFunc *lpDwmIsCompEnabled = + (DwmIsCompositionEnabledFunc*) + GetProcAddress(hDwmApiDll, "DwmIsCompositionEnabled"); + if (lpDwmIsCompEnabled != NULL) { + BOOL bEnabled; + HRESULT res = lpDwmIsCompEnabled(&bEnabled); + if (SUCCEEDED(res)) { + bRes = bEnabled; + J2dTraceLn1(J2D_TRACE_VERBOSE, " composition enabled: %d",bRes); + } else { + J2dTraceLn1(J2D_TRACE_ERROR, + "IsDWMCompositionEnabled: error %x when detecting"\ + "if composition is enabled", res); + } + } else { + J2dTraceLn(J2D_TRACE_ERROR, + "IsDWMCompositionEnabled: no DwmIsCompositionEnabled() "\ + "in dwmapi.dll"); + } + ::FreeLibrary(hDwmApiDll); + } else { + J2dTraceLn(J2D_TRACE_ERROR, + "IsDWMCompositionEnabled: error opening dwmapi.dll"); + } + + dwmIsCompositionEnabled = bRes; + + JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2); + JNU_CallStaticMethodByName(env, NULL, + "sun/awt/Win32GraphicsEnvironment", + "dwmCompositionChanged", "(Z)V", (jboolean)bRes); + return bRes; +} + /* * Class: sun_awt_Win32GraphicsEnvironment * Method: initDisplay @@ -89,6 +158,8 @@ Java_sun_awt_Win32GraphicsEnvironment_initDisplay(JNIEnv *env, // This method needs to be called prior to any display-related activity SetProcessDPIAwareProperty(); + DWMIsCompositionEnabled(); + initScreens(env); } @@ -306,3 +377,14 @@ Java_sun_awt_Win32GraphicsEnvironment_getYResolution(JNIEnv *env, jobject wge) CATCH_BAD_ALLOC_RET(0); } + +/* + * Class: sun_awt_Win32GraphicsEnvironment + * Method: isVistaOS + * Signature: ()Z + */ +JNIEXPORT jboolean JNICALL Java_sun_awt_Win32GraphicsEnvironment_isVistaOS + (JNIEnv *env, jclass wgeclass) +{ + return IS_WINVISTA; +} |