mirror of
https://git.sr.ht/~eliasnaur/gio
synced 2026-07-01 07:35:40 +00:00
ui/app: (wasm) replace TypedArrayOf with the CopyBytes* API
syscall/js.TypedArrayOf is going away in Go 1.13 and is replaced by the CopyBytesToGo, CopyBytesToJS. Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
@@ -387,6 +387,34 @@
|
||||
mem().setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16));
|
||||
},
|
||||
|
||||
// func copyBytesToGo(dst []byte, src ref) (int, bool)
|
||||
"syscall/js.copyBytesToGo": (sp) => {
|
||||
const dst = loadSlice(sp + 8);
|
||||
const src = loadValue(sp + 32);
|
||||
if (!(src instanceof Uint8Array)) {
|
||||
mem().setUint8(sp + 48, 0);
|
||||
return;
|
||||
}
|
||||
const toCopy = src.subarray(0, dst.length);
|
||||
dst.set(toCopy);
|
||||
setInt64(sp + 40, toCopy.length);
|
||||
mem().setUint8(sp + 48, 1);
|
||||
},
|
||||
|
||||
// func copyBytesToJS(dst ref, src []byte) (int, bool)
|
||||
"syscall/js.copyBytesToJS": (sp) => {
|
||||
const dst = loadValue(sp + 8);
|
||||
const src = loadSlice(sp + 16);
|
||||
if (!(dst instanceof Uint8Array)) {
|
||||
mem().setUint8(sp + 48, 0);
|
||||
return;
|
||||
}
|
||||
const toCopy = src.subarray(0, dst.length);
|
||||
dst.set(toCopy);
|
||||
setInt64(sp + 40, toCopy.length);
|
||||
mem().setUint8(sp + 48, 1);
|
||||
},
|
||||
|
||||
"debug": (value) => {
|
||||
console.log(value);
|
||||
},
|
||||
@@ -403,7 +431,6 @@
|
||||
true,
|
||||
false,
|
||||
global,
|
||||
this._inst.exports.mem,
|
||||
this,
|
||||
];
|
||||
this._refs = new Map();
|
||||
@@ -415,9 +442,13 @@
|
||||
let offset = 4096;
|
||||
|
||||
const strPtr = (str) => {
|
||||
let ptr = offset;
|
||||
new Uint8Array(mem.buffer, offset, str.length + 1).set(encoder.encode(str + "\0"));
|
||||
offset += str.length + (8 - (str.length % 8));
|
||||
const ptr = offset;
|
||||
const bytes = encoder.encode(str + "\0");
|
||||
new Uint8Array(mem.buffer, offset, bytes.length).set(bytes);
|
||||
offset += bytes.length;
|
||||
if (offset % 8 !== 0) {
|
||||
offset += 8 - (offset % 8);
|
||||
}
|
||||
return ptr;
|
||||
};
|
||||
|
||||
|
||||
@@ -245,9 +245,7 @@ func (f *Functions) RenderbufferStorage(target, internalformat Enum, width, heig
|
||||
func (f *Functions) ReadPixels(x, y, width, height int, format, ty Enum, data []byte) {
|
||||
f.resizeByteBuffer(len(data))
|
||||
f.Ctx.Call("readPixels", x, y, width, height, int(format), int(ty), f.byteBuf)
|
||||
sub := f.byteBuf.Call("subarray", 0, len(data))
|
||||
d := js.TypedArrayOf(data)
|
||||
d.Call("set", sub)
|
||||
js.CopyBytesToGo(data, f.byteBuf)
|
||||
}
|
||||
func (f *Functions) Scissor(x, y, width, height int32) {
|
||||
f.Ctx.Call("scissor", x, y, width, height)
|
||||
@@ -294,9 +292,7 @@ func (f *Functions) byteArrayOf(data []byte) js.Value {
|
||||
return js.Null()
|
||||
}
|
||||
f.resizeByteBuffer(len(data))
|
||||
s := js.TypedArrayOf(data)
|
||||
f.byteBuf.Call("set", s)
|
||||
s.Release()
|
||||
js.CopyBytesToJS(f.byteBuf, data)
|
||||
return f.byteBuf
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user