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
diff --git a/services/surfaceflinger/DisplayHardware/HWC2.h b/services/surfaceflinger/DisplayHardware/HWC2.h
index af31df8..f4c7fdd 100644
--- a/services/surfaceflinger/DisplayHardware/HWC2.h
+++ b/services/surfaceflinger/DisplayHardware/HWC2.h
@@ -27,6 +27,7 @@
#include <utils/Timers.h>
#include <functional>
+#include <future>
#include <string>
#include <unordered_map>
#include <unordered_set>
@@ -221,18 +222,18 @@
[[clang::warn_unused_result]] virtual hal::Error presentOrValidate(
uint32_t* outNumTypes, uint32_t* outNumRequests,
android::sp<android::Fence>* outPresentFence, uint32_t* state) = 0;
- [[clang::warn_unused_result]] virtual hal::Error setDisplayBrightness(
- float brightness) const = 0;
+ [[clang::warn_unused_result]] virtual std::future<hal::Error> setDisplayBrightness(
+ float brightness) = 0;
[[clang::warn_unused_result]] virtual hal::Error getDisplayVsyncPeriod(
nsecs_t* outVsyncPeriod) const = 0;
[[clang::warn_unused_result]] virtual hal::Error setActiveConfigWithConstraints(
const std::shared_ptr<const HWC2::Display::Config>& config,
const hal::VsyncPeriodChangeConstraints& constraints,
hal::VsyncPeriodChangeTimeline* outTimeline) = 0;
- [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) const = 0;
+ [[clang::warn_unused_result]] virtual hal::Error setAutoLowLatencyMode(bool on) = 0;
[[clang::warn_unused_result]] virtual hal::Error getSupportedContentTypes(
std::vector<hal::ContentType>*) const = 0;
- [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) const = 0;
+ [[clang::warn_unused_result]] virtual hal::Error setContentType(hal::ContentType) = 0;
};
namespace impl {
@@ -294,16 +295,16 @@
hal::Error presentOrValidate(uint32_t* outNumTypes, uint32_t* outNumRequests,
android::sp<android::Fence>* outPresentFence,
uint32_t* state) override;
- hal::Error setDisplayBrightness(float brightness) const override;
+ std::future<hal::Error> setDisplayBrightness(float brightness) override;
hal::Error getDisplayVsyncPeriod(nsecs_t* outVsyncPeriod) const override;
hal::Error setActiveConfigWithConstraints(
const std::shared_ptr<const HWC2::Display::Config>& config,
const hal::VsyncPeriodChangeConstraints& constraints,
hal::VsyncPeriodChangeTimeline* outTimeline) override;
- hal::Error setAutoLowLatencyMode(bool on) const override;
+ hal::Error setAutoLowLatencyMode(bool on) override;
hal::Error getSupportedContentTypes(
std::vector<hal::ContentType>* outSupportedContentTypes) const override;
- hal::Error setContentType(hal::ContentType contentType) const override;
+ hal::Error setContentType(hal::ContentType) override;
// Other Display methods
hal::HWDisplayId getId() const override { return mId; }
bool isConnected() const override { return mIsConnected; }