mirror of
https://github.com/penpot/penpot.git
synced 2025-05-14 00:26:37 +02:00
✨ Write shapes directly to wasm memory
This commit is contained in:
parent
29e0964ebc
commit
4623f36042
9 changed files with 186 additions and 139 deletions
|
@ -1,4 +1,5 @@
|
|||
pub mod render;
|
||||
pub mod shapes;
|
||||
|
||||
use skia_safe as skia;
|
||||
|
||||
|
@ -33,6 +34,19 @@ pub unsafe extern "C" fn draw_rect(state: *mut State, x1: f32, y1: f32, x2: f32,
|
|||
render::render_rect(&mut state.surface, r, skia::Color::RED);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn draw_all_shapes(state: *mut State, zoom: f32, pan_x: f32, pan_y: f32) {
|
||||
let state = unsafe { state.as_mut() }.expect("got an invalid state pointer");
|
||||
|
||||
reset_canvas(state);
|
||||
scale(state, zoom, zoom);
|
||||
translate(state, pan_x, pan_y);
|
||||
|
||||
shapes::draw_all(state);
|
||||
|
||||
flush(state);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn flush(state: *mut State) {
|
||||
let state = unsafe { state.as_mut() }.expect("got an invalid state pointer");
|
||||
|
@ -60,6 +74,12 @@ pub unsafe extern "C" fn reset_canvas(state: *mut State) {
|
|||
flush(state);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn shapes_buffer() -> *mut shapes::Shape {
|
||||
let ptr = shapes::SHAPES_BUFFER.as_mut_ptr();
|
||||
return ptr;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
render::init_gl();
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue