Bug 666446, Part 7/18 - Change nsImageLoader to utilize new refresh driver animations to overcome performance issues with animated background images. [r=roc]

This commit is contained in:
Scott Johnson 2011-10-03 13:39:05 -07:00
parent 90549abb9c
commit 91dcb84e48
2 changed files with 44 additions and 3 deletions

View File

@ -57,6 +57,7 @@
#include "nsStyleContext.h"
#include "nsGkAtoms.h"
#include "nsLayoutUtils.h"
// Paint forcing
#include "prenv.h"
@ -67,7 +68,8 @@ nsImageLoader::nsImageLoader(nsIFrame *aFrame, PRUint32 aActions,
nsImageLoader *aNextLoader)
: mFrame(aFrame),
mActions(aActions),
mNextLoader(aNextLoader)
mNextLoader(aNextLoader),
mRequestRegistered(false)
{
}
@ -105,12 +107,15 @@ nsImageLoader::Destroy()
todestroy->Destroy();
}
mFrame = nsnull;
if (mRequest) {
nsPresContext* presContext = mFrame->PresContext();
nsLayoutUtils::DeregisterImageRequest(presContext, mRequest,
&mRequestRegistered);
mRequest->CancelAndForgetObserver(NS_ERROR_FAILURE);
}
mFrame = nsnull;
mRequest = nsnull;
}
@ -269,3 +274,31 @@ nsImageLoader::DoRedraw(const nsRect* aDamageRect)
mFrame->Invalidate(bounds);
}
}
NS_IMETHODIMP
nsImageLoader::OnStartDecode(imgIRequest *aRequest)
{
// Register our image request with the refresh driver.
nsPresContext* presContext = mFrame->PresContext();
if (!presContext) {
return NS_OK;
}
nsLayoutUtils::RegisterImageRequest(presContext, aRequest,
&mRequestRegistered);
return NS_OK;
}
NS_IMETHODIMP
nsImageLoader::OnStopDecode(imgIRequest *aRequest, nsresult status,
const PRUnichar *statusArg)
{
// Deregister the imgIRequest with the refresh driver if the
// image is not animated.
nsLayoutUtils::DeregisterImageRequestIfNotAnimated(mFrame->PresContext(),
mRequest,
&mRequestRegistered);
return NS_OK;
}

View File

@ -82,6 +82,10 @@ public:
// imgIDecoderObserver (override nsStubImageDecoderObserver)
NS_IMETHOD OnStartContainer(imgIRequest *aRequest, imgIContainer *aImage);
NS_IMETHOD OnStartDecode(imgIRequest *aRequest);
NS_IMETHOD OnStopDecode(imgIRequest *aRequest,
nsresult status,
const PRUnichar *statusArg);
NS_IMETHOD OnStopFrame(imgIRequest *aRequest, PRUint32 aFrame);
NS_IMETHOD OnStopRequest(imgIRequest *aRequest, bool aLastPart);
// Do not override OnDataAvailable since background images are not
@ -109,4 +113,8 @@ private:
nsCOMPtr<imgIRequest> mRequest;
PRUint32 mActions;
nsRefPtr<nsImageLoader> mNextLoader;
// This is a boolean flag indicating whether or not the current image request
// has been registered with the refresh driver.
bool mRequestRegistered;
};