Bug 1154231 - Part 1. Reclaim cached resources when memory-pressure occurs. r=mattwoodrow
This commit is contained in:
@@ -118,6 +118,11 @@ PuppetWidget::Create(nsIWidget *aParent,
|
||||
else {
|
||||
Resize(mBounds.x, mBounds.y, mBounds.width, mBounds.height, false);
|
||||
}
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
mMemoryPressureObserver = new MemoryPressureObserver(this);
|
||||
obs->AddObserver(mMemoryPressureObserver, "memory-pressure", false);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -153,6 +158,9 @@ PuppetWidget::Destroy()
|
||||
Base::OnDestroy();
|
||||
Base::Destroy();
|
||||
mPaintTask.Revoke();
|
||||
if (mMemoryPressureObserver) {
|
||||
mMemoryPressureObserver->Remove();
|
||||
}
|
||||
mChild = nullptr;
|
||||
if (mLayerManager) {
|
||||
mLayerManager->Destroy();
|
||||
@@ -175,10 +183,6 @@ PuppetWidget::Show(bool aState)
|
||||
mChild->mVisible = aState;
|
||||
}
|
||||
|
||||
if (!mVisible && mLayerManager) {
|
||||
mLayerManager->ClearCachedResources();
|
||||
}
|
||||
|
||||
if (!wasVisible && mVisible) {
|
||||
Resize(mBounds.width, mBounds.height, false);
|
||||
Invalidate(mBounds);
|
||||
@@ -1030,6 +1034,35 @@ PuppetWidget::PaintTask::Run()
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(PuppetWidget::MemoryPressureObserver, nsIObserver)
|
||||
|
||||
NS_IMETHODIMP
|
||||
PuppetWidget::MemoryPressureObserver::Observe(nsISupports* aSubject,
|
||||
const char* aTopic,
|
||||
const char16_t* aData)
|
||||
{
|
||||
if (!mWidget) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (strcmp("memory-pressure", aTopic) == 0) {
|
||||
if (!mWidget->mVisible && mWidget->mLayerManager) {
|
||||
mWidget->mLayerManager->ClearCachedResources();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
PuppetWidget::MemoryPressureObserver::Remove()
|
||||
{
|
||||
nsCOMPtr<nsIObserverService> obs = mozilla::services::GetObserverService();
|
||||
if (obs) {
|
||||
obs->RemoveObserver(this, "memory-pressure");
|
||||
}
|
||||
mWidget = nullptr;
|
||||
}
|
||||
|
||||
bool
|
||||
PuppetWidget::NeedsPaint()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user