Bug 1084136 (Part 6) - Don't reset any imgStatusTracker state when discarding. r=tn

--HG--
extra : rebase_source : 48b0bb6827f6b8121f662bab4dcfb823fa8fe870
This commit is contained in:
Seth Fowler 2014-11-06 17:33:59 -08:00
parent f114d563da
commit c3719cd2ba
4 changed files with 34 additions and 36 deletions

View File

@ -109,13 +109,6 @@ public:
*/
virtual void OnStopRequest(bool aIsLastPart, nsresult aStatus) = 0;
/**
* Called when the decoded image data is discarded. This means that the frames
* no longer exist in decoded form, and any attempt to access or draw the
* image will initiate a new series of progressive decode notifications.
*/
virtual void OnDiscard() = 0;
/**
* Called when we are asked to Draw an image that is not locked.
*/

View File

@ -107,14 +107,6 @@ public:
tracker->RecordStopRequest(aLastPart, aStatus);
}
virtual void OnDiscard() MOZ_OVERRIDE
{
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnDiscard");
nsRefPtr<imgStatusTracker> tracker = mTracker.get();
if (!tracker) { return; }
tracker->RecordDiscard();
}
virtual void OnUnlockedDraw() MOZ_OVERRIDE
{
LOG_SCOPE(GetImgLog(), "imgStatusTrackerObserver::OnUnlockedDraw");
@ -715,22 +707,6 @@ imgStatusTracker::SendStopDecode(imgRequestProxy* aProxy,
aProxy->OnStopDecode();
}
void
imgStatusTracker::RecordDiscard()
{
NS_ABORT_IF_FALSE(mImage,
"RecordDiscard called before we have an Image");
// Clear the state bits we no longer deserve.
uint32_t stateBitsToClear = FLAG_DECODE_STOPPED;
mState &= ~stateBitsToClear;
// Clear the status bits we no longer deserve.
uint32_t statusBitsToClear = imgIRequest::STATUS_DECODE_STARTED |
imgIRequest::STATUS_FRAME_COMPLETE |
imgIRequest::STATUS_DECODE_COMPLETE;
mImageStatus &= ~statusBitsToClear;
}
void
imgStatusTracker::SendDiscard(imgRequestProxy* aProxy)
{
@ -929,7 +905,6 @@ void
imgStatusTracker::OnDiscard()
{
MOZ_ASSERT(NS_IsMainThread());
RecordDiscard();
/* notify the kids */
ProxyArray::ForwardIterator iter(mConsumers);

View File

@ -210,7 +210,6 @@ public:
void SendStopFrame(imgRequestProxy* aProxy);
void RecordStopDecode(nsresult statusg);
void SendStopDecode(imgRequestProxy* aProxy, nsresult aStatus);
void RecordDiscard();
void SendDiscard(imgRequestProxy* aProxy);
void RecordUnlockedDraw();
void SendUnlockedDraw(imgRequestProxy* aProxy);

View File

@ -10,11 +10,37 @@ let prefBranch = Cc["@mozilla.org/preferences-service;1"]
.getService(Ci.nsIPrefService)
.getBranch('image.mem.');
function isImgDecoded() {
function ImageDiscardObserver(result) {
this.discard = function onDiscard(request)
{
result.wasDiscarded = true;
this.synchronous = false;
}
this.synchronous = true;
}
function currentRequest() {
let img = gBrowser.getBrowserForTab(newTab).contentWindow
.document.getElementById('testImg');
img.QueryInterface(Ci.nsIImageLoadingContent);
let request = img.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
return img.getRequest(Ci.nsIImageLoadingContent.CURRENT_REQUEST);
}
function attachDiscardObserver(result) {
// Create the discard observer.
let observer = new ImageDiscardObserver(result);
let scriptedObserver = Cc["@mozilla.org/image/tools;1"]
.getService(Ci.imgITools)
.createScriptedObserver(observer);
// Clone the current imgIRequest with our new observer.
let request = currentRequest();
return request.clone(scriptedObserver);
}
function isImgDecoded() {
let request = currentRequest();
return request.imageStatus & Ci.imgIRequest.STATUS_FRAME_COMPLETE ? true : false;
}
@ -43,6 +69,10 @@ function test() {
}
function step2() {
// Attach a discard listener and create a place to hold the result.
var result = { wasDiscarded: false };
var clonedRequest = attachDiscardObserver(result);
// Check that the image is decoded.
forceDecodeImg();
ok(isImgDecoded(), 'Image should initially be decoded.');
@ -53,10 +83,11 @@ function step2() {
var os = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
os.notifyObservers(null, 'memory-pressure', 'heap-minimize');
ok(!isImgDecoded(), 'Image should be discarded.');
ok(result.wasDiscarded, 'Image should be discarded.');
// And we're done.
gBrowser.removeTab(newTab);
prefBranch.setBoolPref('discardable', oldDiscardingPref);
clonedRequest.cancelAndForgetObserver(0);
finish();
}