Bug 1324924 - Add implementation for ImageBitmaps. - r=daoshengmu draft
authorJeff Gilbert <jgilbert@mozilla.com>
Tue, 20 Dec 2016 15:03:50 -0800
changeset 451753 baf853e6549ef27b4c982f09bc228794ce5030a5
parent 451752 77b4efa9426f0d2f0aac051ab637a1c81bc159a2
child 451807 b02f29a0abc9c418862e27acf5e6ebb0c675d44b
push id39282
push userbmo:jgilbert@mozilla.com
push dateTue, 20 Dec 2016 23:12:57 +0000
reviewersdaoshengmu
bugs1324924
milestone53.0a1
Bug 1324924 - Add implementation for ImageBitmaps. - r=daoshengmu MozReview-Commit-ID: 8arcHOHWDzD
dom/canvas/WebGLContext.h
dom/canvas/WebGLTextureUpload.cpp
--- 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);