Skip to content

Commit

Permalink
Backed out changeset e5c85f765f2d (bug 1126739) for bc2 test failures…
Browse files Browse the repository at this point in the history
… on a CLOSED TREE
  • Loading branch information
BavarianTomcat committed Jan 29, 2015
1 parent 51a48b6 commit 8a899ef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 30 deletions.
13 changes: 9 additions & 4 deletions image/src/RasterImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,11 +614,16 @@ RasterImage::IsOpaque()
void
RasterImage::OnSurfaceDiscarded()
{
MOZ_ASSERT(mProgressTracker);
if (!NS_IsMainThread()) {
nsCOMPtr<nsIRunnable> runnable =
NS_NewRunnableMethod(this, &RasterImage::OnSurfaceDiscarded);
NS_DispatchToMainThread(runnable);
return;
}

nsCOMPtr<nsIRunnable> runnable =
NS_NewRunnableMethod(mProgressTracker, &ProgressTracker::OnDiscard);
NS_DispatchToMainThread(runnable);
if (mProgressTracker) {
mProgressTracker->OnDiscard();
}
}

//******************************************************************************
Expand Down
16 changes: 8 additions & 8 deletions image/src/SurfaceCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ class SurfaceCacheImpl MOZ_FINAL : public nsIMemoryReporter
SurfaceCacheImpl(uint32_t aSurfaceCacheExpirationTimeMS,
uint32_t aSurfaceCacheDiscardFactor,
uint32_t aSurfaceCacheSize)
: mExpirationTracker(aSurfaceCacheExpirationTimeMS)
: mExpirationTracker(this, aSurfaceCacheExpirationTimeMS)
, mMemoryPressureObserver(new MemoryPressureObserver)
, mMutex("SurfaceCache")
, mDiscardFactor(aSurfaceCacheDiscardFactor)
Expand Down Expand Up @@ -742,8 +742,6 @@ class SurfaceCacheImpl MOZ_FINAL : public nsIMemoryReporter
nsISupports* aData,
bool aAnonymize) MOZ_OVERRIDE
{
MutexAutoLock lock(mMutex);

// We have explicit memory reporting for the surface cache which is more
// accurate than the cost metrics we report here, but these metrics are
// still useful to report, since they control the cache's behavior.
Expand Down Expand Up @@ -811,18 +809,21 @@ class SurfaceCacheImpl MOZ_FINAL : public nsIMemoryReporter

struct SurfaceTracker : public nsExpirationTracker<CachedSurface, 2>
{
explicit SurfaceTracker(uint32_t aSurfaceCacheExpirationTimeMS)
SurfaceTracker(SurfaceCacheImpl* aCache, uint32_t aSurfaceCacheExpirationTimeMS)
: nsExpirationTracker<CachedSurface, 2>(aSurfaceCacheExpirationTimeMS)
, mCache(aCache)
{ }

protected:
virtual void NotifyExpired(CachedSurface* aSurface) MOZ_OVERRIDE
{
if (sInstance) {
MutexAutoLock lock(sInstance->GetMutex());
sInstance->Remove(aSurface);
if (mCache) {
mCache->Remove(aSurface);
}
}

private:
SurfaceCacheImpl* const mCache; // Weak pointer to owner.
};

struct MemoryPressureObserver : public nsIObserver
Expand All @@ -834,7 +835,6 @@ class SurfaceCacheImpl MOZ_FINAL : public nsIMemoryReporter
const char16_t*) MOZ_OVERRIDE
{
if (sInstance && strcmp(aTopic, "memory-pressure") == 0) {
MutexAutoLock lock(sInstance->GetMutex());
sInstance->DiscardForMemoryPressure();
}
return NS_OK;
Expand Down
32 changes: 14 additions & 18 deletions image/test/browser/browser_bug666317.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ function currentRequest() {
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;
Expand Down Expand Up @@ -57,18 +69,9 @@ function test() {
}

function step2() {
// Create a place to hold the result.
// Attach a discard listener and create a place to hold the result.
var result = { wasDiscarded: false };

// Create the discard observer.
var observer = new ImageDiscardObserver(result);
var scriptedObserver = Cc["@mozilla.org/image/tools;1"]
.getService(Ci.imgITools)
.createScriptedObserver(observer);

// Clone the current imgIRequest with our new observer.
var request = currentRequest();
var clonedRequest = request.clone(scriptedObserver);
var clonedRequest = attachDiscardObserver(result);

// Check that the image is decoded.
forceDecodeImg();
Expand All @@ -80,13 +83,6 @@ function step2() {
var os = Cc["@mozilla.org/observer-service;1"]
.getService(Ci.nsIObserverService);
os.notifyObservers(null, 'memory-pressure', 'heap-minimize');

// The discard notification is delivered asynchronously, so pump the event
// loop before checking.
setTimeout(() => step3(result, scriptedObserver, clonedRequest), 0);
}

function step3(result, scriptedObserver, clonedRequest) {
ok(result.wasDiscarded, 'Image should be discarded.');

// And we're done.
Expand Down

0 comments on commit 8a899ef

Please sign in to comment.