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

Commit ebc8d3aa authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Remove composer sequence IDs

Multiple HWC instances are no longer supported since VR was nixed.

Also, rename HAL callbacks so their origin is clear.

Bug: 182939859
Test: Build
Change-Id: Ia09b120dce1a4659a3cbb8927d44da8fba266c54
Merged-In: Ia09b120dce1a4659a3cbb8927d44da8fba266c54
parent 1394860b
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -39,7 +39,7 @@ public:
    HWComposer();
    HWComposer();
    ~HWComposer() override;
    ~HWComposer() override;


    MOCK_METHOD2(setConfiguration, void(HWC2::ComposerCallback*, int32_t));
    MOCK_METHOD1(setCallback, void(HWC2::ComposerCallback*));
    MOCK_CONST_METHOD3(getDisplayIdentificationData,
    MOCK_CONST_METHOD3(getDisplayIdentificationData,
                       bool(hal::HWDisplayId, uint8_t*, DisplayIdentificationData*));
                       bool(hal::HWDisplayId, uint8_t*, DisplayIdentificationData*));
    MOCK_CONST_METHOD1(hasCapability, bool(hal::Capability));
    MOCK_CONST_METHOD1(hasCapability, bool(hal::Capability));
+8 −12
Original line number Original line Diff line number Diff line
@@ -56,20 +56,16 @@ namespace hal = android::hardware::graphics::composer::hal;
// Implement this interface to receive hardware composer events.
// Implement this interface to receive hardware composer events.
//
//
// These callback functions will generally be called on a hwbinder thread, but
// These callback functions will generally be called on a hwbinder thread, but
// when first registering the callback the onHotplugReceived() function will
// when first registering the callback the onComposerHalHotplug() function will
// immediately be called on the thread calling registerCallback().
// immediately be called on the thread calling registerCallback().
//
// All calls receive a sequenceId, which will be the value that was supplied to
// HWC2::Device::registerCallback(). It's used to help differentiate callbacks
// from different hardware composer instances.
struct ComposerCallback {
struct ComposerCallback {
    virtual void onHotplugReceived(int32_t sequenceId, hal::HWDisplayId, hal::Connection) = 0;
    virtual void onComposerHalHotplug(hal::HWDisplayId, hal::Connection) = 0;
    virtual void onRefreshReceived(int32_t sequenceId, hal::HWDisplayId) = 0;
    virtual void onComposerHalRefresh(hal::HWDisplayId) = 0;
    virtual void onVsyncReceived(int32_t sequenceId, hal::HWDisplayId, int64_t timestamp,
    virtual void onComposerHalVsync(hal::HWDisplayId, int64_t timestamp,
                                    std::optional<hal::VsyncPeriodNanos>) = 0;
                                    std::optional<hal::VsyncPeriodNanos>) = 0;
    virtual void onVsyncPeriodTimingChangedReceived(int32_t sequenceId, hal::HWDisplayId,
    virtual void onComposerHalVsyncPeriodTimingChanged(hal::HWDisplayId,
                                                       const hal::VsyncPeriodChangeTimeline&) = 0;
                                                       const hal::VsyncPeriodChangeTimeline&) = 0;
    virtual void onSeamlessPossible(int32_t sequenceId, hal::HWDisplayId) = 0;
    virtual void onComposerHalSeamlessPossible(hal::HWDisplayId) = 0;


protected:
protected:
    ~ComposerCallback() = default;
    ~ComposerCallback() = default;
+16 −23
Original line number Original line Diff line number Diff line
@@ -82,25 +82,22 @@ using android::HWC2::ComposerCallback;


class ComposerCallbackBridge : public hal::IComposerCallback {
class ComposerCallbackBridge : public hal::IComposerCallback {
public:
public:
    ComposerCallbackBridge(ComposerCallback* callback, int32_t sequenceId,
    ComposerCallbackBridge(ComposerCallback* callback, bool vsyncSwitchingSupported)
                           bool vsyncSwitchingSupported)
          : mCallback(callback), mVsyncSwitchingSupported(vsyncSwitchingSupported) {}
          : mCallback(callback),

