summaryrefslogtreecommitdiff
path: root/cmds/sfdo/sfdo.cpp
diff options
context:
space:
mode:
author Carlos Martinez Romero <carlosmr@google.com> 2023-11-15 21:20:47 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2023-11-15 21:20:47 +0000
commit15e788a9ab2e0990b554b6b06535c90942b40fc1 (patch)
tree33737c7d425ea24c0dacf029a6767b3919c5212c /cmds/sfdo/sfdo.cpp
parent580124a86a3257226b4f986917864a62fd98feeb (diff)
parentb4ea9e6741adafda4f4cfbb48011ab4d1628d5d2 (diff)
Merge changes from topic "sfdo" into main
* changes: [sfdo] Add the forceClientComposition command to sfdo. [sfdo] Fix minor formatting issues.
Diffstat (limited to 'cmds/sfdo/sfdo.cpp')
-rw-r--r--cmds/sfdo/sfdo.cpp83
1 files changed, 69 insertions, 14 deletions
diff --git a/cmds/sfdo/sfdo.cpp b/cmds/sfdo/sfdo.cpp
index 55326ea737..de0e1718ab 100644
--- a/cmds/sfdo/sfdo.cpp
+++ b/cmds/sfdo/sfdo.cpp
@@ -16,7 +16,7 @@
#include <inttypes.h>
#include <stdint.h>
#include <any>
-#include <unordered_map>
+#include <map>
#include <cutils/properties.h>
#include <sys/resource.h>
@@ -29,18 +29,28 @@
using namespace android;
-std::unordered_map<std::string, std::any> g_functions;
+std::map<std::string, std::any> g_functions;
-const std::unordered_map<std::string, std::string> g_function_details = {
- {"DebugFlash", "[optional(delay)] Perform a debug flash."},
- {"FrameRateIndicator", "[hide | show] displays the framerate in the top left corner."},
- {"scheduleComposite", "Force composite ahead of next VSYNC."},
- {"scheduleCommit", "Force commit ahead of next VSYNC."},
- {"scheduleComposite", "PENDING - if you have a good understanding let me know!"},
+enum class ParseToggleResult {
+ kError,
+ kFalse,
+ kTrue,
+};
+
+const std::map<std::string, std::string> g_function_details = {
+ {"debugFlash", "[optional(delay)] Perform a debug flash."},
+ {"frameRateIndicator", "[hide | show] displays the framerate in the top left corner."},
+ {"scheduleComposite", "Force composite ahead of next VSYNC."},
+ {"scheduleCommit", "Force commit ahead of next VSYNC."},
+ {"scheduleComposite", "PENDING - if you have a good understanding let me know!"},
+ {"forceClientComposition",
+ "[enabled | disabled] When enabled, it disables "
+ "Hardware Overlays, and routes all window composition to the GPU. This can "
+ "help check if there is a bug in HW Composer."},
};
static void ShowUsage() {
- std::cout << "usage: sfdo [help, FrameRateIndicator show, DebugFlash enabled, ...]\n\n";
+ std::cout << "usage: sfdo [help, frameRateIndicator show, debugFlash enabled, ...]\n\n";
for (const auto& sf : g_functions) {
const std::string fn = sf.first;
std::string fdetails = "TODO";
@@ -50,7 +60,26 @@ static void ShowUsage() {
}
}
-int FrameRateIndicator([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
+// Returns 1 for positive keywords and 0 for negative keywords.
+// If the string does not match any it will return -1.
+ParseToggleResult parseToggle(const char* str) {
+ const std::unordered_set<std::string> positive{"1", "true", "y", "yes",
+ "on", "enabled", "show"};
+ const std::unordered_set<std::string> negative{"0", "false", "n", "no",
+ "off", "disabled", "hide"};
+
+ const std::string word(str);
+ if (positive.count(word)) {
+ return ParseToggleResult::kTrue;
+ }
+ if (negative.count(word)) {
+ return ParseToggleResult::kFalse;
+ }
+
+ return ParseToggleResult::kError;
+}
+
+int frameRateIndicator(int argc, char** argv) {
bool hide = false, show = false;
if (argc == 3) {
show = strcmp(argv[2], "show") == 0;
@@ -60,13 +89,13 @@ int FrameRateIndicator([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
if (show || hide) {
ComposerServiceAIDL::getComposerService()->enableRefreshRateOverlay(show);
} else {
- std::cerr << "Incorrect usage of FrameRateIndicator. Missing [hide | show].\n";
+ std::cerr << "Incorrect usage of frameRateIndicator. Missing [hide | show].\n";
return -1;
}
return 0;
}
-int DebugFlash([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
+int debugFlash(int argc, char** argv) {
int delay = 0;
if (argc == 3) {
delay = atoi(argv[2]) == 0;
@@ -86,14 +115,40 @@ int scheduleCommit([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
return 0;
}
+int forceClientComposition(int argc, char** argv) {
+ bool enabled = true;
+ // A valid command looks like this:
+ // adb shell sfdo forceClientComposition enabled
+ if (argc >= 3) {
+ const ParseToggleResult toggle = parseToggle(argv[2]);
+ if (toggle == ParseToggleResult::kError) {
+ std::cerr << "Incorrect usage of forceClientComposition. "
+ "Missing [enabled | disabled].\n";
+ return -1;
+ }
+ if (argc > 3) {
+ std::cerr << "Too many arguments after [enabled | disabled]. "
+ "Ignoring extra arguments.\n";
+ }
+ enabled = (toggle == ParseToggleResult::kTrue);
+ } else {
+ std::cerr << "Incorrect usage of forceClientComposition. Missing [enabled | disabled].\n";
+ return -1;
+ }
+
+ ComposerServiceAIDL::getComposerService()->forceClientComposition(enabled);
+ return 0;
+}
+
int main(int argc, char** argv) {
std::cout << "Execute SurfaceFlinger internal commands.\n";
std::cout << "sfdo requires to be run with root permissions..\n";
- g_functions["FrameRateIndicator"] = FrameRateIndicator;
- g_functions["DebugFlash"] = DebugFlash;
+ g_functions["frameRateIndicator"] = frameRateIndicator;
+ g_functions["debugFlash"] = debugFlash;
g_functions["scheduleComposite"] = scheduleComposite;
g_functions["scheduleCommit"] = scheduleCommit;
+ g_functions["forceClientComposition"] = forceClientComposition;
if (argc > 1 && g_functions.find(argv[1]) != g_functions.end()) {
std::cout << "Running: " << argv[1] << "\n";