Bug 1141979 - part1 - WebIDL for native implementation; r=jrmuizel, r=smaug

MozReview-Commit-ID: 9gC0rxhsOLm

--HG--
extra : transplant_source : %7D%9A%C8%05%99%17Y%1E1%404%A7%14%BE%8B%AC%F0b%A2%5B
This commit is contained in:
Kaku Kuo 2015-11-18 16:57:38 +08:00
parent 447d4a1f0d
commit ec2d98e4c3
4 changed files with 250 additions and 3 deletions

View File

@ -226,6 +226,7 @@
#include "mozilla/dom/ScriptSettings.h"
#include "mozilla/dom/NavigatorBinding.h"
#include "mozilla/dom/ImageBitmap.h"
#include "mozilla/dom/ImageBitmapBinding.h"
#include "mozilla/dom/ServiceWorkerRegistration.h"
#include "mozilla/dom/U2F.h"
#include "mozilla/dom/WebIDLGlobalNameHash.h"
@ -14362,6 +14363,11 @@ 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);
}
@ -14370,6 +14376,11 @@ 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);
}

View File

@ -11,8 +11,8 @@ namespace mozilla {
namespace dom {
// So we don't have to forward declare this elsewhere.
class HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmap;
typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmap
class HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer;
typedef HTMLImageElementOrHTMLVideoElementOrHTMLCanvasElementOrBlobOrImageDataOrCanvasRenderingContext2DOrImageBitmapOrArrayBufferViewOrArrayBuffer
ImageBitmapSource;
}

View File

@ -5,15 +5,30 @@
*
* The origin of this IDL file is
* https://html.spec.whatwg.org/multipage/webappapis.html#images
*
* The origin of the extended IDL file is
* 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.
typedef (HTMLImageElement or
HTMLVideoElement or
HTMLCanvasElement or
Blob or
ImageData or
CanvasRenderingContext2D or
ImageBitmap) ImageBitmapSource;
ImageBitmap or
BufferSource) ImageBitmapSource;
[Exposed=(Window,Worker)]
interface ImageBitmap {
@ -42,3 +57,213 @@ interface ImageBitmapFactories {
[Throws]
Promise<ImageBitmap> createImageBitmap(ImageBitmapSource aImage, long aSx, long aSy, long aSw, long aSh);
};
// ImageBitmap-extensions
// Bug 1141979 - [FoxEye] Extend ImageBitmap with interfaces to access its
// underlying image data
/*
* An image or a video frame is conceptually a two-dimensional array of data and
* each element in the array is called a pixel. The pixels are usually stored in
* a one-dimensional array and could be arranged in a variety of image formats.
* Developers need to know how the pixels are formatted so that they are able to
* process them.
*
* The image format describes how pixels in an image are arranged. A single
* pixel has at least one, but usually multiple pixel values. The range of a
* pixel value varies, which means different image formats use different data
* types to store a single pixel value.
*
* The most frequently used data type is 8-bit unsigned integer whose range is
* from 0 to 255, others could be 16-bit integer or 32-bit floating points and
* so forth. The number of pixel values of a single pixel is called the number
* of channels of the image format. Multiple pixel values of a pixel are used
* together to describe the captured property which could be color or depth
* information. For example, if the data is a color image in RGB color space,
* then it is a three-channel image format and a pixel is described by R, G and
* B three pixel values with range from 0 to 255. As another example, if the
* data is a gray image, then it is a single-channel image format with 8-bit
* unsigned integer data type and the pixel value describes the gray scale. For
* depth data, it is a single channel image format too, but the data type is
* 16-bit unsigned integer and the pixel value is the depth level.
*
* For those image formats whose pixels contain multiple pixel values, the pixel
* values might be arranged in one of the following ways:
* 1) Planar pixel layout:
* each channel has its pixel values stored consecutively in separated
* buffers (a.k.a. planes) and then all channel buffers are stored
* consecutively in memory.
* (Ex: RRRRRR......GGGGGG......BBBBBB......)
* 2) Interleaving pixel layout:
* each pixel has its pixel values from all channels stored together and
* interleaves all channels.
* (Ex: RGBRGBRGBRGBRGB......)
*/
/*
* The ImageBitmap extensions use this enumeration to negotiate the image format
* while 1) accessing the underlying data of an ImageBitmap and
* 2) creating a new ImageBitmap.
*
* For each format in this enumeration, we use a 2x2 small image (4 pixels) as
* example to illustrate the pixel layout.
*
* 2x2 image: +--------+--------+
* | pixel1 | pixel2 |
* +--------+--------+
* | pixel3 | pixel4 |
* +--------+--------+
*
*/
enum ImageBitmapFormat {
/*
* Channel order: R, G, B, A
* Channel size: full rgba-chennels
* Pixel layout: interleaving rgba-channels
* Pixel layout illustration:
* [Plane1]: R1 G1 B1 A1 R2 G2 B2 A2 R3 G3 B3 A3 R4 G4 B4 A4
* Data type: 8-bit unsigned integer
*/
"RGBA32",
/*
* Channel order: B, G, R, A
* Channel size: full bgra-channels
* Pixel layout: interleaving bgra-channels
* Pixel layout illustration:
* [Plane1]: B1 G1 R1 A1 B2 G2 R2 A2 B3 G3 R3 A3 B4 G4 R4 A4
* Data type: 8-bit unsigned integer
*/
"BGRA32",
/*
* Channel order: R, G, B
* Channel size: full rgb-channels
* Pixel layout: interleaving rgb-channels
* Pixel layout illustration:
* [Plane1]: R1 G1 B1 R2 G2 B2 R3 G3 B3 R4 G4 B4
* Data type: 8-bit unsigned integer
*/
"RGB24",
/*
* Channel order: B, G, R
* Channel size: full bgr-channels
* Pixel layout: interleaving bgr-channels
* Pixel layout illustration:
* [Plane1]: B1 G1 R1 B2 G2 R2 B3 G3 R3 B4 G4 R4
* Data type: 8-bit unsigned integer
*/
"BGR24",
/*
* Channel order: GRAY
* Channel size: full gray-channel
* Pixel layout: planar gray-channel
* Pixel layout illustration:
* [Plane1]: GRAY1 GRAY2 GRAY3 GRAY4
* Data type: 8-bit unsigned integer
*/
"GRAY8",
/*
* Channel order: Y, U, V
* Channel size: full yuv-channels
* Pixel layout: planar yuv-channels
* Pixel layout illustration:
* [Plane1]: Y1 Y2 Y3 Y4
* [Plane2]: U1 U2 U3 U4
* [Plane3]: V1 V2 V3 V4
* Data type: 8-bit unsigned integer
*/
"YUV444P",
/*
* Channel order: Y, U, V
* Channel size: full y-channel, half uv-channels
* Pixel layout: planar yuv-channels
* Pixel layout illustration:
* [Plane1]: Y1 Y2 Y3 Y4
* [Plane2]: U1 U3
* [Plane3]: V1 V3
* Data type: 8-bit unsigned integer
*/
"YUV422P",
/*
* Channel order: Y, U, V
* Channel size: full y-channel, quarter uv-channels
* Pixel layout: planar yuv-channels
* Pixel layout illustration:
* [Plane1]: Y1 Y2 Y3 Y4
* [Plane2]: U1
* [Plane3]: V1
* Data type: 8-bit unsigned integer
*/
"YUV420P",
/*
* Channel order: Y, U, V
* Channel size: full y-channel, quarter uv-channels
* Pixel layout: planar y-channel, interleaving uv-channels
* Pixel layout illustration:
* [Plane1]: Y1 Y2 Y3 Y4
* [Plane2]: U1 V1
* Data type: 8-bit unsigned integer
*/
"YUV420SP_NV12",
/*
* Channel order: Y, V, U
* Channel size: full y-channel, quarter vu-channels
* Pixel layout: planar y-channel, interleaving vu-channels
* Pixel layout illustration:
* [Plane1]: Y1 Y2 Y3 Y4
* [Plane2]: V1 U1
* Data type: 8-bit unsigned integer
*/
"YUV420SP_NV21",
/*
* Channel order: H, S, V
* Channel size: full hsv-channels
* Pixel layout: interleaving hsv-channels
* Pixel layout illustration:
* [Plane1]: H1 S1 V1 H2 S2 V2 H3 S3 V3
* Data type: 32-bit floating point value
*/
"HSV",
/*
* Channel order: l, a, b
* Channel size: full lab-channels
* Pixel layout: interleaving lab-channels
* Pixel layout illustration:
* [Plane1]: l1 a1 b1 l2 a2 b2 l3 a3 b3
* Data type: 32-bit floating point value
*/
"Lab",
/*
* Channel order: DEPTH
* Channel size: full depth-channel
* Pixel layout: planar depth-channel
* Pixel layout illustration:
* [Plane1]: DEPTH1 DEPTH2 DEPTH3 DEPTH4
* Data type: 16-bit unsigned integer
*/
"DEPTH",
};
enum ChannelPixelLayoutDataType {
"uint8",
"int8",
"uint16",
"int16",
"uint32",
"int32",
"float32",
"float64"
};

View File

@ -15,6 +15,7 @@
#include "mozilla/dom/FunctionBinding.h"
#include "mozilla/dom/IDBFactory.h"
#include "mozilla/dom/ImageBitmap.h"
#include "mozilla/dom/ImageBitmapBinding.h"
#include "mozilla/dom/Promise.h"
#include "mozilla/dom/PromiseWorkerProxy.h"
#include "mozilla/dom/ServiceWorkerGlobalScopeBinding.h"
@ -414,6 +415,11 @@ 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);
}
@ -422,6 +428,11 @@ 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);
}