Bug 822526 - Turn mozilla::image::Image into an interface. r=joe

This commit is contained in:
Seth Fowler 2012-12-19 14:24:32 -08:00
parent 25f403a350
commit 97ce4e1130
6 changed files with 67 additions and 47 deletions

View File

@ -9,9 +9,9 @@ namespace mozilla {
namespace image {
// Constructor
Image::Image(imgStatusTracker* aStatusTracker, nsIURI* aURI) :
mInnerWindowId(0),
ImageResource::ImageResource(imgStatusTracker* aStatusTracker, nsIURI* aURI) :
mURI(aURI),
mInnerWindowId(0),
mAnimationConsumers(0),
mAnimationMode(kNormalAnimMode),
mInitialized(false),
@ -27,7 +27,7 @@ Image::Image(imgStatusTracker* aStatusTracker, nsIURI* aURI) :
}
uint32_t
Image::SizeOfData()
ImageResource::SizeOfData()
{
if (mError)
return 0;
@ -88,14 +88,14 @@ Image::GetDecoderType(const char *aMimeType)
}
void
Image::IncrementAnimationConsumers()
ImageResource::IncrementAnimationConsumers()
{
mAnimationConsumers++;
EvaluateAnimation();
}
void
Image::DecrementAnimationConsumers()
ImageResource::DecrementAnimationConsumers()
{
NS_ABORT_IF_FALSE(mAnimationConsumers >= 1, "Invalid no. of animation consumers!");
mAnimationConsumers--;
@ -103,7 +103,7 @@ Image::DecrementAnimationConsumers()
}
nsresult
Image::GetAnimationModeInternal(uint16_t* aAnimationMode)
ImageResource::GetAnimationModeInternal(uint16_t* aAnimationMode)
{
if (mError)
return NS_ERROR_FAILURE;
@ -115,7 +115,7 @@ Image::GetAnimationModeInternal(uint16_t* aAnimationMode)
}
nsresult
Image::SetAnimationModeInternal(uint16_t aAnimationMode)
ImageResource::SetAnimationModeInternal(uint16_t aAnimationMode)
{
if (mError)
return NS_ERROR_FAILURE;
@ -133,7 +133,7 @@ Image::SetAnimationModeInternal(uint16_t aAnimationMode)
}
void
Image::EvaluateAnimation()
ImageResource::EvaluateAnimation()
{
if (!mAnimating && ShouldAnimate()) {
nsresult rv = StartAnimation();

View File

@ -18,7 +18,17 @@ namespace image {
class Image : public imgIContainer
{
public:
imgStatusTracker& GetStatusTracker() { return *mStatusTracker; }
// Mimetype translation
enum eDecoderType {
eDecoderType_png = 0,
eDecoderType_gif = 1,
eDecoderType_jpeg = 2,
eDecoderType_bmp = 3,
eDecoderType_ico = 4,
eDecoderType_icon = 5,
eDecoderType_unknown = 6
};
static eDecoderType GetDecoderType(const char *aMimeType);
/**
* Flags for Image initialization.
@ -52,6 +62,8 @@ public:
const char* aMimeType,
uint32_t aFlags) = 0;
virtual imgStatusTracker& GetStatusTracker() = 0;
/**
* The rectangle defining the location and size of the currently displayed
* frame.
@ -62,7 +74,7 @@ public:
* The size, in bytes, occupied by the significant data portions of the image.
* This includes both compressed source data and decoded frames.
*/
uint32_t SizeOfData();
virtual uint32_t SizeOfData() = 0;
/**
* The components that make up SizeOfData().
@ -72,22 +84,10 @@ public:
virtual size_t NonHeapSizeOfDecoded() const = 0;
virtual size_t OutOfProcessSizeOfDecoded() const = 0;
// Mimetype translation
enum eDecoderType {
eDecoderType_png = 0,
eDecoderType_gif = 1,
eDecoderType_jpeg = 2,
eDecoderType_bmp = 3,
eDecoderType_ico = 4,
eDecoderType_icon = 5,
eDecoderType_unknown = 6
};
static eDecoderType GetDecoderType(const char *aMimeType);
void IncrementAnimationConsumers();
void DecrementAnimationConsumers();
virtual void IncrementAnimationConsumers() = 0;
virtual void DecrementAnimationConsumers() = 0;
#ifdef DEBUG
uint32_t GetAnimationConsumers() { return mAnimationConsumers; }
virtual uint32_t GetAnimationConsumers() = 0;
#endif
/**
@ -123,21 +123,42 @@ public:
*/
virtual nsresult OnNewSourceData() = 0;
void SetInnerWindowID(uint64_t aInnerWindowId) {
virtual void SetInnerWindowID(uint64_t aInnerWindowId) = 0;
virtual uint64_t InnerWindowID() const = 0;
virtual bool HasError() = 0;
virtual void SetHasError() = 0;
virtual nsIURI* GetURI() = 0;
};
class ImageResource : public Image
{
public:
virtual imgStatusTracker& GetStatusTracker() MOZ_OVERRIDE { return *mStatusTracker; }
virtual uint32_t SizeOfData() MOZ_OVERRIDE;
virtual void IncrementAnimationConsumers() MOZ_OVERRIDE;
virtual void DecrementAnimationConsumers() MOZ_OVERRIDE;
#ifdef DEBUG
virtual uint32_t GetAnimationConsumers() MOZ_OVERRIDE { return mAnimationConsumers; }
#endif
virtual void SetInnerWindowID(uint64_t aInnerWindowId) MOZ_OVERRIDE {
mInnerWindowId = aInnerWindowId;
}
uint64_t InnerWindowID() const { return mInnerWindowId; }
virtual uint64_t InnerWindowID() const MOZ_OVERRIDE { return mInnerWindowId; }
bool HasError() { return mError; }
void SetHasError() { mError = true; }
virtual bool HasError() MOZ_OVERRIDE { return mError; }
virtual void SetHasError() MOZ_OVERRIDE { mError = true; }
/*
* Returns a non-AddRefed pointer to the URI associated with this image.
*/
nsIURI* GetURI() { return mURI; }
virtual nsIURI* GetURI() MOZ_OVERRIDE { return mURI; }
protected:
Image(imgStatusTracker* aStatusTracker, nsIURI* aURI);
ImageResource(imgStatusTracker* aStatusTracker, nsIURI* aURI);
// Shared functionality for implementors of imgIContainer. Every
// implementation of attribute animationMode should forward here.
@ -150,27 +171,26 @@ protected:
*/
virtual void EvaluateAnimation();
/**
* Extended by child classes, if they have additional
* conditions for being able to animate.
*/
virtual bool ShouldAnimate() {
return mAnimationConsumers > 0 && mAnimationMode != kDontAnimMode;
}
virtual nsresult StartAnimation() = 0;
virtual nsresult StopAnimation() = 0;
uint64_t mInnerWindowId;
// Member data shared by all implementations of this abstract class
nsRefPtr<imgStatusTracker> mStatusTracker;
nsCOMPtr<nsIURI> mURI;
uint64_t mInnerWindowId;
uint32_t mAnimationConsumers;
uint16_t mAnimationMode; // Enum values in imgIContainer
bool mInitialized:1; // Have we been initalized?
bool mAnimating:1; // Are we currently animating?
bool mError:1; // Error handling
/**
* Extended by child classes, if they have additional
* conditions for being able to animate
*/
virtual bool ShouldAnimate() {
return mAnimationConsumers > 0 && mAnimationMode != kDontAnimMode;
}
};
} // namespace image

View File

@ -353,7 +353,7 @@ NS_IMPL_ISUPPORTS3(RasterImage, imgIContainer, nsIProperties,
//******************************************************************************
RasterImage::RasterImage(imgStatusTracker* aStatusTracker,
nsIURI* aURI /* = nullptr */) :
Image(aStatusTracker, aURI), // invoke superclass's constructor
ImageResource(aStatusTracker, aURI), // invoke superclass's constructor
mSize(0,0),
mFrameDecodeFlags(DECODE_FLAGS_DEFAULT),
mAnim(nullptr),
@ -3268,7 +3268,7 @@ RasterImage::WriteToRasterImage(nsIInputStream* /* unused */,
bool
RasterImage::ShouldAnimate()
{
return Image::ShouldAnimate() && mFrames.Length() >= 2 &&
return ImageResource::ShouldAnimate() && mFrames.Length() >= 2 &&
!mAnimationFinished;
}

View File

@ -135,7 +135,7 @@ namespace image {
class Decoder;
class RasterImage : public Image
class RasterImage : public ImageResource
, public nsIProperties
, public SupportsWeakPtr<RasterImage>
#ifdef DEBUG

View File

@ -171,7 +171,7 @@ NS_IMPL_ISUPPORTS3(VectorImage,
VectorImage::VectorImage(imgStatusTracker* aStatusTracker,
nsIURI* aURI /* = nullptr */) :
Image(aStatusTracker, aURI), // invoke superclass's constructor
ImageResource(aStatusTracker, aURI), // invoke superclass's constructor
mRestrictedRegion(0, 0, 0, 0),
mIsInitialized(false),
mIsFullyLoaded(false),
@ -297,7 +297,7 @@ VectorImage::StopAnimation()
bool
VectorImage::ShouldAnimate()
{
return Image::ShouldAnimate() && mIsFullyLoaded && mHaveAnimations;
return ImageResource::ShouldAnimate() && mIsFullyLoaded && mHaveAnimations;
}
//------------------------------------------------------------------------------

View File

@ -24,7 +24,7 @@ namespace image {
class SVGDocumentWrapper;
class SVGRootRenderingObserver;
class VectorImage : public Image,
class VectorImage : public ImageResource,
public nsIStreamListener
{
public: