Bug 1128223 (Part 1) - Clean up existing image flags. r=tn

This commit is contained in:
Seth Fowler 2015-02-02 21:40:35 -08:00
parent 997ae89e39
commit 6e474f2af0
7 changed files with 49 additions and 53 deletions

View File

@ -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;
}

View File

@ -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[]=

View File

@ -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.

View File

@ -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());

View File

@ -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;

View File

@ -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<nsIntSize>& 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);

View File

@ -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<RasterImage>
@ -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.