Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
| 30 | using namespace android; |
| 31 | |
| 32 | std::unordered_map<std::string, std::any> g_functions; |
| 33 | |
| 34 | const std::unordered_map<std::string, std::string> g_function_details = { |
Carlos Martinez Romero | 42dc9e9 | 2023-11-06 13:56:00 -0800 | [diff] [blame^] | 35 | {"debugFlash", "[optional(delay)] Perform a debug flash."}, |
| 36 | {"frameRateIndicator", "[hide | show] displays the framerate in the top left corner."}, |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 37 | {"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 | |
| 42 | static void ShowUsage() { |
Carlos Martinez Romero | 42dc9e9 | 2023-11-06 13:56:00 -0800 | [diff] [blame^] | 43 | std::cout << "usage: sfdo [help, frameRateIndicator show, debugFlash enabled, ...]\n\n"; |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 44 | 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 Romero | 42dc9e9 | 2023-11-06 13:56:00 -0800 | [diff] [blame^] | 53 | int frameRateIndicator(int argc, char** argv) { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 54 | 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 Romero | 42dc9e9 | 2023-11-06 13:56:00 -0800 | [diff] [blame^] | 63 | std::cerr << "Incorrect usage of frameRateIndicator. Missing [hide | show].\n"; |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 64 | return -1; |
| 65 | } |
| 66 | return 0; |
| 67 | } |
| 68 | |
Carlos Martinez Romero | 42dc9e9 | 2023-11-06 13:56:00 -0800 | [diff] [blame^] | 69 | int debugFlash(int argc, char** argv) { |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 70 | 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 | |
| 79 | int scheduleComposite([[maybe_unused]] int argc, [[maybe_unused]] char** argv) { |
| 80 | ComposerServiceAIDL::getComposerService()->scheduleComposite(); |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | int scheduleCommit([[maybe_unused]] int argc, [[maybe_unused]] char** argv) { |
| 85 | ComposerServiceAIDL::getComposerService()->scheduleCommit(); |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | int 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 Romero | 42dc9e9 | 2023-11-06 13:56:00 -0800 | [diff] [blame^] | 93 | g_functions["frameRateIndicator"] = frameRateIndicator; |
| 94 | g_functions["debugFlash"] = debugFlash; |
Carlos Martinez Romero | 5ec086e | 2023-02-14 00:44:36 +0000 | [diff] [blame] | 95 | 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 | } |