SF: Move screenshot Surface ops off main thread
This change rearranges the various operations that correspond to
capturing a screenshot such that all of the Surface-related ones
(connect, dequeue, queue, disconnect) are performed on the incoming
Binder thread rather than on SurfaceFlinger's main thread. This has two
major benefits:
1) It reduces the amount of time that the SurfaceFlinger main thread
is blocked while performing a screenshot, often by a considerable
amount. This should reduce the risk of jank when screenshots are
taken, such as for task snapshots during window transitions.
2) It means that the SurfaceFlinger main thread is not susceptible to
being blocked by a badly-performing BufferQueue consumer. This
also enables us to remove the GraphicProducerWrapper class, which
was previously performing a similar role.
Finally, this change also adds a mechanism that detects if the
screenshot would have been performed between the two phases of normal
SurfaceFlinger operation (invalidate and refresh), and defers it if
this condition is detected. This should further reduce the risk of jank
as a screenshot will only occur between frames rather than in the
middle of a frame.
Bug: 62257775
Test: SurfaceFlinger_test and manual verification that screenshots
still work
Change-Id: I23e6f088b4d6e477472dfc2a6c36ef3dd930c047
diff --git a/services/surfaceflinger/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 2360a61..8e47396 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -417,6 +417,14 @@
int32_t minLayerZ, int32_t maxLayerZ,
bool yswap, bool useIdentityTransform, Transform::orientation_flags rotation);
+#ifdef USE_HWC2
+ status_t captureScreenImplLocked(const sp<const DisplayDevice>& device,
+ ANativeWindowBuffer* buffer, Rect sourceCrop,
+ uint32_t reqWidth, uint32_t reqHeight, int32_t minLayerZ,
+ int32_t maxLayerZ, bool useIdentityTransform,
+ Transform::orientation_flags rotation, bool isLocalScreenshot,
+ int* outSyncFd);
+#else
status_t captureScreenImplLocked(
const sp<const DisplayDevice>& hw,
const sp<IGraphicBufferProducer>& producer,
@@ -424,6 +432,7 @@
int32_t minLayerZ, int32_t maxLayerZ,
bool useIdentityTransform, Transform::orientation_flags rotation,
bool isLocalScreenshot);
+#endif
sp<StartBootAnimThread> mStartBootAnimThread = nullptr;
@@ -695,6 +704,8 @@
};
std::queue<CompositePresentTime> mCompositePresentTimes;
+ std::atomic<bool> mRefreshPending{false};
+
/* ------------------------------------------------------------------------
* Feature prototyping
*/