Bug 688238. imglib: Move Decoder::Init() arguments into the constructor. r=joedrew

This makes the lifetime of the arguments more clear. i.e. that they stay the same
for the lifetime of the decoder.

--HG--
extra : rebase_source : 99726522b99d9d546f41d1d4e78e44224101e9b3
This commit is contained in:
Jeff Muizelaar 2011-09-27 12:24:03 -04:00
Родитель b234bc0b54
Коммит cde526e2b7
15 изменённых файлов: 67 добавлений и 69 удалений

Просмотреть файл

@ -63,17 +63,18 @@ PRLogModuleInfo *gBMPLog = PR_NewLogModule("BMPDecoder");
#define LINE(row) ((mBIH.height < 0) ? (-mBIH.height - (row)) : ((row) - 1)) #define LINE(row) ((mBIH.height < 0) ? (-mBIH.height - (row)) : ((row) - 1))
#define PIXEL_OFFSET(row, col) (LINE(row) * mBIH.width + col) #define PIXEL_OFFSET(row, col) (LINE(row) * mBIH.width + col)
nsBMPDecoder::nsBMPDecoder() nsBMPDecoder::nsBMPDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
: Decoder(aImage, aObserver)
{ {
mColors = nsnull; mColors = nsnull;
mRow = nsnull; mRow = nsnull;
mImageData = nsnull; mImageData = nsnull;
mCurPos = mPos = mNumColors = mRowBytes = 0; mCurPos = mPos = mNumColors = mRowBytes = 0;
mOldLine = mCurLine = 1; // Otherwise decoder will never start mOldLine = mCurLine = 1; // Otherwise decoder will never start
mState = eRLEStateInitial; mState = eRLEStateInitial;
mStateData = 0; mStateData = 0;
mLOH = WIN_HEADER_LENGTH; mLOH = WIN_HEADER_LENGTH;
mUseAlphaData = mHaveAlphaData = PR_FALSE; mUseAlphaData = mHaveAlphaData = PR_FALSE;
} }
nsBMPDecoder::~nsBMPDecoder() nsBMPDecoder::~nsBMPDecoder()

Просмотреть файл

