mirror of
https://github.com/penpot/penpot.git
synced 2025-05-17 20:16:11 +02:00
🎉 Refactor memory managemnt for color linear gradient stops
This commit is contained in:
parent
00ab9ad3f0
commit
a4cfaa542c
3 changed files with 74 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
|||
mod debug;
|
||||
mod images;
|
||||
mod math;
|
||||
pub mod mem;
|
||||
mod render;
|
||||
mod shapes;
|
||||
mod state;
|
||||
|
@ -176,14 +177,34 @@ pub extern "C" fn add_shape_linear_fill(
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct RawStopData {
|
||||
color: [u8; 4],
|
||||
offset: u8,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn add_shape_fill_stop(raw_color: u32, offset: f32) {
|
||||
pub extern "C" fn add_shape_fill_stops(ptr: *mut RawStopData, n_stops: i32) {
|
||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
||||
if let Some(shape) = state.current_shape() {
|
||||
let color = skia::Color::new(raw_color);
|
||||
shape
|
||||
.add_gradient_stop(color, offset)
|
||||
.expect("got no fill or an invalid one");
|
||||
unsafe {
|
||||
let buf = Vec::<RawStopData>::from_raw_parts(ptr, n_stops as usize, n_stops as usize);
|
||||
for raw_stop in buf.iter() {
|
||||
let color = skia::Color::from_argb(
|
||||
raw_stop.color[3],
|
||||
raw_stop.color[0],
|
||||
raw_stop.color[1],
|
||||
raw_stop.color[2],
|
||||
);
|
||||
shape
|
||||
.add_gradient_stop(color, (raw_stop.offset as f32) / 100.)
|
||||
.expect("got no fill or an invalid one");
|
||||
}
|
||||
mem::free(
|
||||
ptr as *mut u8,
|
||||
n_stops as usize * std::mem::size_of::<RawStopData>(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue