nsresult DiscardTracker::Reset(Node *node) { // We shouldn't call Reset() with a null |img| pointer, on images which can't // be discarded, or on animated images (which should be marked as // non-discardable, anyway). MOZ_ASSERT(NS_IsMainThread()); MOZ_ASSERT(sInitialized); MOZ_ASSERT(node->img); MOZ_ASSERT(node->img->CanDiscard()); MOZ_ASSERT(!node->img->mAnim); // Insert the node at the front of the list and note when it was inserted. bool wasInList = node->isInList(); if (wasInList) { node->remove(); } node->timestamp = TimeStamp::Now(); sDiscardableImages.insertFront(node); // If the node wasn't already in the list of discardable images, then we may // need to discard some images to stay under the sMaxDecodedImageKB limit. // Call MaybeDiscardSoon to do this check. if (!wasInList) { MaybeDiscardSoon(); } // Make sure the timer is running. nsresult rv = EnableTimer(); NS_ENSURE_SUCCESS(rv,rv); return NS_OK; }
void DiscardTracker::InformAllocation(PRInt64 bytes) { // This function is called back e.g. from RasterImage::Discard(); be careful! sCurrentDecodedImageBytes += bytes; MOZ_ASSERT(sCurrentDecodedImageBytes >= 0); // If we're using too much memory for decoded images, MaybeDiscardSoon will // enqueue a callback to discard some images. MaybeDiscardSoon(); }
/* static */ bool DiscardTracker::TryAllocation(uint64_t aBytes) { MOZ_ASSERT(sInitialized); PR_Lock(sAllocationLock); bool enoughSpace = !gfxPrefs::ImageMemHardLimitDecodedImageKB() || (gfxPrefs::ImageMemHardLimitDecodedImageKB() * 1024) - sCurrentDecodedImageBytes >= aBytes; if (enoughSpace) { sCurrentDecodedImageBytes += aBytes; } PR_Unlock(sAllocationLock); // If we're using too much memory for decoded images, MaybeDiscardSoon will // enqueue a callback to discard some images. MaybeDiscardSoon(); return enoughSpace; }