зеркало из https://github.com/mozilla/pjs.git
Bug 736481 - 2/7 - lose WebGL context on memory-pressure events - r=jgilbert, a=blocking-fennec
This commit is contained in:
Родитель
f90767cb46
Коммит
c1d156e099
|
@ -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()
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче