summaryrefslogtreecommitdiff
path: root/services/surfaceflinger/TransactionCallbackInvoker.cpp
AgeCommit message (Collapse)Author
2025-03-13Introduce a dependency monitor for fences Alec Mouri
This allows for userspace logging for a buffer and read/write dependencies on the buffer. Hook up SF to the dependency monitor. Right now this _does_ emit logs in SF when the primary display is powered down, which is likely indicative of SF being sloppy about release fences in situations where tearing won't be noticeable, but I did verify that manually making screenshotting forget to merge GPU work into a layer's release fence, which has been one way SF's torn the screen, triggers logcat, which is ultimately what we want. Bug: 360932099 Flag: com.android.graphics.surfaceflinger.flags.monitor_buffer_fences Test: manually remove screenshot fence handling and check logs Change-Id: Ica391dfa8a4f2924bb72664b9d9399e4ad9e1747
2024-10-28Clean up BufferReleaseChannel logging Patrick Williams
Bug: 294133380 Flag: com.android.graphics.libgui.flags.buffer_release_channel Test: BLASTBufferQueueTest Change-Id: Ia5e0299794f57c8741649dafd6c1cc9798559e09
2024-10-17Remove release fence flags Melody Hsu
ce_fence_promise and screenshot_fence_preservation flags have been out for several releases. They can be deleted, along with any obsolete code related to the flag removal. Bug: 351894825 Test: atest SurfaceFlinger_test Flag: EXEMPT flag removal Change-Id: Iba6166358c96ff6cfe5c64b68640fcd992c4089f
2024-09-23Revert "Add some tracing for release fences" Alec Mouri
This reverts commit 3118f969f488b738de1976917a0944705c209173. Reason for revert: b/368514217 Change-Id: Id69a0bd8850d2b6c093f7ce78817cdf5705215b1
2024-09-13Add some tracing for release fences Alec Mouri
* Fix FenceMonitor to cleanly teardown * App-side tracing for BBQ release callbacks * Trace future compleition in TxnCallbackInvoker Bug: 360932099 Bug: 357762453 Flag: EXEMPT debugging Test: builds Test: perfetto Change-Id: I188c04da1e249b672b428837c328568d9e7a1e66
2024-08-30Read from BufferReleaseChannel in background thread Patrick Williams
Bug: 294133380 Flag: com.android.graphics.libgui.flags.buffer_release_channel Test: BLASTBufferQueueTest Change-Id: I99c5da3bd99d6893ae24f5d55e7553b02bfc07ab
2024-08-30Revert^3 "Read from BufferReleaseChannel in background thread" Satish Yalla
This reverts commit 7a34bdcde80fbeb55b507cc7975b1f2a5125e562. Reason for revert: Droidmonitor created revert due to b/363109809. Will be verifying through ABTD before submission. Change-Id: I933a9b7602732bcd8c152978bbb2c7ee88a1533b
2024-08-29Revert^2 "Read from BufferReleaseChannel in background thread" Patrick Williams
This reverts commit 8af62f245bfc575a00f08db450067d172ef7c825. Reason for revert: The feature flag was enabled when this change was merged. I've disabled the feature flag so this change shouldn't cause issues. I'll add the missing SELinux permissions in AOSP. Change-Id: I9b07a854b0e0514d8036066f7b05a37a9701991b
2024-08-28Revert "Read from BufferReleaseChannel in background thread" Priyanka Advani (xWF)
This reverts commit 5ab65e9ef047bc802885396f0e1d960901e86a5c. Reason for revert: Droidmonitor created revert due to b/362800004. Will be verifying through ABTD before submission. Change-Id: I440606b3da7f4d4c85f5900ac9b9e6fb18ccd8fa
2024-08-26Read from BufferReleaseChannel in background thread Patrick Williams
Bug: 294133380 Flag: com.android.graphics.libgui.flags.buffer_release_channel Test: BLASTBufferQueueTest Change-Id: I18d2cf5457f615e832352ff9d03729ffe82cf4b9
2024-07-25Revert "Optimize BLAST buffer releases via Unix sockets" Patrick Williams
Reverting due to b/355260320 Change-Id: I8a32f73b6805d3f2bceb2948925be6a9baaa3015
2024-07-23Optimize BLAST buffer releases via Unix sockets Patrick Williams
Bug: 294133380 Flag: com.android.graphics.libgui.flags.buffer_release_channel Test: BLASTBufferQueueTest Change-Id: Ia183452198dadc7f8e540f7219bd44d8b5823458
2024-06-28Create a wrapper for atrace macros Vishnu Nair
Create a SF specific macro to call into atrace. This will make the switch to perfetto for capturing atrace tags easier. Flag: EXEMPT refactor Bug: 349905670 Test: perfetto Change-Id: I4d046d837f52ef78b08e3c97556f2eddb06232dd
2024-06-28Merge "Jank callback API refactor." into main Pascal Mütschard
2024-06-28Jank callback API refactor. Pascal Mütschard
Removes the old work-arounds for missing jank callbacks. Removes the jank data from the transaction completed callback. Adds new function to ISurfaceComposer to register jank listeners. With the new API, jank data is only sent over binder periodically (every ~50 frames) and on a background thread. It is also only tracked for layers where there is a listener registered. Test: manual, libsurfaceflinger_unittest Bug: http://b/336461947 Flag: EXEMPT refactor Change-Id: I3238ce604571832523525cf098832c7352879826
2024-06-26Add trace slices to capture tasks important for latency monitoring Vishnu Nair
Add a trace slices for: - for all post composition work on main thread - transaction callbacks - screenshot work on main thread Flag: EXEMPT adding trace slices + trivial refactor Bug: 333623207 Test: perfetto Change-Id: I6ca0a80941327edc0c78decf82176459d15d4595
2024-03-20Add promise for buffer releaseFence to LayerFE. Melody Hsu
Buffers can only be released when a release fence fires. Instead of tracking and waiting for each layer's Futures to complete, LayerFE can keep track of its own Future via a promise of a fence. This cleans up the shared futures that are currently being tracked and allow us to setup for eventual goals to reduce the number of screenshot calls to the main thread. Tests using a virtual display are modified to use the mirrorDisplay API with a unique layerstack. Bug: b/294936197, b/285553970 Test: manual (screenshot, camera, rotation, picture-in-picture) Test: presubmit Test: atest CompositionEnginePostCompositionTest Test: atest SurfaceFlinger_test Change-Id: I3a0af2cd02d3d010a1ea7c860c5cb0bc20837ec2
2024-01-26Correctly pass screenshot fences to transaction callbacks Alec Mouri
In some instances, a screenshot may be captured before a layer has a release callback registered. This can happen when a new buffer has not yet been transacted before a screenshot is captured. This causes the screenshot fence to be dropped and the possibility of tearing when capturing a screenshot while continuously rendering. To resolve this, buffer screenshot fences into a list of future fences when there is no callback registered, and merge those fences when dispatching the release callback. Bug: 302703346 Test: SurfaceViewTests#testMovingWhiteSurfaceView 100 times Change-Id: I91aec3cdb0973092d48cd77e59dd3999e9d9e847
2023-11-15Assign previous release fence to previous frame ID Alec Mouri
...as otherwise the release timestamps for EGL/Vk timing apis are shifted by one frame. Bug: 295456126 Bug: 301055892 Bug: 303385401 Bug: 310927247 Test: Log and inspect timestamps Change-Id: If1d8a525053591f15b95aeec8dc0bad8a13e6833
2023-02-09Send available JankData in all transaction completion callbacks. Pascal Muetschard
This, effectively, adds JankData to the callbacks also for layers that will not present in the current transaction. Bug: 235178314 Bug: 221393601 Test: atest SurfaceFlinger_test Change-Id: Ia6afaa31ad98a71cb6d6dc146f1094b857ab92b2
2023-01-09Fix flicker issue on external display. Sally Qi
Relnote: when primary and virtual display fences are already signaled while external one is still pending, external display fence should be overridden by merged fence of primary and virtual. Bug: 264002998 Test: atest libsurfaceflinger_unittest Change-Id: Ia1ac1fcc20cfd96d148c549c06777be387df1bde
2022-08-05SF: Clean up postComposition Dominik Laskowski
Avoid repetition and sp<> copies for present fences. Query the present time once. Remove DisplayDevice::getPageFlipCount. Bug: 241285191 Test: Build Change-Id: I6371e25a7422183953c0617dc1e17280f36018e4
2022-05-18Merge "Use semaphore instead of condition variable" into tm-dev Alec Mouri
2022-05-16Use semaphore instead of condition variable Alec Mouri
BackgroundExecutor uses a condition variable to synchronize processing to a work queue, which means that there is possible mutex contention on the main thread in rare scenarios. Instead, we can make the main thread non-blocking with a thread-safe queue, and use semaphores for signaling the background thread to wake up. Using semaphores saves a small number of instructions, but overall reduces contention Bug: 232113929 Test: bouncy ball Change-Id: Iced25e8349bdb2a70cac1ed681059a0b14258407
2022-05-16SF: Do not duplicate fences per layer per frame Dominik Laskowski
Convert the unique_fd of RenderEngineResult (and futures thereof) into sp<Fence> such that postFramebuffer does not duplicate release/present fences. Remove a few copies of shared futures/pointers with std::move. Bug: 232436803 Test: simpleperf (-33% cycles in sys_dup) Change-Id: Ia7c6c8333a712441f3612fb5c720ea2932799636
2022-02-09SF: pass acquire fence on BLAST callbacks Ady Abraham
When latching unsignaled buffers, the acquire fence is not signaled by the time BLAST callback is invoked. In that case pass a fence instead. For latch signaled, we still pass the acquire time itself to avoid sending file descriptors over binder. Bug: 198190384 Test: SF unit tests Change-Id: Ic7ad9b603b60dbf46a62eaf6b76bfbdeeebf6cec
2021-11-19SF: Introduce background task executor Vishnu Nair
Extract logic to execute work outside of the main thread from TransactionCallbackInvoker so we can reuse the thread for other tasks that are not critical to drawing. Bug: 206380307 Test: presubmit Change-Id: I8128d2f333e3aab5639cd1200e820de39f0b3191
2021-11-09Revert "SurfaceFlinger: Emit callbacks for non-buffer layer transactions" Jiakai Zhang
This reverts commit da1fd1508c914c7f0849e4e00a5fae5412433337. Reason for revert: Potential culprit CL for broken test b/205501709 Change-Id: Iece745e0690f4d31b93918697b306ded3abfd0d0
2021-11-04SurfaceFlinger: Emit callbacks for non-buffer layer transactions Vishnu Nair
Ensure we emit callbacks if the transaction contains only non-buffer layer state changes. Test: atest SurfaceFlinger_test Fixes: 205183085 Change-Id: I56bf0dcaff4312628fe2cd1d0b93db520518ec54
2021-10-18SurfaceFlinger: Fix duplicate callbacks Vishnu Nair
Transaction callbacks are emitted early, for empty transactions, after latch for on commit callbacks and on post composition for transaction complete callbacks. Pending callbacks are stored together. If a transaction contains a layer that is presented and a layer that is not presented, the transaction callback will get added to the pending list after the transaction is committed and it will get emitted after buffers are latched and then again at the end of composition. To fix this we make sure to only emit on commit callbacks after a buffer is latched. Test: atest SurfaceFlinger_test Bug: 202394221 Change-Id: I356fbf221812060c17765c53cc3df24cb3cd139a
2021-10-14Revert^2 "Second Patch for async RenderEngine" Sally Qi
Keep the change of Second Patch for async RenderEngine and fix the regression - remove the vector variables which is to store futureFence locally in BufferStateLayer to get avoid fd leaking - screenshots initiated from the app don't wait on the SF main thread. 2109270e74a18585aceffc94d1758cee47bb4175 Bug: 202843200 Bug: 202833127 Bug: 202808760 Test: Wembley PIN setting test, NexusLauncherOutOfProcTests Change-Id: I87847d01e2e330ddec88272cd8608f0b78c0a2cd
2021-10-12Revert "Second Patch for async RenderEngine" Vladimir Marko
Revert "Fix vender implementation due to second patch of async R..." Revert submission 15644535-asyncRenderEngineV2 Reason for revert: Broke multiple tests Reverted Changes: I772122750:Fix vts cases due to function change for async ren... I615f2927d:Second Patch for async RenderEngine I3f47b8b67:Fix vender implementation due to second patch of a... Bug: 202803359 Bug: 202808760 Change-Id: Ib8ef68747621b7114cf2d1dfb856292674729744
2021-10-11Second Patch for async RenderEngine Sally Qi
- pass a vector of <LayerSettings> instead of a vector of pointers to drawLayers function to ensure lifecycle safety. - capture all local variables to call drawLayerInternals in the render engine thread to avoid of pointers being invalidated if it takes long time to pop mFunctions calls. - change renderScreenImplLocked return type as a shared_future object to unblock SF main thread for screen capture events. - block region sampling thread only when SF main thread hasn't completed capture screen event. Bug: 180657548 Test: SurfaceFlinger_test, android.hardware.graphics.composer@2.2-vts, libcompositionengine_test, librenderengine_test, libsurfaceflinger_unittest pass Change-Id: I615f2927d30524988fb12df22fe331e7217c3058
2021-10-11TransactionCallbackInvoker: Send callbacks on thread Robert Carr
The binder serialization cost and one way method cost can add up when we have multiple layers. We invoked these callbacks directly from the main thread in order to reduce latency. Latency requirements are now loosened by two changes: 1. Most of the time we have a queue on the server side and won't be trying to make the next frame from the callback 2. In GL comp where frames are back to back, we now have release at latch. Bug: 201436596 Test: Existing tests pass Change-Id: I1372022b5130e041d6b2429a2e87e2c622086d7a
2021-09-29Simplify TransactionCallbackInvoker Robert Carr
The old code was written around the old threading model, and had to deal with callback registration coming from multiple binder threads that could interleave with sendCallbacks. The old code likewise had to deal with cases where a Transaction would apply but not "latch" in this frame. Both of these cases are removed by queued transactions, and so we can rework the model to be much simpler. This is the first step towards another simplification used to rework the frame queuing model. Test: Existing tests pass Bug: 201436596 Change-Id: I6983221ce66bb31c5da1122bde176ab4465556eb
2021-06-25Blast: Use a unique id to track buffers Vishnu Nair
When buffer queue is configured in shared buffer mode, the client can queue the same buffer over and over again and the consumer can acquire the same buffer repeatedly. BBQ tracks acquired buffers by graphic buffer id and SCC tracks release buffer callbacks by graphic buffer ids. This breaks if a buffer is reused before release. Fix this by using graphic buffer id and framenumber to track acquired buffers and buffer release callbacks. Test: atest CtsDeqpTestCases:dEQP-VK.wsi.android.shared_presentable_image.scale_none.identity.inherit.demand CtsDeqpTestCases:dEQP-VK.wsi.android.colorspace#basic Bug: 191220669 Change-Id: Ibd54df9fa6780c26cd8de769bf9e43163abbed5a
2021-06-17SF: change acquired buffers based on the current refresh rate Ady Abraham
BLASTBufferQueue set the max acquired buffers based on SF vsync configuration (sf.duration and app.duration). This is calculated based on the max supported refresh rate on the device, and it turn is propogated to apps via min_undequeued_buffers to the app could allocate enough buffers for maintaining the pipeline SF expects. This leads to a higher latency when the device is running in a lower refresh rate as there are more buffers on the buffer queue then required. In this change we are holding on the these "extra buffers" and not releasing them back to the buffer queue so the app would use the number of buffers it needs based on the current refresh rate, and to avoid having unnecessary long latency. Bug: 188553729 Test: Run backpressure based game on 60Hz and 120Hz and collect systraces Change-Id: I9d4e6278f0ddd28008ac437ab0576aa79d05166a
2021-04-21Introduce ASurfaceTransaction_setOnCommit api Vishnu Nair
Introduce a new callback for SurfaceControl transactions that fire after we commit a transaction in SurfaceFlinger. This will help some clients pace when they should apply the next transaction so it get applied on the next vsync. If they wait for the existing transaction complete callback, there may not be enough time between when the client applies the transaction and surface flinger waking up and apply it on the new vsync. This would mean the update would arrive a frame late. This callback is guaranteed to fire before the transaction complete callback. It includes all the stats as the transaction complete callback with the exception of jank data, present fence and the previous buffer release fence. This callback piggybacks of the oncomplete callback implementation by modifying the callback id to provide a callback type. The callbacks are filtered in SurfaceFlinger to invoke them earlier. In SurfaceComposerClient, they are filtered again to make sure the callbacks are invoked in order, oncommit before oncomplete. Bug: 185843251 Test: atest ASurfaceControlTest Change-Id: I57e85d75214376935e366d3825a6f3f1a8a4e79b
2021-03-17Introduce release buffer callback for BufferStateLayer Vishnu Nair
Currently BLAST clients use the TransactionCompleted callbacks to determine when to release buffers. The TransactionCompleted callback is overloaded. For transactions without buffers, the callback is called when the transaction is applied on the server. If the Transaction contains one or more buffers, the callback is called when all the buffers are latched and ready to be presented. If we have multiple buffers on multiple transactions, where one or more buffers maybe dropped, the pending callbacks are called together. This may delay signaling the client when a buffer can be released. To fix this, we introduce a new buffer release callback that is called as soon as a buffer is dropped by the server or when a new buffer has been latched and the buffer will no longer be presented. This new callback provides a graphic bufferid to identify the buffer that can be released and a release fence to wait on. BlastBufferQueue has been switched to use this new callback. Other BLAST users continue to use the existing callback. Test: go/wm-smoke Test: atest ReleaseBufferCallbackTest Bug: 178385281 Change-Id: Idd88e4994e543443198a5a8cfa0e3f5f67d5d482
2021-02-03SurfaceFlinger: Emit TransactionCompleted callbacks directly. Robert Carr
Transaction complete callbacks (BLAST Buffer release callbacks), are emitted from a TransactionCompletedThread. There's no clear reason for this behavior, as the actual runtime is exceedingly minimal. This opens us to scheduling delays when we call TransactionCompletedThread.sendCallbacks. In this CL we both remove the threaded nature of TransactionCompletedThread, and also take advantage of it running on the main thread to reduce some unnecessary copying and further reduce its runtime. Bug: 176691195 Test: Existing tests pass Change-Id: Ib1661df24c4a2ee39fc28c29a395158ce0ee7b7f