From 3316a0a08e79739b0508087232efcb3f2803dafe Mon Sep 17 00:00:00 2001 From: Dominik Laskowski Date: Fri, 25 Jan 2019 02:56:41 -0800 Subject: Generalize physical display management This CL enables the framework to manage an arbitrary number of physical displays. It also surfaces physical display IDs, which are stable across reboots and encode (model, port) information that will be propagated further up in a follow-up CL. Bug: 116025192 Test: Boot with more than two displays Test: Hotplug works with any number of displays Test: Verify stable display IDs with "dumpsys display" Change-Id: Idb2eaff66b2e0873be6ad27d337ff18b730d1331 --- cmds/screencap/screencap.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'cmds/screencap/screencap.cpp') diff --git a/cmds/screencap/screencap.cpp b/cmds/screencap/screencap.cpp index 3d74f8b207af..c4976675dc04 100644 --- a/cmds/screencap/screencap.cpp +++ b/cmds/screencap/screencap.cpp @@ -46,23 +46,22 @@ using namespace android; -static uint32_t DEFAULT_DISPLAY_ID = ISurfaceComposer::eDisplayIdMain; - #define COLORSPACE_UNKNOWN 0 #define COLORSPACE_SRGB 1 #define COLORSPACE_DISPLAY_P3 2 -static void usage(const char* pname) +static void usage(const char* pname, PhysicalDisplayId 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 %d.\n" + " -d: specify the physical display ID to capture (default: %" + ANDROID_PHYSICAL_DISPLAY_ID_FORMAT ")\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, DEFAULT_DISPLAY_ID - ); + pname, displayId); } static SkColorType flinger2skia(PixelFormat f) @@ -127,9 +126,14 @@ static status_t notifyMediaScanner(const char* fileName) { int main(int argc, char** argv) { + std::optional displayId = SurfaceComposerClient::getInternalDisplayId(); + if (!displayId) { + fprintf(stderr, "Failed to get token for internal display\n"); + return 1; + } + const char* pname = argv[0]; bool png = false; - int32_t displayId = DEFAULT_DISPLAY_ID; int c; while ((c = getopt(argc, argv, "phd:")) != -1) { switch (c) { @@ -137,11 +141,11 @@ int main(int argc, char** argv) png = true; break; case 'd': - displayId = atoi(optarg); + displayId = atoll(optarg); break; case '?': case 'h': - usage(pname); + usage(pname, *displayId); return 1; } } @@ -166,7 +170,7 @@ int main(int argc, char** argv) } if (fd == -1) { - usage(pname); + usage(pname, *displayId); return 1; } @@ -192,9 +196,10 @@ int main(int argc, char** argv) ProcessState::self()->setThreadPoolMaxThreadCount(0); ProcessState::self()->startThreadPool(); - sp display = SurfaceComposerClient::getBuiltInDisplay(displayId); - if (display == NULL) { - fprintf(stderr, "Unable to get handle for display %d\n", displayId); + const sp display = SurfaceComposerClient::getPhysicalDisplayToken(*displayId); + if (display == nullptr) { + fprintf(stderr, "Failed to get token for invalid display %" + ANDROID_PHYSICAL_DISPLAY_ID_FORMAT "\n", *displayId); return 1; } -- cgit v1.2.3-59-g8ed1b