diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 09:22:09 +0000 |
commit | 43a97878ce14b72f0981164f87f2e35e14151312 (patch) | |
tree | 620249daf56c0258faa40cbdcf9cfba06de2a846 /image/decoders/nsAVIFDecoder.h | |
parent | Initial commit. (diff) | |
download | firefox-43a97878ce14b72f0981164f87f2e35e14151312.tar.xz firefox-43a97878ce14b72f0981164f87f2e35e14151312.zip |
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'image/decoders/nsAVIFDecoder.h')
-rw-r--r-- | image/decoders/nsAVIFDecoder.h | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/image/decoders/nsAVIFDecoder.h b/image/decoders/nsAVIFDecoder.h new file mode 100644 index 0000000000..c653a8131d --- /dev/null +++ b/image/decoders/nsAVIFDecoder.h @@ -0,0 +1,77 @@ +/* -*- 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/. */ + +#ifndef mozilla_image_decoders_nsAVIFDecoder_h +#define mozilla_image_decoders_nsAVIFDecoder_h + +#include "Decoder.h" +#include "mp4parse.h" +#include "SurfacePipe.h" + +#include "aom/aom_decoder.h" +#include "dav1d/dav1d.h" + +#include "mozilla/Telemetry.h" + +namespace mozilla { +namespace image { +class RasterImage; + +class nsAVIFDecoder final : public Decoder { + public: + virtual ~nsAVIFDecoder(); + + DecoderType GetType() const override { return DecoderType::AVIF; } + + protected: + LexerResult DoDecode(SourceBufferIterator& aIterator, + IResumable* aOnResume) override; + Maybe<Telemetry::HistogramID> SpeedHistogram() const override; + + private: + friend class DecoderFactory; + friend class AVIFDecoderInterface; + + // Decoders should only be instantiated via DecoderFactory. + explicit nsAVIFDecoder(RasterImage* aImage); + + static intptr_t ReadSource(uint8_t* aDestBuf, uintptr_t aDestBufSize, + void* aUserData); + + typedef int Dav1dResult; + enum class NonAOMCodecError { NoFrame, SizeOverflow }; + typedef Variant<aom_codec_err_t, NonAOMCodecError> AOMResult; + enum class NonDecoderResult { + NeedMoreData, + MetadataOk, + NoPrimaryItem, + SizeOverflow, + OutOfMemory, + PipeInitError, + WriteBufferError, + AlphaYSizeMismatch, + AlphaYColorDepthMismatch, + MetadataImageSizeMismatch, + InvalidCICP, + }; + using DecodeResult = + Variant<Mp4parseStatus, NonDecoderResult, Dav1dResult, AOMResult>; + DecodeResult Decode(SourceBufferIterator& aIterator, IResumable* aOnResume); + + static bool IsDecodeSuccess(const DecodeResult& aResult); + + void RecordDecodeResultTelemetry(const DecodeResult& aResult); + + Vector<uint8_t> mBufferedData; + + /// Pointer to the next place to read from mBufferedData + const uint8_t* mReadCursor = nullptr; +}; + +} // namespace image +} // namespace mozilla + +#endif // mozilla_image_decoders_nsAVIFDecoder_h |