|
9 | 9 | #include "paragraph/interop.hh" |
10 | 10 |
|
11 | 11 | namespace java { |
| 12 | + namespace io { |
| 13 | + namespace OutputStream { |
| 14 | + jclass cls; |
| 15 | + jmethodID write; |
| 16 | + jmethodID flush; |
| 17 | + |
| 18 | + void onLoad(JNIEnv* env) { |
| 19 | + jclass cls = env->FindClass("java/io/OutputStream"); |
| 20 | + write = env->GetMethodID(cls, "write", "([BII)V"); |
| 21 | + flush = env->GetMethodID(cls, "flush", "()V"); |
| 22 | + } |
| 23 | + } |
| 24 | + } |
| 25 | + |
12 | 26 | namespace lang { |
13 | 27 | namespace Float { |
14 | 28 | jclass cls; |
@@ -37,6 +51,25 @@ namespace java { |
37 | 51 | env->DeleteGlobalRef(cls); |
38 | 52 | } |
39 | 53 | } |
| 54 | + |
| 55 | + namespace Throwable { |
| 56 | + jmethodID printStackTrace; |
| 57 | + |
| 58 | + void onLoad(JNIEnv* env) { |
| 59 | + jclass cls = env->FindClass("java/lang/Throwable"); |
| 60 | + printStackTrace = env->GetMethodID(cls, "printStackTrace", "()V"); |
| 61 | + } |
| 62 | + |
| 63 | + bool exceptionThrown(JNIEnv* env) { |
| 64 | + if (env->ExceptionCheck()) { |
| 65 | + jthrowable th = env->ExceptionOccurred(); |
| 66 | + env->CallVoidMethod(th, printStackTrace); |
| 67 | + env->ExceptionCheck(); // ignore |
| 68 | + return true; |
| 69 | + } else |
| 70 | + return false; |
| 71 | + } |
| 72 | + } |
40 | 73 | } |
41 | 74 |
|
42 | 75 | namespace util { |
@@ -76,8 +109,10 @@ namespace java { |
76 | 109 | } |
77 | 110 |
|
78 | 111 | void onLoad(JNIEnv* env) { |
| 112 | + io::OutputStream::onLoad(env); |
79 | 113 | lang::Float::onLoad(env); |
80 | 114 | lang::String::onLoad(env); |
| 115 | + lang::Throwable::onLoad(env); |
81 | 116 | util::Iterator::onLoad(env); |
82 | 117 | util::function::BooleanSupplier::onLoad(env); |
83 | 118 | } |
@@ -169,6 +204,7 @@ namespace skija { |
169 | 204 | static_cast<uint32_t>(env->GetIntField(featureObj, skija::FontFeature::value)), |
170 | 205 | static_cast<size_t>(env->GetLongField(featureObj, skija::FontFeature::start)), |
171 | 206 | static_cast<size_t>(env->GetLongField(featureObj, skija::FontFeature::end))}; |
| 207 | + env->DeleteLocalRef(featureObj); |
172 | 208 | } |
173 | 209 | return features; |
174 | 210 | } |
@@ -889,6 +925,7 @@ std::vector<SkString> skStringVector(JNIEnv* env, jobjectArray arr) { |
889 | 925 | for (jint i = 0; i < len; ++i) { |
890 | 926 | jstring str = static_cast<jstring>(env->GetObjectArrayElement(arr, i)); |
891 | 927 | res[i] = skString(env, str); |
| 928 | + env->DeleteLocalRef(str); |
892 | 929 | } |
893 | 930 | return res; |
894 | 931 | } |
|
0 commit comments