mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-09 17:31:47 +09:00
Merge remote-tracking branch 'origin/tracking' into custom
This commit is contained in:
commit
0d1cf674f0
39 changed files with 18940 additions and 10805 deletions
|
|
@ -14626,11 +14626,6 @@ already_AddRefed<Promise>
|
|||
nsGlobalWindow::CreateImageBitmap(const ImageBitmapSource& aImage,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (aImage.IsArrayBuffer() || aImage.IsArrayBufferView()) {
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ImageBitmap::Create(this, aImage, Nothing(), aRv);
|
||||
}
|
||||
|
||||
|
|
@ -14639,34 +14634,9 @@ nsGlobalWindow::CreateImageBitmap(const ImageBitmapSource& aImage,
|
|||
int32_t aSx, int32_t aSy, int32_t aSw, int32_t aSh,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (aImage.IsArrayBuffer() || aImage.IsArrayBufferView()) {
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ImageBitmap::Create(this, aImage, Some(gfx::IntRect(aSx, aSy, aSw, aSh)), aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<mozilla::dom::Promise>
|
||||
nsGlobalWindow::CreateImageBitmap(const ImageBitmapSource& aImage,
|
||||
int32_t aOffset, int32_t aLength,
|
||||
ImageBitmapFormat aFormat,
|
||||
const Sequence<ChannelPixelLayout>& aLayout,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (!ImageBitmap::ExtensionsEnabled(nullptr, nullptr)) {
|
||||
aRv.Throw(NS_ERROR_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
if (aImage.IsArrayBuffer() || aImage.IsArrayBufferView()) {
|
||||
return ImageBitmap::Create(this, aImage, aOffset, aLength, aFormat, aLayout,
|
||||
aRv);
|
||||
} else {
|
||||
aRv.Throw(NS_ERROR_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#structured-cloning
|
||||
void
|
||||
nsGlobalWindow::StructuredClone(JSContext* aCx,
|
||||
|
|
|
|||
|
|
@ -562,10 +562,6 @@ DOMInterfaces = {
|
|||
'headerFile': 'xpcjsid.h',
|
||||
},
|
||||
|
||||
'ImageBitmap': {
|
||||
'implicitJSContext': [ 'mapDataInto' ],
|
||||
},
|
||||
|
||||
'ImageCapture': {
|
||||
'binaryNames': { 'videoStreamTrack': 'GetVideoStreamTrack' }
|
||||
},
|
||||
|
|
|
|||
|
|
@ -412,7 +412,6 @@ ImageBitmap::ImageBitmap(nsIGlobalObject* aGlobal, layers::Image* aData,
|
|||
, mDataWrapper(new ImageUtils(mData))
|
||||
, mPictureRect(0, 0, aData->GetSize().width, aData->GetSize().height)
|
||||
, mIsPremultipliedAlpha(aIsPremultipliedAlpha)
|
||||
, mIsCroppingAreaOutSideOfSourceImage(false)
|
||||
, mWriteOnly(aWriteOnly)
|
||||
{
|
||||
MOZ_ASSERT(aData, "aData is null in ImageBitmap constructor.");
|
||||
|
|
@ -442,23 +441,6 @@ ImageBitmap::SetPictureRect(const IntRect& aRect, ErrorResult& aRv)
|
|||
mPictureRect = FixUpNegativeDimension(aRect, aRv);
|
||||
}
|
||||
|
||||
void
|
||||
ImageBitmap::SetIsCroppingAreaOutSideOfSourceImage(const IntSize& aSourceSize,
|
||||
const Maybe<IntRect>& aCroppingRect)
|
||||
{
|
||||
// No cropping at all.
|
||||
if (aCroppingRect.isNothing()) {
|
||||
mIsCroppingAreaOutSideOfSourceImage = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (aCroppingRect->X() < 0 || aCroppingRect->Y() < 0 ||
|
||||
aCroppingRect->Width() > aSourceSize.width ||
|
||||
aCroppingRect->Height() > aSourceSize.height) {
|
||||
mIsCroppingAreaOutSideOfSourceImage = true;
|
||||
}
|
||||
}
|
||||
|
||||
static already_AddRefed<SourceSurface>
|
||||
ConvertColorFormatIfNeeded(RefPtr<SourceSurface> aSurface)
|
||||
{
|
||||
|
|
@ -702,7 +684,6 @@ ImageBitmap::ToCloneData() const
|
|||
UniquePtr<ImageBitmapCloneData> result(new ImageBitmapCloneData());
|
||||
result->mPictureRect = mPictureRect;
|
||||
result->mIsPremultipliedAlpha = mIsPremultipliedAlpha;
|
||||
result->mIsCroppingAreaOutSideOfSourceImage = mIsCroppingAreaOutSideOfSourceImage;
|
||||
RefPtr<SourceSurface> surface = mData->GetAsSourceSurface();
|
||||
result->mSurface = surface->GetDataSurface();
|
||||
MOZ_ASSERT(result->mSurface);
|
||||
|
|
@ -720,9 +701,6 @@ ImageBitmap::CreateFromCloneData(nsIGlobalObject* aGlobal,
|
|||
RefPtr<ImageBitmap> ret = new ImageBitmap(aGlobal, data, aData->mWriteOnly,
|
||||
aData->mIsPremultipliedAlpha);
|
||||
|
||||
ret->mIsCroppingAreaOutSideOfSourceImage =
|
||||
aData->mIsCroppingAreaOutSideOfSourceImage;
|
||||
|
||||
ErrorResult rv;
|
||||
ret->SetPictureRect(aData->mPictureRect, rv);
|
||||
return ret.forget();
|
||||
|
|
@ -796,9 +774,6 @@ ImageBitmap::CreateInternal(nsIGlobalObject* aGlobal, HTMLImageElement& aImageEl
|
|||
ret->SetPictureRect(aCropRect.ref(), aRv);
|
||||
}
|
||||
|
||||
// Set mIsCroppingAreaOutSideOfSourceImage.
|
||||
ret->SetIsCroppingAreaOutSideOfSourceImage(surface->GetSize(), aCropRect);
|
||||
|
||||
return ret.forget();
|
||||
}
|
||||
|
||||
|
|
@ -850,9 +825,6 @@ ImageBitmap::CreateInternal(nsIGlobalObject* aGlobal, HTMLVideoElement& aVideoEl
|
|||
ret->SetPictureRect(aCropRect.ref(), aRv);
|
||||
}
|
||||
|
||||
// Set mIsCroppingAreaOutSideOfSourceImage.
|
||||
ret->SetIsCroppingAreaOutSideOfSourceImage(data->GetSize(), aCropRect);
|
||||
|
||||
return ret.forget();
|
||||
}
|
||||
|
||||
|
|
@ -918,9 +890,6 @@ ImageBitmap::CreateInternal(nsIGlobalObject* aGlobal, HTMLCanvasElement& aCanvas
|
|||
ret->SetPictureRect(cropRect, aRv);
|
||||
}
|
||||
|
||||
// Set mIsCroppingAreaOutSideOfSourceImage.
|
||||
ret->SetIsCroppingAreaOutSideOfSourceImage(surface->GetSize(), aCropRect);
|
||||
|
||||
return ret.forget();
|
||||
}
|
||||
|
||||
|
|
@ -986,9 +955,6 @@ ImageBitmap::CreateInternal(nsIGlobalObject* aGlobal, ImageData& aImageData,
|
|||
// The cropping information has been handled in the CreateImageFromRawData()
|
||||
// function.
|
||||
|
||||
// Set mIsCroppingAreaOutSideOfSourceImage.
|
||||
ret->SetIsCroppingAreaOutSideOfSourceImage(imageSize, aCropRect);
|
||||
|
||||
return ret.forget();
|
||||
}
|
||||
|
||||
|
|
@ -1026,9 +992,6 @@ ImageBitmap::CreateInternal(nsIGlobalObject* aGlobal, CanvasRenderingContext2D&
|
|||
ret->SetPictureRect(aCropRect.ref(), aRv);
|
||||
}
|
||||
|
||||
// Set mIsCroppingAreaOutSideOfSourceImage.
|
||||
ret->SetIsCroppingAreaOutSideOfSourceImage(surface->GetSize(), aCropRect);
|
||||
|
||||
return ret.forget();
|
||||
}
|
||||
|
||||
|
|
@ -1052,14 +1015,6 @@ ImageBitmap::CreateInternal(nsIGlobalObject* aGlobal, ImageBitmap& aImageBitmap,
|
|||
ret->SetPictureRect(aCropRect.ref(), aRv);
|
||||
}
|
||||
|
||||
// Set mIsCroppingAreaOutSideOfSourceImage.
|
||||
if (aImageBitmap.mIsCroppingAreaOutSideOfSourceImage == true) {
|
||||
ret->mIsCroppingAreaOutSideOfSourceImage = true;
|
||||
} else {
|
||||
ret->SetIsCroppingAreaOutSideOfSourceImage(aImageBitmap.mPictureRect.Size(),
|
||||
aCropRect);
|
||||
}
|
||||
|
||||
return ret.forget();
|
||||
}
|
||||
|
||||
|
|
@ -1318,9 +1273,6 @@ private:
|
|||
// Create ImageBitmap object.
|
||||
RefPtr<ImageBitmap> imageBitmap = new ImageBitmap(mGlobalObject, data, false /* write-only */);
|
||||
|
||||
// Set mIsCroppingAreaOutSideOfSourceImage.
|
||||
imageBitmap->SetIsCroppingAreaOutSideOfSourceImage(sourceSize, originalCropRect);
|
||||
|
||||
return imageBitmap.forget();
|
||||
}
|
||||
};
|
||||
|
|
@ -1414,9 +1366,6 @@ private:
|
|||
// Create ImageBitmap object.
|
||||
RefPtr<ImageBitmap> imageBitmap = new ImageBitmap(mGlobalObject, data, false /* write-only */);
|
||||
|
||||
// Set mIsCroppingAreaOutSideOfSourceImage.
|
||||
imageBitmap->SetIsCroppingAreaOutSideOfSourceImage(sourceSize, originalCropRect);
|
||||
|
||||
return imageBitmap.forget();
|
||||
}
|
||||
|
||||
|
|
@ -1506,20 +1455,17 @@ ImageBitmap::ReadStructuredClone(JSContext* aCx,
|
|||
uint32_t picRectWidth_;
|
||||
uint32_t picRectHeight_;
|
||||
uint32_t isPremultipliedAlpha_;
|
||||
uint32_t isCroppingAreaOutSideOfSourceImage_;
|
||||
uint32_t writeOnly;
|
||||
uint32_t dummy;
|
||||
|
||||
if (!JS_ReadUint32Pair(aReader, &picRectX_, &picRectY_) ||
|
||||
!JS_ReadUint32Pair(aReader, &picRectWidth_, &picRectHeight_) ||
|
||||
!JS_ReadUint32Pair(aReader, &isPremultipliedAlpha_,
|
||||
&isCroppingAreaOutSideOfSourceImage_) ||
|
||||
&dummy) ||
|
||||
!JS_ReadUint32Pair(aReader, &writeOnly, &dummy)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
MOZ_ASSERT(dummy == 0);
|
||||
|
||||
int32_t picRectX = BitwiseCast<int32_t>(picRectX_);
|
||||
int32_t picRectY = BitwiseCast<int32_t>(picRectY_);
|
||||
int32_t picRectWidth = BitwiseCast<int32_t>(picRectWidth_);
|
||||
|
|
@ -1540,9 +1486,6 @@ ImageBitmap::ReadStructuredClone(JSContext* aCx,
|
|||
RefPtr<ImageBitmap> imageBitmap =
|
||||
new ImageBitmap(aParent, img, !!writeOnly, isPremultipliedAlpha_);
|
||||
|
||||
imageBitmap->mIsCroppingAreaOutSideOfSourceImage =
|
||||
isCroppingAreaOutSideOfSourceImage_;
|
||||
|
||||
ErrorResult error;
|
||||
imageBitmap->SetPictureRect(IntRect(picRectX, picRectY,
|
||||
picRectWidth, picRectHeight), error);
|
||||
|
|
@ -1572,7 +1515,6 @@ ImageBitmap::WriteStructuredClone(JSStructuredCloneWriter* aWriter,
|
|||
const uint32_t picRectWidth = BitwiseCast<uint32_t>(aImageBitmap->mPictureRect.width);
|
||||
const uint32_t picRectHeight = BitwiseCast<uint32_t>(aImageBitmap->mPictureRect.height);
|
||||
const uint32_t isPremultipliedAlpha = aImageBitmap->mIsPremultipliedAlpha ? 1 : 0;
|
||||
const uint32_t isCroppingAreaOutSideOfSourceImage = aImageBitmap->mIsCroppingAreaOutSideOfSourceImage ? 1 : 0;
|
||||
const uint32_t isWriteOnly = aImageBitmap->mWriteOnly ? 1 : 0;
|
||||
|
||||
// Indexing the cloned surfaces and send the index to the receiver.
|
||||
|
|
@ -1581,8 +1523,7 @@ ImageBitmap::WriteStructuredClone(JSStructuredCloneWriter* aWriter,
|
|||
if (NS_WARN_IF(!JS_WriteUint32Pair(aWriter, SCTAG_DOM_IMAGEBITMAP, index)) ||
|
||||
NS_WARN_IF(!JS_WriteUint32Pair(aWriter, picRectX, picRectY)) ||
|
||||
NS_WARN_IF(!JS_WriteUint32Pair(aWriter, picRectWidth, picRectHeight)) ||
|
||||
NS_WARN_IF(!JS_WriteUint32Pair(aWriter, isPremultipliedAlpha,
|
||||
isCroppingAreaOutSideOfSourceImage)) ||
|
||||
NS_WARN_IF(!JS_WriteUint32Pair(aWriter, isPremultipliedAlpha, 0)) ||
|
||||
NS_WARN_IF(!JS_WriteUint32Pair(aWriter, isWriteOnly, 0))) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -1608,557 +1549,5 @@ ImageBitmap::WriteStructuredClone(JSStructuredCloneWriter* aWriter,
|
|||
return true;
|
||||
}
|
||||
|
||||
/*static*/ bool
|
||||
ImageBitmap::ExtensionsEnabled(JSContext* aCx, JSObject*)
|
||||
{
|
||||
if (NS_IsMainThread()) {
|
||||
return Preferences::GetBool("canvas.imagebitmap_extensions.enabled");
|
||||
} else {
|
||||
WorkerPrivate* workerPrivate = GetWorkerPrivateFromContext(aCx);
|
||||
MOZ_ASSERT(workerPrivate);
|
||||
return workerPrivate->ImageBitmapExtensionsEnabled();
|
||||
}
|
||||
}
|
||||
|
||||
// ImageBitmap extensions.
|
||||
ImageBitmapFormat
|
||||
ImageBitmap::FindOptimalFormat(const Optional<Sequence<ImageBitmapFormat>>& aPossibleFormats,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(mDataWrapper, "No ImageBitmapFormatUtils functionalities.");
|
||||
|
||||
ImageBitmapFormat platformFormat = mDataWrapper->GetFormat();
|
||||
|
||||
if (!aPossibleFormats.WasPassed() ||
|
||||
aPossibleFormats.Value().Contains(platformFormat)) {
|
||||
return platformFormat;
|
||||
} else {
|
||||
// If no matching is found, FindBestMatchingFromat() returns
|
||||
// ImageBitmapFormat::EndGuard_ and we throw an exception.
|
||||
ImageBitmapFormat optimalFormat =
|
||||
FindBestMatchingFromat(platformFormat, aPossibleFormats.Value());
|
||||
|
||||
if (optimalFormat == ImageBitmapFormat::EndGuard_) {
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
return optimalFormat;
|
||||
}
|
||||
}
|
||||
|
||||
int32_t
|
||||
ImageBitmap::MappedDataLength(ImageBitmapFormat aFormat, ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(mDataWrapper, "No ImageBitmapFormatUtils functionalities.");
|
||||
|
||||
if (aFormat == mDataWrapper->GetFormat()) {
|
||||
return mDataWrapper->GetBufferLength();
|
||||
} else {
|
||||
return CalculateImageBufferSize(aFormat, Width(), Height());
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
class MapDataIntoBufferSource
|
||||
{
|
||||
protected:
|
||||
MapDataIntoBufferSource(JSContext* aCx,
|
||||
Promise *aPromise,
|
||||
ImageBitmap *aImageBitmap,
|
||||
const T& aBuffer,
|
||||
int32_t aOffset,
|
||||
ImageBitmapFormat aFormat)
|
||||
: mPromise(aPromise)
|
||||
, mImageBitmap(aImageBitmap)
|
||||
, mBuffer(aCx, aBuffer.Obj())
|
||||
, mOffset(aOffset)
|
||||
, mFormat(aFormat)
|
||||
{
|
||||
MOZ_ASSERT(mPromise);
|
||||
MOZ_ASSERT(JS_IsArrayBufferObject(mBuffer) ||
|
||||
JS_IsArrayBufferViewObject(mBuffer));
|
||||
}
|
||||
|
||||
virtual ~MapDataIntoBufferSource() = default;
|
||||
|
||||
void DoMapDataIntoBufferSource()
|
||||
{
|
||||
ErrorResult error;
|
||||
|
||||
// Prepare destination buffer.
|
||||
uint8_t* bufferData = nullptr;
|
||||
uint32_t bufferLength = 0;
|
||||
bool isSharedMemory = false;
|
||||
if (JS_IsArrayBufferObject(mBuffer)) {
|
||||
js::GetArrayBufferLengthAndData(mBuffer, &bufferLength, &isSharedMemory, &bufferData);
|
||||
} else if (JS_IsArrayBufferViewObject(mBuffer)) {
|
||||
js::GetArrayBufferViewLengthAndData(mBuffer, &bufferLength, &isSharedMemory, &bufferData);
|
||||
} else {
|
||||
error.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
mPromise->MaybeReject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(!bufferData) || NS_WARN_IF(!bufferLength)) {
|
||||
error.Throw(NS_ERROR_NOT_AVAILABLE);
|
||||
mPromise->MaybeReject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check length.
|
||||
const int32_t neededBufferLength =
|
||||
mImageBitmap->MappedDataLength(mFormat, error);
|
||||
|
||||
if (((int32_t)bufferLength - mOffset) < neededBufferLength) {
|
||||
error.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
||||
mPromise->MaybeReject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
// Call ImageBitmapFormatUtils.
|
||||
UniquePtr<ImagePixelLayout> layout =
|
||||
mImageBitmap->mDataWrapper->MapDataInto(bufferData,
|
||||
mOffset,
|
||||
bufferLength,
|
||||
mFormat,
|
||||
error);
|
||||
|
||||
if (NS_WARN_IF(!layout)) {
|
||||
mPromise->MaybeReject(error);
|
||||
return;
|
||||
}
|
||||
|
||||
mPromise->MaybeResolve(*layout);
|
||||
}
|
||||
|
||||
RefPtr<Promise> mPromise;
|
||||
RefPtr<ImageBitmap> mImageBitmap;
|
||||
JS::PersistentRooted<JSObject*> mBuffer;
|
||||
int32_t mOffset;
|
||||
ImageBitmapFormat mFormat;
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class MapDataIntoBufferSourceTask final : public Runnable,
|
||||
public MapDataIntoBufferSource<T>
|
||||
{
|
||||
public:
|
||||
MapDataIntoBufferSourceTask(JSContext* aCx,
|
||||
Promise *aPromise,
|
||||
ImageBitmap *aImageBitmap,
|
||||
const T& aBuffer,
|
||||
int32_t aOffset,
|
||||
ImageBitmapFormat aFormat)
|
||||
: MapDataIntoBufferSource<T>(aCx, aPromise, aImageBitmap, aBuffer, aOffset, aFormat)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~MapDataIntoBufferSourceTask() = default;
|
||||
|
||||
NS_IMETHOD Run() override
|
||||
{
|
||||
MapDataIntoBufferSource<T>::DoMapDataIntoBufferSource();
|
||||
return NS_OK;
|
||||
}
|
||||
};
|
||||
|
||||
template<typename T>
|
||||
class MapDataIntoBufferSourceWorkerTask final : public WorkerSameThreadRunnable,
|
||||
public MapDataIntoBufferSource<T>
|
||||
{
|
||||
public:
|
||||
MapDataIntoBufferSourceWorkerTask(JSContext* aCx,
|
||||
Promise *aPromise,
|
||||
ImageBitmap *aImageBitmap,
|
||||
const T& aBuffer,
|
||||
int32_t aOffset,
|
||||
ImageBitmapFormat aFormat)
|
||||
: WorkerSameThreadRunnable(GetCurrentThreadWorkerPrivate()),
|
||||
MapDataIntoBufferSource<T>(aCx, aPromise, aImageBitmap, aBuffer, aOffset, aFormat)
|
||||
{
|
||||
}
|
||||
|
||||
virtual ~MapDataIntoBufferSourceWorkerTask() = default;
|
||||
|
||||
bool WorkerRun(JSContext* aCx, WorkerPrivate* aWorkerPrivate) override
|
||||
{
|
||||
MapDataIntoBufferSource<T>::DoMapDataIntoBufferSource();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
void AsyncMapDataIntoBufferSource(JSContext* aCx,
|
||||
Promise *aPromise,
|
||||
ImageBitmap *aImageBitmap,
|
||||
const ArrayBufferViewOrArrayBuffer& aBuffer,
|
||||
int32_t aOffset,
|
||||
ImageBitmapFormat aFormat)
|
||||
{
|
||||
MOZ_ASSERT(aCx);
|
||||
MOZ_ASSERT(aPromise);
|
||||
MOZ_ASSERT(aImageBitmap);
|
||||
|
||||
if (NS_IsMainThread()) {
|
||||
nsCOMPtr<nsIRunnable> task;
|
||||
|
||||
if (aBuffer.IsArrayBuffer()) {
|
||||
const ArrayBuffer& buffer = aBuffer.GetAsArrayBuffer();
|
||||
task = new MapDataIntoBufferSourceTask<ArrayBuffer>(aCx, aPromise, aImageBitmap, buffer, aOffset, aFormat);
|
||||
} else if (aBuffer.IsArrayBufferView()) {
|
||||
const ArrayBufferView& bufferView = aBuffer.GetAsArrayBufferView();
|
||||
task = new MapDataIntoBufferSourceTask<ArrayBufferView>(aCx, aPromise, aImageBitmap, bufferView, aOffset, aFormat);
|
||||
}
|
||||
|
||||
NS_DispatchToCurrentThread(task); // Actually, to the main-thread.
|
||||
} else {
|
||||
RefPtr<WorkerSameThreadRunnable> task;
|
||||
|
||||
if (aBuffer.IsArrayBuffer()) {
|
||||
const ArrayBuffer& buffer = aBuffer.GetAsArrayBuffer();
|
||||
task = new MapDataIntoBufferSourceWorkerTask<ArrayBuffer>(aCx, aPromise, aImageBitmap, buffer, aOffset, aFormat);
|
||||
} else if (aBuffer.IsArrayBufferView()) {
|
||||
const ArrayBufferView& bufferView = aBuffer.GetAsArrayBufferView();
|
||||
task = new MapDataIntoBufferSourceWorkerTask<ArrayBufferView>(aCx, aPromise, aImageBitmap, bufferView, aOffset, aFormat);
|
||||
}
|
||||
|
||||
task->Dispatch(); // Actually, to the current worker-thread.
|
||||
}
|
||||
}
|
||||
|
||||
already_AddRefed<Promise>
|
||||
ImageBitmap::MapDataInto(JSContext* aCx,
|
||||
ImageBitmapFormat aFormat,
|
||||
const ArrayBufferViewOrArrayBuffer& aBuffer,
|
||||
int32_t aOffset, ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(mDataWrapper, "No ImageBitmapFormatUtils functionalities.");
|
||||
MOZ_ASSERT(aCx, "No JSContext while calling ImageBitmap::MapDataInto().");
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(mParent, aRv);
|
||||
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Check for cases that should throws.
|
||||
// Case 1:
|
||||
// If image bitmap was cropped to the source rectangle so that it contains any
|
||||
// transparent black pixels (cropping area is outside of the source image),
|
||||
// then reject promise with IndexSizeError and abort these steps.
|
||||
if (mIsCroppingAreaOutSideOfSourceImage) {
|
||||
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
// Case 2:
|
||||
// If the image bitmap is going to be accessed in YUV422/YUV422 series with a
|
||||
// cropping area starts at an odd x or y coordinate.
|
||||
if (aFormat == ImageBitmapFormat::YUV422P ||
|
||||
aFormat == ImageBitmapFormat::YUV420P ||
|
||||
aFormat == ImageBitmapFormat::YUV420SP_NV12 ||
|
||||
aFormat == ImageBitmapFormat::YUV420SP_NV21) {
|
||||
if ((mPictureRect.x & 1) || (mPictureRect.y & 1)) {
|
||||
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
}
|
||||
|
||||
AsyncMapDataIntoBufferSource(aCx, promise, this, aBuffer, aOffset, aFormat);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
// ImageBitmapFactories extensions.
|
||||
static SurfaceFormat
|
||||
ImageFormatToSurfaceFromat(mozilla::dom::ImageBitmapFormat aFormat)
|
||||
{
|
||||
switch(aFormat) {
|
||||
case ImageBitmapFormat::RGBA32:
|
||||
return SurfaceFormat::R8G8B8A8;
|
||||
case ImageBitmapFormat::BGRA32:
|
||||
return SurfaceFormat::B8G8R8A8;
|
||||
case ImageBitmapFormat::RGB24:
|
||||
return SurfaceFormat::R8G8B8;
|
||||
case ImageBitmapFormat::BGR24:
|
||||
return SurfaceFormat::B8G8R8;
|
||||
case ImageBitmapFormat::GRAY8:
|
||||
return SurfaceFormat::A8;
|
||||
case ImageBitmapFormat::HSV:
|
||||
return SurfaceFormat::HSV;
|
||||
case ImageBitmapFormat::Lab:
|
||||
return SurfaceFormat::Lab;
|
||||
case ImageBitmapFormat::DEPTH:
|
||||
return SurfaceFormat::Depth;
|
||||
default:
|
||||
return SurfaceFormat::UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
static already_AddRefed<layers::Image>
|
||||
CreateImageFromBufferSourceRawData(const uint8_t*aBufferData,
|
||||
uint32_t aBufferLength,
|
||||
mozilla::dom::ImageBitmapFormat aFormat,
|
||||
const Sequence<ChannelPixelLayout>& aLayout)
|
||||
{
|
||||
MOZ_ASSERT(aBufferData);
|
||||
MOZ_ASSERT(aBufferLength > 0);
|
||||
|
||||
switch(aFormat) {
|
||||
case ImageBitmapFormat::RGBA32:
|
||||
case ImageBitmapFormat::BGRA32:
|
||||
case ImageBitmapFormat::RGB24:
|
||||
case ImageBitmapFormat::BGR24:
|
||||
case ImageBitmapFormat::GRAY8:
|
||||
case ImageBitmapFormat::HSV:
|
||||
case ImageBitmapFormat::Lab:
|
||||
case ImageBitmapFormat::DEPTH:
|
||||
{
|
||||
const nsTArray<ChannelPixelLayout>& channels = aLayout;
|
||||
MOZ_ASSERT(channels.Length() != 0, "Empty Channels.");
|
||||
|
||||
const SurfaceFormat srcFormat = ImageFormatToSurfaceFromat(aFormat);
|
||||
const uint32_t srcStride = channels[0].mStride;
|
||||
const IntSize srcSize(channels[0].mWidth, channels[0].mHeight);
|
||||
|
||||
RefPtr<DataSourceSurface> dstDataSurface =
|
||||
Factory::CreateDataSourceSurfaceWithStride(srcSize, srcFormat, srcStride);
|
||||
|
||||
if (NS_WARN_IF(!dstDataSurface)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Copy the raw data into the newly created DataSourceSurface.
|
||||
DataSourceSurface::ScopedMap dstMap(dstDataSurface, DataSourceSurface::WRITE);
|
||||
if (NS_WARN_IF(!dstMap.IsMapped())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
const uint8_t* srcBufferPtr = aBufferData;
|
||||
uint8_t* dstBufferPtr = dstMap.GetData();
|
||||
|
||||
for (int i = 0; i < srcSize.height; ++i) {
|
||||
memcpy(dstBufferPtr, srcBufferPtr, srcStride);
|
||||
srcBufferPtr += srcStride;
|
||||
dstBufferPtr += dstMap.GetStride();
|
||||
}
|
||||
|
||||
// Create an Image from the BGRA SourceSurface.
|
||||
RefPtr<SourceSurface> surface = dstDataSurface;
|
||||
RefPtr<layers::Image> image = CreateImageFromSurface(surface);
|
||||
|
||||
if (NS_WARN_IF(!image)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return image.forget();
|
||||
}
|
||||
case ImageBitmapFormat::YUV444P:
|
||||
case ImageBitmapFormat::YUV422P:
|
||||
case ImageBitmapFormat::YUV420P:
|
||||
case ImageBitmapFormat::YUV420SP_NV12:
|
||||
case ImageBitmapFormat::YUV420SP_NV21:
|
||||
{
|
||||
// Prepare the PlanarYCbCrData.
|
||||
const ChannelPixelLayout& yLayout = aLayout[0];
|
||||
const ChannelPixelLayout& uLayout = aFormat != ImageBitmapFormat::YUV420SP_NV21 ? aLayout[1] : aLayout[2];
|
||||
const ChannelPixelLayout& vLayout = aFormat != ImageBitmapFormat::YUV420SP_NV21 ? aLayout[2] : aLayout[1];
|
||||
|
||||
layers::PlanarYCbCrData data;
|
||||
|
||||
// Luminance buffer
|
||||
data.mYChannel = const_cast<uint8_t*>(aBufferData + yLayout.mOffset);
|
||||
data.mYStride = yLayout.mStride;
|
||||
data.mYSize = gfx::IntSize(yLayout.mWidth, yLayout.mHeight);
|
||||
data.mYSkip = yLayout.mSkip;
|
||||
|
||||
// Chroma buffers
|
||||
data.mCbChannel = const_cast<uint8_t*>(aBufferData + uLayout.mOffset);
|
||||
data.mCrChannel = const_cast<uint8_t*>(aBufferData + vLayout.mOffset);
|
||||
data.mCbCrStride = uLayout.mStride;
|
||||
data.mCbCrSize = gfx::IntSize(uLayout.mWidth, uLayout.mHeight);
|
||||
data.mCbSkip = uLayout.mSkip;
|
||||
data.mCrSkip = vLayout.mSkip;
|
||||
|
||||
// Picture rectangle.
|
||||
// We set the picture rectangle to exactly the size of the source image to
|
||||
// keep the full original data.
|
||||
data.mPicX = 0;
|
||||
data.mPicY = 0;
|
||||
data.mPicSize = data.mYSize;
|
||||
|
||||
// Create a layers::Image and set data.
|
||||
if (aFormat == ImageBitmapFormat::YUV444P ||
|
||||
aFormat == ImageBitmapFormat::YUV422P ||
|
||||
aFormat == ImageBitmapFormat::YUV420P) {
|
||||
RefPtr<layers::PlanarYCbCrImage> image =
|
||||
new layers::RecyclingPlanarYCbCrImage(new layers::BufferRecycleBin());
|
||||
|
||||
if (NS_WARN_IF(!image)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Set Data.
|
||||
if (NS_WARN_IF(!image->CopyData(data))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return image.forget();
|
||||
} else {
|
||||
RefPtr<layers::NVImage>image = new layers::NVImage();
|
||||
|
||||
if (NS_WARN_IF(!image)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Set Data.
|
||||
if (NS_WARN_IF(!image->SetData(data))) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return image.forget();
|
||||
}
|
||||
}
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* This is a synchronous task.
|
||||
* This class is used to create a layers::CairoImage from raw data in the main
|
||||
* thread. While creating an ImageBitmap from an BufferSource, we need to create
|
||||
* a SouceSurface from the BufferSource raw data and then set the SourceSurface
|
||||
* into a layers::CairoImage. However, the layers::CairoImage asserts the
|
||||
* setting operation in the main thread, so if we are going to create an
|
||||
* ImageBitmap from an BufferSource off the main thread, we post an event to the
|
||||
* main thread to create a layers::CairoImage from an BufferSource raw data.
|
||||
*
|
||||
* TODO: Once the layers::CairoImage is constructible off the main thread, which
|
||||
* means the SouceSurface could be released anywhere, we do not need this
|
||||
* task anymore.
|
||||
*/
|
||||
class CreateImageFromBufferSourceRawDataInMainThreadSyncTask final :
|
||||
public WorkerMainThreadRunnable
|
||||
{
|
||||
public:
|
||||
CreateImageFromBufferSourceRawDataInMainThreadSyncTask(const uint8_t* aBuffer,
|
||||
uint32_t aBufferLength,
|
||||
mozilla::dom::ImageBitmapFormat aFormat,
|
||||
const Sequence<ChannelPixelLayout>& aLayout,
|
||||
/*output*/ layers::Image** aImage)
|
||||
: WorkerMainThreadRunnable(GetCurrentThreadWorkerPrivate(),
|
||||
NS_LITERAL_CSTRING("ImageBitmap-extensions :: Create Image from BufferSource Raw Data"))
|
||||
, mImage(aImage)
|
||||
, mBuffer(aBuffer)
|
||||
, mBufferLength(aBufferLength)
|
||||
, mFormat(aFormat)
|
||||
, mLayout(aLayout)
|
||||
{
|
||||
MOZ_ASSERT(!(*aImage), "Don't pass an existing Image into CreateImageFromBufferSourceRawDataInMainThreadSyncTask.");
|
||||
}
|
||||
|
||||
bool MainThreadRun() override
|
||||
{
|
||||
RefPtr<layers::Image> image =
|
||||
CreateImageFromBufferSourceRawData(mBuffer, mBufferLength, mFormat, mLayout);
|
||||
|
||||
if (NS_WARN_IF(!image)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
image.forget(mImage);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private:
|
||||
layers::Image** mImage;
|
||||
const uint8_t* mBuffer;
|
||||
uint32_t mBufferLength;
|
||||
mozilla::dom::ImageBitmapFormat mFormat;
|
||||
const Sequence<ChannelPixelLayout>& mLayout;
|
||||
};
|
||||
|
||||
/*static*/ already_AddRefed<Promise>
|
||||
ImageBitmap::Create(nsIGlobalObject* aGlobal,
|
||||
const ImageBitmapSource& aBuffer,
|
||||
int32_t aOffset, int32_t aLength,
|
||||
mozilla::dom::ImageBitmapFormat aFormat,
|
||||
const Sequence<ChannelPixelLayout>& aLayout,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
MOZ_ASSERT(aGlobal);
|
||||
|
||||
RefPtr<Promise> promise = Promise::Create(aGlobal, aRv);
|
||||
|
||||
if (NS_WARN_IF(aRv.Failed())) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
uint8_t* bufferData = nullptr;
|
||||
uint32_t bufferLength = 0;
|
||||
|
||||
if (aBuffer.IsArrayBuffer()) {
|
||||
const ArrayBuffer& buffer = aBuffer.GetAsArrayBuffer();
|
||||
buffer.ComputeLengthAndData();
|
||||
bufferData = buffer.Data();
|
||||
bufferLength = buffer.Length();
|
||||
} else if (aBuffer.IsArrayBufferView()) {
|
||||
const ArrayBufferView& bufferView = aBuffer.GetAsArrayBufferView();
|
||||
bufferView.ComputeLengthAndData();
|
||||
bufferData = bufferView.Data();
|
||||
bufferLength = bufferView.Length();
|
||||
} else {
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
MOZ_ASSERT(bufferData && bufferLength > 0, "Cannot read data from BufferSource.");
|
||||
|
||||
// Check the buffer.
|
||||
if (((uint32_t)(aOffset + aLength) > bufferLength)) {
|
||||
aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
// Create and Crop the raw data into a layers::Image
|
||||
RefPtr<layers::Image> data;
|
||||
if (NS_IsMainThread()) {
|
||||
data = CreateImageFromBufferSourceRawData(bufferData + aOffset, bufferLength,
|
||||
aFormat, aLayout);
|
||||
} else {
|
||||
RefPtr<CreateImageFromBufferSourceRawDataInMainThreadSyncTask> task =
|
||||
new CreateImageFromBufferSourceRawDataInMainThreadSyncTask(bufferData + aOffset,
|
||||
bufferLength,
|
||||
aFormat,
|
||||
aLayout,
|
||||
getter_AddRefs(data));
|
||||
task->Dispatch(Terminating, aRv);
|
||||
if (aRv.Failed()) {
|
||||
return promise.forget();
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_WARN_IF(!data)) {
|
||||
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
// Create an ImageBimtap.
|
||||
// Assume the data from an external buffer is not alpha-premultiplied.
|
||||
RefPtr<ImageBitmap> imageBitmap = new ImageBitmap(aGlobal, data, false);
|
||||
|
||||
// We don't need to call SetPictureRect() here because there is no cropping
|
||||
// supported and the ImageBitmap's mPictureRect is the size of the source
|
||||
// image in default
|
||||
|
||||
// We don't need to set mIsCroppingAreaOutSideOfSourceImage here because there
|
||||
// is no cropping supported and the mIsCroppingAreaOutSideOfSourceImage is
|
||||
// false in default.
|
||||
|
||||
AsyncFulfillImageBitmapPromise(promise, imageBitmap);
|
||||
|
||||
return promise.forget();
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
|||
|
|
@ -45,7 +45,6 @@ class WorkerStructuredCloneClosure;
|
|||
|
||||
class ArrayBufferViewOrArrayBuffer;
|
||||
class CanvasRenderingContext2D;
|
||||
struct ChannelPixelLayout;
|
||||
class CreateImageBitmapFromBlob;
|
||||
class CreateImageBitmapFromBlobTask;
|
||||
class CreateImageBitmapFromBlobWorkerTask;
|
||||
|
|
@ -56,7 +55,6 @@ class HTMLVideoElement;
|
|||
enum class ImageBitmapFormat : uint32_t;
|
||||
class ImageData;
|
||||
class ImageUtils;
|
||||
template<typename T> class MapDataIntoBufferSource;
|
||||
class Promise;
|
||||
class PostMessageEvent; // For StructuredClone between windows.
|
||||
|
||||
|
|
@ -65,7 +63,6 @@ struct ImageBitmapCloneData final
|
|||
RefPtr<gfx::DataSourceSurface> mSurface;
|
||||
gfx::IntRect mPictureRect;
|
||||
bool mIsPremultipliedAlpha;
|
||||
bool mIsCroppingAreaOutSideOfSourceImage;
|
||||
bool mWriteOnly;
|
||||
};
|
||||
|
||||
|
|
@ -133,14 +130,6 @@ public:
|
|||
Create(nsIGlobalObject* aGlobal, const ImageBitmapSource& aSrc,
|
||||
const Maybe<gfx::IntRect>& aCropRect, ErrorResult& aRv);
|
||||
|
||||
static already_AddRefed<Promise>
|
||||
Create(nsIGlobalObject* aGlobal,
|
||||
const ImageBitmapSource& aBuffer,
|
||||
int32_t aOffset, int32_t aLength,
|
||||
mozilla::dom::ImageBitmapFormat aFormat,
|
||||
const Sequence<mozilla::dom::ChannelPixelLayout>& aLayout,
|
||||
ErrorResult& aRv);
|
||||
|
||||
static JSObject*
|
||||
ReadStructuredClone(JSContext* aCx,
|
||||
JSStructuredCloneReader* aReader,
|
||||
|
|
@ -153,34 +142,14 @@ public:
|
|||
nsTArray<RefPtr<gfx::DataSourceSurface>>& aClonedSurfaces,
|
||||
ImageBitmap* aImageBitmap);
|
||||
|
||||
// Mozilla Extensions
|
||||
static bool ExtensionsEnabled(JSContext* aCx, JSObject* aObj);
|
||||
|
||||
friend CreateImageBitmapFromBlob;
|
||||
friend CreateImageBitmapFromBlobTask;
|
||||
friend CreateImageBitmapFromBlobWorkerTask;
|
||||
|
||||
template<typename T>
|
||||
friend class MapDataIntoBufferSource;
|
||||
|
||||
bool IsWriteOnly() const {
|
||||
return mWriteOnly;
|
||||
}
|
||||
|
||||
// Mozilla Extensions
|
||||
ImageBitmapFormat
|
||||
FindOptimalFormat(const Optional<Sequence<ImageBitmapFormat>>& aPossibleFormats,
|
||||
ErrorResult& aRv);
|
||||
|
||||
int32_t
|
||||
MappedDataLength(ImageBitmapFormat aFormat, ErrorResult& aRv);
|
||||
|
||||
already_AddRefed<Promise>
|
||||
MapDataInto(JSContext* aCx,
|
||||
ImageBitmapFormat aFormat,
|
||||
const ArrayBufferViewOrArrayBuffer& aBuffer,
|
||||
int32_t aOffset, ErrorResult& aRv);
|
||||
|
||||
protected:
|
||||
|
||||
/*
|
||||
|
|
@ -210,9 +179,6 @@ protected:
|
|||
|
||||
void SetPictureRect(const gfx::IntRect& aRect, ErrorResult& aRv);
|
||||
|
||||
void SetIsCroppingAreaOutSideOfSourceImage(const gfx::IntSize& aSourceSize,
|
||||
const Maybe<gfx::IntRect>& aCroppingRect);
|
||||
|
||||
static already_AddRefed<ImageBitmap>
|
||||
CreateInternal(nsIGlobalObject* aGlobal, HTMLImageElement& aImageEl,
|
||||
const Maybe<gfx::IntRect>& aCropRect, ErrorResult& aRv);
|
||||
|
|
@ -278,15 +244,6 @@ protected:
|
|||
|
||||
const bool mIsPremultipliedAlpha;
|
||||
|
||||
/*
|
||||
* Set mIsCroppingAreaOutSideOfSourceImage if image bitmap was cropped to the
|
||||
* source rectangle so that it contains any transparent black pixels (cropping
|
||||
* area is outside of the source image).
|
||||
* This is used in mapDataInto() to check if we should reject promise with
|
||||
* IndexSizeError.
|
||||
*/
|
||||
bool mIsCroppingAreaOutSideOfSourceImage;
|
||||
|
||||
/*
|
||||
* Write-Only flag is set to true if this image has been generated from a
|
||||
* cross-origin source. This is the opposite of what is called 'origin-clean'
|
||||
|
|
|
|||
|
|
@ -10,9 +10,8 @@ namespace mozilla {
|
|||
namespace dom {
|
||||
|
||||
// So we don't have to forward declare this elsewhere.
|
||||
class HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer;
|
||||
typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer
|
||||
ImageBitmapSource;
|
||||
class HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmapOrBlobOrCanvasRenderingContext2DOrImageData;
|
||||
typedef HTMLImageElementOrHTMLCanvasElementOrHTMLVideoElementOrImageBitmapOrBlobOrCanvasRenderingContext2DOrImageData ImageBitmapSource;
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2728,16 +2728,6 @@ GetChannelCountOfImageFormat(ImageBitmapFormat aFormat)
|
|||
return format->GetChannelCount();
|
||||
}
|
||||
|
||||
uint32_t
|
||||
CalculateImageBufferSize(ImageBitmapFormat aFormat,
|
||||
uint32_t aWidth, uint32_t aHeight)
|
||||
{
|
||||
UtilsUniquePtr format = Utils::GetUtils(aFormat);
|
||||
MOZ_ASSERT(format, "Cannot get a valid ImageBitmapFormatUtils instance.");
|
||||
|
||||
return format->NeededBufferSize(aWidth, aHeight);
|
||||
}
|
||||
|
||||
UniquePtr<ImagePixelLayout>
|
||||
CopyAndConvertImageData(ImageBitmapFormat aSrcFormat,
|
||||
const uint8_t* aSrcBuffer,
|
||||
|
|
|
|||
|
|
@ -48,14 +48,6 @@ CreatePixelLayoutFromPlanarYCbCrData(const layers::PlanarYCbCrData* aData);
|
|||
uint8_t
|
||||
GetChannelCountOfImageFormat(ImageBitmapFormat aFormat);
|
||||
|
||||
/*
|
||||
* Get the needed buffer size to store the image data in the given
|
||||
* ImageBitmapFormat with the given width and height.
|
||||
*/
|
||||
uint32_t
|
||||
CalculateImageBufferSize(ImageBitmapFormat aFormat,
|
||||
uint32_t aWidth, uint32_t aHeight);
|
||||
|
||||
/*
|
||||
* This function always copies the image data in _aSrcBuffer_ into _aDstBuffer_
|
||||
* and it also performs color conversion if the _aSrcFormat_ and the
|
||||
|
|
|
|||
|
|
@ -118,38 +118,6 @@ public:
|
|||
return (uint32_t)(size.height * stride);
|
||||
}
|
||||
|
||||
virtual UniquePtr<ImagePixelLayout>
|
||||
MapDataInto(uint8_t* aBuffer,
|
||||
uint32_t aOffset,
|
||||
uint32_t aBufferLength,
|
||||
ImageBitmapFormat aFormat,
|
||||
ErrorResult& aRv) const
|
||||
{
|
||||
DataSourceSurface::ScopedMap map(Surface(), DataSourceSurface::READ);
|
||||
if (!map.IsMapped()) {
|
||||
aRv.Throw(NS_ERROR_ILLEGAL_VALUE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// Copy or convert data.
|
||||
UniquePtr<ImagePixelLayout> srcLayout =
|
||||
CreateDefaultPixelLayout(GetFormat(), Surface()->GetSize().width,
|
||||
Surface()->GetSize().height, map.GetStride());
|
||||
|
||||
// Prepare destination buffer.
|
||||
uint8_t* dstBuffer = aBuffer + aOffset;
|
||||
UniquePtr<ImagePixelLayout> dstLayout =
|
||||
CopyAndConvertImageData(GetFormat(), map.GetData(), srcLayout.get(),
|
||||
aFormat, dstBuffer);
|
||||
|
||||
if (!dstLayout) {
|
||||
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return dstLayout;
|
||||
}
|
||||
|
||||
protected:
|
||||
Impl() {}
|
||||
|
||||
|
|
@ -197,32 +165,6 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
UniquePtr<ImagePixelLayout>
|
||||
MapDataInto(uint8_t* aBuffer,
|
||||
uint32_t aOffset,
|
||||
uint32_t aBufferLength,
|
||||
ImageBitmapFormat aFormat,
|
||||
ErrorResult& aRv) const override
|
||||
{
|
||||
// Prepare source buffer and pixel layout.
|
||||
const PlanarYCbCrData* data = GetPlanarYCbCrData();
|
||||
|
||||
UniquePtr<ImagePixelLayout> srcLayout =
|
||||
CreatePixelLayoutFromPlanarYCbCrData(data);
|
||||
|
||||
// Do conversion.
|
||||
UniquePtr<ImagePixelLayout> dstLayout =
|
||||
CopyAndConvertImageData(GetFormat(), data->mYChannel, srcLayout.get(),
|
||||
aFormat, aBuffer+aOffset);
|
||||
|
||||
if (!dstLayout) {
|
||||
aRv.Throw(NS_ERROR_NOT_AVAILABLE);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return dstLayout;
|
||||
}
|
||||
|
||||
private:
|
||||
const PlanarYCbCrData* GetPlanarYCbCrData() const
|
||||
{
|
||||
|
|
@ -274,17 +216,5 @@ ImageUtils::GetBufferLength() const
|
|||
return mImpl->GetBufferLength();
|
||||
}
|
||||
|
||||
UniquePtr<ImagePixelLayout>
|
||||
ImageUtils::MapDataInto(uint8_t* aBuffer,
|
||||
uint32_t aOffset,
|
||||
uint32_t aBufferLength,
|
||||
ImageBitmapFormat aFormat,
|
||||
ErrorResult& aRv) const
|
||||
{
|
||||
MOZ_ASSERT(mImpl);
|
||||
MOZ_ASSERT(aBuffer, "Map data into a null buffer.");
|
||||
return mImpl->MapDataInto(aBuffer, aOffset, aBufferLength, aFormat, aRv);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
|
|
|||
|
|
@ -31,10 +31,6 @@ typedef nsTArray<ChannelPixelLayout> ImagePixelLayout;
|
|||
* (1) GetFormat() converts the image's format into ImageBitmapFormat enum.
|
||||
* (2) GetBufferLength() returns the number of bytes that are used to store
|
||||
* the image's underlying raw data.
|
||||
* (3) MapDataInto() writes the image's underlying raw data into a given
|
||||
* ArrayBuffer in the given format. (If the given format is different from
|
||||
* the existing format, the ImageUtils uses the ImageBitmapFormatUtils to
|
||||
* performa color conversion.)
|
||||
*
|
||||
* In theory, the functionalities of this class could be merged into the
|
||||
* interface of layers::Image. However, this is designed as a isolated wrapper
|
||||
|
|
@ -58,10 +54,6 @@ public:
|
|||
|
||||
uint32_t GetBufferLength() const;
|
||||
|
||||
UniquePtr<ImagePixelLayout>
|
||||
MapDataInto(uint8_t* aBuffer, uint32_t aOffset, uint32_t aBufferLength,
|
||||
ImageBitmapFormat aFormat, ErrorResult& aRv) const;
|
||||
|
||||
protected:
|
||||
Impl* mImpl;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,49 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<head>
|
||||
<title>Test ImageBitmap Extensions (Bug 1141979)</title>
|
||||
<meta charset="utf-8">
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
<script src="imagebitmap_extensions_prepareSources.js"></script>
|
||||
<script src="imagebitmap_extensions_data.js"></script>
|
||||
<script src="imagebitmap_extensions.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
runTests();
|
||||
|
||||
function ok(expect, msg) {
|
||||
window.parent.postMessage({"type": "status", status: !!expect, msg: msg}, "*");
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
|
||||
prepareSources().
|
||||
then( function() { return Promise.all([testAccessing_randomTest("Video", gVideo, 20), // video might use slightly different frames
|
||||
testAccessing_randomTest("Image", gImage, 0),
|
||||
testAccessing_randomTest("Canvas", gCanvas, 0),
|
||||
testAccessing_randomTest("Ctx", gCtx, 0),
|
||||
testAccessing_randomTest("ImageData", gImageData, 0),
|
||||
testAccessing_randomTest("ImageBitmap", gImageBitmap, 0),
|
||||
testAccessing_randomTest("PNG", gPNGBlob, 0),
|
||||
testAccessing_randomTest("JPEG", gJPEGBlob, 10) // JPEG loses information
|
||||
]); }).
|
||||
then( function() { return Promise.all([testCreateFromArrayBffer_randomTest("Video", gVideo, 20), // video might use slightly different frames
|
||||
testCreateFromArrayBffer_randomTest("Image", gImage, 0),
|
||||
testCreateFromArrayBffer_randomTest("Canvas", gCanvas, 0),
|
||||
testCreateFromArrayBffer_randomTest("Ctx", gCtx, 0),
|
||||
testCreateFromArrayBffer_randomTest("ImageData", gImageData, 0),
|
||||
testCreateFromArrayBffer_randomTest("ImageBitmap", gImageBitmap, 0),
|
||||
testCreateFromArrayBffer_randomTest("PNG", gPNGBlob, 0),
|
||||
testCreateFromArrayBffer_randomTest("JPEG", gJPEGBlob, 10) // JPEG loses information
|
||||
]); }).
|
||||
then(testDraw()).
|
||||
then(testExceptions).
|
||||
then(testColorConversions()).
|
||||
then(function() { return testInvalidAccess([gVideo, gImage, gCanvas, gCtx, gImageData, gImageBitmap, gPNGBlob, gJPEGBlob]); } ).
|
||||
then(function() {window.parent.postMessage({"type": "finish"}, "*");}, function(ev) { failed(ev); window.parent.postMessage({"type": "finish"}, "*"); });
|
||||
}
|
||||
|
||||
</script>
|
||||
</body>
|
||||
|
|
@ -1,526 +0,0 @@
|
|||
function failed(ex) {
|
||||
ok(false, "Promise failure: " + ex);
|
||||
}
|
||||
|
||||
function isPixel(sourceType, bitmapFormat, imageData, bitmapImageData, x, y, tolerance) {
|
||||
if (imageData.width != bitmapImageData.width ||
|
||||
imageData.height != bitmapImageData.height) {
|
||||
ok(false, "Wrong dimension");
|
||||
}
|
||||
|
||||
var index = 4 * (y * imageData.width + x);
|
||||
|
||||
var pr = imageData.data[index+0],
|
||||
pg = imageData.data[index+1],
|
||||
pb = imageData.data[index+2],
|
||||
pa = imageData.data[index+3];
|
||||
|
||||
if (bitmapFormat == "RGBA32" || bitmapFormat == "RGBX32") {
|
||||
var bpr = bitmapImageData.data[index+0],
|
||||
bpg = bitmapImageData.data[index+1],
|
||||
bpb = bitmapImageData.data[index+2],
|
||||
bpa = bitmapImageData.data[index+3];
|
||||
}
|
||||
else if (bitmapFormat == "BGRA32" || bitmapFormat == "BGRX32") {
|
||||
var bpb = bitmapImageData.data[index+0],
|
||||
bpg = bitmapImageData.data[index+1],
|
||||
bpr = bitmapImageData.data[index+2],
|
||||
bpa = bitmapImageData.data[index+3];
|
||||
}
|
||||
else {
|
||||
// format might be one of the followings: "R5G6B5", "A8", "YUV", ""
|
||||
ok(false, "Not supported ImageFormat: " + bitmapFormat);
|
||||
}
|
||||
|
||||
ok(pr - tolerance <= bpr && bpr <= pr + tolerance &&
|
||||
pg - tolerance <= bpg && bpg <= pg + tolerance &&
|
||||
pb - tolerance <= bpb && bpb <= pb + tolerance &&
|
||||
pa - tolerance <= bpa && bpa <= pa + tolerance,
|
||||
"pixel[" + x + "][" + y + "]: " + sourceType + " is "+pr+","+pg+","+pb+","+pa+"; ImageBitmap is "+ bpr + "," + bpg + "," + bpb + "," + bpa);
|
||||
}
|
||||
|
||||
function promiseThrows(p, name) {
|
||||
var didThrow;
|
||||
return p.then(function() { didThrow = false; },
|
||||
function() { didThrow = true; })
|
||||
.then(function() { ok(didThrow, name); });
|
||||
}
|
||||
|
||||
function testExceptions() {
|
||||
return Promise.all([
|
||||
promiseThrows(testColorConversion("GRAY8", "RGBA32", undefined, true), "[Exception] Cannot convert from GRAY8 to RGBA32"),
|
||||
promiseThrows(testColorConversion("GRAY8", "BGRA32", undefined, true), "[Exception] Cannot convert from GRAY8 to BGRA32"),
|
||||
promiseThrows(testColorConversion("GRAY8", "RGB24", undefined, true), "[Exception] Cannot convert from GRAY8 to RGB24"),
|
||||
promiseThrows(testColorConversion("GRAY8", "BGR24", undefined, true), "[Exception] Cannot convert from GRAY8 to BGR24"),
|
||||
promiseThrows(testColorConversion("GRAY8", "YUV444P", undefined, true), "[Exception] Cannot convert from GRAY8 to YUV444P"),
|
||||
promiseThrows(testColorConversion("GRAY8", "YUV422P", undefined, true), "[Exception] Cannot convert from GRAY8 to YUV422P"),
|
||||
promiseThrows(testColorConversion("GRAY8", "YUV420P", undefined, true), "[Exception] Cannot convert from GRAY8 to YUV420P"),
|
||||
promiseThrows(testColorConversion("GRAY8", "YUV420SP_NV12", undefined, true), "[Exception] Cannot convert from GRAY8 to YUV420SP_NV12"),
|
||||
promiseThrows(testColorConversion("GRAY8", "YUV420SP_NV21", undefined, true), "[Exception] Cannot convert from GRAY8 to YUV420SP_NV21"),
|
||||
promiseThrows(testColorConversion("GRAY8", "HSV", undefined, true), "[Exception] Cannot convert from GRAY8 to HSV"),
|
||||
promiseThrows(testColorConversion("GRAY8", "Lab", undefined, true), "[Exception] Cannot convert from GRAY8 to Lab"),
|
||||
promiseThrows(testColorConversion("GRAY8", "DEPTH", undefined, true), "[Exception] Cannot convert from GRAY8 to DEPTH"),
|
||||
|
||||
promiseThrows(testColorConversion("DEPTH", "RGBA32", undefined, true), "[Exception] Cannot convert from DEPTH to RGBA32"),
|
||||
promiseThrows(testColorConversion("DEPTH", "BGRA32", undefined, true), "[Exception] Cannot convert from DEPTH to BGRA32"),
|
||||
promiseThrows(testColorConversion("DEPTH", "RGB24", undefined, true), "[Exception] Cannot convert from DEPTH to RGB24"),
|
||||
promiseThrows(testColorConversion("DEPTH", "BGR24", undefined, true), "[Exception] Cannot convert from DEPTH to BGR24"),
|
||||
promiseThrows(testColorConversion("DEPTH", "GRAY8", undefined, true), "[Exception] Cannot convert from DEPTH to GRAY8"),
|
||||
promiseThrows(testColorConversion("DEPTH", "YUV444P", undefined, true), "[Exception] Cannot convert from DEPTH to YUV444P"),
|
||||
promiseThrows(testColorConversion("DEPTH", "YUV422P", undefined, true), "[Exception] Cannot convert from DEPTH to YUV422P"),
|
||||
promiseThrows(testColorConversion("DEPTH", "YUV420P", undefined, true), "[Exception] Cannot convert from DEPTH to YUV420P"),
|
||||
promiseThrows(testColorConversion("DEPTH", "YUV420SP_NV12", undefined, true), "[Exception] Cannot convert from DEPTH to YUV420SP_NV12"),
|
||||
promiseThrows(testColorConversion("DEPTH", "YUV420SP_NV21", undefined, true), "[Exception] Cannot convert from DEPTH to YUV420SP_NV21"),
|
||||
promiseThrows(testColorConversion("DEPTH", "HSV", undefined, true), "[Exception] Cannot convert from DEPTH to HSV"),
|
||||
promiseThrows(testColorConversion("DEPTH", "Lab", undefined, true), "[Exception] Cannot convert from DEPTH to Lab"),
|
||||
|
||||
promiseThrows(testColorConversion("RGBA32", "DEPTH", undefined, true), "[Exception] Cannot convert from RGBA32 to DEPTH"),
|
||||
promiseThrows(testColorConversion("BGRA32", "DEPTH", undefined, true), "[Exception] Cannot convert from BGRA32 to DEPTH"),
|
||||
promiseThrows(testColorConversion("RGB24", "DEPTH", undefined, true), "[Exception] Cannot convert from RGB24 to DEPTH"),
|
||||
promiseThrows(testColorConversion("BGR24", "DEPTH", undefined, true), "[Exception] Cannot convert from BGR24 to DEPTH"),
|
||||
promiseThrows(testColorConversion("YUV444P", "DEPTH", undefined, true), "[Exception] Cannot convert from YUV444P to DEPTH"),
|
||||
promiseThrows(testColorConversion("YUV422P", "DEPTH", undefined, true), "[Exception] Cannot convert from YUV422P to DEPTH"),
|
||||
promiseThrows(testColorConversion("YUV420P", "DEPTH", undefined, true), "[Exception] Cannot convert from YUV420P to DEPTH"),
|
||||
promiseThrows(testColorConversion("YUV420SP_NV12", "DEPTH", undefined, true), "[Exception] Cannot convert from YUV420SP_NV12 to DEPTH"),
|
||||
promiseThrows(testColorConversion("YUV420SP_NV21", "DEPTH", undefined, true), "[Exception] Cannot convert from YUV420SP_NV21 to DEPTH"),
|
||||
promiseThrows(testColorConversion("HSV", "DEPTH", undefined, true), "[Exception] Cannot convert from HSV to DEPTH"),
|
||||
promiseThrows(testColorConversion("Lab", "DEPTH", undefined, true), "[Exception] Cannot convert from Lab to DEPTH"),
|
||||
]);
|
||||
}
|
||||
|
||||
function testInvalidAccess(sources) {
|
||||
|
||||
function callMapDataIntoWithImageBitmapCroppedOutSideOfTheSourceImage(source) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var p = createImageBitmap(source, -1, -1, 2, 2);
|
||||
p.then(
|
||||
function(bitmap) {
|
||||
var format = bitmap.findOptimalFormat();
|
||||
var length = bitmap.mappedDataLength(format);
|
||||
var buffer = new ArrayBuffer(length);
|
||||
bitmap.mapDataInto(format, buffer, 0).then(
|
||||
function(layout) { resolve(); },
|
||||
function(error) { reject(error); }
|
||||
);
|
||||
},
|
||||
function() { resolve(); });
|
||||
});
|
||||
};
|
||||
|
||||
var testCases = sources.map( function(source) {
|
||||
return promiseThrows(callMapDataIntoWithImageBitmapCroppedOutSideOfTheSourceImage(source),
|
||||
"[Exception] mapDataInto() should throw with transparent black."); });
|
||||
|
||||
return Promise.all(testCases);
|
||||
}
|
||||
|
||||
function testColorConversions() {
|
||||
return Promise.all([// From RGBA32
|
||||
testColorConversion("RGBA32", "RGBA32"),
|
||||
testColorConversion("RGBA32", "BGRA32"),
|
||||
testColorConversion("RGBA32", "RGB24"),
|
||||
testColorConversion("RGBA32", "BGR24"),
|
||||
testColorConversion("RGBA32", "GRAY8"),
|
||||
testColorConversion("RGBA32", "YUV444P"),
|
||||
testColorConversion("RGBA32", "YUV422P"),
|
||||
testColorConversion("RGBA32", "YUV420P", 2),
|
||||
testColorConversion("RGBA32", "YUV420SP_NV12"),
|
||||
testColorConversion("RGBA32", "YUV420SP_NV21"),
|
||||
testColorConversion("RGBA32", "HSV", 0.01),
|
||||
testColorConversion("RGBA32", "Lab", 0.5),
|
||||
|
||||
// From BGRA32
|
||||
testColorConversion("BGRA32", "RGBA32"),
|
||||
testColorConversion("BGRA32", "BGRA32"),
|
||||
testColorConversion("BGRA32", "RGB24"),
|
||||
testColorConversion("BGRA32", "BGR24"),
|
||||
testColorConversion("BGRA32", "GRAY8"),
|
||||
testColorConversion("BGRA32", "YUV444P", 3),
|
||||
testColorConversion("BGRA32", "YUV422P", 2),
|
||||
testColorConversion("BGRA32", "YUV420P", 2),
|
||||
testColorConversion("BGRA32", "YUV420SP_NV12", 2),
|
||||
testColorConversion("BGRA32", "YUV420SP_NV21", 2),
|
||||
testColorConversion("BGRA32", "HSV", 0.01),
|
||||
testColorConversion("BGRA32", "Lab", 0.5),
|
||||
|
||||
// From RGB24
|
||||
testColorConversion("RGB24", "RGBA32"),
|
||||
testColorConversion("RGB24", "BGRA32"),
|
||||
testColorConversion("RGB24", "RGB24"),
|
||||
testColorConversion("RGB24", "BGR24"),
|
||||
testColorConversion("RGB24", "GRAY8"),
|
||||
testColorConversion("RGB24", "YUV444P"),
|
||||
testColorConversion("RGB24", "YUV422P"),
|
||||
testColorConversion("RGB24", "YUV420P"),
|
||||
testColorConversion("RGB24", "YUV420SP_NV12"),
|
||||
testColorConversion("RGB24", "YUV420SP_NV21"),
|
||||
testColorConversion("RGB24", "HSV", 0.01),
|
||||
testColorConversion("RGB24", "Lab", 0.5),
|
||||
|
||||
// From BGR24
|
||||
testColorConversion("BGR24", "RGBA32"),
|
||||
testColorConversion("BGR24", "BGRA32"),
|
||||
testColorConversion("BGR24", "RGB24"),
|
||||
testColorConversion("BGR24", "BGR24"),
|
||||
testColorConversion("BGR24", "GRAY8"),
|
||||
testColorConversion("BGR24", "YUV444P"),
|
||||
testColorConversion("BGR24", "YUV422P"),
|
||||
testColorConversion("BGR24", "YUV420P"),
|
||||
testColorConversion("BGR24", "YUV420SP_NV12"),
|
||||
testColorConversion("BGR24", "YUV420SP_NV21"),
|
||||
testColorConversion("BGR24", "HSV", 0.01),
|
||||
testColorConversion("BGR24", "Lab", 0.5),
|
||||
|
||||
// From YUV444P
|
||||
testColorConversion("YUV444P", "RGBA32"),
|
||||
testColorConversion("YUV444P", "BGRA32"),
|
||||
testColorConversion("YUV444P", "RGB24"),
|
||||
testColorConversion("YUV444P", "BGR24"),
|
||||
testColorConversion("YUV444P", "GRAY8"),
|
||||
testColorConversion("YUV444P", "YUV444P"),
|
||||
testColorConversion("YUV444P", "YUV422P", 4),
|
||||
testColorConversion("YUV444P", "YUV420P", 3),
|
||||
testColorConversion("YUV444P", "YUV420SP_NV12", 3),
|
||||
testColorConversion("YUV444P", "YUV420SP_NV21", 3),
|
||||
testColorConversion("YUV444P", "HSV", 0.01),
|
||||
testColorConversion("YUV444P", "Lab", 0.01),
|
||||
|
||||
// From YUV422P
|
||||
testColorConversion("YUV422P", "RGBA32"),
|
||||
testColorConversion("YUV422P", "BGRA32", 2),
|
||||
testColorConversion("YUV422P", "RGB24"),
|
||||
testColorConversion("YUV422P", "BGR24"),
|
||||
testColorConversion("YUV422P", "GRAY8"),
|
||||
testColorConversion("YUV422P", "YUV444P", 3),
|
||||
testColorConversion("YUV422P", "YUV422P"),
|
||||
testColorConversion("YUV422P", "YUV420P"),
|
||||
testColorConversion("YUV422P", "YUV420SP_NV12"),
|
||||
testColorConversion("YUV422P", "YUV420SP_NV21"),
|
||||
testColorConversion("YUV422P", "HSV", 0.01),
|
||||
testColorConversion("YUV422P", "Lab", 0.01),
|
||||
|
||||
// From YUV420P
|
||||
testColorConversion("YUV420P", "RGBA32", 2),
|
||||
testColorConversion("YUV420P", "BGRA32", 2),
|
||||
testColorConversion("YUV420P", "RGB24"),
|
||||
testColorConversion("YUV420P", "BGR24"),
|
||||
testColorConversion("YUV420P", "GRAY8"),
|
||||
testColorConversion("YUV420P", "YUV444P", 3),
|
||||
testColorConversion("YUV420P", "YUV422P", 1),
|
||||
testColorConversion("YUV420P", "YUV420P"),
|
||||
testColorConversion("YUV420P", "YUV420SP_NV12"),
|
||||
testColorConversion("YUV420P", "YUV420SP_NV21"),
|
||||
testColorConversion("YUV420P", "HSV", 0.01),
|
||||
testColorConversion("YUV420P", "Lab", 0.01),
|
||||
|
||||
// From NV12
|
||||
testColorConversion("YUV420SP_NV12", "RGBA32"),
|
||||
testColorConversion("YUV420SP_NV12", "BGRA32", 2),
|
||||
testColorConversion("YUV420SP_NV12", "RGB24"),
|
||||
testColorConversion("YUV420SP_NV12", "BGR24"),
|
||||
testColorConversion("YUV420SP_NV12", "GRAY8"),
|
||||
testColorConversion("YUV420SP_NV12", "YUV444P", 3),
|
||||
testColorConversion("YUV420SP_NV12", "YUV422P", 1),
|
||||
testColorConversion("YUV420SP_NV12", "YUV420P"),
|
||||
testColorConversion("YUV420SP_NV12", "YUV420SP_NV12"),
|
||||
testColorConversion("YUV420SP_NV12", "YUV420SP_NV21"),
|
||||
testColorConversion("YUV420SP_NV12", "HSV", 0.01),
|
||||
testColorConversion("YUV420SP_NV12", "Lab", 0.01),
|
||||
|
||||
// From NV21
|
||||
testColorConversion("YUV420SP_NV21", "RGBA32"),
|
||||
testColorConversion("YUV420SP_NV21", "BGRA32", 2),
|
||||
testColorConversion("YUV420SP_NV21", "RGB24"),
|
||||
testColorConversion("YUV420SP_NV21", "BGR24"),
|
||||
testColorConversion("YUV420SP_NV21", "GRAY8"),
|
||||
testColorConversion("YUV420SP_NV21", "YUV444P", 3),
|
||||
testColorConversion("YUV420SP_NV21", "YUV422P", 1),
|
||||
testColorConversion("YUV420SP_NV21", "YUV420P"),
|
||||
testColorConversion("YUV420SP_NV21", "YUV420SP_NV12"),
|
||||
testColorConversion("YUV420SP_NV21", "YUV420SP_NV21"),
|
||||
testColorConversion("YUV420SP_NV21", "HSV", 0.01),
|
||||
testColorConversion("YUV420SP_NV21", "Lab", 0.01),
|
||||
|
||||
// From HSV
|
||||
testColorConversion("HSV", "RGBA32"),
|
||||
testColorConversion("HSV", "BGRA32"),
|
||||
testColorConversion("HSV", "RGB24"),
|
||||
testColorConversion("HSV", "BGR24"),
|
||||
testColorConversion("HSV", "GRAY8"),
|
||||
testColorConversion("HSV", "YUV444P"),
|
||||
testColorConversion("HSV", "YUV422P"),
|
||||
testColorConversion("HSV", "YUV420P"),
|
||||
testColorConversion("HSV", "YUV420SP_NV12"),
|
||||
testColorConversion("HSV", "YUV420SP_NV21"),
|
||||
testColorConversion("HSV", "HSV", 0),
|
||||
testColorConversion("HSV", "Lab", 0.5),
|
||||
|
||||
// From Lab
|
||||
testColorConversion("Lab", "RGBA32", 1),
|
||||
testColorConversion("Lab", "BGRA32", 1),
|
||||
testColorConversion("Lab", "RGB24", 1),
|
||||
testColorConversion("Lab", "BGR24", 1),
|
||||
testColorConversion("Lab", "GRAY8", 1),
|
||||
testColorConversion("Lab", "YUV444P", 1),
|
||||
testColorConversion("Lab", "YUV422P", 1),
|
||||
testColorConversion("Lab", "YUV420P", 1),
|
||||
testColorConversion("Lab", "YUV420SP_NV12", 1),
|
||||
testColorConversion("Lab", "YUV420SP_NV21", 1),
|
||||
testColorConversion("Lab", "HSV", 0.5),
|
||||
testColorConversion("Lab", "Lab", 0),
|
||||
|
||||
// From GRAY8
|
||||
testColorConversion("GRAY8", "GRAY8"),
|
||||
|
||||
// From DEPTH
|
||||
testColorConversion("DEPTH", "DEPTH", 0, Uint16Array),
|
||||
]);
|
||||
}
|
||||
|
||||
function testDraw() {
|
||||
return Promise.all([doOneDrawTest("RGB24"),
|
||||
doOneDrawTest("BGR24"),
|
||||
doOneDrawTest("YUV444P", 5),
|
||||
doOneDrawTest("YUV422P", 2),
|
||||
doOneDrawTest("YUV420P", 2),
|
||||
doOneDrawTest("YUV420SP_NV12", 2),
|
||||
doOneDrawTest("YUV420SP_NV21", 2),
|
||||
doOneDrawTest("HSV", 2),
|
||||
doOneDrawTest("Lab", 2)]);
|
||||
}
|
||||
|
||||
// Create an ImageBitmap, _bitmap_, from the _source_.
|
||||
// Read the underlying data of _bitmap_ into _bitmapBuffer_.
|
||||
// Compare the _bitmapBuffer_ with gGroundTruthImageData.
|
||||
function testAccessing_randomTest(sourceType, source, duration) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var p = createImageBitmap(source);
|
||||
p.then(
|
||||
function(bitmap) {
|
||||
bitmapFormat = "RGBA32";
|
||||
var bitmapBufferLength = bitmap.mappedDataLength(bitmapFormat);
|
||||
|
||||
var bitmapBuffer = new ArrayBuffer(bitmapBufferLength);
|
||||
var bitmapBufferView = new Uint8ClampedArray(bitmapBuffer, 0, bitmapBufferLength);
|
||||
var promise = bitmap.mapDataInto(bitmapFormat, bitmapBuffer, 0);
|
||||
promise.then(
|
||||
function(bitmapPixelLayout) {
|
||||
// Prepare.
|
||||
bitmapImageData = new ImageData(bitmapBufferView, bitmap.width, bitmap.height);
|
||||
|
||||
// Test.
|
||||
for (var t = 0; t < 50; ++t) {
|
||||
var randomX = Math.floor(Math.random() * 240);
|
||||
var randomY = Math.floor(Math.random() * 175);
|
||||
isPixel(sourceType, "RGBA32", gGroundTruthImageData, bitmapImageData, randomX, randomY, duration);
|
||||
}
|
||||
|
||||
resolve();
|
||||
},
|
||||
function(ev) { failed(ev); reject(); });
|
||||
},
|
||||
function(ev) { failed(ev); reject(); });
|
||||
});
|
||||
}
|
||||
|
||||
// Create an ImageBitmap, _bitmap_, from the _source_.
|
||||
// Read the underlying data of _bitmap_ into _bitmapBuffer_.
|
||||
// Create another ImageBitmap, _bitmap2_, from _bitmapBuffer_.
|
||||
// Read the underlying data of _bitmap2_ into _bitmapBuffer2_.
|
||||
// Compare the _bitmapBuffer2_ with gGroundTruthImageData.
|
||||
function testCreateFromArrayBffer_randomTest(sourceType, source, duration) {
|
||||
return new Promise(function(resolve, reject) {
|
||||
var p = createImageBitmap(source);
|
||||
p.then(
|
||||
function(bitmap) {
|
||||
bitmapFormat = "RGBA32";
|
||||
var bitmapBufferLength = bitmap.mappedDataLength(bitmapFormat);
|
||||
|
||||
var bitmapBuffer = new ArrayBuffer(bitmapBufferLength);
|
||||
var bitmapBufferView = new Uint8ClampedArray(bitmapBuffer, 0, bitmapBufferLength);
|
||||
var promiseMapDataInto = bitmap.mapDataInto(bitmapFormat, bitmapBuffer, 0);
|
||||
promiseMapDataInto.then(
|
||||
function(bitmapPixelLayout) {
|
||||
// Create a new ImageBitmap from an ArrayBuffer.
|
||||
var p2 = createImageBitmap(bitmapBufferView,
|
||||
0,
|
||||
bitmapBufferLength,
|
||||
bitmapFormat,
|
||||
bitmapPixelLayout);
|
||||
|
||||
p2.then(
|
||||
function(bitmap2) {
|
||||
bitmapFormat2 = "RGBA32";
|
||||
var bitmapBufferLength2 = bitmap2.mappedDataLength(bitmapFormat2);
|
||||
|
||||
var bitmapBuffer2 = new ArrayBuffer(bitmapBufferLength2);
|
||||
var bitmapBufferView2 = new Uint8ClampedArray(bitmapBuffer2, 0, bitmapBufferLength2);
|
||||
var promise2 = bitmap2.mapDataInto(bitmapFormat2, bitmapBuffer2, 0);
|
||||
promise2.then(
|
||||
function(bitmapPixelLayout2) {
|
||||
// Prepare.
|
||||
var bitmapImageData2 = new ImageData(bitmapBufferView2, bitmap2.width, bitmap2.height);
|
||||
|
||||
// Test.
|
||||
for (var t = 0; t < 50; ++t) {
|
||||
var randomX = Math.floor(Math.random() * 240);
|
||||
var randomY = Math.floor(Math.random() * 175);
|
||||
isPixel(sourceType, "RGBA32", gGroundTruthImageData, bitmapImageData2, randomX, randomY, duration);
|
||||
}
|
||||
|
||||
resolve();
|
||||
},
|
||||
function(ev) { failed(ev); reject(); });
|
||||
},
|
||||
function(ev) { console.log("p2 rejected!"); failed(ev); reject(); });
|
||||
},
|
||||
function(ev) { console.log("promiseMapDataInto rejected!"); failed(ev); reject(); });
|
||||
},
|
||||
function(ev) { failed(ev); reject(); });
|
||||
});
|
||||
}
|
||||
|
||||
function testColorConversion(sourceFromat, destinationFormat, tolerance, shouldThrow) {
|
||||
|
||||
tolerance = tolerance || 0;
|
||||
shouldThrow = shouldThrow || false;
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
var [srcData, dstData] = getTestData(sourceFromat, destinationFormat);
|
||||
|
||||
ok(!!srcData, "Get valid srcData of type:" + sourceFromat);
|
||||
ok(!!dstData, "Get valid dstData of type:" + destinationFormat);
|
||||
|
||||
// printInfo(sourceFromat, srcData);
|
||||
// printInfo(destinationFormat, dstData);
|
||||
|
||||
// Create a new ImageBitmap from an ArrayBuffer.
|
||||
var p = createImageBitmap(srcData.buffer,
|
||||
0,
|
||||
srcData.bufferLength,
|
||||
srcData.format,
|
||||
srcData.pixelLayout);
|
||||
|
||||
p.then(
|
||||
function(srcBitmap) {
|
||||
ok(!!srcBitmap, "Should get a valid srcBitmap.");
|
||||
ok(srcBitmap.findOptimalFormat() == sourceFromat, "srcBitmap.findOptimalFormat():" + srcBitmap.findOptimalFormat() +
|
||||
" should equal to sourceFromat:" + sourceFromat);
|
||||
|
||||
var dstBufferLength = srcBitmap.mappedDataLength(destinationFormat);
|
||||
var dstBuffer = new ArrayBuffer(dstBufferLength);
|
||||
var dstBufferView = new dstData.ArrayType(dstBuffer, 0, dstBufferLength / dstData.ArrayType.BYTES_PER_ELEMENT);
|
||||
|
||||
// Do color conversion here.
|
||||
var p2 = srcBitmap.mapDataInto(destinationFormat, dstBuffer, 0);
|
||||
p2.then(
|
||||
function(dstPixelLayout) {
|
||||
var dataPixalLayout = dstData.pixelLayout;
|
||||
|
||||
// Check pixel layout.
|
||||
ok(dstPixelLayout.length == dstData.channelCount, "dstPixelLayout.length:" + dstPixelLayout.length +
|
||||
" should equal to dstData.channelCount:" + dstData.channelCount);
|
||||
|
||||
for (var c = 0; c < dstData.channelCount; ++c) {
|
||||
var dstChannelLayout = dstPixelLayout[c];
|
||||
var dataChannelLayout = dataPixalLayout[c];
|
||||
ok(dstChannelLayout.width == dataChannelLayout.width, "channel[" + c + "] dstChannelLayout.width:" + dstChannelLayout.width + " should equal to dataChannelLayout.width:" + dataChannelLayout.width);
|
||||
ok(dstChannelLayout.height == dataChannelLayout.height, "channel[" + c + "] dstChannelLayout.height:" + dstChannelLayout.height + " should equal to dataChannelLayout.height:" + dataChannelLayout.height);
|
||||
ok(dstChannelLayout.skip == dataChannelLayout.skip, "channel[" + c + "] dstChannelLayout.skip:" + dstChannelLayout.skip + " should equal to dataChannelLayout.skip:" + dataChannelLayout.skip);
|
||||
|
||||
for (var i = 0; i < dstChannelLayout.height; ++i) {
|
||||
for (var j = 0; j < dstChannelLayout.width; ++j) {
|
||||
var byteOffset = dstChannelLayout.offset + i * dstChannelLayout.stride + j * (dstChannelLayout.skip + 1) * dstData.ArrayType.BYTES_PER_ELEMENT;
|
||||
var view = new dstData.ArrayType(dstBuffer, byteOffset, 1);
|
||||
var dstBufferViewValue = view[0];
|
||||
var dstDataValue = dstData.getPixelValue(i, j, c);
|
||||
ok(Math.abs(dstBufferViewValue - dstDataValue) <= tolerance,
|
||||
"[" + sourceFromat + " -> " + destinationFormat + "] pixel(" + i + "," + j + ") channnel(" + c +
|
||||
"): dstBufferViewValue:" + dstBufferViewValue +
|
||||
" should equal to dstDataValue:" + dstDataValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resolve();
|
||||
},
|
||||
function(ev) {
|
||||
// If the "mapDataInto" throws, the flow goes here.
|
||||
if (!shouldThrow) { failed(ev); }
|
||||
reject();
|
||||
}
|
||||
);
|
||||
},
|
||||
function(ev) {
|
||||
reject(ev);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
function doOneDrawTest(sourceFromat, tolerance) {
|
||||
tolerance = tolerance || 0;
|
||||
var destinationFormat = "RGBA32";
|
||||
|
||||
return new Promise(function(resolve, reject) {
|
||||
|
||||
var [srcData, dstData] = getTestData(sourceFromat, destinationFormat);
|
||||
ok(!!srcData, "Get valid srcData of type:" + sourceFromat);
|
||||
ok(!!dstData, "Get valid dstData of type:" + destinationFormat);
|
||||
|
||||
var p = createImageBitmap(srcData.buffer,
|
||||
0,
|
||||
srcData.bufferLength,
|
||||
srcData.format,
|
||||
srcData.pixelLayout);
|
||||
|
||||
p.then(
|
||||
function(srcBitmap) {
|
||||
ok(!!srcBitmap, "Should get a valid srcBitmap.");
|
||||
ok(srcBitmap.findOptimalFormat() == sourceFromat, "srcBitmap.findOptimalFormat():" + srcBitmap.findOptimalFormat() +
|
||||
" should equal to sourceFromat:" + sourceFromat);
|
||||
|
||||
var canvas = document.createElement("canvas");
|
||||
canvas.width = srcBitmap.width;
|
||||
canvas.height = srcBitmap.height;
|
||||
var ctx = canvas.getContext("2d");
|
||||
|
||||
ctx.drawImage(srcBitmap, 0, 0, srcBitmap.width, srcBitmap.height);
|
||||
|
||||
// Get an ImageData from the canvas.
|
||||
var imageData = ctx.getImageData(0, 0, srcBitmap.width, srcBitmap.height);
|
||||
|
||||
for (var i = 0; i < srcBitmap.height; ++i) {
|
||||
for (var j = 0; j < srcBitmap.width; ++j) {
|
||||
var pixelOffset = i * srcBitmap.width * dstData.channelCount + j * dstData.channelCount;
|
||||
var dstImageDataValue_R = imageData.data[pixelOffset + 0];
|
||||
var dstImageDataValue_G = imageData.data[pixelOffset + 1];
|
||||
var dstImageDataValue_B = imageData.data[pixelOffset + 2];
|
||||
var dstImageDataValue_A = imageData.data[pixelOffset + 3];
|
||||
|
||||
var logPrefix = "[" + sourceFromat + " -> " + destinationFormat + "] pixel(" + i + "," + j + ")";
|
||||
|
||||
var dstDataValue_R = dstData.getPixelValue(i, j, 0);
|
||||
var dstDataValue_G = dstData.getPixelValue(i, j, 1);
|
||||
var dstDataValue_B = dstData.getPixelValue(i, j, 2);
|
||||
var dstDataValue_A = dstData.getPixelValue(i, j, 3);
|
||||
ok(Math.abs(dstImageDataValue_R - dstDataValue_R) <= tolerance,
|
||||
logPrefix + "channnel(R): dstImageDataValue:" + dstImageDataValue_R + " should equal to dstDataValue_R: " + dstDataValue_R);
|
||||
ok(Math.abs(dstImageDataValue_G - dstDataValue_G) <= tolerance,
|
||||
logPrefix + "channnel(G): dstImageDataValue:" + dstImageDataValue_G + " should equal to dstDataValue_G: " + dstDataValue_G);
|
||||
ok(Math.abs(dstImageDataValue_B - dstDataValue_B) <= tolerance,
|
||||
logPrefix + "channnel(B): dstImageDataValue:" + dstImageDataValue_B + " should equal to dstDataValue_B: " + dstDataValue_B);
|
||||
ok(Math.abs(dstImageDataValue_A - dstDataValue_A) <= tolerance,
|
||||
logPrefix + "channnel(A): dstImageDataValue:" + dstImageDataValue_A + " should equal to dstDataValue_A: " + dstDataValue_A);
|
||||
}
|
||||
}
|
||||
|
||||
resolve();
|
||||
},
|
||||
function(ev) {
|
||||
failed(ev);
|
||||
reject(ev);
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
|
|
@ -1,47 +0,0 @@
|
|||
importScripts("imagebitmap_extensions_data.js");
|
||||
importScripts("imagebitmap_extensions.js");
|
||||
|
||||
var gGroundTruthImageData;
|
||||
var gImageData;
|
||||
var gImageBitmap;
|
||||
var gPNGBlob;
|
||||
var gJPEGBlob;
|
||||
|
||||
onmessage = function(event) {
|
||||
if (event.data.type == "setSources") {
|
||||
gGroundTruthImageData = event.data.groundTruthImageData;
|
||||
gImageData = event.data.imageData;
|
||||
gImageBitmap = event.data.imageBitmap;
|
||||
gPNGBlob = event.data.pngBlob;
|
||||
gJPEGBlob = event.data.jpegBlob;
|
||||
|
||||
ok(!!gGroundTruthImageData, "Get gGroundTruthImageData!");
|
||||
ok(!!gImageData, "Get gImageData!");
|
||||
ok(!!gImageBitmap, "Get gImageBitmap!");
|
||||
ok(!!gPNGBlob, "Get gPNGBlob!");
|
||||
ok(!!gJPEGBlob, "Get gJPEGBlob!");
|
||||
|
||||
runTests();
|
||||
}
|
||||
};
|
||||
|
||||
function ok(expect, msg) {
|
||||
postMessage({"type": "status", status: !!expect, msg: msg});
|
||||
}
|
||||
|
||||
function runTests() {
|
||||
testExceptions().
|
||||
then(testColorConversions()).
|
||||
then( function() { return Promise.all([testAccessing_randomTest("ImageData", gImageData, 0),
|
||||
testAccessing_randomTest("ImageBitmap", gImageBitmap, 0),
|
||||
testAccessing_randomTest("PNG", gPNGBlob, 0),
|
||||
testAccessing_randomTest("JPEG", gJPEGBlob, 10) // JPEG loses information
|
||||
]); }).
|
||||
then( function() { return Promise.all([testCreateFromArrayBffer_randomTest("ImageData", gImageData, 0),
|
||||
testCreateFromArrayBffer_randomTest("ImageBitmap", gImageBitmap, 0),
|
||||
testCreateFromArrayBffer_randomTest("PNG", gPNGBlob, 0),
|
||||
testCreateFromArrayBffer_randomTest("JPEG", gJPEGBlob, 10) // JPEG loses information
|
||||
]); }).
|
||||
then(function() { return testInvalidAccess([gImageData, gImageBitmap, gPNGBlob, gJPEGBlob]); } ).
|
||||
then(function() {postMessage({"type": "finish"});}, function(ev) { failed(ev); postMessage({"type": "finish"}); });
|
||||
}
|
||||
|
|
@ -1,94 +0,0 @@
|
|||
var gImage;
|
||||
var gVideo;
|
||||
var gCanvas;
|
||||
var gCtx;
|
||||
var gImageData;
|
||||
var gImageBitmap;
|
||||
var gPNGBlob;
|
||||
var gJPEGBlob;
|
||||
|
||||
var gGroundTruthImageData;
|
||||
|
||||
function prepareSources() {
|
||||
gVideo = document.createElement("video");
|
||||
gVideo.src = "http://example.com/tests/dom/canvas/test/crossorigin/video.sjs?name=tests/dom/media/test/320x240.ogv&type=video/ogg&cors=anonymous";
|
||||
gVideo.crossOrigin = "anonymous";
|
||||
gVideo.autoplay = "true"
|
||||
|
||||
|
||||
gCanvas = document.createElement("canvas");
|
||||
gCtx = gCanvas.getContext("2d");
|
||||
|
||||
var resolver;
|
||||
var promise = new Promise(function(resolve, reject) {
|
||||
resolver = resolve;
|
||||
});
|
||||
|
||||
// Prepare video.
|
||||
gVideo.onloadeddata = function() {
|
||||
ok(gVideo, "[Prepare Sources] gVideo is ok.");
|
||||
|
||||
// Prepare canvas.
|
||||
gCanvas.width = gVideo.videoWidth;
|
||||
gCanvas.height = gVideo.videoHeight;
|
||||
gCtx.drawImage(gVideo, 0, 0);
|
||||
ok(gCanvas, "[Prepare Sources] gCanvas is ok.");
|
||||
ok(gCtx, "[Prepare Sources] gCtx is ok.");
|
||||
|
||||
// Prepare gGroundTruthImageData.
|
||||
gGroundTruthImageData = gCtx.getImageData(0, 0, gCanvas.width, gCanvas.height);
|
||||
ok(gGroundTruthImageData, "[Prepare Sources] gGroundTruthImageData is ok.");
|
||||
|
||||
// Prepare image.
|
||||
gImage = document.createElement("img");
|
||||
gImage.src = gCanvas.toDataURL();
|
||||
var resolverImage;
|
||||
var promiseImage = new Promise(function(resolve, reject) {
|
||||
resolverImage = resolve;
|
||||
});
|
||||
gImage.onload = function() {
|
||||
resolverImage(true);
|
||||
}
|
||||
|
||||
// Prepare ImageData.
|
||||
gImageData = gCtx.getImageData(0, 0, gCanvas.width, gCanvas.height);
|
||||
ok(gImageData, "[Prepare Sources] gImageData is ok.");
|
||||
|
||||
// Prepapre PNG Blob.
|
||||
var promisePNGBlob = new Promise(function(resolve, reject) {
|
||||
gCanvas.toBlob(function(blob) {
|
||||
gPNGBlob = blob;
|
||||
ok(gPNGBlob, "[Prepare Sources] gPNGBlob is ok.");
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
|
||||
// Prepare JPEG Blob.
|
||||
var promiseJPEGBlob = new Promise(function(resolve, reject) {
|
||||
gCanvas.toBlob(function(blob) {
|
||||
gJPEGBlob = blob;
|
||||
ok(gJPEGBlob, "[Prepare Sources] gJPEGBlob is ok.");
|
||||
resolve(true);
|
||||
}, "image/jpeg", 1.00);
|
||||
});
|
||||
|
||||
// Prepare ImageBitmap.
|
||||
var promiseImageBitmap = new Promise(function(resolve, reject) {
|
||||
var p = createImageBitmap(gCanvas);
|
||||
p.then(function(bitmap) {
|
||||
gImageBitmap = bitmap;
|
||||
ok(gImageBitmap, "[Prepare Sources] gImageBitmap is ok.");
|
||||
resolve(true);
|
||||
});
|
||||
});
|
||||
|
||||
resolver(Promise.all([
|
||||
promiseImage,
|
||||
promisePNGBlob,
|
||||
promiseJPEGBlob,
|
||||
promiseImageBitmap
|
||||
]))
|
||||
}
|
||||
|
||||
return promise;
|
||||
}
|
||||
|
|
@ -27,10 +27,6 @@ support-files =
|
|||
imagebitmap_bug1239300.js
|
||||
imagebitmap_bug1239752.js
|
||||
imagebitmap_extensions.html
|
||||
imagebitmap_extensions.js
|
||||
imagebitmap_extensions_data.js
|
||||
imagebitmap_extensions_on_worker.js
|
||||
imagebitmap_extensions_prepareSources.js
|
||||
imagebitmap_on_worker.js
|
||||
imagebitmap_structuredclone.js
|
||||
imagebitmap_structuredclone_iframe.html
|
||||
|
|
@ -232,10 +228,6 @@ tags = imagebitmap
|
|||
tags = imagebitmap
|
||||
[test_imagebitmap_cropping.html]
|
||||
tags = imagebitmap
|
||||
[test_imagebitmap_extensions.html]
|
||||
tags = imagebitmap
|
||||
[test_imagebitmap_extensions_on_worker.html]
|
||||
tags = imagebitmap
|
||||
[test_imagebitmap_on_worker.html]
|
||||
tags = imagebitmap
|
||||
[test_imagebitmap_structuredclone.html]
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<heand>
|
||||
<title>Test ImageBitmap Extensions (Bug 1141979)</title>
|
||||
<meta charset="utf-8">
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="content"><div>
|
||||
<script type="text/javascript">
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// The createImageBitmap() method is part of Window whose
|
||||
// prototype was created before the preference is set. So I create another
|
||||
// iframe with the right preference setting so that the
|
||||
// createImageBitmap() will be visible.
|
||||
SpecialPowers.pushPrefEnv({'set': [
|
||||
['canvas.imagebitmap_extensions.enabled', true],
|
||||
['gfx.ycbcr.accurate-conversion', true]
|
||||
]}, function() {
|
||||
var div = document.getElementById("content");
|
||||
ok(div, "Parent exists");
|
||||
|
||||
var ifr = document.createElement("iframe");
|
||||
ifr.setAttribute('src', "imagebitmap_extensions.html");
|
||||
div.appendChild(ifr);
|
||||
});
|
||||
|
||||
window.onmessage = function(event) {
|
||||
if (event.data.type == "status") {
|
||||
ok(event.data.status, event.data.msg);
|
||||
} else if (event.data.type == "finish") {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
<!DOCTYPE HTML>
|
||||
<heand>
|
||||
<title>Test ImageBitmap Extensions On Worker (Bug 1141979)</title>
|
||||
<meta charset="utf-8">
|
||||
<script src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<link rel="stylesheet" href="/tests/SimpleTest/test.css">
|
||||
</head>
|
||||
<body>
|
||||
<div id="content"><div>
|
||||
<script src="imagebitmap_extensions_prepareSources.js"></script>
|
||||
<script type="text/javascript">
|
||||
|
||||
var worker;
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
SpecialPowers.pushPrefEnv({'set': [
|
||||
['canvas.imagebitmap_extensions.enabled', true]
|
||||
]}, function() {
|
||||
worker = new Worker("imagebitmap_extensions_on_worker.js");
|
||||
worker.onmessage = function(event) {
|
||||
if (event.data.type == "status") {
|
||||
ok(event.data.status, event.data.msg);
|
||||
} else if (event.data.type == "finish") {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
};
|
||||
|
||||
ok(!!worker, "Worker created successfully.");
|
||||
prepareSources().then(function() {
|
||||
worker.postMessage({"type": "setSources",
|
||||
"groundTruthImageData": gGroundTruthImageData,
|
||||
"imageData": gImageData,
|
||||
"imageBitmap": gImageBitmap,
|
||||
"pngBlob": gPNGBlob,
|
||||
"jpegBlob": gJPEGBlob});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
|
|
@ -334,6 +334,78 @@ nsMixedContentBlocker::AsyncOnChannelRedirect(nsIChannel* aOldChannel,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
bool nsMixedContentBlocker::IsPotentiallyTrustworthyLoopbackURL(nsIURI* aURL) {
|
||||
nsAutoCString host;
|
||||
nsresult rv = aURL->GetHost(host);
|
||||
NS_ENSURE_SUCCESS(rv, false);
|
||||
|
||||
return host.EqualsLiteral("127.0.0.1") || host.EqualsLiteral("::1") ||
|
||||
host.EqualsLiteral("localhost");
|
||||
}
|
||||
|
||||
bool nsMixedContentBlocker::IsPotentiallyTrustworthyOrigin(nsIURI* aURI) {
|
||||
// The following implements:
|
||||
// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
|
||||
|
||||
nsAutoCString scheme;
|
||||
nsresult rv = aURI->GetScheme(scheme);
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Blobs are expected to inherit their principal so we don't expect to have
|
||||
// a codebase principal with scheme 'blob' here. We can't assert that though
|
||||
// since someone could mess with a non-blob URI to give it that scheme.
|
||||
NS_WARNING_ASSERTION(!scheme.EqualsLiteral("blob"),
|
||||
"IsPotentiallyTrustworthyOrigin ignoring blob scheme");
|
||||
|
||||
// According to the specification, the user agent may choose to extend the
|
||||
// trust to other, vendor-specific URL schemes. We use this for "resource:",
|
||||
// which is technically a substituting protocol handler that is not limited to
|
||||
// local resource mapping, but in practice is never mapped remotely as this
|
||||
// would violate assumptions a lot of code makes.
|
||||
if (scheme.EqualsLiteral("https") ||
|
||||
scheme.EqualsLiteral("file") ||
|
||||
scheme.EqualsLiteral("resource") ||
|
||||
scheme.EqualsLiteral("app") ||
|
||||
scheme.EqualsLiteral("moz-extension") ||
|
||||
scheme.EqualsLiteral("wss")) {
|
||||
return true;
|
||||
}
|
||||
|
||||
nsAutoCString host;
|
||||
rv = aURI->GetHost(host);
|
||||
if (NS_FAILED(rv)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IsPotentiallyTrustworthyLoopbackURL(aURI)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// If a host is not considered secure according to the default algorithm, then
|
||||
// check to see if it has been whitelisted by the user. We only apply this
|
||||
// whitelist for network resources, i.e., those with scheme "http" or "ws".
|
||||
// The pref should contain a comma-separated list of hostnames.
|
||||
|
||||
if (!scheme.EqualsLiteral("http") && !scheme.EqualsLiteral("ws")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsAdoptingCString whitelist = Preferences::GetCString("dom.securecontext.whitelist");
|
||||
if (whitelist) {
|
||||
nsCCharSeparatedTokenizer tokenizer(whitelist, ',');
|
||||
while (tokenizer.hasMoreTokens()) {
|
||||
const nsCSubstring& allowedHost = tokenizer.nextToken();
|
||||
if (host.Equals(allowedHost)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/* This version of ShouldLoad() is non-static and called by the Content Policy
|
||||
* API and AsyncOnChannelRedirect(). See nsIContentPolicy::ShouldLoad()
|
||||
* for detailed description of the parameters.
|
||||
|
|
@ -667,6 +739,16 @@ nsMixedContentBlocker::ShouldLoad(bool aHadInsecureImageRedirect,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
bool isHttpScheme = false;
|
||||
rv = innerContentLocation->SchemeIs("http", &isHttpScheme);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
// Allow http requests for trusted origins (e.g. localhost or explicitly trusted contexts)
|
||||
if (isHttpScheme && IsPotentiallyTrustworthyOrigin(innerContentLocation)) {
|
||||
*aDecision = ACCEPT;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// The page might have set the CSP directive 'upgrade-insecure-requests'. In such
|
||||
// a case allow the http: load to succeed with the promise that the channel will
|
||||
// get upgraded to https before fetching any data from the netwerk.
|
||||
|
|
@ -678,9 +760,6 @@ nsMixedContentBlocker::ShouldLoad(bool aHadInsecureImageRedirect,
|
|||
// we only have to check against http: here. Skip mixed content blocking if the
|
||||
// subresource load uses http: and the CSP directive 'upgrade-insecure-requests'
|
||||
// is present on the page.
|
||||
bool isHttpScheme = false;
|
||||
rv = innerContentLocation->SchemeIs("http", &isHttpScheme);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
nsIDocument* document = docShell->GetDocument();
|
||||
MOZ_ASSERT(document, "Expected a document");
|
||||
if (isHttpScheme && document->GetUpgradeInsecureRequests(isPreload)) {
|
||||
|
|
|
|||
|
|
@ -42,6 +42,11 @@ public:
|
|||
|
||||
nsMixedContentBlocker();
|
||||
|
||||
// See:
|
||||
// https://w3c.github.io/webappsec-secure-contexts/#is-origin-trustworthy
|
||||
static bool IsPotentiallyTrustworthyLoopbackURL(nsIURI* aURL);
|
||||
static bool IsPotentiallyTrustworthyOrigin(nsIURI* aURI);
|
||||
|
||||
/* Static version of ShouldLoad() that contains all the Mixed Content Blocker
|
||||
* logic. Called from non-static ShouldLoad().
|
||||
* Called directly from imageLib when an insecure redirect exists in a cached
|
||||
|
|
|
|||
|
|
@ -10,25 +10,17 @@
|
|||
* http://w3c.github.io/mediacapture-worker/#imagebitmap-extensions
|
||||
*/
|
||||
|
||||
// Extensions
|
||||
// Bug 1141979 - [FoxEye] Extend ImageBitmap with interfaces to access its
|
||||
// underlying image data
|
||||
//
|
||||
// Note:
|
||||
// Our overload resolution implementation doesn't deal with a union as the
|
||||
// distinguishing argument which means we cannot overload functions via union
|
||||
// types, a.k.a. we cannot overload createImageBitmap() via ImageBitmapSource
|
||||
// and BufferSource. Here, we work around this issue by adding the BufferSource
|
||||
// into ImageBitmapSource.
|
||||
|
||||
// This is needed because we don't support SVG element as canvas image source.
|
||||
// See bug 1500768.
|
||||
typedef (HTMLImageElement or
|
||||
HTMLVideoElement or
|
||||
HTMLCanvasElement or
|
||||
HTMLVideoElement or
|
||||
ImageBitmap) CanvasImageSourceExcludedSVG;
|
||||
|
||||
typedef (CanvasImageSourceExcludedSVG or
|
||||
Blob or
|
||||
ImageData or
|
||||
CanvasRenderingContext2D or
|
||||
ImageBitmap or
|
||||
BufferSource) ImageBitmapSource;
|
||||
CanvasRenderingContext2D or // This is out of spec.
|
||||
ImageData) ImageBitmapSource;
|
||||
|
||||
[Exposed=(Window,Worker)]
|
||||
interface ImageBitmap {
|
||||
|
|
@ -402,11 +394,3 @@ dictionary ChannelPixelLayout {
|
|||
|
||||
typedef sequence<ChannelPixelLayout> ImagePixelLayout;
|
||||
|
||||
partial interface ImageBitmap {
|
||||
[Throws, Func="mozilla::dom::ImageBitmap::ExtensionsEnabled"]
|
||||
ImageBitmapFormat findOptimalFormat (optional sequence<ImageBitmapFormat> aPossibleFormats);
|
||||
[Throws, Func="mozilla::dom::ImageBitmap::ExtensionsEnabled"]
|
||||
long mappedDataLength (ImageBitmapFormat aFormat);
|
||||
[Throws, Func="mozilla::dom::ImageBitmap::ExtensionsEnabled"]
|
||||
Promise<ImagePixelLayout> mapDataInto (ImageBitmapFormat aFormat, BufferSource aBuffer, long aOffset);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -72,18 +72,3 @@ partial interface WindowOrWorkerGlobalScope {
|
|||
[Throws, Func="mozilla::dom::cache::CacheStorage::PrefEnabled", SameObject]
|
||||
readonly attribute CacheStorage caches;
|
||||
};
|
||||
|
||||
// Mozilla extensions
|
||||
partial interface WindowOrWorkerGlobalScope {
|
||||
// Extensions to ImageBitmap bits.
|
||||
// Bug 1141979 - [FoxEye] Extend ImageBitmap with interfaces to access its
|
||||
// underlying image data
|
||||
//
|
||||
// Note:
|
||||
// Overloaded functions cannot have different "extended attributes",
|
||||
// so I cannot add preference on the extended version of createImageBitmap().
|
||||
// To work around, I will then check the preference at run time and throw if
|
||||
// the preference is set to be false.
|
||||
[Throws]
|
||||
Promise<ImageBitmap> createImageBitmap(ImageBitmapSource aImage, long aOffset, long aLength, ImageBitmapFormat aFormat, ImagePixelLayout aLayout);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#if !(defined(DEBUG) || defined(MOZ_ENABLE_JS_DUMP))
|
||||
WORKER_SIMPLE_PREF("browser.dom.window.dump.enabled", DumpEnabled, DUMP)
|
||||
#endif
|
||||
WORKER_SIMPLE_PREF("canvas.imagebitmap_extensions.enabled", ImageBitmapExtensionsEnabled, IMAGEBITMAP_EXTENSIONS_ENABLED)
|
||||
WORKER_SIMPLE_PREF("dom.caches.enabled", DOMCachesEnabled, DOM_CACHES)
|
||||
WORKER_SIMPLE_PREF("dom.caches.testing.enabled", DOMCachesTestingEnabled, DOM_CACHES_TESTING)
|
||||
WORKER_SIMPLE_PREF("dom.performance.enable_user_timing_logging", PerformanceLoggingEnabled, PERFORMANCE_LOGGING_ENABLED)
|
||||
|
|
|
|||
|
|
@ -450,11 +450,6 @@ already_AddRefed<Promise>
|
|||
WorkerGlobalScope::CreateImageBitmap(const ImageBitmapSource& aImage,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (aImage.IsArrayBuffer() || aImage.IsArrayBufferView()) {
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ImageBitmap::Create(this, aImage, Nothing(), aRv);
|
||||
}
|
||||
|
||||
|
|
@ -463,38 +458,9 @@ WorkerGlobalScope::CreateImageBitmap(const ImageBitmapSource& aImage,
|
|||
int32_t aSx, int32_t aSy, int32_t aSw, int32_t aSh,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
if (aImage.IsArrayBuffer() || aImage.IsArrayBufferView()) {
|
||||
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return ImageBitmap::Create(this, aImage, Some(gfx::IntRect(aSx, aSy, aSw, aSh)), aRv);
|
||||
}
|
||||
|
||||
already_AddRefed<mozilla::dom::Promise>
|
||||
WorkerGlobalScope::CreateImageBitmap(const ImageBitmapSource& aImage,
|
||||
int32_t aOffset, int32_t aLength,
|
||||
ImageBitmapFormat aFormat,
|
||||
const Sequence<ChannelPixelLayout>& aLayout,
|
||||
ErrorResult& aRv)
|
||||
{
|
||||
JSContext* cx = GetCurrentThreadJSContext();
|
||||
MOZ_ASSERT(cx);
|
||||
|
||||
if (!ImageBitmap::ExtensionsEnabled(cx, nullptr)) {
|
||||
aRv.Throw(NS_ERROR_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (aImage.IsArrayBuffer() || aImage.IsArrayBufferView()) {
|
||||
return ImageBitmap::Create(this, aImage, aOffset, aLength, aFormat, aLayout,
|
||||
aRv);
|
||||
} else {
|
||||
aRv.Throw(NS_ERROR_TYPE_ERR);
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
// https://html.spec.whatwg.org/#structured-cloning
|
||||
void WorkerGlobalScope::StructuredClone(JSContext* aCx,
|
||||
JS::Handle<JS::Value> aValue,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue