blob: 72e3d3495e372dd0c9fc2122aa73f278c3f42f7d [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
Cody Northropebe6a562018-10-15 07:22:23 -060026int getCanLoadSystemLibraries_native() {
27 return android::GraphicsEnv::getInstance().getCanLoadSystemLibraries();
28}
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 Zhangf7b0a5f2019-02-19 16:04:10 -080040 jlong driverBuildTime, jstring appPackageName) {
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 Zhang31f5adb2019-02-15 16:15:17 -080047 appPackageNameChars.c_str());
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
Jesse Hallb12249b2016-12-12 12:53:02 -080088const JNINativeMethod g_methods[] = {
Cody Northropebe6a562018-10-15 07:22:23 -060089 { "getCanLoadSystemLibraries", "()I", reinterpret_cast<void*>(getCanLoadSystemLibraries_native) },
Yiwei Zhang1c51f052019-02-14 12:05:47 -080090 { "setDriverPathAndSphalLibraries", "(Ljava/lang/String;Ljava/lang/String;)V", reinterpret_cast<void*>(setDriverPathAndSphalLibraries_native) },
Yiwei Zhangf7b0a5f2019-02-19 16:04:10 -080091 { "setGpuStats", "(Ljava/lang/String;Ljava/lang/String;JJLjava/lang/String;)V", reinterpret_cast<void*>(setGpuStats_native) },
Tim Van Patten3c612842018-11-09 16:48:24 -070092 { "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 -070093 { "getShouldUseAngle", "(Ljava/lang/String;)Z", reinterpret_cast<void*>(shouldUseAngle_native) },
Cody Northrop86cedcb2017-10-20 09:03:13 -060094 { "setLayerPaths", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V", reinterpret_cast<void*>(setLayerPaths_native) },
95 { "setDebugLayers", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayers_native) },
Cody Northrop0fa1d222018-10-23 13:13:21 -060096 { "setDebugLayersGLES", "(Ljava/lang/String;)V", reinterpret_cast<void*>(setDebugLayersGLES_native) },
Jesse Hallb12249b2016-12-12 12:53:02 -080097};
98
99const char* const kGraphicsEnvironmentName = "android/os/GraphicsEnvironment";
100
101} // anonymous namespace
102
103namespace android {
104
105int register_android_os_GraphicsEnvironment(JNIEnv* env) {
106 return RegisterMethodsOrDie(env, kGraphicsEnvironmentName, g_methods, NELEM(g_methods));
107}
108
109} // namespace android