diff options
32 files changed, 358 insertions, 197 deletions
diff --git a/cmds/atrace/atrace.rc b/cmds/atrace/atrace.rc index c7c3a34521..006e5329cd 100644 --- a/cmds/atrace/atrace.rc +++ b/cmds/atrace/atrace.rc @@ -37,12 +37,18 @@ on late-init chmod 0666 /sys/kernel/tracing/events/sched/sched_process_exit/enable chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_waking/enable chmod 0666 /sys/kernel/tracing/events/sched/sched_waking/enable + chmod 0666 /sys/kernel/debug/tracing/events/sched/sched_wakeup_new/enable + chmod 0666 /sys/kernel/tracing/events/sched/sched_wakeup_new/enable chmod 0666 /sys/kernel/debug/tracing/events/cgroup/enable chmod 0666 /sys/kernel/tracing/events/cgroup/enable chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_frequency/enable chmod 0666 /sys/kernel/tracing/events/power/cpu_frequency/enable chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_idle/enable chmod 0666 /sys/kernel/tracing/events/power/cpu_idle/enable + chmod 0666 /sys/kernel/debug/tracing/events/power/clock_enable/enable + chmod 0666 /sys/kernel/tracing/events/power/clock_enable/enable + chmod 0666 /sys/kernel/debug/tracing/events/power/clock_disable/enable + chmod 0666 /sys/kernel/tracing/events/power/clock_disable/enable chmod 0666 /sys/kernel/debug/tracing/events/power/clock_set_rate/enable chmod 0666 /sys/kernel/tracing/events/power/clock_set_rate/enable chmod 0666 /sys/kernel/debug/tracing/events/power/cpu_frequency_limits/enable @@ -79,6 +85,8 @@ on late-init chmod 0666 /sys/kernel/tracing/events/binder/binder_locked/enable chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_unlock/enable chmod 0666 /sys/kernel/tracing/events/binder/binder_unlock/enable + chmod 0666 /sys/kernel/debug/tracing/events/binder/binder_set_priority/enable + chmod 0666 /sys/kernel/tracing/events/binder/binder_set_priority/enable chmod 0666 /sys/kernel/debug/tracing/events/i2c/enable chmod 0666 /sys/kernel/tracing/events/i2c/enable chmod 0666 /sys/kernel/debug/tracing/events/i2c/i2c_read/enable @@ -125,6 +133,8 @@ on late-init chmod 0666 /sys/kernel/tracing/events/lowmemorykiller/lowmemory_kill/enable chmod 0666 /sys/kernel/debug/tracing/events/oom/oom_score_adj_update/enable chmod 0666 /sys/kernel/tracing/events/oom/oom_score_adj_update/enable + chmod 0666 /sys/kernel/debug/tracing/events/oom/mark_victim/enable + chmod 0666 /sys/kernel/tracing/events/oom/mark_victim/enable chmod 0666 /sys/kernel/debug/tracing/events/task/task_rename/enable chmod 0666 /sys/kernel/tracing/events/task/task_rename/enable chmod 0666 /sys/kernel/debug/tracing/events/task/task_newtask/enable @@ -159,6 +169,12 @@ on late-init chmod 0666 /sys/kernel/tracing/events/ipi/ipi_exit/enable chmod 0666 /sys/kernel/debug/tracing/events/ipi/ipi_raise/enable chmod 0666 /sys/kernel/tracing/events/ipi/ipi_raise/enable + chmod 0666 /sys/kernel/debug/tracing/events/clk/clk_enable/enable + chmod 0666 /sys/kernel/tracing/events/clk/clk_disable/enable + chmod 0666 /sys/kernel/debug/tracing/events/clk/clk_disable/enable + chmod 0666 /sys/kernel/tracing/events/clk/clk_enable/enable + chmod 0666 /sys/kernel/debug/tracing/events/clk/clk_set_rate/enable + chmod 0666 /sys/kernel/tracing/events/clk/clk_set_rate/enable # disk chmod 0666 /sys/kernel/tracing/events/f2fs/f2fs_get_data_block/enable diff --git a/cmds/atrace/atrace_userdebug.rc b/cmds/atrace/atrace_userdebug.rc index 6c86c21387..9186514d0a 100644 --- a/cmds/atrace/atrace_userdebug.rc +++ b/cmds/atrace/atrace_userdebug.rc @@ -18,8 +18,3 @@ on post-fs chmod 0666 /sys/kernel/tracing/events/filemap/enable chmod 0666 /sys/kernel/debug/tracing/events/filemap/enable - # irq - chmod 0666 /sys/kernel/tracing/events/irq/enable - chmod 0666 /sys/kernel/debug/tracing/events/irq/enable - chmod 0666 /sys/kernel/tracing/events/ipi/enable - chmod 0666 /sys/kernel/debug/tracing/events/ipi/enable diff --git a/libs/binder/TEST_MAPPING b/libs/binder/TEST_MAPPING index 2e90142af6..1fbaa13887 100644 --- a/libs/binder/TEST_MAPPING +++ b/libs/binder/TEST_MAPPING @@ -22,10 +22,6 @@ "name": "binderParcelTest" }, { - "name": "binderParcelTest", - "host": true - }, - { "name": "binderLibTest" }, { diff --git a/libs/binder/ndk/include_platform/android/binder_manager.h b/libs/binder/ndk/include_platform/android/binder_manager.h index 45807515e4..5df0012bd3 100644 --- a/libs/binder/ndk/include_platform/android/binder_manager.h +++ b/libs/binder/ndk/include_platform/android/binder_manager.h @@ -96,6 +96,22 @@ __attribute__((warn_unused_result)) AIBinder* AServiceManager_waitForService(con bool AServiceManager_isDeclared(const char* instance) __INTRODUCED_IN(31); /** + * Returns all declared instances for a particular interface. + * + * For instance, if 'android.foo.IFoo/foo' is declared, and 'android.foo.IFoo' is + * passed here, then ["foo"] would be returned. + * + * See also AServiceManager_isDeclared. + * + * \param interface interface, e.g. 'android.foo.IFoo' + * \param context to pass to callback + * \param callback taking instance (e.g. 'foo') and context + */ +void AServiceManager_forEachDeclaredInstance(const char* interface, void* context, + void (*callback)(const char*, void*)) + __INTRODUCED_IN(31); + +/** * Prevent lazy services without client from shutting down their process * * \param persist 'true' if the process should not exit. diff --git a/libs/binder/ndk/libbinder_ndk.map.txt b/libs/binder/ndk/libbinder_ndk.map.txt index cef0bf31d2..8d08275eec 100644 --- a/libs/binder/ndk/libbinder_ndk.map.txt +++ b/libs/binder/ndk/libbinder_ndk.map.txt @@ -118,6 +118,7 @@ LIBBINDER_NDK31 { # introduced=31 AIBinder_getCallingSid; # apex AIBinder_setRequestingSid; # apex AServiceManager_isDeclared; # apex llndk + AServiceManager_forEachDeclaredInstance; # apex llndk AServiceManager_registerLazyService; # llndk AServiceManager_waitForService; # apex llndk AServiceManager_forceLazyServicesPersist; # llndk diff --git a/libs/binder/ndk/service_manager.cpp b/libs/binder/ndk/service_manager.cpp index cb0987e3e1..1ccd0d2a2b 100644 --- a/libs/binder/ndk/service_manager.cpp +++ b/libs/binder/ndk/service_manager.cpp @@ -19,6 +19,7 @@ #include "ibinder_internal.h" #include "status_internal.h" +#include <android-base/logging.h> #include <binder/IServiceManager.h> #include <binder/LazyServiceRegistrar.h> @@ -28,6 +29,7 @@ using ::android::IServiceManager; using ::android::sp; using ::android::status_t; using ::android::String16; +using ::android::String8; binder_exception_t AServiceManager_addService(AIBinder* binder, const char* instance) { if (binder == nullptr || instance == nullptr) { @@ -92,6 +94,17 @@ bool AServiceManager_isDeclared(const char* instance) { sp<IServiceManager> sm = defaultServiceManager(); return sm->isDeclared(String16(instance)); } +void AServiceManager_forEachDeclaredInstance(const char* interface, void* context, + void (*callback)(const char*, void*)) { + CHECK(interface != nullptr); + // context may be nullptr + CHECK(callback != nullptr); + + sp<IServiceManager> sm = defaultServiceManager(); + for (const String16& instance : sm->getDeclaredInstances(String16(interface))) { + callback(String8(instance).c_str(), context); + } +} void AServiceManager_forceLazyServicesPersist(bool persist) { auto serviceRegistrar = android::binder::LazyServiceRegistrar::getInstance(); serviceRegistrar.forcePersist(persist); @@ -110,4 +123,4 @@ bool AServiceManager_tryUnregister() { void AServiceManager_reRegister() { auto serviceRegistrar = android::binder::LazyServiceRegistrar::getInstance(); serviceRegistrar.reRegister(); -}
\ No newline at end of file +} diff --git a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp index de1a48dfd8..6a88401962 100644 --- a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp +++ b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp @@ -270,6 +270,25 @@ TEST(NdkBinder, DoubleNumber) { EXPECT_EQ(2, out); } +void defaultInstanceCounter(const char* instance, void* context) { + if (strcmp(instance, "default") == 0) { + ++*(size_t*)(context); + } +} + +TEST(NdkBinder, GetDeclaredInstances) { + bool hasLight = AServiceManager_isDeclared("android.hardware.light.ILights/default"); + + size_t count; + AServiceManager_forEachDeclaredInstance("android.hardware.light.ILights", &count, + defaultInstanceCounter); + + // At the time of writing this test, there is no good interface guaranteed + // to be on all devices. Cuttlefish has light, so this will generally test + // things. + EXPECT_EQ(count, hasLight ? 1 : 0); +} + TEST(NdkBinder, GetLazyService) { // Not declared in the vintf manifest ASSERT_FALSE(AServiceManager_isDeclared(kLazyBinderNdkUnitTestService)); diff --git a/libs/gui/ISurfaceComposer.cpp b/libs/gui/ISurfaceComposer.cpp index 2e4f858a9d..eba7b3c9fd 100644 --- a/libs/gui/ISurfaceComposer.cpp +++ b/libs/gui/ISurfaceComposer.cpp @@ -411,24 +411,6 @@ public: return static_cast<status_t>(reply.readInt32()); } - status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display, - bool* outSupport) const override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - status_t result = data.writeStrongBinder(display); - if (result != NO_ERROR) { - ALOGE("getAutoLowLatencyModeSupport failed to writeStrongBinder: %d", result); - return result; - } - result = remote()->transact(BnSurfaceComposer::GET_AUTO_LOW_LATENCY_MODE_SUPPORT, data, - &reply); - if (result != NO_ERROR) { - ALOGE("getAutoLowLatencyModeSupport failed to transact: %d", result); - return result; - } - return reply.readBool(outSupport); - } - void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) override { Parcel data, reply; status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); @@ -454,23 +436,6 @@ public: } } - status_t getGameContentTypeSupport(const sp<IBinder>& display, - bool* outSupport) const override { - Parcel data, reply; - data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); - status_t result = data.writeStrongBinder(display); - if (result != NO_ERROR) { - ALOGE("getGameContentTypeSupport failed to writeStrongBinder: %d", result); - return result; - } - result = remote()->transact(BnSurfaceComposer::GET_GAME_CONTENT_TYPE_SUPPORT, data, &reply); - if (result != NO_ERROR) { - ALOGE("getGameContentTypeSupport failed to transact: %d", result); - return result; - } - return reply.readBool(outSupport); - } - void setGameContentType(const sp<IBinder>& display, bool on) override { Parcel data, reply; status_t result = data.writeInterfaceToken(ISurfaceComposer::getInterfaceDescriptor()); @@ -1423,23 +1388,6 @@ status_t BnSurfaceComposer::onTransact( result = reply->writeInt32(result); return result; } - - case GET_AUTO_LOW_LATENCY_MODE_SUPPORT: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp<IBinder> display = nullptr; - status_t result = data.readStrongBinder(&display); - if (result != NO_ERROR) { - ALOGE("getAutoLowLatencyModeSupport failed to readStrongBinder: %d", result); - return result; - } - bool supported = false; - result = getAutoLowLatencyModeSupport(display, &supported); - if (result == NO_ERROR) { - result = reply->writeBool(supported); - } - return result; - } - case SET_AUTO_LOW_LATENCY_MODE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp<IBinder> display = nullptr; @@ -1457,23 +1405,6 @@ status_t BnSurfaceComposer::onTransact( setAutoLowLatencyMode(display, setAllm); return result; } - - case GET_GAME_CONTENT_TYPE_SUPPORT: { - CHECK_INTERFACE(ISurfaceComposer, data, reply); - sp<IBinder> display = nullptr; - status_t result = data.readStrongBinder(&display); - if (result != NO_ERROR) { - ALOGE("getGameContentTypeSupport failed to readStrongBinder: %d", result); - return result; - } - bool supported = false; - result = getGameContentTypeSupport(display, &supported); - if (result == NO_ERROR) { - result = reply->writeBool(supported); - } - return result; - } - case SET_GAME_CONTENT_TYPE: { CHECK_INTERFACE(ISurfaceComposer, data, reply); sp<IBinder> display = nullptr; @@ -1491,7 +1422,6 @@ status_t BnSurfaceComposer::onTransact( setGameContentType(display, setGameContentTypeOn); return result; } - case CLEAR_ANIMATION_FRAME_STATS: { CHECK_INTERFACE(ISurfaceComposer, data, reply); status_t result = clearAnimationFrameStats(); diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp index 1a643c2409..0317b2bd2b 100644 --- a/libs/gui/SurfaceComposerClient.cpp +++ b/libs/gui/SurfaceComposerClient.cpp @@ -1904,22 +1904,10 @@ status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display, return ComposerService::getComposerService()->setActiveColorMode(display, colorMode); } -bool SurfaceComposerClient::getAutoLowLatencyModeSupport(const sp<IBinder>& display) { - bool supported = false; - ComposerService::getComposerService()->getAutoLowLatencyModeSupport(display, &supported); - return supported; -} - void SurfaceComposerClient::setAutoLowLatencyMode(const sp<IBinder>& display, bool on) { ComposerService::getComposerService()->setAutoLowLatencyMode(display, on); } -bool SurfaceComposerClient::getGameContentTypeSupport(const sp<IBinder>& display) { - bool supported = false; - ComposerService::getComposerService()->getGameContentTypeSupport(display, &supported); - return supported; -} - void SurfaceComposerClient::setGameContentType(const sp<IBinder>& display, bool on) { ComposerService::getComposerService()->setGameContentType(display, on); } diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h index d0ab4802e1..6289e5a5d0 100644 --- a/libs/gui/include/gui/ISurfaceComposer.h +++ b/libs/gui/include/gui/ISurfaceComposer.h @@ -219,32 +219,17 @@ public: ui::ColorMode colorMode) = 0; /** - * Returns true if the connected display reports support for HDMI 2.1 Auto - * Low Latency Mode. - * For more information, see the HDMI 2.1 specification. - */ - virtual status_t getAutoLowLatencyModeSupport(const sp<IBinder>& display, - bool* outSupport) const = 0; - - /** * Switches Auto Low Latency Mode on/off on the connected display, if it is - * available. This should only be called if #getAutoLowLatencyMode returns - * true. + * available. This should only be called if the display supports Auto Low + * Latency Mode as reported in #getDynamicDisplayInfo. * For more information, see the HDMI 2.1 specification. */ virtual void setAutoLowLatencyMode(const sp<IBinder>& display, bool on) = 0; /** - * Returns true if the connected display reports support for Game Content Type. - * For more information, see the HDMI 1.4 specification. - */ - virtual status_t getGameContentTypeSupport(const sp<IBinder>& display, - bool* outSupport) const = 0; - - /** * This will start sending infoframes to the connected display with - * ContentType=Game (if on=true). This will switch the disply to Game mode. - * This should only be called if #getGameContentTypeSupport returns true. + * ContentType=Game (if on=true). This should only be called if the display + * Game Content Type as reported in #getDynamicDisplayInfo. * For more information, see the HDMI 1.4 specification. */ virtual void setGameContentType(const sp<IBinder>& display, bool on) = 0; @@ -563,9 +548,9 @@ public: CAPTURE_DISPLAY_BY_ID, NOTIFY_POWER_BOOST, SET_GLOBAL_SHADOW_SETTINGS, - GET_AUTO_LOW_LATENCY_MODE_SUPPORT, + GET_AUTO_LOW_LATENCY_MODE_SUPPORT, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. SET_AUTO_LOW_LATENCY_MODE, - GET_GAME_CONTENT_TYPE_SUPPORT, + GET_GAME_CONTENT_TYPE_SUPPORT, // Deprecated. Use GET_DYNAMIC_DISPLAY_INFO instead. SET_GAME_CONTENT_TYPE, SET_FRAME_RATE, ACQUIRE_FRAME_RATE_FLEXIBILITY_TOKEN, diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h index 6f0f18c131..64c8af50bd 100644 --- a/libs/gui/include/gui/SurfaceComposerClient.h +++ b/libs/gui/include/gui/SurfaceComposerClient.h @@ -143,17 +143,11 @@ public: static status_t setActiveColorMode(const sp<IBinder>& display, ui::ColorMode colorMode); - // Reports whether the connected display supports Auto Low Latency Mode - static bool getAutoLowLatencyModeSupport(const sp<IBinder>& display); - // Switches on/off Auto Low Latency Mode on the connected display. This should only be // called if the connected display supports Auto Low Latency Mode as reported by // #getAutoLowLatencyModeSupport static void setAutoLowLatencyMode(const sp<IBinder>& display, bool on); - // Reports whether the connected display supports Game content type - static bool getGameContentTypeSupport(const sp<IBinder>& display); - // Turns Game mode on/off on the connected display. This should only be called // if the display supports Game content type, as reported by #getGameContentTypeSupport static void setGameContentType(const sp<IBinder>& display, bool on); diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp index 3397198fa0..69bb86649c 100644 --- a/libs/gui/tests/Surface_test.cpp +++ b/libs/gui/tests/Surface_test.cpp @@ -757,15 +757,7 @@ public: const sp<IScreenCaptureListener>& /* captureListener */) override { return NO_ERROR; } - status_t getAutoLowLatencyModeSupport(const sp<IBinder>& /*display*/, - bool* /*outSupport*/) const override { - return NO_ERROR; - } void setAutoLowLatencyMode(const sp<IBinder>& /*display*/, bool /*on*/) override {} - status_t getGameContentTypeSupport(const sp<IBinder>& /*display*/, - bool* /*outSupport*/) const override { - return NO_ERROR; - } void setGameContentType(const sp<IBinder>& /*display*/, bool /*on*/) override {} status_t captureDisplay(uint64_t /*displayOrLayerStack*/, const sp<IScreenCaptureListener>& /* captureListener */) override { diff --git a/libs/math/Android.bp b/libs/math/Android.bp index 3cf9f3f97b..907eb67e9a 100644 --- a/libs/math/Android.bp +++ b/libs/math/Android.bp @@ -39,6 +39,7 @@ cc_library_static { "com.android.media.swcodec", "com.android.neuralnetworks", ], + min_sdk_version: "29", export_include_dirs: ["include"], @@ -49,4 +50,23 @@ cc_library_static { } } +cc_library_headers { + name: "libmath_headers", + export_include_dirs: ["include"], + host_supported: true, + vendor_available: true, + + apex_available: [ + "//apex_available:anyapex", + "//apex_available:platform", + ], + min_sdk_version: "apex_inherit", + + target: { + windows: { + enabled: true, + } + } +} + subdirs = ["tests"] diff --git a/libs/math/OWNERS b/libs/math/OWNERS index 6fb149a89c..72d33bc09e 100644 --- a/libs/math/OWNERS +++ b/libs/math/OWNERS @@ -1,6 +1,3 @@ -jaesoo@google.com -jiyong@google.com mathias@google.com -pawin@google.com randolphs@google.com romainguy@google.com diff --git a/libs/math/include/math/HashCombine.h b/libs/math/include/math/HashCombine.h new file mode 100644 index 0000000000..e91b52ba98 --- /dev/null +++ b/libs/math/include/math/HashCombine.h @@ -0,0 +1,38 @@ +/* + * Copyright 2021 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. + */ + +#pragma once + +#include <functional> + +namespace android { +static inline void hashCombineSingleHashed(size_t& combinedHash, size_t hash) { + combinedHash = 31 * combinedHash + hash; +} + +template<typename T> +static inline void hashCombineSingle(size_t& combinedHash, const T& val) { + hashCombineSingleHashed(combinedHash, std::hash<T>{}(val)); +} + +template<typename... Types> +static inline size_t hashCombine(const Types& ... args) { + size_t hash = 0; + ( hashCombineSingle(hash, args), ... ); + return hash; +} + +} // namespace android
\ No newline at end of file diff --git a/libs/math/include/math/TVecHelpers.h b/libs/math/include/math/TVecHelpers.h index 20f852fd9f..0dac662e97 100644 --- a/libs/math/include/math/TVecHelpers.h +++ b/libs/math/include/math/TVecHelpers.h @@ -19,9 +19,11 @@ #include <math.h> #include <stdint.h> +#include <math/HashCombine.h> #include <sys/types.h> #include <cmath> +#include <functional> #include <limits> #include <iostream> @@ -250,6 +252,17 @@ public: } return r; } + + // This isn't strictly a unary operator, but it is a common place shared between both + // matrix and vector classes + size_t hash() const { + VECTOR<T> const& rv(static_cast<VECTOR<T> const&>(*this)); + size_t hashed = 0; + for (size_t i = 0; i < rv.size(); i++) { + android::hashCombineSingle(hashed, rv[i]); + } + return hashed; + } }; /* @@ -606,3 +619,16 @@ public: // ------------------------------------------------------------------------------------- } // namespace details } // namespace android + +namespace std { + template<template<typename T> class VECTOR, typename T> + struct hash<VECTOR<T>> { + static constexpr bool IS_VECTOR = + std::is_base_of<android::details::TVecUnaryOperators<VECTOR, T>, VECTOR<T>>::value; + + typename std::enable_if<IS_VECTOR, size_t>::type + operator()(const VECTOR<T>& v) const { + return v.hash(); + } + }; +} diff --git a/libs/math/include/math/half.h b/libs/math/include/math/half.h index 617a0ab5d2..5ec9bf7b40 100644 --- a/libs/math/include/math/half.h +++ b/libs/math/include/math/half.h @@ -17,6 +17,7 @@ #pragma once #include <stdint.h> +#include <functional> #include <iosfwd> #include <limits> #include <type_traits> @@ -202,6 +203,12 @@ public: inline static constexpr type signaling_NaN() noexcept { return android::half(android::half::binary, 0x7dff); } }; +template<> struct hash<android::half> { + size_t operator()(const android::half& half) { + return std::hash<float>{}(half); + } +}; + } // namespace std #ifdef LIKELY_DEFINED_LOCAL diff --git a/libs/math/tests/Android.bp b/libs/math/tests/Android.bp index 4a7c4dd8a4..14fb72af78 100644 --- a/libs/math/tests/Android.bp +++ b/libs/math/tests/Android.bp @@ -50,3 +50,10 @@ cc_test { static_libs: ["libmath"], cflags: ["-Wall", "-Werror"], } + +cc_test { + name: "hashcombine_test", + srcs: ["hashcombine_test.cpp"], + static_libs: ["libmath"], + cflags: ["-Wall", "-Werror"], +} diff --git a/libs/math/tests/half_test.cpp b/libs/math/tests/half_test.cpp index 604072e557..a514d986e4 100644 --- a/libs/math/tests/half_test.cpp +++ b/libs/math/tests/half_test.cpp @@ -94,4 +94,13 @@ TEST_F(HalfTest, Vec) { EXPECT_EQ(f4.xy, h2); } + +TEST_F(HalfTest, Hash) { + float4 f4a(1,2,3,4); + float4 f4b(2,2,3,4); + half4 h4a(f4a), h4b(f4b); + + EXPECT_NE(std::hash<half4>{}(h4a), std::hash<half4>{}(h4b)); +} + }; // namespace android diff --git a/libs/math/tests/hashcombine_test.cpp b/libs/math/tests/hashcombine_test.cpp new file mode 100644 index 0000000000..96c6e81588 --- /dev/null +++ b/libs/math/tests/hashcombine_test.cpp @@ -0,0 +1,43 @@ +/* + * Copyright 2021 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. + */ + +#define LOG_TAG "HashCombineTest" + +#include <math.h> +#include <stdlib.h> + +#include <math/half.h> +#include <math/vec4.h> + +#include <gtest/gtest.h> + +namespace android { + +class HashCombineTest : public testing::Test { +protected: +}; + +TEST_F(HashCombineTest, Basics) { + char a = 40; + int b = 32; + int c = 55; + float d = 42.f; + float d_ = 42.1f; + + EXPECT_NE(hashCombine(a, b, c, d), hashCombine(a, b, c, d_)); +} + +}; // namespace android diff --git a/libs/ui/Android.bp b/libs/ui/Android.bp index ac0ae72f29..de2b9a406b 100644 --- a/libs/ui/Android.bp +++ b/libs/ui/Android.bp @@ -238,9 +238,11 @@ cc_library_headers { }, header_libs: [ "libnativewindow_headers", + "libmath_headers", ], export_header_lib_headers: [ "libnativewindow_headers", + "libmath_headers", ], min_sdk_version: "29", } diff --git a/libs/ui/DynamicDisplayInfo.cpp b/libs/ui/DynamicDisplayInfo.cpp index 11acdae921..d5c4ef0c17 100644 --- a/libs/ui/DynamicDisplayInfo.cpp +++ b/libs/ui/DynamicDisplayInfo.cpp @@ -39,7 +39,9 @@ size_t DynamicDisplayInfo::getFlattenedSize() const { FlattenableHelpers::getFlattenedSize(activeDisplayModeId) + FlattenableHelpers::getFlattenedSize(supportedColorModes) + FlattenableHelpers::getFlattenedSize(activeColorMode) + - FlattenableHelpers::getFlattenedSize(hdrCapabilities); + FlattenableHelpers::getFlattenedSize(hdrCapabilities) + + FlattenableHelpers::getFlattenedSize(autoLowLatencyModeSupported) + + FlattenableHelpers::getFlattenedSize(gameContentTypeSupported); } status_t DynamicDisplayInfo::flatten(void* buffer, size_t size) const { @@ -51,6 +53,8 @@ status_t DynamicDisplayInfo::flatten(void* buffer, size_t size) const { RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, supportedColorModes)); RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, activeColorMode)); RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, hdrCapabilities)); + RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, autoLowLatencyModeSupported)); + RETURN_IF_ERROR(FlattenableHelpers::flatten(&buffer, &size, gameContentTypeSupported)); return OK; } @@ -60,6 +64,8 @@ status_t DynamicDisplayInfo::unflatten(const void* buffer, size_t size) { RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &supportedColorModes)); RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &activeColorMode)); RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &hdrCapabilities)); + RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &autoLowLatencyModeSupported)); + RETURN_IF_ERROR(FlattenableHelpers::unflatten(&buffer, &size, &gameContentTypeSupported)); return OK; } diff --git a/libs/ui/OWNERS b/libs/ui/OWNERS index 5110a6c8a7..a0b5fe7119 100644 --- a/libs/ui/OWNERS +++ b/libs/ui/OWNERS @@ -1,3 +1,4 @@ +adyabr@google.com alecmouri@google.com chrisforbes@google.com jreck@google.com diff --git a/libs/ui/include/ui/DynamicDisplayInfo.h b/libs/ui/include/ui/DynamicDisplayInfo.h index 6c349b749d..a4c2f71a4c 100644 --- a/libs/ui/include/ui/DynamicDisplayInfo.h +++ b/libs/ui/include/ui/DynamicDisplayInfo.h @@ -41,6 +41,14 @@ struct DynamicDisplayInfo : LightFlattenable<DynamicDisplayInfo> { ui::ColorMode activeColorMode; HdrCapabilities hdrCapabilities; + // True if the display reports support for HDMI 2.1 Auto Low Latency Mode. + // For more information, see the HDMI 2.1 specification. + bool autoLowLatencyModeSupported; + + // True if the display reports support for Game Content Type. + // For more information, see the HDMI 1.4 specification. + bool gameContentTypeSupported; + std::optional<ui::DisplayMode> getActiveDisplayMode() const; bool isFixedSize() const { return false; } diff --git a/libs/ui/include/ui/FloatRect.h b/libs/ui/include/ui/FloatRect.h index 5d329ea6a9..4c9c7b7ef1 100644 --- a/libs/ui/include/ui/FloatRect.h +++ b/libs/ui/include/ui/FloatRect.h @@ -16,6 +16,7 @@ #pragma once +#include <math/HashCombine.h> #include <ostream> namespace android { @@ -62,3 +63,13 @@ static inline void PrintTo(const FloatRect& rect, ::std::ostream* os) { } } // namespace android + +namespace std { + +template <> +struct hash<android::FloatRect> { + size_t operator()(const android::FloatRect& rect) const { + return android::hashCombine(rect.left, rect.top, rect.right, rect.bottom); + } +}; +} // namespace std diff --git a/libs/ui/include/ui/Rect.h b/libs/ui/include/ui/Rect.h index 58323e553e..9e24a077ff 100644 --- a/libs/ui/include/ui/Rect.h +++ b/libs/ui/include/ui/Rect.h @@ -24,6 +24,7 @@ #include <utils/Log.h> #include <utils/TypeHelpers.h> +#include <math/HashCombine.h> #include <ui/FloatRect.h> #include <ui/Point.h> #include <ui/Size.h> @@ -234,4 +235,13 @@ ANDROID_BASIC_TYPES_TRAITS(Rect) }; // namespace android +namespace std { +template <> +struct hash<android::Rect> { + size_t operator()(const android::Rect& rect) const { + return android::hashCombine(rect.left, rect.top, rect.right, rect.bottom); + } +}; +} // namespace std + #endif // ANDROID_UI_RECT diff --git a/libs/ui/include/ui/Region.h b/libs/ui/include/ui/Region.h index 6bb7b8d21c..927c334c85 100644 --- a/libs/ui/include/ui/Region.h +++ b/libs/ui/include/ui/Region.h @@ -21,6 +21,7 @@ #include <sys/types.h> #include <ostream> +#include <math/HashCombine.h> #include <ui/Rect.h> #include <utils/Flattenable.h> @@ -234,4 +235,17 @@ static inline void PrintTo(const Region& region, ::std::ostream* os) { // --------------------------------------------------------------------------- }; // namespace android +namespace std { +template <> +struct hash<android::Region> { + size_t operator()(const android::Region& region) const { + size_t hash = 0; + for (const android::Rect& rect : region) { + android::hashCombineSingle(hash, rect); + } + return hash; + } +}; +} // namespace std + #endif // ANDROID_UI_REGION_H diff --git a/libs/ui/tests/Rect_test.cpp b/libs/ui/tests/Rect_test.cpp index 5499a5b507..9cc36bb15b 100644 --- a/libs/ui/tests/Rect_test.cpp +++ b/libs/ui/tests/Rect_test.cpp @@ -259,4 +259,33 @@ TEST(RectTest, toFloatRect) { EXPECT_EQ(FloatRect(10.f, 20.f, 50.f, 60.f), floatRect); } +TEST(RectTest, RectHash) { + const std::vector<Rect> rects = { + Rect(10, 20, 50, 60), Rect(11, 20, 50, 60), Rect(11, 21, 50, 60), + Rect(11, 21, 51, 60), Rect(11, 21, 51, 61), + }; + + for (const auto& a : rects) { + for (const auto& b : rects) { + const bool hashEq = std::hash<Rect>{}(a) == std::hash<Rect>{}(b); + EXPECT_EQ(a == b, hashEq); + } + } +} + +TEST(RectTest, FloatRectHash) { + const std::vector<FloatRect> floatRects = { + Rect(10, 20, 50, 60).toFloatRect(), Rect(11, 20, 50, 60).toFloatRect(), + Rect(11, 21, 50, 60).toFloatRect(), Rect(11, 21, 51, 60).toFloatRect(), + Rect(11, 21, 51, 61).toFloatRect(), + }; + + for (const auto& a : floatRects) { + for (const auto& b : floatRects) { + const bool hashEq = std::hash<FloatRect>{}(a) == std::hash<FloatRect>{}(b); + EXPECT_EQ(a == b, hashEq); + } + } +} + } // namespace android::ui diff --git a/libs/ui/tests/Region_test.cpp b/libs/ui/tests/Region_test.cpp index c6b826d66e..74924bdce8 100644 --- a/libs/ui/tests/Region_test.cpp +++ b/libs/ui/tests/Region_test.cpp @@ -167,5 +167,17 @@ TEST_F(RegionTest, EqualsToSelf) { ASSERT_TRUE(touchableRegion.contains(50, 50)); } +TEST_F(RegionTest, RegionHash) { + Region region1; + region1.addRectUnchecked(10, 20, 30, 40); + region1.addRectUnchecked(40, 30, 20, 10); + + Region region2; + region2.addRectUnchecked(11, 20, 30, 40); + region2.addRectUnchecked(40, 31, 20, 10); + + EXPECT_NE(std::hash<Region>{}(region1), std::hash<Region>{}(region2)); +} + }; // namespace android diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 4ee759f0b0..472dee2d34 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -966,9 +966,18 @@ status_t SurfaceFlinger::getDynamicDisplayInfo(const sp<IBinder>& displayToken, } info->activeColorMode = display->getCompositionDisplay()->getState().colorMode; - info->supportedColorModes = getDisplayColorModes(display->getPhysicalId()); + const auto displayId = display->getPhysicalId(); + info->supportedColorModes = getDisplayColorModes(displayId); info->hdrCapabilities = display->getHdrCapabilities(); + info->autoLowLatencyModeSupported = + getHwComposer().hasDisplayCapability(displayId, + hal::DisplayCapability::AUTO_LOW_LATENCY_MODE); + std::vector<hal::ContentType> types; + getHwComposer().getSupportedContentTypes(displayId, &types); + info->gameContentTypeSupported = std::any_of(types.begin(), types.end(), [](auto type) { + return type == hal::ContentType::GAME; + }); return NO_ERROR; } @@ -1243,24 +1252,6 @@ status_t SurfaceFlinger::setActiveColorMode(const sp<IBinder>& displayToken, Col return NO_ERROR; } -status_t SurfaceFlinger::getAutoLowLatencyModeSupport(const sp<IBinder>& displayToken, - bool* outSupport) const { - if (!displayToken) { - return BAD_VALUE; - } - - Mutex::Autolock lock(mStateLock); - - const auto displayId = getPhysicalDisplayIdLocked(displayToken); - if (!displayId) { - return NAME_NOT_FOUND; - } - *outSupport = - getHwComposer().hasDisplayCapability(*displayId, - hal::DisplayCapability::AUTO_LOW_LATENCY_MODE); - return NO_ERROR; -} - void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) { static_cast<void>(schedule([=]() MAIN_THREAD { if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { @@ -1271,27 +1262,6 @@ void SurfaceFlinger::setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool })); } -status_t SurfaceFlinger::getGameContentTypeSupport(const sp<IBinder>& displayToken, - bool* outSupport) const { - if (!displayToken) { - return BAD_VALUE; - } - - Mutex::Autolock lock(mStateLock); - - const auto displayId = getPhysicalDisplayIdLocked(displayToken); - if (!displayId) { - return NAME_NOT_FOUND; - } - - std::vector<hal::ContentType> types; - getHwComposer().getSupportedContentTypes(*displayId, &types); - - *outSupport = std::any_of(types.begin(), types.end(), - [](auto type) { return type == hal::ContentType::GAME; }); - return NO_ERROR; -} - void SurfaceFlinger::setGameContentType(const sp<IBinder>& displayToken, bool on) { static_cast<void>(schedule([=]() MAIN_THREAD { if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h index 21cd2a5682..d9af7509a1 100644 --- a/services/surfaceflinger/SurfaceFlinger.h +++ b/services/surfaceflinger/SurfaceFlinger.h @@ -561,11 +561,7 @@ private: status_t getDisplayNativePrimaries(const sp<IBinder>& displayToken, ui::DisplayPrimaries&) override; status_t setActiveColorMode(const sp<IBinder>& displayToken, ui::ColorMode colorMode) override; - status_t getAutoLowLatencyModeSupport(const sp<IBinder>& displayToken, - bool* outSupported) const override; void setAutoLowLatencyMode(const sp<IBinder>& displayToken, bool on) override; - status_t getGameContentTypeSupport(const sp<IBinder>& displayToken, - bool* outSupported) const override; void setGameContentType(const sp<IBinder>& displayToken, bool on) override; void setPowerMode(const sp<IBinder>& displayToken, int mode) override; status_t clearAnimationFrameStats() override; diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp index 2d4690a2af..d1cd397da4 100644 --- a/vulkan/libvulkan/api.cpp +++ b/vulkan/libvulkan/api.cpp @@ -33,6 +33,7 @@ #include <unordered_set> #include <utility> +#include <android-base/properties.h> #include <android-base/strings.h> #include <cutils/properties.h> #include <log/log.h> @@ -134,7 +135,7 @@ class OverrideLayerNames { // If no layers specified via Settings, check legacy properties if (implicit_layers_.count <= 0) { ParseDebugVulkanLayers(); - property_list(ParseDebugVulkanLayer, this); + ParseDebugVulkanLayer(); // sort by priorities auto& arr = implicit_layers_; @@ -181,30 +182,39 @@ class OverrideLayerNames { AddImplicitLayer(prio, p, strlen(p)); } - static void ParseDebugVulkanLayer(const char* key, - const char* val, - void* user_data) { + void ParseDebugVulkanLayer() { + // Checks for consecutive debug.vulkan.layer.<priority> system + // properties after always checking an initial fixed range. static const char prefix[] = "debug.vulkan.layer."; - const size_t prefix_len = sizeof(prefix) - 1; - - if (strncmp(key, prefix, prefix_len) || val[0] == '\0') - return; - key += prefix_len; - - // debug.vulkan.layer.<priority> - int priority = -1; - if (key[0] >= '0' && key[0] <= '9') - priority = atoi(key); + static constexpr int kFixedRangeBeginInclusive = 0; + static constexpr int kFixedRangeEndInclusive = 9; + + bool logged = false; + + int priority = kFixedRangeBeginInclusive; + while (true) { + const std::string prop_key = + std::string(prefix) + std::to_string(priority); + const std::string prop_val = + android::base::GetProperty(prop_key, ""); + + if (!prop_val.empty()) { + if (!logged) { + ALOGI( + "Detected Vulkan layers configured with " + "debug.vulkan.layer.<priority>. Checking for " + "debug.vulkan.layer.<priority> in the range [%d, %d] " + "followed by a consecutive scan.", + kFixedRangeBeginInclusive, kFixedRangeEndInclusive); + logged = true; + } + AddImplicitLayer(priority, prop_val.c_str(), prop_val.length()); + } else if (priority >= kFixedRangeEndInclusive) { + return; + } - if (priority < 0) { - ALOGW("Ignored implicit layer %s with invalid priority %s", val, - key); - return; + ++priority; } - - OverrideLayerNames& override_layers = - *reinterpret_cast<OverrideLayerNames*>(user_data); - override_layers.AddImplicitLayer(priority, val, strlen(val)); } void AddImplicitLayer(int priority, const char* name, size_t len) { |