SurfaceFlinger: move sync_wait for screen capture to client

Free up time from the SF's main thread by moving the fence waiting
to the client.

Test: Observe systrace of region sample thread
Test: adb shell screencap
Test: Recents takes the screenshot
Test: Rotate device
Test: Volume + power down for screenshot
Bug: 178649983
Change-Id: I0a4991c013375b1f354e0728a06ca30a835b0422
diff --git a/libs/gui/ScreenCaptureResults.cpp b/libs/gui/ScreenCaptureResults.cpp
index 2b29487..f3849bc 100644
--- a/libs/gui/ScreenCaptureResults.cpp
+++ b/libs/gui/ScreenCaptureResults.cpp
@@ -25,6 +25,14 @@
     } else {
         SAFE_PARCEL(parcel->writeBool, false);
     }
+
+    if (fence != Fence::NO_FENCE) {
+        SAFE_PARCEL(parcel->writeBool, true);
+        SAFE_PARCEL(parcel->write, *fence);
+    } else {
+        SAFE_PARCEL(parcel->writeBool, false);
+    }
+
     SAFE_PARCEL(parcel->writeBool, capturedSecureLayers);
     SAFE_PARCEL(parcel->writeUint32, static_cast<uint32_t>(capturedDataspace));
     SAFE_PARCEL(parcel->writeInt32, result);
@@ -39,6 +47,13 @@
         SAFE_PARCEL(parcel->read, *buffer);
     }
 
+    bool hasFence;
+    SAFE_PARCEL(parcel->readBool, &hasFence);
+    if (hasFence) {
+        fence = new Fence();
+        SAFE_PARCEL(parcel->read, *fence);
+    }
+
     SAFE_PARCEL(parcel->readBool, &capturedSecureLayers);
     uint32_t dataspace = 0;
     SAFE_PARCEL(parcel->readUint32, &dataspace);