Bug 1880312 - Update aa-stroke to add api for filled_circle. r=lsalzman

Differential Revision: https://phabricator.services.mozilla.com/D201830
This commit is contained in:
Jeff Muizelaar 2024-02-14 16:14:27 +00:00
Родитель a242ac1c0f
Коммит f15dd4c9d7
6 изменённых файлов: 80 добавлений и 6 удалений

Просмотреть файл

@ -5,9 +5,9 @@
[source.crates-io]
replace-with = "vendored-sources"
[source."git+https://github.com/FirefoxGraphics/aa-stroke?rev=ed4206ea11703580cd1d4fc63371a527b29d8252"]
[source."git+https://github.com/FirefoxGraphics/aa-stroke?rev=96e66f91bb8e8efb80ff144eabd668002aa89650"]
git = "https://github.com/FirefoxGraphics/aa-stroke"
rev = "ed4206ea11703580cd1d4fc63371a527b29d8252"
rev = "96e66f91bb8e8efb80ff144eabd668002aa89650"
replace-with = "vendored-sources"
[source."git+https://github.com/FirefoxGraphics/wpf-gpu-raster?rev=99979da091fd58fba8477e7fcdf5ec0727102916"]

2
Cargo.lock сгенерированный
Просмотреть файл

@ -5,7 +5,7 @@ version = 3
[[package]]
name = "aa-stroke"
version = "0.1.0"
source = "git+https://github.com/FirefoxGraphics/aa-stroke?rev=ed4206ea11703580cd1d4fc63371a527b29d8252#ed4206ea11703580cd1d4fc63371a527b29d8252"
source = "git+https://github.com/FirefoxGraphics/aa-stroke?rev=96e66f91bb8e8efb80ff144eabd668002aa89650#96e66f91bb8e8efb80ff144eabd668002aa89650"
dependencies = [
"euclid",
]

Просмотреть файл

@ -1 +1 @@
{"files":{".github/workflows/rust.yml":"6a9f1b122ea02367a2f1ff1fc7b9a728284ceb47fad12e1610cde9d760f4efc3","Cargo.toml":"f507cac11c3c26af28420d68ec3748a5453322d51ef1379a340fdd3b1c9b187a","README.md":"60b34cfa653114d5054009696df2ed2ea1d4926a6bc312d0cac4b84845c2beff","examples/simple.rs":"c196e79568fe4be31a08374aa451c70c9377db5428aef924a985e069c12ed91e","src/bezierflattener.rs":"61687da22490cb1bd901d0b5eb1de3a98802b46c03719ded4163c7a4997f0ad9","src/c_bindings.rs":"7cc3916665a89b8dc1eb1d1ddd2c966e6ece06dba04d228a8ebd807fb2270345","src/lib.rs":"9719ba050cc0ff6093c60646321f0cbedd06d6483106119bd9ca05d6e42ddaae","src/tri_rasterize.rs":"fb6f595ab9340d8ea6429b41638c378bbd772c8e4d8f7793e225624c12cd3a21"},"package":null}
{"files":{".github/workflows/rust.yml":"6a9f1b122ea02367a2f1ff1fc7b9a728284ceb47fad12e1610cde9d760f4efc3","Cargo.toml":"f507cac11c3c26af28420d68ec3748a5453322d51ef1379a340fdd3b1c9b187a","README.md":"60b34cfa653114d5054009696df2ed2ea1d4926a6bc312d0cac4b84845c2beff","examples/simple.rs":"c196e79568fe4be31a08374aa451c70c9377db5428aef924a985e069c12ed91e","src/bezierflattener.rs":"61687da22490cb1bd901d0b5eb1de3a98802b46c03719ded4163c7a4997f0ad9","src/c_bindings.rs":"06225ddd132ae959eda1b445f4e375cead4d8e135c5cba81e828815fe6a5e88b","src/lib.rs":"fc7990e62434f3143b5162aba85ea828ceab51447c5fad5e26e8c6b06ec77050","src/tri_rasterize.rs":"fb6f595ab9340d8ea6429b41638c378bbd772c8e4d8f7793e225624c12cd3a21"},"package":null}

49
third_party/rust/aa-stroke/src/c_bindings.rs поставляемый
Просмотреть файл

