Merge "Use android.hardware.vibrator NDK backend" into main
diff --git a/cmds/servicemanager/NameUtil.h b/cmds/servicemanager/NameUtil.h
index b080939..4b10c2b 100644
--- a/cmds/servicemanager/NameUtil.h
+++ b/cmds/servicemanager/NameUtil.h
@@ -19,8 +19,6 @@
#include <string>
#include <string_view>
-#include <android-base/strings.h>
-
namespace android {
#ifndef VENDORSERVICEMANAGER
diff --git a/libs/binder/Android.bp b/libs/binder/Android.bp
index 80720b0..cdc7166 100644
--- a/libs/binder/Android.bp
+++ b/libs/binder/Android.bp
@@ -87,7 +87,7 @@
cc_cmake_snapshot {
name: "binder_sdk",
- modules: [
+ modules_host: [
"libbinder_sdk",
"libbinder_sdk_single_threaded",
"libbinder_ndk_sdk",
@@ -100,7 +100,6 @@
prebuilts: [
// to enable arm64 host support, build with musl - e.g. on aosp_cf_arm64_phone
"aidl",
- "libc++",
],
include_sources: true,
cflags: [
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp
index 61d0dba..984c93d 100644
--- a/libs/binder/IPCThreadState.cpp
+++ b/libs/binder/IPCThreadState.cpp
@@ -22,9 +22,7 @@
#include <binder/BpBinder.h>
#include <binder/TextOutput.h>
-#include <cutils/sched_policy.h>
#include <utils/CallStack.h>
-#include <utils/Log.h>
#include <atomic>
#include <errno.h>
@@ -287,7 +285,9 @@
return cmd;
}
+LIBBINDER_IGNORE("-Wzero-as-null-pointer-constant")
static pthread_mutex_t gTLSMutex = PTHREAD_MUTEX_INITIALIZER;
+LIBBINDER_IGNORE_END()
static std::atomic<bool> gHaveTLS(false);
static pthread_key_t gTLS = 0;
static std::atomic<bool> gShutdown = false;
diff --git a/libs/binder/IServiceManager.cpp b/libs/binder/IServiceManager.cpp
index 2095586..17e522d 100644
--- a/libs/binder/IServiceManager.cpp
+++ b/libs/binder/IServiceManager.cpp
@@ -29,7 +29,6 @@
#include <android/os/IServiceManager.h>
#include <binder/IPCThreadState.h>
#include <binder/Parcel.h>
-#include <utils/Log.h>
#include <utils/String8.h>
#ifndef __ANDROID_VNDK__
diff --git a/libs/binder/IShellCallback.cpp b/libs/binder/IShellCallback.cpp
index 86dd5c4..1d6852a 100644
--- a/libs/binder/IShellCallback.cpp
+++ b/libs/binder/IShellCallback.cpp
@@ -21,7 +21,6 @@
#include <binder/IShellCallback.h>
-#include <utils/Log.h>
#include <binder/Parcel.h>
#include <utils/String8.h>
diff --git a/libs/binder/LazyServiceRegistrar.cpp b/libs/binder/LazyServiceRegistrar.cpp
index 7644806..0f0af0b 100644
--- a/libs/binder/LazyServiceRegistrar.cpp
+++ b/libs/binder/LazyServiceRegistrar.cpp
@@ -14,15 +14,13 @@
* limitations under the License.
*/
-#include "log/log_main.h"
#define LOG_TAG "AidlLazyServiceRegistrar"
-#include <binder/LazyServiceRegistrar.h>
-#include <binder/IPCThreadState.h>
-#include <binder/IServiceManager.h>
#include <android/os/BnClientCallback.h>
#include <android/os/IServiceManager.h>
-#include <utils/Log.h>
+#include <binder/IPCThreadState.h>
+#include <binder/IServiceManager.h>
+#include <binder/LazyServiceRegistrar.h>
namespace android {
namespace binder {
diff --git a/libs/binder/PersistableBundle.cpp b/libs/binder/PersistableBundle.cpp
index 5b157cc..abb6612 100644
--- a/libs/binder/PersistableBundle.cpp
+++ b/libs/binder/PersistableBundle.cpp
@@ -113,7 +113,7 @@
// Backpatch length. This length value includes the length header.
parcel->setDataPosition(length_pos);
size_t length = end_pos - start_pos;
- if (length > std::numeric_limits<int32_t>::max()) {
+ if (length > static_cast<size_t>(std::numeric_limits<int32_t>::max())) {
ALOGE("Parcel length (%zu) too large to store in 32-bit signed int", length);
return BAD_VALUE;
}
@@ -319,7 +319,7 @@
* pairs themselves.
*/
size_t num_entries = size();
- if (num_entries > std::numeric_limits<int32_t>::max()) {
+ if (num_entries > static_cast<size_t>(std::numeric_limits<int32_t>::max())) {
ALOGE("The size of this PersistableBundle (%zu) too large to store in 32-bit signed int",
num_entries);
return BAD_VALUE;
diff --git a/libs/binder/ProcessState.cpp b/libs/binder/ProcessState.cpp
index 5de152a..a42ede2 100644
--- a/libs/binder/ProcessState.cpp
+++ b/libs/binder/ProcessState.cpp
@@ -26,7 +26,6 @@
#include <binder/Stability.h>
#include <cutils/atomic.h>
#include <utils/AndroidThreads.h>
-#include <utils/Log.h>
#include <utils/String8.h>
#include <utils/Thread.h>
diff --git a/libs/binder/TEST_MAPPING b/libs/binder/TEST_MAPPING
index 2b3ff44..1256173 100644
--- a/libs/binder/TEST_MAPPING
+++ b/libs/binder/TEST_MAPPING
@@ -129,6 +129,12 @@
"name": "memunreachable_binder_test"
}
],
+ "postsubmit": [
+ {
+ "name": "binder_sdk_test",
+ "host": true
+ }
+ ],
"imports": [
{
"path": "packages/modules/Virtualization"
diff --git a/libs/binder/Utils.h b/libs/binder/Utils.h
index 5e1012a..881cdf3 100644
--- a/libs/binder/Utils.h
+++ b/libs/binder/Utils.h
@@ -58,6 +58,19 @@
} \
} while (0)
+#define LIBBINDER_PRAGMA(arg) _Pragma(#arg)
+#if defined(__clang__)
+#define LIBBINDER_PRAGMA_FOR_COMPILER(arg) LIBBINDER_PRAGMA(clang arg)
+#elif defined(__GNUC__)
+#define LIBBINDER_PRAGMA_FOR_COMPILER(arg) LIBBINDER_PRAGMA(GCC arg)
+#else
+#define LIBBINDER_PRAGMA_FOR_COMPILER(arg)
+#endif
+#define LIBBINDER_IGNORE(warning_flag) \
+ LIBBINDER_PRAGMA_FOR_COMPILER(diagnostic push) \
+ LIBBINDER_PRAGMA_FOR_COMPILER(diagnostic ignored warning_flag)
+#define LIBBINDER_IGNORE_END() LIBBINDER_PRAGMA_FOR_COMPILER(diagnostic pop)
+
namespace android {
/**
diff --git a/libs/binder/include/binder/Functional.h b/libs/binder/include/binder/Functional.h
index bb0e5f4..e153969 100644
--- a/libs/binder/include/binder/Functional.h
+++ b/libs/binder/include/binder/Functional.h
@@ -36,7 +36,7 @@
inline void release() { f_.reset(); }
private:
- friend scope_guard<F> android::binder::impl::make_scope_guard(F);
+ friend scope_guard<F> android::binder::impl::make_scope_guard<>(F);
inline scope_guard(F&& f) : f_(std::move(f)) {}
diff --git a/libs/binder/include/binder/ProcessState.h b/libs/binder/include/binder/ProcessState.h
index 8908cb8..021bd58 100644
--- a/libs/binder/include/binder/ProcessState.h
+++ b/libs/binder/include/binder/ProcessState.h
@@ -25,6 +25,7 @@
#include <atomic>
#include <chrono>
+#include <condition_variable>
#include <mutex>
// ---------------------------------------------------------------------------
diff --git a/libs/binder/ndk/include_ndk/android/persistable_bundle.h b/libs/binder/ndk/include_ndk/android/persistable_bundle.h
index 42ae15a..5e0d4da 100644
--- a/libs/binder/ndk/include_ndk/android/persistable_bundle.h
+++ b/libs/binder/ndk/include_ndk/android/persistable_bundle.h
@@ -29,6 +29,11 @@
#include <sys/cdefs.h>
#include <sys/types.h>
+#ifndef __clang__
+#define _Nullable
+#define _Nonnull
+#endif
+
__BEGIN_DECLS
/*
diff --git a/libs/binder/ndk/persistable_bundle.cpp b/libs/binder/ndk/persistable_bundle.cpp
index 9b6877d..afa032e 100644
--- a/libs/binder/ndk/persistable_bundle.cpp
+++ b/libs/binder/ndk/persistable_bundle.cpp
@@ -17,11 +17,12 @@
#include <android/persistable_bundle.h>
#include <binder/PersistableBundle.h>
#include <log/log.h>
-#include <persistable_bundle_internal.h>
#include <string.h>
#include <set>
+#include "persistable_bundle_internal.h"
+
__BEGIN_DECLS
struct APersistableBundle {
diff --git a/libs/binder/ndk/service_manager.cpp b/libs/binder/ndk/service_manager.cpp
index 4436dbe..d6ac4ac 100644
--- a/libs/binder/ndk/service_manager.cpp
+++ b/libs/binder/ndk/service_manager.cpp
@@ -18,6 +18,7 @@
#include <binder/IServiceManager.h>
#include <binder/LazyServiceRegistrar.h>
+#include "../Utils.h"
#include "ibinder_internal.h"
#include "status_internal.h"
@@ -89,7 +90,9 @@
}
sp<IServiceManager> sm = defaultServiceManager();
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
sp<IBinder> binder = sm->getService(String16(instance));
+ LIBBINDER_IGNORE_END()
sp<AIBinder> ret = ABpBinder::lookupOrCreateFromBinder(binder);
AIBinder_incStrong(ret.get());
diff --git a/libs/binder/ndk/tests/Android.bp b/libs/binder/ndk/tests/Android.bp
index 8fb755c..c61a164 100644
--- a/libs/binder/ndk/tests/Android.bp
+++ b/libs/binder/ndk/tests/Android.bp
@@ -34,6 +34,11 @@
cflags: [
"-O0",
"-g",
+ "-Wall",
+ "-Wextra",
+ "-Wextra-semi",
+ "-Werror",
+ "-Winconsistent-missing-override",
],
}
diff --git a/libs/binder/ndk/tests/binderVendorDoubleLoadTest.cpp b/libs/binder/ndk/tests/binderVendorDoubleLoadTest.cpp
index 43b2cb8..66be94f 100644
--- a/libs/binder/ndk/tests/binderVendorDoubleLoadTest.cpp
+++ b/libs/binder/ndk/tests/binderVendorDoubleLoadTest.cpp
@@ -18,8 +18,6 @@
#include <aidl/BnBinderVendorDoubleLoadTest.h>
#include <aidl/android/os/IServiceManager.h>
#include <android-base/logging.h>
-#include <android-base/properties.h>
-#include <android-base/strings.h>
#include <android/binder_ibinder.h>
#include <android/binder_manager.h>
#include <android/binder_process.h>
@@ -30,13 +28,9 @@
#include <binder/Stability.h>
#include <binder/Status.h>
#include <gtest/gtest.h>
-
#include <sys/prctl.h>
using namespace android;
-using ::android::base::EndsWith;
-using ::android::base::GetProperty;
-using ::android::base::Split;
using ::android::binder::Status;
using ::android::internal::Stability;
using ::ndk::ScopedAStatus;
diff --git a/libs/binder/ndk/tests/iface.cpp b/libs/binder/ndk/tests/iface.cpp
index ca92727..08b857f 100644
--- a/libs/binder/ndk/tests/iface.cpp
+++ b/libs/binder/ndk/tests/iface.cpp
@@ -20,6 +20,8 @@
#include <android/binder_auto_utils.h>
+#include "../../Utils.h"
+
using ::android::sp;
using ::android::wp;
@@ -157,10 +159,9 @@
}
sp<IFoo> IFoo::getService(const char* instance, AIBinder** outBinder) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
AIBinder* binder = AServiceManager_getService(instance); // maybe nullptr
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
if (binder == nullptr) {
return nullptr;
}
diff --git a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp
index cd758db..f518a22 100644
--- a/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp
+++ b/libs/binder/ndk/tests/libbinder_ndk_unit_test.cpp
@@ -34,6 +34,7 @@
#include <binder/IServiceManager.h>
#include <binder/IShellCallback.h>
#include <sys/prctl.h>
+#include <sys/socket.h>
#include <chrono>
#include <condition_variable>
@@ -41,6 +42,7 @@
#include <mutex>
#include <thread>
+#include "../Utils.h"
#include "android/binder_ibinder.h"
using namespace android;
@@ -68,21 +70,21 @@
};
class MyBinderNdkUnitTest : public aidl::BnBinderNdkUnitTest {
- ndk::ScopedAStatus repeatInt(int32_t in, int32_t* out) {
+ ndk::ScopedAStatus repeatInt(int32_t in, int32_t* out) override {
*out = in;
return ndk::ScopedAStatus::ok();
}
- ndk::ScopedAStatus takeInterface(const std::shared_ptr<aidl::IEmpty>& empty) {
+ ndk::ScopedAStatus takeInterface(const std::shared_ptr<aidl::IEmpty>& empty) override {
(void)empty;
return ndk::ScopedAStatus::ok();
}
- ndk::ScopedAStatus forceFlushCommands() {
+ ndk::ScopedAStatus forceFlushCommands() override {
// warning: this is assuming that libbinder_ndk is using the same copy
// of libbinder that we are.
android::IPCThreadState::self()->flushCommands();
return ndk::ScopedAStatus::ok();
}
- ndk::ScopedAStatus getsRequestedSid(bool* out) {
+ ndk::ScopedAStatus getsRequestedSid(bool* out) override {
const char* sid = AIBinder_getCallingSid();
std::cout << "Got security context: " << (sid ?: "null") << std::endl;
*out = sid != nullptr;
@@ -96,11 +98,11 @@
fsync(out);
return STATUS_OK;
}
- ndk::ScopedAStatus forcePersist(bool persist) {
+ ndk::ScopedAStatus forcePersist(bool persist) override {
AServiceManager_forceLazyServicesPersist(persist);
return ndk::ScopedAStatus::ok();
}
- ndk::ScopedAStatus setCustomActiveServicesCallback() {
+ ndk::ScopedAStatus setCustomActiveServicesCallback() override {
AServiceManager_setActiveServicesCallback(activeServicesCallback, this);
return ndk::ScopedAStatus::ok();
}
@@ -341,10 +343,9 @@
// libbinder across processes to the NDK service which doesn't implement
// shell
static const sp<android::IServiceManager> sm(android::defaultServiceManager());
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
sp<IBinder> testService = sm->getService(String16(IFoo::kSomeInstanceName));
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
Vector<String16> argsVec;
EXPECT_EQ(OK, IBinder::shellCommand(testService, STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO,
@@ -387,10 +388,9 @@
// checkService on it, since the other process serving it might not be started yet.
{
// getService, not waitForService, to take advantage of timeout
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
auto binder = ndk::SpAIBinder(AServiceManager_getService(IFoo::kSomeInstanceName));
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
ASSERT_NE(nullptr, binder.get());
}
@@ -424,7 +424,7 @@
// 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);
+ EXPECT_EQ(count, hasLight ? 1u : 0u);
}
TEST(NdkBinder, GetLazyService) {
@@ -514,7 +514,7 @@
// may reference other cookie members
(*funcs->onDeath)();
-};
+}
void LambdaOnUnlink(void* cookie) {
auto funcs = static_cast<DeathRecipientCookie*>(cookie);
(*funcs->onUnlink)();
@@ -522,7 +522,7 @@
// may reference other cookie members
delete funcs;
-};
+}
TEST(NdkBinder, DeathRecipient) {
using namespace std::chrono_literals;
@@ -700,7 +700,7 @@
void LambdaOnUnlinkMultiple(void* cookie) {
auto funcs = static_cast<DeathRecipientCookie*>(cookie);
(*funcs->onUnlink)();
-};
+}
TEST(NdkBinder, DeathRecipientMultipleLinks) {
using namespace std::chrono_literals;
@@ -732,7 +732,7 @@
ndk::ScopedAIBinder_DeathRecipient recipient(AIBinder_DeathRecipient_new(LambdaOnDeath));
AIBinder_DeathRecipient_setOnUnlinked(recipient.get(), LambdaOnUnlinkMultiple);
- for (int32_t i = 0; i < kNumberOfLinksToDeath; i++) {
+ for (uint32_t i = 0; i < kNumberOfLinksToDeath; i++) {
EXPECT_EQ(STATUS_OK,
AIBinder_linkToDeath(binder.get(), recipient.get(), static_cast<void*>(cookie)));
}
@@ -744,14 +744,13 @@
EXPECT_TRUE(unlinkCv.wait_for(lockUnlink, 5s, [&] { return unlinkReceived; }))
<< "countdown: " << countdown;
EXPECT_TRUE(unlinkReceived);
- EXPECT_EQ(countdown, 0);
+ EXPECT_EQ(countdown, 0u);
}
TEST(NdkBinder, RetrieveNonNdkService) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
AIBinder* binder = AServiceManager_getService(kExistingNonNdkService);
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
ASSERT_NE(nullptr, binder);
EXPECT_TRUE(AIBinder_isRemote(binder));
EXPECT_TRUE(AIBinder_isAlive(binder));
@@ -765,10 +764,9 @@
}
TEST(NdkBinder, LinkToDeath) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
AIBinder* binder = AServiceManager_getService(kExistingNonNdkService);
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
ASSERT_NE(nullptr, binder);
AIBinder_DeathRecipient* recipient = AIBinder_DeathRecipient_new(OnBinderDeath);
@@ -798,10 +796,9 @@
}
TEST(NdkBinder, SetInheritRtNonLocal) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
AIBinder* binder = AServiceManager_getService(kExistingNonNdkService);
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
ASSERT_NE(binder, nullptr);
ASSERT_TRUE(AIBinder_isRemote(binder));
@@ -837,14 +834,13 @@
}
TEST(NdkBinder, EqualityOfRemoteBinderPointer) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
AIBinder* binderA = AServiceManager_getService(kExistingNonNdkService);
ASSERT_NE(nullptr, binderA);
AIBinder* binderB = AServiceManager_getService(kExistingNonNdkService);
ASSERT_NE(nullptr, binderB);
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
EXPECT_EQ(binderA, binderB);
@@ -858,10 +854,9 @@
}
TEST(NdkBinder, ABpBinderRefCount) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
AIBinder* binder = AServiceManager_getService(kExistingNonNdkService);
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
AIBinder_Weak* wBinder = AIBinder_Weak_new(binder);
ASSERT_NE(nullptr, binder);
@@ -884,10 +879,9 @@
}
TEST(NdkBinder, RequestedSidWorks) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
ndk::SpAIBinder binder(AServiceManager_getService(kBinderNdkUnitTestService));
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
std::shared_ptr<aidl::IBinderNdkUnitTest> service =
aidl::IBinderNdkUnitTest::fromBinder(binder);
@@ -910,10 +904,9 @@
std::shared_ptr<MyEmpty> empty = ndk::SharedRefBase::make<MyEmpty>();
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
ndk::SpAIBinder binder(AServiceManager_getService(kBinderNdkUnitTestService));
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
std::shared_ptr<aidl::IBinderNdkUnitTest> service =
aidl::IBinderNdkUnitTest::fromBinder(binder);
@@ -934,14 +927,11 @@
}
TEST(NdkBinder, ConvertToPlatformBinder) {
- for (const ndk::SpAIBinder& binder :
- {// remote
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- ndk::SpAIBinder(AServiceManager_getService(kBinderNdkUnitTestService)),
-#pragma clang diagnostic pop
- // local
- ndk::SharedRefBase::make<MyBinderNdkUnitTest>()->asBinder()}) {
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
+ ndk::SpAIBinder remoteBinder(AServiceManager_getService(kBinderNdkUnitTestService));
+ LIBBINDER_IGNORE_END()
+ auto localBinder = ndk::SharedRefBase::make<MyBinderNdkUnitTest>()->asBinder();
+ for (const ndk::SpAIBinder& binder : {remoteBinder, localBinder}) {
// convert to platform binder
EXPECT_NE(binder, nullptr);
sp<IBinder> platformBinder = AIBinder_toPlatformBinder(binder.get());
@@ -970,14 +960,11 @@
}
TEST(NdkBinder, GetAndVerifyScopedAIBinder_Weak) {
- for (const ndk::SpAIBinder& binder :
- {// remote
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
- ndk::SpAIBinder(AServiceManager_getService(kBinderNdkUnitTestService)),
-#pragma clang diagnostic pop
- // local
- ndk::SharedRefBase::make<MyBinderNdkUnitTest>()->asBinder()}) {
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
+ ndk::SpAIBinder remoteBinder(AServiceManager_getService(kBinderNdkUnitTestService));
+ LIBBINDER_IGNORE_END()
+ auto localBinder = ndk::SharedRefBase::make<MyBinderNdkUnitTest>()->asBinder();
+ for (const ndk::SpAIBinder& binder : {remoteBinder, localBinder}) {
// get a const ScopedAIBinder_Weak and verify promote
EXPECT_NE(binder.get(), nullptr);
const ndk::ScopedAIBinder_Weak wkAIBinder =
@@ -1046,7 +1033,7 @@
sp<MyResultReceiver> resultReceiver = new MyResultReceiver();
Vector<String16> argsVec;
- for (int i = 0; i < args.size(); i++) {
+ for (size_t i = 0; i < args.size(); i++) {
argsVec.add(String16(args[i]));
}
status_t error = IBinder::shellCommand(unitTestService, inFd[0], outFd[0], errFd[0], argsVec,
@@ -1070,10 +1057,9 @@
TEST(NdkBinder, UseHandleShellCommand) {
static const sp<android::IServiceManager> sm(android::defaultServiceManager());
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
sp<IBinder> testService = sm->getService(String16(kBinderNdkUnitTestService));
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
EXPECT_EQ("", shellCmdToString(testService, {}));
EXPECT_EQ("", shellCmdToString(testService, {"", ""}));
@@ -1083,10 +1069,9 @@
TEST(NdkBinder, FlaggedServiceAccessible) {
static const sp<android::IServiceManager> sm(android::defaultServiceManager());
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
sp<IBinder> testService = sm->getService(String16(kBinderNdkUnitTestServiceFlagged));
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
ASSERT_NE(nullptr, testService);
}
diff --git a/libs/binder/rust/src/binder.rs b/libs/binder/rust/src/binder.rs
index e34d31e..9a252b8 100644
--- a/libs/binder/rust/src/binder.rs
+++ b/libs/binder/rust/src/binder.rs
@@ -768,14 +768,14 @@
$interface:path[$descriptor:expr] {
native: $native:ident($on_transact:path),
proxy: $proxy:ident,
- $(async: $async_interface:ident,)?
+ $(async: $async_interface:ident $(($try_into_local_async:ident))?,)?
}
} => {
$crate::declare_binder_interface! {
$interface[$descriptor] {
native: $native($on_transact),
proxy: $proxy {},
- $(async: $async_interface,)?
+ $(async: $async_interface $(($try_into_local_async))?,)?
stability: $crate::binder_impl::Stability::default(),
}
}
@@ -785,7 +785,7 @@
$interface:path[$descriptor:expr] {
native: $native:ident($on_transact:path),
proxy: $proxy:ident,
- $(async: $async_interface:ident,)?
+ $(async: $async_interface:ident $(($try_into_local_async:ident))?,)?
stability: $stability:expr,
}
} => {
@@ -793,7 +793,7 @@
$interface[$descriptor] {
native: $native($on_transact),
proxy: $proxy {},
- $(async: $async_interface,)?
+ $(async: $async_interface $(($try_into_local_async))?,)?
stability: $stability,
}
}
@@ -805,7 +805,7 @@
proxy: $proxy:ident {
$($fname:ident: $fty:ty = $finit:expr),*
},
- $(async: $async_interface:ident,)?
+ $(async: $async_interface:ident $(($try_into_local_async:ident))?,)?
}
} => {
$crate::declare_binder_interface! {
@@ -814,7 +814,7 @@
proxy: $proxy {
$($fname: $fty = $finit),*
},
- $(async: $async_interface,)?
+ $(async: $async_interface $(($try_into_local_async))?,)?
stability: $crate::binder_impl::Stability::default(),
}
}
@@ -826,7 +826,7 @@
proxy: $proxy:ident {
$($fname:ident: $fty:ty = $finit:expr),*
},
- $(async: $async_interface:ident,)?
+ $(async: $async_interface:ident $(($try_into_local_async:ident))?,)?
stability: $stability:expr,
}
} => {
@@ -838,7 +838,7 @@
proxy: $proxy {
$($fname: $fty = $finit),*
},
- $(async: $async_interface,)?
+ $(async: $async_interface $(($try_into_local_async))?,)?
stability: $stability,
}
}
@@ -854,7 +854,7 @@
$($fname:ident: $fty:ty = $finit:expr),*
},
- $( async: $async_interface:ident, )?
+ $(async: $async_interface:ident $(($try_into_local_async:ident))?,)?
stability: $stability:expr,
}
@@ -1043,6 +1043,24 @@
}
if ibinder.associate_class(<$native as $crate::binder_impl::Remotable>::get_class()) {
+ let service: std::result::Result<$crate::binder_impl::Binder<$native>, $crate::StatusCode> =
+ std::convert::TryFrom::try_from(ibinder.clone());
+ $(
+ // This part is only generated if the user of the macro specifies that the
+ // trait has an `try_into_local_async` implementation.
+ if let Ok(service) = service {
+ if let Some(async_service) = $native::$try_into_local_async(service) {
+ // We were able to associate with our expected class,
+ // the service is local, and the local service is async.
+ return Ok(async_service);
+ }
+ // The service is local but not async. Fall back to treating it as a
+ // remote service. This means that calls to this local service have an
+ // extra performance cost due to serialization, but async handle to
+ // non-async server is considered a rare case, so this is okay.
+ }
+ )?
+ // Treat service as remote.
return Ok($crate::Strong::new(Box::new(<$proxy as $crate::binder_impl::Proxy>::from_binder(ibinder)?)));
}
diff --git a/libs/binder/rust/tests/integration.rs b/libs/binder/rust/tests/integration.rs
index 15ae56f..5359832 100644
--- a/libs/binder/rust/tests/integration.rs
+++ b/libs/binder/rust/tests/integration.rs
@@ -182,7 +182,7 @@
proxy: BpTest {
x: i32 = 100
},
- async: IATest,
+ async: IATest(try_into_local_async),
}
}
@@ -323,6 +323,14 @@
}
}
+impl BnTest {
+ fn try_into_local_async<P: binder::BinderAsyncPool + 'static>(
+ me: Binder<BnTest>,
+ ) -> Option<binder::Strong<dyn IATest<P>>> {
+ Some(binder::Strong::new(Box::new(me) as _))
+ }
+}
+
/// Trivial testing binder interface
pub trait ITestSameDescriptor: Interface {}
@@ -900,6 +908,19 @@
assert_eq!(service.test().unwrap(), service_name);
}
+ #[tokio::test]
+ async fn reassociate_rust_binder_async() {
+ let service_name = "testing_service";
+ let service_ibinder =
+ BnTest::new_binder(TestService::new(service_name), BinderFeatures::default())
+ .as_binder();
+
+ let service: Strong<dyn IATest<Tokio>> =
+ service_ibinder.into_interface().expect("Could not reassociate the generic ibinder");
+
+ assert_eq!(service.test().await.unwrap(), service_name);
+ }
+
#[test]
fn weak_binder_upgrade() {
let service_name = "testing_service";
diff --git a/libs/binder/tests/binderClearBufTest.cpp b/libs/binder/tests/binderClearBufTest.cpp
index 3230a3f..63254cd 100644
--- a/libs/binder/tests/binderClearBufTest.cpp
+++ b/libs/binder/tests/binderClearBufTest.cpp
@@ -75,10 +75,9 @@
};
TEST(BinderClearBuf, ClearKernelBuffer) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
sp<IBinder> binder = defaultServiceManager()->getService(kServerName);
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
ASSERT_NE(nullptr, binder);
std::string replyBuffer;
diff --git a/libs/binder/tests/binderDriverInterfaceTest.cpp b/libs/binder/tests/binderDriverInterfaceTest.cpp
index cf23a46..7be4f21 100644
--- a/libs/binder/tests/binderDriverInterfaceTest.cpp
+++ b/libs/binder/tests/binderDriverInterfaceTest.cpp
@@ -19,11 +19,12 @@
#include <stdio.h>
#include <stdlib.h>
+#include <binder/IBinder.h>
#include <gtest/gtest.h>
#include <linux/android/binder.h>
-#include <binder/IBinder.h>
-#include <sys/mman.h>
#include <poll.h>
+#include <sys/ioctl.h>
+#include <sys/mman.h>
#define BINDER_DEV_NAME "/dev/binder"
@@ -93,8 +94,9 @@
ret = ioctl(m_binderFd, cmd, arg);
EXPECT_EQ(expect_ret, ret);
if (ret < 0) {
- if (errno != accept_errno)
+ if (errno != accept_errno) {
EXPECT_EQ(expect_errno, errno);
+ }
}
}
void binderTestIoctlErr2(int cmd, void *arg, int expect_errno, int accept_errno) {
@@ -274,12 +276,15 @@
binderTestIoctl(BINDER_WRITE_READ, &bwr);
}
EXPECT_EQ(offsetof(typeof(br), pad), bwr.read_consumed);
- if (bwr.read_consumed > offsetof(typeof(br), cmd0))
+ if (bwr.read_consumed > offsetof(typeof(br), cmd0)) {
EXPECT_EQ(BR_NOOP, br.cmd0);
- if (bwr.read_consumed > offsetof(typeof(br), cmd1))
+ }
+ if (bwr.read_consumed > offsetof(typeof(br), cmd1)) {
EXPECT_EQ(BR_TRANSACTION_COMPLETE, br.cmd1);
- if (bwr.read_consumed > offsetof(typeof(br), cmd2))
+ }
+ if (bwr.read_consumed > offsetof(typeof(br), cmd2)) {
EXPECT_EQ(BR_REPLY, br.cmd2);
+ }
if (bwr.read_consumed >= offsetof(typeof(br), pad)) {
EXPECT_EQ(0u, br.arg2.target.ptr);
EXPECT_EQ(0u, br.arg2.cookie);
diff --git a/libs/binder/tests/binderLibTest.cpp b/libs/binder/tests/binderLibTest.cpp
index 00406ed..9b1ba01 100644
--- a/libs/binder/tests/binderLibTest.cpp
+++ b/libs/binder/tests/binderLibTest.cpp
@@ -29,7 +29,6 @@
#include <android-base/properties.h>
#include <android-base/result-gmock.h>
-#include <android-base/strings.h>
#include <binder/Binder.h>
#include <binder/BpBinder.h>
#include <binder/Functional.h>
@@ -48,16 +47,14 @@
#include <sys/socket.h>
#include <sys/un.h>
+#include "../Utils.h"
#include "../binder_module.h"
-#define ARRAY_SIZE(array) (sizeof array / sizeof array[0])
-
using namespace android;
using namespace android::binder::impl;
using namespace std::string_literals;
using namespace std::chrono_literals;
using android::base::testing::HasValue;
-using android::base::testing::Ok;
using android::binder::Status;
using android::binder::unique_fd;
using testing::ExplainMatchResult;
@@ -218,10 +215,9 @@
sp<IServiceManager> sm = defaultServiceManager();
//printf("%s: pid %d, get service\n", __func__, m_pid);
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
m_server = sm->getService(binderLibTestServiceName);
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
ASSERT_TRUE(m_server != nullptr);
//printf("%s: pid %d, get service done\n", __func__, m_pid);
}
@@ -568,7 +564,7 @@
TEST_F(BinderLibTest, SetError) {
int32_t testValue[] = { 0, -123, 123 };
- for (size_t i = 0; i < ARRAY_SIZE(testValue); i++) {
+ for (size_t i = 0; i < countof(testValue); i++) {
Parcel data, reply;
data.writeInt32(testValue[i]);
EXPECT_THAT(m_server->transact(BINDER_LIB_TEST_SET_ERROR_TRANSACTION, data, &reply),
@@ -599,8 +595,8 @@
Parcel data, reply;
int32_t serverId[3];
- data.writeInt32(ARRAY_SIZE(serverId));
- for (size_t i = 0; i < ARRAY_SIZE(serverId); i++) {
+ data.writeInt32(countof(serverId));
+ for (size_t i = 0; i < countof(serverId); i++) {
sp<IBinder> server;
BinderLibTestBundle datai;
@@ -618,7 +614,7 @@
EXPECT_EQ(0, id);
ASSERT_THAT(reply.readInt32(&count), StatusEq(NO_ERROR));
- EXPECT_EQ(ARRAY_SIZE(serverId), (size_t)count);
+ EXPECT_EQ(countof(serverId), (size_t)count);
for (size_t i = 0; i < (size_t)count; i++) {
BinderLibTestBundle replyi(&reply);
@@ -638,8 +634,8 @@
Parcel data, reply;
int32_t serverId[3];
- data.writeInt32(ARRAY_SIZE(serverId));
- for (size_t i = 0; i < ARRAY_SIZE(serverId); i++) {
+ data.writeInt32(countof(serverId));
+ for (size_t i = 0; i < countof(serverId); i++) {
sp<IBinder> server;
BinderLibTestBundle datai;
BinderLibTestBundle datai2;
@@ -664,7 +660,7 @@
EXPECT_EQ(0, id);
ASSERT_THAT(reply.readInt32(&count), StatusEq(NO_ERROR));
- EXPECT_EQ(ARRAY_SIZE(serverId), (size_t)count);
+ EXPECT_EQ(countof(serverId), (size_t)count);
for (size_t i = 0; i < (size_t)count; i++) {
int32_t counti;
@@ -2114,10 +2110,9 @@
if (index == 0) {
ret = sm->addService(binderLibTestServiceName, testService);
} else {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
sp<IBinder> server = sm->getService(binderLibTestServiceName);
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
Parcel data, reply;
data.writeInt32(index);
data.writeStrongBinder(testService);
diff --git a/libs/binder/tests/binderStabilityTest.cpp b/libs/binder/tests/binderStabilityTest.cpp
index 3d99358..7a8f48e 100644
--- a/libs/binder/tests/binderStabilityTest.cpp
+++ b/libs/binder/tests/binderStabilityTest.cpp
@@ -27,8 +27,9 @@
#include <sys/prctl.h>
-#include "aidl/BnBinderStabilityTest.h"
+#include "../Utils.h"
#include "BnBinderStabilityTest.h"
+#include "aidl/BnBinderStabilityTest.h"
using namespace android;
using namespace ndk;
@@ -155,10 +156,9 @@
}
TEST(BinderStability, ForceDowngradeToVendorStability) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
sp<IBinder> serverBinder = android::defaultServiceManager()->getService(kSystemStabilityServer);
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
auto server = interface_cast<IBinderStabilityTest>(serverBinder);
ASSERT_NE(nullptr, server.get());
@@ -209,10 +209,9 @@
EXPECT_EQ(connectionInfo, std::nullopt);
}
TEST(BinderStability, CantCallVendorBinderInSystemContext) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
sp<IBinder> serverBinder = android::defaultServiceManager()->getService(kSystemStabilityServer);
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
auto server = interface_cast<IBinderStabilityTest>(serverBinder);
ASSERT_NE(nullptr, server.get());
@@ -316,11 +315,10 @@
extern "C" void AIBinder_markVendorStability(AIBinder* binder); // <- BAD DO NOT COPY
TEST(BinderStability, NdkCantCallVendorBinderInSystemContext) {
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+ LIBBINDER_IGNORE("-Wdeprecated-declarations")
SpAIBinder binder = SpAIBinder(AServiceManager_getService(
String8(kSystemStabilityServer).c_str()));
-#pragma clang diagnostic pop
+ LIBBINDER_IGNORE_END()
std::shared_ptr<aidl::IBinderStabilityTest> remoteServer =
aidl::IBinderStabilityTest::fromBinder(binder);
diff --git a/libs/binder/tests/binder_sdk/binder_sdk_docker_test.sh b/libs/binder/tests/binder_sdk/binder_sdk_docker_test.sh
index 0eca846..9ea8cb3 100755
--- a/libs/binder/tests/binder_sdk/binder_sdk_docker_test.sh
+++ b/libs/binder/tests/binder_sdk/binder_sdk_docker_test.sh
@@ -57,7 +57,7 @@
exit 1
fi
${ANDROID_BUILD_TOP}/build/soong/soong_ui.bash --make-mode binder_sdk
- BINDER_SDK_ZIP="${ANDROID_BUILD_TOP}/out/soong/.intermediates/frameworks/native/libs/binder/binder_sdk/linux_glibc_x86_64/*/binder_sdk.zip"
+ BINDER_SDK_ZIP="${ANDROID_BUILD_TOP}/out/soong/.intermediates/frameworks/native/libs/binder/binder_sdk/linux_glibc_x86_64/binder_sdk.zip"
DOCKER_PATH="$(dirname $(ls -1 ${BINDER_SDK_ZIP} | head --lines=1))"
fi
diff --git a/libs/binder/tests/unit_fuzzers/BpBinderFuzz.cpp b/libs/binder/tests/unit_fuzzers/BpBinderFuzz.cpp
index a6fd487..bc0d5af 100644
--- a/libs/binder/tests/unit_fuzzers/BpBinderFuzz.cpp
+++ b/libs/binder/tests/unit_fuzzers/BpBinderFuzz.cpp
@@ -36,7 +36,9 @@
FuzzedDataProvider fdp(data, size);
std::string addr = std::string(getenv("TMPDIR") ?: "/tmp") + "/binderRpcBenchmark";
- (void)unlink(addr.c_str());
+ if (0 != unlink(addr.c_str()) && errno != ENOENT) {
+ LOG(WARNING) << "Could not unlink: " << strerror(errno);
+ }
sp<RpcServer> server = RpcServer::make();
diff --git a/libs/gui/LayerState.cpp b/libs/gui/LayerState.cpp
index 3745805..307ae39 100644
--- a/libs/gui/LayerState.cpp
+++ b/libs/gui/LayerState.cpp
@@ -177,6 +177,7 @@
}
SAFE_PARCEL(output.write, stretchEffect);
+ SAFE_PARCEL(output.writeParcelable, edgeExtensionParameters);
SAFE_PARCEL(output.write, bufferCrop);
SAFE_PARCEL(output.write, destinationFrame);
SAFE_PARCEL(output.writeInt32, static_cast<uint32_t>(trustedOverlay));
@@ -306,6 +307,7 @@
}
SAFE_PARCEL(input.read, stretchEffect);
+ SAFE_PARCEL(input.readParcelable, &edgeExtensionParameters);
SAFE_PARCEL(input.read, bufferCrop);
SAFE_PARCEL(input.read, destinationFrame);
uint32_t trustedOverlayInt;
@@ -682,6 +684,10 @@
what |= eStretchChanged;
stretchEffect = other.stretchEffect;
}
+ if (other.what & eEdgeExtensionChanged) {
+ what |= eEdgeExtensionChanged;
+ edgeExtensionParameters = other.edgeExtensionParameters;
+ }
if (other.what & eBufferCropChanged) {
what |= eBufferCropChanged;
bufferCrop = other.bufferCrop;
@@ -783,6 +789,7 @@
CHECK_DIFF(diff, eAutoRefreshChanged, other, autoRefresh);
CHECK_DIFF(diff, eTrustedOverlayChanged, other, trustedOverlay);
CHECK_DIFF(diff, eStretchChanged, other, stretchEffect);
+ CHECK_DIFF(diff, eEdgeExtensionChanged, other, edgeExtensionParameters);
CHECK_DIFF(diff, eBufferCropChanged, other, bufferCrop);
CHECK_DIFF(diff, eDestinationFrameChanged, other, destinationFrame);
if (other.what & eProducerDisconnect) diff |= eProducerDisconnect;
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 902684c..88d3a7c 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -22,6 +22,7 @@
#include <android/gui/BnWindowInfosReportedListener.h>
#include <android/gui/DisplayState.h>
+#include <android/gui/EdgeExtensionParameters.h>
#include <android/gui/ISurfaceComposerClient.h>
#include <android/gui/IWindowInfosListener.h>
#include <android/gui/TrustedPresentationThresholds.h>
@@ -2330,6 +2331,19 @@
return *this;
}
+SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setEdgeExtensionEffect(
+ const sp<SurfaceControl>& sc, const gui::EdgeExtensionParameters& effect) {
+ layer_state_t* s = getLayerState(sc);
+ if (!s) {
+ mStatus = BAD_INDEX;
+ return *this;
+ }
+
+ s->what |= layer_state_t::eEdgeExtensionChanged;
+ s->edgeExtensionParameters = effect;
+ return *this;
+}
+
SurfaceComposerClient::Transaction& SurfaceComposerClient::Transaction::setBufferCrop(
const sp<SurfaceControl>& sc, const Rect& bufferCrop) {
layer_state_t* s = getLayerState(sc);
diff --git a/libs/gui/aidl/android/gui/EdgeExtensionParameters.aidl b/libs/gui/aidl/android/gui/EdgeExtensionParameters.aidl
new file mode 100644
index 0000000..44f4259
--- /dev/null
+++ b/libs/gui/aidl/android/gui/EdgeExtensionParameters.aidl
@@ -0,0 +1,27 @@
+/*
+ * Copyright 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.gui;
+
+
+/** @hide */
+parcelable EdgeExtensionParameters {
+ // These represent the translation of the window as requested by the animation
+ boolean extendRight;
+ boolean extendLeft;
+ boolean extendTop;
+ boolean extendBottom;
+}
\ No newline at end of file
diff --git a/libs/gui/include/gui/LayerState.h b/libs/gui/include/gui/LayerState.h
index 5f2f8dc..3fb1894 100644
--- a/libs/gui/include/gui/LayerState.h
+++ b/libs/gui/include/gui/LayerState.h
@@ -29,6 +29,7 @@
#include <math/mat4.h>
#include <android/gui/DropInputMode.h>
+#include <android/gui/EdgeExtensionParameters.h>
#include <android/gui/FocusRequest.h>
#include <android/gui/TrustedOverlay.h>
@@ -218,6 +219,7 @@
eTrustedOverlayChanged = 0x4000'00000000,
eDropInputModeChanged = 0x8000'00000000,
eExtendedRangeBrightnessChanged = 0x10000'00000000,
+ eEdgeExtensionChanged = 0x20000'00000000,
};
layer_state_t();
@@ -241,7 +243,7 @@
layer_state_t::eCropChanged | layer_state_t::eDestinationFrameChanged |
layer_state_t::eMatrixChanged | layer_state_t::ePositionChanged |
layer_state_t::eTransformToDisplayInverseChanged |
- layer_state_t::eTransparentRegionChanged;
+ layer_state_t::eTransparentRegionChanged | layer_state_t::eEdgeExtensionChanged;
// Buffer and related updates.
static constexpr uint64_t BUFFER_CHANGES = layer_state_t::eApiChanged |
@@ -393,6 +395,9 @@
// Stretch effect to be applied to this layer
StretchEffect stretchEffect;
+ // Edge extension effect to be applied to this layer
+ gui::EdgeExtensionParameters edgeExtensionParameters;
+
Rect bufferCrop;
Rect destinationFrame;
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 88c0c53..a10283b 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -35,6 +35,7 @@
#include <ui/BlurRegion.h>
#include <ui/ConfigStoreTypes.h>
#include <ui/DisplayedFrameStats.h>
+#include <ui/EdgeExtensionEffect.h>
#include <ui/FrameStats.h>
#include <ui/GraphicTypes.h>
#include <ui/PixelFormat.h>
@@ -744,6 +745,17 @@
Transaction& setStretchEffect(const sp<SurfaceControl>& sc,
const StretchEffect& stretchEffect);
+ /**
+ * Provides the edge extension effect configured on a container that the
+ * surface is rendered within.
+ * @param sc target surface the edge extension should be applied to
+ * @param effect the corresponding EdgeExtensionParameters to be applied
+ * to the surface.
+ * @return The transaction being constructed
+ */
+ Transaction& setEdgeExtensionEffect(const sp<SurfaceControl>& sc,
+ const gui::EdgeExtensionParameters& effect);
+
Transaction& setBufferCrop(const sp<SurfaceControl>& sc, const Rect& bufferCrop);
Transaction& setDestinationFrame(const sp<SurfaceControl>& sc,
const Rect& destinationFrame);
diff --git a/libs/renderengine/Android.bp b/libs/renderengine/Android.bp
index 4a04467..ecf98c6 100644
--- a/libs/renderengine/Android.bp
+++ b/libs/renderengine/Android.bp
@@ -105,6 +105,7 @@
"skia/filters/LinearEffect.cpp",
"skia/filters/MouriMap.cpp",
"skia/filters/StretchShaderFactory.cpp",
+ "skia/filters/EdgeExtensionShaderFactory.cpp",
],
}
diff --git a/libs/renderengine/include/renderengine/LayerSettings.h b/libs/renderengine/include/renderengine/LayerSettings.h
index 8ac0af4..859ae8b 100644
--- a/libs/renderengine/include/renderengine/LayerSettings.h
+++ b/libs/renderengine/include/renderengine/LayerSettings.h
@@ -31,6 +31,7 @@
#include <ui/ShadowSettings.h>
#include <ui/StretchEffect.h>
#include <ui/Transform.h>
+#include "ui/EdgeExtensionEffect.h"
#include <iosfwd>
@@ -134,6 +135,7 @@
mat4 blurRegionTransform = mat4();
StretchEffect stretchEffect;
+ EdgeExtensionEffect edgeExtensionEffect;
// Name associated with the layer for debugging purposes.
std::string name;
@@ -183,7 +185,9 @@
lhs.skipContentDraw == rhs.skipContentDraw && lhs.shadow == rhs.shadow &&
lhs.backgroundBlurRadius == rhs.backgroundBlurRadius &&
lhs.blurRegionTransform == rhs.blurRegionTransform &&
- lhs.stretchEffect == rhs.stretchEffect && lhs.whitePointNits == rhs.whitePointNits;
+ lhs.stretchEffect == rhs.stretchEffect &&
+ lhs.edgeExtensionEffect == rhs.edgeExtensionEffect &&
+ lhs.whitePointNits == rhs.whitePointNits;
}
static inline void PrintTo(const Buffer& settings, ::std::ostream* os) {
@@ -254,6 +258,10 @@
*os << "\n}";
}
+static inline void PrintTo(const EdgeExtensionEffect& effect, ::std::ostream* os) {
+ *os << effect;
+}
+
static inline void PrintTo(const LayerSettings& settings, ::std::ostream* os) {
*os << "LayerSettings for '" << settings.name.c_str() << "' {";
*os << "\n .geometry = ";
@@ -285,6 +293,10 @@
*os << "\n .stretchEffect = ";
PrintTo(settings.stretchEffect, os);
}
+
+ if (settings.edgeExtensionEffect.hasEffect()) {
+ *os << "\n .edgeExtensionEffect = " << settings.edgeExtensionEffect;
+ }
*os << "\n .whitePointNits = " << settings.whitePointNits;
*os << "\n}";
}
diff --git a/libs/renderengine/skia/SkiaRenderEngine.cpp b/libs/renderengine/skia/SkiaRenderEngine.cpp
index 5f37125..a609f2d 100644
--- a/libs/renderengine/skia/SkiaRenderEngine.cpp
+++ b/libs/renderengine/skia/SkiaRenderEngine.cpp
@@ -507,16 +507,24 @@
const RuntimeEffectShaderParameters& parameters) {
// The given surface will be stretched by HWUI via matrix transformation
// which gets similar results for most surfaces
- // Determine later on if we need to leverage the stertch shader within
+ // Determine later on if we need to leverage the stretch shader within
// surface flinger
const auto& stretchEffect = parameters.layer.stretchEffect;
const auto& targetBuffer = parameters.layer.source.buffer.buffer;
+ const auto graphicBuffer = targetBuffer ? targetBuffer->getBuffer() : nullptr;
+
auto shader = parameters.shader;
- if (stretchEffect.hasEffect()) {
- const auto graphicBuffer = targetBuffer ? targetBuffer->getBuffer() : nullptr;
- if (graphicBuffer && shader) {
+ if (graphicBuffer && parameters.shader) {
+ if (stretchEffect.hasEffect()) {
shader = mStretchShaderFactory.createSkShader(shader, stretchEffect);
}
+ // The given surface requires to be filled outside of its buffer bounds if the edge
+ // extension is required
+ const auto& edgeExtensionEffect = parameters.layer.edgeExtensionEffect;
+ if (edgeExtensionEffect.hasEffect()) {
+ shader = mEdgeExtensionShaderFactory.createSkShader(shader, parameters.layer,
+ parameters.imageBounds);
+ }
}
if (parameters.requiresLinearEffect) {
@@ -566,8 +574,6 @@
parameters.layerDimmingRatio, 1.f));
}
- const auto targetBuffer = parameters.layer.source.buffer.buffer;
- const auto graphicBuffer = targetBuffer ? targetBuffer->getBuffer() : nullptr;
const auto hardwareBuffer = graphicBuffer ? graphicBuffer->toAHardwareBuffer() : nullptr;
return createLinearEffectShader(shader, effect, runtimeEffect, std::move(colorTransform),
parameters.display.maxLuminance,
@@ -1039,18 +1045,20 @@
toSkColorSpace(layerDataspace)));
}
- paint.setShader(createRuntimeEffectShader(
- RuntimeEffectShaderParameters{.shader = shader,
- .layer = layer,
- .display = display,
- .undoPremultipliedAlpha = !item.isOpaque &&
- item.usePremultipliedAlpha,
- .requiresLinearEffect = requiresLinearEffect,
- .layerDimmingRatio = dimInLinearSpace
- ? layerDimmingRatio
- : 1.f,
- .outputDataSpace = display.outputDataspace,
- .fakeOutputDataspace = fakeDataspace}));
+ SkRect imageBounds;
+ matrix.mapRect(&imageBounds, SkRect::Make(image->bounds()));
+
+ paint.setShader(createRuntimeEffectShader(RuntimeEffectShaderParameters{
+ .shader = shader,
+ .layer = layer,
+ .display = display,
+ .undoPremultipliedAlpha = !item.isOpaque && item.usePremultipliedAlpha,
+ .requiresLinearEffect = requiresLinearEffect,
+ .layerDimmingRatio = dimInLinearSpace ? layerDimmingRatio : 1.f,
+ .outputDataSpace = display.outputDataspace,
+ .fakeOutputDataspace = fakeDataspace,
+ .imageBounds = imageBounds,
+ }));
// Turn on dithering when dimming beyond this (arbitrary) threshold...
static constexpr float kDimmingThreshold = 0.9f;
@@ -1118,7 +1126,8 @@
.requiresLinearEffect = requiresLinearEffect,
.layerDimmingRatio = layerDimmingRatio,
.outputDataSpace = display.outputDataspace,
- .fakeOutputDataspace = fakeDataspace}));
+ .fakeOutputDataspace = fakeDataspace,
+ .imageBounds = SkRect::MakeEmpty()}));
}
if (layer.disableBlending) {
diff --git a/libs/renderengine/skia/SkiaRenderEngine.h b/libs/renderengine/skia/SkiaRenderEngine.h
index c8f9241..224a1ca 100644
--- a/libs/renderengine/skia/SkiaRenderEngine.h
+++ b/libs/renderengine/skia/SkiaRenderEngine.h
@@ -38,6 +38,7 @@
#include "compat/SkiaGpuContext.h"
#include "debug/SkiaCapture.h"
#include "filters/BlurFilter.h"
+#include "filters/EdgeExtensionShaderFactory.h"
#include "filters/LinearEffect.h"
#include "filters/StretchShaderFactory.h"
@@ -156,6 +157,7 @@
float layerDimmingRatio;
const ui::Dataspace outputDataSpace;
const ui::Dataspace fakeOutputDataspace;
+ const SkRect& imageBounds;
};
sk_sp<SkShader> createRuntimeEffectShader(const RuntimeEffectShaderParameters&);
@@ -175,6 +177,7 @@
AutoBackendTexture::CleanupManager mTextureCleanupMgr GUARDED_BY(mRenderingMutex);
StretchShaderFactory mStretchShaderFactory;
+ EdgeExtensionShaderFactory mEdgeExtensionShaderFactory;
sp<Fence> mLastDrawFence;
BlurFilter* mBlurFilter = nullptr;
diff --git a/libs/renderengine/skia/filters/EdgeExtensionShaderFactory.cpp b/libs/renderengine/skia/filters/EdgeExtensionShaderFactory.cpp
new file mode 100644
index 0000000..1dbcc29
--- /dev/null
+++ b/libs/renderengine/skia/filters/EdgeExtensionShaderFactory.cpp
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#include "EdgeExtensionShaderFactory.h"
+#include <SkPoint.h>
+#include <SkRuntimeEffect.h>
+#include <SkStream.h>
+#include <SkString.h>
+#include "log/log_main.h"
+
+namespace android::renderengine::skia {
+
+static const SkString edgeShader = SkString(R"(
+ uniform shader uContentTexture;
+ uniform vec2 uImgSize;
+
+ // TODO(b/214232209) oobTolerance is temporary and will be removed when the scrollbar will be
+ // hidden during the animation
+ const float oobTolerance = 15;
+ const int blurRadius = 3;
+ const float blurArea = float((2 * blurRadius + 1) * (2 * blurRadius + 1));
+
+ vec4 boxBlur(vec2 p) {
+ vec4 sumColors = vec4(0);
+
+ for (int i = -blurRadius; i <= blurRadius; i++) {
+ for (int j = -blurRadius; j <= blurRadius; j++) {
+ sumColors += uContentTexture.eval(p + vec2(i, j));
+ }
+ }
+ return sumColors / blurArea;
+ }
+
+ vec4 main(vec2 coord) {
+ vec2 nearestTexturePoint = clamp(coord, vec2(0, 0), uImgSize);
+ if (coord == nearestTexturePoint) {
+ return uContentTexture.eval(coord);
+ } else {
+ vec2 samplePoint = nearestTexturePoint + oobTolerance * normalize(
+ nearestTexturePoint - coord);
+ return boxBlur(samplePoint);
+ }
+ }
+)");
+
+sk_sp<SkShader> EdgeExtensionShaderFactory::createSkShader(const sk_sp<SkShader>& inputShader,
+ const LayerSettings& layer,
+ const SkRect& imageBounds) {
+ if (mBuilder == nullptr) {
+ const static SkRuntimeEffect::Result instance = SkRuntimeEffect::MakeForShader(edgeShader);
+ if (!instance.errorText.isEmpty()) {
+ ALOGE("EdgeExtensionShaderFactory terminated with an error: %s",
+ instance.errorText.c_str());
+ return nullptr;
+ }
+ mBuilder = std::make_unique<SkRuntimeShaderBuilder>(instance.effect);
+ }
+ mBuilder->child("uContentTexture") = inputShader;
+ if (imageBounds.isEmpty()) {
+ mBuilder->uniform("uImgSize") = SkPoint{layer.geometry.boundaries.getWidth(),
+ layer.geometry.boundaries.getHeight()};
+ } else {
+ mBuilder->uniform("uImgSize") = SkPoint{imageBounds.width(), imageBounds.height()};
+ }
+ return mBuilder->makeShader();
+}
+} // namespace android::renderengine::skia
\ No newline at end of file
diff --git a/libs/renderengine/skia/filters/EdgeExtensionShaderFactory.h b/libs/renderengine/skia/filters/EdgeExtensionShaderFactory.h
new file mode 100644
index 0000000..b0a8a93
--- /dev/null
+++ b/libs/renderengine/skia/filters/EdgeExtensionShaderFactory.h
@@ -0,0 +1,42 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+#include <SkImage.h>
+#include <SkRect.h>
+#include <SkRuntimeEffect.h>
+#include <SkShader.h>
+#include <renderengine/LayerSettings.h>
+#include <ui/EdgeExtensionEffect.h>
+
+namespace android::renderengine::skia {
+
+/**
+ * This shader is designed to prolong the texture of a surface whose bounds have been extended over
+ * the size of the texture. This shader is similar to the default clamp, but adds a blur effect and
+ * samples from close to the edge (compared to on the edge) to avoid weird artifacts when elements
+ * (in particular, scrollbars) touch the edge.
+ */
+class EdgeExtensionShaderFactory {
+public:
+ sk_sp<SkShader> createSkShader(const sk_sp<SkShader>& inputShader, const LayerSettings& layer,
+ const SkRect& imageBounds);
+
+private:
+ std::unique_ptr<SkRuntimeShaderBuilder> mBuilder;
+};
+} // namespace android::renderengine::skia
diff --git a/libs/renderengine/skia/filters/MouriMap.cpp b/libs/renderengine/skia/filters/MouriMap.cpp
index cc25fcc..b458939 100644
--- a/libs/renderengine/skia/filters/MouriMap.cpp
+++ b/libs/renderengine/skia/filters/MouriMap.cpp
@@ -35,7 +35,7 @@
float maximum = 0.0;
for (int y = 0; y < 16; y++) {
for (int x = 0; x < 16; x++) {
- float3 linear = toLinearSrgb(bitmap.eval(xy * 16 + vec2(x, y)).rgb) * hdrSdrRatio;
+ float3 linear = toLinearSrgb(bitmap.eval((xy - 0.5) * 16 + 0.5 + vec2(x, y)).rgb) * hdrSdrRatio;
float maxRGB = max(linear.r, max(linear.g, linear.b));
maximum = max(maximum, log2(max(maxRGB, 1.0)));
}
@@ -49,7 +49,7 @@
float maximum = 0.0;
for (int y = 0; y < 8; y++) {
for (int x = 0; x < 8; x++) {
- maximum = max(maximum, bitmap.eval(xy * 8 + vec2(x, y)).r);
+ maximum = max(maximum, bitmap.eval((xy - 0.5) * 8 + 0.5 + vec2(x, y)).r);
}
}
return float4(float3(maximum), 1.0);
diff --git a/libs/renderengine/tests/RenderEngineTest.cpp b/libs/renderengine/tests/RenderEngineTest.cpp
index 0324135..b5cc65f 100644
--- a/libs/renderengine/tests/RenderEngineTest.cpp
+++ b/libs/renderengine/tests/RenderEngineTest.cpp
@@ -34,9 +34,12 @@
#include <ui/ColorSpace.h>
#include <ui/PixelFormat.h>
+#include <algorithm>
#include <chrono>
#include <condition_variable>
+#include <filesystem>
#include <fstream>
+#include <system_error>
#include "../skia/SkiaGLRenderEngine.h"
#include "../skia/SkiaVkRenderEngine.h"
@@ -259,22 +262,51 @@
~RenderEngineTest() {
if (WRITE_BUFFER_TO_FILE_ON_FAILURE && ::testing::Test::HasFailure()) {
- writeBufferToFile("/data/texture_out_");
+ writeBufferToFile("/data/local/tmp/RenderEngineTest/");
}
const ::testing::TestInfo* const test_info =
::testing::UnitTest::GetInstance()->current_test_info();
ALOGI("**** Tearing down after %s.%s\n", test_info->test_case_name(), test_info->name());
}
- void writeBufferToFile(const char* basename) {
- std::string filename(basename);
- filename.append(::testing::UnitTest::GetInstance()->current_test_info()->name());
- filename.append(".ppm");
- std::ofstream file(filename.c_str(), std::ios::binary);
+ // If called during e.g.
+ // `PerRenderEngineType/RenderEngineTest#drawLayers_fillBufferCheckersRotate90_colorSource/0`
+ // with a directory of `/data/local/tmp/RenderEngineTest`, then mBuffer will be dumped to
+ // `/data/local/tmp/RenderEngineTest/drawLayers_fillBufferCheckersRotate90_colorSource-0.ppm`
+ //
+ // Note: if `directory` does not exist, then its full path will be recursively created with 777
+ // permissions. If `directory` already exists but does not grant the executing user write
+ // permissions, then saving the buffer will fail.
+ //
+ // Since this is test-only code, no security considerations are made.
+ void writeBufferToFile(const filesystem::path& directory) {
+ const auto currentTestInfo = ::testing::UnitTest::GetInstance()->current_test_info();
+ LOG_ALWAYS_FATAL_IF(!currentTestInfo,
+ "writeBufferToFile must be called during execution of a test");
+
+ std::string fileName(currentTestInfo->name());
+ // Test names may include the RenderEngine variant separated by '/', which would separate
+ // the file name into a subdirectory if not corrected.
+ std::replace(fileName.begin(), fileName.end(), '/', '-');
+ fileName.append(".ppm");
+
+ std::error_code err;
+ filesystem::create_directories(directory, err);
+ if (err.value()) {
+ ALOGE("Unable to create directory %s for writing %s (%d: %s)", directory.c_str(),
+ fileName.c_str(), err.value(), err.message().c_str());
+ return;
+ }
+
+ // Append operator ("/") ensures exactly one "/" directly before the argument.
+ const filesystem::path filePath = directory / fileName;
+ std::ofstream file(filePath.c_str(), std::ios::binary);
if (!file.is_open()) {
- ALOGE("Unable to open file: %s", filename.c_str());
- ALOGE("You may need to do: \"adb shell setenforce 0\" to enable "
- "surfaceflinger to write debug images");
+ ALOGE("Unable to open file: %s", filePath.c_str());
+ ALOGE("You may need to do: \"adb shell setenforce 0\" to enable surfaceflinger to "
+ "write debug images, or the %s directory might not give the executing user write "
+ "permission",
+ directory.c_str());
return;
}
@@ -304,6 +336,7 @@
}
}
file.write(reinterpret_cast<char*>(outBuffer.data()), outBuffer.size());
+ ALOGI("Image of incorrect output written to %s", filePath.c_str());
mBuffer->getBuffer()->unlock();
}
diff --git a/libs/ui/include/ui/EdgeExtensionEffect.h b/libs/ui/include/ui/EdgeExtensionEffect.h
new file mode 100644
index 0000000..02126b1
--- /dev/null
+++ b/libs/ui/include/ui/EdgeExtensionEffect.h
@@ -0,0 +1,95 @@
+/*
+ * 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.
+ */
+
+#pragma once
+
+/**
+ * Stores the edge that will be extended
+ */
+namespace android {
+
+enum CanonicalDirections { NONE = 0, LEFT = 1, RIGHT = 2, TOP = 4, BOTTOM = 8 };
+
+inline std::string to_string(CanonicalDirections direction) {
+ switch (direction) {
+ case LEFT:
+ return "LEFT";
+ case RIGHT:
+ return "RIGHT";
+ case TOP:
+ return "TOP";
+ case BOTTOM:
+ return "BOTTOM";
+ case NONE:
+ return "NONE";
+ }
+}
+
+struct EdgeExtensionEffect {
+ EdgeExtensionEffect(bool left, bool right, bool top, bool bottom) {
+ extensionEdges = NONE;
+ if (left) {
+ extensionEdges |= LEFT;
+ }
+ if (right) {
+ extensionEdges |= RIGHT;
+ }
+ if (top) {
+ extensionEdges |= TOP;
+ }
+ if (bottom) {
+ extensionEdges |= BOTTOM;
+ }
+ }
+
+ EdgeExtensionEffect() { EdgeExtensionEffect(false, false, false, false); }
+
+ bool extendsEdge(CanonicalDirections edge) const { return extensionEdges & edge; }
+
+ bool hasEffect() const { return extensionEdges != NONE; };
+
+ void reset() { extensionEdges = NONE; }
+
+ bool operator==(const EdgeExtensionEffect& other) const {
+ return extensionEdges == other.extensionEdges;
+ }
+
+ bool operator!=(const EdgeExtensionEffect& other) const { return !(*this == other); }
+
+private:
+ int extensionEdges;
+};
+
+inline std::string to_string(const EdgeExtensionEffect& effect) {
+ std::string s = "EdgeExtensionEffect={edges=[";
+ if (effect.hasEffect()) {
+ for (CanonicalDirections edge : {LEFT, RIGHT, TOP, BOTTOM}) {
+ if (effect.extendsEdge(edge)) {
+ s += to_string(edge) + ", ";
+ }
+ }
+ } else {
+ s += to_string(NONE);
+ }
+ s += "]}";
+ return s;
+}
+
+inline std::ostream& operator<<(std::ostream& os, const EdgeExtensionEffect effect) {
+ os << to_string(effect);
+ return os;
+}
+} // namespace android
diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp
index 5b5afd3..b1a287f 100644
--- a/opengl/libs/EGL/egl_display.cpp
+++ b/opengl/libs/EGL/egl_display.cpp
@@ -383,6 +383,14 @@
// before using cnx->major & cnx->minor
if (major != nullptr) *major = cnx->major;
if (minor != nullptr) *minor = cnx->minor;
+ auto mergeExtensionStrings = [](const std::vector<std::string>& strings) {
+ std::ostringstream combinedStringStream;
+ std::copy(strings.begin(), strings.end(),
+ std::ostream_iterator<std::string>(combinedStringStream, " "));
+ // gBuiltinExtensionString already has a trailing space so is added here
+ return gBuiltinExtensionString + combinedStringStream.str();
+ };
+ mExtensionString = mergeExtensionStrings(extensionStrings);
}
{ // scope for refLock
@@ -391,14 +399,6 @@
refCond.notify_all();
}
- auto mergeExtensionStrings = [](const std::vector<std::string>& strings) {
- std::ostringstream combinedStringStream;
- std::copy(strings.begin(), strings.end(),
- std::ostream_iterator<std::string>(combinedStringStream, " "));
- // gBuiltinExtensionString already has a trailing space so is added here
- return gBuiltinExtensionString + combinedStringStream.str();
- };
- mExtensionString = mergeExtensionStrings(extensionStrings);
return EGL_TRUE;
}
diff --git a/services/inputflinger/dispatcher/InputDispatcher.cpp b/services/inputflinger/dispatcher/InputDispatcher.cpp
index a76271d..a2e50d7 100644
--- a/services/inputflinger/dispatcher/InputDispatcher.cpp
+++ b/services/inputflinger/dispatcher/InputDispatcher.cpp
@@ -2497,9 +2497,8 @@
}
if (newTouchedWindows.empty()) {
- ALOGI("Dropping event because there is no touchable window at (%.1f, %.1f) on display "
- "%s.",
- x, y, displayId.toString().c_str());
+ LOG(INFO) << "Dropping event because there is no touchable window at (" << x << ", "
+ << y << ") on display " << displayId << ": " << entry;
outInjectionResult = InputEventInjectionResult::FAILED;
return {};
}
diff --git a/services/inputflinger/tests/Android.bp b/services/inputflinger/tests/Android.bp
index bddf43e..189f117 100644
--- a/services/inputflinger/tests/Android.bp
+++ b/services/inputflinger/tests/Android.bp
@@ -116,5 +116,8 @@
test_options: {
unit_test: true,
},
- test_suites: ["device-tests"],
+ test_suites: [
+ "device-tests",
+ "device-platinum-tests",
+ ],
}
diff --git a/services/inputflinger/tests/FakeWindows.h b/services/inputflinger/tests/FakeWindows.h
index ee65d3a..3a3238a 100644
--- a/services/inputflinger/tests/FakeWindows.h
+++ b/services/inputflinger/tests/FakeWindows.h
@@ -304,6 +304,13 @@
WithFlags(expectedFlags)));
}
+ inline void consumeMotionPointerDown(int32_t pointerIdx,
+ const ::testing::Matcher<MotionEvent>& matcher) {
+ const int32_t action = AMOTION_EVENT_ACTION_POINTER_DOWN |
+ (pointerIdx << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT);
+ consumeMotionEvent(testing::AllOf(WithMotionAction(action), matcher));
+ }
+
inline void consumeMotionPointerUp(int32_t pointerIdx,
const ::testing::Matcher<MotionEvent>& matcher) {
const int32_t action = AMOTION_EVENT_ACTION_POINTER_UP |
diff --git a/services/inputflinger/tests/InputDispatcher_test.cpp b/services/inputflinger/tests/InputDispatcher_test.cpp
index 5eab6be..04ed670 100644
--- a/services/inputflinger/tests/InputDispatcher_test.cpp
+++ b/services/inputflinger/tests/InputDispatcher_test.cpp
@@ -4172,6 +4172,121 @@
window2->consumeMotionEvent(WithDownTime(secondDown->getDownTime()));
}
+/**
+ * When events are not split, the downTime should be adjusted such that the downTime corresponds
+ * to the event time of the first ACTION_DOWN. If a new window appears, it should not affect
+ * the event routing because the first window prevents splitting.
+ */
+TEST_F(InputDispatcherTest, SplitTouchesSendCorrectActionDownTimeForNewWindow) {
+ std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeWindowHandle> window1 =
+ sp<FakeWindowHandle>::make(application, mDispatcher, "Window1", DISPLAY_ID);
+ window1->setTouchableRegion(Region{{0, 0, 100, 100}});
+ window1->setPreventSplitting(true);
+
+ sp<FakeWindowHandle> window2 =
+ sp<FakeWindowHandle>::make(application, mDispatcher, "Window2", DISPLAY_ID);
+ window2->setTouchableRegion(Region{{100, 0, 200, 100}});
+
+ mDispatcher->onWindowInfosChanged({{*window1->getInfo()}, {}, 0, 0});
+
+ // Touch down on the first window
+ NotifyMotionArgs downArgs = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
+ .build();
+ mDispatcher->notifyMotion(downArgs);
+
+ window1->consumeMotionEvent(
+ AllOf(WithMotionAction(ACTION_DOWN), WithDownTime(downArgs.downTime)));
+
+ // Second window is added
+ mDispatcher->onWindowInfosChanged({{*window1->getInfo(), *window2->getInfo()}, {}, 0, 0});
+
+ // Now touch down on the window with another pointer
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50))
+ .downTime(downArgs.downTime)
+ .build());
+ window1->consumeMotionPointerDown(1, AllOf(WithDownTime(downArgs.downTime)));
+
+ // Finish the gesture
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50))
+ .downTime(downArgs.downTime)
+ .build());
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
+ .downTime(downArgs.downTime)
+ .build());
+ window1->consumeMotionPointerUp(1, AllOf(WithDownTime(downArgs.downTime)));
+ window1->consumeMotionEvent(
+ AllOf(WithMotionAction(ACTION_UP), WithDownTime(downArgs.downTime)));
+ window2->assertNoEvents();
+}
+
+/**
+ * When splitting touch events, the downTime should be adjusted such that the downTime corresponds
+ * to the event time of the first ACTION_DOWN sent to the new window.
+ * If a new window that does not support split appears on the screen and gets touched with the
+ * second finger, it should not get any events because it doesn't want split touches. At the same
+ * time, the first window should not get the pointer_down event because it supports split touches
+ * (and the touch occurred outside of the bounds of window1).
+ */
+TEST_F(InputDispatcherTest, SplitTouchesDropsEventForNonSplittableSecondWindow) {
+ std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
+ sp<FakeWindowHandle> window1 =
+ sp<FakeWindowHandle>::make(application, mDispatcher, "Window1", DISPLAY_ID);
+ window1->setTouchableRegion(Region{{0, 0, 100, 100}});
+
+ sp<FakeWindowHandle> window2 =
+ sp<FakeWindowHandle>::make(application, mDispatcher, "Window2", DISPLAY_ID);
+ window2->setTouchableRegion(Region{{100, 0, 200, 100}});
+
+ mDispatcher->onWindowInfosChanged({{*window1->getInfo()}, {}, 0, 0});
+
+ // Touch down on the first window
+ NotifyMotionArgs downArgs = MotionArgsBuilder(ACTION_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
+ .build();
+ mDispatcher->notifyMotion(downArgs);
+
+ window1->consumeMotionEvent(
+ AllOf(WithMotionAction(ACTION_DOWN), WithDownTime(downArgs.downTime)));
+
+ // Second window is added
+ window2->setPreventSplitting(true);
+ mDispatcher->onWindowInfosChanged({{*window1->getInfo(), *window2->getInfo()}, {}, 0, 0});
+
+ // Now touch down on the window with another pointer
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_DOWN, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50))
+ .downTime(downArgs.downTime)
+ .build());
+ // Event is dropped because window2 doesn't support split touch, and window1 does.
+
+ // Complete the gesture
+ mDispatcher->notifyMotion(MotionArgsBuilder(POINTER_1_UP, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
+ .pointer(PointerBuilder(1, ToolType::FINGER).x(150).y(50))
+ .downTime(downArgs.downTime)
+ .build());
+ // A redundant MOVE event is generated that doesn't carry any new information
+ window1->consumeMotionEvent(
+ AllOf(WithMotionAction(ACTION_MOVE), WithDownTime(downArgs.downTime)));
+ mDispatcher->notifyMotion(MotionArgsBuilder(ACTION_UP, AINPUT_SOURCE_TOUCHSCREEN)
+ .pointer(PointerBuilder(0, ToolType::FINGER).x(50).y(50))
+ .downTime(downArgs.downTime)
+ .build());
+
+ window1->consumeMotionEvent(
+ AllOf(WithMotionAction(ACTION_UP), WithDownTime(downArgs.downTime)));
+ window1->assertNoEvents();
+ window2->assertNoEvents();
+}
+
TEST_F(InputDispatcherTest, HoverMoveEnterMouseClickAndHoverMoveExit) {
std::shared_ptr<FakeApplicationHandle> application = std::make_shared<FakeApplicationHandle>();
sp<FakeWindowHandle> windowLeft = sp<FakeWindowHandle>::make(application, mDispatcher, "Left",
diff --git a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
index 11759b8..d1429a2 100644
--- a/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
+++ b/services/surfaceflinger/CompositionEngine/include/compositionengine/LayerFECompositionState.h
@@ -35,6 +35,7 @@
#pragma clang diagnostic ignored "-Wextra"
#include <gui/BufferQueue.h>
+#include <ui/EdgeExtensionEffect.h>
#include <ui/GraphicBuffer.h>
#include <ui/GraphicTypes.h>
#include <ui/StretchEffect.h>
@@ -133,12 +134,16 @@
// The bounds of the layer in layer local coordinates
FloatRect geomLayerBounds;
+ // The crop to apply to the layer in layer local coordinates
+ FloatRect geomLayerCrop;
+
ShadowSettings shadowSettings;
// List of regions that require blur
std::vector<BlurRegion> blurRegions;
StretchEffect stretchEffect;
+ EdgeExtensionEffect edgeExtensionEffect;
/*
* Geometry state
diff --git a/services/surfaceflinger/CompositionEngine/src/ClientCompositionRequestCache.cpp b/services/surfaceflinger/CompositionEngine/src/ClientCompositionRequestCache.cpp
index bdaa1d0..d9018bc 100644
--- a/services/surfaceflinger/CompositionEngine/src/ClientCompositionRequestCache.cpp
+++ b/services/surfaceflinger/CompositionEngine/src/ClientCompositionRequestCache.cpp
@@ -37,7 +37,8 @@
lhs.colorTransform == rhs.colorTransform &&
lhs.disableBlending == rhs.disableBlending && lhs.shadow == rhs.shadow &&
lhs.backgroundBlurRadius == rhs.backgroundBlurRadius &&
- lhs.stretchEffect == rhs.stretchEffect;
+ lhs.stretchEffect == rhs.stretchEffect &&
+ lhs.edgeExtensionEffect == rhs.edgeExtensionEffect;
}
inline bool equalIgnoringBuffer(const renderengine::Buffer& lhs, const renderengine::Buffer& rhs) {
diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp
index 70e3c64..e5f6b7b 100644
--- a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp
+++ b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp
@@ -322,6 +322,10 @@
<< touchableRegion.bottom << "," << touchableRegion.right << "}"
<< "}";
}
+
+ if (obj.edgeExtensionEffect.hasEffect()) {
+ out << obj.edgeExtensionEffect;
+ }
return out;
}
@@ -492,8 +496,10 @@
requested.what &
(layer_state_t::eBufferChanged | layer_state_t::eDataspaceChanged |
layer_state_t::eApiChanged | layer_state_t::eShadowRadiusChanged |
- layer_state_t::eBlurRegionsChanged | layer_state_t::eStretchChanged)) {
- forceClientComposition = shadowSettings.length > 0 || stretchEffect.hasEffect();
+ layer_state_t::eBlurRegionsChanged | layer_state_t::eStretchChanged |
+ layer_state_t::eEdgeExtensionChanged)) {
+ forceClientComposition = shadowSettings.length > 0 || stretchEffect.hasEffect() ||
+ edgeExtensionEffect.hasEffect();
}
if (forceUpdate ||
diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp
index 2b1b2c8..4e09381 100644
--- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp
+++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp
@@ -367,6 +367,7 @@
snapshot.geomLayerBounds = getMaxDisplayBounds({});
snapshot.roundedCorner = RoundedCornerState();
snapshot.stretchEffect = {};
+ snapshot.edgeExtensionEffect = {};
snapshot.outputFilter.layerStack = ui::DEFAULT_LAYER_STACK;
snapshot.outputFilter.toInternalDisplay = false;
snapshot.isSecure = false;
@@ -811,6 +812,32 @@
: parentSnapshot.stretchEffect;
}
+ if (forceUpdate ||
+ (snapshot.clientChanges | parentSnapshot.clientChanges) &
+ layer_state_t::eEdgeExtensionChanged) {
+ if (requested.edgeExtensionParameters.extendLeft ||
+ requested.edgeExtensionParameters.extendRight ||
+ requested.edgeExtensionParameters.extendTop ||
+ requested.edgeExtensionParameters.extendBottom) {
+ // This is the root layer to which the extension is applied
+ snapshot.edgeExtensionEffect =
+ EdgeExtensionEffect(requested.edgeExtensionParameters.extendLeft,
+ requested.edgeExtensionParameters.extendRight,
+ requested.edgeExtensionParameters.extendTop,
+ requested.edgeExtensionParameters.extendBottom);
+ } else if (parentSnapshot.clientChanges & layer_state_t::eEdgeExtensionChanged) {
+ // Extension is inherited
+ snapshot.edgeExtensionEffect = parentSnapshot.edgeExtensionEffect;
+ } else {
+ // There is no edge extension
+ snapshot.edgeExtensionEffect.reset();
+ }
+ if (snapshot.edgeExtensionEffect.hasEffect()) {
+ snapshot.clientChanges |= layer_state_t::eEdgeExtensionChanged;
+ snapshot.changes |= RequestedLayerState::Changes::Geometry;
+ }
+ }
+
if (forceUpdate || snapshot.clientChanges & layer_state_t::eColorTransformChanged) {
if (!parentSnapshot.colorTransformIsIdentity) {
snapshot.colorTransform = parentSnapshot.colorTransform * requested.colorTransform;
@@ -899,6 +926,10 @@
updateLayerBounds(snapshot, requested, parentSnapshot, primaryDisplayRotationFlags);
}
+ if (snapshot.edgeExtensionEffect.hasEffect()) {
+ updateBoundsForEdgeExtension(snapshot);
+ }
+
if (forceUpdate || snapshot.clientChanges & layer_state_t::eCornerRadiusChanged ||
snapshot.changes.any(RequestedLayerState::Changes::Geometry |
RequestedLayerState::Changes::BufferUsageFlags)) {
@@ -917,8 +948,8 @@
}
// computed snapshot properties
- snapshot.forceClientComposition =
- snapshot.shadowSettings.length > 0 || snapshot.stretchEffect.hasEffect();
+ snapshot.forceClientComposition = snapshot.shadowSettings.length > 0 ||
+ snapshot.stretchEffect.hasEffect() || snapshot.edgeExtensionEffect.hasEffect();
snapshot.contentOpaque = snapshot.isContentOpaque();
snapshot.isOpaque = snapshot.contentOpaque && !snapshot.roundedCorner.hasRoundedCorners() &&
snapshot.color.a == 1.f;
@@ -973,6 +1004,31 @@
}
}
+/**
+ * According to the edges that we are requested to extend, we increase the bounds to the maximum
+ * extension allowed by the crop (parent crop + requested crop). The animation that called
+ * Transition#setEdgeExtensionEffect is in charge of setting the requested crop.
+ * @param snapshot
+ */
+void LayerSnapshotBuilder::updateBoundsForEdgeExtension(LayerSnapshot& snapshot) {
+ EdgeExtensionEffect& effect = snapshot.edgeExtensionEffect;
+
+ if (effect.extendsEdge(LEFT)) {
+ snapshot.geomLayerBounds.left = snapshot.geomLayerCrop.left;
+ }
+ if (effect.extendsEdge(RIGHT)) {
+ snapshot.geomLayerBounds.right = snapshot.geomLayerCrop.right;
+ }
+ if (effect.extendsEdge(TOP)) {
+ snapshot.geomLayerBounds.top = snapshot.geomLayerCrop.top;
+ }
+ if (effect.extendsEdge(BOTTOM)) {
+ snapshot.geomLayerBounds.bottom = snapshot.geomLayerCrop.bottom;
+ }
+
+ snapshot.transformedBounds = snapshot.geomLayerTransform.transform(snapshot.geomLayerBounds);
+}
+
void LayerSnapshotBuilder::updateLayerBounds(LayerSnapshot& snapshot,
const RequestedLayerState& requested,
const LayerSnapshot& parentSnapshot,
@@ -1012,11 +1068,12 @@
FloatRect parentBounds = parentSnapshot.geomLayerBounds;
parentBounds = snapshot.localTransform.inverse().transform(parentBounds);
snapshot.geomLayerBounds =
- (requested.externalTexture) ? snapshot.bufferSize.toFloatRect() : parentBounds;
+ requested.externalTexture ? snapshot.bufferSize.toFloatRect() : parentBounds;
+ snapshot.geomLayerCrop = parentBounds;
if (!requested.crop.isEmpty()) {
- snapshot.geomLayerBounds = snapshot.geomLayerBounds.intersect(requested.crop.toFloatRect());
+ snapshot.geomLayerCrop = snapshot.geomLayerCrop.intersect(requested.crop.toFloatRect());
}
- snapshot.geomLayerBounds = snapshot.geomLayerBounds.intersect(parentBounds);
+ snapshot.geomLayerBounds = snapshot.geomLayerBounds.intersect(snapshot.geomLayerCrop);
snapshot.transformedBounds = snapshot.geomLayerTransform.transform(snapshot.geomLayerBounds);
const Rect geomLayerBoundsWithoutTransparentRegion =
RequestedLayerState::reduce(Rect(snapshot.geomLayerBounds),
diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h
index dbbad76..f3c56a4 100644
--- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h
+++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.h
@@ -113,6 +113,10 @@
static void resetRelativeState(LayerSnapshot& snapshot);
static void updateRoundedCorner(LayerSnapshot& snapshot, const RequestedLayerState& layerState,
const LayerSnapshot& parentSnapshot, const Args& args);
+ static bool extensionEdgeSharedWithParent(LayerSnapshot& snapshot,
+ const RequestedLayerState& requested,
+ const LayerSnapshot& parentSnapshot);
+ static void updateBoundsForEdgeExtension(LayerSnapshot& snapshot);
void updateLayerBounds(LayerSnapshot& snapshot, const RequestedLayerState& layerState,
const LayerSnapshot& parentSnapshot, uint32_t displayRotationFlags);
static void updateShadows(LayerSnapshot& snapshot, const RequestedLayerState& requested,
diff --git a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
index 17d3f4b..17d2610 100644
--- a/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
+++ b/services/surfaceflinger/FrontEnd/RequestedLayerState.cpp
@@ -609,8 +609,9 @@
layer_state_t::eSidebandStreamChanged | layer_state_t::eColorSpaceAgnosticChanged |
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::eEdgeExtensionChanged | layer_state_t::eBufferCropChanged |
+ layer_state_t::eDestinationFrameChanged | layer_state_t::eDimmingEnabledChanged |
+ layer_state_t::eExtendedRangeBrightnessChanged |
layer_state_t::eDesiredHdrHeadroomChanged |
(FlagManager::getInstance().latch_unsignaled_with_auto_refresh_changed()
? layer_state_t::eFlagsChanged
diff --git a/services/surfaceflinger/LayerFE.cpp b/services/surfaceflinger/LayerFE.cpp
index 8f819b2..b05f0ee 100644
--- a/services/surfaceflinger/LayerFE.cpp
+++ b/services/surfaceflinger/LayerFE.cpp
@@ -173,6 +173,7 @@
break;
}
layerSettings.stretchEffect = mSnapshot->stretchEffect;
+ layerSettings.edgeExtensionEffect = mSnapshot->edgeExtensionEffect;
// Record the name of the layer for debugging further down the stack.
layerSettings.name = mSnapshot->name;
diff --git a/services/surfaceflinger/RegionSamplingThread.cpp b/services/surfaceflinger/RegionSamplingThread.cpp
index 06a4d00..7712d38 100644
--- a/services/surfaceflinger/RegionSamplingThread.cpp
+++ b/services/surfaceflinger/RegionSamplingThread.cpp
@@ -354,7 +354,7 @@
FenceResult fenceResult;
if (FlagManager::getInstance().single_hop_screenshot() &&
- FlagManager::getInstance().ce_fence_promise()) {
+ FlagManager::getInstance().ce_fence_promise() && mFlinger.mRenderEngine->isThreaded()) {
std::vector<sp<LayerFE>> layerFEs;
auto displayState = mFlinger.getSnapshotsFromMainThread(renderAreaBuilder,
getLayerSnapshotsFn, layerFEs);
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index b3c9b7f..d00e762 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -1482,8 +1482,6 @@
void SurfaceFlinger::initiateDisplayModeChanges() {
SFTRACE_CALL();
- std::optional<PhysicalDisplayId> displayToUpdateImmediately;
-
for (const auto& [displayId, physical] : FTL_FAKE_GUARD(mStateLock, mPhysicalDisplays)) {
auto desiredModeOpt = mDisplayModeController.getDesiredMode(displayId);
if (!desiredModeOpt) {
@@ -1537,21 +1535,14 @@
if (outTimeline.refreshRequired) {
scheduleComposite(FrameHint::kNone);
} else {
- // TODO(b/255635711): Remove `displayToUpdateImmediately` to `finalizeDisplayModeChange`
- // for all displays. This was only needed when the loop iterated over `mDisplays` rather
- // than `mPhysicalDisplays`.
- displayToUpdateImmediately = displayId;
- }
- }
+ // HWC has requested to apply the mode change immediately rather than on the next frame.
+ finalizeDisplayModeChange(displayId);
- if (displayToUpdateImmediately) {
- const auto displayId = *displayToUpdateImmediately;
- finalizeDisplayModeChange(displayId);
-
- const auto desiredModeOpt = mDisplayModeController.getDesiredMode(displayId);
- if (desiredModeOpt &&
- mDisplayModeController.getActiveMode(displayId) == desiredModeOpt->mode) {
- applyActiveMode(displayId);
+ const auto desiredModeOpt = mDisplayModeController.getDesiredMode(displayId);
+ if (desiredModeOpt &&
+ mDisplayModeController.getActiveMode(displayId) == desiredModeOpt->mode) {
+ applyActiveMode(displayId);
+ }
}
}
}
@@ -8193,7 +8184,7 @@
}
if (FlagManager::getInstance().single_hop_screenshot() &&
- FlagManager::getInstance().ce_fence_promise()) {
+ FlagManager::getInstance().ce_fence_promise() && mRenderEngine->isThreaded()) {
std::vector<sp<LayerFE>> layerFEs;
auto displayState =
getSnapshotsFromMainThread(renderAreaBuilder, getLayerSnapshotsFn, layerFEs);
@@ -8566,10 +8557,8 @@
// to CompositionEngine::present.
ftl::SharedFuture<FenceResult> presentFuture;
if (FlagManager::getInstance().single_hop_screenshot() &&
- FlagManager::getInstance().ce_fence_promise()) {
- presentFuture = mRenderEngine->isThreaded()
- ? ftl::yield(present()).share()
- : mScheduler->schedule(std::move(present)).share();
+ FlagManager::getInstance().ce_fence_promise() && mRenderEngine->isThreaded()) {
+ presentFuture = ftl::yield(present()).share();
} else {
presentFuture = mRenderEngine->isThreaded() ? ftl::defer(std::move(present)).share()
: ftl::yield(present()).share();
diff --git a/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp b/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp
index 0c3e875..4b0a7c3 100644
--- a/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp
+++ b/services/surfaceflinger/tests/unittests/SurfaceFlinger_DisplayModeSwitching.cpp
@@ -42,6 +42,47 @@
using android::hardware::graphics::composer::V2_4::Error;
using android::hardware::graphics::composer::V2_4::VsyncPeriodChangeTimeline;
+MATCHER_P2(ModeSettledTo, dmc, modeId, "") {
+ const auto displayId = arg->getPhysicalId();
+
+ if (const auto desiredOpt = dmc->getDesiredMode(displayId)) {
+ *result_listener << "Unsettled desired mode "
+ << ftl::to_underlying(desiredOpt->mode.modePtr->getId());
+ return false;
+ }
+
+ if (dmc->getActiveMode(displayId).modePtr->getId() != modeId) {
+ *result_listener << "Settled to unexpected active mode " << ftl::to_underlying(modeId);
+ return false;
+ }
+
+ return true;
+}
+
+MATCHER_P2(ModeSwitchingTo, flinger, modeId, "") {
+ const auto displayId = arg->getPhysicalId();
+ auto& dmc = flinger->mutableDisplayModeController();
+
+ if (!dmc.getDesiredMode(displayId)) {
+ *result_listener << "No desired mode";
+ return false;
+ }
+
+ if (dmc.getDesiredMode(displayId)->mode.modePtr->getId() != modeId) {
+ *result_listener << "Unexpected desired mode " << ftl::to_underlying(modeId);
+ return false;
+ }
+
+ // VsyncModulator should react to mode switches on the pacesetter display.
+ if (displayId == flinger->scheduler()->pacesetterDisplayId() &&
+ !flinger->scheduler()->vsyncModulator().isVsyncConfigEarly()) {
+ *result_listener << "VsyncModulator did not shift to early phase";
+ return false;
+ }
+
+ return true;
+}
+
class DisplayModeSwitchingTest : public DisplayTransactionTest {
public:
void SetUp() override {
@@ -58,8 +99,7 @@
setupScheduler(selectorPtr);
- mFlinger.onComposerHalHotplugEvent(PrimaryDisplayVariant::HWC_DISPLAY_ID,
- DisplayHotplugEvent::CONNECTED);
+ mFlinger.onComposerHalHotplugEvent(kInnerDisplayHwcId, DisplayHotplugEvent::CONNECTED);
mFlinger.configureAndCommit();
auto vsyncController = std::make_unique<mock::VsyncController>();
@@ -87,8 +127,13 @@
static constexpr HWDisplayId kInnerDisplayHwcId = PrimaryDisplayVariant::HWC_DISPLAY_ID;
static constexpr HWDisplayId kOuterDisplayHwcId = kInnerDisplayHwcId + 1;
+ static constexpr PhysicalDisplayId kOuterDisplayId = PhysicalDisplayId::fromPort(254u);
+
auto injectOuterDisplay() {
- constexpr PhysicalDisplayId kOuterDisplayId = PhysicalDisplayId::fromPort(254u);
+ // 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)));
constexpr bool kIsPrimary = false;
TestableSurfaceFlinger::FakeHwcDisplayInjector(kOuterDisplayId, hal::DisplayType::PHYSICAL,
@@ -169,129 +214,139 @@
TestableSurfaceFlinger::SchedulerCallbackImpl::kNoOp);
}
-TEST_F(DisplayModeSwitchingTest, changeRefreshRateOnActiveDisplayWithRefreshRequired) {
- ftl::FakeGuard guard(kMainThreadContext);
+TEST_F(DisplayModeSwitchingTest, changeRefreshRateWithRefreshRequired) {
+ EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId60));
- EXPECT_FALSE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId60);
+ EXPECT_EQ(NO_ERROR,
+ mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
+ mock::createDisplayModeSpecs(kModeId90, 120_Hz)));
- mFlinger.onActiveDisplayChanged(nullptr, *mDisplay);
-
- mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId90, false, 0, 120));
-
- ASSERT_TRUE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getDesiredMode(mDisplayId)->mode.modePtr->getId(), kModeId90);
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId60);
+ EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId90));
// Verify that next commit will call setActiveConfigWithConstraints in HWC
const VsyncPeriodChangeTimeline timeline{.refreshRequired = true};
- EXPECT_SET_ACTIVE_CONFIG(PrimaryDisplayVariant::HWC_DISPLAY_ID, kModeId90);
+ EXPECT_SET_ACTIVE_CONFIG(kInnerDisplayHwcId, kModeId90);
mFlinger.commit();
-
Mock::VerifyAndClearExpectations(mComposer);
- EXPECT_TRUE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId60);
+ EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId90));
// Verify that the next commit will complete the mode change and send
// a onModeChanged event to the framework.
EXPECT_CALL(*mAppEventThread,
onModeChanged(scheduler::FrameRateMode{90_Hz, ftl::as_non_null(kMode90)}));
+
mFlinger.commit();
Mock::VerifyAndClearExpectations(mAppEventThread);
- EXPECT_FALSE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId90);
+ EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId90));
}
-TEST_F(DisplayModeSwitchingTest, changeRefreshRateOnActiveDisplayWithoutRefreshRequired) {
- ftl::FakeGuard guard(kMainThreadContext);
+TEST_F(DisplayModeSwitchingTest, changeRefreshRateWithoutRefreshRequired) {
+ EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId60));
- EXPECT_FALSE(dmc().getDesiredMode(mDisplayId));
+ constexpr bool kAllowGroupSwitching = true;
+ EXPECT_EQ(NO_ERROR,
+ mFlinger.setDesiredDisplayModeSpecs(
+ mDisplay->getDisplayToken().promote(),
+ mock::createDisplayModeSpecs(kModeId90, 120_Hz, kAllowGroupSwitching)));
- mFlinger.onActiveDisplayChanged(nullptr, *mDisplay);
-
- mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId90, true, 0, 120));
-
- ASSERT_TRUE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getDesiredMode(mDisplayId)->mode.modePtr->getId(), kModeId90);
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId60);
+ EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId90));
// Verify that next commit will call setActiveConfigWithConstraints in HWC
// and complete the mode change.
const VsyncPeriodChangeTimeline timeline{.refreshRequired = false};
- EXPECT_SET_ACTIVE_CONFIG(PrimaryDisplayVariant::HWC_DISPLAY_ID, kModeId90);
+ EXPECT_SET_ACTIVE_CONFIG(kInnerDisplayHwcId, kModeId90);
EXPECT_CALL(*mAppEventThread,
onModeChanged(scheduler::FrameRateMode{90_Hz, ftl::as_non_null(kMode90)}));
mFlinger.commit();
- EXPECT_FALSE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId90);
+ EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId90));
}
-TEST_F(DisplayModeSwitchingTest, twoConsecutiveSetDesiredDisplayModeSpecs) {
- ftl::FakeGuard guard(kMainThreadContext);
+TEST_F(DisplayModeSwitchingTest, changeRefreshRateOnTwoDisplaysWithoutRefreshRequired) {
+ const auto [innerDisplay, outerDisplay] = injectOuterDisplay();
- // Test that if we call setDesiredDisplayModeSpecs while a previous mode change
- // is still being processed the later call will be respected.
+ EXPECT_THAT(innerDisplay, ModeSettledTo(&dmc(), kModeId60));
+ EXPECT_THAT(outerDisplay, ModeSettledTo(&dmc(), kModeId120));
- EXPECT_FALSE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId60);
+ EXPECT_EQ(NO_ERROR,
+ mFlinger.setDesiredDisplayModeSpecs(innerDisplay->getDisplayToken().promote(),
+ mock::createDisplayModeSpecs(kModeId90, 120_Hz,
+ true)));
+ EXPECT_EQ(NO_ERROR,
+ mFlinger.setDesiredDisplayModeSpecs(outerDisplay->getDisplayToken().promote(),
+ mock::createDisplayModeSpecs(kModeId60, 60_Hz,
+ true)));
- mFlinger.onActiveDisplayChanged(nullptr, *mDisplay);
-
- mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId90, false, 0, 120));
-
- const VsyncPeriodChangeTimeline timeline{.refreshRequired = true};
- EXPECT_SET_ACTIVE_CONFIG(PrimaryDisplayVariant::HWC_DISPLAY_ID, kModeId90);
-
- mFlinger.commit();
-
- mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId120, false, 0, 180));
-
- ASSERT_TRUE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getDesiredMode(mDisplayId)->mode.modePtr->getId(), kModeId120);
-
- EXPECT_SET_ACTIVE_CONFIG(PrimaryDisplayVariant::HWC_DISPLAY_ID, kModeId120);
-
- mFlinger.commit();
-
- ASSERT_TRUE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getDesiredMode(mDisplayId)->mode.modePtr->getId(), kModeId120);
-
- mFlinger.commit();
-
- EXPECT_FALSE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId120);
-}
-
-TEST_F(DisplayModeSwitchingTest, changeResolutionOnActiveDisplayWithoutRefreshRequired) {
- ftl::FakeGuard guard(kMainThreadContext);
-
- EXPECT_FALSE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId60);
-
- mFlinger.onActiveDisplayChanged(nullptr, *mDisplay);
-
- mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId90_4K, false, 0, 120));
-
- ASSERT_TRUE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getDesiredMode(mDisplayId)->mode.modePtr->getId(), kModeId90_4K);
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId60);
+ EXPECT_THAT(innerDisplay, ModeSwitchingTo(&mFlinger, kModeId90));
+ EXPECT_THAT(outerDisplay, ModeSwitchingTo(&mFlinger, kModeId60));
// Verify that next commit will call setActiveConfigWithConstraints in HWC
// and complete the mode change.
const VsyncPeriodChangeTimeline timeline{.refreshRequired = false};
- EXPECT_SET_ACTIVE_CONFIG(PrimaryDisplayVariant::HWC_DISPLAY_ID, kModeId90_4K);
+ EXPECT_SET_ACTIVE_CONFIG(kInnerDisplayHwcId, kModeId90);
+ EXPECT_SET_ACTIVE_CONFIG(kOuterDisplayHwcId, kModeId60);
+
+ EXPECT_CALL(*mAppEventThread, onModeChanged(_)).Times(2);
+
+ mFlinger.commit();
+
+ EXPECT_THAT(innerDisplay, ModeSettledTo(&dmc(), kModeId90));
+ EXPECT_THAT(outerDisplay, ModeSettledTo(&dmc(), kModeId60));
+}
+
+TEST_F(DisplayModeSwitchingTest, twoConsecutiveSetDesiredDisplayModeSpecs) {
+ // Test that if we call setDesiredDisplayModeSpecs while a previous mode change
+ // is still being processed the later call will be respected.
+
+ EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId60));
+
+ EXPECT_EQ(NO_ERROR,
+ mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
+ mock::createDisplayModeSpecs(kModeId90, 120_Hz)));
+
+ const VsyncPeriodChangeTimeline timeline{.refreshRequired = true};
+ EXPECT_SET_ACTIVE_CONFIG(kInnerDisplayHwcId, kModeId90);
+
+ mFlinger.commit();
+
+ EXPECT_EQ(NO_ERROR,
+ mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
+ mock::createDisplayModeSpecs(kModeId120,
+ 180_Hz)));
+
+ EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId120));
+
+ EXPECT_SET_ACTIVE_CONFIG(kInnerDisplayHwcId, kModeId120);
+
+ mFlinger.commit();
+
+ EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId120));
+
+ mFlinger.commit();
+
+ EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId120));
+}
+
+TEST_F(DisplayModeSwitchingTest, changeResolutionWithoutRefreshRequired) {
+ EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId60));
+
+ EXPECT_EQ(NO_ERROR,
+ mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
+ mock::createDisplayModeSpecs(kModeId90_4K,
+ 120_Hz)));
+
+ EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId90_4K));
+
+ // Verify that next commit will call setActiveConfigWithConstraints in HWC
+ // and complete the mode change.
+ const VsyncPeriodChangeTimeline timeline{.refreshRequired = false};
+ EXPECT_SET_ACTIVE_CONFIG(kInnerDisplayHwcId, kModeId90_4K);
EXPECT_CALL(*mAppEventThread, onHotplugReceived(mDisplayId, true));
@@ -310,61 +365,12 @@
mFlinger.commit();
- EXPECT_FALSE(dmc().getDesiredMode(mDisplayId));
- EXPECT_EQ(dmc().getActiveMode(mDisplayId).modePtr->getId(), kModeId90_4K);
-}
-
-MATCHER_P2(ModeSwitchingTo, flinger, modeId, "") {
- const auto displayId = arg->getPhysicalId();
- auto& dmc = flinger->mutableDisplayModeController();
-
- if (!dmc.getDesiredMode(displayId)) {
- *result_listener << "No desired mode";
- return false;
- }
-
- if (dmc.getDesiredMode(displayId)->mode.modePtr->getId() != modeId) {
- *result_listener << "Unexpected desired mode " << ftl::to_underlying(modeId);
- return false;
- }
-
- // VsyncModulator should react to mode switches on the pacesetter display.
- if (displayId == flinger->scheduler()->pacesetterDisplayId() &&
- !flinger->scheduler()->vsyncModulator().isVsyncConfigEarly()) {
- *result_listener << "VsyncModulator did not shift to early phase";
- return false;
- }
-
- return true;
-}
-
-MATCHER_P2(ModeSettledTo, dmc, modeId, "") {
- const auto displayId = arg->getPhysicalId();
-
- if (const auto desiredOpt = dmc->getDesiredMode(displayId)) {
- *result_listener << "Unsettled desired mode "
- << ftl::to_underlying(desiredOpt->mode.modePtr->getId());
- return false;
- }
-
- ftl::FakeGuard guard(kMainThreadContext);
-
- if (dmc->getActiveMode(displayId).modePtr->getId() != modeId) {
- *result_listener << "Settled to unexpected active mode " << ftl::to_underlying(modeId);
- return false;
- }
-
- return true;
+ EXPECT_THAT(mDisplay, ModeSettledTo(&dmc(), kModeId90_4K));
}
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());
@@ -381,13 +387,11 @@
EXPECT_EQ(NO_ERROR,
mFlinger.setDesiredDisplayModeSpecs(innerDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId90, false,
- 0.f, 120.f)));
+ mock::createDisplayModeSpecs(kModeId90, 120_Hz)));
EXPECT_EQ(NO_ERROR,
mFlinger.setDesiredDisplayModeSpecs(outerDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId60, false,
- 0.f, 120.f)));
+ mock::createDisplayModeSpecs(kModeId60, 120_Hz)));
EXPECT_THAT(innerDisplay, ModeSwitchingTo(&mFlinger, kModeId90));
EXPECT_THAT(outerDisplay, ModeSwitchingTo(&mFlinger, kModeId60));
@@ -414,8 +418,7 @@
EXPECT_EQ(NO_ERROR,
mFlinger.setDesiredDisplayModeSpecs(innerDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId60, false,
- 0.f, 120.f)));
+ mock::createDisplayModeSpecs(kModeId60, 120_Hz)));
EXPECT_THAT(innerDisplay, ModeSwitchingTo(&mFlinger, kModeId60));
EXPECT_SET_ACTIVE_CONFIG(kInnerDisplayHwcId, kModeId60);
@@ -434,10 +437,6 @@
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());
@@ -454,13 +453,11 @@
EXPECT_EQ(NO_ERROR,
mFlinger.setDesiredDisplayModeSpecs(innerDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId90, false,
- 0.f, 120.f)));
+ mock::createDisplayModeSpecs(kModeId90, 120_Hz)));
EXPECT_EQ(NO_ERROR,
mFlinger.setDesiredDisplayModeSpecs(outerDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId60, false,
- 0.f, 120.f)));
+ mock::createDisplayModeSpecs(kModeId60, 120_Hz)));
EXPECT_THAT(innerDisplay, ModeSwitchingTo(&mFlinger, kModeId90));
EXPECT_THAT(outerDisplay, ModeSwitchingTo(&mFlinger, kModeId60));
@@ -486,8 +483,7 @@
EXPECT_EQ(NO_ERROR,
mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId90, false,
- 0.f, 120.f)));
+ mock::createDisplayModeSpecs(kModeId90, 120_Hz)));
EXPECT_THAT(mDisplay, ModeSwitchingTo(&mFlinger, kModeId90));
@@ -511,11 +507,6 @@
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());
@@ -532,13 +523,11 @@
EXPECT_EQ(NO_ERROR,
mFlinger.setDesiredDisplayModeSpecs(innerDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId90, false,
- 0.f, 120.f)));
+ mock::createDisplayModeSpecs(kModeId90, 120_Hz)));
EXPECT_EQ(NO_ERROR,
mFlinger.setDesiredDisplayModeSpecs(outerDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId60, false,
- 0.f, 120.f)));
+ mock::createDisplayModeSpecs(kModeId60, 120_Hz)));
EXPECT_THAT(innerDisplay, ModeSwitchingTo(&mFlinger, kModeId90));
EXPECT_THAT(outerDisplay, ModeSwitchingTo(&mFlinger, kModeId60));
@@ -566,8 +555,8 @@
EXPECT_EQ(NO_ERROR,
mFlinger.setDesiredDisplayModeSpecs(outerDisplay->getDisplayToken().promote(),
- mock::createDisplayModeSpecs(kModeId120, false,
- 0.f, 120.f)));
+ mock::createDisplayModeSpecs(kModeId120,
+ 120_Hz)));
EXPECT_SET_ACTIVE_CONFIG(kOuterDisplayHwcId, kModeId120);
diff --git a/services/surfaceflinger/tests/unittests/mock/MockDisplayModeSpecs.h b/services/surfaceflinger/tests/unittests/mock/MockDisplayModeSpecs.h
index 7b18a82..4d35d4d 100644
--- a/services/surfaceflinger/tests/unittests/mock/MockDisplayModeSpecs.h
+++ b/services/surfaceflinger/tests/unittests/mock/MockDisplayModeSpecs.h
@@ -22,14 +22,13 @@
namespace android::mock {
-inline gui::DisplayModeSpecs createDisplayModeSpecs(DisplayModeId defaultMode,
- bool allowGroupSwitching, float minFps,
- float maxFps) {
+inline gui::DisplayModeSpecs createDisplayModeSpecs(DisplayModeId defaultMode, Fps maxFps,
+ bool allowGroupSwitching = false) {
gui::DisplayModeSpecs specs;
specs.defaultMode = ftl::to_underlying(defaultMode);
specs.allowGroupSwitching = allowGroupSwitching;
- specs.primaryRanges.physical.min = minFps;
- specs.primaryRanges.physical.max = maxFps;
+ specs.primaryRanges.physical.min = 0.f;
+ specs.primaryRanges.physical.max = maxFps.getValue();
specs.primaryRanges.render = specs.primaryRanges.physical;
specs.appRequestRanges = specs.primaryRanges;
return specs;