Bug 1176153. Have binding code grab the array buffer view type for ArrayBufferView arguments, so consumers don't have to manually use JSAPI to do it. Use the new setup in WebGL code. r=smaug
authorBoris Zbarsky <bzbarsky@mit.edu>
Wed, 24 Jun 2015 08:10:15 -0700
changeset 268232 5b6617a653cc6a7d3b13abafa9bb8a663b9b8d95
parent 268231 d12f46ccb758b83e304ecc5e68d59eace4d0303f
child 268233 1e2fe1098aabedc00f44649f96188aca049ceacb
push id4932
push userjlund@mozilla.com
push dateMon, 10 Aug 2015 18:23:06 +0000
treeherdermozilla-esr52@6dd5a4f5f745 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1176153
milestone41.0a1
Bug 1176153. Have binding code grab the array buffer view type for ArrayBufferView arguments, so consumers don't have to manually use JSAPI to do it. Use the new setup in WebGL code. r=smaug
dom/bindings/TypedArray.h
dom/canvas/WebGL2ContextTextures.cpp
dom/canvas/WebGLContextGL.cpp
--- a/dom/bindings/TypedArray.h
+++ b/dom/bindings/TypedArray.h
@@ -185,16 +185,58 @@ private:
       memcpy(buf, data, length*sizeof(T));
     }
     return obj;
   }
 
   TypedArray(const TypedArray&) = delete;
 };
 
+template<JSObject* UnwrapArray(JSObject*),
+         void GetLengthAndData(JSObject*, uint32_t*, uint8_t**),
+         js::Scalar::Type GetViewType(JSObject*)>
+struct ArrayBufferView_base : public TypedArray_base<uint8_t, UnwrapArray,
+                                                     GetLengthAndData> {
+private:
+  typedef TypedArray_base<uint8_t, UnwrapArray, GetLengthAndData> Base;
+
+public:
+  ArrayBufferView_base()
+    : Base()
+  {
+  }
+
+  explicit ArrayBufferView_base(ArrayBufferView_base&& aOther)
+    : Base(Move(aOther)),
+      mType(aOther.mType)
+  {
+    aOther.mType = js::Scalar::MaxTypedArrayViewType;
+  }
+
+private:
+  js::Scalar::Type mType;
+
+public:
+  inline bool Init(JSObject* obj)
+  {
+    if (!Base::Init(obj)) {
+      return false;
+    }
+
+    mType = GetViewType(this->Obj());
+    return true;
+  }
+
+  inline js::Scalar::Type Type() const
+  {
+    MOZ_ASSERT(this->inited());
+    return mType;
+  }
+};
+
 typedef TypedArray<int8_t, js::UnwrapInt8Array, JS_GetInt8ArrayData,
                    js::GetInt8ArrayLengthAndData, JS_NewInt8Array>
         Int8Array;
 typedef TypedArray<uint8_t, js::UnwrapUint8Array, JS_GetUint8ArrayData,
                    js::GetUint8ArrayLengthAndData, JS_NewUint8Array>
         Uint8Array;
 typedef TypedArray<uint8_t, js::UnwrapUint8ClampedArray, JS_GetUint8ClampedArrayData,
                    js::GetUint8ClampedArrayLengthAndData, JS_NewUint8ClampedArray>
@@ -212,17 +254,19 @@ typedef TypedArray<uint32_t, js::UnwrapU
                    js::GetUint32ArrayLengthAndData, JS_NewUint32Array>
         Uint32Array;
 typedef TypedArray<float, js::UnwrapFloat32Array, JS_GetFloat32ArrayData,
                    js::GetFloat32ArrayLengthAndData, JS_NewFloat32Array>
         Float32Array;
 typedef TypedArray<double, js::UnwrapFloat64Array, JS_GetFloat64ArrayData,
                    js::GetFloat64ArrayLengthAndData, JS_NewFloat64Array>
         Float64Array;
-typedef TypedArray_base<uint8_t, js::UnwrapArrayBufferView, js::GetArrayBufferViewLengthAndData>
+typedef ArrayBufferView_base<js::UnwrapArrayBufferView,
+                             js::GetArrayBufferViewLengthAndData,
+                             JS_GetArrayBufferViewType>
         ArrayBufferView;
 typedef TypedArray<uint8_t, js::UnwrapArrayBuffer, JS_GetArrayBufferData,
                    js::GetArrayBufferLengthAndData, JS_NewArrayBuffer>
         ArrayBuffer;
 
 typedef TypedArray<int8_t, js::UnwrapSharedInt8Array, JS_GetSharedInt8ArrayData,
                    js::GetSharedInt8ArrayLengthAndData, JS_NewSharedInt8Array>
         SharedInt8Array;
@@ -245,17 +289,19 @@ typedef TypedArray<uint32_t, js::UnwrapS
                    js::GetSharedUint32ArrayLengthAndData, JS_NewSharedUint32Array>
         SharedUint32Array;
 typedef TypedArray<float, js::UnwrapSharedFloat32Array, JS_GetSharedFloat32ArrayData,
                    js::GetSharedFloat32ArrayLengthAndData, JS_NewSharedFloat32Array>
         SharedFloat32Array;
 typedef TypedArray<double, js::UnwrapSharedFloat64Array, JS_GetSharedFloat64ArrayData,
                    js::GetSharedFloat64ArrayLengthAndData, JS_NewSharedFloat64Array>
         SharedFloat64Array;
