Skip to content
This repository has been archived by the owner on Dec 26, 2023. It is now read-only.

remove gopherjs dep #2

Merged
merged 1 commit into from Oct 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions context2d.go
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package canvas
Expand Down
1 change: 1 addition & 0 deletions context2d_js.go
@@ -1,3 +1,4 @@
//go:build js
// +build js

package canvas
Expand Down
1 change: 1 addition & 0 deletions draw2d_path_font.go
@@ -1,3 +1,4 @@
//go:build !nofont
// +build !nofont

package canvas
Expand Down
1 change: 1 addition & 0 deletions draw2d_path_nofont.go
@@ -1,3 +1,4 @@
//go:build nofont
// +build nofont

package canvas
Expand Down
1 change: 1 addition & 0 deletions draw2d_text.go
@@ -1,3 +1,4 @@
//go:build ignore
// +build ignore

// Copyright 2010 The draw2d Authors. All rights reserved.
Expand Down
1 change: 1 addition & 0 deletions font_darwin.go
@@ -1,3 +1,4 @@
//go:build !js
// +build !js

package canvas
Expand Down
1 change: 1 addition & 0 deletions font_database.go
@@ -1,3 +1,4 @@
//go:build !nofont || !wx
// +build !nofont !wx

package canvas
Expand Down
1 change: 1 addition & 0 deletions font_database_nofont.go
@@ -1,3 +1,4 @@
//go:build nofont || wx
// +build nofont wx

package canvas
Expand Down
1 change: 1 addition & 0 deletions font_init.go
@@ -1,3 +1,4 @@
//go:build !nofont || !wx
// +build !nofont !wx

package canvas
Expand Down
2 changes: 1 addition & 1 deletion gc_js.go
Expand Up @@ -404,7 +404,7 @@ func (c *WebContext2D) LineJoin() LineJoin {
}

func (c *WebContext2D) SetLineDash(dash []float64) {
ar, _ := jsutil.SliceToTypedArray(dash)
ar := jsutil.SliceToTypedArray(dash)
c.ctx2d.Call("setLineDash", ar)
}

