Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move samples out of piet and into local crate #502

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: run
args: --manifest-path=piet-cairo/Cargo.toml --example=test-picture -- --all --out=cairo_samples --compare=./piet/snapshots/cairo
args: --bin samples-cairo --features cairo -- --all --out=cairo_samples --compare=./piet-test/snapshots/cairo
if: contains(matrix.os, 'ubuntu')

- name: upload failures (ubuntu+cairo)
Expand All @@ -45,7 +45,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: run
args: --manifest-path=piet-coregraphics/Cargo.toml --example=test-picture -- --all --out=coregraphics_samples --compare=./piet/snapshots/coregraphics
args: --bin samples-coregraphics --features coregraphics -- --all --out=coregraphics_samples --compare=./piet-test/snapshots/coregraphics
if: contains(matrix.os, 'macOS')

- name: upload failures (macOS)
Expand All @@ -59,7 +59,7 @@ jobs:
uses: actions-rs/cargo@v1
with:
command: run
args: --manifest-path=piet-direct2d/Cargo.toml --example=test-picture -- --all --out=d2d_samples --compare=./piet/snapshots/d2d
args: --bin samples-direct2d --features direct2d -- --all --out=d2d_samples --compare=./piet-test/snapshots/d2d
if: contains(matrix.os, 'windows')

- name: upload failures (d2d)
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "snapshots"]
path = piet/snapshots
path = piet-test/snapshots
url = https://github.com/linebender/piet-snapshots.git
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Piet uses 'snapshot testing' to verify that changes do not unexpectedly modify
behaviour. During CI, sample pictures are generated by the various `picture_{}`
files in `piet`'s [`samples`] module, and the results are compared against
files in the [`piet-test`] crate, and the results are compared against
previously generated versions.

The previously generated versions are stored in a separate repository,
Expand All @@ -29,6 +29,6 @@ or @raphlinus (or another administrator) to set it up for you.
`piet-snapshots`. Rebasing would cause the revision to be rewritten, which would
mean that the commit referenced by the submodule would no longer exist.

[`samples`]: https://github.com/linebender/piet/tree/master/piet/src/samples
[`piet-test`]: https://github.com/linebender/piet/tree/master/piet-test
[`piet-snapshots`]: https://github.com/linebender/piet-snapshots
[persisting workflow data using artifacts]: https://docs.github.com/en/actions/configuring-and-managing-workflows/persisting-workflow-data-using-artifacts
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ default-members = [
"piet-common",
"piet-web",
"piet-web/examples/basic",
"piet-svg"
"piet-svg",
"piet-test"
]
11 changes: 5 additions & 6 deletions piet-cairo/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
[package]
name = "piet-cairo"
version = "0.5.0"
edition = "2018"
authors = ["Raph Levien <raph.levien@gmail.com>"]
description = "Cairo backend for piet 2D graphics abstraction."
readme = "../README.md"
license = "MIT/Apache-2.0"
repository = "https://github.com/linebender/piet"
readme = "../README.md"
edition = "2018"
keywords = ["graphics", "2d"]
categories = ["rendering::graphics-api"]

[dependencies]
piet = { version = "=0.5.0", path = "../piet" }

xi-unicode = "0.3.0"
unicode-segmentation = "1.3.0"

cairo-rs = { version = "0.15.1", default-features = false } # We don't need glib
pango = { version = "0.15.2", features = ["v1_44"] }
pangocairo = "0.15.1"
unicode-segmentation = "1.3.0"
xi-unicode = "0.3.0"

[dev-dependencies]
piet = { version = "=0.5.0", path = "../piet", features = ["samples"] }
cairo-rs = { version = "0.15.1", default-features = false, features = ["png"] }
criterion = "0.3"

[[bench]]
Expand Down
5 changes: 3 additions & 2 deletions piet-common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[package]
name = "piet-common"
version = "0.5.0"
edition = "2018"
authors = ["Raph Levien <raph.levien@gmail.com>"]
description = "Selection of a single preferred back-end for piet"
readme = "README.md"
license = "MIT/Apache-2.0"
repository = "https://github.com/linebender/piet"
readme = "README.md"
edition = "2018"
keywords = ["graphics", "2d"]

