notedeck

One damus client to rule them all
git clone git://jb55.com/notedeck
Log | Files | Refs | README | LICENSE

commit 641c339682c03f6feea681a2710fa04029654e9c
parent a471462ca384a3e38b4ec4010936235849e1f511
Author: William Casarin <jb55@jb55.com>
Date:   Wed, 30 Nov 2022 11:57:06 -0800

get it working on all platforms again

Diffstat:
A.envrc | 1+
M.gitignore | 3+++
MCargo.lock | 820+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
MCargo.toml | 15++++++++-------
Ashell.nix | 33+++++++++++++++++++++++++++++++++
Asrc/android.rs | 366+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/app.rs | 24++++++++++++------------
Msrc/bin/main.rs | 38+++++++++++++++++++++++++++++++++-----
Msrc/lib.rs | 366+------------------------------------------------------------------------------
9 files changed, 1225 insertions(+), 441 deletions(-)

diff --git a/.envrc b/.envrc @@ -0,0 +1 @@ +use nix diff --git a/.gitignore b/.gitignore @@ -2,3 +2,6 @@ .buildcmd /target /dist +.direnv/ +*.patch +*.txt diff --git a/Cargo.lock b/Cargo.lock @@ -68,9 +68,9 @@ dependencies = [ "jni-sys", "libc", "log", - "ndk", + "ndk 0.7.0", "ndk-context", - "ndk-sys", + "ndk-sys 0.4.1+23.1.7779620", "num_enum", ] @@ -108,6 +108,23 @@ dependencies = [ ] [[package]] +name = "arboard" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc120354d1b5ec6d7aaf4876b602def75595937b5e15d356eb554ab5177e08bb" +dependencies = [ + "clipboard-win", + "log", + "objc", + "objc-foundation", + "objc_id", + "parking_lot", + "thiserror", + "winapi", + "x11rb", +] + +[[package]] name = "arrayref" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -257,6 +274,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" [[package]] +name = "bytes" +version = "1.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfb24e866b15a1af2a1b663f10c6b6b8f397a84aadb828f12e5b289ec23a3a3c" + +[[package]] name = "calloop" version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -279,6 +302,12 @@ dependencies = [ ] [[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + +[[package]] name = "cfg-if" version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -291,6 +320,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] +name = "cgl" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ced0551234e87afee12411d535648dd89d2e7f34c78b753395567aff3d447ff" +dependencies = [ + "libc", +] + +[[package]] name = "chrono" version = "0.4.23" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -312,6 +350,57 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fff857943da45f546682664a79488be82e69e43c1a7a2307679ab9afb3a66d2e" [[package]] +name = "clipboard-win" +version = "4.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4ab1b92798304eedc095b53942963240037c0516452cb11aeba709d420b2219" +dependencies = [ + "error-code", + "str-buf", + "winapi", +] + +[[package]] +name = "cmake" +version = "0.1.49" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db34956e100b30725f2eb215f90d4871051239535632f84fea3bc92722c66b7c" +dependencies = [ + "cc", +] + +[[package]] +name = "cocoa" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f425db7937052c684daec3bd6375c8abe2d146dca4b8b143d6db777c39138f3a" +dependencies = [ + "bitflags", + "block", + "cocoa-foundation", + "core-foundation", + "core-graphics", + "foreign-types 0.3.2", + "libc", + "objc", +] + +[[package]] +name = "cocoa-foundation" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ade49b65d560ca58c403a479bb396592b155c0185eada742ee323d1d68d6318" +dependencies = [ + "bitflags", + "block", + "core-foundation", + "core-graphics-types", + "foreign-types 0.3.2", + "libc", + "objc", +] + +[[package]] name = "codespan-reporting" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -339,6 +428,16 @@ dependencies = [ ] [[package]] +name = "combine" +version = "4.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35ed6e9d84f0b51a7f52daf1c7d71dd136fd7a3f41a8462b8cdb8c78d920fad4" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] name = "console_error_panic_hook" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -373,7 +472,7 @@ dependencies = [ "bitflags", "core-foundation", "core-graphics-types", - "foreign-types", + "foreign-types 0.3.2", "libc", ] @@ -385,7 +484,19 @@ checksum = "3a68b68b3446082644c91ac778bf50cd4104bfb002b5a6a7c44cca5a2c70788b" dependencies = [ "bitflags", "core-foundation", - "foreign-types", + "foreign-types 0.3.2", + "libc", +] + +[[package]] +name = "core-text" +version = "19.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d74ada66e07c1cefa18f8abfba765b486f250de2e4a999e5727fc0dd4b4a25" +dependencies = [ + "core-foundation", + "core-graphics", + "foreign-types 0.3.2", "libc", ] @@ -451,6 +562,29 @@ dependencies = [ ] [[package]] +name = "crossfont" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "21fd3add36ea31aba1520aa5288714dd63be506106753226d0eb387a93bc9c45" +dependencies = [ + "cocoa", + "core-foundation", + "core-foundation-sys", + "core-graphics", + "core-text", + "dwrote", + "foreign-types 0.5.0", + "freetype-rs", + "libc", + "log", + "objc", + "once_cell", + "pkg-config", + "servo-fontconfig", + "winapi", +] + +[[package]] name = "crunchy" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -534,8 +668,8 @@ dependencies = [ "android_logger", "chrono", "console_error_panic_hook", + "eframe", "egui 0.19.0", - "egui_demo_lib", "egui_extras", "egui_wgpu_backend", "egui_winit_platform", @@ -555,7 +689,42 @@ dependencies = [ "tracing-subscriber", "tracing-wasm", "wgpu", - "winit", + "winit 0.27.5 (git+https://github.com/rust-windowing/winit.git)", +] + +[[package]] +name = "darling" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a01d95850c592940db9b8194bc39f4bc0e89dee5c4265e4b1807c34a9aba453c" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.13.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835" +dependencies = [ + "darling_core", + "quote", + "syn", ] [[package]] @@ -599,6 +768,42 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" [[package]] +name = "dwrote" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "439a1c2ba5611ad3ed731280541d36d2e9c4ac5e7fb818a27b604bdc5a6aa65b" +dependencies = [ + "lazy_static", + "libc", + "serde", + "serde_derive", + "winapi", + "wio", +] + +[[package]] +name = "eframe" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0d49426c3e72a6728b0c790d22db8bf7bbcff10d83b8b6f3a01295be982302e" +dependencies = [ + "bytemuck", + "egui 0.19.0", + "egui-winit", + "egui_glow", + "getrandom", + "glow", + "glutin", + "js-sys", + "percent-encoding", + "tracing", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "winit 0.27.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] name = "egui" version = "0.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -618,19 +823,22 @@ dependencies = [ "ahash 0.8.2", "epaint 0.19.0", "nohash-hasher", + "tracing", ] [[package]] -name = "egui_demo_lib" +name = "egui-winit" version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c22edd72717f8eeeaa4fc0c8ba417d5a897781e4f164bfb19ac7ee6557bd11d" +checksum = "07ddc525334c416e11580123e147b970f738507f427c9fb1cd09ea2dd7416a3a" dependencies = [ + "arboard", "egui 0.19.0", - "egui_extras", - "enum-map", + "instant", + "smithay-clipboard", "tracing", - "unicode_names2", + "webbrowser", + "winit 0.27.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -647,6 +855,21 @@ dependencies = [ ] [[package]] +name = "egui_glow" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad77d4a00402bae9658ee64be148f4b2a0b38e4fc7874970575ca01ed1c5b75d" +dependencies = [ + "bytemuck", + "egui 0.19.0", + "glow", + "memoffset 0.6.5", + "tracing", + "wasm-bindgen", + "web-sys", +] + +[[package]] name = "egui_wgpu_backend" version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -663,7 +886,7 @@ version = "0.16.0" source = "git+https://github.com/inferrna/egui_winit_platform.git#0e135a98c3e2fb1a428caa40f4c8587978820d2e" dependencies = [ "egui 0.19.0", - "winit", + "winit 0.27.5 (git+https://github.com/rust-windowing/winit.git)", ] [[package]] @@ -701,27 +924,6 @@ dependencies = [ ] [[package]] -name = "enum-map" -version = "2.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f5a56d54c8dd9b3ad34752ed197a4eb2a6601bc010808eb097a04a58ae4c43e1" -dependencies = [ - "enum-map-derive", - "serde", -] - -[[package]] -name = "enum-map-derive" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9045e2676cd5af83c3b167d917b0a5c90a4d8e266e2683d6631b235c457fc27" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] name = "env_logger" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -770,6 +972,26 @@ dependencies = [ ] [[package]] +name = "error-code" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "64f18991e7bf11e7ffee451b5318b5c1a73c52d0d0ada6e5a3017c8c1ced6a21" +dependencies = [ + "libc", + "str-buf", +] + +[[package]] +name = "expat-sys" +version = "2.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "658f19728920138342f68408b7cf7644d90d4784353d8ebc32e7e8663dbe45fa" +dependencies = [ + "cmake", + "pkg-config", +] + +[[package]] name = "exr" version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -814,6 +1036,12 @@ dependencies = [ ] [[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] name = "fontconfig-parser" version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -840,7 +1068,28 @@ version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" dependencies = [ - "foreign-types-shared", + "foreign-types-shared 0.1.1", +] + +[[package]] +name = "foreign-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" +dependencies = [ + "foreign-types-macros", + "foreign-types-shared 0.3.1", +] + +[[package]] +name = "foreign-types-macros" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8469d0d40519bc608ec6863f1cc88f3f1deee15913f2f3b3e573d81ed38cccc" +dependencies = [ + "proc-macro2", + "quote", + "syn", ] [[package]] @@ -850,6 +1099,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] +name = "foreign-types-shared" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" + +[[package]] name = "form_urlencoded" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -859,6 +1114,28 @@ dependencies = [ ] [[package]] +name = "freetype-rs" +version = "0.26.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74eadec9d0a5c28c54bb9882e54787275152a4e36ce206b45d7451384e5bf5fb" +dependencies = [ + "bitflags", + "freetype-sys", + "libc", +] + +[[package]] +name = "freetype-sys" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37d4011c0cc628dfa766fcc195454f4b068d7afdc2adfd28861191d866e731a" +dependencies = [ + "cmake", + "libc", + "pkg-config", +] + +[[package]] name = "futures-core" version = "0.3.25" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -890,6 +1167,16 @@ dependencies = [ ] [[package]] +name = "gethostname" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1ebd34e35c46e00bb73e81363248d627782724609fe1b6396f553f68fe3862e" +dependencies = [ + "libc", + "winapi", +] + +[[package]] name = "getrandom" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -913,6 +1200,17 @@ dependencies = [ ] [[package]] +name = "gl_generator" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a95dfc23a2b4a9a2f5ab41d194f8bfda3cabec42af4e39f08c339eb2a0c124d" +dependencies = [ + "khronos_api", + "log", + "xml-rs", +] + +[[package]] name = "glow" version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -925,6 +1223,71 @@ dependencies = [ ] [[package]] +name = "glutin" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "444c9ad294fdcaf20ccf6726b78f380b5450275540c9b68ab62f49726ad1c713" +dependencies = [ + "cgl", + "cocoa", + "core-foundation", + "glutin_egl_sys", + "glutin_gles2_sys", + "glutin_glx_sys", + "glutin_wgl_sys", + "libloading", + "log", + "objc", + "once_cell", + "osmesa-sys", + "parking_lot", + "raw-window-handle 0.5.0", + "wayland-client", + "wayland-egl", + "winapi", + "winit 0.27.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "glutin_egl_sys" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "68900f84b471f31ea1d1355567eb865a2cf446294f06cef8d653ed7bcf5f013d" +dependencies = [ + "gl_generator", + "winapi", +] + +[[package]] +name = "glutin_gles2_sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8094e708b730a7c8a1954f4f8a31880af00eb8a1c5b5bf85d28a0a3c6d69103" +dependencies = [ + "gl_generator", + "objc", +] + +[[package]] +name = "glutin_glx_sys" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d93d0575865098580c5b3a423188cd959419912ea60b1e48e8b3b526f6d02468" +dependencies = [ + "gl_generator", + "x11-dl", +] + +[[package]] +name = "glutin_wgl_sys" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3da5951a1569dbab865c6f2a863efafff193a93caf05538d193e9e3816d21696" +dependencies = [ + "gl_generator", +] + +[[package]] name = "gpu-alloc" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1027,6 +1390,12 @@ dependencies = [ ] [[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] name = "idna" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1084,6 +1453,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4217ad341ebadf8d8e724e264f13e593e0648f5b3e94b3896a5df283be015ecc" [[package]] +name = "jni" +version = "0.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6df18c2e3db7e453d3c6ac5b3e9d5182664d28788126d39b91f2d1e22b017ec" +dependencies = [ + "cesu8", + "combine", + "jni-sys", + "log", + "thiserror", + "walkdir", +] + +[[package]] name = "jni-sys" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1134,6 +1517,12 @@ dependencies = [ ] [[package]] +name = "khronos_api" +version = "3.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc" + +[[package]] name = "kurbo" version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1255,7 +1644,7 @@ dependencies = [ "bitflags", "block", "core-graphics-types", - "foreign-types", + "foreign-types 0.3.2", "log", "objc", ] @@ -1284,7 +1673,7 @@ dependencies = [ "libc", "log", "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1318,13 +1707,26 @@ dependencies = [ [[package]] name = "ndk" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2032c77e030ddee34a6787a64166008da93f6a352b629261d0fee232b8742dd4" +dependencies = [ + "bitflags", + "jni-sys", + "ndk-sys 0.3.0", + "num_enum", + "thiserror", +] + +[[package]] +name = "ndk" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "451422b7e4718271c8b5b3aadf5adedba43dc76312454b387e98fae0fc951aa0" dependencies = [ "bitflags", "jni-sys", - "ndk-sys", + "ndk-sys 0.4.1+23.1.7779620", "num_enum", "raw-window-handle 0.5.0", "thiserror", @@ -1337,6 +1739,59 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" [[package]] +name = "ndk-glue" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d0c4a7b83860226e6b4183edac21851f05d5a51756e97a1144b7f5a6b63e65f" +dependencies = [ + "lazy_static", + "libc", + "log", + "ndk 0.6.0", + "ndk-context", + "ndk-macro", + "ndk-sys 0.3.0", +] + +[[package]] +name = "ndk-glue" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0434fabdd2c15e0aab768ca31d5b7b333717f03cf02037d5a0a3ff3c278ed67f" +dependencies = [ + "libc", + "log", + "ndk 0.7.0", + "ndk-context", + "ndk-macro", + "ndk-sys 0.4.1+23.1.7779620", + "once_cell", + "parking_lot", +] + +[[package]] +name = "ndk-macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0df7ac00c4672f9d5aece54ee3347520b7e20f158656c7db2e6de01902eb7a6c" +dependencies = [ + "darling", + "proc-macro-crate", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "ndk-sys" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e5a6ae77c8ee183dcbbba6150e2e6b9f3f4196a7666c02a715a95692ec1fa97" +dependencies = [ + "jni-sys", +] + +[[package]] name = "ndk-sys" version = "0.4.1+23.1.7779620" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1347,6 +1802,19 @@ dependencies = [ [[package]] name = "nix" +version = "0.22.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4916f159ed8e5de0082076562152a76b7a1f64a01fd9d1e0fea002c37624faf" +dependencies = [ + "bitflags", + "cc", + "cfg-if", + "libc", + "memoffset 0.6.5", +] + +[[package]] +name = "nix" version = "0.24.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "195cdbc1741b8134346d515b3a56a1c94b0912758009cfd53f99ea0f57b065fc" @@ -1477,6 +1945,17 @@ dependencies = [ ] [[package]] +name = "objc-foundation" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1add1b659e36c9607c7aab864a76c7a4c2760cd0cd2e120f3fb8b952c7e22bf9" +dependencies = [ + "block", + "objc", + "objc_id", +] + +[[package]] name = "objc-sys" version = "0.2.0-beta.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1512,12 +1991,30 @@ dependencies = [ ] [[package]] +name = "objc_id" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c92d4ddb4bd7b50d730c215ff871754d0da6b2178849f8a2a2ab69712d0c073b" +dependencies = [ + "objc", +] + +[[package]] name = "once_cell" version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] +name = "osmesa-sys" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88cfece6e95d2e717e0872a7f53a8684712ad13822a7979bc760b9c77ec0013b" +dependencies = [ + "shared_library", +] + +[[package]] name = "overload" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1552,7 +2049,7 @@ dependencies = [ "libc", "redox_syscall", "smallvec", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -1856,6 +2353,15 @@ dependencies = [ ] [[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] name = "scoped-tls" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1891,6 +2397,18 @@ dependencies = [ [[package]] name = "sctk-adwaita" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61270629cc6b4d77ec1907db1033d5c2e1a404c412743621981a871dc9c12339" +dependencies = [ + "crossfont", + "log", + "smithay-client-toolkit", + "tiny-skia 0.7.0", +] + +[[package]] +name = "sctk-adwaita" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6be6d8911b40c5f91332ce27d2458d57fffc0b061816bf847df23a16f9d3615f" @@ -1933,6 +2451,27 @@ dependencies = [ ] [[package]] +name = "servo-fontconfig" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7e3e22fe5fd73d04ebf0daa049d3efe3eae55369ce38ab16d07ddd9ac5c217c" +dependencies = [ + "libc", + "servo-fontconfig-sys", +] + +[[package]] +name = "servo-fontconfig-sys" +version = "5.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e36b879db9892dfa40f95da1c38a835d41634b825fbd8c4c418093d53c24b388" +dependencies = [ + "expat-sys", + "freetype-sys", + "pkg-config", +] + +[[package]] name = "sha2" version = "0.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1953,6 +2492,16 @@ dependencies = [ ] [[package]] +name = "shared_library" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a9e7e0f2bfae24d8a5b5a66c5b257a83c7412304311512a0c054cd5e619da11" +dependencies = [ + "lazy_static", + "libc", +] + +[[package]] name = "simple_logger" version = "4.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1962,7 +2511,7 @@ dependencies = [ "colored", "log", "time 0.3.17", - "windows-sys", + "windows-sys 0.42.0", ] [[package]] @@ -2015,6 +2564,16 @@ dependencies = [ ] [[package]] +name = "smithay-clipboard" +version = "0.6.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a345c870a1fae0b1b779085e81b51e614767c239e93503588e54c5b17f4b0e8" +dependencies = [ + "smithay-client-toolkit", + "wayland-client", +] + +[[package]] name = "spin" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2046,6 +2605,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] +name = "str-buf" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e08d8363704e6c71fc928674353e6b7c23dcea9d82d7012c8faf2a3a025f8d0" + +[[package]] +name = "strsim" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" + +[[package]] name = "svgfilters" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2387,12 +2958,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f962df74c8c05a667b5ee8bcf162993134c104e96440b663c8daa176dc772d8c" [[package]] -name = "unicode_names2" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "029df4cc8238cefc911704ff8fa210853a0f3bce2694d8f51181dd41ee0f3301" - -[[package]] name = "untrusted" version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2472,6 +3037,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] +name = "walkdir" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "808cf2735cd4b6866113f648b791c6adc5714537bc222d9347bb203386ffda56" +dependencies = [ + "same-file", + "winapi", + "winapi-util", +] + +[[package]] name = "wasi" version = "0.10.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2589,6 +3165,16 @@ dependencies = [ ] [[package]] +name = "wayland-egl" +version = "0.29.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "402de949f81a012926d821a2d659f930694257e76dd92b6e0042ceb27be4107d" +dependencies = [ + "wayland-client", + "wayland-sys", +] + +[[package]] name = "wayland-protocols" version = "0.29.5" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2633,6 +3219,20 @@ dependencies = [ ] [[package]] +name = "webbrowser" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc6a3cffdb686fbb24d9fb8f03a213803277ed2300f11026a3afe1f108dc021b" +dependencies = [ + "jni", + "ndk-glue 0.6.2", + "url", + "web-sys", + "widestring", + "winapi", +] + +[[package]] name = "webpki" version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2717,7 +3317,7 @@ dependencies = [ "block", "core-graphics-types", "d3d12", - "foreign-types", + "foreign-types 0.3.2", "fxhash", "glow", "gpu-alloc", @@ -2752,6 +3352,12 @@ dependencies = [ ] [[package]] +name = "widestring" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "17882f045410753661207383517a6f62ec3dbeb6a4ed2acce01f0728238d1983" + +[[package]] name = "winapi" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2777,6 +3383,15 @@ dependencies = [ ] [[package]] +name = "winapi-wsapoll" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44c17110f57155602a80dca10be03852116403c9ff3cd25b079d666f2aa3df6e" +dependencies = [ + "winapi", +] + +[[package]] name = "winapi-x86_64-pc-windows-gnu" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2784,17 +3399,30 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] name = "windows-sys" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2" +dependencies = [ + "windows_aarch64_msvc 0.36.1", + "windows_i686_gnu 0.36.1", + "windows_i686_msvc 0.36.1", + "windows_x86_64_gnu 0.36.1", + "windows_x86_64_msvc 0.36.1", +] + +[[package]] +name = "windows-sys" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" dependencies = [ "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_msvc", - "windows_x86_64_gnu", + "windows_aarch64_msvc 0.42.0", + "windows_i686_gnu 0.42.0", + "windows_i686_msvc 0.42.0", + "windows_x86_64_gnu 0.42.0", "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_x86_64_msvc 0.42.0", ] [[package]] @@ -2805,24 +3433,48 @@ checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e" [[package]] name = "windows_aarch64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47" + +[[package]] +name = "windows_aarch64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4" [[package]] name = "windows_i686_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6" + +[[package]] +name = "windows_i686_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7" [[package]] name = "windows_i686_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024" + +[[package]] +name = "windows_i686_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246" [[package]] name = "windows_x86_64_gnu" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1" + +[[package]] +name = "windows_x86_64_gnu" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed" @@ -2835,6 +3487,12 @@ checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028" [[package]] name = "windows_x86_64_msvc" +version = "0.36.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680" + +[[package]] +name = "windows_x86_64_msvc" version = "0.42.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" @@ -2842,6 +3500,39 @@ checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" [[package]] name = "winit" version = "0.27.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb796d6fbd86b2fd896c9471e6f04d39d750076ebe5680a3958f00f5ab97657c" +dependencies = [ + "bitflags", + "cocoa", + "core-foundation", + "core-graphics", + "dispatch", + "instant", + "libc", + "log", + "mio", + "ndk 0.7.0", + "ndk-glue 0.7.0", + "objc", + "once_cell", + "parking_lot", + "percent-encoding", + "raw-window-handle 0.4.3", + "raw-window-handle 0.5.0", + "sctk-adwaita 0.4.3", + "smithay-client-toolkit", + "wasm-bindgen", + "wayland-client", + "wayland-protocols", + "web-sys", + "windows-sys 0.36.1", + "x11-dl", +] + +[[package]] +name = "winit" +version = "0.27.5" source = "git+https://github.com/rust-windowing/winit.git#2a58b785fed2a3746f7c7eebce95bce67ddfd27c" dependencies = [ "android-activity", @@ -2853,23 +3544,32 @@ dependencies = [ "libc", "log", "mio", - "ndk", + "ndk 0.7.0", "objc2", "once_cell", "percent-encoding", "raw-window-handle 0.4.3", "raw-window-handle 0.5.0", - "sctk-adwaita", + "sctk-adwaita 0.5.2", "smithay-client-toolkit", "wasm-bindgen", "wayland-client", "wayland-protocols", "web-sys", - "windows-sys", + "windows-sys 0.42.0", "x11-dl", ] [[package]] +name = "wio" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d129932f4644ac2396cb456385cbf9e63b5b30c6e8dc4820bdca4eb082037a5" +dependencies = [ + "winapi", +] + +[[package]] name = "x11-dl" version = "2.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2881,6 +3581,18 @@ dependencies = [ ] [[package]] +name = "x11rb" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e99be55648b3ae2a52342f9a870c0e138709a3493261ce9b469afe6e4df6d8a" +dependencies = [ + "gethostname", + "nix 0.22.3", + "winapi", + "winapi-wsapoll", +] + +[[package]] name = "xcursor" version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/Cargo.toml b/Cargo.toml @@ -13,10 +13,9 @@ crate-type = ["lib", "cdylib"] [dependencies] chrono = "0.4" egui = "0.19.0" +eframe = "0.19.0" egui_extras = { version = "0.19.0", features = ["image", "svg"] } -egui_wgpu_backend = "0.20.0" #egui-winit = "0.19.0" -egui_winit_platform = {git = "https://github.com/inferrna/egui_winit_platform.git"} ehttp = "0.2.0" epi = "0.17.0" hex = "0.4.3" @@ -31,11 +30,16 @@ serde = { version = "1", features = ["derive"] } # You only need this if you wan sha2 = "0.10.6" tracing = "0.1.37" tracing-subscriber = "0.3" -wgpu = "0.14.0" -egui_demo_lib = "0.19" #winit = "0.27.1" +# This dependency will only be included when targeting Android +[target.'cfg(target_os = "android")'.dependencies] +egui_wgpu_backend = "0.20.0" +wgpu = "0.14.0" +winit = { git="https://github.com/rust-windowing/winit.git", default-features = false, features = ["android-native-activity"] } +egui_winit_platform = {git = "https://github.com/inferrna/egui_winit_platform.git"} + [target.'cfg(debug_assertions)'.dependencies] simple_logger = "*" android_logger = "0.11.1" @@ -44,9 +48,6 @@ android_logger = "0.11.1" [target.'cfg(not(target_os = "android"))'.dependencies] winit = { git="https://github.com/rust-windowing/winit.git" } -# This dependency will only be included when targeting Android -[target.'cfg(target_os = "android")'.dependencies] -winit = { git="https://github.com/rust-windowing/winit.git", default-features = false, features = ["android-native-activity"] } # web: [target.'cfg(target_arch = "wasm32")'.dependencies] diff --git a/shell.nix b/shell.nix @@ -0,0 +1,33 @@ +{ pkgs ? import <nixpkgs> {} }: +with pkgs; +let + x11libs = lib.makeLibraryPath [ xorg.libX11 xorg.libXcursor xorg.libXrandr xorg.libXi libglvnd vulkan-loader vulkan-validation-layers ]; + ndk-version = "24.0.8215888"; + androidComposition = androidenv.composeAndroidPackages { + includeNDK = true; + ndkVersions = [ ndk-version ]; + platformVersions = [ "28" "29" "30" ]; + useGoogleAPIs = false; + #useGoogleTVAddOns = false; + #includeExtras = [ + # "extras;google;gcm" + #]; + }; + androidsdk = androidComposition.androidsdk; + android-home = "${androidsdk}/libexec/android-sdk"; + ndk-home = "${android-home}/ndk/${ndk-version}"; +in + +mkShell { + nativeBuildInputs = [ + cargo-edit cargo-watch rustup rustfmt libiconv pkgconfig cmake fontconfig + brotli wabt + + # android + jre openssl libiconv androidsdk + ]; + + ANDROID_HOME = android-home; + NDK_HOME = ndk-home; + LD_LIBRARY_PATH="${x11libs}"; +} diff --git a/src/android.rs b/src/android.rs @@ -0,0 +1,366 @@ +// TODO: replace all of this old stuff with eframe once it supports +// android properly +use crate::app::Damus; + +use ::egui::FontDefinitions; +use chrono::Timelike; +use egui_wgpu_backend::{RenderPass, ScreenDescriptor}; +use egui_winit_platform::{Platform, PlatformDescriptor}; +use log::{error, info, warn}; +use std::iter; +use std::time::Instant; +use wgpu::CompositeAlphaMode; +use winit::event::Event::*; +use winit::event_loop::ControlFlow; +use winit::event_loop::EventLoop; + +#[cfg(target_os = "android")] +use winit::{ + event::StartCause, platform::android::EventLoopBuilderExtAndroid, + platform::run_return::EventLoopExtRunReturn, +}; + +/// A custom event type for the winit app. +#[derive(Debug, Clone, Copy)] +pub enum WinitEvent { + RequestRedraw, +} + +/// This is the repaint signal type that egui needs for requesting a repaint from another thread. +/// It sends the custom RequestRedraw event to the winit event loop. +struct ExampleRepaintSignal(std::sync::Mutex<winit::event_loop::EventLoopProxy<WinitEvent>>); + +impl epi::backend::RepaintSignal for ExampleRepaintSignal { + fn request_repaint(&self) { + match self.0.lock() { + Err(e) => { + error!( + "Failed to lock guard at {} line {} with error\n{}", + file!(), + line!(), + e + ); + } + Ok(e) => { + let _ = e.send_event(WinitEvent::RequestRedraw); + } + }; + } +} + +#[cfg(target_os = "android")] +#[no_mangle] +pub fn android_main(app: winit::platform::android::activity::AndroidApp) { + #[cfg(debug_assertions)] + { + std::env::set_var("RUST_BACKTRACE", "full"); + android_logger::init_once( + android_logger::Config::default().with_min_level(log::Level::Trace), + ); + } + let event_loop = winit::event_loop::EventLoopBuilder::<WinitEvent>::with_user_event() + .with_android_app(app) + .build(); + run_evloop(event_loop); +} + +pub fn run_evloop(mut event_loop: EventLoop<WinitEvent>) { + //'Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.', ..../winit-c2fdb27092aba5a7/418cc44/src/platform_impl/android/mod.rs:1028:13 + warn!("Winit build window at {} line {}", file!(), line!()); + let window = winit::window::WindowBuilder::new() + .with_decorations(!cfg!(android)) /* !cfg!(android) */ + .with_resizable(!cfg!(android)) + .with_transparent(false) + .with_title("egui-wgpu_winit example") + .build(&event_loop) + .unwrap_or_else(|e| { + panic!( + "Failed to init window at {} line {} with error\n{:?}", + file!(), + line!(), + e + ) + }); + + warn!("WGPU new instance at {} line {}", file!(), line!()); + let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY); + + let mut size = window.inner_size(); + let outer_size = window.outer_size(); + + warn!("outer_size = {:?}", outer_size); + warn!("size = {:?}", size); + + warn!("Create platform at {} line {}", file!(), line!()); + // We use the egui_winit_platform crate as the platform. + let mut platform = Platform::new(PlatformDescriptor { + physical_width: size.width as u32, + physical_height: size.height as u32, + scale_factor: window.scale_factor(), + font_definitions: FontDefinitions::default(), + style: Default::default(), + }); + + let mut recreate_surface = false; + + #[cfg(target_os = "android")] + let mut platform = { + //Just find the actual screen size on android + event_loop.run_return(|main_event, tgt, control_flow| { + control_flow.set_poll(); + warn!( + "Got event: {:?} at {} line {}", + &main_event, + file!(), + line!() + ); + match main_event { + NewEvents(e) => match e { + StartCause::ResumeTimeReached { .. } => {} + StartCause::WaitCancelled { .. } => {} + StartCause::Poll => {} + StartCause::Init => {} + }, + WindowEvent { + //window_id, + ref event, + .. + } => { + if let winit::event::WindowEvent::Resized(r) = event { + size = *r; + } + } + DeviceEvent { .. } => {} + UserEvent(_) => {} + Suspended => { + info!("Suspended"); + control_flow.set_poll(); + } + Resumed => { + if let Some(primary_mon) = tgt.primary_monitor() { + size = primary_mon.size(); + window.set_inner_size(size); + warn!( + "Set to new size: {:?} at {} line {}", + &size, + file!(), + line!() + ); + } else if let Some(other_mon) = tgt.available_monitors().next() { + size = other_mon.size(); + window.set_inner_size(size); + warn!( + "Set to new size: {:?} at {} line {}", + &size, + file!(), + line!() + ); + } + + info!("Resumed"); + recreate_surface = true; + control_flow.set_exit(); + } + MainEventsCleared => {} + RedrawRequested(_rdr) => {} + RedrawEventsCleared => {} + LoopDestroyed => {} + }; + platform.handle_event(&main_event); + }); + + warn!("Recreate platform at {} line {}", file!(), line!()); + // We use the egui_winit_platform crate as the platform. + Platform::new(PlatformDescriptor { + physical_width: size.width as u32, + physical_height: size.height as u32, + scale_factor: window.scale_factor(), + font_definitions: FontDefinitions::default(), + style: Default::default(), + }) + }; + + warn!("WGPU new surface at {} line {}", file!(), line!()); + let mut surface = unsafe { instance.create_surface(&window) }; + + warn!("instance request_adapter at {} line {}", file!(), line!()); + // WGPU 0.11+ support force fallback (if HW implementation not supported), set it to true or false (optional). + let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { + power_preference: wgpu::PowerPreference::HighPerformance, + compatible_surface: Some(&surface), + force_fallback_adapter: false, + })) + .unwrap_or_else(|| panic!("Failed get adapter at {} line {}", file!(), line!())); + + warn!("adapter request_device at {} line {}", file!(), line!()); + let (device, queue) = pollster::block_on(adapter.request_device( + &wgpu::DeviceDescriptor { + features: wgpu::Features::default(), + limits: wgpu::Limits::default(), + label: None, + }, + None, + )) + .unwrap_or_else(|e| { + panic!( + "Failed to request device at {} line {} with error\n{:?}", + file!(), + line!(), + e + ) + }); + + let surface_format = surface.get_supported_formats(&adapter)[0]; + let mut surface_config = wgpu::SurfaceConfiguration { + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + format: surface_format, + width: size.width as u32, + height: size.height as u32, + present_mode: wgpu::PresentMode::AutoNoVsync, + alpha_mode: CompositeAlphaMode::Auto, + }; + + warn!("surface configure at {} line {}", file!(), line!()); + surface.configure(&device, &surface_config); + + warn!("RenderPass new at {} line {}", file!(), line!()); + // We use the egui_wgpu_backend crate as the render backend. + let mut egui_rpass = RenderPass::new(&device, surface_format, 1); + + warn!("DemoWindows default at {} line {}", file!(), line!()); + // Display the demo application that ships with egui. + let mut app = Damus::new(); + app.add_test_events(); + + let start_time = Instant::now(); + + warn!("Enter the loop"); + event_loop.run(move |event, _, control_flow| { + // Pass the winit events to the platform integration. + warn!("Got event: {:?} at {} line {}", &event, file!(), line!()); + platform.handle_event(&event); + match event { + RedrawRequested(..) => { + platform.update_time(start_time.elapsed().as_secs_f64()); + + let output_frame = match surface.get_current_texture() { + Ok(frame) => frame, + Err(wgpu::SurfaceError::Outdated) => { + // This error occurs when the app is minimized on Windows. + // Silently return here to prevent spamming the console with: + error!("The underlying surface has changed, and therefore the swap chain must be updated"); + recreate_surface = true; + return; + } + Err(wgpu::SurfaceError::Lost) => { + // This error occurs when the app is minimized on Windows. + // Silently return here to prevent spamming the console with: + error!("LOST surface, drop frame. Originally: \"The swap chain has been lost and needs to be recreated\""); + recreate_surface = true; + return; + } + Err(e) => { + error!("Dropped frame with error: {}", e); + return; + } + }; + let output_view = output_frame + .texture + .create_view(&wgpu::TextureViewDescriptor::default()); + + // Begin to draw the UI frame. + platform.begin_frame(); + + // Draw the demo application. + app.ui(&platform.context()); + + // End the UI frame. We could now handle the output and draw the UI with the backend. + let full_output = platform.end_frame(Some(&window)); + let paint_jobs = platform.context().tessellate(full_output.shapes); + + let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { + label: Some("encoder"), + }); + + // Upload all resources for the GPU. + let screen_descriptor = ScreenDescriptor { + physical_width: surface_config.width, + physical_height: surface_config.height, + scale_factor: window.scale_factor() as f32 + }; + let tdelta: egui::TexturesDelta = full_output.textures_delta; + egui_rpass + .add_textures(&device, &queue, &tdelta) + .expect("add texture ok"); + egui_rpass.update_buffers(&device, &queue, &paint_jobs, &screen_descriptor); + + // Record all render passes. + egui_rpass + .execute( + &mut encoder, + &output_view, + &paint_jobs, + &screen_descriptor, + Some(wgpu::Color::BLACK), + ) + .unwrap_or_else(|e| panic!("Failed to render pass at {} line {} with error\n{:?}", file!(), line!(), e)); + // Submit the commands. + queue.submit(iter::once(encoder.finish())); + + // Redraw egui + output_frame.present(); + + egui_rpass + .remove_textures(tdelta) + .expect("remove texture ok"); + + // Support reactive on windows only, but not on linux. + // if _output.needs_repaint { + // *control_flow = ControlFlow::Poll; + // } else { + // *control_flow = ControlFlow::Wait; + // } + } + MainEventsCleared | UserEvent(WinitEvent::RequestRedraw) => { + window.request_redraw(); + } + WindowEvent { event, .. } => match event { + winit::event::WindowEvent::Resized(size) => { + // Resize with 0 width and height is used by winit to signal a minimize event on Windows. + // See: https://github.com/rust-windowing/winit/issues/208 + // This solves an issue where the app would panic when minimizing on Windows. + if size.width > 0 && size.height > 0 { + surface_config.width = size.width; + surface_config.height = size.height; + surface.configure(&device, &surface_config); + } + } + winit::event::WindowEvent::CloseRequested => { + *control_flow = ControlFlow::Exit; + } + _ => {} + }, + Resumed => { + info!("Damus Resumed (recreate surface? {})", recreate_surface); + if recreate_surface { + //https://github.com/gfx-rs/wgpu/issues/2302 + warn!("WGPU new surface at {} line {}", file!(), line!()); + surface = unsafe { instance.create_surface(&window) }; + warn!("surface configure at {} line {}", file!(), line!()); + surface.configure(&device, &surface_config); + recreate_surface = false; + } + }, + Suspended => { + recreate_surface = true; + }, + _ => (), + } + }); +} + +/// Time of day as seconds since midnight. Used for clock in demo app. +pub fn seconds_since_midnight() -> f64 { + let time = chrono::Local::now().time(); + time.num_seconds_from_midnight() as f64 + 1e-9 * (time.nanosecond() as f64) +} diff --git a/src/app.rs b/src/app.rs @@ -319,18 +319,18 @@ fn add_test_events(damus: &mut Damus<'_>) { } } -//impl eframe::App for Damus<'_> { -// /// Called by the frame work to save state before shutdown. -// fn save(&mut self, storage: &mut dyn eframe::Storage) { -// eframe::set_value(storage, eframe::APP_KEY, self); -// } -// -// /// Called each time the UI needs repainting, which may be many times per second. -// /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. -// fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { -// update_damus(ctx) -// } -//} +impl eframe::App for Damus<'_> { + /// Called by the frame work to save state before shutdown. + fn save(&mut self, storage: &mut dyn eframe::Storage) { + //eframe::set_value(storage, eframe::APP_KEY, self); + } + + /// Called each time the UI needs repainting, which may be many times per second. + /// Put your widgets into a `SidePanel`, `TopPanel`, `CentralPanel`, `Window` or `Area`. + fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) { + self.ui(ctx); + } +} pub const LOREM_IPSUM: &str = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum."; diff --git a/src/bin/main.rs b/src/bin/main.rs @@ -1,8 +1,36 @@ -use damus::WinitEvent; +#![warn(clippy::all, rust_2018_idioms)] +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] // hide console window on Windows in release +use damus::Damus; +use eframe; +// Desktop +#[cfg(not(target_arch = "wasm32"))] fn main() { - #[cfg(debug_assertions)] - simple_logger::init().unwrap(); - let event_loop = winit::event_loop::EventLoopBuilder::<WinitEvent>::with_user_event().build(); - damus::main(event_loop); + // Log to stdout (if you run with `RUST_LOG=debug`). + tracing_subscriber::fmt::init(); + + let native_options = eframe::NativeOptions::default(); + eframe::run_native( + "Damus Desktop", + native_options, + Box::new(|cc| Box::new(Damus::new())), + ); +} + +// Web +#[cfg(target_arch = "wasm32")] +fn main() { + // Make sure panics are logged using `console.error`. + console_error_panic_hook::set_once(); + + // Redirect tracing to console.log and friends: + tracing_wasm::set_as_global_default(); + + let web_options = eframe::WebOptions::default(); + eframe::start_web( + "the_canvas_id", // hardcode it + web_options, + Box::new(|cc| Box::new(Damus::new())), + ) + .expect("failed to start eframe"); } diff --git a/src/lib.rs b/src/lib.rs @@ -1,368 +1,8 @@ +#[cfg(target_os = "android")] +pub mod android; + mod app; mod event; pub use app::Damus; pub use event::Event; - -use ::egui::FontDefinitions; -use chrono::Timelike; -use egui_wgpu_backend::{RenderPass, ScreenDescriptor}; -use egui_winit_platform::{Platform, PlatformDescriptor}; -use log::{error, info, warn}; -use std::iter; -use std::time::Instant; -use wgpu::CompositeAlphaMode; -use winit::event::Event::*; -use winit::event_loop::ControlFlow; -use winit::event_loop::EventLoop; - -#[cfg(target_os = "android")] -use winit::{ - event::StartCause, platform::android::EventLoopBuilderExtAndroid, - platform::run_return::EventLoopExtRunReturn, -}; - -/// A custom event type for the winit app. -#[derive(Debug, Clone, Copy)] -pub enum WinitEvent { - RequestRedraw, -} - -/// This is the repaint signal type that egui needs for requesting a repaint from another thread. -/// It sends the custom RequestRedraw event to the winit event loop. -struct ExampleRepaintSignal(std::sync::Mutex<winit::event_loop::EventLoopProxy<WinitEvent>>); - -impl epi::backend::RepaintSignal for ExampleRepaintSignal { - fn request_repaint(&self) { - match self.0.lock() { - Err(e) => { - error!( - "Failed to lock guard at {} line {} with error\n{}", - file!(), - line!(), - e - ); - } - Ok(e) => { - let _ = e.send_event(WinitEvent::RequestRedraw); - } - }; - } -} - -#[cfg(target_os = "android")] -#[no_mangle] -fn android_main(app: winit::platform::android::activity::AndroidApp) { - #[cfg(debug_assertions)] - { - std::env::set_var("RUST_BACKTRACE", "full"); - android_logger::init_once( - android_logger::Config::default().with_min_level(log::Level::Trace), - ); - } - let event_loop = winit::event_loop::EventLoopBuilder::<WinitEvent>::with_user_event() - .with_android_app(app) - .build(); - main(event_loop); -} - -pub fn main(mut event_loop: EventLoop<WinitEvent>) { - //'Cannot get the native window, it's null and will always be null before Event::Resumed and after Event::Suspended. Make sure you only call this function between those events.', ..../winit-c2fdb27092aba5a7/418cc44/src/platform_impl/android/mod.rs:1028:13 - warn!("Winit build window at {} line {}", file!(), line!()); - let window = winit::window::WindowBuilder::new() - .with_decorations(!cfg!(android)) /* !cfg!(android) */ - .with_resizable(!cfg!(android)) - .with_transparent(false) - .with_title("egui-wgpu_winit example") - .build(&event_loop) - .unwrap_or_else(|e| { - panic!( - "Failed to init window at {} line {} with error\n{:?}", - file!(), - line!(), - e - ) - }); - - warn!("WGPU new instance at {} line {}", file!(), line!()); - let instance = wgpu::Instance::new(wgpu::Backends::PRIMARY); - - let mut size = window.inner_size(); - let outer_size = window.outer_size(); - - warn!("outer_size = {:?}", outer_size); - warn!("size = {:?}", size); - - warn!("Create platform at {} line {}", file!(), line!()); - // We use the egui_winit_platform crate as the platform. - let mut platform = Platform::new(PlatformDescriptor { - physical_width: size.width as u32, - physical_height: size.height as u32, - scale_factor: window.scale_factor(), - font_definitions: FontDefinitions::default(), - style: Default::default(), - }); - - let mut recreate_surface = false; - - #[cfg(target_os = "android")] - let mut platform = { - //Just find the actual screen size on android - event_loop.run_return(|main_event, tgt, control_flow| { - control_flow.set_poll(); - warn!( - "Got event: {:?} at {} line {}", - &main_event, - file!(), - line!() - ); - match main_event { - NewEvents(e) => match e { - StartCause::ResumeTimeReached { .. } => {} - StartCause::WaitCancelled { .. } => {} - StartCause::Poll => {} - StartCause::Init => {} - }, - WindowEvent { - //window_id, - ref event, - .. - } => { - if let winit::event::WindowEvent::Resized(r) = event { - size = *r; - } - } - DeviceEvent { .. } => {} - UserEvent(_) => {} - Suspended => { - info!("Suspended"); - control_flow.set_poll(); - } - Resumed => { - if let Some(primary_mon) = tgt.primary_monitor() { - size = primary_mon.size(); - window.set_inner_size(size); - warn!( - "Set to new size: {:?} at {} line {}", - &size, - file!(), - line!() - ); - } else if let Some(other_mon) = tgt.available_monitors().next() { - size = other_mon.size(); - window.set_inner_size(size); - warn!( - "Set to new size: {:?} at {} line {}", - &size, - file!(), - line!() - ); - } - - info!("Resumed"); - recreate_surface = true; - control_flow.set_exit(); - } - MainEventsCleared => {} - RedrawRequested(_rdr) => {} - RedrawEventsCleared => {} - LoopDestroyed => {} - }; - platform.handle_event(&main_event); - }); - - warn!("Recreate platform at {} line {}", file!(), line!()); - // We use the egui_winit_platform crate as the platform. - Platform::new(PlatformDescriptor { - physical_width: size.width as u32, - physical_height: size.height as u32, - scale_factor: window.scale_factor(), - font_definitions: FontDefinitions::default(), - style: Default::default(), - }) - }; - - warn!("WGPU new surface at {} line {}", file!(), line!()); - let mut surface = unsafe { instance.create_surface(&window) }; - - warn!("instance request_adapter at {} line {}", file!(), line!()); - // WGPU 0.11+ support force fallback (if HW implementation not supported), set it to true or false (optional). - let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { - power_preference: wgpu::PowerPreference::HighPerformance, - compatible_surface: Some(&surface), - force_fallback_adapter: false, - })) - .unwrap_or_else(|| panic!("Failed get adapter at {} line {}", file!(), line!())); - - warn!("adapter request_device at {} line {}", file!(), line!()); - let (device, queue) = pollster::block_on(adapter.request_device( - &wgpu::DeviceDescriptor { - features: wgpu::Features::default(), - limits: wgpu::Limits::default(), - label: None, - }, - None, - )) - .unwrap_or_else(|e| { - panic!( - "Failed to request device at {} line {} with error\n{:?}", - file!(), - line!(), - e - ) - }); - - let surface_format = surface.get_supported_formats(&adapter)[0]; - let mut surface_config = wgpu::SurfaceConfiguration { - usage: wgpu::TextureUsages::RENDER_ATTACHMENT, - format: surface_format, - width: size.width as u32, - height: size.height as u32, - present_mode: wgpu::PresentMode::AutoNoVsync, - alpha_mode: CompositeAlphaMode::Auto, - }; - - warn!("surface configure at {} line {}", file!(), line!()); - surface.configure(&device, &surface_config); - - warn!("RenderPass new at {} line {}", file!(), line!()); - // We use the egui_wgpu_backend crate as the render backend. - let mut egui_rpass = RenderPass::new(&device, surface_format, 1); - - warn!("DemoWindows default at {} line {}", file!(), line!()); - // Display the demo application that ships with egui. - let mut app = Damus::new(); - app.add_test_events(); - - let start_time = Instant::now(); - - warn!("Enter the loop"); - event_loop.run(move |event, _, control_flow| { - // Pass the winit events to the platform integration. - warn!("Got event: {:?} at {} line {}", &event, file!(), line!()); - platform.handle_event(&event); - match event { - RedrawRequested(..) => { - platform.update_time(start_time.elapsed().as_secs_f64()); - - let output_frame = match surface.get_current_texture() { - Ok(frame) => frame, - Err(wgpu::SurfaceError::Outdated) => { - // This error occurs when the app is minimized on Windows. - // Silently return here to prevent spamming the console with: - error!("The underlying surface has changed, and therefore the swap chain must be updated"); - recreate_surface = true; - return; - } - Err(wgpu::SurfaceError::Lost) => { - // This error occurs when the app is minimized on Windows. - // Silently return here to prevent spamming the console with: - error!("LOST surface, drop frame. Originally: \"The swap chain has been lost and needs to be recreated\""); - recreate_surface = true; - return; - } - Err(e) => { - error!("Dropped frame with error: {}", e); - return; - } - }; - let output_view = output_frame - .texture - .create_view(&wgpu::TextureViewDescriptor::default()); - - // Begin to draw the UI frame. - platform.begin_frame(); - - // Draw the demo application. - app.ui(&platform.context()); - - // End the UI frame. We could now handle the output and draw the UI with the backend. - let full_output = platform.end_frame(Some(&window)); - let paint_jobs = platform.context().tessellate(full_output.shapes); - - let mut encoder = device.create_command_encoder(&wgpu::CommandEncoderDescriptor { - label: Some("encoder"), - }); - - // Upload all resources for the GPU. - let screen_descriptor = ScreenDescriptor { - physical_width: surface_config.width, - physical_height: surface_config.height, - scale_factor: window.scale_factor() as f32 - }; - let tdelta: egui::TexturesDelta = full_output.textures_delta; - egui_rpass - .add_textures(&device, &queue, &tdelta) - .expect("add texture ok"); - egui_rpass.update_buffers(&device, &queue, &paint_jobs, &screen_descriptor); - - // Record all render passes. - egui_rpass - .execute( - &mut encoder, - &output_view, - &paint_jobs, - &screen_descriptor, - Some(wgpu::Color::BLACK), - ) - .unwrap_or_else(|e| panic!("Failed to render pass at {} line {} with error\n{:?}", file!(), line!(), e)); - // Submit the commands. - queue.submit(iter::once(encoder.finish())); - - // Redraw egui - output_frame.present(); - - egui_rpass - .remove_textures(tdelta) - .expect("remove texture ok"); - - // Support reactive on windows only, but not on linux. - // if _output.needs_repaint { - // *control_flow = ControlFlow::Poll; - // } else { - // *control_flow = ControlFlow::Wait; - // } - } - MainEventsCleared | UserEvent(WinitEvent::RequestRedraw) => { - window.request_redraw(); - } - WindowEvent { event, .. } => match event { - winit::event::WindowEvent::Resized(size) => { - // Resize with 0 width and height is used by winit to signal a minimize event on Windows. - // See: https://github.com/rust-windowing/winit/issues/208 - // This solves an issue where the app would panic when minimizing on Windows. - if size.width > 0 && size.height > 0 { - surface_config.width = size.width; - surface_config.height = size.height; - surface.configure(&device, &surface_config); - } - } - winit::event::WindowEvent::CloseRequested => { - *control_flow = ControlFlow::Exit; - } - _ => {} - }, - Resumed => { - info!("Damus Resumed (recreate surface? {})", recreate_surface); - if recreate_surface { - //https://github.com/gfx-rs/wgpu/issues/2302 - warn!("WGPU new surface at {} line {}", file!(), line!()); - surface = unsafe { instance.create_surface(&window) }; - warn!("surface configure at {} line {}", file!(), line!()); - surface.configure(&device, &surface_config); - recreate_surface = false; - } - }, - Suspended => { - recreate_surface = true; - }, - _ => (), - } - }); -} - -/// Time of day as seconds since midnight. Used for clock in demo app. -pub fn seconds_since_midnight() -> f64 { - let time = chrono::Local::now().time(); - time.num_seconds_from_midnight() as f64 + 1e-9 * (time.nanosecond() as f64) -}