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

Commit 39dfc94b authored by Dominik Laskowski's avatar Dominik Laskowski
Browse files

SF: Avoid a few nullable sp<DisplayDevice> params

Bug: 255635821
Test: Build
Change-Id: I6c84b89d8b532eca581530931a8b876c37ca3189
parent 82a999b8
Loading
Loading
Loading
Loading
+17 −17
Original line number Original line Diff line number Diff line
@@ -3304,7 +3304,7 @@ void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken,


            // TODO(b/175678251) Call a listener instead.
            // TODO(b/175678251) Call a listener instead.
            if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) {
            if (currentState.physical->hwcDisplayId == getHwComposer().getPrimaryHwcDisplayId()) {
                updateInternalDisplayVsyncLocked(display);
                updateActiveDisplayVsyncLocked(*display);
            }
            }
        }
        }
        return;
        return;
@@ -3332,15 +3332,15 @@ void SurfaceFlinger::processDisplayChanged(const wp<IBinder>& displayToken,
            display->setDisplaySize(currentState.width, currentState.height);
            display->setDisplaySize(currentState.width, currentState.height);


            if (display->getId() == mActiveDisplayId) {
            if (display->getId() == mActiveDisplayId) {
                onActiveDisplaySizeChanged(display);
                onActiveDisplaySizeChanged(*display);
            }
            }
        }
        }
    }
    }
}
}


void SurfaceFlinger::updateInternalDisplayVsyncLocked(const sp<DisplayDevice>& activeDisplay) {
void SurfaceFlinger::updateActiveDisplayVsyncLocked(const DisplayDevice& activeDisplay) {
    mVsyncConfiguration->reset();
    mVsyncConfiguration->reset();
    const Fps refreshRate = activeDisplay->getActiveMode().fps;
    const Fps refreshRate = activeDisplay.getActiveMode().fps;
    updatePhaseConfiguration(refreshRate);
    updatePhaseConfiguration(refreshRate);
    mRefreshRateStats->setRefreshRate(refreshRate);
    mRefreshRateStats->setRefreshRate(refreshRate);
}
}
@@ -4985,7 +4985,7 @@ void SurfaceFlinger::setPowerModeInternal(const sp<DisplayDevice>& display, hal:


        static bool sPrimaryDisplay = true;
        static bool sPrimaryDisplay = true;
        if (sPrimaryDisplay || activeDisplayChanged) {
        if (sPrimaryDisplay || activeDisplayChanged) {
            onActiveDisplayChangedLocked(activeDisplay, display);
            onActiveDisplayChangedLocked(activeDisplay.get(), *display);
            sPrimaryDisplay = false;
            sPrimaryDisplay = false;
        }
        }


@@ -7267,35 +7267,35 @@ void SurfaceFlinger::sample() {
    mRegionSamplingThread->onCompositionComplete(mScheduler->getScheduledFrameTime());
    mRegionSamplingThread->onCompositionComplete(mScheduler->getScheduledFrameTime());
}
}


void SurfaceFlinger::onActiveDisplaySizeChanged(const sp<const DisplayDevice>& activeDisplay) {
void SurfaceFlinger::onActiveDisplaySizeChanged(const DisplayDevice& activeDisplay) {
    mScheduler->onActiveDisplayAreaChanged(activeDisplay->getWidth() * activeDisplay->getHeight());
    mScheduler->onActiveDisplayAreaChanged(activeDisplay.getWidth() * activeDisplay.getHeight());
    getRenderEngine().onActiveDisplaySizeChanged(activeDisplay->getSize());
    getRenderEngine().onActiveDisplaySizeChanged(activeDisplay.getSize());
}
}


