Backed out changeset b44e10f83623 (bug 1125490)

This commit is contained in:
Carsten "Tomcat" Book 2015-01-27 11:15:04 +01:00
parent 875e05e29d
commit 4b5cf31784
6 changed files with 48 additions and 69 deletions

View File

@ -172,15 +172,10 @@ interface nsIImageLoadingContent : imgINotificationObserver
* A visible count is stored, if it is non-zero then this image is considered
* visible. These methods increment, decrement, or return the visible count.
*
* @param aNonvisibleAction What to do if the image's visibility count is now
* zero. If ON_NONVISIBLE_NO_ACTION, nothing will be
* done. If ON_NONVISIBLE_REQUEST_DISCARD, the image
* will be asked to discard its surfaces if possible.
* @param aRequestDiscard Whether to attempt to discard the image if its
* visibility count is now zero.
*/
[noscript, notxpcom] void IncrementVisibleCount();
[noscript, notxpcom] void DecrementVisibleCount(in uint32_t aNonvisibleAction);
[noscript, notxpcom] void DecrementVisibleCount(in boolean aRequestDiscard);
[noscript, notxpcom] uint32_t GetVisibleCount();
const long ON_NONVISIBLE_NO_ACTION = 0;
const long ON_NONVISIBLE_REQUEST_DISCARD = 1;
};

View File

