Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [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 | |
| 17 | #define LOG_TAG "GraphicsEnvironment" |
| 18 | |
Jiyong Park | 354ac499 | 2017-05-08 13:29:35 +0900 | [diff] [blame] | 19 | #include <graphicsenv/GraphicsEnv.h> |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 20 | #include <nativehelper/ScopedUtfChars.h> |
Cody Northrop | 86cedcb | 2017-10-20 09:03:13 -0600 | [diff] [blame] | 21 | #include <nativeloader/native_loader.h> |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 22 | #include "core_jni_helpers.h" |
| 23 | |
| 24 | namespace { |
| 25 | |
| 26 | void setDriverPath(JNIEnv* env, jobject clazz, jstring path) { |
| 27 | ScopedUtfChars pathChars(env, path); |
| 28 | android::GraphicsEnv::getInstance().setDriverPath(pathChars.c_str()); |
| 29 | } |
| 30 | |
Cody Northrop | 86cedcb | 2017-10-20 09:03:13 -0600 | [diff] [blame] | 31 | void setLayerPaths_native(JNIEnv* env, jobject clazz, jobject classLoader, jstring layerPaths) { |
Victor Khimenko | 9f52b4a | 2018-08-16 22:37:21 +0200 | [diff] [blame] | 32 | android::NativeLoaderNamespace* appNamespace = android::FindNativeLoaderNamespaceByClassLoader( |
| 33 | env, classLoader); |
Cody Northrop | 86cedcb | 2017-10-20 09:03:13 -0600 | [diff] [blame] | 34 | ScopedUtfChars layerPathsChars(env, layerPaths); |
| 35 | android::GraphicsEnv::getInstance().setLayerPaths(appNamespace, layerPathsChars.c_str()); |
| 36 | } |
| 37 | |
| 38 | void setDebugLayers_native(JNIEnv* env, jobject clazz, jstring layers) { |
| 39 | if (layers != nullptr) { |
| 40 | ScopedUtfChars layersChars(env, layers); |
| 41 | android::GraphicsEnv::getInstance().setDebugLayers(layersChars.c_str()); |
| 42 | } |
| 43 | } |
| 44 | |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 45 | const JNINativeMethod g_methods[] = { |
| 46 | { "setDriverPath", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPath) }, |
Cody Northrop | 86cedcb | 2017-10-20 09:03:13 -0600 | [diff] [blame] | 47 | { "setLayerPaths", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V", reinterpret_cast<void*>(setLayerPaths_native) }, |
| 48 | { "setDebugLayers", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayers_native) }, |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 49 | }; |
| 50 | |
| 51 | const char* const kGraphicsEnvironmentName = "android/os/GraphicsEnvironment"; |
| 52 | |
| 53 | } // anonymous namespace |
| 54 | |
| 55 | namespace android { |
| 56 | |
| 57 | int register_android_os_GraphicsEnvironment(JNIEnv* env) { |
| 58 | return RegisterMethodsOrDie(env, kGraphicsEnvironmentName, g_methods, NELEM(g_methods)); |
| 59 | } |
| 60 | |
| 61 | } // namespace android |