-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a Vello back-end with a custom winit viewer.
My first PR! 🎉 You can get Rust with [Rustup](https://rustup.rs). Then run `cargo run --release` in the `vello/` directory. Things left to do before merging: - [x] remove `clap` - [x] add rustfmt & clippy checks to CI - [x] add text support - [x] add README - [ ] add CONTRIBUTING Diffs= abe5aab14 Added a Vello back-end with a custom winit viewer. (#5786) Co-authored-by: Dragoș Tiselice <[email protected]> Co-authored-by: Dragoș Tiselice <[email protected]>
- Loading branch information
1 parent
af58b5a
commit bcf1193
Showing
19 changed files
with
1,798 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
adeebb26a7ac58a1aaa18a40ed9d98af46735c97 | ||
abe5aab1431c34a42458a9650831d6b3a7c39feb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
[package] | ||
name = "rive-vello" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[build-dependencies] | ||
cc = { version = "1.0", features = ["parallel"] } | ||
walkdir = "2.3.3" | ||
|
||
[dependencies] | ||
clap = { version = "4.3.19", features = ["derive"] } | ||
image = "0.24.6" | ||
pollster = "0.3.0" | ||
smallvec = "1.8.0" | ||
vello = { git = "https://github.com/linebender/vello", rev = "3cb5462" } | ||
wgpu = "0.17.0" | ||
winit = "0.28.6" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Vello back-end for Rive | ||
|
||
Small application for viewing `.riv` files rendered with Vello. It uses [winit] | ||
for creating the window and [image] to decode images. | ||
|
||
## Build | ||
|
||
You will need clang, Cargo, and the Rust compiler to build. You can can install | ||
Cargo and rustc using [rustup]. | ||
|
||
To use the application, run: | ||
|
||
```bash | ||
$ cargo run --release | ||
``` | ||
|
||
## Usage | ||
|
||
Drop any `.riv` file into the window to open it. Scroll to control the size of | ||
the grid of copies. | ||
|
||
## Caveats | ||
|
||
The current implementation is a work-in-progress and might exhibit artifacts or | ||
render incorrectly. | ||
|
||
Only tested on macOS for the time being. | ||
|
||
[winit]: https://github.com/rust-windowing/winit | ||
[image]: https://github.com/image-rs/image | ||
[rustup]: https://rustup.rs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
use std::{ | ||
env, | ||
ffi::OsString, | ||
path::{Path, PathBuf}, | ||
process::Command, | ||
}; | ||
|
||
use walkdir::WalkDir; | ||
|
||
const CHECKOUT_DIRECTORY: &str = "target"; | ||
|
||
struct Checkout { | ||
path: PathBuf, | ||
} | ||
|
||
impl Checkout { | ||
pub fn new(repo: &str, tag: &str) -> Self { | ||
let name = repo.rsplit_once('/').expect("URL format invalid").1; | ||
let mut path = PathBuf::from(CHECKOUT_DIRECTORY); | ||
|
||
path.push(name); | ||
|
||
if !path.is_dir() { | ||
Command::new("git") | ||
.args([ | ||
"clone", | ||
"-b", | ||
tag, | ||
repo, | ||
&path.as_os_str().to_string_lossy(), | ||
]) | ||
.output() | ||
.unwrap_or_else(|_| panic!("failed to clone {}; is git CLI available?", name)); | ||
} | ||
|
||
Self { path } | ||
} | ||
|
||
pub fn join<P: AsRef<Path>>(&self, path: P) -> PathBuf { | ||
self.path.join(path) | ||
} | ||
} | ||
|
||
fn all_files_with_extension<P: AsRef<Path>>( | ||
path: P, | ||
extension: &str, | ||
) -> impl Iterator<Item = PathBuf> + '_ { | ||
WalkDir::new(path).into_iter().filter_map(move |entry| { | ||
entry | ||
.ok() | ||
.map(|entry| entry.into_path()) | ||
.filter(|path| path.extension() == Some(&OsString::from(extension))) | ||
}) | ||
} | ||
|
||
fn main() { | ||
println!("cargo:rerun-if-changed=src/vello_renderer.hpp"); | ||
println!("cargo:rerun-if-changed=src/vello_renderer.cpp"); | ||
println!("cargo:rerun-if-changed=src/winit_viewer.cpp"); | ||
|
||
let harfbuzz = Checkout::new("https://github.com/harfbuzz/harfbuzz", "8.1.1"); | ||
let sheen_bidi = Checkout::new("https://github.com/Tehreer/SheenBidi", "v2.6"); | ||
|
||
let target = env::var("TARGET").unwrap(); | ||
let profile = env::var("PROFILE").unwrap(); | ||
|
||
let mut cfg = cc::Build::new(); | ||
cfg.compiler("clang") | ||
.cpp(true) | ||
.flag_if_supported("-std=c++11") // for unix | ||
.warnings(false) | ||
.file(harfbuzz.join("src/harfbuzz.cc")); | ||
|
||
if !target.contains("windows") { | ||
cfg.define("HAVE_PTHREAD", "1"); | ||
} | ||
|
||
if target.contains("apple") && profile.contains("release") { | ||
cfg.define("HAVE_CORETEXT", "1"); | ||
} | ||
|
||
if target.contains("windows") { | ||
cfg.define("HAVE_DIRECTWRITE", "1"); | ||
} | ||
|
||
if target.contains("windows-gnu") { | ||
cfg.flag("-Wa,-mbig-obj"); | ||
} | ||
|
||
cfg.compile("harfbuzz"); | ||
|
||
cc::Build::new() | ||
.compiler("clang") | ||
.files(all_files_with_extension(sheen_bidi.join("Source"), "c")) | ||
.include(sheen_bidi.join("Headers")) | ||
.compile("sheenbidi"); | ||
|
||
cc::Build::new() | ||
.compiler("clang") | ||
.cpp(true) | ||
.files(all_files_with_extension("../src", "cpp")) | ||
.files(all_files_with_extension( | ||
"../viewer/src/viewer_content", | ||
"cpp", | ||
)) | ||
.file("src/vello_renderer.cpp") | ||
.file("src/winit_viewer.cpp") | ||
.include("src") | ||
.include("../include") | ||
.include("../viewer/include") | ||
.include(harfbuzz.join("src")) | ||
.include(sheen_bidi.join("Headers")) | ||
.flag("-std=c++14") | ||
.flag("-Wno-everything") | ||
.define("RIVE_SKIP_IMGUI", None) | ||
.define("WITH_RIVE_TEXT", None) | ||
.compile("rive"); | ||
} |
Oops, something went wrong.