Loading libs/gui/LayerState.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -550,7 +550,9 @@ bool InputWindowCommands::merge(const InputWindowCommands& other) { } bool InputWindowCommands::empty() const { return focusRequests.empty() && !syncInputWindows; bool empty = true; empty = focusRequests.empty() && !syncInputWindows; return empty; } void InputWindowCommands::clear() { Loading services/surfaceflinger/BackgroundExecutor.cpp +3 −5 Original line number Diff line number Diff line Loading @@ -32,9 +32,7 @@ BackgroundExecutor::BackgroundExecutor() : Singleton<BackgroundExecutor>() { std::vector<std::function<void()>> tasks; { std::unique_lock lock(mMutex); android::base::ScopedLockAssertion assumeLock(mMutex); mWorkAvailableCv.wait(lock, [&]() REQUIRES(mMutex) { return mDone || !mTasks.empty(); }); mWorkAvailableCv.wait(lock, [&]() { return mDone || !mTasks.empty(); }); tasks = std::move(mTasks); mTasks.clear(); done = mDone; Loading @@ -49,7 +47,7 @@ BackgroundExecutor::BackgroundExecutor() : Singleton<BackgroundExecutor>() { BackgroundExecutor::~BackgroundExecutor() { { std::scoped_lock lock(mMutex); std::unique_lock lock(mMutex); mDone = true; mWorkAvailableCv.notify_all(); } Loading @@ -59,7 +57,7 @@ BackgroundExecutor::~BackgroundExecutor() { } void BackgroundExecutor::execute(std::function<void()> task) { std::scoped_lock lock(mMutex); std::unique_lock lock(mMutex); mTasks.emplace_back(std::move(task)); mWorkAvailableCv.notify_all(); } Loading services/surfaceflinger/BackgroundExecutor.h +3 −4 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ #pragma once #include <android-base/thread_annotations.h> #include <utils/Singleton.h> #include <condition_variable> #include <mutex> Loading @@ -34,10 +33,10 @@ public: private: std::mutex mMutex; std::condition_variable mWorkAvailableCv GUARDED_BY(mMutex); bool mDone GUARDED_BY(mMutex) = false; std::vector<std::function<void()>> mTasks GUARDED_BY(mMutex); std::condition_variable mWorkAvailableCv; std::thread mThread; bool mDone = false; std::vector<std::function<void()>> mTasks; }; } // namespace android services/surfaceflinger/SurfaceFlinger.cpp +22 −39 Original line number Diff line number Diff line Loading @@ -93,7 +93,6 @@ #include <type_traits> #include <unordered_map> #include "BackgroundExecutor.h" #include "BufferLayer.h" #include "BufferQueueLayer.h" #include "BufferStateLayer.h" Loading Loading @@ -516,7 +515,7 @@ void SurfaceFlinger::binderDied(const wp<IBinder>&) { mBootFinished = false; // Sever the link to inputflinger since it's gone as well. BackgroundExecutor::getInstance().execute([=] { mInputFlinger = nullptr; }); static_cast<void>(mScheduler->schedule([=] { mInputFlinger = nullptr; })); // restore initial conditions (default device unblank, etc) initializeDisplays(); Loading Loading @@ -727,15 +726,13 @@ void SurfaceFlinger::bootFinished() { sp<IBinder> input(defaultServiceManager()->getService(String16("inputflinger"))); BackgroundExecutor::getInstance().execute([=] { static_cast<void>(mScheduler->schedule([=] { if (input == nullptr) { ALOGE("Failed to link to input service"); } else { mInputFlinger = interface_cast<os::IInputFlinger>(input); } }); static_cast<void>(mScheduler->schedule([=] { readPersistentProperties(); mPowerAdvisor.onBootFinished(); mBootStage = BootStage::FINISHED; Loading Loading @@ -3053,48 +3050,32 @@ void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { void SurfaceFlinger::updateInputFlinger() { ATRACE_CALL(); std::vector<WindowInfo> windowInfos; std::vector<DisplayInfo> displayInfos; bool updateWindowInfo = false; if (mVisibleRegionsDirty || mInputInfoChanged) { mInputInfoChanged = false; updateWindowInfo = true; buildWindowInfos(windowInfos, displayInfos); } if (!updateWindowInfo && mInputWindowCommands.empty()) { return; } BackgroundExecutor::getInstance().execute([updateWindowInfo, windowInfos = std::move(windowInfos), displayInfos = std::move(displayInfos), inputWindowCommands = std::move(mInputWindowCommands), this]() { ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); if (!mInputFlinger) { return; } if (updateWindowInfo) { mWindowInfosListenerInvoker->windowInfosChanged(windowInfos, displayInfos, inputWindowCommands.syncInputWindows); } else if (inputWindowCommands.syncInputWindows) { if (mVisibleRegionsDirty || mInputInfoChanged) { mInputInfoChanged = false; notifyWindowInfos(); } else if (mInputWindowCommands.syncInputWindows) { // If the caller requested to sync input windows, but there are no // changes to input windows, notify immediately. windowInfosReported(); } for (const auto& focusRequest : inputWindowCommands.focusRequests) { for (const auto& focusRequest : mInputWindowCommands.focusRequests) { mInputFlinger->setFocusedWindow(focusRequest); } }); mInputWindowCommands.clear(); } void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, std::vector<DisplayInfo>& outDisplayInfos) { void SurfaceFlinger::notifyWindowInfos() { std::vector<WindowInfo> windowInfos; std::vector<DisplayInfo> displayInfos; std::unordered_map<uint32_t /*layerStackId*/, std::pair<bool /* isSecure */, const ui::Transform>> inputDisplayDetails; for (const auto& [_, display] : ON_MAIN_THREAD(mDisplays)) { if (!display->receivesInput()) { continue; Loading @@ -3108,7 +3089,7 @@ void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, layerStackId); continue; } outDisplayInfos.emplace_back(info); displayInfos.emplace_back(info); } mDrawingState.traverseInReverseZOrder([&](Layer* layer) { Loading @@ -3128,8 +3109,10 @@ void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, layer->getDebugName(), layerStackId); } outWindowInfos.push_back(layer->fillInputInfo(displayTransform, isSecure)); windowInfos.push_back(layer->fillInputInfo(displayTransform, isSecure)); }); mWindowInfosListenerInvoker->windowInfosChanged(windowInfos, displayInfos, mInputWindowCommands.syncInputWindows); } void SurfaceFlinger::updateCursorAsync() { Loading services/surfaceflinger/SurfaceFlinger.h +1 −3 Original line number Diff line number Diff line Loading @@ -690,8 +690,7 @@ private: void updateLayerGeometry(); void updateInputFlinger(); void buildWindowInfos(std::vector<gui::WindowInfo>& outWindowInfos, std::vector<gui::DisplayInfo>& outDisplayInfos); void notifyWindowInfos(); void commitInputWindowCommands() REQUIRES(mStateLock); void updateCursorAsync(); Loading Loading @@ -1295,7 +1294,6 @@ private: const float mInternalDisplayDensity; const float mEmulatedDisplayDensity; // Should only be accessed by BackgroundExecutor thread. sp<os::IInputFlinger> mInputFlinger; // Should only be accessed by the main thread. InputWindowCommands mInputWindowCommands; Loading Loading
libs/gui/LayerState.cpp +3 −1 Original line number Diff line number Diff line Loading @@ -550,7 +550,9 @@ bool InputWindowCommands::merge(const InputWindowCommands& other) { } bool InputWindowCommands::empty() const { return focusRequests.empty() && !syncInputWindows; bool empty = true; empty = focusRequests.empty() && !syncInputWindows; return empty; } void InputWindowCommands::clear() { Loading
services/surfaceflinger/BackgroundExecutor.cpp +3 −5 Original line number Diff line number Diff line Loading @@ -32,9 +32,7 @@ BackgroundExecutor::BackgroundExecutor() : Singleton<BackgroundExecutor>() { std::vector<std::function<void()>> tasks; { std::unique_lock lock(mMutex); android::base::ScopedLockAssertion assumeLock(mMutex); mWorkAvailableCv.wait(lock, [&]() REQUIRES(mMutex) { return mDone || !mTasks.empty(); }); mWorkAvailableCv.wait(lock, [&]() { return mDone || !mTasks.empty(); }); tasks = std::move(mTasks); mTasks.clear(); done = mDone; Loading @@ -49,7 +47,7 @@ BackgroundExecutor::BackgroundExecutor() : Singleton<BackgroundExecutor>() { BackgroundExecutor::~BackgroundExecutor() { { std::scoped_lock lock(mMutex); std::unique_lock lock(mMutex); mDone = true; mWorkAvailableCv.notify_all(); } Loading @@ -59,7 +57,7 @@ BackgroundExecutor::~BackgroundExecutor() { } void BackgroundExecutor::execute(std::function<void()> task) { std::scoped_lock lock(mMutex); std::unique_lock lock(mMutex); mTasks.emplace_back(std::move(task)); mWorkAvailableCv.notify_all(); } Loading
services/surfaceflinger/BackgroundExecutor.h +3 −4 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ #pragma once #include <android-base/thread_annotations.h> #include <utils/Singleton.h> #include <condition_variable> #include <mutex> Loading @@ -34,10 +33,10 @@ public: private: std::mutex mMutex; std::condition_variable mWorkAvailableCv GUARDED_BY(mMutex); bool mDone GUARDED_BY(mMutex) = false; std::vector<std::function<void()>> mTasks GUARDED_BY(mMutex); std::condition_variable mWorkAvailableCv; std::thread mThread; bool mDone = false; std::vector<std::function<void()>> mTasks; }; } // namespace android
services/surfaceflinger/SurfaceFlinger.cpp +22 −39 Original line number Diff line number Diff line Loading @@ -93,7 +93,6 @@ #include <type_traits> #include <unordered_map> #include "BackgroundExecutor.h" #include "BufferLayer.h" #include "BufferQueueLayer.h" #include "BufferStateLayer.h" Loading Loading @@ -516,7 +515,7 @@ void SurfaceFlinger::binderDied(const wp<IBinder>&) { mBootFinished = false; // Sever the link to inputflinger since it's gone as well. BackgroundExecutor::getInstance().execute([=] { mInputFlinger = nullptr; }); static_cast<void>(mScheduler->schedule([=] { mInputFlinger = nullptr; })); // restore initial conditions (default device unblank, etc) initializeDisplays(); Loading Loading @@ -727,15 +726,13 @@ void SurfaceFlinger::bootFinished() { sp<IBinder> input(defaultServiceManager()->getService(String16("inputflinger"))); BackgroundExecutor::getInstance().execute([=] { static_cast<void>(mScheduler->schedule([=] { if (input == nullptr) { ALOGE("Failed to link to input service"); } else { mInputFlinger = interface_cast<os::IInputFlinger>(input); } }); static_cast<void>(mScheduler->schedule([=] { readPersistentProperties(); mPowerAdvisor.onBootFinished(); mBootStage = BootStage::FINISHED; Loading Loading @@ -3053,48 +3050,32 @@ void SurfaceFlinger::commitTransactionsLocked(uint32_t transactionFlags) { void SurfaceFlinger::updateInputFlinger() { ATRACE_CALL(); std::vector<WindowInfo> windowInfos; std::vector<DisplayInfo> displayInfos; bool updateWindowInfo = false; if (mVisibleRegionsDirty || mInputInfoChanged) { mInputInfoChanged = false; updateWindowInfo = true; buildWindowInfos(windowInfos, displayInfos); } if (!updateWindowInfo && mInputWindowCommands.empty()) { return; } BackgroundExecutor::getInstance().execute([updateWindowInfo, windowInfos = std::move(windowInfos), displayInfos = std::move(displayInfos), inputWindowCommands = std::move(mInputWindowCommands), this]() { ATRACE_NAME("BackgroundExecutor::updateInputFlinger"); if (!mInputFlinger) { return; } if (updateWindowInfo) { mWindowInfosListenerInvoker->windowInfosChanged(windowInfos, displayInfos, inputWindowCommands.syncInputWindows); } else if (inputWindowCommands.syncInputWindows) { if (mVisibleRegionsDirty || mInputInfoChanged) { mInputInfoChanged = false; notifyWindowInfos(); } else if (mInputWindowCommands.syncInputWindows) { // If the caller requested to sync input windows, but there are no // changes to input windows, notify immediately. windowInfosReported(); } for (const auto& focusRequest : inputWindowCommands.focusRequests) { for (const auto& focusRequest : mInputWindowCommands.focusRequests) { mInputFlinger->setFocusedWindow(focusRequest); } }); mInputWindowCommands.clear(); } void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, std::vector<DisplayInfo>& outDisplayInfos) { void SurfaceFlinger::notifyWindowInfos() { std::vector<WindowInfo> windowInfos; std::vector<DisplayInfo> displayInfos; std::unordered_map<uint32_t /*layerStackId*/, std::pair<bool /* isSecure */, const ui::Transform>> inputDisplayDetails; for (const auto& [_, display] : ON_MAIN_THREAD(mDisplays)) { if (!display->receivesInput()) { continue; Loading @@ -3108,7 +3089,7 @@ void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, layerStackId); continue; } outDisplayInfos.emplace_back(info); displayInfos.emplace_back(info); } mDrawingState.traverseInReverseZOrder([&](Layer* layer) { Loading @@ -3128,8 +3109,10 @@ void SurfaceFlinger::buildWindowInfos(std::vector<WindowInfo>& outWindowInfos, layer->getDebugName(), layerStackId); } outWindowInfos.push_back(layer->fillInputInfo(displayTransform, isSecure)); windowInfos.push_back(layer->fillInputInfo(displayTransform, isSecure)); }); mWindowInfosListenerInvoker->windowInfosChanged(windowInfos, displayInfos, mInputWindowCommands.syncInputWindows); } void SurfaceFlinger::updateCursorAsync() { Loading
services/surfaceflinger/SurfaceFlinger.h +1 −3 Original line number Diff line number Diff line Loading @@ -690,8 +690,7 @@ private: void updateLayerGeometry(); void updateInputFlinger(); void buildWindowInfos(std::vector<gui::WindowInfo>& outWindowInfos, std::vector<gui::DisplayInfo>& outDisplayInfos); void notifyWindowInfos(); void commitInputWindowCommands() REQUIRES(mStateLock); void updateCursorAsync(); Loading Loading @@ -1295,7 +1294,6 @@ private: const float mInternalDisplayDensity; const float mEmulatedDisplayDensity; // Should only be accessed by BackgroundExecutor thread. sp<os::IInputFlinger> mInputFlinger; // Should only be accessed by the main thread. InputWindowCommands mInputWindowCommands; Loading