Repository: google/filament
File: android/filament-android/src/main/cpp/Material.cpp (C++)

Code before:
}

extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_Material_nGetRequiredAttributes(JNIEnv*, jclass,
        jlong nativeMaterial) {
    Material* material = (Material*) nativeMaterial;
    return material->getRequiredAttributes().getValue();
}

extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Material_nHasParameter(JNIEnv* env, jclass,
        jlong nativeMaterial, jstring name_) {
    Material* material = (Material*) nativeMaterial;
    const char* name = env->GetStringUTFChars(name_, 0);
    bool hasParameter = material->hasParameter(name);
    env->ReleaseStringUTFChars(name_, name);
    return (jboolean) hasParameter;
}

extern "C" JNIEXPORT jstring JNICALL
Java_com_google_android_filament_Material_nGetParameterTransformName(JNIEnv* env, jclass,
        jlong nativeMaterial, jstring samplerName_) {
    Material* material = (Material*) nativeMaterial;
    const char* samplerName = env->GetStringUTFChars(samplerName_, 0);
    jstring transformName_ = env->NewStringUTF(material->getParameterTransformName(samplerName));
    env->ReleaseStringUTFChars(samplerName_, samplerName);
    return transformName_;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_Material_nCompile(JNIEnv *env, jclass clazz,
        jlong nativeMaterial, jint priority, jint variants, jobject handler, jobject runnable) {
    Material* material = (Material*) nativeMaterial;
    JniCallback* jniCallback = JniCallback::make(env, handler, runnable);
    material->compile(
            (Material::CompilerPriorityQueue) priority,
            (UserVariantFilterBit) variants,
            jniCallback->getHandler(), [jniCallback](Material*){
                JniCallback::postToJavaAndDestroy(jniCallback);
            });
}


Review comment (bug):
`getParameterTransformName` could return `nullptr` if the samplerName didn't exist. In that case, you need to return an empty string according to the javadoc.

Code after:
}

extern "C"
JNIEXPORT jint JNICALL
Java_com_google_android_filament_Material_nGetRequiredAttributes(JNIEnv*, jclass,
        jlong nativeMaterial) {
    Material* material = (Material*) nativeMaterial;
    return material->getRequiredAttributes().getValue();
}

extern "C" JNIEXPORT jboolean JNICALL
Java_com_google_android_filament_Material_nHasParameter(JNIEnv* env, jclass,
        jlong nativeMaterial, jstring name_) {
    Material* material = (Material*) nativeMaterial;
    const char* name = env->GetStringUTFChars(name_, 0);
    bool hasParameter = material->hasParameter(name);
    env->ReleaseStringUTFChars(name_, name);
    return (jboolean) hasParameter;
}

extern "C" JNIEXPORT jstring JNICALL
Java_com_google_android_filament_Material_nGetParameterTransformName(JNIEnv* env, jclass,
        jlong nativeMaterial, jstring samplerName_) {
    Material* material = (Material*) nativeMaterial;
    const char* samplerName = env->GetStringUTFChars(samplerName_, 0);
    const char* transformName = material->getParameterTransformName(samplerName);
    jstring transformName_ = env->NewStringUTF(transformName ? transformName : "");
    env->ReleaseStringUTFChars(samplerName_, samplerName);
    return transformName_;
}

extern "C"
JNIEXPORT void JNICALL
Java_com_google_android_filament_Material_nCompile(JNIEnv *env, jclass clazz,
        jlong nativeMaterial, jint priority, jint variants, jobject handler, jobject runnable) {
    Material* material = (Material*) nativeMaterial;
    JniCallback* jniCallback = JniCallback::make(env, handler, runnable);
    material->compile(
            (Material::CompilerPriorityQueue) priority,
            (UserVariantFilterBit) variants,
            jniCallback->getHandler(), [jniCallback](Material*){
                JniCallback::postToJavaAndDestroy(jniCallback);
            });
}