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 | |
Cody Northrop | ebe6a56 | 2018-10-15 07:22:23 -0600 | [diff] [blame] | 26 | int getCanLoadSystemLibraries_native() { |
| 27 | return android::GraphicsEnv::getInstance().getCanLoadSystemLibraries(); |
| 28 | } |
| 29 | |
Yiwei Zhang | 1c51f05 | 2019-02-14 12:05:47 -0800 | [diff] [blame] | 30 | void setDriverPathAndSphalLibraries_native(JNIEnv* env, jobject clazz, jstring path, |
| 31 | jstring sphalLibraries) { |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 32 | ScopedUtfChars pathChars(env, path); |
Yiwei Zhang | 1c51f05 | 2019-02-14 12:05:47 -0800 | [diff] [blame] | 33 | ScopedUtfChars sphalLibrariesChars(env, sphalLibraries); |
| 34 | android::GraphicsEnv::getInstance().setDriverPathAndSphalLibraries(pathChars.c_str(), |
| 35 | sphalLibrariesChars.c_str()); |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Yiwei Zhang | 33097bf | 2019-02-04 19:01:21 -0800 | [diff] [blame] | 38 | void setGpuStats_native(JNIEnv* env, jobject clazz, jstring driverPackageName, |
| 39 | jstring driverVersionName, jlong driverVersionCode, |
Yiwei Zhang | 27a2743 | 2019-05-06 17:13:05 -0700 | [diff] [blame] | 40 | jlong driverBuildTime, jstring appPackageName, jint vulkanVersion) { |
Yiwei Zhang | 33097bf | 2019-02-04 19:01:21 -0800 | [diff] [blame] | 41 | ScopedUtfChars driverPackageNameChars(env, driverPackageName); |
| 42 | ScopedUtfChars driverVersionNameChars(env, driverVersionName); |
| 43 | ScopedUtfChars appPackageNameChars(env, appPackageName); |
| 44 | android::GraphicsEnv::getInstance().setGpuStats(driverPackageNameChars.c_str(), |
| 45 | driverVersionNameChars.c_str(), |
Yiwei Zhang | f7b0a5f | 2019-02-19 16:04:10 -0800 | [diff] [blame] | 46 | driverVersionCode, driverBuildTime, |
Yiwei Zhang | 27a2743 | 2019-05-06 17:13:05 -0700 | [diff] [blame] | 47 | appPackageNameChars.c_str(), vulkanVersion); |
Yiwei Zhang | 33097bf | 2019-02-04 19:01:21 -0800 | [diff] [blame] | 48 | } |
| 49 | |
Tim Van Patten | 3c61284 | 2018-11-09 16:48:24 -0700 | [diff] [blame] | 50 | void setAngleInfo_native(JNIEnv* env, jobject clazz, jstring path, jstring appName, jstring devOptIn, |
Cody Northrop | 7fd4421 | 2018-09-06 10:30:28 -0600 | [diff] [blame] | 51 | jobject rulesFd, jlong rulesOffset, jlong rulesLength) { |
Cody Northrop | 73c0504 | 2018-04-16 13:23:51 -0600 | [diff] [blame] | 52 | ScopedUtfChars pathChars(env, path); |
Cody Northrop | eb0ca8e | 2018-08-09 16:01:08 -0600 | [diff] [blame] | 53 | ScopedUtfChars appNameChars(env, appName); |
Tim Van Patten | 3c61284 | 2018-11-09 16:48:24 -0700 | [diff] [blame] | 54 | ScopedUtfChars devOptInChars(env, devOptIn); |
Cody Northrop | 7fd4421 | 2018-09-06 10:30:28 -0600 | [diff] [blame] | 55 | |
| 56 | int rulesFd_native = jniGetFDFromFileDescriptor(env, rulesFd); |
| 57 | |
Cody Northrop | 841c3d9 | 2018-08-29 16:36:12 -0600 | [diff] [blame] | 58 | android::GraphicsEnv::getInstance().setAngleInfo(pathChars.c_str(), appNameChars.c_str(), |
Tim Van Patten | 3c61284 | 2018-11-09 16:48:24 -0700 | [diff] [blame] | 59 | devOptInChars.c_str(), rulesFd_native, rulesOffset, rulesLength); |
Cody Northrop | 73c0504 | 2018-04-16 13:23:51 -0600 | [diff] [blame] | 60 | } |
| 61 | |
Tim Van Patten | ddc4391 | 2018-12-18 17:47:52 -0700 | [diff] [blame] | 62 | bool shouldUseAngle_native(JNIEnv* env, jobject clazz, jstring appName) { |
| 63 | ScopedUtfChars appNameChars(env, appName); |
| 64 | return android::GraphicsEnv::getInstance().shouldUseAngle(appNameChars.c_str()); |
| 65 | } |
| 66 | |
Cody Northrop | 86cedcb | 2017-10-20 09:03:13 -0600 | [diff] [blame] | 67 | void setLayerPaths_native(JNIEnv* env, jobject clazz, jobject classLoader, jstring layerPaths) { |
Victor Khimenko | 4f03ec3 | 2018-07-13 16:53:46 +0200 | [diff] [blame] | 68 | android::NativeLoaderNamespace* appNamespace = android::FindNativeLoaderNamespaceByClassLoader( |
| 69 | env, classLoader); |
Cody Northrop | 86cedcb | 2017-10-20 09:03:13 -0600 | [diff] [blame] | 70 | ScopedUtfChars layerPathsChars(env, layerPaths); |
| 71 | android::GraphicsEnv::getInstance().setLayerPaths(appNamespace, layerPathsChars.c_str()); |
| 72 | } |
| 73 | |
| 74 | void setDebugLayers_native(JNIEnv* env, jobject clazz, jstring layers) { |
| 75 | if (layers != nullptr) { |
| 76 | ScopedUtfChars layersChars(env, layers); |
| 77 | android::GraphicsEnv::getInstance().setDebugLayers(layersChars.c_str()); |
| 78 | } |
| 79 | } |
| 80 | |
Cody Northrop | 0fa1d22 | 2018-10-23 13:13:21 -0600 | [diff] [blame] | 81 | void setDebugLayersGLES_native(JNIEnv* env, jobject clazz, jstring layers) { |
| 82 | if (layers != nullptr) { |
| 83 | ScopedUtfChars layersChars(env, layers); |
| 84 | android::GraphicsEnv::getInstance().setDebugLayersGLES(layersChars.c_str()); |
| 85 | } |
| 86 | } |
| 87 | |
Yiwei Zhang | e54faf5 | 2019-05-08 18:43:11 -0700 | [diff] [blame] | 88 | void hintActivityLaunch_native(JNIEnv* env, jobject clazz) { |
| 89 | android::GraphicsEnv::getInstance().hintActivityLaunch(); |
| 90 | } |
| 91 | |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 92 | const JNINativeMethod g_methods[] = { |
Cody Northrop | ebe6a56 | 2018-10-15 07:22:23 -0600 | [diff] [blame] | 93 | { "getCanLoadSystemLibraries", "()I", reinterpret_cast<void*>(getCanLoadSystemLibraries_native) }, |
Yiwei Zhang | 1c51f05 | 2019-02-14 12:05:47 -0800 | [diff] [blame] | 94 | { "setDriverPathAndSphalLibraries", "(Ljava/lang/String;Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPathAndSphalLibraries_native) }, |
Yiwei Zhang | 27a2743 | 2019-05-06 17:13:05 -0700 | [diff] [blame] | 95 | { "setGpuStats", "(Ljava/lang/String;Ljava/lang/String;JJLjava/lang/String;I)V", reinterpret_cast<void*>(setGpuStats_native) }, |
Tim Van Patten | 3c61284 | 2018-11-09 16:48:24 -0700 | [diff] [blame] | 96 | { "setAngleInfo", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/io/FileDescriptor;JJ)V", reinterpret_cast<void*>(setAngleInfo_native) }, |
Tim Van Patten | ddc4391 | 2018-12-18 17:47:52 -0700 | [diff] [blame] | 97 | { "getShouldUseAngle", "(Ljava/lang/String;)Z", reinterpret_cast<void*>(shouldUseAngle_native) }, |
Cody Northrop | 86cedcb | 2017-10-20 09:03:13 -0600 | [diff] [blame] | 98 | { "setLayerPaths", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V", reinterpret_cast<void*>(setLayerPaths_native) }, |
| 99 | { "setDebugLayers", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayers_native) }, |
Cody Northrop | 0fa1d22 | 2018-10-23 13:13:21 -0600 | [diff] [blame] | 100 | { "setDebugLayersGLES", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayersGLES_native) }, |
Yiwei Zhang | e54faf5 | 2019-05-08 18:43:11 -0700 | [diff] [blame] | 101 | { "hintActivityLaunch", "()V", reinterpret_cast<void*>(hintActivityLaunch_native) }, |
Jesse Hall | b12249b | 2016-12-12 12:53:02 -0800 | [diff] [blame] | 102 | }; |
| 103 | |
| 104 | const char* const kGraphicsEnvironmentName = "android/os/GraphicsEnvironment"; |
| 105 | |
| 106 | } // anonymous namespace |
| 107 | |
| 108 | namespace android { |
| 109 | |
| 110 | int register_android_os_GraphicsEnvironment(JNIEnv* env) { |
| 111 | return RegisterMethodsOrDie(env, kGraphicsEnvironmentName, g_methods, NELEM(g_methods)); |
| 112 | } |
| 113 | |
| 114 | } // namespace android |