From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- dom/canvas/ImageBitmap.cpp | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) (limited to 'dom/canvas/ImageBitmap.cpp') diff --git a/dom/canvas/ImageBitmap.cpp b/dom/canvas/ImageBitmap.cpp index 65a9feaa56..28641a1c68 100644 --- a/dom/canvas/ImageBitmap.cpp +++ b/dom/canvas/ImageBitmap.cpp @@ -5,6 +5,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ #include "mozilla/dom/ImageBitmap.h" +#include "mozilla/AppShutdown.h" #include "mozilla/CheckedInt.h" #include "mozilla/dom/BlobImpl.h" #include "mozilla/dom/CanvasRenderingContext2D.h" @@ -362,6 +363,7 @@ static DataSourceSurface* FlipYDataSourceSurface(DataSourceSurface* aSurface) { return nullptr; } + const int bpp = BytesPerPixel(aSurface->GetFormat()); const IntSize srcSize = aSurface->GetSize(); uint8_t* srcBufferPtr = srcMap.GetData(); const uint32_t stride = srcMap.GetStride(); @@ -372,7 +374,8 @@ static DataSourceSurface* FlipYDataSourceSurface(DataSourceSurface* aSurface) { } for (int i = 0; i < srcSize.height / 2; ++i) { - std::swap_ranges(srcBufferPtr + stride * i, srcBufferPtr + stride * (i + 1), + std::swap_ranges(srcBufferPtr + stride * i, + srcBufferPtr + stride * i + srcSize.width * bpp, srcBufferPtr + stride * (srcSize.height - 1 - i)); } @@ -1018,7 +1021,6 @@ already_AddRefed ImageBitmap::CreateImageBitmapInternal( // handle alpha premultiplication if surface not of correct type gfxAlphaType alphaType = aAlphaType; - bool mustCopy = aMustCopy; bool requiresPremultiply = false; bool requiresUnpremultiply = false; @@ -1027,29 +1029,26 @@ already_AddRefed ImageBitmap::CreateImageBitmapInternal( aOptions.mPremultiplyAlpha == PremultiplyAlpha::None) { requiresUnpremultiply = true; alphaType = gfxAlphaType::NonPremult; - if (!aAllocatedImageData) { - mustCopy = true; - } } else if (aAlphaType == gfxAlphaType::NonPremult && aOptions.mPremultiplyAlpha == PremultiplyAlpha::Premultiply) { requiresPremultiply = true; alphaType = gfxAlphaType::Premult; - if (!aAllocatedImageData) { - mustCopy = true; - } } } /* - * if we don't own the data and need to create a new buffer to flip Y. + * if we don't own the data and need to modify the buffer. * or * we need to crop and flip, where crop must come first. * or - * Or the caller demands a copy (WebGL contexts). + * the caller demands a copy (WebGL contexts). */ - if ((aOptions.mImageOrientation == ImageOrientation::FlipY && - (!aAllocatedImageData || aCropRect.isSome())) || - mustCopy) { + bool willModify = aOptions.mImageOrientation == ImageOrientation::FlipY || + requiresPremultiply || requiresUnpremultiply; + if ((willModify && !aAllocatedImageData) || + (aOptions.mImageOrientation == ImageOrientation::FlipY && + aCropRect.isSome()) || + aMustCopy) { dataSurface = surface->GetDataSurface(); dataSurface = CropAndCopyDataSourceSurface(dataSurface, cropRect); @@ -1430,7 +1429,7 @@ already_AddRefed ImageBitmap::CreateInternal( return nullptr; } - bool needToReportMemoryAllocation = true; + bool needToReportMemoryAllocation = false; return CreateImageBitmapInternal(aGlobal, surface, aCropRect, aOptions, writeOnly, needToReportMemoryAllocation, -- cgit v1.2.3