Revert "SF: Update InputFlinger outside main thread"
This reverts commit 42a27b5657975485a72033736f37bfe6de0e21a8.
Reason for revert: <Breaking presubmit tests>
Bug: 207839663
Change-Id: Ic066d5a44339128a59e8aa3bb488a41cad13cf76
diff --git a/services/surfaceflinger/BackgroundExecutor.cpp b/services/surfaceflinger/BackgroundExecutor.cpp
index de8e6b3..3663cdb 100644
--- a/services/surfaceflinger/BackgroundExecutor.cpp
+++ b/services/surfaceflinger/BackgroundExecutor.cpp
@@ -32,9 +32,7 @@
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;
@@ -49,7 +47,7 @@
BackgroundExecutor::~BackgroundExecutor() {
{
- std::scoped_lock lock(mMutex);
+ std::unique_lock lock(mMutex);
mDone = true;
mWorkAvailableCv.notify_all();
}
@@ -59,7 +57,7 @@
}
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();
}
diff --git a/services/surfaceflinger/BackgroundExecutor.h b/services/surfaceflinger/BackgroundExecutor.h
index 6db7dda..6f6d305 100644
--- a/services/surfaceflinger/BackgroundExecutor.h
+++ b/services/surfaceflinger/BackgroundExecutor.h
@@ -16,7 +16,6 @@
#pragma once
-#include <android-base/thread_annotations.h>
#include <utils/Singleton.h>
#include <condition_variable>
#include <mutex>
@@ -34,10 +33,10 @@
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
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 27fc942..93f8406 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -93,7 +93,6 @@
#include <type_traits>
#include <unordered_map>
-#include "BackgroundExecutor.h"
#include "BufferLayer.h"
#include "BufferQueueLayer.h"
#include "BufferStateLayer.h"
@@ -509,7 +508,7 @@
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();
@@ -720,15 +719,13 @@
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;
@@ -3007,48 +3004,32 @@
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()) {
+ if (!mInputFlinger) {
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 the caller requested to sync input windows, but there are no
- // changes to input windows, notify immediately.
- windowInfosReported();
- }
- for (const auto& focusRequest : inputWindowCommands.focusRequests) {
- mInputFlinger->setFocusedWindow(focusRequest);
- }
- });
+ 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 : 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;
@@ -3062,7 +3043,7 @@
layerStackId);
continue;
}
- outDisplayInfos.emplace_back(info);
+ displayInfos.emplace_back(info);
}
mDrawingState.traverseInReverseZOrder([&](Layer* layer) {
@@ -3082,8 +3063,10 @@
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() {
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 353f747..6093be9 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -689,8 +689,7 @@
void updateLayerGeometry();
void updateInputFlinger();
- void buildWindowInfos(std::vector<gui::WindowInfo>& outWindowInfos,
- std::vector<gui::DisplayInfo>& outDisplayInfos);
+ void notifyWindowInfos();
void commitInputWindowCommands() REQUIRES(mStateLock);
void updateCursorAsync();
@@ -1290,7 +1289,6 @@
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;