void SurfaceFlinger::onActiveDisplayChangedLocked(const sp<DisplayDevice>& inactiveDisplay,
void SurfaceFlinger::onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr,
                                                  const sp<DisplayDevice>& activeDisplay) {
                                                  const DisplayDevice& activeDisplay) {
    ATRACE_CALL();
    ATRACE_CALL();


    if (inactiveDisplay) {
    if (inactiveDisplayPtr) {
        inactiveDisplay->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false);
        inactiveDisplayPtr->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(false);
    }
    }


    mActiveDisplayId = activeDisplay->getPhysicalId();
    mActiveDisplayId = activeDisplay.getPhysicalId();
    activeDisplay->getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true);
    activeDisplay.getCompositionDisplay()->setLayerCachingTexturePoolEnabled(true);


    updateInternalDisplayVsyncLocked(activeDisplay);
    updateActiveDisplayVsyncLocked(activeDisplay);
    mScheduler->setModeChangePending(false);
    mScheduler->setModeChangePending(false);
    mScheduler->setLeaderDisplay(mActiveDisplayId);
    mScheduler->setLeaderDisplay(mActiveDisplayId);


    onActiveDisplaySizeChanged(activeDisplay);
    onActiveDisplaySizeChanged(activeDisplay);
    mActiveDisplayTransformHint = activeDisplay->getTransformHint();
    mActiveDisplayTransformHint = activeDisplay.getTransformHint();


    // The policy of the new active/leader display may have changed while it was inactive. In that
    // The policy of the new active/leader display may have changed while it was inactive. In that
    // case, its preferred mode has not been propagated to HWC (via setDesiredActiveMode). In either
    // case, its preferred mode has not been propagated to HWC (via setDesiredActiveMode). In either
    // case, the Scheduler's cachedModeChangedParams must be initialized to the newly active mode,
    // case, the Scheduler's cachedModeChangedParams must be initialized to the newly active mode,
    // and the kernel idle timer of the newly active display must be toggled.
    // and the kernel idle timer of the newly active display must be toggled.
    constexpr bool kForce = true;
    constexpr bool kForce = true;
    applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay->refreshRateSelector(), kForce);
    applyRefreshRateSelectorPolicy(mActiveDisplayId, activeDisplay.refreshRateSelector(), kForce);
}
}


