/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
bool IsNotable() const { // Errors or requests without images are always notable. if (mHasError || mValidating || mProgress == UINT32_MAX ||
mProgress & FLAG_HAS_ERROR || mType == imgIContainer::TYPE_REQUEST) { returntrue;
}
// Sufficiently large images are notable. const size_t NotableThreshold = 16 * 1024;
size_t total = mValues.Source() + mValues.DecodedHeap() +
mValues.DecodedNonHeap() + mValues.DecodedUnknown(); if (total >= NotableThreshold) { returntrue;
}
// Incomplete images are always notable as well; the odds of capturing // mid-decode should be fairly low. for (constauto& surface : mSurfaces) { if (!surface.IsFinished()) { returntrue;
}
}
/////////////////////////////////////////////////////////////////////////////// // Image Base Types ///////////////////////////////////////////////////////////////////////////////
class Image : public imgIContainer { public: /** * Flags for Image initialization. * * Meanings: * * INIT_FLAG_NONE: Lack of flags * * INIT_FLAG_DISCARDABLE: The container should be discardable * * INIT_FLAG_DECODE_IMMEDIATELY: The container should decode as soon as * possible, regardless of what our heuristics say. * * INIT_FLAG_TRANSIENT: The container is likely to exist for only a short time * before being destroyed. (For example, containers for * multipart/x-mixed-replace image parts fall into this category.) If this * flag is set, INIT_FLAG_DISCARDABLE and INIT_FLAG_DECODE_ONLY_ON_DRAW must * not be set. * * INIT_FLAG_SYNC_LOAD: The container is being loaded synchronously, so * it should avoid relying on async workers to get the container ready.
*/ staticconst uint32_t INIT_FLAG_NONE = 0x0; staticconst uint32_t INIT_FLAG_DISCARDABLE = 0x1; staticconst uint32_t INIT_FLAG_DECODE_IMMEDIATELY = 0x2; staticconst uint32_t INIT_FLAG_TRANSIENT = 0x4; staticconst uint32_t INIT_FLAG_SYNC_LOAD = 0x8;
/** * The size, in bytes, occupied by the compressed source data of the image. * If MallocSizeOf does not work on this platform, uses a fallback approach to * ensure that something reasonable is always returned.
*/ virtual size_t SizeOfSourceWithComputedFallback(
SizeOfState& aState) const = 0;
/** * Collect an accounting of the memory occupied by the image's surfaces (which * together make up its decoded data). Each surface is recorded as a separate * SurfaceMemoryCounter, stored in @aCounters.
*/ virtualvoid CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
MallocSizeOf aMallocSizeOf) const = 0;
/** * Called from OnDataAvailable when the stream associated with the image has * received new image data. The arguments are the same as OnDataAvailable's, * but by separating this functionality into a different method we don't * interfere with subclasses which wish to implement nsIStreamListener. * * Images should not do anything that could send out notifications until they * have received their first OnImageDataAvailable notification; in * particular, this means that instantiating decoders should be deferred * until OnImageDataAvailable is called.
*/ virtual nsresult OnImageDataAvailable(nsIRequest* aRequest,
nsIInputStream* aInStr,
uint64_t aSourceOffset,
uint32_t aCount) = 0;
/** * Called from OnStopRequest when the image's underlying request completes. * * @param aRequest The completed request. * @param aStatus A success or failure code. * @param aLastPart Whether this is the final part of the underlying request.
*/ virtual nsresult OnImageDataComplete(nsIRequest* aRequest, nsresult aStatus, bool aLastPart) = 0;
/** * Called when the SurfaceCache discards a surface belonging to this image.
*/ virtualvoid OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) = 0;
/* * Returns a non-AddRefed pointer to the URI associated with this image. * Illegal to use off-main-thread.
*/
nsIURI* GetURI() const override { return mURI; }
/* * Should be called by its subclasses after they populate @aCounters so that * we can cross reference against any of our ImageContainers that contain * surfaces not in the cache.
*/ void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
MallocSizeOf aMallocSizeOf) const override;
// Shared functionality for implementors of imgIContainer. Every // implementation of attribute animationMode should forward here.
nsresult GetAnimationModeInternal(uint16_t* aAnimationMode);
nsresult SetAnimationModeInternal(uint16_t aAnimationMode);
/** * Helper for RequestRefresh. * * If we've had a "recent" refresh (i.e. if this image is being used in * multiple documents & some other document *just* called RequestRefresh() on * this image with a timestamp close to aTime), this method returns true. * * Otherwise, this method updates mLastRefreshTime to aTime & returns false.
*/ bool HadRecentRefresh(const TimeStamp& aTime);
/** * Decides whether animation should or should not be happening, * and makes sure the right thing is being done.
*/ virtualvoid EvaluateAnimation();
/** * Extended by child classes, if they have additional * conditions for being able to animate.
*/ virtualbool ShouldAnimate() { return mAnimationConsumers > 0 && mAnimationMode != kDontAnimMode;
}
#ifdef DEBUG // Records the image drawing for startup performance testing. void NotifyDrawingObservers(); #endif
// Member data shared by all implementations of this abstract class
RefPtr<ProgressTracker> mProgressTracker;
nsCOMPtr<nsIURI> mURI;
TimeStamp mLastRefreshTime;
uint64_t mInnerWindowId;
uint32_t mAnimationConsumers;
uint16_t mAnimationMode; // Enum values in imgIContainer bool mInitialized : 1; // Have we been initialized? bool mAnimating : 1; // Are we currently animating? bool mError : 1; // Error handling
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.