├── .github ├── FUNDING.yml └── workflows │ └── clipboard.yml ├── .gitignore ├── Dockerfile ├── LICENSE ├── README.md ├── clipboard.go ├── clipboard_android.c ├── clipboard_android.go ├── clipboard_darwin.go ├── clipboard_darwin.m ├── clipboard_ios.go ├── clipboard_ios.m ├── clipboard_linux.c ├── clipboard_linux.go ├── clipboard_nocgo.go ├── clipboard_test.go ├── clipboard_windows.go ├── cmd ├── gclip-gui │ ├── AndroidManifest.xml │ ├── README.md │ └── main.go └── gclip │ ├── README.md │ └── main.go ├── example_test.go ├── export_test.go ├── go.mod ├── go.sum ├── tests ├── Makefile ├── test-docker.sh └── testdata │ ├── android.png │ ├── clipboard.png │ ├── darwin.png │ ├── ios.png │ ├── linux.png │ └── windows.png └── vendor ├── golang.org └── x │ ├── exp │ ├── AUTHORS │ ├── CONTRIBUTORS │ ├── LICENSE │ ├── PATENTS │ └── shiny │ │ ├── driver │ │ ├── gldriver │ │ │ ├── buffer.go │ │ │ ├── cocoa.go │ │ │ ├── cocoa.m │ │ │ ├── context.go │ │ │ ├── egl.go │ │ │ ├── gldriver.go │ │ │ ├── other.go │ │ │ ├── screen.go │ │ │ ├── texture.go │ │ │ ├── win32.go │ │ │ ├── window.go │ │ │ ├── x11.c │ │ │ └── x11.go │ │ └── internal │ │ │ ├── drawer │ │ │ └── drawer.go │ │ │ ├── errscreen │ │ │ └── errscreen.go │ │ │ ├── event │ │ │ └── event.go │ │ │ ├── lifecycler │ │ │ └── lifecycler.go │ │ │ ├── win32 │ │ │ ├── key.go │ │ │ ├── syscall.go │ │ │ ├── syscall_windows.go │ │ │ ├── win32.go │ │ │ └── zsyscall_windows.go │ │ │ └── x11key │ │ │ ├── table.go │ │ │ └── x11key.go │ │ └── screen │ │ └── screen.go │ ├── image │ ├── LICENSE │ ├── PATENTS │ ├── bmp │ │ ├── reader.go │ │ └── writer.go │ ├── font │ │ ├── basicfont │ │ │ ├── basicfont.go │ │ │ └── data.go │ │ └── font.go │ └── math │ │ ├── f64 │ │ └── f64.go │ │ └── fixed │ │ └── fixed.go │ ├── mobile │ ├── LICENSE │ ├── PATENTS │ ├── app │ │ ├── GoNativeActivity.java │ │ ├── android.c │ │ ├── android.go │ │ ├── app.go │ │ ├── darwin_desktop.go │ │ ├── darwin_desktop.m │ │ ├── darwin_ios.go │ │ ├── darwin_ios.m │ │ ├── doc.go │ │ ├── internal │ │ │ └── callfn │ │ │ │ ├── callfn.go │ │ │ │ ├── callfn_386.s │ │ │ │ ├── callfn_amd64.s │ │ │ │ ├── callfn_arm.s │ │ │ │ └── callfn_arm64.s │ │ ├── shiny.go │ │ ├── x11.c │ │ └── x11.go │ ├── event │ │ ├── key │ │ │ ├── code_string.go │ │ │ └── key.go │ │ ├── lifecycle │ │ │ └── lifecycle.go │ │ ├── mouse │ │ │ └── mouse.go │ │ ├── paint │ │ │ └── paint.go │ │ ├── size │ │ │ └── size.go │ │ └── touch │ │ │ └── touch.go │ ├── exp │ │ ├── f32 │ │ │ ├── affine.go │ │ │ ├── f32.go │ │ │ ├── mat3.go │ │ │ ├── mat4.go │ │ │ ├── table.go │ │ │ ├── vec3.go │ │ │ └── vec4.go │ │ └── gl │ │ │ └── glutil │ │ │ ├── context_darwin_desktop.go │ │ │ ├── context_x11.go │ │ │ ├── doc.go │ │ │ ├── glimage.go │ │ │ └── glutil.go │ ├── geom │ │ └── geom.go │ ├── gl │ │ ├── consts.go │ │ ├── dll_windows.go │ │ ├── doc.go │ │ ├── fn.go │ │ ├── gl.go │ │ ├── gldebug.go │ │ ├── interface.go │ │ ├── types_debug.go │ │ ├── types_prod.go │ │ ├── work.c │ │ ├── work.go │ │ ├── work.h │ │ ├── work_other.go │ │ ├── work_windows.go │ │ ├── work_windows_386.s │ │ └── work_windows_amd64.s │ └── internal │ │ └── mobileinit │ │ ├── ctx_android.go │ │ ├── mobileinit.go │ │ ├── mobileinit_android.go │ │ └── mobileinit_ios.go │ └── sys │ ├── LICENSE │ ├── PATENTS │ ├── internal │ └── unsafeheader │ │ └── unsafeheader.go │ └── windows │ ├── aliases.go │ ├── dll_windows.go │ ├── empty.s │ ├── env_windows.go │ ├── eventlog.go │ ├── exec_windows.go │ ├── memory_windows.go │ ├── mkerrors.bash │ ├── mkknownfolderids.bash │ ├── mksyscall.go │ ├── race.go │ ├── race0.go │ ├── security_windows.go │ ├── service.go │ ├── setupapi_windows.go │ ├── str.go │ ├── syscall.go │ ├── syscall_windows.go │ ├── types_windows.go │ ├── types_windows_386.go │ ├── types_windows_amd64.go │ ├── types_windows_arm.go │ ├── types_windows_arm64.go │ ├── zerrors_windows.go │ ├── zknownfolderids_windows.go │ └── zsyscall_windows.go └── modules.txt /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | 3 | github: [changkun] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] 4 | patreon: # Replace with a single Patreon username 5 | open_collective: # Replace with a single Open Collective username 6 | ko_fi: # Replace with a single Ko-fi username 7 | tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel 8 | community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry 9 | liberapay: # Replace with a single Liberapay username 10 | issuehunt: # Replace with a single IssueHunt username 11 | otechie: # Replace with a single Otechie username 12 | custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2'] 13 | -------------------------------------------------------------------------------- /.github/workflows/clipboard.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The golang.design Initiative Authors. 2 | # All rights reserved. Use of this source code is governed 3 | # by a MIT license that can be found in the LICENSE file. 4 | # 5 | # Written by Changkun Ou 6 | 7 | name: clipboard 8 | 9 | on: 10 | push: 11 | branches: [ main ] 12 | pull_request: 13 | branches: [ main ] 14 | 15 | jobs: 16 | platform_test: 17 | env: 18 | DISPLAY: ':0.0' 19 | runs-on: ${{ matrix.os }} 20 | strategy: 21 | fail-fast: false 22 | matrix: 23 | os: [ubuntu-latest, macos-latest, windows-latest] 24 | go: ['1.17.x', '1.18.x', '1.19.x', '1.20.x'] 25 | steps: 26 | - name: Install and run dependencies (xvfb libx11-dev) 27 | if: ${{ runner.os == 'Linux' }} 28 | run: | 29 | sudo apt update 30 | sudo apt install -y xvfb libx11-dev x11-utils libegl1-mesa-dev libgles2-mesa-dev 31 | Xvfb :0 -screen 0 1024x768x24 > /dev/null 2>&1 & 32 | # Wait for Xvfb 33 | MAX_ATTEMPTS=120 # About 60 seconds 34 | COUNT=0 35 | echo -n "Waiting for Xvfb to be ready..." 36 | while ! xdpyinfo -display "${DISPLAY}" >/dev/null 2>&1; do 37 | echo -n "." 38 | sleep 0.50s 39 | COUNT=$(( COUNT + 1 )) 40 | if [ "${COUNT}" -ge "${MAX_ATTEMPTS}" ]; then 41 | echo " Gave up waiting for X server on ${DISPLAY}" 42 | exit 1 43 | fi 44 | done 45 | echo "Done - Xvfb is ready!" 46 | 47 | - uses: actions/checkout@v2 48 | - uses: actions/setup-go@v2 49 | with: 50 | stable: 'false' 51 | go-version: ${{ matrix.go }} 52 | 53 | - name: Build (${{ matrix.go }}) 54 | run: | 55 | go build -o gclip cmd/gclip/main.go 56 | go build -o gclip-gui cmd/gclip-gui/main.go 57 | 58 | - name: Run Tests with CGO_ENABLED=1 (${{ matrix.go }}) 59 | if: ${{ runner.os == 'Linux' || runner.os == 'macOS'}} 60 | run: | 61 | CGO_ENABLED=1 go test -v -covermode=atomic . 62 | 63 | - name: Run Tests with CGO_ENABLED=0 (${{ matrix.go }}) 64 | if: ${{ runner.os == 'Linux' || runner.os == 'macOS'}} 65 | run: | 66 | CGO_ENABLED=0 go test -v -covermode=atomic . 67 | 68 | - name: Run Tests on Windows (${{ matrix.go }}) 69 | if: ${{ runner.os == 'Windows'}} 70 | run: | 71 | go test -v -covermode=atomic . -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Binaries for programs and plugins 2 | *.exe 3 | *.exe~ 4 | *.dll 5 | *.so 6 | *.dylib 7 | 8 | # Test binary, built with `go test -c` 9 | *.test 10 | 11 | # Output of the go coverage tool, specifically when used with LiteIDE 12 | *.out 13 | 14 | # Dependency directories (remove the comment below to include it) 15 | # vendor/ 16 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The golang.design Initiative Authors. 2 | # All rights reserved. Use of this source code is governed 3 | # by a MIT license that can be found in the LICENSE file. 4 | # 5 | # Written by Changkun Ou 6 | 7 | FROM golang:1.17 8 | RUN apt-get update && apt-get install -y \ 9 | xvfb libx11-dev libegl1-mesa-dev libgles2-mesa-dev \ 10 | && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 11 | WORKDIR /app 12 | COPY . . 13 | CMD [ "sh", "-c", "./tests/test-docker.sh" ] 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Changkun Ou 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /clipboard.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | /* 8 | Package clipboard provides cross platform clipboard access and supports 9 | macOS/Linux/Windows/Android/iOS platform. Before interacting with the 10 | clipboard, one must call Init to assert if it is possible to use this 11 | package: 12 | 13 | err := clipboard.Init() 14 | if err != nil { 15 | panic(err) 16 | } 17 | 18 | The most common operations are `Read` and `Write`. To use them: 19 | 20 | // write/read text format data of the clipboard, and 21 | // the byte buffer regarding the text are UTF8 encoded. 22 | clipboard.Write(clipboard.FmtText, []byte("text data")) 23 | clipboard.Read(clipboard.FmtText) 24 | 25 | // write/read image format data of the clipboard, and 26 | // the byte buffer regarding the image are PNG encoded. 27 | clipboard.Write(clipboard.FmtImage, []byte("image data")) 28 | clipboard.Read(clipboard.FmtImage) 29 | 30 | Note that read/write regarding image format assumes that the bytes are 31 | PNG encoded since it serves the alpha blending purpose that might be 32 | used in other graphical software. 33 | 34 | In addition, `clipboard.Write` returns a channel that can receive an 35 | empty struct as a signal, which indicates the corresponding write call 36 | to the clipboard is outdated, meaning the clipboard has been overwritten 37 | by others and the previously written data is lost. For instance: 38 | 39 | changed := clipboard.Write(clipboard.FmtText, []byte("text data")) 40 | 41 | select { 42 | case <-changed: 43 | println(`"text data" is no longer available from clipboard.`) 44 | } 45 | 46 | You can ignore the returning channel if you don't need this type of 47 | notification. Furthermore, when you need more than just knowing whether 48 | clipboard data is changed, use the watcher API: 49 | 50 | ch := clipboard.Watch(context.TODO(), clipboard.FmtText) 51 | for data := range ch { 52 | // print out clipboard data whenever it is changed 53 | println(string(data)) 54 | } 55 | */ 56 | package clipboard // import "golang.design/x/clipboard" 57 | 58 | import ( 59 | "context" 60 | "errors" 61 | "fmt" 62 | "os" 63 | "sync" 64 | ) 65 | 66 | var ( 67 | // activate only for running tests. 68 | debug = false 69 | errUnavailable = errors.New("clipboard unavailable") 70 | errUnsupported = errors.New("unsupported format") 71 | ) 72 | 73 | // Format represents the format of clipboard data. 74 | type Format int 75 | 76 | // All sorts of supported clipboard data 77 | const ( 78 | // FmtText indicates plain text clipboard format 79 | FmtText Format = iota 80 | // FmtImage indicates image/png clipboard format 81 | FmtImage 82 | ) 83 | 84 | var ( 85 | // Due to the limitation on operating systems (such as darwin), 86 | // concurrent read can even cause panic, use a global lock to 87 | // guarantee one read at a time. 88 | lock = sync.Mutex{} 89 | initOnce sync.Once 90 | initError error 91 | ) 92 | 93 | // Init initializes the clipboard package. It returns an error 94 | // if the clipboard is not available to use. This may happen if the 95 | // target system lacks required dependency, such as libx11-dev in X11 96 | // environment. For example, 97 | // 98 | // err := clipboard.Init() 99 | // if err != nil { 100 | // panic(err) 101 | // } 102 | // 103 | // If Init returns an error, any subsequent Read/Write/Watch call 104 | // may result in an unrecoverable panic. 105 | func Init() error { 106 | initOnce.Do(func() { 107 | initError = initialize() 108 | }) 109 | return initError 110 | } 111 | 112 | // Read returns a chunk of bytes of the clipboard data if it presents 113 | // in the desired format t presents. Otherwise, it returns nil. 114 | func Read(t Format) []byte { 115 | lock.Lock() 116 | defer lock.Unlock() 117 | 118 | buf, err := read(t) 119 | if err != nil { 120 | if debug { 121 | fmt.Fprintf(os.Stderr, "read clipboard err: %v\n", err) 122 | } 123 | return nil 124 | } 125 | return buf 126 | } 127 | 128 | // Write writes a given buffer to the clipboard in a specified format. 129 | // Write returned a receive-only channel can receive an empty struct 130 | // as a signal, which indicates the clipboard has been overwritten from 131 | // this write. 132 | // If format t indicates an image, then the given buf assumes 133 | // the image data is PNG encoded. 134 | func Write(t Format, buf []byte) <-chan struct{} { 135 | lock.Lock() 136 | defer lock.Unlock() 137 | 138 | changed, err := write(t, buf) 139 | if err != nil { 140 | if debug { 141 | fmt.Fprintf(os.Stderr, "write to clipboard err: %v\n", err) 142 | } 143 | return nil 144 | } 145 | return changed 146 | } 147 | 148 | // Watch returns a receive-only channel that received the clipboard data 149 | // whenever any change of clipboard data in the desired format happens. 150 | // 151 | // The returned channel will be closed if the given context is canceled. 152 | func Watch(ctx context.Context, t Format) <-chan []byte { 153 | return watch(ctx, t) 154 | } 155 | -------------------------------------------------------------------------------- /clipboard_android.c: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | //go:build android 8 | 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #define LOG_FATAL(...) __android_log_print(ANDROID_LOG_FATAL, \ 15 | "GOLANG.DESIGN/X/CLIPBOARD", __VA_ARGS__) 16 | 17 | static jmethodID find_method(JNIEnv *env, jclass clazz, const char *name, const char *sig) { 18 | jmethodID m = (*env)->GetMethodID(env, clazz, name, sig); 19 | if (m == 0) { 20 | (*env)->ExceptionClear(env); 21 | LOG_FATAL("cannot find method %s %s", name, sig); 22 | return 0; 23 | } 24 | return m; 25 | } 26 | 27 | jobject get_clipboard(uintptr_t jni_env, uintptr_t ctx) { 28 | JNIEnv *env = (JNIEnv*)jni_env; 29 | jclass ctxClass = (*env)->GetObjectClass(env, (jobject)ctx); 30 | jmethodID getSystemService = find_method(env, ctxClass, "getSystemService", "(Ljava/lang/String;)Ljava/lang/Object;"); 31 | 32 | jstring service = (*env)->NewStringUTF(env, "clipboard"); 33 | jobject ret = (jobject)(*env)->CallObjectMethod(env, (jobject)ctx, getSystemService, service); 34 | jthrowable err = (*env)->ExceptionOccurred(env); 35 | 36 | if (err != NULL) { 37 | LOG_FATAL("cannot find clipboard"); 38 | (*env)->ExceptionClear(env); 39 | return NULL; 40 | } 41 | return ret; 42 | } 43 | 44 | char *clipboard_read_string(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx) { 45 | JNIEnv *env = (JNIEnv*)jni_env; 46 | jobject mgr = get_clipboard(jni_env, ctx); 47 | if (mgr == NULL) { 48 | return NULL; 49 | } 50 | 51 | jclass mgrClass = (*env)->GetObjectClass(env, mgr); 52 | jmethodID getText = find_method(env, mgrClass, "getText", "()Ljava/lang/CharSequence;"); 53 | 54 | jobject content = (jstring)(*env)->CallObjectMethod(env, mgr, getText); 55 | if (content == NULL) { 56 | return NULL; 57 | } 58 | 59 | jclass clzCharSequence = (*env)->GetObjectClass(env, content); 60 | jmethodID toString = (*env)->GetMethodID(env, clzCharSequence, "toString", "()Ljava/lang/String;"); 61 | jobject s = (*env)->CallObjectMethod(env, content, toString); 62 | 63 | const char *chars = (*env)->GetStringUTFChars(env, s, NULL); 64 | char *copy = strdup(chars); 65 | (*env)->ReleaseStringUTFChars(env, s, chars); 66 | return copy; 67 | } 68 | 69 | void clipboard_write_string(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, char *str) { 70 | JNIEnv *env = (JNIEnv*)jni_env; 71 | jobject mgr = get_clipboard(jni_env, ctx); 72 | if (mgr == NULL) { 73 | return; 74 | } 75 | 76 | jclass mgrClass = (*env)->GetObjectClass(env, mgr); 77 | jmethodID setText = find_method(env, mgrClass, "setText", "(Ljava/lang/CharSequence;)V"); 78 | 79 | (*env)->CallVoidMethod(env, mgr, setText, (*env)->NewStringUTF(env, str)); 80 | } 81 | -------------------------------------------------------------------------------- /clipboard_android.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | //go:build android 8 | 9 | package clipboard 10 | 11 | /* 12 | #cgo LDFLAGS: -landroid -llog 13 | 14 | #include 15 | char *clipboard_read_string(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx); 16 | void clipboard_write_string(uintptr_t java_vm, uintptr_t jni_env, uintptr_t ctx, char *str); 17 | 18 | */ 19 | import "C" 20 | import ( 21 | "bytes" 22 | "context" 23 | "time" 24 | "unsafe" 25 | 26 | "golang.org/x/mobile/app" 27 | ) 28 | 29 | func initialize() error { return nil } 30 | 31 | func read(t Format) (buf []byte, err error) { 32 | switch t { 33 | case FmtText: 34 | s := "" 35 | if err := app.RunOnJVM(func(vm, env, ctx uintptr) error { 36 | cs := C.clipboard_read_string(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx)) 37 | if cs == nil { 38 | return nil 39 | } 40 | 41 | s = C.GoString(cs) 42 | C.free(unsafe.Pointer(cs)) 43 | return nil 44 | }); err != nil { 45 | return nil, err 46 | } 47 | return []byte(s), nil 48 | case FmtImage: 49 | return nil, errUnsupported 50 | default: 51 | return nil, errUnsupported 52 | } 53 | } 54 | 55 | // write writes the given data to clipboard and 56 | // returns true if success or false if failed. 57 | func write(t Format, buf []byte) (<-chan struct{}, error) { 58 | done := make(chan struct{}, 1) 59 | switch t { 60 | case FmtText: 61 | cs := C.CString(string(buf)) 62 | defer C.free(unsafe.Pointer(cs)) 63 | 64 | if err := app.RunOnJVM(func(vm, env, ctx uintptr) error { 65 | C.clipboard_write_string(C.uintptr_t(vm), C.uintptr_t(env), C.uintptr_t(ctx), cs) 66 | done <- struct{}{} 67 | return nil 68 | }); err != nil { 69 | return nil, err 70 | } 71 | return done, nil 72 | case FmtImage: 73 | return nil, errUnsupported 74 | default: 75 | return nil, errUnsupported 76 | } 77 | } 78 | 79 | func watch(ctx context.Context, t Format) <-chan []byte { 80 | recv := make(chan []byte, 1) 81 | ti := time.NewTicker(time.Second) 82 | last := Read(t) 83 | go func() { 84 | for { 85 | select { 86 | case <-ctx.Done(): 87 | close(recv) 88 | return 89 | case <-ti.C: 90 | b := Read(t) 91 | if b == nil { 92 | continue 93 | } 94 | if bytes.Compare(last, b) != 0 { 95 | recv <- b 96 | last = b 97 | } 98 | } 99 | } 100 | }() 101 | return recv 102 | } 103 | -------------------------------------------------------------------------------- /clipboard_darwin.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | //go:build darwin && !ios 8 | 9 | package clipboard 10 | 11 | /* 12 | #cgo CFLAGS: -x objective-c 13 | #cgo LDFLAGS: -framework Foundation -framework Cocoa 14 | #import 15 | #import 16 | 17 | unsigned int clipboard_read_string(void **out); 18 | unsigned int clipboard_read_image(void **out); 19 | int clipboard_write_string(const void *bytes, NSInteger n); 20 | int clipboard_write_image(const void *bytes, NSInteger n); 21 | NSInteger clipboard_change_count(); 22 | */ 23 | import "C" 24 | import ( 25 | "context" 26 | "time" 27 | "unsafe" 28 | ) 29 | 30 | func initialize() error { return nil } 31 | 32 | func read(t Format) (buf []byte, err error) { 33 | var ( 34 | data unsafe.Pointer 35 | n C.uint 36 | ) 37 | switch t { 38 | case FmtText: 39 | n = C.clipboard_read_string(&data) 40 | case FmtImage: 41 | n = C.clipboard_read_image(&data) 42 | } 43 | if data == nil { 44 | return nil, errUnavailable 45 | } 46 | defer C.free(unsafe.Pointer(data)) 47 | if n == 0 { 48 | return nil, nil 49 | } 50 | return C.GoBytes(data, C.int(n)), nil 51 | } 52 | 53 | // write writes the given data to clipboard and 54 | // returns true if success or false if failed. 55 | func write(t Format, buf []byte) (<-chan struct{}, error) { 56 | var ok C.int 57 | switch t { 58 | case FmtText: 59 | if len(buf) == 0 { 60 | ok = C.clipboard_write_string(unsafe.Pointer(nil), 0) 61 | } else { 62 | ok = C.clipboard_write_string(unsafe.Pointer(&buf[0]), 63 | C.NSInteger(len(buf))) 64 | } 65 | case FmtImage: 66 | if len(buf) == 0 { 67 | ok = C.clipboard_write_image(unsafe.Pointer(nil), 0) 68 | } else { 69 | ok = C.clipboard_write_image(unsafe.Pointer(&buf[0]), 70 | C.NSInteger(len(buf))) 71 | } 72 | default: 73 | return nil, errUnsupported 74 | } 75 | if ok != 0 { 76 | return nil, errUnavailable 77 | } 78 | 79 | // use unbuffered data to prevent goroutine leak 80 | changed := make(chan struct{}, 1) 81 | cnt := C.long(C.clipboard_change_count()) 82 | go func() { 83 | for { 84 | // not sure if we are too slow or the user too fast :) 85 | time.Sleep(time.Second) 86 | cur := C.long(C.clipboard_change_count()) 87 | if cnt != cur { 88 | changed <- struct{}{} 89 | close(changed) 90 | return 91 | } 92 | } 93 | }() 94 | return changed, nil 95 | } 96 | 97 | func watch(ctx context.Context, t Format) <-chan []byte { 98 | recv := make(chan []byte, 1) 99 | // not sure if we are too slow or the user too fast :) 100 | ti := time.NewTicker(time.Second) 101 | lastCount := C.long(C.clipboard_change_count()) 102 | go func() { 103 | for { 104 | select { 105 | case <-ctx.Done(): 106 | close(recv) 107 | return 108 | case <-ti.C: 109 | this := C.long(C.clipboard_change_count()) 110 | if lastCount != this { 111 | b := Read(t) 112 | if b == nil { 113 | continue 114 | } 115 | recv <- b 116 | lastCount = this 117 | } 118 | } 119 | } 120 | }() 121 | return recv 122 | } 123 | -------------------------------------------------------------------------------- /clipboard_darwin.m: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | //go:build darwin && !ios 8 | 9 | // Interact with NSPasteboard using Objective-C 10 | // https://developer.apple.com/documentation/appkit/nspasteboard?language=objc 11 | 12 | #import 13 | #import 14 | 15 | unsigned int clipboard_read_string(void **out) { 16 | NSPasteboard * pasteboard = [NSPasteboard generalPasteboard]; 17 | NSData *data = [pasteboard dataForType:NSPasteboardTypeString]; 18 | if (data == nil) { 19 | return 0; 20 | } 21 | NSUInteger siz = [data length]; 22 | *out = malloc(siz); 23 | [data getBytes: *out length: siz]; 24 | return siz; 25 | } 26 | 27 | unsigned int clipboard_read_image(void **out) { 28 | NSPasteboard * pasteboard = [NSPasteboard generalPasteboard]; 29 | NSData *data = [pasteboard dataForType:NSPasteboardTypePNG]; 30 | if (data == nil) { 31 | return 0; 32 | } 33 | NSUInteger siz = [data length]; 34 | *out = malloc(siz); 35 | [data getBytes: *out length: siz]; 36 | return siz; 37 | } 38 | 39 | int clipboard_write_string(const void *bytes, NSInteger n) { 40 | NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; 41 | NSData *data = [NSData dataWithBytes: bytes length: n]; 42 | [pasteboard clearContents]; 43 | BOOL ok = [pasteboard setData: data forType:NSPasteboardTypeString]; 44 | if (!ok) { 45 | return -1; 46 | } 47 | return 0; 48 | } 49 | int clipboard_write_image(const void *bytes, NSInteger n) { 50 | NSPasteboard *pasteboard = [NSPasteboard generalPasteboard]; 51 | NSData *data = [NSData dataWithBytes: bytes length: n]; 52 | [pasteboard clearContents]; 53 | BOOL ok = [pasteboard setData: data forType:NSPasteboardTypePNG]; 54 | if (!ok) { 55 | return -1; 56 | } 57 | return 0; 58 | } 59 | 60 | NSInteger clipboard_change_count() { 61 | return [[NSPasteboard generalPasteboard] changeCount]; 62 | } 63 | -------------------------------------------------------------------------------- /clipboard_ios.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | //go:build ios 8 | 9 | package clipboard 10 | 11 | /* 12 | #cgo CFLAGS: -x objective-c 13 | #cgo LDFLAGS: -framework Foundation -framework UIKit -framework MobileCoreServices 14 | 15 | #import 16 | void clipboard_write_string(char *s); 17 | char *clipboard_read_string(); 18 | */ 19 | import "C" 20 | import ( 21 | "bytes" 22 | "context" 23 | "time" 24 | "unsafe" 25 | ) 26 | 27 | func initialize() error { return nil } 28 | 29 | func read(t Format) (buf []byte, err error) { 30 | switch t { 31 | case FmtText: 32 | return []byte(C.GoString(C.clipboard_read_string())), nil 33 | case FmtImage: 34 | return nil, errUnsupported 35 | default: 36 | return nil, errUnsupported 37 | } 38 | } 39 | 40 | // SetContent sets the clipboard content for iOS 41 | func write(t Format, buf []byte) (<-chan struct{}, error) { 42 | done := make(chan struct{}, 1) 43 | switch t { 44 | case FmtText: 45 | cs := C.CString(string(buf)) 46 | defer C.free(unsafe.Pointer(cs)) 47 | 48 | C.clipboard_write_string(cs) 49 | return done, nil 50 | case FmtImage: 51 | return nil, errUnsupported 52 | default: 53 | return nil, errUnsupported 54 | } 55 | } 56 | 57 | func watch(ctx context.Context, t Format) <-chan []byte { 58 | recv := make(chan []byte, 1) 59 | ti := time.NewTicker(time.Second) 60 | last := Read(t) 61 | go func() { 62 | for { 63 | select { 64 | case <-ctx.Done(): 65 | close(recv) 66 | return 67 | case <-ti.C: 68 | b := Read(t) 69 | if b == nil { 70 | continue 71 | } 72 | if bytes.Compare(last, b) != 0 { 73 | recv <- b 74 | last = b 75 | } 76 | } 77 | } 78 | }() 79 | return recv 80 | } 81 | -------------------------------------------------------------------------------- /clipboard_ios.m: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | //go:build ios 8 | 9 | #import 10 | #import 11 | 12 | void clipboard_write_string(char *s) { 13 | NSString *value = [NSString stringWithUTF8String:s]; 14 | [[UIPasteboard generalPasteboard] setString:value]; 15 | } 16 | 17 | char *clipboard_read_string() { 18 | NSString *str = [[UIPasteboard generalPasteboard] string]; 19 | return (char *)[str UTF8String]; 20 | } 21 | -------------------------------------------------------------------------------- /clipboard_linux.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | //go:build linux && !android 8 | 9 | package clipboard 10 | 11 | /* 12 | #cgo LDFLAGS: -ldl 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | int clipboard_test(); 19 | int clipboard_write( 20 | char* typ, 21 | unsigned char* buf, 22 | size_t n, 23 | uintptr_t handle 24 | ); 25 | unsigned long clipboard_read(char* typ, char **out); 26 | */ 27 | import "C" 28 | import ( 29 | "bytes" 30 | "context" 31 | "fmt" 32 | "os" 33 | "runtime" 34 | "runtime/cgo" 35 | "time" 36 | "unsafe" 37 | ) 38 | 39 | var helpmsg = `%w: Failed to initialize the X11 display, and the clipboard package 40 | will not work properly. Install the following dependency may help: 41 | 42 | apt install -y libx11-dev 43 | 44 | If the clipboard package is in an environment without a frame buffer, 45 | such as a cloud server, it may also be necessary to install xvfb: 46 | 47 | apt install -y xvfb 48 | 49 | and initialize a virtual frame buffer: 50 | 51 | Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & 52 | export DISPLAY=:99.0 53 | 54 | Then this package should be ready to use. 55 | ` 56 | 57 | func initialize() error { 58 | ok := C.clipboard_test() 59 | if ok != 0 { 60 | return fmt.Errorf(helpmsg, errUnavailable) 61 | } 62 | return nil 63 | } 64 | 65 | func read(t Format) (buf []byte, err error) { 66 | switch t { 67 | case FmtText: 68 | return readc("UTF8_STRING") 69 | case FmtImage: 70 | return readc("image/png") 71 | } 72 | return nil, errUnsupported 73 | } 74 | 75 | func readc(t string) ([]byte, error) { 76 | ct := C.CString(t) 77 | defer C.free(unsafe.Pointer(ct)) 78 | 79 | var data *C.char 80 | n := C.clipboard_read(ct, &data) 81 | if data == nil { 82 | return nil, errUnavailable 83 | } 84 | defer C.free(unsafe.Pointer(data)) 85 | switch { 86 | case n == 0: 87 | return nil, nil 88 | default: 89 | return C.GoBytes(unsafe.Pointer(data), C.int(n)), nil 90 | } 91 | } 92 | 93 | // write writes the given data to clipboard and 94 | // returns true if success or false if failed. 95 | func write(t Format, buf []byte) (<-chan struct{}, error) { 96 | var s string 97 | switch t { 98 | case FmtText: 99 | s = "UTF8_STRING" 100 | case FmtImage: 101 | s = "image/png" 102 | } 103 | 104 | start := make(chan int) 105 | done := make(chan struct{}, 1) 106 | 107 | go func() { // serve as a daemon until the ownership is terminated. 108 | runtime.LockOSThread() 109 | defer runtime.UnlockOSThread() 110 | 111 | cs := C.CString(s) 112 | defer C.free(unsafe.Pointer(cs)) 113 | 114 | h := cgo.NewHandle(start) 115 | var ok C.int 116 | if len(buf) == 0 { 117 | ok = C.clipboard_write(cs, nil, 0, C.uintptr_t(h)) 118 | } else { 119 | ok = C.clipboard_write(cs, (*C.uchar)(unsafe.Pointer(&(buf[0]))), C.size_t(len(buf)), C.uintptr_t(h)) 120 | } 121 | if ok != C.int(0) { 122 | fmt.Fprintf(os.Stderr, "write failed with status: %d\n", int(ok)) 123 | } 124 | done <- struct{}{} 125 | close(done) 126 | }() 127 | 128 | status := <-start 129 | if status < 0 { 130 | return nil, errUnavailable 131 | } 132 | // wait until enter event loop 133 | return done, nil 134 | } 135 | 136 | func watch(ctx context.Context, t Format) <-chan []byte { 137 | recv := make(chan []byte, 1) 138 | ti := time.NewTicker(time.Second) 139 | last := Read(t) 140 | go func() { 141 | for { 142 | select { 143 | case <-ctx.Done(): 144 | close(recv) 145 | return 146 | case <-ti.C: 147 | b := Read(t) 148 | if b == nil { 149 | continue 150 | } 151 | if !bytes.Equal(last, b) { 152 | recv <- b 153 | last = b 154 | } 155 | } 156 | } 157 | }() 158 | return recv 159 | } 160 | 161 | //export syncStatus 162 | func syncStatus(h uintptr, val int) { 163 | v := cgo.Handle(h).Value().(chan int) 164 | v <- val 165 | cgo.Handle(h).Delete() 166 | } 167 | -------------------------------------------------------------------------------- /clipboard_nocgo.go: -------------------------------------------------------------------------------- 1 | //go:build !windows && !cgo 2 | 3 | package clipboard 4 | 5 | import "context" 6 | 7 | func initialize() error { 8 | panic("clipboard: cannot use when CGO_ENABLED=0") 9 | } 10 | 11 | func read(t Format) (buf []byte, err error) { 12 | panic("clipboard: cannot use when CGO_ENABLED=0") 13 | } 14 | 15 | func readc(t string) ([]byte, error) { 16 | panic("clipboard: cannot use when CGO_ENABLED=0") 17 | } 18 | 19 | func write(t Format, buf []byte) (<-chan struct{}, error) { 20 | panic("clipboard: cannot use when CGO_ENABLED=0") 21 | } 22 | 23 | func watch(ctx context.Context, t Format) <-chan []byte { 24 | panic("clipboard: cannot use when CGO_ENABLED=0") 25 | } 26 | -------------------------------------------------------------------------------- /cmd/gclip-gui/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 14 | 15 | 16 | 20 | 21 | 22 | 23 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | -------------------------------------------------------------------------------- /cmd/gclip-gui/README.md: -------------------------------------------------------------------------------- 1 | # gclip-gui 2 | 3 | This is a very basic example for verification purpose that demonstrates 4 | how the [golang.design/x/clipboard](https://golang.design/x/clipboard) 5 | can interact with macOS/Linux/Windows/Android/iOS system clipboard. 6 | 7 | The gclip GUI application writes a string to the system clipboard 8 | periodically then reads it back and renders it if possible. 9 | 10 | Because of the system limitation, on mobile devices, only string data is 11 | supported at the moment. Hence, one must use clipboard.FmtText. Other supplied 12 | formats result in a panic. 13 | 14 | This example is intentded as cross platform application. To build it, one 15 | must use [gomobile](https://golang.org/x/mobile). You may follow the instructions 16 | provided in the [GoMobile wiki](https://github.com/golang/go/wiki/Mobile) page. 17 | 18 | 19 | - For desktop: `go build -o gclip-gui` 20 | - For Android: `gomobile build -v -target=android -o gclip-gui.apk` 21 | - For iOS: `gomobile build -v -target=ios -bundleid design.golang.gclip-gui.app` 22 | 23 | ## Screenshots 24 | 25 | | macOS | iOS | Windows | Android | Linux | 26 | |:-----:|:---:|:-------:|:-------:|:-----:| 27 | |![](../../tests/testdata/darwin.png)|![](../../tests/testdata/ios.png)|![](../../tests/testdata/windows.png)|![](../../tests/testdata/android.png)|![](../../tests/testdata/linux.png)| 28 | 29 | ## License 30 | 31 | MIT | © 2021 The golang.design Initiative Authors, written by [Changkun Ou](https://changkun.de). -------------------------------------------------------------------------------- /cmd/gclip/README.md: -------------------------------------------------------------------------------- 1 | # gclip 2 | 3 | `gclip` command offers the ability to interact with the system clipboard 4 | from the shell. To install: 5 | 6 | ```bash 7 | $ go install golang.design/x/clipboard/cmd/gclip@latest 8 | ``` 9 | 10 | ```bash 11 | $ gclip 12 | gclip is a command that provides clipboard interaction. 13 | usage: gclip [-copy|-paste] [-f ] 14 | options: 15 | -copy 16 | copy data to clipboard 17 | -f string 18 | source or destination to a given file path 19 | -paste 20 | paste data from clipboard 21 | examples: 22 | gclip -paste paste from clipboard and prints the content 23 | gclip -paste -f x.txt paste from clipboard and save as text to x.txt 24 | gclip -paste -f x.png paste from clipboard and save as image to x.png 25 | cat x.txt | gclip -copy copy content from x.txt to clipboard 26 | gclip -copy -f x.txt copy content from x.txt to clipboard 27 | gclip -copy -f x.png copy x.png as image data to clipboard 28 | ``` 29 | 30 | If `-copy` is used, the command will exit when the data is no longer 31 | available from the clipboard. You can always send the command to the 32 | background using a shell `&` operator, for example: 33 | 34 | ```bash 35 | $ cat x.txt | gclip -copy & 36 | ``` 37 | 38 | ## License 39 | 40 | MIT | © 2021 The golang.design Initiative Authors, written by [Changkun Ou](https://changkun.de). -------------------------------------------------------------------------------- /cmd/gclip/main.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | package main // go install golang.design/x/clipboard/cmd/gclip@latest 8 | 9 | import ( 10 | "flag" 11 | "fmt" 12 | "io" 13 | "os" 14 | "path/filepath" 15 | 16 | "golang.design/x/clipboard" 17 | ) 18 | 19 | func usage() { 20 | fmt.Fprintf(os.Stderr, `gclip is a command that provides clipboard interaction. 21 | 22 | usage: gclip [-copy|-paste] [-f ] 23 | 24 | options: 25 | `) 26 | flag.PrintDefaults() 27 | fmt.Fprintf(os.Stderr, ` 28 | examples: 29 | gclip -paste paste from clipboard and prints the content 30 | gclip -paste -f x.txt paste from clipboard and save as text to x.txt 31 | gclip -paste -f x.png paste from clipboard and save as image to x.png 32 | 33 | cat x.txt | gclip -copy copy content from x.txt to clipboard 34 | gclip -copy -f x.txt copy content from x.txt to clipboard 35 | gclip -copy -f x.png copy x.png as image data to clipboard 36 | `) 37 | os.Exit(2) 38 | } 39 | 40 | var ( 41 | in = flag.Bool("copy", false, "copy data to clipboard") 42 | out = flag.Bool("paste", false, "paste data from clipboard") 43 | file = flag.String("f", "", "source or destination to a given file path") 44 | ) 45 | 46 | func init() { 47 | err := clipboard.Init() 48 | if err != nil { 49 | panic(err) 50 | } 51 | } 52 | 53 | func main() { 54 | flag.Usage = usage 55 | flag.Parse() 56 | if *out { 57 | if err := pst(); err != nil { 58 | usage() 59 | } 60 | return 61 | } 62 | if *in { 63 | if err := cpy(); err != nil { 64 | usage() 65 | } 66 | return 67 | } 68 | usage() 69 | } 70 | 71 | func cpy() error { 72 | t := clipboard.FmtText 73 | ext := filepath.Ext(*file) 74 | 75 | switch ext { 76 | case ".png": 77 | t = clipboard.FmtImage 78 | case ".txt": 79 | fallthrough 80 | default: 81 | t = clipboard.FmtText 82 | } 83 | 84 | var ( 85 | b []byte 86 | err error 87 | ) 88 | if *file != "" { 89 | b, err = os.ReadFile(*file) 90 | if err != nil { 91 | fmt.Fprintf(os.Stderr, "failed to read given file: %v", err) 92 | return err 93 | } 94 | } else { 95 | b, err = io.ReadAll(os.Stdin) 96 | if err != nil { 97 | fmt.Fprintf(os.Stderr, "failed to read from stdin: %v", err) 98 | return err 99 | } 100 | } 101 | 102 | // Wait until clipboard content has been changed. 103 | <-clipboard.Write(t, b) 104 | return nil 105 | } 106 | 107 | func pst() (err error) { 108 | var b []byte 109 | 110 | b = clipboard.Read(clipboard.FmtText) 111 | if b == nil { 112 | b = clipboard.Read(clipboard.FmtImage) 113 | } 114 | 115 | if *file != "" && b != nil { 116 | err = os.WriteFile(*file, b, os.ModePerm) 117 | if err != nil { 118 | fmt.Fprintf(os.Stderr, "failed to write data to file %s: %v", *file, err) 119 | } 120 | return err 121 | } 122 | 123 | for len(b) > 0 { 124 | n, err := os.Stdout.Write(b) 125 | if err != nil { 126 | return err 127 | } 128 | b = b[n:] 129 | } 130 | return nil 131 | } 132 | -------------------------------------------------------------------------------- /example_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | //go:build cgo 8 | 9 | package clipboard_test 10 | 11 | import ( 12 | "context" 13 | "fmt" 14 | "time" 15 | 16 | "golang.design/x/clipboard" 17 | ) 18 | 19 | func ExampleWrite() { 20 | err := clipboard.Init() 21 | if err != nil { 22 | panic(err) 23 | } 24 | 25 | clipboard.Write(clipboard.FmtText, []byte("Hello, 世界")) 26 | // Output: 27 | } 28 | 29 | func ExampleRead() { 30 | err := clipboard.Init() 31 | if err != nil { 32 | panic(err) 33 | } 34 | 35 | fmt.Println(string(clipboard.Read(clipboard.FmtText))) 36 | // Output: 37 | // Hello, 世界 38 | } 39 | 40 | func ExampleWatch() { 41 | err := clipboard.Init() 42 | if err != nil { 43 | panic(err) 44 | } 45 | 46 | ctx, cancel := context.WithTimeout(context.Background(), time.Second*2) 47 | defer cancel() 48 | 49 | changed := clipboard.Watch(context.Background(), clipboard.FmtText) 50 | go func(ctx context.Context) { 51 | clipboard.Write(clipboard.FmtText, []byte("你好,world")) 52 | }(ctx) 53 | fmt.Println(string(<-changed)) 54 | // Output: 55 | // 你好,world 56 | } 57 | -------------------------------------------------------------------------------- /export_test.go: -------------------------------------------------------------------------------- 1 | // Copyright 2021 The golang.design Initiative Authors. 2 | // All rights reserved. Use of this source code is governed 3 | // by a MIT license that can be found in the LICENSE file. 4 | // 5 | // Written by Changkun Ou 6 | 7 | package clipboard 8 | 9 | // for debugging errors 10 | var ( 11 | Debug = debug 12 | ErrUnavailable = errUnavailable 13 | ) 14 | -------------------------------------------------------------------------------- /go.mod: -------------------------------------------------------------------------------- 1 | module golang.design/x/clipboard 2 | 3 | go 1.17 4 | 5 | require ( 6 | golang.org/x/image v0.6.0 7 | golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c 8 | ) 9 | 10 | require ( 11 | golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 // indirect 12 | golang.org/x/sys v0.5.0 // indirect 13 | ) 14 | -------------------------------------------------------------------------------- /go.sum: -------------------------------------------------------------------------------- 1 | github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= 2 | github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= 3 | golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= 4 | golang.org/x/crypto v0.0.0-20190510104115-cbcb75029529/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= 5 | golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= 6 | golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 h1:estk1glOnSVeJ9tdEZZc5mAMDZk5lNJNyJ6DvrBkTEU= 7 | golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56/go.mod h1:JhuoJpWY28nO4Vef9tZUw9qufEGTyX1+7lmHxV5q5G4= 8 | golang.org/x/image v0.0.0-20190227222117-0694c2d4d067/go.mod h1:kZ7UVZpmo3dzQBMxlp+ypCbDeSB+sBbTgSJuh5dn5js= 9 | golang.org/x/image v0.0.0-20190802002840-cff245a6509b/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= 10 | golang.org/x/image v0.6.0 h1:bR8b5okrPI3g/gyZakLZHeWxAR8Dn5CyxXv1hLH5g/4= 11 | golang.org/x/image v0.6.0/go.mod h1:MXLdDR43H7cDJq5GEGXEVeeNhPgi+YYEQ2pC1byI1x0= 12 | golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= 13 | golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c h1:Gk61ECugwEHL6IiyyNLXNzmu8XslmRP2dS0xjIYhbb4= 14 | golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c/go.mod h1:aAjjkJNdrh3PMckS4B10TGS2nag27cbKR1y2BpUxsiY= 15 | golang.org/x/mod v0.1.0/go.mod h1:0QHyrYULN0/3qlju5TqG8bIK38QM8yzMo5ekMj3DlcY= 16 | golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= 17 | golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= 18 | golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 19 | golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= 20 | golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= 21 | golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= 22 | golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= 23 | golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= 24 | golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 25 | golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 26 | golang.org/x/sync v0.0.0-20220819030929-7fc1605a5dde/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 27 | golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= 28 | golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= 29 | golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 30 | golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= 31 | golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 32 | golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 33 | golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 34 | golang.org/x/sys v0.5.0 h1:MUK/U/4lj1t1oPg0HfuXDN/Z1wv31ZJ/YcPiGccS4DU= 35 | golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= 36 | golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= 37 | golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= 38 | golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= 39 | golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= 40 | golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= 41 | golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= 42 | golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= 43 | golang.org/x/text v0.8.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= 44 | golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= 45 | golang.org/x/tools v0.0.0-20190312151545-0bb0c0a6e846/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs= 46 | golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= 47 | golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= 48 | golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= 49 | golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= 50 | -------------------------------------------------------------------------------- /tests/Makefile: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The golang.design Initiative Authors. 2 | # All rights reserved. Use of this source code is governed 3 | # by a MIT license that can be found in the LICENSE file. 4 | # 5 | # Written by Changkun Ou 6 | 7 | all: test 8 | 9 | test: 10 | go test -v -count=1 -covermode=atomic .. 11 | 12 | test-docker: 13 | docker build -t golang-design/x/clipboard .. 14 | docker run --rm --name cb golang-design/x/clipboard 15 | docker rmi golang-design/x/clipboard -------------------------------------------------------------------------------- /tests/test-docker.sh: -------------------------------------------------------------------------------- 1 | # Copyright 2021 The golang.design Initiative Authors. 2 | # All rights reserved. Use of this source code is governed 3 | # by a MIT license that can be found in the LICENSE file. 4 | # 5 | # Written by Changkun Ou 6 | 7 | # require apt-get install xvfb 8 | Xvfb :99 -screen 0 1024x768x24 > /dev/null 2>&1 & 9 | export DISPLAY=:99.0 10 | 11 | go test -v -covermode=atomic ./... -------------------------------------------------------------------------------- /tests/testdata/android.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang-design/clipboard/b50badc062a526673961e1465a673e3f3dfc1464/tests/testdata/android.png -------------------------------------------------------------------------------- /tests/testdata/clipboard.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang-design/clipboard/b50badc062a526673961e1465a673e3f3dfc1464/tests/testdata/clipboard.png -------------------------------------------------------------------------------- /tests/testdata/darwin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang-design/clipboard/b50badc062a526673961e1465a673e3f3dfc1464/tests/testdata/darwin.png -------------------------------------------------------------------------------- /tests/testdata/ios.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang-design/clipboard/b50badc062a526673961e1465a673e3f3dfc1464/tests/testdata/ios.png -------------------------------------------------------------------------------- /tests/testdata/linux.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang-design/clipboard/b50badc062a526673961e1465a673e3f3dfc1464/tests/testdata/linux.png -------------------------------------------------------------------------------- /tests/testdata/windows.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/golang-design/clipboard/b50badc062a526673961e1465a673e3f3dfc1464/tests/testdata/windows.png -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/AUTHORS: -------------------------------------------------------------------------------- 1 | # This source code refers to The Go Authors for copyright purposes. 2 | # The master list of authors is in the main Go distribution, 3 | # visible at http://tip.golang.org/AUTHORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This source code was written by the Go contributors. 2 | # The master list of contributors is in the main Go distribution, 3 | # visible at http://tip.golang.org/CONTRIBUTORS. 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/gldriver/buffer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package gldriver 6 | 7 | import "image" 8 | 9 | type bufferImpl struct { 10 | // buf should always be equal to (i.e. the same ptr, len, cap as) rgba.Pix. 11 | // It is a separate, redundant field in order to detect modifications to 12 | // the rgba field that are invalid as per the screen.Buffer documentation. 13 | buf []byte 14 | rgba image.RGBA 15 | size image.Point 16 | } 17 | 18 | func (b *bufferImpl) Release() {} 19 | func (b *bufferImpl) Size() image.Point { return b.size } 20 | func (b *bufferImpl) Bounds() image.Rectangle { return image.Rectangle{Max: b.size} } 21 | func (b *bufferImpl) RGBA() *image.RGBA { return &b.rgba } 22 | 23 | func (b *bufferImpl) preUpload() { 24 | // Check that the program hasn't tried to modify the rgba field via the 25 | // pointer returned by the bufferImpl.RGBA method. This check doesn't catch 26 | // 100% of all cases; it simply tries to detect some invalid uses of a 27 | // screen.Buffer such as: 28 | // *buffer.RGBA() = anotherImageRGBA 29 | if len(b.buf) != 0 && len(b.rgba.Pix) != 0 && &b.buf[0] != &b.rgba.Pix[0] { 30 | panic("gldriver: invalid Buffer.RGBA modification") 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/gldriver/context.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !android 6 | 7 | package gldriver 8 | 9 | import ( 10 | "runtime" 11 | 12 | "golang.org/x/mobile/gl" 13 | ) 14 | 15 | // NewContext creates an OpenGL ES context with a dedicated processing thread. 16 | func NewContext() (gl.Context, error) { 17 | glctx, worker := gl.NewContext() 18 | 19 | errCh := make(chan error) 20 | workAvailable := worker.WorkAvailable() 21 | go func() { 22 | runtime.LockOSThread() 23 | err := surfaceCreate() 24 | errCh <- err 25 | if err != nil { 26 | return 27 | } 28 | 29 | for range workAvailable { 30 | worker.DoWork() 31 | } 32 | }() 33 | if err := <-errCh; err != nil { 34 | return nil, err 35 | } 36 | return glctx, nil 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/gldriver/egl.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package gldriver 6 | 7 | // These constants match the values found in the EGL 1.4 headers, 8 | // egl.h, eglext.h, and eglplatform.h. 9 | const ( 10 | _EGL_DONT_CARE = -1 11 | 12 | _EGL_NO_SURFACE = 0 13 | _EGL_NO_CONTEXT = 0 14 | _EGL_NO_DISPLAY = 0 15 | 16 | _EGL_OPENGL_ES2_BIT = 0x04 // EGL_RENDERABLE_TYPE mask 17 | _EGL_WINDOW_BIT = 0x04 // EGL_SURFACE_TYPE mask 18 | 19 | _EGL_OPENGL_ES_API = 0x30A0 20 | _EGL_RENDERABLE_TYPE = 0x3040 21 | _EGL_SURFACE_TYPE = 0x3033 22 | _EGL_BUFFER_SIZE = 0x3020 23 | _EGL_ALPHA_SIZE = 0x3021 24 | _EGL_BLUE_SIZE = 0x3022 25 | _EGL_GREEN_SIZE = 0x3023 26 | _EGL_RED_SIZE = 0x3024 27 | _EGL_DEPTH_SIZE = 0x3025 28 | _EGL_STENCIL_SIZE = 0x3026 29 | _EGL_SAMPLE_BUFFERS = 0x3032 30 | _EGL_CONFIG_CAVEAT = 0x3027 31 | _EGL_NONE = 0x3038 32 | 33 | _EGL_CONTEXT_CLIENT_VERSION = 0x3098 34 | ) 35 | 36 | // ANGLE specific options found in eglext.h 37 | const ( 38 | _EGL_PLATFORM_ANGLE_ANGLE = 0x3202 39 | _EGL_PLATFORM_ANGLE_TYPE_ANGLE = 0x3203 40 | _EGL_PLATFORM_ANGLE_MAX_VERSION_MAJOR_ANGLE = 0x3204 41 | _EGL_PLATFORM_ANGLE_MAX_VERSION_MINOR_ANGLE = 0x3205 42 | _EGL_PLATFORM_ANGLE_TYPE_DEFAULT_ANGLE = 0x3206 43 | 44 | _EGL_PLATFORM_ANGLE_TYPE_D3D9_ANGLE = 0x3207 45 | _EGL_PLATFORM_ANGLE_TYPE_D3D11_ANGLE = 0x3208 46 | _EGL_PLATFORM_ANGLE_DEVICE_TYPE_ANGLE = 0x3209 47 | _EGL_PLATFORM_ANGLE_DEVICE_TYPE_HARDWARE_ANGLE = 0x320A 48 | _EGL_PLATFORM_ANGLE_DEVICE_TYPE_WARP_ANGLE = 0x320B 49 | 50 | _EGL_PLATFORM_ANGLE_TYPE_OPENGL_ANGLE = 0x320D 51 | _EGL_PLATFORM_ANGLE_TYPE_OPENGLES_ANGLE = 0x320E 52 | ) 53 | 54 | const ( 55 | _EGL_SUCCESS = 0x3000 56 | _EGL_NOT_INITIALIZED = 0x3001 57 | _EGL_BAD_ACCESS = 0x3002 58 | _EGL_BAD_ALLOC = 0x3003 59 | _EGL_BAD_ATTRIBUTE = 0x3004 60 | _EGL_BAD_CONFIG = 0x3005 61 | _EGL_BAD_CONTEXT = 0x3006 62 | _EGL_BAD_CURRENT_SURFACE = 0x3007 63 | _EGL_BAD_DISPLAY = 0x3008 64 | _EGL_BAD_MATCH = 0x3009 65 | _EGL_BAD_NATIVE_PIXMAP = 0x300A 66 | _EGL_BAD_NATIVE_WINDOW = 0x300B 67 | _EGL_BAD_PARAMETER = 0x300C 68 | _EGL_BAD_SURFACE = 0x300D 69 | _EGL_CONTEXT_LOST = 0x300E 70 | ) 71 | 72 | func eglErrString(errno uintptr) string { 73 | switch errno { 74 | case _EGL_SUCCESS: 75 | return "EGL_SUCCESS" 76 | case _EGL_NOT_INITIALIZED: 77 | return "EGL_NOT_INITIALIZED" 78 | case _EGL_BAD_ACCESS: 79 | return "EGL_BAD_ACCESS" 80 | case _EGL_BAD_ALLOC: 81 | return "EGL_BAD_ALLOC" 82 | case _EGL_BAD_ATTRIBUTE: 83 | return "EGL_BAD_ATTRIBUTE" 84 | case _EGL_BAD_CONFIG: 85 | return "EGL_BAD_CONFIG" 86 | case _EGL_BAD_CONTEXT: 87 | return "EGL_BAD_CONTEXT" 88 | case _EGL_BAD_CURRENT_SURFACE: 89 | return "EGL_BAD_CURRENT_SURFACE" 90 | case _EGL_BAD_DISPLAY: 91 | return "EGL_BAD_DISPLAY" 92 | case _EGL_BAD_MATCH: 93 | return "EGL_BAD_MATCH" 94 | case _EGL_BAD_NATIVE_PIXMAP: 95 | return "EGL_BAD_NATIVE_PIXMAP" 96 | case _EGL_BAD_NATIVE_WINDOW: 97 | return "EGL_BAD_NATIVE_WINDOW" 98 | case _EGL_BAD_PARAMETER: 99 | return "EGL_BAD_PARAMETER" 100 | case _EGL_BAD_SURFACE: 101 | return "EGL_BAD_SURFACE" 102 | case _EGL_CONTEXT_LOST: 103 | return "EGL_CONTEXT_LOST" 104 | } 105 | return "EGL: unknown error" 106 | } 107 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/gldriver/gldriver.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package gldriver provides an OpenGL driver for accessing a screen. 6 | package gldriver // import "golang.org/x/exp/shiny/driver/gldriver" 7 | 8 | import ( 9 | "encoding/binary" 10 | "fmt" 11 | "math" 12 | 13 | "golang.org/x/exp/shiny/driver/internal/errscreen" 14 | "golang.org/x/exp/shiny/screen" 15 | "golang.org/x/image/math/f64" 16 | "golang.org/x/mobile/gl" 17 | ) 18 | 19 | // Main is called by the program's main function to run the graphical 20 | // application. 21 | // 22 | // It calls f on the Screen, possibly in a separate goroutine, as some OS- 23 | // specific libraries require being on 'the main thread'. It returns when f 24 | // returns. 25 | func Main(f func(screen.Screen)) { 26 | if err := main(f); err != nil { 27 | f(errscreen.Stub(err)) 28 | } 29 | } 30 | 31 | func mul(a, b f64.Aff3) f64.Aff3 { 32 | return f64.Aff3{ 33 | a[0]*b[0] + a[1]*b[3], 34 | a[0]*b[1] + a[1]*b[4], 35 | a[0]*b[2] + a[1]*b[5] + a[2], 36 | 37 | a[3]*b[0] + a[4]*b[3], 38 | a[3]*b[1] + a[4]*b[4], 39 | a[3]*b[2] + a[4]*b[5] + a[5], 40 | } 41 | } 42 | 43 | // writeAff3 must only be called while holding windowImpl.glctxMu. 44 | func writeAff3(glctx gl.Context, u gl.Uniform, a f64.Aff3) { 45 | var m [9]float32 46 | m[0*3+0] = float32(a[0*3+0]) 47 | m[0*3+1] = float32(a[1*3+0]) 48 | m[0*3+2] = 0 49 | m[1*3+0] = float32(a[0*3+1]) 50 | m[1*3+1] = float32(a[1*3+1]) 51 | m[1*3+2] = 0 52 | m[2*3+0] = float32(a[0*3+2]) 53 | m[2*3+1] = float32(a[1*3+2]) 54 | m[2*3+2] = 1 55 | glctx.UniformMatrix3fv(u, m[:]) 56 | } 57 | 58 | // f32Bytes returns the byte representation of float32 values in the given byte 59 | // order. byteOrder must be either binary.BigEndian or binary.LittleEndian. 60 | func f32Bytes(byteOrder binary.ByteOrder, values ...float32) []byte { 61 | le := false 62 | switch byteOrder { 63 | case binary.BigEndian: 64 | case binary.LittleEndian: 65 | le = true 66 | default: 67 | panic(fmt.Sprintf("invalid byte order %v", byteOrder)) 68 | } 69 | 70 | b := make([]byte, 4*len(values)) 71 | for i, v := range values { 72 | u := math.Float32bits(v) 73 | if le { 74 | b[4*i+0] = byte(u >> 0) 75 | b[4*i+1] = byte(u >> 8) 76 | b[4*i+2] = byte(u >> 16) 77 | b[4*i+3] = byte(u >> 24) 78 | } else { 79 | b[4*i+0] = byte(u >> 24) 80 | b[4*i+1] = byte(u >> 16) 81 | b[4*i+2] = byte(u >> 8) 82 | b[4*i+3] = byte(u >> 0) 83 | } 84 | } 85 | return b 86 | } 87 | 88 | // compileProgram must only be called while holding windowImpl.glctxMu. 89 | func compileProgram(glctx gl.Context, vSrc, fSrc string) (gl.Program, error) { 90 | program := glctx.CreateProgram() 91 | if program.Value == 0 { 92 | return gl.Program{}, fmt.Errorf("gldriver: no programs available") 93 | } 94 | 95 | vertexShader, err := compileShader(glctx, gl.VERTEX_SHADER, vSrc) 96 | if err != nil { 97 | return gl.Program{}, err 98 | } 99 | fragmentShader, err := compileShader(glctx, gl.FRAGMENT_SHADER, fSrc) 100 | if err != nil { 101 | glctx.DeleteShader(vertexShader) 102 | return gl.Program{}, err 103 | } 104 | 105 | glctx.AttachShader(program, vertexShader) 106 | glctx.AttachShader(program, fragmentShader) 107 | glctx.LinkProgram(program) 108 | 109 | // Flag shaders for deletion when program is unlinked. 110 | glctx.DeleteShader(vertexShader) 111 | glctx.DeleteShader(fragmentShader) 112 | 113 | if glctx.GetProgrami(program, gl.LINK_STATUS) == 0 { 114 | defer glctx.DeleteProgram(program) 115 | return gl.Program{}, fmt.Errorf("gldriver: program compile: %s", glctx.GetProgramInfoLog(program)) 116 | } 117 | return program, nil 118 | } 119 | 120 | // compileShader must only be called while holding windowImpl.glctxMu. 121 | func compileShader(glctx gl.Context, shaderType gl.Enum, src string) (gl.Shader, error) { 122 | shader := glctx.CreateShader(shaderType) 123 | if shader.Value == 0 { 124 | return gl.Shader{}, fmt.Errorf("gldriver: could not create shader (type %v)", shaderType) 125 | } 126 | glctx.ShaderSource(shader, src) 127 | glctx.CompileShader(shader) 128 | if glctx.GetShaderi(shader, gl.COMPILE_STATUS) == 0 { 129 | defer glctx.DeleteShader(shader) 130 | return gl.Shader{}, fmt.Errorf("gldriver: shader compile: %s", glctx.GetShaderInfoLog(shader)) 131 | } 132 | return shader, nil 133 | } 134 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/gldriver/other.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !darwin !386,!amd64 ios 6 | // +build !linux android 7 | // +build !windows 8 | // +build !openbsd 9 | 10 | package gldriver 11 | 12 | import ( 13 | "fmt" 14 | "runtime" 15 | 16 | "golang.org/x/exp/shiny/screen" 17 | ) 18 | 19 | const useLifecycler = true 20 | const handleSizeEventsAtChannelReceive = true 21 | 22 | func newWindow(opts *screen.NewWindowOptions) (uintptr, error) { return 0, nil } 23 | 24 | func initWindow(id *windowImpl) {} 25 | func showWindow(id *windowImpl) {} 26 | func closeWindow(id uintptr) {} 27 | func drawLoop(w *windowImpl) {} 28 | 29 | func main(f func(screen.Screen)) error { 30 | return fmt.Errorf("gldriver: unsupported GOOS/GOARCH %s/%s", runtime.GOOS, runtime.GOARCH) 31 | } 32 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/gldriver/screen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package gldriver 6 | 7 | import ( 8 | "fmt" 9 | "image" 10 | "sync" 11 | 12 | "golang.org/x/exp/shiny/screen" 13 | "golang.org/x/mobile/gl" 14 | ) 15 | 16 | var theScreen = &screenImpl{ 17 | windows: make(map[uintptr]*windowImpl), 18 | } 19 | 20 | type screenImpl struct { 21 | texture struct { 22 | program gl.Program 23 | pos gl.Attrib 24 | mvp gl.Uniform 25 | uvp gl.Uniform 26 | inUV gl.Attrib 27 | sample gl.Uniform 28 | quad gl.Buffer 29 | } 30 | fill struct { 31 | program gl.Program 32 | pos gl.Attrib 33 | mvp gl.Uniform 34 | color gl.Uniform 35 | quad gl.Buffer 36 | } 37 | 38 | mu sync.Mutex 39 | windows map[uintptr]*windowImpl 40 | } 41 | 42 | func (s *screenImpl) NewBuffer(size image.Point) (retBuf screen.Buffer, retErr error) { 43 | m := image.NewRGBA(image.Rectangle{Max: size}) 44 | return &bufferImpl{ 45 | buf: m.Pix, 46 | rgba: *m, 47 | size: size, 48 | }, nil 49 | } 50 | 51 | func (s *screenImpl) NewTexture(size image.Point) (screen.Texture, error) { 52 | // TODO: can we compile these programs eagerly instead of lazily? 53 | 54 | // Find a GL context for this texture. 55 | // TODO: this might be correct. Some GL objects can be shared 56 | // across contexts. But this needs a review of the spec to make 57 | // sure it's correct, and some testing would be nice. 58 | var w *windowImpl 59 | 60 | s.mu.Lock() 61 | for _, window := range s.windows { 62 | w = window 63 | break 64 | } 65 | s.mu.Unlock() 66 | 67 | if w == nil { 68 | return nil, fmt.Errorf("gldriver: no window available") 69 | } 70 | 71 | w.glctxMu.Lock() 72 | defer w.glctxMu.Unlock() 73 | glctx := w.glctx 74 | if glctx == nil { 75 | return nil, fmt.Errorf("gldriver: no GL context available") 76 | } 77 | 78 | if !glctx.IsProgram(s.texture.program) { 79 | p, err := compileProgram(glctx, textureVertexSrc, textureFragmentSrc) 80 | if err != nil { 81 | return nil, err 82 | } 83 | s.texture.program = p 84 | s.texture.pos = glctx.GetAttribLocation(p, "pos") 85 | s.texture.mvp = glctx.GetUniformLocation(p, "mvp") 86 | s.texture.uvp = glctx.GetUniformLocation(p, "uvp") 87 | s.texture.inUV = glctx.GetAttribLocation(p, "inUV") 88 | s.texture.sample = glctx.GetUniformLocation(p, "sample") 89 | s.texture.quad = glctx.CreateBuffer() 90 | 91 | glctx.BindBuffer(gl.ARRAY_BUFFER, s.texture.quad) 92 | glctx.BufferData(gl.ARRAY_BUFFER, quadCoords, gl.STATIC_DRAW) 93 | } 94 | 95 | t := &textureImpl{ 96 | w: w, 97 | id: glctx.CreateTexture(), 98 | size: size, 99 | } 100 | 101 | glctx.BindTexture(gl.TEXTURE_2D, t.id) 102 | glctx.TexImage2D(gl.TEXTURE_2D, 0, gl.RGBA, size.X, size.Y, gl.RGBA, gl.UNSIGNED_BYTE, nil) 103 | glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR) 104 | glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR) 105 | glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE) 106 | glctx.TexParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE) 107 | 108 | return t, nil 109 | } 110 | 111 | func optsSize(opts *screen.NewWindowOptions) (width, height int) { 112 | width, height = 1024, 768 113 | if opts != nil { 114 | if opts.Width > 0 { 115 | width = opts.Width 116 | } 117 | if opts.Height > 0 { 118 | height = opts.Height 119 | } 120 | } 121 | return width, height 122 | } 123 | 124 | func (s *screenImpl) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) { 125 | id, err := newWindow(opts) 126 | if err != nil { 127 | return nil, err 128 | } 129 | w := &windowImpl{ 130 | s: s, 131 | id: id, 132 | publish: make(chan struct{}), 133 | publishDone: make(chan screen.PublishResult), 134 | drawDone: make(chan struct{}), 135 | } 136 | initWindow(w) 137 | 138 | s.mu.Lock() 139 | s.windows[id] = w 140 | s.mu.Unlock() 141 | 142 | if useLifecycler { 143 | w.lifecycler.SendEvent(w, nil) 144 | } 145 | 146 | showWindow(w) 147 | 148 | return w, nil 149 | } 150 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/gldriver/texture.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package gldriver 6 | 7 | import ( 8 | "encoding/binary" 9 | "image" 10 | "image/color" 11 | "image/draw" 12 | 13 | "golang.org/x/exp/shiny/screen" 14 | "golang.org/x/mobile/gl" 15 | ) 16 | 17 | type textureImpl struct { 18 | w *windowImpl 19 | id gl.Texture 20 | fb gl.Framebuffer 21 | size image.Point 22 | } 23 | 24 | func (t *textureImpl) Size() image.Point { return t.size } 25 | func (t *textureImpl) Bounds() image.Rectangle { return image.Rectangle{Max: t.size} } 26 | 27 | func (t *textureImpl) Release() { 28 | t.w.glctxMu.Lock() 29 | defer t.w.glctxMu.Unlock() 30 | 31 | if t.fb.Value != 0 { 32 | t.w.glctx.DeleteFramebuffer(t.fb) 33 | t.fb = gl.Framebuffer{} 34 | } 35 | t.w.glctx.DeleteTexture(t.id) 36 | t.id = gl.Texture{} 37 | } 38 | 39 | func (t *textureImpl) Upload(dp image.Point, src screen.Buffer, sr image.Rectangle) { 40 | buf := src.(*bufferImpl) 41 | buf.preUpload() 42 | 43 | // src2dst is added to convert from the src coordinate space to the dst 44 | // coordinate space. It is subtracted to convert the other way. 45 | src2dst := dp.Sub(sr.Min) 46 | 47 | // Clip to the source. 48 | sr = sr.Intersect(buf.Bounds()) 49 | 50 | // Clip to the destination. 51 | dr := sr.Add(src2dst) 52 | dr = dr.Intersect(t.Bounds()) 53 | if dr.Empty() { 54 | return 55 | } 56 | 57 | // Bring dr.Min in dst-space back to src-space to get the pixel buffer offset. 58 | pix := buf.rgba.Pix[buf.rgba.PixOffset(dr.Min.X-src2dst.X, dr.Min.Y-src2dst.Y):] 59 | 60 | t.w.glctxMu.Lock() 61 | defer t.w.glctxMu.Unlock() 62 | 63 | t.w.glctx.BindTexture(gl.TEXTURE_2D, t.id) 64 | 65 | width := dr.Dx() 66 | if width*4 == buf.rgba.Stride { 67 | t.w.glctx.TexSubImage2D(gl.TEXTURE_2D, 0, dr.Min.X, dr.Min.Y, width, dr.Dy(), gl.RGBA, gl.UNSIGNED_BYTE, pix) 68 | return 69 | } 70 | // TODO: can we use GL_UNPACK_ROW_LENGTH with glPixelStorei for stride in 71 | // ES 3.0, instead of uploading the pixels row-by-row? 72 | for y, p := dr.Min.Y, 0; y < dr.Max.Y; y++ { 73 | t.w.glctx.TexSubImage2D(gl.TEXTURE_2D, 0, dr.Min.X, y, width, 1, gl.RGBA, gl.UNSIGNED_BYTE, pix[p:]) 74 | p += buf.rgba.Stride 75 | } 76 | } 77 | 78 | func (t *textureImpl) Fill(dr image.Rectangle, src color.Color, op draw.Op) { 79 | minX := float64(dr.Min.X) 80 | minY := float64(dr.Min.Y) 81 | maxX := float64(dr.Max.X) 82 | maxY := float64(dr.Max.Y) 83 | mvp := calcMVP( 84 | t.size.X, t.size.Y, 85 | minX, minY, 86 | maxX, minY, 87 | minX, maxY, 88 | ) 89 | 90 | glctx := t.w.glctx 91 | 92 | t.w.glctxMu.Lock() 93 | defer t.w.glctxMu.Unlock() 94 | 95 | create := t.fb.Value == 0 96 | if create { 97 | t.fb = glctx.CreateFramebuffer() 98 | } 99 | glctx.BindFramebuffer(gl.FRAMEBUFFER, t.fb) 100 | if create { 101 | glctx.FramebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, t.id, 0) 102 | } 103 | 104 | glctx.Viewport(0, 0, t.size.X, t.size.Y) 105 | doFill(t.w.s, t.w.glctx, mvp, src, op) 106 | 107 | // We can't restore the GL state (i.e. bind the back buffer, also known as 108 | // gl.Framebuffer{Value: 0}) right away, since we don't necessarily know 109 | // the right viewport size yet. It is valid to call textureImpl.Fill before 110 | // we've gotten our first size.Event. We bind it lazily instead. 111 | t.w.backBufferBound = false 112 | } 113 | 114 | var quadCoords = f32Bytes(binary.LittleEndian, 115 | 0, 0, // top left 116 | 1, 0, // top right 117 | 0, 1, // bottom left 118 | 1, 1, // bottom right 119 | ) 120 | 121 | const textureVertexSrc = `#version 100 122 | uniform mat3 mvp; 123 | uniform mat3 uvp; 124 | attribute vec3 pos; 125 | attribute vec2 inUV; 126 | varying vec2 uv; 127 | void main() { 128 | vec3 p = pos; 129 | p.z = 1.0; 130 | gl_Position = vec4(mvp * p, 1); 131 | uv = (uvp * vec3(inUV, 1)).xy; 132 | } 133 | ` 134 | 135 | const textureFragmentSrc = `#version 100 136 | precision mediump float; 137 | varying vec2 uv; 138 | uniform sampler2D sample; 139 | void main() { 140 | gl_FragColor = texture2D(sample, uv); 141 | } 142 | ` 143 | 144 | const fillVertexSrc = `#version 100 145 | uniform mat3 mvp; 146 | attribute vec3 pos; 147 | void main() { 148 | vec3 p = pos; 149 | p.z = 1.0; 150 | gl_Position = vec4(mvp * p, 1); 151 | } 152 | ` 153 | 154 | const fillFragmentSrc = `#version 100 155 | precision mediump float; 156 | uniform vec4 color; 157 | void main() { 158 | gl_FragColor = color; 159 | } 160 | ` 161 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/internal/drawer/drawer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package drawer provides functions that help implement screen.Drawer methods. 6 | package drawer // import "golang.org/x/exp/shiny/driver/internal/drawer" 7 | 8 | import ( 9 | "image" 10 | "image/draw" 11 | 12 | "golang.org/x/exp/shiny/screen" 13 | "golang.org/x/image/math/f64" 14 | ) 15 | 16 | // Copy implements the Copy method of the screen.Drawer interface by calling 17 | // the Draw method of that same interface. 18 | func Copy(dst screen.Drawer, dp image.Point, src screen.Texture, sr image.Rectangle, op draw.Op, opts *screen.DrawOptions) { 19 | dst.Draw(f64.Aff3{ 20 | 1, 0, float64(dp.X - sr.Min.X), 21 | 0, 1, float64(dp.Y - sr.Min.Y), 22 | }, src, sr, op, opts) 23 | } 24 | 25 | // Scale implements the Scale method of the screen.Drawer interface by calling 26 | // the Draw method of that same interface. 27 | func Scale(dst screen.Drawer, dr image.Rectangle, src screen.Texture, sr image.Rectangle, op draw.Op, opts *screen.DrawOptions) { 28 | rx := float64(dr.Dx()) / float64(sr.Dx()) 29 | ry := float64(dr.Dy()) / float64(sr.Dy()) 30 | dst.Draw(f64.Aff3{ 31 | rx, 0, float64(dr.Min.X) - rx*float64(sr.Min.X), 32 | 0, ry, float64(dr.Min.Y) - ry*float64(sr.Min.Y), 33 | }, src, sr, op, opts) 34 | } 35 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/internal/errscreen/errscreen.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package errscreen provides a stub Screen implementation. 6 | package errscreen // import "golang.org/x/exp/shiny/driver/internal/errscreen" 7 | 8 | import ( 9 | "image" 10 | 11 | "golang.org/x/exp/shiny/screen" 12 | ) 13 | 14 | // Stub returns a Screen whose methods all return the given error. 15 | func Stub(err error) screen.Screen { 16 | return stub{err} 17 | } 18 | 19 | type stub struct { 20 | err error 21 | } 22 | 23 | func (s stub) NewBuffer(size image.Point) (screen.Buffer, error) { return nil, s.err } 24 | func (s stub) NewTexture(size image.Point) (screen.Texture, error) { return nil, s.err } 25 | func (s stub) NewWindow(opts *screen.NewWindowOptions) (screen.Window, error) { return nil, s.err } 26 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/internal/event/event.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package event provides an infinitely buffered double-ended queue of events. 6 | package event // import "golang.org/x/exp/shiny/driver/internal/event" 7 | 8 | import ( 9 | "sync" 10 | ) 11 | 12 | // Deque is an infinitely buffered double-ended queue of events. The zero value 13 | // is usable, but a Deque value must not be copied. 14 | type Deque struct { 15 | mu sync.Mutex 16 | cond sync.Cond // cond.L is lazily initialized to &Deque.mu. 17 | back []interface{} // FIFO. 18 | front []interface{} // LIFO. 19 | } 20 | 21 | func (q *Deque) lockAndInit() { 22 | q.mu.Lock() 23 | if q.cond.L == nil { 24 | q.cond.L = &q.mu 25 | } 26 | } 27 | 28 | // NextEvent implements the screen.EventDeque interface. 29 | func (q *Deque) NextEvent() interface{} { 30 | q.lockAndInit() 31 | defer q.mu.Unlock() 32 | 33 | for { 34 | if n := len(q.front); n > 0 { 35 | e := q.front[n-1] 36 | q.front[n-1] = nil 37 | q.front = q.front[:n-1] 38 | return e 39 | } 40 | 41 | if n := len(q.back); n > 0 { 42 | e := q.back[0] 43 | q.back[0] = nil 44 | q.back = q.back[1:] 45 | return e 46 | } 47 | 48 | q.cond.Wait() 49 | } 50 | } 51 | 52 | // Send implements the screen.EventDeque interface. 53 | func (q *Deque) Send(event interface{}) { 54 | q.lockAndInit() 55 | defer q.mu.Unlock() 56 | 57 | q.back = append(q.back, event) 58 | q.cond.Signal() 59 | } 60 | 61 | // SendFirst implements the screen.EventDeque interface. 62 | func (q *Deque) SendFirst(event interface{}) { 63 | q.lockAndInit() 64 | defer q.mu.Unlock() 65 | 66 | q.front = append(q.front, event) 67 | q.cond.Signal() 68 | } 69 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/internal/lifecycler/lifecycler.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package lifecycler tracks a window's lifecycle state. 6 | // 7 | // It eliminates sending redundant lifecycle events, ones where the From and To 8 | // stages are equal. For example, moving a window from one part of the screen 9 | // to another should not send multiple events from StageVisible to 10 | // StageVisible, even though the underlying window system's message might only 11 | // hold the new position, and not whether the window was previously visible. 12 | package lifecycler // import "golang.org/x/exp/shiny/driver/internal/lifecycler" 13 | 14 | import ( 15 | "sync" 16 | 17 | "golang.org/x/mobile/event/lifecycle" 18 | ) 19 | 20 | // State is a window's lifecycle state. 21 | type State struct { 22 | mu sync.Mutex 23 | stage lifecycle.Stage 24 | dead bool 25 | focused bool 26 | visible bool 27 | } 28 | 29 | func (s *State) SetDead(b bool) { 30 | s.mu.Lock() 31 | s.dead = b 32 | s.mu.Unlock() 33 | } 34 | 35 | func (s *State) SetFocused(b bool) { 36 | s.mu.Lock() 37 | s.focused = b 38 | s.mu.Unlock() 39 | } 40 | 41 | func (s *State) SetVisible(b bool) { 42 | s.mu.Lock() 43 | s.visible = b 44 | s.mu.Unlock() 45 | } 46 | 47 | func (s *State) SendEvent(r Sender, drawContext interface{}) { 48 | s.mu.Lock() 49 | from, to := s.stage, lifecycle.StageAlive 50 | // The order of these if's is important. For example, once a window becomes 51 | // StageDead, it should never change stage again. 52 | // 53 | // Similarly, focused trumps visible. It's hard to imagine a situation 54 | // where a window is focused and not visible on screen, but in that 55 | // unlikely case, StageFocused seems the most appropriate stage. 56 | if s.dead { 57 | to = lifecycle.StageDead 58 | } else if s.focused { 59 | to = lifecycle.StageFocused 60 | } else if s.visible { 61 | to = lifecycle.StageVisible 62 | } 63 | s.stage = to 64 | s.mu.Unlock() 65 | 66 | if from != to { 67 | r.Send(lifecycle.Event{ 68 | From: from, 69 | To: to, 70 | 71 | // TODO: does shiny use this at all? 72 | DrawContext: drawContext, 73 | }) 74 | } 75 | } 76 | 77 | // Sender is who to send the lifecycle event to. 78 | type Sender interface { 79 | Send(event interface{}) 80 | } 81 | -------------------------------------------------------------------------------- /vendor/golang.org/x/exp/shiny/driver/internal/win32/syscall.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:generate go run $GOROOT/src/syscall/mksyscall_windows.go -output zsyscall_windows.go syscall_windows.go 6 | 7 | package win32 8 | -------------------------------------------------------------------------------- /vendor/golang.org/x/image/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/image/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/image/font/basicfont/basicfont.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:generate go run gen.go 6 | 7 | // Package basicfont provides fixed-size font faces. 8 | package basicfont // import "golang.org/x/image/font/basicfont" 9 | 10 | import ( 11 | "image" 12 | 13 | "golang.org/x/image/font" 14 | "golang.org/x/image/math/fixed" 15 | ) 16 | 17 | // Range maps a contiguous range of runes to vertically adjacent sub-images of 18 | // a Face's Mask image. The rune range is inclusive on the low end and 19 | // exclusive on the high end. 20 | // 21 | // If Low <= r && r < High, then the rune r is mapped to the sub-image of 22 | // Face.Mask whose bounds are image.Rect(0, y*h, Face.Width, (y+1)*h), 23 | // where y = (int(r-Low) + Offset) and h = (Face.Ascent + Face.Descent). 24 | type Range struct { 25 | Low, High rune 26 | Offset int 27 | } 28 | 29 | // Face7x13 is a Face derived from the public domain X11 misc-fixed font files. 30 | // 31 | // At the moment, it holds the printable characters in ASCII starting with 32 | // space, and the Unicode replacement character U+FFFD. 33 | // 34 | // Its data is entirely self-contained and does not require loading from 35 | // separate files. 36 | var Face7x13 = &Face{ 37 | Advance: 7, 38 | Width: 6, 39 | Height: 13, 40 | Ascent: 11, 41 | Descent: 2, 42 | Mask: mask7x13, 43 | Ranges: []Range{ 44 | {'\u0020', '\u007f', 0}, 45 | {'\ufffd', '\ufffe', 95}, 46 | }, 47 | } 48 | 49 | // Face is a basic font face whose glyphs all have the same metrics. 50 | // 51 | // It is safe to use concurrently. 52 | type Face struct { 53 | // Advance is the glyph advance, in pixels. 54 | Advance int 55 | // Width is the glyph width, in pixels. 56 | Width int 57 | // Height is the inter-line height, in pixels. 58 | Height int 59 | // Ascent is the glyph ascent, in pixels. 60 | Ascent int 61 | // Descent is the glyph descent, in pixels. 62 | Descent int 63 | // Left is the left side bearing, in pixels. A positive value means that 64 | // all of a glyph is to the right of the dot. 65 | Left int 66 | 67 | // Mask contains all of the glyph masks. Its width is typically the Face's 68 | // Width, and its height a multiple of the Face's Height. 69 | Mask image.Image 70 | // Ranges map runes to sub-images of Mask. The rune ranges must not 71 | // overlap, and must be in increasing rune order. 72 | Ranges []Range 73 | } 74 | 75 | func (f *Face) Close() error { return nil } 76 | func (f *Face) Kern(r0, r1 rune) fixed.Int26_6 { return 0 } 77 | 78 | func (f *Face) Metrics() font.Metrics { 79 | return font.Metrics{ 80 | Height: fixed.I(f.Height), 81 | Ascent: fixed.I(f.Ascent), 82 | Descent: fixed.I(f.Descent), 83 | XHeight: fixed.I(f.Ascent), 84 | CapHeight: fixed.I(f.Ascent), 85 | CaretSlope: image.Point{X: 0, Y: 1}, 86 | } 87 | } 88 | 89 | func (f *Face) Glyph(dot fixed.Point26_6, r rune) ( 90 | dr image.Rectangle, mask image.Image, maskp image.Point, advance fixed.Int26_6, ok bool) { 91 | 92 | loop: 93 | for _, rr := range [2]rune{r, '\ufffd'} { 94 | for _, rng := range f.Ranges { 95 | if rr < rng.Low || rng.High <= rr { 96 | continue 97 | } 98 | maskp.Y = (int(rr-rng.Low) + rng.Offset) * (f.Ascent + f.Descent) 99 | ok = true 100 | break loop 101 | } 102 | } 103 | if !ok { 104 | return image.Rectangle{}, nil, image.Point{}, 0, false 105 | } 106 | 107 | x := int(dot.X+32)>>6 + f.Left 108 | y := int(dot.Y+32) >> 6 109 | dr = image.Rectangle{ 110 | Min: image.Point{ 111 | X: x, 112 | Y: y - f.Ascent, 113 | }, 114 | Max: image.Point{ 115 | X: x + f.Width, 116 | Y: y + f.Descent, 117 | }, 118 | } 119 | 120 | return dr, f.Mask, maskp, fixed.I(f.Advance), true 121 | } 122 | 123 | func (f *Face) GlyphBounds(r rune) (bounds fixed.Rectangle26_6, advance fixed.Int26_6, ok bool) { 124 | return fixed.R(0, -f.Ascent, f.Width, +f.Descent), fixed.I(f.Advance), true 125 | } 126 | 127 | func (f *Face) GlyphAdvance(r rune) (advance fixed.Int26_6, ok bool) { 128 | return fixed.I(f.Advance), true 129 | } 130 | -------------------------------------------------------------------------------- /vendor/golang.org/x/image/math/f64/f64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package f64 implements float64 vector and matrix types. 6 | package f64 // import "golang.org/x/image/math/f64" 7 | 8 | // Vec2 is a 2-element vector. 9 | type Vec2 [2]float64 10 | 11 | // Vec3 is a 3-element vector. 12 | type Vec3 [3]float64 13 | 14 | // Vec4 is a 4-element vector. 15 | type Vec4 [4]float64 16 | 17 | // Mat3 is a 3x3 matrix in row major order. 18 | // 19 | // m[3*r + c] is the element in the r'th row and c'th column. 20 | type Mat3 [9]float64 21 | 22 | // Mat4 is a 4x4 matrix in row major order. 23 | // 24 | // m[4*r + c] is the element in the r'th row and c'th column. 25 | type Mat4 [16]float64 26 | 27 | // Aff3 is a 3x3 affine transformation matrix in row major order, where the 28 | // bottom row is implicitly [0 0 1]. 29 | // 30 | // m[3*r + c] is the element in the r'th row and c'th column. 31 | type Aff3 [6]float64 32 | 33 | // Aff4 is a 4x4 affine transformation matrix in row major order, where the 34 | // bottom row is implicitly [0 0 0 1]. 35 | // 36 | // m[4*r + c] is the element in the r'th row and c'th column. 37 | type Aff4 [12]float64 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/GoNativeActivity.java: -------------------------------------------------------------------------------- 1 | package org.golang.app; 2 | 3 | import android.app.Activity; 4 | import android.app.NativeActivity; 5 | import android.content.Context; 6 | import android.content.pm.ActivityInfo; 7 | import android.content.pm.PackageManager; 8 | import android.os.Bundle; 9 | import android.util.Log; 10 | import android.view.KeyCharacterMap; 11 | 12 | public class GoNativeActivity extends NativeActivity { 13 | private static GoNativeActivity goNativeActivity; 14 | 15 | public GoNativeActivity() { 16 | super(); 17 | goNativeActivity = this; 18 | } 19 | 20 | String getTmpdir() { 21 | return getCacheDir().getAbsolutePath(); 22 | } 23 | 24 | static int getRune(int deviceId, int keyCode, int metaState) { 25 | try { 26 | int rune = KeyCharacterMap.load(deviceId).get(keyCode, metaState); 27 | if (rune == 0) { 28 | return -1; 29 | } 30 | return rune; 31 | } catch (KeyCharacterMap.UnavailableException e) { 32 | return -1; 33 | } catch (Exception e) { 34 | Log.e("Go", "exception reading KeyCharacterMap", e); 35 | return -1; 36 | } 37 | } 38 | 39 | private void load() { 40 | // Interestingly, NativeActivity uses a different method 41 | // to find native code to execute, avoiding 42 | // System.loadLibrary. The result is Java methods 43 | // implemented in C with JNIEXPORT (and JNI_OnLoad) are not 44 | // available unless an explicit call to System.loadLibrary 45 | // is done. So we do it here, borrowing the name of the 46 | // library from the same AndroidManifest.xml metadata used 47 | // by NativeActivity. 48 | try { 49 | ActivityInfo ai = getPackageManager().getActivityInfo( 50 | getIntent().getComponent(), PackageManager.GET_META_DATA); 51 | if (ai.metaData == null) { 52 | Log.e("Go", "loadLibrary: no manifest metadata found"); 53 | return; 54 | } 55 | String libName = ai.metaData.getString("android.app.lib_name"); 56 | System.loadLibrary(libName); 57 | } catch (Exception e) { 58 | Log.e("Go", "loadLibrary failed", e); 59 | } 60 | } 61 | 62 | @Override 63 | public void onCreate(Bundle savedInstanceState) { 64 | load(); 65 | super.onCreate(savedInstanceState); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/darwin_ios.m: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin && ios 6 | // +build darwin 7 | // +build ios 8 | 9 | #include "_cgo_export.h" 10 | #include 11 | #include 12 | #include 13 | 14 | #import 15 | #import 16 | 17 | struct utsname sysInfo; 18 | 19 | @interface GoAppAppController : GLKViewController 20 | @end 21 | 22 | @interface GoAppAppDelegate : UIResponder 23 | @property (strong, nonatomic) UIWindow *window; 24 | @property (strong, nonatomic) GoAppAppController *controller; 25 | @end 26 | 27 | @implementation GoAppAppDelegate 28 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 29 | lifecycleAlive(); 30 | self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 31 | self.controller = [[GoAppAppController alloc] initWithNibName:nil bundle:nil]; 32 | self.window.rootViewController = self.controller; 33 | [self.window makeKeyAndVisible]; 34 | return YES; 35 | } 36 | 37 | - (void)applicationDidBecomeActive:(UIApplication * )application { 38 | lifecycleFocused(); 39 | } 40 | 41 | - (void)applicationWillResignActive:(UIApplication *)application { 42 | lifecycleVisible(); 43 | } 44 | 45 | - (void)applicationDidEnterBackground:(UIApplication *)application { 46 | lifecycleAlive(); 47 | } 48 | 49 | - (void)applicationWillTerminate:(UIApplication *)application { 50 | lifecycleDead(); 51 | } 52 | @end 53 | 54 | @interface GoAppAppController () 55 | @property (strong, nonatomic) EAGLContext *context; 56 | @property (strong, nonatomic) GLKView *glview; 57 | @end 58 | 59 | @implementation GoAppAppController 60 | - (void)viewWillAppear:(BOOL)animated 61 | { 62 | // TODO: replace by swapping out GLKViewController for a UIVIewController. 63 | [super viewWillAppear:animated]; 64 | self.paused = YES; 65 | } 66 | 67 | - (void)viewDidLoad { 68 | [super viewDidLoad]; 69 | self.context = [[EAGLContext alloc] initWithAPI:kEAGLRenderingAPIOpenGLES2]; 70 | self.glview = (GLKView*)self.view; 71 | self.glview.drawableDepthFormat = GLKViewDrawableDepthFormat24; 72 | self.glview.multipleTouchEnabled = true; // TODO expose setting to user. 73 | self.glview.context = self.context; 74 | self.glview.userInteractionEnabled = YES; 75 | self.glview.enableSetNeedsDisplay = YES; // only invoked once 76 | 77 | // Do not use the GLKViewController draw loop. 78 | self.paused = YES; 79 | self.resumeOnDidBecomeActive = NO; 80 | self.preferredFramesPerSecond = 0; 81 | 82 | int scale = 1; 83 | if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)]) { 84 | scale = (int)[UIScreen mainScreen].scale; // either 1.0, 2.0, or 3.0. 85 | } 86 | setScreen(scale); 87 | 88 | CGSize size = [UIScreen mainScreen].bounds.size; 89 | UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 90 | updateConfig((int)size.width, (int)size.height, orientation); 91 | } 92 | 93 | - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { 94 | [coordinator animateAlongsideTransition:^(id context) { 95 | // TODO(crawshaw): come up with a plan to handle animations. 96 | } completion:^(id context) { 97 | UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 98 | updateConfig((int)size.width, (int)size.height, orientation); 99 | }]; 100 | } 101 | 102 | - (void)glkView:(GLKView *)view drawInRect:(CGRect)rect { 103 | // Now that we have been asked to do the first draw, disable any 104 | // future draw and hand control over to the Go paint.Event cycle. 105 | self.glview.enableSetNeedsDisplay = NO; 106 | startloop((GLintptr)self.context); 107 | } 108 | 109 | #define TOUCH_TYPE_BEGIN 0 // touch.TypeBegin 110 | #define TOUCH_TYPE_MOVE 1 // touch.TypeMove 111 | #define TOUCH_TYPE_END 2 // touch.TypeEnd 112 | 113 | static void sendTouches(int change, NSSet* touches) { 114 | CGFloat scale = [UIScreen mainScreen].scale; 115 | for (UITouch* touch in touches) { 116 | CGPoint p = [touch locationInView:touch.view]; 117 | sendTouch((GoUintptr)touch, (GoUintptr)change, p.x*scale, p.y*scale); 118 | } 119 | } 120 | 121 | - (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event { 122 | sendTouches(TOUCH_TYPE_BEGIN, touches); 123 | } 124 | 125 | - (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { 126 | sendTouches(TOUCH_TYPE_MOVE, touches); 127 | } 128 | 129 | - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event { 130 | sendTouches(TOUCH_TYPE_END, touches); 131 | } 132 | 133 | - (void)touchesCanceled:(NSSet*)touches withEvent:(UIEvent*)event { 134 | sendTouches(TOUCH_TYPE_END, touches); 135 | } 136 | @end 137 | 138 | void runApp(void) { 139 | char* argv[] = {}; 140 | @autoreleasepool { 141 | UIApplicationMain(0, argv, nil, NSStringFromClass([GoAppAppDelegate class])); 142 | } 143 | } 144 | 145 | void makeCurrentContext(GLintptr context) { 146 | EAGLContext* ctx = (EAGLContext*)context; 147 | if (![EAGLContext setCurrentContext:ctx]) { 148 | // TODO(crawshaw): determine how terrible this is. Exit? 149 | NSLog(@"failed to set current context"); 150 | } 151 | } 152 | 153 | void swapBuffers(GLintptr context) { 154 | __block EAGLContext* ctx = (EAGLContext*)context; 155 | dispatch_sync(dispatch_get_main_queue(), ^{ 156 | [EAGLContext setCurrentContext:ctx]; 157 | [ctx presentRenderbuffer:GL_RENDERBUFFER]; 158 | }); 159 | } 160 | 161 | uint64_t threadID() { 162 | uint64_t id; 163 | if (pthread_threadid_np(pthread_self(), &id)) { 164 | abort(); 165 | } 166 | return id; 167 | } 168 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package app lets you write portable all-Go apps for Android and iOS. 7 | 8 | There are typically two ways to use Go on Android and iOS. The first 9 | is to write a Go library and use `gomobile bind` to generate language 10 | bindings for Java and Objective-C. Building a library does not 11 | require the app package. The `gomobile bind` command produces output 12 | that you can include in an Android Studio or Xcode project. For more 13 | on language bindings, see https://golang.org/x/mobile/cmd/gobind. 14 | 15 | The second way is to write an app entirely in Go. The APIs are limited 16 | to those that are portable between both Android and iOS, in particular 17 | OpenGL, audio, and other Android NDK-like APIs. An all-Go app should 18 | use this app package to initialize the app, manage its lifecycle, and 19 | receive events. 20 | 21 | # Building apps 22 | 23 | Apps written entirely in Go have a main function, and can be built 24 | with `gomobile build`, which directly produces runnable output for 25 | Android and iOS. 26 | 27 | The gomobile tool can get installed with go get. For reference, see 28 | https://golang.org/x/mobile/cmd/gomobile. 29 | 30 | For detailed instructions and documentation, see 31 | https://golang.org/wiki/Mobile. 32 | 33 | # Event processing in Native Apps 34 | 35 | The Go runtime is initialized on Android when NativeActivity onCreate is 36 | called, and on iOS when the process starts. In both cases, Go init functions 37 | run before the app lifecycle has started. 38 | 39 | An app is expected to call the Main function in main.main. When the function 40 | exits, the app exits. Inside the func passed to Main, call Filter on every 41 | event received, and then switch on its type. Registered filters run when the 42 | event is received, not when it is sent, so that filters run in the same 43 | goroutine as other code that calls OpenGL. 44 | 45 | package main 46 | 47 | import ( 48 | "log" 49 | 50 | "golang.org/x/mobile/app" 51 | "golang.org/x/mobile/event/lifecycle" 52 | "golang.org/x/mobile/event/paint" 53 | ) 54 | 55 | func main() { 56 | app.Main(func(a app.App) { 57 | for e := range a.Events() { 58 | switch e := a.Filter(e).(type) { 59 | case lifecycle.Event: 60 | // ... 61 | case paint.Event: 62 | log.Print("Call OpenGL here.") 63 | a.Publish() 64 | } 65 | } 66 | }) 67 | } 68 | 69 | An event is represented by the empty interface type interface{}. Any value can 70 | be an event. Commonly used types include Event types defined by the following 71 | packages: 72 | - golang.org/x/mobile/event/lifecycle 73 | - golang.org/x/mobile/event/mouse 74 | - golang.org/x/mobile/event/paint 75 | - golang.org/x/mobile/event/size 76 | - golang.org/x/mobile/event/touch 77 | 78 | For example, touch.Event is the type that represents touch events. Other 79 | packages may define their own events, and send them on an app's event channel. 80 | 81 | Other packages can also register event filters, e.g. to manage resources in 82 | response to lifecycle events. Such packages should call: 83 | 84 | app.RegisterFilter(etc) 85 | 86 | in an init function inside that package. 87 | */ 88 | package app // import "golang.org/x/mobile/app" 89 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/internal/callfn/callfn.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build android && (arm || 386 || amd64 || arm64) 6 | // +build android 7 | // +build arm 386 amd64 arm64 8 | 9 | // Package callfn provides an android entry point. 10 | // 11 | // It is a separate package from app because it contains Go assembly, 12 | // which does not compile in a package using cgo. 13 | package callfn 14 | 15 | // CallFn calls a zero-argument function by its program counter. 16 | // It is only intended for calling main.main. Using it for 17 | // anything else will not end well. 18 | func CallFn(fn uintptr) 19 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/internal/callfn/callfn_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | #include "funcdata.h" 7 | 8 | TEXT ·CallFn(SB),$0-4 9 | MOVL fn+0(FP), AX 10 | CALL AX 11 | RET 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/internal/callfn/callfn_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | #include "funcdata.h" 7 | 8 | TEXT ·CallFn(SB),$0-8 9 | MOVQ fn+0(FP), AX 10 | CALL AX 11 | RET 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/internal/callfn/callfn_arm.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | #include "funcdata.h" 7 | 8 | TEXT ·CallFn(SB),$0-4 9 | MOVW fn+0(FP), R0 10 | BL (R0) 11 | RET 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/internal/callfn/callfn_arm64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | #include "funcdata.h" 7 | 8 | TEXT ·CallFn(SB),$0-8 9 | MOVD fn+0(FP), R0 10 | BL (R0) 11 | RET 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/shiny.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build windows 6 | // +build windows 7 | 8 | package app 9 | 10 | import ( 11 | "log" 12 | 13 | "golang.org/x/exp/shiny/driver/gldriver" 14 | "golang.org/x/exp/shiny/screen" 15 | "golang.org/x/mobile/event/lifecycle" 16 | "golang.org/x/mobile/event/mouse" 17 | "golang.org/x/mobile/event/touch" 18 | "golang.org/x/mobile/gl" 19 | ) 20 | 21 | func main(f func(a App)) { 22 | gldriver.Main(func(s screen.Screen) { 23 | w, err := s.NewWindow(nil) 24 | if err != nil { 25 | log.Fatal(err) 26 | } 27 | defer w.Release() 28 | 29 | theApp.glctx = nil 30 | theApp.worker = nil // handled by shiny 31 | 32 | go func() { 33 | for range theApp.publish { 34 | res := w.Publish() 35 | theApp.publishResult <- PublishResult{ 36 | BackBufferPreserved: res.BackBufferPreserved, 37 | } 38 | } 39 | }() 40 | 41 | donec := make(chan struct{}) 42 | go func() { 43 | // close the donec channel in a defer statement 44 | // so that we could still be able to return even 45 | // if f panics. 46 | defer close(donec) 47 | 48 | f(theApp) 49 | }() 50 | 51 | for { 52 | select { 53 | case <-donec: 54 | return 55 | default: 56 | theApp.Send(convertEvent(w.NextEvent())) 57 | } 58 | } 59 | }) 60 | } 61 | 62 | func convertEvent(e interface{}) interface{} { 63 | switch e := e.(type) { 64 | case lifecycle.Event: 65 | if theApp.glctx == nil { 66 | theApp.glctx = e.DrawContext.(gl.Context) 67 | } 68 | case mouse.Event: 69 | te := touch.Event{ 70 | X: e.X, 71 | Y: e.Y, 72 | } 73 | switch e.Direction { 74 | case mouse.DirNone: 75 | te.Type = touch.TypeMove 76 | case mouse.DirPress: 77 | te.Type = touch.TypeBegin 78 | case mouse.DirRelease: 79 | te.Type = touch.TypeEnd 80 | } 81 | return te 82 | } 83 | return e 84 | } 85 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/x11.c: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build linux && !android 6 | // +build linux,!android 7 | 8 | #include "_cgo_export.h" 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | static Atom wm_delete_window; 17 | 18 | static Window 19 | new_window(Display *x_dpy, EGLDisplay e_dpy, int w, int h, EGLContext *ctx, EGLSurface *surf) { 20 | static const EGLint attribs[] = { 21 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 22 | EGL_SURFACE_TYPE, EGL_WINDOW_BIT, 23 | EGL_BLUE_SIZE, 8, 24 | EGL_GREEN_SIZE, 8, 25 | EGL_RED_SIZE, 8, 26 | EGL_DEPTH_SIZE, 16, 27 | EGL_CONFIG_CAVEAT, EGL_NONE, 28 | EGL_NONE 29 | }; 30 | EGLConfig config; 31 | EGLint num_configs; 32 | if (!eglChooseConfig(e_dpy, attribs, &config, 1, &num_configs)) { 33 | fprintf(stderr, "eglChooseConfig failed\n"); 34 | exit(1); 35 | } 36 | EGLint vid; 37 | if (!eglGetConfigAttrib(e_dpy, config, EGL_NATIVE_VISUAL_ID, &vid)) { 38 | fprintf(stderr, "eglGetConfigAttrib failed\n"); 39 | exit(1); 40 | } 41 | 42 | XVisualInfo visTemplate; 43 | visTemplate.visualid = vid; 44 | int num_visuals; 45 | XVisualInfo *visInfo = XGetVisualInfo(x_dpy, VisualIDMask, &visTemplate, &num_visuals); 46 | if (!visInfo) { 47 | fprintf(stderr, "XGetVisualInfo failed\n"); 48 | exit(1); 49 | } 50 | 51 | Window root = RootWindow(x_dpy, DefaultScreen(x_dpy)); 52 | XSetWindowAttributes attr; 53 | 54 | attr.colormap = XCreateColormap(x_dpy, root, visInfo->visual, AllocNone); 55 | if (!attr.colormap) { 56 | fprintf(stderr, "XCreateColormap failed\n"); 57 | exit(1); 58 | } 59 | 60 | attr.event_mask = StructureNotifyMask | ExposureMask | 61 | ButtonPressMask | ButtonReleaseMask | ButtonMotionMask; 62 | Window win = XCreateWindow( 63 | x_dpy, root, 0, 0, w, h, 0, visInfo->depth, InputOutput, 64 | visInfo->visual, CWColormap | CWEventMask, &attr); 65 | XFree(visInfo); 66 | 67 | XSizeHints sizehints; 68 | sizehints.width = w; 69 | sizehints.height = h; 70 | sizehints.flags = USSize; 71 | XSetNormalHints(x_dpy, win, &sizehints); 72 | XSetStandardProperties(x_dpy, win, "App", "App", None, (char **)NULL, 0, &sizehints); 73 | 74 | static const EGLint ctx_attribs[] = { 75 | EGL_CONTEXT_CLIENT_VERSION, 2, 76 | EGL_NONE 77 | }; 78 | *ctx = eglCreateContext(e_dpy, config, EGL_NO_CONTEXT, ctx_attribs); 79 | if (!*ctx) { 80 | fprintf(stderr, "eglCreateContext failed\n"); 81 | exit(1); 82 | } 83 | *surf = eglCreateWindowSurface(e_dpy, config, win, NULL); 84 | if (!*surf) { 85 | fprintf(stderr, "eglCreateWindowSurface failed\n"); 86 | exit(1); 87 | } 88 | return win; 89 | } 90 | 91 | Display *x_dpy; 92 | EGLDisplay e_dpy; 93 | EGLContext e_ctx; 94 | EGLSurface e_surf; 95 | Window win; 96 | 97 | void 98 | createWindow(void) { 99 | x_dpy = XOpenDisplay(NULL); 100 | if (!x_dpy) { 101 | fprintf(stderr, "XOpenDisplay failed\n"); 102 | exit(1); 103 | } 104 | e_dpy = eglGetDisplay(x_dpy); 105 | if (!e_dpy) { 106 | fprintf(stderr, "eglGetDisplay failed\n"); 107 | exit(1); 108 | } 109 | EGLint e_major, e_minor; 110 | if (!eglInitialize(e_dpy, &e_major, &e_minor)) { 111 | fprintf(stderr, "eglInitialize failed\n"); 112 | exit(1); 113 | } 114 | eglBindAPI(EGL_OPENGL_ES_API); 115 | win = new_window(x_dpy, e_dpy, 600, 800, &e_ctx, &e_surf); 116 | 117 | wm_delete_window = XInternAtom(x_dpy, "WM_DELETE_WINDOW", True); 118 | if (wm_delete_window != None) { 119 | XSetWMProtocols(x_dpy, win, &wm_delete_window, 1); 120 | } 121 | 122 | XMapWindow(x_dpy, win); 123 | if (!eglMakeCurrent(e_dpy, e_surf, e_surf, e_ctx)) { 124 | fprintf(stderr, "eglMakeCurrent failed\n"); 125 | exit(1); 126 | } 127 | 128 | // Window size and DPI should be initialized before starting app. 129 | XEvent ev; 130 | while (1) { 131 | if (XCheckMaskEvent(x_dpy, StructureNotifyMask, &ev) == False) { 132 | continue; 133 | } 134 | if (ev.type == ConfigureNotify) { 135 | onResize(ev.xconfigure.width, ev.xconfigure.height); 136 | break; 137 | } 138 | } 139 | } 140 | 141 | void 142 | processEvents(void) { 143 | while (XPending(x_dpy)) { 144 | XEvent ev; 145 | XNextEvent(x_dpy, &ev); 146 | switch (ev.type) { 147 | case ButtonPress: 148 | onTouchBegin((float)ev.xbutton.x, (float)ev.xbutton.y); 149 | break; 150 | case ButtonRelease: 151 | onTouchEnd((float)ev.xbutton.x, (float)ev.xbutton.y); 152 | break; 153 | case MotionNotify: 154 | onTouchMove((float)ev.xmotion.x, (float)ev.xmotion.y); 155 | break; 156 | case ConfigureNotify: 157 | onResize(ev.xconfigure.width, ev.xconfigure.height); 158 | break; 159 | case ClientMessage: 160 | if (wm_delete_window != None && (Atom)ev.xclient.data.l[0] == wm_delete_window) { 161 | onStop(); 162 | return; 163 | } 164 | break; 165 | } 166 | } 167 | } 168 | 169 | void 170 | swapBuffers(void) { 171 | if (eglSwapBuffers(e_dpy, e_surf) == EGL_FALSE) { 172 | fprintf(stderr, "eglSwapBuffer failed\n"); 173 | exit(1); 174 | } 175 | } 176 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/app/x11.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build linux && !android 6 | // +build linux,!android 7 | 8 | package app 9 | 10 | /* 11 | Simple on-screen app debugging for X11. Not an officially supported 12 | development target for apps, as screens with mice are very different 13 | than screens with touch panels. 14 | */ 15 | 16 | /* 17 | #cgo LDFLAGS: -lEGL -lGLESv2 -lX11 18 | 19 | void createWindow(void); 20 | void processEvents(void); 21 | void swapBuffers(void); 22 | */ 23 | import "C" 24 | import ( 25 | "runtime" 26 | "time" 27 | 28 | "golang.org/x/mobile/event/lifecycle" 29 | "golang.org/x/mobile/event/paint" 30 | "golang.org/x/mobile/event/size" 31 | "golang.org/x/mobile/event/touch" 32 | "golang.org/x/mobile/geom" 33 | ) 34 | 35 | func init() { 36 | theApp.registerGLViewportFilter() 37 | } 38 | 39 | func main(f func(App)) { 40 | runtime.LockOSThread() 41 | 42 | workAvailable := theApp.worker.WorkAvailable() 43 | 44 | C.createWindow() 45 | 46 | // TODO: send lifecycle events when e.g. the X11 window is iconified or moved off-screen. 47 | theApp.sendLifecycle(lifecycle.StageFocused) 48 | 49 | // TODO: translate X11 expose events to shiny paint events, instead of 50 | // sending this synthetic paint event as a hack. 51 | theApp.eventsIn <- paint.Event{} 52 | 53 | donec := make(chan struct{}) 54 | go func() { 55 | // close the donec channel in a defer statement 56 | // so that we could still be able to return even 57 | // if f panics. 58 | defer close(donec) 59 | 60 | f(theApp) 61 | }() 62 | 63 | // TODO: can we get the actual vsync signal? 64 | ticker := time.NewTicker(time.Second / 60) 65 | defer ticker.Stop() 66 | var tc <-chan time.Time 67 | 68 | for { 69 | select { 70 | case <-donec: 71 | return 72 | case <-workAvailable: 73 | theApp.worker.DoWork() 74 | case <-theApp.publish: 75 | C.swapBuffers() 76 | tc = ticker.C 77 | case <-tc: 78 | tc = nil 79 | theApp.publishResult <- PublishResult{} 80 | } 81 | C.processEvents() 82 | } 83 | } 84 | 85 | //export onResize 86 | func onResize(w, h int) { 87 | // TODO(nigeltao): don't assume 72 DPI. DisplayWidth and DisplayWidthMM 88 | // is probably the best place to start looking. 89 | pixelsPerPt := float32(1) 90 | theApp.eventsIn <- size.Event{ 91 | WidthPx: w, 92 | HeightPx: h, 93 | WidthPt: geom.Pt(w), 94 | HeightPt: geom.Pt(h), 95 | PixelsPerPt: pixelsPerPt, 96 | } 97 | } 98 | 99 | func sendTouch(t touch.Type, x, y float32) { 100 | theApp.eventsIn <- touch.Event{ 101 | X: x, 102 | Y: y, 103 | Sequence: 0, // TODO: button?? 104 | Type: t, 105 | } 106 | } 107 | 108 | //export onTouchBegin 109 | func onTouchBegin(x, y float32) { sendTouch(touch.TypeBegin, x, y) } 110 | 111 | //export onTouchMove 112 | func onTouchMove(x, y float32) { sendTouch(touch.TypeMove, x, y) } 113 | 114 | //export onTouchEnd 115 | func onTouchEnd(x, y float32) { sendTouch(touch.TypeEnd, x, y) } 116 | 117 | var stopped bool 118 | 119 | //export onStop 120 | func onStop() { 121 | if stopped { 122 | return 123 | } 124 | stopped = true 125 | theApp.sendLifecycle(lifecycle.StageDead) 126 | theApp.eventsIn <- stopPumping{} 127 | } 128 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/event/key/code_string.go: -------------------------------------------------------------------------------- 1 | // Code generated by "stringer -type=Code"; DO NOT EDIT 2 | 3 | package key 4 | 5 | import "fmt" 6 | 7 | const ( 8 | _Code_name_0 = "CodeUnknown" 9 | _Code_name_1 = "CodeACodeBCodeCCodeDCodeECodeFCodeGCodeHCodeICodeJCodeKCodeLCodeMCodeNCodeOCodePCodeQCodeRCodeSCodeTCodeUCodeVCodeWCodeXCodeYCodeZCode1Code2Code3Code4Code5Code6Code7Code8Code9Code0CodeReturnEnterCodeEscapeCodeDeleteBackspaceCodeTabCodeSpacebarCodeHyphenMinusCodeEqualSignCodeLeftSquareBracketCodeRightSquareBracketCodeBackslash" 10 | _Code_name_2 = "CodeSemicolonCodeApostropheCodeGraveAccentCodeCommaCodeFullStopCodeSlashCodeCapsLockCodeF1CodeF2CodeF3CodeF4CodeF5CodeF6CodeF7CodeF8CodeF9CodeF10CodeF11CodeF12" 11 | _Code_name_3 = "CodePauseCodeInsertCodeHomeCodePageUpCodeDeleteForwardCodeEndCodePageDownCodeRightArrowCodeLeftArrowCodeDownArrowCodeUpArrowCodeKeypadNumLockCodeKeypadSlashCodeKeypadAsteriskCodeKeypadHyphenMinusCodeKeypadPlusSignCodeKeypadEnterCodeKeypad1CodeKeypad2CodeKeypad3CodeKeypad4CodeKeypad5CodeKeypad6CodeKeypad7CodeKeypad8CodeKeypad9CodeKeypad0CodeKeypadFullStop" 12 | _Code_name_4 = "CodeKeypadEqualSignCodeF13CodeF14CodeF15CodeF16CodeF17CodeF18CodeF19CodeF20CodeF21CodeF22CodeF23CodeF24" 13 | _Code_name_5 = "CodeHelp" 14 | _Code_name_6 = "CodeMuteCodeVolumeUpCodeVolumeDown" 15 | _Code_name_7 = "CodeLeftControlCodeLeftShiftCodeLeftAltCodeLeftGUICodeRightControlCodeRightShiftCodeRightAltCodeRightGUI" 16 | _Code_name_8 = "CodeCompose" 17 | ) 18 | 19 | var ( 20 | _Code_index_0 = [...]uint8{0, 11} 21 | _Code_index_1 = [...]uint16{0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 165, 170, 175, 180, 195, 205, 224, 231, 243, 258, 271, 292, 314, 327} 22 | _Code_index_2 = [...]uint8{0, 13, 27, 42, 51, 63, 72, 84, 90, 96, 102, 108, 114, 120, 126, 132, 138, 145, 152, 159} 23 | _Code_index_3 = [...]uint16{0, 9, 19, 27, 37, 54, 61, 73, 87, 100, 113, 124, 141, 156, 174, 195, 213, 228, 239, 250, 261, 272, 283, 294, 305, 316, 327, 338, 356} 24 | _Code_index_4 = [...]uint8{0, 19, 26, 33, 40, 47, 54, 61, 68, 75, 82, 89, 96, 103} 25 | _Code_index_5 = [...]uint8{0, 8} 26 | _Code_index_6 = [...]uint8{0, 8, 20, 34} 27 | _Code_index_7 = [...]uint8{0, 15, 28, 39, 50, 66, 80, 92, 104} 28 | _Code_index_8 = [...]uint8{0, 11} 29 | ) 30 | 31 | func (i Code) String() string { 32 | switch { 33 | case i == 0: 34 | return _Code_name_0 35 | case 4 <= i && i <= 49: 36 | i -= 4 37 | return _Code_name_1[_Code_index_1[i]:_Code_index_1[i+1]] 38 | case 51 <= i && i <= 69: 39 | i -= 51 40 | return _Code_name_2[_Code_index_2[i]:_Code_index_2[i+1]] 41 | case 72 <= i && i <= 99: 42 | i -= 72 43 | return _Code_name_3[_Code_index_3[i]:_Code_index_3[i+1]] 44 | case 103 <= i && i <= 115: 45 | i -= 103 46 | return _Code_name_4[_Code_index_4[i]:_Code_index_4[i+1]] 47 | case i == 117: 48 | return _Code_name_5 49 | case 127 <= i && i <= 129: 50 | i -= 127 51 | return _Code_name_6[_Code_index_6[i]:_Code_index_6[i+1]] 52 | case 224 <= i && i <= 231: 53 | i -= 224 54 | return _Code_name_7[_Code_index_7[i]:_Code_index_7[i+1]] 55 | case i == 65536: 56 | return _Code_name_8 57 | default: 58 | return fmt.Sprintf("Code(%d)", i) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/event/lifecycle/lifecycle.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package lifecycle defines an event for an app's lifecycle. 6 | // 7 | // The app lifecycle consists of moving back and forth between an ordered 8 | // sequence of stages. For example, being at a stage greater than or equal to 9 | // StageVisible means that the app is visible on the screen. 10 | // 11 | // A lifecycle event is a change from one stage to another, which crosses every 12 | // intermediate stage. For example, changing from StageAlive to StageFocused 13 | // implicitly crosses StageVisible. 14 | // 15 | // Crosses can be in a positive or negative direction. A positive crossing of 16 | // StageFocused means that the app has gained the focus. A negative crossing 17 | // means it has lost the focus. 18 | // 19 | // See the golang.org/x/mobile/app package for details on the event model. 20 | package lifecycle // import "golang.org/x/mobile/event/lifecycle" 21 | 22 | import ( 23 | "fmt" 24 | ) 25 | 26 | // Cross is whether a lifecycle stage was crossed. 27 | type Cross uint32 28 | 29 | func (c Cross) String() string { 30 | switch c { 31 | case CrossOn: 32 | return "on" 33 | case CrossOff: 34 | return "off" 35 | } 36 | return "none" 37 | } 38 | 39 | const ( 40 | CrossNone Cross = 0 41 | CrossOn Cross = 1 42 | CrossOff Cross = 2 43 | ) 44 | 45 | // Event is a lifecycle change from an old stage to a new stage. 46 | type Event struct { 47 | From, To Stage 48 | 49 | // DrawContext is the state used for painting, if any is valid. 50 | // 51 | // For OpenGL apps, a non-nil DrawContext is a gl.Context. 52 | // 53 | // TODO: make this an App method if we move away from an event channel? 54 | DrawContext interface{} 55 | } 56 | 57 | func (e Event) String() string { 58 | return fmt.Sprintf("lifecycle.Event{From:%v, To:%v, DrawContext:%v}", e.From, e.To, e.DrawContext) 59 | } 60 | 61 | // Crosses reports whether the transition from From to To crosses the stage s: 62 | // - It returns CrossOn if it does, and the lifecycle change is positive. 63 | // - It returns CrossOff if it does, and the lifecycle change is negative. 64 | // - Otherwise, it returns CrossNone. 65 | // 66 | // See the documentation for Stage for more discussion of positive and negative 67 | // crosses. 68 | func (e Event) Crosses(s Stage) Cross { 69 | switch { 70 | case e.From < s && e.To >= s: 71 | return CrossOn 72 | case e.From >= s && e.To < s: 73 | return CrossOff 74 | } 75 | return CrossNone 76 | } 77 | 78 | // Stage is a stage in the app's lifecycle. The values are ordered, so that a 79 | // lifecycle change from stage From to stage To implicitly crosses every stage 80 | // in the range (min, max], exclusive on the low end and inclusive on the high 81 | // end, where min is the minimum of From and To, and max is the maximum. 82 | // 83 | // The documentation for individual stages talk about positive and negative 84 | // crosses. A positive lifecycle change is one where its From stage is less 85 | // than its To stage. Similarly, a negative lifecycle change is one where From 86 | // is greater than To. Thus, a positive lifecycle change crosses every stage in 87 | // the range (From, To] in increasing order, and a negative lifecycle change 88 | // crosses every stage in the range (To, From] in decreasing order. 89 | type Stage uint32 90 | 91 | // TODO: how does iOS map to these stages? What do cross-platform mobile 92 | // abstractions do? 93 | 94 | const ( 95 | // StageDead is the zero stage. No lifecycle change crosses this stage, 96 | // but: 97 | // - A positive change from this stage is the very first lifecycle change. 98 | // - A negative change to this stage is the very last lifecycle change. 99 | StageDead Stage = iota 100 | 101 | // StageAlive means that the app is alive. 102 | // - A positive cross means that the app has been created. 103 | // - A negative cross means that the app is being destroyed. 104 | // Each cross, either from or to StageDead, will occur only once. 105 | // On Android, these correspond to onCreate and onDestroy. 106 | StageAlive 107 | 108 | // StageVisible means that the app window is visible. 109 | // - A positive cross means that the app window has become visible. 110 | // - A negative cross means that the app window has become invisible. 111 | // On Android, these correspond to onStart and onStop. 112 | // On Desktop, an app window can become invisible if e.g. it is minimized, 113 | // unmapped, or not on a visible workspace. 114 | StageVisible 115 | 116 | // StageFocused means that the app window has the focus. 117 | // - A positive cross means that the app window has gained the focus. 118 | // - A negative cross means that the app window has lost the focus. 119 | // On Android, these correspond to onResume and onFreeze. 120 | StageFocused 121 | ) 122 | 123 | func (s Stage) String() string { 124 | switch s { 125 | case StageDead: 126 | return "StageDead" 127 | case StageAlive: 128 | return "StageAlive" 129 | case StageVisible: 130 | return "StageVisible" 131 | case StageFocused: 132 | return "StageFocused" 133 | default: 134 | return fmt.Sprintf("lifecycle.Stage(%d)", s) 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/event/mouse/mouse.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package mouse defines an event for mouse input. 6 | // 7 | // See the golang.org/x/mobile/app package for details on the event model. 8 | package mouse // import "golang.org/x/mobile/event/mouse" 9 | 10 | import ( 11 | "fmt" 12 | 13 | "golang.org/x/mobile/event/key" 14 | ) 15 | 16 | // Event is a mouse event. 17 | type Event struct { 18 | // X and Y are the mouse location, in pixels. 19 | X, Y float32 20 | 21 | // Button is the mouse button being pressed or released. Its value may be 22 | // zero, for a mouse move or drag without any button change. 23 | Button Button 24 | 25 | // TODO: have a field to hold what other buttons are down, for detecting 26 | // drags or button-chords. 27 | 28 | // Modifiers is a bitmask representing a set of modifier keys: 29 | // key.ModShift, key.ModAlt, etc. 30 | Modifiers key.Modifiers 31 | 32 | // Direction is the direction of the mouse event: DirPress, DirRelease, 33 | // or DirNone (for mouse moves or drags). 34 | Direction Direction 35 | 36 | // TODO: add a Device ID, for multiple input devices? 37 | // TODO: add a time.Time? 38 | } 39 | 40 | // Button is a mouse button. 41 | type Button int32 42 | 43 | // IsWheel reports whether the button is for a scroll wheel. 44 | func (b Button) IsWheel() bool { 45 | return b < 0 46 | } 47 | 48 | // TODO: have a separate axis concept for wheel up/down? How does that relate 49 | // to joystick events? 50 | 51 | const ( 52 | ButtonNone Button = +0 53 | ButtonLeft Button = +1 54 | ButtonMiddle Button = +2 55 | ButtonRight Button = +3 56 | 57 | ButtonWheelUp Button = -1 58 | ButtonWheelDown Button = -2 59 | ButtonWheelLeft Button = -3 60 | ButtonWheelRight Button = -4 61 | ) 62 | 63 | // Direction is the direction of the mouse event. 64 | type Direction uint8 65 | 66 | const ( 67 | DirNone Direction = 0 68 | DirPress Direction = 1 69 | DirRelease Direction = 2 70 | // DirStep is a simultaneous press and release, such as a single step of a 71 | // mouse wheel. 72 | // 73 | // Its value equals DirPress | DirRelease. 74 | DirStep Direction = 3 75 | ) 76 | 77 | func (d Direction) String() string { 78 | switch d { 79 | case DirNone: 80 | return "None" 81 | case DirPress: 82 | return "Press" 83 | case DirRelease: 84 | return "Release" 85 | case DirStep: 86 | return "Step" 87 | default: 88 | return fmt.Sprintf("mouse.Direction(%d)", d) 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/event/paint/paint.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package paint defines an event for the app being ready to paint. 6 | // 7 | // See the golang.org/x/mobile/app package for details on the event model. 8 | package paint // import "golang.org/x/mobile/event/paint" 9 | 10 | // Event indicates that the app is ready to paint the next frame of the GUI. 11 | // 12 | // A frame is completed by calling the App's Publish method. 13 | type Event struct { 14 | // External is true for paint events sent by the screen driver. 15 | // 16 | // An external event may be sent at any time in response to an 17 | // operating system event, for example the window opened, was 18 | // resized, or the screen memory was lost. 19 | // 20 | // Programs actively drawing to the screen as fast as vsync allows 21 | // should ignore external paint events to avoid a backlog of paint 22 | // events building up. 23 | External bool 24 | } 25 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/event/size/size.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package size defines an event for the dimensions, physical resolution and 6 | // orientation of the app's window. 7 | // 8 | // See the golang.org/x/mobile/app package for details on the event model. 9 | package size // import "golang.org/x/mobile/event/size" 10 | 11 | import ( 12 | "image" 13 | 14 | "golang.org/x/mobile/geom" 15 | ) 16 | 17 | // Event holds the dimensions, physical resolution and orientation of the app's 18 | // window. 19 | type Event struct { 20 | // WidthPx and HeightPx are the window's dimensions in pixels. 21 | WidthPx, HeightPx int 22 | 23 | // WidthPt and HeightPt are the window's physical dimensions in points 24 | // (1/72 of an inch). 25 | // 26 | // The values are based on PixelsPerPt and are therefore approximate, as 27 | // per the comment on PixelsPerPt. 28 | WidthPt, HeightPt geom.Pt 29 | 30 | // PixelsPerPt is the window's physical resolution. It is the number of 31 | // pixels in a single geom.Pt, from the golang.org/x/mobile/geom package. 32 | // 33 | // There are a wide variety of pixel densities in existing phones and 34 | // tablets, so apps should be written to expect various non-integer 35 | // PixelsPerPt values. In general, work in geom.Pt. 36 | // 37 | // The value is approximate, in that the OS, drivers or hardware may report 38 | // approximate or quantized values. An N x N pixel square should be roughly 39 | // 1 square inch for N = int(PixelsPerPt * 72), although different square 40 | // lengths (in pixels) might be closer to 1 inch in practice. Nonetheless, 41 | // this PixelsPerPt value should be consistent with e.g. the ratio of 42 | // WidthPx to WidthPt. 43 | PixelsPerPt float32 44 | 45 | // Orientation is the orientation of the device screen. 46 | Orientation Orientation 47 | } 48 | 49 | // Size returns the window's size in pixels, at the time this size event was 50 | // sent. 51 | func (e Event) Size() image.Point { 52 | return image.Point{e.WidthPx, e.HeightPx} 53 | } 54 | 55 | // Bounds returns the window's bounds in pixels, at the time this size event 56 | // was sent. 57 | // 58 | // The top-left pixel is always (0, 0). The bottom-right pixel is given by the 59 | // width and height. 60 | func (e Event) Bounds() image.Rectangle { 61 | return image.Rectangle{Max: image.Point{e.WidthPx, e.HeightPx}} 62 | } 63 | 64 | // Orientation is the orientation of the device screen. 65 | type Orientation int 66 | 67 | const ( 68 | // OrientationUnknown means device orientation cannot be determined. 69 | // 70 | // Equivalent on Android to Configuration.ORIENTATION_UNKNOWN 71 | // and on iOS to: 72 | // UIDeviceOrientationUnknown 73 | // UIDeviceOrientationFaceUp 74 | // UIDeviceOrientationFaceDown 75 | OrientationUnknown Orientation = iota 76 | 77 | // OrientationPortrait is a device oriented so it is tall and thin. 78 | // 79 | // Equivalent on Android to Configuration.ORIENTATION_PORTRAIT 80 | // and on iOS to: 81 | // UIDeviceOrientationPortrait 82 | // UIDeviceOrientationPortraitUpsideDown 83 | OrientationPortrait 84 | 85 | // OrientationLandscape is a device oriented so it is short and wide. 86 | // 87 | // Equivalent on Android to Configuration.ORIENTATION_LANDSCAPE 88 | // and on iOS to: 89 | // UIDeviceOrientationLandscapeLeft 90 | // UIDeviceOrientationLandscapeRight 91 | OrientationLandscape 92 | ) 93 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/event/touch/touch.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package touch defines an event for touch input. 6 | // 7 | // See the golang.org/x/mobile/app package for details on the event model. 8 | package touch // import "golang.org/x/mobile/event/touch" 9 | 10 | // The best source on android input events is the NDK: include/android/input.h 11 | // 12 | // iOS event handling guide: 13 | // https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS 14 | 15 | import ( 16 | "fmt" 17 | ) 18 | 19 | // Event is a touch event. 20 | type Event struct { 21 | // X and Y are the touch location, in pixels. 22 | X, Y float32 23 | 24 | // Sequence is the sequence number. The same number is shared by all events 25 | // in a sequence. A sequence begins with a single TypeBegin, is followed by 26 | // zero or more TypeMoves, and ends with a single TypeEnd. A Sequence 27 | // distinguishes concurrent sequences but its value is subsequently reused. 28 | Sequence Sequence 29 | 30 | // Type is the touch type. 31 | Type Type 32 | } 33 | 34 | // Sequence identifies a sequence of touch events. 35 | type Sequence int64 36 | 37 | // Type describes the type of a touch event. 38 | type Type byte 39 | 40 | const ( 41 | // TypeBegin is a user first touching the device. 42 | // 43 | // On Android, this is a AMOTION_EVENT_ACTION_DOWN. 44 | // On iOS, this is a call to touchesBegan. 45 | TypeBegin Type = iota 46 | 47 | // TypeMove is a user dragging across the device. 48 | // 49 | // A TypeMove is delivered between a TypeBegin and TypeEnd. 50 | // 51 | // On Android, this is a AMOTION_EVENT_ACTION_MOVE. 52 | // On iOS, this is a call to touchesMoved. 53 | TypeMove 54 | 55 | // TypeEnd is a user no longer touching the device. 56 | // 57 | // On Android, this is a AMOTION_EVENT_ACTION_UP. 58 | // On iOS, this is a call to touchesEnded. 59 | TypeEnd 60 | ) 61 | 62 | func (t Type) String() string { 63 | switch t { 64 | case TypeBegin: 65 | return "begin" 66 | case TypeMove: 67 | return "move" 68 | case TypeEnd: 69 | return "end" 70 | } 71 | return fmt.Sprintf("touch.Type(%d)", t) 72 | } 73 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/exp/f32/affine.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package f32 6 | 7 | import "fmt" 8 | 9 | // An Affine is a 3x3 matrix of float32 values for which the bottom row is 10 | // implicitly always equal to [0 0 1]. 11 | // Elements are indexed first by row then column, i.e. m[row][column]. 12 | type Affine [2]Vec3 13 | 14 | func (m Affine) String() string { 15 | return fmt.Sprintf(`Affine[% 0.3f, % 0.3f, % 0.3f, 16 | % 0.3f, % 0.3f, % 0.3f]`, 17 | m[0][0], m[0][1], m[0][2], 18 | m[1][0], m[1][1], m[1][2]) 19 | } 20 | 21 | // Identity sets m to be the identity transform. 22 | func (m *Affine) Identity() { 23 | *m = Affine{ 24 | {1, 0, 0}, 25 | {0, 1, 0}, 26 | } 27 | } 28 | 29 | // Eq reports whether each component of m is within epsilon of the same 30 | // component in n. 31 | func (m *Affine) Eq(n *Affine, epsilon float32) bool { 32 | for i := range m { 33 | for j := range m[i] { 34 | diff := m[i][j] - n[i][j] 35 | if diff < -epsilon || +epsilon < diff { 36 | return false 37 | } 38 | } 39 | } 40 | return true 41 | } 42 | 43 | // Mul sets m to be p × q. 44 | func (m *Affine) Mul(p, q *Affine) { 45 | // Store the result in local variables, in case m == a || m == b. 46 | m00 := p[0][0]*q[0][0] + p[0][1]*q[1][0] 47 | m01 := p[0][0]*q[0][1] + p[0][1]*q[1][1] 48 | m02 := p[0][0]*q[0][2] + p[0][1]*q[1][2] + p[0][2] 49 | m10 := p[1][0]*q[0][0] + p[1][1]*q[1][0] 50 | m11 := p[1][0]*q[0][1] + p[1][1]*q[1][1] 51 | m12 := p[1][0]*q[0][2] + p[1][1]*q[1][2] + p[1][2] 52 | m[0][0] = m00 53 | m[0][1] = m01 54 | m[0][2] = m02 55 | m[1][0] = m10 56 | m[1][1] = m11 57 | m[1][2] = m12 58 | } 59 | 60 | // Inverse sets m to be the inverse of p. 61 | func (m *Affine) Inverse(p *Affine) { 62 | m00 := p[1][1] 63 | m01 := -p[0][1] 64 | m02 := p[1][2]*p[0][1] - p[1][1]*p[0][2] 65 | m10 := -p[1][0] 66 | m11 := p[0][0] 67 | m12 := p[1][0]*p[0][2] - p[1][2]*p[0][0] 68 | 69 | det := m00*m11 - m10*m01 70 | 71 | m[0][0] = m00 / det 72 | m[0][1] = m01 / det 73 | m[0][2] = m02 / det 74 | m[1][0] = m10 / det 75 | m[1][1] = m11 / det 76 | m[1][2] = m12 / det 77 | } 78 | 79 | // Scale sets m to be a scale followed by p. 80 | // It is equivalent to m.Mul(p, &Affine{{x,0,0}, {0,y,0}}). 81 | func (m *Affine) Scale(p *Affine, x, y float32) { 82 | m[0][0] = p[0][0] * x 83 | m[0][1] = p[0][1] * y 84 | m[0][2] = p[0][2] 85 | m[1][0] = p[1][0] * x 86 | m[1][1] = p[1][1] * y 87 | m[1][2] = p[1][2] 88 | } 89 | 90 | // Translate sets m to be a translation followed by p. 91 | // It is equivalent to m.Mul(p, &Affine{{1,0,x}, {0,1,y}}). 92 | func (m *Affine) Translate(p *Affine, x, y float32) { 93 | m[0][0] = p[0][0] 94 | m[0][1] = p[0][1] 95 | m[0][2] = p[0][0]*x + p[0][1]*y + p[0][2] 96 | m[1][0] = p[1][0] 97 | m[1][1] = p[1][1] 98 | m[1][2] = p[1][0]*x + p[1][1]*y + p[1][2] 99 | } 100 | 101 | // Rotate sets m to a rotation in radians followed by p. 102 | // It is equivalent to m.Mul(p, affineRotation). 103 | func (m *Affine) Rotate(p *Affine, radians float32) { 104 | s, c := Sin(radians), Cos(radians) 105 | m.Mul(p, &Affine{ 106 | {+c, +s, 0}, 107 | {-s, +c, 0}, 108 | }) 109 | } 110 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/exp/f32/f32.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:generate go run gen.go -output table.go 6 | 7 | // Package f32 implements some linear algebra and GL helpers for float32s. 8 | // 9 | // Types defined in this package have methods implementing common 10 | // mathematical operations. The common form for these functions is 11 | // 12 | // func (dst *T) Op(lhs, rhs *T) 13 | // 14 | // which reads in traditional mathematical notation as 15 | // 16 | // dst = lhs op rhs. 17 | // 18 | // It is safe to use the destination address as the left-hand side, 19 | // that is, dst *= rhs is dst.Mul(dst, rhs). 20 | // 21 | // # WARNING 22 | // 23 | // The interface to this package is not stable. It will change considerably. 24 | // Only use functions that provide package documentation. Semantics are 25 | // non-obvious. Be prepared for the package name to change. 26 | package f32 // import "golang.org/x/mobile/exp/f32" 27 | 28 | import ( 29 | "encoding/binary" 30 | "fmt" 31 | "math" 32 | ) 33 | 34 | type Radian float32 35 | 36 | func Cos(x float32) float32 { 37 | const n = sinTableLen 38 | i := uint32(int32(x * (n / math.Pi))) 39 | i += n / 2 40 | i &= 2*n - 1 41 | if i >= n { 42 | return -sinTable[i&(n-1)] 43 | } 44 | return sinTable[i&(n-1)] 45 | } 46 | 47 | func Sin(x float32) float32 { 48 | const n = sinTableLen 49 | i := uint32(int32(x * (n / math.Pi))) 50 | i &= 2*n - 1 51 | if i >= n { 52 | return -sinTable[i&(n-1)] 53 | } 54 | return sinTable[i&(n-1)] 55 | } 56 | 57 | func Sqrt(x float32) float32 { 58 | return float32(math.Sqrt(float64(x))) // TODO(crawshaw): implement 59 | } 60 | 61 | func Tan(x float32) float32 { 62 | return float32(math.Tan(float64(x))) // TODO(crawshaw): fast version 63 | } 64 | 65 | // Bytes returns the byte representation of float32 values in the given byte 66 | // order. byteOrder must be either binary.BigEndian or binary.LittleEndian. 67 | func Bytes(byteOrder binary.ByteOrder, values ...float32) []byte { 68 | le := false 69 | switch byteOrder { 70 | case binary.BigEndian: 71 | case binary.LittleEndian: 72 | le = true 73 | default: 74 | panic(fmt.Sprintf("invalid byte order %v", byteOrder)) 75 | } 76 | 77 | b := make([]byte, 4*len(values)) 78 | for i, v := range values { 79 | u := math.Float32bits(v) 80 | if le { 81 | b[4*i+0] = byte(u >> 0) 82 | b[4*i+1] = byte(u >> 8) 83 | b[4*i+2] = byte(u >> 16) 84 | b[4*i+3] = byte(u >> 24) 85 | } else { 86 | b[4*i+0] = byte(u >> 24) 87 | b[4*i+1] = byte(u >> 16) 88 | b[4*i+2] = byte(u >> 8) 89 | b[4*i+3] = byte(u >> 0) 90 | } 91 | } 92 | return b 93 | } 94 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/exp/f32/mat3.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package f32 6 | 7 | import "fmt" 8 | 9 | // A Mat3 is a 3x3 matrix of float32 values. 10 | // Elements are indexed first by row then column, i.e. m[row][column]. 11 | type Mat3 [3]Vec3 12 | 13 | func (m Mat3) String() string { 14 | return fmt.Sprintf(`Mat3[% 0.3f, % 0.3f, % 0.3f, 15 | % 0.3f, % 0.3f, % 0.3f, 16 | % 0.3f, % 0.3f, % 0.3f]`, 17 | m[0][0], m[0][1], m[0][2], 18 | m[1][0], m[1][1], m[1][2], 19 | m[2][0], m[2][1], m[2][2]) 20 | } 21 | 22 | func (m *Mat3) Identity() { 23 | *m = Mat3{ 24 | {1, 0, 0}, 25 | {0, 1, 0}, 26 | {0, 0, 1}, 27 | } 28 | } 29 | 30 | func (m *Mat3) Eq(n *Mat3, epsilon float32) bool { 31 | for i := range m { 32 | for j := range m[i] { 33 | diff := m[i][j] - n[i][j] 34 | if diff < -epsilon || +epsilon < diff { 35 | return false 36 | } 37 | } 38 | } 39 | return true 40 | } 41 | 42 | // Mul stores a × b in m. 43 | func (m *Mat3) Mul(a, b *Mat3) { 44 | // Store the result in local variables, in case m == a || m == b. 45 | m00 := a[0][0]*b[0][0] + a[0][1]*b[1][0] + a[0][2]*b[2][0] 46 | m01 := a[0][0]*b[0][1] + a[0][1]*b[1][1] + a[0][2]*b[2][1] 47 | m02 := a[0][0]*b[0][2] + a[0][1]*b[1][2] + a[0][2]*b[2][2] 48 | m10 := a[1][0]*b[0][0] + a[1][1]*b[1][0] + a[1][2]*b[2][0] 49 | m11 := a[1][0]*b[0][1] + a[1][1]*b[1][1] + a[1][2]*b[2][1] 50 | m12 := a[1][0]*b[0][2] + a[1][1]*b[1][2] + a[1][2]*b[2][2] 51 | m20 := a[2][0]*b[0][0] + a[2][1]*b[1][0] + a[2][2]*b[2][0] 52 | m21 := a[2][0]*b[0][1] + a[2][1]*b[1][1] + a[2][2]*b[2][1] 53 | m22 := a[2][0]*b[0][2] + a[2][1]*b[1][2] + a[2][2]*b[2][2] 54 | m[0][0] = m00 55 | m[0][1] = m01 56 | m[0][2] = m02 57 | m[1][0] = m10 58 | m[1][1] = m11 59 | m[1][2] = m12 60 | m[2][0] = m20 61 | m[2][1] = m21 62 | m[2][2] = m22 63 | } 64 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/exp/f32/vec3.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package f32 6 | 7 | import "fmt" 8 | 9 | type Vec3 [3]float32 10 | 11 | func (v Vec3) String() string { 12 | return fmt.Sprintf("Vec3[% 0.3f, % 0.3f, % 0.3f]", v[0], v[1], v[2]) 13 | } 14 | 15 | func (v *Vec3) Normalize() { 16 | sq := v.Dot(v) 17 | inv := 1 / Sqrt(sq) 18 | v[0] *= inv 19 | v[1] *= inv 20 | v[2] *= inv 21 | } 22 | 23 | func (v *Vec3) Sub(v0, v1 *Vec3) { 24 | v[0] = v0[0] - v1[0] 25 | v[1] = v0[1] - v1[1] 26 | v[2] = v0[2] - v1[2] 27 | } 28 | 29 | func (v *Vec3) Add(v0, v1 *Vec3) { 30 | v[0] = v0[0] + v1[0] 31 | v[1] = v0[1] + v1[1] 32 | v[2] = v0[2] + v1[2] 33 | } 34 | 35 | func (v *Vec3) Mul(v0, v1 *Vec3) { 36 | v[0] = v0[0] * v1[0] 37 | v[1] = v0[1] * v1[1] 38 | v[2] = v0[2] * v1[2] 39 | } 40 | 41 | func (v *Vec3) Cross(v0, v1 *Vec3) { 42 | v[0] = v0[1]*v1[2] - v0[2]*v1[1] 43 | v[1] = v0[2]*v1[0] - v0[0]*v1[2] 44 | v[2] = v0[0]*v1[1] - v0[1]*v1[0] 45 | } 46 | 47 | func (v *Vec3) Dot(v1 *Vec3) float32 { 48 | return v[0]*v1[0] + v[1]*v1[1] + v[2]*v1[2] 49 | } 50 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/exp/f32/vec4.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package f32 6 | 7 | import "fmt" 8 | 9 | type Vec4 [4]float32 10 | 11 | func (v Vec4) String() string { 12 | return fmt.Sprintf("Vec4[% 0.3f, % 0.3f, % 0.3f, % 0.3f]", v[0], v[1], v[2], v[3]) 13 | } 14 | 15 | func (v *Vec4) Normalize() { 16 | sq := v.Dot(v) 17 | inv := 1 / Sqrt(sq) 18 | v[0] *= inv 19 | v[1] *= inv 20 | v[2] *= inv 21 | v[3] *= inv 22 | } 23 | 24 | func (v *Vec4) Sub(v0, v1 *Vec4) { 25 | v[0] = v0[0] - v1[0] 26 | v[1] = v0[1] - v1[1] 27 | v[2] = v0[2] - v1[2] 28 | v[3] = v0[3] - v1[3] 29 | } 30 | 31 | func (v *Vec4) Add(v0, v1 *Vec4) { 32 | v[0] = v0[0] + v1[0] 33 | v[1] = v0[1] + v1[1] 34 | v[2] = v0[2] + v1[2] 35 | v[3] = v0[3] + v1[3] 36 | } 37 | 38 | func (v *Vec4) Mul(v0, v1 *Vec4) { 39 | v[0] = v0[0] * v1[0] 40 | v[1] = v0[1] * v1[1] 41 | v[2] = v0[2] * v1[2] 42 | v[3] = v0[3] * v1[3] 43 | } 44 | 45 | func (v *Vec4) Dot(v1 *Vec4) float32 { 46 | return v[0]*v1[0] + v[1]*v1[1] + v[2]*v1[2] + v[3]*v1[3] 47 | } 48 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/exp/gl/glutil/context_darwin_desktop.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin && !ios 6 | // +build darwin,!ios 7 | 8 | package glutil 9 | 10 | // TODO(crawshaw): Only used in glutil tests for now (cgo is not support in _test.go files). 11 | // TODO(crawshaw): Export some kind of Context. Work out what we can offer, where. Maybe just for tests. 12 | // TODO(crawshaw): Support android and windows. 13 | 14 | /* 15 | #cgo CFLAGS: -DGL_SILENCE_DEPRECATION 16 | #cgo LDFLAGS: -framework OpenGL 17 | #import 18 | #import 19 | 20 | CGLError CGCreate(CGLContextObj* ctx) { 21 | CGLError err; 22 | CGLPixelFormatAttribute attributes[] = { 23 | kCGLPFAOpenGLProfile, (CGLPixelFormatAttribute)kCGLOGLPVersion_3_2_Core, 24 | kCGLPFAColorSize, (CGLPixelFormatAttribute)24, 25 | kCGLPFAAlphaSize, (CGLPixelFormatAttribute)8, 26 | kCGLPFADepthSize, (CGLPixelFormatAttribute)16, 27 | kCGLPFAAccelerated, 28 | kCGLPFADoubleBuffer, 29 | (CGLPixelFormatAttribute) 0 30 | }; 31 | CGLPixelFormatObj pix; 32 | GLint num; 33 | 34 | if ((err = CGLChoosePixelFormat(attributes, &pix, &num)) != kCGLNoError) { 35 | return err; 36 | } 37 | if ((err = CGLCreateContext(pix, 0, ctx)) != kCGLNoError) { 38 | return err; 39 | } 40 | if ((err = CGLDestroyPixelFormat(pix)) != kCGLNoError) { 41 | return err; 42 | } 43 | if ((err = CGLSetCurrentContext(*ctx)) != kCGLNoError) { 44 | return err; 45 | } 46 | if ((err = CGLLockContext(*ctx)) != kCGLNoError) { 47 | return err; 48 | } 49 | return kCGLNoError; 50 | } 51 | */ 52 | import "C" 53 | 54 | import ( 55 | "fmt" 56 | "runtime" 57 | ) 58 | 59 | // contextGL holds a copy of the OpenGL Context from thread-local storage. 60 | // 61 | // Do not move a contextGL between goroutines or OS threads. 62 | type contextGL struct { 63 | ctx C.CGLContextObj 64 | } 65 | 66 | // createContext creates an OpenGL context, binds it as the current context 67 | // stored in thread-local storage, and locks the current goroutine to an os 68 | // thread. 69 | func createContext() (*contextGL, error) { 70 | // The OpenGL active context is stored in TLS. 71 | runtime.LockOSThread() 72 | 73 | c := new(contextGL) 74 | if cglErr := C.CGCreate(&c.ctx); cglErr != C.kCGLNoError { 75 | return nil, fmt.Errorf("CGL: %v", C.GoString(C.CGLErrorString(cglErr))) 76 | } 77 | 78 | // Using attribute arrays in OpenGL 3.3 requires the use of a VBA. 79 | // But VBAs don't exist in ES 2. So we bind a default one. 80 | var id C.GLuint 81 | C.glGenVertexArrays(1, &id) 82 | C.glBindVertexArray(id) 83 | 84 | return c, nil 85 | } 86 | 87 | // destroy destroys an OpenGL context and unlocks the current goroutine from 88 | // its os thread. 89 | func (c *contextGL) destroy() { 90 | C.CGLUnlockContext(c.ctx) 91 | C.CGLSetCurrentContext(nil) 92 | C.CGLDestroyContext(c.ctx) 93 | c.ctx = nil 94 | runtime.UnlockOSThread() 95 | } 96 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/exp/gl/glutil/context_x11.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build linux && !android 6 | // +build linux,!android 7 | 8 | package glutil 9 | 10 | /* 11 | #cgo LDFLAGS: -lEGL 12 | #include 13 | #include 14 | #include 15 | 16 | void createContext(EGLDisplay *out_dpy, EGLContext *out_ctx, EGLSurface *out_surf) { 17 | EGLDisplay e_dpy = eglGetDisplay(EGL_DEFAULT_DISPLAY); 18 | if (!e_dpy) { 19 | fprintf(stderr, "eglGetDisplay failed\n"); 20 | exit(1); 21 | } 22 | EGLint e_major, e_minor; 23 | if (!eglInitialize(e_dpy, &e_major, &e_minor)) { 24 | fprintf(stderr, "eglInitialize failed\n"); 25 | exit(1); 26 | } 27 | eglBindAPI(EGL_OPENGL_ES_API); 28 | static const EGLint config_attribs[] = { 29 | EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 30 | EGL_SURFACE_TYPE, EGL_PBUFFER_BIT, 31 | EGL_BLUE_SIZE, 8, 32 | EGL_GREEN_SIZE, 8, 33 | EGL_RED_SIZE, 8, 34 | EGL_CONFIG_CAVEAT, EGL_NONE, 35 | EGL_NONE 36 | }; 37 | EGLConfig config; 38 | EGLint num_configs; 39 | if (!eglChooseConfig(e_dpy, config_attribs, &config, 1, &num_configs)) { 40 | fprintf(stderr, "eglChooseConfig failed\n"); 41 | exit(1); 42 | } 43 | static const EGLint ctx_attribs[] = { 44 | EGL_CONTEXT_CLIENT_VERSION, 2, 45 | EGL_NONE 46 | }; 47 | EGLContext e_ctx = eglCreateContext(e_dpy, config, EGL_NO_CONTEXT, ctx_attribs); 48 | if (e_ctx == EGL_NO_CONTEXT) { 49 | fprintf(stderr, "eglCreateContext failed\n"); 50 | exit(1); 51 | } 52 | static const EGLint pbuf_attribs[] = { 53 | EGL_NONE 54 | }; 55 | EGLSurface e_surf = eglCreatePbufferSurface(e_dpy, config, pbuf_attribs); 56 | if (e_surf == EGL_NO_SURFACE) { 57 | fprintf(stderr, "eglCreatePbufferSurface failed\n"); 58 | exit(1); 59 | } 60 | if (!eglMakeCurrent(e_dpy, e_surf, e_surf, e_ctx)) { 61 | fprintf(stderr, "eglMakeCurrent failed\n"); 62 | exit(1); 63 | } 64 | *out_surf = e_surf; 65 | *out_ctx = e_ctx; 66 | *out_dpy = e_dpy; 67 | } 68 | 69 | void destroyContext(EGLDisplay e_dpy, EGLContext e_ctx, EGLSurface e_surf) { 70 | if (!eglMakeCurrent(e_dpy, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) { 71 | fprintf(stderr, "eglMakeCurrent failed\n"); 72 | exit(1); 73 | } 74 | if (!eglDestroySurface(e_dpy, e_surf)) { 75 | fprintf(stderr, "eglDestroySurface failed\n"); 76 | exit(1); 77 | } 78 | if (!eglDestroyContext(e_dpy, e_ctx)) { 79 | fprintf(stderr, "eglDestroyContext failed\n"); 80 | exit(1); 81 | } 82 | } 83 | */ 84 | import "C" 85 | 86 | import ( 87 | "runtime" 88 | ) 89 | 90 | type contextGL struct { 91 | dpy C.EGLDisplay 92 | ctx C.EGLContext 93 | surf C.EGLSurface 94 | } 95 | 96 | func createContext() (*contextGL, error) { 97 | runtime.LockOSThread() 98 | c := &contextGL{} 99 | C.createContext(&c.dpy, &c.ctx, &c.surf) 100 | return c, nil 101 | } 102 | 103 | func (c *contextGL) destroy() { 104 | C.destroyContext(c.dpy, c.ctx, c.surf) 105 | runtime.UnlockOSThread() 106 | } 107 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/exp/gl/glutil/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package glutil implements OpenGL utility functions. 6 | package glutil // import "golang.org/x/mobile/exp/gl/glutil" 7 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/exp/gl/glutil/glutil.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin || linux || windows 6 | // +build darwin linux windows 7 | 8 | package glutil // import "golang.org/x/mobile/exp/gl/glutil" 9 | 10 | import ( 11 | "fmt" 12 | 13 | "golang.org/x/mobile/exp/f32" 14 | "golang.org/x/mobile/gl" 15 | ) 16 | 17 | // CreateProgram creates, compiles, and links a gl.Program. 18 | func CreateProgram(glctx gl.Context, vertexSrc, fragmentSrc string) (gl.Program, error) { 19 | program := glctx.CreateProgram() 20 | if program.Value == 0 { 21 | return gl.Program{}, fmt.Errorf("glutil: no programs available") 22 | } 23 | 24 | vertexShader, err := loadShader(glctx, gl.VERTEX_SHADER, vertexSrc) 25 | if err != nil { 26 | return gl.Program{}, err 27 | } 28 | fragmentShader, err := loadShader(glctx, gl.FRAGMENT_SHADER, fragmentSrc) 29 | if err != nil { 30 | glctx.DeleteShader(vertexShader) 31 | return gl.Program{}, err 32 | } 33 | 34 | glctx.AttachShader(program, vertexShader) 35 | glctx.AttachShader(program, fragmentShader) 36 | glctx.LinkProgram(program) 37 | 38 | // Flag shaders for deletion when program is unlinked. 39 | glctx.DeleteShader(vertexShader) 40 | glctx.DeleteShader(fragmentShader) 41 | 42 | if glctx.GetProgrami(program, gl.LINK_STATUS) == 0 { 43 | defer glctx.DeleteProgram(program) 44 | return gl.Program{}, fmt.Errorf("glutil: %s", glctx.GetProgramInfoLog(program)) 45 | } 46 | return program, nil 47 | } 48 | 49 | func loadShader(glctx gl.Context, shaderType gl.Enum, src string) (gl.Shader, error) { 50 | shader := glctx.CreateShader(shaderType) 51 | if shader.Value == 0 { 52 | return gl.Shader{}, fmt.Errorf("glutil: could not create shader (type %v)", shaderType) 53 | } 54 | glctx.ShaderSource(shader, src) 55 | glctx.CompileShader(shader) 56 | if glctx.GetShaderi(shader, gl.COMPILE_STATUS) == 0 { 57 | defer glctx.DeleteShader(shader) 58 | return gl.Shader{}, fmt.Errorf("shader compile: %s", glctx.GetShaderInfoLog(shader)) 59 | } 60 | return shader, nil 61 | } 62 | 63 | // writeAffine writes the contents of an Affine to a 3x3 matrix GL uniform. 64 | func writeAffine(glctx gl.Context, u gl.Uniform, a *f32.Affine) { 65 | var m [9]float32 66 | m[0*3+0] = a[0][0] 67 | m[0*3+1] = a[1][0] 68 | m[0*3+2] = 0 69 | m[1*3+0] = a[0][1] 70 | m[1*3+1] = a[1][1] 71 | m[1*3+2] = 0 72 | m[2*3+0] = a[0][2] 73 | m[2*3+1] = a[1][2] 74 | m[2*3+2] = 1 75 | glctx.UniformMatrix3fv(u, m[:]) 76 | } 77 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/geom/geom.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package geom defines a two-dimensional coordinate system. 7 | 8 | The coordinate system is based on an left-handed Cartesian plane. 9 | That is, X increases to the right and Y increases down. For (x,y), 10 | 11 | (0,0) → (1,0) 12 | ↓ ↘ 13 | (0,1) (1,1) 14 | 15 | The display window places the origin (0, 0) in the upper-left corner of 16 | the screen. Positions on the plane are measured in typographic points, 17 | 1/72 of an inch, which is represented by the Pt type. 18 | 19 | Any interface that draws to the screen using types from the geom package 20 | scales the number of pixels to maintain a Pt as 1/72 of an inch. 21 | */ 22 | package geom // import "golang.org/x/mobile/geom" 23 | 24 | /* 25 | Notes on the various underlying coordinate systems. 26 | 27 | Both Android and iOS (UIKit) use upper-left-origin coordinate systems 28 | with for events, however they have different units. 29 | 30 | UIKit measures distance in points. A point is a single-pixel on a 31 | pre-Retina display. UIKit maintains a scale factor that to turn points 32 | into pixels. On current retina devices, the scale factor is 2.0. 33 | 34 | A UIKit point does not correspond to a fixed physical distance, as the 35 | iPhone has a 163 DPI/PPI (326 PPI retina) display, and the iPad has a 36 | 132 PPI (264 retina) display. Points are 32-bit floats. 37 | 38 | Even though point is the official UIKit term, they are commonly called 39 | pixels. Indeed, the units were equivalent until the retina display was 40 | introduced. 41 | 42 | N.b. as a UIKit point is unrelated to a typographic point, it is not 43 | related to this packages's Pt and Point types. 44 | 45 | More details about iOS drawing: 46 | 47 | https://developer.apple.com/library/ios/documentation/2ddrawing/conceptual/drawingprintingios/GraphicsDrawingOverview/GraphicsDrawingOverview.html 48 | 49 | Android uses pixels. Sub-pixel precision is possible, so pixels are 50 | represented as 32-bit floats. The ACONFIGURATION_DENSITY enum provides 51 | the screen DPI/PPI, which varies frequently between devices. 52 | 53 | It would be tempting to adopt the pixel, given the clear pixel/DPI split 54 | in the core android events API. However, the plot thickens: 55 | 56 | http://developer.android.com/training/multiscreen/screendensities.html 57 | 58 | Android promotes the notion of a density-independent pixel in many of 59 | their interfaces, often prefixed by "dp". 1dp is a real physical length, 60 | as "independent" means it is assumed to be 1/160th of an inch and is 61 | adjusted for the current screen. 62 | 63 | In addition, android has a scale-indepdendent pixel used for expressing 64 | a user's preferred text size. The user text size preference is a useful 65 | notion not yet expressed in the geom package. 66 | 67 | For the sake of clarity when working across platforms, the geom package 68 | tries to put distance between it and the word pixel. 69 | */ 70 | 71 | import "fmt" 72 | 73 | // Pt is a length. 74 | // 75 | // The unit Pt is a typographical point, 1/72 of an inch (0.3527 mm). 76 | // 77 | // It can be be converted to a length in current device pixels by 78 | // multiplying with PixelsPerPt after app initialization is complete. 79 | type Pt float32 80 | 81 | // Px converts the length to current device pixels. 82 | func (p Pt) Px(pixelsPerPt float32) float32 { return float32(p) * pixelsPerPt } 83 | 84 | // String returns a string representation of p like "3.2pt". 85 | func (p Pt) String() string { return fmt.Sprintf("%.2fpt", p) } 86 | 87 | // Point is a point in a two-dimensional plane. 88 | type Point struct { 89 | X, Y Pt 90 | } 91 | 92 | // String returns a string representation of p like "(1.2,3.4)". 93 | func (p Point) String() string { return fmt.Sprintf("(%.2f,%.2f)", p.X, p.Y) } 94 | 95 | // A Rectangle is region of points. 96 | // The top-left point is Min, and the bottom-right point is Max. 97 | type Rectangle struct { 98 | Min, Max Point 99 | } 100 | 101 | // String returns a string representation of r like "(3,4)-(6,5)". 102 | func (r Rectangle) String() string { return r.Min.String() + "-" + r.Max.String() } 103 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/gl/doc.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | /* 6 | Package gl implements Go bindings for OpenGL ES 2.0 and ES 3.0. 7 | 8 | The GL functions are defined on a Context object that is responsible for 9 | tracking a GL context. Typically a windowing system package (such as 10 | golang.org/x/exp/shiny/screen) will call NewContext and provide 11 | a gl.Context for a user application. 12 | 13 | If the gl package is compiled on a platform capable of supporting ES 3.0, 14 | the gl.Context object also implements gl.Context3. 15 | 16 | The bindings are deliberately minimal, staying as close the C API as 17 | possible. The semantics of each function maps onto functions 18 | described in the Khronos documentation: 19 | 20 | https://www.khronos.org/opengles/sdk/docs/man/ 21 | 22 | One notable departure from the C API is the introduction of types 23 | to represent common uses of GLint: Texture, Surface, Buffer, etc. 24 | 25 | # Debug Logging 26 | 27 | A tracing version of the OpenGL bindings is behind the `gldebug` build 28 | tag. It acts as a simplified version of apitrace. Build your Go binary 29 | with 30 | 31 | -tags gldebug 32 | 33 | and each call to a GL function will log its input, output, and any 34 | error messages. For example, 35 | 36 | I/GoLog (27668): gl.GenBuffers(1) [Buffer(70001)] 37 | I/GoLog (27668): gl.BindBuffer(ARRAY_BUFFER, Buffer(70001)) 38 | I/GoLog (27668): gl.BufferData(ARRAY_BUFFER, 36, len(36), STATIC_DRAW) 39 | I/GoLog (27668): gl.BindBuffer(ARRAY_BUFFER, Buffer(70001)) 40 | I/GoLog (27668): gl.VertexAttribPointer(Attrib(0), 6, FLOAT, false, 0, 0) error: [INVALID_VALUE] 41 | 42 | The gldebug tracing has very high overhead, so make sure to remove 43 | the build tag before deploying any binaries. 44 | */ 45 | package gl // import "golang.org/x/mobile/gl" 46 | 47 | /* 48 | Implementation details. 49 | 50 | All GL function calls fill out a C.struct_fnargs and drop it on the work 51 | queue. The Start function drains the work queue and hands over a batch 52 | of calls to C.process which runs them. This allows multiple GL calls to 53 | be executed in a single cgo call. 54 | 55 | A GL call is marked as blocking if it returns a value, or if it takes a 56 | Go pointer. In this case the call will not return until C.process sends a 57 | value on the retvalue channel. 58 | 59 | This implementation ensures any goroutine can make GL calls, but it does 60 | not make the GL interface safe for simultaneous use by multiple goroutines. 61 | For the purpose of analyzing this code for race conditions, picture two 62 | separate goroutines: one blocked on gl.Start, and another making calls to 63 | the gl package exported functions. 64 | */ 65 | 66 | //go:generate go run gendebug.go -o gldebug.go 67 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/gl/fn.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package gl 6 | 7 | import "unsafe" 8 | 9 | type call struct { 10 | args fnargs 11 | parg unsafe.Pointer 12 | blocking bool 13 | } 14 | 15 | type fnargs struct { 16 | fn glfn 17 | 18 | a0 uintptr 19 | a1 uintptr 20 | a2 uintptr 21 | a3 uintptr 22 | a4 uintptr 23 | a5 uintptr 24 | a6 uintptr 25 | a7 uintptr 26 | a8 uintptr 27 | a9 uintptr 28 | } 29 | 30 | type glfn int 31 | 32 | const ( 33 | glfnUNDEFINED glfn = iota 34 | glfnActiveTexture 35 | glfnAttachShader 36 | glfnBindAttribLocation 37 | glfnBindBuffer 38 | glfnBindFramebuffer 39 | glfnBindRenderbuffer 40 | glfnBindTexture 41 | glfnBindVertexArray 42 | glfnBlendColor 43 | glfnBlendEquation 44 | glfnBlendEquationSeparate 45 | glfnBlendFunc 46 | glfnBlendFuncSeparate 47 | glfnBufferData 48 | glfnBufferSubData 49 | glfnCheckFramebufferStatus 50 | glfnClear 51 | glfnClearColor 52 | glfnClearDepthf 53 | glfnClearStencil 54 | glfnColorMask 55 | glfnCompileShader 56 | glfnCompressedTexImage2D 57 | glfnCompressedTexSubImage2D 58 | glfnCopyTexImage2D 59 | glfnCopyTexSubImage2D 60 | glfnCreateProgram 61 | glfnCreateShader 62 | glfnCullFace 63 | glfnDeleteBuffer 64 | glfnDeleteFramebuffer 65 | glfnDeleteProgram 66 | glfnDeleteRenderbuffer 67 | glfnDeleteShader 68 | glfnDeleteTexture 69 | glfnDeleteVertexArray 70 | glfnDepthFunc 71 | glfnDepthRangef 72 | glfnDepthMask 73 | glfnDetachShader 74 | glfnDisable 75 | glfnDisableVertexAttribArray 76 | glfnDrawArrays 77 | glfnDrawElements 78 | glfnEnable 79 | glfnEnableVertexAttribArray 80 | glfnFinish 81 | glfnFlush 82 | glfnFramebufferRenderbuffer 83 | glfnFramebufferTexture2D 84 | glfnFrontFace 85 | glfnGenBuffer 86 | glfnGenFramebuffer 87 | glfnGenRenderbuffer 88 | glfnGenTexture 89 | glfnGenVertexArray 90 | glfnGenerateMipmap 91 | glfnGetActiveAttrib 92 | glfnGetActiveUniform 93 | glfnGetAttachedShaders 94 | glfnGetAttribLocation 95 | glfnGetBooleanv 96 | glfnGetBufferParameteri 97 | glfnGetError 98 | glfnGetFloatv 99 | glfnGetFramebufferAttachmentParameteriv 100 | glfnGetIntegerv 101 | glfnGetProgramInfoLog 102 | glfnGetProgramiv 103 | glfnGetRenderbufferParameteriv 104 | glfnGetShaderInfoLog 105 | glfnGetShaderPrecisionFormat 106 | glfnGetShaderSource 107 | glfnGetShaderiv 108 | glfnGetString 109 | glfnGetTexParameterfv 110 | glfnGetTexParameteriv 111 | glfnGetUniformLocation 112 | glfnGetUniformfv 113 | glfnGetUniformiv 114 | glfnGetVertexAttribfv 115 | glfnGetVertexAttribiv 116 | glfnHint 117 | glfnIsBuffer 118 | glfnIsEnabled 119 | glfnIsFramebuffer 120 | glfnIsProgram 121 | glfnIsRenderbuffer 122 | glfnIsShader 123 | glfnIsTexture 124 | glfnLineWidth 125 | glfnLinkProgram 126 | glfnPixelStorei 127 | glfnPolygonOffset 128 | glfnReadPixels 129 | glfnReleaseShaderCompiler 130 | glfnRenderbufferStorage 131 | glfnSampleCoverage 132 | glfnScissor 133 | glfnShaderSource 134 | glfnStencilFunc 135 | glfnStencilFuncSeparate 136 | glfnStencilMask 137 | glfnStencilMaskSeparate 138 | glfnStencilOp 139 | glfnStencilOpSeparate 140 | glfnTexImage2D 141 | glfnTexParameterf 142 | glfnTexParameterfv 143 | glfnTexParameteri 144 | glfnTexParameteriv 145 | glfnTexSubImage2D 146 | glfnUniform1f 147 | glfnUniform1fv 148 | glfnUniform1i 149 | glfnUniform1iv 150 | glfnUniform2f 151 | glfnUniform2fv 152 | glfnUniform2i 153 | glfnUniform2iv 154 | glfnUniform3f 155 | glfnUniform3fv 156 | glfnUniform3i 157 | glfnUniform3iv 158 | glfnUniform4f 159 | glfnUniform4fv 160 | glfnUniform4i 161 | glfnUniform4iv 162 | glfnUniformMatrix2fv 163 | glfnUniformMatrix3fv 164 | glfnUniformMatrix4fv 165 | glfnUseProgram 166 | glfnValidateProgram 167 | glfnVertexAttrib1f 168 | glfnVertexAttrib1fv 169 | glfnVertexAttrib2f 170 | glfnVertexAttrib2fv 171 | glfnVertexAttrib3f 172 | glfnVertexAttrib3fv 173 | glfnVertexAttrib4f 174 | glfnVertexAttrib4fv 175 | glfnVertexAttribPointer 176 | glfnViewport 177 | 178 | // ES 3.0 functions 179 | glfnUniformMatrix2x3fv 180 | glfnUniformMatrix3x2fv 181 | glfnUniformMatrix2x4fv 182 | glfnUniformMatrix4x2fv 183 | glfnUniformMatrix3x4fv 184 | glfnUniformMatrix4x3fv 185 | glfnBlitFramebuffer 186 | glfnUniform1ui 187 | glfnUniform2ui 188 | glfnUniform3ui 189 | glfnUniform4ui 190 | glfnUniform1uiv 191 | glfnUniform2uiv 192 | glfnUniform3uiv 193 | glfnUniform4uiv 194 | ) 195 | 196 | func goString(buf []byte) string { 197 | for i, b := range buf { 198 | if b == 0 { 199 | return string(buf[:i]) 200 | } 201 | } 202 | panic("buf is not NUL-terminated") 203 | } 204 | 205 | func glBoolean(b bool) uintptr { 206 | if b { 207 | return TRUE 208 | } 209 | return FALSE 210 | } 211 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/gl/types_debug.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build (darwin || linux || openbsd || windows) && gldebug 6 | // +build darwin linux openbsd windows 7 | // +build gldebug 8 | 9 | package gl 10 | 11 | // Alternate versions of the types defined in types.go with extra 12 | // debugging information attached. For documentation, see types.go. 13 | 14 | import "fmt" 15 | 16 | type Enum uint32 17 | 18 | type Attrib struct { 19 | Value uint 20 | name string 21 | } 22 | 23 | type Program struct { 24 | Init bool 25 | Value uint32 26 | } 27 | 28 | type Shader struct { 29 | Value uint32 30 | } 31 | 32 | type Buffer struct { 33 | Value uint32 34 | } 35 | 36 | type Framebuffer struct { 37 | Value uint32 38 | } 39 | 40 | type Renderbuffer struct { 41 | Value uint32 42 | } 43 | 44 | type Texture struct { 45 | Value uint32 46 | } 47 | 48 | type Uniform struct { 49 | Value int32 50 | name string 51 | } 52 | 53 | type VertexArray struct { 54 | Value uint32 55 | } 56 | 57 | func (v Attrib) c() uintptr { return uintptr(v.Value) } 58 | func (v Enum) c() uintptr { return uintptr(v) } 59 | func (v Program) c() uintptr { 60 | if !v.Init { 61 | ret := uintptr(0) 62 | ret-- 63 | return ret 64 | } 65 | return uintptr(v.Value) 66 | } 67 | func (v Shader) c() uintptr { return uintptr(v.Value) } 68 | func (v Buffer) c() uintptr { return uintptr(v.Value) } 69 | func (v Framebuffer) c() uintptr { return uintptr(v.Value) } 70 | func (v Renderbuffer) c() uintptr { return uintptr(v.Value) } 71 | func (v Texture) c() uintptr { return uintptr(v.Value) } 72 | func (v Uniform) c() uintptr { return uintptr(v.Value) } 73 | func (v VertexArray) c() uintptr { return uintptr(v.Value) } 74 | 75 | func (v Attrib) String() string { return fmt.Sprintf("Attrib(%d:%s)", v.Value, v.name) } 76 | func (v Program) String() string { return fmt.Sprintf("Program(%d)", v.Value) } 77 | func (v Shader) String() string { return fmt.Sprintf("Shader(%d)", v.Value) } 78 | func (v Buffer) String() string { return fmt.Sprintf("Buffer(%d)", v.Value) } 79 | func (v Framebuffer) String() string { return fmt.Sprintf("Framebuffer(%d)", v.Value) } 80 | func (v Renderbuffer) String() string { return fmt.Sprintf("Renderbuffer(%d)", v.Value) } 81 | func (v Texture) String() string { return fmt.Sprintf("Texture(%d)", v.Value) } 82 | func (v Uniform) String() string { return fmt.Sprintf("Uniform(%d:%s)", v.Value, v.name) } 83 | func (v VertexArray) String() string { return fmt.Sprintf("VertexArray(%d)", v.Value) } 84 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/gl/types_prod.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build (darwin || linux || openbsd || windows) && !gldebug 6 | // +build darwin linux openbsd windows 7 | // +build !gldebug 8 | 9 | package gl 10 | 11 | import "fmt" 12 | 13 | // Enum is equivalent to GLenum, and is normally used with one of the 14 | // constants defined in this package. 15 | type Enum uint32 16 | 17 | // Types are defined a structs so that in debug mode they can carry 18 | // extra information, such as a string name. See typesdebug.go. 19 | 20 | // Attrib identifies the location of a specific attribute variable. 21 | type Attrib struct { 22 | Value uint 23 | } 24 | 25 | // Program identifies a compiled shader program. 26 | type Program struct { 27 | // Init is set by CreateProgram, as some GL drivers (in particular, 28 | // ANGLE) return true for glIsProgram(0). 29 | Init bool 30 | Value uint32 31 | } 32 | 33 | // Shader identifies a GLSL shader. 34 | type Shader struct { 35 | Value uint32 36 | } 37 | 38 | // Buffer identifies a GL buffer object. 39 | type Buffer struct { 40 | Value uint32 41 | } 42 | 43 | // Framebuffer identifies a GL framebuffer. 44 | type Framebuffer struct { 45 | Value uint32 46 | } 47 | 48 | // A Renderbuffer is a GL object that holds an image in an internal format. 49 | type Renderbuffer struct { 50 | Value uint32 51 | } 52 | 53 | // A Texture identifies a GL texture unit. 54 | type Texture struct { 55 | Value uint32 56 | } 57 | 58 | // Uniform identifies the location of a specific uniform variable. 59 | type Uniform struct { 60 | Value int32 61 | } 62 | 63 | // A VertexArray is a GL object that holds vertices in an internal format. 64 | type VertexArray struct { 65 | Value uint32 66 | } 67 | 68 | func (v Attrib) c() uintptr { return uintptr(v.Value) } 69 | func (v Enum) c() uintptr { return uintptr(v) } 70 | func (v Program) c() uintptr { 71 | if !v.Init { 72 | ret := uintptr(0) 73 | ret-- 74 | return ret 75 | } 76 | return uintptr(v.Value) 77 | } 78 | func (v Shader) c() uintptr { return uintptr(v.Value) } 79 | func (v Buffer) c() uintptr { return uintptr(v.Value) } 80 | func (v Framebuffer) c() uintptr { return uintptr(v.Value) } 81 | func (v Renderbuffer) c() uintptr { return uintptr(v.Value) } 82 | func (v Texture) c() uintptr { return uintptr(v.Value) } 83 | func (v Uniform) c() uintptr { return uintptr(v.Value) } 84 | func (v VertexArray) c() uintptr { return uintptr(v.Value) } 85 | 86 | func (v Attrib) String() string { return fmt.Sprintf("Attrib(%d)", v.Value) } 87 | func (v Program) String() string { return fmt.Sprintf("Program(%d)", v.Value) } 88 | func (v Shader) String() string { return fmt.Sprintf("Shader(%d)", v.Value) } 89 | func (v Buffer) String() string { return fmt.Sprintf("Buffer(%d)", v.Value) } 90 | func (v Framebuffer) String() string { return fmt.Sprintf("Framebuffer(%d)", v.Value) } 91 | func (v Renderbuffer) String() string { return fmt.Sprintf("Renderbuffer(%d)", v.Value) } 92 | func (v Texture) String() string { return fmt.Sprintf("Texture(%d)", v.Value) } 93 | func (v Uniform) String() string { return fmt.Sprintf("Uniform(%d)", v.Value) } 94 | func (v VertexArray) String() string { return fmt.Sprintf("VertexArray(%d)", v.Value) } 95 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/gl/work.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build darwin || linux || openbsd 6 | // +build darwin linux openbsd 7 | 8 | package gl 9 | 10 | /* 11 | #cgo ios LDFLAGS: -framework OpenGLES 12 | #cgo darwin,!ios LDFLAGS: -framework OpenGL 13 | #cgo linux LDFLAGS: -lGLESv2 14 | #cgo openbsd LDFLAGS: -L/usr/X11R6/lib/ -lGLESv2 15 | 16 | #cgo android CFLAGS: -Dos_android 17 | #cgo ios CFLAGS: -Dos_ios 18 | #cgo darwin,!ios CFLAGS: -Dos_macos 19 | #cgo darwin CFLAGS: -DGL_SILENCE_DEPRECATION -DGLES_SILENCE_DEPRECATION 20 | #cgo linux CFLAGS: -Dos_linux 21 | #cgo openbsd CFLAGS: -Dos_openbsd 22 | 23 | #cgo openbsd CFLAGS: -I/usr/X11R6/include/ 24 | 25 | #include 26 | #include "work.h" 27 | 28 | uintptr_t process(struct fnargs* cargs, char* parg0, char* parg1, char* parg2, int count) { 29 | uintptr_t ret; 30 | 31 | ret = processFn(&cargs[0], parg0); 32 | if (count > 1) { 33 | ret = processFn(&cargs[1], parg1); 34 | } 35 | if (count > 2) { 36 | ret = processFn(&cargs[2], parg2); 37 | } 38 | 39 | return ret; 40 | } 41 | */ 42 | import "C" 43 | 44 | import "unsafe" 45 | 46 | const workbufLen = 3 47 | 48 | type context struct { 49 | cptr uintptr 50 | debug int32 51 | 52 | workAvailable chan struct{} 53 | 54 | // work is a queue of calls to execute. 55 | work chan call 56 | 57 | // retvalue is sent a return value when blocking calls complete. 58 | // It is safe to use a global unbuffered channel here as calls 59 | // cannot currently be made concurrently. 60 | // 61 | // TODO: the comment above about concurrent calls isn't actually true: package 62 | // app calls package gl, but it has to do so in a separate goroutine, which 63 | // means that its gl calls (which may be blocking) can race with other gl calls 64 | // in the main program. We should make it safe to issue blocking gl calls 65 | // concurrently, or get the gl calls out of package app, or both. 66 | retvalue chan C.uintptr_t 67 | 68 | cargs [workbufLen]C.struct_fnargs 69 | parg [workbufLen]*C.char 70 | } 71 | 72 | func (ctx *context) WorkAvailable() <-chan struct{} { return ctx.workAvailable } 73 | 74 | type context3 struct { 75 | *context 76 | } 77 | 78 | // NewContext creates a cgo OpenGL context. 79 | // 80 | // See the Worker interface for more details on how it is used. 81 | func NewContext() (Context, Worker) { 82 | glctx := &context{ 83 | workAvailable: make(chan struct{}, 1), 84 | work: make(chan call, workbufLen), 85 | retvalue: make(chan C.uintptr_t), 86 | } 87 | if C.GLES_VERSION == "GL_ES_2_0" { 88 | return glctx, glctx 89 | } 90 | return context3{glctx}, glctx 91 | } 92 | 93 | // Version returns a GL ES version string, either "GL_ES_2_0" or "GL_ES_3_0". 94 | // Future versions of the gl package may return "GL_ES_3_1". 95 | func Version() string { 96 | return C.GLES_VERSION 97 | } 98 | 99 | func (ctx *context) enqueue(c call) uintptr { 100 | ctx.work <- c 101 | 102 | select { 103 | case ctx.workAvailable <- struct{}{}: 104 | default: 105 | } 106 | 107 | if c.blocking { 108 | return uintptr(<-ctx.retvalue) 109 | } 110 | return 0 111 | } 112 | 113 | func (ctx *context) DoWork() { 114 | queue := make([]call, 0, workbufLen) 115 | for { 116 | // Wait until at least one piece of work is ready. 117 | // Accumulate work until a piece is marked as blocking. 118 | select { 119 | case w := <-ctx.work: 120 | queue = append(queue, w) 121 | default: 122 | return 123 | } 124 | blocking := queue[len(queue)-1].blocking 125 | enqueue: 126 | for len(queue) < cap(queue) && !blocking { 127 | select { 128 | case w := <-ctx.work: 129 | queue = append(queue, w) 130 | blocking = queue[len(queue)-1].blocking 131 | default: 132 | break enqueue 133 | } 134 | } 135 | 136 | // Process the queued GL functions. 137 | for i, q := range queue { 138 | ctx.cargs[i] = *(*C.struct_fnargs)(unsafe.Pointer(&q.args)) 139 | ctx.parg[i] = (*C.char)(q.parg) 140 | } 141 | ret := C.process(&ctx.cargs[0], ctx.parg[0], ctx.parg[1], ctx.parg[2], C.int(len(queue))) 142 | 143 | // Cleanup and signal. 144 | queue = queue[:0] 145 | if blocking { 146 | ctx.retvalue <- ret 147 | } 148 | } 149 | } 150 | 151 | func init() { 152 | if unsafe.Sizeof(C.GLint(0)) != unsafe.Sizeof(int32(0)) { 153 | panic("GLint is not an int32") 154 | } 155 | } 156 | 157 | // cString creates C string off the Go heap. 158 | // ret is a *char. 159 | func (ctx *context) cString(str string) (uintptr, func()) { 160 | ptr := unsafe.Pointer(C.CString(str)) 161 | return uintptr(ptr), func() { C.free(ptr) } 162 | } 163 | 164 | // cString creates a pointer to a C string off the Go heap. 165 | // ret is a **char. 166 | func (ctx *context) cStringPtr(str string) (uintptr, func()) { 167 | s, free := ctx.cString(str) 168 | ptr := C.malloc(C.size_t(unsafe.Sizeof((*int)(nil)))) 169 | *(*uintptr)(ptr) = s 170 | return uintptr(ptr), func() { 171 | free() 172 | C.free(ptr) 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/gl/work.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #ifdef os_android 6 | // TODO(crawshaw): We could include and 7 | // condition on __ANDROID_API__ to get GLES3 headers. However 8 | // we also need to add -lGLESv3 to LDFLAGS, which we cannot do 9 | // from inside an ifdef. 10 | #include 11 | #elif os_linux 12 | #include // install on Ubuntu with: sudo apt-get install libegl1-mesa-dev libgles2-mesa-dev libx11-dev 13 | #elif os_openbsd 14 | #include 15 | #endif 16 | 17 | #ifdef os_ios 18 | #include 19 | #endif 20 | 21 | #ifdef os_macos 22 | #include 23 | #define GL_ES_VERSION_3_0 1 24 | #endif 25 | 26 | #if defined(GL_ES_VERSION_3_0) && GL_ES_VERSION_3_0 27 | #define GLES_VERSION "GL_ES_3_0" 28 | #else 29 | #define GLES_VERSION "GL_ES_2_0" 30 | #endif 31 | 32 | #include 33 | #include 34 | 35 | // TODO: generate this enum from fn.go. 36 | typedef enum { 37 | glfnUNDEFINED, 38 | 39 | glfnActiveTexture, 40 | glfnAttachShader, 41 | glfnBindAttribLocation, 42 | glfnBindBuffer, 43 | glfnBindFramebuffer, 44 | glfnBindRenderbuffer, 45 | glfnBindTexture, 46 | glfnBindVertexArray, 47 | glfnBlendColor, 48 | glfnBlendEquation, 49 | glfnBlendEquationSeparate, 50 | glfnBlendFunc, 51 | glfnBlendFuncSeparate, 52 | glfnBufferData, 53 | glfnBufferSubData, 54 | glfnCheckFramebufferStatus, 55 | glfnClear, 56 | glfnClearColor, 57 | glfnClearDepthf, 58 | glfnClearStencil, 59 | glfnColorMask, 60 | glfnCompileShader, 61 | glfnCompressedTexImage2D, 62 | glfnCompressedTexSubImage2D, 63 | glfnCopyTexImage2D, 64 | glfnCopyTexSubImage2D, 65 | glfnCreateProgram, 66 | glfnCreateShader, 67 | glfnCullFace, 68 | glfnDeleteBuffer, 69 | glfnDeleteFramebuffer, 70 | glfnDeleteProgram, 71 | glfnDeleteRenderbuffer, 72 | glfnDeleteShader, 73 | glfnDeleteTexture, 74 | glfnDeleteVertexArray, 75 | glfnDepthFunc, 76 | glfnDepthRangef, 77 | glfnDepthMask, 78 | glfnDetachShader, 79 | glfnDisable, 80 | glfnDisableVertexAttribArray, 81 | glfnDrawArrays, 82 | glfnDrawElements, 83 | glfnEnable, 84 | glfnEnableVertexAttribArray, 85 | glfnFinish, 86 | glfnFlush, 87 | glfnFramebufferRenderbuffer, 88 | glfnFramebufferTexture2D, 89 | glfnFrontFace, 90 | glfnGenBuffer, 91 | glfnGenFramebuffer, 92 | glfnGenRenderbuffer, 93 | glfnGenTexture, 94 | glfnGenVertexArray, 95 | glfnGenerateMipmap, 96 | glfnGetActiveAttrib, 97 | glfnGetActiveUniform, 98 | glfnGetAttachedShaders, 99 | glfnGetAttribLocation, 100 | glfnGetBooleanv, 101 | glfnGetBufferParameteri, 102 | glfnGetError, 103 | glfnGetFloatv, 104 | glfnGetFramebufferAttachmentParameteriv, 105 | glfnGetIntegerv, 106 | glfnGetProgramInfoLog, 107 | glfnGetProgramiv, 108 | glfnGetRenderbufferParameteriv, 109 | glfnGetShaderInfoLog, 110 | glfnGetShaderPrecisionFormat, 111 | glfnGetShaderSource, 112 | glfnGetShaderiv, 113 | glfnGetString, 114 | glfnGetTexParameterfv, 115 | glfnGetTexParameteriv, 116 | glfnGetUniformLocation, 117 | glfnGetUniformfv, 118 | glfnGetUniformiv, 119 | glfnGetVertexAttribfv, 120 | glfnGetVertexAttribiv, 121 | glfnHint, 122 | glfnIsBuffer, 123 | glfnIsEnabled, 124 | glfnIsFramebuffer, 125 | glfnIsProgram, 126 | glfnIsRenderbuffer, 127 | glfnIsShader, 128 | glfnIsTexture, 129 | glfnLineWidth, 130 | glfnLinkProgram, 131 | glfnPixelStorei, 132 | glfnPolygonOffset, 133 | glfnReadPixels, 134 | glfnReleaseShaderCompiler, 135 | glfnRenderbufferStorage, 136 | glfnSampleCoverage, 137 | glfnScissor, 138 | glfnShaderSource, 139 | glfnStencilFunc, 140 | glfnStencilFuncSeparate, 141 | glfnStencilMask, 142 | glfnStencilMaskSeparate, 143 | glfnStencilOp, 144 | glfnStencilOpSeparate, 145 | glfnTexImage2D, 146 | glfnTexParameterf, 147 | glfnTexParameterfv, 148 | glfnTexParameteri, 149 | glfnTexParameteriv, 150 | glfnTexSubImage2D, 151 | glfnUniform1f, 152 | glfnUniform1fv, 153 | glfnUniform1i, 154 | glfnUniform1iv, 155 | glfnUniform2f, 156 | glfnUniform2fv, 157 | glfnUniform2i, 158 | glfnUniform2iv, 159 | glfnUniform3f, 160 | glfnUniform3fv, 161 | glfnUniform3i, 162 | glfnUniform3iv, 163 | glfnUniform4f, 164 | glfnUniform4fv, 165 | glfnUniform4i, 166 | glfnUniform4iv, 167 | glfnUniformMatrix2fv, 168 | glfnUniformMatrix3fv, 169 | glfnUniformMatrix4fv, 170 | glfnUseProgram, 171 | glfnValidateProgram, 172 | glfnVertexAttrib1f, 173 | glfnVertexAttrib1fv, 174 | glfnVertexAttrib2f, 175 | glfnVertexAttrib2fv, 176 | glfnVertexAttrib3f, 177 | glfnVertexAttrib3fv, 178 | glfnVertexAttrib4f, 179 | glfnVertexAttrib4fv, 180 | glfnVertexAttribPointer, 181 | glfnViewport, 182 | 183 | // ES 3.0 functions 184 | glfnUniformMatrix2x3fv, 185 | glfnUniformMatrix3x2fv, 186 | glfnUniformMatrix2x4fv, 187 | glfnUniformMatrix4x2fv, 188 | glfnUniformMatrix3x4fv, 189 | glfnUniformMatrix4x3fv, 190 | glfnBlitFramebuffer, 191 | glfnUniform1ui, 192 | glfnUniform2ui, 193 | glfnUniform3ui, 194 | glfnUniform4ui, 195 | glfnUniform1uiv, 196 | glfnUniform2uiv, 197 | glfnUniform3uiv, 198 | glfnUniform4uiv, 199 | } glfn; 200 | 201 | // TODO: generate this type from fn.go. 202 | struct fnargs { 203 | glfn fn; 204 | 205 | uintptr_t a0; 206 | uintptr_t a1; 207 | uintptr_t a2; 208 | uintptr_t a3; 209 | uintptr_t a4; 210 | uintptr_t a5; 211 | uintptr_t a6; 212 | uintptr_t a7; 213 | uintptr_t a8; 214 | uintptr_t a9; 215 | }; 216 | 217 | extern uintptr_t processFn(struct fnargs* args, char* parg); 218 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/gl/work_other.go: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build (!cgo || (!darwin && !linux && !openbsd)) && !windows 6 | // +build !cgo !darwin,!linux,!openbsd 7 | // +build !windows 8 | 9 | package gl 10 | 11 | // This file contains stub implementations of what the other work*.go files 12 | // provide. These stubs don't do anything, other than compile (e.g. when cgo is 13 | // disabled). 14 | 15 | type context struct{} 16 | 17 | func (*context) enqueue(c call) uintptr { 18 | panic("unimplemented; GOOS/CGO combination not supported") 19 | } 20 | 21 | func (*context) cString(str string) (uintptr, func()) { 22 | panic("unimplemented; GOOS/CGO combination not supported") 23 | } 24 | 25 | func (*context) cStringPtr(str string) (uintptr, func()) { 26 | panic("unimplemented; GOOS/CGO combination not supported") 27 | } 28 | 29 | type context3 = context 30 | 31 | func NewContext() (Context, Worker) { 32 | panic("unimplemented; GOOS/CGO combination not supported") 33 | } 34 | 35 | func Version() string { 36 | panic("unimplemented; GOOS/CGO combination not supported") 37 | } 38 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/gl/work_windows_386.s: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | 7 | // fixFloat is unnecessary for windows/386 8 | TEXT ·fixFloat(SB),NOSPLIT,$0-16 9 | RET 10 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/gl/work_windows_amd64.s: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | #include "textflag.h" 6 | 7 | TEXT ·fixFloat(SB),NOSPLIT,$0-32 8 | MOVQ x0+0(FP), X0 9 | MOVQ x1+8(FP), X1 10 | MOVQ x2+16(FP), X2 11 | MOVQ x3+24(FP), X3 12 | RET 13 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/internal/mobileinit/ctx_android.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mobileinit 6 | 7 | /* 8 | #include 9 | #include 10 | 11 | static char* lockJNI(JavaVM *vm, uintptr_t* envp, int* attachedp) { 12 | JNIEnv* env; 13 | 14 | if (vm == NULL) { 15 | return "no current JVM"; 16 | } 17 | 18 | *attachedp = 0; 19 | switch ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6)) { 20 | case JNI_OK: 21 | break; 22 | case JNI_EDETACHED: 23 | if ((*vm)->AttachCurrentThread(vm, &env, 0) != 0) { 24 | return "cannot attach to JVM"; 25 | } 26 | *attachedp = 1; 27 | break; 28 | case JNI_EVERSION: 29 | return "bad JNI version"; 30 | default: 31 | return "unknown JNI error from GetEnv"; 32 | } 33 | 34 | *envp = (uintptr_t)env; 35 | return NULL; 36 | } 37 | 38 | static char* checkException(uintptr_t jnienv) { 39 | jthrowable exc; 40 | JNIEnv* env = (JNIEnv*)jnienv; 41 | 42 | if (!(*env)->ExceptionCheck(env)) { 43 | return NULL; 44 | } 45 | 46 | exc = (*env)->ExceptionOccurred(env); 47 | (*env)->ExceptionClear(env); 48 | 49 | jclass clazz = (*env)->FindClass(env, "java/lang/Throwable"); 50 | jmethodID toString = (*env)->GetMethodID(env, clazz, "toString", "()Ljava/lang/String;"); 51 | jobject msgStr = (*env)->CallObjectMethod(env, exc, toString); 52 | return (char*)(*env)->GetStringUTFChars(env, msgStr, 0); 53 | } 54 | 55 | static void unlockJNI(JavaVM *vm) { 56 | (*vm)->DetachCurrentThread(vm); 57 | } 58 | */ 59 | import "C" 60 | 61 | import ( 62 | "errors" 63 | "runtime" 64 | "unsafe" 65 | ) 66 | 67 | // currentVM is stored to initialize other cgo packages. 68 | // 69 | // As all the Go packages in a program form a single shared library, 70 | // there can only be one JNI_OnLoad function for initialization. In 71 | // OpenJDK there is JNI_GetCreatedJavaVMs, but this is not available 72 | // on android. 73 | var currentVM *C.JavaVM 74 | 75 | // currentCtx is Android's android.context.Context. May be NULL. 76 | var currentCtx C.jobject 77 | 78 | // SetCurrentContext populates the global Context object with the specified 79 | // current JavaVM instance (vm) and android.context.Context object (ctx). 80 | // The android.context.Context object must be a global reference. 81 | func SetCurrentContext(vm unsafe.Pointer, ctx uintptr) { 82 | currentVM = (*C.JavaVM)(vm) 83 | currentCtx = (C.jobject)(ctx) 84 | } 85 | 86 | // RunOnJVM runs fn on a new goroutine locked to an OS thread with a JNIEnv. 87 | // 88 | // RunOnJVM blocks until the call to fn is complete. Any Java 89 | // exception or failure to attach to the JVM is returned as an error. 90 | // 91 | // The function fn takes vm, the current JavaVM*, 92 | // env, the current JNIEnv*, and 93 | // ctx, a jobject representing the global android.context.Context. 94 | func RunOnJVM(fn func(vm, env, ctx uintptr) error) error { 95 | errch := make(chan error) 96 | go func() { 97 | runtime.LockOSThread() 98 | defer runtime.UnlockOSThread() 99 | 100 | env := C.uintptr_t(0) 101 | attached := C.int(0) 102 | if errStr := C.lockJNI(currentVM, &env, &attached); errStr != nil { 103 | errch <- errors.New(C.GoString(errStr)) 104 | return 105 | } 106 | if attached != 0 { 107 | defer C.unlockJNI(currentVM) 108 | } 109 | 110 | vm := uintptr(unsafe.Pointer(currentVM)) 111 | if err := fn(vm, uintptr(env), uintptr(currentCtx)); err != nil { 112 | errch <- err 113 | return 114 | } 115 | 116 | if exc := C.checkException(env); exc != nil { 117 | errch <- errors.New(C.GoString(exc)) 118 | C.free(unsafe.Pointer(exc)) 119 | return 120 | } 121 | errch <- nil 122 | }() 123 | return <-errch 124 | } 125 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/internal/mobileinit/mobileinit.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package mobileinit contains common initialization logic for mobile platforms 6 | // that is relevant to both all-Go apps and gobind-based apps. 7 | // 8 | // Long-term, some code in this package should consider moving into Go stdlib. 9 | package mobileinit 10 | 11 | import "C" 12 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/internal/mobileinit/mobileinit_android.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mobileinit 6 | 7 | /* 8 | To view the log output run: 9 | adb logcat GoLog:I *:S 10 | */ 11 | 12 | // Android redirects stdout and stderr to /dev/null. 13 | // As these are common debugging utilities in Go, 14 | // we redirect them to logcat. 15 | // 16 | // Unfortunately, logcat is line oriented, so we must buffer. 17 | 18 | /* 19 | #cgo LDFLAGS: -landroid -llog 20 | 21 | #include 22 | #include 23 | #include 24 | */ 25 | import "C" 26 | 27 | import ( 28 | "bufio" 29 | "log" 30 | "os" 31 | "syscall" 32 | "unsafe" 33 | ) 34 | 35 | var ( 36 | ctag = C.CString("GoLog") 37 | // Store the writer end of the redirected stderr and stdout 38 | // so that they are not garbage collected and closed. 39 | stderr, stdout *os.File 40 | ) 41 | 42 | type infoWriter struct{} 43 | 44 | func (infoWriter) Write(p []byte) (n int, err error) { 45 | cstr := C.CString(string(p)) 46 | C.__android_log_write(C.ANDROID_LOG_INFO, ctag, cstr) 47 | C.free(unsafe.Pointer(cstr)) 48 | return len(p), nil 49 | } 50 | 51 | func lineLog(f *os.File, priority C.int) { 52 | const logSize = 1024 // matches android/log.h. 53 | r := bufio.NewReaderSize(f, logSize) 54 | for { 55 | line, _, err := r.ReadLine() 56 | str := string(line) 57 | if err != nil { 58 | str += " " + err.Error() 59 | } 60 | cstr := C.CString(str) 61 | C.__android_log_write(priority, ctag, cstr) 62 | C.free(unsafe.Pointer(cstr)) 63 | if err != nil { 64 | break 65 | } 66 | } 67 | } 68 | 69 | func init() { 70 | log.SetOutput(infoWriter{}) 71 | // android logcat includes all of log.LstdFlags 72 | log.SetFlags(log.Flags() &^ log.LstdFlags) 73 | 74 | r, w, err := os.Pipe() 75 | if err != nil { 76 | panic(err) 77 | } 78 | stderr = w 79 | if err := syscall.Dup3(int(w.Fd()), int(os.Stderr.Fd()), 0); err != nil { 80 | panic(err) 81 | } 82 | go lineLog(r, C.ANDROID_LOG_ERROR) 83 | 84 | r, w, err = os.Pipe() 85 | if err != nil { 86 | panic(err) 87 | } 88 | stdout = w 89 | if err := syscall.Dup3(int(w.Fd()), int(os.Stdout.Fd()), 0); err != nil { 90 | panic(err) 91 | } 92 | go lineLog(r, C.ANDROID_LOG_INFO) 93 | } 94 | -------------------------------------------------------------------------------- /vendor/golang.org/x/mobile/internal/mobileinit/mobileinit_ios.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package mobileinit 6 | 7 | import ( 8 | "io" 9 | "log" 10 | "os" 11 | "unsafe" 12 | ) 13 | 14 | /* 15 | #include 16 | #include 17 | 18 | os_log_t create_os_log() { 19 | return os_log_create("org.golang.mobile", "os_log"); 20 | } 21 | 22 | void os_log_wrap(os_log_t log, const char *str) { 23 | os_log(log, "%s", str); 24 | } 25 | */ 26 | import "C" 27 | 28 | type osWriter struct { 29 | w C.os_log_t 30 | } 31 | 32 | func (o osWriter) Write(p []byte) (n int, err error) { 33 | cstr := C.CString(string(p)) 34 | C.os_log_wrap(o.w, cstr) 35 | C.free(unsafe.Pointer(cstr)) 36 | return len(p), nil 37 | } 38 | 39 | func init() { 40 | log.SetOutput(io.MultiWriter(os.Stderr, osWriter{C.create_os_log()})) 41 | } 42 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/internal/unsafeheader/unsafeheader.go: -------------------------------------------------------------------------------- 1 | // Copyright 2020 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Package unsafeheader contains header declarations for the Go runtime's 6 | // slice and string implementations. 7 | // 8 | // This package allows x/sys to use types equivalent to 9 | // reflect.SliceHeader and reflect.StringHeader without introducing 10 | // a dependency on the (relatively heavy) "reflect" package. 11 | package unsafeheader 12 | 13 | import ( 14 | "unsafe" 15 | ) 16 | 17 | // Slice is the runtime representation of a slice. 18 | // It cannot be used safely or portably and its representation may change in a later release. 19 | type Slice struct { 20 | Data unsafe.Pointer 21 | Len int 22 | Cap int 23 | } 24 | 25 | // String is the runtime representation of a string. 26 | // It cannot be used safely or portably and its representation may change in a later release. 27 | type String struct { 28 | Data unsafe.Pointer 29 | Len int 30 | } 31 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/aliases.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build windows && go1.9 6 | // +build windows,go1.9 7 | 8 | package windows 9 | 10 | import "syscall" 11 | 12 | type Errno = syscall.Errno 13 | type SysProcAttr = syscall.SysProcAttr 14 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/empty.s: -------------------------------------------------------------------------------- 1 | // Copyright 2019 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build !go1.12 6 | // +build !go1.12 7 | 8 | // This file is here to allow bodyless functions with go:linkname for Go 1.11 9 | // and earlier (see https://golang.org/issue/23311). 10 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/env_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2010 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Windows environment variables. 6 | 7 | package windows 8 | 9 | import ( 10 | "syscall" 11 | "unsafe" 12 | ) 13 | 14 | func Getenv(key string) (value string, found bool) { 15 | return syscall.Getenv(key) 16 | } 17 | 18 | func Setenv(key, value string) error { 19 | return syscall.Setenv(key, value) 20 | } 21 | 22 | func Clearenv() { 23 | syscall.Clearenv() 24 | } 25 | 26 | func Environ() []string { 27 | return syscall.Environ() 28 | } 29 | 30 | // Returns a default environment associated with the token, rather than the current 31 | // process. If inheritExisting is true, then this environment also inherits the 32 | // environment of the current process. 33 | func (token Token) Environ(inheritExisting bool) (env []string, err error) { 34 | var block *uint16 35 | err = CreateEnvironmentBlock(&block, token, inheritExisting) 36 | if err != nil { 37 | return nil, err 38 | } 39 | defer DestroyEnvironmentBlock(block) 40 | blockp := uintptr(unsafe.Pointer(block)) 41 | for { 42 | entry := UTF16PtrToString((*uint16)(unsafe.Pointer(blockp))) 43 | if len(entry) == 0 { 44 | break 45 | } 46 | env = append(env, entry) 47 | blockp += 2 * (uintptr(len(entry)) + 1) 48 | } 49 | return env, nil 50 | } 51 | 52 | func Unsetenv(key string) error { 53 | return syscall.Unsetenv(key) 54 | } 55 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/eventlog.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build windows 6 | // +build windows 7 | 8 | package windows 9 | 10 | const ( 11 | EVENTLOG_SUCCESS = 0 12 | EVENTLOG_ERROR_TYPE = 1 13 | EVENTLOG_WARNING_TYPE = 2 14 | EVENTLOG_INFORMATION_TYPE = 4 15 | EVENTLOG_AUDIT_SUCCESS = 8 16 | EVENTLOG_AUDIT_FAILURE = 16 17 | ) 18 | 19 | //sys RegisterEventSource(uncServerName *uint16, sourceName *uint16) (handle Handle, err error) [failretval==0] = advapi32.RegisterEventSourceW 20 | //sys DeregisterEventSource(handle Handle) (err error) = advapi32.DeregisterEventSource 21 | //sys ReportEvent(log Handle, etype uint16, category uint16, eventId uint32, usrSId uintptr, numStrings uint16, dataSize uint32, strings **uint16, rawData *byte) (err error) = advapi32.ReportEventW 22 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/exec_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Fork, exec, wait, etc. 6 | 7 | package windows 8 | 9 | import ( 10 | errorspkg "errors" 11 | "unsafe" 12 | ) 13 | 14 | // EscapeArg rewrites command line argument s as prescribed 15 | // in http://msdn.microsoft.com/en-us/library/ms880421. 16 | // This function returns "" (2 double quotes) if s is empty. 17 | // Alternatively, these transformations are done: 18 | // - every back slash (\) is doubled, but only if immediately 19 | // followed by double quote ("); 20 | // - every double quote (") is escaped by back slash (\); 21 | // - finally, s is wrapped with double quotes (arg -> "arg"), 22 | // but only if there is space or tab inside s. 23 | func EscapeArg(s string) string { 24 | if len(s) == 0 { 25 | return "\"\"" 26 | } 27 | n := len(s) 28 | hasSpace := false 29 | for i := 0; i < len(s); i++ { 30 | switch s[i] { 31 | case '"', '\\': 32 | n++ 33 | case ' ', '\t': 34 | hasSpace = true 35 | } 36 | } 37 | if hasSpace { 38 | n += 2 39 | } 40 | if n == len(s) { 41 | return s 42 | } 43 | 44 | qs := make([]byte, n) 45 | j := 0 46 | if hasSpace { 47 | qs[j] = '"' 48 | j++ 49 | } 50 | slashes := 0 51 | for i := 0; i < len(s); i++ { 52 | switch s[i] { 53 | default: 54 | slashes = 0 55 | qs[j] = s[i] 56 | case '\\': 57 | slashes++ 58 | qs[j] = s[i] 59 | case '"': 60 | for ; slashes > 0; slashes-- { 61 | qs[j] = '\\' 62 | j++ 63 | } 64 | qs[j] = '\\' 65 | j++ 66 | qs[j] = s[i] 67 | } 68 | j++ 69 | } 70 | if hasSpace { 71 | for ; slashes > 0; slashes-- { 72 | qs[j] = '\\' 73 | j++ 74 | } 75 | qs[j] = '"' 76 | j++ 77 | } 78 | return string(qs[:j]) 79 | } 80 | 81 | // ComposeCommandLine escapes and joins the given arguments suitable for use as a Windows command line, 82 | // in CreateProcess's CommandLine argument, CreateService/ChangeServiceConfig's BinaryPathName argument, 83 | // or any program that uses CommandLineToArgv. 84 | func ComposeCommandLine(args []string) string { 85 | var commandLine string 86 | for i := range args { 87 | if i > 0 { 88 | commandLine += " " 89 | } 90 | commandLine += EscapeArg(args[i]) 91 | } 92 | return commandLine 93 | } 94 | 95 | // DecomposeCommandLine breaks apart its argument command line into unescaped parts using CommandLineToArgv, 96 | // as gathered from GetCommandLine, QUERY_SERVICE_CONFIG's BinaryPathName argument, or elsewhere that 97 | // command lines are passed around. 98 | func DecomposeCommandLine(commandLine string) ([]string, error) { 99 | if len(commandLine) == 0 { 100 | return []string{}, nil 101 | } 102 | var argc int32 103 | argv, err := CommandLineToArgv(StringToUTF16Ptr(commandLine), &argc) 104 | if err != nil { 105 | return nil, err 106 | } 107 | defer LocalFree(Handle(unsafe.Pointer(argv))) 108 | var args []string 109 | for _, v := range (*argv)[:argc] { 110 | args = append(args, UTF16ToString((*v)[:])) 111 | } 112 | return args, nil 113 | } 114 | 115 | func CloseOnExec(fd Handle) { 116 | SetHandleInformation(Handle(fd), HANDLE_FLAG_INHERIT, 0) 117 | } 118 | 119 | // FullPath retrieves the full path of the specified file. 120 | func FullPath(name string) (path string, err error) { 121 | p, err := UTF16PtrFromString(name) 122 | if err != nil { 123 | return "", err 124 | } 125 | n := uint32(100) 126 | for { 127 | buf := make([]uint16, n) 128 | n, err = GetFullPathName(p, uint32(len(buf)), &buf[0], nil) 129 | if err != nil { 130 | return "", err 131 | } 132 | if n <= uint32(len(buf)) { 133 | return UTF16ToString(buf[:n]), nil 134 | } 135 | } 136 | } 137 | 138 | // NewProcThreadAttributeList allocates a new ProcThreadAttributeListContainer, with the requested maximum number of attributes. 139 | func NewProcThreadAttributeList(maxAttrCount uint32) (*ProcThreadAttributeListContainer, error) { 140 | var size uintptr 141 | err := initializeProcThreadAttributeList(nil, maxAttrCount, 0, &size) 142 | if err != ERROR_INSUFFICIENT_BUFFER { 143 | if err == nil { 144 | return nil, errorspkg.New("unable to query buffer size from InitializeProcThreadAttributeList") 145 | } 146 | return nil, err 147 | } 148 | alloc, err := LocalAlloc(LMEM_FIXED, uint32(size)) 149 | if err != nil { 150 | return nil, err 151 | } 152 | // size is guaranteed to be ≥1 by InitializeProcThreadAttributeList. 153 | al := &ProcThreadAttributeListContainer{data: (*ProcThreadAttributeList)(unsafe.Pointer(alloc))} 154 | err = initializeProcThreadAttributeList(al.data, maxAttrCount, 0, &size) 155 | if err != nil { 156 | return nil, err 157 | } 158 | return al, err 159 | } 160 | 161 | // Update modifies the ProcThreadAttributeList using UpdateProcThreadAttribute. 162 | func (al *ProcThreadAttributeListContainer) Update(attribute uintptr, value unsafe.Pointer, size uintptr) error { 163 | al.pointers = append(al.pointers, value) 164 | return updateProcThreadAttribute(al.data, 0, attribute, value, size, nil, nil) 165 | } 166 | 167 | // Delete frees ProcThreadAttributeList's resources. 168 | func (al *ProcThreadAttributeListContainer) Delete() { 169 | deleteProcThreadAttributeList(al.data) 170 | LocalFree(Handle(unsafe.Pointer(al.data))) 171 | al.data = nil 172 | al.pointers = nil 173 | } 174 | 175 | // List returns the actual ProcThreadAttributeList to be passed to StartupInfoEx. 176 | func (al *ProcThreadAttributeListContainer) List() *ProcThreadAttributeList { 177 | return al.data 178 | } 179 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/memory_windows.go: -------------------------------------------------------------------------------- 1 | // Copyright 2017 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package windows 6 | 7 | const ( 8 | MEM_COMMIT = 0x00001000 9 | MEM_RESERVE = 0x00002000 10 | MEM_DECOMMIT = 0x00004000 11 | MEM_RELEASE = 0x00008000 12 | MEM_RESET = 0x00080000 13 | MEM_TOP_DOWN = 0x00100000 14 | MEM_WRITE_WATCH = 0x00200000 15 | MEM_PHYSICAL = 0x00400000 16 | MEM_RESET_UNDO = 0x01000000 17 | MEM_LARGE_PAGES = 0x20000000 18 | 19 | PAGE_NOACCESS = 0x00000001 20 | PAGE_READONLY = 0x00000002 21 | PAGE_READWRITE = 0x00000004 22 | PAGE_WRITECOPY = 0x00000008 23 | PAGE_EXECUTE = 0x00000010 24 | PAGE_EXECUTE_READ = 0x00000020 25 | PAGE_EXECUTE_READWRITE = 0x00000040 26 | PAGE_EXECUTE_WRITECOPY = 0x00000080 27 | PAGE_GUARD = 0x00000100 28 | PAGE_NOCACHE = 0x00000200 29 | PAGE_WRITECOMBINE = 0x00000400 30 | PAGE_TARGETS_INVALID = 0x40000000 31 | PAGE_TARGETS_NO_UPDATE = 0x40000000 32 | 33 | QUOTA_LIMITS_HARDWS_MIN_DISABLE = 0x00000002 34 | QUOTA_LIMITS_HARDWS_MIN_ENABLE = 0x00000001 35 | QUOTA_LIMITS_HARDWS_MAX_DISABLE = 0x00000008 36 | QUOTA_LIMITS_HARDWS_MAX_ENABLE = 0x00000004 37 | ) 38 | 39 | type MemoryBasicInformation struct { 40 | BaseAddress uintptr 41 | AllocationBase uintptr 42 | AllocationProtect uint32 43 | PartitionId uint16 44 | RegionSize uintptr 45 | State uint32 46 | Protect uint32 47 | Type uint32 48 | } 49 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/mkerrors.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019 The Go Authors. All rights reserved. 4 | # Use of this source code is governed by a BSD-style 5 | # license that can be found in the LICENSE file. 6 | 7 | set -e 8 | shopt -s nullglob 9 | 10 | winerror="$(printf '%s\n' "/mnt/c/Program Files (x86)/Windows Kits/"/*/Include/*/shared/winerror.h | sort -Vr | head -n 1)" 11 | [[ -n $winerror ]] || { echo "Unable to find winerror.h" >&2; exit 1; } 12 | ntstatus="$(printf '%s\n' "/mnt/c/Program Files (x86)/Windows Kits/"/*/Include/*/shared/ntstatus.h | sort -Vr | head -n 1)" 13 | [[ -n $ntstatus ]] || { echo "Unable to find ntstatus.h" >&2; exit 1; } 14 | 15 | declare -A errors 16 | 17 | { 18 | echo "// Code generated by 'mkerrors.bash'; DO NOT EDIT." 19 | echo 20 | echo "package windows" 21 | echo "import \"syscall\"" 22 | echo "const (" 23 | 24 | while read -r line; do 25 | unset vtype 26 | if [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +([A-Z0-9_]+\()?([A-Z][A-Z0-9_]+k?)\)? ]]; then 27 | key="${BASH_REMATCH[1]}" 28 | value="${BASH_REMATCH[3]}" 29 | elif [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +([A-Z0-9_]+\()?((0x)?[0-9A-Fa-f]+)L?\)? ]]; then 30 | key="${BASH_REMATCH[1]}" 31 | value="${BASH_REMATCH[3]}" 32 | vtype="${BASH_REMATCH[2]}" 33 | elif [[ $line =~ ^#define\ +([A-Z0-9_]+k?)\ +\(\(([A-Z]+)\)((0x)?[0-9A-Fa-f]+)L?\) ]]; then 34 | key="${BASH_REMATCH[1]}" 35 | value="${BASH_REMATCH[3]}" 36 | vtype="${BASH_REMATCH[2]}" 37 | else 38 | continue 39 | fi 40 | [[ -n $key && -n $value ]] || continue 41 | [[ -z ${errors["$key"]} ]] || continue 42 | errors["$key"]="$value" 43 | if [[ -v vtype ]]; then 44 | if [[ $key == FACILITY_* || $key == NO_ERROR ]]; then 45 | vtype="" 46 | elif [[ $vtype == *HANDLE* || $vtype == *HRESULT* ]]; then 47 | vtype="Handle" 48 | else 49 | vtype="syscall.Errno" 50 | fi 51 | last_vtype="$vtype" 52 | else 53 | vtype="" 54 | if [[ $last_vtype == Handle && $value == NO_ERROR ]]; then 55 | value="S_OK" 56 | elif [[ $last_vtype == syscall.Errno && $value == NO_ERROR ]]; then 57 | value="ERROR_SUCCESS" 58 | fi 59 | fi 60 | 61 | echo "$key $vtype = $value" 62 | done < "$winerror" 63 | 64 | while read -r line; do 65 | [[ $line =~ ^#define\ (STATUS_[^\s]+)\ +\(\(NTSTATUS\)((0x)?[0-9a-fA-F]+)L?\) ]] || continue 66 | echo "${BASH_REMATCH[1]} NTStatus = ${BASH_REMATCH[2]}" 67 | done < "$ntstatus" 68 | 69 | echo ")" 70 | } | gofmt > "zerrors_windows.go" 71 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/mkknownfolderids.bash: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Copyright 2019 The Go Authors. All rights reserved. 4 | # Use of this source code is governed by a BSD-style 5 | # license that can be found in the LICENSE file. 6 | 7 | set -e 8 | shopt -s nullglob 9 | 10 | knownfolders="$(printf '%s\n' "/mnt/c/Program Files (x86)/Windows Kits/"/*/Include/*/um/KnownFolders.h | sort -Vr | head -n 1)" 11 | [[ -n $knownfolders ]] || { echo "Unable to find KnownFolders.h" >&2; exit 1; } 12 | 13 | { 14 | echo "// Code generated by 'mkknownfolderids.bash'; DO NOT EDIT." 15 | echo 16 | echo "package windows" 17 | echo "type KNOWNFOLDERID GUID" 18 | echo "var (" 19 | while read -r line; do 20 | [[ $line =~ DEFINE_KNOWN_FOLDER\((FOLDERID_[^,]+),[\t\ ]*(0x[^,]+),[\t\ ]*(0x[^,]+),[\t\ ]*(0x[^,]+),[\t\ ]*(0x[^,]+),[\t\ ]*(0x[^,]+),[\t\ ]*(0x[^,]+),[\t\ ]*(0x[^,]+),[\t\ ]*(0x[^,]+),[\t\ ]*(0x[^,]+),[\t\ ]*(0x[^,]+),[\t\ ]*(0x[^,]+)\) ]] || continue 21 | printf "%s = &KNOWNFOLDERID{0x%08x, 0x%04x, 0x%04x, [8]byte{0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x, 0x%02x}}\n" \ 22 | "${BASH_REMATCH[1]}" $(( "${BASH_REMATCH[2]}" )) $(( "${BASH_REMATCH[3]}" )) $(( "${BASH_REMATCH[4]}" )) \ 23 | $(( "${BASH_REMATCH[5]}" )) $(( "${BASH_REMATCH[6]}" )) $(( "${BASH_REMATCH[7]}" )) $(( "${BASH_REMATCH[8]}" )) \ 24 | $(( "${BASH_REMATCH[9]}" )) $(( "${BASH_REMATCH[10]}" )) $(( "${BASH_REMATCH[11]}" )) $(( "${BASH_REMATCH[12]}" )) 25 | done < "$knownfolders" 26 | echo ")" 27 | } | gofmt > "zknownfolderids_windows.go" 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/mksyscall.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build generate 6 | // +build generate 7 | 8 | package windows 9 | 10 | //go:generate go run golang.org/x/sys/windows/mkwinsyscall -output zsyscall_windows.go eventlog.go service.go syscall_windows.go security_windows.go setupapi_windows.go 11 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/race.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build windows && race 6 | // +build windows,race 7 | 8 | package windows 9 | 10 | import ( 11 | "runtime" 12 | "unsafe" 13 | ) 14 | 15 | const raceenabled = true 16 | 17 | func raceAcquire(addr unsafe.Pointer) { 18 | runtime.RaceAcquire(addr) 19 | } 20 | 21 | func raceReleaseMerge(addr unsafe.Pointer) { 22 | runtime.RaceReleaseMerge(addr) 23 | } 24 | 25 | func raceReadRange(addr unsafe.Pointer, len int) { 26 | runtime.RaceReadRange(addr, len) 27 | } 28 | 29 | func raceWriteRange(addr unsafe.Pointer, len int) { 30 | runtime.RaceWriteRange(addr, len) 31 | } 32 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/race0.go: -------------------------------------------------------------------------------- 1 | // Copyright 2012 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build windows && !race 6 | // +build windows,!race 7 | 8 | package windows 9 | 10 | import ( 11 | "unsafe" 12 | ) 13 | 14 | const raceenabled = false 15 | 16 | func raceAcquire(addr unsafe.Pointer) { 17 | } 18 | 19 | func raceReleaseMerge(addr unsafe.Pointer) { 20 | } 21 | 22 | func raceReadRange(addr unsafe.Pointer, len int) { 23 | } 24 | 25 | func raceWriteRange(addr unsafe.Pointer, len int) { 26 | } 27 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/str.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build windows 6 | // +build windows 7 | 8 | package windows 9 | 10 | func itoa(val int) string { // do it here rather than with fmt to avoid dependency 11 | if val < 0 { 12 | return "-" + itoa(-val) 13 | } 14 | var buf [32]byte // big enough for int64 15 | i := len(buf) - 1 16 | for val >= 10 { 17 | buf[i] = byte(val%10 + '0') 18 | i-- 19 | val /= 10 20 | } 21 | buf[i] = byte(val + '0') 22 | return string(buf[i:]) 23 | } 24 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/syscall.go: -------------------------------------------------------------------------------- 1 | // Copyright 2009 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | //go:build windows 6 | // +build windows 7 | 8 | // Package windows contains an interface to the low-level operating system 9 | // primitives. OS details vary depending on the underlying system, and 10 | // by default, godoc will display the OS-specific documentation for the current 11 | // system. If you want godoc to display syscall documentation for another 12 | // system, set $GOOS and $GOARCH to the desired system. For example, if 13 | // you want to view documentation for freebsd/arm on linux/amd64, set $GOOS 14 | // to freebsd and $GOARCH to arm. 15 | // 16 | // The primary use of this package is inside other packages that provide a more 17 | // portable interface to the system, such as "os", "time" and "net". Use 18 | // those packages rather than this one if you can. 19 | // 20 | // For details of the functions and data types in this package consult 21 | // the manuals for the appropriate operating system. 22 | // 23 | // These calls return err == nil to indicate success; otherwise 24 | // err represents an operating system error describing the failure and 25 | // holds a value of type syscall.Errno. 26 | package windows // import "golang.org/x/sys/windows" 27 | 28 | import ( 29 | "bytes" 30 | "strings" 31 | "syscall" 32 | "unsafe" 33 | ) 34 | 35 | // ByteSliceFromString returns a NUL-terminated slice of bytes 36 | // containing the text of s. If s contains a NUL byte at any 37 | // location, it returns (nil, syscall.EINVAL). 38 | func ByteSliceFromString(s string) ([]byte, error) { 39 | if strings.IndexByte(s, 0) != -1 { 40 | return nil, syscall.EINVAL 41 | } 42 | a := make([]byte, len(s)+1) 43 | copy(a, s) 44 | return a, nil 45 | } 46 | 47 | // BytePtrFromString returns a pointer to a NUL-terminated array of 48 | // bytes containing the text of s. If s contains a NUL byte at any 49 | // location, it returns (nil, syscall.EINVAL). 50 | func BytePtrFromString(s string) (*byte, error) { 51 | a, err := ByteSliceFromString(s) 52 | if err != nil { 53 | return nil, err 54 | } 55 | return &a[0], nil 56 | } 57 | 58 | // ByteSliceToString returns a string form of the text represented by the slice s, with a terminating NUL and any 59 | // bytes after the NUL removed. 60 | func ByteSliceToString(s []byte) string { 61 | if i := bytes.IndexByte(s, 0); i != -1 { 62 | s = s[:i] 63 | } 64 | return string(s) 65 | } 66 | 67 | // BytePtrToString takes a pointer to a sequence of text and returns the corresponding string. 68 | // If the pointer is nil, it returns the empty string. It assumes that the text sequence is terminated 69 | // at a zero byte; if the zero byte is not present, the program may crash. 70 | func BytePtrToString(p *byte) string { 71 | if p == nil { 72 | return "" 73 | } 74 | if *p == 0 { 75 | return "" 76 | } 77 | 78 | // Find NUL terminator. 79 | n := 0 80 | for ptr := unsafe.Pointer(p); *(*byte)(ptr) != 0; n++ { 81 | ptr = unsafe.Pointer(uintptr(ptr) + 1) 82 | } 83 | 84 | return string(unsafe.Slice(p, n)) 85 | } 86 | 87 | // Single-word zero for use when we need a valid pointer to 0 bytes. 88 | // See mksyscall.pl. 89 | var _zero uintptr 90 | 91 | func (ts *Timespec) Unix() (sec int64, nsec int64) { 92 | return int64(ts.Sec), int64(ts.Nsec) 93 | } 94 | 95 | func (tv *Timeval) Unix() (sec int64, nsec int64) { 96 | return int64(tv.Sec), int64(tv.Usec) * 1000 97 | } 98 | 99 | func (ts *Timespec) Nano() int64 { 100 | return int64(ts.Sec)*1e9 + int64(ts.Nsec) 101 | } 102 | 103 | func (tv *Timeval) Nano() int64 { 104 | return int64(tv.Sec)*1e9 + int64(tv.Usec)*1000 105 | } 106 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/types_windows_386.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package windows 6 | 7 | type WSAData struct { 8 | Version uint16 9 | HighVersion uint16 10 | Description [WSADESCRIPTION_LEN + 1]byte 11 | SystemStatus [WSASYS_STATUS_LEN + 1]byte 12 | MaxSockets uint16 13 | MaxUdpDg uint16 14 | VendorInfo *byte 15 | } 16 | 17 | type Servent struct { 18 | Name *byte 19 | Aliases **byte 20 | Port uint16 21 | Proto *byte 22 | } 23 | 24 | type JOBOBJECT_BASIC_LIMIT_INFORMATION struct { 25 | PerProcessUserTimeLimit int64 26 | PerJobUserTimeLimit int64 27 | LimitFlags uint32 28 | MinimumWorkingSetSize uintptr 29 | MaximumWorkingSetSize uintptr 30 | ActiveProcessLimit uint32 31 | Affinity uintptr 32 | PriorityClass uint32 33 | SchedulingClass uint32 34 | _ uint32 // pad to 8 byte boundary 35 | } 36 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/types_windows_amd64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package windows 6 | 7 | type WSAData struct { 8 | Version uint16 9 | HighVersion uint16 10 | MaxSockets uint16 11 | MaxUdpDg uint16 12 | VendorInfo *byte 13 | Description [WSADESCRIPTION_LEN + 1]byte 14 | SystemStatus [WSASYS_STATUS_LEN + 1]byte 15 | } 16 | 17 | type Servent struct { 18 | Name *byte 19 | Aliases **byte 20 | Proto *byte 21 | Port uint16 22 | } 23 | 24 | type JOBOBJECT_BASIC_LIMIT_INFORMATION struct { 25 | PerProcessUserTimeLimit int64 26 | PerJobUserTimeLimit int64 27 | LimitFlags uint32 28 | MinimumWorkingSetSize uintptr 29 | MaximumWorkingSetSize uintptr 30 | ActiveProcessLimit uint32 31 | Affinity uintptr 32 | PriorityClass uint32 33 | SchedulingClass uint32 34 | } 35 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/types_windows_arm.go: -------------------------------------------------------------------------------- 1 | // Copyright 2018 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package windows 6 | 7 | type WSAData struct { 8 | Version uint16 9 | HighVersion uint16 10 | Description [WSADESCRIPTION_LEN + 1]byte 11 | SystemStatus [WSASYS_STATUS_LEN + 1]byte 12 | MaxSockets uint16 13 | MaxUdpDg uint16 14 | VendorInfo *byte 15 | } 16 | 17 | type Servent struct { 18 | Name *byte 19 | Aliases **byte 20 | Port uint16 21 | Proto *byte 22 | } 23 | 24 | type JOBOBJECT_BASIC_LIMIT_INFORMATION struct { 25 | PerProcessUserTimeLimit int64 26 | PerJobUserTimeLimit int64 27 | LimitFlags uint32 28 | MinimumWorkingSetSize uintptr 29 | MaximumWorkingSetSize uintptr 30 | ActiveProcessLimit uint32 31 | Affinity uintptr 32 | PriorityClass uint32 33 | SchedulingClass uint32 34 | _ uint32 // pad to 8 byte boundary 35 | } 36 | -------------------------------------------------------------------------------- /vendor/golang.org/x/sys/windows/types_windows_arm64.go: -------------------------------------------------------------------------------- 1 | // Copyright 2011 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package windows 6 | 7 | type WSAData struct { 8 | Version uint16 9 | HighVersion uint16 10 | MaxSockets uint16 11 | MaxUdpDg uint16 12 | VendorInfo *byte 13 | Description [WSADESCRIPTION_LEN + 1]byte 14 | SystemStatus [WSASYS_STATUS_LEN + 1]byte 15 | } 16 | 17 | type Servent struct { 18 | Name *byte 19 | Aliases **byte 20 | Proto *byte 21 | Port uint16 22 | } 23 | 24 | type JOBOBJECT_BASIC_LIMIT_INFORMATION struct { 25 | PerProcessUserTimeLimit int64 26 | PerJobUserTimeLimit int64 27 | LimitFlags uint32 28 | MinimumWorkingSetSize uintptr 29 | MaximumWorkingSetSize uintptr 30 | ActiveProcessLimit uint32 31 | Affinity uintptr 32 | PriorityClass uint32 33 | SchedulingClass uint32 34 | } 35 | -------------------------------------------------------------------------------- /vendor/modules.txt: -------------------------------------------------------------------------------- 1 | # golang.org/x/exp v0.0.0-20190731235908-ec7cb31e5a56 2 | ## explicit; go 1.12 3 | golang.org/x/exp/shiny/driver/gldriver 4 | golang.org/x/exp/shiny/driver/internal/drawer 5 | golang.org/x/exp/shiny/driver/internal/errscreen 6 | golang.org/x/exp/shiny/driver/internal/event 7 | golang.org/x/exp/shiny/driver/internal/lifecycler 8 | golang.org/x/exp/shiny/driver/internal/win32 9 | golang.org/x/exp/shiny/driver/internal/x11key 10 | golang.org/x/exp/shiny/screen 11 | # golang.org/x/image v0.6.0 12 | ## explicit; go 1.12 13 | golang.org/x/image/bmp 14 | golang.org/x/image/font 15 | golang.org/x/image/font/basicfont 16 | golang.org/x/image/math/f64 17 | golang.org/x/image/math/fixed 18 | # golang.org/x/mobile v0.0.0-20230301163155-e0f57694e12c 19 | ## explicit; go 1.17 20 | golang.org/x/mobile/app 21 | golang.org/x/mobile/app/internal/callfn 22 | golang.org/x/mobile/event/key 23 | golang.org/x/mobile/event/lifecycle 24 | golang.org/x/mobile/event/mouse 25 | golang.org/x/mobile/event/paint 26 | golang.org/x/mobile/event/size 27 | golang.org/x/mobile/event/touch 28 | golang.org/x/mobile/exp/f32 29 | golang.org/x/mobile/exp/gl/glutil 30 | golang.org/x/mobile/geom 31 | golang.org/x/mobile/gl 32 | golang.org/x/mobile/internal/mobileinit 33 | # golang.org/x/sys v0.5.0 34 | ## explicit; go 1.17 35 | golang.org/x/sys/internal/unsafeheader 36 | golang.org/x/sys/windows 37 | --------------------------------------------------------------------------------