Skip to content

Commit

Permalink
fix(SVG): don't use unique_ptr (revery-ui#32)
Browse files Browse the repository at this point in the history
* SVG: don't use unique_ptr on MakeFromStream

* SVG: add ref & unref functions

* Patches: update SVG patch

* Patches: fix patch

* Patches: create generate patches script
  • Loading branch information
zbaylin authored Apr 29, 2021
1 parent 9846aa2 commit 526fdf5
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
27 changes: 27 additions & 0 deletions esy/generate_patch_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

generate_patch() {
base_commit=$1
files=$2
output=$3

git diff $base_commit -- $files > $output
}

# SVG patch
svg_base_commit="91c98f63fbb6365fba96b4141faa2d135c818dd9"
svg_files="include/c/sk_svg.h include/c/sk_types.h src/c/sk_svg.cpp src/c/sk_types_priv.h"
svg_output="./patches/svg-c-bindings.patch"
generate_patch "$svg_base_commit" "$svg_files" "$svg_output"

# BUILD.gn patch
build_gn_base_commit="91c98f63fbb6365fba96b4141faa2d135c818dd9"
build_gn_files="BUILD.gn"
build_gn_output="./patches/build-svg.patch"
generate_patch "$build_gn_base_commit" "$build_gn_files" "$build_gn_output"

# Expose SVGDOM patch
expose_svgdom_base_commit="91c98f63fbb6365fba96b4141faa2d135c818dd9"
expose_svgdom_files="experimental/svg/model/SkSVGDOM.h"
expose_svgdom_output="./patches/expose-svgdom.patch"
generate_patch "$expose_svgdom_base_commit" "$expose_svgdom_files" "$expose_svgdom_output"
15 changes: 11 additions & 4 deletions patches/svg-c-bindings.patch
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ index fa24d1ce0d..4cfeda87ed 100644
typedef struct sk_3dview_t sk_3dview_t;

diff --git a/src/c/sk_svg.cpp b/src/c/sk_svg.cpp
index 01799b8799..1a89349784 100644
index 01799b8799..c31d5d4fc8 100644
--- a/src/c/sk_svg.cpp
+++ b/src/c/sk_svg.cpp
@@ -9,6 +9,11 @@
Expand All @@ -46,7 +46,7 @@ index 01799b8799..1a89349784 100644
#include "sk_svg.h"

#include "sk_types_priv.h"
@@ -18,3 +23,26 @@
@@ -18,3 +23,33 @@
sk_canvas_t* sk_svgcanvas_create(const sk_rect_t* bounds, sk_xmlwriter_t* writer) {
return ToCanvas(SkSVGCanvas::Make(*AsRect(bounds), AsXMLWriter(writer)).release());
}
Expand All @@ -69,8 +69,15 @@ index 01799b8799..1a89349784 100644
+}
+
+sk_svgdom_t *sk_svgdom_create_from_stream(sk_stream_t *stream) {
+ std::unique_ptr<SkStream> skstream(AsStream(stream));
+ return ToSVGDOM(SkSVGDOM::MakeFromStream(*skstream).release());
+ return ToSVGDOM(SkSVGDOM::MakeFromStream(*AsStream(stream)).release());
+}
+
+void sk_svgdom_ref(const sk_svgdom_t *svg) {
+ SkSafeRef(AsSVGDOM(svg));
+}
+
+void sk_svgdom_unref(const sk_svgdom_t *svg) {
+ SkSafeUnref(AsSVGDOM(svg));
+}
+#endif
diff --git a/src/c/sk_types_priv.h b/src/c/sk_types_priv.h
Expand Down
11 changes: 9 additions & 2 deletions src/c/sk_svg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,14 @@ float sk_svgdom_get_container_height(sk_svgdom_t *svgdom) {
}

sk_svgdom_t *sk_svgdom_create_from_stream(sk_stream_t *stream) {
std::unique_ptr<SkStream> skstream(AsStream(stream));
return ToSVGDOM(SkSVGDOM::MakeFromStream(*skstream).release());
return ToSVGDOM(SkSVGDOM::MakeFromStream(*AsStream(stream)).release());
}

void sk_svgdom_ref(const sk_svgdom_t *svg) {
SkSafeRef(AsSVGDOM(svg));
}

void sk_svgdom_unref(const sk_svgdom_t *svg) {
SkSafeUnref(AsSVGDOM(svg));
}
#endif

0 comments on commit 526fdf5

Please sign in to comment.