[Webkit-unassigned] [Bug 120112] Typed Arrays have no public facing API

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Tue Oct 13 11:31:37 PDT 2015


https://bugs.webkit.org/show_bug.cgi?id=120112

--- Comment #24 from Dominic Szablewski <dominic.szablewski at gmail.com> ---
> [Passing pointer to size_t to receive byteLength] I don't believe we have any other api that behaves in this way.
All API functions that may throw an exception use this semantic (if I understood your concerns correctly).

JSValueRef exception = NULL;
JSValueToObject(ctx, value, &exception);

I would argue that doing the same thing with a size_t is not really different. However...

> Mixing and matching what unit the length you're using is a recipe for mistakes.

Point taken. 

So I propose the following set of functions:

JSTypedArrayType JSObjectGetTypedArrayType(JSContextRef ctx, JSObjectRef object);
JSObjectRef JSObjectMakeTypedArray(JSContextRef ctx, JSTypedArrayType arrayType, size_t numElements);
void * JSObjectGetTypedArrayDataPtr(JSContextRef ctx, JSObjectRef object);
size_t JSObjectGetTypedArrayByteLength(JSContextRef ctx, JSObjectRef object);
size_t JSObjectGetTypedArrayNumElements(JSContextRef ctx, JSObjectRef object);


> Also this API fails to allow sharing of data allocated elsewhere (...) Most other data related APIs on OS X allow specifying the external buffer

The JSC API *nowhere* adheres to this. Everything is copied all over the place. Even the somewhat lower level JSString functions copy everything.

Also, as far as I can tell, none of the existing Typed Array or ArrayBuffer constructors allow for using an external data pointer. The data is always allocated internally. The existing WebGL implementation in WebKit gets along just fine with this.

My proposed Typed Array API would still allow for most use cases to avoid copying. E.g. in Ejecta, the Canvas2D .getImageData() functions uses glReadPixels() directly with a Typed Array dataPtr I.e.:


void *dataPtr = JSObjectGetTypedArrayDataPtr(ctx, array);
size_t byteLength = JSObjectGetTypedArrayByteLength(ctx, array);
if( byteLength >= width * height * bytesPerPixel ) {
    glReadPixels(x, y, width, height, format, type, dataPtr);
}


An additional "JSObjectMakeTypedArrayWithDataPtrNoCopy" function (not sure what's the right phrasing here) may have its place, but I still don't believe it's critical and it may even be more confusing than helpful.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-unassigned/attachments/20151013/6475eaff/attachment-0001.html>


More information about the webkit-unassigned mailing list