summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/RegionSamplingThread.cpp
diff options
context:
space:
mode:
author Melody Hsu <melodymhsu@google.com> 2024-06-05 00:07:03 +0000
committer Melody Hsu <melodymhsu@google.com> 2024-06-07 19:08:31 +0000
commit8c42cf19d10c9a685e8d6a88c9057435dd738a6b (patch)
tree8c9cc4534554da4e59c3e805da9ce1b37bca7c43 /services/surfaceflinger/RegionSamplingThread.cpp
parent03a8ff5c5ce9c6d8a4fd61cf44c057ca77c6c16a (diff)
Remove main thread double hop from screenshots
The SF main thread is accessed twice during screenshots, which leads to possible inconsistent states between jumps onto the main thread. Removing the double hop preserves correctness and reduces the amount of computation taking place on the main thread. The only time the main thread should be accessed should be when getting layer snapshots. All other work related to screenshots can take place in a binder thread. Bug: b/294936197, b/285553970 Test: atest SurfaceFlinger_test Flag: com.android.graphics.surfaceflinger.flags.single_hop_screenshot Change-Id: If9fd36f82c2d550bc0821b52fef3ea88b8099116
Diffstat (limited to 'services/surfaceflinger/RegionSamplingThread.cpp')
-rw-r--r--services/surfaceflinger/RegionSamplingThread.cpp33
1 files changed, 23 insertions, 10 deletions
diff --git a/services/surfaceflinger/RegionSamplingThread.cpp b/services/surfaceflinger/RegionSamplingThread.cpp
index 59eb7f5d4a..5add290e96 100644
--- a/services/surfaceflinger/RegionSamplingThread.cpp
+++ b/services/surfaceflinger/RegionSamplingThread.cpp
@@ -348,17 +348,30 @@ void RegionSamplingThread::captureSample() {
constexpr bool kGrayscale = false;
constexpr bool kIsProtected = false;
- if (const auto fenceResult =
- mFlinger.captureScreenshot(SurfaceFlinger::RenderAreaBuilderVariant(
- std::in_place_type<DisplayRenderAreaBuilder>,
- sampledBounds, sampledBounds.getSize(),
- ui::Dataspace::V0_SRGB,
- kHintForSeamlessTransition,
- true /* captureSecureLayers */, displayWeak),
- getLayerSnapshotsFn, buffer, kRegionSampling, kGrayscale,
- kIsProtected, nullptr)
+ SurfaceFlinger::RenderAreaBuilderVariant
+ renderAreaBuilder(std::in_place_type<DisplayRenderAreaBuilder>, sampledBounds,
+ sampledBounds.getSize(), ui::Dataspace::V0_SRGB,
+ kHintForSeamlessTransition, true /* captureSecureLayers */,
+ displayWeak);
+
+ FenceResult fenceResult;
+ if (FlagManager::getInstance().single_hop_screenshot() &&
+ FlagManager::getInstance().ce_fence_promise()) {
+ std::vector<sp<LayerFE>> layerFEs;
+ auto displayState =
+ mFlinger.getDisplayAndLayerSnapshotsFromMainThread(renderAreaBuilder,
+ getLayerSnapshotsFn, layerFEs);
+ fenceResult =
+ mFlinger.captureScreenshot(renderAreaBuilder, buffer, kRegionSampling, kGrayscale,
+ kIsProtected, nullptr, displayState, layerFEs)
.get();
- fenceResult.ok()) {
+ } else {
+ fenceResult =
+ mFlinger.captureScreenshotLegacy(renderAreaBuilder, getLayerSnapshotsFn, buffer,
+ kRegionSampling, kGrayscale, kIsProtected, nullptr)
+ .get();
+ }
+ if (fenceResult.ok()) {
fenceResult.value()->waitForever(LOG_TAG);
}