diff options
Diffstat (limited to 'dom/canvas/ImageBitmap.cpp')
-rw-r--r-- | dom/canvas/ImageBitmap.cpp | 27 |
1 files changed, 13 insertions, 14 deletions
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> 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> 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> ImageBitmap::CreateInternal( return nullptr; } - bool needToReportMemoryAllocation = true; + bool needToReportMemoryAllocation = false; return CreateImageBitmapInternal(aGlobal, surface, aCropRect, aOptions, writeOnly, needToReportMemoryAllocation, |