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

Commit e72ba5e2 authored by joenchen's avatar joenchen Committed by Joen Chen
Browse files

CE: flush the staged brightness to HWC before power off

After SurfaceFlinger receives the brightness commands, the commands are
sent to HWC until the next frame presents. However, no following frames
are present after the power mode is set to off, and HWC cannot receive
the last brightness commands.

This change forces SurfaceFlinger to flush the staged brightness to HWC
prior to execution of power off.

Bug: 239908529
Test: suspend and resume repeatedly
Change-Id: Ia8fb04399e757de16e06e6516d86bdfcfabd5a2e
parent 7fa3483d
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -56,6 +56,9 @@ public:
    // similar requests if needed.
    virtual void createClientCompositionCache(uint32_t cacheSize) = 0;

    // Sends the brightness setting to HWC
    virtual void applyDisplayBrightness(const bool applyImmediately) = 0;

protected:
    ~Display() = default;
};
+1 −0
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ public:
            const compositionengine::DisplayColorProfileCreationArgs&) override;
    void createRenderSurface(const compositionengine::RenderSurfaceCreationArgs&) override;
    void createClientCompositionCache(uint32_t cacheSize) override;
    void applyDisplayBrightness(const bool applyImmediately) override;

    // Internal helpers used by chooseCompositionStrategy()
    using ChangedTypes = android::HWComposer::DeviceRequestedChanges::ChangedTypes;
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ public:
    MOCK_METHOD1(createDisplayColorProfile, void(const DisplayColorProfileCreationArgs&));
    MOCK_METHOD1(createRenderSurface, void(const RenderSurfaceCreationArgs&));
    MOCK_METHOD1(createClientCompositionCache, void(uint32_t));
    MOCK_METHOD1(applyDisplayBrightness, void(const bool));
    MOCK_METHOD1(setPredictCompositionStrategy, void(bool));
};

+15 −10
Original line number Diff line number Diff line
@@ -203,23 +203,16 @@ void Display::setReleasedLayers(const compositionengine::CompositionRefreshArgs&
    setReleasedLayers(std::move(releasedLayers));
}

void Display::beginFrame() {
    Output::beginFrame();

    // If we don't have a HWC display, then we are done.
    const auto halDisplayId = HalDisplayId::tryCast(mId);
    if (!halDisplayId) {
        return;
    }

void Display::applyDisplayBrightness(const bool applyImmediately) {
    auto& hwc = getCompositionEngine().getHwComposer();
    const auto halDisplayId = HalDisplayId::tryCast(*getDisplayId());
    if (const auto physicalDisplayId = PhysicalDisplayId::tryCast(*halDisplayId);
        physicalDisplayId && getState().displayBrightness) {
        const status_t result =
                hwc.setDisplayBrightness(*physicalDisplayId, *getState().displayBrightness,
                                         getState().displayBrightnessNits,
                                         Hwc2::Composer::DisplayBrightnessOptions{
                                                 .applyImmediately = false})
                                                 .applyImmediately = applyImmediately})
                        .get();
        ALOGE_IF(result != NO_ERROR, "setDisplayBrightness failed for %s: %d, (%s)",
                 getName().c_str(), result, strerror(-result));
@@ -228,6 +221,18 @@ void Display::beginFrame() {
    editState().displayBrightness.reset();
}

void Display::beginFrame() {
    Output::beginFrame();

    // If we don't have a HWC display, then we are done.
    const auto halDisplayId = HalDisplayId::tryCast(mId);
    if (!halDisplayId) {
        return;
    }

    applyDisplayBrightness(false);
}

bool Display::chooseCompositionStrategy(
        std::optional<android::HWComposer::DeviceRequestedChanges>* outChanges) {
    ATRACE_CALL();
+9 −0
Original line number Diff line number Diff line
@@ -173,6 +173,15 @@ auto DisplayDevice::getInputInfo() const -> InputInfo {
}

void DisplayDevice::setPowerMode(hal::PowerMode mode) {
    if (mode == hal::PowerMode::OFF || mode == hal::PowerMode::ON) {
        if (mStagedBrightness && mBrightness != *mStagedBrightness) {
            getCompositionDisplay()->setNextBrightness(*mStagedBrightness);
            mBrightness = *mStagedBrightness;
        }
        mStagedBrightness = std::nullopt;
        getCompositionDisplay()->applyDisplayBrightness(true);
    }

    mPowerMode = mode;
    getCompositionDisplay()->setCompositionEnabled(mPowerMode != hal::PowerMode::OFF);
}