From 1cbca71246d050701ae9640c3e93f80348858d6d Mon Sep 17 00:00:00 2001 From: vechro Date: Fri, 30 Jul 2021 15:34:47 +0300 Subject: [PATCH 1/5] Basic, hopefully valid, bindings for RuntimeEffect --- platform/cc/RuntimeEffect.cc | 43 ++++++++++++++++++++++++++++++++++ shared/java/RuntimeEffect.java | 38 ++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 platform/cc/RuntimeEffect.cc create mode 100644 shared/java/RuntimeEffect.java diff --git a/platform/cc/RuntimeEffect.cc b/platform/cc/RuntimeEffect.cc new file mode 100644 index 00000000..392fb168 --- /dev/null +++ b/platform/cc/RuntimeEffect.cc @@ -0,0 +1,43 @@ +#include + +#include "SkRuntimeEffect.h" +#include "interop.hh" + +JNIEXPORT jlong JNICALL +Java_org_jetbrains_skija_RuntimeEffect__1nMakeShader(JNIEnv* env, + jclass jclass, + jlong ptr, + jlong uniformPtr, + jlongArray childrenPtrs, + jlong childCount, + jfloatArray localMatrixArr, + jboolean isOpaque) { + SkRuntimeEffect* runtimeEffect = jlongToPtr(ptr); + SkData* uniform = jlongToPtr(uniformPtr); + sk_sp uniformData = SkData::MakeFromMalloc(uniform, uniform->size()); + + // Matrix + jfloat* m = env->GetFloatArrayElements(localMatrixArr, 0); + SkMatrix* mPtr = new SkMatrix(); + mPtr->setAll(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]); + env->ReleaseFloatArrayElements(localMatrixArr, m, 0); + + sk_sp* children = new sk_sp[childCount]; + SkShader** cPtrs = reinterpret_cast(childrenPtrs); + for (size_t i = 0; i < childCount; i++) { + // This bare pointer was already part of an sk_sp (owned outside of here), + // so we want to ref the new sk_sp so makeShader doesn't clean it up. + children[i] = sk_ref_sp(cPtrs[i]); + } + sk_sp shader = + runtimeEffect->makeShader(uniformData, children, childCount, mPtr, isOpaque); + return ptrToJlong(&shader); +} + +JNIEXPORT jlong JNICALL Java_org_jetbrains_skija_RuntimeEffect__1nMakeColorFilter(JNIEnv* env, + jclass jclass, + jstring sksl) { + SkString skslProper = skString(env, sksl); + SkRuntimeEffect::Result result = SkRuntimeEffect::MakeForColorFilter(skslProper); + return ptrToJlong(result.effect.release()); +} \ No newline at end of file diff --git a/shared/java/RuntimeEffect.java b/shared/java/RuntimeEffect.java new file mode 100644 index 00000000..fd4c7632 --- /dev/null +++ b/shared/java/RuntimeEffect.java @@ -0,0 +1,38 @@ +package org.jetbrains.skija; + +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.Nullable; +import org.jetbrains.skija.impl.*; + +public class RuntimeEffect extends RefCnt { + static { + Library.staticLoad(); + } + + public Shader makeShader(@Nullable Data uniforms, @Nullable Shader[] children, @Nullable Matrix33 localMatrix, + boolean isOpaque) { + Stats.onNativeCall(); + float[] arr = localMatrix == null ? null : localMatrix._mat; + long childCount = children == null ? 0 : children.length; + long[] childrenPtrs = new long[(int) childCount]; + for (int i = 0; i < childCount; i++) { + childrenPtrs[i] = Native.getPtr(children[i]); + } + return new RuntimeEffect(_nMakeShader(_ptr, Native.getPtr(uniforms), childrenPtrs, childCount, arr, isOpaque)); + } + + public RuntimeEffect makeColorFilter(String sksl) { + Stats.onNativeCall(); + return new RuntimeEffect(_nMakeColorFilter(_ptr, sksl)); + } + + @ApiStatus.Internal + public RuntimeEffect(long ptr) { + super(ptr); + } + + public static native long _nMakeShader(long runtimeEffectPtr, long uniformPtr, long[] childrenPtrs, long childCount, + float[] localMatrix, boolean isOpaque); + + public static native long _nMakeColorFilter(long runtimeEffectPtr, String sksl); +} \ No newline at end of file From f9f267e9cd63d2b9944eae2ab18f5ccd8d4e1cdf Mon Sep 17 00:00:00 2001 From: vechro Date: Sat, 7 Aug 2021 10:05:15 +0300 Subject: [PATCH 2/5] Address feedback --- platform/cc/RuntimeEffect.cc | 33 +++++++++++++++++++-------------- shared/java/RuntimeEffect.java | 8 ++++---- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/platform/cc/RuntimeEffect.cc b/platform/cc/RuntimeEffect.cc index 392fb168..0e3efbe7 100644 --- a/platform/cc/RuntimeEffect.cc +++ b/platform/cc/RuntimeEffect.cc @@ -9,29 +9,30 @@ Java_org_jetbrains_skija_RuntimeEffect__1nMakeShader(JNIEnv* env, jlong ptr, jlong uniformPtr, jlongArray childrenPtrs, - jlong childCount, jfloatArray localMatrixArr, jboolean isOpaque) { SkRuntimeEffect* runtimeEffect = jlongToPtr(ptr); + + // Uniform SkData* uniform = jlongToPtr(uniformPtr); sk_sp uniformData = SkData::MakeFromMalloc(uniform, uniform->size()); // Matrix - jfloat* m = env->GetFloatArrayElements(localMatrixArr, 0); - SkMatrix* mPtr = new SkMatrix(); - mPtr->setAll(m[0], m[1], m[2], m[3], m[4], m[5], m[6], m[7], m[8]); - env->ReleaseFloatArrayElements(localMatrixArr, m, 0); + std::unique_ptr localMatrix = skMatrix(env, localMatrixArr); - sk_sp* children = new sk_sp[childCount]; - SkShader** cPtrs = reinterpret_cast(childrenPtrs); + // Children + jsize childCount = env->GetArrayLength(childrenPtrs); + jlong* c = env->GetLongArrayElements(childrenPtrs, 0); + std::vector> children(childCount); for (size_t i = 0; i < childCount; i++) { - // This bare pointer was already part of an sk_sp (owned outside of here), - // so we want to ref the new sk_sp so makeShader doesn't clean it up. - children[i] = sk_ref_sp(cPtrs[i]); + SkShader* si = jlongToPtr(c[i]); + children[i] = sk_ref_sp(si); } - sk_sp shader = - runtimeEffect->makeShader(uniformData, children, childCount, mPtr, isOpaque); - return ptrToJlong(&shader); + env->ReleaseLongArrayElements(childrenPtrs, c, 0); + + sk_sp shader = runtimeEffect->makeShader(uniformData, children.data(), childCount, + localMatrix.get(), isOpaque); + return ptrToJlong(shader.release()); } JNIEXPORT jlong JNICALL Java_org_jetbrains_skija_RuntimeEffect__1nMakeColorFilter(JNIEnv* env, @@ -39,5 +40,9 @@ JNIEXPORT jlong JNICALL Java_org_jetbrains_skija_RuntimeEffect__1nMakeColorFilte jstring sksl) { SkString skslProper = skString(env, sksl); SkRuntimeEffect::Result result = SkRuntimeEffect::MakeForColorFilter(skslProper); - return ptrToJlong(result.effect.release()); + if (result.errorText.isEmpty()) { + return ptrToJlong(result.effect.release()); + } else { + env->ThrowNew(java::lang::RuntimeException::cls, result.errorText.c_str()); + } } \ No newline at end of file diff --git a/shared/java/RuntimeEffect.java b/shared/java/RuntimeEffect.java index fd4c7632..e93923c8 100644 --- a/shared/java/RuntimeEffect.java +++ b/shared/java/RuntimeEffect.java @@ -13,12 +13,12 @@ public Shader makeShader(@Nullable Data uniforms, @Nullable Shader[] children, @ boolean isOpaque) { Stats.onNativeCall(); float[] arr = localMatrix == null ? null : localMatrix._mat; - long childCount = children == null ? 0 : children.length; - long[] childrenPtrs = new long[(int) childCount]; + int childCount = children == null ? 0 : children.length; + long[] childrenPtrs = new long[childCount]; for (int i = 0; i < childCount; i++) { childrenPtrs[i] = Native.getPtr(children[i]); } - return new RuntimeEffect(_nMakeShader(_ptr, Native.getPtr(uniforms), childrenPtrs, childCount, arr, isOpaque)); + return new Shader(_nMakeShader(_ptr, Native.getPtr(uniforms), childrenPtrs, arr, isOpaque)); } public RuntimeEffect makeColorFilter(String sksl) { @@ -31,7 +31,7 @@ public RuntimeEffect(long ptr) { super(ptr); } - public static native long _nMakeShader(long runtimeEffectPtr, long uniformPtr, long[] childrenPtrs, long childCount, + public static native long _nMakeShader(long runtimeEffectPtr, long uniformPtr, long[] childrenPtrs, float[] localMatrix, boolean isOpaque); public static native long _nMakeColorFilter(long runtimeEffectPtr, String sksl); From bd7d6a89695ddefae39cad8319cbd965a297b041 Mon Sep 17 00:00:00 2001 From: vechro Date: Sat, 7 Aug 2021 19:07:18 +0300 Subject: [PATCH 3/5] Add MakeForShader and rename functions Also add extern "C" --- platform/cc/RuntimeEffect.cc | 23 +++++++++++++++++++---- shared/java/RuntimeEffect.java | 13 ++++++++++--- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/platform/cc/RuntimeEffect.cc b/platform/cc/RuntimeEffect.cc index 0e3efbe7..3f6ce6cf 100644 --- a/platform/cc/RuntimeEffect.cc +++ b/platform/cc/RuntimeEffect.cc @@ -3,7 +3,7 @@ #include "SkRuntimeEffect.h" #include "interop.hh" -JNIEXPORT jlong JNICALL +extern "C" JNIEXPORT jlong JNICALL Java_org_jetbrains_skija_RuntimeEffect__1nMakeShader(JNIEnv* env, jclass jclass, jlong ptr, @@ -35,14 +35,29 @@ Java_org_jetbrains_skija_RuntimeEffect__1nMakeShader(JNIEnv* env, return ptrToJlong(shader.release()); } -JNIEXPORT jlong JNICALL Java_org_jetbrains_skija_RuntimeEffect__1nMakeColorFilter(JNIEnv* env, - jclass jclass, - jstring sksl) { +extern "C" JNIEXPORT jlong JNICALL +Java_org_jetbrains_skija_RuntimeEffect__1nMakeForShader(JNIEnv* env, jclass jclass, jstring sksl) { + SkString skslProper = skString(env, sksl); + SkRuntimeEffect::Result result = SkRuntimeEffect::MakeForShader(skslProper); + if (result.errorText.isEmpty()) { + sk_sp effect = result.effect; + return ptrToJlong(effect.release()); + } else { + env->ThrowNew(java::lang::RuntimeException::cls, result.errorText.c_str()); + return 0; + } +} + +extern "C" JNIEXPORT jlong JNICALL +Java_org_jetbrains_skija_RuntimeEffect__1nMakeForColorFilter(JNIEnv* env, + jclass jclass, + jstring sksl) { SkString skslProper = skString(env, sksl); SkRuntimeEffect::Result result = SkRuntimeEffect::MakeForColorFilter(skslProper); if (result.errorText.isEmpty()) { return ptrToJlong(result.effect.release()); } else { env->ThrowNew(java::lang::RuntimeException::cls, result.errorText.c_str()); + return 0; } } \ No newline at end of file diff --git a/shared/java/RuntimeEffect.java b/shared/java/RuntimeEffect.java index e93923c8..95b66305 100644 --- a/shared/java/RuntimeEffect.java +++ b/shared/java/RuntimeEffect.java @@ -21,9 +21,14 @@ public Shader makeShader(@Nullable Data uniforms, @Nullable Shader[] children, @ return new Shader(_nMakeShader(_ptr, Native.getPtr(uniforms), childrenPtrs, arr, isOpaque)); } - public RuntimeEffect makeColorFilter(String sksl) { + public static RuntimeEffect makeForShader(String sksl) { Stats.onNativeCall(); - return new RuntimeEffect(_nMakeColorFilter(_ptr, sksl)); + return new RuntimeEffect(_nMakeForShader(sksl)); + } + + public static RuntimeEffect makeForColorFilter(String sksl) { + Stats.onNativeCall(); + return new RuntimeEffect(_nMakeForColorFilter(sksl)); } @ApiStatus.Internal @@ -34,5 +39,7 @@ public RuntimeEffect(long ptr) { public static native long _nMakeShader(long runtimeEffectPtr, long uniformPtr, long[] childrenPtrs, float[] localMatrix, boolean isOpaque); - public static native long _nMakeColorFilter(long runtimeEffectPtr, String sksl); + public static native long _nMakeForShader(String sksl); + + public static native long _nMakeForColorFilter(String sksl); } \ No newline at end of file From bcb861bc3c82dc19ca575f3e952c77e8127c4182 Mon Sep 17 00:00:00 2001 From: vechro Date: Sat, 7 Aug 2021 19:09:11 +0300 Subject: [PATCH 4/5] Add RuntimeEffect scene --- examples/scenes/src/RuntimeEffectScene.java | 20 ++++++++++++++++++++ examples/scenes/src/Scenes.java | 1 + 2 files changed, 21 insertions(+) create mode 100644 examples/scenes/src/RuntimeEffectScene.java diff --git a/examples/scenes/src/RuntimeEffectScene.java b/examples/scenes/src/RuntimeEffectScene.java new file mode 100644 index 00000000..66366b6f --- /dev/null +++ b/examples/scenes/src/RuntimeEffectScene.java @@ -0,0 +1,20 @@ +package org.jetbrains.skija.examples.scenes; + +import org.jetbrains.skija.*; + +public class RuntimeEffectScene extends Scene { + @Override + public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int ypos) { + var sksl = "const half3 iColor = half3(0, 0.5, 0.75);\n" + + "half4 main(float2 coord) {\n" + + " return iColor.rgb1;\n" + + "}"; + + var effect = RuntimeEffect.makeForShader(sksl); + var myShader = effect.makeShader(null, null, null, false); + + var p = new Paint(); + p.setShader(myShader); + canvas.drawPaint(p); + } +} diff --git a/examples/scenes/src/Scenes.java b/examples/scenes/src/Scenes.java index 40abf5f2..4a504076 100644 --- a/examples/scenes/src/Scenes.java +++ b/examples/scenes/src/Scenes.java @@ -43,6 +43,7 @@ public class Scenes { scenes.put("Pythagoras", null); scenes.put("Run Handler", null); scenes.put("Run Iterator", null); + scenes.put("Runtime Effect", null); scenes.put("SVG", null); scenes.put("SVG Scaling", null); scenes.put("Shaders", null); From 0e1babb7d2dbb3c80cda61080e72eea5a5322721 Mon Sep 17 00:00:00 2001 From: Nikita Prokopov Date: Sat, 7 Aug 2021 22:01:26 +0200 Subject: [PATCH 5/5] Fixed RuntimeEffect::makeShader, expanded RuntimeEffectScene #120 #124 --- CHANGELOG.md | 6 +++ README.md | 22 ++++----- examples/scenes/images/triangle.png | Bin 0 -> 1927 bytes examples/scenes/src/RuntimeEffectScene.java | 50 +++++++++++++++----- examples/scenes/src/Scenes.java | 2 +- platform/cc/RuntimeEffect.cc | 23 ++++----- shared/java/RuntimeEffect.java | 4 +- 7 files changed, 69 insertions(+), 38 deletions(-) create mode 100644 examples/scenes/images/triangle.png diff --git a/CHANGELOG.md b/CHANGELOG.md index 2697bd83..651bd434 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +# 0.92.13 - Aug 7, 2021 + +Added: + +- RuntimeEffect #120 #124 thx @Vechro + # 0.92.11 - July 27, 2021 Added: diff --git a/README.md b/README.md index 90c9e538..f9da09ae 100644 --- a/README.md +++ b/README.md @@ -110,17 +110,17 @@ ColorSpace ▓▓▓▓░░░░░░ PictureRecorder ▓ Data ▓▓▓▓▓▓▓▓▓░ PixelRef ▓▓▓▓▓▓▓▓▓▓ Drawable ▓▓▓▓▓▓▓▓░░ Pixmap ▓▓▓▓▓▓▓▓▓▓ Flattenable ░░░░░░░░░░ Region ▓▓▓▓▓▓▓▓▓▓ -Font ▓▓▓▓▓▓▓▓▓▓ ScalerContext ░░░░░░░░░░ -FontData ░░░░░░░░░░ Shader ▓▓▓▓▓▓▓▓▓▓ -FontManager ▓▓▓▓▓▓▓▓▓░ ShadowUtils ▓▓▓▓▓▓▓▓▓▓ -FontStyle ▓▓▓▓▓▓▓▓▓▓ Stream ░░░░░░░░░░ -FontStyleSet ▓▓▓▓▓▓▓▓▓▓ String ▓░░░░░░░░░ -Image ▓▓░░░░░░░░ Surface ▓░░░░░░░░░ -ImageFilters ▓▓▓▓▓▓▓▓▓▓ TextBlob ▓▓▓▓▓▓▓▓▓▓ -ImageInfo ▓▓▓▓▓▓▓▓▓▓ TextBlobBuilder ▓▓▓▓▓▓▓▓▓▓ -MaskFilter ▓▓▓▓▓▓▓▓▓▓ Typeface ▓▓▓▓▓▓▓▓░░ -Matrix33 ▓▓▓░░░░░░░ WStream ▓▓░░░░░░░░ -Matrix44 ▓▓▓░░░░░░░ +Font ▓▓▓▓▓▓▓▓▓▓ RuntimeEffect ▓▓▓▓▓░░░░░ +FontData ░░░░░░░░░░ ScalerContext ░░░░░░░░░░ +FontManager ▓▓▓▓▓▓▓▓▓░ Shader ▓▓▓▓▓▓▓▓▓▓ +FontStyle ▓▓▓▓▓▓▓▓▓▓ ShadowUtils ▓▓▓▓▓▓▓▓▓▓ +FontStyleSet ▓▓▓▓▓▓▓▓▓▓ Stream ░░░░░░░░░░ +Image ▓▓░░░░░░░░ String ▓░░░░░░░░░ +ImageFilters ▓▓▓▓▓▓▓▓▓▓ Surface ▓░░░░░░░░░ +ImageInfo ▓▓▓▓▓▓▓▓▓▓ TextBlob ▓▓▓▓▓▓▓▓▓▓ +MaskFilter ▓▓▓▓▓▓▓▓▓▓ TextBlobBuilder ▓▓▓▓▓▓▓▓▓▓ +Matrix33 ▓▓▓░░░░░░░ Typeface ▓▓▓▓▓▓▓▓░░ +Matrix44 ▓▓▓░░░░░░░ WStream ▓▓░░░░░░░░ Shaper: Paragraph: diff --git a/examples/scenes/images/triangle.png b/examples/scenes/images/triangle.png new file mode 100644 index 0000000000000000000000000000000000000000..e94ad6ab7ebfcb54dde50f1277e6e3cd4ac33be6 GIT binary patch literal 1927 zcmaJ?e@s(X6n-sAYPDvOb~+}rR>`2g_O(?&UP=Wl+E$C~THxV^p{1`_q(5w*Qji&0 z1Qh@9$7mB&)Tm6V4C#z>jxhxXOTf*c!C?$K9L_OA6b;!Xo7;VDh01U@Iq#l#&-Z=z zocr#{+mn&Ln!}D{BM8D#tCRrFM%q|R`21%lGYn1)Cs>_|G<`pR2)=ZZgxaLlB0}i1 zkZ{Hv#1BCj5EqF|r{U1D7;lgJ8yPV{4Af*u5n7oC%~WMZrUmh3aHfX}8qN358DpTp1$yDGGHak02~so3Tyz@&+ZiI_x&$z&pk5IIY%l-?z>Iu`{*Ug{`GXTHO1 zr_44hpVrkIY+I=$fq>p3L_(PG z^l>e`i$*=ASL!KJK{tR%vRoud(9sPLhcA_EkYoRWO_EsYAR&1w0lI^N0wJKO=r)JW zW-C%m)y;tf{QMv)C?Ln^yBu=21C8Tfg`J~dL*~maRIrCfS|1?@^Aoi)MdxA+_g`|i zC(lAMFk8fLJ8RggUw4gFrtjX(im8f^nNAEpQ(V4KAW{7CL;aQO*^;s~i^#Ivb3b-J za9q9@v9@Q3l8D|N8ZAA2Gxn`n;SHV&r}XEMKSo@O`>k^yK7Z0EbeFbntR5XWX#~}y zDTT7yZTO?gyw;}@W&`NWz7ZSDNDu$gAVAA4{Fqc_Nw@vG<5>8Cngt zG{+z2yr5C6e$J4lJU0Wq0aAPoYbvf9_&nC$Djf@r2X}p+-x2lDs3(1#T6K9HhVB4g zHxrtYw)?^d@9g!}NJhA-{eHA%Im_=gAVcy%dk@h~AIHMf1bE+N?lyu~05bqf!4>7(|2`!suW=wA3akO>A_?mgbO>g2OO skBsH>TAOE-^;<6v*f(uI^?NmQg~iAg?C^|L(Ek#3TDr0+HSeQ;0bTutod5s; literal 0 HcmV?d00001 diff --git a/examples/scenes/src/RuntimeEffectScene.java b/examples/scenes/src/RuntimeEffectScene.java index 66366b6f..62cd78f8 100644 --- a/examples/scenes/src/RuntimeEffectScene.java +++ b/examples/scenes/src/RuntimeEffectScene.java @@ -1,20 +1,48 @@ package org.jetbrains.skija.examples.scenes; +import java.nio.*; +import java.nio.file.*; +import java.nio.file.Path; +import java.io.*; import org.jetbrains.skija.*; public class RuntimeEffectScene extends Scene { - @Override - public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int ypos) { - var sksl = "const half3 iColor = half3(0, 0.5, 0.75);\n" - + "half4 main(float2 coord) {\n" - + " return iColor.rgb1;\n" - + "}"; + public final Shader _texture; + public final RuntimeEffect _effect; + + public RuntimeEffectScene() { + try { + _texture = Image.makeFromEncoded(Files.readAllBytes(Path.of(file("images/triangle.png")))).makeShader(); + } catch (IOException e) { + throw new RuntimeException(e); + } - var effect = RuntimeEffect.makeForShader(sksl); - var myShader = effect.makeShader(null, null, null, false); + _effect = RuntimeEffect.makeForShader( + "uniform float xScale;\n" + + "uniform float xBias;\n" + + "uniform float yScale;\n" + + "uniform float yBias;\n" + + "uniform shader input;\n" + + "half4 main(float2 xy) {\n" + + " half4 tex = sample(input, mod(xy, 100));\n" + + " return half4((xy.x - xBias) / xScale / 2 + 0.5, (xy.y - yBias) / yScale / 2 + 0.5, tex.b, 1);\n" + + "}" + ); + } - var p = new Paint(); - p.setShader(myShader); - canvas.drawPaint(p); + @Override + public void draw(Canvas canvas, int width, int height, float dpi, int xpos, int ypos) { + var bb = ByteBuffer.allocate(4 * 4).order(ByteOrder.nativeOrder()); + bb.putFloat((float) width); + bb.putFloat((float) xpos); + bb.putFloat((float) height); + bb.putFloat((float) ypos); + try (var data = Data.makeFromBytes(bb.array()); + var paint = new Paint(); + var shader = _effect.makeShader(data, new Shader[] { _texture }, null, true);) + { + paint.setShader(shader); + canvas.drawPaint(paint); + } } } diff --git a/examples/scenes/src/Scenes.java b/examples/scenes/src/Scenes.java index 4a504076..32ee174c 100644 --- a/examples/scenes/src/Scenes.java +++ b/examples/scenes/src/Scenes.java @@ -6,7 +6,7 @@ public class Scenes { public static TreeMap scenes; - public static String currentScene = "Bitmap"; + public static String currentScene = "Runtime Effect"; public static HUD hud = new HUD(); public static boolean stats = true; diff --git a/platform/cc/RuntimeEffect.cc b/platform/cc/RuntimeEffect.cc index 3f6ce6cf..85d6e340 100644 --- a/platform/cc/RuntimeEffect.cc +++ b/platform/cc/RuntimeEffect.cc @@ -8,30 +8,27 @@ Java_org_jetbrains_skija_RuntimeEffect__1nMakeShader(JNIEnv* env, jclass jclass, jlong ptr, jlong uniformPtr, - jlongArray childrenPtrs, + jlongArray childrenPtrsArr, jfloatArray localMatrixArr, jboolean isOpaque) { SkRuntimeEffect* runtimeEffect = jlongToPtr(ptr); - - // Uniform SkData* uniform = jlongToPtr(uniformPtr); - sk_sp uniformData = SkData::MakeFromMalloc(uniform, uniform->size()); - - // Matrix std::unique_ptr localMatrix = skMatrix(env, localMatrixArr); - // Children - jsize childCount = env->GetArrayLength(childrenPtrs); - jlong* c = env->GetLongArrayElements(childrenPtrs, 0); + jsize childCount = env->GetArrayLength(childrenPtrsArr); + jlong* childrenPtrs = env->GetLongArrayElements(childrenPtrsArr, 0); std::vector> children(childCount); for (size_t i = 0; i < childCount; i++) { - SkShader* si = jlongToPtr(c[i]); + SkShader* si = jlongToPtr(childrenPtrs[i]); children[i] = sk_ref_sp(si); } - env->ReleaseLongArrayElements(childrenPtrs, c, 0); + env->ReleaseLongArrayElements(childrenPtrsArr, childrenPtrs, 0); - sk_sp shader = runtimeEffect->makeShader(uniformData, children.data(), childCount, - localMatrix.get(), isOpaque); + sk_sp shader = runtimeEffect->makeShader(sk_ref_sp(uniform), + children.data(), + childCount, + localMatrix.get(), + isOpaque); return ptrToJlong(shader.release()); } diff --git a/shared/java/RuntimeEffect.java b/shared/java/RuntimeEffect.java index 95b66305..fb29a101 100644 --- a/shared/java/RuntimeEffect.java +++ b/shared/java/RuntimeEffect.java @@ -12,13 +12,13 @@ public class RuntimeEffect extends RefCnt { public Shader makeShader(@Nullable Data uniforms, @Nullable Shader[] children, @Nullable Matrix33 localMatrix, boolean isOpaque) { Stats.onNativeCall(); - float[] arr = localMatrix == null ? null : localMatrix._mat; int childCount = children == null ? 0 : children.length; long[] childrenPtrs = new long[childCount]; for (int i = 0; i < childCount; i++) { childrenPtrs[i] = Native.getPtr(children[i]); } - return new Shader(_nMakeShader(_ptr, Native.getPtr(uniforms), childrenPtrs, arr, isOpaque)); + float[] matrix = localMatrix == null ? null : localMatrix._mat; + return new Shader(_nMakeShader(_ptr, Native.getPtr(uniforms), childrenPtrs, matrix, isOpaque)); } public static RuntimeEffect makeForShader(String sksl) {