SF: trace display power state
Bug: 267195714
Test: manual
Change-Id: If518fabf16d91c1a58f7b68a5f4de0629df90fec
diff --git a/services/surfaceflinger/DisplayDevice.cpp b/services/surfaceflinger/DisplayDevice.cpp
index 5f73fbc..a89b23c 100644
--- a/services/surfaceflinger/DisplayDevice.cpp
+++ b/services/surfaceflinger/DisplayDevice.cpp
@@ -181,11 +181,23 @@
getCompositionDisplay()->applyDisplayBrightness(true);
}
- mPowerMode = mode;
+ if (mPowerMode) {
+ *mPowerMode = mode;
+ } else {
+ mPowerMode.emplace("PowerMode -" + to_string(getId()), mode);
+ }
getCompositionDisplay()->setCompositionEnabled(isPoweredOn());
}
+void DisplayDevice::tracePowerMode() {
+ // assign the same value for tracing
+ if (mPowerMode) {
+ const hal::PowerMode powerMode = *mPowerMode;
+ *mPowerMode = powerMode;
+ }
+}
+
void DisplayDevice::enableLayerCaching(bool enable) {
getCompositionDisplay()->setLayerCachingEnabled(enable);
}
diff --git a/services/surfaceflinger/DisplayDevice.h b/services/surfaceflinger/DisplayDevice.h
index b86d9be..710c582 100644
--- a/services/surfaceflinger/DisplayDevice.h
+++ b/services/surfaceflinger/DisplayDevice.h
@@ -175,6 +175,7 @@
std::optional<hardware::graphics::composer::hal::PowerMode> getPowerMode() const;
void setPowerMode(hardware::graphics::composer::hal::PowerMode mode);
bool isPoweredOn() const;
+ void tracePowerMode();
// Enables layer caching on this DisplayDevice
void enableLayerCaching(bool enable);
@@ -275,7 +276,8 @@
static ui::Transform::RotationFlags sPrimaryDisplayRotationFlags;
// Allow nullopt as initial power mode.
- std::optional<hardware::graphics::composer::hal::PowerMode> mPowerMode;
+ using TracedPowerMode = TracedOrdinal<hardware::graphics::composer::hal::PowerMode>;
+ std::optional<TracedPowerMode> mPowerMode;
std::optional<float> mStagedBrightness;
std::optional<float> mBrightness;
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index eecfeb6..5a6221a 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2498,6 +2498,7 @@
if (!dropFrame) {
refreshArgs.outputs.push_back(display->getCompositionDisplay());
}
+ display->tracePowerMode();
displayIds.push_back(display->getId());
}
mPowerAdvisor->setDisplays(displayIds);
diff --git a/services/surfaceflinger/TracedOrdinal.h b/services/surfaceflinger/TracedOrdinal.h
index 558b3be..1adc3a5 100644
--- a/services/surfaceflinger/TracedOrdinal.h
+++ b/services/surfaceflinger/TracedOrdinal.h
@@ -24,16 +24,24 @@
#include <cutils/compiler.h>
#include <utils/Trace.h>
-namespace std {
-template <class Rep, class Period>
-bool signbit(std::chrono::duration<Rep, Period> v) {
- return signbit(std::chrono::duration_cast<std::chrono::nanoseconds>(v).count());
-}
-} // namespace std
-
namespace android {
namespace {
+template <class Rep, class Period>
+bool signbit(std::chrono::duration<Rep, Period> v) {
+ return std::signbit(std::chrono::duration_cast<std::chrono::nanoseconds>(v).count());
+}
+
+template <typename Enum, typename std::enable_if<std::is_enum<Enum>::value>::type* = nullptr>
+bool signbit(Enum e) {
+ return std::signbit(static_cast<typename std::underlying_type<Enum>::type>(e));
+}
+
+template <typename T, typename std::enable_if<!std::is_enum<T>::value>::type* = nullptr>
+bool signbit(T t) {
+ return std::signbit(t);
+}
+
template <typename T>
int64_t to_int64(T v) {
return int64_t(v);
@@ -49,14 +57,12 @@
class TracedOrdinal {
public:
static_assert(std::is_same<bool, T>() || (std::is_signed<T>() && std::is_integral<T>()) ||
- std::is_same<std::chrono::nanoseconds, T>(),
+ std::is_same<std::chrono::nanoseconds, T>() || std::is_enum<T>(),
"Type is not supported. Please test it with systrace before adding "
"it to the list.");
TracedOrdinal(std::string name, T initialValue)
- : mName(std::move(name)),
- mHasGoneNegative(std::signbit(initialValue)),
- mData(initialValue) {
+ : mName(std::move(name)), mHasGoneNegative(signbit(initialValue)), mData(initialValue) {
trace();
}
@@ -66,7 +72,7 @@
TracedOrdinal& operator=(T other) {
mData = other;
- mHasGoneNegative = mHasGoneNegative || std::signbit(mData);
+ mHasGoneNegative = mHasGoneNegative || signbit(mData);
trace();
return *this;
}
@@ -81,7 +87,7 @@
mNameNegative = mName + "Negative";
}
- if (!std::signbit(mData)) {
+ if (!signbit(mData)) {
ATRACE_INT64(mName.c_str(), to_int64(mData));
if (mHasGoneNegative) {
ATRACE_INT64(mNameNegative.c_str(), 0);