SF: Remove manual enum stringification
Upgrade to scoped enums where applicable. Pull GameMode from TimeStats
into libgui to plumb it as an enum rather than int32_t.
Bug: 185536303
Test: libsurfaceflinger_unittest
Change-Id: I81fdd24805757ef953484055ee867684eb94fecf
diff --git a/services/surfaceflinger/TimeStats/timestatsproto/TimeStatsHelper.cpp b/services/surfaceflinger/TimeStats/timestatsproto/TimeStatsHelper.cpp
index ffb2f09..69afa2a 100644
--- a/services/surfaceflinger/TimeStats/timestatsproto/TimeStatsHelper.cpp
+++ b/services/surfaceflinger/TimeStats/timestatsproto/TimeStatsHelper.cpp
@@ -16,9 +16,10 @@
#include "timestatsproto/TimeStatsHelper.h"
#include <android-base/stringprintf.h>
-#include <inttypes.h>
+#include <ftl/enum.h>
#include <array>
+#include <cinttypes>
#define HISTOGRAM_SIZE 85
@@ -91,51 +92,15 @@
return result;
}
-std::string TimeStatsHelper::SetFrameRateVote::toString(FrameRateCompatibility compatibility) {
- switch (compatibility) {
- case FrameRateCompatibility::Undefined:
- return "Undefined";
- case FrameRateCompatibility::Default:
- return "Default";
- case FrameRateCompatibility::ExactOrMultiple:
- return "ExactOrMultiple";
- }
-}
-
-std::string TimeStatsHelper::SetFrameRateVote::toString(Seamlessness seamlessness) {
- switch (seamlessness) {
- case Seamlessness::Undefined:
- return "Undefined";
- case Seamlessness::ShouldBeSeamless:
- return "ShouldBeSeamless";
- case Seamlessness::NotRequired:
- return "NotRequired";
- }
-}
-
std::string TimeStatsHelper::SetFrameRateVote::toString() const {
std::string result;
StringAppendF(&result, "frameRate = %.2f\n", frameRate);
StringAppendF(&result, "frameRateCompatibility = %s\n",
- toString(frameRateCompatibility).c_str());
- StringAppendF(&result, "seamlessness = %s\n", toString(seamlessness).c_str());
+ ftl::enum_string(frameRateCompatibility).c_str());
+ StringAppendF(&result, "seamlessness = %s\n", ftl::enum_string(seamlessness).c_str());
return result;
}
-std::string TimeStatsHelper::TimeStatsLayer::toString(int32_t gameMode) const {
- switch (gameMode) {
- case TimeStatsHelper::GameModeUnsupported:
- return "GameModeUnsupported";
- case TimeStatsHelper::GameModeStandard:
- return "GameModeStandard";
- case TimeStatsHelper::GameModePerformance:
- return "GameModePerformance";
- case TimeStatsHelper::GameModeBattery:
- return "GameModeBattery";
- default:
- return "GameModeUnspecified";
- }
-}
std::string TimeStatsHelper::TimeStatsLayer::toString() const {
std::string result = "\n";
StringAppendF(&result, "displayRefreshRate = %d fps\n", displayRefreshRateBucket);
@@ -143,7 +108,7 @@
StringAppendF(&result, "uid = %d\n", uid);
StringAppendF(&result, "layerName = %s\n", layerName.c_str());
StringAppendF(&result, "packageName = %s\n", packageName.c_str());
- StringAppendF(&result, "gameMode = %s\n", toString(gameMode).c_str());
+ StringAppendF(&result, "gameMode = %s\n", ftl::enum_string(gameMode).c_str());
StringAppendF(&result, "totalFrames = %d\n", totalFrames);
StringAppendF(&result, "droppedFrames = %d\n", droppedFrames);
StringAppendF(&result, "lateAcquireFrames = %d\n", lateAcquireFrames);
diff --git a/services/surfaceflinger/TimeStats/timestatsproto/include/timestatsproto/TimeStatsHelper.h b/services/surfaceflinger/TimeStats/timestatsproto/include/timestatsproto/TimeStatsHelper.h
index 2afff8d..438561c 100644
--- a/services/surfaceflinger/TimeStats/timestatsproto/include/timestatsproto/TimeStatsHelper.h
+++ b/services/surfaceflinger/TimeStats/timestatsproto/include/timestatsproto/TimeStatsHelper.h
@@ -15,6 +15,7 @@
*/
#pragma once
+#include <gui/LayerMetadata.h>
#include <timestatsproto/TimeStatsProtoHeader.h>
#include <utils/Timers.h>
@@ -63,6 +64,8 @@
Undefined = 0,
Default = 1,
ExactOrMultiple = 2,
+
+ ftl_last = ExactOrMultiple
} frameRateCompatibility = FrameRateCompatibility::Undefined;
// Needs to be in sync with atoms.proto
@@ -70,25 +73,13 @@
Undefined = 0,
ShouldBeSeamless = 1,
NotRequired = 2,
+
+ ftl_last = NotRequired
} seamlessness = Seamlessness::Undefined;
- static std::string toString(FrameRateCompatibility);
- static std::string toString(Seamlessness);
std::string toString() const;
};
- /**
- * GameMode of the layer. GameModes are set by SysUI through WMShell.
- * Actual game mode definitions are managed by GameManager.java
- * The values defined here should always be in sync with the ones in GameManager.
- */
- enum GameMode {
- GameModeUnsupported = 0,
- GameModeStandard = 1,
- GameModePerformance = 2,
- GameModeBattery = 3,
- };
-
class TimeStatsLayer {
public:
uid_t uid;
@@ -96,7 +87,7 @@
std::string packageName;
int32_t displayRefreshRateBucket = 0;
int32_t renderRateBucket = 0;
- int32_t gameMode = 0;
+ GameMode gameMode = GameMode::Unsupported;
int32_t totalFrames = 0;
int32_t droppedFrames = 0;
int32_t lateAcquireFrames = 0;
@@ -106,7 +97,6 @@
std::unordered_map<std::string, Histogram> deltas;
std::string toString() const;
- std::string toString(int32_t gameMode) const;
SFTimeStatsLayerProto toProto() const;
};
@@ -137,13 +127,14 @@
struct LayerStatsKey {
uid_t uid = 0;
std::string layerName;
- int32_t gameMode = 0;
+ GameMode gameMode = GameMode::Unsupported;
struct Hasher {
size_t operator()(const LayerStatsKey& key) const {
size_t uidHash = std::hash<uid_t>{}(key.uid);
size_t layerNameHash = std::hash<std::string>{}(key.layerName);
- size_t gameModeHash = std::hash<int32_t>{}(key.gameMode);
+ using T = std::underlying_type_t<GameMode>;
+ size_t gameModeHash = std::hash<T>{}(static_cast<T>(key.gameMode));
return HashCombine(uidHash, HashCombine(layerNameHash, gameModeHash));
}
};