From 4926841c48be94861e2b4a0c419367a2168940a7 Mon Sep 17 00:00:00 2001 From: aarzilli Date: Tue, 19 Mar 2019 12:00:54 +0100 Subject: [PATCH] add support for gomobile missing features and problems: - stuff gets drawn under the status bar - orientation changes aren't handled at all and after the first one the app will not respond to touches correctly - pinch or any other gesture is unsupported - scrolling by dragging anywhere is unsupported - no way to show/hide software keyboard (either automatically or manually) - software rendering is probably too slow for ARM CPUs --- _examples/demo/overview.go | 3 + _examples/overview/overview.go | 3 + clipboard/clipboard_linux.go | 2 + clipboard/clipboard_other.go | 17 + context.go | 28 - go.mod | 7 +- go.sum | 9 + gomobile.go | 372 ++ gomobile_android.go | 5 + gomobile_linux.go | 6 + masterwindow.go | 255 + shiny.go | 206 +- .../x/exp/shiny/driver/gldriver/cocoa.m | 1 + .../x/exp/shiny/driver/gldriver/context.go | 2 + .../x/exp/shiny/driver/gldriver/other.go | 3 + .../x/exp/shiny/driver/gldriver/screen.go | 2 +- .../exp/shiny/driver/internal/event/event.go | 22 +- .../exp/shiny/driver/internal/win32/win32.go | 10 +- vendor/golang.org/x/image/font/font.go | 12 + .../x/mobile/app/GoNativeActivity.java | 67 + vendor/golang.org/x/mobile/app/android.c | 200 + vendor/golang.org/x/mobile/app/android.go | 819 ++++ vendor/golang.org/x/mobile/app/app.go | 213 + .../golang.org/x/mobile/app/darwin_desktop.go | 496 ++ .../golang.org/x/mobile/app/darwin_desktop.m | 249 + vendor/golang.org/x/mobile/app/darwin_ios.go | 216 + vendor/golang.org/x/mobile/app/darwin_ios.m | 165 + vendor/golang.org/x/mobile/app/doc.go | 85 + .../x/mobile/app/internal/callfn/callfn.go | 17 + .../x/mobile/app/internal/callfn/callfn_386.s | 11 + .../mobile/app/internal/callfn/callfn_amd64.s | 11 + .../x/mobile/app/internal/callfn/callfn_arm.s | 11 + .../mobile/app/internal/callfn/callfn_arm64.s | 11 + vendor/golang.org/x/mobile/app/shiny.go | 70 + vendor/golang.org/x/mobile/app/x11.c | 173 + vendor/golang.org/x/mobile/app/x11.go | 122 + .../x/mobile/event/lifecycle/lifecycle.go | 2 +- .../golang.org/x/mobile/event/mouse/mouse.go | 2 +- .../golang.org/x/mobile/event/touch/touch.go | 72 + vendor/golang.org/x/mobile/exp/f32/affine.go | 109 + vendor/golang.org/x/mobile/exp/f32/f32.go | 93 + vendor/golang.org/x/mobile/exp/f32/gen.go | 48 + vendor/golang.org/x/mobile/exp/f32/mat3.go | 63 + vendor/golang.org/x/mobile/exp/f32/mat4.go | 193 + vendor/golang.org/x/mobile/exp/f32/table.go | 4105 +++++++++++++++++ vendor/golang.org/x/mobile/exp/f32/vec3.go | 49 + vendor/golang.org/x/mobile/exp/f32/vec4.go | 47 + .../exp/gl/glutil/context_darwin_desktop.go | 95 + .../x/mobile/exp/gl/glutil/context_x11.go | 105 + .../golang.org/x/mobile/exp/gl/glutil/doc.go | 6 + .../x/mobile/exp/gl/glutil/glimage.go | 333 ++ .../x/mobile/exp/gl/glutil/glutil.go | 75 + vendor/golang.org/x/mobile/gl/fn.go | 3 + vendor/golang.org/x/mobile/gl/gendebug.go | 624 ++- vendor/golang.org/x/mobile/gl/gl.go | 37 +- vendor/golang.org/x/mobile/gl/gldebug.go | 55 +- vendor/golang.org/x/mobile/gl/interface.go | 17 +- vendor/golang.org/x/mobile/gl/types_debug.go | 8 +- vendor/golang.org/x/mobile/gl/types_prod.go | 9 +- vendor/golang.org/x/mobile/gl/work.c | 14 +- vendor/golang.org/x/mobile/gl/work.go | 7 +- vendor/golang.org/x/mobile/gl/work.h | 5 + vendor/golang.org/x/mobile/gl/work_windows.go | 11 +- .../mobile/internal/mobileinit/ctx_android.go | 124 + .../mobile/internal/mobileinit/mobileinit.go | 11 + .../internal/mobileinit/mobileinit_android.go | 93 + .../internal/mobileinit/mobileinit_ios.go | 38 + vendor/golang.org/x/sys/windows/aliases.go | 13 + .../x/sys/windows/asm_windows_386.s | 4 +- .../x/sys/windows/asm_windows_amd64.s | 2 +- .../x/sys/windows/asm_windows_arm.s | 11 + .../golang.org/x/sys/windows/dll_windows.go | 18 +- vendor/golang.org/x/sys/windows/env_unset.go | 15 - .../golang.org/x/sys/windows/env_windows.go | 6 +- .../x/sys/windows/memory_windows.go | 26 + vendor/golang.org/x/sys/windows/mksyscall.go | 2 +- vendor/golang.org/x/sys/windows/race.go | 2 +- vendor/golang.org/x/sys/windows/race0.go | 2 +- .../x/sys/windows/security_windows.go | 65 +- vendor/golang.org/x/sys/windows/service.go | 40 + vendor/golang.org/x/sys/windows/syscall.go | 9 +- .../x/sys/windows/syscall_windows.go | 261 +- .../{ztypes_windows.go => types_windows.go} | 297 +- ...es_windows_386.go => types_windows_386.go} | 2 +- ...indows_amd64.go => types_windows_amd64.go} | 2 +- .../x/sys/windows/types_windows_arm.go | 22 + .../x/sys/windows/zsyscall_windows.go | 779 +++- vendor/modules.txt | 16 +- 88 files changed, 11441 insertions(+), 507 deletions(-) create mode 100644 clipboard/clipboard_other.go create mode 100644 gomobile.go create mode 100644 gomobile_android.go create mode 100644 gomobile_linux.go create mode 100644 masterwindow.go create mode 100644 vendor/golang.org/x/mobile/app/GoNativeActivity.java create mode 100644 vendor/golang.org/x/mobile/app/android.c create mode 100644 vendor/golang.org/x/mobile/app/android.go create mode 100644 vendor/golang.org/x/mobile/app/app.go create mode 100644 vendor/golang.org/x/mobile/app/darwin_desktop.go create mode 100644 vendor/golang.org/x/mobile/app/darwin_desktop.m create mode 100644 vendor/golang.org/x/mobile/app/darwin_ios.go create mode 100644 vendor/golang.org/x/mobile/app/darwin_ios.m create mode 100644 vendor/golang.org/x/mobile/app/doc.go create mode 100644 vendor/golang.org/x/mobile/app/internal/callfn/callfn.go create mode 100644 vendor/golang.org/x/mobile/app/internal/callfn/callfn_386.s create mode 100644 vendor/golang.org/x/mobile/app/internal/callfn/callfn_amd64.s create mode 100644 vendor/golang.org/x/mobile/app/internal/callfn/callfn_arm.s create mode 100644 vendor/golang.org/x/mobile/app/internal/callfn/callfn_arm64.s create mode 100644 vendor/golang.org/x/mobile/app/shiny.go create mode 100644 vendor/golang.org/x/mobile/app/x11.c create mode 100644 vendor/golang.org/x/mobile/app/x11.go create mode 100644 vendor/golang.org/x/mobile/event/touch/touch.go create mode 100644 vendor/golang.org/x/mobile/exp/f32/affine.go create mode 100644 vendor/golang.org/x/mobile/exp/f32/f32.go create mode 100644 vendor/golang.org/x/mobile/exp/f32/gen.go create mode 100644 vendor/golang.org/x/mobile/exp/f32/mat3.go create mode 100644 vendor/golang.org/x/mobile/exp/f32/mat4.go create mode 100644 vendor/golang.org/x/mobile/exp/f32/table.go create mode 100644 vendor/golang.org/x/mobile/exp/f32/vec3.go create mode 100644 vendor/golang.org/x/mobile/exp/f32/vec4.go create mode 100644 vendor/golang.org/x/mobile/exp/gl/glutil/context_darwin_desktop.go create mode 100644 vendor/golang.org/x/mobile/exp/gl/glutil/context_x11.go create mode 100644 vendor/golang.org/x/mobile/exp/gl/glutil/doc.go create mode 100644 vendor/golang.org/x/mobile/exp/gl/glutil/glimage.go create mode 100644 vendor/golang.org/x/mobile/exp/gl/glutil/glutil.go create mode 100644 vendor/golang.org/x/mobile/internal/mobileinit/ctx_android.go create mode 100644 vendor/golang.org/x/mobile/internal/mobileinit/mobileinit.go create mode 100644 vendor/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go create mode 100644 vendor/golang.org/x/mobile/internal/mobileinit/mobileinit_ios.go create mode 100644 vendor/golang.org/x/sys/windows/aliases.go create mode 100644 vendor/golang.org/x/sys/windows/asm_windows_arm.s delete mode 100644 vendor/golang.org/x/sys/windows/env_unset.go create mode 100644 vendor/golang.org/x/sys/windows/memory_windows.go rename vendor/golang.org/x/sys/windows/{ztypes_windows.go => types_windows.go} (74%) rename vendor/golang.org/x/sys/windows/{ztypes_windows_386.go => types_windows_386.go} (88%) rename vendor/golang.org/x/sys/windows/{ztypes_windows_amd64.go => types_windows_amd64.go} (88%) create mode 100644 vendor/golang.org/x/sys/windows/types_windows_arm.go diff --git a/_examples/demo/overview.go b/_examples/demo/overview.go index 07c9f78..f21b03b 100644 --- a/_examples/demo/overview.go +++ b/_examples/demo/overview.go @@ -326,6 +326,9 @@ func (od *overviewDemo) overviewMenubar(w *nucular.Window) { w.Progress(&od.Prog, 100, true) w.SliderInt(0, &od.Slider, 16, 1) w.CheckboxText("check", &od.Check) + perf := w.Master().GetPerf() + w.CheckboxText("Show perf", &perf) + w.Master().SetPerf(perf) if w.MenuItem(label.TA("Close", "LC")) { go w.Master().Close() } diff --git a/_examples/overview/overview.go b/_examples/overview/overview.go index 8077eaf..ab2ae3a 100644 --- a/_examples/overview/overview.go +++ b/_examples/overview/overview.go @@ -354,6 +354,9 @@ func (od *overviewDemo) overviewMenubar(w *nucular.Window) { w.Progress(&od.Prog, 100, true) w.SliderInt(0, &od.Slider, 16, 1) w.CheckboxText("check", &od.Check) + perf := w.Master().GetPerf() + w.CheckboxText("Show perf", &perf) + w.Master().SetPerf(perf) } if w := w.Menu(label.TA("THEME", "CC"), 180, nil); w != nil { w.Row(25).Dynamic(1) diff --git a/clipboard/clipboard_linux.go b/clipboard/clipboard_linux.go index 8a770f6..c2386fc 100644 --- a/clipboard/clipboard_linux.go +++ b/clipboard/clipboard_linux.go @@ -1,3 +1,5 @@ +// +build !android + package clipboard import ( diff --git a/clipboard/clipboard_other.go b/clipboard/clipboard_other.go new file mode 100644 index 0000000..15fe6d9 --- /dev/null +++ b/clipboard/clipboard_other.go @@ -0,0 +1,17 @@ +// +build !windows,!linux,!darwin android + +package clipboard + +func Start() { +} + +func Get() string { + return "" +} + +func GetPrimary() string { + return "" +} + +func Set(text string) { +} diff --git a/context.go b/context.go index 3bf2e77..7a90547 100644 --- a/context.go +++ b/context.go @@ -23,34 +23,6 @@ import ( "golang.org/x/mobile/event/mouse" ) -type MasterWindow interface { - context() *context - - Main() - Changed() - Close() - Closed() bool - ActivateEditor(ed *TextEditor) - - Style() *nstyle.Style - SetStyle(*nstyle.Style) - - GetPerf() bool - SetPerf(bool) - - Input() *Input - - PopupOpen(title string, flags WindowFlags, rect rect.Rect, scale bool, updateFn UpdateFn) - - Walk(WindowWalkFn) - ResetWindows() *DockSplit - - Lock() - Unlock() -} - -type WindowWalkFn func(title string, data interface{}, docked bool, splitSize int, rect rect.Rect) - const perfUpdate = false const dumpFrame = false diff --git a/go.mod b/go.mod index baef0f4..369b99c 100644 --- a/go.mod +++ b/go.mod @@ -4,8 +4,7 @@ require ( github.com/BurntSushi/xgb v0.0.0-20160522221800-27f122750802 github.com/golang/freetype v0.0.0-20161208064710-d9be45aaf745 github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad - golang.org/x/exp v0.0.0-20171209012058-072991165226 - golang.org/x/image v0.0.0-20170331233916-ce0faa1867f5 - golang.org/x/mobile v0.0.0-20170307115833-eb9032959f05 - golang.org/x/sys v0.0.0-20160717071931-a646d33e2ee3 // indirect + golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 + golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 + golang.org/x/mobile v0.0.0-20190318164015-6bd122906c08 ) diff --git a/go.sum b/go.sum index 4edc3f2..b043d17 100644 --- a/go.sum +++ b/go.sum @@ -6,9 +6,18 @@ github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad h1:eMxs9EL0Pv github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= golang.org/x/exp v0.0.0-20171209012058-072991165226 h1:sb67HiWk98LHu6TtgnfVTHraZYkXLgFRJlXcNahrXCc= golang.org/x/exp v0.0.0-20171209012058-072991165226/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 h1:idBdZTd9UioThJp8KpM/rTSinK/ChZFBE43/WtIy8zg= +golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/image v0.0.0-20170331233916-ce0faa1867f5 h1:Y8k2xgnl71xxKST1qLiv87kmWlHW0oAu9SaUXmIxE1s= golang.org/x/image v0.0.0-20170331233916-ce0faa1867f5/go.mod h1:ux5Hcp/YLpHSI86hEcLt0YII63i6oz57MZXIpbrjZUs= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 h1:KYGJGHOQy8oSi1fDlSpcZF0+juKwk/hEMv5SiwHogR0= +golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= golang.org/x/mobile v0.0.0-20170307115833-eb9032959f05 h1:SfnKURPqpZR7R25slH48KrxWWFWNkMWMkE9ntmoPgTg= golang.org/x/mobile v0.0.0-20170307115833-eb9032959f05/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= +golang.org/x/mobile v0.0.0-20190318164015-6bd122906c08 h1:REhdg1qxVTaAJcvh9BOGNgt2kd+KiUZ148XXlLp08FU= +golang.org/x/mobile v0.0.0-20190318164015-6bd122906c08/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/sys v0.0.0-20160717071931-a646d33e2ee3 h1:ZLExsLvnoqWSw6JB6k6RjWobIHGR3NG9dzVANJ7SVKc= golang.org/x/sys v0.0.0-20160717071931-a646d33e2ee3/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190312061237-fead79001313 h1:pczuHS43Cp2ktBEEmLwScxgjWsBSzdaQiKzUyf3DTTc= +golang.org/x/sys v0.0.0-20190312061237-fead79001313/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= diff --git a/gomobile.go b/gomobile.go new file mode 100644 index 0000000..c00b507 --- /dev/null +++ b/gomobile.go @@ -0,0 +1,372 @@ +// +build android nucular_mobile + +package nucular + +import ( + "encoding/binary" + "fmt" + "image" + "math/bits" + "sync/atomic" + "time" + + "github.com/aarzilli/nucular/rect" + + "golang.org/x/mobile/app" + "golang.org/x/mobile/event/lifecycle" + "golang.org/x/mobile/event/mouse" + "golang.org/x/mobile/event/paint" + "golang.org/x/mobile/event/size" + "golang.org/x/mobile/event/touch" + "golang.org/x/mobile/exp/f32" + "golang.org/x/mobile/exp/gl/glutil" + "golang.org/x/mobile/gl" + + "golang.org/x/image/font" + "golang.org/x/image/math/fixed" + "image/draw" +) + +type masterWindow struct { + masterWindowCommon + + a app.App + sz size.Event // size in pixels of screen + glctx gl.Context // OpenGL ES context + + closing bool + + screenTextureProgram gl.Program // gpu program to render a single image that fills the entire screen + screenTriangleBuf gl.Buffer // vertices of two triangles filling the entire screen + screenTextureProjectionBuf gl.Buffer // maps screenTriangleBuf triangles to a single texture + positionAttrib gl.Attrib // vertex shitter position attribute + texCoordAttrib gl.Attrib // vertex shitter a_texCoord attribute (pass-through attribute with texture coordinates) + sampleUniform gl.Uniform // fragment shitter 'sample' uniform (the screen texture) + + screenTexture gl.Texture // texture that will fill the screen + screenTextureAllocated bool // was screenTexture allocated? + + wndbuf *image.RGBA // image of the whole screen for software renderer, gets copied into screenTexture on draw +} + +func NewMasterWindowSize(flags WindowFlags, title string, sz image.Point, updatefn UpdateFn) MasterWindow { + ctx := &context{} + wnd := &masterWindow{} + + wnd.masterWindowCommonInit(ctx, flags, updatefn, wnd) + + return wnd +} + +// Shows window, runs event loop +func (mw *masterWindow) Main() { + app.Main(mw.main) +} + +func (mw *masterWindow) Close() { + mw.a.Send(lifecycle.Event{From: lifecycle.StageAlive, To: lifecycle.StageDead}) +} + +func (mw *masterWindow) Closed() bool { + mw.uilock.Lock() + defer mw.uilock.Unlock() + return mw.closing +} + +func (mw *masterWindow) main(a app.App) { + mw.a = a + go mw.updater() + for e := range a.Events() { + mw.uilock.Lock() + mw.handleEventLocked(e) + mw.uilock.Unlock() + } +} + +func (mw *masterWindow) handleEventLocked(e interface{}) { + switch e := mw.a.Filter(e).(type) { + case lifecycle.Event: + switch e.Crosses(lifecycle.StageVisible) { + case lifecycle.CrossOn: + mw.glctx, _ = e.DrawContext.(gl.Context) + mw.onStart() + if (mw.sz != size.Event{}) { + mw.a.Send(mw.sz) + } + mw.a.Send(paint.Event{}) + case lifecycle.CrossOff: + mw.closeLocked() + mw.glctx = nil + } + case size.Event: + mw.sz = e + mw.onResize() + mw.prevCmds = mw.prevCmds[:0] + if changed := atomic.LoadInt32(&mw.ctx.changed); changed < 2 { + atomic.StoreInt32(&mw.ctx.changed, 2) + } + case paint.Event: + if mw.glctx == nil || e.External || mw.wndbuf == nil { + // As we are actively painting as fast as + // we can (usually 60 FPS), skip any paint + // events sent by the system. + return + } + + mw.prevCmds = mw.prevCmds[:0] + mw.updateLocked() + case touch.Event: + changed := atomic.LoadInt32(&mw.ctx.changed) + if changed < 2 { + atomic.StoreInt32(&mw.ctx.changed, 2) + } + + mw.ctx.Input.Mouse.Pos.X = int(e.X) + mw.ctx.Input.Mouse.Pos.Y = int(e.Y) + mw.ctx.Input.Mouse.Delta = mw.ctx.Input.Mouse.Pos.Sub(mw.ctx.Input.Mouse.Prev) + + switch e.Type { + case touch.TypeBegin, touch.TypeEnd: + down := e.Type == touch.TypeBegin + + btn := &mw.ctx.Input.Mouse.Buttons[mouse.ButtonLeft] + if btn.Down == down { + break + } + + if down { + btn.ClickedPos.X = int(e.X) + btn.ClickedPos.Y = int(e.Y) + } + btn.Clicked = true + btn.Down = down + } + } +} + +func (w *masterWindow) updater() { + var down bool + for { + if down { + time.Sleep(10 * time.Millisecond) + } else { + time.Sleep(20 * time.Millisecond) + } + func() { + w.uilock.Lock() + defer w.uilock.Unlock() + if w.closing { + return + } + changed := atomic.LoadInt32(&w.ctx.changed) + if changed > 0 { + atomic.AddInt32(&w.ctx.changed, -1) + w.a.Send(paint.Event{}) + } else if gomobileBackendKeepPainting { + w.a.Send(paint.Event{}) + } else { + down = false + for _, btn := range w.ctx.Input.Mouse.Buttons { + if btn.Down { + down = true + } + } + if down { + w.a.Send(paint.Event{}) + } + } + }() + } +} + +func (w *masterWindow) onStart() { + var err error + w.screenTextureProgram, err = glutil.CreateProgram(w.glctx, screenTextureVertexShitter, screenTextureFragmentShitter) + if err != nil { + panic(err) + } + + w.screenTriangleBuf = w.glctx.CreateBuffer() + w.glctx.BindBuffer(gl.ARRAY_BUFFER, w.screenTriangleBuf) + w.glctx.BufferData(gl.ARRAY_BUFFER, f32.Bytes(binary.LittleEndian, + -1.0, 1.0, 0.0, + 1.0, 1.0, 0.0, + -1.0, -1.0, 0.0, + 1.0, -1.0, 0.0, + ), gl.STATIC_DRAW) + + w.screenTextureProjectionBuf = w.glctx.CreateBuffer() + w.glctx.BindBuffer(gl.ARRAY_BUFFER, w.screenTextureProjectionBuf) + w.glctx.BufferData(gl.ARRAY_BUFFER, f32.Bytes(binary.LittleEndian, + 0.0, 0.0, + 1.0, 0.0, + 0.0, 1.0, + 1.0, 1.0, + ), gl.STATIC_DRAW) + + w.positionAttrib = w.glctx.GetAttribLocation(w.screenTextureProgram, "position") + w.texCoordAttrib = w.glctx.GetAttribLocation(w.screenTextureProgram, "a_texCoord") + w.sampleUniform = w.glctx.GetUniformLocation(w.screenTextureProgram, "sample") +} + +func (w *masterWindow) closeLocked() { + w.closing = true + + w.glctx.DeleteProgram(w.screenTextureProgram) + w.glctx.DeleteBuffer(w.screenTriangleBuf) + w.glctx.DeleteBuffer(w.screenTextureProjectionBuf) + + if w.screenTextureAllocated { + w.glctx.DeleteTexture(w.screenTexture) + } +} + +func (w *masterWindow) onResize() { + if w.glctx == nil { + return + } + if w.screenTextureAllocated { + w.glctx.DeleteTexture(w.screenTexture) + } + + w.screenTextureAllocated = true + + w2 := roundToPower2(w.sz.WidthPx) + h2 := roundToPower2(w.sz.HeightPx) + + w.wndbuf = image.NewRGBA(image.Rect(0, 0, w2, h2)) + + fx := float32(w.sz.WidthPx) / float32(w2) + fy := float32(w.sz.HeightPx) / float32(h2) + + w.glctx.BindBuffer(gl.ARRAY_BUFFER, w.screenTextureProjectionBuf) + w.glctx.BufferData(gl.ARRAY_BUFFER, f32.Bytes(binary.LittleEndian, + 0.0, 0.0, + fx, 0.0, + 0.0, fy, + fx, fy), gl.STATIC_DRAW) + + w.screenTexture = w.glctx.CreateTexture() + w.glctx.BindTexture(gl.TEXTURE_2D, w.screenTexture) + w.glctx.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, w2, h2, gl.RGBA, gl.UNSIGNED_BYTE, w.wndbuf.Pix) + w.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) + w.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) + w.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) + w.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) +} + +func roundToPower2(x int) int { + return 1 << (bits.LeadingZeros(0) - bits.LeadingZeros(uint(x))) +} + +func (w *masterWindow) updateLocked() { + w.ctx.Windows[0].Bounds = rect.Rect{0, 0, w.sz.WidthPx, w.sz.HeightPx} + in := &w.ctx.Input + in.Mouse.clip = nk_null_rect + //TODO: when we can pop up a soft keyboard fill in.Keyboard.Text here + + var t0, t1, te time.Time + if perfUpdate || w.Perf { + t0 = time.Now() + } + + if dumpFrame && !perfUpdate { + panic("dumpFrame") + } + + w.ctx.Update() + + if perfUpdate || w.Perf { + t1 = time.Now() + } + nprimitives := w.draw() + if perfUpdate && nprimitives > 0 { + te = time.Now() + + fps := 1.0 / te.Sub(t0).Seconds() + + fmt.Printf("Update %0.4f msec = %0.4f updatefn + %0.4f draw (%d primitives) [max fps %0.2f]\n", te.Sub(t0).Seconds()*1000, t1.Sub(t0).Seconds()*1000, te.Sub(t1).Seconds()*1000, nprimitives, fps) + } + if w.Perf && nprimitives > 0 { + te = time.Now() + w.drawPerfCounter(w.wndbuf, image.Rect(0, 0, w.sz.WidthPx, w.sz.HeightPx), t0, t1, te) + } + { + s := fmt.Sprintf("Last size event %v", w.sz) + d := font.Drawer{ + Dst: w.wndbuf, + Src: image.White, + Face: w.ctx.Style.Font} + + width := d.MeasureString(s).Ceil() + + bounds := image.Rect(0, 0, w.sz.WidthPx, w.sz.HeightPx) + bounds.Min.X = bounds.Max.X - width + bounds.Min.Y = bounds.Max.Y - (w.ctx.Style.Font.Metrics().Ascent + w.ctx.Style.Font.Metrics().Descent).Ceil() + draw.Draw(w.wndbuf, bounds, image.Black, bounds.Min, draw.Src) + d.Dot = fixed.P(bounds.Min.X, bounds.Min.Y+w.ctx.Style.Font.Metrics().Ascent.Ceil()) + d.DrawString(s) + } + if dumpFrame && frameCnt < 1000 && nprimitives > 0 { + w.dumpFrame(w.wndbuf.SubImage(image.Rect(0, 0, w.sz.WidthPx, w.sz.HeightPx)).(*image.RGBA), t0, t1, te, nprimitives) + } + if nprimitives > 0 { + w.glctx.UseProgram(w.screenTextureProgram) + + bounds := w.wndbuf.Bounds() + + w.glctx.BindTexture(gl.TEXTURE_2D, w.screenTexture) + w.glctx.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, bounds.Dx(), bounds.Dy(), gl.RGBA, gl.UNSIGNED_BYTE, w.wndbuf.Pix) + + // set uniform 'sample' + w.glctx.ActiveTexture(gl.TEXTURE0) + w.glctx.BindTexture(gl.TEXTURE_2D, w.screenTexture) + w.glctx.Uniform1i(w.sampleUniform, 0) + + // position input + w.glctx.BindBuffer(gl.ARRAY_BUFFER, w.screenTriangleBuf) + w.glctx.EnableVertexAttribArray(w.positionAttrib) + w.glctx.VertexAttribPointer(w.positionAttrib, 3, gl.FLOAT, false, 0, 0) + + // a_texCoord input + w.glctx.BindBuffer(gl.ARRAY_BUFFER, w.screenTextureProjectionBuf) + w.glctx.EnableVertexAttribArray(w.texCoordAttrib) + w.glctx.VertexAttribPointer(w.texCoordAttrib, 2, gl.FLOAT, false, 0, 0) + + w.glctx.DrawArrays(gl.TRIANGLE_STRIP, 0, 4) + w.glctx.DisableVertexAttribArray(w.positionAttrib) + w.glctx.DisableVertexAttribArray(w.texCoordAttrib) + + w.a.Publish() + } +} + +func (w *masterWindow) draw() int { + contextAllCommands(w.ctx) + w.ctx.Reset() + + if !w.drawChanged() { + return 0 + } + + w.prevCmds = append(w.prevCmds[:0], w.ctx.cmds...) + + return w.ctx.Draw(w.wndbuf.SubImage(image.Rect(0, 0, w.sz.WidthPx, w.sz.HeightPx)).(*image.RGBA)) +} + +const screenTextureVertexShitter = `#version 100 +attribute vec4 position; +attribute vec2 a_texCoord; +varying vec2 v_texCoord; +void main() { + gl_Position = position; + v_texCoord = a_texCoord; +}` + +const screenTextureFragmentShitter = `#version 100 +precision mediump float; +varying vec2 v_texCoord; +uniform sampler2D sample; +void main() { + gl_FragColor = texture2D(sample, v_texCoord); +}` diff --git a/gomobile_android.go b/gomobile_android.go new file mode 100644 index 0000000..2d4bb5f --- /dev/null +++ b/gomobile_android.go @@ -0,0 +1,5 @@ +// +build android + +package nucular + +const gomobileBackendKeepPainting = false diff --git a/gomobile_linux.go b/gomobile_linux.go new file mode 100644 index 0000000..70da28a --- /dev/null +++ b/gomobile_linux.go @@ -0,0 +1,6 @@ +// +build linux,!android + +package nucular + +// The x11 backend of gomobile sucks and unless we paint constantly it will not process X11 events +const gomobileBackendKeepPainting = true diff --git a/masterwindow.go b/masterwindow.go new file mode 100644 index 0000000..1134ea9 --- /dev/null +++ b/masterwindow.go @@ -0,0 +1,255 @@ +package nucular + +import ( + "bufio" + "fmt" + "image" + "image/draw" + "image/png" + "os" + "sync" + "sync/atomic" + "time" + + "github.com/aarzilli/nucular/command" + "github.com/aarzilli/nucular/rect" + nstyle "github.com/aarzilli/nucular/style" + + "golang.org/x/image/font" + "golang.org/x/image/math/fixed" +) + +type MasterWindow interface { + context() *context + + Main() + Changed() + Close() + Closed() bool + ActivateEditor(ed *TextEditor) + + Style() *nstyle.Style + SetStyle(*nstyle.Style) + + GetPerf() bool + SetPerf(bool) + + Input() *Input + + PopupOpen(title string, flags WindowFlags, rect rect.Rect, scale bool, updateFn UpdateFn) + + Walk(WindowWalkFn) + ResetWindows() *DockSplit + + Lock() + Unlock() +} + +func NewMasterWindow(flags WindowFlags, title string, updatefn UpdateFn) MasterWindow { + return NewMasterWindowSize(flags, title, image.Point{640, 480}, updatefn) +} + +type WindowWalkFn func(title string, data interface{}, docked bool, splitSize int, rect rect.Rect) + +type masterWindowCommon struct { + ctx *context + + layout panel + + // show performance counters + Perf bool + + uilock sync.Mutex + + prevCmds []command.Command +} + +func (mw *masterWindowCommon) masterWindowCommonInit(ctx *context, flags WindowFlags, updatefn UpdateFn, wnd MasterWindow) { + ctx.Input.Mouse.valid = true + ctx.DockedWindows.Split.MinSize = 40 + + mw.layout.Flags = flags + + ctx.setupMasterWindow(&mw.layout, updatefn) + + mw.ctx = ctx + mw.ctx.mw = wnd + + mw.SetStyle(nstyle.FromTheme(nstyle.DefaultTheme, 1.0)) +} + +func (mw *masterWindowCommon) context() *context { + return mw.ctx +} + +func (mw *masterWindowCommon) Walk(fn WindowWalkFn) { + mw.ctx.Walk(fn) +} + +func (mw *masterWindowCommon) ResetWindows() *DockSplit { + return mw.ctx.ResetWindows() +} + +func (mw *masterWindowCommon) Input() *Input { + return &mw.ctx.Input +} + +func (mw *masterWindowCommon) ActivateEditor(ed *TextEditor) { + mw.ctx.activateEditor = ed +} + +func (mw *masterWindowCommon) Style() *nstyle.Style { + return &mw.ctx.Style +} + +func (mw *masterWindowCommon) SetStyle(style *nstyle.Style) { + mw.ctx.Style = *style + mw.ctx.Style.Defaults() +} + +func (mw *masterWindowCommon) GetPerf() bool { + return mw.Perf +} + +func (mw *masterWindowCommon) SetPerf(perf bool) { + mw.Perf = perf +} + +// Forces an update of the window. +func (mw *masterWindowCommon) Changed() { + atomic.AddInt32(&mw.ctx.changed, 1) +} + +func (mw *masterWindowCommon) Lock() { + mw.uilock.Lock() +} + +func (mw *masterWindowCommon) Unlock() { + mw.uilock.Unlock() +} + +// Opens a popup window inside win. Will return true until the +// popup window is closed. +// The contents of the popup window will be updated by updateFn +func (mw *masterWindowCommon) PopupOpen(title string, flags WindowFlags, rect rect.Rect, scale bool, updateFn UpdateFn) { + go func() { + mw.ctx.mw.Lock() + defer mw.ctx.mw.Unlock() + mw.ctx.popupOpen(title, flags, rect, scale, updateFn) + mw.ctx.mw.Changed() + }() +} + +var frameCnt int + +func (w *masterWindowCommon) dumpFrame(wimg *image.RGBA, t0, t1, te time.Time, nprimitives int) { + bounds := image.Rect(w.ctx.Input.Mouse.Pos.X, w.ctx.Input.Mouse.Pos.Y, w.ctx.Input.Mouse.Pos.X+10, w.ctx.Input.Mouse.Pos.Y+10) + + draw.Draw(wimg, bounds, image.White, bounds.Min, draw.Src) + + if fh, err := os.Create(fmt.Sprintf("framedump/frame%03d.png", frameCnt)); err == nil { + png.Encode(fh, wimg) + fh.Close() + } + + if fh, err := os.Create(fmt.Sprintf("framedump/frame%03d.txt", frameCnt)); err == nil { + wr := bufio.NewWriter(fh) + fps := 1.0 / te.Sub(t0).Seconds() + tot := time.Duration(0) + fmt.Fprintf(wr, "# Update %0.4fms = %0.4f updatefn + %0.4f draw (%d primitives) [max fps %0.2f]\n", te.Sub(t0).Seconds()*1000, t1.Sub(t0).Seconds()*1000, te.Sub(t1).Seconds()*1000, nprimitives, fps) + for i := range w.prevCmds { + fmt.Fprintf(wr, "%0.2fms %#v\n", w.ctx.cmdstim[i].Seconds()*1000, w.prevCmds[i]) + tot += w.ctx.cmdstim[i] + } + fmt.Fprintf(wr, "sanity check %0.2fms\n", tot.Seconds()*1000) + wr.Flush() + fh.Close() + } + + frameCnt++ +} + +func (w *masterWindowCommon) drawPerfCounter(img *image.RGBA, bounds image.Rectangle, t0, t1, te time.Time) { + fps := 1.0 / te.Sub(t0).Seconds() + + s := fmt.Sprintf("%0.4fms + %0.4fms (%0.2f)", t1.Sub(t0).Seconds()*1000, te.Sub(t1).Seconds()*1000, fps) + d := font.Drawer{ + Dst: img, + Src: image.White, + Face: w.ctx.Style.Font} + + width := d.MeasureString(s).Ceil() + + bounds.Min.X = bounds.Max.X - width + bounds.Min.Y = bounds.Max.Y - (w.ctx.Style.Font.Metrics().Ascent + w.ctx.Style.Font.Metrics().Descent).Ceil() + draw.Draw(img, bounds, image.Black, bounds.Min, draw.Src) + d.Dot = fixed.P(bounds.Min.X, bounds.Min.Y+w.ctx.Style.Font.Metrics().Ascent.Ceil()) + d.DrawString(s) +} + +// compares cmds to the last draw frame, returns true if there is a change +func (w *masterWindowCommon) drawChanged() bool { + + contextAllCommands(w.ctx) + w.ctx.Reset() + + cmds := w.ctx.cmds + + if len(cmds) != len(w.prevCmds) { + return true + } + + for i := range cmds { + if cmds[i].Kind != w.prevCmds[i].Kind { + return true + } + + cmd := &cmds[i] + pcmd := &w.prevCmds[i] + + switch cmds[i].Kind { + case command.ScissorCmd: + if *pcmd != *cmd { + return true + } + + case command.LineCmd: + if *pcmd != *cmd { + return true + } + + case command.RectFilledCmd: + if i == 0 { + cmd.RectFilled.Color.A = 0xff + } + if *pcmd != *cmd { + return true + } + + case command.TriangleFilledCmd: + if *pcmd != *cmd { + return true + } + + case command.CircleFilledCmd: + if *pcmd != *cmd { + return true + } + + case command.ImageCmd: + if *pcmd != *cmd { + return true + } + + case command.TextCmd: + if *pcmd != *cmd { + return true + } + + default: + panic(UnknownCommandErr) + } + } + + return false +} diff --git a/shiny.go b/shiny.go index 214072e..117b40d 100644 --- a/shiny.go +++ b/shiny.go @@ -1,28 +1,21 @@ -// +build linux,!nucular_mobile darwin,!nucular_mobile windows,!nucular_mobile +// +build linux,!android,!nucular_mobile darwin,!nucular_mobile windows,!nucular_mobile package nucular import ( - "bufio" "bytes" "fmt" "image" - "image/draw" - "image/png" "os" "sync" "sync/atomic" "time" "github.com/aarzilli/nucular/clipboard" - "github.com/aarzilli/nucular/command" "github.com/aarzilli/nucular/rect" - nstyle "github.com/aarzilli/nucular/style" "golang.org/x/exp/shiny/driver" "golang.org/x/exp/shiny/screen" - "golang.org/x/image/font" - "golang.org/x/image/math/fixed" "golang.org/x/mobile/event/key" "golang.org/x/mobile/event/lifecycle" "golang.org/x/mobile/event/mouse" @@ -32,12 +25,12 @@ import ( //go:generate go-bindata -o internal/assets/assets.go -pkg assets DroidSansMono.ttf -var frameCnt = 0 - var clipboardStarted bool = false var clipboardMu sync.Mutex type masterWindow struct { + masterWindowCommon + Title string screen screen.Screen wnd screen.Window @@ -46,32 +39,22 @@ type masterWindow struct { initialSize image.Point - // show performance counters - Perf bool // window is focused Focus bool - ctx *context - layout panel - prevCmds []command.Command textbuffer bytes.Buffer - uilock sync.Mutex closing bool focusedOnce bool } -func NewMasterWindow(flags WindowFlags, title string, updatefn UpdateFn) MasterWindow { - return NewMasterWindowSize(flags, title, image.Point{640, 480}, updatefn) -} - // Creates new master window func NewMasterWindowSize(flags WindowFlags, title string, sz image.Point, updatefn UpdateFn) MasterWindow { ctx := &context{} - ctx.Input.Mouse.valid = true - ctx.DockedWindows.Split.MinSize = 40 - wnd := &masterWindow{ctx: ctx} - wnd.layout.Flags = flags + wnd := &masterWindow{} + + wnd.masterWindowCommonInit(ctx, flags, updatefn, wnd) + wnd.Title = title wnd.initialSize = sz @@ -82,11 +65,6 @@ func NewMasterWindowSize(flags WindowFlags, title string, sz image.Point, update } clipboardMu.Unlock() - ctx.setupMasterWindow(&wnd.layout, updatefn) - ctx.mw = wnd - - wnd.SetStyle(nstyle.FromTheme(nstyle.DefaultTheme, 1.0)) - return wnd } @@ -95,22 +73,6 @@ func (mw *masterWindow) Main() { driver.Main(mw.main) } -func (mw *masterWindow) context() *context { - return mw.ctx -} - -func (mw *masterWindow) Walk(fn WindowWalkFn) { - mw.ctx.Walk(fn) -} - -func (mw *masterWindow) Input() *Input { - return &mw.ctx.Input -} - -func (mw *masterWindow) ResetWindows() *DockSplit { - return mw.ctx.ResetWindows() -} - func (mw *masterWindow) Lock() { mw.uilock.Lock() } @@ -277,11 +239,6 @@ func (w *masterWindow) updater() { } } -// Forces an update of the window. -func (mw *masterWindow) Changed() { - atomic.AddInt32(&mw.ctx.changed, 1) -} - func (w *masterWindow) updateLocked() { w.ctx.Windows[0].Bounds = rect.FromRectangle(w.bounds) in := &w.ctx.Input @@ -313,52 +270,10 @@ func (w *masterWindow) updateLocked() { } if w.Perf && nprimitives > 0 { te = time.Now() - - fps := 1.0 / te.Sub(t0).Seconds() - - s := fmt.Sprintf("%0.4fms + %0.4fms (%0.2f)", t1.Sub(t0).Seconds()*1000, te.Sub(t1).Seconds()*1000, fps) - img := w.wndb.RGBA() - d := font.Drawer{ - Dst: img, - Src: image.White, - Face: w.ctx.Style.Font} - - width := d.MeasureString(s).Ceil() - - bounds := w.bounds - bounds.Min.X = bounds.Max.X - width - bounds.Min.Y = bounds.Max.Y - (w.ctx.Style.Font.Metrics().Ascent + w.ctx.Style.Font.Metrics().Descent).Ceil() - draw.Draw(img, bounds, image.Black, bounds.Min, draw.Src) - d.Dot = fixed.P(bounds.Min.X, bounds.Min.Y+w.ctx.Style.Font.Metrics().Ascent.Ceil()) - d.DrawString(s) + w.drawPerfCounter(w.wndb.RGBA(), w.bounds, t0, t1, te) } if dumpFrame && frameCnt < 1000 && nprimitives > 0 { - wimg := w.wndb.RGBA() - - bounds := image.Rect(w.ctx.Input.Mouse.Pos.X, w.ctx.Input.Mouse.Pos.Y, w.ctx.Input.Mouse.Pos.X+10, w.ctx.Input.Mouse.Pos.Y+10) - - draw.Draw(wimg, bounds, image.White, bounds.Min, draw.Src) - - if fh, err := os.Create(fmt.Sprintf("framedump/frame%03d.png", frameCnt)); err == nil { - png.Encode(fh, wimg) - fh.Close() - } - - if fh, err := os.Create(fmt.Sprintf("framedump/frame%03d.txt", frameCnt)); err == nil { - wr := bufio.NewWriter(fh) - fps := 1.0 / te.Sub(t0).Seconds() - tot := time.Duration(0) - fmt.Fprintf(wr, "# Update %0.4fms = %0.4f updatefn + %0.4f draw (%d primitives) [max fps %0.2f]\n", te.Sub(t0).Seconds()*1000, t1.Sub(t0).Seconds()*1000, te.Sub(t1).Seconds()*1000, nprimitives, fps) - for i := range w.prevCmds { - fmt.Fprintf(wr, "%0.2fms %#v\n", w.ctx.cmdstim[i].Seconds()*1000, w.prevCmds[i]) - tot += w.ctx.cmdstim[i] - } - fmt.Fprintf(wr, "sanity check %0.2fms\n", tot.Seconds()*1000) - wr.Flush() - fh.Close() - } - - frameCnt++ + w.dumpFrame(w.wndb.RGBA(), t0, t1, te, nprimitives) } if nprimitives > 0 { w.wnd.Upload(w.bounds.Min, w.wndb, w.bounds) @@ -398,110 +313,11 @@ func (w *masterWindow) setupBuffer(sz image.Point) { } func (w *masterWindow) draw() int { - wimg := w.wndb.RGBA() - - contextAllCommands(w.ctx) - w.ctx.Reset() - - if !w.drawChanged(w.ctx.cmds) { + if !w.drawChanged() { return 0 } w.prevCmds = append(w.prevCmds[:0], w.ctx.cmds...) - return w.ctx.Draw(wimg) -} - -// compares cmds to the last draw frame, returns true if there is a change -func (w *masterWindow) drawChanged(cmds []command.Command) bool { - if len(cmds) != len(w.prevCmds) { - return true - } - - for i := range cmds { - if cmds[i].Kind != w.prevCmds[i].Kind { - return true - } - - cmd := &cmds[i] - pcmd := &w.prevCmds[i] - - switch cmds[i].Kind { - case command.ScissorCmd: - if *pcmd != *cmd { - return true - } - - case command.LineCmd: - if *pcmd != *cmd { - return true - } - - case command.RectFilledCmd: - if i == 0 { - cmd.RectFilled.Color.A = 0xff - } - if *pcmd != *cmd { - return true - } - - case command.TriangleFilledCmd: - if *pcmd != *cmd { - return true - } - - case command.CircleFilledCmd: - if *pcmd != *cmd { - return true - } - - case command.ImageCmd: - if *pcmd != *cmd { - return true - } - - case command.TextCmd: - if *pcmd != *cmd { - return true - } - - default: - panic(UnknownCommandErr) - } - } - - return false -} - -func (mw *masterWindow) ActivateEditor(ed *TextEditor) { - mw.ctx.activateEditor = ed -} - -func (mw *masterWindow) Style() *nstyle.Style { - return &mw.ctx.Style -} - -func (mw *masterWindow) SetStyle(style *nstyle.Style) { - mw.ctx.Style = *style - mw.ctx.Style.Defaults() -} - -func (mw *masterWindow) GetPerf() bool { - return mw.Perf -} - -func (mw *masterWindow) SetPerf(perf bool) { - mw.Perf = perf -} - -// Opens a popup window inside win. Will return true until the -// popup window is closed. -// The contents of the popup window will be updated by updateFn -func (mw *masterWindow) PopupOpen(title string, flags WindowFlags, rect rect.Rect, scale bool, updateFn UpdateFn) { - go func() { - mw.uilock.Lock() - defer mw.uilock.Unlock() - mw.ctx.popupOpen(title, flags, rect, scale, updateFn) - mw.Changed() - }() + return w.ctx.Draw(w.wndb.RGBA()) } diff --git a/vendor/golang.org/x/exp/shiny/driver/gldriver/cocoa.m b/vendor/golang.org/x/exp/shiny/driver/gldriver/cocoa.m index d8bfb8c..3410b58 100644 --- a/vendor/golang.org/x/exp/shiny/driver/gldriver/cocoa.m +++ b/vendor/golang.org/x/exp/shiny/driver/gldriver/cocoa.m @@ -34,6 +34,7 @@ void makeCurrentContext(uintptr_t context) { NSOpenGLContext* ctx = (NSOpenGLContext*)context; [ctx makeCurrentContext]; + [ctx update]; } void flushContext(uintptr_t context) { diff --git a/vendor/golang.org/x/exp/shiny/driver/gldriver/context.go b/vendor/golang.org/x/exp/shiny/driver/gldriver/context.go index 63fb170..197be35 100644 --- a/vendor/golang.org/x/exp/shiny/driver/gldriver/context.go +++ b/vendor/golang.org/x/exp/shiny/driver/gldriver/context.go @@ -2,6 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. +// +build !android + package gldriver import ( diff --git a/vendor/golang.org/x/exp/shiny/driver/gldriver/other.go b/vendor/golang.org/x/exp/shiny/driver/gldriver/other.go index 6da5133..bbfc034 100644 --- a/vendor/golang.org/x/exp/shiny/driver/gldriver/other.go +++ b/vendor/golang.org/x/exp/shiny/driver/gldriver/other.go @@ -16,6 +16,9 @@ import ( "golang.org/x/exp/shiny/screen" ) +const useLifecycler = true +const handleSizeEventsAtChannelReceive = true + func newWindow(opts *screen.NewWindowOptions) (uintptr, error) { return 0, nil } func initWindow(id *windowImpl) {} diff --git a/vendor/golang.org/x/exp/shiny/driver/gldriver/screen.go b/vendor/golang.org/x/exp/shiny/driver/gldriver/screen.go index 3100ebc..f6f18f1 100644 --- a/vendor/golang.org/x/exp/shiny/driver/gldriver/screen.go +++ b/vendor/golang.org/x/exp/shiny/driver/gldriver/screen.go @@ -99,7 +99,7 @@ func (s *screenImpl) NewTexture(size image.Point) (screen.Texture, error) { } glctx.BindTexture(gl.TEXTURE_2D, t.id) - glctx.TexImage2D(gl.TEXTURE_2D, 0, size.X, size.Y, gl.RGBA, gl.UNSIGNED_BYTE, nil) + glctx.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, size.X, size.Y, gl.RGBA, gl.UNSIGNED_BYTE, nil) glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) diff --git a/vendor/golang.org/x/exp/shiny/driver/internal/event/event.go b/vendor/golang.org/x/exp/shiny/driver/internal/event/event.go index 4d28dbf..686a123 100644 --- a/vendor/golang.org/x/exp/shiny/driver/internal/event/event.go +++ b/vendor/golang.org/x/exp/shiny/driver/internal/event/event.go @@ -18,23 +18,29 @@ type Deque struct { front []interface{} // LIFO. } -// NextEvent implements the screen.EventDeque interface. -func (q *Deque) NextEvent() interface{} { +func (q *Deque) lockAndInit() { q.mu.Lock() - defer q.mu.Unlock() if q.cond.L == nil { q.cond.L = &q.mu } +} + +// NextEvent implements the screen.EventDeque interface. +func (q *Deque) NextEvent() interface{} { + q.lockAndInit() + defer q.mu.Unlock() for { if n := len(q.front); n > 0 { e := q.front[n-1] + q.front[n-1] = nil q.front = q.front[:n-1] return e } if n := len(q.back); n > 0 { e := q.back[0] + q.back[0] = nil q.back = q.back[1:] return e } @@ -45,11 +51,8 @@ func (q *Deque) NextEvent() interface{} { // Send implements the screen.EventDeque interface. func (q *Deque) Send(event interface{}) { - q.mu.Lock() + q.lockAndInit() defer q.mu.Unlock() - if q.cond.L == nil { - q.cond.L = &q.mu - } q.back = append(q.back, event) q.cond.Signal() @@ -57,11 +60,8 @@ func (q *Deque) Send(event interface{}) { // SendFirst implements the screen.EventDeque interface. func (q *Deque) SendFirst(event interface{}) { - q.mu.Lock() + q.lockAndInit() defer q.mu.Unlock() - if q.cond.L == nil { - q.cond.L = &q.mu - } q.front = append(q.front, event) q.cond.Signal() diff --git a/vendor/golang.org/x/exp/shiny/driver/internal/win32/win32.go b/vendor/golang.org/x/exp/shiny/driver/internal/win32/win32.go index 5836073..deaeb37 100644 --- a/vendor/golang.org/x/exp/shiny/driver/internal/win32/win32.go +++ b/vendor/golang.org/x/exp/shiny/driver/internal/win32/win32.go @@ -116,10 +116,7 @@ func Show(hwnd syscall.Handle) { } func Release(hwnd syscall.Handle) { - // TODO(andlabs): check for errors from this? - // TODO(andlabs): remove unsafe - _DestroyWindow(hwnd) - // TODO(andlabs): what happens if we're still painting? + SendMessage(hwnd, _WM_CLOSE, 0, 0) } func sendFocus(hwnd syscall.Handle, uMsg uint32, wParam, lParam uintptr) (lResult uintptr) { @@ -170,8 +167,11 @@ func sendSize(hwnd syscall.Handle) { } func sendClose(hwnd syscall.Handle, uMsg uint32, wParam, lParam uintptr) (lResult uintptr) { + // TODO(ktye): DefWindowProc calls DestroyWindow by default. + // To intercept destruction of the window, return 0 and call + // DestroyWindow when appropriate. LifecycleEvent(hwnd, lifecycle.StageDead) - return 0 + return _DefWindowProc(hwnd, uMsg, wParam, lParam) } func sendMouseEvent(hwnd syscall.Handle, uMsg uint32, wParam, lParam uintptr) (lResult uintptr) { diff --git a/vendor/golang.org/x/image/font/font.go b/vendor/golang.org/x/image/font/font.go index 05f4357..4d9d63c 100644 --- a/vendor/golang.org/x/image/font/font.go +++ b/vendor/golang.org/x/image/font/font.go @@ -86,6 +86,18 @@ type Metrics struct { // value is typically positive, even though a descender goes below the // baseline. Descent fixed.Int26_6 + + // XHeight is the distance from the top of non-ascending lowercase letters + // to the baseline. + XHeight fixed.Int26_6 + + // CapHeight is the distance from the top of uppercase letters to the + // baseline. + CapHeight fixed.Int26_6 + + // CaretSlope is the slope of a caret as a vector with the Y axis pointing up. + // The slope {0, 1} is the vertical caret. + CaretSlope image.Point } // Drawer draws text on a destination image. diff --git a/vendor/golang.org/x/mobile/app/GoNativeActivity.java b/vendor/golang.org/x/mobile/app/GoNativeActivity.java new file mode 100644 index 0000000..e829c8c --- /dev/null +++ b/vendor/golang.org/x/mobile/app/GoNativeActivity.java @@ -0,0 +1,67 @@ +package org.golang.app; + +import android.app.Activity; +import android.app.NativeActivity; +import android.content.Context; +import android.content.pm.ActivityInfo; +import android.content.pm.PackageManager; +import android.os.Bundle; +import android.util.Log; +import android.view.KeyCharacterMap; + +public class GoNativeActivity extends NativeActivity { + private static GoNativeActivity goNativeActivity; + + public GoNativeActivity() { + super(); + goNativeActivity = this; + } + + String getTmpdir() { + return getCacheDir().getAbsolutePath(); + } + + static int getRune(int deviceId, int keyCode, int metaState) { + try { + int rune = KeyCharacterMap.load(deviceId).get(keyCode, metaState); + if (rune == 0) { + return -1; + } + return rune; + } catch (KeyCharacterMap.UnavailableException e) { + return -1; + } catch (Exception e) { + Log.e("Go", "exception reading KeyCharacterMap", e); + return -1; + } + } + + private void load() { + // Interestingly, NativeActivity uses a different method + // to find native code to execute, avoiding + // System.loadLibrary. The result is Java methods + // implemented in C with JNIEXPORT (and JNI_OnLoad) are not + // available unless an explicit call to System.loadLibrary + // is done. So we do it here, borrowing the name of the + // library from the same AndroidManifest.xml metadata used + // by NativeActivity. + try { + ActivityInfo ai = getPackageManager().getActivityInfo( + getIntent().getComponent(), PackageManager.GET_META_DATA); + if (ai.metaData == null) { + Log.e("Go", "loadLibrary: no manifest metadata found"); + return; + } + String libName = ai.metaData.getString("android.app.lib_name"); + System.loadLibrary(libName); + } catch (Exception e) { + Log.e("Go", "loadLibrary failed", e); + } + } + + @Override + public void onCreate(Bundle savedInstanceState) { + load(); + super.onCreate(savedInstanceState); + } +} diff --git a/vendor/golang.org/x/mobile/app/android.c b/vendor/golang.org/x/mobile/app/android.c new file mode 100644 index 0000000..0ceb9f6 --- /dev/null +++ b/vendor/golang.org/x/mobile/app/android.c @@ -0,0 +1,200 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build android + +#include +#include +#include +#include +#include +#include +#include "_cgo_export.h" + +#define LOG_INFO(...) __android_log_print(ANDROID_LOG_INFO, "Go", __VA_ARGS__) +#define LOG_FATAL(...) __android_log_print(ANDROID_LOG_FATAL, "Go", __VA_ARGS__) + +static jclass current_class; + +static jclass find_class(JNIEnv *env, const char *class_name) { + jclass clazz = (*env)->FindClass(env, class_name); + if (clazz == NULL) { + (*env)->ExceptionClear(env); + LOG_FATAL("cannot find %s", class_name); + return NULL; + } + return clazz; +} + +static jmethodID find_method(JNIEnv *env, jclass clazz, const char *name, const char *sig) { + jmethodID m = (*env)->GetMethodID(env, clazz, name, sig); + if (m == 0) { + (*env)->ExceptionClear(env); + LOG_FATAL("cannot find method %s %s", name, sig); + return 0; + } + return m; +} + +static jmethodID find_static_method(JNIEnv *env, jclass clazz, const char *name, const char *sig) { + jmethodID m = (*env)->GetStaticMethodID(env, clazz, name, sig); + if (m == 0) { + (*env)->ExceptionClear(env); + LOG_FATAL("cannot find method %s %s", name, sig); + return 0; + } + return m; +} + +static jmethodID key_rune_method; + +jint JNI_OnLoad(JavaVM* vm, void* reserved) { + JNIEnv* env; + if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK) { + return -1; + } + + return JNI_VERSION_1_6; +} + +static int main_running = 0; + +// Entry point from our subclassed NativeActivity. +// +// By here, the Go runtime has been initialized (as we are running in +// -buildmode=c-shared) but the first time it is called, Go's main.main +// hasn't been called yet. +// +// The Activity may be created and destroyed multiple times throughout +// the life of a single process. Each time, onCreate is called. +void ANativeActivity_onCreate(ANativeActivity *activity, void* savedState, size_t savedStateSize) { + if (!main_running) { + JNIEnv* env = activity->env; + + // Note that activity->clazz is mis-named. + current_class = (*env)->GetObjectClass(env, activity->clazz); + current_class = (*env)->NewGlobalRef(env, current_class); + key_rune_method = find_static_method(env, current_class, "getRune", "(III)I"); + + setCurrentContext(activity->vm, (*env)->NewGlobalRef(env, activity->clazz)); + + // Set TMPDIR. + jmethodID gettmpdir = find_method(env, current_class, "getTmpdir", "()Ljava/lang/String;"); + jstring jpath = (jstring)(*env)->CallObjectMethod(env, activity->clazz, gettmpdir, NULL); + const char* tmpdir = (*env)->GetStringUTFChars(env, jpath, NULL); + if (setenv("TMPDIR", tmpdir, 1) != 0) { + LOG_INFO("setenv(\"TMPDIR\", \"%s\", 1) failed: %d", tmpdir, errno); + } + (*env)->ReleaseStringUTFChars(env, jpath, tmpdir); + + // Call the Go main.main. + uintptr_t mainPC = (uintptr_t)dlsym(RTLD_DEFAULT, "main.main"); + if (!mainPC) { + LOG_FATAL("missing main.main"); + } + callMain(mainPC); + main_running = 1; + } + + // These functions match the methods on Activity, described at + // http://developer.android.com/reference/android/app/Activity.html + // + // Note that onNativeWindowResized is not called on resize. Avoid it. + // https://code.google.com/p/android/issues/detail?id=180645 + activity->callbacks->onStart = onStart; + activity->callbacks->onResume = onResume; + activity->callbacks->onSaveInstanceState = onSaveInstanceState; + activity->callbacks->onPause = onPause; + activity->callbacks->onStop = onStop; + activity->callbacks->onDestroy = onDestroy; + activity->callbacks->onWindowFocusChanged = onWindowFocusChanged; + activity->callbacks->onNativeWindowCreated = onNativeWindowCreated; + activity->callbacks->onNativeWindowRedrawNeeded = onNativeWindowRedrawNeeded; + activity->callbacks->onNativeWindowDestroyed = onNativeWindowDestroyed; + activity->callbacks->onInputQueueCreated = onInputQueueCreated; + activity->callbacks->onInputQueueDestroyed = onInputQueueDestroyed; + activity->callbacks->onConfigurationChanged = onConfigurationChanged; + activity->callbacks->onLowMemory = onLowMemory; + + onCreate(activity); +} + +// TODO(crawshaw): Test configuration on more devices. +static const EGLint RGB_888[] = { + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_BLUE_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_RED_SIZE, 8, + EGL_DEPTH_SIZE, 16, + EGL_CONFIG_CAVEAT, EGL_NONE, + EGL_NONE +}; + +EGLDisplay display = NULL; +EGLSurface surface = NULL; + +static char* initEGLDisplay() { + display = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (!eglInitialize(display, 0, 0)) { + return "EGL initialize failed"; + } + return NULL; +} + +char* createEGLSurface(ANativeWindow* window) { + char* err; + EGLint numConfigs, format; + EGLConfig config; + EGLContext context; + + if (display == 0) { + if ((err = initEGLDisplay()) != NULL) { + return err; + } + } + + if (!eglChooseConfig(display, RGB_888, &config, 1, &numConfigs)) { + return "EGL choose RGB_888 config failed"; + } + if (numConfigs <= 0) { + return "EGL no config found"; + } + + eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format); + if (ANativeWindow_setBuffersGeometry(window, 0, 0, format) != 0) { + return "EGL set buffers geometry failed"; + } + + surface = eglCreateWindowSurface(display, config, window, NULL); + if (surface == EGL_NO_SURFACE) { + return "EGL create surface failed"; + } + + const EGLint contextAttribs[] = { EGL_CONTEXT_CLIENT_VERSION, 2, EGL_NONE }; + context = eglCreateContext(display, config, EGL_NO_CONTEXT, contextAttribs); + + if (eglMakeCurrent(display, surface, surface, context) == EGL_FALSE) { + return "eglMakeCurrent failed"; + } + return NULL; +} + +char* destroyEGLSurface() { + if (!eglDestroySurface(display, surface)) { + return "EGL destroy surface failed"; + } + return NULL; +} + +int32_t getKeyRune(JNIEnv* env, AInputEvent* e) { + return (int32_t)(*env)->CallStaticIntMethod( + env, + current_class, + key_rune_method, + AInputEvent_getDeviceId(e), + AKeyEvent_getKeyCode(e), + AKeyEvent_getMetaState(e) + ); +} diff --git a/vendor/golang.org/x/mobile/app/android.go b/vendor/golang.org/x/mobile/app/android.go new file mode 100644 index 0000000..213e31d --- /dev/null +++ b/vendor/golang.org/x/mobile/app/android.go @@ -0,0 +1,819 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build android + +/* +Android Apps are built with -buildmode=c-shared. They are loaded by a +running Java process. + +Before any entry point is reached, a global constructor initializes the +Go runtime, calling all Go init functions. All cgo calls will block +until this is complete. Next JNI_OnLoad is called. When that is +complete, one of two entry points is called. + +All-Go apps built using NativeActivity enter at ANativeActivity_onCreate. + +Go libraries (for example, those built with gomobile bind) do not use +the app package initialization. +*/ + +package app + +/* +#cgo LDFLAGS: -landroid -llog -lEGL -lGLESv2 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +EGLDisplay display; +EGLSurface surface; + +char* createEGLSurface(ANativeWindow* window); +char* destroyEGLSurface(); +int32_t getKeyRune(JNIEnv* env, AInputEvent* e); +*/ +import "C" +import ( + "fmt" + "log" + "os" + "time" + "unsafe" + + "golang.org/x/mobile/app/internal/callfn" + "golang.org/x/mobile/event/key" + "golang.org/x/mobile/event/lifecycle" + "golang.org/x/mobile/event/paint" + "golang.org/x/mobile/event/size" + "golang.org/x/mobile/event/touch" + "golang.org/x/mobile/geom" + "golang.org/x/mobile/internal/mobileinit" +) + +// RunOnJVM runs fn on a new goroutine locked to an OS thread with a JNIEnv. +// +// RunOnJVM blocks until the call to fn is complete. Any Java +// exception or failure to attach to the JVM is returned as an error. +// +// The function fn takes vm, the current JavaVM*, +// env, the current JNIEnv*, and +// ctx, a jobject representing the global android.context.Context. +func RunOnJVM(fn func(vm, jniEnv, ctx uintptr) error) error { + return mobileinit.RunOnJVM(fn) +} + +//export setCurrentContext +func setCurrentContext(vm *C.JavaVM, ctx C.jobject) { + mobileinit.SetCurrentContext(unsafe.Pointer(vm), uintptr(ctx)) +} + +//export callMain +func callMain(mainPC uintptr) { + for _, name := range []string{"TMPDIR", "PATH", "LD_LIBRARY_PATH"} { + n := C.CString(name) + os.Setenv(name, C.GoString(C.getenv(n))) + C.free(unsafe.Pointer(n)) + } + + // Set timezone. + // + // Note that Android zoneinfo is stored in /system/usr/share/zoneinfo, + // but it is in some kind of packed TZiff file that we do not support + // yet. As a stopgap, we build a fixed zone using the tm_zone name. + var curtime C.time_t + var curtm C.struct_tm + C.time(&curtime) + C.localtime_r(&curtime, &curtm) + tzOffset := int(curtm.tm_gmtoff) + tz := C.GoString(curtm.tm_zone) + time.Local = time.FixedZone(tz, tzOffset) + + go callfn.CallFn(mainPC) +} + +//export onStart +func onStart(activity *C.ANativeActivity) { +} + +//export onResume +func onResume(activity *C.ANativeActivity) { +} + +//export onSaveInstanceState +func onSaveInstanceState(activity *C.ANativeActivity, outSize *C.size_t) unsafe.Pointer { + return nil +} + +//export onPause +func onPause(activity *C.ANativeActivity) { +} + +//export onStop +func onStop(activity *C.ANativeActivity) { +} + +//export onCreate +func onCreate(activity *C.ANativeActivity) { + // Set the initial configuration. + // + // Note we use unbuffered channels to talk to the activity loop, and + // NativeActivity calls these callbacks sequentially, so configuration + // will be set before <-windowRedrawNeeded is processed. + windowConfigChange <- windowConfigRead(activity) +} + +//export onDestroy +func onDestroy(activity *C.ANativeActivity) { +} + +//export onWindowFocusChanged +func onWindowFocusChanged(activity *C.ANativeActivity, hasFocus C.int) { +} + +//export onNativeWindowCreated +func onNativeWindowCreated(activity *C.ANativeActivity, window *C.ANativeWindow) { +} + +//export onNativeWindowRedrawNeeded +func onNativeWindowRedrawNeeded(activity *C.ANativeActivity, window *C.ANativeWindow) { + // Called on orientation change and window resize. + // Send a request for redraw, and block this function + // until a complete draw and buffer swap is completed. + // This is required by the redraw documentation to + // avoid bad draws. + windowRedrawNeeded <- window + <-windowRedrawDone +} + +//export onNativeWindowDestroyed +func onNativeWindowDestroyed(activity *C.ANativeActivity, window *C.ANativeWindow) { + windowDestroyed <- window +} + +//export onInputQueueCreated +func onInputQueueCreated(activity *C.ANativeActivity, q *C.AInputQueue) { + inputQueue <- q + <-inputQueueDone +} + +//export onInputQueueDestroyed +func onInputQueueDestroyed(activity *C.ANativeActivity, q *C.AInputQueue) { + inputQueue <- nil + <-inputQueueDone +} + +//export onContentRectChanged +func onContentRectChanged(activity *C.ANativeActivity, rect *C.ARect) { +} + +type windowConfig struct { + orientation size.Orientation + pixelsPerPt float32 +} + +func windowConfigRead(activity *C.ANativeActivity) windowConfig { + aconfig := C.AConfiguration_new() + C.AConfiguration_fromAssetManager(aconfig, activity.assetManager) + orient := C.AConfiguration_getOrientation(aconfig) + density := C.AConfiguration_getDensity(aconfig) + C.AConfiguration_delete(aconfig) + + // Calculate the screen resolution. This value is approximate. For example, + // a physical resolution of 200 DPI may be quantized to one of the + // ACONFIGURATION_DENSITY_XXX values such as 160 or 240. + // + // A more accurate DPI could possibly be calculated from + // https://developer.android.com/reference/android/util/DisplayMetrics.html#xdpi + // but this does not appear to be accessible via the NDK. In any case, the + // hardware might not even provide a more accurate number, as the system + // does not apparently use the reported value. See golang.org/issue/13366 + // for a discussion. + var dpi int + switch density { + case C.ACONFIGURATION_DENSITY_DEFAULT: + dpi = 160 + case C.ACONFIGURATION_DENSITY_LOW, + C.ACONFIGURATION_DENSITY_MEDIUM, + 213, // C.ACONFIGURATION_DENSITY_TV + C.ACONFIGURATION_DENSITY_HIGH, + 320, // ACONFIGURATION_DENSITY_XHIGH + 480, // ACONFIGURATION_DENSITY_XXHIGH + 640: // ACONFIGURATION_DENSITY_XXXHIGH + dpi = int(density) + case C.ACONFIGURATION_DENSITY_NONE: + log.Print("android device reports no screen density") + dpi = 72 + default: + log.Printf("android device reports unknown density: %d", density) + // All we can do is guess. + if density > 0 { + dpi = int(density) + } else { + dpi = 72 + } + } + + o := size.OrientationUnknown + switch orient { + case C.ACONFIGURATION_ORIENTATION_PORT: + o = size.OrientationPortrait + case C.ACONFIGURATION_ORIENTATION_LAND: + o = size.OrientationLandscape + } + + return windowConfig{ + orientation: o, + pixelsPerPt: float32(dpi) / 72, + } +} + +//export onConfigurationChanged +func onConfigurationChanged(activity *C.ANativeActivity) { + // A rotation event first triggers onConfigurationChanged, then + // calls onNativeWindowRedrawNeeded. We extract the orientation + // here and save it for the redraw event. + windowConfigChange <- windowConfigRead(activity) +} + +//export onLowMemory +func onLowMemory(activity *C.ANativeActivity) { +} + +var ( + inputQueue = make(chan *C.AInputQueue) + inputQueueDone = make(chan struct{}) + windowDestroyed = make(chan *C.ANativeWindow) + windowRedrawNeeded = make(chan *C.ANativeWindow) + windowRedrawDone = make(chan struct{}) + windowConfigChange = make(chan windowConfig) +) + +func init() { + theApp.registerGLViewportFilter() +} + +func main(f func(App)) { + mainUserFn = f + // TODO: merge the runInputQueue and mainUI functions? + go func() { + if err := mobileinit.RunOnJVM(runInputQueue); err != nil { + log.Fatalf("app: %v", err) + } + }() + // Preserve this OS thread for: + // 1. the attached JNI thread + // 2. the GL context + if err := mobileinit.RunOnJVM(mainUI); err != nil { + log.Fatalf("app: %v", err) + } +} + +var mainUserFn func(App) + +func mainUI(vm, jniEnv, ctx uintptr) error { + workAvailable := theApp.worker.WorkAvailable() + + donec := make(chan struct{}) + go func() { + mainUserFn(theApp) + close(donec) + }() + + var pixelsPerPt float32 + var orientation size.Orientation + + for { + select { + case <-donec: + return nil + case cfg := <-windowConfigChange: + pixelsPerPt = cfg.pixelsPerPt + orientation = cfg.orientation + case w := <-windowRedrawNeeded: + if C.surface == nil { + if errStr := C.createEGLSurface(w); errStr != nil { + return fmt.Errorf("%s (%s)", C.GoString(errStr), eglGetError()) + } + } + theApp.sendLifecycle(lifecycle.StageFocused) + widthPx := int(C.ANativeWindow_getWidth(w)) + heightPx := int(C.ANativeWindow_getHeight(w)) + theApp.eventsIn <- size.Event{ + WidthPx: widthPx, + HeightPx: heightPx, + WidthPt: geom.Pt(float32(widthPx) / pixelsPerPt), + HeightPt: geom.Pt(float32(heightPx) / pixelsPerPt), + PixelsPerPt: pixelsPerPt, + Orientation: orientation, + } + theApp.eventsIn <- paint.Event{External: true} + case <-windowDestroyed: + if C.surface != nil { + if errStr := C.destroyEGLSurface(); errStr != nil { + return fmt.Errorf("%s (%s)", C.GoString(errStr), eglGetError()) + } + } + C.surface = nil + theApp.sendLifecycle(lifecycle.StageAlive) + case <-workAvailable: + theApp.worker.DoWork() + case <-theApp.publish: + // TODO: compare a generation number to redrawGen for stale paints? + if C.surface != nil { + // eglSwapBuffers blocks until vsync. + if C.eglSwapBuffers(C.display, C.surface) == C.EGL_FALSE { + log.Printf("app: failed to swap buffers (%s)", eglGetError()) + } + } + select { + case windowRedrawDone <- struct{}{}: + default: + } + theApp.publishResult <- PublishResult{} + } + } +} + +func runInputQueue(vm, jniEnv, ctx uintptr) error { + env := (*C.JNIEnv)(unsafe.Pointer(jniEnv)) // not a Go heap pointer + + // Android loopers select on OS file descriptors, not Go channels, so we + // translate the inputQueue channel to an ALooper_wake call. + l := C.ALooper_prepare(C.ALOOPER_PREPARE_ALLOW_NON_CALLBACKS) + pending := make(chan *C.AInputQueue, 1) + go func() { + for q := range inputQueue { + pending <- q + C.ALooper_wake(l) + } + }() + + var q *C.AInputQueue + for { + if C.ALooper_pollAll(-1, nil, nil, nil) == C.ALOOPER_POLL_WAKE { + select { + default: + case p := <-pending: + if q != nil { + processEvents(env, q) + C.AInputQueue_detachLooper(q) + } + q = p + if q != nil { + C.AInputQueue_attachLooper(q, l, 0, nil, nil) + } + inputQueueDone <- struct{}{} + } + } + if q != nil { + processEvents(env, q) + } + } +} + +func processEvents(env *C.JNIEnv, q *C.AInputQueue) { + var e *C.AInputEvent + for C.AInputQueue_getEvent(q, &e) >= 0 { + if C.AInputQueue_preDispatchEvent(q, e) != 0 { + continue + } + processEvent(env, e) + C.AInputQueue_finishEvent(q, e, 0) + } +} + +func processEvent(env *C.JNIEnv, e *C.AInputEvent) { + switch C.AInputEvent_getType(e) { + case C.AINPUT_EVENT_TYPE_KEY: + processKey(env, e) + case C.AINPUT_EVENT_TYPE_MOTION: + // At most one of the events in this batch is an up or down event; get its index and change. + upDownIndex := C.size_t(C.AMotionEvent_getAction(e)&C.AMOTION_EVENT_ACTION_POINTER_INDEX_MASK) >> C.AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT + upDownType := touch.TypeMove + switch C.AMotionEvent_getAction(e) & C.AMOTION_EVENT_ACTION_MASK { + case C.AMOTION_EVENT_ACTION_DOWN, C.AMOTION_EVENT_ACTION_POINTER_DOWN: + upDownType = touch.TypeBegin + case C.AMOTION_EVENT_ACTION_UP, C.AMOTION_EVENT_ACTION_POINTER_UP: + upDownType = touch.TypeEnd + } + + for i, n := C.size_t(0), C.AMotionEvent_getPointerCount(e); i < n; i++ { + t := touch.TypeMove + if i == upDownIndex { + t = upDownType + } + theApp.eventsIn <- touch.Event{ + X: float32(C.AMotionEvent_getX(e, i)), + Y: float32(C.AMotionEvent_getY(e, i)), + Sequence: touch.Sequence(C.AMotionEvent_getPointerId(e, i)), + Type: t, + } + } + default: + log.Printf("unknown input event, type=%d", C.AInputEvent_getType(e)) + } +} + +func processKey(env *C.JNIEnv, e *C.AInputEvent) { + deviceID := C.AInputEvent_getDeviceId(e) + if deviceID == 0 { + // Software keyboard input, leaving for scribe/IME. + return + } + + k := key.Event{ + Rune: rune(C.getKeyRune(env, e)), + Code: convAndroidKeyCode(int32(C.AKeyEvent_getKeyCode(e))), + } + switch C.AKeyEvent_getAction(e) { + case C.AKEY_STATE_DOWN: + k.Direction = key.DirPress + case C.AKEY_STATE_UP: + k.Direction = key.DirRelease + default: + k.Direction = key.DirNone + } + // TODO(crawshaw): set Modifiers. + theApp.eventsIn <- k +} + +func eglGetError() string { + switch errNum := C.eglGetError(); errNum { + case C.EGL_SUCCESS: + return "EGL_SUCCESS" + case C.EGL_NOT_INITIALIZED: + return "EGL_NOT_INITIALIZED" + case C.EGL_BAD_ACCESS: + return "EGL_BAD_ACCESS" + case C.EGL_BAD_ALLOC: + return "EGL_BAD_ALLOC" + case C.EGL_BAD_ATTRIBUTE: + return "EGL_BAD_ATTRIBUTE" + case C.EGL_BAD_CONTEXT: + return "EGL_BAD_CONTEXT" + case C.EGL_BAD_CONFIG: + return "EGL_BAD_CONFIG" + case C.EGL_BAD_CURRENT_SURFACE: + return "EGL_BAD_CURRENT_SURFACE" + case C.EGL_BAD_DISPLAY: + return "EGL_BAD_DISPLAY" + case C.EGL_BAD_SURFACE: + return "EGL_BAD_SURFACE" + case C.EGL_BAD_MATCH: + return "EGL_BAD_MATCH" + case C.EGL_BAD_PARAMETER: + return "EGL_BAD_PARAMETER" + case C.EGL_BAD_NATIVE_PIXMAP: + return "EGL_BAD_NATIVE_PIXMAP" + case C.EGL_BAD_NATIVE_WINDOW: + return "EGL_BAD_NATIVE_WINDOW" + case C.EGL_CONTEXT_LOST: + return "EGL_CONTEXT_LOST" + default: + return fmt.Sprintf("Unknown EGL err: %d", errNum) + } +} + +func convAndroidKeyCode(aKeyCode int32) key.Code { + // Many Android key codes do not map into USB HID codes. + // For those, key.CodeUnknown is returned. This switch has all + // cases, even the unknown ones, to serve as a documentation + // and search aid. + switch aKeyCode { + case C.AKEYCODE_UNKNOWN: + case C.AKEYCODE_SOFT_LEFT: + case C.AKEYCODE_SOFT_RIGHT: + case C.AKEYCODE_HOME: + return key.CodeHome + case C.AKEYCODE_BACK: + case C.AKEYCODE_CALL: + case C.AKEYCODE_ENDCALL: + case C.AKEYCODE_0: + return key.Code0 + case C.AKEYCODE_1: + return key.Code1 + case C.AKEYCODE_2: + return key.Code2 + case C.AKEYCODE_3: + return key.Code3 + case C.AKEYCODE_4: + return key.Code4 + case C.AKEYCODE_5: + return key.Code5 + case C.AKEYCODE_6: + return key.Code6 + case C.AKEYCODE_7: + return key.Code7 + case C.AKEYCODE_8: + return key.Code8 + case C.AKEYCODE_9: + return key.Code9 + case C.AKEYCODE_STAR: + case C.AKEYCODE_POUND: + case C.AKEYCODE_DPAD_UP: + case C.AKEYCODE_DPAD_DOWN: + case C.AKEYCODE_DPAD_LEFT: + case C.AKEYCODE_DPAD_RIGHT: + case C.AKEYCODE_DPAD_CENTER: + case C.AKEYCODE_VOLUME_UP: + return key.CodeVolumeUp + case C.AKEYCODE_VOLUME_DOWN: + return key.CodeVolumeDown + case C.AKEYCODE_POWER: + case C.AKEYCODE_CAMERA: + case C.AKEYCODE_CLEAR: + case C.AKEYCODE_A: + return key.CodeA + case C.AKEYCODE_B: + return key.CodeB + case C.AKEYCODE_C: + return key.CodeC + case C.AKEYCODE_D: + return key.CodeD + case C.AKEYCODE_E: + return key.CodeE + case C.AKEYCODE_F: + return key.CodeF + case C.AKEYCODE_G: + return key.CodeG + case C.AKEYCODE_H: + return key.CodeH + case C.AKEYCODE_I: + return key.CodeI + case C.AKEYCODE_J: + return key.CodeJ + case C.AKEYCODE_K: + return key.CodeK + case C.AKEYCODE_L: + return key.CodeL + case C.AKEYCODE_M: + return key.CodeM + case C.AKEYCODE_N: + return key.CodeN + case C.AKEYCODE_O: + return key.CodeO + case C.AKEYCODE_P: + return key.CodeP + case C.AKEYCODE_Q: + return key.CodeQ + case C.AKEYCODE_R: + return key.CodeR + case C.AKEYCODE_S: + return key.CodeS + case C.AKEYCODE_T: + return key.CodeT + case C.AKEYCODE_U: + return key.CodeU + case C.AKEYCODE_V: + return key.CodeV + case C.AKEYCODE_W: + return key.CodeW + case C.AKEYCODE_X: + return key.CodeX + case C.AKEYCODE_Y: + return key.CodeY + case C.AKEYCODE_Z: + return key.CodeZ + case C.AKEYCODE_COMMA: + return key.CodeComma + case C.AKEYCODE_PERIOD: + return key.CodeFullStop + case C.AKEYCODE_ALT_LEFT: + return key.CodeLeftAlt + case C.AKEYCODE_ALT_RIGHT: + return key.CodeRightAlt + case C.AKEYCODE_SHIFT_LEFT: + return key.CodeLeftShift + case C.AKEYCODE_SHIFT_RIGHT: + return key.CodeRightShift + case C.AKEYCODE_TAB: + return key.CodeTab + case C.AKEYCODE_SPACE: + return key.CodeSpacebar + case C.AKEYCODE_SYM: + case C.AKEYCODE_EXPLORER: + case C.AKEYCODE_ENVELOPE: + case C.AKEYCODE_ENTER: + return key.CodeReturnEnter + case C.AKEYCODE_DEL: + return key.CodeDeleteBackspace + case C.AKEYCODE_GRAVE: + return key.CodeGraveAccent + case C.AKEYCODE_MINUS: + return key.CodeHyphenMinus + case C.AKEYCODE_EQUALS: + return key.CodeEqualSign + case C.AKEYCODE_LEFT_BRACKET: + return key.CodeLeftSquareBracket + case C.AKEYCODE_RIGHT_BRACKET: + return key.CodeRightSquareBracket + case C.AKEYCODE_BACKSLASH: + return key.CodeBackslash + case C.AKEYCODE_SEMICOLON: + return key.CodeSemicolon + case C.AKEYCODE_APOSTROPHE: + return key.CodeApostrophe + case C.AKEYCODE_SLASH: + return key.CodeSlash + case C.AKEYCODE_AT: + case C.AKEYCODE_NUM: + case C.AKEYCODE_HEADSETHOOK: + case C.AKEYCODE_FOCUS: + case C.AKEYCODE_PLUS: + case C.AKEYCODE_MENU: + case C.AKEYCODE_NOTIFICATION: + case C.AKEYCODE_SEARCH: + case C.AKEYCODE_MEDIA_PLAY_PAUSE: + case C.AKEYCODE_MEDIA_STOP: + case C.AKEYCODE_MEDIA_NEXT: + case C.AKEYCODE_MEDIA_PREVIOUS: + case C.AKEYCODE_MEDIA_REWIND: + case C.AKEYCODE_MEDIA_FAST_FORWARD: + case C.AKEYCODE_MUTE: + case C.AKEYCODE_PAGE_UP: + return key.CodePageUp + case C.AKEYCODE_PAGE_DOWN: + return key.CodePageDown + case C.AKEYCODE_PICTSYMBOLS: + case C.AKEYCODE_SWITCH_CHARSET: + case C.AKEYCODE_BUTTON_A: + case C.AKEYCODE_BUTTON_B: + case C.AKEYCODE_BUTTON_C: + case C.AKEYCODE_BUTTON_X: + case C.AKEYCODE_BUTTON_Y: + case C.AKEYCODE_BUTTON_Z: + case C.AKEYCODE_BUTTON_L1: + case C.AKEYCODE_BUTTON_R1: + case C.AKEYCODE_BUTTON_L2: + case C.AKEYCODE_BUTTON_R2: + case C.AKEYCODE_BUTTON_THUMBL: + case C.AKEYCODE_BUTTON_THUMBR: + case C.AKEYCODE_BUTTON_START: + case C.AKEYCODE_BUTTON_SELECT: + case C.AKEYCODE_BUTTON_MODE: + case C.AKEYCODE_ESCAPE: + return key.CodeEscape + case C.AKEYCODE_FORWARD_DEL: + return key.CodeDeleteForward + case C.AKEYCODE_CTRL_LEFT: + return key.CodeLeftControl + case C.AKEYCODE_CTRL_RIGHT: + return key.CodeRightControl + case C.AKEYCODE_CAPS_LOCK: + return key.CodeCapsLock + case C.AKEYCODE_SCROLL_LOCK: + case C.AKEYCODE_META_LEFT: + return key.CodeLeftGUI + case C.AKEYCODE_META_RIGHT: + return key.CodeRightGUI + case C.AKEYCODE_FUNCTION: + case C.AKEYCODE_SYSRQ: + case C.AKEYCODE_BREAK: + case C.AKEYCODE_MOVE_HOME: + case C.AKEYCODE_MOVE_END: + case C.AKEYCODE_INSERT: + return key.CodeInsert + case C.AKEYCODE_FORWARD: + case C.AKEYCODE_MEDIA_PLAY: + case C.AKEYCODE_MEDIA_PAUSE: + case C.AKEYCODE_MEDIA_CLOSE: + case C.AKEYCODE_MEDIA_EJECT: + case C.AKEYCODE_MEDIA_RECORD: + case C.AKEYCODE_F1: + return key.CodeF1 + case C.AKEYCODE_F2: + return key.CodeF2 + case C.AKEYCODE_F3: + return key.CodeF3 + case C.AKEYCODE_F4: + return key.CodeF4 + case C.AKEYCODE_F5: + return key.CodeF5 + case C.AKEYCODE_F6: + return key.CodeF6 + case C.AKEYCODE_F7: + return key.CodeF7 + case C.AKEYCODE_F8: + return key.CodeF8 + case C.AKEYCODE_F9: + return key.CodeF9 + case C.AKEYCODE_F10: + return key.CodeF10 + case C.AKEYCODE_F11: + return key.CodeF11 + case C.AKEYCODE_F12: + return key.CodeF12 + case C.AKEYCODE_NUM_LOCK: + return key.CodeKeypadNumLock + case C.AKEYCODE_NUMPAD_0: + return key.CodeKeypad0 + case C.AKEYCODE_NUMPAD_1: + return key.CodeKeypad1 + case C.AKEYCODE_NUMPAD_2: + return key.CodeKeypad2 + case C.AKEYCODE_NUMPAD_3: + return key.CodeKeypad3 + case C.AKEYCODE_NUMPAD_4: + return key.CodeKeypad4 + case C.AKEYCODE_NUMPAD_5: + return key.CodeKeypad5 + case C.AKEYCODE_NUMPAD_6: + return key.CodeKeypad6 + case C.AKEYCODE_NUMPAD_7: + return key.CodeKeypad7 + case C.AKEYCODE_NUMPAD_8: + return key.CodeKeypad8 + case C.AKEYCODE_NUMPAD_9: + return key.CodeKeypad9 + case C.AKEYCODE_NUMPAD_DIVIDE: + return key.CodeKeypadSlash + case C.AKEYCODE_NUMPAD_MULTIPLY: + return key.CodeKeypadAsterisk + case C.AKEYCODE_NUMPAD_SUBTRACT: + return key.CodeKeypadHyphenMinus + case C.AKEYCODE_NUMPAD_ADD: + return key.CodeKeypadPlusSign + case C.AKEYCODE_NUMPAD_DOT: + return key.CodeKeypadFullStop + case C.AKEYCODE_NUMPAD_COMMA: + case C.AKEYCODE_NUMPAD_ENTER: + return key.CodeKeypadEnter + case C.AKEYCODE_NUMPAD_EQUALS: + return key.CodeKeypadEqualSign + case C.AKEYCODE_NUMPAD_LEFT_PAREN: + case C.AKEYCODE_NUMPAD_RIGHT_PAREN: + case C.AKEYCODE_VOLUME_MUTE: + return key.CodeMute + case C.AKEYCODE_INFO: + case C.AKEYCODE_CHANNEL_UP: + case C.AKEYCODE_CHANNEL_DOWN: + case C.AKEYCODE_ZOOM_IN: + case C.AKEYCODE_ZOOM_OUT: + case C.AKEYCODE_TV: + case C.AKEYCODE_WINDOW: + case C.AKEYCODE_GUIDE: + case C.AKEYCODE_DVR: + case C.AKEYCODE_BOOKMARK: + case C.AKEYCODE_CAPTIONS: + case C.AKEYCODE_SETTINGS: + case C.AKEYCODE_TV_POWER: + case C.AKEYCODE_TV_INPUT: + case C.AKEYCODE_STB_POWER: + case C.AKEYCODE_STB_INPUT: + case C.AKEYCODE_AVR_POWER: + case C.AKEYCODE_AVR_INPUT: + case C.AKEYCODE_PROG_RED: + case C.AKEYCODE_PROG_GREEN: + case C.AKEYCODE_PROG_YELLOW: + case C.AKEYCODE_PROG_BLUE: + case C.AKEYCODE_APP_SWITCH: + case C.AKEYCODE_BUTTON_1: + case C.AKEYCODE_BUTTON_2: + case C.AKEYCODE_BUTTON_3: + case C.AKEYCODE_BUTTON_4: + case C.AKEYCODE_BUTTON_5: + case C.AKEYCODE_BUTTON_6: + case C.AKEYCODE_BUTTON_7: + case C.AKEYCODE_BUTTON_8: + case C.AKEYCODE_BUTTON_9: + case C.AKEYCODE_BUTTON_10: + case C.AKEYCODE_BUTTON_11: + case C.AKEYCODE_BUTTON_12: + case C.AKEYCODE_BUTTON_13: + case C.AKEYCODE_BUTTON_14: + case C.AKEYCODE_BUTTON_15: + case C.AKEYCODE_BUTTON_16: + case C.AKEYCODE_LANGUAGE_SWITCH: + case C.AKEYCODE_MANNER_MODE: + case C.AKEYCODE_3D_MODE: + case C.AKEYCODE_CONTACTS: + case C.AKEYCODE_CALENDAR: + case C.AKEYCODE_MUSIC: + case C.AKEYCODE_CALCULATOR: + } + /* Defined in an NDK API version beyond what we use today: + C.AKEYCODE_ASSIST + C.AKEYCODE_BRIGHTNESS_DOWN + C.AKEYCODE_BRIGHTNESS_UP + C.AKEYCODE_EISU + C.AKEYCODE_HENKAN + C.AKEYCODE_KANA + C.AKEYCODE_KATAKANA_HIRAGANA + C.AKEYCODE_MEDIA_AUDIO_TRACK + C.AKEYCODE_MUHENKAN + C.AKEYCODE_RO + C.AKEYCODE_YEN + C.AKEYCODE_ZENKAKU_HANKAKU + */ + return key.CodeUnknown +} diff --git a/vendor/golang.org/x/mobile/app/app.go b/vendor/golang.org/x/mobile/app/app.go new file mode 100644 index 0000000..e228b13 --- /dev/null +++ b/vendor/golang.org/x/mobile/app/app.go @@ -0,0 +1,213 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build linux darwin windows + +package app + +import ( + "golang.org/x/mobile/event/lifecycle" + "golang.org/x/mobile/event/size" + "golang.org/x/mobile/gl" + _ "golang.org/x/mobile/internal/mobileinit" +) + +// Main is called by the main.main function to run the mobile application. +// +// It calls f on the App, in a separate goroutine, as some OS-specific +// libraries require being on 'the main thread'. +func Main(f func(App)) { + main(f) +} + +// App is how a GUI mobile application interacts with the OS. +type App interface { + // Events returns the events channel. It carries events from the system to + // the app. The type of such events include: + // - lifecycle.Event + // - mouse.Event + // - paint.Event + // - size.Event + // - touch.Event + // from the golang.org/x/mobile/event/etc packages. Other packages may + // define other event types that are carried on this channel. + Events() <-chan interface{} + + // Send sends an event on the events channel. It does not block. + Send(event interface{}) + + // Publish flushes any pending drawing commands, such as OpenGL calls, and + // swaps the back buffer to the screen. + Publish() PublishResult + + // TODO: replace filters (and the Events channel) with a NextEvent method? + + // Filter calls each registered event filter function in sequence. + Filter(event interface{}) interface{} + + // RegisterFilter registers a event filter function to be called by Filter. The + // function can return a different event, or return nil to consume the event, + // but the function can also return its argument unchanged, where its purpose + // is to trigger a side effect rather than modify the event. + RegisterFilter(f func(interface{}) interface{}) +} + +// PublishResult is the result of an App.Publish call. +type PublishResult struct { + // BackBufferPreserved is whether the contents of the back buffer was + // preserved. If false, the contents are undefined. + BackBufferPreserved bool +} + +var theApp = &app{ + eventsOut: make(chan interface{}), + lifecycleStage: lifecycle.StageDead, + publish: make(chan struct{}), + publishResult: make(chan PublishResult), +} + +func init() { + theApp.eventsIn = pump(theApp.eventsOut) + theApp.glctx, theApp.worker = gl.NewContext() +} + +func (a *app) sendLifecycle(to lifecycle.Stage) { + if a.lifecycleStage == to { + return + } + a.eventsIn <- lifecycle.Event{ + From: a.lifecycleStage, + To: to, + DrawContext: a.glctx, + } + a.lifecycleStage = to +} + +type app struct { + filters []func(interface{}) interface{} + + eventsOut chan interface{} + eventsIn chan interface{} + lifecycleStage lifecycle.Stage + publish chan struct{} + publishResult chan PublishResult + + glctx gl.Context + worker gl.Worker +} + +func (a *app) Events() <-chan interface{} { + return a.eventsOut +} + +func (a *app) Send(event interface{}) { + a.eventsIn <- event +} + +func (a *app) Publish() PublishResult { + // gl.Flush is a lightweight (on modern GL drivers) blocking call + // that ensures all GL functions pending in the gl package have + // been passed onto the GL driver before the app package attempts + // to swap the screen buffer. + // + // This enforces that the final receive (for this paint cycle) on + // gl.WorkAvailable happens before the send on endPaint. + a.glctx.Flush() + a.publish <- struct{}{} + return <-a.publishResult +} + +func (a *app) Filter(event interface{}) interface{} { + for _, f := range a.filters { + event = f(event) + } + return event +} + +func (a *app) RegisterFilter(f func(interface{}) interface{}) { + a.filters = append(a.filters, f) +} + +type stopPumping struct{} + +// pump returns a channel src such that sending on src will eventually send on +// dst, in order, but that src will always be ready to send/receive soon, even +// if dst currently isn't. It is effectively an infinitely buffered channel. +// +// In particular, goroutine A sending on src will not deadlock even if goroutine +// B that's responsible for receiving on dst is currently blocked trying to +// send to A on a separate channel. +// +// Send a stopPumping on the src channel to close the dst channel after all queued +// events are sent on dst. After that, other goroutines can still send to src, +// so that such sends won't block forever, but such events will be ignored. +func pump(dst chan interface{}) (src chan interface{}) { + src = make(chan interface{}) + go func() { + // initialSize is the initial size of the circular buffer. It must be a + // power of 2. + const initialSize = 16 + i, j, buf, mask := 0, 0, make([]interface{}, initialSize), initialSize-1 + + srcActive := true + for { + maybeDst := dst + if i == j { + maybeDst = nil + } + if maybeDst == nil && !srcActive { + // Pump is stopped and empty. + break + } + + select { + case maybeDst <- buf[i&mask]: + buf[i&mask] = nil + i++ + + case e := <-src: + if _, ok := e.(stopPumping); ok { + srcActive = false + continue + } + + if !srcActive { + continue + } + + // Allocate a bigger buffer if necessary. + if i+len(buf) == j { + b := make([]interface{}, 2*len(buf)) + n := copy(b, buf[j&mask:]) + copy(b[n:], buf[:j&mask]) + i, j = 0, len(buf) + buf, mask = b, len(b)-1 + } + + buf[j&mask] = e + j++ + } + } + + close(dst) + // Block forever. + for range src { + } + }() + return src +} + +// TODO: do this for all build targets, not just linux (x11 and Android)? If +// so, should package gl instead of this package call RegisterFilter?? +// +// TODO: does Android need this?? It seems to work without it (Nexus 7, +// KitKat). If only x11 needs this, should we move this to x11.go?? +func (a *app) registerGLViewportFilter() { + a.RegisterFilter(func(e interface{}) interface{} { + if e, ok := e.(size.Event); ok { + a.glctx.Viewport(0, 0, e.WidthPx, e.HeightPx) + } + return e + }) +} diff --git a/vendor/golang.org/x/mobile/app/darwin_desktop.go b/vendor/golang.org/x/mobile/app/darwin_desktop.go new file mode 100644 index 0000000..5a0302f --- /dev/null +++ b/vendor/golang.org/x/mobile/app/darwin_desktop.go @@ -0,0 +1,496 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin +// +build !ios + +package app + +// Simple on-screen app debugging for OS X. Not an officially supported +// development target for apps, as screens with mice are very different +// than screens with touch panels. + +/* +#cgo CFLAGS: -x objective-c -DGL_SILENCE_DEPRECATION +#cgo LDFLAGS: -framework Cocoa -framework OpenGL +#import // for HIToolbox/Events.h +#import +#include + +void runApp(void); +void stopApp(void); +void makeCurrentContext(GLintptr); +uint64 threadID(); +*/ +import "C" +import ( + "log" + "runtime" + "sync" + + "golang.org/x/mobile/event/key" + "golang.org/x/mobile/event/lifecycle" + "golang.org/x/mobile/event/paint" + "golang.org/x/mobile/event/size" + "golang.org/x/mobile/event/touch" + "golang.org/x/mobile/geom" +) + +var initThreadID uint64 + +func init() { + // Lock the goroutine responsible for initialization to an OS thread. + // This means the goroutine running main (and calling runApp below) + // is locked to the OS thread that started the program. This is + // necessary for the correct delivery of Cocoa events to the process. + // + // A discussion on this topic: + // https://groups.google.com/forum/#!msg/golang-nuts/IiWZ2hUuLDA/SNKYYZBelsYJ + runtime.LockOSThread() + initThreadID = uint64(C.threadID()) +} + +func main(f func(App)) { + if tid := uint64(C.threadID()); tid != initThreadID { + log.Fatalf("app.Main called on thread %d, but app.init ran on %d", tid, initThreadID) + } + + go func() { + f(theApp) + C.stopApp() + // TODO(crawshaw): trigger runApp to return + }() + + C.runApp() +} + +// loop is the primary drawing loop. +// +// After Cocoa has captured the initial OS thread for processing Cocoa +// events in runApp, it starts loop on another goroutine. It is locked +// to an OS thread for its OpenGL context. +// +// The loop processes GL calls until a publish event appears. +// Then it runs any remaining GL calls and flushes the screen. +// +// As NSOpenGLCPSwapInterval is set to 1, the call to CGLFlushDrawable +// blocks until the screen refresh. +func (a *app) loop(ctx C.GLintptr) { + runtime.LockOSThread() + C.makeCurrentContext(ctx) + + workAvailable := a.worker.WorkAvailable() + + for { + select { + case <-workAvailable: + a.worker.DoWork() + case <-theApp.publish: + loop1: + for { + select { + case <-workAvailable: + a.worker.DoWork() + default: + break loop1 + } + } + C.CGLFlushDrawable(C.CGLGetCurrentContext()) + theApp.publishResult <- PublishResult{} + select { + case drawDone <- struct{}{}: + default: + } + } + } +} + +var drawDone = make(chan struct{}) + +// drawgl is used by Cocoa to occasionally request screen updates. +// +//export drawgl +func drawgl() { + switch theApp.lifecycleStage { + case lifecycle.StageFocused, lifecycle.StageVisible: + theApp.Send(paint.Event{ + External: true, + }) + <-drawDone + } +} + +//export startloop +func startloop(ctx C.GLintptr) { + go theApp.loop(ctx) +} + +var windowHeightPx float32 + +//export setGeom +func setGeom(pixelsPerPt float32, widthPx, heightPx int) { + windowHeightPx = float32(heightPx) + theApp.eventsIn <- size.Event{ + WidthPx: widthPx, + HeightPx: heightPx, + WidthPt: geom.Pt(float32(widthPx) / pixelsPerPt), + HeightPt: geom.Pt(float32(heightPx) / pixelsPerPt), + PixelsPerPt: pixelsPerPt, + } +} + +var touchEvents struct { + sync.Mutex + pending []touch.Event +} + +func sendTouch(t touch.Type, x, y float32) { + theApp.eventsIn <- touch.Event{ + X: x, + Y: windowHeightPx - y, + Sequence: 0, + Type: t, + } +} + +//export eventMouseDown +func eventMouseDown(x, y float32) { sendTouch(touch.TypeBegin, x, y) } + +//export eventMouseDragged +func eventMouseDragged(x, y float32) { sendTouch(touch.TypeMove, x, y) } + +//export eventMouseEnd +func eventMouseEnd(x, y float32) { sendTouch(touch.TypeEnd, x, y) } + +//export lifecycleDead +func lifecycleDead() { theApp.sendLifecycle(lifecycle.StageDead) } + +//export eventKey +func eventKey(runeVal int32, direction uint8, code uint16, flags uint32) { + var modifiers key.Modifiers + for _, mod := range mods { + if flags&mod.flags == mod.flags { + modifiers |= mod.mod + } + } + + theApp.eventsIn <- key.Event{ + Rune: convRune(rune(runeVal)), + Code: convVirtualKeyCode(code), + Modifiers: modifiers, + Direction: key.Direction(direction), + } +} + +//export eventFlags +func eventFlags(flags uint32) { + for _, mod := range mods { + if flags&mod.flags == mod.flags && lastFlags&mod.flags != mod.flags { + eventKey(-1, uint8(key.DirPress), mod.code, flags) + } + if lastFlags&mod.flags == mod.flags && flags&mod.flags != mod.flags { + eventKey(-1, uint8(key.DirRelease), mod.code, flags) + } + } + lastFlags = flags +} + +var lastFlags uint32 + +var mods = [...]struct { + flags uint32 + code uint16 + mod key.Modifiers +}{ + // Left and right variants of modifier keys have their own masks, + // but they are not documented. These were determined empirically. + {1<<17 | 0x102, C.kVK_Shift, key.ModShift}, + {1<<17 | 0x104, C.kVK_RightShift, key.ModShift}, + {1<<18 | 0x101, C.kVK_Control, key.ModControl}, + // TODO key.ControlRight + {1<<19 | 0x120, C.kVK_Option, key.ModAlt}, + {1<<19 | 0x140, C.kVK_RightOption, key.ModAlt}, + {1<<20 | 0x108, C.kVK_Command, key.ModMeta}, + {1<<20 | 0x110, C.kVK_Command, key.ModMeta}, // TODO: missing kVK_RightCommand +} + +//export lifecycleAlive +func lifecycleAlive() { theApp.sendLifecycle(lifecycle.StageAlive) } + +//export lifecycleVisible +func lifecycleVisible() { + theApp.sendLifecycle(lifecycle.StageVisible) +} + +//export lifecycleFocused +func lifecycleFocused() { theApp.sendLifecycle(lifecycle.StageFocused) } + +// convRune marks the Carbon/Cocoa private-range unicode rune representing +// a non-unicode key event to -1, used for Rune in the key package. +// +// http://www.unicode.org/Public/MAPPINGS/VENDORS/APPLE/CORPCHAR.TXT +func convRune(r rune) rune { + if '\uE000' <= r && r <= '\uF8FF' { + return -1 + } + return r +} + +// convVirtualKeyCode converts a Carbon/Cocoa virtual key code number +// into the standard keycodes used by the key package. +// +// To get a sense of the key map, see the diagram on +// http://boredzo.org/blog/archives/2007-05-22/virtual-key-codes +func convVirtualKeyCode(vkcode uint16) key.Code { + switch vkcode { + case C.kVK_ANSI_A: + return key.CodeA + case C.kVK_ANSI_B: + return key.CodeB + case C.kVK_ANSI_C: + return key.CodeC + case C.kVK_ANSI_D: + return key.CodeD + case C.kVK_ANSI_E: + return key.CodeE + case C.kVK_ANSI_F: + return key.CodeF + case C.kVK_ANSI_G: + return key.CodeG + case C.kVK_ANSI_H: + return key.CodeH + case C.kVK_ANSI_I: + return key.CodeI + case C.kVK_ANSI_J: + return key.CodeJ + case C.kVK_ANSI_K: + return key.CodeK + case C.kVK_ANSI_L: + return key.CodeL + case C.kVK_ANSI_M: + return key.CodeM + case C.kVK_ANSI_N: + return key.CodeN + case C.kVK_ANSI_O: + return key.CodeO + case C.kVK_ANSI_P: + return key.CodeP + case C.kVK_ANSI_Q: + return key.CodeQ + case C.kVK_ANSI_R: + return key.CodeR + case C.kVK_ANSI_S: + return key.CodeS + case C.kVK_ANSI_T: + return key.CodeT + case C.kVK_ANSI_U: + return key.CodeU + case C.kVK_ANSI_V: + return key.CodeV + case C.kVK_ANSI_W: + return key.CodeW + case C.kVK_ANSI_X: + return key.CodeX + case C.kVK_ANSI_Y: + return key.CodeY + case C.kVK_ANSI_Z: + return key.CodeZ + case C.kVK_ANSI_1: + return key.Code1 + case C.kVK_ANSI_2: + return key.Code2 + case C.kVK_ANSI_3: + return key.Code3 + case C.kVK_ANSI_4: + return key.Code4 + case C.kVK_ANSI_5: + return key.Code5 + case C.kVK_ANSI_6: + return key.Code6 + case C.kVK_ANSI_7: + return key.Code7 + case C.kVK_ANSI_8: + return key.Code8 + case C.kVK_ANSI_9: + return key.Code9 + case C.kVK_ANSI_0: + return key.Code0 + // TODO: move the rest of these codes to constants in key.go + // if we are happy with them. + case C.kVK_Return: + return key.CodeReturnEnter + case C.kVK_Escape: + return key.CodeEscape + case C.kVK_Delete: + return key.CodeDeleteBackspace + case C.kVK_Tab: + return key.CodeTab + case C.kVK_Space: + return key.CodeSpacebar + case C.kVK_ANSI_Minus: + return key.CodeHyphenMinus + case C.kVK_ANSI_Equal: + return key.CodeEqualSign + case C.kVK_ANSI_LeftBracket: + return key.CodeLeftSquareBracket + case C.kVK_ANSI_RightBracket: + return key.CodeRightSquareBracket + case C.kVK_ANSI_Backslash: + return key.CodeBackslash + // 50: Keyboard Non-US "#" and ~ + case C.kVK_ANSI_Semicolon: + return key.CodeSemicolon + case C.kVK_ANSI_Quote: + return key.CodeApostrophe + case C.kVK_ANSI_Grave: + return key.CodeGraveAccent + case C.kVK_ANSI_Comma: + return key.CodeComma + case C.kVK_ANSI_Period: + return key.CodeFullStop + case C.kVK_ANSI_Slash: + return key.CodeSlash + case C.kVK_CapsLock: + return key.CodeCapsLock + case C.kVK_F1: + return key.CodeF1 + case C.kVK_F2: + return key.CodeF2 + case C.kVK_F3: + return key.CodeF3 + case C.kVK_F4: + return key.CodeF4 + case C.kVK_F5: + return key.CodeF5 + case C.kVK_F6: + return key.CodeF6 + case C.kVK_F7: + return key.CodeF7 + case C.kVK_F8: + return key.CodeF8 + case C.kVK_F9: + return key.CodeF9 + case C.kVK_F10: + return key.CodeF10 + case C.kVK_F11: + return key.CodeF11 + case C.kVK_F12: + return key.CodeF12 + // 70: PrintScreen + // 71: Scroll Lock + // 72: Pause + // 73: Insert + case C.kVK_Home: + return key.CodeHome + case C.kVK_PageUp: + return key.CodePageUp + case C.kVK_ForwardDelete: + return key.CodeDeleteForward + case C.kVK_End: + return key.CodeEnd + case C.kVK_PageDown: + return key.CodePageDown + case C.kVK_RightArrow: + return key.CodeRightArrow + case C.kVK_LeftArrow: + return key.CodeLeftArrow + case C.kVK_DownArrow: + return key.CodeDownArrow + case C.kVK_UpArrow: + return key.CodeUpArrow + case C.kVK_ANSI_KeypadClear: + return key.CodeKeypadNumLock + case C.kVK_ANSI_KeypadDivide: + return key.CodeKeypadSlash + case C.kVK_ANSI_KeypadMultiply: + return key.CodeKeypadAsterisk + case C.kVK_ANSI_KeypadMinus: + return key.CodeKeypadHyphenMinus + case C.kVK_ANSI_KeypadPlus: + return key.CodeKeypadPlusSign + case C.kVK_ANSI_KeypadEnter: + return key.CodeKeypadEnter + case C.kVK_ANSI_Keypad1: + return key.CodeKeypad1 + case C.kVK_ANSI_Keypad2: + return key.CodeKeypad2 + case C.kVK_ANSI_Keypad3: + return key.CodeKeypad3 + case C.kVK_ANSI_Keypad4: + return key.CodeKeypad4 + case C.kVK_ANSI_Keypad5: + return key.CodeKeypad5 + case C.kVK_ANSI_Keypad6: + return key.CodeKeypad6 + case C.kVK_ANSI_Keypad7: + return key.CodeKeypad7 + case C.kVK_ANSI_Keypad8: + return key.CodeKeypad8 + case C.kVK_ANSI_Keypad9: + return key.CodeKeypad9 + case C.kVK_ANSI_Keypad0: + return key.CodeKeypad0 + case C.kVK_ANSI_KeypadDecimal: + return key.CodeKeypadFullStop + case C.kVK_ANSI_KeypadEquals: + return key.CodeKeypadEqualSign + case C.kVK_F13: + return key.CodeF13 + case C.kVK_F14: + return key.CodeF14 + case C.kVK_F15: + return key.CodeF15 + case C.kVK_F16: + return key.CodeF16 + case C.kVK_F17: + return key.CodeF17 + case C.kVK_F18: + return key.CodeF18 + case C.kVK_F19: + return key.CodeF19 + case C.kVK_F20: + return key.CodeF20 + // 116: Keyboard Execute + case C.kVK_Help: + return key.CodeHelp + // 118: Keyboard Menu + // 119: Keyboard Select + // 120: Keyboard Stop + // 121: Keyboard Again + // 122: Keyboard Undo + // 123: Keyboard Cut + // 124: Keyboard Copy + // 125: Keyboard Paste + // 126: Keyboard Find + case C.kVK_Mute: + return key.CodeMute + case C.kVK_VolumeUp: + return key.CodeVolumeUp + case C.kVK_VolumeDown: + return key.CodeVolumeDown + // 130: Keyboard Locking Caps Lock + // 131: Keyboard Locking Num Lock + // 132: Keyboard Locking Scroll Lock + // 133: Keyboard Comma + // 134: Keyboard Equal Sign + // ...: Bunch of stuff + case C.kVK_Control: + return key.CodeLeftControl + case C.kVK_Shift: + return key.CodeLeftShift + case C.kVK_Option: + return key.CodeLeftAlt + case C.kVK_Command: + return key.CodeLeftGUI + case C.kVK_RightControl: + return key.CodeRightControl + case C.kVK_RightShift: + return key.CodeRightShift + case C.kVK_RightOption: + return key.CodeRightAlt + // TODO key.CodeRightGUI + default: + return key.CodeUnknown + } +} diff --git a/vendor/golang.org/x/mobile/app/darwin_desktop.m b/vendor/golang.org/x/mobile/app/darwin_desktop.m new file mode 100644 index 0000000..615c29b --- /dev/null +++ b/vendor/golang.org/x/mobile/app/darwin_desktop.m @@ -0,0 +1,249 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin +// +build !ios + +#include "_cgo_export.h" +#include +#include + +#import +#import +#import + +void makeCurrentContext(GLintptr context) { + NSOpenGLContext* ctx = (NSOpenGLContext*)context; + [ctx makeCurrentContext]; +} + +uint64 threadID() { + uint64 id; + if (pthread_threadid_np(pthread_self(), &id)) { + abort(); + } + return id; +} + +@interface MobileGLView : NSOpenGLView +{ +} +@end + +@implementation MobileGLView +- (void)prepareOpenGL { + [self setWantsBestResolutionOpenGLSurface:YES]; + GLint swapInt = 1; + +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" + [[self openGLContext] setValues:&swapInt forParameter:NSOpenGLCPSwapInterval]; +#pragma clang diagnostic pop + + // Using attribute arrays in OpenGL 3.3 requires the use of a VBA. + // But VBAs don't exist in ES 2. So we bind a default one. + GLuint vba; + glGenVertexArrays(1, &vba); + glBindVertexArray(vba); + + startloop((GLintptr)[self openGLContext]); +} + +- (void)reshape { + [super reshape]; + + // Calculate screen PPI. + // + // Note that the backingScaleFactor converts from logical + // pixels to actual pixels, but both of these units vary + // independently from real world size. E.g. + // + // 13" Retina Macbook Pro, 2560x1600, 227ppi, backingScaleFactor=2, scale=3.15 + // 15" Retina Macbook Pro, 2880x1800, 220ppi, backingScaleFactor=2, scale=3.06 + // 27" iMac, 2560x1440, 109ppi, backingScaleFactor=1, scale=1.51 + // 27" Retina iMac, 5120x2880, 218ppi, backingScaleFactor=2, scale=3.03 + NSScreen *screen = [NSScreen mainScreen]; + double screenPixW = [screen frame].size.width * [screen backingScaleFactor]; + + CGDirectDisplayID display = (CGDirectDisplayID)[[[screen deviceDescription] valueForKey:@"NSScreenNumber"] intValue]; + CGSize screenSizeMM = CGDisplayScreenSize(display); // in millimeters + float ppi = 25.4 * screenPixW / screenSizeMM.width; + float pixelsPerPt = ppi/72.0; + + // The width and height reported to the geom package are the + // bounds of the OpenGL view. Several steps are necessary. + // First, [self bounds] gives us the number of logical pixels + // in the view. Multiplying this by the backingScaleFactor + // gives us the number of actual pixels. + NSRect r = [self bounds]; + int w = r.size.width * [screen backingScaleFactor]; + int h = r.size.height * [screen backingScaleFactor]; + + setGeom(pixelsPerPt, w, h); +} + +- (void)drawRect:(NSRect)theRect { + // Called during resize. This gets rid of flicker when resizing. + drawgl(); +} + +- (void)mouseDown:(NSEvent *)theEvent { + double scale = [[NSScreen mainScreen] backingScaleFactor]; + NSPoint p = [theEvent locationInWindow]; + eventMouseDown(p.x * scale, p.y * scale); +} + +- (void)mouseUp:(NSEvent *)theEvent { + double scale = [[NSScreen mainScreen] backingScaleFactor]; + NSPoint p = [theEvent locationInWindow]; + eventMouseEnd(p.x * scale, p.y * scale); +} + +- (void)mouseDragged:(NSEvent *)theEvent { + double scale = [[NSScreen mainScreen] backingScaleFactor]; + NSPoint p = [theEvent locationInWindow]; + eventMouseDragged(p.x * scale, p.y * scale); +} + +- (void)windowDidBecomeKey:(NSNotification *)notification { + lifecycleFocused(); +} + +- (void)windowDidResignKey:(NSNotification *)notification { + if (![NSApp isHidden]) { + lifecycleVisible(); + } +} + +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification { + lifecycleAlive(); + [[NSRunningApplication currentApplication] activateWithOptions:(NSApplicationActivateAllWindows | NSApplicationActivateIgnoringOtherApps)]; + [self.window makeKeyAndOrderFront:self]; + lifecycleVisible(); +} + +- (void)applicationWillTerminate:(NSNotification *)aNotification { + lifecycleDead(); +} + +- (void)applicationDidHide:(NSNotification *)aNotification { + lifecycleAlive(); +} + +- (void)applicationWillUnhide:(NSNotification *)notification { + lifecycleVisible(); +} + +- (void)windowWillClose:(NSNotification *)notification { + lifecycleAlive(); +} +@end + +@interface MobileResponder : NSResponder +{ +} +@end + +@implementation MobileResponder +- (void)keyDown:(NSEvent *)theEvent { + [self key:theEvent]; +} +- (void)keyUp:(NSEvent *)theEvent { + [self key:theEvent]; +} +- (void)key:(NSEvent *)theEvent { + NSRange range = [theEvent.characters rangeOfComposedCharacterSequenceAtIndex:0]; + + uint8_t buf[4] = {0, 0, 0, 0}; + if (![theEvent.characters getBytes:buf + maxLength:4 + usedLength:nil + encoding:NSUTF32LittleEndianStringEncoding + options:NSStringEncodingConversionAllowLossy + range:range + remainingRange:nil]) { + NSLog(@"failed to read key event %@", theEvent); + return; + } + + uint32_t rune = (uint32_t)buf[0]<<0 | (uint32_t)buf[1]<<8 | (uint32_t)buf[2]<<16 | (uint32_t)buf[3]<<24; + + uint8_t direction; + if ([theEvent isARepeat]) { + direction = 0; + } else if (theEvent.type == NSEventTypeKeyDown) { + direction = 1; + } else { + direction = 2; + } + eventKey((int32_t)rune, direction, theEvent.keyCode, theEvent.modifierFlags); +} + +- (void)flagsChanged:(NSEvent *)theEvent { + eventFlags(theEvent.modifierFlags); +} +@end + +void +runApp(void) { + [NSAutoreleasePool new]; + [NSApplication sharedApplication]; + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + + id menuBar = [[NSMenu new] autorelease]; + id menuItem = [[NSMenuItem new] autorelease]; + [menuBar addItem:menuItem]; + [NSApp setMainMenu:menuBar]; + + id menu = [[NSMenu new] autorelease]; + id name = [[NSProcessInfo processInfo] processName]; + + id hideMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Hide" + action:@selector(hide:) keyEquivalent:@"h"] + autorelease]; + [menu addItem:hideMenuItem]; + + id quitMenuItem = [[[NSMenuItem alloc] initWithTitle:@"Quit" + action:@selector(terminate:) keyEquivalent:@"q"] + autorelease]; + [menu addItem:quitMenuItem]; + [menuItem setSubmenu:menu]; + + NSRect rect = NSMakeRect(0, 0, 600, 800); + + NSWindow* window = [[[NSWindow alloc] initWithContentRect:rect + styleMask:NSWindowStyleMaskTitled + backing:NSBackingStoreBuffered + defer:NO] + autorelease]; + window.styleMask |= NSWindowStyleMaskResizable; + window.styleMask |= NSWindowStyleMaskMiniaturizable; + window.styleMask |= NSWindowStyleMaskClosable; + window.title = name; + [window cascadeTopLeftFromPoint:NSMakePoint(20,20)]; + + NSOpenGLPixelFormatAttribute attr[] = { + NSOpenGLPFAOpenGLProfile, NSOpenGLProfileVersion3_2Core, + NSOpenGLPFAColorSize, 24, + NSOpenGLPFAAlphaSize, 8, + NSOpenGLPFADepthSize, 16, + NSOpenGLPFAAccelerated, + NSOpenGLPFADoubleBuffer, + NSOpenGLPFAAllowOfflineRenderers, + 0 + }; + id pixFormat = [[NSOpenGLPixelFormat alloc] initWithAttributes:attr]; + MobileGLView* view = [[MobileGLView alloc] initWithFrame:rect pixelFormat:pixFormat]; + [window setContentView:view]; + [window setDelegate:view]; + [NSApp setDelegate:view]; + + window.nextResponder = [[[MobileResponder alloc] init] autorelease]; + + [NSApp run]; +} + +void stopApp(void) { + [NSApp terminate:nil]; +} diff --git a/vendor/golang.org/x/mobile/app/darwin_ios.go b/vendor/golang.org/x/mobile/app/darwin_ios.go new file mode 100644 index 0000000..f21816c --- /dev/null +++ b/vendor/golang.org/x/mobile/app/darwin_ios.go @@ -0,0 +1,216 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin +// +build ios + +package app + +/* +#cgo CFLAGS: -x objective-c -DGL_SILENCE_DEPRECATION +#cgo LDFLAGS: -framework Foundation -framework UIKit -framework GLKit -framework OpenGLES -framework QuartzCore +#include +#include +#include +#include +#import + +extern struct utsname sysInfo; + +void runApp(void); +void makeCurrentContext(GLintptr ctx); +void swapBuffers(GLintptr ctx); +uint64_t threadID(); +*/ +import "C" +import ( + "log" + "runtime" + "strings" + "sync" + + "golang.org/x/mobile/event/lifecycle" + "golang.org/x/mobile/event/paint" + "golang.org/x/mobile/event/size" + "golang.org/x/mobile/event/touch" + "golang.org/x/mobile/geom" +) + +var initThreadID uint64 + +func init() { + // Lock the goroutine responsible for initialization to an OS thread. + // This means the goroutine running main (and calling the run function + // below) is locked to the OS thread that started the program. This is + // necessary for the correct delivery of UIKit events to the process. + // + // A discussion on this topic: + // https://groups.google.com/forum/#!msg/golang-nuts/IiWZ2hUuLDA/SNKYYZBelsYJ + runtime.LockOSThread() + initThreadID = uint64(C.threadID()) +} + +func main(f func(App)) { + if tid := uint64(C.threadID()); tid != initThreadID { + log.Fatalf("app.Run called on thread %d, but app.init ran on %d", tid, initThreadID) + } + + go func() { + f(theApp) + // TODO(crawshaw): trigger runApp to return + }() + C.runApp() + panic("unexpected return from app.runApp") +} + +var pixelsPerPt float32 +var screenScale int // [UIScreen mainScreen].scale, either 1, 2, or 3. + +//export setScreen +func setScreen(scale int) { + C.uname(&C.sysInfo) + name := C.GoString(&C.sysInfo.machine[0]) + + var v float32 + + switch { + case strings.HasPrefix(name, "iPhone"): + v = 163 + case strings.HasPrefix(name, "iPad"): + // TODO: is there a better way to distinguish the iPad Mini? + switch name { + case "iPad2,5", "iPad2,6", "iPad2,7", "iPad4,4", "iPad4,5", "iPad4,6", "iPad4,7": + v = 163 // iPad Mini + default: + v = 132 + } + default: + v = 163 // names like i386 and x86_64 are the simulator + } + + if v == 0 { + log.Printf("unknown machine: %s", name) + v = 163 // emergency fallback + } + + pixelsPerPt = v * float32(scale) / 72 + screenScale = scale +} + +//export updateConfig +func updateConfig(width, height, orientation int32) { + o := size.OrientationUnknown + switch orientation { + case C.UIDeviceOrientationPortrait, C.UIDeviceOrientationPortraitUpsideDown: + o = size.OrientationPortrait + case C.UIDeviceOrientationLandscapeLeft, C.UIDeviceOrientationLandscapeRight: + o = size.OrientationLandscape + } + widthPx := screenScale * int(width) + heightPx := screenScale * int(height) + theApp.eventsIn <- size.Event{ + WidthPx: widthPx, + HeightPx: heightPx, + WidthPt: geom.Pt(float32(widthPx) / pixelsPerPt), + HeightPt: geom.Pt(float32(heightPx) / pixelsPerPt), + PixelsPerPt: pixelsPerPt, + Orientation: o, + } + theApp.eventsIn <- paint.Event{External: true} +} + +// touchIDs is the current active touches. The position in the array +// is the ID, the value is the UITouch* pointer value. +// +// It is widely reported that the iPhone can handle up to 5 simultaneous +// touch events, while the iPad can handle 11. +var touchIDs [11]uintptr + +var touchEvents struct { + sync.Mutex + pending []touch.Event +} + +//export sendTouch +func sendTouch(cTouch, cTouchType uintptr, x, y float32) { + id := -1 + for i, val := range touchIDs { + if val == cTouch { + id = i + break + } + } + if id == -1 { + for i, val := range touchIDs { + if val == 0 { + touchIDs[i] = cTouch + id = i + break + } + } + if id == -1 { + panic("out of touchIDs") + } + } + + t := touch.Type(cTouchType) + if t == touch.TypeEnd { + touchIDs[id] = 0 + } + + theApp.eventsIn <- touch.Event{ + X: x, + Y: y, + Sequence: touch.Sequence(id), + Type: t, + } +} + +//export lifecycleDead +func lifecycleDead() { theApp.sendLifecycle(lifecycle.StageDead) } + +//export lifecycleAlive +func lifecycleAlive() { theApp.sendLifecycle(lifecycle.StageAlive) } + +//export lifecycleVisible +func lifecycleVisible() { theApp.sendLifecycle(lifecycle.StageVisible) } + +//export lifecycleFocused +func lifecycleFocused() { theApp.sendLifecycle(lifecycle.StageFocused) } + +//export startloop +func startloop(ctx C.GLintptr) { + go theApp.loop(ctx) +} + +// loop is the primary drawing loop. +// +// After UIKit has captured the initial OS thread for processing UIKit +// events in runApp, it starts loop on another goroutine. It is locked +// to an OS thread for its OpenGL context. +func (a *app) loop(ctx C.GLintptr) { + runtime.LockOSThread() + C.makeCurrentContext(ctx) + + workAvailable := a.worker.WorkAvailable() + + for { + select { + case <-workAvailable: + a.worker.DoWork() + case <-theApp.publish: + loop1: + for { + select { + case <-workAvailable: + a.worker.DoWork() + default: + break loop1 + } + } + C.swapBuffers(ctx) + theApp.publishResult <- PublishResult{} + } + } +} diff --git a/vendor/golang.org/x/mobile/app/darwin_ios.m b/vendor/golang.org/x/mobile/app/darwin_ios.m new file mode 100644 index 0000000..08bb72f --- /dev/null +++ b/vendor/golang.org/x/mobile/app/darwin_ios.m @@ -0,0 +1,165 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin +// +build ios + +#include "_cgo_export.h" +#include +#include +#include + +#import +#import + +struct utsname sysInfo; + +@interface GoAppAppController : GLKViewController +@end + +@interface GoAppAppDelegate : UIResponder +@property (strong, nonatomic) UIWindow *window; +@property (strong, nonatomic) GoAppAppController *controller; +@end + +@implementation GoAppAppDelegate +- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { + lifecycleAlive(); + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.controller = [[GoAppAppController alloc] initWithNibName:nil bundle:nil]; + self.window.rootViewController = self.controller; + [self.window makeKeyAndVisible]; + return YES; +} + +- (void)applicationDidBecomeActive:(UIApplication * )application { + lifecycleFocused(); +} + +- (void)applicationWillResignActive:(UIApplication *)application { + lifecycleVisible(); +} + +- (void)applicationDidEnterBackground:(UIApplication *)application { + lifecycleAlive(); +} + +- (void)applicationWillTerminate:(UIApplication *)application { + lifecycleDead(); +} +@end + +@interface GoAppAppController () +@property (strong, nonatomic) EAGLContext *context; +@property (strong, nonatomic) GLKView *glview; +@end + +@implementation GoAppAppController +- (void)viewWillAppear:(BOOL)animated +{ + // TODO: replace by swapping out GLKViewController for a UIVIewController. + [super viewWillAppear:animated]; + self.paused = YES; +} + +- (void)viewDidLoad { + [super viewDidLoad]; + self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; + self.glview = (GLKView*)self.view; + self.glview.drawableDepthFormat = GLKViewDrawableDepthFormat24; + self.glview.multipleTouchEnabled = true; // TODO expose setting to user. + self.glview.context = self.context; + self.glview.userInteractionEnabled = YES; + self.glview.enableSetNeedsDisplay = YES; // only invoked once + + // Do not use the GLKViewController draw loop. + self.paused = YES; + self.resumeOnDidBecomeActive = NO; + self.preferredFramesPerSecond = 0; + + int scale = 1; + if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) { + scale = (int)[UIScreen mainScreen].scale; // either 1.0, 2.0, or 3.0. + } + setScreen(scale); + + CGSize size = [UIScreen mainScreen].bounds.size; + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + updateConfig((int)size.width, (int)size.height, orientation); +} + +- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { + [coordinator animateAlongsideTransition:^(id context) { + // TODO(crawshaw): come up with a plan to handle animations. + } completion:^(id context) { + UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; + updateConfig((int)size.width, (int)size.height, orientation); + }]; +} + +- (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { + // Now that we have been asked to do the first draw, disable any + // future draw and hand control over to the Go paint.Event cycle. + self.glview.enableSetNeedsDisplay = NO; + startloop((GLintptr)self.context); +} + +#define TOUCH_TYPE_BEGIN 0 // touch.TypeBegin +#define TOUCH_TYPE_MOVE 1 // touch.TypeMove +#define TOUCH_TYPE_END 2 // touch.TypeEnd + +static void sendTouches(int change, NSSet* touches) { + CGFloat scale = [UIScreen mainScreen].scale; + for (UITouch* touch in touches) { + CGPoint p = [touch locationInView:touch.view]; + sendTouch((GoUintptr)touch, (GoUintptr)change, p.x*scale, p.y*scale); + } +} + +- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { + sendTouches(TOUCH_TYPE_BEGIN, touches); +} + +- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { + sendTouches(TOUCH_TYPE_MOVE, touches); +} + +- (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { + sendTouches(TOUCH_TYPE_END, touches); +} + +- (void)touchesCanceled:(NSSet*)touches withEvent:(UIEvent*)event { + sendTouches(TOUCH_TYPE_END, touches); +} +@end + +void runApp(void) { + @autoreleasepool { + UIApplicationMain(0, nil, nil, NSStringFromClass([GoAppAppDelegate class])); + } +} + +void makeCurrentContext(GLintptr context) { + EAGLContext* ctx = (EAGLContext*)context; + if (![EAGLContext setCurrentContext:ctx]) { + // TODO(crawshaw): determine how terrible this is. Exit? + NSLog(@"failed to set current context"); + } +} + +void swapBuffers(GLintptr context) { + __block EAGLContext* ctx = (EAGLContext*)context; + dispatch_sync(dispatch_get_main_queue(), ^{ + [EAGLContext setCurrentContext:ctx]; + [ctx presentRenderbuffer:GL_RENDERBUFFER]; + }); +} + +uint64_t threadID() { + uint64_t id; + if (pthread_threadid_np(pthread_self(), &id)) { + abort(); + } + return id; +} diff --git a/vendor/golang.org/x/mobile/app/doc.go b/vendor/golang.org/x/mobile/app/doc.go new file mode 100644 index 0000000..80e21a0 --- /dev/null +++ b/vendor/golang.org/x/mobile/app/doc.go @@ -0,0 +1,85 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +/* +Package app lets you write portable all-Go apps for Android and iOS. + +There are typically two ways to use Go on Android and iOS. The first +is to write a Go library and use `gomobile bind` to generate language +bindings for Java and Objective-C. Building a library does not +require the app package. The `gomobile bind` command produces output +that you can include in an Android Studio or Xcode project. For more +on language bindings, see https://golang.org/x/mobile/cmd/gobind. + +The second way is to write an app entirely in Go. The APIs are limited +to those that are portable between both Android and iOS, in particular +OpenGL, audio, and other Android NDK-like APIs. An all-Go app should +use this app package to initialize the app, manage its lifecycle, and +receive events. + +Building apps + +Apps written entirely in Go have a main function, and can be built +with `gomobile build`, which directly produces runnable output for +Android and iOS. + +The gomobile tool can get installed with go get. For reference, see +https://golang.org/x/mobile/cmd/gomobile. + +For detailed instructions and documentation, see +https://golang.org/wiki/Mobile. + +Event processing in Native Apps + +The Go runtime is initialized on Android when NativeActivity onCreate is +called, and on iOS when the process starts. In both cases, Go init functions +run before the app lifecycle has started. + +An app is expected to call the Main function in main.main. When the function +exits, the app exits. Inside the func passed to Main, call Filter on every +event received, and then switch on its type. Registered filters run when the +event is received, not when it is sent, so that filters run in the same +goroutine as other code that calls OpenGL. + + package main + + import ( + "log" + + "golang.org/x/mobile/app" + "golang.org/x/mobile/event/lifecycle" + "golang.org/x/mobile/event/paint" + ) + + func main() { + app.Main(func(a app.App) { + for e := range a.Events() { + switch e := a.Filter(e).(type) { + case lifecycle.Event: + // ... + case paint.Event: + log.Print("Call OpenGL here.") + a.Publish() + } + } + }) + } + +An event is represented by the empty interface type interface{}. Any value can +be an event. Commonly used types include Event types defined by the following +packages: + - golang.org/x/mobile/event/lifecycle + - golang.org/x/mobile/event/mouse + - golang.org/x/mobile/event/paint + - golang.org/x/mobile/event/size + - golang.org/x/mobile/event/touch +For example, touch.Event is the type that represents touch events. Other +packages may define their own events, and send them on an app's event channel. + +Other packages can also register event filters, e.g. to manage resources in +response to lifecycle events. Such packages should call: + app.RegisterFilter(etc) +in an init function inside that package. +*/ +package app // import "golang.org/x/mobile/app" diff --git a/vendor/golang.org/x/mobile/app/internal/callfn/callfn.go b/vendor/golang.org/x/mobile/app/internal/callfn/callfn.go new file mode 100644 index 0000000..42dd028 --- /dev/null +++ b/vendor/golang.org/x/mobile/app/internal/callfn/callfn.go @@ -0,0 +1,17 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build android +// +build arm 386 amd64 arm64 + +// Package callfn provides an android entry point. +// +// It is a separate package from app because it contains Go assembly, +// which does not compile in a package using cgo. +package callfn + +// CallFn calls a zero-argument function by its program counter. +// It is only intended for calling main.main. Using it for +// anything else will not end well. +func CallFn(fn uintptr) diff --git a/vendor/golang.org/x/mobile/app/internal/callfn/callfn_386.s b/vendor/golang.org/x/mobile/app/internal/callfn/callfn_386.s new file mode 100644 index 0000000..d2bb54f --- /dev/null +++ b/vendor/golang.org/x/mobile/app/internal/callfn/callfn_386.s @@ -0,0 +1,11 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" +#include "funcdata.h" + +TEXT ·CallFn(SB),$0-4 + MOVL fn+0(FP), AX + CALL AX + RET diff --git a/vendor/golang.org/x/mobile/app/internal/callfn/callfn_amd64.s b/vendor/golang.org/x/mobile/app/internal/callfn/callfn_amd64.s new file mode 100644 index 0000000..8769604 --- /dev/null +++ b/vendor/golang.org/x/mobile/app/internal/callfn/callfn_amd64.s @@ -0,0 +1,11 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" +#include "funcdata.h" + +TEXT ·CallFn(SB),$0-8 + MOVQ fn+0(FP), AX + CALL AX + RET diff --git a/vendor/golang.org/x/mobile/app/internal/callfn/callfn_arm.s b/vendor/golang.org/x/mobile/app/internal/callfn/callfn_arm.s new file mode 100644 index 0000000..d71f748 --- /dev/null +++ b/vendor/golang.org/x/mobile/app/internal/callfn/callfn_arm.s @@ -0,0 +1,11 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" +#include "funcdata.h" + +TEXT ·CallFn(SB),$0-4 + MOVW fn+0(FP), R0 + BL (R0) + RET diff --git a/vendor/golang.org/x/mobile/app/internal/callfn/callfn_arm64.s b/vendor/golang.org/x/mobile/app/internal/callfn/callfn_arm64.s new file mode 100644 index 0000000..545ad50 --- /dev/null +++ b/vendor/golang.org/x/mobile/app/internal/callfn/callfn_arm64.s @@ -0,0 +1,11 @@ +// Copyright 2016 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" +#include "funcdata.h" + +TEXT ·CallFn(SB),$0-8 + MOVD fn+0(FP), R0 + BL (R0) + RET diff --git a/vendor/golang.org/x/mobile/app/shiny.go b/vendor/golang.org/x/mobile/app/shiny.go new file mode 100644 index 0000000..3257dfa --- /dev/null +++ b/vendor/golang.org/x/mobile/app/shiny.go @@ -0,0 +1,70 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows + +package app + +import ( + "log" + + "golang.org/x/exp/shiny/driver/gldriver" + "golang.org/x/exp/shiny/screen" + "golang.org/x/mobile/event/lifecycle" + "golang.org/x/mobile/event/mouse" + "golang.org/x/mobile/event/touch" + "golang.org/x/mobile/gl" +) + +func main(f func(a App)) { + gldriver.Main(func(s screen.Screen) { + w, err := s.NewWindow(nil) + if err != nil { + log.Fatal(err) + } + defer w.Release() + + theApp.glctx = nil + theApp.worker = nil // handled by shiny + + go func() { + for range theApp.publish { + res := w.Publish() + theApp.publishResult <- PublishResult{ + BackBufferPreserved: res.BackBufferPreserved, + } + } + }() + + go f(theApp) + + for { + theApp.Send(convertEvent(w.NextEvent())) + } + }) +} + +func convertEvent(e interface{}) interface{} { + switch e := e.(type) { + case lifecycle.Event: + if theApp.glctx == nil { + theApp.glctx = e.DrawContext.(gl.Context) + } + case mouse.Event: + te := touch.Event{ + X: e.X, + Y: e.Y, + } + switch e.Direction { + case mouse.DirNone: + te.Type = touch.TypeMove + case mouse.DirPress: + te.Type = touch.TypeBegin + case mouse.DirRelease: + te.Type = touch.TypeEnd + } + return te + } + return e +} diff --git a/vendor/golang.org/x/mobile/app/x11.c b/vendor/golang.org/x/mobile/app/x11.c new file mode 100644 index 0000000..f4a7ef3 --- /dev/null +++ b/vendor/golang.org/x/mobile/app/x11.c @@ -0,0 +1,173 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build linux,!android + +#include "_cgo_export.h" +#include +#include +#include +#include +#include + +static Atom wm_delete_window; + +static Window +new_window(Display *x_dpy, EGLDisplay e_dpy, int w, int h, EGLContext *ctx, EGLSurface *surf) { + static const EGLint attribs[] = { + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_SURFACE_TYPE, EGL_WINDOW_BIT, + EGL_BLUE_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_RED_SIZE, 8, + EGL_DEPTH_SIZE, 16, + EGL_CONFIG_CAVEAT, EGL_NONE, + EGL_NONE + }; + EGLConfig config; + EGLint num_configs; + if (!eglChooseConfig(e_dpy, attribs, &config, 1, &num_configs)) { + fprintf(stderr, "eglChooseConfig failed\n"); + exit(1); + } + EGLint vid; + if (!eglGetConfigAttrib(e_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { + fprintf(stderr, "eglGetConfigAttrib failed\n"); + exit(1); + } + + XVisualInfo visTemplate; + visTemplate.visualid = vid; + int num_visuals; + XVisualInfo *visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); + if (!visInfo) { + fprintf(stderr, "XGetVisualInfo failed\n"); + exit(1); + } + + Window root = RootWindow(x_dpy, DefaultScreen(x_dpy)); + XSetWindowAttributes attr; + + attr.colormap = XCreateColormap(x_dpy, root, visInfo->visual, AllocNone); + if (!attr.colormap) { + fprintf(stderr, "XCreateColormap failed\n"); + exit(1); + } + + attr.event_mask = StructureNotifyMask | ExposureMask | + ButtonPressMask | ButtonReleaseMask | ButtonMotionMask; + Window win = XCreateWindow( + x_dpy, root, 0, 0, w, h, 0, visInfo->depth, InputOutput, + visInfo->visual, CWColormap | CWEventMask, &attr); + XFree(visInfo); + + XSizeHints sizehints; + sizehints.width = w; + sizehints.height = h; + sizehints.flags = USSize; + XSetNormalHints(x_dpy, win, &sizehints); + XSetStandardProperties(x_dpy, win, "App", "App", None, (char **)NULL, 0, &sizehints); + + static const EGLint ctx_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + *ctx = eglCreateContext(e_dpy, config, EGL_NO_CONTEXT, ctx_attribs); + if (!*ctx) { + fprintf(stderr, "eglCreateContext failed\n"); + exit(1); + } + *surf = eglCreateWindowSurface(e_dpy, config, win, NULL); + if (!*surf) { + fprintf(stderr, "eglCreateWindowSurface failed\n"); + exit(1); + } + return win; +} + +Display *x_dpy; +EGLDisplay e_dpy; +EGLContext e_ctx; +EGLSurface e_surf; +Window win; + +void +createWindow(void) { + x_dpy = XOpenDisplay(NULL); + if (!x_dpy) { + fprintf(stderr, "XOpenDisplay failed\n"); + exit(1); + } + e_dpy = eglGetDisplay(x_dpy); + if (!e_dpy) { + fprintf(stderr, "eglGetDisplay failed\n"); + exit(1); + } + EGLint e_major, e_minor; + if (!eglInitialize(e_dpy, &e_major, &e_minor)) { + fprintf(stderr, "eglInitialize failed\n"); + exit(1); + } + eglBindAPI(EGL_OPENGL_ES_API); + win = new_window(x_dpy, e_dpy, 600, 800, &e_ctx, &e_surf); + + wm_delete_window = XInternAtom(x_dpy, "WM_DELETE_WINDOW", True); + if (wm_delete_window != None) { + XSetWMProtocols(x_dpy, win, &wm_delete_window, 1); + } + + XMapWindow(x_dpy, win); + if (!eglMakeCurrent(e_dpy, e_surf, e_surf, e_ctx)) { + fprintf(stderr, "eglMakeCurrent failed\n"); + exit(1); + } + + // Window size and DPI should be initialized before starting app. + XEvent ev; + while (1) { + if (XCheckMaskEvent(x_dpy, StructureNotifyMask, &ev) == False) { + continue; + } + if (ev.type == ConfigureNotify) { + onResize(ev.xconfigure.width, ev.xconfigure.height); + break; + } + } +} + +void +processEvents(void) { + while (XPending(x_dpy)) { + XEvent ev; + XNextEvent(x_dpy, &ev); + switch (ev.type) { + case ButtonPress: + onTouchBegin((float)ev.xbutton.x, (float)ev.xbutton.y); + break; + case ButtonRelease: + onTouchEnd((float)ev.xbutton.x, (float)ev.xbutton.y); + break; + case MotionNotify: + onTouchMove((float)ev.xmotion.x, (float)ev.xmotion.y); + break; + case ConfigureNotify: + onResize(ev.xconfigure.width, ev.xconfigure.height); + break; + case ClientMessage: + if (wm_delete_window != None && (Atom)ev.xclient.data.l[0] == wm_delete_window) { + onStop(); + return; + } + break; + } + } +} + +void +swapBuffers(void) { + if (eglSwapBuffers(e_dpy, e_surf) == EGL_FALSE) { + fprintf(stderr, "eglSwapBuffer failed\n"); + exit(1); + } +} diff --git a/vendor/golang.org/x/mobile/app/x11.go b/vendor/golang.org/x/mobile/app/x11.go new file mode 100644 index 0000000..d6fe7b2 --- /dev/null +++ b/vendor/golang.org/x/mobile/app/x11.go @@ -0,0 +1,122 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build linux,!android + +package app + +/* +Simple on-screen app debugging for X11. Not an officially supported +development target for apps, as screens with mice are very different +than screens with touch panels. +*/ + +/* +#cgo LDFLAGS: -lEGL -lGLESv2 -lX11 + +void createWindow(void); +void processEvents(void); +void swapBuffers(void); +*/ +import "C" +import ( + "runtime" + "time" + + "golang.org/x/mobile/event/lifecycle" + "golang.org/x/mobile/event/paint" + "golang.org/x/mobile/event/size" + "golang.org/x/mobile/event/touch" + "golang.org/x/mobile/geom" +) + +func init() { + theApp.registerGLViewportFilter() +} + +func main(f func(App)) { + runtime.LockOSThread() + + workAvailable := theApp.worker.WorkAvailable() + + C.createWindow() + + // TODO: send lifecycle events when e.g. the X11 window is iconified or moved off-screen. + theApp.sendLifecycle(lifecycle.StageFocused) + + // TODO: translate X11 expose events to shiny paint events, instead of + // sending this synthetic paint event as a hack. + theApp.eventsIn <- paint.Event{} + + donec := make(chan struct{}) + go func() { + f(theApp) + close(donec) + }() + + // TODO: can we get the actual vsync signal? + ticker := time.NewTicker(time.Second / 60) + defer ticker.Stop() + var tc <-chan time.Time + + for { + select { + case <-donec: + return + case <-workAvailable: + theApp.worker.DoWork() + case <-theApp.publish: + C.swapBuffers() + tc = ticker.C + case <-tc: + tc = nil + theApp.publishResult <- PublishResult{} + } + C.processEvents() + } +} + +//export onResize +func onResize(w, h int) { + // TODO(nigeltao): don't assume 72 DPI. DisplayWidth and DisplayWidthMM + // is probably the best place to start looking. + pixelsPerPt := float32(1) + theApp.eventsIn <- size.Event{ + WidthPx: w, + HeightPx: h, + WidthPt: geom.Pt(w), + HeightPt: geom.Pt(h), + PixelsPerPt: pixelsPerPt, + } +} + +func sendTouch(t touch.Type, x, y float32) { + theApp.eventsIn <- touch.Event{ + X: x, + Y: y, + Sequence: 0, // TODO: button?? + Type: t, + } +} + +//export onTouchBegin +func onTouchBegin(x, y float32) { sendTouch(touch.TypeBegin, x, y) } + +//export onTouchMove +func onTouchMove(x, y float32) { sendTouch(touch.TypeMove, x, y) } + +//export onTouchEnd +func onTouchEnd(x, y float32) { sendTouch(touch.TypeEnd, x, y) } + +var stopped bool + +//export onStop +func onStop() { + if stopped { + return + } + stopped = true + theApp.sendLifecycle(lifecycle.StageDead) + theApp.eventsIn <- stopPumping{} +} diff --git a/vendor/golang.org/x/mobile/event/lifecycle/lifecycle.go b/vendor/golang.org/x/mobile/event/lifecycle/lifecycle.go index bed3b49..9a5f54e 100644 --- a/vendor/golang.org/x/mobile/event/lifecycle/lifecycle.go +++ b/vendor/golang.org/x/mobile/event/lifecycle/lifecycle.go @@ -58,7 +58,7 @@ func (e Event) String() string { return fmt.Sprintf("lifecycle.Event{From:%v, To:%v, DrawContext:%v}", e.From, e.To, e.DrawContext) } -// Crosses returns whether the transition from From to To crosses the stage s: +// Crosses reports whether the transition from From to To crosses the stage s: // - It returns CrossOn if it does, and the lifecycle change is positive. // - It returns CrossOff if it does, and the lifecycle change is negative. // - Otherwise, it returns CrossNone. diff --git a/vendor/golang.org/x/mobile/event/mouse/mouse.go b/vendor/golang.org/x/mobile/event/mouse/mouse.go index 45029cc..eec2fc0 100644 --- a/vendor/golang.org/x/mobile/event/mouse/mouse.go +++ b/vendor/golang.org/x/mobile/event/mouse/mouse.go @@ -40,7 +40,7 @@ type Event struct { // Button is a mouse button. type Button int32 -// IsWheel returns whether the button is for a scroll wheel. +// IsWheel reports whether the button is for a scroll wheel. func (b Button) IsWheel() bool { return b < 0 } diff --git a/vendor/golang.org/x/mobile/event/touch/touch.go b/vendor/golang.org/x/mobile/event/touch/touch.go new file mode 100644 index 0000000..c91967b --- /dev/null +++ b/vendor/golang.org/x/mobile/event/touch/touch.go @@ -0,0 +1,72 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package touch defines an event for touch input. +// +// See the golang.org/x/mobile/app package for details on the event model. +package touch // import "golang.org/x/mobile/event/touch" + +// The best source on android input events is the NDK: include/android/input.h +// +// iOS event handling guide: +// https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS + +import ( + "fmt" +) + +// Event is a touch event. +type Event struct { + // X and Y are the touch location, in pixels. + X, Y float32 + + // Sequence is the sequence number. The same number is shared by all events + // in a sequence. A sequence begins with a single TypeBegin, is followed by + // zero or more TypeMoves, and ends with a single TypeEnd. A Sequence + // distinguishes concurrent sequences but its value is subsequently reused. + Sequence Sequence + + // Type is the touch type. + Type Type +} + +// Sequence identifies a sequence of touch events. +type Sequence int64 + +// Type describes the type of a touch event. +type Type byte + +const ( + // TypeBegin is a user first touching the device. + // + // On Android, this is a AMOTION_EVENT_ACTION_DOWN. + // On iOS, this is a call to touchesBegan. + TypeBegin Type = iota + + // TypeMove is a user dragging across the device. + // + // A TypeMove is delivered between a TypeBegin and TypeEnd. + // + // On Android, this is a AMOTION_EVENT_ACTION_MOVE. + // On iOS, this is a call to touchesMoved. + TypeMove + + // TypeEnd is a user no longer touching the device. + // + // On Android, this is a AMOTION_EVENT_ACTION_UP. + // On iOS, this is a call to touchesEnded. + TypeEnd +) + +func (t Type) String() string { + switch t { + case TypeBegin: + return "begin" + case TypeMove: + return "move" + case TypeEnd: + return "end" + } + return fmt.Sprintf("touch.Type(%d)", t) +} diff --git a/vendor/golang.org/x/mobile/exp/f32/affine.go b/vendor/golang.org/x/mobile/exp/f32/affine.go new file mode 100644 index 0000000..708a309 --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/f32/affine.go @@ -0,0 +1,109 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package f32 + +import "fmt" + +// An Affine is a 3x3 matrix of float32 values for which the bottom row is +// implicitly always equal to [0 0 1]. +// Elements are indexed first by row then column, i.e. m[row][column]. +type Affine [2]Vec3 + +func (m Affine) String() string { + return fmt.Sprintf(`Affine[% 0.3f, % 0.3f, % 0.3f, + % 0.3f, % 0.3f, % 0.3f]`, + m[0][0], m[0][1], m[0][2], + m[1][0], m[1][1], m[1][2]) +} + +// Identity sets m to be the identity transform. +func (m *Affine) Identity() { + *m = Affine{ + {1, 0, 0}, + {0, 1, 0}, + } +} + +// Eq reports whether each component of m is within epsilon of the same +// component in n. +func (m *Affine) Eq(n *Affine, epsilon float32) bool { + for i := range m { + for j := range m[i] { + diff := m[i][j] - n[i][j] + if diff < -epsilon || +epsilon < diff { + return false + } + } + } + return true +} + +// Mul sets m to be p × q. +func (m *Affine) Mul(p, q *Affine) { + // Store the result in local variables, in case m == a || m == b. + m00 := p[0][0]*q[0][0] + p[0][1]*q[1][0] + m01 := p[0][0]*q[0][1] + p[0][1]*q[1][1] + m02 := p[0][0]*q[0][2] + p[0][1]*q[1][2] + p[0][2] + m10 := p[1][0]*q[0][0] + p[1][1]*q[1][0] + m11 := p[1][0]*q[0][1] + p[1][1]*q[1][1] + m12 := p[1][0]*q[0][2] + p[1][1]*q[1][2] + p[1][2] + m[0][0] = m00 + m[0][1] = m01 + m[0][2] = m02 + m[1][0] = m10 + m[1][1] = m11 + m[1][2] = m12 +} + +// Inverse sets m to be the inverse of p. +func (m *Affine) Inverse(p *Affine) { + m00 := p[1][1] + m01 := -p[0][1] + m02 := p[1][2]*p[0][1] - p[1][1]*p[0][2] + m10 := -p[1][0] + m11 := p[0][0] + m12 := p[1][0]*p[0][2] - p[1][2]*p[0][0] + + det := m00*m11 - m10*m01 + + m[0][0] = m00 / det + m[0][1] = m01 / det + m[0][2] = m02 / det + m[1][0] = m10 / det + m[1][1] = m11 / det + m[1][2] = m12 / det +} + +// Scale sets m to be a scale followed by p. +// It is equivalent to m.Mul(p, &Affine{{x,0,0}, {0,y,0}}). +func (m *Affine) Scale(p *Affine, x, y float32) { + m[0][0] = p[0][0] * x + m[0][1] = p[0][1] * y + m[0][2] = p[0][2] + m[1][0] = p[1][0] * x + m[1][1] = p[1][1] * y + m[1][2] = p[1][2] +} + +// Translate sets m to be a translation followed by p. +// It is equivalent to m.Mul(p, &Affine{{1,0,x}, {0,1,y}}). +func (m *Affine) Translate(p *Affine, x, y float32) { + m[0][0] = p[0][0] + m[0][1] = p[0][1] + m[0][2] = p[0][0]*x + p[0][1]*y + p[0][2] + m[1][0] = p[1][0] + m[1][1] = p[1][1] + m[1][2] = p[1][0]*x + p[1][1]*y + p[1][2] +} + +// Rotate sets m to a rotation in radians followed by p. +// It is equivalent to m.Mul(p, affineRotation). +func (m *Affine) Rotate(p *Affine, radians float32) { + s, c := Sin(radians), Cos(radians) + m.Mul(p, &Affine{ + {+c, +s, 0}, + {-s, +c, 0}, + }) +} diff --git a/vendor/golang.org/x/mobile/exp/f32/f32.go b/vendor/golang.org/x/mobile/exp/f32/f32.go new file mode 100644 index 0000000..d794398 --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/f32/f32.go @@ -0,0 +1,93 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +//go:generate go run gen.go -output table.go + +// Package f32 implements some linear algebra and GL helpers for float32s. +// +// Types defined in this package have methods implementing common +// mathematical operations. The common form for these functions is +// +// func (dst *T) Op(lhs, rhs *T) +// +// which reads in traditional mathematical notation as +// +// dst = lhs op rhs. +// +// It is safe to use the destination address as the left-hand side, +// that is, dst *= rhs is dst.Mul(dst, rhs). +// +// WARNING +// +// The interface to this package is not stable. It will change considerably. +// Only use functions that provide package documentation. Semantics are +// non-obvious. Be prepared for the package name to change. +package f32 // import "golang.org/x/mobile/exp/f32" + +import ( + "encoding/binary" + "fmt" + "math" +) + +type Radian float32 + +func Cos(x float32) float32 { + const n = sinTableLen + i := uint32(int32(x * (n / math.Pi))) + i += n / 2 + i &= 2*n - 1 + if i >= n { + return -sinTable[i&(n-1)] + } + return sinTable[i&(n-1)] +} + +func Sin(x float32) float32 { + const n = sinTableLen + i := uint32(int32(x * (n / math.Pi))) + i &= 2*n - 1 + if i >= n { + return -sinTable[i&(n-1)] + } + return sinTable[i&(n-1)] +} + +func Sqrt(x float32) float32 { + return float32(math.Sqrt(float64(x))) // TODO(crawshaw): implement +} + +func Tan(x float32) float32 { + return float32(math.Tan(float64(x))) // TODO(crawshaw): fast version +} + +// Bytes returns the byte representation of float32 values in the given byte +// order. byteOrder must be either binary.BigEndian or binary.LittleEndian. +func Bytes(byteOrder binary.ByteOrder, values ...float32) []byte { + le := false + switch byteOrder { + case binary.BigEndian: + case binary.LittleEndian: + le = true + default: + panic(fmt.Sprintf("invalid byte order %v", byteOrder)) + } + + b := make([]byte, 4*len(values)) + for i, v := range values { + u := math.Float32bits(v) + if le { + b[4*i+0] = byte(u >> 0) + b[4*i+1] = byte(u >> 8) + b[4*i+2] = byte(u >> 16) + b[4*i+3] = byte(u >> 24) + } else { + b[4*i+0] = byte(u >> 24) + b[4*i+1] = byte(u >> 16) + b[4*i+2] = byte(u >> 8) + b[4*i+3] = byte(u >> 0) + } + } + return b +} diff --git a/vendor/golang.org/x/mobile/exp/f32/gen.go b/vendor/golang.org/x/mobile/exp/f32/gen.go new file mode 100644 index 0000000..a8438bb --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/f32/gen.go @@ -0,0 +1,48 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build ignore + +package main + +/* +This program generates table.go. Invoke it as: +go run gen.go -output table.go +*/ + +import ( + "bytes" + "flag" + "fmt" + "go/format" + "io/ioutil" + "log" + "math" +) + +// N is the number of entries in the sin look-up table. It must be a power of 2. +const N = 4096 + +var filename = flag.String("output", "table.go", "output file name") + +func main() { + b := new(bytes.Buffer) + fmt.Fprintf(b, "// Code generated by go run gen.go; DO NOT EDIT\n\npackage f32\n\n") + fmt.Fprintf(b, "const sinTableLen = %d\n\n", N) + fmt.Fprintf(b, "// sinTable[i] equals sin(i * π / sinTableLen).\n") + fmt.Fprintf(b, "var sinTable = [sinTableLen]float32{\n") + for i := 0; i < N; i++ { + radians := float64(i) * (math.Pi / N) + fmt.Fprintf(b, "%v,\n", float32(math.Sin(radians))) + } + fmt.Fprintf(b, "}\n") + + data, err := format.Source(b.Bytes()) + if err != nil { + log.Fatal(err) + } + if err := ioutil.WriteFile(*filename, data, 0644); err != nil { + log.Fatal(err) + } +} diff --git a/vendor/golang.org/x/mobile/exp/f32/mat3.go b/vendor/golang.org/x/mobile/exp/f32/mat3.go new file mode 100644 index 0000000..2577dbf --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/f32/mat3.go @@ -0,0 +1,63 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package f32 + +import "fmt" + +// A Mat3 is a 3x3 matrix of float32 values. +// Elements are indexed first by row then column, i.e. m[row][column]. +type Mat3 [3]Vec3 + +func (m Mat3) String() string { + return fmt.Sprintf(`Mat3[% 0.3f, % 0.3f, % 0.3f, + % 0.3f, % 0.3f, % 0.3f, + % 0.3f, % 0.3f, % 0.3f]`, + m[0][0], m[0][1], m[0][2], + m[1][0], m[1][1], m[1][2], + m[2][0], m[2][1], m[2][2]) +} + +func (m *Mat3) Identity() { + *m = Mat3{ + {1, 0, 0}, + {0, 1, 0}, + {0, 0, 1}, + } +} + +func (m *Mat3) Eq(n *Mat3, epsilon float32) bool { + for i := range m { + for j := range m[i] { + diff := m[i][j] - n[i][j] + if diff < -epsilon || +epsilon < diff { + return false + } + } + } + return true +} + +// Mul stores a × b in m. +func (m *Mat3) Mul(a, b *Mat3) { + // Store the result in local variables, in case m == a || m == b. + m00 := a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0] + m01 := a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1] + m02 := a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2] + m10 := a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0] + m11 := a[1][0]*b[0][1] + a[1][1]*b[1][1] + a[1][2]*b[2][1] + m12 := a[1][0]*b[0][2] + a[1][1]*b[1][2] + a[1][2]*b[2][2] + m20 := a[2][0]*b[0][0] + a[2][1]*b[1][0] + a[2][2]*b[2][0] + m21 := a[2][0]*b[0][1] + a[2][1]*b[1][1] + a[2][2]*b[2][1] + m22 := a[2][0]*b[0][2] + a[2][1]*b[1][2] + a[2][2]*b[2][2] + m[0][0] = m00 + m[0][1] = m01 + m[0][2] = m02 + m[1][0] = m10 + m[1][1] = m11 + m[1][2] = m12 + m[2][0] = m20 + m[2][1] = m21 + m[2][2] = m22 +} diff --git a/vendor/golang.org/x/mobile/exp/f32/mat4.go b/vendor/golang.org/x/mobile/exp/f32/mat4.go new file mode 100644 index 0000000..75d3a59 --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/f32/mat4.go @@ -0,0 +1,193 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package f32 + +import "fmt" + +// A Mat4 is a 4x4 matrix of float32 values. +// Elements are indexed first by row then column, i.e. m[row][column]. +type Mat4 [4]Vec4 + +func (m Mat4) String() string { + return fmt.Sprintf(`Mat4[% 0.3f, % 0.3f, % 0.3f, % 0.3f, + % 0.3f, % 0.3f, % 0.3f, % 0.3f, + % 0.3f, % 0.3f, % 0.3f, % 0.3f, + % 0.3f, % 0.3f, % 0.3f, % 0.3f]`, + m[0][0], m[0][1], m[0][2], m[0][3], + m[1][0], m[1][1], m[1][2], m[1][3], + m[2][0], m[2][1], m[2][2], m[2][3], + m[3][0], m[3][1], m[3][2], m[3][3]) +} + +func (m *Mat4) Identity() { + *m = Mat4{ + {1, 0, 0, 0}, + {0, 1, 0, 0}, + {0, 0, 1, 0}, + {0, 0, 0, 1}, + } +} + +func (m *Mat4) Eq(n *Mat4, epsilon float32) bool { + for i := range m { + for j := range m[i] { + diff := m[i][j] - n[i][j] + if diff < -epsilon || +epsilon < diff { + return false + } + } + } + return true +} + +// Mul stores a × b in m. +func (m *Mat4) Mul(a, b *Mat4) { + // Store the result in local variables, in case m == a || m == b. + m00 := a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0] + a[0][3]*b[3][0] + m01 := a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1] + a[0][3]*b[3][1] + m02 := a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2] + a[0][3]*b[3][2] + m03 := a[0][0]*b[0][3] + a[0][1]*b[1][3] + a[0][2]*b[2][3] + a[0][3]*b[3][3] + m10 := a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0] + a[1][3]*b[3][0] + m11 := a[1][0]*b[0][1] + a[1][1]*b[1][1] + a[1][2]*b[2][1] + a[1][3]*b[3][1] + m12 := a[1][0]*b[0][2] + a[1][1]*b[1][2] + a[1][2]*b[2][2] + a[1][3]*b[3][2] + m13 := a[1][0]*b[0][3] + a[1][1]*b[1][3] + a[1][2]*b[2][3] + a[1][3]*b[3][3] + m20 := a[2][0]*b[0][0] + a[2][1]*b[1][0] + a[2][2]*b[2][0] + a[2][3]*b[3][0] + m21 := a[2][0]*b[0][1] + a[2][1]*b[1][1] + a[2][2]*b[2][1] + a[2][3]*b[3][1] + m22 := a[2][0]*b[0][2] + a[2][1]*b[1][2] + a[2][2]*b[2][2] + a[2][3]*b[3][2] + m23 := a[2][0]*b[0][3] + a[2][1]*b[1][3] + a[2][2]*b[2][3] + a[2][3]*b[3][3] + m30 := a[3][0]*b[0][0] + a[3][1]*b[1][0] + a[3][2]*b[2][0] + a[3][3]*b[3][0] + m31 := a[3][0]*b[0][1] + a[3][1]*b[1][1] + a[3][2]*b[2][1] + a[3][3]*b[3][1] + m32 := a[3][0]*b[0][2] + a[3][1]*b[1][2] + a[3][2]*b[2][2] + a[3][3]*b[3][2] + m33 := a[3][0]*b[0][3] + a[3][1]*b[1][3] + a[3][2]*b[2][3] + a[3][3]*b[3][3] + m[0][0] = m00 + m[0][1] = m01 + m[0][2] = m02 + m[0][3] = m03 + m[1][0] = m10 + m[1][1] = m11 + m[1][2] = m12 + m[1][3] = m13 + m[2][0] = m20 + m[2][1] = m21 + m[2][2] = m22 + m[2][3] = m23 + m[3][0] = m30 + m[3][1] = m31 + m[3][2] = m32 + m[3][3] = m33 +} + +// Perspective sets m to be the GL perspective matrix. +func (m *Mat4) Perspective(fov Radian, aspect, near, far float32) { + t := Tan(float32(fov) / 2) + + m[0][0] = 1 / (aspect * t) + m[1][1] = 1 / t + m[2][2] = -(far + near) / (far - near) + m[2][3] = -1 + m[3][2] = -2 * far * near / (far - near) +} + +// Scale sets m to be a scale followed by p. +// It is equivalent to +// m.Mul(p, &Mat4{ +// {x, 0, 0, 0}, +// {0, y, 0, 0}, +// {0, 0, z, 0}, +// {0, 0, 0, 1}, +// }). +func (m *Mat4) Scale(p *Mat4, x, y, z float32) { + m[0][0] = p[0][0] * x + m[0][1] = p[0][1] * y + m[0][2] = p[0][2] * z + m[0][3] = p[0][3] + m[1][0] = p[1][0] * x + m[1][1] = p[1][1] * y + m[1][2] = p[1][2] * z + m[1][3] = p[1][3] + m[2][0] = p[2][0] * x + m[2][1] = p[2][1] * y + m[2][2] = p[2][2] * z + m[2][3] = p[2][3] + m[3][0] = p[3][0] * x + m[3][1] = p[3][1] * y + m[3][2] = p[3][2] * z + m[3][3] = p[3][3] +} + +// Translate sets m to be a translation followed by p. +// It is equivalent to +// m.Mul(p, &Mat4{ +// {1, 0, 0, x}, +// {0, 1, 0, y}, +// {0, 0, 1, z}, +// {0, 0, 0, 1}, +// }). +func (m *Mat4) Translate(p *Mat4, x, y, z float32) { + m[0][0] = p[0][0] + m[0][1] = p[0][1] + m[0][2] = p[0][2] + m[0][3] = p[0][0]*x + p[0][1]*y + p[0][2]*z + p[0][3] + m[1][0] = p[1][0] + m[1][1] = p[1][1] + m[1][2] = p[1][2] + m[1][3] = p[1][0]*x + p[1][1]*y + p[1][2]*z + p[1][3] + m[2][0] = p[2][0] + m[2][1] = p[2][1] + m[2][2] = p[2][2] + m[2][3] = p[2][0]*x + p[2][1]*y + p[2][2]*z + p[2][3] + m[3][0] = p[3][0] + m[3][1] = p[3][1] + m[3][2] = p[3][2] + m[3][3] = p[3][0]*x + p[3][1]*y + p[3][2]*z + p[3][3] +} + +// Rotate sets m to a rotation in radians around a specified axis, followed by p. +// It is equivalent to m.Mul(p, affineRotation). +func (m *Mat4) Rotate(p *Mat4, angle Radian, axis *Vec3) { + a := *axis + a.Normalize() + + c, s := Cos(float32(angle)), Sin(float32(angle)) + d := 1 - c + + m.Mul(p, &Mat4{{ + c + d*a[0]*a[1], + 0 + d*a[0]*a[1] + s*a[2], + 0 + d*a[0]*a[1] - s*a[1], + 0, + }, { + 0 + d*a[1]*a[0] - s*a[2], + c + d*a[1]*a[1], + 0 + d*a[1]*a[2] + s*a[0], + 0, + }, { + 0 + d*a[2]*a[0] + s*a[1], + 0 + d*a[2]*a[1] - s*a[0], + c + d*a[2]*a[2], + 0, + }, { + 0, 0, 0, 1, + }}) +} + +func (m *Mat4) LookAt(eye, center, up *Vec3) { + f, s, u := new(Vec3), new(Vec3), new(Vec3) + + *f = *center + f.Sub(f, eye) + f.Normalize() + + s.Cross(f, up) + s.Normalize() + u.Cross(s, f) + + *m = Mat4{ + {s[0], u[0], -f[0], 0}, + {s[1], u[1], -f[1], 0}, + {s[2], u[2], -f[2], 0}, + {-s.Dot(eye), -u.Dot(eye), +f.Dot(eye), 1}, + } +} diff --git a/vendor/golang.org/x/mobile/exp/f32/table.go b/vendor/golang.org/x/mobile/exp/f32/table.go new file mode 100644 index 0000000..eeff419 --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/f32/table.go @@ -0,0 +1,4105 @@ +// Code generated by go run gen.go; DO NOT EDIT + +package f32 + +const sinTableLen = 4096 + +// sinTable[i] equals sin(i * π / sinTableLen). +var sinTable = [sinTableLen]float32{ + 0, + 0.0007669903, + 0.0015339801, + 0.002300969, + 0.0030679568, + 0.0038349426, + 0.004601926, + 0.005368907, + 0.0061358847, + 0.0069028586, + 0.007669829, + 0.008436794, + 0.009203754, + 0.00997071, + 0.010737659, + 0.011504602, + 0.012271538, + 0.013038468, + 0.0138053885, + 0.014572302, + 0.015339206, + 0.016106103, + 0.016872987, + 0.017639864, + 0.01840673, + 0.019173585, + 0.019940428, + 0.02070726, + 0.02147408, + 0.022240888, + 0.023007682, + 0.023774462, + 0.024541229, + 0.025307981, + 0.026074719, + 0.02684144, + 0.027608145, + 0.028374836, + 0.029141508, + 0.029908165, + 0.030674804, + 0.031441424, + 0.032208025, + 0.03297461, + 0.033741172, + 0.034507714, + 0.035274237, + 0.036040742, + 0.036807224, + 0.037573684, + 0.03834012, + 0.039106537, + 0.039872926, + 0.040639296, + 0.04140564, + 0.042171963, + 0.04293826, + 0.04370453, + 0.044470772, + 0.04523699, + 0.04600318, + 0.046769347, + 0.047535483, + 0.048301592, + 0.049067676, + 0.049833726, + 0.05059975, + 0.05136574, + 0.052131705, + 0.052897636, + 0.053663537, + 0.05442941, + 0.055195246, + 0.05596105, + 0.05672682, + 0.057492558, + 0.058258265, + 0.059023935, + 0.059789572, + 0.06055517, + 0.061320737, + 0.062086266, + 0.06285176, + 0.063617215, + 0.06438263, + 0.06514801, + 0.06591335, + 0.06667866, + 0.06744392, + 0.06820914, + 0.06897433, + 0.06973947, + 0.070504576, + 0.07126963, + 0.07203465, + 0.07279963, + 0.07356457, + 0.07432945, + 0.0750943, + 0.07585911, + 0.076623864, + 0.07738858, + 0.078153245, + 0.07891786, + 0.07968244, + 0.080446966, + 0.08121145, + 0.08197588, + 0.08274026, + 0.0835046, + 0.08426889, + 0.085033126, + 0.08579731, + 0.08656145, + 0.087325536, + 0.08808957, + 0.08885355, + 0.08961748, + 0.09038136, + 0.09114519, + 0.091908954, + 0.092672676, + 0.09343634, + 0.09419994, + 0.0949635, + 0.09572699, + 0.09649043, + 0.097253814, + 0.09801714, + 0.09878041, + 0.099543616, + 0.10030677, + 0.10106986, + 0.1018329, + 0.102595866, + 0.10335878, + 0.10412163, + 0.10488442, + 0.105647154, + 0.10640982, + 0.10717242, + 0.10793497, + 0.108697444, + 0.109459855, + 0.110222206, + 0.11098449, + 0.11174671, + 0.11250886, + 0.11327095, + 0.11403298, + 0.114794925, + 0.115556814, + 0.11631863, + 0.11708038, + 0.11784206, + 0.11860368, + 0.119365215, + 0.12012669, + 0.120888084, + 0.121649414, + 0.12241068, + 0.12317186, + 0.12393297, + 0.12469402, + 0.12545498, + 0.12621588, + 0.1269767, + 0.12773745, + 0.1284981, + 0.1292587, + 0.13001922, + 0.13077967, + 0.13154003, + 0.13230032, + 0.13306053, + 0.13382065, + 0.1345807, + 0.13534068, + 0.13610058, + 0.13686039, + 0.13762012, + 0.13837977, + 0.13913934, + 0.13989884, + 0.14065824, + 0.14141756, + 0.1421768, + 0.14293596, + 0.14369503, + 0.14445402, + 0.14521292, + 0.14597175, + 0.14673047, + 0.14748912, + 0.14824767, + 0.14900614, + 0.14976454, + 0.15052283, + 0.15128104, + 0.15203916, + 0.15279719, + 0.15355512, + 0.15431297, + 0.15507074, + 0.1558284, + 0.15658598, + 0.15734346, + 0.15810084, + 0.15885815, + 0.15961535, + 0.16037245, + 0.16112947, + 0.1618864, + 0.16264322, + 0.16339995, + 0.16415659, + 0.16491312, + 0.16566956, + 0.1664259, + 0.16718215, + 0.16793829, + 0.16869435, + 0.1694503, + 0.17020614, + 0.17096189, + 0.17171754, + 0.17247309, + 0.17322853, + 0.17398387, + 0.17473911, + 0.17549425, + 0.1762493, + 0.17700422, + 0.17775905, + 0.17851377, + 0.17926839, + 0.1800229, + 0.18077731, + 0.18153161, + 0.1822858, + 0.18303989, + 0.18379387, + 0.18454774, + 0.1853015, + 0.18605515, + 0.18680869, + 0.18756212, + 0.18831545, + 0.18906866, + 0.18982176, + 0.19057475, + 0.19132763, + 0.1920804, + 0.19283305, + 0.19358559, + 0.19433801, + 0.19509032, + 0.19584252, + 0.1965946, + 0.19734657, + 0.1980984, + 0.19885014, + 0.19960175, + 0.20035325, + 0.20110464, + 0.2018559, + 0.20260704, + 0.20335807, + 0.20410897, + 0.20485975, + 0.20561041, + 0.20636095, + 0.20711137, + 0.20786168, + 0.20861185, + 0.20936191, + 0.21011184, + 0.21086164, + 0.21161133, + 0.21236089, + 0.21311031, + 0.21385963, + 0.21460882, + 0.21535787, + 0.2161068, + 0.2168556, + 0.21760428, + 0.21835282, + 0.21910124, + 0.21984953, + 0.22059768, + 0.22134572, + 0.22209363, + 0.2228414, + 0.22358903, + 0.22433653, + 0.22508392, + 0.22583115, + 0.22657827, + 0.22732525, + 0.22807208, + 0.22881879, + 0.22956537, + 0.23031181, + 0.2310581, + 0.23180428, + 0.23255031, + 0.2332962, + 0.23404196, + 0.23478758, + 0.23553306, + 0.2362784, + 0.2370236, + 0.23776866, + 0.23851359, + 0.23925838, + 0.24000302, + 0.24074753, + 0.24149188, + 0.24223611, + 0.24298018, + 0.24372411, + 0.2444679, + 0.24521154, + 0.24595505, + 0.24669841, + 0.24744162, + 0.24818468, + 0.24892761, + 0.24967039, + 0.250413, + 0.2511555, + 0.2518978, + 0.25264, + 0.25338203, + 0.25412393, + 0.25486565, + 0.25560725, + 0.25634867, + 0.25708997, + 0.2578311, + 0.25857207, + 0.25931293, + 0.2600536, + 0.2607941, + 0.26153448, + 0.2622747, + 0.26301476, + 0.26375467, + 0.26449442, + 0.26523402, + 0.26597348, + 0.26671275, + 0.26745188, + 0.26819086, + 0.26892966, + 0.2696683, + 0.2704068, + 0.27114516, + 0.27188334, + 0.27262136, + 0.2733592, + 0.2740969, + 0.27483445, + 0.27557182, + 0.27630904, + 0.27704608, + 0.27778298, + 0.2785197, + 0.27925625, + 0.27999264, + 0.28072888, + 0.28146493, + 0.28220084, + 0.28293657, + 0.28367212, + 0.28440753, + 0.28514278, + 0.28587782, + 0.28661272, + 0.28734747, + 0.28808203, + 0.28881642, + 0.28955063, + 0.29028466, + 0.29101855, + 0.29175225, + 0.2924858, + 0.29321915, + 0.29395235, + 0.29468536, + 0.2954182, + 0.2961509, + 0.29688337, + 0.2976157, + 0.29834786, + 0.29907984, + 0.29981163, + 0.30054325, + 0.3012747, + 0.30200595, + 0.30273703, + 0.30346796, + 0.30419868, + 0.30492923, + 0.3056596, + 0.3063898, + 0.30711982, + 0.30784965, + 0.3085793, + 0.30930877, + 0.31003806, + 0.31076714, + 0.31149608, + 0.3122248, + 0.31295338, + 0.31368175, + 0.31440994, + 0.31513792, + 0.31586576, + 0.31659338, + 0.31732082, + 0.3180481, + 0.31877515, + 0.31950203, + 0.32022873, + 0.32095525, + 0.32168156, + 0.3224077, + 0.32313362, + 0.32385936, + 0.32458493, + 0.3253103, + 0.32603547, + 0.32676044, + 0.32748523, + 0.32820985, + 0.32893425, + 0.32965845, + 0.3303825, + 0.3311063, + 0.33182994, + 0.33255336, + 0.3332766, + 0.33399966, + 0.3347225, + 0.33544514, + 0.3361676, + 0.33688986, + 0.3376119, + 0.33833376, + 0.33905542, + 0.33977687, + 0.34049815, + 0.34121922, + 0.34194008, + 0.34266073, + 0.34338117, + 0.34410143, + 0.34482148, + 0.34554133, + 0.34626096, + 0.34698042, + 0.34769964, + 0.34841868, + 0.3491375, + 0.34985614, + 0.35057455, + 0.35129276, + 0.35201076, + 0.35272855, + 0.35344616, + 0.35416353, + 0.3548807, + 0.35559767, + 0.35631442, + 0.35703096, + 0.3577473, + 0.3584634, + 0.35917935, + 0.35989505, + 0.3606105, + 0.3613258, + 0.36204088, + 0.36275572, + 0.36347038, + 0.3641848, + 0.364899, + 0.36561298, + 0.36632678, + 0.36704034, + 0.36775368, + 0.36846682, + 0.36917976, + 0.36989245, + 0.37060493, + 0.3713172, + 0.37202924, + 0.37274107, + 0.37345266, + 0.37416407, + 0.37487522, + 0.37558618, + 0.3762969, + 0.37700742, + 0.3777177, + 0.37842774, + 0.3791376, + 0.3798472, + 0.3805566, + 0.38126576, + 0.38197473, + 0.38268343, + 0.38339192, + 0.3841002, + 0.38480824, + 0.38551605, + 0.38622364, + 0.386931, + 0.38763815, + 0.38834503, + 0.38905174, + 0.38975817, + 0.3904644, + 0.39117038, + 0.39187613, + 0.39258167, + 0.39328697, + 0.39399204, + 0.39469686, + 0.39540148, + 0.39610586, + 0.39681, + 0.3975139, + 0.39821756, + 0.398921, + 0.3996242, + 0.40032718, + 0.40102988, + 0.4017324, + 0.40243465, + 0.40313667, + 0.40383846, + 0.40454, + 0.4052413, + 0.40594238, + 0.4066432, + 0.4073438, + 0.40804416, + 0.40874428, + 0.40944415, + 0.4101438, + 0.41084316, + 0.41154233, + 0.41224122, + 0.41293988, + 0.41363832, + 0.4143365, + 0.4150344, + 0.41573212, + 0.41642955, + 0.41712677, + 0.4178237, + 0.41852042, + 0.4192169, + 0.4199131, + 0.4206091, + 0.4213048, + 0.42200026, + 0.4226955, + 0.42339048, + 0.4240852, + 0.42477968, + 0.4254739, + 0.42616788, + 0.4268616, + 0.42755508, + 0.42824832, + 0.42894128, + 0.429634, + 0.4303265, + 0.4310187, + 0.43171066, + 0.43240237, + 0.43309382, + 0.43378502, + 0.43447596, + 0.43516666, + 0.4358571, + 0.43654725, + 0.43723717, + 0.43792683, + 0.43861625, + 0.4393054, + 0.43999428, + 0.4406829, + 0.44137126, + 0.44205937, + 0.44274724, + 0.4434348, + 0.44412214, + 0.4448092, + 0.44549602, + 0.44618255, + 0.44686884, + 0.44755486, + 0.4482406, + 0.4489261, + 0.44961134, + 0.45029628, + 0.450981, + 0.45166543, + 0.45234957, + 0.45303348, + 0.4537171, + 0.45440048, + 0.45508358, + 0.4557664, + 0.45644897, + 0.45713127, + 0.4578133, + 0.45849505, + 0.45917654, + 0.45985776, + 0.46053872, + 0.4612194, + 0.4618998, + 0.46257994, + 0.4632598, + 0.46393937, + 0.46461868, + 0.46529773, + 0.4659765, + 0.466655, + 0.4673332, + 0.46801114, + 0.46868882, + 0.46936622, + 0.47004333, + 0.47072017, + 0.47139674, + 0.47207302, + 0.47274902, + 0.47342476, + 0.4741002, + 0.47477537, + 0.47545028, + 0.47612488, + 0.47679922, + 0.4774733, + 0.47814706, + 0.47882056, + 0.47949377, + 0.48016667, + 0.48083934, + 0.48151168, + 0.48218378, + 0.48285556, + 0.48352706, + 0.4841983, + 0.48486924, + 0.4855399, + 0.4862103, + 0.48688036, + 0.48755017, + 0.48821968, + 0.4888889, + 0.48955783, + 0.49022648, + 0.49089485, + 0.4915629, + 0.4922307, + 0.4928982, + 0.4935654, + 0.4942323, + 0.49489895, + 0.49556527, + 0.4962313, + 0.49689704, + 0.4975625, + 0.49822766, + 0.49889255, + 0.4995571, + 0.5002214, + 0.50088537, + 0.50154907, + 0.50221246, + 0.50287557, + 0.50353837, + 0.5042009, + 0.5048631, + 0.50552505, + 0.50618666, + 0.506848, + 0.507509, + 0.5081697, + 0.50883013, + 0.50949025, + 0.5101501, + 0.5108096, + 0.5114688, + 0.51212776, + 0.5127864, + 0.5134447, + 0.51410276, + 0.51476043, + 0.5154179, + 0.516075, + 0.5167318, + 0.5173883, + 0.51804453, + 0.5187004, + 0.519356, + 0.52001125, + 0.52066624, + 0.52132094, + 0.5219753, + 0.5226294, + 0.5232831, + 0.52393657, + 0.52458966, + 0.5252425, + 0.525895, + 0.52654725, + 0.52719915, + 0.52785075, + 0.528502, + 0.529153, + 0.52980363, + 0.530454, + 0.531104, + 0.5317537, + 0.5324031, + 0.5330522, + 0.533701, + 0.53434944, + 0.53499764, + 0.5356455, + 0.53629297, + 0.53694016, + 0.53758705, + 0.53823364, + 0.53887993, + 0.53952587, + 0.54017144, + 0.5408168, + 0.54146177, + 0.54210645, + 0.5427508, + 0.5433948, + 0.54403853, + 0.5446819, + 0.545325, + 0.54596776, + 0.5466102, + 0.5472523, + 0.54789406, + 0.5485355, + 0.54917663, + 0.5498175, + 0.55045795, + 0.55109817, + 0.55173796, + 0.5523775, + 0.5530167, + 0.55365556, + 0.5542941, + 0.55493236, + 0.55557024, + 0.5562078, + 0.556845, + 0.55748194, + 0.5581185, + 0.5587548, + 0.5593907, + 0.5600263, + 0.56066155, + 0.5612965, + 0.56193113, + 0.5625654, + 0.56319934, + 0.56383294, + 0.56446624, + 0.5650992, + 0.5657318, + 0.5663641, + 0.56699604, + 0.56762767, + 0.56825894, + 0.5688899, + 0.56952053, + 0.5701508, + 0.57078075, + 0.57141036, + 0.5720396, + 0.57266855, + 0.57329714, + 0.57392544, + 0.5745534, + 0.57518095, + 0.57580817, + 0.5764351, + 0.57706165, + 0.5776879, + 0.57831377, + 0.5789393, + 0.5795646, + 0.5801894, + 0.58081394, + 0.5814381, + 0.582062, + 0.5826855, + 0.58330864, + 0.58393145, + 0.58455396, + 0.58517605, + 0.58579785, + 0.5864193, + 0.58704036, + 0.58766115, + 0.5882816, + 0.5889016, + 0.5895213, + 0.5901407, + 0.5907597, + 0.5913784, + 0.59199667, + 0.59261465, + 0.5932323, + 0.5938496, + 0.5944665, + 0.59508306, + 0.5956993, + 0.5963152, + 0.5969307, + 0.59754586, + 0.5981607, + 0.5987752, + 0.5993893, + 0.60000306, + 0.60061646, + 0.60122955, + 0.6018422, + 0.6024546, + 0.6030666, + 0.6036782, + 0.60428953, + 0.6049005, + 0.60551107, + 0.60612124, + 0.6067311, + 0.60734063, + 0.6079498, + 0.6085586, + 0.60916704, + 0.60977507, + 0.6103828, + 0.61099017, + 0.6115972, + 0.6122038, + 0.6128101, + 0.613416, + 0.61402154, + 0.61462677, + 0.6152316, + 0.6158361, + 0.6164402, + 0.6170439, + 0.6176473, + 0.6182503, + 0.618853, + 0.6194553, + 0.6200572, + 0.62065876, + 0.62126, + 0.6218608, + 0.62246126, + 0.62306136, + 0.6236611, + 0.6242605, + 0.6248595, + 0.6254581, + 0.6260564, + 0.62665427, + 0.6272518, + 0.627849, + 0.62844574, + 0.6290422, + 0.62963825, + 0.63023394, + 0.6308292, + 0.6314242, + 0.63201874, + 0.63261294, + 0.6332068, + 0.6338002, + 0.6343933, + 0.634986, + 0.63557833, + 0.63617027, + 0.63676184, + 0.63735306, + 0.6379439, + 0.63853437, + 0.63912445, + 0.6397142, + 0.6403035, + 0.64089245, + 0.64148104, + 0.6420692, + 0.64265704, + 0.6432445, + 0.64383155, + 0.64441824, + 0.6450045, + 0.6455905, + 0.64617604, + 0.6467612, + 0.64734596, + 0.6479304, + 0.6485144, + 0.64909804, + 0.6496813, + 0.6502642, + 0.65084666, + 0.6514288, + 0.65201056, + 0.6525919, + 0.65317285, + 0.6537534, + 0.6543336, + 0.6549134, + 0.65549284, + 0.6560719, + 0.65665054, + 0.6572288, + 0.6578067, + 0.6583842, + 0.6589613, + 0.65953803, + 0.66011435, + 0.6606903, + 0.66126585, + 0.661841, + 0.6624158, + 0.66299015, + 0.66356415, + 0.6641378, + 0.664711, + 0.6652838, + 0.66585624, + 0.66642827, + 0.66699994, + 0.6675712, + 0.668142, + 0.6687125, + 0.6692826, + 0.66985226, + 0.67042154, + 0.67099047, + 0.671559, + 0.67212707, + 0.67269474, + 0.67326206, + 0.673829, + 0.6743955, + 0.6749616, + 0.6755274, + 0.6760927, + 0.6766576, + 0.6772222, + 0.6777863, + 0.67835003, + 0.67891335, + 0.6794763, + 0.68003887, + 0.680601, + 0.6811627, + 0.6817241, + 0.682285, + 0.68284553, + 0.6834057, + 0.6839654, + 0.6845247, + 0.6850837, + 0.6856422, + 0.6862003, + 0.68675804, + 0.68731534, + 0.68787223, + 0.68842876, + 0.6889849, + 0.68954057, + 0.69009584, + 0.6906507, + 0.6912052, + 0.6917592, + 0.6923129, + 0.69286615, + 0.69341904, + 0.69397146, + 0.6945235, + 0.6950751, + 0.6956263, + 0.6961771, + 0.6967275, + 0.6972775, + 0.6978271, + 0.69837624, + 0.698925, + 0.6994733, + 0.70002127, + 0.7005688, + 0.7011159, + 0.7016626, + 0.7022089, + 0.70275474, + 0.7033002, + 0.70384526, + 0.70438987, + 0.70493406, + 0.7054779, + 0.70602125, + 0.70656425, + 0.70710677, + 0.70764893, + 0.7081906, + 0.70873195, + 0.7092728, + 0.7098133, + 0.7103534, + 0.710893, + 0.7114322, + 0.711971, + 0.7125094, + 0.7130473, + 0.71358484, + 0.714122, + 0.7146587, + 0.71519494, + 0.71573085, + 0.7162663, + 0.7168013, + 0.7173359, + 0.71787006, + 0.7184038, + 0.7189371, + 0.71947, + 0.72000253, + 0.72053456, + 0.7210662, + 0.72159743, + 0.7221282, + 0.7226586, + 0.72318846, + 0.723718, + 0.7242471, + 0.72477573, + 0.72530395, + 0.7258318, + 0.7263591, + 0.7268861, + 0.72741264, + 0.7279387, + 0.72846437, + 0.7289896, + 0.7295144, + 0.7300388, + 0.73056275, + 0.7310863, + 0.7316094, + 0.732132, + 0.7326543, + 0.73317605, + 0.7336974, + 0.73421836, + 0.7347389, + 0.73525894, + 0.73577857, + 0.7362978, + 0.7368166, + 0.7373349, + 0.7378528, + 0.7383703, + 0.7388873, + 0.7394039, + 0.7399201, + 0.74043584, + 0.7409511, + 0.741466, + 0.74198043, + 0.7424944, + 0.74300796, + 0.7435211, + 0.74403375, + 0.744546, + 0.74505776, + 0.74556917, + 0.7460801, + 0.74659055, + 0.7471006, + 0.7476102, + 0.74811935, + 0.7486281, + 0.7491364, + 0.7496442, + 0.75015163, + 0.75065863, + 0.75116515, + 0.7516712, + 0.7521768, + 0.75268203, + 0.7531868, + 0.75369114, + 0.754195, + 0.7546984, + 0.7552014, + 0.7557039, + 0.756206, + 0.75670767, + 0.7572088, + 0.7577096, + 0.7582099, + 0.7587098, + 0.7592092, + 0.75970817, + 0.7602067, + 0.76070476, + 0.7612024, + 0.76169956, + 0.7621963, + 0.7626926, + 0.7631884, + 0.7636838, + 0.76417875, + 0.76467323, + 0.76516724, + 0.7656609, + 0.766154, + 0.7666467, + 0.7671389, + 0.7676307, + 0.768122, + 0.7686129, + 0.76910335, + 0.7695933, + 0.77008283, + 0.7705719, + 0.7710605, + 0.7715487, + 0.7720364, + 0.77252364, + 0.77301043, + 0.7734968, + 0.7739827, + 0.7744681, + 0.7749531, + 0.77543765, + 0.7759217, + 0.77640533, + 0.7768885, + 0.77737117, + 0.7778534, + 0.7783352, + 0.7788165, + 0.77929735, + 0.77977777, + 0.78025776, + 0.7807372, + 0.78121626, + 0.7816948, + 0.7821729, + 0.7826506, + 0.7831278, + 0.7836045, + 0.7840808, + 0.78455657, + 0.7850319, + 0.78550684, + 0.78598124, + 0.7864552, + 0.7869287, + 0.78740174, + 0.78787434, + 0.7883464, + 0.78881806, + 0.78928924, + 0.78976, + 0.7902302, + 0.7907, + 0.79116935, + 0.7916382, + 0.79210657, + 0.7925745, + 0.79304194, + 0.79350895, + 0.7939755, + 0.7944415, + 0.79490715, + 0.79537225, + 0.7958369, + 0.79630107, + 0.7967648, + 0.79722804, + 0.79769087, + 0.79815316, + 0.798615, + 0.7990764, + 0.79953724, + 0.7999977, + 0.80045766, + 0.80091715, + 0.80137616, + 0.8018347, + 0.8022928, + 0.8027504, + 0.8032075, + 0.8036642, + 0.80412036, + 0.8045761, + 0.80503136, + 0.8054861, + 0.8059404, + 0.8063942, + 0.8068476, + 0.80730045, + 0.80775285, + 0.8082047, + 0.80865616, + 0.8091071, + 0.8095576, + 0.81000763, + 0.81045717, + 0.81090623, + 0.8113549, + 0.811803, + 0.8122506, + 0.81269777, + 0.8131444, + 0.8135906, + 0.8140363, + 0.81448156, + 0.8149263, + 0.8153706, + 0.81581444, + 0.8162577, + 0.8167006, + 0.8171429, + 0.8175848, + 0.8180262, + 0.81846714, + 0.81890756, + 0.8193475, + 0.81978697, + 0.82022595, + 0.82066447, + 0.8211025, + 0.82154006, + 0.82197714, + 0.8224137, + 0.8228498, + 0.8232854, + 0.8237205, + 0.82415515, + 0.8245893, + 0.825023, + 0.82545614, + 0.8258889, + 0.82632107, + 0.8267528, + 0.827184, + 0.8276148, + 0.82804507, + 0.8284748, + 0.8289041, + 0.82933295, + 0.8297612, + 0.83018905, + 0.8306164, + 0.83104324, + 0.8314696, + 0.8318955, + 0.83232087, + 0.8327458, + 0.8331702, + 0.8335941, + 0.8340175, + 0.8344404, + 0.8348629, + 0.8352848, + 0.8357063, + 0.8361273, + 0.83654773, + 0.8369677, + 0.8373872, + 0.8378062, + 0.8382247, + 0.8386427, + 0.83906025, + 0.83947724, + 0.8398938, + 0.84030986, + 0.84072536, + 0.84114045, + 0.841555, + 0.841969, + 0.8423826, + 0.84279567, + 0.84320825, + 0.8436203, + 0.8440319, + 0.84444296, + 0.8448536, + 0.84526366, + 0.84567326, + 0.8460823, + 0.8464909, + 0.84689903, + 0.8473066, + 0.84771377, + 0.84812033, + 0.8485265, + 0.848932, + 0.84933716, + 0.84974176, + 0.8501459, + 0.85054946, + 0.85095257, + 0.8513552, + 0.8517573, + 0.8521589, + 0.85256, + 0.8529606, + 0.8533607, + 0.8537603, + 0.8541594, + 0.854558, + 0.8549561, + 0.85535365, + 0.85575074, + 0.85614735, + 0.8565434, + 0.85693896, + 0.857334, + 0.8577286, + 0.85812265, + 0.8585162, + 0.85890925, + 0.8593018, + 0.8596939, + 0.86008537, + 0.86047643, + 0.86086696, + 0.86125696, + 0.8616465, + 0.86203545, + 0.86242396, + 0.8628119, + 0.8631994, + 0.86358637, + 0.86397284, + 0.8643588, + 0.86474425, + 0.8651292, + 0.8655136, + 0.86589754, + 0.866281, + 0.8666639, + 0.86704624, + 0.8674281, + 0.8678095, + 0.86819035, + 0.8685707, + 0.86895055, + 0.86932987, + 0.86970866, + 0.87008697, + 0.8704648, + 0.87084204, + 0.87121886, + 0.8715951, + 0.87197083, + 0.87234604, + 0.8727208, + 0.873095, + 0.8734687, + 0.8738418, + 0.87421453, + 0.87458664, + 0.8749583, + 0.8753294, + 0.8757, + 0.8760701, + 0.8764397, + 0.8768087, + 0.87717724, + 0.8775453, + 0.8779128, + 0.8782798, + 0.87864625, + 0.8790122, + 0.87937766, + 0.8797426, + 0.880107, + 0.8804709, + 0.8808343, + 0.8811971, + 0.88155943, + 0.8819213, + 0.88228256, + 0.88264334, + 0.8830036, + 0.88336337, + 0.88372254, + 0.88408124, + 0.88443947, + 0.8847971, + 0.88515425, + 0.88551086, + 0.88586694, + 0.88622254, + 0.8865776, + 0.88693213, + 0.8872861, + 0.88763964, + 0.88799256, + 0.88834506, + 0.88869697, + 0.88904834, + 0.88939923, + 0.8897496, + 0.8900994, + 0.89044875, + 0.8907975, + 0.89114577, + 0.8914935, + 0.8918407, + 0.8921874, + 0.89253354, + 0.8928792, + 0.8932243, + 0.8935689, + 0.893913, + 0.8942565, + 0.8945995, + 0.894942, + 0.89528394, + 0.89562535, + 0.89596623, + 0.89630663, + 0.8966465, + 0.89698577, + 0.89732456, + 0.8976628, + 0.8980006, + 0.8983378, + 0.8986745, + 0.8990106, + 0.89934623, + 0.8996813, + 0.9000159, + 0.9003499, + 0.9006834, + 0.9010164, + 0.9013488, + 0.90168077, + 0.90201217, + 0.902343, + 0.9026733, + 0.9030031, + 0.90333235, + 0.9036611, + 0.9039893, + 0.90431696, + 0.9046441, + 0.9049707, + 0.90529674, + 0.9056223, + 0.90594727, + 0.90627176, + 0.9065957, + 0.9069191, + 0.907242, + 0.90756434, + 0.9078861, + 0.90820736, + 0.9085281, + 0.90884835, + 0.909168, + 0.9094871, + 0.9098057, + 0.91012377, + 0.9104413, + 0.91075826, + 0.91107476, + 0.91139066, + 0.91170603, + 0.91202086, + 0.91233516, + 0.912649, + 0.9129622, + 0.9132749, + 0.91358703, + 0.91389865, + 0.9142098, + 0.9145203, + 0.9148303, + 0.9151398, + 0.9154487, + 0.9157571, + 0.916065, + 0.9163723, + 0.9166791, + 0.9169853, + 0.917291, + 0.91759616, + 0.9179008, + 0.91820484, + 0.9185084, + 0.9188114, + 0.9191139, + 0.9194158, + 0.91971713, + 0.92001796, + 0.9203183, + 0.92061806, + 0.9209172, + 0.9212159, + 0.92151403, + 0.92181164, + 0.92210865, + 0.9224052, + 0.9227011, + 0.9229965, + 0.92329144, + 0.9235858, + 0.9238795, + 0.92417276, + 0.9244655, + 0.9247576, + 0.92504925, + 0.9253403, + 0.9256308, + 0.9259208, + 0.9262102, + 0.9264991, + 0.9267875, + 0.92707527, + 0.9273625, + 0.92764926, + 0.9279354, + 0.928221, + 0.9285061, + 0.9287906, + 0.9290746, + 0.929358, + 0.9296409, + 0.92992324, + 0.93020505, + 0.93048626, + 0.93076694, + 0.9310471, + 0.9313267, + 0.93160576, + 0.9318843, + 0.9321622, + 0.9324396, + 0.9327165, + 0.9329928, + 0.93326855, + 0.9335438, + 0.93381846, + 0.9340925, + 0.9343661, + 0.93463916, + 0.9349116, + 0.9351835, + 0.93545485, + 0.9357257, + 0.93599594, + 0.93626565, + 0.9365348, + 0.93680346, + 0.9370715, + 0.937339, + 0.937606, + 0.93787235, + 0.93813825, + 0.93840355, + 0.9386683, + 0.9389325, + 0.9391961, + 0.9394592, + 0.93972176, + 0.9399837, + 0.9402452, + 0.94050604, + 0.9407664, + 0.94102615, + 0.9412854, + 0.94154406, + 0.9418022, + 0.94205976, + 0.9423168, + 0.9425732, + 0.9428291, + 0.9430844, + 0.9433392, + 0.94359344, + 0.9438471, + 0.94410026, + 0.9443528, + 0.9446048, + 0.9448563, + 0.9451072, + 0.94535756, + 0.9456073, + 0.9458566, + 0.94610524, + 0.9463534, + 0.9466009, + 0.9468479, + 0.9470944, + 0.94734025, + 0.9475856, + 0.9478304, + 0.9480746, + 0.94831824, + 0.9485614, + 0.9488039, + 0.9490459, + 0.9492873, + 0.94952816, + 0.9497685, + 0.9500083, + 0.95024747, + 0.95048606, + 0.9507241, + 0.95096165, + 0.95119864, + 0.951435, + 0.9516709, + 0.95190614, + 0.95214087, + 0.952375, + 0.9526086, + 0.95284164, + 0.9530741, + 0.953306, + 0.9535374, + 0.9537682, + 0.95399845, + 0.9542281, + 0.9544572, + 0.95468575, + 0.95491374, + 0.9551412, + 0.95536804, + 0.95559436, + 0.9558201, + 0.95604527, + 0.95626986, + 0.9564939, + 0.95671743, + 0.95694035, + 0.9571627, + 0.9573845, + 0.9576057, + 0.95782644, + 0.9580465, + 0.9582661, + 0.95848507, + 0.95870346, + 0.9589213, + 0.95913863, + 0.95935535, + 0.95957154, + 0.95978713, + 0.9600021, + 0.96021664, + 0.9604305, + 0.9606439, + 0.9608566, + 0.96106887, + 0.96128047, + 0.9614916, + 0.96170205, + 0.96191204, + 0.9621214, + 0.9623302, + 0.9625385, + 0.96274614, + 0.96295327, + 0.9631598, + 0.9633658, + 0.9635712, + 0.96377605, + 0.9639804, + 0.96418405, + 0.96438724, + 0.9645898, + 0.96479183, + 0.96499324, + 0.9651941, + 0.96539444, + 0.9655942, + 0.9657934, + 0.965992, + 0.96619, + 0.96638745, + 0.9665844, + 0.9667807, + 0.96697646, + 0.96717167, + 0.9673663, + 0.96756035, + 0.9677538, + 0.96794677, + 0.9681391, + 0.96833086, + 0.9685221, + 0.96871275, + 0.9689028, + 0.9690923, + 0.96928126, + 0.9694696, + 0.96965736, + 0.9698446, + 0.97003126, + 0.97021735, + 0.97040284, + 0.9705878, + 0.97077215, + 0.9709559, + 0.97113913, + 0.9713218, + 0.9715039, + 0.9716854, + 0.9718663, + 0.97204673, + 0.9722265, + 0.97240573, + 0.97258437, + 0.97276247, + 0.97293997, + 0.9731169, + 0.97329324, + 0.973469, + 0.97364426, + 0.9738189, + 0.97399294, + 0.97416645, + 0.97433937, + 0.97451174, + 0.9746835, + 0.9748547, + 0.97502536, + 0.9751954, + 0.97536486, + 0.9755338, + 0.9757021, + 0.9758699, + 0.9760371, + 0.9762037, + 0.97636974, + 0.9765352, + 0.97670007, + 0.9768644, + 0.97702813, + 0.9771913, + 0.9773539, + 0.97751594, + 0.97767735, + 0.9778382, + 0.9779985, + 0.97815824, + 0.9783174, + 0.9784759, + 0.97863394, + 0.97879136, + 0.9789482, + 0.97910446, + 0.97926015, + 0.97941524, + 0.9795698, + 0.97972375, + 0.9798771, + 0.9800299, + 0.9801821, + 0.9803338, + 0.98048484, + 0.98063534, + 0.98078525, + 0.9809346, + 0.9810834, + 0.9812316, + 0.9813792, + 0.98152626, + 0.9816727, + 0.98181856, + 0.9819639, + 0.9821086, + 0.9822527, + 0.9823963, + 0.9825393, + 0.9826817, + 0.98282355, + 0.9829648, + 0.9831055, + 0.9832456, + 0.9833851, + 0.983524, + 0.9836624, + 0.98380023, + 0.98393744, + 0.98407406, + 0.9842101, + 0.98434556, + 0.98448044, + 0.9846148, + 0.9847485, + 0.98488164, + 0.98501426, + 0.9851462, + 0.98527765, + 0.9854085, + 0.9855387, + 0.9856684, + 0.9857975, + 0.98592603, + 0.98605394, + 0.9861813, + 0.9863081, + 0.9864343, + 0.9865599, + 0.9866849, + 0.9868094, + 0.9869333, + 0.98705655, + 0.9871793, + 0.9873014, + 0.98742294, + 0.98754394, + 0.98766434, + 0.98778415, + 0.98790336, + 0.988022, + 0.9881401, + 0.9882576, + 0.9883745, + 0.9884908, + 0.9886065, + 0.98872167, + 0.9888363, + 0.98895025, + 0.9890637, + 0.9891765, + 0.98928875, + 0.98940045, + 0.9895115, + 0.989622, + 0.98973197, + 0.9898413, + 0.98995006, + 0.9900582, + 0.9901658, + 0.9902728, + 0.9903792, + 0.9904851, + 0.99059033, + 0.990695, + 0.9907991, + 0.99090266, + 0.99100554, + 0.99110794, + 0.9912097, + 0.99131083, + 0.99141145, + 0.99151146, + 0.9916109, + 0.99170977, + 0.991808, + 0.9919057, + 0.9920028, + 0.9920993, + 0.99219525, + 0.9922906, + 0.9923853, + 0.99247956, + 0.99257314, + 0.9926661, + 0.9927586, + 0.9928504, + 0.9929417, + 0.99303234, + 0.99312246, + 0.9932119, + 0.99330086, + 0.9933892, + 0.993477, + 0.9935641, + 0.99365073, + 0.99373674, + 0.99382216, + 0.993907, + 0.9939912, + 0.9940749, + 0.99415797, + 0.99424046, + 0.99432236, + 0.99440366, + 0.9944844, + 0.9945646, + 0.99464417, + 0.99472314, + 0.9948015, + 0.9948793, + 0.99495655, + 0.9950332, + 0.99510926, + 0.9951847, + 0.9952596, + 0.9953339, + 0.99540764, + 0.9954808, + 0.9955533, + 0.99562526, + 0.9956966, + 0.9957674, + 0.9958376, + 0.99590725, + 0.99597627, + 0.9960447, + 0.9961126, + 0.9961798, + 0.9962465, + 0.9963126, + 0.9963781, + 0.99644303, + 0.9965074, + 0.9965711, + 0.9966343, + 0.9966969, + 0.9967589, + 0.9968203, + 0.9968811, + 0.9969413, + 0.997001, + 0.99706006, + 0.99711853, + 0.9971764, + 0.99723375, + 0.99729043, + 0.9973466, + 0.99740213, + 0.9974571, + 0.99751145, + 0.9975652, + 0.99761844, + 0.99767107, + 0.99772304, + 0.9977745, + 0.9978253, + 0.99787563, + 0.9979253, + 0.9979744, + 0.99802285, + 0.9980708, + 0.9981181, + 0.99816483, + 0.998211, + 0.99825656, + 0.99830157, + 0.9983459, + 0.9983897, + 0.99843293, + 0.99847555, + 0.99851763, + 0.99855906, + 0.99859995, + 0.99864024, + 0.99867994, + 0.99871904, + 0.99875754, + 0.99879545, + 0.9988328, + 0.99886954, + 0.9989057, + 0.9989413, + 0.9989763, + 0.9990107, + 0.9990445, + 0.99907774, + 0.99911034, + 0.9991424, + 0.9991739, + 0.99920475, + 0.99923503, + 0.9992648, + 0.99929386, + 0.99932235, + 0.9993503, + 0.99937767, + 0.99940443, + 0.9994306, + 0.99945617, + 0.9994812, + 0.9995056, + 0.9995294, + 0.99955267, + 0.9995753, + 0.9995974, + 0.9996188, + 0.9996397, + 0.99966, + 0.9996797, + 0.9996988, + 0.99971735, + 0.9997353, + 0.99975264, + 0.9997694, + 0.9997856, + 0.99980116, + 0.9998162, + 0.9998306, + 0.99984443, + 0.99985766, + 0.9998703, + 0.99988234, + 0.99989384, + 0.9999047, + 0.999915, + 0.9999247, + 0.99993384, + 0.99994236, + 0.9999503, + 0.9999576, + 0.9999644, + 0.9999706, + 0.99997616, + 0.99998116, + 0.9999856, + 0.9999894, + 0.99999267, + 0.9999953, + 0.9999974, + 0.9999988, + 0.9999997, + 1, + 0.9999997, + 0.9999988, + 0.9999974, + 0.9999953, + 0.99999267, + 0.9999894, + 0.9999856, + 0.99998116, + 0.99997616, + 0.9999706, + 0.9999644, + 0.9999576, + 0.9999503, + 0.99994236, + 0.99993384, + 0.9999247, + 0.999915, + 0.9999047, + 0.99989384, + 0.99988234, + 0.9998703, + 0.99985766, + 0.99984443, + 0.9998306, + 0.9998162, + 0.99980116, + 0.9997856, + 0.9997694, + 0.99975264, + 0.9997353, + 0.99971735, + 0.9996988, + 0.9996797, + 0.99966, + 0.9996397, + 0.9996188, + 0.9995974, + 0.9995753, + 0.99955267, + 0.9995294, + 0.9995056, + 0.9994812, + 0.99945617, + 0.9994306, + 0.99940443, + 0.99937767, + 0.9993503, + 0.99932235, + 0.99929386, + 0.9992648, + 0.99923503, + 0.99920475, + 0.9991739, + 0.9991424, + 0.99911034, + 0.99907774, + 0.9990445, + 0.9990107, + 0.9989763, + 0.9989413, + 0.9989057, + 0.99886954, + 0.9988328, + 0.99879545, + 0.99875754, + 0.99871904, + 0.99867994, + 0.99864024, + 0.99859995, + 0.99855906, + 0.99851763, + 0.99847555, + 0.99843293, + 0.9983897, + 0.9983459, + 0.99830157, + 0.99825656, + 0.998211, + 0.99816483, + 0.9981181, + 0.9980708, + 0.99802285, + 0.9979744, + 0.9979253, + 0.99787563, + 0.9978253, + 0.9977745, + 0.99772304, + 0.99767107, + 0.99761844, + 0.9975652, + 0.99751145, + 0.9974571, + 0.99740213, + 0.9973466, + 0.99729043, + 0.99723375, + 0.9971764, + 0.99711853, + 0.99706006, + 0.997001, + 0.9969413, + 0.9968811, + 0.9968203, + 0.9967589, + 0.9966969, + 0.9966343, + 0.9965711, + 0.9965074, + 0.99644303, + 0.9963781, + 0.9963126, + 0.9962465, + 0.9961798, + 0.9961126, + 0.9960447, + 0.99597627, + 0.99590725, + 0.9958376, + 0.9957674, + 0.9956966, + 0.99562526, + 0.9955533, + 0.9954808, + 0.99540764, + 0.9953339, + 0.9952596, + 0.9951847, + 0.99510926, + 0.9950332, + 0.99495655, + 0.9948793, + 0.9948015, + 0.99472314, + 0.99464417, + 0.9945646, + 0.9944844, + 0.99440366, + 0.99432236, + 0.99424046, + 0.99415797, + 0.9940749, + 0.9939912, + 0.993907, + 0.99382216, + 0.99373674, + 0.99365073, + 0.9935641, + 0.993477, + 0.9933892, + 0.99330086, + 0.9932119, + 0.99312246, + 0.99303234, + 0.9929417, + 0.9928504, + 0.9927586, + 0.9926661, + 0.99257314, + 0.99247956, + 0.9923853, + 0.9922906, + 0.99219525, + 0.9920993, + 0.9920028, + 0.9919057, + 0.991808, + 0.99170977, + 0.9916109, + 0.99151146, + 0.99141145, + 0.99131083, + 0.9912097, + 0.99110794, + 0.99100554, + 0.99090266, + 0.9907991, + 0.990695, + 0.99059033, + 0.9904851, + 0.9903792, + 0.9902728, + 0.9901658, + 0.9900582, + 0.98995006, + 0.9898413, + 0.98973197, + 0.989622, + 0.9895115, + 0.98940045, + 0.98928875, + 0.9891765, + 0.9890637, + 0.98895025, + 0.9888363, + 0.98872167, + 0.9886065, + 0.9884908, + 0.9883745, + 0.9882576, + 0.9881401, + 0.988022, + 0.98790336, + 0.98778415, + 0.98766434, + 0.98754394, + 0.98742294, + 0.9873014, + 0.9871793, + 0.98705655, + 0.9869333, + 0.9868094, + 0.9866849, + 0.9865599, + 0.9864343, + 0.9863081, + 0.9861813, + 0.98605394, + 0.98592603, + 0.9857975, + 0.9856684, + 0.9855387, + 0.9854085, + 0.98527765, + 0.9851462, + 0.98501426, + 0.98488164, + 0.9847485, + 0.9846148, + 0.98448044, + 0.98434556, + 0.9842101, + 0.98407406, + 0.98393744, + 0.98380023, + 0.9836624, + 0.983524, + 0.9833851, + 0.9832456, + 0.9831055, + 0.9829648, + 0.98282355, + 0.9826817, + 0.9825393, + 0.9823963, + 0.9822527, + 0.9821086, + 0.9819639, + 0.98181856, + 0.9816727, + 0.98152626, + 0.9813792, + 0.9812316, + 0.9810834, + 0.9809346, + 0.98078525, + 0.98063534, + 0.98048484, + 0.9803338, + 0.9801821, + 0.9800299, + 0.9798771, + 0.97972375, + 0.9795698, + 0.97941524, + 0.97926015, + 0.97910446, + 0.9789482, + 0.97879136, + 0.97863394, + 0.9784759, + 0.9783174, + 0.97815824, + 0.9779985, + 0.9778382, + 0.97767735, + 0.97751594, + 0.9773539, + 0.9771913, + 0.97702813, + 0.9768644, + 0.97670007, + 0.9765352, + 0.97636974, + 0.9762037, + 0.9760371, + 0.9758699, + 0.9757021, + 0.9755338, + 0.97536486, + 0.9751954, + 0.97502536, + 0.9748547, + 0.9746835, + 0.97451174, + 0.97433937, + 0.97416645, + 0.97399294, + 0.9738189, + 0.97364426, + 0.973469, + 0.97329324, + 0.9731169, + 0.97293997, + 0.97276247, + 0.97258437, + 0.97240573, + 0.9722265, + 0.97204673, + 0.9718663, + 0.9716854, + 0.9715039, + 0.9713218, + 0.97113913, + 0.9709559, + 0.97077215, + 0.9705878, + 0.97040284, + 0.97021735, + 0.97003126, + 0.9698446, + 0.96965736, + 0.9694696, + 0.96928126, + 0.9690923, + 0.9689028, + 0.96871275, + 0.9685221, + 0.96833086, + 0.9681391, + 0.96794677, + 0.9677538, + 0.96756035, + 0.9673663, + 0.96717167, + 0.96697646, + 0.9667807, + 0.9665844, + 0.96638745, + 0.96619, + 0.965992, + 0.9657934, + 0.9655942, + 0.96539444, + 0.9651941, + 0.96499324, + 0.96479183, + 0.9645898, + 0.96438724, + 0.96418405, + 0.9639804, + 0.96377605, + 0.9635712, + 0.9633658, + 0.9631598, + 0.96295327, + 0.96274614, + 0.9625385, + 0.9623302, + 0.9621214, + 0.96191204, + 0.96170205, + 0.9614916, + 0.96128047, + 0.96106887, + 0.9608566, + 0.9606439, + 0.9604305, + 0.96021664, + 0.9600021, + 0.95978713, + 0.95957154, + 0.95935535, + 0.95913863, + 0.9589213, + 0.95870346, + 0.95848507, + 0.9582661, + 0.9580465, + 0.95782644, + 0.9576057, + 0.9573845, + 0.9571627, + 0.95694035, + 0.95671743, + 0.9564939, + 0.95626986, + 0.95604527, + 0.9558201, + 0.95559436, + 0.95536804, + 0.9551412, + 0.95491374, + 0.95468575, + 0.9544572, + 0.9542281, + 0.95399845, + 0.9537682, + 0.9535374, + 0.953306, + 0.9530741, + 0.95284164, + 0.9526086, + 0.952375, + 0.95214087, + 0.95190614, + 0.9516709, + 0.951435, + 0.95119864, + 0.95096165, + 0.9507241, + 0.95048606, + 0.95024747, + 0.9500083, + 0.9497685, + 0.94952816, + 0.9492873, + 0.9490459, + 0.9488039, + 0.9485614, + 0.94831824, + 0.9480746, + 0.9478304, + 0.9475856, + 0.94734025, + 0.9470944, + 0.9468479, + 0.9466009, + 0.9463534, + 0.94610524, + 0.9458566, + 0.9456073, + 0.94535756, + 0.9451072, + 0.9448563, + 0.9446048, + 0.9443528, + 0.94410026, + 0.9438471, + 0.94359344, + 0.9433392, + 0.9430844, + 0.9428291, + 0.9425732, + 0.9423168, + 0.94205976, + 0.9418022, + 0.94154406, + 0.9412854, + 0.94102615, + 0.9407664, + 0.94050604, + 0.9402452, + 0.9399837, + 0.93972176, + 0.9394592, + 0.9391961, + 0.9389325, + 0.9386683, + 0.93840355, + 0.93813825, + 0.93787235, + 0.937606, + 0.937339, + 0.9370715, + 0.93680346, + 0.9365348, + 0.93626565, + 0.93599594, + 0.9357257, + 0.93545485, + 0.9351835, + 0.9349116, + 0.93463916, + 0.9343661, + 0.9340925, + 0.93381846, + 0.9335438, + 0.93326855, + 0.9329928, + 0.9327165, + 0.9324396, + 0.9321622, + 0.9318843, + 0.93160576, + 0.9313267, + 0.9310471, + 0.93076694, + 0.93048626, + 0.93020505, + 0.92992324, + 0.9296409, + 0.929358, + 0.9290746, + 0.9287906, + 0.9285061, + 0.928221, + 0.9279354, + 0.92764926, + 0.9273625, + 0.92707527, + 0.9267875, + 0.9264991, + 0.9262102, + 0.9259208, + 0.9256308, + 0.9253403, + 0.92504925, + 0.9247576, + 0.9244655, + 0.92417276, + 0.9238795, + 0.9235858, + 0.92329144, + 0.9229965, + 0.9227011, + 0.9224052, + 0.92210865, + 0.92181164, + 0.92151403, + 0.9212159, + 0.9209172, + 0.92061806, + 0.9203183, + 0.92001796, + 0.91971713, + 0.9194158, + 0.9191139, + 0.9188114, + 0.9185084, + 0.91820484, + 0.9179008, + 0.91759616, + 0.917291, + 0.9169853, + 0.9166791, + 0.9163723, + 0.916065, + 0.9157571, + 0.9154487, + 0.9151398, + 0.9148303, + 0.9145203, + 0.9142098, + 0.91389865, + 0.91358703, + 0.9132749, + 0.9129622, + 0.912649, + 0.91233516, + 0.91202086, + 0.91170603, + 0.91139066, + 0.91107476, + 0.91075826, + 0.9104413, + 0.91012377, + 0.9098057, + 0.9094871, + 0.909168, + 0.90884835, + 0.9085281, + 0.90820736, + 0.9078861, + 0.90756434, + 0.907242, + 0.9069191, + 0.9065957, + 0.90627176, + 0.90594727, + 0.9056223, + 0.90529674, + 0.9049707, + 0.9046441, + 0.90431696, + 0.9039893, + 0.9036611, + 0.90333235, + 0.9030031, + 0.9026733, + 0.902343, + 0.90201217, + 0.90168077, + 0.9013488, + 0.9010164, + 0.9006834, + 0.9003499, + 0.9000159, + 0.8996813, + 0.89934623, + 0.8990106, + 0.8986745, + 0.8983378, + 0.8980006, + 0.8976628, + 0.89732456, + 0.89698577, + 0.8966465, + 0.89630663, + 0.89596623, + 0.89562535, + 0.89528394, + 0.894942, + 0.8945995, + 0.8942565, + 0.893913, + 0.8935689, + 0.8932243, + 0.8928792, + 0.89253354, + 0.8921874, + 0.8918407, + 0.8914935, + 0.89114577, + 0.8907975, + 0.89044875, + 0.8900994, + 0.8897496, + 0.88939923, + 0.88904834, + 0.88869697, + 0.88834506, + 0.88799256, + 0.88763964, + 0.8872861, + 0.88693213, + 0.8865776, + 0.88622254, + 0.88586694, + 0.88551086, + 0.88515425, + 0.8847971, + 0.88443947, + 0.88408124, + 0.88372254, + 0.88336337, + 0.8830036, + 0.88264334, + 0.88228256, + 0.8819213, + 0.88155943, + 0.8811971, + 0.8808343, + 0.8804709, + 0.880107, + 0.8797426, + 0.87937766, + 0.8790122, + 0.87864625, + 0.8782798, + 0.8779128, + 0.8775453, + 0.87717724, + 0.8768087, + 0.8764397, + 0.8760701, + 0.8757, + 0.8753294, + 0.8749583, + 0.87458664, + 0.87421453, + 0.8738418, + 0.8734687, + 0.873095, + 0.8727208, + 0.87234604, + 0.87197083, + 0.8715951, + 0.87121886, + 0.87084204, + 0.8704648, + 0.87008697, + 0.86970866, + 0.86932987, + 0.86895055, + 0.8685707, + 0.86819035, + 0.8678095, + 0.8674281, + 0.86704624, + 0.8666639, + 0.866281, + 0.86589754, + 0.8655136, + 0.8651292, + 0.86474425, + 0.8643588, + 0.86397284, + 0.86358637, + 0.8631994, + 0.8628119, + 0.86242396, + 0.86203545, + 0.8616465, + 0.86125696, + 0.86086696, + 0.86047643, + 0.86008537, + 0.8596939, + 0.8593018, + 0.85890925, + 0.8585162, + 0.85812265, + 0.8577286, + 0.857334, + 0.85693896, + 0.8565434, + 0.85614735, + 0.85575074, + 0.85535365, + 0.8549561, + 0.854558, + 0.8541594, + 0.8537603, + 0.8533607, + 0.8529606, + 0.85256, + 0.8521589, + 0.8517573, + 0.8513552, + 0.85095257, + 0.85054946, + 0.8501459, + 0.84974176, + 0.84933716, + 0.848932, + 0.8485265, + 0.84812033, + 0.84771377, + 0.8473066, + 0.84689903, + 0.8464909, + 0.8460823, + 0.84567326, + 0.84526366, + 0.8448536, + 0.84444296, + 0.8440319, + 0.8436203, + 0.84320825, + 0.84279567, + 0.8423826, + 0.841969, + 0.841555, + 0.84114045, + 0.84072536, + 0.84030986, + 0.8398938, + 0.83947724, + 0.83906025, + 0.8386427, + 0.8382247, + 0.8378062, + 0.8373872, + 0.8369677, + 0.83654773, + 0.8361273, + 0.8357063, + 0.8352848, + 0.8348629, + 0.8344404, + 0.8340175, + 0.8335941, + 0.8331702, + 0.8327458, + 0.83232087, + 0.8318955, + 0.8314696, + 0.83104324, + 0.8306164, + 0.83018905, + 0.8297612, + 0.82933295, + 0.8289041, + 0.8284748, + 0.82804507, + 0.8276148, + 0.827184, + 0.8267528, + 0.82632107, + 0.8258889, + 0.82545614, + 0.825023, + 0.8245893, + 0.82415515, + 0.8237205, + 0.8232854, + 0.8228498, + 0.8224137, + 0.82197714, + 0.82154006, + 0.8211025, + 0.82066447, + 0.82022595, + 0.81978697, + 0.8193475, + 0.81890756, + 0.81846714, + 0.8180262, + 0.8175848, + 0.8171429, + 0.8167006, + 0.8162577, + 0.81581444, + 0.8153706, + 0.8149263, + 0.81448156, + 0.8140363, + 0.8135906, + 0.8131444, + 0.81269777, + 0.8122506, + 0.811803, + 0.8113549, + 0.81090623, + 0.81045717, + 0.81000763, + 0.8095576, + 0.8091071, + 0.80865616, + 0.8082047, + 0.80775285, + 0.80730045, + 0.8068476, + 0.8063942, + 0.8059404, + 0.8054861, + 0.80503136, + 0.8045761, + 0.80412036, + 0.8036642, + 0.8032075, + 0.8027504, + 0.8022928, + 0.8018347, + 0.80137616, + 0.80091715, + 0.80045766, + 0.7999977, + 0.79953724, + 0.7990764, + 0.798615, + 0.79815316, + 0.79769087, + 0.79722804, + 0.7967648, + 0.79630107, + 0.7958369, + 0.79537225, + 0.79490715, + 0.7944415, + 0.7939755, + 0.79350895, + 0.79304194, + 0.7925745, + 0.79210657, + 0.7916382, + 0.79116935, + 0.7907, + 0.7902302, + 0.78976, + 0.78928924, + 0.78881806, + 0.7883464, + 0.78787434, + 0.78740174, + 0.7869287, + 0.7864552, + 0.78598124, + 0.78550684, + 0.7850319, + 0.78455657, + 0.7840808, + 0.7836045, + 0.7831278, + 0.7826506, + 0.7821729, + 0.7816948, + 0.78121626, + 0.7807372, + 0.78025776, + 0.77977777, + 0.77929735, + 0.7788165, + 0.7783352, + 0.7778534, + 0.77737117, + 0.7768885, + 0.77640533, + 0.7759217, + 0.77543765, + 0.7749531, + 0.7744681, + 0.7739827, + 0.7734968, + 0.77301043, + 0.77252364, + 0.7720364, + 0.7715487, + 0.7710605, + 0.7705719, + 0.77008283, + 0.7695933, + 0.76910335, + 0.7686129, + 0.768122, + 0.7676307, + 0.7671389, + 0.7666467, + 0.766154, + 0.7656609, + 0.76516724, + 0.76467323, + 0.76417875, + 0.7636838, + 0.7631884, + 0.7626926, + 0.7621963, + 0.76169956, + 0.7612024, + 0.76070476, + 0.7602067, + 0.75970817, + 0.7592092, + 0.7587098, + 0.7582099, + 0.7577096, + 0.7572088, + 0.75670767, + 0.756206, + 0.7557039, + 0.7552014, + 0.7546984, + 0.754195, + 0.75369114, + 0.7531868, + 0.75268203, + 0.7521768, + 0.7516712, + 0.75116515, + 0.75065863, + 0.75015163, + 0.7496442, + 0.7491364, + 0.7486281, + 0.74811935, + 0.7476102, + 0.7471006, + 0.74659055, + 0.7460801, + 0.74556917, + 0.74505776, + 0.744546, + 0.74403375, + 0.7435211, + 0.74300796, + 0.7424944, + 0.74198043, + 0.741466, + 0.7409511, + 0.74043584, + 0.7399201, + 0.7394039, + 0.7388873, + 0.7383703, + 0.7378528, + 0.7373349, + 0.7368166, + 0.7362978, + 0.73577857, + 0.73525894, + 0.7347389, + 0.73421836, + 0.7336974, + 0.73317605, + 0.7326543, + 0.732132, + 0.7316094, + 0.7310863, + 0.73056275, + 0.7300388, + 0.7295144, + 0.7289896, + 0.72846437, + 0.7279387, + 0.72741264, + 0.7268861, + 0.7263591, + 0.7258318, + 0.72530395, + 0.72477573, + 0.7242471, + 0.723718, + 0.72318846, + 0.7226586, + 0.7221282, + 0.72159743, + 0.7210662, + 0.72053456, + 0.72000253, + 0.71947, + 0.7189371, + 0.7184038, + 0.71787006, + 0.7173359, + 0.7168013, + 0.7162663, + 0.71573085, + 0.71519494, + 0.7146587, + 0.714122, + 0.71358484, + 0.7130473, + 0.7125094, + 0.711971, + 0.7114322, + 0.710893, + 0.7103534, + 0.7098133, + 0.7092728, + 0.70873195, + 0.7081906, + 0.70764893, + 0.70710677, + 0.70656425, + 0.70602125, + 0.7054779, + 0.70493406, + 0.70438987, + 0.70384526, + 0.7033002, + 0.70275474, + 0.7022089, + 0.7016626, + 0.7011159, + 0.7005688, + 0.70002127, + 0.6994733, + 0.698925, + 0.69837624, + 0.6978271, + 0.6972775, + 0.6967275, + 0.6961771, + 0.6956263, + 0.6950751, + 0.6945235, + 0.69397146, + 0.69341904, + 0.69286615, + 0.6923129, + 0.6917592, + 0.6912052, + 0.6906507, + 0.69009584, + 0.68954057, + 0.6889849, + 0.68842876, + 0.68787223, + 0.68731534, + 0.68675804, + 0.6862003, + 0.6856422, + 0.6850837, + 0.6845247, + 0.6839654, + 0.6834057, + 0.68284553, + 0.682285, + 0.6817241, + 0.6811627, + 0.680601, + 0.68003887, + 0.6794763, + 0.67891335, + 0.67835003, + 0.6777863, + 0.6772222, + 0.6766576, + 0.6760927, + 0.6755274, + 0.6749616, + 0.6743955, + 0.673829, + 0.67326206, + 0.67269474, + 0.67212707, + 0.671559, + 0.67099047, + 0.67042154, + 0.66985226, + 0.6692826, + 0.6687125, + 0.668142, + 0.6675712, + 0.66699994, + 0.66642827, + 0.66585624, + 0.6652838, + 0.664711, + 0.6641378, + 0.66356415, + 0.66299015, + 0.6624158, + 0.661841, + 0.66126585, + 0.6606903, + 0.66011435, + 0.65953803, + 0.6589613, + 0.6583842, + 0.6578067, + 0.6572288, + 0.65665054, + 0.6560719, + 0.65549284, + 0.6549134, + 0.6543336, + 0.6537534, + 0.65317285, + 0.6525919, + 0.65201056, + 0.6514288, + 0.65084666, + 0.6502642, + 0.6496813, + 0.64909804, + 0.6485144, + 0.6479304, + 0.64734596, + 0.6467612, + 0.64617604, + 0.6455905, + 0.6450045, + 0.64441824, + 0.64383155, + 0.6432445, + 0.64265704, + 0.6420692, + 0.64148104, + 0.64089245, + 0.6403035, + 0.6397142, + 0.63912445, + 0.63853437, + 0.6379439, + 0.63735306, + 0.63676184, + 0.63617027, + 0.63557833, + 0.634986, + 0.6343933, + 0.6338002, + 0.6332068, + 0.63261294, + 0.63201874, + 0.6314242, + 0.6308292, + 0.63023394, + 0.62963825, + 0.6290422, + 0.62844574, + 0.627849, + 0.6272518, + 0.62665427, + 0.6260564, + 0.6254581, + 0.6248595, + 0.6242605, + 0.6236611, + 0.62306136, + 0.62246126, + 0.6218608, + 0.62126, + 0.62065876, + 0.6200572, + 0.6194553, + 0.618853, + 0.6182503, + 0.6176473, + 0.6170439, + 0.6164402, + 0.6158361, + 0.6152316, + 0.61462677, + 0.61402154, + 0.613416, + 0.6128101, + 0.6122038, + 0.6115972, + 0.61099017, + 0.6103828, + 0.60977507, + 0.60916704, + 0.6085586, + 0.6079498, + 0.60734063, + 0.6067311, + 0.60612124, + 0.60551107, + 0.6049005, + 0.60428953, + 0.6036782, + 0.6030666, + 0.6024546, + 0.6018422, + 0.60122955, + 0.60061646, + 0.60000306, + 0.5993893, + 0.5987752, + 0.5981607, + 0.59754586, + 0.5969307, + 0.5963152, + 0.5956993, + 0.59508306, + 0.5944665, + 0.5938496, + 0.5932323, + 0.59261465, + 0.59199667, + 0.5913784, + 0.5907597, + 0.5901407, + 0.5895213, + 0.5889016, + 0.5882816, + 0.58766115, + 0.58704036, + 0.5864193, + 0.58579785, + 0.58517605, + 0.58455396, + 0.58393145, + 0.58330864, + 0.5826855, + 0.582062, + 0.5814381, + 0.58081394, + 0.5801894, + 0.5795646, + 0.5789393, + 0.57831377, + 0.5776879, + 0.57706165, + 0.5764351, + 0.57580817, + 0.57518095, + 0.5745534, + 0.57392544, + 0.57329714, + 0.57266855, + 0.5720396, + 0.57141036, + 0.57078075, + 0.5701508, + 0.56952053, + 0.5688899, + 0.56825894, + 0.56762767, + 0.56699604, + 0.5663641, + 0.5657318, + 0.5650992, + 0.56446624, + 0.56383294, + 0.56319934, + 0.5625654, + 0.56193113, + 0.5612965, + 0.56066155, + 0.5600263, + 0.5593907, + 0.5587548, + 0.5581185, + 0.55748194, + 0.556845, + 0.5562078, + 0.55557024, + 0.55493236, + 0.5542941, + 0.55365556, + 0.5530167, + 0.5523775, + 0.55173796, + 0.55109817, + 0.55045795, + 0.5498175, + 0.54917663, + 0.5485355, + 0.54789406, + 0.5472523, + 0.5466102, + 0.54596776, + 0.545325, + 0.5446819, + 0.54403853, + 0.5433948, + 0.5427508, + 0.54210645, + 0.54146177, + 0.5408168, + 0.54017144, + 0.53952587, + 0.53887993, + 0.53823364, + 0.53758705, + 0.53694016, + 0.53629297, + 0.5356455, + 0.53499764, + 0.53434944, + 0.533701, + 0.5330522, + 0.5324031, + 0.5317537, + 0.531104, + 0.530454, + 0.52980363, + 0.529153, + 0.528502, + 0.52785075, + 0.52719915, + 0.52654725, + 0.525895, + 0.5252425, + 0.52458966, + 0.52393657, + 0.5232831, + 0.5226294, + 0.5219753, + 0.52132094, + 0.52066624, + 0.52001125, + 0.519356, + 0.5187004, + 0.51804453, + 0.5173883, + 0.5167318, + 0.516075, + 0.5154179, + 0.51476043, + 0.51410276, + 0.5134447, + 0.5127864, + 0.51212776, + 0.5114688, + 0.5108096, + 0.5101501, + 0.50949025, + 0.50883013, + 0.5081697, + 0.507509, + 0.506848, + 0.50618666, + 0.50552505, + 0.5048631, + 0.5042009, + 0.50353837, + 0.50287557, + 0.50221246, + 0.50154907, + 0.50088537, + 0.5002214, + 0.4995571, + 0.49889255, + 0.49822766, + 0.4975625, + 0.49689704, + 0.4962313, + 0.49556527, + 0.49489895, + 0.4942323, + 0.4935654, + 0.4928982, + 0.4922307, + 0.4915629, + 0.49089485, + 0.49022648, + 0.48955783, + 0.4888889, + 0.48821968, + 0.48755017, + 0.48688036, + 0.4862103, + 0.4855399, + 0.48486924, + 0.4841983, + 0.48352706, + 0.48285556, + 0.48218378, + 0.48151168, + 0.48083934, + 0.48016667, + 0.47949377, + 0.47882056, + 0.47814706, + 0.4774733, + 0.47679922, + 0.47612488, + 0.47545028, + 0.47477537, + 0.4741002, + 0.47342476, + 0.47274902, + 0.47207302, + 0.47139674, + 0.47072017, + 0.47004333, + 0.46936622, + 0.46868882, + 0.46801114, + 0.4673332, + 0.466655, + 0.4659765, + 0.46529773, + 0.46461868, + 0.46393937, + 0.4632598, + 0.46257994, + 0.4618998, + 0.4612194, + 0.46053872, + 0.45985776, + 0.45917654, + 0.45849505, + 0.4578133, + 0.45713127, + 0.45644897, + 0.4557664, + 0.45508358, + 0.45440048, + 0.4537171, + 0.45303348, + 0.45234957, + 0.45166543, + 0.450981, + 0.45029628, + 0.44961134, + 0.4489261, + 0.4482406, + 0.44755486, + 0.44686884, + 0.44618255, + 0.44549602, + 0.4448092, + 0.44412214, + 0.4434348, + 0.44274724, + 0.44205937, + 0.44137126, + 0.4406829, + 0.43999428, + 0.4393054, + 0.43861625, + 0.43792683, + 0.43723717, + 0.43654725, + 0.4358571, + 0.43516666, + 0.43447596, + 0.43378502, + 0.43309382, + 0.43240237, + 0.43171066, + 0.4310187, + 0.4303265, + 0.429634, + 0.42894128, + 0.42824832, + 0.42755508, + 0.4268616, + 0.42616788, + 0.4254739, + 0.42477968, + 0.4240852, + 0.42339048, + 0.4226955, + 0.42200026, + 0.4213048, + 0.4206091, + 0.4199131, + 0.4192169, + 0.41852042, + 0.4178237, + 0.41712677, + 0.41642955, + 0.41573212, + 0.4150344, + 0.4143365, + 0.41363832, + 0.41293988, + 0.41224122, + 0.41154233, + 0.41084316, + 0.4101438, + 0.40944415, + 0.40874428, + 0.40804416, + 0.4073438, + 0.4066432, + 0.40594238, + 0.4052413, + 0.40454, + 0.40383846, + 0.40313667, + 0.40243465, + 0.4017324, + 0.40102988, + 0.40032718, + 0.3996242, + 0.398921, + 0.39821756, + 0.3975139, + 0.39681, + 0.39610586, + 0.39540148, + 0.39469686, + 0.39399204, + 0.39328697, + 0.39258167, + 0.39187613, + 0.39117038, + 0.3904644, + 0.38975817, + 0.38905174, + 0.38834503, + 0.38763815, + 0.386931, + 0.38622364, + 0.38551605, + 0.38480824, + 0.3841002, + 0.38339192, + 0.38268343, + 0.38197473, + 0.38126576, + 0.3805566, + 0.3798472, + 0.3791376, + 0.37842774, + 0.3777177, + 0.37700742, + 0.3762969, + 0.37558618, + 0.37487522, + 0.37416407, + 0.37345266, + 0.37274107, + 0.37202924, + 0.3713172, + 0.37060493, + 0.36989245, + 0.36917976, + 0.36846682, + 0.36775368, + 0.36704034, + 0.36632678, + 0.36561298, + 0.364899, + 0.3641848, + 0.36347038, + 0.36275572, + 0.36204088, + 0.3613258, + 0.3606105, + 0.35989505, + 0.35917935, + 0.3584634, + 0.3577473, + 0.35703096, + 0.35631442, + 0.35559767, + 0.3548807, + 0.35416353, + 0.35344616, + 0.35272855, + 0.35201076, + 0.35129276, + 0.35057455, + 0.34985614, + 0.3491375, + 0.34841868, + 0.34769964, + 0.34698042, + 0.34626096, + 0.34554133, + 0.34482148, + 0.34410143, + 0.34338117, + 0.34266073, + 0.34194008, + 0.34121922, + 0.34049815, + 0.33977687, + 0.33905542, + 0.33833376, + 0.3376119, + 0.33688986, + 0.3361676, + 0.33544514, + 0.3347225, + 0.33399966, + 0.3332766, + 0.33255336, + 0.33182994, + 0.3311063, + 0.3303825, + 0.32965845, + 0.32893425, + 0.32820985, + 0.32748523, + 0.32676044, + 0.32603547, + 0.3253103, + 0.32458493, + 0.32385936, + 0.32313362, + 0.3224077, + 0.32168156, + 0.32095525, + 0.32022873, + 0.31950203, + 0.31877515, + 0.3180481, + 0.31732082, + 0.31659338, + 0.31586576, + 0.31513792, + 0.31440994, + 0.31368175, + 0.31295338, + 0.3122248, + 0.31149608, + 0.31076714, + 0.31003806, + 0.30930877, + 0.3085793, + 0.30784965, + 0.30711982, + 0.3063898, + 0.3056596, + 0.30492923, + 0.30419868, + 0.30346796, + 0.30273703, + 0.30200595, + 0.3012747, + 0.30054325, + 0.29981163, + 0.29907984, + 0.29834786, + 0.2976157, + 0.29688337, + 0.2961509, + 0.2954182, + 0.29468536, + 0.29395235, + 0.29321915, + 0.2924858, + 0.29175225, + 0.29101855, + 0.29028466, + 0.28955063, + 0.28881642, + 0.28808203, + 0.28734747, + 0.28661272, + 0.28587782, + 0.28514278, + 0.28440753, + 0.28367212, + 0.28293657, + 0.28220084, + 0.28146493, + 0.28072888, + 0.27999264, + 0.27925625, + 0.2785197, + 0.27778298, + 0.27704608, + 0.27630904, + 0.27557182, + 0.27483445, + 0.2740969, + 0.2733592, + 0.27262136, + 0.27188334, + 0.27114516, + 0.2704068, + 0.2696683, + 0.26892966, + 0.26819086, + 0.26745188, + 0.26671275, + 0.26597348, + 0.26523402, + 0.26449442, + 0.26375467, + 0.26301476, + 0.2622747, + 0.26153448, + 0.2607941, + 0.2600536, + 0.25931293, + 0.25857207, + 0.2578311, + 0.25708997, + 0.25634867, + 0.25560725, + 0.25486565, + 0.25412393, + 0.25338203, + 0.25264, + 0.2518978, + 0.2511555, + 0.250413, + 0.24967039, + 0.24892761, + 0.24818468, + 0.24744162, + 0.24669841, + 0.24595505, + 0.24521154, + 0.2444679, + 0.24372411, + 0.24298018, + 0.24223611, + 0.24149188, + 0.24074753, + 0.24000302, + 0.23925838, + 0.23851359, + 0.23776866, + 0.2370236, + 0.2362784, + 0.23553306, + 0.23478758, + 0.23404196, + 0.2332962, + 0.23255031, + 0.23180428, + 0.2310581, + 0.23031181, + 0.22956537, + 0.22881879, + 0.22807208, + 0.22732525, + 0.22657827, + 0.22583115, + 0.22508392, + 0.22433653, + 0.22358903, + 0.2228414, + 0.22209363, + 0.22134572, + 0.22059768, + 0.21984953, + 0.21910124, + 0.21835282, + 0.21760428, + 0.2168556, + 0.2161068, + 0.21535787, + 0.21460882, + 0.21385963, + 0.21311031, + 0.21236089, + 0.21161133, + 0.21086164, + 0.21011184, + 0.20936191, + 0.20861185, + 0.20786168, + 0.20711137, + 0.20636095, + 0.20561041, + 0.20485975, + 0.20410897, + 0.20335807, + 0.20260704, + 0.2018559, + 0.20110464, + 0.20035325, + 0.19960175, + 0.19885014, + 0.1980984, + 0.19734657, + 0.1965946, + 0.19584252, + 0.19509032, + 0.19433801, + 0.19358559, + 0.19283305, + 0.1920804, + 0.19132763, + 0.19057475, + 0.18982176, + 0.18906866, + 0.18831545, + 0.18756212, + 0.18680869, + 0.18605515, + 0.1853015, + 0.18454774, + 0.18379387, + 0.18303989, + 0.1822858, + 0.18153161, + 0.18077731, + 0.1800229, + 0.17926839, + 0.17851377, + 0.17775905, + 0.17700422, + 0.1762493, + 0.17549425, + 0.17473911, + 0.17398387, + 0.17322853, + 0.17247309, + 0.17171754, + 0.17096189, + 0.17020614, + 0.1694503, + 0.16869435, + 0.16793829, + 0.16718215, + 0.1664259, + 0.16566956, + 0.16491312, + 0.16415659, + 0.16339995, + 0.16264322, + 0.1618864, + 0.16112947, + 0.16037245, + 0.15961535, + 0.15885815, + 0.15810084, + 0.15734346, + 0.15658598, + 0.1558284, + 0.15507074, + 0.15431297, + 0.15355512, + 0.15279719, + 0.15203916, + 0.15128104, + 0.15052283, + 0.14976454, + 0.14900614, + 0.14824767, + 0.14748912, + 0.14673047, + 0.14597175, + 0.14521292, + 0.14445402, + 0.14369503, + 0.14293596, + 0.1421768, + 0.14141756, + 0.14065824, + 0.13989884, + 0.13913934, + 0.13837977, + 0.13762012, + 0.13686039, + 0.13610058, + 0.13534068, + 0.1345807, + 0.13382065, + 0.13306053, + 0.13230032, + 0.13154003, + 0.13077967, + 0.13001922, + 0.1292587, + 0.1284981, + 0.12773745, + 0.1269767, + 0.12621588, + 0.12545498, + 0.12469402, + 0.12393297, + 0.12317186, + 0.12241068, + 0.121649414, + 0.120888084, + 0.12012669, + 0.119365215, + 0.11860368, + 0.11784206, + 0.11708038, + 0.11631863, + 0.115556814, + 0.114794925, + 0.11403298, + 0.11327095, + 0.11250886, + 0.11174671, + 0.11098449, + 0.110222206, + 0.109459855, + 0.108697444, + 0.10793497, + 0.10717242, + 0.10640982, + 0.105647154, + 0.10488442, + 0.10412163, + 0.10335878, + 0.102595866, + 0.1018329, + 0.10106986, + 0.10030677, + 0.099543616, + 0.09878041, + 0.09801714, + 0.097253814, + 0.09649043, + 0.09572699, + 0.0949635, + 0.09419994, + 0.09343634, + 0.092672676, + 0.091908954, + 0.09114519, + 0.09038136, + 0.08961748, + 0.08885355, + 0.08808957, + 0.087325536, + 0.08656145, + 0.08579731, + 0.085033126, + 0.08426889, + 0.0835046, + 0.08274026, + 0.08197588, + 0.08121145, + 0.080446966, + 0.07968244, + 0.07891786, + 0.078153245, + 0.07738858, + 0.076623864, + 0.07585911, + 0.0750943, + 0.07432945, + 0.07356457, + 0.07279963, + 0.07203465, + 0.07126963, + 0.070504576, + 0.06973947, + 0.06897433, + 0.06820914, + 0.06744392, + 0.06667866, + 0.06591335, + 0.06514801, + 0.06438263, + 0.063617215, + 0.06285176, + 0.062086266, + 0.061320737, + 0.06055517, + 0.059789572, + 0.059023935, + 0.058258265, + 0.057492558, + 0.05672682, + 0.05596105, + 0.055195246, + 0.05442941, + 0.053663537, + 0.052897636, + 0.052131705, + 0.05136574, + 0.05059975, + 0.049833726, + 0.049067676, + 0.048301592, + 0.047535483, + 0.046769347, + 0.04600318, + 0.04523699, + 0.044470772, + 0.04370453, + 0.04293826, + 0.042171963, + 0.04140564, + 0.040639296, + 0.039872926, + 0.039106537, + 0.03834012, + 0.037573684, + 0.036807224, + 0.036040742, + 0.035274237, + 0.034507714, + 0.033741172, + 0.03297461, + 0.032208025, + 0.031441424, + 0.030674804, + 0.029908165, + 0.029141508, + 0.028374836, + 0.027608145, + 0.02684144, + 0.026074719, + 0.025307981, + 0.024541229, + 0.023774462, + 0.023007682, + 0.022240888, + 0.02147408, + 0.02070726, + 0.019940428, + 0.019173585, + 0.01840673, + 0.017639864, + 0.016872987, + 0.016106103, + 0.015339206, + 0.014572302, + 0.0138053885, + 0.013038468, + 0.012271538, + 0.011504602, + 0.010737659, + 0.00997071, + 0.009203754, + 0.008436794, + 0.007669829, + 0.0069028586, + 0.0061358847, + 0.005368907, + 0.004601926, + 0.0038349426, + 0.0030679568, + 0.002300969, + 0.0015339801, + 0.0007669903, +} diff --git a/vendor/golang.org/x/mobile/exp/f32/vec3.go b/vendor/golang.org/x/mobile/exp/f32/vec3.go new file mode 100644 index 0000000..f966ce6 --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/f32/vec3.go @@ -0,0 +1,49 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package f32 + +import "fmt" + +type Vec3 [3]float32 + +func (v Vec3) String() string { + return fmt.Sprintf("Vec3[% 0.3f, % 0.3f, % 0.3f]", v[0], v[1], v[2]) +} + +func (v *Vec3) Normalize() { + sq := v.Dot(v) + inv := 1 / Sqrt(sq) + v[0] *= inv + v[1] *= inv + v[2] *= inv +} + +func (v *Vec3) Sub(v0, v1 *Vec3) { + v[0] = v0[0] - v1[0] + v[1] = v0[1] - v1[1] + v[2] = v0[2] - v1[2] +} + +func (v *Vec3) Add(v0, v1 *Vec3) { + v[0] = v0[0] + v1[0] + v[1] = v0[1] + v1[1] + v[2] = v0[2] + v1[2] +} + +func (v *Vec3) Mul(v0, v1 *Vec3) { + v[0] = v0[0] * v1[0] + v[1] = v0[1] * v1[1] + v[2] = v0[2] * v1[2] +} + +func (v *Vec3) Cross(v0, v1 *Vec3) { + v[0] = v0[1]*v1[2] - v0[2]*v1[1] + v[1] = v0[2]*v1[0] - v0[0]*v1[2] + v[2] = v0[0]*v1[1] - v0[1]*v1[0] +} + +func (v *Vec3) Dot(v1 *Vec3) float32 { + return v[0]*v1[0] + v[1]*v1[1] + v[2]*v1[2] +} diff --git a/vendor/golang.org/x/mobile/exp/f32/vec4.go b/vendor/golang.org/x/mobile/exp/f32/vec4.go new file mode 100644 index 0000000..ac7f7e0 --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/f32/vec4.go @@ -0,0 +1,47 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package f32 + +import "fmt" + +type Vec4 [4]float32 + +func (v Vec4) String() string { + return fmt.Sprintf("Vec4[% 0.3f, % 0.3f, % 0.3f, % 0.3f]", v[0], v[1], v[2], v[3]) +} + +func (v *Vec4) Normalize() { + sq := v.Dot(v) + inv := 1 / Sqrt(sq) + v[0] *= inv + v[1] *= inv + v[2] *= inv + v[3] *= inv +} + +func (v *Vec4) Sub(v0, v1 *Vec4) { + v[0] = v0[0] - v1[0] + v[1] = v0[1] - v1[1] + v[2] = v0[2] - v1[2] + v[3] = v0[3] - v1[3] +} + +func (v *Vec4) Add(v0, v1 *Vec4) { + v[0] = v0[0] + v1[0] + v[1] = v0[1] + v1[1] + v[2] = v0[2] + v1[2] + v[3] = v0[3] + v1[3] +} + +func (v *Vec4) Mul(v0, v1 *Vec4) { + v[0] = v0[0] * v1[0] + v[1] = v0[1] * v1[1] + v[2] = v0[2] * v1[2] + v[3] = v0[3] * v1[3] +} + +func (v *Vec4) Dot(v1 *Vec4) float32 { + return v[0]*v1[0] + v[1]*v1[1] + v[2]*v1[2] + v[3]*v1[3] +} diff --git a/vendor/golang.org/x/mobile/exp/gl/glutil/context_darwin_desktop.go b/vendor/golang.org/x/mobile/exp/gl/glutil/context_darwin_desktop.go new file mode 100644 index 0000000..42488a2 --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/gl/glutil/context_darwin_desktop.go @@ -0,0 +1,95 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin +// +build !ios + +package glutil + +// TODO(crawshaw): Only used in glutil tests for now (cgo is not support in _test.go files). +// TODO(crawshaw): Export some kind of Context. Work out what we can offer, where. Maybe just for tests. +// TODO(crawshaw): Support android and windows. + +/* +#cgo CFLAGS: -DGL_SILENCE_DEPRECATION +#cgo LDFLAGS: -framework OpenGL +#import +#import + +CGLError CGCreate(CGLContextObj* ctx) { + CGLError err; + CGLPixelFormatAttribute attributes[] = { + kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, + kCGLPFAColorSize, (CGLPixelFormatAttribute)24, + kCGLPFAAlphaSize, (CGLPixelFormatAttribute)8, + kCGLPFADepthSize, (CGLPixelFormatAttribute)16, + kCGLPFAAccelerated, + kCGLPFADoubleBuffer, + (CGLPixelFormatAttribute) 0 + }; + CGLPixelFormatObj pix; + GLint num; + + if ((err = CGLChoosePixelFormat(attributes, &pix, &num)) != kCGLNoError) { + return err; + } + if ((err = CGLCreateContext(pix, 0, ctx)) != kCGLNoError) { + return err; + } + if ((err = CGLDestroyPixelFormat(pix)) != kCGLNoError) { + return err; + } + if ((err = CGLSetCurrentContext(*ctx)) != kCGLNoError) { + return err; + } + if ((err = CGLLockContext(*ctx)) != kCGLNoError) { + return err; + } + return kCGLNoError; +} +*/ +import "C" + +import ( + "fmt" + "runtime" +) + +// contextGL holds a copy of the OpenGL Context from thread-local storage. +// +// Do not move a contextGL between goroutines or OS threads. +type contextGL struct { + ctx C.CGLContextObj +} + +// createContext creates an OpenGL context, binds it as the current context +// stored in thread-local storage, and locks the current goroutine to an os +// thread. +func createContext() (*contextGL, error) { + // The OpenGL active context is stored in TLS. + runtime.LockOSThread() + + c := new(contextGL) + if cglErr := C.CGCreate(&c.ctx); cglErr != C.kCGLNoError { + return nil, fmt.Errorf("CGL: %v", C.GoString(C.CGLErrorString(cglErr))) + } + + // Using attribute arrays in OpenGL 3.3 requires the use of a VBA. + // But VBAs don't exist in ES 2. So we bind a default one. + var id C.GLuint + C.glGenVertexArrays(1, &id) + C.glBindVertexArray(id) + + return c, nil +} + +// destroy destroys an OpenGL context and unlocks the current goroutine from +// its os thread. +func (c *contextGL) destroy() { + C.CGLUnlockContext(c.ctx) + C.CGLSetCurrentContext(nil) + C.CGLDestroyContext(c.ctx) + c.ctx = nil + runtime.UnlockOSThread() +} diff --git a/vendor/golang.org/x/mobile/exp/gl/glutil/context_x11.go b/vendor/golang.org/x/mobile/exp/gl/glutil/context_x11.go new file mode 100644 index 0000000..49bda4b --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/gl/glutil/context_x11.go @@ -0,0 +1,105 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build linux,!android + +package glutil + +/* +#cgo LDFLAGS: -lEGL +#include +#include +#include + +void createContext(EGLDisplay *out_dpy, EGLContext *out_ctx, EGLSurface *out_surf) { + EGLDisplay e_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); + if (!e_dpy) { + fprintf(stderr, "eglGetDisplay failed\n"); + exit(1); + } + EGLint e_major, e_minor; + if (!eglInitialize(e_dpy, &e_major, &e_minor)) { + fprintf(stderr, "eglInitialize failed\n"); + exit(1); + } + eglBindAPI(EGL_OPENGL_ES_API); + static const EGLint config_attribs[] = { + EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, + EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, + EGL_BLUE_SIZE, 8, + EGL_GREEN_SIZE, 8, + EGL_RED_SIZE, 8, + EGL_CONFIG_CAVEAT, EGL_NONE, + EGL_NONE + }; + EGLConfig config; + EGLint num_configs; + if (!eglChooseConfig(e_dpy, config_attribs, &config, 1, &num_configs)) { + fprintf(stderr, "eglChooseConfig failed\n"); + exit(1); + } + static const EGLint ctx_attribs[] = { + EGL_CONTEXT_CLIENT_VERSION, 2, + EGL_NONE + }; + EGLContext e_ctx = eglCreateContext(e_dpy, config, EGL_NO_CONTEXT, ctx_attribs); + if (e_ctx == EGL_NO_CONTEXT) { + fprintf(stderr, "eglCreateContext failed\n"); + exit(1); + } + static const EGLint pbuf_attribs[] = { + EGL_NONE + }; + EGLSurface e_surf = eglCreatePbufferSurface(e_dpy, config, pbuf_attribs); + if (e_surf == EGL_NO_SURFACE) { + fprintf(stderr, "eglCreatePbufferSurface failed\n"); + exit(1); + } + if (!eglMakeCurrent(e_dpy, e_surf, e_surf, e_ctx)) { + fprintf(stderr, "eglMakeCurrent failed\n"); + exit(1); + } + *out_surf = e_surf; + *out_ctx = e_ctx; + *out_dpy = e_dpy; +} + +void destroyContext(EGLDisplay e_dpy, EGLContext e_ctx, EGLSurface e_surf) { + if (!eglMakeCurrent(e_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { + fprintf(stderr, "eglMakeCurrent failed\n"); + exit(1); + } + if (!eglDestroySurface(e_dpy, e_surf)) { + fprintf(stderr, "eglDestroySurface failed\n"); + exit(1); + } + if (!eglDestroyContext(e_dpy, e_ctx)) { + fprintf(stderr, "eglDestroyContext failed\n"); + exit(1); + } +} +*/ +import "C" + +import ( + "runtime" +) + +type contextGL struct { + dpy C.EGLDisplay + ctx C.EGLContext + surf C.EGLSurface +} + +func createContext() (*contextGL, error) { + runtime.LockOSThread() + c := &contextGL{} + C.createContext(&c.dpy, &c.ctx, &c.surf) + return c, nil +} + +func (c *contextGL) destroy() { + C.destroyContext(c.dpy, c.ctx, c.surf) + runtime.UnlockOSThread() +} diff --git a/vendor/golang.org/x/mobile/exp/gl/glutil/doc.go b/vendor/golang.org/x/mobile/exp/gl/glutil/doc.go new file mode 100644 index 0000000..44b1210 --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/gl/glutil/doc.go @@ -0,0 +1,6 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package glutil implements OpenGL utility functions. +package glutil // import "golang.org/x/mobile/exp/gl/glutil" diff --git a/vendor/golang.org/x/mobile/exp/gl/glutil/glimage.go b/vendor/golang.org/x/mobile/exp/gl/glutil/glimage.go new file mode 100644 index 0000000..c5542fa --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/gl/glutil/glimage.go @@ -0,0 +1,333 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build linux darwin windows + +package glutil + +import ( + "encoding/binary" + "image" + "runtime" + "sync" + + "golang.org/x/mobile/event/size" + "golang.org/x/mobile/exp/f32" + "golang.org/x/mobile/geom" + "golang.org/x/mobile/gl" +) + +// Images maintains the shared state used by a set of *Image objects. +type Images struct { + glctx gl.Context + quadXY gl.Buffer + quadUV gl.Buffer + program gl.Program + pos gl.Attrib + mvp gl.Uniform + uvp gl.Uniform + inUV gl.Attrib + textureSample gl.Uniform + + mu sync.Mutex + activeImages int +} + +// NewImages creates an *Images. +func NewImages(glctx gl.Context) *Images { + program, err := CreateProgram(glctx, vertexShader, fragmentShader) + if err != nil { + panic(err) + } + + p := &Images{ + glctx: glctx, + quadXY: glctx.CreateBuffer(), + quadUV: glctx.CreateBuffer(), + program: program, + pos: glctx.GetAttribLocation(program, "pos"), + mvp: glctx.GetUniformLocation(program, "mvp"), + uvp: glctx.GetUniformLocation(program, "uvp"), + inUV: glctx.GetAttribLocation(program, "inUV"), + textureSample: glctx.GetUniformLocation(program, "textureSample"), + } + + glctx.BindBuffer(gl.ARRAY_BUFFER, p.quadXY) + glctx.BufferData(gl.ARRAY_BUFFER, quadXYCoords, gl.STATIC_DRAW) + glctx.BindBuffer(gl.ARRAY_BUFFER, p.quadUV) + glctx.BufferData(gl.ARRAY_BUFFER, quadUVCoords, gl.STATIC_DRAW) + + return p +} + +// Release releases any held OpenGL resources. +// All *Image objects must be released first, or this function panics. +func (p *Images) Release() { + if p.program == (gl.Program{}) { + return + } + + p.mu.Lock() + rem := p.activeImages + p.mu.Unlock() + if rem > 0 { + panic("glutil.Images.Release called, but active *Image objects remain") + } + + p.glctx.DeleteProgram(p.program) + p.glctx.DeleteBuffer(p.quadXY) + p.glctx.DeleteBuffer(p.quadUV) + + p.program = gl.Program{} +} + +// Image bridges between an *image.RGBA and an OpenGL texture. +// +// The contents of the *image.RGBA can be uploaded as a texture and drawn as a +// 2D quad. +// +// The number of active Images must fit in the system's OpenGL texture limit. +// The typical use of an Image is as a texture atlas. +type Image struct { + RGBA *image.RGBA + + gltex gl.Texture + width int + height int + images *Images +} + +// NewImage creates an Image of the given size. +// +// Both a host-memory *image.RGBA and a GL texture are created. +func (p *Images) NewImage(w, h int) *Image { + dx := roundToPower2(w) + dy := roundToPower2(h) + + // TODO(crawshaw): Using VertexAttribPointer we can pass texture + // data with a stride, which would let us use the exact number of + // pixels on the host instead of the rounded up power 2 size. + m := image.NewRGBA(image.Rect(0, 0, dx, dy)) + + img := &Image{ + RGBA: m.SubImage(image.Rect(0, 0, w, h)).(*image.RGBA), + images: p, + width: dx, + height: dy, + } + + p.mu.Lock() + p.activeImages++ + p.mu.Unlock() + + img.gltex = p.glctx.CreateTexture() + + p.glctx.BindTexture(gl.TEXTURE_2D, img.gltex) + p.glctx.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, img.width, img.height, gl.RGBA, gl.UNSIGNED_BYTE, nil) + p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) + p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) + p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) + p.glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) + + runtime.SetFinalizer(img, (*Image).Release) + return img +} + +func roundToPower2(x int) int { + x2 := 1 + for x2 < x { + x2 *= 2 + } + return x2 +} + +// Upload copies the host image data to the GL device. +func (img *Image) Upload() { + img.images.glctx.BindTexture(gl.TEXTURE_2D, img.gltex) + img.images.glctx.TexSubImage2D(gl.TEXTURE_2D, 0, 0, 0, img.width, img.height, gl.RGBA, gl.UNSIGNED_BYTE, img.RGBA.Pix) +} + +// Release invalidates the Image and removes any underlying data structures. +// The Image cannot be used after being deleted. +func (img *Image) Release() { + if img.gltex == (gl.Texture{}) { + return + } + + img.images.glctx.DeleteTexture(img.gltex) + img.gltex = gl.Texture{} + + img.images.mu.Lock() + img.images.activeImages-- + img.images.mu.Unlock() +} + +// Draw draws the srcBounds part of the image onto a parallelogram, defined by +// three of its corners, in the current GL framebuffer. +func (img *Image) Draw(sz size.Event, topLeft, topRight, bottomLeft geom.Point, srcBounds image.Rectangle) { + glimage := img.images + glctx := img.images.glctx + + glctx.BlendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA) + glctx.Enable(gl.BLEND) + + // TODO(crawshaw): Adjust viewport for the top bar on android? + glctx.UseProgram(glimage.program) + { + // We are drawing a parallelogram PQRS, defined by three of its + // corners, onto the entire GL framebuffer ABCD. The two quads may + // actually be equal, but in the general case, PQRS can be smaller, + // and PQRS is not necessarily axis-aligned. + // + // A +---------------+ B + // | P +-----+ Q | + // | | | | + // | S +-----+ R | + // D +---------------+ C + // + // There are two co-ordinate spaces: geom space and framebuffer space. + // In geom space, the ABCD rectangle is: + // + // (0, 0) (geom.Width, 0) + // (0, geom.Height) (geom.Width, geom.Height) + // + // and the PQRS quad is: + // + // (topLeft.X, topLeft.Y) (topRight.X, topRight.Y) + // (bottomLeft.X, bottomLeft.Y) (implicit, implicit) + // + // In framebuffer space, the ABCD rectangle is: + // + // (-1, +1) (+1, +1) + // (-1, -1) (+1, -1) + // + // First of all, convert from geom space to framebuffer space. For + // later convenience, we divide everything by 2 here: px2 is half of + // the P.X co-ordinate (in framebuffer space). + px2 := -0.5 + float32(topLeft.X/sz.WidthPt) + py2 := +0.5 - float32(topLeft.Y/sz.HeightPt) + qx2 := -0.5 + float32(topRight.X/sz.WidthPt) + qy2 := +0.5 - float32(topRight.Y/sz.HeightPt) + sx2 := -0.5 + float32(bottomLeft.X/sz.WidthPt) + sy2 := +0.5 - float32(bottomLeft.Y/sz.HeightPt) + // Next, solve for the affine transformation matrix + // [ a00 a01 a02 ] + // a = [ a10 a11 a12 ] + // [ 0 0 1 ] + // that maps A to P: + // a × [ -1 +1 1 ]' = [ 2*px2 2*py2 1 ]' + // and likewise maps B to Q and D to S. Solving those three constraints + // implies that C maps to R, since affine transformations keep parallel + // lines parallel. This gives 6 equations in 6 unknowns: + // -a00 + a01 + a02 = 2*px2 + // -a10 + a11 + a12 = 2*py2 + // +a00 + a01 + a02 = 2*qx2 + // +a10 + a11 + a12 = 2*qy2 + // -a00 - a01 + a02 = 2*sx2 + // -a10 - a11 + a12 = 2*sy2 + // which gives: + // a00 = (2*qx2 - 2*px2) / 2 = qx2 - px2 + // and similarly for the other elements of a. + writeAffine(glctx, glimage.mvp, &f32.Affine{{ + qx2 - px2, + px2 - sx2, + qx2 + sx2, + }, { + qy2 - py2, + py2 - sy2, + qy2 + sy2, + }}) + } + + { + // Mapping texture co-ordinates is similar, except that in texture + // space, the ABCD rectangle is: + // + // (0,0) (1,0) + // (0,1) (1,1) + // + // and the PQRS quad is always axis-aligned. First of all, convert + // from pixel space to texture space. + w := float32(img.width) + h := float32(img.height) + px := float32(srcBounds.Min.X-img.RGBA.Rect.Min.X) / w + py := float32(srcBounds.Min.Y-img.RGBA.Rect.Min.Y) / h + qx := float32(srcBounds.Max.X-img.RGBA.Rect.Min.X) / w + sy := float32(srcBounds.Max.Y-img.RGBA.Rect.Min.Y) / h + // Due to axis alignment, qy = py and sx = px. + // + // The simultaneous equations are: + // 0 + 0 + a02 = px + // 0 + 0 + a12 = py + // a00 + 0 + a02 = qx + // a10 + 0 + a12 = qy = py + // 0 + a01 + a02 = sx = px + // 0 + a11 + a12 = sy + writeAffine(glctx, glimage.uvp, &f32.Affine{{ + qx - px, + 0, + px, + }, { + 0, + sy - py, + py, + }}) + } + + glctx.ActiveTexture(gl.TEXTURE0) + glctx.BindTexture(gl.TEXTURE_2D, img.gltex) + glctx.Uniform1i(glimage.textureSample, 0) + + glctx.BindBuffer(gl.ARRAY_BUFFER, glimage.quadXY) + glctx.EnableVertexAttribArray(glimage.pos) + glctx.VertexAttribPointer(glimage.pos, 2, gl.FLOAT, false, 0, 0) + + glctx.BindBuffer(gl.ARRAY_BUFFER, glimage.quadUV) + glctx.EnableVertexAttribArray(glimage.inUV) + glctx.VertexAttribPointer(glimage.inUV, 2, gl.FLOAT, false, 0, 0) + + glctx.DrawArrays(gl.TRIANGLE_STRIP, 0, 4) + + glctx.DisableVertexAttribArray(glimage.pos) + glctx.DisableVertexAttribArray(glimage.inUV) + + glctx.Disable(gl.BLEND) +} + +var quadXYCoords = f32.Bytes(binary.LittleEndian, + -1, +1, // top left + +1, +1, // top right + -1, -1, // bottom left + +1, -1, // bottom right +) + +var quadUVCoords = f32.Bytes(binary.LittleEndian, + 0, 0, // top left + 1, 0, // top right + 0, 1, // bottom left + 1, 1, // bottom right +) + +const vertexShader = `#version 100 +uniform mat3 mvp; +uniform mat3 uvp; +attribute vec3 pos; +attribute vec2 inUV; +varying vec2 UV; +void main() { + vec3 p = pos; + p.z = 1.0; + gl_Position = vec4(mvp * p, 1); + UV = (uvp * vec3(inUV, 1)).xy; +} +` + +const fragmentShader = `#version 100 +precision mediump float; +varying vec2 UV; +uniform sampler2D textureSample; +void main(){ + gl_FragColor = texture2D(textureSample, UV); +} +` diff --git a/vendor/golang.org/x/mobile/exp/gl/glutil/glutil.go b/vendor/golang.org/x/mobile/exp/gl/glutil/glutil.go new file mode 100644 index 0000000..5acafb5 --- /dev/null +++ b/vendor/golang.org/x/mobile/exp/gl/glutil/glutil.go @@ -0,0 +1,75 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin linux windows + +package glutil // import "golang.org/x/mobile/exp/gl/glutil" + +import ( + "fmt" + + "golang.org/x/mobile/exp/f32" + "golang.org/x/mobile/gl" +) + +// CreateProgram creates, compiles, and links a gl.Program. +func CreateProgram(glctx gl.Context, vertexSrc, fragmentSrc string) (gl.Program, error) { + program := glctx.CreateProgram() + if program.Value == 0 { + return gl.Program{}, fmt.Errorf("glutil: no programs available") + } + + vertexShader, err := loadShader(glctx, gl.VERTEX_SHADER, vertexSrc) + if err != nil { + return gl.Program{}, err + } + fragmentShader, err := loadShader(glctx, gl.FRAGMENT_SHADER, fragmentSrc) + if err != nil { + glctx.DeleteShader(vertexShader) + return gl.Program{}, err + } + + glctx.AttachShader(program, vertexShader) + glctx.AttachShader(program, fragmentShader) + glctx.LinkProgram(program) + + // Flag shaders for deletion when program is unlinked. + glctx.DeleteShader(vertexShader) + glctx.DeleteShader(fragmentShader) + + if glctx.GetProgrami(program, gl.LINK_STATUS) == 0 { + defer glctx.DeleteProgram(program) + return gl.Program{}, fmt.Errorf("glutil: %s", glctx.GetProgramInfoLog(program)) + } + return program, nil +} + +func loadShader(glctx gl.Context, shaderType gl.Enum, src string) (gl.Shader, error) { + shader := glctx.CreateShader(shaderType) + if shader.Value == 0 { + return gl.Shader{}, fmt.Errorf("glutil: could not create shader (type %v)", shaderType) + } + glctx.ShaderSource(shader, src) + glctx.CompileShader(shader) + if glctx.GetShaderi(shader, gl.COMPILE_STATUS) == 0 { + defer glctx.DeleteShader(shader) + return gl.Shader{}, fmt.Errorf("shader compile: %s", glctx.GetShaderInfoLog(shader)) + } + return shader, nil +} + +// writeAffine writes the contents of an Affine to a 3x3 matrix GL uniform. +func writeAffine(glctx gl.Context, u gl.Uniform, a *f32.Affine) { + var m [9]float32 + m[0*3+0] = a[0][0] + m[0*3+1] = a[1][0] + m[0*3+2] = 0 + m[1*3+0] = a[0][1] + m[1*3+1] = a[1][1] + m[1*3+2] = 0 + m[2*3+0] = a[0][2] + m[2*3+1] = a[1][2] + m[2*3+2] = 1 + glctx.UniformMatrix3fv(u, m[:]) +} diff --git a/vendor/golang.org/x/mobile/gl/fn.go b/vendor/golang.org/x/mobile/gl/fn.go index 35c52c8..3f2f3ad 100644 --- a/vendor/golang.org/x/mobile/gl/fn.go +++ b/vendor/golang.org/x/mobile/gl/fn.go @@ -38,6 +38,7 @@ const ( glfnBindFramebuffer glfnBindRenderbuffer glfnBindTexture + glfnBindVertexArray glfnBlendColor glfnBlendEquation glfnBlendEquationSeparate @@ -65,6 +66,7 @@ const ( glfnDeleteRenderbuffer glfnDeleteShader glfnDeleteTexture + glfnDeleteVertexArray glfnDepthFunc glfnDepthRangef glfnDepthMask @@ -84,6 +86,7 @@ const ( glfnGenFramebuffer glfnGenRenderbuffer glfnGenTexture + glfnGenVertexArray glfnGenerateMipmap glfnGetActiveAttrib glfnGetActiveUniform diff --git a/vendor/golang.org/x/mobile/gl/gendebug.go b/vendor/golang.org/x/mobile/gl/gendebug.go index 936accb..842fede 100644 --- a/vendor/golang.org/x/mobile/gl/gendebug.go +++ b/vendor/golang.org/x/mobile/gl/gendebug.go @@ -24,6 +24,614 @@ import ( "strconv" ) +var enumWhitelist = []string{ + "POINTS", + "LINES", + "LINE_LOOP", + "LINE_STRIP", + "TRIANGLES", + "TRIANGLE_STRIP", + "TRIANGLE_FAN", + "SRC_COLOR", + "ONE_MINUS_SRC_COLOR", + "SRC_ALPHA", + "ONE_MINUS_SRC_ALPHA", + "DST_ALPHA", + "ONE_MINUS_DST_ALPHA", + "DST_COLOR", + "ONE_MINUS_DST_COLOR", + "SRC_ALPHA_SATURATE", + "FUNC_ADD", + "BLEND_EQUATION", + "BLEND_EQUATION_RGB", + "BLEND_EQUATION_ALPHA", + "FUNC_SUBTRACT", + "FUNC_REVERSE_SUBTRACT", + "BLEND_DST_RGB", + "BLEND_SRC_RGB", + "BLEND_DST_ALPHA", + "BLEND_SRC_ALPHA", + "CONSTANT_COLOR", + "ONE_MINUS_CONSTANT_COLOR", + "CONSTANT_ALPHA", + "ONE_MINUS_CONSTANT_ALPHA", + "BLEND_COLOR", + "ARRAY_BUFFER", + "ELEMENT_ARRAY_BUFFER", + "ARRAY_BUFFER_BINDING", + "ELEMENT_ARRAY_BUFFER_BINDING", + "STREAM_DRAW", + "STATIC_DRAW", + "DYNAMIC_DRAW", + "BUFFER_SIZE", + "BUFFER_USAGE", + "CURRENT_VERTEX_ATTRIB", + "FRONT", + "BACK", + "FRONT_AND_BACK", + "TEXTURE_2D", + "CULL_FACE", + "BLEND", + "DITHER", + "STENCIL_TEST", + "DEPTH_TEST", + "SCISSOR_TEST", + "POLYGON_OFFSET_FILL", + "SAMPLE_ALPHA_TO_COVERAGE", + "SAMPLE_COVERAGE", + "INVALID_ENUM", + "INVALID_VALUE", + "INVALID_OPERATION", + "OUT_OF_MEMORY", + "CW", + "CCW", + "LINE_WIDTH", + "ALIASED_POINT_SIZE_RANGE", + "ALIASED_LINE_WIDTH_RANGE", + "CULL_FACE_MODE", + "FRONT_FACE", + "DEPTH_RANGE", + "DEPTH_WRITEMASK", + "DEPTH_CLEAR_VALUE", + "DEPTH_FUNC", + "STENCIL_CLEAR_VALUE", + "STENCIL_FUNC", + "STENCIL_FAIL", + "STENCIL_PASS_DEPTH_FAIL", + "STENCIL_PASS_DEPTH_PASS", + "STENCIL_REF", + "STENCIL_VALUE_MASK", + "STENCIL_WRITEMASK", + "STENCIL_BACK_FUNC", + "STENCIL_BACK_FAIL", + "STENCIL_BACK_PASS_DEPTH_FAIL", + "STENCIL_BACK_PASS_DEPTH_PASS", + "STENCIL_BACK_REF", + "STENCIL_BACK_VALUE_MASK", + "STENCIL_BACK_WRITEMASK", + "VIEWPORT", + "SCISSOR_BOX", + "COLOR_CLEAR_VALUE", + "COLOR_WRITEMASK", + "UNPACK_ALIGNMENT", + "PACK_ALIGNMENT", + "MAX_TEXTURE_SIZE", + "MAX_VIEWPORT_DIMS", + "SUBPIXEL_BITS", + "RED_BITS", + "GREEN_BITS", + "BLUE_BITS", + "ALPHA_BITS", + "DEPTH_BITS", + "STENCIL_BITS", + "POLYGON_OFFSET_UNITS", + "POLYGON_OFFSET_FACTOR", + "TEXTURE_BINDING_2D", + "SAMPLE_BUFFERS", + "SAMPLES", + "SAMPLE_COVERAGE_VALUE", + "SAMPLE_COVERAGE_INVERT", + "NUM_COMPRESSED_TEXTURE_FORMATS", + "COMPRESSED_TEXTURE_FORMATS", + "DONT_CARE", + "FASTEST", + "NICEST", + "GENERATE_MIPMAP_HINT", + "BYTE", + "UNSIGNED_BYTE", + "SHORT", + "UNSIGNED_SHORT", + "INT", + "UNSIGNED_INT", + "FLOAT", + "FIXED", + "DEPTH_COMPONENT", + "ALPHA", + "RGB", + "RGBA", + "LUMINANCE", + "LUMINANCE_ALPHA", + "UNSIGNED_SHORT_4_4_4_4", + "UNSIGNED_SHORT_5_5_5_1", + "UNSIGNED_SHORT_5_6_5", + "MAX_VERTEX_ATTRIBS", + "MAX_VERTEX_UNIFORM_VECTORS", + "MAX_VARYING_VECTORS", + "MAX_COMBINED_TEXTURE_IMAGE_UNITS", + "MAX_VERTEX_TEXTURE_IMAGE_UNITS", + "MAX_TEXTURE_IMAGE_UNITS", + "MAX_FRAGMENT_UNIFORM_VECTORS", + "SHADER_TYPE", + "DELETE_STATUS", + "LINK_STATUS", + "VALIDATE_STATUS", + "ATTACHED_SHADERS", + "ACTIVE_UNIFORMS", + "ACTIVE_UNIFORM_MAX_LENGTH", + "ACTIVE_ATTRIBUTES", + "ACTIVE_ATTRIBUTE_MAX_LENGTH", + "SHADING_LANGUAGE_VERSION", + "CURRENT_PROGRAM", + "NEVER", + "LESS", + "EQUAL", + "LEQUAL", + "GREATER", + "NOTEQUAL", + "GEQUAL", + "ALWAYS", + "KEEP", + "REPLACE", + "INCR", + "DECR", + "INVERT", + "INCR_WRAP", + "DECR_WRAP", + "VENDOR", + "RENDERER", + "VERSION", + "EXTENSIONS", + "NEAREST", + "LINEAR", + "NEAREST_MIPMAP_NEAREST", + "LINEAR_MIPMAP_NEAREST", + "NEAREST_MIPMAP_LINEAR", + "LINEAR_MIPMAP_LINEAR", + "TEXTURE_MAG_FILTER", + "TEXTURE_MIN_FILTER", + "TEXTURE_WRAP_S", + "TEXTURE_WRAP_T", + "TEXTURE", + "TEXTURE_CUBE_MAP", + "TEXTURE_BINDING_CUBE_MAP", + "TEXTURE_CUBE_MAP_POSITIVE_X", + "TEXTURE_CUBE_MAP_NEGATIVE_X", + "TEXTURE_CUBE_MAP_POSITIVE_Y", + "TEXTURE_CUBE_MAP_NEGATIVE_Y", + "TEXTURE_CUBE_MAP_POSITIVE_Z", + "TEXTURE_CUBE_MAP_NEGATIVE_Z", + "MAX_CUBE_MAP_TEXTURE_SIZE", + "TEXTURE0", + "TEXTURE1", + "TEXTURE2", + "TEXTURE3", + "TEXTURE4", + "TEXTURE5", + "TEXTURE6", + "TEXTURE7", + "TEXTURE8", + "TEXTURE9", + "TEXTURE10", + "TEXTURE11", + "TEXTURE12", + "TEXTURE13", + "TEXTURE14", + "TEXTURE15", + "TEXTURE16", + "TEXTURE17", + "TEXTURE18", + "TEXTURE19", + "TEXTURE20", + "TEXTURE21", + "TEXTURE22", + "TEXTURE23", + "TEXTURE24", + "TEXTURE25", + "TEXTURE26", + "TEXTURE27", + "TEXTURE28", + "TEXTURE29", + "TEXTURE30", + "TEXTURE31", + "ACTIVE_TEXTURE", + "REPEAT", + "CLAMP_TO_EDGE", + "MIRRORED_REPEAT", + "VERTEX_ATTRIB_ARRAY_ENABLED", + "VERTEX_ATTRIB_ARRAY_SIZE", + "VERTEX_ATTRIB_ARRAY_STRIDE", + "VERTEX_ATTRIB_ARRAY_TYPE", + "VERTEX_ATTRIB_ARRAY_NORMALIZED", + "VERTEX_ATTRIB_ARRAY_POINTER", + "VERTEX_ATTRIB_ARRAY_BUFFER_BINDING", + "IMPLEMENTATION_COLOR_READ_TYPE", + "IMPLEMENTATION_COLOR_READ_FORMAT", + "COMPILE_STATUS", + "INFO_LOG_LENGTH", + "SHADER_SOURCE_LENGTH", + "SHADER_COMPILER", + "SHADER_BINARY_FORMATS", + "NUM_SHADER_BINARY_FORMATS", + "LOW_FLOAT", + "MEDIUM_FLOAT", + "HIGH_FLOAT", + "LOW_INT", + "MEDIUM_INT", + "HIGH_INT", + "FRAMEBUFFER", + "RENDERBUFFER", + "RGBA4", + "RGB5_A1", + "RGB565", + "DEPTH_COMPONENT16", + "STENCIL_INDEX8", + "RENDERBUFFER_WIDTH", + "RENDERBUFFER_HEIGHT", + "RENDERBUFFER_INTERNAL_FORMAT", + "RENDERBUFFER_RED_SIZE", + "RENDERBUFFER_GREEN_SIZE", + "RENDERBUFFER_BLUE_SIZE", + "RENDERBUFFER_ALPHA_SIZE", + "RENDERBUFFER_DEPTH_SIZE", + "RENDERBUFFER_STENCIL_SIZE", + "FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE", + "FRAMEBUFFER_ATTACHMENT_OBJECT_NAME", + "FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL", + "FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE", + "COLOR_ATTACHMENT0", + "DEPTH_ATTACHMENT", + "STENCIL_ATTACHMENT", + "FRAMEBUFFER_COMPLETE", + "FRAMEBUFFER_INCOMPLETE_ATTACHMENT", + "FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT", + "FRAMEBUFFER_INCOMPLETE_DIMENSIONS", + "FRAMEBUFFER_UNSUPPORTED", + "FRAMEBUFFER_BINDING", + "RENDERBUFFER_BINDING", + "MAX_RENDERBUFFER_SIZE", + "INVALID_FRAMEBUFFER_OPERATION", + "DEPTH_BUFFER_BIT", + "STENCIL_BUFFER_BIT", + "COLOR_BUFFER_BIT", + "FLOAT_VEC2", + "FLOAT_VEC3", + "FLOAT_VEC4", + "INT_VEC2", + "INT_VEC3", + "INT_VEC4", + "BOOL", + "BOOL_VEC2", + "BOOL_VEC3", + "BOOL_VEC4", + "FLOAT_MAT2", + "FLOAT_MAT3", + "FLOAT_MAT4", + "SAMPLER_2D", + "SAMPLER_CUBE", + "FRAGMENT_SHADER", + "VERTEX_SHADER", + "FALSE", + "TRUE", + "ZERO", + "ONE", + "NO_ERROR", + "NONE", + "ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH", + "ACTIVE_UNIFORM_BLOCKS", + "ALREADY_SIGNALED", + "ANY_SAMPLES_PASSED", + "ANY_SAMPLES_PASSED_CONSERVATIVE", + "BLUE", + "BUFFER_ACCESS_FLAGS", + "BUFFER_MAP_LENGTH", + "BUFFER_MAP_OFFSET", + "BUFFER_MAPPED", + "BUFFER_MAP_POINTER", + "COLOR", + "COLOR_ATTACHMENT10", + "COLOR_ATTACHMENT1", + "COLOR_ATTACHMENT11", + "COLOR_ATTACHMENT12", + "COLOR_ATTACHMENT13", + "COLOR_ATTACHMENT14", + "COLOR_ATTACHMENT15", + "COLOR_ATTACHMENT2", + "COLOR_ATTACHMENT3", + "COLOR_ATTACHMENT4", + "COLOR_ATTACHMENT5", + "COLOR_ATTACHMENT6", + "COLOR_ATTACHMENT7", + "COLOR_ATTACHMENT8", + "COLOR_ATTACHMENT9", + "COMPARE_REF_TO_TEXTURE", + "COMPRESSED_R11_EAC", + "COMPRESSED_RG11_EAC", + "COMPRESSED_RGB8_ETC2", + "COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2", + "COMPRESSED_RGBA8_ETC2_EAC", + "COMPRESSED_SIGNED_R11_EAC", + "COMPRESSED_SIGNED_RG11_EAC", + "COMPRESSED_SRGB8_ALPHA8_ETC2_EAC", + "COMPRESSED_SRGB8_ETC2", + "COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2", + "CONDITION_SATISFIED", + "COPY_READ_BUFFER", + "COPY_READ_BUFFER_BINDING", + "COPY_WRITE_BUFFER", + "COPY_WRITE_BUFFER_BINDING", + "CURRENT_QUERY", + "DEPTH", + "DEPTH24_STENCIL8", + "DEPTH32F_STENCIL8", + "DEPTH_COMPONENT24", + "DEPTH_COMPONENT32F", + "DEPTH_STENCIL", + "DEPTH_STENCIL_ATTACHMENT", + "DRAW_BUFFER0", + "DRAW_BUFFER10", + "DRAW_BUFFER1", + "DRAW_BUFFER11", + "DRAW_BUFFER12", + "DRAW_BUFFER13", + "DRAW_BUFFER14", + "DRAW_BUFFER15", + "DRAW_BUFFER2", + "DRAW_BUFFER3", + "DRAW_BUFFER4", + "DRAW_BUFFER5", + "DRAW_BUFFER6", + "DRAW_BUFFER7", + "DRAW_BUFFER8", + "DRAW_BUFFER9", + "DRAW_FRAMEBUFFER", + "DRAW_FRAMEBUFFER_BINDING", + "DYNAMIC_COPY", + "DYNAMIC_READ", + "FLOAT_32_UNSIGNED_INT_24_8_REV", + "FLOAT_MAT2x3", + "FLOAT_MAT2x4", + "FLOAT_MAT3x2", + "FLOAT_MAT3x4", + "FLOAT_MAT4x2", + "FLOAT_MAT4x3", + "FRAGMENT_SHADER_DERIVATIVE_HINT", + "FRAMEBUFFER_ATTACHMENT_ALPHA_SIZE", + "FRAMEBUFFER_ATTACHMENT_BLUE_SIZE", + "FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING", + "FRAMEBUFFER_ATTACHMENT_COMPONENT_TYPE", + "FRAMEBUFFER_ATTACHMENT_DEPTH_SIZE", + "FRAMEBUFFER_ATTACHMENT_GREEN_SIZE", + "FRAMEBUFFER_ATTACHMENT_RED_SIZE", + "FRAMEBUFFER_ATTACHMENT_STENCIL_SIZE", + "FRAMEBUFFER_ATTACHMENT_TEXTURE_LAYER", + "FRAMEBUFFER_DEFAULT", + "FRAMEBUFFER_INCOMPLETE_MULTISAMPLE", + "FRAMEBUFFER_UNDEFINED", + "GREEN", + "HALF_FLOAT", + "INT_2_10_10_10_REV", + "INTERLEAVED_ATTRIBS", + "INT_SAMPLER_2D", + "INT_SAMPLER_2D_ARRAY", + "INT_SAMPLER_3D", + "INT_SAMPLER_CUBE", + "INVALID_INDEX", + "MAJOR_VERSION", + "MAP_FLUSH_EXPLICIT_BIT", + "MAP_INVALIDATE_BUFFER_BIT", + "MAP_INVALIDATE_RANGE_BIT", + "MAP_READ_BIT", + "MAP_UNSYNCHRONIZED_BIT", + "MAP_WRITE_BIT", + "MAX", + "MAX_3D_TEXTURE_SIZE", + "MAX_ARRAY_TEXTURE_LAYERS", + "MAX_COLOR_ATTACHMENTS", + "MAX_COMBINED_FRAGMENT_UNIFORM_COMPONENTS", + "MAX_COMBINED_UNIFORM_BLOCKS", + "MAX_COMBINED_VERTEX_UNIFORM_COMPONENTS", + "MAX_DRAW_BUFFERS", + "MAX_ELEMENT_INDEX", + "MAX_ELEMENTS_INDICES", + "MAX_ELEMENTS_VERTICES", + "MAX_FRAGMENT_INPUT_COMPONENTS", + "MAX_FRAGMENT_UNIFORM_BLOCKS", + "MAX_FRAGMENT_UNIFORM_COMPONENTS", + "MAX_PROGRAM_TEXEL_OFFSET", + "MAX_SAMPLES", + "MAX_SERVER_WAIT_TIMEOUT", + "MAX_TEXTURE_LOD_BIAS", + "MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS", + "MAX_TRANSFORM_FEEDBACK_SEPARATE_ATTRIBS", + "MAX_TRANSFORM_FEEDBACK_SEPARATE_COMPONENTS", + "MAX_UNIFORM_BLOCK_SIZE", + "MAX_UNIFORM_BUFFER_BINDINGS", + "MAX_VARYING_COMPONENTS", + "MAX_VERTEX_OUTPUT_COMPONENTS", + "MAX_VERTEX_UNIFORM_BLOCKS", + "MAX_VERTEX_UNIFORM_COMPONENTS", + "MIN", + "MINOR_VERSION", + "MIN_PROGRAM_TEXEL_OFFSET", + "NUM_EXTENSIONS", + "NUM_PROGRAM_BINARY_FORMATS", + "NUM_SAMPLE_COUNTS", + "OBJECT_TYPE", + "PACK_ROW_LENGTH", + "PACK_SKIP_PIXELS", + "PACK_SKIP_ROWS", + "PIXEL_PACK_BUFFER", + "PIXEL_PACK_BUFFER_BINDING", + "PIXEL_UNPACK_BUFFER", + "PIXEL_UNPACK_BUFFER_BINDING", + "PRIMITIVE_RESTART_FIXED_INDEX", + "PROGRAM_BINARY_FORMATS", + "PROGRAM_BINARY_LENGTH", + "PROGRAM_BINARY_RETRIEVABLE_HINT", + "QUERY_RESULT", + "QUERY_RESULT_AVAILABLE", + "R11F_G11F_B10F", + "R16F", + "R16I", + "R16UI", + "R32F", + "R32I", + "R32UI", + "R8", + "R8I", + "R8_SNORM", + "R8UI", + "RASTERIZER_DISCARD", + "READ_BUFFER", + "READ_FRAMEBUFFER", + "READ_FRAMEBUFFER_BINDING", + "RED", + "RED_INTEGER", + "RENDERBUFFER_SAMPLES", + "RG", + "RG16F", + "RG16I", + "RG16UI", + "RG32F", + "RG32I", + "RG32UI", + "RG8", + "RG8I", + "RG8_SNORM", + "RG8UI", + "RGB10_A2", + "RGB10_A2UI", + "RGB16F", + "RGB16I", + "RGB16UI", + "RGB32F", + "RGB32I", + "RGB32UI", + "RGB8", + "RGB8I", + "RGB8_SNORM", + "RGB8UI", + "RGB9_E5", + "RGBA16F", + "RGBA16I", + "RGBA16UI", + "RGBA32F", + "RGBA32I", + "RGBA32UI", + "RGBA8", + "RGBA8I", + "RGBA8_SNORM", + "RGBA8UI", + "RGBA_INTEGER", + "RGB_INTEGER", + "RG_INTEGER", + "SAMPLER_2D_ARRAY", + "SAMPLER_2D_ARRAY_SHADOW", + "SAMPLER_2D_SHADOW", + "SAMPLER_3D", + "SAMPLER_BINDING", + "SAMPLER_CUBE_SHADOW", + "SEPARATE_ATTRIBS", + "SIGNALED", + "SIGNED_NORMALIZED", + "SRGB", + "SRGB8", + "SRGB8_ALPHA8", + "STATIC_COPY", + "STATIC_READ", + "STENCIL", + "STREAM_COPY", + "STREAM_READ", + "SYNC_CONDITION", + "SYNC_FENCE", + "SYNC_FLAGS", + "SYNC_FLUSH_COMMANDS_BIT", + "SYNC_GPU_COMMANDS_COMPLETE", + "SYNC_STATUS", + "TEXTURE_2D_ARRAY", + "TEXTURE_3D", + "TEXTURE_BASE_LEVEL", + "TEXTURE_BINDING_2D_ARRAY", + "TEXTURE_BINDING_3D", + "TEXTURE_COMPARE_FUNC", + "TEXTURE_COMPARE_MODE", + "TEXTURE_IMMUTABLE_FORMAT", + "TEXTURE_IMMUTABLE_LEVELS", + "TEXTURE_MAX_LEVEL", + "TEXTURE_MAX_LOD", + "TEXTURE_MIN_LOD", + "TEXTURE_SWIZZLE_A", + "TEXTURE_SWIZZLE_B", + "TEXTURE_SWIZZLE_G", + "TEXTURE_SWIZZLE_R", + "TEXTURE_WRAP_R", + "TIMEOUT_EXPIRED", + "TRANSFORM_FEEDBACK", + "TRANSFORM_FEEDBACK_ACTIVE", + "TRANSFORM_FEEDBACK_BINDING", + "TRANSFORM_FEEDBACK_BUFFER", + "TRANSFORM_FEEDBACK_BUFFER_BINDING", + "TRANSFORM_FEEDBACK_BUFFER_MODE", + "TRANSFORM_FEEDBACK_BUFFER_SIZE", + "TRANSFORM_FEEDBACK_BUFFER_START", + "TRANSFORM_FEEDBACK_PAUSED", + "TRANSFORM_FEEDBACK_PRIMITIVES_WRITTEN", + "TRANSFORM_FEEDBACK_VARYING_MAX_LENGTH", + "TRANSFORM_FEEDBACK_VARYINGS", + "UNIFORM_ARRAY_STRIDE", + "UNIFORM_BLOCK_ACTIVE_UNIFORM_INDICES", + "UNIFORM_BLOCK_ACTIVE_UNIFORMS", + "UNIFORM_BLOCK_BINDING", + "UNIFORM_BLOCK_DATA_SIZE", + "UNIFORM_BLOCK_INDEX", + "UNIFORM_BLOCK_NAME_LENGTH", + "UNIFORM_BLOCK_REFERENCED_BY_FRAGMENT_SHADER", + "UNIFORM_BLOCK_REFERENCED_BY_VERTEX_SHADER", + "UNIFORM_BUFFER", + "UNIFORM_BUFFER_BINDING", + "UNIFORM_BUFFER_OFFSET_ALIGNMENT", + "UNIFORM_BUFFER_SIZE", + "UNIFORM_BUFFER_START", + "UNIFORM_IS_ROW_MAJOR", + "UNIFORM_MATRIX_STRIDE", + "UNIFORM_NAME_LENGTH", + "UNIFORM_OFFSET", + "UNIFORM_SIZE", + "UNIFORM_TYPE", + "UNPACK_IMAGE_HEIGHT", + "UNPACK_ROW_LENGTH", + "UNPACK_SKIP_IMAGES", + "UNPACK_SKIP_PIXELS", + "UNPACK_SKIP_ROWS", + "UNSIGNALED", + "UNSIGNED_INT_10F_11F_11F_REV", + "UNSIGNED_INT_2_10_10_10_REV", + "UNSIGNED_INT_24_8", + "UNSIGNED_INT_5_9_9_9_REV", + "UNSIGNED_INT_SAMPLER_2D", + "UNSIGNED_INT_SAMPLER_2D_ARRAY", + "UNSIGNED_INT_SAMPLER_3D", + "UNSIGNED_INT_SAMPLER_CUBE", + "UNSIGNED_INT_VEC2", + "UNSIGNED_INT_VEC3", + "UNSIGNED_INT_VEC4", + "UNSIGNED_NORMALIZED", + "VERTEX_ARRAY_BINDING", + "VERTEX_ATTRIB_ARRAY_DIVISOR", + "VERTEX_ATTRIB_ARRAY_INTEGER", + "WAIT_FAILED", +} + var outfile = flag.String("o", "", "result will be written to the file instead of stdout.") var fset = new(token.FileSet) @@ -273,10 +881,10 @@ const preamble = `// Copyright 2014 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Generated from gl.go using go generate. DO NOT EDIT. +// Code generated from gl.go using go generate. DO NOT EDIT. // See doc.go for details. -// +build linux darwin windows +// +build linux darwin windows openbsd // +build gldebug package gl @@ -325,9 +933,18 @@ type entry struct { value uint64 } +func genWhitelistMap(whitelist []string) map[string]bool { + m := make(map[string]bool) + for _, v := range enumWhitelist { + m[v] = true + } + return m +} + // enum builds a list of all GL constants that make up the gl.Enum type. func enum(f *ast.File) []entry { var entries []entry + whitelist := genWhitelistMap(enumWhitelist) for _, d := range f.Decls { gendecl, ok := d.(*ast.GenDecl) if !ok { @@ -344,6 +961,9 @@ func enum(f *ast.File) []entry { if len(v.Names) != 1 || len(v.Values) != 1 { continue } + if _, ok := whitelist[v.Names[0].Name]; !ok { + continue + } val, err := strconv.ParseUint(v.Values[0].(*ast.BasicLit).Value, 0, 64) if err != nil { log.Fatalf("enum %s: %v", v.Names[0].Name, err) diff --git a/vendor/golang.org/x/mobile/gl/gl.go b/vendor/golang.org/x/mobile/gl/gl.go index b4215de..bc67a90 100644 --- a/vendor/golang.org/x/mobile/gl/gl.go +++ b/vendor/golang.org/x/mobile/gl/gl.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build linux darwin windows +// +build linux darwin windows openbsd // +build !gldebug package gl @@ -90,6 +90,15 @@ func (ctx *context) BindTexture(target Enum, t Texture) { }) } +func (ctx *context) BindVertexArray(va VertexArray) { + ctx.enqueue(call{ + args: fnargs{ + fn: glfnBindVertexArray, + a0: va.c(), + }, + }) +} + func (ctx *context) BlendColor(red, green, blue, alpha float32) { ctx.enqueue(call{ args: fnargs{ @@ -380,6 +389,15 @@ func (ctx *context) CreateTexture() Texture { }))} } +func (ctx *context) CreateVertexArray() VertexArray { + return VertexArray{Value: uint32(ctx.enqueue(call{ + args: fnargs{ + fn: glfnGenVertexArray, + }, + blocking: true, + }))} +} + func (ctx *context) CullFace(mode Enum) { ctx.enqueue(call{ args: fnargs{ @@ -393,7 +411,7 @@ func (ctx *context) DeleteBuffer(v Buffer) { ctx.enqueue(call{ args: fnargs{ fn: glfnDeleteBuffer, - a0: uintptr(v.Value), + a0: v.c(), }, }) } @@ -402,7 +420,7 @@ func (ctx *context) DeleteFramebuffer(v Framebuffer) { ctx.enqueue(call{ args: fnargs{ fn: glfnDeleteFramebuffer, - a0: uintptr(v.Value), + a0: v.c(), }, }) } @@ -443,6 +461,15 @@ func (ctx *context) DeleteTexture(v Texture) { }) } +func (ctx *context) DeleteVertexArray(v VertexArray) { + ctx.enqueue(call{ + args: fnargs{ + fn: glfnDeleteVertexArray, + a0: v.c(), + }, + }) +} + func (ctx *context) DepthFunc(fn Enum) { ctx.enqueue(call{ args: fnargs{ @@ -1230,7 +1257,7 @@ func (ctx *context) StencilOpSeparate(face, sfail, dpfail, dppass Enum) { }) } -func (ctx *context) TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum, data []byte) { +func (ctx *context) TexImage2D(target Enum, level int, internalFormat int, width, height int, format Enum, ty Enum, data []byte) { // It is common to pass TexImage2D a nil data, indicating that a // bound GL buffer is being used as the source. In that case, it // is not necessary to block. @@ -1245,7 +1272,7 @@ func (ctx *context) TexImage2D(target Enum, level int, width, height int, format // TODO(crawshaw): GLES3 offset for PIXEL_UNPACK_BUFFER and PIXEL_PACK_BUFFER. a0: target.c(), a1: uintptr(level), - a2: uintptr(format), + a2: uintptr(internalFormat), a3: uintptr(width), a4: uintptr(height), a5: format.c(), diff --git a/vendor/golang.org/x/mobile/gl/gldebug.go b/vendor/golang.org/x/mobile/gl/gldebug.go index 6cb6fba..a5ab1b5 100644 --- a/vendor/golang.org/x/mobile/gl/gldebug.go +++ b/vendor/golang.org/x/mobile/gl/gldebug.go @@ -2,10 +2,10 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// Generated from gl.go using go generate. DO NOT EDIT. +// Code generated from gl.go using go generate. DO NOT EDIT. // See doc.go for details. -// +build linux darwin windows +// +build linux darwin windows openbsd // +build gldebug package gl @@ -1123,8 +1123,6 @@ func (v Enum) String() string { return "TEXTURE_WRAP_R" case 0x911b: return "TIMEOUT_EXPIRED" - case 0xffffffffffffffff: - return "TIMEOUT_IGNORED" case 0x8e22: return "TRANSFORM_FEEDBACK" case 0x8e24: @@ -1339,6 +1337,19 @@ func (ctx *context) BindTexture(target Enum, t Texture) { blocking: true}) } +func (ctx *context) BindVertexArray(va VertexArray) { + defer func() { + errstr := ctx.errDrain() + log.Printf("gl.BindVertexArray(%v) %v", va, errstr) + }() + ctx.enqueueDebug(call{ + args: fnargs{ + fn: glfnBindVertexArray, + a0: va.c(), + }, + blocking: true}) +} + func (ctx *context) BlendColor(red, green, blue, alpha float32) { defer func() { errstr := ctx.errDrain() @@ -1729,6 +1740,19 @@ func (ctx *context) CreateTexture() (r0 Texture) { }))} } +func (ctx *context) CreateVertexArray() (r0 VertexArray) { + defer func() { + errstr := ctx.errDrain() + log.Printf("gl.CreateVertexArray() %v%v", r0, errstr) + }() + return VertexArray{Value: uint32(ctx.enqueue(call{ + args: fnargs{ + fn: glfnGenVertexArray, + }, + blocking: true, + }))} +} + func (ctx *context) CullFace(mode Enum) { defer func() { errstr := ctx.errDrain() @@ -1750,7 +1774,7 @@ func (ctx *context) DeleteBuffer(v Buffer) { ctx.enqueueDebug(call{ args: fnargs{ fn: glfnDeleteBuffer, - a0: uintptr(v.Value), + a0: v.c(), }, blocking: true}) } @@ -1763,7 +1787,7 @@ func (ctx *context) DeleteFramebuffer(v Framebuffer) { ctx.enqueueDebug(call{ args: fnargs{ fn: glfnDeleteFramebuffer, - a0: uintptr(v.Value), + a0: v.c(), }, blocking: true}) } @@ -1820,6 +1844,19 @@ func (ctx *context) DeleteTexture(v Texture) { blocking: true}) } +func (ctx *context) DeleteVertexArray(v VertexArray) { + defer func() { + errstr := ctx.errDrain() + log.Printf("gl.DeleteVertexArray(%v) %v", v, errstr) + }() + ctx.enqueueDebug(call{ + args: fnargs{ + fn: glfnDeleteVertexArray, + a0: v.c(), + }, + blocking: true}) +} + func (ctx *context) DepthFunc(fn Enum) { defer func() { errstr := ctx.errDrain() @@ -2861,10 +2898,10 @@ func (ctx *context) StencilOpSeparate(face, sfail, dpfail, dppass Enum) { blocking: true}) } -func (ctx *context) TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum, data []byte) { +func (ctx *context) TexImage2D(target Enum, level int, internalFormat int, width, height int, format Enum, ty Enum, data []byte) { defer func() { errstr := ctx.errDrain() - log.Printf("gl.TexImage2D(%v, %v, %v, %v, %v, %v, len(%d)) %v", target, level, width, height, format, ty, len(data), errstr) + log.Printf("gl.TexImage2D(%v, %v, %v, %v, %v, %v, %v, len(%d)) %v", target, level, internalFormat, width, height, format, ty, len(data), errstr) }() parg := unsafe.Pointer(nil) if len(data) > 0 { @@ -2876,7 +2913,7 @@ func (ctx *context) TexImage2D(target Enum, level int, width, height int, format a0: target.c(), a1: uintptr(level), - a2: uintptr(format), + a2: uintptr(internalFormat), a3: uintptr(width), a4: uintptr(height), a5: format.c(), diff --git a/vendor/golang.org/x/mobile/gl/interface.go b/vendor/golang.org/x/mobile/gl/interface.go index 8c93954..189c29e 100644 --- a/vendor/golang.org/x/mobile/gl/interface.go +++ b/vendor/golang.org/x/mobile/gl/interface.go @@ -56,6 +56,11 @@ type Context interface { // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindTexture.xhtml BindTexture(target Enum, t Texture) + // BindVertexArray binds a vertex array. + // + // http://www.khronos.org/opengles/sdk/docs/man3/html/glBindVertexArray.xhtml + BindVertexArray(rb VertexArray) + // BlendColor sets the blend color. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glBlendColor.xhtml @@ -187,6 +192,11 @@ type Context interface { // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenTextures.xhtml CreateTexture() Texture + // CreateTVertexArray creates a vertex array. + // + // http://www.khronos.org/opengles/sdk/docs/man3/html/glGenVertexArrays.xhtml + CreateVertexArray() VertexArray + // CullFace specifies which polygons are candidates for culling. // // Valid modes: FRONT, BACK, FRONT_AND_BACK. @@ -224,6 +234,11 @@ type Context interface { // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteTextures.xhtml DeleteTexture(v Texture) + // DeleteVertexArray deletes the given render buffer object. + // + // http://www.khronos.org/opengles/sdk/docs/man3/html/glDeleteVertexArrays.xhtml + DeleteVertexArray(v VertexArray) + // DepthFunc sets the function used for depth buffer comparisons. // // Valid fn values: @@ -612,7 +627,7 @@ type Context interface { // TexImage2D writes a 2D texture image. // // http://www.khronos.org/opengles/sdk/docs/man3/html/glTexImage2D.xhtml - TexImage2D(target Enum, level int, width, height int, format Enum, ty Enum, data []byte) + TexImage2D(target Enum, level int, internalFormat int, width, height int, format Enum, ty Enum, data []byte) // TexSubImage2D writes a subregion of a 2D texture image. // diff --git a/vendor/golang.org/x/mobile/gl/types_debug.go b/vendor/golang.org/x/mobile/gl/types_debug.go index dc251a0..f5a888e 100644 --- a/vendor/golang.org/x/mobile/gl/types_debug.go +++ b/vendor/golang.org/x/mobile/gl/types_debug.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build linux darwin windows +// +build linux darwin windows openbsd // +build gldebug package gl @@ -49,6 +49,10 @@ type Uniform struct { name string } +type VertexArray struct { + Value uint32 +} + func (v Attrib) c() uintptr { return uintptr(v.Value) } func (v Enum) c() uintptr { return uintptr(v) } func (v Program) c() uintptr { @@ -65,6 +69,7 @@ func (v Framebuffer) c() uintptr { return uintptr(v.Value) } func (v Renderbuffer) c() uintptr { return uintptr(v.Value) } func (v Texture) c() uintptr { return uintptr(v.Value) } func (v Uniform) c() uintptr { return uintptr(v.Value) } +func (v VertexArray) c() uintptr { return uintptr(v.Value) } func (v Attrib) String() string { return fmt.Sprintf("Attrib(%d:%s)", v.Value, v.name) } func (v Program) String() string { return fmt.Sprintf("Program(%d)", v.Value) } @@ -74,3 +79,4 @@ func (v Framebuffer) String() string { return fmt.Sprintf("Framebuffer(%d)", v. func (v Renderbuffer) String() string { return fmt.Sprintf("Renderbuffer(%d)", v.Value) } func (v Texture) String() string { return fmt.Sprintf("Texture(%d)", v.Value) } func (v Uniform) String() string { return fmt.Sprintf("Uniform(%d:%s)", v.Value, v.name) } +func (v VertexArray) String() string { return fmt.Sprintf("VertexArray(%d)", v.Value) } diff --git a/vendor/golang.org/x/mobile/gl/types_prod.go b/vendor/golang.org/x/mobile/gl/types_prod.go index 35dc4c6..716116e 100644 --- a/vendor/golang.org/x/mobile/gl/types_prod.go +++ b/vendor/golang.org/x/mobile/gl/types_prod.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build linux darwin windows +// +build linux darwin windows openbsd // +build !gldebug package gl @@ -59,6 +59,11 @@ type Uniform struct { Value int32 } +// A VertexArray is a GL object that holds vertices in an internal format. +type VertexArray struct { + Value uint32 +} + func (v Attrib) c() uintptr { return uintptr(v.Value) } func (v Enum) c() uintptr { return uintptr(v) } func (v Program) c() uintptr { @@ -75,6 +80,7 @@ func (v Framebuffer) c() uintptr { return uintptr(v.Value) } func (v Renderbuffer) c() uintptr { return uintptr(v.Value) } func (v Texture) c() uintptr { return uintptr(v.Value) } func (v Uniform) c() uintptr { return uintptr(v.Value) } +func (v VertexArray) c() uintptr { return uintptr(v.Value) } func (v Attrib) String() string { return fmt.Sprintf("Attrib(%d)", v.Value) } func (v Program) String() string { return fmt.Sprintf("Program(%d)", v.Value) } @@ -84,3 +90,4 @@ func (v Framebuffer) String() string { return fmt.Sprintf("Framebuffer(%d)", v. func (v Renderbuffer) String() string { return fmt.Sprintf("Renderbuffer(%d)", v.Value) } func (v Texture) String() string { return fmt.Sprintf("Texture(%d)", v.Value) } func (v Uniform) String() string { return fmt.Sprintf("Uniform(%d)", v.Value) } +func (v VertexArray) String() string { return fmt.Sprintf("VertexArray(%d)", v.Value) } diff --git a/vendor/golang.org/x/mobile/gl/work.c b/vendor/golang.org/x/mobile/gl/work.c index 75380d0..7203acf 100644 --- a/vendor/golang.org/x/mobile/gl/work.c +++ b/vendor/golang.org/x/mobile/gl/work.c @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin linux +// +build darwin linux openbsd #include #include "_cgo_export.h" @@ -30,6 +30,9 @@ static void glUniform1uiv(GLint location, GLsizei count, const GLuint *value) { static void glUniform2uiv(GLint location, GLsizei count, const GLuint *value) { gles3missing(); } static void glUniform3uiv(GLint location, GLsizei count, const GLuint *value) { gles3missing(); } static void glUniform4uiv(GLint location, GLsizei count, const GLuint *value) { gles3missing(); } +static void glBindVertexArray(GLuint array) { gles3missing(); } +static void glGenVertexArrays(GLsizei n, GLuint *arrays) { gles3missing(); } +static void glDeleteVertexArrays(GLsizei n, const GLuint *arrays) { gles3missing(); } #endif uintptr_t processFn(struct fnargs* args, char* parg) { @@ -59,6 +62,9 @@ uintptr_t processFn(struct fnargs* args, char* parg) { case glfnBindTexture: glBindTexture((GLenum)args->a0, (GLint)args->a1); break; + case glfnBindVertexArray: + glBindVertexArray((GLenum)args->a0); + break; case glfnBlendColor: glBlendColor(*(GLfloat*)&args->a0, *(GLfloat*)&args->a1, *(GLfloat*)&args->a2, *(GLfloat*)&args->a3); break; @@ -143,6 +149,9 @@ uintptr_t processFn(struct fnargs* args, char* parg) { case glfnDeleteTexture: glDeleteTextures(1, (const GLuint*)(&args->a0)); break; + case glfnDeleteVertexArray: + glDeleteVertexArrays(1, (const GLuint*)(&args->a0)); + break; case glfnDepthFunc: glDepthFunc((GLenum)args->a0); break; @@ -200,6 +209,9 @@ uintptr_t processFn(struct fnargs* args, char* parg) { case glfnGenTexture: glGenTextures(1, (GLuint*)&ret); break; + case glfnGenVertexArray: + glGenVertexArrays(1, (GLuint*)&ret); + break; case glfnGenerateMipmap: glGenerateMipmap((GLenum)args->a0); break; diff --git a/vendor/golang.org/x/mobile/gl/work.go b/vendor/golang.org/x/mobile/gl/work.go index 574b03b..9f340c1 100644 --- a/vendor/golang.org/x/mobile/gl/work.go +++ b/vendor/golang.org/x/mobile/gl/work.go @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// +build darwin linux +// +build darwin linux openbsd package gl @@ -12,13 +12,18 @@ package gl #cgo darwin,arm LDFLAGS: -framework OpenGLES #cgo darwin,arm64 LDFLAGS: -framework OpenGLES #cgo linux LDFLAGS: -lGLESv2 +#cgo openbsd LDFLAGS: -L/usr/X11R6/lib/ -lGLESv2 #cgo android CFLAGS: -Dos_android #cgo ios CFLAGS: -Dos_ios #cgo darwin,amd64,!ios CFLAGS: -Dos_osx #cgo darwin,arm CFLAGS: -Dos_ios #cgo darwin,arm64 CFLAGS: -Dos_ios +#cgo darwin CFLAGS: -DGL_SILENCE_DEPRECATION #cgo linux CFLAGS: -Dos_linux +#cgo openbsd CFLAGS: -Dos_openbsd + +#cgo openbsd CFLAGS: -I/usr/X11R6/include/ #include #include "work.h" diff --git a/vendor/golang.org/x/mobile/gl/work.h b/vendor/golang.org/x/mobile/gl/work.h index 9ba29ca..cc2e48c 100644 --- a/vendor/golang.org/x/mobile/gl/work.h +++ b/vendor/golang.org/x/mobile/gl/work.h @@ -10,6 +10,8 @@ #include #elif os_linux #include // install on Ubuntu with: sudo apt-get install libegl1-mesa-dev libgles2-mesa-dev libx11-dev +#elif os_openbsd +#include #endif #ifdef os_ios @@ -41,6 +43,7 @@ typedef enum { glfnBindFramebuffer, glfnBindRenderbuffer, glfnBindTexture, + glfnBindVertexArray, glfnBlendColor, glfnBlendEquation, glfnBlendEquationSeparate, @@ -68,6 +71,7 @@ typedef enum { glfnDeleteRenderbuffer, glfnDeleteShader, glfnDeleteTexture, + glfnDeleteVertexArray, glfnDepthFunc, glfnDepthRangef, glfnDepthMask, @@ -87,6 +91,7 @@ typedef enum { glfnGenFramebuffer, glfnGenRenderbuffer, glfnGenTexture, + glfnGenVertexArray, glfnGenerateMipmap, glfnGetActiveAttrib, glfnGetActiveUniform, diff --git a/vendor/golang.org/x/mobile/gl/work_windows.go b/vendor/golang.org/x/mobile/gl/work_windows.go index 9c97213..4119ac6 100644 --- a/vendor/golang.org/x/mobile/gl/work_windows.go +++ b/vendor/golang.org/x/mobile/gl/work_windows.go @@ -128,6 +128,8 @@ func (ctx *context) doWork(c call) (ret uintptr) { syscall.Syscall(glBindRenderbuffer.Addr(), 2, c.args.a0, c.args.a1, 0) case glfnBindTexture: syscall.Syscall(glBindTexture.Addr(), 2, c.args.a0, c.args.a1, 0) + case glfnBindVertexArray: + syscall.Syscall(glBindVertexArray.Addr(), 1, c.args.a0, 0, 0) case glfnBlendColor: syscall.Syscall6(glBlendColor.Addr(), 4, c.args.a0, c.args.a1, c.args.a2, c.args.a3, 0, 0) case glfnBlendEquation: @@ -180,6 +182,8 @@ func (ctx *context) doWork(c call) (ret uintptr) { syscall.Syscall(glDeleteRenderbuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&c.args.a0)), 0) case glfnDeleteShader: syscall.Syscall(glDeleteShader.Addr(), 1, c.args.a0, 0, 0) + case glfnDeleteVertexArray: + syscall.Syscall(glDeleteVertexArrays.Addr(), 2, 1, uintptr(unsafe.Pointer(&c.args.a0)), 0) case glfnDeleteTexture: syscall.Syscall(glDeleteTextures.Addr(), 2, 1, uintptr(unsafe.Pointer(&c.args.a0)), 0) case glfnDepthFunc: @@ -218,6 +222,8 @@ func (ctx *context) doWork(c call) (ret uintptr) { syscall.Syscall(glGenFramebuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&ret)), 0) case glfnGenRenderbuffer: syscall.Syscall(glGenRenderbuffers.Addr(), 2, 1, uintptr(unsafe.Pointer(&ret)), 0) + case glfnGenVertexArray: + syscall.Syscall(glGenVertexArrays.Addr(), 2, 1, uintptr(unsafe.Pointer(&ret)), 0) case glfnGenTexture: syscall.Syscall(glGenTextures.Addr(), 2, 1, uintptr(unsafe.Pointer(&ret)), 0) case glfnGenerateMipmap: @@ -389,7 +395,7 @@ func (ctx *context) doWork(c call) (ret uintptr) { case glfnVertexAttrib3fv: syscall.Syscall(glVertexAttrib3fv.Addr(), 2, c.args.a0, uintptr(c.parg), 0) case glfnVertexAttrib4f: - syscall.Syscall6(glVertexAttrib3f.Addr(), 5, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) + syscall.Syscall6(glVertexAttrib4f.Addr(), 5, c.args.a0, c.args.a1, c.args.a2, c.args.a3, c.args.a4, c.args.a5) case glfnVertexAttrib4fv: syscall.Syscall(glVertexAttrib4fv.Addr(), 2, c.args.a0, uintptr(c.parg), 0) case glfnVertexAttribPointer: @@ -424,6 +430,7 @@ var ( glBindFramebuffer = libGLESv2.NewProc("glBindFramebuffer") glBindRenderbuffer = libGLESv2.NewProc("glBindRenderbuffer") glBindTexture = libGLESv2.NewProc("glBindTexture") + glBindVertexArray = libGLESv2.NewProc("glBindVertexArray") glBlendColor = libGLESv2.NewProc("glBlendColor") glBlendEquation = libGLESv2.NewProc("glBlendEquation") glBlendEquationSeparate = libGLESv2.NewProc("glBlendEquationSeparate") @@ -451,6 +458,7 @@ var ( glDeleteRenderbuffers = libGLESv2.NewProc("glDeleteRenderbuffers") glDeleteShader = libGLESv2.NewProc("glDeleteShader") glDeleteTextures = libGLESv2.NewProc("glDeleteTextures") + glDeleteVertexArrays = libGLESv2.NewProc("glDeleteVertexArrays") glDepthFunc = libGLESv2.NewProc("glDepthFunc") glDepthRangef = libGLESv2.NewProc("glDepthRangef") glDepthMask = libGLESv2.NewProc("glDepthMask") @@ -470,6 +478,7 @@ var ( glGenFramebuffers = libGLESv2.NewProc("glGenFramebuffers") glGenRenderbuffers = libGLESv2.NewProc("glGenRenderbuffers") glGenTextures = libGLESv2.NewProc("glGenTextures") + glGenVertexArrays = libGLESv2.NewProc("glGenVertexArrays") glGenerateMipmap = libGLESv2.NewProc("glGenerateMipmap") glGetActiveAttrib = libGLESv2.NewProc("glGetActiveAttrib") glGetActiveUniform = libGLESv2.NewProc("glGetActiveUniform") diff --git a/vendor/golang.org/x/mobile/internal/mobileinit/ctx_android.go b/vendor/golang.org/x/mobile/internal/mobileinit/ctx_android.go new file mode 100644 index 0000000..b58881a --- /dev/null +++ b/vendor/golang.org/x/mobile/internal/mobileinit/ctx_android.go @@ -0,0 +1,124 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mobileinit + +/* +#include +#include + +static char* lockJNI(JavaVM *vm, uintptr_t* envp, int* attachedp) { + JNIEnv* env; + + if (vm == NULL) { + return "no current JVM"; + } + + *attachedp = 0; + switch ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6)) { + case JNI_OK: + break; + case JNI_EDETACHED: + if ((*vm)->AttachCurrentThread(vm, &env, 0) != 0) { + return "cannot attach to JVM"; + } + *attachedp = 1; + break; + case JNI_EVERSION: + return "bad JNI version"; + default: + return "unknown JNI error from GetEnv"; + } + + *envp = (uintptr_t)env; + return NULL; +} + +static char* checkException(uintptr_t jnienv) { + jthrowable exc; + JNIEnv* env = (JNIEnv*)jnienv; + + if (!(*env)->ExceptionCheck(env)) { + return NULL; + } + + exc = (*env)->ExceptionOccurred(env); + (*env)->ExceptionClear(env); + + jclass clazz = (*env)->FindClass(env, "java/lang/Throwable"); + jmethodID toString = (*env)->GetMethodID(env, clazz, "toString", "()Ljava/lang/String;"); + jobject msgStr = (*env)->CallObjectMethod(env, exc, toString); + return (char*)(*env)->GetStringUTFChars(env, msgStr, 0); +} + +static void unlockJNI(JavaVM *vm) { + (*vm)->DetachCurrentThread(vm); +} +*/ +import "C" + +import ( + "errors" + "runtime" + "unsafe" +) + +// currentVM is stored to initialize other cgo packages. +// +// As all the Go packages in a program form a single shared library, +// there can only be one JNI_OnLoad function for initialization. In +// OpenJDK there is JNI_GetCreatedJavaVMs, but this is not available +// on android. +var currentVM *C.JavaVM + +// currentCtx is Android's android.context.Context. May be NULL. +var currentCtx C.jobject + +// SetCurrentContext populates the global Context object with the specified +// current JavaVM instance (vm) and android.context.Context object (ctx). +// The android.context.Context object must be a global reference. +func SetCurrentContext(vm unsafe.Pointer, ctx uintptr) { + currentVM = (*C.JavaVM)(vm) + currentCtx = (C.jobject)(ctx) +} + +// RunOnJVM runs fn on a new goroutine locked to an OS thread with a JNIEnv. +// +// RunOnJVM blocks until the call to fn is complete. Any Java +// exception or failure to attach to the JVM is returned as an error. +// +// The function fn takes vm, the current JavaVM*, +// env, the current JNIEnv*, and +// ctx, a jobject representing the global android.context.Context. +func RunOnJVM(fn func(vm, env, ctx uintptr) error) error { + errch := make(chan error) + go func() { + runtime.LockOSThread() + defer runtime.UnlockOSThread() + + env := C.uintptr_t(0) + attached := C.int(0) + if errStr := C.lockJNI(currentVM, &env, &attached); errStr != nil { + errch <- errors.New(C.GoString(errStr)) + return + } + if attached != 0 { + defer C.unlockJNI(currentVM) + } + + vm := uintptr(unsafe.Pointer(currentVM)) + if err := fn(vm, uintptr(env), uintptr(currentCtx)); err != nil { + errch <- err + return + } + + if exc := C.checkException(env); exc != nil { + errch <- errors.New(C.GoString(exc)) + C.free(unsafe.Pointer(exc)) + return + } + errch <- nil + }() + return <-errch +} diff --git a/vendor/golang.org/x/mobile/internal/mobileinit/mobileinit.go b/vendor/golang.org/x/mobile/internal/mobileinit/mobileinit.go new file mode 100644 index 0000000..65c0912 --- /dev/null +++ b/vendor/golang.org/x/mobile/internal/mobileinit/mobileinit.go @@ -0,0 +1,11 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package mobileinit contains common initialization logic for mobile platforms +// that is relevant to both all-Go apps and gobind-based apps. +// +// Long-term, some code in this package should consider moving into Go stdlib. +package mobileinit + +import "C" diff --git a/vendor/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go b/vendor/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go new file mode 100644 index 0000000..cd73f43 --- /dev/null +++ b/vendor/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go @@ -0,0 +1,93 @@ +// Copyright 2014 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package mobileinit + +/* +To view the log output run: +adb logcat GoLog:I *:S +*/ + +// Android redirects stdout and stderr to /dev/null. +// As these are common debugging utilities in Go, +// we redirect them to logcat. +// +// Unfortunately, logcat is line oriented, so we must buffer. + +/* +#cgo LDFLAGS: -landroid -llog + +#include +#include +#include +*/ +import "C" + +import ( + "bufio" + "log" + "os" + "syscall" + "unsafe" +) + +var ( + ctag = C.CString("GoLog") + // Store the writer end of the redirected stderr and stdout + // so that they are not garbage collected and closed. + stderr, stdout *os.File +) + +type infoWriter struct{} + +func (infoWriter) Write(p []byte) (n int, err error) { + cstr := C.CString(string(p)) + C.__android_log_write(C.ANDROID_LOG_INFO, ctag, cstr) + C.free(unsafe.Pointer(cstr)) + return len(p), nil +} + +func lineLog(f *os.File, priority C.int) { + const logSize = 1024 // matches android/log.h. + r := bufio.NewReaderSize(f, logSize) + for { + line, _, err := r.ReadLine() + str := string(line) + if err != nil { + str += " " + err.Error() + } + cstr := C.CString(str) + C.__android_log_write(priority, ctag, cstr) + C.free(unsafe.Pointer(cstr)) + if err != nil { + break + } + } +} + +func init() { + log.SetOutput(infoWriter{}) + // android logcat includes all of log.LstdFlags + log.SetFlags(log.Flags() &^ log.LstdFlags) + + r, w, err := os.Pipe() + if err != nil { + panic(err) + } + stderr = w + if err := syscall.Dup3(int(w.Fd()), int(os.Stderr.Fd()), 0); err != nil { + panic(err) + } + go lineLog(r, C.ANDROID_LOG_ERROR) + + r, w, err = os.Pipe() + if err != nil { + panic(err) + } + stdout = w + if err := syscall.Dup3(int(w.Fd()), int(os.Stdout.Fd()), 0); err != nil { + panic(err) + } + go lineLog(r, C.ANDROID_LOG_INFO) +} diff --git a/vendor/golang.org/x/mobile/internal/mobileinit/mobileinit_ios.go b/vendor/golang.org/x/mobile/internal/mobileinit/mobileinit_ios.go new file mode 100644 index 0000000..dda9b0f --- /dev/null +++ b/vendor/golang.org/x/mobile/internal/mobileinit/mobileinit_ios.go @@ -0,0 +1,38 @@ +// Copyright 2015 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build darwin +// +build arm arm64 + +package mobileinit + +import ( + "io" + "log" + "os" + "unsafe" +) + +/* +#include +#include + +void asl_log_wrap(const char *str) { + asl_log(NULL, NULL, ASL_LEVEL_NOTICE, "%s", str); +} +*/ +import "C" + +type aslWriter struct{} + +func (aslWriter) Write(p []byte) (n int, err error) { + cstr := C.CString(string(p)) + C.asl_log_wrap(cstr) + C.free(unsafe.Pointer(cstr)) + return len(p), nil +} + +func init() { + log.SetOutput(io.MultiWriter(os.Stderr, aslWriter{})) +} diff --git a/vendor/golang.org/x/sys/windows/aliases.go b/vendor/golang.org/x/sys/windows/aliases.go new file mode 100644 index 0000000..af3af60 --- /dev/null +++ b/vendor/golang.org/x/sys/windows/aliases.go @@ -0,0 +1,13 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// +build windows +// +build go1.9 + +package windows + +import "syscall" + +type Errno = syscall.Errno +type SysProcAttr = syscall.SysProcAttr diff --git a/vendor/golang.org/x/sys/windows/asm_windows_386.s b/vendor/golang.org/x/sys/windows/asm_windows_386.s index 1c20dd2..21d994d 100644 --- a/vendor/golang.org/x/sys/windows/asm_windows_386.s +++ b/vendor/golang.org/x/sys/windows/asm_windows_386.s @@ -6,8 +6,8 @@ // System calls for 386, Windows are implemented in runtime/syscall_windows.goc // -TEXT ·getprocaddress(SB), 7, $0-8 +TEXT ·getprocaddress(SB), 7, $0-16 JMP syscall·getprocaddress(SB) -TEXT ·loadlibrary(SB), 7, $0-4 +TEXT ·loadlibrary(SB), 7, $0-12 JMP syscall·loadlibrary(SB) diff --git a/vendor/golang.org/x/sys/windows/asm_windows_amd64.s b/vendor/golang.org/x/sys/windows/asm_windows_amd64.s index 4d025ab..5bfdf79 100644 --- a/vendor/golang.org/x/sys/windows/asm_windows_amd64.s +++ b/vendor/golang.org/x/sys/windows/asm_windows_amd64.s @@ -9,5 +9,5 @@ TEXT ·getprocaddress(SB), 7, $0-32 JMP syscall·getprocaddress(SB) -TEXT ·loadlibrary(SB), 7, $0-8 +TEXT ·loadlibrary(SB), 7, $0-24 JMP syscall·loadlibrary(SB) diff --git a/vendor/golang.org/x/sys/windows/asm_windows_arm.s b/vendor/golang.org/x/sys/windows/asm_windows_arm.s new file mode 100644 index 0000000..55d8b91 --- /dev/null +++ b/vendor/golang.org/x/sys/windows/asm_windows_arm.s @@ -0,0 +1,11 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "textflag.h" + +TEXT ·getprocaddress(SB),NOSPLIT,$0 + B syscall·getprocaddress(SB) + +TEXT ·loadlibrary(SB),NOSPLIT,$0 + B syscall·loadlibrary(SB) diff --git a/vendor/golang.org/x/sys/windows/dll_windows.go b/vendor/golang.org/x/sys/windows/dll_windows.go index 0f62046..ba67658 100644 --- a/vendor/golang.org/x/sys/windows/dll_windows.go +++ b/vendor/golang.org/x/sys/windows/dll_windows.go @@ -1,4 +1,4 @@ -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -116,7 +116,7 @@ func (p *Proc) Addr() uintptr { //go:uintptrescapes -// Call executes procedure p with arguments a. It will panic, if more then 15 arguments +// Call executes procedure p with arguments a. It will panic, if more than 15 arguments // are supplied. // // The returned error is always non-nil, constructed from the result of GetLastError. @@ -160,7 +160,6 @@ func (p *Proc) Call(a ...uintptr) (r1, r2 uintptr, lastErr error) { default: panic("Call " + p.Name + " with too many arguments " + itoa(len(a)) + ".") } - return } // A LazyDLL implements access to a single DLL. @@ -290,6 +289,7 @@ func (p *LazyProc) mustFind() { // Addr returns the address of the procedure represented by p. // The return value can be passed to Syscall to run the procedure. +// It will panic if the procedure cannot be found. func (p *LazyProc) Addr() uintptr { p.mustFind() return p.proc.Addr() @@ -297,8 +297,8 @@ func (p *LazyProc) Addr() uintptr { //go:uintptrescapes -// Call executes procedure p with arguments a. It will panic, if more then 15 arguments -// are supplied. +// Call executes procedure p with arguments a. It will panic, if more than 15 arguments +// are supplied. It will also panic if the procedure cannot be found. // // The returned error is always non-nil, constructed from the result of GetLastError. // Callers must inspect the primary return value to decide whether an error occurred @@ -359,11 +359,11 @@ func loadLibraryEx(name string, system bool) (*DLL, error) { // trying to load "foo.dll" out of the system // folder, but LoadLibraryEx doesn't support // that yet on their system, so emulate it. - windir, _ := Getenv("WINDIR") // old var; apparently works on XP - if windir == "" { - return nil, errString("%WINDIR% not defined") + systemdir, err := GetSystemDirectory() + if err != nil { + return nil, err } - loadDLL = windir + "\\System32\\" + name + loadDLL = systemdir + "\\" + name } } h, err := LoadLibraryEx(loadDLL, 0, flags) diff --git a/vendor/golang.org/x/sys/windows/env_unset.go b/vendor/golang.org/x/sys/windows/env_unset.go deleted file mode 100644 index 4ed03ae..0000000 --- a/vendor/golang.org/x/sys/windows/env_unset.go +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2014 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// +build windows -// +build go1.4 - -package windows - -import "syscall" - -func Unsetenv(key string) error { - // This was added in Go 1.4. - return syscall.Unsetenv(key) -} diff --git a/vendor/golang.org/x/sys/windows/env_windows.go b/vendor/golang.org/x/sys/windows/env_windows.go index a9d8ef4..bdc71e2 100644 --- a/vendor/golang.org/x/sys/windows/env_windows.go +++ b/vendor/golang.org/x/sys/windows/env_windows.go @@ -1,4 +1,4 @@ -// Copyright 2010 The Go Authors. All rights reserved. +// Copyright 2010 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -23,3 +23,7 @@ func Clearenv() { func Environ() []string { return syscall.Environ() } + +func Unsetenv(key string) error { + return syscall.Unsetenv(key) +} diff --git a/vendor/golang.org/x/sys/windows/memory_windows.go b/vendor/golang.org/x/sys/windows/memory_windows.go new file mode 100644 index 0000000..f80a420 --- /dev/null +++ b/vendor/golang.org/x/sys/windows/memory_windows.go @@ -0,0 +1,26 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package windows + +const ( + MEM_COMMIT = 0x00001000 + MEM_RESERVE = 0x00002000 + MEM_DECOMMIT = 0x00004000 + MEM_RELEASE = 0x00008000 + MEM_RESET = 0x00080000 + MEM_TOP_DOWN = 0x00100000 + MEM_WRITE_WATCH = 0x00200000 + MEM_PHYSICAL = 0x00400000 + MEM_RESET_UNDO = 0x01000000 + MEM_LARGE_PAGES = 0x20000000 + + PAGE_NOACCESS = 0x01 + PAGE_READONLY = 0x02 + PAGE_READWRITE = 0x04 + PAGE_WRITECOPY = 0x08 + PAGE_EXECUTE_READ = 0x20 + PAGE_EXECUTE_READWRITE = 0x40 + PAGE_EXECUTE_WRITECOPY = 0x80 +) diff --git a/vendor/golang.org/x/sys/windows/mksyscall.go b/vendor/golang.org/x/sys/windows/mksyscall.go index e1c88c9..fb7db0e 100644 --- a/vendor/golang.org/x/sys/windows/mksyscall.go +++ b/vendor/golang.org/x/sys/windows/mksyscall.go @@ -1,4 +1,4 @@ -// Copyright 2009 The Go Authors. All rights reserved. +// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/vendor/golang.org/x/sys/windows/race.go b/vendor/golang.org/x/sys/windows/race.go index 343e18a..a74e3e2 100644 --- a/vendor/golang.org/x/sys/windows/race.go +++ b/vendor/golang.org/x/sys/windows/race.go @@ -1,4 +1,4 @@ -// Copyright 2012 The Go Authors. All rights reserved. +// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/vendor/golang.org/x/sys/windows/race0.go b/vendor/golang.org/x/sys/windows/race0.go index 17af843..e44a3cb 100644 --- a/vendor/golang.org/x/sys/windows/race0.go +++ b/vendor/golang.org/x/sys/windows/race0.go @@ -1,4 +1,4 @@ -// Copyright 2012 The Go Authors. All rights reserved. +// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/vendor/golang.org/x/sys/windows/security_windows.go b/vendor/golang.org/x/sys/windows/security_windows.go index ca09bdd..f5f2d8b 100644 --- a/vendor/golang.org/x/sys/windows/security_windows.go +++ b/vendor/golang.org/x/sys/windows/security_windows.go @@ -1,4 +1,4 @@ -// Copyright 2012 The Go Authors. All rights reserved. +// Copyright 2012 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -132,6 +132,36 @@ const ( SECURITY_NT_NON_UNIQUE_RID = 0x15 ) +// Predefined domain-relative RIDs for local groups. +// See https://msdn.microsoft.com/en-us/library/windows/desktop/aa379649(v=vs.85).aspx +const ( + DOMAIN_ALIAS_RID_ADMINS = 0x220 + DOMAIN_ALIAS_RID_USERS = 0x221 + DOMAIN_ALIAS_RID_GUESTS = 0x222 + DOMAIN_ALIAS_RID_POWER_USERS = 0x223 + DOMAIN_ALIAS_RID_ACCOUNT_OPS = 0x224 + DOMAIN_ALIAS_RID_SYSTEM_OPS = 0x225 + DOMAIN_ALIAS_RID_PRINT_OPS = 0x226 + DOMAIN_ALIAS_RID_BACKUP_OPS = 0x227 + DOMAIN_ALIAS_RID_REPLICATOR = 0x228 + DOMAIN_ALIAS_RID_RAS_SERVERS = 0x229 + DOMAIN_ALIAS_RID_PREW2KCOMPACCESS = 0x22a + DOMAIN_ALIAS_RID_REMOTE_DESKTOP_USERS = 0x22b + DOMAIN_ALIAS_RID_NETWORK_CONFIGURATION_OPS = 0x22c + DOMAIN_ALIAS_RID_INCOMING_FOREST_TRUST_BUILDERS = 0x22d + DOMAIN_ALIAS_RID_MONITORING_USERS = 0x22e + DOMAIN_ALIAS_RID_LOGGING_USERS = 0x22f + DOMAIN_ALIAS_RID_AUTHORIZATIONACCESS = 0x230 + DOMAIN_ALIAS_RID_TS_LICENSE_SERVERS = 0x231 + DOMAIN_ALIAS_RID_DCOM_USERS = 0x232 + DOMAIN_ALIAS_RID_IUSERS = 0x238 + DOMAIN_ALIAS_RID_CRYPTO_OPERATORS = 0x239 + DOMAIN_ALIAS_RID_CACHEABLE_PRINCIPALS_GROUP = 0x23b + DOMAIN_ALIAS_RID_NON_CACHEABLE_PRINCIPALS_GROUP = 0x23c + DOMAIN_ALIAS_RID_EVENT_LOG_READERS_GROUP = 0x23d + DOMAIN_ALIAS_RID_CERTSVC_DCOM_ACCESS_GROUP = 0x23e +) + //sys LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) = advapi32.LookupAccountSidW //sys LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen *uint32, refdDomainName *uint16, refdDomainNameLen *uint32, use *uint32) (err error) = advapi32.LookupAccountNameW //sys ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) = advapi32.ConvertSidToStringSidW @@ -266,6 +296,7 @@ const ( TOKEN_ADJUST_PRIVILEGES TOKEN_ADJUST_GROUPS TOKEN_ADJUST_DEFAULT + TOKEN_ADJUST_SESSIONID TOKEN_ALL_ACCESS = STANDARD_RIGHTS_REQUIRED | TOKEN_ASSIGN_PRIMARY | @@ -275,7 +306,8 @@ const ( TOKEN_QUERY_SOURCE | TOKEN_ADJUST_PRIVILEGES | TOKEN_ADJUST_GROUPS | - TOKEN_ADJUST_DEFAULT + TOKEN_ADJUST_DEFAULT | + TOKEN_ADJUST_SESSIONID TOKEN_READ = STANDARD_RIGHTS_READ | TOKEN_QUERY TOKEN_WRITE = STANDARD_RIGHTS_WRITE | TOKEN_ADJUST_PRIVILEGES | @@ -335,9 +367,12 @@ type Tokengroups struct { Groups [1]SIDAndAttributes } +// Authorization Functions +//sys checkTokenMembership(tokenHandle Token, sidToCheck *SID, isMember *int32) (err error) = advapi32.CheckTokenMembership //sys OpenProcessToken(h Handle, access uint32, token *Token) (err error) = advapi32.OpenProcessToken //sys GetTokenInformation(t Token, infoClass uint32, info *byte, infoLen uint32, returnedLen *uint32) (err error) = advapi32.GetTokenInformation //sys GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) = userenv.GetUserProfileDirectoryW +//sys getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) = kernel32.GetSystemDirectoryW // An access token contains the security information for a logon session. // The system creates an access token when a user logs on, and every @@ -433,3 +468,29 @@ func (t Token) GetUserProfileDirectory() (string, error) { } } } + +// GetSystemDirectory retrieves path to current location of the system +// directory, which is typically, though not always, C:\Windows\System32. +func GetSystemDirectory() (string, error) { + n := uint32(MAX_PATH) + for { + b := make([]uint16, n) + l, e := getSystemDirectory(&b[0], n) + if e != nil { + return "", e + } + if l <= n { + return UTF16ToString(b[:l]), nil + } + n = l + } +} + +// IsMember reports whether the access token t is a member of the provided SID. +func (t Token) IsMember(sid *SID) (bool, error) { + var b int32 + if e := checkTokenMembership(t, sid, &b); e != nil { + return false, e + } + return b != 0, nil +} diff --git a/vendor/golang.org/x/sys/windows/service.go b/vendor/golang.org/x/sys/windows/service.go index 1c11d39..62fc31b 100644 --- a/vendor/golang.org/x/sys/windows/service.go +++ b/vendor/golang.org/x/sys/windows/service.go @@ -43,6 +43,11 @@ const ( SC_STATUS_PROCESS_INFO = 0 + SC_ACTION_NONE = 0 + SC_ACTION_RESTART = 1 + SC_ACTION_REBOOT = 2 + SC_ACTION_RUN_COMMAND = 3 + SERVICE_STOPPED = 1 SERVICE_START_PENDING = 2 SERVICE_STOP_PENDING = 3 @@ -95,6 +100,8 @@ const ( SERVICE_CONFIG_FAILURE_ACTIONS = 2 NO_ERROR = 0 + + SC_ENUM_PROCESS_INFO = 0 ) type SERVICE_STATUS struct { @@ -128,6 +135,37 @@ type SERVICE_DESCRIPTION struct { Description *uint16 } +type SERVICE_STATUS_PROCESS struct { + ServiceType uint32 + CurrentState uint32 + ControlsAccepted uint32 + Win32ExitCode uint32 + ServiceSpecificExitCode uint32 + CheckPoint uint32 + WaitHint uint32 + ProcessId uint32 + ServiceFlags uint32 +} + +type ENUM_SERVICE_STATUS_PROCESS struct { + ServiceName *uint16 + DisplayName *uint16 + ServiceStatusProcess SERVICE_STATUS_PROCESS +} + +type SERVICE_FAILURE_ACTIONS struct { + ResetPeriod uint32 + RebootMsg *uint16 + Command *uint16 + ActionsCount uint32 + Actions *SC_ACTION +} + +type SC_ACTION struct { + Type uint32 + Delay uint32 +} + //sys CloseServiceHandle(handle Handle) (err error) = advapi32.CloseServiceHandle //sys CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access uint32, srvType uint32, startType uint32, errCtl uint32, pathName *uint16, loadOrderGroup *uint16, tagId *uint32, dependencies *uint16, serviceStartName *uint16, password *uint16) (handle Handle, err error) [failretval==0] = advapi32.CreateServiceW //sys OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, err error) [failretval==0] = advapi32.OpenServiceW @@ -141,3 +179,5 @@ type SERVICE_DESCRIPTION struct { //sys QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, bufSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfigW //sys ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err error) = advapi32.ChangeServiceConfig2W //sys QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceConfig2W +//sys EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serviceState uint32, services *byte, bufSize uint32, bytesNeeded *uint32, servicesReturned *uint32, resumeHandle *uint32, groupName *uint16) (err error) = advapi32.EnumServicesStatusExW +//sys QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) = advapi32.QueryServiceStatusEx diff --git a/vendor/golang.org/x/sys/windows/syscall.go b/vendor/golang.org/x/sys/windows/syscall.go index 4e2fbe8..af828a9 100644 --- a/vendor/golang.org/x/sys/windows/syscall.go +++ b/vendor/golang.org/x/sys/windows/syscall.go @@ -5,17 +5,20 @@ // +build windows // Package windows contains an interface to the low-level operating system -// primitives. OS details vary depending on the underlying system, and +// primitives. OS details vary depending on the underlying system, and // by default, godoc will display the OS-specific documentation for the current -// system. If you want godoc to display syscall documentation for another -// system, set $GOOS and $GOARCH to the desired system. For example, if +// system. If you want godoc to display syscall documentation for another +// system, set $GOOS and $GOARCH to the desired system. For example, if // you want to view documentation for freebsd/arm on linux/amd64, set $GOOS // to freebsd and $GOARCH to arm. +// // The primary use of this package is inside other packages that provide a more // portable interface to the system, such as "os", "time" and "net". Use // those packages rather than this one if you can. +// // For details of the functions and data types in this package consult // the manuals for the appropriate operating system. +// // These calls return err == nil to indicate success; otherwise // err represents an operating system error describing the failure and // holds a value of type syscall.Errno. diff --git a/vendor/golang.org/x/sys/windows/syscall_windows.go b/vendor/golang.org/x/sys/windows/syscall_windows.go index 592d73e..f72fa55 100644 --- a/vendor/golang.org/x/sys/windows/syscall_windows.go +++ b/vendor/golang.org/x/sys/windows/syscall_windows.go @@ -1,4 +1,4 @@ -// Copyright 2009 The Go Authors. All rights reserved. +// Copyright 2009 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -16,7 +16,46 @@ import ( type Handle uintptr -const InvalidHandle = ^Handle(0) +const ( + InvalidHandle = ^Handle(0) + + // Flags for DefineDosDevice. + DDD_EXACT_MATCH_ON_REMOVE = 0x00000004 + DDD_NO_BROADCAST_SYSTEM = 0x00000008 + DDD_RAW_TARGET_PATH = 0x00000001 + DDD_REMOVE_DEFINITION = 0x00000002 + + // Return values for GetDriveType. + DRIVE_UNKNOWN = 0 + DRIVE_NO_ROOT_DIR = 1 + DRIVE_REMOVABLE = 2 + DRIVE_FIXED = 3 + DRIVE_REMOTE = 4 + DRIVE_CDROM = 5 + DRIVE_RAMDISK = 6 + + // File system flags from GetVolumeInformation and GetVolumeInformationByHandle. + FILE_CASE_SENSITIVE_SEARCH = 0x00000001 + FILE_CASE_PRESERVED_NAMES = 0x00000002 + FILE_FILE_COMPRESSION = 0x00000010 + FILE_DAX_VOLUME = 0x20000000 + FILE_NAMED_STREAMS = 0x00040000 + FILE_PERSISTENT_ACLS = 0x00000008 + FILE_READ_ONLY_VOLUME = 0x00080000 + FILE_SEQUENTIAL_WRITE_ONCE = 0x00100000 + FILE_SUPPORTS_ENCRYPTION = 0x00020000 + FILE_SUPPORTS_EXTENDED_ATTRIBUTES = 0x00800000 + FILE_SUPPORTS_HARD_LINKS = 0x00400000 + FILE_SUPPORTS_OBJECT_IDS = 0x00010000 + FILE_SUPPORTS_OPEN_BY_FILE_ID = 0x01000000 + FILE_SUPPORTS_REPARSE_POINTS = 0x00000080 + FILE_SUPPORTS_SPARSE_FILES = 0x00000040 + FILE_SUPPORTS_TRANSACTIONS = 0x00200000 + FILE_SUPPORTS_USN_JOURNAL = 0x02000000 + FILE_UNICODE_ON_DISK = 0x00000004 + FILE_VOLUME_IS_COMPRESSED = 0x00008000 + FILE_VOLUME_QUOTAS = 0x00000020 +) // StringToUTF16 is deprecated. Use UTF16FromString instead. // If s contains a NUL byte this function panics instead of @@ -71,12 +110,19 @@ func UTF16PtrFromString(s string) (*uint16, error) { func Getpagesize() int { return 4096 } -// Converts a Go function to a function pointer conforming -// to the stdcall or cdecl calling convention. This is useful when -// interoperating with Windows code requiring callbacks. -// Implemented in runtime/syscall_windows.goc -func NewCallback(fn interface{}) uintptr -func NewCallbackCDecl(fn interface{}) uintptr +// NewCallback converts a Go function to a function pointer conforming to the stdcall calling convention. +// This is useful when interoperating with Windows code requiring callbacks. +// The argument is expected to be a function with with one uintptr-sized result. The function must not have arguments with size larger than the size of uintptr. +func NewCallback(fn interface{}) uintptr { + return syscall.NewCallback(fn) +} + +// NewCallbackCDecl converts a Go function to a function pointer conforming to the cdecl calling convention. +// This is useful when interoperating with Windows code requiring callbacks. +// The argument is expected to be a function with with one uintptr-sized result. The function must not have arguments with size larger than the size of uintptr. +func NewCallbackCDecl(fn interface{}) uintptr { + return syscall.NewCallbackCDecl(fn) +} // windows api calls @@ -93,7 +139,8 @@ func NewCallbackCDecl(fn interface{}) uintptr //sys WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) (err error) //sys SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence uint32) (newlowoffset uint32, err error) [failretval==0xffffffff] //sys CloseHandle(handle Handle) (err error) -//sys GetStdHandle(stdhandle int) (handle Handle, err error) [failretval==InvalidHandle] +//sys GetStdHandle(stdhandle uint32) (handle Handle, err error) [failretval==InvalidHandle] +//sys SetStdHandle(stdhandle uint32, handle Handle) (err error) //sys findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err error) [failretval==InvalidHandle] = FindFirstFileW //sys findNextFile1(handle Handle, data *win32finddata1) (err error) = FindNextFileW //sys FindClose(handle Handle) (err error) @@ -109,6 +156,7 @@ func NewCallbackCDecl(fn interface{}) uintptr //sys GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) = GetComputerNameExW //sys SetEndOfFile(handle Handle) (err error) //sys GetSystemTimeAsFileTime(time *Filetime) +//sys GetSystemTimePreciseAsFileTime(time *Filetime) //sys GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) [failretval==0xffffffff] //sys CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, threadcnt uint32) (handle Handle, err error) //sys GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overlapped **Overlapped, timeout uint32) (err error) @@ -124,6 +172,7 @@ func NewCallbackCDecl(fn interface{}) uintptr //sys GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, kernelTime *Filetime, userTime *Filetime) (err error) //sys DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetProcessHandle Handle, lpTargetHandle *Handle, dwDesiredAccess uint32, bInheritHandle bool, dwOptions uint32) (err error) //sys WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, err error) [failretval==0xffffffff] +//sys waitForMultipleObjects(count uint32, handles uintptr, waitAll bool, waitMilliseconds uint32) (event uint32, err error) [failretval==0xffffffff] = WaitForMultipleObjects //sys GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) = GetTempPathW //sys CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, size uint32) (err error) //sys GetFileType(filehandle Handle) (n uint32, err error) @@ -152,6 +201,9 @@ func NewCallbackCDecl(fn interface{}) uintptr //sys FlushViewOfFile(addr uintptr, length uintptr) (err error) //sys VirtualLock(addr uintptr, length uintptr) (err error) //sys VirtualUnlock(addr uintptr, length uintptr) (err error) +//sys VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error) = kernel32.VirtualAlloc +//sys VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) = kernel32.VirtualFree +//sys VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) = kernel32.VirtualProtect //sys TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint32, overlapped *Overlapped, transmitFileBuf *TransmitFileBuffers, flags uint32) (err error) = mswsock.TransmitFile //sys ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree bool, mask uint32, retlen *uint32, overlapped *Overlapped, completionRoutine uintptr) (err error) = kernel32.ReadDirectoryChangesW //sys CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) = crypt32.CertOpenSystemStoreW @@ -171,6 +223,8 @@ func NewCallbackCDecl(fn interface{}) uintptr //sys RegQueryValueEx(key Handle, name *uint16, reserved *uint32, valtype *uint32, buf *byte, buflen *uint32) (regerrno error) = advapi32.RegQueryValueExW //sys getCurrentProcessId() (pid uint32) = kernel32.GetCurrentProcessId //sys GetConsoleMode(console Handle, mode *uint32) (err error) = kernel32.GetConsoleMode +//sys SetConsoleMode(console Handle, mode uint32) (err error) = kernel32.SetConsoleMode +//sys GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) = kernel32.GetConsoleScreenBufferInfo //sys WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, reserved *byte) (err error) = kernel32.WriteConsoleW //sys ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, inputControl *byte) (err error) = kernel32.ReadConsoleW //sys CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, err error) [failretval==InvalidHandle] = kernel32.CreateToolhelp32Snapshot @@ -181,11 +235,51 @@ func NewCallbackCDecl(fn interface{}) uintptr //sys CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags uint32) (err error) [failretval&0xff==0] = CreateSymbolicLinkW //sys CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr) (err error) [failretval&0xff==0] = CreateHardLinkW //sys GetCurrentThreadId() (id uint32) -//sys CreateEvent(eventAttrs *syscall.SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) = kernel32.CreateEventW +//sys CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) = kernel32.CreateEventW +//sys CreateEventEx(eventAttrs *SecurityAttributes, name *uint16, flags uint32, desiredAccess uint32) (handle Handle, err error) = kernel32.CreateEventExW +//sys OpenEvent(desiredAccess uint32, inheritHandle bool, name *uint16) (handle Handle, err error) = kernel32.OpenEventW //sys SetEvent(event Handle) (err error) = kernel32.SetEvent +//sys ResetEvent(event Handle) (err error) = kernel32.ResetEvent +//sys PulseEvent(event Handle) (err error) = kernel32.PulseEvent + +// Volume Management Functions +//sys DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) = DefineDosDeviceW +//sys DeleteVolumeMountPoint(volumeMountPoint *uint16) (err error) = DeleteVolumeMountPointW +//sys FindFirstVolume(volumeName *uint16, bufferLength uint32) (handle Handle, err error) [failretval==InvalidHandle] = FindFirstVolumeW +//sys FindFirstVolumeMountPoint(rootPathName *uint16, volumeMountPoint *uint16, bufferLength uint32) (handle Handle, err error) [failretval==InvalidHandle] = FindFirstVolumeMountPointW +//sys FindNextVolume(findVolume Handle, volumeName *uint16, bufferLength uint32) (err error) = FindNextVolumeW +//sys FindNextVolumeMountPoint(findVolumeMountPoint Handle, volumeMountPoint *uint16, bufferLength uint32) (err error) = FindNextVolumeMountPointW +//sys FindVolumeClose(findVolume Handle) (err error) +//sys FindVolumeMountPointClose(findVolumeMountPoint Handle) (err error) +//sys GetDriveType(rootPathName *uint16) (driveType uint32) = GetDriveTypeW +//sys GetLogicalDrives() (drivesBitMask uint32, err error) [failretval==0] +//sys GetLogicalDriveStrings(bufferLength uint32, buffer *uint16) (n uint32, err error) [failretval==0] = GetLogicalDriveStringsW +//sys GetVolumeInformation(rootPathName *uint16, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) = GetVolumeInformationW +//sys GetVolumeInformationByHandle(file Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) = GetVolumeInformationByHandleW +//sys GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) = GetVolumeNameForVolumeMountPointW +//sys GetVolumePathName(fileName *uint16, volumePathName *uint16, bufferLength uint32) (err error) = GetVolumePathNameW +//sys GetVolumePathNamesForVolumeName(volumeName *uint16, volumePathNames *uint16, bufferLength uint32, returnLength *uint32) (err error) = GetVolumePathNamesForVolumeNameW +//sys QueryDosDevice(deviceName *uint16, targetPath *uint16, max uint32) (n uint32, err error) [failretval==0] = QueryDosDeviceW +//sys SetVolumeLabel(rootPathName *uint16, volumeName *uint16) (err error) = SetVolumeLabelW +//sys SetVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16) (err error) = SetVolumeMountPointW // syscall interface implementation for other packages +// GetProcAddressByOrdinal retrieves the address of the exported +// function from module by ordinal. +func GetProcAddressByOrdinal(module Handle, ordinal uintptr) (proc uintptr, err error) { + r0, _, e1 := syscall.Syscall(procGetProcAddress.Addr(), 2, uintptr(module), ordinal, 0) + proc = uintptr(r0) + if proc == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + func Exit(code int) { ExitProcess(uint32(code)) } func makeInheritSa() *SecurityAttributes { @@ -311,8 +405,8 @@ var ( Stderr = getStdHandle(STD_ERROR_HANDLE) ) -func getStdHandle(h int) (fd Handle) { - r, _ := GetStdHandle(h) +func getStdHandle(stdhandle uint32) (fd Handle) { + r, _ := GetStdHandle(stdhandle) CloseOnExec(r) return r } @@ -484,6 +578,10 @@ func Chmod(path string, mode uint32) (err error) { return SetFileAttributes(p, attrs) } +func LoadGetSystemTimePreciseAsFileTime() error { + return procGetSystemTimePreciseAsFileTime.Find() +} + func LoadCancelIoEx() error { return procCancelIoEx.Find() } @@ -492,6 +590,18 @@ func LoadSetFileCompletionNotificationModes() error { return procSetFileCompletionNotificationModes.Find() } +func WaitForMultipleObjects(handles []Handle, waitAll bool, waitMilliseconds uint32) (event uint32, err error) { + // Every other win32 array API takes arguments as "pointer, count", except for this function. So we + // can't declare it as a usual [] type, because mksyscall will use the opposite order. We therefore + // trivially stub this ourselves. + + var handlePtr *Handle + if len(handles) > 0 { + handlePtr = &handles[0] + } + return waitForMultipleObjects(uint32(len(handles)), uintptr(unsafe.Pointer(handlePtr)), waitAll, waitMilliseconds) +} + // net api calls const socket_error = uintptr(^uint32(0)) @@ -558,7 +668,7 @@ type RawSockaddr struct { type RawSockaddrAny struct { Addr RawSockaddr - Pad [96]int8 + Pad [100]int8 } type Sockaddr interface { @@ -607,19 +717,69 @@ func (sa *SockaddrInet6) sockaddr() (unsafe.Pointer, int32, error) { return unsafe.Pointer(&sa.raw), int32(unsafe.Sizeof(sa.raw)), nil } +type RawSockaddrUnix struct { + Family uint16 + Path [UNIX_PATH_MAX]int8 +} + type SockaddrUnix struct { Name string + raw RawSockaddrUnix } func (sa *SockaddrUnix) sockaddr() (unsafe.Pointer, int32, error) { - // TODO(brainman): implement SockaddrUnix.sockaddr() - return nil, 0, syscall.EWINDOWS + name := sa.Name + n := len(name) + if n > len(sa.raw.Path) { + return nil, 0, syscall.EINVAL + } + if n == len(sa.raw.Path) && name[0] != '@' { + return nil, 0, syscall.EINVAL + } + sa.raw.Family = AF_UNIX + for i := 0; i < n; i++ { + sa.raw.Path[i] = int8(name[i]) + } + // length is family (uint16), name, NUL. + sl := int32(2) + if n > 0 { + sl += int32(n) + 1 + } + if sa.raw.Path[0] == '@' { + sa.raw.Path[0] = 0 + // Don't count trailing NUL for abstract address. + sl-- + } + + return unsafe.Pointer(&sa.raw), sl, nil } func (rsa *RawSockaddrAny) Sockaddr() (Sockaddr, error) { switch rsa.Addr.Family { case AF_UNIX: - return nil, syscall.EWINDOWS + pp := (*RawSockaddrUnix)(unsafe.Pointer(rsa)) + sa := new(SockaddrUnix) + if pp.Path[0] == 0 { + // "Abstract" Unix domain socket. + // Rewrite leading NUL as @ for textual display. + // (This is the standard convention.) + // Not friendly to overwrite in place, + // but the callers below don't care. + pp.Path[0] = '@' + } + + // Assume path ends at NUL. + // This is not technically the Linux semantics for + // abstract Unix domain sockets--they are supposed + // to be uninterpreted fixed-size binary blobs--but + // everyone uses this convention. + n := 0 + for n < len(pp.Path) && pp.Path[n] != 0 { + n++ + } + bytes := (*[10000]byte)(unsafe.Pointer(&pp.Path[0]))[0:n] + sa.Name = string(bytes) + return sa, nil case AF_INET: pp := (*RawSockaddrInet4)(unsafe.Pointer(rsa)) @@ -761,6 +921,75 @@ func ConnectEx(fd Handle, sa Sockaddr, sendBuf *byte, sendDataLen uint32, bytesS return connectEx(fd, ptr, n, sendBuf, sendDataLen, bytesSent, overlapped) } +var sendRecvMsgFunc struct { + once sync.Once + sendAddr uintptr + recvAddr uintptr + err error +} + +func loadWSASendRecvMsg() error { + sendRecvMsgFunc.once.Do(func() { + var s Handle + s, sendRecvMsgFunc.err = Socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP) + if sendRecvMsgFunc.err != nil { + return + } + defer CloseHandle(s) + var n uint32 + sendRecvMsgFunc.err = WSAIoctl(s, + SIO_GET_EXTENSION_FUNCTION_POINTER, + (*byte)(unsafe.Pointer(&WSAID_WSARECVMSG)), + uint32(unsafe.Sizeof(WSAID_WSARECVMSG)), + (*byte)(unsafe.Pointer(&sendRecvMsgFunc.recvAddr)), + uint32(unsafe.Sizeof(sendRecvMsgFunc.recvAddr)), + &n, nil, 0) + if sendRecvMsgFunc.err != nil { + return + } + sendRecvMsgFunc.err = WSAIoctl(s, + SIO_GET_EXTENSION_FUNCTION_POINTER, + (*byte)(unsafe.Pointer(&WSAID_WSASENDMSG)), + uint32(unsafe.Sizeof(WSAID_WSASENDMSG)), + (*byte)(unsafe.Pointer(&sendRecvMsgFunc.sendAddr)), + uint32(unsafe.Sizeof(sendRecvMsgFunc.sendAddr)), + &n, nil, 0) + }) + return sendRecvMsgFunc.err +} + +func WSASendMsg(fd Handle, msg *WSAMsg, flags uint32, bytesSent *uint32, overlapped *Overlapped, croutine *byte) error { + err := loadWSASendRecvMsg() + if err != nil { + return err + } + r1, _, e1 := syscall.Syscall6(sendRecvMsgFunc.sendAddr, 6, uintptr(fd), uintptr(unsafe.Pointer(msg)), uintptr(flags), uintptr(unsafe.Pointer(bytesSent)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine))) + if r1 == socket_error { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return err +} + +func WSARecvMsg(fd Handle, msg *WSAMsg, bytesReceived *uint32, overlapped *Overlapped, croutine *byte) error { + err := loadWSASendRecvMsg() + if err != nil { + return err + } + r1, _, e1 := syscall.Syscall6(sendRecvMsgFunc.recvAddr, 5, uintptr(fd), uintptr(unsafe.Pointer(msg)), uintptr(unsafe.Pointer(bytesReceived)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0) + if r1 == socket_error { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return err +} + // Invented structures to support what package os expects. type Rusage struct { CreationTime Filetime diff --git a/vendor/golang.org/x/sys/windows/ztypes_windows.go b/vendor/golang.org/x/sys/windows/types_windows.go similarity index 74% rename from vendor/golang.org/x/sys/windows/ztypes_windows.go rename to vendor/golang.org/x/sys/windows/types_windows.go index 1fe19d1..141ca81 100644 --- a/vendor/golang.org/x/sys/windows/ztypes_windows.go +++ b/vendor/golang.org/x/sys/windows/types_windows.go @@ -1,4 +1,4 @@ -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. @@ -29,6 +29,7 @@ const ( ERROR_NOT_FOUND syscall.Errno = 1168 ERROR_PRIVILEGE_NOT_HELD syscall.Errno = 1314 WSAEACCES syscall.Errno = 10013 + WSAEMSGSIZE syscall.Errno = 10040 WSAECONNRESET syscall.Errno = 10054 ) @@ -93,16 +94,29 @@ const ( FILE_APPEND_DATA = 0x00000004 FILE_WRITE_ATTRIBUTES = 0x00000100 - FILE_SHARE_READ = 0x00000001 - FILE_SHARE_WRITE = 0x00000002 - FILE_SHARE_DELETE = 0x00000004 - FILE_ATTRIBUTE_READONLY = 0x00000001 - FILE_ATTRIBUTE_HIDDEN = 0x00000002 - FILE_ATTRIBUTE_SYSTEM = 0x00000004 - FILE_ATTRIBUTE_DIRECTORY = 0x00000010 - FILE_ATTRIBUTE_ARCHIVE = 0x00000020 - FILE_ATTRIBUTE_NORMAL = 0x00000080 - FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400 + FILE_SHARE_READ = 0x00000001 + FILE_SHARE_WRITE = 0x00000002 + FILE_SHARE_DELETE = 0x00000004 + + FILE_ATTRIBUTE_READONLY = 0x00000001 + FILE_ATTRIBUTE_HIDDEN = 0x00000002 + FILE_ATTRIBUTE_SYSTEM = 0x00000004 + FILE_ATTRIBUTE_DIRECTORY = 0x00000010 + FILE_ATTRIBUTE_ARCHIVE = 0x00000020 + FILE_ATTRIBUTE_DEVICE = 0x00000040 + FILE_ATTRIBUTE_NORMAL = 0x00000080 + FILE_ATTRIBUTE_TEMPORARY = 0x00000100 + FILE_ATTRIBUTE_SPARSE_FILE = 0x00000200 + FILE_ATTRIBUTE_REPARSE_POINT = 0x00000400 + FILE_ATTRIBUTE_COMPRESSED = 0x00000800 + FILE_ATTRIBUTE_OFFLINE = 0x00001000 + FILE_ATTRIBUTE_NOT_CONTENT_INDEXED = 0x00002000 + FILE_ATTRIBUTE_ENCRYPTED = 0x00004000 + FILE_ATTRIBUTE_INTEGRITY_STREAM = 0x00008000 + FILE_ATTRIBUTE_VIRTUAL = 0x00010000 + FILE_ATTRIBUTE_NO_SCRUB_DATA = 0x00020000 + FILE_ATTRIBUTE_RECALL_ON_OPEN = 0x00040000 + FILE_ATTRIBUTE_RECALL_ON_DATA_ACCESS = 0x00400000 INVALID_FILE_ATTRIBUTES = 0xffffffff @@ -122,9 +136,9 @@ const ( DUPLICATE_CLOSE_SOURCE = 0x00000001 DUPLICATE_SAME_ACCESS = 0x00000002 - STD_INPUT_HANDLE = -10 - STD_OUTPUT_HANDLE = -11 - STD_ERROR_HANDLE = -12 + STD_INPUT_HANDLE = -10 & (1<<32 - 1) + STD_OUTPUT_HANDLE = -11 & (1<<32 - 1) + STD_ERROR_HANDLE = -12 & (1<<32 - 1) FILE_BEGIN = 0 FILE_CURRENT = 1 @@ -158,20 +172,10 @@ const ( WAIT_OBJECT_0 = 0x00000000 WAIT_FAILED = 0xFFFFFFFF - CREATE_NEW_PROCESS_GROUP = 0x00000200 - CREATE_UNICODE_ENVIRONMENT = 0x00000400 - PROCESS_TERMINATE = 1 PROCESS_QUERY_INFORMATION = 0x00000400 SYNCHRONIZE = 0x00100000 - PAGE_READONLY = 0x02 - PAGE_READWRITE = 0x04 - PAGE_WRITECOPY = 0x08 - PAGE_EXECUTE_READ = 0x20 - PAGE_EXECUTE_READWRITE = 0x40 - PAGE_EXECUTE_WRITECOPY = 0x80 - FILE_MAP_COPY = 0x01 FILE_MAP_WRITE = 0x02 FILE_MAP_READ = 0x04 @@ -184,6 +188,26 @@ const ( APPLICATION_ERROR = 1 << 29 ) +const ( + // Process creation flags. + CREATE_BREAKAWAY_FROM_JOB = 0x01000000 + CREATE_DEFAULT_ERROR_MODE = 0x04000000 + CREATE_NEW_CONSOLE = 0x00000010 + CREATE_NEW_PROCESS_GROUP = 0x00000200 + CREATE_NO_WINDOW = 0x08000000 + CREATE_PROTECTED_PROCESS = 0x00040000 + CREATE_PRESERVE_CODE_AUTHZ_LEVEL = 0x02000000 + CREATE_SEPARATE_WOW_VDM = 0x00000800 + CREATE_SHARED_WOW_VDM = 0x00001000 + CREATE_SUSPENDED = 0x00000004 + CREATE_UNICODE_ENVIRONMENT = 0x00000400 + DEBUG_ONLY_THIS_PROCESS = 0x00000002 + DEBUG_PROCESS = 0x00000001 + DETACHED_PROCESS = 0x00000008 + EXTENDED_STARTUPINFO_PRESENT = 0x00080000 + INHERIT_PARENT_AFFINITY = 0x00010000 +) + const ( // flags for CreateToolhelp32Snapshot TH32CS_SNAPHEAPLIST = 0x01 @@ -246,15 +270,87 @@ const ( USAGE_MATCH_TYPE_AND = 0 USAGE_MATCH_TYPE_OR = 1 + /* msgAndCertEncodingType values for CertOpenStore function */ X509_ASN_ENCODING = 0x00000001 PKCS_7_ASN_ENCODING = 0x00010000 - CERT_STORE_PROV_MEMORY = 2 - - CERT_STORE_ADD_ALWAYS = 4 - + /* storeProvider values for CertOpenStore function */ + CERT_STORE_PROV_MSG = 1 + CERT_STORE_PROV_MEMORY = 2 + CERT_STORE_PROV_FILE = 3 + CERT_STORE_PROV_REG = 4 + CERT_STORE_PROV_PKCS7 = 5 + CERT_STORE_PROV_SERIALIZED = 6 + CERT_STORE_PROV_FILENAME_A = 7 + CERT_STORE_PROV_FILENAME_W = 8 + CERT_STORE_PROV_FILENAME = CERT_STORE_PROV_FILENAME_W + CERT_STORE_PROV_SYSTEM_A = 9 + CERT_STORE_PROV_SYSTEM_W = 10 + CERT_STORE_PROV_SYSTEM = CERT_STORE_PROV_SYSTEM_W + CERT_STORE_PROV_COLLECTION = 11 + CERT_STORE_PROV_SYSTEM_REGISTRY_A = 12 + CERT_STORE_PROV_SYSTEM_REGISTRY_W = 13 + CERT_STORE_PROV_SYSTEM_REGISTRY = CERT_STORE_PROV_SYSTEM_REGISTRY_W + CERT_STORE_PROV_PHYSICAL_W = 14 + CERT_STORE_PROV_PHYSICAL = CERT_STORE_PROV_PHYSICAL_W + CERT_STORE_PROV_SMART_CARD_W = 15 + CERT_STORE_PROV_SMART_CARD = CERT_STORE_PROV_SMART_CARD_W + CERT_STORE_PROV_LDAP_W = 16 + CERT_STORE_PROV_LDAP = CERT_STORE_PROV_LDAP_W + CERT_STORE_PROV_PKCS12 = 17 + + /* store characteristics (low WORD of flag) for CertOpenStore function */ + CERT_STORE_NO_CRYPT_RELEASE_FLAG = 0x00000001 + CERT_STORE_SET_LOCALIZED_NAME_FLAG = 0x00000002 CERT_STORE_DEFER_CLOSE_UNTIL_LAST_FREE_FLAG = 0x00000004 - + CERT_STORE_DELETE_FLAG = 0x00000010 + CERT_STORE_UNSAFE_PHYSICAL_FLAG = 0x00000020 + CERT_STORE_SHARE_STORE_FLAG = 0x00000040 + CERT_STORE_SHARE_CONTEXT_FLAG = 0x00000080 + CERT_STORE_MANIFOLD_FLAG = 0x00000100 + CERT_STORE_ENUM_ARCHIVED_FLAG = 0x00000200 + CERT_STORE_UPDATE_KEYID_FLAG = 0x00000400 + CERT_STORE_BACKUP_RESTORE_FLAG = 0x00000800 + CERT_STORE_MAXIMUM_ALLOWED_FLAG = 0x00001000 + CERT_STORE_CREATE_NEW_FLAG = 0x00002000 + CERT_STORE_OPEN_EXISTING_FLAG = 0x00004000 + CERT_STORE_READONLY_FLAG = 0x00008000 + + /* store locations (high WORD of flag) for CertOpenStore function */ + CERT_SYSTEM_STORE_CURRENT_USER = 0x00010000 + CERT_SYSTEM_STORE_LOCAL_MACHINE = 0x00020000 + CERT_SYSTEM_STORE_CURRENT_SERVICE = 0x00040000 + CERT_SYSTEM_STORE_SERVICES = 0x00050000 + CERT_SYSTEM_STORE_USERS = 0x00060000 + CERT_SYSTEM_STORE_CURRENT_USER_GROUP_POLICY = 0x00070000 + CERT_SYSTEM_STORE_LOCAL_MACHINE_GROUP_POLICY = 0x00080000 + CERT_SYSTEM_STORE_LOCAL_MACHINE_ENTERPRISE = 0x00090000 + CERT_SYSTEM_STORE_UNPROTECTED_FLAG = 0x40000000 + CERT_SYSTEM_STORE_RELOCATE_FLAG = 0x80000000 + + /* Miscellaneous high-WORD flags for CertOpenStore function */ + CERT_REGISTRY_STORE_REMOTE_FLAG = 0x00010000 + CERT_REGISTRY_STORE_SERIALIZED_FLAG = 0x00020000 + CERT_REGISTRY_STORE_ROAMING_FLAG = 0x00040000 + CERT_REGISTRY_STORE_MY_IE_DIRTY_FLAG = 0x00080000 + CERT_REGISTRY_STORE_LM_GPT_FLAG = 0x01000000 + CERT_REGISTRY_STORE_CLIENT_GPT_FLAG = 0x80000000 + CERT_FILE_STORE_COMMIT_ENABLE_FLAG = 0x00010000 + CERT_LDAP_STORE_SIGN_FLAG = 0x00010000 + CERT_LDAP_STORE_AREC_EXCLUSIVE_FLAG = 0x00020000 + CERT_LDAP_STORE_OPENED_FLAG = 0x00040000 + CERT_LDAP_STORE_UNBIND_FLAG = 0x00080000 + + /* addDisposition values for CertAddCertificateContextToStore function */ + CERT_STORE_ADD_NEW = 1 + CERT_STORE_ADD_USE_EXISTING = 2 + CERT_STORE_ADD_REPLACE_EXISTING = 3 + CERT_STORE_ADD_ALWAYS = 4 + CERT_STORE_ADD_REPLACE_EXISTING_INHERIT_PROPERTIES = 5 + CERT_STORE_ADD_NEWER = 6 + CERT_STORE_ADD_NEWER_INHERIT_PROPERTIES = 7 + + /* ErrorStatus values for CertTrustStatus struct */ CERT_TRUST_NO_ERROR = 0x00000000 CERT_TRUST_IS_NOT_TIME_VALID = 0x00000001 CERT_TRUST_IS_REVOKED = 0x00000004 @@ -271,11 +367,31 @@ const ( CERT_TRUST_HAS_NOT_DEFINED_NAME_CONSTRAINT = 0x00002000 CERT_TRUST_HAS_NOT_PERMITTED_NAME_CONSTRAINT = 0x00004000 CERT_TRUST_HAS_EXCLUDED_NAME_CONSTRAINT = 0x00008000 + CERT_TRUST_IS_PARTIAL_CHAIN = 0x00010000 + CERT_TRUST_CTL_IS_NOT_TIME_VALID = 0x00020000 + CERT_TRUST_CTL_IS_NOT_SIGNATURE_VALID = 0x00040000 + CERT_TRUST_CTL_IS_NOT_VALID_FOR_USAGE = 0x00080000 + CERT_TRUST_HAS_WEAK_SIGNATURE = 0x00100000 CERT_TRUST_IS_OFFLINE_REVOCATION = 0x01000000 CERT_TRUST_NO_ISSUANCE_CHAIN_POLICY = 0x02000000 CERT_TRUST_IS_EXPLICIT_DISTRUST = 0x04000000 CERT_TRUST_HAS_NOT_SUPPORTED_CRITICAL_EXT = 0x08000000 + /* InfoStatus values for CertTrustStatus struct */ + CERT_TRUST_HAS_EXACT_MATCH_ISSUER = 0x00000001 + CERT_TRUST_HAS_KEY_MATCH_ISSUER = 0x00000002 + CERT_TRUST_HAS_NAME_MATCH_ISSUER = 0x00000004 + CERT_TRUST_IS_SELF_SIGNED = 0x00000008 + CERT_TRUST_HAS_PREFERRED_ISSUER = 0x00000100 + CERT_TRUST_HAS_ISSUANCE_CHAIN_POLICY = 0x00000400 + CERT_TRUST_HAS_VALID_NAME_CONSTRAINTS = 0x00000400 + CERT_TRUST_IS_PEER_TRUSTED = 0x00000800 + CERT_TRUST_HAS_CRL_VALIDITY_EXTENDED = 0x00001000 + CERT_TRUST_IS_FROM_EXCLUSIVE_TRUST_STORE = 0x00002000 + CERT_TRUST_IS_CA_TRUSTED = 0x00004000 + CERT_TRUST_IS_COMPLEX_CHAIN = 0x00010000 + + /* policyOID values for CertVerifyCertificateChainPolicy function */ CERT_CHAIN_POLICY_BASE = 1 CERT_CHAIN_POLICY_AUTHENTICODE = 2 CERT_CHAIN_POLICY_AUTHENTICODE_TS = 3 @@ -284,6 +400,7 @@ const ( CERT_CHAIN_POLICY_NT_AUTH = 6 CERT_CHAIN_POLICY_MICROSOFT_ROOT = 7 CERT_CHAIN_POLICY_EV = 8 + CERT_CHAIN_POLICY_SSL_F12 = 9 CERT_E_EXPIRED = 0x800B0101 CERT_E_ROLE = 0x800B0103 @@ -291,8 +408,16 @@ const ( CERT_E_UNTRUSTEDROOT = 0x800B0109 CERT_E_CN_NO_MATCH = 0x800B010F + /* AuthType values for SSLExtraCertChainPolicyPara struct */ AUTHTYPE_CLIENT = 1 AUTHTYPE_SERVER = 2 + + /* Checks values for SSLExtraCertChainPolicyPara struct */ + SECURITY_FLAG_IGNORE_REVOCATION = 0x00000080 + SECURITY_FLAG_IGNORE_UNKNOWN_CA = 0x00000100 + SECURITY_FLAG_IGNORE_WRONG_USAGE = 0x00000200 + SECURITY_FLAG_IGNORE_CERT_CN_INVALID = 0x00001000 + SECURITY_FLAG_IGNORE_CERT_DATE_INVALID = 0x00002000 ) var ( @@ -301,6 +426,14 @@ var ( OID_SGC_NETSCAPE = []byte("2.16.840.1.113730.4.1\x00") ) +// Pointer represents a pointer to an arbitrary Windows type. +// +// Pointer-typed fields may point to one of many different types. It's +// up to the caller to provide a pointer to the appropriate type, cast +// to Pointer. The caller must obey the unsafe.Pointer rules while +// doing so. +type Pointer *struct{} + // Invented values to support what package os expects. type Timeval struct { Sec int32 @@ -574,6 +707,16 @@ const ( IPV6_JOIN_GROUP = 0xc IPV6_LEAVE_GROUP = 0xd + MSG_OOB = 0x1 + MSG_PEEK = 0x2 + MSG_DONTROUTE = 0x4 + MSG_WAITALL = 0x8 + + MSG_TRUNC = 0x0100 + MSG_CTRUNC = 0x0200 + MSG_BCAST = 0x0400 + MSG_MCAST = 0x0800 + SOMAXCONN = 0x7fffffff TCP_NODELAY = 1 @@ -591,6 +734,15 @@ type WSABuf struct { Buf *byte } +type WSAMsg struct { + Name *syscall.RawSockaddrAny + Namelen int32 + Buffers *WSABuf + BufferCount uint32 + Control WSABuf + Flags uint32 +} + // Invented values to support what package os expects. const ( S_IFMT = 0x1f000 @@ -850,11 +1002,15 @@ type MibIfRow struct { Descr [MAXLEN_IFDESCR]byte } +type CertInfo struct { + // Not implemented +} + type CertContext struct { EncodingType uint32 EncodedCert *byte Length uint32 - CertInfo uintptr + CertInfo *CertInfo Store Handle } @@ -869,12 +1025,16 @@ type CertChainContext struct { RevocationFreshnessTime uint32 } +type CertTrustListInfo struct { + // Not implemented +} + type CertSimpleChain struct { Size uint32 TrustStatus CertTrustStatus NumElements uint32 Elements **CertChainElement - TrustListInfo uintptr + TrustListInfo *CertTrustListInfo HasRevocationFreshnessTime uint32 RevocationFreshnessTime uint32 } @@ -889,14 +1049,18 @@ type CertChainElement struct { ExtendedErrorInfo *uint16 } +type CertRevocationCrlInfo struct { + // Not implemented +} + type CertRevocationInfo struct { Size uint32 RevocationResult uint32 RevocationOid *byte - OidSpecificInfo uintptr + OidSpecificInfo Pointer HasFreshnessTime uint32 FreshnessTime uint32 - CrlInfo uintptr // *CertRevocationCrlInfo + CrlInfo *CertRevocationCrlInfo } type CertTrustStatus struct { @@ -927,7 +1091,7 @@ type CertChainPara struct { type CertChainPolicyPara struct { Size uint32 Flags uint32 - ExtraPolicyPara uintptr + ExtraPolicyPara Pointer } type SSLExtraCertChainPolicyPara struct { @@ -942,7 +1106,7 @@ type CertChainPolicyStatus struct { Error uint32 ChainIndex uint32 ElementIndex uint32 - ExtraPolicyStatus uintptr + ExtraPolicyStatus Pointer } const ( @@ -1018,6 +1182,20 @@ var WSAID_CONNECTEX = GUID{ [8]byte{0x8e, 0xe9, 0x76, 0xe5, 0x8c, 0x74, 0x06, 0x3e}, } +var WSAID_WSASENDMSG = GUID{ + 0xa441e712, + 0x754f, + 0x43ca, + [8]byte{0x84, 0xa7, 0x0d, 0xee, 0x44, 0xcf, 0x60, 0x6d}, +} + +var WSAID_WSARECVMSG = GUID{ + 0xf689d7c8, + 0x6f1f, + 0x436b, + [8]byte{0x8a, 0x53, 0xe5, 0x4f, 0xe3, 0x51, 0xc3, 0x22}, +} + const ( FILE_SKIP_COMPLETION_PORT_ON_SUCCESS = 1 FILE_SKIP_SET_EVENT_ON_HANDLE = 2 @@ -1240,3 +1418,52 @@ const ( IfOperStatusNotPresent = 6 IfOperStatusLowerLayerDown = 7 ) + +// Console related constants used for the mode parameter to SetConsoleMode. See +// https://docs.microsoft.com/en-us/windows/console/setconsolemode for details. + +const ( + ENABLE_PROCESSED_INPUT = 0x1 + ENABLE_LINE_INPUT = 0x2 + ENABLE_ECHO_INPUT = 0x4 + ENABLE_WINDOW_INPUT = 0x8 + ENABLE_MOUSE_INPUT = 0x10 + ENABLE_INSERT_MODE = 0x20 + ENABLE_QUICK_EDIT_MODE = 0x40 + ENABLE_EXTENDED_FLAGS = 0x80 + ENABLE_AUTO_POSITION = 0x100 + ENABLE_VIRTUAL_TERMINAL_INPUT = 0x200 + + ENABLE_PROCESSED_OUTPUT = 0x1 + ENABLE_WRAP_AT_EOL_OUTPUT = 0x2 + ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x4 + DISABLE_NEWLINE_AUTO_RETURN = 0x8 + ENABLE_LVB_GRID_WORLDWIDE = 0x10 +) + +type Coord struct { + X int16 + Y int16 +} + +type SmallRect struct { + Left int16 + Top int16 + Right int16 + Bottom int16 +} + +// Used with GetConsoleScreenBuffer to retrieve information about a console +// screen buffer. See +// https://docs.microsoft.com/en-us/windows/console/console-screen-buffer-info-str +// for details. + +type ConsoleScreenBufferInfo struct { + Size Coord + CursorPosition Coord + Attributes uint16 + Window SmallRect + MaximumWindowSize Coord +} + +const UNIX_PATH_MAX = 108 // defined in afunix.h diff --git a/vendor/golang.org/x/sys/windows/ztypes_windows_386.go b/vendor/golang.org/x/sys/windows/types_windows_386.go similarity index 88% rename from vendor/golang.org/x/sys/windows/ztypes_windows_386.go rename to vendor/golang.org/x/sys/windows/types_windows_386.go index 10f33be..fe0ddd0 100644 --- a/vendor/golang.org/x/sys/windows/ztypes_windows_386.go +++ b/vendor/golang.org/x/sys/windows/types_windows_386.go @@ -1,4 +1,4 @@ -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/vendor/golang.org/x/sys/windows/ztypes_windows_amd64.go b/vendor/golang.org/x/sys/windows/types_windows_amd64.go similarity index 88% rename from vendor/golang.org/x/sys/windows/ztypes_windows_amd64.go rename to vendor/golang.org/x/sys/windows/types_windows_amd64.go index 3f272c2..7e154c2 100644 --- a/vendor/golang.org/x/sys/windows/ztypes_windows_amd64.go +++ b/vendor/golang.org/x/sys/windows/types_windows_amd64.go @@ -1,4 +1,4 @@ -// Copyright 2011 The Go Authors. All rights reserved. +// Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. diff --git a/vendor/golang.org/x/sys/windows/types_windows_arm.go b/vendor/golang.org/x/sys/windows/types_windows_arm.go new file mode 100644 index 0000000..74571e3 --- /dev/null +++ b/vendor/golang.org/x/sys/windows/types_windows_arm.go @@ -0,0 +1,22 @@ +// Copyright 2018 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package windows + +type WSAData struct { + Version uint16 + HighVersion uint16 + Description [WSADESCRIPTION_LEN + 1]byte + SystemStatus [WSASYS_STATUS_LEN + 1]byte + MaxSockets uint16 + MaxUdpDg uint16 + VendorInfo *byte +} + +type Servent struct { + Name *byte + Aliases **byte + Port uint16 + Proto *byte +} diff --git a/vendor/golang.org/x/sys/windows/zsyscall_windows.go b/vendor/golang.org/x/sys/windows/zsyscall_windows.go index 3ff8f52..308c97e 100644 --- a/vendor/golang.org/x/sys/windows/zsyscall_windows.go +++ b/vendor/golang.org/x/sys/windows/zsyscall_windows.go @@ -1,4 +1,4 @@ -// MACHINE GENERATED BY 'go generate' COMMAND; DO NOT EDIT +// Code generated by 'go generate'; DO NOT EDIT. package windows @@ -9,6 +9,31 @@ import ( var _ unsafe.Pointer +// Do the interface allocations only once for common +// Errno values. +const ( + errnoERROR_IO_PENDING = 997 +) + +var ( + errERROR_IO_PENDING error = syscall.Errno(errnoERROR_IO_PENDING) +) + +// errnoErr returns common boxed Errno values, to prevent +// allocations at runtime. +func errnoErr(e syscall.Errno) error { + switch e { + case 0: + return nil + case errnoERROR_IO_PENDING: + return errERROR_IO_PENDING + } + // TODO: add more here, after collecting data on the common + // error values see on Windows. (perhaps when running + // all.bat?) + return e +} + var ( modadvapi32 = NewLazySystemDLL("advapi32.dll") modkernel32 = NewLazySystemDLL("kernel32.dll") @@ -39,6 +64,8 @@ var ( procQueryServiceConfigW = modadvapi32.NewProc("QueryServiceConfigW") procChangeServiceConfig2W = modadvapi32.NewProc("ChangeServiceConfig2W") procQueryServiceConfig2W = modadvapi32.NewProc("QueryServiceConfig2W") + procEnumServicesStatusExW = modadvapi32.NewProc("EnumServicesStatusExW") + procQueryServiceStatusEx = modadvapi32.NewProc("QueryServiceStatusEx") procGetLastError = modkernel32.NewProc("GetLastError") procLoadLibraryW = modkernel32.NewProc("LoadLibraryW") procLoadLibraryExW = modkernel32.NewProc("LoadLibraryExW") @@ -53,6 +80,7 @@ var ( procSetFilePointer = modkernel32.NewProc("SetFilePointer") procCloseHandle = modkernel32.NewProc("CloseHandle") procGetStdHandle = modkernel32.NewProc("GetStdHandle") + procSetStdHandle = modkernel32.NewProc("SetStdHandle") procFindFirstFileW = modkernel32.NewProc("FindFirstFileW") procFindNextFileW = modkernel32.NewProc("FindNextFileW") procFindClose = modkernel32.NewProc("FindClose") @@ -68,6 +96,7 @@ var ( procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW") procSetEndOfFile = modkernel32.NewProc("SetEndOfFile") procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime") + procGetSystemTimePreciseAsFileTime = modkernel32.NewProc("GetSystemTimePreciseAsFileTime") procGetTimeZoneInformation = modkernel32.NewProc("GetTimeZoneInformation") procCreateIoCompletionPort = modkernel32.NewProc("CreateIoCompletionPort") procGetQueuedCompletionStatus = modkernel32.NewProc("GetQueuedCompletionStatus") @@ -83,6 +112,7 @@ var ( procGetProcessTimes = modkernel32.NewProc("GetProcessTimes") procDuplicateHandle = modkernel32.NewProc("DuplicateHandle") procWaitForSingleObject = modkernel32.NewProc("WaitForSingleObject") + procWaitForMultipleObjects = modkernel32.NewProc("WaitForMultipleObjects") procGetTempPathW = modkernel32.NewProc("GetTempPathW") procCreatePipe = modkernel32.NewProc("CreatePipe") procGetFileType = modkernel32.NewProc("GetFileType") @@ -111,6 +141,9 @@ var ( procFlushViewOfFile = modkernel32.NewProc("FlushViewOfFile") procVirtualLock = modkernel32.NewProc("VirtualLock") procVirtualUnlock = modkernel32.NewProc("VirtualUnlock") + procVirtualAlloc = modkernel32.NewProc("VirtualAlloc") + procVirtualFree = modkernel32.NewProc("VirtualFree") + procVirtualProtect = modkernel32.NewProc("VirtualProtect") procTransmitFile = modmswsock.NewProc("TransmitFile") procReadDirectoryChangesW = modkernel32.NewProc("ReadDirectoryChangesW") procCertOpenSystemStoreW = modcrypt32.NewProc("CertOpenSystemStoreW") @@ -130,6 +163,8 @@ var ( procRegQueryValueExW = modadvapi32.NewProc("RegQueryValueExW") procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId") procGetConsoleMode = modkernel32.NewProc("GetConsoleMode") + procSetConsoleMode = modkernel32.NewProc("SetConsoleMode") + procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo") procWriteConsoleW = modkernel32.NewProc("WriteConsoleW") procReadConsoleW = modkernel32.NewProc("ReadConsoleW") procCreateToolhelp32Snapshot = modkernel32.NewProc("CreateToolhelp32Snapshot") @@ -140,7 +175,30 @@ var ( procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW") procGetCurrentThreadId = modkernel32.NewProc("GetCurrentThreadId") procCreateEventW = modkernel32.NewProc("CreateEventW") + procCreateEventExW = modkernel32.NewProc("CreateEventExW") + procOpenEventW = modkernel32.NewProc("OpenEventW") procSetEvent = modkernel32.NewProc("SetEvent") + procResetEvent = modkernel32.NewProc("ResetEvent") + procPulseEvent = modkernel32.NewProc("PulseEvent") + procDefineDosDeviceW = modkernel32.NewProc("DefineDosDeviceW") + procDeleteVolumeMountPointW = modkernel32.NewProc("DeleteVolumeMountPointW") + procFindFirstVolumeW = modkernel32.NewProc("FindFirstVolumeW") + procFindFirstVolumeMountPointW = modkernel32.NewProc("FindFirstVolumeMountPointW") + procFindNextVolumeW = modkernel32.NewProc("FindNextVolumeW") + procFindNextVolumeMountPointW = modkernel32.NewProc("FindNextVolumeMountPointW") + procFindVolumeClose = modkernel32.NewProc("FindVolumeClose") + procFindVolumeMountPointClose = modkernel32.NewProc("FindVolumeMountPointClose") + procGetDriveTypeW = modkernel32.NewProc("GetDriveTypeW") + procGetLogicalDrives = modkernel32.NewProc("GetLogicalDrives") + procGetLogicalDriveStringsW = modkernel32.NewProc("GetLogicalDriveStringsW") + procGetVolumeInformationW = modkernel32.NewProc("GetVolumeInformationW") + procGetVolumeInformationByHandleW = modkernel32.NewProc("GetVolumeInformationByHandleW") + procGetVolumeNameForVolumeMountPointW = modkernel32.NewProc("GetVolumeNameForVolumeMountPointW") + procGetVolumePathNameW = modkernel32.NewProc("GetVolumePathNameW") + procGetVolumePathNamesForVolumeNameW = modkernel32.NewProc("GetVolumePathNamesForVolumeNameW") + procQueryDosDeviceW = modkernel32.NewProc("QueryDosDeviceW") + procSetVolumeLabelW = modkernel32.NewProc("SetVolumeLabelW") + procSetVolumeMountPointW = modkernel32.NewProc("SetVolumeMountPointW") procWSAStartup = modws2_32.NewProc("WSAStartup") procWSACleanup = modws2_32.NewProc("WSACleanup") procWSAIoctl = modws2_32.NewProc("WSAIoctl") @@ -190,9 +248,11 @@ var ( procAllocateAndInitializeSid = modadvapi32.NewProc("AllocateAndInitializeSid") procFreeSid = modadvapi32.NewProc("FreeSid") procEqualSid = modadvapi32.NewProc("EqualSid") + procCheckTokenMembership = modadvapi32.NewProc("CheckTokenMembership") procOpenProcessToken = modadvapi32.NewProc("OpenProcessToken") procGetTokenInformation = modadvapi32.NewProc("GetTokenInformation") procGetUserProfileDirectoryW = moduserenv.NewProc("GetUserProfileDirectoryW") + procGetSystemDirectoryW = modkernel32.NewProc("GetSystemDirectoryW") ) func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) { @@ -200,7 +260,7 @@ func RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Hand handle = Handle(r0) if handle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -212,7 +272,7 @@ func DeregisterEventSource(handle Handle) (err error) { r1, _, e1 := syscall.Syscall(procDeregisterEventSource.Addr(), 1, uintptr(handle), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -224,7 +284,7 @@ func ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrS r1, _, e1 := syscall.Syscall9(procReportEventW.Addr(), 9, uintptr(log), uintptr(etype), uintptr(category), uintptr(eventId), uintptr(usrSId), uintptr(numStrings), uintptr(dataSize), uintptr(unsafe.Pointer(strings)), uintptr(unsafe.Pointer(rawData))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -237,7 +297,7 @@ func OpenSCManager(machineName *uint16, databaseName *uint16, access uint32) (ha handle = Handle(r0) if handle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -249,7 +309,7 @@ func CloseServiceHandle(handle Handle) (err error) { r1, _, e1 := syscall.Syscall(procCloseServiceHandle.Addr(), 1, uintptr(handle), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -262,7 +322,7 @@ func CreateService(mgr Handle, serviceName *uint16, displayName *uint16, access handle = Handle(r0) if handle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -275,7 +335,7 @@ func OpenService(mgr Handle, serviceName *uint16, access uint32) (handle Handle, handle = Handle(r0) if handle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -287,7 +347,7 @@ func DeleteService(service Handle) (err error) { r1, _, e1 := syscall.Syscall(procDeleteService.Addr(), 1, uintptr(service), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -299,7 +359,7 @@ func StartService(service Handle, numArgs uint32, argVectors **uint16) (err erro r1, _, e1 := syscall.Syscall(procStartServiceW.Addr(), 3, uintptr(service), uintptr(numArgs), uintptr(unsafe.Pointer(argVectors))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -311,7 +371,7 @@ func QueryServiceStatus(service Handle, status *SERVICE_STATUS) (err error) { r1, _, e1 := syscall.Syscall(procQueryServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(status)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -323,7 +383,7 @@ func ControlService(service Handle, control uint32, status *SERVICE_STATUS) (err r1, _, e1 := syscall.Syscall(procControlService.Addr(), 3, uintptr(service), uintptr(control), uintptr(unsafe.Pointer(status))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -335,7 +395,7 @@ func StartServiceCtrlDispatcher(serviceTable *SERVICE_TABLE_ENTRY) (err error) { r1, _, e1 := syscall.Syscall(procStartServiceCtrlDispatcherW.Addr(), 1, uintptr(unsafe.Pointer(serviceTable)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -347,7 +407,7 @@ func SetServiceStatus(service Handle, serviceStatus *SERVICE_STATUS) (err error) r1, _, e1 := syscall.Syscall(procSetServiceStatus.Addr(), 2, uintptr(service), uintptr(unsafe.Pointer(serviceStatus)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -359,7 +419,7 @@ func ChangeServiceConfig(service Handle, serviceType uint32, startType uint32, e r1, _, e1 := syscall.Syscall12(procChangeServiceConfigW.Addr(), 11, uintptr(service), uintptr(serviceType), uintptr(startType), uintptr(errorControl), uintptr(unsafe.Pointer(binaryPathName)), uintptr(unsafe.Pointer(loadOrderGroup)), uintptr(unsafe.Pointer(tagId)), uintptr(unsafe.Pointer(dependencies)), uintptr(unsafe.Pointer(serviceStartName)), uintptr(unsafe.Pointer(password)), uintptr(unsafe.Pointer(displayName)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -371,7 +431,7 @@ func QueryServiceConfig(service Handle, serviceConfig *QUERY_SERVICE_CONFIG, buf r1, _, e1 := syscall.Syscall6(procQueryServiceConfigW.Addr(), 4, uintptr(service), uintptr(unsafe.Pointer(serviceConfig)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -383,7 +443,7 @@ func ChangeServiceConfig2(service Handle, infoLevel uint32, info *byte) (err err r1, _, e1 := syscall.Syscall(procChangeServiceConfig2W.Addr(), 3, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(info))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -395,7 +455,31 @@ func QueryServiceConfig2(service Handle, infoLevel uint32, buff *byte, buffSize r1, _, e1 := syscall.Syscall6(procQueryServiceConfig2W.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func EnumServicesStatusEx(mgr Handle, infoLevel uint32, serviceType uint32, serviceState uint32, services *byte, bufSize uint32, bytesNeeded *uint32, servicesReturned *uint32, resumeHandle *uint32, groupName *uint16) (err error) { + r1, _, e1 := syscall.Syscall12(procEnumServicesStatusExW.Addr(), 10, uintptr(mgr), uintptr(infoLevel), uintptr(serviceType), uintptr(serviceState), uintptr(unsafe.Pointer(services)), uintptr(bufSize), uintptr(unsafe.Pointer(bytesNeeded)), uintptr(unsafe.Pointer(servicesReturned)), uintptr(unsafe.Pointer(resumeHandle)), uintptr(unsafe.Pointer(groupName)), 0, 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func QueryServiceStatusEx(service Handle, infoLevel uint32, buff *byte, buffSize uint32, bytesNeeded *uint32) (err error) { + r1, _, e1 := syscall.Syscall6(procQueryServiceStatusEx.Addr(), 5, uintptr(service), uintptr(infoLevel), uintptr(unsafe.Pointer(buff)), uintptr(buffSize), uintptr(unsafe.Pointer(bytesNeeded)), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -425,7 +509,7 @@ func _LoadLibrary(libname *uint16) (handle Handle, err error) { handle = Handle(r0) if handle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -447,7 +531,7 @@ func _LoadLibraryEx(libname *uint16, zero Handle, flags uintptr) (handle Handle, handle = Handle(r0) if handle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -459,7 +543,7 @@ func FreeLibrary(handle Handle) (err error) { r1, _, e1 := syscall.Syscall(procFreeLibrary.Addr(), 1, uintptr(handle), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -481,7 +565,7 @@ func _GetProcAddress(module Handle, procname *byte) (proc uintptr, err error) { proc = uintptr(r0) if proc == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -494,7 +578,7 @@ func GetVersion() (ver uint32, err error) { ver = uint32(r0) if ver == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -511,7 +595,7 @@ func FormatMessage(flags uint32, msgsrc uintptr, msgid uint32, langid uint32, bu n = uint32(r0) if n == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -529,7 +613,7 @@ func CreateFile(name *uint16, access uint32, mode uint32, sa *SecurityAttributes handle = Handle(r0) if handle == InvalidHandle { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -545,7 +629,7 @@ func ReadFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) ( r1, _, e1 := syscall.Syscall6(procReadFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -561,7 +645,7 @@ func WriteFile(handle Handle, buf []byte, done *uint32, overlapped *Overlapped) r1, _, e1 := syscall.Syscall6(procWriteFile.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(_p0)), uintptr(len(buf)), uintptr(unsafe.Pointer(done)), uintptr(unsafe.Pointer(overlapped)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -574,7 +658,7 @@ func SetFilePointer(handle Handle, lowoffset int32, highoffsetptr *int32, whence newlowoffset = uint32(r0) if newlowoffset == 0xffffffff { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -586,7 +670,7 @@ func CloseHandle(handle Handle) (err error) { r1, _, e1 := syscall.Syscall(procCloseHandle.Addr(), 1, uintptr(handle), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -594,12 +678,24 @@ func CloseHandle(handle Handle) (err error) { return } -func GetStdHandle(stdhandle int) (handle Handle, err error) { +func GetStdHandle(stdhandle uint32) (handle Handle, err error) { r0, _, e1 := syscall.Syscall(procGetStdHandle.Addr(), 1, uintptr(stdhandle), 0, 0) handle = Handle(r0) if handle == InvalidHandle { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func SetStdHandle(stdhandle uint32, handle Handle) (err error) { + r1, _, e1 := syscall.Syscall(procSetStdHandle.Addr(), 2, uintptr(stdhandle), uintptr(handle), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -612,7 +708,7 @@ func findFirstFile1(name *uint16, data *win32finddata1) (handle Handle, err erro handle = Handle(r0) if handle == InvalidHandle { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -624,7 +720,7 @@ func findNextFile1(handle Handle, data *win32finddata1) (err error) { r1, _, e1 := syscall.Syscall(procFindNextFileW.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -636,7 +732,7 @@ func FindClose(handle Handle) (err error) { r1, _, e1 := syscall.Syscall(procFindClose.Addr(), 1, uintptr(handle), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -648,7 +744,7 @@ func GetFileInformationByHandle(handle Handle, data *ByHandleFileInformation) (e r1, _, e1 := syscall.Syscall(procGetFileInformationByHandle.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(data)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -661,7 +757,7 @@ func GetCurrentDirectory(buflen uint32, buf *uint16) (n uint32, err error) { n = uint32(r0) if n == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -673,7 +769,7 @@ func SetCurrentDirectory(path *uint16) (err error) { r1, _, e1 := syscall.Syscall(procSetCurrentDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -685,7 +781,7 @@ func CreateDirectory(path *uint16, sa *SecurityAttributes) (err error) { r1, _, e1 := syscall.Syscall(procCreateDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(path)), uintptr(unsafe.Pointer(sa)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -697,7 +793,7 @@ func RemoveDirectory(path *uint16) (err error) { r1, _, e1 := syscall.Syscall(procRemoveDirectoryW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -709,7 +805,7 @@ func DeleteFile(path *uint16) (err error) { r1, _, e1 := syscall.Syscall(procDeleteFileW.Addr(), 1, uintptr(unsafe.Pointer(path)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -721,7 +817,7 @@ func MoveFile(from *uint16, to *uint16) (err error) { r1, _, e1 := syscall.Syscall(procMoveFileW.Addr(), 2, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -733,7 +829,7 @@ func MoveFileEx(from *uint16, to *uint16, flags uint32) (err error) { r1, _, e1 := syscall.Syscall(procMoveFileExW.Addr(), 3, uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(to)), uintptr(flags)) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -745,7 +841,7 @@ func GetComputerName(buf *uint16, n *uint32) (err error) { r1, _, e1 := syscall.Syscall(procGetComputerNameW.Addr(), 2, uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -757,7 +853,7 @@ func GetComputerNameEx(nametype uint32, buf *uint16, n *uint32) (err error) { r1, _, e1 := syscall.Syscall(procGetComputerNameExW.Addr(), 3, uintptr(nametype), uintptr(unsafe.Pointer(buf)), uintptr(unsafe.Pointer(n))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -769,7 +865,7 @@ func SetEndOfFile(handle Handle) (err error) { r1, _, e1 := syscall.Syscall(procSetEndOfFile.Addr(), 1, uintptr(handle), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -782,12 +878,17 @@ func GetSystemTimeAsFileTime(time *Filetime) { return } +func GetSystemTimePreciseAsFileTime(time *Filetime) { + syscall.Syscall(procGetSystemTimePreciseAsFileTime.Addr(), 1, uintptr(unsafe.Pointer(time)), 0, 0) + return +} + func GetTimeZoneInformation(tzi *Timezoneinformation) (rc uint32, err error) { r0, _, e1 := syscall.Syscall(procGetTimeZoneInformation.Addr(), 1, uintptr(unsafe.Pointer(tzi)), 0, 0) rc = uint32(r0) if rc == 0xffffffff { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -800,7 +901,7 @@ func CreateIoCompletionPort(filehandle Handle, cphandle Handle, key uint32, thre handle = Handle(r0) if handle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -812,7 +913,7 @@ func GetQueuedCompletionStatus(cphandle Handle, qty *uint32, key *uint32, overla r1, _, e1 := syscall.Syscall6(procGetQueuedCompletionStatus.Addr(), 5, uintptr(cphandle), uintptr(unsafe.Pointer(qty)), uintptr(unsafe.Pointer(key)), uintptr(unsafe.Pointer(overlapped)), uintptr(timeout), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -824,7 +925,7 @@ func PostQueuedCompletionStatus(cphandle Handle, qty uint32, key uint32, overlap r1, _, e1 := syscall.Syscall6(procPostQueuedCompletionStatus.Addr(), 4, uintptr(cphandle), uintptr(qty), uintptr(key), uintptr(unsafe.Pointer(overlapped)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -836,7 +937,7 @@ func CancelIo(s Handle) (err error) { r1, _, e1 := syscall.Syscall(procCancelIo.Addr(), 1, uintptr(s), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -848,7 +949,7 @@ func CancelIoEx(s Handle, o *Overlapped) (err error) { r1, _, e1 := syscall.Syscall(procCancelIoEx.Addr(), 2, uintptr(s), uintptr(unsafe.Pointer(o)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -866,7 +967,7 @@ func CreateProcess(appName *uint16, commandLine *uint16, procSecurity *SecurityA r1, _, e1 := syscall.Syscall12(procCreateProcessW.Addr(), 10, uintptr(unsafe.Pointer(appName)), uintptr(unsafe.Pointer(commandLine)), uintptr(unsafe.Pointer(procSecurity)), uintptr(unsafe.Pointer(threadSecurity)), uintptr(_p0), uintptr(creationFlags), uintptr(unsafe.Pointer(env)), uintptr(unsafe.Pointer(currentDir)), uintptr(unsafe.Pointer(startupInfo)), uintptr(unsafe.Pointer(outProcInfo)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -885,7 +986,7 @@ func OpenProcess(da uint32, inheritHandle bool, pid uint32) (handle Handle, err handle = Handle(r0) if handle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -897,7 +998,7 @@ func TerminateProcess(handle Handle, exitcode uint32) (err error) { r1, _, e1 := syscall.Syscall(procTerminateProcess.Addr(), 2, uintptr(handle), uintptr(exitcode), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -909,7 +1010,7 @@ func GetExitCodeProcess(handle Handle, exitcode *uint32) (err error) { r1, _, e1 := syscall.Syscall(procGetExitCodeProcess.Addr(), 2, uintptr(handle), uintptr(unsafe.Pointer(exitcode)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -921,7 +1022,7 @@ func GetStartupInfo(startupInfo *StartupInfo) (err error) { r1, _, e1 := syscall.Syscall(procGetStartupInfoW.Addr(), 1, uintptr(unsafe.Pointer(startupInfo)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -934,7 +1035,7 @@ func GetCurrentProcess() (pseudoHandle Handle, err error) { pseudoHandle = Handle(r0) if pseudoHandle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -946,7 +1047,7 @@ func GetProcessTimes(handle Handle, creationTime *Filetime, exitTime *Filetime, r1, _, e1 := syscall.Syscall6(procGetProcessTimes.Addr(), 5, uintptr(handle), uintptr(unsafe.Pointer(creationTime)), uintptr(unsafe.Pointer(exitTime)), uintptr(unsafe.Pointer(kernelTime)), uintptr(unsafe.Pointer(userTime)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -964,7 +1065,7 @@ func DuplicateHandle(hSourceProcessHandle Handle, hSourceHandle Handle, hTargetP r1, _, e1 := syscall.Syscall9(procDuplicateHandle.Addr(), 7, uintptr(hSourceProcessHandle), uintptr(hSourceHandle), uintptr(hTargetProcessHandle), uintptr(unsafe.Pointer(lpTargetHandle)), uintptr(dwDesiredAccess), uintptr(_p0), uintptr(dwOptions), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -977,7 +1078,26 @@ func WaitForSingleObject(handle Handle, waitMilliseconds uint32) (event uint32, event = uint32(r0) if event == 0xffffffff { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func waitForMultipleObjects(count uint32, handles uintptr, waitAll bool, waitMilliseconds uint32) (event uint32, err error) { + var _p0 uint32 + if waitAll { + _p0 = 1 + } else { + _p0 = 0 + } + r0, _, e1 := syscall.Syscall6(procWaitForMultipleObjects.Addr(), 4, uintptr(count), uintptr(handles), uintptr(_p0), uintptr(waitMilliseconds), 0, 0) + event = uint32(r0) + if event == 0xffffffff { + if e1 != 0 { + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -990,7 +1110,7 @@ func GetTempPath(buflen uint32, buf *uint16) (n uint32, err error) { n = uint32(r0) if n == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1002,7 +1122,7 @@ func CreatePipe(readhandle *Handle, writehandle *Handle, sa *SecurityAttributes, r1, _, e1 := syscall.Syscall6(procCreatePipe.Addr(), 4, uintptr(unsafe.Pointer(readhandle)), uintptr(unsafe.Pointer(writehandle)), uintptr(unsafe.Pointer(sa)), uintptr(size), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1015,7 +1135,7 @@ func GetFileType(filehandle Handle) (n uint32, err error) { n = uint32(r0) if n == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1027,7 +1147,7 @@ func CryptAcquireContext(provhandle *Handle, container *uint16, provider *uint16 r1, _, e1 := syscall.Syscall6(procCryptAcquireContextW.Addr(), 5, uintptr(unsafe.Pointer(provhandle)), uintptr(unsafe.Pointer(container)), uintptr(unsafe.Pointer(provider)), uintptr(provtype), uintptr(flags), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1039,7 +1159,7 @@ func CryptReleaseContext(provhandle Handle, flags uint32) (err error) { r1, _, e1 := syscall.Syscall(procCryptReleaseContext.Addr(), 2, uintptr(provhandle), uintptr(flags), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1051,7 +1171,7 @@ func CryptGenRandom(provhandle Handle, buflen uint32, buf *byte) (err error) { r1, _, e1 := syscall.Syscall(procCryptGenRandom.Addr(), 3, uintptr(provhandle), uintptr(buflen), uintptr(unsafe.Pointer(buf))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1064,7 +1184,7 @@ func GetEnvironmentStrings() (envs *uint16, err error) { envs = (*uint16)(unsafe.Pointer(r0)) if envs == nil { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1076,7 +1196,7 @@ func FreeEnvironmentStrings(envs *uint16) (err error) { r1, _, e1 := syscall.Syscall(procFreeEnvironmentStringsW.Addr(), 1, uintptr(unsafe.Pointer(envs)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1089,7 +1209,7 @@ func GetEnvironmentVariable(name *uint16, buffer *uint16, size uint32) (n uint32 n = uint32(r0) if n == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1101,7 +1221,7 @@ func SetEnvironmentVariable(name *uint16, value *uint16) (err error) { r1, _, e1 := syscall.Syscall(procSetEnvironmentVariableW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(value)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1113,7 +1233,7 @@ func SetFileTime(handle Handle, ctime *Filetime, atime *Filetime, wtime *Filetim r1, _, e1 := syscall.Syscall6(procSetFileTime.Addr(), 4, uintptr(handle), uintptr(unsafe.Pointer(ctime)), uintptr(unsafe.Pointer(atime)), uintptr(unsafe.Pointer(wtime)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1126,7 +1246,7 @@ func GetFileAttributes(name *uint16) (attrs uint32, err error) { attrs = uint32(r0) if attrs == INVALID_FILE_ATTRIBUTES { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1138,7 +1258,7 @@ func SetFileAttributes(name *uint16, attrs uint32) (err error) { r1, _, e1 := syscall.Syscall(procSetFileAttributesW.Addr(), 2, uintptr(unsafe.Pointer(name)), uintptr(attrs), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1150,7 +1270,7 @@ func GetFileAttributesEx(name *uint16, level uint32, info *byte) (err error) { r1, _, e1 := syscall.Syscall(procGetFileAttributesExW.Addr(), 3, uintptr(unsafe.Pointer(name)), uintptr(level), uintptr(unsafe.Pointer(info))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1169,7 +1289,7 @@ func CommandLineToArgv(cmd *uint16, argc *int32) (argv *[8192]*[8192]uint16, err argv = (*[8192]*[8192]uint16)(unsafe.Pointer(r0)) if argv == nil { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1182,7 +1302,7 @@ func LocalFree(hmem Handle) (handle Handle, err error) { handle = Handle(r0) if handle != 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1194,7 +1314,7 @@ func SetHandleInformation(handle Handle, mask uint32, flags uint32) (err error) r1, _, e1 := syscall.Syscall(procSetHandleInformation.Addr(), 3, uintptr(handle), uintptr(mask), uintptr(flags)) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1206,7 +1326,7 @@ func FlushFileBuffers(handle Handle) (err error) { r1, _, e1 := syscall.Syscall(procFlushFileBuffers.Addr(), 1, uintptr(handle), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1219,7 +1339,7 @@ func GetFullPathName(path *uint16, buflen uint32, buf *uint16, fname **uint16) ( n = uint32(r0) if n == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1232,7 +1352,7 @@ func GetLongPathName(path *uint16, buf *uint16, buflen uint32) (n uint32, err er n = uint32(r0) if n == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1245,7 +1365,7 @@ func GetShortPathName(longpath *uint16, shortpath *uint16, buflen uint32) (n uin n = uint32(r0) if n == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1258,7 +1378,7 @@ func CreateFileMapping(fhandle Handle, sa *SecurityAttributes, prot uint32, maxS handle = Handle(r0) if handle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1271,7 +1391,7 @@ func MapViewOfFile(handle Handle, access uint32, offsetHigh uint32, offsetLow ui addr = uintptr(r0) if addr == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1283,7 +1403,7 @@ func UnmapViewOfFile(addr uintptr) (err error) { r1, _, e1 := syscall.Syscall(procUnmapViewOfFile.Addr(), 1, uintptr(addr), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1295,7 +1415,7 @@ func FlushViewOfFile(addr uintptr, length uintptr) (err error) { r1, _, e1 := syscall.Syscall(procFlushViewOfFile.Addr(), 2, uintptr(addr), uintptr(length), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1307,7 +1427,7 @@ func VirtualLock(addr uintptr, length uintptr) (err error) { r1, _, e1 := syscall.Syscall(procVirtualLock.Addr(), 2, uintptr(addr), uintptr(length), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1319,7 +1439,44 @@ func VirtualUnlock(addr uintptr, length uintptr) (err error) { r1, _, e1 := syscall.Syscall(procVirtualUnlock.Addr(), 2, uintptr(addr), uintptr(length), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func VirtualAlloc(address uintptr, size uintptr, alloctype uint32, protect uint32) (value uintptr, err error) { + r0, _, e1 := syscall.Syscall6(procVirtualAlloc.Addr(), 4, uintptr(address), uintptr(size), uintptr(alloctype), uintptr(protect), 0, 0) + value = uintptr(r0) + if value == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func VirtualFree(address uintptr, size uintptr, freetype uint32) (err error) { + r1, _, e1 := syscall.Syscall(procVirtualFree.Addr(), 3, uintptr(address), uintptr(size), uintptr(freetype)) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func VirtualProtect(address uintptr, size uintptr, newprotect uint32, oldprotect *uint32) (err error) { + r1, _, e1 := syscall.Syscall6(procVirtualProtect.Addr(), 4, uintptr(address), uintptr(size), uintptr(newprotect), uintptr(unsafe.Pointer(oldprotect)), 0, 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1331,7 +1488,7 @@ func TransmitFile(s Handle, handle Handle, bytesToWrite uint32, bytsPerSend uint r1, _, e1 := syscall.Syscall9(procTransmitFile.Addr(), 7, uintptr(s), uintptr(handle), uintptr(bytesToWrite), uintptr(bytsPerSend), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(transmitFileBuf)), uintptr(flags), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1349,7 +1506,7 @@ func ReadDirectoryChanges(handle Handle, buf *byte, buflen uint32, watchSubTree r1, _, e1 := syscall.Syscall9(procReadDirectoryChangesW.Addr(), 8, uintptr(handle), uintptr(unsafe.Pointer(buf)), uintptr(buflen), uintptr(_p0), uintptr(mask), uintptr(unsafe.Pointer(retlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1362,7 +1519,7 @@ func CertOpenSystemStore(hprov Handle, name *uint16) (store Handle, err error) { store = Handle(r0) if store == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1375,7 +1532,7 @@ func CertOpenStore(storeProvider uintptr, msgAndCertEncodingType uint32, cryptPr handle = Handle(r0) if handle == InvalidHandle { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1388,7 +1545,7 @@ func CertEnumCertificatesInStore(store Handle, prevContext *CertContext) (contex context = (*CertContext)(unsafe.Pointer(r0)) if context == nil { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1400,7 +1557,7 @@ func CertAddCertificateContextToStore(store Handle, certContext *CertContext, ad r1, _, e1 := syscall.Syscall6(procCertAddCertificateContextToStore.Addr(), 4, uintptr(store), uintptr(unsafe.Pointer(certContext)), uintptr(addDisposition), uintptr(unsafe.Pointer(storeContext)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1412,7 +1569,7 @@ func CertCloseStore(store Handle, flags uint32) (err error) { r1, _, e1 := syscall.Syscall(procCertCloseStore.Addr(), 2, uintptr(store), uintptr(flags), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1424,7 +1581,7 @@ func CertGetCertificateChain(engine Handle, leaf *CertContext, time *Filetime, a r1, _, e1 := syscall.Syscall9(procCertGetCertificateChain.Addr(), 8, uintptr(engine), uintptr(unsafe.Pointer(leaf)), uintptr(unsafe.Pointer(time)), uintptr(additionalStore), uintptr(unsafe.Pointer(para)), uintptr(flags), uintptr(reserved), uintptr(unsafe.Pointer(chainCtx)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1442,7 +1599,7 @@ func CertCreateCertificateContext(certEncodingType uint32, certEncoded *byte, en context = (*CertContext)(unsafe.Pointer(r0)) if context == nil { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1454,7 +1611,7 @@ func CertFreeCertificateContext(ctx *CertContext) (err error) { r1, _, e1 := syscall.Syscall(procCertFreeCertificateContext.Addr(), 1, uintptr(unsafe.Pointer(ctx)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1466,7 +1623,7 @@ func CertVerifyCertificateChainPolicy(policyOID uintptr, chain *CertChainContext r1, _, e1 := syscall.Syscall6(procCertVerifyCertificateChainPolicy.Addr(), 4, uintptr(policyOID), uintptr(unsafe.Pointer(chain)), uintptr(unsafe.Pointer(para)), uintptr(unsafe.Pointer(status)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1524,7 +1681,31 @@ func GetConsoleMode(console Handle, mode *uint32) (err error) { r1, _, e1 := syscall.Syscall(procGetConsoleMode.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(mode)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func SetConsoleMode(console Handle, mode uint32) (err error) { + r1, _, e1 := syscall.Syscall(procSetConsoleMode.Addr(), 2, uintptr(console), uintptr(mode), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func GetConsoleScreenBufferInfo(console Handle, info *ConsoleScreenBufferInfo) (err error) { + r1, _, e1 := syscall.Syscall(procGetConsoleScreenBufferInfo.Addr(), 2, uintptr(console), uintptr(unsafe.Pointer(info)), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1536,7 +1717,7 @@ func WriteConsole(console Handle, buf *uint16, towrite uint32, written *uint32, r1, _, e1 := syscall.Syscall6(procWriteConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(towrite), uintptr(unsafe.Pointer(written)), uintptr(unsafe.Pointer(reserved)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1548,7 +1729,7 @@ func ReadConsole(console Handle, buf *uint16, toread uint32, read *uint32, input r1, _, e1 := syscall.Syscall6(procReadConsoleW.Addr(), 5, uintptr(console), uintptr(unsafe.Pointer(buf)), uintptr(toread), uintptr(unsafe.Pointer(read)), uintptr(unsafe.Pointer(inputControl)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1561,7 +1742,7 @@ func CreateToolhelp32Snapshot(flags uint32, processId uint32) (handle Handle, er handle = Handle(r0) if handle == InvalidHandle { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1573,7 +1754,7 @@ func Process32First(snapshot Handle, procEntry *ProcessEntry32) (err error) { r1, _, e1 := syscall.Syscall(procProcess32FirstW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1585,7 +1766,7 @@ func Process32Next(snapshot Handle, procEntry *ProcessEntry32) (err error) { r1, _, e1 := syscall.Syscall(procProcess32NextW.Addr(), 2, uintptr(snapshot), uintptr(unsafe.Pointer(procEntry)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1597,7 +1778,7 @@ func DeviceIoControl(handle Handle, ioControlCode uint32, inBuffer *byte, inBuff r1, _, e1 := syscall.Syscall9(procDeviceIoControl.Addr(), 8, uintptr(handle), uintptr(ioControlCode), uintptr(unsafe.Pointer(inBuffer)), uintptr(inBufferSize), uintptr(unsafe.Pointer(outBuffer)), uintptr(outBufferSize), uintptr(unsafe.Pointer(bytesReturned)), uintptr(unsafe.Pointer(overlapped)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1609,7 +1790,7 @@ func CreateSymbolicLink(symlinkfilename *uint16, targetfilename *uint16, flags u r1, _, e1 := syscall.Syscall(procCreateSymbolicLinkW.Addr(), 3, uintptr(unsafe.Pointer(symlinkfilename)), uintptr(unsafe.Pointer(targetfilename)), uintptr(flags)) if r1&0xff == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1621,7 +1802,7 @@ func CreateHardLink(filename *uint16, existingfilename *uint16, reserved uintptr r1, _, e1 := syscall.Syscall(procCreateHardLinkW.Addr(), 3, uintptr(unsafe.Pointer(filename)), uintptr(unsafe.Pointer(existingfilename)), uintptr(reserved)) if r1&0xff == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1635,12 +1816,44 @@ func GetCurrentThreadId() (id uint32) { return } -func CreateEvent(eventAttrs *syscall.SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) { +func CreateEvent(eventAttrs *SecurityAttributes, manualReset uint32, initialState uint32, name *uint16) (handle Handle, err error) { r0, _, e1 := syscall.Syscall6(procCreateEventW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(manualReset), uintptr(initialState), uintptr(unsafe.Pointer(name)), 0, 0) handle = Handle(r0) if handle == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func CreateEventEx(eventAttrs *SecurityAttributes, name *uint16, flags uint32, desiredAccess uint32) (handle Handle, err error) { + r0, _, e1 := syscall.Syscall6(procCreateEventExW.Addr(), 4, uintptr(unsafe.Pointer(eventAttrs)), uintptr(unsafe.Pointer(name)), uintptr(flags), uintptr(desiredAccess), 0, 0) + handle = Handle(r0) + if handle == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func OpenEvent(desiredAccess uint32, inheritHandle bool, name *uint16) (handle Handle, err error) { + var _p0 uint32 + if inheritHandle { + _p0 = 1 + } else { + _p0 = 0 + } + r0, _, e1 := syscall.Syscall(procOpenEventW.Addr(), 3, uintptr(desiredAccess), uintptr(_p0), uintptr(unsafe.Pointer(name))) + handle = Handle(r0) + if handle == 0 { + if e1 != 0 { + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1652,7 +1865,258 @@ func SetEvent(event Handle) (err error) { r1, _, e1 := syscall.Syscall(procSetEvent.Addr(), 1, uintptr(event), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func ResetEvent(event Handle) (err error) { + r1, _, e1 := syscall.Syscall(procResetEvent.Addr(), 1, uintptr(event), 0, 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func PulseEvent(event Handle) (err error) { + r1, _, e1 := syscall.Syscall(procPulseEvent.Addr(), 1, uintptr(event), 0, 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func DefineDosDevice(flags uint32, deviceName *uint16, targetPath *uint16) (err error) { + r1, _, e1 := syscall.Syscall(procDefineDosDeviceW.Addr(), 3, uintptr(flags), uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath))) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func DeleteVolumeMountPoint(volumeMountPoint *uint16) (err error) { + r1, _, e1 := syscall.Syscall(procDeleteVolumeMountPointW.Addr(), 1, uintptr(unsafe.Pointer(volumeMountPoint)), 0, 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func FindFirstVolume(volumeName *uint16, bufferLength uint32) (handle Handle, err error) { + r0, _, e1 := syscall.Syscall(procFindFirstVolumeW.Addr(), 2, uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength), 0) + handle = Handle(r0) + if handle == InvalidHandle { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func FindFirstVolumeMountPoint(rootPathName *uint16, volumeMountPoint *uint16, bufferLength uint32) (handle Handle, err error) { + r0, _, e1 := syscall.Syscall(procFindFirstVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength)) + handle = Handle(r0) + if handle == InvalidHandle { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func FindNextVolume(findVolume Handle, volumeName *uint16, bufferLength uint32) (err error) { + r1, _, e1 := syscall.Syscall(procFindNextVolumeW.Addr(), 3, uintptr(findVolume), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferLength)) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func FindNextVolumeMountPoint(findVolumeMountPoint Handle, volumeMountPoint *uint16, bufferLength uint32) (err error) { + r1, _, e1 := syscall.Syscall(procFindNextVolumeMountPointW.Addr(), 3, uintptr(findVolumeMountPoint), uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(bufferLength)) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func FindVolumeClose(findVolume Handle) (err error) { + r1, _, e1 := syscall.Syscall(procFindVolumeClose.Addr(), 1, uintptr(findVolume), 0, 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func FindVolumeMountPointClose(findVolumeMountPoint Handle) (err error) { + r1, _, e1 := syscall.Syscall(procFindVolumeMountPointClose.Addr(), 1, uintptr(findVolumeMountPoint), 0, 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func GetDriveType(rootPathName *uint16) (driveType uint32) { + r0, _, _ := syscall.Syscall(procGetDriveTypeW.Addr(), 1, uintptr(unsafe.Pointer(rootPathName)), 0, 0) + driveType = uint32(r0) + return +} + +func GetLogicalDrives() (drivesBitMask uint32, err error) { + r0, _, e1 := syscall.Syscall(procGetLogicalDrives.Addr(), 0, 0, 0, 0) + drivesBitMask = uint32(r0) + if drivesBitMask == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func GetLogicalDriveStrings(bufferLength uint32, buffer *uint16) (n uint32, err error) { + r0, _, e1 := syscall.Syscall(procGetLogicalDriveStringsW.Addr(), 2, uintptr(bufferLength), uintptr(unsafe.Pointer(buffer)), 0) + n = uint32(r0) + if n == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func GetVolumeInformation(rootPathName *uint16, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) { + r1, _, e1 := syscall.Syscall9(procGetVolumeInformationW.Addr(), 8, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func GetVolumeInformationByHandle(file Handle, volumeNameBuffer *uint16, volumeNameSize uint32, volumeNameSerialNumber *uint32, maximumComponentLength *uint32, fileSystemFlags *uint32, fileSystemNameBuffer *uint16, fileSystemNameSize uint32) (err error) { + r1, _, e1 := syscall.Syscall9(procGetVolumeInformationByHandleW.Addr(), 8, uintptr(file), uintptr(unsafe.Pointer(volumeNameBuffer)), uintptr(volumeNameSize), uintptr(unsafe.Pointer(volumeNameSerialNumber)), uintptr(unsafe.Pointer(maximumComponentLength)), uintptr(unsafe.Pointer(fileSystemFlags)), uintptr(unsafe.Pointer(fileSystemNameBuffer)), uintptr(fileSystemNameSize), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func GetVolumeNameForVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16, bufferlength uint32) (err error) { + r1, _, e1 := syscall.Syscall(procGetVolumeNameForVolumeMountPointW.Addr(), 3, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), uintptr(bufferlength)) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func GetVolumePathName(fileName *uint16, volumePathName *uint16, bufferLength uint32) (err error) { + r1, _, e1 := syscall.Syscall(procGetVolumePathNameW.Addr(), 3, uintptr(unsafe.Pointer(fileName)), uintptr(unsafe.Pointer(volumePathName)), uintptr(bufferLength)) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func GetVolumePathNamesForVolumeName(volumeName *uint16, volumePathNames *uint16, bufferLength uint32, returnLength *uint32) (err error) { + r1, _, e1 := syscall.Syscall6(procGetVolumePathNamesForVolumeNameW.Addr(), 4, uintptr(unsafe.Pointer(volumeName)), uintptr(unsafe.Pointer(volumePathNames)), uintptr(bufferLength), uintptr(unsafe.Pointer(returnLength)), 0, 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func QueryDosDevice(deviceName *uint16, targetPath *uint16, max uint32) (n uint32, err error) { + r0, _, e1 := syscall.Syscall(procQueryDosDeviceW.Addr(), 3, uintptr(unsafe.Pointer(deviceName)), uintptr(unsafe.Pointer(targetPath)), uintptr(max)) + n = uint32(r0) + if n == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func SetVolumeLabel(rootPathName *uint16, volumeName *uint16) (err error) { + r1, _, e1 := syscall.Syscall(procSetVolumeLabelW.Addr(), 2, uintptr(unsafe.Pointer(rootPathName)), uintptr(unsafe.Pointer(volumeName)), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func SetVolumeMountPoint(volumeMountPoint *uint16, volumeName *uint16) (err error) { + r1, _, e1 := syscall.Syscall(procSetVolumeMountPointW.Addr(), 2, uintptr(unsafe.Pointer(volumeMountPoint)), uintptr(unsafe.Pointer(volumeName)), 0) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1672,7 +2136,7 @@ func WSACleanup() (err error) { r1, _, e1 := syscall.Syscall(procWSACleanup.Addr(), 0, 0, 0, 0) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1684,7 +2148,7 @@ func WSAIoctl(s Handle, iocc uint32, inbuf *byte, cbif uint32, outbuf *byte, cbo r1, _, e1 := syscall.Syscall9(procWSAIoctl.Addr(), 9, uintptr(s), uintptr(iocc), uintptr(unsafe.Pointer(inbuf)), uintptr(cbif), uintptr(unsafe.Pointer(outbuf)), uintptr(cbob), uintptr(unsafe.Pointer(cbbr)), uintptr(unsafe.Pointer(overlapped)), uintptr(completionRoutine)) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1697,7 +2161,7 @@ func socket(af int32, typ int32, protocol int32) (handle Handle, err error) { handle = Handle(r0) if handle == InvalidHandle { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1709,7 +2173,7 @@ func Setsockopt(s Handle, level int32, optname int32, optval *byte, optlen int32 r1, _, e1 := syscall.Syscall6(procsetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(optlen), 0) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1721,7 +2185,7 @@ func Getsockopt(s Handle, level int32, optname int32, optval *byte, optlen *int3 r1, _, e1 := syscall.Syscall6(procgetsockopt.Addr(), 5, uintptr(s), uintptr(level), uintptr(optname), uintptr(unsafe.Pointer(optval)), uintptr(unsafe.Pointer(optlen)), 0) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1733,7 +2197,7 @@ func bind(s Handle, name unsafe.Pointer, namelen int32) (err error) { r1, _, e1 := syscall.Syscall(procbind.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen)) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1745,7 +2209,7 @@ func connect(s Handle, name unsafe.Pointer, namelen int32) (err error) { r1, _, e1 := syscall.Syscall(procconnect.Addr(), 3, uintptr(s), uintptr(name), uintptr(namelen)) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1757,7 +2221,7 @@ func getsockname(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) { r1, _, e1 := syscall.Syscall(procgetsockname.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1769,7 +2233,7 @@ func getpeername(s Handle, rsa *RawSockaddrAny, addrlen *int32) (err error) { r1, _, e1 := syscall.Syscall(procgetpeername.Addr(), 3, uintptr(s), uintptr(unsafe.Pointer(rsa)), uintptr(unsafe.Pointer(addrlen))) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1781,7 +2245,7 @@ func listen(s Handle, backlog int32) (err error) { r1, _, e1 := syscall.Syscall(proclisten.Addr(), 2, uintptr(s), uintptr(backlog), 0) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1793,7 +2257,7 @@ func shutdown(s Handle, how int32) (err error) { r1, _, e1 := syscall.Syscall(procshutdown.Addr(), 2, uintptr(s), uintptr(how), 0) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1805,7 +2269,7 @@ func Closesocket(s Handle) (err error) { r1, _, e1 := syscall.Syscall(procclosesocket.Addr(), 1, uintptr(s), 0, 0) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1817,7 +2281,7 @@ func AcceptEx(ls Handle, as Handle, buf *byte, rxdatalen uint32, laddrlen uint32 r1, _, e1 := syscall.Syscall9(procAcceptEx.Addr(), 8, uintptr(ls), uintptr(as), uintptr(unsafe.Pointer(buf)), uintptr(rxdatalen), uintptr(laddrlen), uintptr(raddrlen), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(overlapped)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1834,7 +2298,7 @@ func WSARecv(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *uint32 r1, _, e1 := syscall.Syscall9(procWSARecv.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1846,7 +2310,7 @@ func WSASend(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32, r1, _, e1 := syscall.Syscall9(procWSASend.Addr(), 7, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine)), 0, 0) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1858,7 +2322,7 @@ func WSARecvFrom(s Handle, bufs *WSABuf, bufcnt uint32, recvd *uint32, flags *ui r1, _, e1 := syscall.Syscall9(procWSARecvFrom.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(recvd)), uintptr(unsafe.Pointer(flags)), uintptr(unsafe.Pointer(from)), uintptr(unsafe.Pointer(fromlen)), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine))) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1870,7 +2334,7 @@ func WSASendTo(s Handle, bufs *WSABuf, bufcnt uint32, sent *uint32, flags uint32 r1, _, e1 := syscall.Syscall9(procWSASendTo.Addr(), 9, uintptr(s), uintptr(unsafe.Pointer(bufs)), uintptr(bufcnt), uintptr(unsafe.Pointer(sent)), uintptr(flags), uintptr(unsafe.Pointer(to)), uintptr(tolen), uintptr(unsafe.Pointer(overlapped)), uintptr(unsafe.Pointer(croutine))) if r1 == socket_error { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1892,7 +2356,7 @@ func _GetHostByName(name *byte) (h *Hostent, err error) { h = (*Hostent)(unsafe.Pointer(r0)) if h == nil { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1919,7 +2383,7 @@ func _GetServByName(name *byte, proto *byte) (s *Servent, err error) { s = (*Servent)(unsafe.Pointer(r0)) if s == nil { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -1947,7 +2411,7 @@ func _GetProtoByName(name *byte) (p *Protoent, err error) { p = (*Protoent)(unsafe.Pointer(r0)) if p == nil { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2016,7 +2480,7 @@ func SetFileCompletionNotificationModes(handle Handle, flags uint8) (err error) r1, _, e1 := syscall.Syscall(procSetFileCompletionNotificationModes.Addr(), 2, uintptr(handle), uintptr(flags), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2029,7 +2493,7 @@ func WSAEnumProtocols(protocols *int32, protocolBuffer *WSAProtocolInfo, bufferL n = int32(r0) if n == -1 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2056,7 +2520,7 @@ func MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, nwrite = int32(r0) if nwrite == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2068,7 +2532,7 @@ func TranslateName(accName *uint16, accNameFormat uint32, desiredNameFormat uint r1, _, e1 := syscall.Syscall6(procTranslateNameW.Addr(), 5, uintptr(unsafe.Pointer(accName)), uintptr(accNameFormat), uintptr(desiredNameFormat), uintptr(unsafe.Pointer(translatedName)), uintptr(unsafe.Pointer(nSize)), 0) if r1&0xff == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2080,7 +2544,7 @@ func GetUserNameEx(nameFormat uint32, nameBuffre *uint16, nSize *uint32) (err er r1, _, e1 := syscall.Syscall(procGetUserNameExW.Addr(), 3, uintptr(nameFormat), uintptr(unsafe.Pointer(nameBuffre)), uintptr(unsafe.Pointer(nSize))) if r1&0xff == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2116,7 +2580,7 @@ func LookupAccountSid(systemName *uint16, sid *SID, name *uint16, nameLen *uint3 r1, _, e1 := syscall.Syscall9(procLookupAccountSidW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(name)), uintptr(unsafe.Pointer(nameLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2128,7 +2592,7 @@ func LookupAccountName(systemName *uint16, accountName *uint16, sid *SID, sidLen r1, _, e1 := syscall.Syscall9(procLookupAccountNameW.Addr(), 7, uintptr(unsafe.Pointer(systemName)), uintptr(unsafe.Pointer(accountName)), uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(sidLen)), uintptr(unsafe.Pointer(refdDomainName)), uintptr(unsafe.Pointer(refdDomainNameLen)), uintptr(unsafe.Pointer(use)), 0, 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2140,7 +2604,7 @@ func ConvertSidToStringSid(sid *SID, stringSid **uint16) (err error) { r1, _, e1 := syscall.Syscall(procConvertSidToStringSidW.Addr(), 2, uintptr(unsafe.Pointer(sid)), uintptr(unsafe.Pointer(stringSid)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2152,7 +2616,7 @@ func ConvertStringSidToSid(stringSid *uint16, sid **SID) (err error) { r1, _, e1 := syscall.Syscall(procConvertStringSidToSidW.Addr(), 2, uintptr(unsafe.Pointer(stringSid)), uintptr(unsafe.Pointer(sid)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2170,7 +2634,7 @@ func CopySid(destSidLen uint32, destSid *SID, srcSid *SID) (err error) { r1, _, e1 := syscall.Syscall(procCopySid.Addr(), 3, uintptr(destSidLen), uintptr(unsafe.Pointer(destSid)), uintptr(unsafe.Pointer(srcSid))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2182,7 +2646,7 @@ func AllocateAndInitializeSid(identAuth *SidIdentifierAuthority, subAuth byte, s r1, _, e1 := syscall.Syscall12(procAllocateAndInitializeSid.Addr(), 11, uintptr(unsafe.Pointer(identAuth)), uintptr(subAuth), uintptr(subAuth0), uintptr(subAuth1), uintptr(subAuth2), uintptr(subAuth3), uintptr(subAuth4), uintptr(subAuth5), uintptr(subAuth6), uintptr(subAuth7), uintptr(unsafe.Pointer(sid)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2194,7 +2658,7 @@ func FreeSid(sid *SID) (err error) { r1, _, e1 := syscall.Syscall(procFreeSid.Addr(), 1, uintptr(unsafe.Pointer(sid)), 0, 0) if r1 != 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2208,11 +2672,23 @@ func EqualSid(sid1 *SID, sid2 *SID) (isEqual bool) { return } +func checkTokenMembership(tokenHandle Token, sidToCheck *SID, isMember *int32) (err error) { + r1, _, e1 := syscall.Syscall(procCheckTokenMembership.Addr(), 3, uintptr(tokenHandle), uintptr(unsafe.Pointer(sidToCheck)), uintptr(unsafe.Pointer(isMember))) + if r1 == 0 { + if e1 != 0 { + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + func OpenProcessToken(h Handle, access uint32, token *Token) (err error) { r1, _, e1 := syscall.Syscall(procOpenProcessToken.Addr(), 3, uintptr(h), uintptr(access), uintptr(unsafe.Pointer(token))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2224,7 +2700,7 @@ func GetTokenInformation(t Token, infoClass uint32, info *byte, infoLen uint32, r1, _, e1 := syscall.Syscall6(procGetTokenInformation.Addr(), 5, uintptr(t), uintptr(infoClass), uintptr(unsafe.Pointer(info)), uintptr(infoLen), uintptr(unsafe.Pointer(returnedLen)), 0) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) } else { err = syscall.EINVAL } @@ -2236,7 +2712,20 @@ func GetUserProfileDirectory(t Token, dir *uint16, dirLen *uint32) (err error) { r1, _, e1 := syscall.Syscall(procGetUserProfileDirectoryW.Addr(), 3, uintptr(t), uintptr(unsafe.Pointer(dir)), uintptr(unsafe.Pointer(dirLen))) if r1 == 0 { if e1 != 0 { - err = error(e1) + err = errnoErr(e1) + } else { + err = syscall.EINVAL + } + } + return +} + +func getSystemDirectory(dir *uint16, dirLen uint32) (len uint32, err error) { + r0, _, e1 := syscall.Syscall(procGetSystemDirectoryW.Addr(), 2, uintptr(unsafe.Pointer(dir)), uintptr(dirLen), 0) + len = uint32(r0) + if len == 0 { + if e1 != 0 { + err = errnoErr(e1) } else { err = syscall.EINVAL } diff --git a/vendor/modules.txt b/vendor/modules.txt index 22530a9..73ca9b8 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -10,7 +10,7 @@ github.com/golang/freetype/truetype # github.com/hashicorp/golang-lru v0.0.0-20160813221303-0a025b7e63ad github.com/hashicorp/golang-lru github.com/hashicorp/golang-lru/simplelru -# golang.org/x/exp v0.0.0-20171209012058-072991165226 +# golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8 golang.org/x/exp/shiny/driver golang.org/x/exp/shiny/screen golang.org/x/exp/shiny/driver/gldriver @@ -23,17 +23,23 @@ golang.org/x/exp/shiny/driver/internal/lifecycler golang.org/x/exp/shiny/driver/internal/win32 golang.org/x/exp/shiny/driver/internal/x11key golang.org/x/exp/shiny/driver/internal/swizzle -# golang.org/x/image v0.0.0-20170331233916-ce0faa1867f5 +# golang.org/x/image v0.0.0-20190227222117-0694c2d4d067 golang.org/x/image/font golang.org/x/image/math/fixed golang.org/x/image/math/f64 -# golang.org/x/mobile v0.0.0-20170307115833-eb9032959f05 +# golang.org/x/mobile v0.0.0-20190318164015-6bd122906c08 +golang.org/x/mobile/app golang.org/x/mobile/event/key golang.org/x/mobile/event/lifecycle golang.org/x/mobile/event/mouse golang.org/x/mobile/event/paint golang.org/x/mobile/event/size -golang.org/x/mobile/geom +golang.org/x/mobile/event/touch +golang.org/x/mobile/exp/gl/glutil golang.org/x/mobile/gl -# golang.org/x/sys v0.0.0-20160717071931-a646d33e2ee3 +golang.org/x/mobile/app/internal/callfn +golang.org/x/mobile/geom +golang.org/x/mobile/internal/mobileinit +golang.org/x/mobile/exp/f32 +# golang.org/x/sys v0.0.0-20190312061237-fead79001313 golang.org/x/sys/windows