From 287efbde21cbed26887b9466475aad0643c771df Mon Sep 17 00:00:00 2001 From: Seth Fowler Date: Sun, 26 Jun 2016 00:09:24 -0700 Subject: [PATCH] Bug 1282275 - Return IDecodingTask objects instead of Decoder objects from most DecoderFactory functions. r=dholbert --- image/DecoderFactory.cpp | 16 ++++++++++------ image/DecoderFactory.h | 7 ++++--- image/IDecodingTask.h | 9 +++++++++ image/RasterImage.cpp | 33 ++++++++++++++++----------------- 4 files changed, 39 insertions(+), 26 deletions(-) diff --git a/image/DecoderFactory.cpp b/image/DecoderFactory.cpp index 951b188a1740..ad451c9831f8 100644 --- a/image/DecoderFactory.cpp +++ b/image/DecoderFactory.cpp @@ -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 +/* static */ already_AddRefed DecoderFactory::CreateDecoder(DecoderType aType, RasterImage* aImage, SourceBuffer* aSourceBuffer, @@ -139,10 +140,11 @@ DecoderFactory::CreateDecoder(DecoderType aType, return nullptr; } - return decoder.forget(); + RefPtr task = new DecodingTask(WrapNotNull(decoder)); + return task.forget(); } -/* static */ already_AddRefed +/* static */ already_AddRefed DecoderFactory::CreateAnimationDecoder(DecoderType aType, RasterImage* aImage, SourceBuffer* aSourceBuffer, @@ -171,10 +173,11 @@ DecoderFactory::CreateAnimationDecoder(DecoderType aType, return nullptr; } - return decoder.forget(); + RefPtr task = new DecodingTask(WrapNotNull(decoder)); + return task.forget(); } -/* static */ already_AddRefed +/* static */ already_AddRefed DecoderFactory::CreateMetadataDecoder(DecoderType aType, RasterImage* aImage, SourceBuffer* aSourceBuffer, @@ -198,7 +201,8 @@ DecoderFactory::CreateMetadataDecoder(DecoderType aType, return nullptr; } - return decoder.forget(); + RefPtr task = new MetadataDecodingTask(WrapNotNull(decoder)); + return task.forget(); } /* static */ already_AddRefed diff --git a/image/DecoderFactory.h b/image/DecoderFactory.h index 85bb5ec0b1aa..d41c9facbf18 100644 --- a/image/DecoderFactory.h +++ b/image/DecoderFactory.h @@ -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 + static already_AddRefed 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 + static already_AddRefed 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 + static already_AddRefed CreateMetadataDecoder(DecoderType aType, RasterImage* aImage, SourceBuffer* aSourceBuffer, diff --git a/image/IDecodingTask.h b/image/IDecodingTask.h index 0e60683ae3c9..bc2b2fe35a66 100644 --- a/image/IDecodingTask.h +++ b/image/IDecodingTask.h @@ -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 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 GetDecoder() const override { return mDecoder; } + private: virtual ~DecodingTask() { } @@ -102,6 +107,8 @@ public: // page load. TaskPriority Priority() const override { return TaskPriority::eHigh; } + NotNull 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 GetDecoder() const override { return mDecoder; } + private: virtual ~AnonymousDecodingTask() { } diff --git a/image/RasterImage.cpp b/image/RasterImage.cpp index e1a0d30921a0..7d13d44f38da 100644 --- a/image/RasterImage.cpp +++ b/image/RasterImage.cpp @@ -1306,30 +1306,31 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags) } // Create a decoder. - RefPtr decoder; + RefPtr 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 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 = + RefPtr 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 task = new MetadataDecodingTask(WrapNotNull(decoder)); LaunchDecodingTask(task, this, aFlags, mHasSourceData); return NS_OK; }