Backed out changeset 9e9c62f86ca3 (bug 1119774)

This commit is contained in:
Carsten "Tomcat" Book 2015-01-12 15:35:19 +01:00
Родитель 3927deff78
Коммит 441a3dad22
3 изменённых файлов: 27 добавлений и 78 удалений

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

@ -127,24 +127,6 @@ public:
mSizeDecode = aSizeDecode;
}
/**
* If this decoder supports downscale-during-decode, sets the target size that
* this image should be decoded to.
*
* If this decoder *doesn't* support downscale-during-decode, returns
* NS_ERROR_NOT_AVAILABLE. If the provided size is unacceptable, returns
* another error.
*
* Returning NS_OK from this method is a promise that the decoder will decode
* the image to the requested target size unless it encounters an error.
*
* This must be called before Init() is called.
*/
virtual nsresult SetTargetSize(const nsIntSize& aSize)
{
return NS_ERROR_NOT_AVAILABLE;
}
/**
* Set whether should send partial invalidations.
*

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

@ -34,7 +34,6 @@
#include "gfxContext.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Move.h"
#include "mozilla/MemoryReporting.h"
@ -348,7 +347,8 @@ RasterImage::Init(const char* aMimeType,
}
// Create the initial size decoder.
nsresult rv = Decode(DecodeStrategy::ASYNC, Nothing(), DECODE_FLAGS_DEFAULT);
nsresult rv = Decode(DecodeStrategy::ASYNC, DECODE_FLAGS_DEFAULT,
/* aDoSizeDecode = */ true);
if (NS_FAILED(rv)) {
return NS_ERROR_FAILURE;
}
@ -519,18 +519,11 @@ RasterImage::LookupFrame(uint32_t aFrameNum,
aFlags ^ FLAG_DECODE_NO_PREMULTIPLY_ALPHA);
}
if (!ref && !mHasSize) {
// We can't request a decode without knowing our intrinsic size. Give up.
return DrawableFrameRef();
}
if (!ref) {
// The OS threw this frame away. We need to redecode if we can.
MOZ_ASSERT(!mAnim, "Animated frames should be locked");
// XXX(seth): We'll add downscale-during-decode-related logic here in a
// later part, but for now we just use our intrinsic size.
WantDecodedFrames(mSize, aFlags, aShouldSyncNotify);
WantDecodedFrames(aFlags, aShouldSyncNotify);
// If we were able to sync decode, we should already have the frame. If we
// had to decode asynchronously, maybe we've gotten lucky.
@ -1141,7 +1134,8 @@ RasterImage::OnImageDataComplete(nsIRequest*, nsISupports*, nsresult aStatus,
// We need to guarantee that we've gotten the image's size, or at least
// determined that we won't be able to get it, before we deliver the load
// event. That means we have to do a synchronous size decode here.
Decode(DecodeStrategy::SYNC_IF_POSSIBLE, Nothing(), DECODE_FLAGS_DEFAULT);
Decode(DecodeStrategy::SYNC_IF_POSSIBLE, DECODE_FLAGS_DEFAULT,
/* aDoSizeDecode = */ true);
}
// Determine our final status, giving precedence to Necko failure codes. We
@ -1267,16 +1261,13 @@ RasterImage::CanDiscard() {
// Sets up a decoder for this image.
already_AddRefed<Decoder>
RasterImage::CreateDecoder(const Maybe<nsIntSize>& aSize, uint32_t aFlags)
RasterImage::CreateDecoder(bool aDoSizeDecode, uint32_t aFlags)
{
// Make sure we actually get size before doing a full decode.
if (aSize) {
MOZ_ASSERT(mHasSize, "Must do a size decode before a full decode!");
MOZ_ASSERT(mDownscaleDuringDecode || *aSize == mSize,
"Can only decode to our intrinsic size if we're not allowed to "
"downscale-during-decode");
} else {
if (aDoSizeDecode) {
MOZ_ASSERT(!mHasSize, "Should not do unnecessary size decodes");
} else {
MOZ_ASSERT(mHasSize, "Must do a size decode before a full decode!");
}
// Figure out which decoder we want.
@ -1317,36 +1308,27 @@ RasterImage::CreateDecoder(const Maybe<nsIntSize>& aSize, uint32_t aFlags)
MOZ_ASSERT(decoder, "Should have a decoder now");
// Initialize the decoder.
decoder->SetSizeDecode(!aSize);
decoder->SetSizeDecode(aDoSizeDecode);
decoder->SetSendPartialInvalidations(!mHasBeenDecoded);
decoder->SetImageIsTransient(mTransient);
decoder->SetDecodeFlags(DecodeFlags(aFlags));
if (aSize) {
if (!aDoSizeDecode) {
// We already have the size; tell the decoder so it can preallocate a
// frame. By default, we create an ARGB frame with no offset. If decoders
// need a different type, they need to ask for it themselves.
decoder->SetSize(mSize, mOrientation);
decoder->NeedNewFrame(0, 0, 0, aSize->width, aSize->height,
decoder->NeedNewFrame(0, 0, 0, mSize.width, mSize.height,
SurfaceFormat::B8G8R8A8);
decoder->AllocateFrame();
}
decoder->SetIterator(mSourceBuffer->Iterator());
// Set a target size for downscale-during-decode if applicable.
if (mDownscaleDuringDecode && aSize && *aSize != mSize) {
DebugOnly<nsresult> rv = decoder->SetTargetSize(*aSize);
MOZ_ASSERT(nsresult(rv) != NS_ERROR_NOT_AVAILABLE,
"We're downscale-during-decode but decoder doesn't support it?");
MOZ_ASSERT(NS_SUCCEEDED(rv), "Bad downscale-during-decode target size?");
}
decoder->Init();
if (NS_FAILED(decoder->GetDecoderError())) {
return nullptr;
}
if (!aSize) {
if (!aDoSizeDecode) {
Telemetry::GetHistogramById(Telemetry::IMAGE_DECODE_COUNT)->Subtract(mDecodeCount);
mDecodeCount++;
Telemetry::GetHistogramById(Telemetry::IMAGE_DECODE_COUNT)->Add(mDecodeCount);
@ -1366,13 +1348,12 @@ RasterImage::CreateDecoder(const Maybe<nsIntSize>& aSize, uint32_t aFlags)
}
void
RasterImage::WantDecodedFrames(const nsIntSize& aSize, uint32_t aFlags,
bool aShouldSyncNotify)
RasterImage::WantDecodedFrames(uint32_t aFlags, bool aShouldSyncNotify)
{
if (aShouldSyncNotify) {
// We can sync notify, which means we can also sync decode.
if (aFlags & FLAG_SYNC_DECODE) {
Decode(DecodeStrategy::SYNC_IF_POSSIBLE, Some(aSize), aFlags);
Decode(DecodeStrategy::SYNC_IF_POSSIBLE, aFlags);
return;
}
@ -1380,12 +1361,12 @@ RasterImage::WantDecodedFrames(const nsIntSize& aSize, uint32_t aFlags,
// case that we're redecoding an image (see bug 845147).
Decode(mHasBeenDecoded ? DecodeStrategy::ASYNC
: DecodeStrategy::SYNC_FOR_SMALL_IMAGES,
Some(aSize), aFlags);
aFlags);
return;
}
// We can't sync notify, so do an async decode.
Decode(DecodeStrategy::ASYNC, Some(aSize), aFlags);
Decode(DecodeStrategy::ASYNC, aFlags);
}
//******************************************************************************
@ -1450,30 +1431,30 @@ RasterImage::IsDecoded()
NS_IMETHODIMP
RasterImage::Decode(DecodeStrategy aStrategy,
const Maybe<nsIntSize>& aSize,
uint32_t aFlags)
uint32_t aFlags,
bool aDoSizeDecode /* = false */)
{
MOZ_ASSERT(!aSize || NS_IsMainThread());
MOZ_ASSERT(aDoSizeDecode || NS_IsMainThread());
if (mError) {
return NS_ERROR_FAILURE;
}
// If we don't have a size yet, we can't do any other decoding.
if (!mHasSize && aSize) {
if (!mHasSize && !aDoSizeDecode) {
mWantFullDecode = true;
return NS_OK;
}
// Create a decoder.
nsRefPtr<Decoder> decoder = CreateDecoder(aSize, aFlags);
nsRefPtr<Decoder> decoder = CreateDecoder(aDoSizeDecode, aFlags);
if (!decoder) {
return NS_ERROR_FAILURE;
}
// Send out early notifications right away. (Unless this is a size decode,
// which doesn't send out any notifications until the end.)
if (aSize) {
if (!aDoSizeDecode) {
NotifyProgress(decoder->TakeProgress(),
decoder->TakeInvalidRect(),
decoder->GetDecodeFlags());

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

@ -326,26 +326,12 @@ private:
// Decoding.
//////////////////////////////////////////////////////////////////////////////
/**
* Creates and runs a decoder, either synchronously or asynchronously
* according to @aStrategy. Passes the provided target size @aSize and decode
* flags @aFlags to CreateDecoder. If a size decode is desired, pass Nothing
* for @aSize.
*/
NS_IMETHOD Decode(DecodeStrategy aStrategy,
const Maybe<nsIntSize>& aSize,
uint32_t aFlags);
already_AddRefed<Decoder> CreateDecoder(bool aDoSizeDecode, uint32_t aFlags);
/**
* Creates a new decoder with a target size of @aSize and decode flags
* specified by @aFlags. If a size decode is desired, pass Nothing() for
* @aSize.
*/
already_AddRefed<Decoder> CreateDecoder(const Maybe<nsIntSize>& aSize,
uint32_t aFlags);
void WantDecodedFrames(uint32_t aFlags, bool aShouldSyncNotify);
void WantDecodedFrames(const nsIntSize& aSize, uint32_t aFlags,
bool aShouldSyncNotify);
NS_IMETHOD Decode(DecodeStrategy aStrategy, uint32_t aFlags,
bool aDoSizeDecode = false);
private: // data
nsIntSize mSize;