Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ee70fdb2 authored by Vishnu Nair's avatar Vishnu Nair
Browse files

Ensure BBQs created in a VRI use the same apply token

Pass in an apply token when creating BBQ so we do not get out of
order buffer updates if the BBQ is recreated without tearing down
the surfacecontrol.

Flag: EXEMPT bugfix
Test: presubmit
Bug: 353332587
Change-Id: I257a055d0a45f8395ae0930cbac23ceda8430cbf
parent 9a6338cd
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ import android.graphics.drawable.Drawable;
import android.hardware.HardwareBuffer;
import android.hardware.display.DisplayManager;
import android.hardware.display.DisplayManager.DisplayListener;
import android.os.Binder;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -370,6 +371,7 @@ public abstract class WallpaperService extends Service {
        private float mDefaultDimAmount = 0.05f;
        SurfaceControl mBbqSurfaceControl;
        BLASTBufferQueue mBlastBufferQueue;
        IBinder mBbqApplyToken = new Binder();
        private SurfaceControl mScreenshotSurfaceControl;
        private Point mScreenshotSize = new Point();

@@ -2390,6 +2392,7 @@ public abstract class WallpaperService extends Service {
            if (mBlastBufferQueue == null) {
                mBlastBufferQueue = new BLASTBufferQueue("Wallpaper", mBbqSurfaceControl,
                        width, height, format);
                mBlastBufferQueue.setApplyToken(mBbqApplyToken);
                // We only return the Surface the first time, as otherwise
                // it hasn't changed and there is no need to update.
                ret = mBlastBufferQueue.createSurface();
+5 −0
Original line number Diff line number Diff line
@@ -829,6 +829,7 @@ public final class ViewRootImpl implements ViewParent,
    private final SurfaceControl mSurfaceControl = new SurfaceControl();
    private BLASTBufferQueue mBlastBufferQueue;
    private IBinder mBbqApplyToken = new Binder();
    private final HdrRenderState mHdrRenderState = new HdrRenderState(this);
@@ -2743,6 +2744,10 @@ public final class ViewRootImpl implements ViewParent,
        mBlastBufferQueue = new BLASTBufferQueue(mTag, mSurfaceControl,
                mSurfaceSize.x, mSurfaceSize.y, mWindowAttributes.format);
        mBlastBufferQueue.setTransactionHangCallback(sTransactionHangCallback);
        // If we create and destroy BBQ without recreating the SurfaceControl, we can end up
        // queuing buffers on multiple apply tokens causing out of order buffer submissions. We
        // fix this by setting the same apply token on all BBQs created by this VRI.
        mBlastBufferQueue.setApplyToken(mBbqApplyToken);
        Surface blastSurface;
        if (addSchandleToVriSurface()) {
            blastSurface = mBlastBufferQueue.createSurfaceWithHandle();
+12 −5
Original line number Diff line number Diff line
@@ -16,16 +16,16 @@

#define LOG_TAG "BLASTBufferQueue"

#include <nativehelper/JNIHelp.h>

#include <android_runtime/AndroidRuntime.h>
#include <android_runtime/android_view_Surface.h>
#include <utils/Log.h>
#include <utils/RefBase.h>

#include <android_util_Binder.h>
#include <gui/BLASTBufferQueue.h>
#include <gui/Surface.h>
#include <gui/SurfaceComposerClient.h>
#include <nativehelper/JNIHelp.h>
#include <utils/Log.h>
#include <utils/RefBase.h>

#include "core_jni_helpers.h"

namespace android {
@@ -209,6 +209,12 @@ static jobject nativeGatherPendingTransactions(JNIEnv* env, jclass clazz, jlong
                          reinterpret_cast<jlong>(transaction));
}

static void nativeSetApplyToken(JNIEnv* env, jclass clazz, jlong ptr, jobject applyTokenObject) {
    sp<BLASTBufferQueue> queue = reinterpret_cast<BLASTBufferQueue*>(ptr);
    sp<IBinder> token(ibinderForJavaObject(env, applyTokenObject));
    return queue->setApplyToken(std::move(token));
}

static const JNINativeMethod gMethods[] = {
        /* name, signature, funcPtr */
        // clang-format off
@@ -227,6 +233,7 @@ static const JNINativeMethod gMethods[] = {
        {"nativeSetTransactionHangCallback",
         "(JLandroid/graphics/BLASTBufferQueue$TransactionHangCallback;)V",
         (void*)nativeSetTransactionHangCallback},
        {"nativeSetApplyToken", "(JLandroid/os/IBinder;)V", (void*)nativeSetApplyToken},
        // clang-format on
};

+6 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package android.graphics;

import android.annotation.NonNull;
import android.os.IBinder;
import android.view.Surface;
import android.view.SurfaceControl;

@@ -47,6 +48,7 @@ public final class BLASTBufferQueue {
            long frameNumber);
    private static native void nativeSetTransactionHangCallback(long ptr,
            TransactionHangCallback callback);
    private static native void nativeSetApplyToken(long ptr, IBinder applyToken);

    public interface TransactionHangCallback {
        void onTransactionHang(String reason);
@@ -204,4 +206,8 @@ public final class BLASTBufferQueue {
    public void setTransactionHangCallback(TransactionHangCallback hangCallback) {
        nativeSetTransactionHangCallback(mNativeObject, hangCallback);
    }

    public void setApplyToken(IBinder applyToken) {
        nativeSetApplyToken(mNativeObject, applyToken);
    }
}