Send ScreenCaptureListener to native screen capture requests.

Allow for asynchronous screenshot by sending a ScreenCaptureListener to
handle screenshot callbacks. All existing calls are still synchronous
since the SurfaceControl method will block the caller until the results
from SurfaceFlinger are ready.

Test: power + volume down
Test: adb shell screencap
Bug: 162367424
Change-Id: I54c34003c0786b585dd20530a06dbd4b266e178c
This commit is contained in:
chaviw
2020-08-18 16:06:40 -07:00
parent 25953d498f
commit 3510924a6d
3 changed files with 172 additions and 46 deletions

View File

@@ -30,8 +30,9 @@
#include <binder/ProcessState.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/ISurfaceComposer.h>
#include <gui/SurfaceComposerClient.h>
#include <gui/SyncScreenCaptureListener.h>
#include <ui/DisplayInfo.h>
#include <ui/GraphicTypes.h>
@@ -181,13 +182,18 @@ int main(int argc, char** argv)
ProcessState::self()->setThreadPoolMaxThreadCount(0);
ProcessState::self()->startThreadPool();
ScreenCaptureResults captureResults;
status_t result = ScreenshotClient::captureDisplay(displayId->value, captureResults);
sp<SyncScreenCaptureListener> captureListener = new SyncScreenCaptureListener();
status_t result = ScreenshotClient::captureDisplay(displayId->value, captureListener);
if (result != NO_ERROR) {
close(fd);
return 1;
}
ScreenCaptureResults captureResults = captureListener->waitForResults();
if (captureResults.result != NO_ERROR) {
close(fd);
return 1;
}
ui::Dataspace dataspace = captureResults.capturedDataspace;
sp<GraphicBuffer> buffer = captureResults.buffer;