Debian Codegraph @

core/jni/android_os_GraphicsEnvironment.cpp

raw symbols SCIP
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
19 #include <vector>
20
21 #include <graphicsenv/GraphicsEnv.h>
22 #include <nativehelper/ScopedUtfChars.h>
23 #include <nativeloader/native_loader.h>
24 #include "core_jni_helpers.h"
25
26 namespace {
27
28 bool isDebuggable_native() {
29 return android::GraphicsEnv::getInstance().isDebuggable();
30 }
31
32 void setDriverPathAndSphalLibraries_native(JNIEnv* env, jobject clazz, jstring path,
33 jstring sphalLibraries) {
34 ScopedUtfChars pathChars(env, path);
35 ScopedUtfChars sphalLibrariesChars(env, sphalLibraries);
36 android::GraphicsEnv::getInstance().setDriverPathAndSphalLibraries(pathChars.c_str(),
37 sphalLibrariesChars.c_str());
38 }
39
40 void setGpuStats_native(JNIEnv* env, jobject clazz, jstring driverPackageName,
41 jstring driverVersionName, jlong driverVersionCode,
42 jlong driverBuildTime, jstring appPackageName, jint vulkanVersion) {
43 ScopedUtfChars driverPackageNameChars(env, driverPackageName);
44 ScopedUtfChars driverVersionNameChars(env, driverVersionName);
45 ScopedUtfChars appPackageNameChars(env, appPackageName);
46 android::GraphicsEnv::getInstance().setGpuStats(driverPackageNameChars.c_str(),
47 driverVersionNameChars.c_str(),
48 driverVersionCode, driverBuildTime,
49 appPackageNameChars.c_str(), vulkanVersion);
50 }
51
52 void setAngleInfo_native(JNIEnv* env, jobject clazz, jstring path, jstring appName,
53 jboolean angleIsSystemDriver, jstring devOptIn, jobjectArray featuresObj) {
54 ScopedUtfChars pathChars(env, path);
55 ScopedUtfChars appNameChars(env, appName);
56 ScopedUtfChars devOptInChars(env, devOptIn);
57
58 std::vector<std::string> features;
59 if (featuresObj != nullptr) {
60 jsize length = env->GetArrayLength(featuresObj);
61 for (jsize i = 0; i < length; ++i) {
62 jstring jstr = static_cast<jstring>(env->GetObjectArrayElement(featuresObj, i));
63 // null entries are ignored
64 if (jstr == nullptr) {
65 continue;
66 }
67 const char* cstr = env->GetStringUTFChars(jstr, nullptr);
68 if (cstr == nullptr) {
69 continue;
70 }
71 features.emplace_back(cstr);
72 env->ReleaseStringUTFChars(jstr, cstr);
73 }
74 }
75
76 android::GraphicsEnv::getInstance().setAngleInfo(pathChars.c_str(), appNameChars.c_str(),
77 angleIsSystemDriver, devOptInChars.c_str(),
78 features);
79 }
80
81 void setLegacyDriverInfo_native(JNIEnv* env, jobject clazz, jstring appName,
82 jboolean angleIsSystemDriver, jstring legacyDriverName) {
83 ScopedUtfChars appNameChars(env, appName);
84 ScopedUtfChars legacyDriverNameChars(env, legacyDriverName);
85
86 android::GraphicsEnv::getInstance().setLegacyDriverInfo(appNameChars.c_str(),
87 angleIsSystemDriver,
88 legacyDriverNameChars.c_str());
89 }
90
91 bool shouldUseAngle_native(JNIEnv* env, jobject clazz, jstring appName) {
92 ScopedUtfChars appNameChars(env, appName);
93 return android::GraphicsEnv::getInstance().shouldUseAngle(appNameChars.c_str());
94 }
95
96 void setLayerPaths_native(JNIEnv* env, jobject clazz, jobject classLoader, jstring layerPaths) {
97 android::NativeLoaderNamespace* appNamespace = android::FindNativeLoaderNamespaceByClassLoader(
98 env, classLoader);
99 ScopedUtfChars layerPathsChars(env, layerPaths);
100 android::GraphicsEnv::getInstance().setLayerPaths(appNamespace, layerPathsChars.c_str());
101 }
102
103 void setDebugLayers_native(JNIEnv* env, jobject clazz, jstring layers) {
104 if (layers != nullptr) {
105 ScopedUtfChars layersChars(env, layers);
106 android::GraphicsEnv::getInstance().setDebugLayers(layersChars.c_str());
107 }
108 }
109
110 void setDebugLayersGLES_native(JNIEnv* env, jobject clazz, jstring layers) {
111 if (layers != nullptr) {
112 ScopedUtfChars layersChars(env, layers);
113 android::GraphicsEnv::getInstance().setDebugLayersGLES(layersChars.c_str());
114 }
115 }
116
117 bool setInjectLayersPrSetDumpable_native() {
118 return android::GraphicsEnv::getInstance().setInjectLayersPrSetDumpable();
119 }
120
121 void hintActivityLaunch_native(JNIEnv* env, jobject clazz) {
122 android::GraphicsEnv::getInstance().hintActivityLaunch();
123 }
124
125 const JNINativeMethod g_methods[] = {
126 {"isDebuggable", "()Z", reinterpret_cast<void*>(isDebuggable_native)},
127 {"setDriverPathAndSphalLibraries", "(Ljava/lang/String;Ljava/lang/String;)V",
128 reinterpret_cast<void*>(setDriverPathAndSphalLibraries_native)},
129 {"setGpuStats", "(Ljava/lang/String;Ljava/lang/String;JJLjava/lang/String;I)V",
130 reinterpret_cast<void*>(setGpuStats_native)},
131 {"setInjectLayersPrSetDumpable", "()Z",
132 reinterpret_cast<void*>(setInjectLayersPrSetDumpable_native)},
133 {"setAngleInfo",
134 "(Ljava/lang/String;Ljava/lang/String;ZLjava/lang/String;[Ljava/lang/String;)V",
135 reinterpret_cast<void*>(setAngleInfo_native)},
136 {"setLegacyDriverInfo", "(Ljava/lang/String;ZLjava/lang/String;)V",
137 reinterpret_cast<void*>(setLegacyDriverInfo_native)},
138 {"getShouldUseAngle", "(Ljava/lang/String;)Z",
139 reinterpret_cast<void*>(shouldUseAngle_native)},
140 {"setLayerPaths", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V",
141 reinterpret_cast<void*>(setLayerPaths_native)},
142 {"setDebugLayers", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayers_native)},
143 {"setDebugLayersGLES", "(Ljava/lang/String;)V",
144 reinterpret_cast<void*>(setDebugLayersGLES_native)},
145 {"hintActivityLaunch", "()V", reinterpret_cast<void*>(hintActivityLaunch_native)},
146 };
147
148 const char* const kGraphicsEnvironmentName = "android/os/GraphicsEnvironment";
149
150 } // anonymous namespace
151
152 namespace android {
153
154 int register_android_os_GraphicsEnvironment(JNIEnv* env) {
155 return RegisterMethodsOrDie(env, kGraphicsEnvironmentName, g_methods, NELEM(g_methods));
156 }
157
158 } // namespace android