1. First read there a general build instruction.
viewtopic.php?f=19&t=13556
Unfortunately VS2013 wont install on XP, so you must have newer windows. That why i want make it bulding under mingw.
2. Get source code from github
3. Do editting, according following entries, probably you can make and apply them as patch.
4. Compile, mozconfig is regular as of [1]. And i added new option too --disable-skia, use it if you know why.
configure.in
427c427
< WINVER=600
---
> WINVER=502
2183c2183
< WIN32_SUBSYSTEM_VERSION=6.00
---
> WIN32_SUBSYSTEM_VERSION=5.01
5716a5717,5719
> MOZ_DIRECTX_SDK_PATH=
> MOZ_D3DCOMPILER_XP_DLL=
> MOZ_D3DCOMPILER_XP_CAB=
5740a5744,5745
> MOZ_REQUIRE_ALL_D3DCS=1
>
5788a5794,5843
> ######################################
> # Find _43 for use by XP.
>
> # Get the SDK path from the registry.
> # First try to get the June 2010 SDK
> MOZ_DIRECTX_SDK_REG_KEY=`reg query 'HKLM\Software\Microsoft\DirectX' //s | grep 'Microsoft DirectX SDK (June 2010)' | head -n 1`
> if test -z "$MOZ_DIRECTX_SDK_REG_KEY" ; then
> # Otherwise just take whatever comes first
> MOZ_DIRECTX_SDK_REG_KEY=`reg query 'HKLM\Software\Microsoft\DirectX' //s | grep 'Microsoft DirectX SDK' | head -n 1`
> fi
> MOZ_DIRECTX_SDK_PATH=`reg query "$MOZ_DIRECTX_SDK_REG_KEY" //v InstallPath | grep REG_SZ | sed 's/.*\([[a-zA-Z]]\)\\:\\\\/\\1\\:\\\\/' | sed 's,\\\\,/,g'`
>
> if test -n "$MOZ_DIRECTX_SDK_PATH" &&
> test -f "$MOZ_DIRECTX_SDK_PATH"/lib/$MOZ_D3D_CPU_SUFFIX/dxguid.lib ; then
> AC_MSG_RESULT([Found DirectX SDK via registry, using $MOZ_DIRECTX_SDK_PATH])
> else
> AC_MSG_RESULT([DirectX SDK not found.])
> MOZ_DIRECTX_SDK_PATH=
> fi
>
> # Check that our DirectX SDK is acceptable.
> if test -n "$MOZ_DIRECTX_SDK_PATH"; then
> if test -n "`echo $MOZ_DIRECTX_SDK_REG_KEY | grep 'February 2010'`" ; then
> AC_MSG_RESULT([Found the February 2010 DirectX SDK, which is unacceptable to ANGLE.])
> MOZ_DIRECTX_SDK_PATH=
> fi
> fi
>
> if test -n "$MOZ_DIRECTX_SDK_PATH"; then
> # Find a D3D compiler DLL in the DirectX SDK, if we didn't find one already.
> # Get the SDK numeric version (e.g. 43) by looking at the dependencies of d3dx9.lib
> MOZ_D3DX9_VERSION=`dumpbin //headers "$MOZ_DIRECTX_SDK_PATH"/lib/$MOZ_D3D_CPU_SUFFIX/d3dx9.lib | egrep d3dx9_[[0-9]][[0-9]]\.dll | head -n1 | sed 's/.*\([[0-9]][[0-9]]\).*/\\1/g'`
>
> if test -n "$MOZ_D3DX9_VERSION" ; then
> MOZ_D3DCOMPILER_XP_CAB=`find "$MOZ_DIRECTX_SDK_PATH"/Redist -name *D3DCompiler_${MOZ_D3DX9_VERSION}_${MOZ_D3D_CPU_SUFFIX}.cab | head -n1`
>
> if test -n "$MOZ_D3DCOMPILER_XP_CAB"; then
> MOZ_D3DCOMPILER_XP_DLL=D3DCompiler_$MOZ_D3DX9_VERSION.dll
> else
> AC_MSG_RESULT([Couldn't find a CAB containing the D3D compiler DLL.])
> AC_MSG_ERROR([DirectX SDK at "$MOZ_DIRECTX_SDK_PATH" appears broken.])
> MOZ_DIRECTX_SDK_PATH=
> fi
> else
> AC_MSG_RESULT([Couldn't determine the D3DX9 version for the DirectX SDK.])
> MOZ_DIRECTX_SDK_PATH=
> fi
> else
> AC_MSG_RESULT([Couldn't find an acceptable DirectX SDK for ANGLE, needed for d3dcompiler_43.])
> fi
5792a5848
> MOZ_FOUND_BOTH_D3D_COMPILERS=1
5796a5853,5861
> else
> MOZ_FOUND_BOTH_D3D_COMPILERS=
> fi
>
> if test -n "$MOZ_D3DCOMPILER_XP_DLL"; then
> MOZ_FOUND_A_D3D_COMPILER=1
> AC_MSG_RESULT([Found d3dcompiler DLL for XP: $MOZ_D3DCOMPILER_XP_DLL])
> else
> MOZ_FOUND_BOTH_D3D_COMPILERS=
5802a5868,5872
>
> if test -n "$MOZ_REQUIRE_ALL_D3DCS" -a -z "$MOZ_FOUND_BOTH_D3D_COMPILERS"; then
> AC_MSG_ERROR([Both D3D compilers _43 and _46+ are required by --enable-require-d3d-compilers.])
> AC_MSG_ERROR([ Install Windows SDK 8.0+, as well as DirectX SDK (June 2010 version or newer), or reconfigure without this flag.])
> fi
7672a7743,7747
> MOZ_ARG_ENABLE_BOOL(skia,
> [ --disable-skia Disable use of Skia],
> MOZ_ENABLE_SKIA=,
> MOZ_ENABLE_SKIA=)
>
8188a8264,8266
> AC_SUBST(MOZ_DIRECTX_SDK_PATH)
> AC_SUBST(MOZ_D3DCOMPILER_XP_DLL)
> AC_SUBST(MOZ_D3DCOMPILER_XP_CAB)
< WINVER=600
---
> WINVER=502
2183c2183
< WIN32_SUBSYSTEM_VERSION=6.00
---
> WIN32_SUBSYSTEM_VERSION=5.01
5716a5717,5719
> MOZ_DIRECTX_SDK_PATH=
> MOZ_D3DCOMPILER_XP_DLL=
> MOZ_D3DCOMPILER_XP_CAB=
5740a5744,5745
> MOZ_REQUIRE_ALL_D3DCS=1
>
5788a5794,5843
> ######################################
> # Find _43 for use by XP.
>
> # Get the SDK path from the registry.
> # First try to get the June 2010 SDK
> MOZ_DIRECTX_SDK_REG_KEY=`reg query 'HKLM\Software\Microsoft\DirectX' //s | grep 'Microsoft DirectX SDK (June 2010)' | head -n 1`
> if test -z "$MOZ_DIRECTX_SDK_REG_KEY" ; then
> # Otherwise just take whatever comes first
> MOZ_DIRECTX_SDK_REG_KEY=`reg query 'HKLM\Software\Microsoft\DirectX' //s | grep 'Microsoft DirectX SDK' | head -n 1`
> fi
> MOZ_DIRECTX_SDK_PATH=`reg query "$MOZ_DIRECTX_SDK_REG_KEY" //v InstallPath | grep REG_SZ | sed 's/.*\([[a-zA-Z]]\)\\:\\\\/\\1\\:\\\\/' | sed 's,\\\\,/,g'`
>
> if test -n "$MOZ_DIRECTX_SDK_PATH" &&
> test -f "$MOZ_DIRECTX_SDK_PATH"/lib/$MOZ_D3D_CPU_SUFFIX/dxguid.lib ; then
> AC_MSG_RESULT([Found DirectX SDK via registry, using $MOZ_DIRECTX_SDK_PATH])
> else
> AC_MSG_RESULT([DirectX SDK not found.])
> MOZ_DIRECTX_SDK_PATH=
> fi
>
> # Check that our DirectX SDK is acceptable.
> if test -n "$MOZ_DIRECTX_SDK_PATH"; then
> if test -n "`echo $MOZ_DIRECTX_SDK_REG_KEY | grep 'February 2010'`" ; then
> AC_MSG_RESULT([Found the February 2010 DirectX SDK, which is unacceptable to ANGLE.])
> MOZ_DIRECTX_SDK_PATH=
> fi
> fi
>
> if test -n "$MOZ_DIRECTX_SDK_PATH"; then
> # Find a D3D compiler DLL in the DirectX SDK, if we didn't find one already.
> # Get the SDK numeric version (e.g. 43) by looking at the dependencies of d3dx9.lib
> MOZ_D3DX9_VERSION=`dumpbin //headers "$MOZ_DIRECTX_SDK_PATH"/lib/$MOZ_D3D_CPU_SUFFIX/d3dx9.lib | egrep d3dx9_[[0-9]][[0-9]]\.dll | head -n1 | sed 's/.*\([[0-9]][[0-9]]\).*/\\1/g'`
>
> if test -n "$MOZ_D3DX9_VERSION" ; then
> MOZ_D3DCOMPILER_XP_CAB=`find "$MOZ_DIRECTX_SDK_PATH"/Redist -name *D3DCompiler_${MOZ_D3DX9_VERSION}_${MOZ_D3D_CPU_SUFFIX}.cab | head -n1`
>
> if test -n "$MOZ_D3DCOMPILER_XP_CAB"; then
> MOZ_D3DCOMPILER_XP_DLL=D3DCompiler_$MOZ_D3DX9_VERSION.dll
> else
> AC_MSG_RESULT([Couldn't find a CAB containing the D3D compiler DLL.])
> AC_MSG_ERROR([DirectX SDK at "$MOZ_DIRECTX_SDK_PATH" appears broken.])
> MOZ_DIRECTX_SDK_PATH=
> fi
> else
> AC_MSG_RESULT([Couldn't determine the D3DX9 version for the DirectX SDK.])
> MOZ_DIRECTX_SDK_PATH=
> fi
> else
> AC_MSG_RESULT([Couldn't find an acceptable DirectX SDK for ANGLE, needed for d3dcompiler_43.])
> fi
5792a5848
> MOZ_FOUND_BOTH_D3D_COMPILERS=1
5796a5853,5861
> else
> MOZ_FOUND_BOTH_D3D_COMPILERS=
> fi
>
> if test -n "$MOZ_D3DCOMPILER_XP_DLL"; then
> MOZ_FOUND_A_D3D_COMPILER=1
> AC_MSG_RESULT([Found d3dcompiler DLL for XP: $MOZ_D3DCOMPILER_XP_DLL])
> else
> MOZ_FOUND_BOTH_D3D_COMPILERS=
5802a5868,5872
>
> if test -n "$MOZ_REQUIRE_ALL_D3DCS" -a -z "$MOZ_FOUND_BOTH_D3D_COMPILERS"; then
> AC_MSG_ERROR([Both D3D compilers _43 and _46+ are required by --enable-require-d3d-compilers.])
> AC_MSG_ERROR([ Install Windows SDK 8.0+, as well as DirectX SDK (June 2010 version or newer), or reconfigure without this flag.])
> fi
7672a7743,7747
> MOZ_ARG_ENABLE_BOOL(skia,
> [ --disable-skia Disable use of Skia],
> MOZ_ENABLE_SKIA=,
> MOZ_ENABLE_SKIA=)
>
8188a8264,8266
> AC_SUBST(MOZ_DIRECTX_SDK_PATH)
> AC_SUBST(MOZ_D3DCOMPILER_XP_DLL)
> AC_SUBST(MOZ_D3DCOMPILER_XP_CAB)
180,186d179
< #ifdef XP_WIN
< if (!IsWindowsVistaOrGreater()) {
< Output("Couldn't load valid PE image.\n");
< return 255;
< }
<
< #endif
261a255,294
> #ifdef XP_WIN
>
> /**
> * Used only when GetTickCount64 is not available on the platform.
> * Last result of GetTickCount call. Kept in [ms].
> */
> static DWORD sLastGTCResult = 0;
>
> /**
> * Higher part of the 64-bit value of MozGetTickCount64,
> * incremented atomically.
> */
> static DWORD sLastGTCRollover = 0;
>
> /**
> * Function protecting GetTickCount result from rolling over. The original
> * code comes from the Windows implementation of the TimeStamp class minus the
> * locking harness which isn't needed here.
> *
> * @returns The current time in milliseconds
> */
> static ULONGLONG WINAPI
> MozGetTickCount64()
> {
> DWORD GTC = ::GetTickCount();
>
> /* Pull the rollover counter forward only if new value of GTC goes way
> * down under the last saved result */
> if ((sLastGTCResult > GTC) && ((sLastGTCResult - GTC) > (1UL << 30)))
> ++sLastGTCRollover;
>
> sLastGTCResult = GTC;
> return (ULONGLONG)sLastGTCRollover << 32 | sLastGTCResult;
> }
>
> typedef ULONGLONG (WINAPI* GetTickCount64_t)();
> static GetTickCount64_t sGetTickCount64 = nullptr;
>
> #endif
>
272c305,315
< return GetTickCount64() * freq.QuadPart;
---
>
> HMODULE kernelDLL = GetModuleHandleW(L"kernel32.dll");
> sGetTickCount64 = reinterpret_cast<GetTickCount64_t>
> (GetProcAddress(kernelDLL, "GetTickCount64"));
>
> if (!sGetTickCount64) {
> /* If the platform does not support the GetTickCount64 (Windows XP doesn't),
> * then use our fallback implementation based on GetTickCount. */
> sGetTickCount64 = MozGetTickCount64;
> }
> return sGetTickCount64() * freq.QuadPart;
< #ifdef XP_WIN
< if (!IsWindowsVistaOrGreater()) {
< Output("Couldn't load valid PE image.\n");
< return 255;
< }
<
< #endif
261a255,294
> #ifdef XP_WIN
>
> /**
> * Used only when GetTickCount64 is not available on the platform.
> * Last result of GetTickCount call. Kept in [ms].
> */
> static DWORD sLastGTCResult = 0;
>
> /**
> * Higher part of the 64-bit value of MozGetTickCount64,
> * incremented atomically.
> */
> static DWORD sLastGTCRollover = 0;
>
> /**
> * Function protecting GetTickCount result from rolling over. The original
> * code comes from the Windows implementation of the TimeStamp class minus the
> * locking harness which isn't needed here.
> *
> * @returns The current time in milliseconds
> */
> static ULONGLONG WINAPI
> MozGetTickCount64()
> {
> DWORD GTC = ::GetTickCount();
>
> /* Pull the rollover counter forward only if new value of GTC goes way
> * down under the last saved result */
> if ((sLastGTCResult > GTC) && ((sLastGTCResult - GTC) > (1UL << 30)))
> ++sLastGTCRollover;
>
> sLastGTCResult = GTC;
> return (ULONGLONG)sLastGTCRollover << 32 | sLastGTCResult;
> }
>
> typedef ULONGLONG (WINAPI* GetTickCount64_t)();
> static GetTickCount64_t sGetTickCount64 = nullptr;
>
> #endif
>
272c305,315
< return GetTickCount64() * freq.QuadPart;
---
>
> HMODULE kernelDLL = GetModuleHandleW(L"kernel32.dll");
> sGetTickCount64 = reinterpret_cast<GetTickCount64_t>
> (GetProcAddress(kernelDLL, "GetTickCount64"));
>
> if (!sGetTickCount64) {
> /* If the platform does not support the GetTickCount64 (Windows XP doesn't),
> * then use our fallback implementation based on GetTickCount. */
> sGetTickCount64 = MozGetTickCount64;
> }
> return sGetTickCount64() * freq.QuadPart;
62a63,65
> ifdef MOZ_D3DCOMPILER_XP_DLL
> DEFINES += -DMOZ_D3DCOMPILER_XP_DLL=$(MOZ_D3DCOMPILER_XP_DLL)
> endif
> ifdef MOZ_D3DCOMPILER_XP_DLL
> DEFINES += -DMOZ_D3DCOMPILER_XP_DLL=$(MOZ_D3DCOMPILER_XP_DLL)
> endif
655a656,659
> #ifdef MOZ_D3DCOMPILER_XP_DLL
> @BINPATH@/@MOZ_D3DCOMPILER_XP_DLL@
> #endif
>
> #ifdef MOZ_D3DCOMPILER_XP_DLL
> @BINPATH@/@MOZ_D3DCOMPILER_XP_DLL@
> #endif
>
160c160
< "\"d3dcompiler_46.dll\", \"d3dcompiler_47.dll\" }",
---
> "\"d3dcompiler_47.dll\", \"d3dcompiler_46.dll\", \"d3dcompiler_43.dll\" }",
< "\"d3dcompiler_46.dll\", \"d3dcompiler_47.dll\" }",
---
> "\"d3dcompiler_47.dll\", \"d3dcompiler_46.dll\", \"d3dcompiler_43.dll\" }",
11a12,15
> ifdef MOZ_D3DCOMPILER_XP_CAB
> expand '$(MOZ_D3DCOMPILER_XP_CAB)' -F:$(MOZ_D3DCOMPILER_XP_DLL) '$(DIST)/bin'
> endif
>
> ifdef MOZ_D3DCOMPILER_XP_CAB
> expand '$(MOZ_D3DCOMPILER_XP_CAB)' -F:$(MOZ_D3DCOMPILER_XP_DLL) '$(DIST)/bin'
> endif
>
344c344
< 'ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ "d3dcompiler_46.dll", "d3dcompiler_47.dll" }',
---
> 'ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ "d3dcompiler_46.dll", "d3dcompiler_47.dll", "d3dcompiler_43.dll" }',
359c359
< 'ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ "d3dcompiler_46.dll", "d3dcompiler_47.dll" }',
---
> 'ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ "d3dcompiler_46.dll", "d3dcompiler_47.dll", "d3dcompiler_43.dll" }',
< 'ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ "d3dcompiler_46.dll", "d3dcompiler_47.dll" }',
---
> 'ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ "d3dcompiler_46.dll", "d3dcompiler_47.dll", "d3dcompiler_43.dll" }',
359c359
< 'ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ "d3dcompiler_46.dll", "d3dcompiler_47.dll" }',
---
> 'ANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES={ "d3dcompiler_46.dll", "d3dcompiler_47.dll", "d3dcompiler_43.dll" }',
232c232
< SOURCES['renderer/d3d/HLSLCompiler.cpp'].flags += ['-DANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES=\'{ TEXT("d3dcompiler_47.dll"), TEXT("d3dcompiler_46.dll") }\'']
---
> SOURCES['renderer/d3d/HLSLCompiler.cpp'].flags += ['-DANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES=\'{ TEXT("d3dcompiler_47.dll"), TEXT("d3dcompiler_46.dll"), TEXT("d3dcompiler_43.dll") }\'']
< SOURCES['renderer/d3d/HLSLCompiler.cpp'].flags += ['-DANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES=\'{ TEXT("d3dcompiler_47.dll"), TEXT("d3dcompiler_46.dll") }\'']
---
> SOURCES['renderer/d3d/HLSLCompiler.cpp'].flags += ['-DANGLE_PRELOADED_D3DCOMPILER_MODULE_NAMES=\'{ TEXT("d3dcompiler_47.dll"), TEXT("d3dcompiler_46.dll"), TEXT("d3dcompiler_43.dll") }\'']
148a149,153
> #ifdef MOZ_D3DCOMPILER_XP_DLL
> if (LoadLibraryForEGLOnWindows(NS_LITERAL_STRING(NS_STRINGIFY(MOZ_D3DCOMPILER_XP_DLL))))
> break;
> #endif
>
> #ifdef MOZ_D3DCOMPILER_XP_DLL
> if (LoadLibraryForEGLOnWindows(NS_LITERAL_STRING(NS_STRINGIFY(MOZ_D3DCOMPILER_XP_DLL))))
> break;
> #endif
>
152a153,154
> if CONFIG['MOZ_D3DCOMPILER_XP_DLL']:
> DEFINES['MOZ_D3DCOMPILER_XP_DLL'] = CONFIG['MOZ_D3DCOMPILER_XP_DLL']
> if CONFIG['MOZ_D3DCOMPILER_XP_DLL']:
> DEFINES['MOZ_D3DCOMPILER_XP_DLL'] = CONFIG['MOZ_D3DCOMPILER_XP_DLL']
1837a1838
> featureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3);
> featureLevels.AppendElement(D3D_FEATURE_LEVEL_9_3);
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Hal.h"
#include "HalImpl.h"
#include "nsITimer.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/battery/Constants.h"
#include "nsComponentManagerUtils.h"
#include <windows.h>
#include "mozilla/WindowsVersion.h"
using namespace mozilla::dom::battery;
namespace mozilla {
namespace hal_impl {
static nsCOMPtr<nsITimer> sUpdateTimer;
#if (WINVER >= 0x0600)
/* Power Event API is Vista or later */
static decltype(RegisterPowerSettingNotification)* sRegisterPowerSettingNotification = nullptr;
static decltype(UnregisterPowerSettingNotification)* sUnregisterPowerSettingNotification = nullptr;
static HPOWERNOTIFY sPowerHandle = nullptr;
static HPOWERNOTIFY sCapacityHandle = nullptr;
static HWND sHWnd = nullptr;
#endif
static void
UpdateHandler(nsITimer* aTimer, void* aClosure) {
NS_ASSERTION(!IsVistaOrLater(),
"We shouldn't call this function for Vista or later version!");
static hal::BatteryInformation sLastInfo;
hal::BatteryInformation currentInfo;
hal_impl::GetCurrentBatteryInformation(¤tInfo);
if (sLastInfo.level() != currentInfo.level() ||
sLastInfo.charging() != currentInfo.charging() ||
sLastInfo.remainingTime() != currentInfo.remainingTime()) {
hal::NotifyBatteryChange(currentInfo);
sLastInfo = currentInfo;
}
}
#if (WINVER >= 0x0600)
static
LRESULT CALLBACK
BatteryWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (msg != WM_POWERBROADCAST || wParam != PBT_POWERSETTINGCHANGE) {
return DefWindowProc(hwnd, msg, wParam, lParam);
}
hal::BatteryInformation currentInfo;
// Since we need update remainingTime, we cannot use LPARAM.
hal_impl::GetCurrentBatteryInformation(¤tInfo);
hal::NotifyBatteryChange(currentInfo);
return TRUE;
}
#else
static
LRESULT CALLBACK
BatteryWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (msg != WM_POWERBROADCAST) {
return DefWindowProc(hwnd, msg, wParam, lParam);
}
hal::BatteryInformation currentInfo;
// Since we need update remainingTime, we cannot use LPARAM.
hal_impl::GetCurrentBatteryInformation(¤tInfo);
hal::NotifyBatteryChange(currentInfo);
return TRUE;
}
#endif
void
EnableBatteryNotifications()
{
#if (WINVER >= 0x0600)
HMODULE hUser32 = GetModuleHandleW(L"USER32.DLL");
if (!sRegisterPowerSettingNotification)
sRegisterPowerSettingNotification = (decltype(RegisterPowerSettingNotification)*)
GetProcAddress(hUser32, "RegisterPowerSettingNotification");
if (!sUnregisterPowerSettingNotification)
sUnregisterPowerSettingNotification = (decltype(UnregisterPowerSettingNotification)*)
GetProcAddress(hUser32, "UnregisterPowerSettingNotification");
if (!sRegisterPowerSettingNotification ||
!sUnregisterPowerSettingNotification) {
NS_ASSERTION(false, "Canot find PowerSettingNotification functions.");
return;
}
// Create custom window to watch battery event
// If we can get Goanna's window handle, this is unnecessary.
if (sHWnd == nullptr) {
WNDCLASSW wc;
HMODULE hSelf = GetModuleHandle(nullptr);
if (!GetClassInfoW(hSelf, L"MozillaBatteryClass", &wc)) {
ZeroMemory(&wc, sizeof(WNDCLASSW));
wc.hInstance = hSelf;
wc.lpfnWndProc = BatteryWindowProc;
wc.lpszClassName = L"MozillaBatteryClass";
RegisterClassW(&wc);
}
sHWnd = CreateWindowW(L"MozillaBatteryClass", L"Battery Watcher",
0, 0, 0, 0, 0,
nullptr, nullptr, hSelf, nullptr);
}
if (sHWnd == nullptr) {
// Couldn't get window; bail.
return;
}
sPowerHandle =
sRegisterPowerSettingNotification(sHWnd,
&GUID_ACDC_POWER_SOURCE,
DEVICE_NOTIFY_WINDOW_HANDLE);
sCapacityHandle =
sRegisterPowerSettingNotification(sHWnd,
&GUID_BATTERY_PERCENTAGE_REMAINING,
DEVICE_NOTIFY_WINDOW_HANDLE);
#else
// } else
// {
// for Windows XP. If we remove Windows XP support,
// we should remove timer-based power notification
sUpdateTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
if (sUpdateTimer) {
sUpdateTimer->InitWithFuncCallback(UpdateHandler,
nullptr,
Preferences::GetInt("dom.battery.timer",
30000 /* 30s */),
nsITimer::TYPE_REPEATING_SLACK);
}
// }
#endif
}
void
DisableBatteryNotifications()
{
#if (WINVER >= 0x0600)
if (sPowerHandle) {
sUnregisterPowerSettingNotification(sPowerHandle);
sPowerHandle = nullptr;
}
if (sCapacityHandle) {
sUnregisterPowerSettingNotification(sCapacityHandle);
sCapacityHandle = nullptr;
}
if (sHWnd) {
DestroyWindow(sHWnd);
sHWnd = nullptr;
}
#else
if (sUpdateTimer) {
sUpdateTimer->Cancel();
sUpdateTimer = nullptr;
}
// }
#endif
}
void
GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
{
SYSTEM_POWER_STATUS status;
if (!GetSystemPowerStatus(&status)) {
aBatteryInfo->level() = kDefaultLevel;
aBatteryInfo->charging() = kDefaultCharging;
aBatteryInfo->remainingTime() = kDefaultRemainingTime;
return;
}
aBatteryInfo->level() =
status.BatteryLifePercent == 255 ? kDefaultLevel
: ((double)status.BatteryLifePercent) / 100.0;
aBatteryInfo->charging() = (status.ACLineStatus != 0);
if (status.ACLineStatus != 0) {
if (aBatteryInfo->level() == 1.0) {
// GetSystemPowerStatus API may returns -1 for BatteryFullLifeTime.
// So, if battery is 100%, set kDefaultRemainingTime at force.
aBatteryInfo->remainingTime() = kDefaultRemainingTime;
} else {
aBatteryInfo->remainingTime() =
status.BatteryFullLifeTime == (DWORD)-1 ? kUnknownRemainingTime
: status.BatteryFullLifeTime;
}
} else {
aBatteryInfo->remainingTime() =
status.BatteryLifeTime == (DWORD)-1 ? kUnknownRemainingTime
: status.BatteryLifeTime;
}
}
} // hal_impl
} // mozilla
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "Hal.h"
#include "HalImpl.h"
#include "nsITimer.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/battery/Constants.h"
#include "nsComponentManagerUtils.h"
#include <windows.h>
#include "mozilla/WindowsVersion.h"
using namespace mozilla::dom::battery;
namespace mozilla {
namespace hal_impl {
static nsCOMPtr<nsITimer> sUpdateTimer;
#if (WINVER >= 0x0600)
/* Power Event API is Vista or later */
static decltype(RegisterPowerSettingNotification)* sRegisterPowerSettingNotification = nullptr;
static decltype(UnregisterPowerSettingNotification)* sUnregisterPowerSettingNotification = nullptr;
static HPOWERNOTIFY sPowerHandle = nullptr;
static HPOWERNOTIFY sCapacityHandle = nullptr;
static HWND sHWnd = nullptr;
#endif
static void
UpdateHandler(nsITimer* aTimer, void* aClosure) {
NS_ASSERTION(!IsVistaOrLater(),
"We shouldn't call this function for Vista or later version!");
static hal::BatteryInformation sLastInfo;
hal::BatteryInformation currentInfo;
hal_impl::GetCurrentBatteryInformation(¤tInfo);
if (sLastInfo.level() != currentInfo.level() ||
sLastInfo.charging() != currentInfo.charging() ||
sLastInfo.remainingTime() != currentInfo.remainingTime()) {
hal::NotifyBatteryChange(currentInfo);
sLastInfo = currentInfo;
}
}
#if (WINVER >= 0x0600)
static
LRESULT CALLBACK
BatteryWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (msg != WM_POWERBROADCAST || wParam != PBT_POWERSETTINGCHANGE) {
return DefWindowProc(hwnd, msg, wParam, lParam);
}
hal::BatteryInformation currentInfo;
// Since we need update remainingTime, we cannot use LPARAM.
hal_impl::GetCurrentBatteryInformation(¤tInfo);
hal::NotifyBatteryChange(currentInfo);
return TRUE;
}
#else
static
LRESULT CALLBACK
BatteryWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) {
if (msg != WM_POWERBROADCAST) {
return DefWindowProc(hwnd, msg, wParam, lParam);
}
hal::BatteryInformation currentInfo;
// Since we need update remainingTime, we cannot use LPARAM.
hal_impl::GetCurrentBatteryInformation(¤tInfo);
hal::NotifyBatteryChange(currentInfo);
return TRUE;
}
#endif
void
EnableBatteryNotifications()
{
#if (WINVER >= 0x0600)
HMODULE hUser32 = GetModuleHandleW(L"USER32.DLL");
if (!sRegisterPowerSettingNotification)
sRegisterPowerSettingNotification = (decltype(RegisterPowerSettingNotification)*)
GetProcAddress(hUser32, "RegisterPowerSettingNotification");
if (!sUnregisterPowerSettingNotification)
sUnregisterPowerSettingNotification = (decltype(UnregisterPowerSettingNotification)*)
GetProcAddress(hUser32, "UnregisterPowerSettingNotification");
if (!sRegisterPowerSettingNotification ||
!sUnregisterPowerSettingNotification) {
NS_ASSERTION(false, "Canot find PowerSettingNotification functions.");
return;
}
// Create custom window to watch battery event
// If we can get Goanna's window handle, this is unnecessary.
if (sHWnd == nullptr) {
WNDCLASSW wc;
HMODULE hSelf = GetModuleHandle(nullptr);
if (!GetClassInfoW(hSelf, L"MozillaBatteryClass", &wc)) {
ZeroMemory(&wc, sizeof(WNDCLASSW));
wc.hInstance = hSelf;
wc.lpfnWndProc = BatteryWindowProc;
wc.lpszClassName = L"MozillaBatteryClass";
RegisterClassW(&wc);
}
sHWnd = CreateWindowW(L"MozillaBatteryClass", L"Battery Watcher",
0, 0, 0, 0, 0,
nullptr, nullptr, hSelf, nullptr);
}
if (sHWnd == nullptr) {
// Couldn't get window; bail.
return;
}
sPowerHandle =
sRegisterPowerSettingNotification(sHWnd,
&GUID_ACDC_POWER_SOURCE,
DEVICE_NOTIFY_WINDOW_HANDLE);
sCapacityHandle =
sRegisterPowerSettingNotification(sHWnd,
&GUID_BATTERY_PERCENTAGE_REMAINING,
DEVICE_NOTIFY_WINDOW_HANDLE);
#else
// } else
// {
// for Windows XP. If we remove Windows XP support,
// we should remove timer-based power notification
sUpdateTimer = do_CreateInstance(NS_TIMER_CONTRACTID);
if (sUpdateTimer) {
sUpdateTimer->InitWithFuncCallback(UpdateHandler,
nullptr,
Preferences::GetInt("dom.battery.timer",
30000 /* 30s */),
nsITimer::TYPE_REPEATING_SLACK);
}
// }
#endif
}
void
DisableBatteryNotifications()
{
#if (WINVER >= 0x0600)
if (sPowerHandle) {
sUnregisterPowerSettingNotification(sPowerHandle);
sPowerHandle = nullptr;
}
if (sCapacityHandle) {
sUnregisterPowerSettingNotification(sCapacityHandle);
sCapacityHandle = nullptr;
}
if (sHWnd) {
DestroyWindow(sHWnd);
sHWnd = nullptr;
}
#else
if (sUpdateTimer) {
sUpdateTimer->Cancel();
sUpdateTimer = nullptr;
}
// }
#endif
}
void
GetCurrentBatteryInformation(hal::BatteryInformation* aBatteryInfo)
{
SYSTEM_POWER_STATUS status;
if (!GetSystemPowerStatus(&status)) {
aBatteryInfo->level() = kDefaultLevel;
aBatteryInfo->charging() = kDefaultCharging;
aBatteryInfo->remainingTime() = kDefaultRemainingTime;
return;
}
aBatteryInfo->level() =
status.BatteryLifePercent == 255 ? kDefaultLevel
: ((double)status.BatteryLifePercent) / 100.0;
aBatteryInfo->charging() = (status.ACLineStatus != 0);
if (status.ACLineStatus != 0) {
if (aBatteryInfo->level() == 1.0) {
// GetSystemPowerStatus API may returns -1 for BatteryFullLifeTime.
// So, if battery is 100%, set kDefaultRemainingTime at force.
aBatteryInfo->remainingTime() = kDefaultRemainingTime;
} else {
aBatteryInfo->remainingTime() =
status.BatteryFullLifeTime == (DWORD)-1 ? kUnknownRemainingTime
: status.BatteryFullLifeTime;
}
} else {
aBatteryInfo->remainingTime() =
status.BatteryLifeTime == (DWORD)-1 ? kUnknownRemainingTime
: status.BatteryLifeTime;
}
}
} // hal_impl
} // mozilla
10,12d9
< #undef _WIN32_WINNT
< #define _WIN32_WINNT 0x0600
<
18d14
< #include <winbase.h>
174a171,180
> // Used only when GetTickCount64 is not available on the platform.
> // Last result of GetTickCount call.
> //
> // Kept in [ms]
> static DWORD sLastGTCResult = 0;
>
> // Higher part of the 64-bit value of MozGetTickCount64,
> // incremented atomically.
> static DWORD sLastGTCRollover = 0;
>
176a183,205
> typedef ULONGLONG (WINAPI* GetTickCount64_t)();
> static GetTickCount64_t sGetTickCount64 = nullptr;
>
> // Function protecting GetTickCount result from rolling over,
> // result is in [ms]
> static ULONGLONG WINAPI
> MozGetTickCount64()
> {
> DWORD GTC = ::GetTickCount();
>
> // Cheaper then CMPXCHG8B
> AutoCriticalSection lock(&sTimeStampLock);
>
> // Pull the rollover counter forward only if new value of GTC goes way
> // down under the last saved result
> if ((sLastGTCResult > GTC) && ((sLastGTCResult - GTC) > (1UL << 30))) {
> ++sLastGTCRollover;
> }
>
> sLastGTCResult = GTC;
> return ULONGLONG(sLastGTCRollover) << 32 | sLastGTCResult;
> }
>
341c370
< uint64_t now = ms2mt(GetTickCount64());
---
> uint64_t now = ms2mt(sGetTickCount64());
462a492,502
> // Decide which implementation to use for the high-performance timer.
>
> HMODULE kernelDLL = GetModuleHandleW(L"kernel32.dll");
> sGetTickCount64 = reinterpret_cast<GetTickCount64_t>(
> GetProcAddress(kernelDLL, "GetTickCount64"));
> if (!sGetTickCount64) {
> // If the platform does not support the GetTickCount64 (Windows XP doesn't),
> // then use our fallback implementation based on GetTickCount.
> sGetTickCount64 = MozGetTickCount64;
> }
>
501c541
< ULONGLONG GTC = ms2mt(GetTickCount64());
---
> ULONGLONG GTC = ms2mt(sGetTickCount64());
< #undef _WIN32_WINNT
< #define _WIN32_WINNT 0x0600
<
18d14
< #include <winbase.h>
174a171,180
> // Used only when GetTickCount64 is not available on the platform.
> // Last result of GetTickCount call.
> //
> // Kept in [ms]
> static DWORD sLastGTCResult = 0;
>
> // Higher part of the 64-bit value of MozGetTickCount64,
> // incremented atomically.
> static DWORD sLastGTCRollover = 0;
>
176a183,205
> typedef ULONGLONG (WINAPI* GetTickCount64_t)();
> static GetTickCount64_t sGetTickCount64 = nullptr;
>
> // Function protecting GetTickCount result from rolling over,
> // result is in [ms]
> static ULONGLONG WINAPI
> MozGetTickCount64()
> {
> DWORD GTC = ::GetTickCount();
>
> // Cheaper then CMPXCHG8B
> AutoCriticalSection lock(&sTimeStampLock);
>
> // Pull the rollover counter forward only if new value of GTC goes way
> // down under the last saved result
> if ((sLastGTCResult > GTC) && ((sLastGTCResult - GTC) > (1UL << 30))) {
> ++sLastGTCRollover;
> }
>
> sLastGTCResult = GTC;
> return ULONGLONG(sLastGTCRollover) << 32 | sLastGTCResult;
> }
>
341c370
< uint64_t now = ms2mt(GetTickCount64());
---
> uint64_t now = ms2mt(sGetTickCount64());
462a492,502
> // Decide which implementation to use for the high-performance timer.
>
> HMODULE kernelDLL = GetModuleHandleW(L"kernel32.dll");
> sGetTickCount64 = reinterpret_cast<GetTickCount64_t>(
> GetProcAddress(kernelDLL, "GetTickCount64"));
> if (!sGetTickCount64) {
> // If the platform does not support the GetTickCount64 (Windows XP doesn't),
> // then use our fallback implementation based on GetTickCount.
> sGetTickCount64 = MozGetTickCount64;
> }
>
501c541
< ULONGLONG GTC = ms2mt(GetTickCount64());
---
> ULONGLONG GTC = ms2mt(sGetTickCount64());