/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* vim:set ts=2 sw=2 sts=2 et cindent: */ /* 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_DOM_WEBCODECS_WEBCODECSUTILS_H #define MOZILLA_DOM_WEBCODECS_WEBCODECSUTILS_H #include #include "ErrorList.h" #include "js/TypeDecls.h" #include "mozilla/Maybe.h" #include "mozilla/Result.h" #include "mozilla/Span.h" #include "mozilla/dom/BindingDeclarations.h" #include "mozilla/dom/Nullable.h" #include "mozilla/dom/UnionTypes.h" namespace mozilla { namespace gfx { enum class ColorRange : uint8_t; enum class ColorSpace2 : uint8_t; enum class SurfaceFormat : int8_t; enum class TransferFunction : uint8_t; enum class YUVColorSpace : uint8_t; } // namespace gfx namespace dom { /* * The followings are helpers for WebCodecs methods */ nsTArray GuessContainers(const nsAString& aCodec); /* * Below are helpers for conversion among Maybe, Optional, and Nullable. */ template Maybe OptionalToMaybe(const Optional& aOptional) { if (aOptional.WasPassed()) { return Some(aOptional.Value()); } return Nothing(); } template const T* OptionalToPointer(const Optional& aOptional) { return aOptional.WasPassed() ? &aOptional.Value() : nullptr; } template Maybe NullableToMaybe(const Nullable& aNullable) { if (!aNullable.IsNull()) { return Some(aNullable.Value()); } return Nothing(); } template Nullable MaybeToNullable(const Maybe& aOptional) { if (aOptional.isSome()) { return Nullable(aOptional.value()); } return Nullable(); } /* * Below are helpers to operate ArrayBuffer or ArrayBufferView. */ Result, nsresult> GetSharedArrayBufferData( const MaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer& aBuffer); Result, nsresult> GetSharedArrayBufferData( const OwningMaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer& aBuffer); Result CloneBuffer( JSContext* aCx, OwningMaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer& aDest, const OwningMaybeSharedArrayBufferViewOrMaybeSharedArrayBuffer& aSrc); /* * The following are utilities to convert between VideoColorSpace values to * gfx's values. */ enum class VideoColorPrimaries : uint8_t; enum class VideoMatrixCoefficients : uint8_t; enum class VideoTransferCharacteristics : uint8_t; gfx::ColorRange ToColorRange(bool aIsFullRange); gfx::YUVColorSpace ToColorSpace(VideoMatrixCoefficients aMatrix); gfx::TransferFunction ToTransferFunction( VideoTransferCharacteristics aTransfer); gfx::ColorSpace2 ToPrimaries(VideoColorPrimaries aPrimaries); bool ToFullRange(const gfx::ColorRange& aColorRange); Maybe ToMatrixCoefficients( const gfx::YUVColorSpace& aColorSpace); Maybe ToTransferCharacteristics( const gfx::TransferFunction& aTransferFunction); Maybe ToPrimaries(const gfx::ColorSpace2& aColorSpace); /* * The following are utilities to convert from gfx's formats to * VideoPixelFormats. */ enum class ImageBitmapFormat : uint8_t; enum class VideoPixelFormat : uint8_t; Maybe SurfaceFormatToVideoPixelFormat( gfx::SurfaceFormat aFormat); Maybe ImageBitmapFormatToVideoPixelFormat( ImageBitmapFormat aFormat); } // namespace dom } // namespace mozilla #endif // MOZILLA_DOM_WEBCODECS_WEBCODECSUTILS_H