Skip to content

Commit

Permalink
fix: memory leak in some blend mode (#1015)
Browse files Browse the repository at this point in the history
* fix: memory leak in some blend mode

By add correct drop handle for SkPicture

* fmt

---------

Co-authored-by: LISPCoC <[email protected]>
  • Loading branch information
Brooooooklyn and lispcoc authored Mar 4, 2025
1 parent 529e96c commit 319f5b2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions skia-c/skia_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,11 @@ extern "C"
return reinterpret_cast<skiac_path *>(new_path);
}

void skiac_picture_destroy(skiac_picture *c_picture)
{
reinterpret_cast<SkPicture *>(c_picture)->unref();
}

// SkPictureRecorder
skiac_picture_recorder *skiac_picture_recorder_create() {
return reinterpret_cast<skiac_picture_recorder *>(new SkPictureRecorder());
Expand Down
1 change: 1 addition & 0 deletions skia-c/skia_c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,7 @@ extern "C"
void skiac_svg_text_to_path(const uint8_t *data, size_t length, skiac_font_collection *c_collection, skiac_sk_data *output_data);

// SkPictureRecorder
void skiac_picture_destroy(skiac_picture *c_picture);
skiac_picture_recorder *skiac_picture_recorder_create();
void skiac_picture_recorder_begin_recording(skiac_picture_recorder *c_picture_recorder, float x, float y, float width, float height);
skiac_canvas *skiac_picture_recorder_get_recording_canvas(skiac_picture_recorder *c_picture_recorder);
Expand Down
9 changes: 9 additions & 0 deletions src/sk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,7 @@ pub mod ffi {
) -> *mut skiac_shader;

pub fn skiac_bitmap_destroy(c_bitmap: *mut skiac_bitmap);
pub fn skiac_picture_destroy(c_picture: *mut skiac_picture);

// SkString
pub fn skiac_delete_sk_string(c_sk_string: *mut skiac_sk_string);
Expand Down Expand Up @@ -3773,6 +3774,14 @@ impl Drop for SkWMemoryStream {
#[derive(Debug)]
pub struct SkPicture(*mut ffi::skiac_picture);

impl Drop for SkPicture {
fn drop(&mut self) {
unsafe {
ffi::skiac_picture_destroy(self.0);
}
}
}

#[derive(Debug)]
pub struct SkPictureRecorder(pub(crate) *mut ffi::skiac_picture_recorder);

Expand Down

0 comments on commit 319f5b2

Please sign in to comment.