Commit 6fdac95a56d450867f4b2283315487a3c1c312fe

Jason Macnak 2022-12-15T20:36:01

Mirror Android AHB formats in ANGLE owned enum The existing code seems to try to keep all AHB formats defined in android_util.cpp (potentially in an attempt to simplify format conversions?). However, trying to avoid redefinition errors when conditionally re-defining the AHB formats across builds/branches is difficult. IIUC, there are two levels at play when building for Android: 1) "target level": the level of the phone/device you are building for. 2) "build level": the level of the repository/checkout you are building from. The "target level" (__ANDROID_API__) cannot be used to guard the definitions in android_util.cpp because it is possible to build for an older device in a newer branch. For example, suppose AHARDWAREBUFFER_FORMAT_X was introduced in Android T. If ANGLE tried to redefine AHARDWAREBUFFER_FORMAT_X in android_util.cpp with the guard "if __ANDROID_API__ < T", re-definition errors would still occur when building for Android S devices ( __ANDROID_API__ set to S) from inside of an Android T branch because the format would still be defined in android/hardware_buffer.h. A failure of this type can be seen in aosp/2308065 which tried to guard AHARDWAREBUFFER_FORMAT_R8_UNORM with "if __ANDROID_API__ < 33". Additionally, Android sets __ANDROID_API__ to 10000 before releases are cut and it is supposed to be fixed at release time. However, this has been observed to not be fixed on some less maintained side branches. Detecting the "build level" seems to be quite difficult. When building from outside of Android, this is the NDK level which can be detected using __ANDROID_NDK__ and __NDK_MAJOR__. When building from inside of Android, this is the latest level available on your specific branch. I believe this can only be found by incrementally checking for the existence of the various __ANDROID_API_R__, __ANDROID_API_S__, etc defines. This alternative can be seen in https://crrev.com/c/4039066. However, this is very difficult to find and read. Instead, let's just define ANGLE's own enum which mirrors the Android enums which can be used without having to worry about the current build system or release/branch. Bug: b/259551816 Test: cvd start --gpu_mode=guest_swiftshader Test: atest librenderengine_test Test: ANGLE presubmit Test: Android presubmit on aosp/master (aosp/2360445) Test: Android presubmit on aosp/android13-gsi (aosp/2360447) Test: Android presubmit on aosp/android11-gsi (aosp/2360520) Change-Id: I62f12cb0e1cc4b3b24aab7b85f39360a2cd2e438 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/4112148 Commit-Queue: Jason Macnak <natsu@google.com> Reviewed-by: Ian Elliott <ianelliott@google.com> Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>