-typedef TypedArray_base<uint8_t, js::UnwrapSharedArrayBufferView, js::GetSharedArrayBufferViewLengthAndData>
+typedef ArrayBufferView_base<js::UnwrapSharedArrayBufferView,
+                             js::GetSharedArrayBufferViewLengthAndData,
+                             JS_GetSharedArrayBufferViewType>
         SharedArrayBufferView;
 typedef TypedArray<uint8_t, js::UnwrapSharedArrayBuffer, JS_GetSharedArrayBufferData,
                    js::GetSharedArrayBufferLengthAndData, JS_NewSharedArrayBuffer>
         SharedArrayBuffer;
 
 // A class for converting an nsTArray to a TypedArray
 // Note: A TypedArrayCreator must not outlive the nsTArray it was created from.
 //       So this is best used to pass from things that understand nsTArray to
--- a/dom/canvas/WebGL2ContextTextures.cpp
+++ b/dom/canvas/WebGL2ContextTextures.cpp
@@ -219,17 +219,17 @@ WebGL2Context::TexImage3D(GLenum target,
         dataLength = 0;
         jsArrayType = js::Scalar::MaxTypedArrayViewType;
     } else {
         const ArrayBufferView& view = pixels.Value();
         view.ComputeLengthAndData();
 
         data = view.Data();
         dataLength = view.Length();
-        jsArrayType = JS_GetArrayBufferViewType(view.Obj());
+        jsArrayType = view.Type();
     }
 
     const WebGLTexImageFunc func = WebGLTexImageFunc::TexImage;
     const WebGLTexDimensions dims = WebGLTexDimensions::Tex3D;
 
     if (!ValidateTexImageTarget(target, func, dims))
         return;
 
@@ -362,17 +362,17 @@ WebGL2Context::TexSubImage3D(GLenum rawT
     {
         return;
     }
 
     if (type != existingType) {
         return ErrorInvalidOperation("texSubImage3D: type differs from that of the existing image");
     }
 
-    js::Scalar::Type jsArrayType = JS_GetArrayBufferViewType(view.Obj());
+    js::Scalar::Type jsArrayType = view.Type();
     void* data = view.Data();
     size_t dataLength = view.Length();
 
     if (!ValidateTexInputData(type, jsArrayType, func, dims))
         return;
 
     const size_t bitsPerTexel = GetBitsPerTexel(existingEffectiveInternalFormat);
     MOZ_ASSERT((bitsPerTexel % 8) == 0); // should not have compressed formats here.
--- a/dom/canvas/WebGLContextGL.cpp
+++ b/dom/canvas/WebGLContextGL.cpp
@@ -2028,17 +2028,17 @@ WebGLContext::ReadPixels(GLint x, GLint 
         requiredDataType = js::Scalar::Uint16;
         break;
 
     default:
         MOZ_CRASH("bad `type`");
     }
 
     const ArrayBufferView& pixbuf = pixels.Value();
-    int dataType = JS_GetArrayBufferViewType(pixbuf.Obj());
+    int dataType = pixbuf.Type();
 
     // Check the pixels param type
     if (dataType != requiredDataType)
         return ErrorInvalidOperation("readPixels: Mismatched type/pixels types");
 
     // Check the pixels param size
     CheckedUint32 checked_neededByteLength =
         GetImageSize(height, width, 1, bytesPerPixel, mPixelStorePackAlignment);
@@ -3406,17 +3406,17 @@ WebGLContext::TexImage2D(GLenum rawTarge
         length = 0;
         jsArrayType = js::Scalar::MaxTypedArrayViewType;
     } else {
         const ArrayBufferView& view = pixels.Value();
         view.ComputeLengthAndData();
 
         data = view.Data();
         length = view.Length();
-        jsArrayType = JS_GetArrayBufferViewType(view.Obj());
+        jsArrayType = view.Type();
     }
 
     if (!ValidateTexImageTarget(rawTarget, WebGLTexImageFunc::TexImage, WebGLTexDimensions::Tex2D))
         return;
 
     return TexImage2D_base(rawTarget, level, internalformat, width, height, 0, border, format, type,
                            data, length, jsArrayType,
                            WebGLTexelFormat::Auto, false);
@@ -3605,18 +3605,17 @@ WebGLContext::TexSubImage2D(GLenum rawTa
     const ArrayBufferView& view = pixels.Value();
     view.ComputeLengthAndData();
 
     if (!ValidateTexImageTarget(rawTarget, WebGLTexImageFunc::TexSubImage, WebGLTexDimensions::Tex2D))
         return;
 
     return TexSubImage2D_base(rawTarget, level, xoffset, yoffset,
                               width, height, 0, format, type,
-                              view.Data(), view.Length(),
-                              JS_GetArrayBufferViewType(view.Obj()),
+                              view.Data(), view.Length(), view.Type(),
                               WebGLTexelFormat::Auto, false);
 }
 
 void
 WebGLContext::TexSubImage2D(GLenum target, GLint level,
                             GLint xoffset, GLint yoffset,
                             GLenum format, GLenum type, ImageData* pixels,
                             ErrorResult& rv)