2010-08-14 08:09:48 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04: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 08:09:48 +04:00
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#ifndef mozilla_image_Image_h
|
|
|
|
#define mozilla_image_Image_h
|
2010-08-14 08:09:48 +04:00
|
|
|
|
2021-05-20 15:31:27 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2018-10-02 20:28:33 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2021-04-14 12:00:13 +03:00
|
|
|
#include "mozilla/ProfilerMarkers.h"
|
2020-11-23 19:21:38 +03:00
|
|
|
#include "mozilla/SizeOfState.h"
|
2020-09-21 21:14:47 +03:00
|
|
|
#include "mozilla/ThreadSafeWeakPtr.h"
|
2015-01-07 12:35:20 +03:00
|
|
|
#include "mozilla/TimeStamp.h"
|
2020-09-21 21:14:47 +03:00
|
|
|
#include "mozilla/Tuple.h"
|
2015-07-29 07:02:45 +03:00
|
|
|
#include "gfx2DGlue.h"
|
2010-08-14 08:09:48 +04:00
|
|
|
#include "imgIContainer.h"
|
2017-11-17 14:45:23 +03:00
|
|
|
#include "ImageContainer.h"
|
2021-05-13 19:24:07 +03:00
|
|
|
#include "ImageRegion.h"
|
2017-11-17 14:45:27 +03:00
|
|
|
#include "LookupResult.h"
|
2014-05-08 13:53:00 +04:00
|
|
|
#include "nsStringFwd.h"
|
2015-04-28 21:46:17 +03:00
|
|
|
#include "ProgressTracker.h"
|
|
|
|
#include "SurfaceCache.h"
|
2021-11-27 14:47:36 +03:00
|
|
|
#include "WebRenderImageProvider.h"
|
2013-09-07 17:01:08 +04:00
|
|
|
|
2020-01-21 17:39:59 +03:00
|
|
|
class imgRequest;
|
2013-09-07 17:01:08 +04:00
|
|
|
class nsIRequest;
|
|
|
|
class nsIInputStream;
|
2010-08-14 08:09:48 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
2012-01-06 20:02:27 +04:00
|
|
|
namespace image {
|
2010-08-14 08:09:48 +04:00
|
|
|
|
2015-04-28 21:46:17 +03:00
|
|
|
class Image;
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Memory Reporting
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
struct MemoryCounter {
|
|
|
|
MemoryCounter()
|
|
|
|
: mSource(0),
|
|
|
|
mDecodedHeap(0),
|
|
|
|
mDecodedNonHeap(0),
|
2020-02-06 01:22:13 +03:00
|
|
|
mDecodedUnknown(0),
|
2018-02-22 22:26:29 +03:00
|
|
|
mExternalHandles(0),
|
2018-09-25 16:13:51 +03:00
|
|
|
mFrameIndex(0),
|
2020-02-06 01:22:13 +03:00
|
|
|
mExternalId(0),
|
|
|
|
mSurfaceTypes(0) {}
|
2015-04-28 21:46:17 +03: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-06 01:22:13 +03:00
|
|
|
void SetDecodedUnknown(size_t aCount) { mDecodedUnknown = aCount; }
|
|
|
|
size_t DecodedUnknown() const { return mDecodedUnknown; }
|
2018-02-22 22:26:29 +03:00
|
|
|
void SetExternalHandles(size_t aCount) { mExternalHandles = aCount; }
|
|
|
|
size_t ExternalHandles() const { return mExternalHandles; }
|
2018-09-25 16:13:51 +03: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-06 01:22:13 +03:00
|
|
|
void SetSurfaceTypes(uint32_t aTypes) { mSurfaceTypes = aTypes; }
|
|
|
|
uint32_t SurfaceTypes() const { return mSurfaceTypes; }
|
2015-04-28 21:46:17 +03:00
|
|
|
|
|
|
|
MemoryCounter& operator+=(const MemoryCounter& aOther) {
|
|
|
|
mSource += aOther.mSource;
|
|
|
|
mDecodedHeap += aOther.mDecodedHeap;
|
|
|
|
mDecodedNonHeap += aOther.mDecodedNonHeap;
|
2020-02-06 01:22:13 +03:00
|
|
|
mDecodedUnknown += aOther.mDecodedUnknown;
|
2018-02-22 22:26:29 +03:00
|
|
|
mExternalHandles += aOther.mExternalHandles;
|
2020-02-06 01:22:13 +03:00
|
|
|
mSurfaceTypes |= aOther.mSurfaceTypes;
|
2015-04-28 21:46:17 +03:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
size_t mSource;
|
|
|
|
size_t mDecodedHeap;
|
|
|
|
size_t mDecodedNonHeap;
|
2020-02-06 01:22:13 +03:00
|
|
|
size_t mDecodedUnknown;
|
2018-02-22 22:26:29 +03:00
|
|
|
size_t mExternalHandles;
|
2018-09-25 16:13:51 +03:00
|
|
|
size_t mFrameIndex;
|
|
|
|
uint64_t mExternalId;
|
2020-02-06 01:22:13 +03:00
|
|
|
uint32_t mSurfaceTypes;
|
2015-04-28 21:46:17 +03:00
|
|
|
};
|
|
|
|
|
2021-05-20 15:31:27 +03:00
|
|
|
enum class SurfaceMemoryCounterType { NORMAL, CONTAINER };
|
2015-04-28 21:46:17 +03:00
|
|
|
|
|
|
|
struct SurfaceMemoryCounter {
|
|
|
|
SurfaceMemoryCounter(
|
2021-11-27 14:47:36 +03:00
|
|
|
const SurfaceKey& aKey, bool aIsLocked, bool aCannotSubstitute,
|
|
|
|
bool aIsFactor2, bool aFinished,
|
2015-04-28 21:46:17 +03:00
|
|
|
SurfaceMemoryCounterType aType = SurfaceMemoryCounterType::NORMAL)
|
|
|
|
: mKey(aKey),
|
|
|
|
mType(aType),
|
|
|
|
mIsLocked(aIsLocked),
|
2017-09-05 14:58:46 +03:00
|
|
|
mCannotSubstitute(aCannotSubstitute),
|
2020-01-21 12:59:15 +03:00
|
|
|
mIsFactor2(aIsFactor2),
|
|
|
|
mFinished(aFinished) {}
|
2015-04-28 21:46:17 +03: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 14:58:46 +03:00
|
|
|
bool CannotSubstitute() const { return mCannotSubstitute; }
|
|
|
|
bool IsFactor2() const { return mIsFactor2; }
|
2020-01-21 12:59:15 +03:00
|
|
|
bool IsFinished() const { return mFinished; }
|
2015-04-28 21:46:17 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
const SurfaceKey mKey;
|
|
|
|
MemoryCounter mValues;
|
|
|
|
const SurfaceMemoryCounterType mType;
|
|
|
|
const bool mIsLocked;
|
2017-09-05 14:58:46 +03:00
|
|
|
const bool mCannotSubstitute;
|
|
|
|
const bool mIsFactor2;
|
2020-01-21 12:59:15 +03:00
|
|
|
const bool mFinished;
|
2015-04-28 21:46:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
struct ImageMemoryCounter {
|
2020-01-21 17:39:59 +03:00
|
|
|
ImageMemoryCounter(imgRequest* aRequest, SizeOfState& aState, bool aIsUsed);
|
2020-01-21 19:32:11 +03:00
|
|
|
ImageMemoryCounter(imgRequest* aRequest, Image* aImage, SizeOfState& aState,
|
|
|
|
bool aIsUsed);
|
2015-04-28 21:46:17 +03: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 17:39:59 +03:00
|
|
|
uint32_t Progress() const { return mProgress; }
|
2015-04-28 21:46:17 +03:00
|
|
|
uint16_t Type() const { return mType; }
|
|
|
|
bool IsUsed() const { return mIsUsed; }
|
2020-01-21 17:39:59 +03:00
|
|
|
bool HasError() const { return mHasError; }
|
2020-01-21 19:32:11 +03:00
|
|
|
bool IsValidating() const { return mValidating; }
|
2015-04-28 21:46:17 +03:00
|
|
|
|
|
|
|
bool IsNotable() const {
|
2020-01-21 17:39:59 +03:00
|
|
|
// Errors or requests without images are always notable.
|
2020-02-06 01:22:13 +03:00
|
|
|
if (mHasError || mValidating || mProgress == UINT32_MAX ||
|
|
|
|
mProgress & FLAG_HAS_ERROR || mType == imgIContainer::TYPE_REQUEST) {
|
2020-01-21 17:39:59 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Sufficiently large images are notable.
|
2015-04-28 21:46:17 +03:00
|
|
|
const size_t NotableThreshold = 16 * 1024;
|
2020-02-06 01:22:13 +03:00
|
|
|
size_t total = mValues.Source() + mValues.DecodedHeap() +
|
|
|
|
mValues.DecodedNonHeap() + mValues.DecodedUnknown();
|
2020-01-21 17:39:59 +03: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 21:46:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsCString mURI;
|
|
|
|
nsTArray<SurfaceMemoryCounter> mSurfaces;
|
|
|
|
gfx::IntSize mIntrinsicSize;
|
|
|
|
MemoryCounter mValues;
|
2020-01-21 17:39:59 +03:00
|
|
|
uint32_t mProgress;
|
2015-04-28 21:46:17 +03:00
|
|
|
uint16_t mType;
|
|
|
|
const bool mIsUsed;
|
2020-01-21 17:39:59 +03:00
|
|
|
bool mHasError;
|
2020-01-21 19:32:11 +03:00
|
|
|
bool mValidating;
|
2015-04-28 21:46:17 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Image Base Types
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2010-08-14 08:09:48 +04:00
|
|
|
class Image : public imgIContainer {
|
|
|
|
public:
|
2010-08-14 08:09:49 +04:00
|
|
|
/**
|
|
|
|
* Flags for Image initialization.
|
|
|
|
*
|
|
|
|
* Meanings:
|
|
|
|
*
|
|
|
|
* INIT_FLAG_NONE: Lack of flags
|
|
|
|
*
|
|
|
|
* INIT_FLAG_DISCARDABLE: The container should be discardable
|
|
|
|
*
|
2015-04-08 02:44:29 +03:00
|
|
|
* INIT_FLAG_DECODE_IMMEDIATELY: The container should decode as soon as
|
|
|
|
* possible, regardless of what our heuristics say.
|
|
|
|
*
|
2015-01-07 12:37:20 +03: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-25 01:39:00 +03:00
|
|
|
* flag is set, INIT_FLAG_DISCARDABLE and INIT_FLAG_DECODE_ONLY_ON_DRAW must
|
|
|
|
* not be set.
|
2015-01-19 01:02:13 +03:00
|
|
|
*
|
2015-06-30 12:37:58 +03: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 08:09:49 +04:00
|
|
|
*/
|
2015-01-19 01:02:13 +03:00
|
|
|
static const uint32_t INIT_FLAG_NONE = 0x0;
|
|
|
|
static const uint32_t INIT_FLAG_DISCARDABLE = 0x1;
|
2015-07-15 04:16:31 +03:00
|
|
|
static const uint32_t INIT_FLAG_DECODE_IMMEDIATELY = 0x2;
|
|
|
|
static const uint32_t INIT_FLAG_TRANSIENT = 0x4;
|
2015-09-20 02:21:05 +03:00
|
|
|
static const uint32_t INIT_FLAG_SYNC_LOAD = 0x8;
|
2010-08-14 08:09:49 +04:00
|
|
|
|
2014-11-15 07:10:47 +03:00
|
|
|
virtual already_AddRefed<ProgressTracker> GetProgressTracker() = 0;
|
|
|
|
virtual void SetProgressTracker(ProgressTracker* aProgressTracker) {}
|
2012-12-20 02:24:32 +04:00
|
|
|
|
2010-08-14 08:09:49 +04:00
|
|
|
/**
|
2014-11-27 05:00:15 +03: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 08:09:49 +04:00
|
|
|
*/
|
2017-07-28 13:10:04 +03:00
|
|
|
virtual size_t SizeOfSourceWithComputedFallback(
|
|
|
|
SizeOfState& aState) const = 0;
|
2010-10-06 19:37:12 +04:00
|
|
|
|
|
|
|
/**
|
2015-04-28 21:46:17 +03: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-30 00:14:19 +04:00
|
|
|
*/
|
2015-04-28 21:46:17 +03:00
|
|
|
virtual void CollectSizeOfSurfaces(nsTArray<SurfaceMemoryCounter>& aCounters,
|
|
|
|
MallocSizeOf aMallocSizeOf) const = 0;
|
2014-05-08 13:53:00 +04:00
|
|
|
|
2012-12-20 02:24:32 +04:00
|
|
|
virtual void IncrementAnimationConsumers() = 0;
|
|
|
|
virtual void DecrementAnimationConsumers() = 0;
|
2010-09-08 04:33:02 +04:00
|
|
|
#ifdef DEBUG
|
2012-12-20 02:24:32 +04:00
|
|
|
virtual uint32_t GetAnimationConsumers() = 0;
|
2010-09-08 04:33:02 +04:00
|
|
|
#endif
|
|
|
|
|
2012-12-18 02:05:18 +04: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,
|
|
|
|
nsIInputStream* aInStr,
|
|
|
|
uint64_t aSourceOffset,
|
|
|
|
uint32_t aCount) = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Called from OnStopRequest when the image's underlying request completes.
|
2013-02-14 06:41:10 +04:00
|
|
|
*
|
|
|
|
* @param aRequest The completed request.
|
|
|
|
* @param aStatus A success or failure code.
|
|
|
|
* @param aLastPart Whether this is the final part of the underlying request.
|
2012-12-18 02:05:18 +04:00
|
|
|
*/
|
2021-11-24 14:25:41 +03:00
|
|
|
virtual nsresult OnImageDataComplete(nsIRequest* aRequest, nsresult aStatus,
|
2013-02-14 06:41:10 +04:00
|
|
|
bool aLastPart) = 0;
|
2012-12-18 02:05:18 +04:00
|
|
|
|
2014-11-28 06:55:57 +03:00
|
|
|
/**
|
2015-09-20 02:20:59 +03:00
|
|
|
* Called when the SurfaceCache discards a surface belonging to this image.
|
2014-11-28 06:55:57 +03:00
|
|
|
*/
|
2017-03-16 11:06:06 +03:00
|
|
|
virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) = 0;
|
2014-11-28 06:55:57 +03:00
|
|
|
|
2012-12-20 02:24:32 +04: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 03:42:56 +03:00
|
|
|
virtual nsIURI* GetURI() const = 0;
|
2020-04-01 00:16:39 +03: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-20 02:24:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class ImageResource : public Image {
|
|
|
|
public:
|
2015-03-21 19:28:04 +03:00
|
|
|
already_AddRefed<ProgressTracker> GetProgressTracker() override {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<ProgressTracker> progressTracker = mProgressTracker;
|
2014-11-15 07:10:47 +03:00
|
|
|
MOZ_ASSERT(progressTracker);
|
|
|
|
return progressTracker.forget();
|
2013-09-28 22:28:44 +04:00
|
|
|
}
|
2014-12-04 22:23:00 +03:00
|
|
|
|
2018-02-09 08:22:43 +03:00
|
|
|
void SetProgressTracker(ProgressTracker* aProgressTracker) final {
|
2014-11-15 07:10:47 +03:00
|
|
|
MOZ_ASSERT(aProgressTracker);
|
|
|
|
MOZ_ASSERT(!mProgressTracker);
|
|
|
|
mProgressTracker = aProgressTracker;
|
2013-09-28 22:28:44 +04:00
|
|
|
}
|
2012-12-20 02:24:32 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void IncrementAnimationConsumers() override;
|
|
|
|
virtual void DecrementAnimationConsumers() override;
|
2012-12-20 02:24:32 +04:00
|
|
|
#ifdef DEBUG
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual uint32_t GetAnimationConsumers() override {
|
2014-12-04 22:23:00 +03:00
|
|
|
return mAnimationConsumers;
|
|
|
|
}
|
2012-12-20 02:24:32 +04:00
|
|
|
#endif
|
|
|
|
|
2017-03-16 11:06:06 +03:00
|
|
|
virtual void OnSurfaceDiscarded(const SurfaceKey& aSurfaceKey) override {}
|
2014-11-28 06:55:57 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual void SetInnerWindowID(uint64_t aInnerWindowId) override {
|
2011-08-25 00:44:35 +04:00
|
|
|
mInnerWindowId = aInnerWindowId;
|
2010-12-20 19:21:59 +03:00
|
|
|
}
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual uint64_t InnerWindowID() const override { return mInnerWindowId; }
|
2010-12-20 19:21:59 +03:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual bool HasError() override { return mError; }
|
|
|
|
virtual void SetHasError() override { mError = true; }
|
2012-12-15 03:42:18 +04:00
|
|
|
|
2012-12-20 01:28:54 +04:00
|
|
|
/*
|
|
|
|
* Returns a non-AddRefed pointer to the URI associated with this image.
|
2013-09-12 04:01:59 +04:00
|
|
|
* Illegal to use off-main-thread.
|
2012-12-20 01:28:54 +04:00
|
|
|
*/
|
2018-06-06 03:42:56 +03:00
|
|
|
nsIURI* GetURI() const override { return mURI; }
|
2012-12-20 01:28:54 +04:00
|
|
|
|
2021-05-20 15:31:27 +03:00
|
|
|
/*
|
|
|
|
* 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;
|
|
|
|
|
2021-11-27 14:47:36 +03:00
|
|
|
ImageProviderId GetImageProviderId() const { return mProviderId; }
|
|
|
|
|
2010-08-14 08:09:48 +04:00
|
|
|
protected:
|
2018-06-06 03:42:56 +03:00
|
|
|
explicit ImageResource(nsIURI* aURI);
|
2015-04-29 02:32:02 +03:00
|
|
|
~ImageResource();
|
2010-08-14 08:09:48 +04:00
|
|
|
|
2018-06-06 03:42:56 +03:00
|
|
|
bool GetSpecTruncatedTo1k(nsCString& aSpec) const;
|
|
|
|
|
2012-10-20 00:27:11 +04:00
|
|
|
// Shared functionality for implementors of imgIContainer. Every
|
|
|
|
// implementation of attribute animationMode should forward here.
|
2014-12-04 22:23:00 +03:00
|
|
|
nsresult GetAnimationModeInternal(uint16_t* aAnimationMode);
|
2012-10-20 00:27:11 +04:00
|
|
|
nsresult SetAnimationModeInternal(uint16_t aAnimationMode);
|
|
|
|
|
2014-05-08 22:37:39 +04: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 19:00:31 +04:00
|
|
|
bool HadRecentRefresh(const TimeStamp& aTime);
|
2014-05-08 22:37:39 +04:00
|
|
|
|
2010-09-08 04:33:02 +04:00
|
|
|
/**
|
|
|
|
* Decides whether animation should or should not be happening,
|
|
|
|
* and makes sure the right thing is being done.
|
|
|
|
*/
|
|
|
|
virtual void EvaluateAnimation();
|
|
|
|
|
2012-12-20 02:24:32 +04: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 04:33:02 +04:00
|
|
|
virtual nsresult StartAnimation() = 0;
|
|
|
|
virtual nsresult StopAnimation() = 0;
|
|
|
|
|
2016-11-17 09:25:53 +03:00
|
|
|
void SendOnUnlockedDraw(uint32_t aFlags);
|
|
|
|
|
2017-11-17 14:45:23 +03:00
|
|
|
#ifdef DEBUG
|
|
|
|
// Records the image drawing for startup performance testing.
|
|
|
|
void NotifyDrawingObservers();
|
|
|
|
#endif
|
|
|
|
|
2010-08-14 08:09:48 +04:00
|
|
|
// Member data shared by all implementations of this abstract class
|
2018-06-06 03:42:56 +03:00
|
|
|
RefPtr<ProgressTracker> mProgressTracker;
|
|
|
|
nsCOMPtr<nsIURI> mURI;
|
2014-05-08 22:37:39 +04:00
|
|
|
TimeStamp mLastRefreshTime;
|
2013-09-12 04:01:59 +04:00
|
|
|
uint64_t mInnerWindowId;
|
|
|
|
uint32_t mAnimationConsumers;
|
|
|
|
uint16_t mAnimationMode; // Enum values in imgIContainer
|
2019-09-12 12:00:52 +03:00
|
|
|
bool mInitialized : 1; // Have we been initialized?
|
2013-09-12 04:01:59 +04:00
|
|
|
bool mAnimating : 1; // Are we currently animating?
|
|
|
|
bool mError : 1; // Error handling
|
2017-11-17 14:45:23 +03:00
|
|
|
|
2021-04-14 12:00:13 +03:00
|
|
|
class MOZ_RAII AutoProfilerImagePaintMarker {
|
|
|
|
public:
|
|
|
|
explicit AutoProfilerImagePaintMarker(ImageResource* self)
|
2021-07-14 21:18:17 +03:00
|
|
|
: mStartTime(TimeStamp::Now()) {
|
2021-04-14 12:00:13 +03:00
|
|
|
nsAutoCString spec;
|
2021-11-09 02:59:35 +03:00
|
|
|
if (self->mURI && profiler_thread_is_being_profiled_for_markers()) {
|
2021-04-14 12:00:13 +03:00
|
|
|
static const size_t sMaxTruncatedLength = 1024;
|
|
|
|
self->mURI->GetSpec(mSpec);
|
|
|
|
if (mSpec.Length() >= sMaxTruncatedLength) {
|
|
|
|
mSpec.Truncate(sMaxTruncatedLength);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
~AutoProfilerImagePaintMarker() {
|
|
|
|
if (!mSpec.IsEmpty()) {
|
|
|
|
PROFILER_MARKER_TEXT("Image Paint", GRAPHICS,
|
|
|
|
MarkerTiming::IntervalUntilNowFrom(mStartTime),
|
|
|
|
mSpec);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
TimeStamp mStartTime;
|
|
|
|
nsAutoCString mSpec;
|
|
|
|
};
|
|
|
|
|
2017-11-17 14:45:24 +03:00
|
|
|
private:
|
2021-11-27 14:47:36 +03:00
|
|
|
ImageProviderId mProviderId;
|
2010-08-14 08:09:48 +04:00
|
|
|
};
|
|
|
|
|
2012-01-06 20:02:27 +04:00
|
|
|
} // namespace image
|
2010-08-14 08:09:48 +04:00
|
|
|
} // namespace mozilla
|
|
|
|
|
2015-05-15 06:52:05 +03:00
|
|
|
#endif // mozilla_image_Image_h
|