Bug 736481 - 5/7 - make memory-pressure observer lifetime match WebGL context lifetime - r=jgilbert, a=blocking-fennec

This commit is contained in:
Benoit Jacob 2012-04-21 16:48:22 -04:00
parent b5fa6b73b1
commit 674aed832a
3 changed files with 25 additions and 11 deletions

View File

@ -187,16 +187,6 @@ 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()
@ -210,6 +200,16 @@ WebGLContext::~WebGLContext()
void
WebGLContext::DestroyResourcesAndContext()
{
if (mMemoryPressureObserver) {
nsCOMPtr<nsIObserverService> observerService
= mozilla::services::GetObserverService();
if (observerService) {
observerService->RemoveObserver(mMemoryPressureObserver,
"memory-pressure");
}
mMemoryPressureObserver = nsnull;
}
if (!gl)
return;

View File

@ -104,8 +104,9 @@ class WebGLFramebuffer;
class WebGLRenderbuffer;
class WebGLUniformLocation;
class WebGLExtension;
class WebGLContext;
struct WebGLVertexAttribData;
class WebGLMemoryPressureObserver;
class WebGLRectangleObject;
class WebGLContextBoundObject;
@ -959,6 +960,7 @@ protected:
ForceDiscreteGPUHelperCGL mForceDiscreteGPUHelper;
#endif
nsRefPtr<WebGLMemoryPressureObserver> mMemoryPressureObserver;
public:
// console logging helpers

View File

@ -51,6 +51,8 @@
#include <algorithm>
#include "nsIObserverService.h"
using namespace mozilla;
/*
@ -679,5 +681,15 @@ WebGLContext::InitAndValidateGL()
return false;
}
mMemoryPressureObserver
= new WebGLMemoryPressureObserver(this);
nsCOMPtr<nsIObserverService> observerService
= mozilla::services::GetObserverService();
if (observerService) {
observerService->AddObserver(mMemoryPressureObserver,
"memory-pressure",
false);
}
return true;
}