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

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

SF: Remove conditional lock in setPowerMode

The mCurrentState access in setPowerModeInternal was only for looking up
the sequence ID of the display.

Bug: 74619554
Test: Boot
Change-Id: If0fad8f19bf8680f247476c3ffe52667e061fdd3
parent 55ef412b
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -222,6 +222,7 @@ DisplayDevice::DisplayDevice(DisplayDeviceCreationArgs&& args)
      : lastCompositionHadVisibleLayers(false),
        mFlinger(args.flinger),
        mDisplayToken(args.displayToken),
        mSequenceId(args.sequenceId),
        mId(args.displayId),
        mNativeWindow(args.nativeWindow),
        mGraphicBuffer(nullptr),
+3 −0
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ public:

    const std::optional<DisplayId>& getId() const { return mId; }
    const wp<IBinder>& getDisplayToken() const { return mDisplayToken; }
    int32_t getSequenceId() const { return mSequenceId; }

    int32_t getSupportedPerFrameMetadata() const { return mSupportedPerFrameMetadata; }

@@ -205,6 +206,7 @@ public:
private:
    const sp<SurfaceFlinger> mFlinger;
    const wp<IBinder> mDisplayToken;
    const int32_t mSequenceId;

    std::optional<DisplayId> mId;

@@ -332,6 +334,7 @@ struct DisplayDeviceCreationArgs {
    const wp<IBinder> displayToken;
    const std::optional<DisplayId> displayId;

    int32_t sequenceId{0};
    bool isVirtual{false};
    bool isSecure{false};
    sp<ANativeWindow> nativeWindow;
+6 −12
Original line number Diff line number Diff line
@@ -1494,7 +1494,7 @@ void SurfaceFlinger::updateVrFlinger() {
    // Re-enable default display.
    display = getDefaultDisplayDeviceLocked();
    LOG_ALWAYS_FATAL_IF(!display);
    setPowerModeInternal(display, currentDisplayPowerMode, /*stateLockHeld*/ true);
    setPowerModeInternal(display, currentDisplayPowerMode);

    // Reset the timing values to account for the period of the swapped in HWC
    const auto activeConfig = getHwComposer().getActiveConfig(*display->getId());
@@ -2358,6 +2358,7 @@ sp<DisplayDevice> SurfaceFlinger::setupNewDisplayDeviceInternal(
        const DisplayDeviceState& state, const sp<DisplaySurface>& dispSurface,
        const sp<IGraphicBufferProducer>& producer) {
    DisplayDeviceCreationArgs creationArgs(this, displayToken, displayId);
    creationArgs.sequenceId = state.sequenceId;
    creationArgs.isVirtual = state.isVirtual();
    creationArgs.isSecure = state.isSecure;
    creationArgs.displaySurface = dispSurface;
@@ -3932,7 +3933,7 @@ void SurfaceFlinger::onInitializeDisplays() {
    const auto display = getDisplayDevice(displayToken);
    if (!display) return;

    setPowerModeInternal(display, HWC_POWER_MODE_NORMAL, /*stateLockHeld*/ false);
    setPowerModeInternal(display, HWC_POWER_MODE_NORMAL);

    const auto activeConfig = getHwComposer().getActiveConfig(*display->getId());
    const nsecs_t period = activeConfig->getVsyncPeriod();
@@ -3949,8 +3950,7 @@ void SurfaceFlinger::initializeDisplays() {
    postMessageAsync(new LambdaMessage([this] { onInitializeDisplays(); }));
}

void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, int mode,
                                          bool stateLockHeld) {
void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, int mode) {
    if (display->isVirtual()) {
        ALOGE("%s: Invalid operation on virtual display", __FUNCTION__);
        return;
@@ -3969,13 +3969,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, int
    display->setPowerMode(mode);

    if (mInterceptor->isEnabled()) {
        ConditionalLock lock(mStateLock, !stateLockHeld);
        ssize_t idx = mCurrentState.displays.indexOfKey(display->getDisplayToken());
        if (idx < 0) {
            ALOGW("Surface Interceptor SavePowerMode: invalid display token");
            return;
        }
        mInterceptor->savePowerModeUpdate(mCurrentState.displays.valueAt(idx).sequenceId, mode);
        mInterceptor->savePowerModeUpdate(display->getSequenceId(), mode);
    }

    if (currentMode == HWC_POWER_MODE_OFF) {
@@ -4070,7 +4064,7 @@ void SurfaceFlinger::setPowerMode(const sp<IBinder>& displayToken, int mode) {
        } else if (display->isVirtual()) {
            ALOGW("Attempt to set power mode %d for virtual display", mode);
        } else {
            setPowerModeInternal(display, mode, /*stateLockHeld*/ false);
            setPowerModeInternal(display, mode);
        }
    }));
}
+1 −1
Original line number Diff line number Diff line
@@ -524,7 +524,7 @@ private:
    // called on the main thread in response to setActiveConfig()
    void setActiveConfigInternal(const sp<DisplayDevice>& display, int mode);
    // called on the main thread in response to setPowerMode()
    void setPowerModeInternal(const sp<DisplayDevice>& display, int mode, bool stateLockHeld);
    void setPowerModeInternal(const sp<DisplayDevice>& display, int mode);

    // Called on the main thread in response to setActiveColorMode()
    void setActiveColorModeInternal(const sp<DisplayDevice>& display, ui::ColorMode colorMode,
+2 −3
Original line number Diff line number Diff line
@@ -227,9 +227,8 @@ public:

    auto onInitializeDisplays() { return mFlinger->onInitializeDisplays(); }

    auto setPowerModeInternal(const sp<DisplayDevice>& display, int mode,
                              bool stateLockHeld = false) {
        return mFlinger->setPowerModeInternal(display, mode, stateLockHeld);
    auto setPowerModeInternal(const sp<DisplayDevice>& display, int mode) {
        return mFlinger->setPowerModeInternal(display, mode);
    }

    auto onMessageReceived(int32_t what) { return mFlinger->onMessageReceived(what); }