Bug 1907121 - Move YCbCrUtils API assertions to caller side r=gfx-reviewers,nical
Initially, the YCbCrUtils and yuv_convert APIs asserted success internally. With recent changes, those assertions were removed. This patch reintroduces those assertions on the caller's side instead, except the `ConvertToRGBA` in ImageConversion.cpp. Differential Revision: https://phabricator.services.mozilla.com/D216191
This commit is contained in:
@@ -366,8 +366,12 @@ nsresult ImageEncoder::ExtractDataInternal(
|
|||||||
}
|
}
|
||||||
data.SetCapacity(length);
|
data.SetCapacity(length);
|
||||||
|
|
||||||
ConvertYCbCrToRGB(*ycbcrImage->GetData(), format, aSize.ToUnknownSize(),
|
rv = ConvertYCbCrToRGB(*ycbcrImage->GetData(), format,
|
||||||
data.Elements(), stride);
|
aSize.ToUnknownSize(), data.Elements(), stride);
|
||||||
|
if (NS_FAILED(rv)) {
|
||||||
|
MOZ_ASSERT_UNREACHABLE("Failed to convert YUV into RGB data");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
|
|
||||||
rv = aEncoder->InitFromData(data.Elements(),
|
rv = aEncoder->InitFromData(data.Elements(),
|
||||||
aSize.width * aSize.height * 4, aSize.width,
|
aSize.width * aSize.height * 4, aSize.width,
|
||||||
|
|||||||
@@ -275,8 +275,12 @@ nsresult ConvertToRGBA(Image* aImage, const SurfaceFormat& aDestFormat,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ConvertYCbCrToRGB32(*data, convertedFormat, aDestBuffer,
|
nsresult result =
|
||||||
AssertedCast<int32_t>(aDestStride), premultOp);
|
ConvertYCbCrToRGB32(*data, convertedFormat, aDestBuffer,
|
||||||
|
AssertedCast<int32_t>(aDestStride), premultOp);
|
||||||
|
if (NS_FAILED(result)) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
if (convertedFormat == aDestFormat) {
|
if (convertedFormat == aDestFormat) {
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
|
|||||||
@@ -448,12 +448,16 @@ already_AddRefed<VideoData> VideoData::CreateAndCopyData(
|
|||||||
|
|
||||||
// The naming convention for libyuv and associated utils is word-order.
|
// The naming convention for libyuv and associated utils is word-order.
|
||||||
// The naming convention in the gfx stack is byte-order.
|
// The naming convention in the gfx stack is byte-order.
|
||||||
ConvertI420AlphaToARGB(aBuffer.mPlanes[0].mData, aBuffer.mPlanes[1].mData,
|
nsresult result = ConvertI420AlphaToARGB(
|
||||||
aBuffer.mPlanes[2].mData, aAlphaPlane.mData,
|
aBuffer.mPlanes[0].mData, aBuffer.mPlanes[1].mData,
|
||||||
AssertedCast<int>(aBuffer.mPlanes[0].mStride),
|
aBuffer.mPlanes[2].mData, aAlphaPlane.mData,
|
||||||
AssertedCast<int>(aBuffer.mPlanes[1].mStride),
|
AssertedCast<int>(aBuffer.mPlanes[0].mStride),
|
||||||
buffer.data, buffer.stride, buffer.size.width,
|
AssertedCast<int>(aBuffer.mPlanes[1].mStride), buffer.data, buffer.stride,
|
||||||
buffer.size.height);
|
buffer.size.width, buffer.size.height);
|
||||||
|
if (NS_FAILED(result)) {
|
||||||
|
MOZ_ASSERT_UNREACHABLE("Failed to convert I420 YUVA into RGBA data");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
return v.forget();
|
return v.forget();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -689,8 +689,9 @@ nsresult PlanarYCbCrImage::BuildSurfaceDescriptorBuffer(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::ConvertYCbCrToRGB(mData, format, size, buffer, stride);
|
rv = gfx::ConvertYCbCrToRGB(mData, format, size, buffer, stride);
|
||||||
return NS_OK;
|
MOZ_ASSERT(NS_SUCCEEDED(rv), "Failed to convert YUV into RGB data");
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto ySize = pdata->YDataSize();
|
auto ySize = pdata->YDataSize();
|
||||||
@@ -878,8 +879,11 @@ already_AddRefed<gfx::SourceSurface> PlanarYCbCrImage::GetAsSourceSurface() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::ConvertYCbCrToRGB(mData, format, size, mapping.GetData(),
|
if (NS_WARN_IF(NS_FAILED(gfx::ConvertYCbCrToRGB(
|
||||||
mapping.GetStride());
|
mData, format, size, mapping.GetData(), mapping.GetStride())))) {
|
||||||
|
MOZ_ASSERT_UNREACHABLE("Failed to convert YUV into RGB data");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
mSourceSurface = surface;
|
mSourceSurface = surface;
|
||||||
|
|
||||||
@@ -957,8 +961,11 @@ already_AddRefed<SourceSurface> NVImage::GetAsSourceSurface() {
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::ConvertYCbCrToRGB(aData, format, size, mapping.GetData(),
|
if (NS_WARN_IF(NS_FAILED(gfx::ConvertYCbCrToRGB(
|
||||||
mapping.GetStride());
|
aData, format, size, mapping.GetData(), mapping.GetStride())))) {
|
||||||
|
MOZ_ASSERT_UNREACHABLE("Failed to convert YUV into RGB data");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
mSourceSurface = surface;
|
mSourceSurface = surface;
|
||||||
|
|
||||||
@@ -1025,7 +1032,11 @@ nsresult NVImage::BuildSurfaceDescriptorBuffer(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!mSourceSurface) {
|
if (!mSourceSurface) {
|
||||||
gfx::ConvertYCbCrToRGB(aData, format, size, output, stride);
|
rv = gfx::ConvertYCbCrToRGB(aData, format, size, output, stride);
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
|
MOZ_ASSERT_UNREACHABLE("Failed to convert YUV into RGB data");
|
||||||
|
return rv;
|
||||||
|
}
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "YCbCrUtils.h" // for YCbCr conversions
|
#include "YCbCrUtils.h" // for YCbCr conversions
|
||||||
#include "gfx2DGlue.h" // for SurfaceFormatToImageFormat
|
#include "gfx2DGlue.h" // for SurfaceFormatToImageFormat
|
||||||
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
#include "mozilla/Assertions.h" // for MOZ_ASSERT, etc
|
||||||
|
#include "mozilla/DebugOnly.h" // for DebugOnly
|
||||||
#include "mozilla/gfx/2D.h" // for DataSourceSurface, Factory
|
#include "mozilla/gfx/2D.h" // for DataSourceSurface, Factory
|
||||||
#include "mozilla/gfx/Logging.h" // for gfxDebug
|
#include "mozilla/gfx/Logging.h" // for gfxDebug
|
||||||
#include "mozilla/gfx/Tools.h" // for GetAlignedStride, etc
|
#include "mozilla/gfx/Tools.h" // for GetAlignedStride, etc
|
||||||
@@ -319,8 +320,12 @@ already_AddRefed<DataSourceSurface> DataSourceSurfaceFromYCbCrDescriptor(
|
|||||||
ycbcrData.mColorDepth = aDescriptor.colorDepth();
|
ycbcrData.mColorDepth = aDescriptor.colorDepth();
|
||||||
ycbcrData.mChromaSubsampling = aDescriptor.chromaSubsampling();
|
ycbcrData.mChromaSubsampling = aDescriptor.chromaSubsampling();
|
||||||
|
|
||||||
gfx::ConvertYCbCrToRGB(ycbcrData, gfx::SurfaceFormat::B8G8R8X8, size,
|
if (NS_WARN_IF(NS_FAILED(
|
||||||
map.mData, map.mStride);
|
gfx::ConvertYCbCrToRGB(ycbcrData, gfx::SurfaceFormat::B8G8R8X8, size,
|
||||||
|
map.mData, map.mStride)))) {
|
||||||
|
MOZ_ASSERT_UNREACHABLE("Failed to convert YUV into RGB data");
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
result->Unmap();
|
result->Unmap();
|
||||||
return result.forget();
|
return result.forget();
|
||||||
@@ -345,8 +350,9 @@ void ConvertAndScaleFromYCbCrDescriptor(uint8_t* aBuffer,
|
|||||||
ycbcrData.mColorDepth = aDescriptor.colorDepth();
|
ycbcrData.mColorDepth = aDescriptor.colorDepth();
|
||||||
ycbcrData.mChromaSubsampling = aDescriptor.chromaSubsampling();
|
ycbcrData.mChromaSubsampling = aDescriptor.chromaSubsampling();
|
||||||
|
|
||||||
gfx::ConvertYCbCrToRGB(ycbcrData, aDestFormat, aDestSize, aDestBuffer,
|
DebugOnly<nsresult> result = gfx::ConvertYCbCrToRGB(
|
||||||
aStride);
|
ycbcrData, aDestFormat, aDestSize, aDestBuffer, aStride);
|
||||||
|
MOZ_ASSERT(NS_SUCCEEDED(result), "Failed to convert YUV into RGB data");
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::IntSize GetCroppedCbCrSize(const YCbCrDescriptor& aDescriptor) {
|
gfx::IntSize GetCroppedCbCrSize(const YCbCrDescriptor& aDescriptor) {
|
||||||
|
|||||||
@@ -72,8 +72,13 @@ static nsresult CopyFromLockedMacIOSurface(MacIOSurface* aSurface,
|
|||||||
: gfx::ColorRange::LIMITED;
|
: gfx::ColorRange::LIMITED;
|
||||||
data.mChromaSubsampling = ChromaSubsampling::HALF_WIDTH_AND_HEIGHT;
|
data.mChromaSubsampling = ChromaSubsampling::HALF_WIDTH_AND_HEIGHT;
|
||||||
|
|
||||||
ConvertYCbCrToRGB(data, SurfaceFormat::B8G8R8X8, aSize, aData, aStride);
|
nsresult result =
|
||||||
} else if (ioFormat == SurfaceFormat::YUV422) {
|
ConvertYCbCrToRGB(data, SurfaceFormat::B8G8R8X8, aSize, aData, aStride);
|
||||||
|
MOZ_ASSERT(NS_SUCCEEDED(result), "Failed to convert YUV into RGB data");
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ioFormat == SurfaceFormat::YUV422) {
|
||||||
if (aSize.width == ALIGNED_32(aSize.width)) {
|
if (aSize.width == ALIGNED_32(aSize.width)) {
|
||||||
// Optimization when width is aligned to 32.
|
// Optimization when width is aligned to 32.
|
||||||
libyuv::ConvertToARGB((uint8_t*)aSurface->GetBaseAddress(),
|
libyuv::ConvertToARGB((uint8_t*)aSurface->GetBaseAddress(),
|
||||||
@@ -135,7 +140,10 @@ static nsresult CopyFromLockedMacIOSurface(MacIOSurface* aSurface,
|
|||||||
: gfx::ColorRange::LIMITED;
|
: gfx::ColorRange::LIMITED;
|
||||||
data.mChromaSubsampling = ChromaSubsampling::HALF_WIDTH;
|
data.mChromaSubsampling = ChromaSubsampling::HALF_WIDTH;
|
||||||
|
|
||||||
ConvertYCbCrToRGB(data, SurfaceFormat::B8G8R8X8, aSize, aData, aStride);
|
nsresult result = ConvertYCbCrToRGB(data, SurfaceFormat::B8G8R8X8, aSize,
|
||||||
|
aData, aStride);
|
||||||
|
MOZ_ASSERT(NS_SUCCEEDED(result), "Failed to convert YUV into RGB data");
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
unsigned char* ioData = (unsigned char*)aSurface->GetBaseAddress();
|
unsigned char* ioData = (unsigned char*)aSurface->GetBaseAddress();
|
||||||
|
|||||||
@@ -1922,8 +1922,9 @@ nsAVIFDecoder::DecodeResult nsAVIFDecoder::DoDecodeInternal(
|
|||||||
MOZ_LOG(sAVIFLog, LogLevel::Debug,
|
MOZ_LOG(sAVIFLog, LogLevel::Debug,
|
||||||
("[this=%p] calling gfx::ConvertYCbCrToRGB32 premultOp: %p", this,
|
("[this=%p] calling gfx::ConvertYCbCrToRGB32 premultOp: %p", this,
|
||||||
premultOp));
|
premultOp));
|
||||||
gfx::ConvertYCbCrToRGB32(*decodedData, format, rgbBuf.get(),
|
DebugOnly<nsresult> result = gfx::ConvertYCbCrToRGB32(
|
||||||
rgbStride.value(), premultOp);
|
*decodedData, format, rgbBuf.get(), rgbStride.value(), premultOp);
|
||||||
|
MOZ_ASSERT(NS_SUCCEEDED(result), "Failed to convert YUV into RGB data");
|
||||||
|
|
||||||
MOZ_LOG(sAVIFLog, LogLevel::Debug,
|
MOZ_LOG(sAVIFLog, LogLevel::Debug,
|
||||||
("[this=%p] calling SurfacePipeFactory::CreateSurfacePipe", this));
|
("[this=%p] calling SurfacePipeFactory::CreateSurfacePipe", this));
|
||||||
|
|||||||
Reference in New Issue
Block a user