From 4de6e7437fe03709e900ab7dba38f761489ccce6 Mon Sep 17 00:00:00 2001 From: John Reck Date: Tue, 14 Nov 2023 18:32:32 -0500 Subject: Add CaptureArgs & long options to screencap Test: make && adb shell screencap Change-Id: I0141a9ea9b51a06bafdeac6c7848986906b8eacc --- cmds/screencap/screencap.cpp | 44 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) (limited to 'cmds/screencap/screencap.cpp') diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp index 2d235331a672..917529ec1dcf 100644 --- a/cmds/screencap/screencap.cpp +++ b/cmds/screencap/screencap.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -32,6 +33,7 @@ #include #include +#include #include #include #include @@ -48,14 +50,17 @@ using namespace android; #define COLORSPACE_DISPLAY_P3 2 void usage(const char* pname, ftl::Optional displayIdOpt) { - fprintf(stderr, - "usage: %s [-hp] [-d display-id] [FILENAME]\n" - " -h: this message\n" - " -p: save the file as a png.\n" - " -d: specify the display ID to capture%s\n" - " see \"dumpsys SurfaceFlinger --display-id\" for valid display IDs.\n" - "If FILENAME ends with .png it will be saved as a png.\n" - "If FILENAME is not given, the results will be printed to stdout.\n", + fprintf(stderr, R"( +usage: %s [-hp] [-d display-id] [FILENAME] + -h: this message + -p: save the file as a png. + -d: specify the display ID to capture%s + see "dumpsys SurfaceFlinger --display-id" for valid display IDs. + --hint-for-seamless If set will use the hintForSeamless path in SF + +If FILENAME ends with .png it will be saved as a png. +If FILENAME is not given, the results will be printed to stdout. +)", pname, displayIdOpt .transform([](DisplayId id) { @@ -65,6 +70,21 @@ void usage(const char* pname, ftl::Optional displayIdOpt) { .c_str()); } +// For options that only exist in long-form. Anything in the +// 0-255 range is reserved for short options (which just use their ASCII value) +namespace LongOpts { +enum { + Reserved = 255, + HintForSeamless, +}; +} + +static const struct option LONG_OPTIONS[] = { + {"png", no_argument, nullptr, 'p'}, + {"help", no_argument, nullptr, 'h'}, + {"hint-for-seamless", no_argument, nullptr, LongOpts::HintForSeamless}, + {0, 0, 0, 0}}; + static int32_t flinger2bitmapFormat(PixelFormat f) { switch (f) { @@ -134,10 +154,11 @@ int main(int argc, char** argv) return 1; } std::optional displayIdOpt; + gui::CaptureArgs captureArgs; const char* pname = argv[0]; bool png = false; int c; - while ((c = getopt(argc, argv, "phd:")) != -1) { + while ((c = getopt_long(argc, argv, "phd:", LONG_OPTIONS, nullptr)) != -1) { switch (c) { case 'p': png = true; @@ -165,6 +186,9 @@ int main(int argc, char** argv) } usage(pname, displayIdOpt); return 1; + case LongOpts::HintForSeamless: + captureArgs.hintForSeamlessTransition = true; + break; } } @@ -215,7 +239,7 @@ int main(int argc, char** argv) ProcessState::self()->startThreadPool(); sp captureListener = new SyncScreenCaptureListener(); - ScreenshotClient::captureDisplay(*displayIdOpt, captureListener); + ScreenshotClient::captureDisplay(*displayIdOpt, captureArgs, captureListener); ScreenCaptureResults captureResults = captureListener->waitForResults(); if (!captureResults.fenceResult.ok()) { -- cgit v1.2.3-59-g8ed1b