[features]
Expand Down Expand Up @@ -35,6 +35,7 @@ serde = ["piet/serde"]
[dependencies]
piet = { version = "=0.5.0", path = "../piet" }
piet-web = { version = "=0.5.0", path = "../piet-web", optional = true }

cfg-if = "1.0"
png = { version = "0.17", optional = true }

Expand Down
11 changes: 4 additions & 7 deletions piet-coregraphics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,25 +1,22 @@
[package]
name = "piet-coregraphics"
version = "0.5.0"
edition = "2018"
authors = ["Jeff Muizelaar <jrmuizel@gmail.com>, Raph Levien <raph.levien@gmail.com>, Colin Rofls <colin.rofls@gmail.com>"]
description = "CoreGraphics backend for piet 2D graphics abstraction."
readme = "../README.md"
license = "MIT/Apache-2.0"
repository = "https://github.com/linebender/piet"
readme = "../README.md"
edition = "2018"
keywords = ["graphics", "2d"]
categories = ["rendering::graphics-api"]

[dependencies]
piet = { version = "=0.5.0", path = "../piet" }

associative-cache = "1.0"

foreign-types = "0.3.2"
core-graphics = "0.22.2"
core-text = "19.0.0"
core-foundation = "0.9"
core-foundation-sys = "0.8"
associative-cache = "1.0"

[dev-dependencies]
piet = { version = "=0.5.0", path = "../piet", features = ["samples"] }
png = "0.17"
9 changes: 3 additions & 6 deletions piet-direct2d/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
[package]
name = "piet-direct2d"
version = "0.5.0"
edition = "2018"
authors = ["Raph Levien <raph.levien@gmail.com>"]
description = "Direct2D backend for piet 2D graphics abstraction."
readme = "../README.md"
license = "MIT/Apache-2.0"
repository = "https://github.com/linebender/piet"
readme = "../README.md"
edition = "2018"
keywords = ["graphics", "2d"]
categories = ["rendering::graphics-api"]

[dependencies]
piet = { version = "=0.5.0", path = "../piet" }

utf16_lit = "2.0"
associative-cache = "1.0"

wio = "0.2.2"
winapi = { version = "0.3.8", features = ["d2d1", "d2d1_1", "d2d1effects", "d2dbasetypes", "dcommon", "d3d11", "dxgi", "winnls"] }
dwrote = { version = "0.11.0", default_features = false }

[dev-dependencies]
piet = { version = "=0.5.0", path = "../piet", features = ["samples"] }
image = "0.24.0"
14 changes: 8 additions & 6 deletions piet-svg/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
[package]
name = "piet-svg"
version = "0.5.0"
edition = "2018"
authors = ["Benjamin Saunders <ben.e.saunders@gmail.com>"]
description = "SVG backend for piet 2D graphics abstraction."
edition = "2018"
readme = "../README.md"
license = "MIT/Apache-2.0"
repository = "https://github.com/linebender/piet"
keywords = ["graphics", "2d"]
Expand All @@ -14,13 +15,14 @@ default = []
evcxr = ["evcxr_runtime"]

[dependencies]
piet = { version = "=0.5.0", path = "../piet" }

svg = "0.10.0"
base64 = "0.13.0"
evcxr_runtime = { version = "1.1.0", optional = true }
font-kit = "0.10.1"
image = { version = "0.24.0", default-features = false, features = ["png"] }
piet = { version = "=0.5.0", path = "../piet" }
rustybuzz = "0.4.0"
svg = "0.10.0"
evcxr_runtime = { version = "1.1.0", optional = true }
image = { version = "0.24.0", default-features = false, features = ["png"] }

[dev-dependencies]
piet = { version = "=0.5.0", path = "../piet", features = ["samples"] }
piet-test = { path = "../piet-test" }
3 changes: 2 additions & 1 deletion piet-svg/examples/basic-svg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

use std::io;

use piet::{samples, RenderContext};
use piet::RenderContext;
use piet_test::samples;