@ -1,4 +1,4 @@
use crate::{Stroker, StrokeStyle, Point};
use crate::{filled_circle_with_path_builder, PathBuilder, Point, StrokeStyle, Stroker};
type OutputVertex = crate::Vertex;
@ -90,6 +90,31 @@ pub unsafe extern "C" fn aa_stroke_release(s: *mut Stroker) {
drop(Box::from_raw(s));
}
#[no_mangle]
pub extern "C" fn aa_stroke_filled_circle(
cx: f32, cy: f32, radius: f32, output_ptr: *mut OutputVertex, output_capacity: usize
) -> VertexBuffer {
let mut path_builder = PathBuilder::new(1.);
if output_ptr != std::ptr::null_mut() {
let slice = unsafe { std::slice::from_raw_parts_mut(output_ptr, output_capacity) };
path_builder.set_output_buffer(slice);
}
filled_circle_with_path_builder(&mut path_builder, Point::new(cx, cy), radius);
if let Some(output_buffer_size) = path_builder.get_output_buffer_size() {
VertexBuffer {
data: std::ptr::null(),
len: output_buffer_size,
}
} else {
let result = path_builder.finish();
let len = result.len();
let vb = VertexBuffer { data: Box::leak(result).as_ptr(), len };
vb
}
}
#[test]
fn simple() {
@ -120,3 +145,25 @@ fn output_buffer() {
unsafe { aa_stroke_release(s) } ;
}
#[test]
fn filled_circle_output_buffer() {
use crate::Vertex;
let mut output = Vec::new();
output.resize_with(1000, || OutputVertex{x: 0., y: 0., coverage: 0.});
let center = Point::new(100., 100.);
let radius = 33.;
let vb = aa_stroke_filled_circle(center.x, center.y, radius, output.as_mut_ptr(), output.len());
assert_ne!(vb.len, 0);
assert_eq!(vb.data, std::ptr::null());
let result = &output[0..vb.len];
let min_x = result.iter().map(|v: &Vertex| v.x).reduce(|a, b| a.min(b)).unwrap();
let max_x = result.iter().map(|v: &Vertex| v.x).reduce(|a, b| a.max(b)).unwrap();
let min_y = result.iter().map(|v: &Vertex| v.y).reduce(|a, b| a.min(b)).unwrap();
let max_y = result.iter().map(|v: &Vertex| v.y).reduce(|a, b| a.max(b)).unwrap();
assert_eq!(min_x, center.x - (radius + 0.5));
assert_eq!(max_x, center.x + (radius + 0.5));
assert_eq!(min_y, center.y - (radius + 0.5));
assert_eq!(max_y, center.y + (radius + 0.5));
}

27
third_party/rust/aa-stroke/src/lib.rs поставляемый
Просмотреть файл

@ -904,6 +904,33 @@ impl<'z> Stroker<'z> {
}
}
fn filled_circle_with_path_builder(mut path_builder: &mut PathBuilder, center: Point, radius: f32) {
arc(&mut path_builder, center.x, center.y, radius, Vector::new(1., 0.), Vector::new(-1., 0.));
arc(&mut path_builder, center.x, center.y, radius, Vector::new(-1., 0.), Vector::new(1., 0.));
}
/// Returns an anti-aliased triangle mesh for a filled circle.
pub fn filled_circle(center: Point, radius: f32) -> Box<[Vertex]> {
let mut path_builder = PathBuilder::new(1.);
filled_circle_with_path_builder(&mut path_builder, center, radius);
path_builder.finish()
}
#[test]
fn filled_circle_test() {
let center = Point::new(100., 100.);
let radius = 33.;
let result = filled_circle(center, radius);
let min_x = result.iter().map(|v: &Vertex| v.x).reduce(|a, b| a.min(b)).unwrap();
let max_x = result.iter().map(|v: &Vertex| v.x).reduce(|a, b| a.max(b)).unwrap();
let min_y = result.iter().map(|v: &Vertex| v.y).reduce(|a, b| a.min(b)).unwrap();
let max_y = result.iter().map(|v: &Vertex| v.y).reduce(|a, b| a.max(b)).unwrap();
assert_eq!(min_x, center.x - (radius + 0.5));
assert_eq!(max_x, center.x + (radius + 0.5));
assert_eq!(min_y, center.y - (radius + 0.5));
assert_eq!(max_y, center.y + (radius + 0.5));
}
#[test]
fn simple() {
let mut stroker = Stroker::new(&StrokeStyle{

Просмотреть файл

@ -101,7 +101,7 @@ processtools = { path = "../../../components/processtools" }
qcms = { path = "../../../../gfx/qcms", features = ["c_bindings", "neon"], default-features = false }
wpf-gpu-raster = { git = "https://github.com/FirefoxGraphics/wpf-gpu-raster", rev = "99979da091fd58fba8477e7fcdf5ec0727102916" }
aa-stroke = { git = "https://github.com/FirefoxGraphics/aa-stroke", rev = "ed4206ea11703580cd1d4fc63371a527b29d8252" }
aa-stroke = { git = "https://github.com/FirefoxGraphics/aa-stroke", rev = "96e66f91bb8e8efb80ff144eabd668002aa89650" }
url = "2.5.0"