            mSequenceId(sequenceId),
    Return<void> onHotplug(hal::HWDisplayId display, hal::Connection connection) override {
            mVsyncSwitchingSupported(vsyncSwitchingSupported) {}
        mCallback->onComposerHalHotplug(display, connection);

    Return<void> onHotplug(hal::HWDisplayId display, hal::Connection conn) override {
        mCallback->onHotplugReceived(mSequenceId, display, conn);
        return Void();
        return Void();
    }
    }


    Return<void> onRefresh(hal::HWDisplayId display) override {
    Return<void> onRefresh(hal::HWDisplayId display) override {
        mCallback->onRefreshReceived(mSequenceId, display);
        mCallback->onComposerHalRefresh(display);
        return Void();
        return Void();
    }
    }


    Return<void> onVsync(hal::HWDisplayId display, int64_t timestamp) override {
    Return<void> onVsync(hal::HWDisplayId display, int64_t timestamp) override {
        if (!mVsyncSwitchingSupported) {
        if (!mVsyncSwitchingSupported) {
            mCallback->onVsyncReceived(mSequenceId, display, timestamp, std::nullopt);
            mCallback->onComposerHalVsync(display, timestamp, std::nullopt);
        } else {
        } else {
            ALOGW("Unexpected onVsync callback on composer >= 2.4, ignoring.");
            ALOGW("Unexpected onVsync callback on composer >= 2.4, ignoring.");
        }
        }
@@ -110,8 +107,7 @@ public:
    Return<void> onVsync_2_4(hal::HWDisplayId display, int64_t timestamp,
    Return<void> onVsync_2_4(hal::HWDisplayId display, int64_t timestamp,
                             hal::VsyncPeriodNanos vsyncPeriodNanos) override {
                             hal::VsyncPeriodNanos vsyncPeriodNanos) override {
        if (mVsyncSwitchingSupported) {
        if (mVsyncSwitchingSupported) {
            mCallback->onVsyncReceived(mSequenceId, display, timestamp,
            mCallback->onComposerHalVsync(display, timestamp, vsyncPeriodNanos);
                                       std::make_optional(vsyncPeriodNanos));
        } else {
        } else {
            ALOGW("Unexpected onVsync_2_4 callback on composer <= 2.3, ignoring.");
            ALOGW("Unexpected onVsync_2_4 callback on composer <= 2.3, ignoring.");
        }
        }
@@ -119,20 +115,18 @@ public:
    }
    }


    Return<void> onVsyncPeriodTimingChanged(
    Return<void> onVsyncPeriodTimingChanged(
            hal::HWDisplayId display,
            hal::HWDisplayId display, const hal::VsyncPeriodChangeTimeline& timeline) override {
            const hal::VsyncPeriodChangeTimeline& updatedTimeline) override {
        mCallback->onComposerHalVsyncPeriodTimingChanged(display, timeline);
        mCallback->onVsyncPeriodTimingChangedReceived(mSequenceId, display, updatedTimeline);
        return Void();
        return Void();
    }
    }


    Return<void> onSeamlessPossible(hal::HWDisplayId display) override {
    Return<void> onSeamlessPossible(hal::HWDisplayId display) override {
        mCallback->onSeamlessPossible(mSequenceId, display);
        mCallback->onComposerHalSeamlessPossible(display);
        return Void();
        return Void();
    }
    }


private:
private:
    ComposerCallback* mCallback;
    ComposerCallback* const mCallback;
    const int32_t mSequenceId;
    const bool mVsyncSwitchingSupported;
    const bool mVsyncSwitchingSupported;
};
};


@@ -155,7 +149,7 @@ HWComposer::~HWComposer() {
    mDisplayData.clear();
    mDisplayData.clear();
}
}


void HWComposer::setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) {
void HWComposer::setCallback(HWC2::ComposerCallback* callback) {
    loadCapabilities();
    loadCapabilities();
    loadLayerMetadataSupport();
    loadLayerMetadataSupport();


@@ -164,10 +158,9 @@ void HWComposer::setConfiguration(HWC2::ComposerCallback* callback, int32_t sequ
        return;
        return;
    }
    }
    mRegisteredCallback = true;
    mRegisteredCallback = true;
    sp<ComposerCallbackBridge> callbackBridge(

            new ComposerCallbackBridge(callback, sequenceId,
    mComposer->registerCallback(
                                       mComposer->isVsyncPeriodSwitchSupported()));
            sp<ComposerCallbackBridge>::make(callback, mComposer->isVsyncPeriodSwitchSupported()));
    mComposer->registerCallback(callbackBridge);
}
}


bool HWComposer::getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
bool HWComposer::getDisplayIdentificationData(hal::HWDisplayId hwcDisplayId, uint8_t* outPort,
+2 −2
Original line number Original line Diff line number Diff line
@@ -100,7 +100,7 @@ public:


    virtual ~HWComposer();
    virtual ~HWComposer();


    virtual void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) = 0;
    virtual void setCallback(HWC2::ComposerCallback*) = 0;


