remove tiny-skia and replace chunk renderer with a GPU-based one

This commit is contained in:
りき萌 2025-09-05 17:41:25 +02:00
parent 39632f56a7
commit b4c3260f49
10 changed files with 253 additions and 434 deletions

View file

@ -11,7 +11,6 @@ arrayvec = { version = "0.7.4", default-features = false }
dlmalloc = { version = "0.2.6", features = ["global"] }
haku.workspace = true
log.workspace = true
tiny-skia = { workspace = true, features = ["no-std-float"] }
paste = "1.0.15"
[features]

View file

@ -16,10 +16,6 @@ use haku::{
token::Lexis,
};
use log::{debug, info};
use tiny_skia::{
BlendMode, Color, FillRule, LineCap, Paint, PathBuilder, Pixmap, PremultipliedColorU8, Rect,
Shader, Stroke, Transform,
};
pub mod logging;
#[cfg(not(feature = "std"))]
@ -201,147 +197,6 @@ extern "C" fn haku_status_string(code: StatusCode) -> *const i8 {
.as_ptr()
}
struct PixmapCanvas {
pixmap: Pixmap,
pb: PathBuilder,
transform: Transform,
}
#[unsafe(no_mangle)]
extern "C" fn haku_pixmap_new(width: u32, height: u32) -> *mut PixmapCanvas {
let ptr = Box::leak(Box::new(PixmapCanvas {
pixmap: Pixmap::new(width, height).expect("invalid pixmap size"),
pb: PathBuilder::new(),
transform: Transform::identity(),
})) as *mut _;
debug!("created pixmap with size {width}x{height}: {ptr:?}");
ptr
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_pixmap_destroy(c: *mut PixmapCanvas) {
debug!("destroying pixmap: {c:?}");
drop(Box::from_raw(c))
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_pixmap_data(c: *mut PixmapCanvas) -> *mut u8 {
let c = &mut *c;
c.pixmap.pixels_mut().as_mut_ptr() as *mut u8
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_pixmap_clear(c: *mut PixmapCanvas) {
let c = &mut *c;
c.pixmap
.pixels_mut()
.fill(PremultipliedColorU8::TRANSPARENT);
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_pixmap_set_translation(c: *mut PixmapCanvas, x: f32, y: f32) {
let c = &mut *c;
c.transform = Transform::from_translate(x, y);
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_pixmap_begin(c: *mut PixmapCanvas) -> bool {
let c = &mut *c;
c.pb.clear();
true
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_pixmap_line(
c: *mut PixmapCanvas,
x1: f32,
y1: f32,
x2: f32,
y2: f32,
) -> bool {
let c = &mut *c;
c.pb.move_to(x1, y1);
c.pb.line_to(x2, y2);
true
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_pixmap_rectangle(
c: *mut PixmapCanvas,
x: f32,
y: f32,
width: f32,
height: f32,
) -> bool {
let c = &mut *c;
if let Some(rect) = Rect::from_xywh(x, y, width, height) {
c.pb.push_rect(rect);
}
true
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_pixmap_circle(c: *mut PixmapCanvas, x: f32, y: f32, r: f32) -> bool {
let c = &mut *c;
c.pb.push_circle(x, y, r);
true
}
fn default_paint() -> Paint<'static> {
Paint {
shader: Shader::SolidColor(Color::BLACK),
blend_mode: BlendMode::SourceOver,
anti_alias: false,
force_hq_pipeline: false,
}
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_pixmap_fill(c: *mut PixmapCanvas, r: u8, g: u8, b: u8, a: u8) -> bool {
let c = &mut *c;
let pb = mem::take(&mut c.pb);
if let Some(path) = pb.finish() {
let paint = Paint {
shader: Shader::SolidColor(Color::from_rgba8(r, g, b, a)),
..default_paint()
};
c.pixmap
.fill_path(&path, &paint, FillRule::EvenOdd, c.transform, None);
}
true
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_pixmap_stroke(
c: *mut PixmapCanvas,
r: u8,
g: u8,
b: u8,
a: u8,
thickness: f32,
) -> bool {
let c = &mut *c;
let pb = mem::take(&mut c.pb);
if let Some(path) = pb.finish() {
let paint = Paint {
shader: Shader::SolidColor(Color::from_rgba8(r, g, b, a)),
..default_paint()
};
c.pixmap.stroke_path(
&path,
&paint,
&Stroke {
width: thickness,
line_cap: LineCap::Round,
..Default::default()
},
c.transform,
None,
);
}
true
}
#[unsafe(no_mangle)]
unsafe extern "C" fn haku_compile_brush(
instance: *mut Instance,