Blame image/SurfaceCache.h

Packit f0b94e
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
Packit f0b94e
/* This Source Code Form is subject to the terms of the Mozilla Public
Packit f0b94e
 * License, v. 2.0. If a copy of the MPL was not distributed with this
Packit f0b94e
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * SurfaceCache is a service for caching temporary surfaces and decoded image
Packit f0b94e
 * data in imagelib.
Packit f0b94e
 */
Packit f0b94e
Packit f0b94e
#ifndef mozilla_image_SurfaceCache_h
Packit f0b94e
#define mozilla_image_SurfaceCache_h
Packit f0b94e
Packit f0b94e
#include "mozilla/Maybe.h"  // for Maybe
Packit f0b94e
#include "mozilla/NotNull.h"
Packit f0b94e
#include "mozilla/MemoryReporting.h"  // for MallocSizeOf
Packit f0b94e
#include "mozilla/HashFunctions.h"    // for HashGeneric and AddToHash
Packit f0b94e
#include "gfx2DGlue.h"
Packit f0b94e
#include "gfxPoint.h"           // for gfxSize
Packit f0b94e
#include "nsCOMPtr.h"           // for already_AddRefed
Packit f0b94e
#include "mozilla/gfx/Point.h"  // for mozilla::gfx::IntSize
Packit f0b94e
#include "mozilla/gfx/2D.h"     // for SourceSurface
Packit f0b94e
#include "PlaybackType.h"
Packit f0b94e
#include "SurfaceFlags.h"
Packit f0b94e
#include "SVGImageContext.h"  // for SVGImageContext
Packit f0b94e
Packit f0b94e
namespace mozilla {
Packit f0b94e
namespace image {
Packit f0b94e
Packit f0b94e
class Image;
Packit f0b94e
class ISurfaceProvider;
Packit f0b94e
class LookupResult;
Packit f0b94e
class SurfaceCacheImpl;
Packit f0b94e
struct SurfaceMemoryCounter;
Packit f0b94e
Packit f0b94e
/*
Packit f0b94e
 * ImageKey contains the information we need to look up all SurfaceCache entries
Packit f0b94e
 * for a particular image.
Packit f0b94e
 */
Packit f0b94e
typedef Image* ImageKey;
Packit f0b94e
Packit f0b94e
/*
Packit f0b94e
 * SurfaceKey contains the information we need to look up a specific
Packit f0b94e
 * SurfaceCache entry. Together with an ImageKey, this uniquely identifies the
Packit f0b94e
 * surface.
Packit f0b94e
 *
Packit f0b94e
 * Callers should construct a SurfaceKey using the appropriate helper function
Packit f0b94e
 * for their image type - either RasterSurfaceKey or VectorSurfaceKey.
Packit f0b94e
 */
Packit f0b94e
class SurfaceKey {
Packit f0b94e
  typedef gfx::IntSize IntSize;
Packit f0b94e
Packit f0b94e
 public:
Packit f0b94e
  bool operator==(const SurfaceKey& aOther) const {
Packit f0b94e
    return aOther.mSize == mSize && aOther.mSVGContext == mSVGContext &&
Packit f0b94e
           aOther.mPlayback == mPlayback && aOther.mFlags == mFlags;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  PLDHashNumber Hash() const {
Packit f0b94e
    PLDHashNumber hash = HashGeneric(mSize.width, mSize.height);
Packit f0b94e
    hash = AddToHash(hash, mSVGContext.map(HashSIC).valueOr(0));
Packit f0b94e
    hash = AddToHash(hash, uint8_t(mPlayback), uint32_t(mFlags));
Packit f0b94e
    return hash;
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  SurfaceKey CloneWithSize(const IntSize& aSize) const {
Packit f0b94e
    return SurfaceKey(aSize, mSVGContext, mPlayback, mFlags);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  const IntSize& Size() const { return mSize; }
Packit f0b94e
  const Maybe<SVGImageContext>& SVGContext() const { return mSVGContext; }
Packit f0b94e
  PlaybackType Playback() const { return mPlayback; }
Packit f0b94e
  SurfaceFlags Flags() const { return mFlags; }
Packit f0b94e
Packit f0b94e
 private:
Packit f0b94e
  SurfaceKey(const IntSize& aSize, const Maybe<SVGImageContext>& aSVGContext,
Packit f0b94e
             PlaybackType aPlayback, SurfaceFlags aFlags)
Packit f0b94e
      : mSize(aSize),
Packit f0b94e
        mSVGContext(aSVGContext),
Packit f0b94e
        mPlayback(aPlayback),
Packit f0b94e
        mFlags(aFlags) {}
Packit f0b94e
Packit f0b94e
  static PLDHashNumber HashSIC(const SVGImageContext& aSIC) {
Packit f0b94e
    return aSIC.Hash();
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  friend SurfaceKey RasterSurfaceKey(const IntSize&, SurfaceFlags,
Packit f0b94e
                                     PlaybackType);
Packit f0b94e
  friend SurfaceKey VectorSurfaceKey(const IntSize&,
Packit f0b94e
                                     const Maybe<SVGImageContext>&);
Packit f0b94e
Packit f0b94e
  IntSize mSize;
Packit f0b94e
  Maybe<SVGImageContext> mSVGContext;
Packit f0b94e
  PlaybackType mPlayback;
Packit f0b94e
  SurfaceFlags mFlags;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
inline SurfaceKey RasterSurfaceKey(const gfx::IntSize& aSize,
Packit f0b94e
                                   SurfaceFlags aFlags,
Packit f0b94e
                                   PlaybackType aPlayback) {
Packit f0b94e
  return SurfaceKey(aSize, Nothing(), aPlayback, aFlags);
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
inline SurfaceKey VectorSurfaceKey(const gfx::IntSize& aSize,
Packit f0b94e
                                   const Maybe<SVGImageContext>& aSVGContext) {
Packit f0b94e
  // We don't care about aFlags for VectorImage because none of the flags we
Packit f0b94e
  // have right now influence VectorImage's rendering. If we add a new flag that
Packit f0b94e
  // *does* affect how a VectorImage renders, we'll have to change this.
Packit f0b94e
  // Similarly, we don't accept a PlaybackType parameter because we don't
Packit f0b94e
  // currently cache frames of animated SVG images.
Packit f0b94e
  return SurfaceKey(aSize, aSVGContext, PlaybackType::eStatic,
Packit f0b94e
                    DefaultSurfaceFlags());
Packit f0b94e
}
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * AvailabilityState is used to track whether an ISurfaceProvider has a surface
Packit f0b94e
 * available or is just a placeholder.
Packit f0b94e
 *
Packit f0b94e
 * To ensure that availability changes are atomic (and especially that internal
Packit f0b94e
 * SurfaceCache code doesn't have to deal with asynchronous availability
Packit f0b94e
 * changes), an ISurfaceProvider which starts as a placeholder can only reveal
Packit f0b94e
 * the fact that it now has a surface available via a call to
Packit f0b94e
 * SurfaceCache::SurfaceAvailable().
Packit f0b94e
 *
Packit f0b94e
 * It also tracks whether or not there are "explicit" users of this surface
Packit f0b94e
 * which will not accept substitutes. This is used by SurfaceCache when pruning
Packit f0b94e
 * unnecessary surfaces from the cache.
Packit f0b94e
 */
Packit f0b94e
class AvailabilityState {
Packit f0b94e
 public:
Packit f0b94e
  static AvailabilityState StartAvailable() { return AvailabilityState(true); }
Packit f0b94e
  static AvailabilityState StartAsPlaceholder() {
Packit f0b94e
    return AvailabilityState(false);
Packit f0b94e
  }
Packit f0b94e
Packit f0b94e
  bool IsAvailable() const { return mIsAvailable; }
Packit f0b94e
  bool IsPlaceholder() const { return !mIsAvailable; }
Packit f0b94e
  bool CannotSubstitute() const { return mCannotSubstitute; }
Packit f0b94e
Packit f0b94e
  void SetCannotSubstitute() { mCannotSubstitute = true; }
Packit f0b94e
Packit f0b94e
 private:
Packit f0b94e
  friend class SurfaceCacheImpl;
Packit f0b94e
Packit f0b94e
  explicit AvailabilityState(bool aIsAvailable)
Packit f0b94e
      : mIsAvailable(aIsAvailable), mCannotSubstitute(false) {}
Packit f0b94e
Packit f0b94e
  void SetAvailable() { mIsAvailable = true; }
Packit f0b94e
Packit f0b94e
  bool mIsAvailable : 1;
Packit f0b94e
  bool mCannotSubstitute : 1;
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
enum class InsertOutcome : uint8_t {
Packit f0b94e
  SUCCESS,                 // Success (but see Insert documentation).
Packit f0b94e
  FAILURE,                 // Couldn't insert (e.g., for capacity reasons).
Packit f0b94e
  FAILURE_ALREADY_PRESENT  // A surface with the same key is already present.
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
/**
Packit f0b94e
 * SurfaceCache is an ImageLib-global service that allows caching of decoded
Packit f0b94e
 * image surfaces, temporary surfaces (e.g. for caching rotated or clipped
Packit f0b94e
 * versions of images), or dynamically generated surfaces (e.g. for animations).
Packit f0b94e
 * SurfaceCache entries normally expire from the cache automatically if they go
Packit f0b94e
 * too long without being accessed.
Packit f0b94e
 *
Packit f0b94e
 * Because SurfaceCache must support both normal surfaces and dynamically
Packit f0b94e
 * generated surfaces, it does not actually hold surfaces directly. Instead, it
Packit f0b94e
 * holds ISurfaceProvider objects which can provide access to a surface when
Packit f0b94e
 * requested; SurfaceCache doesn't care about the details of how this is
Packit f0b94e
 * accomplished.
Packit f0b94e
 *
Packit f0b94e
 * Sometime it's useful to temporarily prevent entries from expiring from the
Packit f0b94e
 * cache. This is most often because losing the data could harm the user
Packit f0b94e
 * experience (for example, we often don't want to allow surfaces that are
Packit f0b94e
 * currently visible to expire) or because it's not possible to rematerialize
Packit f0b94e
 * the surface. SurfaceCache supports this through the use of image locking; see
Packit f0b94e
 * the comments for Insert() and LockImage() for more details.
Packit f0b94e
 *
Packit f0b94e
 * Any image which stores surfaces in the SurfaceCache *must* ensure that it
Packit f0b94e
 * calls RemoveImage() before it is destroyed. See the comments for
Packit f0b94e
 * RemoveImage() for more details.
Packit f0b94e
 */
Packit f0b94e
struct SurfaceCache {
Packit f0b94e
  typedef gfx::IntSize IntSize;
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Initialize static data. Called during imagelib module initialization.
Packit f0b94e
   */
Packit f0b94e
  static void Initialize();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Release static data. Called during imagelib module shutdown.
Packit f0b94e
   */
Packit f0b94e
  static void Shutdown();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Looks up the requested cache entry and returns a drawable reference to its
Packit f0b94e
   * associated surface.
Packit f0b94e
   *
Packit f0b94e
   * If the image associated with the cache entry is locked, then the entry will
Packit f0b94e
   * be locked before it is returned.
Packit f0b94e
   *
Packit f0b94e
   * If a matching ISurfaceProvider was found in the cache, but SurfaceCache
Packit f0b94e
   * couldn't obtain a surface from it (e.g. because it had stored its surface
Packit f0b94e
   * in a volatile buffer which was discarded by the OS) then it is
Packit f0b94e
   * automatically removed from the cache and an empty LookupResult is returned.
Packit f0b94e
   * Note that this will never happen to ISurfaceProviders associated with a
Packit f0b94e
   * locked image; SurfaceCache tells such ISurfaceProviders to keep a strong
Packit f0b94e
   * references to their data internally.
Packit f0b94e
   *
Packit f0b94e
   * @param aImageKey       Key data identifying which image the cache entry
Packit f0b94e
   *                        belongs to.
Packit f0b94e
   * @param aSurfaceKey     Key data which uniquely identifies the requested
Packit f0b94e
   *                        cache entry.
Packit f0b94e
   * @return                a LookupResult which will contain a DrawableSurface
Packit f0b94e
   *                        if the cache entry was found.
Packit f0b94e
   */
Packit f0b94e
  static LookupResult Lookup(const ImageKey aImageKey,
Packit f0b94e
                             const SurfaceKey& aSurfaceKey);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Looks up the best matching cache entry and returns a drawable reference to
Packit f0b94e
   * its associated surface.
Packit f0b94e
   *
Packit f0b94e
   * The result may vary from the requested cache entry only in terms of size.
Packit f0b94e
   *
Packit f0b94e
   * @param aImageKey       Key data identifying which image the cache entry
Packit f0b94e
   *                        belongs to.
Packit f0b94e
   * @param aSurfaceKey     Key data which uniquely identifies the requested
Packit f0b94e
   *                        cache entry.
Packit f0b94e
   * @return                a LookupResult which will contain a DrawableSurface
Packit f0b94e
   *                        if a cache entry similar to the one the caller
Packit f0b94e
   *                        requested could be found. Callers can use
Packit f0b94e
   *                        LookupResult::IsExactMatch() to check whether the
Packit f0b94e
   *                        returned surface exactly matches @aSurfaceKey.
Packit f0b94e
   */
Packit f0b94e
  static LookupResult LookupBestMatch(const ImageKey aImageKey,
Packit f0b94e
                                      const SurfaceKey& aSurfaceKey);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Insert an ISurfaceProvider into the cache. If an entry with the same
Packit f0b94e
   * ImageKey and SurfaceKey is already in the cache, Insert returns
Packit f0b94e
   * FAILURE_ALREADY_PRESENT. If a matching placeholder is already present, it
Packit f0b94e
   * is replaced.
Packit f0b94e
   *
Packit f0b94e
   * Cache entries will never expire as long as they remain locked, but if they
Packit f0b94e
   * become unlocked, they can expire either because the SurfaceCache runs out
Packit f0b94e
   * of capacity or because they've gone too long without being used.  When it
Packit f0b94e
   * is first inserted, a cache entry is locked if its associated image is
Packit f0b94e
   * locked.  When that image is later unlocked, the cache entry becomes
Packit f0b94e
   * unlocked too. To become locked again at that point, two things must happen:
Packit f0b94e
   * the image must become locked again (via LockImage()), and the cache entry
Packit f0b94e
   * must be touched again (via one of the Lookup() functions).
Packit f0b94e
   *
Packit f0b94e
   * All of this means that a very particular procedure has to be followed for
Packit f0b94e
   * cache entries which cannot be rematerialized. First, they must be inserted
Packit f0b94e
   * *after* the image is locked with LockImage(); if you use the other order,
Packit f0b94e
   * the cache entry might expire before LockImage() gets called or before the
Packit f0b94e
   * entry is touched again by Lookup(). Second, the image they are associated
Packit f0b94e
   * with must never be unlocked.
Packit f0b94e
   *
Packit f0b94e
   * If a cache entry cannot be rematerialized, it may be important to know
Packit f0b94e
   * whether it was inserted into the cache successfully. Insert() returns
Packit f0b94e
   * FAILURE if it failed to insert the cache entry, which could happen because
Packit f0b94e
   * of capacity reasons, or because it was already freed by the OS. If the
Packit f0b94e
   * cache entry isn't associated with a locked image, checking for SUCCESS or
Packit f0b94e
   * FAILURE is useless: the entry might expire immediately after being
Packit f0b94e
   * inserted, even though Insert() returned SUCCESS. Thus, many callers do not
Packit f0b94e
   * need to check the result of Insert() at all.
Packit f0b94e
   *
Packit f0b94e
   * @param aProvider    The new cache entry to insert into the cache.
Packit f0b94e
   * @return SUCCESS if the cache entry was inserted successfully. (But see
Packit f0b94e
   *           above for more information about when you should check this.)
Packit f0b94e
   *         FAILURE if the cache entry could not be inserted, e.g. for capacity
Packit f0b94e
   *           reasons. (But see above for more information about when you
Packit f0b94e
   *           should check this.)
Packit f0b94e
   *         FAILURE_ALREADY_PRESENT if an entry with the same ImageKey and
Packit f0b94e
   *           SurfaceKey already exists in the cache.
Packit f0b94e
   */
Packit f0b94e
  static InsertOutcome Insert(NotNull<ISurfaceProvider*> aProvider);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Mark the cache entry @aProvider as having an available surface. This turns
Packit f0b94e
   * a placeholder cache entry into a normal cache entry. The cache entry
Packit f0b94e
   * becomes locked if the associated image is locked; otherwise, it starts in
Packit f0b94e
   * the unlocked state.
Packit f0b94e
   *
Packit f0b94e
   * If the cache entry containing @aProvider has already been evicted from the
Packit f0b94e
   * surface cache, this function has no effect.
Packit f0b94e
   *
Packit f0b94e
   * It's illegal to call this function if @aProvider is not a placeholder; by
Packit f0b94e
   * definition, non-placeholder ISurfaceProviders should have a surface
Packit f0b94e
   * available already.
Packit f0b94e
   *
Packit f0b94e
   * @param aProvider       The cache entry that now has a surface available.
Packit f0b94e
   */
Packit f0b94e
  static void SurfaceAvailable(NotNull<ISurfaceProvider*> aProvider);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Checks if a surface of a given size could possibly be stored in the cache.
Packit f0b94e
   * If CanHold() returns false, Insert() will always fail to insert the
Packit f0b94e
   * surface, but the inverse is not true: Insert() may take more information
Packit f0b94e
   * into account than just image size when deciding whether to cache the
Packit f0b94e
   * surface, so Insert() may still fail even if CanHold() returns true.
Packit f0b94e
   *
Packit f0b94e
   * Use CanHold() to avoid the need to create a temporary surface when we know
Packit f0b94e
   * for sure the cache can't hold it.
Packit f0b94e
   *
Packit f0b94e
   * @param aSize  The dimensions of a surface in pixels.
Packit f0b94e
   * @param aBytesPerPixel  How many bytes each pixel of the surface requires.
Packit f0b94e
   *                        Defaults to 4, which is appropriate for RGBA or RGBX
Packit f0b94e
   *                        images.
Packit f0b94e
   *
Packit f0b94e
   * @return false if the surface cache can't hold a surface of that size.
Packit f0b94e
   */
Packit f0b94e
  static bool CanHold(const IntSize& aSize, uint32_t aBytesPerPixel = 4);
Packit f0b94e
  static bool CanHold(size_t aSize);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Locks an image. Any of the image's cache entries which are either inserted
Packit f0b94e
   * or accessed while the image is locked will not expire.
Packit f0b94e
   *
Packit f0b94e
   * Locking an image does not automatically lock that image's existing cache
Packit f0b94e
   * entries. A call to LockImage() guarantees that entries which are inserted
Packit f0b94e
   * afterward will not expire before the next call to UnlockImage() or
Packit f0b94e
   * UnlockSurfaces() for that image. Cache entries that are accessed via
Packit f0b94e
   * Lookup() or LookupBestMatch() after a LockImage() call will also not expire
Packit f0b94e
   * until the next UnlockImage() or UnlockSurfaces() call for that image. Any
Packit f0b94e
   * other cache entries owned by the image may expire at any time.
Packit f0b94e
   *
Packit f0b94e
   * All of an image's cache entries are removed by RemoveImage(), whether the
Packit f0b94e
   * image is locked or not.
Packit f0b94e
   *
Packit f0b94e
   * It's safe to call LockImage() on an image that's already locked; this has
Packit f0b94e
   * no effect.
Packit f0b94e
   *
Packit f0b94e
   * You must always unlock any image you lock. You may do this explicitly by
Packit f0b94e
   * calling UnlockImage(), or implicitly by calling RemoveImage(). Since you're
Packit f0b94e
   * required to call RemoveImage() when you destroy an image, this doesn't
Packit f0b94e
   * impose any additional requirements, but it's preferable to call
Packit f0b94e
   * UnlockImage() earlier if it's possible.
Packit f0b94e
   *
Packit f0b94e
   * @param aImageKey    The image to lock.
Packit f0b94e
   */
Packit f0b94e
  static void LockImage(const ImageKey aImageKey);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Unlocks an image, allowing any of its cache entries to expire at any time.
Packit f0b94e
   *
Packit f0b94e
   * It's OK to call UnlockImage() on an image that's already unlocked; this has
Packit f0b94e
   * no effect.
Packit f0b94e
   *
Packit f0b94e
   * @param aImageKey    The image to unlock.
Packit f0b94e
   */
Packit f0b94e
  static void UnlockImage(const ImageKey aImageKey);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Unlocks the existing cache entries of an image, allowing them to expire at
Packit f0b94e
   * any time.
Packit f0b94e
   *
Packit f0b94e
   * This does not unlock the image itself, so accessing the cache entries via
Packit f0b94e
   * Lookup() or LookupBestMatch() will lock them again, and prevent them from
Packit f0b94e
   * expiring.
Packit f0b94e
   *
Packit f0b94e
   * This is intended to be used in situations where it's no longer clear that
Packit f0b94e
   * all of the cache entries owned by an image are needed. Calling
Packit f0b94e
   * UnlockSurfaces() and then taking some action that will cause Lookup() to
Packit f0b94e
   * touch any cache entries that are still useful will permit the remaining
Packit f0b94e
   * entries to expire from the cache.
Packit f0b94e
   *
Packit f0b94e
   * If the image is unlocked, this has no effect.
Packit f0b94e
   *
Packit f0b94e
   * @param aImageKey    The image which should have its existing cache entries
Packit f0b94e
   *                     unlocked.
Packit f0b94e
   */
Packit f0b94e
  static void UnlockEntries(const ImageKey aImageKey);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Removes all cache entries (including placeholders) associated with the
Packit f0b94e
   * given image from the cache.  If the image is locked, it is automatically
Packit f0b94e
   * unlocked.
Packit f0b94e
   *
Packit f0b94e
   * This MUST be called, at a minimum, when an Image which could be storing
Packit f0b94e
   * entries in the surface cache is destroyed. If another image were allocated
Packit f0b94e
   * at the same address it could result in subtle, difficult-to-reproduce bugs.
Packit f0b94e
   *
Packit f0b94e
   * @param aImageKey  The image which should be removed from the cache.
Packit f0b94e
   */
Packit f0b94e
  static void RemoveImage(const ImageKey aImageKey);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Attempts to remove cache entries (including placeholders) associated with
Packit f0b94e
   * the given image from the cache, assuming there is an equivalent entry that
Packit f0b94e
   * it is able substitute that entry with. Note that this only applies if the
Packit f0b94e
   * image is in factor of 2 mode. If it is not, this operation does nothing.
Packit f0b94e
   *
Packit f0b94e
   * @param aImageKey  The image whose cache which should be pruned.
Packit f0b94e
   */
Packit f0b94e
  static void PruneImage(const ImageKey aImageKey);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Evicts all evictable entries from the cache.
Packit f0b94e
   *
Packit f0b94e
   * All entries are evictable except for entries associated with locked images.
Packit f0b94e
   * Non-evictable entries can only be removed by RemoveImage().
Packit f0b94e
   */
Packit f0b94e
  static void DiscardAll();
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * Collects an accounting of the surfaces contained in the SurfaceCache for
Packit f0b94e
   * the given image, along with their size and various other metadata.
Packit f0b94e
   *
Packit f0b94e
   * This is intended for use with memory reporting.
Packit f0b94e
   *
Packit f0b94e
   * @param aImageKey     The image to report memory usage for.
Packit f0b94e
   * @param aCounters     An array into which the report for each surface will
Packit f0b94e
   *                      be written.
Packit f0b94e
   * @param aMallocSizeOf A fallback malloc memory reporting function.
Packit f0b94e
   */
Packit f0b94e
  static void CollectSizeOfSurfaces(const ImageKey aImageKey,
Packit f0b94e
                                    nsTArray<SurfaceMemoryCounter>& aCounters,
Packit f0b94e
                                    MallocSizeOf aMallocSizeOf);
Packit f0b94e
Packit f0b94e
  /**
Packit f0b94e
   * @return maximum capacity of the SurfaceCache in bytes. This is only exposed
Packit f0b94e
   * for use by tests; normal code should use CanHold() instead.
Packit f0b94e
   */
Packit f0b94e
  static size_t MaximumCapacity();
Packit f0b94e
Packit f0b94e
 private:
Packit f0b94e
  virtual ~SurfaceCache() = 0;  // Forbid instantiation.
Packit f0b94e
};
Packit f0b94e
Packit f0b94e
}  // namespace image
Packit f0b94e
}  // namespace mozilla
Packit f0b94e
Packit f0b94e
#endif  // mozilla_image_SurfaceCache_h