    virtual bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
    virtual bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
                                              DisplayIdentificationData* outData) const = 0;
                                              DisplayIdentificationData* outData) const = 0;
@@ -252,7 +252,7 @@ public:


    ~HWComposer() override;
    ~HWComposer() override;


    void setConfiguration(HWC2::ComposerCallback* callback, int32_t sequenceId) override;
    void setCallback(HWC2::ComposerCallback*) override;


    bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
    bool getDisplayIdentificationData(hal::HWDisplayId, uint8_t* outPort,
                                      DisplayIdentificationData* outData) const override;
                                      DisplayIdentificationData* outData) const override;
+13 −30
Original line number Original line Diff line number Diff line
@@ -783,7 +783,7 @@ void SurfaceFlinger::init() {
                    .build()));
                    .build()));
    mCompositionEngine->setTimeStats(mTimeStats);
    mCompositionEngine->setTimeStats(mTimeStats);
    mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName));
    mCompositionEngine->setHwComposer(getFactory().createHWComposer(mHwcServiceName));
    mCompositionEngine->getHwComposer().setConfiguration(this, getBE().mComposerSequenceId);
    mCompositionEngine->getHwComposer().setCallback(this);
    ClientCache::getInstance().setRenderEngine(&getRenderEngine());
    ClientCache::getInstance().setRenderEngine(&getRenderEngine());


    if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) {
    if (base::GetBoolProperty("debug.sf.enable_hwc_vds"s, false)) {
@@ -1663,16 +1663,11 @@ nsecs_t SurfaceFlinger::getVsyncPeriodFromHWC() const {
    return 0;
    return 0;
}
}


void SurfaceFlinger::onVsyncReceived(int32_t sequenceId, hal::HWDisplayId hwcDisplayId,
void SurfaceFlinger::onComposerHalVsync(hal::HWDisplayId hwcDisplayId, int64_t timestamp,
                                     int64_t timestamp,
                                        std::optional<hal::VsyncPeriodNanos> vsyncPeriod) {
                                        std::optional<hal::VsyncPeriodNanos> vsyncPeriod) {
    ATRACE_NAME("SF onVsync");
    ATRACE_CALL();


    Mutex::Autolock lock(mStateLock);
    Mutex::Autolock lock(mStateLock);
    // Ignore any vsyncs from a previous hardware composer.
    if (sequenceId != getBE().mComposerSequenceId) {
        return;
    }


    if (const auto displayId = getHwComposer().toPhysicalDisplayId(hwcDisplayId)) {
    if (const auto displayId = getHwComposer().toPhysicalDisplayId(hwcDisplayId)) {
        auto token = getPhysicalDisplayTokenLocked(*displayId);
        auto token = getPhysicalDisplayTokenLocked(*displayId);
@@ -1723,16 +1718,11 @@ void SurfaceFlinger::changeRefreshRateLocked(const RefreshRate& refreshRate,
    setDesiredActiveMode({refreshRate.getModeId(), event});
    setDesiredActiveMode({refreshRate.getModeId(), event});
}
}


void SurfaceFlinger::onHotplugReceived(int32_t sequenceId, hal::HWDisplayId hwcDisplayId,
void SurfaceFlinger::onComposerHalHotplug(hal::HWDisplayId hwcDisplayId,
                                          hal::Connection connection) {
                                          hal::Connection connection) {
    ALOGI("%s(%d, %" PRIu64 ", %s)", __FUNCTION__, sequenceId, hwcDisplayId,
    ALOGI("%s(%" PRIu64 ", %s)", __func__, hwcDisplayId,
          connection == hal::Connection::CONNECTED ? "connected" : "disconnected");
          connection == hal::Connection::CONNECTED ? "connected" : "disconnected");


    // Ignore events that do not have the right sequenceId.
    if (sequenceId != getBE().mComposerSequenceId) {
        return;
    }

    // Only lock if we're not on the main thread. This function is normally
    // Only lock if we're not on the main thread. This function is normally
    // called on a hwbinder thread, but for the primary display it's called on
    // called on a hwbinder thread, but for the primary display it's called on
    // the main thread with the state lock already held, so don't attempt to
    // the main thread with the state lock already held, so don't attempt to
@@ -1749,26 +1739,19 @@ void SurfaceFlinger::onHotplugReceived(int32_t sequenceId, hal::HWDisplayId hwcD
    setTransactionFlags(eDisplayTransactionNeeded);
    setTransactionFlags(eDisplayTransactionNeeded);
}
}


void SurfaceFlinger::onVsyncPeriodTimingChangedReceived(
void SurfaceFlinger::onComposerHalVsyncPeriodTimingChanged(
        int32_t sequenceId, hal::HWDisplayId /*display*/,
        hal::HWDisplayId, const hal::VsyncPeriodChangeTimeline& timeline) {
        const hal::VsyncPeriodChangeTimeline& updatedTimeline) {
    Mutex::Autolock lock(mStateLock);
    Mutex::Autolock lock(mStateLock);
    if (sequenceId != getBE().mComposerSequenceId) {
    mScheduler->onNewVsyncPeriodChangeTimeline(timeline);
        return;
    }
    mScheduler->onNewVsyncPeriodChangeTimeline(updatedTimeline);
}
}


void SurfaceFlinger::onSeamlessPossible(int32_t /*sequenceId*/, hal::HWDisplayId /*display*/) {
void SurfaceFlinger::onComposerHalSeamlessPossible(hal::HWDisplayId) {
    // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and
    // TODO(b/142753666): use constraints when calling to setActiveModeWithConstraints and
    // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE.
    // use this callback to know when to retry in case of SEAMLESS_NOT_POSSIBLE.
}
}


void SurfaceFlinger::onRefreshReceived(int sequenceId, hal::HWDisplayId /*hwcDisplayId*/) {
void SurfaceFlinger::onComposerHalRefresh(hal::HWDisplayId) {
    Mutex::Autolock lock(mStateLock);
    Mutex::Autolock lock(mStateLock);
    if (sequenceId != getBE().mComposerSequenceId) {
        return;
    }
    repaintEverythingForHWC();
    repaintEverythingForHWC();
}
}


@@ -5651,7 +5634,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r
                    Mutex::Autolock lock(mStateLock);
                    Mutex::Autolock lock(mStateLock);
                    hwcId = getHwComposer().getInternalHwcDisplayId();
                    hwcId = getHwComposer().getInternalHwcDisplayId();
                }
                }
                onHotplugReceived(getBE().mComposerSequenceId, *hwcId, hal::Connection::CONNECTED);
                onComposerHalHotplug(*hwcId, hal::Connection::CONNECTED);
                return NO_ERROR;
                return NO_ERROR;
            }
            }
            // Modify the max number of display frames stored within FrameTimeline
            // Modify the max number of display frames stored within FrameTimeline
Loading