From 5690bde1e9192bc161ff6ae9fc80d8c4eaef6fd9 Mon Sep 17 00:00:00 2001 From: Dominik Laskowski Date: Thu, 23 Apr 2020 19:04:22 -0700 Subject: SF: Defer setDisplayBrightness to Binder thread setDisplayBrightness blocks for a long time so cannot run on the main thread. Keep display lookup on the main thread, but return a deferred future to the Binder thread and run it there. Bug: 154202427 Bug: 123715322 Test: systrace with backdoor to set brightness Change-Id: I88e60c95db5fdcaa1bf5ebb9711e3bf5ab6539a1 --- services/surfaceflinger/SurfaceFlinger.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'services/surfaceflinger/SurfaceFlinger.cpp') diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp index 29434990f6..794e8a7a44 100644 --- a/services/surfaceflinger/SurfaceFlinger.cpp +++ b/services/surfaceflinger/SurfaceFlinger.cpp @@ -108,6 +108,7 @@ #include "LayerVector.h" #include "MonitoredProducer.h" #include "NativeWindowSurface.h" +#include "Promise.h" #include "RefreshRateOverlay.h" #include "RegionSamplingThread.h" #include "Scheduler/DispSync.h" @@ -1491,14 +1492,15 @@ status_t SurfaceFlinger::setDisplayBrightness(const sp& displayToken, f return BAD_VALUE; } - return schedule([=]() -> status_t { + return promise::chain(schedule([=] { if (const auto displayId = getPhysicalDisplayIdLocked(displayToken)) { return getHwComposer().setDisplayBrightness(*displayId, brightness); } else { ALOGE("%s: Invalid display token %p", __FUNCTION__, displayToken.get()); - return NAME_NOT_FOUND; + return promise::yield(NAME_NOT_FOUND); } - }) + })) + .then([](std::future task) { return task; }) .get(); } -- cgit v1.2.3-59-g8ed1b