Bug 1282354 - Move code for SurfaceCache placeholder insertion from RasterImage to DecoderFactory. r=dholbert

This commit is contained in:
Seth Fowler 2016-06-26 22:05:58 -07:00
Родитель d7bb652cf1
Коммит 8220b27059
3 изменённых файлов: 34 добавлений и 16 удалений

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

@ -108,6 +108,7 @@ DecoderFactory::GetDecoder(DecoderType aType,
DecoderFactory::CreateDecoder(DecoderType aType, DecoderFactory::CreateDecoder(DecoderType aType,
NotNull<RasterImage*> aImage, NotNull<RasterImage*> aImage,
NotNull<SourceBuffer*> aSourceBuffer, NotNull<SourceBuffer*> aSourceBuffer,
const IntSize& aIntrinsicSize,
const Maybe<IntSize>& aTargetSize, const Maybe<IntSize>& aTargetSize,
DecoderFlags aDecoderFlags, DecoderFlags aDecoderFlags,
SurfaceFlags aSurfaceFlags, SurfaceFlags aSurfaceFlags,
@ -139,6 +140,17 @@ DecoderFactory::CreateDecoder(DecoderType aType,
return nullptr; return nullptr;
} }
// Add a placeholder to the SurfaceCache so we won't trigger any more decoders
// with the same parameters.
IntSize surfaceSize = aTargetSize.valueOr(aIntrinsicSize);
SurfaceKey surfaceKey =
RasterSurfaceKey(surfaceSize, aSurfaceFlags, /* aFrameNum = */ 0);
InsertOutcome outcome =
SurfaceCache::InsertPlaceholder(ImageKey(aImage.get()), surfaceKey);
if (outcome != InsertOutcome::SUCCESS) {
return nullptr;
}
RefPtr<IDecodingTask> task = new DecodingTask(WrapNotNull(decoder)); RefPtr<IDecodingTask> task = new DecodingTask(WrapNotNull(decoder));
return task.forget(); return task.forget();
} }
@ -147,6 +159,7 @@ DecoderFactory::CreateDecoder(DecoderType aType,
DecoderFactory::CreateAnimationDecoder(DecoderType aType, DecoderFactory::CreateAnimationDecoder(DecoderType aType,
NotNull<RasterImage*> aImage, NotNull<RasterImage*> aImage,
NotNull<SourceBuffer*> aSourceBuffer, NotNull<SourceBuffer*> aSourceBuffer,
const IntSize& aIntrinsicSize,
DecoderFlags aDecoderFlags, DecoderFlags aDecoderFlags,
SurfaceFlags aSurfaceFlags) SurfaceFlags aSurfaceFlags)
{ {
@ -172,6 +185,16 @@ DecoderFactory::CreateAnimationDecoder(DecoderType aType,
return nullptr; return nullptr;
} }
// 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(aIntrinsicSize, aSurfaceFlags, /* aFrameNum = */ 0);
InsertOutcome outcome =
SurfaceCache::InsertPlaceholder(ImageKey(aImage.get()), surfaceKey);
if (outcome != InsertOutcome::SUCCESS) {
return nullptr;
}
RefPtr<IDecodingTask> task = new DecodingTask(WrapNotNull(decoder)); RefPtr<IDecodingTask> task = new DecodingTask(WrapNotNull(decoder));
return task.forget(); return task.forget();
} }

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

@ -54,6 +54,8 @@ public:
* notifications as decoding progresses. * notifications as decoding progresses.
* @param aSourceBuffer The SourceBuffer which the decoder will read its data * @param aSourceBuffer The SourceBuffer which the decoder will read its data
* from. * from.
* @param aIntrinsicSize The intrinsic size of the image, normally obtained
* during the metadata decode.
* @param aTargetSize If not Nothing(), the target size which the image should * @param aTargetSize If not Nothing(), the target size which the image should
* be scaled to during decoding. It's an error to specify * be scaled to during decoding. It's an error to specify
* a target size for a decoder type which doesn't support * a target size for a decoder type which doesn't support
@ -68,6 +70,7 @@ public:
CreateDecoder(DecoderType aType, CreateDecoder(DecoderType aType,
NotNull<RasterImage*> aImage, NotNull<RasterImage*> aImage,
NotNull<SourceBuffer*> aSourceBuffer, NotNull<SourceBuffer*> aSourceBuffer,
const gfx::IntSize& aIntrinsicSize,
const Maybe<gfx::IntSize>& aTargetSize, const Maybe<gfx::IntSize>& aTargetSize,
DecoderFlags aDecoderFlags, DecoderFlags aDecoderFlags,
SurfaceFlags aSurfaceFlags, SurfaceFlags aSurfaceFlags,
@ -82,6 +85,8 @@ public:
* notifications as decoding progresses. * notifications as decoding progresses.
* @param aSourceBuffer The SourceBuffer which the decoder will read its data * @param aSourceBuffer The SourceBuffer which the decoder will read its data
* from. * from.
* @param aIntrinsicSize The intrinsic size of the image, normally obtained
* during the metadata decode.
* @param aDecoderFlags Flags specifying the behavior of this decoder. * @param aDecoderFlags Flags specifying the behavior of this decoder.
* @param aSurfaceFlags Flags specifying the type of output this decoder * @param aSurfaceFlags Flags specifying the type of output this decoder
* should produce. * should produce.
@ -90,6 +95,7 @@ public:
CreateAnimationDecoder(DecoderType aType, CreateAnimationDecoder(DecoderType aType,
NotNull<RasterImage*> aImage, NotNull<RasterImage*> aImage,
NotNull<SourceBuffer*> aSourceBuffer, NotNull<SourceBuffer*> aSourceBuffer,
const gfx::IntSize& aIntrinsicSize,
DecoderFlags aDecoderFlags, DecoderFlags aDecoderFlags,
SurfaceFlags aSurfaceFlags); SurfaceFlags aSurfaceFlags);

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

@ -1309,12 +1309,13 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags)
RefPtr<IDecodingTask> task; RefPtr<IDecodingTask> task;
if (mAnim) { if (mAnim) {
task = DecoderFactory::CreateAnimationDecoder(mDecoderType, WrapNotNull(this), task = DecoderFactory::CreateAnimationDecoder(mDecoderType, WrapNotNull(this),
mSourceBuffer, decoderFlags, mSourceBuffer, mSize,
surfaceFlags); decoderFlags, surfaceFlags);
} else { } else {
task = DecoderFactory::CreateDecoder(mDecoderType, WrapNotNull(this), task = DecoderFactory::CreateDecoder(mDecoderType, WrapNotNull(this),
mSourceBuffer, targetSize, decoderFlags, mSourceBuffer, mSize, targetSize,
surfaceFlags, mRequestedSampleSize); decoderFlags, surfaceFlags,
mRequestedSampleSize);
} }
// Make sure DecoderFactory was able to create a decoder successfully. // Make sure DecoderFactory was able to create a decoder successfully.
@ -1322,18 +1323,6 @@ RasterImage::Decode(const IntSize& aSize, uint32_t aFlags)
return NS_ERROR_FAILURE; 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), surfaceKey);
if (outcome != InsertOutcome::SUCCESS) {
return NS_ERROR_FAILURE;
}
mDecodeCount++; mDecodeCount++;
// We're ready to decode; start the decoder. // We're ready to decode; start the decoder.