diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 98b8a872a345..cd8816120917 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -6967,17 +6967,15 @@ void nsGlobalWindowInner::FireOnNewGlobalObject() { #endif already_AddRefed nsGlobalWindowInner::CreateImageBitmap( - JSContext* aCx, const ImageBitmapSource& aImage, - const ImageBitmapOptions& aOptions, ErrorResult& aRv) { - return ImageBitmap::Create(this, aImage, Nothing(), aOptions, aRv); + JSContext* aCx, const ImageBitmapSource& aImage, ErrorResult& aRv) { + return ImageBitmap::Create(this, aImage, Nothing(), aRv); } already_AddRefed nsGlobalWindowInner::CreateImageBitmap( JSContext* aCx, const ImageBitmapSource& aImage, int32_t aSx, int32_t aSy, - int32_t aSw, int32_t aSh, const ImageBitmapOptions& aOptions, - ErrorResult& aRv) { - return ImageBitmap::Create( - this, aImage, Some(gfx::IntRect(aSx, aSy, aSw, aSh)), aOptions, aRv); + int32_t aSw, int32_t aSh, ErrorResult& aRv) { + return ImageBitmap::Create(this, aImage, + Some(gfx::IntRect(aSx, aSy, aSw, aSh)), aRv); } mozilla::dom::TabGroup* nsGlobalWindowInner::TabGroupInner() { diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index 68710f3154ec..6c63178fcc53 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -56,7 +56,6 @@ #include "nsComponentManagerUtils.h" #include "nsSize.h" #include "nsCheapSets.h" -#include "mozilla/dom/ImageBitmapBinding.h" #include "mozilla/dom/ImageBitmapSource.h" #include "mozilla/UniquePtr.h" #include "nsRefreshDriver.h" @@ -884,13 +883,11 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget, already_AddRefed CreateImageBitmap( JSContext* aCx, const mozilla::dom::ImageBitmapSource& aImage, - const mozilla::dom::ImageBitmapOptions& aOptions, mozilla::ErrorResult& aRv); already_AddRefed CreateImageBitmap( JSContext* aCx, const mozilla::dom::ImageBitmapSource& aImage, int32_t aSx, int32_t aSy, int32_t aSw, int32_t aSh, - const mozilla::dom::ImageBitmapOptions& aOptions, mozilla::ErrorResult& aRv); // ChromeWindow bits. Do NOT call these unless your window is in @@ -1444,7 +1441,6 @@ class nsGlobalWindowInner final : public mozilla::dom::EventTarget, NS_IMETHOD Run() override { if (mInner) { - ; RefPtr inner = std::move(mInner); inner->Run(); } diff --git a/dom/canvas/ImageBitmap.cpp b/dom/canvas/ImageBitmap.cpp index 0f051abe9643..317e06b25f42 100644 --- a/dom/canvas/ImageBitmap.cpp +++ b/dom/canvas/ImageBitmap.cpp @@ -257,32 +257,6 @@ static already_AddRefed CropAndCopyDataSourceSurface( return dstDataSurface.forget(); } -static DataSourceSurface* FlipYDataSourceSurface(DataSourceSurface* aSurface) { - MOZ_ASSERT(aSurface); - - // Invert in y direction. - DataSourceSurface::ScopedMap srcMap(aSurface, DataSourceSurface::READ_WRITE); - if (NS_WARN_IF(!srcMap.IsMapped())) { - return nullptr; - } - - const IntSize srcSize = aSurface->GetSize(); - uint8_t* srcBufferPtr = srcMap.GetData(); - const uint32_t stride = srcMap.GetStride(); - - CheckedInt copiedBytesPerRaw = CheckedInt(stride); - if (!copiedBytesPerRaw.isValid()) { - return nullptr; - } - - for (int i = 0; i < srcSize.height / 2; ++i) { - std::swap_ranges(srcBufferPtr + stride * i, srcBufferPtr + stride * (i + 1), - srcBufferPtr + stride * (srcSize.height - 1 - i)); - } - - return aSurface; -} - /* * Encapsulate the given _aSurface_ into a layers::SourceSurfaceImage. */ @@ -301,8 +275,7 @@ static already_AddRefed CreateImageFromSurface( */ static already_AddRefed CreateSurfaceFromRawData( const gfx::IntSize& aSize, uint32_t aStride, gfx::SurfaceFormat aFormat, - uint8_t* aBuffer, uint32_t aBufferLength, const Maybe& aCropRect, - const ImageBitmapOptions& aOptions) { + uint8_t* aBuffer, uint32_t aBufferLength, const Maybe& aCropRect) { MOZ_ASSERT(!aSize.IsEmpty()); MOZ_ASSERT(aBuffer); @@ -328,26 +301,17 @@ static already_AddRefed CreateSurfaceFromRawData( return nullptr; } - if (aOptions.mImageOrientation == ImageOrientation::FlipY) { - result = FlipYDataSourceSurface(result); - } - - if (NS_WARN_IF(!result)) { - return nullptr; - } - return result.forget(); } static already_AddRefed CreateImageFromRawData( const gfx::IntSize& aSize, uint32_t aStride, gfx::SurfaceFormat aFormat, - uint8_t* aBuffer, uint32_t aBufferLength, const Maybe& aCropRect, - const ImageBitmapOptions& aOptions) { + uint8_t* aBuffer, uint32_t aBufferLength, const Maybe& aCropRect) { MOZ_ASSERT(NS_IsMainThread()); // Copy and crop the source buffer into a SourceSurface. RefPtr rgbaSurface = CreateSurfaceFromRawData( - aSize, aStride, aFormat, aBuffer, aBufferLength, aCropRect, aOptions); + aSize, aStride, aFormat, aBuffer, aBufferLength, aCropRect); if (NS_WARN_IF(!rgbaSurface)) { return nullptr; @@ -406,8 +370,7 @@ class CreateImageFromRawDataInMainThreadSyncTask final CreateImageFromRawDataInMainThreadSyncTask( uint8_t* aBuffer, uint32_t aBufferLength, uint32_t aStride, gfx::SurfaceFormat aFormat, const gfx::IntSize& aSize, - const Maybe& aCropRect, layers::Image** aImage, - const ImageBitmapOptions& aOptions) + const Maybe& aCropRect, layers::Image** aImage) : WorkerMainThreadRunnable( GetCurrentThreadWorkerPrivate(), NS_LITERAL_CSTRING("ImageBitmap :: Create Image from Raw Data")), @@ -417,8 +380,7 @@ class CreateImageFromRawDataInMainThreadSyncTask final mStride(aStride), mFormat(aFormat), mSize(aSize), - mCropRect(aCropRect), - mOptions(aOptions) { + mCropRect(aCropRect) { MOZ_ASSERT(!(*aImage), "Don't pass an existing Image into " "CreateImageFromRawDataInMainThreadSyncTask."); @@ -426,7 +388,7 @@ class CreateImageFromRawDataInMainThreadSyncTask final bool MainThreadRun() override { RefPtr image = CreateImageFromRawData( - mSize, mStride, mFormat, mBuffer, mBufferLength, mCropRect, mOptions); + mSize, mStride, mFormat, mBuffer, mBufferLength, mCropRect); if (NS_WARN_IF(!image)) { return false; @@ -445,7 +407,6 @@ class CreateImageFromRawDataInMainThreadSyncTask final gfx::SurfaceFormat mFormat; gfx::IntSize mSize; const Maybe& mCropRect; - const ImageBitmapOptions mOptions; }; /* @@ -713,79 +674,10 @@ already_AddRefed ImageBitmap::CreateFromOffscreenCanvas( return ret.forget(); } -/* static */ -already_AddRefed ImageBitmap::CreateImageBitmapInternal( - nsIGlobalObject* aGlobal, gfx::SourceSurface* aSurface, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - const bool aWriteOnly, const bool aAllocatedImageData, const bool aMustCopy, - ErrorResult& aRv) { - bool needToReportMemoryAllocation = aAllocatedImageData; - const IntSize srcSize = aSurface->GetSize(); - IntRect cropRect = - aCropRect.valueOr(IntRect(0, 0, srcSize.width, srcSize.height)); - - RefPtr surface = aSurface; - RefPtr dataSurface; - - /* - * if we don't own the data and need to create a new buffer to flip Y. - * or - * we need to crop and flip, where crop must come first. - * or - * Or the caller demands a copy (WebGL contexts). - */ - if ((aOptions.mImageOrientation == ImageOrientation::FlipY && - (!aAllocatedImageData || aCropRect.isSome())) || - aMustCopy) { - dataSurface = surface->GetDataSurface(); - - dataSurface = CropAndCopyDataSourceSurface(dataSurface, cropRect); - if (NS_WARN_IF(!dataSurface)) { - return nullptr; - } - - surface = dataSurface; - cropRect.MoveTo(0, 0); - needToReportMemoryAllocation = true; - } - - // flip image in Y direction - if (aOptions.mImageOrientation == ImageOrientation::FlipY) { - if (!dataSurface) { - dataSurface = surface->GetDataSurface(); - }; - - surface = FlipYDataSourceSurface(dataSurface); - if (NS_WARN_IF(!surface)) { - return nullptr; - } - } - - // Create an Image from the SourceSurface. - RefPtr data = CreateImageFromSurface(surface); - - if (NS_WARN_IF(!data)) { - aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); - return nullptr; - } - - RefPtr ret = new ImageBitmap(aGlobal, data, aWriteOnly); - - if (needToReportMemoryAllocation) { - ret->mAllocatedImageData = true; - } - - // Set the picture rectangle. - ret->SetPictureRect(cropRect, aRv); - - return ret.forget(); -} - /* static */ already_AddRefed ImageBitmap::CreateInternal( nsIGlobalObject* aGlobal, HTMLImageElement& aImageEl, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv) { + const Maybe& aCropRect, ErrorResult& aRv) { // Check if the image element is completely available or not. if (!aImageEl.Complete()) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); @@ -803,18 +695,28 @@ already_AddRefed ImageBitmap::CreateInternal( return nullptr; } - bool needToReportMemoryAllocation = false; + // Create ImageBitmap. + RefPtr data = CreateImageFromSurface(surface); - return CreateImageBitmapInternal(aGlobal, surface, aCropRect, aOptions, - writeOnly, needToReportMemoryAllocation, - false, aRv); + if (NS_WARN_IF(!data)) { + aRv.Throw(NS_ERROR_NOT_AVAILABLE); + return nullptr; + } + + RefPtr ret = new ImageBitmap(aGlobal, data, writeOnly); + + // Set the picture rectangle. + if (ret && aCropRect.isSome()) { + ret->SetPictureRect(aCropRect.ref(), aRv); + } + + return ret.forget(); } /* static */ already_AddRefed ImageBitmap::CreateInternal( nsIGlobalObject* aGlobal, SVGImageElement& aImageEl, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv) { + const Maybe& aCropRect, ErrorResult& aRv) { bool writeOnly = true; // Get the SourceSurface out from the image element and then do security @@ -826,18 +728,28 @@ already_AddRefed ImageBitmap::CreateInternal( return nullptr; } - bool needToReportMemoryAllocation = false; + // Create ImageBitmap. + RefPtr data = CreateImageFromSurface(surface); - return CreateImageBitmapInternal(aGlobal, surface, aCropRect, aOptions, - writeOnly, needToReportMemoryAllocation, - false, aRv); + if (NS_WARN_IF(!data)) { + aRv.Throw(NS_ERROR_NOT_AVAILABLE); + return nullptr; + } + + RefPtr ret = new ImageBitmap(aGlobal, data, writeOnly); + + // Set the picture rectangle. + if (ret && aCropRect.isSome()) { + ret->SetPictureRect(aCropRect.ref(), aRv); + } + + return ret.forget(); } /* static */ already_AddRefed ImageBitmap::CreateInternal( nsIGlobalObject* aGlobal, HTMLVideoElement& aVideoEl, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv) { + const Maybe& aCropRect, ErrorResult& aRv) { aVideoEl.MarkAsContentSource( mozilla::dom::HTMLVideoElement::CallerAPI::CREATE_IMAGEBITMAP); @@ -868,21 +780,20 @@ already_AddRefed ImageBitmap::CreateInternal( aRv.Throw(NS_ERROR_NOT_AVAILABLE); return nullptr; } + RefPtr ret = new ImageBitmap(aGlobal, data, writeOnly); - RefPtr surface = data->GetAsSourceSurface(); + // Set the picture rectangle. + if (ret && aCropRect.isSome()) { + ret->SetPictureRect(aCropRect.ref(), aRv); + } - bool needToReportMemoryAllocation = false; - - return CreateImageBitmapInternal(aGlobal, surface, aCropRect, aOptions, - writeOnly, needToReportMemoryAllocation, - false, aRv); + return ret.forget(); } /* static */ already_AddRefed ImageBitmap::CreateInternal( nsIGlobalObject* aGlobal, HTMLCanvasElement& aCanvasEl, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv) { + const Maybe& aCropRect, ErrorResult& aRv) { if (aCanvasEl.Width() == 0 || aCanvasEl.Height() == 0) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return nullptr; @@ -900,28 +811,56 @@ already_AddRefed ImageBitmap::CreateInternal( writeOnly = aCanvasEl.IsWriteOnly(); } + // Crop the source surface if needed. + RefPtr croppedSurface; + IntRect cropRect = aCropRect.valueOr(IntRect()); + // If the HTMLCanvasElement's rendering context is WebGL, then the snapshot // we got from the HTMLCanvasElement is a DataSourceSurface which is a copy // of the rendering context. We handle cropping in this case. bool needToReportMemoryAllocation = false; - bool mustCopy = false; - if ((aCanvasEl.GetCurrentContextType() == CanvasContextType::WebGL1 || aCanvasEl.GetCurrentContextType() == CanvasContextType::WebGL2) && aCropRect.isSome()) { - mustCopy = true; + RefPtr dataSurface = surface->GetDataSurface(); + croppedSurface = CropAndCopyDataSourceSurface(dataSurface, cropRect); + cropRect.MoveTo(0, 0); + needToReportMemoryAllocation = true; + } else { + croppedSurface = surface; } - return CreateImageBitmapInternal(aGlobal, surface, aCropRect, aOptions, - writeOnly, needToReportMemoryAllocation, - mustCopy, aRv); + if (NS_WARN_IF(!croppedSurface)) { + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return nullptr; + } + + // Create an Image from the SourceSurface. + RefPtr data = CreateImageFromSurface(croppedSurface); + + if (NS_WARN_IF(!data)) { + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); + return nullptr; + } + + RefPtr ret = new ImageBitmap(aGlobal, data, writeOnly); + + if (needToReportMemoryAllocation) { + ret->mAllocatedImageData = true; + } + + // Set the picture rectangle. + if (ret && aCropRect.isSome()) { + ret->SetPictureRect(cropRect, aRv); + } + + return ret.forget(); } /* static */ already_AddRefed ImageBitmap::CreateInternal( nsIGlobalObject* aGlobal, ImageData& aImageData, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv) { + const Maybe& aCropRect, ErrorResult& aRv) { // Copy data into SourceSurface. dom::Uint8ClampedArray array; DebugOnly inited = array.Init(aImageData.GetDataObject()); @@ -949,12 +888,12 @@ already_AddRefed ImageBitmap::CreateInternal( RefPtr data; if (NS_IsMainThread()) { data = CreateImageFromRawData(imageSize, imageStride, FORMAT, array.Data(), - dataLength, aCropRect, aOptions); + dataLength, aCropRect); } else { RefPtr task = new CreateImageFromRawDataInMainThreadSyncTask( array.Data(), dataLength, imageStride, FORMAT, imageSize, aCropRect, - getter_AddRefs(data), aOptions); + getter_AddRefs(data)); task->Dispatch(Canceling, aRv); } @@ -978,8 +917,7 @@ already_AddRefed ImageBitmap::CreateInternal( /* static */ already_AddRefed ImageBitmap::CreateInternal( nsIGlobalObject* aGlobal, CanvasRenderingContext2D& aCanvasCtx, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv) { + const Maybe& aCropRect, ErrorResult& aRv) { nsCOMPtr win = do_QueryInterface(aGlobal); nsGlobalWindowInner* window = nsGlobalWindowInner::Cast(win); if (NS_WARN_IF(!window) || !window->GetExtantDoc()) { @@ -1007,32 +945,44 @@ already_AddRefed ImageBitmap::CreateInternal( return nullptr; } - bool needToReportMemoryAllocation = true; + RefPtr data = CreateImageFromSurface(surface); - return CreateImageBitmapInternal(aGlobal, surface, aCropRect, aOptions, - writeOnly, needToReportMemoryAllocation, - false, aRv); + if (NS_WARN_IF(!data)) { + aRv.Throw(NS_ERROR_NOT_AVAILABLE); + return nullptr; + } + + RefPtr ret = new ImageBitmap(aGlobal, data, writeOnly); + + ret->mAllocatedImageData = true; + + // Set the picture rectangle. + if (ret && aCropRect.isSome()) { + ret->SetPictureRect(aCropRect.ref(), aRv); + } + + return ret.forget(); } /* static */ already_AddRefed ImageBitmap::CreateInternal( nsIGlobalObject* aGlobal, ImageBitmap& aImageBitmap, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv) { + const Maybe& aCropRect, ErrorResult& aRv) { if (!aImageBitmap.mData) { aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); return nullptr; } RefPtr data = aImageBitmap.mData; + RefPtr ret = new ImageBitmap( + aGlobal, data, aImageBitmap.mWriteOnly, aImageBitmap.mAlphaType); - RefPtr surface = data->GetAsSourceSurface(); + // Set the picture rectangle. + if (ret && aCropRect.isSome()) { + ret->SetPictureRect(aCropRect.ref(), aRv); + } - bool needToReportMemoryAllocation = false; - - return CreateImageBitmapInternal(aGlobal, surface, aCropRect, aOptions, - aImageBitmap.mWriteOnly, - needToReportMemoryAllocation, false, aRv); + return ret.forget(); } class FulfillImageBitmapPromise { @@ -1104,8 +1054,7 @@ class CreateImageBitmapFromBlob final : public CancelableRunnable, static already_AddRefed Create( Promise* aPromise, nsIGlobalObject* aGlobal, Blob& aBlob, - const Maybe& aCropRect, nsIEventTarget* aMainThreadEventTarget, - const ImageBitmapOptions& aOptions); + const Maybe& aCropRect, nsIEventTarget* aMainThreadEventTarget); NS_IMETHOD Run() override { MOZ_ASSERT(IsCurrentThread()); @@ -1125,8 +1074,7 @@ class CreateImageBitmapFromBlob final : public CancelableRunnable, CreateImageBitmapFromBlob(Promise* aPromise, nsIGlobalObject* aGlobal, already_AddRefed aInputStream, const Maybe& aCropRect, - nsIEventTarget* aMainThreadEventTarget, - const ImageBitmapOptions& aOptions) + nsIEventTarget* aMainThreadEventTarget) : CancelableRunnable("dom::CreateImageBitmapFromBlob"), mMutex("dom::CreateImageBitmapFromBlob::mMutex"), mPromise(aPromise), @@ -1135,7 +1083,6 @@ class CreateImageBitmapFromBlob final : public CancelableRunnable, mCropRect(aCropRect), mOriginalCropRect(aCropRect), mMainThreadEventTarget(aMainThreadEventTarget), - mFlipY(aOptions.mImageOrientation == ImageOrientation::FlipY), mThread(GetCurrentVirtualThread()) {} virtual ~CreateImageBitmapFromBlob() {} @@ -1183,8 +1130,8 @@ class CreateImageBitmapFromBlob final : public CancelableRunnable, Maybe mCropRect; Maybe mOriginalCropRect; IntSize mSourceSize; + nsCOMPtr mMainThreadEventTarget; - const bool mFlipY; void* mThread; }; @@ -1216,8 +1163,7 @@ class CreateImageBitmapFromBlobRunnable : public WorkerRunnable { static void AsyncCreateImageBitmapFromBlob(Promise* aPromise, nsIGlobalObject* aGlobal, Blob& aBlob, - const Maybe& aCropRect, - const ImageBitmapOptions& aOptions) { + const Maybe& aCropRect) { // Let's identify the main-thread event target. nsCOMPtr mainThreadEventTarget; if (NS_IsMainThread()) { @@ -1229,7 +1175,7 @@ static void AsyncCreateImageBitmapFromBlob(Promise* aPromise, } RefPtr task = CreateImageBitmapFromBlob::Create( - aPromise, aGlobal, aBlob, aCropRect, mainThreadEventTarget, aOptions); + aPromise, aGlobal, aBlob, aCropRect, mainThreadEventTarget); if (NS_WARN_IF(!task)) { aPromise->MaybeReject(NS_ERROR_DOM_INVALID_STATE_ERR); return; @@ -1241,8 +1187,7 @@ static void AsyncCreateImageBitmapFromBlob(Promise* aPromise, /* static */ already_AddRefed ImageBitmap::Create( nsIGlobalObject* aGlobal, const ImageBitmapSource& aSrc, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv) { + const Maybe& aCropRect, ErrorResult& aRv) { MOZ_ASSERT(aGlobal); RefPtr promise = Promise::Create(aGlobal, aRv); @@ -1271,41 +1216,41 @@ already_AddRefed ImageBitmap::Create( MOZ_ASSERT( NS_IsMainThread(), "Creating ImageBitmap from HTMLImageElement off the main thread."); - imageBitmap = CreateInternal(aGlobal, aSrc.GetAsHTMLImageElement(), - aCropRect, aOptions, aRv); + imageBitmap = + CreateInternal(aGlobal, aSrc.GetAsHTMLImageElement(), aCropRect, aRv); } else if (aSrc.IsSVGImageElement()) { MOZ_ASSERT( NS_IsMainThread(), "Creating ImageBitmap from SVGImageElement off the main thread."); - imageBitmap = CreateInternal(aGlobal, aSrc.GetAsSVGImageElement(), - aCropRect, aOptions, aRv); + imageBitmap = + CreateInternal(aGlobal, aSrc.GetAsSVGImageElement(), aCropRect, aRv); } else if (aSrc.IsHTMLVideoElement()) { MOZ_ASSERT( NS_IsMainThread(), "Creating ImageBitmap from HTMLVideoElement off the main thread."); - imageBitmap = CreateInternal(aGlobal, aSrc.GetAsHTMLVideoElement(), - aCropRect, aOptions, aRv); + imageBitmap = + CreateInternal(aGlobal, aSrc.GetAsHTMLVideoElement(), aCropRect, aRv); } else if (aSrc.IsHTMLCanvasElement()) { MOZ_ASSERT( NS_IsMainThread(), "Creating ImageBitmap from HTMLCanvasElement off the main thread."); - imageBitmap = CreateInternal(aGlobal, aSrc.GetAsHTMLCanvasElement(), - aCropRect, aOptions, aRv); + imageBitmap = + CreateInternal(aGlobal, aSrc.GetAsHTMLCanvasElement(), aCropRect, aRv); } else if (aSrc.IsImageData()) { - imageBitmap = CreateInternal(aGlobal, aSrc.GetAsImageData(), aCropRect, - aOptions, aRv); + imageBitmap = + CreateInternal(aGlobal, aSrc.GetAsImageData(), aCropRect, aRv); } else if (aSrc.IsCanvasRenderingContext2D()) { MOZ_ASSERT(NS_IsMainThread(), "Creating ImageBitmap from CanvasRenderingContext2D off the " "main thread."); imageBitmap = CreateInternal(aGlobal, aSrc.GetAsCanvasRenderingContext2D(), - aCropRect, aOptions, aRv); + aCropRect, aRv); } else if (aSrc.IsImageBitmap()) { - imageBitmap = CreateInternal(aGlobal, aSrc.GetAsImageBitmap(), aCropRect, - aOptions, aRv); + imageBitmap = + CreateInternal(aGlobal, aSrc.GetAsImageBitmap(), aCropRect, aRv); } else if (aSrc.IsBlob()) { AsyncCreateImageBitmapFromBlob(promise, aGlobal, aSrc.GetAsBlob(), - aCropRect, aOptions); + aCropRect); return promise.forget(); } else { MOZ_CRASH("Unsupported type!"); @@ -1462,8 +1407,7 @@ size_t BindingJSObjectMallocBytes(ImageBitmap* aBitmap) { /* static */ already_AddRefed CreateImageBitmapFromBlob::Create( Promise* aPromise, nsIGlobalObject* aGlobal, Blob& aBlob, - const Maybe& aCropRect, nsIEventTarget* aMainThreadEventTarget, - const ImageBitmapOptions& aOptions) { + const Maybe& aCropRect, nsIEventTarget* aMainThreadEventTarget) { // Get the internal stream of the blob. nsCOMPtr stream; ErrorResult error; @@ -1484,8 +1428,7 @@ already_AddRefed CreateImageBitmapFromBlob::Create( } RefPtr task = new CreateImageBitmapFromBlob( - aPromise, aGlobal, stream.forget(), aCropRect, aMainThreadEventTarget, - aOptions); + aPromise, aGlobal, stream.forget(), aCropRect, aMainThreadEventTarget); // Nothing to do for the main-thread. if (NS_IsMainThread()) { @@ -1633,7 +1576,6 @@ CreateImageBitmapFromBlob::OnImageReady(imgIContainer* aImgContainer, // Crop the source surface if needed. RefPtr croppedSurface = surface; - RefPtr dataSurface = surface->GetDataSurface(); if (mCropRect.isSome()) { // The blob is just decoded into a RasterImage and not optimized yet, so the @@ -1648,22 +1590,11 @@ CreateImageBitmapFromBlob::OnImageReady(imgIContainer* aImgContainer, // TODO: Bug1189632 is going to refactor this create-from-blob part to // decode the blob off the main thread. Re-check if we should do // cropping at this moment again there. - + RefPtr dataSurface = surface->GetDataSurface(); croppedSurface = CropAndCopyDataSourceSurface(dataSurface, mCropRect.ref()); - if (NS_WARN_IF(!croppedSurface)) { - MimeTypeAndDecodeAndCropBlobCompletedMainThread( - nullptr, NS_ERROR_DOM_INVALID_STATE_ERR); - return NS_OK; - } - - dataSurface = croppedSurface->GetDataSurface(); mCropRect->MoveTo(0, 0); } - if (mFlipY) { - croppedSurface = FlipYDataSourceSurface(dataSurface); - } - if (NS_WARN_IF(!croppedSurface)) { MimeTypeAndDecodeAndCropBlobCompletedMainThread( nullptr, NS_ERROR_DOM_INVALID_STATE_ERR); diff --git a/dom/canvas/ImageBitmap.h b/dom/canvas/ImageBitmap.h index d66c7ac296d5..f11fc8ccc0c5 100644 --- a/dom/canvas/ImageBitmap.h +++ b/dom/canvas/ImageBitmap.h @@ -8,7 +8,6 @@ #define mozilla_dom_ImageBitmap_h #include "mozilla/Attributes.h" -#include "mozilla/dom/ImageBitmapBinding.h" #include "mozilla/dom/ImageBitmapSource.h" #include "mozilla/dom/TypedArray.h" #include "mozilla/gfx/Rect.h" @@ -120,7 +119,6 @@ class ImageBitmap final : public nsISupports, public nsWrapperCache { static already_AddRefed Create(nsIGlobalObject* aGlobal, const ImageBitmapSource& aSrc, const Maybe& aCropRect, - const ImageBitmapOptions& aOptions, ErrorResult& aRv); static JSObject* ReadStructuredClone( @@ -171,46 +169,33 @@ class ImageBitmap final : public nsISupports, public nsWrapperCache { void SetPictureRect(const gfx::IntRect& aRect, ErrorResult& aRv); - static already_AddRefed CreateImageBitmapInternal( - nsIGlobalObject* aGlobal, gfx::SourceSurface* aSurface, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - const bool aWriteOnly, const bool aAllocatedImageData, - const bool aMustCopy, ErrorResult& aRv); - static already_AddRefed CreateInternal( nsIGlobalObject* aGlobal, HTMLImageElement& aImageEl, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv); + const Maybe& aCropRect, ErrorResult& aRv); static already_AddRefed CreateInternal( nsIGlobalObject* aGlobal, SVGImageElement& aImageEl, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv); + const Maybe& aCropRect, ErrorResult& aRv); static already_AddRefed CreateInternal( nsIGlobalObject* aGlobal, HTMLVideoElement& aVideoEl, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv); + const Maybe& aCropRect, ErrorResult& aRv); static already_AddRefed CreateInternal( nsIGlobalObject* aGlobal, HTMLCanvasElement& aCanvasEl, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv); + const Maybe& aCropRect, ErrorResult& aRv); static already_AddRefed CreateInternal( nsIGlobalObject* aGlobal, ImageData& aImageData, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv); + const Maybe& aCropRect, ErrorResult& aRv); static already_AddRefed CreateInternal( nsIGlobalObject* aGlobal, CanvasRenderingContext2D& aCanvasCtx, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv); + const Maybe& aCropRect, ErrorResult& aRv); static already_AddRefed CreateInternal( nsIGlobalObject* aGlobal, ImageBitmap& aImageBitmap, - const Maybe& aCropRect, const ImageBitmapOptions& aOptions, - ErrorResult& aRv); + const Maybe& aCropRect, ErrorResult& aRv); nsCOMPtr mParent; diff --git a/dom/webidl/ImageBitmap.webidl b/dom/webidl/ImageBitmap.webidl index ed92659bd078..8c27ed1a2591 100644 --- a/dom/webidl/ImageBitmap.webidl +++ b/dom/webidl/ImageBitmap.webidl @@ -386,18 +386,3 @@ dictionary ChannelPixelLayout { }; typedef sequence ImagePixelLayout; - -enum ImageOrientation { "none", "flipY" }; -//enum PremultiplyAlpha { "none", "premultiply", "default" }; -//enum ColorSpaceConversion { "none", "default" }; -//enum ResizeQuality { "pixelated", "low", "medium", "high" }; - -dictionary ImageBitmapOptions { - ImageOrientation imageOrientation = "none"; - // options to be added bugs: 1363861 - //PremultiplyAlpha premultiplyAlpha = "default"; - //ColorSpaceConversion colorSpaceConversion = "default"; - //[EnforceRange] unsigned long resizeWidth; - //[EnforceRange] unsigned long resizeHeight; - //ResizeQuality resizeQuality = "low"; -}; diff --git a/dom/webidl/WindowOrWorkerGlobalScope.webidl b/dom/webidl/WindowOrWorkerGlobalScope.webidl index af1fbee7435d..91dd66d252c9 100644 --- a/dom/webidl/WindowOrWorkerGlobalScope.webidl +++ b/dom/webidl/WindowOrWorkerGlobalScope.webidl @@ -40,9 +40,9 @@ interface mixin WindowOrWorkerGlobalScope { // ImageBitmap [Throws] - Promise createImageBitmap(ImageBitmapSource aImage, optional ImageBitmapOptions aOptions = {}); + Promise createImageBitmap(ImageBitmapSource aImage); [Throws] - Promise createImageBitmap(ImageBitmapSource aImage, long aSx, long aSy, long aSw, long aSh, optional ImageBitmapOptions aOptions = {}); + Promise createImageBitmap(ImageBitmapSource aImage, long aSx, long aSy, long aSw, long aSh); }; // https://fetch.spec.whatwg.org/#fetch-method diff --git a/dom/workers/WorkerScope.cpp b/dom/workers/WorkerScope.cpp index 4d3656061c91..9fac4a2fd48f 100644 --- a/dom/workers/WorkerScope.cpp +++ b/dom/workers/WorkerScope.cpp @@ -491,17 +491,15 @@ already_AddRefed WorkerGlobalScope::GetIndexedDB( } already_AddRefed WorkerGlobalScope::CreateImageBitmap( - JSContext* aCx, const ImageBitmapSource& aImage, - const ImageBitmapOptions& aOptions, ErrorResult& aRv) { - return ImageBitmap::Create(this, aImage, Nothing(), aOptions, aRv); + JSContext* aCx, const ImageBitmapSource& aImage, ErrorResult& aRv) { + return ImageBitmap::Create(this, aImage, Nothing(), aRv); } already_AddRefed WorkerGlobalScope::CreateImageBitmap( JSContext* aCx, const ImageBitmapSource& aImage, int32_t aSx, int32_t aSy, - int32_t aSw, int32_t aSh, const ImageBitmapOptions& aOptions, - ErrorResult& aRv) { - return ImageBitmap::Create( - this, aImage, Some(gfx::IntRect(aSx, aSy, aSw, aSh)), aOptions, aRv); + int32_t aSw, int32_t aSh, ErrorResult& aRv) { + return ImageBitmap::Create(this, aImage, + Some(gfx::IntRect(aSx, aSy, aSw, aSh)), aRv); } nsresult WorkerGlobalScope::Dispatch( diff --git a/dom/workers/WorkerScope.h b/dom/workers/WorkerScope.h index 671550776073..abe95123b0c6 100644 --- a/dom/workers/WorkerScope.h +++ b/dom/workers/WorkerScope.h @@ -14,7 +14,6 @@ #include "mozilla/dom/Headers.h" #include "mozilla/dom/RequestBinding.h" #include "nsWeakReference.h" -#include "mozilla/dom/ImageBitmapBinding.h" #include "mozilla/dom/ImageBitmapSource.h" #ifdef XP_WIN @@ -173,14 +172,15 @@ class WorkerGlobalScope : public DOMEventTargetHelper, bool IsSecureContext() const; - already_AddRefed CreateImageBitmap( - JSContext* aCx, const ImageBitmapSource& aImage, - const ImageBitmapOptions& aOptions, ErrorResult& aRv); + already_AddRefed CreateImageBitmap(JSContext* aCx, + const ImageBitmapSource& aImage, + ErrorResult& aRv); - already_AddRefed CreateImageBitmap( - JSContext* aCx, const ImageBitmapSource& aImage, int32_t aSx, int32_t aSy, - int32_t aSw, int32_t aSh, const ImageBitmapOptions& aOptions, - ErrorResult& aRv); + already_AddRefed CreateImageBitmap(JSContext* aCx, + const ImageBitmapSource& aImage, + int32_t aSx, int32_t aSy, + int32_t aSw, int32_t aSh, + ErrorResult& aRv); bool WindowInteractionAllowed() const { return mWindowInteractionsAllowed > 0; diff --git a/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-flipY.html.ini b/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-flipY.html.ini index 5dbfa707ce13..f9332a11de9c 100644 --- a/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-flipY.html.ini +++ b/testing/web-platform/meta/2dcontext/imagebitmap/createImageBitmap-flipY.html.ini @@ -1,7 +1,67 @@ [createImageBitmap-flipY.html] + [createImageBitmap from a vector SVGImageElement imageOrientation: "none", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from a vector SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from an HTMLCanvasElement imageOrientation: "none", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from an ImageData imageOrientation: "none", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from an HTMLVideoElement from a data URL imageOrientation: "flipY", and drawImage on the created ImageBitmap] + expected: FAIL [createImageBitmap from an OffscreenCanvas imageOrientation: "flipY", and drawImage on the created ImageBitmap] expected: FAIL + [createImageBitmap from a vector HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from an HTMLVideoElement imageOrientation: "flipY", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from a Blob imageOrientation: "flipY", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from an HTMLCanvasElement imageOrientation: "flipY", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from an HTMLVideoElement imageOrientation: "none", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from an ImageData imageOrientation: "flipY", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from a bitmap HTMLImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap] + expected: FAIL + [createImageBitmap from an OffscreenCanvas imageOrientation: "none", and drawImage on the created ImageBitmap] expected: FAIL + + [createImageBitmap from an ImageBitmap imageOrientation: "flipY", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from a vector HTMLImageElement imageOrientation: "none", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from a Blob imageOrientation: "none", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from an HTMLVideoElement from a data URL imageOrientation: "none", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from an ImageBitmap imageOrientation: "none", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from a bitmap HTMLImageElement imageOrientation: "none", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from a bitmap SVGImageElement imageOrientation: "flipY", and drawImage on the created ImageBitmap] + expected: FAIL + + [createImageBitmap from a bitmap SVGImageElement imageOrientation: "none", and drawImage on the created ImageBitmap] + expected: FAIL +