@ -105,8 +105,8 @@ nsImageLoadingContent::DestroyImageLoadingContent()
{
// Cancel our requests so they won't hold stale refs to us
// NB: Don't ask to discard the images here.
ClearCurrentRequest(NS_BINDING_ABORTED, ON_NONVISIBLE_NO_ACTION);
ClearPendingRequest(NS_BINDING_ABORTED, ON_NONVISIBLE_NO_ACTION);
ClearCurrentRequest(NS_BINDING_ABORTED, 0);
ClearPendingRequest(NS_BINDING_ABORTED, 0);
}
nsImageLoadingContent::~nsImageLoadingContent()
@ -554,7 +554,7 @@ nsImageLoadingContent::FrameDestroyed(nsIFrame* aFrame)
if (aFrame->HasAnyStateBits(NS_FRAME_IN_POPUP)) {
// We assume all images in popups are visible, so this decrement balances
// out the increment in FrameCreated above.
DecrementVisibleCount(ON_NONVISIBLE_NO_ACTION);
DecrementVisibleCount(/* aRequestDiscard = */ false);
}
}
@ -777,14 +777,15 @@ nsImageLoadingContent::IncrementVisibleCount()
}
void
nsImageLoadingContent::DecrementVisibleCount(uint32_t aNonvisibleAction)
nsImageLoadingContent::DecrementVisibleCount(bool aRequestDiscard)
{
NS_ASSERTION(mVisibleCount > 0, "visible count should be positive here");
mVisibleCount--;
if (mVisibleCount == 0) {
UntrackImage(mCurrentRequest, aNonvisibleAction);
UntrackImage(mPendingRequest, aNonvisibleAction);
uint32_t flags = aRequestDiscard ? REQUEST_DISCARD : 0;
UntrackImage(mCurrentRequest, flags);
UntrackImage(mPendingRequest, flags);
}
}
@ -1096,8 +1097,8 @@ void
nsImageLoadingContent::CancelImageRequests(bool aNotify)
{
AutoStateChanger changer(this, aNotify);
ClearPendingRequest(NS_BINDING_ABORTED, ON_NONVISIBLE_REQUEST_DISCARD);
ClearCurrentRequest(NS_BINDING_ABORTED, ON_NONVISIBLE_REQUEST_DISCARD);
ClearPendingRequest(NS_BINDING_ABORTED, REQUEST_DISCARD);
ClearCurrentRequest(NS_BINDING_ABORTED, REQUEST_DISCARD);
}
nsresult
@ -1109,8 +1110,8 @@ nsImageLoadingContent::UseAsPrimaryRequest(imgRequestProxy* aRequest,
AutoStateChanger changer(this, aNotify);
// Get rid if our existing images
ClearPendingRequest(NS_BINDING_ABORTED, ON_NONVISIBLE_REQUEST_DISCARD);
ClearCurrentRequest(NS_BINDING_ABORTED, ON_NONVISIBLE_REQUEST_DISCARD);
ClearPendingRequest(NS_BINDING_ABORTED, REQUEST_DISCARD);
ClearCurrentRequest(NS_BINDING_ABORTED, REQUEST_DISCARD);
// Clone the request we were given.
nsRefPtr<imgRequestProxy>& req = PrepareNextRequest(aImageLoadType);
@ -1227,7 +1228,7 @@ nsImageLoadingContent::SetBlockedRequest(nsIURI* aURI, int16_t aContentDecision)
// reason "image source changed". However, apparently there's some abuse
// over in nsImageFrame where the displaying of the "broken" icon for the
// next image depends on the cancel reason of the previous image. ugh.
ClearPendingRequest(NS_ERROR_IMAGE_BLOCKED, ON_NONVISIBLE_REQUEST_DISCARD);
ClearPendingRequest(NS_ERROR_IMAGE_BLOCKED, REQUEST_DISCARD);
// For the blocked case, we only want to cancel the existing current request
// if size is not available. bz says the web depends on this behavior.
@ -1235,7 +1236,7 @@ nsImageLoadingContent::SetBlockedRequest(nsIURI* aURI, int16_t aContentDecision)
mImageBlockingStatus = aContentDecision;
uint32_t keepFlags = mCurrentRequestFlags & REQUEST_IS_IMAGESET;
ClearCurrentRequest(NS_ERROR_IMAGE_BLOCKED, ON_NONVISIBLE_REQUEST_DISCARD);
ClearCurrentRequest(NS_ERROR_IMAGE_BLOCKED, REQUEST_DISCARD);
// We still want to remember what URI we were and if it was an imageset,
// despite not having an actual request. These are both cleared as part of
@ -1253,8 +1254,7 @@ nsImageLoadingContent::PrepareCurrentRequest(ImageLoadType aImageLoadType)
mImageBlockingStatus = nsIContentPolicy::ACCEPT;
// Get rid of anything that was there previously.
ClearCurrentRequest(NS_ERROR_IMAGE_SRC_CHANGED,
ON_NONVISIBLE_REQUEST_DISCARD);
ClearCurrentRequest(NS_ERROR_IMAGE_SRC_CHANGED, REQUEST_DISCARD);
if (mNewRequestsWillNeedAnimationReset) {
mCurrentRequestFlags |= REQUEST_NEEDS_ANIMATION_RESET;
@ -1272,8 +1272,7 @@ nsRefPtr<imgRequestProxy>&
nsImageLoadingContent::PreparePendingRequest(ImageLoadType aImageLoadType)
{
// Get rid of anything that was there previously.
ClearPendingRequest(NS_ERROR_IMAGE_SRC_CHANGED,
ON_NONVISIBLE_REQUEST_DISCARD);
ClearPendingRequest(NS_ERROR_IMAGE_SRC_CHANGED, REQUEST_DISCARD);
if (mNewRequestsWillNeedAnimationReset) {
mPendingRequestFlags |= REQUEST_NEEDS_ANIMATION_RESET;
@ -1338,7 +1337,7 @@ nsImageLoadingContent::MakePendingRequestCurrent()
void
nsImageLoadingContent::ClearCurrentRequest(nsresult aReason,
uint32_t aNonvisibleAction)
uint32_t aFlags)
{
if (!mCurrentRequest) {
// Even if we didn't have a current request, we might have been keeping
@ -1356,7 +1355,7 @@ nsImageLoadingContent::ClearCurrentRequest(nsresult aReason,
&mCurrentRequestRegistered);
// Clean up the request.
UntrackImage(mCurrentRequest, aNonvisibleAction);
UntrackImage(mCurrentRequest, aFlags);
mCurrentRequest->CancelAndForgetObserver(aReason);
mCurrentRequest = nullptr;
mCurrentRequestFlags = 0;
@ -1364,7 +1363,7 @@ nsImageLoadingContent::ClearCurrentRequest(nsresult aReason,
void
nsImageLoadingContent::ClearPendingRequest(nsresult aReason,
uint32_t aNonvisibleAction)
uint32_t aFlags)
{
if (!mPendingRequest)
return;
@ -1374,7 +1373,7 @@ nsImageLoadingContent::ClearPendingRequest(nsresult aReason,
nsLayoutUtils::DeregisterImageRequest(GetFramePresContext(), mPendingRequest,
&mPendingRequestRegistered);
UntrackImage(mPendingRequest, aNonvisibleAction);
UntrackImage(mPendingRequest, aFlags);
mPendingRequest->CancelAndForgetObserver(aReason);
mPendingRequest = nullptr;
mPendingRequestFlags = 0;
@ -1474,9 +1473,7 @@ nsImageLoadingContent::TrackImage(imgIRequest* aImage)
}
void
nsImageLoadingContent::UntrackImage(imgIRequest* aImage,
uint32_t aNonvisibleAction
/* = ON_NONVISIBLE_NO_ACTION */)
nsImageLoadingContent::UntrackImage(imgIRequest* aImage, uint32_t aFlags /* = 0 */)
{
if (!aImage)
return;
@ -1493,10 +1490,9 @@ nsImageLoadingContent::UntrackImage(imgIRequest* aImage,
if (doc && (mCurrentRequestFlags & REQUEST_IS_TRACKED)) {
mCurrentRequestFlags &= ~REQUEST_IS_TRACKED;
doc->RemoveImage(mCurrentRequest,
(aNonvisibleAction == ON_NONVISIBLE_REQUEST_DISCARD)
? nsIDocument::REQUEST_DISCARD
: 0);
} else if (aNonvisibleAction == ON_NONVISIBLE_REQUEST_DISCARD) {
(aFlags & REQUEST_DISCARD) ? nsIDocument::REQUEST_DISCARD : 0);
}
else if (aFlags & REQUEST_DISCARD) {
// If we're not in the document we may still need to be discarded.
aImage->RequestDiscard();
}
@ -1505,10 +1501,9 @@ nsImageLoadingContent::UntrackImage(imgIRequest* aImage,
if (doc && (mPendingRequestFlags & REQUEST_IS_TRACKED)) {
mPendingRequestFlags &= ~REQUEST_IS_TRACKED;
doc->RemoveImage(mPendingRequest,
(aNonvisibleAction == ON_NONVISIBLE_REQUEST_DISCARD)
? nsIDocument::REQUEST_DISCARD
: 0);
} else if (aNonvisibleAction == ON_NONVISIBLE_REQUEST_DISCARD) {
(aFlags & REQUEST_DISCARD) ? nsIDocument::REQUEST_DISCARD : 0);
}
else if (aFlags & REQUEST_DISCARD) {
// If we're not in the document we may still need to be discarded.
aImage->RequestDiscard();
}

View File

@ -316,12 +316,9 @@ protected:
/**
* Cancels and nulls-out the "current" and "pending" requests if they exist.
*
* @param aNonvisibleAction An action to take if the image is no longer
* visible as a result; see |UntrackImage|.
*/
void ClearCurrentRequest(nsresult aReason, uint32_t aNonvisibleAction);
void ClearPendingRequest(nsresult aReason, uint32_t aNonvisibleAction);
void ClearCurrentRequest(nsresult aReason, uint32_t aFlags);
void ClearPendingRequest(nsresult aReason, uint32_t aFlags);
/**
* Retrieve a pointer to the 'registered with the refresh driver' flag for
@ -350,14 +347,14 @@ protected:
*
* No-op if aImage is null.
*
* @param aNonvisibleAction What to do if the image's visibility count is now
* zero. If ON_NONVISIBLE_NO_ACTION, nothing will be
* done. If ON_NONVISIBLE_REQUEST_DISCARD, the image
* will be asked to discard its surfaces if possible.
* REQUEST_DISCARD passed to UntrackImage means we request the discard of the
* decoded data of the image.
*/
void TrackImage(imgIRequest* aImage);
void UntrackImage(imgIRequest* aImage,
uint32_t aNonvisibleAction = ON_NONVISIBLE_NO_ACTION);
enum {
REQUEST_DISCARD = 0x1
};
void UntrackImage(imgIRequest* aImage, uint32_t aFlags = 0);
/* MEMBERS */
nsRefPtr<imgRequestProxy> mCurrentRequest;

View File

@ -1153,7 +1153,7 @@ PresShell::Destroy()
mUpdateImageVisibilityEvent.Revoke();
ClearVisibleImagesList(nsIImageLoadingContent::ON_NONVISIBLE_REQUEST_DISCARD);
ClearVisibleImagesList(/* aRequestDiscard = */ true);
if (mCaret) {
mCaret->Terminate();
@ -5820,8 +5820,7 @@ PresShell::MarkImagesInListVisible(const nsDisplayList& aList)
static PLDHashOperator
DecrementVisibleCount(nsRefPtrHashKey<nsIImageLoadingContent>* aEntry, void*)
{
aEntry->GetKey()->DecrementVisibleCount(
nsIImageLoadingContent::ON_NONVISIBLE_NO_ACTION);
aEntry->GetKey()->DecrementVisibleCount(/* aRequestDiscard = */ false);
return PL_DHASH_NEXT;
}
@ -5845,8 +5844,7 @@ PresShell::ClearImageVisibilityVisited(nsView* aView, bool aClear)
if (aClear) {
PresShell* presShell = static_cast<PresShell*>(vm->GetPresShell());
if (!presShell->mImageVisibilityVisited) {
presShell->ClearVisibleImagesList(
nsIImageLoadingContent::ON_NONVISIBLE_NO_ACTION);
presShell->ClearVisibleImagesList(/* aRequestDiscard = */ false);
}
presShell->mImageVisibilityVisited = false;
}
@ -5859,18 +5857,15 @@ static PLDHashOperator
DecrementVisibleCountAndDiscard(nsRefPtrHashKey<nsIImageLoadingContent>* aEntry,
void*)
{
aEntry->GetKey()->DecrementVisibleCount(
nsIImageLoadingContent::ON_NONVISIBLE_REQUEST_DISCARD);
aEntry->GetKey()->DecrementVisibleCount(/* aRequestDiscard = */ true);
return PL_DHASH_NEXT;
}
void
PresShell::ClearVisibleImagesList(uint32_t aNonvisibleAction)
PresShell::ClearVisibleImagesList(bool aRequestDiscard)
{
auto enumerator
= aNonvisibleAction == nsIImageLoadingContent::ON_NONVISIBLE_REQUEST_DISCARD
? DecrementVisibleCountAndDiscard
: DecrementVisibleCount;
auto enumerator = aRequestDiscard ? DecrementVisibleCountAndDiscard
: DecrementVisibleCount;
mVisibleImages.EnumerateEntries(enumerator, nullptr);
mVisibleImages.Clear();
}
@ -6001,8 +5996,7 @@ PresShell::UpdateImageVisibility()
// call update on that frame
nsIFrame* rootFrame = GetRootFrame();
if (!rootFrame) {
ClearVisibleImagesList(
nsIImageLoadingContent::ON_NONVISIBLE_REQUEST_DISCARD);
ClearVisibleImagesList(/* aRequestDiscard = */ true);
return;
}
@ -6161,8 +6155,7 @@ PresShell::RemoveImageFromVisibleList(nsIImageLoadingContent* aImage)
mVisibleImages.RemoveEntry(aImage);
if (mVisibleImages.Count() < count) {
// aImage was in the hashtable, so we need to decrement its visible count
aImage->DecrementVisibleCount(
nsIImageLoadingContent::ON_NONVISIBLE_NO_ACTION);
aImage->DecrementVisibleCount(/* aRequestDiscard = */ false);
}
}

View File

@ -731,7 +731,7 @@ protected:
nsRevocableEventPtr<nsRunnableMethod<PresShell> > mUpdateImageVisibilityEvent;
void ClearVisibleImagesList(uint32_t aNonvisibleAction);
void ClearVisibleImagesList(bool aRequestDiscard);
static void ClearImageVisibilityVisited(nsView* aView, bool aClear);
static void MarkImagesInListVisible(const nsDisplayList& aList);
void MarkImagesInSubtreeVisible(nsIFrame* aFrame, const nsRect& aRect);

View File

@ -82,8 +82,7 @@ SVGFEImageFrame::DestroyFrom(nsIFrame* aDestructRoot)
if (imageLoader) {
imageLoader->FrameDestroyed(this);
imageLoader
->DecrementVisibleCount(nsIImageLoadingContent::ON_NONVISIBLE_NO_ACTION);
imageLoader->DecrementVisibleCount(/* aRequestDiscard = */ false);
}
SVGFEImageFrameBase::DestroyFrom(aDestructRoot);