1
1
mirror of https://github.com/wez/wezterm.git synced 2024-11-22 22:42:48 +03:00

remove wgpu from window test deps

We don't use this and all it really does it make `cargo test`
take longer
This commit is contained in:
Wez Furlong 2021-11-23 05:39:07 -07:00
parent d1e0562631
commit f9ce727281
3 changed files with 3 additions and 860 deletions

547
Cargo.lock generated
View File

@ -23,12 +23,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aae1277d39aeec15cb388266ecc24b11c80469deae6067e17a1a7aa9e5c1f234"
[[package]]
name = "ahash"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "739f4a8db6605981345c5654f3a85b056ce52f37a39d34da03f25bf2151ea16e"
[[package]]
name = "ahash"
version = "0.7.6"
@ -124,15 +118,6 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]]
name = "ash"
version = "0.32.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06063a002a77d2734631db74e8f4ce7148b77fe522e6bca46f2ae7774fd48112"
dependencies = [
"libloading 0.7.2",
]
[[package]]
name = "assert_fs"
version = "1.0.6"
@ -412,21 +397,6 @@ checksum = "ea52a394d9a85bf9819ca50382187ece2497501dbd6397fd33388400e512a90e"
name = "bintree"
version = "0.1.0"
[[package]]
name = "bit-set"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e11e16035ea35e4e5997b393eacbf6f63983188f7a2ad25bfb13465f5ad59de"
dependencies = [
"bit-vec",
]
[[package]]
name = "bit-vec"
version = "0.6.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "349f9b6a179ed607305526ca489b34ad0a41aed5f7980fa90eb03160b69598fb"
[[package]]
name = "bitflags"
version = "1.3.2"
@ -593,12 +563,6 @@ version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "cfg_aliases"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e"
[[package]]
name = "cgl"
version = "0.3.2"
@ -683,21 +647,6 @@ dependencies = [
"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 0.9.2",
"core-graphics-types",
"foreign-types",
"libc",
"objc",
]
[[package]]
name = "codec"
version = "0.1.0"
@ -719,16 +668,6 @@ dependencies = [
"zstd",
]
[[package]]
name = "codespan-reporting"
version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e"
dependencies = [
"termcolor",
"unicode-width",
]
[[package]]
name = "color-types"
version = "0.1.0"
@ -813,12 +752,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb58b6451e8c2a812ad979ed1d83378caa5e927eef2622017a45f251457c2c9d"
[[package]]
name = "copyless"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2df960f5d869b2dd8532793fde43eb5427cceb126c929747a26823ab0eeb536"
[[package]]
name = "core-foundation"
version = "0.7.0"
@ -1005,17 +938,6 @@ dependencies = [
"syn",
]
[[package]]
name = "d3d12"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2daefd788d1e96e0a9d66dee4b828b883509bc3ea9ce30665f04c3246372690c"
dependencies = [
"bitflags",
"libloading 0.7.2",
"winapi 0.3.9",
]
[[package]]
name = "deflate"
version = "0.8.6"
@ -1145,15 +1067,6 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "drm-fourcc"
version = "2.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0aafbcdb8afc29c1a7ee5fbe53b5d62f4565b35a042a662ca9fecd0b54dae6f4"
dependencies = [
"serde",
]
[[package]]
name = "dwrote"
version = "0.11.0"
@ -1350,16 +1263,6 @@ dependencies = [
"smallvec 0.6.14",
]
[[package]]
name = "external-memory"
version = "0.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e4dfe8d292b014422776a8c516862d2bff8a81b223a4461dfdc45f3862dc9d39"
dependencies = [
"bitflags",
"drm-fourcc",
]
[[package]]
name = "fake-simd"
version = "0.1.2"
@ -1408,12 +1311,6 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "fixedbitset"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37ab347416e802de484e4d03c7316c48f1ecb56574dfd4a46a80f173ce1de04d"
[[package]]
name = "flate2"
version = "1.0.22"
@ -1645,15 +1542,6 @@ dependencies = [
"slab",
]
[[package]]
name = "fxhash"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c31b6d751ae2c7f11320402d34e41349dd1016f8d5d45e48c4312bc8625af50c"
dependencies = [
"byteorder",
]
[[package]]
name = "generic-array"
version = "0.12.4"
@ -1706,168 +1594,6 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "gfx-auxil"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1694991b11d642680e82075a75c7c2bd75556b805efa7660b705689f05b1ab1c"
dependencies = [
"fxhash",
"gfx-hal",
"spirv_cross",
]
[[package]]
name = "gfx-backend-dx11"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f9e453baf3aaef2b0c354ce0b3d63d76402e406a59b64b7182d123cfa6635ae"
dependencies = [
"arrayvec",
"bitflags",
"gfx-auxil",
"gfx-hal",
"gfx-renderdoc",
"libloading 0.7.2",
"log",
"parking_lot 0.11.2",
"range-alloc",
"raw-window-handle",
"smallvec 1.7.0",
"spirv_cross",
"thunderdome",
"winapi 0.3.9",
"wio",
]
[[package]]
name = "gfx-backend-dx12"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21506399f64a3c4d389182a89a30073856ae33eb712315456b4fd8f39ee7682a"
dependencies = [
"arrayvec",
"bit-set",
"bitflags",
"d3d12",
"gfx-auxil",
"gfx-hal",
"gfx-renderdoc",
"log",
"parking_lot 0.11.2",
"range-alloc",
"raw-window-handle",
"smallvec 1.7.0",
"spirv_cross",
"thunderdome",
"winapi 0.3.9",
]
[[package]]
name = "gfx-backend-empty"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "29c8f813c47791918aa00dc9c9ddf961d23fa8c2a5d869e6cb8ea84f944820f4"
dependencies = [
"gfx-hal",
"log",
"raw-window-handle",
]
[[package]]
name = "gfx-backend-gl"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bae057fc3a0ab23ecf97ae51d4017d27d5ddf0aab16ee6dcb58981af88c3152"
dependencies = [
"arrayvec",
"bitflags",
"fxhash",
"gfx-hal",
"glow",
"js-sys",
"khronos-egl",
"libloading 0.7.2",
"log",
"naga",
"parking_lot 0.11.2",
"raw-window-handle",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gfx-backend-metal"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0de85808e2a98994c6af925253f8a9593bc57180ef1ea137deab6d35cc949517"
dependencies = [
"arrayvec",
"bitflags",
"block",
"cocoa-foundation",
"copyless",
"core-graphics-types",
"foreign-types",
"fxhash",
"gfx-hal",
"log",
"metal",
"naga",
"objc",
"parking_lot 0.11.2",
"profiling",
"range-alloc",
"raw-window-handle",
"storage-map",
]
[[package]]
name = "gfx-backend-vulkan"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9861ec855acbbc65c0e4f966d761224886e811dc2c6d413a4776e9293d0e5c0"
dependencies = [
"arrayvec",
"ash",
"byteorder",
"core-graphics-types",
"gfx-hal",
"gfx-renderdoc",
"inplace_it",
"log",
"naga",
"objc",
"parking_lot 0.11.2",
"raw-window-handle",
"smallvec 1.7.0",
"winapi 0.3.9",
]
[[package]]
name = "gfx-hal"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7fbb575ea793dd0507b3082f4f2cde62dc9f3cebd98f5cd49ba2a4da97a976fd"
dependencies = [
"bitflags",
"external-memory",
"naga",
"raw-window-handle",
"thiserror",
]
[[package]]
name = "gfx-renderdoc"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c8027995e247e2426d3a00d13f5191dd56c314bff02dc4b54cbf727f1ba9c40a"
dependencies = [
"libloading 0.7.2",
"log",
"renderdoc-sys",
]
[[package]]
name = "gif"
version = "0.11.3"
@ -1946,63 +1672,12 @@ dependencies = [
"web-sys",
]
[[package]]
name = "glow"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b80b98efaa8a34fce11d60dd2ce2760d5d83c373cbcc73bb87c2a3a84a54108"
dependencies = [
"js-sys",
"slotmap 0.4.3",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "glyph-names"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8050dc1be3880f690a771051d09727d759229d299afffa1488acc3556879039d"
[[package]]
name = "gpu-alloc"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbc1b6ca374e81862526786d9cb42357ce03706ed1b8761730caafd02ab91f3a"
dependencies = [
"bitflags",
"gpu-alloc-types",
]
[[package]]
name = "gpu-alloc-types"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "54804d0d6bc9d7f26db4eaec1ad10def69b599315f487d32c334a80d1efe67a5"
dependencies = [
"bitflags",
]
[[package]]
name = "gpu-descriptor"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e8a70f1e87a3840ed6a3e99e02c2b861e4dbdf26f0d07e38f42ea5aff46cfce2"
dependencies = [
"bitflags",
"gpu-descriptor-types",
"hashbrown 0.9.1",
]
[[package]]
name = "gpu-descriptor-types"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "363e3677e55ad168fef68cf9de3a4a310b53124c5e784c53a1d70e92d23f2126"
dependencies = [
"bitflags",
]
[[package]]
name = "guillotiere"
version = "0.6.2"
@ -2027,22 +1702,13 @@ version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e1de41fb8dba9714efd92241565cdff73f78508c95697dd56787d3cba27e2353"
[[package]]
name = "hashbrown"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d7afe4a420e3fe79967a00898cc1f4db7c8a49a9333a29f8a4bd76a253d5cd04"
dependencies = [
"ahash 0.4.7",
]
[[package]]
name = "hashbrown"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e"
dependencies = [
"ahash 0.7.6",
"ahash",
]
[[package]]
@ -2161,16 +1827,6 @@ dependencies = [
"tiff",
]
[[package]]
name = "indexmap"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5"
dependencies = [
"autocfg",
"hashbrown 0.11.2",
]
[[package]]
name = "indoc"
version = "1.0.3"
@ -2200,12 +1856,6 @@ dependencies = [
"libc",
]
[[package]]
name = "inplace_it"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90953f308a79fe6d62a4643e51f848fbfddcd05975a38e69fdf4ab86a7baf7ca"
[[package]]
name = "instant"
version = "0.1.12"
@ -2311,16 +1961,6 @@ dependencies = [
"winapi-build",
]
[[package]]
name = "khronos-egl"
version = "4.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8c2352bd1d0bceb871cb9d40f24360c8133c11d7486b68b5381c1dd1a32015e3"
dependencies = [
"libc",
"libloading 0.7.2",
]
[[package]]
name = "khronos_api"
version = "3.1.0"
@ -2588,27 +2228,13 @@ dependencies = [
"autocfg",
]
[[package]]
name = "metal"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0514f491f4cc03632ab399ee01e2c1c1b12d3e1cf2d667c1ff5f87d6dcd2084"
dependencies = [
"bitflags",
"block",
"core-graphics-types",
"foreign-types",
"log",
"objc",
]
[[package]]
name = "metrics"
version = "0.17.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a00f42f354a2ed4894db863b3a4db47aef2d2e4435b937221749bd37a8a7aaa8"
dependencies = [
"ahash 0.7.6",
"ahash",
"metrics-macros",
"proc-macro-hack",
]
@ -2751,24 +2377,6 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "naga"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef670817eef03d356d5a509ea275e7dd3a78ea9e24261ea3cb2dfed1abb08f64"
dependencies = [
"bit-set",
"bitflags",
"codespan-reporting",
"fxhash",
"log",
"num-traits",
"petgraph",
"rose_tree",
"spirv_headers",
"thiserror",
]
[[package]]
name = "nanorand"
version = "0.6.1"
@ -3008,7 +2616,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "915b1b472bc21c53464d6c8461c9d3af805ba1ef837e1cac254428f4a77177b1"
dependencies = [
"malloc_buf",
"objc_exception",
]
[[package]]
@ -3022,15 +2629,6 @@ dependencies = [
"objc_id",
]
[[package]]
name = "objc_exception"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad970fb455818ad6cba4c122ad012fae53ae8b4795f86378bce65e4f6bab2ca4"
dependencies = [
"cc",
]
[[package]]
name = "objc_id"
version = "0.1.1"
@ -3285,16 +2883,6 @@ dependencies = [
"sha-1",
]
[[package]]
name = "petgraph"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "467d164a6de56270bd7c4d070df81d07beace25012d5103ced4e9ff08d6afdb7"
dependencies = [
"fixedbitset",
"indexmap",
]
[[package]]
name = "phf"
version = "0.8.0"
@ -3559,12 +3147,6 @@ dependencies = [
"unicode-xid",
]
[[package]]
name = "profiling"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9926767b8b8244d7b6b64546585121d193c3d0b4856ccd656b7bfa9deb91ab6a"
[[package]]
name = "promise"
version = "0.2.0"
@ -3729,12 +3311,6 @@ dependencies = [
"rand_core 0.5.1",
]
[[package]]
name = "range-alloc"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "63e935c45e09cc6dcf00d2f0b2d630a58f4095320223d47fc68918722f0538b6"
[[package]]
name = "rangeset"
version = "0.1.0"
@ -3873,12 +3449,6 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "renderdoc-sys"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1382d1f0a252c4bf97dc20d979a2fdd05b024acd7c2ed0f7595d7817666a157"
[[package]]
name = "rental"
version = "0.5.6"
@ -3933,15 +3503,6 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "rose_tree"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "284de9dae38774e2813aaabd7e947b4a6fe9b8c58c2309f754a487cdd50de1c2"
dependencies = [
"petgraph",
]
[[package]]
name = "rstest"
version = "0.11.0"
@ -4271,12 +3832,6 @@ version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9def91fd1e018fe007022791f865d0ccc9b3a0d5001e01aabb8b40e46000afb5"
[[package]]
name = "slotmap"
version = "0.4.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bf34684c5767b87de9119790e92e9a1d60056be2ceeaf16a8e6ef13082aeab1"
[[package]]
name = "slotmap"
version = "1.0.6"
@ -4388,27 +3943,6 @@ dependencies = [
"lock_api 0.4.5",
]
[[package]]
name = "spirv_cross"
version = "0.23.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "60647fadbf83c4a72f0d7ea67a7ca3a81835cf442b8deae5c134c3e0055b2e14"
dependencies = [
"cc",
"js-sys",
"wasm-bindgen",
]
[[package]]
name = "spirv_headers"
version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f5b132530b1ac069df335577e3581765995cba5a13995cdbbdbc8fb057c532c"
dependencies = [
"bitflags",
"num-traits",
]
[[package]]
name = "ssh2"
version = "0.9.3"
@ -4433,15 +3967,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f"
[[package]]
name = "storage-map"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418bb14643aa55a7841d5303f72cf512cfb323b8cc221d51580500a1ca75206c"
dependencies = [
"lock_api 0.4.5",
]
[[package]]
name = "strip-ansi-escapes"
version = "0.1.0"
@ -4699,12 +4224,6 @@ dependencies = [
"once_cell",
]
[[package]]
name = "thunderdome"
version = "0.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f685624f172cd0bde6f3363412455e81c018f2379fdf5a218e0be003f1bba642"
[[package]]
name = "tiff"
version = "0.6.1"
@ -5490,65 +5009,6 @@ dependencies = [
"zvariant",
]
[[package]]
name = "wgpu"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd247f8b26fd3d42ef2f320d378025cd6e84d782ef749fab45cc3b981fbe3275"
dependencies = [
"arrayvec",
"js-sys",
"log",
"naga",
"parking_lot 0.11.2",
"raw-window-handle",
"smallvec 1.7.0",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"wgpu-core",
"wgpu-types",
]
[[package]]
name = "wgpu-core"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "958a8a5e418492723ab4e7933bf6dbdf06f5dc87274ba2ae0e4f9c891aac579c"
dependencies = [
"arrayvec",
"bitflags",
"cfg_aliases",
"copyless",
"fxhash",
"gfx-backend-dx11",
"gfx-backend-dx12",
"gfx-backend-empty",
"gfx-backend-gl",
"gfx-backend-metal",
"gfx-backend-vulkan",
"gfx-hal",
"gpu-alloc",
"gpu-descriptor",
"log",
"naga",
"parking_lot 0.11.2",
"profiling",
"raw-window-handle",
"smallvec 1.7.0",
"thiserror",
"wgpu-types",
]
[[package]]
name = "wgpu-types"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4f5c9678cd533558e28b416d66947b099742df1939307478db54f867137f1b60"
dependencies = [
"bitflags",
]
[[package]]
name = "whoami"
version = "1.2.0"
@ -5650,7 +5110,6 @@ dependencies = [
"wayland-protocols",
"wezterm-font",
"wezterm-input-types",
"wgpu",
"winapi 0.3.9",
"winreg 0.6.2",
"x11",
@ -5855,7 +5314,7 @@ dependencies = [
"serde",
"serde_repr",
"sha1",
"slotmap 1.0.6",
"slotmap",
"static_assertions",
"zbus_macros",
"zbus_names",

View File

@ -10,7 +10,6 @@ build = "build.rs"
[dev-dependencies]
pretty_env_logger = "0.4"
wgpu = "0.9"
k9 = "0.11.0"
[build-dependencies]

View File

@ -1,315 +0,0 @@
use ::window::*;
use anyhow::Context;
use promise::spawn::spawn;
#[cfg(target_os = "macos")]
use raw_window_handle::{HasRawWindowHandle, RawWindowHandle};
use std::cell::RefCell;
use std::rc::Rc;
use wezterm_font::FontConfiguration;
pub struct GpuContext {
pub swap_chain: wgpu::SwapChain,
pub sc_desc: wgpu::SwapChainDescriptor,
pub adapter: wgpu::Adapter,
pub device: wgpu::Device,
pub queue: wgpu::Queue,
pub surface: wgpu::Surface,
}
struct MyWindow {
allow_close: bool,
cursor_pos: Point,
dims: Dimensions,
gpu: Option<GpuContext>,
render_pipeline: Option<wgpu::RenderPipeline>,
}
impl Drop for MyWindow {
fn drop(&mut self) {
eprintln!("MyWindow dropped");
}
}
impl MyWindow {
async fn enable_wgpu(&mut self, win: &Window) -> anyhow::Result<()> {
let instance = wgpu::Instance::new(if cfg!(target_os = "macos") {
wgpu::BackendBit::METAL
} else if cfg!(windows) {
// Vulkan supports window opacity, but DX12 doesn't
wgpu::BackendBit::PRIMARY
// wgpu::BackendBit::DX12
} else {
wgpu::BackendBit::PRIMARY
});
let surface = unsafe { instance.create_surface(win) };
let adapter = instance
.request_adapter(&wgpu::RequestAdapterOptions {
power_preference: wgpu::PowerPreference::LowPower,
compatible_surface: Some(&surface),
})
.await
.ok_or_else(|| anyhow::anyhow!("No suitable GPU adapters found on the system!"))?;
let adapter_info = adapter.get_info();
log::info!("wgpu adapter: {:?}", adapter_info);
let (device, queue) = adapter
.request_device(
&wgpu::DeviceDescriptor {
label: None,
features: wgpu::Features::empty(),
limits: wgpu::Limits::default(),
},
None,
)
.await
.context("Unable to find a suitable GPU adapter!")?;
log::info!("wgpu device features: {:?}", device.features());
log::info!("wgpu device limits: {:?}", device.limits());
let format = adapter
.get_swap_chain_preferred_format(&surface)
.ok_or_else(|| anyhow::anyhow!("adapter is not compatible with surface"))?;
let sc_desc = wgpu::SwapChainDescriptor {
usage: wgpu::TextureUsage::RENDER_ATTACHMENT,
format,
width: self.dims.pixel_width as u32,
height: self.dims.pixel_height as u32,
present_mode: wgpu::PresentMode::Mailbox,
};
let swap_chain = device.create_swap_chain(&surface, &sc_desc);
let gpu = GpuContext {
swap_chain,
sc_desc,
adapter,
device,
queue,
surface,
};
let shader = gpu
.device
.create_shader_module(&wgpu::ShaderModuleDescriptor {
label: None,
source: wgpu::ShaderSource::Wgsl(std::borrow::Cow::Borrowed(include_str!(
"shader.wgsl"
))),
flags: wgpu::ShaderFlags::all(),
});
let pipeline_layout = gpu
.device
.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor {
label: None,
bind_group_layouts: &[],
push_constant_ranges: &[],
});
self.render_pipeline
.replace(
gpu.device
.create_render_pipeline(&wgpu::RenderPipelineDescriptor {
label: None,
layout: Some(&pipeline_layout),
vertex: wgpu::VertexState {
module: &shader,
entry_point: "vs_main",
buffers: &[],
},
fragment: Some(wgpu::FragmentState {
module: &shader,
entry_point: "fs_main",
targets: &[format.into()],
}),
primitive: wgpu::PrimitiveState::default(),
depth_stencil: None,
multisample: wgpu::MultisampleState::default(),
}),
);
self.gpu.replace(gpu);
self.paint(win)?;
Ok(())
}
fn paint(&mut self, win: &Window) -> anyhow::Result<()> {
self.fix_transparency(win);
if let Some(gpu) = self.gpu.as_mut() {
let frame = match gpu.swap_chain.get_current_frame() {
Ok(frame) => frame,
Err(err) => {
log::info!("get_current_frame: {:#}", err);
gpu.swap_chain = gpu.device.create_swap_chain(&gpu.surface, &gpu.sc_desc);
gpu.swap_chain
.get_current_frame()
.expect("Failed to acquire next swap chain texture!")
}
};
let mut encoder = gpu
.device
.create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None });
{
let mut rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[wgpu::RenderPassColorAttachment {
view: &frame.output.view,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color {
r: 0.,
g: 0.,
b: 0.5,
a: 0.5,
}),
store: true,
},
}],
depth_stencil_attachment: None,
});
rpass.set_pipeline(self.render_pipeline.as_ref().unwrap());
rpass.draw(0..3, 0..1);
}
gpu.queue.submit(Some(encoder.finish()));
}
Ok(())
}
#[cfg(not(target_os = "macos"))]
fn fix_transparency(&mut self, _: &Window) {}
#[cfg(target_os = "macos")]
fn fix_transparency(&mut self, win: &Window) {
if let RawWindowHandle::MacOS(h) = win.raw_window_handle() {
use cocoa::base::{id, NO};
use objc::*;
unsafe {
// Allow transparency, as the default for Metal is opaque
let layer: id = msg_send![h.ns_view as id, layer];
let () = msg_send![layer, setOpaque: NO];
}
}
}
fn resize(&mut self, dims: Dimensions) {
if self.dims == dims {
// May just be a move event
return;
}
self.dims = dims;
if let Some(gpu) = self.gpu.as_mut() {
gpu.sc_desc.width = dims.pixel_width as u32;
gpu.sc_desc.height = dims.pixel_height as u32;
gpu.swap_chain = gpu.device.create_swap_chain(&gpu.surface, &gpu.sc_desc);
}
}
fn dispatch(&mut self, event: WindowEvent, win: &Window) {
match event {
WindowEvent::CloseRequested => {
eprintln!("can I close?");
if self.allow_close {
win.close();
} else {
self.allow_close = true;
}
}
WindowEvent::Destroyed => {
eprintln!("destroy was called!");
Connection::get().unwrap().terminate_message_loop();
}
WindowEvent::Resized {
dimensions,
window_state: _,
} => {
self.resize(dimensions);
#[cfg(target_os = "macos")]
self.paint(win).unwrap();
}
WindowEvent::MouseEvent(event) => {
self.cursor_pos = event.coords;
win.invalidate();
win.set_cursor(Some(MouseCursor::Arrow));
if event.kind == MouseEventKind::Press(MousePress::Left) {
eprintln!("{:?}", event);
}
}
WindowEvent::KeyEvent(key) => {
eprintln!("{:?}", key);
win.set_cursor(Some(MouseCursor::Text));
win.default_key_processing(key);
}
WindowEvent::NeedRepaint => {
self.paint(win).unwrap();
}
WindowEvent::AppearanceChanged(_)
| WindowEvent::Notification(_)
| WindowEvent::FocusChanged(_) => {}
}
}
}
async fn spawn_window() -> anyhow::Result<()> {
let fontconfig = Rc::new(FontConfiguration::new(
None,
::window::default_dpi() as usize,
)?);
let state = Rc::new(RefCell::new(MyWindow {
allow_close: false,
cursor_pos: Point::new(100, 200),
dims: Dimensions {
pixel_width: 800,
pixel_height: 600,
dpi: 0,
},
gpu: None,
render_pipeline: None,
}));
let cb_state = Rc::clone(&state);
let win = Window::new_window(
"myclass",
"the title",
800,
600,
None,
fontconfig,
move |event, window| {
let mut state = cb_state.borrow_mut();
state.dispatch(event, window)
},
)
.await?;
eprintln!("before show");
win.show();
{
let mut state = state.borrow_mut();
state.enable_wgpu(&win).await?;
}
eprintln!("window is visible, do loop");
Ok(())
}
fn main() -> anyhow::Result<()> {
let _ = pretty_env_logger::formatted_builder()
.filter(Some("wgpu_core"), log::LevelFilter::Error)
.filter(Some("gfx_backend_metal"), log::LevelFilter::Error)
.filter_level(log::LevelFilter::Info)
.try_init();
let conn = Connection::init()?;
spawn(async {
eprintln!("running this async block");
dbg!(spawn_window().await).ok();
eprintln!("end of async block");
})
.detach();
conn.run_message_loop()
}