blob: 4f3f283859b48d10ce4dc7c1b59a06f542c2b66d [file] [log] [blame]
Jesse Hallb12249b2016-12-12 12:53:02 -08001/*
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 Park354ac4992017-05-08 13:29:35 +090019#include <graphicsenv/GraphicsEnv.h>
Jesse Hallb12249b2016-12-12 12:53:02 -080020#include <nativehelper/ScopedUtfChars.h>
Cody Northrop86cedcb2017-10-20 09:03:13 -060021#include <nativeloader/native_loader.h>
Jesse Hallb12249b2016-12-12 12:53:02 -080022#include "core_jni_helpers.h"
23
24namespace {
25
Yiwei Zhang097a3062019-11-08 12:16:28 -080026bool isDebuggable_native() {
27 return android::GraphicsEnv::getInstance().isDebuggable();
Cody Northropebe6a562018-10-15 07:22:23 -060028}
29
Yiwei Zhang1c51f052019-02-14 12:05:47 -080030void setDriverPathAndSphalLibraries_native(JNIEnv* env, jobject clazz, jstring path,
31 jstring sphalLibraries) {
Jesse Hallb12249b2016-12-12 12:53:02 -080032 ScopedUtfChars pathChars(env, path);
Yiwei Zhang1c51f052019-02-14 12:05:47 -080033 ScopedUtfChars sphalLibrariesChars(env, sphalLibraries);
34 android::GraphicsEnv::getInstance().setDriverPathAndSphalLibraries(pathChars.c_str(),
35 sphalLibrariesChars.c_str());
Jesse Hallb12249b2016-12-12 12:53:02 -080036}
37
Yiwei Zhang33097bf2019-02-04 19:01:21 -080038void setGpuStats_native(JNIEnv* env, jobject clazz, jstring driverPackageName,
39 jstring driverVersionName, jlong driverVersionCode,
Yiwei Zhang27a27432019-05-06 17:13:05 -070040 jlong driverBuildTime, jstring appPackageName, jint vulkanVersion) {
Yiwei Zhang33097bf2019-02-04 19:01:21 -080041 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 Zhangf7b0a5f2019-02-19 16:04:10 -080046 driverVersionCode, driverBuildTime,
Yiwei Zhang27a27432019-05-06 17:13:05 -070047 appPackageNameChars.c_str(), vulkanVersion);
Yiwei Zhang33097bf2019-02-04 19:01:21 -080048}
49
Tim Van Patten3c612842018-11-09 16:48:24 -070050void setAngleInfo_native(JNIEnv* env, jobject clazz, jstring path, jstring appName, jstring devOptIn,
Cody Northrop7fd44212018-09-06 10:30:28 -060051 jobject rulesFd, jlong rulesOffset, jlong rulesLength) {
Cody Northrop73c05042018-04-16 13:23:51 -060052 ScopedUtfChars pathChars(env, path);
Cody Northropeb0ca8e2018-08-09 16:01:08 -060053 ScopedUtfChars appNameChars(env, appName);
Tim Van Patten3c612842018-11-09 16:48:24 -070054 ScopedUtfChars devOptInChars(env, devOptIn);
Cody Northrop7fd44212018-09-06 10:30:28 -060055
56 int rulesFd_native = jniGetFDFromFileDescriptor(env, rulesFd);
57
Cody Northrop841c3d92018-08-29 16:36:12 -060058 android::GraphicsEnv::getInstance().setAngleInfo(pathChars.c_str(), appNameChars.c_str(),
Tim Van Patten3c612842018-11-09 16:48:24 -070059 devOptInChars.c_str(), rulesFd_native, rulesOffset, rulesLength);
Cody Northrop73c05042018-04-16 13:23:51 -060060}
61
Tim Van Pattenddc43912018-12-18 17:47:52 -070062bool 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 Northrop86cedcb2017-10-20 09:03:13 -060067void setLayerPaths_native(JNIEnv* env, jobject clazz, jobject classLoader, jstring layerPaths) {
Victor Khimenko4f03ec32018-07-13 16:53:46 +020068 android::NativeLoaderNamespace* appNamespace = android::FindNativeLoaderNamespaceByClassLoader(
69 env, classLoader);
Cody Northrop86cedcb2017-10-20 09:03:13 -060070 ScopedUtfChars layerPathsChars(env, layerPaths);
71 android::GraphicsEnv::getInstance().setLayerPaths(appNamespace, layerPathsChars.c_str());
72}
73
74void 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 Northrop0fa1d222018-10-23 13:13:21 -060081void 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
Adam Bodnare638cad2019-09-06 14:31:14 -070088bool setInjectLayersPrSetDumpable_native() {
89 return android::GraphicsEnv::getInstance().setInjectLayersPrSetDumpable();
90}
91
Yiwei Zhange54faf52019-05-08 18:43:11 -070092void hintActivityLaunch_native(JNIEnv* env, jobject clazz) {
93 android::GraphicsEnv::getInstance().hintActivityLaunch();
94}
95
Jesse Hallb12249b2016-12-12 12:53:02 -080096const JNINativeMethod g_methods[] = {
Yiwei Zhang097a3062019-11-08 12:16:28 -080097 { "isDebuggable", "()Z", reinterpret_cast<void*>(isDebuggable_native) },
Yiwei Zhang1c51f052019-02-14 12:05:47 -080098 { "setDriverPathAndSphalLibraries", "(Ljava/lang/String;Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPathAndSphalLibraries_native) },
Yiwei Zhang27a27432019-05-06 17:13:05 -070099 { "setGpuStats", "(Ljava/lang/String;Ljava/lang/String;JJLjava/lang/String;I)V", reinterpret_cast<void*>(setGpuStats_native) },
Adam Bodnare638cad2019-09-06 14:31:14 -0700100 { "setInjectLayersPrSetDumpable", "()Z", reinterpret_cast<void*>(setInjectLayersPrSetDumpable_native) },
Tim Van Patten3c612842018-11-09 16:48:24 -0700101 { "setAngleInfo", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/io/FileDescriptor;JJ)V", reinterpret_cast<void*>(setAngleInfo_native) },
Tim Van Pattenddc43912018-12-18 17:47:52 -0700102 { "getShouldUseAngle", "(Ljava/lang/String;)Z", reinterpret_cast<void*>(shouldUseAngle_native) },
Cody Northrop86cedcb2017-10-20 09:03:13 -0600103 { "setLayerPaths", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V", reinterpret_cast<void*>(setLayerPaths_native) },
104 { "setDebugLayers", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayers_native) },
Cody Northrop0fa1d222018-10-23 13:13:21 -0600105 { "setDebugLayersGLES", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayersGLES_native) },
Yiwei Zhange54faf52019-05-08 18:43:11 -0700106 { "hintActivityLaunch", "()V", reinterpret_cast<void*>(hintActivityLaunch_native) },
Jesse Hallb12249b2016-12-12 12:53:02 -0800107};
108
109const char* const kGraphicsEnvironmentName = "android/os/GraphicsEnvironment";
110
111} // anonymous namespace
112
113namespace android {
114
115int register_android_os_GraphicsEnvironment(JNIEnv* env) {
116 return RegisterMethodsOrDie(env, kGraphicsEnvironmentName, g_methods, NELEM(g_methods));
117}
118
119} // namespace android