diff options
| author | 2023-06-29 00:11:12 +0000 | |
|---|---|---|
| committer | 2023-06-30 19:39:22 +0000 | |
| commit | a19c130bead854751212cfe87562b9e808289c09 (patch) | |
| tree | 19bafc87d3a90d6fc2694298e36733716ac094b8 | |
| parent | 80684c3e12953e43e5eeab331ad97c1676ffb42a (diff) | |
Load native GLES driver when specified.
Since ANGLE and native GLES drivers can coexist, when native is
specified, the loader must load the native GLES drivers specified in
ro.hardware.egl. This patch passes this information down to the native
graphics environment so that the EGL loader can properly check.
Bug: b/283858001
Test: atest CtsAngleDeveloperOptionHostTest -c with ANGLE being default
Test: atest CtsAngleDeveloperOptionHostTest -c with native being default
Change-Id: I5b0b6df40daf436eb81009c83a5b585531765f4c
| -rw-r--r-- | core/java/android/os/GraphicsEnvironment.java | 68 | ||||
| -rw-r--r-- | core/jni/android_os_GraphicsEnvironment.cpp | 6 |
2 files changed, 45 insertions, 29 deletions
diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java index e6bdfe1b95c4..7664bada2c28 100644 --- a/core/java/android/os/GraphicsEnvironment.java +++ b/core/java/android/os/GraphicsEnvironment.java @@ -112,9 +112,17 @@ public class GraphicsEnvironment { private static final int ANGLE_GL_DRIVER_ALL_ANGLE_OFF = 0; // Values for ANGLE_GL_DRIVER_SELECTION_VALUES - private static final String ANGLE_GL_DRIVER_CHOICE_DEFAULT = "default"; - private static final String ANGLE_GL_DRIVER_CHOICE_ANGLE = "angle"; - private static final String ANGLE_GL_DRIVER_CHOICE_NATIVE = "native"; + private enum AngleDriverChoice { + DEFAULT("default"), + ANGLE("angle"), + NATIVE("native"); + + public final String choice; + + AngleDriverChoice(String choice) { + this.choice = choice; + } + } private static final String PROPERTY_RO_ANGLE_SUPPORTED = "ro.gfx.angle.supported"; @@ -195,15 +203,16 @@ public class GraphicsEnvironment { } /** - * Query to determine if ANGLE should be used + * Query to determine the ANGLE driver choice. */ - private boolean shouldUseAngle(Context context, Bundle coreSettings, String packageName) { + private AngleDriverChoice queryAngleChoice(Context context, Bundle coreSettings, + String packageName) { if (TextUtils.isEmpty(packageName)) { Log.v(TAG, "No package name specified; use the system driver"); - return false; + return AngleDriverChoice.DEFAULT; } - return shouldUseAngleInternal(context, coreSettings, packageName); + return queryAngleChoiceInternal(context, coreSettings, packageName); } private int getVulkanVersion(PackageManager pm) { @@ -424,10 +433,11 @@ public class GraphicsEnvironment { * forces a choice; * 3) Use ANGLE if isAngleEnabledByGameMode() returns true; */ - private boolean shouldUseAngleInternal(Context context, Bundle bundle, String packageName) { + private AngleDriverChoice queryAngleChoiceInternal(Context context, Bundle bundle, + String packageName) { // Make sure we have a good package name if (TextUtils.isEmpty(packageName)) { - return false; + return AngleDriverChoice.DEFAULT; } // Check the semi-global switch (i.e. once system has booted enough) for whether ANGLE @@ -442,7 +452,7 @@ public class GraphicsEnvironment { } if (allUseAngle == ANGLE_GL_DRIVER_ALL_ANGLE_ON) { Log.v(TAG, "Turn on ANGLE for all applications."); - return true; + return AngleDriverChoice.ANGLE; } // Get the per-application settings lists @@ -465,7 +475,7 @@ public class GraphicsEnvironment { + optInPackages.size() + ", " + "number of values: " + optInValues.size()); - return mEnabledByGameMode; + return mEnabledByGameMode ? AngleDriverChoice.ANGLE : AngleDriverChoice.DEFAULT; } // See if this application is listed in the per-application settings list @@ -473,7 +483,7 @@ public class GraphicsEnvironment { if (pkgIndex < 0) { Log.v(TAG, packageName + " is not listed in per-application setting"); - return mEnabledByGameMode; + return mEnabledByGameMode ? AngleDriverChoice.ANGLE : AngleDriverChoice.DEFAULT; } mAngleOptInIndex = pkgIndex; @@ -483,14 +493,14 @@ public class GraphicsEnvironment { Log.v(TAG, "ANGLE Developer option for '" + packageName + "' " + "set to: '" + optInValue + "'"); - if (optInValue.equals(ANGLE_GL_DRIVER_CHOICE_ANGLE)) { - return true; - } else if (optInValue.equals(ANGLE_GL_DRIVER_CHOICE_NATIVE)) { - return false; + if (optInValue.equals(AngleDriverChoice.ANGLE.choice)) { + return AngleDriverChoice.ANGLE; + } else if (optInValue.equals(AngleDriverChoice.NATIVE.choice)) { + return AngleDriverChoice.NATIVE; } else { // The user either chose default or an invalid value; go with the default driver or what // the game mode indicates - return mEnabledByGameMode; + return mEnabledByGameMode ? AngleDriverChoice.ANGLE : AngleDriverChoice.DEFAULT; } } @@ -558,7 +568,13 @@ public class GraphicsEnvironment { private boolean setupAngle(Context context, Bundle bundle, PackageManager packageManager, String packageName) { - if (!shouldUseAngle(context, bundle, packageName)) { + final AngleDriverChoice angleDriverChoice = queryAngleChoice(context, bundle, packageName); + if (angleDriverChoice == AngleDriverChoice.DEFAULT) { + return false; + } + + if (queryAngleChoice(context, bundle, packageName) == AngleDriverChoice.NATIVE) { + nativeSetAngleInfo("", true, packageName, null); return false; } @@ -627,10 +643,10 @@ public class GraphicsEnvironment { Log.d(TAG, "ANGLE package libs: " + paths); } - // If we make it to here, ANGLE will be used. Call setAngleInfo() with the package name, - // and features to use. + // If we make it to here, ANGLE apk will be used. Call nativeSetAngleInfo() with the + // application package name and ANGLE features to use. final String[] features = getAngleEglFeatures(context, bundle); - setAngleInfo(paths, false, packageName, features); + nativeSetAngleInfo(paths, false, packageName, features); return true; } @@ -652,10 +668,10 @@ public class GraphicsEnvironment { return false; } - // If we make it to here, ANGLE will be used. Call setAngleInfo() with the package name, - // and features to use. + // If we make it to here, system ANGLE will be used. Call nativeSetAngleInfo() with + // the application package name and ANGLE features to use. final String[] features = getAngleEglFeatures(context, bundle); - setAngleInfo("", true, packageName, features); + nativeSetAngleInfo("system", false, packageName, features); return true; } @@ -936,8 +952,8 @@ public class GraphicsEnvironment { private static native void setDriverPathAndSphalLibraries(String path, String sphalLibraries); private static native void setGpuStats(String driverPackageName, String driverVersionName, long driverVersionCode, long driverBuildTime, String appPackageName, int vulkanVersion); - private static native void setAngleInfo(String path, boolean useSystemAngle, String packageName, - String[] features); + private static native void nativeSetAngleInfo(String path, boolean useNativeDriver, + String packageName, String[] features); private static native boolean setInjectLayersPrSetDumpable(); private static native void nativeToggleAngleAsSystemDriver(boolean enabled); diff --git a/core/jni/android_os_GraphicsEnvironment.cpp b/core/jni/android_os_GraphicsEnvironment.cpp index afc3cbd15f88..8fc30d1c248d 100644 --- a/core/jni/android_os_GraphicsEnvironment.cpp +++ b/core/jni/android_os_GraphicsEnvironment.cpp @@ -50,7 +50,7 @@ void setGpuStats_native(JNIEnv* env, jobject clazz, jstring driverPackageName, appPackageNameChars.c_str(), vulkanVersion); } -void setAngleInfo_native(JNIEnv* env, jobject clazz, jstring path, jboolean useSystemAngle, +void setAngleInfo_native(JNIEnv* env, jobject clazz, jstring path, jboolean useNativeDriver, jstring packageName, jobjectArray featuresObj) { ScopedUtfChars pathChars(env, path); ScopedUtfChars packageNameChars(env, packageName); @@ -73,7 +73,7 @@ void setAngleInfo_native(JNIEnv* env, jobject clazz, jstring path, jboolean useS } } - android::GraphicsEnv::getInstance().setAngleInfo(pathChars.c_str(), useSystemAngle, + android::GraphicsEnv::getInstance().setAngleInfo(pathChars.c_str(), useNativeDriver, packageNameChars.c_str(), features); } @@ -118,7 +118,7 @@ const JNINativeMethod g_methods[] = { reinterpret_cast<void*>(setGpuStats_native)}, {"setInjectLayersPrSetDumpable", "()Z", reinterpret_cast<void*>(setInjectLayersPrSetDumpable_native)}, - {"setAngleInfo", "(Ljava/lang/String;ZLjava/lang/String;[Ljava/lang/String;)V", + {"nativeSetAngleInfo", "(Ljava/lang/String;ZLjava/lang/String;[Ljava/lang/String;)V", reinterpret_cast<void*>(setAngleInfo_native)}, {"setLayerPaths", "(Ljava/lang/ClassLoader;Ljava/lang/String;)V", reinterpret_cast<void*>(setLayerPaths_native)}, |