Expand Down
2 changes: 1 addition & 1 deletion gc_js_weapp.go
Expand Up @@ -16,7 +16,7 @@ func NewWebContext2D(width, height int) Context2D {

func (c *WebContext2D) SetImage(img image.Image, dx float64, dy float64) {
rgba := imageToNRGBA(img)
data, _ := jsutil.SliceToTypedArray(rgba.Pix)
data := jsutil.SliceToTypedArray(rgba.Pix)
//p2 := jsId.Invoke(rgba.Pix)
//data := js.Global.Get("Uint8ClampedArray").New(4 * img.Bounds().Dx() * img.Bounds().Dy())
//jsCopy.Invoke(data, p2)
Expand Down
2 changes: 1 addition & 1 deletion gc_js_web.go
Expand Up @@ -19,7 +19,7 @@ func NewWebContext2D(width, height int) Context2D {

func (c *WebContext2D) SetImage(img image.Image, dx float64, dy float64) {
nrgba := imageToNRGBA(img)
data, _ := jsutil.SliceToTypedArray(nrgba.Pix)
data := jsutil.SliceToTypedArray(nrgba.Pix)
imdata := c.ctx2d.Call("createImageData", nrgba.Rect.Dx(), nrgba.Rect.Dy())
imdata.Get("data").Call("set", data)
c.ctx2d.Call("putImageData", imdata, dx, dy)
Expand Down
1 change: 1 addition & 0 deletions gc_js_wegame.go
@@ -1,3 +1,4 @@
//go:build wegame
// +build wegame

package canvas
Expand Down
2 changes: 1 addition & 1 deletion gc_js_wx.go
Expand Up @@ -32,7 +32,7 @@ var (

func (c *WebContext2D) SetImage(img image.Image, dx float64, dy float64) {
nrgba := imageToNRGBA(img)
data, _ := jsutil.SliceToTypedArray(nrgba.Pix)
data := jsutil.SliceToTypedArray(nrgba.Pix)
imdata := c.ctx2d.Call("createImageData", nrgba.Rect.Dx(), nrgba.Rect.Dy())
imdata.Get("data").Call("set", data)
c.ctx2d.Call("putImageData", imdata, dx, dy)
Expand Down
1 change: 0 additions & 1 deletion go.mod
Expand Up @@ -5,6 +5,5 @@ go 1.16
require (
github.com/esimov/stackblur-go v1.0.1-0.20190121110005-00e727e3c7a9
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
github.com/gopherjs/gopherjs v0.0.0-20211004101933-6b77bd30416d
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
)
574 changes: 0 additions & 574 deletions go.sum

Large diffs are not rendered by default.

45 changes: 0 additions & 45 deletions jsutil/go112_js.go

This file was deleted.

88 changes: 0 additions & 88 deletions jsutil/go113_gopherjs.go

This file was deleted.

85 changes: 10 additions & 75 deletions jsutil/go113_js.go → jsutil/slice_js.go
Expand Up @@ -12,17 +12,14 @@
// See the License for the specific language governing permissions and
// limitations under the License.

//go:build go1.13
// +build go1.13
// +build wasm

package jsutil

import (
"fmt"
"reflect"
"runtime"
"syscall/js"
"unsafe"
)

func Uint8ArrayToSlice(value js.Value) []byte {
Expand All @@ -35,68 +32,6 @@ func ArrayBufferToSlice(value js.Value) []byte {
return Uint8ArrayToSlice(js.Global().Get("Uint8Array").New(value))
}

func sliceToByteSlice(s interface{}) (bs []byte) {
switch s := s.(type) {
case []int8:
h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
bs = *(*[]byte)(unsafe.Pointer(h))
runtime.KeepAlive(s)
case []int16:
h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
h.Len *= 2
h.Cap *= 2
bs = *(*[]byte)(unsafe.Pointer(h))
runtime.KeepAlive(s)
case []int32:
h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
h.Len *= 4
h.Cap *= 4
bs = *(*[]byte)(unsafe.Pointer(h))
runtime.KeepAlive(s)
case []int64:
h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
h.Len *= 8
h.Cap *= 8
bs = *(*[]byte)(unsafe.Pointer(h))
runtime.KeepAlive(s)
case []uint8:
return s
case []uint16:
h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
h.Len *= 2
h.Cap *= 2
bs = *(*[]byte)(unsafe.Pointer(h))
runtime.KeepAlive(s)
case []uint32:
h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
h.Len *= 4
h.Cap *= 4
bs = *(*[]byte)(unsafe.Pointer(h))
runtime.KeepAlive(s)
case []uint64:
h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
h.Len *= 8
h.Cap *= 8
bs = *(*[]byte)(unsafe.Pointer(h))
runtime.KeepAlive(s)
case []float32:
h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
h.Len *= 4
h.Cap *= 4
bs = *(*[]byte)(unsafe.Pointer(h))
runtime.KeepAlive(s)
case []float64:
h := (*reflect.SliceHeader)(unsafe.Pointer(&s))
h.Len *= 8
h.Cap *= 8
bs = *(*[]byte)(unsafe.Pointer(h))
runtime.KeepAlive(s)
default:
panic(fmt.Sprintf("jsutil: unexpected value at sliceToBytesSlice: %T", s))
}
return
}

var temporaryBuffer = js.Global().Get("ArrayBuffer").New(16)

func getTemporaryUint8Array(size int) js.Value {
Expand All @@ -109,47 +44,47 @@ func getTemporaryUint8Array(size int) js.Value {
return js.Global().Get("Uint8Array").New(temporaryBuffer, 0, size)
}

func SliceToTypedArray(s interface{}) (js.Value, func()) {
func SliceToTypedArray(s interface{}) js.Value {
switch s := s.(type) {
case []int8:
a := getTemporaryUint8Array(len(s))
js.CopyBytesToJS(a, sliceToByteSlice(s))
buf := a.Get("buffer")
return js.Global().Get("Int8Array").New(buf, a.Get("byteOffset"), a.Get("byteLength")), func() {}
return js.Global().Get("Int8Array").New(buf, a.Get("byteOffset"), a.Get("byteLength"))
case []int16:
a := getTemporaryUint8Array(len(s) * 2)
js.CopyBytesToJS(a, sliceToByteSlice(s))
buf := a.Get("buffer")
return js.Global().Get("Int16Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/2), func() {}
return js.Global().Get("Int16Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/2)
case []int32:
a := getTemporaryUint8Array(len(s) * 4)
js.CopyBytesToJS(a, sliceToByteSlice(s))
buf := a.Get("buffer")
return js.Global().Get("Int32Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/4), func() {}
return js.Global().Get("Int32Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/4)
case []uint8:
a := getTemporaryUint8Array(len(s))
js.CopyBytesToJS(a, s)
return a, func() {}
return a
case []uint16:
a := getTemporaryUint8Array(len(s) * 2)
js.CopyBytesToJS(a, sliceToByteSlice(s))
buf := a.Get("buffer")
return js.Global().Get("Uint16Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/2), func() {}
return js.Global().Get("Uint16Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/2)
case []uint32:
a := getTemporaryUint8Array(len(s) * 4)
js.CopyBytesToJS(a, sliceToByteSlice(s))
buf := a.Get("buffer")
return js.Global().Get("Uint32Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/4), func() {}
return js.Global().Get("Uint32Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/4)
case []float32:
a := getTemporaryUint8Array(len(s) * 4)
js.CopyBytesToJS(a, sliceToByteSlice(s))
buf := a.Get("buffer")
return js.Global().Get("Float32Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/4), func() {}
return js.Global().Get("Float32Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/4)
case []float64:
a := getTemporaryUint8Array(len(s) * 8)
js.CopyBytesToJS(a, sliceToByteSlice(s))
buf := a.Get("buffer")
return js.Global().Get("Float64Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/8), func() {}
return js.Global().Get("Float64Array").New(buf, a.Get("byteOffset"), a.Get("byteLength").Int()/8)
default:
panic(fmt.Sprintf("jsutil: unexpected value at SliceToTypedArray: %T", s))
}
Expand Down