Loading services/surfaceflinger/RegionSamplingThread.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -279,7 +279,7 @@ void RegionSamplingThread::captureSample() { { // TODO(b/159112860): Don't keep sp<DisplayDevice> outside of SF main thread const sp<const DisplayDevice> display = mFlinger.getDefaultDisplayDevice(); const sp<const DisplayDevice> display = mFlinger.getActiveDisplay(); displayWeak = display; layerStack = display->getLayerStack(); orientation = ui::Transform::toRotationFlags(display->getOrientation()); Loading services/surfaceflinger/Scheduler/Scheduler.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,12 @@ void Scheduler::setPacesetterDisplay(PhysicalDisplayId pacesetterId) { updatePhaseConfiguration(pacesetterId, pacesetterSelectorPtr()->getActiveMode().fps); } PhysicalDisplayId Scheduler::getPacesetterDisplayId() const { std::scoped_lock lock(mDisplayLock); LOG_ALWAYS_FATAL_IF(!mPacesetterDisplayId, "Missing a pacesetter!"); return *mPacesetterDisplayId; } void Scheduler::registerDisplay(PhysicalDisplayId displayId, RefreshRateSelectorPtr selectorPtr, PhysicalDisplayId activeDisplayId) { auto schedulePtr = Loading services/surfaceflinger/Scheduler/Scheduler.h +4 −2 Original line number Diff line number Diff line Loading @@ -98,6 +98,8 @@ public: void setPacesetterDisplay(PhysicalDisplayId) REQUIRES(kMainThreadContext) EXCLUDES(mDisplayLock, mVsyncConfigLock); PhysicalDisplayId getPacesetterDisplayId() const EXCLUDES(mDisplayLock); using RefreshRateSelectorPtr = std::shared_ptr<RefreshRateSelector>; using ConstVsyncSchedulePtr = std::shared_ptr<const VsyncSchedule>; Loading Loading @@ -549,8 +551,8 @@ private: ui::PhysicalDisplayMap<PhysicalDisplayId, Display> mDisplays GUARDED_BY(mDisplayLock) GUARDED_BY(kMainThreadContext); ftl::Optional<PhysicalDisplayId> mPacesetterDisplayId GUARDED_BY(mDisplayLock) GUARDED_BY(kMainThreadContext); // May be read from any thread, but must only be written from the main thread. ftl::Optional<PhysicalDisplayId> mPacesetterDisplayId GUARDED_BY(mDisplayLock); ftl::Optional<DisplayRef> pacesetterDisplayLocked() REQUIRES(mDisplayLock) { return static_cast<const Scheduler*>(this)->pacesetterDisplayLocked().transform( Loading services/surfaceflinger/SurfaceFlinger.cpp +18 −15 Original line number Diff line number Diff line Loading @@ -704,11 +704,11 @@ std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() con std::vector<PhysicalDisplayId> displayIds; displayIds.reserve(mPhysicalDisplays.size()); const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); displayIds.push_back(defaultDisplayId); const auto activeDisplayId = getActiveDisplayLocked()->getPhysicalId(); displayIds.push_back(activeDisplayId); for (const auto& [id, display] : mPhysicalDisplays) { if (id != defaultDisplayId) { if (id != activeDisplayId) { displayIds.push_back(id); } } Loading Loading @@ -960,7 +960,7 @@ void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { processDisplayAdded(token, state); mDrawingState.displays.add(token, state); display = getDefaultDisplayDeviceLocked(); display = getActiveDisplayLocked(); } LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); Loading Loading @@ -6465,7 +6465,7 @@ void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositio ClientCache::getInstance().dump(result); DebugEGLImageTracker::getInstance()->dump(result); if (const auto display = getDefaultDisplayDeviceLocked()) { if (const auto display = getActiveDisplayLocked()) { display->getCompositionDisplay()->getState().undefinedRegion.dump(result, "undefinedRegion"); StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", Loading @@ -6473,7 +6473,7 @@ void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositio } StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); if (const auto display = getDefaultDisplayDeviceLocked()) { if (const auto display = getActiveDisplayLocked()) { std::string peakFps, xDpi, yDpi; const auto activeMode = display->refreshRateSelector().getActiveMode(); if (const auto activeModePtr = activeMode.modePtr.get()) { Loading Loading @@ -6846,7 +6846,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r } // Is a DisplayColorSetting supported? case 1027: { const auto display = getDefaultDisplayDevice(); const auto display = getActiveDisplay(); if (!display) { return NAME_NOT_FOUND; } Loading Loading @@ -6929,7 +6929,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r case 1035: { // Parameters: // - (required) i32 mode id. // - (optional) i64 display id. Using default display if not provided. // - (optional) i64 display id. Using pacesetter display if not provided. // - (optional) f min render rate. Using mode's fps is not provided. // - (optional) f max render rate. Using mode's fps is not provided. Loading @@ -6938,7 +6938,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r const auto display = [&]() -> sp<IBinder> { uint64_t value; if (data.readUint64(&value) != NO_ERROR) { return getDefaultDisplayDevice()->getDisplayToken().promote(); return getPacesetterDisplay()->getDisplayToken().promote(); } if (const auto token = Loading Loading @@ -6976,7 +6976,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r return mScheduler ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); FTL_FAKE_GUARD(mStateLock, getPacesetterDisplayLocked()); // This is a little racy, but not in a way that hurts anything. As // we grab the defaultMode from the display manager policy, we could Loading @@ -6996,7 +6996,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r return mScheduler ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); FTL_FAKE_GUARD(mStateLock, getPacesetterDisplayLocked()); return setDesiredDisplayModeSpecsInternal( display, scheduler::RefreshRateSelector::NoOverridePolicy{}); Loading Loading @@ -7256,7 +7256,7 @@ void SurfaceFlinger::kernelTimerChanged(bool expired) { // Update the overlay on the main thread to avoid race conditions with // RefreshRateSelector::getActiveMode static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); const auto display = FTL_FAKE_GUARD(mStateLock, getPacesetterDisplayLocked()); if (!display) { ALOGW("%s: default display is null", __func__); return; Loading Loading @@ -7879,7 +7879,7 @@ bool SurfaceFlinger::getDisplayStateOnMainThread(ScreenshotArgs& args) { } if (display == nullptr) { display = getDefaultDisplayDeviceLocked(); display = getPacesetterDisplayLocked(); } if (display != nullptr) { Loading Loading @@ -8413,7 +8413,8 @@ status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { Fps maxRefreshRate = 60_Hz; if (!getHwComposer().isHeadless()) { if (const auto display = getDefaultDisplayDevice()) { const sp<const DisplayDevice> display = getPacesetterDisplay(); if (display) { maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; } } Loading @@ -8428,7 +8429,9 @@ uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t ui if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { refreshRate = *frameRateOverride; } else if (!getHwComposer().isHeadless()) { if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { const sp<const DisplayDevice> display = FTL_FAKE_GUARD(mStateLock, getPacesetterDisplayLocked()); if (display) { refreshRate = display->refreshRateSelector().getActiveMode().fps; } } Loading services/surfaceflinger/SurfaceFlinger.h +21 −6 Original line number Diff line number Diff line Loading @@ -1028,18 +1028,33 @@ private: return nullptr; } // Returns the primary display or (for foldables) the active display. sp<const DisplayDevice> getDefaultDisplayDeviceLocked() const REQUIRES(mStateLock) { return const_cast<SurfaceFlinger*>(this)->getDefaultDisplayDeviceLocked(); sp<const DisplayDevice> getPacesetterDisplayLocked() const REQUIRES(mStateLock) { return const_cast<SurfaceFlinger*>(this)->getPacesetterDisplayLocked(); } sp<DisplayDevice> getDefaultDisplayDeviceLocked() REQUIRES(mStateLock) { sp<DisplayDevice> getPacesetterDisplayLocked() REQUIRES(mStateLock) { if (!FlagManager::getInstance().pacesetter_selection()) { return getActiveDisplayLocked(); } return getDisplayDeviceLocked(mScheduler->getPacesetterDisplayId()); } sp<const DisplayDevice> getPacesetterDisplay() const EXCLUDES(mStateLock) { Mutex::Autolock lock(mStateLock); return getPacesetterDisplayLocked(); } sp<const DisplayDevice> getActiveDisplayLocked() const REQUIRES(mStateLock) { return const_cast<SurfaceFlinger*>(this)->getActiveDisplayLocked(); } sp<DisplayDevice> getActiveDisplayLocked() REQUIRES(mStateLock) { return getDisplayDeviceLocked(mActiveDisplayId); } sp<const DisplayDevice> getDefaultDisplayDevice() const EXCLUDES(mStateLock) { sp<const DisplayDevice> getActiveDisplay() const EXCLUDES(mStateLock) { Mutex::Autolock lock(mStateLock); return getDefaultDisplayDeviceLocked(); return getActiveDisplayLocked(); } using DisplayDeviceAndSnapshot = std::pair<sp<DisplayDevice>, display::DisplaySnapshotRef>; Loading Loading
services/surfaceflinger/RegionSamplingThread.cpp +1 −1 Original line number Diff line number Diff line Loading @@ -279,7 +279,7 @@ void RegionSamplingThread::captureSample() { { // TODO(b/159112860): Don't keep sp<DisplayDevice> outside of SF main thread const sp<const DisplayDevice> display = mFlinger.getDefaultDisplayDevice(); const sp<const DisplayDevice> display = mFlinger.getActiveDisplay(); displayWeak = display; layerStack = display->getLayerStack(); orientation = ui::Transform::toRotationFlags(display->getOrientation()); Loading
services/surfaceflinger/Scheduler/Scheduler.cpp +6 −0 Original line number Diff line number Diff line Loading @@ -133,6 +133,12 @@ void Scheduler::setPacesetterDisplay(PhysicalDisplayId pacesetterId) { updatePhaseConfiguration(pacesetterId, pacesetterSelectorPtr()->getActiveMode().fps); } PhysicalDisplayId Scheduler::getPacesetterDisplayId() const { std::scoped_lock lock(mDisplayLock); LOG_ALWAYS_FATAL_IF(!mPacesetterDisplayId, "Missing a pacesetter!"); return *mPacesetterDisplayId; } void Scheduler::registerDisplay(PhysicalDisplayId displayId, RefreshRateSelectorPtr selectorPtr, PhysicalDisplayId activeDisplayId) { auto schedulePtr = Loading
services/surfaceflinger/Scheduler/Scheduler.h +4 −2 Original line number Diff line number Diff line Loading @@ -98,6 +98,8 @@ public: void setPacesetterDisplay(PhysicalDisplayId) REQUIRES(kMainThreadContext) EXCLUDES(mDisplayLock, mVsyncConfigLock); PhysicalDisplayId getPacesetterDisplayId() const EXCLUDES(mDisplayLock); using RefreshRateSelectorPtr = std::shared_ptr<RefreshRateSelector>; using ConstVsyncSchedulePtr = std::shared_ptr<const VsyncSchedule>; Loading Loading @@ -549,8 +551,8 @@ private: ui::PhysicalDisplayMap<PhysicalDisplayId, Display> mDisplays GUARDED_BY(mDisplayLock) GUARDED_BY(kMainThreadContext); ftl::Optional<PhysicalDisplayId> mPacesetterDisplayId GUARDED_BY(mDisplayLock) GUARDED_BY(kMainThreadContext); // May be read from any thread, but must only be written from the main thread. ftl::Optional<PhysicalDisplayId> mPacesetterDisplayId GUARDED_BY(mDisplayLock); ftl::Optional<DisplayRef> pacesetterDisplayLocked() REQUIRES(mDisplayLock) { return static_cast<const Scheduler*>(this)->pacesetterDisplayLocked().transform( Loading
services/surfaceflinger/SurfaceFlinger.cpp +18 −15 Original line number Diff line number Diff line Loading @@ -704,11 +704,11 @@ std::vector<PhysicalDisplayId> SurfaceFlinger::getPhysicalDisplayIdsLocked() con std::vector<PhysicalDisplayId> displayIds; displayIds.reserve(mPhysicalDisplays.size()); const auto defaultDisplayId = getDefaultDisplayDeviceLocked()->getPhysicalId(); displayIds.push_back(defaultDisplayId); const auto activeDisplayId = getActiveDisplayLocked()->getPhysicalId(); displayIds.push_back(activeDisplayId); for (const auto& [id, display] : mPhysicalDisplays) { if (id != defaultDisplayId) { if (id != activeDisplayId) { displayIds.push_back(id); } } Loading Loading @@ -960,7 +960,7 @@ void SurfaceFlinger::init() FTL_FAKE_GUARD(kMainThreadContext) { processDisplayAdded(token, state); mDrawingState.displays.add(token, state); display = getDefaultDisplayDeviceLocked(); display = getActiveDisplayLocked(); } LOG_ALWAYS_FATAL_IF(!display, "Failed to configure the primary display"); Loading Loading @@ -6465,7 +6465,7 @@ void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositio ClientCache::getInstance().dump(result); DebugEGLImageTracker::getInstance()->dump(result); if (const auto display = getDefaultDisplayDeviceLocked()) { if (const auto display = getActiveDisplayLocked()) { display->getCompositionDisplay()->getState().undefinedRegion.dump(result, "undefinedRegion"); StringAppendF(&result, " orientation=%s, isPoweredOn=%d\n", Loading @@ -6473,7 +6473,7 @@ void SurfaceFlinger::dumpAll(const DumpArgs& args, const std::string& compositio } StringAppendF(&result, " transaction-flags : %08x\n", mTransactionFlags.load()); if (const auto display = getDefaultDisplayDeviceLocked()) { if (const auto display = getActiveDisplayLocked()) { std::string peakFps, xDpi, yDpi; const auto activeMode = display->refreshRateSelector().getActiveMode(); if (const auto activeModePtr = activeMode.modePtr.get()) { Loading Loading @@ -6846,7 +6846,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r } // Is a DisplayColorSetting supported? case 1027: { const auto display = getDefaultDisplayDevice(); const auto display = getActiveDisplay(); if (!display) { return NAME_NOT_FOUND; } Loading Loading @@ -6929,7 +6929,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r case 1035: { // Parameters: // - (required) i32 mode id. // - (optional) i64 display id. Using default display if not provided. // - (optional) i64 display id. Using pacesetter display if not provided. // - (optional) f min render rate. Using mode's fps is not provided. // - (optional) f max render rate. Using mode's fps is not provided. Loading @@ -6938,7 +6938,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r const auto display = [&]() -> sp<IBinder> { uint64_t value; if (data.readUint64(&value) != NO_ERROR) { return getDefaultDisplayDevice()->getDisplayToken().promote(); return getPacesetterDisplay()->getDisplayToken().promote(); } if (const auto token = Loading Loading @@ -6976,7 +6976,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r return mScheduler ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); FTL_FAKE_GUARD(mStateLock, getPacesetterDisplayLocked()); // This is a little racy, but not in a way that hurts anything. As // we grab the defaultMode from the display manager policy, we could Loading @@ -6996,7 +6996,7 @@ status_t SurfaceFlinger::onTransact(uint32_t code, const Parcel& data, Parcel* r return mScheduler ->schedule([this]() FTL_FAKE_GUARD(kMainThreadContext) { const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); FTL_FAKE_GUARD(mStateLock, getPacesetterDisplayLocked()); return setDesiredDisplayModeSpecsInternal( display, scheduler::RefreshRateSelector::NoOverridePolicy{}); Loading Loading @@ -7256,7 +7256,7 @@ void SurfaceFlinger::kernelTimerChanged(bool expired) { // Update the overlay on the main thread to avoid race conditions with // RefreshRateSelector::getActiveMode static_cast<void>(mScheduler->schedule([=, this]() FTL_FAKE_GUARD(kMainThreadContext) { const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked()); const auto display = FTL_FAKE_GUARD(mStateLock, getPacesetterDisplayLocked()); if (!display) { ALOGW("%s: default display is null", __func__); return; Loading Loading @@ -7879,7 +7879,7 @@ bool SurfaceFlinger::getDisplayStateOnMainThread(ScreenshotArgs& args) { } if (display == nullptr) { display = getDefaultDisplayDeviceLocked(); display = getPacesetterDisplayLocked(); } if (display != nullptr) { Loading Loading @@ -8413,7 +8413,8 @@ status_t SurfaceFlinger::getMaxAcquiredBufferCount(int* buffers) const { Fps maxRefreshRate = 60_Hz; if (!getHwComposer().isHeadless()) { if (const auto display = getDefaultDisplayDevice()) { const sp<const DisplayDevice> display = getPacesetterDisplay(); if (display) { maxRefreshRate = display->refreshRateSelector().getSupportedRefreshRateRange().max; } } Loading @@ -8428,7 +8429,9 @@ uint32_t SurfaceFlinger::getMaxAcquiredBufferCountForCurrentRefreshRate(uid_t ui if (const auto frameRateOverride = mScheduler->getFrameRateOverride(uid)) { refreshRate = *frameRateOverride; } else if (!getHwComposer().isHeadless()) { if (const auto display = FTL_FAKE_GUARD(mStateLock, getDefaultDisplayDeviceLocked())) { const sp<const DisplayDevice> display = FTL_FAKE_GUARD(mStateLock, getPacesetterDisplayLocked()); if (display) { refreshRate = display->refreshRateSelector().getActiveMode().fps; } } Loading
services/surfaceflinger/SurfaceFlinger.h +21 −6 Original line number Diff line number Diff line Loading @@ -1028,18 +1028,33 @@ private: return nullptr; } // Returns the primary display or (for foldables) the active display. sp<const DisplayDevice> getDefaultDisplayDeviceLocked() const REQUIRES(mStateLock) { return const_cast<SurfaceFlinger*>(this)->getDefaultDisplayDeviceLocked(); sp<const DisplayDevice> getPacesetterDisplayLocked() const REQUIRES(mStateLock) { return const_cast<SurfaceFlinger*>(this)->getPacesetterDisplayLocked(); } sp<DisplayDevice> getDefaultDisplayDeviceLocked() REQUIRES(mStateLock) { sp<DisplayDevice> getPacesetterDisplayLocked() REQUIRES(mStateLock) { if (!FlagManager::getInstance().pacesetter_selection()) { return getActiveDisplayLocked(); } return getDisplayDeviceLocked(mScheduler->getPacesetterDisplayId()); } sp<const DisplayDevice> getPacesetterDisplay() const EXCLUDES(mStateLock) { Mutex::Autolock lock(mStateLock); return getPacesetterDisplayLocked(); } sp<const DisplayDevice> getActiveDisplayLocked() const REQUIRES(mStateLock) { return const_cast<SurfaceFlinger*>(this)->getActiveDisplayLocked(); } sp<DisplayDevice> getActiveDisplayLocked() REQUIRES(mStateLock) { return getDisplayDeviceLocked(mActiveDisplayId); } sp<const DisplayDevice> getDefaultDisplayDevice() const EXCLUDES(mStateLock) { sp<const DisplayDevice> getActiveDisplay() const EXCLUDES(mStateLock) { Mutex::Autolock lock(mStateLock); return getDefaultDisplayDeviceLocked(); return getActiveDisplayLocked(); } using DisplayDeviceAndSnapshot = std::pair<sp<DisplayDevice>, display::DisplaySnapshotRef>; Loading