Merge "Add gatherPendingTransactions in BBQ"

This commit is contained in:
Chavi Weingarten
2022-02-09 15:41:48 +00:00
committed by Android (Google) Code Review
4 changed files with 48 additions and 7 deletions

View File

@@ -2779,9 +2779,13 @@ public final class SurfaceControl implements Parcelable {
* is allowed as a convenience.
*/
public Transaction() {
mNativeObject = nativeCreateTransaction();
mFreeNativeResources
= sRegistry.registerNativeAllocation(this, mNativeObject);
this(nativeCreateTransaction());
}
private Transaction(long nativeObject) {
mNativeObject = nativeObject;
mFreeNativeResources =
sRegistry.registerNativeAllocation(this, mNativeObject);
}
private Transaction(Parcel in) {

View File

@@ -4169,19 +4169,22 @@ public final class ViewRootImpl implements ViewParent,
+ " didProduceBuffer=" + didProduceBuffer);
}
Transaction tmpTransaction = new Transaction();
tmpTransaction.merge(mRtBLASTSyncTransaction);
// If frame wasn't drawn, clear out the next transaction so it doesn't affect the next
// draw attempt. The next transaction and transaction complete callback were only set
// for the current draw attempt.
if (!didProduceBuffer) {
mBlastBufferQueue.setSyncTransaction(null);
// Apply the transactions that were sent to mergeWithNextTransaction since the
// Get the transactions that were sent to mergeWithNextTransaction since the
// frame didn't draw on this vsync. It's possible the frame will draw later, but
// it's better to not be sync than to block on a frame that may never come.
mBlastBufferQueue.applyPendingTransactions(mRtLastAttemptedDrawFrameNum);
Transaction pendingTransactions = mBlastBufferQueue.gatherPendingTransactions(
mRtLastAttemptedDrawFrameNum);
tmpTransaction.merge(pendingTransactions);
}
Transaction tmpTransaction = new Transaction();
tmpTransaction.merge(mRtBLASTSyncTransaction);
// Post at front of queue so the buffer can be processed immediately and allow RT
// to continue processing new buffers. If RT tries to process buffers before the sync
// buffer is applied, the new buffers will not get acquired and could result in a

View File

@@ -30,6 +30,11 @@
namespace android {
static struct {
jclass clazz;
jmethodID ctor;
} gTransactionClassInfo;
static jlong nativeCreate(JNIEnv* env, jclass clazz, jstring jName) {
ScopedUtfChars name(env, jName);
sp<BLASTBufferQueue> queue = new BLASTBufferQueue(name.c_str());
@@ -86,6 +91,14 @@ static bool nativeIsSameSurfaceControl(JNIEnv* env, jclass clazz, jlong ptr, jlo
return queue->isSameSurfaceControl(reinterpret_cast<SurfaceControl*>(surfaceControl));
}
static jobject nativeGatherPendingTransactions(JNIEnv* env, jclass clazz, jlong ptr,
jlong frameNum) {
sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
SurfaceComposerClient::Transaction* transaction = queue->gatherPendingTransactions(frameNum);
return env->NewObject(gTransactionClassInfo.clazz, gTransactionClassInfo.ctor,
reinterpret_cast<jlong>(transaction));
}
static const JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
// clang-format off
@@ -98,6 +111,7 @@ static const JNINativeMethod gMethods[] = {
{"nativeGetLastAcquiredFrameNum", "(J)J", (void*)nativeGetLastAcquiredFrameNum},
{"nativeApplyPendingTransactions", "(JJ)V", (void*)nativeApplyPendingTransactions},
{"nativeIsSameSurfaceControl", "(JJ)Z", (void*)nativeIsSameSurfaceControl},
{"nativeGatherPendingTransactions", "(JJ)Landroid/view/SurfaceControl$Transaction;", (void*)nativeGatherPendingTransactions}
// clang-format on
};
@@ -105,6 +119,11 @@ int register_android_graphics_BLASTBufferQueue(JNIEnv* env) {
int res = jniRegisterNativeMethods(env, "android/graphics/BLASTBufferQueue",
gMethods, NELEM(gMethods));
LOG_ALWAYS_FATAL_IF(res < 0, "Unable to register native methods.");
jclass transactionClazz = FindClassOrDie(env, "android/view/SurfaceControl$Transaction");
gTransactionClassInfo.clazz = MakeGlobalRefOrDie(env, transactionClazz);
gTransactionClassInfo.ctor =
GetMethodIDOrDie(env, gTransactionClassInfo.clazz, "<init>", "(J)V");
return 0;
}

View File

@@ -39,6 +39,8 @@ public final class BLASTBufferQueue {
private static native long nativeGetLastAcquiredFrameNum(long ptr);
private static native void nativeApplyPendingTransactions(long ptr, long frameNumber);
private static native boolean nativeIsSameSurfaceControl(long ptr, long surfaceControlPtr);
private static native SurfaceControl.Transaction nativeGatherPendingTransactions(long ptr,
long frameNumber);
/** Create a new connection with the surface flinger. */
public BLASTBufferQueue(String name, SurfaceControl sc, int width, int height,
@@ -159,4 +161,17 @@ public final class BLASTBufferQueue {
public boolean isSameSurfaceControl(SurfaceControl sc) {
return nativeIsSameSurfaceControl(mNativeObject, sc.mNativeObject);
}
/**
* Get any transactions that were passed to {@link #mergeWithNextTransaction} with the
* specified frameNumber. This is intended to ensure transactions don't get stuck as pending
* if the specified frameNumber is never drawn.
*
* @param frameNumber The frameNumber used to determine which transactions to apply.
* @return a Transaction that contains the merge of all the transactions that were sent to
* mergeWithNextTransaction
*/
public SurfaceControl.Transaction gatherPendingTransactions(long frameNumber) {
return nativeGatherPendingTransactions(mNativeObject, frameNumber);
}
}