@ -59,7 +59,7 @@ class nsBMPDecoder : public Decoder
{ {
public: public:
nsBMPDecoder(); nsBMPDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver);
~nsBMPDecoder(); ~nsBMPDecoder();
// Specifies whether or not the BMP file will contain alpha data // Specifies whether or not the BMP file will contain alpha data

Просмотреть файл

@ -107,8 +107,9 @@ namespace imagelib {
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
// GIF Decoder Implementation // GIF Decoder Implementation
nsGIFDecoder2::nsGIFDecoder2() nsGIFDecoder2::nsGIFDecoder2(RasterImage *aImage, imgIDecoderObserver* aObserver)
: mCurrentRow(-1) : Decoder(aImage, aObserver)
, mCurrentRow(-1)
, mLastFlushedRow(-1) , mLastFlushedRow(-1)
, mImageData(nsnull) , mImageData(nsnull)
, mOldColor(0) , mOldColor(0)

Просмотреть файл

@ -58,7 +58,7 @@ class nsGIFDecoder2 : public Decoder
{ {
public: public:
nsGIFDecoder2(); nsGIFDecoder2(RasterImage *aImage, imgIDecoderObserver* aObserver);
~nsGIFDecoder2(); ~nsGIFDecoder2();
virtual void WriteInternal(const char* aBuffer, PRUint32 aCount); virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);

Просмотреть файл

@ -99,7 +99,8 @@ nsICODecoder::GetNumColors()
} }
nsICODecoder::nsICODecoder() nsICODecoder::nsICODecoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
: Decoder(aImage, aObserver)
{ {
mPos = mImageOffset = mCurrIcon = mNumIcons = mBPP = mRowBytes = 0; mPos = mImageOffset = mCurrIcon = mNumIcons = mBPP = mRowBytes = 0;
mIsPNG = PR_FALSE; mIsPNG = PR_FALSE;
@ -317,8 +318,8 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
mIsPNG = !memcmp(mSignature, nsPNGDecoder::pngSignatureBytes, mIsPNG = !memcmp(mSignature, nsPNGDecoder::pngSignatureBytes,
PNGSIGNATURESIZE); PNGSIGNATURESIZE);
if (mIsPNG) { if (mIsPNG) {
mContainedDecoder = new nsPNGDecoder(); mContainedDecoder = new nsPNGDecoder(mImage, mObserver);
mContainedDecoder->InitSharedDecoder(mImage, mObserver); mContainedDecoder->InitSharedDecoder();
mContainedDecoder->Write(mSignature, PNGSIGNATURESIZE); mContainedDecoder->Write(mSignature, PNGSIGNATURESIZE);
mDataError = mContainedDecoder->HasDataError(); mDataError = mContainedDecoder->HasDataError();
if (mContainedDecoder->HasDataError()) { if (mContainedDecoder->HasDataError()) {
@ -386,11 +387,11 @@ nsICODecoder::WriteInternal(const char* aBuffer, PRUint32 aCount)
// Init the bitmap decoder which will do most of the work for us // Init the bitmap decoder which will do most of the work for us
// It will do everything except the AND mask which isn't present in bitmaps // It will do everything except the AND mask which isn't present in bitmaps
// bmpDecoder is for local scope ease, it will be freed by mContainedDecoder // bmpDecoder is for local scope ease, it will be freed by mContainedDecoder
nsBMPDecoder *bmpDecoder = new nsBMPDecoder(); nsBMPDecoder *bmpDecoder = new nsBMPDecoder(mImage, mObserver);
mContainedDecoder = bmpDecoder; mContainedDecoder = bmpDecoder;
bmpDecoder->SetUseAlphaData(PR_TRUE); bmpDecoder->SetUseAlphaData(PR_TRUE);
mContainedDecoder->SetSizeDecode(IsSizeDecode()); mContainedDecoder->SetSizeDecode(IsSizeDecode());
mContainedDecoder->InitSharedDecoder(mImage, mObserver); mContainedDecoder->InitSharedDecoder();
// The ICO format when containing a BMP does not include the 14 byte // The ICO format when containing a BMP does not include the 14 byte
// bitmap file header. To use the code of the BMP decoder we need to // bitmap file header. To use the code of the BMP decoder we need to

Просмотреть файл

@ -58,7 +58,7 @@ class nsICODecoder : public Decoder
{ {
public: public:
nsICODecoder(); nsICODecoder(RasterImage *aImage, imgIDecoderObserver* aObserver);
virtual ~nsICODecoder(); virtual ~nsICODecoder();
// Obtains the width of the icon directory entry // Obtains the width of the icon directory entry

Просмотреть файл

@ -50,13 +50,14 @@
namespace mozilla { namespace mozilla {
namespace imagelib { namespace imagelib {
nsIconDecoder::nsIconDecoder() : nsIconDecoder::nsIconDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
mWidth(-1), : Decoder(aImage, aObserver),
mHeight(-1), mWidth(-1),
mPixBytesRead(0), mHeight(-1),
mPixBytesTotal(0), mPixBytesRead(0),
mImageData(nsnull), mPixBytesTotal(0),
mState(iconStateStart) mImageData(nsnull),
mState(iconStateStart)
{ {
// Nothing to do // Nothing to do
} }

Просмотреть файл

@ -74,7 +74,7 @@ class nsIconDecoder : public Decoder
{ {
public: public:
nsIconDecoder(); nsIconDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver);
virtual ~nsIconDecoder(); virtual ~nsIconDecoder();
virtual void WriteInternal(const char* aBuffer, PRUint32 aCount); virtual void WriteInternal(const char* aBuffer, PRUint32 aCount);

Просмотреть файл

@ -109,7 +109,8 @@ METHODDEF(void) my_error_exit (j_common_ptr cinfo);
#define MAX_JPEG_MARKER_LENGTH (((PRUint32)1 << 16) - 1) #define MAX_JPEG_MARKER_LENGTH (((PRUint32)1 << 16) - 1)
nsJPEGDecoder::nsJPEGDecoder() nsJPEGDecoder::nsJPEGDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
: Decoder(aImage, aObserver)
{ {
mState = JPEG_HEADER; mState = JPEG_HEADER;
mReading = PR_TRUE; mReading = PR_TRUE;

Просмотреть файл

@ -86,7 +86,7 @@ class RasterImage;
class nsJPEGDecoder : public Decoder class nsJPEGDecoder : public Decoder
{ {
public: public:
nsJPEGDecoder(); nsJPEGDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver);
virtual ~nsJPEGDecoder(); virtual ~nsJPEGDecoder();
virtual void InitInternal(); virtual void InitInternal();

Просмотреть файл

@ -81,13 +81,14 @@ static PRLogModuleInfo *gPNGDecoderAccountingLog =
const PRUint8 const PRUint8
nsPNGDecoder::pngSignatureBytes[] = { 137, 80, 78, 71, 13, 10, 26, 10 }; nsPNGDecoder::pngSignatureBytes[] = { 137, 80, 78, 71, 13, 10, 26, 10 };
nsPNGDecoder::nsPNGDecoder() : nsPNGDecoder::nsPNGDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
mPNG(nsnull), mInfo(nsnull), : Decoder(aImage, aObserver),
mCMSLine(nsnull), interlacebuf(nsnull), mPNG(nsnull), mInfo(nsnull),
mInProfile(nsnull), mTransform(nsnull), mCMSLine(nsnull), interlacebuf(nsnull),
mHeaderBuf(nsnull), mHeaderBytesRead(0), mInProfile(nsnull), mTransform(nsnull),
mChannels(0), mFrameIsHidden(PR_FALSE), mHeaderBuf(nsnull), mHeaderBytesRead(0),
mCMSMode(0), mDisablePremultipliedAlpha(PR_FALSE) mChannels(0), mFrameIsHidden(PR_FALSE),
mCMSMode(0), mDisablePremultipliedAlpha(PR_FALSE)
{ {
} }

Просмотреть файл

@ -59,7 +59,7 @@ class RasterImage;
class nsPNGDecoder : public Decoder class nsPNGDecoder : public Decoder
{ {
public: public:
nsPNGDecoder(); nsPNGDecoder(RasterImage *aImage, imgIDecoderObserver* aObserver);
virtual ~nsPNGDecoder(); virtual ~nsPNGDecoder();
virtual void InitInternal(); virtual void InitInternal();

Просмотреть файл

@ -44,7 +44,7 @@
namespace mozilla { namespace mozilla {
namespace imagelib { namespace imagelib {
Decoder::Decoder() Decoder::Decoder(RasterImage *aImage, imgIDecoderObserver* aObserver)
: mDecodeFlags(0) : mDecodeFlags(0)
, mFrameCount(0) , mFrameCount(0)
, mFailCode(NS_OK) , mFailCode(NS_OK)
@ -54,6 +54,12 @@ Decoder::Decoder()
, mDecodeDone(false) , mDecodeDone(false)
, mDataError(false) , mDataError(false)
{ {
// We should always have an image
NS_ABORT_IF_FALSE(aImage, "Can't initialize decoder without an image!");
// Save our paremeters
mImage = aImage;
mObserver = aObserver;
} }
Decoder::~Decoder() Decoder::~Decoder()
@ -67,17 +73,10 @@ Decoder::~Decoder()
*/ */
void void
Decoder::Init(RasterImage* aImage, imgIDecoderObserver* aObserver) Decoder::Init()
{ {
// We should always have an image
NS_ABORT_IF_FALSE(aImage, "Can't initialize decoder without an image!");
// No re-initializing // No re-initializing
NS_ABORT_IF_FALSE(mImage == nsnull, "Can't re-initialize a decoder!"); NS_ABORT_IF_FALSE(!mInitialized, "Can't re-initialize a decoder!");
// Save our paremeters
mImage = aImage;
mObserver = aObserver;
// Fire OnStartDecode at init time to support bug 512435 // Fire OnStartDecode at init time to support bug 512435
if (!IsSizeDecode() && mObserver) if (!IsSizeDecode() && mObserver)
@ -90,18 +89,11 @@ Decoder::Init(RasterImage* aImage, imgIDecoderObserver* aObserver)
// Initializes a decoder whose aImage and aObserver is already being used by a // Initializes a decoder whose aImage and aObserver is already being used by a
// parent decoder // parent decoder
void void
Decoder::InitSharedDecoder(RasterImage* aImage, imgIDecoderObserver* aObserver) Decoder::InitSharedDecoder()
{ {
// We should always have an image
NS_ABORT_IF_FALSE(aImage, "Can't initialize decoder without an image!");
// No re-initializing // No re-initializing
NS_ABORT_IF_FALSE(mImage == nsnull, "Can't re-initialize a decoder!"); NS_ABORT_IF_FALSE(!mInitialized, "Can't re-initialize a decoder!");
// Save our parameters
mImage = aImage;
mObserver = aObserver;
// Implementation-specific initialization // Implementation-specific initialization
InitInternal(); InitInternal();

Просмотреть файл

@ -50,7 +50,7 @@ class Decoder
{ {
public: public:
Decoder(); Decoder(RasterImage* aImage, imgIDecoderObserver* aObserver);
virtual ~Decoder(); virtual ~Decoder();
/** /**
@ -61,7 +61,7 @@ public:
* *
* Notifications Sent: TODO * Notifications Sent: TODO
*/ */
void Init(RasterImage* aImage, imgIDecoderObserver* aObserver); void Init();
/** /**
@ -73,7 +73,7 @@ public:
* *
* Notifications Sent: TODO * Notifications Sent: TODO
*/ */
void InitSharedDecoder(RasterImage* aImage, imgIDecoderObserver* aObserver); void InitSharedDecoder();
/** /**
* Writes data to the decoder. * Writes data to the decoder.

Просмотреть файл

@ -2167,35 +2167,35 @@ RasterImage::InitDecoder(bool aDoSizeDecode)
eDecoderType type = GetDecoderType(mSourceDataMimeType.get()); eDecoderType type = GetDecoderType(mSourceDataMimeType.get());
CONTAINER_ENSURE_TRUE(type != eDecoderType_unknown, NS_IMAGELIB_ERROR_NO_DECODER); CONTAINER_ENSURE_TRUE(type != eDecoderType_unknown, NS_IMAGELIB_ERROR_NO_DECODER);
nsCOMPtr<imgIDecoderObserver> observer(do_QueryReferent(mObserver));
// Instantiate the appropriate decoder // Instantiate the appropriate decoder
switch (type) { switch (type) {
case eDecoderType_png: case eDecoderType_png:
mDecoder = new nsPNGDecoder(); mDecoder = new nsPNGDecoder(this, observer);
break; break;
case eDecoderType_gif: case eDecoderType_gif:
mDecoder = new nsGIFDecoder2(); mDecoder = new nsGIFDecoder2(this, observer);
break; break;
case eDecoderType_jpeg: case eDecoderType_jpeg:
mDecoder = new nsJPEGDecoder(); mDecoder = new nsJPEGDecoder(this, observer);
break; break;
case eDecoderType_bmp: case eDecoderType_bmp:
mDecoder = new nsBMPDecoder(); mDecoder = new nsBMPDecoder(this, observer);
break; break;
case eDecoderType_ico: case eDecoderType_ico:
mDecoder = new nsICODecoder(); mDecoder = new nsICODecoder(this, observer);
break; break;
case eDecoderType_icon: case eDecoderType_icon:
mDecoder = new nsIconDecoder(); mDecoder = new nsIconDecoder(this, observer);
break; break;
default: default:
NS_ABORT_IF_FALSE(0, "Shouldn't get here!"); NS_ABORT_IF_FALSE(0, "Shouldn't get here!");
} }
// Initialize the decoder // Initialize the decoder
nsCOMPtr<imgIDecoderObserver> observer(do_QueryReferent(mObserver));
mDecoder->SetSizeDecode(aDoSizeDecode); mDecoder->SetSizeDecode(aDoSizeDecode);
mDecoder->SetDecodeFlags(mFrameDecodeFlags); mDecoder->SetDecodeFlags(mFrameDecodeFlags);
mDecoder->Init(this, observer); mDecoder->Init();
CONTAINER_ENSURE_SUCCESS(mDecoder->GetDecoderError()); CONTAINER_ENSURE_SUCCESS(mDecoder->GetDecoderError());
// Create a decode worker // Create a decode worker