summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Huihong Luo <huisinro@google.com> 2022-09-26 11:32:52 -0700
committer Huihong Luo <huisinro@google.com> 2022-09-26 20:27:14 +0000
commit41ea7d141e1e5df8cda81903cb7923caaa9471c8 (patch)
tree11ed0069648404a944f00ab89c9c0d04deba1e3c
parent82839ebcfc80ff5938e58bdbf7d863af8af11fd0 (diff)
Remove internal display related methods
Sync with changes made in SurfaceFlinger and SurfaceComposerClient. In the case of multi-display devices, a display id must be specified with "-d" option for screencap, since SurfaceFlinger is not guaranteed to provide the correct default display. Note this change breaks the default behavior of screencap, therefore tools that rely on screencap will have to be modified to select a display to deal with multi-display devices. Bug: 241285477 Test: manual, run screencap command to verify Change-Id: Ibe3679d810602456205e157fe2cb8cc510062215
-rw-r--r--cmds/screencap/screencap.cpp42
1 files changed, 31 insertions, 11 deletions
diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp
index 4ed1c8e20674..44fb6b320102 100644
--- a/cmds/screencap/screencap.cpp
+++ b/cmds/screencap/screencap.cpp
@@ -45,17 +45,23 @@ using namespace android;
#define COLORSPACE_SRGB 1
#define COLORSPACE_DISPLAY_P3 2
-static void usage(const char* pname, DisplayId displayId)
+static void usage(const char* pname, std::optional<PhysicalDisplayId> displayId)
{
+ std::string defaultDisplayStr = "";
+ if (!displayId) {
+ defaultDisplayStr = "";
+ } else {
+ defaultDisplayStr = " (default: " + to_string(*displayId) + ")";
+ }
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 (default: %s)\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",
- pname, to_string(displayId).c_str());
+ pname, defaultDisplayStr.c_str());
}
static int32_t flinger2bitmapFormat(PixelFormat f)
@@ -121,12 +127,12 @@ static status_t notifyMediaScanner(const char* fileName) {
int main(int argc, char** argv)
{
- std::optional<DisplayId> displayId = SurfaceComposerClient::getInternalDisplayId();
- if (!displayId) {
- fprintf(stderr, "Failed to get ID for internal display\n");
+ const std::vector<PhysicalDisplayId> ids = SurfaceComposerClient::getPhysicalDisplayIds();
+ if (ids.empty()) {
+ fprintf(stderr, "Failed to get ID for any displays.\n");
return 1;
}
-
+ std::optional<PhysicalDisplayId> displayId;
const char* pname = argv[0];
bool png = false;
int c;
@@ -136,18 +142,32 @@ int main(int argc, char** argv)
png = true;
break;
case 'd':
- displayId = DisplayId::fromValue(atoll(optarg));
+ displayId = DisplayId::fromValue<PhysicalDisplayId>(atoll(optarg));
if (!displayId) {
- fprintf(stderr, "Invalid display ID\n");
+ fprintf(stderr, "Invalid display ID: %s\n", optarg);
return 1;
}
break;
case '?':
case 'h':
- usage(pname, *displayId);
+ if (ids.size() == 1) {
+ displayId = ids.front();
+ }
+ usage(pname, displayId);
return 1;
}
}
+
+ if (!displayId) { // no diplsay id is specified
+ if (ids.size() == 1) {
+ displayId = ids.front();
+ } else {
+ fprintf(stderr, "Please specify a display ID (-d display-id) for multi-display device.\n");
+ fprintf(stderr, "See \"dumpsys SurfaceFlinger --display-id\" for valid display IDs.\n");
+ return 1;
+ }
+ }
+
argc -= optind;
argv += optind;
@@ -169,7 +189,7 @@ int main(int argc, char** argv)
}
if (fd == -1) {
- usage(pname, *displayId);
+ usage(pname, displayId);
return 1;
}