Home | History | Annotate | Download | only in jni
      1 /*
      2  * Copyright 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #define LOG_TAG "ApplicationLoaders"
     18 
     19 #include <nativehelper/ScopedUtfChars.h>
     20 #include <nativeloader/native_loader.h>
     21 #include <vulkan/vulkan_loader_data.h>
     22 
     23 #include "core_jni_helpers.h"
     24 
     25 static void setupVulkanLayerPath_native(JNIEnv* env, jobject clazz,
     26         jobject classLoader, jstring librarySearchPath) {
     27     android_namespace_t* ns = android::FindNamespaceByClassLoader(env, classLoader);
     28     ScopedUtfChars layerPathChars(env, librarySearchPath);
     29 
     30     vulkan::LoaderData& loader_data = vulkan::LoaderData::GetInstance();
     31     if (loader_data.layer_path.empty()) {
     32         loader_data.layer_path = layerPathChars.c_str();
     33         loader_data.app_namespace = ns;
     34     } else {
     35         ALOGV("Vulkan layer search path already set, not clobbering with '%s' for namespace %p'",
     36                 layerPathChars.c_str(), ns);
     37     }
     38 }
     39 
     40 static const JNINativeMethod g_methods[] = {
     41     { "setupVulkanLayerPath", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V",
     42       reinterpret_cast<void*>(setupVulkanLayerPath_native) },
     43 };
     44 
     45 static const char* const kApplicationLoadersName = "android/app/ApplicationLoaders";
     46 
     47 namespace android
     48 {
     49 
     50 int register_android_app_ApplicationLoaders(JNIEnv* env) {
     51     return RegisterMethodsOrDie(env, kApplicationLoadersName, g_methods, NELEM(g_methods));
     52 }
     53 
     54 } // namespace android
     55