2010-08-14 04:09:48 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* 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/. */
|
2010-08-14 04:09:48 +00:00
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#ifndef mozilla_image_Image_h
|
|
|
|
#define mozilla_image_Image_h
|
2010-08-14 04:09:48 +00:00
|
|
|
|
2018-10-02 17:28:33 +00:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-06-23 12:03:39 +00:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2020-11-23 16:21:38 +00:00
|
|
|
#include "mozilla/SizeOfState.h"
|
2020-09-21 18:14:47 +00:00
|
|
|
#include "mozilla/ThreadSafeWeakPtr.h"
|
2015-01-07 09:35:20 +00:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2020-09-21 18:14:47 +00:00
|
|
|
#include "mozilla/Tuple.h"
|
2015-07-29 04:02:45 +00:00
|
|
|
#include "gfx2DGlue.h"
|
2010-08-14 04:09:48 +00:00
|
|
|
#include "imgIContainer.h"
|
2017-11-17 11:45:23 +00:00
|
|
|
#include "ImageContainer.h"
|
2017-11-17 11:45:27 +00:00
|
|
|
#include "LookupResult.h"
|
2014-05-08 09:53:00 +00:00
|
|
|
#include "nsStringFwd.h"
|
2015-04-28 18:46:17 +00:00
|
|
|
#include "ProgressTracker.h"
|
|
|
|
#include "SurfaceCache.h"
|
2013-09-07 13:01:08 +00:00
|
|
|
|
2020-01-21 14:39:59 +00:00
|
|
|
class imgRequest;
|
2013-09-07 13:01:08 +00:00
|
|
|
class nsIRequest;
|
|
|
|
class nsIInputStream;
|
2010-08-14 04:09:48 +00:00
|
|
|
|
|
|
|
namespace mozilla {
|
2012-01-06 16:02:27 +00:00
|
|
|
namespace image {
|
2010-08-14 04:09:48 +00:00
|
|
|
|
2015-04-28 18:46:17 +00:00
|
|
|
class Image;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Memory Reporting
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct MemoryCounter {
|
|
|
|
MemoryCounter()
|
|
|
|
: mSource(0),
|
|
|
|
mDecodedHeap(0),
|
|
|
|
mDecodedNonHeap(0),
|
2020-02-05 22:22:13 +00:00
|
|
|
mDecodedUnknown(0),
|
2018-02-22 19:26:29 +00:00
|
|
|
mExternalHandles(0),
|
2018-09-25 13:13:51 +00:00
|
|
|
mFrameIndex(0),
|
2020-02-05 22:22:13 +00:00
|
|
|
mExternalId(0),
|
|
|
|
mSurfaceTypes(0) {}
|
2015-04-28 18:46:17 +00:00
|
|
|
|
|
|
|
void SetSource(size_t aCount) { mSource = aCount; }
|
|
|
|
size_t Source() const { return mSource; }
|
|
|
|
void SetDecodedHeap(size_t aCount) { mDecodedHeap = aCount; }
|
|
|
|
size_t DecodedHeap() const { return mDecodedHeap; }
|
|
|
|
void SetDecodedNonHeap(size_t aCount) { mDecodedNonHeap = aCount; }
|
|
|
|
size_t DecodedNonHeap() const { return mDecodedNonHeap; }
|
2020-02-05 22:22:13 +00:00
|
|
|
void SetDecodedUnknown(size_t aCount) { mDecodedUnknown = aCount; }
|
|
|
|
size_t DecodedUnknown() const { return mDecodedUnknown; }
|
2018-02-22 19:26:29 +00:00
|
|
|
void SetExternalHandles(size_t aCount) { mExternalHandles = aCount; }
|
|
|
|
size_t ExternalHandles() const { return mExternalHandles; }
|
2018-09-25 13:13:51 +00:00
|
|
|
void SetFrameIndex(size_t aIndex) { mFrameIndex = aIndex; }
|
|
|
|
size_t FrameIndex() const { return mFrameIndex; }
|
|
|
|
void SetExternalId(uint64_t aId) { mExternalId = aId; }
|
|
|
|
uint64_t ExternalId() const { return mExternalId; }
|
2020-02-05 22:22:13 +00:00
|
|
|
void SetSurfaceTypes(uint32_t aTypes) { mSurfaceTypes = aTypes; }
|
|
|
|
uint32_t SurfaceTypes() const { return mSurfaceTypes; }
|
2015-04-28 18:46:17 +00:00
|
|
|
|
|
|
|
MemoryCounter& operator+=(const MemoryCounter& aOther) {
|
|
|
|
mSource += aOther.mSource;
|
|
|
|
mDecodedHeap += aOther.mDecodedHeap;
|
|
|
|
mDecodedNonHeap += aOther.mDecodedNonHeap;
|
2020-02-05 22:22:13 +00:00
|
|
|
mDecodedUnknown += aOther.mDecodedUnknown;
|
2018-02-22 19:26:29 +00:00
|
|
|
mExternalHandles += aOther.mExternalHandles;
|
2020-02-05 22:22:13 +00:00
|
|
|
mSurfaceTypes |= aOther.mSurfaceTypes;
|
2015-04-28 18:46:17 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t mSource;
|
|
|
|
size_t mDecodedHeap;
|
|
|
|
size_t mDecodedNonHeap;
|
2020-02-05 22:22:13 +00:00
|
|
|
size_t mDecodedUnknown;
|
2018-02-22 19:26:29 +00:00
|
|
|
size_t mExternalHandles;
|
2018-09-25 13:13:51 +00:00
|
|
|
size_t mFrameIndex;
|
|
|
|
uint64_t mExternalId;
|
2020-02-05 22:22:13 +00:00
|
|
|
uint32_t mSurfaceTypes;
|
2015-04-28 18:46:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class SurfaceMemoryCounterType { NORMAL, COMPOSITING, COMPOSITING_PREV };
|
|
|
|
|
|
|
|
struct SurfaceMemoryCounter {
|
|
|
|
SurfaceMemoryCounter(
|
|
|
|
const SurfaceKey& aKey, bool aIsLocked, bool aCannotSubstitute,
|
2020-01-21 09:59:15 +00:00
|
|
|
bool aIsFactor2, bool aFinished,
|
2015-04-28 18:46:17 +00:00
|
|
|
SurfaceMemoryCounterType aType = SurfaceMemoryCounterType::NORMAL)
|
|
|
|
: mKey(aKey),
|
|
|
|
mType(aType),
|
|
|
|
mIsLocked(aIsLocked),
|
2017-09-05 11:58:46 +00:00
|
|
|
mCannotSubstitute(aCannotSubstitute),
|
2020-01-21 09:59:15 +00:00
|
|
|
mIsFactor2(aIsFactor2),
|
|
|
|
mFinished(aFinished) {}
|
2015-04-28 18:46:17 +00:00
|
|
|
|
|
|
|
const SurfaceKey& Key() const { return mKey; }
|
|
|
|
MemoryCounter& Values() { return mValues; }
|
|
|
|
const MemoryCounter& Values() const { return mValues; }
|
|
|
|
SurfaceMemoryCounterType Type() const { return mType; }
|
|
|
|
bool IsLocked() const { return mIsLocked; }
|
2017-09-05 11:58:46 +00:00
|
|
|
bool CannotSubstitute() const { return mCannotSubstitute; }
|
|
|
|
bool IsFactor2() const { return mIsFactor2; }
|
2020-01-21 09:59:15 +00:00
|
|
|
bool IsFinished() const { return mFinished; }
|
2015-04-28 18:46:17 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
const SurfaceKey mKey;
|
|
|
|
MemoryCounter mValues;
|
|
|
|
const SurfaceMemoryCounterType mType;
|
|
|
|
const bool mIsLocked;
|
2017-09-05 11:58:46 +00:00
|
|
|
const bool mCannotSubstitute;
|
|
|
|
const bool mIsFactor2;
|
2020-01-21 09:59:15 +00:00
|
|
|
const bool mFinished;
|
2015-04-28 18:46:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ImageMemoryCounter {
|
2020-01-21 14:39:59 +00:00
|
|
|
ImageMemoryCounter(imgRequest* aRequest, SizeOfState& aState, bool aIsUsed);
|
2020-01-21 16:32:11 +00:00
|
|
|
ImageMemoryCounter(imgRequest* aRequest, Image* aImage, SizeOfState& aState,
|
|
|
|
bool aIsUsed);
|
2015-04-28 18:46:17 +00:00
|
|
|
|
|
|
|
nsCString& URI() { return mURI; }
|
|
|
|
const nsCString& URI() const { return mURI; }
|
|
|
|
const nsTArray<SurfaceMemoryCounter>& Surfaces() const { return mSurfaces; }
|
|
|
|
const gfx::IntSize IntrinsicSize() const { return mIntrinsicSize; }
|
|
|
|
const MemoryCounter& Values() const { return mValues; }
|
2020-01-21 14:39:59 +00:00
|
|
|
uint32_t Progress() const { return mProgress; }
|
2015-04-28 18:46:17 +00:00
|
|
|
uint16_t Type() const { return mType; }
|
|
|
|
bool IsUsed() const { return mIsUsed; }
|
2020-01-21 14:39:59 +00:00
|
|
|
bool HasError() const { return mHasError; }
|
2020-01-21 16:32:11 +00:00
|
|
|
bool IsValidating() const { return mValidating; }
|
2015-04-28 18:46:17 +00:00
|
|
|
|
|
|
|
bool IsNotable() const {
|
2020-01-21 14:39:59 +00:00
|
|
|
// Errors or requests without images are always notable.
|
2020-02-05 22:22:13 +00:00
|
|
|
if (mHasError || mValidating || mProgress == UINT32_MAX ||
|
|
|
|
mProgress & FLAG_HAS_ERROR || mType == imgIContainer::TYPE_REQUEST) {
|
2020-01-21 14:39:59 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sufficiently large images are notable.
|
2015-04-28 18:46:17 +00:00
|
|
|
const size_t NotableThreshold = 16 * 1024;
|
2020-02-05 22:22:13 +00:00
|
|
|
size_t total = mValues.Source() + mValues.DecodedHeap() +
|
|
|
|
mValues.DecodedNonHeap() + mValues.DecodedUnknown();
|
2020-01-21 14:39:59 +00:00
|
|
|
if (total >= NotableThreshold) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Incomplete images are always notable as well; the odds of capturing
|
|
|
|
// mid-decode should be fairly low.
|
|
|
|
for (const auto& surface : mSurfaces) {
|
|
|
|
if (!surface.IsFinished()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-04-28 18:46:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCString mURI;
|
|
|
|
nsTArray<SurfaceMemoryCounter> mSurfaces;
|
|
|
|
gfx::IntSize mIntrinsicSize;
|
|
|
|
MemoryCounter mValues;
|
2020-01-21 14:39:59 +00:00
|
|
|
uint32_t mProgress;
|
2015-04-28 18:46:17 +00:00
|
|
|
uint16_t mType;
|
|
|
|
const bool mIsUsed;
|
2020-01-21 14:39:59 +00:00
|
|
|
bool mHasError;
|
2020-01-21 16:32:11 +00:00
|
|
|
bool mValidating;
|
2015-04-28 18:46:17 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Image Base Types
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-08-14 04:09:48 +00:00
|
|
|
class Image : public imgIContainer {
|
|
|
|
public:
|
2010-08-14 04:09:49 +00:00
|
|
|
/**
|
|
|
|
* Flags for Image initialization.
|
|
|
|
*
|
|
|
|
* Meanings:
|
|
|
|
*
|
|
|
|
* INIT_FLAG_NONE: Lack of flags
|
|
|
|
*
|
|
|
|
* INIT_FLAG_DISCARDABLE: The container should be discardable
|
|
|
|
*
|
2015-04-07 23:44:29 +00:00
|
|
|
* INIT_FLAG_DECODE_IMMEDIATELY: The container should decode as soon as
|
|
|
|
* possible, regardless of what our heuristics say.
|
|
|
|
*
|
2015-01-07 09:37:20 +00:00
|
|
|
* 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
|
2015-03-24 22:39:00 +00:00
|
|
|
* flag is set, INIT_FLAG_DISCARDABLE and INIT_FLAG_DECODE_ONLY_ON_DRAW must
|
|
|
|
* not be set.
|
2015-01-18 22:02:13 +00:00
|
|
|
*
|
2015-06-30 09:37:58 +00:00
|
|
|
* INIT_FLAG_SYNC_LOAD: The container is being loaded synchronously, so
|
|
|
|
* it should avoid relying on async workers to get the container ready.
|
2010-08-14 04:09:49 +00:00
|
|
|
*/
|
2015-01-18 22:02:13 +00:00
|
|
|
static const uint32_t INIT_FLAG_NONE = 0x0;
|
|
|
|
static const uint32_t INIT_FLAG_DISCARDABLE = 0x1;
|
2015-07-15 01:16:31 +00:00
|
|
|
static const uint32_t INIT_FLAG_DECODE_IMMEDIATELY = 0x2;
|
|
|
|
static const uint32_t INIT_FLAG_TRANSIENT = 0x4;
|
2015-09-19 23:21:05 +00:00
|
|
|
static const uint32_t INIT_FLAG_SYNC_LOAD = 0x8;
|
2010-08-14 04:09:49 +00:00
|
|
|
|
2014-11-15 04:10:47 +00:00
|
|
|
virtual already_AddRefed<ProgressTracker> GetProgressTracker() = 0;
|
|
|
|
virtual void SetProgressTracker(ProgressTracker* aProgressTracker) {}
|
2012-12-19 22:24:32 +00:00
|
|
|
|
2010-08-14 04:09:49 +00:00
|
|
|
/**
|
2014-11-27 02:00:15 +00:00
|
|
|
* 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.
|
2010-08-14 04:09:49 +00:00
|
|
|
*/
|
2017-07-28 10:10:04 +00:00
|
|
|
virtual size_t SizeOfSourceWithComputedFallback(
|
|
|
|
SizeOfState& aState) const = 0;
|
2010-10-06 15:37:12 +00:00
|
|
|
|
|
|
|
/**
|
2015-04-28 18:46:17 +00:00
|
|
|
* 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.
|
2013-03-29 20:14:19 +00:00
|
|
|
*/
|
2015-04-28 18:46:17 +00:00
|
|
|
virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const = 0;
|
2014-05-08 09:53:00 +00:00
|
|
|
|
2012-12-19 22:24:32 +00:00
|
|
|
virtual void IncrementAnimationConsumers() = 0;
|
|
|
|
virtual void DecrementAnimationConsumers() = 0;
|
2010-09-08 00:33:02 +00:00
|
|
|
#ifdef DEBUG
|
2012-12-19 22:24:32 +00:00
|
|
|
virtual uint32_t GetAnimationConsumers() = 0;
|
2010-09-08 00:33:02 +00:00
|
|
|
#endif
|
|
|
|
|
2012-12-17 22:05:18 +00:00
|
|
|
/**
|
|
|
|
* 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,
|
|
|
|
nsISupports* aContext,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
|
|
|
uint32_t aCount) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called from OnStopRequest when the image's underlying request completes.
|
2013-02-14 02:41:10 +00:00
|
|
|
*
|
|
|
|
* @param aRequest The completed request.
|
|
|
|
* @param aContext Context from Necko's OnStopRequest.
|
|
|
|
* @param aStatus A success or failure code.
|
|
|
|
* @param aLastPart Whether this is the final part of the underlying request.
|
2012-12-17 22:05:18 +00:00
|
|
|
*/
|
|
|
|
virtual nsresult OnImageDataComplete(nsIRequest* aRequest,
|
|
|
|
nsISupports* aContext, nsresult aStatus,
|
2013-02-14 02:41:10 +00:00
|
|
|
bool aLastPart) = 0;
|
2012-12-17 22:05:18 +00:00
|
|
|
|
2014-11-28 03:55:57 +00:00
|
|
|
/**
|
2015-09-19 23:20:59 +00:00
|
|
|
* Called when the SurfaceCache discards a surface belonging to this image.
|
2014-11-28 03:55:57 +00:00
|
|
|
*/
|
2017-03-16 08:06:06 +00:00
|
|
|
virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) = 0;
|
2014-11-28 03:55:57 +00:00
|
|
|
|
2012-12-19 22:24:32 +00:00
|
|
|
virtual void SetInnerWindowID(uint64_t aInnerWindowId) = 0;
|
|
|
|
virtual uint64_t InnerWindowID() const = 0;
|
|
|
|
|
|
|
|
virtual bool HasError() = 0;
|
|
|
|
virtual void SetHasError() = 0;
|
|
|
|
|
2018-06-06 00:42:56 +00:00
|
|
|
virtual nsIURI* GetURI() const = 0;
|
2020-03-31 21:16:39 +00:00
|
|
|
|
|
|
|
NS_IMETHOD GetHotspotX(int32_t* aX) override {
|
|
|
|
*aX = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
NS_IMETHOD GetHotspotY(int32_t* aY) override {
|
|
|
|
*aY = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-12-19 22:24:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class ImageResource : public Image {
|
|
|
|
public:
|
2015-03-21 16:28:04 +00:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() override {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ProgressTracker> progressTracker = mProgressTracker;
|
2014-11-15 04:10:47 +00:00
|
|
|
MOZ_ASSERT(progressTracker);
|
|
|
|
return progressTracker.forget();
|
2013-09-28 18:28:44 +00:00
|
|
|
}
|
2014-12-04 19:23:00 +00:00
|
|
|
|
2018-02-09 05:22:43 +00:00
|
|
|
void SetProgressTracker(ProgressTracker* aProgressTracker) final {
|
2014-11-15 04:10:47 +00:00
|
|
|
MOZ_ASSERT(aProgressTracker);
|
|
|
|
MOZ_ASSERT(!mProgressTracker);
|
|
|
|
mProgressTracker = aProgressTracker;
|
2013-09-28 18:28:44 +00:00
|
|
|
}
|
2012-12-19 22:24:32 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void IncrementAnimationConsumers() override;
|
|
|
|
virtual void DecrementAnimationConsumers() override;
|
2012-12-19 22:24:32 +00:00
|
|
|
#ifdef DEBUG
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual uint32_t GetAnimationConsumers() override {
|
2014-12-04 19:23:00 +00:00
|
|
|
return mAnimationConsumers;
|
|
|
|
}
|
2012-12-19 22:24:32 +00:00
|
|
|
#endif
|
|
|
|
|
2017-03-16 08:06:06 +00:00
|
|
|
virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override {}
|
2014-11-28 03:55:57 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual void SetInnerWindowID(uint64_t aInnerWindowId) override {
|
2011-08-24 20:44:35 +00:00
|
|
|
mInnerWindowId = aInnerWindowId;
|
2010-12-20 16:21:59 +00:00
|
|
|
}
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual uint64_t InnerWindowID() const override { return mInnerWindowId; }
|
2010-12-20 16:21:59 +00:00
|
|
|
|
2015-03-21 16:28:04 +00:00
|
|
|
virtual bool HasError() override { return mError; }
|
|
|
|
virtual void SetHasError() override { mError = true; }
|
2012-12-14 23:42:18 +00:00
|
|
|
|
2012-12-19 21:28:54 +00:00
|
|
|
/*
|
|
|
|
* Returns a non-AddRefed pointer to the URI associated with this image.
|
2013-09-12 00:01:59 +00:00
|
|
|
* Illegal to use off-main-thread.
|
2012-12-19 21:28:54 +00:00
|
|
|
*/
|
2018-06-06 00:42:56 +00:00
|
|
|
nsIURI* GetURI() const override { return mURI; }
|
2012-12-19 21:28:54 +00:00
|
|
|
|
2010-08-14 04:09:48 +00:00
|
|
|
protected:
|
2018-06-06 00:42:56 +00:00
|
|
|
explicit ImageResource(nsIURI* aURI);
|
2015-04-28 23:32:02 +00:00
|
|
|
~ImageResource();
|
2010-08-14 04:09:48 +00:00
|
|
|
|
2019-02-13 19:13:55 +00:00
|
|
|
layers::ContainerProducerID GetImageProducerId() const {
|
|
|
|
return mImageProducerID;
|
|
|
|
}
|
|
|
|
|
2018-06-06 00:42:56 +00:00
|
|
|
bool GetSpecTruncatedTo1k(nsCString& aSpec) const;
|
|
|
|
|
2012-10-19 20:27:11 +00:00
|
|
|
// Shared functionality for implementors of imgIContainer. Every
|
|
|
|
// implementation of attribute animationMode should forward here.
|
2014-12-04 19:23:00 +00:00
|
|
|
nsresult GetAnimationModeInternal(uint16_t* aAnimationMode);
|
2012-10-19 20:27:11 +00:00
|
|
|
nsresult SetAnimationModeInternal(uint16_t aAnimationMode);
|
|
|
|
|
2014-05-08 18:37:39 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*/
|
2014-07-10 15:00:31 +00:00
|
|
|
bool HadRecentRefresh(const TimeStamp& aTime);
|
2014-05-08 18:37:39 +00:00
|
|
|
|
2010-09-08 00:33:02 +00:00
|
|
|
/**
|
|
|
|
* Decides whether animation should or should not be happening,
|
|
|
|
* and makes sure the right thing is being done.
|
|
|
|
*/
|
|
|
|
virtual void EvaluateAnimation();
|
|
|
|
|
2012-12-19 22:24:32 +00:00
|
|
|
/**
|
|
|
|
* Extended by child classes, if they have additional
|
|
|
|
* conditions for being able to animate.
|
|
|
|
*/
|
|
|
|
virtual bool ShouldAnimate() {
|
|
|
|
return mAnimationConsumers > 0 && mAnimationMode != kDontAnimMode;
|
|
|
|
}
|
|
|
|
|
2010-09-08 00:33:02 +00:00
|
|
|
virtual nsresult StartAnimation() = 0;
|
|
|
|
virtual nsresult StopAnimation() = 0;
|
|
|
|
|
2016-11-17 06:25:53 +00:00
|
|
|
void SendOnUnlockedDraw(uint32_t aFlags);
|
|
|
|
|
2017-11-17 11:45:23 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Records the image drawing for startup performance testing.
|
|
|
|
void NotifyDrawingObservers();
|
|
|
|
#endif
|
|
|
|
|
2010-08-14 04:09:48 +00:00
|
|
|
// Member data shared by all implementations of this abstract class
|
2018-06-06 00:42:56 +00:00
|
|
|
RefPtr<ProgressTracker> mProgressTracker;
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2014-05-08 18:37:39 +00:00
|
|
|
TimeStamp mLastRefreshTime;
|
2013-09-12 00:01:59 +00:00
|
|
|
uint64_t mInnerWindowId;
|
|
|
|
uint32_t mAnimationConsumers;
|
|
|
|
uint16_t mAnimationMode; // Enum values in imgIContainer
|
2019-09-12 09:00:52 +00:00
|
|
|
bool mInitialized : 1; // Have we been initialized?
|
2013-09-12 00:01:59 +00:00
|
|
|
bool mAnimating : 1; // Are we currently animating?
|
|
|
|
bool mError : 1; // Error handling
|
2017-11-17 11:45:23 +00:00
|
|
|
|
2018-09-21 00:22:06 +00:00
|
|
|
/**
|
|
|
|
* Attempt to find a matching cached surface in the SurfaceCache, and if not
|
|
|
|
* available, request the production of such a surface (either synchronously
|
|
|
|
* or asynchronously).
|
|
|
|
*
|
|
|
|
* If the draw result is BAD_IMAGE, BAD_ARGS or NOT_READY, the size will be
|
|
|
|
* the same as aSize. If it is TEMPORARY_ERROR, INCOMPLETE, or SUCCESS, the
|
|
|
|
* size is a hint as to what we expect the surface size to be, once the best
|
|
|
|
* fitting size is available. It may or may not match the size of the surface
|
|
|
|
* returned at this moment. This is useful for choosing how to store the final
|
|
|
|
* result (e.g. if going into an ImageContainer, ideally we would share the
|
|
|
|
* same container for many requested sizes, if they all end up with the same
|
|
|
|
* best fit size in the end).
|
|
|
|
*
|
|
|
|
* A valid surface should only be returned for SUCCESS and INCOMPLETE.
|
|
|
|
*
|
|
|
|
* Any other draw result is invalid.
|
|
|
|
*/
|
2017-12-11 15:37:59 +00:00
|
|
|
virtual Tuple<ImgDrawResult, gfx::IntSize, RefPtr<gfx::SourceSurface>>
|
2017-11-17 11:45:24 +00:00
|
|
|
GetFrameInternal(const gfx::IntSize& aSize,
|
2017-11-17 19:08:52 +00:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2017-11-17 11:45:24 +00:00
|
|
|
uint32_t aWhichFrame, uint32_t aFlags) {
|
2017-12-11 15:37:59 +00:00
|
|
|
return MakeTuple(ImgDrawResult::BAD_IMAGE, aSize,
|
2017-11-17 11:45:27 +00:00
|
|
|
RefPtr<gfx::SourceSurface>());
|
2017-11-17 11:45:24 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 11:45:26 +00:00
|
|
|
/**
|
|
|
|
* Calculate the estimated size to use for an image container with the given
|
|
|
|
* parameters. It may not be the same as the given size, and it may not be
|
|
|
|
* the same as the size of the surface in the image container, but it is the
|
|
|
|
* best effort estimate.
|
|
|
|
*/
|
2018-09-13 23:48:21 +00:00
|
|
|
virtual Tuple<ImgDrawResult, gfx::IntSize> GetImageContainerSize(
|
|
|
|
layers::LayerManager* aManager, const gfx::IntSize& aSize,
|
|
|
|
uint32_t aFlags) {
|
|
|
|
return MakeTuple(ImgDrawResult::NOT_SUPPORTED, gfx::IntSize(0, 0));
|
2017-11-17 11:45:26 +00:00
|
|
|
}
|
|
|
|
|
2018-09-13 23:48:21 +00:00
|
|
|
ImgDrawResult GetImageContainerImpl(layers::LayerManager* aManager,
|
|
|
|
const gfx::IntSize& aSize,
|
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
|
|
|
uint32_t aFlags,
|
|
|
|
layers::ImageContainer** aContainer);
|
2017-11-17 11:45:24 +00:00
|
|
|
|
2018-12-17 13:31:04 +00:00
|
|
|
/**
|
|
|
|
* Re-requests the appropriate frames for each image container using
|
|
|
|
* GetFrameInternal.
|
|
|
|
* @returns True if any image containers were updated, else false.
|
|
|
|
*/
|
|
|
|
bool UpdateImageContainer(const Maybe<gfx::IntRect>& aDirtyRect);
|
2017-11-17 11:45:24 +00:00
|
|
|
|
|
|
|
void ReleaseImageContainer();
|
|
|
|
|
|
|
|
private:
|
2017-11-17 11:45:27 +00:00
|
|
|
void SetCurrentImage(layers::ImageContainer* aContainer,
|
|
|
|
gfx::SourceSurface* aSurface,
|
2018-10-02 17:28:33 +00:00
|
|
|
const Maybe<gfx::IntRect>& aDirtyRect);
|
2017-11-17 11:45:25 +00:00
|
|
|
|
2017-11-17 11:45:25 +00:00
|
|
|
struct ImageContainerEntry {
|
|
|
|
ImageContainerEntry(const gfx::IntSize& aSize,
|
2017-11-17 19:08:52 +00:00
|
|
|
const Maybe<SVGImageContext>& aSVGContext,
|
2017-11-17 11:45:28 +00:00
|
|
|
layers::ImageContainer* aContainer, uint32_t aFlags)
|
2017-11-17 11:45:25 +00:00
|
|
|
: mSize(aSize),
|
2017-11-17 19:08:52 +00:00
|
|
|
mSVGContext(aSVGContext),
|
2017-11-17 11:45:25 +00:00
|
|
|
mContainer(aContainer),
|
2017-12-11 15:37:59 +00:00
|
|
|
mLastDrawResult(ImgDrawResult::NOT_READY),
|
2017-11-17 11:45:28 +00:00
|
|
|
mFlags(aFlags) {}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2017-11-17 11:45:25 +00:00
|
|
|
gfx::IntSize mSize;
|
2017-11-17 19:08:52 +00:00
|
|
|
Maybe<SVGImageContext> mSVGContext;
|
2017-11-17 11:45:25 +00:00
|
|
|
// A weak pointer to our ImageContainer, which stays alive only as long as
|
|
|
|
// the layer system needs it.
|
2020-09-21 18:14:47 +00:00
|
|
|
ThreadSafeWeakPtr<layers::ImageContainer> mContainer;
|
2017-12-11 15:37:59 +00:00
|
|
|
// If mContainer is non-null, this contains the ImgDrawResult we obtained
|
2017-11-17 11:45:25 +00:00
|
|
|
// the last time we updated it.
|
2017-12-11 15:37:59 +00:00
|
|
|
ImgDrawResult mLastDrawResult;
|
2017-11-17 11:45:28 +00:00
|
|
|
// Cached flags to use for decoding. FLAG_ASYNC_NOTIFY should always be set
|
|
|
|
// but FLAG_HIGH_QUALITY_SCALING may vary.
|
|
|
|
uint32_t mFlags;
|
2017-11-17 11:45:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
AutoTArray<ImageContainerEntry, 1> mImageContainers;
|
2017-11-17 11:45:23 +00:00
|
|
|
layers::ImageContainer::ProducerID mImageProducerID;
|
|
|
|
layers::ImageContainer::FrameID mLastFrameID;
|
2010-08-14 04:09:48 +00:00
|
|
|
};
|
|
|
|
|
2012-01-06 16:02:27 +00:00
|
|
|
} // namespace image
|
2010-08-14 04:09:48 +00:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-05-15 03:52:05 +00:00
|
|
|
#endif // mozilla_image_Image_h
|