fn main() {
let test_picture_number = std::env::args()
Expand Down
37 changes: 37 additions & 0 deletions piet-test/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
[package]
name = "piet-test"
version = "0.0.0"
edition = "2018"
publish = false

[[bin]]
name = "samples-cairo"
required-features = ["cairo"]

[[bin]]
name = "samples-direct2d"
required-features = ["direct2d"]

[[bin]]
name = "samples-coregraphics"
required-features = ["coregraphics"]

[features]
cairo = ["piet-cairo", "cairo-rs"]
direct2d = ["piet-direct2d", "winapi"]
coregraphics = ["piet-coregraphics", "core-graphics"]

[dependencies]
piet = { path = "../piet" }
piet-cairo = { path = "../piet-cairo", optional = true }
piet-direct2d = { path = "../piet-direct2d", optional = true }
piet-coregraphics = { path = "../piet-coregraphics", optional = true }

png = "0.17"
pico-args = "0.4.0"
os_info = { version = "3.0.0", default-features = false }
image = { version = "0.24", default-features = false, features = ["png"] }

core-graphics = { version = "0.22.2", optional = true }
winapi = { version = "0.3.8", features = ["dxgi"], optional = true }
cairo-rs = { version = "0.15.1", default-features = false, features = ["png"], optional = true }
3 changes: 3 additions & 0 deletions piet-test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# piet-test: Sample images and common tests

See [CONTRIBUTING.md](../CONTRIBUTING.md) on instructions on updating the reference snapshots.
1 change: 1 addition & 0 deletions piet-test/snapshots
Submodule snapshots added at b251dc
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ use std::process::Command;

use cairo::{Context, Format, ImageSurface};

use piet::{samples, RenderContext};
use piet::RenderContext;
use piet_cairo::CairoRenderContext;
use piet_test::samples;

const HIDPI: f64 = 2.0;
const FILE_PREFIX: &str = "cairo-test-";

fn main() {
let sys_info = additional_system_info();
samples::samples_main(run_sample, FILE_PREFIX, Some(&sys_info));
samples::samples_main("samples-cairo", run_sample, FILE_PREFIX, Some(&sys_info));
}

fn run_sample(idx: usize, base_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ use core_graphics::color_space::CGColorSpace;
use core_graphics::context::CGContext;

use piet::kurbo::Size;
use piet::{samples, RenderContext};
use piet::RenderContext;
use piet_coregraphics::CoreGraphicsContext;
use piet_test::samples;

const SCALE: f64 = 2.0;
const FILE_PREFIX: &str = "coregraphics-test-";

fn main() {
samples::samples_main(run_sample, FILE_PREFIX, None);
samples::samples_main("samples-coregraphics", run_sample, FILE_PREFIX, None);
}

fn run_sample(idx: usize, base_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
Expand All @@ -33,17 +34,18 @@ fn run_sample(idx: usize, base_dir: &Path) -> Result<(), Box<dyn std::error::Err

piet_context.finish()?;
std::mem::drop(piet_context);
let mut data = cg_ctx.data().to_vec();
let file = File::create(path)?;
let w = BufWriter::new(file);

let mut encoder = png::Encoder::new(w, size.width as u32, size.height as u32);
encoder.set_color(png::ColorType::Rgba);
encoder.set_depth(png::BitDepth::Eight);
let mut writer = encoder.write_header()?;

piet_coregraphics::unpremultiply_rgba(&mut data);
writer.write_image_data(&data).map_err(Into::into)
let mut raw_pixels = cg_ctx.data().to_vec();
piet_coregraphics::unpremultiply_rgba(&mut raw_pixels);

image::save_buffer(
&path,
&raw_pixels,
size.width as u32,
size.height as u32,
image::ColorType::Rgba8,
)?;
Ok(())
}

fn make_cg_ctx(size: Size) -> CGContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use std::path::Path;

use winapi::shared::dxgi::DXGI_MAP_READ;

use piet::{samples, RenderContext};
use piet::RenderContext;
use piet_direct2d::{D2DRenderContext, D2DText};
use piet_test::samples;

const HIDPI: f32 = 2.0;
const FILE_PREFIX: &str = "d2d-test-";

fn main() {
samples::samples_main(run_sample, FILE_PREFIX, None);
samples::samples_main("samples-direct2d", run_sample, FILE_PREFIX, None);
}

fn run_sample(number: usize, base_dir: &Path) -> Result<(), Box<dyn std::error::Error>> {
Expand Down
1 change: 1 addition & 0 deletions piet-test/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod samples;
Loading