зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1324924 - Support ImageBitmap for Tex*Image*. (flattened) - r=bz,daoshengmu,mtseng
MozReview-Commit-ID: JzcbzeFHyHn
This commit is contained in:
Родитель
f18df6e96d
Коммит
8a9c965490
|
@ -1296,7 +1296,7 @@ StructuredCloneHolder::CustomWriteTransferHandler(JSContext* aCx,
|
|||
*aExtraData = 0;
|
||||
*aTag = SCTAG_DOM_IMAGEBITMAP;
|
||||
*aOwnership = JS::SCTAG_TMO_CUSTOM;
|
||||
*aContent = bitmap->ToCloneData();
|
||||
*aContent = bitmap->ToCloneData().release();
|
||||
MOZ_ASSERT(*aContent);
|
||||
bitmap->Close();
|
||||
|
||||
|
|
|
@ -723,10 +723,10 @@ ImageBitmap::TransferAsImage()
|
|||
return image.forget();
|
||||
}
|
||||
|
||||
ImageBitmapCloneData*
|
||||
ImageBitmap::ToCloneData()
|
||||
UniquePtr<ImageBitmapCloneData>
|
||||
ImageBitmap::ToCloneData() const
|
||||
{
|
||||
ImageBitmapCloneData* result = new ImageBitmapCloneData();
|
||||
UniquePtr<ImageBitmapCloneData> result(new ImageBitmapCloneData());
|
||||
result->mPictureRect = mPictureRect;
|
||||
result->mIsPremultipliedAlpha = mIsPremultipliedAlpha;
|
||||
result->mIsCroppingAreaOutSideOfSourceImage = mIsCroppingAreaOutSideOfSourceImage;
|
||||
|
@ -734,7 +734,7 @@ ImageBitmap::ToCloneData()
|
|||
result->mSurface = surface->GetDataSurface();
|
||||
MOZ_ASSERT(result->mSurface);
|
||||
|
||||
return result;
|
||||
return Move(result);
|
||||
}
|
||||
|
||||
/* static */ already_AddRefed<ImageBitmap>
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
#include "mozilla/dom/TypedArray.h"
|
||||
#include "mozilla/gfx/Rect.h"
|
||||
#include "mozilla/Maybe.h"
|
||||
#include "mozilla/UniquePtr.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
struct JSContext;
|
||||
|
@ -115,8 +116,8 @@ public:
|
|||
already_AddRefed<layers::Image>
|
||||
TransferAsImage();
|
||||
|
||||
ImageBitmapCloneData*
|
||||
ToCloneData();
|
||||
UniquePtr<ImageBitmapCloneData>
|
||||
ToCloneData() const;
|
||||
|
||||
static already_AddRefed<ImageBitmap>
|
||||
CreateFromCloneData(nsIGlobalObject* aGlobal, ImageBitmapCloneData* aData);
|
||||
|
|
|
@ -205,6 +205,7 @@ struct TexImageSource
|
|||
|
||||
const WebGLsizeiptr* mPboOffset;
|
||||
|
||||
const dom::ImageBitmap* mImageBitmap;
|
||||
const dom::ImageData* mImageData;
|
||||
|
||||
const dom::Element* mDomElem;
|
||||
|
@ -248,6 +249,10 @@ struct TexImageSourceAdapter final : public TexImageSource
|
|||
mPboOffset = pboOffset;
|
||||
}
|
||||
|
||||
TexImageSourceAdapter(const dom::ImageBitmap* imageBitmap, ErrorResult*) {
|
||||
mImageBitmap = imageBitmap;
|
||||
}
|
||||
|
||||
TexImageSourceAdapter(const dom::ImageData* imageData, ErrorResult*) {
|
||||
mImageData = imageData;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include "GLContext.h"
|
||||
#include "mozilla/gfx/2D.h"
|
||||
#include "mozilla/dom/HTMLVideoElement.h"
|
||||
#include "mozilla/dom/ImageBitmap.h"
|
||||
#include "mozilla/dom/ImageData.h"
|
||||
#include "mozilla/MathAlgorithms.h"
|
||||
#include "mozilla/Scoped.h"
|
||||
|
@ -210,6 +211,35 @@ FromPboOffset(WebGLContext* webgl, const char* funcName, TexImageTarget target,
|
|||
isClientData, ptr, availBufferBytes);
|
||||
}
|
||||
|
||||
static UniquePtr<webgl::TexUnpackBlob>
|
||||
FromImageBitmap(WebGLContext* webgl, const char* funcName, TexImageTarget target,
|
||||
uint32_t width, uint32_t height, uint32_t depth,
|
||||
const dom::ImageBitmap& imageBitmap)
|
||||
{
|
||||
UniquePtr<dom::ImageBitmapCloneData> cloneData = Move(imageBitmap.ToCloneData());
|
||||
const RefPtr<gfx::DataSourceSurface> surf = cloneData->mSurface;
|
||||
|
||||
////
|
||||
|
||||
if (!width) {
|
||||
width = surf->GetSize().width;
|
||||
}
|
||||
|
||||
if (!height) {
|
||||
height = surf->GetSize().height;
|
||||
}
|
||||
|
||||
////
|
||||
|
||||
|
||||
// WhatWG "HTML Living Standard" (30 October 2015):
|
||||
// "The getImageData(sx, sy, sw, sh) method [...] Pixels must be returned as
|
||||
// non-premultiplied alpha values."
|
||||
const bool isAlphaPremult = cloneData->mIsPremultipliedAlpha;
|
||||
return MakeUnique<webgl::TexUnpackSurface>(webgl, target, width, height, depth, surf,
|
||||
isAlphaPremult);
|
||||
}
|
||||
|
||||
static UniquePtr<webgl::TexUnpackBlob>
|
||||
FromImageData(WebGLContext* webgl, const char* funcName, TexImageTarget target,
|
||||
uint32_t width, uint32_t height, uint32_t depth,
|
||||
|
@ -380,6 +410,11 @@ WebGLContext::From(const char* funcName, TexImageTarget target, GLsizei rawWidth
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
if (src.mImageBitmap) {
|
||||
return FromImageBitmap(this, funcName, target, width, height, depth,
|
||||
*(src.mImageBitmap));
|
||||
}
|
||||
|
||||
if (src.mImageData) {
|
||||
return FromImageData(this, funcName, target, width, height, depth,
|
||||
*(src.mImageData), scopedArr);
|
||||
|
|
|
@ -364,6 +364,9 @@ interface WebGL2RenderingContextBase
|
|||
void texImage2D(GLenum target, GLint level, GLint internalformat,
|
||||
GLenum format, GLenum type, HTMLVideoElement source); // May throw DOMException
|
||||
[Throws] // Another overhead throws.
|
||||
void texImage2D(GLenum target, GLint level, GLint internalformat,
|
||||
GLenum format, GLenum type, ImageBitmap source);
|
||||
[Throws] // Another overhead throws.
|
||||
void texImage2D(GLenum target, GLint level, GLint internalformat,
|
||||
GLenum format, GLenum type, ImageData source);
|
||||
|
||||
|
@ -381,6 +384,9 @@ interface WebGL2RenderingContextBase
|
|||
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
GLenum format, GLenum type, HTMLVideoElement source); // May throw DOMException
|
||||
[Throws] // Another overhead throws.
|
||||
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
GLenum format, GLenum type, ImageBitmap source);
|
||||
[Throws] // Another overhead throws.
|
||||
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
GLenum format, GLenum type, ImageData source);
|
||||
|
||||
|
@ -401,6 +407,10 @@ interface WebGL2RenderingContextBase
|
|||
GLint border, GLenum format, GLenum type,
|
||||
HTMLVideoElement source); // May throw DOMException
|
||||
[Throws] // Another overhead throws.
|
||||
void texImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
|
||||
GLint border, GLenum format, GLenum type,
|
||||
ImageBitmap source);
|
||||
[Throws] // Another overhead throws.
|
||||
void texImage2D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
|
||||
GLint border, GLenum format, GLenum type,
|
||||
ImageData source);
|
||||
|
@ -425,6 +435,10 @@ interface WebGL2RenderingContextBase
|
|||
GLsizei depth, GLint border, GLenum format, GLenum type,
|
||||
HTMLVideoElement source); // May throw DOMException
|
||||
[Throws] // Another overhead throws.
|
||||
void texImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
|
||||
GLsizei depth, GLint border, GLenum format, GLenum type,
|
||||
ImageBitmap source);
|
||||
[Throws] // Another overhead throws.
|
||||
void texImage3D(GLenum target, GLint level, GLint internalformat, GLsizei width, GLsizei height,
|
||||
GLsizei depth, GLint border, GLenum format, GLenum type,
|
||||
ImageData source);
|
||||
|
@ -452,6 +466,10 @@ interface WebGL2RenderingContextBase
|
|||
GLsizei height, GLenum format, GLenum type,
|
||||
HTMLVideoElement source); // May throw DOMException
|
||||
[Throws] // Another overhead throws.
|
||||
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
|
||||
GLsizei height, GLenum format, GLenum type,
|
||||
ImageBitmap source);
|
||||
[Throws] // Another overhead throws.
|
||||
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLsizei width,
|
||||
GLsizei height, GLenum format, GLenum type,
|
||||
ImageData source);
|
||||
|
@ -477,6 +495,10 @@ interface WebGL2RenderingContextBase
|
|||
GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
|
||||
HTMLVideoElement source); // May throw DOMException
|
||||
[Throws] // Another overhead throws.
|
||||
void texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
|
||||
GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
|
||||
ImageBitmap source);
|
||||
[Throws] // Another overhead throws.
|
||||
void texSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset, GLint zoffset,
|
||||
GLsizei width, GLsizei height, GLsizei depth, GLenum format, GLenum type,
|
||||
ImageData source);
|
||||
|
|
|
@ -743,6 +743,9 @@ interface WebGLRenderingContext {
|
|||
GLsizei width, GLsizei height, GLint border, GLenum format,
|
||||
GLenum type, ArrayBufferView? pixels);
|
||||
[Throws] // Can't actually throw.
|
||||
void texImage2D(GLenum target, GLint level, GLint internalformat,
|
||||
GLenum format, GLenum type, ImageBitmap pixels);
|
||||
[Throws] // Can't actually throw.
|
||||
void texImage2D(GLenum target, GLint level, GLint internalformat,
|
||||
GLenum format, GLenum type, ImageData pixels);
|
||||
[Throws]
|
||||
|
@ -761,6 +764,9 @@ interface WebGLRenderingContext {
|
|||
GLsizei width, GLsizei height,
|
||||
GLenum format, GLenum type, ArrayBufferView? pixels);
|
||||
[Throws] // Can't actually throw.
|
||||
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
GLenum format, GLenum type, ImageBitmap pixels);
|
||||
[Throws] // Can't actually throw.
|
||||
void texSubImage2D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
|
||||
GLenum format, GLenum type, ImageData pixels);
|
||||
[Throws]
|
||||
|
|
Загрузка…
Ссылка в новой задаче