diff options
95 files changed, 1465 insertions, 1003 deletions
diff --git a/cmds/atrace/atrace.rc b/cmds/atrace/atrace.rc index 3e6d2e01f8..a3e29a81f1 100644 --- a/cmds/atrace/atrace.rc +++ b/cmds/atrace/atrace.rc @@ -317,7 +317,7 @@ on late-init && property:ro.boot.fastboot.boottrace= # Only create the tracing instance if persist.mm_events.enabled # Attempting to remove the tracing instance after it has been created # will likely fail with EBUSY as it would be in use by traced_probes. -on post-fs-data && property:persist.mm_events.enabled=true +on mm_events_property_available && property:persist.mm_events.enabled=true # Create MM Events Tracing Instance for Kmem Activity Trigger mkdir /sys/kernel/debug/tracing/instances/mm_events 0755 system system mkdir /sys/kernel/tracing/instances/mm_events 0755 system system @@ -402,6 +402,9 @@ on post-fs-data && property:persist.mm_events.enabled=true chmod 0666 /sys/kernel/debug/tracing/instances/mm_events/per_cpu/cpu23/trace chmod 0666 /sys/kernel/tracing/instances/mm_events/per_cpu/cpu23/trace +on property:ro.persistent_properties.ready=true + trigger mm_events_property_available + # Handle hyp tracing instance on late-init && property:ro.boot.hypervisor.vm.supported=1 diff --git a/cmds/dumpstate/Android.bp b/cmds/dumpstate/Android.bp index 23f185e305..341fabb32a 100644 --- a/cmds/dumpstate/Android.bp +++ b/cmds/dumpstate/Android.bp @@ -114,6 +114,7 @@ cc_defaults { "libincidentcompanion", "libdumpsys", "libserviceutils", + "android.tracing.flags_c_lib", ], } diff --git a/cmds/dumpstate/dumpstate.cpp b/cmds/dumpstate/dumpstate.cpp index 5ee6b155f2..5f109fb224 100644 --- a/cmds/dumpstate/dumpstate.cpp +++ b/cmds/dumpstate/dumpstate.cpp @@ -17,49 +17,9 @@ #define LOG_TAG "dumpstate" #define ATRACE_TAG ATRACE_TAG_ALWAYS -#include <dirent.h> -#include <errno.h> -#include <fcntl.h> -#include <inttypes.h> -#include <libgen.h> -#include <limits.h> -#include <math.h> -#include <poll.h> -#include <stdbool.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <sys/mount.h> -#include <sys/poll.h> -#include <sys/prctl.h> -#include <sys/resource.h> -#include <sys/stat.h> -#include <sys/time.h> -#include <sys/wait.h> -#include <signal.h> -#include <stdarg.h> -#include <string.h> -#include <sys/capability.h> -#include <sys/inotify.h> -#include <sys/klog.h> -#include <time.h> -#include <unistd.h> - -#include <chrono> -#include <cmath> -#include <fstream> -#include <functional> -#include <future> -#include <memory> -#include <numeric> -#include <regex> -#include <set> -#include <string> -#include <utility> -#include <vector> +#include "dumpstate.h" #include <aidl/android/hardware/dumpstate/IDumpstateDevice.h> -#include <android_app_admin_flags.h> #include <android-base/file.h> #include <android-base/properties.h> #include <android-base/scopeguard.h> @@ -74,6 +34,8 @@ #include <android/hardware/dumpstate/1.1/types.h> #include <android/hidl/manager/1.0/IServiceManager.h> #include <android/os/IIncidentCompanion.h> +#include <android_app_admin_flags.h> +#include <android_tracing.h> #include <binder/IServiceManager.h> #include <cutils/multiuser.h> #include <cutils/native_handle.h> @@ -81,21 +43,60 @@ #include <cutils/sockets.h> #include <cutils/trace.h> #include <debuggerd/client.h> +#include <dirent.h> #include <dumpsys.h> #include <dumputils/dump_utils.h> +#include <errno.h> +#include <fcntl.h> #include <hardware_legacy/power.h> #include <hidl/ServiceManagement.h> +#include <inttypes.h> +#include <libgen.h> +#include <limits.h> #include <log/log.h> #include <log/log_read.h> +#include <math.h> #include <openssl/sha.h> +#include <poll.h> #include <private/android_filesystem_config.h> #include <private/android_logger.h> #include <serviceutils/PriorityDumper.h> +#include <signal.h> +#include <stdarg.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/capability.h> +#include <sys/inotify.h> +#include <sys/klog.h> +#include <sys/mount.h> +#include <sys/poll.h> +#include <sys/prctl.h> +#include <sys/resource.h> +#include <sys/stat.h> +#include <sys/time.h> +#include <sys/wait.h> +#include <time.h> +#include <unistd.h> #include <utils/StrongPointer.h> #include <vintf/VintfObject.h> + +#include <chrono> +#include <cmath> +#include <fstream> +#include <functional> +#include <future> +#include <memory> +#include <numeric> +#include <regex> +#include <set> +#include <string> +#include <utility> +#include <vector> + #include "DumpstateInternal.h" #include "DumpstateService.h" -#include "dumpstate.h" namespace dumpstate_hal_hidl_1_0 = android::hardware::dumpstate::V1_0; namespace dumpstate_hal_hidl = android::hardware::dumpstate::V1_1; @@ -3455,16 +3456,24 @@ void Dumpstate::MaybeSnapshotUiTraces() { return; } - const std::vector<std::vector<std::string>> dumpTracesForBugReportCommands = { - {"dumpsys", "activity", "service", "SystemUIService", "WMShell", "protolog", - "save-for-bugreport"}, - {"dumpsys", "activity", "service", "SystemUIService", "WMShell", "transitions", "tracing", - "save-for-bugreport"}, + std::vector<std::vector<std::string>> dumpTracesForBugReportCommands = { {"cmd", "input_method", "tracing", "save-for-bugreport"}, {"cmd", "window", "tracing", "save-for-bugreport"}, {"cmd", "window", "shell", "tracing", "save-for-bugreport"}, }; + if (!android_tracing_perfetto_transition_tracing()) { + dumpTracesForBugReportCommands.push_back({"dumpsys", "activity", "service", + "SystemUIService", "WMShell", "transitions", + "tracing", "save-for-bugreport"}); + } + + if (!android_tracing_perfetto_protolog()) { + dumpTracesForBugReportCommands.push_back({"dumpsys", "activity", "service", + "SystemUIService", "WMShell", "protolog", + "save-for-bugreport"}); + } + for (const auto& command : dumpTracesForBugReportCommands) { RunCommand( // Empty name because it's not intended to be classified as a bugreport section. diff --git a/cmds/dumpstate/tests/dumpstate_test.cpp b/cmds/dumpstate/tests/dumpstate_test.cpp index fc828864d5..2afabed813 100644 --- a/cmds/dumpstate/tests/dumpstate_test.cpp +++ b/cmds/dumpstate/tests/dumpstate_test.cpp @@ -16,23 +16,7 @@ #define LOG_TAG "dumpstate_test" -#include "DumpstateInternal.h" -#include "DumpstateService.h" -#include "android/os/BnDumpstate.h" #include "dumpstate.h" -#include "DumpPool.h" - -#include <gmock/gmock.h> -#include <gmock/gmock-matchers.h> -#include <gtest/gtest.h> - -#include <fcntl.h> -#include <libgen.h> -#include <signal.h> -#include <sys/types.h> -#include <unistd.h> -#include <filesystem> -#include <thread> #include <aidl/android/hardware/dumpstate/IDumpstateDevice.h> #include <android-base/file.h> @@ -41,10 +25,27 @@ #include <android-base/strings.h> #include <android-base/unique_fd.h> #include <android/hardware/dumpstate/1.1/types.h> +#include <android_tracing.h> #include <cutils/log.h> #include <cutils/properties.h> +#include <fcntl.h> +#include <gmock/gmock-matchers.h> +#include <gmock/gmock.h> +#include <gtest/gtest.h> +#include <libgen.h> +#include <signal.h> +#include <sys/types.h> +#include <unistd.h> #include <ziparchive/zip_archive.h> +#include <filesystem> +#include <thread> + +#include "DumpPool.h" +#include "DumpstateInternal.h" +#include "DumpstateService.h" +#include "android/os/BnDumpstate.h" + namespace android { namespace os { namespace dumpstate { @@ -999,10 +1000,13 @@ TEST_F(DumpstateTest, DumpPool_withParallelRunDisabled_isNull) { TEST_F(DumpstateTest, PreDumpUiData) { // These traces are always enabled, i.e. they are always pre-dumped - const std::vector<std::filesystem::path> uiTraces = { - std::filesystem::path{"/data/misc/wmtrace/wm_transition_trace.winscope"}, - std::filesystem::path{"/data/misc/wmtrace/shell_transition_trace.winscope"}, - }; + std::vector<std::filesystem::path> uiTraces; + if (!android_tracing_perfetto_transition_tracing()) { + uiTraces.push_back( + std::filesystem::path{"/data/misc/wmtrace/wm_transition_trace.winscope"}); + uiTraces.push_back( + std::filesystem::path{"/data/misc/wmtrace/shell_transition_trace.winscope"}); + } for (const auto traceFile : uiTraces) { std::system(("rm -f " + traceFile.string()).c_str()); diff --git a/include/android/input.h b/include/android/input.h index 16d86af44c..b5c1e5c354 100644 --- a/include/android/input.h +++ b/include/android/input.h @@ -1490,6 +1490,14 @@ int32_t AMotionEvent_getClassification(const AInputEvent* motion_event) */ const AInputEvent* AMotionEvent_fromJava(JNIEnv* env, jobject motionEvent) __INTRODUCED_IN(31); +/** + * Creates a java android.view.InputEvent object that is a copy of the specified native + * {@link AInputEvent}. Returns null on error + * + * Available since API level 35. + */ +jobject AInputEvent_toJava(JNIEnv* env, const AInputEvent* aInputEvent) __INTRODUCED_IN(35); + struct AInputQueue; /** * Input queue diff --git a/include/android/surface_control.h b/include/android/surface_control.h index cce2e46471..321737e226 100644 --- a/include/android/surface_control.h +++ b/include/android/surface_control.h @@ -528,9 +528,8 @@ void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transactio /** * Sets the desired extended range brightness for the layer. This only applies for layers whose - * dataspace has RANGE_EXTENDED set on it. - * - * Available since API level 34. + * dataspace has RANGE_EXTENDED set on it. See: ASurfaceTransaction_setDesiredHdrHeadroom, prefer + * using this API for formats that encode an HDR/SDR ratio as part of generating the buffer. * * @param surface_control The layer whose extended range brightness is being specified * @param currentBufferRatio The current hdr/sdr ratio of the current buffer as represented as @@ -564,6 +563,12 @@ void ASurfaceTransaction_setHdrMetadata_cta861_3(ASurfaceTransaction* transactio * determined entirely by the dataspace being used (ie, typically SDR * however PQ or HLG transfer functions will still result in HDR) * + * When called after ASurfaceTransaction_setDesiredHdrHeadroom, the + * desiredRatio will override the desiredHeadroom provided by + * ASurfaceTransaction_setDesiredHdrHeadroom. Conversely, when called before + * ASurfaceTransaction_setDesiredHdrHeadroom, the desiredHeadroom provided by + *. ASurfaceTransaction_setDesiredHdrHeadroom will override the desiredRatio. + * * Must be finite && >= 1.0f * * Available since API level 34. @@ -574,6 +579,45 @@ void ASurfaceTransaction_setExtendedRangeBrightness(ASurfaceTransaction* transac float desiredRatio) __INTRODUCED_IN(__ANDROID_API_U__); /** + * Sets the desired hdr headroom for the layer. See: ASurfaceTransaction_setExtendedRangeBrightness, + * prefer using this API for formats that conform to HDR standards like HLG or HDR10, that do not + * communicate a HDR/SDR ratio as part of generating the buffer. + * + * @param surface_control The layer whose desired hdr headroom is being specified + * + * @param desiredHeadroom The desired hdr/sdr ratio as represented as peakHdrBrightnessInNits / + * targetSdrWhitePointInNits. This can be used to communicate the max + * desired brightness range of the panel. The system may not be able to, or + * may choose not to, deliver the requested range. + * + * While requesting a large desired ratio will result in the most + * dynamic range, voluntarily reducing the requested range can help + * improve battery life as well as can improve quality by ensuring + * greater bit depth is allocated to the luminance range in use. + * + * Default value is 0.0f and indicates that the system will choose the best + * headroom for this surface control's content. Typically, this means that + * HLG/PQ encoded content will be displayed with some HDR headroom greater + * than 1.0. + * + * When called after ASurfaceTransaction_setExtendedRangeBrightness, the + * desiredHeadroom will override the desiredRatio provided by + * ASurfaceTransaction_setExtendedRangeBrightness. Conversely, when called + * before ASurfaceTransaction_setExtendedRangeBrightness, the desiredRatio + * provided by ASurfaceTransaction_setExtendedRangeBrightness will override + * the desiredHeadroom. + * + * Must be finite && >= 1.0f or 0.0f to indicate there is no desired + * headroom. + * + * Available since API level 35. + */ +void ASurfaceTransaction_setDesiredHdrHeadroom(ASurfaceTransaction* transaction, + ASurfaceControl* surface_control, + float desiredHeadroom) + __INTRODUCED_IN(__ANDROID_API_V__); + +/** * Same as ASurfaceTransaction_setFrameRateWithChangeStrategy(transaction, surface_control, * frameRate, compatibility, ANATIVEWINDOW_CHANGE_FRAME_RATE_ONLY_IF_SEAMLESS). * diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp index ae0fb018ef..941e0918f7 100644 --- a/libs/binder/Android.bp +++ b/libs/binder/Android.bp @@ -320,6 +320,24 @@ cc_defaults { "ServiceManagerHost.cpp", ], }, + android: { + shared_libs: [ + "libapexsupport", + "libvndksupport", + ], + }, + recovery: { + exclude_shared_libs: [ + "libapexsupport", + "libvndksupport", + ], + }, + native_bridge: { + exclude_shared_libs: [ + "libapexsupport", + "libvndksupport", + ], + }, }, cflags: [ "-DBINDER_WITH_KERNEL_IPC", diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp index fe566fccb2..39573ec54d 100644 --- a/libs/binder/IServiceManager.cpp +++ b/libs/binder/IServiceManager.cpp @@ -40,6 +40,11 @@ #include "ServiceManagerHost.h" #endif +#if defined(__ANDROID__) && !defined(__ANDROID_RECOVERY__) && !defined(__ANDROID_NATIVE_BRIDGE__) +#include <android/apexsupport.h> +#include <vndksupport/linker.h> +#endif + #include "Static.h" namespace android { @@ -259,6 +264,27 @@ bool checkPermission(const String16& permission, pid_t pid, uid_t uid, bool logP } } +void* openDeclaredPassthroughHal(const String16& interface, const String16& instance, int flag) { +#if defined(__ANDROID__) && !defined(__ANDROID_RECOVERY__) && !defined(__ANDROID_NATIVE_BRIDGE__) + sp<IServiceManager> sm = defaultServiceManager(); + String16 name = interface + String16("/") + instance; + if (!sm->isDeclared(name)) { + return nullptr; + } + String16 libraryName = interface + String16(".") + instance + String16(".so"); + if (auto updatableViaApex = sm->updatableViaApex(name); updatableViaApex.has_value()) { + return AApexSupport_loadLibrary(String8(libraryName).c_str(), + String8(*updatableViaApex).c_str(), flag); + } + return android_load_sphal_library(String8(libraryName).c_str(), flag); +#else + (void)interface; + (void)instance; + (void)flag; + return nullptr; +#endif +} + #endif //__ANDROID_VNDK__ // ---------------------------------------------------------------------- diff --git a/libs/binder/include/binder/IServiceManager.h b/libs/binder/include/binder/IServiceManager.h index 55167a7db0..486bdfba78 100644 --- a/libs/binder/include/binder/IServiceManager.h +++ b/libs/binder/include/binder/IServiceManager.h @@ -207,6 +207,8 @@ status_t getService(const String16& name, sp<INTERFACE>* outService) return NAME_NOT_FOUND; } +void* openDeclaredPassthroughHal(const String16& interface, const String16& instance, int flag); + bool checkCallingPermission(const String16& permission); bool checkCallingPermission(const String16& permission, int32_t* outPid, int32_t* outUid); diff --git a/libs/binder/ndk/include_platform/android/binder_manager.h b/libs/binder/ndk/include_platform/android/binder_manager.h index 316a79cfee..b34b30d638 100644 --- a/libs/binder/ndk/include_platform/android/binder_manager.h +++ b/libs/binder/ndk/include_platform/android/binder_manager.h @@ -243,6 +243,18 @@ void AServiceManager_getUpdatableApexName(const char* instance, void* context, __INTRODUCED_IN(__ANDROID_API_U__); /** + * Opens a declared passthrough HAL. + * + * \param instance identifier of the passthrough service (e.g. "mapper") + * \param instance identifier of the implemenatation (e.g. "default") + * \param flag passed to dlopen() + */ +void* AServiceManager_openDeclaredPassthroughHal(const char* interface, const char* instance, + int flag) + // TODO(b/302113279) use __INTRODUCED_LLNDK for vendor variants + __INTRODUCED_IN(__ANDROID_API_V__); + +/** * Prevent lazy services without client from shutting down their process * * This should only be used if it is every eventually set to false. If a diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt index 0843a8e648..de624e44f6 100644 --- a/libs/binder/ndk/libbinder_ndk.map.txt +++ b/libs/binder/ndk/libbinder_ndk.map.txt @@ -204,6 +204,7 @@ LIBBINDER_NDK35 { # introduced=VanillaIceCream APersistableBundle_getDoubleVectorKeys; APersistableBundle_getStringVectorKeys; APersistableBundle_getPersistableBundleKeys; + AServiceManager_openDeclaredPassthroughHal; # systemapi llndk }; LIBBINDER_NDK_PLATFORM { diff --git a/libs/binder/ndk/service_manager.cpp b/libs/binder/ndk/service_manager.cpp index 3bfdc59ec2..5529455cc6 100644 --- a/libs/binder/ndk/service_manager.cpp +++ b/libs/binder/ndk/service_manager.cpp @@ -200,6 +200,13 @@ void AServiceManager_getUpdatableApexName(const char* instance, void* context, callback(String8(updatableViaApex.value()).c_str(), context); } } +void* AServiceManager_openDeclaredPassthroughHal(const char* interface, const char* instance, + int flag) { + LOG_ALWAYS_FATAL_IF(interface == nullptr, "interface == nullptr"); + LOG_ALWAYS_FATAL_IF(instance == nullptr, "instance == nullptr"); + + return openDeclaredPassthroughHal(String16(interface), String16(instance), flag); +} void AServiceManager_forceLazyServicesPersist(bool persist) { auto serviceRegistrar = android::binder::LazyServiceRegistrar::getInstance(); serviceRegistrar.forcePersist(persist); diff --git a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp index cab1a60370..966ec959b6 100644 --- a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +++ b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp @@ -984,7 +984,7 @@ int main(int argc, char* argv[]) { return generatedFlaggedService(test_flags, kBinderNdkUnitTestServiceFlagged); } - ABinderProcess_setThreadPoolMaxThreadCount(1); // to receive death notifications/callbacks + ABinderProcess_setThreadPoolMaxThreadCount(0); ABinderProcess_startThreadPool(); return RUN_ALL_TESTS(); diff --git a/libs/binder/tests/Android.bp b/libs/binder/tests/Android.bp index aba2319485..2f0987fd1a 100644 --- a/libs/binder/tests/Android.bp +++ b/libs/binder/tests/Android.bp @@ -100,9 +100,14 @@ aidl_interface { enabled: true, platform_apis: true, }, + + // TODO: switch from FileDescriptor to ParcelFileDescriptor ndk: { enabled: false, }, + rust: { + enabled: false, + }, }, } diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp index cb1a1ee443..0ee96e7317 100644 --- a/libs/binder/tests/binderLibTest.cpp +++ b/libs/binder/tests/binderLibTest.cpp @@ -70,7 +70,7 @@ MATCHER_P(StatusEq, expected, (negation ? "not " : "") + statusToString(expected } static ::testing::AssertionResult IsPageAligned(void *buf) { - if (((unsigned long)buf & ((unsigned long)PAGE_SIZE - 1)) == 0) + if (((unsigned long)buf & ((unsigned long)getpagesize() - 1)) == 0) return ::testing::AssertionSuccess(); else return ::testing::AssertionFailure() << buf << " is not page aligned"; diff --git a/libs/bufferstreams/Android.bp b/libs/bufferstreams/Android.bp index 365fc457d1..6c2a980f71 100644 --- a/libs/bufferstreams/Android.bp +++ b/libs/bufferstreams/Android.bp @@ -19,6 +19,7 @@ package { aconfig_declarations { name: "bufferstreams_flags", package: "com.android.graphics.bufferstreams.flags", + container: "system", srcs: [ "aconfig/bufferstreams_flags.aconfig", ], diff --git a/libs/bufferstreams/aconfig/bufferstreams_flags.aconfig b/libs/bufferstreams/aconfig/bufferstreams_flags.aconfig index e258725e3d..d0f7812d21 100644 --- a/libs/bufferstreams/aconfig/bufferstreams_flags.aconfig +++ b/libs/bufferstreams/aconfig/bufferstreams_flags.aconfig @@ -1,4 +1,5 @@ package: "com.android.graphics.bufferstreams.flags" +container: "system" flag { name: "bufferstreams_steel_thread" diff --git a/libs/gui/Android.bp b/libs/gui/Android.bp index eb4d3df21d..4c3cc6cc3d 100644 --- a/libs/gui/Android.bp +++ b/libs/gui/Android.bp @@ -23,6 +23,7 @@ package { aconfig_declarations { name: "libgui_flags", package: "com.android.graphics.libgui.flags", + container: "system", srcs: ["libgui_flags.aconfig"], } diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp index 7564c26316..1e0aacddab 100644 --- a/libs/gui/LayerState.cpp +++ b/libs/gui/LayerState.cpp @@ -611,6 +611,10 @@ void layer_state_t::merge(const layer_state_t& other) { desiredHdrSdrRatio = other.desiredHdrSdrRatio; currentHdrSdrRatio = other.currentHdrSdrRatio; } + if (other.what & eDesiredHdrHeadroomChanged) { + what |= eDesiredHdrHeadroomChanged; + desiredHdrSdrRatio = other.desiredHdrSdrRatio; + } if (other.what & eCachingHintChanged) { what |= eCachingHintChanged; cachingHint = other.cachingHint; @@ -774,6 +778,7 @@ uint64_t layer_state_t::diff(const layer_state_t& other) const { CHECK_DIFF(diff, eDataspaceChanged, other, dataspace); CHECK_DIFF2(diff, eExtendedRangeBrightnessChanged, other, currentHdrSdrRatio, desiredHdrSdrRatio); + CHECK_DIFF(diff, eDesiredHdrHeadroomChanged, other, desiredHdrSdrRatio); CHECK_DIFF(diff, eCachingHintChanged, other, cachingHint); CHECK_DIFF(diff, eHdrMetadataChanged, other, hdrMetadata); if (other.what & eSurfaceDamageRegionChanged && diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 83c2b7f703..4f1356bebb 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -1808,6 +1808,20 @@ SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setExten return *this; } +SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setDesiredHdrHeadroom( + const sp<SurfaceControl>& sc, float desiredRatio) { + layer_state_t* s = getLayerState(sc); + if (!s) { + mStatus = BAD_INDEX; + return *this; + } + s->what |= layer_state_t::eDesiredHdrHeadroomChanged; + s->desiredHdrSdrRatio = desiredRatio; + + registerSurfaceControlForCallback(sc); + return *this; +} + SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setCachingHint( const sp<SurfaceControl>& sc, gui::CachingHint cachingHint) { layer_state_t* s = getLayerState(sc); diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h index 920310ea9e..0fedea7b9e 100644 --- a/libs/gui/include/gui/LayerState.h +++ b/libs/gui/include/gui/LayerState.h @@ -209,7 +209,7 @@ struct layer_state_t { eBackgroundBlurRadiusChanged = 0x80'00000000, eProducerDisconnect = 0x100'00000000, eFixedTransformHintChanged = 0x200'00000000, - /* unused 0x400'00000000, */ + eDesiredHdrHeadroomChanged = 0x400'00000000, eBlurRegionsChanged = 0x800'00000000, eAutoRefreshChanged = 0x1000'00000000, eStretchChanged = 0x2000'00000000, @@ -248,7 +248,8 @@ struct layer_state_t { layer_state_t::eSidebandStreamChanged | layer_state_t::eSurfaceDamageRegionChanged | layer_state_t::eTransformToDisplayInverseChanged | layer_state_t::eTransparentRegionChanged | - layer_state_t::eExtendedRangeBrightnessChanged; + layer_state_t::eExtendedRangeBrightnessChanged | + layer_state_t::eDesiredHdrHeadroomChanged; // Content updates. static constexpr uint64_t CONTENT_CHANGES = layer_state_t::BUFFER_CHANGES | diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index 88a2c342e7..288882695a 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -594,6 +594,7 @@ public: Transaction& setDataspace(const sp<SurfaceControl>& sc, ui::Dataspace dataspace); Transaction& setExtendedRangeBrightness(const sp<SurfaceControl>& sc, float currentBufferRatio, float desiredRatio); + Transaction& setDesiredHdrHeadroom(const sp<SurfaceControl>& sc, float desiredRatio); Transaction& setCachingHint(const sp<SurfaceControl>& sc, gui::CachingHint cachingHint); Transaction& setHdrMetadata(const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata); Transaction& setSurfaceDamageRegion(const sp<SurfaceControl>& sc, diff --git a/libs/gui/libgui_flags.aconfig b/libs/gui/libgui_flags.aconfig index b081030c9f..38646992da 100644 --- a/libs/gui/libgui_flags.aconfig +++ b/libs/gui/libgui_flags.aconfig @@ -1,4 +1,5 @@ package: "com.android.graphics.libgui.flags" +container: "system" flag { name: "bq_setframerate" diff --git a/libs/gui/tests/Android.bp b/libs/gui/tests/Android.bp index 6dcd501404..e606b9941e 100644 --- a/libs/gui/tests/Android.bp +++ b/libs/gui/tests/Android.bp @@ -3,6 +3,7 @@ // Build the binary to $(TARGET_OUT_DATA_NATIVE_TESTS)/$(LOCAL_MODULE) // to integrate with auto-test framework. package { + default_team: "trendy_team_android_core_graphics_stack", // See: http://go/android-license-faq // A large-scale-change added 'default_applicable_licenses' to import // all of the 'license_kinds' from "frameworks_native_license" diff --git a/libs/input/Android.bp b/libs/input/Android.bp index e5fb2c5b7a..8b693390d0 100644 --- a/libs/input/Android.bp +++ b/libs/input/Android.bp @@ -39,6 +39,7 @@ filegroup { aconfig_declarations { name: "com.android.input.flags-aconfig", package: "com.android.input.flags", + container: "system", srcs: ["input_flags.aconfig"], } diff --git a/libs/input/input_flags.aconfig b/libs/input/input_flags.aconfig index ec7a2849ea..5af48550c6 100644 --- a/libs/input/input_flags.aconfig +++ b/libs/input/input_flags.aconfig @@ -1,4 +1,5 @@ package: "com.android.input.flags" +container: "system" flag { name: "enable_outbound_event_verification" diff --git a/libs/nativewindow/AHardwareBuffer.cpp b/libs/nativewindow/AHardwareBuffer.cpp index 745b6f30cc..52612870ab 100644 --- a/libs/nativewindow/AHardwareBuffer.cpp +++ b/libs/nativewindow/AHardwareBuffer.cpp @@ -586,7 +586,7 @@ int AHardwareBuffer_createFromHandle(const AHardwareBuffer_Desc* desc, return NO_ERROR; } -enum AHardwareBufferStatus AHardwareBuffer_allocate2( +enum AHardwareBufferStatus AHardwareBuffer_allocateWithOptions( const AHardwareBuffer_Desc* desc, const AHardwareBufferLongOptions* additionalOptions, size_t additionalOptionsSize, AHardwareBuffer** outBuffer) { (void)additionalOptions; diff --git a/libs/nativewindow/include/vndk/hardware_buffer.h b/libs/nativewindow/include/vndk/hardware_buffer.h index 491860125f..bcfae10201 100644 --- a/libs/nativewindow/include/vndk/hardware_buffer.h +++ b/libs/nativewindow/include/vndk/hardware_buffer.h @@ -150,7 +150,7 @@ enum AHardwareBufferStatus : int32_t { * AHARDWAREBUFFER_STATUS_UNKNOWN_ERROR for any other error * any reason. The returned buffer has a reference count of 1. */ -enum AHardwareBufferStatus AHardwareBuffer_allocate2( +enum AHardwareBufferStatus AHardwareBuffer_allocateWithOptions( const AHardwareBuffer_Desc* _Nonnull desc, const AHardwareBufferLongOptions* _Nullable additionalOptions, size_t additionalOptionsSize, AHardwareBuffer* _Nullable* _Nonnull outBuffer) __INTRODUCED_IN(__ANDROID_API_V__); diff --git a/libs/nativewindow/libnativewindow.map.txt b/libs/nativewindow/libnativewindow.map.txt index 8bc1292986..e29d5a6bb4 100644 --- a/libs/nativewindow/libnativewindow.map.txt +++ b/libs/nativewindow/libnativewindow.map.txt @@ -2,7 +2,7 @@ LIBNATIVEWINDOW { global: AHardwareBuffer_acquire; AHardwareBuffer_allocate; - AHardwareBuffer_allocate2; # llndk systemapi + AHardwareBuffer_allocateWithOptions; # llndk systemapi AHardwareBuffer_createFromHandle; # llndk systemapi AHardwareBuffer_describe; AHardwareBuffer_getId; # introduced=31 diff --git a/libs/nativewindow/tests/AHardwareBufferTest.cpp b/libs/nativewindow/tests/AHardwareBufferTest.cpp index 1f0128a48e..136395aac0 100644 --- a/libs/nativewindow/tests/AHardwareBufferTest.cpp +++ b/libs/nativewindow/tests/AHardwareBufferTest.cpp @@ -188,7 +188,7 @@ TEST(AHardwareBufferTest, Allocate2NoExtras) { }; AHardwareBuffer* buffer = nullptr; - ASSERT_EQ(0, AHardwareBuffer_allocate2(&desc, nullptr, 0, &buffer)); + ASSERT_EQ(0, AHardwareBuffer_allocateWithOptions(&desc, nullptr, 0, &buffer)); uint64_t id = 0; EXPECT_EQ(0, AHardwareBuffer_getId(buffer, &id)); EXPECT_NE(0, id); @@ -219,7 +219,7 @@ TEST(AHardwareBufferTest, Allocate2WithExtras) { std::array<AHardwareBufferLongOptions, 1> extras = {{ {.name = "android.hardware.graphics.common.Dataspace", ADATASPACE_DISPLAY_P3}, }}; - ASSERT_EQ(0, AHardwareBuffer_allocate2(&desc, extras.data(), extras.size(), &buffer)); + ASSERT_EQ(0, AHardwareBuffer_allocateWithOptions(&desc, extras.data(), extras.size(), &buffer)); uint64_t id = 0; EXPECT_EQ(0, AHardwareBuffer_getId(buffer, &id)); EXPECT_NE(0, id); diff --git a/libs/renderengine/skia/filters/KawaseBlurFilter.cpp b/libs/renderengine/skia/filters/KawaseBlurFilter.cpp index 5c9820cdc5..09f09a697a 100644 --- a/libs/renderengine/skia/filters/KawaseBlurFilter.cpp +++ b/libs/renderengine/skia/filters/KawaseBlurFilter.cpp @@ -111,7 +111,7 @@ sk_sp<SkImage> KawaseBlurFilter::generate(GrRecordingContext* context, constexpr int kSampleCount = 1; constexpr bool kMipmapped = false; constexpr SkSurfaceProps* kProps = nullptr; - sk_sp<SkSurface> surface = SkSurfaces::RenderTarget(context, skgpu::Budgeted::kYes, scaledInfo, + sk_sp<SkSurface> surface = SkSurfaces::RenderTarget(context, skgpu::Budgeted::kNo, scaledInfo, kSampleCount, kTopLeft_GrSurfaceOrigin, kProps, kMipmapped, input->isProtected()); LOG_ALWAYS_FATAL_IF(!surface, "%s: Failed to create surface for blurring!", __func__); diff --git a/libs/sensorprivacy/Android.bp b/libs/sensorprivacy/Android.bp index 00514c4417..1e7e70775a 100644 --- a/libs/sensorprivacy/Android.bp +++ b/libs/sensorprivacy/Android.bp @@ -57,6 +57,7 @@ cc_library_shared { filegroup { name: "libsensorprivacy_aidl", srcs: [ + "aidl/android/hardware/CameraPrivacyAllowlistEntry.aidl", "aidl/android/hardware/ISensorPrivacyListener.aidl", "aidl/android/hardware/ISensorPrivacyManager.aidl", ], diff --git a/libs/sensorprivacy/SensorPrivacyManager.cpp b/libs/sensorprivacy/SensorPrivacyManager.cpp index 57c74ee565..fe9378616d 100644 --- a/libs/sensorprivacy/SensorPrivacyManager.cpp +++ b/libs/sensorprivacy/SensorPrivacyManager.cpp @@ -108,7 +108,7 @@ bool SensorPrivacyManager::isSensorPrivacyEnabled() bool SensorPrivacyManager::isToggleSensorPrivacyEnabled(int sensor) { - sp<hardware::ISensorPrivacyManager> service = getService(); + sp<hardware::ISensorPrivacyManager> service = getService(); if (service != nullptr) { bool result; service->isCombinedToggleSensorPrivacyEnabled(sensor, &result); @@ -143,6 +143,39 @@ status_t SensorPrivacyManager::isToggleSensorPrivacyEnabled(int toggleType, int return UNKNOWN_ERROR; } +int SensorPrivacyManager::getToggleSensorPrivacyState(int toggleType, int sensor) +{ + sp<hardware::ISensorPrivacyManager> service = getService(); + if (service != nullptr) { + int result; + service->getToggleSensorPrivacyState(toggleType, sensor, &result); + return result; + } + // if the SensorPrivacyManager is not available then assume sensor privacy is disabled + return DISABLED; +} + +std::vector<hardware::CameraPrivacyAllowlistEntry> + SensorPrivacyManager::getCameraPrivacyAllowlist(){ + sp<hardware::ISensorPrivacyManager> service = getService(); + std::vector<hardware::CameraPrivacyAllowlistEntry> result; + if (service != nullptr) { + service->getCameraPrivacyAllowlist(&result); + return result; + } + return result; +} + +bool SensorPrivacyManager::isCameraPrivacyEnabled(String16 packageName){ + sp<hardware::ISensorPrivacyManager> service = getService(); + if (service != nullptr) { + bool result; + service->isCameraPrivacyEnabled(packageName, &result); + return result; + } + return false; +} + status_t SensorPrivacyManager::linkToDeath(const sp<IBinder::DeathRecipient>& recipient) { sp<hardware::ISensorPrivacyManager> service = getService(); diff --git a/libs/sensorprivacy/aidl/android/hardware/CameraPrivacyAllowlistEntry.aidl b/libs/sensorprivacy/aidl/android/hardware/CameraPrivacyAllowlistEntry.aidl new file mode 100644 index 0000000000..03e153704b --- /dev/null +++ b/libs/sensorprivacy/aidl/android/hardware/CameraPrivacyAllowlistEntry.aidl @@ -0,0 +1,22 @@ +/** + * Copyright (c) 2024, The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.hardware; + +parcelable CameraPrivacyAllowlistEntry { + String packageName; + boolean isMandatory; +} diff --git a/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyListener.aidl b/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyListener.aidl index eccd54c3eb..694af00a87 100644 --- a/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyListener.aidl +++ b/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyListener.aidl @@ -21,4 +21,5 @@ package android.hardware; */ oneway interface ISensorPrivacyListener { void onSensorPrivacyChanged(int toggleType, int sensor, boolean enabled); + void onSensorPrivacyStateChanged(int toggleType, int sensor, int state); } diff --git a/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyManager.aidl b/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyManager.aidl index 49a1e1ea05..b6bd39e557 100644 --- a/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyManager.aidl +++ b/libs/sensorprivacy/aidl/android/hardware/ISensorPrivacyManager.aidl @@ -16,6 +16,7 @@ package android.hardware; +import android.hardware.CameraPrivacyAllowlistEntry; import android.hardware.ISensorPrivacyListener; /** @hide */ @@ -41,4 +42,15 @@ interface ISensorPrivacyManager { void setToggleSensorPrivacy(int userId, int source, int sensor, boolean enable); void setToggleSensorPrivacyForProfileGroup(int userId, int source, int sensor, boolean enable); + + List<CameraPrivacyAllowlistEntry> getCameraPrivacyAllowlist(); + + int getToggleSensorPrivacyState(int toggleType, int sensor); + + void setToggleSensorPrivacyState(int userId, int source, int sensor, int state); + + void setToggleSensorPrivacyStateForProfileGroup(int userId, int source, int sensor, int state); + + boolean isCameraPrivacyEnabled(String packageName); + } diff --git a/libs/sensorprivacy/include/sensorprivacy/SensorPrivacyManager.h b/libs/sensorprivacy/include/sensorprivacy/SensorPrivacyManager.h index fc5fdf7900..9e97e166be 100644 --- a/libs/sensorprivacy/include/sensorprivacy/SensorPrivacyManager.h +++ b/libs/sensorprivacy/include/sensorprivacy/SensorPrivacyManager.h @@ -32,12 +32,22 @@ class SensorPrivacyManager public: enum { TOGGLE_SENSOR_MICROPHONE = 1, - TOGGLE_SENSOR_CAMERA = 2 + TOGGLE_SENSOR_CAMERA = 2, + TOGGLE_SENSOR_UNKNOWN = -1 }; enum { TOGGLE_TYPE_SOFTWARE = 1, - TOGGLE_TYPE_HARDWARE = 2 + TOGGLE_TYPE_HARDWARE = 2, + TOGGLE_TYPE_UNKNOWN = -1 + }; + + enum { + ENABLED = 1, + DISABLED = 2, + AUTOMOTIVE_DRIVER_ASSISTANCE_HELPFUL_APPS = 3, + AUTOMOTIVE_DRIVER_ASSISTANCE_REQUIRED_APPS = 4, + AUTOMOTIVE_DRIVER_ASSISTANCE_APPS = 5 }; SensorPrivacyManager(); @@ -51,6 +61,9 @@ public: bool isToggleSensorPrivacyEnabled(int sensor); bool isToggleSensorPrivacyEnabled(int toggleType, int sensor); status_t isToggleSensorPrivacyEnabled(int toggleType, int sensor, bool &result); + int getToggleSensorPrivacyState(int toggleType, int sensor); + std::vector<hardware::CameraPrivacyAllowlistEntry> getCameraPrivacyAllowlist(); + bool isCameraPrivacyEnabled(String16 packageName); status_t linkToDeath(const sp<IBinder::DeathRecipient>& recipient); status_t unlinkToDeath(const sp<IBinder::DeathRecipient>& recipient); diff --git a/libs/ui/DisplayIdentification.cpp b/libs/ui/DisplayIdentification.cpp index 16ed82af7c..82e5427317 100644 --- a/libs/ui/DisplayIdentification.cpp +++ b/libs/ui/DisplayIdentification.cpp @@ -21,6 +21,7 @@ #include <cctype> #include <numeric> #include <optional> +#include <span> #include <log/log.h> @@ -46,6 +47,7 @@ uint64_t shiftMix(uint64_t val) { return val ^ (val >> 47); } +__attribute__((no_sanitize("unsigned-integer-overflow"))) uint64_t hash64Len16(uint64_t u, uint64_t v) { constexpr uint64_t kMul = 0x9ddfea08eb382d69; uint64_t a = (u ^ v) * kMul; @@ -56,6 +58,7 @@ uint64_t hash64Len16(uint64_t u, uint64_t v) { return b; } +__attribute__((no_sanitize("unsigned-integer-overflow"))) uint64_t hash64Len0To16(const char* s, uint64_t len) { constexpr uint64_t k2 = 0x9ae16a3b2f90404f; constexpr uint64_t k3 = 0xc949d7c7509e6557; @@ -81,7 +84,7 @@ uint64_t hash64Len0To16(const char* s, uint64_t len) { return k2; } -using byte_view = std::basic_string_view<uint8_t>; +using byte_view = std::span<const uint8_t>; constexpr size_t kEdidBlockSize = 128; constexpr size_t kEdidHeaderLength = 5; @@ -89,7 +92,8 @@ constexpr size_t kEdidHeaderLength = 5; constexpr uint16_t kVirtualEdidManufacturerId = 0xffffu; std::optional<uint8_t> getEdidDescriptorType(const byte_view& view) { - if (view.size() < kEdidHeaderLength || view[0] || view[1] || view[2] || view[4]) { + if (static_cast<size_t>(view.size()) < kEdidHeaderLength || view[0] || view[1] || view[2] || + view[4]) { return {}; } @@ -164,7 +168,7 @@ Cea861ExtensionBlock parseCea861Block(const byte_view& block) { constexpr size_t kDataBlockHeaderSize = 1; const size_t dataBlockSize = bodyLength + kDataBlockHeaderSize; - if (block.size() < dataBlockOffset + dataBlockSize) { + if (static_cast<size_t>(block.size()) < dataBlockOffset + dataBlockSize) { ALOGW("Invalid EDID: CEA 861 data block is truncated."); break; } @@ -264,7 +268,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) { } byte_view view(edid.data(), edid.size()); - view.remove_prefix(kDescriptorOffset); + view = view.subspan(kDescriptorOffset); std::string_view displayName; std::string_view serialNumber; @@ -274,13 +278,13 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) { constexpr size_t kDescriptorLength = 18; for (size_t i = 0; i < kDescriptorCount; i++) { - if (view.size() < kDescriptorLength) { + if (static_cast<size_t>(view.size()) < kDescriptorLength) { break; } if (const auto type = getEdidDescriptorType(view)) { byte_view descriptor(view.data(), kDescriptorLength); - descriptor.remove_prefix(kEdidHeaderLength); + descriptor = descriptor.subspan(kEdidHeaderLength); switch (*type) { case 0xfc: @@ -295,7 +299,7 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) { } } - view.remove_prefix(kDescriptorLength); + view = view.subspan(kDescriptorLength); } std::string_view modelString = displayName; @@ -327,8 +331,8 @@ std::optional<Edid> parseEdid(const DisplayIdentificationData& edid) { const size_t numExtensions = edid[kNumExtensionsOffset]; view = byte_view(edid.data(), edid.size()); for (size_t blockNumber = 1; blockNumber <= numExtensions; blockNumber++) { - view.remove_prefix(kEdidBlockSize); - if (view.size() < kEdidBlockSize) { + view = view.subspan(kEdidBlockSize); + if (static_cast<size_t>(view.size()) < kEdidBlockSize) { ALOGW("Invalid EDID: block %zu is truncated.", blockNumber); break; } @@ -399,4 +403,4 @@ uint64_t cityHash64Len0To16(std::string_view sv) { return hash64Len0To16(sv.data(), len); } -} // namespace android
\ No newline at end of file +} // namespace android diff --git a/libs/ui/Gralloc5.cpp b/libs/ui/Gralloc5.cpp index b07e15534a..f217810b6a 100644 --- a/libs/ui/Gralloc5.cpp +++ b/libs/ui/Gralloc5.cpp @@ -89,10 +89,18 @@ static void *loadIMapperLibrary() { return nullptr; } - std::string lib_name = "mapper." + mapperSuffix + ".so"; - void *so = android_load_sphal_library(lib_name.c_str(), RTLD_LOCAL | RTLD_NOW); + void* so = nullptr; + // TODO(b/322384429) switch this to __ANDROID_API_V__ when V is finalized + // TODO(b/302113279) use __ANDROID_VENDOR_API__ for vendor variant + if (__builtin_available(android __ANDROID_API_FUTURE__, *)) { + so = AServiceManager_openDeclaredPassthroughHal("mapper", mapperSuffix.c_str(), + RTLD_LOCAL | RTLD_NOW); + } else { + std::string lib_name = "mapper." + mapperSuffix + ".so"; + so = android_load_sphal_library(lib_name.c_str(), RTLD_LOCAL | RTLD_NOW); + } if (!so) { - ALOGE("Failed to load %s", lib_name.c_str()); + ALOGE("Failed to load mapper.%s.so", mapperSuffix.c_str()); } return so; }(); diff --git a/libs/ui/tests/Android.bp b/libs/ui/tests/Android.bp index 8ce017d7a3..9a202150c5 100644 --- a/libs/ui/tests/Android.bp +++ b/libs/ui/tests/Android.bp @@ -54,6 +54,17 @@ cc_test { } cc_test { + name: "DisplayIdentification_test", + shared_libs: ["libui"], + static_libs: ["libgmock"], + srcs: ["DisplayIdentification_test.cpp"], + cflags: [ + "-Wall", + "-Werror", + ], +} + +cc_test { name: "FlattenableHelpers_test", shared_libs: ["libui"], srcs: ["FlattenableHelpers_test.cpp"], diff --git a/libs/vibrator/fuzzer/Android.bp b/libs/vibrator/fuzzer/Android.bp index cb063af2f6..faa77ca9df 100644 --- a/libs/vibrator/fuzzer/Android.bp +++ b/libs/vibrator/fuzzer/Android.bp @@ -18,6 +18,7 @@ */ package { + default_team: "trendy_team_haptics_framework", // See: http://go/android-license-faq // A large-scale-change added 'default_applicable_licenses' to import // all of the 'license_kinds' from "frameworks_native_license" diff --git a/libs/vr/libpdx/private/pdx/rpc/string_wrapper.h b/libs/vr/libpdx/private/pdx/rpc/string_wrapper.h index 2d0a4ea6ec..371ed89fc9 100644 --- a/libs/vr/libpdx/private/pdx/rpc/string_wrapper.h +++ b/libs/vr/libpdx/private/pdx/rpc/string_wrapper.h @@ -17,12 +17,12 @@ namespace rpc { // C strings more efficient by avoiding unnecessary copies when remote method // signatures specify std::basic_string arguments or return values. template <typename CharT = std::string::value_type, - typename Traits = std::char_traits<CharT>> + typename Traits = std::char_traits<std::remove_cv_t<CharT>>> class StringWrapper { public: // Define types in the style of STL strings to support STL operators. typedef Traits traits_type; - typedef typename Traits::char_type value_type; + typedef CharT value_type; typedef std::size_t size_type; typedef value_type& reference; typedef const value_type& const_reference; diff --git a/services/inputflinger/reader/InputDevice.cpp b/services/inputflinger/reader/InputDevice.cpp index f3f15df151..2baf576903 100644 --- a/services/inputflinger/reader/InputDevice.cpp +++ b/services/inputflinger/reader/InputDevice.cpp @@ -265,6 +265,8 @@ std::list<NotifyArgs> InputDevice::configureInternal(nsecs_t when, } if (!changes.any() || changes.test(Change::DISPLAY_INFO)) { + const auto oldAssociatedDisplayId = getAssociatedDisplayId(); + // In most situations, no port or name will be specified. mAssociatedDisplayPort = std::nullopt; mAssociatedDisplayUniqueId = std::nullopt; @@ -306,6 +308,10 @@ std::list<NotifyArgs> InputDevice::configureInternal(nsecs_t when, getName().c_str(), mAssociatedDisplayUniqueId->c_str()); } } + + if (getAssociatedDisplayId() != oldAssociatedDisplayId) { + bumpGeneration(); + } } for_each_mapper([this, when, &readerConfig, changes, &out](InputMapper& mapper) { diff --git a/services/inputflinger/reader/mapper/CursorInputMapper.cpp b/services/inputflinger/reader/mapper/CursorInputMapper.cpp index 65f69c5155..45f09ae32a 100644 --- a/services/inputflinger/reader/mapper/CursorInputMapper.cpp +++ b/services/inputflinger/reader/mapper/CursorInputMapper.cpp @@ -23,6 +23,7 @@ #include <optional> #include <com_android_input_flags.h> +#include <ftl/enum.h> #include <input/AccelerationCurve.h> #include "CursorButtonAccumulator.h" @@ -136,7 +137,7 @@ void CursorInputMapper::dump(std::string& dump) { dump += StringPrintf(INDENT3 "VWheelScale: %0.3f\n", mVWheelScale); dump += StringPrintf(INDENT3 "HWheelScale: %0.3f\n", mHWheelScale); dump += StringPrintf(INDENT3 "DisplayId: %s\n", toString(mDisplayId).c_str()); - dump += StringPrintf(INDENT3 "Orientation: %d\n", mOrientation); + dump += StringPrintf(INDENT3 "Orientation: %s\n", ftl::enum_string(mOrientation).c_str()); dump += StringPrintf(INDENT3 "ButtonState: 0x%08x\n", mButtonState); dump += StringPrintf(INDENT3 "Down: %s\n", toString(isPointerDown(mButtonState))); dump += StringPrintf(INDENT3 "DownTime: %" PRId64 "\n", mDownTime); diff --git a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp index 9e7e956866..738517b67e 100644 --- a/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp +++ b/services/inputflinger/reader/mapper/KeyboardInputMapper.cpp @@ -20,6 +20,7 @@ #include "KeyboardInputMapper.h" +#include <ftl/enum.h> #include <ui/Rotation.h> namespace android { @@ -143,7 +144,7 @@ void KeyboardInputMapper::dump(std::string& dump) { dump += INDENT2 "Keyboard Input Mapper:\n"; dumpParameters(dump); dump += StringPrintf(INDENT3 "KeyboardType: %d\n", mKeyboardType); - dump += StringPrintf(INDENT3 "Orientation: %d\n", getOrientation()); + dump += StringPrintf(INDENT3 "Orientation: %s\n", ftl::enum_string(getOrientation()).c_str()); dump += StringPrintf(INDENT3 "KeyDowns: %zu keys currently down\n", mKeyDowns.size()); dump += StringPrintf(INDENT3 "MetaState: 0x%0x\n", mMetaState); dump += INDENT3 "KeyboardLayoutInfo: "; diff --git a/services/inputflinger/rust/Android.bp b/services/inputflinger/rust/Android.bp index 9e6dbe432d..255c7eb679 100644 --- a/services/inputflinger/rust/Android.bp +++ b/services/inputflinger/rust/Android.bp @@ -13,6 +13,10 @@ // limitations under the License. // Generate the C++ code that Rust calls into. +package { + default_team: "trendy_team_input_framework", +} + genrule { name: "inputflinger_rs_bootstrap_bridge_code", tools: ["cxxbridge"], diff --git a/services/inputflinger/rust/lib.rs b/services/inputflinger/rust/lib.rs index 25dfb03cb8..4af7b84a21 100644 --- a/services/inputflinger/rust/lib.rs +++ b/services/inputflinger/rust/lib.rs @@ -65,9 +65,9 @@ mod ffi { /// /// # Safety /// -/// This function is safe iff `callback` is a valid pointer to an `AIBinder` interface of type -/// `IInputFlingerRustBootstrapCallback`. The pointer must have had its reference count manually -/// incremented using `AIBinder_incStrong`. See `binder::unstable_api::new_spibinder`. +/// The provided `callback` must be a valid pointer to an `AIBinder` interface of type +/// `IInputFlingerRustBootstrapCallback`, and the caller must give this function ownership of one +/// strong refcount to the interface. See `binder::unstable_api::new_spibinder`. unsafe fn create_inputflinger_rust(callback: *mut ffi::IInputFlingerRustBootstrapCallbackAIBinder) { logger::init( logger::Config::default() diff --git a/services/inputflinger/tests/GestureConverter_test.cpp b/services/inputflinger/tests/GestureConverter_test.cpp index 163076974f..dd88165561 100644 --- a/services/inputflinger/tests/GestureConverter_test.cpp +++ b/services/inputflinger/tests/GestureConverter_test.cpp @@ -47,6 +47,7 @@ const auto TOUCHPAD_PALM_REJECTION_V2 = } // namespace using testing::AllOf; +using testing::Each; using testing::ElementsAre; using testing::VariantWith; @@ -117,15 +118,15 @@ TEST_F(GestureConverterTest, Move) { ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithRelativeMotion(0, 0))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(POINTER_X - 5, POINTER_Y + 10), - WithRelativeMotion(-5, 10), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithRelativeMotion(-5, 10), WithButtonState(0), + WithPressure(0.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X - 5, POINTER_Y + 10)); @@ -156,14 +157,15 @@ TEST_F(GestureConverterTest, Move_Rotated) { ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithRelativeMotion(0, 0))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), WithCoords(POINTER_X + 10, POINTER_Y + 5), - WithRelativeMotion(10, 5), WithToolType(ToolType::FINGER), - WithButtonState(0), WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithRelativeMotion(10, 5), WithButtonState(0), + WithPressure(0.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); ASSERT_NO_FATAL_FAILURE(mFakePointerController->assertPosition(POINTER_X + 10, POINTER_Y + 5)); } @@ -183,25 +185,20 @@ TEST_F(GestureConverterTest, ButtonsChange) { ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | - AMOTION_EVENT_BUTTON_SECONDARY), - WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + AMOTION_EVENT_BUTTON_SECONDARY))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | - AMOTION_EVENT_BUTTON_SECONDARY), - WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + AMOTION_EVENT_BUTTON_SECONDARY))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); // Then release the left button Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -224,20 +221,16 @@ TEST_F(GestureConverterTest, ButtonsChange) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), - WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), - WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))), VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithMotionAction(AMOTION_EVENT_ACTION_UP)), VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), + WithCoords(POINTER_X, POINTER_Y), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, ButtonDownAfterMoveExitsHover) { @@ -274,17 +267,15 @@ TEST_F(GestureConverterTest, DragWithButton) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); // Move Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); @@ -307,23 +298,16 @@ TEST_F(GestureConverterTest, DragWithButton) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), - WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(0), - WithCoords(POINTER_X - 5, POINTER_Y + 10), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))), VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithButtonState(0), - WithCoords(POINTER_X - 5, POINTER_Y + 10), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithMotionAction(AMOTION_EVENT_ACTION_UP)), VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithButtonState(0), - WithCoords(POINTER_X - 5, POINTER_Y + 10), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), + WithCoords(POINTER_X - 5, POINTER_Y + 10), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Scroll) { @@ -340,20 +324,17 @@ TEST_F(GestureConverterTest, Scroll) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), WithGestureScrollDistance(0, 0, EPSILON), - WithMotionClassification( - MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), WithDownTime(downTime), - WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithDownTime(downTime))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(POINTER_X, POINTER_Y - 10), - WithGestureScrollDistance(0, 10, EPSILON), - WithMotionClassification( - MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), - WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithGestureScrollDistance(0, 10, EPSILON))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), + WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); @@ -377,15 +358,14 @@ TEST_F(GestureConverterTest, Scroll) { WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification( MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), - WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(POINTER_X, POINTER_Y), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Scroll_Rotated) { @@ -403,18 +383,16 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(POINTER_X, POINTER_Y), WithGestureScrollDistance(0, 0, EPSILON), - WithMotionClassification( - MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), WithDownTime(downTime), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithDownTime(downTime))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(POINTER_X - 10, POINTER_Y), - WithGestureScrollDistance(0, 10, EPSILON), - WithMotionClassification( - MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithGestureScrollDistance(0, 10, EPSILON))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); @@ -435,15 +413,14 @@ TEST_F(GestureConverterTest, Scroll_Rotated) { WithCoords(POINTER_X - 15, POINTER_Y), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification( - MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + MotionClassification::TWO_FINGER_SWIPE))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(POINTER_X, POINTER_Y), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) { @@ -511,7 +488,6 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/-5, /*dy=*/10); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); - ASSERT_EQ(1u, args.size()); ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( WithMotionClassification(MotionClassification::NONE)))); @@ -554,46 +530,39 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); ASSERT_EQ(4u, args.size()); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); // Three fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), - WithGestureSwipeFingerCount(3), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithPointerCount(1u))); PointerCoords finger0Start = arg.pointerCoords[0]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); PointerCoords finger1Start = arg.pointerCoords[1]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); PointerCoords finger2Start = arg.pointerCoords[2]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); @@ -630,8 +599,7 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { WithGestureSwipeFingerCount(3), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(3u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | @@ -640,22 +608,21 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) { WithGestureSwipeFingerCount(3), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(POINTER_X, POINTER_Y), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { @@ -669,37 +636,35 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); ASSERT_EQ(4u, args.size()); + ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT)))); // Three fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), - WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithPointerCount(1u))); PointerCoords finger0Start = arg.pointerCoords[0]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); PointerCoords finger1Start = arg.pointerCoords[1]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); PointerCoords finger2Start = arg.pointerCoords[2]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); @@ -730,21 +695,18 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_Rotated) { AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); + ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT)))); } TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { @@ -757,56 +719,46 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); ASSERT_EQ(5u, args.size()); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); // Four fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), - WithGestureSwipeFingerCount(4), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithPointerCount(1u))); PointerCoords finger0Start = arg.pointerCoords[0]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); PointerCoords finger1Start = arg.pointerCoords[1]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); PointerCoords finger2Start = arg.pointerCoords[2]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u))); PointerCoords finger3Start = arg.pointerCoords[3]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); @@ -847,8 +799,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { WithGestureSwipeFingerCount(4), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(4u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | @@ -857,8 +808,7 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { WithGestureSwipeFingerCount(4), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(3u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | @@ -867,22 +817,21 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) { WithGestureSwipeFingerCount(4), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(POINTER_X, POINTER_Y), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Pinch_Inwards) { @@ -897,20 +846,20 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithMotionClassification(MotionClassification::PINCH), - WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(POINTER_X - 100, POINTER_Y), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithMotionClassification(MotionClassification::PINCH), - WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, POINTER_X + 100, POINTER_Y), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithPointerCount(2u))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); @@ -935,20 +884,19 @@ TEST_F(GestureConverterTest, Pinch_Inwards) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(POINTER_X, POINTER_Y), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Pinch_Outwards) { @@ -963,20 +911,20 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithMotionClassification(MotionClassification::PINCH), - WithGesturePinchScaleFactor(1.0f, EPSILON), WithCoords(POINTER_X - 100, POINTER_Y), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithMotionClassification(MotionClassification::PINCH), - WithGesturePinchScaleFactor(1.0f, EPSILON), WithPointerCoords(1, POINTER_X + 100, POINTER_Y), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithPointerCount(2u))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1.2, GESTURES_ZOOM_UPDATE); @@ -1001,20 +949,19 @@ TEST_F(GestureConverterTest, Pinch_Outwards) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(POINTER_X, POINTER_Y), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) { @@ -1084,26 +1031,21 @@ TEST_F(GestureConverterTest, ResetWithButtonPressed) { ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), - WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), - WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithButtonState(0))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, ResetDuringScroll) { @@ -1122,15 +1064,14 @@ TEST_F(GestureConverterTest, ResetDuringScroll) { WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification( MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), - WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(POINTER_X, POINTER_Y), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { @@ -1151,8 +1092,7 @@ TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { WithGestureOffset(0, 0, EPSILON), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(3u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | @@ -1160,20 +1100,19 @@ TEST_F(GestureConverterTest, ResetDuringThreeFingerSwipe) { WithGestureOffset(0, 0, EPSILON), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, ResetDuringPinch) { @@ -1193,20 +1132,19 @@ TEST_F(GestureConverterTest, ResetDuringPinch) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(POINTER_X, POINTER_Y), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, FlingTapDown) { @@ -1249,45 +1187,31 @@ TEST_F(GestureConverterTest, Tap) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), - WithButtonState(0), WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithButtonState(0), WithPressure(0.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), + WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTest, Click) { @@ -1310,27 +1234,21 @@ TEST_F(GestureConverterTest, Click) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithPressure(1.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), + WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* down= */ GESTURES_BUTTON_NONE, @@ -1340,22 +1258,18 @@ TEST_F(GestureConverterTest, Click) { ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), - WithButtonState(0), WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithPressure(0.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), + WithRelativeMotion(0.f, 0.f), WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabled, @@ -1448,33 +1362,28 @@ TEST_F_WITH_FLAGS(GestureConverterTest, TapWithTapToClickDisabledWithDelay, /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); - - ASSERT_EQ(6u, args.size()); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), - WithRelativeMotion(0.f, 0.f), WithButtonState(0))); - args.pop_front(); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))); - args.pop_front(); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), - WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1), - WithRelativeMotion(0.f, 0.f))); - args.pop_front(); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), - WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), - WithRelativeMotion(0.f, 0.f))); - args.pop_front(); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f), - WithButtonState(0))); - args.pop_front(); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithRelativeMotion(0, 0), - WithButtonState(0))); + ASSERT_THAT(args, + ElementsAre(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), + WithButtonState(0))), + VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), + WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), + VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), + WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), + WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), + VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), + WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), + WithButtonState(0))), + VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), + WithButtonState(0))), + VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), + WithButtonState(0))))); + ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f)))); } TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, @@ -1499,27 +1408,21 @@ TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithPressure(1.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), + WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* down= */ GESTURES_BUTTON_NONE, @@ -1530,22 +1433,18 @@ TEST_F_WITH_FLAGS(GestureConverterTest, ClickWithTapToClickDisabled, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(0), WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithCoords(POINTER_X, POINTER_Y), - WithRelativeMotion(0, 0), WithToolType(ToolType::FINGER), - WithButtonState(0), WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithButtonState(0), WithPressure(0.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(POINTER_X, POINTER_Y), + WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); // Future taps should be re-enabled ASSERT_FALSE(mReader->getContext()->isPreventingTouchpadTaps()); @@ -1633,15 +1532,15 @@ TEST_F(GestureConverterTestWithChoreographer, Move) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithCoords(0, 0), WithRelativeMotion(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithRelativeMotion(0, 0))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), - WithCoords(0, 0), WithRelativeMotion(-5, 10), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithRelativeMotion(-5, 10), WithButtonState(0), + WithPressure(0.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); // The same gesture again should only repeat the HOVER_MOVE, not the HOVER_ENTER. args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture); @@ -1665,15 +1564,15 @@ TEST_F(GestureConverterTestWithChoreographer, Move_Rotated) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithCoords(0, 0), WithRelativeMotion(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithRelativeMotion(0, 0))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_MOVE), - WithCoords(0, 0), WithRelativeMotion(10, 5), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithRelativeMotion(10, 5), WithButtonState(0), + WithPressure(0.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) { @@ -1691,22 +1590,20 @@ TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) { ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | - AMOTION_EVENT_BUTTON_SECONDARY), - WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + AMOTION_EVENT_BUTTON_SECONDARY))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY | - AMOTION_EVENT_BUTTON_SECONDARY), - WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + AMOTION_EVENT_BUTTON_SECONDARY))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); // Then release the left button Gesture leftUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, @@ -1729,20 +1626,15 @@ TEST_F(GestureConverterTestWithChoreographer, ButtonsChange) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), - WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), - WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY))), VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithMotionAction(AMOTION_EVENT_ACTION_UP)), VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, ButtonDownAfterMoveExitsHover) { @@ -1779,15 +1671,15 @@ TEST_F(GestureConverterTestWithChoreographer, DragWithButton) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); // Move Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10); @@ -1807,20 +1699,15 @@ TEST_F(GestureConverterTestWithChoreographer, DragWithButton) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), - WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY))), VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithMotionAction(AMOTION_EVENT_ACTION_UP)), VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER)))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, Scroll) { @@ -1837,20 +1724,17 @@ TEST_F(GestureConverterTestWithChoreographer, Scroll) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0), WithGestureScrollDistance(0, 0, EPSILON), - WithMotionClassification( - MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), WithDownTime(downTime), - WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithDownTime(downTime))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(0, -10), - WithGestureScrollDistance(0, 10, EPSILON), - WithMotionClassification( - MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), - WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithGestureScrollDistance(0, 10, EPSILON))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), + WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); @@ -1873,15 +1757,14 @@ TEST_F(GestureConverterTestWithChoreographer, Scroll) { WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification( MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), - WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) { @@ -1899,18 +1782,16 @@ TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) { AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithCoords(0, 0), WithGestureScrollDistance(0, 0, EPSILON), - WithMotionClassification( - MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), WithDownTime(downTime), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithDownTime(downTime))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), WithCoords(-10, 0), - WithGestureScrollDistance(0, 10, EPSILON), - WithMotionClassification( - MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithGestureScrollDistance(0, 10, EPSILON))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::TWO_FINGER_SWIPE), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5); args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture); @@ -1931,15 +1812,14 @@ TEST_F(GestureConverterTestWithChoreographer, Scroll_Rotated) { WithCoords(-15, 0), WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification( - MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + MotionClassification::TWO_FINGER_SWIPE))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, Scroll_ClearsClassificationAfterGesture) { @@ -2049,46 +1929,39 @@ TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) { std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); ASSERT_EQ(4u, args.size()); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithGestureSwipeFingerCount(3), WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); // Three fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), - WithGestureSwipeFingerCount(3), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithPointerCount(1u))); PointerCoords finger0Start = arg.pointerCoords[0]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); PointerCoords finger1Start = arg.pointerCoords[1]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); PointerCoords finger2Start = arg.pointerCoords[2]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithGestureOffset(0, -0.01, EPSILON), WithGestureSwipeFingerCount(3), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX()); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX()); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX()); @@ -2125,8 +1998,7 @@ TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) { WithGestureSwipeFingerCount(3), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(3u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | @@ -2135,22 +2007,21 @@ TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Vertical) { WithGestureSwipeFingerCount(3), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(3), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) { @@ -2164,37 +2035,35 @@ TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) { std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); ASSERT_EQ(4u, args.size()); + ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT)))); // Three fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), - WithPointerCount(1u), WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithPointerCount(1u))); PointerCoords finger0Start = arg.pointerCoords[0]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); PointerCoords finger1Start = arg.pointerCoords[1]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); PointerCoords finger2Start = arg.pointerCoords[2]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, -0.01, EPSILON), WithPointerCount(3u))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() - 10); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() - 10); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() - 10); @@ -2225,21 +2094,18 @@ TEST_F(GestureConverterTestWithChoreographer, ThreeFingerSwipe_Rotated) { AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithGestureOffset(0, 0, EPSILON), WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER))))); + ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithDisplayId(ADISPLAY_ID_DEFAULT)))); } TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) { @@ -2252,56 +2118,46 @@ TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) { std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture); ASSERT_EQ(5u, args.size()); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), + WithGestureSwipeFingerCount(4), WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); // Four fake fingers should be created. We don't actually care where they are, so long as they // move appropriately. NotifyMotionArgs arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithGestureOffset(0, 0, EPSILON), - WithGestureSwipeFingerCount(4), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithPointerCount(1u))); PointerCoords finger0Start = arg.pointerCoords[0]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(2u))); PointerCoords finger1Start = arg.pointerCoords[1]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(3u))); PointerCoords finger2Start = arg.pointerCoords[2]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_POINTER_DOWN | 3 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0, 0, EPSILON), WithPointerCount(4u))); PointerCoords finger3Start = arg.pointerCoords[3]; args.pop_front(); arg = std::get<NotifyMotionArgs>(args.front()); ASSERT_THAT(arg, AllOf(WithMotionAction(AMOTION_EVENT_ACTION_MOVE), - WithGestureOffset(0.01, 0, EPSILON), WithGestureSwipeFingerCount(4), - WithMotionClassification(MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))); + WithGestureOffset(0.01, 0, EPSILON), WithPointerCount(4u))); EXPECT_EQ(arg.pointerCoords[0].getX(), finger0Start.getX() + 10); EXPECT_EQ(arg.pointerCoords[1].getX(), finger1Start.getX() + 10); EXPECT_EQ(arg.pointerCoords[2].getX(), finger2Start.getX() + 10); @@ -2342,8 +2198,7 @@ TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) { WithGestureSwipeFingerCount(4), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(4u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(4u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | @@ -2352,8 +2207,7 @@ TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) { WithGestureSwipeFingerCount(4), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(3u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | @@ -2362,22 +2216,21 @@ TEST_F(GestureConverterTestWithChoreographer, FourFingerSwipe_Horizontal) { WithGestureSwipeFingerCount(4), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithGestureSwipeFingerCount(4), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) { @@ -2392,20 +2245,18 @@ TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithMotionClassification(MotionClassification::PINCH), - WithGesturePinchScaleFactor(1.0f, EPSILON), - WithCoords(-100, 0), WithPointerCount(1u), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithCoords(-100, 0), WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithMotionClassification(MotionClassification::PINCH), - WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCoords(1, 100, 0), WithPointerCount(2u), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithPointerCoords(1, 100, 0), WithPointerCount(2u))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 0.8, GESTURES_ZOOM_UPDATE); @@ -2429,20 +2280,19 @@ TEST_F(GestureConverterTestWithChoreographer, Pinch_Inwards) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) { @@ -2457,20 +2307,18 @@ TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithMotionClassification(MotionClassification::PINCH), - WithGesturePinchScaleFactor(1.0f, EPSILON), - WithCoords(-100, 0), WithPointerCount(1u), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithCoords(-100, 0), WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_DOWN | 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), - WithMotionClassification(MotionClassification::PINCH), - WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCoords(1, 100, 0), WithPointerCount(2u), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithPointerCoords(1, 100, 0), WithPointerCount(2u))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionClassification(MotionClassification::PINCH), + WithGesturePinchScaleFactor(1.0f, EPSILON), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dz= */ 1.1, GESTURES_ZOOM_UPDATE); @@ -2494,20 +2342,19 @@ TEST_F(GestureConverterTestWithChoreographer, Pinch_Outwards) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, Pinch_ClearsClassificationAfterGesture) { @@ -2577,25 +2424,21 @@ TEST_F(GestureConverterTestWithChoreographer, ResetWithButtonPressed) { ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY), - WithCoords(0, 0), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(AMOTION_EVENT_BUTTON_SECONDARY))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_SECONDARY), - WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithButtonState(0), WithCoords(0, 0), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithButtonState(0))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) { @@ -2614,15 +2457,14 @@ TEST_F(GestureConverterTestWithChoreographer, ResetDuringScroll) { WithGestureScrollDistance(0, 0, EPSILON), WithMotionClassification( MotionClassification::TWO_FINGER_SWIPE), - WithToolType(ToolType::FINGER), - WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithFlags(AMOTION_EVENT_FLAG_IS_GENERATED_GESTURE))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) { @@ -2643,8 +2485,7 @@ TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) { WithGestureOffset(0, 0, EPSILON), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(3u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(3u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction( AMOTION_EVENT_ACTION_POINTER_UP | @@ -2652,20 +2493,19 @@ TEST_F(GestureConverterTestWithChoreographer, ResetDuringThreeFingerSwipe) { WithGestureOffset(0, 0, EPSILON), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithGestureOffset(0, 0, EPSILON), WithMotionClassification( MotionClassification::MULTI_FINGER_SWIPE), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) { @@ -2685,20 +2525,19 @@ TEST_F(GestureConverterTestWithChoreographer, ResetDuringPinch) { 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(2u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(2u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithMotionClassification(MotionClassification::PINCH), WithGesturePinchScaleFactor(1.0f, EPSILON), - WithPointerCount(1u), WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPointerCount(1u))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithCoords(0, 0), - WithMotionClassification(MotionClassification::NONE), - WithToolType(ToolType::FINGER), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithMotionClassification(MotionClassification::NONE))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, FlingTapDown) { @@ -2737,41 +2576,31 @@ TEST_F(GestureConverterTestWithChoreographer, Tap) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(0), WithCoords(0, 0), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithCoords(0, 0), WithRelativeMotion(0, 0), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithButtonState(0), WithPressure(0.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), + WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F(GestureConverterTestWithChoreographer, Click) { @@ -2794,24 +2623,21 @@ TEST_F(GestureConverterTestWithChoreographer, Click) { ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithPressure(1.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), + WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* down= */ GESTURES_BUTTON_NONE, @@ -2822,21 +2648,18 @@ TEST_F(GestureConverterTestWithChoreographer, Click) { ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), - WithButtonState(0), WithCoords(0, 0), - WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), - WithCoords(0, 0), WithRelativeMotion(0, 0), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithPressure(0.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithButtonState(0), WithCoords(0, 0), + WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); } TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabled, @@ -2929,33 +2752,28 @@ TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, TapWithTapToClickDisabl /* down= */ GESTURES_BUTTON_LEFT, /* up= */ GESTURES_BUTTON_LEFT, /* is_tap= */ true); args = converter.handleGesture(currentTime, currentTime, currentTime, tapGesture); - - ASSERT_EQ(6u, args.size()); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), - WithRelativeMotion(0.f, 0.f), WithButtonState(0))); - args.pop_front(); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), WithRelativeMotion(0.f, 0.f), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))); - args.pop_front(); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), - WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(1), - WithRelativeMotion(0.f, 0.f))); - args.pop_front(); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), - WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(0), - WithRelativeMotion(0.f, 0.f))); - args.pop_front(); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), WithRelativeMotion(0.f, 0.f), - WithButtonState(0))); - args.pop_front(); - ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()), - AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), WithRelativeMotion(0, 0), - WithButtonState(0))); + ASSERT_THAT(args, + ElementsAre(VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), + WithButtonState(0))), + VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), + WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), + VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), + WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), + WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY))), + VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_RELEASE), + WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), + WithButtonState(0))), + VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_UP), + WithButtonState(0))), + VariantWith<NotifyMotionArgs>( + AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_ENTER), + WithButtonState(0))))); + ASSERT_THAT(args, Each(VariantWith<NotifyMotionArgs>(WithRelativeMotion(0.f, 0.f)))); } TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisabled, @@ -2981,24 +2799,21 @@ TEST_F_WITH_FLAGS(GestureConverterTestWithChoreographer, ClickWithTapToClickDisa ASSERT_THAT(args, ElementsAre(VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_HOVER_EXIT), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(0), - WithPressure(0.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithButtonState(0), WithPressure(0.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_DOWN), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), WithDisplayId(ADISPLAY_ID_DEFAULT))), + WithPressure(1.0f))), VariantWith<NotifyMotionArgs>( AllOf(WithMotionAction(AMOTION_EVENT_ACTION_BUTTON_PRESS), WithActionButton(AMOTION_EVENT_BUTTON_PRIMARY), WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithCoords(0, 0), WithRelativeMotion(0.f, 0.f), - WithToolType(ToolType::FINGER), - WithButtonState(AMOTION_EVENT_BUTTON_PRIMARY), - WithPressure(1.0f), - WithDisplayId(ADISPLAY_ID_DEFAULT))))); + WithPressure(1.0f))))); + ASSERT_THAT(args, + Each(VariantWith<NotifyMotionArgs>(AllOf(WithCoords(0, 0), + WithRelativeMotion(0.f, 0.f), + WithToolType(ToolType::FINGER), + WithDisplayId(ADISPLAY_ID_DEFAULT))))); Gesture buttonUpGesture(kGestureButtonsChange, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* down= */ GESTURES_BUTTON_NONE, diff --git a/services/inputflinger/tests/InputReader_test.cpp b/services/inputflinger/tests/InputReader_test.cpp index c1dc7ffcfb..476f755bae 100644 --- a/services/inputflinger/tests/InputReader_test.cpp +++ b/services/inputflinger/tests/InputReader_test.cpp @@ -2893,9 +2893,12 @@ TEST_F(InputDeviceTest, Configure_UniqueId_CorrectlyMatches) { mFakePolicy->addDisplayViewport(SECONDARY_DISPLAY_ID, DISPLAY_WIDTH, DISPLAY_HEIGHT, ui::ROTATION_0, /* isActive= */ true, DISPLAY_UNIQUE_ID, NO_PORT, ViewportType::INTERNAL); + const auto initialGeneration = mDevice->getGeneration(); unused += mDevice->configure(ARBITRARY_TIME, mFakePolicy->getReaderConfiguration(), InputReaderConfiguration::Change::DISPLAY_INFO); ASSERT_EQ(DISPLAY_UNIQUE_ID, mDevice->getAssociatedDisplayUniqueId()); + ASSERT_GT(mDevice->getGeneration(), initialGeneration); + ASSERT_EQ(mDevice->getDeviceInfo().getAssociatedDisplayId(), SECONDARY_DISPLAY_ID); } /** diff --git a/services/sensorservice/Android.bp b/services/sensorservice/Android.bp index 019fefaca4..afaf0ae84f 100644 --- a/services/sensorservice/Android.bp +++ b/services/sensorservice/Android.bp @@ -10,6 +10,7 @@ package { aconfig_declarations { name: "sensorservice_flags", package: "com.android.frameworks.sensorservice.flags", + container: "system", srcs: ["senserservice_flags.aconfig"], } diff --git a/services/sensorservice/SensorService.h b/services/sensorservice/SensorService.h index ad10e7a7bd..118d9281fc 100644 --- a/services/sensorservice/SensorService.h +++ b/services/sensorservice/SensorService.h @@ -340,6 +340,12 @@ private: binder::Status onSensorPrivacyChanged(int toggleType, int sensor, bool enabled); + // This callback is used for additional automotive-specific states for sensor privacy + // such as AUTO_DRIVER_ASSISTANCE_APPS. The newly defined states will only be valid + // for camera privacy on automotive devices. onSensorPrivacyChanged() will still be + // invoked whenever the enabled status of a toggle changes. + binder::Status onSensorPrivacyStateChanged(int, int, int) {return binder::Status::ok();} + protected: std::atomic_bool mSensorPrivacyEnabled; wp<SensorService> mService; diff --git a/services/sensorservice/senserservice_flags.aconfig b/services/sensorservice/senserservice_flags.aconfig index a3bd0ee483..8d43f79950 100644 --- a/services/sensorservice/senserservice_flags.aconfig +++ b/services/sensorservice/senserservice_flags.aconfig @@ -1,4 +1,5 @@ package: "com.android.frameworks.sensorservice.flags" +container: "system" flag { name: "dynamic_sensor_hal_reconnect_handling" diff --git a/services/surfaceflinger/Android.bp b/services/surfaceflinger/Android.bp index 0989863b7d..dcef9a3775 100644 --- a/services/surfaceflinger/Android.bp +++ b/services/surfaceflinger/Android.bp @@ -10,6 +10,7 @@ package { aconfig_declarations { name: "surfaceflinger_flags", package: "com.android.graphics.surfaceflinger.flags", + container: "system", srcs: ["surfaceflinger_flags.aconfig"], } diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/CachedSet.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/CachedSet.h index d26ca9dd00..e2d17ee502 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/CachedSet.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/CachedSet.h @@ -147,8 +147,6 @@ public: bool hasProtectedLayers() const; - bool hasSolidColorLayers() const; - // True if any layer in this cached set has CachingHint::Disabled bool cachingHintExcludesLayers() const; diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h index 1f241b091c..dc3821ca43 100644 --- a/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h +++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/impl/planner/LayerState.h @@ -258,11 +258,6 @@ public: gui::CachingHint getCachingHint() const { return mCachingHint.get(); } - bool hasSolidColorCompositionType() const { - return getOutputLayer()->getLayerFE().getCompositionState()->compositionType == - aidl::android::hardware::graphics::composer3::Composition::SOLID_COLOR; - } - float getFps() const { return getOutputLayer()->getLayerFE().getCompositionState()->fps; } void dump(std::string& result) const; diff --git a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp index 7fe3369f88..091c207464 100644 --- a/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp +++ b/services/surfaceflinger/CompositionEngine/src/OutputLayer.cpp @@ -394,7 +394,6 @@ void OutputLayer::writeStateToHWC(bool includeGeometry, bool skipLayer, uint32_t auto requestedCompositionType = outputIndependentState->compositionType; if (requestedCompositionType == Composition::SOLID_COLOR && state.overrideInfo.buffer) { - // this should never happen, as SOLID_COLOR is skipped from caching, b/230073351 requestedCompositionType = Composition::DEVICE; } @@ -665,6 +664,9 @@ void OutputLayer::uncacheBuffers(const std::vector<uint64_t>& bufferIdsToUncache void OutputLayer::writeBufferStateToHWC(HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState, bool skipLayer) { + if (skipLayer && outputIndependentState.buffer == nullptr) { + return; + } auto supportedPerFrameMetadata = getOutput().getDisplayColorProfile()->getSupportedPerFrameMetadata(); if (auto error = hwcLayer->setPerFrameMetadata(supportedPerFrameMetadata, diff --git a/services/surfaceflinger/CompositionEngine/src/planner/CachedSet.cpp b/services/surfaceflinger/CompositionEngine/src/planner/CachedSet.cpp index 869dda61bb..1f53588412 100644 --- a/services/surfaceflinger/CompositionEngine/src/planner/CachedSet.cpp +++ b/services/surfaceflinger/CompositionEngine/src/planner/CachedSet.cpp @@ -393,12 +393,6 @@ bool CachedSet::hasProtectedLayers() const { [](const Layer& layer) { return layer.getState()->isProtected(); }); } -bool CachedSet::hasSolidColorLayers() const { - return std::any_of(mLayers.cbegin(), mLayers.cend(), [](const Layer& layer) { - return layer.getState()->hasSolidColorCompositionType(); - }); -} - bool CachedSet::cachingHintExcludesLayers() const { const bool shouldExcludeLayers = std::any_of(mLayers.cbegin(), mLayers.cend(), [](const Layer& layer) { diff --git a/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp b/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp index 91cfe5dd41..0a5c43a99b 100644 --- a/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp +++ b/services/surfaceflinger/CompositionEngine/src/planner/Flattener.cpp @@ -513,13 +513,6 @@ void Flattener::buildCachedSets(time_point now) { } } - for (const CachedSet& layer : mLayers) { - if (layer.hasSolidColorLayers()) { - ATRACE_NAME("layer->hasSolidColorLayers()"); - return; - } - } - std::vector<Run> runs = findCandidateRuns(now); std::optional<Run> bestRun = findBestRun(runs); diff --git a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp index a7296f3d7a..62cfaf412c 100644 --- a/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp +++ b/services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp @@ -4018,7 +4018,6 @@ TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, TEST_F(OutputComposeSurfacesTest_UsesExpectedDisplaySettings, usesExpectedDisplaySettingsWithFp16Buffer) { SET_FLAG_FOR_TEST(flags::fp16_client_target, true); - ALOGE("alecmouri: %d", flags::fp16_client_target()); verify().ifMixedCompositionIs(false) .andIfUsesHdr(true) .withDisplayBrightnessNits(kDisplayLuminance) diff --git a/services/surfaceflinger/Display/DisplayModeRequest.h b/services/surfaceflinger/Display/DisplayModeRequest.h index d07cdf55d2..ec3ec526a1 100644 --- a/services/surfaceflinger/Display/DisplayModeRequest.h +++ b/services/surfaceflinger/Display/DisplayModeRequest.h @@ -16,6 +16,7 @@ #pragma once +#include <android-base/stringprintf.h> #include <ftl/non_null.h> #include <scheduler/FrameRateMode.h> @@ -27,10 +28,19 @@ struct DisplayModeRequest { // Whether to emit DisplayEventReceiver::DISPLAY_EVENT_MODE_CHANGE. bool emitEvent = false; + + // Whether to force the request to be applied, even if the mode is unchanged. + bool force = false; }; inline bool operator==(const DisplayModeRequest& lhs, const DisplayModeRequest& rhs) { return lhs.mode == rhs.mode && lhs.emitEvent == rhs.emitEvent; } +inline std::string to_string(const DisplayModeRequest& request) { + constexpr const char* kBool[] = {"false", "true"}; + return base::StringPrintf("{mode=%s, emitEvent=%s, force=%s}", to_string(request.mode).c_str(), + kBool[request.emitEvent], kBool[request.force]); +} + } // namespace android::display diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp index 5f20cd9c87..62f8fb16f0 100644 --- a/services/surfaceflinger/DisplayDevice.cpp +++ b/services/surfaceflinger/DisplayDevice.cpp @@ -24,6 +24,7 @@ #define ATRACE_TAG ATRACE_TAG_GRAPHICS +#include <common/FlagManager.h> #include <compositionengine/CompositionEngine.h> #include <compositionengine/Display.h> #include <compositionengine/DisplayColorProfile.h> @@ -214,6 +215,17 @@ void DisplayDevice::setActiveMode(DisplayModeId modeId, Fps vsyncRate, Fps rende bool DisplayDevice::initiateModeChange(display::DisplayModeRequest&& desiredMode, const hal::VsyncPeriodChangeConstraints& constraints, hal::VsyncPeriodChangeTimeline& outTimeline) { + // TODO(b/255635711): Flow the DisplayModeRequest through the desired/pending/active states. For + // now, `desiredMode` and `mDesiredModeOpt` are one and the same, but the latter is not cleared + // until the next `SF::initiateDisplayModeChanges`. However, the desired mode has been consumed + // at this point, so clear the `force` flag to prevent an endless loop of `initiateModeChange`. + if (FlagManager::getInstance().connected_display()) { + std::scoped_lock lock(mDesiredModeLock); + if (mDesiredModeOpt) { + mDesiredModeOpt->force = false; + } + } + mPendingModeOpt = std::move(desiredMode); mIsModeSetPending = true; @@ -517,29 +529,27 @@ void DisplayDevice::animateOverlay() { } } -auto DisplayDevice::setDesiredMode(display::DisplayModeRequest&& desiredMode, bool force) - -> DesiredModeAction { - ATRACE_CALL(); - - const auto& desiredModePtr = desiredMode.mode.modePtr; - - LOG_ALWAYS_FATAL_IF(getPhysicalId() != desiredModePtr->getPhysicalDisplayId(), - "DisplayId mismatch"); - - ALOGV("%s(%s)", __func__, to_string(*desiredModePtr).c_str()); +auto DisplayDevice::setDesiredMode(display::DisplayModeRequest&& desiredMode) -> DesiredModeAction { + ATRACE_NAME(concatId(__func__).c_str()); + ALOGD("%s %s", concatId(__func__).c_str(), to_string(desiredMode).c_str()); std::scoped_lock lock(mDesiredModeLock); if (mDesiredModeOpt) { // A mode transition was already scheduled, so just override the desired mode. const bool emitEvent = mDesiredModeOpt->emitEvent; + const bool force = mDesiredModeOpt->force; mDesiredModeOpt = std::move(desiredMode); mDesiredModeOpt->emitEvent |= emitEvent; + if (FlagManager::getInstance().connected_display()) { + mDesiredModeOpt->force |= force; + } return DesiredModeAction::None; } // If the desired mode is already active... const auto activeMode = refreshRateSelector().getActiveMode(); - if (!force && activeMode.modePtr->getId() == desiredModePtr->getId()) { + if (const auto& desiredModePtr = desiredMode.mode.modePtr; + !desiredMode.force && activeMode.modePtr->getId() == desiredModePtr->getId()) { if (activeMode == desiredMode.mode) { return DesiredModeAction::None; } diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h index 4ab6321064..edd57cce91 100644 --- a/services/surfaceflinger/DisplayDevice.h +++ b/services/surfaceflinger/DisplayDevice.h @@ -189,8 +189,7 @@ public: enum class DesiredModeAction { None, InitiateDisplayModeSwitch, InitiateRenderRateSwitch }; - DesiredModeAction setDesiredMode(display::DisplayModeRequest&&, bool force = false) - EXCLUDES(mDesiredModeLock); + DesiredModeAction setDesiredMode(display::DisplayModeRequest&&) EXCLUDES(mDesiredModeLock); using DisplayModeRequestOpt = ftl::Optional<display::DisplayModeRequest>; diff --git a/services/surfaceflinger/DisplayHardware/HWC2.cpp b/services/surfaceflinger/DisplayHardware/HWC2.cpp index 704ece516d..84f668d9df 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.cpp +++ b/services/surfaceflinger/DisplayHardware/HWC2.cpp @@ -27,6 +27,7 @@ #include "HWC2.h" #include <android/configuration.h> +#include <common/FlagManager.h> #include <ui/Fence.h> #include <ui/FloatRect.h> #include <ui/GraphicBuffer.h> @@ -281,19 +282,28 @@ Error Display::getRequests(HWC2::DisplayRequest* outDisplayRequests, return Error::NONE; } -Error Display::getConnectionType(ui::DisplayConnectionType* outType) const { - if (mType != DisplayType::PHYSICAL) return Error::BAD_DISPLAY; +ftl::Expected<ui::DisplayConnectionType, hal::Error> Display::getConnectionType() const { + if (!mConnectionType) { + mConnectionType = [this]() -> decltype(mConnectionType) { + if (mType != DisplayType::PHYSICAL) { + return ftl::Unexpected(Error::BAD_DISPLAY); + } - using ConnectionType = Hwc2::IComposerClient::DisplayConnectionType; - ConnectionType connectionType; - const auto error = static_cast<Error>(mComposer.getDisplayConnectionType(mId, &connectionType)); - if (error != Error::NONE) { - return error; + using ConnectionType = Hwc2::IComposerClient::DisplayConnectionType; + ConnectionType connectionType; + + if (const auto error = static_cast<Error>( + mComposer.getDisplayConnectionType(mId, &connectionType)); + error != Error::NONE) { + return ftl::Unexpected(error); + } + + return connectionType == ConnectionType::INTERNAL ? ui::DisplayConnectionType::Internal + : ui::DisplayConnectionType::External; + }(); } - *outType = connectionType == ConnectionType::INTERNAL ? ui::DisplayConnectionType::Internal - : ui::DisplayConnectionType::External; - return Error::NONE; + return *mConnectionType; } bool Display::hasCapability(DisplayCapability capability) const { @@ -416,7 +426,14 @@ Error Display::setActiveConfigWithConstraints(hal::HWConfigId configId, VsyncPeriodChangeTimeline* outTimeline) { ALOGV("[%" PRIu64 "] setActiveConfigWithConstraints", mId); - if (isVsyncPeriodSwitchSupported()) { + // FIXME (b/319505580): At least the first config set on an external display must be + // `setActiveConfig`, so skip over the block that calls `setActiveConfigWithConstraints` + // for simplicity. + const bool connected_display = FlagManager::getInstance().connected_display(); + + if (isVsyncPeriodSwitchSupported() && + (!connected_display || + getConnectionType().value_opt() != ui::DisplayConnectionType::External)) { Hwc2::IComposerClient::VsyncPeriodChangeConstraints hwc2Constraints; hwc2Constraints.desiredTimeNanos = constraints.desiredTimeNanos; hwc2Constraints.seamlessRequired = constraints.seamlessRequired; diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h index f907061774..de044e0b76 100644 --- a/services/surfaceflinger/DisplayHardware/HWC2.h +++ b/services/surfaceflinger/DisplayHardware/HWC2.h @@ -18,6 +18,7 @@ #include <android-base/expected.h> #include <android-base/thread_annotations.h> +#include <ftl/expected.h> #include <ftl/future.h> #include <gui/HdrMetadata.h> #include <math/mat4.h> @@ -120,7 +121,8 @@ public: [[nodiscard]] virtual hal::Error getRequests( hal::DisplayRequest* outDisplayRequests, std::unordered_map<Layer*, hal::LayerRequest>* outLayerRequests) = 0; - [[nodiscard]] virtual hal::Error getConnectionType(ui::DisplayConnectionType*) const = 0; + [[nodiscard]] virtual ftl::Expected<ui::DisplayConnectionType, hal::Error> getConnectionType() + const = 0; [[nodiscard]] virtual hal::Error supportsDoze(bool* outSupport) const = 0; [[nodiscard]] virtual hal::Error getHdrCapabilities( android::HdrCapabilities* outCapabilities) const = 0; @@ -213,7 +215,7 @@ public: hal::Error getRequests( hal::DisplayRequest* outDisplayRequests, std::unordered_map<HWC2::Layer*, hal::LayerRequest>* outLayerRequests) override; - hal::Error getConnectionType(ui::DisplayConnectionType*) const override; + ftl::Expected<ui::DisplayConnectionType, hal::Error> getConnectionType() const override; hal::Error supportsDoze(bool* outSupport) const override EXCLUDES(mDisplayCapabilitiesMutex); hal::Error getHdrCapabilities(android::HdrCapabilities* outCapabilities) const override; hal::Error getOverlaySupport(aidl::android::hardware::graphics::composer3::OverlayProperties* @@ -294,6 +296,8 @@ private: const hal::HWDisplayId mId; hal::DisplayType mType; + // Cached on first call to getConnectionType. + mutable std::optional<ftl::Expected<ui::DisplayConnectionType, hal::Error>> mConnectionType; bool mIsConnected = false; using Layers = std::unordered_map<hal::HWLayerId, std::weak_ptr<HWC2::impl::Layer>>; diff --git a/services/surfaceflinger/DisplayHardware/HWComposer.cpp b/services/surfaceflinger/DisplayHardware/HWComposer.cpp index bac24c701e..cfa03397d6 100644 --- a/services/surfaceflinger/DisplayHardware/HWComposer.cpp +++ b/services/surfaceflinger/DisplayHardware/HWComposer.cpp @@ -364,15 +364,13 @@ ui::DisplayConnectionType HWComposer::getDisplayConnectionType(PhysicalDisplayId RETURN_IF_INVALID_DISPLAY(displayId, ui::DisplayConnectionType::Internal); const auto& hwcDisplay = mDisplayData.at(displayId).hwcDisplay; - ui::DisplayConnectionType type; - const auto error = hwcDisplay->getConnectionType(&type); - - const auto FALLBACK_TYPE = hwcDisplay->getId() == mPrimaryHwcDisplayId - ? ui::DisplayConnectionType::Internal - : ui::DisplayConnectionType::External; - - RETURN_IF_HWC_ERROR(error, displayId, FALLBACK_TYPE); - return type; + if (const auto connectionType = hwcDisplay->getConnectionType()) { + return connectionType.value(); + } else { + LOG_HWC_ERROR(__func__, connectionType.error(), displayId); + return hwcDisplay->getId() == mPrimaryHwcDisplayId ? ui::DisplayConnectionType::Internal + : ui::DisplayConnectionType::External; + } } bool HWComposer::isVsyncPeriodSwitchSupported(PhysicalDisplayId displayId) const { diff --git a/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp b/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp index ee6d37bc9c..a0c943ba72 100644 --- a/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp +++ b/services/surfaceflinger/DisplayHardware/PowerAdvisor.cpp @@ -48,7 +48,6 @@ namespace impl { using aidl::android::hardware::power::Boost; using aidl::android::hardware::power::Mode; using aidl::android::hardware::power::SessionHint; -using aidl::android::hardware::power::SessionTag; using aidl::android::hardware::power::WorkDuration; PowerAdvisor::~PowerAdvisor() = default; @@ -207,12 +206,9 @@ bool PowerAdvisor::supportsPowerHintSession() { bool PowerAdvisor::ensurePowerHintSessionRunning() { if (mHintSession == nullptr && !mHintSessionThreadIds.empty() && usePowerHintSession()) { - auto ret = - getPowerHal().createHintSessionWithConfig(getpid(), static_cast<int32_t>(getuid()), - mHintSessionThreadIds, - mTargetDuration.ns(), - SessionTag::SURFACEFLINGER, - &mSessionConfig); + auto ret = getPowerHal().createHintSession(getpid(), static_cast<int32_t>(getuid()), + mHintSessionThreadIds, mTargetDuration.ns()); + if (ret.isOk()) { mHintSession = ret.value(); } diff --git a/services/surfaceflinger/DisplayHardware/PowerAdvisor.h b/services/surfaceflinger/DisplayHardware/PowerAdvisor.h index d6ffb2af1f..bbe51cc09d 100644 --- a/services/surfaceflinger/DisplayHardware/PowerAdvisor.h +++ b/services/surfaceflinger/DisplayHardware/PowerAdvisor.h @@ -292,9 +292,6 @@ private: // Whether we should send reportActualWorkDuration calls static const bool sUseReportActualDuration; - // Metadata about the session returned from PowerHAL - aidl::android::hardware::power::SessionConfig mSessionConfig; - // How long we expect hwc to run after the present call until it waits for the fence static constexpr const Duration kFenceWaitStartDelayValidated{150us}; static constexpr const Duration kFenceWaitStartDelaySkippedValidate{250us}; diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp index 3ef9e69620..ea06cf6de6 100644 --- a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp +++ b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp @@ -381,6 +381,9 @@ void LayerSnapshot::merge(const RequestedLayerState& requested, bool forceUpdate currentHdrSdrRatio = requested.currentHdrSdrRatio; desiredHdrSdrRatio = requested.desiredHdrSdrRatio; } + if (forceUpdate || requested.what & layer_state_t::eDesiredHdrHeadroomChanged) { + desiredHdrSdrRatio = requested.desiredHdrSdrRatio; + } if (forceUpdate || requested.what & layer_state_t::eCachingHintChanged) { cachingHint = requested.cachingHint; } diff --git a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp index 2cf4c1b7dd..cb0e2a1938 100644 --- a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp +++ b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp @@ -98,7 +98,7 @@ RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args) z = 0; layerStack = ui::DEFAULT_LAYER_STACK; transformToDisplayInverse = false; - desiredHdrSdrRatio = 1.f; + desiredHdrSdrRatio = -1.f; currentHdrSdrRatio = 1.f; dataspaceRequested = false; hdrMetadata.validTypes = 0; @@ -606,7 +606,8 @@ bool RequestedLayerState::isSimpleBufferUpdate(const layer_state_t& s) const { layer_state_t::eShadowRadiusChanged | layer_state_t::eFixedTransformHintChanged | layer_state_t::eTrustedOverlayChanged | layer_state_t::eStretchChanged | layer_state_t::eBufferCropChanged | layer_state_t::eDestinationFrameChanged | - layer_state_t::eDimmingEnabledChanged | layer_state_t::eExtendedRangeBrightnessChanged; + layer_state_t::eDimmingEnabledChanged | layer_state_t::eExtendedRangeBrightnessChanged | + layer_state_t::eDesiredHdrHeadroomChanged; if (changedFlags & deniedChanges) { ATRACE_FORMAT_INSTANT("%s: false [has denied changes flags 0x%" PRIx64 "]", __func__, s.what & deniedChanges); diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp index 219a8e20a4..736fec6fb2 100644 --- a/services/surfaceflinger/Layer.cpp +++ b/services/surfaceflinger/Layer.cpp @@ -3395,6 +3395,14 @@ bool Layer::setExtendedRangeBrightness(float currentBufferRatio, float desiredRa return true; } +bool Layer::setDesiredHdrHeadroom(float desiredRatio) { + if (mDrawingState.desiredHdrSdrRatio == desiredRatio) return false; + mDrawingState.desiredHdrSdrRatio = desiredRatio; + mDrawingState.modified = true; + setTransactionFlags(eTransactionNeeded); + return true; +} + bool Layer::setCachingHint(gui::CachingHint cachingHint) { if (mDrawingState.cachingHint == cachingHint) return false; mDrawingState.cachingHint = cachingHint; @@ -3991,6 +3999,13 @@ bool Layer::isSimpleBufferUpdate(const layer_state_t& s) const { } } + if (s.what & layer_state_t::eDesiredHdrHeadroomChanged) { + if (mDrawingState.desiredHdrSdrRatio != s.desiredHdrSdrRatio) { + ATRACE_FORMAT_INSTANT("%s: false [eDesiredHdrHeadroomChanged changed]", __func__); + return false; + } + } + return true; } diff --git a/services/surfaceflinger/Layer.h b/services/surfaceflinger/Layer.h index dfd57c65e3..0ceecec7ec 100644 --- a/services/surfaceflinger/Layer.h +++ b/services/surfaceflinger/Layer.h @@ -233,7 +233,7 @@ public: bool autoRefresh = false; bool dimmingEnabled = true; float currentHdrSdrRatio = 1.f; - float desiredHdrSdrRatio = 1.f; + float desiredHdrSdrRatio = -1.f; gui::CachingHint cachingHint = gui::CachingHint::Enabled; int64_t latchedVsyncId = 0; bool useVsyncIdForRefreshRateSelection = false; @@ -317,6 +317,7 @@ public: void setDesiredPresentTime(nsecs_t /*desiredPresentTime*/, bool /*isAutoTimestamp*/); bool setDataspace(ui::Dataspace /*dataspace*/); bool setExtendedRangeBrightness(float currentBufferRatio, float desiredRatio); + bool setDesiredHdrHeadroom(float desiredRatio); bool setCachingHint(gui::CachingHint cachingHint); bool setHdrMetadata(const HdrMetadata& /*hdrMetadata*/); bool setSurfaceDamageRegion(const Region& /*surfaceDamage*/); @@ -546,7 +547,7 @@ public: sp<IBinder> mReleaseBufferEndpoint; bool mFrameLatencyNeeded{false}; - float mDesiredHdrSdrRatio = 1.f; + float mDesiredHdrSdrRatio = -1.f; }; BufferInfo mBufferInfo; diff --git a/services/surfaceflinger/Scheduler/LayerInfo.cpp b/services/surfaceflinger/Scheduler/LayerInfo.cpp index 9c4f7a510b..9745452e89 100644 --- a/services/surfaceflinger/Scheduler/LayerInfo.cpp +++ b/services/surfaceflinger/Scheduler/LayerInfo.cpp @@ -327,7 +327,8 @@ LayerInfo::RefreshRateVotes LayerInfo::getRefreshRateVote(const RefreshRateSelec mLayerVote.type != LayerHistory::LayerVoteType::ExplicitDefault) { ATRACE_FORMAT_INSTANT("Vote %s", ftl::enum_string(mLayerVote.type).c_str()); ALOGV("%s voted %d", mName.c_str(), static_cast<int>(mLayerVote.type)); - votes.push_back(mLayerVote); + votes.push_back({mLayerVote.type, mLayerVote.fps, mLayerVote.seamlessness, + FrameRateCategory::Default, mLayerVote.categorySmoothSwitchOnly}); } return votes; diff --git a/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp b/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp index eeca6bea7a..e696e8c358 100644 --- a/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp +++ b/services/surfaceflinger/Scheduler/RefreshRateSelector.cpp @@ -855,7 +855,7 @@ auto RefreshRateSelector::getRankedFrameRatesLocked(const std::vector<LayerRequi ALOGV("Touch Boost"); ATRACE_FORMAT_INSTANT("%s (Touch Boost [late])", to_string(touchRefreshRates.front().frameRateMode.fps).c_str()); - return {touchRefreshRates, GlobalSignals{.touch = signals.touch}}; + return {touchRefreshRates, GlobalSignals{.touch = true}}; } // If we never scored any layers, and we don't favor high refresh rates, prefer to stay with the diff --git a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp index 963f9e9f6c..b92fa24670 100644 --- a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp +++ b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.cpp @@ -43,16 +43,6 @@ nsecs_t getExpectedCallbackTime(nsecs_t nextVsyncTime, return nextVsyncTime - timing.readyDuration - timing.workDuration; } -nsecs_t getExpectedCallbackTime(VSyncTracker& tracker, nsecs_t now, - const VSyncDispatch::ScheduleTiming& timing) { - const auto nextVsyncTime = - tracker.nextAnticipatedVSyncTimeFrom(std::max(timing.lastVsync, - now + timing.workDuration + - timing.readyDuration), - timing.lastVsync); - return getExpectedCallbackTime(nextVsyncTime, timing); -} - } // namespace VSyncDispatch::~VSyncDispatch() = default; @@ -107,7 +97,7 @@ ScheduleResult VSyncDispatchTimerQueueEntry::schedule(VSyncDispatch::ScheduleTim mArmedInfo && (nextVsyncTime > (mArmedInfo->mActualVsyncTime + mMinVsyncDistance)); bool const wouldSkipAWakeup = mArmedInfo && ((nextWakeupTime > (mArmedInfo->mActualWakeupTime + mMinVsyncDistance))); - if (FlagManager::getInstance().dont_skip_on_early()) { + if (FlagManager::getInstance().dont_skip_on_early_ro()) { if (wouldSkipAVsyncTarget || wouldSkipAWakeup) { nextVsyncTime = mArmedInfo->mActualVsyncTime; } else { @@ -128,8 +118,11 @@ ScheduleResult VSyncDispatchTimerQueueEntry::schedule(VSyncDispatch::ScheduleTim return nextWakeupTime; } -void VSyncDispatchTimerQueueEntry::addPendingWorkloadUpdate(VSyncDispatch::ScheduleTiming timing) { +nsecs_t VSyncDispatchTimerQueueEntry::addPendingWorkloadUpdate( + VSyncTracker& tracker, nsecs_t now, VSyncDispatch::ScheduleTiming timing) { mWorkloadUpdateInfo = timing; + const auto armedInfo = update(tracker, now, timing, mArmedInfo); + return armedInfo.mActualWakeupTime; } bool VSyncDispatchTimerQueueEntry::hasPendingWorkloadUpdate() const { @@ -157,6 +150,31 @@ nsecs_t VSyncDispatchTimerQueueEntry::adjustVsyncIfNeeded(VSyncTracker& tracker, return nextVsyncTime; } +auto VSyncDispatchTimerQueueEntry::update(VSyncTracker& tracker, nsecs_t now, + VSyncDispatch::ScheduleTiming timing, + std::optional<ArmingInfo> armedInfo) const -> ArmingInfo { + const auto earliestReadyBy = now + timing.workDuration + timing.readyDuration; + const auto earliestVsync = std::max(earliestReadyBy, timing.lastVsync); + + const auto nextVsyncTime = + adjustVsyncIfNeeded(tracker, /*nextVsyncTime*/ + tracker.nextAnticipatedVSyncTimeFrom(earliestVsync, + timing.lastVsync)); + const auto nextReadyTime = nextVsyncTime - timing.readyDuration; + const auto nextWakeupTime = nextReadyTime - timing.workDuration; + + bool const wouldSkipAVsyncTarget = + armedInfo && (nextVsyncTime > (armedInfo->mActualVsyncTime + mMinVsyncDistance)); + bool const wouldSkipAWakeup = + armedInfo && (nextWakeupTime > (armedInfo->mActualWakeupTime + mMinVsyncDistance)); + if (FlagManager::getInstance().dont_skip_on_early_ro() && + (wouldSkipAVsyncTarget || wouldSkipAWakeup)) { + return *armedInfo; + } + + return ArmingInfo{nextWakeupTime, nextVsyncTime, nextReadyTime}; +} + void VSyncDispatchTimerQueueEntry::update(VSyncTracker& tracker, nsecs_t now) { if (!mArmedInfo && !mWorkloadUpdateInfo) { return; @@ -167,17 +185,7 @@ void VSyncDispatchTimerQueueEntry::update(VSyncTracker& tracker, nsecs_t now) { mWorkloadUpdateInfo.reset(); } - const auto earliestReadyBy = now + mScheduleTiming.workDuration + mScheduleTiming.readyDuration; - const auto earliestVsync = std::max(earliestReadyBy, mScheduleTiming.lastVsync); - - const auto nextVsyncTime = - adjustVsyncIfNeeded(tracker, /*nextVsyncTime*/ - tracker.nextAnticipatedVSyncTimeFrom(earliestVsync, - mScheduleTiming.lastVsync)); - const auto nextReadyTime = nextVsyncTime - mScheduleTiming.readyDuration; - const auto nextWakeupTime = nextReadyTime - mScheduleTiming.workDuration; - - mArmedInfo = {nextWakeupTime, nextVsyncTime, nextReadyTime}; + mArmedInfo = update(tracker, now, mScheduleTiming, mArmedInfo); } void VSyncDispatchTimerQueueEntry::disarm() { @@ -394,8 +402,7 @@ ScheduleResult VSyncDispatchTimerQueue::scheduleLocked(CallbackToken token, * timer recalculation to avoid cancelling a callback that is about to fire. */ auto const rearmImminent = now > mIntendedWakeupTime; if (CC_UNLIKELY(rearmImminent)) { - callback->addPendingWorkloadUpdate(scheduleTiming); - return getExpectedCallbackTime(*mTracker, now, scheduleTiming); + return callback->addPendingWorkloadUpdate(*mTracker, now, scheduleTiming); } const ScheduleResult result = callback->schedule(scheduleTiming, *mTracker, now); diff --git a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h index 81c746e866..b5ddd25293 100644 --- a/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h +++ b/services/surfaceflinger/Scheduler/VSyncDispatchTimerQueue.h @@ -69,7 +69,7 @@ public: // Adds a pending upload of the earliestVSync and workDuration that will be applied on the next // call to update() - void addPendingWorkloadUpdate(VSyncDispatch::ScheduleTiming); + nsecs_t addPendingWorkloadUpdate(VSyncTracker&, nsecs_t now, VSyncDispatch::ScheduleTiming); // Checks if there is a pending update to the workload, returning true if so. bool hasPendingWorkloadUpdate() const; @@ -83,7 +83,15 @@ public: void dump(std::string& result) const; private: + struct ArmingInfo { + nsecs_t mActualWakeupTime; + nsecs_t mActualVsyncTime; + nsecs_t mActualReadyTime; + }; + nsecs_t adjustVsyncIfNeeded(VSyncTracker& tracker, nsecs_t nextVsyncTime) const; + ArmingInfo update(VSyncTracker&, nsecs_t now, VSyncDispatch::ScheduleTiming, + std::optional<ArmingInfo>) const; const std::string mName; const VSyncDispatch::Callback mCallback; @@ -91,11 +99,6 @@ private: VSyncDispatch::ScheduleTiming mScheduleTiming; const nsecs_t mMinVsyncDistance; - struct ArmingInfo { - nsecs_t mActualWakeupTime; - nsecs_t mActualVsyncTime; - nsecs_t mActualReadyTime; - }; std::optional<ArmingInfo> mArmedInfo; std::optional<nsecs_t> mLastDispatchTime; diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 173b6fed3b..5bb550834e 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -1230,8 +1230,10 @@ status_t SurfaceFlinger::getDisplayStats(const sp<IBinder>& displayToken, return NO_ERROR; } -void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& request, bool force) { - const auto displayId = request.mode.modePtr->getPhysicalDisplayId(); +void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& desiredMode) { + const auto mode = desiredMode.mode; + const auto displayId = mode.modePtr->getPhysicalDisplayId(); + ATRACE_NAME(ftl::Concat(__func__, ' ', displayId.value).c_str()); const auto display = getDisplayDeviceLocked(displayId); @@ -1240,10 +1242,9 @@ void SurfaceFlinger::setDesiredMode(display::DisplayModeRequest&& request, bool return; } - const auto mode = request.mode; - const bool emitEvent = request.emitEvent; + const bool emitEvent = desiredMode.emitEvent; - switch (display->setDesiredMode(std::move(request), force)) { + switch (display->setDesiredMode(std::move(desiredMode))) { case DisplayDevice::DesiredModeAction::InitiateDisplayModeSwitch: // DisplayDevice::setDesiredMode updated the render rate, so inform Scheduler. mScheduler->setRenderRate(displayId, @@ -1429,7 +1430,8 @@ void SurfaceFlinger::initiateDisplayModeChanges() { to_string(displayModePtrOpt->get()->getVsyncRate()).c_str(), to_string(display->getId()).c_str()); - if (display->getActiveMode() == desiredModeOpt->mode) { + if ((!FlagManager::getInstance().connected_display() || !desiredModeOpt->force) && + display->getActiveMode() == desiredModeOpt->mode) { applyActiveMode(display); continue; } @@ -3109,6 +3111,7 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId, for (auto& [compositionDisplay, listener] : hdrInfoListeners) { HdrLayerInfoReporter::HdrLayerInfo info; int32_t maxArea = 0; + auto updateInfoFn = [&](const std::shared_ptr<compositionengine::Display>& compositionDisplay, const frontend::LayerSnapshot& snapshot, const sp<LayerFE>& layerFe) { @@ -3119,7 +3122,7 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId, compositionDisplay->getOutputLayerForLayer(layerFe); if (outputLayer) { const float desiredHdrSdrRatio = - snapshot.desiredHdrSdrRatio <= 1.f + snapshot.desiredHdrSdrRatio < 1.f ? std::numeric_limits<float>::infinity() : snapshot.desiredHdrSdrRatio; info.mergeDesiredRatio(desiredHdrSdrRatio); @@ -3284,13 +3287,88 @@ std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( std::vector<HWComposer::HWCDisplayMode> hwcModes; std::optional<hal::HWConfigId> activeModeHwcIdOpt; + const bool isExternalDisplay = FlagManager::getInstance().connected_display() && + getHwComposer().getDisplayConnectionType(displayId) == + ui::DisplayConnectionType::External; + int attempt = 0; constexpr int kMaxAttempts = 3; do { hwcModes = getHwComposer().getModes(displayId, scheduler::RefreshRateSelector::kMinSupportedFrameRate .getPeriodNsecs()); - activeModeHwcIdOpt = getHwComposer().getActiveMode(displayId).value_opt(); + const auto activeModeHwcIdExp = getHwComposer().getActiveMode(displayId); + activeModeHwcIdOpt = activeModeHwcIdExp.value_opt(); + + if (isExternalDisplay && + activeModeHwcIdExp.has_error([](status_t error) { return error == NO_INIT; })) { + constexpr nsecs_t k59HzVsyncPeriod = 16949153; + constexpr nsecs_t k60HzVsyncPeriod = 16666667; + + // DM sets the initial mode for an external display to 1080p@60, but + // this comes after SF creates its own state (including the + // DisplayDevice). For now, pick the same mode in order to avoid + // inconsistent state and unnecessary mode switching. + // TODO (b/318534874): Let DM decide the initial mode. + // + // Try to find 1920x1080 @ 60 Hz + if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), + [](const auto& mode) { + return mode.width == 1920 && + mode.height == 1080 && + mode.vsyncPeriod == k60HzVsyncPeriod; + }); + iter != hwcModes.end()) { + activeModeHwcIdOpt = iter->hwcId; + break; + } + + // Try to find 1920x1080 @ 59-60 Hz + if (const auto iter = std::find_if(hwcModes.begin(), hwcModes.end(), + [](const auto& mode) { + return mode.width == 1920 && + mode.height == 1080 && + mode.vsyncPeriod >= k60HzVsyncPeriod && + mode.vsyncPeriod <= k59HzVsyncPeriod; + }); + iter != hwcModes.end()) { + activeModeHwcIdOpt = iter->hwcId; + break; + } + + // The display does not support 1080p@60, and this is the last attempt to pick a display + // mode. Prefer 60 Hz if available, with the closest resolution to 1080p. + if (attempt + 1 == kMaxAttempts) { + std::vector<HWComposer::HWCDisplayMode> hwcModeOpts; + + for (const auto& mode : hwcModes) { + if (mode.width <= 1920 && mode.height <= 1080 && + mode.vsyncPeriod >= k60HzVsyncPeriod && + mode.vsyncPeriod <= k59HzVsyncPeriod) { + hwcModeOpts.push_back(mode); + } + } + + if (const auto iter = std::max_element(hwcModeOpts.begin(), hwcModeOpts.end(), + [](const auto& a, const auto& b) { + const auto aSize = a.width * a.height; + const auto bSize = b.width * b.height; + if (aSize < bSize) + return true; + else if (aSize == bSize) + return a.vsyncPeriod > b.vsyncPeriod; + else + return false; + }); + iter != hwcModeOpts.end()) { + activeModeHwcIdOpt = iter->hwcId; + break; + } + + // hwcModeOpts was empty, use hwcModes[0] as the last resort + activeModeHwcIdOpt = hwcModes[0].hwcId; + } + } const auto isActiveMode = [activeModeHwcIdOpt](const HWComposer::HWCDisplayMode& mode) { return mode.hwcId == activeModeHwcIdOpt; @@ -3351,6 +3429,10 @@ std::pair<DisplayModes, DisplayModePtr> SurfaceFlinger::loadDisplayModes( return pair.second->getHwcId() == activeModeHwcIdOpt; })->second; + if (isExternalDisplay) { + ALOGI("External display %s initial mode: {%s}", to_string(displayId).c_str(), + to_string(*activeMode).c_str()); + } return {modes, activeMode}; } @@ -3659,6 +3741,27 @@ void SurfaceFlinger::processDisplayAdded(const wp<IBinder>& displayToken, } mDisplays.try_emplace(displayToken, std::move(display)); + + // For an external display, loadDisplayModes already attempted to select the same mode + // as DM, but SF still needs to be updated to match. + // TODO (b/318534874): Let DM decide the initial mode. + if (const auto& physical = state.physical; + mScheduler && physical && FlagManager::getInstance().connected_display()) { + const bool isInternalDisplay = mPhysicalDisplays.get(physical->id) + .transform(&PhysicalDisplay::isInternal) + .value_or(false); + + if (!isInternalDisplay) { + auto activeModePtr = physical->activeMode; + const auto fps = activeModePtr->getPeakFps(); + + setDesiredMode( + {.mode = scheduler::FrameRateMode{fps, + ftl::as_non_null(std::move(activeModePtr))}, + .emitEvent = false, + .force = true}); + } + } } void SurfaceFlinger::processDisplayRemoved(const wp<IBinder>& displayToken) { @@ -5457,6 +5560,11 @@ uint32_t SurfaceFlinger::setClientStateLocked(const FrameTimelineInfo& frameTime flags |= eTraversalNeeded; } } + if (what & layer_state_t::eDesiredHdrHeadroomChanged) { + if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { + flags |= eTraversalNeeded; + } + } if (what & layer_state_t::eCachingHintChanged) { if (layer->setCachingHint(s.cachingHint)) { flags |= eTraversalNeeded; @@ -5642,6 +5750,11 @@ uint32_t SurfaceFlinger::updateLayerCallbacksAndStats(const FrameTimelineInfo& f flags |= eTraversalNeeded; } } + if (what & layer_state_t::eDesiredHdrHeadroomChanged) { + if (layer->setDesiredHdrHeadroom(s.desiredHdrSdrRatio)) { + flags |= eTraversalNeeded; + } + } if (what & layer_state_t::eBufferChanged) { std::optional<ui::Transform::RotationFlags> transformHint = std::nullopt; frontend::LayerSnapshot* snapshot = mLayerSnapshotBuilder.getSnapshot(layer->sequence); @@ -8383,7 +8496,7 @@ status_t SurfaceFlinger::applyRefreshRateSelectorPolicy( return INVALID_OPERATION; } - setDesiredMode({std::move(preferredMode), .emitEvent = true}, force); + setDesiredMode({std::move(preferredMode), .emitEvent = true, .force = force}); // Update the frameRateOverride list as the display render rate might have changed if (mScheduler->updateFrameRateOverrides(scheduler::GlobalSignals{}, preferredFps)) { diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 992bc00f65..be057979f9 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -716,7 +716,7 @@ private: // Show hdr sdr ratio overlay bool mHdrSdrRatioOverlay = false; - void setDesiredMode(display::DisplayModeRequest&&, bool force = false) REQUIRES(mStateLock); + void setDesiredMode(display::DisplayModeRequest&&) REQUIRES(mStateLock); status_t setActiveModeFromBackdoor(const sp<display::DisplayToken>&, DisplayModeId, Fps minFps, Fps maxFps); diff --git a/services/surfaceflinger/common/FlagManager.cpp b/services/surfaceflinger/common/FlagManager.cpp index 425d2dac3e..f7adc0e5d6 100644 --- a/services/surfaceflinger/common/FlagManager.cpp +++ b/services/surfaceflinger/common/FlagManager.cpp @@ -108,8 +108,6 @@ void FlagManager::dump(std::string& result) const { DUMP_SERVER_FLAG(use_skia_tracing); /// Trunk stable server flags /// - DUMP_SERVER_FLAG(late_boot_misc2); - DUMP_SERVER_FLAG(dont_skip_on_early); DUMP_SERVER_FLAG(refresh_rate_overlay_on_external_display); /// Trunk stable readonly flags /// @@ -132,6 +130,7 @@ void FlagManager::dump(std::string& result) const { DUMP_READ_ONLY_FLAG(vulkan_renderengine); DUMP_READ_ONLY_FLAG(renderable_buffer_usage); DUMP_READ_ONLY_FLAG(restore_blur_step); + DUMP_READ_ONLY_FLAG(dont_skip_on_early_ro); #undef DUMP_READ_ONLY_FLAG #undef DUMP_SERVER_FLAG #undef DUMP_FLAG_INTERVAL @@ -210,16 +209,9 @@ FLAG_MANAGER_READ_ONLY_FLAG(screenshot_fence_preservation, "debug.sf.screenshot_ FLAG_MANAGER_READ_ONLY_FLAG(vulkan_renderengine, "debug.renderengine.vulkan") FLAG_MANAGER_READ_ONLY_FLAG(renderable_buffer_usage, "") FLAG_MANAGER_READ_ONLY_FLAG(restore_blur_step, "debug.renderengine.restore_blur_step") +FLAG_MANAGER_READ_ONLY_FLAG(dont_skip_on_early_ro, "") /// Trunk stable server flags /// -FLAG_MANAGER_SERVER_FLAG(late_boot_misc2, "") FLAG_MANAGER_SERVER_FLAG(refresh_rate_overlay_on_external_display, "") -/// Exceptions /// -bool FlagManager::dont_skip_on_early() const { - // Even though this is a server writable flag, we do call it before boot completed, but that's - // fine since the decision is done per frame. We can't do caching though. - return flags::dont_skip_on_early(); -} - } // namespace android diff --git a/services/surfaceflinger/common/include/common/FlagManager.h b/services/surfaceflinger/common/include/common/FlagManager.h index 86efd306a0..18f623faff 100644 --- a/services/surfaceflinger/common/include/common/FlagManager.h +++ b/services/surfaceflinger/common/include/common/FlagManager.h @@ -48,8 +48,6 @@ public: bool use_skia_tracing() const; /// Trunk stable server flags /// - bool late_boot_misc2() const; - bool dont_skip_on_early() const; bool refresh_rate_overlay_on_external_display() const; /// Trunk stable readonly flags /// @@ -72,6 +70,7 @@ public: bool vulkan_renderengine() const; bool renderable_buffer_usage() const; bool restore_blur_step() const; + bool dont_skip_on_early_ro() const; protected: // overridden for unit tests diff --git a/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.cpp b/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.cpp index 8cd6e1bb3a..ff2ee7e0f4 100644 --- a/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.cpp +++ b/services/surfaceflinger/fuzzer/surfaceflinger_scheduler_fuzzer.cpp @@ -175,7 +175,8 @@ void SchedulerFuzzer::fuzzVSyncDispatchTimerQueue() { auto const wakeup = entry.wakeupTime(); auto const ready = entry.readyTime(); entry.callback(entry.executing(), *wakeup, *ready); - entry.addPendingWorkloadUpdate({.workDuration = mFdp.ConsumeIntegral<nsecs_t>(), + entry.addPendingWorkloadUpdate(*stubTracker, 0, + {.workDuration = mFdp.ConsumeIntegral<nsecs_t>(), .readyDuration = mFdp.ConsumeIntegral<nsecs_t>(), .lastVsync = mFdp.ConsumeIntegral<nsecs_t>()}); dump<scheduler::VSyncDispatchTimerQueueEntry>(&entry, &mFdp); diff --git a/services/surfaceflinger/surfaceflinger_flags.aconfig b/services/surfaceflinger/surfaceflinger_flags.aconfig index 0ebc41be7c..f5ec1eeaf2 100644 --- a/services/surfaceflinger/surfaceflinger_flags.aconfig +++ b/services/surfaceflinger/surfaceflinger_flags.aconfig @@ -1,4 +1,5 @@ package: "com.android.graphics.surfaceflinger.flags" +container: "system" flag { name: "misc1" @@ -16,13 +17,6 @@ flag { is_fixed_read_only: true } -flag{ - name: "late_boot_misc2" - namespace: "core_graphics" - description: "This flag controls minor miscellaneous SurfaceFlinger changes. Cannot be read before boot finished!" - bug: "297389311" -} - flag { name: "vrr_config" namespace: "core_graphics" @@ -40,13 +34,6 @@ flag { } flag { - name: "dont_skip_on_early" - namespace: "core_graphics" - description: "This flag is guarding the behaviour where SurfaceFlinger is trying to opportunistically present a frame when the configuration change from late to early" - bug: "273702768" -} - -flag { name: "multithreaded_present" namespace: "core_graphics" description: "Controls whether to offload present calls to another thread" @@ -196,3 +183,14 @@ flag { purpose: PURPOSE_BUGFIX } } + +flag { + name: "dont_skip_on_early_ro" + namespace: "core_graphics" + description: "This flag is guarding the behaviour where SurfaceFlinger is trying to opportunistically present a frame when the configuration change from late to early" + bug: "273702768" + is_fixed_read_only: true + metadata { + purpose: PURPOSE_BUGFIX + } +} diff --git a/services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h b/services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h index 387d2f26e6..f26336a655 100644 --- a/services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h +++ b/services/surfaceflinger/tests/unittests/DisplayTransactionTestHelpers.h @@ -461,9 +461,11 @@ struct HwcDisplayVariant { ? IComposerClient::DisplayConnectionType::INTERNAL : IComposerClient::DisplayConnectionType::EXTERNAL; + using ::testing::AtLeast; EXPECT_CALL(*test->mComposer, getDisplayConnectionType(HWC_DISPLAY_ID, _)) - .WillOnce(DoAll(SetArgPointee<1>(CONNECTION_TYPE), - Return(hal::V2_4::Error::NONE))); + .Times(AtLeast(1)) + .WillRepeatedly(DoAll(SetArgPointee<1>(CONNECTION_TYPE), + Return(hal::V2_4::Error::NONE))); } EXPECT_CALL(*test->mComposer, setClientTargetSlotCount(_)) diff --git a/services/surfaceflinger/tests/unittests/FlagManagerTest.cpp b/services/surfaceflinger/tests/unittests/FlagManagerTest.cpp index 0c820fb291..0adf0b617a 100644 --- a/services/surfaceflinger/tests/unittests/FlagManagerTest.cpp +++ b/services/surfaceflinger/tests/unittests/FlagManagerTest.cpp @@ -28,6 +28,7 @@ namespace android { +using namespace com::android::graphics::surfaceflinger; using testing::Return; class TestableFlagManager : public FlagManager { @@ -86,26 +87,26 @@ TEST_F(FlagManagerTest, legacyReturnsValue) { TEST_F(FlagManagerTest, creashesIfQueriedBeforeBoot) { mFlagManager.markBootIncomplete(); - EXPECT_DEATH(FlagManager::getInstance().late_boot_misc2(), ""); + EXPECT_DEATH(FlagManager::getInstance() + .refresh_rate_overlay_on_external_display(), ""); } TEST_F(FlagManagerTest, returnsOverrideTrue) { mFlagManager.markBootCompleted(); - SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::late_boot_misc2, false); + SET_FLAG_FOR_TEST(flags::refresh_rate_overlay_on_external_display, false); // This is stored in a static variable, so this test depends on the fact // that this flag has not been read in this process. EXPECT_CALL(mFlagManager, getBoolProperty).WillOnce(Return(true)); - EXPECT_TRUE(mFlagManager.late_boot_misc2()); + EXPECT_TRUE(mFlagManager.refresh_rate_overlay_on_external_display()); // Further calls will not result in further calls to getBoolProperty. - EXPECT_TRUE(mFlagManager.late_boot_misc2()); + EXPECT_TRUE(mFlagManager.refresh_rate_overlay_on_external_display()); } TEST_F(FlagManagerTest, returnsOverrideReadonly) { - SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::add_sf_skipped_frames_to_trace, - false); + SET_FLAG_FOR_TEST(flags::add_sf_skipped_frames_to_trace, false); // This is stored in a static variable, so this test depends on the fact // that this flag has not been read in this process. @@ -113,12 +114,13 @@ TEST_F(FlagManagerTest, returnsOverrideReadonly) { EXPECT_TRUE(mFlagManager.add_sf_skipped_frames_to_trace()); } -TEST_F(FlagManagerTest, returnsOverrideFalse) { +// disabling this test since we need to use a unique flag for this test, +// but we only one server flag currently. Re-enable once we have a new flag +// and change this test to use a unique flag. +TEST_F(FlagManagerTest, DISABLED_returnsOverrideFalse) { mFlagManager.markBootCompleted(); - SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags:: - refresh_rate_overlay_on_external_display, - true); + SET_FLAG_FOR_TEST(flags::refresh_rate_overlay_on_external_display, true); // This is stored in a static variable, so this test depends on the fact // that this flag has not been read in this process. @@ -129,7 +131,7 @@ TEST_F(FlagManagerTest, returnsOverrideFalse) { TEST_F(FlagManagerTest, ignoresOverrideInUnitTestMode) { mFlagManager.setUnitTestMode(); - SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::multithreaded_present, true); + SET_FLAG_FOR_TEST(flags::multithreaded_present, true); // If this has not been called in this process, it will be called. // Regardless, the result is ignored. @@ -144,13 +146,13 @@ TEST_F(FlagManagerTest, returnsValue) { EXPECT_CALL(mFlagManager, getBoolProperty).WillRepeatedly(Return(std::nullopt)); { - SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::late_boot_misc2, true); - EXPECT_EQ(true, mFlagManager.late_boot_misc2()); + SET_FLAG_FOR_TEST(flags::refresh_rate_overlay_on_external_display, true); + EXPECT_EQ(true, mFlagManager.refresh_rate_overlay_on_external_display()); } { - SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::late_boot_misc2, false); - EXPECT_EQ(false, mFlagManager.late_boot_misc2()); + SET_FLAG_FOR_TEST(flags::refresh_rate_overlay_on_external_display, false); + EXPECT_EQ(false, mFlagManager.refresh_rate_overlay_on_external_display()); } } @@ -160,28 +162,14 @@ TEST_F(FlagManagerTest, readonlyReturnsValue) { EXPECT_CALL(mFlagManager, getBoolProperty).WillRepeatedly(Return(std::nullopt)); { - SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::misc1, true); + SET_FLAG_FOR_TEST(flags::misc1, true); EXPECT_EQ(true, mFlagManager.misc1()); } { - SET_FLAG_FOR_TEST(com::android::graphics::surfaceflinger::flags::misc1, false); + SET_FLAG_FOR_TEST(flags::misc1, false); EXPECT_EQ(false, mFlagManager.misc1()); } } -TEST_F(FlagManagerTest, dontSkipOnEarlyIsNotCached) { - EXPECT_CALL(mFlagManager, getBoolProperty).WillRepeatedly(Return(std::nullopt)); - - const auto initialValue = com::android::graphics::surfaceflinger::flags::dont_skip_on_early(); - - com::android::graphics::surfaceflinger::flags::dont_skip_on_early(true); - EXPECT_EQ(true, mFlagManager.dont_skip_on_early()); - - com::android::graphics::surfaceflinger::flags::dont_skip_on_early(false); - EXPECT_EQ(false, mFlagManager.dont_skip_on_early()); - - com::android::graphics::surfaceflinger::flags::dont_skip_on_early(initialValue); -} - } // namespace android diff --git a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp index a25804c909..2cff2f2929 100644 --- a/services/surfaceflinger/tests/unittests/HWComposerTest.cpp +++ b/services/surfaceflinger/tests/unittests/HWComposerTest.cpp @@ -102,6 +102,29 @@ TEST_F(HWComposerTest, isHeadless) { ASSERT_TRUE(mHwc.isHeadless()); } +TEST_F(HWComposerTest, getDisplayConnectionType) { + // Unknown display. + EXPECT_EQ(mHwc.getDisplayConnectionType(PhysicalDisplayId::fromPort(0)), + ui::DisplayConnectionType::Internal); + + constexpr hal::HWDisplayId kHwcDisplayId = 1; + expectHotplugConnect(kHwcDisplayId); + + const auto info = mHwc.onHotplug(kHwcDisplayId, hal::Connection::CONNECTED); + ASSERT_TRUE(info); + + EXPECT_CALL(*mHal, getDisplayConnectionType(kHwcDisplayId, _)) + .WillOnce(DoAll(SetArgPointee<1>(IComposerClient::DisplayConnectionType::EXTERNAL), + Return(V2_4::Error::NONE))); + + // The first call caches the connection type. + EXPECT_EQ(mHwc.getDisplayConnectionType(info->id), ui::DisplayConnectionType::External); + + // Subsequent calls return the cached connection type. + EXPECT_EQ(mHwc.getDisplayConnectionType(info->id), ui::DisplayConnectionType::External); + EXPECT_EQ(mHwc.getDisplayConnectionType(info->id), ui::DisplayConnectionType::External); +} + TEST_F(HWComposerTest, getActiveMode) { // Unknown display. EXPECT_EQ(mHwc.getActiveMode(PhysicalDisplayId::fromPort(0)), ftl::Unexpected(BAD_INDEX)); @@ -449,7 +472,7 @@ TEST_F(HWComposerSetCallbackTest, loadsLayerMetadataSupport) { {kMetadata1Name, kMetadata1Mandatory}, {kMetadata2Name, kMetadata2Mandatory}, }), - Return(hardware::graphics::composer::V2_4::Error::NONE))); + Return(V2_4::Error::NONE))); EXPECT_CALL(*mHal, getOverlaySupport(_)).WillOnce(Return(HalError::NONE)); EXPECT_CALL(*mHal, getHdrConversionCapabilities(_)).WillOnce(Return(HalError::NONE)); @@ -467,8 +490,7 @@ TEST_F(HWComposerSetCallbackTest, loadsLayerMetadataSupport) { TEST_F(HWComposerSetCallbackTest, handlesUnsupportedCallToGetLayerGenericMetadataKeys) { EXPECT_CALL(*mHal, getCapabilities()).WillOnce(Return(std::vector<aidl::Capability>{})); - EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_)) - .WillOnce(Return(hardware::graphics::composer::V2_4::Error::UNSUPPORTED)); + EXPECT_CALL(*mHal, getLayerGenericMetadataKeys(_)).WillOnce(Return(V2_4::Error::UNSUPPORTED)); EXPECT_CALL(*mHal, getOverlaySupport(_)).WillOnce(Return(HalError::UNSUPPORTED)); EXPECT_CALL(*mHal, getHdrConversionCapabilities(_)).WillOnce(Return(HalError::UNSUPPORTED)); EXPECT_CALL(*mHal, registerCallback(_)); @@ -528,7 +550,7 @@ TEST_F(HWComposerLayerGenericMetadataTest, forwardsSupportedMetadata) { setLayerGenericMetadata(kDisplayId, kLayerId, kLayerGenericMetadata1Name, kLayerGenericMetadata1Mandatory, kLayerGenericMetadata1Value)) - .WillOnce(Return(hardware::graphics::composer::V2_4::Error::NONE)); + .WillOnce(Return(V2_4::Error::NONE)); auto result = mLayer.setLayerGenericMetadata(kLayerGenericMetadata1Name, kLayerGenericMetadata1Mandatory, kLayerGenericMetadata1Value); @@ -538,7 +560,7 @@ TEST_F(HWComposerLayerGenericMetadataTest, forwardsSupportedMetadata) { setLayerGenericMetadata(kDisplayId, kLayerId, kLayerGenericMetadata2Name, kLayerGenericMetadata2Mandatory, kLayerGenericMetadata2Value)) - .WillOnce(Return(hardware::graphics::composer::V2_4::Error::UNSUPPORTED)); + .WillOnce(Return(V2_4::Error::UNSUPPORTED)); result = mLayer.setLayerGenericMetadata(kLayerGenericMetadata2Name, kLayerGenericMetadata2Mandatory, kLayerGenericMetadata2Value); diff --git a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp index bc06a31173..9b8ff42782 100644 --- a/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp +++ b/services/surfaceflinger/tests/unittests/LayerHistoryTest.cpp @@ -646,7 +646,7 @@ TEST_F(LayerHistoryTest, oneLayerExplicitVoteWithCategory) { // Second LayerRequirement is the frame rate specification EXPECT_EQ(LayerHistory::LayerVoteType::ExplicitDefault, summarizeLayerHistory(time)[1].vote); EXPECT_EQ(73.4_Hz, summarizeLayerHistory(time)[1].desiredRefreshRate); - EXPECT_EQ(FrameRateCategory::High, summarizeLayerHistory(time)[1].frameRateCategory); + EXPECT_EQ(FrameRateCategory::Default, summarizeLayerHistory(time)[1].frameRateCategory); // layer became inactive, but the vote stays setDefaultLayerVote(layer.get(), LayerHistory::LayerVoteType::Heuristic); diff --git a/services/surfaceflinger/tests/unittests/LayerInfoTest.cpp b/services/surfaceflinger/tests/unittests/LayerInfoTest.cpp index 9fe9ee8515..c1fa6ac6f2 100644 --- a/services/surfaceflinger/tests/unittests/LayerInfoTest.cpp +++ b/services/surfaceflinger/tests/unittests/LayerInfoTest.cpp @@ -213,7 +213,8 @@ TEST_F(LayerInfoTest, getRefreshRateVote_explicitVote) { TEST_F(LayerInfoTest, getRefreshRateVote_explicitVoteWithCategory) { LayerInfo::LayerVote vote = {.type = LayerHistory::LayerVoteType::ExplicitDefault, .fps = 20_Hz, - .category = FrameRateCategory::High}; + .category = FrameRateCategory::High, + .categorySmoothSwitchOnly = true}; layerInfo.setLayerVote(vote); auto actualVotes = @@ -221,10 +222,12 @@ TEST_F(LayerInfoTest, getRefreshRateVote_explicitVoteWithCategory) { ASSERT_EQ(actualVotes.size(), 2u); ASSERT_EQ(actualVotes[0].type, LayerHistory::LayerVoteType::ExplicitCategory); ASSERT_EQ(actualVotes[0].category, vote.category); + ASSERT_TRUE(actualVotes[0].categorySmoothSwitchOnly); ASSERT_EQ(actualVotes[1].type, vote.type); ASSERT_EQ(actualVotes[1].fps, vote.fps); ASSERT_EQ(actualVotes[1].seamlessness, vote.seamlessness); - ASSERT_EQ(actualVotes[1].category, vote.category); + ASSERT_EQ(actualVotes[1].category, FrameRateCategory::Default); + ASSERT_TRUE(actualVotes[1].categorySmoothSwitchOnly); } TEST_F(LayerInfoTest, getRefreshRateVote_explicitCategory) { diff --git a/services/surfaceflinger/tests/unittests/PowerAdvisorTest.cpp b/services/surfaceflinger/tests/unittests/PowerAdvisorTest.cpp index 415b0d2edf..9c66a97573 100644 --- a/services/surfaceflinger/tests/unittests/PowerAdvisorTest.cpp +++ b/services/surfaceflinger/tests/unittests/PowerAdvisorTest.cpp @@ -74,14 +74,12 @@ void PowerAdvisorTest::SetUp() { void PowerAdvisorTest::startPowerHintSession(bool returnValidSession) { mMockPowerHintSession = ndk::SharedRefBase::make<NiceMock<MockIPowerHintSession>>(); if (returnValidSession) { - ON_CALL(*mMockPowerHalController, createHintSessionWithConfig) - .WillByDefault(DoAll(SetArgPointee<5>(aidl::android::hardware::power::SessionConfig{ - .id = 12}), - Return(HalResult<std::shared_ptr<IPowerHintSession>>:: - fromStatus(binder::Status::ok(), - mMockPowerHintSession)))); + ON_CALL(*mMockPowerHalController, createHintSession) + .WillByDefault( + Return(HalResult<std::shared_ptr<IPowerHintSession>>:: + fromStatus(binder::Status::ok(), mMockPowerHintSession))); } else { - ON_CALL(*mMockPowerHalController, createHintSessionWithConfig) + ON_CALL(*mMockPowerHalController, createHintSession) .WillByDefault(Return(HalResult<std::shared_ptr<IPowerHintSession>>:: fromStatus(binder::Status::ok(), nullptr))); } @@ -285,7 +283,7 @@ TEST_F(PowerAdvisorTest, hintSessionValidWhenNullFromPowerHAL) { } TEST_F(PowerAdvisorTest, hintSessionOnlyCreatedOnce) { - EXPECT_CALL(*mMockPowerHalController, createHintSessionWithConfig(_, _, _, _, _, _)).Times(1); + EXPECT_CALL(*mMockPowerHalController, createHintSession(_, _, _, _)).Times(1); mPowerAdvisor->onBootFinished(); startPowerHintSession(); mPowerAdvisor->startPowerHintSession({1, 2, 3}); @@ -337,7 +335,7 @@ TEST_F(PowerAdvisorTest, hintSessionTestNotifyReportRace) { return ndk::ScopedAStatus::fromExceptionCode(-127); }); - ON_CALL(*mMockPowerHalController, createHintSessionWithConfig) + ON_CALL(*mMockPowerHalController, createHintSession) .WillByDefault(Return( HalResult<std::shared_ptr<IPowerHintSession>>:: fromStatus(ndk::ScopedAStatus::fromExceptionCode(-127), nullptr))); diff --git a/services/surfaceflinger/tests/unittests/RefreshRateSelectorTest.cpp b/services/surfaceflinger/tests/unittests/RefreshRateSelectorTest.cpp index c03cbd7142..39a8aacaf8 100644 --- a/services/surfaceflinger/tests/unittests/RefreshRateSelectorTest.cpp +++ b/services/surfaceflinger/tests/unittests/RefreshRateSelectorTest.cpp @@ -103,7 +103,7 @@ struct TestableRefreshRateSelector : RefreshRateSelector { auto& mutableGetRankedRefreshRatesCache() { return mGetRankedFrameRatesCache; } auto getRankedFrameRates(const std::vector<LayerRequirement>& layers, - GlobalSignals signals) const { + GlobalSignals signals = {}) const { const auto result = RefreshRateSelector::getRankedFrameRates(layers, signals); EXPECT_TRUE(std::is_sorted(result.ranking.begin(), result.ranking.end(), @@ -1619,10 +1619,11 @@ TEST_P(RefreshRateSelectorTest, getBestFrameRateMode_withFrameRateCategory_HighH lr1.name = "ExplicitCategory HighHint"; lr2.vote = LayerVoteType::NoVote; lr2.name = "NoVote"; - auto actualFrameRateMode = selector.getBestFrameRateMode(layers); + auto actualRankedFrameRates = selector.getRankedFrameRates(layers); // Gets touch boost - EXPECT_EQ(120_Hz, actualFrameRateMode.fps); - EXPECT_EQ(kModeId120, actualFrameRateMode.modePtr->getId()); + EXPECT_EQ(120_Hz, actualRankedFrameRates.ranking.front().frameRateMode.fps); + EXPECT_EQ(kModeId120, actualRankedFrameRates.ranking.front().frameRateMode.modePtr->getId()); + EXPECT_TRUE(actualRankedFrameRates.consideredSignals.touch); // No touch boost, for example a game that uses setFrameRate(30, default compatibility). lr1.vote = LayerVoteType::ExplicitCategory; @@ -1631,9 +1632,10 @@ TEST_P(RefreshRateSelectorTest, getBestFrameRateMode_withFrameRateCategory_HighH lr2.vote = LayerVoteType::ExplicitDefault; lr2.desiredRefreshRate = 30_Hz; lr2.name = "30Hz ExplicitDefault"; - actualFrameRateMode = selector.getBestFrameRateMode(layers); - EXPECT_EQ(30_Hz, actualFrameRateMode.fps); - EXPECT_EQ(kModeId30, actualFrameRateMode.modePtr->getId()); + actualRankedFrameRates = selector.getRankedFrameRates(layers); + EXPECT_EQ(30_Hz, actualRankedFrameRates.ranking.front().frameRateMode.fps); + EXPECT_EQ(kModeId30, actualRankedFrameRates.ranking.front().frameRateMode.modePtr->getId()); + EXPECT_FALSE(actualRankedFrameRates.consideredSignals.touch); lr1.vote = LayerVoteType::ExplicitCategory; lr1.frameRateCategory = FrameRateCategory::HighHint; @@ -1641,10 +1643,11 @@ TEST_P(RefreshRateSelectorTest, getBestFrameRateMode_withFrameRateCategory_HighH lr2.vote = LayerVoteType::ExplicitCategory; lr2.frameRateCategory = FrameRateCategory::HighHint; lr2.name = "ExplicitCategory HighHint#2"; - actualFrameRateMode = selector.getBestFrameRateMode(layers); + actualRankedFrameRates = selector.getRankedFrameRates(layers); // Gets touch boost - EXPECT_EQ(120_Hz, actualFrameRateMode.fps); - EXPECT_EQ(kModeId120, actualFrameRateMode.modePtr->getId()); + EXPECT_EQ(120_Hz, actualRankedFrameRates.ranking.front().frameRateMode.fps); + EXPECT_EQ(kModeId120, actualRankedFrameRates.ranking.front().frameRateMode.modePtr->getId()); + EXPECT_TRUE(actualRankedFrameRates.consideredSignals.touch); lr1.vote = LayerVoteType::ExplicitCategory; lr1.frameRateCategory = FrameRateCategory::HighHint; @@ -1652,10 +1655,11 @@ TEST_P(RefreshRateSelectorTest, getBestFrameRateMode_withFrameRateCategory_HighH lr2.vote = LayerVoteType::ExplicitCategory; lr2.frameRateCategory = FrameRateCategory::Low; lr2.name = "ExplicitCategory Low"; - actualFrameRateMode = selector.getBestFrameRateMode(layers); + actualRankedFrameRates = selector.getRankedFrameRates(layers); // Gets touch boost - EXPECT_EQ(120_Hz, actualFrameRateMode.fps); - EXPECT_EQ(kModeId120, actualFrameRateMode.modePtr->getId()); + EXPECT_EQ(120_Hz, actualRankedFrameRates.ranking.front().frameRateMode.fps); + EXPECT_EQ(kModeId120, actualRankedFrameRates.ranking.front().frameRateMode.modePtr->getId()); + EXPECT_TRUE(actualRankedFrameRates.consideredSignals.touch); lr1.vote = LayerVoteType::ExplicitCategory; lr1.frameRateCategory = FrameRateCategory::HighHint; @@ -1663,10 +1667,11 @@ TEST_P(RefreshRateSelectorTest, getBestFrameRateMode_withFrameRateCategory_HighH lr2.vote = LayerVoteType::ExplicitExactOrMultiple; lr2.desiredRefreshRate = 30_Hz; lr2.name = "30Hz ExplicitExactOrMultiple"; - actualFrameRateMode = selector.getBestFrameRateMode(layers); + actualRankedFrameRates = selector.getRankedFrameRates(layers); // Gets touch boost - EXPECT_EQ(120_Hz, actualFrameRateMode.fps); - EXPECT_EQ(kModeId120, actualFrameRateMode.modePtr->getId()); + EXPECT_EQ(120_Hz, actualRankedFrameRates.ranking.front().frameRateMode.fps); + EXPECT_EQ(kModeId120, actualRankedFrameRates.ranking.front().frameRateMode.modePtr->getId()); + EXPECT_TRUE(actualRankedFrameRates.consideredSignals.touch); lr1.vote = LayerVoteType::ExplicitCategory; lr1.frameRateCategory = FrameRateCategory::HighHint; @@ -1674,14 +1679,17 @@ TEST_P(RefreshRateSelectorTest, getBestFrameRateMode_withFrameRateCategory_HighH lr2.vote = LayerVoteType::ExplicitExact; lr2.desiredRefreshRate = 30_Hz; lr2.name = "30Hz ExplicitExact"; - actualFrameRateMode = selector.getBestFrameRateMode(layers); + actualRankedFrameRates = selector.getRankedFrameRates(layers); if (selector.supportsAppFrameRateOverrideByContent()) { // Gets touch boost - EXPECT_EQ(120_Hz, actualFrameRateMode.fps); - EXPECT_EQ(kModeId120, actualFrameRateMode.modePtr->getId()); + EXPECT_EQ(120_Hz, actualRankedFrameRates.ranking.front().frameRateMode.fps); + EXPECT_EQ(kModeId120, + actualRankedFrameRates.ranking.front().frameRateMode.modePtr->getId()); + EXPECT_TRUE(actualRankedFrameRates.consideredSignals.touch); } else { - EXPECT_EQ(30_Hz, actualFrameRateMode.fps); - EXPECT_EQ(kModeId30, actualFrameRateMode.modePtr->getId()); + EXPECT_EQ(30_Hz, actualRankedFrameRates.ranking.front().frameRateMode.fps); + EXPECT_EQ(kModeId30, actualRankedFrameRates.ranking.front().frameRateMode.modePtr->getId()); + EXPECT_FALSE(actualRankedFrameRates.consideredSignals.touch); } } diff --git a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp index 10c584871e..b0595257a9 100644 --- a/services/surfaceflinger/tests/unittests/SchedulerTest.cpp +++ b/services/surfaceflinger/tests/unittests/SchedulerTest.cpp @@ -339,6 +339,61 @@ TEST_F(SchedulerTest, chooseDisplayModesSingleDisplay) { EXPECT_EQ(choice->get(), DisplayModeChoice({120_Hz, kDisplay1Mode120}, globalSignals)); } +TEST_F(SchedulerTest, chooseDisplayModesSingleDisplayHighHintTouchSignal) { + mScheduler->registerDisplay(kDisplayId1, + std::make_shared<RefreshRateSelector>(kDisplay1Modes, + kDisplay1Mode60->getId())); + + using DisplayModeChoice = TestableScheduler::DisplayModeChoice; + + std::vector<RefreshRateSelector::LayerRequirement> layers = + std::vector<RefreshRateSelector::LayerRequirement>({{.weight = 1.f}, {.weight = 1.f}}); + auto& lr1 = layers[0]; + auto& lr2 = layers[1]; + + // Scenario that is similar to game. Expects no touch boost. + lr1.vote = RefreshRateSelector::LayerVoteType::ExplicitCategory; + lr1.frameRateCategory = FrameRateCategory::HighHint; + lr1.name = "ExplicitCategory HighHint"; + lr2.vote = RefreshRateSelector::LayerVoteType::ExplicitDefault; + lr2.desiredRefreshRate = 30_Hz; + lr2.name = "30Hz ExplicitDefault"; + mScheduler->setContentRequirements(layers); + auto modeChoices = mScheduler->chooseDisplayModes(); + ASSERT_EQ(1u, modeChoices.size()); + auto choice = modeChoices.get(kDisplayId1); + ASSERT_TRUE(choice); + EXPECT_EQ(choice->get(), DisplayModeChoice({60_Hz, kDisplay1Mode60}, {.touch = false})); + + // Scenario that is similar to video playback and interaction. Expects touch boost. + lr1.vote = RefreshRateSelector::LayerVoteType::ExplicitCategory; + lr1.frameRateCategory = FrameRateCategory::HighHint; + lr1.name = "ExplicitCategory HighHint"; + lr2.vote = RefreshRateSelector::LayerVoteType::ExplicitExactOrMultiple; + lr2.desiredRefreshRate = 30_Hz; + lr2.name = "30Hz ExplicitExactOrMultiple"; + mScheduler->setContentRequirements(layers); + modeChoices = mScheduler->chooseDisplayModes(); + ASSERT_EQ(1u, modeChoices.size()); + choice = modeChoices.get(kDisplayId1); + ASSERT_TRUE(choice); + EXPECT_EQ(choice->get(), DisplayModeChoice({120_Hz, kDisplay1Mode120}, {.touch = true})); + + // Scenario with explicit category and HighHint. Expects touch boost. + lr1.vote = RefreshRateSelector::LayerVoteType::ExplicitCategory; + lr1.frameRateCategory = FrameRateCategory::HighHint; + lr1.name = "ExplicitCategory HighHint"; + lr2.vote = RefreshRateSelector::LayerVoteType::ExplicitCategory; + lr2.frameRateCategory = FrameRateCategory::Low; + lr2.name = "ExplicitCategory Low"; + mScheduler->setContentRequirements(layers); + modeChoices = mScheduler->chooseDisplayModes(); + ASSERT_EQ(1u, modeChoices.size()); + choice = modeChoices.get(kDisplayId1); + ASSERT_TRUE(choice); + EXPECT_EQ(choice->get(), DisplayModeChoice({120_Hz, kDisplay1Mode120}, {.touch = true})); +} + TEST_F(SchedulerTest, chooseDisplayModesMultipleDisplays) { mScheduler->registerDisplay(kDisplayId1, std::make_shared<RefreshRateSelector>(kDisplay1Modes, diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp index 9efb503dde..15a6db626a 100644 --- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp +++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp @@ -21,9 +21,13 @@ #include "mock/DisplayHardware/MockDisplayMode.h" #include "mock/MockDisplayModeSpecs.h" +#include <com_android_graphics_surfaceflinger_flags.h> +#include <common/test/FlagUtils.h> #include <ftl/fake_guard.h> #include <scheduler/Fps.h> +using namespace com::android::graphics::surfaceflinger; + #define EXPECT_SET_ACTIVE_CONFIG(displayId, modeId) \ EXPECT_CALL(*mComposer, \ setActiveConfigWithConstraints(displayId, \ @@ -349,6 +353,13 @@ MATCHER_P(ModeSettledTo, modeId, "") { } TEST_F(DisplayModeSwitchingTest, innerXorOuterDisplay) { + SET_FLAG_FOR_TEST(flags::connected_display, true); + + // For the inner display, this is handled by setupHwcHotplugCallExpectations. + EXPECT_CALL(*mComposer, getDisplayConnectionType(kOuterDisplayHwcId, _)) + .WillOnce(DoAll(SetArgPointee<1>(IComposerClient::DisplayConnectionType::INTERNAL), + Return(hal::V2_4::Error::NONE))); + const auto [innerDisplay, outerDisplay] = injectOuterDisplay(); EXPECT_TRUE(innerDisplay->isPoweredOn()); @@ -412,6 +423,12 @@ TEST_F(DisplayModeSwitchingTest, innerXorOuterDisplay) { } TEST_F(DisplayModeSwitchingTest, innerAndOuterDisplay) { + SET_FLAG_FOR_TEST(flags::connected_display, true); + + // For the inner display, this is handled by setupHwcHotplugCallExpectations. + EXPECT_CALL(*mComposer, getDisplayConnectionType(kOuterDisplayHwcId, _)) + .WillOnce(DoAll(SetArgPointee<1>(IComposerClient::DisplayConnectionType::INTERNAL), + Return(hal::V2_4::Error::NONE))); const auto [innerDisplay, outerDisplay] = injectOuterDisplay(); EXPECT_TRUE(innerDisplay->isPoweredOn()); @@ -485,6 +502,13 @@ TEST_F(DisplayModeSwitchingTest, powerOffDuringModeSet) { } TEST_F(DisplayModeSwitchingTest, powerOffDuringConcurrentModeSet) { + SET_FLAG_FOR_TEST(flags::connected_display, true); + + // For the inner display, this is handled by setupHwcHotplugCallExpectations. + EXPECT_CALL(*mComposer, getDisplayConnectionType(kOuterDisplayHwcId, _)) + .WillOnce(DoAll(SetArgPointee<1>(IComposerClient::DisplayConnectionType::INTERNAL), + Return(hal::V2_4::Error::NONE))); + const auto [innerDisplay, outerDisplay] = injectOuterDisplay(); EXPECT_TRUE(innerDisplay->isPoweredOn()); diff --git a/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp b/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp index 4bf58de05c..eb4e84ef4f 100644 --- a/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp +++ b/services/surfaceflinger/tests/unittests/VSyncDispatchTimerQueueTest.cpp @@ -734,7 +734,7 @@ TEST_F(VSyncDispatchTimerQueueTest, canMoveCallbackBackwardsInTime) { // b/1450138150 TEST_F(VSyncDispatchTimerQueueTest, doesNotMoveCallbackBackwardsAndSkipAScheduledTargetVSync) { - SET_FLAG_FOR_TEST(flags::dont_skip_on_early, false); + SET_FLAG_FOR_TEST(flags::dont_skip_on_early_ro, false); EXPECT_CALL(mMockClock, alarmAt(_, 500)); CountingCallback cb(mDispatch); @@ -754,7 +754,7 @@ TEST_F(VSyncDispatchTimerQueueTest, doesNotMoveCallbackBackwardsAndSkipASchedule // b/1450138150 TEST_F(VSyncDispatchTimerQueueTest, movesCallbackBackwardsAndSkipAScheduledTargetVSync) { - SET_FLAG_FOR_TEST(flags::dont_skip_on_early, true); + SET_FLAG_FOR_TEST(flags::dont_skip_on_early_ro, true); Sequence seq; EXPECT_CALL(mMockClock, alarmAt(_, 500)).InSequence(seq); @@ -821,7 +821,7 @@ TEST_F(VSyncDispatchTimerQueueTest, canScheduleLargeNegativeOffset) { } TEST_F(VSyncDispatchTimerQueueTest, scheduleUpdatesDoesNotAffectSchedulingState) { - SET_FLAG_FOR_TEST(flags::dont_skip_on_early, false); + SET_FLAG_FOR_TEST(flags::dont_skip_on_early_ro, false); EXPECT_CALL(mMockClock, alarmAt(_, 600)); @@ -839,7 +839,7 @@ TEST_F(VSyncDispatchTimerQueueTest, scheduleUpdatesDoesNotAffectSchedulingState) } TEST_F(VSyncDispatchTimerQueueTest, scheduleUpdatesDoesAffectSchedulingState) { - SET_FLAG_FOR_TEST(flags::dont_skip_on_early, true); + SET_FLAG_FOR_TEST(flags::dont_skip_on_early_ro, true); Sequence seq; EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq); @@ -917,6 +917,8 @@ TEST_F(VSyncDispatchTimerQueueTest, skipsSchedulingIfTimerReschedulingIsImminent // If the same callback tries to reschedule itself after it's too late, timer opts to apply the // update later, as opposed to blocking the calling thread. TEST_F(VSyncDispatchTimerQueueTest, skipsSchedulingIfTimerReschedulingIsImminentSameCallback) { + SET_FLAG_FOR_TEST(flags::dont_skip_on_early_ro, false); + Sequence seq; EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq); EXPECT_CALL(mMockClock, alarmAt(_, 1630)).InSequence(seq); @@ -939,6 +941,37 @@ TEST_F(VSyncDispatchTimerQueueTest, skipsSchedulingIfTimerReschedulingIsImminent } // b/154303580. +// If the same callback tries to reschedule itself after it's too late, timer opts to apply the +// update later, as opposed to blocking the calling thread. +TEST_F(VSyncDispatchTimerQueueTest, doesntSkipSchedulingIfTimerReschedulingIsImminentSameCallback) { + SET_FLAG_FOR_TEST(flags::dont_skip_on_early_ro, true); + + Sequence seq; + EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq); + EXPECT_CALL(mMockClock, alarmAt(_, 1630)).InSequence(seq); + CountingCallback cb(mDispatch); + + auto result = + mDispatch->schedule(cb, {.workDuration = 400, .readyDuration = 0, .lastVsync = 1000}); + EXPECT_TRUE(result.has_value()); + EXPECT_EQ(600, *result); + + mMockClock.setLag(100); + mMockClock.advanceBy(620); + + result = mDispatch->schedule(cb, {.workDuration = 370, .readyDuration = 0, .lastVsync = 2000}); + EXPECT_TRUE(result.has_value()); + EXPECT_EQ(600, *result); + mMockClock.advanceBy(80); + + ASSERT_EQ(1, cb.mCalls.size()); + EXPECT_EQ(1000, cb.mCalls[0]); + + ASSERT_EQ(1, cb.mWakeupTime.size()); + EXPECT_EQ(600, cb.mWakeupTime[0]); +} + +// b/154303580. TEST_F(VSyncDispatchTimerQueueTest, skipsRearmingWhenNotNextScheduled) { Sequence seq; EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq); @@ -1051,7 +1084,7 @@ TEST_F(VSyncDispatchTimerQueueTest, basicAlarmSettingFutureWithReadyDuration) { } TEST_F(VSyncDispatchTimerQueueTest, updatesVsyncTimeForCloseWakeupTime) { - SET_FLAG_FOR_TEST(flags::dont_skip_on_early, false); + SET_FLAG_FOR_TEST(flags::dont_skip_on_early_ro, false); Sequence seq; EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq); @@ -1074,7 +1107,7 @@ TEST_F(VSyncDispatchTimerQueueTest, updatesVsyncTimeForCloseWakeupTime) { } TEST_F(VSyncDispatchTimerQueueTest, doesNotUpdatesVsyncTimeForCloseWakeupTime) { - SET_FLAG_FOR_TEST(flags::dont_skip_on_early, true); + SET_FLAG_FOR_TEST(flags::dont_skip_on_early_ro, true); Sequence seq; EXPECT_CALL(mMockClock, alarmAt(_, 600)).InSequence(seq); @@ -1098,7 +1131,7 @@ TEST_F(VSyncDispatchTimerQueueTest, doesNotUpdatesVsyncTimeForCloseWakeupTime) { } TEST_F(VSyncDispatchTimerQueueTest, skipAVsyc) { - SET_FLAG_FOR_TEST(flags::dont_skip_on_early, false); + SET_FLAG_FOR_TEST(flags::dont_skip_on_early_ro, false); EXPECT_CALL(mMockClock, alarmAt(_, 500)); CountingCallback cb(mDispatch); @@ -1117,7 +1150,7 @@ TEST_F(VSyncDispatchTimerQueueTest, skipAVsyc) { } TEST_F(VSyncDispatchTimerQueueTest, dontskipAVsyc) { - SET_FLAG_FOR_TEST(flags::dont_skip_on_early, true); + SET_FLAG_FOR_TEST(flags::dont_skip_on_early_ro, true); Sequence seq; EXPECT_CALL(mMockClock, alarmAt(_, 500)).InSequence(seq); @@ -1344,14 +1377,17 @@ TEST_F(VSyncDispatchTimerQueueEntryTest, reportsScheduledIfStillTime) { .has_value()); } -TEST_F(VSyncDispatchTimerQueueEntryTest, storesPendingUpdatesUntilUpdate) { +TEST_F(VSyncDispatchTimerQueueEntryTest, storesPendingUpdatesUntilUpdateAndDontSkip) { static constexpr auto effectualOffset = 200; VSyncDispatchTimerQueueEntry entry( "test", [](auto, auto, auto) {}, mVsyncMoveThreshold); EXPECT_FALSE(entry.hasPendingWorkloadUpdate()); - entry.addPendingWorkloadUpdate({.workDuration = 100, .readyDuration = 0, .lastVsync = 400}); - entry.addPendingWorkloadUpdate( - {.workDuration = effectualOffset, .readyDuration = 0, .lastVsync = 400}); + entry.addPendingWorkloadUpdate(*mStubTracker.get(), 0, + {.workDuration = 100, .readyDuration = 0, .lastVsync = 400}); + entry.addPendingWorkloadUpdate(*mStubTracker.get(), 0, + {.workDuration = effectualOffset, + .readyDuration = 0, + .lastVsync = 400}); EXPECT_TRUE(entry.hasPendingWorkloadUpdate()); entry.update(*mStubTracker.get(), 0); EXPECT_FALSE(entry.hasPendingWorkloadUpdate()); diff --git a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h index 7413235c19..602bdfc152 100644 --- a/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h +++ b/services/surfaceflinger/tests/unittests/mock/DisplayHardware/MockHWC2.h @@ -53,7 +53,8 @@ public: MOCK_METHOD(hal::Error, getRequests, (hal::DisplayRequest *, (std::unordered_map<Layer *, hal::LayerRequest> *)), (override)); - MOCK_METHOD(hal::Error, getConnectionType, (ui::DisplayConnectionType *), (const, override)); + MOCK_METHOD((ftl::Expected<ui::DisplayConnectionType, hal::Error>), getConnectionType, (), + (const, override)); MOCK_METHOD(hal::Error, supportsDoze, (bool *), (const, override)); MOCK_METHOD(hal::Error, getHdrCapabilities, (android::HdrCapabilities *), (const, override)); MOCK_METHOD(hal::Error, getDisplayedContentSamplingAttributes, diff --git a/services/vibratorservice/benchmarks/Android.bp b/services/vibratorservice/benchmarks/Android.bp index a468146bc0..5437995899 100644 --- a/services/vibratorservice/benchmarks/Android.bp +++ b/services/vibratorservice/benchmarks/Android.bp @@ -13,6 +13,7 @@ // limitations under the License. package { + default_team: "trendy_team_haptics_framework", // See: http://go/android-license-faq // A large-scale-change added 'default_applicable_licenses' to import // all of the 'license_kinds' from "frameworks_native_license" diff --git a/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp b/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp index 971a0b960e..e11a809bc1 100644 --- a/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp +++ b/services/vibratorservice/benchmarks/VibratorHalControllerBenchmarks.cpp @@ -152,6 +152,7 @@ BENCHMARK_WRAPPER(VibratorBench, off, { BENCHMARK_WRAPPER(VibratorBench, setAmplitude, { if (!hasCapabilities(vibrator::Capabilities::AMPLITUDE_CONTROL, state)) { + state.SkipWithMessage("missing capability"); return; } @@ -180,6 +181,7 @@ BENCHMARK_WRAPPER(VibratorBench, setAmplitude, { BENCHMARK_WRAPPER(VibratorBench, setAmplitudeCached, { if (!hasCapabilities(vibrator::Capabilities::AMPLITUDE_CONTROL, state)) { + state.SkipWithMessage("missing capability"); return; } @@ -200,6 +202,7 @@ BENCHMARK_WRAPPER(VibratorBench, setAmplitudeCached, { BENCHMARK_WRAPPER(VibratorBench, setExternalControl, { if (!hasCapabilities(vibrator::Capabilities::EXTERNAL_CONTROL, state)) { + state.SkipWithMessage("missing capability"); return; } @@ -221,6 +224,7 @@ BENCHMARK_WRAPPER(VibratorBench, setExternalControl, { BENCHMARK_WRAPPER(VibratorBench, setExternalControlCached, { if (!hasCapabilities(vibrator::Capabilities::EXTERNAL_CONTROL, state)) { + state.SkipWithMessage("missing capability"); return; } @@ -239,6 +243,7 @@ BENCHMARK_WRAPPER(VibratorBench, setExternalControlCached, { BENCHMARK_WRAPPER(VibratorBench, setExternalAmplitudeCached, { if (!hasCapabilities(vibrator::Capabilities::EXTERNAL_AMPLITUDE_CONTROL, state)) { + state.SkipWithMessage("missing capability"); return; } @@ -331,9 +336,11 @@ protected: BENCHMARK_WRAPPER(VibratorEffectsBench, alwaysOnEnable, { if (!hasCapabilities(vibrator::Capabilities::ALWAYS_ON_CONTROL, state)) { + state.SkipWithMessage("missing capability"); return; } if (!hasArgs(state)) { + state.SkipWithMessage("missing args"); return; } @@ -357,9 +364,11 @@ BENCHMARK_WRAPPER(VibratorEffectsBench, alwaysOnEnable, { BENCHMARK_WRAPPER(VibratorEffectsBench, alwaysOnDisable, { if (!hasCapabilities(vibrator::Capabilities::ALWAYS_ON_CONTROL, state)) { + state.SkipWithMessage("missing capability"); return; } if (!hasArgs(state)) { + state.SkipWithMessage("missing args"); return; } @@ -384,6 +393,7 @@ BENCHMARK_WRAPPER(VibratorEffectsBench, alwaysOnDisable, { BENCHMARK_WRAPPER(VibratorEffectsBench, performEffect, { if (!hasArgs(state)) { + state.SkipWithMessage("missing args"); return; } @@ -441,9 +451,11 @@ protected: BENCHMARK_WRAPPER(VibratorPrimitivesBench, performComposedEffect, { if (!hasCapabilities(vibrator::Capabilities::COMPOSE_EFFECTS, state)) { + state.SkipWithMessage("missing capability"); return; } if (!hasArgs(state)) { + state.SkipWithMessage("missing args"); return; } @@ -468,4 +480,4 @@ BENCHMARK_WRAPPER(VibratorPrimitivesBench, performComposedEffect, { } }); -BENCHMARK_MAIN();
\ No newline at end of file +BENCHMARK_MAIN(); diff --git a/vulkan/libvulkan/swapchain.cpp b/vulkan/libvulkan/swapchain.cpp index 892cd19f2f..13141933ac 100644 --- a/vulkan/libvulkan/swapchain.cpp +++ b/vulkan/libvulkan/swapchain.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include "vulkan/vulkan_core.h" #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include <aidl/android/hardware/graphics/common/Dataspace.h> @@ -158,6 +159,25 @@ int InvertTransformToNative(VkSurfaceTransformFlagBitsKHR transform) { } } +const static VkColorSpaceKHR colorSpaceSupportedByVkEXTSwapchainColorspace[] = { + VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT, + VK_COLOR_SPACE_DISPLAY_P3_LINEAR_EXT, + VK_COLOR_SPACE_DCI_P3_NONLINEAR_EXT, + VK_COLOR_SPACE_BT709_LINEAR_EXT, + VK_COLOR_SPACE_BT709_NONLINEAR_EXT, + VK_COLOR_SPACE_BT2020_LINEAR_EXT, + VK_COLOR_SPACE_HDR10_ST2084_EXT, + VK_COLOR_SPACE_HDR10_HLG_EXT, + VK_COLOR_SPACE_ADOBERGB_LINEAR_EXT, + VK_COLOR_SPACE_ADOBERGB_NONLINEAR_EXT, + VK_COLOR_SPACE_PASS_THROUGH_EXT, + VK_COLOR_SPACE_DCI_P3_LINEAR_EXT}; + +const static VkColorSpaceKHR + colorSpaceSupportedByVkEXTSwapchainColorspaceOnFP16SurfaceOnly[] = { + VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT, + VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT}; + class TimingInfo { public: TimingInfo(const VkPresentTimeGOOGLE* qp, uint64_t nativeFrameId) @@ -745,16 +765,22 @@ VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev, }; if (colorspace_ext) { - all_formats.emplace_back(VkSurfaceFormatKHR{ - VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_PASS_THROUGH_EXT}); - all_formats.emplace_back(VkSurfaceFormatKHR{ - VK_FORMAT_R8G8B8A8_SRGB, VK_COLOR_SPACE_PASS_THROUGH_EXT}); - all_formats.emplace_back(VkSurfaceFormatKHR{ - VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_BT709_LINEAR_EXT}); - all_formats.emplace_back(VkSurfaceFormatKHR{ - VK_FORMAT_R8G8B8A8_UNORM, VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT}); - all_formats.emplace_back(VkSurfaceFormatKHR{ - VK_FORMAT_R8G8B8A8_SRGB, VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT}); + for (VkColorSpaceKHR colorSpace : + colorSpaceSupportedByVkEXTSwapchainColorspace) { + if (GetNativeDataspace(colorSpace, GetNativePixelFormat( + VK_FORMAT_R8G8B8A8_UNORM)) != + DataSpace::UNKNOWN) { + all_formats.emplace_back( + VkSurfaceFormatKHR{VK_FORMAT_R8G8B8A8_UNORM, colorSpace}); + } + + if (GetNativeDataspace(colorSpace, GetNativePixelFormat( + VK_FORMAT_R8G8B8A8_SRGB)) != + DataSpace::UNKNOWN) { + all_formats.emplace_back( + VkSurfaceFormatKHR{VK_FORMAT_R8G8B8A8_SRGB, colorSpace}); + } + } } // NOTE: Any new formats that are added must be coordinated across different @@ -766,9 +792,16 @@ VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev, all_formats.emplace_back(VkSurfaceFormatKHR{ VK_FORMAT_R5G6B5_UNORM_PACK16, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}); if (colorspace_ext) { - all_formats.emplace_back( - VkSurfaceFormatKHR{VK_FORMAT_R5G6B5_UNORM_PACK16, - VK_COLOR_SPACE_PASS_THROUGH_EXT}); + for (VkColorSpaceKHR colorSpace : + colorSpaceSupportedByVkEXTSwapchainColorspace) { + if (GetNativeDataspace( + colorSpace, + GetNativePixelFormat(VK_FORMAT_R5G6B5_UNORM_PACK16)) != + DataSpace::UNKNOWN) { + all_formats.emplace_back(VkSurfaceFormatKHR{ + VK_FORMAT_R5G6B5_UNORM_PACK16, colorSpace}); + } + } } } @@ -777,18 +810,28 @@ VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev, all_formats.emplace_back(VkSurfaceFormatKHR{ VK_FORMAT_R16G16B16A16_SFLOAT, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}); if (colorspace_ext) { - all_formats.emplace_back( - VkSurfaceFormatKHR{VK_FORMAT_R16G16B16A16_SFLOAT, - VK_COLOR_SPACE_PASS_THROUGH_EXT}); - all_formats.emplace_back( - VkSurfaceFormatKHR{VK_FORMAT_R16G16B16A16_SFLOAT, - VK_COLOR_SPACE_EXTENDED_SRGB_LINEAR_EXT}); - all_formats.emplace_back( - VkSurfaceFormatKHR{VK_FORMAT_R16G16B16A16_SFLOAT, - VK_COLOR_SPACE_EXTENDED_SRGB_NONLINEAR_EXT}); - all_formats.emplace_back( - VkSurfaceFormatKHR{VK_FORMAT_R16G16B16A16_SFLOAT, - VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT}); + for (VkColorSpaceKHR colorSpace : + colorSpaceSupportedByVkEXTSwapchainColorspace) { + if (GetNativeDataspace( + colorSpace, + GetNativePixelFormat(VK_FORMAT_R16G16B16A16_SFLOAT)) != + DataSpace::UNKNOWN) { + all_formats.emplace_back(VkSurfaceFormatKHR{ + VK_FORMAT_R16G16B16A16_SFLOAT, colorSpace}); + } + } + + for ( + VkColorSpaceKHR colorSpace : + colorSpaceSupportedByVkEXTSwapchainColorspaceOnFP16SurfaceOnly) { + if (GetNativeDataspace( + colorSpace, + GetNativePixelFormat(VK_FORMAT_R16G16B16A16_SFLOAT)) != + DataSpace::UNKNOWN) { + all_formats.emplace_back(VkSurfaceFormatKHR{ + VK_FORMAT_R16G16B16A16_SFLOAT, colorSpace}); + } + } } } @@ -798,12 +841,16 @@ VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev, VkSurfaceFormatKHR{VK_FORMAT_A2B10G10R10_UNORM_PACK32, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}); if (colorspace_ext) { - all_formats.emplace_back( - VkSurfaceFormatKHR{VK_FORMAT_A2B10G10R10_UNORM_PACK32, - VK_COLOR_SPACE_PASS_THROUGH_EXT}); - all_formats.emplace_back( - VkSurfaceFormatKHR{VK_FORMAT_A2B10G10R10_UNORM_PACK32, - VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT}); + for (VkColorSpaceKHR colorSpace : + colorSpaceSupportedByVkEXTSwapchainColorspace) { + if (GetNativeDataspace( + colorSpace, GetNativePixelFormat( + VK_FORMAT_A2B10G10R10_UNORM_PACK32)) != + DataSpace::UNKNOWN) { + all_formats.emplace_back(VkSurfaceFormatKHR{ + VK_FORMAT_A2B10G10R10_UNORM_PACK32, colorSpace}); + } + } } } @@ -836,12 +883,18 @@ VkResult GetPhysicalDeviceSurfaceFormatsKHR(VkPhysicalDevice pdev, VkSurfaceFormatKHR{VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16, VK_COLOR_SPACE_SRGB_NONLINEAR_KHR}); if (colorspace_ext) { - all_formats.emplace_back( - VkSurfaceFormatKHR{VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16, - VK_COLOR_SPACE_PASS_THROUGH_EXT}); - all_formats.emplace_back( - VkSurfaceFormatKHR{VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16, - VK_COLOR_SPACE_DISPLAY_P3_NONLINEAR_EXT}); + for (VkColorSpaceKHR colorSpace : + colorSpaceSupportedByVkEXTSwapchainColorspace) { + if (GetNativeDataspace( + colorSpace, + GetNativePixelFormat( + VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16)) != + DataSpace::UNKNOWN) { + all_formats.emplace_back(VkSurfaceFormatKHR{ + VK_FORMAT_R10X6G10X6B10X6A10X6_UNORM_4PACK16, + colorSpace}); + } + } } } |