Bug 1324924 - Add implementation for ImageBitmaps. - r=daoshengmu
MozReview-Commit-ID: 8arcHOHWDzD
--- a/dom/canvas/WebGLContext.h
+++ b/dom/canvas/WebGLContext.h
@@ -200,16 +200,17 @@ struct IndexedBufferBinding
struct TexImageSource
{
const dom::ArrayBufferView* mView;
GLuint mViewElemOffset;
GLuint mViewElemLengthOverride;
const WebGLsizeiptr* mPboOffset;
+ const dom::ImageBitmap* mImageBitmap;
const dom::ImageData* mImageData;
const dom::Element* mDomElem;
ErrorResult* mOut_error;
protected:
TexImageSource() {
memset(this, 0, sizeof(*this));
@@ -243,16 +244,20 @@ struct TexImageSourceAdapter final : pub
TexImageSourceAdapter(const WebGLsizeiptr* pboOffset, GLuint ignored1, GLuint ignored2 = 0) {
mPboOffset = pboOffset;
}
TexImageSourceAdapter(const WebGLsizeiptr* pboOffset, ErrorResult* ignored) {
mPboOffset = pboOffset;
}
+ TexImageSourceAdapter(const dom::ImageBitmap* imageBitmap, ErrorResult*) {
+ mImageBitmap = imageBitmap;
+ }
+
TexImageSourceAdapter(const dom::ImageData* imageData, ErrorResult*) {
mImageData = imageData;
}
TexImageSourceAdapter(const dom::Element* domElem, ErrorResult* const out_error) {
mDomElem = domElem;
mOut_error = out_error;
}
--- a/dom/canvas/WebGLTextureUpload.cpp
+++ b/dom/canvas/WebGLTextureUpload.cpp
@@ -8,16 +8,17 @@
#include <algorithm>
#include "CanvasUtils.h"
#include "gfxPrefs.h"
#include "GLBlitHelper.h"
#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"
#include "mozilla/Unused.h"
#include "ScopedGLHelpers.h"
#include "TexUnpackBlob.h"
#include "WebGLBuffer.h"
#include "WebGLContext.h"
@@ -206,16 +207,45 @@ FromPboOffset(WebGLContext* webgl, const
const bool isClientData = false;
const auto ptr = (const uint8_t*)pboOffset;
return MakeUnique<webgl::TexUnpackBytes>(webgl, target, width, height, depth,
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,
const dom::ImageData& imageData, dom::Uint8ClampedArray* scopedArr)
{
DebugOnly<bool> inited = scopedArr->Init(imageData.GetDataObject());
MOZ_ASSERT(inited);
scopedArr->ComputeLengthAndData();
@@ -375,16 +405,21 @@ WebGLContext::From(const char* funcName,
*(src.mPboOffset));
}
if (mBoundPixelUnpackBuffer) {
ErrorInvalidOperation("%s: PIXEL_UNPACK_BUFFER must be null.", funcName);
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);
}
if (src.mDomElem) {
return FromDomElem(funcName, target, width, height, depth, *(src.mDomElem),
src.mOut_error);