Merge "BLAST: Ensure buffers are submitted before reporting draw finished"

This commit is contained in:
Vishnu Nair
2020-10-16 23:03:51 +00:00
committed by Android (Google) Code Review
3 changed files with 25 additions and 7 deletions

View File

@@ -3876,10 +3876,6 @@ public final class ViewRootImpl implements ViewParent,
}
private void addFrameCallbackIfNeeded() {
if (!mNextDrawUseBLASTSyncTransaction) {
return;
}
// Frame callbacks will always occur after submitting draw requests and before
// the draw actually occurs. This will ensure that we set the next transaction
// for the frame that's about to get drawn and not on a previous frame that.
@@ -3887,8 +3883,19 @@ public final class ViewRootImpl implements ViewParent,
// This is thread safe since mRtNextFrameReportConsumeWithBlast will only be
// modified in onFrameDraw and then again in onFrameComplete. This is to ensure the
// next frame completed should be reported with the blast sync transaction.
registerRtFrameCallback(createFrameDrawingCallback());
mNextDrawUseBLASTSyncTransaction = false;
if (mNextDrawUseBLASTSyncTransaction) {
registerRtFrameCallback(createFrameDrawingCallback());
mNextDrawUseBLASTSyncTransaction = false;
} else if (mReportNextDraw) {
registerRtFrameCallback(frame -> {
if (mBlastBufferQueue != null) {
// If we need to report next draw, wait for adapter to flush its shadow queue
// by processing previously queued buffers so that we can submit the
// transaction a timely manner.
mBlastBufferQueue.flushShadowQueue();
}
});
}
}
private void performDraw() {

View File

@@ -69,13 +69,19 @@ static void nativeUpdate(JNIEnv*env, jclass clazz, jlong ptr, jlong surfaceContr
queue->update(reinterpret_cast<SurfaceControl*>(surfaceControl), width, height);
}
static void nativeFlushShadowQueue(JNIEnv* env, jclass clazz, jlong ptr) {
sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
queue->flushShadowQueue();
}
static const JNINativeMethod gMethods[] = {
/* name, signature, funcPtr */
{"nativeCreate", "(Ljava/lang/String;JJJZ)J", (void*)nativeCreate},
{"nativeGetSurface", "(J)Landroid/view/Surface;", (void*)nativeGetSurface},
{"nativeDestroy", "(J)V", (void*)nativeDestroy},
{"nativeSetNextTransaction", "(JJ)V", (void*)nativeSetNextTransaction},
{"nativeUpdate", "(JJJJ)V", (void*)nativeUpdate}};
{"nativeUpdate", "(JJJJ)V", (void*)nativeUpdate},
{"nativeFlushShadowQueue", "(J)V", (void*)nativeFlushShadowQueue}};
int register_android_graphics_BLASTBufferQueue(JNIEnv* env) {
int res = jniRegisterNativeMethods(env, "android/graphics/BLASTBufferQueue",

View File

@@ -32,6 +32,7 @@ public final class BLASTBufferQueue {
private static native Surface nativeGetSurface(long ptr);
private static native void nativeSetNextTransaction(long ptr, long transactionPtr);
private static native void nativeUpdate(long ptr, long surfaceControl, long width, long height);
private static native void nativeFlushShadowQueue(long ptr);
/** Create a new connection with the surface flinger. */
public BLASTBufferQueue(String name, SurfaceControl sc, int width, int height,
@@ -69,4 +70,8 @@ public final class BLASTBufferQueue {
super.finalize();
}
}
public void flushShadowQueue() {
nativeFlushShadowQueue(mNativeObject);
}
}