Introduce ASurfaceTransaction_setOnCommit api
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. Bug: 185843251 Test: atest ASurfaceControlTest Change-Id: If0d5d01a1d5c2029eb81667356e666d7297376d4
This commit is contained in:
@@ -259,6 +259,7 @@ LIBANDROID {
|
||||
ASurfaceTransaction_setHdrMetadata_cta861_3; # introduced=29
|
||||
ASurfaceTransaction_setHdrMetadata_smpte2086; # introduced=29
|
||||
ASurfaceTransaction_setOnComplete; # introduced=29
|
||||
ASurfaceTransaction_setOnCommit; # introduced=31
|
||||
ASurfaceTransaction_setPosition; # introduced=31
|
||||
ASurfaceTransaction_setCrop; # introduced=31
|
||||
ASurfaceTransaction_setBufferTransform; # introduced=31
|
||||
|
||||
@@ -260,6 +260,7 @@ struct ASurfaceTransactionStats {
|
||||
std::unordered_map<ASurfaceControl*, ASurfaceControlStats> aSurfaceControlStats;
|
||||
int64_t latchTime;
|
||||
sp<Fence> presentFence;
|
||||
bool transactionCompleted;
|
||||
};
|
||||
|
||||
int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* aSurfaceTransactionStats) {
|
||||
@@ -269,6 +270,9 @@ int64_t ASurfaceTransactionStats_getLatchTime(ASurfaceTransactionStats* aSurface
|
||||
|
||||
int ASurfaceTransactionStats_getPresentFenceFd(ASurfaceTransactionStats* aSurfaceTransactionStats) {
|
||||
CHECK_NOT_NULL(aSurfaceTransactionStats);
|
||||
LOG_ALWAYS_FATAL_IF(!aSurfaceTransactionStats->transactionCompleted,
|
||||
"ASurfaceTransactionStats queried from an incomplete transaction callback");
|
||||
|
||||
auto& presentFence = aSurfaceTransactionStats->presentFence;
|
||||
return (presentFence) ? presentFence->dup() : -1;
|
||||
}
|
||||
@@ -313,6 +317,8 @@ int ASurfaceTransactionStats_getPreviousReleaseFenceFd(
|
||||
ASurfaceTransactionStats* aSurfaceTransactionStats, ASurfaceControl* aSurfaceControl) {
|
||||
CHECK_NOT_NULL(aSurfaceTransactionStats);
|
||||
CHECK_NOT_NULL(aSurfaceControl);
|
||||
LOG_ALWAYS_FATAL_IF(!aSurfaceTransactionStats->transactionCompleted,
|
||||
"ASurfaceTransactionStats queried from an incomplete transaction callback");
|
||||
|
||||
const auto& aSurfaceControlStats =
|
||||
aSurfaceTransactionStats->aSurfaceControlStats.find(aSurfaceControl);
|
||||
@@ -334,7 +340,6 @@ void ASurfaceTransactionStats_releaseASurfaceControls(ASurfaceControl** aSurface
|
||||
void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* aSurfaceTransaction, void* context,
|
||||
ASurfaceTransaction_OnComplete func) {
|
||||
CHECK_NOT_NULL(aSurfaceTransaction);
|
||||
CHECK_NOT_NULL(context);
|
||||
CHECK_NOT_NULL(func);
|
||||
|
||||
TransactionCompletedCallbackTakesContext callback = [func](void* callback_context,
|
||||
@@ -345,6 +350,7 @@ void ASurfaceTransaction_setOnComplete(ASurfaceTransaction* aSurfaceTransaction,
|
||||
|
||||
aSurfaceTransactionStats.latchTime = latchTime;
|
||||
aSurfaceTransactionStats.presentFence = presentFence;
|
||||
aSurfaceTransactionStats.transactionCompleted = true;
|
||||
|
||||
auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats;
|
||||
|
||||
@@ -695,3 +701,33 @@ void ASurfaceTransaction_setEnableBackPressure(ASurfaceTransaction* aSurfaceTran
|
||||
layer_state_t::eEnableBackpressure : 0;
|
||||
transaction->setFlags(surfaceControl, flags, layer_state_t::eEnableBackpressure);
|
||||
}
|
||||
|
||||
void ASurfaceTransaction_setOnCommit(ASurfaceTransaction* aSurfaceTransaction, void* context,
|
||||
ASurfaceTransaction_OnCommit func) {
|
||||
CHECK_NOT_NULL(aSurfaceTransaction);
|
||||
CHECK_NOT_NULL(func);
|
||||
|
||||
TransactionCompletedCallbackTakesContext callback =
|
||||
[func](void* callback_context, nsecs_t latchTime, const sp<Fence>& /* presentFence */,
|
||||
const std::vector<SurfaceControlStats>& surfaceControlStats) {
|
||||
ASurfaceTransactionStats aSurfaceTransactionStats;
|
||||
aSurfaceTransactionStats.latchTime = latchTime;
|
||||
aSurfaceTransactionStats.transactionCompleted = false;
|
||||
|
||||
auto& aSurfaceControlStats = aSurfaceTransactionStats.aSurfaceControlStats;
|
||||
for (const auto&
|
||||
[surfaceControl, latchTime, acquireTime, presentFence,
|
||||
previousReleaseFence, transformHint,
|
||||
frameEvents] : surfaceControlStats) {
|
||||
ASurfaceControl* aSurfaceControl =
|
||||
reinterpret_cast<ASurfaceControl*>(surfaceControl.get());
|
||||
aSurfaceControlStats[aSurfaceControl].acquireTime = acquireTime;
|
||||
}
|
||||
|
||||
(*func)(callback_context, &aSurfaceTransactionStats);
|
||||
};
|
||||
|
||||
Transaction* transaction = ASurfaceTransaction_to_Transaction(aSurfaceTransaction);
|
||||
|
||||
transaction->addTransactionCommittedCallback(callback, context);
|
||||
}
|
||||
Reference in New Issue
Block a user