mirror of
https://github.com/penpot/penpot.git
synced 2025-05-23 06:16:11 +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();
|
||||
}
|
||||
|
|
31
render-wasm/src/shapes.rs
Normal file
31
render-wasm/src/shapes.rs
Normal file
|
@ -0,0 +1,31 @@
|
|||
use crate::render::{render_rect, State};
|
||||
use skia_safe as skia;
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub struct Selrect {
|
||||
pub x1: f32,
|
||||
pub y1: f32,
|
||||
pub x2: f32,
|
||||
pub y2: f32,
|
||||
}
|
||||
|
||||
pub type Shape = Selrect; // temp
|
||||
|
||||
pub static mut SHAPES_BUFFER: [Shape; 2048] = [Selrect {
|
||||
x1: 0.0,
|
||||
y1: 0.0,
|
||||
x2: 0.0,
|
||||
y2: 0.0,
|
||||
}; 2048];
|
||||
|
||||
pub(crate) fn draw_all(state: &mut State) {
|
||||
let shapes;
|
||||
unsafe {
|
||||
shapes = SHAPES_BUFFER.iter();
|
||||
}
|
||||
|
||||
for shape in shapes {
|
||||
let r = skia::Rect::new(shape.x1, shape.y1, shape.x2, shape.y2);
|
||||
render_rect(&mut state.surface, r, skia::Color::RED);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue