From 8d8137ed429d2648aa6c6bfdaa8007c668042448 Mon Sep 17 00:00:00 2001 From: Ian Elliott Date: Tue, 26 Apr 2022 03:02:46 +0000 Subject: [PATCH] Revert "Restore ANGLE being enabled for game dashboard" This reverts commit 3a947939dc213495190ae329d6d5db62d7348d1c. Reason for revert: Allow for revert of "Change Android platform for when ANGLE is default". See: b/230126358: candidate for test breakage on cf_x86_64_phone-userdebug Reverted Changes: I2446b18e9:Change Android platform for when ANGLE is default I83e59002b:Change Android platform for when ANGLE is default Change-Id: Ib835ee46829a8e9106b183ca32816ca62e306b1c --- core/java/android/os/GraphicsEnvironment.java | 107 ++++++++---------- 1 file changed, 49 insertions(+), 58 deletions(-) diff --git a/core/java/android/os/GraphicsEnvironment.java b/core/java/android/os/GraphicsEnvironment.java index 41a2bb462fe3d..c2208de32569f 100644 --- a/core/java/android/os/GraphicsEnvironment.java +++ b/core/java/android/os/GraphicsEnvironment.java @@ -122,11 +122,6 @@ public class GraphicsEnvironment { // The following value is a deprecated choice for "legacy" private static final String ANGLE_GL_DRIVER_CHOICE_NATIVE = "native"; - // Values returned by getDriverForPackage() and getDefaultDriverToUse() (avoid returning - // strings for performance reasons) - private static final int ANGLE_GL_DRIVER_TO_USE_LEGACY = 0; - private static final int ANGLE_GL_DRIVER_TO_USE_ANGLE = 1; - private ClassLoader mClassLoader; private String mLibrarySearchPaths; private String mLibraryPermittedPaths; @@ -170,10 +165,8 @@ public class GraphicsEnvironment { */ mEglLegacyDriver = "mali"; /*}*/ - } else { - mEglLegacyDriver = eglSystemDriver; + Log.v(TAG, "Legacy GLES driver is '" + mEglLegacyDriver + "'"); } - Log.v(TAG, "Legacy GLES driver is '" + mEglLegacyDriver + "'"); // Setup ANGLE and pass down ANGLE details to the C++ code Trace.traceBegin(Trace.TRACE_TAG_GRAPHICS, "setupAngle"); @@ -232,8 +225,22 @@ public class GraphicsEnvironment { return mAngleIsSystemDriver ? true : false; } - final int driverToUse = getDriverForPackage(context, coreSettings, packageName); - return driverToUse == ANGLE_GL_DRIVER_TO_USE_ANGLE; + // getDriverForPackage() will change "default" into either "angle" or "legacy" + final String devOptIn = getDriverForPackage(context, coreSettings, packageName); + Log.v(TAG, "ANGLE Developer option for '" + packageName + "' " + + "set to: '" + devOptIn + "'"); + + // We only want to use ANGLE if the developer has explicitly chosen something other than + // default driver. + final boolean forceAngle = devOptIn.equals(ANGLE_GL_DRIVER_CHOICE_ANGLE); + final boolean forceLegacy = devOptIn.equals(ANGLE_GL_DRIVER_CHOICE_LEGACY); + if (forceAngle || forceLegacy) { + Log.v(TAG, "ANGLE developer option for " + packageName + ": " + devOptIn); + } + + final boolean gameModeEnabledAngle = isAngleEnabledByGameMode(context, packageName); + + return !forceLegacy && (forceAngle || gameModeEnabledAngle); } private int getVulkanVersion(PackageManager pm) { @@ -434,35 +441,17 @@ public class GraphicsEnvironment { } /** - * Return the appropriate "default" driver, unless overridden by isAngleEnabledByGameMode(). + * Return the appropriate "default" driver choice. */ - private int getDefaultDriverToUse(Context context, String packageName) { - if (mAngleIsSystemDriver || isAngleEnabledByGameMode(context, packageName)) { - return ANGLE_GL_DRIVER_TO_USE_ANGLE; + private String getDefaultDriverChoice() { + if (mAngleIsSystemDriver) { + return ANGLE_GL_DRIVER_CHOICE_ANGLE; } else { - return ANGLE_GL_DRIVER_TO_USE_LEGACY; + return ANGLE_GL_DRIVER_CHOICE_LEGACY; } } - /* - * Determine which GLES "driver" should be used for the package, taking into account the - * following factors (in priority order): - * - * 1) The semi-global switch (i.e. Settings.Global.ANGLE_GL_DRIVER_ALL_ANGLE; which is set by - * the "angle_gl_driver_all_angle" setting; which forces a driver for all processes that - * start after the Java run time is up), if it forces a choice; otherwise ... - * 2) The per-application switch (i.e. Settings.Global.ANGLE_GL_DRIVER_SELECTION_PKGS and - * Settings.Global.ANGLE_GL_DRIVER_SELECTION_VALUES; which corresponds to the - * “angle_gl_driver_selection_pkgs” and “angle_gl_driver_selection_values” settings); if it - * forces a choice; otherwise ... - * 3) Use ANGLE if isAngleEnabledByGameMode() returns true; otherwise ... - * 4) The global switch (i.e. use the system driver, whether ANGLE or legacy; - * a.k.a. mAngleIsSystemDriver, which is set by the device’s “ro.hardware.egl” property) - * - * Factors 1 and 2 are decided by this method. Factors 3 and 4 are decided by - * getDefaultDriverToUse(). - */ - private int getDriverForPackage(Context context, Bundle bundle, String packageName) { + private String getDriverForPackage(Context context, Bundle bundle, String packageName) { // Check the semi-global switch (i.e. once system has booted enough) for whether ANGLE // should be forced on or off for "all appplications" final int allUseAngle; @@ -475,16 +464,16 @@ public class GraphicsEnvironment { } if (allUseAngle == ANGLE_GL_DRIVER_ALL_ANGLE_ON) { Log.v(TAG, "Turn on ANGLE for all applications."); - return ANGLE_GL_DRIVER_TO_USE_ANGLE; + return ANGLE_GL_DRIVER_CHOICE_ANGLE; } if (allUseAngle == ANGLE_GL_DRIVER_ALL_LEGACY) { Log.v(TAG, "Disable ANGLE for all applications."); - return ANGLE_GL_DRIVER_TO_USE_LEGACY; + return ANGLE_GL_DRIVER_CHOICE_LEGACY; } // Make sure we have a good package name if (TextUtils.isEmpty(packageName)) { - return getDefaultDriverToUse(context, packageName); + return getDefaultDriverChoice(); } // Get the per-application settings lists @@ -493,9 +482,9 @@ public class GraphicsEnvironment { contentResolver, bundle, Settings.Global.ANGLE_GL_DRIVER_SELECTION_PKGS); final List optInValues = getGlobalSettingsString( contentResolver, bundle, Settings.Global.ANGLE_GL_DRIVER_SELECTION_VALUES); - Log.v(TAG, "Currently set values for:"); - Log.v(TAG, " angle_gl_driver_selection_pkgs = " + optInPackages); - Log.v(TAG, " angle_gl_driver_selection_values =" + optInValues); + Log.v(TAG, "getDriverForPackage(): Currently set values for:"); + Log.v(TAG, "getDriverForPackage(): angle_gl_driver_selection_pkgs =" + optInPackages); + Log.v(TAG, "getDriverForPackage(): angle_gl_driver_selection_values =" + optInValues); // Make sure we have good settings to use if (optInPackages.size() != optInValues.size()) { @@ -505,7 +494,7 @@ public class GraphicsEnvironment { + optInPackages.size() + ", " + "number of values: " + optInValues.size()); - return getDefaultDriverToUse(context, packageName); + return getDefaultDriverChoice(); } // See if this application is listed in the per-application settings lists @@ -515,7 +504,7 @@ public class GraphicsEnvironment { // The application is NOT listed in the per-application settings lists; and so use the // system driver (i.e. either ANGLE or the Legacy driver) Log.v(TAG, "getDriverForPackage(): No per-application setting"); - return getDefaultDriverToUse(context, packageName); + return getDefaultDriverChoice(); } mAngleOptInIndex = pkgIndex; @@ -526,19 +515,13 @@ public class GraphicsEnvironment { // setting--choosing the current system driver if the setting is "default" (i.e. either // ANGLE or the Legacy driver) String rtnValue = optInValues.get(pkgIndex); - Log.v(TAG, - "ANGLE Developer option for '" + packageName + "' " - + "set to: '" + rtnValue + "'"); - if (rtnValue.equals(ANGLE_GL_DRIVER_CHOICE_ANGLE)) { - return ANGLE_GL_DRIVER_TO_USE_ANGLE; - } else if (rtnValue.equals(ANGLE_GL_DRIVER_CHOICE_NATIVE) - || rtnValue.equals(ANGLE_GL_DRIVER_CHOICE_LEGACY)) { - return ANGLE_GL_DRIVER_TO_USE_LEGACY; - } else { - // The user either chose default or an invalid value; go with the default driver or what - // the game dashboard indicates - return getDefaultDriverToUse(context, packageName); + if (rtnValue.equals(ANGLE_GL_DRIVER_CHOICE_DEFAULT)) { + return getDefaultDriverChoice(); } + if (rtnValue.equals(ANGLE_GL_DRIVER_CHOICE_NATIVE)) { + return ANGLE_GL_DRIVER_CHOICE_LEGACY; + } + return rtnValue; } /** @@ -661,11 +644,19 @@ public class GraphicsEnvironment { Log.v(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. + // We need to call setAngleInfo() with the package name and the developer option value + // (legacy/angle/other). Later, when we are actually trying to load a driver, + // GraphicsEnv::getShouldUseAngle() has seen the package name before and can confidently + // answer yes/no based on the previously set developer option value. + final String devOptIn; final String[] features = getAngleEglFeatures(context, bundle); - setAngleInfo( - paths, packageName, mAngleIsSystemDriver, ANGLE_GL_DRIVER_CHOICE_ANGLE, features); + final boolean gameModeEnabledAngle = isAngleEnabledByGameMode(context, packageName); + if (gameModeEnabledAngle) { + devOptIn = ANGLE_GL_DRIVER_CHOICE_ANGLE; + } else { + devOptIn = getDriverForPackage(context, bundle, packageName); + } + setAngleInfo(paths, packageName, mAngleIsSystemDriver, devOptIn, features); return true; }