blob: f00f7b55130d3b52e6310a25196c217bd992711e [file] [log] [blame]
Carlos Martinez Romero5ec086e2023-02-14 00:44:36 +00001/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#include <inttypes.h>
17#include <stdint.h>
18#include <any>
19#include <unordered_map>
20
21#include <cutils/properties.h>
22#include <sys/resource.h>
23#include <utils/Log.h>
24
25#include <gui/ISurfaceComposer.h>
26#include <gui/SurfaceComposerClient.h>
27#include <gui/SurfaceControl.h>
28#include <private/gui/ComposerServiceAIDL.h>
29
30using namespace android;
31
32std::unordered_map<std::string, std::any> g_functions;
33
34const std::unordered_map<std::string, std::string> g_function_details = {
Carlos Martinez Romero42dc9e92023-11-06 13:56:00 -080035 {"debugFlash", "[optional(delay)] Perform a debug flash."},
36 {"frameRateIndicator", "[hide | show] displays the framerate in the top left corner."},
Carlos Martinez Romero5ec086e2023-02-14 00:44:36 +000037 {"scheduleComposite", "Force composite ahead of next VSYNC."},
38 {"scheduleCommit", "Force commit ahead of next VSYNC."},
39 {"scheduleComposite", "PENDING - if you have a good understanding let me know!"},
40};
41
42static void ShowUsage() {
Carlos Martinez Romero42dc9e92023-11-06 13:56:00 -080043 std::cout << "usage: sfdo [help, frameRateIndicator show, debugFlash enabled, ...]\n\n";
Carlos Martinez Romero5ec086e2023-02-14 00:44:36 +000044 for (const auto& sf : g_functions) {
45 const std::string fn = sf.first;
46 std::string fdetails = "TODO";
47 if (g_function_details.find(fn) != g_function_details.end())
48 fdetails = g_function_details.find(fn)->second;
49 std::cout << " " << fn << ": " << fdetails << "\n";
50 }
51}
52
Carlos Martinez Romero42dc9e92023-11-06 13:56:00 -080053int frameRateIndicator(int argc, char** argv) {
Carlos Martinez Romero5ec086e2023-02-14 00:44:36 +000054 bool hide = false, show = false;
55 if (argc == 3) {
56 show = strcmp(argv[2], "show") == 0;
57 hide = strcmp(argv[2], "hide") == 0;
58 }
59
60 if (show || hide) {
61 ComposerServiceAIDL::getComposerService()->enableRefreshRateOverlay(show);
62 } else {
Carlos Martinez Romero42dc9e92023-11-06 13:56:00 -080063 std::cerr << "Incorrect usage of frameRateIndicator. Missing [hide | show].\n";
Carlos Martinez Romero5ec086e2023-02-14 00:44:36 +000064 return -1;
65 }
66 return 0;
67}
68
Carlos Martinez Romero42dc9e92023-11-06 13:56:00 -080069int debugFlash(int argc, char** argv) {
Carlos Martinez Romero5ec086e2023-02-14 00:44:36 +000070 int delay = 0;
71 if (argc == 3) {
72 delay = atoi(argv[2]) == 0;
73 }
74
75 ComposerServiceAIDL::getComposerService()->setDebugFlash(delay);
76 return 0;
77}
78
79int scheduleComposite([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
80 ComposerServiceAIDL::getComposerService()->scheduleComposite();
81 return 0;
82}
83
84int scheduleCommit([[maybe_unused]] int argc, [[maybe_unused]] char** argv) {
85 ComposerServiceAIDL::getComposerService()->scheduleCommit();
86 return 0;
87}
88
89int main(int argc, char** argv) {
90 std::cout << "Execute SurfaceFlinger internal commands.\n";
91 std::cout << "sfdo requires to be run with root permissions..\n";
92
Carlos Martinez Romero42dc9e92023-11-06 13:56:00 -080093 g_functions["frameRateIndicator"] = frameRateIndicator;
94 g_functions["debugFlash"] = debugFlash;
Carlos Martinez Romero5ec086e2023-02-14 00:44:36 +000095 g_functions["scheduleComposite"] = scheduleComposite;
96 g_functions["scheduleCommit"] = scheduleCommit;
97
98 if (argc > 1 && g_functions.find(argv[1]) != g_functions.end()) {
99 std::cout << "Running: " << argv[1] << "\n";
100 const std::string key(argv[1]);
101 const auto fn = g_functions[key];
102 int result = std::any_cast<int (*)(int, char**)>(fn)(argc, argv);
103 if (result == 0) {
104 std::cout << "Success.\n";
105 }
106 return result;
107 } else {
108 ShowUsage();
109 }
110 return 0;
111}