status_t SurfaceFlinger::addWindowInfosListener(
status_t SurfaceFlinger::addWindowInfosListener(
+4 −6
Original line number Original line Diff line number Diff line
@@ -1008,13 +1008,11 @@ private:
    VirtualDisplayId acquireVirtualDisplay(ui::Size, ui::PixelFormat) REQUIRES(mStateLock);
    VirtualDisplayId acquireVirtualDisplay(ui::Size, ui::PixelFormat) REQUIRES(mStateLock);
    void releaseVirtualDisplay(VirtualDisplayId);
    void releaseVirtualDisplay(VirtualDisplayId);


    // TODO(b/255635821): Replace pointers with references. `inactiveDisplay` is only ever `nullptr`
    void onActiveDisplayChangedLocked(const DisplayDevice* inactiveDisplayPtr,
    // in tests, and `activeDisplay` must not be `nullptr` as a precondition.
                                      const DisplayDevice& activeDisplay)
    void onActiveDisplayChangedLocked(const sp<DisplayDevice>& inactiveDisplay,
                                      const sp<DisplayDevice>& activeDisplay)
            REQUIRES(mStateLock, kMainThreadContext);
            REQUIRES(mStateLock, kMainThreadContext);


    void onActiveDisplaySizeChanged(const sp<const DisplayDevice>&);
    void onActiveDisplaySizeChanged(const DisplayDevice&);


    /*
    /*
     * Debugging & dumpsys
     * Debugging & dumpsys
@@ -1080,7 +1078,7 @@ private:
                                               std::chrono::nanoseconds presentLatency);
                                               std::chrono::nanoseconds presentLatency);
    int getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const;
    int getMaxAcquiredBufferCountForRefreshRate(Fps refreshRate) const;


    void updateInternalDisplayVsyncLocked(const sp<DisplayDevice>& activeDisplay)
    void updateActiveDisplayVsyncLocked(const DisplayDevice& activeDisplay)
            REQUIRES(mStateLock, kMainThreadContext);
            REQUIRES(mStateLock, kMainThreadContext);


    bool isHdrLayer(const frontend::LayerSnapshot& snapshot) const;
    bool isHdrLayer(const frontend::LayerSnapshot& snapshot) const;
+6 −6
Original line number Original line Diff line number Diff line
@@ -119,7 +119,7 @@ TEST_F(DisplayModeSwitchingTest, changeRefreshRate_OnActiveDisplay_WithRefreshRe
    ASSERT_FALSE(mDisplay->getDesiredActiveMode().has_value());
    ASSERT_FALSE(mDisplay->getDesiredActiveMode().has_value());
    ASSERT_EQ(mDisplay->getActiveMode().modePtr->getId(), kModeId60);
    ASSERT_EQ(mDisplay->getActiveMode().modePtr->getId(), kModeId60);


    mFlinger.onActiveDisplayChanged(mDisplay);
    mFlinger.onActiveDisplayChanged(*mDisplay);


    mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
    mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
                                        mock::createDisplayModeSpecs(kModeId90.value(), false, 0,
                                        mock::createDisplayModeSpecs(kModeId90.value(), false, 0,
@@ -159,7 +159,7 @@ TEST_F(DisplayModeSwitchingTest, changeRefreshRate_OnActiveDisplay_WithoutRefres


    ASSERT_FALSE(mDisplay->getDesiredActiveMode().has_value());
    ASSERT_FALSE(mDisplay->getDesiredActiveMode().has_value());


    mFlinger.onActiveDisplayChanged(mDisplay);
    mFlinger.onActiveDisplayChanged(*mDisplay);


    mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
    mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
                                        mock::createDisplayModeSpecs(kModeId90.value(), true, 0,
                                        mock::createDisplayModeSpecs(kModeId90.value(), true, 0,
@@ -195,7 +195,7 @@ TEST_F(DisplayModeSwitchingTest, twoConsecutiveSetDesiredDisplayModeSpecs) {
    ASSERT_FALSE(mDisplay->getDesiredActiveMode().has_value());
    ASSERT_FALSE(mDisplay->getDesiredActiveMode().has_value());
    ASSERT_EQ(mDisplay->getActiveMode().modePtr->getId(), kModeId60);
    ASSERT_EQ(mDisplay->getActiveMode().modePtr->getId(), kModeId60);


    mFlinger.onActiveDisplayChanged(mDisplay);
    mFlinger.onActiveDisplayChanged(*mDisplay);


    mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
    mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
                                        mock::createDisplayModeSpecs(kModeId90.value(), false, 0,
                                        mock::createDisplayModeSpecs(kModeId90.value(), false, 0,
@@ -238,7 +238,7 @@ TEST_F(DisplayModeSwitchingTest, changeResolution_OnActiveDisplay_WithoutRefresh
    ASSERT_FALSE(mDisplay->getDesiredActiveMode().has_value());
    ASSERT_FALSE(mDisplay->getDesiredActiveMode().has_value());
    ASSERT_EQ(mDisplay->getActiveMode().modePtr->getId(), kModeId60);
    ASSERT_EQ(mDisplay->getActiveMode().modePtr->getId(), kModeId60);


    mFlinger.onActiveDisplayChanged(mDisplay);
    mFlinger.onActiveDisplayChanged(*mDisplay);


    mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
    mFlinger.setDesiredDisplayModeSpecs(mDisplay->getDisplayToken().promote(),
                                        mock::createDisplayModeSpecs(kModeId90_4K.value(), false, 0,
                                        mock::createDisplayModeSpecs(kModeId90_4K.value(), false, 0,
@@ -315,7 +315,7 @@ TEST_F(DisplayModeSwitchingTest, multiDisplay) {
    EXPECT_EQ(innerDisplay->getActiveMode().modePtr->getId(), kModeId60);
    EXPECT_EQ(innerDisplay->getActiveMode().modePtr->getId(), kModeId60);
    EXPECT_EQ(outerDisplay->getActiveMode().modePtr->getId(), kModeId120);
    EXPECT_EQ(outerDisplay->getActiveMode().modePtr->getId(), kModeId120);


    mFlinger.onActiveDisplayChanged(innerDisplay);
    mFlinger.onActiveDisplayChanged(*innerDisplay);


    EXPECT_EQ(NO_ERROR,
    EXPECT_EQ(NO_ERROR,
              mFlinger.setDesiredDisplayModeSpecs(innerDisplay->getDisplayToken().promote(),
              mFlinger.setDesiredDisplayModeSpecs(innerDisplay->getDisplayToken().promote(),
@@ -359,7 +359,7 @@ TEST_F(DisplayModeSwitchingTest, multiDisplay) {
    EXPECT_FALSE(outerDisplay->getDesiredActiveMode());
    EXPECT_FALSE(outerDisplay->getDesiredActiveMode());
    EXPECT_EQ(outerDisplay->getActiveMode().modePtr->getId(), kModeId120);
    EXPECT_EQ(outerDisplay->getActiveMode().modePtr->getId(), kModeId120);


    mFlinger.onActiveDisplayChanged(outerDisplay);
    mFlinger.onActiveDisplayChanged(*outerDisplay);


    // No transition on the inner display.
    // No transition on the inner display.
    EXPECT_FALSE(innerDisplay->getDesiredActiveMode());
    EXPECT_FALSE(innerDisplay->getDesiredActiveMode());
+1 −1
Original line number Original line Diff line number Diff line
@@ -473,7 +473,7 @@ public:
        return mFlinger->setDesiredDisplayModeSpecs(displayToken, specs);
        return mFlinger->setDesiredDisplayModeSpecs(displayToken, specs);
    }
    }


    void onActiveDisplayChanged(const sp<DisplayDevice>& activeDisplay) {
    void onActiveDisplayChanged(const DisplayDevice& activeDisplay) {
        Mutex::Autolock lock(mFlinger->mStateLock);
        Mutex::Autolock lock(mFlinger->mStateLock);
        ftl::FakeGuard guard(kMainThreadContext);
        ftl::FakeGuard guard(kMainThreadContext);
        mFlinger->onActiveDisplayChangedLocked(nullptr, activeDisplay);
        mFlinger->onActiveDisplayChangedLocked(nullptr, activeDisplay);