Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 380bf855 authored by Ian Elliott's avatar Ian Elliott Committed by Cody Northrop
Browse files

Use either the version-0 or version-1 opt-in/out API

Test: Manual testing
Test: cts-tradefed run singleCommand cts -m CtsAngleIntegrationHostTestCases
Bug: 80239516
Change-Id: I8778b6f480c19bdae8800bd4da223643f1619c11
parent 04e70437
Loading
Loading
Loading
Loading
+48 −10
Original line number Diff line number Diff line
@@ -51,6 +51,14 @@ extern "C" {
  typedef bool (*fpANGLEUseForApplication)(const char* appName, const char* deviceMfr,
                                           const char* deviceModel, ANGLEPreference developerOption,
                                           ANGLEPreference appPreference);

  // TODO(ianelliott@): Get this from an ANGLE header:
  typedef bool (*fpANGLEGetUtilityAPI)(unsigned int* versionToUse);

  // TODO(ianelliott@): Get this from an ANGLE header:
  typedef bool (*fpAndroidUseANGLEForApplication)(int fd, long offset, long length,
                                                  const char* appName, const char* deviceMfr,
                                                  const char* deviceModel);
}

// ----------------------------------------------------------------------------
@@ -541,21 +549,51 @@ static void* load_angle(const char* kind, android_namespace_t* ns, egl_connectio
        char model[PROPERTY_VALUE_MAX];
        property_get("ro.product.manufacturer", manufacturer, "UNSET");
        property_get("ro.product.model", model, "UNSET");
        ANGLEPreference app_preference = getAnglePref(android_getAngleAppPref());

        so = load_angle_from_namespace("feature_support", ns);
        if (so) {
            ALOGV("Temporarily loaded ANGLE's opt-in/out logic from namespace");
            fpANGLEUseForApplication fp =
            bool use_version0_API = false;
            bool use_version1_API = false;
            fpANGLEGetUtilityAPI ANGLEGetUtilityAPI =
                    (fpANGLEGetUtilityAPI)dlsym(so, "ANGLEGetUtilityAPI");
            if (ANGLEGetUtilityAPI) {
                unsigned int versionToUse = 1;
                if ((ANGLEGetUtilityAPI)(&versionToUse)) {
                    if (versionToUse == 1) {
                        use_version1_API = true;
                    } else {
                        use_version0_API = true;
                    }
                }
            } else {
                use_version0_API = true;
            }
            if (use_version1_API) {
                // Use the new version 1 API to determine if the
                // application should use the ANGLE or the native driver.
                fpAndroidUseANGLEForApplication AndroidUseANGLEForApplication =
                        (fpAndroidUseANGLEForApplication)dlsym(so, "AndroidUseANGLEForApplication");
                if (AndroidUseANGLEForApplication) {
                    use_angle = (AndroidUseANGLEForApplication)(rules_fd, rules_offset,
                                                                rules_length, app_name_str.c_str(),
                                                                manufacturer, model);
                } else {
                    ALOGW("Cannot find AndroidUseANGLEForApplication in library");
                }
            } else if (use_version0_API) {
                // Use the old version 0 API to determine if the
                // application should use the ANGLE or the native driver.
                fpANGLEUseForApplication ANGLEUseForApplication =
                        (fpANGLEUseForApplication)dlsym(so, "ANGLEUseForApplication");
            if (fp) {
                use_angle = (fp)(app_name_str.c_str(), manufacturer, model, developer_option,
                                 app_preference);
                if (ANGLEUseForApplication) {
                    ANGLEPreference app_preference = getAnglePref(android_getAngleAppPref());
                    use_angle = (ANGLEUseForApplication)(app_name_str.c_str(), manufacturer, model,
                                                         developer_option, app_preference);
                    ALOGV("Result of opt-in/out logic is %s", use_angle ? "true" : "false");
                } else {
                    ALOGW("Cannot find ANGLEUseForApplication in library");
                }

            }
            ALOGV("Close temporarily-loaded ANGLE opt-in/out logic");
            dlclose(so);
            so = nullptr;