Files
frameworks_base/graphics/java/android/graphics/BLASTBufferQueue.java
Vishnu Nair 0aa41a85fe Merge SV transactions to VRI BlastBufferQueue
Currently SV with blast sync requests a sync transaction from VRI and
merges its transactions with VRI's sync transaction. This can break if
we are not able to set the request in time.

Instead this change will merge SV transaction from the renderthread to
the VRI BlastBufferQueue specifying the framenumber which the
transaction should be merged with. The transaction will be queued until
we submit a VRI buffer with the requested frame number.

Test: open bubbles with sv blast
Test: atest SurfaceViewSyncTest
Bug: 175594838
Change-Id: I87ba346d782f615bab2e8a692adb2b3c49ef4021
2020-12-28 10:10:56 -08:00

127 lines
4.8 KiB
Java

/*
* Copyright (C) 2019 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package android.graphics;
import android.annotation.Nullable;
import android.view.Surface;
import android.view.SurfaceControl;
/**
* @hide
*/
public final class BLASTBufferQueue {
// Note: This field is accessed by native code.
public long mNativeObject; // BLASTBufferQueue*
private static native long nativeCreate(String name, long surfaceControl, long width,
long height, boolean tripleBufferingEnabled);
private static native void nativeDestroy(long ptr);
private static native Surface nativeGetSurface(long ptr, boolean includeSurfaceControlHandle);
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);
private static native void nativeMergeWithNextTransaction(long ptr, long transactionPtr,
long frameNumber);
private static native void nativeSetTransactionCompleteCallback(long ptr, long frameNumber,
TransactionCompleteCallback callback);
/**
* Callback sent to {@link #setTransactionCompleteCallback(long, TransactionCompleteCallback)}
*/
public interface TransactionCompleteCallback {
/**
* Invoked when the transaction has completed.
* @param frameNumber The frame number of the buffer that was in that transaction
*/
void onTransactionComplete(long frameNumber);
}
/** Create a new connection with the surface flinger. */
public BLASTBufferQueue(String name, SurfaceControl sc, int width, int height,
boolean tripleBufferingEnabled) {
mNativeObject = nativeCreate(name, sc.mNativeObject, width, height, tripleBufferingEnabled);
}
public void destroy() {
nativeDestroy(mNativeObject);
mNativeObject = 0;
}
/**
* @return a new Surface instance from the IGraphicsBufferProducer of the adapter.
*/
public Surface createSurface() {
return nativeGetSurface(mNativeObject, false /* includeSurfaceControlHandle */);
}
/**
* @return a new Surface instance from the IGraphicsBufferProducer of the adapter and
* the SurfaceControl handle.
*/
public Surface createSurfaceWithHandle() {
return nativeGetSurface(mNativeObject, true /* includeSurfaceControlHandle */);
}
/**
* Send the transaction to BBQ so the next frame can be added and not applied immediately.
* This gives the caller a chance to apply the transaction when it's ready.
* @param t The transaction to add the frame to. This can be null to clear the transaction.
*/
public void setNextTransaction(@Nullable SurfaceControl.Transaction t) {
nativeSetNextTransaction(mNativeObject, t == null ? 0 : t.mNativeObject);
}
public void update(SurfaceControl sc, int width, int height) {
nativeUpdate(mNativeObject, sc.mNativeObject, width, height);
}
/**
* Set a callback when the transaction with the frame number has been completed.
* @param frameNumber The frame number to get the transaction complete callback for
* @param completeCallback The callback that should be invoked.
*/
public void setTransactionCompleteCallback(long frameNumber,
@Nullable TransactionCompleteCallback completeCallback) {
nativeSetTransactionCompleteCallback(mNativeObject, frameNumber, completeCallback);
}
@Override
protected void finalize() throws Throwable {
try {
if (mNativeObject != 0) {
nativeDestroy(mNativeObject);
}
} finally {
super.finalize();
}
}
public void flushShadowQueue() {
nativeFlushShadowQueue(mNativeObject);
}
/**
* Merge the transaction passed in to the next transaction in BlastBufferQueue. The next
* transaction will be applied or merged when the next frame with specified frame number
* is available.
*/
public void mergeWithNextTransaction(SurfaceControl.Transaction t, long frameNumber) {
nativeMergeWithNextTransaction(mNativeObject, t.mNativeObject, frameNumber);
}
}