Bug 1282275 - Return IDecodingTask objects instead of Decoder objects from most DecoderFactory functions. r=dholbert

This commit is contained in:
Seth Fowler 2016-06-26 00:09:24 -07:00
Родитель 9b38306626
Коммит 287efbde21
4 изменённых файлов: 39 добавлений и 26 удалений

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

@ -10,6 +10,7 @@
#include "nsString.h"
#include "Decoder.h"
#include "IDecodingTask.h"
#include "nsPNGDecoder.h"
#include "nsGIFDecoder2.h"
#include "nsJPEGDecoder.h"
@ -104,7 +105,7 @@ DecoderFactory::GetDecoder(DecoderType aType,
return decoder.forget();
}
/* static */ already_AddRefed<Decoder>
/* static */ already_AddRefed<IDecodingTask>
DecoderFactory::CreateDecoder(DecoderType aType,
RasterImage* aImage,
SourceBuffer* aSourceBuffer,
@ -139,10 +140,11 @@ DecoderFactory::CreateDecoder(DecoderType aType,
return nullptr;
}
return decoder.forget();
RefPtr<IDecodingTask> task = new DecodingTask(WrapNotNull(decoder));
return task.forget();
}
/* static */ already_AddRefed<Decoder>
/* static */ already_AddRefed<IDecodingTask>
DecoderFactory::CreateAnimationDecoder(DecoderType aType,
RasterImage* aImage,
SourceBuffer* aSourceBuffer,
@ -171,10 +173,11 @@ DecoderFactory::CreateAnimationDecoder(DecoderType aType,
return nullptr;
}
return decoder.forget();
RefPtr<IDecodingTask> task = new DecodingTask(WrapNotNull(decoder));
return task.forget();
}
/* static */ already_AddRefed<Decoder>
/* static */ already_AddRefed<IDecodingTask>
DecoderFactory::CreateMetadataDecoder(DecoderType aType,
RasterImage* aImage,
SourceBuffer* aSourceBuffer,
@ -198,7 +201,8 @@ DecoderFactory::CreateMetadataDecoder(DecoderType aType,
return nullptr;
}
return decoder.forget();
RefPtr<IDecodingTask> task = new MetadataDecodingTask(WrapNotNull(decoder));
return task.forget();
}
/* static */ already_AddRefed<Decoder>

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

@ -20,6 +20,7 @@ namespace mozilla {
namespace image {
class Decoder;
class IDecodingTask;
class RasterImage;
class SourceBuffer;
@ -64,7 +65,7 @@ public:
* @param aSampleSize The sample size requested using #-moz-samplesize (or 0
* if none).
*/
static already_AddRefed<Decoder>
static already_AddRefed<IDecodingTask>
CreateDecoder(DecoderType aType,
RasterImage* aImage,
SourceBuffer* aSourceBuffer,
@ -86,7 +87,7 @@ public:
* @param aSurfaceFlags Flags specifying the type of output this decoder
* should produce.
*/
static already_AddRefed<Decoder>
static already_AddRefed<IDecodingTask>
CreateAnimationDecoder(DecoderType aType,
RasterImage* aImage,
SourceBuffer* aSourceBuffer,
@ -107,7 +108,7 @@ public:
* @param aSampleSize The sample size requested using #-moz-samplesize (or 0
* if none).
*/
static already_AddRefed<Decoder>
static already_AddRefed<IDecodingTask>
CreateMetadataDecoder(DecoderType aType,
RasterImage* aImage,
SourceBuffer* aSourceBuffer,

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

@ -47,6 +47,9 @@ public:
/// DecodePool. Subclasses can override this if they need different behavior.
void Resume() override;
/// @return a non-null weak pointer to the Decoder associated with this task.
virtual NotNull<Decoder*> GetDecoder() const = 0;
// Notify the Image associated with a Decoder of its progress, sending a
// runnable to the main thread if necessary.
// XXX(seth): This is a hack that will be removed soon.
@ -74,6 +77,8 @@ public:
// don't block layout or page load.
TaskPriority Priority() const override { return TaskPriority::eLow; }
NotNull<Decoder*> GetDecoder() const override { return mDecoder; }
private:
virtual ~DecodingTask() { }
@ -102,6 +107,8 @@ public:
// page load.
TaskPriority Priority() const override { return TaskPriority::eHigh; }
NotNull<Decoder*> GetDecoder() const override { return mDecoder; }
private:
virtual ~MetadataDecodingTask() { }
@ -130,6 +137,8 @@ public:
// matter what, we don't want to resume by posting a task to the DecodePool.
void Resume() override { }
NotNull<Decoder*> GetDecoder() const override { return mDecoder; }
private:
virtual ~AnonymousDecodingTask() { }

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

@ -1306,30 +1306,31 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags)
}
// Create a decoder.
RefPtr<Decoder> decoder;
RefPtr<IDecodingTask> task;
if (mAnim) {
decoder = DecoderFactory::CreateAnimationDecoder(mDecoderType, this,
mSourceBuffer, decoderFlags,
surfaceFlags);
task = DecoderFactory::CreateAnimationDecoder(mDecoderType, this,
mSourceBuffer, decoderFlags,
surfaceFlags);
} else {
decoder = DecoderFactory::CreateDecoder(mDecoderType, this, mSourceBuffer,
targetSize, decoderFlags,
surfaceFlags,
mRequestedSampleSize);
task = DecoderFactory::CreateDecoder(mDecoderType, this, mSourceBuffer,
targetSize, decoderFlags,
surfaceFlags,
mRequestedSampleSize);
}
// Make sure DecoderFactory was able to create a decoder successfully.
if (!decoder) {
if (!task) {
return NS_ERROR_FAILURE;
}
// Add a placeholder for the first frame to the SurfaceCache so we won't
// trigger any more decoders with the same parameters.
SurfaceKey surfaceKey =
RasterSurfaceKey(aSize,
task->GetDecoder()->GetSurfaceFlags(),
/* aFrameNum = */ 0);
InsertOutcome outcome =
SurfaceCache::InsertPlaceholder(ImageKey(this),
RasterSurfaceKey(aSize,
decoder->GetSurfaceFlags(),
/* aFrameNum = */ 0));
SurfaceCache::InsertPlaceholder(ImageKey(this), surfaceKey);
if (outcome != InsertOutcome::SUCCESS) {
return NS_ERROR_FAILURE;
}
@ -1337,7 +1338,6 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags)
mDecodeCount++;
// We're ready to decode; start the decoder.
RefPtr<IDecodingTask> task = new DecodingTask(WrapNotNull(decoder));
LaunchDecodingTask(task, this, aFlags, mHasSourceData);
return NS_OK;
}
@ -1352,17 +1352,16 @@ RasterImage::DecodeMetadata(uint32_t aFlags)
MOZ_ASSERT(!mHasSize, "Should not do unnecessary metadata decodes");
// Create a decoder.
RefPtr<Decoder> decoder =
RefPtr<IDecodingTask> task =
DecoderFactory::CreateMetadataDecoder(mDecoderType, this, mSourceBuffer,
mRequestedSampleSize);
// Make sure DecoderFactory was able to create a decoder successfully.
if (!decoder) {
if (!task) {
return NS_ERROR_FAILURE;
}
// We're ready to decode; start the decoder.
RefPtr<IDecodingTask> task = new MetadataDecodingTask(WrapNotNull(decoder));
LaunchDecodingTask(task, this, aFlags, mHasSourceData);
return NS_OK;
}