Bug 823610: Make discarding GL contexts of foreground pages on memory pressure pref-able, and pref off for b2g. r=jgilbert,jlebar

This commit is contained in:
Chris Jones 2013-01-03 15:39:25 -08:00
parent 25eb36e582
commit 90fdd69121
8 changed files with 39 additions and 4 deletions

View File

@ -615,3 +615,7 @@ pref("wap.UAProf.tagname", "x-wap-profile");
// Wait up to this much milliseconds when orientation changed
pref("layers.orientation.sync.timeout", 1000);
// Don't discard WebGL contexts for foreground apps on memory
// pressure.
pref("webgl.can-lose-context-in-foreground", false);

View File

@ -45,12 +45,14 @@
#include "mozilla/Services.h"
#include "mozilla/dom/WebGLRenderingContextBinding.h"
#include "mozilla/dom/BindingUtils.h"
#include "mozilla/dom/ipc/ProcessPriorityManager.h"
#include "Layers.h"
using namespace mozilla;
using namespace mozilla::gl;
using namespace mozilla::dom;
using namespace mozilla::dom::ipc;
using namespace mozilla::layers;
NS_IMETHODIMP
@ -63,7 +65,10 @@ WebGLMemoryPressureObserver::Observe(nsISupports* aSubject,
bool wantToLoseContext = true;
if (!nsCRT::strcmp(aSomeData, NS_LITERAL_STRING("heap-minimize").get()))
if (!mContext->mCanLoseContextInForeground && CurrentProcessIsForeground())
wantToLoseContext = false;
else if (!nsCRT::strcmp(aSomeData,
NS_LITERAL_STRING("heap-minimize").get()))
wantToLoseContext = mContext->mLoseContextOnHeapMinimize;
if (wantToLoseContext)
@ -179,6 +184,7 @@ WebGLContext::WebGLContext()
mContextStatus = ContextStable;
mContextLostErrorSet = false;
mLoseContextOnHeapMinimize = false;
mCanLoseContextInForeground = true;
mAlreadyGeneratedWarnings = 0;
mAlreadyWarnedAboutFakeVertexAttrib0 = false;

View File

@ -843,6 +843,7 @@ protected:
bool mHasRobustness;
bool mIsMesa;
bool mLoseContextOnHeapMinimize;
bool mCanLoseContextInForeground;
template<typename WebGLObjectType>
void DeleteWebGLObjectsArray(nsTArray<WebGLObjectType>& array);

View File

@ -858,6 +858,7 @@ WebGLContext::InitAndValidateGL()
mMinCapability = Preferences::GetBool("webgl.min_capability_mode", false);
mDisableExtensions = Preferences::GetBool("webgl.disable-extensions", false);
mLoseContextOnHeapMinimize = Preferences::GetBool("webgl.lose-context-on-heap-minimize", false);
mCanLoseContextInForeground = Preferences::GetBool("webgl.can-lose-context-in-foreground", true);
mActiveTexture = 0;
mWebGLError = LOCAL_GL_NO_ERROR;

View File

@ -4,6 +4,7 @@
* 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 "mozilla/ClearOnShutdown.h"
#include "mozilla/dom/ipc/ProcessPriorityManager.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/TabChild.h"
@ -26,6 +27,7 @@
#include "nsIDOMEventTarget.h"
#include "nsIDOMDocument.h"
#include "nsPIDOMWindow.h"
#include "StaticPtr.h"
#ifdef XP_WIN
#include <process.h>
@ -42,6 +44,8 @@ namespace ipc {
namespace {
static bool sInitialized = false;
class ProcessPriorityManager;
static StaticRefPtr<ProcessPriorityManager> sManager;
// Some header defines a LOG macro, but we don't want it here.
#ifdef LOG
@ -127,6 +131,8 @@ public:
NS_DECL_NSIOBSERVER
NS_DECL_NSIDOMEVENTLISTENER
ProcessPriority GetPriority() const { return mProcessPriority; }
private:
void SetPriority(ProcessPriority aPriority);
void OnContentDocumentGlobalCreated(nsISupports* aOuterWindow);
@ -389,9 +395,15 @@ InitProcessPriorityManager()
return;
}
// This object is held alive by the observer service.
nsRefPtr<ProcessPriorityManager> mgr = new ProcessPriorityManager();
mgr->Init();
sManager = new ProcessPriorityManager();
sManager->Init();
ClearOnShutdown(&sManager);
}
bool
CurrentProcessIsForeground()
{
return sManager->GetPriority() >= PROCESS_PRIORITY_FOREGROUND;
}
} // namespace ipc

View File

@ -26,6 +26,13 @@ namespace ipc {
*/
void InitProcessPriorityManager();
/**
* True iff the current process has foreground or higher priority as
* computed by DOM visibility. The returned answer may not match the
* actual OS process priority, for short intervals.
*/
bool CurrentProcessIsForeground();
} // namespace ipc
} // namespace dom
} // namespace mozilla

View File

@ -70,6 +70,9 @@ typedef Observer<SwitchEvent> SwitchObserver;
enum ProcessPriority {
PROCESS_PRIORITY_BACKGROUND,
PROCESS_PRIORITY_BACKGROUND_HOMESCREEN,
// Any priority greater than or equal to FOREGROUND is considered
// "foreground" for the purposes of priority testing, for example
// CurrentProcessIsForeground().
PROCESS_PRIORITY_FOREGROUND,
PROCESS_PRIORITY_MASTER,
NUM_PROCESS_PRIORITY

View File

@ -3706,6 +3706,7 @@ pref("webgl.prefer-16bpp", false);
pref("webgl.default-no-alpha", false);
pref("webgl.force-layers-readback", false);
pref("webgl.lose-context-on-heap-minimize", false);
pref("webgl.can-lose-context-in-foreground", true);
// Stagefright prefs
pref("stagefright.force-enabled", false);