Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 67ae943b authored by Priyanka's avatar Priyanka
Browse files

Support screen recording of multiple displays simultaneously.

Ensure layer stack assigned to each new virtual display is actually random (and different) by initializing via srand.
Assign unique display name to each new virtual display to better differentiate them.
Add --version flag to more easily parse version information than from --help.

Bug: 264688932
Flag: EXEMPT bug fix
Test: adb shell screenrecord --display-id VALID_DISPLAY_ID run twice in different terminals for different display ids
Change-Id: I7a3be9086cf91f98fbb88ad559e6a14e1513f250
parent 84677267
Loading
Loading
Loading
Loading
+20 −1
Original line number Diff line number Diff line
@@ -362,13 +362,26 @@ static status_t prepareVirtualDisplay(
        const ui::DisplayState& displayState,
        const sp<IGraphicBufferProducer>& bufferProducer,
        sp<IBinder>* pDisplayHandle, sp<SurfaceControl>* mirrorRoot) {
    static const std::string kDisplayName("ScreenRecorder");
    std::string displayName = gPhysicalDisplayId
      ? "ScreenRecorder " + to_string(*gPhysicalDisplayId)
      : "ScreenRecorder";
    static const std::string kDisplayName(displayName);

    sp<IBinder> dpy = SurfaceComposerClient::createVirtualDisplay(kDisplayName, gSecureDisplay);
    SurfaceComposerClient::Transaction t;
    t.setDisplaySurface(dpy, bufferProducer);
    setDisplayProjection(t, dpy, displayState);

    // ensures that random layer stack assigned to virtual display changes
    // between calls - if a list of displays with their layer stacks becomes
    // available, we should use it to ensure a new layer stack is used here
    std::srand(
      std::chrono::duration_cast<std::chrono::milliseconds>(
        std::chrono::system_clock::now().time_since_epoch()
       ).count());
    ui::LayerStack layerStack = ui::LayerStack::fromValue(std::rand());
    t.setDisplayLayerStack(dpy, layerStack);

    PhysicalDisplayId displayId;
    status_t err = getPhysicalDisplayId(displayId);
    if (err != NO_ERROR) {
@@ -1224,6 +1237,8 @@ static void usage() {
        "    see \"dumpsys SurfaceFlinger --display-id\" for valid display IDs.\n"
        "--verbose\n"
        "    Display interesting information on stdout.\n"
        "--version\n"
        "    Show Android screenrecord version.\n"
        "--help\n"
        "    Show this message.\n"
        "\n"
@@ -1255,6 +1270,7 @@ int main(int argc, char* const argv[]) {
        { "bframes",            required_argument,  NULL, 'B' },
        { "display-id",         required_argument,  NULL, 'd' },
        { "capture-secure",     no_argument,        NULL, 'S' },
        { "version",            no_argument,        NULL, 'x' },
        { NULL,                 0,                  NULL, 0 }
    };

@@ -1377,6 +1393,9 @@ int main(int argc, char* const argv[]) {
        case 'S':
            gSecureDisplay = true;
            break;
        case 'x':
            fprintf(stderr, "%d.%d\n", kVersionMajor, kVersionMinor);
            return 0;
        default:
            if (ic != '?') {
                fprintf(stderr, "getopt_long returned unexpected value 0x%x\n", ic);
+1 −1
Original line number Diff line number Diff line
@@ -18,6 +18,6 @@
#define SCREENRECORD_SCREENRECORD_H

#define kVersionMajor 1
#define kVersionMinor 3
#define kVersionMinor 4

#endif /*SCREENRECORD_SCREENRECORD_H*/