зеркало из https://github.com/mozilla/gecko-dev.git
Bug 927254 - Purge SkiaGL texture cache on memory pressure r=gwright
--HG-- extra : rebase_source : 0b6c68c129319c96ad3056ab7b6321c04c7fbcb5
This commit is contained in:
Родитель
4f93036d32
Коммит
c7ee4d278f
|
@ -1007,6 +1007,8 @@ public:
|
|||
SetGlobalSkiaCacheLimits(int aCount, int aSizeInBytes);
|
||||
#endif
|
||||
|
||||
static void PurgeTextureCaches();
|
||||
|
||||
#if defined(USE_SKIA) && defined(MOZ_ENABLE_FREETYPE)
|
||||
static TemporaryRef<GlyphRenderingOptions>
|
||||
CreateCairoGlyphRenderingOptions(FontHinting aHinting, bool aAutoHinting);
|
||||
|
|
|
@ -128,6 +128,28 @@ DrawTargetSkia::SetGlobalCacheLimits(int aCount, int aSizeInBytes)
|
|||
|
||||
DrawTargetSkia::RebalanceCacheLimits();
|
||||
}
|
||||
|
||||
void
|
||||
DrawTargetSkia::PurgeCache()
|
||||
{
|
||||
if (mGrContext) {
|
||||
mGrContext->purgeCache();
|
||||
}
|
||||
}
|
||||
|
||||
/* static */ void
|
||||
DrawTargetSkia::PurgeTextureCaches()
|
||||
{
|
||||
std::vector<DrawTargetSkia*>& targets = GLDrawTargets();
|
||||
uint32_t targetCount = targets.size();
|
||||
if (targetCount == 0)
|
||||
return;
|
||||
|
||||
for (uint32_t i = 0; i < targetCount; i++) {
|
||||
targets[i]->PurgeCache();
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
DrawTargetSkia::DrawTargetSkia()
|
||||
|
|
|
@ -106,8 +106,11 @@ public:
|
|||
SurfaceFormat aFormat) MOZ_OVERRIDE;
|
||||
|
||||
void SetCacheLimits(int aCount, int aSizeInBytes);
|
||||
void PurgeCache();
|
||||
|
||||
static void SetGlobalCacheLimits(int aCount, int aSizeInBytes);
|
||||
static void RebalanceCacheLimits();
|
||||
static void PurgeTextureCaches();
|
||||
#endif
|
||||
|
||||
operator std::string() const {
|
||||
|
|
|
@ -521,6 +521,14 @@ Factory::SetGlobalSkiaCacheLimits(int aCount, int aSizeInBytes)
|
|||
}
|
||||
#endif // USE_SKIA_GPU
|
||||
|
||||
void
|
||||
Factory::PurgeTextureCaches()
|
||||
{
|
||||
#ifdef USE_SKIA_GPU
|
||||
DrawTargetSkia::PurgeTextureCaches();
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef USE_SKIA_FREETYPE
|
||||
TemporaryRef<GlyphRenderingOptions>
|
||||
Factory::CreateCairoGlyphRenderingOptions(FontHinting aHinting, bool aAutoHinting)
|
||||
|
|
|
@ -46,6 +46,7 @@
|
|||
#include "nsServiceManagerUtils.h"
|
||||
#include "nsTArray.h"
|
||||
#include "nsILocaleService.h"
|
||||
#include "nsIObserverService.h"
|
||||
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
|
@ -204,6 +205,25 @@ OrientationSyncPrefsObserver::Observe(nsISupports *aSubject,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
class MemoryPressureObserver MOZ_FINAL : public nsIObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIOBSERVER
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(MemoryPressureObserver, nsIObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
MemoryPressureObserver::Observe(nsISupports *aSubject,
|
||||
const char *aTopic,
|
||||
const PRUnichar *someData)
|
||||
{
|
||||
NS_ASSERTION(NS_strcmp(aTopic, "memory-pressure") == 0, "unexpected event topic");
|
||||
Factory::PurgeTextureCaches();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// this needs to match the list of pref font.default.xx entries listed in all.js!
|
||||
// the order *must* match the order in eFontPrefLang
|
||||
static const char *gPrefLangNames[] = {
|
||||
|
@ -278,10 +298,6 @@ gfxPlatform::gfxPlatform()
|
|||
uint32_t canvasMask = (1 << BACKEND_CAIRO) | (1 << BACKEND_SKIA);
|
||||
uint32_t contentMask = 1 << BACKEND_CAIRO;
|
||||
InitBackendPrefs(canvasMask, contentMask);
|
||||
|
||||
#ifdef USE_SKIA
|
||||
InitializeSkiaCaches();
|
||||
#endif
|
||||
}
|
||||
|
||||
gfxPlatform*
|
||||
|
@ -446,6 +462,17 @@ gfxPlatform::Init()
|
|||
false);
|
||||
|
||||
CreateCMSOutputProfile();
|
||||
|
||||
#ifdef USE_SKIA
|
||||
gPlatform->InitializeSkiaCaches();
|
||||
#endif
|
||||
|
||||
// Listen to memory pressure event so we can purge DrawTarget caches
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
gPlatform->mMemoryPressureObserver = new MemoryPressureObserver();
|
||||
obs->AddObserver(gPlatform->mMemoryPressureObserver, "memory-pressure", false);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -474,6 +501,14 @@ gfxPlatform::Shutdown()
|
|||
NS_ASSERTION(gPlatform->mFontPrefsObserver, "mFontPrefsObserver has alreay gone");
|
||||
Preferences::RemoveObservers(gPlatform->mFontPrefsObserver, kObservedPrefs);
|
||||
gPlatform->mFontPrefsObserver = nullptr;
|
||||
|
||||
NS_ASSERTION(gPlatform->mMemoryPressureObserver, "mMemoryPressureObserver has already gone");
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->RemoveObserver(gPlatform->mMemoryPressureObserver, "memory-pressure");
|
||||
}
|
||||
|
||||
gPlatform->mMemoryPressureObserver = nullptr;
|
||||
}
|
||||
|
||||
#ifdef MOZ_WIDGET_ANDROID
|
||||
|
|
|
@ -716,6 +716,7 @@ private:
|
|||
nsCOMPtr<nsIObserver> mSRGBOverrideObserver;
|
||||
nsCOMPtr<nsIObserver> mFontPrefsObserver;
|
||||
nsCOMPtr<nsIObserver> mOrientationSyncPrefsObserver;
|
||||
nsCOMPtr<nsIObserver> mMemoryPressureObserver;
|
||||
|
||||
// The preferred draw target backend to use for canvas
|
||||
mozilla::gfx::BackendType mPreferredCanvasBackend;
|
||||
|
|
Загрузка…
Ссылка в новой задаче