SF: Cleanup creating / destroying virtual display APIs
Follow-up CL for cleanup requested by SF owner in http://ag/27202517.
Misc:
- Fix type conversion warnings for print format.
- Return status destroying virtual display in SF and add appropriate
checks in UT.
- Use static constexpr / const for compile-time effciciency.
Bug: 339525838
Bug: 137375833
Bug: 194863377
Test: atest libsurfaceflinger_unittest
Test: atest SurfaceFlinger_test
Flag: EXEMPT refactor
Change-Id: I7859720989c9244b26f8764c3323a8495064c888
diff --git a/libs/gui/SurfaceComposerClient.cpp b/libs/gui/SurfaceComposerClient.cpp
index 7aaaebb..0a85cf8 100644
--- a/libs/gui/SurfaceComposerClient.cpp
+++ b/libs/gui/SurfaceComposerClient.cpp
@@ -1280,18 +1280,22 @@
}
// ---------------------------------------------------------------------------
-sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool isSecure,
- const std::string& uniqueId,
- float requestedRefreshRate) {
+sp<IBinder> SurfaceComposerClient::createVirtualDisplay(const std::string& displayName,
+ bool isSecure, const std::string& uniqueId,
+ float requestedRefreshRate) {
sp<IBinder> display = nullptr;
- binder::Status status = ComposerServiceAIDL::getComposerService()
- ->createDisplay(std::string(displayName.c_str()), isSecure,
- uniqueId, requestedRefreshRate, &display);
+ binder::Status status =
+ ComposerServiceAIDL::getComposerService()->createVirtualDisplay(displayName, isSecure,
+ uniqueId,
+ requestedRefreshRate,
+ &display);
return status.isOk() ? display : nullptr;
}
-void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) {
- ComposerServiceAIDL::getComposerService()->destroyDisplay(display);
+status_t SurfaceComposerClient::destroyVirtualDisplay(const sp<IBinder>& displayToken) {
+ return ComposerServiceAIDL::getComposerService()
+ ->destroyVirtualDisplay(displayToken)
+ .transactionError();
}
std::vector<PhysicalDisplayId> SurfaceComposerClient::getPhysicalDisplayIds() {
diff --git a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl
index c6e7197..11ccc9c 100644
--- a/libs/gui/aidl/android/gui/ISurfaceComposer.aidl
+++ b/libs/gui/aidl/android/gui/ISurfaceComposer.aidl
@@ -105,14 +105,14 @@
*
* requires ACCESS_SURFACE_FLINGER permission.
*/
- @nullable IBinder createDisplay(@utf8InCpp String displayName, boolean isSecure,
+ @nullable IBinder createVirtualDisplay(@utf8InCpp String displayName, boolean isSecure,
@utf8InCpp String uniqueId, float requestedRefreshRate);
/**
* Destroy a virtual display.
* requires ACCESS_SURFACE_FLINGER permission.
*/
- void destroyDisplay(IBinder display);
+ void destroyVirtualDisplay(IBinder displayToken);
/**
* Get stable IDs for connected physical displays.
diff --git a/libs/gui/include/gui/ISurfaceComposer.h b/libs/gui/include/gui/ISurfaceComposer.h
index 738c73a..eb4a802 100644
--- a/libs/gui/include/gui/ISurfaceComposer.h
+++ b/libs/gui/include/gui/ISurfaceComposer.h
@@ -130,8 +130,8 @@
CREATE_CONNECTION, // Deprecated. Autogenerated by .aidl now.
GET_STATIC_DISPLAY_INFO, // Deprecated. Autogenerated by .aidl now.
CREATE_DISPLAY_EVENT_CONNECTION, // Deprecated. Autogenerated by .aidl now.
- CREATE_DISPLAY, // Deprecated. Autogenerated by .aidl now.
- DESTROY_DISPLAY, // Deprecated. Autogenerated by .aidl now.
+ CREATE_VIRTUAL_DISPLAY, // Deprecated. Autogenerated by .aidl now.
+ DESTROY_VIRTUAL_DISPLAY, // Deprecated. Autogenerated by .aidl now.
GET_PHYSICAL_DISPLAY_TOKEN, // Deprecated. Autogenerated by .aidl now.
SET_TRANSACTION_STATE,
AUTHENTICATE_SURFACE, // Deprecated. Autogenerated by .aidl now.
diff --git a/libs/gui/include/gui/SurfaceComposerClient.h b/libs/gui/include/gui/SurfaceComposerClient.h
index 987efe0..e2307ed 100644
--- a/libs/gui/include/gui/SurfaceComposerClient.h
+++ b/libs/gui/include/gui/SurfaceComposerClient.h
@@ -376,11 +376,11 @@
sp<SurfaceControl> mirrorDisplay(DisplayId displayId);
static const std::string kEmpty;
- static sp<IBinder> createDisplay(const String8& displayName, bool isSecure,
- const std::string& uniqueId = kEmpty,
- float requestedRefreshRate = 0);
+ static sp<IBinder> createVirtualDisplay(const std::string& displayName, bool isSecure,
+ const std::string& uniqueId = kEmpty,
+ float requestedRefreshRate = 0);
- static void destroyDisplay(const sp<IBinder>& display);
+ static status_t destroyVirtualDisplay(const sp<IBinder>& displayToken);
static std::vector<PhysicalDisplayId> getPhysicalDisplayIds();
diff --git a/libs/gui/tests/EndToEndNativeInputTest.cpp b/libs/gui/tests/EndToEndNativeInputTest.cpp
index c0e7965..b0db396 100644
--- a/libs/gui/tests/EndToEndNativeInputTest.cpp
+++ b/libs/gui/tests/EndToEndNativeInputTest.cpp
@@ -1186,9 +1186,8 @@
MultiDisplayTests() : InputSurfacesTest() { ProcessState::self()->startThreadPool(); }
void TearDown() override {
- for (auto& token : mVirtualDisplays) {
- SurfaceComposerClient::destroyDisplay(token);
- }
+ std::for_each(mVirtualDisplays.begin(), mVirtualDisplays.end(),
+ SurfaceComposerClient::destroyVirtualDisplay);
InputSurfacesTest::TearDown();
}
@@ -1203,7 +1202,7 @@
std::string name = "VirtualDisplay";
name += std::to_string(mVirtualDisplays.size());
- sp<IBinder> token = SurfaceComposerClient::createDisplay(String8(name.c_str()), isSecure);
+ sp<IBinder> token = SurfaceComposerClient::createVirtualDisplay(name, isSecure);
SurfaceComposerClient::Transaction t;
t.setDisplaySurface(token, producer);
t.setDisplayFlags(token, receivesInput ? 0x01 /* DisplayDevice::eReceivesInput */ : 0);
diff --git a/libs/gui/tests/Surface_test.cpp b/libs/gui/tests/Surface_test.cpp
index eee4fb9..6c6a849 100644
--- a/libs/gui/tests/Surface_test.cpp
+++ b/libs/gui/tests/Surface_test.cpp
@@ -673,13 +673,14 @@
return binder::Status::ok();
}
- binder::Status createDisplay(const std::string& /*displayName*/, bool /*isSecure*/,
- const std::string& /*uniqueId*/, float /*requestedRefreshRate*/,
- sp<IBinder>* /*outDisplay*/) override {
+ binder::Status createVirtualDisplay(const std::string& /*displayName*/, bool /*isSecure*/,
+ const std::string& /*uniqueId*/,
+ float /*requestedRefreshRate*/,
+ sp<IBinder>* /*outDisplay*/) override {
return binder::Status::ok();
}
- binder::Status destroyDisplay(const sp<IBinder>& /*display*/) override {
+ binder::Status destroyVirtualDisplay(const sp<IBinder>& /*displayToken*/) override {
return binder::Status::ok();
}