From: <man...@us...> - 2014-03-26 12:06:53
|
Revision: 3966 http://sourceforge.net/p/modplug/code/3966 Author: manxorist Date: 2014-03-26 12:06:33 +0000 (Wed, 26 Mar 2014) Log Message: ----------- [Ref] Add mpt::windows::Version::IsWine() . [Ref] Cache windows version information globally in tracker builds (instead of potentially at every usage site). [Ref] Slightly modify mpt::Windws::Version interface. Modified Paths: -------------- trunk/OpenMPT/common/misc_util.cpp trunk/OpenMPT/common/misc_util.h trunk/OpenMPT/mptrack/CImageListEx.h trunk/OpenMPT/mptrack/Mptrack.cpp trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp trunk/OpenMPT/sounddev/SoundDeviceThread.cpp trunk/OpenMPT/sounddev/SoundDeviceThread.h trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp Modified: trunk/OpenMPT/common/misc_util.cpp =================================================================== --- trunk/OpenMPT/common/misc_util.cpp 2014-03-26 01:38:45 UTC (rev 3965) +++ trunk/OpenMPT/common/misc_util.cpp 2014-03-26 12:06:33 UTC (rev 3966) @@ -614,6 +614,111 @@ } // namespace Util + + +#if defined(WIN32) + +namespace mpt +{ +namespace Windows +{ +namespace Version +{ + + +#if defined(MODPLUG_TRACKER) + + +static bool SystemIsNT = true; + +// Initialize to used SDK version +static uint32 SystemVersion = +#if NTDDI_VERSION >= 0x06030000 // NTDDI_WINBLUE + mpt::Windows::Version::Win81 +#elif NTDDI_VERSION >= 0x06020000 // NTDDI_WIN8 + mpt::Windows::Version::Win8 +#elif NTDDI_VERSION >= 0x06010000 // NTDDI_WIN7 + mpt::Windows::Version::Win7 +#elif NTDDI_VERSION >= 0x06000000 // NTDDI_VISTA + mpt::Windows::Version::WinVista +#elif NTDDI_VERSION >= NTDDI_WINXP + mpt::Windows::Version::WinXP +#elif NTDDI_VERSION >= NTDDI_WIN2K + mpt::Windows::Version::Win2000 +#else + mpt::Windows::Version::WinNT4 +#endif + ; + +static bool SystemIsWine = false; + + +void Init() +//--------- +{ + OSVERSIONINFOEXW versioninfoex; + MemsetZero(versioninfoex); + versioninfoex.dwOSVersionInfoSize = sizeof(versioninfoex); + GetVersionExW((LPOSVERSIONINFOW)&versioninfoex); + SystemIsNT = (versioninfoex.dwPlatformId == VER_PLATFORM_WIN32_NT); + SystemVersion = ((uint32)mpt::saturate_cast<uint8>(versioninfoex.dwMajorVersion) << 8) | ((uint32)mpt::saturate_cast<uint8>(versioninfoex.dwMinorVersion) << 0); + SystemIsWine = false; + HMODULE hNTDLL = LoadLibraryW(L"ntdll.dll"); + if(hNTDLL) + { + SystemIsWine = (GetProcAddress(hNTDLL, "wine_get_version") != NULL); + FreeLibrary(hNTDLL); + hNTDLL = NULL; + } +} + + +bool IsAtLeast(mpt::Windows::Version::Number version) +//--------------------------------------------------- +{ + return (SystemVersion >= (uint32)version); +} + + +bool IsNT() +//--------- +{ + return SystemIsNT; +} + + +bool IsWine() +//----------- +{ + return SystemIsWine; +} + + +#else // !MODPLUG_TRACKER + + +bool IsAtLeast(mpt::Windows::Version::Number version) +//--------------------------------------------------- +{ + OSVERSIONINFOEXW versioninfoex; + MemsetZero(versioninfoex); + versioninfoex.dwOSVersionInfoSize = sizeof(versioninfoex); + GetVersionExW((LPOSVERSIONINFOW)&versioninfoex); + uint32 SystemVersion = ((uint32)mpt::saturate_cast<uint8>(versioninfoex.dwMajorVersion) << 8) | ((uint32)mpt::saturate_cast<uint8>(versioninfoex.dwMinorVersion) << 0); + return (SystemVersion >= (uint32)version); +} + + +#endif // MODPLUG_TRACKER + + +} // namespace Version +} // namespace Windows +} // namespace mpt + +#endif // WIN32 + + #if defined(MPT_WITH_DYNBIND) @@ -671,10 +776,10 @@ // Check for KB2533623: bool hasKB2533623 = false; - if(mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWin8) + if(mpt::Windows::Version::IsAtLeast(mpt::Windows::Version::Win8)) { hasKB2533623 = true; - } else if(mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWinVista) + } else if(mpt::Windows::Version::IsAtLeast(mpt::Windows::Version::WinVista)) { HMODULE hKernel32DLL = LoadLibraryW(L"kernel32.dll"); if(hKernel32DLL) Modified: trunk/OpenMPT/common/misc_util.h =================================================================== --- trunk/OpenMPT/common/misc_util.h 2014-03-26 01:38:45 UTC (rev 3965) +++ trunk/OpenMPT/common/misc_util.h 2014-03-26 12:06:33 UTC (rev 3966) @@ -680,55 +680,61 @@ } // namespace Util -namespace mpt -{ #if defined(WIN32) +namespace mpt +{ namespace Windows { +namespace Version +{ -enum WinNTVersion + +enum Number { - VerWinNT4 = 0x0400, - VerWin98 = 0x040a, - VerWinME = 0x045a, - VerWin2000 = 0x0500, - VerWinXP = 0x0501, - VerWinXPSP2 = 0x0502, - VerWinVista = 0x0600, - VerWin7 = 0x0601, - VerWin8 = 0x0602, + + // Win9x + Win98 = 0x040a, + WinME = 0x045a, + + // WinNT + WinNT4 = 0x0400, + Win2000 = 0x0500, + WinXP = 0x0501, + WinVista = 0x0600, + Win7 = 0x0601, + Win8 = 0x0602, + Win81 = 0x0603, + }; -// returns version in the form of the _WIN32_WINNT_* macros or mpt::Windows::WinNTVersion -static inline uint32 GetWinNTVersion() -//------------------------------------ -{ - OSVERSIONINFO versioninfo; - MemsetZero(versioninfo); - versioninfo.dwOSVersionInfoSize = sizeof(versioninfo); - GetVersionEx(&versioninfo); - return ((uint32)mpt::saturate_cast<uint8>(versioninfo.dwMajorVersion) << 8) | (uint32)mpt::saturate_cast<uint8>(versioninfo.dwMinorVersion); -} -static inline bool IsWinNT() -//-------------------------- -{ - OSVERSIONINFO versioninfo; - MemsetZero(versioninfo); - versioninfo.dwOSVersionInfoSize = sizeof(versioninfo); - GetVersionEx(&versioninfo); - return (versioninfo.dwPlatformId == VER_PLATFORM_WIN32_NT); -} +#if defined(MODPLUG_TRACKER) +// Initializes version information. +// Version information is cached in order to be safely available in audio real-time contexts. +// Checking version information (especially detecting Wine) can be slow. +void Init(); + +bool IsAtLeast(mpt::Windows::Version::Number version); +bool IsNT(); +bool IsWine(); + +#else // !MODPLUG_TRACKER + +bool IsAtLeast(mpt::Windows::Version::Number version); + +#endif // MODPLUG_TRACKER + + +} // namespace Version } // namespace Windows +} // namespace mpt #endif // WIN32 -} // namespace mpt - #if defined(MPT_WITH_DYNBIND) namespace mpt Modified: trunk/OpenMPT/mptrack/CImageListEx.h =================================================================== --- trunk/OpenMPT/mptrack/CImageListEx.h 2014-03-26 01:38:45 UTC (rev 3965) +++ trunk/OpenMPT/mptrack/CImageListEx.h 2014-03-26 12:06:33 UTC (rev 3966) @@ -23,7 +23,7 @@ #ifdef _M_IX86 // This is only relevant for Win9x (testing for supported SDK version won't work here because we only support Win9x through KernelEx). // Win9x only supports 1-bit transparency, so we pre-multiply all pixels with the default button face colour and create a transparency mask. - if(!mpt::Windows::IsWinNT()) + if(!mpt::Windows::Version::IsNT()) { BITMAP bm; bitmap->GetBitmap(&bm); Modified: trunk/OpenMPT/mptrack/Mptrack.cpp =================================================================== --- trunk/OpenMPT/mptrack/Mptrack.cpp 2014-03-26 01:38:45 UTC (rev 3965) +++ trunk/OpenMPT/mptrack/Mptrack.cpp 2014-03-26 12:06:33 UTC (rev 3966) @@ -848,6 +848,8 @@ // Start loading BeginWaitCursor(); + mpt::Windows::Version::Init(); + Log("OpenMPT Start"); ASSERT(nullptr == m_pDocManager); Modified: trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2014-03-26 01:38:45 UTC (rev 3965) +++ trunk/OpenMPT/sounddev/SoundDeviceDirectSound.cpp 2014-03-26 12:06:33 UTC (rev 3966) @@ -248,7 +248,7 @@ } m_dwWritePos = 0xFFFFFFFF; SetWakeupInterval(std::min(m_Settings.UpdateIntervalMS / 1000.0, m_nDSoundBufferSize / (2.0 * m_Settings.GetBytesPerSecond()))); - m_Flags.NeedsClippedFloat = (mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWinVista); + m_Flags.NeedsClippedFloat = mpt::Windows::Version::IsAtLeast(mpt::Windows::Version::WinVista); SoundBufferAttributes bufferAttributes; bufferAttributes.Latency = m_nDSoundBufferSize * 1.0 / m_Settings.GetBytesPerSecond(); bufferAttributes.UpdateInterval = std::min(m_Settings.UpdateIntervalMS / 1000.0, m_nDSoundBufferSize / (2.0 * m_Settings.GetBytesPerSecond())); Modified: trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2014-03-26 01:38:45 UTC (rev 3965) +++ trunk/OpenMPT/sounddev/SoundDevicePortAudio.cpp 2014-03-26 12:06:33 UTC (rev 3966) @@ -103,10 +103,10 @@ framesPerBuffer = paFramesPerBufferUnspecified; // let portaudio choose } else if(m_HostApi == Pa_HostApiTypeIdToHostApiIndex(paMME)) { - m_Flags.NeedsClippedFloat = (mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWinVista); + m_Flags.NeedsClippedFloat = mpt::Windows::Version::IsAtLeast(mpt::Windows::Version::WinVista); } else if(m_HostApi == Pa_HostApiTypeIdToHostApiIndex(paDirectSound)) { - m_Flags.NeedsClippedFloat = (mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWinVista); + m_Flags.NeedsClippedFloat = mpt::Windows::Version::IsAtLeast(mpt::Windows::Version::WinVista); } else { m_Flags.NeedsClippedFloat = false; Modified: trunk/OpenMPT/sounddev/SoundDeviceThread.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceThread.cpp 2014-03-26 01:38:45 UTC (rev 3965) +++ trunk/OpenMPT/sounddev/SoundDeviceThread.cpp 2014-03-26 12:06:33 UTC (rev 3966) @@ -26,8 +26,6 @@ //------------------------------------------------------------------------------------------ { - m_HasNTKernel = mpt::Windows::IsWinNT(); - m_WakeupInterval = 0.0; m_hPlayThread = NULL; m_dwPlayThreadId = 0; @@ -81,7 +79,7 @@ , hTask(NULL) { - m_HasVista = (mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWinVista); + m_HasVista = mpt::Windows::Version::IsAtLeast(mpt::Windows::Version::WinVista); if(m_HasVista) { @@ -175,7 +173,7 @@ sleepEvent = NULL; - if(self.m_HasNTKernel) + if(mpt::Windows::Version::IsNT()) { if(periodic_nt_timer) { @@ -211,7 +209,7 @@ void Retrigger() //-------------- { - if(self.m_HasNTKernel) + if(mpt::Windows::Version::IsNT()) { if(!periodic_nt_timer) { @@ -228,7 +226,7 @@ CPeriodicWaker::~CPeriodicWaker() //------------------------------- { - if(self.m_HasNTKernel) + if(mpt::Windows::Version::IsNT()) { if(periodic_nt_timer) { Modified: trunk/OpenMPT/sounddev/SoundDeviceThread.h =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceThread.h 2014-03-26 01:38:45 UTC (rev 3965) +++ trunk/OpenMPT/sounddev/SoundDeviceThread.h 2014-03-26 12:06:33 UTC (rev 3966) @@ -44,8 +44,6 @@ private: CSoundDeviceWithThread & m_SoundDevice; - bool m_HasNTKernel; - double m_WakeupInterval; HANDLE m_hAudioWakeUp; HANDLE m_hPlayThread; Modified: trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp =================================================================== --- trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2014-03-26 01:38:45 UTC (rev 3965) +++ trunk/OpenMPT/sounddev/SoundDeviceWaveout.cpp 2014-03-26 12:06:33 UTC (rev 3966) @@ -108,7 +108,7 @@ m_nWriteBuffer = 0; SetWakeupEvent(m_ThreadWakeupEvent); SetWakeupInterval(m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond()); - m_Flags.NeedsClippedFloat = (mpt::Windows::GetWinNTVersion() >= mpt::Windows::VerWinVista); + m_Flags.NeedsClippedFloat = mpt::Windows::Version::IsAtLeast(mpt::Windows::Version::WinVista); SoundBufferAttributes bufferAttributes; bufferAttributes.Latency = m_nWaveBufferSize * m_nPreparedHeaders * 1.0 / m_Settings.GetBytesPerSecond(); bufferAttributes.UpdateInterval = m_nWaveBufferSize * 1.0 / m_Settings.GetBytesPerSecond(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |