Dimitry Ivanov | 0997908 | 2016-04-19 11:11:01 -0700 | [diff] [blame] | 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 | |
Chia-I Wu | 15e74c9 | 2016-06-28 08:39:33 +0800 | [diff] [blame] | 17 | #define LOG_TAG "ApplicationLoaders" |
| 18 | |
Dimitry Ivanov | 0997908 | 2016-04-19 11:11:01 -0700 | [diff] [blame] | 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) { |
Chia-I Wu | 15e74c9 | 2016-06-28 08:39:33 +0800 | [diff] [blame] | 27 | android_namespace_t* ns = android::FindNamespaceByClassLoader(env, classLoader); |
Dimitry Ivanov | 0997908 | 2016-04-19 11:11:01 -0700 | [diff] [blame] | 28 | ScopedUtfChars layerPathChars(env, librarySearchPath); |
Chia-I Wu | 15e74c9 | 2016-06-28 08:39:33 +0800 | [diff] [blame] | 29 | |
Dimitry Ivanov | 0997908 | 2016-04-19 11:11:01 -0700 | [diff] [blame] | 30 | vulkan::LoaderData& loader_data = vulkan::LoaderData::GetInstance(); |
Chia-I Wu | 15e74c9 | 2016-06-28 08:39:33 +0800 | [diff] [blame] | 31 | if (loader_data.layer_path.empty()) { |
| 32 | loader_data.layer_path = layerPathChars.c_str(); |
| 33 | loader_data.app_namespace = ns; |
| 34 | } else { |
| 35 | ALOGD("ignored Vulkan layer search path %s for namespace %p", |
| 36 | layerPathChars.c_str(), ns); |
| 37 | } |
Dimitry Ivanov | 0997908 | 2016-04-19 11:11:01 -0700 | [diff] [blame] | 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 |