/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
switch (aType) { case DecoderType::PNG:
decoder = new nsPNGDecoder(aImage); break; case DecoderType::GIF:
decoder = new nsGIFDecoder2(aImage); break; case DecoderType::JPEG: // If we have all the data we don't want to waste cpu time doing // a progressive decode.
decoder = new nsJPEGDecoder(
aImage, aIsRedecode ? Decoder::SEQUENTIAL : Decoder::PROGRESSIVE); break; case DecoderType::BMP:
decoder = new nsBMPDecoder(aImage); break; case DecoderType::BMP_CLIPBOARD:
decoder = new nsBMPDecoder(aImage, /* aForClipboard */ true); break; case DecoderType::ICO:
decoder = new nsICODecoder(aImage); break; case DecoderType::ICON:
decoder = new nsIconDecoder(aImage); break; case DecoderType::WEBP:
decoder = new nsWebPDecoder(aImage); break; #ifdef MOZ_AV1 case DecoderType::AVIF:
decoder = new nsAVIFDecoder(aImage); break; #endif #ifdef MOZ_JXL case DecoderType::JXL:
decoder = new nsJXLDecoder(aImage); break; #endif default:
MOZ_ASSERT_UNREACHABLE("Unknown decoder type");
}
// Only can use COUNT_FRAMES with metadata decoders. if (NS_WARN_IF(bool(aDecoderFlags & DecoderFlags::COUNT_FRAMES))) { return NS_ERROR_INVALID_ARG;
}
// Create an anonymous decoder. Interaction with the SurfaceCache and the // owning RasterImage will be mediated by DecodedSurfaceProvider.
RefPtr<Decoder> decoder = GetDecoder(
aType, nullptr, bool(aDecoderFlags & DecoderFlags::IS_REDECODE));
MOZ_ASSERT(decoder, "Should have a decoder now");
nsresult rv = decoder->Init(); if (NS_FAILED(rv)) { return NS_ERROR_FAILURE;
}
// Create a DecodedSurfaceProvider which will manage the decoding process and // make this decoder's output available in the surface cache.
SurfaceKey surfaceKey =
RasterSurfaceKey(aOutputSize, aSurfaceFlags, PlaybackType::eStatic); auto provider = MakeNotNull<RefPtr<DecodedSurfaceProvider>>(
aImage, surfaceKey, WrapNotNull(decoder)); if (aDecoderFlags & DecoderFlags::CANNOT_SUBSTITUTE) {
provider->Availability().SetCannotSubstitute();
}
// Attempt to insert the surface provider into the surface cache right away so // we won't trigger any more decoders with the same parameters. switch (SurfaceCache::Insert(provider)) { case InsertOutcome::SUCCESS: break; case InsertOutcome::FAILURE_ALREADY_PRESENT: return NS_ERROR_ALREADY_INITIALIZED; default: return NS_ERROR_FAILURE;
}
// Return the surface provider in its IDecodingTask guise.
RefPtr<IDecodingTask> task = provider.get();
task.forget(aOutTask); return NS_OK;
}
// Only can use COUNT_FRAMES with metadata decoders. if (NS_WARN_IF(bool(aDecoderFlags & DecoderFlags::COUNT_FRAMES))) { return NS_ERROR_INVALID_ARG;
}
// Create an anonymous decoder. Interaction with the SurfaceCache and the // owning RasterImage will be mediated by AnimationSurfaceProvider.
RefPtr<Decoder> decoder =
GetDecoder(aType, nullptr, /* aIsRedecode = */ true);
MOZ_ASSERT(decoder, "Should have a decoder now");
// Initialize the decoder.
decoder->SetMetadataDecode(false);
decoder->SetIterator(aSourceBuffer->Iterator());
decoder->SetDecoderFlags(aDecoderFlags | DecoderFlags::IS_REDECODE);
decoder->SetSurfaceFlags(aSurfaceFlags);
nsresult rv = decoder->Init(); if (NS_FAILED(rv)) { return NS_ERROR_FAILURE;
}
// Create an AnimationSurfaceProvider which will manage the decoding process // and make this decoder's output available in the surface cache.
SurfaceKey surfaceKey =
RasterSurfaceKey(aIntrinsicSize, aSurfaceFlags, PlaybackType::eAnimated); auto provider = MakeNotNull<RefPtr<AnimationSurfaceProvider>>(
aImage, surfaceKey, WrapNotNull(decoder), aCurrentFrame);
// Attempt to insert the surface provider into the surface cache right away so // we won't trigger any more decoders with the same parameters. switch (SurfaceCache::Insert(provider)) { case InsertOutcome::SUCCESS: break; case InsertOutcome::FAILURE_ALREADY_PRESENT: return NS_ERROR_ALREADY_INITIALIZED; default: return NS_ERROR_FAILURE;
}
// Return the surface provider in its IDecodingTask guise.
RefPtr<IDecodingTask> task = provider.get();
task.forget(aOutTask); return NS_OK;
}
// In an ideal world, we would assert aDecoder->HasAnimation() but we cannot. // The decoder may not have detected it is animated yet (e.g. it did not even // get scheduled yet, or it has only decoded the first frame and has yet to // rediscover it is animated).
DecoderType type = aDecoder->GetType();
MOZ_ASSERT(type == DecoderType::GIF || type == DecoderType::PNG ||
type == DecoderType::WEBP || type == DecoderType::AVIF, "Calling CloneAnimationDecoder for non-animating DecoderType");
RefPtr<Decoder> decoder = GetDecoder(type, nullptr, /* aIsRedecode = */ true);
MOZ_ASSERT(decoder, "Should have a decoder now");
// Initialize the decoder.
decoder->SetMetadataDecode(false);
decoder->SetIterator(aDecoder->GetSourceBuffer()->Iterator());
decoder->SetDecoderFlags(aDecoder->GetDecoderFlags());
decoder->SetSurfaceFlags(aDecoder->GetSurfaceFlags());
decoder->SetFrameRecycler(aDecoder->GetFrameRecycler());
if (NS_FAILED(decoder->Init())) { return nullptr;
}
// Only can use COUNT_FRAMES with metadata decoders. if (NS_WARN_IF(bool(aDecoderFlags & DecoderFlags::COUNT_FRAMES))) { return nullptr;
}
RefPtr<Decoder> decoder =
GetDecoder(aType, /* aImage = */ nullptr, /* aIsRedecode = */ false);
MOZ_ASSERT(decoder, "Should have a decoder now");
// Initialize the decoder.
decoder->SetMetadataDecode(false);
decoder->SetIterator(aSourceBuffer->Iterator());
// Anonymous decoders are always transient; we don't want to optimize surfaces // or do any other expensive work that might be wasted.
DecoderFlags decoderFlags = DecoderFlags::IMAGE_IS_TRANSIENT;
// Set an output size for downscale-during-decode if requested. if (aOutputSize) {
decoder->SetOutputSize(OrientedIntSize::FromUnknownSize(*aOutputSize));
}
if (NS_FAILED(decoder->Init())) { return nullptr;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.