Bug 736481 - 2/7 - lose WebGL context on memory-pressure events - r=jgilbert, a=blocking-fennec

This commit is contained in:
Benoit Jacob 2012-04-21 16:48:22 -04:00
parent 7e0123bd58
commit 3c1e40fdd9
2 changed files with 42 additions and 0 deletions

View File

@ -71,10 +71,25 @@
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
#include "nsIObserverService.h"
using namespace mozilla;
using namespace mozilla::gl;
using namespace mozilla::layers;
NS_IMPL_ISUPPORTS1(WebGLMemoryPressureObserver, nsIObserver)
NS_IMETHODIMP
WebGLMemoryPressureObserver::Observe(nsISupports* aSubject,
const char* aTopic,
const PRUnichar* aSomeData)
{
if (strcmp(aTopic, "memory-pressure") == 0)
mContext->ForceLoseContext();
return NS_OK;
}
nsresult NS_NewCanvasRenderingContextWebGL(nsIDOMWebGLRenderingContext** aResult);
@ -172,6 +187,16 @@ WebGLContext::WebGLContext()
mContextRestorer = do_CreateInstance("@mozilla.org/timer;1");
mContextStatus = ContextStable;
mContextLostErrorSet = false;
nsRefPtr<WebGLMemoryPressureObserver> memoryPressureObserver
= new WebGLMemoryPressureObserver(this);
nsCOMPtr<nsIObserverService> observerService
= mozilla::services::GetObserverService();
if (observerService) {
observerService->AddObserver(memoryPressureObserver,
"memory-pressure",
false);
}
}
WebGLContext::~WebGLContext()

View File

@ -59,6 +59,7 @@
#include "nsIJSNativeInitializer.h"
#include "nsContentUtils.h"
#include "nsWrapperCache.h"
#include "nsIObserver.h"
#include "GLContextProvider.h"
#include "Layers.h"
@ -526,6 +527,7 @@ class WebGLContext :
friend class WebGLMemoryMultiReporterWrapper;
friend class WebGLExtensionLoseContext;
friend class WebGLContextUserData;
friend class WebGLMemoryPressureObserver;
public:
WebGLContext();
@ -2887,6 +2889,21 @@ class WebGLMemoryMultiReporterWrapper
}
};
class WebGLMemoryPressureObserver MOZ_FINAL
: public nsIObserver
{
public:
NS_DECL_ISUPPORTS
NS_DECL_NSIOBSERVER
WebGLMemoryPressureObserver(WebGLContext *context)
: mContext(context)
{}
private:
WebGLContext *mContext;
};
}
#endif