Bug 1171371 - On memory-pressure, remove any stale images from the visible images list. r=tn

This commit is contained in:
Seth Fowler 2015-06-04 11:08:19 -07:00
Родитель 7af5b304e6
Коммит b4ddf9bb30
3 изменённых файлов: 31 добавлений и 8 удалений

Просмотреть файл

@ -1570,7 +1570,8 @@ public:
// Clears the current list of visible images on this presshell and replaces it
// with images that are in the display list aList.
virtual void RebuildImageVisibilityDisplayList(const nsDisplayList& aList) = 0;
virtual void RebuildImageVisibility(nsRect* aRect = nullptr) = 0;
virtual void RebuildImageVisibility(nsRect* aRect = nullptr,
bool aRemoveOnly = false) = 0;
// Ensures the image is in the list of visible images.
virtual void EnsureImageInVisibleList(nsIImageLoadingContent* aImage) = 0;

Просмотреть файл

@ -920,6 +920,7 @@ PresShell::Init(nsIDocument* aDocument,
#ifdef MOZ_XUL
os->AddObserver(this, "chrome-flush-skin-caches", false);
#endif
os->AddObserver(this, "memory-pressure", false);
}
}
@ -1144,6 +1145,7 @@ PresShell::Destroy()
#ifdef MOZ_XUL
os->RemoveObserver(this, "chrome-flush-skin-caches");
#endif
os->RemoveObserver(this, "memory-pressure");
}
}
@ -5587,12 +5589,15 @@ PresShell::ClearVisibleImagesList(uint32_t aNonvisibleAction)
}
void
PresShell::MarkImagesInSubtreeVisible(nsIFrame* aFrame, const nsRect& aRect)
PresShell::MarkImagesInSubtreeVisible(nsIFrame* aFrame,
const nsRect& aRect,
bool aRemoveOnly /* = false */)
{
MOZ_ASSERT(aFrame->PresContext()->PresShell() == this, "wrong presshell");
nsCOMPtr<nsIImageLoadingContent> content(do_QueryInterface(aFrame->GetContent()));
if (content && aFrame->StyleVisibility()->IsVisible()) {
if (content && aFrame->StyleVisibility()->IsVisible() &&
(!aRemoveOnly || content->GetVisibleCount() > 0)) {
uint32_t count = mVisibleImages.Count();
mVisibleImages.PutEntry(content);
if (mVisibleImages.Count() > count) {
@ -5673,7 +5678,8 @@ PresShell::MarkImagesInSubtreeVisible(nsIFrame* aFrame, const nsRect& aRect)
}
void
PresShell::RebuildImageVisibility(nsRect* aRect)
PresShell::RebuildImageVisibility(nsRect* aRect,
bool aRemoveOnly /* = false */)
{
MOZ_ASSERT(!mImageVisibilityVisited, "already visited?");
mImageVisibilityVisited = true;
@ -5692,7 +5698,7 @@ PresShell::RebuildImageVisibility(nsRect* aRect)
if (aRect) {
vis = *aRect;
}
MarkImagesInSubtreeVisible(rootFrame, vis);
MarkImagesInSubtreeVisible(rootFrame, vis, aRemoveOnly);
DecrementVisibleCount(oldVisibleImages,
nsIImageLoadingContent::ON_NONVISIBLE_NO_ACTION);
@ -5700,6 +5706,12 @@ PresShell::RebuildImageVisibility(nsRect* aRect)
void
PresShell::UpdateImageVisibility()
{
DoUpdateImageVisibility(/* aRemoveOnly = */ false);
}
void
PresShell::DoUpdateImageVisibility(bool aRemoveOnly)
{
MOZ_ASSERT(!mPresContext || mPresContext->IsRootContentDocument(),
"updating image visibility on a non-root content document?");
@ -5718,7 +5730,7 @@ PresShell::UpdateImageVisibility()
return;
}
RebuildImageVisibility();
RebuildImageVisibility(/* aRect = */ nullptr, aRemoveOnly);
ClearImageVisibilityVisited(rootFrame->GetView(), true);
#ifdef DEBUG_IMAGE_VISIBILITY_DISPLAY_LIST
@ -9326,6 +9338,13 @@ PresShell::Observe(nsISupports* aSubject,
return NS_OK;
}
if (!nsCRT::strcmp(aTopic, "memory-pressure") &&
!AssumeAllImagesVisible() &&
mPresContext->IsRootContentDocument()) {
DoUpdateImageVisibility(/* aRemoveOnly = */ true);
return NS_OK;
}
NS_WARNING("unrecognized topic in PresShell::Observe");
return NS_ERROR_FAILURE;
}

Просмотреть файл

@ -374,7 +374,8 @@ public:
virtual void ScheduleImageVisibilityUpdate() override;
virtual void RebuildImageVisibilityDisplayList(const nsDisplayList& aList) override;
virtual void RebuildImageVisibility(nsRect* aRect = nullptr) override;
virtual void RebuildImageVisibility(nsRect* aRect = nullptr,
bool aRemoveOnly = false) override;
virtual void EnsureImageInVisibleList(nsIImageLoadingContent* aImage) override;
@ -726,6 +727,7 @@ protected:
virtual void ResumePainting() override;
void UpdateImageVisibility();
void DoUpdateImageVisibility(bool aRemoveOnly);
void UpdateActivePointerState(mozilla::WidgetGUIEvent* aEvent);
nsRevocableEventPtr<nsRunnableMethod<PresShell> > mUpdateImageVisibilityEvent;
@ -733,7 +735,8 @@ protected:
void ClearVisibleImagesList(uint32_t aNonvisibleAction);
static void ClearImageVisibilityVisited(nsView* aView, bool aClear);
static void MarkImagesInListVisible(const nsDisplayList& aList);
void MarkImagesInSubtreeVisible(nsIFrame* aFrame, const nsRect& aRect);
void MarkImagesInSubtreeVisible(nsIFrame* aFrame, const nsRect& aRect,
bool aRemoveOnly = false);
// Methods for dispatching KeyboardEvent and BeforeAfterKeyboardEvent.
void HandleKeyboardEvent(nsINode* aTarget,