Bug 1282275 - Return IDecodingTask objects instead of Decoder objects from most DecoderFactory functions. r=dholbert
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
|
|
||||||
#include "Decoder.h"
|
#include "Decoder.h"
|
||||||
|
#include "IDecodingTask.h"
|
||||||
#include "nsPNGDecoder.h"
|
#include "nsPNGDecoder.h"
|
||||||
#include "nsGIFDecoder2.h"
|
#include "nsGIFDecoder2.h"
|
||||||
#include "nsJPEGDecoder.h"
|
#include "nsJPEGDecoder.h"
|
||||||
@@ -104,7 +105,7 @@ DecoderFactory::GetDecoder(DecoderType aType,
|
|||||||
return decoder.forget();
|
return decoder.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ already_AddRefed<Decoder>
|
/* static */ already_AddRefed<IDecodingTask>
|
||||||
DecoderFactory::CreateDecoder(DecoderType aType,
|
DecoderFactory::CreateDecoder(DecoderType aType,
|
||||||
RasterImage* aImage,
|
RasterImage* aImage,
|
||||||
SourceBuffer* aSourceBuffer,
|
SourceBuffer* aSourceBuffer,
|
||||||
@@ -139,10 +140,11 @@ DecoderFactory::CreateDecoder(DecoderType aType,
|
|||||||
return nullptr;
|
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,
|
DecoderFactory::CreateAnimationDecoder(DecoderType aType,
|
||||||
RasterImage* aImage,
|
RasterImage* aImage,
|
||||||
SourceBuffer* aSourceBuffer,
|
SourceBuffer* aSourceBuffer,
|
||||||
@@ -171,10 +173,11 @@ DecoderFactory::CreateAnimationDecoder(DecoderType aType,
|
|||||||
return nullptr;
|
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,
|
DecoderFactory::CreateMetadataDecoder(DecoderType aType,
|
||||||
RasterImage* aImage,
|
RasterImage* aImage,
|
||||||
SourceBuffer* aSourceBuffer,
|
SourceBuffer* aSourceBuffer,
|
||||||
@@ -198,7 +201,8 @@ DecoderFactory::CreateMetadataDecoder(DecoderType aType,
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return decoder.forget();
|
RefPtr<IDecodingTask> task = new MetadataDecodingTask(WrapNotNull(decoder));
|
||||||
|
return task.forget();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ already_AddRefed<Decoder>
|
/* static */ already_AddRefed<Decoder>
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace mozilla {
|
|||||||
namespace image {
|
namespace image {
|
||||||
|
|
||||||
class Decoder;
|
class Decoder;
|
||||||
|
class IDecodingTask;
|
||||||
class RasterImage;
|
class RasterImage;
|
||||||
class SourceBuffer;
|
class SourceBuffer;
|
||||||
|
|
||||||
@@ -64,7 +65,7 @@ public:
|
|||||||
* @param aSampleSize The sample size requested using #-moz-samplesize (or 0
|
* @param aSampleSize The sample size requested using #-moz-samplesize (or 0
|
||||||
* if none).
|
* if none).
|
||||||
*/
|
*/
|
||||||
static already_AddRefed<Decoder>
|
static already_AddRefed<IDecodingTask>
|
||||||
CreateDecoder(DecoderType aType,
|
CreateDecoder(DecoderType aType,
|
||||||
RasterImage* aImage,
|
RasterImage* aImage,
|
||||||
SourceBuffer* aSourceBuffer,
|
SourceBuffer* aSourceBuffer,
|
||||||
@@ -86,7 +87,7 @@ public:
|
|||||||
* @param aSurfaceFlags Flags specifying the type of output this decoder
|
* @param aSurfaceFlags Flags specifying the type of output this decoder
|
||||||
* should produce.
|
* should produce.
|
||||||
*/
|
*/
|
||||||
static already_AddRefed<Decoder>
|
static already_AddRefed<IDecodingTask>
|
||||||
CreateAnimationDecoder(DecoderType aType,
|
CreateAnimationDecoder(DecoderType aType,
|
||||||
RasterImage* aImage,
|
RasterImage* aImage,
|
||||||
SourceBuffer* aSourceBuffer,
|
SourceBuffer* aSourceBuffer,
|
||||||
@@ -107,7 +108,7 @@ public:
|
|||||||
* @param aSampleSize The sample size requested using #-moz-samplesize (or 0
|
* @param aSampleSize The sample size requested using #-moz-samplesize (or 0
|
||||||
* if none).
|
* if none).
|
||||||
*/
|
*/
|
||||||
static already_AddRefed<Decoder>
|
static already_AddRefed<IDecodingTask>
|
||||||
CreateMetadataDecoder(DecoderType aType,
|
CreateMetadataDecoder(DecoderType aType,
|
||||||
RasterImage* aImage,
|
RasterImage* aImage,
|
||||||
SourceBuffer* aSourceBuffer,
|
SourceBuffer* aSourceBuffer,
|
||||||
|
|||||||
@@ -47,6 +47,9 @@ public:
|
|||||||
/// DecodePool. Subclasses can override this if they need different behavior.
|
/// DecodePool. Subclasses can override this if they need different behavior.
|
||||||
void Resume() override;
|
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
|
// Notify the Image associated with a Decoder of its progress, sending a
|
||||||
// runnable to the main thread if necessary.
|
// runnable to the main thread if necessary.
|
||||||
// XXX(seth): This is a hack that will be removed soon.
|
// XXX(seth): This is a hack that will be removed soon.
|
||||||
@@ -74,6 +77,8 @@ public:
|
|||||||
// don't block layout or page load.
|
// don't block layout or page load.
|
||||||
TaskPriority Priority() const override { return TaskPriority::eLow; }
|
TaskPriority Priority() const override { return TaskPriority::eLow; }
|
||||||
|
|
||||||
|
NotNull<Decoder*> GetDecoder() const override { return mDecoder; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual ~DecodingTask() { }
|
virtual ~DecodingTask() { }
|
||||||
|
|
||||||
@@ -102,6 +107,8 @@ public:
|
|||||||
// page load.
|
// page load.
|
||||||
TaskPriority Priority() const override { return TaskPriority::eHigh; }
|
TaskPriority Priority() const override { return TaskPriority::eHigh; }
|
||||||
|
|
||||||
|
NotNull<Decoder*> GetDecoder() const override { return mDecoder; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual ~MetadataDecodingTask() { }
|
virtual ~MetadataDecodingTask() { }
|
||||||
|
|
||||||
@@ -130,6 +137,8 @@ public:
|
|||||||
// matter what, we don't want to resume by posting a task to the DecodePool.
|
// matter what, we don't want to resume by posting a task to the DecodePool.
|
||||||
void Resume() override { }
|
void Resume() override { }
|
||||||
|
|
||||||
|
NotNull<Decoder*> GetDecoder() const override { return mDecoder; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
virtual ~AnonymousDecodingTask() { }
|
virtual ~AnonymousDecodingTask() { }
|
||||||
|
|
||||||
|
|||||||
@@ -1306,30 +1306,31 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create a decoder.
|
// Create a decoder.
|
||||||
RefPtr<Decoder> decoder;
|
RefPtr<IDecodingTask> task;
|
||||||
if (mAnim) {
|
if (mAnim) {
|
||||||
decoder = DecoderFactory::CreateAnimationDecoder(mDecoderType, this,
|
task = DecoderFactory::CreateAnimationDecoder(mDecoderType, this,
|
||||||
mSourceBuffer, decoderFlags,
|
mSourceBuffer, decoderFlags,
|
||||||
surfaceFlags);
|
surfaceFlags);
|
||||||
} else {
|
} else {
|
||||||
decoder = DecoderFactory::CreateDecoder(mDecoderType, this, mSourceBuffer,
|
task = DecoderFactory::CreateDecoder(mDecoderType, this, mSourceBuffer,
|
||||||
targetSize, decoderFlags,
|
targetSize, decoderFlags,
|
||||||
surfaceFlags,
|
surfaceFlags,
|
||||||
mRequestedSampleSize);
|
mRequestedSampleSize);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make sure DecoderFactory was able to create a decoder successfully.
|
// Make sure DecoderFactory was able to create a decoder successfully.
|
||||||
if (!decoder) {
|
if (!task) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a placeholder for the first frame to the SurfaceCache so we won't
|
// Add a placeholder for the first frame to the SurfaceCache so we won't
|
||||||
// trigger any more decoders with the same parameters.
|
// trigger any more decoders with the same parameters.
|
||||||
|
SurfaceKey surfaceKey =
|
||||||
|
RasterSurfaceKey(aSize,
|
||||||
|
task->GetDecoder()->GetSurfaceFlags(),
|
||||||
|
/* aFrameNum = */ 0);
|
||||||
InsertOutcome outcome =
|
InsertOutcome outcome =
|
||||||
SurfaceCache::InsertPlaceholder(ImageKey(this),
|
SurfaceCache::InsertPlaceholder(ImageKey(this), surfaceKey);
|
||||||
RasterSurfaceKey(aSize,
|
|
||||||
decoder->GetSurfaceFlags(),
|
|
||||||
/* aFrameNum = */ 0));
|
|
||||||
if (outcome != InsertOutcome::SUCCESS) {
|
if (outcome != InsertOutcome::SUCCESS) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
@@ -1337,7 +1338,6 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags)
|
|||||||
mDecodeCount++;
|
mDecodeCount++;
|
||||||
|
|
||||||
// We're ready to decode; start the decoder.
|
// We're ready to decode; start the decoder.
|
||||||
RefPtr<IDecodingTask> task = new DecodingTask(WrapNotNull(decoder));
|
|
||||||
LaunchDecodingTask(task, this, aFlags, mHasSourceData);
|
LaunchDecodingTask(task, this, aFlags, mHasSourceData);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
@@ -1352,17 +1352,16 @@ RasterImage::DecodeMetadata(uint32_t aFlags)
|
|||||||
MOZ_ASSERT(!mHasSize, "Should not do unnecessary metadata decodes");
|
MOZ_ASSERT(!mHasSize, "Should not do unnecessary metadata decodes");
|
||||||
|
|
||||||
// Create a decoder.
|
// Create a decoder.
|
||||||
RefPtr<Decoder> decoder =
|
RefPtr<IDecodingTask> task =
|
||||||
DecoderFactory::CreateMetadataDecoder(mDecoderType, this, mSourceBuffer,
|
DecoderFactory::CreateMetadataDecoder(mDecoderType, this, mSourceBuffer,
|
||||||
mRequestedSampleSize);
|
mRequestedSampleSize);
|
||||||
|
|
||||||
// Make sure DecoderFactory was able to create a decoder successfully.
|
// Make sure DecoderFactory was able to create a decoder successfully.
|
||||||
if (!decoder) {
|
if (!task) {
|
||||||
return NS_ERROR_FAILURE;
|
return NS_ERROR_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// We're ready to decode; start the decoder.
|
// We're ready to decode; start the decoder.
|
||||||
RefPtr<IDecodingTask> task = new MetadataDecodingTask(WrapNotNull(decoder));
|
|
||||||
LaunchDecodingTask(task, this, aFlags, mHasSourceData);
|
LaunchDecodingTask(task, this, aFlags, mHasSourceData);
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user