mirror of
https://github.com/roytam1/palemoon27.git
synced 2026-05-26 14:30:27 +00:00
6a3c8aef33
- Bug 1125514 - Use jemalloc's metadata statistics to compute bookkeeping. r=glandium (541dbcfc6f) - Bug 1201462 - Don't count arena allocated metadata once per bin. r=glandium (57e7c31081) - back some warnings (377df69d65) - Bug 1219501. In imagelib, initialize the number of cores to at least 1 in case of error. r=seth (3d7d1635f0) - Bug 1219501. Limit total number of image decoding threads to 32 regardless of number asked for. r=seth (829a7a623d) - Bug 1213744 (Part 1) - Support zero-size frame rects and detecting the end of the frame in Downscaler. r=tn (05e29075cc) - Bug 1213744 (Part 2) - Clamp the GIF frame rect to the visible rect for DDD and don't decode outside it. r=tn (8a25e10a3e) - Bug 1194837. Don't use the inverse orientation matrix when computing the image space invalidate rect. r=seth (cb5e4c2643) - Bug 1214054 - Don't fire DECODE_COMPLETE in VectorImage::OnSVGDocumetError(). r=dholbert (bb7c34e46f) - Bug 1195878 - If we detect animation during a full decode, drop the results of the full decode on the floor. r=tn (a765af2b68) - Bug 1210553 - Remove the alternate flags arguments from SurfaceCache's Lookup functions. r=dholbert (15c6124f98) - Bug 1217320 - Remove more XPIDL signature comments in .cpp files. r=froydnj (411ac93047) - Bug 1186796 - Replace nsBaseHashtable::EnumerateRead() calls in image/ with iterators r=njn (665773ae6d) - Bug 1186792 - Replace nsBaseHashtable::EnumerateRead() calls in hal/ with iterators. r=dhylands. (d57c6b11da) - Bug 1187142 - Replace nsBaseHashtable::Enumerate() calls in hal/ with iterators. r=dhylands. (ec05c5b125) - Bug 1186793 - Replace nsBaseHashtable::EnumerateRead() calls in gfx/ with iterators r=njn (9b3cdd92ce) - Bug 1215900 - Fix clang's -Wimplicit-fallthrough warnings in gfx/ipc/ GfxMessageUtils.h. r=mstange (f55605f1fe) - Bug 618898 - Part 1: Add WGL_NV_DX_interop. r=jgilbert (73390398ed) - Bug 618898 - Add D3D11SharedSurfaceInterop. r=jgilbert (3dde956b85) - Bug 1208513 - Resurrect SharedSurface_GLTexture for use on iOS r=jgilbert (b0fdc90414) - Bug 1150760 - Don't call workaround unless necessary. - r=kamidphish (9bdd135931) - Bug 1151106 - let debugger stop on each iteration of a "for(;;)" loop; r=jimb (b1b921c3a7) - Bug 1223652 - Remove redundant else block after return statement in CGBlockScopeList::findEnclosingScope. r=arai (f1368bfc73) - Bug 1219515 - IonMonkey: Fix ThrowIfNotConstructing was not declared. r=evilpie (1d6cedad10) - Bug 1224044 - Use stable hashing in SavedFramePtrHasher r=terrence (4389cf1b70) - Bug 1206596: Change js::SavedStacks to use mozilla::FastBernoulliTrial. r=fitzgen (1c4a8d1929) - Bug 1206357: Add mfbt/FastBernoulliTrial.h, implementing efficient random sampling. r=waldo (7143e53dba) - No bug: Fix comment in mfbt/FastBernoulliTrial.h. DONTBUILD r=me (e3343f8d9d) - Bug 1217919 - Separate dynamic module scopes from those of function calls r=shu (521f6826e5) - Bug 1202568 - Cherry-pick warning fixes from upstream double-conversion. r=Ms2ger (ef738f753b) - add back some disabled android stuff (0351b0c518) - Bug 1135261 - return new window from window.open in desktop runtime; r=marco,smaug,junior,wesj (fa4d8f2468) - Bug 898075 - Remove the mozbrowserasyncscroll event from Gecko. r=botond,kanru,sicking (b1fdcb7630) - namespace (91374d2db8)
282 lines
7.2 KiB
C++
282 lines
7.2 KiB
C++
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
/* 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 "mozilla/HalWakeLock.h"
|
|
#include "mozilla/Services.h"
|
|
#include "mozilla/StaticPtr.h"
|
|
#include "mozilla/dom/ContentParent.h"
|
|
#include "nsClassHashtable.h"
|
|
#include "nsDataHashtable.h"
|
|
#include "nsHashKeys.h"
|
|
#include "nsIPropertyBag2.h"
|
|
#include "nsIObserverService.h"
|
|
|
|
using namespace mozilla;
|
|
using namespace mozilla::hal;
|
|
|
|
namespace {
|
|
|
|
struct LockCount {
|
|
LockCount()
|
|
: numLocks(0)
|
|
, numHidden(0)
|
|
{}
|
|
uint32_t numLocks;
|
|
uint32_t numHidden;
|
|
nsTArray<uint64_t> processes;
|
|
};
|
|
|
|
typedef nsDataHashtable<nsUint64HashKey, LockCount> ProcessLockTable;
|
|
typedef nsClassHashtable<nsStringHashKey, ProcessLockTable> LockTable;
|
|
|
|
int sActiveListeners = 0;
|
|
StaticAutoPtr<LockTable> sLockTable;
|
|
bool sInitialized = false;
|
|
bool sIsShuttingDown = false;
|
|
|
|
WakeLockInformation
|
|
WakeLockInfoFromLockCount(const nsAString& aTopic, const LockCount& aLockCount)
|
|
{
|
|
// TODO: Once we abandon b2g18, we can switch this to use the
|
|
// WakeLockInformation constructor, which is better because it doesn't let us
|
|
// forget to assign a param. For now we have to do it this way, because
|
|
// b2g18 doesn't have the nsTArray <--> InfallibleTArray conversion (bug
|
|
// 819791).
|
|
|
|
WakeLockInformation info;
|
|
info.topic() = aTopic;
|
|
info.numLocks() = aLockCount.numLocks;
|
|
info.numHidden() = aLockCount.numHidden;
|
|
info.lockingProcesses().AppendElements(aLockCount.processes);
|
|
return info;
|
|
}
|
|
|
|
static void
|
|
CountWakeLocks(ProcessLockTable* aTable, LockCount* aTotalCount)
|
|
{
|
|
for (auto iter = aTable->Iter(); !iter.Done(); iter.Next()) {
|
|
const uint64_t& key = iter.Key();
|
|
LockCount count = iter.UserData();
|
|
|
|
aTotalCount->numLocks += count.numLocks;
|
|
aTotalCount->numHidden += count.numHidden;
|
|
|
|
// This is linear in the number of processes, but that should be small.
|
|
if (!aTotalCount->processes.Contains(key)) {
|
|
aTotalCount->processes.AppendElement(key);
|
|
}
|
|
}
|
|
}
|
|
|
|
class ClearHashtableOnShutdown final : public nsIObserver {
|
|
~ClearHashtableOnShutdown() {}
|
|
public:
|
|
NS_DECL_ISUPPORTS
|
|
NS_DECL_NSIOBSERVER
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS(ClearHashtableOnShutdown, nsIObserver)
|
|
|
|
NS_IMETHODIMP
|
|
ClearHashtableOnShutdown::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* data)
|
|
{
|
|
MOZ_ASSERT(!strcmp(aTopic, "xpcom-shutdown"));
|
|
|
|
sIsShuttingDown = true;
|
|
sLockTable = nullptr;
|
|
|
|
return NS_OK;
|
|
}
|
|
|
|
class CleanupOnContentShutdown final : public nsIObserver {
|
|
~CleanupOnContentShutdown() {}
|
|
public:
|
|
NS_DECL_ISUPPORTS
|
|
NS_DECL_NSIOBSERVER
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS(CleanupOnContentShutdown, nsIObserver)
|
|
|
|
NS_IMETHODIMP
|
|
CleanupOnContentShutdown::Observe(nsISupports* aSubject, const char* aTopic, const char16_t* data)
|
|
{
|
|
MOZ_ASSERT(!strcmp(aTopic, "ipc:content-shutdown"));
|
|
|
|
if (sIsShuttingDown) {
|
|
return NS_OK;
|
|
}
|
|
|
|
nsCOMPtr<nsIPropertyBag2> props = do_QueryInterface(aSubject);
|
|
if (!props) {
|
|
NS_WARNING("ipc:content-shutdown message without property bag as subject");
|
|
return NS_OK;
|
|
}
|
|
|
|
uint64_t childID = 0;
|
|
nsresult rv = props->GetPropertyAsUint64(NS_LITERAL_STRING("childID"),
|
|
&childID);
|
|
if (NS_SUCCEEDED(rv)) {
|
|
for (auto iter = sLockTable->Iter(); !iter.Done(); iter.Next()) {
|
|
nsAutoPtr<ProcessLockTable>& table = iter.Data();
|
|
|
|
if (table->Get(childID, nullptr)) {
|
|
table->Remove(childID);
|
|
|
|
LockCount totalCount;
|
|
CountWakeLocks(table, &totalCount);
|
|
|
|
if (sActiveListeners) {
|
|
NotifyWakeLockChange(WakeLockInfoFromLockCount(iter.Key(),
|
|
totalCount));
|
|
}
|
|
|
|
if (totalCount.numLocks == 0) {
|
|
iter.Remove();
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
NS_WARNING("ipc:content-shutdown message without childID property");
|
|
}
|
|
return NS_OK;
|
|
}
|
|
|
|
void
|
|
Init()
|
|
{
|
|
sLockTable = new LockTable();
|
|
sInitialized = true;
|
|
|
|
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
|
if (obs) {
|
|
obs->AddObserver(new ClearHashtableOnShutdown(), "xpcom-shutdown", false);
|
|
obs->AddObserver(new CleanupOnContentShutdown(), "ipc:content-shutdown", false);
|
|
}
|
|
}
|
|
|
|
} // namespace
|
|
|
|
namespace mozilla {
|
|
|
|
namespace hal {
|
|
|
|
WakeLockState
|
|
ComputeWakeLockState(int aNumLocks, int aNumHidden)
|
|
{
|
|
if (aNumLocks == 0) {
|
|
return WAKE_LOCK_STATE_UNLOCKED;
|
|
} else if (aNumLocks == aNumHidden) {
|
|
return WAKE_LOCK_STATE_HIDDEN;
|
|
} else {
|
|
return WAKE_LOCK_STATE_VISIBLE;
|
|
}
|
|
}
|
|
|
|
} // namespace hal
|
|
|
|
namespace hal_impl {
|
|
|
|
void
|
|
EnableWakeLockNotifications()
|
|
{
|
|
sActiveListeners++;
|
|
}
|
|
|
|
void
|
|
DisableWakeLockNotifications()
|
|
{
|
|
sActiveListeners--;
|
|
}
|
|
|
|
void
|
|
ModifyWakeLock(const nsAString& aTopic,
|
|
hal::WakeLockControl aLockAdjust,
|
|
hal::WakeLockControl aHiddenAdjust,
|
|
uint64_t aProcessID)
|
|
{
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
MOZ_ASSERT(aProcessID != CONTENT_PROCESS_ID_UNKNOWN);
|
|
|
|
if (sIsShuttingDown) {
|
|
return;
|
|
}
|
|
if (!sInitialized) {
|
|
Init();
|
|
}
|
|
|
|
ProcessLockTable* table = sLockTable->Get(aTopic);
|
|
LockCount processCount;
|
|
LockCount totalCount;
|
|
if (!table) {
|
|
table = new ProcessLockTable();
|
|
sLockTable->Put(aTopic, table);
|
|
} else {
|
|
table->Get(aProcessID, &processCount);
|
|
CountWakeLocks(table, &totalCount);
|
|
}
|
|
|
|
MOZ_ASSERT(processCount.numLocks >= processCount.numHidden);
|
|
MOZ_ASSERT(aLockAdjust >= 0 || processCount.numLocks > 0);
|
|
MOZ_ASSERT(aHiddenAdjust >= 0 || processCount.numHidden > 0);
|
|
MOZ_ASSERT(totalCount.numLocks >= totalCount.numHidden);
|
|
MOZ_ASSERT(aLockAdjust >= 0 || totalCount.numLocks > 0);
|
|
MOZ_ASSERT(aHiddenAdjust >= 0 || totalCount.numHidden > 0);
|
|
|
|
WakeLockState oldState = ComputeWakeLockState(totalCount.numLocks, totalCount.numHidden);
|
|
bool processWasLocked = processCount.numLocks > 0;
|
|
|
|
processCount.numLocks += aLockAdjust;
|
|
processCount.numHidden += aHiddenAdjust;
|
|
|
|
totalCount.numLocks += aLockAdjust;
|
|
totalCount.numHidden += aHiddenAdjust;
|
|
|
|
if (processCount.numLocks) {
|
|
table->Put(aProcessID, processCount);
|
|
} else {
|
|
table->Remove(aProcessID);
|
|
}
|
|
if (!totalCount.numLocks) {
|
|
sLockTable->Remove(aTopic);
|
|
}
|
|
|
|
if (sActiveListeners &&
|
|
(oldState != ComputeWakeLockState(totalCount.numLocks,
|
|
totalCount.numHidden) ||
|
|
processWasLocked != (processCount.numLocks > 0))) {
|
|
|
|
WakeLockInformation info;
|
|
hal::GetWakeLockInfo(aTopic, &info);
|
|
NotifyWakeLockChange(info);
|
|
}
|
|
}
|
|
|
|
void
|
|
GetWakeLockInfo(const nsAString& aTopic, WakeLockInformation* aWakeLockInfo)
|
|
{
|
|
if (sIsShuttingDown) {
|
|
NS_WARNING("You don't want to get wake lock information during xpcom-shutdown!");
|
|
*aWakeLockInfo = WakeLockInformation();
|
|
return;
|
|
}
|
|
if (!sInitialized) {
|
|
Init();
|
|
}
|
|
|
|
ProcessLockTable* table = sLockTable->Get(aTopic);
|
|
if (!table) {
|
|
*aWakeLockInfo = WakeLockInfoFromLockCount(aTopic, LockCount());
|
|
return;
|
|
}
|
|
LockCount totalCount;
|
|
CountWakeLocks(table, &totalCount);
|
|
*aWakeLockInfo = WakeLockInfoFromLockCount(aTopic, totalCount);
|
|
}
|
|
|
|
} // namespace hal_impl
|
|
} // namespace mozilla
|