Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit d53801c5 authored by Alan Ding's avatar Alan Ding
Browse files

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
parent 56a49bae
Loading
Loading
Loading
Loading
+12 −8
Original line number Diff line number Diff line
@@ -1280,18 +1280,22 @@ status_t SurfaceComposerClient::Transaction::sendSurfaceFlushJankDataTransaction
}
// ---------------------------------------------------------------------------

sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, bool isSecure,
                                                 const std::string& uniqueId,
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() {
+2 −2
Original line number Diff line number Diff line
@@ -105,14 +105,14 @@ interface ISurfaceComposer {
     *
     * 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.
+2 −2
Original line number Diff line number Diff line
@@ -130,8 +130,8 @@ public:
        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.
+4 −4
Original line number Diff line number Diff line
@@ -376,11 +376,11 @@ public:
    sp<SurfaceControl> mirrorDisplay(DisplayId displayId);

    static const std::string kEmpty;
    static sp<IBinder> createDisplay(const String8& displayName, bool isSecure,
    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();

+3 −4
Original line number Diff line number Diff line
@@ -1186,9 +1186,8 @@ public:
    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 @@ public:

        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);
Loading