Use DisplayCaptureArgs for displayCapture functions.
Updated displayCapture functions to use the DisplayCaptureArgs and
ScreenCaptureResults instead of the list of arguments and out arguments.
This only updated the native code, not JNI or Java
Test: display screenshot + secure works
Test: adb shell screencap
Test: SurfaceFlinger_test
Bug: 162367424
Change-Id: I5210a0881c96436c128c3ffb328a5a6ee01beca7
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index aba5861..334812e 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -4969,7 +4969,7 @@
return OK;
}
case CAPTURE_LAYERS:
- case CAPTURE_SCREEN:
+ case CAPTURE_DISPLAY:
case ADD_REGION_SAMPLING_LISTENER:
case REMOVE_REGION_SAMPLING_LISTENER: {
// codes that require permission check
@@ -4983,7 +4983,7 @@
}
return OK;
}
- case CAPTURE_SCREEN_BY_ID: {
+ case CAPTURE_DISPLAY_BY_ID: {
IPCThreadState* ipc = IPCThreadState::self();
const int uid = ipc->getCallingUid();
if (uid == AID_ROOT || uid == AID_GRAPHICS || uid == AID_SYSTEM || uid == AID_SHELL) {
@@ -5429,51 +5429,6 @@
const int mApi;
};
-status_t SurfaceFlinger::captureScreen(const sp<IBinder>& displayToken,
- sp<GraphicBuffer>* outBuffer, bool& outCapturedSecureLayers,
- Dataspace reqDataspace, ui::PixelFormat reqPixelFormat,
- const Rect& sourceCrop, uint32_t reqWidth,
- uint32_t reqHeight, bool useIdentityTransform,
- ui::Rotation rotation, bool captureSecureLayers) {
- ATRACE_CALL();
-
- if (!displayToken) return BAD_VALUE;
-
- auto renderAreaRotation = ui::Transform::toRotationFlags(rotation);
- if (renderAreaRotation == ui::Transform::ROT_INVALID) {
- ALOGE("%s: Invalid rotation: %s", __FUNCTION__, toCString(rotation));
- renderAreaRotation = ui::Transform::ROT_0;
- }
-
- wp<DisplayDevice> displayWeak;
- ui::LayerStack layerStack;
- ui::Size reqSize(reqWidth, reqHeight);
- {
- Mutex::Autolock lock(mStateLock);
- sp<DisplayDevice> display = getDisplayDeviceLocked(displayToken);
- if (!display) return NAME_NOT_FOUND;
- displayWeak = display;
- layerStack = display->getLayerStack();
-
- // set the requested width/height to the logical display viewport size
- // by default
- if (reqWidth == 0 || reqHeight == 0) {
- reqSize = display->getViewport().getSize();
- }
- }
-
- RenderAreaFuture renderAreaFuture = promise::defer([=] {
- return DisplayRenderArea::create(displayWeak, sourceCrop, reqSize, reqDataspace,
- renderAreaRotation, captureSecureLayers);
- });
-
- auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) {
- traverseLayersInLayerStack(layerStack, visitor);
- };
- return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, reqSize, outBuffer,
- reqPixelFormat, useIdentityTransform, outCapturedSecureLayers);
-}
-
static Dataspace pickDataspaceFromColorMode(const ColorMode colorMode) {
switch (colorMode) {
case ColorMode::DISPLAY_P3:
@@ -5486,6 +5441,54 @@
}
}
+status_t SurfaceFlinger::captureDisplay(const DisplayCaptureArgs& args,
+ ScreenCaptureResults& captureResults) {
+ ATRACE_CALL();
+
+ if (!args.displayToken) return BAD_VALUE;
+
+ auto renderAreaRotation = ui::Transform::toRotationFlags(args.rotation);
+ if (renderAreaRotation == ui::Transform::ROT_INVALID) {
+ ALOGE("%s: Invalid rotation: %s", __FUNCTION__, toCString(args.rotation));
+ renderAreaRotation = ui::Transform::ROT_0;
+ }
+
+ wp<DisplayDevice> displayWeak;
+ ui::LayerStack layerStack;
+ ui::Size reqSize(args.width, args.height);
+ ui::Dataspace dataspace;
+ {
+ Mutex::Autolock lock(mStateLock);
+ sp<DisplayDevice> display = getDisplayDeviceLocked(args.displayToken);
+ if (!display) return NAME_NOT_FOUND;
+ displayWeak = display;
+ layerStack = display->getLayerStack();
+
+ // set the requested width/height to the logical display viewport size
+ // by default
+ if (args.width == 0 || args.height == 0) {
+ reqSize = display->getViewport().getSize();
+ }
+
+ const ui::ColorMode colorMode = display->getCompositionDisplay()->getState().colorMode;
+ dataspace = pickDataspaceFromColorMode(colorMode);
+ }
+
+ RenderAreaFuture renderAreaFuture = promise::defer([=] {
+ return DisplayRenderArea::create(displayWeak, args.sourceCrop, reqSize, dataspace,
+ renderAreaRotation, args.captureSecureLayers);
+ });
+
+ auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) {
+ traverseLayersInLayerStack(layerStack, visitor);
+ };
+
+ captureResults.capturedDataspace = dataspace;
+ return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, reqSize,
+ &captureResults.buffer, args.pixelFormat, args.useIdentityTransform,
+ captureResults.capturedSecureLayers);
+}
+
status_t SurfaceFlinger::setSchedFifo(bool enabled) {
static constexpr int kFifoPriority = 2;
static constexpr int kOtherPriority = 0;
@@ -5525,8 +5528,8 @@
return nullptr;
}
-status_t SurfaceFlinger::captureScreen(uint64_t displayOrLayerStack, Dataspace* outDataspace,
- sp<GraphicBuffer>* outBuffer) {
+status_t SurfaceFlinger::captureDisplay(uint64_t displayOrLayerStack,
+ ScreenCaptureResults& captureResults) {
ui::LayerStack layerStack;
wp<DisplayDevice> displayWeak;
ui::Size size;
@@ -5562,24 +5565,24 @@
default:
break;
}
- *outDataspace =
+ captureResults.capturedDataspace =
pickDataspaceFromColorMode(display->getCompositionDisplay()->getState().colorMode);
}
RenderAreaFuture renderAreaFuture = promise::defer([=] {
- return DisplayRenderArea::create(displayWeak, Rect(), size, *outDataspace,
- captureOrientation, false /* captureSecureLayers */);
+ return DisplayRenderArea::create(displayWeak, Rect(), size,
+ captureResults.capturedDataspace, captureOrientation,
+ false /* captureSecureLayers */);
});
auto traverseLayers = [this, layerStack](const LayerVector::Visitor& visitor) {
traverseLayersInLayerStack(layerStack, visitor);
};
- bool ignored = false;
-
- return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, size, outBuffer,
- ui::PixelFormat::RGBA_8888, false /* useIdentityTransform */,
- ignored /* outCapturedSecureLayers */);
+ return captureScreenCommon(std::move(renderAreaFuture), traverseLayers, size,
+ &captureResults.buffer, ui::PixelFormat::RGBA_8888,
+ false /* useIdentityTransform */,
+ captureResults.capturedSecureLayers);
}
status_t SurfaceFlinger::captureLayers(
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 2c4e40d..55f8034 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -433,13 +433,10 @@
ISurfaceComposer::VsyncSource vsyncSource = eVsyncSourceApp,
ISurfaceComposer::ConfigChanged configChanged =
ISurfaceComposer::eConfigChangedSuppress) override;
- status_t captureScreen(const sp<IBinder>& displayToken, sp<GraphicBuffer>* outBuffer,
- bool& outCapturedSecureLayers, ui::Dataspace reqDataspace,
- ui::PixelFormat reqPixelFormat, const Rect& sourceCrop,
- uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
- ui::Rotation rotation, bool captureSecureLayers) override;
- status_t captureScreen(uint64_t displayOrLayerStack, ui::Dataspace* outDataspace,
- sp<GraphicBuffer>* outBuffer) override;
+ status_t captureDisplay(const DisplayCaptureArgs& args,
+ ScreenCaptureResults& captureResults) override;
+ status_t captureDisplay(uint64_t displayOrLayerStack,
+ ScreenCaptureResults& captureResults) override;
status_t captureLayers(
const sp<IBinder>& parentHandle, sp<GraphicBuffer>* outBuffer,
const ui::Dataspace reqDataspace, const ui::PixelFormat reqPixelFormat,
diff --git a/services/surfaceflinger/tests/LayerTransactionTest.h b/services/surfaceflinger/tests/LayerTransactionTest.h
index f3e11d8..d4e952a 100644
--- a/services/surfaceflinger/tests/LayerTransactionTest.h
+++ b/services/surfaceflinger/tests/LayerTransactionTest.h
@@ -40,6 +40,8 @@
sp<ISurfaceComposer> sf(ComposerService::getComposerService());
ASSERT_NO_FATAL_FAILURE(sf->getColorManagement(&mColorManagementUsed));
+
+ mCaptureArgs.displayToken = mDisplay;
}
virtual void TearDown() {
@@ -249,6 +251,9 @@
sp<SurfaceControl> mBlackBgSurface;
bool mColorManagementUsed;
+ DisplayCaptureArgs mCaptureArgs;
+ ScreenCaptureResults mCaptureResults;
+
private:
void SetUpDisplay() {
mDisplay = mClient->getInternalDisplayToken();
diff --git a/services/surfaceflinger/tests/LayerTransaction_test.cpp b/services/surfaceflinger/tests/LayerTransaction_test.cpp
index 1f8f7ed..0ef4150 100644
--- a/services/surfaceflinger/tests/LayerTransaction_test.cpp
+++ b/services/surfaceflinger/tests/LayerTransaction_test.cpp
@@ -32,18 +32,16 @@
ASSERT_NO_FATAL_FAILURE(fillBufferQueueLayerColor(layer, Color::RED, 32, 32));
sp<ISurfaceComposer> composer = ComposerService::getComposerService();
- sp<GraphicBuffer> outBuffer;
Transaction()
.setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure)
.apply(true);
- ASSERT_EQ(PERMISSION_DENIED,
- composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false));
+ ASSERT_EQ(PERMISSION_DENIED, composer->captureDisplay(mCaptureArgs, mCaptureResults));
UIDFaker f(AID_SYSTEM);
// By default the system can capture screenshots with secure layers but they
// will be blacked out
- ASSERT_EQ(NO_ERROR, composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false));
+ ASSERT_EQ(NO_ERROR, composer->captureDisplay(mCaptureArgs, mCaptureResults));
{
SCOPED_TRACE("as system");
@@ -53,13 +51,12 @@
// Here we pass captureSecureLayers = true and since we are AID_SYSTEM we should be able
// to receive them...we are expected to take care with the results.
- bool outCapturedSecureLayers;
- ASSERT_EQ(NO_ERROR,
- composer->captureScreen(mDisplay, &outBuffer, outCapturedSecureLayers,
- ui::Dataspace::V0_SRGB, ui::PixelFormat::RGBA_8888, Rect(), 0,
- 0, false, ui::ROTATION_0, true));
- ASSERT_EQ(true, outCapturedSecureLayers);
- ScreenCapture sc(outBuffer);
+ DisplayCaptureArgs args;
+ args.displayToken = mDisplay;
+ args.captureSecureLayers = true;
+ ASSERT_EQ(NO_ERROR, composer->captureDisplay(args, mCaptureResults));
+ ASSERT_EQ(true, mCaptureResults.capturedSecureLayers);
+ ScreenCapture sc(mCaptureResults.buffer);
sc.expectColor(Rect(0, 0, 32, 32), Color::RED);
}
diff --git a/services/surfaceflinger/tests/LayerTypeTransaction_test.cpp b/services/surfaceflinger/tests/LayerTypeTransaction_test.cpp
index 84780ba..2ec4ea4 100644
--- a/services/surfaceflinger/tests/LayerTypeTransaction_test.cpp
+++ b/services/surfaceflinger/tests/LayerTypeTransaction_test.cpp
@@ -170,11 +170,15 @@
Transaction()
.setFlags(layer, layer_state_t::eLayerSecure, layer_state_t::eLayerSecure)
.apply(true);
- ASSERT_EQ(PERMISSION_DENIED,
- composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false));
+
+ DisplayCaptureArgs args;
+ args.displayToken = mDisplay;
+
+ ScreenCaptureResults captureResults;
+ ASSERT_EQ(PERMISSION_DENIED, composer->captureDisplay(args, captureResults));
Transaction().setFlags(layer, 0, layer_state_t::eLayerSecure).apply(true);
- ASSERT_EQ(NO_ERROR, composer->captureScreen(mDisplay, &outBuffer, Rect(), 0, 0, false));
+ ASSERT_EQ(NO_ERROR, composer->captureDisplay(args, captureResults));
}
TEST_P(LayerTypeTransactionTest, RefreshRateIsInitialized) {
sp<SurfaceControl> layer;
diff --git a/services/surfaceflinger/tests/utils/ScreenshotUtils.h b/services/surfaceflinger/tests/utils/ScreenshotUtils.h
index 5480b00..ffdf55b 100644
--- a/services/surfaceflinger/tests/utils/ScreenshotUtils.h
+++ b/services/surfaceflinger/tests/utils/ScreenshotUtils.h
@@ -35,9 +35,12 @@
const auto sf = ComposerService::getComposerService();
SurfaceComposerClient::Transaction().apply(true);
- sp<GraphicBuffer> outBuffer;
- ASSERT_EQ(NO_ERROR, sf->captureScreen(displayToken, &outBuffer, Rect(), 0, 0, false));
- *sc = std::make_unique<ScreenCapture>(outBuffer);
+ DisplayCaptureArgs args;
+ args.displayToken = displayToken;
+
+ ScreenCaptureResults captureResults;
+ ASSERT_EQ(NO_ERROR, sf->captureDisplay(args, captureResults));
+ *sc = std::make_unique<ScreenCapture>(captureResults.buffer);
}
static void captureLayers(std::unique_ptr<ScreenCapture>* sc, sp<IBinder>& parentHandle,