mirror of
https://github.com/penpot/penpot.git
synced 2025-05-25 00:46:11 +02:00
Merge pull request #5992 from penpot/elenatorro-10314-use-mutex-for-static-mut
🔧 Do not use global static mut variables when possible
This commit is contained in:
commit
a361e0b990
6 changed files with 270 additions and 218 deletions
|
@ -264,7 +264,8 @@ RUN set -eux; \
|
||||||
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION --default-host ${rustArch}; \
|
./rustup-init -y --no-modify-path --profile minimal --default-toolchain $RUST_VERSION --default-host ${rustArch}; \
|
||||||
rm rustup-init; \
|
rm rustup-init; \
|
||||||
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
|
chmod -R a+w $RUSTUP_HOME $CARGO_HOME; \
|
||||||
rustup component add rustfmt;
|
rustup component add rustfmt; \
|
||||||
|
rustup component add clippy;
|
||||||
|
|
||||||
WORKDIR /usr/local
|
WORKDIR /usr/local
|
||||||
|
|
||||||
|
|
50
render-wasm/lint
Executable file
50
render-wasm/lint
Executable file
|
@ -0,0 +1,50 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
# Enable debugging if the script is run with --debug
|
||||||
|
if [[ "$1" == "--debug" ]]; then
|
||||||
|
set -x
|
||||||
|
fi
|
||||||
|
|
||||||
|
. ./_build_env
|
||||||
|
|
||||||
|
ALLOWED_RULES="
|
||||||
|
-A clippy::box_collection \
|
||||||
|
-A clippy::clone_on_copy \
|
||||||
|
-A clippy::derivable_impls \
|
||||||
|
-A clippy::enum_variant_names \
|
||||||
|
-A clippy::field_reassign_with_default \
|
||||||
|
-A clippy::from_over_into \
|
||||||
|
-A clippy::len_zero \
|
||||||
|
-A clippy::manual_map \
|
||||||
|
-A clippy::map_entry \
|
||||||
|
-A clippy::missing_safety_doc \
|
||||||
|
-A clippy::missing_transmute_annotations \
|
||||||
|
-A clippy::needless_borrow \
|
||||||
|
-A clippy::needless_borrows_for_generic_args \
|
||||||
|
-A clippy::needless_range_loop \
|
||||||
|
-A clippy::needless_return \
|
||||||
|
-A clippy::redundant_closure \
|
||||||
|
-A clippy::redundant_field_names \
|
||||||
|
-A clippy::single_match \
|
||||||
|
-A clippy::slow_vector_initialization \
|
||||||
|
-A clippy::too_many_arguments \
|
||||||
|
-A clippy::unnecessary_to_owned \
|
||||||
|
-A clippy::unused_unit \
|
||||||
|
-A clippy::unwrap_or_default \
|
||||||
|
-A clippy::useless_format \
|
||||||
|
-A clippy::wrong_self_convention \
|
||||||
|
-A dead_code"
|
||||||
|
|
||||||
|
# ./lint --fix
|
||||||
|
if [[ "$1" == "--fix" ]]; then
|
||||||
|
cargo clippy \
|
||||||
|
--fix --allow-dirty \
|
||||||
|
--target=wasm32-unknown-emscripten \
|
||||||
|
-- -D warnings \
|
||||||
|
$ALLOWED_RULES
|
||||||
|
else
|
||||||
|
cargo clippy \
|
||||||
|
--target=wasm32-unknown-emscripten \
|
||||||
|
-- -D warnings \
|
||||||
|
$ALLOWED_RULES
|
||||||
|
fi
|
|
@ -24,6 +24,22 @@ extern "C" {
|
||||||
) -> *const ::std::os::raw::c_void;
|
) -> *const ::std::os::raw::c_void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! with_state {
|
||||||
|
($state:ident, $block:block) => {
|
||||||
|
let $state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
||||||
|
$block
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
macro_rules! with_current_shape {
|
||||||
|
($state:ident, |$shape:ident: &mut Shape| $block:block) => {
|
||||||
|
let $state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
||||||
|
if let Some($shape) = $state.current_shape() {
|
||||||
|
$block
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
fn init_gl() {
|
fn init_gl() {
|
||||||
unsafe {
|
unsafe {
|
||||||
gl::load_with(|addr| {
|
gl::load_with(|addr| {
|
||||||
|
@ -50,167 +66,167 @@ pub extern "C" fn clean_up() {
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn clear_cache() {
|
pub extern "C" fn clear_cache() {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
let render_state = state.render_state();
|
let render_state = state.render_state();
|
||||||
render_state.clear_cache();
|
render_state.clear_cache();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_render_options(debug: u32, dpr: f32) {
|
pub extern "C" fn set_render_options(debug: u32, dpr: f32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
let render_state = state.render_state();
|
let render_state = state.render_state();
|
||||||
|
|
||||||
render_state.set_debug_flags(debug);
|
render_state.set_debug_flags(debug);
|
||||||
render_state.set_dpr(dpr);
|
render_state.set_dpr(dpr);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_canvas_background(raw_color: u32) {
|
pub extern "C" fn set_canvas_background(raw_color: u32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_state!(state, {
|
||||||
let color = skia::Color::new(raw_color);
|
let color = skia::Color::new(raw_color);
|
||||||
state.set_background_color(color);
|
state.set_background_color(color);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn render(timestamp: i32) {
|
pub extern "C" fn render(timestamp: i32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
state.start_render_loop(timestamp).expect("Error rendering");
|
state.start_render_loop(timestamp).expect("Error rendering");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn render_from_cache() {
|
pub extern "C" fn render_from_cache() {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
state.render_from_cache();
|
state.render_from_cache();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn process_animation_frame(timestamp: i32) {
|
pub extern "C" fn process_animation_frame(timestamp: i32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
state
|
state
|
||||||
.process_animation_frame(timestamp)
|
.process_animation_frame(timestamp)
|
||||||
.expect("Error processing animation frame");
|
.expect("Error processing animation frame");
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn reset_canvas() {
|
pub extern "C" fn reset_canvas() {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
state.render_state().reset_canvas();
|
state.render_state().reset_canvas();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn resize_viewbox(width: i32, height: i32) {
|
pub extern "C" fn resize_viewbox(width: i32, height: i32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
state.resize(width, height);
|
state.resize(width, height);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_view(zoom: f32, x: f32, y: f32) {
|
pub extern "C" fn set_view(zoom: f32, x: f32, y: f32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
let render_state = state.render_state();
|
let render_state = state.render_state();
|
||||||
render_state.invalidate_cache_if_needed();
|
render_state.invalidate_cache_if_needed();
|
||||||
render_state.viewbox.set_all(zoom, x, y);
|
render_state.viewbox.set_all(zoom, x, y);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_view_zoom(zoom: f32) {
|
pub extern "C" fn set_view_zoom(zoom: f32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
state.render_state().viewbox.set_zoom(zoom);
|
state.render_state().viewbox.set_zoom(zoom);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_view_xy(x: f32, y: f32) {
|
pub extern "C" fn set_view_xy(x: f32, y: f32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
state.render_state().viewbox.set_pan_xy(x, y);
|
state.render_state().viewbox.set_pan_xy(x, y);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn use_shape(a: u32, b: u32, c: u32, d: u32) {
|
pub extern "C" fn use_shape(a: u32, b: u32, c: u32, d: u32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||||
state.use_shape(id);
|
state.use_shape(id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_masked_group(masked: bool) {
|
pub extern "C" fn set_shape_masked_group(masked: bool) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_masked(masked);
|
shape.set_masked(masked);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_bool_type(raw_bool_type: u8) {
|
pub extern "C" fn set_shape_bool_type(raw_bool_type: u8) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
shape.set_bool_type(BoolType::from(raw_bool_type));
|
||||||
shape.set_bool_type(BoolType::from(raw_bool_type))
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub unsafe extern "C" fn set_shape_type(shape_type: u8) {
|
pub unsafe extern "C" fn set_shape_type(shape_type: u8) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
|
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_shape_type(Type::from(shape_type));
|
shape.set_shape_type(Type::from(shape_type));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_selrect(left: f32, top: f32, right: f32, bottom: f32) {
|
pub extern "C" fn set_shape_selrect(left: f32, top: f32, right: f32, bottom: f32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_selrect(left, top, right, bottom);
|
shape.set_selrect(left, top, right, bottom);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_clip_content(clip_content: bool) {
|
pub extern "C" fn set_shape_clip_content(clip_content: bool) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_clip(clip_content);
|
shape.set_clip(clip_content);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_rotation(rotation: f32) {
|
pub extern "C" fn set_shape_rotation(rotation: f32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_rotation(rotation);
|
shape.set_rotation(rotation);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_transform(a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) {
|
pub extern "C" fn set_shape_transform(a: f32, b: f32, c: f32, d: f32, e: f32, f: f32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_transform(a, b, c, d, e, f);
|
shape.set_transform(a, b, c, d, e, f);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn add_shape_child(a: u32, b: u32, c: u32, d: u32) {
|
pub extern "C" fn add_shape_child(a: u32, b: u32, c: u32, d: u32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.add_child(id);
|
shape.add_child(id);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn clear_shape_children() {
|
pub extern "C" fn clear_shape_children() {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.clear_children();
|
shape.clear_children();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn add_shape_solid_fill(raw_color: u32) {
|
pub extern "C" fn add_shape_solid_fill(raw_color: u32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
let color = skia::Color::new(raw_color);
|
let color = skia::Color::new(raw_color);
|
||||||
shape.add_fill(shapes::Fill::Solid(color));
|
shape.add_fill(shapes::Fill::Solid(color));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -221,14 +237,13 @@ pub extern "C" fn add_shape_linear_fill(
|
||||||
end_y: f32,
|
end_y: f32,
|
||||||
opacity: f32,
|
opacity: f32,
|
||||||
) {
|
) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.add_fill(shapes::Fill::new_linear_gradient(
|
shape.add_fill(shapes::Fill::new_linear_gradient(
|
||||||
(start_x, start_y),
|
(start_x, start_y),
|
||||||
(end_x, end_y),
|
(end_x, end_y),
|
||||||
opacity,
|
opacity,
|
||||||
))
|
));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -240,15 +255,14 @@ pub extern "C" fn add_shape_radial_fill(
|
||||||
opacity: f32,
|
opacity: f32,
|
||||||
width: f32,
|
width: f32,
|
||||||
) {
|
) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.add_fill(shapes::Fill::new_radial_gradient(
|
shape.add_fill(shapes::Fill::new_radial_gradient(
|
||||||
(start_x, start_y),
|
(start_x, start_y),
|
||||||
(end_x, end_y),
|
(end_x, end_y),
|
||||||
opacity,
|
opacity,
|
||||||
width,
|
width,
|
||||||
))
|
));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -260,22 +274,24 @@ pub extern "C" fn add_shape_fill_stops() {
|
||||||
.map(|data| shapes::RawStopData::from_bytes(data.try_into().unwrap()))
|
.map(|data| shapes::RawStopData::from_bytes(data.try_into().unwrap()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
|
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape
|
shape
|
||||||
.add_fill_gradient_stops(entries)
|
.add_fill_gradient_stops(entries)
|
||||||
.expect("could not add gradient stops");
|
.expect("could not add gradient stops");
|
||||||
}
|
});
|
||||||
|
|
||||||
mem::free_bytes();
|
mem::free_bytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn store_font(family_name_size: u32, font_size: u32) {
|
pub extern "C" fn store_font(family_name_size: u32, font_size: u32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
unsafe {
|
unsafe {
|
||||||
let font_bytes =
|
let font_bytes = Vec::<u8>::from_raw_parts(
|
||||||
Vec::<u8>::from_raw_parts(mem::buffer_ptr(), font_size as usize, font_size as usize);
|
mem::buffer_ptr(),
|
||||||
|
font_size as usize,
|
||||||
|
font_size as usize,
|
||||||
|
);
|
||||||
let family_name = String::from_raw_parts(
|
let family_name = String::from_raw_parts(
|
||||||
mem::buffer_ptr().add(font_size as usize),
|
mem::buffer_ptr().add(font_size as usize),
|
||||||
family_name_size as usize,
|
family_name_size as usize,
|
||||||
|
@ -289,11 +305,12 @@ pub extern "C" fn store_font(family_name_size: u32, font_size: u32) {
|
||||||
}
|
}
|
||||||
mem::free_bytes();
|
mem::free_bytes();
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn store_image(a: u32, b: u32, c: u32, d: u32) {
|
pub extern "C" fn store_image(a: u32, b: u32, c: u32, d: u32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||||
let image_bytes = mem::bytes();
|
let image_bytes = mem::bytes();
|
||||||
|
|
||||||
|
@ -305,13 +322,15 @@ pub extern "C" fn store_image(a: u32, b: u32, c: u32, d: u32) {
|
||||||
}
|
}
|
||||||
|
|
||||||
mem::free_bytes();
|
mem::free_bytes();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn is_image_cached(a: u32, b: u32, c: u32, d: u32) -> bool {
|
pub extern "C" fn is_image_cached(a: u32, b: u32, c: u32, d: u32) -> bool {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_state!(state, {
|
||||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||||
state.render_state().has_image(&id)
|
return state.render_state().has_image(&id);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -324,29 +343,26 @@ pub extern "C" fn add_shape_image_fill(
|
||||||
width: i32,
|
width: i32,
|
||||||
height: i32,
|
height: i32,
|
||||||
) {
|
) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.add_fill(shapes::Fill::new_image_fill(
|
shape.add_fill(shapes::Fill::new_image_fill(
|
||||||
id,
|
id,
|
||||||
(alpha * 0xff as f32).floor() as u8,
|
(alpha * 0xff as f32).floor() as u8,
|
||||||
(width, height),
|
(width, height),
|
||||||
));
|
));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn clear_shape_fills() {
|
pub extern "C" fn clear_shape_fills() {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.clear_fills();
|
shape.clear_fills();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_svg_raw_content() {
|
pub extern "C" fn set_shape_svg_raw_content() {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
let bytes = mem::bytes();
|
let bytes = mem::bytes();
|
||||||
let svg_raw_content = String::from_utf8(bytes)
|
let svg_raw_content = String::from_utf8(bytes)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -355,62 +371,54 @@ pub extern "C" fn set_shape_svg_raw_content() {
|
||||||
shape
|
shape
|
||||||
.set_svg_raw_content(svg_raw_content)
|
.set_svg_raw_content(svg_raw_content)
|
||||||
.expect("Failed to set svg raw content");
|
.expect("Failed to set svg raw content");
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_blend_mode(mode: i32) {
|
pub extern "C" fn set_shape_blend_mode(mode: i32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_blend_mode(render::BlendMode::from(mode));
|
shape.set_blend_mode(render::BlendMode::from(mode));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_opacity(opacity: f32) {
|
pub extern "C" fn set_shape_opacity(opacity: f32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_opacity(opacity);
|
shape.set_opacity(opacity);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_constraint_h(constraint: u8) {
|
pub extern "C" fn set_shape_constraint_h(constraint: u8) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
shape.set_constraint_h(ConstraintH::from(constraint));
|
||||||
shape.set_constraint_h(ConstraintH::from(constraint))
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_constraint_v(constraint: u8) {
|
pub extern "C" fn set_shape_constraint_v(constraint: u8) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
shape.set_constraint_v(ConstraintV::from(constraint));
|
||||||
shape.set_constraint_v(ConstraintV::from(constraint))
|
});
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_hidden(hidden: bool) {
|
pub extern "C" fn set_shape_hidden(hidden: bool) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_hidden(hidden);
|
shape.set_hidden(hidden);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_blur(blur_type: u8, hidden: bool, value: f32) {
|
pub extern "C" fn set_shape_blur(blur_type: u8, hidden: bool, value: f32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_blur(blur_type, hidden, value);
|
shape.set_blur(blur_type, hidden, value);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_path_content() {
|
pub extern "C" fn set_shape_path_content() {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
|
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
let bytes = mem::bytes();
|
let bytes = mem::bytes();
|
||||||
let raw_segments = bytes
|
let raw_segments = bytes
|
||||||
.chunks(size_of::<shapes::RawPathData>())
|
.chunks(size_of::<shapes::RawPathData>())
|
||||||
|
@ -419,48 +427,44 @@ pub extern "C" fn set_shape_path_content() {
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
shape.set_path_segments(raw_segments).unwrap();
|
shape.set_path_segments(raw_segments).unwrap();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn add_shape_center_stroke(width: f32, style: u8, cap_start: u8, cap_end: u8) {
|
pub extern "C" fn add_shape_center_stroke(width: f32, style: u8, cap_start: u8, cap_end: u8) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.add_stroke(shapes::Stroke::new_center_stroke(
|
shape.add_stroke(shapes::Stroke::new_center_stroke(
|
||||||
width, style, cap_start, cap_end,
|
width, style, cap_start, cap_end,
|
||||||
));
|
));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn add_shape_inner_stroke(width: f32, style: u8, cap_start: u8, cap_end: u8) {
|
pub extern "C" fn add_shape_inner_stroke(width: f32, style: u8, cap_start: u8, cap_end: u8) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.add_stroke(shapes::Stroke::new_inner_stroke(
|
shape.add_stroke(shapes::Stroke::new_inner_stroke(
|
||||||
width, style, cap_start, cap_end,
|
width, style, cap_start, cap_end,
|
||||||
))
|
));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn add_shape_outer_stroke(width: f32, style: u8, cap_start: u8, cap_end: u8) {
|
pub extern "C" fn add_shape_outer_stroke(width: f32, style: u8, cap_start: u8, cap_end: u8) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.add_stroke(shapes::Stroke::new_outer_stroke(
|
shape.add_stroke(shapes::Stroke::new_outer_stroke(
|
||||||
width, style, cap_start, cap_end,
|
width, style, cap_start, cap_end,
|
||||||
))
|
));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn add_shape_stroke_solid_fill(raw_color: u32) {
|
pub extern "C" fn add_shape_stroke_solid_fill(raw_color: u32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
let color = skia::Color::new(raw_color);
|
let color = skia::Color::new(raw_color);
|
||||||
shape
|
shape
|
||||||
.set_stroke_fill(shapes::Fill::Solid(color))
|
.set_stroke_fill(shapes::Fill::Solid(color))
|
||||||
.expect("could not add stroke solid fill");
|
.expect("could not add stroke solid fill");
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -471,8 +475,7 @@ pub extern "C" fn add_shape_stroke_linear_fill(
|
||||||
end_y: f32,
|
end_y: f32,
|
||||||
opacity: f32,
|
opacity: f32,
|
||||||
) {
|
) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape
|
shape
|
||||||
.set_stroke_fill(shapes::Fill::new_linear_gradient(
|
.set_stroke_fill(shapes::Fill::new_linear_gradient(
|
||||||
(start_x, start_y),
|
(start_x, start_y),
|
||||||
|
@ -480,7 +483,7 @@ pub extern "C" fn add_shape_stroke_linear_fill(
|
||||||
opacity,
|
opacity,
|
||||||
))
|
))
|
||||||
.expect("could not add stroke linear fill");
|
.expect("could not add stroke linear fill");
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -492,8 +495,7 @@ pub extern "C" fn add_shape_stroke_radial_fill(
|
||||||
opacity: f32,
|
opacity: f32,
|
||||||
width: f32,
|
width: f32,
|
||||||
) {
|
) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape
|
shape
|
||||||
.set_stroke_fill(shapes::Fill::new_radial_gradient(
|
.set_stroke_fill(shapes::Fill::new_radial_gradient(
|
||||||
(start_x, start_y),
|
(start_x, start_y),
|
||||||
|
@ -502,7 +504,7 @@ pub extern "C" fn add_shape_stroke_radial_fill(
|
||||||
width,
|
width,
|
||||||
))
|
))
|
||||||
.expect("could not add stroke radial fill");
|
.expect("could not add stroke radial fill");
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -514,13 +516,12 @@ pub extern "C" fn add_shape_stroke_stops() {
|
||||||
.map(|data| shapes::RawStopData::from_bytes(data.try_into().unwrap()))
|
.map(|data| shapes::RawStopData::from_bytes(data.try_into().unwrap()))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
|
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape
|
shape
|
||||||
.add_stroke_gradient_stops(entries)
|
.add_stroke_gradient_stops(entries)
|
||||||
.expect("could not add gradient stops");
|
.expect("could not add gradient stops");
|
||||||
}
|
});
|
||||||
|
|
||||||
mem::free_bytes();
|
mem::free_bytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,9 +553,8 @@ pub extern "C" fn add_shape_image_stroke(
|
||||||
width: i32,
|
width: i32,
|
||||||
height: i32,
|
height: i32,
|
||||||
) {
|
) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
let id = uuid_from_u32_quartet(a, b, c, d);
|
let id = uuid_from_u32_quartet(a, b, c, d);
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape
|
shape
|
||||||
.set_stroke_fill(shapes::Fill::new_image_fill(
|
.set_stroke_fill(shapes::Fill::new_image_fill(
|
||||||
id,
|
id,
|
||||||
|
@ -562,30 +562,26 @@ pub extern "C" fn add_shape_image_stroke(
|
||||||
(width, height),
|
(width, height),
|
||||||
))
|
))
|
||||||
.expect("could not add stroke image fill");
|
.expect("could not add stroke image fill");
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn clear_shape_strokes() {
|
pub extern "C" fn clear_shape_strokes() {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.clear_strokes();
|
shape.clear_strokes();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_corners(r1: f32, r2: f32, r3: f32, r4: f32) {
|
pub extern "C" fn set_shape_corners(r1: f32, r2: f32, r3: f32, r4: f32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_corners((r1, r2, r3, r4));
|
shape.set_corners((r1, r2, r3, r4));
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn set_shape_path_attrs(num_attrs: u32) {
|
pub extern "C" fn set_shape_path_attrs(num_attrs: u32) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("Got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
|
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
let bytes = mem::bytes();
|
let bytes = mem::bytes();
|
||||||
let mut start = 0;
|
let mut start = 0;
|
||||||
for _ in 0..num_attrs {
|
for _ in 0..num_attrs {
|
||||||
|
@ -593,7 +589,7 @@ pub extern "C" fn set_shape_path_attrs(num_attrs: u32) {
|
||||||
let value = extract_string(&mut start, &bytes);
|
let value = extract_string(&mut start, &bytes);
|
||||||
shape.set_path_attr(name, value);
|
shape.set_path_attr(name, value);
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -632,7 +628,7 @@ pub extern "C" fn set_modifiers() {
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
state.modifiers.insert(entry.id, entry.transform);
|
state.modifiers.insert(entry.id, entry.transform);
|
||||||
}
|
}
|
||||||
state.render_state.clear_cache();
|
state.render_state().clear_cache();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -645,21 +641,19 @@ pub extern "C" fn add_shape_shadow(
|
||||||
raw_style: u8,
|
raw_style: u8,
|
||||||
hidden: bool,
|
hidden: bool,
|
||||||
) {
|
) {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
let color = skia::Color::new(raw_color);
|
let color = skia::Color::new(raw_color);
|
||||||
let style = shapes::ShadowStyle::from(raw_style);
|
let style = shapes::ShadowStyle::from(raw_style);
|
||||||
let shadow = shapes::Shadow::new(color, blur, spread, (x, y), style, hidden);
|
let shadow = shapes::Shadow::new(color, blur, spread, (x, y), style, hidden);
|
||||||
shape.add_shadow(shadow);
|
shape.add_shadow(shadow);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn clear_shape_shadows() {
|
pub extern "C" fn clear_shape_shadows() {
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.clear_shadows();
|
shape.clear_shadows();
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -684,8 +678,7 @@ pub extern "C" fn set_flex_layout_data(
|
||||||
let justify_content = shapes::JustifyContent::from_u8(justify_content);
|
let justify_content = shapes::JustifyContent::from_u8(justify_content);
|
||||||
let wrap_type = shapes::WrapType::from_u8(wrap_type);
|
let wrap_type = shapes::WrapType::from_u8(wrap_type);
|
||||||
|
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_flex_layout_data(
|
shape.set_flex_layout_data(
|
||||||
dir,
|
dir,
|
||||||
row_gap,
|
row_gap,
|
||||||
|
@ -700,7 +693,7 @@ pub extern "C" fn set_flex_layout_data(
|
||||||
padding_bottom,
|
padding_bottom,
|
||||||
padding_left,
|
padding_left,
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
@ -729,8 +722,7 @@ pub extern "C" fn set_layout_child_data(
|
||||||
let max_w = if has_max_w { Some(max_w) } else { None };
|
let max_w = if has_max_w { Some(max_w) } else { None };
|
||||||
let min_w = if has_min_w { Some(min_w) } else { None };
|
let min_w = if has_min_w { Some(min_w) } else { None };
|
||||||
|
|
||||||
let state = unsafe { STATE.as_mut() }.expect("got an invalid state pointer");
|
with_current_shape!(state, |shape: &mut Shape| {
|
||||||
if let Some(shape) = state.current_shape() {
|
|
||||||
shape.set_flex_layout_child_data(
|
shape.set_flex_layout_child_data(
|
||||||
margin_top,
|
margin_top,
|
||||||
margin_right,
|
margin_right,
|
||||||
|
@ -745,7 +737,7 @@ pub extern "C" fn set_layout_child_data(
|
||||||
is_absolute,
|
is_absolute,
|
||||||
z_index,
|
z_index,
|
||||||
);
|
);
|
||||||
}
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
|
|
|
@ -1,47 +1,57 @@
|
||||||
static mut BUFFERU8: Option<Box<Vec<u8>>> = None;
|
use std::sync::Mutex;
|
||||||
|
|
||||||
|
static BUFFERU8: Mutex<Option<Box<Vec<u8>>>> = Mutex::new(None);
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn alloc_bytes(len: usize) -> *mut u8 {
|
pub extern "C" fn alloc_bytes(len: usize) -> *mut u8 {
|
||||||
// TODO: Figure out how to deal with Result<T> from Emscripten
|
let mut guard = BUFFERU8.lock().unwrap();
|
||||||
if unsafe { BUFFERU8.is_some() } {
|
|
||||||
|
if guard.is_some() {
|
||||||
panic!("Bytes already allocated");
|
panic!("Bytes already allocated");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buffer = Box::new(vec![0u8; len]);
|
let mut new_buffer = Box::new(vec![0u8; len]);
|
||||||
let ptr = buffer.as_mut_ptr();
|
let ptr = new_buffer.as_mut_ptr();
|
||||||
|
|
||||||
unsafe { BUFFERU8 = Some(buffer) };
|
*guard = Some(new_buffer);
|
||||||
return ptr;
|
ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn write_bytes(bytes: Vec<u8>) -> *mut u8 {
|
pub fn write_bytes(bytes: Vec<u8>) -> *mut u8 {
|
||||||
if unsafe { BUFFERU8.is_some() } {
|
let mut guard = BUFFERU8.lock().unwrap();
|
||||||
|
|
||||||
|
if guard.is_some() {
|
||||||
panic!("Bytes already allocated");
|
panic!("Bytes already allocated");
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut buffer = Box::new(bytes);
|
let mut new_buffer = Box::new(bytes);
|
||||||
let ptr = buffer.as_mut_ptr();
|
let ptr = new_buffer.as_mut_ptr();
|
||||||
|
|
||||||
unsafe { BUFFERU8 = Some(buffer) };
|
*guard = Some(new_buffer);
|
||||||
return ptr;
|
ptr
|
||||||
}
|
}
|
||||||
|
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn free_bytes() {
|
pub extern "C" fn free_bytes() {
|
||||||
if unsafe { BUFFERU8.is_some() } {
|
let mut guard = BUFFERU8.lock().unwrap();
|
||||||
let buffer = unsafe { BUFFERU8.take() }.expect("uninitialized buffer");
|
*guard = None;
|
||||||
std::mem::drop(buffer);
|
std::mem::drop(guard);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn buffer_ptr() -> *mut u8 {
|
pub fn buffer_ptr() -> *mut u8 {
|
||||||
let buffer = unsafe { BUFFERU8.as_mut() }.expect("uninitializied buffer");
|
let guard = BUFFERU8.lock().unwrap();
|
||||||
buffer.as_mut_ptr()
|
|
||||||
|
guard
|
||||||
|
.as_ref()
|
||||||
|
.map_or(std::ptr::null_mut(), |buffer| buffer.as_ptr() as *mut u8)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn bytes() -> Vec<u8> {
|
pub fn bytes() -> Vec<u8> {
|
||||||
let buffer = unsafe { BUFFERU8.take() }.expect("uninitialized buffer");
|
let mut guard = BUFFERU8.lock().unwrap();
|
||||||
*buffer
|
|
||||||
|
guard
|
||||||
|
.take()
|
||||||
|
.map_or_else(|| panic!("Buffer is not initialized"), |buffer| *buffer)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait SerializableResult {
|
pub trait SerializableResult {
|
||||||
|
|
|
@ -458,7 +458,7 @@ impl RenderState {
|
||||||
if self
|
if self
|
||||||
.cached_surface_image
|
.cached_surface_image
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map_or(true, |img| img.invalid)
|
.is_none_or(|img| img.invalid)
|
||||||
{
|
{
|
||||||
self.cached_surface_image = Some(CachedSurfaceImage {
|
self.cached_surface_image = Some(CachedSurfaceImage {
|
||||||
image: self.surfaces.snapshot(SurfaceId::Current),
|
image: self.surfaces.snapshot(SurfaceId::Current),
|
||||||
|
|
|
@ -59,12 +59,11 @@ impl<'a> State<'a> {
|
||||||
let new_shape = Shape::new(id);
|
let new_shape = Shape::new(id);
|
||||||
self.shapes.insert(id, new_shape);
|
self.shapes.insert(id, new_shape);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.current_id = Some(id);
|
self.current_id = Some(id);
|
||||||
self.current_shape = self.shapes.get_mut(&id);
|
self.current_shape = self.shapes.get_mut(&id);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_shape(&'a mut self) -> Option<&'a mut Shape> {
|
pub fn current_shape(&mut self) -> Option<&mut Shape> {
|
||||||
self.current_shape.as_deref_mut()
|
self.current_shape.as_deref_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue