diff --git a/image/decoders/nsJPEGDecoder.cpp b/image/decoders/nsJPEGDecoder.cpp index 17af7049c521..59bcdc6298e4 100644 --- a/image/decoders/nsJPEGDecoder.cpp +++ b/image/decoders/nsJPEGDecoder.cpp @@ -158,7 +158,7 @@ void nsJPEGDecoder::InitInternal() { mCMSMode = gfxPlatform::GetCMSMode(); - if ((mDecodeFlags & DECODER_NO_COLORSPACE_CONVERSION) != 0) { + if (GetDecodeFlags() & imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION) { mCMSMode = eCMSMode_Off; } diff --git a/image/decoders/nsPNGDecoder.cpp b/image/decoders/nsPNGDecoder.cpp index 00b719141cc6..859128531362 100644 --- a/image/decoders/nsPNGDecoder.cpp +++ b/image/decoders/nsPNGDecoder.cpp @@ -226,11 +226,11 @@ nsPNGDecoder::InitInternal() } mCMSMode = gfxPlatform::GetCMSMode(); - if ((mDecodeFlags & DECODER_NO_COLORSPACE_CONVERSION) != 0) { + if (GetDecodeFlags() & imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION) { mCMSMode = eCMSMode_Off; } - mDisablePremultipliedAlpha = (mDecodeFlags & DECODER_NO_PREMULTIPLY_ALPHA) - != 0; + mDisablePremultipliedAlpha = + GetDecodeFlags() & imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA; #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED static png_byte color_chunks[]= diff --git a/image/public/imgIContainer.idl b/image/public/imgIContainer.idl index 9e48792c5618..23f7b7c67714 100644 --- a/image/public/imgIContainer.idl +++ b/image/public/imgIContainer.idl @@ -69,7 +69,7 @@ native nsIntSizeByVal(nsIntSize); * * Internally, imgIContainer also manages animation of images. */ -[scriptable, builtinclass, uuid(4adb4c92-284d-4f5a-85e7-e924ec57510f)] +[scriptable, builtinclass, uuid(25236a61-9568-4b2b-a2ce-209a2db9771d)] interface imgIContainer : nsISupports { /** @@ -146,12 +146,10 @@ interface imgIContainer : nsISupports * * Meanings: * - * FLAG_NONE: Lack of flags + * FLAG_NONE: Lack of flags. * * FLAG_SYNC_DECODE: Forces synchronous/non-progressive decode of all - * available data before the call returns. It is an error to pass this flag - * from a call stack that originates in a decoder (ie, from a decoder - * observer event). + * available data before the call returns. * * FLAG_DECODE_NO_PREMULTIPLY_ALPHA: Do not premultiply alpha if * it's not already premultiplied in the image data. @@ -166,28 +164,31 @@ interface imgIContainer : nsISupports * FLAG_HIGH_QUALITY_SCALING: A hint as to whether this image should be * scaled using the high quality scaler. Do not set this if not drawing to * a window or not listening to invalidations. + * + * FLAG_WANT_DATA_SURFACE: Can be passed to GetFrame when the caller wants a + * DataSourceSurface instead of a hardware accelerated surface. This can be + * important for performance (by avoiding an upload to/readback from the GPU) + * when the caller knows they want a SourceSurface of type DATA. + * + * FLAG_BYPASS_SURFACE_CACHE: Forces drawing to happen rather than taking + * cached rendering from the surface cache. This is used when we are printing, + * for example, where we want the vector commands from VectorImages to end up + * in the PDF output rather than a cached rendering at screen resolution. */ + const unsigned long FLAG_NONE = 0x0; + const unsigned long FLAG_SYNC_DECODE = 0x1; + const unsigned long FLAG_DECODE_NO_PREMULTIPLY_ALPHA = 0x2; + const unsigned long FLAG_DECODE_NO_COLORSPACE_CONVERSION = 0x4; + const unsigned long FLAG_CLAMP = 0x8; + const unsigned long FLAG_HIGH_QUALITY_SCALING = 0x10; + const unsigned long FLAG_WANT_DATA_SURFACE = 0x20; + const unsigned long FLAG_BYPASS_SURFACE_CACHE = 0x40; - const long FLAG_NONE = 0x0; - const long FLAG_SYNC_DECODE = 0x1; - const long FLAG_DECODE_NO_PREMULTIPLY_ALPHA = 0x2; - const long FLAG_DECODE_NO_COLORSPACE_CONVERSION = 0x4; - const long FLAG_CLAMP = 0x8; - const long FLAG_HIGH_QUALITY_SCALING = 0x10; /** - * Can be passed to GetFrame when the caller wants a DataSourceSurface - * instead of a hardware accelerated surface. This can be important for - * performance (by avoiding an upload to/readback from the GPU) when the - * caller knows they want a SourceSurface of type DATA. + * A constant specifying the default set of decode flags (i.e., the default + * values for FLAG_DECODE_*). */ - const long FLAG_WANT_DATA_SURFACE = 0x20; - /** - * Forces drawing to happen rather than taking cached rendering from the - * surface cache. This is used when we are printing, for example, where we - * want the vector commands from VectorImages to end up in the PDF output - * rather than a cached rendering at screen resolution. - */ - const long FLAG_BYPASS_SURFACE_CACHE = 0x40; + const unsigned long DECODE_FLAGS_DEFAULT = 0; /** * Constants for specifying various "special" frames. diff --git a/image/src/Decoder.cpp b/image/src/Decoder.cpp index 2f97a55954b6..e8ed18c6911d 100644 --- a/image/src/Decoder.cpp +++ b/image/src/Decoder.cpp @@ -28,7 +28,7 @@ Decoder::Decoder(RasterImage* aImage) , mImageData(nullptr) , mColormap(nullptr) , mChunkCount(0) - , mDecodeFlags(0) + , mFlags(0) , mBytesDecoded(0) , mSendPartialInvalidations(false) , mDataDone(false) @@ -353,7 +353,7 @@ Decoder::AllocateFrame(const nsIntSize& aTargetSize /* = nsIntSize() */) mCurrentFrame = EnsureFrame(mNewFrameData.mFrameNum, targetSize, mNewFrameData.mFrameRect, - mDecodeFlags, + GetDecodeFlags(), mNewFrameData.mFormat, mNewFrameData.mPaletteDepth, mCurrentFrame.get()); diff --git a/image/src/Decoder.h b/image/src/Decoder.h index a5d4d126af37..f5b235a57100 100644 --- a/image/src/Decoder.h +++ b/image/src/Decoder.h @@ -240,21 +240,14 @@ public: */ bool WasAborted() const { return mDecodeAborted; } - // flags. Keep these in sync with imgIContainer.idl. - // SetDecodeFlags must be called before Init(), otherwise - // default flags are assumed. - enum { - DECODER_NO_PREMULTIPLY_ALPHA = 0x2, // imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA - DECODER_NO_COLORSPACE_CONVERSION = 0x4 // imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION - }; - enum DecodeStyle { PROGRESSIVE, // produce intermediate frames representing the partial state of the image SEQUENTIAL // decode to final image immediately }; - void SetDecodeFlags(uint32_t aFlags) { mDecodeFlags = aFlags; } - uint32_t GetDecodeFlags() { return mDecodeFlags; } + void SetFlags(uint32_t aFlags) { mFlags = aFlags; } + uint32_t GetFlags() const { return mFlags; } + uint32_t GetDecodeFlags() const { return DecodeFlags(mFlags); } bool HasSize() const { return mImageMetadata.HasSize(); } void SetSizeOnImage(); @@ -457,7 +450,7 @@ protected: TimeDuration mDecodeTime; uint32_t mChunkCount; - uint32_t mDecodeFlags; + uint32_t mFlags; size_t mBytesDecoded; bool mSendPartialInvalidations; bool mDataDone; diff --git a/image/src/RasterImage.cpp b/image/src/RasterImage.cpp index b805bb524f4d..ae01a97ebfb1 100644 --- a/image/src/RasterImage.cpp +++ b/image/src/RasterImage.cpp @@ -61,16 +61,6 @@ namespace image { using std::ceil; using std::min; -// a mask for flags that will affect the decoding -#define DECODE_FLAGS_MASK (imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA | imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION) -#define DECODE_FLAGS_DEFAULT 0 - -static uint32_t -DecodeFlags(uint32_t aFlags) -{ - return aFlags & DECODE_FLAGS_MASK; -} - // The maximum number of times any one RasterImage was decoded. This is only // used for statistics. static int32_t sMaxDecodeCount = 0; @@ -1359,7 +1349,7 @@ RasterImage::CreateDecoder(const Maybe& aSize, uint32_t aFlags) decoder->SetSizeDecode(!aSize); decoder->SetSendPartialInvalidations(!mHasBeenDecoded); decoder->SetImageIsTransient(mTransient); - decoder->SetDecodeFlags(DecodeFlags(aFlags)); + decoder->SetFlags(aFlags); if (!mHasBeenDecoded && aSize) { // Lock the image while we're decoding, so that it doesn't get evicted from @@ -1783,7 +1773,7 @@ RasterImage::Draw(gfxContext* aContext, // Illegal -- you can't draw with non-default decode flags. // (Disabling colorspace conversion might make sense to allow, but // we don't currently.) - if ((aFlags & DECODE_FLAGS_MASK) != DECODE_FLAGS_DEFAULT) + if (DecodeFlags(aFlags) != DECODE_FLAGS_DEFAULT) return NS_ERROR_FAILURE; NS_ENSURE_ARG_POINTER(aContext); diff --git a/image/src/RasterImage.h b/image/src/RasterImage.h index 4d69eb3cf763..5eed939e3d7e 100644 --- a/image/src/RasterImage.h +++ b/image/src/RasterImage.h @@ -27,6 +27,7 @@ #include "DecodePool.h" #include "Orientation.h" #include "nsIObserver.h" +#include "mozilla/Attributes.h" #include "mozilla/Maybe.h" #include "mozilla/MemoryReporting.h" #include "mozilla/TimeStamp.h" @@ -138,6 +139,17 @@ enum class DecodeStrategy : uint8_t { SYNC_IF_POSSIBLE }; +/** + * Given a set of imgIContainer FLAG_* flags, returns those flags that can + * affect the output of decoders. + */ +inline MOZ_CONSTEXPR uint32_t +DecodeFlags(uint32_t aFlags) +{ + return aFlags & (imgIContainer::FLAG_DECODE_NO_PREMULTIPLY_ALPHA | + imgIContainer::FLAG_DECODE_NO_COLORSPACE_CONVERSION); +} + class RasterImage MOZ_FINAL : public ImageResource , public nsIProperties , public SupportsWeakPtr @@ -217,7 +229,7 @@ public: */ void NotifyProgress(Progress aProgress, const nsIntRect& aInvalidRect = nsIntRect(), - uint32_t aFlags = 0); + uint32_t aFlags = DECODE_FLAGS_DEFAULT); /** * Records telemetry and does final teardown of the provided decoder.